Files
lelong/app/Http/Controllers/AuthMobile/LelongMobileController.php
T
2022-01-24 10:01:47 +08:00

145 lines
5.1 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\LelongBidMarhun;
use App\Models\lelkarat;
use Carbon\Carbon;
class LelongMobileController extends Controller
{
public function getlelongdetails(Request $request){
$currentdate = Carbon::now();
$currentdate = $currentdate->toDateString();
// $arrayLelong = [];
$lelong = Lelong::where('tarikh_lelong','=',$currentdate)->get()->toArray();
// $lelongbid = LelongBid::where('t_lelong', '=', $currentdate)
// ->select('lelong_id',
// 'id as lelongbid_id',
// 'caw_id',
// 'kodcaw',
// 'norujukan',
// 't_lelong as tarikh_lelong',
// 'hargaasas',
// 'hargajual',
// 't_jual',
// 'nopembeli',
// 'jbg',
// 'kadarupah',
// 'upahsimpan',
// 'ansuran',
// 'pinjaman',
// 'bakiupah',
// 'cajlain',
// 'cajlelong',
// 'baki',
// 'gst_hj',
// 'gst_cl',
// 'percent',
// 'status_jual',
// 'status_payment')
// ->get();
foreach($lelong as $index1=>$lel)
{
$lelongbid = LelongBid::whereIn('lelong_id',$lelong)
->select('lelong_id',
'id as lelongbid_id',
'caw_id',
'kodcaw',
'norujukan',
't_lelong as tarikh_lelong',
'hargaasas',
'hargajual',
't_jual',
'nopembeli',
'jbg',
'kadarupah',
'upahsimpan',
'ansuran',
'pinjaman',
'bakiupah',
'cajlain',
'cajlelong',
'baki',
'gst_hj',
'gst_cl',
'percent',
'status_jual',
'status_payment')
// ->union($lelong)
->get()->toArray();
$lelongbidmarhun = LelongBidMarhun::join('lelongbid', 'lelongbidmarhun.lelongbid_id', '=', 'lelongbid.id')
->get()->toArray();
$lelong[$index1]['lelongbid'] = $lelongbid;
$lelong[$index1]['lelongbid']['lelongbidmarhun'] = $lelongbidmarhun;
// array_push($lelong[$index1],'lelongzz','lasdsa');
// array_push($lelong[$index1],['lelong_bid' => $lelongbid[0], 'lelong_bid_marhun' => $lelongbidmarhun]);
}
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('fee' == 1)->first();
if($feepayment != null){
$selectBid = LelongBid::join('lelong', 'lelongbid.lelong_id', '=', 'lelong.id')
->where('norujukan', $request->norujukan)
->select('id',
't_lelong',
'nilaimarhun',
'cajlelong')
->get();
$currentdate = Carbon::now()->toDateTimeString();
$lelongBidder = new LelongBidder();
$lelongBidder->nama_bidder = $fields['nama_bidder'];
$lelongBidder->hargabida = $fields['hargabida'];
$lelongBidder->nosirilel = $fields['nosirilel'];
$lelongBidder->nopembeli = $fields['nopembeli'];
$lelongBidder->t_lelong = $selectBid;
$lelongBidder->lelongbid_id = $selectBid;
$lelongBidder->nilaimarhun = $selectBid;
$lelongBidder->cajlelong = $selectBid;
$lelongBidder->status_bidder = $fields['status_bidder'];
$lelongBidder->status_bidder_win = $fields['status_bidder_win'];
$lelongBidder->status_payment = $fields['status_payment'];
$lelongBidder->masa_bidaan = $currentdate;
$lelongBidder->lelongBidder_type = 2; //type 2 = pembida
$lelongBidder->save();
}
else if($feepayment == null){
return response()->json("unsuccess", 201);
}
}
}