ADD:添加后台文章、通知等管理端接口;
FIX:修正若干已知错误;
This commit is contained in:
@@ -66,3 +66,4 @@ private.html
|
||||
/assets/
|
||||
/admins/web/assets/
|
||||
/logs/
|
||||
/admins/runtime/
|
||||
|
||||
@@ -133,7 +133,7 @@ class NewsController extends Common{
|
||||
}
|
||||
}
|
||||
|
||||
$cols = ['orderby'=>'orderby','deleted'=>'deleted','cid'=>'cid','liked'=>'liked','reading'=>'reading','viewed'=>'viewed'];
|
||||
$cols = ['order_by'=>'order_by','deleted'=>'deleted','cid'=>'cid','liked'=>'liked','reading'=>'reading','viewed'=>'viewed'];
|
||||
foreach($cols as $col=>$key){
|
||||
if(isset($post[$key])){
|
||||
$data[$col] = (int)$post[$key];
|
||||
|
||||
@@ -89,7 +89,7 @@ class Common extends Controller
|
||||
|
||||
public function fansToken($user = [], $refresh = FALSE, $expire = NULL)
|
||||
{
|
||||
//生成token(用户数据,是否强制更新,过期时间 // TBD 具体方法有待优化
|
||||
//生成token(用户数据,是否强制更新,过期时间 // TBD 具体方法有待优化;Token应该入库,有核对流程
|
||||
$expire = $expire ? $expire : '+1 day';
|
||||
$token = Yii::$app->session->get('fansToken');
|
||||
$tokenExpired = Yii::$app->session->get('fansTokenExpired');
|
||||
|
||||
@@ -119,8 +119,8 @@ class FansController extends Common
|
||||
if (!$res) {
|
||||
$this->result('验证码校验失败');
|
||||
}
|
||||
if (($this->timetamp - $res->create_at) > 300) {
|
||||
// 超时5分钟
|
||||
if (($this->timestamp - $res->create_at) > 300) {
|
||||
//超时5分钟
|
||||
$this->result('验证码已失效,请重新获取');
|
||||
}
|
||||
|
||||
@@ -283,8 +283,8 @@ class FansController extends Common
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加一个新用户
|
||||
* @param $data 用户数据
|
||||
* 添加一个新用户 用户数据
|
||||
* @param $data
|
||||
* @return void
|
||||
*/
|
||||
private function fansAdd($data, $userModel)
|
||||
@@ -301,9 +301,9 @@ class FansController extends Common
|
||||
return $userModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $user 用户实例
|
||||
* @param $hasExt 有否扩展
|
||||
/** 用户实例、有否扩展
|
||||
* @param $user
|
||||
* @param $hasExt
|
||||
* @return void
|
||||
*/
|
||||
private function fansLogin($user, $hasExt = FALSE)
|
||||
|
||||
@@ -44,7 +44,7 @@ class IndexController extends Common
|
||||
public function actionAdsSplash()
|
||||
{
|
||||
$ads = [
|
||||
// "http://public.hiluker.com/ctms/client/app-kp/kp01.jpg",
|
||||
"http://public.hiluker.com/ctms/client/app-kp/kp01.jpg",
|
||||
"http://public.hiluker.com/ctms/client/app-kp/kp03.jpg",
|
||||
];
|
||||
$this->result('开屏广告!', $ads, 200);
|
||||
@@ -55,7 +55,7 @@ class IndexController extends Common
|
||||
$ads = [
|
||||
'0'=>[
|
||||
"image"=>'http://public.hiluker.com/ctms/client/app-banner/banner01.jpg',
|
||||
"link"=>'/pages/uni-starter/ucenter/ucenter'
|
||||
"link"=>'/pages/ctms/news/list/list'
|
||||
],
|
||||
'1'=>[
|
||||
"image"=>'http://public.hiluker.com/ctms/client/app-banner/banner03.jpg',
|
||||
@@ -96,18 +96,18 @@ class IndexController extends Common
|
||||
$_where[]=['=','is_turnover',0]; //排除交车单
|
||||
$_where[] = ['between','sign_date',$start,$end];
|
||||
$data = $model->find()->where($_where);
|
||||
$order_today_count = $data->count();
|
||||
$order_today_count = (int)$data->count();
|
||||
//今日交车
|
||||
$_where = $where;
|
||||
$_where[]=['=','is_turnover',1]; //交车单
|
||||
$_where[] = ['between','sign_date',$start,$end];
|
||||
$data = $model->find()->where($_where);
|
||||
$jiaoche_today_count = $data->count();
|
||||
$jiaoche_today_count = (int)$data->count();
|
||||
//今日录单
|
||||
$_where = $where;
|
||||
$_where[] = ['between','create_at',$start,$end];
|
||||
$data = $model->find()->where($_where);
|
||||
$order_today_create = $data->count();
|
||||
$order_today_create = (int)$data->count();
|
||||
|
||||
//昨日
|
||||
$_end = $start;
|
||||
@@ -118,18 +118,18 @@ class IndexController extends Common
|
||||
$_where[]=['=','is_turnover',0]; //排除交车单
|
||||
$_where[] = ['between','sign_date',$_start,$_end];
|
||||
$data = $model->find()->where($_where);
|
||||
$order_yesterday_count = $data->count();
|
||||
$order_yesterday_count = (int)$data->count();
|
||||
//昨日交车
|
||||
$_where = $where;
|
||||
$_where[]=['=','is_turnover',1]; //交车单
|
||||
$_where[] = ['between','sign_date',$_start,$_end];
|
||||
$data = $model->find()->where($_where);
|
||||
$jiaoche_yesterday_count = $data->count();
|
||||
$jiaoche_yesterday_count = (int)$data->count();
|
||||
//昨日录单
|
||||
$_where = $where;
|
||||
$_where[] = ['between','create_at',$_start,$_end];
|
||||
$data = $model->find()->where($_where);
|
||||
$order_yesterday_create = $data->count();
|
||||
$order_yesterday_create = (int)$data->count();
|
||||
|
||||
//本月起始时间点
|
||||
$_start = date('Y-m-01 00:00:00');
|
||||
@@ -142,31 +142,33 @@ class IndexController extends Common
|
||||
$_where[]=['=','is_turnover',0]; //排除交车单
|
||||
$_where[] = ['between','sign_date',$_start,$_end];
|
||||
$data = $model->find()->where($_where);
|
||||
$order_month_count = $data->count();
|
||||
$order_month_count = (int)$data->count();
|
||||
//本月交车
|
||||
$_where = $where;
|
||||
$_where[]=['=','is_turnover',1];
|
||||
$_where[] = ['between','sign_date',$_start,$_end];
|
||||
$data = $model->find()->where($_where);
|
||||
$jiaoche_month_count = $data->count();
|
||||
$jiaoche_month_count = (int)$data->count();
|
||||
|
||||
//累计运单
|
||||
$_where = $where;
|
||||
$_where[]=['=','is_turnover',0]; //排除交车单
|
||||
$data = $model->find()->where($_where);
|
||||
$order_all_count = $data->count();
|
||||
$order_all_count = (int)$data->count();
|
||||
//累计交车
|
||||
$_where = $where;
|
||||
$_where[]=['=','is_turnover',1];
|
||||
$data = $model->find()->where($_where);
|
||||
$jiaoche_all_count = $data->count();
|
||||
$jiaoche_all_count = (int)$data->count();
|
||||
|
||||
$return = [];
|
||||
$return['code'] = 200;
|
||||
$return['msg'] = '首页数据下载!';
|
||||
$return['data']= [
|
||||
'orderToday'=>$order_today_count,
|
||||
'orderTodayCreate'=>$order_today_create,
|
||||
'orderYesterday'=>$order_yesterday_count,
|
||||
'orderYesterdayCreate'=>$order_yesterday_create,
|
||||
'orderMonth'=>$order_month_count,
|
||||
'orderTotal'=>$order_all_count,
|
||||
'jiaocheToday'=>$jiaoche_today_count,
|
||||
|
||||
@@ -57,6 +57,7 @@ class NewsController extends Common
|
||||
}
|
||||
$model = new AcNews();
|
||||
$detail = $model->findOne($id);
|
||||
if(!$detail) $this->result('查询失败,未找到指定内容!');
|
||||
$s = $this->formatDetail($detail->toArray());
|
||||
$this->result('查询成功!', $s, 200);
|
||||
}
|
||||
@@ -188,7 +189,7 @@ class NewsController extends Common
|
||||
|
||||
// 'src="/upload/pics/'
|
||||
$upload_url = 'https://dacms.hiluker.cn';
|
||||
$s['content'] = str_replace('src="/upload/pics/', 'src="' . $upload_url . '/upload/pics/', $s['content']);
|
||||
$s['content'] = str_replace('src="/upload/pics/', 'src="' . $upload_url . '/upload-ctms/pics/', $s['content']);
|
||||
return $s;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,8 +52,10 @@ class OrderpreController extends Common
|
||||
$post = $this->postdata;
|
||||
$search = isset($post['search']) ? $post['search'] : [];
|
||||
//预置搜索条件,只允许查询与自己完全相关的订单
|
||||
if(!$this->user_id) $this->result('用户未登陆,拒绝查询!', [], 0);
|
||||
$where[] = ['=', 'from_uid', $this->user_id];
|
||||
$search['phone'] = $this->user_info->mobile;
|
||||
if(!$search['phone']) $this->result('没有用户手机号,查询失败!', [], 0);
|
||||
$where[] = ['=', 'from_mobile', $search['phone']];
|
||||
|
||||
if (isset($search['carno']) && !empty($search['carno'])) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace api\controllers\client\v1;
|
||||
|
||||
use Yii;
|
||||
use vendor\aliyun\dysms\Sms;
|
||||
use vendor\aliyun\dysms\Sms as DysmsClient;
|
||||
use common\models\CSms;
|
||||
use common\models\CVcode;
|
||||
use addons\models\AcPlat;
|
||||
@@ -21,7 +21,9 @@ class SmsController extends Common
|
||||
public function actionIndex()
|
||||
{
|
||||
$apis = [
|
||||
'vcode'=>'获取短信验证码'
|
||||
'vcode'=>'获取短信验证码',
|
||||
'send'=>'群发',
|
||||
'caiwu'=>'财务获取验证码'
|
||||
];
|
||||
$this->result('您正使用CMTS-CLIENT系统短信管理接口!', $apis, 200);
|
||||
}
|
||||
@@ -157,7 +159,7 @@ class SmsController extends Common
|
||||
$config['sign'] = isset($dataPost['sign']) ? $dataPost['sign'] : $params['aliDySms']['sign'];
|
||||
|
||||
$option = array();
|
||||
$sms = new Sms($option, $config);
|
||||
$sms = new DysmsClient($option, $config);
|
||||
$_time = time();
|
||||
$vcodeModel = new CVcode();
|
||||
//查询上次发送记录
|
||||
@@ -215,7 +217,7 @@ class SmsController extends Common
|
||||
break;
|
||||
}
|
||||
|
||||
// 发送前控制
|
||||
//发送前控制
|
||||
$host = yii::$app->request->hostName;
|
||||
$debug = $params['aliDySms']['debug'] ?? FALSE;
|
||||
$domains = $params['aliDySms']['domains'] ?? [];
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
class Common extends Controller
|
||||
{
|
||||
protected int $pid = 0;
|
||||
protected object $plat;
|
||||
protected int $user_id = 0;
|
||||
protected int $site_id = 0;
|
||||
protected int $store_id = 0;
|
||||
@@ -151,17 +152,91 @@
|
||||
|
||||
/*
|
||||
* SN格式化处理(ID转SN)
|
||||
* 除平台SN(强制4位)外,其他一律32位
|
||||
* 基础格式:平台前缀PSN-应用场景标识-时间戳-随机码后缀
|
||||
* */
|
||||
public function idToSn($id,$type){
|
||||
$plat = AcPlat::findOne($this->pid);
|
||||
$psn = $plat->sn; //"AYCL",强制4位
|
||||
$_sn = $psn.'-'; //4+1=5
|
||||
$_id = intval($id);
|
||||
if($_id != $id) return false;
|
||||
$res = false;
|
||||
|
||||
switch ($type) {
|
||||
//常规运单
|
||||
case 'order':
|
||||
$pre = 'YD';
|
||||
$pre = 'YD'; //2位
|
||||
if($id>=0){
|
||||
$str = date('YmdHis'); //20250701120102,14位
|
||||
$_sn .= $pre.$str; //5+2+14 = 21;
|
||||
$sn = '00000000000'; //11位
|
||||
$sn = substr($sn, 0, 11 - strlen($id));
|
||||
$sn .= $id;
|
||||
$_sn .= $sn; //21+11 = 32
|
||||
}else{
|
||||
$str = date('YmdHis'); //20250701120102,14位
|
||||
$str2 = date('ymdH'); //25070112, 8位
|
||||
$sn = md5($str,true); //转换为二进制16个字符串的md5
|
||||
$_sn .= $pre.$str2.'-'.$sn; //5+2+8+1+16 = 32;
|
||||
}
|
||||
$res = true;
|
||||
break;
|
||||
//预制运单
|
||||
case 'orderPre':
|
||||
$pre = 'PREYD'; //5位
|
||||
if($id>=0){
|
||||
$str = date('ymdHi'); //2507011201,10位
|
||||
$_sn .= $pre.$str.'-'; //5+5+10+1 = 21;
|
||||
$sn = '00000000000'; //11位
|
||||
$sn = substr($sn, 0, 11 - strlen($id));
|
||||
$sn .= $id;
|
||||
$_sn .= $sn; //21+11 = 32
|
||||
}else{
|
||||
$str = date('YmdHis'); //20250701120102,14位
|
||||
$str2 = date('ymd'); //250701, 6位
|
||||
$sn = md5($str,true); //转换为二进制16个字符串的md5
|
||||
$_sn .= $pre.$str2.$sn; //5+5+6+16 = 32;
|
||||
}
|
||||
$res = true;
|
||||
break;
|
||||
//新闻内容
|
||||
case 'news':
|
||||
$pre = 'NEWS'; //4位
|
||||
if($id>=0){
|
||||
$str = date('YmdHis'); //20250701120102,14位
|
||||
$_sn .= $pre.$str; //5+4+14 = 23;
|
||||
$sn = '000000000'; //9位
|
||||
$sn = substr($sn, 0, 9 - strlen($id));
|
||||
$sn .= $id;
|
||||
$_sn .= $sn; //23+9 = 32
|
||||
}else{
|
||||
$str = date('YmdHis'); //20250701120102,14位
|
||||
$str2 = date('ymd'); //250701, 6位
|
||||
$sn = md5($str,true); //转换为二进制16个字符串的md5
|
||||
$_sn .= $pre.$str2.'-'.$sn; //5+4+6+1+16 = 32;
|
||||
}
|
||||
$res = true;
|
||||
break;
|
||||
default:
|
||||
//默认方式,无须前缀、后缀
|
||||
$_str = date('YmdHis'); //20250701120102
|
||||
$md5_hash = md5($_str.$type,true); //转换为二进制16个字符串的md5
|
||||
$_sn .= $md5_hash; //5+16 = 21;
|
||||
if($id>=0){
|
||||
$sn = '00000000000'; //11位
|
||||
$sn = substr($sn, 0, 11 - strlen($id));
|
||||
$sn .= $id;
|
||||
$_sn .= $sn; //21+11 = 32
|
||||
}else{
|
||||
$_str = date('ymdHi'); //2507011201, 10位
|
||||
$_sn .= $_str.mt_rand(0,9); //21+10+1=32;
|
||||
}
|
||||
$res = true;
|
||||
break;
|
||||
}
|
||||
return $pre.$sn;
|
||||
if(!$res) return false;
|
||||
return $_sn;
|
||||
}
|
||||
|
||||
//校验财务验证码
|
||||
@@ -187,4 +262,5 @@
|
||||
}
|
||||
return ['res'=>true,'err'=>'','code'=>0];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -160,9 +160,11 @@
|
||||
$this->preChonghong($detail);
|
||||
|
||||
//操作日志处理
|
||||
$statusCode = $detail->status_code;
|
||||
$_status = $status[$statusCode] ?? '未知';
|
||||
$key = 'cwlogs';
|
||||
$logs = $detail->cwlogs ? json_decode($detail->cwlogs, TRUE) : [];
|
||||
$log = $this->user_info->username . '于' . date('Y-m-d H:i') . '申请冲红;冲红前状态码[' . $status . ']';
|
||||
$log = $this->user_info->username . '于' . date('Y-m-d H:i') . '申请冲红;冲红前状态码[' . $_status . ']';
|
||||
array_unshift($logs, $log);
|
||||
|
||||
/*修改票据状态,状态代码:2 */
|
||||
|
||||
@@ -67,18 +67,18 @@
|
||||
$_where[] = ['=', 'is_turnover', 0]; //排除交车单
|
||||
$_where[] = ['between', 'sign_date', $start, $end];
|
||||
$data = $model->find()->where($_where);
|
||||
$order_today_count = $data->count();
|
||||
$order_today_count = (int)$data->count();
|
||||
//今日交车
|
||||
$_where = $where;
|
||||
$_where[] = ['=', 'is_turnover', 1]; //交车单
|
||||
$_where[] = ['between', 'sign_date', $start, $end];
|
||||
$data = $model->find()->where($_where);
|
||||
$jiaoche_today_count = $data->count();
|
||||
$jiaoche_today_count = (int)$data->count();
|
||||
//今日录单
|
||||
$_where = $where;
|
||||
$_where[] = ['between', 'create_at', $start, $end];
|
||||
$data = $model->find()->where($_where);
|
||||
$order_today_create = $data->count();
|
||||
$order_today_create = (int)$data->count();
|
||||
|
||||
//昨日
|
||||
$_end = $start;
|
||||
@@ -89,18 +89,18 @@
|
||||
$_where[] = ['=', 'is_turnover', 0]; //排除交车单
|
||||
$_where[] = ['between', 'sign_date', $_start, $_end];
|
||||
$data = $model->find()->where($_where);
|
||||
$order_yesterday_count = $data->count();
|
||||
$order_yesterday_count = (int)$data->count();
|
||||
//昨日交车
|
||||
$_where = $where;
|
||||
$_where[] = ['=', 'is_turnover', 1]; //交车单
|
||||
$_where[] = ['between', 'sign_date', $_start, $_end];
|
||||
$data = $model->find()->where($_where);
|
||||
$jiaoche_yesterday_count = $data->count();
|
||||
$jiaoche_yesterday_count = (int)$data->count();
|
||||
//昨日录单
|
||||
$_where = $where;
|
||||
$_where[] = ['between', 'create_at', $_start, $_end];
|
||||
$data = $model->find()->where($_where);
|
||||
$order_yesterday_create = $data->count();
|
||||
$order_yesterday_create = (int)$data->count();
|
||||
|
||||
//本月起始时间点
|
||||
$_start = date('Y-m-01 00:00:00');
|
||||
@@ -113,31 +113,33 @@
|
||||
$_where[] = ['=', 'is_turnover', 0]; //排除交车单
|
||||
$_where[] = ['between', 'sign_date', $_start, $_end];
|
||||
$data = $model->find()->where($_where);
|
||||
$order_month_count = $data->count();
|
||||
$order_month_count = (int)$data->count();
|
||||
//本月交车
|
||||
$_where = $where;
|
||||
$_where[] = ['=', 'is_turnover', 1];
|
||||
$_where[] = ['between', 'sign_date', $_start, $_end];
|
||||
$data = $model->find()->where($_where);
|
||||
$jiaoche_month_count = $data->count();
|
||||
$jiaoche_month_count = (int)$data->count();
|
||||
|
||||
//累计运单
|
||||
$_where = $where;
|
||||
$_where[] = ['=', 'is_turnover', 0]; //排除交车单
|
||||
$data = $model->find()->where($_where);
|
||||
$order_all_count = $data->count();
|
||||
$order_all_count = (int)$data->count();
|
||||
//累计交车
|
||||
$_where = $where;
|
||||
$_where[] = ['=', 'is_turnover', 1];
|
||||
$data = $model->find()->where($_where);
|
||||
$jiaoche_all_count = $data->count();
|
||||
$jiaoche_all_count = (int)$data->count();
|
||||
|
||||
$return = [];
|
||||
$return['code'] = 200;
|
||||
$return['msg'] = '首页数据下载!';
|
||||
$return['data'] = [
|
||||
'orderToday' => $order_today_count,
|
||||
'orderYesterday' => $order_yesterday_count,
|
||||
'orderTodayCreate'=>$order_today_create,
|
||||
'orderYesterday'=>$order_yesterday_count,
|
||||
'orderYesterdayCreate'=>$order_yesterday_create,
|
||||
'orderMonth' => $order_month_count,
|
||||
'orderTotal' => $order_all_count,
|
||||
'jiaocheToday' => $jiaoche_today_count,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,271 @@
|
||||
<?php
|
||||
namespace api\controllers\gm\v1;
|
||||
use addons\models\AcNews;
|
||||
use addons\models\AcNewsCat;
|
||||
use Yii;
|
||||
use yii\data\Pagination;
|
||||
|
||||
class NewsCatController extends Common
|
||||
{
|
||||
public function beforeAction($action)
|
||||
{
|
||||
if (!$this->pid) {
|
||||
$this->result('您正使用本系统内部接口,禁止非法链接使用!');
|
||||
}
|
||||
return parent::beforeAction($action);
|
||||
}
|
||||
|
||||
public function actionIndex()
|
||||
{
|
||||
$apis = [
|
||||
'list'=>'清单',
|
||||
'detail'=>'详情',
|
||||
'add'=>'添加',
|
||||
'edit'=>'编辑',
|
||||
'delete'=>'删除',
|
||||
'show'=>'显示',
|
||||
'hide'=>'隐藏',
|
||||
'ajax'=>'ajax操作'
|
||||
];
|
||||
$this->result('您正使用CMTS-GM系统文章分类管理接口!', $apis, 200);
|
||||
}
|
||||
|
||||
public function actionList()
|
||||
{
|
||||
$s = $this->search();
|
||||
$res = $s['res'];
|
||||
if (!$res) {
|
||||
$this->result('没有查询到相应的数据!', [], 0);
|
||||
}
|
||||
|
||||
$data= [
|
||||
'total'=>intval($s['query']->count()),
|
||||
'cats' => $res,
|
||||
'page'=>$this->page
|
||||
];
|
||||
$this->result('文章分类查询成功!', $data, 200);
|
||||
}
|
||||
|
||||
public function actionDetail()
|
||||
{
|
||||
$id = (int)Yii::$app->request->get('id');
|
||||
if(!$id) $this->result('请求错误,未携带ID参数');
|
||||
$model = new AcNewsCat();
|
||||
$res = $model->findOne($id);
|
||||
if(!$res) $this->result('未查询到相应数据');
|
||||
//SN处理
|
||||
if(!$res->sn){
|
||||
$sn = $this->idToSn($id,'NewsCat');
|
||||
if($sn) $res->sn = $sn;
|
||||
$res->save();
|
||||
}
|
||||
$this->result('文章分类查询完成', $res->toArray(), 200);
|
||||
}
|
||||
|
||||
public function actionAdd()
|
||||
{
|
||||
//数据预检查、编排
|
||||
$data = $this->preSave('add');
|
||||
if(!$data) $this->result('数据预检查未通过,保存失败', $data, 100);
|
||||
|
||||
//保存资料
|
||||
$model = new AcNewsCat();
|
||||
foreach ($data as $key=>$val) {
|
||||
$model->$key = $val;
|
||||
}
|
||||
$res = $model->save();
|
||||
$msg = '数据保存失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
$msg = '数据保存成功!';
|
||||
$return = [];
|
||||
$return['id']= $model->attributes['id']; //获取插入后id;
|
||||
$this->result($msg,$return, 200);
|
||||
}
|
||||
|
||||
public function actionEdit()
|
||||
{
|
||||
$detail = $this->preUpdate();
|
||||
//数据预检查、编排
|
||||
$data = $this->preSave('edit');
|
||||
if(!$data) $this->result('数据预检查未通过,保存失败', $data, 100);
|
||||
|
||||
//保存资料
|
||||
foreach ($data as $key=>$val) {
|
||||
$detail->$key = $val;
|
||||
}
|
||||
$res = $detail->save();
|
||||
$msg = '数据编辑失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
$msg = '数据编辑成功!';
|
||||
$return = [];
|
||||
$return['data']= $detail;
|
||||
$this->result($msg,$return, 200);
|
||||
}
|
||||
|
||||
public function actionDelete()
|
||||
{
|
||||
$detail = $this->preUpdate();
|
||||
$data = [];
|
||||
$data['update_at'] = time();
|
||||
$data['deleted'] = $detail->deleted + 1;
|
||||
|
||||
//保存资料
|
||||
foreach ($data as $key=>$val) {
|
||||
$detail->$key = $val;
|
||||
}
|
||||
$res = $detail->save();
|
||||
$msg = '文章数据删除失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
|
||||
$msg = '文章数据删除成功!';
|
||||
$this->result($msg,[], 200);
|
||||
}
|
||||
|
||||
public function actionAjax()
|
||||
{
|
||||
$detail = $this->preUpdate();
|
||||
$get = Yii::$app->request->get();
|
||||
$msg = '';
|
||||
$errorCode = 0;
|
||||
$detail->update_at = time();
|
||||
|
||||
switch ($get['do']) {
|
||||
case 'hide':
|
||||
$detail->is_show = 0;
|
||||
$res = $detail->save();
|
||||
if ($res) {
|
||||
$msg = '文章隐藏标记成功';
|
||||
$errorCode = 200;
|
||||
} else {
|
||||
$msg = '文章隐藏标记失败';
|
||||
}
|
||||
break;
|
||||
case 'show':
|
||||
$detail->is_show = 1;
|
||||
$res = $detail->save();
|
||||
if ($res) {
|
||||
$msg = '文章显示标记成功';
|
||||
$errorCode = 200;
|
||||
} else {
|
||||
$msg = '文章显示标记失败';
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
$this->result($msg,[], $errorCode);
|
||||
}
|
||||
|
||||
private function search(){
|
||||
$pid = $this->pid;
|
||||
$return = [];
|
||||
$model = new AcNewsCat();
|
||||
$where = $where2 = [];
|
||||
$where['pid'] = $pid;
|
||||
$post = $this->postdata;
|
||||
$search = $post['search'] ?? [];
|
||||
$search['title'] = isset($search['title']) ? trim(htmlspecialchars_decode($search['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2[] = 'or';
|
||||
$where2[] = ['LIKE', 'title', $search['title']];
|
||||
$where2[] = ['LIKE', 'des', $search['title']];
|
||||
}
|
||||
|
||||
$search['pcat'] = isset($search['cat']) ? trim(htmlspecialchars_decode($search['pcat_sn'])) : '';
|
||||
$search['pcid'] = isset($search['cid']) ? intval($search['pcid']) : 0;
|
||||
if (!empty($search['pcat'])) {
|
||||
$where['pcat_sn'] = $search['pcat'];
|
||||
}elseif ($search['pcid']) {
|
||||
$where['pcid'] = $search['pcid'];
|
||||
}
|
||||
|
||||
$where['deleted'] = 0;
|
||||
$data = $model->find()->where($where);
|
||||
if ($search['title']) {
|
||||
$data = $data->andwhere($where2);
|
||||
}
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => $this->pageSize]);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->orderBy('order_by DESC')->all();
|
||||
|
||||
return ['res'=>$res,'query'=>$data];
|
||||
}
|
||||
|
||||
/*
|
||||
* 数据更新前的预检查,返回对应关联数据
|
||||
* 必须确保get与post数据中均包含需更新的数据id且一致
|
||||
* */
|
||||
private function preUpdate()
|
||||
{
|
||||
$id = (int)Yii::$app->request->get('id');
|
||||
if(!$id) $this->result('请求错误,未携带ID参数');
|
||||
$post = $this->postdata;
|
||||
if($post['id'] != $id) $this->result('传参id与请求数据不匹配',[],403);
|
||||
$model = new AcNewsCat();
|
||||
$res = $model->findOne($id);
|
||||
if(!$res) $this->result('未查询到相应数据',[],404);
|
||||
//SN处理
|
||||
if(!$res->sn){
|
||||
$sn = $this->idToSn($id,'NewsCat');
|
||||
if($sn) $res->sn = $sn;
|
||||
$res->save();
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
/*
|
||||
* 数据保存前的预检查(查重、参数校验等)
|
||||
* 要保存的数据[],直接从post中取出
|
||||
* @op,操作类型(add,edit……)
|
||||
* 校验机制:
|
||||
* 编辑数据时,必须用get方式传入参数id,并与post进来的数据id进行比对,只有一致时才能继续;
|
||||
* 查重:禁止录入重复数据
|
||||
* 返回:校验重组后的数据
|
||||
* */
|
||||
private function preSave($op)
|
||||
{
|
||||
$post = $this->postdata;
|
||||
$data = [];
|
||||
//格式化数据
|
||||
//目标键=》POST键
|
||||
$_time = time();
|
||||
$id = 0;
|
||||
$model = new AcNewsCat();
|
||||
switch ($op) {
|
||||
case 'add':
|
||||
$data['is_show'] = 1;
|
||||
$data['create_at'] = $_time;
|
||||
$data['update_at'] = $data['create_at'];
|
||||
$sn = $this->idToSn($id,'NewsCat');
|
||||
if($sn) $data['sn'] = $sn;
|
||||
break;
|
||||
case 'edit':
|
||||
$id = (int)Yii::$app->request->get('id');
|
||||
$_id = (int)$post['id'];
|
||||
if(!$id != $_id) $this->result('id参数不匹配,请检查');
|
||||
$data['update_at'] = $_time;
|
||||
$data['is_show'] = isset($post['is_show']) ? intval($post['is_show']) : 0;
|
||||
break;
|
||||
}
|
||||
|
||||
$data['pid'] = $this->pid;
|
||||
|
||||
//目标键=》POST键
|
||||
$cols = ['title'=>'title','des'=>'des'];
|
||||
foreach($cols as $col=>$key){
|
||||
if(isset($post[$key])){
|
||||
$data[$col] = trim($post[$key]);
|
||||
}elseif(!$id){
|
||||
$data[$col] = '';
|
||||
}
|
||||
}
|
||||
|
||||
$cols = ['order_by' => 'order_by', 'deleted'=>'deleted','pcat_id'=>'pcat_id'];
|
||||
foreach ($cols as $col => $key) {
|
||||
if(isset($post[$key])){
|
||||
$data[$col] = (int)$post[$key];
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,277 @@
|
||||
<?php
|
||||
namespace api\controllers\gm\v1;
|
||||
use addons\models\AcNews;
|
||||
use Yii;
|
||||
use yii\data\Pagination;
|
||||
|
||||
class NewsController extends Common
|
||||
{
|
||||
public function beforeAction($action)
|
||||
{
|
||||
if (!$this->pid) {
|
||||
$this->result('您正使用本系统内部接口,禁止非法链接使用!');
|
||||
}
|
||||
return parent::beforeAction($action);
|
||||
}
|
||||
|
||||
public function actionIndex()
|
||||
{
|
||||
$apis = [
|
||||
'list'=>'清单',
|
||||
'detail'=>'详情',
|
||||
'add'=>'添加',
|
||||
'edit'=>'编辑',
|
||||
'delete'=>'删除',
|
||||
'show'=>'显示',
|
||||
'hide'=>'隐藏',
|
||||
'ajax'=>'ajax操作'
|
||||
];
|
||||
$this->result('您正使用CMTS-GM系统文章内容管理接口!', $apis, 200);
|
||||
}
|
||||
|
||||
public function actionList()
|
||||
{
|
||||
$s = $this->search();
|
||||
$res = $s['res'];
|
||||
if (!$res) {
|
||||
$this->result('没有查询到相应的数据!', [], 0);
|
||||
}
|
||||
|
||||
$data= [
|
||||
'total'=>intval($s['query']->count()),
|
||||
'news' => $res,
|
||||
'page'=>$this->page
|
||||
];
|
||||
$this->result('文章查询成功!', $data, 200);
|
||||
}
|
||||
|
||||
public function actionDetail()
|
||||
{
|
||||
$id = (int)Yii::$app->request->get('id');
|
||||
if(!$id) $this->result('请求错误,未携带ID参数');
|
||||
$model = new AcNews();
|
||||
$res = $model->findOne($id);
|
||||
if(!$res) $this->result('未查询到相应数据');
|
||||
//SN处理
|
||||
if(!$res->sn){
|
||||
$sn = $this->idToSn($id,'News');
|
||||
if($sn) $res->sn = $sn;
|
||||
$res->save();
|
||||
}
|
||||
$this->result('文章信息查询完成', $res->toArray(), 200);
|
||||
}
|
||||
|
||||
public function actionAdd()
|
||||
{
|
||||
//数据预检查、编排
|
||||
$data = $this->preSave('add');
|
||||
if(!$data) $this->result('数据预检查未通过,保存失败', $data, 100);
|
||||
|
||||
//保存资料
|
||||
$model = new AcNews();
|
||||
foreach ($data as $key=>$val) {
|
||||
$model->$key = $val;
|
||||
}
|
||||
$res = $model->save();
|
||||
$msg = '数据保存失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
$msg = '数据保存成功!';
|
||||
$return = [];
|
||||
$return['id']= $model->attributes['id']; //获取插入后id;
|
||||
$this->result($msg,$return, 200);
|
||||
}
|
||||
|
||||
public function actionEdit()
|
||||
{
|
||||
$detail = $this->preUpdate();
|
||||
//数据预检查、编排
|
||||
$data = $this->preSave('edit');
|
||||
if(!$data) $this->result('数据预检查未通过,保存失败', $data, 100);
|
||||
|
||||
//保存资料
|
||||
foreach ($data as $key=>$val) {
|
||||
$detail->$key = $val;
|
||||
}
|
||||
$res = $detail->save();
|
||||
$msg = '数据编辑失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
$msg = '数据编辑成功!';
|
||||
$return = [];
|
||||
$return['data']= $detail;
|
||||
$this->result($msg,$return, 200);
|
||||
}
|
||||
|
||||
public function actionDelete()
|
||||
{
|
||||
$detail = $this->preUpdate();
|
||||
$data = [];
|
||||
$data['update_at'] = time();
|
||||
$data['deleted'] = $detail->deleted + 1;
|
||||
|
||||
//保存资料
|
||||
foreach ($data as $key=>$val) {
|
||||
$detail->$key = $val;
|
||||
}
|
||||
$res = $detail->save();
|
||||
$msg = '文章数据删除失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
|
||||
$msg = '文章数据删除成功!';
|
||||
$this->result($msg,[], 200);
|
||||
}
|
||||
|
||||
public function actionAjax()
|
||||
{
|
||||
$detail = $this->preUpdate();
|
||||
$get = Yii::$app->request->get();
|
||||
$msg = '';
|
||||
$errorCode = 0;
|
||||
$detail->update_at = time();
|
||||
|
||||
switch ($get['do']) {
|
||||
case 'hide':
|
||||
$detail->is_show = 0;
|
||||
$res = $detail->save();
|
||||
if ($res) {
|
||||
$msg = '文章隐藏标记成功';
|
||||
$errorCode = 200;
|
||||
} else {
|
||||
$msg = '文章隐藏标记失败';
|
||||
}
|
||||
break;
|
||||
case 'show':
|
||||
$detail->is_show = 1;
|
||||
$res = $detail->save();
|
||||
if ($res) {
|
||||
$msg = '文章显示标记成功';
|
||||
$errorCode = 200;
|
||||
} else {
|
||||
$msg = '文章显示标记失败';
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
$this->result($msg,[], $errorCode);
|
||||
}
|
||||
|
||||
private function search(){
|
||||
$pid = $this->pid;
|
||||
$return = [];
|
||||
$model = new AcNews();
|
||||
$where = $where2 = [];
|
||||
$where['pid'] = $pid;
|
||||
$post = $this->postdata;
|
||||
$search = $post['search'] ?? [];
|
||||
$search['title'] = isset($search['title']) ? trim(htmlspecialchars_decode($search['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2[] = 'or';
|
||||
$where2[] = ['LIKE', 'title', $search['title']];
|
||||
$where2[] = ['LIKE', 'des', $search['title']];
|
||||
}
|
||||
|
||||
$search['cat'] = isset($search['cat']) ? trim(htmlspecialchars_decode($search['cat_sn'])) : '';
|
||||
$search['cid'] = isset($search['cid']) ? intval($search['cid']) : 0;
|
||||
if (!empty($search['cat'])) {
|
||||
$where['cat_sn'] = $search['cat'];
|
||||
}elseif ($search['cid']) {
|
||||
$where['cid'] = $search['cid'];
|
||||
}
|
||||
|
||||
$where['deleted'] = 0;
|
||||
$data = $model->find()->where($where);
|
||||
if ($search['title']) {
|
||||
$data = $data->andwhere($where2);
|
||||
}
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => $this->pageSize]);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->orderBy('order_by DESC')->all();
|
||||
|
||||
return ['res'=>$res,'query'=>$data];
|
||||
}
|
||||
|
||||
/*
|
||||
* 数据更新前的预检查,返回对应关联数据
|
||||
* 必须确保get与post数据中均包含需更新的数据id且一致
|
||||
* */
|
||||
private function preUpdate()
|
||||
{
|
||||
$id = (int)Yii::$app->request->get('id');
|
||||
if(!$id) $this->result('请求错误,未携带ID参数');
|
||||
$post = $this->postdata;
|
||||
if($post['id'] != $id) $this->result('传参id与请求数据不匹配',[],403);
|
||||
$model = new AcNews();
|
||||
$res = $model->findOne($id);
|
||||
if(!$res) $this->result('未查询到相应数据',[],404);
|
||||
//SN处理
|
||||
if(!$res->sn){
|
||||
$sn = $this->idToSn($id,'News');
|
||||
if($sn) $res->sn = $sn;
|
||||
$res->save();
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
/*
|
||||
* 数据保存前的预检查(查重、参数校验等)
|
||||
* 要保存的数据[],直接从post中取出
|
||||
* @op,操作类型(add,edit……)
|
||||
* 校验机制:
|
||||
* 编辑数据时,必须用get方式传入参数id,并与post进来的数据id进行比对,只有一致时才能继续;
|
||||
* 查重:禁止录入重复数据
|
||||
* 返回:校验重组后的数据
|
||||
* */
|
||||
private function preSave($op)
|
||||
{
|
||||
$post = $this->postdata;
|
||||
$data = [];
|
||||
//格式化数据
|
||||
//目标键=》POST键
|
||||
$_time = time();
|
||||
$id = 0;
|
||||
$model = new AcNews();
|
||||
switch ($op) {
|
||||
case 'add':
|
||||
$data['is_show'] = 1;
|
||||
$data['create_at'] = $_time;
|
||||
$data['update_at'] = $data['create_at'];
|
||||
$sn = $this->idToSn($id,'News');
|
||||
if($sn) $data['sn'] = $sn;
|
||||
break;
|
||||
case 'edit':
|
||||
$id = (int)Yii::$app->request->get('id');
|
||||
$_id = (int)$post['id'];
|
||||
if(!$id != $_id) $this->result('id参数不匹配,请检查');
|
||||
$data['update_at'] = $_time;
|
||||
$data['is_show'] = isset($post['is_show']) ? intval($post['is_show']) : 0;
|
||||
break;
|
||||
}
|
||||
|
||||
$data['pid'] = $this->pid;
|
||||
|
||||
//目标键=》POST键
|
||||
$cols = ['title'=>'title','des'=>'des'];
|
||||
foreach($cols as $col=>$key){
|
||||
if(isset($post[$key])){
|
||||
$data[$col] = trim($post[$key]);
|
||||
}elseif(!$id){
|
||||
$data[$col] = '';
|
||||
}
|
||||
}
|
||||
|
||||
$cols = ['content'=>'editor'];
|
||||
foreach($cols as $col=>$key){
|
||||
if(isset($post[$key])){
|
||||
$data[$col] = htmlspecialchars($post[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$cols = ['order_by' => 'order_by', 'deleted' => 'deleted','cid'=>'cid','liked'=>'liked','reading'=>'reading','viewed'=>'viewed'];
|
||||
foreach ($cols as $col => $key) {
|
||||
if(isset($post[$key])){
|
||||
$data[$col] = (int)$post[$key];
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,269 @@
|
||||
<?php
|
||||
namespace api\controllers\gm\v1;
|
||||
use addons\models\AcNotice;
|
||||
use Yii;
|
||||
use yii\data\Pagination;
|
||||
|
||||
class NoticeController extends Common
|
||||
{
|
||||
public function beforeAction($action)
|
||||
{
|
||||
if (!$this->pid) {
|
||||
$this->result('您正使用本系统内部接口,禁止非法链接使用!');
|
||||
}
|
||||
return parent::beforeAction($action);
|
||||
}
|
||||
|
||||
public function actionIndex()
|
||||
{
|
||||
$apis = [
|
||||
'list'=>'清单',
|
||||
'detail'=>'详情',
|
||||
'add'=>'添加',
|
||||
'edit'=>'编辑',
|
||||
'delete'=>'删除',
|
||||
'show'=>'显示',
|
||||
'hide'=>'隐藏',
|
||||
'ajax'=>'ajax操作'
|
||||
];
|
||||
$this->result('您正使用CMTS-GM系统通知内容管理接口!', $apis, 200);
|
||||
}
|
||||
|
||||
public function actionList()
|
||||
{
|
||||
$s = $this->search();
|
||||
$res = $s['res'];
|
||||
if (!$res) {
|
||||
$this->result('没有查询到相应的数据!', [], 0);
|
||||
}
|
||||
|
||||
$data= [
|
||||
'total'=>intval($s['query']->count()),
|
||||
'news' => $res,
|
||||
'page'=>$this->page
|
||||
];
|
||||
$this->result('通知查询成功!', $data, 200);
|
||||
}
|
||||
|
||||
public function actionDetail()
|
||||
{
|
||||
$id = (int)Yii::$app->request->get('id');
|
||||
if(!$id) $this->result('请求错误,未携带ID参数');
|
||||
$model = new AcNotice();
|
||||
$res = $model->findOne($id);
|
||||
if(!$res) $this->result('未查询到相应数据');
|
||||
//SN处理
|
||||
if(!$res->sn){
|
||||
$sn = $this->idToSn($id,'Notice');
|
||||
if($sn) $res->sn = $sn;
|
||||
$res->save();
|
||||
}
|
||||
$this->result('文章信息查询完成', $res->toArray(), 200);
|
||||
}
|
||||
|
||||
public function actionAdd()
|
||||
{
|
||||
//数据预检查、编排
|
||||
$data = $this->preSave('add');
|
||||
if(!$data) $this->result('数据预检查未通过,保存失败', $data, 100);
|
||||
|
||||
//保存资料
|
||||
$model = new AcNotice();
|
||||
foreach ($data as $key=>$val) {
|
||||
$model->$key = $val;
|
||||
}
|
||||
$res = $model->save();
|
||||
$msg = '数据保存失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
$msg = '数据保存成功!';
|
||||
$return = [];
|
||||
$return['id']= $model->attributes['id']; //获取插入后id;
|
||||
$this->result($msg,$return, 200);
|
||||
}
|
||||
|
||||
public function actionEdit()
|
||||
{
|
||||
$detail = $this->preUpdate();
|
||||
//数据预检查、编排
|
||||
$data = $this->preSave('edit');
|
||||
if(!$data) $this->result('数据预检查未通过,保存失败', $data, 100);
|
||||
|
||||
//保存资料
|
||||
foreach ($data as $key=>$val) {
|
||||
$detail->$key = $val;
|
||||
}
|
||||
$res = $detail->save();
|
||||
$msg = '数据编辑失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
$msg = '数据编辑成功!';
|
||||
$return = [];
|
||||
$return['data']= $detail;
|
||||
$this->result($msg,$return, 200);
|
||||
}
|
||||
|
||||
public function actionDelete()
|
||||
{
|
||||
$detail = $this->preUpdate();
|
||||
$data = [];
|
||||
$data['update_at'] = time();
|
||||
$data['deleted'] = $detail->deleted + 1;
|
||||
|
||||
//保存资料
|
||||
foreach ($data as $key=>$val) {
|
||||
$detail->$key = $val;
|
||||
}
|
||||
$res = $detail->save();
|
||||
$msg = '通知数据删除失败!';
|
||||
if(!$res) $this->result($msg, [], 100);
|
||||
|
||||
$msg = '通知数据删除成功!';
|
||||
$this->result($msg,[], 200);
|
||||
}
|
||||
|
||||
public function actionAjax()
|
||||
{
|
||||
$detail = $this->preUpdate();
|
||||
$get = Yii::$app->request->get();
|
||||
$msg = '';
|
||||
$errorCode = 0;
|
||||
$detail->update_at = time();
|
||||
|
||||
switch ($get['do']) {
|
||||
case 'hide':
|
||||
$detail->is_show = 0;
|
||||
$res = $detail->save();
|
||||
if ($res) {
|
||||
$msg = '文章隐藏标记成功';
|
||||
$errorCode = 200;
|
||||
} else {
|
||||
$msg = '文章隐藏标记失败';
|
||||
}
|
||||
break;
|
||||
case 'show':
|
||||
$detail->is_show = 1;
|
||||
$res = $detail->save();
|
||||
if ($res) {
|
||||
$msg = '文章显示标记成功';
|
||||
$errorCode = 200;
|
||||
} else {
|
||||
$msg = '文章显示标记失败';
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
$this->result($msg,[], $errorCode);
|
||||
}
|
||||
|
||||
private function search(){
|
||||
$pid = $this->pid;
|
||||
$return = [];
|
||||
$model = new AcNotice();
|
||||
$where = $where2 = [];
|
||||
$where['pid'] = $pid;
|
||||
$post = $this->postdata;
|
||||
$search = $post['search'] ?? [];
|
||||
$search['title'] = isset($search['title']) ? trim(htmlspecialchars_decode($search['title'])) : '';
|
||||
if (!empty($search['title'])) {
|
||||
$where2[] = 'or';
|
||||
$where2[] = ['LIKE', 'title', $search['title']];
|
||||
$where2[] = ['LIKE', 'content', $search['title']];
|
||||
}
|
||||
|
||||
$where['deleted'] = 0;
|
||||
$data = $model->find()->where($where);
|
||||
if ($search['title']) {
|
||||
$data = $data->andwhere($where2);
|
||||
}
|
||||
$pages = new Pagination(['totalCount' => $data->count(), 'pageSize' => $this->pageSize]);
|
||||
$res = $data->offset($pages->offset)->limit($pages->limit)->orderBy('order_by DESC')->all();
|
||||
|
||||
return ['res'=>$res,'query'=>$data];
|
||||
}
|
||||
|
||||
/*
|
||||
* 数据更新前的预检查,返回对应关联数据
|
||||
* 必须确保get与post数据中均包含需更新的数据id且一致
|
||||
* */
|
||||
private function preUpdate()
|
||||
{
|
||||
$id = (int)Yii::$app->request->get('id');
|
||||
if(!$id) $this->result('请求错误,未携带ID参数');
|
||||
$post = $this->postdata;
|
||||
if($post['id'] != $id) $this->result('传参id与请求数据不匹配',[],403);
|
||||
$model = new AcNotice();
|
||||
$res = $model->findOne($id);
|
||||
if(!$res) $this->result('未查询到相应数据',[],404);
|
||||
//SN处理
|
||||
if(!$res->sn){
|
||||
$sn = $this->idToSn($id,'Notice');
|
||||
if($sn) $res->sn = $sn;
|
||||
$res->save();
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
/*
|
||||
* 数据保存前的预检查(查重、参数校验等)
|
||||
* 要保存的数据[],直接从post中取出
|
||||
* @op,操作类型(add,edit……)
|
||||
* 校验机制:
|
||||
* 编辑数据时,必须用get方式传入参数id,并与post进来的数据id进行比对,只有一致时才能继续;
|
||||
* 查重:禁止录入重复数据
|
||||
* 返回:校验重组后的数据
|
||||
* */
|
||||
private function preSave($op)
|
||||
{
|
||||
$post = $this->postdata;
|
||||
$data = [];
|
||||
//格式化数据
|
||||
//目标键=》POST键
|
||||
$_time = time();
|
||||
$id = 0;
|
||||
$model = new AcNotice();
|
||||
switch ($op) {
|
||||
case 'add':
|
||||
$data['is_show'] = 1;
|
||||
$data['create_at'] = $_time;
|
||||
$data['update_at'] = $data['create_at'];
|
||||
$sn = $this->idToSn($id,'Notice');
|
||||
if($sn) $data['sn'] = $sn;
|
||||
break;
|
||||
case 'edit':
|
||||
$id = (int)Yii::$app->request->get('id');
|
||||
$_id = (int)$post['id'];
|
||||
if(!$id != $_id) $this->result('id参数不匹配,请检查');
|
||||
$data['update_at'] = $_time;
|
||||
$data['is_show'] = isset($post['is_show']) ? intval($post['is_show']) : 0;
|
||||
break;
|
||||
}
|
||||
|
||||
$data['pid'] = $this->pid;
|
||||
|
||||
//目标键=》POST键
|
||||
$cols = ['title'=>'title','des'=>'des'];
|
||||
foreach($cols as $col=>$key){
|
||||
if(isset($post[$key])){
|
||||
$data[$col] = trim($post[$key]);
|
||||
}elseif(!$id){
|
||||
$data[$col] = '';
|
||||
}
|
||||
}
|
||||
|
||||
$cols = ['content'=>'editor'];
|
||||
foreach($cols as $col=>$key){
|
||||
if(isset($post[$key])){
|
||||
$data[$col] = htmlspecialchars($post[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$cols = ['order_by' => 'order_by', 'deleted' => 'deleted','cid'=>'cid','liked'=>'liked','reading'=>'reading','viewed'=>'viewed'];
|
||||
foreach ($cols as $col => $key) {
|
||||
if(isset($post[$key])){
|
||||
$data[$col] = (int)$post[$key];
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user