MerchantController.php 4.5 KB

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