SpecialTaskCategory.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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\special;
  12. use traits\ModelTrait;
  13. use basic\ModelBasic;
  14. use service\UtilService as Util;
  15. use app\admin\model\special\SpecialTask;
  16. class SpecialTaskCategory extends ModelBasic
  17. {
  18. use ModelTrait;
  19. /**
  20. * 全部素材分类
  21. */
  22. public static function taskCategoryAll($type=0){
  23. $model=self::where('is_del',0);
  24. if($type==1){
  25. $model=$model->where('pid',0);
  26. }
  27. $list=$model->select();
  28. $list=count($list) > 0 ? $list->toArray() : [];
  29. $list=Util::sortListTier($list);
  30. return $list;
  31. }
  32. /**
  33. * 素材分类列表
  34. */
  35. public static function getAllList($where){
  36. $data = self::setWhere($where)->page((int)$where['page'], (int)$where['limit'])->select();
  37. $data=count($data) > 0 ? $data->toArray() : [];
  38. foreach ($data as &$item){
  39. $pids=self::categoryId($item['id']);
  40. if(count($pids)>0){
  41. $item['sum']=SpecialTask::where("pid",'in', $pids)->count();
  42. }else{
  43. $item['sum']=SpecialTask::where("pid", $item['id'])->count();
  44. }
  45. }
  46. $count = self::setWhere($where)->count();
  47. return compact('data', 'count');
  48. }
  49. public static function setWhere($where)
  50. {
  51. $model = self::order('sort desc,add_time desc')->where('is_del', 0)->where('pid',$where['pid']);
  52. if ($where['cate_name'] != '') $model = $model->where('title', 'like', "%$where[cate_name]%");
  53. return $model;
  54. }
  55. /**获取一个分类下的所有分类ID
  56. * @param int $pid
  57. */
  58. public static function categoryId($pid=0){
  59. $data=self::where('is_del', 0)->where('pid',$pid)->column('id');
  60. return $data;
  61. }
  62. }