1. 快速获得记录条数
$medalCnt = MedalUser::select(DB::raw('count(*) as medal_cnt'))
->where('uid', $this->uid)
->where('medal_id', $medalId)
->value('medal_cnt');
2. 减少某项值
$affected = Wallet::where('uid', $this->uid)->where('coin_id', 12)
->decrement('total',$medal['exchange_num']);
if (!$affected) {
throw new \Exception('变更失败');
}
3. 增加某项值
$affected = MedalUserLiveness::where(