重构:文创豆商城 文创豆兑换商品改为兑换额度兑换商品

This commit is contained in:
wuhui_zzw 2023-12-02 13:41:30 +08:00
parent 37d8f86555
commit 712d26faf3
14 changed files with 80 additions and 16 deletions

View File

@ -908,6 +908,7 @@ class SurveyController extends BaseController{
'ims_yz_withdraw_rich_text',
'ims_yz_help_center_content',
'ims_yz_rich_text',
'ims_yz_wechat_menu',
// 经销商相关

View File

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

View File

@ -213,6 +213,10 @@ trait PreOrderGoodsTrait
return $this->getPriceCalculator()->getLegumes();
}
public function getUseLegumesPrice(){
return $this->getPriceCalculator()->getLegumesPrice();
}
/**
* 原始价格
* @return mixed

View File

@ -71,10 +71,12 @@ class Trade extends BaseModel
$this->balance = $member->credit2 ?: 0;
// 判断:当前订单是否为文创豆兑换商品
$this->use_legumes_exchange_total = $this->orders->sum('use_legumes_total');
$this->use_legumes_price_total = $this->orders->sum('use_legumes_price');
$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);
// $holdGoodsLegumes = CulturalSpace::uniacid()->where('uid',$member->uid)->value('goods_legumes');
$holdGoodsLegumesPrice = CulturalSpace::uniacid()->where('uid',$member->uid)->value('goods_legumes_money');
$this->is_allow_exchange = (int)($holdGoodsLegumesPrice >= $this->use_legumes_price_total);
}
event(new AfterTradeCreatedEvent($this));

View File

@ -508,8 +508,9 @@ class PreOrder extends Order
'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(),// 获取使用的文创豆总数
'use_legumes_price' => $this->getLegumesPriceTotal(),// 获取使用的兑换额度
];
$attributes = array_merge($this->getAttributes(),$attributes);
$this->setRawAttributes($attributes);

View File

@ -64,9 +64,15 @@ trait PreOrderTrait
return $this->goods_price = $this->orderGoods->getPrice();
}
// 文创豆兑换 - 获取使用的豆
public function getLegumesTotal(){
return $this->use_legumes_total = $this->orderGoods->getLegumesTotal();
}
// 文创豆兑换 - 获取使用的兑换额度
public function getLegumesPriceTotal(){
return $this->use_legumes_price = $this->orderGoods->getLegumesPriceTotal();
}
/**
* 统计订单商品会员价金额
* @return int

View File

@ -119,10 +119,20 @@ abstract class BaseOrderGoodsPrice extends OrderGoodsPrice
return $this->use_legumes_exchange;
}
return 0;
}
public function getLegumesPrice(){
if((int)request()->input('is_legumes_exchange') == 1){
$this->use_legumes_exchange_price = GoodsCulturalSpace::uniacid()->where('goods_id',(int)$this->orderGoods->goods_id)->value('legumes_exchange_price');
return $this->use_legumes_exchange_price;
}
return 0;
}
//todo blank 商品价格适配器
public function goodsPriceManager()
{

View File

@ -87,6 +87,7 @@ class LegumesController extends BaseController{
$info = CulturalSpaceLegumesWithdrawal::find($id);
$uid = $info->uid;
$buyGoodsNum = (float)$info->buy_goods_num;
$buyGoodsNumMoney = (float)$info->buy_goods_num_money;
$realityAmount = $info->reality_amount;
$month = $info->created_at->format('Ym');
// 修改状态
@ -103,7 +104,10 @@ class LegumesController extends BaseController{
$result = (new ExternalApi())->salaryModelOutOrder($info);
if((int)$result['respCode'] != 2) throw new ShopException($result['respDesc']);
// 商品兑换豆 到账
(new CulturalSpaceGoodsLegumes())->changeHandle((int)$uid,$buyGoodsNum,1,"易出申请转换",0,['legumes_withdrawal_id' => $id]);
(new CulturalSpaceGoodsLegumes())->changeHandle((int)$uid,$buyGoodsNum,1,"易出申请转换",0,[
'legumes_withdrawal_id' => $id,
'change_money' => $buyGoodsNumMoney
]);
DB::commit();
return $this->successJson('打款成功');

View File

@ -241,6 +241,7 @@ class IndexController extends ApiController{
return $this->successJson('success',[
'voucher_number' => $culturalSpaceInfo->voucher_number,
'goods_legumes' => $culturalSpaceInfo->goods_legumes,
'goods_legumes_money' => $culturalSpaceInfo->goods_legumes_money,
'commission_rate' => $withdrawalCommissionRate,
'task_video_link' => $set['task_video_link']
]);

View File

@ -22,6 +22,7 @@ class OrderPaidListener{
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
'change_money' => $model->use_legumes_price
]);
}
// 订单支付成功奖励贡献值

View File

@ -44,8 +44,10 @@ class CulturalSpaceGoodsLegumes extends BaseModel{
public function changeHandle(int $uid,float $changeNum,int $changeType,string $remark,int $changeSource = 1,array $params = []){
// 获取当前用户持有数量
$changeFront = (float)CulturalSpace::uniacid()->where('uid',$uid)->value('goods_legumes');
$changeFrontMoney = (float)CulturalSpace::uniacid()->where('uid',$uid)->value('goods_legumes_money');
// 变更后的数量
$changeAfter = $changeType == 1 ? $changeFront + $changeNum : $changeFront - $changeNum;
$changeAfterMoney = $changeType == 1 ? $changeFrontMoney + $params['change_money'] : $changeFrontMoney - $params['change_money'];
// 变更记录
$data = [
'uniacid' => \YunShop::app()->uniacid,
@ -61,10 +63,16 @@ class CulturalSpaceGoodsLegumes extends BaseModel{
'remark' => $remark,
'created_at' => time(),// 变更时间
'source' => $changeSource,
'change_quantity_money' => $params['change_money'] ?? 0,// 具体变更金额
'change_front_money' => $changeFrontMoney ?? 0,// 变更前拥有的金额
'change_after_money' => $changeAfterMoney ?? 0,// 变更后拥有的金额
];
$id = $this->insertGetId($data);
// 修改用户持有
CulturalSpace::uniacid()->where('uid',$uid)->update(['goods_legumes' => $changeAfter]);
CulturalSpace::uniacid()->where('uid',$uid)->update([
'goods_legumes' => $changeAfter,
'goods_legumes_money' => $changeAfterMoney,
]);
return $id;
}

View File

@ -95,20 +95,30 @@ class CulturalSpaceLegumesWithdrawal extends BaseModel{
$culturalFund = CulturalFund::uniacid()->first();
$currentFee = $culturalFund->current_fee;
$reality_amount = (float)sprintf("%.2f",$reality_num * $currentFee);// 实际打款数量
// 计算金额
$fund_num_money = (float)sprintf("%.2f",$fund_num * $currentFee );// 基金池部分
$buy_goods_num_money = (float)sprintf("%.2f",$buy_goods_num * $currentFee );// 购物部分
$withdrawal_num_money = (float)sprintf("%.2f",$withdrawal_num * $currentFee );// 易出部分
$commission_num_money = (float)sprintf("%.2f",$commission_num * $currentFee );// 手续费
// 记录
$data = [
'uniacid' => \YunShop::app()->uniacid,
'uid' => $uid,
'withdrawal_total_num' => $totalNum, // 文创豆提现总数
'withdrawal_total_num' => $totalNum, // 文创豆提现总数(豆)
'fund_ratio' => $fundRatio, // 基金池比例
'fund_num' => $fund_num, // 基金池数量
'fund_num' => $fund_num, // 基金池数量(豆)
'fund_num_money' => $fund_num_money, // 基金池数量(元)
'buy_goods_ratio' => $buyGoodsRatio, // 购物豆部分比例
'buy_goods_num' => $buy_goods_num, // 购物豆部分数量
'buy_goods_num' => $buy_goods_num, // 购物豆部分数量(豆)
'buy_goods_num_money' => $buy_goods_num_money, // 购物豆部分数量(元)
'withdrawal_ratio' => $withdrawalRatio, // 易出部分比例
'withdrawal_num' => $withdrawal_num, // 易出数量
'withdrawal_num' => $withdrawal_num, // 易出数量(豆)
'withdrawal_num_money' => $withdrawal_num_money, // 易出数量(元)
'commission_ratio' => $commissionRatio, // 手续费比例
'commission_num' => $commission_num, // 手续费数量
'reality_num' => $reality_num, // 实际易出文创豆
'commission_num' => $commission_num, // 手续费数量(豆)
'commission_num_money' => $commission_num_money, // 手续费数量(元)
'reality_num' => $reality_num, // 实际易出文创豆(豆)
'current_fee' => $currentFee, // 费率
'reality_amount' => $reality_amount, // 实际提现打款数量(元)
'status' => 0, // 审核状态0=待审核1=待打款2=已驳回

View File

@ -61,7 +61,7 @@ class GoodsCulturalSpace extends BaseModel{
$result = self::uniacid()
->select(['id','goods_id','legumes_exchange_price'])
->with(['belongsToGoods'=>function($query){
$query->select(['id','title','thumb']);
$query->select(['id','title','thumb','price']);
}])
->where('is_open',1)
->where('is_legumes_exchange',1)
@ -76,8 +76,9 @@ class GoodsCulturalSpace extends BaseModel{
// 计算需要使用的文创豆
$fundInfo = CulturalFund::getfund();
$currentFee = $fundInfo['current_fee'];
$holdExchangeLegumes = (float)CulturalSpace::uniacid()->where('uid',$uid)->value('goods_legumes');// 当前用户持有的用以兑换商品的文创豆
$data['data'] = array_map(function($item) use ($currentFee,$holdExchangeLegumes){
// $holdExchangeLegumes = (float)CulturalSpace::uniacid()->where('uid',$uid)->value('goods_legumes');// 当前用户持有的用以兑换商品的文创豆
$holdExchangeLegumesMoney = (float)CulturalSpace::uniacid()->where('uid',$uid)->value('goods_legumes_money');// 当前用户持有的兑换额度
$data['data'] = array_map(function($item) use ($currentFee,$holdExchangeLegumesMoney){
// 使用的文创豆
$useLegumes = ceil($item['legumes_exchange_price'] / $currentFee);
$useLegumes = $useLegumes <= 1 ? 1 : $useLegumes;
@ -87,8 +88,9 @@ class GoodsCulturalSpace extends BaseModel{
'legumes_exchange_price' => $item['legumes_exchange_price'],
'goods_title' => $item['belongs_to_goods']['title'],
'goods_thumb' => $item['belongs_to_goods']['thumb'],
'goods_price' => $item['belongs_to_goods']['price'],
'use_legumes' => $useLegumes,
'is_allow_exchange' => (int)$holdExchangeLegumes >= $useLegumes,
'is_allow_exchange' => (int)$holdExchangeLegumesMoney >= $item['legumes_exchange_price'],
];
},$data['data']);

View File

@ -88,29 +88,37 @@
</div>
</template>
</el-table-column>
<el-table-column align="center" prop="withdrawal_total_num" label="易出总数" width="100"></el-table-column>
<el-table-column align="center" label="易出总数" width="100">
<template slot-scope="scope">
[[scope.row.withdrawal_total_num]]
</template>
</el-table-column>
<el-table-column align="center" label="基金池" width="110">
<template slot-scope="scope">
<el-tag type="warning" disable-transitions>[[scope.row.fund_ratio]]%</el-tag>
<el-tag type="success" disable-transitions style="margin-top: 10px;">[[scope.row.fund_num]]</el-tag>
<el-tag type="danger" disable-transitions style="margin-top: 10px;">[[scope.row.fund_num_money]]</el-tag>
</template>
</el-table-column>
<el-table-column align="center" label="易出部分" width="110">
<template slot-scope="scope">
<el-tag type="warning" disable-transitions>[[scope.row.withdrawal_ratio]]%</el-tag>
<el-tag type="success" disable-transitions style="margin-top: 10px;">[[scope.row.withdrawal_num]]</el-tag>
<el-tag type="danger" disable-transitions style="margin-top: 10px;">[[scope.row.withdrawal_num_money]]</el-tag>
</template>
</el-table-column>
<el-table-column align="center" label="购物部分" width="110">
<template slot-scope="scope">
<el-tag type="warning" disable-transitions>[[scope.row.buy_goods_ratio]]%</el-tag>
<el-tag type="success" disable-transitions style="margin-top: 10px;">[[scope.row.buy_goods_num]]</el-tag>
<el-tag type="danger" disable-transitions style="margin-top: 10px;">[[scope.row.buy_goods_num_money]]</el-tag>
</template>
</el-table-column>
<el-table-column align="center" label="手续费" width="110">
<template slot-scope="scope">
<el-tag type="warning" disable-transitions>[[scope.row.commission_ratio]]%</el-tag>
<el-tag type="success" disable-transitions style="margin-top: 10px;">[[scope.row.commission_num]]</el-tag>
<el-tag type="danger" disable-transitions style="margin-top: 10px;">[[scope.row.commission_num_money]]</el-tag>
</template>
</el-table-column>
<el-table-column align="center" prop="current_fee" label="费率" width="80"></el-table-column>