From cc49abc76c26539a97ecfe43d447849ab9a56594 Mon Sep 17 00:00:00 2001 From: fengxinyhyl Date: Sun, 17 Mar 2024 17:08:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=90=A5=E9=94=80=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=EF=BC=8C=E4=BC=98=E5=8C=96=E8=B5=84=E4=BA=A7=E8=8E=B7?= =?UTF-8?q?=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/dao/store/product/SpuDao.php | 12 ++ .../user/UserAssetsLogRepository.php | 158 ++++++++++++------ app/controller/api/store/product/StoreSpu.php | 6 +- app/event.php | 2 +- config/log.php | 2 +- crmeb/listens/AppEnd.php | 22 +++ 6 files changed, 145 insertions(+), 57 deletions(-) create mode 100644 crmeb/listens/AppEnd.php diff --git a/app/common/dao/store/product/SpuDao.php b/app/common/dao/store/product/SpuDao.php index 542dbc5..31dbdd6 100644 --- a/app/common/dao/store/product/SpuDao.php +++ b/app/common/dao/store/product/SpuDao.php @@ -58,6 +58,18 @@ class SpuDao extends BaseDao ->when(isset($where['mer_ids']) && $where['mer_ids'] !== '',function($query)use($where){ $query->whereIn('P.mer_id',$where['mer_ids']); }) + ->when(isset($where['is_hot']) && $where['is_hot'] !== '',function($query)use($where){ + $query->whereIn('P.is_hot',$where['is_hot']); + }) + ->when(isset($where['is_benefit']) && $where['is_benefit'] !== '',function($query)use($where){ + $query->whereIn('P.is_benefit',$where['is_benefit']); + }) + ->when(isset($where['is_best']) && $where['is_best'] !== '',function($query)use($where){ + $query->whereIn('P.is_best',$where['is_best']); + }) + ->when(isset($where['is_new']) && $where['is_new'] !== '',function($query)use($where){ + $query->whereIn('P.is_new',$where['is_new']); + }) ->when(isset($where['keyword']) && $where['keyword'] !== '',function($query)use($where){ if (is_numeric($where['keyword'])) { $query->whereLike("S.store_name|S.keyword|S.product_id", "%{$where['keyword']}%"); diff --git a/app/common/repositories/user/UserAssetsLogRepository.php b/app/common/repositories/user/UserAssetsLogRepository.php index aa35ae5..9c6a6eb 100644 --- a/app/common/repositories/user/UserAssetsLogRepository.php +++ b/app/common/repositories/user/UserAssetsLogRepository.php @@ -17,6 +17,10 @@ use app\common\dao\user\UserAssetsLogDao; use app\common\repositories\BaseRepository; use app\common\repositories\store\product\ProductAssistRepository; use app\common\repositories\store\product\ProductRepository; +use app\common\repositories\system\groupData\GroupDataRepository; +use think\db\exception\DataNotFoundException; +use think\db\exception\DbException; +use think\db\exception\ModelNotFoundException; use think\facade\Log; /** @@ -43,11 +47,12 @@ class UserAssetsLogRepository extends BaseRepository const STATUS_SUCCESS = 1; // 成功 const STATUS_REFUND = 2; // 退款 - public function __construct(UserAssetsLogDao $dao, UserAssetsRepository $userAssetsRepository, ProductRepository $productRepository) + public function __construct(UserAssetsLogDao $dao, UserAssetsRepository $userAssetsRepository, ProductRepository $productRepository, GroupDataRepository $groupRepository) { $this->dao = $dao; $this->userAssetsRepository = $userAssetsRepository; $this->productRepository = $productRepository; + $this->groupDataRepository = $groupRepository; } /** @@ -91,25 +96,36 @@ class UserAssetsLogRepository extends BaseRepository * @update 2024/3/15 17:22 * @author zhangkxiang * @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"} */ public function userPayEvent($groupOrder) { - $logList = array(); - $consume = $welfare = $huitong = $contribution = 0; - // 循环groupOrder, 按照商家订单处理 + // 配置信息 + $config = $this->groupDataRepository->getGroupDataLst(0, 100, 1, 100); + $config = array_column($config['list'], "value", 'key'); + foreach ($groupOrder['orderList'] as $orderItem) { $base = 0; - // 1. 本人的消费积分 - $logList[] = array( - 'uid' => $groupOrder['uid'], - 'asset_type' => self::ASSET_TYPE_CONSUME, - 'type' => self::CHANGE_TYPE_ORDER_GET, - 'status' => self::STATUS_FROZEN, - 'order_id' => $orderItem['order_id'], - 'count' => $orderItem['pay_price'], - ); - $consume += $orderItem['pay_price']; - foreach ($orderItem['orderProduct'] as $orderProduct) { // 获取商品详情(奖励积分 $product = $this->productRepository->detail($orderProduct['product_id'], null); @@ -120,47 +136,81 @@ class UserAssetsLogRepository extends BaseRepository } } - // 如果该订单奖励基数大于0 - if($base){ - // 2. 本人的福利积分 - $orderWelfare = round($base * 0.1, 2); - $welfare+= $orderWelfare; - $logList[] = array( - 'uid' => $groupOrder['uid'], - 'asset_type' => self::ASSET_TYPE_WELFARE, - 'type' => self::CHANGE_TYPE_ORDER_GET, - 'status' => self::STATUS_FROZEN, - 'order_id' => $orderItem['order_id'], - 'count' => $orderWelfare, - ); - - // 3. 本人的惠通宝 - $orderHuitong = round($base * 0.05, 2); - $huitong+= $orderHuitong; - $logList[] = array( - 'uid' => $groupOrder['uid'], - 'asset_type' => self::ASSET_TYPE_HUITONG, - 'type' => self::CHANGE_TYPE_ORDER_GET, - 'status' => self::STATUS_FROZEN, - 'order_id' => $orderItem['order_id'], - 'count' => $orderHuitong, - ); - - // 4. 本人的贡献值 - $orderContribution = round($base * 0.01, 2); - $contribution+= $orderContribution; - $logList[] = array( - 'uid' => $groupOrder['uid'], - 'asset_type' => self::ASSET_TYPE_HUITONG, - 'type' => self::CHANGE_TYPE_ORDER_GET, - 'status' => self::STATUS_FROZEN, - 'order_id' => $orderItem['order_id'], - 'count' => $orderContribution, - ); - } + // 1. 用户资产 + $this->userAssets($orderItem, $config, $base); + + } + } + + + /** + * notes 用户资产变动 + * @param $orderItem + * @param $config + * @param $base + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + * @create 2024/3/17 17:06 + * @update 2024/3/17 17:06 + * @author zhangkxiang + * @editor + */ + public function userAssets($orderItem, $config, $base){ + $logList = array(); + $welfare = $huitong = $contribution = 0; + + // 1. 本人的消费积分 + $logList[] = array( + 'uid' => $orderItem['uid'], + 'asset_type' => self::ASSET_TYPE_CONSUME, + 'type' => self::CHANGE_TYPE_ORDER_GET, + 'status' => self::STATUS_FROZEN, + 'order_id' => $orderItem['order_id'], + 'count' => $orderItem['pay_price'], + ); + $consume = $orderItem['pay_price']; + + // 如果该订单奖励基数大于0 + if($base){ + // 2. 本人的福利积分 + $orderWelfare = round($base * 0.1, 2); + $welfare = $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, + ); + + // 3. 本人的惠通宝 + $orderHuitong = round($base * $config['huitong_user'] /100, 2); + $huitong = $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, + ); + + // 4. 本人的贡献值 + $orderContribution = round($base * $config['contribution_user']/100, 2); + $contribution = $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, + ); } $this->addLog($logList); - $this->userAssetsRepository->orderEvent($groupOrder['uid'], self::STATUS_FROZEN, compact('consume', 'welfare', 'huitong', 'contribution')); + $this->userAssetsRepository->orderEvent($orderItem['uid'], self::STATUS_FROZEN, compact('consume', 'welfare', 'huitong', 'contribution')); } public function addLog($list) diff --git a/app/controller/api/store/product/StoreSpu.php b/app/controller/api/store/product/StoreSpu.php index f09807d..de1055d 100644 --- a/app/controller/api/store/product/StoreSpu.php +++ b/app/controller/api/store/product/StoreSpu.php @@ -55,7 +55,11 @@ class StoreSpu extends BaseController 'common', 'is_trader', 'product_ids', - 'mer_id' + 'mer_id', + 'is_hot', + 'is_benefit', + 'is_best', + 'is_new', ]); $where['is_gift_bag'] = 0; $where['product_type'] = 0; diff --git a/app/event.php b/app/event.php index b2f20a5..71f5444 100644 --- a/app/event.php +++ b/app/event.php @@ -16,7 +16,7 @@ return [ 'listen' => [ 'AppInit' => [], 'HttpRun' => [], - 'HttpEnd' => [], + 'HttpEnd' => [\crmeb\listens\AppEnd::class], 'LogLevel' => [], 'LogWrite' => [], 'swoole.task' => [\crmeb\listens\SwooleTaskListen::class], diff --git a/config/log.php b/config/log.php index 4e6f4cf..a7dc5c5 100644 --- a/config/log.php +++ b/config/log.php @@ -48,7 +48,7 @@ return [ 'format' => '[%s][%s] %s', // 是否实时写入 'realtime_write' => true, - 'file_size' => 1024 * 1024 * 10, + 'file_size' => 1024 * 10, ], 'sql' => [ // 日志记录方式 diff --git a/crmeb/listens/AppEnd.php b/crmeb/listens/AppEnd.php new file mode 100644 index 0000000..78c92e3 --- /dev/null +++ b/crmeb/listens/AppEnd.php @@ -0,0 +1,22 @@ +