和蕙健康小程序后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

92 lines
3.1 KiB

<?php
namespace addons\shopro\job;
use addons\shopro\service\CommissionScoreLog;
use think\queue\Job;
use think\Db;
use think\exception\HttpResponseException;
use addons\shopro\service\commission\Agent as AgentService;
/**
* 分销任务
*/
class Commission extends BaseJob
{
/**
* 分销商升级
*/
public function agentUpgrade(Job $job, $payload)
{
try {
$userId = $payload['user_id'];
$agent = new AgentService($userId);
if ($agent->user) {
Db::transaction(function () use ($agent) {
$agent->runAgentUpgradePlan();
});
}
$job->delete();
} catch (HttpResponseException $e) {
$data = $e->getResponse()->getData();
$message = $data ? ($data['msg'] ?? '') : $e->getMessage();
format_log_error($e, 'AgentUpgrade.HttpResponseException', $message);
} catch (\Exception $e) {
format_log_error($e, 'AgentUpgrade');
}
}
/**
* 分销商升级 (新)
*/
public function createAsyncAgentUpgradeNew(Job $job, $payload) {
try {
$userId = $payload['user_id'];
$order = $payload['order'];
\think\Log::info('当前分销商ID=' . json_encode($userId));
// dd(11);
$agentScore = new CommissionScoreLog($userId);
\think\Log::info('当前分销商数据=' . json_encode($agentScore));
if ($agentScore->user) {
Db::transaction(function () use ($agentScore, $order) {
$agentScore->runAgentUpgradePlan($order);
});
}
$job->delete();
}catch (HttpResponseException $e) {
$data = $e->getResponse()->getData();
$message = $data ? ($data['msg'] ?? '') : $e->getMessage();
format_log_error($e, 'AgentUpgradeNew.HttpResponseException', $message);
} catch (\Exception $e) {
format_log_error($e, 'AgentUpgradeNew');
}
}
/**
* 分销积分结算佣金
*/
public function createAsyncAgentScoreSettlePlan(Job $job, $payload) {
try {
$userId = $payload['user_id'];
$order = $payload['order'];
\think\Log::info('当前分销商ID=' . json_encode($userId));
$agentScore = new CommissionScoreLog($userId);
\think\Log::info('当前分销商数据=' . json_encode($agentScore->user));
if ($agentScore->user) {
Db::transaction(function () use ($agentScore, $order) {
\think\Log::info('当前分销商订单数据=' . json_encode($order));
$agentScore->agentScoreSettlePlan($order);
});
}
$job->delete();
}catch (HttpResponseException $e) {
$data = $e->getResponse()->getData();
$message = $data ? ($data['msg'] ?? '') : $e->getMessage();
format_log_error($e, 'agentScoreSettle.HttpResponseException', $message);
} catch (\Exception $e) {
format_log_error($e, 'agentScoreSettle');
}
}
}