|
|
@@ -8,13 +8,9 @@ use app\common\enum\WorkEnum;
|
|
|
use app\common\logic\BaseLogic;
|
|
|
use app\common\model\coupon\UserCoupon;
|
|
|
use app\common\model\dict\DictData;
|
|
|
-use app\common\model\effective\EffectiveCategory;
|
|
|
-use app\common\model\effective\EffectiveRules;
|
|
|
use app\common\model\goods\Goods;
|
|
|
use app\common\model\master_worker\MasterWorker;
|
|
|
-use app\common\model\orders\OrderEffectiveLog;
|
|
|
use app\common\model\orders\RechargeOrder;
|
|
|
-use app\common\model\performance\PerformanceRules;
|
|
|
use app\common\model\recharge\OrderGoods;
|
|
|
use app\common\model\works\ServiceWork;
|
|
|
use app\workerapi\logic\ServiceWorkLogLogic;
|
|
|
@@ -414,4 +410,133 @@ class ServiceOrderLogic extends BaseLogic
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public static function firmOrderSave($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('请先补充您的联系方式后在提交订单');
|
|
|
+ }
|
|
|
+
|
|
|
+ //根据服务工单计算当前订单应支付金额
|
|
|
+ $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);
|
|
|
+ }else{
|
|
|
+ $order_amount = $order_amount-$order_coupon_amount;
|
|
|
+ }
|
|
|
+ $user_coupon->voucher_status = 1;
|
|
|
+ $user_coupon->voucher_count = $user_coupon->voucher_count-1;
|
|
|
+ $user_coupon->save();
|
|
|
+ }
|
|
|
+
|
|
|
+ //生成服务工单
|
|
|
+ $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,
|
|
|
+ 'appointment_time' => strtotime($params['appointment_time']),
|
|
|
+ 'user_id'=>$params['user_id']
|
|
|
+ ];
|
|
|
+ $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']==1?1:0,
|
|
|
+ '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();
|
|
|
+ return [
|
|
|
+ 'order_id' => (int)$order['id'],
|
|
|
+ ];
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Db::rollback();
|
|
|
+ self::setError($e->getMessage());
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|