* +---------------------------------------------------------------------- */ namespace App\Http\Model\Client; use App\Http\Model\BaseModel; use crmeb\traits\model\TimeDataTrait; use Illuminate\Database\Eloquent\Relations\HasOne; /** * 客户关注 * Class ClientSubscribe. */ class ClientSubscribe extends BaseModel { use TimeDataTrait; /** * @var string */ protected $table = 'client_subscribe'; /** * @var string */ protected $primaryKey = 'id'; /** * 一对一关联客户. * @return HasOne */ public function client() { return $this->hasOne(Customer::class, 'id', 'eid')->select([ 'customer.id', 'customer.customer_name as name', ]); } /** * 客户ID作用域 */ public function scopeEid($query, $value) { if (is_array($value)) { $query->whereIn('eid', $value); } elseif ($value !== '') { $query->where('eid', $value); } } /** * 用户ID作用域 */ public function scopeUid($query, $value) { if (is_array($value)) { $query->whereIn('uid', $value); } elseif ($value !== '') { $query->where('uid', $value); } } }