1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
/**
* Created by PhpStorm.
* User: chouchou
* Date: 2020-6-21
* Time: 18:52
*/
namespace app\api\controller\v2\common;
use app\em\controller\WriteOff;
use app\em\model\EmAccount;
use app\em\model\EmPayment;
use app\em\model\EmPaymentFk;
use app\em\model\EmPaymentInvoice;
use think\facade\Log;
class Payment
{
public function index()
{
$data = request()->get();
$res = $this->checkKey($data['key']);
if ($res !== true) return json([
'code' => 201,
'message' => $res,
'data' => ''
]);
if ($data['action'] == 1) {
Log::record(date('Y-m-d H:i:s').' OA单号:'.$data['numb'].' 接口操作:单据状态更新');
return $this->update($data['numb'],$data['status'],$data['mes']);
} else {
return $this->dropNumb($data['numb'],$data['status']);
}
}
//更新payment状态
private function update($numb,$status,$mes='')
{
$paymentFk = (new EmPaymentFk())->get(['oafk_numb' => $numb]);
$payment = (new EmPayment())->get(['payment_id' => $paymentFk->payment_id]);
$account = EmAccount::get(['account_id'=>$payment->account_id]);
$account->amount += $payment->amount ;
$account->save();
$payment->status = $status;
$payment->pay_date = time();
$payment->save();
$res = (new WriteOff())->writeOffFromPayment($payment->payment_id);
Log::record(date('Y-m-d H:i:s').' OA单号:'.$numb . $res);
}
//作废单据
private function dropNumb($numb,$status)
{
$paymentFk = (new EmPaymentFk())->get(['oafk_numb' => $numb]);
$payment = (new EmPayment())->get(['payment_id' => $paymentFk->payment_id]);
$paymentFk->delete();
$payment->status = $status;
$payment->save();
//删除payment_invoice表
$delNum = (new EmPaymentInvoice())->where('payment_id', '=', $payment->payment_id)->delete();
Log::record(date('Y-m-d H:i:s').' OA单号:'.$numb. '缴费单已作废');
}
private function checkKey($key)
{
if (empty($key)) {
return '秘钥不能为空';
}
$baseKey = substr(md5(config('oafk.oa_key') . date('Y-m-d')), 0, 12);
if ($key != $baseKey) {
return '秘钥错误';
}
return true;
}
public function setInvoiceStatus($statusCode, $value, $index = 0)
{
return substr_replace($statusCode, $value, $index, 1);
}
}