ShopController.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace addons\WechatVideoShop\backend\controllers;
  3. use addons\WechatVideoShop\common\models\WechatVideoShop;
  4. use common\enums\StatusEnum;
  5. use common\models\common\Region;
  6. class ShopController extends BaseController
  7. {
  8. public $enableCsrfValidation = false;
  9. /**
  10. *
  11. * @return string
  12. */
  13. public function actionIndex()
  14. {
  15. if ($this->request->isAjax) {
  16. if ($this->request->isGet) {
  17. $param = \Yii::$app->request->get();
  18. $params['where'] = [
  19. ['mall_id' => $this->mall_id],
  20. ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]],
  21. ];
  22. $params['limit'] = $param['limit'] ?? 15;
  23. $params['page'] = $param['page'] ?? 1;
  24. $list = WechatVideoShop::listPage($params);
  25. if ($list === false) {
  26. return $this->error(WechatVideoShop::getStaticError());
  27. }
  28. return $this->success('数据请求成功', $list);
  29. }
  30. }
  31. return $this->render($this->action->id);
  32. }
  33. /**
  34. * @Description: 店铺编辑
  35. * @Author: zsan
  36. * @DateTime 2023-06-23 14:56:48
  37. * @return mixed
  38. */
  39. public function actionEdit()
  40. {
  41. if ($this->request->isAjax) {
  42. if ($this->request->isGet) {
  43. $param = \Yii::$app->request->get();
  44. $where = [
  45. ['mall_id' => $this->mall_id],
  46. ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]],
  47. ['id' => $param['id']]
  48. ];
  49. $detail = WechatVideoShop::getOne($where, true, ['provinceInfo', 'cityInfo', 'districtInfo']);
  50. $detail['callback_url'] = \Yii::getAlias('@apiUrl') . "/wechat-video-shop/v1/event/callback";
  51. return $this->success('数据请求成功', $detail ?? []);
  52. } elseif ($this->request->isPost) {
  53. $param = \Yii::$app->request->post();
  54. $params = $param['setting'];
  55. $params['mall_id'] = $this->mall_id;
  56. // 获取店铺信息
  57. $model = WechatVideoShop::setData($params);
  58. if ($model === false) return $this->error(WechatVideoShop::getStaticError());
  59. return $this->success('数据保存成功');
  60. }
  61. }
  62. return $this->render($this->action->id, ['callback_url' => \Yii::getAlias('@apiUrl') . "/wechat-video-shop/v1/event/callback"]);
  63. }
  64. public function actionRegion()
  65. {
  66. $id = intval(\Yii::$app->request->get('region_id', 0));
  67. $ret = Region::lists([
  68. 'where' => [
  69. ['parent_id' => $id]
  70. ]
  71. ]);
  72. return $this->success('获取成功', $ret);
  73. }
  74. public function actionList()
  75. {
  76. }
  77. }