model = new Order(); $this->refund_order_model = new RefundOrder(); $this->comment_model = new Comment(); $this->admin_info = $this->adminInfo(); if(empty($this->admin_info)){ $this->errorMsg('你还没有管理员权限'); } } /** * @author chenniang * @DataTime: 2023-04-20 11:44 * @功能说明:获取当前用户的角色权限 */ public function adminInfo(){ $admin_model = new RoleAdmin(); $dis = [ 'user_id' => $this->getUserId(), 'status' => 1 ]; $data = $admin_model->dataInfo($dis); if(!empty($data['admin_id'])){ $admin_model = new Admin(); $admin = $admin_model->dataInfo(['id'=>$data['admin_id']]); //获取下级的代理商 $data['admin_arr'] = $admin_model->getAdminId($admin); $data['phone_encryption'] = $admin['phone_encryption']; }else{ $data['phone_encryption'] = 1; } return $data; } /** * @author chenniang * @DataTime: 2023-04-20 11:54 * @功能说明:首页各项数据统计 */ public function index(){ //订单管理各类状态 $order_type = [2,3,4,5,6,7]; $dis = [ 'uniacid' => $this->_uniacid, 'is_add' => 0 ]; $where = []; if(!empty($this->admin_info['admin_id'])){ $where[] = ['admin_id','in',$this->admin_info['admin_arr']]; } //订单数据 foreach ($order_type as $value){ $data['order_count'][$value] = $this->model->where($dis)->where($where)->where(['pay_type'=>$value])->count(); } //拒单 $data['refuse_order'][8] = $this->model->where($dis)->where($where)->where(['pay_type'=>8])->count(); //加钟服务 $dis['is_add'] = 1; $order_type = [2,3,6,7]; //订单数据 foreach ($order_type as $value){ if($value==6){ $data['add_count'][$value] = $this->model->where($dis)->where($where)->where('pay_type','in',[4,5,6])->count(); }else{ $data['add_count'][$value] = $this->model->where($dis)->where($where)->where(['pay_type'=>$value])->count(); } } $order_type = [1]; //加钟退款 foreach ($order_type as $value){ $data['add_refund_count'][$value] = $this->refund_order_model->where($dis)->where($where)->where(['status'=>$value])->count(); } $dis['is_add'] = 0; //退款 foreach ($order_type as $value){ $data['refund_count'][$value] = $this->refund_order_model->where($dis)->where($where)->where(['status'=>$value])->count(); } //菜单权限 $data['node'] = $this->admin_info['node']; //是否是代理商 $data['is_agent'] = !empty($this->admin_info['admin_id'])?1:0; //通知 $notice_model = new NoticeList(); //列表 $admin_arr = !empty($this->admin_info['admin_id'])?$this->admin_info['admin_arr']:0; $data = $notice_model->indexOrderNotice($data,$this->_uniacid,$admin_arr,$this->admin_info['node']); return $this->success($data); } /** * @author chenniang * @DataTime: 2021-03-15 14:43 * @功能说明:列表 */ public function orderList(){ $input = $this->_param; $is_add = isset($input['is_add'])?$input['is_add']:0; $dis[] = ['uniacid','=',$this->_uniacid]; $dis[] = ['is_add','=',$is_add]; if(!empty($this->admin_info['admin_id'])){ $dis[] = ['admin_id','in',$this->admin_info['admin_arr']]; } if(!empty($input['pay_type'])){ $dis[] = ['pay_type','=',$input['pay_type']]; }else{ $dis[] = ['pay_type','not in',[-1,1,8]]; } //订单号搜索 if(!empty($input['order_code'])){ $dis[] = ['order_code','like','%'.$input['order_code'].'%']; } $data = $this->model->where($dis)->field('id,material_price,coach_id,store_id,true_car_price,is_comment,order_code,true_service_price,pay_type,pay_price,start_time,create_time,user_id,end_time,add_pid,is_add')->order('id desc')->paginate(10)->toArray(); if(!empty($data['data'])){ foreach ($data['data'] as &$v){ $v['create_time'] = date('Y-m-d H:i:s',$v['create_time']); $v['start_time'] = date('Y-m-d H:i',$v['start_time']); $v['end_time'] = date('Y-m-d H:i',$v['end_time']); } } return $this->success($data); } /** * @author chenniang * @DataTime: 2021-03-15 14:58 * @功能说明:订单详情 */ public function orderInfo(){ $input = $this->_param; $dis = [ 'id' => $input['id'] ]; $data = $this->model->dataInfo($dis); $data['time_long'] = $data['true_time_long']; $data['distance'] = distance_text($data['distance']); //加钟订单 if($data['is_add']==0){ $data['add_order_id'] = $this->model->where(['add_pid'=>$data['id']])->where('pay_type','>',1)->field('id,order_code')->select()->toArray(); }else{ $data['add_pid'] = $this->model->where(['id'=>$data['add_pid']])->field('id,order_code')->find(); } $order_model = new OrderData(); //订单附表 $order_data = $order_model->dataInfo(['order_id'=>$input['id'],'uniacid'=>$this->_uniacid]); $data = array_merge($order_data,$data); //订单转派记录 $change_log_model = new CoachChangeLog(); $data['dispatch_record'] = $change_log_model->orderChangeLog($input['id']); $admin_model = new \app\massage\model\Admin(); $data['admin_name'] = $admin_model->where(['id'=>$data['admin_id']])->value('agent_name'); //门店订单 if(!empty($data['store_id'])){ $store_model = new StoreList(); $data['store_info'] = $store_model->where(['id'=>$data['store_id']])->field('title,cover,address,lng,lat,phone')->find(); } $arr = ['create_time','pay_time','serout_time','arrive_time','receiving_time','start_service_time','order_end_time','coach_refund_time']; foreach ($arr as $value){ $data[$value] = !empty($data[$value])?date('Y-m-d H:i:s',$data[$value]):0; } $data['start_time'] = date('Y-m-d H:i',$data['start_time']).'-'.date('H:i',$data['end_time']); $data['can_refund_price'] = $this->model->getOrderRefundPrice($data); $data['phone_encryption'] = $this->admin_info['phone_encryption']; return $this->success($data); } /** * @author chenniang * @DataTime: 2021-03-19 17:50 * @功能说明:退款订单详情 */ public function refundOrderInfo(){ $input = $this->_param; $dis = [ 'id' => $input['id'] ]; $data = $this->refund_order_model->dataInfo($dis); $data['pay_order_code'] = $this->model->where(['id'=>$data['order_id']])->value('order_code'); $data['create_time'] = date('Y-m-d H:i:s',$data['create_time']); $data['refund_time'] = !empty($data['refund_time'])?date('Y-m-d H:i:s',$data['refund_time']):""; $pay_order = $this->model->dataInfo(['id'=>$data['order_id']]); $data['car_type'] = $pay_order['car_type']; $data['distance'] = distance_text($pay_order['distance']); $data['pay_car_price'] = $pay_order['car_price']; $admin_model = new \app\massage\model\Admin(); $data['admin_name'] = $admin_model->where(['id'=>$data['admin_id']])->value('agent_name'); $data['store_id'] = $pay_order['store_id']; //门店订单 if(!empty($pay_order['store_id'])){ $store_model = new StoreList(); $data['store_info'] = $store_model->where(['id'=>$pay_order['store_id']])->field('title,cover,address,lng,lat,phone')->find(); } $data['phone_encryption'] = $this->admin_info['phone_encryption']; return $this->success($data); } /** * @author chenniang * @DataTime: 2021-03-17 17:44 * @功能说明:退款订单列表 */ public function refundOrderList(){ $input = $this->_param; $dis[] = ['a.uniacid','=',$this->_uniacid]; //订单状态搜索 if(!empty($input['status'])){ $dis[] = ['a.status','=',$input['status']]; }else{ $dis[] = ['a.status','>',-1]; } if(!empty($this->admin_info['admin_id'])){ $dis[] = ['d.admin_id','in',$this->admin_info['admin_arr']]; } if(!empty($input['order_code'])){ $dis[] = ['a.order_code','like','%'.$input['order_code'].'%']; } $is_add = !empty($input['is_add'])?$input['is_add']:0; $dis[] = ['a.is_add','=',$is_add]; $data = $this->refund_order_model->indexAdminDataList($dis); return $this->success($data); } /** * @author chenniang * @DataTime: 2021-03-18 09:21 * @功能说明:拒绝退款 */ public function noPassRefund(){ $input = $this->_input; $res = $this->refund_order_model->noPassRefund($input['id'],$this->getUserId()); if(!empty($res['code'])){ $this->errorMsg($res['msg']); } return $this->success($res); } /**\ * @author chenniang * @DataTime: 2021-03-18 09:28 * @功能说明:同意退款 */ public function passRefund(){ $input = $this->_input; $order = $this->refund_order_model->dataInfo(['id'=>$input['id']]); $is_app= $this->model->where(['id'=>$order['order_id']])->value('app_pay'); $res = $this->refund_order_model->passOrder($input['id'],$input['price'],$this->payConfig($this->_uniacid,$is_app),$this->getUserId(),$input['text']); if(!empty($res['code'])){ $this->errorMsg($res['msg']); } return $this->success($res); } /** * @author chenniang * @DataTime: 2022-12-15 11:34 * @功能说明:订单升级记录 */ public function orderUpRecord(){ $input = $this->_param; $order_model = new UpOrderList(); $data = $order_model->orderUpRecord($input['order_id']); return $this->success($data); } /** * @author chenniang * @DataTime: 2021-07-11 22:34 * @功能说明:技师修改订单信息) */ public function adminUpdateOrder() { $input = $this->_input; $order = $this->model->dataInfo(['id' => $input['order_id']]); $update = $this->model->coachOrdertext($input,1); $refund_model = new RefundOrder(); //判断有无申请中的退款订单 $refund_order = $refund_model->dataInfo(['order_id' => $order['id'], 'status' => 1]); if (!empty($refund_order)) { $this->errorMsg('该订单正在申请退款,请先联系处理再进行下一步'); } if($order['pay_type']<1){ $this->errorMsg('订单已被取消'); } Db::startTrans(); if($input['type']==7){ if ($order['pay_type'] != 6&&!empty($order['coach_id'])) { $this->errorMsg('订单状态错误'); } $this->model->hxOrder($order); }elseif ($input['type'] == -1){ if ($order['pay_price'] > 0&&$order['pay_type']>1) { $refund_model = new RefundOrder(); $res = $refund_model->refundCash($this->payConfig($this->_uniacid,$order['app_pay']), $order, $order['pay_price']); if (!empty($res['code'])) { Db::rollback(); $this->errorMsg($res['msg']); } if ($res != true) { Db::rollback(); $this->errorMsg('退款失败,请重试2'); } } //取消订单 $res = $this->model->cancelOrder($order); if (!empty($res['code'])) { Db::rollback(); $this->errorMsg($res['msg']); } } $this->model->dataUpdate(['id' => $input['order_id']], $update); //到达后车费秒到账 if($input['type']==5){ $coach_model = new Coach(); $coach_model->coachCarPriceAccount($order,$this->payConfig($this->_uniacid,$order['app_pay'])); } $log_model = new OrderLog(); $log_model->addLog($input['order_id'],$this->_uniacid,$input['type'],$order['pay_type'],1,$this->getUserId()); Db::commit(); return $this->success(true); } /** * @author chenniang * @DataTime: 2023-02-27 14:52 * @功能说明:订单更换技师 */ public function orderChangeCoach(){ $input = $this->_input; $refund_model = new RefundOrder(); //判断有无申请中的退款订单 $refund_order = $refund_model->dataInfo(['order_id' => $input['order_id'], 'status' => 1]); if (!empty($refund_order)) { $this->errorMsg('该订单正在申请退款,请先处理再进行下一步'); } $success_add_order = $this->model->dataInfo(['add_pid'=>$input['order_id'],'pay_type'=>7]); if(!empty($success_add_order)){ $this->errorMsg('该订单加钟订单已经完成,无法转单'); } $order = $this->model->dataInfo(['id'=>$input['order_id']]); $change_model = new CoachChangeLog(); $coach_name = !empty($input['coach_name'])?$input['coach_name']:''; $text = !empty($input['text'])?$input['text']:''; $phone = !empty($input['mobile'])?$input['mobile']:''; $admin_id = !empty($input['admin_id'])?$input['admin_id']:0; $res = $change_model->orderChangeCoach($order,$input['coach_id'],$this->_user['id'],$admin_id,$coach_name,$text,$phone); if (!empty($res['code'])) { $this->errorMsg($res['msg']); } return $this->success($res); } /** * @author chenniang * @DataTime: 2023-02-28 14:21 * @功能说明:订单转派技师列表 */ public function orderChangeCoachList(){ $input = $this->_param; $coach_model = new Coach(); $order = $this->model->dataInfo(['id'=>$input['order_id']]); //获取订单里想关联服务的技师 $coach_id = $coach_model->getOrderServiceCoach($order); $dis[] = ['uniacid','=',$this->_uniacid]; $dis[] = ['status','=',2]; $dis[] = ['id','in',$coach_id]; $dis[] = ['id','<>',$order['coach_id']]; $dis[] = ['is_work','=',1]; $dis[] = ['user_id','>',0]; if(!empty($this->admin_info['admin_id'])){ $dis[] = ['admin_id','in',$this->admin_info['admin_arr']]; } if(!empty($input['coach_name'])){ $dis[] = ['coach_name','like','%'.$input['coach_name'].'%']; } //门店订单 只能转同门店的技师 if(!empty($order['store_id'])){ $dis[] = ['store_id','=',$order['store_id']]; } $list = $coach_model->where($dis)->select()->toArray(); $log_model = new CoachChangeLog(); //转派技师时候 获取满足条件的技师 并获取最近的服务时间 $arr = $log_model->getNearTimeCoach($order,$list); $top = !empty($input['type'])&&$input['type']==1?'distance asc,id desc':'near_time asc,id desc'; $lat = $order['address_info']['lat']; $lng = $order['address_info']['lng']; $alh = 'ACOS(SIN(('.$lat.' * 3.1415) / 180 ) *SIN((lat * 3.1415) / 180 ) +COS(('.$lat.' * 3.1415) / 180 ) * COS((lat * 3.1415) / 180 ) *COS(('.$lng.' * 3.1415) / 180 - (lng * 3.1415) / 180 ) ) * 6378.137*1000 as distance'; $data = $coach_model->where('id','in',$arr)->field(['*', $alh])->order($top)->paginate(10)->toArray(); if(!empty($data['data'])){ $admin_model = new \app\massage\model\Admin(); $user_model = new User(); foreach ($data['data'] as &$v){ $v['partner_name'] = $user_model->where(['id'=>$v['partner_id']])->value('nickName'); $v['near_time'] = date('m-d H:i',$v['near_time']); $v['admin_info']= $admin_model->where(['id'=>$v['admin_id']])->field('city_type,agent_name as username')->find(); $v['price'] = $coach_model->getCoachServicePrice($order,$v['id']); } } return $this->success($data); } /** * @author chenniang * @DataTime: 2021-07-16 10:28 * @功能说明: */ public function noticeUpdate(){ $input = $this->_input; $notice_model = new NoticeList(); $data = $notice_model->dataUpdate(['id'=>$input['id']],$input); return $this->success($data); } /** * @author chenniang * @DataTime: 2022-12-09 15:18 * @功能说明:技师获取客户虚拟电话 */ public function getVirtualPhone(){ $input = $this->_input; $order_model = new Order(); $user_model = new User(); $order = $order_model->dataInfo(['id'=>$input['order_id']]); return $this->success($order['address_info']['mobile']); return $order['address_info']['mobile']; $called = new \app\virtual\model\Config(); $phone = $user_model->where(['id'=>$this->getUserId()])->value('phone'); if(empty($phone)){ $res = $order['address_info']['mobile']; }else{ $res = $called->getVirtual($order,1,$phone); } return $this->success($res); } /** * @author chenniang * @DataTime: 2022-06-22 21:30 * @功能说明:加盟商下拉框 */ public function adminSelect(){ $input = $this->_param; $dis = [ 'is_admin' => 0, 'status' => 1, 'uniacid' => $this->_uniacid ]; $where = []; if(!empty($this->admin_info['admin_id'])){ $where[] = ['id','in',$this->admin_info['admin_arr']]; } $admin_model = new Admin(); $data = $admin_model->where($dis)->where($where)->field('id,username,agent_name')->select()->toArray(); return $this->success($data); } }