| | |
| | | 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; |
| | |
| | | $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']; |
| | | // 计算可用消费券抵扣 |
| | |
| | | // 积分兑换扣除用户积分 |
| | | 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); |
| | |
| | | // 订单商品列表 |
| | | $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'], |
| | |
| | | '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; |
| | | // 积分抵扣总数量 |
| | |
| | | $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; |
| | | } |