MerchantController.php 5.8 KB

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