添加:代理中心 - 申请成为代理人员

This commit is contained in:
wuhui_zzw 2024-02-01 15:39:24 +08:00
parent 4c9ac5189a
commit 8f8dc5912e
10 changed files with 385 additions and 15 deletions

View File

@ -0,0 +1,75 @@
<?php
namespace app\common\dao\marketing;
use app\common\dao\BaseDao;
use app\common\model\marketing\AgentApply;
class AgentApplyDao extends BaseDao{
protected function getModel(): string{
return AgentApply::class;
}
/**
* Common: 公共搜索查询
* Author: wu-hui
* Time: 2024/02/01 14:02
* @param array $params
* @return AgentApply
*/
public function searchList(array $params){
return (new AgentApply())
->when(isset($params['id']) && $params['id'] !== '',function($query) use ($params){
$query->where('id', (int)$params['id']);
})
->when(isset($params['uid']) && $params['uid'] !== '',function($query) use ($params){
$query->where('uid', (int)$params['uid']);
})
->when(isset($params['pid']) && $params['pid'] !== '',function($query) use ($params){
$query->where('pid', (int)$params['pid']);
})
->when(isset($params['contact_name']) && $params['contact_name'] !== '',function($query) use ($params){
$query->where('contact_name', 'like', "%{$params['contact_name']}%");
})
->when(isset($params['contact_phone']) && $params['contact_phone'] !== '',function($query) use ($params){
$query->where('contact_phone', $params['contact_phone']);
})
->when(isset($params['agent_type']) && $params['agent_type'] !== '',function($query) use ($params){
$query->where('agent_type', (int)$params['agent_type']);
})
->with([
'user' => function($query){
$query->field('uid,nickname,avatar');
},
'province' => function($query){
$query->field('id,name as province_name,code as province_code')->bind(['province_name', 'province_code']);
},
'city' => function($query){
$query->field('id,name as city_name,code as city_code')->bind(['city_name', 'city_code']);
},
'area' => function($query){
$query->field('id,name as area_name,code as area_code')->bind(['area_name', 'area_code']);
},
'street' => function($query){
$query->field('id,name as street_name,code as street_code')->bind(['street_name', 'street_code']);
},
'parent' => function($query){
$query->field('id,uid,agent_type')
->with([
'user' => function($query){
$query->field('uid,nickname,avatar')->bind(['nickname','avatar']);
}
]);
},
])
->order('create_time DESC,id DESC');
}
}

View File

@ -50,7 +50,7 @@ class StoreGroupOrderDao extends BaseDao
$query = StoreGroupOrder::getDB()->when(isset($where['paid']) && $where['paid'] !== '', function ($query) use ($where) {
$query->where('paid', $where['paid']);
})
->whereNotIn('activity_type', [30,31])
->whereNotIn('activity_type', [30,31,32])
->when(isset($where['paid']) && $where['paid'] !== '', function ($query) use ($where) {
$query->where('paid', $where['paid']);
})

View File

@ -0,0 +1,39 @@
<?php
namespace app\common\model\marketing;
use app\common\model\BaseModel;
use app\common\model\store\CityArea;
use app\common\model\user\User;
class AgentApply extends BaseModel{
public static function tablePk(): string{
return 'id';
}
public static function tableName(): string{
return 'agent_apply';
}
public function user(){
return $this->hasOne(User::class, 'uid', 'uid');
}
public function parent(){
return $this->hasOne(self::class, 'id', 'pid');
}
public function province(){
return $this->hasOne(CityArea::class, 'id', 'province_id');
}
public function city(){
return $this->hasOne(CityArea::class, 'id', 'city_id');
}
public function area(){
return $this->hasOne(CityArea::class, 'id', 'area_id');
}
public function street(){
return $this->hasOne(CityArea::class, 'id', 'street_id');
}
}

View File

@ -0,0 +1,128 @@
<?php
namespace app\common\repositories\marketing;
use app\common\dao\marketing\AgentApplyDao;
use app\common\repositories\BaseRepository;
use app\common\repositories\store\order\StoreOrderCreateRepository;
use app\common\repositories\store\order\StoreOrderRepository;
use crmeb\services\LockService;
use think\facade\Db;
class AgentApplyRepository extends BaseRepository{
protected $dao;
public function __construct(AgentApplyDao $dao){
$this->dao = $dao;
}
/**
* Common: 公共查询模型
* Author: wu-hui
* Time: 2024/02/01 14:56
* @param $search
* @return \app\common\model\marketing\AgentApply
*/
public function getSearchModel($search){
return $this->dao->searchList($search);
}
// 提交申请信息(同步生成订单)
public function editApplyInfo($params){
return Db::transaction(function() use ($params){
// 生成申请信息
$applyInfoKeys = array_flip((array)[
"uid",
"pid",
"agent_type",
"contact_name",
"contact_phone",
"province_id",
"city_id",
"area_id",
"street_id",
"address",
"mer_name",
"mer_class_id",
"mer_type_id",
"mer_images"
]);
$applyInfo = array_intersect_key($params['data'], $applyInfoKeys);
// 支付信息
$payInfo = array_intersect_key($params['data'],array_flip((array)["pay_type","return_url"]));
$payResult = [];
// 根据操作类型进行对应的处理
if($params['agentApplyId'] > 0){
// 编辑
debug("开发中......");
return '成功';
}
else{
// 添加 是否需要支付
$payMoney = 0;// 默认 无需支付
$config = app()->make(AgentRepository::class)->getConfig();
switch ((int)$applyInfo['agent_type']) {
case 2: $payMoney = $config['province_money'] ?? 0;break;
case 3: $payMoney = $config['field_staff_money'] ?? 0;break;
case 4: $payMoney = $config['internal_staff_money'] ?? 0;break;
case 5: $payMoney = $config['operator_money'] ?? 0;break;
case 6: $payMoney = $config['partner_money'] ?? 0;break;
case 7: $payMoney = $config['mer_money'] ?? 0;break;
case 8: $payMoney = $config['delivery_money'] ?? 0;break;
}
// 判断:是否需要支付 需要支付生成订单并且获取支付信息
$orderId = 0;// 默认 无需支付、无订单信息
if((float)$payMoney > 0){
$userInfo = $params['user_info'] ?? [];
$payInfo['money'] = (float)$payMoney;
// 发起支付
$groupOrder = app()
->make(LockService::class)
->exec('online_order.create',function() use ($payInfo,$userInfo){
$payType = array_search($payInfo['pay_type'],StoreOrderRepository::PAY_TYPE);
return app()
->make(StoreOrderCreateRepository::class)
->onlinePayment($payType,$payInfo,$userInfo, 32);
});
$payResult = app()
->make(StoreOrderRepository::class)
->pay($payInfo['pay_type'],$userInfo,$groupOrder,$payInfo['return_url'],$params['is_app']);
// 子订单只存在一个 直接查询即可
$orderId = app()->make(StoreOrderRepository::class)
->getSearch([])
->where('group_order_id',$groupOrder->group_order_id)
->value('order_id');
}
// 生成申请信息
$applyInfo['order_id'] = $orderId;
$this->dao->create($applyInfo);
return $payResult;
}
});
}
}

View File

