90 lines
1.9 KiB
PHP
90 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Model;
|
|
|
|
use Hyperf\DbConnection\Model\Model;
|
|
|
|
/**
|
|
* @property int $id
|
|
* @property int $user_id
|
|
* @property string $balance
|
|
* @property string $integral
|
|
*/
|
|
class UserAccount extends Model
|
|
{
|
|
/**
|
|
* The table associated with the model.
|
|
*/
|
|
protected ?string $table = 'user_account';
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*/
|
|
protected array $fillable = [];
|
|
protected array $guarded = [];
|
|
|
|
/**
|
|
* The attributes that should be cast to native types.
|
|
*/
|
|
protected array $casts = ['id' => 'integer', 'user_id' => 'integer'];
|
|
|
|
const CREATED_AT = null;
|
|
const UPDATED_AT = null;
|
|
|
|
/**
|
|
* @param int $userId
|
|
* @return \Hyperf\Database\Model\Model|UserAccount|null
|
|
*/
|
|
public function getAccountByUserId(int $userId): \Hyperf\Database\Model\Model|UserAccount|null
|
|
{
|
|
return $this->where('user_id',$userId)->first();
|
|
}
|
|
|
|
/**
|
|
* 增加积分
|
|
* @param $userId
|
|
* @param $num
|
|
* @return int
|
|
*/
|
|
public function incPointByUserId($userId, $num): int
|
|
{
|
|
return $this->where('id', $userId)->increment('integral', $num);
|
|
}
|
|
|
|
/**
|
|
* 减少积分
|
|
* @param $userId
|
|
* @param $num
|
|
* @return int
|
|
*/
|
|
public function decIntegralByUserId($userId, $num): int
|
|
{
|
|
return $this->where('id', $userId)->decrement('integral', $num);
|
|
}
|
|
|
|
|
|
/**
|
|
* 增加余额
|
|
* @param $userId
|
|
* @param $num
|
|
* @return int
|
|
*/
|
|
public function incBalanceByUserId($userId, $num): int
|
|
{
|
|
return $this->where('id', $userId)->increment('balance', $num);
|
|
}
|
|
|
|
/**
|
|
* 减少余额
|
|
* @param $userId
|
|
* @param $num
|
|
* @return int
|
|
*/
|
|
public function decBalanceByUserId($userId, $num): int
|
|
{
|
|
return $this->where('id', $userId)->decrement('balance', $num);
|
|
}
|
|
}
|