Commit 333e99ac authored by clone's avatar clone

新增客户

parent 92d19c12
......@@ -328,7 +328,7 @@ class Member extends Basic{
if ($result == -1) {
return $this->response(101, '该用户已经存在!');
}
$this->params['id'] = $result;
}
......
......@@ -22,13 +22,13 @@ class Users extends Model
*/
public function selectUser($userId, $fields = 'id,user_phone')
{
$param["status"] = array( "in", [-1,0] );
$data = $this->field($fields)
$param["status"] = array( "in", [ -1, 0 ] );
$data = $this->field($fields)
->where($param)
->find($userId);
if (isset($data->user_pic)) {
$data->user_pic = HEADERIMGURL.$data->user_pic;
$data->user_pic = HEADERIMGURL . $data->user_pic;
}
return $data;
}
......@@ -64,7 +64,8 @@ class Users extends Model
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getUserAgent($pageNo = 1, $pageSize = 15, $order_ = 'a.id desc', $fields = '*', $params = '', $type = 0) {
public function getUserAgent($pageNo = 1, $pageSize = 15, $order_ = 'a.id desc', $fields = '*', $params = '', $type = 0)
{
$data = [];
......@@ -79,16 +80,16 @@ class Users extends Model
} elseif ($type == 2) {
$result = $this->field($fields)
->alias('a')
->join('u_phone_follow_up b','a.id = b.user_id', 'left')
->join('u_phone_follow_up b', 'a.id = b.user_id', 'left')
->where($params)
->order($order_)
->limit($pageSize)
->page($pageNo)
->select();
} elseif($type == 3) {
} elseif ($type == 3) {
$result = $this->field($fields)
->alias('a')
->join('a_agents b','a.agent_id = b.id', 'left')
->join('a_agents b', 'a.agent_id = b.id', 'left')
->where($params)
->order($order_)
->limit($pageSize)
......@@ -104,19 +105,19 @@ class Users extends Model
}
$user_follow = new UPhoneFollowPp();
foreach ($result as $k=>$v) {
foreach ($result as $k => $v) {
$data[$k] = $v->getData();
if ($data[$k]['user_pic']) {
$data[$k]['user_pic'] = CURRENT_URL.'static/head_portrait/'.$data[$k]['user_pic'];
$data[$k]['user_pic'] = CURRENT_URL . 'static/head_portrait/' . $data[$k]['user_pic'];
} else {
$data[$k]['user_pic'] = '';
}
$user_data = $this->field('id,user_nick,user_phone')->where('id',$data[$k]['referrer_id'])->find();
$data[$k]['name'] = $user_data['user_nick'];
$data[$k]['phone'] = $user_data['user_phone'];
$data[$k]['follow_time'] = $user_follow->where('user_id',$data[$k]['id'])->order('id desc')->value('create_time');
$user_data = $this->field('id,user_nick,user_phone')->where('id', $data[$k]['referrer_id'])->find();
$data[$k]['name'] = $user_data['user_nick'];
$data[$k]['phone'] = $user_data['user_phone'];
$data[$k]['follow_time'] = $user_follow->where('user_id', $data[$k]['id'])->order('id desc')->value('create_time');
}
return $data;
}
......@@ -131,21 +132,22 @@ class Users extends Model
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getUserAgentTotal($params, $type = 0) {
public function getUserAgentTotal($params, $type = 0)
{
if ($type == 1) {
$id = $this->field('id')->where('user_phone','LIKE',$params['user_phone']['1'].'%')->find();
$id = $this->field('id')->where('user_phone', 'LIKE', $params['user_phone']['1'] . '%')->find();
$result = $this->alias('a')
->where($params)
->where('referrer_id','=',$id->id)
->where('referrer_id', '=', $id->id)
->count();
} elseif ($type == 2 ) {
} elseif ($type == 2) {
$result = $this->alias('a')
->join('u_phone_follow_up b','a.id = b.user_id', 'left')
->join('u_phone_follow_up b', 'a.id = b.user_id', 'left')
->where($params)
->count();
} elseif($type == 3) {
} elseif ($type == 3) {
$result = $this->alias('a')
->join('a_agents b','a.agent_id = b.id', 'left')
->join('a_agents b', 'a.agent_id = b.id', 'left')
->where($params)
->count();
} else {
......@@ -160,7 +162,8 @@ class Users extends Model
* @param $params
* @return int|string
*/
public function getMyUserCount($params){
public function getMyUserCount($params)
{
$result = $this->alias('a')
->where($params)
->count();
......@@ -175,20 +178,21 @@ class Users extends Model
* @param int $status
* @return array
*/
public function delete_user($id, $status = 1) {
public function delete_user($id, $status = 1)
{
$arr = array(
"id" => $id,
"status" => $status,
"id" => $id,
"status" => $status,
"update_time" => date("Y-m-d H:i:s")
);
Db::startTrans();
try {
$id = $this->update($arr);
Db::commit();
return [ "code" => "200", "msg" => '删除成功', 'data'=>$id];
return [ "code" => "200", "msg" => '删除成功', 'data' => $id ];
} catch (\Exception $e) {
Db::rollback();
return [ "code" => "101", "msg" => "没有该用户", 'data'=>''];
return [ "code" => "101", "msg" => "没有该用户", 'data' => '' ];
}
}
......@@ -199,24 +203,40 @@ class Users extends Model
* @param int $id
* @return false|int
*/
public function edit($data, $id = 0) {
$insert_data['user_nick'] = $data['user_nick'];
if(!empty($data['user_phone'])){
public function edit($data, $id = 0)
{
if (!empty($data['user_nick'])) {
$insert_data['user_nick'] = $data['user_nick'];
}
if (!empty($data['user_phone'])) {
$insert_data['user_phone'] = $data['user_phone'];
}
$insert_data['sex'] = $data['sex'];
$insert_data['agent_id'] = $data['agents_id'];
if ($id) {
if (!empty($data['sex'])) {
$insert_data['sex'] = $data['sex'];
}
if (!empty($data['agents_id'])) {
$insert_data['agent_id'] = $data['agents_id'];
}
if (!empty($data['industry_type'])) {
$insert_data['industry_type'] = $data['industry_type'];
}
if (!empty($data['price_demand'])) {
$insert_data['price_demand'] = $data['price_demand'];
}
if (!empty($data['area_demand'])) {
$insert_data['area_demand'] = $data['area_demand'];
}
if ($id && $id > 0) {
//修改
$insert_data['update_time']= date('Y-m-d H:i:s');
$this->save($insert_data,['id'=>$id]);
$insert_data['update_time'] = date('Y-m-d H:i:s');
$this->save($insert_data, [ 'id' => $id ]);
$return_id = $id;
} else {
//新增
$is_exist = $this->where('user_phone',$data['user_phone'])->count();
$is_exist = $this->where('user_phone', $data['user_phone'])->count();
if (empty($is_exist)) {
$insert_data['source'] = 20;
$insert_data['status'] = -1;
$insert_data['source'] = 20;
$insert_data['status'] = -1;
$insert_data['create_time'] = date('Y-m-d H:i:s');
$this->save($insert_data);
$return_id = $this->id;
......@@ -237,13 +257,16 @@ class Users extends Model
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getClient($id) {
public function getClient($id)
{
if ($id) {
$data = $this->field('a.id as user_id,a.user_nick,a.user_phone,a.sex,a.agent_id,a.create_time,b.name,b.phone')
$field = "a.id as user_id,a.user_nick,a.user_phone,a.sex,a.agent_id,a.industry_type,a.price_demand,a.area_demand,a.create_time,b.name,b.phone";
$data = $this->field($field)
->alias('a')
->join('a_agents b','a.agent_id=b.id', 'left')
->where('a.id',$id)->find();
$data['agents'] = $data['name'].'-'.$data['phone'];
->join('a_agents b', 'a.agent_id=b.id', 'left')
->where('a.id', $id)->find();
$data['agents'] = $data['name'] . '-' . $data['phone'];
unset($data['name']);
unset($data['phone']);
} else {
......@@ -263,9 +286,10 @@ class Users extends Model
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAgentUserTb($p = 1, $pageSize = 15, $order_= 'id desc',$field, $where){
public function getAgentUserTb($p = 1, $pageSize = 15, $order_ = 'id desc', $field, $where)
{
$r = $this->field($field)
$r = $this->field($field)
->where($where)
->order($order_)
->limit($pageSize)
......@@ -307,12 +331,13 @@ class Users extends Model
* @param $params
* @return int|string
*/
public function getAddUserNumByAgentId($params){
public function getAddUserNumByAgentId($params)
{
$where_ = [];
if(isset($params["agent_id"])){
if (isset($params["agent_id"])) {
$where_["agent_id"] = $params["agent_id"];
}
if(isset($params["create_time"])){
if (isset($params["create_time"])) {
$where_["create_time"] = $params["create_time"];
}
return Db::table($this->table)
......@@ -326,13 +351,14 @@ class Users extends Model
* @param $params
* @return false|\PDOStatement|string|\think\Collection
*/
public function getAddUserNumGroupTime($params){
$field = "count(1) as num,DATE(create_time) as day";
public function getAddUserNumGroupTime($params)
{
$field = "count(1) as num,DATE(create_time) as day";
$where_ = [];
if(isset($params["agent_id"])){
if (isset($params["agent_id"])) {
$where_["agent_id"] = $params["agent_id"];
}
if(isset($params["create_time"])){
if (isset($params["create_time"])) {
$where_["create_time"] = $params["create_time"];
}
return Db::table($this->table)
......@@ -342,13 +368,14 @@ class Users extends Model
->select();
}
public function getAddUserNum($params){
$field = "count(1) as num";
public function getAddUserNum($params)
{
$field = "count(1) as num";
$where_ = [];
if(isset($params["agent_id"])){
if (isset($params["agent_id"])) {
$where_["agent_id"] = $params["agent_id"];
}
if(isset($params["create_time"])){
if (isset($params["create_time"])) {
$where_["create_time"] = $params["create_time"];
}
return Db::table($this->table)
......@@ -358,26 +385,26 @@ class Users extends Model
}
public function all_user_count($params='')
public function all_user_count($params = '')
{
return db('u_users')
->where($params)
->count();
}
/**
* 普通跟进,对客户状态进行更新
*/
public function update_user_status($conditions='')
public function update_user_status($conditions = '')
{
return db('u_users')->update($conditions);
}
public function all_user($params='',$pagesize,$pagenum)
public function all_user($params = '', $pagesize, $pagenum)
{
return db('u_users')
->where($params)
->order('id desc')
//->where('user_nick|user_phone','like',"%$phone_or_name%")
//->where('create_time','< time',$Two_days_ago)//小于两天前,即排除48小时内受保护的客户
->limit($pagesize)
......@@ -391,30 +418,31 @@ class Users extends Model
* @param $params
* @return false|mixed|\PDOStatement|string|\think\Collection
*/
public function insertUserConvert($params){
$where_ = [];
$params["user_phone"] = strlen($params["user_phone"])>11 ? substr($params["user_phone"], 0,11) : $params["user_phone"];
if(!isset($params["user_phone"]) || !preg_match('/^1[3456789]\d{9}$/', $params["user_phone"])){
return null;
public function insertUserConvert($params)
{
$where_ = [];
$params["user_phone"] = strlen($params["user_phone"]) > 11 ? substr($params["user_phone"], 0, 11) : $params["user_phone"];
if (!isset($params["user_phone"]) || !preg_match('/^1[3456789]\d{9}$/', $params["user_phone"])) {
return null;
}
$where_ ["user_phone"] = $params ["user_phone"];
$model = Db::name($this->table);
$model = Db::name($this->table);
$list = $model
$list = $model
->field("id,user_name,user_phone")
->where($where_)
->limit(1)
->limit(1)
->select();
if(count($list) > 0){
if (count($list) > 0) {
return $list[0];
}else{
$id = $model->insertGetId($params);
if($id > 0){
$list["id"] = $id;
$list["user_name"] = $params["user_name"];
$list["user_phone"] = $params["user_phone"];
return $list;
}
} else {
$id = $model->insertGetId($params);
if ($id > 0) {
$list["id"] = $id;
$list["user_name"] = $params["user_name"];
$list["user_phone"] = $params["user_phone"];
return $list;
}
}
}
......@@ -430,18 +458,20 @@ class Users extends Model
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getUserById($field = '*', $id, $where = '') {
public function getUserById($field = '*', $id, $where = '')
{
return $this->field($field)
->where('id',$id)
->where('id', $id)
->where($where)
->find();
}
public function getAgentByUserId($field,$params){
public function getAgentByUserId($field, $params)
{
return Db::name($this->table)
->field($field)
->alias("a")
->join("a_agents b","a.agent_id=b.id","left")
->join("a_agents b", "a.agent_id=b.id", "left")
->where($params)
->select();
}
......@@ -457,15 +487,16 @@ class Users extends Model
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function findUserByPhone($field = '*', $phone, $lock = false) {
public function findUserByPhone($field = '*', $phone, $lock = false)
{
if ($lock) {
$data = $this->field($field)
->where('user_phone',$phone)
->where('user_phone', $phone)
->lock(true)
->find();
} else {
$data = $this->field($field)
->where('user_phone',$phone)
->where('user_phone', $phone)
->find();
}
......@@ -477,7 +508,8 @@ class Users extends Model
* @return array|false
* @throws \Exception
*/
public function updateUserAll($data) {
public function updateUserAll($data)
{
return $this->saveAll($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