添加:代理中心 - 代理审核通过后佣金处理及免审核处理
This commit is contained in:
parent
e4cfd30c3a
commit
ea3f5e6b07
|
|
@ -43,6 +43,9 @@ class AgentApplyDao extends BaseDao{
|
|||
->when(isset($params['status']) && $params['status'] !== '',function($query) use ($params){
|
||||
$query->where('status', (int)$params['status']);
|
||||
})
|
||||
->when(isset($params['order_id']) && $params['order_id'] !== '',function($query) use ($params){
|
||||
$query->where('order_id', (int)$params['order_id']);
|
||||
})
|
||||
->with([
|
||||
'user' => function($query){
|
||||
$query->field('uid,nickname,avatar');
|
||||
|
|
@ -74,7 +77,7 @@ class AgentApplyDao extends BaseDao{
|
|||
$query->field('mer_type_id,type_name as mer_type_name')->bind(['mer_type_name']);
|
||||
},
|
||||
'orderInfo' => function($query){
|
||||
$query->field('order_id,status,order_sn');
|
||||
$query->field('order_id,status,order_sn,group_order_id,pay_price');
|
||||
},
|
||||
])
|
||||
->order('create_time DESC,id DESC');
|
||||
|
|
|
|||
|
|
@ -39,22 +39,28 @@ class AgentBrokerageDao extends BaseDao{
|
|||
'userOrder' => function($query){
|
||||
$query->field('order_id,order_sn,create_time,title');
|
||||
},
|
||||
'staff' => function($query){
|
||||
'staff' => function($query){
|
||||
$query->field('uid,nickname,avatar');
|
||||
},
|
||||
'store' => function($query){
|
||||
'store' => function($query){
|
||||
$query->field('uid,nickname,avatar');
|
||||
},
|
||||
'area' => function($query){
|
||||
'area' => function($query){
|
||||
$query->field('uid,nickname,avatar');
|
||||
},
|
||||
'areaStore' => function($query){
|
||||
$query->field('uid,nickname,avatar');
|
||||
},
|
||||
'delivery' => function($query){
|
||||
'delivery' => function($query){
|
||||
$query->field('uid,nickname,avatar');
|
||||
},
|
||||
'province' => function($query){
|
||||
'province' => function($query){
|
||||
$query->field('uid,nickname,avatar');
|
||||
},
|
||||
'initiator' => function($query){
|
||||
$query->field('uid,nickname,avatar');
|
||||
},
|
||||
'fieldStaff' => function($query){
|
||||
$query->field('uid,nickname,avatar');
|
||||
},
|
||||
])
|
||||
|
|
|
|||
|
|
@ -43,32 +43,37 @@ class AgentDao extends BaseDao{
|
|||
$query->whereIn('agent_type',[1,2,3,4,5]);
|
||||
})
|
||||
->with([
|
||||
'user' => function($query){
|
||||
'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']);
|
||||
$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']);
|
||||
'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']);
|
||||
'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']);
|
||||
'street' => function($query){
|
||||
$query->field('id,name as street_name,code as street_code')
|
||||
->bind(['street_name','street_code']);
|
||||
},
|
||||
'mer' => function($query){
|
||||
'mer' => function($query){
|
||||
$query->field('mer_id,mer_name,mer_avatar');
|
||||
},
|
||||
'merList' => function($query){
|
||||
'merList' => function($query){
|
||||
$query->field('agent_id,mer_name,mer_avatar');
|
||||
},
|
||||
'parent' => function($query){
|
||||
'parent' => function($query){
|
||||
$query->field('id,uid,agent_type')
|
||||
->with([
|
||||
'user' => function($query){
|
||||
$query->field('uid,nickname,avatar')->bind(['nickname','avatar']);
|
||||
$query->field('uid,nickname,avatar')
|
||||
->bind(['nickname','avatar']);
|
||||
}
|
||||
]);
|
||||
},
|
||||
|
|
@ -78,10 +83,4 @@ class AgentDao extends BaseDao{
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,6 +66,9 @@ class Agent extends BaseModel{
|
|||
public function parent(){
|
||||
return $this->hasOne(self::class, 'id', 'pid');
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function province(){
|
||||
return $this->hasOne(CityArea::class, 'id', 'province_id');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,10 +20,6 @@ class AgentApply extends BaseModel{
|
|||
return 'agent_apply';
|
||||
}
|
||||
|
||||
|
||||
public function setMerImagesAttr($value){
|
||||
return implode(',',$value);
|
||||
}
|
||||
public function getMerImagesAttr($value){
|
||||
if(!empty($value)) return explode(',',$value);
|
||||
|
||||
|
|
|
|||
|
|
@ -38,6 +38,12 @@ class AgentBrokerage extends BaseModel{
|
|||
public function province(){
|
||||
return $this->hasOne(User::class,'uid', 'province_uid');
|
||||
}
|
||||
public function initiator(){
|
||||
return $this->hasOne(User::class,'uid', 'initiator_uid');
|
||||
}
|
||||
public function fieldStaff(){
|
||||
return $this->hasOne(User::class,'uid', 'field_staff_uid');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -49,7 +49,13 @@ class AgentApplyRepository extends BaseRepository{
|
|||
|
||||
return compact('count','list');
|
||||
}
|
||||
// 提交申请信息(同步生成订单)
|
||||
/**
|
||||
* Common: 提交申请信息(同步生成订单)
|
||||
* Author: wu-hui
|
||||
* Time: 2024/02/02 11:21
|
||||
* @param $params
|
||||
* @return mixed
|
||||
*/
|
||||
public function editApplyInfo($params){
|
||||
return Db::transaction(function() use ($params){
|
||||
// 生成申请信息
|
||||
|
|
@ -70,19 +76,17 @@ class AgentApplyRepository extends BaseRepository{
|
|||
"mer_images"
|
||||
]);
|
||||
$applyInfo = array_intersect_key($params['data'], $applyInfoKeys);
|
||||
$applyInfo['mer_images'] = implode(',',$applyInfo['mer_images']);
|
||||
// 支付信息
|
||||
$payInfo = array_intersect_key($params['data'],array_flip((array)["pay_type","return_url"]));
|
||||
$payResult = [];
|
||||
// 根据操作类型进行对应的处理
|
||||
if($params['agentApplyId'] > 0){
|
||||
// 编辑
|
||||
$applyInfo['status'] = 0;
|
||||
$applyInfo['reason'] = '';
|
||||
|
||||
|
||||
|
||||
|
||||
debug("开发中......");
|
||||
|
||||
return '成功';
|
||||
$this->dao->update($params['agentApplyId'], $applyInfo);
|
||||
}
|
||||
else{
|
||||
// 添加 是否需要支付
|
||||
|
|
@ -123,9 +127,9 @@ class AgentApplyRepository extends BaseRepository{
|
|||
// 生成申请信息
|
||||
$applyInfo['order_id'] = $orderId;
|
||||
$this->dao->create($applyInfo);
|
||||
|
||||
return $payResult;
|
||||
}
|
||||
|
||||
return $payResult;
|
||||
});
|
||||
}
|
||||
/**
|
||||
|
|
@ -173,9 +177,10 @@ class AgentApplyRepository extends BaseRepository{
|
|||
'is_bro_goods' => $config['broadcast_goods_type'] == 1 ? 0 : 1,
|
||||
'mer_password' => $password,
|
||||
'is_margin' => $margin['is_margin'] ?? -1,
|
||||
'margin' => $margin['margin'] ?? 0,
|
||||
'agent_id' => $agentId
|
||||
'margin' => $margin['margin'] ?? 0
|
||||
]);
|
||||
// 关联商户信息
|
||||
Agent::update(['mer_id'=>$merchant->mer_id],['id'=>$agentId]);
|
||||
// 存在默认管理员信息 生成管理员
|
||||
$staffUserInfo = User::where('uid', $applyInfo['uid'])->findOrEmpty()->toArray();
|
||||
$staffData = [
|
||||
|
|
@ -199,7 +204,6 @@ class AgentApplyRepository extends BaseRepository{
|
|||
];
|
||||
app()->make(StoreServiceRepository::class)->createInfo($staffData);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -207,15 +211,4 @@ class AgentApplyRepository extends BaseRepository{
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,10 @@
|
|||
namespace app\common\repositories\marketing;
|
||||
|
||||
use app\common\dao\marketing\AgentBrokerageDao;
|
||||
use app\common\model\marketing\AgentBrokerage;
|
||||
use app\common\repositories\BaseRepository;
|
||||
|
||||
use think\facade\Db;
|
||||
use think\facade\Log;
|
||||
|
||||
class AgentBrokerageRepository extends BaseRepository{
|
||||
|
||||
|
|
@ -32,15 +34,112 @@ class AgentBrokerageRepository extends BaseRepository{
|
|||
|
||||
return compact('count','list');
|
||||
}
|
||||
/**
|
||||
* Common: 邀请代理人员奖励
|
||||
* Author: wu-hui
|
||||
* Time: 2024/02/02 14:20
|
||||
* @param int $orderId
|
||||
* @return mixed
|
||||
*/
|
||||
public function inviteAgentGive(int $orderId){
|
||||
Log::info('支付成功 - 邀请代理人员奖励及免审核 - 开始处理: '.$orderId);
|
||||
return Db::transaction(function() use ($orderId){
|
||||
// 获取配置信息
|
||||
$config = app()->make(AgentRepository::class)->getConfig();
|
||||
// 获取申请信息
|
||||
$applyInfo = app()->make(AgentApplyRepository::class)->getSearchModel(['order_id'=>$orderId])->findOrEmpty()->toArray();
|
||||
// 获取全部上级
|
||||
$upAllList = app()->make(AgentRepository::class)->getAllUp($applyInfo['pid']);
|
||||
$upAllList = array_column($upAllList, null, 'agent_type');
|
||||
// 获取佣金信息 类型:1=发起人,2=省公司,3=省合伙人(外勤),4=省合伙人(内勤),5=区县运营商,6=区县合伙人,7=餐厅,8=配送商
|
||||
$initiator = $upAllList[1] ?? [];
|
||||
$province = $upAllList[2] ?? [];
|
||||
$fieldStaff = $upAllList[3] ?? [];
|
||||
$areaStore = $upAllList[5] ?? [];
|
||||
$area = $upAllList[6] ?? [];
|
||||
$data = [
|
||||
'source' => 1,
|
||||
'user_order_id' => $orderId,
|
||||
// 发起人
|
||||
'initiator_uid' => $initiator ? $initiator['uid'] : 0,
|
||||
'initiator_agent_id' => $initiator ? $initiator['id'] : 0,
|
||||
// 省公司
|
||||
'province_uid' => $province ? $province['uid'] : 0,
|
||||
'province_agent_id' => $province ? $province['id'] : 0,
|
||||
// 外勤
|
||||
'field_staff_uid' => $fieldStaff ? $fieldStaff['uid'] : 0,
|
||||
'field_staff_agent_id' => $fieldStaff ? $fieldStaff['id'] : 0,
|
||||
// 运营商
|
||||
'area_store_uid' => $areaStore ? $areaStore['uid'] : 0,
|
||||
'area_store_agent_id' => $areaStore ? $areaStore['id'] : 0,
|
||||
// 合伙人
|
||||
'area_uid' => $area ? $area['uid'] : 0,
|
||||
'area_agent_id' => $area ? $area['id'] : 0,
|
||||
];
|
||||
$isToExamine = 0;// 是否免审核 0=需要审核,1=无需审核
|
||||
switch((int)$applyInfo['agent_type']){
|
||||
case 2:
|
||||
$isToExamine = $config['province_process'] ?? 0;
|
||||
$data['platform_brokerage'] = $config['province_money_platform'] ?? 0;
|
||||
$data['initiator_brokerage'] = $config['province_money_initiator'] ?? 0;
|
||||
break;
|
||||
case 3:
|
||||
$isToExamine = $config['field_staff_process'] ?? 0;
|
||||
$data['platform_brokerage'] = $config['field_staff_money_platform'] ?? 0;
|
||||
$data['initiator_brokerage'] = $config['field_staff_money_initiator'] ?? 0;
|
||||
$data['province_brokerage'] = $config['field_staff_money_province'] ?? 0;
|
||||
break;
|
||||
case 4:
|
||||
$isToExamine = $config['internal_staff_process'] ?? 0;
|
||||
$data['platform_brokerage'] = $config['internal_staff_money_platform'] ?? 0;
|
||||
$data['initiator_brokerage'] = $config['internal_staff_money_initiator'] ?? 0;
|
||||
$data['province_brokerage'] = $config['internal_staff_money_province'] ?? 0;
|
||||
break;
|
||||
case 5:
|
||||
$isToExamine = $config['operator_process'] ?? 0;
|
||||
$data['platform_brokerage'] = $config['operator_money_platform'] ?? 0;
|
||||
$data['initiator_brokerage'] = $config['operator_money_initiator'] ?? 0;
|
||||
$data['province_brokerage'] = $config['operator_money_province'] ?? 0;
|
||||
$data['field_staff_brokerage'] = $config['operator_money_field_staff'] ?? 0;
|
||||
break;
|
||||
case 6:
|
||||
$isToExamine = $config['partner_process'] ?? 0;
|
||||
$data['platform_brokerage'] = $config['partner_money_platform'] ?? 0;
|
||||
$data['initiator_brokerage'] = $config['partner_money_initiator'] ?? 0;
|
||||
$data['province_brokerage'] = $config['partner_money_province'] ?? 0;
|
||||
$data['field_staff_brokerage'] = $config['partner_money_field_staff'] ?? 0;
|
||||
$data['area_store_brokerage'] = $config['partner_money_operator'] ?? 0;
|
||||
break;
|
||||
case 7:
|
||||
$isToExamine = $config['mer_process'] ?? 0;
|
||||
$data['platform_brokerage'] = $config['mer_money_platform'] ?? 0;
|
||||
$data['initiator_brokerage'] = $config['mer_money_initiator'] ?? 0;
|
||||
$data['province_brokerage'] = $config['mer_money_province'] ?? 0;
|
||||
$data['field_staff_brokerage'] = $config['mer_money_field_staff'] ?? 0;
|
||||
$data['area_store_brokerage'] = $config['mer_money_operator'] ?? 0;
|
||||
$data['area_brokerage'] = $config['mer_money_partner'] ?? 0;
|
||||
break;
|
||||
case 8:
|
||||
$isToExamine = $config['delivery_process'] ?? 0;
|
||||
$data['platform_brokerage'] = $config['delivery_money_platform'] ?? 0;
|
||||
$data['initiator_brokerage'] = $config['delivery_money_initiator'] ?? 0;
|
||||
$data['province_brokerage'] = $config['delivery_money_province'] ?? 0;
|
||||
$data['field_staff_brokerage'] = $config['delivery_money_field_staff'] ?? 0;
|
||||
$data['area_store_brokerage'] = $config['delivery_money_operator'] ?? 0;
|
||||
$data['area_brokerage'] = $config['delivery_money_partner'] ?? 0;
|
||||
break;
|
||||
}
|
||||
// 判断:是否免审核
|
||||
if($isToExamine){
|
||||
app()->make(AgentApplyRepository::class)->toExaminePass([
|
||||
'id' => $applyInfo['id'],
|
||||
'status' => 1,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
AgentBrokerage::insert($data);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -317,6 +317,23 @@ class AgentRepository extends BaseRepository{
|
|||
|
||||
return $config;
|
||||
}
|
||||
/**
|
||||
* Common: 获取全部的上级信息
|
||||
* Author: wu-hui
|
||||
* Time: 2024/02/02 13:52
|
||||
* @param $pid
|
||||
* @param array $data
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function getAllUp($pid,$data = []){
|
||||
$info = $this->getSingleInfo($pid);
|
||||
if($info['pid'] > 0) $data = $this->getAllUp($info['pid'], $data);
|
||||
else $data[] = $info;
|
||||
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,7 +69,10 @@ class StoreGroupOrderRepository extends BaseRepository
|
|||
*/
|
||||
public function detail($uid, $id,$flag = true)
|
||||
{
|
||||
return $this->search(['paid' => 0, 'uid' => $uid])->where('group_order_id', $id)
|
||||
return $this->getSearch([])
|
||||
->where('paid', 0)
|
||||
->where('uid', $uid)
|
||||
->where('group_order_id', $id)
|
||||
->with([
|
||||
'orderList' => function (Relation $query) use ($flag) {
|
||||
$query->when($flag, function ($query) {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
namespace app\controller\admin;
|
||||
|
||||
|
||||
use app\common\repositories\marketing\AgentBrokerageRepository;
|
||||
use app\common\repositories\store\order\StoreOrderProductRepository;
|
||||
use app\common\repositories\store\order\StoreOrderRepository;
|
||||
use app\common\repositories\system\CacheRepository;
|
||||
|
|
@ -435,8 +436,8 @@ class Common extends BaseController
|
|||
|
||||
public function test(){
|
||||
|
||||
|
||||
$this->sqlInit();
|
||||
// app()->make(AgentBrokerageRepository::class)->inviteAgentGive((int)247);
|
||||
// $this->sqlInit();
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -142,7 +142,7 @@ class Agent extends BaseController{
|
|||
->getSearchModel([])
|
||||
->where('mer_name', $data['mer_name'])
|
||||
->when($agentApplyId > 0,function($query) use ($agentApplyId){
|
||||
$query->where('id','!=',$agentApplyId);
|
||||
$query->where('id','<>',$agentApplyId);
|
||||
})
|
||||
->count();
|
||||
if($isHas > 0) throw new ValidateException('商户已经存在,请勿重复申请!');
|
||||
|
|
@ -151,7 +151,7 @@ class Agent extends BaseController{
|
|||
$isHas = (int)app()->make(AgentApplyRepository::class)
|
||||
->getSearchModel(['contact_phone'=>$data['contact_phone']])
|
||||
->when($agentApplyId > 0,function($query) use ($agentApplyId){
|
||||
$query->where('id','!=',$agentApplyId);
|
||||
$query->where('id','<>',$agentApplyId);
|
||||
})->count();
|
||||
if($isHas > 0) throw new ValidateException('联系人电话已经存在,请勿重复申请!');
|
||||
$isHas = (int)$this->repository
|
||||
|
|
@ -166,7 +166,7 @@ class Agent extends BaseController{
|
|||
$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);
|
||||
$query->where('id','<>',$agentApplyId);
|
||||
})->count();
|
||||
if($isHas > 0) throw new ValidateException('代理身份信息已经存在,请勿重复申请!');
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use app\common\model\user\ExchangeIntegralRecord;
|
|||
use app\common\model\user\ExchangeQuota;
|
||||
use app\common\model\user\ExchangeQuotaRecord;
|
||||
use app\common\model\user\User;
|
||||
use app\common\repositories\marketing\AgentBrokerageRepository;
|
||||
use app\common\repositories\system\merchant\MerchantRepository;
|
||||
use app\common\repositories\user\ExchangePickupPointRepository;
|
||||
use think\facade\Log;
|
||||
|
|
@ -29,6 +30,7 @@ class OrderPaySuccessEvent{
|
|||
$this->exchangeGoodsHandle($groupOrder);
|
||||
}else if($groupOrder->activity_type == 32){
|
||||
// 代理入驻支付
|
||||
$this->agentPaySuccessHandle($groupOrder);
|
||||
}else{
|
||||
// 其他订单
|
||||
$this->orderPaySuccessHandle($groupOrder);
|
||||
|
|
@ -130,6 +132,14 @@ class OrderPaySuccessEvent{
|
|||
|
||||
return true;
|
||||
}
|
||||
// 支付成功 - 代理申请入驻支付成功
|
||||
public function agentPaySuccessHandle($groupOrder){
|
||||
foreach($groupOrder->orderList as $orderInfo){
|
||||
app()->make(AgentBrokerageRepository::class)->inviteAgentGive((int)$orderInfo->order_id);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -390,7 +390,7 @@ Route::group('api/', function () {
|
|||
Route::get('get_config', 'getConfig');// 获取配置信息
|
||||
Route::post('agent_apply', 'apply');// 提交申请信息
|
||||
Route::post('apply_record', 'applyRecord');// 申请记录
|
||||
Route::post('apply_info', 'applyInfo');// 申请记录
|
||||
Route::get('apply_info', 'applyInfo');// 申请记录
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue