Circulation.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace App\Module\Fund\Service;
  3. use App\Module\Fund\Models\FundCirculationModel;
  4. /**
  5. * Class Circulation 资金流转的服务层
  6. *
  7. * @package logic\user\fund\Service
  8. */
  9. class Circulation
  10. {
  11. /**
  12. * 流转
  13. *
  14. * @param int $user_id 用户
  15. * @param int $fund_id 流出账户
  16. * @param int $to_fund_id 流入账户
  17. * @param int $amount 资金总数
  18. * @param string $remark 备注信息
  19. * @return bool|int|string
  20. */
  21. public static function handle($user_id, $fund_id, $to_fund_id, int $amount, int $re_id, string $re_type, $remark)
  22. {
  23. $data = [
  24. 'user_id' => $user_id,
  25. 'fund_id' => $fund_id,
  26. 'to_fund_id' => $to_fund_id,
  27. 'remark' => $remark,
  28. 're_id' => $re_id,
  29. 're_type' => $re_type,
  30. 'total_fee' => $amount,
  31. 'create_time' => time(),
  32. 'ok_time' => 0
  33. ];
  34. # 进行验证
  35. $va = new \App\Module\Fund\Validations\Circulation($data);
  36. $va->validate();
  37. if ($va->isFail()) {
  38. return $va->firstError();
  39. }
  40. $Model = new FundCirculationModel();
  41. $Model->setData($data);
  42. if ($Model->save() === false) {
  43. return $Model->getMessage();
  44. }
  45. return (int)$Model->id;
  46. }
  47. }