FinanceController.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. <?php
  2. namespace addons\Store\client\controllers;
  3. use addons\JoinPay\common\global_func\payment_logic\JoinPayFastPay;
  4. use addons\JoinPay\common\models\JoinPayUserBankcard;
  5. use addons\Store\common\models\Store;
  6. use addons\Store\common\models\StoreBank;
  7. use addons\Store\common\models\StoreCashierOrder;
  8. use addons\Store\common\models\StoreCommission;
  9. use addons\Store\common\models\StoreCommissionCheck;
  10. use addons\Store\common\models\StoreSettings;
  11. use addons\Store\common\models\StoreStatistics;
  12. use addons\Store\common\models\StoreWithdrawLog;
  13. use Cassandra\Date;
  14. use common\enums\AddonsEnum;
  15. use common\enums\ApiStatusEnum;
  16. use common\enums\StatusEnum;
  17. use common\enums\UserWalletEnum;
  18. use common\helpers\ArrayHelper;
  19. use common\helpers\BankCardHelper;
  20. use common\helpers\StringHelper;
  21. use common\models\common\UserBankCard;
  22. use common\models\mall\MallAddons;
  23. use common\models\user\User;
  24. use common\models\user\UserWithdrawLog;
  25. use services\common\UserWalletService;
  26. use addons\Store\common\enums\StoreEnum;
  27. use common\globals\GlobalInvoke;
  28. use common\enums\WithdrawWayEnum;
  29. use common\models\common\PlatformSetting;
  30. use yii\helpers\Json;
  31. class FinanceController extends BaseController
  32. {
  33. /**
  34. * 财务首页
  35. * @Author bing
  36. * @DateTime 2022-04-26 18:03:57
  37. * @return void
  38. * @copyright: Copyright (c) 2022 广东七件事集团
  39. */
  40. public function actionIndex()
  41. {
  42. if (\Yii::$app->request->isAjax) {
  43. if (\Yii::$app->request->isGet) {
  44. $get = \Yii::$app->request->get();
  45. $where[] = ['mall_id' => $this->mall_id];
  46. $where[] = ['store_id' => $this->store_id];
  47. if (!empty($get['keyword'])) {
  48. $user_list = User::lists(['where' => [['mall_id' => $this->mall_id], [
  49. 'or',
  50. ['like', 'username', trim($get['keyword'])],
  51. ['like', 'nickname', trim($get['keyword'])],
  52. ['like', 'mobile', trim($get['keyword'])]
  53. ]], 'select' => 'id']);
  54. $where[] = ['user_id' => array_column($user_list, 'id')];
  55. }
  56. if (!empty($get['user_id'])) $where[] = ['user_id' => $get['user_id']];
  57. if (!empty($get['order_no'])) $where[] = ['order_no' => $get['order_no']];
  58. if (isset($get['is_settlement']) && $get['is_settlement'] != -1) $where[] = ['is_settlement' => $get['is_settlement']];
  59. $store = Store::findOne(['id' => $this->store_id]);
  60. $total_expenses = $store_balance = $unsettled_amount = 0;
  61. if (!empty($store)) {
  62. $total_expenses = $store['total_expenses'];
  63. $store_balance = bcadd($store['balance'] ,$store['unsettled_amount'],2);
  64. $unsettled_amount = $store['unsettled_amount'];
  65. }
  66. $time = time();
  67. $where[] = ['>=', 'created_at', $time - 365 * 24 * 3600];
  68. $list = StoreStatistics::lists(['where' => $where, 'index' => 'date_time']);
  69. $month = date('m', $time);
  70. $monty_int = intval($month);
  71. $year = date('Y', $time);
  72. $chart_time_arr = [];
  73. $settle_income_arr = [];
  74. if ($monty_int < 12) {
  75. $front_year = $year - 1;
  76. for ($i = $monty_int; $i <= 12; $i++) {
  77. if ($i < 10) {
  78. $month_time = $front_year . '-0' . $i;
  79. } else {
  80. $month_time = $front_year . '-' . $i;
  81. }
  82. $settle_income_arr[] = $list[$month_time]['income_money'] ?? 0;
  83. $chart_time_arr[] = $month_time;
  84. }
  85. for ($i = 1; $i <= $monty_int; $i++) {
  86. if ($i < 10) {
  87. $month_time = $year . '-0' . $i;
  88. } else {
  89. $month_time = $year . '-' . $i;
  90. }
  91. $chart_time_arr[] = $month_time;
  92. $settle_income_arr[] = $list[$month_time]['income_money'] ?? 0;
  93. }
  94. }
  95. $order_total_arr = [];
  96. $order_total_arr['store_balance'] = ['type' => 'store_balance', 'name' => '店铺余额(元)', 'value' => $store_balance, 'prompt' => ''];
  97. $order_total_arr['unsettled_amount'] = ['type' => 'unsettled_amount', 'name' => '包含待结算店铺余额(元)', 'value' => $unsettled_amount, 'prompt' => ''];
  98. $order_total_arr['total_expenses'] = ['type' => 'total_expenses', 'name' => '已提现(元)', 'value' => $total_expenses, 'prompt' => ''];
  99. $data['order_total_arr'] = $order_total_arr;
  100. $data['chart_time_arr'] = $chart_time_arr;
  101. $data['settle_income_arr'] = $settle_income_arr;
  102. return $this->success('ok', $data);
  103. }
  104. }
  105. return $this->render($this->action->id);
  106. }
  107. /**
  108. * 收入明细
  109. * @Author bing
  110. * @DateTime 2022-04-26 18:04:25
  111. * @return void
  112. * @copyright: Copyright (c) 2022 广东七件事集团
  113. */
  114. public function actionIncomeLog()
  115. {
  116. if (\Yii::$app->request->isAjax) {
  117. if (\Yii::$app->request->isGet) {
  118. $get = \Yii::$app->request->get();
  119. $where[] = ['mall_id' => $this->mall_id];
  120. $where[] = ['store_id' => $this->store_id];
  121. $where[] = ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]];
  122. if (!empty($get['keyword'])) {
  123. $user_list = User::lists(['where' => [['mall_id' => $this->mall_id], [
  124. 'or',
  125. ['like', 'username', trim($get['keyword'])],
  126. ['like', 'nickname', trim($get['keyword'])],
  127. ['like', 'mobile', trim($get['keyword'])]
  128. ]], 'select' => 'id']);
  129. $where[] = ['user_id' => array_column($user_list, 'id')];
  130. }
  131. if (!empty($get['user_id'])) $where[] = ['user_id' => $get['user_id']];
  132. if (!empty($get['order_no'])) $where[] = ['order_no' => $get['order_no']];
  133. if (isset($get['is_settlement']) && $get['is_settlement'] !== '') $where[] = ['is_settlement' => $get['is_settlement']];
  134. $params = [
  135. 'where' => $where,
  136. 'order' => 'id desc',
  137. 'with' => ['user'],
  138. 'limit' => $get['limit'] ?? $this->pageSize,
  139. ];
  140. $store = Store::findOne(['id' => $this->store_id]);
  141. $page_data = StoreCommission::listPage($params);
  142. if ($page_data === false) return $this->error(StoreCommission::getStaticError());
  143. $total_num = $total_order_money = $total_settled_amount = $unsettled_amount = 0;
  144. if (!empty($store)) {
  145. $total_num = $store['total_num'];
  146. $total_order_money = $store['total_order_money'];
  147. $total_settled_amount = $store['total_settled_amount'];
  148. $unsettled_amount = $store['unsettled_amount'];
  149. }
  150. if (!empty($page_data['list'])) {
  151. $user_id_arr = array_column($page_data['list'], 'user_id');
  152. $user_list = User::lists(['where' => [['id' => $user_id_arr]], 'index' => 'id']);
  153. $order_no_arr = array_column($page_data['list'], 'order_no');
  154. foreach ($page_data['list'] as &$item) {
  155. if ($item['type'] == 2) $order_no_arr[] = $item['order_no'];
  156. }
  157. if (!empty($order_no_arr)) {
  158. $store_cashier_order_list = StoreCashierOrder::lists(['where' => [['order_no' => $order_no_arr]], 'select' => 'order_no,extra', 'index' => 'order_no']);
  159. }
  160. $ids = array_column($page_data['list'],'id');
  161. $check_list = StoreCommissionCheck::lists([
  162. 'where'=>[
  163. ['store_commission_id'=>$ids],
  164. ['check_status'=>[0,1]]
  165. ],
  166. 'index'=>'store_commission_id'
  167. ]);
  168. foreach ($page_data['list'] as &$item) {
  169. $item['nickname'] = $item['mobile'] = $item['avatar_url'] = '';
  170. if (isset($user_list[$item['user_id']])) {
  171. $item['nickname'] = $user_list[$item['user_id']]['nickname'];
  172. $item['mobile'] = $user_list[$item['user_id']]['mobile'];
  173. $item['avatar_url'] = $user_list[$item['user_id']]['avatar_url'];
  174. }
  175. $score_deduction_bear_text = '';
  176. switch ($item['score_deduction_bear']){
  177. case -1:
  178. $score_deduction_bear_text = '未开启积分抵扣';
  179. break;
  180. case 0:
  181. $score_deduction_bear_text = '平台';
  182. break;
  183. case 1:
  184. $score_deduction_bear_text = '门店';
  185. break;
  186. }
  187. $item['score_deduction_bear_text'] = $score_deduction_bear_text;
  188. if ($item['type'] == 2) {
  189. if (isset($store_cashier_order_list[$item['order_no']])) {
  190. $addons_bonus = 0;
  191. $extra = json_decode($store_cashier_order_list[$item['order_no']]['extra'], true);
  192. if (!empty($extra)) {
  193. foreach ($extra as $k => $v) {
  194. if (in_array($k, ['agent_commission', 'distribution_commission','boss_commission','area_commission','double_copy_commission'])) $addons_bonus += $v;
  195. }
  196. }
  197. $item['addons_bonus'] = bcadd($addons_bonus,0,2);
  198. }
  199. }
  200. if(empty($store['payment_settlement_type'])){
  201. $item['is_show'] = 0;
  202. }else{
  203. $item['is_show'] = 1;
  204. if(isset($check_list[$item['id']])){
  205. $item['is_show'] = 0;
  206. }
  207. }
  208. }
  209. }
  210. $order_total_arr = [];
  211. $order_total_arr[] = ['type' => 'total_num', 'name' => '总数', 'value' => $total_num, 'prompt' => ''];
  212. $order_total_arr[] = ['type' => 'total_order_money', 'name' => '订单总金额', 'value' => $total_order_money, 'prompt' => ''];
  213. $order_total_arr[] = ['type' => 'total_settled_amount', 'name' => '提成已结算总金额', 'value' => $total_settled_amount, 'prompt' => ''];
  214. $order_total_arr[] = ['type' => 'unsettled_amount', 'name' => '提成未结算总金额', 'value' => $unsettled_amount, 'prompt' => ''];
  215. $page_data['order_total_arr'] = $order_total_arr;
  216. return $this->success('ok', $page_data);
  217. }
  218. }
  219. return $this->render($this->action->id);
  220. }
  221. /**
  222. * 提现申请(逻辑有变动请在原逻辑基础上修改)
  223. * @Author bing
  224. * @DateTime 2022-04-26 18:04:50
  225. * @return void
  226. * @copyright: Copyright (c) 2022 广东七件事集团
  227. */
  228. public function actionWithdrawal()
  229. {
  230. if (\Yii::$app->request->isAjax) {
  231. if (\Yii::$app->request->isGet) {
  232. $store = Store::getOne([['id' => $this->store_id]], true, [], false, 'id,user_id,balance');
  233. $user = User::getOne([['id' => $store['user_id']]], true, [], false, 'id,nickname,avatar_url,mobile');
  234. $store_banks = StoreBank::lists(['where' => [['store_id' => $store['id']], ['status' => StatusEnum::ENABLED]], 'id,mall_id,store_id,username,bank,card_no']);
  235. $finance = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'finance');
  236. $storeSetting = StoreSettings::findOne(['store_id' => $this->store_id]);
  237. //提现条件
  238. if(isset($finance['balance_cash_type'])){
  239. $cashType = json_decode($finance['balance_cash_type'],true);
  240. }else{
  241. //默认银行卡/余额提现
  242. $cashType = ['balance','bank'];
  243. }
  244. $balance_cash_service_fee = 0;
  245. // 走的独立设置
  246. if (!empty($storeSetting->is_enable_withdraw_setting)) {
  247. $finance['balance_cash_service_fee_limit'] = $storeSetting->balance_cash_service_fee_limit;
  248. $finance['balance_cash_service_fee_month'] = $storeSetting->balance_cash_service_fee_month;
  249. $finance['balance_cash_service_fee_diff'] = $storeSetting->balance_cash_service_fee_diff;
  250. $finance['balance_cash_service_fee'] = $storeSetting->balance_cash_service_fee;
  251. }
  252. if(!empty($finance['balance_cash_service_fee_limit'])){
  253. $month_start = strtotime(date('Y-m-01 00:00:00'));
  254. $month_end = time();
  255. $cash_total = StoreWithdrawLog::find()
  256. ->where(['mall_id'=>$this->mall_id,'withdraw_status'=>[0,1],'user_id'=>$store['user_id'],'status'=>StatusEnum::ENABLED])
  257. ->andWhere(['>=','created_at',$month_start])
  258. ->andWhere(['<','created_at',$month_end])
  259. ->andWhere(['!=','type','balance'])
  260. ->sum('num') ?? 0;
  261. if($cash_total > $finance['balance_cash_service_fee_month']){
  262. $balance_cash_service_fee = $finance['balance_cash_service_fee_diff'] ?? 0;
  263. }
  264. }else{
  265. if(isset($finance['balance_cash_service_fee'])){
  266. $balance_cash_service_fee = $finance['balance_cash_service_fee'] ?? 0;
  267. }else{
  268. $balance_cash_service_fee = \Yii::$app->services->setting->mall->get($this->mall_id, 'withdraw_balance.balance_cash_service_fee');
  269. }
  270. }
  271. $store['balance_cash_service_fee'] = $balance_cash_service_fee;
  272. if (!$cashType) {
  273. return $this->error('系统未设置提现方式');
  274. }
  275. $cash__type_name = [];
  276. $get_system_setting = PlatformSetting::getConfByGroup('system', true);
  277. if (!empty($cashType)) {
  278. $cash_type = $cashType;
  279. $cash__type_name = [];
  280. $default_withdraw_way = WithdrawWayEnum::getDefaultWithDrawWayMap(WithdrawWayEnum::WITHDRAW_TYPE_2);
  281. $extension_withdraw_way = GlobalInvoke::exec(GlobalInvoke::INVOKE_GET_WITHDRAW_EXTENSION_WAY,$this->mall_id,['mall_id'=>$this->mall_id]);
  282. $all_withdraw = array_merge($default_withdraw_way,$extension_withdraw_way);
  283. $cash_type_keys = array_keys($all_withdraw);
  284. foreach ($cash_type as $i => $item) {
  285. if (isset($all_withdraw[$item])) {
  286. if (isset($all_withdraw[$item])) {
  287. if (is_array($all_withdraw[$item])) {
  288. $name = $all_withdraw[$item]['name'] ?? '';
  289. } else {
  290. $name = $all_withdraw[$item];
  291. }
  292. }
  293. $cash__type_name[$i]['type'] = $item;
  294. $cash__type_name[$i]['name'] = $name;
  295. }
  296. }
  297. }
  298. return $this->success('ok', ['user' => $user, 'store' => $store, 'store_banks' => $store_banks,'cash__type_name'=>$cash__type_name],ApiStatusEnum::CODE_SUCCESS,0);
  299. } else {
  300. $params = \Yii::$app->request->post('form');
  301. $store = Store::getOne([['id' => $this->store_id]], false, [], false, 'id,mall_id,user_id,balance');
  302. $form = new StoreWithdrawLog();
  303. $params['mall_id'] = $this->mall_id;
  304. $params['user_id'] = $store['user_id'];
  305. $params['store_id'] = $this->store_id;
  306. $form->attributes = $params;
  307. $data = $form->saveRecord($params);
  308. if ($data['state']) {
  309. return $this->success('操作成功', $data['data']);
  310. } else {
  311. return $this->error($data['msg']);
  312. }
  313. }
  314. }
  315. return $this->render($this->action->id);
  316. }
  317. public function getCashTypeName($user_id){
  318. $cash_type_name = [];
  319. $payment = \Yii::$app->services->setting->mall->get($this->mall_id, 'withdraw_balance');
  320. if (!$payment) return $cash_type_name;
  321. $cashType = $payment['balance_cash_type'];
  322. if(!empty($cashType)) {
  323. $cash_type = Json::decode($cashType);
  324. $default_withdraw_way = WithdrawWayEnum::getDefaultWithDrawWayMap(WithdrawWayEnum::WITHDRAW_TYPE_2);
  325. $extension_withdraw_way = GlobalInvoke::exec(GlobalInvoke::INVOKE_GET_WITHDRAW_EXTENSION_WAY, $this->mall_id, ['mall_id' => $this->mall_id]);
  326. $all_withdraw = array_merge($default_withdraw_way, $extension_withdraw_way);
  327. $cash_type_keys = array_keys($all_withdraw);
  328. $get_system_setting = PlatformSetting::getConfByGroup('system', true);
  329. $bank_card_list = [];
  330. if (in_array('bank', $cash_type_keys) || in_array('joinpay', $cash_type_keys)) {
  331. $bank_card_list = UserBankCard::getUserCardList($user_id, $this->mall_id);
  332. }
  333. foreach ($cash_type as $i => $item) {
  334. if(in_array($item,['alipay_tax'])) continue;
  335. if (isset($all_withdraw[$item])) {
  336. $taxFee = 0;
  337. $name = '';
  338. if (isset($all_withdraw[$item])) {
  339. if (is_array($all_withdraw[$item])) {
  340. $name = $all_withdraw[$item]['name'] ?? '';
  341. $taxFee = $all_withdraw[$item]['taxFee'] ?? 0;
  342. } else {
  343. $name = $all_withdraw[$item];
  344. }
  345. }
  346. $cash_type_name[$i]['type'] = $item;
  347. $cash_type_name[$i]['taxFee'] = $taxFee;
  348. $cash_type_name[$i]['name'] = $name;
  349. $cash_type_name[$i]['img'] = $get_system_setting['api_url']['value'] . '/resources/img/payment/' . $item . '.png';
  350. if ('bank' == $item || 'joinpay' == $item || 'yunfast_pay' == $item) {
  351. $cash_type_name[$i]['bank_card_list'] = $bank_card_list;
  352. }
  353. }
  354. }
  355. }
  356. return $cash_type_name;
  357. }
  358. //编辑银行卡
  359. public function actionEditStoreBank()
  360. {
  361. if (\Yii::$app->request->isPost) {
  362. $params = \Yii::$app->request->post('form');
  363. $params['mall_id'] = $this->mall_id;
  364. $params['store_id'] = $this->store_id;
  365. $res = StoreBank::setData($params);
  366. if ($res == false) $this->error('操作失败');
  367. return $this->success();
  368. } else {
  369. $params = \Yii::$app->request->get();
  370. $store_bank_info = StoreBank::getOne([['id' => $params['id']], ['mall_id' => $this->mall_id], ['store_id' => $this->store_id]], true);
  371. return $this->success('ok', ['store_bank_info' => $store_bank_info],ApiStatusEnum::CODE_SUCCESS,0);
  372. }
  373. }
  374. //删除银行卡
  375. public function actionDelStoreBank()
  376. {
  377. $params = \Yii::$app->request->get();
  378. $params['mall_id'] = $this->mall_id;
  379. $params['store_id'] = $this->store_id;
  380. $params['status'] = StatusEnum::DELETE;
  381. $res = StoreBank::setData($params);
  382. if ($res == false) $this->error('操作失败');
  383. return $this->success();
  384. }
  385. //编辑汇聚银行卡
  386. public function actionEditStoreBankPay()
  387. {
  388. if (\Yii::$app->request->isPost) {
  389. $post = \Yii::$app->request->post('form');
  390. $rules = [
  391. [['bank_card_no', 'id_no', 'payer_name', 'mobile_no','bank_account_type'], 'required'],
  392. ['bank_card_no', 'string', 'max' => 64],
  393. [['id_no', 'payer_name',], 'string', 'max' => 255],
  394. [['mobile_no'], 'string', 'max' => 32],
  395. ];
  396. $res = \Yii::$app->services->validate->validate($post, $rules);
  397. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  398. $post['mall_id'] = $this->mall_id;
  399. $obj = new BankCardHelper();
  400. $bank_info = $obj->bankInfo($post['bank_card_no']);
  401. if(empty($bank_info)) return $this->error('银行卡号有问题');
  402. $bank_info_arr = explode('-',$bank_info);
  403. $bankShortList = json_decode($obj->getBankShortList(),true);
  404. $bank_code = '';
  405. $bank_name = '';
  406. foreach ($bankShortList as $k=>$v){
  407. if(strpos($v,$bank_info_arr[0])!==false){
  408. $bank_code = $k;
  409. $bank_name = $v;
  410. break;
  411. }
  412. }
  413. if(empty($bank_name)||empty($bank_code)) return $this->error('无法识别的银行卡号的银行简码');
  414. $post['bank_code'] = $bank_code;
  415. $post['bank_name'] = $bank_name;
  416. $post['id_type'] = 1;
  417. switch ($bank_info_arr[2]){
  418. case '借记卡':
  419. $card_type = 'dc';
  420. $card_type_name = '储蓄卡';
  421. break;
  422. case '贷记卡':
  423. $card_type = 'cc';
  424. $card_type_name = '信用卡';
  425. break;
  426. default:
  427. return $this->error('无法识别的银行卡号');
  428. }
  429. $store = Store::findOne(['id'=>$this->store_id,'status'=>StatusEnum::ENABLED]);
  430. if(empty($store)) return $this->error('门店不存在');
  431. $post['user_id'] = $store['user_id'];
  432. $post['card_type'] = $card_type;
  433. $post['card_type_name'] = $card_type_name;
  434. $bank_card_info = UserBankCard::findOne(['mall_id'=>$this->mall_id,'bank_card_no' => $post['bank_card_no'], 'status' => StatusEnum::ENABLED]);
  435. if (!empty($bank_card_info)) {
  436. return $this->error('银行卡已经被绑定');
  437. }
  438. $card_id = StoreBank::addJoinPayBankCard($this->mall_id,$post);
  439. try {
  440. //调用汇聚接口:发送签约短信
  441. $settings = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_JOIN_PAY, 'basic');
  442. $fast_pay_class = new JoinPayFastPay($settings);
  443. $fast_pay_class->sendSignSms($card_id);
  444. return $this->success('操作成功', ['card_id' => $card_id]);
  445. } catch (\Exception $e) {
  446. return $this->error($e->getMessage());
  447. }
  448. } else {
  449. $params = \Yii::$app->request->get();
  450. $store_bank_info = StoreBank::getOne([['id' => $params['id']], ['mall_id' => $this->mall_id], ['store_id' => $this->store_id]], true);
  451. return $this->success('ok', ['store_bank_info' => $store_bank_info],ApiStatusEnum::CODE_SUCCESS,0);
  452. }
  453. }
  454. public function actionGetSmsCode(){
  455. try {
  456. $post = \Yii::$app->request->post();
  457. $rules = [
  458. [['card_id'], 'required'],
  459. [['card_id'], 'integer'],
  460. ];
  461. $res = \Yii::$app->services->validate->validate($post, $rules);
  462. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  463. $store = Store::findOne(['id'=>$this->store_id,'status'=>StatusEnum::ENABLED]);
  464. if(empty($store)) return $this->error('门店不存在');
  465. $model = UserBankCard::findOne(['id'=>$post['card_id'],'user_id'=>$store['user_id']]);
  466. if(empty($model)) return $this->error('用户银行卡不存在');
  467. //调用汇聚接口:发送签约短信
  468. $settings = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_JOIN_PAY, 'basic');
  469. $fast_pay_class = new JoinPayFastPay($settings);
  470. $fast_pay_class->sendSignSms($model->id);
  471. return $this->success('操作成功', ['card_id' => $model->id]);
  472. } catch (\Exception $e) {
  473. return $this->error($e->getMessage());
  474. }
  475. }
  476. //签约
  477. public function actionSignContract()
  478. {
  479. if (!\Yii::$app->request->isPost) {
  480. return $this->error('请求方式错误');
  481. }
  482. $post = \Yii::$app->request->post();
  483. $rules = [
  484. [['card_id', 'sms_code'], 'required'],
  485. [['card_id'], 'integer'],
  486. ['sms_code', 'string'],
  487. ];
  488. $res = \Yii::$app->services->validate->validate($post, $rules);
  489. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  490. $store = Store::findOne(['id'=>$this->store_id,'status'=>StatusEnum::ENABLED]);
  491. if(empty($store)) return $this->error('门店不存在');
  492. $post['user_id'] = $store['user_id'];
  493. $card_info = UserBankCard::findOne([
  494. 'mall_id' => $this->mall_id,
  495. 'status' => StatusEnum::ENABLED,
  496. 'id' => $post['card_id'],
  497. 'user_id' => $store['user_id'],
  498. ]);
  499. if (empty($card_info)) return $this->error('银行卡不存在');
  500. $joinpay_card_info = JoinPayUserBankcard::findOne([
  501. 'mall_id' => $this->mall_id,
  502. 'status' => StatusEnum::ENABLED,
  503. 'card_id' => $post['card_id'],
  504. 'user_id' => $store['user_id'],
  505. ]);
  506. if (empty($joinpay_card_info)) {
  507. return $this->error('银行卡数据异常');
  508. }
  509. if ($joinpay_card_info->is_sign == 1) {
  510. return $this->error('银行卡已经签约');
  511. }
  512. try {
  513. // 签约快捷支付
  514. $settings = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_JOIN_PAY, 'basic');
  515. $fast_pay_class = new JoinPayFastPay($settings);
  516. $fast_pay_class->sign($post['card_id'], $post['sms_code']);
  517. $card_info = ArrayHelper::toArray($card_info);
  518. $card_info['is_sign'] = 1;
  519. $card_info['is_auth'] = true;
  520. $card_info['icon'] = UserBankCard::getBankPicture($card_info['bank_code'], 'icon');
  521. unset($card_info['cvv'], $card_info['sign_no'], $card_info['payer_name'], $card_info['id_no']);
  522. return $this->success('签约成功', ['card_info' => $card_info], ApiStatusEnum::CODE_SUCCESS, 0);
  523. } catch (\Exception $e) {
  524. return $this->error($e->getMessage());
  525. }
  526. }
  527. //解约
  528. public function actionContractRelieve()
  529. {
  530. if (!\Yii::$app->request->isPost) {
  531. return $this->error('请求方式错误');
  532. }
  533. $post = \Yii::$app->request->post();
  534. $rules = [
  535. [['card_id'], 'required'],
  536. [['card_id'], 'integer'],
  537. ];
  538. $store = Store::findOne(['id'=>$this->store_id,'status'=>StatusEnum::ENABLED]);
  539. if(empty($store)) return $this->error('门店不存在');
  540. $res = \Yii::$app->services->validate->validate($post, $rules);
  541. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  542. $card_info = UserBankCard::findOne([
  543. 'mall_id' => $this->mall_id,
  544. 'id' => $post['card_id'],
  545. 'status' => StatusEnum::ENABLED,
  546. 'user_id' => $store['user_id'],
  547. ]);
  548. $joinpay_card_info = JoinPayUserBankcard::findOne([
  549. 'mall_id' => $this->mall_id,
  550. 'user_id' => $store['user_id'],
  551. 'card_id' => $post['card_id'],
  552. 'status' => StatusEnum::ENABLED,
  553. 'is_sign' => 1,
  554. ]);
  555. if (empty($card_info) || empty($joinpay_card_info)) {
  556. return $this->error('银行卡不存在或者已经解除签约');
  557. };
  558. try {
  559. // 解除快捷支付签约
  560. $settings = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_JOIN_PAY, 'basic');
  561. $fast_pay_class = new JoinPayFastPay($settings);
  562. $fast_pay_class->unsign($joinpay_card_info);
  563. return $this->success('解约成功');
  564. } catch (\Exception $e) {
  565. return $this->error($e->getMessage());
  566. }
  567. }
  568. /**
  569. * 提现日志
  570. * @Author bing
  571. * @DateTime 2022-04-26 18:04:50
  572. * @return void
  573. * @copyright: Copyright (c) 2022 广东七件事集团
  574. */
  575. public function actionWithdrawalLog()
  576. {
  577. if (\Yii::$app->request->isAjax) {
  578. if (\Yii::$app->request->isGet) {
  579. $params = \Yii::$app->request->get();
  580. $where[] = ['mall_id' => $this->mall_id];
  581. $where[] = ['store_id' => $this->store_id];
  582. if (!empty($params['start'])) $where[] = ['>=', 'created_at', strtotime($params['start'])];
  583. if (!empty($params['end'])) $where[] = ['<=', 'created_at', strtotime($params['end'])];
  584. if (isset($params['withdraw_status']) && $params['withdraw_status'] !== '') $where[] = ['withdraw_status' => $params['withdraw_status']];
  585. $params['where'] = $where;
  586. $params['order'] = 'id desc';
  587. $page_data = StoreWithdrawLog::listPage($params);
  588. if ($page_data === false) return $this->error(StoreWithdrawLog::getStaticError());
  589. if (!empty($page_data['list'])) {
  590. foreach ($page_data['list'] as &$item) {
  591. $item['extra'] = json_decode($item['extra'], true);
  592. if('bank' == $item['type']){
  593. if(isset($item['extra']['card_no'])){
  594. $item['extra']['bank_account'] = $item['extra']['card_no'];
  595. }
  596. if(isset($item['extra']['username'])){
  597. $item['extra']['name'] = $item['extra']['username'];
  598. }
  599. if(isset($item['extra']['bank'])){
  600. $item['extra']['bank_name'] = $item['extra']['bank'];
  601. }
  602. }
  603. }
  604. }
  605. return $this->success('ok', $page_data);
  606. }
  607. }
  608. }
  609. }