Commit b2e0da38 authored by hujun's avatar hujun

门店列表

parent 18157b7d
...@@ -12,6 +12,7 @@ namespace app\index\controller; ...@@ -12,6 +12,7 @@ namespace app\index\controller;
use app\api_broker\service\RedisCacheService; use app\api_broker\service\RedisCacheService;
use app\index\extend\Basic; use app\index\extend\Basic;
use app\index\validate\StoreValidate; use app\index\validate\StoreValidate;
use app\model\AAgents;
use app\model\ADistrict; use app\model\ADistrict;
use app\model\AStore; use app\model\AStore;
...@@ -24,18 +25,22 @@ class Store extends Basic ...@@ -24,18 +25,22 @@ class Store extends Basic
/** /**
* 门店列表 * 门店列表
* *
* @return string|\think\response\View * @return \think\Response|\think\response\View
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
*/ */
public function index() { public function index()
if ($this->request->isAjax()) { {
if (!$this->request->isAjax()) {
return view('index');
}
$pageNo = empty($this->params['pageNo']) ? 1 : $this->params['pageNo']; $pageNo = empty($this->params['pageNo']) ? 1 : $this->params['pageNo'];
$pageSize = empty($this->params['pageSize']) ? 10 : $this->params['pageSize']; $pageSize = empty($this->params['pageSize']) ? 10 : $this->params['pageSize'];
$field = 'a.id,a.district_id,a.store_name,a.create_time'; $field = 'a.id,a.district_id,a.store_name,a.create_time';
$where['a.status'] = 0; $where['a.status'] = 0;
$join = 0; $where['b.level'] = ['in', '20,40'];
//门店名 //门店名
if (!empty($this->params['store_id'])) { if (!empty($this->params['store_id'])) {
$where['a.id'] = $this->params['store_id']; $where['a.id'] = $this->params['store_id'];
...@@ -51,24 +56,35 @@ class Store extends Basic ...@@ -51,24 +56,35 @@ class Store extends Basic
//店长姓名 //店长姓名
if (!empty($this->params['agents_name'])) { if (!empty($this->params['agents_name'])) {
$where['b.name'] = ['LIKE','%'.$this->params['agents_name'].'%']; $where['b.name'] = ['LIKE', '%' . $this->params['agents_name'] . '%'];
$join = 1;//连表查询店长名
} }
//店长手机号 //店长手机号
if (!empty($this->params['agents_phone'])) { if (!empty($this->params['agents_phone'])) {
$where['b.phone'] = ['LIKE',$this->params['agents_phone'].'%']; $where['b.phone'] = ['LIKE', $this->params['agents_phone'] . '%'];
$join = 1;
} }
$store = new AStore(); $store = new AStore();
$this->data['list'] = $store->getStoreList($pageNo, $pageSize, 'id DESC', $field, $where, $join); $m_agent = new AAgents();
$this->data['total'] = $store->getStoreListTotal($where, $join); $m_district = new ADistrict();
$return = $this->response($this->code, $this->msg, $this->data); $list = $store->getStoreAgentList($pageNo, $pageSize, 'id DESC', $field, $where);
} else { $this->data['total'] = $store->getStoreAgentListTotal($where);
//总监列表
$return = view('index'); $agent_where['level'] = 20;
} $status_arr = [0 => '正常', 1 => '长假', 2 => '离职', 3 => '转勤', 4 => '黑名单', 5 => '冻结'];
return $return; $district_data = $m_district->getDistrictColumn('id,district_name', ['status' => 0]);
foreach ($list as $k => $v) {
$list[$k]['district_name'] = $district_data[$v['district_id']];
$list[$k]['agents_total'] = $m_agent->getListDistrictTotal(['store_id' => $v['id'], 'level' => 10]);
$agent_where['store_id'] = $v['id'];
$agent_data = $m_agent->getStoreIdByAgentId('name,phone,status', $agent_where);
$agent_name = '';
foreach ($agent_data as $k2 => $v2) {
$agent_name .= $v2['name'] . '-' . $v2['phone'] . '(' . $status_arr[$v2['status']] . '),';
}
$list[$k]['agents_name'] = rtrim($agent_name, ',');
}
$this->data['list'] = $list;
return $this->response($this->code, $this->msg, $this->data);
} }
/** /**
......
...@@ -216,4 +216,14 @@ class ADistrict extends BaseModel ...@@ -216,4 +216,14 @@ class ADistrict extends BaseModel
return $result; return $result;
} }
/**
* @param $field
* @param $where
* @return array
*/
public function getDistrictColumn($field, $where)
{
return $this->where($where)
->column($field);
}
} }
\ No newline at end of file
...@@ -176,6 +176,42 @@ class AStore extends BaseModel ...@@ -176,6 +176,42 @@ class AStore extends BaseModel
return $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 getStoreAgentList($pageNo = 1, $pageSize = 15, $order_ = 'id desc', $field = '', $params = '')
{
return $this->field($field)->alias('a')
->join('a_agents b', 'a.id = b.store_id', 'left')
->where($params)
->order($order_)
->limit($pageSize)
->page($pageNo)
->select();
}
/**
* @param string $params
* @return int|string
*/
public function getStoreAgentListTotal($params = '')
{
return $this->alias('a')
->join('a_agents b', 'a.id = b.store_id', 'left')
->where($params)
->count('a.id');
}
/** /**
* 门店列表总数 * 门店列表总数
* *
......
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