StoreCashdrawController.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <?php
  2. namespace addons\Store\backend\controllers;
  3. use addons\Store\common\models\StoreWithdrawLog;
  4. use common\enums\ApiStatusEnum;
  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 = StoreWithdrawLog::listPage($params);
  60. if (false === $cash_list) {
  61. return $this->error(StoreWithdrawLog::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. $account_info = [];
  80. switch ($list['type']){
  81. case 'balance':
  82. $account_info = [
  83. 'account_no' => $user['mobile'] ?? '',
  84. 'account_username' => $user['nickname'] ?? '',
  85. 'account_organization' => '平台',
  86. ];
  87. break;
  88. case 'bank':
  89. $extra = json_decode($list['extra'], true);
  90. if(isset($extra['card_no'])){
  91. $account_info['bank_account'] = $extra['card_no'];
  92. }elseif(isset($extra['bank_account'])){
  93. $account_info['bank_account'] = $extra['bank_account'];
  94. }
  95. if(isset($extra['username'])){
  96. $account_info['name'] = $extra['username'];
  97. }elseif(isset($extra['name'])){
  98. $account_info['name'] = $extra['name'];
  99. }
  100. if(isset($extra['bank'])){
  101. $account_info['bank_name'] = $extra['bank'];
  102. }elseif(isset($extra['bank_name'])){
  103. $account_info['bank_name'] = $extra['bank_name'];
  104. }
  105. break;
  106. case 'joinpay':
  107. case 'fast_join_pay':
  108. $extra = json_decode($list['extra'], true);
  109. if (isset($extra['bank_card_no'])) {
  110. $account_info['bank_account'] = $extra['bank_card_no'];
  111. }
  112. if (isset($extra['payer_name'])) {
  113. $account_info['name'] = $extra['payer_name'];
  114. }
  115. if (isset($extra['bank_name'])) {
  116. $account_info['bank_name'] = $extra['bank_name'];
  117. }
  118. if (isset($extra['bank_account_type'])) {
  119. $account_info['bank_account_type'] = $extra['bank_account_type'];
  120. }
  121. if (isset($extra['name'])) {
  122. $account_info['name'] = $extra['name'];
  123. }
  124. if (isset($extra['bank_account'])) {
  125. $account_info['bank_account'] = $extra['bank_account'];
  126. }
  127. break;
  128. default:
  129. $extra = json_decode($list['extra'], true);
  130. $account_info = $extra;
  131. break;
  132. }
  133. $list['account_info'] = $account_info;
  134. if($list['type']=='balance'){
  135. $list['type_name'] = '提现到余额';
  136. }else{
  137. $list['type_name'] = $type_map[$list['type']]??'';
  138. }
  139. }
  140. }
  141. $cash_list['export_list'] = StoreWithdrawLog::exportFieldList();
  142. return $this->success('success', $cash_list, ApiStatusEnum::CODE_SUCCESS, JSON_BIGINT_AS_STRING);
  143. } else {
  144. if (\Yii::$app->request->post('flag') == 'EXPORT') {
  145. $post = \Yii::$app->request->post();
  146. // dd($post);
  147. switch ($post['curr_tabname']) {
  148. case 'waiting-payment':
  149. $status_name = '待打款';
  150. break;
  151. case 'payment':
  152. $status_name = '已打款';
  153. break;
  154. case 'refund':
  155. $status_name = '已驳回';
  156. break;
  157. }
  158. $post['mall_id'] = $this->mall_id;
  159. $filename = '门店提现审核-' . $status_name . '列表-' . date('YmdHis') . '_' . rand(10000, 99999);
  160. // dd($post, $filename);
  161. $res = CsvExportHelper::exportDownLoadCenter($this->mall_id, $filename, DownloadEnum::TYPE_STORE_CASHDRAW_AUDIT, StoreWithdrawLog::class, 'exportHandle', $post);
  162. if ($res === false) return $this->error('加入导出任务失败' . CsvExportHelper::getStaticError());
  163. return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!');
  164. }
  165. }
  166. }
  167. /**
  168. * @name:
  169. * @msg: 门店提现审核操作
  170. * @param {*}
  171. * @return {*}
  172. */
  173. public function actionAudit()
  174. {
  175. if (!\Yii::$app->request->isPost) {
  176. return $this->error('请求方式错误');
  177. }
  178. $post = \Yii::$app->request->post();
  179. $rules = [
  180. [['id', 'action'], 'required'],
  181. ['remark', 'string', 'max' => '255'],
  182. ['action', 'in', 'range' => ['pass', 'refund']],
  183. ];
  184. $res = \Yii::$app->services->validate->validate($post, $rules);
  185. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  186. if ('pass' == $post['action']) {
  187. $withdraw_status = 1;
  188. } else {
  189. $withdraw_status = 2;
  190. }
  191. $params = [
  192. 'id' => $post['id'],
  193. 'withdraw_status' => $withdraw_status,
  194. 'remark' => $post['remark'],
  195. ];
  196. $res = StoreWithdrawLog::cashAudit($this->mall_id, $params);
  197. if (false === $res) {
  198. return $this->error(StoreWithdrawLog::getStaticError());
  199. }
  200. return $this->success('操作成功');
  201. }
  202. }