You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
142 lines
3.7 KiB
142 lines
3.7 KiB
5 years ago
|
<?php
|
||
|
|
||
|
namespace frontend\controllers;
|
||
|
|
||
|
use common\libs\MyLib;
|
||
|
use common\models\GiftGroupT;
|
||
|
use common\models\GiftType2T;
|
||
|
use common\models\GiftType3T;
|
||
|
use common\models\GiftTypeT;
|
||
|
use common\models\UserT;
|
||
|
use Yii;
|
||
|
use yii\web\Response;
|
||
|
|
||
|
class GiftGroupController extends \yii\web\Controller
|
||
|
{
|
||
|
public $my = null;
|
||
|
|
||
|
public function init()
|
||
|
{
|
||
|
parent::init();
|
||
|
|
||
|
$cookie = Yii::$app->request->cookies;
|
||
|
$user_id = MyLib::encrypt($cookie->get('aid'),'DECODE');
|
||
|
|
||
|
if($user_id != 0)
|
||
|
{
|
||
|
$this->my = UserT::findOne(['id'=>$user_id]);
|
||
|
} else {
|
||
|
Yii::$app->response->redirect('/common/login')->send();
|
||
|
exit;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public function actionIndex()
|
||
|
{
|
||
|
$request = Yii::$app->request;
|
||
|
$name = $request->get('name');
|
||
|
|
||
|
$query = GiftGroupT::find()
|
||
|
->orderBy('id ASC')
|
||
|
->where('id>0');
|
||
|
if($name != '') {
|
||
|
$query = $query->andWhere('name like "'.$name.'%"');
|
||
|
}
|
||
|
$total = $query->count();
|
||
|
|
||
|
$items = $query->all();
|
||
|
|
||
|
return $this->render('index',[
|
||
|
'items' => $items,
|
||
|
'name' => $name
|
||
|
]);
|
||
|
}
|
||
|
|
||
|
public function actionEdit()
|
||
|
{
|
||
|
$request = Yii::$app->request;
|
||
|
$id = $request->get('id',0);
|
||
|
$info = GiftGroupT::findOne(['id'=>$id]);
|
||
|
if(!$info)
|
||
|
$info = new GiftGroupT();
|
||
|
$gifts = $info->gifts;
|
||
|
$gift_ids = array();
|
||
|
if($gifts) {
|
||
|
foreach($gifts as $gift) {
|
||
|
$gift_ids[] = $gift->id;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$gift_items = GiftType3T::find()->all();
|
||
|
|
||
|
return $this->render('edit',[
|
||
|
'info'=>$info,
|
||
|
'gift_ids'=>$gift_ids,
|
||
|
'gift_items'=>$gift_items
|
||
|
]);
|
||
|
}
|
||
|
|
||
|
public function actionSave() {
|
||
|
Yii::$app->response->format = Response::FORMAT_JSON;
|
||
|
$request = Yii::$app->request;
|
||
|
$result = array();
|
||
|
if($request->isPost) {
|
||
|
$id = intval($request->post('id'));
|
||
|
$name = $request->post('name');
|
||
|
$is_free = $request->post('is_free',0);
|
||
|
$is_damage = $request->post('is_damage',0);
|
||
|
$gift_ids = $request->post('gift_ids');
|
||
|
$gift_str = join(',',$gift_ids);
|
||
|
$min_money = $request->post('min_money');
|
||
|
$max_money = $request->post('max_money');
|
||
|
$group_ids = $request->post('group_ids');
|
||
|
|
||
|
$row = null;
|
||
|
if($id > 0) {
|
||
|
$row = GiftGroupT::findOne(['id'=>$id]);
|
||
|
} else {
|
||
|
$row = new GiftGroupT();
|
||
|
}
|
||
|
$row->name = $name;
|
||
|
$row->is_free = $is_free;
|
||
|
$row->is_damage = $is_damage;
|
||
|
$row->gift_ids = $gift_str;
|
||
|
$row->min_money = $min_money;
|
||
|
$row->max_money = $max_money;
|
||
|
$row->group_ids = $group_ids;
|
||
|
if(!$row->save()) {
|
||
|
var_dump($row->errors);
|
||
|
}
|
||
|
|
||
|
$result['success'] = true;
|
||
|
$result['msg'] = '操作成功';
|
||
|
return $result;
|
||
|
}
|
||
|
$result['success'] = false;
|
||
|
$reuslt['msg'] = '操作失败';
|
||
|
return $result;
|
||
|
}
|
||
|
|
||
|
public function actionDelete()
|
||
|
{
|
||
|
Yii::$app->response->format = Response::FORMAT_JSON;
|
||
|
$request = Yii::$app->request;
|
||
|
$result = array();
|
||
|
$result['success'] = false;
|
||
|
$result['msg'] = '删除失败';
|
||
|
|
||
|
if($request->isPost) {
|
||
|
$id = $request->post('id',0);
|
||
|
|
||
|
if($id > 0) {
|
||
|
$row = GiftGroupT::findOne(['id'=>$id]);
|
||
|
$row->delete();
|
||
|
|
||
|
$result['success'] = true;
|
||
|
$result['msg'] = '删除成功';
|
||
|
}
|
||
|
}
|
||
|
return $result;
|
||
|
}
|
||
|
}
|