| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- <?php
- namespace addons\Store\backend\controllers;
- use addons\Store\common\models\StoreWithdrawLog;
- use common\enums\ApiStatusEnum;
- use common\enums\DownloadEnum;
- use common\enums\StatusEnum;
- use common\enums\WithdrawWayEnum;
- use common\globals\GlobalInvoke;
- use common\helpers\csv\CsvExportHelper;
- use common\logic\common\PaymentLogic;
- use common\models\user\User;
- use yii\helpers\Json;
- class StoreCashdrawController extends BaseController
- {
- public function actionIndex()
- {
- if (!\Yii::$app->request->isAjax) {
- return $this->render('/store-cashdraw/index');
- }
- if (\Yii::$app->request->isGet) {
- $page = \Yii::$app->request->get('page', 1);
- $limit = \Yii::$app->request->get('limit', $this->pageSize);
- $tabname = \Yii::$app->request->get('tabname');
- if (empty($tabname) || !in_array($tabname, ['waiting-payment', 'payment', 'refund'])) {
- return $this->error('参数错误');
- }
- $cash_status_map = ['waiting-payment' => 0, 'payment' => 1, 'refund' => 2];
- $user_id = \Yii::$app->request->get('user_id');
- $nickname = \Yii::$app->request->get('nickname');
- $start_time = \Yii::$app->request->get('start_time');
- $end_time = \Yii::$app->request->get('end_time');
- $wheres[] = ['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'withdraw_status' => $cash_status_map[$tabname]];
- if (!empty($user_id)) {
- $wheres[] = ['user_id' => $user_id];
- }
- if (!empty($nickname)) {
- $users = User::find()
- ->select('id,nickname,mobile,avatar_url')
- ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
- ->andWhere(['like', 'nickname', $nickname])
- ->asArray()
- ->indexBy('id')
- ->all();
- $wheres[] = ['user_id' => array_column($users, 'id')];
- }
- if (!empty($start_time)) {
- $wheres[] = ['>=', 'created_at', strtotime($start_time)];
- }
- if (!empty($end_time)) {
- $wheres[] = ['<=', 'created_at', strtotime($end_time . ' 23:59:59')];
- }
- $params = [
- 'select' => 'id,mall_id,user_id,num,actual_num,poundage_num,type,extra,withdraw_status,created_at,remark',
- 'where' => $wheres,
- 'order' => 'created_at desc',
- 'page' => $page,
- 'limit' => $limit,
- ];
- $cash_list = StoreWithdrawLog::listPage($params);
- if (false === $cash_list) {
- return $this->error(StoreWithdrawLog::getStaticError());
- }
- if (!empty($cash_list['list'])) {
- if (empty($users)) {
- $user_ids = array_column($cash_list['list'], 'user_id');
- $users = User::find()
- ->select('id,nickname,mobile,avatar_url')
- ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'id' => $user_ids])
- ->asArray()
- ->indexBy('id')
- ->all();
- }
- $type_map= PaymentLogic::getWithdrawTypeMap($this->mall_id);
- foreach ($cash_list['list'] as &$list) {
- $user = $users[$list['user_id']] ?? [];
- $list['nickname'] = $user['nickname'] ?? '';
- $list['avatar_url'] = !empty($user['avatar_url']) ? $user['avatar_url'] : \Yii::$app->request->hostInfo . '/resources/img/common/default-avatar.png';
- $list['mobile'] = $user['mobile'] ?? '';
- $account_info = [];
- switch ($list['type']){
- case 'balance':
- $account_info = [
- 'account_no' => $user['mobile'] ?? '',
- 'account_username' => $user['nickname'] ?? '',
- 'account_organization' => '平台',
- ];
- break;
- case 'bank':
- $extra = json_decode($list['extra'], true);
- if(isset($extra['card_no'])){
- $account_info['bank_account'] = $extra['card_no'];
- }elseif(isset($extra['bank_account'])){
- $account_info['bank_account'] = $extra['bank_account'];
- }
- if(isset($extra['username'])){
- $account_info['name'] = $extra['username'];
- }elseif(isset($extra['name'])){
- $account_info['name'] = $extra['name'];
- }
- if(isset($extra['bank'])){
- $account_info['bank_name'] = $extra['bank'];
- }elseif(isset($extra['bank_name'])){
- $account_info['bank_name'] = $extra['bank_name'];
- }
- break;
- case 'joinpay':
- case 'fast_join_pay':
- $extra = json_decode($list['extra'], true);
- if (isset($extra['bank_card_no'])) {
- $account_info['bank_account'] = $extra['bank_card_no'];
- }
- if (isset($extra['payer_name'])) {
- $account_info['name'] = $extra['payer_name'];
- }
- if (isset($extra['bank_name'])) {
- $account_info['bank_name'] = $extra['bank_name'];
- }
- if (isset($extra['bank_account_type'])) {
- $account_info['bank_account_type'] = $extra['bank_account_type'];
- }
- if (isset($extra['name'])) {
- $account_info['name'] = $extra['name'];
- }
- if (isset($extra['bank_account'])) {
- $account_info['bank_account'] = $extra['bank_account'];
- }
- break;
- default:
- $extra = json_decode($list['extra'], true);
- $account_info = $extra;
- break;
- }
- $list['account_info'] = $account_info;
- if($list['type']=='balance'){
- $list['type_name'] = '提现到余额';
- }else{
- $list['type_name'] = $type_map[$list['type']]??'';
- }
- }
- }
- $cash_list['export_list'] = StoreWithdrawLog::exportFieldList();
- return $this->success('success', $cash_list, ApiStatusEnum::CODE_SUCCESS, JSON_BIGINT_AS_STRING);
- } else {
- if (\Yii::$app->request->post('flag') == 'EXPORT') {
- $post = \Yii::$app->request->post();
- // dd($post);
- switch ($post['curr_tabname']) {
- case 'waiting-payment':
- $status_name = '待打款';
- break;
- case 'payment':
- $status_name = '已打款';
- break;
- case 'refund':
- $status_name = '已驳回';
- break;
- }
- $post['mall_id'] = $this->mall_id;
- $filename = '门店提现审核-' . $status_name . '列表-' . date('YmdHis') . '_' . rand(10000, 99999);
- // dd($post, $filename);
- $res = CsvExportHelper::exportDownLoadCenter($this->mall_id, $filename, DownloadEnum::TYPE_STORE_CASHDRAW_AUDIT, StoreWithdrawLog::class, 'exportHandle', $post);
- if ($res === false) return $this->error('加入导出任务失败' . CsvExportHelper::getStaticError());
- return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!');
- }
- }
- }
- /**
- * @name:
- * @msg: 门店提现审核操作
- * @param {*}
- * @return {*}
- */
- public function actionAudit()
- {
- if (!\Yii::$app->request->isPost) {
- return $this->error('请求方式错误');
- }
- $post = \Yii::$app->request->post();
- $rules = [
- [['id', 'action'], 'required'],
- ['remark', 'string', 'max' => '255'],
- ['action', 'in', 'range' => ['pass', 'refund']],
- ];
- $res = \Yii::$app->services->validate->validate($post, $rules);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- if ('pass' == $post['action']) {
- $withdraw_status = 1;
- } else {
- $withdraw_status = 2;
- }
- $params = [
- 'id' => $post['id'],
- 'withdraw_status' => $withdraw_status,
- 'remark' => $post['remark'],
- ];
- $res = StoreWithdrawLog::cashAudit($this->mall_id, $params);
- if (false === $res) {
- return $this->error(StoreWithdrawLog::getStaticError());
- }
- return $this->success('操作成功');
- }
- }
|