IntelligenceCategory.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace app\admin\model;
  3. use support\Db;
  4. use support\Model;
  5. /**
  6. * 智能产品分类模型
  7. * Class Users
  8. * @package app\admin\model
  9. */
  10. class IntelligenceCategory extends Model
  11. {
  12. /**
  13. * The table associated with the model.
  14. *
  15. * @var string
  16. */
  17. protected $table = 'intelligence_category';
  18. public $timestamps = false;
  19. /**
  20. * Notes:获取智能产品分类列表
  21. * @param string $keywords
  22. * @param int $page
  23. * @param int $limit
  24. * @return array
  25. * User: ZQ
  26. * Date: 2022/9/13
  27. */
  28. public static function getCategoryList(int $page, int $limit, string $keywords, int $pid)
  29. {
  30. if (!empty($keywords)){
  31. $list = static::select('*')
  32. ->where(['category_del'=>0])
  33. ->when($keywords != '', function ($query) use ($keywords){
  34. $query->where('category_name', 'like', '%' . $keywords . '%');
  35. })
  36. ->orderBy('category_create_time','DESC')
  37. ->forPage($page, $limit)
  38. ->get();
  39. }else{
  40. $list = static::select('*')
  41. ->where(['category_del'=>0, 'category_pid'=>$pid])
  42. ->when($keywords != '', function ($query) use ($keywords){
  43. $query->where('category_name', 'like', '%' . $keywords . '%');
  44. })
  45. ->orderBy('category_create_time','DESC')
  46. ->forPage($page, $limit)
  47. ->get();
  48. }
  49. $count = static::where(['category_del'=>0])
  50. ->when($keywords != '', function ($query) use ($keywords){
  51. $query->where('category_name', 'like', '%' . $keywords . '%');
  52. })
  53. ->count();
  54. return [$list, $count];
  55. }
  56. /**
  57. * Notes:获取分类列表
  58. * @return array
  59. * User: ZQ
  60. * Date: 2022/9/19`
  61. */
  62. public static function categoryAll($pid)
  63. {
  64. $list = static::select(['category_id as value','category_name as label'])
  65. ->where(['category_del'=>0,'category_pid'=>$pid])
  66. ->orderBy('category_create_time','DESC')
  67. ->get();
  68. return $list;
  69. }
  70. }