BlacklistController.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace addons\Member\merchant\controllers;
  3. use Yii;
  4. use common\enums\MemberTypeEnum;
  5. use common\enums\StatusEnum;
  6. use common\traits\MerchantCurd;
  7. use common\forms\MemberForm as Member;
  8. use common\models\base\SearchModel;
  9. /**
  10. * 黑名单
  11. *
  12. * Class BlacklistController
  13. * @package addons\Member\merchant\controllers
  14. * @author jianyan74 <751393839@qq.com>
  15. */
  16. class BlacklistController extends BaseController
  17. {
  18. use MerchantCurd;
  19. /**
  20. * @var Member
  21. */
  22. public $modelClass = Member::class;
  23. /**
  24. * 首页
  25. *
  26. * @return string
  27. * @throws \yii\web\NotFoundHttpException
  28. */
  29. public function actionIndex()
  30. {
  31. $searchModel = new SearchModel([
  32. 'model' => $this->modelClass,
  33. 'scenario' => 'default',
  34. 'partialMatchAttributes' => ['realname', 'mobile'], // 模糊查询
  35. 'defaultOrder' => [
  36. 'id' => SORT_DESC
  37. ],
  38. 'pageSize' => $this->pageSize
  39. ]);
  40. $dataProvider = $searchModel
  41. ->search(Yii::$app->request->queryParams);
  42. $dataProvider->query
  43. ->andWhere([
  44. 'type' => MemberTypeEnum::MEMBER,
  45. 'status' => StatusEnum::DISABLED
  46. ])
  47. ->andFilterWhere(['merchant_id' => $this->getMerchantId()])
  48. ->with(['account', 'memberLevel', 'tag']);
  49. return $this->render($this->action->id, [
  50. 'dataProvider' => $dataProvider,
  51. 'searchModel' => $searchModel,
  52. 'levelMap' => Yii::$app->services->memberLevel->getMap(),
  53. ]);
  54. }
  55. /**
  56. * 黑名单
  57. *
  58. * @param $id
  59. * @return mixed
  60. */
  61. public function actionBlacklist($id)
  62. {
  63. if (!($model = $this->modelClass::findOne($id))) {
  64. return $this->message("找不到数据", $this->redirect(Yii::$app->request->referrer), 'error');
  65. }
  66. $model->status = StatusEnum::ENABLED;
  67. if ($model->save()) {
  68. return $this->message("移出黑名单成功", $this->redirect(Yii::$app->request->referrer));
  69. }
  70. return $this->message("移出黑名单失败", $this->redirect(Yii::$app->request->referrer), 'error');
  71. }
  72. }
粤ICP备19079148号