Explorar o código

重置订单优惠券

whitefang hai 1 ano
pai
achega
713e94452c

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

@@ -154,6 +154,23 @@ class ServiceOrderController extends BaseApiController
         return $this->data($result);
         return $this->data($result);
     }
     }
 
 
+    /**
+     * 重置订单优惠券
+     * @return \think\response\Json
+     */
+    public function cancelOrderCoupon()
+    {
+        $params = (new ServiceOrderValidate())->post()->goCheck('cancelOrderCoupon', [
+            'user_id' => $this->userId,
+            'user_info' => $this->userInfo
+        ]);
+        $result = ServiceOrderLogic::cancelOrderCoupon($params);
+        if (false === $result) {
+            return $this->fail(ServiceOrderLogic::getError());
+        }
+        return $this->success('保存成功', [], 1, 1);
+    }
+
     public function firmOrderLists()
     public function firmOrderLists()
     {
     {
         return $this->dataLists(new ServiceOrderLists());
         return $this->dataLists(new ServiceOrderLists());

+ 28 - 8
app/api/logic/ServiceOrderLogic.php

@@ -265,13 +265,33 @@ class ServiceOrderLogic extends BaseLogic
     }
     }
 
 
     /**
     /**
-     * 取消订单优惠券
-     * @return void
-     */
-//    public function canleOrderCoupon()
-//    {
-//
-//    }
+     * 重置订单优惠券
+     * * @param $params
+     * * * @return array|false
+ */
+    public static function cancelOrderCoupon($params)
+    {
+        Db::startTrans();
+        try {
+            $order = \app\common\model\recharge\RechargeOrder::where('id',$params['order_id'])->findOrEmpty();
+            if(!empty($order['coupon_id'])){
+                $user_coupon_ed = UserCoupon::findOrEmpty($order['coupon_id']);
+                $user_coupon_ed->voucher_count = $user_coupon_ed->voucher_count+1;
+                $user_coupon_ed->voucher_status = 0;
+                $user_coupon_ed->save();
+
+                $order->order_amount = $order->order_amount+$order->coupon_price;
+                $order->coupon_id = 0;
+                $order->coupon_price = 0;
+                $order->save();
+            }
+            Db::commit();
+        } catch (\Exception $e) {
+            self::setError($e->getMessage());
+            return false;
+        }
+
+    }
 
 
     /**
     /**
      * 获取订单工程师信息
      * 获取订单工程师信息
@@ -452,7 +472,7 @@ class ServiceOrderLogic extends BaseLogic
                 $v['pay_way_name'] = $pay_way_data[$v['pay_way']];
                 $v['pay_way_name'] = $pay_way_data[$v['pay_way']];
 
 
                 if($v['payment_type']!=1 and !empty($order_info['service_work']['spare_total'])){
                 if($v['payment_type']!=1 and !empty($order_info['service_work']['spare_total'])){
-                    $v['order_total'] = $v['order_total'] - $order_info['service_work']['spare_total'] + $v['coupon_price'];
+                    $v['order_total'] = $v['order_total'] - $order_info['service_work']['spare_total'];
                     $v['order_amount'] = $v['order_amount'] - $order_info['service_work']['spare_total'] + $v['coupon_price'];
                     $v['order_amount'] = $v['order_amount'] - $order_info['service_work']['spare_total'] + $v['coupon_price'];
                 }
                 }
 
 

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

@@ -14,6 +14,7 @@ class ServiceOrderValidate extends BaseValidate
 {
 {
 
 
     protected $rule = [
     protected $rule = [
+        'order_id'=>'require',
         'sn'=>'require',
         'sn'=>'require',
         'address' => 'require',
         'address' => 'require',
         'appointment_time' => 'require|dateFormat:Y-m-d H:i:s',
         'appointment_time' => 'require|dateFormat:Y-m-d H:i:s',
@@ -25,6 +26,7 @@ class ServiceOrderValidate extends BaseValidate
 
 
 
 
     protected $message = [
     protected $message = [
+        'order_id.require' => '订单ID错误',
         'sn.require' => '订单编号错误',
         'sn.require' => '订单编号错误',
         'address.require' => '请填写地址',
         'address.require' => '请填写地址',
         'appointment_time.require' => '请填写预约上门时间',
         'appointment_time.require' => '请填写预约上门时间',
@@ -87,4 +89,9 @@ class ServiceOrderValidate extends BaseValidate
     {
     {
         return $this->only(['address','appointment_time','pay_way','contact_number','contact_people']);
         return $this->only(['address','appointment_time','pay_way','contact_number','contact_people']);
     }
     }
+
+    public function sceneCancelOrderCoupon()
+    {
+        return $this->only(['order_id']);
+    }
 }
 }