Files
yusheng-php/application/api/model/MarketValue.php
2025-11-28 15:29:53 +08:00

61 lines
2.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\api\model;
use think\Db;
use think\Model;
class MarketValue extends Model
{
/*
* 身价变化
* @param int $user_id 用户id
* @param int $change_value 身价变化值
* @param int $type 0-升值1-系统降身价2-使用降身卡
* * @return array
*/
public function change($user_id,$change_value,$type){
//判断是否为整数
if(!is_int($change_value)){
return ['code' => 0, 'msg' => '身价变化参数错误'];
}
$before = db::name('user')->where('id',$user_id)->value('market_value');
if($type == 0){
$result = db::name('user')->where('id',$user_id)->setInc('market_value',$change_value);
if($result){
//记录一条日志
db::name('vs_user_market_value_log')->insert([
'user_id' => $user_id,
'before' => $before,
'change_value' => $change_value,
'afterwards' => $before + $change_value,
'type' => $type,
'createtime' => time()
]);
}
}else{
//降身价
$change = $before-$change_value;
if($change <= 1){
$afterwards = 1;
$result = db::name('user')->where('id',$user_id)->update(['market_value' => 1]);
}else{
$afterwards = $change;
$result = db::name('user')->where('id',$user_id)->setDec('market_value',$change_value);
}
if($result){
//记录一条日志
db::name('vs_user_market_value_log')->insert([
'user_id' => $user_id,
'before' => $before,
'change_value' => $change_value,
'afterwards' => $afterwards,
'type' => $type,
'createtime' => time()
]);
}
}
return ['code' => 1, 'msg' => '成功'];
}
}