| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace App\Module\Fund\Models;
- use App\Module\User\Models\User;
- use UCore\ModelCore;
- /**
- * 资金表
- *
- * field start
- * field end
- *
- */
- class FundModel extends ModelCore
- {
- protected $table = 'fund';
- public $timestamps = false;
- /**
- *
- * @param $user_id
- * @param $fund_id
- * @return false|FundModel
- */
- static public function getAccount($user_id, $fund_id)
- {
- $q = self::query()->where([
- 'user_id' => $user_id,
- 'fund_id' => $fund_id
- ])->lockForUpdate()->first();
- return $q;
- }
- /**
- * @param $userId
- * @param $fundIds
- * @return \Illuminate\Database\Eloquent\Collection
- * 获取用户全部资金账户
- */
- public static function getAllAccount($userId, $fundIds)
- {
- $query = self::query();
- $query->where('user_id', $userId);
- $query->whereIn('fund_id', $fundIds);
- return $query->get();
- }
- public function user()
- {
- return $this->hasOne(User::class, 'id', 'user_id');
- }
- //
- // public function userInfo()
- // {
- // return $this->hasOne(UserInfo::class, 'user_id', 'user_id');
- // }
- /**
- * @param $userId
- * @param $fundId
- * @param $amount
- * @return int
- * 减少资金
- */
- public static function dec($userId, $fundId, $amount)
- {
- $query = self::query();
- $query->where('user_id', $userId);
- $query->where('fund_id', $fundId);
- return $query->decrement('balance', $amount);
- }
- /**
- * @param $userId
- * @param $fundId
- * @param $amount
- * @return int
- * 增加资金
- */
- public static function inc($userId, $fundId, $amount)
- {
- $query = self::query();
- $query->where('user_id', $userId);
- $query->where('fund_id', $fundId);
- return $query->increment('balance', $amount);
- }
- }
|