| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- <?php
- namespace ghs\controllers;
- use biz\shop\classes\ShopAdminClass;
- use biz\sj\classes\MerchantClass;
- use biz\sj\services\MerchantExtendService;
- use biz\sj\services\MerchantService;
- use bizHd\saas\services\SetAuthService;
- use Yii;
- use common\components\util;
- class MerchantController extends BaseController
- {
- public $guestAccess = ['detail', 'introduce-shop'];
- //运费设置 ssh 2019.12.8
- public function actionFreightSetting()
- {
- $get = Yii::$app->request->get();
- $first = isset($get['first']) && is_numeric($get['first']) ? $get['first'] : 5;
- $add = isset($get['add']) && is_numeric($get['add']) ? $get['add'] : 5;
- MerchantExtendService::updateByCondition(['sjId' => $this->sjId], ['freeDistance' => $first, 'freight' => $add]);
- util::complete();
- }
- //商家信息 ssh 2019.12.8
- public function actionDetail()
- {
- $merchant = isset($this->sj) && !empty($this->sj) ? $this->sj->attributes : [];
- if (empty($merchant)) {
- util::success([]);
- }
- $name = $merchant['name'] ?? '';
- $shopName = $this->shop->shopName ?? '';
- if ($shopName != '首店') {
- $name .= ' ' . $shopName;
- }
- $merchant['name'] = $name;
- $merchant['staff'] = $this->shopAdmin;
- $merchant['shopInfo'] = $this->shop;
- $ext = isset($this->sjExtend) && !empty($this->sjExtend) ? $this->sjExtend->attributes : [];
- $merchant = MerchantService::getInfo($merchant, $ext);
- util::success($merchant);
- }
- //商家现有的会员等级 ssh 2019.12.12
- public function actionMemberLevel()
- {
- $list = MerchantExtendService::getGradeList($this->sjExtend->attributes, false, false);
- $extend = $this->sjExtend->attributes;
- $gradeSwitch = isset($extend['gradeSwitch']) ? $extend['gradeSwitch'] : 1;
- util::success(['list' => $list, 'gradeSwitch' => $gradeSwitch]);
- }
- //会员等级更新 ssh 2019.12.18
- public function actionMemberLevelUpdate()
- {
- $extend = $this->sjExtend->attributes;
- if ($extend['gradeSwitch'] == 0) {
- util::fail('会员等级已设置不能修改');
- }
- $list = Yii::$app->request->post('list');
- if (empty($list) || is_array($list) == false) {
- util::fail('请填写会员等级');
- }
- if (count($list) > 9) {
- util::fail('最多可以设置9个等级');
- }
- $data = [];
- foreach ($list as $key => $val) {
- if ($key > 0) {
- $currentGrowth = $val[1];
- $previousGrowth = $list[$key - 1][1];
- if ($currentGrowth <= $previousGrowth) {
- util::fail('等级越高成长值也要越高');
- }
- $currentDiscount = $val[2];
- $previousDiscount = $list[$key - 1][2];
- if ($currentDiscount >= $previousDiscount) {
- util::fail('等级越高折扣要越低');
- }
- }
- $data[] = $val[0] . '_' . $val[1] . '_' . $val[2];
- }
- if (empty($data)) {
- util::fail('请填写会员等级!');
- }
- $string = implode('I', $data);
- MerchantExtendService::updateByCondition(['sjId' => $this->sjId], ['gradeList' => $string, 'gradeSwitch' => 0]);
- util::complete('提交成功');
- }
- //常用链接
- public function actionCommonUrl()
- {
- $list = MerchantService::getCommonUrlList();
- util::success($list);
- }
- //商家当前的权限id列表 ssh 2020.1.23
- public function actionAuth()
- {
- $merchant = $this->sj->attributes;
- $setId = $merchant['setId'];
- $endId = 1;
- $ids = SetAuthService::getAuthIdList($setId, $endId);
- util::success(['ids' => $ids]);
- }
- //商家信息 ssh 2020.1.11
- public function actionIntroduceShop()
- {
- $ghsShopAdminId = Yii::$app->request->get('ghsShopAdminId');
- $hdShopAdminId = Yii::$app->request->get('hdShopAdminId');
- if (!empty($ghsShopAdminId)) {
- $relation = ShopAdminClass::getById($ghsShopAdminId);
- } else {
- if (empty($hdShopAdminId)) {
- util::success([]);
- }
- $relation = ShopAdminClass::getById($hdShopAdminId);
- }
- if (empty($relation)) {
- util::success([]);
- }
- $sjId = $relation['sjId'];
- $merchant = MerchantClass::getMerchantById($sjId);
- if (empty($merchant)) {
- util::success([]);
- }
- util::success(['introduce' => $merchant]);
- }
- }
|