ProductController.php
1.23 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
<?php
namespace soa\controllers\v1;
use Yii;
use soa\controllers\BaseController;
use common\models\RoomProduct;
/**
* Site controller
*/
class ProductController extends BaseController
{
/**
* 房间商品列表
* @return type
*/
public function actionList()
{
if (!$room_id = $this->requests('room_id')){
$this->renderJson(Yii::$app->params['failed_code'],'缺少id');
}
$key = __CLASS__.__FUNCTION__.'room_id'.$room_id;
if (!$ret = $this->cache->get($key)){
$ret = RoomProduct::find()
->where(['room_id'=>$room_id])
->orderBy(['sort'=>SORT_ASC,'create_time'=>SORT_DESC])
->select('product_id')->asArray()->column();
$dependency = new \yii\caching\DbDependency(['sql' => Yii::$app->db
->createCommand('SELECT MAX(update_time),count(*) FROM {{%room_product}} WHERE room_id=:room_id')
->bindValue(':room_id', $room_id)
->getRawSql()]);
$this->cache->set($key, $ret, Yii::$app->params['defaultCacheExpire'], $dependency);
}
$this->renderJson(Yii::$app->params['success_code'],'',$ret);
}
}