request->isAjax) { if (\Yii::$app->request->isGet) { $get = \Yii::$app->request->get(); $where[] = ['mall_id' => $this->mall_id]; $where[] = ['store_id' => $this->store_id]; if (!empty($get['keyword'])) { $user_list = User::lists(['where' => [['mall_id' => $this->mall_id], [ 'or', ['like', 'username', trim($get['keyword'])], ['like', 'nickname', trim($get['keyword'])], ['like', 'mobile', trim($get['keyword'])] ]], 'select' => 'id']); $where[] = ['user_id' => array_column($user_list, 'id')]; } if (!empty($get['user_id'])) $where[] = ['user_id' => $get['user_id']]; if (!empty($get['order_no'])) $where[] = ['order_no' => $get['order_no']]; if (isset($get['is_settlement']) && $get['is_settlement'] != -1) $where[] = ['is_settlement' => $get['is_settlement']]; $store = Store::findOne(['id' => $this->store_id]); $total_expenses = $store_balance = $unsettled_amount = 0; if (!empty($store)) { $total_expenses = $store['total_expenses']; $store_balance = bcadd($store['balance'] ,$store['unsettled_amount'],2); $unsettled_amount = $store['unsettled_amount']; } $time = time(); $where[] = ['>=', 'created_at', $time - 365 * 24 * 3600]; $list = StoreStatistics::lists(['where' => $where, 'index' => 'date_time']); $month = date('m', $time); $monty_int = intval($month); $year = date('Y', $time); $chart_time_arr = []; $settle_income_arr = []; if ($monty_int < 12) { $front_year = $year - 1; for ($i = $monty_int; $i <= 12; $i++) { if ($i < 10) { $month_time = $front_year . '-0' . $i; } else { $month_time = $front_year . '-' . $i; } $settle_income_arr[] = $list[$month_time]['income_money'] ?? 0; $chart_time_arr[] = $month_time; } for ($i = 1; $i <= $monty_int; $i++) { if ($i < 10) { $month_time = $year . '-0' . $i; } else { $month_time = $year . '-' . $i; } $chart_time_arr[] = $month_time; $settle_income_arr[] = $list[$month_time]['income_money'] ?? 0; } } $order_total_arr = []; $order_total_arr['store_balance'] = ['type' => 'store_balance', 'name' => '店铺余额(元)', 'value' => $store_balance, 'prompt' => '']; $order_total_arr['unsettled_amount'] = ['type' => 'unsettled_amount', 'name' => '包含待结算店铺余额(元)', 'value' => $unsettled_amount, 'prompt' => '']; $order_total_arr['total_expenses'] = ['type' => 'total_expenses', 'name' => '已提现(元)', 'value' => $total_expenses, 'prompt' => '']; $data['order_total_arr'] = $order_total_arr; $data['chart_time_arr'] = $chart_time_arr; $data['settle_income_arr'] = $settle_income_arr; return $this->success('ok', $data); } } return $this->render($this->action->id); } /** * 收入明细 * @Author bing * @DateTime 2022-04-26 18:04:25 * @return void * @copyright: Copyright (c) 2022 广东七件事集团 */ public function actionIncomeLog() { if (\Yii::$app->request->isAjax) { if (\Yii::$app->request->isGet) { $get = \Yii::$app->request->get(); $where[] = ['mall_id' => $this->mall_id]; $where[] = ['store_id' => $this->store_id]; $where[] = ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]; if (!empty($get['keyword'])) { $user_list = User::lists(['where' => [['mall_id' => $this->mall_id], [ 'or', ['like', 'username', trim($get['keyword'])], ['like', 'nickname', trim($get['keyword'])], ['like', 'mobile', trim($get['keyword'])] ]], 'select' => 'id']); $where[] = ['user_id' => array_column($user_list, 'id')]; } if (!empty($get['user_id'])) $where[] = ['user_id' => $get['user_id']]; if (!empty($get['order_no'])) $where[] = ['order_no' => $get['order_no']]; if (isset($get['is_settlement']) && $get['is_settlement'] !== '') $where[] = ['is_settlement' => $get['is_settlement']]; $params = [ 'where' => $where, 'order' => 'id desc', 'with' => ['user'], 'limit' => $get['limit'] ?? $this->pageSize, ]; $store = Store::findOne(['id' => $this->store_id]); $page_data = StoreCommission::listPage($params); if ($page_data === false) return $this->error(StoreCommission::getStaticError()); $total_num = $total_order_money = $total_settled_amount = $unsettled_amount = 0; if (!empty($store)) { $total_num = $store['total_num']; $total_order_money = $store['total_order_money']; $total_settled_amount = $store['total_settled_amount']; $unsettled_amount = $store['unsettled_amount']; } if (!empty($page_data['list'])) { $user_id_arr = array_column($page_data['list'], 'user_id'); $user_list = User::lists(['where' => [['id' => $user_id_arr]], 'index' => 'id']); $order_no_arr = array_column($page_data['list'], 'order_no'); foreach ($page_data['list'] as &$item) { if ($item['type'] == 2) $order_no_arr[] = $item['order_no']; } if (!empty($order_no_arr)) { $store_cashier_order_list = StoreCashierOrder::lists(['where' => [['order_no' => $order_no_arr]], 'select' => 'order_no,extra', 'index' => 'order_no']); } $ids = array_column($page_data['list'],'id'); $check_list = StoreCommissionCheck::lists([ 'where'=>[ ['store_commission_id'=>$ids], ['check_status'=>[0,1]] ], 'index'=>'store_commission_id' ]); foreach ($page_data['list'] as &$item) { $item['nickname'] = $item['mobile'] = $item['avatar_url'] = ''; if (isset($user_list[$item['user_id']])) { $item['nickname'] = $user_list[$item['user_id']]['nickname']; $item['mobile'] = $user_list[$item['user_id']]['mobile']; $item['avatar_url'] = $user_list[$item['user_id']]['avatar_url']; } $score_deduction_bear_text = ''; switch ($item['score_deduction_bear']){ case -1: $score_deduction_bear_text = '未开启积分抵扣'; break; case 0: $score_deduction_bear_text = '平台'; break; case 1: $score_deduction_bear_text = '门店'; break; } $item['score_deduction_bear_text'] = $score_deduction_bear_text; if ($item['type'] == 2) { if (isset($store_cashier_order_list[$item['order_no']])) { $addons_bonus = 0; $extra = json_decode($store_cashier_order_list[$item['order_no']]['extra'], true); if (!empty($extra)) { foreach ($extra as $k => $v) { if (in_array($k, ['agent_commission', 'distribution_commission','boss_commission','area_commission','double_copy_commission'])) $addons_bonus += $v; } } $item['addons_bonus'] = bcadd($addons_bonus,0,2); } } if(empty($store['payment_settlement_type'])){ $item['is_show'] = 0; }else{ $item['is_show'] = 1; if(isset($check_list[$item['id']])){ $item['is_show'] = 0; } } } } $order_total_arr = []; $order_total_arr[] = ['type' => 'total_num', 'name' => '总数', 'value' => $total_num, 'prompt' => '']; $order_total_arr[] = ['type' => 'total_order_money', 'name' => '订单总金额', 'value' => $total_order_money, 'prompt' => '']; $order_total_arr[] = ['type' => 'total_settled_amount', 'name' => '提成已结算总金额', 'value' => $total_settled_amount, 'prompt' => '']; $order_total_arr[] = ['type' => 'unsettled_amount', 'name' => '提成未结算总金额', 'value' => $unsettled_amount, 'prompt' => '']; $page_data['order_total_arr'] = $order_total_arr; return $this->success('ok', $page_data); } } return $this->render($this->action->id); } /** * 提现申请(逻辑有变动请在原逻辑基础上修改) * @Author bing * @DateTime 2022-04-26 18:04:50 * @return void * @copyright: Copyright (c) 2022 广东七件事集团 */ public function actionWithdrawal() { if (\Yii::$app->request->isAjax) { if (\Yii::$app->request->isGet) { $store = Store::getOne([['id' => $this->store_id]], true, [], false, 'id,user_id,balance'); $user = User::getOne([['id' => $store['user_id']]], true, [], false, 'id,nickname,avatar_url,mobile'); $store_banks = StoreBank::lists(['where' => [['store_id' => $store['id']], ['status' => StatusEnum::ENABLED]], 'id,mall_id,store_id,username,bank,card_no']); $finance = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'finance'); $storeSetting = StoreSettings::findOne(['store_id' => $this->store_id]); //提现条件 if(isset($finance['balance_cash_type'])){ $cashType = json_decode($finance['balance_cash_type'],true); }else{ //默认银行卡/余额提现 $cashType = ['balance','bank']; } $balance_cash_service_fee = 0; // 走的独立设置 if (!empty($storeSetting->is_enable_withdraw_setting)) { $finance['balance_cash_service_fee_limit'] = $storeSetting->balance_cash_service_fee_limit; $finance['balance_cash_service_fee_month'] = $storeSetting->balance_cash_service_fee_month; $finance['balance_cash_service_fee_diff'] = $storeSetting->balance_cash_service_fee_diff; $finance['balance_cash_service_fee'] = $storeSetting->balance_cash_service_fee; } if(!empty($finance['balance_cash_service_fee_limit'])){ $month_start = strtotime(date('Y-m-01 00:00:00')); $month_end = time(); $cash_total = StoreWithdrawLog::find() ->where(['mall_id'=>$this->mall_id,'withdraw_status'=>[0,1],'user_id'=>$store['user_id'],'status'=>StatusEnum::ENABLED]) ->andWhere(['>=','created_at',$month_start]) ->andWhere(['<','created_at',$month_end]) ->andWhere(['!=','type','balance']) ->sum('num') ?? 0; if($cash_total > $finance['balance_cash_service_fee_month']){ $balance_cash_service_fee = $finance['balance_cash_service_fee_diff'] ?? 0; } }else{ if(isset($finance['balance_cash_service_fee'])){ $balance_cash_service_fee = $finance['balance_cash_service_fee'] ?? 0; }else{ $balance_cash_service_fee = \Yii::$app->services->setting->mall->get($this->mall_id, 'withdraw_balance.balance_cash_service_fee'); } } $store['balance_cash_service_fee'] = $balance_cash_service_fee; if (!$cashType) { return $this->error('系统未设置提现方式'); } $cash__type_name = []; $get_system_setting = PlatformSetting::getConfByGroup('system', true); if (!empty($cashType)) { $cash_type = $cashType; $cash__type_name = []; $default_withdraw_way = WithdrawWayEnum::getDefaultWithDrawWayMap(WithdrawWayEnum::WITHDRAW_TYPE_2); $extension_withdraw_way = GlobalInvoke::exec(GlobalInvoke::INVOKE_GET_WITHDRAW_EXTENSION_WAY,$this->mall_id,['mall_id'=>$this->mall_id]); $all_withdraw = array_merge($default_withdraw_way,$extension_withdraw_way); $cash_type_keys = array_keys($all_withdraw); foreach ($cash_type as $i => $item) { if (isset($all_withdraw[$item])) { if (isset($all_withdraw[$item])) { if (is_array($all_withdraw[$item])) { $name = $all_withdraw[$item]['name'] ?? ''; } else { $name = $all_withdraw[$item]; } } $cash__type_name[$i]['type'] = $item; $cash__type_name[$i]['name'] = $name; } } } return $this->success('ok', ['user' => $user, 'store' => $store, 'store_banks' => $store_banks,'cash__type_name'=>$cash__type_name],ApiStatusEnum::CODE_SUCCESS,0); } else { $params = \Yii::$app->request->post('form'); $store = Store::getOne([['id' => $this->store_id]], false, [], false, 'id,mall_id,user_id,balance'); $form = new StoreWithdrawLog(); $params['mall_id'] = $this->mall_id; $params['user_id'] = $store['user_id']; $params['store_id'] = $this->store_id; $form->attributes = $params; $data = $form->saveRecord($params); if ($data['state']) { return $this->success('操作成功', $data['data']); } else { return $this->error($data['msg']); } } } return $this->render($this->action->id); } public function getCashTypeName($user_id){ $cash_type_name = []; $payment = \Yii::$app->services->setting->mall->get($this->mall_id, 'withdraw_balance'); if (!$payment) return $cash_type_name; $cashType = $payment['balance_cash_type']; if(!empty($cashType)) { $cash_type = Json::decode($cashType); $default_withdraw_way = WithdrawWayEnum::getDefaultWithDrawWayMap(WithdrawWayEnum::WITHDRAW_TYPE_2); $extension_withdraw_way = GlobalInvoke::exec(GlobalInvoke::INVOKE_GET_WITHDRAW_EXTENSION_WAY, $this->mall_id, ['mall_id' => $this->mall_id]); $all_withdraw = array_merge($default_withdraw_way, $extension_withdraw_way); $cash_type_keys = array_keys($all_withdraw); $get_system_setting = PlatformSetting::getConfByGroup('system', true); $bank_card_list = []; if (in_array('bank', $cash_type_keys) || in_array('joinpay', $cash_type_keys)) { $bank_card_list = UserBankCard::getUserCardList($user_id, $this->mall_id); } foreach ($cash_type as $i => $item) { if(in_array($item,['alipay_tax'])) continue; if (isset($all_withdraw[$item])) { $taxFee = 0; $name = ''; if (isset($all_withdraw[$item])) { if (is_array($all_withdraw[$item])) { $name = $all_withdraw[$item]['name'] ?? ''; $taxFee = $all_withdraw[$item]['taxFee'] ?? 0; } else { $name = $all_withdraw[$item]; } } $cash_type_name[$i]['type'] = $item; $cash_type_name[$i]['taxFee'] = $taxFee; $cash_type_name[$i]['name'] = $name; $cash_type_name[$i]['img'] = $get_system_setting['api_url']['value'] . '/resources/img/payment/' . $item . '.png'; if ('bank' == $item || 'joinpay' == $item || 'yunfast_pay' == $item) { $cash_type_name[$i]['bank_card_list'] = $bank_card_list; } } } } return $cash_type_name; } //编辑银行卡 public function actionEditStoreBank() { if (\Yii::$app->request->isPost) { $params = \Yii::$app->request->post('form'); $params['mall_id'] = $this->mall_id; $params['store_id'] = $this->store_id; $res = StoreBank::setData($params); if ($res == false) $this->error('操作失败'); return $this->success(); } else { $params = \Yii::$app->request->get(); $store_bank_info = StoreBank::getOne([['id' => $params['id']], ['mall_id' => $this->mall_id], ['store_id' => $this->store_id]], true); return $this->success('ok', ['store_bank_info' => $store_bank_info],ApiStatusEnum::CODE_SUCCESS,0); } } //删除银行卡 public function actionDelStoreBank() { $params = \Yii::$app->request->get(); $params['mall_id'] = $this->mall_id; $params['store_id'] = $this->store_id; $params['status'] = StatusEnum::DELETE; $res = StoreBank::setData($params); if ($res == false) $this->error('操作失败'); return $this->success(); } //编辑汇聚银行卡 public function actionEditStoreBankPay() { if (\Yii::$app->request->isPost) { $post = \Yii::$app->request->post('form'); $rules = [ [['bank_card_no', 'id_no', 'payer_name', 'mobile_no','bank_account_type'], 'required'], ['bank_card_no', 'string', 'max' => 64], [['id_no', 'payer_name',], 'string', 'max' => 255], [['mobile_no'], 'string', 'max' => 32], ]; $res = \Yii::$app->services->validate->validate($post, $rules); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $post['mall_id'] = $this->mall_id; $obj = new BankCardHelper(); $bank_info = $obj->bankInfo($post['bank_card_no']); if(empty($bank_info)) return $this->error('银行卡号有问题'); $bank_info_arr = explode('-',$bank_info); $bankShortList = json_decode($obj->getBankShortList(),true); $bank_code = ''; $bank_name = ''; foreach ($bankShortList as $k=>$v){ if(strpos($v,$bank_info_arr[0])!==false){ $bank_code = $k; $bank_name = $v; break; } } if(empty($bank_name)||empty($bank_code)) return $this->error('无法识别的银行卡号的银行简码'); $post['bank_code'] = $bank_code; $post['bank_name'] = $bank_name; $post['id_type'] = 1; switch ($bank_info_arr[2]){ case '借记卡': $card_type = 'dc'; $card_type_name = '储蓄卡'; break; case '贷记卡': $card_type = 'cc'; $card_type_name = '信用卡'; break; default: return $this->error('无法识别的银行卡号'); } $store = Store::findOne(['id'=>$this->store_id,'status'=>StatusEnum::ENABLED]); if(empty($store)) return $this->error('门店不存在'); $post['user_id'] = $store['user_id']; $post['card_type'] = $card_type; $post['card_type_name'] = $card_type_name; $bank_card_info = UserBankCard::findOne(['mall_id'=>$this->mall_id,'bank_card_no' => $post['bank_card_no'], 'status' => StatusEnum::ENABLED]); if (!empty($bank_card_info)) { return $this->error('银行卡已经被绑定'); } $card_id = StoreBank::addJoinPayBankCard($this->mall_id,$post); try { //调用汇聚接口:发送签约短信 $settings = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_JOIN_PAY, 'basic'); $fast_pay_class = new JoinPayFastPay($settings); $fast_pay_class->sendSignSms($card_id); return $this->success('操作成功', ['card_id' => $card_id]); } catch (\Exception $e) { return $this->error($e->getMessage()); } } else { $params = \Yii::$app->request->get(); $store_bank_info = StoreBank::getOne([['id' => $params['id']], ['mall_id' => $this->mall_id], ['store_id' => $this->store_id]], true); return $this->success('ok', ['store_bank_info' => $store_bank_info],ApiStatusEnum::CODE_SUCCESS,0); } } public function actionGetSmsCode(){ try { $post = \Yii::$app->request->post(); $rules = [ [['card_id'], 'required'], [['card_id'], 'integer'], ]; $res = \Yii::$app->services->validate->validate($post, $rules); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $store = Store::findOne(['id'=>$this->store_id,'status'=>StatusEnum::ENABLED]); if(empty($store)) return $this->error('门店不存在'); $model = UserBankCard::findOne(['id'=>$post['card_id'],'user_id'=>$store['user_id']]); if(empty($model)) return $this->error('用户银行卡不存在'); //调用汇聚接口:发送签约短信 $settings = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_JOIN_PAY, 'basic'); $fast_pay_class = new JoinPayFastPay($settings); $fast_pay_class->sendSignSms($model->id); return $this->success('操作成功', ['card_id' => $model->id]); } catch (\Exception $e) { return $this->error($e->getMessage()); } } //签约 public function actionSignContract() { if (!\Yii::$app->request->isPost) { return $this->error('请求方式错误'); } $post = \Yii::$app->request->post(); $rules = [ [['card_id', 'sms_code'], 'required'], [['card_id'], 'integer'], ['sms_code', 'string'], ]; $res = \Yii::$app->services->validate->validate($post, $rules); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $store = Store::findOne(['id'=>$this->store_id,'status'=>StatusEnum::ENABLED]); if(empty($store)) return $this->error('门店不存在'); $post['user_id'] = $store['user_id']; $card_info = UserBankCard::findOne([ 'mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'id' => $post['card_id'], 'user_id' => $store['user_id'], ]); if (empty($card_info)) return $this->error('银行卡不存在'); $joinpay_card_info = JoinPayUserBankcard::findOne([ 'mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'card_id' => $post['card_id'], 'user_id' => $store['user_id'], ]); if (empty($joinpay_card_info)) { return $this->error('银行卡数据异常'); } if ($joinpay_card_info->is_sign == 1) { return $this->error('银行卡已经签约'); } try { // 签约快捷支付 $settings = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_JOIN_PAY, 'basic'); $fast_pay_class = new JoinPayFastPay($settings); $fast_pay_class->sign($post['card_id'], $post['sms_code']); $card_info = ArrayHelper::toArray($card_info); $card_info['is_sign'] = 1; $card_info['is_auth'] = true; $card_info['icon'] = UserBankCard::getBankPicture($card_info['bank_code'], 'icon'); unset($card_info['cvv'], $card_info['sign_no'], $card_info['payer_name'], $card_info['id_no']); return $this->success('签约成功', ['card_info' => $card_info], ApiStatusEnum::CODE_SUCCESS, 0); } catch (\Exception $e) { return $this->error($e->getMessage()); } } //解约 public function actionContractRelieve() { if (!\Yii::$app->request->isPost) { return $this->error('请求方式错误'); } $post = \Yii::$app->request->post(); $rules = [ [['card_id'], 'required'], [['card_id'], 'integer'], ]; $store = Store::findOne(['id'=>$this->store_id,'status'=>StatusEnum::ENABLED]); if(empty($store)) return $this->error('门店不存在'); $res = \Yii::$app->services->validate->validate($post, $rules); if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage()); $card_info = UserBankCard::findOne([ 'mall_id' => $this->mall_id, 'id' => $post['card_id'], 'status' => StatusEnum::ENABLED, 'user_id' => $store['user_id'], ]); $joinpay_card_info = JoinPayUserBankcard::findOne([ 'mall_id' => $this->mall_id, 'user_id' => $store['user_id'], 'card_id' => $post['card_id'], 'status' => StatusEnum::ENABLED, 'is_sign' => 1, ]); if (empty($card_info) || empty($joinpay_card_info)) { return $this->error('银行卡不存在或者已经解除签约'); }; try { // 解除快捷支付签约 $settings = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_JOIN_PAY, 'basic'); $fast_pay_class = new JoinPayFastPay($settings); $fast_pay_class->unsign($joinpay_card_info); return $this->success('解约成功'); } catch (\Exception $e) { return $this->error($e->getMessage()); } } /** * 提现日志 * @Author bing * @DateTime 2022-04-26 18:04:50 * @return void * @copyright: Copyright (c) 2022 广东七件事集团 */ public function actionWithdrawalLog() { if (\Yii::$app->request->isAjax) { if (\Yii::$app->request->isGet) { $params = \Yii::$app->request->get(); $where[] = ['mall_id' => $this->mall_id]; $where[] = ['store_id' => $this->store_id]; if (!empty($params['start'])) $where[] = ['>=', 'created_at', strtotime($params['start'])]; if (!empty($params['end'])) $where[] = ['<=', 'created_at', strtotime($params['end'])]; if (isset($params['withdraw_status']) && $params['withdraw_status'] !== '') $where[] = ['withdraw_status' => $params['withdraw_status']]; $params['where'] = $where; $params['order'] = 'id desc'; $page_data = StoreWithdrawLog::listPage($params); if ($page_data === false) return $this->error(StoreWithdrawLog::getStaticError()); if (!empty($page_data['list'])) { foreach ($page_data['list'] as &$item) { $item['extra'] = json_decode($item['extra'], true); if('bank' == $item['type']){ if(isset($item['extra']['card_no'])){ $item['extra']['bank_account'] = $item['extra']['card_no']; } if(isset($item['extra']['username'])){ $item['extra']['name'] = $item['extra']['username']; } if(isset($item['extra']['bank'])){ $item['extra']['bank_name'] = $item['extra']['bank']; } } } } return $this->success('ok', $page_data); } } } }