update 任务3结算

This commit is contained in:
chenbo 2023-11-07 18:29:54 +08:00
parent 5869879e93
commit 0c36e8dbc0
3 changed files with 137 additions and 3 deletions

View File

@ -215,4 +215,20 @@ class ShopRequestLogic extends BaseLogic
return false;
}
}
/**
* 查询手机号用户的交易金额
*/
public static function getUserTradeAmount($param)
{
try {
$requestResponse = HttpClient::create()->request('GET', env('url.shop_prefix'). '', [
'query' => $param
]);
return json_decode($requestResponse->getContent(), true);
} catch (Exception $e) {
self::setError($e->getMessage());
return false;
}
}
}

View File

@ -430,6 +430,26 @@ class TownShareProfit
}
}
public function dealTaskSettlementMaster3(Task $taskInfo, Company $townCompany, $taskSchedulePlan, $leftTransactionPool)
{
try {
Db::startTrans();
$this->shareProfit($taskInfo, $townCompany, $taskSchedulePlan);
// 更改结算状态
(new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']);
// 更改任务状态
Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]);
// 更新交易池
(new TaskTemplate())->updateTransactionPool($taskSchedulePlan['template_info']['id'], $leftTransactionPool);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
Log::error($taskSchedulePlan['template_info']['title'].'-任务结算失败:' . $e->getMessage());
return false;
}
}
public function dealTaskSettlementMaster4(Task $taskInfo, Company $townCompany, $taskSchedulePlan, $leftTransactionPool)
{
try {
@ -439,7 +459,7 @@ class TownShareProfit
(new TaskSchedulingPlan())->settlement($taskSchedulePlan['id']);
// 更改任务状态
Task::where(['id' => $taskSchedulePlan['task_id']])->update(['status' => 3,'money' => $taskInfo['money']]);
// 更新交易池
// 更新交易池
(new TaskTemplate())->updateTransactionPool($taskSchedulePlan['template_info']['id'], $leftTransactionPool);
Db::commit();
return true;

View File

@ -806,14 +806,28 @@ class TaskLogic extends BaseLogic
}
// todo
/**
* @param $taskSchedulePlan
* 信息收集与促销
* 任务累计天数 小于 第一阶段 关闭任务
* 任务累计天数 = 第一阶段 判断信息收集任务是否完成,完成则结算
* 任务累计天数 大于 第一阶段 小于第一+第二阶段 判断交易任务是否完成,完成则结算
* 任务累计天数 = 第一+第二阶段 判断信息收集和交易任务是否完成,完成则结算
* 任务累计天数 大于 第一+第二阶段 小于第一+第二+第三阶段 判断交易任务是否完成,完成则结算,否则关闭任务
*/
private static function masterTask3Settlement($taskSchedulePlan)
{
Log::info(['镇农科公司定时任务结算执行-'.$taskSchedulePlan['template_info']['title']]);
$taskTemplateInfo = $taskSchedulePlan['template_info'];
$dayCount = $taskTemplateInfo['day_count'];
$stageDayTwoCount = bcadd($taskTemplateInfo['stage_day_one'],$taskTemplateInfo['stage_day_two']);
$target = $taskTemplateInfo['extend']['target'];
$taskInfo = Task::where(['id' => $taskSchedulePlan['task_id']])->find();
$townCompany = Company::where(['id' => $taskTemplateInfo['company_id']])->find();
// 任务交易池,用于叠加交易额
$townTransactionPool = $taskTemplateInfo['transaction_pool'];
// 任务累计天数 小于 第一阶段 关闭任务
if ($dayCount < $taskTemplateInfo['stage_day_one']) {
(new Task())->closeTask($taskSchedulePlan['task_id']);
@ -822,8 +836,92 @@ class TaskLogic extends BaseLogic
// 任务累计天数 = 第一阶段 收集信息 >= 1家
if ($dayCount == $taskTemplateInfo['stage_day_one']) {
$purchaseSalesInfo = $taskTemplateInfo['extend']['purchase_sales_info'];
$purchaseSalesCount = count($purchaseSalesInfo['planting']) + count($purchaseSalesInfo['supply']);
if ($purchaseSalesCount >= 1) {
$taskInfo['money'] = bcmul($taskTemplateInfo['money'], $taskTemplateInfo['stage_day_one'], 2);
(new TownShareProfit())->dealTaskSettlementMaster3($taskInfo, $townCompany, $taskSchedulePlan, $townTransactionPool);
}
}
// 任务累计天数 大于 第一阶段 小于第一+第二阶段 判断交易任务是否完成,完成则结算,否则关闭任务
if ($dayCount > $taskTemplateInfo['stage_day_one'] && $dayCount < $stageDayTwoCount) {
// 查询收集到的用户在商城的交易金额(前置条件:信息收集中的手机号注册商城并交易)
$phoneList = [];
foreach ($purchaseSalesInfo['planting'] as $item) {
$phoneList[] = $item['phone'];
}
foreach ($purchaseSalesInfo['supply'] as $item) {
$phoneList[] = $item['shopkeeperPhone'];
}
$param = [
'start_time' => strtotime(date('Y-m-d', time())),
'end_time' => strtotime(date('Y-m-d', time())) + 86399,
'phone' => implode(',', $phoneList)
];
$result = ShopRequestLogic::getUserTradeAmount($param); // todo 对接接口
$tradeAmount = $result['data']['trade_amount'];
$totalAmount = bcadd($tradeAmount, $townTransactionPool, 2); // 总的交易金额 = 当日交易额 + 累计交易池
$purchaseSalesInfo = $taskTemplateInfo['extend']['purchase_sales_info'];
$purchaseSalesCount = bcadd(count($purchaseSalesInfo['planting']), count($purchaseSalesInfo['supply']));
// 目标金额 = 274 * 收集用户数
$targetTradeAmount = bcmul($purchaseSalesCount, 274, 2);
// 完成条件: 交易金额 >= 目标金额
if (bccomp($totalAmount, $targetTradeAmount, 2) ==0 || bccomp($totalAmount, $targetTradeAmount, 2) ==1) {
$taskInfo['money'] = bcdiv($taskTemplateInfo['money_two'], 2, 2);
$leftTransactionPool = bcsub($totalAmount, $targetTradeAmount, 2);
(new TownShareProfit())->dealTaskSettlementMaster3($taskInfo, $townCompany, $taskSchedulePlan, $leftTransactionPool);
} else {
(new Task())->closeTask($taskSchedulePlan['task_id']);
}
}
// 任务累计天数 = 第一+第二阶段 判断信息收集和交易任务是否完成,完成则结算,否则关闭任务
if ($dayCount == $stageDayTwoCount) {
$purchaseSalesInfo = $taskTemplateInfo['extend']['purchase_sales_info'];
$purchaseSalesCount = count($purchaseSalesInfo['planting']) + count($purchaseSalesInfo['supply']);
if ($purchaseSalesCount >= $target) {
$taskInfo['money'] = bcmul(bcdiv($taskTemplateInfo['money_two'], 2, 2), $taskTemplateInfo['stage_day_two'], 2);
(new TownShareProfit())->dealTaskSettlementMaster3($taskInfo, $townCompany, $taskSchedulePlan, $townTransactionPool);
}
}
// 任务累计天数 大于 第一+第二阶段 每日结算 判断交易任务是否完成,完成则结算,否则关闭任务
if ($dayCount >= $stageDayTwoCount) {
// 查询收集到的用户在商城的交易金额(前置条件:信息收集中的手机号注册商城并交易)
$phoneList = [];
foreach ($purchaseSalesInfo['planting'] as $item) {
$phoneList[] = $item['phone'];
}
foreach ($purchaseSalesInfo['supply'] as $item) {
$phoneList[] = $item['shopkeeperPhone'];
}
$param = [
'start_time' => strtotime(date('Y-m-d', time())),
'end_time' => strtotime(date('Y-m-d', time())) + 86399,
'phone' => implode(',', $phoneList)
];
$result = ShopRequestLogic::getUserTradeAmount($param); // todo 对接接口
$tradeAmount = $result['data']['trade_amount'];
$totalAmount = bcadd($tradeAmount, $townTransactionPool, 2); // 总的交易金额 = 当日交易额 + 累计交易池
// 目标金额 = 274 * 总目标数
$targetTradeAmount = bcmul($target, 274, 2);
// 完成条件: 交易金额 >= 目标金额
if (bccomp($totalAmount, $targetTradeAmount, 2) ==0 || bccomp($totalAmount, $targetTradeAmount, 2) ==1) {
$taskInfo['money'] = bcdiv($taskTemplateInfo['money_two'], 2, 2);
$leftTransactionPool = bcsub($totalAmount, $targetTradeAmount, 2);
(new TownShareProfit())->dealTaskSettlementMaster3($taskInfo, $townCompany, $taskSchedulePlan, $leftTransactionPool);
} else {
(new Task())->closeTask($taskSchedulePlan['task_id']);
}
}
}
/**