TransportationController.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace backendApi\modules\v1\controllers;
  3. use common\helpers\Form;
  4. use common\models\Currency;
  5. use common\models\CurrencyConversions;
  6. use common\models\forms\CurrenciesConversionsForm;
  7. use common\models\forms\FreeTemplateForm;
  8. use common\models\FreeTemplate;
  9. use yii\db\Exception;
  10. use yii\web\HttpException;
  11. class TransportationController extends BaseController
  12. {
  13. public $modelClass = FreeTemplate::class;
  14. public function actionTransportationList()
  15. {
  16. $data = $this->modelClass::getFromCache();
  17. return static::notice(['data' => $data]);
  18. }
  19. public function actionSetTransportation()
  20. {
  21. if (\Yii::$app->request->isPost) {
  22. $formModel = new FreeTemplateForm();
  23. $formModel->scenario = 'setTransportation';
  24. if ($formModel->load(\Yii::$app->request->post(), '') && $formModel->setTransportation()) {
  25. // 更新缓存
  26. $this->modelClass::updateToCache();
  27. return static::notice(\Yii::t('ctx', 'successfully'));
  28. } else {
  29. return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
  30. }
  31. }
  32. return static::notice(\Yii::t('ctx', 'illegalRequest'));
  33. }
  34. }