Browse Source

保养列表和订单消息

zhangxiaobin 1 year ago
parent
commit
a6208926d3

+ 7 - 8
application/api/controller/Order.php

@@ -165,20 +165,19 @@ class Order extends Api
             $serviceTypeId = input('servicetype_id',0);
             $carId = input('car_id',0);
             $carNumber = input('car_number','');
+            $o = 'order';
+            $st = 'servicetype';
             if (!empty($serviceTypeId)) {
-                $where['servicetype_id'] = $serviceTypeId;
+                $where[$o.'.servicetype_id'] = $serviceTypeId;
             }
             if (!empty($carId)) {
-                $where['car_id'] = $carId;
+                $where[$o.'.user_car_id'] = $carId;
             }
             if (empty($carNumber)) {
-                $where['user_car_number'] = $carNumber;
+                $where[$o.'.user_car_number'] = $carNumber;
             }
-            $where['user_id'] = $this->auth->id;
-            $where['status'] = 3;//状态:2=待处理,3=已完成,4=已取消
-
-            $o = 'order';
-            $st = 'servicetype';
+            $where[$o.'.user_id'] = $this->auth->id;
+            $where[$o.'.status'] = 3;//状态:2=待处理,3=已完成,4=已取消
             $field = $o.'.id,servicetype_id,server_info,finish_time,next_date,next_carlicheng,pay_fee,appen_fee,'.$st.'.title as `service_title`';
             $result = $this->model->alias($o)->field($field)
                 ->join($st,$st.'.id = '.$o.'.servicetype_id','LEFT')

+ 17 - 2
application/api/controller/company/Order.php

@@ -3,10 +3,13 @@
 namespace app\api\controller\company;
 
 use app\common\controller\Apic;
+use app\common\service\UserService;
 use think\Db;
 
 use alipaysdkphpallmaster\aop\AopClient;
 use alipaysdkphpallmaster\aop\request\AlipayTradePayRequest;
+use think\Log;
+
 /**
  * 订单管理
  */
@@ -123,7 +126,13 @@ class Order extends Apic
         if($rs === false){
             $this->error('取消失败');
         }
-
+        //订单取消发送消息
+        $userService = new UserService();
+        $params['order_id'] = $id;
+        $orderRes = $userService->msgPreOrder($params);
+        if (!$orderRes['status']) {
+            Log::error('order_id:'.$id.' error:'.$orderRes['msg']);
+        }
         $this->success('取消成功');
 
     }
@@ -156,7 +165,13 @@ class Order extends Apic
         }
 
         Db::commit();
-
+        //订单取消发送消息
+        $userService = new UserService();
+        $params['order_id'] = $id;
+        $orderRes = $userService->msgPreOrder($params);
+        if (!$orderRes['status']) {
+            Log::error('order_id:'.$id.' error:'.$orderRes['msg']);
+        }
         //是否弹出保养
         $baoyang_switch = Db::name('servicetype')->where('id',$info['servicetype_id'])->value('baoyang_switch');
 

+ 7 - 4
application/api/controller/company/Preorder.php

@@ -5,6 +5,7 @@ namespace app\api\controller\company;
 use app\common\controller\Apic;
 use app\common\service\UserService;
 use think\Db;
