MerchantController.php 5.2 KB

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