MerchantController.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. //运费设置 ssh 2019.12.8
  13. public function actionFreightSetting()
  14. {
  15. $get = Yii::$app->request->get();
  16. $first = isset($get['first']) && is_numeric($get['first']) ? $get['first'] : 5;
  17. $add = isset($get['add']) && is_numeric($get['add']) ? $get['add'] : 5;
  18. MerchantExtendService::updateByCondition(['merchantId' => $this->sjId], ['freeDistance' => $first, 'freight' => $add]);
  19. util::complete();
  20. }
  21. //商家信息 ssh 2019.12.8
  22. public function actionDetail()
  23. {
  24. $merchant = $this->sj;
  25. if (empty($merchant)) {
  26. util::success([]);
  27. }
  28. $merchant = MerchantService::getInfo($this->sj, $this->sjExtend);
  29. util::success($merchant);
  30. }
  31. //商家现有的会员等级 ssh 2019.12.12
  32. public function actionMemberLevel()
  33. {
  34. $list = MerchantExtendService::getGradeList($this->sjExtend, false, false);
  35. $extend = $this->sjExtend;
  36. $gradeSwitch = isset($extend['gradeSwitch']) ? $extend['gradeSwitch'] : 1;
  37. util::success(['list' => $list, 'gradeSwitch' => $gradeSwitch]);
  38. }
  39. //会员等级更新 ssh 2019.12.18
  40. public function actionMemberLevelUpdate()
  41. {
  42. $extend = $this->sjExtend;
  43. if ($extend['gradeSwitch'] == 0) {
  44. util::fail('会员等级已设置不能修改');
  45. }
  46. $list = Yii::$app->request->post('list');
  47. if (empty($list) || is_array($list) == false) {
  48. util::fail('请填写会员等级');
  49. }
  50. if (count($list) > 9) {
  51. util::fail('最多可以设置9个等级');
  52. }
  53. $data = [];
  54. foreach ($list as $key => $val) {
  55. if ($key > 0) {
  56. $currentGrowth = $val[1];
  57. $previousGrowth = $list[$key - 1][1];
  58. if ($currentGrowth <= $previousGrowth) {
  59. util::fail('等级越高成长值也要越高');
  60. }
  61. $currentDiscount = $val[2];
  62. $previousDiscount = $list[$key - 1][2];
  63. if ($currentDiscount >= $previousDiscount) {
  64. util::fail('等级越高折扣要越低');
  65. }
  66. }
  67. $data[] = $val[0] . '_' . $val[1] . '_' . $val[2];
  68. }
  69. if (empty($data)) {
  70. util::fail('请填写会员等级!');
  71. }
  72. $string = implode('I', $data);
  73. MerchantExtendService::updateByCondition(['merchantId' => $this->sjId], ['gradeList' => $string, 'gradeSwitch' => 0]);
  74. util::complete('提交成功');
  75. }
  76. //常用链接
  77. public function actionCommonUrl()
  78. {
  79. $list = MerchantService::getCommonUrlList();
  80. util::success($list);
  81. }
  82. //商家当前的权限id列表 ssh 2020.1.23
  83. public function actionAuth()
  84. {
  85. $merchant = $this->sj;
  86. $setId = $merchant['setId'];
  87. $endId = 1;
  88. $ids = SetAuthService::getAuthIdList($setId, $endId);
  89. util::success(['ids' => $ids]);
  90. }
  91. //商家信息 ssh 2020.1.11
  92. public function actionIntroduceShop()
  93. {
  94. $id = Yii::$app->request->get('id');
  95. $merchant = MerchantService::getMerchantById($id);
  96. if (empty($merchant)) {
  97. util::fail('没有找到介绍人');
  98. }
  99. $name = isset($merchant['name']) ? $merchant['name'] : '';
  100. $logoUrl = isset($merchant['smallLogoUrl']) && !empty($merchant['smallLogoUrl']) ? $merchant['smallLogoUrl'] : imgUtil::getPrefix() . '/hhb_small.png';
  101. $address = $merchant['address'] ?? '';
  102. $data = ['name' => $name, 'smallLogoUrl' => $logoUrl, 'id' => $id, 'fullAddress' => $address];
  103. util::success($data);
  104. }
  105. }