StoreCategory.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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 think\Model;
  14. class StoreCategory extends BaseModel
  15. {
  16. /**
  17. * @return string
  18. * @author xaboy
  19. * @day 2020-03-30
  20. */
  21. public static function tablePk(): string
  22. {
  23. return 'store_category_id';
  24. }
  25. /**
  26. * @return string
  27. * @author xaboy
  28. * @day 2020-03-30
  29. */
  30. public static function tableName(): string
  31. {
  32. return 'store_category';
  33. }
  34. /**
  35. * 获取父级名称
  36. * @Author:Qinii
  37. * @Date: 2020/5/22
  38. * @param $value
  39. * @return string
  40. */
  41. public function getAncestorsAttr($value)
  42. {
  43. $value = self::whereIn('store_category_id',$this->path_ids)->order('level ASC')->column('cate_name');
  44. return implode('/',$value).'/'.$this->cate_name;
  45. }
  46. /**
  47. * 获取path的id
  48. * @Author:Qinii
  49. * @Date: 2020/5/22
  50. * @return array
  51. */
  52. public function getPathIdsAttr()
  53. {
  54. return explode('/',$this->path);
  55. }
  56. /**
  57. * 获取子集id
  58. * @Author:Qinii
  59. * @Date: 2020/5/22
  60. * @param $value
  61. * @return array
  62. */
  63. public function getChildIdsAttr($value)
  64. {
  65. return self::where('path','like','%/'.$this->store_category_id.'/%')->column('store_category_id');
  66. }
  67. public function searchIdsAttr($query,$value)
  68. {
  69. $query->where('store_category_id','in',$value);
  70. }
  71. }