You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.6 KiB
70 lines
1.6 KiB
<?php
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class LanzuUserBalance extends Model
|
|
{
|
|
protected $table = 'lanzu_user_balance';
|
|
protected $dateFormat = 'U';
|
|
|
|
/**
|
|
* 获取可提现金额
|
|
* @param $uid
|
|
* @param $uType 0/1 普通用户/服务商
|
|
*/
|
|
public static function getBalance($uid, $uType = 0)
|
|
{
|
|
$row = self::where(['source_id' => $uid, 'user_type' => $uType])->first();
|
|
if ($row) {
|
|
return $row->balance;
|
|
} else {
|
|
return '0.00';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 扣减可提现金额
|
|
*/
|
|
public static function reduceBalance($sid, $type, $reduceMoney)
|
|
{
|
|
$row = self::where(['source_id' => $sid, 'user_type' => $type])->first();
|
|
if ($row) {
|
|
$row->balance = $row->balance - $reduceMoney;
|
|
return $row->save();
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 回退审核未通过时的提现金额
|
|
*/
|
|
public static function returnBalance($sid, $uType, $returnMoney)
|
|
{
|
|
$row = self::where(['source_id' => $sid, 'user_type' => $uType])->first();
|
|
if ($row) {
|
|
$row->balance = $row->balance + $returnMoney;
|
|
return $row->save();
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 生成一条数据
|
|
*/
|
|
public static function create($sid, $type)
|
|
{
|
|
$self = new self();
|
|
$self->source_id = $sid;
|
|
$self->user_type = $type;
|
|
$self->balance = 0;
|
|
$self->save();
|
|
}
|
|
|
|
|
|
}
|