MerchantController.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. //运费设置 shish 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(['merchantId' => $this->sjId], ['freeDistance' => $first, 'freight' => $add]);
  20. util::complete();
  21. }
  22. //商家信息 shish 2019.12.8
  23. public function actionDetail()
  24. {
  25. $merchant = $this->sj;
  26. if (empty($merchant)) {
  27. util::success([]);
  28. }
  29. $merchant = MerchantService::getInfo($this->sj, $this->sjExtend);
  30. util::success($merchant);
  31. }
  32. //商家现有的会员等级 shish 2019.12.12
  33. public function actionMemberLevel()
  34. {
  35. $list = MerchantExtendService::getGradeList($this->sjExtend, false, false);
  36. $extend = $this->sjExtend;
  37. $gradeSwitch = isset($extend['gradeSwitch']) ? $extend['gradeSwitch'] : 1;
  38. util::success(['list' => $list, 'gradeSwitch' => $gradeSwitch]);
  39. }
  40. //会员等级更新 shish 2019.12.18
  41. public function actionMemberLevelUpdate()
  42. {
  43. $extend = $this->sjExtend;
  44. if ($extend['gradeSwitch'] == 0) {
  45. util::fail('会员等级已设置不能修改');
  46. }
  47. $list = Yii::$app->request->post('list');
  48. if (empty($list) || is_array($list) == false) {
  49. util::fail('请填写会员等级');
  50. }
  51. if (count($list) > 9) {
  52. util::fail('最多可以设置9个等级');
  53. }
  54. $data = [];
  55. foreach ($list as $key => $val) {
  56. if ($key > 0) {
  57. $currentGrowth = $val[1];
  58. $previousGrowth = $list[$key - 1][1];
  59. if ($currentGrowth <= $previousGrowth) {
  60. util::fail('等级越高成长值也要越高');
  61. }
  62. $currentDiscount = $val[2];
  63. $previousDiscount = $list[$key - 1][2];
  64. if ($currentDiscount >= $previousDiscount) {
  65. util::fail('等级越高折扣要越低');
  66. }
  67. }
  68. $data[] = $val[0] . '_' . $val[1] . '_' . $val[2];
  69. }
  70. if (empty($data)) {
  71. util::fail('请填写会员等级!');
  72. }
  73. $string = implode('I', $data);
  74. MerchantExtendService::updateByCondition(['merchantId' => $this->sjId], ['gradeList' => $string, 'gradeSwitch' => 0]);
  75. util::complete('提交成功');
  76. }
  77. //常用链接
  78. public function actionCommonUrl()
  79. {
  80. $list = MerchantService::getCommonUrlList();
  81. util::success($list);
  82. }
  83. //商家当前的权限id列表 shish 2020.1.23
  84. public function actionAuth()
  85. {
  86. $merchant = $this->sj;
  87. $setId = $merchant['setId'];
  88. $endId = 1;
  89. $ids = SetAuthService::getAuthIdList($setId, $endId);
  90. util::success(['ids' => $ids]);
  91. }
  92. //商家信息 shish 2020.1.11
  93. public function actionIntroduceShop()
  94. {
  95. $id = Yii::$app->request->get('id');
  96. $merchant = MerchantService::getMerchantById($id);
  97. if (empty($merchant)) {
  98. util::fail('没有找到介绍人');
  99. }
  100. $merchantName = isset($merchant['merchantName']) ? $merchant['merchantName'] : '';
  101. $smallLogoUrl = isset($merchant['smallLogoUrl']) ? $merchant['smallLogoUrl'] : '';
  102. $logoUrl = isset($merchant['logoUrl']) ? $merchant['logoUrl'] : '';
  103. $data = ['merchantName' => $merchantName, 'smallLogoUrl' => $smallLogoUrl, 'id' => $id, 'logoUrl' => $logoUrl, 'fullAddress' => '暂无'];
  104. util::success($data);
  105. }
  106. //当前用户获取门店信息
  107. public function actionGetShopInfo()
  108. {
  109. $merchant = $this->sj;
  110. $merchant['defaultShop'] = ShopService::getDefaultShopInfo($merchant);
  111. util::success($merchant);
  112. }
  113. //当前用户获取商家信息
  114. public function actionGetInfo()
  115. {
  116. $merchant = MerchantService::getInfo($this->sj, $this->sjExtend);
  117. util::success($merchant);
  118. }
  119. //客户的会员等级 shish 2020.1.2
  120. public function actionUserGrade()
  121. {
  122. $list = MerchantExtendService::getGradeList($this->sjExtend, 'asc', false);
  123. util::success($list);
  124. }
  125. //获取商家的到期时间 shish 2020.2.22
  126. public function actionGetDeadline()
  127. {
  128. $id = Yii::$app->request->get('merchantId');
  129. $merchant = MerchantService::getById($id);
  130. $deadline = $merchant['deadline'];
  131. util::success(['date' => $deadline]);
  132. }
  133. }