/**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     // 验证一下必填项
     $this->validate($request, ['name' => 'required', 'productImg' => 'required', 'purchasePrice' => 'required', 'price' => 'required', 'wholesalePrice' => 'required', 'description' => 'required']);
     $status = ['ok' => false, 'msg' => ''];
     $imgPath = ImageUtil::saveImgFromRequest($request, 'productImg', 'img/wd/product/' . Input::get('category'));
     if (!is_null($imgPath)) {
         $product = new Product(['name' => Input::get('name'), 'subtitle' => Input::get('subtitle'), 'thumbnail' => $imgPath, 'category_id' => Input::get('category'), 'domestic_price' => Input::get('purchasePrice'), 'retail_price' => Input::get('price'), 'wholesale_price' => Input::get('wholesalePrice'), 'count' => Input::get('count'), 'description' => Input::get('description')]);
         if (!$product->save()) {
             $status['msg'] = trans('products.addNewProduct.errors.addError');
         } else {
             $status['ok'] = true;
             // 这里需要记录一下进货记录
             $log = new InventoryLog(['product_id' => $product->id, 'count' => Input::get('count'), 'price' => Input::get("purchasePrice"), 'type' => InventoryConfig::IN]);
             $log->save();
         }
     } else {
         $status['msg'] = trans('products.addNewProduct.errors.imgError');
     }
     if ($status['ok']) {
         //            return Redirect::back()->withMessage(['ok' => trans('products.addNewProduct.success.added')]);
         // 暂时跳转到信息列表页面吧
         //            return redirect($request->getPathInfo());
         //            return redirect($request->getPathInfo() . '/create')->withMessages(
         //                ['ok' => trans('products.addNewProduct.success.added')]
         //            );
         return redirect($request->getPathInfo())->withOk(trans('products.addNewProduct.success.added'));
     } else {
         return Redirect::back()->withInput()->withErrors($status['msg']);
     }
 }
 /**
  * 库存结算
  *
  * @return response
  */
 public function balancing()
 {
     return response()->json(['inventory' => Product::sum('count'), 'totalPrice' => InventoryLog::where('type', '=', InventoryConfig::IN)->sum(DB::raw('count * price')), 'totalPayment' => InventoryLog::where('type', '=', InventoryConfig::OUT)->sum(DB::raw('count * price'))]);
 }