|
@@ -16,159 +16,174 @@ class Order extends Apic
|
|
|
protected $noNeedRight = '*';
|
|
|
|
|
|
|
|
|
+ private function status_text($status){
|
|
|
+ $arr = [
|
|
|
+ 1 => '待支付',
|
|
|
+ 2 => '待处理',
|
|
|
+ 3 => '已完成',
|
|
|
+ 4 => '已取消',
|
|
|
+ ];
|
|
|
+
|
|
|
+ return isset($arr[$status]) ? $arr[$status] : '';
|
|
|
+ }
|
|
|
//
|
|
|
public function lists(){
|
|
|
$keyword = input('keyword','');
|
|
|
- $status = input('status','all');
|
|
|
+ $starttime = input('starttime',0);
|
|
|
+ $endtime = input('endtime',0);
|
|
|
+ $servicetype_id = intval(input('servicetype_id',0));
|
|
|
+ $status = intval(input('status',0));
|
|
|
|
|
|
$where = [
|
|
|
- 'company_id' => $this->auth->id,
|
|
|
+ 'company_id' => $this->auth->company_id,
|
|
|
];
|
|
|
- if($status !== 'all'){
|
|
|
- $where['status'] = $status;
|
|
|
- }
|
|
|
- if($status == 20){ //待还车
|
|
|
- $where['status'] = 20;
|
|
|
- $where['endtime'] = ['gt',time()];
|
|
|
+ if($starttime || $endtime){
|
|
|
+ $where['createtime'] = ['between',$starttime,$endtime];
|
|
|
}
|
|
|
- if($status == 200){ //逾期
|
|
|
- $where['status'] = 20;
|
|
|
- $where['endtime'] = ['elt',time()];
|
|
|
+ if($servicetype_id){
|
|
|
+ $where['servicetype_id'] = $servicetype_id;
|
|
|
}
|
|
|
- if($status == 30){
|
|
|
- $where['status'] = ['IN',[-1,-2,30]];
|
|
|
+ if($status){
|
|
|
+ $where['status'] = $status; //状态:1=待支付,2=待处理,3=已核销(完成),4=已取消
|
|
|
}
|
|
|
+
|
|
|
if(!empty($keyword))
|
|
|
{
|
|
|
- $where['user_truename|user_mobile|orderno'] = ['LIKE','%'.$keyword.'%'];
|
|
|
+ $where['user_car_number|user_mobile'] = ['LIKE','%'.$keyword.'%'];
|
|
|
}
|
|
|
- $list = Db::name('order')->where($where)->order('id desc')->autopage()->select();
|
|
|
-
|
|
|
- $list = list_domain_image($list,['car_image','idcard_images','driver_images','get_yibiao_images','get_carvideo','back_yibiao_images','back_carvideo']);
|
|
|
+ $list = Db::name('order')->alias('order')
|
|
|
+ ->join('servicetype','order.servicetype_id = servicetype.id','LEFT')
|
|
|
+ ->field('order.id,orderno,ordertype,user_name,user_car_number,createtime,servicetype_id,server_info,status,finish_time,cancel_reason,servicetype.title as servicetype_title,servicetype.baoyang_switch')->where($where)->order('order.id desc')->autopage()->select();
|
|
|
|
|
|
foreach($list as $key => &$val){
|
|
|
- $val['status_text'] = $this->status_text($val['status'],$val['endtime']);
|
|
|
-
|
|
|
- if($val['status'] == 20 && time() >= $val['endtime']){
|
|
|
- $val['status'] = 200; //強制改掉
|
|
|
- }
|
|
|
-
|
|
|
- //追加取消
|
|
|
- $val['cancel_info'] = (object)[];
|
|
|
- if($val['status'] == -1 || $val['status'] == -2){
|
|
|
- //取消订单追加取消原因
|
|
|
- $val['cancel_info'] = Db::name('order_cancel')->where('order_id',$val['id'])->find();
|
|
|
- }
|
|
|
-
|
|
|
- //追加评价
|
|
|
- $val['comment_info'] = (object)[];
|
|
|
- if($val['status'] == 30){
|
|
|
- //完成订单追加评价
|
|
|
- $comment_info = Db::name('order_comment')->where('order_id',$val['id'])->find();
|
|
|
- if($comment_info){
|
|
|
- $val['comment_info'] = $comment_info;
|
|
|
- }
|
|
|
- }
|
|
|
+ $val['status_text'] = $this->status_text($val['status']);
|
|
|
}
|
|
|
$this->success(1,$list);
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
//详情
|
|
|
public function info(){
|
|
|
$id = input('id',0);
|
|
|
- $info = Db::name('order')->where('id',$id)->find();
|
|
|
- $info = info_domain_image($info,['car_image','idcard_images','driver_images','get_yibiao_images','get_carvideo','back_yibiao_images','back_carvideo']);
|
|
|
+ $info = Db::name('order')->alias('order')
|
|
|
+ ->join('servicetype','order.servicetype_id = servicetype.id','LEFT')
|
|
|
+ ->field('order.*,servicetype.title as servicetype_title,servicetype.baoyang_switch')
|
|
|
+ ->where('order.id',$id)->find();
|
|
|
+ $info = info_domain_image($info,['server_images']);
|
|
|
+ $info['status_text'] = $this->status_text($info['status']);
|
|
|
|
|
|
- $info['status_text'] = $this->status_text($info['status'],$info['endtime']);
|
|
|
- if($info['status'] == 20 && time() >= $info['endtime']){
|
|
|
- $info['status'] = 200; //強制改掉
|
|
|
- }
|
|
|
-
|
|
|
- //完成订单追加评价
|
|
|
- $comment_info = Db::name('order_comment')->alias('c')
|
|
|
- ->field('c.*,user.avatar,user.mobile')
|
|
|
- ->join('user','c.user_id = user.id','LEFT')
|
|
|
- ->where('c.order_id',$id)->find();
|
|
|
- $comment_info = info_domain_image($comment_info,['avatar']);
|
|
|
- if(!empty($comment_info)){
|
|
|
- $comment_info['mobile'] = str_replace(substr($comment_info['mobile'],3,5),'****',$comment_info['mobile']);
|
|
|
- }
|
|
|
- $info['comment_info'] = $comment_info;
|
|
|
-
|
|
|
- //取消订单追加取消原因
|
|
|
- $info['cancel_info'] = Db::name('order_cancel')->where('order_id',$id)->find();
|
|
|
+ $info['appen_list'] = Db::name('order_appen')->where('order_id',$id)->select();
|
|
|
|
|
|
$this->success(1,$info);
|
|
|
}
|
|
|
- //取消理由
|
|
|
- public function cancel_config(){
|
|
|
- $list = Db::name('company_cancel_config')->order('id asc')->select();
|
|
|
- $this->success(1,$list);
|
|
|
- }
|
|
|
+
|
|
|
//取消
|
|
|
public function cancel(){
|
|
|
$id = input('id',0);
|
|
|
$reason = input('reason','');
|
|
|
|
|
|
- Db::startTrans();
|
|
|
- $info = Db::name('order')->where('id',$id)->where('company_id',$this->auth->id)->lock(true)->find();
|
|
|
- if($info['status'] == -2){
|
|
|
- Db::rollback();
|
|
|
- $this->error('当前订单已经申请取消,已付款订单审核后可退款');
|
|
|
+ $info = Db::name('order')->where('id',$id)->where('company_id',$this->auth->company_id)->find();
|
|
|
+ if($info['status'] == 4){
|
|
|
+ $this->error('当前订单已经取消');
|
|
|
}
|
|
|
- if($info['status'] != 0 && $info['status'] != 10){
|
|
|
- Db::rollback();
|
|
|
+ if($info['status'] != 0 && $info['status'] != 2){
|
|
|
$this->error('当前订单状态不能取消');
|
|
|
}
|
|
|
+ if($info['ordertype'] == 3){
|
|
|
+ $this->error('套餐订单不能取消');
|
|
|
+ }
|
|
|
+
|
|
|
+ //取消
|
|
|
+ $rs = Db::name('order')->where('id',$id)->update(['status'=>4,'cancel_time'=>time(),'finish_time'=>time(),'cancel_reason'=>$reason]);
|
|
|
|
|
|
- //未付款取消
|
|
|
- if($info['status'] == 0){
|
|
|
- $rs = Db::name('order')->where('id',$id)->update(['status'=>-1]);
|
|
|
+ if($rs === false){
|
|
|
+ $this->error('取消失败');
|
|
|
}
|
|
|
|
|
|
- //已付款取消
|
|
|
- if($info['status'] == 10){
|
|
|
- $rs = Db::name('order')->where('id',$id)->update(['status'=>-2]);
|
|
|
- //扣除车行收益
|
|
|
- //从计划任务里走
|
|
|
+ $this->success('取消成功');
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //完成
|
|
|
+ public function finish(){
|
|
|
+ $id = input('id',0);
|
|
|
+
|
|
|
+ $info = Db::name('order')->where('id',$id)->where('company_id',$this->auth->company_id)->find();
|
|
|
+ if($info['status'] == 2){
|
|
|
+ $this->error('当前订单不能完成');
|
|
|
}
|
|
|
|
|
|
+ //完成
|
|
|
+ $rs = Db::name('order')->where('id',$id)->update(['status'=>3,'finish_time'=>time()]);
|
|
|
+
|
|
|
if($rs === false){
|
|
|
+ $this->error('操作失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ $baoyang_switch = Db::name('servicetype')->where('id',$info['servicetype_id'])->value('baoyang_switch');
|
|
|
+
|
|
|
+ $this->success('操作成功',$baoyang_switch);
|
|
|
+ }
|
|
|
+
|
|
|
+ //追加列表
|
|
|
+ public function appen_lists(){
|
|
|
+ $id = input('id',0);
|
|
|
+
|
|
|
+ $info = Db::name('order')->field('id,orderno,pay_fee,package_price,appen_fee')->where('id',$id)->where('company_id',$this->auth->company_id)->find();
|
|
|
+ if(!$info){
|
|
|
+ $this->error('不存在的订单');
|
|
|
+ }
|
|
|
+
|
|
|
+ $info['appen_list'] = Db::name('order_appen')->where('order_id',$id)->select();
|
|
|
+
|
|
|
+ $this->success(1,$info);
|
|
|
+ }
|
|
|
+
|
|
|
+ //追加新费用
|
|
|
+ public function appen_newone(){
|
|
|
+ $id = input('id',0);
|
|
|
+
|
|
|
+ Db::startTrans();
|
|
|
+ $info = Db::name('order')->field('id,orderno,pay_fee,package_price,appen_fee')->where('id',$id)->where('company_id',$this->auth->company_id)->lock(true)->find();
|
|
|
+ if(!$info){
|
|
|
+ $this->error('不存在的订单');
|
|
|
+ }
|
|
|
+
|
|
|
+ //加入新的一条
|
|
|
+ $name = input('name','');
|
|
|
+ $price = intval(input('price',0));
|
|
|
+
|
|
|
+ if($price <= 0){
|
|
|
Db::rollback();
|
|
|
- $this->error('申请取消失败');
|
|
|
+ $this->error('请填写正确的金额');
|
|
|
}
|
|
|
|
|
|
$data = [
|
|
|
- 'user_id' => $info['user_id'],
|
|
|
- 'company_id' => $info['company_id'],
|
|
|
- 'order_id' => $info['id'],
|
|
|
- 'reason' => '商家取消:'.$reason,
|
|
|
- 'refund_price' => 0,
|
|
|
- 'type' => $info['status'], //分类:0=未付款,10=已付款
|
|
|
+ 'order_id' => $id,
|
|
|
+ 'name' => $name,
|
|
|
+ 'price' => $price,
|
|
|
'createtime' => time(),
|
|
|
- 'status' => $info['status'] == 0 ? 2 : 0, //状态:0=未处理,1=已处理,2=无需处理
|
|
|
- 'from' => 2, //取消方:1=用户取消,2=商户取消
|
|
|
];
|
|
|
|
|
|
- $rs_cancle = Db::name('order_cancel')->insertGetId($data);
|
|
|
- if(!$rs_cancle){
|
|
|
+ $log_id = Db::name('order_appen')->insertGetId($data);
|
|
|
+ if(!$log_id){
|
|
|
Db::rollback();
|
|
|
- $this->error('申请取消失败');
|
|
|
+ $this->error('操作失败');
|
|
|
}
|
|
|
|
|
|
- //解除汽车占用
|
|
|
- $rs_car = Db::name('car')->where('id',$info['car_id'])->update(['status'=>1]);
|
|
|
- if(!$rs_car){
|
|
|
+ //计算追加总额做冗余
|
|
|
+ $sum_price = Db::name('order_appen')->where('order_id',$id)->sum('price');
|
|
|
+ $rs = Db::name('order')->where('id',$id)->update(['appen_fee'=>$sum_price]);
|
|
|
+ if($rs === false){
|
|
|
Db::rollback();
|
|
|
- $this->error('申请取消失败');
|
|
|
+ $this->error('操作失败');
|
|
|
}
|
|
|
|
|
|
+ //结束
|
|
|
Db::commit();
|
|
|
- $this->success('取消成功');
|
|
|
-
|
|
|
+ $this->success();
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
}
|