public function postFinish() { $order = order::find(Input::get('id')); $order->status = 1; if ($order->update()) { $finish = new finishorder(); $data = array('name' => Input::get('name'), 'idorder' => Input::get('id')); $finish->fill($data); if ($finish->save()) { $detailorder = detailorder::select('productID', 'quantity')->where('orderid', Input::get('id'))->get(); foreach ($detailorder as $value) { $producto = product::find($value->productID); $producto->quantity = $producto->quantity - $value->quantity; $producto->update(); } return 1; } $order->status = 0; $order->update(); return -1; } return -1; }
public function delete() { $order = detailorder::where('productID', Input::get('id'))->get(); if (count($order) > 0) { return Redirect::to('admin/product/recyclebin')->with(['message' => 'Sản phẩm "' . Input::get('title') . '" đã có đơn đặt hàng. Bạn không thể xóa.']); } $product = product::find(Input::get('id')); if ($product->delete()) { DB::table('detailproduct')->where('productID', Input::get('id'))->delete(); return Redirect::to('admin/product/recyclebin')->with(['message' => 'Xóa thành công sản phẩm "' . Input::get('title') . '"']); } else { return Redirect::to('admin/product/recyclebin')->with(['message' => 'Có lỗi xóa sản phẩm "' . Input::get('title') . '" thất bại. Vui lòng thử lại.']); } }