<?php
|
|
namespace app\common\model\takeout;
|
|
use app\common\model\BaseModel;
|
|
|
/**
|
* 用户模型
|
*/
|
class Deliveryman extends BaseModel
|
{
|
protected $name = 'takeout_deliveryman';
|
protected $pk = 'user_id';
|
|
/**
|
* 关联会员记录表
|
* @return \think\model\relation\BelongsTo
|
*/
|
public function user()
|
{
|
return $this->belongsTo('app\\common\\model\\user\\User');
|
}
|
|
/**
|
* 关联团长记录表
|
* @return \think\model\relation\BelongsTo
|
*/
|
public function commander()
|
{
|
return $this->belongsTo('app\\common\\model\\takeout\\Commander','commander_id','commander_id');
|
}
|
|
/**
|
* 关联学校记录表
|
* @return \think\model\relation\BelongsTo
|
*/
|
public function school()
|
{
|
return $this->belongsTo('app\\common\\model\\takeout\\School','school_id','school_id');
|
}
|
|
|
/**
|
* 详情
|
*/
|
public static function detail($user_id, $with = ['user','commander','school'])
|
{
|
return (new static())->with($with)->find($user_id);
|
}
|
|
/**
|
* 是否为配送员
|
*/
|
public static function isDeliveryman($user_id)
|
{
|
$user = self::detail($user_id);
|
return !!$user && !$user['is_delete'];
|
}
|
|
/**
|
* 新增记录
|
* @param $user_id
|
* @param $data
|
* @return bool
|
*/
|
public static function add($user_id, $data)
|
{
|
$model = static::detail($user_id) ?: new static;
|
$model->save(array_merge([
|
'user_id' => $user_id,
|
'is_delete' => 0,
|
'app_id' => $model::$app_id,
|
], $data));
|
return true;
|
}
|
}
|