<?php
namespace app \index \controller ;
use think\Hook;
use app\index\controller\Acl;
use app\index\model\Account as Accounts;
use app\index\controller\Formfield;
use app\index\model\Accountinfo;
class Account extends Acl {
public function main(){
return $this->fetch();
}
public function account_list(){
$input=input('post.');
if(isset_full($input,'page') && isset_full($input,'limit')){
$sql=get_sql($input,[
'name'=>'full_name_py_link',
'number'=>'full_like',
'data'=>'full_like'
],'account') $sql=auth('account',$sql) $count = Accounts::where ($sql)->count() $arr = Accounts::where($sql)->page($input['page'],$input['limit'])->order('id desc')->select() $resule=[
'code'=>0,
'msg'=>'获取成功',
'count'=>$count,
'data'=>$arr
] }else{
$resule=['state'=>'error','info'=>'传入参数不完整!'];
}
return json($resule);
}
public function set_account(){
$input=input('post.');
if(isset($input['id'])){
if(empty($input['id'])){
$vali = $this->validate($input,'account');
if($vali===true){
$input['py']=zh2py($input['name']) $create_info=Accounts::create(syn_sql($input,'account'));
Hook::listen('create_account',$create_info) push_log('新增资金账户信息[ '.$create_info['name'].' ]') $resule=['state'=>'success'];
}else{
$resule=['state'=>'error','info'=>$vali];
}
}else{
$vali = $this->validate($input,'account.update');
if($vali===true){
$input['py']=zh2py($input['name']) $update_info=Accounts::update(syn_sql($input,'account'));
Hook::listen('update_account',$update_info) push_log('更新资金账户信息[ '.$update_info['name'].' ]') $resule=['state'=>'success'];
}else{
$resule=['state'=>'error','info'=>$vali];
}
}
}else{
$resule=['state'=>'error','info'=>'传入参数不完整!'];
}
return json($resule);
}
public function get_account(){
$input=input('post.');
if(isset_full($input,'id')){
$resule=Accounts::where(['id'=>$input['id']])->find();
}else{
$resule=['state'=>'error','info'=>'传入参数不完整!'];
}
return json($resule);
}
public function del_account(){
$input=input('post.');
if(isset_full($input,'arr') && is_array($input['arr'])){
$exist=more_table_find([
['table'=>'cashierclass','where'=>['account'=>['in',$input['arr']]]],
['table'=>'eftinfo','where'=>['account'=>['in',$input['arr']]]],
['table'=>'gatherinfo','where'=>['account'=>['in',$input['arr']]]],
['table'=>'itemorderbill','where'=>['account'=>['in',$input['arr']]]],
['table'=>'itemorderclass','where'=>['account'=>['in',$input['arr']]]],
['table'=>'otgatherinfo','where'=>['account'=>['in',$input['arr']]]],
['table'=>'otpaymentinfo','where'=>['account'=>['in',$input['arr']]]],
['table'=>'paymentinfo','where'=>['account'=>['in',$input['arr']]]],
['table'=>'purchasebill','where'=>['account'=>['in',$input['arr']]]],
['table'=>'purchaseclass','where'=>['account'=>['in',$input['arr']]]],
['table'=>'recashierclass','where'=>['account'=>['in',$input['arr']]]],
['table'=>'repurchasebill','where'=>['account'=>['in',$input['arr']]]],
['table'=>'repurchaseclass','where'=>['account'=>['in',$input['arr']]]],
['table'=>'resalebill','where'=>['account'=>['in',$input['arr']]]],
['table'=>'resaleclass','where'=>['account'=>['in',$input['arr']]]],
['table'=>'rpurchasebill','where'=>['account'=>['in',$input['arr']]]],
['table'=>'rpurchaseclass','where'=>['account'=>['in',$input['arr']]]],
['table'=>'salebill','where'=>['account'=>['in',$input['arr']]]],
['table'=>'saleclass','where'=>['account'=>['in',$input['arr']]]]
]);
if(!$exist){
$info=db('account')->where(['id'=>['in',$input['arr']]])->select() foreach ($info as $info_vo) {
push_log('删除资金账户信息[ '.$info_vo['name'].' ]') Hook::listen('del_account',$info_vo['id']) }
Accounts::where(['id'=>['in',$input['arr']]])->delete();
$resule=['state'=>'success'];
}else{
$resule=['state'=>'error','info'=>'存在数据关联,删除失败!'];
}
}else{
$resule=['state'=>'error','info'=>'传入参数不完整!'];
}
return json($resule);
}
public function export_account(){
$input=input('get.');
$sql=get_sql($input,[
'name'=>'full_name_py_link',
'number'=>'full_like',
'data'=>'full_like'
],'account') $arr = Accounts::where($sql)->order('id desc')->select() $formfield=get_formfield('account_export','array') $excel=[] array_push($excel,['type'=>'title','info'=>'资金账户列表']);
$table_cell=[] foreach ($formfield as $formfield_vo) {
$table_cell[$formfield_vo['key']]=$formfield_vo['text'];
}
$table_data=[] foreach ($arr as $arr_vo) {
$row_data=[];
foreach ($formfield as $formfield_vo) {
$val='nod_initial' foreach (explode('|',$formfield_vo['data']) as $source) {
$val=$val=='nod_initial'?$arr_vo[$source]:(isset($val[$source])?$val[$source]:'');
}
$row_data[$formfield_vo['key']]=$val }
array_push($table_data,$row_data) }
array_push($excel,['type'=>'table','info'=>['cell'=>$table_cell,'data'=>$table_data]]) $sum_arr=get_sums($table_data,['balance']);
array_push($excel,['type'=>'node','info'=>['资金余额汇总:'.$sum_arr['balance']]]) push_log('导出资金账户信息') export_excel('资金账户列表',$excel);
}
public function accountinfo(){
return $this->fetch();
}
public function accountinfo_list(){
$input=input('post.');
if(isset_full($input,'pid') && isset_full($input,'page') && isset_full($input,'limit')){
$sql=get_sql($input,[
'type'=>'full_eq',
'set'=>'full_dec_1',
'user'=>'full_division_in',
'start_time'=>'stime',
'end_time'=>'etime',
'data'=>'full_like'
],'accountinfo') $sql=auth('accountinfo',$sql) $count = Accountinfo::where ($sql)->count() $arr = Accountinfo::with('userinfo,typedata')->where($sql)->page($input['page'],$input['limit'])->order('id desc')->select() $resule=[
'code'=>0,
'msg'=>'获取成功',
'count'=>$count,
'data'=>$arr
]
}else{
$resule=['state'=>'error','info'=>'传入参数不完整!'];
}
return json($resule);
}
public function export_accountinfo(){
$input=input('get.');
$sql=get_sql($input,[
'type'=>'full_eq',
'set'=>'full_dec_1',
'user'=>'full_division_in',
'start_time'=>'stime',
'end_time'=>'etime',
'data'=>'full_like'
],'accountinfo') $sql=auth('accountinfo',$sql) $info=Accounts::where(['id'=>$input['pid']])->find() $arr = Accountinfo::with('userinfo,typedata')->where($sql)->order('id desc')->select() $formfield=get_formfield('accountinfo_export','array') $excel=[] array_push($excel,['type'=>'title','info'=>'资金账户['.$info['name'].']明细信息']);
$table_cell=[] foreach ($formfield as $formfield_vo) {
$table_cell[$formfield_vo['key']]=$formfield_vo['text'];
}
$table_data=[] foreach ($arr as $arr_vo) {
$row_data=[];
foreach ($formfield as $formfield_vo) {
$val='nod_initial' foreach (explode('|',$formfield_vo['data']) as $source) {
$val=$val=='nod_initial'?$arr_vo[$source]:(isset($val[$source])?$val[$source]:'');
}
$row_data[$formfield_vo['key']]=$val }
array_push($table_data,$row_data) }
array_push($excel,['type'=>'table','info'=>['cell'=>$table_cell,'data'=>$table_data]]) array_push($excel,[
'type'=>'node',
'info'=>[
'开账日期:',$info['createtime'],
'期初余额:',$info['initial'],
'剩余资余额:',$info['balance']
]
]);
push_log('导出资金账户['.$info['name'].']明细信息') export_excel('资金账户['.$info['name'].']明细信息',$excel);
}
}