地区逻辑调整

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)
{
return UserPartner::getInstance()->where('partner_id', $id)
->where('uid','<>','')
->field(['id'])
->find();
}

@ -18,6 +18,7 @@ namespace app\common\repositories\system\admin;
use app\common\dao\system\admin\PartnerDao;
use app\common\model\system\admin\Partner;
use app\common\repositories\BaseRepository;
use app\common\model\user\UserPartner;
use app\common\repositories\system\auth\RoleRepository;
use crmeb\exceptions\AuthException;
use crmeb\services\JwtTokenService;
@ -30,6 +31,7 @@ use think\db\exception\ModelNotFoundException;
use think\exception\ValidateException;
use think\facade\Cache;
use think\facade\Config;
use think\facade\Db;
use think\facade\Route;
use think\Model;
@ -70,7 +72,21 @@ class PartnerRepository extends BaseRepository
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)
{
$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);
}
//删除
public function delete(int $id)
{
UserPartner::getDB()->where('partner_id', $id)->delete();
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)
{
$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);
if ($data['is_area'] == 1 && $this->repository->fieldExists('area_id', $data['area_id'])) {
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('请补全对应角色类型的关联数据');
}
$this->repository->create($data);
@ -65,7 +69,7 @@ class Partner extends BaseController
{
$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);
if ($data['is_area'] == 1) {
@ -79,7 +83,11 @@ class Partner extends BaseController
$data['area_level'] = 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('请补全对应角色类型的关联数据');
}

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

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

Loading…
Cancel
Save