地区逻辑调整

main
limu 11 months ago
parent f7f6dfbed3
commit 7a498cb4eb
  1. 1
      app/common/dao/system/admin/PartnerDao.php
  2. 30
      app/common/repositories/system/admin/PartnerRepository.php
  3. 16
      app/controller/admin/system/admin/Partner.php
  4. 1
      app/validate/admin/PartnerRoleValidate.php
  5. 60
      config/partner.php

@ -59,6 +59,7 @@ class PartnerDao extends BaseDao
public function existsUser(int $id) public function existsUser(int $id)
{ {
return UserPartner::getInstance()->where('partner_id', $id) return UserPartner::getInstance()->where('partner_id', $id)
->where('uid','<>','')
->field(['id']) ->field(['id'])
->find(); ->find();
} }

@ -18,6 +18,7 @@ namespace app\common\repositories\system\admin;
use app\common\dao\system\admin\PartnerDao; use app\common\dao\system\admin\PartnerDao;
use app\common\model\system\admin\Partner; use app\common\model\system\admin\Partner;
use app\common\repositories\BaseRepository; use app\common\repositories\BaseRepository;
use app\common\model\user\UserPartner;
use app\common\repositories\system\auth\RoleRepository; use app\common\repositories\system\auth\RoleRepository;
use crmeb\exceptions\AuthException; use crmeb\exceptions\AuthException;
use crmeb\services\JwtTokenService; use crmeb\services\JwtTokenService;
@ -30,6 +31,7 @@ use think\db\exception\ModelNotFoundException;
use think\exception\ValidateException; use think\exception\ValidateException;
use think\facade\Cache; use think\facade\Cache;
use think\facade\Config; use think\facade\Config;
use think\facade\Db;
use think\facade\Route; use think\facade\Route;
use think\Model; use think\Model;
@ -70,7 +72,21 @@ class PartnerRepository extends BaseRepository
public function create(array $data) public function create(array $data)
{ {
return $this->dao->create($data); return Db::transaction(function () use ($data) {
//生成角色
$info = $this->dao->create($data);
$userPartner = [];
for ($i = 1;$i <= $data['max_role_num']; $i++ ) {
$name = $i == 1 ? $data['name'] : $data['name'] . '_' . $i;
$userPartner[] = [
'partner_name' => $name,
'partner_id' => $info->id,
];
}
UserPartner::getDB()->insertAll($userPartner);
});
} }
/** /**
@ -100,12 +116,22 @@ class PartnerRepository extends BaseRepository
*/ */
public function update(int $id, array $data) public function update(int $id, array $data)
{ {
$old = $this->dao->get($id)->toArray();
if($old['name'] != $data['name']){
$list = UserPartner::getDB()->where('partner_id',$id)->select();
foreach($list as $k=>$v){
$name = str_replace($old['name'],$data['name'],$v['partner_name']);
UserPartner::getDB()->where('id', $v['id'])->update(['partner_name' => $name]);
}
}
return $this->dao->update($id, $data); return $this->dao->update($id, $data);
} }
//删除 //删除
public function delete(int $id) public function delete(int $id)
{ {
UserPartner::getDB()->where('partner_id', $id)->delete();
return $this->dao->delete($id); return $this->dao->delete($id);
} }
@ -117,6 +143,4 @@ class PartnerRepository extends BaseRepository
} }
} }

