|
|
<?php
|
|
|
namespace backend\controllers;
|
|
|
|
|
|
use Yii;
|
|
|
use backend\components\Pagination;
|
|
|
use yii\helpers\ArrayHelper;
|
|
|
use common\lib\YohoApi\Client as YohoApiClient;
|
|
|
|
|
|
/**
|
|
|
* 红包
|
|
|
*/
|
|
|
class RedbagController extends BaseController
|
|
|
{
|
|
|
|
|
|
public function init()
|
|
|
{
|
|
|
parent::init();
|
|
|
|
|
|
$this->main_id = 'live';
|
|
|
$this->sub_id = 'room';
|
|
|
$this->sub_title = '红包管理';
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 房间优惠券列表
|
|
|
* @return type
|
|
|
*/
|
|
|
public function actionList()
|
|
|
{
|
|
|
if (!$room_id = Yii::$app->getRequest()->getQueryParam('id')){
|
|
|
return $this->redirect($this->_refer);
|
|
|
}
|
|
|
|
|
|
$model = \app\models\RoomRedbag::find()->where(['room_id'=>$room_id]);
|
|
|
|
|
|
$count = clone $model;
|
|
|
$pagination = new Pagination(['totalCount' =>$count->count()]);
|
|
|
$list = $model
|
|
|
->offset($pagination->offset)->limit($pagination->limit)
|
|
|
->orderBy(['create_time'=>SORT_DESC])
|
|
|
->indexBy('coupon_id')
|
|
|
->all();
|
|
|
|
|
|
/**
|
|
|
* 获取有货商品信息
|
|
|
*/
|
|
|
$couponId = [];
|
|
|
foreach ($list as $model){
|
|
|
$couponId[] = $model->coupon_id;
|
|
|
}
|
|
|
//if ($couponId){
|
|
|
if (false){
|
|
|
var_dump(YohoApiClient::self()->couponList([14366,14368]));exit;
|
|
|
$ret = YohoApiClient::self()->couponList($couponId);
|
|
|
if (empty($ret['product_list'])){
|
|
|
array_shift($productSkn);
|
|
|
$ret = YohoApiClient::self()->h5ProductBatch($productSkn);
|
|
|
}
|
|
|
|
|
|
//var_dump(YohoApiClient::self()->h5ProductBatch([51188407,51188408,51188414,51188421,51188468]));
|
|
|
//var_dump(YohoApiClient::getRequestUrl());
|
|
|
|
|
|
if (!empty($ret['product_list'])){
|
|
|
foreach ($ret['product_list'] as $product){
|
|
|
if (!empty($list[$product['product_skn']])){
|
|
|
$list[$product['product_skn']]->setAttributes([
|
|
|
'product_name' => $product['product_name'],
|
|
|
'sales_price' => $product['sales_price'],
|
|
|
]);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return $this->render('list',[
|
|
|
'room'=> \app\models\Room::findOne(['room_id'=>$room_id]),
|
|
|
'pagination'=>$pagination,
|
|
|
'list'=>$list,
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 添加商品
|
|
|
* @return type
|
|
|
*/
|
|
|
public function actionAdd()
|
|
|
{
|
|
|
if (!$room_id = Yii::$app->getRequest()->getQueryParam('id')){
|
|
|
return $this->redirect($this->_refer);
|
|
|
}
|
|
|
|
|
|
$model = new \app\models\RoomRedbag;
|
|
|
if (Yii::$app->getRequest()->isPost){
|
|
|
$post = Yii::$app->getRequest()->post();
|
|
|
$model->room_id = $room_id;
|
|
|
if ($model->load($post,'') && $model->save()){
|
|
|
Yii::$app->session->setFlash('success', '创建成功。');
|
|
|
return $this->redirect($this->_refer);
|
|
|
}else{
|
|
|
Yii::$app->session->setFlash('warning', current($model->getFirstErrors()));
|
|
|
$model->setAttributes($post);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
$masters = \app\models\Master::getId2name();
|
|
|
$types = [''=>'0 无主播']+$masters;
|
|
|
|
|
|
return $this->render('edit',[
|
|
|
'model'=>$model,
|
|
|
'types'=>$types,
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 编辑商品
|
|
|
* @return type
|
|
|
*/
|
|
|
public function actionEdit()
|
|
|
{
|
|
|
if (!$id = Yii::$app->getRequest()->getQueryParam('id')){
|
|
|
return $this->redirect($this->_refer);
|
|
|
}
|
|
|
|
|
|
if (!$model = \app\models\RoomRedbag::findOne($id)){
|
|
|
Yii::$app->session->setFlash('error', '找不到该红包');
|
|
|
return $this->redirect($this->_refer);
|
|
|
}
|
|
|
|
|
|
if (Yii::$app->getRequest()->isPost){
|
|
|
$post = Yii::$app->getRequest()->post();
|
|
|
if ($model->load($post,'') && $model->save()){
|
|
|
Yii::$app->session->setFlash('success', '编辑成功。');
|
|
|
return $this->redirect($this->_refer);
|
|
|
}else{
|
|
|
Yii::$app->session->setFlash('warning', current($model->getFirstErrors()));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
$masters = \app\models\Master::getId2name();
|
|
|
$types = [''=>'0 无主播']+$masters;
|
|
|
|
|
|
return $this->render('edit',[
|
|
|
'model'=>$model,
|
|
|
'types'=>$types,
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 商品操作
|
|
|
* @return type
|
|
|
*/
|
|
|
public function actionOperate()
|
|
|
{
|
|
|
if (!$id = Yii::$app->getRequest()->getQueryParam('id')){
|
|
|
return $this->redirect($this->_refer);
|
|
|
}
|
|
|
if (!$type = Yii::$app->getRequest()->getQueryParam('type')){
|
|
|
return $this->redirect($this->_refer);
|
|
|
}
|
|
|
|
|
|
if (!$model = \app\models\RoomRedbag::findOne($id)){
|
|
|
Yii::$app->session->setFlash('error', '找不到该红包');
|
|
|
return $this->redirect($this->_refer);
|
|
|
}
|
|
|
|
|
|
switch ($type){
|
|
|
case 'del'://删除
|
|
|
$r = $model->delete();
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
if (!empty($r)){
|
|
|
Yii::$app->session->setFlash('success', '操作成功');
|
|
|
}else{
|
|
|
Yii::$app->session->setFlash('error', '操作失败');
|
|
|
}
|
|
|
|
|
|
return $this->redirect($this->_refer);
|
|
|
}
|
|
|
} |
...
|
...
|
|