MerchantController.php 4.3 KB

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