<?php
|
|
namespace app\common\model\supplier;
|
|
use app\common\model\BaseModel;
|
|
/**
|
* 商家供应商提现记录模型
|
*/
|
class Balance extends BaseModel
|
{
|
protected $name = 'supplier_user_balance';
|
protected $pk = 'balance_id';
|
|
|
/**
|
* 关联供应商表
|
*/
|
public function supplier()
|
{
|
return $this->belongsTo('app\\common\\model\\supplier\\Supplier', 'shop_supplier_id', 'shop_supplier_id');
|
}
|
|
/**
|
* 关联应用表
|
*/
|
public function user()
|
{
|
return $this->belongsTo('app\\common\\model\\user\\User', 'user_id', 'user_id');
|
}
|
|
/**
|
* 详情
|
*/
|
public static function detail($where)
|
{
|
$model = new static;
|
if (is_array($where)) {
|
$filter = $where;
|
} else {
|
$filter['balance_id'] = (int)$where;
|
}
|
return $model->where($filter)->with(['supplier', 'user'])->find();
|
}
|
|
/**
|
* 增加余额
|
*/
|
public function setIncBalance($shop_supplier_id,$user_id,$money)
|
{
|
$model = $this->where('user_id', '=', $user_id)
|
->where('shop_supplier_id', '=', $shop_supplier_id)
|
->find();
|
if(!empty($detail)){
|
return $model->where('user_id', '=', $user_id)
|
->where('shop_supplier_id', '=', $shop_supplier_id)
|
->inc('balance', $money)
|
->update();
|
}else{
|
$save_data = [
|
'user_id' => $user_id,
|
'shop_supplier_id' => $shop_supplier_id,
|
'balance' => $money,
|
];
|
return $this->save($save_data);
|
}
|
|
}
|
|
/**
|
* 减少余额
|
*/
|
public function setDecBalance($shop_supplier_id,$user_id,$money)
|
{
|
return $this->where('user_id', '=', $user_id)
|
->where('shop_supplier_id', '=', $shop_supplier_id)
|
->dec('balance', $money)
|
->update();
|
}
|
|
/**
|
* 获取总余额
|
*/
|
public static function getTotalBalance($user_id)
|
{
|
$model = new static();
|
return $model->where('user_id', '=', $user_id)
|
->sum("balance");
|
}
|
}
|