From 62a164760bb9a0d8276829abc00233afedb3a79d Mon Sep 17 00:00:00 2001
From: wuhui_zzw <1760308791@qq.com>
Date: Fri, 8 Dec 2023 17:19:02 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=9A=E8=82=A1=E4=B8=9C?=
=?UTF-8?q?=E5=88=86=E7=BA=A2=E6=94=AF=E6=8C=81=E5=95=86=E5=93=81=E5=8D=95?=
=?UTF-8?q?=E7=8B=AC=E8=AE=BE=E7=BD=AE=E6=AF=94=E4=BE=8B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../src/admin/SetController.php | 2 +-
.../src/models/GoodsShareholderDividend.php | 15 +++
.../src/services/CycleAmounyService.php | 113 ++++++++++++++++++
.../src/services/TimedTaskService.php | 75 ++++++++----
.../views/widget/profit/shareholderProfit.js | 40 ++++++-
5 files changed, 221 insertions(+), 24 deletions(-)
diff --git a/plugins/shareholder-dividend/src/admin/SetController.php b/plugins/shareholder-dividend/src/admin/SetController.php
index 566ec6a4..94acab11 100644
--- a/plugins/shareholder-dividend/src/admin/SetController.php
+++ b/plugins/shareholder-dividend/src/admin/SetController.php
@@ -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();
diff --git a/plugins/shareholder-dividend/src/models/GoodsShareholderDividend.php b/plugins/shareholder-dividend/src/models/GoodsShareholderDividend.php
index b5b293fe..4631621a 100644
--- a/plugins/shareholder-dividend/src/models/GoodsShareholderDividend.php
+++ b/plugins/shareholder-dividend/src/models/GoodsShareholderDividend.php
@@ -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;
}
diff --git a/plugins/shareholder-dividend/src/services/CycleAmounyService.php b/plugins/shareholder-dividend/src/services/CycleAmounyService.php
index 3e1043c1..9282caff 100644
--- a/plugins/shareholder-dividend/src/services/CycleAmounyService.php
+++ b/plugins/shareholder-dividend/src/services/CycleAmounyService.php
@@ -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;
+ }
+
+
+
+
+
+
+
}
\ No newline at end of file
diff --git a/plugins/shareholder-dividend/src/services/TimedTaskService.php b/plugins/shareholder-dividend/src/services/TimedTaskService.php
index 827005d2..8a2e5acd 100644
--- a/plugins/shareholder-dividend/src/services/TimedTaskService.php
+++ b/plugins/shareholder-dividend/src/services/TimedTaskService.php
@@ -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 ***************************************************/
diff --git a/plugins/shareholder-dividend/views/widget/profit/shareholderProfit.js b/plugins/shareholder-dividend/views/widget/profit/shareholderProfit.js
index 0ee3092e..f7598fc4 100644
--- a/plugins/shareholder-dividend/views/widget/profit/shareholderProfit.js
+++ b/plugins/shareholder-dividend/views/widget/profit/shareholderProfit.js
@@ -15,7 +15,35 @@ define({
否
是
-
+
+
+ 不开启
+ 开启
+
+
+
+
+ 经销商等级
+
+
+ 分红金额比例
+
+
+
+
+ {{level.level_name}}
+
+
+
+
+ %
+
+
+
+
+
+
+
@@ -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,
}
},
},