| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- <?php
- namespace addons\HiGo\backend\controllers;
- use addons\HiGo\common\models\HigoWithdrawLog;
- use backend\modules\mall\services\WithdrawalService;
- use common\enums\ApiStatusEnum;
- use common\enums\DownloadEnum;
- use common\globals\GlobalInvoke;
- use common\helpers\csv\CsvExportHelper;
- use Yii;
- /**
- * 默认控制器
- *
- * Class WithdrawController
- * @package addons\HiGo\backend\controllers
- */
- class WithdrawController extends BaseController
- {
- public $enableCsrfValidation = false;
- /**
- * 首页
- *
- * @return string
- */
- public function actionIndex()
- {
- if (Yii::$app->request->isAjax) {
- if (Yii::$app->request->isPost) {
- if (Yii::$app->request->post('flag') === 'EXPORT') {
- $post = Yii::$app->request->post();
- if (isset($post['status']) && ($post['status'] == -1 || $post['status'] === '')) unset($post['status']);
- $post['mall_id'] = $this->mall_id;
- $filename = '嗨贝提现审核-' . date('YmdHis') . '_' . rand(10000, 99999);
- $res = CsvExportHelper::exportDownLoadCenter($this->mall_id, $filename, DownloadEnum::TYPE_CASHDRAW_AUDIT, HigoWithdrawLog::class, 'exportHandle', $post);
- if ($res === false) return $this->error('加入导出任务失败' . CsvExportHelper::getStaticError());
- return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!');
- }
- } else {
- $log = new HigoWithdrawLog();
- $params = Yii::$app->request->get();
- $params['mall_id'] = $this->mall_id;
- $logs = $log->searchLogList($params);
- //公告调用:提现是否需要验证码
- $need_risk = GlobalInvoke::exec(GlobalInvoke::WITHDRAW_RISK, $this->mall_id, ['mall_id' => $this->mall_id]);
- $mobile = '';
- if ($need_risk && $need_risk['is_enable']) {
- $mobile = $need_risk['cash_mobile'];
- }
- $data = [
- 'list' => $logs['data']['list'],
- 'export_list' => $logs['data']['export_list'],
- 'pagination' => $logs['data']['pagination'],
- 'need_risk' => $need_risk ? $need_risk['is_enable'] : false,
- 'mobile' => $mobile
- ];
- return $this->success('success', $data, ApiStatusEnum::CODE_SUCCESS, 0);
- }
- }
- return $this->render('index');
- }
- /**
- * @Author: 广东七件事 ganxiaohao
- * @Date: 2020-05-30
- * @Time: 10:15
- * @Note:提现处理
- * @throws \Exception
- */
- public function actionCashApply()
- {
- try {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isPost) {
- $post = \Yii::$app->request->post();
- if ($post['status'] == 2) {
- $check = $this->checkCashRisk($post);
- if (!$check) {
- return $this->error('验证码错误');
- }
- }
- $form = new HigoWithdrawLog();
- $form->attributes = \Yii::$app->request->post();
- $res = $form->updateLog();
- if ($res) return $this->success('操作成功', ['res' => $res]);
- return $this->error('错误');
- }
- }
- } catch (\Exception $e) {
- return $this->error($e->getMessage());
- }
- }
- /**
- * 批量审核处理
- * @Author: lun
- * @DateTime: 2022/7/16 0016 15:31
- * @Copyright: copyright (c) 2021 广东七件事集团
- */
- public function actionBatchCashApply()
- {
- try {
- $request = \Yii::$app->request;
- if ($request->isAjax && $request->isPost) {
- $params = $request->post();
- // 检查提交的参数
- $res = \Yii::$app->services->validate->validate($params, [
- [['ids', 'status'], 'required'],
- [['status'], 'integer'],
- [['content'], 'string'],
- ['ids', 'safe']
- ]);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- $ids = $params['ids']; // 上传的提现记录id
- foreach ($ids as $id) {
- $model = HigoWithdrawLog::findOne(['id' => $id]);
- if ($model) {
- $model->status = $params['status'];
- $model->content = $params['content'] ?? '';
- $res = $model->updateLog(); // 处理提现
- if ($res === false) throw new \Exception($model->getErrorMessage());
- }
- }
- }
- return $this->success('批量操作成功');
- } catch (\Exception $e) {
- return $this->error('批量操作失败:' . $e->getMessage());
- }
- }
- // 支付宝代付提现
- public function actionAlitopay()
- {
- $data = $this->request->post();
- $data['mall_id'] = $this->mall_id;
- $data['log_id'] = is_string($data['id']) ? explode(',', $data['id']) : $data["id"];
- // $data['log_id'] = [272,274];
- $service = new WithdrawalService($data);
- $res = $service->aliToPay();
- if ($res === false) {
- return $this->error($service->error);
- }
- return $this->success('操作成功', ['res' => $res]);
- }
- // 代税宝提现
- public function actionAvoidtax()
- {
- $data = $this->request->post();
- $data['mall_id'] = $this->mall_id;
- $data['log_id'] = is_string($data['id']) ? explode(',', $data['id']) : $data["id"];
- $service = new WithdrawalService($data);
- $res = $service->avoidtaxToPay();
- if ($res === false) {
- return $this->error($service->error);
- }
- return $this->success('操作成功', ['res' => $res]);
- }
- /**
- * 检查 支付宝代付、代税宝 插件是否开启
- */
- public function actionCheckChannel()
- {
- $res = GlobalInvoke::exec(GlobalInvoke::INVOKE_WITHDRAW_WITHDRAWAL_CHANNEL, $this->mall_id, [
- 'mall_id' => $this->mall_id
- ]);
- return $this->success('操作成功', $res);
- }
- /**
- * 检测是否需要手机验证码
- * @param $params
- * @return bool
- */
- private function checkCashRisk($params)
- {
- //打款操作:检测是否需要手机验证码,全局调用
- $need_risk = GlobalInvoke::exec(GlobalInvoke::WITHDRAW_RISK, $this->mall_id, ['mall_id' => $this->mall_id]);
- if ($need_risk && $need_risk['is_enable']) {
- if (empty($params['verification_code'])) {
- return false;
- }
- $check = GlobalInvoke::exec(GlobalInvoke::WITHDRAW_RISK_CAPTCHA, $this->mall_id, ['mall_id' => $this->mall_id, 'cash_id' => $params['id'], 'captcha' => $params['verification_code']]);
- if (!$check['status']) {
- return false;
- }
- }
- return true;
- }
- }
|