Commit b2e0da38 authored by hujun's avatar hujun

门店列表

parent 18157b7d
......@@ -12,6 +12,7 @@ namespace app\index\controller;
use app\api_broker\service\RedisCacheService;
use app\index\extend\Basic;
use app\index\validate\StoreValidate;
use app\model\AAgents;
use app\model\ADistrict;
use app\model\AStore;
......@@ -24,51 +25,66 @@ class Store extends Basic
/**
* 门店列表
*
* @return string|\think\response\View
* @return \think\Response|\think\response\View
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function index() {
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;
$join = 0;
//门店名
if (!empty($this->params['store_id'])) {
$where['a.id'] = $this->params['store_id'];
}
public function index()
{
if (!$this->request->isAjax()) {
return view('index');
}
if (!empty($this->params['city'])) {
$where['a.city'] = $this->params['city'];
}
$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;
$where['b.level'] = ['in', '20,40'];
//门店名
if (!empty($this->params['store_id'])) {
$where['a.id'] = $this->params['store_id'];
}
if (!empty($this->params['district_id'])) {
$where['a.district_id'] = $this->params['district_id'];
}
if (!empty($this->params['city'])) {
$where['a.city'] = $this->params['city'];
}
//店长姓名
if (!empty($this->params['agents_name'])) {
$where['b.name'] = ['LIKE','%'.$this->params['agents_name'].'%'];
$join = 1;//连表查询店长名
}
if (!empty($this->params['district_id'])) {
$where['a.district_id'] = $this->params['district_id'];
}
//店长手机号
if (!empty($this->params['agents_phone'])) {
$where['b.phone'] = ['LIKE',$this->params['agents_phone'].'%'];
$join = 1;
//店长姓名
if (!empty($this->params['agents_name'])) {
$where['b.name'] = ['LIKE', '%' . $this->params['agents_name'] . '%'];
}
//店长手机号
if (!empty($this->params['agents_phone'])) {
$where['b.phone'] = ['LIKE', $this->params['agents_phone'] . '%'];
}
$store = new AStore();
$m_agent = new AAgents();
$m_district = new ADistrict();
$list = $store->getStoreAgentList($pageNo, $pageSize, 'id DESC', $field, $where);
$this->data['total'] = $store->getStoreAgentListTotal($where);
$agent_where['level'] = 20;
$status_arr = [0 => '正常', 1 => '长假', 2 => '离职', 3 => '转勤', 4 => '黑名单', 5 => '冻结'];
$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']] . '),';
}
$store = new AStore();
$this->data['list'] = $store->getStoreList($pageNo, $pageSize, 'id DESC', $field, $where, $join);
$this->data['total'] = $store->getStoreListTotal($where, $join);
$return = $this->response($this->code, $this->msg, $this->data);
} else {
//总监列表
$return = view('index');
$list[$k]['agents_name'] = rtrim($agent_name, ',');
}
return $return;
$this->data['list'] = $list;
return $this->response($this->code, $this->msg, $this->data);
}
/**
......
......@@ -216,4 +216,14 @@ class ADistrict extends BaseModel
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
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