LogController.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: leo
  5. * Date: 2018/3/9
  6. * Time: 上午11:56
  7. */
  8. namespace console\controllers;
  9. use backendApi\modules\v1\models\lists\bonus\FlowBonusList;
  10. use backendApi\modules\v1\models\lists\log\UserLoginList;
  11. use common\helpers\Cache;
  12. use common\libs\export\module\BonusExport;
  13. use console\libs\logging\OperateAsync;
  14. class LogController extends BaseController
  15. {
  16. /**
  17. * 异步保存日志
  18. * @param $taskKey
  19. */
  20. public function actionSave($taskKey){
  21. $params = Cache::getAsyncParams($taskKey);
  22. $operate = new OperateAsync([], $params);
  23. if(!$operate->asyncSave()){
  24. // 记录错误系统日志
  25. }
  26. }
  27. /**
  28. * 奖金流水列表导出
  29. * @param $taskId
  30. * @return bool
  31. */
  32. public function actionUserLoginExport($taskId){
  33. return $this->_export($taskId, UserLoginList::class, '会员登录日志');
  34. }
  35. /**
  36. * 导出方法
  37. * @param $taskId
  38. * @param $className
  39. * @param $listName
  40. * @return bool
  41. */
  42. private function _export($taskId, $className, $listName){
  43. $factory = BonusExport::factory($taskId);
  44. $factory->listModelClass = $className;
  45. try {
  46. if ($factory->generate()) {
  47. \Yii::$app->swooleAsyncTimer->pushAsyncResultToAdmin($factory->getUserId(), $listName.'导出成功');
  48. }
  49. unset($factory, $taskId, $className, $listName);
  50. return true;
  51. } catch (\Exception $e) {
  52. echo $listName.'导出失败。详情:' . $e->getMessage();
  53. \Yii::$app->swooleAsyncTimer->pushAsyncResultToAdmin($factory->getUserId(), $listName.'导出失败。详情:' . $e->getMessage(), false);
  54. }
  55. unset($factory, $taskId, $className, $listName);
  56. return false;
  57. }
  58. }