|
|
@@ -1185,63 +1185,66 @@ class PerfCalc {
|
|
|
return true;
|
|
|
}
|
|
|
echo sprintf("时间:[%s]店服务奖业绩计算,当前offset为:【%s】" . PHP_EOL, date('Y-m-d H:i:s', time()) , $offset);
|
|
|
- // 从缓存列表里面从底层往上倒序获取会员 IS_HAS_USER 0 代表是此结算周期新增的业绩
|
|
|
+
|
|
|
$allData = PerfOrder::findUseDbCalc()
|
|
|
- ->select('ID,SN,DEC_SN,DEC_TYPE,USER_ID,PV,PERIOD_NUM,CALC_MONTH')
|
|
|
+ ->select('ID,USER_ID, SUM(PV) AS MONTH_PV, CALC_MONTH')
|
|
|
->where('CALC_MONTH=:CALC_MONTH', [':CALC_MONTH' => $this->_calcYearMonth])
|
|
|
+ ->groupBy('USER_ID')
|
|
|
->orderBy('USER_ID DESC')
|
|
|
->offset($offset)
|
|
|
->limit($this->_limit)
|
|
|
->asArray()
|
|
|
->all();
|
|
|
+
|
|
|
if ($allData) {
|
|
|
foreach ($allData as $everyData) {
|
|
|
- // 记录pv分配,为了好找小组业绩,需要将即便是没有订单的用户也保存进去.
|
|
|
- // 这样,需要判断是否有用户,有的话,需要更新此用户的PV,把0改成正常的PV,不在重新插入了.
|
|
|
$userId = $everyData['USER_ID'];
|
|
|
- $pv = $everyData['PV'];
|
|
|
- $perfOrderId = $everyData['ID'];
|
|
|
+ $pv = $everyData['MONTH_PV'];
|
|
|
$userBaseInfo = CalcCache::getUserInfo($userId, $this->_periodNum);
|
|
|
+ $userNetWork = CalcCache::getUserNetWorkNewInfo($userId, $this->_periodNum);
|
|
|
+ // 记录有业绩单的用户
|
|
|
+ StorePerfLog::addOrUpdate(
|
|
|
+ $this->_periodNum,
|
|
|
+ $this->_calcYearMonth,
|
|
|
+ $userId,
|
|
|
+ [
|
|
|
+ 'USER_ID' => $userId,
|
|
|
+ 'IS_STUDIO' => $userBaseInfo['IS_STUDIO'],
|
|
|
+ 'MONTH_PV' => $pv,
|
|
|
+ 'PERIOD_NUM' => $this->_periodNum,
|
|
|
+ 'CALC_MONTH' => $this->_calcYearMonth,
|
|
|
+ 'CREATE_AT' => time(),
|
|
|
+ 'PARENT_UID' => $userNetWork['PARENT_UID']
|
|
|
+ ],
|
|
|
+ $pv
|
|
|
+ );
|
|
|
// 判断此用户是否是店铺,如果是店铺则累计此业绩到自己身上
|
|
|
if ($userBaseInfo['IS_STUDIO'] == 1) {
|
|
|
CalcCache::addHasPerfUsers($userId, $this->_periodNum);
|
|
|
CalcCache::nowPeriodPerf($userId, $this->_periodNum, [
|
|
|
'STORE_PV_GRAND' => $pv,
|
|
|
]);
|
|
|
-
|
|
|
- StorePerfLog::addOrUpdate(
|
|
|
- $this->_periodNum,
|
|
|
- $this->_calcYearMonth,
|
|
|
- $userId,
|
|
|
- [
|
|
|
- 'PERF_ORDER_ID' => $perfOrderId,
|
|
|
- 'USER_ID' => $userId,
|
|
|
- 'IS_STUDIO' => 1,
|
|
|
- 'PV' => $pv,
|
|
|
- 'PERIOD_NUM' => $this->_periodNum,
|
|
|
- 'CALC_MONTH' => $this->_calcYearMonth,
|
|
|
- 'CREATE_AT' => time(),
|
|
|
- ]
|
|
|
- );
|
|
|
} else {
|
|
|
- // 如果此用户不是店铺,则往上找用户上级,是否是店铺,并累计上去
|
|
|
- // 给上追加业绩
|
|
|
+ // 如果此用户不是店铺,继续上找到店铺并累加上去PV
|
|
|
$this->loopNetworkParentDo($userId, function ($parent) use (&$everyData) {
|
|
|
$parentUser = CalcCache::getUserInfo($parent['PARENT_UID'], $this->_periodNum);
|
|
|
+ $userNetWork = CalcCache::getUserNetWorkNewInfo($parent['PARENT_UID'], $this->_periodNum);
|
|
|
$isStudio = $parentUser['IS_STUDIO'] == 1 ? true : false;
|
|
|
+ $appendPv = $isStudio ? $everyData['MONTH_PV'] : 0;
|
|
|
StorePerfLog::addOrUpdate(
|
|
|
$this->_periodNum,
|
|
|
$this->_calcYearMonth,
|
|
|
$parent['PARENT_UID'],
|
|
|
[
|
|
|
- 'PERF_ORDER_ID' => $everyData['ID'],
|
|
|
'USER_ID' => $parent['PARENT_UID'],
|
|
|
- 'IS_STUDIO' => $parentUser['IS_STUDIO'],
|
|
|
- 'PV' => $everyData['PV'],
|
|
|
+ 'IS_STUDIO' => $isStudio,
|
|
|
+ 'MONTH_PV' => 0,
|
|
|
'PERIOD_NUM' => $this->_periodNum,
|
|
|
'CALC_MONTH' => $this->_calcYearMonth,
|
|
|
'CREATE_AT' => time(),
|
|
|
- ]
|
|
|
+ 'PARENT_UID' => $userNetWork['PARENT_UID']
|
|
|
+ ],
|
|
|
+ $appendPv
|
|
|
);
|
|
|
if ($isStudio) {
|
|
|
CalcCache::nowPeriodPerf($parent['PARENT_UID'], $this->_periodNum, [
|