db->close(); if (!LockHelper::lock($lock_key, $identification, 30, 60)) throw new \Exception('业绩进入待结算,当前访问过多'); // 获取当前系统所有可用的 mall_id $now = time(); // $now ='1647219869';//调测使用 $grant_list = AchievementGrantLog::find()->where(['is_wait' => 0, 'status' => StatusEnum::ENABLED]) ->andWhere(['<=', 'wait_settlement_time', $now]) ->all(); if (!empty($grant_list)) { foreach ($grant_list as $grant) { $grant->is_wait = 1; $grant->save(); // $res = AchievementLogic::toBeSettled($grant['id']); // if ($res === false) throw new \Exception(AchievementLogic::getStaticError()); //更新所有不结算的数据 奖励金额为0 AchievementAwardLog::updateSkipSettlement($grant['id']); //更新周期统计 AchievementOrderLogic::updateGrant($grant); } } LockHelper::uLock($lock_key,$identification); return ExitCode::OK; } catch (\Exception $e) { LockHelper::uLock($lock_key,$identification); $errmsg = '业绩进入待结算: errmsg => ' . $e->getMessage() . ', file: ' . $e->getFile() . ', line: ' . $e->getLine(); echo $errmsg . PHP_EOL; \Yii::error($errmsg); \Yii::getLogger()->flush(true); return false; } } /** * 定时任务,结算业绩 */ public static function actionAutoGrantAchievement() { $lock_key = RedisKeyEnum::suffix(RedisKeyEnum::LOCK_ACHIEVEMENT_GRANT); $identification = uniqid(); try { \Yii::$app->db->close(); if (!LockHelper::lock($lock_key, $identification, 30, 60)) throw new \Exception('结算业绩,当前访问过多'); $now = time(); // $now ='1647219869';//调测使用 $grant_list = AchievementGrantLog::find()->where(['is_wait' => 1, 'is_settlement' => 0, 'status' => StatusEnum::ENABLED]) ->andWhere(['<=', 'settlement_time', $now])->all(); if (!empty($grant_list)) { foreach ($grant_list as $grant) { if ($grant['is_award_need_confirm']) { //开启业绩审核确认模式先不处理 continue; } $res = AchievementLogic::grantAchievement($grant['id']); if ($res === false) throw new \Exception(AchievementLogic::getStaticError()); } } LockHelper::uLock($lock_key,$identification); } catch (\Exception $e) { LockHelper::uLock($lock_key,$identification); $errmsg = '结算业绩: errmsg => ' . $e->getMessage() . ', file: ' . $e->getFile() . ', line: ' . $e->getLine(); echo $errmsg . PHP_EOL; \Yii::error($errmsg); \Yii::getLogger()->flush(true); return false; } } /** * 定时任务,整点添加规则 */ public static function actionAutoAddGrantLog() { $lock_key = RedisKeyEnum::suffix(RedisKeyEnum::LOCK_ACHIEVEMENT_ADD_GRANT_LOG); $identification = uniqid(); try { \Yii::$app->db->close(); if (!LockHelper::lock($lock_key, $identification, 30, 60)) throw new \Exception('整点添加规则,当前访问过多'); $malls = Mall::getEnableMallList(); $mall_ids = array_column($malls, 'id'); echo ' 获取到的 mall_id => ' . implode(', ', $mall_ids) . PHP_EOL; foreach ($mall_ids as $mall_id) { $res = AchievementLogic::addGrantLog($mall_id); if ($res === false) throw new \Exception(AchievementLogic::getStaticError()); } LockHelper::uLock($lock_key,$identification); } catch (\Exception $e) { LockHelper::uLock($lock_key,$identification); $errmsg = '整点添加规则: errmsg => ' . $e->getMessage() . ', file: ' . $e->getFile() . ', line: ' . $e->getLine(); echo $errmsg . PHP_EOL; \Yii::error($errmsg); \Yii::getLogger()->flush(true); return false; } } public function actionTest() { // 13899 13900 13901 $order = Order::findOne(13901); AchievementOrderLogic::orderStatistics($order);//统计业绩 } }