Commit c6c61bdf authored by luhongguang's avatar luhongguang

Merge branch 'colonel' into test

parents 22165a5c c961677c
...@@ -20,6 +20,12 @@ class ColonelDistributorColonel extends MysqlBase ...@@ -20,6 +20,12 @@ class ColonelDistributorColonel extends MysqlBase
const DEFAULT_COLUMN = ['colonel_id','user_id','take_place_id','phone','contact_name','colonel_source']; const DEFAULT_COLUMN = ['colonel_id','user_id','take_place_id','phone','contact_name','colonel_source'];
public static function getColonelUserIds()
{
$colonelUserData = ColonelDistributorColonel::select(['user_id']);
return array_column((array)$colonelUserData, 'user_id');
}
public static function getRecord(array $where, $column = '*') public static function getRecord(array $where, $column = '*')
{ {
return self::get($column, $where); return self::get($column, $where);
......
...@@ -18,6 +18,11 @@ class ColonelDistributorInviteOrderNum extends MysqlBase ...@@ -18,6 +18,11 @@ class ColonelDistributorInviteOrderNum extends MysqlBase
return self::get($columns, $where, $options); return self::get($columns, $where, $options);
} }
public static function getRecords(array $where, $column = '*')
{
return (array)self::select($column, $where);
}
public static function getRecordMaster($where, $columns = [], $options = []) public static function getRecordMaster($where, $columns = [], $options = [])
{ {
if (empty($columns)) { if (empty($columns)) {
...@@ -48,4 +53,4 @@ class ColonelDistributorInviteOrderNum extends MysqlBase ...@@ -48,4 +53,4 @@ class ColonelDistributorInviteOrderNum extends MysqlBase
{ {
return self::delete($where); return self::delete($where);
} }
} }
\ No newline at end of file
...@@ -21,6 +21,11 @@ class ColonelDistributorPayInfo extends MysqlBase ...@@ -21,6 +21,11 @@ class ColonelDistributorPayInfo extends MysqlBase
self::TYPE_FINISH_TARGET => "完成目标单数", self::TYPE_FINISH_TARGET => "完成目标单数",
]; ];
public static function getRecords(array $where, $column = '*')
{
return (array)self::select($column, $where);
}
public static function getRecord($where, $columns = [], $options = []) public static function getRecord($where, $columns = [], $options = [])
{ {
if (empty($columns)) { if (empty($columns)) {
...@@ -44,7 +49,7 @@ class ColonelDistributorPayInfo extends MysqlBase ...@@ -44,7 +49,7 @@ class ColonelDistributorPayInfo extends MysqlBase
public static function updateRecord($columns, $where) public static function updateRecord($columns, $where)
{ {
return self::update($columns, $where); return (int)self::update($columns, $where);
} }
public static function save($data, $where = [], $options = []) public static function save($data, $where = [], $options = [])
...@@ -59,4 +64,4 @@ class ColonelDistributorPayInfo extends MysqlBase ...@@ -59,4 +64,4 @@ class ColonelDistributorPayInfo extends MysqlBase
{ {
return self::delete($where); return self::delete($where);
} }
} }
\ No newline at end of file
<?php <?php
/**
* Created by PhpStorm.
* User: pengfei@yidian-inc.com
* Date: 2021/9/3 2:23 下午
*/
use App\Base\Job; use App\Base\Job;
use Api\PhpServices\Idgen\Idgen; use Api\PhpServices\Idgen\Idgen;
...@@ -10,251 +15,270 @@ use App\Models\marketing\mysql\ColonelDistributorPayInfo; ...@@ -10,251 +15,270 @@ use App\Models\marketing\mysql\ColonelDistributorPayInfo;
use App\Exception\custom\InterfaceException; use App\Exception\custom\InterfaceException;
use Api\PhpUtils\Http\HttpUtil; use Api\PhpUtils\Http\HttpUtil;
use App\Models\user\mysql\UserWechatBind; use App\Models\user\mysql\UserWechatBind;
use App\Services\marketing\PindanActivityColonelConfigService;
class ColonelorderController extends Job class ColonelorderController extends Job
{ {
const DEFAULT_USER_BATCH_SIZE = 100; const REWARD_UNIT = 100; // 奖励单位: 分
const INVITE_NEW_USER_REWARD = 3 * self::REWARD_UNIT; // 邀请新用户奖励
const DEFAULT_USER_BATCH_SIZE = 100; // 批量处理数据条数
public $today; public $colonelConfigList; // 活动配置
public $yesterday; public $settlementDate; // 活动结算日
public $colonelConfig; public $startTime; // 活动结算日-开始时间
public $colonelConfigList; public $endTime; // 活动结算日-结束时间
/**
* Notes: 初始化-读取配置
* User: pengfei@yidian-inc.com
* Date: 2021/9/3 4:13 下午
*/
public function init() public function init()
{ {
parent::init(); parent::init();
$this->today = date("Y-m-d"); $timeRange = PindanActivityColonelConfigService::getSettlementTimeRange();
$this->yesterday = date("Y-m-d", strtotime("-1 day")); $this->settlementDate = $timeRange['date'];
$this->colonelConfig = $this->getColonelConfig($this->yesterday); $this->startTime = $timeRange['start_time'];
if (!empty($this->colonelConfig)) { $this->endTime = $timeRange['end_time'];
$this->colonelConfigList = json_decode($this->colonelConfig['data'], true); $this->colonelConfigList = $this->getColonelConfig($this->settlementDate);
}
} }
/**
* Notes: 计算奖励脚本
* User: pengfei@yidian-inc.com
* Date: 2021/9/3 4:05 下午
* @throws InterfaceException
*/
public function indexAction() public function indexAction()
{ {
FileLog::info("colonel_distributor_order", '团长分销-计算奖励脚本:start'); $this->loggerInfo('start');
$userIdList = $this->getColonelUserIds(); if ($userIdList = ColonelDistributorColonel::getColonelUserIds()) {
if (!empty($userIdList)) {
$userIdList = array_chunk($userIdList, self::DEFAULT_USER_BATCH_SIZE); $userIdList = array_chunk($userIdList, self::DEFAULT_USER_BATCH_SIZE);
$colonelPayInfoData = []; $colonelPayInfoData = [];
foreach ($userIdList as $userIds) { foreach ($userIdList as $userIds) {
// 完成目标单数 $this->getInviteOrderData($userIds, $colonelPayInfoData); // 完成目标单数
if ($inviteOrderData = $this->getInviteOrderData($userIds)) { $this->getInviteNewUserData($userIds, $colonelPayInfoData); // 邀请新用户奖励
$colonelPayInfoData = array_merge($colonelPayInfoData,$inviteOrderData);
}
// 邀请新用户奖励
if ($inviteNewUserData = $this->getInviteNewUserData($userIds)) {
$colonelPayInfoData = array_merge($colonelPayInfoData,$inviteNewUserData);
}
} }
$this->handleSavePayInfo($colonelPayInfoData); $this->handleSavePayInfo($colonelPayInfoData);
} }
FileLog::info("colonel_distributor_order", '团长分销-计算奖励脚本:end'); $this->loggerInfo('end');
echo "success";
} }
/** /**
* 保存奖励信息 * Notes: 保存奖励信息
* @param $yesterday * User: pengfei@yidian-inc.com
* @return true * Date: 2021/9/3 4:34 下午
* @param $colonelPayInfoData
*/ */
public function handleSavePayInfo($colonelPayInfoData) private function handleSavePayInfo($colonelPayInfoData)
{ {
FileLog::info("colonel_distributor_order", '团长分销-计算奖励脚本:colonelPayInfoCount='.count($colonelPayInfoData)); $this->loggerInfo('colonelPayInfoCount=' . count($colonelPayInfoData));
if (!empty($colonelPayInfoData)) { if (!empty($colonelPayInfoData)) {
$data = $this->addIdgenId($colonelPayInfoData); $data = $this->getFormatPayInfoData($colonelPayInfoData);
try { try {
ColonelDistributorPayInfo::beginTransaction(); ColonelDistributorPayInfo::beginTransaction();
if (!$this->addColonelDistributorPayInfo($data)) { if (!$this->addColonelDistributorPayInfo($data)) {
throw new \Exception(sprintf("写入错误参数 %s", json_encode($data))); throw new Exception(sprintf("写入错误参数 %s", json_encode($data)));
} }
if (!ColonelDistributorPayInfo::commit()) { if (!ColonelDistributorPayInfo::commit()) {
throw new \Exception(sprintf("事务提交失败 %s", json_encode($data))); throw new Exception(sprintf("事务提交失败 %s", json_encode($data)));
} }
} catch (\Exception $e) { $this->loggerError('success');
} catch (Exception $e) {
ColonelDistributorPayInfo::rollback(); ColonelDistributorPayInfo::rollback();
FileLog::info("add_colonel_distributor_pay_info", $e->getMessage()); $this->loggerError('error=' . $e->getMessage());
} }
} }
return true;
} }
/** /**
* 获取新用户奖励 * Notes: 获取新用户奖励
* @param $yesterday * User: pengfei@yidian-inc.com
* @return array * Date: 2021/9/3 4:47 下午
* @param $userIds
* @param $colonelPayInfoData
* @throws InterfaceException
*/ */
public function getInviteNewUserData($userIds) private function getInviteNewUserData($userIds, &$colonelPayInfoData)
{ {
$inviteNewUserList = $this->getInviteNewUserList($userIds, $this->today); if ($inviteNewUserList = $this->getInviteNewUserList($userIds)) {
$inviteOrderData = []; $userNickList = $this->getUserList(array_column($inviteNewUserList, 'user_id'));
if (!empty($inviteNewUserList)) {
$userNickList = $this->getUserList(array_column($inviteNewUserList, "user_id"));
foreach ($inviteNewUserList as $newUser) { foreach ($inviteNewUserList as $newUser) {
$payInfo = [ $colonelPayInfoData[] = [
"colonel_user_id" => $newUser["inviter_user_id"], 'date' => $this->settlementDate,
"date" => $this->yesterday, 'type' => ColonelDistributorPayInfo::TYPE_NEW_USER,
"type" => ColonelDistributorPayInfo::TYPE_NEW_USER, 'reward' => self::INVITE_NEW_USER_REWARD,
"reward" => 3 * 100, 'finish_num' => 1,
"finish_num" => 1, 'invite_user_id' => $newUser['user_id'],
"invite_user_id" => $newUser["user_id"], 'invite_user_nick' => empty($userNickList[$newUser['user_id']]['user_nick']) ? '' : $userNickList[$newUser['user_id']]['user_nick'],
"invite_user_nick" => empty($userNickList[$newUser["user_id"]]["user_nick"]) ? "" : $userNickList[$newUser["user_id"]]["user_nick"], 'colonel_user_id' => $newUser['inviter_user_id'],
]; ];
$inviteOrderData[] = $payInfo;
} }
} }
return $inviteOrderData;
} }
/** /**
* 获取完成目标单数奖励 * Notes: 获取完成目标单数奖励
* @param $yesterday * User: pengfei@yidian-inc.com
* @return array * Date: 2021/9/3 4:47 下午
* @param $userIds
* @param $colonelPayInfoData
*/ */
public function getInviteOrderData($userIds) private function getInviteOrderData($userIds, &$colonelPayInfoData)
{ {
//完成目标单数 if (!empty($this->colonelConfigList)) {
$inviteOrderData = []; $inviteOrderNumList = $this->getInviteOrderNum($userIds, $this->settlementDate);
if (empty($this->colonelConfigList)) { foreach ($inviteOrderNumList as $orderNum) {
return $inviteOrderData; foreach ($this->colonelConfigList as $config) {
} if ($orderNum['num'] >= $config['assess_order_num']) {
$inviteOrderNumList = $this->getInviteOrderNum($userIds, $this->yesterday, $this->today); $colonelPayInfoData[] = [
foreach ($inviteOrderNumList as $orderNum) { 'date' => $this->settlementDate,
foreach ($this->colonelConfigList as $config) { 'type' => ColonelDistributorPayInfo::TYPE_FINISH_TARGET,
if (!empty($orderNum["num"]) && $orderNum["num"] >= $config["assess_order_num"]) { 'reward' => $config['reward_amount'] * self::REWARD_UNIT,
$payInfo = [ 'finish_num' => $config['assess_order_num'],
"colonel_user_id" => $orderNum["colonel_user_id"], 'invite_user_id' => 0,
"date" => $this->yesterday, 'invite_user_nick' => '',
"type" => ColonelDistributorPayInfo::TYPE_FINISH_TARGET, 'colonel_user_id' => $orderNum['colonel_user_id'],
"reward" => $config["reward_amount"] * 100, ];
"finish_num" => $config["assess_order_num"], }
"invite_user_id" => 0,
"invite_user_nick" => "",
];
$inviteOrderData[] = $payInfo;
} }
} }
} }
return $inviteOrderData;
} }
/** /**
* 团长任务配置 * 团长任务配置
* @param $yesterday * @param $yesterday
* @return \Api\PhpUtils\Mysql\MysqlBase * @return array
*/ */
public function getColonelConfig($yesterday) private function getColonelConfig($yesterday): array
{ {
$type = empty($params["type"]) ? ColonelDistributorConfig::TYPE_COLONEL : $params["type"]; $config = ColonelDistributorConfig::getRecord([
$config = ColonelDistributorConfig::getRecord(["date" => $yesterday, "type" => $type]); 'date' => $yesterday,
'type' => ColonelDistributorConfig::TYPE_COLONEL
]);
if (empty($config)) { if (empty($config)) {
$config = ColonelDistributorConfig::getRecord([ $config = ColonelDistributorConfig::getRecord([
"date[<=]" => $yesterday, 'date[<=]' => $yesterday,
"ORDER" => ["date" => "DESC"], 'ORDER' => ['date' => 'DESC'],
"LIMIT" => 1 'LIMIT' => 1
]); ]);
} }
return $config; $configData = [];
} if (empty($config['data'])) {
$configData = json_decode($config['data'], true);
/**
* 团长user_id
* @return array
*/
public function getColonelUserIds()
{
$colonelRes = ColonelDistributorColonel::select(["user_id"], ["LIMIT" => 10000000]);
$userIds = [];
if (!empty($colonelRes)) {
$userIds = array_column($colonelRes, "user_id");
} }
return $userIds; return $configData;
} }
/** /**
* 获取order num * 获取order num
* @param $colonelUserIds * @param $colonelUserIds
* @param $startTime * @param $date
* @param $endTime * @return array
* @return \Api\PhpUtils\Mysql\MysqlBase
*/ */
public function getInviteOrderNum($colonelUserIds, $startTime, $endTime) private function getInviteOrderNum($colonelUserIds, $date): array
{ {
return ColonelDistributorInviteOrderNum::select( return ColonelDistributorInviteOrderNum::getRecords(
["colonel_user_id", "num", "date"],
[ [
"colonel_user_id" => $colonelUserIds, 'colonel_user_id' => $colonelUserIds,
"date[>=]" => $startTime, 'date' => $date,
"date[<]" => $endTime,
], ],
[] ['colonel_user_id', 'num']
); );
} }
/** /**
* 获取有效新用户信息 * Notes: 获取有效新用户信息
* User: pengfei@yidian-inc.com
* Date: 2021/9/3 4:03 下午
* @param $userIds * @param $userIds
* @param $date * @return array
* @return array|mixed
* @throws InterfaceException * @throws InterfaceException
*/ */
public function getInviteNewUserList($userIds, $date) private function getInviteNewUserList($userIds): array
{ {
$url = config('interface', 'coupon.background.wx_invite_relation_list_by_user_ids'); $url = config('interface', 'coupon.background.wx_invite_relation_list_by_user_ids');
if (empty($url)) { if (empty($url)) {
throw new InterfaceException(['cus' => 0]); throw new InterfaceException(['cus' => 0]);
} }
$res = HttpUtil::get($url, ["user_ids" => $userIds, "date" => $date]); $res = HttpUtil::get($url,
if (!empty($res["response"]["result"])) { ['user_ids' => $userIds, 'start_time' => $this->startTime, 'end_time' => $this->endTime]);
$res = array_column($res["response"]["result"], null, "user_id"); if (!empty($res['response']['result'])) {
return array_values($res); return array_values(array_column($res['response']['result'], null, 'user_id'));
} }
return []; return [];
} }
/** /**
* 给数据整理 colonel_distributor_pay_info_id * Notes: 获取pay_info数据
* User: pengfei@yidian-inc.com
* Date: 2021/9/3 4:07 下午
* @param $data * @param $data
* @param string $type * @return array
* @return mixed
*/ */
public function addIdgenId($data, $type = "goods") private function getFormatPayInfoData($data): array
{ {
$count = count($data); $count = count($data);
$res = Idgen::get(appConfig('idgen.partner'), appConfig('idgen.key'), [], [[ $res = Idgen::get(appConfig('idgen.partner'), appConfig('idgen.key'), [], [
"type" => $type, [
'number' => 00, 'type' => 'goods',
"count" => $count]]); 'number' => 00,
$ids = $res['id_datetime'][$type] ?? []; 'count' => $count
]
]);
$ids = $res['id_datetime']['goods'] ?? [];
foreach ($data as $key => $item) { foreach ($data as $key => $item) {
$data[$key]["colonel_distributor_pay_info_id"] = $ids[$key]; $data[$key]['colonel_distributor_pay_info_id'] = $ids[$key];
} }
return $data; return $data;
} }
/** /**
* 用户信息,获取昵称 * Notes: 用户信息,获取昵称
* User: pengfei@yidian-inc.com
* Date: 2021/9/3 4:09 下午
* @param $userIds * @param $userIds
* @return \Api\PhpUtils\Mysql\MysqlBase|array * @return array
*/ */
public function getUserList($userIds) private function getUserList($userIds): array
{ {
$list = UserWechatBind::select(["user_id", "user_nick"], ["user_id" => $userIds], []); $list = UserWechatBind::select(['user_id', 'user_nick'], ['user_id' => $userIds], []);
if (!empty($list)) { return array_column((array)$list, null, 'user_id');
$list = array_column($list, null, "user_id");
}
return $list;
} }
/** /**
* 写入数据 * Notes: 写入数据
* User: pengfei@yidian-inc.com
* Date: 2021/9/3 4:10 下午
* @param $data * @param $data
* @return \Api\PhpUtils\Mysql\MysqlBase * @return bool
*/
private function addColonelDistributorPayInfo($data): bool
{
return (int)ColonelDistributorPayInfo::save($data);
}
/**
* Notes: 记录 info 日志
* User: pengfei@yidian-inc.com
* Date: 2021/9/3 4:10 下午
* @param $log
*/
private function loggerInfo($log)
{
FileLog::info('colonel_distributor_order', 'colonel_distributor_order:' . $log, false, true);
}
/**
* Notes: 记录 error 日志
* User: pengfei@yidian-inc.com
* Date: 2021/9/3 4:10 下午
* @param $log
*/ */
public function addColonelDistributorPayInfo($data) private function loggerError($log)
{ {
return ColonelDistributorPayInfo::save($data); FileLog::error('colonel_distributor_order', $log, null, 'bp-server@yidian-inc.com', true);
} }
} }
\ No newline at end of file
<?php <?php
/**
* Created by PhpStorm.
* User: pengfei@yidian-inc.com
* Date: 2021/9/3 2:23 下午
*/
use App\Base\Job; use App\Base\Job;
use Api\PhpUtils\Log\FileLog; use Api\PhpUtils\Log\FileLog;
...@@ -8,128 +13,204 @@ use Api\PhpUtils\Http\HttpUtil; ...@@ -8,128 +13,204 @@ use Api\PhpUtils\Http\HttpUtil;
class ColonelwalletController extends Job class ColonelwalletController extends Job
{ {
const CAPITAL_POOL_ID = 2; // 资金池id
const CAPITAL_POOL_OP = 200; //200:团长奖励
const WALLET_SERVICE_NAME = 11; // 10生活圈优惠券,11营销活动
const WALLET_SOURCE_NAME = 1; //使用方名,1生活圈,2主端
/**
* Notes: 奖励结算脚本
* User: pengfei@yidian-inc.com
* Date: 2021/9/3 6:03 下午
* @throws InterfaceException
*/
public function indexAction() public function indexAction()
{ {
FileLog::info("colonel_distributor_wallet", '团长分销-奖励钱包脚本:start'); $this->loggerInfo('start');
$yesterday = date("Y-m-d", strtotime("-1 day")); $payInfoList = $this->getPayInfoList();
$payInfoList = $this->getPayInfo($yesterday); $this->loggerInfo('payInfoCount=' . count($payInfoList));
FileLog::info("colonel_distributor_wallet", '团长分销-奖励钱包脚本:payInfoCount='.count($payInfoList));
if (!empty($payInfoList)) { if (!empty($payInfoList)) {
if ($this->deductingInventory($payInfoList)) { if ($this->deductingInventory($payInfoList)) {
if ($this->toWallet($payInfoList)) { if ($this->toWallet($payInfoList)) {
$this->handlePayInfoStatus(array_column($payInfoList, 'pay_info_id')); if ($this->handlePayInfoStatus(array_column($payInfoList, 'pay_info_id'))) {
$this->loggerInfo('success');
}
} }
} }
} }
FileLog::info("colonel_distributor_wallet", '团长分销-奖励钱包脚本:end'); $this->loggerInfo('end');
echo "success";
}
/**
* colonel_distributor_pay_info 数据
* @param $date
* @return array
*/
public function getPayInfo($date)
{
$list = ColonelDistributorPayInfo::select("*", ["date" => $date,'status' => ColonelDistributorPayInfo::STATUS_NOT_USE], []);
$data = [];
if (!empty($list)) {
foreach ($list as $item) {
//去重
$key = $item["colonel_user_id"].$item["date"].$item["type"].$item["finish_num"];
$data[$key] = $item;
}
$data = array_values($data);
}
return $data;
} }
/** /**
* 写入钱包 * Notes: 结算写入钱包
* User: pengfei@yidian-inc.com
* Date: 2021/9/3 6:04 下午
* @param $payInfoList
* @return bool
* @throws InterfaceException
*/ */
public function toWallet($payInfoList) private function toWallet($payInfoList): bool
{ {
$url = config('interface', 'wallet.account.transfer'); if (!$url = config('interface', 'wallet.account.transfer')) {
if (empty($url)) {
throw new InterfaceException(['cus' => 0]); throw new InterfaceException(['cus' => 0]);
} }
$data = []; $httpParams = self::getWalletHttpParams();
$list = [];
foreach ($payInfoList as $payInfo) { foreach ($payInfoList as $payInfo) {
if ($payInfo["type"] == ColonelDistributorPayInfo::TYPE_NEW_USER) { $list[] = [
$desc = "邀请新用户(".$payInfo["invite_user_nick"].")完成下单奖励"; 'user_id' => $payInfo['colonel_user_id'],
} 'service_name' => self::WALLET_SERVICE_NAME,
if ($payInfo["type"] == ColonelDistributorPayInfo::TYPE_FINISH_TARGET) { 'source_name' => self::WALLET_SOURCE_NAME,
$desc = "完成".$payInfo["finish_num"]."单用户下单奖励"; 'third_order_id' => $payInfo['colonel_distributor_pay_info_id'],
} 'third_order_id_type' => $payInfo['type'],
$tmp = []; 'third_order_desc' => self::getThirdOrderDesc($payInfo),
$tmp["user_id"] = $payInfo["colonel_user_id"]; 'amount' => $payInfo['reward'],
$tmp["service_name"] = 11; //服务名字,10生活圈优惠券,11营销活动 'extra' => $payInfo
$tmp["source_name"] = 1; //使用方名,1生活圈,2主端 ];
$tmp["third_order_id"] = $payInfo["colonel_distributor_pay_info_id"];
$tmp["third_order_id_type"] = $payInfo["type"];
$tmp["third_order_desc"] = $desc;
$tmp["amount"] = $payInfo["reward"];
$tmp["extra"] = $payInfo;
$data[] = $tmp;
} }
$httpParams['list'] = $list;
$res = HttpUtil::post($url, ["list" => $data]); $response = HttpUtil::post($url, $httpParams, 100000, 3);
if ($res['code'] == 0 && isset($res['response']["result"])) { $this->loggerInfo("url=$url,response:" . json_encode($response));
$date = date("Y-m-d H:i:s"); if (!empty($response['response']['result']) && $response['code'] == 0) {
FileLog::info("colonel_distributor_to_wallet", $date." 写入钱包成功"); $this->loggerInfo('调用钱包服务成功,count=' . count($payInfoList));
return true; return true;
} else { } else {
$msg = json_encode(["list" => $data]); $this->loggerError('调用钱包服务失败,httpParams=' . json_encode($httpParams));
FileLog::error("colonel_distributor_to_wallet", $msg, null, 'bp-server@yidian-inc.com');
return false; return false;
} }
} }
/** /**
* 资金池授予用户奖励 * Notes: 资金池授予用户奖励
* User: pengfei@yidian-inc.com
* Date: 2021/9/3 6:04 下午
* @param $payInfoList
* @return bool
* @throws InterfaceException
*/ */
public function deductingInventory($payInfoList) private function deductingInventory($payInfoList): bool
{ {
$url = config('interface', 'coupon.capitalpool.grant_user_amount'); if (!$url = config('interface', 'coupon.capitalpool.grant_user_amount')) {
if (empty($url)) {
throw new InterfaceException(['cus' => 0]); throw new InterfaceException(['cus' => 0]);
} }
$httpParams = [
$data["capital_pool_id"] = 2; 'capital_pool_id' => self::CAPITAL_POOL_ID
];
$body = [];
foreach ($payInfoList as $payInfo) { foreach ($payInfoList as $payInfo) {
if ($payInfo["type"] == ColonelDistributorPayInfo::TYPE_NEW_USER) { $body[] = [
$desc = "邀请新用户(".$payInfo["invite_user_nick"].")完成下单奖励"; 'op' => self::CAPITAL_POOL_OP,
} 'user_id' => $payInfo['colonel_user_id'],
if ($payInfo["type"] == ColonelDistributorPayInfo::TYPE_FINISH_TARGET) { 'amount' => $payInfo['reward'],
$desc = "完成".$payInfo["finish_num"]."单用户下单奖励"; 'third_order_id' => $payInfo['colonel_distributor_pay_info_id'],
} 'third_order_id_type' => $payInfo['type'],
$tmp = []; 'third_order_desc' => self::getThirdOrderDesc($payInfo),
$tmp["op"] = 200; //200:团长奖励 ];
$tmp["user_id"] = $payInfo["colonel_user_id"];
$tmp["amount"] = $payInfo["reward"];
$tmp["third_order_id"] = $payInfo["colonel_distributor_pay_info_id"];
$tmp["third_order_id_type"] = $payInfo["type"];
$tmp["third_order_desc"] = $desc;
$data["body"][] = $tmp;
} }
$res = HttpUtil::post($url, $data, 100000, 3); $httpParams['body'] = $body;
if ($res['code'] == 0 && isset($res['response']["result"])) { $res = HttpUtil::post($url, $httpParams, 100000, 3);
$date = date("Y-m-d H:i:s"); $this->loggerInfo("url=$url,response:" . json_encode($res));
FileLog::info("colonel_distributor_deducting_inventory", $date." 资金池授予用户奖励成功"); if ($res['code'] == 0 && isset($res['response']['result'])) {
$this->loggerInfo('调用资金池服务成功,count=' . count($payInfoList));
return true; return true;
} else { } else {
$msg = json_encode(["list" => $data]); $this->loggerError('调用资金池服务失败,httpParams=' . json_encode($httpParams));
FileLog::error("colonel_distributor_deducting_inventory", $msg, null, 'bp-server@yidian-inc.com');
return false; return false;
} }
} }
/** /**
* 修改状态 * Notes: 获取钱包服务请求参数
* User: pengfei@yidian-inc.com
* Date: 2021/9/3 7:34 下午
* @return array
*/
private function getWalletHttpParams(): array
{
// TODO 此处看后期业务发展 看是否需要封装WalletSdk
$date = date('Y-m-d H:i:s');
return [
'transfer_service_id' => '', //TODO
'sign' => self::getWalletHttpSign($date),
'time' => $date
];
}
/**
* Notes: 获取钱包签名
* User: pengfei@yidian-inc.com
* Date: 2021/9/3 7:34 下午
* @param $date
* @return string
*/
private function getWalletHttpSign($date): string
{
$transfer_service_secret = ''; //TODO
return md5($date . $transfer_service_secret);
}
/**
* Notes: 获取待结算数据
* User: pengfei@yidian-inc.com
* Date: 2021/9/3 7:23 下午
* @return array
*/
private function getPayInfoList(): array
{
return ColonelDistributorPayInfo::getRecords(['status' => ColonelDistributorPayInfo::STATUS_NOT_USE]);
}
/**
* Notes: 获取描述信息
* User: pengfei@yidian-inc.com
* Date: 2021/9/3 6:10 下午
* @param $payInfo
* @return string
*/
private function getThirdOrderDesc($payInfo): string
{
$desc = '';
if ($payInfo['type'] == ColonelDistributorPayInfo::TYPE_NEW_USER) {
$desc = "邀请新用户(" . $payInfo["invite_user_nick"] . ")完成下单奖励";
} elseif ($payInfo['type'] == ColonelDistributorPayInfo::TYPE_FINISH_TARGET) {
$desc = "完成" . $payInfo["finish_num"] . "单用户下单奖励";
}
return $desc;
}
/**
* Notes: 修改状态
* User: pengfei@yidian-inc.com
* Date: 2021/9/3 6:09 下午
* @param array $payInfoIds
* @return bool
*/
private function handlePayInfoStatus(array $payInfoIds): bool
{
return ColonelDistributorPayInfo::updateRecord(['status' => ColonelDistributorPayInfo::STATUS_USE],
['pay_info_id' => $payInfoIds]);
}
/**
* Notes: 记录 info 日志
* User: pengfei@yidian-inc.com
* Date: 2021/9/3 4:10 下午
* @param $log
*/
private function loggerInfo($log)
{
FileLog::info('colonel_distributor_wallet', 'colonel_distributor_wallet:' . $log, false, true);
}
/**
* Notes: 记录 error 日志
* User: pengfei@yidian-inc.com
* Date: 2021/9/3 4:10 下午
* @param $log
*/ */
public function handlePayInfoStatus(array $payInfoIds) private function loggerError($log)
{ {
return ColonelDistributorPayInfo::updateRecord(['status' => ColonelDistributorPayInfo::STATUS_USE], ['pay_info_id' => $payInfoIds]); FileLog::error('colonel_distributor_wallet', $log, null, 'bp-server@yidian-inc.com', true);
} }
} }
\ No newline at end of file
...@@ -66,7 +66,8 @@ class ColonelService ...@@ -66,7 +66,8 @@ class ColonelService
*/ */
public static function isApply($userId): array public static function isApply($userId): array
{ {
$applyInfo = ColonelDistributorColonelApply::getRecord(['user_id' => $userId], ['colonel_apply_id','audit_status']); $applyInfo = ColonelDistributorColonelApply::getRecord(['user_id' => $userId],
['colonel_apply_id', 'audit_status']);
return [ return [
// -1.未申请 0.未审核 1.审核通过 2.审核未通过 // -1.未申请 0.未审核 1.审核通过 2.审核未通过
'apply_status' => isset($applyInfo['audit_status']) ? intval($applyInfo['audit_status']) : -1 'apply_status' => isset($applyInfo['audit_status']) ? intval($applyInfo['audit_status']) : -1
...@@ -83,12 +84,13 @@ class ColonelService ...@@ -83,12 +84,13 @@ class ColonelService
*/ */
public static function getManageApplyList(array $params): array public static function getManageApplyList(array $params): array
{ {
$params = self::getPageParams($params); $params = self::getPageParams($params);
$result = ColonelDistributorColonelApply::getPages([], ColonelDistributorColonelApply::DEFAULT_COLUMN, $params['page'], $params['page_size']); $result = ColonelDistributorColonelApply::getPages([], ColonelDistributorColonelApply::DEFAULT_COLUMN,
$params['page'], $params['page_size']);
if (empty($result['count'])) { if (empty($result['count'])) {
return $result; return $result;
} }
$userMap = self::getUserMap(array_column($result['result'], 'user_id')); $userMap = self::getUserMap(array_column($result['result'], 'user_id'));
$takePlaceMap = self::getColonelTakePlaceMap(array_column($result['result'], 'colonel_apply_id')); $takePlaceMap = self::getColonelTakePlaceMap(array_column($result['result'], 'colonel_apply_id'));
foreach ($result['result'] as &$applyVal) { foreach ($result['result'] as &$applyVal) {
$applyVal['user_avatar'] = !empty($userMap[$applyVal['user_id']]['user_avatar']) ? $userMap[$applyVal['user_id']]['user_avatar'] : ''; $applyVal['user_avatar'] = !empty($userMap[$applyVal['user_id']]['user_avatar']) ? $userMap[$applyVal['user_id']]['user_avatar'] : '';
...@@ -114,8 +116,9 @@ class ColonelService ...@@ -114,8 +116,9 @@ class ColonelService
*/ */
public static function getManageList(array $params): array public static function getManageList(array $params): array
{ {
$params = self::getPageParams($params); $params = self::getPageParams($params);
$result = ColonelDistributorColonel::getPages([], ColonelDistributorColonel::DEFAULT_COLUMN, $params['page'], $params['page_size']); $result = ColonelDistributorColonel::getPages([], ColonelDistributorColonel::DEFAULT_COLUMN, $params['page'],
$params['page_size']);
if (empty($result['count'])) { if (empty($result['count'])) {
return $result; return $result;
} }
...@@ -124,9 +127,9 @@ class ColonelService ...@@ -124,9 +127,9 @@ class ColonelService
$incomeMap = PindanActivityInviteOrderService::incomeStatistics(["user_ids" => $userIds]); $incomeMap = PindanActivityInviteOrderService::incomeStatistics(["user_ids" => $userIds]);
foreach ($result['result'] as &$colonelVal) { foreach ($result['result'] as &$colonelVal) {
$userId = $colonelVal['user_id']; $userId = $colonelVal['user_id'];
$colonelVal['user_avatar'] = !empty($userMap[$userId]['user_avatar']) ? $userMap[$userId]['user_avatar'] : ''; $colonelVal['user_avatar'] = !empty($userMap[$userId]['user_avatar']) ? $userMap[$userId]['user_avatar'] : '';
$colonelVal['yesterday_income'] = !empty($incomeMap[$userId]['yesterday_reward']) ? $incomeMap[$userId]['yesterday_reward'] : 0; $colonelVal['yesterday_income'] = !empty($incomeMap[$userId]['yesterday_reward']) ? $incomeMap[$userId]['yesterday_reward'] : 0;
$colonelVal['total_income'] = !empty($incomeMap[$userId]['all_reward']) ? $incomeMap[$userId]['all_reward'] : 0; $colonelVal['total_income'] = !empty($incomeMap[$userId]['all_reward']) ? $incomeMap[$userId]['all_reward'] : 0;
} }
unset($colonelVal); unset($colonelVal);
return $result; return $result;
...@@ -144,7 +147,8 @@ class ColonelService ...@@ -144,7 +147,8 @@ class ColonelService
public static function handleManageAudit($applyId, $auditStatus): bool public static function handleManageAudit($applyId, $auditStatus): bool
{ {
// 审核状态参数检测 // 审核状态参数检测
if (!in_array($auditStatus, [ColonelDistributorColonelApply::STATUS_PASS,ColonelDistributorColonelApply::STATUS_REJECT])) { if (!in_array($auditStatus,
[ColonelDistributorColonelApply::STATUS_PASS, ColonelDistributorColonelApply::STATUS_REJECT])) {
throw new MarketingException(MarketingException::COLONEL_AUDIT_STATUS); throw new MarketingException(MarketingException::COLONEL_AUDIT_STATUS);
} }
// 审核状态数据检测 // 审核状态数据检测
...@@ -155,7 +159,8 @@ class ColonelService ...@@ -155,7 +159,8 @@ class ColonelService
try { try {
ColonelDistributorColonelApply::beginTransaction(); ColonelDistributorColonelApply::beginTransaction();
// 修改申请状态 // 修改申请状态
$updateStatus = ColonelDistributorColonelApply::updateRecord(['audit_status' => $auditStatus], ['colonel_apply_id' => $applyId,'audit_status' => ColonelDistributorColonelApply::STATUS_AUDIT]); $updateStatus = ColonelDistributorColonelApply::updateRecord(['audit_status' => $auditStatus],
['colonel_apply_id' => $applyId, 'audit_status' => ColonelDistributorColonelApply::STATUS_AUDIT]);
if (empty($updateStatus)) { if (empty($updateStatus)) {
throw new MarketingException(MarketingException::COLONEL_AUDIT_STATUS_FAILED); throw new MarketingException(MarketingException::COLONEL_AUDIT_STATUS_FAILED);
} }
...@@ -265,7 +270,7 @@ class ColonelService ...@@ -265,7 +270,7 @@ class ColonelService
*/ */
private static function getUserMap(array $userIds): array private static function getUserMap(array $userIds): array
{ {
$userWechatList = UserWechatBind::getRecords(['user_id' => $userIds], ['user_id','user_nick','user_avatar']); $userWechatList = UserWechatBind::getRecords(['user_id' => $userIds], ['user_id', 'user_nick', 'user_avatar']);
return array_column((array)$userWechatList, null, 'user_id'); return array_column((array)$userWechatList, null, 'user_id');
} }
...@@ -278,7 +283,8 @@ class ColonelService ...@@ -278,7 +283,8 @@ class ColonelService
*/ */
private static function getColonelTakePlaceMap(array $colonelApplyIds): array private static function getColonelTakePlaceMap(array $colonelApplyIds): array
{ {
$colonels = ColonelDistributorColonel::getRecords(['colonel_apply_id' => $colonelApplyIds], ['colonel_apply_id','take_place_id']); $colonels = ColonelDistributorColonel::getRecords(['colonel_apply_id' => $colonelApplyIds],
['colonel_apply_id', 'take_place_id']);
return array_column((array)$colonels, 'take_place_id', 'colonel_apply_id'); return array_column((array)$colonels, 'take_place_id', 'colonel_apply_id');
} }
...@@ -291,8 +297,8 @@ class ColonelService ...@@ -291,8 +297,8 @@ class ColonelService
*/ */
private static function getPageParams(array $params = []): array private static function getPageParams(array $params = []): array
{ {
$params['page'] = !empty($params['page']) ? $params['page'] : 1; $params['page'] = !empty($params['page']) ? $params['page'] : 1;
$params['page_size'] = !empty($params['page_size']) ? $params['page_size'] : 20; $params['page_size'] = !empty($params['page_size']) ? $params['page_size'] : 20;
return $params; return $params;
} }
} }
...@@ -99,14 +99,8 @@ class PindanActivityColonelConfigService ...@@ -99,14 +99,8 @@ class PindanActivityColonelConfigService
*/ */
public static function getTaskData($params = []) public static function getTaskData($params = [])
{ {
$hour = date("H"); $timeRange = self::getActivityTimeRange();
if ($hour < 10 && $hour > 0) { $date = date("Y-m-d", strtotime($timeRange["start_time"]));
$date = date("Y-m-d", strtotime("-1 day"));
} elseif ($hour > 16) {
$date = date("Y-m-d");
} else {
$date = date("Y-m-d");
}
$configList = self::colonelConfig(["date" => $date, "type" => ColonelDistributorConfig::TYPE_COLONEL]); $configList = self::colonelConfig(["date" => $date, "type" => ColonelDistributorConfig::TYPE_COLONEL]);
$marketingId = empty($configList[0]["marketing_id"]) ? 0 : $configList[0]["marketing_id"]; $marketingId = empty($configList[0]["marketing_id"]) ? 0 : $configList[0]["marketing_id"];
...@@ -144,15 +138,38 @@ class PindanActivityColonelConfigService ...@@ -144,15 +138,38 @@ class PindanActivityColonelConfigService
public static function getActivityTimeRange() : array public static function getActivityTimeRange() : array
{ {
// 获取活动时间范围 例如活动时间(2021-09-03) --- 2021-09-03:12:00:00 - 2021-09-04:12:00:00 // 获取活动时间范围 例如活动时间(2021-09-03) --- 2021-09-03:12:00:00 - 2021-09-04:12:00:00
$hour = ' '.self::ACTIVITY_DEFAULT_HOUR . ":00:00"; $hour = ' '.self::ACTIVITY_DEFAULT_HOUR . ':00:00';
if (date("H") >= 12) { if (date('H') >= self::ACTIVITY_DEFAULT_HOUR) {
$startTime = date("Y-m-d").$hour; $startTime = date('Y-m-d').$hour;
$endTime = date("Y-m-d", strtotime("+1 day")).$hour; $endTime = date('Y-m-d', strtotime('+1 day')).$hour;
} else { } else {
$startTime = date("Y-m-d", strtotime("-1 day")).$hour; $startTime = date('Y-m-d', strtotime('-1 day')).$hour;
$endTime = date("Y-m-d").$hour; $endTime = date('Y-m-d').$hour;
} }
return ['start_time' => $startTime,'end_time' => $endTime]; return [
'start_time' => $startTime,
'end_time' => $endTime,
'date' => date('Y-m-d', strtotime($startTime))
];
}
/**
* Notes: 获取结算时间范围
* User: pengfei@yidian-inc.com
* Date: 2021/9/3 2:50 下午
* @return string[]
*/
public static function getSettlementTimeRange() : array
{
// 获取活动时间范围 例如当前时间(2021-09-03 12:00:00) 应结算时间为 2021-08-31-:12:00:00 - 2021-09-01:12:00:00
$hour = ' '.self::ACTIVITY_DEFAULT_HOUR . ':00:00';
$startTime = date('Y-m-d', strtotime('-3 day')).$hour;
$endTime = date('Y-m-d', strtotime('-2 day')).$hour;
return [
'start_time' => $startTime,
'end_time' => $endTime,
'date' => date('Y-m-d', strtotime($startTime))
];
} }
} }
\ No newline at end of file
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
"require": { "require": {
"php": "7.2.*", "php": "7.2.*",
"ext-json": "*", "ext-json": "*",
"api/php_utils":"1.0.14", "api/php_utils":"1.0.15",
"api/php_services":"1.0.13", "api/php_services":"1.0.13",
"ext-openssl": "*" "ext-openssl": "*"
}, },
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "27230da37f9a20daffbb900882abde53", "content-hash": "a7741f079784d6a5d991f5e205ec4307",
"packages": [ "packages": [
{ {
"name": "api/php_services", "name": "api/php_services",
...@@ -30,11 +30,11 @@ ...@@ -30,11 +30,11 @@
}, },
{ {
"name": "api/php_utils", "name": "api/php_utils",
"version": "v1.0.14", "version": "v1.0.15",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://git.yidian-inc.com:8021/bp/php_utils.git", "url": "https://git.yidian-inc.com:8021/bp/php_utils.git",
"reference": "a7bc4caaaee7aa1650e3055630860699c7fbc506" "reference": "feb1de3de8f74171202237e1443f8a395038b8d7"
}, },
"require": { "require": {
"elasticsearch/elasticsearch": "~7.0", "elasticsearch/elasticsearch": "~7.0",
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
} }
}, },
"description": "bp api php_utils", "description": "bp api php_utils",
"time": "2021-09-01T03:11:17+00:00" "time": "2021-09-03T08:58:11+00:00"
}, },
{ {
"name": "bacon/bacon-qr-code", "name": "bacon/bacon-qr-code",
......
...@@ -61,7 +61,7 @@ class HttpUtil ...@@ -61,7 +61,7 @@ class HttpUtil
{ {
// 增加traceId // 增加traceId
if(is_array($headers)) { if(is_array($headers)) {
$headers['X-TRACE-ID'] = Tracer::getTraceId(); $headers[] = 'X-TRACE-ID: ' . Tracer::getTraceId();
} }
$url = $url ."?". http_build_query($params); $url = $url ."?". http_build_query($params);
return self::curl($url, $timeout, $retries, $headers, [], $proxy, 'GET', $curl_opts); return self::curl($url, $timeout, $retries, $headers, [], $proxy, 'GET', $curl_opts);
...@@ -97,7 +97,7 @@ class HttpUtil ...@@ -97,7 +97,7 @@ class HttpUtil
{ {
// 增加traceId // 增加traceId
if(is_array($headers)) { if(is_array($headers)) {
$headers['X-TRACE-ID'] = Tracer::getTraceId(); $headers[] = 'X-TRACE-ID: ' . Tracer::getTraceId();
} }
return self::curl($url, $timeout, $retries, $headers, $post, $proxy, 'POST', $curl_opts); return self::curl($url, $timeout, $retries, $headers, $post, $proxy, 'POST', $curl_opts);
} }
......
...@@ -32,7 +32,7 @@ private static $installed = array ( ...@@ -32,7 +32,7 @@ private static $installed = array (
'aliases' => 'aliases' =>
array ( array (
), ),
'reference' => '5b271e605f425df64cb7d8d019fa921c045caceb', 'reference' => 'bdf89778ba6a83a43c24ce687bdd41b5057a7532',
'name' => 'yidian/yaf_demo', 'name' => 'yidian/yaf_demo',
), ),
'versions' => 'versions' =>
...@@ -48,12 +48,12 @@ private static $installed = array ( ...@@ -48,12 +48,12 @@ private static $installed = array (
), ),
'api/php_utils' => 'api/php_utils' =>
array ( array (
'pretty_version' => 'v1.0.14', 'pretty_version' => 'v1.0.15',
'version' => '1.0.14.0', 'version' => '1.0.15.0',
'aliases' => 'aliases' =>
array ( array (
), ),
'reference' => 'a7bc4caaaee7aa1650e3055630860699c7fbc506', 'reference' => 'feb1de3de8f74171202237e1443f8a395038b8d7',
), ),
'bacon/bacon-qr-code' => 'bacon/bacon-qr-code' =>
array ( array (
...@@ -332,7 +332,7 @@ private static $installed = array ( ...@@ -332,7 +332,7 @@ private static $installed = array (
'aliases' => 'aliases' =>
array ( array (
), ),
'reference' => '5b271e605f425df64cb7d8d019fa921c045caceb', 'reference' => 'bdf89778ba6a83a43c24ce687bdd41b5057a7532',
), ),
), ),
); );
......
...@@ -27,12 +27,12 @@ ...@@ -27,12 +27,12 @@
}, },
{ {
"name": "api/php_utils", "name": "api/php_utils",
"version": "v1.0.14", "version": "v1.0.15",
"version_normalized": "1.0.14.0", "version_normalized": "1.0.15.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://git.yidian-inc.com:8021/bp/php_utils.git", "url": "https://git.yidian-inc.com:8021/bp/php_utils.git",
"reference": "a7bc4caaaee7aa1650e3055630860699c7fbc506" "reference": "feb1de3de8f74171202237e1443f8a395038b8d7"
}, },
"require": { "require": {
"elasticsearch/elasticsearch": "~7.0", "elasticsearch/elasticsearch": "~7.0",
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
"mongodb/mongodb": "1.4.3", "mongodb/mongodb": "1.4.3",
"php": "7.2.*" "php": "7.2.*"
}, },
"time": "2021-09-01T03:11:17+00:00", "time": "2021-09-03T08:58:11+00:00",
"type": "library", "type": "library",
"installation-source": "source", "installation-source": "source",
"autoload": { "autoload": {
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
'aliases' => 'aliases' =>
array ( array (
), ),
'reference' => '5b271e605f425df64cb7d8d019fa921c045caceb', 'reference' => 'bdf89778ba6a83a43c24ce687bdd41b5057a7532',
'name' => 'yidian/yaf_demo', 'name' => 'yidian/yaf_demo',
), ),
'versions' => 'versions' =>
...@@ -22,12 +22,12 @@ ...@@ -22,12 +22,12 @@
), ),
'api/php_utils' => 'api/php_utils' =>
array ( array (
'pretty_version' => 'v1.0.14', 'pretty_version' => 'v1.0.15',
'version' => '1.0.14.0', 'version' => '1.0.15.0',
'aliases' => 'aliases' =>
array ( array (
), ),
'reference' => 'a7bc4caaaee7aa1650e3055630860699c7fbc506', 'reference' => 'feb1de3de8f74171202237e1443f8a395038b8d7',
), ),
'bacon/bacon-qr-code' => 'bacon/bacon-qr-code' =>
array ( array (
...@@ -306,7 +306,7 @@ ...@@ -306,7 +306,7 @@
'aliases' => 'aliases' =>
array ( array (
), ),
'reference' => '5b271e605f425df64cb7d8d019fa921c045caceb', 'reference' => 'bdf89778ba6a83a43c24ce687bdd41b5057a7532',
), ),
), ),
); );
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