HelperController.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace addons\TinyShop\merchant\modules\common\controllers;
  3. use Yii;
  4. use yii\data\ActiveDataProvider;
  5. use common\traits\MerchantCurd;
  6. use addons\TinyShop\common\models\common\Helper;
  7. use addons\TinyShop\merchant\controllers\BaseController;
  8. /**
  9. * 站点帮助
  10. *
  11. * Class HelperController
  12. * @package addons\TinyShop\merchant\modules\common\controllers
  13. * @author jianyan74 <751393839@qq.com>
  14. */
  15. class HelperController extends BaseController
  16. {
  17. use MerchantCurd;
  18. /**
  19. * @var Helper
  20. */
  21. public $modelClass = Helper::class;
  22. /**
  23. * Lists all Tree models.
  24. * @return mixed
  25. */
  26. public function actionIndex()
  27. {
  28. $query = $this->modelClass::find()
  29. ->orderBy('sort asc, created_at asc')
  30. ->andWhere(['merchant_id' => $this->getMerchantId()]);
  31. $dataProvider = new ActiveDataProvider([
  32. 'query' => $query,
  33. 'pagination' => false
  34. ]);
  35. return $this->render('index', [
  36. 'dataProvider' => $dataProvider
  37. ]);
  38. }
  39. /**
  40. * @return mixed|string|\yii\console\Response|\yii\web\Response
  41. * @throws \yii\base\ExitException
  42. */
  43. public function actionEdit()
  44. {
  45. $request = Yii::$app->request;
  46. $id = $request->get('id');
  47. $model = $this->findModel($id);
  48. $model->pid = $request->get('pid', null) ?? $model->pid; // 父id
  49. if ($model->load(Yii::$app->request->post())) {
  50. return $model->save()
  51. ? $this->redirect(['index'])
  52. : $this->message($this->getError($model), $this->redirect(['index']), 'error');
  53. }
  54. return $this->render($this->action->id, [
  55. 'model' => $model,
  56. 'dropDownList' => Yii::$app->tinyShopService->helper->getDropDownForEdit($id),
  57. ]);
  58. }
  59. }
粤ICP备19079148号