Commit dcdc6ee9 authored by hujun's avatar hujun

门店列表和搜索

parent ecccbecf
...@@ -17,15 +17,49 @@ class Store extends Basic ...@@ -17,15 +17,49 @@ class Store extends Basic
protected $data; protected $data;
protected $code = 200; protected $code = 200;
protected $msg = ''; protected $msg = '';
/** /**
* @return \think\response\View * 门店列表
*
* @return string|\think\response\View
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/ */
public function index() { public function index() {
$result['code'] = 200;
$result['msg'] = '';
if ($this->request->isAjax()) { if ($this->request->isAjax()) {
$pageNo = empty($this->params['pageNo']) ? 1 : $this->params['pageNo'];
$pageSize = empty($this->params['pageSize']) ? 10 : $this->params['pageSize'];
$field = 'a.id,a.district_id,a.store_name,a.create_time';
$where['a.status'] = 0;
//门店名
if (!empty($this->params['store_name'])) {
$where['store_name'] = ['LIKE',$this->params['store_name'].'%'];
}
if (!empty($this->params['city'])) {
$where['city'] = $this->params['city'];
}
if (!empty($this->params['district'])) {
$where['district'] = $this->params['district'];
}
//店长姓名
if (!empty($this->params['agents_name'])) {
$where['b.name'] = ['LIKE',$this->params['agents_name'].'%'];
$join = 1;//连表查询店长名
}
//店长手机号
if (!empty($this->params['agents_phone'])) {
$where['b.phone'] = ['LIKE',$this->params['agents_phone'].'%'];
$join = 1;
}
$store = new AStore();
$this->data = $this->data = $store->getStoreList($pageNo, $pageSize, 'id DESC', $field, $where, $join);
$return = $this->response($this->code, $this->msg, $this->data);
} else { } else {
//总监列表 //总监列表
$return = view('index'); $return = view('index');
...@@ -37,10 +71,8 @@ class Store extends Basic ...@@ -37,10 +71,8 @@ class Store extends Basic
* 添加门店 * 添加门店
* *
* @return \think\Response * @return \think\Response
* @throws \think\db\exception\DataNotFoundException * @throws \Exception
* @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\PDOException3
* @throws \think\exception\DbException
* @throws \think\exception\PDOException
*/ */
public function addStore() { public function addStore() {
$district = new AStore(); $district = new AStore();
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
namespace app\model; namespace app\model;
use think\Db;
class AStore extends BaseModel class AStore extends BaseModel
{ {
/** /**
...@@ -79,4 +81,53 @@ class AStore extends BaseModel ...@@ -79,4 +81,53 @@ class AStore extends BaseModel
$data['agents_name'] = $agents_name['name'].'-'.$agents_name['phone']; $data['agents_name'] = $agents_name['name'].'-'.$agents_name['phone'];
return $data; 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 getStoreList($pageNo = 1, $pageSize = 15, $order_ = 'id desc', $field = '', $params = '', $join = 0){
$data = array();
if ($join) {
$field .= ',b.name,b.phone';
$where['b.status'] = 0;
$where['b.level'] = 20;
$store_data = $this->field($field)->alias('a')->join('a_agents b','a.id=b.store_id','left')
->where($params)
->order($order_)
->limit($pageSize)
->page($pageNo)
->select();
foreach ($store_data as $k=>$v) {
$data[$k] = $v;
$data[$k]['district_name'] = Db::table('a_district')->where('id',$v['district_id'])->value('district_name');
$data[$k]['agents_name'] = $v['name'].'-'.$v['phone'];
$data[$k]['agents_total'] = Db::table('a_agents')->where(['status'=>0,'store_id'=>$v['id']])->count();
}
} else {
$store_data = $this->field($field)->alias('a')
->where($params)
->order($order_)
->limit($pageSize)
->page($pageNo)
->select();
foreach ($store_data as $k=>$v) {
$data[$k] = $v;
$data[$k]['district_name'] = Db::table('a_district')->where('id',$v->district_id)->value('district_name');
$data[$k]['agents_name'] = Db::table('a_agents')->field('concat_ws("-",name,phone) as name')->where(['status'=>0,'level'=>20,'store_id'=>$v->id])->find();
$data[$k]['agents_name'] = $data[$k]['agents_name']['name']? $data[$k]['agents_name']['name'] : "";
$data[$k]['agents_total'] = Db::table('a_agents')->where(['status'=>0,'store_id'=>$v->id])->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