WriteOffCrontabController.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace addons\WriteOff\console\controllers;
  3. use addons\WriteOff\common\logic\RewardLogic;
  4. use common\enums\RedisKeyEnum;
  5. use common\enums\StatusEnum;
  6. use common\helpers\LockHelper;
  7. use common\models\mall\Mall;
  8. use yii\console\Controller;
  9. use yii\console\ExitCode;
  10. class WriteOffCrontabController extends Controller
  11. {
  12. public function actionSettle()
  13. {
  14. $lock_key = RedisKeyEnum::suffix('write_off_achievement_settle');
  15. $identification = uniqid();
  16. try {
  17. \Yii::$app->db->close();
  18. if (!LockHelper::lock($lock_key, $identification, 30, 60)) throw new \Exception('业绩进入待结算,当前访问过多');
  19. // 获取当前系统所有可用的 mall_id
  20. $mall_list = Mall::getEnableMallList(true);
  21. if(!empty($mall_list)){
  22. foreach($mall_list as $mall){
  23. RewardLogic::achievementPromoteReward($mall['id']);
  24. }
  25. }
  26. LockHelper::uLock($lock_key,$identification);
  27. return ExitCode::OK;
  28. } catch (\Exception $e) {
  29. LockHelper::uLock($lock_key,$identification);
  30. $errmsg = '业绩结算: errmsg => ' . $e->getMessage() . ', file: ' . $e->getFile() . ', line: ' . $e->getLine();
  31. echo $errmsg . PHP_EOL;
  32. \Yii::error($errmsg);
  33. \Yii::getLogger()->flush(true);
  34. return false;
  35. }
  36. }
  37. }