MerchantController.php 5.1 KB

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