|
|
@@ -31,6 +31,7 @@ use common\models\PerfStandard;
|
|
|
use common\models\Period;
|
|
|
use common\models\DecOrder;
|
|
|
use common\models\EmployLevel;
|
|
|
+use common\models\PerfActiveUser;
|
|
|
use common\models\UserRelation;
|
|
|
use yii\base\Exception;
|
|
|
use yii\base\StaticInstanceTrait;
|
|
|
@@ -171,18 +172,22 @@ class PerfCalc {
|
|
|
$this->loopWriteMonthPerf();
|
|
|
$t7 = microtime(true);
|
|
|
echo('本月业绩入库完成,耗时:' . round($t7 - $t6, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
|
|
|
- $this->_updatePercent(95);
|
|
|
+ $this->_updatePercent(90);
|
|
|
|
|
|
// //达标业绩
|
|
|
// $this->loopCalcPerfByStandardFXOrder();
|
|
|
// //达标业绩入库
|
|
|
// $this->loopWriteStandardPerf();
|
|
|
- $t8 = microtime(true);
|
|
|
+ $t9 = microtime(true);
|
|
|
//echo('本月业绩入库完成,耗时:' . round($t8 - $t7, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
|
|
|
- $this->_updatePercent(100);
|
|
|
+ $this->_updatePercent(95);
|
|
|
|
|
|
+ $t10 = microtime(true);
|
|
|
+ // 通过插入到perforder中的业绩订单数据,生成此业绩期活跃用户数据
|
|
|
+ $this->loopWriteActiveUser();
|
|
|
+ $this->_updatePercent(100);
|
|
|
|
|
|
- echo('结算全部完成,共耗时:' . round($t8 - $t1, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
|
|
|
+ echo('结算全部完成,共耗时:' . round($t10 - $t9, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
|
|
|
} catch (\Exception $e) {
|
|
|
$this->errorCalcTask();
|
|
|
$this->addError('calc', $e->getMessage());
|
|
|
@@ -282,6 +287,8 @@ class PerfCalc {
|
|
|
PerfPeriod::pageDeleteAll('PERIOD_NUM='.$this->_periodNum);
|
|
|
// 业绩单
|
|
|
PerfOrder::pageDeleteAll('PERIOD_NUM='.$this->_periodNum);
|
|
|
+ // 删除活跃用户
|
|
|
+ PerfActiveUser::pageDeleteAll('PERIOD_NUM='.$this->_periodNum.' AND IS_SENT=0 ');
|
|
|
// 月结时要清空的数据
|
|
|
if ($this->_isCalcMonth) {
|
|
|
// 月业绩表
|
|
|
@@ -291,6 +298,106 @@ class PerfCalc {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 循环判断活跃会员,并入库
|
|
|
+ * @param int $offset
|
|
|
+ * @return bool
|
|
|
+ * @throws \yii\db\Exception
|
|
|
+ */
|
|
|
+ public function loopWriteActiveUser($offset = 0) {
|
|
|
+ echo sprintf("时间:[%s]本期活跃用户PerfOrder表中,当前offset为:【%s】" . PHP_EOL, date('Y-m-d H:i:s', time()) , $offset);
|
|
|
+ // 从PerfOrder表中获取此周期的用户数据
|
|
|
+ $data = PerfPeriod::findUseDbCalc()
|
|
|
+ ->select('USER_ID')
|
|
|
+ ->where('PERIOD_NUM=:PERIOD_NUM',[
|
|
|
+ ':PERIOD_NUM' => $this->_periodNum
|
|
|
+ ])->offset($offset)->limit($this->_limit)->asArray()->all();
|
|
|
+ if ($data) {
|
|
|
+ foreach ($data as $upv) {
|
|
|
+ $userId = $upv['USER_ID'];
|
|
|
+ // 判断用户每周是否是活跃用户
|
|
|
+ $allData = PerfOrder::findUseDbCalc()
|
|
|
+ ->select('USER_ID,PV,DEC_AMOUNT,PERIOD_NUM,CALC_MONTH,P_CALC_MONTH, DEC_SN,ORDER_CREATED_AT')
|
|
|
+ ->where('PERIOD_NUM=:PERIOD_NUM',[
|
|
|
+ ':PERIOD_NUM' => $this->_periodNum
|
|
|
+ ])
|
|
|
+ ->where('USER_ID=:USER_ID',[
|
|
|
+ ':USER_ID' => $userId
|
|
|
+ ])
|
|
|
+ ->where('IS_SENT=:IS_SENT',[
|
|
|
+ ':IS_SENT' => 0
|
|
|
+ ])
|
|
|
+ ->orderBy('ORDER_CREATED_AT DESC')
|
|
|
+ ->asArray()
|
|
|
+ ->all();
|
|
|
+ if($allData) {
|
|
|
+ $this->weekMonthOrder($allData);
|
|
|
+
|
|
|
+ unset($insertDataPeriodPerf, $allData);
|
|
|
+ }
|
|
|
+
|
|
|
+ unset($allData);
|
|
|
+ }
|
|
|
+
|
|
|
+ unset($data);
|
|
|
+ return $this->loopWriteActiveUser($offset + $this->_limit);
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 活跃判断
|
|
|
+ public function weekMonthOrder($data) {
|
|
|
+ // 获取每个订单是周几,把他们分别放到各自的周里面.
|
|
|
+ // 因为是自然月,所以需要知道是此月的几号,是此月的第几周.然后往前和往后推出时间戳范围内pv的累计之和是多少
|
|
|
+ $one = 24*60*60; // 一天的时间戳
|
|
|
+ $time_arr = [];
|
|
|
+ foreach ($data as $orders) {
|
|
|
+ $day = intval(date('d', $orders['ORDER_CREATED_AT'])); // 当月第多少号
|
|
|
+ $weekDay = (date('w', $orders['ORDER_CREATED_AT']) == 0) ? 7 : date('w', $orders['ORDER_CREATED_AT']);// 周几 1-7
|
|
|
+ $format = date('Y-m-d', $orders['ORDER_CREATED_AT']);
|
|
|
+ $orderDayStart = strtotime($format.' 0:0:0');
|
|
|
+ $orderDayEnd = strtotime($format.' 23:59:59');
|
|
|
+ $caluc = 7-$weekDay;
|
|
|
+ $calucWeekStart = $orderDayStart - $caluc*$one;
|
|
|
+ $calucWeekEnd = $orderDayEnd + $caluc*$one;
|
|
|
+ if (!isset($time_arr[$calucWeekStart])) {
|
|
|
+ $time_arr[$calucWeekStart] = array_merge($orders, [
|
|
|
+ 'temp_start' => $calucWeekStart,
|
|
|
+ 'temp_end' => $calucWeekEnd,
|
|
|
+ 'calculate_total_pv' => $orders['PV']
|
|
|
+ ]);
|
|
|
+ } else {
|
|
|
+ $time_arr[$calucWeekStart]['calculate_total_pv'] = $time_arr[$calucWeekStart]['calculate_total_pv'] + $orders['PV'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ unset($data);
|
|
|
+ $insert = [];
|
|
|
+ // 循环判断,当周pv累计是否达到400
|
|
|
+ foreach ($time_arr as $k => $v) {
|
|
|
+ if ($v['calculate_total_pv'] >= $this->_sysConfig['activeUserPvCondition']['VALUE']) {
|
|
|
+ // 如果个人业累计绩达400PV,取得连续四周活跃
|
|
|
+ // 取出周末再增加三周的时间戳
|
|
|
+ $insert[] = [
|
|
|
+ 'ID' => SnowFake::instance()->generateId(),
|
|
|
+ 'USER_ID' => $v['USER_ID'],
|
|
|
+ 'PERIOD_NUM' => $v['PERIOD_NUM'],
|
|
|
+ 'CALC_MONTH' => $v['CALC_MONTH'],
|
|
|
+ 'P_CALC_MONTH' => $v['P_CALC_MONTH'],
|
|
|
+ 'SRATR_AT' => $v['temp_start'],
|
|
|
+ 'END_AT' => $v['temp_end']+(3*7*24*60*60),
|
|
|
+ 'CREATED_AT' => time(),
|
|
|
+ 'PV' => $v['calculate_total_pv'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ PerfActiveUser::batchInsert($insert);
|
|
|
+
|
|
|
+ unset($insert);
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 周结,向上级算业绩,并计入业绩单
|
|
|
* @param int $offset
|
|
|
@@ -392,6 +499,7 @@ class PerfCalc {
|
|
|
'P_CALC_MONTH' => Date::ociToDate($this->_calcYearMonth, Date::OCI_TIME_FORMAT_SHORT_MONTH),
|
|
|
'CREATED_AT' => Date::nowTime(),
|
|
|
'CLOSED_AT' => 0,
|
|
|
+ 'ORDER_CREATED_AT' => $data['CREATED_AT'],
|
|
|
];
|
|
|
unset($data, $decInfo, $sn, $toInfo);
|
|
|
}
|
|
|
@@ -411,7 +519,7 @@ class PerfCalc {
|
|
|
*/
|
|
|
public function loopCalcPeriodPerfByOrderDec($offset = 0) {
|
|
|
// 循环获取全部报单
|
|
|
- $allData = OrderDec::findUseDbCalc()->select('ID,SN,USER_ID,ORDER_TYPE,ORDER_AMOUNT,PV,PAY_AMOUNT,PAY_PV,PERIOD_NUM,PAY_TYPE')->where("PERIOD_NUM=:PERIOD_NUM AND IS_DELETE=0 AND ORDER_TYPE=:ORDER_TYPE", [':PERIOD_NUM' => $this->_periodNum, ':ORDER_TYPE'=>'ZC'])->orderBy('ID DESC')->offset($offset)->limit($this->_limit)->asArray()->all();
|
|
|
+ $allData = OrderDec::findUseDbCalc()->select('CREATED_AT,ID,SN,USER_ID,ORDER_TYPE,ORDER_AMOUNT,PV,PAY_AMOUNT,PAY_PV,PERIOD_NUM,PAY_TYPE')->where("PERIOD_NUM=:PERIOD_NUM AND IS_DELETE=0 AND ORDER_TYPE=:ORDER_TYPE", [':PERIOD_NUM' => $this->_periodNum, ':ORDER_TYPE'=>'ZC'])->orderBy('ID DESC')->offset($offset)->limit($this->_limit)->asArray()->all();
|
|
|
if ($allData) {
|
|
|
$insertPerfOrderData = [];
|
|
|
foreach ($allData as $data) {
|
|
|
@@ -493,6 +601,7 @@ class PerfCalc {
|
|
|
'P_CALC_MONTH' => Date::ociToDate($this->_calcYearMonth, Date::OCI_TIME_FORMAT_SHORT_MONTH),
|
|
|
'CREATED_AT' => Date::nowTime(),
|
|
|
'CLOSED_AT' => 0,
|
|
|
+ 'ORDER_CREATED_AT' => $data['CREATED_AT']
|
|
|
];
|
|
|
unset($data, $decInfo, $sn, $toInfo);
|
|
|
}
|
|
|
@@ -615,6 +724,7 @@ class PerfCalc {
|
|
|
'P_CALC_MONTH' => Date::ociToDate($this->_calcYearMonth, Date::OCI_TIME_FORMAT_SHORT_MONTH),
|
|
|
'CREATED_AT' => Date::nowTime(),
|
|
|
'CLOSED_AT' => 0,
|
|
|
+ 'ORDER_CREATED_AT' => $data['CREATED_AT']
|
|
|
];
|
|
|
unset($data, $baseInfo, $sn, $orderCashAmount, $payPv, $cacheDataKey);
|
|
|
}
|
|
|
@@ -730,6 +840,7 @@ class PerfCalc {
|
|
|
'P_CALC_MONTH' => Date::ociToDate($this->_calcYearMonth, Date::OCI_TIME_FORMAT_SHORT_MONTH),
|
|
|
'CREATED_AT' => Date::nowTime(),
|
|
|
'CLOSED_AT' => 0,
|
|
|
+ 'ORDER_CREATED_AT' => $data['CREATED_AT']
|
|
|
];
|
|
|
unset($data, $baseInfo, $sn, $orderCashAmount, $payPv, $cacheDataKey);
|
|
|
}
|