| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- namespace App\Module\Fund\Service;
- use App\Module\Fund\Models\FundCirculationModel;
- /**
- * Class Circulation 资金流转的服务层
- *
- * @package logic\user\fund\Service
- */
- class Circulation
- {
- /**
- * 流转
- *
- * @param int $user_id 用户
- * @param int $fund_id 流出账户
- * @param int $to_fund_id 流入账户
- * @param int $amount 资金总数
- * @param string $remark 备注信息
- * @return bool|int|string
- */
- public static function handle($user_id, $fund_id, $to_fund_id, int $amount, int $re_id, string $re_type, $remark)
- {
- $data = [
- 'user_id' => $user_id,
- 'fund_id' => $fund_id,
- 'to_fund_id' => $to_fund_id,
- 'remark' => $remark,
- 're_id' => $re_id,
- 're_type' => $re_type,
- 'total_fee' => $amount,
- 'create_time' => time(),
- 'ok_time' => 0
- ];
- # 进行验证
- $va = new \App\Module\Fund\Validations\Circulation($data);
- $va->validate();
- if ($va->isFail()) {
- return $va->firstError();
- }
- $Model = new FundCirculationModel();
- $Model->setData($data);
- if ($Model->save() === false) {
- return $Model->getMessage();
- }
- return (int)$Model->id;
- }
- }
|