Circulation.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace App\Module\Fund\Logic;
  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 float $amount 资金总数(小数形式)
  18. * @param int $re_id 关联ID
  19. * @param string $re_type 关联类型
  20. * @param string $remark 备注信息
  21. * @return bool|int|string
  22. */
  23. public static function handle($user_id, $fund_id, $to_fund_id, float $amount, int $re_id, string $re_type, $remark)
  24. {
  25. $data = [
  26. 'user_id' => $user_id,
  27. 'fund_id' => $fund_id,
  28. 'to_fund_id' => $to_fund_id,
  29. 'remark' => $remark,
  30. 're_id' => $re_id,
  31. 're_type' => $re_type,
  32. 'total_fee' => $amount,
  33. 'create_time' => time(),
  34. 'ok_time' => 0
  35. ];
  36. # 进行验证
  37. $va = new \App\Module\Fund\Validations\Circulation($data);
  38. $va->validate();
  39. if ($va->isFail()) {
  40. return $va->firstError();
  41. }
  42. $Model = new FundCirculationModel();
  43. $Model->setData($data);
  44. if ($Model->save() === false) {
  45. return $Model->getMessage();
  46. }
  47. return (int)$Model->id;
  48. }
  49. }