添加:股东分红支持商品单独设置比例
This commit is contained in:
parent
9c88c0fcf2
commit
62a164760b
|
|
@ -24,7 +24,7 @@ class SetController extends BaseController
|
|||
public function fix()
|
||||
{
|
||||
|
||||
// (new TimedTaskService())->shareholderDividendOrder(79);
|
||||
// (new TimedTaskService())->shareholderDividendOrder(21);
|
||||
// 手动触发全网分红处理流程
|
||||
// (new \Yunshop\ShareholderDividend\services\TimedTaskService)->handle();
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ namespace Yunshop\ShareholderDividend\models;
|
|||
use app\common\models\BaseModel;
|
||||
use Yunshop\StoreCashier\common\models\StoreGoods;
|
||||
use Yunshop\StoreCashier\common\models\StoreSetting;
|
||||
use Yunshop\TeamDividend\models\TeamDividendLevelModel;
|
||||
|
||||
class GoodsShareholderDividend extends BaseModel
|
||||
{
|
||||
|
|
@ -48,6 +49,10 @@ class GoodsShareholderDividend extends BaseModel
|
|||
$data['goods_id'] = $goodsId;
|
||||
$data['uniacid'] = \YunShop::app()->uniacid;
|
||||
$data['is_no_count'] = $data['is_no_count'] ?: 0;
|
||||
$data['is_alone'] = $data['is_alone'] ?: 0;
|
||||
$data['alone_rule'] = json_encode((array)$data['alone_rule'],JSON_UNESCAPED_UNICODE);
|
||||
|
||||
|
||||
$dividendModel->setRawAttributes($data);
|
||||
return $dividendModel->save();
|
||||
}
|
||||
|
|
@ -59,6 +64,16 @@ class GoodsShareholderDividend extends BaseModel
|
|||
$model = static::where(['goods_id' => $goodsId])->first();
|
||||
}
|
||||
!$model && $model = new static;
|
||||
|
||||
if($model->alone_rule){
|
||||
$model->alone_rule = json_decode($model->alone_rule,true);
|
||||
}else{
|
||||
$model->alone_rule = TeamDividendLevelModel::uniacid()->select(['id','level_name'])->orderBy('id','DESC')->get()->toArray();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -192,4 +192,117 @@ class CycleAmounyService
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Common: 根据订单 获取实际共分红金额
|
||||
* Author: wu-hui
|
||||
* Time: 2023/12/08 17:05
|
||||
* @param $orderId
|
||||
* @param $method
|
||||
* @param $rate
|
||||
* @param $levelId
|
||||
* @return float|int
|
||||
*/
|
||||
public static function getOrderAmountNew($orderId, $method, $rate, $levelId){
|
||||
$orderGoodsList = OrderGoods::uniacid()
|
||||
->select([
|
||||
'yz_order.price',
|
||||
'yz_order.dispatch_price',
|
||||
'yz_order_goods.id',
|
||||
'yz_order_goods.payment_amount',
|
||||
'yz_order_goods.goods_cost_price',
|
||||
'yz_goods_shareholder_dividend.is_alone',
|
||||
'yz_goods_shareholder_dividend.alone_rule'
|
||||
])
|
||||
->leftJoin('yz_order','yz_order.id','=','yz_order_goods.order_id')
|
||||
->leftJoin('yz_goods_shareholder_dividend','yz_goods_shareholder_dividend.goods_id','=','yz_order_goods.goods_id')
|
||||
->where('yz_order_goods.order_id',$orderId)
|
||||
->where('yz_goods_shareholder_dividend.is_no_count','!=',1)
|
||||
->whereIn('yz_order.status',[Order::WAIT_SEND,Order::WAIT_RECEIVE,Order::COMPLETE]) // 统计已支付-待发货,已支付-待收货,已完成订单
|
||||
->get();
|
||||
if($orderGoodsList) {
|
||||
$orderGoodsList = $orderGoodsList->toArray();
|
||||
return self::computeLvCountOrderAmount($orderGoodsList,$method, $rate, $levelId);
|
||||
}else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Common: 根据周期 获取实际共分红金额
|
||||
* Author: wu-hui
|
||||
* Time: 2023/12/08 17:09
|
||||
* @param $startTime
|
||||
* @param $endTime
|
||||
* @param $method
|
||||
* @param $rate
|
||||
* @param $levelId
|
||||
* @return float|int
|
||||
*/
|
||||
public static function getCycleAmountNew($startTime,$endTime, $method, $rate, $levelId){
|
||||
$orderGoodsList = OrderGoods::uniacid()
|
||||
->select([
|
||||
'yz_order.price',
|
||||
'yz_order.dispatch_price',
|
||||
'yz_order_goods.id',
|
||||
'yz_order_goods.payment_amount',
|
||||
'yz_order_goods.goods_cost_price',
|
||||
'yz_goods_shareholder_dividend.is_alone',
|
||||
'yz_goods_shareholder_dividend.alone_rule'
|
||||
])
|
||||
->leftJoin('yz_order','yz_order.id','=','yz_order_goods.order_id')
|
||||
->leftJoin('yz_goods_shareholder_dividend','yz_goods_shareholder_dividend.goods_id','=','yz_order_goods.goods_id')
|
||||
->whereBetween('yz_order.created_at', [$startTime, $endTime])
|
||||
->where('yz_goods_shareholder_dividend.is_no_count','!=',1)
|
||||
->whereIn('yz_order.status',[Order::WAIT_SEND,Order::WAIT_RECEIVE,Order::COMPLETE]) // 统计已支付-待发货,已支付-待收货,已完成订单
|
||||
->get();
|
||||
if($orderGoodsList) {
|
||||
$orderGoodsList = $orderGoodsList->toArray();
|
||||
return self::computeLvCountOrderAmount($orderGoodsList,$method, $rate, $levelId);
|
||||
}else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Common: 计算 实际使用的分红金额
|
||||
* Author: wu-hui
|
||||
* Time: 2023/12/08 17:05
|
||||
* @param $orderGoodsList
|
||||
* @param $method
|
||||
* @param $rate
|
||||
* @param $levelId
|
||||
* @return float|int
|
||||
*/
|
||||
private static function computeLvCountOrderAmount($orderGoodsList, $method, $rate, $levelId){
|
||||
$TotalMoney = 0;
|
||||
foreach($orderGoodsList as $orderGoodsInfo){
|
||||
// 获取使用金额
|
||||
if ($method) {
|
||||
$useMoney = $orderGoodsInfo['payment_amount'] - $orderGoodsInfo['goods_cost_price'];
|
||||
} else {
|
||||
$orderRate = $orderGoodsInfo['payment_amount'] / $orderGoodsInfo['price'];
|
||||
$useMoney = $orderGoodsInfo['payment_amount'] - ($orderGoodsInfo['dispatch_price'] * $orderRate);
|
||||
}
|
||||
// 获取实际金额
|
||||
if($orderGoodsInfo['is_alone']){
|
||||
// 独立设置
|
||||
$aloneRule = json_decode($orderGoodsInfo['alone_rule'],true);
|
||||
$aloneRule = array_column($aloneRule,'ratio','id');
|
||||
$aloneRate = (float)$aloneRule[$levelId];
|
||||
$TotalMoney += (float)sprintf("%.2f", $useMoney / 100 * $aloneRate);
|
||||
}else{
|
||||
// 非独立设置
|
||||
$TotalMoney += (float)sprintf("%.2f", $useMoney / 100 * $rate);
|
||||
}
|
||||
}
|
||||
|
||||
return $TotalMoney;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -42,6 +42,9 @@ class TimedTaskService
|
|||
public $set;
|
||||
public $setLog;
|
||||
|
||||
public $startTime;
|
||||
public $endTime;
|
||||
|
||||
/**
|
||||
* 股东分红入口
|
||||
*/
|
||||
|
|
@ -59,7 +62,7 @@ class TimedTaskService
|
|||
Setting::$uniqueAccountId = \YunShop::app()->uniacid = $u->uniacid;
|
||||
$this->set = Setting::get('plugin.shareholder');
|
||||
$this->setLog = Setting::get('plugin.shareholder_log');
|
||||
$is_execute = $this->isExecute();
|
||||
$is_execute = true;//$this->isExecute();
|
||||
if ($is_execute) {
|
||||
\Log::info('========股东分红UNIACID:' . $u->uniacid . '执行========');
|
||||
$this->setLog['current_d'] = date('d');
|
||||
|
|
@ -287,16 +290,33 @@ class TimedTaskService
|
|||
}
|
||||
// 股东分红 - 每个周期进行结算
|
||||
private function shareholderDividendV2(){
|
||||
$orderAmount = CycleAmounyService::getCycleAmount($this->set['culate_cycle'], $this->set['culate_method']); // 上一个周期金额
|
||||
if ($orderAmount <= 0) {
|
||||
\Log::info('========shareholderDividend():没有返现总金额');
|
||||
ExceptionLog::create([
|
||||
'uniacid' => \YunShop::app()->uniacid,
|
||||
'comment' => '没有返现总金额',
|
||||
'time' => date('Y-m-d H:i:s', time())
|
||||
]);
|
||||
return;
|
||||
|
||||
switch ($this->set['culate_cycle']) {
|
||||
case 0:
|
||||
$this->endTime = strtotime(Carbon::today()->toDateTimeString());
|
||||
$this->startTime = strtotime(Carbon::yesterday()->toDateTimeString());
|
||||
break;
|
||||
case 1:
|
||||
$this->endTime = strtotime(Carbon::today()->toDateTimeString());
|
||||
$this->startTime = Carbon::today()->modify('-1 week')->timestamp;
|
||||
break;
|
||||
case 2:
|
||||
$this->endTime = Carbon::now()->startOfMonth()->timestamp;
|
||||
$this->startTime = Carbon::now()->modify('-1 month')->startOfMonth()->timestamp;
|
||||
break;
|
||||
}
|
||||
|
||||
// $orderAmount = CycleAmounyService::getCycleAmount($this->set['culate_cycle'], $this->set['culate_method']); // 上一个周期金额
|
||||
// if ($orderAmount <= 0) {
|
||||
// \Log::info('========shareholderDividend():没有返现总金额');
|
||||
// ExceptionLog::create([
|
||||
// 'uniacid' => \YunShop::app()->uniacid,
|
||||
// 'comment' => '没有返现总金额',
|
||||
// 'time' => date('Y-m-d H:i:s', time())
|
||||
// ]);
|
||||
// return;
|
||||
// }
|
||||
$orderAmount = 0;
|
||||
$this->shareholderDividendHandle($orderAmount);
|
||||
}
|
||||
// 股东分红 - 订单支付成功后进行结算
|
||||
|
|
@ -304,16 +324,17 @@ class TimedTaskService
|
|||
\Log::debug('--- 股东分红 - 订单支付成功后进行结算 ----',$orderId);
|
||||
$this->set = Setting::get('plugin.shareholder');
|
||||
// 获取信息
|
||||
$orderAmount = CycleAmounyService::getOrderAmount($orderId, $this->set['culate_method']);
|
||||
if ($orderAmount <= 0) {
|
||||
\Log::info('========shareholderDividend():没有返现总金额');
|
||||
ExceptionLog::create([
|
||||
'uniacid' => \YunShop::app()->uniacid,
|
||||
'comment' => '没有返现总金额',
|
||||
'time' => date('Y-m-d H:i:s', time())
|
||||
]);
|
||||
return;
|
||||
}
|
||||
// $orderAmount = CycleAmounyService::getOrderAmount($orderId, $this->set['culate_method']);
|
||||
// if ($orderAmount <= 0) {
|
||||
// \Log::info('========shareholderDividend():没有返现总金额');
|
||||
// ExceptionLog::create([
|
||||
// 'uniacid' => \YunShop::app()->uniacid,
|
||||
// 'comment' => '没有返现总金额',
|
||||
// 'time' => date('Y-m-d H:i:s', time())
|
||||
// ]);
|
||||
// return;
|
||||
// }
|
||||
$orderAmount = 0;
|
||||
$this->shareholderDividendHandle($orderAmount,'order',$orderId);
|
||||
}
|
||||
// 股东分红 - 统一处理
|
||||
|
|
@ -355,7 +376,19 @@ class TimedTaskService
|
|||
}
|
||||
$teamAgentCount = $teamAgents->count(); // 同等级代理人数
|
||||
$teamAgentsList = $teamAgents->get();
|
||||
$lvCountOrderAmount = sprintf("%.2f", $orderAmount / 100 * $rate);// 当前等级共分红金额
|
||||
// 当前等级共分红金额
|
||||
$lvCountOrderAmount = 0;
|
||||
if($settlementType == 'order'){
|
||||
// 根据订单查询
|
||||
$lvCountOrderAmount = (float)CycleAmounyService::getOrderAmountNew($orderId, $this->set['culate_method'],$rate,$teamLevel['id']);
|
||||
}else{
|
||||
// 根据周期查询
|
||||
$lvCountOrderAmount = (float)CycleAmounyService::getCycleAmountNew($this->startTime,$this->endTime, $this->set['culate_method'],$rate,$teamLevel['id']);
|
||||
}
|
||||
// 共分红金额 为0 跳出循环
|
||||
if($lvCountOrderAmount <= 0) continue;
|
||||
|
||||
// $lvCountOrderAmount = sprintf("%.2f", $orderAmount / 100 * $rate);
|
||||
// 获取当前等级的全部权重值
|
||||
foreach ($teamAgentsList as $item) {
|
||||
/********* 权重值相关操作 START ***************************************************/
|
||||
|
|
|
|||
|
|
@ -15,7 +15,35 @@ define({
|
|||
<el-radio v-model="is_no_count" :label="1">否</el-radio>
|
||||
<el-radio v-model="is_no_count" :label="0">是</el-radio>
|
||||
</el-form-item>
|
||||
|
||||
<template v-if="!is_no_count">
|
||||
<el-form-item label="是否开启独立规则" label-width="200px">
|
||||
<el-radio v-model="is_alone" :label="0">不开启</el-radio>
|
||||
<el-radio v-model="is_alone" :label="1">开启</el-radio>
|
||||
</el-form-item>
|
||||
<el-form-item v-show="is_alone">
|
||||
<el-row :gutter="20" class="gutter">
|
||||
<el-col :span="6">
|
||||
<div class="grid-content bg-purple">经销商等级</div>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<div class="grid-content bg-purple">分红金额比例</div>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row :gutter="20" class="gutter" v-for="(level, index) in alone_rule" :key="index">
|
||||
<el-col :span="6">
|
||||
<div class="grid-content bg-purple">{{level.level_name}}</div>
|
||||
</el-col>
|
||||
<el-col :span="12" class="flex-col">
|
||||
<el-col :span="10">
|
||||
<el-input placeholder="请输入百分比" v-model.number="level.ratio" step="0.01" maxlength="10" size="small" type="number">
|
||||
<template slot="append">%</template>
|
||||
</el-input>
|
||||
</el-col>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-form-item>
|
||||
</template>
|
||||
|
||||
<el-divider></el-divider>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -44,19 +72,27 @@ define({
|
|||
},
|
||||
data(){
|
||||
return {
|
||||
is_no_count: 1, // 1否 0是
|
||||
is_no_count: 1, // 1否 0是
|
||||
is_alone: 0,
|
||||
alone_rule: {},
|
||||
}
|
||||
},
|
||||
mounted () {
|
||||
if (this.form.item && !Array.isArray(this.form.item)) {
|
||||
this.is_no_count = this.form.item.is_no_count;
|
||||
this.is_alone = this.form.item.is_alone;
|
||||
this.alone_rule = this.form.item.alone_rule;
|
||||
}
|
||||
|
||||
console.log(this.form);
|
||||
},
|
||||
|
||||
methods: {
|
||||
validate () {
|
||||
return {
|
||||
is_no_count: this.is_no_count,
|
||||
is_alone: this.is_alone,
|
||||
alone_rule: this.alone_rule,
|
||||
}
|
||||
},
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in New Issue