From f9642ea6cd1252829b30efeecdbd3de9e79da3c3 Mon Sep 17 00:00:00 2001 From: wangxinglong <2371974647@qq.com> Date: Thu, 7 Apr 2022 14:31:17 +0800 Subject: [PATCH] setter --- app/controller/manager/Agency.php | 14 +++++++++----- app/controller/manager/Coupon.php | 6 ++++-- app/controller/manager/Member.php | 2 +- app/repository/BusinessRepository.php | 18 +++++++++++++++++- view/manager/agency/edit_channel.html | 3 +-- 5 files changed, 32 insertions(+), 11 deletions(-) diff --git a/app/controller/manager/Agency.php b/app/controller/manager/Agency.php index 73cb84f..0b5a6c3 100644 --- a/app/controller/manager/Agency.php +++ b/app/controller/manager/Agency.php @@ -4,6 +4,7 @@ namespace app\controller\manager; use app\model\Business as BusinessModel; use app\model\Log; +use app\model\Member; use app\model\Member as MemberModel; use app\repository\BusinessRepository; use Exception; @@ -30,6 +31,11 @@ class Agency extends Base public function add() { if ($this->request->isPost()) { + $roles = array_filter( explode(",",$this->auth["roles"])); + //如果是 渠道商或者工作人员 + if(!in_array(Member::ANENT_ROLE_ID,$roles)){ + return $this->json(4001,"您不是是代理商,不能添加工作人员"); + } $item = input('post.'); $validate = $this->validateByApi($item, [ @@ -71,8 +77,6 @@ class Agency extends Base } $this->data['roleJson'] = $this->roleJson(); - $this->data['business'] = BusinessRepository::getInstance()->getBusinessAll(); - return $this->view(); } @@ -127,7 +131,7 @@ class Agency extends Base } $this->data['roleJson'] = $this->roleJson(); - $this->data['business'] = BusinessRepository::getInstance()->getBusinessAll(); + $this->data['business'] = BusinessRepository::getInstance()->getBusinessAll($this->auth["roles"],$this->auth["business_code"]); return $this->view(); } @@ -256,7 +260,7 @@ class Agency extends Base $this->data['item'] = $info; - $this->data['business'] = BusinessRepository::getInstance()->getBusinessAll(); + $this->data['business'] = BusinessRepository::getInstance()->getBusinessAll($this->auth["roles"],$this->auth["business_code"]); return $this->view(); } @@ -287,7 +291,7 @@ class Agency extends Base } /** - * 渠道商列表 + * 代理商列表 * * @return Json|View * @throws Exception diff --git a/app/controller/manager/Coupon.php b/app/controller/manager/Coupon.php index 56cec18..3d533f5 100644 --- a/app/controller/manager/Coupon.php +++ b/app/controller/manager/Coupon.php @@ -380,7 +380,9 @@ class Coupon extends Base } - $this->data['business'] = BusinessRepository::getInstance()->getBusinessAll(); + + $this->data['business'] = BusinessRepository::getInstance()->getBusinessAll($this->auth["roles"],$this->auth["business_code"]); + $this->data['type'] = CouponRepository::getInstance()->getCouponTypeAll(); return $this->view('add'); @@ -537,7 +539,7 @@ class Coupon extends Base if (empty($couponMain)) { return $this->error("签到券不存在"); } - $this->data['business'] = BusinessRepository::getInstance()->getBusinessAll(); + $this->data['business'] = BusinessRepository::getInstance()->getBusinessAll($this->auth["roles"],$this->auth["business_code"]); $this->data['type'] = CouponRepository::getInstance()->getCouponTypeAll(); $this->data['item'] = $couponMain; diff --git a/app/controller/manager/Member.php b/app/controller/manager/Member.php index 80c8670..cecb446 100644 --- a/app/controller/manager/Member.php +++ b/app/controller/manager/Member.php @@ -178,7 +178,7 @@ class Member extends Base $this->data['item'] = $info; $this->data['roleJson'] = $this->roleJson(explode(',', $info['roles'])); - $this->data['business'] = BusinessRepository::getInstance()->getBusinessAll(); + $this->data['business'] = BusinessRepository::getInstance()->getBusinessAll($this->auth["roles"],$this->auth["business_code"]); return $this->view(); } diff --git a/app/repository/BusinessRepository.php b/app/repository/BusinessRepository.php index 4e70402..845d303 100644 --- a/app/repository/BusinessRepository.php +++ b/app/repository/BusinessRepository.php @@ -7,6 +7,7 @@ use app\model\Account; use app\model\Business; use app\model\CouponMain; use app\model\Deduction; +use app\model\Member; use app\model\Recharge; use app\service\Repository; use app\traits\account\ApplyStaffTrait; @@ -136,11 +137,26 @@ class BusinessRepository extends Repository } /* 获取所有的商家*/ - public function getBusinessAll() + public function getBusinessAll($roles = "",$businessCode ="") { + $roles = array_filter( explode(",",$roles)); + + $isAdmin = true; + //如果是 渠道商或者工作人员 + if( + in_array(Member::ANENT_ROLE_ID,$roles) + || + in_array(Member::STAFF_ROLE_ID,$roles) + ){ + $isAdmin=false; + } + return Business::alias("a") ->join("account b", "a.code = b.business_code") ->field("a.code , a.business_name , a.contact_name") + ->when(!$isAdmin,function ($q)use($businessCode){ + $q->where("a.agency_code",$businessCode); + }) ->order("a.id desc") ->group("a.id") ->select(); diff --git a/view/manager/agency/edit_channel.html b/view/manager/agency/edit_channel.html index ccf0e42..941a009 100644 --- a/view/manager/agency/edit_channel.html +++ b/view/manager/agency/edit_channel.html @@ -35,8 +35,7 @@