OaAgent.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Ksh
  5. * Date: 2017/6/26
  6. * Time: 11:12
  7. */
  8. namespace huolib\oa;
  9. use think\Db;
  10. class OaAgent extends Oa {
  11. public function __construct() {
  12. parent::__construct();
  13. }
  14. /**
  15. * 添加军团长 一级渠道
  16. *
  17. * @param $user_nicename 渠道昵称
  18. * @param $user_login 渠道用户名
  19. * @param $user_pass 渠道密码
  20. */
  21. public function oa2AddAgent($user_nicename, $user_login, $user_pass) {
  22. if (!$this->hasOa()) {
  23. $this->hs_api_json('201', '未接通oa');
  24. exit;
  25. }
  26. if (!$user_nicename) {
  27. $this->hs_api_json('201', '渠道名称不能为空');
  28. exit;
  29. }
  30. if (!$user_pass) {
  31. $this->hs_api_json('201', '密码不能为空');
  32. exit;
  33. }
  34. if (!$user_login) {
  35. $this->hs_api_json('201', '帐号不能为空');
  36. exit;
  37. }
  38. //判断该添加渠道名称是否已经存在
  39. $checknicename = Db::name(self::AGENT_DB_NAME)->where(array("user_nicename" => $user_nicename))->find();
  40. if (!empty($checknicename)) {
  41. $this->hs_api_json('201', '该渠道名称已被使用,请勿重复添加');
  42. exit;
  43. }
  44. //判断该添加账号是否已经存在
  45. $checkusername = Db::name(self::AGENT_DB_NAME)->where(array("user_login" => $user_login))->find();
  46. if (!empty($checkusername)) {
  47. $this->hs_api_json('201', '该渠道账号已被使用,请勿重复添加');
  48. exit;
  49. }
  50. $_role_id = \huolib\constant\AgentConst::AGENT_ROLE_AGENT;
  51. $_parent_id = 1;
  52. $_rs = (new \huo\controller\agent\Agent())->addAgent(
  53. $user_login, $user_nicename, $user_pass, $_parent_id, $_role_id
  54. );
  55. if (!empty($_rs) && isset($_rs['code']) && 200 == $_rs['code']) {
  56. $this->hs_api_json('200', '创建一级渠道成功');
  57. }
  58. $this->hs_api_json('201', '创建一级渠道失败');
  59. }
  60. /**
  61. * 加推广员 二级渠道
  62. *
  63. * @param $_legion_name
  64. * @param $user_nicename
  65. * @param $user_login
  66. * @param $user_pass
  67. */
  68. public function oa2addSub($_legion_name, $user_nicename, $user_login, $user_pass) {
  69. if (!$this->hasOa()) {
  70. $this->hs_api_json('201', '未接通oa');
  71. exit;
  72. }
  73. if (!$_legion_name) {
  74. $this->hs_api_json('201', '一级渠道名称不能为空');
  75. exit;
  76. }
  77. if (!$user_nicename) {
  78. $this->hs_api_json('201', '二级渠道名称不能为空');
  79. exit;
  80. }
  81. if (!$user_pass) {
  82. $this->hs_api_json('201', '密码不能为空');
  83. exit;
  84. }
  85. if (!$user_login) {
  86. $this->hs_api_json('201', '帐号不能为空');
  87. exit;
  88. }
  89. $_legion_role_id = \huolib\constant\AgentConst::AGENT_ROLE_AGENT;
  90. $_legion_info = Db::name(self::AGENT_DB_NAME)->where(
  91. array('user_login' => $_legion_name, 'role_id' => $_legion_role_id)
  92. )->find();
  93. if (empty($_legion_info)) {
  94. $this->hs_api_json('201', '军团长不存在');
  95. exit;
  96. }
  97. //判断该添加渠道名称是否已经存在
  98. $checknicename = Db::name(self::AGENT_DB_NAME)->where(array("user_nicename" => $user_nicename))->find();
  99. if (!empty($checknicename)) {
  100. $this->hs_api_json('201', '该渠道名称已被使用,请勿重复添加');
  101. exit;
  102. }
  103. //判断该添加账号是否已经存在
  104. $checkusername = Db::name(self::AGENT_DB_NAME)->where(array("user_login" => $user_login))->find();
  105. if (!empty($checkusername)) {
  106. $this->hs_api_json('201', '该渠道账号已被使用,请勿重复添加');
  107. exit;
  108. }
  109. $_role_id = \huolib\constant\AgentConst::AGENT_ROLE_GH;
  110. $_parent_id = $_legion_info['id'];
  111. $_rs = (new \huo\controller\agent\Agent())->addAgent(
  112. $user_login, $user_nicename, $user_pass, $_parent_id, $_role_id
  113. );
  114. if (!empty($_rs) && isset($_rs['code']) && 200 == $_rs['code']) {
  115. $this->hs_api_json('200', '创建二级渠道成功');
  116. }
  117. $this->hs_api_json('201', '创建二级渠道失败');
  118. }
  119. /**
  120. * 检测军团长
  121. *
  122. * @param $legion_name
  123. *
  124. * @return $this
  125. */
  126. public function checkAgentByAgentName($legion_name) {
  127. if (!$this->hasOa()) {
  128. $this->hs_api_json('201', '未接通oa');
  129. exit;
  130. }
  131. $_legion_name = $legion_name;
  132. $_map = array();
  133. $_map['user_login'] = $_legion_name;
  134. $_map['role_id'] = \huolib\constant\AgentConst::AGENT_ROLE_AGENT;
  135. $_rs = Db::name(self::AGENT_DB_NAME)->where($_map)->find();
  136. if (!empty($_rs)) {
  137. $this->hs_api_json('200', '军团长存在');
  138. } else {
  139. $this->hs_api_json('201', '军团长不存在');
  140. }
  141. }
  142. /**
  143. * @param string $legion_name
  144. * @param string $agent_name
  145. *
  146. *
  147. */
  148. public function checkAgentByAgentNameAndLegionName($legion_name = '', $agent_name = '') {
  149. if (!$this->hasOa()) {
  150. $this->hs_api_json('201', '未接通oa');
  151. exit;
  152. }
  153. $_map = array();
  154. $_map['user_login'] = $legion_name;
  155. $_map['role_id'] = \huolib\constant\AgentConst::AGENT_ROLE_AGENT;
  156. $_legion_info = Db::name(self::AGENT_DB_NAME)->where($_map)->find();
  157. if (!empty($_legion_info)) {
  158. $_agent_map = array();
  159. $_agent_map['user_login'] = $agent_name;
  160. $_agent_map['role_id'] = \huolib\constant\AgentConst::AGENT_ROLE_GH;
  161. $_agent_info = Db::name(self::AGENT_DB_NAME)->where($_agent_map)->find();
  162. if (!empty($_agent_info)) {
  163. if ($_agent_info['parent_id'] == $_legion_info['id']) {
  164. $this->hs_api_json('200', '推广员存在');
  165. }
  166. $this->hs_api_json('201', '军团长和推广员关系错误');
  167. } else {
  168. $this->hs_api_json('201', '推广员不存在');
  169. }
  170. } else {
  171. $this->hs_api_json('201', '军团长不存在');
  172. }
  173. }
  174. }