Files
yusheng-php/application/api/model/MarketValue.php
2025-12-01 15:03:05 +08:00

57 lines
1.9 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-使用降身卡,3-签约溢价 涨身价
* * @return array
*/
public function change($user_id,$change_value,$type){
$before = db::name('user')->where('id',$user_id)->value('market_value');
if($type == 0 || $type == 3){
$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' => '成功'];
}
}