| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- namespace App\Services\Common;
- use App\Helpers\Jwt;
- use App\Models\ActionLogModel;
- use App\Models\DriverModel;
- use App\Models\DriverProfileModel;
- use App\Services\BaseService;
- use App\Services\RedisService;
- use App\Services\SmsService;
- use Illuminate\Support\Facades\DB;
- use phpQrcode\QRcode;
- /**
- * 司机管理-服务类
- * @author laravel开发员
- * @since 2020/11/11
- * Class DriverService
- * @package App\Services\Api
- */
- class DriverService extends BaseService
- {
- // 静态对象
- protected static $instance = null;
- /**
- * 构造函数
- * @author laravel开发员
- * @since 2020/11/11
- * DriverService constructor.
- */
- public function __construct()
- {
- $this->model = new DriverModel();
- }
- /**
- * 静态入口
- */
- public static function make()
- {
- if (!self::$instance) {
- self::$instance = new static();
- }
- return self::$instance;
- }
- /**
- * @param $params
- * @param int $pageSize
- * @return array
- */
- public function getDataList($params, $pageSize = 15)
- {
- $where = ['a.mark' => 1];
- $list = $this->model->with(['carCategory','brand','profile','level'])->from('driver as a')
- ->leftJoin('member as b', 'b.id', '=', 'a.user_id')
- ->where($where)
- ->where(function ($query) use($params){
- $keyword = isset($params['keyword'])? $params['keyword'] : '';
- if($keyword){
- $query->where('a.realname','like',"%{$keyword}%")->orWhere('a.mobile','like',"%{$keyword}%")->orWhere('a.car_number','like',"%{$keyword}%");
- }
- $status = isset($params['status'])? $params['status'] : 0;
- $type = isset($params['type'])? $params['type'] : 0;
- if($status && is_array($status)){
- $query->whereIn('a.status', $status);
- }else if($status){
- $query->where('a.status', $status);
- }
- if($type == 2){
- $query->whereIn('a.status', [2,4]);
- }
- })
- ->select(['a.*','b.nickname','b.username'])
- ->orderBy('a.create_time','desc')
- ->orderBy('a.id','desc')
- ->paginate($pageSize > 0 ? $pageSize : 9999999);
- $list = $list? $list->toArray() :[];
- if($list){
- foreach($list['data'] as &$item){
- $item['create_time'] = $item['create_time']? datetime($item['create_time'],'Y-m-d H:i:s') : '';
- $item['avatar'] = isset($item['avatar']) && $item['avatar']? get_image_url($item['avatar']) : '';
- // 认证资料
- $item['bank_account'] = ['bank_name'=>'','bank_card'=>'','realname'=>''];
- if(isset($item['profile'])){
- $item['profile'] = $item['profile']? $item['profile'] : [];
- if($item['profile']){
- $item['profile']['alipay_qrcode'] = $item['profile']['alipay_qrcode']? get_image_url($item['profile']['alipay_qrcode']) : '';
- $item['profile']['wxpay_qrcode'] = $item['profile']['wxpay_qrcode']? get_image_url($item['profile']['wxpay_qrcode']) : '';
- $item['bank_account'] = $item['profile']['bank_account']? json_decode($item['profile']['bank_account']) : ['bank_name'=>'','bank_card'=>'','realname'=>''];
- $item['profile']['idcard_img'] = $item['profile']['idcard_img']? get_image_url($item['profile']['idcard_img']) : '';
- $item['profile']['driver_license'] = $item['profile']['driver_license']? get_image_url($item['profile']['driver_license']) : '';
- $item['profile']['driving_license'] = $item['profile']['driving_license']? get_image_url($item['profile']['driving_license']) : '';
- $item['profile']['qualification_certificate'] = $item['profile']['qualification_certificate']? get_image_url($item['profile']['qualification_certificate']) : '';
- $item['profile']['transport_certificate'] = $item['profile']['transport_certificate']? get_image_url($item['profile']['transport_certificate']) : '';
- $item['profile']['no_crime_certificate'] = $item['profile']['no_crime_certificate']? get_image_url($item['profile']['no_crime_certificate']) : '';
- }
- }
- $item['level_name'] = isset($item['level']) && $item['level']? $item['level']['name'] : '';
- $item['level'] = isset($item['level']) && $item['level']? $item['level']['id'] : 0;
- $vipExpired = isset($item['vip_expired'])? $item['vip_expired'] : '';
- if($vipExpired && date('Y-m-d H:i:s')>$vipExpired){
- $item['level'] = 1;
- $item['level_name'] = '普通会员';
- }
- }
- }
- return [
- 'pageSize'=> $pageSize,
- 'total'=>isset($list['total'])? $list['total'] : 0,
- 'list'=> isset($list['data'])? $list['data'] : []
- ];
- }
- /**
- * 获取资料详情
- * @param $where
- * @param array $field
- */
- public function getInfo($where, $type = 'info', array $field = [])
- {
- $defaultField = ['id','user_id', 'realname', 'mobile','car_number', 'balance','car_cate_id','car_brand_id','vip_expired','level','is_auth','order_count','online_time','receive_order','lock_type','driver_type','is_online', 'status', 'avatar'];
- $field = $field ? $field : $defaultField;
- if (is_array($where)) {
- $info = $this->model->with(['level','profile'])->where($where)->select($field)->first();
- } else {
- $info = $this->model->with(['level','profile'])->where(['id' => (int)$where])->select($field)->first();
- }
- $info = $info ? $info->toArray() : [];
- if ($info) {
- if(isset($info['avatar'])){
- $info['avatar'] = $info['avatar'] ? get_image_url($info['avatar']) : '';
- }
- if(isset($info['balance'])){
- $info['balance'] = moneyFormat($info['balance'], 2);
- }
- if(isset($info['tz_score'])){
- $info['tz_score'] = moneyFormat($info['tz_score'], 2);
- }
- if(isset($info['mobile'])){
- $info['mobile'] = $info['mobile']? $info['mobile'] : '';
- $info['mobile_text'] = $info['mobile']? format_mobile($info['mobile']) : '';
- }
- if(isset($info['level'])){
- $info['level'] = $info['level']? $info['level'] : [];
- }
- // 认证资料
- $info['bank_account'] = [];
- if(isset($info['profile'])){
- $info['profile'] = $info['profile']? $info['profile'] : [];
- if($info['profile']){
- $info['profile']['idcard_img'] = $info['profile']['idcard_img']? get_image_url($info['profile']['idcard_img']) : '';
- $info['profile']['driver_license'] = $info['profile']['driver_license']? get_image_url($info['profile']['driver_license']) : '';
- $info['profile']['driving_license'] = $info['profile']['driving_license']? get_image_url($info['profile']['driving_license']) : '';
- $info['profile']['qualification_certificate'] = $info['profile']['qualification_certificate']? get_image_url($info['profile']['qualification_certificate']) : '';
- $info['profile']['transport_certificate'] = $info['profile']['transport_certificate']? get_image_url($info['profile']['transport_certificate']) : '';
- $info['profile']['no_crime_certificate'] = $info['profile']['no_crime_certificate']? get_image_url($info['profile']['no_crime_certificate']) : '';
- }
- }
- }
- return $info;
- }
- /**
- * 按日期统计注册司机数
- * @param string $beginAt 开始时间
- * @param string $endAt 结束时间
- * @param int[] $status 状态:数组或数值
- * @return mixed
- */
- public function getRegisterCount($beginAt='', $endAt='', $status=[2,4])
- {
- $where = ['mark' => 1];
- return $this->model->where($where)->where(function($query) use($beginAt,$endAt,$status){
- if($beginAt && $endAt){
- $query->whereBetween('create_time', [strtotime($beginAt), strtotime($endAt)]);
- }else if($beginAt){
- $query->where('create_time','>=', strtotime($beginAt));
- }
- if($status && is_array($status)){
- $query->whereIn('status',$status);
- }else if($status){
- $query->where('status',$status);
- }
- })->count('id');
- }
- /**
- * 添加会编辑会员
- * @return array
- * @since 2020/11/11
- * @author laravel开发员
- */
- public function edit()
- {
- // 请求参数
- $data = request()->all();
- // 头像处理
- $avatar = trim($data['avatar']);
- if ($avatar) {
- $data['avatar'] = get_image_path($avatar);
- }
- $profile = isset($data['profile'])? $data['profile'] : [];
- if($profile){
- if(isset($profile['idcard_img'])){
- $profile['idcard_img'] = get_image_path($profile['idcard_img']);
- }
- if(isset($profile['wxpay_qrcode'])){
- $profile['wxpay_qrcode'] = get_image_path($profile['wxpay_qrcode']);
- }
- if(isset($profile['alipay_qrcode'])){
- $profile['alipay_qrcode'] = get_image_path($profile['alipay_qrcode']);
- }
- if(isset($data['bank_account'])){
- $profile['bank_account'] = $data['bank_account']? json_encode($data['bank_account'], 256) : '';
- }
- if(isset($profile['driver_license'])){
- $profile['driver_license'] = get_image_path($profile['driver_license']);
- }
- if(isset($profile['driving_license'])){
- $profile['driving_license'] = get_image_path($profile['driving_license']);
- }
- if(!empty($profile['qualification_certificate'])){
- $profile['qualification_certificate'] = get_image_path($profile['qualification_certificate']);
- }
- if(!empty($profile['transport_certificate'])){
- $profile['transport_certificate'] = get_image_path($profile['transport_certificate']);
- }
- if(!empty($profile['no_crime_certificate'])){
- $profile['no_crime_certificate'] = get_image_path($profile['no_crime_certificate']);
- }
- }
- // 手机号唯一
- $id = isset($data['id'])? $data['id'] : 0;
- $mobile = isset($data['mobile'])? trim($data['mobile']) : '';
- $checkId = $this->model->where(['mobile'=>$mobile,'mark'=>1])->value('id');
- if($checkId && ($id != $checkId)){
- return message('手机号已存在',false);
- }
- unset($data['profile']);
- DB::beginTransaction();
- $result = parent::edit($data); // TODO: Change the autogenerated stub
- $success = isset($result['success'])? $result['success'] : '';
- $id = isset($result['data']['id'])? $result['data']['id'] : 0;
- if($success != true || !$id){
- DB::rollBack();
- return message('保存失败',false);
- }
- $profile['driver_id'] = $id;
- if(DriverProfileModel::where(['driver_id'=> $id])->value('id')){
- if (!DriverProfileModel::where(['driver_id' => $id])->update($profile)) {
- DB::rollBack();
- return message('保存失败',false);
- }
- }else{
- if(!DriverProfileModel::insertgetId($profile)){
- DB::rollBack();
- return message('保存失败',false);
- }
- }
- // 设置日志标题
- ActionLogModel::setTitle("修改或审核司机信息");
- ActionLogModel::record();
- DB::commit();
- return $result;
- }
- /**
- * 选项
- * @return array
- */
- public function options()
- {
- // 获取参数
- $param = request()->all();
- // 用户ID
- $keyword = getter($param, "keyword");
- $userId = getter($param, "driver_id");
- $datas = $this->model->where(['status'=> 2,'mark'=>1])
- ->where(function($query) use($userId){
- if($userId){
- $query->whereNotIn('id', [$userId]);
- }
- })
- ->where(function($query) use($keyword){
- if($keyword){
- $query->where('realname','like',"%{$keyword}%")->orWhere('mobile','like',"%{$keyword}%");
- }
- })
- ->select(['id','mobile','realname','car_number','status'])
- ->get();
- return $datas? $datas->toArray() : [];
- }
- /**
- * 删除
- * @return array
- */
- public function delete()
- {
- // 设置日志标题
- ActionLogModel::setTitle("删除司机信息");
- ActionLogModel::record();
- $this->model->where('mark',0)->where('update_time','<=', time() - 15*86400)->delete();
- return parent::delete(); // TODO: Change the autogenerated stub
- }
- }
|