ZtPayController.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace app\api\controller;
  3. use app\models\trade\ZtpayCallback;
  4. use app\models\user\UserMoney;
  5. use app\Request;
  6. use crmeb\basic\BaseModel;
  7. use crmeb\services\ZtPayService;
  8. use think\Exception;
  9. class ZtPayController
  10. {
  11. public function notify(Request $request)
  12. {
  13. ob_clean();
  14. $param = $request->param();
  15. @file_put_contents('zt_pay.txt', "【" . date('Y-m-d H:i:s') . "】" . json_encode($param) . PHP_EOL, FILE_APPEND);
  16. $data = json_decode(json_encode($param), true);
  17. BaseModel::beginTrans();
  18. try {
  19. ZtpayCallback::create(
  20. [
  21. 'name' => $data['name'],
  22. 'name_alias' => $data['name_alias'],
  23. 'time' => $data['time'],
  24. 'sign' => $data['sign'],
  25. 'hash' => $data['data']['hash'],
  26. 'from' => $data['data']['from'],
  27. 'to' => $data['data']['to'],
  28. 'memo' => $data['data']['memo'],
  29. 'amount' => $data['data']['amount'],
  30. 'fee_amount' => $data['data']['fee_amount'],
  31. 'add_time' => strtotime($data['data']['add_time']),
  32. 'type' => $data['data']['type'],
  33. 'state' => $data['data']['state'],
  34. ]
  35. );
  36. if ($data['data']['type'] == 1 && $data['data']['state'] == 1) {
  37. $user = UserMoney::where('address' . ($data['name_alias'] ? ("_" . $data['name_alias']) : ""), $data['data']['to'])->value('uid');
  38. if ($user) {
  39. UserMoney::incomeMoney($user, $data['name'], $data['data']['amount'], 'recharge', '用户充值', '用户充值' . $data['data']['amount'] . $data['name']);
  40. }
  41. // $money_types = sys_data('money_type');
  42. // foreach ($money_types as $v) {
  43. // if ($data['data']['to'] == $v['__money_address']) {
  44. // $user = UserMoney::where('address', $data['data']['from'])->value('uid');
  45. // if ($user) {
  46. // UserMoney::incomeMoney($user, $v['code'], $data['data']['amount'], 'recharge', '用户充值', '用户充值' . $data['data']['amount'] . $v['name']);
  47. // }
  48. // }
  49. // }
  50. }
  51. BaseModel::commitTrans();
  52. echo 'SUCCESS';
  53. exit;
  54. } catch (Exception $e) {
  55. BaseModel::rollbackTrans();
  56. @file_put_contents('zt_pay.txt', "【" . date('Y-m-d H:i:s') . "】" . json_encode($e->getMessage()) . PHP_EOL, FILE_APPEND);
  57. echo 'FAIL';
  58. exit;
  59. }
  60. }
  61. }