LifeFood.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace app\admin\model;
  3. use support\Model;
  4. /**
  5. * 健康美食模型
  6. * Class Users
  7. * @package app\admin\model
  8. */
  9. class LifeFood extends Model
  10. {
  11. const ROLE_STATUS = 1;
  12. const IS_DEL_YES = 1;
  13. const IS_DEL_NO = 0;
  14. const FOOD_IS_SHOW = [
  15. self::IS_DEL_YES => '已删除',
  16. self::IS_DEL_NO => '未删除'
  17. ];
  18. /**
  19. * The table associated with the model.
  20. *
  21. * @var string
  22. */
  23. protected $table = 'life_healthy_food';
  24. public $timestamps = false;
  25. /**
  26. * Notes:获取健康美食列表
  27. * @param string $keywords
  28. * @param int $page
  29. * @param int $limit
  30. * @return array
  31. * User: ZQ
  32. * Date: 2022/10/17
  33. */
  34. public static function getFoodList(int $page, int $limit, string $keywords)
  35. {
  36. $list = static::select(['life_healthy_food.*','category.category_name'])
  37. ->where(['food_is_del'=>static::IS_DEL_NO])
  38. ->when($keywords != '', function ($query) use ($keywords){
  39. $query->where('food_name', 'like', '%' . $keywords . '%');
  40. })
  41. ->leftJoin('category','category_id','=','life_healthy_food.food_category_id')
  42. ->orderBy('food_create_time','DESC')
  43. ->forPage($page, $limit)
  44. ->get();
  45. $count = static::where(['food_is_del'=>static::IS_DEL_NO])
  46. ->when($keywords != '', function ($query) use ($keywords){
  47. $query->where('food_name', 'like', '%' . $keywords . '%');
  48. })
  49. ->count();
  50. return [$list, $count];
  51. }
  52. /**
  53. * Notes:获取所有健康美食
  54. * @return array
  55. * User: ZQ
  56. * Date: 2022/10/17
  57. */
  58. public static function getFoodAll()
  59. {
  60. $list = static::select(['food_id','food_name'])
  61. ->where(['food_is_del'=>static::IS_DEL_NO])
  62. ->orderBy('food_create_time','DESC')
  63. ->get();
  64. return $list;
  65. }
  66. /**
  67. * Notes:获取健康美食名称
  68. * @param string $account
  69. * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|null
  70. * User: ZQ
  71. * Date: 2022/10/17
  72. */
  73. public static function foodMation($admin_cinema)
  74. {
  75. $where = [];
  76. $where['food_is_del'] = static::IS_DEL_NO;
  77. $mation = static::where($where)
  78. ->when($admin_cinema != '', function ($query) use ($admin_cinema){
  79. $query->whereIn('food_id', $admin_cinema);
  80. })
  81. ->get('food_name');
  82. return $mation;
  83. }
  84. }