| | |
| | | use app\api\model\plus\coupon\UserCoupon as UserCouponModel; |
| | | use app\api\model\product\Category; |
| | | use app\api\service\consumption\ConsumptionDeductService; |
| | | use app\api\service\points\PointsDeductService; |
| | | use app\common\enum\order\OrderPayTypeEnum; |
| | | use app\common\enum\order\OrderSourceEnum; |
| | | use app\common\enum\order\OrderTypeEnum; |
| | | use app\common\enum\supplier\SupplierType; |
| | | use app\common\model\settings\Setting as SettingModel; |
| | | use app\api\service\coupon\ProductDeductService; |
| | | use app\common\model\store\Store as StoreModel; |
| | |
| | | $totalConsumptionMoney = 0; |
| | | $totalConsumption = 0; |
| | | $totalProductReduce = 0; |
| | | $settlementPrice=0; |
| | | $this->commonOrderData = $this->getCommonOrderData(); |
| | | // 供应商 |
| | | foreach ($this->supplierData as &$supplier) { |
| | |
| | | // 设置订单商品总金额(不含优惠折扣) |
| | | $this->setOrderTotalPrice($supplier['productList']); |
| | | $orderTotalPrice += $this->orderData['order_total_price']; |
| | | // 设置订单商品总结算金额 |
| | | $this->setOrderSettlementPrice($supplier['productList']); |
| | | $settlementPrice += $this->orderData['settlement_price']; |
| | | // 先计算商品满减 |
| | | $this->setProductReduce($supplier['productList']); |
| | | $totalProductReduce += $this->orderData['product_reduce_money']; |
| | |
| | | $this->setOrderCouponMoney($couponList, $this->orderData['coupon_id'], $supplier['productList']); |
| | | } |
| | | // 计算可用积分抵扣 |
| | | $this->setOrderPoints($supplier['productList']); |
| | | $this->setOrderPoints($supplier['productList'],$supplier['supplier']); |
| | | $totalPointsMoney += $this->orderData['points_money']; |
| | | $totalPoints += $this->orderData['points_num']; |
| | | // 计算可用消费券抵扣 |
| | |
| | | } |
| | | $this->orderData['store_id'] = $this->params['supplier'][$supplier['shop_supplier_id']]['store_id']; |
| | | } |
| | | |
| | | |
| | | // 处理配送方式 |
| | | if ($this->orderData['delivery'] == DeliveryTypeEnum::EXPRESS) { |
| | | $this->setOrderExpress($supplier['productList']); |
| | |
| | | $this->commonOrderData = array_merge([ |
| | | 'order_total_num' => $orderTotalNum, // 商品总数量 |
| | | 'order_total_price' => helper::number2($orderTotalPrice), // 商品总价 |
| | | 'settlement_price' => helper::number2($settlementPrice), // 商品总结算价 |
| | | 'order_pay_price' => helper::number2($orderPayPrice), // 商品总价,最终支付 |
| | | 'coupon_list' => $couponList, |
| | | 'coupon_id_sys' => $coupon_id, |
| | |
| | | // 订单商品的总金额(不含优惠券折扣) |
| | | $this->orderData['order_total_price'] = helper::number2(helper::getArrayColumnSum($productList, 'total_price')); |
| | | } |
| | | /** |
| | | * 设置订单的商品总结算金额(不含优惠折扣) |
| | | */ |
| | | private function setOrderSettlementPrice($productList) |
| | | { |
| | | // 订单商品的总金额(不含优惠券折扣) |
| | | $this->orderData['settlement_price'] = helper::number2(helper::getArrayColumnSum($productList, 'total_settlement_price')); |
| | | } |
| | | |
| | | /** |
| | | * 当前用户可用的优惠券列表 |
| | |
| | | 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']); |
| | | } |
| | |
| | | // 积分兑换扣除用户积分 |
| | | if ($commomOrder['force_points']) { |
| | | $describe = "用户积分兑换消费:{$this->model['order_no']}"; |
| | | $this->user->setIncPoints(-$commomOrder['points_num'], $describe); |
| | | $this->user->setIncPoints(-$commomOrder['points_num'], $describe,0,true,($supplier['supplier']['supplier_type'] == SupplierType::GROUPBUYING?1:0)); |
| | | } 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); |
| | | $this->user->setIncPoints(-$commomOrder['points_num'], $describe,0,true,($supplier['supplier']['supplier_type'] == SupplierType::GROUPBUYING?1:0)); |
| | | } |
| | | // 积分抵扣情况下扣除用户积分 |
| | | // 消费券抵扣情况下扣除用户消费券 |
| | | if ($commomOrder['is_allow_consumption'] && $commomOrder['is_real_use_consumption'] && $commomOrder['consumption_num'] > 0) { |
| | | $describe = "用户消费:{$this->model['order_no']}"; |
| | | $this->user->setIncConsumption(-$commomOrder['consumption_num'], $describe); |
| | |
| | | 'user_id' => $this->user['user_id'], |
| | | 'order_no' => $this->model->orderNo(), |
| | | 'total_price' => $order['order_total_price'], |
| | | 'settlement_price' => $order['settlement_price'], |
| | | 'order_price' => $order['order_price'], |
| | | 'coupon_id' => $supplier['orderData']['coupon_id'], |
| | | 'coupon_money' => $supplier['orderData']['coupon_money'], |
| | |
| | | // 订单商品列表 |
| | | $productList = []; |
| | | foreach ($supplier['productList'] as $product) { |
| | | $product_type = 0; |
| | | if ($product['is_brand'] == 1) { |
| | | $product_type = 10; |
| | | }else if ($supplier['supplier']['supplier_type'] == SupplierType::GROUPBUYING) { |
| | | $product_type = 20; |
| | | } |
| | | $item = [ |
| | | 'order_id' => $status, |
| | | 'user_id' => $this->user['user_id'], |
| | |
| | | 'image_id' => $product['image'][0]['image_id'], |
| | | 'deduct_stock_type' => $product['deduct_stock_type'], |
| | | 'spec_type' => $product['spec_type'], |
| | | 'open_coupon' => $product['open_coupon'], |
| | | 'open_coupons' => $product['open_coupons'], |
| | | 'spec_sku_id' => $product['product_sku']['spec_sku_id'], |
| | | 'product_sku_id' => $product['product_sku']['product_sku_id'], |
| | | 'product_attr' => $product['product_sku']['product_attr'], |
| | |
| | | 'product_no' => $product['product_sku']['product_no'], |
| | | 'product_price' => $product['product_sku']['product_price'], |
| | | 'line_price' => $product['product_sku']['line_price'], |
| | | 'settlement_price' => $product['product_sku']['settlement_price'], |
| | | 'product_weight' => $product['product_sku']['product_weight'], |
| | | 'is_user_grade' => (int)$product['is_user_grade'], |
| | | 'grade_ratio' => $product['grade_ratio'], |
| | |
| | | 'consumption_bonus' => isset($product['consumption_bonus'])?$product['consumption_bonus']:0, |
| | | 'total_num' => $product['total_num'], |
| | | 'total_price' => $product['total_price'], |
| | | 'total_settlement_price' => $product['total_settlement_price'], |
| | | 'total_pay_price' => $product['total_pay_price'], |
| | | 'supplier_money' => $product['supplier_money'], |
| | | 'is_agent' => $product['is_agent'], |
| | |
| | | 'is_viewpoint_money' => $product['is_viewpoint_money'], |
| | | 'viewpoint_money' => $product['viewpoint_money'], |
| | | 'deduction_price' => empty($product['deduction_price']) ? 0 : $product['deduction_price'],//券商品的抵扣金额 by yj 2024.1.10 |
| | | 'product_type' => $product_type, |
| | | 'is_activation_code' => $product['is_activation_code'], |
| | | 'activation_code_num' => $product['product_sku']['activation_code_num'], |
| | | 'activation_code_exchange' => $product['activation_code_exchange'], |
| | | 'is_gift_pack' => $product['is_gift_pack'], |
| | | 'vip_order_num' => $product['vip_order_num'], |
| | | ]; |
| | | // 记录订单商品来源id |
| | | $item['product_source_id'] = isset($product['product_source_id']) ? $product['product_source_id'] : 0; |
| | |
| | | /** |
| | | * 计算订单可用积分抵扣 |
| | | */ |
| | | private function setOrderPoints($productList) |
| | | private function setOrderPoints($productList,$supplier) |
| | | { |
| | | $this->orderData['points_money'] = 0; |
| | | // 积分抵扣总数量 |
| | | $this->orderData['points_num'] = 0; |
| | | // 允许积分抵扣 |
| | | $this->orderData['is_allow_points'] = false; |
| | | |
| | | // 只有团购类商品允许使用品牌积分 |
| | | $points=$supplier['supplier_type']==SupplierType::GROUPBUYING?$this->user['points']:$this->user['points']-$this->user['brand_points']; |
| | | // 积分商城兑换 |
| | | if (isset($this->settledRule['force_points']) && $this->settledRule['force_points']) { |
| | | // 积分抵扣金额,商品价格-兑换金额 |
| | |
| | | $this->orderData['points_num'] = $productList[0]['points_num']; |
| | | // 允许积分抵扣 |
| | | $this->orderData['is_allow_points'] = true; |
| | | if ($this->user['points'] < $productList[0]['points_num']) { |
| | | if ($points < $productList[0]['points_num']) { |
| | | $this->error = '积分不足,去多赚点积分吧!'; |
| | | return false; |
| | | } |
| | |
| | | // 订单最多可抵扣的积分总数量 |
| | | $maxPointsNumCount = helper::getArrayColumnSum($productList, 'max_points_num'); |
| | | // 实际可抵扣的积分数量 |
| | | $actualPointsNum = min($maxPointsNumCount, $this->user['points']); |
| | | $actualPointsNum = min($maxPointsNumCount, $points); |
| | | if ($actualPointsNum < 1) { |
| | | $this->orderData['points_money'] = 0; |
| | | // 积分抵扣总数量 |
| | |
| | | return false; |
| | | } |
| | | // 计算订单商品实际抵扣的积分数量和金额 |
| | | $ProductDeduct = new ConsumptionDeductService($productList); |
| | | $ProductDeduct = new PointsDeductService($productList); |
| | | $ProductDeduct->setProductPoints($maxPointsNumCount, $actualPointsNum); |
| | | // 积分抵扣总金额 |
| | | $orderPointsMoney = helper::getArrayColumnSum($productList, 'points_money'); |
| | |
| | | $product['max_points_num'] = $product['points_num']; |
| | | } else { |
| | | // 商品不允许积分抵扣 |
| | | if (!$product['is_points_discount']) continue; |
| | | if (!$product['is_points_discount']||$product['is_vip']||$product['is_newcomer']||$product['is_repurchase']) continue; |
| | | // 积分抵扣比例 |
| | | $deductionRatio = helper::bcdiv($setting['discount']['max_money_ratio'], 100); |
| | | // 最多可抵扣的金额 |
| | |
| | | $service = new FullDeductService; |
| | | $completed = $service->setProductFullreduceMoney($productListTemp, $reduce['reduced_price']); |
| | | // 分配订单商品优惠券抵扣金额 |
| | | foreach ($productList as $key => &$product) { |
| | | $product['fullreduce_money'] = $completed[$key]['fullreduce_money'] / 100; |
| | | if ($completed){ |
| | | // 分配订单商品优惠券抵扣金额 |
| | | foreach ($productList as $key => &$product) { |
| | | $product['fullreduce_money'] = $completed[$key]['fullreduce_money'] / 100; |
| | | } |
| | | } |
| | | return true; |
| | | } |