更新code权限

This commit is contained in:
yaooo 2023-11-04 14:27:57 +08:00
parent d05f6389dd
commit b069478887
2 changed files with 83 additions and 82 deletions

View File

@ -163,7 +163,7 @@ abstract class ApiController
$authList = Cache::get('RulesSrc' . $uid);
$pathUrl = $prefixMod . '/' . $conMod . '/' . $action;
if (!in_array($pathUrl, $authList)) {
$this->apiError('用户无权限');
$this->apiError('用户无权限', [], 2);
}
}

View File

@ -51,6 +51,7 @@ class FinanceIncome extends ApiController
//新增
public function add()
{
$this->checkAuth();
$param = get_params();
$this->uid = JWT_UID;
$auth = isAuthIncome($this->uid);
@ -58,98 +59,97 @@ class FinanceIncome extends ApiController
$this->apiError("你没有到账管理权限请联系管理员或者HR");
}
$inid = $param['inid'];
$admin_id = $this->uid;
//计算已到账的金额
$hasIncome = InvoiceIncome::where(['inid'=>$inid,'status'=>1])->sum('amount');
//查询发票金额
$invoiceAmount = Invoice::where(['id'=>$inid])->value('amount');
if($param['enter_type']==1){ //单个到账记录
//相关内容多个数组
$enterPriceData=isset($param['amount'])? $param['amount'] : '';
$enterTimeData=isset($param['enter_time'])? $param['enter_time'] : '';
$remarksData=isset($param['remarks'])? $param['remarks'] : '';
$inid = $param['inid'];
$admin_id = $this->uid;
//计算已到账的金额
$hasIncome = InvoiceIncome::where(['inid'=>$inid,'status'=>1])->sum('amount');
//查询发票金额
$invoiceAmount = Invoice::where(['id'=>$inid])->value('amount');
if($param['enter_type']==1){ //单个到账记录
//相关内容多个数组
$enterPriceData=isset($param['amount'])? $param['amount'] : '';
$enterTimeData=isset($param['enter_time'])? $param['enter_time'] : '';
$remarksData=isset($param['remarks'])? $param['remarks'] : '';
//把合同协议关联的单个内容的发票入账明细重新添加
if($enterPriceData){
$enter_price = 0;
$insert = [];
$time = time();
foreach ($enterPriceData as $key => $value) {
if (!$value ) continue;
$insert[] = [
'inid' => $inid,
'amount' => $value,
'enter_time' => $enterTimeData[$key]? strtotime($enterTimeData[$key]) : 0,
'remarks' => $remarksData[$key],
'admin_id' => $admin_id,
'create_time' => $time
];
$enter_price += $value*100;
}
if(($enter_price + $hasIncome*100)> $invoiceAmount*100){
return to_assign(1,'到账金额大于发票金额,不允许保存');
}
else{
$res = InvoiceIncome::strict(false)->field(true)->insertAll($insert);
if($res!==false){
if(($enter_price + $hasIncome*100) == $invoiceAmount*100){
//发票全部到账
Invoice::where(['id'=>$inid])->update(['is_cash'=>2,'enter_amount'=>$invoiceAmount,'enter_time'=>time()]);
}
else if(($enter_price + $hasIncome*100) < $invoiceAmount*100){
$incomeTotal=($enter_price + $hasIncome*100)/100;
//发票部分到账
Invoice::where(['id'=>$inid])->update(['is_cash'=>1,'enter_amount'=>$incomeTotal,'enter_time'=>time()]);
}
add_log('add',$inid,$param);
return to_assign();
}
else{
return to_assign(1,'保存失败');
}
}
//把合同协议关联的单个内容的发票入账明细重新添加
if($enterPriceData){
$enter_price = 0;
$insert = [];
$time = time();
foreach ($enterPriceData as $key => $value) {
if (!$value ) continue;
$insert[] = [
'inid' => $inid,
'amount' => $value,
'enter_time' => $enterTimeData[$key]? strtotime($enterTimeData[$key]) : 0,
'remarks' => $remarksData[$key],
'admin_id' => $admin_id,
'create_time' => $time
];
$enter_price += $value*100;
}
if(($enter_price + $hasIncome*100)> $invoiceAmount*100){
return to_assign(1,'到账金额大于发票金额,不允许保存');
}
else{
return to_assign(1,'提交的到账数据异常,请核对再提交');
$res = InvoiceIncome::strict(false)->field(true)->insertAll($insert);
if($res!==false){
if(($enter_price + $hasIncome*100) == $invoiceAmount*100){
//发票全部到账
Invoice::where(['id'=>$inid])->update(['is_cash'=>2,'enter_amount'=>$invoiceAmount,'enter_time'=>time()]);
}
else if(($enter_price + $hasIncome*100) < $invoiceAmount*100){
$incomeTotal=($enter_price + $hasIncome*100)/100;
//发票部分到账
Invoice::where(['id'=>$inid])->update(['is_cash'=>1,'enter_amount'=>$incomeTotal,'enter_time'=>time()]);
}
add_log('add',$inid,$param);
return to_assign();
}
else{
return to_assign(1,'保存失败');
}
}
}
else if($param['enter_type']==2){ //全部到账记录
$enter_price = ($invoiceAmount*100-$hasIncome*100)/100;
$data = [
'inid' => $inid,
'amount' => $enter_price,
'enter_time' => isset($param['enter_time'])? strtotime($param['enter_time']) : 0,
'remarks' => '一次性全部到账',
'admin_id' => $admin_id,
'create_time' => time()
];
$res = InvoiceIncome::strict(false)->field(true)->insertGetId($data);
if($res!==false){
//设置发票全部到账
Invoice::where(['id'=>$inid])->update(['is_cash'=>2,'enter_amount'=>$invoiceAmount,'enter_time'=>time()]);
add_log('add',$inid,$param);
return to_assign();
}
else{
return to_assign(1,'提交的到账数据异常,请核对再提交');
}
else if ($param['enter_type']==3) {//全部反账记录
//作废初始化发票到账数据
$res = InvoiceIncome::where(['inid'=>$inid])->update(['status'=>'6','update_time'=>time()]);
if($res!==false){
//设置发票全部没到账
Invoice::where(['id'=>$inid])->update(['is_cash'=>0,'enter_amount'=>0,'enter_time'=>0]);
add_log('tovoid',$inid,$param);
return to_assign();
}
}
else if($param['enter_type']==2){ //全部到账记录
$enter_price = ($invoiceAmount*100-$hasIncome*100)/100;
$data = [
'inid' => $inid,
'amount' => $enter_price,
'enter_time' => isset($param['enter_time'])? strtotime($param['enter_time']) : 0,
'remarks' => '一次性全部到账',
'admin_id' => $admin_id,
'create_time' => time()
];
$res = InvoiceIncome::strict(false)->field(true)->insertGetId($data);
if($res!==false){
//设置发票全部到账
Invoice::where(['id'=>$inid])->update(['is_cash'=>2,'enter_amount'=>$invoiceAmount,'enter_time'=>time()]);
add_log('add',$inid,$param);
return to_assign();
}
}
else if ($param['enter_type']==3) {//全部反账记录
//作废初始化发票到账数据
$res = InvoiceIncome::where(['inid'=>$inid])->update(['status'=>'6','update_time'=>time()]);
if($res!==false){
//设置发票全部没到账
Invoice::where(['id'=>$inid])->update(['is_cash'=>0,'enter_amount'=>0,'enter_time'=>0]);
add_log('tovoid',$inid,$param);
return to_assign();
}
}
}
//查看
public function view()
{
$this->checkAuth();
$this->uid = JWT_UID;
$id = empty(get_params('id')) ? 0 : get_params('id');
$model = new Invoice();
@ -181,6 +181,7 @@ class FinanceIncome extends ApiController
//删除到账记录
public function delete()
{
$this->checkAuth();
$param = get_params();
$this->uid = JWT_UID;
if(empty($param['id'])){