CateController.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace addons\CardSecret\backend\controllers;
  3. use addons\CardSecret\common\listeners\OrderFinishListener;
  4. use addons\CardSecret\common\listeners\OrderPaidListener;
  5. use addons\CardSecret\common\models\Cate;
  6. use common\enums\StatusEnum;
  7. use Yii;
  8. use yii\db\Exception;
  9. /**
  10. * 默认控制器
  11. *
  12. * Class DefaultController
  13. * @package addons\CardSecret\backend\controllers
  14. */
  15. class CateController extends BaseController
  16. {
  17. public $enableCsrfValidation = false;
  18. /**
  19. * 首页
  20. *
  21. * @return string
  22. */
  23. public function actionIndex()
  24. {
  25. $retuest = Yii::$app->request;
  26. if ($retuest->isAjax) {
  27. if ($retuest->isGet) {
  28. $get = Yii::$app->request->get();
  29. // 检查提交的参数
  30. $res = Yii::$app->services->validate->validate($get,[
  31. [['id','keyword'], 'safe'],
  32. [['limit'],'default','value' => '15'],
  33. ]);
  34. if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  35. $where = [];
  36. if(!empty($get['keyword'])) $where[] = ['like', 'name', $get['keyword']];
  37. $where[] = ['=', 'mall_id', $this->mall_id];
  38. $where[] = ['>=', 'status', StatusEnum::DISABLED];
  39. $order = 'sort,created_at desc';
  40. $params = array('where' => $where, 'order'=>$order, 'limit' => $get['limit']);
  41. $list = Cate::listPage($params, false, true);
  42. $this->success('获取成功', $list);
  43. }
  44. } else {
  45. return $this->render($this->action->id);
  46. }
  47. }
  48. /**
  49. * 等级编辑
  50. * @Author: ltm
  51. * @DateTime: 2021/10/21 0021 11:29
  52. * @Copyright: copyright (c) 2021 广东七件事集团
  53. * @return mixed|string|void
  54. */
  55. public function actionEdit()
  56. {
  57. try {
  58. $request = Yii::$app->request;
  59. if ($request->isAjax) {
  60. // 提交等级内容
  61. if ($request->isPost) {
  62. $params = Yii::$app->request->post();
  63. $res = Yii::$app->services->validate->validate($params, [
  64. [['name','id','status'], 'safe'],
  65. ]);
  66. if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  67. $params = Cate::exceptNullVal($params);
  68. if(!empty($params['id'])) $params['updated_at'] = time();//更新
  69. $params['create_at'] = time();
  70. if(!$params['name']) unset($params['name']);
  71. $params['mall_id'] = $this->mall_id;
  72. if(isset($params['status']) && !in_array($params['status'],[StatusEnum::DISABLED,StatusEnum::ENABLED,StatusEnum::DELETE])) throw new Exception("参数错误");;
  73. $res = Cate::setData($params);
  74. if ($res === false) throw new Exception(Cate::getStaticError());
  75. return $this->success('操作成功');
  76. }
  77. }
  78. } catch (\Exception $e) {
  79. return $this->error($e->getMessage(), []);
  80. }
  81. return $this->render($this->action->id);
  82. }
  83. //测试使用,测试完进行删除
  84. public function actionTestpaid()
  85. {
  86. $add['id'] = 8130;
  87. $d = "发放";
  88. var_dump(preg_match("/^[0-9a-zA-Z]{0,50}$/",$d));die;
  89. $res = OrderFinishListener::async_handle($add);
  90. }
  91. }