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.
208 lines
5.1 KiB
208 lines
5.1 KiB
5 years ago
|
<?php
|
||
|
|
||
|
namespace frontend\controllers;
|
||
|
|
||
|
use common\libs\MyLib;
|
||
|
use common\models\ConfigT;
|
||
|
use common\models\OrderT;
|
||
|
use common\models\PhoneDayT;
|
||
|
use common\models\UserT;
|
||
|
use common\models\SysIpT;
|
||
|
use Yii;
|
||
|
use yii\helpers\ArrayHelper;
|
||
|
use yii\helpers\Json;
|
||
|
use yii\web\Cookie;
|
||
|
use yii\web\Response;
|
||
|
use yii\web\User;
|
||
|
|
||
|
class SystemController extends \yii\web\Controller
|
||
|
{
|
||
|
public $my = null;
|
||
|
public $web = null;
|
||
|
private $_STATE = 1;
|
||
|
|
||
|
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 {
|
||
|
$this->my = null;
|
||
|
}
|
||
|
|
||
|
$this->web = ConfigT::findOne(['id'=>1]);
|
||
|
}
|
||
|
|
||
|
public function actionConfig()
|
||
|
{
|
||
|
return $this->render('config');
|
||
|
}
|
||
|
|
||
|
public function actionSave()
|
||
|
{
|
||
|
Yii::$app->response->format = Response::FORMAT_JSON;
|
||
|
$request = Yii::$app->request;
|
||
|
$result = array();
|
||
|
$result['success'] = false;
|
||
|
$result['msg'] = '保存失败';
|
||
|
|
||
|
if($request->isPost) {
|
||
|
$name = $request->post('name');
|
||
|
$super_password = $request->post('super_password');
|
||
|
$max_other_money = $request->post('max_other_money');
|
||
|
$max_other_area_rate = $request->post('max_other_area_rate');
|
||
|
$max_dis_money = $request->post('max_dis_money');
|
||
|
$max_out_rate = $request->post('max_out_rate');
|
||
|
|
||
|
$tran = UserT::getDb()->beginTransaction();
|
||
|
|
||
|
try {
|
||
|
$row = $this->web;
|
||
|
$row->name = $name;
|
||
|
if($super_password != '') {
|
||
|
$row->super_salt = MyLib::randomStr(4);
|
||
|
$row->super_password = MyLib::hashPwd($super_password,$row->super_salt);
|
||
|
}
|
||
|
$row->max_other_money = $max_other_money;
|
||
|
$row->max_other_area_rate = $max_other_area_rate;
|
||
|
$row->max_dis_money = $max_dis_money;
|
||
|
$row->max_out_rate = $max_out_rate;
|
||
|
$row->save();
|
||
|
|
||
|
$tran->commit();
|
||
|
} catch(\Exception $e) {
|
||
|
$tran->rollBack();
|
||
|
throw $e;
|
||
|
}
|
||
|
|
||
|
$result['success'] = true;
|
||
|
$result['msg'] = '保存成功';
|
||
|
}
|
||
|
return $result;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* IP管理
|
||
|
* IP动态管理功能
|
||
|
* @param 参数
|
||
|
* @return 返回类型
|
||
|
* @author liukangle
|
||
|
*
|
||
|
*/
|
||
|
public function actionIp(){
|
||
|
|
||
|
$request = Yii::$app->request;
|
||
|
$name = $request->get('name');
|
||
|
$ips = SysIpT::find();
|
||
|
if($name != ''){
|
||
|
$ips = $ips->andWhere(['like','city_name',$name]);
|
||
|
}
|
||
|
$ips = $ips->andWhere('status ='.$this->_STATE);
|
||
|
$data = $ips->orderBy('id ASC')->all();
|
||
|
|
||
|
return $this->render('ip',[
|
||
|
'info' => $data,
|
||
|
'name' => $name,
|
||
|
]);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 修改,添加页面
|
||
|
* 修改,添加
|
||
|
* @param id int
|
||
|
* @return 返回类型
|
||
|
* @author liukangle
|
||
|
*
|
||
|
*/
|
||
|
public function actionEdit()
|
||
|
{
|
||
|
|
||
|
$request = Yii::$app->request;
|
||
|
$id = $request->get('id');
|
||
|
if($id > 0) {
|
||
|
$info = SysIpT::findOne(['id'=>$id]);
|
||
|
} else {
|
||
|
$info = new SysIpT();
|
||
|
}
|
||
|
return $this->render('edit',[
|
||
|
'info' => $info,
|
||
|
]);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 修改保存添加
|
||
|
* 功能
|
||
|
* @param 参数
|
||
|
* @return 返回类型
|
||
|
* @author liukangle
|
||
|
*
|
||
|
*/
|
||
|
public function actionIpSave()
|
||
|
{
|
||
|
Yii::$app->response->format = Response::FORMAT_JSON;
|
||
|
$request = Yii::$app->request;
|
||
|
|
||
|
$result = array();
|
||
|
$result['success'] = false;
|
||
|
$result['msg'] = '保存失败';
|
||
|
|
||
|
if($request->isPost){
|
||
|
|
||
|
$data = $request->post();
|
||
|
if($data['id'] > 0) {
|
||
|
$row = SysIpT::findOne(['id'=>$data['id']]);
|
||
|
} else {
|
||
|
$row = new SysIpT();
|
||
|
}
|
||
|
$row->attributes = $data;
|
||
|
if(!$row->validate()){
|
||
|
$result['msg'] = current(current($row->errors)).'!';
|
||
|
return $result;
|
||
|
}
|
||
|
$row->save();
|
||
|
|
||
|
$result['success'] = true;
|
||
|
$result['msg'] = '保存成功';
|
||
|
}
|
||
|
|
||
|
return $result;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 删除
|
||
|
* ip删除
|
||
|
* @param 参数
|
||
|
* @return 返回类型
|
||
|
* @author liukangle
|
||
|
*
|
||
|
*/
|
||
|
public function actionDel()
|
||
|
{
|
||
|
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');
|
||
|
if($id > 0){
|
||
|
$row = SysIpT::findOne(['id'=>$id]);
|
||
|
$row->status = 0;
|
||
|
$row->save();
|
||
|
|
||
|
$result['success'] = true;
|
||
|
$result['msg'] = '保存成功';
|
||
|
}
|
||
|
|
||
|
return $result;
|
||
|
}
|
||
|
}
|
||
|
}
|