Agent.php 3.8 KB

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