PackageGoods.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. namespace app\admin\model;
  3. use support\Db;
  4. use support\Model;
  5. /**
  6. * 角色模型
  7. * Class Users
  8. * @package app\admin\model
  9. */
  10. class PackageGoods extends Model
  11. {
  12. const GOODS_PUT_SHELVES = '1';
  13. const GOODS_LOWER_SHELF = '2';
  14. const GOODS_STATUS = [
  15. self::GOODS_PUT_SHELVES => '上架',
  16. self::GOODS_LOWER_SHELF => '下架'
  17. ];
  18. /**
  19. * The table associated with the model.
  20. *
  21. * @var string
  22. */
  23. protected $table = 'package_goods';
  24. public $timestamps = false;
  25. /**
  26. * Notes:获取产品列表
  27. * @param string $keywords
  28. * @param int $page
  29. * @param int $limit
  30. * @return array
  31. * User: QJF
  32. * Date: 2022/9/20
  33. */
  34. public static function getPackageGoodsList(int $page, int $limit, $keywords)
  35. {
  36. $model = new PackageGoods();
  37. if($limit == 1000){
  38. $model = $model->where('goods_status',1);
  39. }
  40. $list = $model->select('*')
  41. ->with('Category')
  42. ->when($keywords != '', function ($query) use ($keywords){
  43. $query->where('goods_name', 'like', '%' . $keywords . '%');
  44. })
  45. ->orderBy('goods_update_time','DESC')
  46. ->forPage($page, $limit)
  47. ->get();
  48. $count = $model->when($keywords != '', function ($query) use ($keywords){
  49. $query->where('goods_name', $keywords);
  50. })
  51. ->count();
  52. return [$list, $count];
  53. }
  54. //测试
  55. public static function getProductList(int $page, int $limit, string $keywords)
  56. {
  57. $list = static::select(['intelligence_products.*','intelligence_category.category_name'])
  58. ->where(['product_del'=>0])
  59. ->when($keywords != '', function ($query) use ($keywords){
  60. $query->where('product_name', $keywords);
  61. })
  62. ->leftJoin('intelligence_category', 'category_id', '=', 'intelligence_products.product__category_id')
  63. ->orderBy('product_create_time','DESC')
  64. ->forPage($page, $limit)
  65. ->get();
  66. $count = static::where(['product_del'=>0])
  67. ->when($keywords != '', function ($query) use ($keywords){
  68. $query->where('product_name', $keywords);
  69. })
  70. ->count();
  71. return [$list, $count];
  72. }
  73. public function Category(){
  74. return $this->belongsTo(PackageGoodsCategory::class,'goods_category_id','category_id');
  75. }
  76. public function getGoodsCreateTimeAttribute($value)
  77. {
  78. return date('Y-m-d H:i:s', $value);
  79. }
  80. public function getGoodsUpdateTimeAttribute($value)
  81. {
  82. return date('Y-m-d H:i:s', $value);
  83. }
  84. /**
  85. * Notes:获取套餐包包含所有产品
  86. * @param array $goods_ids
  87. * @return array
  88. * User: yym
  89. * Date: 2022/9/22
  90. */
  91. public static function getPackageGoodsListNew(array $goods_ids)
  92. {
  93. return static::where(['goods_status' => static::GOODS_PUT_SHELVES])
  94. ->whereIn('goods_id', $goods_ids)
  95. ->get()
  96. ->toArray();
  97. }
  98. }