|
|
@@ -32,6 +32,7 @@ use common\models\Period;
|
|
|
use common\models\DecOrder;
|
|
|
use common\models\EmployLevel;
|
|
|
use common\models\PerfActiveUser;
|
|
|
+use common\models\StorePerfLog;
|
|
|
use common\models\UserRelation;
|
|
|
use yii\base\Exception;
|
|
|
use yii\base\StaticInstanceTrait;
|
|
|
@@ -174,12 +175,18 @@ class PerfCalc {
|
|
|
echo('本月业绩入库完成,耗时:' . round($t7 - $t6, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
|
|
|
$this->_updatePercent(90);
|
|
|
|
|
|
- // //达标业绩
|
|
|
- $this->loopCalcPerfByStandardFXOrder();
|
|
|
- // //达标业绩入库
|
|
|
- $this->loopWriteStandardPerf();
|
|
|
+ // 店服务奖/月节点
|
|
|
+ $this->storePerf();
|
|
|
+ $t8 = microtime(true);
|
|
|
+ echo('店服务业绩计算,耗时:' . round($t8 - $t7, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
|
|
|
+ $this->_updatePercent(95);
|
|
|
+
|
|
|
+ // // //达标业绩
|
|
|
+ // $this->loopCalcPerfByStandardFXOrder();
|
|
|
+ // // //达标业绩入库
|
|
|
+ // $this->loopWriteStandardPerf();
|
|
|
$t9 = microtime(true);
|
|
|
- echo('本月业绩入库完成,耗时:' . round($t9 - $t7, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
|
|
|
+ echo('本月业绩入库完成,耗时:' . round($t9 - $t8, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
|
|
|
$this->_updatePercent(95);
|
|
|
|
|
|
|
|
|
@@ -294,6 +301,8 @@ class PerfCalc {
|
|
|
if ($this->_isCalcMonth) {
|
|
|
// 月业绩表
|
|
|
PerfMonth::pageDeleteAll("CALC_MONTH='{$this->_calcYearMonth}'");
|
|
|
+ // 店服务业绩log表
|
|
|
+ StorePerfLog::pageDeleteAll("CALC_MONTH='{$this->_calcYearMonth}'");
|
|
|
//达标业绩表
|
|
|
PerfStandard::pageDeleteAll("CALC_MONTH='{$this->_calcYearMonth}'");
|
|
|
}
|
|
|
@@ -1165,6 +1174,96 @@ class PerfCalc {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 店服务奖,循环结算月所有数据,并计算小组业绩
|
|
|
+ * @param int $offset
|
|
|
+ * @return bool
|
|
|
+ * @throws \yii\db\Exception
|
|
|
+ */
|
|
|
+ public function storePerf($offset = 0) {
|
|
|
+ if(!$this->_isCalcMonth){
|
|
|
+ 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')
|
|
|
+ ->where('CALC_MONTH=:CALC_MONTH', [':CALC_MONTH' => $this->_calcYearMonth])
|
|
|
+ ->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'];
|
|
|
+ $userBaseInfo = CalcCache::getUserInfo($userId, $this->_periodNum);
|
|
|
+ // 判断此用户是否是店铺,如果是店铺则累计此业绩到自己身上
|
|
|
+ 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 {
|
|
|
+ // 如果此用户不是店铺,则往上找用户上级,是否是店铺,并累计上去
|
|
|
+ // 给上追加业绩
|
|
|
+ $this->loopNetworkParentDo($userId, function ($parent) use (&$everyData) {
|
|
|
+ $parentUser = CalcCache::getUserInfo($parent['PARENT_UID'], $this->_periodNum);
|
|
|
+ $isStudio = $parentUser['IS_STUDIO'] == 1 ? true : false;
|
|
|
+ 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'],
|
|
|
+ 'PERIOD_NUM' => $this->_periodNum,
|
|
|
+ 'CALC_MONTH' => $this->_calcYearMonth,
|
|
|
+ 'CREATE_AT' => time(),
|
|
|
+ ]
|
|
|
+ );
|
|
|
+ if ($isStudio) {
|
|
|
+ CalcCache::nowPeriodPerf($parent['PARENT_UID'], $this->_periodNum, [
|
|
|
+ 'STORE_PV_GRAND' => $everyData['PV']
|
|
|
+ ]);
|
|
|
+ CalcCache::addHasPerfUsers($parent['PARENT_UID'], $this->_periodNum);
|
|
|
+
|
|
|
+ return self::LOOP_FINISH;
|
|
|
+ }
|
|
|
+
|
|
|
+ unset($parent);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ unset($allData);
|
|
|
+ return $this->storePerf($offset + $this->_limit);
|
|
|
+ }
|
|
|
+
|
|
|
+ unset($allData);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 循环达标业绩会员,并入库
|