|
|
@@ -415,67 +415,67 @@ class ServiceOrderLogic extends BaseLogic
|
|
|
{
|
|
|
Db::startTrans();
|
|
|
try {
|
|
|
- $goods = Goods::findOrEmpty($params['goods_id']);
|
|
|
- if($goods->isEmpty()){
|
|
|
+ $goodIds = array_column($params['order_goods'],'id');
|
|
|
+ $goodInfo = Goods::whereIn('id',$goodIds)->select();
|
|
|
+ $ids = $goodInfo->column('id');
|
|
|
+ if(!empty(array_diff($goodIds,$ids))){
|
|
|
throw new Exception('产品不存在!');
|
|
|
}
|
|
|
if(empty($params['user_info']['mobile'])){
|
|
|
throw new Exception('请先补充您的联系方式后在提交订单');
|
|
|
}
|
|
|
-
|
|
|
- //根据服务工单计算当前订单应支付金额
|
|
|
- $order_total = $goods['service_total'];
|
|
|
- if($goods['goods_payment_type'] == GoodsEnum::ISGOODS_PAYMENT_TYPE){
|
|
|
- //一口价订单
|
|
|
- $order_amount = $goods['service_fee'];
|
|
|
- }else{
|
|
|
- $order_total = $goods['base_service_fee'];
|
|
|
- $order_amount = $goods['service_fee'];
|
|
|
- }
|
|
|
-
|
|
|
- //优惠券验证
|
|
|
- if(!empty($params['coupon_id'])){
|
|
|
- $user_coupon = UserCoupon::where(['id'=>$params['coupon_id'],'user_id'=>$params['user_id'],'voucher_status'=>0])
|
|
|
- ->where('voucher_count','>',0)
|
|
|
- ->where('expire_time','>=',time())
|
|
|
- ->where('begin_use','<',time())
|
|
|
- ->findOrEmpty();
|
|
|
- if($user_coupon->isEmpty()){
|
|
|
- throw new Exception('该优惠券无法使用');
|
|
|
- }
|
|
|
- if($goods['goods_payment_type'] == GoodsEnum::ISGOODS_PAYMENT_TYPE and $order_amount<$user_coupon['amount_require']){
|
|
|
- throw new Exception('该优惠劵不满足满减使用条件');
|
|
|
- }
|
|
|
- if($goods['goods_payment_type'] != GoodsEnum::ISGOODS_PAYMENT_TYPE){
|
|
|
- throw new Exception('请在支付尾款的时候使用该优惠券');
|
|
|
- }
|
|
|
- //优惠券折扣
|
|
|
- if($user_coupon['mold_type'] == 1){
|
|
|
- //按比例折扣
|
|
|
- if($user_coupon['discount_ratio']>=1){
|
|
|
- throw new Exception('优惠券有误,请联系客服');
|
|
|
- }
|
|
|
- $order_coupon_amount = intval($order_amount*(1-$user_coupon['discount_ratio']));
|
|
|
- }else{
|
|
|
- $order_coupon_amount = $user_coupon['amount'];
|
|
|
- }
|
|
|
- if(!empty($user_coupon['max_deductible_price'])){
|
|
|
- $order_amount = ($order_coupon_amount>$user_coupon['max_deductible_price'])?($order_amount-$user_coupon['max_deductible_price']):($order_amount-$order_coupon_amount);
|
|
|
+ $order_amount = 0;
|
|
|
+ $order_total = 0;
|
|
|
+
|
|
|
+ $orderGoodsData = [];
|
|
|
+ $goodsPaymentTypeArr = [];
|
|
|
+ //计算订单总金额和结算金额
|
|
|
+ foreach($params['order_goods'] as $val){
|
|
|
+ $goods = $goodInfo->where('id',$val['id'])->toArray()[0];
|
|
|
+ //根据服务工单计算当前订单应支付金额
|
|
|
+ $order_total = $goods['service_total'];
|
|
|
+ if($goods['goods_payment_type'] == GoodsEnum::ISGOODS_PAYMENT_TYPE){
|
|
|
+ //一口价订单
|
|
|
+ $order_amount = $goods['service_fee']*$val['goods_number'];
|
|
|
}else{
|
|
|
- $order_amount = $order_amount-$order_coupon_amount;
|
|
|
+ $order_total = $goods['base_service_fee']*$val['goods_number'];
|
|
|
+ $order_amount = $goods['service_fee']*$val['goods_number'];
|
|
|
}
|
|
|
- $user_coupon->voucher_status = 1;
|
|
|
- $user_coupon->voucher_count = $user_coupon->voucher_count-1;
|
|
|
- $user_coupon->save();
|
|
|
+ $goodsPaymentTypeArr[] = $goods['goods_payment_type'];
|
|
|
+ $orderGoodsData[] = [
|
|
|
+ 'goods_id' => $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' => $val['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'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ if(count(array_unique($goodsPaymentTypeArr))>1){
|
|
|
+ throw new Exception('订单中存在多种支付方式');
|
|
|
}
|
|
|
-
|
|
|
//生成服务工单
|
|
|
$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,
|
|
|
+ 'title' => $goods['goods_name'] . '*' .$val['goods_number'].$goods['good_unit'],
|
|
|
'category_type' => $goods['category_type'],
|
|
|
'goods_category_ids' => $goods['goods_category_ids'],
|
|
|
'goods_category_id' => $goods['goods_category_id'],
|
|
|
@@ -483,7 +483,8 @@ class ServiceOrderLogic extends BaseLogic
|
|
|
'service_fee' => $goods['service_fee'],
|
|
|
'work_pay_status'=>WorkEnum::UN_PAY_STATUS,
|
|
|
'appointment_time' => strtotime($params['appointment_time']),
|
|
|
- 'user_id'=>$params['user_id']
|
|
|
+ 'user_id' => $params['user_id'],
|
|
|
+ 'work_type' => 1,
|
|
|
];
|
|
|
$service_work = ServiceWork::create($work_data);
|
|
|
|
|
|
@@ -504,31 +505,12 @@ class ServiceOrderLogic extends BaseLogic
|
|
|
];
|
|
|
|
|
|
$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'],
|
|
|
- ]);
|
|
|
+ array_walk($orderGoodsData, function (&$value, $key, $data) {
|
|
|
+ $value = array_merge($value, ['sn' => $data['sn']]);
|
|
|
+ },$data);
|
|
|
+ dd($orderGoodsData);
|
|
|
+ $orderGoodsModel = new OrderGoods();
|
|
|
+ $orderGoodsModel->saveAll($orderGoodsData);
|
|
|
Db::commit();
|
|
|
return [
|
|
|
'order_id' => (int)$order['id'],
|