CashAgainstAreaController.php 1.4 KB

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