AgentController.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\api\v2\agent;
  12. use app\Request;
  13. use app\services\other\AgreementServices;
  14. use app\services\user\UserBrokerageServices;
  15. use app\services\user\UserServices;
  16. class AgentController
  17. {
  18. /**
  19. * 获取用户推广用户列表
  20. * @param Request $request
  21. * @param UserServices $userServices
  22. * @throws \think\db\exception\DataNotFoundException
  23. * @throws \think\db\exception\DbException
  24. * @throws \think\db\exception\ModelNotFoundException
  25. */
  26. public function agentUserList(Request $request, UserServices $userServices)
  27. {
  28. [$type] = $request->getMore([
  29. ['type', 0]
  30. ], true);
  31. $uid = $request->uid();
  32. return app('json')->successful($userServices->agentUserList($uid, $type));
  33. }
  34. /**
  35. * 获取用户推广获得收益,佣金轮播,分销规则
  36. * @param Request $request
  37. * @return mixed
  38. * @throws \think\db\exception\DataNotFoundException
  39. * @throws \think\db\exception\DbException
  40. * @throws \think\db\exception\ModelNotFoundException
  41. */
  42. public function agentInfo(Request $request)
  43. {
  44. /** @var AgreementServices $agreementService */
  45. $agreementService = app()->make(AgreementServices::class);
  46. /** @var UserBrokerageServices $userBrokerageServices */
  47. $userBrokerageServices = app()->make(UserBrokerageServices::class);
  48. $data['agreement'] = $agreementService->getAgreementBytype(2)['content'] ?? '';
  49. $data['price'] = $userBrokerageServices->sum(['uid' => $request->uid(), 'pm' => 1, 'not_type' => ['extract_fail', 'refund']], 'number', true);
  50. $list = $userBrokerageServices->getList(['pm' => 1, 'not_type' => ['extract_fail', 'refund']], '*', 1, 10, [], ['user']);
  51. foreach ($list as $item) {
  52. $data['list'][] = [
  53. 'nickname' => $item['user']['nickname'] ?? '',
  54. 'price' => $item['number']
  55. ];
  56. }
  57. return app('json')->successful($data);
  58. }
  59. }