Action.php
9.62 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
<?php
class QLib_Action extends Q_Action
{
private $_appConfig = array();
private $_sessionNamespace = array();
protected $domain = '';
protected $staticDomain = '';
public function init()
{
$this->_appConfig = $this->_config();
$this->domain = $this->_appConfig['website']['domain'];
$this->staticDomain = $this->_appConfig['website']['static']['url'];
}
/**
* @param $template
* @return QLib_Paging
*/
public function _paging($template = 'paging')
{
$paging = new QLib_Paging($template);
return $paging;
}
public function _assign($name, $value)
{
return $this->getView()->assign($name, $value);
}
/**
* 获取初始化注册的config
* @param string $name
* @return mixed
*/
public function _config($name = 'config')
{
return Yaf_Registry::get($name);
}
/**
* 获取JS URL
*
* @param String $jsName
* @return String
*/
public function _js($jsName, $local = false)
{
if (isset(QLibConfigs_Static::$_js[$jsName])) {
$js = $this->_appConfig['website']['static']['url'];
if ($local == false) {
$js .= QLibConfigs_Static::$_js[$jsName];
} else {
$js = QLibConfigs_Static::$_js[$jsName];
}
return $js;
}
return '';
}
/**
* 获取Css URL
*
* @param String $cssName
* @return String
*/
public function _css($cssName, $local = false)
{
if (isset(QLibConfigs_Static::$_css[$cssName])) {
$css = $this->_appConfig['website']['static']['url'];
if ($local == false) {
$css .= QLibConfigs_Static::$_css[$cssName];
} else {
$css = QLibConfigs_Static::$_css[$cssName];
}
return $css;
}
return '';
}
/**
* TODO
* @param string $layout
* @param string $layoutPath
*/
public function _setLayout($layout = 'default', $layoutPath = '')
{
if (!empty($layoutPath)) {
$this->_config = Yaf_Application::app()->getConfig();
$this->setLayoutPath();
}
$this->getView()->setLayout($layout);
}
/**
* 获取参数
* @param null $name
* @param null $default
* @return mixed
*/
protected function _getEnv($name = null, $default = null)
{
return $this->getRequest()->getEnv($name, $default);
}
/**
* 封装一下获取param参数
* @param String $key
* @param mixed $default
* @return mixed
*/
protected function _getParam($key, $default = null)
{
return $this->getRequest()->getParam($key, $default);
}
/**
* 获取所有参数
* @return array
*/
protected function _getParams()
{
return $this->_request->getParams();
}
/**
* 获取所有参数
* @return mixed
*/
protected function _getRequests()
{
return $this->_request->getRequest();
}
protected function _p()
{
return $_POST;
}
protected function _g()
{
return $_GET;
}
protected function requestParams()
{
return $_POST + $_GET;
}
/**
* 封装一下获取get参数
* @param String $key
* @param mixed $default
* @return mixed
*/
protected function _get($key, $default = null)
{
return $this->getRequest()->getQuery($key, $default);
}
/**
*
* @param unknown $key
* @param string $default
*/
protected function _param($key, $default = null)
{
$reqObj = $this->getRequest();
if ($reqObj->isGet()) {
return $reqObj->getQuery($key, $default);
} else {
return $reqObj->getPost($key, $default);
}
}
/**
* 封装一下获取post参数
* @param String $key
* @param mixed $default
* @return mixed
*/
protected function _post($key, $default = null)
{
return $this->getRequest()->getPost($key, $default);
}
/**
* 封装一下获取post参数
* @param String $key
* @param mixed $default
* @return mixed
*/
protected function _typePost($key, $settype = null, $default = null)
{
$result = $this->getRequest()->getPost($key, $default);
switch ($settype) {
case 'bool':
$result = (bool)$result;
break;
case 'int':
$result = (int)$result;
break;
case 'string':
$result = (string)$result;
break;
case 'float':
$result = (float)$result;
break;
case 'binary':
$result = (binary)$result;
break;
default:
$result = $result;
break;
}
return $result;
}
/**
* 关闭模板 & Layout
*/
public function _disable()
{
$this->disableLayout();
$this->disableView();
}
/**
* 关闭模板
*/
public function disableView()
{
Yaf_Dispatcher::getInstance()->autoRender(FALSE);
}
/**
* 关闭Layout
*/
public function disableLayout()
{
$this->getView()->setLayout('');
}
/**
* 使用session
* @param $namespace
* @return Q_Core_SessionNamespace
*/
public function _sessionNamespace($namespace)
{
$this->sessionStart();
if (empty($this->_sessionNamespace[$namespace])) {
$this->_sessionNamespace[$namespace] = new Q_Core_SessionNamespace ($namespace);
}
return $this->_sessionNamespace[$namespace];
}
/**
* 需要验证请调用该函数
* @param string $refer
* @return int
*/
public function _auth($refer = 'auto')
{
$this->sessionStart();
if (($this->uid = $this->getProfileSession('pid')) < 1) {
$referUrl = $refer == 'auto' ? $_SERVER['REQUEST_URI'] : $refer;
$redirectUrl = '/?refer=' . rawurlencode($referUrl);
header('Location: ' . $redirectUrl);
}
return $this->uid;
}
public function getProfileSession($keyName = null)
{
$profileSession = $this->_sessionNamespace('adminx_profile')->__get(QLibConfigs_GlobalConfig::$session_name);
if (empty($keyName)) {
return $profileSession;
}
return $profileSession['pid'];
}
/**
* 获取token_session_key
* @return mixed
*/
public function _sessionToken()
{
$this->sessionStart();
$session = QINAuth_Factory::profile('mini_web');
return $session->getSession('token_session_key');
}
/**
* 获取用户ID判断是否登录
* @return int
*/
public function _getUid()
{
$this->sessionStart();
$this->uid = QINAuth_Factory::profile('mini_web')->getSession();
return $this->uid;
}
/**
* 跳转地址
* @param string $refer
* @return string
*/
public function gotoUrl($refer = '')
{
$Uri = '';
if ($refer == '') {
$Uri = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
}
$referer = empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER'];
if ($Uri == $referer) {
$gotoUrl = '/';
} else {
$gotoUrl = !empty($refer) ? rawurldecode($refer) : '/';
}
return $gotoUrl;
}
/**
* 通过uid获取用户数据
* @param integer $uid
*
*/
protected static function _getUserInfo($uid)
{
$baseInfo = YHMPassport_Models_Profile_Client::getByUid($uid);
if (empty($baseInfo)) {
return array();
}
//星级评定结果
$store_info = YHMStore_Models_Store_Client::getByUid($uid);
$star = YHMComment_Models_Comment_Client::getStarByStoreId($store_info['id']);
$head_ico = empty($baseInfo['head_ico']) ? 'yhfair-user-head.d0861a87d5c6986dd490120524ff3e04.jpg' : $baseInfo['head_ico'];
$backgroup = empty($baseInfo['background_img']) ? 'yhfair-user-background.7c1ab223b0aa88d95abd2d6a4ef6ddca.jpg' : $baseInfo['background_img'];
$gender = empty($baseInfo['gender']) ? 0 : $baseInfo['gender'];
$area_code = empty($baseInfo['area_code']) ? 0 : $baseInfo['area_code'];
return array(
'uid' => $uid,
'store_id' => $store_info['id'],
'nick_name' => $baseInfo['nick_name'],
'gender' => $gender,
'area_code' => $area_code,
'identity' => $baseInfo['identity'],
'head_ico' => 'http://yhfair-user-head.qiniudn.com/' . $head_ico,
'background_img' => 'http://yhfair-user-background.qiniudn.com/' . $backgroup,
'star' => $star,
'store_type' => $store_info['store_type'], //3为Master,2为潮店,1为潮人
'is_real_name' => 'N',
'has_deposit' => 'N'
);
}
/**
* 为列表的商品信息获取数据
* @param integer $product_skc
*/
protected static function _getGoodsForList($product_skc)
{
$defalut_image = YHMProduct_Models_Goodsimages_Client::getDefaultImageBySkc($product_skc);
if (empty($defalut_image)) {
$defalut_image = YHMProduct_Models_Goodsimages_Client::getOneImageBySkc($product_skc);
}
return array(
'product_skc' => $product_skc,
'goods_image' => $defalut_image
);
}
}