Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function showUserTransactionMonthly($userId)
- {
- $monthlyTransaction = [];
- for ($i = 1; $i <= 12; $i++){
- $monthIsFraud = Transaction::whereMonth('created_at',$this->generateMonth($i))
- ->where('is_fraud',1)
- ->where('user_id',$userId)
- ->count();
- $monthIsNotFraud = Transaction::whereMonth('created_at',$this->generateMonth($i))
- ->where('is_fraud',0)
- ->where('user_id',$userId)
- ->count();
- $monthlyTransaction[] = [
- 'valueIsFraud' =>$monthIsFraud,
- 'valueNotFraud'=>$monthIsNotFraud
- ];
- }
- $isFraud=[];
- $isNotFraud=[];
- foreach ($monthlyTransaction as $item){
- $isFraud[]=$item['valueIsFraud'];
- $isNotFraud[]=$item['valueNotFraud'];
- }
- $params=[
- 'isFraud'=>$isFraud,
- 'notFraud'=>$isNotFraud
- ];
- return response()->json($params);
- }
- public function showUserTransactionByIp($userId)
- {
- $transaction=Transaction::select('ip_address')
- ->where('user_id',$userId)
- ->groupBy('ip_address')
- ->get();
- $isFraud=[];
- $isNotFraud=[];
- $ipAddress=[];
- foreach ($transaction as $item){
- $ipAddress[]=$item->ip_address;
- $IpIsFraud=Transaction::where(['ip_address'=>$item->ip_address,'user_id'=>$userId])
- ->where('is_fraud',1)->count();
- $IpNotFraud=Transaction::where(['ip_address'=>$item->ip_address,'user_id'=>$userId])
- ->where('is_fraud',0)->count();
- $isFraud[]=$IpIsFraud;
- $isNotFraud[]=$IpNotFraud;
- }
- $params=[
- 'ipAddress'=>$ipAddress,
- 'isFraud'=>$isFraud,
- 'notFraud'=>$isNotFraud
- ];
- return response()->json($params);
- }
- private function generateMonth($idx)
- {
- if(strlen($idx) < 2){
- $idx = '0'.$idx;
- }
- return $idx;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement