ProvinceGatherLogController.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace addons\RfDevTool\backend\controllers;
  3. use Yii;
  4. use common\traits\Curd;
  5. use common\enums\StatusEnum;
  6. use common\models\base\SearchModel;
  7. use common\helpers\ArrayHelper;
  8. use addons\RfDevTool\common\queues\ProvinceChildJob;
  9. use addons\RfDevTool\common\models\ProvinceGatherLog;
  10. /**
  11. * Class ProvinceGatherLogController
  12. * @package addons\RfDevTool\backend\controllers
  13. * @author jianyan74 <751393839@qq.com>
  14. */
  15. class ProvinceGatherLogController extends BaseController
  16. {
  17. use Curd;
  18. /**
  19. * @var ProvinceGatherLog
  20. */
  21. public $modelClass = ProvinceGatherLog::class;
  22. /**
  23. * @return string
  24. * @throws \yii\web\NotFoundHttpException
  25. */
  26. public function actionIndex()
  27. {
  28. $job_id = Yii::$app->request->get('job_id');
  29. $searchModel = new SearchModel([
  30. 'model' => ProvinceGatherLog::class,
  31. 'scenario' => 'default',
  32. 'partialMatchAttributes' => [], // 模糊查询
  33. 'defaultOrder' => [
  34. 'id' => SORT_DESC
  35. ],
  36. 'pageSize' => $this->pageSize
  37. ]);
  38. $dataProvider = $searchModel
  39. ->search(Yii::$app->request->queryParams);
  40. $dataProvider->query
  41. ->andWhere(['job_id' => $job_id])
  42. ->andWhere(['reconnection' => 0])
  43. ->andWhere(['status' => StatusEnum::ENABLED]);
  44. return $this->render('index', [
  45. 'searchModel' => $searchModel,
  46. 'dataProvider' => $dataProvider,
  47. ]);
  48. }
  49. /**
  50. * ajax编辑/创建
  51. *
  52. * @return mixed|string|\yii\web\Response
  53. * @throws \yii\base\ExitException
  54. */
  55. public function actionAjaxEdit()
  56. {
  57. $id = Yii::$app->request->get('id');
  58. $model = $this->findModel($id);
  59. if (Yii::$app->request->isPost) {
  60. $data = ArrayHelper::filter(Yii::$app->request->post(), ['chlidPrefix', 'chlidLink']);
  61. $model->data = ArrayHelper::merge($model->data, $data);
  62. return $model->save()
  63. ? $this->redirect(Yii::$app->request->referrer)
  64. : $this->message($this->getError($model), $this->redirect(Yii::$app->request->referrer), 'error');
  65. }
  66. return $this->renderAjax($this->action->id, [
  67. 'model' => $model,
  68. ]);
  69. }
  70. /**
  71. * @param $id
  72. * @return mixed
  73. */
  74. public function actionRetry($id)
  75. {
  76. $model = ProvinceGatherLog::findOne(['id' => $id]);
  77. $model->status = StatusEnum::DISABLED;
  78. $model->save();
  79. $queue = new ProvinceChildJob([
  80. 'parent' => $model->data,
  81. 'baseUrl' => $model->url,
  82. 'maxLevel' => $model->max_level,
  83. 'job_id' => $model->job_id,
  84. 'level' => $model->level,
  85. ]);
  86. $messageId = Yii::$app->queue->push($queue);
  87. return $this->message('推入队列成功,请注意执行', $this->redirect(['index', 'job_id' => $model['job_id']]));
  88. }
  89. }
粤ICP备19079148号