Commit e4e0f932 authored by zhuwei's avatar zhuwei

办公室门店列表

parent 4c07227a
......@@ -9,6 +9,7 @@ namespace app\index\controller;
use app\index\extend\Basic;
use app\model\AAgents;
use app\model\AStore;
use app\model\FOffice;
use think\Request;
......@@ -44,7 +45,7 @@ class StoreFee extends Basic
return $this->response("101", $checkResult);
}
$office = $this->getOffice('',$params['office_name']);
$office = $this->getOffice('id',['office_name'=>$params['office_name']]);
if ($office) {
return $this->response("101", '已存在该办公室!');
}
......@@ -86,7 +87,7 @@ class StoreFee extends Basic
return $this->response("101", $checkResult);
}
$office = $this->getOffice($params['id'],$name='');
$office = $this->getOffice('id',['id'=>$params['id']]);
if (!$office) {
return $this->response("101", '不存在该办公室!');
}
......@@ -163,25 +164,79 @@ class StoreFee extends Basic
/**
* 根据ID或者办公室名字查询是否存在
* @param $id
* @param $name
* @param $field
* @param $conditions
* @return array|false|\PDOStatement|string|\think\Model
*/
public function getOffice($id='',$name='')
public function getOffice($field,$conditions)
{
$conditions = [];
if ($id) {
$conditions['id'] = $id;
}
if ($name) {
$conditions['office_name'] = $name;
}
$field = 'id';
$result = $this->f_office->findByOne($field, $conditions);
return $result;
}
/*
* 办公室门店列表
*/
public function getStoreList()
{
$params = $this->params;
$params = array(
"id" => '1',//id
);
$checkResult = $this->validate($params, "StoreFeeValidate.getOfficeInfo");
if (true !== $checkResult) {
return $this->response("101", $checkResult);
}
$office = $this->getOffice('id',['id'=>$params['id']]);
if (!$office) {
return $this->response("101", '不存在该办公室!');
}
$m_store = new AStore();
$store_params['office_id'] = $params['id'];
$store_field = 'id,store_name';
$store_result = $m_store->getStore($store_params, $store_field);
if (!$store_result) {
return $this->response("200", "成功", []);
}
foreach ($store_result as $k => $v) {
$people_num_list = $this->getPeopleListAndNum($v['id']);
$store_result[$k]['people_num'] = $people_num_list['people_num'];
$store_result[$k]['people_list'] = $people_num_list['people_list'];
}
$data['list'] = $store_result;
return $this->response("200", "成功", $data);
}
/**
* 查门店人数和名单
* @param $store_id
* @return mixed
*/
public function getPeopleListAndNum($store_id)
{
$params = [];
$params["store_id"] = $store_id;
$params["status"] = 0;
$m_agent = new AAgents();
$m_agent_res = $m_agent->getAgentsByStoreId($params);
$people_num = count($m_agent_res);
$people_list = "";
if ($people_num > 0) {
foreach ($m_agent_res as $k => $v) {
$people_list .= $v["name"] . ",";
}
$people_list = rtrim($people_list, ",");
}
$return['people_list'] = $people_list;
$return['people_num'] = $people_num;
return $return;
}
}
\ No newline at end of file
......@@ -522,6 +522,7 @@ Route::group('index', [
'getOfficeList' => [ 'index/StoreFee/getOfficeList', [ 'method' => 'POST|GET' ] ],
'getOfficeInfo' => [ 'index/StoreFee/getOfficeInfo', [ 'method' => 'POST|GET' ] ],
'editOffice' => [ 'index/StoreFee/editOffice', [ 'method' => 'POST|GET' ] ],
'getStoreList' => [ 'index/StoreFee/getStoreList', [ 'method' => 'POST|GET' ] ],
]);
......
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