Commit ca6ddbbf authored by hujun's avatar hujun

部门列表搜索

parent c99efa29
......@@ -9,7 +9,6 @@
namespace app\index\controller;
use app\index\extend\Basic;
use app\model\AAgents;
use app\model\ADistrict;
class District extends Basic
{
......@@ -31,18 +30,28 @@ class District extends Basic
$data['msg'] = '';
$pageNo = empty($this->params['pageNo']) ? 1 : $this->params['pageNo'];
$pageSize = empty($this->params['pageSize']) ? 10 : $this->params['pageSize'];
$search = $this->params['search'];
$agents = new AAgents();
$field = 'district_id,id,name,create_time,phone';
$where = '';
$where .= 'level in (30,40) AND status=0';
$agents = new ADistrict();
if ($search != NULL) {
$where .= " AND (phone like '{$search}%' or name like '{$search}%')";
$where = '';
$join = 0;
if ($this->params['search'] != NULL) {
$field = 'a.id,a.district_name,a.create_time,b.name,b.phone';
$where .= "a.status=0 AND (phone like '{$this->params['search']}%' or name like '{$this->params['search']}%')";
$join = 1;
}
$data['list'] = $agents->getListDistrict($pageNo, $pageSize, 'id DESC', $field, $where);
$data['total'] = $agents->getListDistrictTotal($where);
if ($this->params['district_name'] != NULL) {
if ($join == 0) {
$field = 'a.id,a.district_name,a.create_time';
$where['status'] =0;
$where['district_name'] = ['LIKE', $this->params['district_name'].'%'];
} else {
$where .= " AND district_name LIKE '{$this->params['district_name']}%'";
}
}
$data['list'] = $agents->getListDistrict($pageNo, $pageSize, 'id DESC', $field, $where,$join);
$data['total'] = $agents->getListDistrictTotal($where,$join);
return $this->response($data['status'], $data['msg'], $data);
}
......
......@@ -94,4 +94,88 @@ class ADistrict extends BaseModel
return $data;
}
/**
* 部门列表
*
* @param int $pageNo
* @param int $pageSize
* @param string $order_
* @param string $field
* @param string $params
* @return array
* @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 = '', $join = 0) {
if ($join == 0) {
$data = $this->field($field)->alias('a')
->where($params)
->order($order_)
->limit($pageSize)
->page($pageNo)
->select();
$result = array();
foreach ($data as $k=>$v){
$result[$k] = $v;
if (isset($v->id)) {
if ($result[$k]['district_name']) {
$agents = Db::table('a_agents')->field('name,phone')->where([
'status'=>0,'district_id'=>$v->id
])->find();
$result[$k]['name'] = $agents['name'].'-'.$agents['phone'];
$result[$k]['store_num'] = Db::table('a_store')->where([
'status'=>0,'district_id'=>$v->id
])->count('store_name');
} else {
$result[$k]['store_num'] = '';
}
}
}
} else {
$data = $this->field($field)->alias('a')
->join('a_agents b','a.id=b.district_id','left')
->where($params)
->order($order_)
->limit($pageSize)
->page($pageNo)
->select();
$result = array();
foreach ($data as $k=>$v){
$result[$k] = $v;
if (isset($v->id)) {
if ($result[$k]['district_name']) {
$result[$k]['name'] = $v['name'].'-'.$v['phone'];
$result[$k]['store_num'] = Db::table('a_store')->where([
'status'=>0,'district_id'=>$v->id
])->count('store_name');
} else {
$result[$k]['store_num'] = '';
}
}
}
}
return $result;
}
/**
* 总监列表总数
*
* @param $params
* @param int $join
* @return int|string
*/
public function getListDistrictTotal($params, $join=0){
if ($join == 0) {
$data = $this->where($params)->count();
} else {
$data = $this->alias('a')
->join('a_agents b','a.id=b.district_id','left')
->where($params)->count();
}
return $data;
}
}
\ 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