StoreCategory.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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\admin\model\store;
  12. use traits\ModelTrait;
  13. use basic\ModelBasic;
  14. use service\UtilService;
  15. /**
  16. * Class StoreCategory
  17. * @package app\admin\model\store
  18. */
  19. class StoreCategory extends ModelBasic
  20. {
  21. use ModelTrait;
  22. /*
  23. * 异步获取分类列表
  24. * @param $where
  25. * @return array
  26. */
  27. public static function CategoryList($where){
  28. $data=($data=self::systemPage($where,true)->page((int)$where['page'],(int)$where['limit'])->select()) && count($data) ? $data->toArray() :[];
  29. foreach ($data as &$item){
  30. if($item['pid']) $item['pid_name'] = self::where('id',$item['pid'])->value('cate_name');
  31. else $item['pid_name'] = '顶级';
  32. }
  33. $count=self::systemPage($where,true)->count();
  34. return compact('count','data');
  35. }
  36. /**
  37. * @param $where
  38. * @return array
  39. */
  40. public static function systemPage($where,$isAjax=false){
  41. $model = new self;
  42. if($where['pid'] != '') $model = $model->where('pid',$where['pid']);
  43. else if($where['pid']=='' && $where['cate_name']=='') $model = $model->where('pid',0);
  44. if($where['is_show'] != '') $model = $model->where('is_show',$where['is_show']);
  45. if($where['cate_name'] != '') $model = $model->where('cate_name','LIKE',"%$where[cate_name]%");
  46. if(isset($where['mer_id']) && $where['mer_id']) $model->where('mer_id',$where['mer_id']);
  47. if($isAjax===true){
  48. if(isset($where['order']) && $where['order']!=''){
  49. $model=$model->order(self::setOrder($where['order']));
  50. }else{
  51. $model=$model->order('sort DESC');
  52. }
  53. return $model;
  54. }
  55. return self::page($model,function ($item){
  56. if($item['pid']){
  57. $item['pid_name'] = self::where('id',$item['pid'])->value('cate_name');
  58. }else{
  59. $item['pid_name'] = '顶级';
  60. }
  61. },$where);
  62. }
  63. /**
  64. * 获取顶级分类
  65. * @return array
  66. */
  67. public static function getCategory($field = 'id,cate_name')
  68. {
  69. return self::where('is_show',1)->column($field);
  70. }
  71. /**
  72. * 分级排序列表
  73. * @param null $model
  74. * @return array
  75. */
  76. public static function getTierList($model = null)
  77. {
  78. if($model === null) $model = new self();
  79. return UtilService::sortListTier($model->select()->toArray());
  80. }
  81. public static function delCategory($id){
  82. $count = self::where('pid',$id)->count();
  83. if($count)
  84. return false;
  85. else{
  86. return self::del($id);
  87. }
  88. }
  89. }