119 lines
3.6 KiB
PHP
119 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\AuthMobile;
|
|
|
|
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;
|
|
|
|
class LelongMobileController extends Controller
|
|
{
|
|
|
|
public function getlelongdetails(Request $request){
|
|
|
|
$currentdate = Carbon::now();
|
|
$currentdate = $currentdate->toDateString();
|
|
|
|
// $arrayLelong = [];
|
|
$lelong = Lelong::where('tarikh_lelong','=',$currentdate)->get()->toArray();
|
|
|
|
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;
|
|
}
|
|
|
|
}
|
|
|
|
return response()->json($lelong);
|
|
|
|
}
|
|
|
|
public function getListKarat(Request $request){
|
|
|
|
$getKarat = lelkarat::all();
|
|
|
|
// $lelongBidder = lelongBidder::all();
|
|
|
|
return response()->json($getKarat);
|
|
|
|
}
|
|
|
|
public function bidderSelectBidItem(Request $request){
|
|
|
|
$feepayment = Payment::where('status', '=', 1)->first();
|
|
|
|
if($feepayment != null){
|
|
|
|
$user = User::where('id', '=', $request->user_id)
|
|
->first();
|
|
|
|
$selectBid = Cart::join('lelongbid', 'carts.lelongbid_id', '=', 'lelongbid.id')
|
|
->where('lelongbid.norujukan', $request->norujukan)
|
|
->select('lelongbid.id as lelongbid_id',
|
|
'lelongbid.t_lelong',
|
|
'lelongbid.nilaimarhun',
|
|
'lelongbid.cajlelong',
|
|
'carts.hargabida')
|
|
->get();
|
|
|
|
// dd($selectBid[0]->hargabida);
|
|
|
|
$currentdate = Carbon::now()->toDateTimeString();
|
|
|
|
$lelongBidder = new LelongBidder();
|
|
$lelongBidder->nama_bidder = $request->name;
|
|
$lelongBidder->user_id = $user->id;
|
|
$lelongBidder->notelbimbit = $user->notelbimbit;
|
|
$lelongBidder->hargabida = $selectBid[0]->hargabida;
|
|
$lelongBidder->lelongbid_id = $selectBid[0]->lelongbid_id;
|
|
$lelongBidder->nilaimarhun = $selectBid[0]->nilaimarhun;
|
|
$lelongBidder->cajlelong = $selectBid[0]->cajlelong;
|
|
$lelongBidder->masa_bidaan = $currentdate;
|
|
$lelongBidder->save();
|
|
|
|
return response()->json("success", 201);
|
|
}
|
|
else if($feepayment == null){
|
|
return response()->json("unsuccess", 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);
|
|
}
|
|
}
|