DistributionMemberController.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop100%开源免费商用商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | 商业版本务必购买商业授权,以免引起法律纠纷
  8. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  9. // | gitee下载:https://gitee.com/likeshop_gitee
  10. // | github下载:https://github.com/likeshop-github
  11. // | 访问官网:https://www.likeshop.cn
  12. // | 访问社区:https://home.likeshop.cn
  13. // | 访问手册:http://doc.likeshop.cn
  14. // | 微信公众号:likeshop技术社区
  15. // | likeshop团队 版权所有 拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshopTeam
  18. // +----------------------------------------------------------------------
  19. namespace app\adminapi\controller\distribution;
  20. use app\adminapi\controller\BaseAdminController;
  21. use app\adminapi\lists\distribution\FansLists;
  22. use app\adminapi\logic\distribution\DistributionMemberLogic;
  23. use app\adminapi\validate\distribution\DistributionMemberValidate;
  24. use app\common\model\Distribution;
  25. use app\common\model\DistributionLevel;
  26. use app\common\model\User;
  27. /**
  28. * 分销会员控制器
  29. * Class DistributionMemberController
  30. * @package app\adminapi\controller\distribution
  31. */
  32. class DistributionMemberController extends BaseAdminController
  33. {
  34. /**
  35. * @notes 查看分销会员列表
  36. * @return \think\response\Json
  37. * @author Tab
  38. * @date 2021/7/27 16:27
  39. */
  40. public function lists()
  41. {
  42. return $this->dataLists();
  43. }
  44. /**
  45. * @notes 开通分销
  46. * @return \think\response\Json
  47. * @author Tab
  48. * @date 2021/7/27 17:37
  49. */
  50. public function open()
  51. {
  52. $params = (new DistributionMemberValidate())->post()->goCheck('open');
  53. $result = DistributionMemberLogic::open($params);
  54. if ($result) {
  55. return $this->success('开通成功', [], 1, 1);
  56. }
  57. return $this->fail(DistributionMemberLogic::getError());
  58. }
  59. /**
  60. * @notes 查看分销商详情
  61. * @return \think\response\Json
  62. * @author Tab
  63. * @date 2021/9/14 16:53
  64. */
  65. public function detail()
  66. {
  67. $params = (new DistributionMemberValidate())->goCheck('detail');
  68. $result = DistributionMemberLogic::detail($params);
  69. return $this->data($result);
  70. }
  71. /**
  72. * @notes 调整分销等级界面信息
  73. * @return \think\response\Json
  74. * @author Tab
  75. * @date 2021/9/14 18:39
  76. */
  77. public function adjustLevelInfo()
  78. {
  79. $params = (new DistributionMemberValidate())->goCheck('adjustLevelInfo');
  80. $result = DistributionMemberLogic::adjustLevelInfo($params);
  81. return $this->data($result);
  82. }
  83. /**
  84. * @notes 调整分销商等级
  85. * @return \think\response\Json
  86. * @author Tab
  87. * @date 2021/9/14 18:55
  88. */
  89. public function adjustLevel()
  90. {
  91. $params = (new DistributionMemberValidate())->post()->goCheck('adjustLevel');
  92. $result = DistributionMemberLogic::adjustLevel($params);
  93. if ($result) {
  94. return $this->success('调整成功', [], 1, 1);
  95. }
  96. return $this->fail(DistributionMemberLogic::getError());
  97. }
  98. /**
  99. * @notes 冻结/解冻资格
  100. * @return \think\response\Json
  101. * @author Tab
  102. * @date 2021/9/14 19:09
  103. */
  104. public function freeze()
  105. {
  106. $params = (new DistributionMemberValidate())->post()->goCheck('freeze');
  107. $result = DistributionMemberLogic::freeze($params);
  108. if ($result) {
  109. return $this->success('操作成功', [], 1, 1);
  110. }
  111. return $this->fail(DistributionMemberLogic::getError());
  112. }
  113. /**
  114. * @notes 查看下级
  115. * @return \think\response\Json
  116. * @author Tab
  117. * @date 2021/9/14 19:22
  118. */
  119. public function getFans()
  120. {
  121. $params = (new DistributionMemberValidate())->goCheck('fans');
  122. $result = DistributionMemberLogic::getFans($params);
  123. return $this->data($result);
  124. }
  125. /**
  126. * @notes 下级列表
  127. * @return \think\response\Json
  128. * @author Tab
  129. * @date 2021/9/14 19:52
  130. */
  131. public function getFansLists()
  132. {
  133. $params = (new DistributionMemberValidate())->goCheck('fansLists');
  134. return $this->dataLists(new FansLists());
  135. }
  136. /**
  137. * @notes 分销初始化数据
  138. * @return \think\response\Json
  139. * @author Tab
  140. * @date 2021/9/6 14:26
  141. */
  142. public function updateTable()
  143. {
  144. try {
  145. $defaultLevel = DistributionLevel::where('is_default', 1)->findOrEmpty()->toArray();
  146. if (empty($defaultLevel)) {
  147. // 没有默认等级,初始化
  148. DistributionLevel::create([
  149. 'name' => '默认等级',
  150. 'weights' => '1',
  151. 'is_default' => '1',
  152. 'remark' => '默认等级',
  153. 'update_relation' => '1'
  154. ]);
  155. }
  156. // 默认分销会员等级
  157. $defaultLevelId = DistributionLevel::where('is_default', 1)->value('id');
  158. // 生成分销基础信息表
  159. $users = User::field('id')->select()->toArray();
  160. $distribution = Distribution::column('user_id');
  161. $addData = [];
  162. foreach($users as $item) {
  163. if (in_array($item['id'], $distribution)) {
  164. // 已有基础分销记录,跳过
  165. continue;
  166. }
  167. $data = [
  168. 'user_id' => $item['id'],
  169. 'level_id' => $defaultLevelId,
  170. 'is_distribution' => 0,
  171. 'is_freeze' => 0,
  172. 'remark' => '',
  173. ];
  174. $addData[] = $data;
  175. }
  176. $distributionModel = new Distribution();
  177. $distributionModel->saveAll($addData);
  178. return $this->success('初始化完成');
  179. } catch(\Exception $e) {
  180. return $this->fail($e->getMessage());
  181. }
  182. }
  183. }