LocalConfigController.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace addons\TinyShop\merchant\modules\common\controllers;
  3. use Yii;
  4. use common\helpers\ArrayHelper;
  5. use common\helpers\DateHelper;
  6. use common\enums\StatusEnum;
  7. use common\traits\MerchantCurd;
  8. use addons\TinyShop\common\models\common\LocalConfig;
  9. use addons\TinyShop\merchant\controllers\BaseController;
  10. /**
  11. * Class LocalConfigController
  12. * @package addons\TinyShop\merchant\modules\common\controllers
  13. * @author jianyan74 <751393839@qq.com>
  14. */
  15. class LocalConfigController extends BaseController
  16. {
  17. use MerchantCurd;
  18. /**
  19. * @var LocalConfig
  20. */
  21. public $modelClass = LocalConfig::class;
  22. /**
  23. * 编辑/创建
  24. *
  25. * @return mixed
  26. */
  27. public function actionEdit()
  28. {
  29. $model = $this->findModel($this->getMerchantId());
  30. $model->is_start = StatusEnum::ENABLED;
  31. if ($model->load(Yii::$app->request->post()) && $model->save()) {
  32. return $this->message('保存成功', $this->redirect(['edit']));
  33. }
  34. $section = DateHelper::formatHours(ArrayHelper::numBetween(0, 86400, true, 1800));
  35. return $this->render($this->action->id, [
  36. 'model' => $model,
  37. 'section' => $section,
  38. ]);
  39. }
  40. /**
  41. * 返回模型
  42. *
  43. * @param $id
  44. * @return \yii\db\ActiveRecord
  45. */
  46. protected function findModel($id)
  47. {
  48. /* @var $model \yii\db\ActiveRecord */
  49. if (empty(($model = $this->modelClass::findOne(['merchant_id' => $id, 'is_start' => StatusEnum::ENABLED])))) {
  50. $model = new $this->modelClass;
  51. return $model->loadDefaultValues();
  52. }
  53. return $model;
  54. }
  55. }
粤ICP备19079148号