Ejemplo n.º 1
0
 public function insertAction()
 {
     if (!$this->user) {
         $this->flashJson(500, array(), "请先登陆!");
         exit;
     }
     $userId = $this->user->id;
     $name = $this->request->getPost('name');
     $price = $this->request->getPost('price');
     $description = $this->request->getPost('description');
     $from = $this->request->getPost('from');
     $fromUrl = $this->request->getPost('from_url');
     $lImgs = $this->request->getPost('l_imgs');
     $model = new ProductModel();
     $model->name = strval($name);
     $model->image_url = reset($lImgs);
     $model->more_image_urls = json_encode($lImgs);
     $model->description = strval($description);
     $model->price = floatval($price);
     $model->from = strval($from);
     $model->from_url = strval($fromUrl);
     $model->user_id = $userId;
     $model->likeit = 1;
     $model->addtime = $model->modtime = date("Y-m-d H:i:s");
     if ($model->save() == false) {
         $this->flashJson(500, array(), "暂时不能推荐商品!");
         foreach ($model->getMessages() as $message) {
             getDI()->get('logger')->error($message->__toString());
         }
     } else {
         $this->flashJson(200, array('forward' => $this->url->get('goods/detail-') . $model->id . '.html'), "商品推荐成功!");
     }
     exit;
 }