Base.php
1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
namespace addons\shopro\controller\store;
use addons\shopro\exception\Exception;
use addons\shopro\controller\Base as AddonsBase;
use addons\shopro\model\Store;
use addons\shopro\model\User;
use addons\shopro\model\UserStore;
class Base extends AddonsBase
{
public function _initialize()
{
parent::_initialize();
// 验证登录用户是否可以访问门店接口
$this->checkUserStore();
}
/**
* 检测用户管理的是否有门店
*/
private function checkUserStore() {
// 获取当前用户的门店
$user = User::info();
$store_id = $this->request->param('store_id');
if (!$store_id) {
throw new Exception('请选择门店');
}
$userStore = UserStore::with('store')->where('user_id', $user->id)->where('store_id', $store_id)->find();
if (!$userStore || !$userStore->store) {
throw new Exception('权限不足');
}
$store = $userStore->store->toArray();
// 存 session 本次请求有效
session('current_oper_store', $store);
}
}