示例#1
0
 public function order()
 {
     //get Session option
     $option = Session::get('option');
     //get Cart
     $cart = Cart::content();
     //get type order
     $type = $option['type'];
     //payment method
     $payMethod = Session::get('pay_med');
     if ($option['type'] == 'logged') {
         $order = new Order();
         DB::beginTransaction();
         try {
             $idUser = array_get(session('user'), 'id');
             $order->user_id = $idUser;
             $order->delivery_detail_id = 0;
             $order->comment = $payMethod['comment'];
             $order->save();
             $idOrder = Order::where('user_id', $idUser)->orderBy('id', 'desc')->first()->id;
             //add order detail and sub amount of product
             foreach ($cart as $item) {
                 $root_price = Cd::find($item['id'])->root_price;
                 $modelOrderDetail = new OrderDetail();
                 $modelOrderDetail->order_id = $idOrder;
                 $modelOrderDetail->product_id = $item['id'];
                 $modelOrderDetail->quantity = $item['qty'];
                 $modelOrderDetail->root_price = $root_price;
                 $modelOrderDetail->price = $item->price;
                 $modelOrderDetail->save();
                 //sub qty product
                 $cd = Cd::find($item['id']);
                 if ($cd->quantity - $item['qty'] <= 0) {
                     throw new QtyCDException();
                 }
                 $cd->quantity = $cd->quantity - $item['qty'];
                 $cd->buy_time = $cd->buy_time + $item['qty'];
                 $cd->save();
             }
             DB::commit();
             $this->clear();
             return redirect_success('FrontendController@index', 'Ordered, Check your email to check detail');
         } catch (QtyCDException $e) {
             DB::rollback();
             return redirect_errors($e->notify());
         } catch (\Exception $e) {
             DB::rollback();
             return redirect_errors("Sorry cannot to this deal!");
         }
     } else {
         $deliveryDetail = Session::get('shi_add');
         $order = new Order();
         $modelDeliverDetail = new DeliveryDetail();
         $modelDeliverDetail = autoAssignDataToProperty($modelDeliverDetail, $deliveryDetail);
         //            dd($modelDeliverDetail);
         DB::beginTransaction();
         try {
             $orderHuman = $modelDeliverDetail;
             $modelDeliverDetail->save();
             $newDeliverDetail = new DeliveryDetail();
             $delivery = $newDeliverDetail->getDeliveryDetail($deliveryDetail);
             $order->user_id = 0;
             $order->delivery_detail_id = $delivery->id;
             $order->comment = $payMethod['comment'];
             $order->save();
             $idOrder = Order::where('delivery_detail_id', $delivery->id)->first()->id;
             //add order detail and sub amount of product
             foreach ($cart as $item) {
                 $modelOrderDetail = new OrderDetail();
                 $modelOrderDetail->order_id = $idOrder;
                 $modelOrderDetail->product_id = $item['id'];
                 $modelOrderDetail->quantity = $item['qty'];
                 $modelOrderDetail->price = $item['price'];
                 $modelOrderDetail->save();
                 //
                 $cd = Cd::find($item['id']);
                 if ($cd->quantity - $item['qty'] <= 0) {
                     throw new QtyCDException();
                 } else {
                     $cd->quantity = $cd->quantity - $item['qty'];
                 }
             }
             DB::commit();
             $this->clear();
             //send
             //                Mail::send('auth.mail_welcome', ['last_name' => $orderHuman->lastname, 'key' => $key_active, 'password' => $pass], function ($message) use ($data) {
             //                    $message
             //                        ->to($data['email'], $data['name'])
             //                        ->from('*****@*****.**')
             //                        ->subject('Thank you for your buying!');
             //                });
             return redirect_success('FrontendController@index', 'Ordered, Check your email to check detail');
         } catch (QtyCDException $e) {
             DB::rollback();
             return redirect_errors($e->notify());
         } catch (\Exception $e) {
             DB::rollback();
             return redirect_errors("Sorry cannot to this deal!");
         }
     }
 }
示例#2
0
 public function resetPassword(ResetPassword $request)
 {
     //getDataRequest
     $getDataRequest = $request->all();
     $ck = User::where('email', $getDataRequest['email'])->where('status', User::ACTIVED_STATUS)->count();
     //check active
     if ($ck == 0) {
         return redirect_errors('Account active yet!');
     }
     //get User data
     $user = User::where('email', $getDataRequest['email'])->get(['name', 'key_active', 'remember_token'])->first()->toArray();
     //gen new pass
     $newPass = str_random(8);
     $codePass = md5($newPass . md5($user['remember_token']));
     //put into array data
     $data = ['name' => $user['name'], 'email' => $getDataRequest['email'], 'password' => $newPass];
     //update User and check update
     if ($user = User::where('email', $getDataRequest['email'])->update(['password' => $codePass, 'key_active' => str_random(30)])) {
         Mail::send('auth.mail_repass', ['name' => $data['name'], 'password' => $newPass], function ($message) use($data) {
             $message->to($data['email'], $data['name'])->from('*****@*****.**')->subject('Reset Password TopMp3!');
         });
         return redirect_success('AuthController@getLogin', 'Check your email ' . $data['email'] . ' to check new password!');
     } else {
         return redirect_errors('Have error!');
     }
     //end check update
 }
示例#3
0
 public function destroy($id)
 {
     if ($id == 1) {
         return redirect_success('Admin\\CategoryController@index', Lang::get('Can not delete this category'));
     }
     Category::where('parent_id', $id)->update(['parent_id' => 0]);
     Product::where('category_id', $id)->update(['category_id' => 1]);
     Category::find($id)->delete();
     return redirect_success('Admin\\CategoryController@index', Lang::get('messages.delete_success'));
 }
示例#4
0
 public function destroy($id)
 {
     Pages::find($id)->delete();
     return redirect_success('Admin\\PagesController@index', Lang::get('messages.delete_success'));
 }
示例#5
0
 public function setThumbnail()
 {
     $products = Product::all()->toArray();
     foreach ($products as $item) {
         $images = Images::where('productID', $item['id'])->first();
         $thumbnail = $images['imageSrc'];
         $model = Product::find($item['id']);
         $model->thumbnail = $thumbnail;
         $model->save();
     }
     return redirect_success('Admin\\ProductController@index', "Set Thumbnail Success");
 }
示例#6
0
 public function destroy($id)
 {
     //Order::find($id)->delete();
     return redirect_success('OrderController@index', "Cannot delete order item");
 }