LevelController.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace addons\Member\merchant\controllers;
  3. use Yii;
  4. use common\enums\MemberTypeEnum;
  5. use common\models\base\SearchModel;
  6. use common\traits\MerchantCurd;
  7. use common\enums\StatusEnum;
  8. use common\models\member\Level;
  9. /**
  10. * 会员等级管理
  11. *
  12. * Class LevelController
  13. * @author Maomao
  14. * @package addons\Member\merchant\controllers
  15. */
  16. class LevelController extends BaseController
  17. {
  18. use MerchantCurd;
  19. /**
  20. * @var \yii\db\ActiveRecord
  21. */
  22. public $modelClass = Level::class;
  23. /**
  24. * 首页
  25. *
  26. * @return string
  27. * @throws \yii\web\NotFoundHttpException
  28. */
  29. public function actionIndex()
  30. {
  31. $merchant_id = Yii::$app->services->merchant->getNotNullId();
  32. $searchModel = new SearchModel([
  33. 'model' => $this->modelClass,
  34. 'scenario' => 'default',
  35. 'partialMatchAttributes' => ['name'], // 模糊查询
  36. 'defaultOrder' => [
  37. 'level' => SORT_ASC
  38. ],
  39. 'pageSize' => $this->pageSize
  40. ]);
  41. $dataProvider = $searchModel
  42. ->search(Yii::$app->request->queryParams);
  43. $dataProvider->query
  44. ->andWhere(['>=', 'status', StatusEnum::DISABLED])
  45. ->andWhere(['merchant_id' => $merchant_id]);
  46. $levelConfig = Yii::$app->services->memberLevelConfig->one($merchant_id);
  47. return $this->render($this->action->id, [
  48. 'dataProvider' => $dataProvider,
  49. 'searchModel' => $searchModel,
  50. 'memberLevelUpgradeType' => $levelConfig->upgrade_type
  51. ]);
  52. }
  53. /**
  54. * 删除
  55. *
  56. * @param $id
  57. * @return mixed
  58. * @throws \Throwable
  59. * @throws \yii\db\StaleObjectException
  60. */
  61. public function actionDelete($id)
  62. {
  63. $model = $this->findModel($id);
  64. if ($hasLevel = Yii::$app->services->member->hasLevel($model->level, MemberTypeEnum::MEMBER, $model->merchant_id)) {
  65. return $this->message("已经在使用中,无法删除", $this->redirect(['index']), 'error');
  66. }
  67. if ($model->delete()) {
  68. return $this->message("删除成功", $this->redirect(['index']));
  69. }
  70. return $this->message("删除失败", $this->redirect(['index']), 'error');
  71. }
  72. }
粤ICP备19079148号