| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- <?php
- namespace addons\Happiness\backend\controllers;
- use addons\Store\common\models\StoreWithdrawLog;
- use addons\Happiness\common\models\HappinessWithdrawLog;
- use common\enums\ApiStatusEnum;
- use common\enums\StatusEnum;
- 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 = HappinessWithdrawLog::listPage($params);
- if (false === $cash_list) {
- return $this->error(HappinessWithdrawLog::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= HappinessWithdrawLog::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 if($list['type']=='auto'){
- // $list['type_name'] = '微信自动打款';
- // }else if($list['type']=='bank'){
- // $list['type_name'] = '银行卡线下转账';
- // }else{
- $list['type_name'] = $type_map[$list['type']]??'';
- // }
- }
- }
- // $cash_list['export_list'] = HappinessWithdrawLog::exportFieldList();
- return $this->success('success', $cash_list, ApiStatusEnum::CODE_SUCCESS, JSON_BIGINT_AS_STRING);
- }
- }
- /**
- * @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 = HappinessWithdrawLog::cashAudit($this->mall_id, $params);
- if (false === $res) {
- return $this->error(StoreWithdrawLog::getStaticError());
- }
- return $this->success('操作成功');
- }
- }
|