Commit 3d37279a authored by pengfei's avatar pengfei

update 团长分销奖励-计算奖励脚本增加资金池余额判断

parent e0a32a06
......@@ -13,6 +13,7 @@ use App\Models\marketing\mysql\ColonelDistributorInviteOrderNum;
use App\Models\marketing\mysql\ColonelDistributorPayInfo;
use App\Exception\custom\InterfaceException;
use Api\PhpUtils\Http\HttpUtil;
use App\Models\marketing\mysql\Marketing;
use App\Models\user\mysql\UserWechatBind;
use App\Services\marketing\PindanActivityColonelConfigService;
use Api\PhpUtils\Log\JobLog;
......@@ -22,6 +23,7 @@ class ColonelorderController extends Job
const REWARD_UNIT = 100; // 奖励单位: 分
const INVITE_NEW_USER_REWARD = 3 * self::REWARD_UNIT; // 邀请新用户奖励
const DEFAULT_USER_BATCH_SIZE = 100; // 批量处理数据条数
const ACTIVITY_OFFLINE_BALANCE = 50 * self::REWARD_UNIT; // 活动余额下线阈值
public $colonelConfigList; // 活动配置
public $settlementDate; // 活动结算日
......@@ -59,6 +61,7 @@ class ColonelorderController extends Job
if (!empty($colonelPayInfoData)) {
try {
$this->loggerInfo('colonelPayInfoCount=' . count($colonelPayInfoData));
$this->handleMarketingBalance($colonelPayInfoData);
$colonelPayInfoData = $this->getFormatPayInfoData($colonelPayInfoData);
$this->handleSavePayInfo($colonelPayInfoData);
$this->loggerInfo('success');
......@@ -263,6 +266,77 @@ class ColonelorderController extends Job
return (int)ColonelDistributorPayInfo::save($data);
}
/**
* Notes: 获取团长分销资余额
* User: pengfei@yidian-inc.com
* Date: 2021/9/9 6:19 下午
* @return array
* @throws Exception
*/
private function getMarketingCapitalPoolBalance(): array
{
if (!$url = config('interface', 'coupon.capitalpool.detail')) {
throw new Exception('没有capitalpool配置');
}
if (!$marketing = $this->getMarketingInfo()) {
throw new Exception('没有获取到资金池');
}
$httpParams = [
'capital_pool_id' => $marketing['capital_pool_id']
];
$response = HttpUtil::post($url, $httpParams, 100000, 3);
$this->loggerInfo("url=$url,request=" . json_encode($httpParams) . ";response=" . json_encode($response));
if (!isset($response['response']['result']['capital_pool_total'])) {
throw new Exception('没有获取到资金池信息');
}
$result = $response['response']['result'];
$balance = ($result['capital_pool_total'] - $result['capital_pool_lock'] - $result['capital_pool_used']);
return [
'marketing_id' => $marketing['marketing_id'],
'balance' => $balance
];
}
/**
* Notes: 检测资金余额,是否下线活动
* User: pengfei@yidian-inc.com
* Date: 2021/9/9 6:29 下午
* @param $colonelPayInfoData
* @throws Exception
*/
private function handleMarketingBalance($colonelPayInfoData)
{
$totalReward = array_sum(array_column($colonelPayInfoData, 'reward'));
$marketing = $this->getMarketingCapitalPoolBalance();
$diffBalance = $marketing['balance'] - $totalReward;
if (0 >= $diffBalance) {
throw new Exception('资金池可用余额不足');
}
// 达到活动下线条件
if (self::ACTIVITY_OFFLINE_BALANCE >= $diffBalance) {
Marketing::updateRecord(['online_status' => Marketing::ONLINE_STATUS_GUANBI],
['marketing_id' => $marketing['marketing_id']]);
}
}
/**
* Notes: 获取团长分销活动
* User: pengfei@yidian-inc.com
* Date: 2021/9/9 6:06 下午
* @return array
*/
private function getMarketingInfo(): array
{
$where = [
'marketing_type' => Marketing::MARKETING_TYPE_TUANZHANG,
'ORDER' => ['marketing_id' => 'DESC'],
// 'online_status' => Marketing::ONLINE_STATUS_QIDONG TODO 待确认状态
];
$where['ORDER'] = ["create_time" => "DESC"];
$marketing = Marketing::getRecord($where, ['marketing_id', 'capital_pool_id']);
return (array)$marketing;
}
/**
* Notes: 加载配置
* User: pengfei@yidian-inc.com
......@@ -281,7 +355,7 @@ class ColonelorderController extends Job
$hour = PindanActivityColonelConfigService::ACTIVITY_DEFAULT_HOUR;
$this->settlementDate = $params['date'];
$this->startTime = "{$params['date']} $hour:00:00";
$this->endTime = date('Y-m-d H:i:s',strtotime($this->startTime . ' +1 day'));
$this->endTime = date('Y-m-d H:i:s', strtotime($this->startTime . ' +1 day'));
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment