StoreCategory.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace app\common\model\store;
  3. use app\common\model\BaseModel;
  4. use think\Model;
  5. class StoreCategory extends BaseModel
  6. {
  7. /**
  8. * @return string
  9. * @author zfy
  10. * @day 2020-03-30
  11. */
  12. public static function tablePk(): string
  13. {
  14. return 'store_category_id';
  15. }
  16. /**
  17. * @return string
  18. * @author zfy
  19. * @day 2020-03-30
  20. */
  21. public static function tableName(): string
  22. {
  23. return 'store_category';
  24. }
  25. /**
  26. * 获取父级名称
  27. * @Author:Qinii
  28. * @Date: 2020/5/22
  29. * @param $value
  30. * @return string
  31. */
  32. public function getAncestorsAttr($value)
  33. {
  34. $value = self::whereIn('store_category_id',$this->path_ids)->order('level ASC')->column('cate_name');
  35. return implode('/',$value).'/'.$this->cate_name;
  36. }
  37. /**
  38. * 获取path的id
  39. * @Author:Qinii
  40. * @Date: 2020/5/22
  41. * @return array
  42. */
  43. public function getPathIdsAttr()
  44. {
  45. return explode('/',$this->path);
  46. }
  47. /**
  48. * 获取子集id
  49. * @Author:Qinii
  50. * @Date: 2020/5/22
  51. * @param $value
  52. * @return array
  53. */
  54. public function getChildIdsAttr($value)
  55. {
  56. return self::where('path','like','%/'.$this->store_category_id.'/%')->column('store_category_id');
  57. }
  58. public function searchIdsAttr($query,$value)
  59. {
  60. $query->where('store_category_id','in',$value);
  61. }
  62. }