MerchantController.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 = MerchantService::getInfo($this->merchant, $this->merchantExtend);
  24. util::success($merchant);
  25. }
  26. //商家现有的会员等级 shish 2019.12.12
  27. public function actionMemberLevel()
  28. {
  29. $list = MerchantExtendService::getGradeList($this->merchantExtend, false, false);
  30. $extend = $this->merchantExtend;
  31. $gradeSwitch = isset($extend['gradeSwitch']) ? $extend['gradeSwitch'] : 1;
  32. util::success(['list' => $list, 'gradeSwitch' => $gradeSwitch]);
  33. }
  34. //会员等级更新 shish 2019.12.18
  35. public function actionMemberLevelUpdate()
  36. {
  37. $extend = $this->merchantExtend;
  38. if ($extend['gradeSwitch'] == 0) {
  39. util::fail('会员等级已设置不能修改');
  40. }
  41. $list = Yii::$app->request->post('list');
  42. if (empty($list) || is_array($list) == false) {
  43. util::fail('请填写会员等级');
  44. }
  45. if (count($list) > 9) {
  46. util::fail('最多可以设置9个等级');
  47. }
  48. $data = [];
  49. foreach ($list as $key => $val) {
  50. if ($key > 0) {
  51. $currentGrowth = $val[1];
  52. $previousGrowth = $list[$key - 1][1];
  53. if ($currentGrowth <= $previousGrowth) {
  54. util::fail('等级越高成长值也要越高');
  55. }
  56. $currentDiscount = $val[2];
  57. $previousDiscount = $list[$key - 1][2];
  58. if ($currentDiscount >= $previousDiscount) {
  59. util::fail('等级越高折扣要越低');
  60. }
  61. }
  62. $data[] = $val[0] . '_' . $val[1] . '_' . $val[2];
  63. }
  64. if (empty($data)) {
  65. util::fail('请填写会员等级!');
  66. }
  67. $string = implode('I', $data);
  68. MerchantExtendService::updateByCondition(['merchantId' => $this->merchantId], ['gradeList' => $string, 'gradeSwitch' => 0]);
  69. util::complete('提交成功');
  70. }
  71. //常用链接
  72. public function actionCommonUrl()
  73. {
  74. $list = MerchantService::getCommonUrlList();
  75. util::success($list);
  76. }
  77. //商家当前的权限id列表 shish 2020.1.23
  78. public function actionAuth()
  79. {
  80. $merchant = $this->merchant;
  81. $setId = $merchant['setId'];
  82. $endId = 1;
  83. $ids = SetAuthService::getAuthIdList($setId, $endId);
  84. util::success(['ids' => $ids]);
  85. }
  86. }