MerchantController.php 3.9 KB

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