CateController.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. namespace addons\WechatVideoShop\backend\controllers;
  3. use addons\WechatVideoShop\common\enums\WechatVideoShopCateAuditStatusEnums;
  4. use addons\WechatVideoShop\common\expand\sdk\weixin\src\request\cate\CategoryInfoRequest;
  5. use addons\WechatVideoShop\common\models\WechatVideoShopCate;
  6. use addons\WechatVideoShop\common\models\WechatVideoShopCateAudit;
  7. use addons\WechatVideoShop\common\service\CateService;
  8. use addons\WechatVideoShop\common\service\ShopService;
  9. use common\enums\StatusEnum;
  10. use Yii;
  11. class CateController extends BaseController
  12. {
  13. public $enableCsrfValidation = false;
  14. public function actionIndex()
  15. {
  16. if (\Yii::$app->request->isAjax) {
  17. $service = new CateService();
  18. if (\Yii::$app->request->isPost) {
  19. } else {
  20. $data = Yii::$app->request->get();
  21. $valid = Yii::$app->services->validate->validate($data, [
  22. [['status', 'shop_id'], 'integer'],
  23. ]);
  24. if ($valid === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  25. $ret = $service->index($this->mall_id, $data);
  26. // 获取所有店铺键值对
  27. $ret['shop'] = (new ShopService())->ShopArr($this->mall_id);
  28. return is_string($ret) ? $this->error($ret) : $this->success('获取成功', $ret);
  29. }
  30. }
  31. return $this->render('index');
  32. }
  33. /**
  34. * @return mixed|void|null
  35. * @throws \Exception
  36. */
  37. public function actionCreate()
  38. {
  39. if (\Yii::$app->request->isPost) {
  40. $data = Yii::$app->request->post();
  41. $valid = Yii::$app->services->validate->validate($data, [
  42. [['cats', 'certificate'], 'safe'],
  43. [['shop_id'], 'integer'],
  44. [['cats', 'shop_id'], 'required'],
  45. ], [
  46. 'cats' => '类目',
  47. 'certificate' => '资质',
  48. 'shop_id' => '店铺',
  49. ]);
  50. if ($valid === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  51. $ret = (new CateService())->create($this->mall_id, $data);
  52. return is_string($ret) ? $this->error($ret) : $this->success('提交成功');
  53. }
  54. }
  55. /**
  56. * 撤回类目审核
  57. * @return mixed|null
  58. */
  59. public function actionCancelAudit()
  60. {
  61. return $this->success('');
  62. }
  63. /**
  64. * 删除类目
  65. * @return mixed|null
  66. */
  67. public function actionDelete()
  68. {
  69. return $this->success('');
  70. }
  71. /**
  72. * @return mixed|null
  73. */
  74. public function actionWxList()
  75. {
  76. // 取出第一个店铺
  77. $shop_id = (new ShopService())->firstShopId($this->mall_id);
  78. if (empty($shop_id)) return $this->error("请先绑定小店");
  79. $ret = (new CateService($shop_id))->wxList($this->mall_id, $shop_id);
  80. return is_string($ret) ? $this->error($ret) : $this->success('获取成功', $ret);
  81. }
  82. /**
  83. * @return array|false|mixed|string
  84. */
  85. public function actionList()
  86. {
  87. $data = Yii::$app->request->get();
  88. $valid = Yii::$app->services->validate->validate($data, [
  89. [['shop_id'], 'integer'],
  90. [['shop_id'], 'required'],
  91. ], [
  92. 'shop_id' => '店铺',
  93. ]);
  94. if ($valid === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  95. $ret = (new CateService())->enableList($this->mall_id, $data['shop_id']);
  96. return is_string($ret) ? $this->error($ret) : $this->success("获取成功", $ret);
  97. }
  98. /**
  99. * @return mixed|null
  100. */
  101. public function actionWxInfo()
  102. {
  103. $data = Yii::$app->request->get();
  104. $valid = Yii::$app->services->validate->validate($data, [
  105. [['id', 'shop_id'], 'integer'],
  106. [['id', 'shop_id'], 'required'],
  107. ], [
  108. 'id' => '类目',
  109. 'shop_id' => '店铺',
  110. ]);
  111. if ($valid === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
  112. $ret = (new CateService($data['shop_id']))->wxCatInfo($data['id']);
  113. return is_string($ret) ? $this->error($ret) : $this->success('获取成功', $ret);
  114. }
  115. }