| | |
| | | use app\common\enum\order\OrderSourceEnum; |
| | | use app\common\enum\order\OrderTypeEnum; |
| | | use app\common\model\settings\Setting as SettingModel; |
| | | use app\api\service\points\ConsumptionDeductService; |
| | | use app\api\service\consumption\ConsumptionDeductService; |
| | | use app\api\model\store\Store as StoreModel; |
| | | use app\api\service\user\UserService; |
| | | use app\common\enum\settings\DeliveryTypeEnum; |
| | |
| | | use app\common\service\BaseService; |
| | | use app\common\service\product\factory\ProductFactory; |
| | | use app\api\service\fullreduce\FullDeductService; |
| | | use app\common\model\plus\table\Record as RecordModel; //by lyzflash |
| | | use app\common\model\plus\table\Record as RecordModel; |
| | | |
| | | //by lyzflash |
| | | use app\common\model\order\OrderTrade as OrderTradeModel; |
| | | use app\common\model\branch\ActivityOrder as BranchActivityOrderModel; |
| | | use app\common\model\user\PointsLog as PointsLogModel; |
| | | use app\api\service\points\PointsDeductService; |
| | | |
| | | /** |
| | | * 订单结算服务基类 |
| | |
| | | $totalPoints = 0; |
| | | $totalProductReduce = 0; |
| | | $totalServicePrice = 0; |
| | | $totalConsumptionMoney = 0; |
| | | $totalConsumption = 0; |
| | | $this->commonOrderData = $this->getCommonOrderData(); |
| | | // 供应商 |
| | | foreach ($this->supplierData as &$supplier) { |
| | | // 整理订单数据 |
| | | $this->orderData = $this->getOrderData($supplier['shop_supplier_id'],$supplier['productList']); |
| | | $this->orderData = $this->getOrderData($supplier['shop_supplier_id'], $supplier['productList']); |
| | | // 订单商品总数量 |
| | | $orderTotalNum += helper::getArrayColumnSum($supplier['productList'], 'total_num'); |
| | | // 设置订单商品总服务费用 |
| | |
| | | $orderTotalPrice += $this->orderData['order_total_price']; |
| | | // 计算积分商城抵扣 |
| | | $this->setOrderPoints($supplier['productList'], $this->settledRule['force_points']); |
| | | // 计算积分商城抵扣 |
| | | $this->setOrderConsumption($supplier['productList']); |
| | | // 计算订单商品的实际付款金额 |
| | | $this->setOrderProductPayPrice($supplier['productList']); |
| | | |
| | | // 设置默认配送方式 |
| | | if(!isset($this->params['supplier'])){ |
| | | $deliveryType=SettingModel::getItem('store')['delivery_type']; |
| | | $delivery=$this->params['delivery']; |
| | | if(in_array($delivery,$deliveryType)){ |
| | | $delivery=$delivery; |
| | | }else if(in_array("10",$deliveryType)){ |
| | | $delivery=10; |
| | | }else if(in_array("40",$deliveryType)){ |
| | | $delivery=40; |
| | | }else{ |
| | | $delivery = $deliveryType[0]; |
| | | } |
| | | |
| | | if (!isset($this->params['supplier'])) { |
| | | $deliveryType = SettingModel::getItem('store')['delivery_type']; |
| | | $delivery = $this->params['delivery']; |
| | | if (in_array($delivery, $deliveryType)) { |
| | | $delivery = $delivery; |
| | | } else if (in_array("10", $deliveryType)) { |
| | | $delivery = 10; |
| | | } else if (in_array("40", $deliveryType)) { |
| | | $delivery = 40; |
| | | } else { |
| | | $delivery = $deliveryType[0]; |
| | | } |
| | | |
| | | $this->orderData['delivery'] = $supplier['productList'][0]['is_virtual'] == 1 || $supplier['productList'][0]['is_virtual'] == 2 || $supplier['productList'][0]['is_virtual'] == 3 ? 30 : $delivery; |
| | | }else{ |
| | | if($supplier['productList'][0]['is_virtual'] == 1 || $supplier['productList'][0]['is_virtual'] == 2 || $supplier['productList'][0]['is_virtual'] == 3){ |
| | | } else { |
| | | if ($supplier['productList'][0]['is_virtual'] == 1 || $supplier['productList'][0]['is_virtual'] == 2 || $supplier['productList'][0]['is_virtual'] == 3) { |
| | | $this->orderData['delivery'] = 30; |
| | | }else { |
| | | } else { |
| | | $this->orderData['delivery'] = $this->params['supplier'][$supplier['shop_supplier_id']]['delivery']; |
| | | } |
| | | $this->orderData['store_id'] = $this->params['supplier'][$supplier['shop_supplier_id']]['store_id']; |
| | | } |
| | | |
| | | |
| | | // 处理配送方式 |
| | | if ($this->orderData['delivery'] == DeliveryTypeEnum::EXPRESS) { |
| | | $this->setOrderExpress($supplier['productList']); |
| | |
| | | } elseif ($this->orderData['delivery'] == DeliveryTypeEnum::EXTRACT) { |
| | | $this->orderData['store_id'] > 0 && $this->orderData['extract_store'] = StoreModel::detail($this->params['supplier'][$supplier['shop_supplier_id']]['store_id']); |
| | | } elseif ($this->orderData['delivery'] == DeliveryTypeEnum::STORESS) { |
| | | $this->orderData['extract_store_id'] = isset($this->params['delivery_store']) ? $this->params['delivery_store'] : $this->orderData['store_id']; |
| | | } |
| | | $this->orderData['extract_store_id'] = isset($this->params['delivery_store']) ? $this->params['delivery_store'] : $this->orderData['store_id']; |
| | | } |
| | | |
| | | // 计算订单最终金额 |
| | | $this->setOrderPayPrice($supplier['productList']); |
| | |
| | | $this->setOrderPoints($supplier['productList'], $this->settledRule['force_points']); |
| | | $totalPointsMoney += $this->orderData['points_money']; |
| | | $totalPoints += $this->orderData['points_num']; |
| | | // 计算可用消费券抵扣 |
| | | $this->setOrderConsumption($supplier['productList']); |
| | | $totalConsumptionMoney += $this->orderData['consumption_money']; |
| | | $totalConsumption += $this->orderData['consumption_num']; |
| | | // 商品总价 - 积分抵扣 |
| | | foreach ($supplier['productList'] as &$product) { |
| | | $value = $product['total_pay_price']; |
| | | // 减去积分抵扣金额 |
| | | if ($this->orderData['is_allow_points'] && $this->commonOrderData['is_use_points'] && !$this->settledRule['force_points']) { |
| | | $value = helper::bcsub($product['total_pay_price'], $product['points_money']); |
| | | }// 减去消费券抵扣金额 |
| | | if ($this->orderData['is_allow_consumption'] && $this->commonOrderData['is_use_consumption'] && !$this->settledRule['force_points']) { |
| | | $value = helper::bcsub($value, $product['consumption_money']); |
| | | } |
| | | $product['total_pay_price'] = helper::number2($value); |
| | | } |
| | |
| | | $this->commonOrderData['is_use_points'] && $orderPayPrice = $orderPayPrice - $totalPointsMoney; |
| | | // 计算订单积分赠送数量 |
| | | $this->setOrderPointsBonus(); |
| | | // 计算订单消费券赠送数量 |
| | | $this->setOrderConsumptionBonus(); |
| | | |
| | | //订单数据 |
| | | $this->commonOrderData = array_merge([ |
| | |
| | | 'order_pay_price' => helper::number2($orderPayPrice), // 商品总价,最终支付 |
| | | 'total_service_price' => helper::number2($totalServicePrice), // 商品总服务费 |
| | | 'coupon_list' => [], |
| | | 'coupon_id_sys' =>'', |
| | | 'coupon_id_sys' => '', |
| | | 'coupon_money_sys' => 0, |
| | | 'points_money' => $totalPointsMoney, |
| | | 'points_num' => $totalPoints, |
| | | 'is_real_use_points' => $this->params['is_use_points'], |
| | | 'is_real_use_consumption' => $this->params['is_use_consumption'], |
| | | 'product_reduce_money' => $totalProductReduce, |
| | | 'consumption_money' => $totalConsumptionMoney, |
| | | 'consumption_num' => $totalConsumption, |
| | | 'verify_data' => $verify_data, |
| | | 'booking_data' => $booking_data, |
| | | 'last_extract' => UserService::getLastExtract($this->user['user_id']), |
| | | // 房间id |
| | | 'room_id' => isset($this->params['room_id']) && $this->params['room_id'] > 0 ? $this->params['room_id'] : 0, |
| | | // 计次卡 |
| | | 'counting_id' => 0, |
| | | 'counting_id' => 0, |
| | | 'user_counting_data' => [], |
| | | 'activity_id' => $this->params['activity_id'], //活动id |
| | | ], $this->commonOrderData, $this->settledRule); |
| | |
| | | return false; |
| | | } |
| | | // 判断是否超过限购数量 |
| | | if($product['limit_num'] > 0){ |
| | | if ($product['limit_num'] > 0) { |
| | | $hasNum = OrderModel::getHasBuyOrderNum($this->user['user_id'], $product['product_id']); |
| | | if($hasNum + $product['total_num'] > $product['limit_num']){ |
| | | if ($hasNum + $product['total_num'] > $product['limit_num']) { |
| | | $this->error = "很抱歉,购买超过此商品最大限购数量"; |
| | | return false; |
| | | } |
| | |
| | | if ($this->orderData['is_allow_points'] && $this->commonOrderData['is_use_points'] && !$this->settledRule['force_points']) { |
| | | $value = helper::bcsub($value, $product['points_money']); |
| | | } |
| | | // 减去消费券抵扣金额 |
| | | if ($this->orderData['is_allow_consumption'] && $this->commonOrderData['is_use_consumption'] && !$this->settledRule['force_points']) { |
| | | $value = helper::bcsub($value, $product['consumption_money']); |
| | | } |
| | | $product['total_pay_price'] = helper::number2($value); |
| | | } |
| | | |
| | |
| | | /** |
| | | * 整理订单数据(结算台初始化) |
| | | */ |
| | | private function getOrderData($shop_supplier_id,$productList=[]) |
| | | private function getOrderData($shop_supplier_id, $productList = []) |
| | | { |
| | | // 系统支持的配送方式 (后台设置) |
| | | $deliveryType = SettingModel::getItem('store')['delivery_type']; |
| | | |
| | | $deliveryType = SettingModel::getItem('store')['delivery_type']; |
| | | |
| | | // 积分设置 |
| | | $pointsSetting = SettingModel::getItem('points'); |
| | | |
| | | if(isset($this->params['supplier'])){ |
| | | if (isset($this->params['supplier'])) { |
| | | $delivery = $this->params['supplier'][$shop_supplier_id]['delivery']; |
| | | }else{ |
| | | if(in_array("10",$deliveryType)){ |
| | | $delivery=10; |
| | | }else if(in_array("40",$deliveryType)){ |
| | | $delivery=40; |
| | | }else{ |
| | | $delivery = $deliveryType[0]; |
| | | } |
| | | } |
| | | } else { |
| | | if (in_array("10", $deliveryType)) { |
| | | $delivery = 10; |
| | | } else if (in_array("40", $deliveryType)) { |
| | | $delivery = 40; |
| | | } else { |
| | | $delivery = $deliveryType[0]; |
| | | } |
| | | } |
| | | |
| | | if(!empty($productList) && ($productList[0]['is_virtual'] == 1 || $productList[0]['is_virtual'] == 3)){ |
| | | if (!empty($productList) && ($productList[0]['is_virtual'] == 1 || $productList[0]['is_virtual'] == 3)) { |
| | | //虚拟商品核销 by yj |
| | | $verify_data = [ |
| | | 'is_verify' => $productList[0]['is_verify'] && empty($productList[0]['virtual_auto']) ? 1 : 0, //必须是手动发货并且支持核销 |
| | |
| | | $verify_data['verify_start_time'] = date('Y-m-d', $productList[0]['verify_start_time']); |
| | | $verify_data['verify_end_time'] = date('Y-m-d', $productList[0]['verify_end_time']); |
| | | } |
| | | }else{ |
| | | } else { |
| | | $verify_data = []; |
| | | } |
| | | |
| | | //通过收货地址获取最近的门店 |
| | | if(!empty($this->user['address_default'])){ |
| | | if (!empty($this->user['address_default'])) { |
| | | $address = $this->user['address_default']; |
| | | $store_list = (new storeModel())->getList(false,$address["longitude"],$address["latitude"],false,$shop_supplier_id); |
| | | if(!empty($store_list)){ |
| | | $store_list = (new storeModel())->getList(false, $address["longitude"], $address["latitude"], false, $shop_supplier_id); |
| | | if (!empty($store_list)) { |
| | | $sell_store_id = $store_list[0]["store_id"]; |
| | | } |
| | | } |
| | |
| | | //优惠券id |
| | | 'coupon_id' => 0, |
| | | //优惠金额 |
| | | 'coupon_money'=>0, |
| | | 'coupon_money' => 0, |
| | | //总服务费用金额 |
| | | 'total_service_price'=>0, |
| | | 'total_service_price' => 0, |
| | | // 通过收货地址获取最近的门店出货 |
| | | 'sell_store_id' => empty($sell_store_id) ? 0 : $sell_store_id, |
| | | ]; |
| | |
| | | /*if( $this->user['user_id'] == 8743){ |
| | | print_r("a".$cityId);exit; |
| | | }*/ |
| | | /* if(empty($cityId)){ |
| | | $this->error = "请先完善您的收货地址再提交订单"; |
| | | return false; |
| | | }*/ |
| | | /* if(empty($cityId)){ |
| | | $this->error = "请先完善您的收货地址再提交订单"; |
| | | return false; |
| | | }*/ |
| | | |
| | | // 初始化配送服务类 |
| | | $ExpressService = new ExpressService( |
| | |
| | | //如果是积分兑换,判断用户积分是否足够 |
| | | if ($this->settledRule['force_points']) { |
| | | //因为积分会过期问题 所以现在读取现在有的积分 |
| | | $points = ( new PointsLogModel())->getUserPoints($this->user['user_id']); |
| | | $points = (new PointsLogModel())->getUserPoints($this->user['user_id']); |
| | | if ($points < $order['orderData']['points_num']) { |
| | | $this->error = '用户积分不足,无法使用积分兑换'; |
| | | return false; |
| | |
| | | $this->saveOrderAddress($commomOrder['address'], $status); |
| | | } elseif ($supplier['orderData']['delivery'] == DeliveryTypeEnum::EXTRACT) { |
| | | // 记录自提信息 |
| | | if(!empty($this->params['linkman']) && !empty($this->params['phone'])){ |
| | | if (!empty($this->params['linkman']) && !empty($this->params['phone'])) { |
| | | $this->saveOrderExtract($this->params['linkman'], $this->params['phone']); |
| | | }else{ |
| | | } else { |
| | | $this->saveOrderExtract($commomOrder['address']['name'], $commomOrder['address']['phone']); |
| | | } |
| | | } |
| | |
| | | $this->saveOrderProduct($supplier, $status, $commomOrder); |
| | | |
| | | // 更新商品库存 (针对下单减库存的商品) |
| | | if(!empty($commomOrder["extract_store_id"])){ |
| | | if (!empty($commomOrder["extract_store_id"])) { |
| | | //自提门店 |
| | | $sell_store_id = $commomOrder["extract_store_id"]; |
| | | }elseif(!empty($commomOrder["sell_store_id"])){ |
| | | } elseif (!empty($commomOrder["sell_store_id"])) { |
| | | //没有自提门店,判断出货门店 |
| | | $sell_store_id = $supplier['orderData']["sell_store_id"]; |
| | | }else{ |
| | | } else { |
| | | $sell_store_id = 0; |
| | | } |
| | | // 减库存 |
| | |
| | | // 积分兑换扣除用户积分 |
| | | if ($commomOrder['force_points']) { |
| | | $describe = "用户积分兑换消费:{$this->model['order_no']}"; |
| | | $this->user->setIncPoints(-$commomOrder['points_num'], $describe,0,true,$status); |
| | | $this->user->setIncPoints(-$commomOrder['points_num'], $describe, 0, true, $status); |
| | | } else { |
| | | // 积分抵扣情况下扣除用户积分 |
| | | if ($commomOrder['is_allow_points'] && $commomOrder['is_real_use_points'] && $commomOrder['points_num'] > 0) { |
| | | $describe = "用户消费:{$this->model['order_no']}"; |
| | | $this->user->setIncPoints(-$commomOrder['points_num'], $describe,0,true,$status); |
| | | $this->user->setIncPoints(-$commomOrder['points_num'], $describe, 0, true, $status); |
| | | } |
| | | if ($commomOrder['is_allow_consumption'] && $commomOrder['is_real_use_consumption'] && $commomOrder['consumption_num'] > 0) { |
| | | $describe = "用户消费:{$this->model['order_no']}"; |
| | | $this->user->setIncConsumption(-$commomOrder['consumptions_num'], $describe,0,true,$status); |
| | | $this->user->setIncConsumption(-$commomOrder['consumptions_num'], $describe, 0, true, $status); |
| | | } |
| | | } |
| | | return $status; |
| | |
| | | 'order_price' => $order['order_price'], |
| | | 'coupon_id' => 0, |
| | | 'coupon_money' => $supplier['orderData']['coupon_money'], |
| | | 'coupon_id_sys'=>0, |
| | | 'coupon_money_sys'=>0, |
| | | 'points_money' => $commomOrder['is_real_use_points'] == 1?$supplier['orderData']['points_money']:0, |
| | | 'points_num' => $commomOrder['is_real_use_points'] == 1?$supplier['orderData']['points_num']:0, |
| | | 'coupon_id_sys' => 0, |
| | | 'coupon_money_sys' => 0, |
| | | 'points_money' => $commomOrder['is_real_use_points'] == 1 ? $supplier['orderData']['points_money'] : 0, |
| | | 'points_num' => $commomOrder['is_real_use_points'] == 1 ? $supplier['orderData']['points_num'] : 0, |
| | | 'pay_price' => $order['order_pay_price'], |
| | | 'delivery_type' => $supplier['orderData']['delivery'], |
| | | 'pay_type' => $commomOrder['pay_type'], |
| | |
| | | 'buyer_remark' => $this->params['supplier'][$supplier['shop_supplier_id']]['remark'], |
| | | 'order_source' => $this->orderSource['source'], |
| | | 'points_bonus' => $supplier['orderData']['points_bonus'], |
| | | 'is_agent' => $this->settledRule['is_agent']? 1:0, |
| | | 'is_agent' => $this->settledRule['is_agent'] ? 1 : 0, |
| | | 'shop_supplier_id' => $supplier['shop_supplier_id'], |
| | | 'supplier_money' => $order['supplier_money'], |
| | | 'sys_money' => $order['sys_money'], |
| | | 'app_id' => $this->app_id, |
| | | 'room_id' => $commomOrder['room_id'], |
| | | 'virtual_auto' => $supplier['productList'][0]['virtual_auto'], |
| | | 'is_verify' => isset($supplier['productList'][0]['is_verify'])?$supplier['productList'][0]['is_verify']:0, //是否支持核销 by yj |
| | | 'is_verify' => isset($supplier['productList'][0]['is_verify']) ? $supplier['productList'][0]['is_verify'] : 0, //是否支持核销 by yj |
| | | 'is_virtual' => $supplier['productList'][0]['is_virtual'], //是否是服务商品 by yj |
| | | 'product_reduce_money' => 0, |
| | | 'product_reduce_money' => 0, |
| | | 'user_counting_id' => empty($commomOrder['user_counting_data']) ? 0 : $commomOrder['user_counting_data']["order_id"], |
| | | 'total_service_price' => empty($order['total_service_price']) ? 0 : $order['total_service_price'], |
| | | // 'sell_store_id' => empty($sell_store_id) ? 0 : $sell_store_id, |
| | |
| | | $data['express_price'] = $order['express_price']; |
| | | } elseif ($supplier['orderData']['delivery'] == DeliveryTypeEnum::EXTRACT) { |
| | | $data['extract_store_id'] = $order['extract_store']['store_id']; |
| | | }elseif ($supplier['orderData']['delivery'] == DeliveryTypeEnum::STORESS) { |
| | | } elseif ($supplier['orderData']['delivery'] == DeliveryTypeEnum::STORESS) { |
| | | //配送门店 |
| | | $data['delivery_store'] = isset($this->params['delivery_store']) ? $this->params['delivery_store'] : $order['extract_store_id']; |
| | | $data['extract_store_id'] = isset($this->params['delivery_store']) ? $this->params['delivery_store'] : $order['extract_store_id']; |
| | | } |
| | | $data['delivery_store'] = isset($this->params['delivery_store']) ? $this->params['delivery_store'] : $order['extract_store_id']; |
| | | $data['extract_store_id'] = isset($this->params['delivery_store']) ? $this->params['delivery_store'] : $order['extract_store_id']; |
| | | } |
| | | |
| | | //随主订单配置 |
| | | $config = SettingModel::getItem('trade'); |
| | |
| | | $this->model->save($data); |
| | | $order_id = $this->model['order_id']; |
| | | $activity_order = new BranchActivityOrderModel(); |
| | | $activity_order->save(['order_id'=>$order_id,'activity_id'=>$commomOrder['activity_id'], 'app_id' => $this->app_id, 'shop_supplier_id' => $supplier['shop_supplier_id']]); |
| | | $activity_order->save(['order_id' => $order_id, 'activity_id' => $commomOrder['activity_id'], 'app_id' => $this->app_id, 'shop_supplier_id' => $supplier['shop_supplier_id']]); |
| | | return $order_id; |
| | | } |
| | | |
| | |
| | | 'line_price' => $product['product_sku']['line_price'], |
| | | 'product_weight' => empty($product['product_sku']['product_weight']) ? 0 : $product['product_sku']['product_weight'], |
| | | 'is_user_grade' => (int)$product['is_user_grade'], |
| | | 'grade_ratio' => $product['grade_ratio']??0, |
| | | 'grade_product_price' => isset($product['grade_product_price'])?$product['grade_product_price']:0, |
| | | 'grade_total_money' => $product['grade_total_money']??0, |
| | | 'coupon_money' => isset($product['coupon_money'])?$product['coupon_money']:0, |
| | | 'points_money' => isset($product['points_money']) && $commomOrder['is_real_use_points']?$product['points_money']:0, |
| | | 'points_num' => isset($product['points_num']) && $commomOrder['is_real_use_points']?$product['points_num']:0, |
| | | 'points_bonus' => isset($product['points_bonus'])?$product['points_bonus']:0, |
| | | 'grade_ratio' => $product['grade_ratio'] ?? 0, |
| | | 'grade_product_price' => isset($product['grade_product_price']) ? $product['grade_product_price'] : 0, |
| | | 'grade_total_money' => $product['grade_total_money'] ?? 0, |
| | | 'coupon_money' => isset($product['coupon_money']) ? $product['coupon_money'] : 0, |
| | | 'points_money' => isset($product['points_money']) && $commomOrder['is_real_use_points'] ? $product['points_money'] : 0, |
| | | 'points_num' => isset($product['points_num']) && $commomOrder['is_real_use_points'] ? $product['points_num'] : 0, |
| | | 'points_bonus' => isset($product['points_bonus']) ? $product['points_bonus'] : 0, |
| | | 'total_num' => $product['total_num'], |
| | | 'total_price' => $product['total_price'], |
| | | 'total_pay_price' => $product['total_pay_price'], |
| | |
| | | 'first_money' => $product['first_money'], |
| | | 'second_money' => $product['second_money'], |
| | | 'third_money' => $product['third_money'], |
| | | 'fullreduce_money' => isset($product['fullreduce_money'])?$product['fullreduce_money']:0, |
| | | 'fullreduce_money' => isset($product['fullreduce_money']) ? $product['fullreduce_money'] : 0, |
| | | 'virtual_content' => $product['virtual_content'], |
| | | 'is_alone_team' => $product['is_alone_team'], |
| | | 'alone_team_equity' => $product['alone_team_equity'], |
| | |
| | | 'is_verify' => $product['is_verify'], |
| | | 'verify_type' => $product['verify_type'], |
| | | 'verify_day' => $product['verify_day'], |
| | | 'service_name' => !empty($product['service_name'])?$product['service_name']:'', |
| | | 'service_price' => !empty($product['service_price'])?$product['service_price']:0, |
| | | 'service_name' => !empty($product['service_name']) ? $product['service_name'] : '', |
| | | 'service_price' => !empty($product['service_price']) ? $product['service_price'] : 0, |
| | | ]; |
| | | |
| | | // 记录订单商品来源id |
| | |
| | | $this->orderData['is_allow_points'] = true; |
| | | |
| | | //因为积分会过期问题 所以现在读取现在有的积分 |
| | | $points = ( new PointsLogModel())->getUserPoints($this->user['user_id']); |
| | | $points = (new PointsLogModel())->getUserPoints($this->user['user_id']); |
| | | if ($points < $productList[0]['points_num']) { |
| | | $this->error = '用户积分不足,无法使用积分兑换'; |
| | | return false; |
| | | } |
| | | /* if ($this->user['points'] < $productList[0]['points_num']) { |
| | | $this->error = '积分不足,去多赚点积分吧!'; |
| | | return false; |
| | | }*/ |
| | | /* if ($this->user['points'] < $productList[0]['points_num']) { |
| | | $this->error = '积分不足,去多赚点积分吧!'; |
| | | return false; |
| | | }*/ |
| | | return true; |
| | | } |
| | | if($force_points){ |
| | | if ($force_points) { |
| | | return true; |
| | | } |
| | | // 积分设置 |
| | |
| | | return false; |
| | | } |
| | | // 计算订单商品实际抵扣的积分数量和金额 |
| | | $ProductDeduct = new ConsumptionDeductService($productList); |
| | | $ProductDeduct = new PointsDeductService($productList); |
| | | $ProductDeduct->setProductPoints($maxPointsNumCount, $actualPointsNum); |
| | | // 积分抵扣总金额 |
| | | $orderPointsMoney = helper::getArrayColumnSum($productList, 'points_money'); |
| | |
| | | // 最多可抵扣的积分数量 |
| | | $product['max_points_num'] = helper::bcdiv($maxPointsMoney, $setting['discount']['discount_ratio'], 0); |
| | | // 如果超过商品最大抵扣数量 |
| | | if($product['max_points_discount'] > 0 && $product['max_points_num'] > $product['max_points_discount'] * $product['total_num']){ |
| | | if ($product['max_points_discount'] > 0 && $product['max_points_num'] > $product['max_points_discount'] * $product['total_num']) { |
| | | $product['max_points_num'] = $product['max_points_discount'] * $product['total_num']; |
| | | } |
| | | } |
| | |
| | | private function setOrderPointsBonus() |
| | | { |
| | | // 初始化商品积分赠送数量 |
| | | foreach ($this->supplierData as &$supplier){ |
| | | foreach ($supplier['productList'] as $product){ |
| | | foreach ($this->supplierData as &$supplier) { |
| | | foreach ($supplier['productList'] as $product) { |
| | | $product['points_bonus'] = 0; |
| | | } |
| | | $supplier['orderData']['points_bonus'] = 0; |
| | |
| | | |
| | | |
| | | /** |
| | | * 计算订单可用消费券抵扣 |
| | | */ |
| | | private function setOrderConsumption($productList) |
| | | { |
| | | $this->orderData['consumption_money'] = 0; |
| | | // 消费券抵扣总数量 |
| | | $this->orderData['consumption_num'] = 0; |
| | | // 允许消费券抵扣 |
| | | $this->orderData['is_allow_consumption'] = false; |
| | | // 消费券设置 |
| | | $setting = SettingModel::getItem('consumption'); |
| | | // 条件:后台开启下单使用消费券抵扣 |
| | | if (!$setting['is_shopping_discount']) { |
| | | return false; |
| | | } |
| | | // 条件:订单金额满足[?]元 |
| | | if (helper::bccomp($setting['discount']['full_order_price'], $this->orderData['order_total_price']) === 1) { |
| | | return false; |
| | | } |
| | | // 计算订单商品最多可抵扣的消费券数量 |
| | | $this->setOrderConsumptionMaxPointsNum($productList); |
| | | // 订单最多可抵扣的消费券总数量 |
| | | $maxConsumptionNumCount = helper::getArrayColumnSum($productList, 'max_consumption_num'); |
| | | // 实际可抵扣的消费券数量 |
| | | $actualConsumptionNum = min($maxConsumptionNumCount, $this->user['consumer_coupon']); |
| | | if ($actualConsumptionNum < 1) { |
| | | $this->orderData['consumption_money'] = 0; |
| | | // 消费券抵扣总数量 |
| | | $this->orderData['consumption_num'] = 0; |
| | | // 允许消费券抵扣 |
| | | $this->orderData['is_allow_consumption'] = true; |
| | | return false; |
| | | } |
| | | // 计算订单商品实际抵扣的消费券数量和金额 |
| | | $ProductDeduct = new ConsumptionDeductService($productList); |
| | | $ProductDeduct->setProductConsumption($maxConsumptionNumCount, $actualConsumptionNum); |
| | | // 消费券抵扣总金额 |
| | | $orderConsumptionMoney = helper::getArrayColumnSum($productList, 'consumption_money'); |
| | | $this->orderData['consumption_money'] = helper::number2($orderConsumptionMoney); |
| | | // 消费券抵扣总数量 |
| | | $this->orderData['consumption_num'] = $actualConsumptionNum; |
| | | // 允许消费券抵扣 |
| | | $this->orderData['is_allow_consumption'] = true; |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 计算订单商品最多可抵扣的消费券数量 |
| | | */ |
| | | private function setOrderConsumptionMaxPointsNum($productList) |
| | | { |
| | | // 消费券设置 |
| | | $setting = SettingModel::getItem('consumption'); |
| | | foreach ($productList as &$product) { |
| | | // 商品不允许消费券抵扣 |
| | | if (!$product['is_consumption_discount'] || $product['is_repurchase'] || $product['is_newcomer'] || $product['is_vip']) continue; |
| | | // 消费券抵扣比例 |
| | | $deductionRatio = helper::bcdiv($setting['discount']['max_money_ratio'], 100); |
| | | // 最多可抵扣的金额 |
| | | $maxPointsMoney = helper::bcmul($product['total_price'], $deductionRatio); |
| | | // 最多可抵扣的消费券数量 |
| | | $product['max_consumption_num'] = helper::bcdiv($maxPointsMoney, $setting['discount']['discount_ratio'], 0); |
| | | // 如果超过商品最大抵扣数量 |
| | | if ($product['max_consumption_discount'] > 0 && $product['max_consumption_num'] > $product['max_consumption_discount'] * $product['total_num']) { |
| | | $product['max_consumption_num'] = $product['max_consumption_discount'] * $product['total_num']; |
| | | } |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 计算订单消费券赠送数量 |
| | | */ |
| | | private function setOrderConsumptionBonus() |
| | | { |
| | | // 初始化商品消费券赠送数量 |
| | | foreach ($this->supplierData as &$supplier) { |
| | | foreach ($supplier['productList'] as $product) { |
| | | $product['consumption_bonus'] = 0; |
| | | } |
| | | $supplier['orderData']['consumption_bonus'] = 0; |
| | | } |
| | | // 消费券设置 |
| | | $setting = SettingModel::getItem('consumption'); |
| | | // 条件:后台开启开启购物送消费券 |
| | | if (!$setting['is_shopping_gift']) { |
| | | return false; |
| | | } |
| | | // 设置商品消费券赠送数量 |
| | | foreach ($this->supplierData as &$supplier) { |
| | | foreach ($supplier['productList'] as &$product) { |
| | | // 消费券赠送比例 |
| | | $ratio = $setting['gift_ratio'] / 100; |
| | | // 计算抵扣的消费券数量 |
| | | $product['consumption_bonus'] = !$product['is_consumption_gift'] ? 0 : helper::bcmul($product['total_pay_price'], $ratio, 0); |
| | | } |
| | | // 订单消费券赠送数量 |
| | | $supplier['orderData']['consumption_bonus'] = helper::getArrayColumnSum($supplier['productList'], 'consumption_bonus'); |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 设置订单商品服务费用 |
| | | */ |
| | | private function setProductService($productList) |
| | |
| | | $productListTemp = helper::getArrayColumns($productList, ['total_price']); |
| | | $service = new FullDeductService; |
| | | $completed = $service->setProductFullreduceMoney($productListTemp, $reduce['reduced_price']); |
| | | if($completed){ |
| | | if ($completed) { |
| | | // 分配订单商品优惠券抵扣金额 |
| | | foreach ($productList as $key => &$product) { |
| | | $product['fullreduce_money'] = $completed[$key]['fullreduce_money'] / 100; |
| | |
| | | private function setOrderFinalPrice() |
| | | { |
| | | |
| | | foreach ($this->supplierData as &$supplier){ |
| | | foreach ($this->supplierData as &$supplier) { |
| | | //商户独立抽成 |
| | | $config = SettingModel::getSupplierCommissionRate($supplier["shop_supplier_id"]); |
| | | $sys_percent = intval($config['commission_rate']); |
| | | $supplier_percent = 100 - $sys_percent; |
| | | // 供应商结算金额,包括运费 |
| | | $supplier['orderData']['supplier_money'] = helper::number2($supplier['orderData']['order_price'] * $supplier_percent/100 + $supplier['orderData']['express_price']); |
| | | $supplier['orderData']['supplier_money'] = helper::number2($supplier['orderData']['order_price'] * $supplier_percent / 100 + $supplier['orderData']['express_price']); |
| | | // 平台分佣金额 |
| | | $supplier['orderData']['sys_money'] = helper::number2($supplier['orderData']['order_price'] * $sys_percent/100); |
| | | $supplier['orderData']['sys_money'] = helper::number2($supplier['orderData']['order_price'] * $sys_percent / 100); |
| | | // 产品价格 |
| | | // 结算金额不包括运费 |
| | | foreach ($supplier['productList'] as &$product){ |
| | | foreach ($supplier['productList'] as &$product) { |
| | | |
| | | $product['supplier_money'] = helper::number2($product['total_pay_price'] * $supplier_percent/100); |
| | | $product['sys_money'] = helper::number2($product['total_pay_price'] * $sys_percent/100); |
| | | $product['supplier_money'] = helper::number2($product['total_pay_price'] * $supplier_percent / 100); |
| | | $product['sys_money'] = helper::number2($product['total_pay_price'] * $sys_percent / 100); |
| | | } |
| | | } |
| | | $price = 0; |
| | | foreach ($this->supplierData as &$supplier){ |
| | | foreach ($this->supplierData as &$supplier) { |
| | | $price += $supplier['orderData']['order_pay_price']; |
| | | } |
| | | |