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.
simple-yewu/frontend/controllers/SystemController.php

235 lines
5.8 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;
5 years ago
public $enableCsrfValidation = false;
public $layout = 'blue-main';
5 years ago
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
*
*/
5 years ago
public function actionIp() {
return $this->render('ip');
}
5 years ago
5 years ago
public function actionIpJson(){
Yii::$app->response->format = Response::FORMAT_JSON;
5 years ago
$request = Yii::$app->request;
5 years ago
$ips = SysIpT::find()->orderBy('id ASC');
$total = $ips->count();
$items = $ips->all();
$data = [];
$data['total'] = $total;
$data['rows'] = [];
foreach($items as $item) {
$row = $item->toArray();
$data['rows'][] = $row;
5 years ago
}
5 years ago
return $data;
5 years ago
}
/**
* 修改,添加页面
* 修改,添加
* @param id int
* @return 返回类型
* @author liukangle
*
*/
5 years ago
public function actionIpEdit()
5 years ago
{
$request = Yii::$app->request;
$id = $request->get('id');
if($id > 0) {
$info = SysIpT::findOne(['id'=>$id]);
} else {
$info = new SysIpT();
}
5 years ago
return $this->render('ip-edit',[
5 years ago
'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
*
*/
5 years ago
public function actionIpDelete()
5 years ago
{
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]);
5 years ago
if($row) {
$row->delete();
}
5 years ago
$result['success'] = true;
5 years ago
$result['msg'] = '删除成功';
5 years ago
}
return $result;
}
}
5 years ago
public function actionTest() {
$items = OrderT::find()
->where('status_id=10')
->all();
5 years ago
foreach($items as $item) {
$car_info = $item->car;
if(!$car_info) {
echo 'error';
break;
}
5 years ago
$car_info->op1_id = $item->user_id;
if(!$car_info->save()) {
print_r($car_info->getErrors());
break;
}
5 years ago
}
5 years ago
return count($items);
5 years ago
}
5 years ago
}