Commit 1ba0db05 authored by hujun's avatar hujun

站点返回值

parent a3a7204b
......@@ -9,6 +9,7 @@
namespace app\index\controller;
use app\index\extend\Basic;
use app\index\service\BrokerService;
use app\model\AuthGroup;
use app\model\AuthGroupSetting;
use app\model\AuthGroupSite;
......@@ -458,7 +459,10 @@ class Auth extends Basic
* @return \think\Response
*/
public function setSite() {
$m_auth = new AuthGroupSite();
$aa = new BrokerService();
var_dump($aa->checkSite(1,1));die;
$m_auth = new AuthGroupSite();
$msg = '';
$code = 200;
$list = [];
......
......@@ -16,6 +16,7 @@ use app\model\AAgents;
use app\model\ABindingDevice;
use app\model\ADistrict;
use app\model\AOperatingRecords;
use app\model\ASite;
use app\model\AuthGroupSite;
use app\model\GHousesToAgents;
use app\model\OMarchInModel;
......@@ -265,11 +266,11 @@ class BrokerService
* 检查角色是否属于某个站点
*
* @param $agent_id
* @param $site_id
* @return bool
*/
public function checkSite($agent_id, $site_id) {
$m_site = new AuthGroupSite();
public function checkSite($agent_id) {
$m_group_site = new AuthGroupSite();
$m_site = new ASite();
if (empty($agent_id)) {
return false;
}
......@@ -277,12 +278,20 @@ class BrokerService
if ($auth_group_id) {
$where['group_id'] = $auth_group_id;
$where['status'] = 0;
$where[] = ['EXP', 'find_in_set('.$site_id.', site_id)'];
$id = $m_site->getSite('id', $where);
if (count($id['data']) > 0) {
$result = true;
} else {
$site_id = $m_group_site->getGroupSite('site_id', $where);
$city = $m_site->getSiteByIdColumn($site_id['data']['site_id'], 'city');
if (empty($city)) {
$result = false;
} else {
$num = $m_site->getTotal(['is_del'=>0]);
if (count($city) == $num) {
$result['city'] = 'all';
$result['site_id'] = 'all';
} else {
$result['city'] = implode(',', $city);
$result['site_id'] = $site_id['data']['site_id'];
}
}
} else {
$result = false;
......
......@@ -75,4 +75,17 @@ class ASite extends BaseModel
return $return;
}
/**
* 根据id获取单个字段值
*
* @param $id
* @param $fields
* @return mixed
*/
public function getSiteByIdColumn($id, $fields)
{
$return = $this->where('id', 'in',$id)->column($fields);
return $return;
}
}
......@@ -51,21 +51,22 @@ class AuthGroupSite extends BaseModel
}
/**
* @param $field
* @param $site_id
* @param $where
* @return mixed
*/
public function getSite($field, $where) {
public function getGroupSite($site_id, $where) {
$data['data'] = [];
try {
$data['data'] = $this->field($field)
$data['data'] = $this->db_->field($site_id)
->where($where)
->select();
->find();
$data['status'] = 'successful';
} catch(\Exception $e) {
} catch (\Exception $e) {
$data['status'] = 'fail';
$data['msg'] = $e->getMessage();
}
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