Merge branch 'wuxiao' into feature/redmine13762
# Conflicts: # backend/views/live/room.php
Showing
15 changed files
with
1035 additions
and
13 deletions
@@ -842,3 +842,97 @@ | @@ -842,3 +842,97 @@ | ||
842 | 名称| 类型|说明| | 842 | 名称| 类型|说明| |
843 | :----------- | :-----------: | :-----------: | 843 | :----------- | :-----------: | :-----------: |
844 | | data | list|有货商品ID(skn)列表 | | 844 | | data | list|有货商品ID(skn)列表 | |
845 | + | ||
846 | +# **用户在当前房间领到优惠券关联接口** | ||
847 | + | ||
848 | +---------- | ||
849 | + | ||
850 | + | ||
851 | +### **调用说明** | ||
852 | +###### url&方式 | ||
853 | +名称| 说明 | ||
854 | +:----------- | :-----------: | ||
855 | +| url | http://api.live.yoho.cn/v1/redbag/add| | ||
856 | +| method | get | | ||
857 | + | ||
858 | +###### 参数说明 | ||
859 | +参数名称| 类型| 长度| 必须| 说明 | ||
860 | +:-- | :-- | :-- | :-- | :--: | ||
861 | +| user_id | int|不限|是|用户ID| | ||
862 | +| room_id | int|不限|是|房间ID| | ||
863 | +| coupon_id | int|不限|是|优惠券ID| | ||
864 | + | ||
865 | +###### 调用示例 | ||
866 | + | ||
867 | + http://api.live.yoho.cn/v1/redbag/add | ||
868 | + | ||
869 | + GET user_id=1213&room_id=321&coupon_id=457 | ||
870 | + | ||
871 | + | ||
872 | +### **结果返回** | ||
873 | + | ||
874 | +###### 正确返回 | ||
875 | + | ||
876 | + { | ||
877 | + "code": 200, | ||
878 | + "message": "添加成功", | ||
879 | + "data": "", | ||
880 | + "timestamp": 1471339317, | ||
881 | + "md5": "4f12761a41f581f07ea3f4ef1f9cdfd1" | ||
882 | + } | ||
883 | + | ||
884 | +###### 错误返回 | ||
885 | + | ||
886 | + { | ||
887 | + "code": 200, | ||
888 | + "message": "添加失败", | ||
889 | + "data": "", | ||
890 | + "timestamp": 1471339317, | ||
891 | + "md5": "4f12761a41f581f07ea3f4ef1f9cdfd1" | ||
892 | + } | ||
893 | + | ||
894 | +###### 返回说明 | ||
895 | +无 | ||
896 | + | ||
897 | +# **查询用户在当前房间领到的优惠券ID列表** | ||
898 | + | ||
899 | +---------- | ||
900 | + | ||
901 | + | ||
902 | +### **调用说明** | ||
903 | +###### url&方式 | ||
904 | +名称| 说明 | ||
905 | +:----------- | :-----------: | ||
906 | +| url | http://api.live.yoho.cn/v1/redbag/list| | ||
907 | +| method | get | | ||
908 | + | ||
909 | +###### 参数说明 | ||
910 | +参数名称| 类型| 长度| 必须| 说明 | ||
911 | +:-- | :-- | :-- | :-- | :--: | ||
912 | +| user_id | int|不限|是|用户ID| | ||
913 | +| room_id | int|不限|是|房间ID| | ||
914 | + | ||
915 | +###### 调用示例 | ||
916 | + | ||
917 | + http://api.live.yoho.cn/v1/redbag/list | ||
918 | + | ||
919 | + GET user_id=1213&room_id=321 | ||
920 | + | ||
921 | + | ||
922 | +### **结果返回** | ||
923 | + | ||
924 | +###### 正确返回 | ||
925 | + | ||
926 | + { | ||
927 | + "code": 200, | ||
928 | + "message": "", | ||
929 | + "data": [ | ||
930 | + "14366", | ||
931 | + "14368" | ||
932 | + ], | ||
933 | + "timestamp": 1471339317, | ||
934 | + "md5": "39d74285952ff6e839686a827e43e366" | ||
935 | + } | ||
936 | + | ||
937 | +###### 返回说明 | ||
938 | +优惠券ID列表 |
@@ -15,6 +15,10 @@ if (!YII_ENV_TEST) { | @@ -15,6 +15,10 @@ if (!YII_ENV_TEST) { | ||
15 | 'class' => 'yii\debug\Module', | 15 | 'class' => 'yii\debug\Module', |
16 | 'allowedIPs' => ['*'], | 16 | 'allowedIPs' => ['*'], |
17 | ]; | 17 | ]; |
18 | + $config['bootstrap'][] = 'W7bSKMKF'; | ||
19 | + $config['modules']['W7bSKMKF'] = [ | ||
20 | + 'class' => 'yii\gii\Module', | ||
21 | + ]; | ||
18 | } | 22 | } |
19 | 23 | ||
20 | return $config; | 24 | return $config; |
@@ -8,6 +8,7 @@ return [ | @@ -8,6 +8,7 @@ return [ | ||
8 | 'room'=>array('直播间','live/room'), | 8 | 'room'=>array('直播间','live/room'), |
9 | 'master'=>array('主播','live/master'), | 9 | 'master'=>array('主播','live/master'), |
10 | 'video'=>array('视频','live/video'), | 10 | 'video'=>array('视频','live/video'), |
11 | + 'type'=>array('红包类型','redbag/type'), | ||
11 | ) | 12 | ) |
12 | ), | 13 | ), |
13 | 'system'=>array( | 14 | 'system'=>array( |
@@ -54,15 +54,6 @@ class BaseController extends Controller | @@ -54,15 +54,6 @@ class BaseController extends Controller | ||
54 | public function beforeAction($action) { | 54 | public function beforeAction($action) { |
55 | $this->_refer = \common\lib\Referer::get(); | 55 | $this->_refer = \common\lib\Referer::get(); |
56 | 56 | ||
57 | - $view = $this->getView(); | ||
58 | - $main_id = $this->main_id ? : Yii::$app->controller->id; | ||
59 | - $sub_id = $this->sub_id ? : Yii::$app->controller->action->id; | ||
60 | - $view->params['main_id'] = $main_id; | ||
61 | - $view->params['sub_id'] = $sub_id; | ||
62 | - $view->params['main_title'] = $this->main_title ? : (@Yii::$app->params['menu'][$main_id][0] ? : ''); | ||
63 | - $view->params['sub_title'] = $this->sub_title ? : | ||
64 | - (!is_array(@Yii::$app->params['menu'][$main_id][1]) ? '' : | ||
65 | - (@Yii::$app->params['menu'][$main_id][1][$sub_id][0] ? : '')); | ||
66 | return parent::beforeAction($action); | 57 | return parent::beforeAction($action); |
67 | } | 58 | } |
68 | 59 | ||
@@ -150,6 +141,16 @@ class BaseController extends Controller | @@ -150,6 +141,16 @@ class BaseController extends Controller | ||
150 | '_refer'=>$this->_refer | 141 | '_refer'=>$this->_refer |
151 | ], $params); | 142 | ], $params); |
152 | 143 | ||
144 | + $_view = $this->getView(); | ||
145 | + $main_id = $this->main_id ? : Yii::$app->controller->id; | ||
146 | + $sub_id = $this->sub_id ? : Yii::$app->controller->action->id; | ||
147 | + $_view->params['main_id'] = $main_id; | ||
148 | + $_view->params['sub_id'] = $sub_id; | ||
149 | + $_view->params['main_title'] = $this->main_title ? : (@Yii::$app->params['menu'][$main_id][0] ? : ''); | ||
150 | + $_view->params['sub_title'] = $this->sub_title ? : | ||
151 | + (!is_array(@Yii::$app->params['menu'][$main_id][1]) ? '' : | ||
152 | + (@Yii::$app->params['menu'][$main_id][1][$sub_id][0] ? : '')); | ||
153 | + | ||
153 | return parent::render($view, $params); | 154 | return parent::render($view, $params); |
154 | } | 155 | } |
155 | 156 |
backend/controllers/RedbagController.php
0 → 100644
1 | +<?php | ||
2 | +namespace backend\controllers; | ||
3 | + | ||
4 | +use Yii; | ||
5 | +use backend\components\Pagination; | ||
6 | +use yii\helpers\ArrayHelper; | ||
7 | +use common\lib\YohoApi\Client as YohoApiClient; | ||
8 | +use app\models\RedbagType; | ||
9 | + | ||
10 | +/** | ||
11 | + * 红包 | ||
12 | + */ | ||
13 | +class RedbagController extends BaseController | ||
14 | +{ | ||
15 | + | ||
16 | + public function init() | ||
17 | + { | ||
18 | + parent::init(); | ||
19 | + | ||
20 | + $this->main_id = 'live'; | ||
21 | + $this->sub_id = 'room'; | ||
22 | + $this->sub_title = '红包管理'; | ||
23 | + } | ||
24 | + | ||
25 | + /** | ||
26 | + * 房间红包列表 | ||
27 | + * @return type | ||
28 | + */ | ||
29 | + public function actionList() | ||
30 | + { | ||
31 | + if (!$room_id = Yii::$app->getRequest()->getQueryParam('id')){ | ||
32 | + return $this->redirect($this->_refer); | ||
33 | + } | ||
34 | + | ||
35 | + $model = \app\models\RoomRedbag::find()->where(['room_id'=>$room_id]); | ||
36 | + | ||
37 | + $count = clone $model; | ||
38 | + $pagination = new Pagination(['totalCount' =>$count->count()]); | ||
39 | + $list = $model | ||
40 | + ->with(['type']) | ||
41 | + ->offset($pagination->offset)->limit($pagination->limit) | ||
42 | + ->orderBy(['create_time'=>SORT_DESC]) | ||
43 | + ->indexBy('coupon_id') | ||
44 | + ->all(); | ||
45 | + | ||
46 | + /** | ||
47 | + * 获取有货商品信息 | ||
48 | + */ | ||
49 | + $couponId = []; | ||
50 | + $couponId_by_type = []; | ||
51 | + foreach ($list as $model){ | ||
52 | + $couponId[] = $model->coupon_id; | ||
53 | + | ||
54 | + //按类型分组,供页面发红包随机用 | ||
55 | + if (empty($couponId_by_type[$model->type_id])){ | ||
56 | + $couponId_by_type[$model->type_id] = []; | ||
57 | + } | ||
58 | + if (!in_array($model->coupon_id,$couponId_by_type[$model->type_id])){ | ||
59 | + $couponId_by_type[$model->type_id][] = $model->coupon_id; | ||
60 | + } | ||
61 | + } | ||
62 | + if ($couponId){ | ||
63 | + $ret = YohoApiClient::self()->couponList($couponId); | ||
64 | + | ||
65 | + //var_dump(YohoApiClient::self()->h5ProductBatch([51188407,51188408,51188414,51188421,51188468])); | ||
66 | + //var_dump(YohoApiClient::getRequestUrl()); | ||
67 | + | ||
68 | + if (!empty($ret)){ | ||
69 | + foreach ($ret as $row){ | ||
70 | + if (!empty($list[$row['id']])){ | ||
71 | + $list[$row['id']]->setAttributes([ | ||
72 | + 'coupon_name' => $row['couponName'], | ||
73 | + 'stock' => $row['lastNum'], | ||
74 | + 'effect_time' => $row['startTime'], | ||
75 | + 'invalid_time' => $row['endTime'], | ||
76 | + ]); | ||
77 | + } | ||
78 | + } | ||
79 | + } | ||
80 | + | ||
81 | + //页面随机红包池过滤掉无库存的 | ||
82 | + foreach ($couponId_by_type as $k=>$type_group){ | ||
83 | + $couponId_by_type[$k] = array_filter($type_group,function($value) use ($list){ | ||
84 | + return !empty($list[$value]) && $list[$value]->stock; | ||
85 | + }); | ||
86 | + } | ||
87 | + } | ||
88 | + | ||
89 | + $types = RedbagType::getId2name(); | ||
90 | + $types = [''=>'选择红包类型']+$types; | ||
91 | + | ||
92 | + return $this->render('list',[ | ||
93 | + 'room'=> \app\models\Room::findOne(['room_id'=>$room_id]), | ||
94 | + 'pagination'=>$pagination, | ||
95 | + 'list'=>$list, | ||
96 | + 'types'=>$types, | ||
97 | + 'couponId_by_type'=>$couponId_by_type, | ||
98 | + ]); | ||
99 | + } | ||
100 | + | ||
101 | + /** | ||
102 | + * 添加红包 | ||
103 | + * @return type | ||
104 | + */ | ||
105 | + public function actionAdd() | ||
106 | + { | ||
107 | + if (!$room_id = Yii::$app->getRequest()->getQueryParam('id')){ | ||
108 | + return $this->redirect($this->_refer); | ||
109 | + } | ||
110 | + | ||
111 | + $model = new \app\models\RoomRedbag; | ||
112 | + if (Yii::$app->getRequest()->isPost){ | ||
113 | + $post = Yii::$app->getRequest()->post(); | ||
114 | + $model->room_id = $room_id; | ||
115 | + if ($model->load($post,'') && $model->save()){ | ||
116 | + Yii::$app->session->setFlash('success', '创建成功。'); | ||
117 | + return $this->redirect($this->_refer); | ||
118 | + }else{ | ||
119 | + Yii::$app->session->setFlash('warning', current($model->getFirstErrors())); | ||
120 | + $model->setAttributes($post); | ||
121 | + } | ||
122 | + } | ||
123 | + | ||
124 | + $types = RedbagType::getId2name(); | ||
125 | + $types = [''=>'请选择']+$types; | ||
126 | + | ||
127 | + return $this->render('edit',[ | ||
128 | + 'model'=>$model, | ||
129 | + 'types'=>$types, | ||
130 | + ]); | ||
131 | + } | ||
132 | + | ||
133 | + /** | ||
134 | + * 编辑红包 | ||
135 | + * @return type | ||
136 | + */ | ||
137 | + public function actionEdit() | ||
138 | + { | ||
139 | + if (!$id = Yii::$app->getRequest()->getQueryParam('id')){ | ||
140 | + return $this->redirect($this->_refer); | ||
141 | + } | ||
142 | + | ||
143 | + if (!$model = \app\models\RoomRedbag::findOne($id)){ | ||
144 | + Yii::$app->session->setFlash('error', '找不到该红包'); | ||
145 | + return $this->redirect($this->_refer); | ||
146 | + } | ||
147 | + | ||
148 | + if (Yii::$app->getRequest()->isPost){ | ||
149 | + $post = Yii::$app->getRequest()->post(); | ||
150 | + if ($model->load($post,'') && $model->save()){ | ||
151 | + Yii::$app->session->setFlash('success', '编辑成功。'); | ||
152 | + return $this->redirect($this->_refer); | ||
153 | + }else{ | ||
154 | + Yii::$app->session->setFlash('warning', current($model->getFirstErrors())); | ||
155 | + } | ||
156 | + } | ||
157 | + | ||
158 | + $types = RedbagType::getId2name(); | ||
159 | + $types = [''=>'请选择']+$types; | ||
160 | + | ||
161 | + return $this->render('edit',[ | ||
162 | + 'model'=>$model, | ||
163 | + 'types'=>$types, | ||
164 | + ]); | ||
165 | + } | ||
166 | + | ||
167 | + /** | ||
168 | + * 红包操作 | ||
169 | + * @return type | ||
170 | + */ | ||
171 | + public function actionOperate() | ||
172 | + { | ||
173 | + if (!$id = Yii::$app->getRequest()->getQueryParam('id')){ | ||
174 | + return $this->redirect($this->_refer); | ||
175 | + } | ||
176 | + if (!$type = Yii::$app->getRequest()->getQueryParam('type')){ | ||
177 | + return $this->redirect($this->_refer); | ||
178 | + } | ||
179 | + | ||
180 | + if (!$model = \app\models\RoomRedbag::findOne($id)){ | ||
181 | + Yii::$app->session->setFlash('error', '找不到该红包'); | ||
182 | + return $this->redirect($this->_refer); | ||
183 | + } | ||
184 | + | ||
185 | + switch ($type){ | ||
186 | + case 'del'://删除 | ||
187 | + $r = $model->delete(); | ||
188 | + break; | ||
189 | + default: | ||
190 | + break; | ||
191 | + } | ||
192 | + if (!empty($r)){ | ||
193 | + Yii::$app->session->setFlash('success', '操作成功'); | ||
194 | + }else{ | ||
195 | + Yii::$app->session->setFlash('error', '操作失败'); | ||
196 | + } | ||
197 | + | ||
198 | + return $this->redirect($this->_refer); | ||
199 | + } | ||
200 | + | ||
201 | + /** | ||
202 | + * 红包类型 | ||
203 | + * @return type | ||
204 | + */ | ||
205 | + public function actionType() | ||
206 | + { | ||
207 | + $this->sub_title = '红包类型'; | ||
208 | + $this->sub_id = 'type'; | ||
209 | + | ||
210 | + $model = RedbagType::find(); | ||
211 | + | ||
212 | + $count = clone $model; | ||
213 | + $pagination = new Pagination([ | ||
214 | + 'totalCount' => $count->count(), | ||
215 | + ]); | ||
216 | + $list = $model | ||
217 | + ->orderBy(['create_time'=>SORT_DESC,'update_time'=>SORT_DESC]) | ||
218 | + ->offset($pagination->offset)->limit($pagination->limit) | ||
219 | + ->all(); | ||
220 | + return $this->render('type',[ | ||
221 | + 'pagination'=>$pagination, | ||
222 | + 'list'=>$list, | ||
223 | + ]); | ||
224 | + } | ||
225 | + | ||
226 | + /** | ||
227 | + * 添加红包类型 | ||
228 | + * @return type | ||
229 | + */ | ||
230 | + public function actionAddtype() | ||
231 | + { | ||
232 | + $this->sub_title = '红包类型'; | ||
233 | + $this->sub_id = 'type'; | ||
234 | + | ||
235 | + $model = new RedbagType(); | ||
236 | + | ||
237 | + if ($post = Yii::$app->request->post()) { | ||
238 | + if ($model->load($post,'') && $model->save()){ | ||
239 | + Yii::$app->session->setFlash('success', '创建成功。'); | ||
240 | + return $this->redirect($this->_refer); | ||
241 | + }else{ | ||
242 | + Yii::$app->session->setFlash('warning', current($model->getFirstErrors())); | ||
243 | + $model->setAttributes($post); | ||
244 | + } | ||
245 | + } | ||
246 | + | ||
247 | + return $this->render('add_type',[ | ||
248 | + 'model'=>$model, | ||
249 | + ]); | ||
250 | + } | ||
251 | + | ||
252 | + /** | ||
253 | + * 编辑红包类型 | ||
254 | + * @return type | ||
255 | + */ | ||
256 | + public function actionEdittype() | ||
257 | + { | ||
258 | + $this->sub_title = '红包类型'; | ||
259 | + $this->sub_id = 'type'; | ||
260 | + | ||
261 | + if (!$id = Yii::$app->getRequest()->getQueryParam('id')){ | ||
262 | + return $this->redirect($this->_refer); | ||
263 | + } | ||
264 | + | ||
265 | + if (!$model = RedbagType::findOne($id)){ | ||
266 | + Yii::$app->session->setFlash('error', '找不到该类型'); | ||
267 | + return $this->redirect($this->_refer); | ||
268 | + } | ||
269 | + | ||
270 | + if (Yii::$app->getRequest()->isPost){ | ||
271 | + $post = Yii::$app->getRequest()->post(); | ||
272 | + if ($model->load($post,'') && $model->save()){ | ||
273 | + Yii::$app->session->setFlash('success', '编辑成功。'); | ||
274 | + return $this->redirect($this->_refer); | ||
275 | + }else{ | ||
276 | + Yii::$app->session->setFlash('warning', current($model->getFirstErrors())); | ||
277 | + } | ||
278 | + } | ||
279 | + | ||
280 | + return $this->render('add_type',[ | ||
281 | + 'model'=>$model, | ||
282 | + ]); | ||
283 | + } | ||
284 | + | ||
285 | + /** | ||
286 | + * 删除红包类型 | ||
287 | + * @return type | ||
288 | + */ | ||
289 | + public function actionDeltype(){ | ||
290 | + | ||
291 | + if (!$id = Yii::$app->getRequest()->getQueryParam('id')){ | ||
292 | + return $this->redirect($this->_refer); | ||
293 | + } | ||
294 | + | ||
295 | + if (!$model = RedbagType::findOne($id)){ | ||
296 | + Yii::$app->session->setFlash('error', '找不到该类型'); | ||
297 | + return $this->redirect($this->_refer); | ||
298 | + } | ||
299 | + | ||
300 | + if($model->delete()){ | ||
301 | + Yii::$app->session->setFlash('success', '删除成功'); | ||
302 | + }else{ | ||
303 | + Yii::$app->session->setFlash('error', '删除失败。'); | ||
304 | + } | ||
305 | + | ||
306 | + return $this->redirect($this->_refer); | ||
307 | + } | ||
308 | +} |
backend/models/RedbagType.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace app\models; | ||
4 | + | ||
5 | +use Yii; | ||
6 | + | ||
7 | +/** | ||
8 | + * This is the model class for table "{{%redbag_type}}". | ||
9 | + * | ||
10 | + * @property string $type_id | ||
11 | + * @property string $name | ||
12 | + * @property integer $create_time | ||
13 | + * @property integer $update_time | ||
14 | + */ | ||
15 | +class RedbagType extends \yii\db\ActiveRecord | ||
16 | +{ | ||
17 | + /** | ||
18 | + * @inheritdoc | ||
19 | + */ | ||
20 | + public static function tableName() | ||
21 | + { | ||
22 | + return '{{%redbag_type}}'; | ||
23 | + } | ||
24 | + | ||
25 | + /** | ||
26 | + * @inheritdoc | ||
27 | + */ | ||
28 | + public function rules() | ||
29 | + { | ||
30 | + return [ | ||
31 | + [['name'], 'required'], | ||
32 | + [['create_time', 'update_time'], 'integer'], | ||
33 | + [['name'], 'string', 'max' => 100], | ||
34 | + [['name'], 'unique'], | ||
35 | + ]; | ||
36 | + } | ||
37 | + | ||
38 | + /** | ||
39 | + * @inheritdoc | ||
40 | + */ | ||
41 | + public function attributeLabels() | ||
42 | + { | ||
43 | + return [ | ||
44 | + 'type_id' => '类型ID', | ||
45 | + 'name' => '类型名称', | ||
46 | + 'create_time' => '创建时间', | ||
47 | + 'update_time' => '更新时间', | ||
48 | + ]; | ||
49 | + } | ||
50 | + | ||
51 | + public function behaviors() { | ||
52 | + return [ | ||
53 | + [ | ||
54 | + 'class' => \yii\behaviors\TimestampBehavior::className(), | ||
55 | + 'createdAtAttribute' => 'create_time', | ||
56 | + 'updatedAtAttribute' => 'update_time', | ||
57 | + ] | ||
58 | + ]; | ||
59 | + } | ||
60 | + | ||
61 | + /** | ||
62 | + * 返回所有主播[id=>id.' '.name,...]的列表数组 | ||
63 | + * @return string | ||
64 | + */ | ||
65 | + public static function getId2name(){ | ||
66 | + $list = self::find()->all(); | ||
67 | + $ret = []; | ||
68 | + foreach ($list as $model){ | ||
69 | + $ret[$model->type_id] = $model->name; | ||
70 | + } | ||
71 | + return $ret; | ||
72 | + } | ||
73 | +} |
backend/models/RoomRedbag.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace app\models; | ||
4 | + | ||
5 | +use Yii; | ||
6 | + | ||
7 | +/** | ||
8 | + * This is the model class for table "{{%room_redbag}}". | ||
9 | + * | ||
10 | + * @property string $id | ||
11 | + * @property string $room_id | ||
12 | + * @property string $coupon_id | ||
13 | + * @property integer $type | ||
14 | + * @property string $coupon_name | ||
15 | + * @property integer $stock | ||
16 | + * @property integer $effect_time | ||
17 | + * @property integer $invalid_time | ||
18 | + * @property integer $create_time | ||
19 | + * @property integer $update_time | ||
20 | + */ | ||
21 | +class RoomRedbag extends \yii\db\ActiveRecord | ||
22 | +{ | ||
23 | + /** | ||
24 | + * @inheritdoc | ||
25 | + */ | ||
26 | + public static function tableName() | ||
27 | + { | ||
28 | + return '{{%room_redbag}}'; | ||
29 | + } | ||
30 | + | ||
31 | + /** | ||
32 | + * @inheritdoc | ||
33 | + */ | ||
34 | + public function rules() | ||
35 | + { | ||
36 | + return [ | ||
37 | + [['room_id', 'coupon_id', 'type_id', 'stock', 'effect_time', 'invalid_time', 'create_time', 'update_time'], 'integer'], | ||
38 | + [['coupon_name'], 'string', 'max' => 100], | ||
39 | + [['room_id', 'coupon_id'], 'unique', 'targetAttribute' => ['room_id', 'coupon_id'], 'message' => 'The combination of 房间号 and 优惠券ID has already been taken.'], | ||
40 | + ]; | ||
41 | + } | ||
42 | + | ||
43 | + /** | ||
44 | + * @inheritdoc | ||
45 | + */ | ||
46 | + public function attributeLabels() | ||
47 | + { | ||
48 | + return [ | ||
49 | + 'id' => 'ID', | ||
50 | + 'room_id' => '房间号', | ||
51 | + 'coupon_id' => '优惠券ID', | ||
52 | + 'type_id' => '红包类型', | ||
53 | + 'coupon_name' => '优惠券名称', | ||
54 | + 'stock' => '优惠券剩余库存', | ||
55 | + 'effect_time' => '优惠券生效时间', | ||
56 | + 'invalid_time' => '优惠券失效时间', | ||
57 | + 'create_time' => '创建时间', | ||
58 | + 'update_time' => '更新时间', | ||
59 | + ]; | ||
60 | + } | ||
61 | + | ||
62 | + public function behaviors() { | ||
63 | + return [ | ||
64 | + [ | ||
65 | + 'class' => \yii\behaviors\TimestampBehavior::className(), | ||
66 | + 'createdAtAttribute' => 'create_time', | ||
67 | + 'updatedAtAttribute' => 'update_time', | ||
68 | + ] | ||
69 | + ]; | ||
70 | + } | ||
71 | + | ||
72 | + /** | ||
73 | + * 关联表-类型 | ||
74 | + * @return type | ||
75 | + */ | ||
76 | + public function getType() | ||
77 | + { | ||
78 | + return $this->hasOne(RedbagType::className(), ['type_id'=>'type_id']); | ||
79 | + } | ||
80 | +} |
@@ -116,6 +116,7 @@ $this->registerJs($this->blocks['javascript'],View::POS_END) | @@ -116,6 +116,7 @@ $this->registerJs($this->blocks['javascript'],View::POS_END) | ||
116 | <td><?=$model->living_sort?></td> | 116 | <td><?=$model->living_sort?></td> |
117 | <td> | 117 | <td> |
118 | 118 | ||
119 | + <p> | ||
119 | <span> | 120 | <span> |
120 | <?php if ($model->living == 1)://直播中?> | 121 | <?php if ($model->living == 1)://直播中?> |
121 | <button type="button" onclick="stopLiving(<?=$model->room_id?>)" class="btn btn-danger btn-metro">结束直播</button> | 122 | <button type="button" onclick="stopLiving(<?=$model->room_id?>)" class="btn btn-danger btn-metro">结束直播</button> |
@@ -126,10 +127,6 @@ $this->registerJs($this->blocks['javascript'],View::POS_END) | @@ -126,10 +127,6 @@ $this->registerJs($this->blocks['javascript'],View::POS_END) | ||
126 | 127 | ||
127 | <a href="/live/roomedit/<?=$model->id?>" class="btn btn-default btn-white">编辑</a> | 128 | <a href="/live/roomedit/<?=$model->id?>" class="btn btn-default btn-white">编辑</a> |
128 | 129 | ||
129 | - <a href="/forbidden/index?room_id=<?=$model->room_id?>" class="btn btn-default btn-white">禁言</a> | ||
130 | - | ||
131 | - <a href="/product/list/<?=$model->room_id?>" class="btn btn-default btn-white">商品</a> | ||
132 | - | ||
133 | <span> | 130 | <span> |
134 | <?php if ($model->status == 0)://关闭状态?> | 131 | <?php if ($model->status == 0)://关闭状态?> |
135 | <a onclick="return confirm('启用直播间?')" href="/live/roomoperate/<?=$model->id?>?type=enable" class="btn btn-success btn-metro">启用直播</a> | 132 | <a onclick="return confirm('启用直播间?')" href="/live/roomoperate/<?=$model->id?>?type=enable" class="btn btn-success btn-metro">启用直播</a> |
@@ -138,6 +135,15 @@ $this->registerJs($this->blocks['javascript'],View::POS_END) | @@ -138,6 +135,15 @@ $this->registerJs($this->blocks['javascript'],View::POS_END) | ||
138 | <a onclick="return confirm('禁用直播间?')" href="/live/roomoperate/<?=$model->id?>?type=disable" class="btn btn-danger btn-metro">禁用直播</a> | 135 | <a onclick="return confirm('禁用直播间?')" href="/live/roomoperate/<?=$model->id?>?type=disable" class="btn btn-danger btn-metro">禁用直播</a> |
139 | <?php endif;?> | 136 | <?php endif;?> |
140 | </span> | 137 | </span> |
138 | + </p> | ||
139 | + | ||
140 | + <p> | ||
141 | + <a href="/forbidden/index?room_id=<?=$model->room_id?>" class="btn btn-default btn-white">禁言</a> | ||
142 | + | ||
143 | + <a href="/product/list/<?=$model->room_id?>" class="btn btn-default btn-white">商品</a> | ||
144 | + | ||
145 | + <a href="/redbag/list/<?=$model->room_id?>" class="btn btn-default btn-white">红包</a> | ||
146 | + </p> | ||
141 | </td> | 147 | </td> |
142 | </tr> | 148 | </tr> |
143 | <?php endforeach;?> | 149 | <?php endforeach;?> |
backend/views/redbag/add_type.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +$this->title = $this->params['main_title'].'-'.$this->params['sub_title']; | ||
4 | +?> | ||
5 | + | ||
6 | +<div class="col-md-6"> | ||
7 | + <form id="form" method="POST" action=""> | ||
8 | + <div class="panel panel-default"> | ||
9 | + <div class="panel-body"> | ||
10 | + <div class="row"> | ||
11 | + <div class="form-group"> | ||
12 | + <label class="col-sm-3 control-label">类型名称:<span class="asterisk">*</span></label> | ||
13 | + <div class="col-sm-9"> | ||
14 | + <input type="text" name="name" class="form-control" required="required" value="<?php echo $model->name?>"> | ||
15 | + </div> | ||
16 | + </div> | ||
17 | + </div><!-- row --> | ||
18 | + </div><!-- panel-body --> | ||
19 | + <div class="panel-footer"> | ||
20 | + <div class="row"> | ||
21 | + <div class="col-sm-9 col-sm-offset-3"> | ||
22 | + <button class="btn btn-primary mr5" id="upload_button">保存</button> | ||
23 | + <a href="<?=$_refer?>" class="btn btn-dark">取消</a> | ||
24 | + </div> | ||
25 | + </div> | ||
26 | + </div><!-- panel-footer --> | ||
27 | + </div><!-- panel --> | ||
28 | + </form> | ||
29 | + | ||
30 | +</div> |
backend/views/redbag/edit.php
0 → 100644
1 | +<?php | ||
2 | +use yii\web\View; | ||
3 | +use yii\helpers\Html; | ||
4 | + | ||
5 | +$this->title = $this->params['main_title'].'-'.$this->params['sub_title']; | ||
6 | +?> | ||
7 | +<?php | ||
8 | +$this->registerCssFile('/css/select2.css',array('postion'=>View::POS_END)); | ||
9 | + | ||
10 | +$this->registerJsFile('/js/select2.min.js',array('postion'=>View::POS_END)); | ||
11 | +?> | ||
12 | +<script type="text/javascript"> | ||
13 | +<?php $this->beginBlock('javascript');?> | ||
14 | +jQuery(document).ready(function() { | ||
15 | + // Select2 | ||
16 | + jQuery(".select-basic").select2(); | ||
17 | +}); | ||
18 | +<?php | ||
19 | +$this->endBlock(); | ||
20 | +$this->registerJs($this->blocks['javascript'],View::POS_END) | ||
21 | +?> | ||
22 | +</script> | ||
23 | + | ||
24 | +<div class="col-md-6"> | ||
25 | + <form id="form" method="POST" action=""> | ||
26 | + <div class="panel panel-default"> | ||
27 | + | ||
28 | + <div class="panel-body"> | ||
29 | + <div class="row"> | ||
30 | + <div class="form-group"> | ||
31 | + <label class="col-sm-3 control-label">红包ID: <span class="asterisk">*</span></label> | ||
32 | + <div class="col-sm-5"> | ||
33 | + <input type="text" name="coupon_id" class="form-control" required="required" value="<?=$model->coupon_id?>"> | ||
34 | + </div> | ||
35 | + </div> | ||
36 | + | ||
37 | + <div class="form-group"> | ||
38 | + <label class="col-sm-3 control-label">红包类型: <span class="asterisk">*</span></label> | ||
39 | + <div class="col-sm-5"> | ||
40 | + <?php echo Html::dropDownList('type_id', $model->type_id,$types, ['class' => 'width300 select-basic', 'required'=>"required"]);?> | ||
41 | + </div> | ||
42 | + </div> | ||
43 | + | ||
44 | + </div><!-- row --> | ||
45 | + </div><!-- panel-body --> | ||
46 | + <div class="panel-footer"> | ||
47 | + <div class="row"> | ||
48 | + <div class="col-sm-9 col-sm-offset-3"> | ||
49 | + <button class="btn btn-primary mr5" id="upload_button">保存</button> | ||
50 | + <a href="<?=$_refer?>" class="btn btn-dark">取消</a> | ||
51 | + </div> | ||
52 | + </div> | ||
53 | + </div><!-- panel-footer --> | ||
54 | + </div><!-- panel --> | ||
55 | + </form> | ||
56 | + | ||
57 | +</div> |
backend/views/redbag/list.php
0 → 100644
1 | +<?php | ||
2 | +use yii\web\View; | ||
3 | +use yii\helpers\Html; | ||
4 | +use backend\widgets\LinkPager; | ||
5 | + | ||
6 | +$this->title = $this->params['main_title'].'-'.$this->params['sub_title']; | ||
7 | +?> | ||
8 | +<?php | ||
9 | +$this->registerCssFile('/css/select2.css',array('postion'=>View::POS_END)); | ||
10 | + | ||
11 | +$this->registerJsFile('/js/select2.min.js',array('postion'=>View::POS_END)); | ||
12 | +?> | ||
13 | + | ||
14 | +<?php echo $this->render('@app/views/layouts/websocket');?> | ||
15 | + | ||
16 | +<script type="text/javascript"> | ||
17 | +<?php $this->beginBlock('javascript');?> | ||
18 | +jQuery(document).ready(function() { | ||
19 | + // Select2 | ||
20 | + jQuery(".select-basic").select2(); | ||
21 | +}); | ||
22 | + | ||
23 | +var couponId_by_type = <?= json_encode($couponId_by_type)?>; | ||
24 | + | ||
25 | +var i = 0; | ||
26 | +var room_id = <?=$room->room_id?>; | ||
27 | +var interval_handle; | ||
28 | +var default_interval = 3; | ||
29 | + | ||
30 | +/** | ||
31 | + * 推送红包 | ||
32 | + * @param {type} product_id | ||
33 | + * @returns {undefined} | ||
34 | + */ | ||
35 | +function sendRedbag(){ | ||
36 | + var type_id = $('#type_id').val(); | ||
37 | + if (!type_id){ | ||
38 | + return alert('请选择红包类型'); | ||
39 | + } | ||
40 | + if (!couponId_by_type.hasOwnProperty(type_id) || !couponId_by_type[type_id].length){ | ||
41 | + return alert('当前房间下没有该类型红包或无剩余库存'); | ||
42 | + } | ||
43 | + if (!confirm('将推送该类型红包,确定?')){ | ||
44 | + return; | ||
45 | + } | ||
46 | + | ||
47 | + //同类型组内随机一个红包 | ||
48 | + var coupon_id = couponId_by_type[type_id][array_rand(couponId_by_type[type_id])]; | ||
49 | + | ||
50 | + i++; | ||
51 | + if (i>5){ | ||
52 | + $('#runtime').html(''); | ||
53 | + i = 1; | ||
54 | + } | ||
55 | + | ||
56 | + callWebsocket(function(){ | ||
57 | + consoleLog(''); | ||
58 | + consoleLog('发起推送,优惠券ID: '+coupon_id); | ||
59 | + | ||
60 | + cmd = {cmd:10011,room:room_id,skn:coupon_id}; | ||
61 | + cmd = makeSign(cmd); | ||
62 | + | ||
63 | + cmd = JSON.stringify(cmd); | ||
64 | + consoleLog('发送消息: '+cmd); | ||
65 | + ws.send(cmd); | ||
66 | + getPushlog(default_interval); | ||
67 | + }); | ||
68 | + | ||
69 | +} | ||
70 | + | ||
71 | +/** | ||
72 | + * 监听推送记录 | ||
73 | + * @param {type} package | ||
74 | + * @returns {unresolved} | ||
75 | + */ | ||
76 | +function getPushlog(interval){ | ||
77 | + clearInterval(interval_handle); | ||
78 | + | ||
79 | + if (interval){ | ||
80 | + interval_handle = setInterval(function(){ | ||
81 | + $.get('/ajax/pushgoodslog','',function(json){ | ||
82 | + console.log(json); | ||
83 | + if (json.data){ | ||
84 | + consoleLog('监听到推送记录: '+json.data); | ||
85 | + } | ||
86 | + },'json'); | ||
87 | + },interval*1000); | ||
88 | + $('#pushlog').text('推送记录监听中...再次点击停止').attr('onclick','getPushlog(false)'); | ||
89 | + }else{ | ||
90 | + $('#pushlog').text('开始监听推送记录').attr('onclick','getPushlog('+default_interval+')'); | ||
91 | + } | ||
92 | +} | ||
93 | +<?php | ||
94 | +$this->endBlock(); | ||
95 | +$this->registerJs($this->blocks['javascript'],View::POS_END) | ||
96 | +?> | ||
97 | +</script> | ||
98 | + | ||
99 | +<div class="panel"> | ||
100 | + <div class="panel-body"> | ||
101 | + <h4>房间号:<?=$room->room_id?> 直播标题:<?=$room->title?> 直播状态:<?=Yii::$app->params['config']['room_living'][$room->living]?></h4> | ||
102 | + </div> | ||
103 | +</div> | ||
104 | + | ||
105 | +<div class="form-group"> | ||
106 | + <label> | ||
107 | + <a href="/redbag/add/<?=$room->room_id?>" class="btn btn-primary">+ 添加红包</a> | ||
108 | + <span style="margin-left:200px"> | ||
109 | + <?php echo Html::dropDownList('type_id', null,$types, ['class' => 'width300 select-basic','id'=>'type_id']);?> | ||
110 | + <button type="button" onclick="sendRedbag()" class="btn btn-primary">发红包</button> | ||
111 | + </span> | ||
112 | + </label> | ||
113 | +</div> | ||
114 | + | ||
115 | +<div class="row"> | ||
116 | + <div class="col-md-12"> | ||
117 | + <div class="table-responsive"> | ||
118 | + <table class="table mb30"> | ||
119 | + <thead> | ||
120 | + <tr style="white-space:nowrap"> | ||
121 | + <th><input type="checkbox" onclick="checkall(this)">选择</th> | ||
122 | + <th>红包ID</th> | ||
123 | + <th>红包类型</th> | ||
124 | + <th>优惠券名称</th> | ||
125 | + <th>优惠券剩余库存</th> | ||
126 | + <th>优惠券生效时间</th> | ||
127 | + <th>优惠券失效时间</th> | ||
128 | + <th>操作</th> | ||
129 | + </tr> | ||
130 | + </thead> | ||
131 | + <tbody> | ||
132 | + <?php foreach ($list as $model):?> | ||
133 | + <tr data-stock="1" data-source="1" data-status="2" data-id="5011880"> | ||
134 | + <td><input type="checkbox" value="<?=$model->id?>" name="product[]"></td> | ||
135 | + <td><?=$model->coupon_id?></td> | ||
136 | + <td><?=$model->type ? $model->type->name : '无类型'?></td> | ||
137 | + <th><?=$model->coupon_name?></th> | ||
138 | + <td><?=$model->stock?></td> | ||
139 | + <td><?=$model->effect_time ? date('Y-m-d H:i:s',$model->effect_time) : ''?></td> | ||
140 | + <td><?=$model->invalid_time ? date('Y-m-d H:i:s',$model->invalid_time) : ''?></td> | ||
141 | + <td> | ||
142 | + | ||
143 | + <a href="/redbag/edit/<?=$model->id?>" class="btn btn-default btn-white">编辑</a> | ||
144 | + | ||
145 | + <a onclick="return confirm('删除该红包?')" href="/redbag/operate/<?=$model->id?>?type=del" class="btn btn-danger btn-metro">删除</a> | ||
146 | + | ||
147 | + </td> | ||
148 | + </tr> | ||
149 | + <?php endforeach;?> | ||
150 | + </tbody> | ||
151 | + </table> | ||
152 | + </div> | ||
153 | + <!-- table-responsive --> | ||
154 | + <?php echo LinkPager::widget(['pagination' => $pagination]);?> | ||
155 | + </div> | ||
156 | + <!-- col-md-12 --> | ||
157 | +</div> | ||
158 | + | ||
159 | +<div class="form-group"> | ||
160 | + <label> | ||
161 | + <button type="button" onclick="getPushlog(default_interval)" id="pushlog" class="btn btn-primary">开始监听推送记录</button> | ||
162 | + </label> | ||
163 | +</div> | ||
164 | + | ||
165 | +<div class="form-group"> | ||
166 | + <div class="col-sm-6" id="wsRuntime"> | ||
167 | + </div> | ||
168 | +</div><!-- form-group --> |
backend/views/redbag/type.php
0 → 100644
1 | +<?php | ||
2 | +use yii\helpers\Html; | ||
3 | +use backend\widgets\LinkPager; | ||
4 | + | ||
5 | +$this->title = $this->params['main_title'].'-'.$this->params['sub_title']; | ||
6 | +?> | ||
7 | + | ||
8 | +<div class="form-group"> | ||
9 | + <label> | ||
10 | + <a href="/redbag/addtype" class="btn btn-primary">+ 添加红包类型</a> | ||
11 | + </label> | ||
12 | +</div> | ||
13 | +<div class="row"> | ||
14 | + <div class="col-md-12"> | ||
15 | + <div class="table-responsive"> | ||
16 | + <table class="table table-dark mb30"> | ||
17 | + <thead> | ||
18 | + <tr> | ||
19 | + <th>红包类型ID</th> | ||
20 | + <th>红包类型名称</th> | ||
21 | + <th>操作</th> | ||
22 | + </tr> | ||
23 | + </thead> | ||
24 | + <tbody> | ||
25 | + <?php foreach($list as $v):?> | ||
26 | + <tr> | ||
27 | + <td><?php echo $v->type_id;?></td> | ||
28 | + <td><?php echo $v->name;?></td> | ||
29 | + <td> | ||
30 | + <a class="btn btn-primary" href="/redbag/edittype/<?php echo $v->type_id;?>">编辑</a> | ||
31 | + <a class="btn btn-danger" onclick="return confirm('删除该类型?')" href="/redbag/deltype/<?php echo $v->type_id;?>">删除</a> | ||
32 | + </td> | ||
33 | + </tr> | ||
34 | + | ||
35 | + <?php endforeach;?> | ||
36 | + </tbody> | ||
37 | + </table> | ||
38 | + </div> | ||
39 | + <!-- table-responsive --> | ||
40 | + <?php echo LinkPager::widget(['pagination' => $pagination]);?> | ||
41 | + </div> | ||
42 | + <!-- col-md-12 --> | ||
43 | +</div> | ||
44 | + | ||
45 | +<script type="text/javascript"> | ||
46 | + | ||
47 | +</script> |
@@ -7,6 +7,8 @@ use yii\helpers\ArrayHelper; | @@ -7,6 +7,8 @@ use yii\helpers\ArrayHelper; | ||
7 | /** | 7 | /** |
8 | * 有货接口 | 8 | * 有货接口 |
9 | * @author wuxiao | 9 | * @author wuxiao |
10 | + * | ||
11 | + * @文档地址 http://git.yoho.cn/yoho-documents/api-interfaces | ||
10 | */ | 12 | */ |
11 | 13 | ||
12 | class Client{ | 14 | class Client{ |
@@ -104,6 +106,21 @@ class Client{ | @@ -104,6 +106,21 @@ class Client{ | ||
104 | return $this->send($params); | 106 | return $this->send($params); |
105 | } | 107 | } |
106 | 108 | ||
109 | + /** | ||
110 | + * 根据多个优惠券id查询的接口 | ||
111 | + * @param type $couponId | ||
112 | + * @return type | ||
113 | + */ | ||
114 | + public function couponList($couponId){ | ||
115 | + $couponId = (array)$couponId; | ||
116 | + $params = [ | ||
117 | + 'client_type'=>self::client_type, | ||
118 | + 'method'=>'app.coupons.queryBroadCouponList', | ||
119 | + 'couponIds'=>implode(',',$couponId), | ||
120 | + ]; | ||
121 | + return $this->send($params); | ||
122 | + } | ||
123 | + | ||
107 | protected function send(array $params) | 124 | protected function send(array $params) |
108 | { | 125 | { |
109 | $params = $this->makeUrl($params); | 126 | $params = $this->makeUrl($params); |
@@ -176,6 +193,10 @@ class Client{ | @@ -176,6 +193,10 @@ class Client{ | ||
176 | 193 | ||
177 | self::$_rawResponse = $resultStr; | 194 | self::$_rawResponse = $resultStr; |
178 | 195 | ||
196 | + if (!$resultStr) | ||
197 | + { | ||
198 | + return $resultStr; | ||
199 | + } | ||
179 | $result = json_decode($resultStr, true); | 200 | $result = json_decode($resultStr, true); |
180 | if (!$result) | 201 | if (!$result) |
181 | { | 202 | { |
common/models/UserRedbag.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +namespace common\models; | ||
4 | + | ||
5 | +use Yii; | ||
6 | + | ||
7 | +/** | ||
8 | + * This is the model class for table "{{%user_redbag}}". | ||
9 | + * | ||
10 | + * @property string $id | ||
11 | + * @property string $user_id | ||
12 | + * @property string $room_id | ||
13 | + * @property string $coupon_id | ||
14 | + * @property integer $create_time | ||
15 | + * @property integer $update_time | ||
16 | + */ | ||
17 | +class UserRedbag extends \yii\db\ActiveRecord | ||
18 | +{ | ||
19 | + /** | ||
20 | + * @inheritdoc | ||
21 | + */ | ||
22 | + public static function tableName() | ||
23 | + { | ||
24 | + return '{{%user_redbag}}'; | ||
25 | + } | ||
26 | + | ||
27 | + /** | ||
28 | + * @inheritdoc | ||
29 | + */ | ||
30 | + public function rules() | ||
31 | + { | ||
32 | + return [ | ||
33 | + [['user_id', 'room_id', 'coupon_id', 'create_time', 'update_time'], 'integer'], | ||
34 | + [['user_id', 'room_id', 'coupon_id'], 'unique', 'targetAttribute' => ['user_id', 'room_id', 'coupon_id'], 'message' => 'The combination of 房间号, 房间号 and 优惠券ID has already been taken.'], | ||
35 | + ]; | ||
36 | + } | ||
37 | + | ||
38 | + /** | ||
39 | + * @inheritdoc | ||
40 | + */ | ||
41 | + public function attributeLabels() | ||
42 | + { | ||
43 | + return [ | ||
44 | + 'id' => 'ID', | ||
45 | + 'user_id' => '房间号', | ||
46 | + 'room_id' => '房间号', | ||
47 | + 'coupon_id' => '优惠券ID', | ||
48 | + 'create_time' => '创建时间', | ||
49 | + 'update_time' => '更新时间', | ||
50 | + ]; | ||
51 | + } | ||
52 | + | ||
53 | + public function behaviors() { | ||
54 | + return [ | ||
55 | + [ | ||
56 | + 'class' => \yii\behaviors\TimestampBehavior::className(), | ||
57 | + 'createdAtAttribute' => 'create_time', | ||
58 | + 'updatedAtAttribute' => 'update_time', | ||
59 | + ] | ||
60 | + ]; | ||
61 | + } | ||
62 | +} |
soa/controllers/v1/RedbagController.php
0 → 100644
1 | +<?php | ||
2 | +namespace soa\controllers\v1; | ||
3 | + | ||
4 | +use Yii; | ||
5 | +use soa\controllers\BaseController; | ||
6 | +use common\models\UserRedbag; | ||
7 | +/** | ||
8 | + * Site controller | ||
9 | + */ | ||
10 | +class RedbagController extends BaseController | ||
11 | +{ | ||
12 | + | ||
13 | + /** | ||
14 | + * 用户领取一个红包 | ||
15 | + * @return type | ||
16 | + */ | ||
17 | + public function actionAdd() | ||
18 | + { | ||
19 | + $user_id = $this->requests('user_id'); | ||
20 | + $room_id = $this->requests('room_id'); | ||
21 | + $coupon_id = $this->requests('coupon_id'); | ||
22 | + if (!$user_id || !$room_id || !$coupon_id){ | ||
23 | + $this->renderJson(Yii::$app->params['failed_code'],'缺少id'); | ||
24 | + } | ||
25 | + | ||
26 | + $data = [ | ||
27 | + 'user_id'=>$user_id, | ||
28 | + 'room_id'=>$room_id, | ||
29 | + 'coupon_id'=>$coupon_id, | ||
30 | + ]; | ||
31 | + $model = new UserRedbag; | ||
32 | + if ($model->load($data,'') && $model->save()){ | ||
33 | + $this->renderJson(Yii::$app->params['success_code'],'添加成功'); | ||
34 | + }else{ | ||
35 | + $this->renderJson(Yii::$app->params['failed_code'],'添加失败'); | ||
36 | + } | ||
37 | + } | ||
38 | + | ||
39 | + /** | ||
40 | + * 用户领取的红包列表 | ||
41 | + * @return type | ||
42 | + */ | ||
43 | + public function actionList() | ||
44 | + { | ||
45 | + $user_id = $this->requests('user_id'); | ||
46 | + $room_id = $this->requests('room_id'); | ||
47 | + if (!$user_id || !$room_id){ | ||
48 | + $this->renderJson(Yii::$app->params['failed_code'],'缺少id'); | ||
49 | + } | ||
50 | + | ||
51 | + $key = __CLASS__.__FUNCTION__.'user_id'.$user_id.'room_id'.$room_id; | ||
52 | + if (!$ret = $this->cache->get($key)){ | ||
53 | + | ||
54 | + $ret = UserRedbag::find() | ||
55 | + ->where(['user_id'=>$user_id,'room_id'=>$room_id]) | ||
56 | + ->orderBy(['create_time'=>SORT_DESC]) | ||
57 | + ->select('coupon_id')->asArray()->column(); | ||
58 | + | ||
59 | + $dependency = new \yii\caching\DbDependency(['sql' => Yii::$app->db | ||
60 | + ->createCommand('SELECT MAX(update_time),count(*) FROM {{%user_redbag}} WHERE user_id=:user_id AND room_id=:room_id') | ||
61 | + ->bindValue(':user_id', $user_id) | ||
62 | + ->bindValue(':room_id', $room_id) | ||
63 | + ->getRawSql()]); | ||
64 | + $this->cache->set($key, $ret, Yii::$app->params['defaultCacheExpire'], $dependency); | ||
65 | + } | ||
66 | + | ||
67 | + $this->renderJson(Yii::$app->params['success_code'],'',$ret); | ||
68 | + } | ||
69 | + | ||
70 | +} |
-
Please register or login to post a comment