MerchantShop.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. namespace app\admin\model;
  3. use support\Db;
  4. use support\Model;
  5. /**
  6. * 店铺
  7. * Class MerchantShop
  8. * @package app\admin\model
  9. */
  10. class MerchantShop extends Model
  11. {
  12. const DEL_NO = 0;
  13. const DEL_YES = 1;
  14. const SHOP_DEL = [
  15. self::DEL_NO => '未删除',
  16. self::DEL_YES => '已删除'
  17. ];
  18. /**
  19. * The table associated with the model.
  20. *
  21. * @var string
  22. */
  23. protected $table = 'merchant_shop';
  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/23
  33. */
  34. public static function getShopList(int $page, int $limit,$keywords)
  35. {
  36. $list = static::select('*')
  37. ->when($keywords != '', function ($query) use ($keywords){
  38. $query->where('shop_name', 'like', '%' . $keywords . '%');
  39. })
  40. ->where('shop_del',0)
  41. ->orderBy('shop_create_time','DESC')
  42. ->forPage($page, $limit)
  43. ->get();
  44. $count = static::when($keywords != '', function ($query) use ($keywords){
  45. $query->where('shop_name', 'like', '%' . $keywords . '%');
  46. }) ->where('shop_del',0)->count();
  47. return [$list, $count];
  48. }
  49. /**
  50. * Notes:获取健康店铺列表
  51. * @param string $keywords
  52. * @param int $page
  53. * @param int $limit
  54. * @return array
  55. * User: QJF
  56. * Date: 2022/11/08
  57. */
  58. public static function getHealthyShopList()
  59. {
  60. $list = static::select('*')
  61. ->where(['shop_del'=>0,'shop_type'=>1])
  62. ->orderBy('shop_create_time','DESC')
  63. ->get();
  64. return [$list];
  65. }
  66. public function getShopCreateTimeAttribute($value)
  67. {
  68. return date('Y-m-d H:i:s', $value);
  69. }
  70. //获取器修改产品标签
  71. public function getShopLabelAttribute($value)
  72. {
  73. return explode('|', $value);
  74. }
  75. /**
  76. * Notes:根据分类获取店铺列表
  77. * @param int $category_id
  78. * @return array
  79. * User: QJF
  80. * Date: 2022/9/23
  81. */
  82. public static function getCategoryShop($category_id)
  83. {
  84. $list = static::select(['shop_id','shop_name'])
  85. ->when($category_id != '', function ($query) use ($category_id){
  86. $query->where('shop_category_id', $category_id);
  87. })
  88. ->where('shop_del',0)
  89. ->orderBy('shop_create_time','DESC')
  90. ->get();
  91. return $list;
  92. }
  93. /**
  94. * Notes:店铺子集列表
  95. * @param int $category_id
  96. * @return array
  97. * User: QJF
  98. * Date: 2022/9/23
  99. */
  100. public static function getCategorysShop()
  101. {
  102. $list = static::select(['shop_id','shop_name'])
  103. ->with('children')
  104. ->where('shop_del',0)
  105. ->orderBy('shop_create_time','DESC')
  106. ->get()
  107. ->toArray();
  108. return $list;
  109. }
  110. /**
  111. * Notes:子集模型关联
  112. * @return \Illuminate\Database\Eloquent\Relations\HasMany
  113. * User: ZQ
  114. * Date: 2022/11/10
  115. */
  116. public function children()
  117. {
  118. return $this->hasMany(MerchantShopCategory::class, 'category_shop_id', 'shop_id')
  119. ->where('category_del',0);
  120. }
  121. }