Base.php
1.2 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
45
46
47
48
<?php
namespace addons\groupon\controller\store;
use addons\groupon\exception\Exception;
use addons\groupon\controller\Base as AddonsBase;
use addons\groupon\model\Store;
use addons\groupon\model\User;
use addons\groupon\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) {
$this->error('请选择自提点');
}
$userStore = UserStore::with('store')->where('user_id', $user->id)->where('store_id', $store_id)->find();
if (!$userStore || !$userStore->store) {
$this->error('权限不足');
}
$store = $userStore->store->toArray();
if (!$store['status']) {
$this->error('自提点已被禁用');
}
// 存 session 本次请求有效
session('current_oper_store', $store);
}
}