public function delFlea($id)
 {
     $token = Input::get('token', '');
     $u_id = Input::get('u_id', 0);
     DB::beginTransaction();
     try {
         $user = User::chkUserByToken($token, $u_id);
         $product = Product::find($id);
         if (empty($product) || $product->u_id != $u_id) {
             throw new Exception("没有找到请求的产品", 2001);
         }
         $quantity = ProductQuantity::where('p_id', '=', $id)->first();
         if (empty($quantity)) {
             throw new Exception("获取库存信息失败", 2001);
         }
         $product->delete();
         $quantity->delete();
         $re = Tools::reTrue('删除成功');
         DB::commit();
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '删除失败:' . $e->getMessage());
         DB::rollback();
     }
     return Response::json($re);
 }
Example #2
0
 public function saveProduct($stock)
 {
     $now = new DateTime();
     $this->baseValidate();
     $this->active_at = $now->format('Y-m-d H:i:s');
     $this->save();
     $quantity = ProductQuantity::where('p_id', '=', $this->p_id)->first();
     if (empty($quantity)) {
         $quantity = new ProductQuantity();
         $quantity->p_id = $this->p_id;
         $quantity->b_id = $this->b_id;
         $quantity->u_id = $this->u_id;
         $quantity->q_total = $stock;
         $quantity->addQuantity();
     }
     $freez = $quantity->q_cart + $quantity->q_sold;
     if ($freez > $stock) {
         throw new Exception("库存数量不能小于:" . $freez, 1);
     }
     $quantity->q_total = $stock;
     $quantity->save();
     return $this->p_id;
 }