LogHelper.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace App\Http\HelperTraits;
  3. use App\Models\AccountLog;
  4. trait LogHelper
  5. {
  6. /**
  7. * account log记录
  8. * @param $data
  9. * @return AccountLog
  10. * @throws \Exception
  11. */
  12. // public function writeAccountLog($data) {
  13. // if (!isset($data['obj_type']) || empty($data['obj_type'])) {
  14. // throw new \Exception('obj_type must be supplied and cannot be empty');
  15. // }
  16. // if (!isset($data['obj_id']) || empty($data['obj_id'])) {
  17. // throw new \Exception('obj_id must be supplied and cannot be empty');
  18. // }
  19. // if (!isset($data['direction'])) {
  20. // $data['direction'] = 1;
  21. // }
  22. // if ($data['direction'] != 1 && $data['direction'] != 2) {
  23. // throw new \Exception('direction must be 1 or 2');
  24. // }
  25. // if (isset($data['vm_type']) && !array_key_exists($data['vm_type'], AccountLog::getAllType())) {
  26. // throw new \Exception('vm_type invalid');
  27. // }
  28. // if (isset($data['channel']) && !array_key_exists($data['channel'], AccountLog::getAllChannels())) {
  29. // throw new \Exception('channel invalid');
  30. // }
  31. // if (isset($data['op']) && !array_key_exists($data['op'], AccountLog::getAllop())) {
  32. // throw new \Exception('op invalid');
  33. // }
  34. //
  35. // return AccountLog::create($data);
  36. // }
  37. //
  38. // public function logAccount($objType, $objId, $objName, $op, $vmType, $amount, $direction, $balance, $channel, $note = null) {
  39. // return $this->writeAccountLog([
  40. // 'obj_type' => $objType,
  41. // 'obj_id' => $objId,
  42. // 'obj_name' => $objName,
  43. // 'vm_type' => $vmType,
  44. // 'amount' => $amount,
  45. // 'balance' => $balance,
  46. // 'direction' => $direction,
  47. // 'op' => $op,
  48. // 'channel' => $channel,
  49. // 'note' => $note,
  50. // ]);
  51. // }
  52. private function logAccount($fromType, $fromId, $fromName, $fromAmount, $op, $toType, $toId, $toName, $toAmount) {
  53. return AccountLog::create([
  54. 'from_type' => $fromType,
  55. 'from_id' => $fromId,
  56. 'from_name' => $fromName,
  57. 'from_amount' => $fromAmount,
  58. 'op' => $op,
  59. 'to_type' => $toType,
  60. 'to_id' => $toId,
  61. 'to_name' => $toName,
  62. 'to_amount' => $toAmount,
  63. ]);
  64. }
  65. }