+use think\Log;
 
 /**
  * 预约管理
@@ -32,9 +33,6 @@ class Preorder extends Apic
     public function cancel(){
         $id = input('pre_order_id',0);
         $cancel_reason = input('cancel_reason','');
-        $userService = new UserService();
-        $params['pre_order_id'] = $id;
-        $preOrderRes = $userService->msgPreOrder($params);echo '<pre>';var_dump($preOrderRes);exit;
         $update = [
             'cancel_reason' => $cancel_reason,
             'cancel_time'   => time(),
@@ -42,7 +40,12 @@ class Preorder extends Apic
             'pre_order_status' => 0,
         ];
         Db::name('pre_order')->where('id',$id)->where('company_id',$this->auth->company_id)->update($update);
-
+        $userService = new UserService();
+        $params['pre_order_id'] = $id;
+        $preOrderRes = $userService->msgPreOrder($params);
+        if (!$preOrderRes['status']) {
+            Log::error('pre_order_id:'.$id.' error:'.$preOrderRes['msg']);
+        }
         $this->success('取消成功');
     }
 

+ 181 - 0
application/common/model/Order.php

@@ -0,0 +1,181 @@
+<?php
+
+namespace app\common\model;
+
+use think\Model;
+
+
+class Order extends Model
+{
+
+    
+
+    
+
+    // 表名
+    protected $name = 'order';
+    
+    // 自动写入时间戳字段
+    protected $autoWriteTimestamp = 'integer';
+
+    // 定义时间戳字段名
+    protected $createTime = 'createtime';
+    protected $updateTime = false;
+    protected $deleteTime = false;
+
+    // 追加属性
+    protected $append = [
+        /*'ordertype_text',
+        'server_time_text',
+        'package_endtime_text',
+        'status_text',
+        'pay_time_text',
+        'paytype_text',
+        'hexiao_time_text',
+        'cancel_time_text',
+        'finish_time_text'*/
+    ];
+    
+
+    
+    public function getOrdertypeList()
+    {
+        return ['1' => __('Ordertype 1'), '2' => __('Ordertype 2'), '3' => __('Ordertype 3')];
+    }
+
+    public function getStatusList()
+    {
+        return ['2' => '待处理', '3' => '已完成', '4' => '已取消'];
+    }
+
+    public function getPaytypeList()
+    {
+        return ['1' => __('Paytype 1'), '2' => __('Paytype 2'), '3' => __('Paytype 3')];
+    }
+
+
+    public function getOrdertypeTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['ordertype']) ? $data['ordertype'] : '');
+        $list = $this->getOrdertypeList();
+        return isset($list[$value]) ? $list[$value] : '';
+    }
+
+
+    public function getServerTimeTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['server_time']) ? $data['server_time'] : '');
+        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
+    }
+
+
+    public function getPackageEndtimeTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['package_endtime']) ? $data['package_endtime'] : '');
+        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
+    }
+
+
+    public function getStatusTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
+        $list = $this->getStatusList();
+        return isset($list[$value]) ? $list[$value] : '';
+    }
+
+
+    public function getPayTimeTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['pay_time']) ? $data['pay_time'] : '');
+        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
+    }
+
+
+    public function getPaytypeTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['paytype']) ? $data['paytype'] : '');
+        $list = $this->getPaytypeList();
+        return isset($list[$value]) ? $list[$value] : '';
+    }
+
+
+    public function getHexiaoTimeTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['hexiao_time']) ? $data['hexiao_time'] : '');
+        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
+    }
+
+
+    public function getCancelTimeTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['cancel_time']) ? $data['cancel_time'] : '');
+        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
+    }
+
+
+    public function getFinishTimeTextAttr($value, $data)
+    {
+        $value = $value ? $value : (isset($data['finish_time']) ? $data['finish_time'] : '');
+        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
+    }
+
+    protected function setServerTimeAttr($value)
+    {
+        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
+    }
+
+    protected function setPackageEndtimeAttr($value)
+    {
+        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
+    }
+
+    protected function setPayTimeAttr($value)
+    {
+        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
+    }
+
+    protected function setHexiaoTimeAttr($value)
+    {
+        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
+    }
+
+    protected function setCancelTimeAttr($value)
+    {
+        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
+    }
+
+    protected function setFinishTimeAttr($value)
+    {
+        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
+    }
+
+
+    public function company()
+    {
+        return $this->belongsTo('Company', 'company_id', 'id', [], 'LEFT')->setEagerlyType(0);
+    }
+
+
+    public function staff()
+    {
+        return $this->belongsTo('app\admin\model\company\Staff', 'staff_id', 'id', [], 'LEFT')->setEagerlyType(0);
+    }
+
+
+    public function user()
+    {
+        return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
+    }
+
+
+    public function preOrder()
+    {
+        return $this->belongsTo('app\admin\model\pre\Order', 'pre_order_id', 'id', [], 'LEFT')->setEagerlyType(0);
+    }
+
+
+    public function servicetype()
+    {
+        return $this->belongsTo('Servicetype', 'servicetype_id', 'id', [], 'LEFT')->setEagerlyType(0);
+    }
+}

+ 50 - 0
application/common/service/UserService.php

@@ -152,6 +152,56 @@ class UserService
     }
 
     /**
+     * 订单消息
+     * @return void
+     */
+    public function msgOrder($params=[])
+    {
+        $result = [
+            'status' => 1,
+            'msg' => '操作成功',
+            'data' => [],
+        ];
+        try {
+            $orderId = isset($params['order_id']) ? $params['order_id'] : 0;
+
+            $o = 'order';
+            $u = 'user';
+            $where[$o.'.id'] = $orderId;
+            $field = $o.'.*,'.$u.'.mini_openid';
+            $order = Db::name('order')->alias($o)->field($field)
+                ->join($u,$u.'.id = '.$o.'.user_id','LEFT')
+                ->where($where)->find();
+            if (empty($order)) {
+                throw new Exception('未找到订单信息');
+            }
+            $statusArr = model('Order')->getStatusList();
+            $statusText = isset($statusArr[$order['status']]) ? $statusArr[$order['status']] : '';
+            $wechatTemplate = config('param.wechat_template');
+            $orderMsg = isset($wechatTemplate['order']) ? $wechatTemplate['order'] : [];
+            /*工单号{{character_string1.DATA}}
+              处理进度 {{phrase4.DATA}}
+              提交时间 {{time2.DATA}}*/
+            $data = [//数据内容
+                "character_string1"  => ["value" => $order['orderno']],
+                "phrase4" => ["value" => $statusText],
+                "time2" => ["value" => date('Y年m月d日 H:i:s',$order['createtime'])],
+            ];
+            $paramsData = $orderMsg;
+            $paramsData['mini_openid'] = $orderMsg['mini_openid'];
+            $paramsData['data'] = $data;
+            $msgRes = $this->wechatMessageSend($paramsData);
+            if (!$msgRes['status']) {
+                throw new Exception($msgRes['msg']);
+            }
+        } catch (Exception $e) {
+            $result['status'] = 0;
+            $result['msg'] = $e->getMessage();
+        }
+        return $result;
+    }
+
+    /**
      * 微信消息发送
      * @return void
      */