添加:购买会员卡生成佣金信息

添加:代理商佣金明细查看
This commit is contained in:
wuhui_zzw 2024-01-26 21:15:29 +08:00
parent 67e28cd8fd
commit 601c27c1ca
10 changed files with 233 additions and 21 deletions

View File

@ -0,0 +1,70 @@
<?php
namespace app\common\dao\marketing;
use app\common\dao\BaseDao;
use app\common\model\marketing\AgentBrokerage;
class AgentBrokerageDao extends BaseDao{
protected function getModel(): string{
return AgentBrokerage::class;
}
// 公共搜索查询
public function searchList(array $params){
return (new AgentBrokerage())
->when(isset($params['id']) && $params['id'] !== '',function($query) use ($params){
$query->where('id', (int)$params['id']);
})
->when(isset($params['staff_uid']) && $params['staff_uid'] !== '',function($query) use ($params){
$query->where('staff_uid', (int)$params['staff_uid']);
})
->when(isset($params['store_uid']) && $params['store_uid'] !== '',function($query) use ($params){
$query->where('store_uid', (int)$params['store_uid']);
})
->when(isset($params['store_uid']) && $params['store_uid'] !== '',function($query) use ($params){
$query->where('store_uid', (int)$params['store_uid']);
})
->when(isset($params['area_store_uid']) && $params['area_store_uid'] !== '',function($query) use ($params){
$query->where('area_store_uid', (int)$params['area_store_uid']);
})
->when(isset($params['delivery_uid']) && $params['delivery_uid'] !== '',function($query) use ($params){
$query->where('delivery_uid', (int)$params['delivery_uid']);
})
->when(isset($params['province_uid']) && $params['province_uid'] !== '',function($query) use ($params){
$query->where('province_uid', (int)$params['province_uid']);
})
->with([
'userOrder' => function($query){
$query->field('order_id,order_sn,create_time,title');
},
'staff' => function($query){
$query->field('uid,nickname,avatar');
},
'store' => function($query){
$query->field('uid,nickname,avatar');
},
'area' => function($query){
$query->field('uid,nickname,avatar');
},
'areaStore' => function($query){
$query->field('uid,nickname,avatar');
},
'delivery' => function($query){
$query->field('uid,nickname,avatar');
},
'province' => function($query){
$query->field('uid,nickname,avatar');
},
])
->order('create_time DESC,id DESC');
}
}

View File

@ -0,0 +1,44 @@
<?php
namespace app\common\model\marketing;
use app\common\model\BaseModel;
use app\common\model\user\User;
use app\common\model\user\UserOrder;
class AgentBrokerage extends BaseModel{
public static function tablePk(): string{
return 'id';
}
public static function tableName(): string{
return 'agent_brokerage';
}
public function userOrder(){
return $this->hasOne(UserOrder::class,'order_id', 'user_order_id');
}
public function staff(){
return $this->hasOne(User::class,'uid', 'staff_uid');
}
public function store(){
return $this->hasOne(User::class,'uid', 'store_uid');
}
public function area(){
return $this->hasOne(User::class,'uid', 'area_uid');
}
public function areaStore(){
return $this->hasOne(User::class,'uid', 'area_store_uid');
}
public function delivery(){
return $this->hasOne(User::class,'uid', 'delivery_uid');
}
public function province(){
return $this->hasOne(User::class,'uid', 'province_uid');
}
}

View File

