88 lines
2.2 KiB
PHP
88 lines
2.2 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/24 18:15
|
|
* @return string
|
|
*/
|
|
public function getOnlyKeyAttr():string{
|
|
return ($this->uid ?? '') . '_' . ($this->agent_type ?? '');
|
|
}
|
|
/**
|
|
* Common: 获取器 —— 获取配送商关联的商户
|
|
* Author: wu-hui
|
|
* Time: 2024/01/25 17:58
|
|
* @return array|string
|
|
*/
|
|
public function getMerIdListAttr(){
|
|
if(($this->agent_type ?? 0) == 8 && ($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)->count();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
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');
|
|
}
|
|
}
|