WithdrawController.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <?php
  2. namespace addons\HiGo\backend\controllers;
  3. use addons\HiGo\common\models\HigoWithdrawLog;
  4. use backend\modules\mall\services\WithdrawalService;
  5. use common\enums\ApiStatusEnum;
  6. use common\enums\DownloadEnum;
  7. use common\globals\GlobalInvoke;
  8. use common\helpers\csv\CsvExportHelper;
  9. use Yii;
  10. /**
  11. * 默认控制器
  12. *
  13. * Class WithdrawController
  14. * @package addons\HiGo\backend\controllers
  15. */
  16. class WithdrawController extends BaseController
  17. {
  18. public $enableCsrfValidation = false;
  19. /**
  20. * 首页
  21. *
  22. * @return string
  23. */
  24. public function actionIndex()
  25. {
  26. if (Yii::$app->request->isAjax) {
  27. if (Yii::$app->request->isPost) {
  28. if (Yii::$app->request->post('flag') === 'EXPORT') {
  29. $post = Yii::$app->request->post();
  30. if (isset($post['status']) && ($post['status'] == -1 || $post['status'] === '')) unset($post['status']);
  31. $post['mall_id'] = $this->mall_id;
  32. $filename = '嗨贝提现审核-' . date('YmdHis') . '_' . rand(10000, 99999);
  33. $res = CsvExportHelper::exportDownLoadCenter($this->mall_id, $filename, DownloadEnum::TYPE_CASHDRAW_AUDIT, HigoWithdrawLog::class, 'exportHandle', $post);
  34. if ($res === false) return $this->error('加入导出任务失败' . CsvExportHelper::getStaticError());
  35. return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!');
  36. }
  37. } else {
  38. $log = new HigoWithdrawLog();
  39. $params = Yii::$app->request->get();
  40. $params['mall_id'] = $this->mall_id;
  41. $logs = $log->searchLogList($params);
  42. //公告调用:提现是否需要验证码
  43. $need_risk = GlobalInvoke::exec(GlobalInvoke::WITHDRAW_RISK, $this->mall_id, ['mall_id' => $this->mall_id]);
  44. $mobile = '';
  45. if ($need_risk && $need_risk['is_enable']) {
  46. $mobile = $need_risk['cash_mobile'];
  47. }
  48. $data = [
  49. 'list' => $logs['data']['list'],
  50. 'export_list' => $logs['data']['export_list'],
  51. 'pagination' => $logs['data']['pagination'],
  52. 'need_risk' => $need_risk ? $need_risk['is_enable'] : false,
  53. 'mobile' => $mobile
  54. ];
  55. return $this->success('success', $data, ApiStatusEnum::CODE_SUCCESS, 0);
  56. }
  57. }
  58. return $this->render('index');
  59. }
  60. /**
  61. * @Author: 广东七件事 ganxiaohao
  62. * @Date: 2020-05-30
  63. * @Time: 10:15
  64. * @Note:提现处理
  65. * @throws \Exception
  66. */
  67. public function actionCashApply()
  68. {
  69. try {
  70. if (\Yii::$app->request->isAjax) {
  71. if (\Yii::$app->request->isPost) {
  72. $post = \Yii::$app->request->post();
  73. if ($post['status'] == 2) {
  74. $check = $this->checkCashRisk($post);
  75. if (!$check) {
  76. return $this->error('验证码错误');
  77. }
  78. }
  79. $form = new HigoWithdrawLog();
  80. $form->attributes = \Yii::$app->request->post();
  81. $res = $form->updateLog();
  82. if ($res) return $this->success('操作成功', ['res' => $res]);
  83. return $this->error('错误');
  84. }
  85. }
  86. } catch (\Exception $e) {
  87. return $this->error($e->getMessage());
  88. }
  89. }
  90. /**
  91. * 批量审核处理
  92. * @Author: lun
  93. * @DateTime: 2022/7/16 0016 15:31
  94. * @Copyright: copyright (c) 2021 广东七件事集团
  95. */
  96. public function actionBatchCashApply()
  97. {
  98. try {
  99. $request = \Yii::$app->request;
  100. if ($request->isAjax && $request->isPost) {
  101. $params = $request->post();
  102. // 检查提交的参数
  103. $res = \Yii::$app->services->validate->validate($params, [
  104. [['ids', 'status'], 'required'],
  105. [['status'], 'integer'],
  106. [['content'], 'string'],
  107. ['ids', 'safe']
  108. ]);
  109. if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
  110. $ids = $params['ids']; // 上传的提现记录id
  111. foreach ($ids as $id) {
  112. $model = HigoWithdrawLog::findOne(['id' => $id]);
  113. if ($model) {
  114. $model->status = $params['status'];
  115. $model->content = $params['content'] ?? '';
  116. $res = $model->updateLog(); // 处理提现
  117. if ($res === false) throw new \Exception($model->getErrorMessage());
  118. }
  119. }
  120. }
  121. return $this->success('批量操作成功');
  122. } catch (\Exception $e) {
  123. return $this->error('批量操作失败:' . $e->getMessage());
  124. }
  125. }
  126. // 支付宝代付提现
  127. public function actionAlitopay()
  128. {
  129. $data = $this->request->post();
  130. $data['mall_id'] = $this->mall_id;
  131. $data['log_id'] = is_string($data['id']) ? explode(',', $data['id']) : $data["id"];
  132. // $data['log_id'] = [272,274];
  133. $service = new WithdrawalService($data);
  134. $res = $service->aliToPay();
  135. if ($res === false) {
  136. return $this->error($service->error);
  137. }
  138. return $this->success('操作成功', ['res' => $res]);
  139. }
  140. // 代税宝提现
  141. public function actionAvoidtax()
  142. {
  143. $data = $this->request->post();
  144. $data['mall_id'] = $this->mall_id;
  145. $data['log_id'] = is_string($data['id']) ? explode(',', $data['id']) : $data["id"];
  146. $service = new WithdrawalService($data);
  147. $res = $service->avoidtaxToPay();
  148. if ($res === false) {
  149. return $this->error($service->error);
  150. }
  151. return $this->success('操作成功', ['res' => $res]);
  152. }
  153. /**
  154. * 检查 支付宝代付、代税宝 插件是否开启
  155. */
  156. public function actionCheckChannel()
  157. {
  158. $res = GlobalInvoke::exec(GlobalInvoke::INVOKE_WITHDRAW_WITHDRAWAL_CHANNEL, $this->mall_id, [
  159. 'mall_id' => $this->mall_id
  160. ]);
  161. return $this->success('操作成功', $res);
  162. }
  163. /**
  164. * 检测是否需要手机验证码
  165. * @param $params
  166. * @return bool
  167. */
  168. private function checkCashRisk($params)
  169. {
  170. //打款操作:检测是否需要手机验证码,全局调用
  171. $need_risk = GlobalInvoke::exec(GlobalInvoke::WITHDRAW_RISK, $this->mall_id, ['mall_id' => $this->mall_id]);
  172. if ($need_risk && $need_risk['is_enable']) {
  173. if (empty($params['verification_code'])) {
  174. return false;
  175. }
  176. $check = GlobalInvoke::exec(GlobalInvoke::WITHDRAW_RISK_CAPTCHA, $this->mall_id, ['mall_id' => $this->mall_id, 'cash_id' => $params['id'], 'captcha' => $params['verification_code']]);
  177. if (!$check['status']) {
  178. return false;
  179. }
  180. }
  181. return true;
  182. }
  183. }