<?php
namespace app\controller;
use app\controller\Acl;
use app\model\Account as Accounts;
use think\facade\Db;
use think\exception\ValidateException;
class Account extends Acl {
public function record(){
$input=input('post.');
if(existFull($input,['page','limit'])){
$sql=fastSql($input,[
['name','fullLike'],
['number','fullLike'],
['data','fullLike']
]) $sql=frameScope($sql) $sql=sqlAuth('account',$sql) $count = Accounts::where($sql)->count() $info = Accounts::with(['frameData'])->where($sql)->append(['extension'])->page($input['page'],$input['limit'])->order(['id'=>'desc'])->select() $result=[
'state'=>'success',
'count'=>$count,
'info'=>$info
] }else{
$result=['state'=>'error','info'=>'传入参数不完整!'];
}
return json($result);
}
public function save(){
$input=input('post.');
if(isset($input['id'])){
try {
unset($input['balance']);
empty($input['id'])?$this->validate($input,'app\validate\Account'):$this->validate($input,'app\validate\Account.update');
} catch (ValidateException $e) {
return json(['state'=>'error','info'=>$e->getError()]);
exit;
}
Db::startTrans();
try {
if(empty($input['id'])){
Accounts::create($input);
pushLog('新增资金账户[ '.$input['name'].' ]') }else{
Accounts::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=Accounts::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'=>'sell','where'=>[['account','=',$input['id']]]],
['table'=>'sre','where'=>[['account','=',$input['id']]]],
['table'=>'buy','where'=>[['account','=',$input['id']]]],
['table'=>'bre','where'=>[['account','=',$input['id']]]],
['table'=>'ice','where'=>[['account','=',$input['id']]]],
['table'=>'oce','where'=>[['account','=',$input['id']]]],
['table'=>'allot_info','where'=>[['account|tat','=',$input['id']]]],
['table'=>'deploy','where'=>[['source','like','%"account":'.$input['id'].'%']]]
]);
if(empty($exist)){
$find=Db::name('account')->where([['id','=',$input['id']]])->find();
Db::startTrans();
try {
Db::name('account')->where([['id','=',$input['id']]])->delete();
Db::name('account_info')->where([['pid','=',$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);
}
}