'timestamp', 'end_time' => 'timestamp', 'create_time' => 'timestamp', 'update_time' => 'timestamp', ]; // 设置json类型字段 protected $json = [ 'active_goods_info', 'active_value']; // 设置JSON数据返回数组 protected $jsonAssoc = true; /** * 活动商品项 * @return \think\model\relation\HasMany */ public function activeGoods() { return $this->hasMany(ActiveGoods::class, 'active_id', 'active_id'); } /** * 活动状态 * @param $value * @param $data * @return mixed|string */ public function getActiveStatusNameAttr($value, $data) { if (empty($data['active_status'])) { return ''; } return ActiveDict::getStatus()[$data['active_status']] ?? ''; } /** * 活动类型 * @param $value * @param $data * @return mixed|string */ public function getActiveTypeNameAttr($value, $data) { if (empty($data['active_type'])) { return ''; } return ActiveDict::getType()[$data['active_type']] ?? ''; } /** * 活动商品类型 * @param $value * @param $data * @return mixed|string */ public function getActiveGoodsTypeNameAttr($value, $data) { if (empty($data['active_goods_type'])) { return ''; } return ActiveDict::getGoodsType()[$data['active_goods_type']] ?? ''; } /** * 活动类别 * @param $value * @param $data * @return mixed|string */ public function getActiveClassNameAttr($value, $data) { if (empty($data['active_class'])) { return ''; } return ActiveDict::getClass()[$data['active_class']] ?? ''; } /** * 搜索器:标题 * @param $value * @param $data */ public function searchActiveNameAttr($query, $value, $data) { if ($value) { $query->where("active_name", 'like', '%'.$value.'%'); } } /** * 搜索器:状态 * @param $value * @param $data */ public function searchActiveStatusAttr($query, $value, $data) { if ($value) { $query->where("active_status", '=', $value); } } /** * 活动结束时间搜索器 * @param Query $query * @param $value * @param $data */ public function searchEndTimeAttr(Query $query, $value, $data) { $start_time = empty($value[0]) ? 0 : strtotime($value[0]); $end_time = empty($value[1]) ? 0 : strtotime($value[1]); if ($start_time > 0 && $end_time > 0) { $query->whereBetweenTime('end_time', $start_time, $end_time); } else if ($start_time > 0 && $end_time == 0) { $query->where([['end_time', '>=', $start_time]]); } else if ($start_time == 0 && $end_time > 0) { $query->where([['end_time', '<=', $end_time]]); } } }