CateTreeGridController.php 1.8 KB

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