StoreCashdrawController.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <?php
  2. namespace addons\Mch\backend\controllers;
  3. use addons\Mch\common\models\MchWithdrawLog;
  4. use addons\Store\common\models\StoreWithdrawLog;
  5. use common\enums\DownloadEnum;
  6. use common\enums\StatusEnum;
  7. use common\enums\WithdrawWayEnum;
  8. use common\globals\GlobalInvoke;
  9. use common\helpers\csv\CsvExportHelper;
  10. use common\logic\common\PaymentLogic;
  11. use common\models\user\User;
  12. use yii\helpers\Json;
  13. class StoreCashdrawController extends BaseController
  14. {
  15. public function actionIndex()
  16. {
  17. if (!\Yii::$app->request->isAjax) {
  18. return $this->render('/store-cashdraw/index');
  19. }
  20. if (\Yii::$app->request->isGet) {
  21. $page = \Yii::$app->request->get('page', 1);
  22. $limit = \Yii::$app->request->get('limit', $this->pageSize);
  23. $tabname = \Yii::$app->request->get('tabname');
  24. if (empty($tabname) || !in_array($tabname, ['waiting-payment', 'payment', 'refund'])) {
  25. return $this->error('参数错误');
  26. }
  27. $cash_status_map = ['waiting-payment' => 0, 'payment' => 1, 'refund' => 2];
  28. $user_id = \Yii::$app->request->get('user_id');
  29. $nickname = \Yii::$app->request->get('nickname');
  30. $start_time = \Yii::$app->request->get('start_time');
  31. $end_time = \Yii::$app->request->get('end_time');
  32. $wheres[] = ['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'withdraw_status' => $cash_status_map[$tabname]];
  33. if (!empty($user_id)) {
  34. $wheres[] = ['user_id' => $user_id];
  35. }
  36. if (!empty($nickname)) {
  37. $users = User::find()
  38. ->select('id,nickname,mobile,avatar_url')
  39. ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
  40. ->andWhere(['like', 'nickname', $nickname])
  41. ->asArray()
  42. ->indexBy('id')
  43. ->all();
  44. $wheres[] = ['user_id' => array_column($users, 'id')];
  45. }
  46. if (!empty($start_time)) {
  47. $wheres[] = ['>=', 'created_at', strtotime($start_time)];
  48. }
  49. if (!empty($end_time)) {
  50. $wheres[] = ['<=', 'created_at', strtotime($end_time . ' 23:59:59')];
  51. }
  52. $params = [
  53. 'select' => 'id,mall_id,user_id,num,actual_num,poundage_num,type,extra,withdraw_status,created_at,remark',
  54. 'where' => $wheres,
  55. 'order' => 'created_at desc',
  56. 'page' => $page,
  57. 'limit' => $limit,
  58. ];
  59. $cash_list = MchWithdrawLog::listPage($params);
  60. if (false === $cash_list) {
  61. return $this->error(MchWithdrawLog::getStaticError());
  62. }
  63. if (!empty($cash_list['list'])) {
  64. if (empty($users)) {
  65. $user_ids = array_column($cash_list['list'], 'user_id');
  66. $users = User::find()
  67. ->select('id,nickname,mobile,avatar_url')
  68. ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'id' => $user_ids])
  69. ->asArray()
  70. ->indexBy('id')
  71. ->all();
  72. }
  73. $type_map = PaymentLogic::getWithdrawTypeMap($this->mall_id);
  74. foreach ($cash_list['list'] as &$list) {
  75. $user = $users[$list['user_id']] ?? [];
  76. $list['nickname'] = $user['nickname'] ?? '';
  77. $list['avatar_url'] = !empty($user['avatar_url']) ? $user['avatar_url'] : \Yii::$app->request->hostInfo . '/resources/img/common/default-avatar.png';
  78. $list['mobile'] = $user['mobile'] ?? '';
  79. switch ($list['type']){
  80. case 'balance':
  81. $account_info = [
  82. 'account_no' => $user['mobile'] ?? '',
  83. 'account_username' => $user['nickname'] ?? '',
  84. 'account_organization' => '平台',
  85. ];
  86. $list['actual_num'] = $list['num'];
  87. $list['poundage_num'] = 0;
  88. break;
  89. case 'bank':
  90. $extra = json_decode($list['extra'], true);
  91. if(isset($extra['card_no'])){
  92. $account_info['bank_account'] = $extra['card_no'];
  93. }
  94. if(isset($extra['username'])){
  95. $account_info['name'] = $extra['username'];
  96. }
  97. if(isset($extra['bank'])){
  98. $account_info['bank_name'] = $extra['bank'];
  99. }
  100. break;
  101. case 'joinpay':
  102. case 'fast_join_pay':
  103. $extra = json_decode($list['extra'], true);
  104. if (isset($extra['bank_card_no'])) {
  105. $account_info['bank_account'] = $extra['bank_card_no'];
  106. }
  107. if (isset($extra['payer_name'])) {
  108. $account_info['name'] = $extra['payer_name'];
  109. }
  110. if (isset($extra['bank_name'])) {
  111. $account_info['bank_name'] = $extra['bank_name'];
  112. }
  113. if (isset($extra['bank_account_type'])) {
  114. $account_info['bank_account_type'] = $extra['bank_account_type'];
  115. }
  116. break;
  117. default:
  118. $extra = json_decode($list['extra'], true);
  119. $account_info = $extra;
  120. break;
  121. }
  122. $list['account_info'] = $account_info;
  123. if($list['type']=='balance'){
  124. $list['type_name'] = '提现到余额';
  125. }else{
  126. $list['type_name'] = $type_map[$list['type']]??'';
  127. }
  128. }
  129. }
  130. $cash_list['export_list'] = MchWithdrawLog::exportFieldList();
  131. return $this->success('success', $cash_list);
  132. } else {
  133. if (\Yii::$app->request->post('flag') == 'EXPORT') {
  134. $post = \Yii::$app->request->post();
  135. // dd($post);
  136. switch ($post['curr_tabname']) {
  137. case 'waiting-payment':
  138. $status_name = '待打款';
  139. break;
  140. case 'payment':
  141. $status_name = '已打款';
  142. break;
  143. case 'refund':
  144. $status_name = '已驳回';
  145. break;
  146. }
  147. $post['mall_id'] = $this->mall_id;
  148. $filename = '多商户提现审核-' . $status_name . '列表-' . date('YmdHis') . '_' . rand(10000, 99999);
  149. // dd($post, $filename);
  150. $res = CsvExportHelper::exportDownLoadCenter($this->mall_id, $filename, DownloadEnum::TYPE_STORE_CASHDRAW_AUDIT, MchWithdrawLog::class, 'exportHandle', $post);
  151. if ($res === false) return $this->error('加入导出任务失败' . CsvExportHelper::getStaticError());
  152. return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!');
  153. }
  154. }
  155. }
  156. /**
  157. * @name:
  158. * @msg: 多商户提现审核操作
  159. * @param {*}
  160. * @return {*}
  161. */
  162. public function actionAudit()
  163. {
  164. if (!\Yii::$app->request->isPost) {
  165. return $this->error('请求方式错误');
  166. }
  167. $post = \Yii::$app->request->post();
  168. $rules = [
  169. [['id', 'action'], 'required'],
  170. ['remark', 'string', 'max' => '255'],
  171. ['action', 'in', 'range' => ['pass', 'refund']],
  172. ];
  173. $res = \Yii::$app->services->validate->validate($post, $rules);
  174. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  175. if ('pass' == $post['action']) {
  176. $withdraw_status = 1;
  177. } else {
  178. $withdraw_status = 2;
  179. }
  180. $params = [
  181. 'id' => $post['id'],
  182. 'withdraw_status' => $withdraw_status,
  183. 'remark' => $post['remark'],
  184. ];
  185. try {
  186. $res = MchWithdrawLog::cashAudit($this->mall_id, $params);
  187. if (false === $res) {
  188. return $this->error(MchWithdrawLog::getStaticError());
  189. }
  190. }catch (\Exception $e){
  191. return $this->error($e->getMessage());
  192. }
  193. return $this->success('操作成功');
  194. }
  195. }