| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670 |
- <?php
- namespace addons\Area\api\modules\v1\controllers;
- use addons\Area\common\enums\AreaEnum;
- use addons\Area\common\models\AreaAgent;
- use addons\Area\common\models\AreaApply;
- use addons\Area\common\models\AreaCommunity;
- use addons\Area\common\models\AreaGoods;
- use addons\Area\common\models\AreaOrder;
- use addons\Store\common\models\StoreOrderDetail;
- use common\enums\AddonsEnum;
- use common\enums\ApiStatusEnum;
- use common\enums\StatusEnum;
- use common\enums\UserWalletEnum;
- use common\helpers\ArrayHelper;
- use common\models\common\CapitalLog;
- use common\models\common\Region;
- use common\models\order\OrderDetail;
- use common\models\user\Town;
- use common\models\user\User;
- use common\models\user\UserPartitionRelationship;
- use Couchbase\DesignDocument;
- use Yii;
- use api\controllers\OnAuthController;
- use Exception;
- /**
- * 默认控制器
- *
- * Class DefaultController
- * @package addons\Area\api\modules\v1\controllers
- */
- class DefaultController extends OnAuthController
- {
- public $modelClass = '';
- /**
- * 不用进行登录验证的方法
- *
- * 例如: ['index', 'update', 'create', 'view', 'delete']
- * 默认全部需要验证
- *
- * @var array
- */
- protected $authOptional = ['index'];
- protected $level_id_arr = [AreaEnum::PROVINCE => 'province_id', AreaEnum::CITY => 'city_id', AreaEnum::DISTRICT => 'district_id', AreaEnum::TOWN => 'town_id'];
- /**
- * @desc:区域管理中心
- * @Author: hua
- * @Date: 2022/1/20
- * @Time: 16:07
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|void
- */
- public function actionCenter()
- {
- $user_id = $this->user_id;
- $area_agent = AreaAgent::getOne([['mall_id' => $this->mall_id], ['user_id' => $user_id],['status'=>StatusEnum::ENABLED]], true, ['user']);
- $show_tips = '';
- if (empty($area_agent)) $show_tips = '请先申请区域代理';
- $wallet_type = 'commission';
- $data = CapitalLog::getSummary($user_id, $wallet_type, AreaEnum::ADDONS_NAME);
- $data['user'] = User::find()
- ->select('id, nickname, avatar_url')
- ->where(['id' => $this->user_id, 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]])
- ->asArray()->one();
- $areaAgent = AreaAgent::find()
- ->select('id, user_id, level, address, created_at')
- ->where(['user_id' => $this->user_id, 'mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
- ->with([
- 'user' => function ($query) {
- $query->select('id, nickname, avatar_url');
- }
- ])
- ->asArray()->all();
- $area_agents = [];
- $data['level_map'] = AreaEnum::getLevelMap(null, $this->mall_id);
- $area_agent_list = AreaAgent::find()->where(['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED], 'mall_id' => $this->mall_id])
- ->select('level, count(id) as counts')
- ->groupBy('level')
- ->indexBy('level')
- ->asArray()->all();
- foreach ($data['level_map'] as $k => $v) {
- if (empty($k)) continue;
- if (isset($area_agent_list[$k])) {
- $area_agents[] = array_merge($area_agent_list[$k], ['name' => $v]);
- }else {
- $area_agents[] = ['level' => $k, 'counts' => 0, 'name' => $v];
- }
- }
- if (!empty($areaAgent)) {
- foreach ($areaAgent as &$item) {
- $item['created_at'] = date("Y-m-d H:i:s", $item['created_at']);
- }
- }
- if (isset($data['level_map'][6])) unset($data['level_map'][6]);
- $data['area_agent_list'] = $areaAgent ?? [];
- $data['area_agents'] = $area_agents ?? [];
- $data['show_tips'] = $show_tips;
- $result = AreaAgent::getIncomeInfo(['user_id' => $user_id, 'mall_id' => $this->mall_id, 'addons_name' => AddonsEnum::ADDONS_NAME_AREA]);
- $data['total_income'] = $result['total_commission'];
- $config = \Yii::$app->services->setting->addons->get($this->mall_id, AreaEnum::ADDONS_NAME, 'basic');
- $data['is_enable_apply'] = $config['is_enable_apply'] ?? StatusEnum::ENABLED;
- $data['protocol'] = $config['protocol'] ?? "";
- $data['is_buy_area'] = $config['is_buy_area'] ?? StatusEnum::DISABLED;
- return $this->success('成功', $data);
- }
- /**
- * @desc:奖励列表
- * @Author: hua
- * @Date: 2021/11/4
- * @Time: 17:00
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|void
- */
- public function actionLogList()
- {
- $params = \Yii::$app->request->get();
- $wallet_type = 'commission';
- if(!empty($params['list_type'])&&$params['list_type'] ==1){//未结算
- $wallet_type = 'commission_frozen';
- $params['status'] = StatusEnum::DISABLED;
- }
- $params['mall_id'] = $this->mall_id;
- $params['user_id'] = $this->user_id;
- $list = CapitalLog::getCapitalLogList($params, $wallet_type, AreaEnum::ADDONS_NAME, ', change_type');
- if (!empty($list)) {
- foreach ($list['list'] as &$item) {
- $item['status'] = 1;
- if(!empty($params['list_type'])&&$params['list_type'] ==1){
- $item['status'] = 0;
- }
- }
- }
- $list['capital_type_map'] = UserWalletEnum::getCapitalTypeMapByCommission();
- return $this->success('成功', $list);
- }
- /**
- * @desc:我的代理
- * @Author: hua
- * @Date: 2022/1/20
- * @Time: 16:37
- * @Copyright: copyright (c) 2021 广东七件事集团
- */
- public function actionGetChildrenList()
- {
- $child_ids = UserPartitionRelationship::getChildIdArr($this->user_id);
- $params = Yii::$app->request->get();
- $where = [['mall_id' => $this->mall_id], ['user_id' => $child_ids], ['status' => StatusEnum::ENABLED]];
- $where[] = !empty($params['level']) ? ['level' => $params['level']] : ['level' => AreaEnum::PROVINCE];
- $params['where'] = $where;
- $params['with'] = ['user' => function ($query) {
- $query->select('id,avatar_url,nickname,mobile');
- }];
- $params['select'] = 'id,user_id,address,level';
- $list = AreaAgent::listPage($params);
- $list['level_map'] = AreaEnum::getLevelMap(null, $this->mall_id);
- $area_agents = [];
- $area_agent_list = AreaAgent::lists(['where' => [['mall_id' => $this->mall_id], ['status' => StatusEnum::ENABLED], ['user_id' => $child_ids]], 'group' => 'level', 'select' => 'level,count(*) counts', 'index' => 'level']);
- foreach ($list['level_map'] as $k => $v) {
- if (empty($k)) continue;
- if (isset($area_agent_list[$k])) {
- $area_agents[] = array_merge($area_agent_list[$k], ['name' => $v]);
- }else {
- $area_agents[] = ['level' => $k, 'counts' => 0, 'name' => $v];
- }
- }
- if (isset($list['level_map'][6])) unset($list['level_map'][6]);
- $list['area_agents'] = $area_agents;
- return $this->success('成功', $list);
- }
- /**
- * @desc:获取区域列表
- * @Author: hua
- * @Date: 2022/1/20
- * @Time: 16:07
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|void
- */
- public function actionGetRegion()
- {
- $params = Yii::$app->request->get();
- $res = Yii::$app->services->validate->validate($params, [
- [['parent_id'], 'integer']
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- if (empty($params['parent_id'])) {
- $region = Region::findOne(['level' => 0]);
- $parent_id = $region['id'];
- } else {
- $parent_id = $params['parent_id'];
- }
- $list = AreaAgent::getRegionList($parent_id, $this->mall_id, $this->level_id_arr);
- // $list['level_map'] = AreaEnum::getLevelMap(null, $this->mall_id);
- $list = ArrayHelper::removeDuplicates($list, 'name');
- return $this->success('成功', $list);
- }
- /**
- * @desc:申请页面-根据省、市、区、镇获取地区列表
- * @Author: hua
- * @Date: 2022/1/20
- * @Time: 16:08
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|void
- */
- public function actionGetDistrictList()
- {
- $params = Yii::$app->request->get();
- $res = Yii::$app->services->validate->validate($params, [
- [['level'], 'required'],
- [['level'], 'integer'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- if ($params['level'] > 4) $params['level'] = 4;
- $list = AreaAgent::getDistrictList($params);
- return $this->success('操作成功', $list);
- }
- /**
- * @desc:获取镇列表
- * @Author: hua
- * @Date: 2022/1/20
- * @Time: 16:08
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|void
- */
- public function actionGetTownList()
- {
- $params = \Yii::$app->request->get();
- $res = Yii::$app->services->validate->validate($params, [
- [['district_id'], 'required'],
- [['district_id','type'], 'integer'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $district_id = $params['district_id'];
- $list = Town::lists(['where' => [['district_id' => $district_id]], 'select' => 'id,district_id,name']);
- if(!empty($params['type'])){
- $area_agent_list = AreaAgent::lists([
- 'where' => [
- ['district_id' => $params['district_id']],
- ['level' => 4],
- ['mall_id' => $this->mall_id],
- ['status' => StatusEnum::ENABLED]
- ],
- 'select' => 'id,user_id,town_id',
- 'with' => ['user' => function ($query) {
- $query->select('id,nickname,avatar_url');
- }],
- ]);
- $area_agent_arr = [];
- foreach ($area_agent_list as $val){
- $area_agent_arr[$val['town_id']][]=$val;
- }
- foreach ($list as &$item) {
- $item['agent_list'] = [];
- if (isset($area_agent_arr[$item['id']])) $item['agent_list'] = $area_agent_arr[$item['id']];
- }
- }
- if (!empty($list)) {
- foreach ($list as &$item) {
- $item['level'] = 4;
- }
- }
- return $this->success('操作成功', $list);
- }
- /**
- * @desc:获取小区列表
- * @Author: hua
- * @Date: 2022/1/20
- * @Time: 16:08
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|void
- */
- public function actionGetCommunityList()
- {
- $params = \Yii::$app->request->get();
- $res = Yii::$app->services->validate->validate($params, [
- [['town_id'], 'required'],
- [['town_id','type'], 'integer'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $town_id = $params['town_id'];
- $list = AreaCommunity::lists(['where' => [['town_id' => $town_id, 'mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED]], 'select' => 'id,town_id,community_name as name']);
- if(!empty($params['type'])){
- $area_agent_list = AreaAgent::lists([
- 'where' => [
- ['town_id' => $params['town_id']],
- ['level' => 5],
- ['mall_id' => $this->mall_id],
- ['status' => StatusEnum::ENABLED]
- ],
- 'select' => 'id,user_id,community_id',
- 'with' => ['user' => function ($query) {
- $query->select('id,nickname,avatar_url');
- }],
- ]);
- $area_agent_arr = [];
- foreach ($area_agent_list as $val){
- $area_agent_arr[$val['community_id']][]=$val;
- }
- foreach ($list as &$item) {
- $item['agent_list'] = [];
- if (isset($area_agent_arr[$item['id']])) $item['agent_list'] = $area_agent_arr[$item['id']];
- }
- }
- if (!empty($list)) {
- foreach ($list as &$item) {
- $item['level'] = 5;
- }
- }
- return $this->success('操作成功', $list);
- }
- /**
- * @desc:提交申请
- * @Author: hua
- * @Date: 2022/1/20
- * @Time: 9:42
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|void
- */
- public function actionApply()
- {
- $params = \Yii::$app->request->post();
- $res = Yii::$app->services->validate->validate($params, [
- [['level', 'mobile', 'realname'], 'required'],
- [['level', 'province_id', 'city_id', 'district_id', 'town_id', 'community_id'], 'integer'],
- [['marks',], 'string']
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $params['town_id'] = $params['town_id'] ?:0;
- $params['community_id'] = $params['community_id'] ?: 0;
- $model = AreaAgent::findOne([
- 'user_id' => $this->user_id,
- 'mall_id' => $this->mall_id,
- 'province_id' => $params['province_id'],
- 'city_id' => $params['city_id'],
- 'district_id' => $params['district_id'],
- 'town_id' => $params['town_id'],
- 'community_id' => $params['community_id'],
- 'level' => $params['level'],
- 'status' => StatusEnum::ENABLED,
- ]);
- if (!empty($model)) return $this->error('您已经是该区域代理!');
- switch ($params['level']) {
- case AreaEnum::PROVINCE:
- $field = 'province_id';
- $value = $params['province_id'];
- break;
- case AreaEnum::CITY:
- $field = 'city_id';
- $value = $params['city_id'];
- break;
- case AreaEnum::DISTRICT:
- $field = 'district_id';
- $value = $params['district_id'];
- break;
- case AreaEnum::TOWN:
- $field = 'town_id';
- $value = $params['town_id'];
- break;
- case AreaEnum::COMMUNITY:
- $field = 'community_id';
- $value = $params['community_id'];
- break;
- default:
- return $this->error('请选择区域');
- }
- $res = AreaApply::findOne([
- 'user_id' => $this->user_id,
- 'mall_id' => $this->mall_id,
- 'check_status' => AreaEnum::NOT_APPROVED,
- $field => $value,
- ]);
- if (!empty($res)) return $this->error('你已经提交过该地区的申请了,请耐心等待审核结果!');
- $config = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_AREA, 'basic');
- $counts = AreaAgent::find()->where(['user_id' => $this->user_id, 'mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])->count();
- $apply_counts = AreaApply::find()->where(['user_id' => $this->user_id, 'mall_id' => $this->mall_id, 'check_status' => AreaEnum::NOT_APPROVED])->count();
- if (!empty($config['can_apply_area_num']) && $config['can_apply_area_num'] != -1 && ($counts + $apply_counts) >= $config['can_apply_area_num']) return $this->error('超出可申请最大数量!');
- //如果开启了购买申请资格按钮
- if ($config['is_buy_area'] == 1 && $params['level'] == 3) {
- // if (empty($params['order_id'])) return $this->error('请先购买申请资格');
- //查询是否已购买资格
- $order_data = AreaOrder::getOne([
- ['mall_id' => $this->mall_id],
- ['user_id' => $this->user_id],
- ['level' => $params['level']],
- ['area_id' => $params['district_id']],
- ['is_pay' => StatusEnum::ENABLED],
- ['status' => StatusEnum::ENABLED],
- // ['id' => $params['order_id']]
- ], true);
- // print_r($order_data);exit;
- if (empty($order_data)) return $this->error('请先购买申请资格');
- $config['is_check'] = 0;
- $params['pay_price'] = $order_data['price'];
- $params['status'] = StatusEnum::ENABLED;
- $params['order_id'] = $order_data['id'];
- }
- $params['mall_id'] = $this->mall_id;
- $params['user_id'] = $this->user_id;
- $params['mobile'] = (string)$params['mobile'];
- if (empty($config['is_check'])) {
- $res = AreaAgent::setData($params);
- if ($res === false) return $this->error(AreaAgent::getStaticError());
- $params['check_status'] = '1';
- $params['marks'] = '系统管理员审核通过';
- $res = AreaApply::setData($params);
- if ($res === false) return $this->error(AreaApply::getStaticError());
- } else {
- $res = AreaApply::setData($params);
- if ($res === false) return $this->error(AreaApply::getStaticError());
- }
- return $this->success('操作成功');
- }
- /**
- * @desc:是否是区域代理
- * @Author: hua
- * @Date: 2022/2/7
- * @Time: 11:39
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|void
- */
- public function actionIsAreaAgent(){
- $user_id = $this->user_id;
- $mall_id = $this->mall_id;
- $config = \Yii::$app->services->setting->addons->get($this->mall_id, AreaEnum::ADDONS_NAME, 'basic');
- $is_enable_apply = $config['is_enable_apply'] ?? StatusEnum::ENABLED;
- // 根据需求当用户为代理时优先返回
- $res = AreaAgent::findOne(['user_id'=>$user_id,'mall_id'=>$mall_id,'status'=>[StatusEnum::ENABLED,StatusEnum::DISABLED]]);
- if(!empty($res)) return $this->success('操作成功',['is_area_agent'=>1,'is_apply'=>0,'is_enable_apply' => $is_enable_apply]);
- $res = AreaApply::findOne(['user_id'=>$user_id,'mall_id'=>$mall_id,'check_status'=>AreaEnum::NOT_APPROVED]);
- // 根据需求当用户已经用户审核通过的代理身份了。这个时候如果用户在重新申请其它代理。并且在审核中。则不应该阻止用户进入代理页面
- $isCheckArea = AreaApply::find()
- ->where(['user_id'=>$user_id,'mall_id'=>$mall_id,'check_status'=>AreaEnum::APPROVED, 'status' => 1])->exists();
- if(!empty($res) && !$isCheckArea) return $this->success('操作成功',['is_apply'=>1,'is_area_agent'=>0,'is_enable_apply' => $is_enable_apply]);
- return $this->success('操作成功',[
- 'is_area_agent'=> 0,
- 'is_apply'=> 0,
- 'is_enable_apply' => $is_enable_apply
- ]);
- }
- /**
- * @desc:申请审核列表
- * @Author: hua
- * @Date: 2022/1/20
- * @Time: 9:54
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|void
- */
- public function actionApplyList()
- {
- $params = \Yii::$app->request->get();
- $mall_id = $this->mall_id;
- $where[] = ['mall_id' => $mall_id];
- $where[] = ['user_id' => $this->user_id];
- $where[] = ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]];
- $params['limit'] = 10;
- $params['where'] = $where;
- $params['order'] = 'id DESC';
- $params['select'] = 'id,user_id,level,address,realname, mobile,check_status,marks,created_at,is_refund,pay_price,refund_remark';
- $pageData = AreaApply::listPage($params, false);
- if ($pageData === false) return $this->error(AreaApply::getStaticError());
- $pageData['level_map'] = AreaEnum::getLevelMap(null, $this->mall_id);
- $pageData['check_status'] = AreaEnum::getCheckStatusMap();
- if (!empty($pageData['list'])) {
- foreach ($pageData['list'] as &$datum) {
- $datum['goods'] = [];
- }
- }
- return $this->success('操作成功', $pageData);
- }
- /**
- * 获取所属代理列表
- * @return mixed|null
- */
- public function actionList()
- {
- $only_dividend_goods_type = \Yii::$app->services->setting->addons->get($this->mall_id,
- AreaEnum::ADDONS_NAME, 'basic.only_dividend_goods_type');
- $with = [];
- if ($only_dividend_goods_type == StatusEnum::DISABLED) {
- $with = ['goods' => function ($query) {
- $query->with(['goods' => function($query1) {
- $query1->select('id, goods_name, cover_pic, price');
- }])->select('agent_id, goods_id');
- }];
- }
- $ret = AreaAgent::listPage([
- 'where' => [
- ['mall_id' => $this->mall_id],
- ['user_id' => $this->user_id],
- ['status' => StatusEnum::ENABLED]
- ],
- 'order' => 'id desc',
- 'select' => 'id, level, address, created_at',
- 'with' => $with,
- 'limit' => 10
- ]);
- if (!empty(AreaAgent::getStaticError())) return $this->error(AreaAgent::getStaticError());
- $ret['level_map'] = AreaEnum::getLevelMap(null, $this->mall_id);
- if (!empty($ret['list'])) {
- foreach ($ret['list'] as &$item) {
- $item['created_at'] = date("Y-m-d H:i:s", $item['created_at']);
- if (!empty($item['goods'])) {
- $item['goods'] = array_column($item['goods'], 'goods');
- } else {
- $item['goods'] = [];
- }
- }
- }
- $ret['is_any_goods'] = $only_dividend_goods_type;
- return $this->success('获取成功', $ret);
- }
- /**
- * 我的个人收益
- */
- public function actionMyIncome()
- {
- $params = Yii::$app->request->get();
- $type = in_array($params['type'] ?? null, ['0', '1'])
- ? (int)$params['type']
- : 0;; // 收益类型0:未结算 1: 已结算
- $where = [
- ['<>', 'capital_type', 'withdrawal_refund'], // 过滤提现驳回
- ['=', 'mall_id', $this->mall_id],
- ['=', 'user_id', $this->user_id],
- ['=', 'from_type', AreaEnum::ADDONS_NAME],
- ['=', 'change_type', 'add'],
- ];
- try {
- if (empty($type)) {
- $where[] = ['=', 'status', StatusEnum::ENABLED];
- }
- // 设置收益类型
- CapitalLog::$capitalType = $type === 1 ? "commission" : "commission_frozen";
- $params['where'] = $where;
- $params['order'] = 'id desc';
- $params['select'] = 'id, user_id, change_type, change_num, source_table, source_table_id, created_at';
- $params['with'] = [
- 'user' => function ($query) {
- $query->select('id, nickname, avatar_url');
- }
- ];
- $list = CapitalLog::listPage($params);
- if (!empty($list['list'])) {
- foreach ($list['list'] as &$item) {
- if (!empty($item['created_at'])) $item['created_at'] = date("Y-m-d H:i:s", $item['created_at']);
- // 因为订单详情有门店订单和主商城订单,所以需要过滤掉
- if ($item['source_table'] == 'order_detail') { // 主商城
- $orderDetail = OrderDetail::find()
- ->select('id, order_id, goods_id, num, goods_name, price')
- ->where(['id' => $item['source_table_id']])
- ->with([
- 'order' => function ($query) {
- $query->select('id, order_no');
- }
- ])->asArray()->one();
- if (!empty($orderDetail)) {
- $item['order_detail'] = $orderDetail;
- }
- } else if ($item['source_table'] == 'store_order_detail') { // 门店订单
- $orderDetail = StoreOrderDetail::find()
- ->select('id, order_id, num, goods_name, price')
- ->where(['id' => $item['source_table_id']])
- ->with([
- 'order' => function ($query) {
- $query->select('id, order_no');
- }
- ])->asArray()->one();
- if (!empty($orderDetail)) {
- $item['order_detail'] = $orderDetail;
- }
- }
- }
- }
- return $this->success('请求成功', $list);
- } catch (\Exception $e) {
- return $this->error('请求失败');
- }
- }
- /**
- * 我的区域代理人员
- */
- public function actionMyChildArea()
- {
- try {
- // 获取当前用户直推下级
- $userIds = UserPartitionRelationship::getChildIdArr($this->user_id, 1);
- // 获取当前商城设置的区域代理等级
- $areaLevelList = AreaEnum::getLevelMap(null, $this->mall_id);
- $areaList = AreaAgent::find()->where(['mall_id' => $this->mall_id, 'user_id' => $userIds, 'status' => StatusEnum::ENABLED])
- ->select('level, count(1) as count')
- ->groupBy('level')
- ->indexBy('level')
- ->asArray()
- ->all();
- $areaLevelSystemList = [];
- foreach ($areaLevelList as $key => $value) {
- if ($key == 0) continue; // 过滤掉无用数据
- $areaLevelSystemList[] = [
- 'level' => $key,
- 'name' => $value,
- 'count' => $areaList[$key]['count'] ?? 0
- ];
- }
- return $this->success('请求成功', $areaLevelSystemList);
- } catch (\Exception $e) {
- return $this->error('请求失败');
- }
- }
- /**
- * 直推下级区域人员列表
- * @return void
- */
- public function actionMyChildAreaList()
- {
- try {
- // 获取当前用户直推下级
- $params = Yii::$app->request->get();
- $userIds = UserPartitionRelationship::getChildIdArr($this->user_id, 1);
- if (empty($params['level'])) return $this->error('请选择对应区域');
- $where[] = ['=', 'level', $params['level']];
- $where = [
- ['=', 'mall_id', $this->mall_id],
- ['=', 'user_id', $userIds],
- ['=', 'level', $params['level']],
- ['=', 'status', StatusEnum::ENABLED],
- ];
- $params['where'] = $where;
- $params['order'] = 'id desc';
- $params['select'] = 'id, user_id, level, address';
- $params['with'] = [
- 'user' => function ($query) {
- $query->select('id, nickname, avatar_url, mobile');
- }
- ];
- $list = AreaAgent::listPage($params);
- return $this->success('请求成功', $list);
- } catch (Exception $e) {
- return $this->error('请求失败');
- }
- }
- }
|