123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- namespace app\admin\model;
- use support\Model;
- /**
- * 健康美食模型
- * Class Users
- * @package app\admin\model
- */
- class LifeFood extends Model
- {
- const ROLE_STATUS = 1;
- const IS_DEL_YES = 1;
- const IS_DEL_NO = 0;
- const FOOD_IS_SHOW = [
- self::IS_DEL_YES => '已删除',
- self::IS_DEL_NO => '未删除'
- ];
- /**
- * The table associated with the model.
- *
- * @var string
- */
- protected $table = 'life_healthy_food';
- public $timestamps = false;
- /**
- * Notes:获取健康美食列表
- * @param string $keywords
- * @param int $page
- * @param int $limit
- * @return array
- * User: ZQ
- * Date: 2022/10/17
- */
- public static function getFoodList(int $page, int $limit, string $keywords)
- {
- $list = static::select(['life_healthy_food.*','category.category_name'])
- ->where(['food_is_del'=>static::IS_DEL_NO])
- ->when($keywords != '', function ($query) use ($keywords){
- $query->where('food_name', 'like', '%' . $keywords . '%');
- })
- ->leftJoin('category','category_id','=','life_healthy_food.food_category_id')
- ->orderBy('food_create_time','DESC')
- ->forPage($page, $limit)
- ->get();
- $count = static::where(['food_is_del'=>static::IS_DEL_NO])
- ->when($keywords != '', function ($query) use ($keywords){
- $query->where('food_name', 'like', '%' . $keywords . '%');
- })
- ->count();
- return [$list, $count];
- }
- /**
- * Notes:获取所有健康美食
- * @return array
- * User: ZQ
- * Date: 2022/10/17
- */
- public static function getFoodAll()
- {
- $list = static::select(['food_id','food_name'])
- ->where(['food_is_del'=>static::IS_DEL_NO])
- ->orderBy('food_create_time','DESC')
- ->get();
- return $list;
- }
- /**
- * Notes:获取健康美食名称
- * @param string $account
- * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|null
- * User: ZQ
- * Date: 2022/10/17
- */
- public static function foodMation($admin_cinema)
- {
- $where = [];
- $where['food_is_del'] = static::IS_DEL_NO;
- $mation = static::where($where)
- ->when($admin_cinema != '', function ($query) use ($admin_cinema){
- $query->whereIn('food_id', $admin_cinema);
- })
- ->get('food_name');
- return $mation;
- }
- }
|