修改:餐厅、酒道馆、烟酒店绑定商户流程优化修改

This commit is contained in:
wuhui_zzw 2024-03-22 11:14:23 +08:00
parent 5efcff9683
commit 7bfc8433f6
3 changed files with 52 additions and 16 deletions

View File

@ -32,7 +32,7 @@ class Agent extends BaseModel{
* @return array|string
*/
public function getMerIdListAttr(){
if(($this->agent_type ?? 0) == 8 && ($this->id ?? 0) > 0){
if(($this->id ?? 0) > 0){
return Merchant::where('agent_id',$this->id)->column('mer_id');
}

View File

@ -181,12 +181,10 @@ class AgentRepository extends BaseRepository{
Agent::update($updateInfo,['id'=>$agentId]);
// 修改配送商 - 商户关联信息
$merIdList = is_array($data['mer_id_list']) ? $data['mer_id_list'] : [];
if(count($merIdList) > 0){
// 删除已经存在的关联信息
Merchant::update(['agent_id' => null],['agent_id'=>$agentId]);
// 建立新的关联信息
Merchant::whereIn('mer_id',$data['mer_id_list'])->update(['agent_id' => $agentId]);
}
// 删除已经存在的关联信息
Merchant::update(['agent_id' => null],['agent_id'=>$agentId]);
// 建立新的关联信息
if(count($merIdList) > 0) Merchant::whereIn('mer_id',$merIdList)->update(['agent_id' => $agentId]);
}
/**
* Common: 代理添加/编辑 —— 处理子类信息
@ -225,8 +223,8 @@ class AgentRepository extends BaseRepository{
$childrenItemId = $childrenItem['id'] ?? 0;
$handleData = array_intersect_key($childrenItem, $keys);
$handleData['pid'] = $agentId;
// 判断:如果为配送商 处理商户关联信息
if($childrenItem['agent_type'] == 8){
// 判断:如果为配送商、烟酒馆 处理商户关联信息
if(in_array($childrenItem['agent_type'],[8,11])){
// 判断:应该修改还是编辑
if((int)$childrenItemId > 0) $this->dao->update($childrenItemId,$handleData);
else $childrenItemId = Agent::insertGetId($handleData);
@ -273,26 +271,62 @@ class AgentRepository extends BaseRepository{
*/
public function getEditInfo($params){
// 获取当前信息 编辑类型0=发起人管理,1=发起人,2=省公司,3=省合伙人(外勤),4=省合伙人(内勤),5=区县运营商,6=区县合伙人,7=餐厅,8=配送商
$info = [];
if((int)$params['agent_id'] > 0) {
// 非发起人管理存在info及children_list
$info = $this->dao->searchList(['id' => $params['agent_id']])->findOrEmpty();
$childrenList = $this->dao
$children_list = $this->dao
->searchList(['pid' => $params['agent_id']])
->select()
->toArray();
}
else{
// 发起人管理仅存在children_list
$childrenList = $this->dao
$children_list = $this->dao
->searchList(['pid' => 0,'agent_type' => 1])
->select()
->toArray();
}
// 获取已被酒道馆绑定的商户
$shop_mer = $this->getMerchant(0);
// 获取已被烟酒店绑定的商户
$wine = $this->getMerchant(3);
// 获取已被餐厅绑定的商户
$mer = Agent::hasWhere('mer',function($query){
$query->where('is_del',0);
},'Agent.mer_id,Agent.id as agent_id,Agent.contact_name')
->where('Agent.mer_id','>',0)
->where('Agent.is_del',0)
->select()
->toArray();
return [
'info' => $info ?? [],
'children_list' => $childrenList
];
return compact('info','children_list','shop_mer','wine','mer');
}
/**
* Common: 获取对应类型已绑定的 酒道馆 || 烟酒馆
* Author: wu-hui
* Time: 2024/03/22 10:38
* @param $merchantType
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
private function getMerchant($merchantType){
return Merchant::hasWhere('agent',function($query){
$query->where('is_del',0);
},'Merchant.mer_id,Merchant.agent_id,Merchant.merchant_type')
->where('agent_id','>',0)
->where('merchant_type',$merchantType)
->with([
'agent' => function($query){
$query->field(['id','contact_name'])
->bind(['contact_name']);
}
])
->select()
->toArray();
}
/**
* Common: 获取配置

View File

@ -230,7 +230,9 @@ class Agent extends BaseController{
if(count($merIdList) > 0){
// 判断:是否存在重复
$newMerIdList = call_user_func_array('array_merge', $merIdList);
if(count($newMerIdList) != count(array_unique($newMerIdList))) throw new ValidateException('每个商户只能关联一个配送商,请勿重复关联!');
if(count($newMerIdList) != count(array_unique($newMerIdList))) {
throw new ValidateException('每个商户只能关联一个配送商,请勿重复关联!');
}
// 判断:当前关联商户中,是否存在其他已经被关联的商户
$ids = array_filter(array_column($childrenList,'id'));
$isHas = (int)app()->make(MerchantRepository::class)