Circulation.php 1.4 KB

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