Commit 1da0d767 authored by clone's avatar clone

bug

parent 66a631c2
......@@ -24,6 +24,7 @@ use think\Request;
class Broker extends Basic
{
protected $a_agents;
public function __construct(Request $request = null)
{
parent::__construct($request);
......@@ -38,41 +39,42 @@ class Broker extends Basic
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function login() {
$data['data'] = [];
public function login()
{
$data['data'] = [];
if (empty($this->params['phone']) && empty($this->params['pwd'])) {
return $this->response(101, '用户名或密码为空',$data['data']);
return $this->response(101, '用户名或密码为空', $data['data']);
}
$field = 'id,device_id,store_id,auth_group_id,district_id,level,name,phone,password,sex,img,inviter_id,status';
$where['phone'] = $this->params['phone'];
$where['id'] = ['<>',1];
$agents_data = $this->a_agents->getAgentInfo($field, '', $where);
$field = 'id,device_id,store_id,auth_group_id,district_id,level,name,phone,password,sex,img,inviter_id,status';
$where['phone'] = $this->params['phone'];
$where['id'] = [ '<>', 1 ];
$agents_data = $this->a_agents->getAgentInfo($field, '', $where);
if (empty($agents_data)) {
return $this->response(101, '没有该用户',$data['data']);
return $this->response(101, '没有该用户', $data['data']);
}
if ($agents_data['status'] == 2) {
return $this->response(101, '您已离职',$data['data']);
return $this->response(101, '您已离职', $data['data']);
}
if ($agents_data['status'] == 1) {
return $this->response(101, '账号已冻结',$data['data']);
return $this->response(101, '账号已冻结', $data['data']);
}
if ($agents_data['password'] != md5($this->params['pwd'])) {
return $this->response(101, '密码错误',$data['data']);
return $this->response(101, '密码错误', $data['data']);
}
$agents_data['device_id'] = $this->params['device_id'];
$agents_data['last_login_ip'] = ip2long($this->request->ip());
$agents_data['device_id'] = $this->params['device_id'];
$agents_data['last_login_ip'] = ip2long($this->request->ip());
$agents_data['last_login_time'] = date('Y-m-d H:i:s');
$agents_data->allowField(true)->save();
if (!empty($agents_data['img'])) {
$agents_data['img'] = AGENTHEADERIMGURL.$agents_data->img;
$agents_data['img'] = AGENTHEADERIMGURL . $agents_data->img;
}
$jwt_data['id'] = $agents_data['id'];
......@@ -80,11 +82,11 @@ class Broker extends Basic
$jwt_data['phone'] = $agents_data['phone'];
$jwt_data['level'] = $agents_data['level'];
$jwt = new JwtUntils();
$data['data'] = $agents_data->getData();
$jwt = new JwtUntils();
$data['data'] = $agents_data->getData();
$data['data']['last_login_ip'] = long2ip($data['data']['last_login_ip']);
$data['data']['AuthToken'] = $jwt->createToken($jwt_data);
$data['msg'] = '登陆成功';
$data['data']['AuthToken'] = $jwt->createToken($jwt_data);
$data['msg'] = '登陆成功';
return $this->response(200, $data['msg'], $data['data']);
}
......@@ -97,25 +99,26 @@ class Broker extends Basic
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getBroker() {
public function getBroker()
{
$data['status'] = 200;
$data['data'] = '';
$data['msg'] = '';
$data['data'] = '';
$data['msg'] = '';
$pageNo = empty($this->params['pageNo']) ? 1 : $this->params['pageNo'];
$pageSize = empty($this->params['pageSize']) ? 10 : $this->params['pageSize'];
$where = 'status <> 2';
if ($this->params['phone']) {
$where .= ' AND concat(phone,name) like "%'.$this->params['phone'].'%"';
$where .= ' AND concat(phone,name) like "%' . $this->params['phone'] . '%"';
}
if ($this->params['level']) {
$where .= ' AND level in ('.$this->params['level'].')';
$where .= ' AND level in (' . $this->params['level'] . ')';
}
if ($where) {
$field = 'id,name,phone';
$data['data'] = $this->a_agents->getList($pageNo, $pageSize, 'id DESC', $field, '',$where);
$field = 'id,name,phone';
$data['data'] = $this->a_agents->getList($pageNo, $pageSize, 'id DESC', $field, '', $where);
} else {
$data['msg'] = '没有经纪人信息';
}
......@@ -132,7 +135,7 @@ class Broker extends Basic
public function add_phone_follow_up()
{
header('Access-Control-Allow-Origin:*');
$params = $this->params;
$params = $this->params;
/*$params['content']='跟进内容';//跟进内容
$params['labels_id']=1;//g_labels表主键
$params['user_id']=1;//u_users ID用户表id
......@@ -143,25 +146,25 @@ class Broker extends Basic
return $this->response("300", "参数不全", [ 'remote_groupid' => '' ]);
}
$content = $params['content'];
$labels_id = $params['labels_id'];
$user_id = $params['user_id'];
$agent_id = $params['agent_id'];
$user_status = $params['user_status'];
$type = $params['type'];//0电话跟进 1普通跟进
$content = $params['content'];
$labels_id = $params['labels_id'];
$user_id = $params['user_id'];
$agent_id = $params['agent_id'];
$user_status = $params['user_status'];
$type = $params['type'];//0电话跟进 1普通跟进
//主表查询商铺详细信息
$UPhoneFollowPp = new UPhoneFollowPp();
$UPhoneFollowPp->content = $content;
$UPhoneFollowPp->labels_id = $labels_id;
$UPhoneFollowPp->user_id = $user_id;
$UPhoneFollowPp->agent_id = $agent_id;
$UPhoneFollowPp->type = $type;
$UPhoneFollowPp->user_status = $user_status;
$UPhoneFollowPp = new UPhoneFollowPp();
$UPhoneFollowPp->content = $content;
$UPhoneFollowPp->labels_id = $labels_id;
$UPhoneFollowPp->user_id = $user_id;
$UPhoneFollowPp->agent_id = $agent_id;
$UPhoneFollowPp->type = $type;
$UPhoneFollowPp->user_status = $user_status;
$UPhoneFollowPp->save();
//dump($UPhoneFollowPp->id);exit;
//跟进,对客户状态进行更新 0:求租;1:已租;-1:无效
$Users = new Users();
$Users -> update_user_status(['id'=>$user_id,'user_status'=>$user_status]);
$Users->update_user_status([ 'id' => $user_id, 'user_status' => $user_status ]);
if ($UPhoneFollowPp->id) {
return $this->response("200", "success!", $UPhoneFollowPp->id);
......@@ -180,9 +183,9 @@ class Broker extends Basic
*/
public function user_search()
{
$Two_days_ago = date("Y-m-d h:i:s",strtotime("-2 day"));
$Two_days_ago = date("Y-m-d h:i:s", strtotime("-2 day"));
//dump($Two_days_ago);
$params = $this->params;
$params = $this->params;
/* $params['phone_or_name'] ='周振磊';
$params['pagenum'] ='1';
$params['user_id'] ='10';*/
......@@ -190,42 +193,45 @@ class Broker extends Basic
return $this->response("300", "参数不全", [ 'remote_groupid' => '' ]);
}
$phone_or_name = trim($params['phone_or_name']);
$pagenum = isset($params['pagenum']) ? $params['pagenum'] : 1;
$pagesize = 15;
$user_id = $params['user_id'];
$phone_or_name = trim($params['phone_or_name']);
$pagenum = isset($params['pagenum']) ? $params['pagenum'] : 1;
$pagesize = 15;
$user_id = $params['user_id'];
$user = new Users();
// 查询数据集
$user_res =$user ->where('user_name|user_phone','like',"%$phone_or_name%")
$user_res = $user->where('user_name|user_phone', 'like', "%$phone_or_name%")
//->where('create_time','< time',$Two_days_ago)//小于两天前,即排除48小时内受保护的客户
// ->whereOr('agent_id',$user_id)
->limit($pagesize)
->page($pagenum)
->field('id as user_id,sex,user_name,user_phone')
->field('id as user_id,sex,user_name,user_nick,user_phone')
->select();
// echo $user->getLastSql();
// echo $user->getLastSql();
//$user_res =$user->user_search($phone_or_name,$Two_days_ago,$user_id,$pagesize,$pagenum);
$total =$user ->where('user_name|user_phone','like',"%$phone_or_name%")
$total = $user->where('user_name|user_phone|user_nick', 'like', "%$phone_or_name%")
//->where('create_time','< time',$Two_days_ago)
// ->whereOr('agent_id',$user_id)
->count();
$total = intval($total / $pagesize) + (($total % $pagesize == 0) ? 0 : 1);
$user_res=json_decode(json_encode($user_res),true);//对象转数组
foreach($user_res as $k=>$v){
$total = intval($total / $pagesize) + (($total % $pagesize == 0) ? 0 : 1);
$user_res = json_decode(json_encode($user_res), true);//对象转数组
foreach ($user_res as $k => $v) {
//dump($v);exit;
$user_res[$k]['user_name']=$v['user_name']?$v['user_name']:'未知';
if (empty($v["user_name"])) {
$user_res[$k]['user_name'] = $v["user_nick"];
}
$user_res[$k]['user_name'] = $v['user_name'] ? $v['user_name'] : '未知';
}
/*dump($total);
var_dump($user_res);
exit;*/
if ($user_res) {
return $this->response("200", "success!", ['user_date'=>$user_res,'pagenum'=>$pagenum,'total'=>$total]);
return $this->response("200", "success!", [ 'user_date' => $user_res, 'pagenum' => $pagenum, 'total' => $total ]);
} else {
return $this->response("200", "request null",['user_date'=>[],'pagenum'=>$pagenum,'total'=>$total]);
return $this->response("200", "request null", [ 'user_date' => [], 'pagenum' => $pagenum, 'total' => $total ]);
}
}
......@@ -241,55 +247,55 @@ class Broker extends Basic
{
header('Access-Control-Allow-Origin:*');
$params = $this->params;
/* $params = array(
"user_id" => 828
);*/
/* $params = array(
"user_id" => 828
);*/
if (!isset($params['user_id'])) {
return $this->response("300", "参数不全", [ 'remote_groupid' => '' ]);
}
$user_id = $params['user_id'];
$user_id = $params['user_id'];
$agent = new AAgents();
/* $searchdate = empty($params['searchdate']) ? '':$params['searchdate'];
$pagenum = isset($params['pagenum']) ? $params['pagenum'] : 1;
$pagesize = 15;
/* $searchdate = empty($params['searchdate']) ? '':$params['searchdate'];
$pagenum = isset($params['pagenum']) ? $params['pagenum'] : 1;
$pagesize = 15;
$UPhoneFollowPp = new UPhoneFollowPp();
// 查询电话跟进数据
$UPhoneFollowPp_res = $UPhoneFollowPp->select_useraction_search($user_id,$searchdate);
$UPhoneFollowPp = new UPhoneFollowPp();
// 查询电话跟进数据
$UPhoneFollowPp_res = $UPhoneFollowPp->select_useraction_search($user_id,$searchdate);
foreach($UPhoneFollowPp_res as $k=>$v){
$agents_res = $agent->verifyUser('name,phone,img','',['id'=>$v['agent_id']]);
$UPhoneFollowPp_res[$k]['agentinfo'] = $agents_res ? $agents_res['name'].'-'.$agents_res['phone']:'未知';
$UPhoneFollowPp_res[$k]['user_pic'] = AGENTHEADERIMGURL.$agents_res['img'];
$UPhoneFollowPp_res[$k]['label'] = '';
foreach($UPhoneFollowPp_res as $k=>$v){
$agents_res = $agent->verifyUser('name,phone,img','',['id'=>$v['agent_id']]);
$UPhoneFollowPp_res[$k]['agentinfo'] = $agents_res ? $agents_res['name'].'-'.$agents_res['phone']:'未知';
$UPhoneFollowPp_res[$k]['user_pic'] = AGENTHEADERIMGURL.$agents_res['img'];
$UPhoneFollowPp_res[$k]['label'] = '';
//电话跟进标签
if($v['labels_id']){
$labels = new ULabels();
$table_res = $labels->get_labelsname($v['labels_id']);
$UPhoneFollowPp_res[$k]['label'] = $table_res[0]['name'];
}
}*/
//电话跟进标签
if($v['labels_id']){
$labels = new ULabels();
$table_res = $labels->get_labelsname($v['labels_id']);
$UPhoneFollowPp_res[$k]['label'] = $table_res[0]['name'];
}
}*/
$user = new Users();
$user_res = $user->useraction_search_user_res($user_id);
$user = new Users();
$user_res = $user->useraction_search_user_res($user_id);
$user_res['user_pic'] = HEADERIMGURL.$user_res['user_pic'];
$user_res['user_pic'] = HEADERIMGURL . $user_res['user_pic'];
$agents_res = $agent->verifyUser('name,phone','', ['id'=>$user_res['agent_id']]);
$user_res['agentinfo'] = $agents_res ? $agents_res['name'].'-'.$agents_res['phone']:'未知';
$agents_res = $agent->verifyUser('name,phone', '', [ 'id' => $user_res['agent_id'] ]);
$user_res['agentinfo'] = $agents_res ? $agents_res['name'] . '-' . $agents_res['phone'] : '未知';
$orderLog = new OrderLogService();
$records = new GOperatingRecords();
$records_result = $records->user_history($user_id);
$data['user_info'] = $user_res;
$data['user_date'] = $orderLog->selectListByUserId($user_id,'');
$orderLog = new OrderLogService();
$records = new GOperatingRecords();
$records_result = $records->user_history($user_id);
$data['user_info'] = $user_res;
$data['user_date'] = $orderLog->selectListByUserId($user_id, '');
$data['user_history'] = $records_result;
$data['agent_path'] = AGENTHEADERIMGURL;
$data['agent_path'] = AGENTHEADERIMGURL;
return $this->response("200", "success!", $data);
}
......@@ -297,25 +303,27 @@ class Broker extends Basic
* 搜索动态
* @return \think\Response
*/
public function userStateSearch(){
public function userStateSearch()
{
$params = $this->params;
/* $params = array(
"user_id" => 828,
"keyword" => "asdfas"
);*/
if(!isset($params["user_id"]) || !isset($params["keyword"])){
return $this->response("101","请输入需要检索的关键词");
}
$orderLog = new OrderLogService();
$data = $orderLog->selectListByUserId($params["user_id"],$params["keyword"]);
/* $params = array(
"user_id" => 828,
"keyword" => "asdfas"
);*/
if (!isset($params["user_id"]) || !isset($params["keyword"])) {
return $this->response("101", "请输入需要检索的关键词");
}
$orderLog = new OrderLogService();
$data = $orderLog->selectListByUserId($params["user_id"], $params["keyword"]);
$data['agent_path'] = AGENTHEADERIMGURL;
return $this->response("200","request success",$data);
return $this->response("200", "request success", $data);
}
/**
* 编辑密码
*/
public function editAgent() {
public function editAgent()
{
$data['code'] = 200;
$data['msg'] = "";
$data['data'] = [];
......@@ -342,10 +350,11 @@ class Broker extends Basic
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function forgetPwd() {
public function forgetPwd()
{
$data['code'] = 101;
$data['msg'] = "";
$data['data'] = [];
$data['data'] = [];
if (empty($this->params['pwd'])) {
return $this->response(101, '手机号为空', $data['data']);
......@@ -359,23 +368,23 @@ class Broker extends Basic
return $this->response(101, 'Token is null', $data['data']);
}
$agents = new AAgents();
$agents = new AAgents();
$agent_data = $agents->getInfo($this->params['phone'], '', false, 'id');
if (empty($agent_data['id'])) {
return $this->response(101, '没有该用户信息', $data['data']);
}
$jwt = new JwtUntils();
$jwt_data = $jwt->getDecode($this->params['token']);
$code = $jwt_data['data']['code'];
$jwt_phone = $jwt_data['data']['phone'];
$jwt = new JwtUntils();
$jwt_data = $jwt->getDecode($this->params['token']);
$code = $jwt_data['data']['code'];
$jwt_phone = $jwt_data['data']['phone'];
if ($code == $this->request->param('code') && $jwt_phone == $this->params['phone']) {
if ($code == $this->request->param('code') && $jwt_phone == $this->params['phone']) {
$agents->forgetPwd($agent_data['id'], $this->params['pwd']);
$data['data'] = ['id' => $agent_data['id']];
$data['data'] = [ 'id' => $agent_data['id'] ];
$data['code'] = 200;
$data['msg'] = '修改成功';
$data['msg'] = '修改成功';
} else {
$data['msg'] = '验证码错误';
}
......@@ -391,33 +400,34 @@ class Broker extends Basic
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function uploadHeadImg() {
public function uploadHeadImg()
{
$data['status'] = 101;
$data['msg'] = '';
$data['data'] = '';
$file = request()->file('image');
if($file){
$path = ROOT_PATH . 'public' . DS . 'static'. DS . 'user_header';
$info = $file->validate(['size'=>512000,'ext'=>'jpg,png']) //限制500KB
if ($file) {
$path = ROOT_PATH . 'public' . DS . 'static' . DS . 'user_header';
$info = $file->validate([ 'size' => 512000, 'ext' => 'jpg,png' ])//限制500KB
->move($path);
if($info){
$user = new AAgents();
$user_data = $user->field('img')->where('id',$this->agentId)->find();
@unlink($path.DS.$user_data->img); //删除原来的图片
$img_path = $info->getSaveName(); //生成的图片路径
if ($info) {
$user = new AAgents();
$user_data = $user->field('img')->where('id', $this->agentId)->find();
@unlink($path . DS . $user_data->img); //删除原来的图片
$img_path = $info->getSaveName(); //生成的图片路径
//更新用户信息
$user_data->img = $img_path;
$user_data->save();
$static_path = $path.DS.$img_path; //生成图片的绝对路径
$image = \think\Image::open($static_path);
$static_path = $path . DS . $img_path; //生成图片的绝对路径
$image = \think\Image::open($static_path);
$image->thumb(500, 500)->save($static_path); //生成缩略图
$data['status'] = 200;
$data['msg'] = '上传成功';
$data['data'] = ['file_name' => AGENTHEADERIMGURL . $img_path];
}else{
$data['data'] = [ 'file_name' => AGENTHEADERIMGURL . $img_path ];
} else {
// 上传失败获取错误信息
$data['msg'] = $file->getError();
}
......@@ -433,12 +443,13 @@ class Broker extends Basic
*
* @return \think\Response
*/
public function token(){
public function token()
{
header('Access-Control-Allow-Origin:*');
$jwt = new JwtUntils();
$jwt = new JwtUntils();
$data['phone'] = $this->params['phone'];
$token = $jwt->createToken($data);
return $this->response(200, "", ['AuthToken'=>$token]);
$token = $jwt->createToken($data);
return $this->response(200, "", [ 'AuthToken' => $token ]);
}
/**
......@@ -449,10 +460,11 @@ class Broker extends Basic
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAgentsByPhone() {
public function getAgentsByPhone()
{
header('Access-Control-Allow-Origin:*');
$agents = new AAgents();
$data = $agents->getInfo($this->agentPhone);
$agents = new AAgents();
$data = $agents->getInfo($this->agentPhone);
$data['openid'] = "";
$data['token'] = $this->authToken;
return $this->response(200, "", $data);
......@@ -466,7 +478,8 @@ class Broker extends Basic
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function sendSms() {
public function sendSms()
{
$data['data'] = [];
$data['status'] = 101;
......@@ -482,24 +495,24 @@ class Broker extends Basic
//忘记密码验证
if ($this->params['type'] == 'forget') {
$agent = new AAgents();
$num = $agent->getAgentExist($this->params['phone']);
$num = $agent->getAgentExist($this->params['phone']);
if ($num == 0) {
return $this->response($data['status'], '您未注册,请注册');
}
}
$noteLog = new NoteLog();
$send_time = $noteLog->field('send_time')->where('phone', $this->params['phone'])
->where('is_success',1)
->where('send_time','between time',[date('Y-m-d').' 00:00:00',date('Y-m-d').' 23:59:59'])
$noteLog = new NoteLog();
$send_time = $noteLog->field('send_time')->where('phone', $this->params['phone'])
->where('is_success', 1)
->where('send_time', 'between time', [ date('Y-m-d') . ' 00:00:00', date('Y-m-d') . ' 23:59:59' ])
->select();
$num = count($send_time); //发送数量
$num = count($send_time); //发送数量
if (!empty($send_time[$num-1]) && (time() - strtotime($send_time[$num-1]->send_time) < 58) && $num != 0) {
if (!empty($send_time[$num - 1]) && (time() - strtotime($send_time[$num - 1]->send_time) < 58) && $num != 0) {
return $this->response($data['status'], '1分钟内不能再次获取验证码', $data['data']);
}
if ($num > 7){
if ($num > 7) {
return $this->response($data['status'], '短信发送超过上限', $data['data']);
}
......@@ -507,15 +520,15 @@ class Broker extends Basic
$result['statusCode'] = '';
$message = new MessageUntils();
$result = $message->sendCheckCode($this->params['phone']);
$result = $message->sendCheckCode($this->params['phone']);
if (empty($result['status'])) {
$data['msg'] = '短信发送失败';
$data['msg'] = '短信发送失败';
} else {
$data['status'] = 200;
$data['data']['token'] = $result['token'];
$data['data']['sms_code'] = $result['sms_code'];
$data['msg'] = '短信发送成功';
$data['status'] = 200;
$data['data']['token'] = $result['token'];
$data['data']['sms_code'] = $result['sms_code'];
$data['msg'] = '短信发送成功';
}
return $this->response($data['status'], $data['msg'], $data['data']);
}
......@@ -527,9 +540,10 @@ class Broker extends Basic
* @throws \Endroid\QrCode\Exception\InvalidPathException
* @throws \Endroid\QrCode\Exception\InvalidWriterException
*/
public function qrCode() {
public function qrCode()
{
$parms = $this->params;
$parms = $this->params;
$data['status'] = 101;
$data['data'] = array();
$data['msg'] = '';
......@@ -542,10 +556,10 @@ class Broker extends Basic
return $this->response($data['status'], '没有该用户', $data['data']);
}
$code = new GenerateCodeUntils();
$url = $this->request->domain().'/app/share_register?referrer_source=20&id='.$this->agentId;
$path = $code->getCode($url, $this->agentId, 2);
$data['data'] = ['path' => $this->request->domain().'/'.$path];
$code = new GenerateCodeUntils();
$url = $this->request->domain() . '/app/share_register?referrer_source=20&id=' . $this->agentId;
$path = $code->getCode($url, $this->agentId, 2);
$data['data'] = [ 'path' => $this->request->domain() . '/' . $path ];
$data['status'] = 200;
return $this->response($data['status'], $data['msg'], $data['data']);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment