diff --git a/app/common/modules/orderGoods/OrderGoodsCollection.php b/app/common/modules/orderGoods/OrderGoodsCollection.php index 12f1dc06..7afdcce2 100644 --- a/app/common/modules/orderGoods/OrderGoodsCollection.php +++ b/app/common/modules/orderGoods/OrderGoodsCollection.php @@ -40,6 +40,12 @@ class OrderGoodsCollection extends Collection }); } + public function getLegumesTotal(){ + return $this->sum(function (PreOrderGoods $orderGoods) { + return $orderGoods->getUseLegumes(); + }); + } + /** * 获取会员价 * @return int diff --git a/app/common/modules/orderGoods/models/PreOrderGoods.php b/app/common/modules/orderGoods/models/PreOrderGoods.php index 33b04b3c..8cab962c 100644 --- a/app/common/modules/orderGoods/models/PreOrderGoods.php +++ b/app/common/modules/orderGoods/models/PreOrderGoods.php @@ -25,6 +25,8 @@ use app\frontend\modules\order\models\PreOrder; use app\frontend\modules\orderGoods\taxFee\OrderGoodsTaxFeeManager; use Illuminate\Support\Carbon; use Illuminate\Support\Collection; +use Yunshop\CulturalSpace\models\CulturalFund; +use Yunshop\CulturalSpace\models\GoodsCulturalSpace; use Yunshop\PointMall\models\PointMallGoodsModel; use Yunshop\PointMall\models\PointMallGoodsOptionsModel; @@ -163,6 +165,15 @@ class PreOrderGoods extends OrderGoods $this->product_sn = $this->goodsOption->product_sn ? (string)$this->goodsOption->product_sn : $this->product_sn; } + // 当前商品是否为文创豆兑换 文创豆兑换-计算使用的豆数量 + $this->is_legumes_exchange = (int)request()->input('is_legumes_exchange'); + if($this->is_legumes_exchange == 1){ + $legumes_exchange_price = GoodsCulturalSpace::uniacid()->where('goods_id',(int)$this->goods_id)->value('legumes_exchange_price'); + $current_fee = CulturalFund::uniacid()->value('current_fee'); + $this->legumes_rate = $current_fee; + $this->legumes_exchange_price = $legumes_exchange_price; + $this->use_legumes_exchange = (float)sprintf("%.2f",$legumes_exchange_price * $current_fee); + } // 判断:当前商品是否存在积分商品设置 /*if((int)$this->pointGoods->id > 0){ $this->point_status = 1; diff --git a/app/common/modules/orderGoods/models/PreOrderGoodsTrait.php b/app/common/modules/orderGoods/models/PreOrderGoodsTrait.php index 96f2071a..53dff1de 100644 --- a/app/common/modules/orderGoods/models/PreOrderGoodsTrait.php +++ b/app/common/modules/orderGoods/models/PreOrderGoodsTrait.php @@ -208,6 +208,11 @@ trait PreOrderGoodsTrait return $this->getPriceCalculator()->getPrice(); } + public function getUseLegumes() + { + return $this->getPriceCalculator()->getLegumes(); + } + /** * 原始价格 * @return mixed diff --git a/app/common/modules/trade/models/Trade.php b/app/common/modules/trade/models/Trade.php index 5f752272..f78a40f8 100644 --- a/app/common/modules/trade/models/Trade.php +++ b/app/common/modules/trade/models/Trade.php @@ -20,6 +20,7 @@ use app\framework\Http\Request; use app\frontend\models\Member; use app\frontend\modules\order\models\PreOrder; use Illuminate\Support\Facades\DB; +use Yunshop\CulturalSpace\models\CulturalSpace; use Yunshop\PackageDelivery\models\DeliveryOrder; use Yunshop\StoreCashier\common\models\SelfDelivery; @@ -68,6 +69,14 @@ class Trade extends BaseModel $this->is_diy_form_jump = \Setting::get('shop.order.is_diy_form_jump') ?: 0; $member = Member::current(); $this->balance = $member->credit2 ?: 0; + // 判断:当前订单是否为文创豆兑换商品 + $this->use_legumes_exchange_total = $this->orders->sum('use_legumes_total'); + $this->is_allow_exchange = 0;// 是否允许兑换 默认不允许 + if($this->use_legumes_exchange_total > 0){ + $holdGoodsLegumes = CulturalSpace::uniacid()->where('uid',$member->uid)->value('goods_legumes'); + $this->is_allow_exchange = (int)($holdGoodsLegumes >= $this->use_legumes_exchange_total); + } + event(new AfterTradeCreatedEvent($this)); } diff --git a/app/frontend/modules/finance/deduction/PointGoodsDeduction.php b/app/frontend/modules/finance/deduction/PointGoodsDeduction.php index 90b32ee3..88d6c10d 100644 --- a/app/frontend/modules/finance/deduction/PointGoodsDeduction.php +++ b/app/frontend/modules/finance/deduction/PointGoodsDeduction.php @@ -17,8 +17,10 @@ class PointGoodsDeduction extends GoodsDeduction return 'point'; } - public function deductible($goods) - { + public function deductible($goods){ + // 判断:如果是文创豆兑换商品 禁用积分抵扣 + if((int)request()->input('is_legumes_exchange') == 1) return false; + return true; } } \ No newline at end of file diff --git a/app/frontend/modules/order/models/PreOrder.php b/app/frontend/modules/order/models/PreOrder.php index 0a73cb59..11813ee5 100644 --- a/app/frontend/modules/order/models/PreOrder.php +++ b/app/frontend/modules/order/models/PreOrder.php @@ -504,14 +504,12 @@ class PreOrder extends Order 'shop_name' => $this->getShopName(),// 店铺名称 'need_address' => $this->isNeedAddress(),//订单不需要填写地址 //发票信息应该保存到订单发票表上 - 'invoice_type' => $this->getRequest() - ->input('invoice_type'),//发票类型 - 'rise_type' => $this->getRequest() - ->input('rise_type'),//收件人或单位 - 'collect_name' => $this->getRequest() - ->input('call'),//抬头或单位名称 - 'company_number' => $this->getRequest() - ->input('company_number'),//单位识别号 + 'invoice_type' => $this->getRequest()->input('invoice_type'),//发票类型 + 'rise_type' => $this->getRequest()->input('rise_type'),//收件人或单位 + 'collect_name' => $this->getRequest()->input('call'),//抬头或单位名称 + 'company_number' => $this->getRequest()->input('company_number'),//单位识别号 + // 使用的文创豆总数 + 'use_legumes_total' => $this->getLegumesTotal(),// 获取使用的文创豆总数 ]; $attributes = array_merge($this->getAttributes(),$attributes); $this->setRawAttributes($attributes); diff --git a/app/frontend/modules/order/models/PreOrderTrait.php b/app/frontend/modules/order/models/PreOrderTrait.php index 03f5396a..643ba685 100644 --- a/app/frontend/modules/order/models/PreOrderTrait.php +++ b/app/frontend/modules/order/models/PreOrderTrait.php @@ -64,6 +64,9 @@ trait PreOrderTrait return $this->goods_price = $this->orderGoods->getPrice(); } + public function getLegumesTotal(){ + return $this->use_legumes_total = $this->orderGoods->getLegumesTotal(); + } /** * 统计订单商品会员价金额 * @return int diff --git a/app/frontend/modules/orderGoods/price/option/BaseOrderGoodsPrice.php b/app/frontend/modules/orderGoods/price/option/BaseOrderGoodsPrice.php index e8e210a6..2738e2e2 100644 --- a/app/frontend/modules/orderGoods/price/option/BaseOrderGoodsPrice.php +++ b/app/frontend/modules/orderGoods/price/option/BaseOrderGoodsPrice.php @@ -24,6 +24,8 @@ use app\frontend\models\orderGoods\PreOrderGoodsDiscount; use app\frontend\modules\orderGoods\OrderGoodsTaxfeeNode; use app\frontend\modules\orderGoods\price\adapter\GoodsAdapterManager; use app\frontend\modules\orderGoods\taxFee\BaseTaxFee; +use Yunshop\CulturalSpace\models\CulturalFund; +use Yunshop\CulturalSpace\models\GoodsCulturalSpace; abstract class BaseOrderGoodsPrice extends OrderGoodsPrice { @@ -93,14 +95,10 @@ abstract class BaseOrderGoodsPrice extends OrderGoodsPrice */ public function getPrice() { - - if (isset($this->price)) { - return $this->price; - } - if ($this->isCoinExchange()) { - return 0; - } - + // 判断:开启文创豆兑换 价格为0 + if((int)request()->input('is_legumes_exchange') == 1) return 0; + if (isset($this->price)) return $this->price; + if ($this->isCoinExchange()) return 0; // 商品销售价 - 等级优惠金额 $this->price = $this->getGoodsPrice(); @@ -110,6 +108,21 @@ abstract class BaseOrderGoodsPrice extends OrderGoodsPrice return $this->price; } + public function getLegumes(){ + if((int)request()->input('is_legumes_exchange') == 1){ + $legumes_exchange_price = GoodsCulturalSpace::uniacid()->where('goods_id',(int)$this->orderGoods->goods_id)->value('legumes_exchange_price'); + $current_fee = CulturalFund::uniacid()->value('current_fee'); + $this->legumes_rate = $current_fee; + $this->legumes_exchange_price = $legumes_exchange_price; + $this->use_legumes_exchange = (float)sprintf("%.2f",$legumes_exchange_price * $current_fee); + + return $this->use_legumes_exchange; + } + + + return 0; + } + //todo blank 商品价格适配器 public function goodsPriceManager() { @@ -121,8 +134,11 @@ abstract class BaseOrderGoodsPrice extends OrderGoodsPrice return $this->priceClass; } - public function getVipPrice() - { + public function getVipPrice(){ + + // 判断:开启文创豆兑换 价格为0 + if((int)request()->input('is_legumes_exchange') == 1) return 0; + if ($this->isCoinExchange()) { return 0; } @@ -136,7 +152,7 @@ abstract class BaseOrderGoodsPrice extends OrderGoodsPrice */ private function isCoinExchange() { - if (!isset($this->isCoinExchange)) { + if (!isset($this->isCoinExchange) && (int)request()->input('is_legumes_exchange') != 1) { //blank not deduction if ($this->orderGoods->order->isDeductionDisable()) { @@ -147,7 +163,8 @@ abstract class BaseOrderGoodsPrice extends OrderGoodsPrice // 判断:当前商品是否为积分商品&& (int)$this->orderGoods->pointGoods->id > 0 if (!$this->orderGoods->goods->hasOneSale->has_all_point_deduct ) { $this->isCoinExchange = false; - } else { + } + else { $this->isCoinExchange = true; $relations = collect(\app\common\modules\shop\ShopConfig::current()->get('shop-foundation.coin-exchange'))->sortBy('weight'); diff --git a/app/frontend/modules/orderGoods/price/option/OrderGoodsPrice.php b/app/frontend/modules/orderGoods/price/option/OrderGoodsPrice.php index e26d6277..13d4c527 100644 --- a/app/frontend/modules/orderGoods/price/option/OrderGoodsPrice.php +++ b/app/frontend/modules/orderGoods/price/option/OrderGoodsPrice.php @@ -37,12 +37,15 @@ abstract class OrderGoodsPrice */ abstract public function getPrice(); + /** * 计算商品销售价格 * @return float */ abstract public function getGoodsPrice(); + + /** * 计算商品市场价格 * @return float diff --git a/plugins/cultural-space/src/listener/OrderPaidListener.php b/plugins/cultural-space/src/listener/OrderPaidListener.php index 9534edb1..55a438a5 100644 --- a/plugins/cultural-space/src/listener/OrderPaidListener.php +++ b/plugins/cultural-space/src/listener/OrderPaidListener.php @@ -7,6 +7,8 @@ use app\common\events\order\AfterOrderPaidEvent; use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Foundation\Bus\DispatchesJobs; use Yunshop\CulturalSpace\models\CulturalSpace; +use Yunshop\CulturalSpace\models\CulturalSpaceGoodsLegumes; + class OrderPaidListener{ use DispatchesJobs; @@ -16,6 +18,12 @@ class OrderPaidListener{ public function handle(AfterOrderPaidEvent $event){ try { $model = $event->getOrderModel(); + // 订单支付成功 扣除商品文创豆 + if($model->use_legumes_total > 0) { + (new CulturalSpaceGoodsLegumes())->changeHandle((int)$model->uid,(float)$model->use_legumes_total,0,"兑换商品使用",1,[ + 'order_id' => $model->id ?? 0,// 订单id + ]); + } // 订单支付成功奖励贡献值 $CulturalSpace=new CulturalSpace(); $CulturalSpace->buyGoodsGiveContribution($model->uid,$model->id);