添加:文创豆兑换商品

This commit is contained in:
wuhui_zzw 2023-11-30 17:01:46 +08:00
parent d2f28fa2fb
commit f44ad3bad1
10 changed files with 84 additions and 22 deletions

View File

@ -40,6 +40,12 @@ class OrderGoodsCollection extends Collection
});
}
public function getLegumesTotal(){
return $this->sum(function (PreOrderGoods $orderGoods) {
return $orderGoods->getUseLegumes();
});
}
/**
* 获取会员价
* @return int

View File

@ -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;

View File

@ -208,6 +208,11 @@ trait PreOrderGoodsTrait
return $this->getPriceCalculator()->getPrice();
}
public function getUseLegumes()
{
return $this->getPriceCalculator()->getLegumes();
}
/**
* 原始价格
* @return mixed

View File

@ -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));
}

View File

@ -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;
}
}

View File

@ -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);

View File

@ -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

View File

@ -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');

View File

@ -37,12 +37,15 @@ abstract class OrderGoodsPrice
*/
abstract public function getPrice();
/**
* 计算商品销售价格
* @return float
*/
abstract public function getGoodsPrice();
/**
* 计算商品市场价格
* @return float

View File

@ -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);