StoreCashdrawController.php 8.5 KB

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