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 = MchWithdrawLog::listPage($params); if (false === $cash_list) { return $this->error(MchWithdrawLog::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'] ?? ''; switch ($list['type']){ case 'balance': $account_info = [ 'account_no' => $user['mobile'] ?? '', 'account_username' => $user['nickname'] ?? '', 'account_organization' => '平台', ]; $list['actual_num'] = $list['num']; $list['poundage_num'] = 0; break; case 'bank': $extra = json_decode($list['extra'], true); if(isset($extra['card_no'])){ $account_info['bank_account'] = $extra['card_no']; } if(isset($extra['username'])){ $account_info['name'] = $extra['username']; } if(isset($extra['bank'])){ $account_info['bank_name'] = $extra['bank']; } 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']; } 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'] = MchWithdrawLog::exportFieldList(); return $this->success('success', $cash_list); } 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, MchWithdrawLog::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'], ]; try { $res = MchWithdrawLog::cashAudit($this->mall_id, $params); if (false === $res) { return $this->error(MchWithdrawLog::getStaticError()); } }catch (\Exception $e){ return $this->error($e->getMessage()); } return $this->success('操作成功'); } }