MerchantController.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace ghs\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 common\components\imgUtil;
  8. use Yii;
  9. use common\components\util;
  10. class MerchantController extends BaseController
  11. {
  12. public $guestAccess = ['detail'];
  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(['merchantId' => $this->sjId], ['freeDistance' => $first, 'freight' => $add]);
  20. util::complete();
  21. }
  22. //商家信息 ssh 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. //商家现有的会员等级 ssh 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. //会员等级更新 ssh 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列表 ssh 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. //商家信息 ssh 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. $name = isset($merchant['name']) ? $merchant['name'] : '';
  101. $logoUrl = isset($merchant['smallLogoUrl']) && !empty($merchant['smallLogoUrl']) ? $merchant['smallLogoUrl'] : imgUtil::getPrefix() . '/hhb_small.png';
  102. $address = $merchant['address'] ?? '';
  103. $data = ['name' => $name, 'smallLogoUrl' => $logoUrl, 'id' => $id, 'fullAddress' => $address];
  104. util::success($data);
  105. }
  106. }