public function createAction() { if (!$this->user) { $this->flashJson(403); return; } $productId = $this->request->getPost("product_id", "int"); if ($productId < 1) { $this->flashJson(500, array(), "非法请求"); return; } $productModel = ProductModel::findFirst($productId); if (empty($productModel)) { $this->flashJson(500, array(), "商品不存在"); return; } $model = WishlistModel::findFirst("user_id=" . $this->user->id . " AND product_id=" . $productId); if (empty($model)) { $model = new WishlistModel(); $model->user_id = $this->user->id; $model->product_id = $productId; $time = date('Y-m-d H:i:s'); $model->addtime = $time; $model->modtime = $time; if ($model->save() == false) { $this->flashJson(500, array('type' => 'create'), "数据库插入失败"); return; } } $wishlistModel = WishlistModel::find("product_id=" . $productId); $this->flashJson(200, array('type' => 'create', 'count' => $wishlistModel->count())); return; }