Commit 52424ff0 authored by zhuwei's avatar zhuwei

3

parent 870b5fbe
<?php
/**
* Created by PhpStorm.
* User: fu ju
* Date: 2018/1/20
* Time: 17:52
*/
namespace app\model;
use think\Db;
use think\Log;
class AAgents extends BaseModel
{
protected $table = 'a_agents';
/**
* 返回经纪人和部门信息
*
* @param $phone
* @param string $pwd
* @param bool $department
* @param string $field
* @return array|false|\PDOStatement|string|\think\Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getInfo($phone, $pwd = '', $department = true, $field = '*')
{
$where['status'] = 0;
$where['phone'] = $phone;
if ($pwd != '') {
$where['password'] = md5($pwd);
}
$agents_data = $this->field($field)->where($where)->find();
if (!$department) {
return $agents_data;
}
if (!empty($agents_data->store_id)) {
$store_name = Db::table('a_store')->where('id', $agents_data['store_id'])->value('store_name');
$agents_data['department'] = $store_name;
}
if (!empty($agents_data->auth_group_id)) {
$district_name = Db::table('a_district')->where('id', $agents_data['district_id'])->value('district_name');
$agents_data['department'] = $district_name ? $district_name . '-' . $store_name : $district_name;
}
$agents_data['commission'] = 500;
switch ($agents_data['level']) {
case 10 :
$agents_data['level_name'] = '业务员';
break;
case 20 :
$agents_data['level_name'] = '店长';
break;
case 30 :
$agents_data['level_name'] = '总监';
break;
case 40 :
$agents_data['level_name'] = '总监';
break;
}
return $agents_data;
}
/**分页列表
* @param int $p
* @param int $pageSize
* @param string $order_
* @param string $field
* @param string $join
* @param string $where
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getListJoin($p = 1, $pageSize = 15, $order_ = 'id desc', $field = '', $join = '', $where = '')
{
$data = $this->field($field)
->alias('a')
->join($join)
->where($where)
->order($order_)
->limit($pageSize)
->page($p)
->select();
//echo $this->getLastSql();
return $data;
}
//更新数据
public function saveStatus($name, $key, $ids)
{
$r = $this->where("id", 'in', $ids)->update([ $name => $key ]);
return $r;
}
/**
* 通过ids批量添加数据
*
* @param $ids
* @param $data
* @return array|false|int
* @throws \Exception
*/
public function addAllAccess($ids, $data)
{
$idarr = explode($ids);
if (is_array($idarr)) {
$arr = array();
foreach ($idarr as $v) {
$data['uid'] = $v;
$arr[] = $data;
}
$r = $this->saveAll($arr);
} else {
$data['uid'] = $ids;
$r = $this->save($data);
}
return $r;
}
/**
* 记录总数
*
* @param $params
* @return int|string
*/
public function getTotal2($join, $params)
{
return $this->alias('a')
->join($join)
->where($params)->count();
}
/**
* 操作盘方记录
*
* @param int $pageNo
* @param int $pageSize
* @param string $order_
* @param string $field
* @param string $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getRecords($pageNo = 1, $pageSize = 15, $order_ = 'id desc', $field = '', $params = '')
{
$data = Db::table('g_operating_records')
->field($field)
->where($params)
->limit($pageSize)
->order($order_)
->page($pageNo)
->select();
return $data;
}
/**
* @param $field
* @param $join
* @param $params
* @return array|false|\PDOStatement|string|\think\Model
*/
public function verifyUser($field, $join, $params)
{
try {
$data = $this->field($field)
->alias('a')
->join($join)
->where($params)
->find();
} catch (\Exception $e) {
$data = [];
}
return $data;
}
/**
* 总监列表
*
* @param int $pageNo
* @param int $pageSize
* @param string $order_
* @param string $field
* @param string $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getListDistrict($pageNo = 1, $pageSize = 15, $order_ = 'id desc', $field = '', $params = '')
{
$data = $this->field($field)
->where($params)
->order($order_)
->limit($pageSize)
->page($pageNo)
->select();
$district_where['status'] = 0;
$store_where['status'] = 0;
$result = array();
foreach ($data as $k => $v) {
$result[$k] = $v;
if (isset($v->district_id)) {
$district_where['id'] = $v->district_id;
$result[$k]['district_name'] = Db::table('a_district')->where($district_where)->value('district_name');
if ($result[$k]['district_name']) {
$store_where['district_id'] = $v->district_id;
$result[$k]['store_num'] = Db::table('a_store')->where($store_where)->count('store_name');
} else {
$result[$k]['store_num'] = '';
}
}
}
return $result;
}
/**
* 总监列表总数
*
* @param $params
* @return int|string
*/
public function getListDistrictTotal($params)
{
return $this->where($params)
->count();
}
/**
* 获取经纪人
*
* @param string $field
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAgentById($field = "id", $params)
{
$where_ = [];
if (isset($params["agent_id"])) {
$where_["id"] = $params["agent_id"];
}
if (isset($params["name"])) {
$where_["name"] = $params["name"];
}
if (isset($params["phone"])) {
$where_["phone"] = $params["phone"];
}
if (isset($params["store_id"])) {
$where_["store_id"] = $params["store_id"];
}
if (isset($params["district_id"])) {
$where_["district_id"] = $params["district_id"];
}
if (isset($params["status"])) {
$where_["status"] = $params["status"];
}
if (isset($params["level"])) {
$where_["level"] = $params["level"];
}
if (isset($params['in_id'])) {
$where_['id'] = [ 'in', $params['in_id'] ];
}
if (isset($params['id'])) {
$where_['id'] = $params['id'];
}
$result = $this->field($field)
->where($where_)
->select();
// echo $this->getLastSql();
return $result;
}
public function getAgentByIdV2($field = "a.id", $params, $page_no, $page_size)
{
$order_ = 'a.id desc';
$where_ = [];
if (isset($params["agent_id"])) {
$where_["a.id"] = $params["agent_id"];
}
if (isset($params["name"])) {
$where_["a.name"] = $params["name"];
}
if (isset($params["phone"])) {
$where_["a.phone"] = $params["phone"];
}
if (isset($params["store_id"])) {
$where_["a.store_id"] = $params["store_id"];
}
if (isset($params["district_id"])) {
$where_["a.district_id"] = $params["district_id"];
}
if (isset($params["status"])) {
$where_["a.status"] = $params["status"];
}
if (isset($params["level"])) {
$where_["a.level"] = $params["level"];
}
if (isset($params['in_id'])) {
$where_['a.id'] = [ 'in', $params['in_id'] ];
}
$result = $this->field($field)
->alias('a')
->join('a_store b', 'a.store_id = b.id', 'left')
->where($where_)
->limit($page_size)
->page($page_no)
->order($order_)
->select();
//echo $this->getLastSql();
return $result;
}
/**
* 修改密码
*
* @param $id
* @param $pwd
* @param $old_pwd
* @return bool|false|int
*/
public function editPwd($id, $pwd, $old_pwd)
{
$field_pwd = $this->where('id', $id)->value('password');
if ($field_pwd == md5($old_pwd)) {
$result = $this->save([ 'password' => md5($pwd) ], [ 'id' => $id ]);
} else {
$result = false;
}
return $result;
}
/**
* 忘记密码
*
* @param $id
* @param $pwd
* @return false|int
*/
public function forgetPwd($id, $pwd)
{
return $this->save([ 'password' => md5($pwd) ], [ 'id' => $id ]);
}
/**
* 分页列表
* @param int $p
* @param int $pageSize
* @param string $order_
* @param string $field
* @param string $join
* @param string $where
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getList($p = 1, $pageSize = 15, $order_ = 'id desc', $field = '', $join = '', $where = '')
{
$data = $this->field($field)
->alias('a')
->join($join)
->where($where)
->order($order_)
->limit($pageSize)
->page($p)
->select();
return $data;
}
/**
* 统计任务获取经纪人列表
*
* @param int $pageNo
* @param int $pageSize
* @param string $field
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAgentsListByTask($pageNo = 1, $pageSize = 15, $field = "id")
{
$params["district_id"] = array( 'not in', array( '13', '14', '15' ) );
return Db::table($this->table)
->field($field)
->where($params)
->limit($pageSize)
->page($pageNo)
->select();
}
/**
* @param string $field
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAgentsListByPK( $field = "id",$params)
{
$data = Db::table($this->table)
->field($field)
->alias("a")
->join("t_agent_total b","a.id=b.agent_id","left")
->join("a_store c","a.store_id=c.id","left")
->where($params)
->group("b.agent_id")
->order("performance desc")
->select();
//echo $this->getLastSql();
return $data;
}
public function getAgentListByPk1($siteId,$position,$startTime,$endTime,$ids){
$str_ids = " ";
if($ids){
$str_ids = " and a.id in ($ids)";
}
$sql = "select aa.id,aa.store_name,aa.name,aa.phone,aa.performance from
(select a.id,c.store_name,a.name,a.phone,0.00 as performance from a_agents a
left join a_store c on a.store_id=c.id
where a.position=$position and a.site_id=$siteId and a.status in (0,3) $str_ids )
as aa left join
(select a.id,c.store_name,a.name,a.phone,0.00 as performance from a_agents a
left join t_agent_total b on a.id=b.agent_id left join a_store c on a.store_id=c.id
where b.total_time BETWEEN '$startTime' and '$endTime'and a.status in (0,3) $str_ids GROUP BY b.agent_id )
as bb on aa.id = bb.id where bb.id is null" ;
$data = Db::table($this->table)->query($sql);
//echo $this->getLastSql();
return $data;
}
/**
* 获取经纪人列表--排掉店子和总监
*
* @param int $pageNo
* @param int $pageSize
* @param string $field
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAgentsListByLookShop($pageNo = 1, $pageSize = 15, $field = "id")
{
$where["level"] = 10;
return Db::table($this->table)
->field($field)
->where($where)
->limit($pageSize)
->page($pageNo)
->select();
}
/**
* 获取经纪人总数
* @return int|string
*/
public function getAgentsCountByTask()
{
$params["district_id"] = array( 'not in', array( '13', '14', '15' ) );
return Db::table($this->table)
->where($params)
->count();
}
/**
* 批量获取经纪人
*
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAgentsByStoreId($params)
{
$result = Db::table($this->table)
->field("id,name,status")
->where($params)
->select();
//echo Db::table($this->table)->getLastSql();
//dump($this->getLastSql());
return $result;
}
/**
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function countAgentNum($params)
{
$where_ = $whereOr_ = [];
if (isset($params["quit_time"])) {
$whereOr_["a.quit_time"] = $params["quit_time"];
$whereOr_["a.status"] = 3;
}
if (isset($params["district_id"])) {
$where_["a.district_id"] = $params["district_id"];
$where_["a.status"] = 0;
}
$result = Db::table($this->table)
->field("a.id,a.store_id ,b.store_name,count(a.id) as agent_num")
->alias("a")
->join("a_store b", "a.store_id = b.id", "left")
->where($where_)
->whereOr(function ($query) use ($whereOr_) {
$query->where($whereOr_);
})
->group("a.store_id")
->select();
//echo Db::table($this->table)->getLastSql();
return $result;
}
/**
* @param $field
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAgentsInfoByAgentId($field, $params)
{
$where_ = [];
if (isset($params["agent_id"])) {
$where_["a.id"] = $params["agent_id"];
}
if (isset($params["phone"])) {
$where_["a.phone"] = $params["phone"];
}
if (isset($params["store_id"])) {
$where_["b.id"] = $params["store_id"];
$where_["a.level"] = array( "in", "20,40" );
}
if (isset($params["district_id"])) {
$where_["c.id"] = $params["district_id"];
$where_["a.level"] = array( "in", "30,40" );
}
$where_["a.status"] = 0;
$result = Db::table($this->table)
->field($field)
->alias("a")
->join("a_store b", "a.store_id = b.id", "left")
->join("a_district c", "a.district_id = c.id", "left")
->where($where_)
->select();
//echo $this->getLastSql();
return $result;
}
/**
* 查询经纪人信息-业绩排行用
* @param $field
* @param $params
* @return false|\PDOStatement|string|\think\Collection
*/
public function getAgentsInfoByAgentIdForPerformanceService($field, $params)
{
$where_ = [];
if (isset($params["agent_id"])) {
$where_["a.id"] = $params["agent_id"];
}
if (isset($params["phone"])) {
$where_["a.phone"] = $params["phone"];
}
if (isset($params["store_id"])) {
$where_["b.id"] = $params["store_id"];
$where_["a.level"] = array( "in", "20,40" );
}
if (isset($params["district_id"])) {
$where_["c.id"] = $params["district_id"];
$where_["a.level"] = array( "in", "30,40" );
}
$result = Db::table($this->table)
->field($field)
->alias("a")
->join("a_store b", "a.store_id = b.id", "left")
->join("a_district c", "a.district_id = c.id", "left")
->where($where_)
->select();
//echo $this->getLastSql();
return $result;
}
/**
* @param $field
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAgentsInfoByShop($field, $params)
{
$where_["a.status"] = 0;
$result = Db::table($this->table)
->field($field)
->alias("a")
->join("a_store b", "a.store_id = b.id", "left")
->join("a_district c", "a.district_id = c.id", "left")
->where($params)
->select();
return $result;
}
/**
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getStoreOrDistrict($params)
{
$result = Db::table($this->table)
->field("id,name,img")
->where($params)
->select();
//echo Db::table($this->table)->getLastSql();
return $result;
}
/**
* @param $field
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function searchAgentsByKeyword($field, $params)
{
$params["status"] = array("in","0,3");
$result = Db::table($this->table)
->field($field)
->where($params)
->select();
return $result;
}
/**
* @param $field
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAgentsByKeyword($field, $params)
{
$result = Db::table($this->table)
->field($field)
->where($params)
->select();
return $result;
}
public function searchAgentsByKeywordPcInfo($field, $params,$page_size,$page_no)
{
$params["a.status"] = 0;
$result = Db::table($this->table)
->field($field)
->alias("a")
->join("a_store b", "a.store_id = b.id", "left")
->where($params)
->limit($page_size)
->page($page_no)
->select();
//echo $this->getLastSql();
return $result;
}
/**
* 检查是否有权限
*
* @param $id
* @param $agents_id
* @return array|false|\PDOStatement|string|\think\Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function agentsAuth($id, $agents_id)
{
return $this->alias('a')
->field('b.id')
->join('auth_group b', 'a.auth_group_id=b.id', 'left')
->where("FIND_IN_SET({$id},b.rules)")
->where('a.id', $agents_id)
->where('b.status', 0)
->find();
}
/**
* 根据id检查是否有权限
*
* @param $agents_id
* @param $rule
* @return mixed
*/
public function agentsAuthId($agents_id, $rule)
{
$rules = $this->alias('a')
->field('b.id')
->join('auth_group b', 'a.auth_group_id=b.id', 'left')
->where('b.status', 0)
->where('a.id', $agents_id)
->value('rules');
$rule_model = new AuthRule();
return $rule_model->where('id', 'in', $rules)
->where('name', $rule)
->value('id');
}
/**
* 根据id检查是否有权限
*
* @param $agents_id
* @param $rule
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function agentsAuthIds($agents_id, $rule)
{
$rules = $this->alias('a')
->field('b.id')
->join('auth_group b', 'a.auth_group_id=b.id', 'left')
->where('b.status', 0)
->where('a.id', $agents_id)
->value('rules');
$rule_model = new AuthRule();
$result = $rule_model
->field("id,name")
->where('id', 'in', $rules)
->where($rule)
->select();
return $result;
}
/**
* 根据id获取单个字段值
*
* @param $id
* @param $fields
* @return mixed
*/
public function getAgentsById($id, $fields)
{
return $this->where('id', $id)->value($fields);
}
/**
* @param $where
* @param $fields
* @return mixed
*/
public function getAgentsByWhere($where, $fields)
{
return $this->where($where)->value($fields);
}
/**
* @param $where
* @param $fields
* @return mixed
*/
public function getAgentsByWhereColumn($where, $fields)
{
return $this->where($where)->column($fields);
}
/**
* @param $where
* @param $fields
* @return array|false|\PDOStatement|string|\think\Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAgentsStoreById($where, $fields)
{
return $this->alias('a')
->field($fields)
->join('a_store b', 'a.store_id=b.id', 'left')
->where($where)
->find();
}
/**
* @param $field
* @param $params
* @param $is_store
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getStoreOrAgentInfo($field, $params,$is_store)
{
if($is_store == 2){
$result = Db::table($this->table)
->field($field)
->alias("a")
->join("a_store b", "a.store_id = b.id", "left")
->join("a_agents c", "a.store_id = c.store_id", "left")
->where($params)
->select();
}else{
$result = Db::table($this->table)
->field($field)
->alias("a")
->join("a_store b", "a.store_id = b.id", "left")
->where($params)
->select();
}
// echo $this->getLastSql();
return $result;
}
/**
* @param string $field
* @param string $agent_id
* @param string $params
* @return array|false|\PDOStatement|string|\think\Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAgentInfo($field = '', $agent_id = '', $params = '')
{
if ($agent_id != '') {
$where['id'] = $agent_id;
} else {
$where = $params;
}
$result = $this->field($field)
->where($where)
->find();
//echo $this->getLastSql();
return $result;
}
/**
* 验证用户是否存在
*
* @param $phone
* @return int|string
*/
public function getAgentExist($phone)
{
return $this->where([
'phone' => $phone,
'status' => 0
])->count();
}
/**
* 根据order_id获得独家和盘方
*
* @param $order_id
* @return array|false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAgentEelationByOrderId($order_id)
{
$order = new OrderModel();
$house_id = $order->where('id', $order_id)->value('house_id');
$data = [];
if (!empty($house_id)) {
$agent_device = $this->alias('a')
->field('a.id,a.device_id')
->join('g_houses_to_agents b', 'a.id = b.agents_id', 'left')
->where('houses_id', $house_id)
->where('type', 'in', '2,3')
->where('is_del', 0)
->select();
foreach ($agent_device as $k => $v) {
$data[$k] = $v->getData();
}
}
return $data;
}
/**
* 多个id获取经纪人信息
*
* @param array $agent_id
* @param string $field
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAgentAllById($agent_id = [], $field = '*')
{
return Db::table($this->table)->field($field)
->where('id', 'in', implode(',', $agent_id))
->where('status', 0)
->select();
}
/**
* 店长
*
* @param $agent_id
* @return array|false|\PDOStatement|string|\think\Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getStoreAgentId($agent_id)
{
$store_id = $this->where('id', $agent_id)->value('store_id');
return $this->alias('a')
->field('b.store_name,a.id,a.device_id')
->join('a_store b', 'a.store_id=b.id')
->where('b.id', $store_id)
->where('level', 'in', '20,30')
->find();
}
/**
* @param $agent_id
* @return mixed
*/
public function Agents_res($agent_id)
{
return db('a_agents')->alias('a')
->field('name,phone,img,store_name')
->join('a_store b', 'a.store_id=b.id', 'left')
->where('a.id', $agent_id)
->find();
}
/**
* 查询经纪人
*
* @param int $pageNo
* @param int $pageSize
* @param string $order_
* @param $field
* @param $params
* @param string $house_id
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getUser($pageNo = 1, $pageSize = 15, $order_ = 'id desc', $field, $params, $house_id = '')
{
return $this->field($field)->alias('a')
->join('u_evaluate b', 'a.id = b.agents_id', 'left')
->join('g_houses_to_agents c', 'a.id=c.agents_id', 'left')
->where('c.type', 1)
->where($params)
->group('a.id')
->order($order_)
->limit($pageSize)
->page($pageNo)
->select();
}
/**
* @param int $pageNo
* @param int $pageSize
* @param string $order_
* @param string $field
* @param string $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function searchAgentShop($pageNo = 1, $pageSize = 15, $order_ = 'id desc', $field = '', $params = '')
{
return $this->field($field)
->alias('a')
->join('a_store b', 'a.store_id = b.id', 'left')
->where($params)
->order($order_)
->limit($pageSize)
->page($pageNo)
->select();
}
/**
* @param $field
* @param $params
* @param $group
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAgentsList($field, $params, $group)
{
$where_ = [];
if ($group == "store_id") {
$where_['level'] = array( "in", [ 20, 40 ] );
}
$result = Db::name($this->table)
->field($field)
->where($params)
->where($where_)
->group($group)
->select();
return $result;
}
/**
* 获取用户的客方经纪人
*
* @param string $field
* @param array $params
* @param int $house_id
* @return array|false|\PDOStatement|string|\think\Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getUserAgent($field = '', $params = [], $house_id = 0)
{
$data = $this->field($field)->alias('a')
->join('u_evaluate b', 'a.id = b.agents_id', 'left')
->join('g_houses_to_agents c', 'a.id=c.agents_id', 'left')
->join('u_users d', 'a.id = d.agent_id', 'left')
->where('c.houses_id', $house_id)
->where('c.type', 1)
->where($params)
->find();
return $data;
}
/**
* 查找客方经纪人
*
* @param string $field
* @param array $params
* @return array|false|\PDOStatement|string|\think\Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAgentClient(string $field = '*', array $params = [])
{
return $this->field($field)->alias('a')
->join('u_evaluate b', 'a.id = b.agents_id', 'left')
->join('u_users c', 'a.id = c.agent_id', 'left')
->where($params)
->find();
}
/**
* 经纪人与部门和门店数据
*
* @param $field
* @param $where
* @return array|false|\PDOStatement|string|\think\Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getStoreDistrict($field, $where)
{
return $this->field($field)
->alias('a')
->join('a_store b', 'a.store_id = b.id', 'left')
->join('a_district c', 'a.district_id = c.id', 'left')
->where($where)
->find();
}
/**
* 经纪人详情
* @param $id
* @return array|bool|false|\PDOStatement|string|Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function agentsDetail($id)
{
if ($id) {
$result = $this->field('id,name as realname,create_time,img,store_id')->find($id);
$evaluate_grade = Db::table('u_evaluate')
->field('sum(evaluate_grade) as evaluate_grade, count(*) as evaluate_num')
->where('agents_id', $id)->where('is_show', 0)->find();
$m_store = new AStore();
$result['sub_shopname'] = $m_store->getStoreKeyById('store_name', [ 'id' => $result['store_id'] ]);
if ($evaluate_grade['evaluate_grade']) {
$grade = floor(($evaluate_grade['evaluate_grade'] / 2) / $evaluate_grade['evaluate_num']);
} else {
$grade = 0;
}
$result['evaluate_grade'] = $grade; //评分等级
$result['evaluate_num'] = $evaluate_grade['evaluate_num']; //评论数量
$result['watch_shop'] = Db::table('u_appoint_watch_shop')
->where('agents_id', $id)->count(); //看铺
$result['head_portrait'] = AGENTHEADERIMGURL . $result['img'];
$bargain = new OBargainModel();
$result['JournalAccounts'] = $bargain->ifBargainNumByOrderId([ 'agent_id' => $id ]); //成交记录
$current_time = time();
$user_time = strtotime($result['create_time']);
$year = date('Y', $current_time) - date('Y', $user_time);
//入职年限
if ($year == 0) {
$result['created'] = '4年以上';
} else {
$result['created'] = '5年以上';
}
$result['label'] = array( 0 => '待定标签数据', 1 => '待定标签数据' );
$data = $result;
} else {
$data = false;
}
return $data;
}
/**
* 更新数据
*
* @param $id
* @param $data
* @return AAgents|bool
*/
public function updateData($id, $data)
{
if ($id) {
$result = $this->where('id', $id)->update($data);
} else {
$result = false;
}
return $result;
}
/**
* 获取经纪人数量
*
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAgentsCountByStoreId($params)
{
$result = Db::table($this->table)
->field("id,name")
->where($params)
->count();
//echo Db::table($this->table)->getLastSql();
//dump($this->getLastSql());
return $result;
}
/**
* @param $field
* @param $params
* @return string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAgentsIdsArray($field, $params)
{
$params["status"] = 0;
$result = Db::table($this->table)
->field($field)
->where($params)
->select();
if($result){
$agentIds = "";
foreach ($result as $key1 => $value1) {
$agentIds .= $value1["id"] . ',';
}
$agentIds = rtrim($agentIds, ",");//经纪人ID集合
}
return $agentIds;
}
/**
* @param $field
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAgentsInfo($field, $params)
{
//$params["a.status"] = 0;
$result = Db::table($this->table)
->alias('a')
->join('a_store b', 'b.id=a.store_id', 'left' )
->field($field)
->where($params)
->select();
return $result;
}
/**
* @param $field
* @param $where
* @return array|false|\PDOStatement|string|\think\Model
*/
public function agentBargainDetail($field, $where) {
try {
$data = $this->alias('a')
->field($field)
->join('o_bargain b', 'a.id = b.agent_id', 'left')
->where($where)
->find();
} catch (\Exception $e) {
$data = [];
}
return $data;
}
/**
* @param $field
* @param $where
* @return array|false|\PDOStatement|string|\think\Model
*/
public function agentBargainAll($field, $where) {
try {
$data = $this->alias('a')
->field($field)
->join('o_bargain b', 'a.id = b.agent_id', 'left')
->where($where)
->select();
} catch (\Exception $e) {
$data = [];
}
return $data;
}
/**
* 获取绑定号码
*
* @param $field
* @param $where
* @return mixed
*/
public function getAgentCallPhone($field, $where) {
try {
$result['data'] = $this->alias('a')
->field($field)
->join('aliYun_binding_phone b', 'a.phone = b.phone_a', 'left')
->join('aliYun_phone c', 'b.aliYun_phone_id = c.id', 'left')
->where($where)
->select();
$result['status'] = 'successful';
} catch (\Exception $e) {
$result['data'] = [];
$result['status'] = 'fail';
$result['msg'] = $e->getMessage();
}
return $result;
}
/**
* 根据门店id查店长ID
* @param $params
* @return false|\PDOStatement|string|\think\Collection
*/
public function getAgentsManagerID($params)
{
$result = Db::table($this->table)
->field("id")
->where($params)
->limit(1)
->select();
//echo Db::table($this->table)->getLastSql();
//dump($this->getLastSql());
return $result;
}
/**
* 客户来电数
* @param $field
* @param $params
* @return false|\PDOStatement|string|\think\Collection
*/
public function getUserPhoneNum($field ,$params)
{
$result = Db::table($this->table)
->field($field)
->where($params)
->group('district_id')
->select();
//echo $this->getLastSql();
return $result;
}
/**
* @param $params
* @return int|string
*/
public function saveAgent($params) {
$save_data = [];
//设备id
if (!empty($params['device_id'])) {
$save_data['device_id'] = $params['device_id'];
}
//门店id
if (!empty($params['store_id'])) {
$save_data['store_id'] = $params['store_id'];
}
//角色id
if (!empty($params['auth_group_id'])) {
$save_data['auth_group_id'] = $params['auth_group_id'];
}
//部门id
if (!empty($params['district_id'])) {
$save_data['district_id'] = $params['district_id'];
}
//等级 10业务员 20店长 30总监 40店长和总监
if (!empty($params['level'])) {
$save_data['level'] = $params['level'];
}
//业务员姓名
if (!empty($params['name'])) {
$save_data['name'] = $params['name'];
}
//业务员手机号
if (!empty($params['phone'])) {
$save_data['phone'] = $params['phone'];
}
//密码
if (!empty($params['password'])) {
$save_data['password'] = md5($params['password']); //默认号码后6位
}
//密码
if (!empty($params['password_md5'])) {
$save_data['password'] = $params['password_md5']; //不需要加密
}
//性别 0保密 1男 2女
if (isset($params['sex'])) {
$save_data['sex'] = $params['sex'];
}
//头像
if (!empty($params['img'])) {
$save_data['img'] = $params['img'];
}
//账号状态,0正常 1冻结 2离职 3转勤
if (isset($params['status'])) {
$save_data['status'] = $params['status'];
}
//邀请人id
if (!empty($params['inviter_id'])) {
$save_data['inviter_id'] = $params['inviter_id'];
}
//0可以访问后台,1不可以
if (!empty($params['admin_off'])) {
$save_data['admin_off'] = $params['admin_off'];
}
//备注
if (!empty($params['remarks'])) {
$save_data['remarks'] = $params['remarks'];
}
//ip存入数字 php ip2long和long2ip转换
if (!empty($params['last_login_ip'])) {
$save_data['last_login_ip'] = $params['last_login_ip'];
}
//最后登录时间
if (!empty($params['last_login_time'])) {
$save_data['last_login_time'] = $params['last_login_time'];
}
//离职日期
if (!empty($params['quit_time'])) {
$save_data['quit_time'] = $params['quit_time'];
}
//所属站点
if (!empty($params['site_id'])) {
$save_data['site_id'] = $params['site_id'];
}
//职称 1店长 2经理 3主任 4顾问 0新人
if (!empty($params['position'])) {
$save_data['position'] = $params['position'];
}
if (empty($params['id'])) {
$save_data['position'] = 5;
$save_data['create_time'] = date('Y-m-d H:i:s', time());
$save_data['auth_group_id'] = 5;
$id = $this->insertGetId($save_data);
} else {
$save_data['update_time'] = date('Y-m-d H:i:s', time());
$num = $this->where('id', $params['id'])->update($save_data);
$id = $num > 0 ? $params['id']:0;
}
return $id;
}
/**
* @param $where
* @param $fields
* @return array|false|\PDOStatement|string|\think\Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAgentsSite($where, $fields)
{
return $this->alias('a')
->field($fields)
->join('a_site b', 'a.site_id=b.id', 'left')
->where($where)
->find();
}
/**
* @param $where
* @param $fields
* @return array|false|\PDOStatement|string|\think\Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAgentSiteList($where, $fields)
{
return $this->field($fields)
->alias('a')
->join('a_site b', 'a.site_id=b.id', 'left')
->where($where)
->group('a.site_id')
->select();
}
/**
* 消息页面--通讯录
* @param $field
* @param $params
* @param $page_size
* @param $page_no
* @return false|\PDOStatement|string|\think\Collection
*/
public function getPhoneBookList($field, $params,$page_size,$page_no)
{
$params["Agents.status"] = 0;
$result = $this
->field($field)
->alias("Agents")
->where($params)
->limit($page_size)
->page($page_no)
->select();
//echo $this->getLastSql();
return $result;
}
/**
* 消息页面--通讯录
* @param $params
* @return int|string
*/
public function getPhoneBookListTotal($params)
{
$params["Agents.status"] = 0;
$result = $this->alias("Agents")->where($params)->count();
//echo $this->getLastSql();
return $result;
}
}
\ No newline at end of file
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