提交 0b7f6b3d authored 作者: chengye's avatar chengye 提交者: wangkr

payment to oa api

上级 7c2252b3
...@@ -107,12 +107,6 @@ function createPass(){ ...@@ -107,12 +107,6 @@ function createPass(){
return substr(md5(config('admin.passwd_salt').time()),0,10); return substr(md5(config('admin.passwd_salt').time()),0,10);
} }
//生成10位的随机密码
//将密码返回给控制器
//控制器通过MD加密之后存储到数据库
/** /**
* 基站状态递归实现无限极分类 * 基站状态递归实现无限极分类
* @param $array 分类数据 * @param $array 分类数据
......
...@@ -5,18 +5,18 @@ ...@@ -5,18 +5,18 @@
*/ */
namespace app\em\controller; namespace app\em\controller;
use app\admin\controller\Base; use app\admin\controller\Base;
use app\admin\model\DepartmentModel;
use app\admin\model\ElectricMeter; use app\admin\model\ElectricMeter;
use app\em\model\EmAccount; use app\em\model\EmAccount;
use app\em\model\EmCert; use app\em\model\EmCert;
use app\em\model\EmInvoice; use app\em\model\EmInvoice;
use app\em\model\EmInvoiceHistory;
use app\em\model\EmPayment; use app\em\model\EmPayment;
use app\em\model\EmPaymentFk;
use app\em\model\EmPaymentInvoice; use app\em\model\EmPaymentInvoice;
use app\em\model\EmPaymentInvoiceBalance; use app\em\model\EmPaymentInvoiceBalance;
use app\em\model\EmPaymentReceipt; use app\em\model\EmPaymentReceipt;
use app\em\model\Staff; use app\em\model\Staff;
use app\em\validate\AddPaymentValidate; use app\em\validate\AddPaymentValidate;
use function Sodium\library_version_major;
use think\Exception; use think\Exception;
use think\facade\Request; use think\facade\Request;
use think\facade\Session; use think\facade\Session;
...@@ -219,60 +219,6 @@ class Payment extends Base ...@@ -219,60 +219,6 @@ class Payment extends Base
return $this->fetch(); return $this->fetch();
} }
//更新缴费数据 即保存缴费 记录一次缴费
// public function update(){
// $data = Request::post();
//
// //更新缴费信息
// $payment = EmPayment::get(['payment_id'=>$data['payment_id']]);
// $payment->amount = $data['paid_totle']; //记录凭证金额
// $payment->staff_id = $data['staff_id'];
// //等待审核1,2已审核 1阶段暂忽略
// //$payment->status = 1;
// $payment->status = 2;
// $payment->save();
//
// //更新账单状态
// //1.查询所有账单
// $invArr = [];
// foreach ($data['paid'] as $key => $item) {
// $invArr['invoice_id'] = $key;
// $invArr['paid_amount'] = $item['paid_amount'];
// }
// /*
// * 循环查询账单 并计算balance的数值 更新balance,并将当前的状态,同步到历史数据一份进行销账的追踪
// * 通过与balance的计算结果比较 如果balance=0,则账单状态更新为已缴费 如果不为0则更新为部分缴费
// * 账单与缴费凭证关系的建立 通过缴费单与凭证的关联关系获取,显示在账单详情中
// */
// foreach ($invArr as $item){
// $inv = EmInvoice::get(['invoice_id'=>$item['invoice_id']]);
//
// $balance = $inv->payment_balance - $inv['paid_amount'];
//
// //计算状态
// if($balance == 0){
// $inv->status = setInvoiceStatus($inv->status,self::PAYMENT_FULL_CODE,self::PAYMENT_STATUS_INDEX);
// } else {
// $inv->status = setInvoiceStatus($inv->status,self::PAYMENT_PARTIAL_CODE,self::PAYMENT_STATUS_INDEX);
// }
//
// $inv->payment_balance = $balance;
//
// //更新账单信息
// $inv->save();
// //保存销账明细,复制当前对象数据 到history表
//
// $invHistory = new EmInvoiceHistory();
//
// if(!$invHistory->save($inv->toarray())){
// throw new Exception('保存销账明细错误!');
// } else {
// return json(['status'=>1,'message'=>'缴费成功!']);
// }
// }
//
// }
//缴费单详情 //缴费单详情
public function detail(){ public function detail(){
$payment_id = Request::param('payment_id'); $payment_id = Request::param('payment_id');
...@@ -280,6 +226,16 @@ class Payment extends Base ...@@ -280,6 +226,16 @@ class Payment extends Base
//查询缴费单基本信息 //查询缴费单基本信息
$payment = $epModel->where('payment_id','=',$payment_id)->find(); $payment = $epModel->where('payment_id','=',$payment_id)->find();
if($payment->status_fk != 0){
$fkModel = EmPaymentFk::get(['payment_id'=>$payment->payment_id]);
$fkModel->link = config('oafk.base_url').config('oafk.link') . $fkModel->oafk_id;
} else {
$fkModel = new EmPaymentFk();
$fkModel->oafk_numb = '';
$fkModel->link = '';
}
$this->assign('fk',$fkModel);
switch ($payment->status){ switch ($payment->status){
case 0: case 0:
$payment->statusTitle = '未缴费'; $payment->statusTitle = '未缴费';
...@@ -443,4 +399,139 @@ class Payment extends Base ...@@ -443,4 +399,139 @@ class Payment extends Base
$this->assign('data',$eibs); $this->assign('data',$eibs);
return $this->fetch(); return $this->fetch();
} }
public function payoa(){
$payment_id = Request::param('payment_id');
$user = Session::get('user');
$staff = Staff::get($user['user_id']);
$this->assign('payment_id',$payment_id);
$this->assign('payee',$this->getGys($staff->email));
$this->assign('payOrg',$this->getFkInfo(2));
$this->assign('payType',$this->getFkInfo(1));
return $this->fetch('pay_oa');
}
public function docnumb(){
$user = Session::get('user');
$staff = Staff::get($user['user_id']);
$dept = DepartmentModel::get($staff->d_id);
$post = Request::post();
$payment = EmPayment::get(['payment_id'=>$post['payment_id']]);
if($this->checkFkStatus($post['payment_id'])) return json(['status'=>0,'message'=>'该缴费单已经创建付款单无法再次创建.']);
$account = EmAccount::get(['account_id'=>$payment->account_id]);
$em = \app\em\model\Em::with('rule')->get($account->em_id);
$station = (new \app\em\model\Em)->getBaseInfo($account->em_id);
if($user['is_admin']) $staffName = 'admin';
else $staffName = substr($staff->email,0,strpos($staff->email,'@'));
$invs = (new EmPayment())->getinvsInfo($payment->payment_id);
$amount = 0;
foreach ($invs as $inv){
if($inv->payment_balance == 0){
$amount += 0;
} else if($inv->payment_amount == $inv->payment_balance){
$amount += $inv->payment_amount;
} else {
$amount += $inv->payment_amount - $inv->payment_balance;
}
}
$amount = round($amount,2);
$data = [
'title'=>$post['title'],
'uname'=>$staffName,
'payType'=>$post['payType'],
'dept'=>$dept->name,
'payee'=>$post['payee'],
'payOrg'=>$post['payOrg'],
'fkinfo'=>$post['fkinfo'],
'remarks'=>$post['remark'],
'type'=>2,
'date'=>$post['date'],
'details'=>[
[
'chargeType'=>"维护电费",
'amount'=> $amount,
'projectNumber'=> $station->proj_number,
'contractNumber'=> $em->rule->pay_protocol_numb,
'receipt'=>''
]
]
];
foreach ($data as $k => $v){
if(empty($v)) return json(['status'=>0,'message'=>'字段值全部必填,请检查']);
if($k == 'details') {
foreach ($v as $a=>$b){
foreach ($b as $aa => $bb){
if($aa != 'receipt'){
if(empty($bb)) return json(['status'=>0,'message'=>'金额为空,或成本中心编码不存在']);
}
}
}
}
}
$res = $this->createFkNumb($data);
$result = false;
if(!empty($res['data'])){
$payment->status_fk = 1;
$fkModel = new EmPaymentFk();
$fkModel->payment_id = $payment->payment_id;
$fkModel->oafk_id = $res['data']['id'];
$fkModel->oafk_numb = $res['data']['numb'];
$result = $payment->save() && $fkModel->save();
}
if($result)
return json(['status'=>1,'message'=>'创建单据成功']);
else
return json(['status'=>0,'message'=>'创建单据失败']);
}
public function apiKey(){
return md5(config('oafk.oa_key'));
}
public function getGys($email)
{
$url = config('oafk.base_url').config('oafk.gys') . $this->apiKey();
$data = ['email' => $email];
$res = httpPOST($url, $data);
$res = json_decode($res,true);
foreach ($res['data'] as $k => $v){
if(!empty($v['bank_info'])){
foreach ($v['bank_info'] as $a => $b){
$temp[$a] = '银行名称: '.$b['open_bank_name']. '账号: '.$b['bank_code'];
}
$res['data'][$k]['bankInfo'] = json_encode($temp);
}
}
return $res['data'];
}
public function getFkInfo($type){
$url = config('oafk.base_url').config('oafk.type') . $this->apiKey();
$data = ['type'=>$type];
$res = httpPOST($url, $data);
$res = json_decode($res,true);
return $res['data'];
}
public function createFkNumb($data){
$url = config('oafk.base_url').config('oafk.fk') . $this->apiKey();
$res = httpPOST($url, ['data'=>json_encode($data)]);
$res = json_decode($res,true);
return $res;
}
public function checkFkStatus($payment_id){
$res = (new EmPaymentFk())->get(['payment_id'=>$payment_id]);
return $res ? true : false;
}
} }
\ No newline at end of file
<?php
namespace app\em\model;
class EmPaymentFk extends Base
{
protected $table = 'em_payment_fk';
}
\ No newline at end of file
...@@ -70,10 +70,7 @@ ...@@ -70,10 +70,7 @@
缴费凭证: 缴费凭证:
</label> </label>
<div class="layui-input-inline"> <div class="layui-input-inline">
<a class="layui-btn layui-btn-normal layui-right" lay-submit lay-filter="showCert" onclick="return false;">查看</a> <a href="{$fk.link}">{$fk.oafk_numb|default='无'}</a>
{if $payment.status <= 3}
<button class="layui-btn layui-btn-normal layui-right" lay-submit lay-filter="addCert" onclick="return false;"><i class="layui-icon layui-icon-add-circle-fine"></i></button>
{/if}
</div> </div>
</div> </div>
</div> </div>
...@@ -130,7 +127,6 @@ ...@@ -130,7 +127,6 @@
</div> </div>
{/if} {/if}
<div class="layui-form-item layui-col-md-offset4"> <div class="layui-form-item layui-col-md-offset4">
{if $payment.status <= 3} {if $payment.status <= 3}
<button class="layui-btn" lay-filter="save" lay-submit="">提交</button> <button class="layui-btn" lay-filter="save" lay-submit="">提交</button>
...@@ -140,7 +136,7 @@ ...@@ -140,7 +136,7 @@
审核 审核
</button> </button>
{/if} {/if}
{if $payment.oa_numb == ''} {if $fk.oafk_numb == ''}
<button class="layui-btn" lay-filter="pay" lay-submit=""> <button class="layui-btn" lay-filter="pay" lay-submit="">
创建付款 创建付款
</button> </button>
...@@ -182,8 +178,6 @@ ...@@ -182,8 +178,6 @@
time: time, time: time,
}); });
} }
form.on('submit(submit)', form.on('submit(submit)',
function (data) { function (data) {
$.ajax({ $.ajax({
...@@ -239,6 +233,14 @@ ...@@ -239,6 +233,14 @@
} }
); );
form.on('submit(pay)',
function (data) {
$url = '/payment/payoa/{$payment.payment_id}'
xadmin.open('补充付款信息',$url)
return false;
}
);
//保存信息 //保存信息
form.on('submit(save)', form.on('submit(save)',
function (data) { function (data) {
...@@ -282,28 +284,6 @@ ...@@ -282,28 +284,6 @@
return false; return false;
}); });
//审核通过
form.on('submit(pay)',
function (data) {
$.ajax({
url: '/payment/payoa',
method: "POST",
data: data.field,
dataType: "json",
success: function (data) {
if (data.status == 1) {
layer.msg(data.message,{icon: 6,time: 2000},function(){
window.location.href="/payment"
})
} else {
layer.msg(data.message || data.msg,{icon: 5,time: 1000 })
}
}
});
return false;
});
//上传电表照片 //上传电表照片
var upPhoto = upload.render({ var upPhoto = upload.render({
elem: '#up_photo' , elem: '#up_photo' ,
......
{extend name="public:base" /}
{block name="body"}
<div class="layui-row">
<div class="layui-col-md12">
<div class="layui-card">
<form class="layui-form">
<!--添加结算凭证-->
<div class="layui-form-box">
<div class="layui-form-body">
<div class="layui-row">
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label layui-text-left">
缴费单号:
</label>
<div class="layui-input-inline">
<input type="text" name="payment_id" autocomplete="off"
class="layui-input" value="{$payment_id}" disabled="disabled">
</div>
</div>
</div>
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label layui-text-left">
单据抬头:
</label>
<div class="layui-input-inline">
<input type="text" name="title" autocomplete="off"
class="layui-input" value="电费付款">
</div>
</div>
</div>
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label layui-text-left">
汇款方式:
</label>
<div class="layui-input-inline">
<select name="payType" id="payType">
{volist name="payType" id="item"}
<option value="{$item.name}">{$item.name}</option>
{/volist}
</select>
</div>
</div>
</div>
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label layui-text-left">
收款方:
</label>
<div class="layui-input-inline">
<select name="payee" id="payee" lay-filter="change">
{volist name="payee" id="item"}
<option value="{$item.name}" data-info='{$item.bankInfo|default='
'}'>{$item.name}</option>
{/volist}
</select>
</div>
</div>
</div>
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label layui-text-left">
付款组织:
</label>
<div class="layui-input-inline">
<select name="payOrg" id="payOrg">
{volist name="payOrg" id="item"}
<option value="{$item.name}">{$item.name}</option>
{/volist}
</select>
</div>
</div>
</div>
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label layui-text-left">
付款日期:
</label>
<div class="layui-input-inline">
<input type="text" name="date" id="date" autocomplete="off" class="layui-input">
</div>
</div>
</div>
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label layui-text-left">
付款信息:
</label>
<div class="layui-input-inline">
<textarea class="layui-textarea" name="fkinfo" id="fkinfo"></textarea>
</div>
</div>
</div>
<div class="layui-col-md5">
<div class="layui-form-item">
<label class="layui-form-label layui-text-left">
备注:
</label>
<div class="layui-input-inline">
<textarea class="layui-textarea" name="remark" id="remark"></textarea>
</div>
</div>
</div>
</div>
<div class="layui-form-item layui-col-md-offset4">
<button class="layui-btn" lay-filter="submit" lay-submit="">
创建
</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
{/block}
{block name="js"}
<script type="text/javascript">
//初始化Layui控件
layui.use(['form', 'layer', 'laydate', 'upload'],
function () {
$ = layui.jquery;
var form = layui.form,
layer = layui.layer,
laydate = layui.laydate;
form.on('select(change)', function (data) {
var that = $(data.elem);
var info = that.find('option:selected').data('info');
$("#fkinfo").text(info);
});
laydate.render({
elem: '#date',
trigger: 'click',
});
//消息提示
function layMsg(msg, type = 6, time = 1000) {
layer.msg(msg, {
icon: type,
time: time,
});
}
//生成缴费单
form.on('submit(submit)',
function (data) {
$.ajax({
url: '/payment/docnumb',
method: "POST",
data: data.field,
dataType: "json",
success: function (data) {
if (data.status == 1) {
layer.msg(data.message, {icon: 6, time: 3000}, function () {
xadmin.close();
// 可以对父窗口进行刷新
xadmin.father_reload();
})
} else {
layer.msg(data.message, {icon: 5, time: 3000})
}
}
});
return false;
});
});
</script>
{/block}
<?php
return [
'oa_key' => '5bdfcedb618e1e03abf18e391278c1f4',
'base_url' => 'http://chengye-dev.gonn.tech',
'gys' => '/api.php?m=opensupplier&a=list&openkey=',
'type' => '/api.php?m=openfkinfo&a=fkinfor&openkey=',
'fk' => '/api.php?m=openfk&a=create&openkey=',
'link'=>'/task.php?a=p&num=oayfk&mid='
];
?>
\ No newline at end of file
...@@ -168,6 +168,8 @@ Route::post('payment/createAll','em/payment/createAll'); ...@@ -168,6 +168,8 @@ Route::post('payment/createAll','em/payment/createAll');
Route::post('payment/update','em/payment/update'); Route::post('payment/update','em/payment/update');
Route::post('payment/save','em/payment/store'); Route::post('payment/save','em/payment/store');
Route::post('payment/confirm','em/payment/confirm'); Route::post('payment/confirm','em/payment/confirm');
Route::get('payment/payoa/:payment_id','em/payment/payoa');
Route::post('payment/docnumb','em/payment/docnumb');
//结算 //结算
Route::get('settle','em/settle/index'); Route::get('settle','em/settle/index');
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论