public function postAllocation($ProductId) { $rules = array('num' => 'required|numeric'); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { return Redirect::to('goods/allocation/' . $ProductId)->withErrors($validator)->withInput(); } $form_product = Product::find($ProductId); $good = Good::find($form_product->good_id); $num = $good->unit * Input::get('num'); // 减库存 // if ($num > $form_product->store) { return Redirect::to('goods/allocation/' . $ProductId)->with('error', '调拨数量,不能大于现有库存数量!'); } // $form_product->store = $form_product->store - $num; // $form_product->save(); // $to_product = new Product(); // $to_product->good_id = $good->id; // $to_product->purchase = 0; // $to_product->sell = 0; // $to_product->store = $num; // $to_product->cost = $form_product->cost; // $to_product->price = $form_product->price; // $to_product->damage = 0; // $to_product->replacement = 0; // $to_product->warehouse_id = Input::get('warehouse_id'); // $to_product->production_date = $form_product->production_date; // $to_product->life = $form_product->life; // $to_product->cost_date = $form_product->cost_date; // $to_product->life_date = $form_product->life_date; // $to_product->save(); $allocation = new Allocation(); $allocation->good_id = $good->id; $allocation->to_product_id = '0'; $allocation->from_product_id = $form_product->id; $allocation->to_warehouse_id = Input::get('warehouse_id'); $allocation->from_warehouse_id = $form_product->warehouse_id; $allocation->num = $num; $allocation->allocation_status = '0'; $allocation->save(); // 日志 // // $this->__goodLog($good->id, $form_product->id, 'allocation'); return Redirect::to('goods/list/' . $good->id)->with('success', '调拨成功!'); }