public function getProductInfo($condition) { $term = new Product(); $term->setConnection($this->connection); $result = self::formatCondition($term->newQuery(), $condition)->get(); return $result; }
public function addCommentByLine($line, $time, $mode) { $data = array('code' => 200, 'message' => 'success'); $line = explode('#', $line); $sn = $line[0]; if (empty($sn)) { $data['message'] = "sn is empty"; $data['code'] = 500; return $data; } $product = new Product(); $product->setConnection($this->connection); $result = self::formatCondition($product, array('sn' => $sn))->first(); if ($result == null) { $data['message'] = $sn . " product not found"; $data['code'] = 500; return $data; } $res = $this->formatCommentData($line, $time, $mode); if ($res['code'] != 200) { $data['message'] = $res['message']; $data['code'] = 500; return $data; } $comment_data = $res['data']; $pid = $result->pid; //dd($comment_data); $comment = new Comment(); $cid = $comment->setConnection($this->connection)->addComment($comment_data); if ($cid == 0) { $data['message'] = $sn . " insert comment error"; $data['code'] = 500; return $data; } // insert products_comments $productComment = new ProductsComment(); $affected = $productComment->setConnection($this->connection)->addProductComment(array('pid' => $pid, 'cid' => $cid)); if (empty($affected)) { $data['message'] = $sn . " insert products_comments failed"; $data['code'] = 500; return $data; } // insert five star $commentFiveStar = new FiveStar(); $affected = $commentFiveStar->setConnection($this->connection)->addCommentFiveStar(array('pid' => $pid, 'cid' => $cid, 'uid' => 1, 'grade' => 5, 'create' => $time)); if (empty($affected)) { $data['message'] = $sn . " insert widget_fivestars failed\n"; $data['code'] = 500; return $data; } return $data; }