StoreCategory.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\model\store;
  12. use app\common\model\BaseModel;
  13. use app\common\model\store\product\Product;
  14. use think\Model;
  15. class StoreCategory extends BaseModel
  16. {
  17. /**
  18. * @return string
  19. * @author xaboy
  20. * @day 2020-03-30
  21. */
  22. public static function tablePk(): string
  23. {
  24. return 'store_category_id';
  25. }
  26. /**
  27. * @return string
  28. * @author xaboy
  29. * @day 2020-03-30
  30. */
  31. public static function tableName(): string
  32. {
  33. return 'store_category';
  34. }
  35. /**
  36. * 获取父级名称
  37. * @Author:Qinii
  38. * @Date: 2020/5/22
  39. * @param $value
  40. * @return string
  41. */
  42. public function getAncestorsAttr($value)
  43. {
  44. $value = self::whereIn('store_category_id',$this->path_ids)->order('level ASC')->column('cate_name');
  45. return implode('/',$value).'/'.$this->cate_name;
  46. }
  47. /**
  48. * 获取path的id
  49. * @Author:Qinii
  50. * @Date: 2020/5/22
  51. * @return array
  52. */
  53. public function getPathIdsAttr()
  54. {
  55. return explode('/',$this->path);
  56. }
  57. public function getHasProductAttr()
  58. {
  59. return Product::where('cate_id',$this->store_category_id)->count() > 0 ? 1 : 0;
  60. }
  61. /**
  62. * 获取子集id
  63. * @Author:Qinii
  64. * @Date: 2020/5/22
  65. * @param $value
  66. * @return array
  67. */
  68. public function getChildIdsAttr($value)
  69. {
  70. return self::where('path','like','%/'.$this->store_category_id.'/%')->column('store_category_id');
  71. }
  72. public function getThreeChildIdsAttr($value)
  73. {
  74. return self::where('path','like','%/'.$this->store_category_id.'/%')->where('level',2)->column('store_category_id');
  75. }
  76. public function searchIdAttr($query,$value)
  77. {
  78. $query->where('store_category_id',$value);
  79. }
  80. public function searchIdsAttr($query,$value)
  81. {
  82. $query->whereIn('store_category_id',$value);
  83. }
  84. public function searchStatusAttr($query,$value)
  85. {
  86. $query->where('is_show',$value);
  87. }
  88. public function searchMerIdsAttr($query,$value)
  89. {
  90. $query->whereIn('mer_id',$value);
  91. }
  92. public function searchLevelAttr($query,$value)
  93. {
  94. $query->whereIn('level',$value);
  95. }
  96. }