MerchantController.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. namespace ghs\controllers;
  3. use biz\shop\classes\ShopAdminClass;
  4. use biz\sj\classes\MerchantClass;
  5. use biz\sj\services\MerchantExtendService;
  6. use biz\sj\services\MerchantService;
  7. use bizHd\saas\services\SetAuthService;
  8. use Yii;
  9. use common\components\util;
  10. class MerchantController extends BaseController
  11. {
  12. public $guestAccess = ['detail', 'introduce-shop'];
  13. //运费设置 ssh 2019.12.8
  14. public function actionFreightSetting()
  15. {
  16. $get = Yii::$app->request->get();
  17. $first = isset($get['first']) && is_numeric($get['first']) ? $get['first'] : 5;
  18. $add = isset($get['add']) && is_numeric($get['add']) ? $get['add'] : 5;
  19. MerchantExtendService::updateByCondition(['merchantId' => $this->sjId], ['freeDistance' => $first, 'freight' => $add]);
  20. util::complete();
  21. }
  22. //商家信息 ssh 2019.12.8
  23. public function actionDetail()
  24. {
  25. $merchant = $this->sj;
  26. if (empty($merchant)) {
  27. util::success([]);
  28. }
  29. $merchant = MerchantService::getInfo($this->sj, $this->sjExtend);
  30. util::success($merchant);
  31. }
  32. //商家现有的会员等级 ssh 2019.12.12
  33. public function actionMemberLevel()
  34. {
  35. $list = MerchantExtendService::getGradeList($this->sjExtend, false, false);
  36. $extend = $this->sjExtend;
  37. $gradeSwitch = isset($extend['gradeSwitch']) ? $extend['gradeSwitch'] : 1;
  38. util::success(['list' => $list, 'gradeSwitch' => $gradeSwitch]);
  39. }
  40. //会员等级更新 ssh 2019.12.18
  41. public function actionMemberLevelUpdate()
  42. {
  43. $extend = $this->sjExtend;
  44. if ($extend['gradeSwitch'] == 0) {
  45. util::fail('会员等级已设置不能修改');
  46. }
  47. $list = Yii::$app->request->post('list');
  48. if (empty($list) || is_array($list) == false) {
  49. util::fail('请填写会员等级');
  50. }
  51. if (count($list) > 9) {
  52. util::fail('最多可以设置9个等级');
  53. }
  54. $data = [];
  55. foreach ($list as $key => $val) {
  56. if ($key > 0) {
  57. $currentGrowth = $val[1];
  58. $previousGrowth = $list[$key - 1][1];
  59. if ($currentGrowth <= $previousGrowth) {
  60. util::fail('等级越高成长值也要越高');
  61. }
  62. $currentDiscount = $val[2];
  63. $previousDiscount = $list[$key - 1][2];
  64. if ($currentDiscount >= $previousDiscount) {
  65. util::fail('等级越高折扣要越低');
  66. }
  67. }
  68. $data[] = $val[0] . '_' . $val[1] . '_' . $val[2];
  69. }
  70. if (empty($data)) {
  71. util::fail('请填写会员等级!');
  72. }
  73. $string = implode('I', $data);
  74. MerchantExtendService::updateByCondition(['merchantId' => $this->sjId], ['gradeList' => $string, 'gradeSwitch' => 0]);
  75. util::complete('提交成功');
  76. }
  77. //常用链接
  78. public function actionCommonUrl()
  79. {
  80. $list = MerchantService::getCommonUrlList();
  81. util::success($list);
  82. }
  83. //商家当前的权限id列表 ssh 2020.1.23
  84. public function actionAuth()
  85. {
  86. $merchant = $this->sj;
  87. $setId = $merchant['setId'];
  88. $endId = 1;
  89. $ids = SetAuthService::getAuthIdList($setId, $endId);
  90. util::success(['ids' => $ids]);
  91. }
  92. //商家信息 ssh 2020.1.11
  93. public function actionIntroduceShop()
  94. {
  95. $ghsShopAdminId = Yii::$app->request->get('ghsShopAdminId');
  96. $hdShopAdminId = Yii::$app->request->get('hdShopAdminId');
  97. if (!empty($ghsShopAdminId)) {
  98. $relation = ShopAdminClass::getById($ghsShopAdminId);
  99. } else {
  100. if (empty($hdShopAdminId)) {
  101. util::success([]);
  102. }
  103. $relation = ShopAdminClass::getById($hdShopAdminId);
  104. }
  105. if (empty($relation)) {
  106. util::success([]);
  107. }
  108. $sjId = $relation['merchantId'];
  109. $merchant = MerchantClass::getMerchantById($sjId);
  110. if (empty($merchant)) {
  111. util::success([]);
  112. }
  113. util::success(['introduce' => $merchant]);
  114. }
  115. }