RechargeController.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\client\controllers\v1;
  8. use app\models\Lg;
  9. use app\models\Option;
  10. use app\constants\OptionSetting;
  11. use app\models\Level;
  12. use app\models\Order;
  13. use app\models\Recharge;
  14. use app\models\RechargeModule;
  15. use app\models\ReOrder;
  16. use app\models\Store;
  17. use app\models\User;
  18. use app\modules\client\behaviors\Auth;
  19. use app\modules\client\controllers\BaseController;
  20. use app\modules\client\models\v1\DetailForm;
  21. use app\modules\client\models\v1\RechargePayDataForm;
  22. use app\modules\client\models\v1\RechargeSubmitForm;
  23. use app\modules\client\models\v1\RecordForm;
  24. use yii\base\BaseObject;
  25. use app\modules\admin\models\ReOrderForm;
  26. use app\modules\client\models\v1\CashForm;
  27. use yii\helpers\ArrayHelper;
  28. use yii\helpers\Json;
  29. use yii\helpers\VarDumper;
  30. class RechargeController extends BaseController
  31. {
  32. public function behaviors()
  33. {
  34. return parent::behaviors();
  35. }
  36. /**
  37. * 申请提现
  38. */
  39. public function actionCashApply()
  40. {
  41. $form = new CashForm();
  42. $form->user_id = get_user_id();
  43. $form->store_id = get_store_id();
  44. $form->attributes = post_params();
  45. return $this->asJson($form->cashBalance());
  46. }
  47. /**
  48. * 获取提现相关
  49. */
  50. public function actionGetPrice()
  51. {
  52. $store_id = get_store_id();
  53. $store = Store::findOne($store_id);
  54. $balancToCash = (int)Option::get(OptionSetting::BALANCE_TO_CASH, $store_id, 'recharge', 0)['value'];
  55. if (!$balancToCash) {
  56. return $this->asJson([
  57. 'code' => 1,
  58. 'msg' => '提现功能未开启'
  59. ]);
  60. }
  61. $balancToCashSet = json_decode(Option::get(OptionSetting::BALANCE_TO_CASH_SETTING, $this->store_id, 'recharge', '{}')['value'], true);
  62. if (!isset($balancToCashSet['cash_service_charge'])) {
  63. $balancToCashSet['cash_service_charge'] = 0;
  64. }
  65. $saas_user = get_saas_user();
  66. $lg_info = Lg::find()->where(['user_id' => $saas_user->id, 'store_id' => get_store_id(),'status'=>1,'is_delete'=>0])->one();
  67. $res = [
  68. 'money' => get_user()->money,
  69. 'balancToCash' => $balancToCash,
  70. 'balancToCashSet' => $balancToCashSet,
  71. ];
  72. // 新提现方式
  73. $res['cash_method_list'] = [];
  74. $saas_user = get_saas_user();
  75. if (!empty($saas_user->withdraw_method)) {
  76. $cash_method = json_decode($saas_user->withdraw_method, true);
  77. if($lg_info){
  78. //灵工
  79. $cash_method = array_merge($cash_method, [[
  80. 'type' => 'lg'
  81. ]]);
  82. }
  83. if (is_array($cash_method)) {
  84. foreach($cash_method as $i => $item){
  85. if ($item['type'] === 'wechat' && $balancToCashSet['balance_to_cash_pay_type']['wechat'] == 0) {
  86. unset($cash_method[$i]);
  87. }
  88. if ($item['type'] === 'alipay' && $balancToCashSet['balance_to_cash_pay_type']['alipay'] == 0) {
  89. unset($cash_method[$i]);
  90. }
  91. if ($item['type'] === 'bank_card' && $balancToCashSet['balance_to_cash_pay_type']['bank_card'] == 0) {
  92. unset($cash_method[$i]);
  93. }
  94. if ($item['type'] === 'lg' && $store->lg_cash == 0) {
  95. unset($cash_method[$i]);
  96. }
  97. }
  98. $res['cash_method_list'] = array_values($cash_method);
  99. }
  100. }else{
  101. if($lg_info){
  102. //灵工
  103. $cash_method[]['type'] = 'lg';
  104. $res['cash_method_list'] = array_values($cash_method);
  105. }
  106. }
  107. return $this->asJson(['code' => 0, 'msg' => 'success', 'data' => $res]);
  108. }
  109. public function actionIndex()
  110. {
  111. $user = get_user();
  112. // 搜索指定月份的充值记录及余额消费记录
  113. $form = new RecordForm();
  114. $form->user = $user;
  115. $form->attributes = get_params();
  116. $form->store_id = get_store_id();
  117. $res = $form->search();
  118. if ($res['code'] == 1) {
  119. return $this->asJson($res);
  120. }
  121. // 余额页设置
  122. $form = new RechargeModule();
  123. $form->store_id = get_store_id();
  124. $setting = $form->search_recharge();
  125. $data = [
  126. 'money' => $user->money,
  127. 'list' => $res['data']['list'],
  128. 'setting' => $setting,
  129. 'date' => $res['data']['date'],
  130. ];
  131. return $this->asJson(['code' => 0, 'msg' => 'success', 'data' => $data]);
  132. }
  133. /**
  134. * 搜索指定月份的充值记录及余额消费记录
  135. * @return \yii\web\Response
  136. * @throws \yii\db\Exception
  137. */
  138. public function actionRecord()
  139. {
  140. $user = get_user();
  141. $form = new RecordForm();
  142. $form->attributes = get_params();
  143. $form->store_id = get_store_id();
  144. $form->user = $user;
  145. $res = $form->search();
  146. return $this->asJson($res);
  147. }
  148. //充值记录
  149. public function actionRechargeOrder()
  150. {
  151. $user = get_user();
  152. $form = new RecordForm();
  153. $form->attributes = get_params();
  154. $form->store_id = get_store_id();
  155. $form->user = $user;
  156. return $this->asJson($form->rechargeOrder());
  157. }
  158. //充值订单申请退款
  159. public function actionRechargeOrderRefundMoneyApply()
  160. {
  161. $user = get_user();
  162. $form = new ReOrderForm();
  163. $form->store_id = get_store_id();
  164. $order_id = input_params('order_id', 0);
  165. $desc_user = input_params('desc_user', '');
  166. return $this->asJson($form->refundMoneyApply($user->id, $order_id, $desc_user));
  167. }
  168. //充值订单退款列表
  169. public function actionRechargeOrderRefundMoneyList()
  170. {
  171. $form = new ReOrderForm();
  172. $form->store_id = get_store_id();
  173. $form->user_id = get_user_id();
  174. $form->order_id = input_params('order_id', 0);
  175. return $this->asJson($form->refundMoneyList());
  176. }
  177. public function actionLeagueRecord()
  178. {
  179. $user = get_user();
  180. $form = new RecordForm();
  181. $form->attributes = get_params();
  182. $form->store_id = get_store_id();
  183. $form->user = $user;
  184. $res = $form->league_search();
  185. return $this->asJson($res);
  186. }
  187. /**
  188. * 充值可选列表
  189. * @return \yii\web\Response
  190. */
  191. public function actionList()
  192. {
  193. $name = [
  194. 'recharge_wallet_status',
  195. 'recharge_custom_status',
  196. 'recharge_pic_url',
  197. 'recharge_ad_pic_url',
  198. 'recharge_page_url',
  199. 'recharge_p_pic_url',
  200. 'recharge_help',
  201. ];
  202. $data = Option::get($name, get_store_id(), 'recharge');
  203. $data = array_column($data, null, 'name');
  204. $balance = [
  205. 'status' => $data['recharge_wallet_status']['value'],
  206. 'pic_url' => $data['recharge_pic_url']['value'],
  207. 'ad_pic_url' => $data['recharge_ad_pic_url']['value'],
  208. 'page_url' => $data['recharge_page_url']['value'],
  209. 'p_pic_url' => $data['recharge_p_pic_url']['value'],
  210. 'help' => $data['recharge_help']['value'],
  211. 'type' => $data['recharge_custom_status']['value'],
  212. ];
  213. $list = Recharge::find()->where(['store_id' => get_store_id(), 'is_delete' => 0])
  214. ->orderBy(['pay_price' => SORT_DESC])->asArray()->all();
  215. $levelType = Level::find()->where(['store_id' => get_store_id(), 'is_delete' => Level::NOT_DELETE])->asArray()->all();
  216. foreach ($list as &$val) {
  217. foreach ($levelType as $type) {
  218. if ($val['level_up'] == $type['level']) {
  219. $val['level_up_name'] = $type['name'];
  220. break;
  221. }
  222. }
  223. }
  224. // $list = array_filter($list, function($item) {
  225. // return $item['level_up'] != get_user()->level;
  226. // });
  227. // TODO: msg_id
  228. $data = [
  229. 'list' => array_values($list),
  230. 'tpl_msg_id' => '',
  231. 'balance' => $balance
  232. ];
  233. return $this->asJson(['code' => 0, 'msg' => 'success', 'data' => $data]);
  234. }
  235. /**
  236. * 充值提交
  237. * @return \yii\web\Response
  238. */
  239. public function actionSubmit()
  240. {
  241. $form = new RechargeSubmitForm();
  242. $form->store_id = get_store_id();
  243. $form->user = get_user();
  244. $form->attributes = post_params();
  245. // if (get_params('_form') === 'h5') {
  246. // $form->pay_type = 1;
  247. // }
  248. return $this->asJson($form->save());
  249. }
  250. /**
  251. * 余额收支详情
  252. * @return \yii\web\Response
  253. */
  254. public function actionDetail()
  255. {
  256. $form = new DetailForm();
  257. $form->store_id = get_store_id();
  258. $form->attributes = get_params();
  259. return $this->asJson($form->search());
  260. }
  261. //充值方式
  262. public function actionGetPayTypeList() {
  263. $pay_type_list_json = Option::get(OptionSetting::STORE_PAYMENT, get_store_id(), 'pay', Option::get(OptionSetting::STORE_PAYMENT, get_store_id(), 'store', '{"wechat":{"value":1}}')['value']);
  264. $pay_type_list = Json::decode($pay_type_list_json['value']);
  265. $user_pay_list_json = Option::get('payment_' . get_user_id(), get_store_id(), 'user')['value'];
  266. if ($user_pay_list_json) {
  267. $user_pay_list_arr = Json::decode($user_pay_list_json);
  268. foreach ($pay_type_list as $key => &$value) {
  269. if (isset($user_pay_list_arr[$key]) && $user_pay_list_arr[$key]['value'] == 0 && $value['value'] == 1) {
  270. $value['value'] = 0;
  271. }
  272. }
  273. }
  274. $new_list = [];
  275. foreach ($pay_type_list as $index => $pay_type_value) {
  276. if ((is_wechat_platform() || is_h5() || is_app_platform()) && $index == 'wechat' && $pay_type_value['value'] == 1) {
  277. $new_list[] = [
  278. 'name' => '微信支付',
  279. 'payment' => 1,
  280. 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1/statics/images/recharge/icon-online.png'
  281. ];
  282. }
  283. if ((is_wechat_platform()) && $index == Order::PAY_TYPE_KEY_WX_B2B && $pay_type_value['value'] == 1) {
  284. $new_list[] = [
  285. 'name' => Order::PAY_TYPE_NAME_WX_B2B,
  286. 'payment' => Order::PAY_TYPE_WX_B2B,
  287. 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1/statics/images/recharge/icon-online.png'
  288. ];
  289. }
  290. if ((is_alipay_platform() || is_h5() || is_app_platform()) && $index == 'alipay' && $pay_type_value['value'] == 1) {
  291. $new_list[] = [
  292. 'name' => '支付宝支付',
  293. 'payment' => 4,
  294. 'icon' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1/statics/images/recharge/icon-alipay.png'
  295. ];
  296. }
  297. }
  298. return $this->asJson([
  299. 'code' => 0,
  300. 'msg' => '',
  301. 'data' => $new_list
  302. ]);
  303. }
  304. }