@ -0,0 +1,47 @@
<?php
namespace app\common\repositories\marketing;
use app\common\dao\marketing\AgentBrokerageDao;
use app\common\repositories\BaseRepository;
class AgentBrokerageRepository extends BaseRepository{
protected $dao;
public function __construct(AgentBrokerageDao $dao){
$this->dao = $dao;
}
/**
* Common: 获取信息列表
* Author: wu-hui
* Time: 2024/01/26 20:38
* @param array $params
* @param int $page
* @param int $limit
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getList(array $params,int $page,int $limit):array{
$query = $this->dao->searchList($params);
$count = $query->count();
$list = $query->page($page,$limit)->select();
return compact('count','list');
}
}

View File

@ -855,7 +855,7 @@ class MerchantRepository extends BaseRepository
// 参数获取
switch($type){
case 'promote':
$valueData = 'mer_id=' . $data['mer_id'];
$valueData = 'mid=' . $data['mid']. '&suid=' .$data['suid'];
$path = 'pages/annex/vip_center/index';
return app()->make(QrcodeService::class)->createQrCode($valueData,$path);
break;

View File

@ -72,6 +72,8 @@ class UserOrderRepository extends BaseRepository
'pay_type' => $res['value']['price'] == 0 ? 'free' : $params['pay_type'],
'status' => 1,
'other' => $user->is_svip == -1 ? 'first' : '',
'bind_mer_id' => $params['bind_mer_id'] ?? '',
'bind_staff_id' => $params['bind_staff_id'] ?? '',
];
$body = [
'order_sn' => $order_sn,

View File

@ -2,6 +2,7 @@
namespace app\controller\admin\marketing;
use app\common\repositories\marketing\AgentBrokerageRepository;
use app\common\repositories\marketing\AgentRepository;
use app\common\repositories\system\merchant\MerchantRepository;
use crmeb\basic\BaseController;
@ -204,7 +205,19 @@ class Agent extends BaseController{
}
/**
* Common: 佣金列表
* Author: wu-hui
* Time: 2024/01/26 20:36
* @return mixed
*/
public function commissionList(){
[$page, $limit] = $this->getPage();
$params = $this->request->params(['staff_uid','store_uid','store_uid','area_store_uid','delivery_uid','province_uid']);
$data = app()->make(AgentBrokerageRepository::class)->getList((array)$params,(int)$page,(int)$limit);
return app('json')->success($data);
}

View File

@ -116,7 +116,7 @@ class Merchant extends BaseController
// 参数获取
$merId = $this->request->param('mer_id');
if((int)$merId > 0){
$qrcode = $this->repository->createQrCode(['mer_id'=>$merId]);
$qrcode = $this->repository->createQrCode(['mid'=>$merId,'suid'=>$this->request->uid()]);
return app('json')->success(['qr_code' => $qrcode]);
}

View File

@ -71,7 +71,7 @@ class Svip extends BaseController
*/
public function createOrder($id, GroupDataRepository $groupDataRepository, UserOrderRepository $userOrderRepository)
{
$params = $this->request->params(['pay_type','return_url']);
$params = $this->request->params(['pay_type','return_url','bind_mer_id','bind_staff_id']);
if (!in_array($params['pay_type'], ['weixin', 'routine', 'h5', 'alipay', 'alipayQr', 'weixinQr'], true))
return app('json')->fail('请选择正确的支付方式');
$res = $groupDataRepository->getWhere(['group_data_id' => $id, 'status' => 1]);

View File

@ -3,6 +3,10 @@
namespace app\listener\exchangeQuota;
use app\common\model\marketing\Agent;
use app\common\model\marketing\AgentBrokerage;
use app\common\model\store\service\StoreService;
use app\common\model\system\merchant\Merchant;
use app\common\model\user\ExchangeQuota;
use app\common\model\user\ExchangeQuotaRecord;
use think\facade\Log;
@ -63,26 +67,52 @@ class OrderVipPayEvent{
// 会员卡开通成功 - 分佣操作
private function agentBrokerageHandle($order, $vipInfo){
Log::info('会员卡开通成功 - 分佣操作 - 开始: '.var_export($vipInfo,1));
// 获取用户各个角色信息
$bindStaffId = $order->bind_staff_id ?? 0;
$bindMerId = $order->bind_mer_id ?? 0;
$isOpenBrokerage = $vipInfo['is_open_brokerage'] ?? 0;
if($bindStaffId > 0 && $bindMerId > 0 && $isOpenBrokerage == 2){
// 获取 门店员工在员工表的id
$serviceId = StoreService::where('uid',$bindStaffId)->where('mer_id',$bindMerId)->value('service_id');
// 获取 门店(餐厅信息)
$agent7 = Agent::where('mer_id',$bindMerId)->where('agent_type',7)->findOrEmpty();
// 获取 区县合伙人
$agent6 = Agent::where('id',($agent7->pid ?? 0))->where('agent_type',6)->findOrEmpty();
// 获取 区县运营商
$agent5 = Agent::where('id',($agent6->pid ?? 0))->where('agent_type',5)->findOrEmpty();
// 获取 省合伙人(外勤)
$agent3 = Agent::where('id',($agent5->pid ?? 0))->where('agent_type',3)->findOrEmpty();
// 获取 省公司
$agent2 = Agent::where('id',($agent3->pid ?? 0))->where('agent_type',2)->findOrEmpty();
// 获取 配送商
$deliveryAgentId = (int)Merchant::where('mer_id',$bindMerId)->value('agent_id');
$agent8 = Agent::where('id',$deliveryAgentId)->where('agent_type',8)->findOrEmpty();
$data = [
'user_order_id' => $order->order_id,
'staff_uid' => $bindStaffId,
'staff_id' => $serviceId,
'staff_brokerage' => (float)$vipInfo['brokerage_staff'],
'store_uid' => $agent7->uid ?? 0,
'store_agent_id' => $agent7->id ?? 0,
'store_brokerage' => (float)$vipInfo['brokerage_store'],
'area_uid' => $agent6->uid ?? 0,
'area_agent_id' => $agent6->id ?? 0,
'area_brokerage' => (float)$vipInfo['brokerage_area'],
'area_store_uid' => $agent5->uid ?? 0,
'area_store_agent_id' => $agent5->id ?? 0,
'area_store_brokerage' => (float)$vipInfo['brokerage_area_store'],
'delivery_uid' => $agent8->uid ?? 0,
'delivery_agent_id' => $agent8->id ?? 0,
'delivery_brokerage' => (float)$vipInfo['brokerage_delivery'],
'province_uid' => $agent2->uid ?? 0,
'province_agent_id' => $agent2->id ?? 0,
'province_brokerage' => (float)$vipInfo['brokerage_province'],
'platform_brokerage' => (float)$vipInfo['brokerage_platform'],
];
AgentBrokerage::insert($data);
}
}
}

View File

@ -475,6 +475,12 @@ Route::group(function () {
Route::get('get_edit_info','/getEditInfo')->name('systemMarketingAgentGetEditInfo')->option([
'_alias' => '获取编辑信息',
]);
// 代理商佣金明细
Route::get('commission_list','/commissionList')->name('systemMarketingAgentCommissionList')->option([
'_alias' => '佣金明细',
]);
})->prefix('admin.marketing.Agent')->option([
'_path' => '/marketing/agent/list',