12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- namespace app\api\controller;
- use app\models\trade\ZtpayCallback;
- use app\models\user\UserMoney;
- use app\Request;
- use crmeb\basic\BaseModel;
- use crmeb\services\ZtPayService;
- use think\Exception;
- class ZtPayController
- {
- public function notify(Request $request)
- {
- ob_clean();
- $param = $request->param();
- @file_put_contents('zt_pay.txt', "【" . date('Y-m-d H:i:s') . "】" . json_encode($param) . PHP_EOL, FILE_APPEND);
- $data = json_decode(json_encode($param), true);
- BaseModel::beginTrans();
- try {
- ZtpayCallback::create(
- [
- 'name' => $data['name'],
- 'name_alias' => $data['name_alias'],
- 'time' => $data['time'],
- 'sign' => $data['sign'],
- 'hash' => $data['data']['hash'],
- 'from' => $data['data']['from'],
- 'to' => $data['data']['to'],
- 'memo' => $data['data']['memo'],
- 'amount' => $data['data']['amount'],
- 'fee_amount' => $data['data']['fee_amount'],
- 'add_time' => strtotime($data['data']['add_time']),
- 'type' => $data['data']['type'],
- 'state' => $data['data']['state'],
- ]
- );
- if ($data['data']['type'] == 1 && $data['data']['state'] == 1) {
- $user = UserMoney::where('address' . ($data['name_alias'] ? ("_" . $data['name_alias']) : ""), $data['data']['to'])->value('uid');
- if ($user) {
- UserMoney::incomeMoney($user, $data['name'], $data['data']['amount'], 'recharge', '用户充值', '用户充值' . $data['data']['amount'] . $data['name']);
- }
- // $money_types = sys_data('money_type');
- // foreach ($money_types as $v) {
- // if ($data['data']['to'] == $v['__money_address']) {
- // $user = UserMoney::where('address', $data['data']['from'])->value('uid');
- // if ($user) {
- // UserMoney::incomeMoney($user, $v['code'], $data['data']['amount'], 'recharge', '用户充值', '用户充值' . $data['data']['amount'] . $v['name']);
- // }
- // }
- // }
- }
- BaseModel::commitTrans();
- echo 'SUCCESS';
- exit;
- } catch (Exception $e) {
- BaseModel::rollbackTrans();
- @file_put_contents('zt_pay.txt', "【" . date('Y-m-d H:i:s') . "】" . json_encode($e->getMessage()) . PHP_EOL, FILE_APPEND);
- echo 'FAIL';
- exit;
- }
- }
- }
|