Showing
9 changed files
with
592 additions
and
20 deletions
@@ -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; |
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 | + | ||
9 | +/** | ||
10 | + * 红包 | ||
11 | + */ | ||
12 | +class RedbagController extends BaseController | ||
13 | +{ | ||
14 | + | ||
15 | + public function init() | ||
16 | + { | ||
17 | + parent::init(); | ||
18 | + | ||
19 | + $this->main_id = 'live'; | ||
20 | + $this->sub_id = 'room'; | ||
21 | + $this->sub_title = '红包管理'; | ||
22 | + } | ||
23 | + | ||
24 | + /** | ||
25 | + * 房间优惠券列表 | ||
26 | + * @return type | ||
27 | + */ | ||
28 | + public function actionList() | ||
29 | + { | ||
30 | + if (!$room_id = Yii::$app->getRequest()->getQueryParam('id')){ | ||
31 | + return $this->redirect($this->_refer); | ||
32 | + } | ||
33 | + | ||
34 | + $model = \app\models\RoomRedbag::find()->where(['room_id'=>$room_id]); | ||
35 | + | ||
36 | + $count = clone $model; | ||
37 | + $pagination = new Pagination(['totalCount' =>$count->count()]); | ||
38 | + $list = $model | ||
39 | + ->offset($pagination->offset)->limit($pagination->limit) | ||
40 | + ->orderBy(['create_time'=>SORT_DESC]) | ||
41 | + ->indexBy('coupon_id') | ||
42 | + ->all(); | ||
43 | + | ||
44 | + /** | ||
45 | + * 获取有货商品信息 | ||
46 | + */ | ||
47 | + $couponId = []; | ||
48 | + foreach ($list as $model){ | ||
49 | + $couponId[] = $model->coupon_id; | ||
50 | + } | ||
51 | + //if ($couponId){ | ||
52 | + if (false){ | ||
53 | + var_dump(YohoApiClient::self()->couponList([14366,14368]));exit; | ||
54 | + $ret = YohoApiClient::self()->couponList($couponId); | ||
55 | + if (empty($ret['product_list'])){ | ||
56 | + array_shift($productSkn); | ||
57 | + $ret = YohoApiClient::self()->h5ProductBatch($productSkn); | ||
58 | + } | ||
59 | + | ||
60 | + //var_dump(YohoApiClient::self()->h5ProductBatch([51188407,51188408,51188414,51188421,51188468])); | ||
61 | + //var_dump(YohoApiClient::getRequestUrl()); | ||
62 | + | ||
63 | + if (!empty($ret['product_list'])){ | ||
64 | + foreach ($ret['product_list'] as $product){ | ||
65 | + if (!empty($list[$product['product_skn']])){ | ||
66 | + $list[$product['product_skn']]->setAttributes([ | ||
67 | + 'product_name' => $product['product_name'], | ||
68 | + 'sales_price' => $product['sales_price'], | ||
69 | + ]); | ||
70 | + } | ||
71 | + } | ||
72 | + } | ||
73 | + } | ||
74 | + | ||
75 | + return $this->render('list',[ | ||
76 | + 'room'=> \app\models\Room::findOne(['room_id'=>$room_id]), | ||
77 | + 'pagination'=>$pagination, | ||
78 | + 'list'=>$list, | ||
79 | + ]); | ||
80 | + } | ||
81 | + | ||
82 | + /** | ||
83 | + * 添加商品 | ||
84 | + * @return type | ||
85 | + */ | ||
86 | + public function actionAdd() | ||
87 | + { | ||
88 | + if (!$room_id = Yii::$app->getRequest()->getQueryParam('id')){ | ||
89 | + return $this->redirect($this->_refer); | ||
90 | + } | ||
91 | + | ||
92 | + $model = new \app\models\RoomRedbag; | ||
93 | + if (Yii::$app->getRequest()->isPost){ | ||
94 | + $post = Yii::$app->getRequest()->post(); | ||
95 | + $model->room_id = $room_id; | ||
96 | + if ($model->load($post,'') && $model->save()){ | ||
97 | + Yii::$app->session->setFlash('success', '创建成功。'); | ||
98 | + return $this->redirect($this->_refer); | ||
99 | + }else{ | ||
100 | + Yii::$app->session->setFlash('warning', current($model->getFirstErrors())); | ||
101 | + $model->setAttributes($post); | ||
102 | + } | ||
103 | + } | ||
104 | + | ||
105 | + $masters = \app\models\Master::getId2name(); | ||
106 | + $types = [''=>'0 无主播']+$masters; | ||
107 | + | ||
108 | + return $this->render('edit',[ | ||
109 | + 'model'=>$model, | ||
110 | + 'types'=>$types, | ||
111 | + ]); | ||
112 | + } | ||
113 | + | ||
114 | + /** | ||
115 | + * 编辑商品 | ||
116 | + * @return type | ||
117 | + */ | ||
118 | + public function actionEdit() | ||
119 | + { | ||
120 | + if (!$id = Yii::$app->getRequest()->getQueryParam('id')){ | ||
121 | + return $this->redirect($this->_refer); | ||
122 | + } | ||
123 | + | ||
124 | + if (!$model = \app\models\RoomRedbag::findOne($id)){ | ||
125 | + Yii::$app->session->setFlash('error', '找不到该红包'); | ||
126 | + return $this->redirect($this->_refer); | ||
127 | + } | ||
128 | + | ||
129 | + if (Yii::$app->getRequest()->isPost){ | ||
130 | + $post = Yii::$app->getRequest()->post(); | ||
131 | + if ($model->load($post,'') && $model->save()){ | ||
132 | + Yii::$app->session->setFlash('success', '编辑成功。'); | ||
133 | + return $this->redirect($this->_refer); | ||
134 | + }else{ | ||
135 | + Yii::$app->session->setFlash('warning', current($model->getFirstErrors())); | ||
136 | + } | ||
137 | + } | ||
138 | + | ||
139 | + $masters = \app\models\Master::getId2name(); | ||
140 | + $types = [''=>'0 无主播']+$masters; | ||
141 | + | ||
142 | + return $this->render('edit',[ | ||
143 | + 'model'=>$model, | ||
144 | + 'types'=>$types, | ||
145 | + ]); | ||
146 | + } | ||
147 | + | ||
148 | + /** | ||
149 | + * 商品操作 | ||
150 | + * @return type | ||
151 | + */ | ||
152 | + public function actionOperate() | ||
153 | + { | ||
154 | + if (!$id = Yii::$app->getRequest()->getQueryParam('id')){ | ||
155 | + return $this->redirect($this->_refer); | ||
156 | + } | ||
157 | + if (!$type = Yii::$app->getRequest()->getQueryParam('type')){ | ||
158 | + return $this->redirect($this->_refer); | ||
159 | + } | ||
160 | + | ||
161 | + if (!$model = \app\models\RoomRedbag::findOne($id)){ | ||
162 | + Yii::$app->session->setFlash('error', '找不到该红包'); | ||
163 | + return $this->redirect($this->_refer); | ||
164 | + } | ||
165 | + | ||
166 | + switch ($type){ | ||
167 | + case 'del'://删除 | ||
168 | + $r = $model->delete(); | ||
169 | + break; | ||
170 | + default: | ||
171 | + break; | ||
172 | + } | ||
173 | + if (!empty($r)){ | ||
174 | + Yii::$app->session->setFlash('success', '操作成功'); | ||
175 | + }else{ | ||
176 | + Yii::$app->session->setFlash('error', '操作失败'); | ||
177 | + } | ||
178 | + | ||
179 | + return $this->redirect($this->_refer); | ||
180 | + } | ||
181 | +} |
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', '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' => '红包类型', | ||
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 | +} |
@@ -112,28 +112,34 @@ $this->registerJs($this->blocks['javascript'],View::POS_END) | @@ -112,28 +112,34 @@ $this->registerJs($this->blocks['javascript'],View::POS_END) | ||
112 | </td> | 112 | </td> |
113 | <td> | 113 | <td> |
114 | 114 | ||
115 | - <span> | ||
116 | - <?php if ($model->living == 1)://直播中?> | ||
117 | - <button type="button" onclick="stopLiving(<?=$model->room_id?>)" class="btn btn-danger btn-metro">结束直播</button> | ||
118 | - <?php else:?> | ||
119 | - <a onclick="return confirm('将房间设为直播中状态,确定?')" href="/live/roomoperate/<?=$model->id?>?type=start" class="btn btn-success btn-metro">开始直播</a> | ||
120 | - <?php endif;?> | ||
121 | - </span> | ||
122 | - | ||
123 | - <a href="/live/roomedit/<?=$model->id?>" class="btn btn-default btn-white">编辑</a> | 115 | + <p> |
116 | + <span> | ||
117 | + <?php if ($model->living == 1)://直播中?> | ||
118 | + <button type="button" onclick="stopLiving(<?=$model->room_id?>)" class="btn btn-danger btn-metro">结束直播</button> | ||
119 | + <?php else:?> | ||
120 | + <a onclick="return confirm('将房间设为直播中状态,确定?')" href="/live/roomoperate/<?=$model->id?>?type=start" class="btn btn-success btn-metro">开始直播</a> | ||
121 | + <?php endif;?> | ||
122 | + </span> | ||
123 | + | ||
124 | + <a href="/live/roomedit/<?=$model->id?>" class="btn btn-default btn-white">编辑</a> | ||
124 | 125 | ||
125 | - <a href="/forbidden/index?room_id=<?=$model->room_id?>" class="btn btn-default btn-white">禁言</a> | 126 | + <span> |
127 | + <?php if ($model->status == 0)://关闭状态?> | ||
128 | + <a onclick="return confirm('启用直播间?')" href="/live/roomoperate/<?=$model->id?>?type=enable" class="btn btn-success btn-metro">启用直播</a> | ||
129 | + <a onclick="return confirm('删除直播间?')" href="/live/roomoperate/<?=$model->id?>?type=del" class="btn btn-danger btn-metro">删除</a> | ||
130 | + <?php else:?> | ||
131 | + <a onclick="return confirm('禁用直播间?')" href="/live/roomoperate/<?=$model->id?>?type=disable" class="btn btn-danger btn-metro">禁用直播</a> | ||
132 | + <?php endif;?> | ||
133 | + </span> | ||
134 | + </p> | ||
126 | 135 | ||
127 | - <a href="/product/list/<?=$model->room_id?>" class="btn btn-default btn-white">商品</a> | ||
128 | - | ||
129 | - <span> | ||
130 | - <?php if ($model->status == 0)://关闭状态?> | ||
131 | - <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=del" class="btn btn-danger btn-metro">删除</a> | ||
133 | - <?php else:?> | ||
134 | - <a onclick="return confirm('禁用直播间?')" href="/live/roomoperate/<?=$model->id?>?type=disable" class="btn btn-danger btn-metro">禁用直播</a> | ||
135 | - <?php endif;?> | ||
136 | - </span> | 136 | + <p> |
137 | + <a href="/forbidden/index?room_id=<?=$model->room_id?>" class="btn btn-default btn-white">禁言</a> | ||
138 | + | ||
139 | + <a href="/product/list/<?=$model->room_id?>" class="btn btn-default btn-white">商品</a> | ||
140 | + | ||
141 | + <a href="/redbag/list/<?=$model->room_id?>" class="btn btn-default btn-white">红包</a> | ||
142 | + </p> | ||
137 | </td> | 143 | </td> |
138 | </tr> | 144 | </tr> |
139 | <?php endforeach;?> | 145 | <?php endforeach;?> |
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', $model->type,$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 | + | ||
9 | +<?php echo $this->render('@app/views/layouts/websocket');?> | ||
10 | + | ||
11 | +<script type="text/javascript"> | ||
12 | +<?php $this->beginBlock('javascript');?> | ||
13 | +var i = 0; | ||
14 | +var room_id = <?=$room->room_id?>; | ||
15 | +var interval_handle; | ||
16 | +var default_interval = 3; | ||
17 | + | ||
18 | +/** | ||
19 | + * 监听推送记录 | ||
20 | + * @param {type} package | ||
21 | + * @returns {unresolved} | ||
22 | + */ | ||
23 | +function getPushlog(interval){ | ||
24 | + clearInterval(interval_handle); | ||
25 | + | ||
26 | + if (interval){ | ||
27 | + interval_handle = setInterval(function(){ | ||
28 | + $.get('/ajax/pushgoodslog','',function(json){ | ||
29 | + console.log(json); | ||
30 | + if (json.data){ | ||
31 | + consoleLog('监听到推送记录: '+json.data); | ||
32 | + } | ||
33 | + },'json'); | ||
34 | + },interval*1000); | ||
35 | + $('#pushlog').text('推送记录监听中...再次点击停止').attr('onclick','getPushlog(false)'); | ||
36 | + }else{ | ||
37 | + $('#pushlog').text('开始监听推送记录').attr('onclick','getPushlog('+default_interval+')'); | ||
38 | + } | ||
39 | +} | ||
40 | +<?php | ||
41 | +$this->endBlock(); | ||
42 | +$this->registerJs($this->blocks['javascript'],View::POS_END) | ||
43 | +?> | ||
44 | +</script> | ||
45 | + | ||
46 | +<div class="panel"> | ||
47 | + <div class="panel-body"> | ||
48 | + <h4>房间号:<?=$room->room_id?> 直播标题:<?=$room->title?> 直播状态:<?=Yii::$app->params['config']['room_living'][$room->living]?></h4> | ||
49 | + </div> | ||
50 | +</div> | ||
51 | + | ||
52 | +<div class="form-group"> | ||
53 | + <label> | ||
54 | + <a href="/redbag/add/<?=$room->room_id?>" class="btn btn-primary">+ 添加红包</a> | ||
55 | + <button type="button" onclick="refreshProduct()" class="btn btn-primary" style="margin-left:200px">发红包</button> | ||
56 | + </label> | ||
57 | +</div> | ||
58 | + | ||
59 | +<div class="row"> | ||
60 | + <div class="col-md-12"> | ||
61 | + <div class="table-responsive"> | ||
62 | + <table class="table mb30"> | ||
63 | + <thead> | ||
64 | + <tr style="white-space:nowrap"> | ||
65 | + <th><input type="checkbox" onclick="checkall(this)">选择</th> | ||
66 | + <th>优惠券ID</th> | ||
67 | + <th>优惠券名称</th> | ||
68 | + <th>优惠券剩余库存</th> | ||
69 | + <th>优惠券生效时间</th> | ||
70 | + <th>优惠券失效时间</th> | ||
71 | + <th>操作</th> | ||
72 | + </tr> | ||
73 | + </thead> | ||
74 | + <tbody> | ||
75 | + <?php foreach ($list as $model):?> | ||
76 | + <tr data-stock="1" data-source="1" data-status="2" data-id="5011880"> | ||
77 | + <td><input type="checkbox" value="<?=$model->id?>" name="product[]"></td> | ||
78 | + <td><?=$model->coupon_id?></td> | ||
79 | + <th><?=$model->coupon_name?></th> | ||
80 | + <td><?=$model->stock?></td> | ||
81 | + <td><?=$model->effect_time?></td> | ||
82 | + <td><?=$model->invalid_time?></td> | ||
83 | + <td> | ||
84 | + | ||
85 | + <a href="/redbag/edit/<?=$model->id?>" class="btn btn-default btn-white">编辑</a> | ||
86 | + | ||
87 | + <a onclick="return confirm('删除该红包?')" href="/redbag/operate/<?=$model->id?>?type=del" class="btn btn-danger btn-metro">删除</a> | ||
88 | + | ||
89 | + </td> | ||
90 | + </tr> | ||
91 | + <?php endforeach;?> | ||
92 | + </tbody> | ||
93 | + </table> | ||
94 | + </div> | ||
95 | + <!-- table-responsive --> | ||
96 | + <?php echo LinkPager::widget(['pagination' => $pagination]);?> | ||
97 | + </div> | ||
98 | + <!-- col-md-12 --> | ||
99 | +</div> | ||
100 | + | ||
101 | +<div class="form-group"> | ||
102 | + <label> | ||
103 | + <button type="button" onclick="getPushlog(default_interval)" id="pushlog" class="btn btn-primary">开始监听推送记录</button> | ||
104 | + </label> | ||
105 | +</div> | ||
106 | + | ||
107 | +<div class="form-group"> | ||
108 | + <div class="col-sm-6" id="wsRuntime"> | ||
109 | + </div> | ||
110 | +</div><!-- form-group --> |
@@ -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,22 @@ class Client{ | @@ -104,6 +106,22 @@ 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 | + $url = 'http://192.168.102.210:8088/platform/coupon/queryBroadCouponList'; | ||
117 | + $params = [ | ||
118 | + 'client_type'=>self::client_type, | ||
119 | + 'couponIds'=>implode(',',$couponId), | ||
120 | + ]; | ||
121 | + $params = $this->makeUrl($params); | ||
122 | + return $this->_sendRequest($url,$params); | ||
123 | + } | ||
124 | + | ||
107 | protected function send(array $params) | 125 | protected function send(array $params) |
108 | { | 126 | { |
109 | $params = $this->makeUrl($params); | 127 | $params = $this->makeUrl($params); |
@@ -176,6 +194,10 @@ class Client{ | @@ -176,6 +194,10 @@ class Client{ | ||
176 | 194 | ||
177 | self::$_rawResponse = $resultStr; | 195 | self::$_rawResponse = $resultStr; |
178 | 196 | ||
197 | + if (!$resultStr) | ||
198 | + { | ||
199 | + return $resultStr; | ||
200 | + } | ||
179 | $result = json_decode($resultStr, true); | 201 | $result = json_decode($resultStr, true); |
180 | if (!$result) | 202 | if (!$result) |
181 | { | 203 | { |
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 | +} |
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 | + if (!$user_id || !$room_id){ | ||
22 | + $this->renderJson(Yii::$app->params['failed_code'],'缺少id'); | ||
23 | + } | ||
24 | + | ||
25 | + $data = [ | ||
26 | + 'user_id'=>$user_id, | ||
27 | + 'room_id'=>$room_id, | ||
28 | + 'coupon_id'=>$coupon_id, | ||
29 | + ]; | ||
30 | + $model = new UserRedbag; | ||
31 | + if ($model->load($data,'') && $model->save()){ | ||
32 | + $this->renderJson(Yii::$app->params['success_code'],'',$ret); | ||
33 | + }else{ | ||
34 | + $this->renderJson(Yii::$app->params['failed_code']); | ||
35 | + } | ||
36 | + } | ||
37 | + | ||
38 | + /** | ||
39 | + * 用户领取的红包列表 | ||
40 | + * @return type | ||
41 | + */ | ||
42 | + public function actionList() | ||
43 | + { | ||
44 | + $user_id = $this->requests('user_id'); | ||
45 | + $room_id = $this->requests('room_id'); | ||
46 | + if (!$user_id || !$room_id){ | ||
47 | + $this->renderJson(Yii::$app->params['failed_code'],'缺少id'); | ||
48 | + } | ||
49 | + | ||
50 | + $key = __CLASS__.__FUNCTION__.'user_id'.$user_id.'room_id'.$room_id; | ||
51 | + if (!$ret = $this->cache->get($key)){ | ||
52 | + | ||
53 | + $ret = UserRedbag::find() | ||
54 | + ->where(['user_id'=>$user_id,'room_id'=>$room_id]) | ||
55 | + ->orderBy(['create_time'=>SORT_DESC]) | ||
56 | + ->select('coupon_id')->asArray()->column(); | ||
57 | + | ||
58 | + $dependency = new \yii\caching\DbDependency(['sql' => Yii::$app->db | ||
59 | + ->createCommand('SELECT MAX(update_time),count(*) FROM {{%user_redbag}} WHERE user_id=:user_id AND room_id=:room_id') | ||
60 | + ->bindValue(':user_id', $user_id) | ||
61 | + ->bindValue(':room_id', $room_id) | ||
62 | + ->getRawSql()]); | ||
63 | + $this->cache->set($key, $ret, Yii::$app->params['defaultCacheExpire'], $dependency); | ||
64 | + } | ||
65 | + | ||
66 | + $this->renderJson(Yii::$app->params['success_code'],'',$ret); | ||
67 | + } | ||
68 | + | ||
69 | +} |
-
Please register or login to post a comment