From c82b023545dfe6cc89b97d8ce81f230d239e301c Mon Sep 17 00:00:00 2001 From: wuhui_zzw <1760308791@qq.com> Date: Thu, 4 Jan 2024 18:08:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E4=BD=A3=E9=87=91?= =?UTF-8?q?=E6=8F=90=E7=8E=B0=E8=AE=A1=E7=AE=97=E9=94=99=E8=AF=AF=EF=BC=8C?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E6=8F=90=E7=8E=B0=E5=90=8E=E5=8F=AF=E8=83=BD?= =?UTF-8?q?=E4=BC=9A=E5=A2=9E=E5=8A=A0=E5=89=A9=E4=BD=99=E5=8F=AF=E6=8F=90?= =?UTF-8?q?=E7=8E=B0=E4=BD=A3=E9=87=91=E6=95=B0=E9=87=8F=E7=9A=84=E4=BD=A3?= =?UTF-8?q?=E9=87=91=20=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=8F=90=E7=8E=B0?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E7=9A=84=E4=BD=A3=E9=87=91=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/dao/user/UserBillDao.php | 23 ++++++++++----- app/common/model/user/User.php | 13 +++++++-- .../order/PointsOrderCreateRepository.php | 6 +++- .../PartnerSettlementCycleRepository.php | 2 ++ .../repositories/user/UserBillRepository.php | 28 +++++++++++++++++++ .../user/UserExtractRepository.php | 6 +++- 6 files changed, 66 insertions(+), 12 deletions(-) diff --git a/app/common/dao/user/UserBillDao.php b/app/common/dao/user/UserBillDao.php index b28a5a0..1d90ef5 100644 --- a/app/common/dao/user/UserBillDao.php +++ b/app/common/dao/user/UserBillDao.php @@ -123,17 +123,23 @@ class UserBillDao extends BaseDao foreach($lst as $bill){ $refundPrice = bcadd($refundPrice,$bill['number'],2); } - // 招商佣金&推广员佣金 + + return $refundPrice; + /* // 招商佣金&推广员佣金 $commissionList = UserBill::getDB()->where('category', 'brokerage') ->whereIn('type', ['commission_merchants','commission_promoter']) ->where('uid', $uid) + ->where('pm', 1) ->where('status', 0) ->field('link_id,number') ->select() ->toArray(); $commissionRefundPrice = 0; - if (count($lst)) { - $commissionRefundPrice = -1 * UserBill::getDB()->whereIn('link_id', array_column($lst, 'link_id'))->where('uid', $uid) + if (count($commissionList)) { + $commissionRefundPrice = -1 * UserBill::getDB() + ->whereIn('link_id', array_column($commissionList, 'link_id')) + ->where('uid', $uid) + ->where('pm', 0) ->where('category', 'brokerage') ->whereIn('type', ['commission_merchants', 'commission_promoter']) ->sum('number'); @@ -146,13 +152,16 @@ class UserBillDao extends BaseDao ->where('category', 'brokerage') ->whereIn('type', ['commission_partner']) ->where('uid', $uid) + ->where('pm', 1) ->where('status', 0) ->field('link_id,number') ->select() ->toArray(); $commissionPartnerRefundPrice = 0; - if (count($lst)) { - $commissionPartnerRefundPrice = -1 * UserBill::getDB()->whereIn('link_id', array_column($lst, 'link_id')) + if (count($commissionPartnerList)) { + $commissionPartnerRefundPrice = -1 * UserBill::getDB() + ->whereIn('link_id', array_column($commissionPartnerList, 'link_id')) + ->where('pm', 0) ->where('uid', $uid) ->where('category', 'brokerage') ->whereIn('type', ['commission_partner']) @@ -160,10 +169,10 @@ class UserBillDao extends BaseDao } foreach ($commissionPartnerList as $billThree) { $commissionPartnerRefundPrice = bcadd($commissionPartnerRefundPrice, $billThree['number'], 2); - } + }*/ - return (float)sprintf("%.2f",(float)$refundPrice + (float)$commissionRefundPrice + (float)$commissionPartnerList); + // return (float)sprintf("%.2f",(float)$refundPrice + (float)$commissionRefundPrice + (float)$commissionPartnerList); } public function lockIntegral($uid = null, $order_id = null) diff --git a/app/common/model/user/User.php b/app/common/model/user/User.php index 23d9a76..7586abd 100644 --- a/app/common/model/user/User.php +++ b/app/common/model/user/User.php @@ -230,9 +230,16 @@ class User extends BaseModel return app()->make(UserBillRepository::class)->totalBrokerage($this->uid) ?: 0; } - public function getTotalBrokeragePriceAttr() - { - return bcadd($this->lock_brokerage, $this->brokerage_price, 2); + public function getBrokeragePriceAttr($value){ + // 添加:合伙人佣金、招商佣金、推广佣金 + $PlatformCommissionMoney = app()->make(UserBillRepository::class)->getPlatformCommissionMoney($this->uid); + + // debug([$value,$PlatformCommissionMoney]); + return (float)sprintf("%.2f",$value + $PlatformCommissionMoney); + } + + public function getTotalBrokeragePriceAttr(){ + return (float)bcadd($this->lock_brokerage, $this->brokerage_price, 2); } public function getTotalIntegralAttr() diff --git a/app/common/repositories/store/order/PointsOrderCreateRepository.php b/app/common/repositories/store/order/PointsOrderCreateRepository.php index b64c78b..4607c94 100644 --- a/app/common/repositories/store/order/PointsOrderCreateRepository.php +++ b/app/common/repositories/store/order/PointsOrderCreateRepository.php @@ -269,7 +269,11 @@ class PointsOrderCreateRepository if (!$orderInfo['address']['province_id']) throw new ValidateException('请完善收货地址信息'); if (!$orderInfo['order_delivery_status']) throw new ValidateException('部分商品配送方式不一致,请单独下单'); if ($orderInfo['order_total_price'] > 1000000) throw new ValidateException('支付金额超出最大限制'); - if ($orderInfo['order_total_integral'] > $user->integral) throw new ValidateException('积分不足'); + // if ($orderInfo['order_total_integral'] > $user->integral) throw new ValidateException('积分不足'); + + $hold_legumes_integral = app()->make(LegumesLogRepository::class)->getHoldLegumesIntegral((int)$user->uid); + if ($orderInfo['order_total_integral'] > $hold_legumes_integral) throw new ValidateException('积分不足'); + $merchantCartList = $orderInfo['order']; $address =$orderInfo['address']; $user_address = isset($address) ? ($address['province'] . $address['city'] . $address['district'] . $address['street'] . $address['detail']) : ''; diff --git a/app/common/repositories/store/platformCommission/PartnerSettlementCycleRepository.php b/app/common/repositories/store/platformCommission/PartnerSettlementCycleRepository.php index 1b53a18..3d2195d 100644 --- a/app/common/repositories/store/platformCommission/PartnerSettlementCycleRepository.php +++ b/app/common/repositories/store/platformCommission/PartnerSettlementCycleRepository.php @@ -59,6 +59,8 @@ class PartnerSettlementCycleRepository extends BaseRepository{ if($this->set['commission_partner_cycle'] == 1) [$this->startTime,$this->endTime] = getTimeStamp('last_week');// 周 else if($this->set['commission_partner_cycle'] == 2) [$this->startTime,$this->endTime] = getTimeStamp('last_month');// 月 else [$this->startTime,$this->endTime] = getTimeStamp('yesterday');// 天 + + // [$this->startTime,$this->endTime] = getTimeStamp('today');// 测试使用 // 判断:是否允许执行 $this->settlementIsRun(); // 佣金分红计算并且记录 diff --git a/app/common/repositories/user/UserBillRepository.php b/app/common/repositories/user/UserBillRepository.php index ded28d4..d26214c 100644 --- a/app/common/repositories/user/UserBillRepository.php +++ b/app/common/repositories/user/UserBillRepository.php @@ -8,6 +8,7 @@ namespace app\common\repositories\user; use app\common\dao\BaseDao; use app\common\dao\user\UserBillDao; +use app\common\model\user\UserBill; use app\common\repositories\BaseRepository; use app\common\repositories\store\product\ProductRepository; use crmeb\jobs\SendSmsJob; @@ -264,6 +265,33 @@ class UserBillRepository extends BaseRepository ], ]; } + /** + * Common: 获取用户实际获得的可用合伙人佣金、推广佣金、招商佣金(已解冻) + * Author: wu-hui + * Time: 2024/01/04 18:00 + * @param $uid + * @return float + */ + public function getPlatformCommissionMoney($uid){ + // 获得佣金 + $increaseMoney = (float)UserBill::getDB()->where('category', 'brokerage') + ->whereIn('type', ['commission_merchants','commission_promoter', 'commission_partner']) + ->where('uid', $uid) + ->where('pm', 1) + ->where('status', 1) + ->field('link_id,number') + ->sum('number'); + // 退款减少佣金 + $reduceMoney = (float)UserBill::getDB()->where('category', 'brokerage') + ->whereIn('type', ['commission_merchants','commission_promoter', 'commission_partner']) + ->where('uid', $uid) + ->where('pm', 0) + ->where('status', 1) + ->field('link_id,number') + ->sum('number'); + // 实际获得佣金 + return (float)sprintf("%.2f", $increaseMoney - $reduceMoney); + } } diff --git a/app/common/repositories/user/UserExtractRepository.php b/app/common/repositories/user/UserExtractRepository.php index f58d376..d54f06c 100644 --- a/app/common/repositories/user/UserExtractRepository.php +++ b/app/common/repositories/user/UserExtractRepository.php @@ -108,7 +108,11 @@ class UserExtractRepository extends BaseRepository if(!$openid) throw new ValidateException('openID获取失败,请确认是微信用户'); } } - $brokerage_price = bcsub($user['brokerage_price'],$data['extract_price'],2); + // 由于 佣金包含平台抽成相关佣金 需要减去相关佣金,然后计算。否则会出现问题 + $PlatformCommissionMoney = app()->make(UserBillRepository::class)->getPlatformCommissionMoney($user['uid']); + $brokeragePrice = bcsub($user['brokerage_price'],$PlatformCommissionMoney,2); + $brokerage_price = bcsub($brokeragePrice,$data['extract_price'],2); + // debug($brokerage_price); $user->brokerage_price = $brokerage_price; $user->save();