DriverLineService.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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\ComplaintModel;
  13. use App\Models\DriverLineModel;
  14. use App\Models\FreightPackageModel;
  15. use App\Models\TicketModel;
  16. use App\Services\BaseService;
  17. use App\Services\RedisService;
  18. /**
  19. * 线路查询记录管理-服务类
  20. * @author laravel开发员
  21. * @since 2020/11/11
  22. * @package App\Services\Common
  23. */
  24. class DriverLineService extends BaseService
  25. {
  26. // 静态对象
  27. protected static $instance = null;
  28. /**
  29. * 构造函数
  30. * @author laravel开发员
  31. * @since 2020/11/11
  32. */
  33. public function __construct()
  34. {
  35. $this->model = new DriverLineModel();
  36. }
  37. /**
  38. * 静态入口
  39. */
  40. public static function make()
  41. {
  42. if (!self::$instance) {
  43. self::$instance = new static();
  44. }
  45. return self::$instance;
  46. }
  47. /**
  48. * 列表
  49. * @param $params
  50. * @param int $pageSize
  51. * @return array
  52. */
  53. public function getDataList($params, $pageSize = 15)
  54. {
  55. $where = ['a.mark' => 1];
  56. $list = $this->model->from('driver_lines as a')
  57. ->leftJoin('driver as b','b.id','=','a.driver_id')
  58. ->leftJoin('car_category as c','c.id','=','a.car_cate_id')
  59. ->where($where)
  60. ->where(function ($query) use($params){
  61. $keyword = isset($params['keyword'])? $params['keyword'] : '';
  62. if($keyword){
  63. $query->where('a.address','like',"%{$keyword}%")->orWhere('a.depart_address','like',"%{$keyword}%")->orWhere('a.via','like',"%{$keyword}%");
  64. }
  65. })
  66. ->where(function ($query) use($params){
  67. $driver = isset($params['driver'])? $params['driver'] : '';
  68. if($driver){
  69. $query->where('b.realname','like',"%{$driver}%")->orWhere('b.mobile','like',"%{$driver}%");
  70. }
  71. })
  72. ->where(function ($query) use($params){
  73. $status = isset($params['status'])? $params['status'] : 0;
  74. if($status>0 && is_array($status)){
  75. $query->whereIn('a.status', $status);
  76. }else if($status){
  77. $query->where('a.status', $status);
  78. }
  79. $type = isset($params['type'])? $params['type'] : 0;
  80. if($type>0){
  81. $query->where('a.type', $type);
  82. }
  83. })
  84. ->select(['a.*','b.realname as driver_name','b.mobile','c.name as cate_name'])
  85. ->orderBy('a.create_time','desc')
  86. ->orderBy('a.id','desc')
  87. ->paginate($pageSize > 0 ? $pageSize : 9999999);
  88. $list = $list? $list->toArray() :[];
  89. if($list){
  90. foreach($list['data'] as &$item){
  91. $item['create_time'] = $item['create_time']? datetime($item['create_time'],'Y-m-d H.i.s') : '';
  92. $item['username'] = $item['driver_name']? $item['driver_name'].($item['mobile']?'('.$item['mobile'].')':'') : '';
  93. }
  94. }
  95. return [
  96. 'pageSize'=> $pageSize,
  97. 'total'=>isset($list['total'])? $list['total'] : 0,
  98. 'list'=> isset($list['data'])? $list['data'] : []
  99. ];
  100. }
  101. /**
  102. * 编辑
  103. * @return array
  104. */
  105. public function edit()
  106. {
  107. $data = request()->post();
  108. return parent::edit($data);
  109. }
  110. }