You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
3.9 KiB

  1. <?php
  2. namespace App\Service;
  3. use App\Model\FinancialRecord;
  4. class FinancialRecordService implements FinancialRecordServiceInterface
  5. {
  6. /**
  7. * @inheritDoc
  8. */
  9. public function communityAwardByPlatNewUser($user_id, $source_id, $money, $user_type=2, $source_type=1, $money_type=1, $desc='新用户奖励', $comment='社区服务点')
  10. {
  11. $this->record(
  12. $user_id,
  13. [
  14. 'user_id' => $user_id,
  15. 'user_type' => $user_type,
  16. 'money' => $money,
  17. 'money_type' => $money_type,
  18. 'source_id' => $source_id,
  19. 'source_type' => $source_type,
  20. 'desc' => $desc,
  21. 'comment' => $comment,
  22. 'status' => FinancialRecord::STATUS_NORMAL,
  23. ]
  24. );
  25. $this->ledgerAccounts($source_id, $money, $source_type, $money_type, $desc, $comment);
  26. }
  27. /**
  28. * @inheritDoc
  29. */
  30. public function communityAwardByPlatNewUserFirstOLOrder($user_id, $source_id, $money, $user_type=2, $source_type=1, $money_type=1, $desc='新用户首单奖励', $comment='社区服务点')
  31. {
  32. $this->record(
  33. $user_id,
  34. [
  35. 'user_id' => $user_id,
  36. 'user_type' => $user_type,
  37. 'money' => $money,
  38. 'money_type' => $money_type,
  39. 'source_id' => $source_id,
  40. 'source_type' => $source_type,
  41. 'desc' => $desc,
  42. 'comment' => $comment,
  43. 'status' => FinancialRecord::STATUS_NORMAL,
  44. ]
  45. );
  46. $this->ledgerAccounts($source_id, $money, $source_type, $money_type, $desc, $comment);
  47. }
  48. /**
  49. * @inheritDoc
  50. */
  51. public function communitySeparateAccountsByOrderComp($user_id, $source_id, $money, $user_type=2, $source_type=1, $money_type=2, $desc='用户订单分成', $comment='社区服务点')
  52. {
  53. $this->record(
  54. $user_id,
  55. [
  56. 'user_id' => $user_id,
  57. 'user_type' => $user_type,
  58. 'money' => $money,
  59. 'money_type' => $money_type,
  60. 'source_id' => $source_id,
  61. 'source_type' => $source_type,
  62. 'desc' => $desc,
  63. 'comment' => $comment,
  64. 'status' => FinancialRecord::STATUS_NORMAL,
  65. ]
  66. );
  67. $this->ledgerAccounts($source_id, $money, $source_type, $money_type, $desc, $comment);
  68. }
  69. public function ledgerAccounts($source_id, $money, $source_type, $money_type, $desc, $comment='')
  70. {
  71. return $this->record(
  72. FinancialRecord::ACCOUNT_LEDGER,
  73. [
  74. 'user_id' => FinancialRecord::ACCOUNT_LEDGER,
  75. 'user_type' => FinancialRecord::USER_TYPE_LEDGER,
  76. 'money' => $money,
  77. 'money_type' => $money_type,
  78. 'source_id' => $source_id,
  79. 'source_type' => $source_type,
  80. 'desc' => $desc,
  81. 'comment' => $comment,
  82. 'status' => FinancialRecord::STATUS_NORMAL,
  83. ],
  84. true
  85. );
  86. }
  87. public function record($user_id, $record, $isLedger=false)
  88. {
  89. $financialRecord = new FinancialRecord();
  90. if (!$isLedger) {
  91. $mod = bcmod((string)$user_id, '5', 0);
  92. $financialRecord->suffix($mod);
  93. }
  94. return $financialRecord->fill(
  95. [
  96. 'user_id' => $user_id,
  97. 'user_type' => $record['user_type'],
  98. 'money' => $record['money'],
  99. 'money_type' => $record['money_type'],
  100. 'source_id' => $record['source_id'],
  101. 'source_type' => $record['source_type'],
  102. 'desc' => $record['desc'],
  103. 'comment' => $record['comment'],
  104. 'status' => $record['status'],
  105. ]
  106. )->save();
  107. }
  108. }