MerchantController.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. namespace hd\controllers;
  3. use bizHd\auth\services\AuthService;
  4. use biz\sj\services\MerchantExtendService;
  5. use biz\sj\services\MerchantService;
  6. use bizHd\saas\services\SetAuthService;
  7. use Yii;
  8. use common\components\util;
  9. use bizHd\merchant\services\ShopService;
  10. use yii\web\Controller;
  11. class MerchantController extends BaseController
  12. {
  13. public $guestAccessAction = ['detail'];
  14. //运费设置 shish 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(['merchantId' => $this->sjId], ['freeDistance' => $first, 'freight' => $add]);
  21. util::complete();
  22. }
  23. //商家信息 shish 2019.12.8
  24. public function actionDetail()
  25. {
  26. $merchant = $this->sj;
  27. if (empty($merchant)) {
  28. util::success([]);
  29. }
  30. $merchant = MerchantService::getInfo($this->sj, $this->sjExtend);
  31. util::success($merchant);
  32. }
  33. //商家现有的会员等级 shish 2019.12.12
  34. public function actionMemberLevel()
  35. {
  36. $list = MerchantExtendService::getGradeList($this->sjExtend, false, false);
  37. $extend = $this->sjExtend;
  38. $gradeSwitch = isset($extend['gradeSwitch']) ? $extend['gradeSwitch'] : 1;
  39. util::success(['list' => $list, 'gradeSwitch' => $gradeSwitch]);
  40. }
  41. //会员等级更新 shish 2019.12.18
  42. public function actionMemberLevelUpdate()
  43. {
  44. $extend = $this->sjExtend;
  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(['merchantId' => $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列表 shish 2020.1.23
  85. public function actionAuth()
  86. {
  87. $merchant = $this->sj;
  88. $setId = $merchant['setId'];
  89. $endId = 1;
  90. $ids = SetAuthService::getAuthIdList($setId, $endId);
  91. util::success(['ids' => $ids]);
  92. }
  93. //商家信息 shish 2020.1.11
  94. public function actionIntroduceShop()
  95. {
  96. $id = Yii::$app->request->get('id');
  97. $merchant = MerchantService::getMerchantById($id);
  98. if (empty($merchant)) {
  99. util::fail('没有找到介绍人');
  100. }
  101. $merchantName = isset($merchant['merchantName']) ? $merchant['merchantName'] : '';
  102. $smallLogoUrl = isset($merchant['smallLogoUrl']) ? $merchant['smallLogoUrl'] : '';
  103. $logoUrl = isset($merchant['logoUrl']) ? $merchant['logoUrl'] : '';
  104. $data = ['merchantName' => $merchantName, 'smallLogoUrl' => $smallLogoUrl, 'id' => $id, 'logoUrl' => $logoUrl, 'fullAddress' => '暂无'];
  105. util::success($data);
  106. }
  107. //当前用户获取门店信息
  108. public function actionGetShopInfo()
  109. {
  110. $merchant = $this->sj;
  111. $merchant['defaultShop'] = ShopService::getDefaultShopInfo($merchant);
  112. util::success($merchant);
  113. }
  114. //当前用户获取商家信息
  115. public function actionGetInfo()
  116. {
  117. $merchant = MerchantService::getInfo($this->sj, $this->sjExtend);
  118. util::success($merchant);
  119. }
  120. //客户的会员等级 shish 2020.1.2
  121. public function actionUserGrade()
  122. {
  123. $list = MerchantExtendService::getGradeList($this->sjExtend, 'asc', false);
  124. util::success($list);
  125. }
  126. //获取商家的到期时间 shish 2020.2.22
  127. public function actionGetDeadline()
  128. {
  129. $id = Yii::$app->request->get('merchantId');
  130. $merchant = MerchantService::getById($id);
  131. $deadline = $merchant['deadline'];
  132. util::success(['date' => $deadline]);
  133. }
  134. }