From 4ba9d5c48c995d2e9e52f66168490adbd5eb4662 Mon Sep 17 00:00:00 2001 From: fengxinyhyl Date: Sun, 17 Mar 2024 22:20:11 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A1=E7=AE=97=E9=A1=B9=E7=9B=AE=E7=BB=8F?= =?UTF-8?q?=E7=90=86=E7=9A=84=E6=95=B0=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/UserAssetsLogRepository.php | 242 +++++++++++++++--- 1 file changed, 208 insertions(+), 34 deletions(-) diff --git a/app/common/repositories/user/UserAssetsLogRepository.php b/app/common/repositories/user/UserAssetsLogRepository.php index 9c6a6eb..3660f48 100644 --- a/app/common/repositories/user/UserAssetsLogRepository.php +++ b/app/common/repositories/user/UserAssetsLogRepository.php @@ -98,25 +98,25 @@ class UserAssetsLogRepository extends BaseRepository * @editor * * {"name":"福利积分--项目经理", "value":10, "key":"welfare_project"} - {"name":"福利积分--一星经理", "value":30, "key":"welfare_project_1"} - {"name":"福利积分--二星经理", "value":50, "key":"welfare_project_2"} - {"name":"福利积分--三星经理", "value":80, "key":"welfare_project_3"} - {"name":"贡献值--用户", "value":1, "key":"contribution_user"} - {"name":"贡献值--项目经理", "value":1, "key":"contribution_project"} - {"name":"贡献值--一星经理", "value":2, "key":"contribution_project_1"} - {"name":"贡献值--二星经理", "value":3, "key":"contribution_project_2"} - {"name":"贡献值--三星经理", "value":4, "key":"contribution_project_3"} - {"name":"惠通宝--用户", "value":5, "key":"huitong_user"} - {"name":"惠通宝--项目经理", "value":10, "key":"huitong_project"} - {"name":"惠通宝--一星经理", "value":30, "key":"huitong_project_1"} - {"name":"惠通宝--二星经理", "value":50, "key":"huitong_project_2"} - {"name":"惠通宝--三星经理", "value":80, "key":"huitong_project_3"} - {"name":"福利积分--区域代理--区域代理奖", "value":1, "key":"welfare_agent"} - {"name":"福利积分--区域代理--推荐商家奖", "value":1, "key":"welfare_agent_recommend"} - {"name":"福利积分--项目经理--推荐商家奖", "value":1, "key":"welfare_project_recommend"} - {"name":"福利积分--商户--推荐商家奖", "value":1, "key":"welfare_merchat_recommend"} - {"name":"惠通宝增值幅度比例配置", "value":10, "key":"huitong_add"} - {"name":"福利积分--存在分红点用户奖励", "value":10, "key":"share_award"} + * {"name":"福利积分--一星经理", "value":30, "key":"welfare_project_1"} + * {"name":"福利积分--二星经理", "value":50, "key":"welfare_project_2"} + * {"name":"福利积分--三星经理", "value":80, "key":"welfare_project_3"} + * {"name":"贡献值--用户", "value":1, "key":"contribution_user"} + * {"name":"贡献值--项目经理", "value":1, "key":"contribution_project"} + * {"name":"贡献值--一星经理", "value":2, "key":"contribution_project_1"} + * {"name":"贡献值--二星经理", "value":3, "key":"contribution_project_2"} + * {"name":"贡献值--三星经理", "value":4, "key":"contribution_project_3"} + * {"name":"惠通宝--用户", "value":5, "key":"huitong_user"} + * {"name":"惠通宝--项目经理", "value":10, "key":"huitong_project"} + * {"name":"惠通宝--一星经理", "value":30, "key":"huitong_project_1"} + * {"name":"惠通宝--二星经理", "value":50, "key":"huitong_project_2"} + * {"name":"惠通宝--三星经理", "value":80, "key":"huitong_project_3"} + * {"name":"福利积分--区域代理--区域代理奖", "value":1, "key":"welfare_agent"} + * {"name":"福利积分--区域代理--推荐商家奖", "value":1, "key":"welfare_agent_recommend"} + * {"name":"福利积分--项目经理--推荐商家奖", "value":1, "key":"welfare_project_recommend"} + * {"name":"福利积分--商户--推荐商家奖", "value":1, "key":"welfare_merchat_recommend"} + * {"name":"惠通宝增值幅度比例配置", "value":10, "key":"huitong_add"} + * {"name":"福利积分--存在分红点用户奖励", "value":10, "key":"share_award"} */ public function userPayEvent($groupOrder) { @@ -125,7 +125,7 @@ class UserAssetsLogRepository extends BaseRepository $config = array_column($config['list'], "value", 'key'); foreach ($groupOrder['orderList'] as $orderItem) { - $base = 0; + $base = 0; foreach ($orderItem['orderProduct'] as $orderProduct) { // 获取商品详情(奖励积分 $product = $this->productRepository->detail($orderProduct['product_id'], null); @@ -139,10 +139,166 @@ class UserAssetsLogRepository extends BaseRepository // 1. 用户资产 $this->userAssets($orderItem, $config, $base); + // 2. 项目经理资产 + if ($base) { + $startProjectUid = $this->projectAssets($orderItem, $config, $base); + // 3. 培育经理资产 + $this->breedAssets($startProjectUid, $orderItem['order_id'], $config, $base); + + } } } + /** + * notes + * @param $startProjectUid + * @param $orderId + * @param $config + * @param $base + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + * @create 2024/3/17 19:32 + * @update 2024/3/17 19:32 + * @author zhangkxiang + * @editor + */ + public function breedAssets($startProjectUid, $orderId, $config, $base) + { + $consume = 0; + $userRepository = app(UserRepository::class); + $userProject = $userRepository->get($startProjectUid); + if (empty($userProject)) { + return; + } + + if ($userProject['group_id'] > 4 or $userProject['group_id'] <= 1) { + return; + } + $group = $userProject['group_id'] - 1; + + // 1. 项目经理的福利积分 + $orderWelfare = round($base * $config['welfare_project'] * $config['welfare_project_' . $group] / 10000, 2); + $welfare = $this->_getValue($orderWelfare); + $logList[] = array( + 'uid' => $userProject['uid'], + 'asset_type' => self::ASSET_TYPE_WELFARE, + 'type' => self::CHANGE_TYPE_ORDER_GET, + 'status' => self::STATUS_FROZEN, + 'order_id' => $orderId, + 'count' => $welfare, + ); + + // 2. 项目经理的惠通宝 + $orderHuitong = round($base * $config['huitong_project'] * $config['huitong_project_' . $group] / 10000, 2); + $huitong = $this->_getValue($orderHuitong); + $logList[] = array( + 'uid' => $userProject['uid'], + 'asset_type' => self::ASSET_TYPE_HUITONG, + 'type' => self::CHANGE_TYPE_ORDER_GET, + 'status' => self::STATUS_FROZEN, + 'order_id' => $orderId, + 'count' => $huitong, + ); + + // 3. 项目经理的贡献值 + $orderContribution = round($base * $config['contribution_project'] * $config['contribution_project_' . $group] / 10000, 2); + $contribution = $this->_getValue($orderContribution); + $logList[] = array( + 'uid' => $userProject['uid'], + 'asset_type' => self::ASSET_TYPE_CONTRIBUTION, + 'type' => self::CHANGE_TYPE_ORDER_GET, + 'status' => self::STATUS_FROZEN, + 'order_id' => $orderId, + 'count' => $contribution, + ); + $this->addLog($logList); + $this->userAssetsRepository->orderEvent($userProject['uid'], self::STATUS_FROZEN, compact('consume', 'welfare', 'huitong', 'contribution')); + } + + + /** + * notes + * @param $orderItem + * @param $config + * @param $base + * @create 2024/3/17 19:32 + * @update 2024/3/17 19:32 + * @author zhangkxiang + * @editor + */ + public function projectAssets($orderItem, $config, $base) + { + $consume = 0; + $uid = $orderItem['uid']; + $orderId = $orderItem['order_id']; + $userProject = null; + $userRepository = app(UserRepository::class); + $user = $userRepository->get($uid); + if (empty($user)) { + return 0; + } + + // 查找第一个项目经理 + while (!$userProject) { + $user = $userRepository->get($user['spread_uid']); + if (empty($user)) { + return 0; + } + + if ($user['group_id']) { + $userProject = $user; + } + } + + if (empty($userProject)) { + return 0; + } + + $logList = array(); + + // 1. 项目经理的福利积分 + $orderWelfare = round($base * $config['welfare_project'] / 100, 2); + $welfare = $this->_getValue($orderWelfare); + $logList[] = array( + 'uid' => $userProject['uid'], + 'asset_type' => self::ASSET_TYPE_WELFARE, + 'type' => self::CHANGE_TYPE_ORDER_GET, + 'status' => self::STATUS_FROZEN, + 'order_id' => $orderId, + 'count' => $welfare, + ); + + // 2. 项目经理的惠通宝 + $orderHuitong = round($base * $config['huitong_project'] / 100, 2); + $huitong = $this->_getValue($orderHuitong); + $logList[] = array( + 'uid' => $userProject['uid'], + 'asset_type' => self::ASSET_TYPE_HUITONG, + 'type' => self::CHANGE_TYPE_ORDER_GET, + 'status' => self::STATUS_FROZEN, + 'order_id' => $orderId, + 'count' => $huitong, + ); + + // 3. 项目经理的贡献值 + $orderContribution = round($base * $config['contribution_project'] / 100, 2); + $contribution = $this->_getValue($orderContribution); + $logList[] = array( + 'uid' => $userProject['uid'], + 'asset_type' => self::ASSET_TYPE_CONTRIBUTION, + 'type' => self::CHANGE_TYPE_ORDER_GET, + 'status' => self::STATUS_FROZEN, + 'order_id' => $orderId, + 'count' => $contribution, + ); + $this->addLog($logList); + $this->userAssetsRepository->orderEvent($userProject['uid'], self::STATUS_FROZEN, compact('consume', 'welfare', 'huitong', 'contribution')); + return $userProject['spread_uid']; + } + + /** * notes 用户资产变动 * @param $orderItem @@ -156,7 +312,8 @@ class UserAssetsLogRepository extends BaseRepository * @author zhangkxiang * @editor */ - public function userAssets($orderItem, $config, $base){ + public function userAssets($orderItem, $config, $base) + { $logList = array(); $welfare = $huitong = $contribution = 0; @@ -169,50 +326,67 @@ class UserAssetsLogRepository extends BaseRepository 'order_id' => $orderItem['order_id'], 'count' => $orderItem['pay_price'], ); - $consume = $orderItem['pay_price']; + $consume = $orderItem['pay_price']; // 如果该订单奖励基数大于0 - if($base){ + if ($base) { // 2. 本人的福利积分 $orderWelfare = round($base * 0.1, 2); - $welfare = $orderWelfare; - $logList[] = array( + $welfare = $this->_getValue($orderWelfare); + $logList[] = array( 'uid' => $orderItem['uid'], 'asset_type' => self::ASSET_TYPE_WELFARE, 'type' => self::CHANGE_TYPE_ORDER_GET, 'status' => self::STATUS_FROZEN, 'order_id' => $orderItem['order_id'], - 'count' => $orderWelfare, + 'count' => $welfare, ); // 3. 本人的惠通宝 - $orderHuitong = round($base * $config['huitong_user'] /100, 2); - $huitong = $orderHuitong; - $logList[] = array( + $orderHuitong = round($base * $config['huitong_user'] / 100, 2); + $huitong = $this->_getValue($orderHuitong); + $logList[] = array( 'uid' => $orderItem['uid'], 'asset_type' => self::ASSET_TYPE_HUITONG, 'type' => self::CHANGE_TYPE_ORDER_GET, 'status' => self::STATUS_FROZEN, 'order_id' => $orderItem['order_id'], - 'count' => $orderHuitong, + 'count' => $huitong, ); // 4. 本人的贡献值 - $orderContribution = round($base * $config['contribution_user']/100, 2); - $contribution = $orderContribution; - $logList[] = array( + $orderContribution = round($base * $config['contribution_user'] / 100, 2); + $contribution = $this->_getValue($orderContribution); + $logList[] = array( 'uid' => $orderItem['uid'], 'asset_type' => self::ASSET_TYPE_CONTRIBUTION, 'type' => self::CHANGE_TYPE_ORDER_GET, 'status' => self::STATUS_FROZEN, 'order_id' => $orderItem['order_id'], - 'count' => $orderContribution, + 'count' => $contribution, ); } $this->addLog($logList); $this->userAssetsRepository->orderEvent($orderItem['uid'], self::STATUS_FROZEN, compact('consume', 'welfare', 'huitong', 'contribution')); } + + private function _getValue($value){ + if($value < 0.01){ + return 0.01; + } + return $value; + } + + + /** + * notes 插入变动日志,如果小于0.01则插入0.01 + * @param $list + * @create 2024/3/17 22:09 + * @update 2024/3/17 22:09 + * @author zhangkxiang + * @editor + */ public function addLog($list) { $this->dao->insertAll($list);