// +---------------------------------------------------------------------- namespace app\common\model\groupon; use cores\BaseModel; use think\model\relation\BelongsTo; /** * 拼团拼单成员模型 * Class TaskUsers * @package app\common\model\groupon */ class TaskUsers extends BaseModel { // 定义表名 protected $name = 'groupon_task_users'; // 定义主键 protected $pk = 'id'; /** * 关联模型:用户信息 * @return BelongsTo */ public function user(): BelongsTo { $module = self::getCalledModule(); return $this->BelongsTo("app\\{$module}\\model\\User")->field(['user_id', 'nick_name', 'avatar_id']); } /** * 关联模型:机器人信息 * @return BelongsTo */ public function robot(): BelongsTo { return $this->BelongsTo('Robot', 'robot_id'); } /** * 获取器:拼单开始时间 * @param $value * @return false|string */ public function getStartTimeAttr($value) { return format_time($value); } /** * 判断用户是否已经参与了拼单 * @param int $taskId * @param int $userId * @return bool */ public static function isJoin(int $taskId, int $userId): bool { return (bool)(new static)->where('task_id', '=', $taskId) ->where('user_id', '=', $userId) ->where('is_robot', '=', 0) ->value('id'); } }