Agent.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. namespace app\api\controller\user;
  3. use app\api\controller\Controller;
  4. use app\api\model\plus\agent\Referee;
  5. use app\api\model\plus\agent\Setting;
  6. use app\api\model\plus\agent\User as AgentUserModel;
  7. use app\api\model\plus\agent\Apply as AgentApplyModel;
  8. use app\api\model\settings\Message as MessageModel;
  9. /**
  10. * 分销中心
  11. */
  12. class Agent extends Controller
  13. {
  14. // 用户
  15. private $user;
  16. // 分销商
  17. private $agent;
  18. // 分销设置
  19. private $setting;
  20. /**
  21. * 构造方法
  22. */
  23. public function initialize()
  24. {
  25. parent::initialize();
  26. // 用户信息
  27. $this->user = $this->getUser();
  28. // 分销商用户信息
  29. $this->agent = AgentUserModel::detail($this->user['user_id']);
  30. // 分销商设置
  31. $this->setting = Setting::getAll();
  32. }
  33. /**
  34. * 分销商中心
  35. */
  36. public function center()
  37. {
  38. return $this->renderSuccess('', [
  39. // 当前是否为分销商
  40. 'is_agent' => $this->isAgentUser(),
  41. // 当前是否在申请中
  42. 'is_applying' => AgentApplyModel::isApplying($this->user['user_id']),
  43. // 当前用户信息
  44. 'user' => $this->user,
  45. // 分销商用户信息
  46. 'agent' => $this->agent,
  47. // 背景图
  48. 'background' => $this->setting['background']['values']['index'],
  49. // 页面文字
  50. 'words' => $this->setting['words']['values'],
  51. ]);
  52. }
  53. /**
  54. * 分销商申请状态
  55. */
  56. public function apply($referee_id = null, $platform= '')
  57. {
  58. // 推荐人昵称
  59. $referee_name = '平台';
  60. // 如果之前有关联分销商,则继续关联之前的分销商
  61. $has_referee_id = Referee::getRefereeUserId($this->user['user_id'], 1);
  62. if($has_referee_id > 0){
  63. $referee_id = $has_referee_id;
  64. }
  65. if ($referee_id > 0 && ($referee = AgentUserModel::detail($referee_id))) {
  66. $referee_name = $referee['user']['nickName'];
  67. }
  68. return $this->renderSuccess('', [
  69. // 当前是否为分销商
  70. 'is_agent' => $this->isAgentUser(),
  71. // 当前是否在申请中
  72. 'is_applying' => AgentApplyModel::isApplying($this->user['user_id']),
  73. // 推荐人昵称
  74. 'referee_name' => $referee_name,
  75. // 背景图
  76. 'background' => $this->setting['background']['values']['apply'],
  77. // 页面文字
  78. 'words' => $this->setting['words']['values'],
  79. // 申请协议
  80. 'license' => $this->setting['license']['values']['license'],
  81. // 如果来源是小程序, 则获取小程序订阅消息id.获取售后通知.
  82. 'template_arr' => MessageModel::getMessageByNameArr($platform, ['agent_apply_user']),
  83. ]);
  84. }
  85. /**
  86. * 分销商提现信息
  87. */
  88. public function cash($platform = '')
  89. {
  90. // 如果来源是小程序, 则获取小程序订阅消息id.获取售后通知.
  91. $template_arr = MessageModel::getMessageByNameArr($platform, ['agent_cash_user']);
  92. return $this->renderSuccess('', [
  93. // 分销商用户信息
  94. 'agent' => $this->agent,
  95. // 结算设置
  96. 'settlement' => $this->setting['settlement']['values'],
  97. // 背景图
  98. 'background' => $this->setting['background']['values']['cash_apply'],
  99. // 页面文字
  100. 'words' => $this->setting['words']['values'],
  101. // 小程序消息
  102. 'template_arr' => $template_arr
  103. ]);
  104. }
  105. /**
  106. * 当前用户是否为分销商
  107. */
  108. private function isAgentUser()
  109. {
  110. return !!$this->agent && !$this->agent['is_delete'];
  111. }
  112. }