105 lines
3.0 KiB
PHP
105 lines
3.0 KiB
PHP
<?php
|
||
namespace app\common\model\marketing;
|
||
|
||
|
||
use app\common\model\BaseModel;
|
||
use app\common\model\store\CityArea;
|
||
use app\common\model\system\merchant\Merchant;
|
||
use app\common\model\user\User;
|
||
|
||
/**
|
||
* Common: 代理中心
|
||
* Author: wu-hui
|
||
* Time: 2024/01/23 17:53
|
||
* Class Agent
|
||
* @package app\common\model\user
|
||
*/
|
||
class Agent extends BaseModel{
|
||
|
||
|
||
public static function tablePk(): string{
|
||
return 'id';
|
||
}
|
||
|
||
public static function tableName(): string{
|
||
return 'agent';
|
||
}
|
||
|
||
/**
|
||
* Common: 获取器 —— 获取配送商关联的商户
|
||
* Author: wu-hui
|
||
* Time: 2024/01/25 17:58
|
||
* @return array|string
|
||
*/
|
||
public function getMerIdListAttr(){
|
||
if(($this->id ?? 0) > 0){
|
||
return Merchant::where('agent_id',$this->id)->column('mer_id');
|
||
}
|
||
|
||
return [];
|
||
}
|
||
/**
|
||
* Common: 获取器 —— 获取下级数量(直属)
|
||
* Author: wu-hui
|
||
* Time: 2024/01/25 19:06
|
||
* @return int
|
||
*/
|
||
public function getChildrenCountAttr():int{
|
||
if(($this->id ?? 0) > 0){
|
||
return self::where('pid',$this->id)->where('is_del',0)->count();
|
||
}
|
||
return 0;
|
||
}
|
||
/**
|
||
* Common: 获取角色类型
|
||
* Author: wu-hui
|
||
* Time: 2024/02/20 10:44
|
||
* @return string
|
||
*/
|
||
public function getAgentTypeTextAttr():string{
|
||
// 类型:1=总部发起人,2=省公司发起人,3=省合伙人(外勤),4=省合伙人(内勤),5=区县运营商,6=区县合伙人,7=餐厅,8=配送商,9=总部外勤,10=总部内勤,10=烟酒店代销商
|
||
$agentType = $this->agent_type ?? -1;
|
||
switch($agentType){
|
||
case 1: return '总部发起人';break;
|
||
case 2: return '省公司发起人';break;
|
||
case 3: return '省公司外勤';break;
|
||
case 4: return '省公司内勤';break;
|
||
case 5: return '区县运营商';break;
|
||
case 6: return '区县合伙人';break;
|
||
case 7: return '餐厅';break;
|
||
case 8: return '配送商';break;
|
||
case 9: return '总部外勤';break;
|
||
case 10: return '总部内勤';break;
|
||
case 11: return '烟酒店代销商';break;
|
||
}
|
||
|
||
return '';
|
||
}
|
||
|
||
|
||
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');
|
||
}
|
||
public function mer(){
|
||
return $this->hasOne(Merchant::class, 'mer_id', 'mer_id');
|
||
}
|
||
public function merList(){
|
||
return $this->hasMany(Merchant::class, 'agent_id', 'id');
|
||
}
|
||
}
|