HealthyProduct.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace app\admin\model;
  3. use support\Model;
  4. /**
  5. * 健康产品模型
  6. * Class Users
  7. * @package app\admin\model
  8. */
  9. class HealthyProduct extends Model
  10. {
  11. const ROLE_STATUS = 1;
  12. const IS_DEL_YES = 1;
  13. const IS_DEL_NO = 0;
  14. const PRODUCT_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 = 'healthy_product';
  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/11/9
  33. */
  34. public static function getProductList(int $page, int $limit, string $keywords)
  35. {
  36. $list = static::select(['healthy_product.*','merchant_shop_category.category_name','merchant_shop.shop_name'])
  37. ->where(['product_del'=>static::IS_DEL_NO])
  38. ->when($keywords != '', function ($query) use ($keywords){
  39. $query->where('product_name', 'like', '%' . $keywords . '%');
  40. })
  41. ->leftJoin('merchant_shop_category','category_id','=','healthy_product.product_category_id')
  42. ->leftJoin('merchant_shop','shop_id','=','healthy_product.product_shop_id')
  43. ->orderBy('product_sort','DESC')
  44. ->orderBy('product_create_time','DESC')
  45. ->forPage($page, $limit)
  46. ->get();
  47. $count = static::where(['product_del'=>static::IS_DEL_NO])
  48. ->when($keywords != '', function ($query) use ($keywords){
  49. $query->where('product_name', 'like', '%' . $keywords . '%');
  50. })
  51. ->count();
  52. return [$list, $count];
  53. }
  54. /**
  55. * Notes:获取所有健康产品
  56. * @return array
  57. * User: ZQ
  58. * Date: 2022/10/14
  59. */
  60. public static function getProductAll()
  61. {
  62. $list = static::select(['product_id','product_name'])
  63. ->where(['product_del'=>static::IS_DEL_NO])
  64. ->orderBy('product_add_time','DESC')
  65. ->get();
  66. return $list;
  67. }
  68. /**
  69. * Notes:获取健康产品名称
  70. * @param string $account
  71. * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|null
  72. * User: ZQ
  73. * Date: 2022/10/14
  74. */
  75. public static function bookMation($admin_cinema)
  76. {
  77. $where = [];
  78. $where['product_del'] = static::IS_DEL_NO;
  79. $mation = static::where($where)
  80. ->when($admin_cinema != '', function ($query) use ($admin_cinema){
  81. $query->whereIn('product_id', $admin_cinema);
  82. })
  83. ->get('product_name');
  84. return $mation;
  85. }
  86. }