123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Ksh
- * Date: 2017/6/26
- * Time: 11:12
- */
- namespace huolib\oa;
- use think\Db;
- class OaAgent extends Oa {
- public function __construct() {
- parent::__construct();
- }
- /**
- * 添加军团长 一级渠道
- *
- * @param $user_nicename 渠道昵称
- * @param $user_login 渠道用户名
- * @param $user_pass 渠道密码
- */
- public function oa2AddAgent($user_nicename, $user_login, $user_pass) {
- if (!$this->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', '军团长不存在');
- }
- }
- }
|