| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326 |
- <?php
- namespace common\models;
- use common\helpers\snowflake\SnowFake;
- use Exception;
- use Yii;
- /**
- * This is the model class for table "{{%SERVE_LOG}}".
- *
- * @property string $ID
- * @property string $PERIOD_NUM 业绩期
- * @property string $LOG_DESCRIBE 日志信息
- * @property string $CREATE_AT 创建时间
- * @property string $CALC_MONTH 结算年月
- */
- class ServeLog extends \common\components\ActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%SERVE_LOG}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['PERIOD_NUM', 'CALC_MONTH', 'CREATE_AT'], 'required'],
- [['ID'], 'unique'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'ID' => 'ID',
- 'PERIOD_NUM' => '业绩期',
- 'LOG_DESCRIBE' => '描述信息',
- 'CALC_MONTH' => '总人数',
- 'CREATE_AT' => '总业绩',
- ];
- }
- // =============================业绩相关日志==========================================================================
- /**
- * 无逻辑日志,直接传文案
- * @param int $periodNum
- * @param int $calcMonth 业绩期
- */
- public static function noParamsLog($periodNum, $calcMonth, $desc) {
- $logData[] = [
- 'PERIOD_NUM' => $periodNum,
- 'CALC_MONTH' => $calcMonth,
- 'LOG_DESCRIBE' => $desc,
- 'CREATE_AT' => time()
- ];
- ServeLog::batchInsert($logData);
- return true;
- }
-
- // 第一步,记录期数结算年月
- /**
- * 记录业绩期,结算年月
- * @param int $periodNum
- * @param int $calcMonth 业绩期
- */
- public static function periodMonth($periodNum, $calcMonth) {
- $logData[] = [
- 'PERIOD_NUM' => $periodNum,
- 'CALC_MONTH' => $calcMonth,
- 'LOG_DESCRIBE' => "期数:$periodNum,结算年月:$calcMonth,开始计算业绩",
- 'CREATE_AT' => time()
- ];
- ServeLog::batchInsert($logData);
- return true;
- }
- /**
- * 记录推送过来的基础数据
- * @param int $periodNum
- * @param int $calcMonth 业绩期
- */
- public static function basicData($periodNum, $calcMonth) {
- $userCount = User::find()->where('1=1')->count('ID');
- $infoCount = UserInfo::find()->where('1=1')->count('ID');
- $networkConut = UserNetwork::find()->where('1=1')->count('ID');
- $userPerfConut = UserPerf::find()->where('1=1')->count('ID');
- $calcBonusQyConut = CalcBonusQY::find()->where('1=1')->count('ID');
- $perfPeriodCount = PerfPeriod::find()->where('1=1')->count('ID');
- $perfOrderCount = PerfOrder::find()->where('1=1')->count('ID');
- $relationCount = UserRelation::find()->where('1=1')->count('ID');
- $periodCount = Period::find()->where('1=1')->count('ID');
- $perfMonthCount = PerfMonth::find()->where('1=1')->count('ID');
- $desc = "记录推送基础数据信息:AR_USER-推送用户总条数:$userCount;AR_USER_INFO-推送用户信息总条数:$infoCount;
- AR_USER_NETWORK_NEW-推送安置网络总条数:$networkConut;AR_USER_PERF-推送用户结余业绩总条数:$userPerfConut;
- AR_CALC_BONUS_QY-推送团队奖总条数:$calcBonusQyConut;AR_PERF_PERIOD-推送期业绩总条数:$perfPeriodCount;
- AR_PERIOD-推送业绩期总条数:$periodCount;AR_USER_RELATION_NEW-推送开拓网络总条数:$relationCount;
- AR_PERF_MONTH-推送月业绩表总条数:$perfMonthCount;AR_PERF_ORDER-推送业绩单总条数:$perfOrderCount";
- $logData[] = [
- 'PERIOD_NUM' => $periodNum,
- 'CALC_MONTH' => $calcMonth,
- 'LOG_DESCRIBE' => $desc,
- 'CREATE_AT' => time()
- ];
- ServeLog::batchInsert($logData);
- return true;
- }
- /**
- * 记录清除的期业绩和月业绩
- * @param int $periodNum
- * @param int $calcMonth 业绩期
- */
- public static function clearPerf($periodNum, $calcMonth) {
- $perfPeriodCount = PerfPeriod::find()
- ->where('PERIOD_NUM=:PERIOD_NUM', [':PERIOD_NUM'=>$periodNum])
- ->count('ID');
- $perfMonthCount = PerfMonth::find()
- ->where('CALC_MONTH=:CALC_MONTH', [':CALC_MONTH'=>$calcMonth])
- ->count('ID');
- $desc = "清除业绩数据:AR_PERF_PERIOD-清除期业绩表总条数:$perfPeriodCount;AR_PERF_MONTH-清除月业绩表总条数:$perfMonthCount";
- $logData[] = [
- 'PERIOD_NUM' => $periodNum,
- 'CALC_MONTH' => $calcMonth,
- 'LOG_DESCRIBE' => $desc,
- 'CREATE_AT' => time()
- ];
- ServeLog::batchInsert($logData);
- return true;
- }
- /**
- * 记录缓存用户数据
- * @param int $periodNum
- * @param int $calcMonth 业绩期
- */
- public static function cacheUserTotal($periodNum, $calcMonth) {
- $allUserCount = UserInfo::findUseDbCalc()
- ->from(UserInfo::tableName(). 'AS UI')
- ->select('UI.USER_ID,U.STATUS')
- ->leftJoin(User::tableName() . 'AS U', 'U.ID=UI.USER_ID')
- ->where('1=1')
- ->count('UI.USER_ID');
- $activeUserCount = UserInfo::findUseDbCalc()
- ->from(UserInfo::tableName(). 'AS UI')
- ->select('UI.USER_ID,U.STATUS')
- ->leftJoin(User::tableName() . 'AS U', 'U.ID=UI.USER_ID')
- ->where('U.STATUS=1')
- ->count('UI.USER_ID');
- $total = $allUserCount+$activeUserCount;
- $desc = "缓存用户信息-结束,缓存数量:$total";
- $logData[] = [
- 'PERIOD_NUM' => $periodNum,
- 'CALC_MONTH' => $calcMonth,
- 'LOG_DESCRIBE' => $desc,
- 'CREATE_AT' => time()
- ];
- ServeLog::batchInsert($logData);
- return true;
- }
- /**
- * 记录期业绩数据
- * @param int $periodNum
- * @param int $calcMonth 业绩期
- */
- public static function perfPeriodInfo($periodNum, $calcMonth) {
- $data = PerfPeriod::findUseSlaves()
- ->select('SUM(PV_PCS) AS TOTAL_PV_PCS, COUNT(ID) AS TOTAL_NUM')
- ->where('PERIOD_NUM=:PERIOD_NUM', ['PERIOD_NUM'=>$periodNum])
- ->asArray()
- ->one();
- $num = $data['TOTAL_NUM'];
- $total_pvpcs = $data['TOTAL_NUM'];
- $desc = "期业绩计算完成:AR_PERF_PERIOD-期业绩总条数:$num,期业绩个人消费PV总数:$total_pvpcs";
- $logData[] = [
- 'PERIOD_NUM' => $periodNum,
- 'CALC_MONTH' => $calcMonth,
- 'LOG_DESCRIBE' => $desc,
- 'CREATE_AT' => time()
- ];
- ServeLog::batchInsert($logData);
- return true;
- }
- /**
- * 记录月业绩数据
- * @param int $periodNum
- * @param int $calcMonth 业绩期
- */
- public static function perfMonthInfo($periodNum, $calcMonth) {
- $data = PerfMonth::findUseSlaves()
- ->select('SUM(PV_PCS) AS TOTAL_PV_PCS, COUNT(ID) AS TOTAL_NUM')
- ->where('CALC_MONTH=:CALC_MONTH', ['CALC_MONTH'=>$calcMonth])
- ->asArray()
- ->one();
- $num = $data['TOTAL_NUM'];
- $total_pvpcs = $data['TOTAL_NUM'];
- $desc = "月业绩计算完成:AR_PERF_MONTH-月业绩表总条数:$num,月业绩个人消费总数:$total_pvpcs";
- $logData[] = [
- 'PERIOD_NUM' => $periodNum,
- 'CALC_MONTH' => $calcMonth,
- 'LOG_DESCRIBE' => $desc,
- 'CREATE_AT' => time()
- ];
- ServeLog::batchInsert($logData);
- return true;
- }
- /**
- * 记录期业绩活跃数据
- * @param int $periodNum
- * @param int $calcMonth 业绩期
- */
- public static function perfPeriodActive($periodNum, $calcMonth) {
- $data = PerfPeriod::findUseSlaves()
- ->select('COUNT(ID) AS TOTAL_NUM')
- ->where('PERIOD_NUM=:PERIOD_NUM AND IS_ACTIVE=1', ['PERIOD_NUM'=>$periodNum])
- ->asArray()
- ->one();
- $num = $data['TOTAL_NUM'];
- $desc = "期业绩更新活跃状态,活跃人数:$num";
- $logData[] = [
- 'PERIOD_NUM' => $periodNum,
- 'CALC_MONTH' => $calcMonth,
- 'LOG_DESCRIBE' => $desc,
- 'CREATE_AT' => time()
- ];
- ServeLog::batchInsert($logData);
- return true;
- }
-
-
-
-
-
-
-
-
- // =============================奖金相关日志=====================================================================================
-
- // ------以下为记录操作流程
- // 记录请求时间
- public static function recordRequest($time, $periodNum, $desc = '', $needCheck = false) {
- // 查询此期是否存在计算中,如果在计算中则不用记录
- if ($needCheck) {
- $hasPerpare = Period::findUseSlaves()
- ->select('ID')
- ->where('PERIOD_NUM=:PERIOD_NUM AND IS_PREPARE=1', [':PERIOD_NUM'=>$periodNum])
- ->asArray()
- ->one();
- if (empty($hasPerpare)) {
- return true;
- }
- }
- $logData[] = [
- 'ID' => SnowFake::instance()->generateId(),
- 'PERIOD_NUM' => $periodNum ?: 0,
- 'TASK_TYPE' => 'serve',
- 'TASK_DESCRIBE' => $desc ?: '请求服务开始',
- 'START_AT' => $time
- ];
- ServeProcess::batchInsert($logData);
- return true;
- }
- // 记录计算基础数据
- public static function recordDataInfo($time, $periodNum) {
- $userCount = User::find()->where('1=1')->count('ID'); // user表总数
- $perfSum = PerfOrder::find()->where('1=1')->sum('PV');// 业绩单总业绩
- $infoCount = UserInfo::find()->where('1=1')->count('ID'); // userinfo表总数
- $networkConut = UserNetwork::find()->where('1=1')->count('ID'); // UserNetwork总数
- $relationCount = UserRelation::find()->where('1=1')->count('ID'); // UserRelation
- $logData[] = [
- 'ID' => SnowFake::instance()->generateId(),
- 'PERIOD_NUM' => $periodNum ?: 0,
- 'TASK_TYPE' => 'serve',
- 'TASK_DESCRIBE' => '统计业务系统数据信息',
- 'START_AT' => $time,
- 'CALC_USER_TOTAL' => $userCount > 0 ? $userCount : 0,
- 'CALC_PERF_TOTAL' => $perfSum > 0 ? $perfSum : 0,
- 'CALC_USERINFO_TOTAL' => $infoCount > 0 ? $infoCount : 0,
- 'CALC_NETWORK_TOTAL' => $networkConut > 0 ? $networkConut : 0,
- 'CALC_RELATION_TOTAL' => $relationCount > 0 ? $relationCount :0
- ];
- ServeProcess::batchInsert($logData);
- }
- // 记录流程
- public static function recordProcess($start, $end, $periodNum, $desc, $type='perf') {
- try {
- $logData[] = [
- 'ID' => SnowFake::instance()->generateId(),
- 'PERIOD_NUM' => $periodNum ?: 0,
- 'TASK_TYPE' => $type,
- 'START_AT' => $start,
- 'END_AT' => $end,
- 'TASK_DESCRIBE' => $desc,
- ];
- ServeProcess::batchInsert($logData);
- } catch (Exception $e) {
- var_dump($e->getMessage());
- }
- }
- }
|