🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
## 接口情况 作者:ncgis 时间:20150506 作用:获取商品详细信息(主要是图片价格快递信息) 提交方法:GET 提交参数 ~~~ good_id:商品id ~~~ 所在文件:product 接口地址:http://test.lingsq.com/index.php/api?method=lingsqapi.api.product.getProductdDetail&good_id=[good\_id] 返回数据样式: ~~~ ## 格式一 { "data": { "login": { "member_lv_id": "1", "status": true }, "goods": { "name": "黄绿豆芽", "price": "2.700", "store": "10000.00", "weight": "500.000", "units": "g", "appcontent": "", "mktprice": "2.700", "pic": [ { "l": "http://test.lingsq.com/public/images/store76/03/d1/0a/cbfdef9850527859a279380a23424552.jpg?1435113666#h", "m": "http://test.lingsq.com/public/images/store76/47/0b/30/f43a468bd0772ebe711af660380be760.jpg?1435113666#h", "s": "http://test.lingsq.com/public/images/store76/96/bc/b2/e0dce8acf1fe359bc9ec1b1383475540.jpg?1435113666#h", "image_id": "10f4c63be7867e13e624d57b657c8257" }, { "l": "http://test.lingsq.com/public/images/store76/9c/bd/77/bfa3d7838f7c370b1169c51f92d78d72.jpg?1435113669#h", "m": "http://test.lingsq.com/public/images/store76/74/40/d5/8e6a02599d775244efe9eb274cab108a.jpg?1435113669#h", "s": "http://test.lingsq.com/public/images/store76/74/0f/51/a7be1d03f7684ece168a9b31aa4b9207.jpg?1435113669#h", "image_id": "eb1b4d5e09950b44493281944f2674a0" }, { "l": "http://test.lingsq.com/public/images/store76/29/7e/de/bf02603eecef99e06b71c13ce3800531.jpg?1435113672#h", "m": "http://test.lingsq.com/public/images/store76/77/dc/0d/00e7a6a94113d819b6be660b61dfc073.jpg?1435113672#h", "s": "http://test.lingsq.com/public/images/store76/76/27/fd/60bb65621ed15e3c0f4b2a4a977125f1.jpg?1435113672#h", "image_id": "646be59d70cc8e626ef09cd26c0556dc" }, { "l": "http://test.lingsq.com/public/images/store76/78/af/28/d38f948065f0c91981ca4cc495e15486.jpg?1435113675#h", "m": "http://test.lingsq.com/public/images/store76/b5/77/5b/112e37856a3427ce7f559d933243d342.jpg?1435113675#h", "s": "http://test.lingsq.com/public/images/store76/1c/b6/51/941f787f8b0c4a30233bcb1e1f05f52c.jpg?1435113675#h", "image_id": "195cd9b852f0b8bf841af42c75a8c6e8" } ], "description": "<img src=\"http://www.lingsq.com/public/images/store76/ea/92/19/80d9ea7a38b3538c28122ae073c93897.jpg?1427452930#h\">" } }, "errNo": 1, "errMsg": "ok", "res": "" } ## 格式二 { "data": { "login": { "member_lv_id": "1", "status": true }, "goods": { "name": "test", "price": "10.000", "store": "400.00", "weight": "0.000", "units": "g", "appcontent": "4345343", "mktprice": "12.000", "product": [ { "mktprice": "12.000", "price": "10.000", "product_id": "721", "spec_info": "size:m", "store": "100.00", "unit": "间", "pic": [ { "l": "http://test.lingsq.com/public/images/store76/b7/a0/7f/839a7ec639545a9de86c63ae6ef085ae.jpg?1435113148#h", "m": "http://test.lingsq.com/public/images/store76/f9/89/c6/bea538ab23cc7cb14fa88cd3b2e35ad4.jpg?1435113148#h", "s": "http://test.lingsq.com/public/images/store76/50/29/88/901a5126f399b6d87d72d31d4e7dae1f.jpg?1435113148#h", "image_id": "9b03b050cb7ad236e5a43f59c754d1a8" }, { "l": "http://test.lingsq.com/public/images/store76/3f/94/2b/5af467fc939309774262e07b8c52dc09.jpg?1435113151#h", "m": "http://test.lingsq.com/public/images/store76/37/7a/32/663ed4738371dba8a7123c8f7c1ea354.jpg?1435113151#h", "s": "http://test.lingsq.com/public/images/store76/c2/70/8a/ac1900ab8291ad397702018b96a86acc.jpg?1435113151#h", "image_id": "ad031281c07b5b8e477bd8779de91336" } ], "lvpric": [ { "goods_id": "393", "product_id": "721", "level_id": "1", "price": "9.000" }, { "goods_id": "393", "product_id": "721", "level_id": "2", "price": "8.000" }, { "goods_id": "393", "product_id": "721", "level_id": "3", "price": "7.000" } ] }, { "mktprice": "13.200", "price": "11.000", "product_id": "722", "spec_info": "size:l", "store": "100.00", "unit": "间", "pic": [ { "l": "http://test.lingsq.com/public/images/store76/3f/94/2b/5af467fc939309774262e07b8c52dc09.jpg?1435113151#h", "m": "http://test.lingsq.com/public/images/store76/37/7a/32/663ed4738371dba8a7123c8f7c1ea354.jpg?1435113151#h", "s": "http://test.lingsq.com/public/images/store76/c2/70/8a/ac1900ab8291ad397702018b96a86acc.jpg?1435113151#h", "image_id": "ad031281c07b5b8e477bd8779de91336" } ], "lvpric": [ { "goods_id": "393", "product_id": "722", "level_id": "1", "price": "9.000" }, { "goods_id": "393", "product_id": "722", "level_id": "2", "price": "8.000" }, { "goods_id": "393", "product_id": "722", "level_id": "3", "price": "7.000" } ] }, { "mktprice": "134.400", "price": "112.000", "product_id": "723", "spec_info": "size:xl", "store": "100.00", "unit": "间", "pic": [ { "l": "http://test.lingsq.com/public/images/store76/b7/a0/7f/839a7ec639545a9de86c63ae6ef085ae.jpg?1435113148#h", "m": "http://test.lingsq.com/public/images/store76/f9/89/c6/bea538ab23cc7cb14fa88cd3b2e35ad4.jpg?1435113148#h", "s": "http://test.lingsq.com/public/images/store76/50/29/88/901a5126f399b6d87d72d31d4e7dae1f.jpg?1435113148#h", "image_id": "9b03b050cb7ad236e5a43f59c754d1a8" } ], "lvpric": [ { "goods_id": "393", "product_id": "723", "level_id": "1", "price": "115.000" }, { "goods_id": "393", "product_id": "723", "level_id": "2", "price": "114.000" }, { "goods_id": "393", "product_id": "723", "level_id": "3", "price": "113.000" } ] }, { "mktprice": "135.600", "price": "113.000", "product_id": "724", "spec_info": "size:xxl", "store": "100.00", "unit": "间", "pic": [ { "l": "http://test.lingsq.com/public/images/store76/3f/94/2b/5af467fc939309774262e07b8c52dc09.jpg?1435113151#h", "m": "http://test.lingsq.com/public/images/store76/37/7a/32/663ed4738371dba8a7123c8f7c1ea354.jpg?1435113151#h", "s": "http://test.lingsq.com/public/images/store76/c2/70/8a/ac1900ab8291ad397702018b96a86acc.jpg?1435113151#h", "image_id": "ad031281c07b5b8e477bd8779de91336" } ], "lvpric": [ { "goods_id": "393", "product_id": "724", "level_id": "1", "price": "11.000" }, { "goods_id": "393", "product_id": "724", "level_id": "2", "price": "11.000" }, { "goods_id": "393", "product_id": "724", "level_id": "3", "price": "11.000" } ] } ], "description": "adsfsdfasdfasdfsdfa\n<img src=\"http://test.lingsq.com/public/images/store76/b5/bf/91/adbc2448d14d9055b78a6b5c9710bf4b.jpg?1430902823#h\">" } }, "errNo": 1, "errMsg": "ok", "res": "" } ~~~ 参数说明 ~~~ ~~~ ## 实现代码 ~~~ /** * @作者 ncgis * @作用 主要是获取商品的详细信息 * @时间 20150506 * @请求方式 GET * @提交参数 good_id 必选 * @返回数据格式:见文档 * */ public function getProductdDetail() { if (empty($_GET["good_id"])) { $back["errNo"] = 20005; $back["errMsg"] = $this->errMsg($back["errNo"]); return $back; } $gid = $_GET["good_id"]; $goodtable = app::get('b2c')->model('goods'); //最大产品 $productstable = app::get('b2c')->model('products'); //产品 $image_attachtable = app::get('image')->model('image_attach'); $goods_lv_pricetable = app::get('b2c')->model('goods_lv_price'); //价格 $filter["goods_id"] = $gid; $goods = $goodtable->getList("name,price,store,weight,units,appcontent,mktprice,spec_desc",$filter); unset($filter); if (empty($goods)) { $pagedata["errNo"] = 20009; $pagedata["errMsg"] = $this->errMsg($pagedata["errNo"]); return $pagedata; } $goods[0]["units"] = empty($goods[0]["units"]) ? "g" : $goods[0]["units"]; $filter["goods_id"] = $gid; // $product = $productstable->getList("mktprice,price,product_id,spec_info,store,unit,spec_desc",$filter); unset($filter); $filter["target_id"] = $gid; $filter["target_type"] = "goods"; $images = $image_attachtable->getList("*", $filter); $siteMember = $this->libProduct->get_current_member(); $login['member_lv_id'] = $siteMember['member_lv']; $login['status'] = $siteMember['member_id'] ? true : false; $back["data"]["login"] = $login; unset($filter); if (!empty($goods["0"]["spec_desc"])) { foreach ($product as $key => $v) { $spec_private_value_idarray = array_keys($v["spec_desc"]["spec_private_value_id"]); $spec_private_value = array_values($v["spec_desc"]["spec_private_value_id"]); array_push($spec_private_value_idarray, $spec_private_value["0"]); $picid = explode(",", $goods["0"]["spec_desc"][$spec_private_value_idarray["0"]][$spec_private_value_idarray["1"]]["spec_goods_images"]); $filter["image_id|in"] = $picid; $images = $image_attachtable->getList("*", $filter); $product[$key]["pic"] = $this->libProduct->getImageUrl($images); unset($filter); $filter["goods_id"] = $gid; $filter["product_id"] = $v["product_id"]; $lvpric = $goods_lv_pricetable->getList("*", $filter); if (!empty($lvpric)) { $product[$key]["lvpric"] = $lvpric; } unset($product[$key]["spec_desc"]); } unset($goods["0"]["spec_desc"]); $goods["0"]["product"] = $product; $back["data"]["goods"] = $goods["0"]; $back["data"]["goods"]["description"] = $this->getProductNewsDetail($gid); } else { unset($goods["0"]["spec_desc"]); $goods["0"]["pic"] = $this->libProduct->getImageUrl($images); $filter["goods_id"] = $gid; $lvpric = $goods_lv_pricetable->getList("*", $filter); if (!empty($lvpric)) { $goods["0"]["lvpric"] = $lvpric; } $goods["0"]["description"] = $this->getProductNewsDetail($gid); $back["data"]["goods"] = $goods["0"]; //$back["data"]["goods"] = $goods["0"]; } $back["errNo"] = 1; $back["errMsg"] = $this->errMsg($back["errNo"]); return $back; } /** * @作用 主要是获取商品的详细信息 完 * */ public function getProductNewsDetail($goods_id) { $org_aGoods = kernel::single('b2c_goods_model')->getGoods($goods_id); return $org_aGoods['description']; } ~~~