account = $account; } /** * Execute the job. * * @return void */ public function handle() { $account = $this->account; if (empty($account)) return; //总收益是否匹配余额+提现金额+冻结金额 $res = $this->checkTatalValue($account); if (empty($res)) { $msg = "收益账号id:{$account->id},出现异常:总收益金额不匹配余额与提现金额总和"; $account->update(['is_banned'=>1, "reason"=>$msg]); throw new \Exception($msg); } //总提现金额是否匹配提现记录表 $res = $this->checkWithdrawValue($account); if (empty($res)) { $msg = "收益账号id:{$account->id},出现异常:总提现记录不匹配已提现金额与冻结提现金额总和"; $account->update(['is_banned'=>1, 'reason'=>$msg]); throw new \Exception($msg); } //商户还是用户 if ($this->account->m_user_id) { //用户 //总收益金额是否匹配收益表 $res = $this->checkUserEarningValue($account); if (empty($res)) { $msg = "收益账号id:{$account->id},出现异常:总收益金额不匹配收益记录表"; $account->update(['is_banned'=>1, 'reason'=>$msg]); throw new \Exception($msg); } }else { //商户 $res = $this->checkMerchantEarningValue($account); if (empty($res)) { $msg = "收益账号id:{$account->id},出现异常:总收益金额不匹配收益记录表"; $account->update(['is_banned'=>1, "reason"=>$msg]); throw new \Exception($msg); } } $account->update(['is_banned'=>0, 'reason'=>null]); return; } public function checkMerchantEarningValue($account) { //总收益金额 = 总收益记录金额 - 转账金额 //总收益金额 $earning_value = MEarning::where(['m_id'=>$account->m_id, 'm_user_id'=>$account->m_user_id])->sum("value"); //转账金额 $transfer_value = MerchantTransferLog::where(['m_id'=>$account->m_id])->sum('amount'); Log::info("总金额:{ $account->total_value }"); Log::info("收益金额-转账金额: $earning_value - $transfer_value = ".($earning_value - $transfer_value)); return $account->total_value == number_format($earning_value - $transfer_value, 2, '.', ''); } /** * 检测提现金额是否正确 * @param $account * @return bool */ public function checkWithdrawValue($account) { $value = MEarningwithdraws::where(['m_id'=>$account->m_id, 'm_user_id'=>$account->m_user_id])->where('status', '<>', 'canceled')->sum('value'); Log::info("总提现:{ $value }"); Log::info("总提现相加:{ $account->withdrawl + $account->frozen_withdraw }"); return $value == number_format($account->withdrawl + $account->frozen_withdraw, 2, '.', ''); } /** * 检测用户总收益金额是否正确 * @param $account * @return bool */ public function checkUserEarningValue($account) { $value = MEarning::where(['m_id'=>$account->m_id, 'm_user_id'=>$account->m_user_id])->sum("value"); Log::info("总收益金额:{ $account->total_value }"); Log::info("收益记录金额:{ $value }"); return $account->total_value == $value; } /** * 检测总金额是否正确 * @param $account * @return bool */ public function checkTatalValue($account) { $sum = number_format($account->balance + $account->withdrawl + $account->frozen_withdraw + $account->frozen_earning, 2, '.', ''); Log::info("总金额:{ $account->total_value }"); Log::info("总金额相加:{ $account->balance + $account->withdrawl + $account->frozen_withdraw + $account->frozen_earning} = $sum"); return $account->total_value == $sum; } }