whitefang пре 1 година
родитељ
комит
28bca839c4

+ 30 - 0
app/api/controller/ServiceOrderController.php

@@ -10,11 +10,19 @@ use app\api\validate\ServiceOrderValidate;
  */
 class ServiceOrderController extends BaseApiController
 {
+    /**
+     * 订单列表
+     * @return \think\response\Json
+     */
     public function lists()
     {
         return $this->dataLists(new ServiceOrderLists());
     }
 
+    /**
+     * 订单详情
+     * @return \think\response\Json
+     */
     public function detail()
     {
         $params = (new ServiceOrderValidate())->goCheck('detail',[
@@ -27,6 +35,10 @@ class ServiceOrderController extends BaseApiController
         return $this->data($result);
     }
 
+    /**
+     * 提交订单
+     * @return \think\response\Json
+     */
     public function submitOrder()
     {
         $params = (new ServiceOrderValidate())->post()->goCheck('add', [
@@ -40,4 +52,22 @@ class ServiceOrderController extends BaseApiController
         }
         return $this->data($result);
     }
+
+    /**
+     * 取消订单
+     * @return \think\response\Json
+     */
+    public function cancelOrder()
+    {
+        $params = (new ServiceOrderValidate())->post()->goCheck('cancel', [
+            'user_id' => $this->userId,
+            'terminal' => $this->userInfo['terminal'],
+            'user_info' => $this->userInfo
+        ]);
+        $result = ServiceOrderLogic::cancelOrder($params);
+        if (false === $result) {
+            return $this->fail(ServiceOrderLogic::getError());
+        }
+        return $this->success('取消成功', [], 1, 1);
+    }
 }

+ 41 - 2
app/api/logic/ServiceOrderLogic.php

@@ -36,7 +36,7 @@ class ServiceOrderLogic extends BaseLogic
             if($goods->isEmpty()){
                 throw new Exception('产品不存在!');
             }
-            if($params['user_info']['mobile']){
+            if(empty($params['user_info']['mobile'])){
                 throw new Exception('请先补充您的联系方式后在提交订单');
             }
 
@@ -156,7 +156,7 @@ class ServiceOrderLogic extends BaseLogic
             }
 
             //搜索当前工单下的所有订单记录
-            $order_info['pay_orders'] = \app\common\model\recharge\RechargeOrder::where(['work_id'=>$order_info['work_id']])->field('pay_status,payment_type,pay_way,pay_time,order_amount')->order('id asc')->select()->toArray();
+            $order_info['pay_orders'] = \app\common\model\recharge\RechargeOrder::where(['work_id'=>$order_info['work_id']])->field('id as order_id, pay_status,payment_type,pay_way,pay_time,order_amount')->order('id asc')->select()->toArray();
             $pay_status_data = DictData::where('type_value','pay_status')->column('name','value');
             $payment_type_data = DictData::where('type_value','payment_type')->column('name','value');
             $pay_way_data = DictData::where('type_value','pay_way')->column('name','value');
@@ -173,4 +173,43 @@ class ServiceOrderLogic extends BaseLogic
                 return false;
             }
     }
+
+
+    /**
+     * 取消订单
+     * @param $params
+     * @return false|void
+     */
+    public static function cancelOrder($params)
+    {
+        Db::startTrans();
+        try {
+            $work_id =  \app\common\model\recharge\RechargeOrder::where([
+                    'order_type' => 0,
+                    'user_id' => $params['user_id'],
+                    'sn'=>$params['sn']
+                ])->value('work_id');
+            if(empty($work_id)){
+                throw new Exception('订单不存在');
+            }
+
+            $payed_order = \app\common\model\recharge\RechargeOrder::where(['user_id'=>$params['user_id'],'work_id'=>$work_id,'pay_status'=>1])->findOrEmpty();
+            if(!$payed_order->isEmpty()){
+                throw new Exception('存在已支付订单,不允许取消订单,请联系客服');
+            }
+            //软删除订单
+            $cancel_order = \app\common\model\recharge\RechargeOrder::where(['user_id'=>$params['user_id'],'work_id'=>$work_id])->findOrEmpty();
+            $cancel_order->delete();
+            //更新工单状态为已取消
+            $service_work = ServiceWork::find($work_id);
+            $service_work->service_status = 4;
+            $service_work->save();
+
+            Db::commit();
+        }
+        catch (\Exception $e) {
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
 }

+ 5 - 0
app/api/validate/ServiceOrderValidate.php

@@ -42,4 +42,9 @@ class ServiceOrderValidate extends BaseValidate
         return $this->only(['sn']);
     }
 
+    public function sceneCancel()
+    {
+        return $this->only(['sn']);
+    }
+
 }