Commit 333e99ac authored by clone's avatar clone

新增客户

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