hasOa()) { $this->hs_api_json('201', '未接通oa'); exit; } if (!$user_nicename) { $this->hs_api_json('201', '渠道名称不能为空'); exit; } if (!$user_pass) { $this->hs_api_json('201', '密码不能为空'); exit; } if (!$user_login) { $this->hs_api_json('201', '帐号不能为空'); exit; } //判断该添加渠道名称是否已经存在 $checknicename = Db::name(self::AGENT_DB_NAME)->where(array("user_nicename" => $user_nicename))->find(); if (!empty($checknicename)) { $this->hs_api_json('201', '该渠道名称已被使用,请勿重复添加'); exit; } //判断该添加账号是否已经存在 $checkusername = Db::name(self::AGENT_DB_NAME)->where(array("user_login" => $user_login))->find(); if (!empty($checkusername)) { $this->hs_api_json('201', '该渠道账号已被使用,请勿重复添加'); exit; } $_role_id = \huolib\constant\AgentConst::AGENT_ROLE_AGENT; $_parent_id = 1; $_rs = (new \huo\controller\agent\Agent())->addAgent( $user_login, $user_nicename, $user_pass, $_parent_id, $_role_id ); if (!empty($_rs) && isset($_rs['code']) && 200 == $_rs['code']) { $this->hs_api_json('200', '创建一级渠道成功'); } $this->hs_api_json('201', '创建一级渠道失败'); } /** * 加推广员 二级渠道 * * @param $_legion_name * @param $user_nicename * @param $user_login * @param $user_pass */ public function oa2addSub($_legion_name, $user_nicename, $user_login, $user_pass) { if (!$this->hasOa()) { $this->hs_api_json('201', '未接通oa'); exit; } if (!$_legion_name) { $this->hs_api_json('201', '一级渠道名称不能为空'); exit; } if (!$user_nicename) { $this->hs_api_json('201', '二级渠道名称不能为空'); exit; } if (!$user_pass) { $this->hs_api_json('201', '密码不能为空'); exit; } if (!$user_login) { $this->hs_api_json('201', '帐号不能为空'); exit; } $_legion_role_id = \huolib\constant\AgentConst::AGENT_ROLE_AGENT; $_legion_info = Db::name(self::AGENT_DB_NAME)->where( array('user_login' => $_legion_name, 'role_id' => $_legion_role_id) )->find(); if (empty($_legion_info)) { $this->hs_api_json('201', '军团长不存在'); exit; } //判断该添加渠道名称是否已经存在 $checknicename = Db::name(self::AGENT_DB_NAME)->where(array("user_nicename" => $user_nicename))->find(); if (!empty($checknicename)) { $this->hs_api_json('201', '该渠道名称已被使用,请勿重复添加'); exit; } //判断该添加账号是否已经存在 $checkusername = Db::name(self::AGENT_DB_NAME)->where(array("user_login" => $user_login))->find(); if (!empty($checkusername)) { $this->hs_api_json('201', '该渠道账号已被使用,请勿重复添加'); exit; } $_role_id = \huolib\constant\AgentConst::AGENT_ROLE_GH; $_parent_id = $_legion_info['id']; $_rs = (new \huo\controller\agent\Agent())->addAgent( $user_login, $user_nicename, $user_pass, $_parent_id, $_role_id ); if (!empty($_rs) && isset($_rs['code']) && 200 == $_rs['code']) { $this->hs_api_json('200', '创建二级渠道成功'); } $this->hs_api_json('201', '创建二级渠道失败'); } /** * 检测军团长 * * @param $legion_name * * @return $this */ public function checkAgentByAgentName($legion_name) { if (!$this->hasOa()) { $this->hs_api_json('201', '未接通oa'); exit; } $_legion_name = $legion_name; $_map = array(); $_map['user_login'] = $_legion_name; $_map['role_id'] = \huolib\constant\AgentConst::AGENT_ROLE_AGENT; $_rs = Db::name(self::AGENT_DB_NAME)->where($_map)->find(); if (!empty($_rs)) { $this->hs_api_json('200', '军团长存在'); } else { $this->hs_api_json('201', '军团长不存在'); } } /** * @param string $legion_name * @param string $agent_name * * */ public function checkAgentByAgentNameAndLegionName($legion_name = '', $agent_name = '') { if (!$this->hasOa()) { $this->hs_api_json('201', '未接通oa'); exit; } $_map = array(); $_map['user_login'] = $legion_name; $_map['role_id'] = \huolib\constant\AgentConst::AGENT_ROLE_AGENT; $_legion_info = Db::name(self::AGENT_DB_NAME)->where($_map)->find(); if (!empty($_legion_info)) { $_agent_map = array(); $_agent_map['user_login'] = $agent_name; $_agent_map['role_id'] = \huolib\constant\AgentConst::AGENT_ROLE_GH; $_agent_info = Db::name(self::AGENT_DB_NAME)->where($_agent_map)->find(); if (!empty($_agent_info)) { if ($_agent_info['parent_id'] == $_legion_info['id']) { $this->hs_api_json('200', '推广员存在'); } $this->hs_api_json('201', '军团长和推广员关系错误'); } else { $this->hs_api_json('201', '推广员不存在'); } } else { $this->hs_api_json('201', '军团长不存在'); } } }