|
|
@@ -6,6 +6,7 @@ use app\common\enum\GoodsEnum;
|
|
|
use app\common\enum\PayEnum;
|
|
|
use app\common\enum\WorkEnum;
|
|
|
use app\common\logic\BaseLogic;
|
|
|
+use app\common\logic\PaymentLogic;
|
|
|
use app\common\model\coupon\UserCoupon;
|
|
|
use app\common\model\dict\DictData;
|
|
|
use app\common\model\goods\Goods;
|
|
|
@@ -172,6 +173,87 @@ class ServiceOrderLogic extends BaseLogic
|
|
|
];
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 提交尾款订单
|
|
|
+ * @param array $params
|
|
|
+ * @return array|false
|
|
|
+ */
|
|
|
+ public static function submitFinalOrder($params)
|
|
|
+ {
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ $order = \app\common\model\recharge\RechargeOrder::where('sn',$params['sn'])->findOrEmpty();
|
|
|
+ if ($order->isEmpty()) {
|
|
|
+ throw new Exception('订单不存在');
|
|
|
+ }
|
|
|
+ //判断订单类型.服务订单尾款处理
|
|
|
+ if($order['order_type'] == 0 and $order['pay_status'] == PayEnum::ISPAID)//服务工单
|
|
|
+ {
|
|
|
+ $order = RechargeOrder::where(['work_id'=>$order['work_id'],'pay_status'=>0])->findOrEmpty();
|
|
|
+ if($order->isEmpty()){
|
|
|
+ throw new Exception('订单已支付');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($order['pay_status'] == PayEnum::ISPAID) {
|
|
|
+ throw new Exception('订单已支付');
|
|
|
+ }
|
|
|
+
|
|
|
+ $order_goods = OrderGoods::where('sn',$params['sn'])->findOrEmpty();
|
|
|
+ $goods = Goods::findOrEmpty($order_goods['goods_id']);
|
|
|
+ //判断是否存在优惠券
|
|
|
+ //优惠券验证
|
|
|
+ if(!empty($order['coupon_id'])){
|
|
|
+ $order->coupon_id = 0;
|
|
|
+ $order->coupon_price = 0;
|
|
|
+ $order->order_amount = $order->order_total;
|
|
|
+ $order->save();
|
|
|
+ $order = \app\common\model\recharge\RechargeOrder::where('sn',$order['sn'])->findOrEmpty();
|
|
|
+ }
|
|
|
+ if(!empty($params['coupon_id']) && empty($order['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['order_amount']<$user_coupon['amount_require']){
|
|
|
+ throw new Exception('该优惠劵不满足满减使用条件');
|
|
|
+ }
|
|
|
+ //优惠券折扣
|
|
|
+ if($user_coupon['mold_type'] == 1){
|
|
|
+ //按比例折扣
|
|
|
+ if($user_coupon['discount_ratio']>=1){
|
|
|
+ throw new Exception('优惠券有误,请联系客服');
|
|
|
+ }
|
|
|
+ $order_coupon_amount = intval($order['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['order_amount']-$user_coupon['max_deductible_price']):($order['order_amount']-$order_coupon_amount);
|
|
|
+ }else{
|
|
|
+ $order_amount = $order['order_amount']-$order_coupon_amount;
|
|
|
+ }
|
|
|
+ $user_coupon->voucher_status = 1;
|
|
|
+ $user_coupon->voucher_count = $user_coupon->voucher_count-1;
|
|
|
+ $user_coupon->save();
|
|
|
+ }
|
|
|
+
|
|
|
+ $order->coupon_id = !empty($params['coupon_id'])?$params['coupon_id']:0;
|
|
|
+ $order->coupon_price = !empty($order_coupon_amount)?$order_coupon_amount:0;
|
|
|
+ $order->order_amount = !empty($order_amount)?$order_amount:$order->order_amount;
|
|
|
+ $order->save();
|
|
|
+ Db::commit();
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ self::setError($e->getMessage());
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取订单工程师信息
|
|
|
* * @param $params
|