request->isAjax) { if (\Yii::$app->request->isGet) { $get = \Yii::$app->request->get(); $get['mall_id'] = $this->mall_id; $params = []; $user_id_arr = []; if (isset($get['level']) && !empty($get['level'])) $params['where'][] = ['=', 'level', $get['level']]; $is_search = 0; if (!empty($get['user_id'])){ $is_search = 1; $user_id_arr[]=$get['user_id']; } if (!empty($get['keyword'])) { $is_search = 1; $user_list = User::lists(['where'=>[['mall_id'=>$this->mall_id],[ 'or', ['like', 'username', $get['keyword']], ['like', 'nickname', $get['keyword']], ['like', 'mobile', $get['keyword']] ]],'select'=>'id']); $user_ids = array_column($user_list,'id'); if(!empty($user_id_arr)){ $user_id_arr = array_intersect($user_id_arr,$user_ids); }else{ $user_id_arr = $user_ids; } } if($is_search)$params['where'][] = ['in', 'user_id', $user_id_arr]; $params['where'][] = ['=', 'mall_id',$this->mall_id]; $params['where'][] = ['in', 'status', [StatusEnum::ENABLED, StatusEnum::DISABLED]]; $params['limit'] = 10; $params['order'] = 'id DESC'; $pageData = Agent::listPage($params, false); if ($pageData === false) return $this->error(Agent::getStaticError()); if(!empty($pageData['list'])){ $user_id_arr = array_column($pageData['list'],'user_id'); $user_list = $user_list = User::lists(['where'=>[['id'=>$user_id_arr]],'select'=>'id,nickname,avatar_url,mobile,parent_id']); $user_arr = $parent_arr = []; $parent_id_arr = []; foreach ($user_list as $item){ $parent_id_arr[]=$item['parent_id']; $user_arr[$item['id']] = $item; } $user_parent_list = $user_list = User::lists(['where'=>[['id'=>$parent_id_arr]],'select'=>'id,nickname,avatar_url,mobile']); foreach ($user_parent_list as $item){ $parent_arr[$item['id']] = $item; } $province_ids = array_column($pageData['list'], 'province_id') ?? []; $region_list = Region::lists([ 'where' => [ ['id' => $province_ids] ], 'select' => 'id, name, level', 'index' => 'id' ]); foreach ($pageData['list'] as &$v) { $v['nickname'] = $v['avatar_url'] = $v['parent_id'] = $v['parent_name'] = $v['mobile'] = ''; if (isset($user_arr[$v['user_id']])) { $v['mobile'] = $user_arr[$v['user_id']]['mobile']; $v['nickname'] = $user_arr[$v['user_id']]['nickname']; $v['avatar_url'] = $user_arr[$v['user_id']]['avatar_url']; $v['parent_id'] = $user_arr[$v['user_id']]['parent_id']; if (isset($parent_arr[$v['parent_id']])) { $v['parent_name'] = $parent_arr[$v['parent_id']]['nickname']; } $v['provinceinfo'] = $region_list[$v['province_id']] ?? []; } } } $args = []; $args['where'] = [['mall_id' => $this->mall_id], ['<>', 'status', StatusEnum::DELETE]]; $args['select'] = 'id,level,name'; $args['order'] = 'level asc'; $level_list = AgentLevel::lists($args, true); if (empty($level_list)) $level_list = [['id' => 0, 'level' => 0, 'name' => '默认等级']]; $pageData['agentLevelList'] = $level_list; $pageData['export_list'] = Agent::exportFieldsList(); $configs = \Yii::$app->services->setting->addons->get($this->mall_id, AgentEnum::ADDONS_NAME, 'basic'); $pageData['is_enable_province'] = $configs['is_enable_province'] ?? 0; return $this->success('操作成功', $pageData); } } // if (\Yii::$app->request->post('flag') == 'EXPORT') { // $post = \Yii::$app->request->post(); // $post['mall_id'] = $this->mall_id; // $filename = '经销商列表-' . date('YmdHis') . '_' . rand(10000, 99999); // $res = CsvExportHelper::exportDownLoadCenter($this->mall_id, $filename, DownloadEnum::TYPE_AGENT, Agent::class, 'exportHandle', $post); // if ($res === false) return $this->error('加入导出任务失败' . CsvExportHelper::getStaticError()); // return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!'); // } return $this->render('index', []); } public function actionExport() { if (\Yii::$app->request->post('flag') == 'EXPORT') { $post = \Yii::$app->request->post(); $post['mall_id'] = $this->mall_id; $filename = '经销商列表-' . date('YmdHis') . '_' . rand(10000, 99999); $res = CsvExportHelper::exportDownLoadCenter($this->mall_id, $filename, DownloadEnum::TYPE_AGENT, Agent::class, 'exportHandle', $post); if ($res === false) return $this->error('加入导出任务失败' . CsvExportHelper::getStaticError()); return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!'); } } /** * @desc:修改经销商等级 * @Author: hua * @Date: 2021/10/23 * @Time: 17:33 * @Copyright: copyright (c) 2021 广东七件事集团 * @return mixed|void */ public function actionLevelChange() { if (\Yii::$app->request->isAjax) { if (\Yii::$app->request->isPost) { $params = \Yii::$app->request->post(); $res = Yii::$app->services->validate->validate($params, [ [['id', 'user_id', 'level'], 'required'], [['user_id', 'level'], 'integer'], [['provinceinfo'], 'safe'] ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $model = Agent::findOne(['mall_id' => $this->mall_id, 'id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]); $params['mall_id'] = $this->mall_id; $provinceinfo = $params['provinceinfo']; unset($params['provinceinfo']); $params['province_id'] = $provinceinfo['id'] ?? 0; $params['admin_id'] = $this->admin->id; $res = Agent::setData($params); if ($res === false) return $this->error(AgentLevel::getStaticError()); //会员标签 \Yii::$app->services->rabbitMq->push(RabbitMqEnum::EXCHANGE_TASK, RabbitMqEnum::TASK_QUEUE, [ 'user_id'=>$params['user_id'], 'mall_id'=>$params['mall_id'], 'cate_ids'=>[MemberLabelEnum::AGENT_LEVEL] ], MemberLabelLogic::class, 'executeSyncCateId2Or3'); $event = new AgentUpgradeAfterEvent($this->mall_id); Yii::$app->services->events->dispatch( $event, [ 'user_id' => $params['user_id'], 'mall_id' => $this->mall_id, 'after_level' => $params['level'], 'before_level' => $model->level, 'is_admin' => 1, 'operator_user_id' => $this->admin->id, 'agent_id' => $params['id'] ], $event->listeners ); // 记录更新区域行为 if ($params['province_id'] != $model->province_id) { AgentBehaviorLogsService::dispatchUserBehaviorLogsEvent( $event->mall_id ?? 0, [ 'user_id' => $params['user_id'], 'mall_id' => $this->mall_id, 'after_province_id' => $params['province_id'], 'before_province_id' => $model->province_id, 'is_admin' => 1, 'operator_user_id' => $this->admin->id, 'agent_id' => $params['id'], 'behavior' => AgentBehaviorLogsEnum::BEHAVIOR_MODIFY_AGENT_PROVINCE ] ); } return $this->success('操作成功'); } } return $this->error(); } /** * @desc:修改备注 * @Author: hua * @Date: 2021/10/23 * @Time: 17:29 * @Copyright: copyright (c) 2021 广东七件事集团 * @return mixed|void */ public function actionRemarksEdit() { if (\Yii::$app->request->isAjax) { if (\Yii::$app->request->isPost) { $params = \Yii::$app->request->post(); $res = Yii::$app->services->validate->validate($params, [ [['id', 'user_id'], 'required'], [['user_id'], 'integer'], [['remarks'], 'safe'] ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $params['mall_id'] = $this->mall_id; $res = Agent::setData($params); if ($res === false) return $this->error(Agent::getStaticError()); return $this->success('操作成功'); } } return $this->error(); } /** * @desc:搜索用户 * @Author: hua * @Date: 2021/10/23 * @Time: 17:55 * @Copyright: copyright (c) 2021 广东七件事集团 * @return mixed|void */ public function actionSearchUser() { if (\Yii::$app->request->isAjax) { $keyword = \Yii::$app->request->get('keyword', ''); $params = ['keyword' => $keyword, 'mall_id' => $this->mall_id]; $query = User::find()->alias('u') ->where(['u.status' => StatusEnum::ENABLED, 'u.mall_id' => $params['mall_id']]) ->andWhere(['u.is_inviter' => 1]); if (isset($params['keyword']) && !empty($params['keyword'])) { $query->andWhere(['or', ['like', 'nickname', $params['keyword']], ['like', 'mobile', $params['keyword']], ['like', 'id', $params['keyword']]]); } $list = $query->limit(20)->select('u.id,u.nickname,u.mobile,u.avatar_url')->asArray()->all(); foreach ($list as &$item) { if (empty($item['nickname'])) { $item['nickname'] = $item['mobile'] . "(id:{$item['id']})"; } } $list['list'] = $list; return $this->success('操作成功', $list); } return $this->error(); } /** * @desc:保存经销商 * @Author: hua * @Date: 2021/10/23 * @Time: 17:39 * @Copyright: copyright (c) 2021 广东七件事集团 * @return mixed|void */ public function actionEdit() { if (\Yii::$app->request->isAjax) { if (\Yii::$app->request->isPost) { $postData = \Yii::$app->request->post(); $res = Yii::$app->services->validate->validate($postData, [ [['user_id', 'level'], 'required'], [['user_id', 'level'], 'integer'] ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $wheres = [ 'user_id' => $postData['user_id'], 'mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, ]; $model = Agent::findOne($wheres); if (!empty($model)) return $this->error('该会员已经是经销商,不能重复添加'); $postData['mall_id'] = $this->mall_id; $postData['status'] = StatusEnum::ENABLED; $postData['admin_id'] = $this->admin->id; $res = Agent::setData($postData); if ($res === false) return $this->error(Agent::getStaticError()); //会员标签 \Yii::$app->services->rabbitMq->push(RabbitMqEnum::EXCHANGE_TASK, RabbitMqEnum::TASK_QUEUE, [ 'user_id'=>$postData['user_id'], 'mall_id'=>$postData['mall_id'], 'cate_ids'=>[MemberLabelEnum::AGENT_LEVEL] ], MemberLabelLogic::class, 'executeSyncCateId2Or3'); $event = new AgentAddEvent($this->mall_id); Yii::$app->services->events->dispatch( $event, [ 'user_id' => $res->user_id, 'mall_id' => $this->mall_id, 'is_admin' => 1, 'operator_user_id' => $this->admin->id, 'agent_id' => $res->id, 'level' => $res->level ], $event->listeners ); return $this->success('操作成功'); } } return $this->error(); } /** * @desc:删除经销商 * @Author: hua * @Date: 2021/10/23 * @Time: 17:24 * @Copyright: copyright (c) 2021 广东七件事集团 * @return mixed|void */ public function actionDelete() { if (\Yii::$app->request->isAjax) { if (\Yii::$app->request->isPost) { $params = \Yii::$app->request->post(); $res = Yii::$app->services->validate->validate($params, [ [['id'], 'required'], [['id'], 'integer'] ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $params['mall_id'] = $this->mall_id; $params['status'] = StatusEnum::DELETE; $res = Agent::setData($params); if ($res === false) return $this->error(Agent::getStaticError()); $event = new AgentDeleteEvent($this->mall_id); Yii::$app->services->events->dispatch( $event, [ 'user_id' => $res->user_id, 'mall_id' => $this->mall_id, 'is_admin' => 1, 'operator_user_id' => $this->admin->id, 'agent_id' => $params['id'] ], $event->listeners ); return $this->success('操作成功'); } } return $this->error(); } /** * @desc:批量修改等级 * @Author: hua * @Date: 2021/10/23 * @Time: 17:43 * @Copyright: copyright (c) 2021 广东七件事集团 * @return mixed|void */ public function actionBatchLevel() { if (\Yii::$app->request->isAjax) { if (\Yii::$app->request->isPost) { $params = \Yii::$app->request->post(); $res = Yii::$app->services->validate->validate($params, [ [['batch_ids', 'level'], 'required'], [['level'], 'integer'] ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $params['mall_id'] = $this->mall_id; $params['status'] = StatusEnum::ENABLED; $agentBeforeLevelList = Agent::find() ->where(['id' => $params['batch_ids']]) ->select('id, level, user_id') ->indexBy('id') ->asArray() ->all(); $res = Agent::batchLevel($params); if ($res === false) return $this->error(Agent::getStaticError()); foreach ($params['batch_ids'] as $batchId) { if (!isset($agentBeforeLevelList[$batchId])) { continue; } $event = new AgentUpgradeAfterEvent($this->mall_id); Yii::$app->services->events->dispatch( $event, [ 'user_id' => $agentBeforeLevelList[$batchId]['user_id'], 'mall_id' => $this->mall_id, 'after_level' => $params['level'], 'before_level' => $agentBeforeLevelList[$batchId]['level'], 'is_admin' => 1, 'operator_user_id' => $this->admin->id, 'agent_id' => $batchId ], $event->listeners ); } return $this->success('操作成功'); } } return $this->error(); } /** * 经销商配置 */ public function actionSetting() { if (\Yii::$app->request->isAjax) { return $this->error(); } return $this->render('setting'); } /** * @desc:已经启用的等级 * @Author: hua * @Date: 2021/10/23 * @Time: 17:31 * @Copyright: copyright (c) 2021 广东七件事集团 * @return mixed|void */ public function actionEnableList() { if (\Yii::$app->request->isAjax) { if (\Yii::$app->request->isGet) { $level = \Yii::$app->request->get('level'); $where = [['mall_id' => $this->mall_id], ['=', 'status', StatusEnum::ENABLED]]; if (!empty($level)) $where[] = ['level' => $level]; $args['where'] = $where; $args['select'] = 'id,level,name'; $args['order'] = 'level asc'; $list['list'] = AgentLevel::lists($args, true); return $this->success('操作成功', $list); } } return $this->error(); } public function actionGetProvinces() { if (\Yii::$app->request->isAjax) { if (\Yii::$app->request->isGet) { $list = Region::lists([ 'where' => [ ['level' => 1] ], 'select' => 'id,name,lng,lat', ]); return $this->success('操作成功', $list); } } } public function actionCommissionBasicLog() { if (\Yii::$app->request->isAjax) { if (\Yii::$app->request->isGet) { $get = \Yii::$app->request->get(); $get['mall_id'] = $this->mall_id; $params = []; if (!empty($get['source_table_id'])) { $params['where'][] = ['source_table_id'=> $get['source_table_id']]; } $params['where'][] = ['=', 'mall_id',$this->mall_id]; $params['where'][] = ['in', 'status', [StatusEnum::ENABLED, StatusEnum::DISABLED]]; $params['order'] = 'id desc'; $params['limit'] = 10; $pageData = AgentCommissionBasisLog::listPage($params, false); if ($pageData === false) return $this->error(AgentCommissionBasisLog::getStaticError()); if(!empty($pageData['list'])){ foreach ($pageData['list'] as &$item){ if($item['basic_config']) $item['basic_config'] = json_encode(json_decode($item['basic_config'],true),JSON_UNESCAPED_UNICODE); if($item['level_config']) $item['level_config'] = json_encode(json_decode($item['level_config'],true),JSON_UNESCAPED_UNICODE); if($item['goods_config']) $item['goods_config'] = json_encode(json_decode($item['goods_config'],true),JSON_UNESCAPED_UNICODE); } } return $this->success('操作成功', $pageData); } } return $this->render('commission-basic-log', []); } public function actionGoodsModeSetting() { $request = Yii::$app->request; if ($request->isAjax && $request->isPost) { $is_install_regular_bonus = (int)MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_REGULAR_BONUS); return $this->success('操作成功', compact('is_install_regular_bonus')); } } /** * 供应商库存 * @Author:hua * @Date:2024-02-22 17:53 * @Copyright:copyright(c)2024 广东七件事集团 * @return mixed|string|void */ public function actionSupplierStock(){ if (\Yii::$app->request->isAjax) { if (\Yii::$app->request->isGet) { $get = \Yii::$app->request->get(); $get['mall_id'] = $this->mall_id; $params = []; if (isset($get['level']) && !empty($get['level'])) $params['where'][] = ['=', 'level', $get['level']]; if (!empty($get['keyword'])) { $user_list = User::lists(['where'=>[['mall_id'=>$this->mall_id],[ 'or', ['=', 'id', $get['keyword']], ['like', 'username', $get['keyword']], ['like', 'nickname', $get['keyword']], ['like', 'mobile', $get['keyword']] ]],'select'=>'id']); $user_ids = array_column($user_list,'id'); $params['where'][] = ['in', 'user_id', $user_ids]; } $params['where'][] = ['=', 'mall_id',$this->mall_id]; $params['where'][] = ['in', 'status', [StatusEnum::ENABLED, StatusEnum::DISABLED]]; $params['limit'] = 10; $params['order'] = 'id DESC'; $pageData = Agent::listPage($params, false); if ($pageData === false) return $this->error(Agent::getStaticError()); if(!empty($pageData['list'])){ $user_id_arr = array_column($pageData['list'],'user_id'); $user_list = User::lists(['where'=>[['id'=>$user_id_arr]],'select'=>'id,nickname,avatar_url,mobile,parent_id']); $user_arr = []; foreach ($user_list as $item){ $user_arr[$item['id']] = $item; } $dsn = Yii::$app->db->dsn; if(strpos($dsn,'port=8066')===false){ $commission_log_list = CommissionLog::lists([ 'where'=>[ ['user_id'=>$user_id_arr], ['from_type'=>'Agent'] ], 'select'=>'sum(change_num) as change_num,user_id', 'group'=>'user_id', 'index'=>'user_id' ]); $commission_log_count_list = CommissionLog::lists([ 'where'=>[ ['user_id'=>$user_id_arr], ['from_type'=>'Agent'] ], 'select'=>'count(*) counts,user_id', 'group'=>'user_id', 'index'=>'user_id' ]); } foreach ($pageData['list'] as &$v) { $v['nickname'] = $v['avatar_url'] = $v['mobile'] = ''; if (isset($user_arr[$v['user_id']])) { $v['mobile'] = $user_arr[$v['user_id']]['mobile']; $v['nickname'] = $user_arr[$v['user_id']]['nickname']; $v['avatar_url'] = $user_arr[$v['user_id']]['avatar_url']; } $v['change_num'] = $v['counts'] = 0; if(strpos($dsn,'port=8066')===false){ if (isset($commission_log_list[$v['user_id']])) { $v['change_num'] = $commission_log_list[$v['user_id']]['change_num']; } if (isset($commission_log_count_list[$v['user_id']])) { $v['counts'] = $commission_log_count_list[$v['user_id']]['counts']; } }else{ $change_num = CommissionLog::find()->where(['user_id'=>$v['user_id'],'from_type'=>'Agent'])->sum('change_num'); if(!empty($change_num)) $v['change_num'] = $change_num; $counts = CommissionLog::find()->where(['user_id'=>$v['user_id'],'from_type'=>'Agent'])->count(); if(!empty($counts)) $v['counts'] = $counts; } } } $args = []; $args['where'] = [['mall_id' => $this->mall_id], ['<>', 'status', StatusEnum::DELETE]]; $args['select'] = 'id,level,name'; $args['order'] = 'level asc'; $level_list = AgentLevel::lists($args, true); if (empty($level_list)) $level_list = [['id' => 0, 'level' => 0, 'name' => '默认等级']]; $pageData['agentLevelList'] = $level_list; $pageData['export_list'] = Agent::getSupplierStockExportFieldsList(); return $this->success('操作成功', $pageData); } if (\Yii::$app->request->post('flag') == 'EXPORT') { $post = \Yii::$app->request->post(); $post['mall_id'] = $this->mall_id; $filename = '供应商库存-' . date('YmdHis') . '_' . rand(10000, 99999); $res = CsvExportHelper::exportDownLoadCenter($this->mall_id, $filename, DownloadEnum::TYPE_AGENT, Agent::class, 'exportHandleSupplierStock', $post); if ($res === false) return $this->error('加入导出任务失败' . CsvExportHelper::getStaticError()); return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!'); } } return $this->render('supplier-stock', []); } /** * 供应商订单 * @Author:hua * @Date:2024-02-22 17:53 * @Copyright:copyright(c)2024 广东七件事集团 * @return mixed|string|void */ public function actionSupplierOrder(){ if (\Yii::$app->request->isAjax) { if (\Yii::$app->request->isGet) { $get = \Yii::$app->request->get(); $get['mall_id'] = $this->mall_id; $params = ['where' => [['status' => StatusEnum::ENABLED]]]; if (!empty($get['order_no'])){ $params['where'][] = ['=', 'order_no', trim($get['order_no'])]; } if (!empty($get['keyword'])) { $user_list = User::lists(['where'=>[['mall_id'=>$this->mall_id],[ 'or', ['=', 'id', $get['keyword']], ['like', 'username', $get['keyword']], ['like', 'nickname', $get['keyword']], ['like', 'mobile', $get['keyword']] ]],'select'=>'id']); $user_ids = array_column($user_list,'id'); $params['where'][] = ['in', 'buy_user_id', $user_ids]; } if (!empty($get['seller_keyword'])) { $user_list = User::lists(['where'=>[['mall_id'=>$this->mall_id],[ 'or', ['=', 'id', $get['seller_keyword']], ['like', 'username', $get['seller_keyword']], ['like', 'nickname', $get['seller_keyword']], ['like', 'mobile', $get['seller_keyword']] ]],'select'=>'id']); $user_ids = array_column($user_list,'id'); $params['where'][] = ['in', 'seller_user_id', $user_ids]; } $params['where'][] = ['=', 'mall_id',$this->mall_id]; $params['limit'] = 10; $params['order'] = 'id DESC'; $pageData = AgentSupplierOrder::listPage($params, false); if ($pageData === false) return $this->error(Agent::getStaticError()); if(!empty($pageData['list'])){ $buy_user_ids = array_column($pageData['list'],'buy_user_id'); $seller_user_ids = array_column($pageData['list'],'seller_user_id'); $order_no_arr = array_column($pageData['list'],'order_no'); $user_id_arr = array_merge($buy_user_ids,$seller_user_ids); $user_arr = User::lists(['where'=>[['id'=>$user_id_arr]],'index'=>'id','select'=>'id,nickname,avatar_url,mobile,parent_id']); $order_arr = Order::lists(['where'=>[['order_no'=>$order_no_arr]],'index'=>'order_no','select'=>'order_no,order_status']); foreach ($pageData['list'] as &$v) { $v['nickname'] = $v['avatar_url'] = $v['mobile'] = ''; $v['seller_nickname'] = $v['seller_avatar_url'] = $v['seller_mobile'] = ''; $v['order_status'] = 0; if (isset($user_arr[$v['buy_user_id']])) { $v['mobile'] = $user_arr[$v['buy_user_id']]['mobile']; $v['nickname'] = $user_arr[$v['buy_user_id']]['nickname']; $v['avatar_url'] = $user_arr[$v['buy_user_id']]['avatar_url']; } if (isset($order_arr[$v['order_no']])) { $v['order_status'] = $order_arr[$v['order_no']]['order_status']; } if (isset($user_arr[$v['seller_user_id']])) { $v['seller_mobile'] = $user_arr[$v['seller_user_id']]['mobile']; $v['seller_nickname'] = $user_arr[$v['seller_user_id']]['nickname']; $v['seller_avatar_url'] = $user_arr[$v['seller_user_id']]['avatar_url']; } } } $args = []; $args['where'] = [['mall_id' => $this->mall_id], ['<>', 'status', StatusEnum::DELETE]]; $args['select'] = 'id,level,name'; $args['order'] = 'level asc'; $level_list = AgentLevel::lists($args, true); if (empty($level_list)) $level_list = [['id' => 0, 'level' => 0, 'name' => '默认等级']]; $pageData['agentLevelList'] = $level_list; $pageData['export_list'] = AgentSupplierOrder::exportFieldsList(); $cache_key = RedisKeyEnum::suffix(AgentSupplierOrder::OLD_DATA_GENERATE_, $this->mall_id); $cache = \Yii::$app->cache; $cache_data = $cache->get($cache_key); $pageData['is_generate_old_data'] = $cache_data ?? 0; return $this->success('操作成功', $pageData); } if (\Yii::$app->request->post('flag') == 'EXPORT') { $post = \Yii::$app->request->post(); $post['mall_id'] = $this->mall_id; $filename = '供应商订单-' . date('YmdHis') . '_' . rand(10000, 99999); $res = CsvExportHelper::exportDownLoadCenter($this->mall_id, $filename, DownloadEnum::TYPE_AGENT, AgentSupplierOrder::class, 'exportHandle', $post); if ($res === false) return $this->error('加入导出任务失败' . CsvExportHelper::getStaticError()); return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!'); } } return $this->render('supplier-order', []); } /** * 生成旧数据 * @Author:hua * @Date:2024-02-23 15:44 * @Copyright:copyright(c)2024 广东七件事集团 * @return mixed|void */ public function actionOldDataGenerate(){ $data = ['mall_id'=>$this->mall_id]; \Yii::$app->services->rabbitMq->push(RabbitMqEnum::EXCHANGE_TASK, RabbitMqEnum::TASK_QUEUE, $data, AgentSupplierOrder::class, 'oldDataGenerate'); return $this->success('操作成功', []); } /** * 导入日志记录 * @return mixed|void */ public function actionGetImportLevelLog() { $params = \Yii::$app->request->get(); $params['where'] = [ ['mall_id'=>$this->mall_id] ]; $params['order'] = 'id desc'; $data = AgentImportLevelLog::listPage($params, false, true); if (!empty($data['list'])) { foreach ($data['list'] as &$v) { $v['url'] = ''; if ($v['fail_counts']) $v['url'] = \Yii::$app->urlManager->createUrl(['agent/default/export-level-fail', 'log_id' => $v['id']]); } } return $this->success('操作成功', $data); } /** * 导出失败日志 */ public function actionExportLevelFail() { AgentImportLevelFailLog::exportFailLog(\Yii::$app->request->get()); } /** * 会员批量导入模板下载 */ public function actionImportLevelModel() { $csv = new CsvExport(); $file_name = '批量导入经销商等级模板-' . date('YmdHis', time()); $head_list = array_column(Agent::$head_list, 'field_name'); return $csv->export([], $head_list, $file_name); } /** * 批量导入等级 * @return mixed|string|void */ public function actionImportLevel() { set_time_limit(0); if (\Yii::$app->request->isAjax) { $params = \Yii::$app->request->post(); $res = Yii::$app->services->validate->validate($params, [ [['current_num'], 'required'], [['file'], 'file', 'extensions' => ['csv']], [['file_path'], 'string'], [['sync'], 'safe'], ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $params['mall_id'] = $this->mall_id; if(!empty($params['sync'])){ $res = Agent::importLevelSync($params); }else{ $res = Agent::importLevel($params); } if (empty($res['fail_counts'])) return $this->success('操作成功', $res); if (!empty($res['fail_counts'])) return $this->error('导入失败'.$res['fail_counts'].'条'); return $this->error(Agent::getStaticError()); } else { return $this->render($this->action->id); } } /** * 供应商收入列表 * * @return string|void */ public function actionSupplierCommission() { $service = new AgentSupplierCommissionService([]); $service->mall_id = $this->mall_id; if (!$this->request->isAjax) { return $this->render($this->action->id, ['allowDeliveryTask' => (int)$service->allowDeliveryTask()]); } $this->success('success', $service->getList($this->request->get(), false)); } /** * 供应商收入导出 * * @return void */ public function actionSupplierCommissionExport() { $filename = '供应商收入数据-' . date('YmdHis') . '_' . random_int(10000, 99999); $data = Yii::$app->request->post('params'); $data['mall_id'] = $this->mall_id; $res = CsvExportHelper::exportDownLoadCenter( $this->mall_id, $filename, DownloadEnum::TYPE_AGENT_SUPPLIER_COMMISSION, AgentSupplierCommissionService::class, 'export', $data ); if ($res === false) { return $this->error('加入导出任务失败' . CsvExportHelper::getStaticError()); } return $this->success('添加导出任务成功,任务完成后请在下载中心进行下载!'); } /** * @return mixed|null * @throws Exception */ public function actionSyncOldData() { // 检查是否允许投递 $service = new AgentSupplierCommissionService([]); $service->mall_id = $this->mall_id; if (!$service->allowDeliveryTask()) { return $this->error('当前已同步数据'); } AgentSupplierCommissionSyncLog::setData([ 'mall_id' => $this->mall_id, 'status' => StatusEnum::DISABLED ]); $data = ['mall_id'=>$this->mall_id]; \Yii::$app->services->rabbitMq->push(RabbitMqEnum::EXCHANGE_LONG_DURATION, RabbitMqEnum::LONG_DURATION_QUEUE, $data, AgentSupplierCommissionService::class, 'syncOldData'); return $this->success(); } /** * 经销商日志 * * @return mixed|string|null */ public function actionLog() { if (!$this->request->isAjax) { foreach (AgentBehaviorLogsEnum::OPERATOR_USER_TYPE_MAP as $value => $label) { $operatorUserTypeOptions[] = compact('label', 'value'); } foreach (AgentBehaviorLogsEnum::BEHAVIOR_MAP as $value => $label) { $behaviorOptions[] = compact('label', 'value'); } $operatorUserTypeOptions = json_encode($operatorUserTypeOptions); $behaviorOptions = json_encode($behaviorOptions); return $this->render($this->action->id, compact('operatorUserTypeOptions', 'behaviorOptions')); } $service = new LogsServices(['mall_id' => $this->mall_id]); return $this->success('success', $service->getAgentLogs($this->request->get())); } /** * 获取订单details列表 * * @return void */ public function actionGetOrderDetails() { $this->success( 'success', (new OrderService(['mall_id' => $this->mall_id]))->getOrderDetails($this->request->get()) ); } /** * 重新分配佣金 * * @return void */ public function actionRedistributeCommissions() { if (!$this->request->isPost) { $this->error('请求类型错误'); return; } $post = $this->request->post(); $res = Yii::$app->services->validate->validate($post, [ [['order_details_ids'], 'required'], ['order_details_ids', 'each', 'rule' => ['integer']], ]); if ($res === false) { return $this->error(Yii::$app->services->validate->getErrorMessage()); } $service = new AgentSupplierCommissionService(['mall_id' => $this->mall_id]); if ($service->redistributeCommissions($post)) { $this->success('success'); return; } $this->error($service->getError()); } }