FinanceController.php 30 KB

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