@ -17,6 +17,17 @@ class AgentRepository extends BaseRepository{
public function __construct(AgentDao $dao){
$this->dao = $dao;
}
/**
* Common: 公共查询模型
* Author: wu-hui
* Time: 2024/02/01 15:01
* @param $search
* @return Agent
*/
public function getSearchModel($search){
return $this->dao->searchList($search);
}
/**
* Common: 获取信息列表
* Author: wu-hui

View File

@ -2808,10 +2808,10 @@ class StoreOrderCreateRepository extends StoreOrderRepository{
}*/
// 在线买单 - 订单
public function onlinePayment($payType, $payInfo, $user){
// 在线买单 - 订单、代理入驻 - 订单
public function onlinePayment($payType, $payInfo, $user, $activityType = 30){
$payMoney = abs((float)$payInfo['money']);
$merId = (int)$payInfo['mer_id'];
$merId = array_key_exists('mer_id',$payInfo) ? (int)$payInfo['mer_id'] : 0;
$uid = $user->uid;
// 是否自购
$isSelfBuy = $user->is_promoter && systemConfig('extension_self') ? 1 : 0;
@ -2825,7 +2825,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository{
// 整理订单数据
$orderList[] = [
'cartInfo' => [],
'activity_type' => 30,// 30=在线买单
'activity_type' => $activityType,// 30=在线买单32=代理入驻
'commission_rate' => 0,
'order_type' => 0,
'is_virtual' => 1,
@ -2849,7 +2849,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository{
'integral' => 0,
'integral_price' => 0,
'give_integral' => 0,
'mer_id' => $merId,
'mer_id' => $merId ?? 0,
'cost' => 0,
'order_extend' => '',
'coupon_id' => '',
@ -2878,7 +2878,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository{
'integral' => 0,
'integral_price' => 0,
'give_integral' => 0,
'activity_type' => 30,// 30=在线买单
'activity_type' => $activityType,// 30=在线买单32=代理入驻
];
$group = Db::transaction(function() use ($user,$groupOrder,$orderList){
$storeGroupOrderRepository = app()->make(StoreGroupOrderRepository::class);

View File

@ -150,6 +150,9 @@ class StoreOrderRepository extends BaseRepository
}else if($groupOrder['activity_type'] == 31){
$data['title'] = '酒道馆差价补齐';
$data['mark'] = '余额支付' . floatval($groupOrder['pay_price']) . '元';
}else if($groupOrder['activity_type'] == 32){
$data['title'] = '用户申请成为代理人员';
$data['mark'] = '余额支付' . floatval($groupOrder['pay_price']) . '元';
}
$userBillRepository->decBill($user['uid'], 'now_money', 'pay_product', $data);
@ -252,7 +255,7 @@ class StoreOrderRepository extends BaseRepository
app()->make(ProductAssistSetRepository::class)->changStatus($order->orderProduct[0]['activity_id']);
}
if ($order->order_type == 1 && $order->status != 10) $order->verify_code = $this->verifyCode();
if (!in_array($order->activity_type,[30,31]) && $order->orderProduct[0]->product->type == 2) {
if (!in_array($order->activity_type,[30,31,32]) && $order->orderProduct[0]->product->type == 2) {
$order->status = 2;
$order->delivery_type = 6;
$order->delivery_name = '自动发货';
@ -260,7 +263,7 @@ class StoreOrderRepository extends BaseRepository
$isPoints = true;
}
// 判断:是否为在线买单、酒道馆补差价 在线买单,订单支付则订单完成
if(in_array($order->activity_type,[30,31])){
if(in_array($order->activity_type,[30,31,32])){
$order->status = 3;
}

View File

@ -3,10 +3,12 @@
namespace app\controller\api;
use app\common\model\system\merchant\Merchant;
use app\common\repositories\marketing\AgentApplyRepository;
use app\common\repositories\marketing\AgentRepository;
use crmeb\basic\BaseController;
use think\App;
use think\exception\ValidateException;
class Agent extends BaseController{
@ -58,10 +60,119 @@ class Agent extends BaseController{
return app('json')->success($res);
}
/**
* Common: 获取配置信息
* Author: wu-hui
* Time: 2024/01/31 15:49
* @return mixed
*/
public function getConfig(){
$config = app()->make(AgentRepository::class)->getConfig();
return app('json')->success($config);
}
/**
* Common: 申请成为代理
* Author: wu-hui
* Time: 2024/02/01 15:14
* @return mixed
*/
public function apply(){
// 获取申请参数
$params = $this->applyCheckParams();
// 处理数据
$params['user_info'] = $this->request->userInfo();
$params['is_app'] = $this->request->isApp();
$res = app()->make(AgentApplyRepository::class)->editApplyInfo($params);
if($res) return $res;
else return app('json')->success("操作成功");
}
/**
* Common: 申请参数获取 & 参数校验
* Author: wu-hui
* Time: 2024/02/01 13:41
* @return array
*/
public function applyCheckParams():array{
// 参数获取
$agentApplyId = (int)$this->request->param('id');
$data = $this->request->params([
['pid',0],
['agent_type',0],
'contact_name',
'contact_phone',
['province_id',0],
['city_id', 0],
['area_id', 0],
['street_id', 0],
'address',
['mer_name', ''],
['mer_class_id', 0],
['mer_type_id', 0],
['mer_images', []],
// 支付相关
'pay_type',
'return_url'
]);
$data['uid'] = $this->request->uid();
// 信息验证
if((int)$data['pid'] <= 0) throw new ValidateException('非法请求,无邀请信息!');
if(!in_array((int)$data['agent_type'], [2,3,4,5,6,7,8])) throw new ValidateException('非法请求,代理类型错误!');
if(empty($data['contact_name'])) throw new ValidateException('请输入联系人姓名!');
if(empty($data['contact_phone'])) throw new ValidateException('请输入联系人电话!');
if((int)$data['province_id'] <= 0) throw new ValidateException('请选择地区!');
if(in_array((int)$data['agent_type'], [5,6,7])){
if((int)$data['city_id'] <= 0) throw new ValidateException('请选择地区!');
if((int)$data['area_id'] <= 0) throw new ValidateException('请选择地区!');
}
if((int)$data['agent_type'] == 7){
if((int)$data['street_id'] <= 0) throw new ValidateException('请选择地区!');
if(empty($data['address'])) throw new ValidateException('请输入详细地址!');
if(empty($data['mer_name'])) throw new ValidateException('请输入商户名称!');
if((int)$data['mer_class_id'] <= 0) throw new ValidateException('请选择商户分类!');
if((int)$data['mer_type_id'] <= 0) throw new ValidateException('请选择商户类型!');
if(count($data['mer_images']) <= 0) throw new ValidateException('请上传资质证明图片!');
// 判断:商户名称是否重复
$merHas = Merchant::where('mer_name',$data['mer_name'])->count();
if($merHas > 0) throw new ValidateException('商户已经存在!');
// 判断:商户名称是否重复
$isHas = app()->make(AgentApplyRepository::class)
->getSearchModel([])
->where('mer_name', $data['mer_name'])
->when($agentApplyId > 0,function($query) use ($agentApplyId){
$query->where('id','!=',$agentApplyId);
})
->count();
if($isHas > 0) throw new ValidateException('商户已经存在,请勿重复申请!');
}
// 信息是否重复
$isHas = (int)app()->make(AgentApplyRepository::class)
->getSearchModel(['contact_phone'=>$data['contact_phone']])
->when($agentApplyId > 0,function($query) use ($agentApplyId){
$query->where('id','!=',$agentApplyId);
})->count();
if($isHas > 0) throw new ValidateException('联系人电话已经存在,请勿重复申请!');
$isHas = (int)$this->repository
->getSearchModel(['contact_phone'=>$data['contact_phone']])
->count();
if($isHas > 0) throw new ValidateException('联系人电话已经存在,请勿重复申请!');
// 不能 重复成为当前等级的用户
$isHas = (int)$this->repository
->getSearchModel(['agent_type'=>$data['agent_type'],'uid'=>$data['uid']])
->count();
if($isHas > 0) throw new ValidateException('代理身份信息已经存在!');
$isHas = (int)app()->make(AgentApplyRepository::class)
->getSearchModel(['agent_type'=>$data['agent_type'],'uid'=>$data['uid']])
->when($agentApplyId > 0,function($query) use ($agentApplyId){
$query->where('id','!=',$agentApplyId);
})->count();
if($isHas > 0) throw new ValidateException('代理身份信息已经存在,请勿重复申请!');
return compact("agentApplyId", "data");
}
}

View File

@ -25,8 +25,10 @@ class OrderPaySuccessEvent{
// 在线支付订单
$this->giveExchangeIntegral($groupOrder);
}else if($groupOrder->activity_type == 31){
// 在线支付订单
// 兑换商品补差价处理
$this->exchangeGoodsHandle($groupOrder);
}else if($groupOrder->activity_type == 32){
// 代理入驻支付
}else{
// 其他订单
$this->orderPaySuccessHandle($groupOrder);

View File

@ -387,8 +387,8 @@ Route::group('api/', function () {
Route::get('agent_list', 'agentList');// 我的代理身份列表
Route::get('qr_code_invite', 'qrCodeInviteSupplier');// 供应商邀请二维码
Route::get('single_agent_info/:id', 'singleAgentInfo');// 获取单个代理人员信息
Route::get('get_config', 'getConfig');// 获取配置信息
Route::post('agent_apply', 'apply');// 提交申请信息
@ -534,6 +534,7 @@ Route::group('api/', function () {
Route::get('list', 'api.store.product.StoreCoupon/lst');
Route::get('getlst', 'api.store.product.StoreCoupon/getList');
Route::get('new_people', 'api.store.product.StoreCoupon/newPeople');
Route::get('create_qrcode', 'api.store.product.StoreCoupon/createQRcode');
});
//商户