CarBrandService.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 LARAVEL研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: laravel开发员 <laravel.qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Services\Common;
  12. use App\Models\CarBrandModel;
  13. use App\Services\BaseService;
  14. use Darabonba\GatewaySpi\Models\InterceptorContext\request;
  15. /**
  16. * 车品牌管理-服务类
  17. * @author laravel开发员
  18. * @since 2020/11/11
  19. * @package App\Services\Common
  20. */
  21. class CarBrandService extends BaseService
  22. {
  23. // 静态对象
  24. protected static $instance = null;
  25. /**
  26. * 构造函数
  27. * @author laravel开发员
  28. * @since 2020/11/11
  29. * CarCategoryService constructor.
  30. */
  31. public function __construct()
  32. {
  33. $this->model = new CarBrandModel();
  34. }
  35. /**
  36. * 静态入口
  37. * @return MemberService|static|null
  38. */
  39. public static function make()
  40. {
  41. if (!self::$instance) {
  42. self::$instance = new static();
  43. }
  44. return self::$instance;
  45. }
  46. /**
  47. * 列表
  48. * @param $params
  49. * @param int $pageSize
  50. * @return array
  51. */
  52. public function getDataList($params, $pageSize = 15)
  53. {
  54. $where = ['a.mark' => 1];
  55. $list = $this->model->from('car_brand as a')
  56. ->where($where)
  57. ->where(function ($query) use($params){
  58. $keyword = isset($params['keyword'])? $params['keyword'] : '';
  59. if($keyword){
  60. $query->where('a.name','like',"%{$keyword}%");
  61. }
  62. })
  63. ->where(function ($query) use($params){
  64. $status = isset($params['status'])? $params['status'] : 0;
  65. if($status>0 && is_array($status)){
  66. $query->whereIn('a.status', $status);
  67. }else if($status){
  68. $query->where('a.status', $status);
  69. }
  70. })
  71. ->select(['a.*'])
  72. ->orderBy('a.create_time','desc')
  73. ->paginate($pageSize > 0 ? $pageSize : 9999999);
  74. $list = $list? $list->toArray() :[];
  75. if($list){
  76. foreach($list['data'] as &$item){
  77. $item['create_time'] = $item['create_time']? datetime($item['create_time'],'Y-m-d H.i.s') : '';
  78. $item['icon'] = isset($item['icon']) && $item['icon']? get_image_url($item['icon']) : '';
  79. }
  80. }
  81. return [
  82. 'pageSize'=> $pageSize,
  83. 'total'=>isset($list['total'])? $list['total'] : 0,
  84. 'list'=> isset($list['data'])? $list['data'] : []
  85. ];
  86. }
  87. /**
  88. * 编辑
  89. * @return array
  90. */
  91. public function edit()
  92. {
  93. $data = request()->post();
  94. if(isset($data['icon']) && $data['icon']){
  95. $data['icon'] = get_image_path($data['icon']);
  96. }
  97. return parent::edit($data);
  98. }
  99. /**
  100. * 车型选项
  101. * @param int $num
  102. * @return array|mixed
  103. */
  104. public function getOptions($num = 99,$field=[])
  105. {
  106. $field = $field? $field : ['id','name','color'];
  107. $datas = $this->model->where(['status'=>1,'mark'=>1])
  108. ->select($field)
  109. ->limit($num)
  110. ->orderBy('sort','desc')
  111. ->orderBy('id','desc')
  112. ->get();
  113. $datas = $datas? $datas->toArray() : [];
  114. if($datas){
  115. foreach ($datas as &$item){
  116. if(isset($item['icon'])){
  117. $item['icon'] = $item['icon']? get_image_url($item['icon']) : '';
  118. }
  119. }
  120. unset($item);
  121. }
  122. return $datas;
  123. }
  124. }