1074 lines
36 KiB
PHP
1074 lines
36 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Mobile;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\Request;
|
|
use App\Models\Lelong;
|
|
use App\Models\LelongBid;
|
|
use App\Models\LelongBidder;
|
|
use App\Models\LelongBidMarhun;
|
|
use App\Models\LelKarat;
|
|
use App\Models\User;
|
|
use App\Models\Payment;
|
|
use App\Models\Cart;
|
|
use Carbon\Carbon;
|
|
use App\Models\Cawangan;
|
|
use App\Models\Resit;
|
|
use App\Models\FileResit;
|
|
use App\Models\Invoice;
|
|
use App\Models\JenisEmas;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
class LelongMobileController extends Controller
|
|
{
|
|
|
|
public function getlelongdetails(Request $request){
|
|
|
|
$currentdate = Carbon::now();
|
|
$currentdate = $currentdate->toDateString();
|
|
|
|
// $arrayLelong = [];
|
|
$lelong = Lelong::where('tarikh_lelong','=',$currentdate)
|
|
->where('sts_lelong','=',1)
|
|
->get()->toArray();
|
|
|
|
if($lelong)
|
|
{
|
|
foreach($lelong as $index1=>$lel)
|
|
{
|
|
$lelongbid = LelongBid::whereIn('lelong_id',$lelong)
|
|
->get()->toArray();
|
|
|
|
$lelong[$index1]['lelongbid'] = $lelongbid;
|
|
|
|
foreach($lelongbid as $index2=>$lelbidmarhun){
|
|
$cawangan = Cawangan::where('id','=',$lelbidmarhun['caw_id'])->first()->toArray();
|
|
// $id = lelongbid::first();
|
|
|
|
$lelongbidmarhun = LelongBidMarhun::where('lelongbid_id', $lelbidmarhun['id'])
|
|
->get()->toArray();
|
|
|
|
$lelong[$index1]['lelongbid'][$index2]['lelongbidmarhun'] = $lelongbidmarhun;
|
|
$lelong[$index1]['lelongbid'][$index2]['cawangan'] = $cawangan;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
$lelong[0]['lelongbid'] = [];
|
|
}
|
|
|
|
return response()->json($lelong);
|
|
|
|
}
|
|
|
|
public function getListKarat()
|
|
{
|
|
|
|
$activeLelong = Lelong::where('sts_lelong', '=', 1)->first();
|
|
if (isset($activeLelong)) {
|
|
$getKarat = LelKarat::where('lelong_id', '=' ,$activeLelong['id'])->get();
|
|
|
|
$updatedDateTime = $getKarat[0]['updated_at']->toDateTimeString();
|
|
return response()->json([
|
|
'success' => true,
|
|
'karat' => $getKarat,
|
|
'update_time' => $updatedDateTime
|
|
], 201);
|
|
} else {
|
|
return response()->json([
|
|
'success' => false,
|
|
], 201);
|
|
}
|
|
|
|
}
|
|
|
|
public function bidderSelectBidItem(Request $request){
|
|
|
|
// $feepayment = Payment::join('resit', 'payment.resit_id','=','resit.id')
|
|
// ->where('payment.user_id',$request->user_id)
|
|
// ->where('payment.lelong_id', '=', $request->lelong_id)
|
|
// ->where('resit.resit_type',1)
|
|
// ->where('resit.status','PAID')->first();
|
|
// // dd($feepayment);
|
|
// if($feepayment != null){
|
|
|
|
$user = User::where('id', '=', $request->user_id)
|
|
->first();
|
|
|
|
$carts = Cart::join('lelongbid', 'carts.lelongbid_id', '=', 'lelongbid.id')
|
|
// ->join('lelong', 'lelongbid.lelong_id', '=', 'lelong.id')
|
|
// ->where('lelong.sts_lelong','=',1)
|
|
->where('carts.user_id', $user->id)
|
|
->select('lelongbid.id as lelongbid_id',
|
|
'lelongbid.t_lelong',
|
|
'lelongbid.nilaimarhun',
|
|
'lelongbid.cajlelong',
|
|
'carts.hargabida',
|
|
'carts.id as cart_id')
|
|
->get();
|
|
// dd($carts);
|
|
// dd($selectBid[0]->hargabida);
|
|
|
|
$currentdate = Carbon::now()->toDateTimeString();
|
|
|
|
foreach($carts as $cart)
|
|
{
|
|
$lelongBidder = new LelongBidder();
|
|
$lelongBidder->nama_bidder = $request->name;
|
|
$lelongBidder->user_id = $user->id;
|
|
$lelongBidder->notelbimbit = $user->notelbimbit;
|
|
$lelongBidder->hargabida = $cart->hargabida;
|
|
$lelongBidder->lelongbid_id = $cart->lelongbid_id;
|
|
$lelongBidder->nilaimarhun = $cart->nilaimarhun;
|
|
$lelongBidder->cajlelong = $cart->cajlelong;
|
|
$lelongBidder->masa_bidaan = $currentdate;
|
|
if($lelongBidder->save())
|
|
{
|
|
$delincart = Cart::where('id',$cart->cart_id)->first();
|
|
$delincart->delete();
|
|
}
|
|
|
|
}
|
|
|
|
$response = [
|
|
'success' => "success",
|
|
'message' => "Bidder berjaya disimpan"
|
|
];
|
|
|
|
return response()->json($response, 201);
|
|
// }
|
|
// else if($feepayment == null){
|
|
|
|
// $response = [
|
|
// 'success' => "error",
|
|
// 'message' => "Something wrong with the server"
|
|
// ];
|
|
// return response()->json($response, 201);
|
|
// }
|
|
}
|
|
|
|
public function listBidItem(Request $request){
|
|
|
|
$lelongbidder = LelongBidder::where('user_id','=', $request->user_id)
|
|
->get()->toArray();
|
|
|
|
foreach($lelongbidder as $index1=>$lelbid)
|
|
{
|
|
$lelongbid = LelongBid::whereIn('id',$lelongbidder)
|
|
->get()->toArray();
|
|
|
|
$lelongbidder[$index1]['lelongbid'] = $lelongbid;
|
|
}
|
|
|
|
return response()->json($lelongbidder);
|
|
}
|
|
|
|
public function bidRecord(Request $request)
|
|
{
|
|
$lelongbidder = LelongBidder::join('lelongbid', 'lelongbidder.lelongbid_id', '=', 'lelongbid.id')
|
|
->where('user_id', '=', $request->user_id)
|
|
->where('lelong_id', '=', $request->lelong_id)
|
|
->get()->toArray();
|
|
foreach ($lelongbidder as $index => $data) {
|
|
$cawangan = Cawangan::where('caw_code', '=', $data['kodcaw'])->select('caw_name')->first();
|
|
$lelongbidder[$index]['caw_name'] = $cawangan['caw_name'];
|
|
}
|
|
|
|
return response()->json($lelongbidder);
|
|
}
|
|
|
|
public function bidRecordByCawangan($userId, Request $request)
|
|
{
|
|
$groupCawangan = LelongBidder::join('lelongbid', 'lelongbidder.lelongbid_id', '=', 'lelongbid.id')
|
|
->join('cawangan', 'lelongbid.caw_id', '=', 'cawangan.id')
|
|
->where('user_id', '=', $userId)
|
|
->where('lelong_id', $request->lelongId)
|
|
->select('caw_id', 'caw_name')
|
|
->groupBy('caw_id')
|
|
->get()->toArray();
|
|
|
|
foreach ($groupCawangan as $index => $cawangan) {
|
|
|
|
$lelongBidder = LelongBidder::join('lelongbid', 'lelongbidder.lelongbid_id', '=', 'lelongbid.id')
|
|
->where('user_id', $userId)
|
|
->where('caw_id', $cawangan)
|
|
->get()->toArray();
|
|
|
|
foreach ($lelongBidder as $index1 => $data) {
|
|
|
|
$marhun = LelongBidMarhun::where('lelongbid_id', '=', $data['id'])->get()->toArray();
|
|
$lelongBidder[$index1]['lelongbidmarhun'] = $marhun;
|
|
}
|
|
$groupCawangan[$index]['lelongbid'] = $lelongBidder;
|
|
}
|
|
|
|
if ($groupCawangan) {
|
|
return response()->json([
|
|
'success' => true,
|
|
'lelongbidder' => $groupCawangan
|
|
], 201);
|
|
} else {
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => 'Empty Data'
|
|
], 201);
|
|
}
|
|
}
|
|
|
|
// please do not delete this changes
|
|
// backup web pembida
|
|
public function listBidItemWeb($user_id, Request $request){
|
|
|
|
$lelongbidder = LelongBidder::join('lelongbid', 'lelongbidder.lelongbid_id', '=', 'lelongbid.id')
|
|
->where('user_id','=', $request->user_id)
|
|
->select('lelongbid.lelong_id', 'lelongbid.t_lelong')
|
|
->groupBy('lelongbid.lelong_id', 'lelongbid.t_lelong')
|
|
->get()->toArray();
|
|
|
|
foreach($lelongbidder as $index1=>$lelbid)
|
|
{
|
|
$lelongbid = LelongBid::join('lelongbidder', 'lelongbid.id', '=', 'lelongbidder.lelongbid_id')
|
|
->where('lelong_id', $lelbid['lelong_id'])
|
|
->where('lelongbidder.user_id', $request->user_id)
|
|
->get()->toArray();
|
|
|
|
$lelongbidder[$index1]['lelongbid']=$lelongbid;
|
|
|
|
}
|
|
return response()->json($lelongbidder);
|
|
}
|
|
|
|
public function historyFeePay (Request $request)
|
|
{
|
|
$checkpay = Payment::join('resit', 'payment.resit_id', '=', 'resit.id')
|
|
->where('resit.user_id', $request->user_id)
|
|
->where('payment.lelong_id', $request->lelong_id)
|
|
->where('payment.status', 1)
|
|
->where('resit.resit_type', 1)
|
|
->select('resit.id as resit id',
|
|
'resit.resit_type',
|
|
'resit.status as resit_status',
|
|
'resit.paid_at',
|
|
'payment.id as payment_id',
|
|
'payment.lelong_id',
|
|
'payment.status as payment_status'
|
|
)
|
|
->first();
|
|
|
|
if($checkpay)
|
|
{
|
|
$response =
|
|
[
|
|
"message" => "Success",
|
|
"status" => 1
|
|
];
|
|
}
|
|
else
|
|
{
|
|
$response =
|
|
[
|
|
"message" => "Sila buat pembayaran yuran terlebih dahulu",
|
|
"status" => 2
|
|
];
|
|
}
|
|
return response()->json($response, 201) ;
|
|
}
|
|
|
|
public function searchLelByCaw(Request $request){
|
|
|
|
$currentdate = Carbon::now();
|
|
$currentdate = $currentdate->toDateString();
|
|
|
|
// $arrayLelong = [];
|
|
$lelong = Lelong::join('cawangan_lelong', 'lelong.id', '=', 'cawangan_lelong.lelong_id')
|
|
->where('tarikh_lelong','=',$currentdate)
|
|
->where('caw_id', '=', $request->caw_id)
|
|
->where('status_online', '=', 1)
|
|
->get()->toArray();
|
|
|
|
foreach($lelong as $index1=>$lel)
|
|
{
|
|
$lelongbid = LelongBid::where('lelong_id',$lel['lelong_id'])
|
|
->where('caw_id', '=', $request->caw_id)
|
|
->get()->toArray();
|
|
|
|
$lelong[$index1]['lelongbid'] = $lelongbid;
|
|
|
|
foreach($lelongbid as $index2=>$lelbidmarhun){
|
|
// $cawangan = Cawangan::where('id','=',$lelbidmarhun['caw_id'])->first()->toArray();
|
|
// $id = lelongbid::first();
|
|
|
|
$lelongbidmarhun = LelongBidMarhun::where('lelongbid_id', $lelbidmarhun['id'])
|
|
->get()->toArray();
|
|
|
|
$lelong[$index1]['lelongbid'][$index2]['lelongbidmarhun'] = $lelongbidmarhun;
|
|
// $lelong[$index1]['lelongbid'][$index2]['cawangan'] = $cawangan;
|
|
}
|
|
|
|
}
|
|
|
|
if($lelong) {
|
|
return response()->json(
|
|
['success' => true, 'message' => $lelong], 201
|
|
);
|
|
}
|
|
else {
|
|
return response()->json(
|
|
['success' => false, 'message' => 'Empty Data'], 201
|
|
);
|
|
}
|
|
}
|
|
|
|
public function listSuratLelong(Request $request)
|
|
{
|
|
$currentdate = Carbon::now();
|
|
$currentdate = $currentdate->toDateString();
|
|
|
|
$lelong = Lelong::join('cawangan_lelong', 'lelong.id', '=', 'cawangan_lelong.lelong_id')
|
|
->where('tarikh_lelong', '=', $currentdate)
|
|
->where('caw_id', '=', $request->caw_id)
|
|
->where('status_online', '=', 1)
|
|
->first();
|
|
|
|
if ($lelong) {
|
|
$lelongbid = LelongBid::where('lelong_id', $lelong['lelong_id'])
|
|
->where('caw_id', '=', $request->caw_id)
|
|
->select('id', 'kodcaw')
|
|
->get();
|
|
$pluckedLelongBid = $lelongbid->pluck('id')->toArray();
|
|
|
|
$carts = Cart::where('user_id', $request->user_id)
|
|
->select('lelongbid_id')
|
|
->get();
|
|
$pluckedCarts = $carts->pluck('lelongbid_id')->toArray();
|
|
|
|
$lelongbidder = LelongBidder::join('lelongbid', 'lelongbidder.lelongbid_id', "=", 'lelongbid.id')
|
|
->where('lelong_id', $request->lelong_id)
|
|
->where('user_id', $request->user_id)
|
|
->select('lelongbid_id')
|
|
->get();
|
|
$pluckedLelongBidder = $lelongbidder->pluck('lelongbid_id')->toArray();
|
|
|
|
$arrayDiff1 = array_diff($pluckedLelongBid, $pluckedCarts);
|
|
$arrayDiff2 = array_diff($arrayDiff1, $pluckedLelongBidder);
|
|
|
|
$listLelong = [];
|
|
foreach ($arrayDiff2 as $index => $data) {
|
|
|
|
$lelongbid = LelongBid::
|
|
// join('filemarhun', 'lelongbid.id', '=', 'filemarhun.lelongbid_id')
|
|
where('id', $data)
|
|
// ->where('photo_type', 1)
|
|
->first()->toArray();
|
|
$lelongbidmarhun = LelongBidMarhun::where('lelongbid_id', $lelongbid['id'])->get()->toArray();
|
|
foreach ($lelongbidmarhun as $index1 => $marhun) {
|
|
$marhunDesc = JenisEmas::where('marhun', $marhun['marhun'])->first()->toArray();
|
|
$lelongbidmarhun[$index1]['marhun_desc'] = $marhunDesc['descpt'];
|
|
}
|
|
|
|
$lelongbid['lelongbidmarhun'] = $lelongbidmarhun;
|
|
|
|
array_push($listLelong, $lelongbid);
|
|
}
|
|
$lelong['lelongbid'] = $listLelong;
|
|
|
|
return response()->json(
|
|
['success' => true, 'message' => $lelong],
|
|
201
|
|
);
|
|
} else {
|
|
return response()->json(
|
|
['success' => false, 'message' => 'Empty Data'],
|
|
201
|
|
);
|
|
}
|
|
}
|
|
|
|
public function searchLelongByCawangan(Request $request){
|
|
|
|
$currentdate = Carbon::now();
|
|
$currentdate = $currentdate->toDateString();
|
|
|
|
// $arrayLelong = [];
|
|
$lelong = Lelong::join('cawangan_lelong', 'lelong.id', '=', 'cawangan_lelong.lelong_id')
|
|
->where('tarikh_lelong','=',$currentdate)
|
|
->where('caw_id', '=', $request->caw_id)
|
|
->where('status_online', '=', 1)
|
|
->get()->toArray();
|
|
dd($lelong);
|
|
|
|
|
|
foreach($lelong as $index1 => $lel)
|
|
{
|
|
$lelongbid = LelongBid ::where('lelong_id', $lel['lelong_id'])
|
|
->where('caw_id', '=', $request->caw_id)
|
|
->get()->toArray();
|
|
|
|
$lelong[$index1]['lelongbid'] = $lelongbid;
|
|
// dd($lelong);
|
|
|
|
|
|
|
|
foreach($lelongbid as $index=>$lelbidmarhun){
|
|
// $cawangan = Cawangan::where('id','=',$lelbidmarhun['caw_id'])->first()->toArray();
|
|
// $id = lelongbid::first();
|
|
|
|
$lelongbidmarhun = LelongBidMarhun::where('lelongbid_id', $lelbidmarhun['id'])
|
|
->get()->toArray();
|
|
|
|
$lelong['lelongbid'][$index]['lelongbidmarhun'] = $lelongbidmarhun;
|
|
// $lelong[$index1]['lelongbid'][$index2]['cawangan'] = $cawangan;
|
|
// dd($lelong);
|
|
}
|
|
}
|
|
|
|
if($lelong) {
|
|
return response()->json(
|
|
['success' => true, 'message' => $lelong], 201
|
|
);
|
|
}
|
|
else {
|
|
return response()->json(
|
|
['success' => false, 'message' => 'Empty Data'], 201
|
|
);
|
|
}
|
|
|
|
}
|
|
|
|
public function bidresult($user_id)
|
|
{
|
|
$sag = LelongBidder::join('lelongbid', 'lelongbidder.lelongbid_id', '=', 'lelongbid.id')
|
|
->join('lelong', 'lelongbid.lelong_id', '=', 'lelong.id')
|
|
->where('lelongbidder.user_id',$user_id)
|
|
// ->where('lelongbid.lelong_id',$lelong_id)
|
|
->where('lelongbidder.status_bidder',1)
|
|
->whereNull('lelongbidder.status_payment')
|
|
->select(
|
|
'lelongbid.lelong_id',
|
|
'lelongbidder.user_id',
|
|
'lelongbidder.lelongbid_id',
|
|
'lelongbidder.hargabida',
|
|
'lelongbidder.status_payment',
|
|
'lelongbid.norujukan'
|
|
|
|
)
|
|
->get();
|
|
|
|
// dd($sag);
|
|
$data = [];
|
|
$total_hargabida = $sag->sum('hargabida');
|
|
array_push($data,[
|
|
'sag'=> $sag,
|
|
'total_hargabida'=> $total_hargabida
|
|
]);
|
|
// dd($winner);
|
|
return response()->json($data);
|
|
}
|
|
|
|
public function bidresults($user_id, $lelong_id)
|
|
{
|
|
$sag = LelongBid::join('lelongbidder', 'lelongbid.id', '=', 'lelongbidder.lelongbid_id')
|
|
->where('lelongbid.lelong_id', $lelong_id)
|
|
->where('lelongbidder.user_id', $user_id)
|
|
->where('lelongbidder.status_bidder', 1)
|
|
->select(
|
|
'lelongbid.kodcaw'
|
|
)
|
|
->groupBy('lelongbid.kodcaw')
|
|
->get();
|
|
// dd($sag->toArray());
|
|
$getTarikhLelong = Lelong::where('id', $lelong_id)->select('tarikh_lelong')->first();
|
|
$tarikhLelong = $getTarikhLelong->tarikh_lelong;
|
|
|
|
$data = [];
|
|
|
|
foreach ($sag as $index1 => $kodcaw) {
|
|
$groupBycaw = LelongBid::join('lelongbidder', 'lelongbid.id', '=', 'lelongbidder.lelongbid_id')
|
|
->where('lelongbid.lelong_id', $lelong_id)
|
|
->where('lelongbidder.user_id', $user_id)
|
|
->where('lelongbidder.status_bidder', 1)
|
|
->where('lelongbid.kodcaw', $kodcaw->kodcaw)
|
|
->select(
|
|
'lelongbidder.id AS id',
|
|
'lelongbid.norujukan AS norujukan',
|
|
'lelongbid.kodcaw AS kodcaw',
|
|
'lelongbidder.hargabida AS total_payment',
|
|
'lelongbid.marhun AS marhun',
|
|
'lelongbidder.status_payment')
|
|
->get();
|
|
|
|
$getCawangan = Cawangan::where('caw_code', $kodcaw->kodcaw)
|
|
->select('caw_name', 'caw_code')
|
|
->first();
|
|
$namaCawangan = $getCawangan->caw_name;
|
|
$kodCawangan = $getCawangan->caw_code;
|
|
|
|
$sag = $groupBycaw;
|
|
|
|
$total_hargabida = 0;
|
|
foreach ($groupBycaw as $hargabida) {
|
|
$totalbida = Lelongbidder::where('id', $hargabida['id'])
|
|
->select('hargabida')
|
|
->first();
|
|
$total_hargabida = $total_hargabida + $totalbida['hargabida'];
|
|
}
|
|
|
|
array_push($data, [
|
|
'kodcaw' => $kodCawangan,
|
|
'cawangan' => $namaCawangan,
|
|
'sag' => $sag,
|
|
'total_hargabida' => $total_hargabida
|
|
]);
|
|
}
|
|
|
|
$response = [
|
|
'success' => true,
|
|
'tarikh_lelong' => $tarikhLelong,
|
|
'data' => $data
|
|
];
|
|
|
|
return response()->json($response);
|
|
|
|
}
|
|
|
|
public function bidPayRemaining($user_id, $lelong_id)
|
|
{
|
|
$sag = LelongBid::join('lelongbidder', 'lelongbid.id', '=', 'lelongbidder.lelongbid_id')
|
|
->where('lelongbid.lelong_id', $lelong_id)
|
|
->where('lelongbidder.user_id', $user_id)
|
|
->where('lelongbidder.status_bidder', 1)
|
|
->whereNull('lelongbidder.status_payment')
|
|
->select(
|
|
'lelongbid.kodcaw'
|
|
)
|
|
->groupBy('lelongbid.kodcaw')
|
|
->get();
|
|
// dd($sag->toArray());
|
|
$getTarikhLelong = Lelong::where('id', $lelong_id)->select('tarikh_lelong')->first();
|
|
$tarikhLelong = $getTarikhLelong->tarikh_lelong;
|
|
|
|
$data = [];
|
|
|
|
foreach ($sag as $index1 => $kodcaw) {
|
|
// dd($kodcaw->toArray());
|
|
$groupBycaw = LelongBid::join('lelongbidder', 'lelongbid.id', '=', 'lelongbidder.lelongbid_id')
|
|
->where('lelongbid.lelong_id', $lelong_id)
|
|
->where('lelongbidder.user_id', $user_id)
|
|
->where('lelongbidder.status_bidder', 1)
|
|
->whereNull('lelongbidder.status_payment')
|
|
->where('lelongbid.kodcaw', $kodcaw->kodcaw)
|
|
->select(
|
|
'lelongbidder.id AS id',
|
|
'lelongbid.norujukan AS norujukan',
|
|
'lelongbid.kodcaw AS kodcaw',
|
|
'lelongbidder.hargabida AS total_payment',
|
|
'lelongbid.marhun AS marhun',
|
|
'lelongbidder.status_payment')
|
|
->get();
|
|
|
|
$getCawangan = Cawangan::where('caw_code', $kodcaw->kodcaw)
|
|
->select('caw_name', 'caw_code')
|
|
->first();
|
|
$namaCawangan = $getCawangan->caw_name;
|
|
$kodCawangan = $getCawangan->caw_code;
|
|
|
|
$sag = $groupBycaw;
|
|
|
|
$total_hargabida = 0;
|
|
foreach ($groupBycaw as $hargabida) {
|
|
$totalbida = Lelongbidder::where('id', $hargabida['id'])
|
|
->select('hargabida')
|
|
->first();
|
|
$total_hargabida = $total_hargabida + $totalbida['hargabida'];
|
|
}
|
|
|
|
array_push($data, [
|
|
'kodcaw' => $kodCawangan,
|
|
'cawangan' => $namaCawangan,
|
|
'sag' => $sag,
|
|
'total_hargabida' => $total_hargabida
|
|
]);
|
|
}
|
|
|
|
$response = [
|
|
'success' => true,
|
|
'tarikh_lelong' => $tarikhLelong,
|
|
'data' => $data
|
|
];
|
|
|
|
return response()->json($response);
|
|
|
|
}
|
|
|
|
public function updatebiditem(Request $request)
|
|
{
|
|
// dd($request->norujukan->toArray());
|
|
// foreach($request->norujukan as $norujukan)
|
|
// {
|
|
// dd($norujukan);
|
|
// }
|
|
$currentdate = Carbon::now();
|
|
$currentdate = $currentdate->toDateTimeString();
|
|
|
|
$lelongbid = LelongBid::whereIn('norujukan',$request->norujukan)
|
|
->where('lelong_id',$request->lelong_id)
|
|
->get();
|
|
|
|
foreach($lelongbid as $bid)
|
|
{
|
|
$lelongbidder = LelongBidder::where('lelongbid_id',$bid->id)
|
|
->where('user_id',$request->user_id)->first();
|
|
$lelongbidder->status_payment =1;
|
|
$lelongbidder->payment_id = $request->paymentid;
|
|
$lelongbidder->save();
|
|
|
|
$lelongbid = LelongBid::where('id',$bid->id)->first();
|
|
$lelongbid->status_jual = 1;
|
|
$lelongbid->t_jual = $currentdate;
|
|
$lelongbid->hargajual = $lelongbidder->hargabida;
|
|
$lelongbid->save();
|
|
|
|
}
|
|
|
|
// $alllelongbidder = LelongBidder::join('lelongbid','lelongbidder.lelongbid_id','lelongbid.id')
|
|
// ->where('lelongbidder.user_id',$request->user_id)
|
|
// ->where('lelongbid.lelong_id',$request->lelong_id)
|
|
// ->where('lelongbidder.status_bidder',1)
|
|
// ->select('lelongbidder.hargabida')
|
|
// ->get();
|
|
|
|
// $resit = Resit::where('lelong_id',$request->lelong_id)
|
|
// ->where('user_id',$request->user_id)
|
|
// ->where('resit_type',2)
|
|
// ->first();
|
|
|
|
// if($resit->total_payment > $alllelongbidder->SUM('hargabida'))
|
|
// {
|
|
// $resit->status = 'PAID';
|
|
// $resit->paid_at = $currentdate;
|
|
// $resit->save();
|
|
// }
|
|
|
|
$response = [
|
|
'success' => "success",
|
|
'message' => "Bidaan berjaya dibayar"
|
|
];
|
|
|
|
return response()->json($response, 201);
|
|
|
|
}
|
|
|
|
public function history($user_id)
|
|
{
|
|
$lelongs_id = LelongBidder::join('lelongbid', 'lelongbidder.lelongbid_id', '=', 'lelongbid.id')
|
|
->where('lelongbidder.user_id',$user_id)->select('lelongbid.lelong_id')->groupBy('lelongbid.lelong_id')->get();
|
|
|
|
$arrayID = [];
|
|
foreach($lelongs_id as $lelong_id)
|
|
{
|
|
array_push($arrayID,$lelong_id);
|
|
}
|
|
$lelongs = Lelong::whereIn('id',$arrayID)->get()->toArray();
|
|
// dd($lelongs);
|
|
|
|
foreach($lelongs as $index1 => $lelong)
|
|
{
|
|
// dd($lelong['id']);
|
|
$datalelongbidder = LelongBidder::join('lelongbid', 'lelongbidder.lelongbid_id', '=', 'lelongbid.id')
|
|
->where('lelongbid.lelong_id',$lelong['id'])
|
|
->where('user_id',$user_id)
|
|
->where('status_bidder',1)->get();
|
|
|
|
$payment = Payment::join('resit', 'payment.resit_id', '=', 'resit.id')
|
|
->where('payment.lelong_id',$lelong['id'])
|
|
->where('payment.user_id',$user_id)
|
|
->where('resit.resit_type',2)
|
|
->first();
|
|
|
|
if($payment->status == 'PAID')
|
|
{
|
|
$status = 'Selesai';
|
|
}
|
|
else
|
|
{
|
|
$status = 'Belum Selesai';
|
|
}
|
|
$lelongs[$index1]['total'] = $datalelongbidder->sum('hargabida');
|
|
$lelongs[$index1]['status'] = $status;
|
|
$lelongs[$index1]['detail_sag'] = $datalelongbidder;
|
|
}
|
|
return response()->json($lelongs, 201);
|
|
}
|
|
|
|
public function listCawLelongToday()
|
|
{
|
|
|
|
$currentdate = Carbon::now();
|
|
$currentdate = $currentdate->toDateString();
|
|
|
|
$lelong = Lelong::join('cawangan_lelong', 'lelong.id', '=', 'cawangan_lelong.lelong_id')
|
|
->join('cawangan', 'cawangan_lelong.caw_id', '=', 'cawangan.id')
|
|
->where('tarikh_lelong', '=', $currentdate)
|
|
->select(
|
|
'lelong.id as lelong_id',
|
|
'lelong.tarikh_lelong',
|
|
'cawangan.caw_name',
|
|
'cawangan_lelong.caw_id',
|
|
'cawangan_lelong.masamula_lelong',
|
|
'cawangan_lelong.masatamat_lelong',
|
|
)
|
|
->get();
|
|
if ($lelong->isNotEmpty()) {
|
|
return response()->json([
|
|
'success' => true,
|
|
'lelong' => $lelong,
|
|
]);
|
|
} else {
|
|
return response()->json([
|
|
'success' => false,
|
|
]);
|
|
}
|
|
}
|
|
|
|
public function listCawLelongTodayStarted()
|
|
{
|
|
|
|
$currentdate = Carbon::now();
|
|
$currentdate = $currentdate->toDateString();
|
|
|
|
$lelong = Lelong::join('cawangan_lelong', 'lelong.id', '=', 'cawangan_lelong.lelong_id')
|
|
->join('cawangan', 'cawangan_lelong.caw_id', '=', 'cawangan.id')
|
|
->where('tarikh_lelong', '=', $currentdate)
|
|
->where('cawangan_lelong.status_online', 1)
|
|
->select(
|
|
'lelong.id as lelong_id',
|
|
'lelong.tarikh_lelong',
|
|
'cawangan.caw_name',
|
|
'cawangan_lelong.caw_id',
|
|
'lelong.masamula_lelong',
|
|
'lelong.masatamat_lelong',
|
|
)
|
|
->get()->toArray();
|
|
// dd($lelong);
|
|
|
|
if ($lelong) {
|
|
return response()->json([
|
|
'success' => true,
|
|
'lelong' => $lelong
|
|
]);
|
|
} else {
|
|
return response()->json([
|
|
'success' => false,
|
|
]);
|
|
}
|
|
}
|
|
|
|
public function listCawLelongNext()
|
|
{
|
|
|
|
$currentdate = Carbon::now();
|
|
$currentdate = $currentdate->toDateString();
|
|
|
|
$lelong = Lelong::join('cawangan_lelong', 'lelong.id', '=', 'cawangan_lelong.lelong_id')
|
|
->join('cawangan', 'cawangan_lelong.caw_id', '=', 'cawangan.id')
|
|
->where('tarikh_lelong', '>', $currentdate)
|
|
->select(
|
|
'lelong.id as lelong_id',
|
|
'lelong.tarikh_lelong',
|
|
'cawangan.caw_name',
|
|
'cawangan_lelong.caw_id',
|
|
'lelong.masamula_lelong',
|
|
'lelong.masatamat_lelong',
|
|
)
|
|
->orderBy('lelong.tarikh_lelong', 'ASC')
|
|
->get()->toArray();
|
|
|
|
if ($lelong) {
|
|
return response()->json([
|
|
'success' => true,
|
|
'lelong' => $lelong
|
|
]);
|
|
} else {
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => "Empty Data"
|
|
]);
|
|
}
|
|
}
|
|
|
|
public function bayarCdm(Request $request)
|
|
{
|
|
// dd($request->all());
|
|
$validator = Validator::make($request->all(), [
|
|
'lelong_id' => 'required|string',
|
|
'user_id' => 'required',
|
|
]);
|
|
|
|
if ($validator->fails()) {
|
|
$errors = [
|
|
'success' => "error",
|
|
'message' => $validator->errors()
|
|
];
|
|
return response($errors, 201);
|
|
}
|
|
|
|
$currentdate = Carbon::now();
|
|
$currentdate = $currentdate->toDateTimeString();
|
|
|
|
$user = Auth::user();
|
|
|
|
// $imageName = time().'.'.$request->resit->extension();
|
|
// $data = base64_encode($request->resit->get());
|
|
// $file_type = $request->resit->extension();
|
|
|
|
$resit = Resit::where('lelong_id', $request->lelong_id)
|
|
->where('user_id',$request->user_id)
|
|
->where('resit_type', 2)
|
|
->first();
|
|
|
|
$payment = new Payment;
|
|
$payment->user_id = $request->user_id;
|
|
$payment->lelong_id = $request->lelong_id;
|
|
$payment->kodcaw = $user->kodcaw;
|
|
$payment->status_payment_opt = 3;
|
|
$payment->status = 2;
|
|
$payment->remark = 'BAYARAN CDM';
|
|
$payment->resit_id = $resit->id;
|
|
$payment->total_payment = $request->total_payment;
|
|
$payment->diminta_pada = $currentdate;
|
|
$payment->diminta_oleh = $user->id;
|
|
$payment->save();
|
|
|
|
if($payment)
|
|
{
|
|
$images = $request->images;
|
|
foreach($images as $img)
|
|
{
|
|
$addfile = new FileResit;
|
|
$addfile->user_id = $request->user_id;
|
|
$addfile->payment_id = $payment->id;
|
|
$addfile->file_type = $img['file_type'];
|
|
$addfile->filename = $img['filename'];
|
|
$addfile->save();
|
|
}
|
|
}
|
|
|
|
$bid_id = $request->bid_id;
|
|
foreach($bid_id as $bid)
|
|
{
|
|
$eachbid = LelongBidder::join('lelongbid', 'lelongbidder.lelongbid_id', '=', 'lelongbid.id')
|
|
->join('users', 'lelongbidder.user_id', '=', 'users.id')
|
|
->where('lelongbidder.lelongbid_id', $bid['lelongbid_id'])
|
|
->select('lelongbidder.hargabida',
|
|
'lelongbid.hargaasas',
|
|
'lelongbid.norujukan',
|
|
'lelongbidder.lelongbid_id',
|
|
'lelongbidder.id as lelongbidder_id',
|
|
'lelongbid.lelong_id as lelong_id'
|
|
)
|
|
->first();
|
|
|
|
$updatelelbidbidder = LelongBidder::where('lelongbid_id', $bid['lelongbid_id'])
|
|
->where('user_id',$request->user_id)
|
|
->first();
|
|
$updatelelbidbidder->status_payment = 2;
|
|
$updatelelbidbidder->payment_id = $payment->id;
|
|
$updatelelbidbidder->save();
|
|
|
|
$eachbidupdate = LelongBid::where('id',$bid)->first();
|
|
$eachbidupdate->hargajual = $eachbid->hargabida;
|
|
$eachbidupdate->save();
|
|
|
|
}
|
|
if ($payment) {
|
|
return response()->json([
|
|
'success' => true,
|
|
'user' => $user,
|
|
'payment' => $payment,
|
|
'file_resit' => $images,
|
|
'updatelelbidbidder' => $updatelelbidbidder,
|
|
'eachbidupdate' => $eachbidupdate
|
|
]);
|
|
}
|
|
else {
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => "Muat naik bukti pembayaran tidak berjaya!"
|
|
]);
|
|
}
|
|
|
|
// return response($response, 201);
|
|
}
|
|
|
|
public function updateResit(Request $request)
|
|
{
|
|
$validator = Validator::make($request->all(), [
|
|
'lelong_id' => 'required|string',
|
|
'user_id' => 'required',
|
|
'payment_id' => 'required'
|
|
]);
|
|
|
|
if ($validator->fails()) {
|
|
$errors = [
|
|
'success' => "error",
|
|
'message' => $validator->errors()
|
|
];
|
|
return response($errors, 201);
|
|
}
|
|
|
|
$paymentexist = Payment::join('fileresit', 'payment.id', '=', 'fileresit.payment_id')
|
|
->where('payment.lelong_id', $request->lelong_id)
|
|
->where('payment.user_id', $request->user_id)
|
|
->first();
|
|
|
|
if($paymentexist)
|
|
{
|
|
$getpayment = Payment::join('fileresit', 'payment.id', '=', 'fileresit.payment_id')
|
|
->where('payment.lelong_id', $request->lelong_id)
|
|
->where('payment.user_id', $request->user_id)
|
|
->select('payment.id as payment_id',
|
|
'payment.lelong_id',
|
|
'payment.user_id',
|
|
'fileresit.id as fileresit_id',
|
|
'fileresit.file_type',
|
|
'fileresit.filename'
|
|
)
|
|
->first();
|
|
|
|
|
|
$images = $request->images;
|
|
foreach($images as $img)
|
|
{
|
|
$deletepayment = FileResit::where('payment_id', $request->payment_id)
|
|
->where('id', $img['fileresit_id'])
|
|
->delete();
|
|
|
|
$addfile = new FileResit;
|
|
$addfile->user_id = $request->user_id;
|
|
$addfile->payment_id = $request->payment_id;
|
|
$addfile->file_type = $img['file_type'];
|
|
$addfile->filename = $img['filename'];
|
|
$addfile->save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($addfile) {
|
|
return response()->json([
|
|
'success' => true,
|
|
'payment' => $paymentexist,
|
|
'file_resit' => $images
|
|
]);
|
|
}
|
|
else {
|
|
return response()->json([
|
|
'success' => false,
|
|
'message' => "Kemaskini bukti pembayaran tidak berjaya!"
|
|
]);
|
|
}
|
|
|
|
}
|
|
|
|
public function getInvoiceId(Request $request) {
|
|
$invoice = Invoice::where('user_id', $request->user_id)->where('lelong_id', $request->lelong_id)->first();
|
|
|
|
if ($invoice) {
|
|
return response()->json([
|
|
'success' => true,
|
|
'invoice' => $invoice,
|
|
]);
|
|
} else {
|
|
return response()->json([
|
|
'success' => false,
|
|
]);
|
|
}
|
|
}
|
|
|
|
public function resultLelong(Request $request)
|
|
{
|
|
$lelong = Lelong::join('lelongbid', 'lelong.id', '=', 'lelongbid.lelong_id')
|
|
->join('lelongbidder', 'lelongbid.id', '=', 'lelongbidder.lelongbid_id')
|
|
->where('lelongbidder.user_id', $request->user_id)
|
|
->where('status_bidder', 1)
|
|
->select('lelong.id', 'lelong.tarikh_lelong')
|
|
->groupBy('lelong.id')
|
|
->orderBy('lelong.id','desc')
|
|
->get();
|
|
|
|
foreach ($lelong as $index => $tarikhLelong) {
|
|
|
|
$jumlah = 0;
|
|
$status = 1;
|
|
$lelongbid = LelongBid::join('lelongbidder', 'lelongbid.id', 'lelongbidder.lelongbid_id')
|
|
->where('lelongbid.lelong_id', $tarikhLelong->id)
|
|
->where('lelongbidder.user_id', $request->user_id)
|
|
->where('status_bidder', 1)
|
|
->select('lelongbidder.hargabida', 'lelongbidder.status_payment')
|
|
->get();
|
|
|
|
foreach ($lelongbid as $data) {
|
|
$jumlah = $jumlah + $data->hargabida;
|
|
|
|
if($data->status_payment == null) {
|
|
$status = null;
|
|
}
|
|
|
|
}
|
|
|
|
$lelong[$index]['jumlah'] = $jumlah;
|
|
$lelong[$index]['status'] = $status;
|
|
}
|
|
|
|
if (!empty($lelong)) {
|
|
return response()->json([
|
|
'success' => true,
|
|
'lelong' => $lelong,
|
|
]);
|
|
} else {
|
|
return response()->json([
|
|
'success' => false,
|
|
]);
|
|
}
|
|
}
|
|
|
|
public function resultStatus($userId, $lelongId)
|
|
{
|
|
// dd('hey');
|
|
$lelong = Lelong::join('lelongbid', 'lelong.id', '=', 'lelongbid.lelong_id')
|
|
->join('lelongbidder', 'lelongbid.id', '=', 'lelongbidder.lelongbid_id')
|
|
->where('lelongbidder.user_id', $userId)
|
|
->where('lelong.id', $lelongId)
|
|
->where('status_bidder', 1)
|
|
->get();
|
|
|
|
foreach ($lelong as $index) {
|
|
|
|
$status = true;
|
|
|
|
if ($index->status_payment == null || $index->status_payment == 0) {
|
|
$status = false;
|
|
}
|
|
}
|
|
|
|
if ($lelong) {
|
|
return response()->json([
|
|
'success' => true,
|
|
'statusMenang' => true,
|
|
'statusBayaran' => $status,
|
|
]);
|
|
} else {
|
|
return response()->json([
|
|
'success' => false,
|
|
'statusMenang' => false,
|
|
|
|
]);
|
|
}
|
|
}
|
|
}
|