| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257 |
- <?php
- /*
- * @Descripttion:
- * @version:
- * @Author: ewgof
- * @Date: 2022-04-29 10:31:21
- * @LastEditors: Please set LastEditors
- * @LastEditTime: 2024-07-15 15:26:41
- */
- namespace addons\Store\backend\controllers;
- use addons\Agent\common\models\AgentLevel;
- use addons\BusinessBonus\common\events\user\UpgradeUserEvent;
- use addons\Distribution\common\enums\DistributionEnum;
- use addons\Distribution\common\models\DistributionLevel;
- use addons\HuifuPay\common\service\HuifuBillShareService;
- use addons\Store\common\enums\StoreEnum;
- use addons\Store\common\models\Store;
- use addons\Store\common\models\StoreAdmin;
- use addons\Store\common\models\StoreCate;
- use addons\Store\common\models\StoreClerk;
- use addons\Store\common\models\StoreCommunity;
- use addons\Store\common\models\StoreGoods;
- use addons\Store\common\models\StoreMiniCode;
- use addons\Store\common\models\StoreModel;
- use addons\Store\common\models\StoreOrder;
- use addons\Store\common\models\StoreSettings;
- use common\enums\AddonsEnum;
- use common\enums\GoodsTypeEnum;
- use common\enums\OrderStatusEnum;
- use common\enums\StatusEnum;
- use common\globals\GlobalInvoke;
- use common\helpers\MiniQrCode;
- use common\helpers\QrCode;
- use common\helpers\RegularHelper;
- use common\logic\common\AddonsLimit;
- use common\models\common\MallSetting;
- use common\models\common\Region;
- use common\models\mall\MallAddons;
- use common\models\mall\MallHost;
- use common\models\user\User;
- use common\models\user\UserLevel;
- use Yii;
- use common\models\user\Town;
- use addons\Store\common\logic\StoreCreateSync;
- use addons\Store\common\services\StoreService;
- class StoreController extends BaseController
- {
- public function actionIndex()
- {
- if (!\Yii::$app->request->isAjax) {
- return $this->render('/store/index');
- }
- if (\Yii::$app->request->isGet) {
- $page = \Yii::$app->request->get('page', 1);
- $limit = \Yii::$app->request->get('limit', $this->pageSize);
- $store_name = \Yii::$app->request->get('store_name');
- $cate_id = \Yii::$app->request->get('cate_id');
- $storeowner = \Yii::$app->request->get('storeowner');
- $nickname = \Yii::$app->request->get('nickname');
- // 门店状态,1:正常;2:过期;3:禁用
- $status = \Yii::$app->request->get('status');
- $time_sort = \Yii::$app->request->get('time_sort');
- $time = time();
- $wheres[] = ['mall_id' => $this->mall_id, 'check_status' => StoreEnum::CHECK_ADOPT];
- if (empty($status)) {
- $wheres[] = ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]];
- } else {
- if (1 == $status) {
- $wheres[] = ['status' => StatusEnum::ENABLED];
- $wheres[] = ['or', ['>=', 'expire_time', $time], ['expire_time' => 0]];
- } elseif (2 == $status) {
- $wheres[] = ['status' => StatusEnum::ENABLED];
- $wheres[] = ['<=', 'expire_time', $time];
- $wheres[] = ['!=', 'expire_time', 0];
- } elseif (3 == $status) {
- $wheres[] = ['status' => StatusEnum::DISABLED];
- } else {
- return $this->error('参数错误');
- }
- }
- if (!empty($cate_id)) {
- $wheres[] = ['c_id' => $cate_id];
- }
- if (!empty($store_name)) {
- $store_name = trim($store_name);
- $wheres[] = ['or',['like', 'store_name', $store_name], ['id' => $store_name]];
- }
- if (!empty($storeowner)) {
- $wheres[] = ['like', 'shop_owner', $storeowner];
- }
- if (!empty($nickname)) {
- $users = User::find()
- ->select('id,nickname,mobile,avatar_url')
- ->where(['like', 'nickname', $nickname])
- ->andWhere(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
- ->asArray()
- ->indexBy('id')
- ->all();
- $user_ids = array_column($users, 'id');
- $wheres[] = ['user_id' => $user_ids];
- }
- $orderBy = 'created_at desc';
- if (isset($time_sort) && $time_sort > 0) {
- switch ($time_sort) {
- case 1:
- $orderBy = 'expire_time asc';
- $wheres[] = ['>', 'expire_time', time()];
- break;
- case 2:
- $orderBy = 'expire_time desc';
- break;
- }
- }
- $params = [
- 'select' => 'id,mall_id,user_id,shop_owner,shop_mobile,store_name,c_id,province_id,check_status,city_id,district_id,address,logo_img,total_money,balance,expire_time,user_nums,status,created_at,is_freeze,total_order_money,total_settled_amount,unsettled_amount,total_num,street_id,community_id,is_sync,sync_status',
- 'where' => $wheres,
- 'order' => $orderBy,
- 'page' => $page,
- 'limit' => $limit,
- ];
- $store_list = Store::listPage($params);
- if (false === $store_list) {
- return $this->error(Store::getStaticError());
- }
- if (!empty($store_list['list'])) {
- if (empty($users)) {
- $user_ids = array_unique(array_column($store_list['list'], 'user_id'));
- $users = User::find()
- ->select('id,nickname,mobile,avatar_url')
- ->where(['id' => $user_ids, 'mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
- ->asArray()
- ->indexBy('id')
- ->all();
- }
- $cate_ids = array_unique(array_column($store_list['list'], 'c_id'));
- $categorys = StoreCate::find()
- ->select('id,name')
- ->where(['id' => $cate_ids, 'mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
- ->asArray()
- ->indexBy('id')
- ->all();
- $region_ids = [];
- $province_ids = array_unique(array_column($store_list['list'], 'province_id'));
- $city_ids = array_unique(array_column($store_list['list'], 'city_id'));
- $district_ids = array_unique(array_column($store_list['list'], 'district_id'));
- $street_ids = array_unique(array_column($store_list['list'], 'street_id'));
- $community_ids = array_unique(array_column($store_list['list'], 'community_id'));
- $region_ids = array_merge($province_ids, $city_ids, $district_ids);
- $regions = Region::find()
- ->select('id,name')
- ->where(['id' => $region_ids])
- ->asArray()
- ->indexBy('id')
- ->all();
- $streets = town::find()
- ->select('id,name')
- ->where(['id'=>$street_ids])
- ->asArray()
- ->indexBy('id')
- ->all();
- $communitys = StoreCommunity::find()
- ->select('id,community_name')
- ->where(['mall_id'=>$this->mall_id,'id'=>$community_ids])
- ->asArray()
- ->indexBy('id')
- ->all();
- $H5Url = MallHost::getHost($this->mall_id,'h5_url');
- foreach ($store_list['list'] as &$list) {
- $h5_domain = $H5Url . '/#/plugins2/Store/pay/cashRegister?sign=' . $this->mall['mall_sign'];
- $user = $users[$list['user_id']] ?? [];
- $category = $categorys[$list['c_id']] ?? [];
- $province = $regions[$list['province_id']] ?? [];
- $city = $regions[$list['city_id']] ?? [];
- $district = $regions[$list['district_id']] ?? [];
- $streetInfo = $streets[$list['street_id']] ?? [];
- if($list['community_id'] == '-1'){
- $CommunityInfo = '其它社区';
- }else{
- if(isset($communitys[$list['community_id']])){
- $CommunityInfo = $communitys[$list['community_id']]['community_name'];
- }else{
- $CommunityInfo = '';
- }
- }
- $list['nickname'] = $user['nickname'] ?? '';
- $list['avatar_url'] = $user['avatar_url'] ?: \Yii::$app->request->hostInfo . '/resources/img/common/default-avatar.png';
- $list['category'] = $category['name'] ?? '';
- //判断address字段是否只是详细
- preg_match('/(.*?(?:省|自治区|北京市|天津市|上海市|重庆市))+(.*?(?:市|自治州|地区|区划|县))+(.*?(?:市|区|县|镇|乡|街道))/', $list['address'], $matches);
- if(count($matches) > 1){
- $list['store_address'] = $list['address'];
- }else{
- $list['store_address'] = ($province['name'] ?? '') . ($city['name'] ?? '') . ($district['name'] ?? ''). ($streetInfo['name'] ?? ''). ($CommunityInfo ?? '') . $list['address'];
- }
- // 门店状态,1:正常;2:过期;3:禁用
- if ($list['status'] == StatusEnum::ENABLED && $list['check_status'] == StoreEnum::CHECK_ADOPT && ($list['expire_time'] > $time || $list['expire_time'] == 0) && $list['is_freeze'] == StoreEnum::FREEZE_NO) {
- $list['store_status'] = 1;
- } elseif ($list['status'] == StatusEnum::ENABLED && $list['check_status'] == StoreEnum::CHECK_ADOPT && $list['expire_time'] > 0 && $list['expire_time'] <= $time) {
- $list['store_status'] = 2;
- } elseif ($list['status'] == StatusEnum::DISABLED) {
- $list['store_status'] = 3;
- }elseif($list['is_freeze'] == StoreEnum::FREEZE_YES) {
- $list['store_status'] = 4;
- } else {
- $list['store_status'] = 1;
- }
- if($list['is_sync'] && $list['sync_status'] == StoreEnum::SYNC_STATUS_IN_SYNC) {
- $list['store_status'] = 5;
- }
- $h5_domain .= '&store_id=' . $list['id'];
- $list['store_collection_url'] = $h5_domain;
- $list['promotion_code'] = $H5Url . '/#/plugins2/Store/store/index?store_id='.$list['id']."&sign=" . $this->mall['mall_sign']."&pid=" . $list['user_id'];
- }
- }
- $store_list['store_login_url'] = \Yii::$app->request->hostInfo . '?r=store/client/auth/login&sign=' . $this->mall['mall_sign'];
- $cate_list = StoreCate::find()
- ->select('id,name')
- ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
- ->asArray()
- ->all();
- $store_list['cate_list'] = $cate_list;
- return $this->success('success', $store_list);
- }
- }
- /**
- * @name:
- * @msg: 切换门店状态
- * @param {*}
- * @return {*}
- */
- public function actionSwitchStatus()
- {
- if (!\Yii::$app->request->isPost) {
- return $this->error('请求方式错误');
- }
- $post = \Yii::$app->request->post();
- $rules = [
- [['store_id', 'status'], 'required'],
- [['store_id', 'status'], 'integer'],
- ['status', 'in', 'range' => [1, 3]],
- ];
- $res = \Yii::$app->services->validate->validate($post, $rules);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- if (1 == $post['status']) {
- $status = StatusEnum::ENABLED;
- } else {
- $status = StatusEnum::DISABLED;
- }
- $params = [
- 'id' => $post['store_id'],
- 'status' => $status,
- 'mall_id' => $this->mall_id,
- ];
- $res = Store::setData($params);
- if (false === $res) {
- return $this->error(Store::getStaticError());
- }
- return $this->success('操作成功');
- }
- /**
- * @name:
- * @msg: 根据地区id获取第一层子级地区信息列表
- * @param {*}
- * @return {*}
- */
- public function actionGetRegions()
- {
- if (!\Yii::$app->request->isGet) {
- return $this->error('请求方式错误');
- }
- $region_id = \Yii::$app->request->get('region_id');
- $level = \Yii::$app->request->get('level');
- if (empty($region_id)) {
- return $this->error('参数错误');
- }
- $region = Region::findOne($region_id);
- if (empty($region) && $level <= 3) {
- return $this->error('地区信息未找到');
- }
- if(isset($level) && $level >= 3){
- if($level == 3){
- $region_list = Town::find()
- ->select('id,name')
- ->where(['district_id' => $region->id])
- ->asArray()
- ->indexBy('id')
- ->all();
- }else{
- $region_list = StoreCommunity::find()
- ->select('id,community_name')
- ->where(['street_id' => $region_id,'mall_id'=>$this->mall_id,'status'=>0])
- ->asArray()
- ->indexBy('id')
- ->all();
- $data = ['id'=>'-1','community_name'=>'其它社区'];
- $region_list[] = $data;
- }
- }else{
- $region_list = Region::find()
- ->select('id,name,lng,lat')
- ->where(['parent_id' => $region->id])
- ->asArray()
- ->indexBy('id')
- ->all();
- }
- return $this->success('success', $region_list);
- }
- /**
- * @name:
- * @msg: 获取用户列表
- * @param {*}
- * @return {*}
- */
- public function actionGetUsers()
- {
- if (!\Yii::$app->request->isGet) {
- return $this->error('请求方式错误');
- }
- $user_id = \Yii::$app->request->get('user_id');
- $keyword = \Yii::$app->request->get('keyword');
- $page = \Yii::$app->request->get('page', 1);
- $limit = \Yii::$app->request->get('limit', $this->pageSize);
- $store_user_ids = Store::find()->select('user_id')->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])->asArray()->column();
- $wheres[] = ['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED];
- $wheres[] = ['not in', 'id', $store_user_ids];
- if (!empty($user_id)) {
- $wheres[] = ['id' => $user_id];
- }
- if (!empty($keyword)) {
- $wheres[] = ['or', ['like', 'nickname', $keyword], ['like', 'mobile', $keyword]];
- }
- $params = [
- 'select' => 'id,nickname,avatar_url,mobile,level,parent_id',
- 'where' => $wheres,
- 'order' => 'created_at desc',
- 'page' => $page,
- 'limit' => $limit,
- ];
- $user_list = User::listPage($params);
- if (empty($user_list['list'])) {
- if (false === $user_list['list']) {
- return $this->error(User::getStaticError());
- }
- } else {
- $levels = UserLevel::find()
- ->select('id,level,name')
- ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
- ->asArray()
- ->indexBy('level')
- ->all();
- $parent_ids = array_column($user_list['list'], 'parent_id');
- $parent_users = User::find()
- ->select('id,nickname,avatar_url,mobile,level,parent_id')
- ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'id' => $parent_ids])
- ->asArray()
- ->indexBy('id')
- ->all();
- foreach ($user_list['list'] as &$user) {
- if (empty($user['avatar_url'])) {
- $user['avatar_url'] = \Yii::$app->request->hostInfo . '/resources/img/common/default-avatar.png';
- }
- $level = $levels[$user['level']] ?? [];
- $parent_user = $parent_users[$user['parent_id']] ?? [];
- $user['level_name'] = $level['name'] ?? '';
- $user['parent_nickname'] = $parent_user['nickname'] ?? '';
- }
- }
- return $this->success('success', $user_list);
- }
- /**
- * @name:
- * @msg: 门店添加/编辑
- * @param {*}
- * @return {*}
- */
- public function actionStorage()
- {
- if (!\Yii::$app->request->isAjax) {
- return $this->render('/store/add-edit');
- }
- if (\Yii::$app->request->isGet) {
- $cate_list = StoreCate::find()
- ->select('id,name')
- ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
- ->asArray()
- ->all();
- $regions = Region::find()
- ->select('id,name,lng,lat')
- ->where(['level' => 1])
- ->asArray()
- ->indexBy('id')
- ->all();
- $setting = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'community_set');
- $community_status = $setting['community_status']??0;
- $enter = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'enter');
- $enter['template_store_id'] = 0;
- if (empty($enter['template_store'])) {
- $enter['template_store'] = '';
- } else {
- $enter['template_store'] = json_decode($enter['template_store'], true);
- $template_store = end($enter['template_store']);
- $enter['template_store_id'] = $template_store['id'] ?? 0;
- }
- return $this->success('success', ['list' => $cate_list, 'provinces' => $regions,'community_status'=>$community_status, 'enter' => $enter]);
- } else {
- $post = \Yii::$app->request->post();
- $rules = [
- [['user_id', 'shop_mobile', 'shop_owner', 'store_name', 'c_id', 'logo_img', 'license_img', 'province_id', 'city_id', 'district_id', 'address', 'longitude', 'latitude'], 'required'],
- [['user_id', 'shop_mobile', 'c_id', 'province_id', 'city_id', 'district_id', 'street_id', 'community_id', 'is_set_template', 'template_store_id'], 'integer'],
- [['longitude', 'latitude'], 'number'],
- [['shop_owner', 'store_name', 'store_desc', 'logo_img', 'license_img', 'address'], 'string', 'max' => 255],
- [['logo_img', 'license_img'], 'url'],
- ['shop_mobile', function ($attribute, $params) {
- if (!RegularHelper::verify('mobile', $this->$attribute)) {
- $this->addError($attribute, '手机号格式错误');
- }
- }],
- ['store_desc', 'default', 'value' => ''],
- ['store_desc', 'safe']
- ];
- $res = \Yii::$app->services->validate->validate($post, $rules);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- // dd($post);
- $post['mall_id'] = $this->mall_id;
- $config_enter = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'enter');
- // dd($config_enter);
- if (1 == $config_enter['time_status']) {
- $days = $config_enter['expired_days'];
- $post['expire_time'] = time() + $days * 24 * 60 * 60;
- } else {
- $post['expire_time'] = 0;
- }
- $post['check_status'] = StoreEnum::CHECK_ADOPT;
- if($post['is_set_template']) {
- $post['is_sync'] = 1;
- }
- $post['is_examine'] = -1;
- $post['is_admin'] = 1;
- $store = Store::addStore($post);
- if (false === $store) {
- return $this->error(Store::getStaticError());
- }
- if($post['check_status']==StoreEnum::CHECK_ADOPT){
- if(!empty($store)){
- $params = [
- 'mall_id'=>$store['mall_id'],
- 'user_id'=>$store['user_id'],
- 'store_id'=>$store['id'],
- 'remark'=>'后台新增门店添加',
- ];
- $res = StoreClerk::setData($params);
- //触发招商分红用户条件升级
- if (MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_BUSINESS_BONUS)) {
- $event = new UpgradeUserEvent($this->mall_id);
- $data = ['mall_id' => $store['mall_id'], 'user_id' => $store['user_id']];
- \Yii::$app->services->events->dispatch($event, $data, $event->listeners);
- }
- }
- }
- //处理复制数据
- if ($post['is_set_template']) {
- \Yii::$app->services->rabbitMq->delay(10, [
- 'mall_id' => $this->mall_id,
- 'self_store_id' => $store['id'],
- 'source_store_id' => $post['template_store_id']
- ], StoreCreateSync::class, 'synStoreData');
- }
- return $this->success('添加成功');
- }
- }
- /**
- * @name:
- * @msg: 门店详情
- * @param {*}
- * @return {*}
- */
- public function actionDetail()
- {
- if (!\Yii::$app->request->isAjax) {
- // 获取组件配置
- $addons_setting = AddonsLimit::getGlobalSetting($this->mall_id);
- $addons_arr = [AddonsEnum::ADDONS_NAME_DISTRIBUTION, AddonsEnum::ADDONS_NAME_AGENT, AddonsEnum::ADDONS_NAME_AREA,AddonsEnum::ADDONS_NAME_DOUBLE_COPY,AddonsEnum::ADDONS_NAME_REBATE];
- if (!empty($addons_setting)) {
- foreach ($addons_setting as $key => $val) {
- if (!in_array($key, $addons_arr)) unset($addons_setting[$key]);
- }
- }
- $huifu_addons = StatusEnum::DISABLED;
- if (MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_HUIFU_PAY)) {
- $huifu_addons = HuifuBillShareService::isEnableShare($this->mall_id);
- }
- return $this->render('/store/detail', ['addons_settings' => $addons_setting,
- 'huifu_addons' => $huifu_addons]);
- }
- if (\Yii::$app->request->isGet) {
- $store_id = \Yii::$app->request->get('store_id');
- if (empty($store_id)) {
- return $this->error('参数错误');
- }
- $categorys = StoreCate::find()
- ->select('id,name,parent_id')
- ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
- ->asArray()
- ->all();
- $store = Store::find()
- ->where(['mall_id' => $this->mall_id, 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED], 'id' => $store_id])
- ->asArray()
- ->one();
- if (empty($store)) {
- return $this->error('门店不存在');
- }
- $store['cate_name'] = StoreCate::getAllParentName($store['c_id'],$categorys,$this->mall_id);
- $region_ids = [$store['province_id'], $store['city_id'], $store['district_id']];
- $regions = Region::find()
- ->select('id,name')
- ->where(['id' => $region_ids])
- ->asArray()
- ->indexBy('id')
- ->all();
- $store['addr'] = $regions[$store['province_id']]['name'] . '/' . $regions[$store['city_id']]['name'] . '/' . $regions[$store['district_id']]['name'];
- $good_counts = StoreGoods::find()
- ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'store_id' => $store_id])
- ->count();
- $store['good_counts'] = $good_counts;
- $store['total_order_number'] = $store['total_num'];
- $store['unsettled_amount'] = $store['total_expenses'];
- $streets = Town::find()
- ->where(['district_id'=>$store['district_id']])
- ->select('id,name')
- ->asArray()
- ->indexBy('id')
- ->all();
- $street_name = $streets[$store['street_id']]['name']??'';
- if($store['community_id'] == '-1'){
- $communitys_name = '其它社区';
- }else{
- $communitys = StoreCommunity::find()
- ->select('id,community_name')
- ->where(['street_id' => $store['street_id'],'status'=>0])
- ->asArray()
- ->indexBy('id')
- ->all();
- $communitys_name = $communitys[$store['community_id']]['community_name'] ?? '';
- }
- $store['show_address'] = $regions[$store['province_id']]['name'].$regions[$store['city_id']]['name'].$regions[$store['district_id']]['name'].$street_name.$communitys_name.$store['address'];
- $store['address_names'] = $regions[$store['province_id']]['name'].'-'.$regions[$store['city_id']]['name'].'-'.$regions[$store['district_id']]['name'].'-'.$street_name.'-'.$communitys_name.'-'.$store['address'];
- $basic_setting = $store;
- $store_admin = StoreAdmin::findOne(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED, 'store_id' =>$store_id]);
- $settings = StoreSettings::find()
- ->where(['mall_id' => $this->mall_id, 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED], 'store_id' => $store_id])
- ->asArray()
- ->one();
- $default_store_service_ratio = 10;
- $basic = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_STORE, 'basic');
- if ($basic['service_fee_type'] == 1) {
- $default_store_service_ratio = $basic['max_platform_ratio'];
- }
- $store_setting = [
- 'shop_status' => $store['shop_status'] ?? 0,
- 'business_time_start' => $store['business_time_start'] ?? '',
- 'business_time_end' => $store['business_time_end'] ?? '',
- 'store_background' => $store['store_background'] ?? '',
- 'device_id' => $store['device_id'] ?? '',
- 'username' => $store_admin->username,
- 'store_service_fee' => $settings['store_service_fee'] ?? 0,
- 'store_service_fee_type' => $settings['store_service_fee_type'] ?? 0,
- 'store_service_ratio' => $settings['store_service_ratio'] ?? $default_store_service_ratio,
- 'huifu_mch_no' => $settings['huifu_mch_no'] ?? '',
- 'store_settle_type' => $settings['store_settle_type'] ?? 1,
- 'store_service_fee_settle_type' => $settings['store_service_fee_settle_type'] ?? 1,
- 'store_settle_scene' => $settings['store_settle_scene'] ?? 1,
- 'store_commission_authority' => json_decode($settings['store_commission_authority'], true) ?? [],
- 'show_sync_goods' => $store['show_sync_goods'] ?? 0,
- 'is_enable_withdraw_setting' => $settings['is_enable_withdraw_setting'] ?? 0,
- 'balance_cash_service_fee_limit' => $settings['balance_cash_service_fee_limit'] ?? 0,
- 'balance_cash_service_fee' => $settings['balance_cash_service_fee'] ?? 0,
- 'balance_cash_service_fee_diff' => $settings['balance_cash_service_fee_diff'] ?? 0,
- 'balance_cash_service_fee_month' => $settings['balance_cash_service_fee_month'] ?? 0,
- 'is_allow_editing' => $settings['is_allow_editing'] ?? 0,
- //平台设置的服务费类型
- 'platform_service_fee_type' => \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'basic.service_fee_type')
- ];
- /* ---------- 用户权重相关配置处理 start ------ */
- $cashier_setting = [
- 'cachier_service_ratio' => $settings['cachier_service_ratio'] ?? 10,
- 'cashier_member_status' => $settings['cashier_member_status'] ?? 0,
- 'cashier_member_settings' => $settings['cashier_member_settings'],
- 'cashier_distribution_is_enable' => $settings['cashier_distribution_is_enable'] ?? 0,
- 'cashier_distribution_is_enable_score' => $settings['cashier_distribution_is_enable_score'] ?? 0,
- 'cashier_distribution_settings' => $settings['cashier_distribution_settings'],
- 'cashier_distribution_settings_score' => $settings['cashier_distribution_settings_score']??[],
- 'cashier_agent_is_enable' => $settings['cashier_agent_is_enable'] ?? 0,
- 'cashier_agent_settings' => $settings['cashier_agent_settings'],
- 'preferential_undertaking' => $settings['preferential_undertaking']??'1',
- 'is_preferential_undertaking' => $settings['is_preferential_undertaking']??0,
- 'is_preferential_gift' => $settings['is_preferential_gift']??0,
- 'cashier_goods_complete_direct' => $settings['cashier_goods_complete_direct']??0,
- 'deepNames' => [],
- 'enable_discount_price' => $settings['enable_discount_price'] ?? 0,
- 'discount_price_scale' => $settings['discount_price_scale'] ?? 0,
- 'cashier_is_open_discount' => $settings['cashier_is_open_discount'] ?? 0,
- 'is_area_enable' => $settings['is_area_enable'] ?? 0,
- ];
- $level = \Yii::$app->services->setting->addons->get($this->mall_id, AddonsEnum::ADDONS_NAME_DISTRIBUTION, 'basic.level');
- if(empty($level)) $level = 0;
- if($level>0) $cashier_setting['deepNames'][]='一级';
- if($level>1) $cashier_setting['deepNames'][]='二级';
- if($level>2) $cashier_setting['deepNames'][]='三级';
- $member_levels = UserLevel::find()
- ->select('level,name as level_name')
- ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
- ->asArray()
- ->all();
- if (empty($member_levels)) {
- $member_levels = [
- // ['level' => 0, 'level_name' => '默认权重'],
- ];
- }
- if (!empty($cashier_setting['cashier_member_settings'])) {
- $setting_members = json_decode($cashier_setting['cashier_member_settings'], true);
- $mem_levels = array_column($setting_members, 'level');
- $mem_level_discount_map = array_column($setting_members, 'discount', 'level');
- } else {
- $mem_levels = [];
- $mem_level_discount_map = [];
- }
- foreach ($member_levels as &$mlevel) {
- if (!in_array($mlevel['level'], $mem_levels)) {
- $mlevel['discount'] = 0;
- } else {
- $mlevel['discount'] = floatval($mem_level_discount_map[$mlevel['level']] ?? 0);
- }
- }
- // dd($member_levels);
- $cashier_setting['cashier_member_settings'] = $member_levels;
- /* ---------- 用户权重相关配置处理 end ------ */
- /* ---------- 分销权重相关配置处理 start ------ */
- $is_install_distribution = MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_DISTRIBUTION);
- if (!$is_install_distribution) {
- $distribution_settings = [];
- $is_distribution_enable = 0;
- $is_distribution_enable_score = 0;
- } else {
- $is_distribution_enable = 1;
- $is_distribution_enable_score = 1;
- $setting = \Yii::$app->services->setting->addons->get($this->mall_id, DistributionEnum::ADDONS_NAME, 'basic');
- $default_level_name = '默认等级';
- if(!empty($setting['default_level_name'])){
- $default_level_name = $setting['default_level_name'];
- }
- $distribution_levels = [['level' => 0, 'level_name' => $default_level_name]];
- $distribution_levels_temp = DistributionLevel::find()
- ->select('level,name as level_name')
- ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
- ->asArray()
- ->all();
- $distribution_levels = array_merge($distribution_levels, $distribution_levels_temp);
- if (!empty($cashier_setting['cashier_distribution_settings'])) {
- $distribution_settings = json_decode($cashier_setting['cashier_distribution_settings'], true);
- $distr_levels = array_column($distribution_settings, 'level');
- $distr_level_discount_map = array_column($distribution_settings, 'commission_rate', 'level');
- } else {
- $distr_levels = $distr_level_discount_map = [];
- }
- if (!empty($cashier_setting['cashier_distribution_settings_score'])) {
- $distribution_settings = json_decode($cashier_setting['cashier_distribution_settings_score'], true);
- $distr_levels_score = array_column($distribution_settings, 'level');
- $distr_level_discount_map_score = array_column($distribution_settings, 'commission_rate', 'level');
- } else {
- $distr_levels_score = $distr_level_discount_map_score = [];
- }
- $distribution_levels_score = $distribution_levels;
- foreach ($distribution_levels as &$dlevel) {
- if (!in_array($dlevel['level'], $distr_levels)) {
- $dlevel['commission_rate'] = [0, 0,0];
- } else {
- $dlevel['commission_rate'] = $distr_level_discount_map[$dlevel['level']] ?? [0, 0,0];
- }
- }
- foreach ($distribution_levels_score as &$dlevel) {
- if (!in_array($dlevel['level'], $distr_levels_score)) {
- $dlevel['commission_rate'] = [0, 0,0];
- } else {
- $dlevel['commission_rate'] = $distr_level_discount_map_score[$dlevel['level']] ?? [0, 0,0];
- }
- }
- $cashier_setting['cashier_distribution_settings'] = $distribution_levels;
- $cashier_setting['cashier_distribution_settings_score'] = $distribution_levels_score;
- $cashier_setting['is_distribution_enable'] = $is_distribution_enable;
- $cashier_setting['is_distribution_enable_score'] = $is_distribution_enable_score;
- }
- /* ---------- 分销权重相关配置处理 end ------ */
- /****收银台区域奖励配置 ----start----****/
- $is_install_area = MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_AREA);
- $area_currency_arr = ['detail' => '佣金', 'detail_score' => '积分'];
- $cashier_setting['area_currency'] = $area_currency_arr;
- if ($is_install_area) {
- $area_levels = [
- 6 => ['level' => 6, 'level_name' => '大区代'],
- 1 => ['level' => 1, 'level_name' => '省代'],
- 2 => ['level' => 2, 'level_name' => '市代'],
- 3 => ['level' => 3, 'level_name' => '区代'],
- 4 => ['level' => 4, 'level_name' => '镇代'],
- 5 => ['level' => 5, 'level_name' => '小区代']
- ];
- $areaSystem = json_decode($settings['cashier_area_settings'], true) ?? [];
- if (empty($areaSystem)) {
- // 默认配置
- foreach ($area_currency_arr as $area => $item) {
- foreach ($area_levels as $value) {
- $areaSystem[$area][] = [
- 'level' => $value['level'],
- 'level_name' => $value['level_name'],
- 'prize' => 0,
- 'equal_prize' => 0
- ];
- }
- }
- $areaSystem['detail_remaining_ratio'] = 0;
- $areaSystem['detail_score_remaining_ratio'] = 0;
- $areaSystem['is_enable'] = 0;
- }
- // 获取配置信息
- $cashier_setting['is_area_enable_cashier'] = 1;
- $cashier_setting['cashier_area_settings'] = $areaSystem;
- } else {
- $cashier_setting['is_area_enable_cashier'] = 0;
- $cashier_setting['cashier_area_settings'] = null;
- }
- /* ---------- 经销等级相关配置处理 start ------ */
- $is_install_agent = MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_AGENT);
- if (!$is_install_agent) {
- $agent_settings = [
- 'team_rewards' => [
- // ['level' => 0, 'level_name' => '默认权重', 'commission_rate' => 0],
- ],
- 'equal_rewards' => [
- // ['level' => 0, 'level_name' => '默认权重', 'commission_rate' => 0],
- ],
- 'over_rewards' => [
- // ['level' => 0, 'level_name' => '默认权重', 'commission_rate' => 0],
- ],
- ];
- $is_agent_enable = 0;
- } else {
- $is_agent_enable = 1;
- $agent_levels = AgentLevel::find()
- ->select('level,name as level_name')
- ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
- ->asArray()
- ->all();
- if (empty($agent_levels)) {
- $agent_levels = [
- // ['level' => 0, 'level_name' => '默认权重'],
- ];
- }
- if (!empty($cashier_setting['cashier_agent_settings'])) {
- $agent_settings = json_decode($cashier_setting['cashier_agent_settings'], true);
- } else {
- $agent_settings = [
- 'team_rewards' => [
- // ['level' => 0, 'level_name' => '默认权重', 'commission_rate' => 0],
- ],
- 'equal_rewards' => [
- // ['level' => 0, 'level_name' => '默认权重', 'commission_rate' => 0],
- ],
- 'over_rewards' => [
- // ['level' => 0, 'level_name' => '默认权重', 'commission_rate' => 0],
- ],
- ];
- }
- foreach ($agent_settings as $reward_name => $setting) {
- foreach ($setting as $val) {
- $agent_settings[$reward_name][$val['level']] = $val;
- }
- }
- $ag_levels = array_column($agent_settings['team_rewards'], 'level');
- $agent_level_settings = [];
- foreach ($agent_levels as $alevel) {
- if (!in_array($alevel['level'], $ag_levels)) {
- $arr = $alevel;
- $arr['commission_rate'] = 0;
- $agent_level_settings['team_rewards'][] = $arr;
- $agent_level_settings['equal_rewards'][] = $arr;
- $agent_level_settings['over_rewards'][] = $arr;
- } else {
- $arr = [
- 'level' => $alevel['level'],
- 'level_name' => $alevel['level_name'],
- 'commission_rate' => $agent_settings['team_rewards'][$alevel['level']]['commission_rate'] ?? 0,
- ];
- $agent_level_settings['team_rewards'][] = $arr;
- $arr['commission_rate'] = $agent_settings['equal_rewards'][$alevel['level']]['commission_rate'] ?? 0;
- $agent_level_settings['equal_rewards'][] = $arr;
- $arr['commission_rate'] = $agent_settings['over_rewards'][$alevel['level']]['commission_rate'] ?? 0;
- $agent_level_settings['over_rewards'][] = $arr;
- }
- }
- $cashier_setting['cashier_agent_settings'] = $agent_level_settings;
- $cashier_setting['is_agent_enable'] = $is_agent_enable;
- /* ---------- 经销权重相关配置处理 end ------ */
- }
- if(!isset($store_setting['device_id']))$store_setting['device_id'] = '';
- $setting = \Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'community_set');
- $community_status = $setting['community_status']??0;
- //赋值省市区街道等详情信息
- $regions_provinces = Region::find()
- ->select('id,name')
- ->where(['level' => 1])
- ->asArray()
- ->indexBy('id')
- ->all();
- return $this->success('success', ['basic_setting' => $basic_setting, 'store_setting' => $store_setting, 'cashier_setting' => $cashier_setting, 'categorys' => $categorys,'provinces'=>$regions_provinces,'community_status'=>$community_status]);
- } else {
- $post = \Yii::$app->request->post();
- $group = $post['group'];
- $store_id = $post['store_id'];
- if (empty($group) || !in_array($group, ['store_setting', 'cashier_setting', 'basic_setting']) || empty($store_id)) {
- return $this->error('参数错误');
- }
- // dd($post[$group]);
- $rules = [
- 'basic_setting' => [
- [['store_name', 'logo_img', 'license_img', 'share_title', 'share_desc', 'share_pic', 'longitude', 'latitude', 'address', 'share_title', 'share_desc', 'share_pic', 'addr'], 'string', 'max' => 255],
- [['shop_mobile', 'c_id', 'expire_time','payment_settlement_type','province_id','city_id','district_id','street_id','community_id'], 'integer'],
- ],
- 'store_setting' => [
- [['shop_status', 'business_time_start', 'business_time_end', 'username', 'store_service_fee', 'store_service_ratio', 'store_settle_type', 'store_settle_scene', 'store_service_fee_settle_type'], 'required'],
- [['shop_status', 'store_service_fee', 'store_settle_type', 'store_settle_scene', 'status', 'show_sync_goods', 'is_enable_withdraw_setting', 'balance_cash_service_fee_limit', 'store_service_fee_type','is_allow_editing', 'store_service_fee_settle_type'], 'integer'],
- [['store_service_ratio', 'balance_cash_service_fee', 'balance_cash_service_fee_diff', 'balance_cash_service_fee_month'], 'number'],
- [['business_time_start', 'business_time_end', 'store_background', 'Distribution', 'Agent', 'Area','DoubleCopy', 'huifu_mch_no','Rebate'], 'string'],
- [['password', 'store_commission_authority','device_id'], 'safe'],
- ],
- 'cashier_setting' => [
- [['cachier_service_ratio', 'cashier_member_status', 'cashier_distribution_is_enable', 'cashier_agent_is_enable','is_preferential_undertaking','preferential_undertaking'], 'required'],
- [['cashier_member_status', 'cashier_distribution_is_enable', 'cashier_distribution_is_enable_score', 'cashier_agent_is_enable','cashier_goods_complete_direct','enable_discount_price','cashier_is_open_discount'], 'integer'],
- [['id','cashier_member_settings','cashier_distribution_settings','cashier_distribution_settings_score','cashier_agent_settings','is_preferential_gift', 'cashier_area_settings'], 'safe'],
- [['discount_price_scale'], 'number']
- ],
- ];
- $res = \Yii::$app->services->validate->validate($post[$group], $rules[$group]);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- $post[$group]['store_id'] = $store_id;
- if ('store_setting' == $group) {
- $addons_settings = [];
- if (!empty($post[$group]['Distribution'])) {
- $addons_settings['Distribution'] = json_decode($post[$group]['Distribution'], true);
- if (!empty($addons_settings['Distribution']['is_enable'])) {
- $post[$group]['store_commission_authority']['distribution'] = 1;
- } else {
- $post[$group]['store_commission_authority']['distribution'] = 0;
- }
- }
- if (!empty($post[$group]['Area'])) {
- $addons_settings['Area'] = json_decode($post[$group]['Area'], true);
- if (!empty($addons_settings['Area']['is_enable'])) {
- $post[$group]['store_commission_authority']['area'] = 1;
- } else {
- $post[$group]['store_commission_authority']['area'] = 0;
- }
- }
- if (!empty($post[$group]['Agent'])) {
- $addons_settings['Agent'] = json_decode($post[$group]['Agent'], true);
- if (!empty($addons_settings['Agent']['is_enable'])) {
- $post[$group]['store_commission_authority']['agent'] = 1;
- } else {
- $post[$group]['store_commission_authority']['agent'] = 0;
- }
- }
- if (!empty($post[$group]['DoubleCopy'])) {
- $addons_settings['DoubleCopy'] = json_decode($post[$group]['DoubleCopy'], true);
- if (!empty($addons_settings['DoubleCopy']['is_enable'])) {
- $post[$group]['store_commission_authority']['doubleCopy'] = 1;
- } else {
- $post[$group]['store_commission_authority']['doubleCopy'] = 0;
- }
- }
- if (!empty($post[$group]['Rebate'])) {
- $addons_settings['Rebate'] = json_decode($post[$group]['Rebate'], true);
- }
- $res = StoreSettings::saveStoreSetting($this->mall_id, $post[$group], $addons_settings);
- if (false === $res) {
- return $this->error(StoreSettings::getStaticError());
- }
- return $this->success('保存成功');
- } elseif ('cashier_setting' == $group) {
- $res = StoreSettings::setData($this->mall_id, $post[$group]);
- if (false === $res) {
- return $this->error(StoreSettings::getStaticError());
- }
- return $this->success('保存成功');
- } elseif ('basic_setting' == $group) {
- $post[$group]['mall_id'] = $this->mall_id;
- $post[$group]['id'] = $store_id;
- unset($post[$group]['store_id']);
- // dd($post);
- $addr = $post[$group]['addr'] ?? '';
- if (!empty($addr)) {
- $addrs = explode('/', $addr);
- if(!empty($addrs[0])&&!empty( $addrs[1])&&!empty( $addrs[2])){
- $addrs[0] = str_replace('中国','',$addrs[0]);
- $regions = Region::find()
- ->select('id,name,level')
- ->where(['or', ['name' => $addrs[0]], ['name' => $addrs[1]], ['name' => $addrs[2]]])
- ->asArray()
- ->indexBy('level')
- ->all();
- $post[$group]['province_id'] = $regions[1]['id'];
- $post[$group]['city_id'] = $regions[2]['id'];
- $post[$group]['district_id'] = $regions[3]['id'];
- }
- }
- $post[$group]['community_id'] = !empty($post[$group]['community_id']) ? $post[$group]['community_id'] : 0;
- $res = Store::setData($post[$group]);
- if (false === $res) {
- return $this->error(Store::getStaticError());
- }
- return $this->success('保存成功');
- }
- }
- }
- public function actionModelDetail()
- {
- if (!\Yii::$app->request->isGet) {
- return $this->error('请求方式错误');
- }
- $store_id = \Yii::$app->request->get('store_id');
- if (empty($store_id)) {
- return $this->error('参数错误');
- }
- $store_model = StoreModel::getOne([['mall_id' => $this->mall_id, 'store_id' => $store_id]], true);
- $content = $setting = [];
- if (!empty($store_model['content'])) {
- $content = json_decode($store_model['content'], true);
- }
- // 获取配置
- foreach ($content as $key => &$item) {
- $setting[$key] = $item;
- }
- // 获取权重
- $level_params = ['where' => [['=', 'mall_id', $this->mall_id], ['=', 'status', StatusEnum::ENABLED]], 'select' => 'level,name'];
- $level_params['mall_id'] = $this->mall_id;
- $level = GlobalInvoke::exec(GlobalInvoke::GOODS_MODEL_LEVEL, $this->mall_id, $level_params);
- $commission_type_map = GoodsTypeEnum::getCommissionTypeMap($this->mall_id);
- unset($commission_type_map['digital']);
- $status = $store_model['status'] ?? 0;
- $area_levels = [
- 1 => ['level' => 1, 'name' => '省代'],
- 2 => ['level' => 2, 'name' => '市代'],
- 3 => ['level' => 3, 'name' => '区代'],
- 4 => ['level' => 4, 'name' => '镇代'],
- ];
- $level['Area'] = $area_levels;
- return $this->success('操作成功', compact('status', 'level', 'setting', 'commission_type_map'));
- }
- /**
- * 组件获取店铺列表
- * @Author: lun
- * @DateTime: 2022/8/3 0003 18:40
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|void
- */
- public function actionStoreList()
- {
- $retuest = \Yii::$app->request;
- if ($retuest->isAjax) {
- if ($retuest->isGet) {
- $get = \Yii::$app->request->get();
- // 检查提交的参数
- $res = \Yii::$app->services->validate->validate($get,[
- [['id'], 'integer'],
- [['store_name'], 'string'],
- [['store_ids', 'exist_ids'], 'safe'],
- ]);
- if($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- $where = $list = [];
- !empty($get['id']) && $where[] = ['=', 'id', $get['id']];
- $where[] = ['=', 'mall_id', $this->mall_id];
- !empty($get['store_name']) && $where[] = ['like', 'store_name', $get['store_name']];
- !empty($get['store_ids']) && $where[] = ['id' => $get['store_ids']];
- !empty($get['exist_ids']) && $where[] = ['not in', 'id', $get['exist_ids']];
- $where[] = ['=', 'check_status', StatusEnum::ENABLED];
- $where[] = ['=', 'status', StatusEnum::ENABLED];
- $order = 'created_at desc';
- $select = 'id,c_id,mall_id,logo_img,store_name,shop_mobile,created_at';
- $params = array('where' => $where, 'select' => $select, 'order' => $order, 'limit' => $get['limit']);
- $params['with'] = ['cate' => function ($query) {
- $query->select('id, name');
- }];
- $list = Store::listPage($params, false, true);
- return $this->success('获取成功', $list);
- }
- }
- }
- /**
- * 小程序推广码/收银码
- *
- * @return mixed
- */
- public function actionShowMiniPromotionCode()
- {
- $request = \Yii::$app->request;
- if ($request->isAjax) {
- if ($request->isPost) {
- $params = \Yii::$app->request->post();
- // 检查提交的参数
- $res = \Yii::$app->services->validate->validate($params,[
- [['id','type'], 'required'],
- ]);
- if($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- $store = Store::findOne(['mall_id'=>$this->mall_id,'id'=>$params['id']]);
- if(empty($store)) return $this->error('店铺不存在');
- $model = StoreMiniCode::findOne(['store_id'=>$store['id'],'mall_id'=>$this->mall_id,'type'=>$params['type'], 'status' => StatusEnum::ENABLED]);
- if(empty($model)){
- $mall = $this->mall;
- $content = [
- 'mall_id'=>$this->mall_id,
- 'store_id'=>$store['id'],
- 'mall_sign'=>$mall['mall_sign'],
- 'type'=>$params['type'],
- 'pid'=>$store['user_id'],
- ];
- $content = json_encode($content);
- if($params['type']==1){
- $page = 'plugins2/Store/store/index';
- }else{
- $page = '/plugins2/Store/pay/cashRegister';
- }
- $code = md5($content);
- $obj = new MiniQrCode();
- $applet_code = $obj->getAppletQrCode($this->mall_id,$page,$code);
- $params['mall_id'] = $this->mall_id;
- $params['code'] = $code;
- $params['store_id'] = $store['id'];
- $params['content'] = $content;
- $params['applet_code'] = $applet_code;
- $model = StoreMiniCode::setData($params);
- if($model==false){
- return $this->error(StoreMiniCode::getStaticError());
- }
- } else if (empty($model->applet_code)) {
- $mall = $this->mall;
- $content = [
- 'mall_id'=>$this->mall_id,
- 'store_id'=>$store['id'],
- 'mall_sign'=>$mall['mall_sign'],
- 'type'=>$params['type'],
- 'pid'=>$store['user_id'],
- ];
- $content = json_encode($content);
- if($params['type']==1){
- $page = 'plugins2/Store/store/index';
- }else{
- $page = '/plugins2/Store/pay/cashRegister';
- }
- $code = md5($content);
- $obj = new MiniQrCode();
- $applet_code = $obj->getAppletQrCode($this->mall_id,$page,$code);
- $model->applet_code = $applet_code;
- $model->save();
- }
- $applet_url = $model['applet_code'];
- return $this->success('获取成功',['applet_url'=>$applet_url]);
- }
- }
- }
- /**
- * 选择门店接口,外部调用
- * @return mixed|void
- */
- public function actionSelectStore(){
- if (Yii::$app->request->isAjax && Yii::$app->request->isGet) {
- $params = Yii::$app->request->get();
- $params['where'][] = ['mall_id' => $this->mall_id];
- $params['where'][] = ['status' => [StatusEnum::ENABLED]];
- if (!empty($params['keyword'])) $params['where'][] = ['or', ['like', 'store_name', $params['keyword']], ['id' => $params['keyword']]];
- $params['order'] = 'id desc';
- $params['select'] = 'id,store_name,shop_owner,shop_mobile,logo_img,store_desc,shop_status,status';
- $list = Store::listPage($params);
- return $this->success('操作成功', $list);
- }
- }
- //门店删除
- public function actionDel(){
- try {
- $params = Yii::$app->request->post();
- Store::delStore($this->mall_id,$params['id']);
- return $this->success();
- }catch (\Exception $e){
- return $this->error($e->getMessage());
- }
- }
- /**
- * 门店列表(全部门店)
- *
- * @return string
- */
- public function actionList()
- {
- $service = new StoreService(['mall_id' => $this->mall_id]);
- return $this->success('ok', $service->getStoreList());
- }
- /**
- * 云喇叭测试
- * @Author:lun
- * @Date:2024-01-06 16:22
- * @Copyright:copyright(c)2023 广东七件事集团
- * @return mixed|void|null
- */
- public function actionSuonaTest()
- {
- $request = Yii::$app->request;
- if ($request->isPost) {
- $params = $request->post();
- // 检查提交的参数
- $res = Yii::$app->services->validate->validate($params,[
- [['store_id','device_id'], 'required'],
- ]);
- if($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- $basic = Yii::$app->services->setting->addons->get($this->mall_id, StoreEnum::ADDONS_NAME, 'basic');
- if (empty($basic['suona_appId'])) return $this->error('appId不能为空');
- if (empty($basic['suona_appSecret'])) return $this->error('appSecret不能为空');
- if (empty($basic['suona_host'])) return $this->error('appSecret不能为空');
- $url = $basic['suona_host'] . 'plugin.yunqian-api.api.push.sendSpeakerMessage';
- try {
- $obj = new \addons\Store\common\logic\order\SuonaLogic($basic['suona_appId'], $basic['suona_appSecret']);
- $data = $obj->suona($url,100, $params['device_id'],6);
- if ($data['response']['result'] == 0) return $this->error('测试失败:' .'请求参数:'. $data['params'] .',请求响应:'. $data['response']['msg']);
- return $this->success('测试成功');
- } catch (\Exception $e) {
- return $this->error('请求报错:' . $e->getMessage());
- }
- }
- }
- /**
- * 清除小程序码
- * @return void
- */
- public function actionCleanMiniCode()
- {
- $service = new StoreService(['mall_id' => $this->mall_id]);
- return $service->cleanMiniCode()
- ? $this->success('清除成功')
- : $this->error('清除失败');
- }
- public function actionStoreCateTree()
- {
- if (Yii::$app->request->isAjax) {
- if (Yii::$app->request->isGet) {
- $cond = [['mall_id' => $this->mall_id]];
- $list = StoreCate::getCates($cond, [], true, 'id,name,parent_id');
- $list = StoreCate::getTreeCate($list);
- return $this->success('操作成功', compact('list'));
- }
- }
- }
- /**
- * 选择门店店长接口,外部调用
- * @return mixed|void
- */
- public function actionSelectStoreUser(){
- if (Yii::$app->request->isAjax && Yii::$app->request->isGet) {
- $params = Yii::$app->request->get();
- $params['where'][] = ['mall_id' => $this->mall_id];
- $params['where'][] = ['status' => [StatusEnum::ENABLED]];
- if (!empty($params['keyword'])) {
- $uids = User::find()
- ->where(['mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])
- ->where(['or', ['like', 'nickname', $params['keyword']], ['like', 'mobile', $params['keyword']]])
- ->select('id')
- ->column();
- $uids[] = -1; //防止$uid 空数组
- $params['where'][] = ['in', 'user_id', $uids];
- }
- if (!empty($params['user_id'])) {
- $params['where'][] = ['id' => $params['user_id']];
- }
- $params['order'] = 'id desc';
- $params['select'] = 'id,user_id,store_name,shop_owner,shop_mobile,logo_img,store_desc,shop_status,status';
- $list = Store::listPage($params);
- if(empty($list['list']) == false){
- $uids = array_column($list['list'],'user_id');
- $u_where = [];
- $u_where[] = ['in','id',$uids];
- $userList = User::lists(['where' => $u_where],true);
- if(empty($userList) == false){
- $userList = array_column($userList, null, 'id');
- }
- $user_level_arr = UserLevel::getUserLevelArr($this->mall_id);
- foreach ($list['list'] as &$item){
- $user = $userList[$item['user_id']];
- $item['avatar_url'] = $user['avatar_url'];
- $item['nickname'] = $user['nickname'];
- $item['mobile'] = $user['mobile'];
- $item['level_name'] = !empty($user_level_arr[$user['level']]) ? $user_level_arr[$user['level']] : MallSetting::getDefaultLevelName($this->mall_id);
- }
- }
- return $this->success('操作成功', $list);
- }
- }
- }
|