MerchantController.php 4.6 KB

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