Przeglądaj źródła

add - 企业用户订单发布接口

liugc 1 rok temu
rodzic
commit
b7e10d89cd

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

@@ -293,4 +293,29 @@ class ServiceOrderController extends BaseApiController
 
 
 
+    public function firmOrderLists()
+    {
+        return $this->dataLists(new ServiceOrderLists());
+    }
+
+    public function firmOrderSave()
+    {
+        $params = (new ServiceOrderValidate())->post()->goCheck('firmOrderSave', [
+            'user_id' => $this->userId,
+            'terminal' => $this->userInfo['terminal'],
+            'user_info' => $this->userInfo
+        ]);
+        Log::write(json_encode($params,JSON_UNESCAPED_UNICODE));
+        if(count($params['order_goods']) == 0){
+            return $this->fail('请选择商品');
+        }else{
+            $params['goods_id'] = $params['order_goods'][0]['id'];
+        }
+        $result = ServiceOrderLogic::firmSubmitOrder($params);
+        if (false === $result) {
+            return $this->fail(ServiceOrderLogic::getError());
+        }
+        return $this->data($result);
+    }
+
 }

+ 105 - 0
app/api/logic/ServiceOrderLogic.php

@@ -979,4 +979,109 @@ class ServiceOrderLogic extends BaseLogic
         }
     }
 
+    /**
+     * 提交订单
+     * @param array $params
+     * @return array|false
+     */
+    public static function firmSubmitOrder($params)
+    {
+        Db::startTrans();
+        try {
+            $goods = Goods::findOrEmpty($params['goods_id']);
+            if($goods->isEmpty()){
+                throw new Exception('产品不存在!');
+            }
+            if(empty($params['user_info']['mobile'])){
+                throw new Exception('请先补充您的联系方式后在提交订单');
+            }
+
+            //根据服务工单计算当前订单应支付金额
+            if($goods['goods_payment_type'] == GoodsEnum::ISGOODS_PAYMENT_TYPE){
+                //一口价订单
+                $order_total = $goods['service_fee'];
+                $order_amount = $goods['service_fee'];
+            }else if ($goods['goods_payment_type'] == GoodsEnum::DEP_GOODS_PAYMENT_TYPE){
+                $order_total = $goods['service_fee'];
+                $order_amount = $goods['service_fee'];
+            }
+            else{
+                $order_total = $goods['base_service_fee'];
+                $order_amount = $goods['service_fee'];
+            }
+
+
+            //生成服务工单
+            $work_data = [
+                'work_sn' => generate_sn(ServiceWork::class, 'work_sn'),
+                'real_name' => $params['contact_people'],
+                'mobile' => $params['contact_number'],
+                'address' => $params['address'],
+                'title' => $goods->goods_name . '*' . $goods->goods_number.$goods->good_unit,
+                'category_type' => $goods['category_type'],
+                'goods_category_ids' => $goods['goods_category_ids'],
+                'goods_category_id' => $goods['goods_category_id'],
+                'base_service_fee' => $goods['base_service_fee'],
+                'service_fee' => $goods['service_fee'],
+                'work_pay_status'=>WorkEnum::UN_PAY_STATUS,
+                'work_type'=> 1,
+                'appointment_time' => strtotime($params['appointment_time']),
+                'user_id'=>$params['user_id'],
+                'lon'=>!empty($params['lon'])?$params['lon']:0,
+                'lat'=>!empty($params['lat'])?$params['lat']:0,
+            ];
+            $service_work = ServiceWork::create($work_data);
+            //生成服务订单
+            $data = [
+                'work_id'=> $service_work['id'],
+                'sn' => generate_sn(RechargeOrder::class, 'sn'),
+                'order_type'=>0,//服务订单
+                'order_terminal' => $params['terminal'],
+                'payment_type'=>$goods['goods_payment_type']==GoodsEnum::ISGOODS_PAYMENT_TYPE?0:1,
+                'user_id' => $params['user_id'],
+                'pay_status' => PayEnum::UNPAID,
+                'coupon_id'=>!empty($params['coupon_id'])?$params['coupon_id']:0,
+                'coupon_price'=>!empty($order_coupon_amount)?$order_coupon_amount:0,
+                'pay_way' => $params['pay_way'],
+                'order_total' => $order_total,
+                'order_amount' => $order_amount,
+            ];
+            $order = RechargeOrder::create($data);
+            //生成订单服务详情
+            OrderGoods::create([
+                'sn' => $order['sn'],
+                'goods_id' => $params['goods_id'],
+                'category_type' => $goods['category_type'],
+                'goods_category_ids' => $goods['goods_category_ids'],
+                'goods_category_id' => $goods['goods_category_id'],
+                'goods_name' => $goods['goods_name'],
+                'goods_image' => $goods['goods_image'],
+                'goods_video' => $goods['goods_video'],
+                'goods_number' => $goods['goods_number'],
+                'good_unit' => $goods['good_unit'],
+                'goods_size' => $goods['goods_size'],
+                'goods_type' => $goods['goods_type'],
+                'goods_brand' => $goods['goods_brand'],
+                'install_guide' => $goods['install_guide'],
+                'goods_payment_type'=>$goods['goods_payment_type'],
+                'base_service_fee' => $goods['base_service_fee'],
+                'service_total' => $goods['service_total'],
+                'service_fee' => $goods['service_fee'],
+                'service_image' => $goods['service_image'],
+                'warranty_period'=>$goods['warranty_period'],
+                'fee_schedule' => $goods['fee_schedule'],
+                'goods_status' => $goods['goods_status'],
+            ]);
+            Db::commit();
+        } catch (\Exception $e) {
+            self::setError($e->getMessage());
+            return false;
+        }
+
+        return [
+            'order_id' => (int)$order['id'],
+            'work_id' => (int)$order['work_id'],
+        ];
+    }
+
 }