推荐奖励

main
fengxinyhyl 9 months ago
parent 4ba9d5c48c
commit b3d1f7f4af
  1. 127
      app/common/repositories/user/UserAssetsLogRepository.php

@ -18,6 +18,7 @@ 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 app\common\repositories\system\merchant\MerchantRepository;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
@ -114,7 +115,7 @@ class UserAssetsLogRepository extends BaseRepository
* {"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":1, "key":"welfare_merchant_recommend"}
* {"name":"惠通宝增值幅度比例配置", "value":10, "key":"huitong_add"}
* {"name":"福利积分--存在分红点用户奖励", "value":10, "key":"share_award"}
*/
@ -139,14 +140,133 @@ class UserAssetsLogRepository extends BaseRepository
// 1. 用户资产
$this->userAssets($orderItem, $config, $base);
// 2. 项目经理资产
if ($base) {
// 2. 项目经理资产
$startProjectUid = $this->projectAssets($orderItem, $config, $base);
// 3. 培育经理资产
$this->breedAssets($startProjectUid, $orderItem['order_id'], $config, $base);
// 4.区域代理资产
$this->agentAssets($orderItem['district_id'], $orderItem['order_id'], $config, $base);
// 5. 推荐资产
$this->recommendAssets($orderItem['mer_id'], $orderItem['order_id'], $config, $base);
}
}
}
/**
* notes 推荐资产
* @param $merId
* @param $orderId
* @param $config
* @param $base
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @create 2024/3/17 23:08
* @update 2024/3/17 23:08
* @author zhangkxiang
* @editor
*/
public function recommendAssets($merId, $orderId, $config, $base){
$consume = $welfare = $huitong = $contribution = 0;
/**
* @var MerchantRepository $merRepository
*/
$merRepository = app(MerchantRepository::class);
$merchant = $merRepository->get($merId);
if (empty($merchant)) {
return;
}
if($merchant['spread_uid'] == 0){
return;
}
/**
* @var UserRepository $userRepository
*/
$userRepository = app(UserRepository::class);
$user = $userRepository->get($merchant['spread_uid']);
if (empty($user)) {
return;
}
$log= array(
'uid' => $user['uid'],
'asset_type' => self::ASSET_TYPE_WELFARE,
'type' => self::CHANGE_TYPE_ORDER_GET,
'status' => self::STATUS_FROZEN,
'order_id' => $orderId,
);
if($user['agent_district_id']){
// 区域代理
$orderWelfare = round($base * $config['welfare_agent_recommend'] / 100, 2);
$welfare = $this->_getValue($orderWelfare);
$ext = array('district_id' => $user['agent_district_id'], 'name' => "区域代理推荐商家");
}elseif ($user['group_id']){
// 项目经理
$orderWelfare = round($base * $config['welfare_project_recommend'] / 100, 2);
$welfare = $this->_getValue($orderWelfare);
$ext = array('group_id' => $user['group_id'], 'name' => "项目经理推荐商家");
}elseif ($user['mer_id']){
// 商家
$orderWelfare = round($base * $config['welfare_merchant_recommend'] / 100, 2);
$welfare = $this->_getValue($orderWelfare);
$ext = array('mer_id' => $user['mer_id'], 'name' => "商家推荐商家");
} else{
return ;
}
$log['count'] = $welfare;
$log['ext'] = $ext;
$this->addLog([$log]);
$this->userAssetsRepository->orderEvent($user['uid'], self::STATUS_FROZEN, compact('consume', 'welfare', 'huitong', 'contribution'));
}
/**
* notes 区域推荐奖励
* @param $districtId
* @param $orderId
* @param $config
* @param $base
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @create 2024/3/17 22:49
* @update 2024/3/17 22:49
* @author zhangkxiang
* @editor
*/
public function agentAssets($districtId, $orderId, $config, $base){
$consume = $welfare = $huitong = $contribution = 0;
/**
* @var UserRepository $userRepository
*/
$userRepository = app(UserRepository::class);
$user = $userRepository->getWhere(array('agent_district_id' => $districtId));
if (empty($user)) {
return;
}
// 1. 项目经理的福利积分
$orderWelfare = round($base * $config['welfare_agent'] / 100, 2);
$welfare = $this->_getValue($orderWelfare);
$logList[] = array(
'uid' => $user['uid'],
'asset_type' => self::ASSET_TYPE_WELFARE,
'type' => self::CHANGE_TYPE_ORDER_GET,
'status' => self::STATUS_FROZEN,
'order_id' => $orderId,
'count' => $welfare,
'ext' => array('district_id' => $districtId, 'name' => "区域代理"),
);
$this->addLog($logList);
$this->userAssetsRepository->orderEvent($user['uid'], self::STATUS_FROZEN, compact('consume', 'welfare', 'huitong', 'contribution'));
}
@ -389,6 +509,9 @@ class UserAssetsLogRepository extends BaseRepository
*/
public function addLog($list)
{
foreach ($list as $key => $item) {
$list[$key]['ext'] = $item['ext'] ?? array();
}
$this->dao->insertAll($list);
}

Loading…
Cancel
Save