Add & update API for upload receipt CDM
This commit is contained in:
@@ -15,7 +15,9 @@ use App\Models\Cart;
|
||||
use Carbon\Carbon;
|
||||
use App\Models\Cawangan;
|
||||
use App\Models\Resit;
|
||||
use App\Models\FileResit;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class LelongMobileController extends Controller
|
||||
{
|
||||
@@ -586,11 +588,114 @@ class LelongMobileController extends Controller
|
||||
|
||||
public function bayarCdm(Request $request)
|
||||
{
|
||||
// dd($request->all());
|
||||
$validator = Validator::make($request->all(), [
|
||||
'lelong_id' => 'required|string',
|
||||
'lelongbid_id' => 'required|string|unique:users',
|
||||
'user_id' => 'required|string|unique:users'
|
||||
|
||||
'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()) {
|
||||
@@ -619,84 +724,39 @@ class LelongMobileController extends Controller
|
||||
'fileresit.filename'
|
||||
)
|
||||
->first();
|
||||
|
||||
$updatepayment = FileResit::where('payment_id', $getpayment['payment_id'])
|
||||
->where('id', $getpayment['fileresit_id'])
|
||||
->first();
|
||||
$updatepayment->id;
|
||||
$updatepayment->user_id = $request->user_id;
|
||||
$updatepayment->payment_id = $updatepayment->payment_id;
|
||||
$updatepayment->file_type = $request->file_type;
|
||||
$updatepayment->filename = $request->filename;
|
||||
$updatepayment->update();
|
||||
|
||||
return response($response, 201);
|
||||
}
|
||||
else
|
||||
{
|
||||
$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();
|
||||
|
||||
$addfile = new FileResit;
|
||||
$addfile->user_id = $request->user_id;
|
||||
$addfile->payment_id = $payment->id;
|
||||
$addfile->file_type = $file_type;
|
||||
$addfile->filename = $data;
|
||||
// $addfile->save();
|
||||
|
||||
foreach($bid_id as $bid)
|
||||
$images = $request->images;
|
||||
foreach($images as $img)
|
||||
{
|
||||
$eachbid = LelongBidder::join('lelongbid', 'lelongbidder.lelongbid_id', '=', 'lelongbid.id')
|
||||
->join('users', 'lelongbidder.user_id', '=', 'users.id')
|
||||
->where('lelongbidder.lelongbid_id', $bid)
|
||||
->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', $eachbid->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();
|
||||
|
||||
$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();
|
||||
|
||||
}
|
||||
|
||||
return response($response, 201);
|
||||
|
||||
}
|
||||
|
||||
if ($addfile) {
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'payment' => $paymentexist,
|
||||
'file_resit' => $images
|
||||
]);
|
||||
}
|
||||
else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => "Kemaskini bukti pembayaran tidak berjaya!"
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,6 +66,7 @@ Route::group(['middleware' => ['auth:sanctum']], function () {
|
||||
Route::get('/listcawlelongtodaystarted', [LelongMobileController::class, 'listCawLelongTodayStarted']);
|
||||
Route::get('/listcawlelongnext', [LelongMobileController::class, 'listCawLelongNext']);
|
||||
Route::post('/bayarcdm', [LelongMobileController::class, 'bayarCdm']);
|
||||
Route::post('/updateresit', [LelongMobileController::class, 'updateResit']);
|
||||
|
||||
// Lelong => Bidder
|
||||
Route::post('/bidder/biditem', [LelongMobileController::class, 'bidderSelectBidItem']);
|
||||
|
||||
Reference in New Issue
Block a user