MerchantController.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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(['sjId' => $this->sjId], ['freeDistance' => $first, 'freight' => $add]);
  20. util::complete();
  21. }
  22. //商家信息 ssh 2019.12.8
  23. public function actionDetail()
  24. {
  25. $merchant = isset($this->sj) && !empty($this->sj) ? $this->sj->attributes : [];
  26. if (empty($merchant)) {
  27. util::success([]);
  28. }
  29. $default = $this->shop->default ?? 0;
  30. $name = $merchant['name'] ?? '';
  31. if ($default != 1) {
  32. $shopName = $this->shop->shopName ?? '';
  33. $name .= ' ' . $shopName;
  34. }
  35. $merchant['name'] = $name;
  36. //我的账号不显示莱漫名称
  37. if (isset($this->shopAdminId) && $this->shopAdminId == 126188) {
  38. $merchant['name'] = '';
  39. }
  40. $ext = isset($this->sjExtend) && !empty($this->sjExtend) ? $this->sjExtend->attributes : [];
  41. $merchant = MerchantService::getInfo($merchant, $ext);
  42. util::success($merchant);
  43. }
  44. //商家现有的会员等级 ssh 2019.12.12
  45. public function actionMemberLevel()
  46. {
  47. $list = MerchantExtendService::getGradeList($this->sjExtend->attributes, false, false);
  48. $extend = $this->sjExtend->attributes;
  49. $gradeSwitch = isset($extend['gradeSwitch']) ? $extend['gradeSwitch'] : 1;
  50. util::success(['list' => $list, 'gradeSwitch' => $gradeSwitch]);
  51. }
  52. //会员等级更新 ssh 2019.12.18
  53. public function actionMemberLevelUpdate()
  54. {
  55. $extend = $this->sjExtend->attributes;
  56. if ($extend['gradeSwitch'] == 0) {
  57. util::fail('会员等级已设置不能修改');
  58. }
  59. $list = Yii::$app->request->post('list');
  60. if (empty($list) || is_array($list) == false) {
  61. util::fail('请填写会员等级');
  62. }
  63. if (count($list) > 9) {
  64. util::fail('最多可以设置9个等级');
  65. }
  66. $data = [];
  67. foreach ($list as $key => $val) {
  68. if ($key > 0) {
  69. $currentGrowth = $val[1];
  70. $previousGrowth = $list[$key - 1][1];
  71. if ($currentGrowth <= $previousGrowth) {
  72. util::fail('等级越高成长值也要越高');
  73. }
  74. $currentDiscount = $val[2];
  75. $previousDiscount = $list[$key - 1][2];
  76. if ($currentDiscount >= $previousDiscount) {
  77. util::fail('等级越高折扣要越低');
  78. }
  79. }
  80. $data[] = $val[0] . '_' . $val[1] . '_' . $val[2];
  81. }
  82. if (empty($data)) {
  83. util::fail('请填写会员等级!');
  84. }
  85. $string = implode('I', $data);
  86. MerchantExtendService::updateByCondition(['sjId' => $this->sjId], ['gradeList' => $string, 'gradeSwitch' => 0]);
  87. util::complete('提交成功');
  88. }
  89. //常用链接
  90. public function actionCommonUrl()
  91. {
  92. $list = MerchantService::getCommonUrlList();
  93. util::success($list);
  94. }
  95. //商家当前的权限id列表 ssh 2020.1.23
  96. public function actionAuth()
  97. {
  98. $merchant = $this->sj->attributes;
  99. $setId = $merchant['setId'];
  100. $endId = 1;
  101. $ids = SetAuthService::getAuthIdList($setId, $endId);
  102. util::success(['ids' => $ids]);
  103. }
  104. //商家信息 ssh 2020.1.11
  105. public function actionIntroduceShop()
  106. {
  107. $ghsShopAdminId = Yii::$app->request->get('ghsShopAdminId');
  108. $hdShopAdminId = Yii::$app->request->get('hdShopAdminId');
  109. if (!empty($ghsShopAdminId)) {
  110. $relation = ShopAdminClass::getById($ghsShopAdminId);
  111. } else {
  112. if (empty($hdShopAdminId)) {
  113. util::success([]);
  114. }
  115. $relation = ShopAdminClass::getById($hdShopAdminId);
  116. }
  117. if (empty($relation)) {
  118. util::success([]);
  119. }
  120. $sjId = $relation['sjId'];
  121. $merchant = MerchantClass::getMerchantById($sjId);
  122. if (empty($merchant)) {
  123. util::success([]);
  124. }
  125. util::success(['introduce' => $merchant]);
  126. }
  127. }