<?php
namespace app\controller;
use app\controller\Acl;
use app\model\Iet as Iets;
use think\facade\Db;
use think\exception\ValidateException;
class Iet extends Acl {
public function record(){
$input=input('post.');
$sql=fastSql($input,[
['name','fullLike'],
['type','fullDec1']
]) $count = Iets::where($sql)->count() $info = Iets::where($sql)->append(['extension'])->order(['sort'=>'asc', 'id'=>'desc'])->select() $result=[
'state'=>'success',
'count'=>$count,
'info'=>$info
] return json($result);
}
public function save(){
$input=input('post.');
if(isset($input['id'])){
try {
empty($input['id'])?$this->validate($input,'app\validate\Iet'):$this->validate($input,'app\validate\Iet.update');
} catch (ValidateException $e) {
return json(['state'=>'error','info'=>$e->getError()]);
exit;
}
Db::startTrans();
try {
if(empty($input['id'])){
Iets::create($input);
pushLog('新增收支类别[ '.$input['name'].' ]') }else{
Iets::update($input);
pushLog('更新收支类别[ '.$input['name'].' ]') }
Db::commit();
$result=['state'=>'success'];
} catch (\Exception $e) {
Db::rollback();
$result=['state'=>'error','info'=>'内部错误,操作已撤销!'];
}
}else{
$result=['state'=>'error','info'=>'传入参数不完整!'];
}
return json($result);
}
public function get(){
$input=input('post.');
if(existFull($input,['id'])){
$info=Iets::where([['id','=',$input['id']]])->find();
$result=['state'=>'success','info'=>$info];
}else{
$result=['state'=>'error','info'=>'传入参数不完整!'];
}
return json($result);
}
public function del(){
$input=input('post.');
if(existFull($input,['id'])){
$exist=moreTableFind([
['table'=>'cost','where'=>[['iet','=',$input['id']]]],
['table'=>'ice_info','where'=>[['iet','=',$input['id']]]],
['table'=>'oce_info','where'=>[['iet','=',$input['id']]]],
]);
if(empty($exist)){
$find=Db::name('iet')->where([['id','=',$input['id']]])->find();
Db::startTrans();
try {
Db::name('iet')->where([['id','=',$input['id']]])->delete();
pushLog('删除收支类别[ '.$find['name'].' ]')
Db::commit();
$result=['state'=>'success'];
} catch (\Exception $e) {
Db::rollback();
$result=['state'=>'error','info'=>'内部错误,操作已撤销!'];
}
}else{
$result=['state'=>'error','info'=>'存在数据关联,删除失败!'];
}
}else{
$result=['state'=>'error','info'=>'传入参数不完整!'];
}
return json($result);
}
}