| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- /**
- * 描述.
- *
- * @author nj
- * @date 2021-08-18 12:59
- */
- namespace App\Repositories;
- use App\Models\Mysql\BalanceLogModel;
- use Carbon\Carbon;
- use KZ2\Laravel\Repositories\Eloquent\Repository;
- class BalanceLogRepository extends Repository
- {
- public function model()
- {
- return BalanceLogModel::class;
- }
- /**
- * 记录.
- * @param mixed $currAgent
- * @param mixed $prevAgent
- * @param string $changeNote 改变备注.
- * @return bool
- */
- public function record($currAgent, $prevAgent, $changeNote = '')
- {
- if (empty($currAgent->uid)) {
- logger('BalanceLogRepository::record', ['err' => '入参数据没有用户UID']);
- return false;
- }
- if (strval($currAgent->uid) !== strval($prevAgent->uid)) {
- logger('BalanceLogsRepository::record', ['err' => '前后2个用户不一致']);
- return false;
- }
- $result = false;
- $prevBalance = $prevAgent->balance; // 上次余额
- $currBalance = $currAgent->balance; // 当前余额
- $prevFrozen = $prevAgent->frozen; // 上次冻结
- $currFrozen = $currAgent->frozen; // 当前冻结
- $createdAt = Carbon::now()->toDateTimeString();
- $diffBalance = $currBalance - $prevBalance; // 前后余额差额
- $diffFrozen = $currFrozen - $prevFrozen; // 前后冻结资金差.
- if ($diffBalance != 0 || $diffFrozen != 0) {
- $item = [
- 'created_at' => $createdAt,
- 'agent_uid' => $currAgent->uid,
- 'curr_balance' => $currBalance,
- 'prev_balance' => $prevBalance,
- 'diff_balance' => $diffBalance,
- 'change_note' => $changeNote,
- 'curr_frozen' => $currFrozen,
- 'prev_frozen' => $prevFrozen,
- ];
- $result = BalanceLogModel::create($item);
- }
- return boolval($result);
- }
- }
|