@ -49,12 +49,16 @@ class Partner extends BaseController
public function add(PartnerRoleValidate $validate) public function add(PartnerRoleValidate $validate)
{ {
$data = $this->request->params(['name', 'ratio', 'is_area', 'area_level', $data = $this->request->params(['name', 'ratio', 'is_area', 'area_level',
'area_id', ['status', 1], ['type', 1], ['max_role_num', 0], 'brand_id', 'trade_id']); 'area_id', ['status', 1], ['type', 1], ['max_role_num', 1], 'brand_id', 'trade_id', 'region_id']);
$validate->check($data); $validate->check($data);
if ($data['is_area'] == 1 && $this->repository->fieldExists('area_id', $data['area_id'])) { if ($data['is_area'] == 1 && $this->repository->fieldExists('area_id', $data['area_id'])) {
return app('json')->fail('该区域已经有了代理角色,请勿重复添加'); return app('json')->fail('该区域已经有了代理角色,请勿重复添加');
} }
if (($data['type'] == 3 && empty($data['brand_id']) || ($data['type'] == 4 && empty($data['trade_id'])))) { if (
($data['type'] == 3 && empty($data['brand_id']))
|| ($data['type'] == 4 && empty($data['trade_id']))
|| ($data['type'] == 2 && empty($data['region_id']))
) {
return app('json')->fail('请补全对应角色类型的关联数据'); return app('json')->fail('请补全对应角色类型的关联数据');
} }
$this->repository->create($data); $this->repository->create($data);
@ -65,7 +69,7 @@ class Partner extends BaseController
{ {
$data = $this->request->params(['name', 'ratio', 'is_area', 'area_level', $data = $this->request->params(['name', 'ratio', 'is_area', 'area_level',
'area_id', ['status', 1], ['type', 1], ['max_role_num', 0], 'brand_id', 'trade_id','id']); 'area_id', ['status', 1], ['type', 1], 'brand_id', 'trade_id', 'id', 'region_id']);
$validate->check($data); $validate->check($data);
if ($data['is_area'] == 1) { if ($data['is_area'] == 1) {
@ -79,7 +83,11 @@ class Partner extends BaseController
$data['area_level'] = 0; $data['area_level'] = 0;
$data['area_id'] = 0; $data['area_id'] = 0;
} }
if (($data['type'] == 3 && empty($data['brand_id']) || ($data['type'] == 4 && empty($data['trade_id'])))) { if (
($data['type'] == 3 && empty($data['brand_id']))
|| ($data['type'] == 4 && empty($data['trade_id']))
|| ($data['type'] == 2 && empty($data['region_id']))
) {
return app('json')->fail('请补全对应角色类型的关联数据'); return app('json')->fail('请补全对应角色类型的关联数据');
} }

@ -25,5 +25,6 @@ class PartnerRoleValidate extends Validate
'ratio|比例' => 'require', 'ratio|比例' => 'require',
'status|启用状态' => 'require|in:1,2', 'status|启用状态' => 'require|in:1,2',
'type|角色类型' => 'require|in:1,2,3,4', 'type|角色类型' => 'require|in:1,2,3,4',
'max_role_num|配置人数' => 'require|min:1'
]; ];
} }

@ -56,56 +56,42 @@ return [
'pay_community' => '0.03', 'pay_community' => '0.03',
], ],
], ],
//品牌代理商等级配置 //大区配置
'brand_level' => [ 'region_type' => [
[ [
'alias' => '全球品牌代言人', 'id' => 1,
'level_name' => 'B7', 'name' => '华东地区',
'min_price' => '1000000', 'province_ids' => [13,12,14,15,2,16,2768,21],
'pay_community' => '0.3',
'promotion_community' => '0.1'
], ],
[ [
'alias' => '亚太区品牌代言人', 'id' => 2,
'level_name' => 'B6', 'name' => '华南地区',
'min_price' => '500000', 'province_ids' => [19,20,52993,23],
'pay_community' => '0.3',
'promotion_community' => '0.1'
], ],
[ [
'alias' => '中国区品牌代言人', 'id' => 3,
'level_name' => 'B5', 'name' => '华北地区',
'min_price' => '300000', 'province_ids' => [1,3,5,6,11],
'pay_community' => '0.3',
'promotion_community' => '0.1'
], ],
[ [
'alias' => '品牌形象大使', 'id' => 4,
'level_name' => 'B4', 'name' => '华中地区',
'min_price' => '100000', 'province_ids' => [7,17,18],
'pay_community' => '0.3',
'promotion_community' => '0.1'
], ],
[ [
'alias' => '品牌推广大使', 'id' => 5,
'level_name' => 'B3', 'name' => '西南地区',
'min_price' => '50000', 'province_ids' => [25,22,24,26,4],
'pay_community' => '0.3',
'promotion_community' => '0.1'
], ],
[ [
'alias' => '品牌推荐官', 'id' => 6,
'level_name' => 'B2', 'name' => '西北地区',
'min_price' => '30000', 'province_ids' => [27,28,29,30,31],
'pay_community' => '0.3',
'promotion_community' => '0.1'
], ],
[ [
'alias' => '品牌体验官', 'id' => 7,
'level_name' => 'B1', 'name' => '东北地区',
'min_price' => '10000', 'province_ids' => [8,9,10],
'pay_community' => '0.3',
'promotion_community' => '0.1'
], ],
], ],
]; ];

Loading…
Cancel
Save