Goods.php 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Db;
  4. use think\facade\Lang;
  5. /**
  6. * ============================================================================
  7. *
  8. * ============================================================================
  9. * 版权所有 2014-2028 浙江惠利玛产业互联网有限公司,并保留所有权利。
  10. * 网站地址: https://www.valimart.net/
  11. * ----------------------------------------------------------------------------
  12. *
  13. * ============================================================================
  14. * 商品控制器
  15. */
  16. class Goods extends MobileMall {
  17. private $PI = 3.14159265358979324;
  18. private $x_pi = 0;
  19. public function initialize() {
  20. parent::initialize();
  21. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/goods.lang.php');
  22. $this->x_pi = 3.14159265358979324 * 3000.0 / 180.0;
  23. }
  24. /**
  25. * @api {POST} api/Goods/goods_list 商品列表
  26. * @apiVersion 1.0.0
  27. * @apiGroup Goods
  28. *
  29. * @apiParam {Int} cate_id 分类ID
  30. * @apiParam {String} keyword 关键词
  31. * @apiParam {String} b_id 品牌id
  32. * @apiParam {Float} price_from 价格从
  33. * @apiParam {Float} price_to 价格到
  34. * @apiParam {Int} sort_key 排序键 goods_salenum销量 goods_click浏览量 goods_price价格
  35. * @apiParam {Int} sort_order 排序值 1升序 2降序
  36. * @apiParam {Int} gift 是否有赠品 1有
  37. * @apiParam {Int} own_shop 自营 1是
  38. * @apiParam {Int} area_id 地区id
  39. * @apiParam {Int} xianshi 是否秒杀 1是
  40. * @apiParam {Int} page 页码
  41. * @apiParam {Int} per_page 每页显示数量
  42. *
  43. * @apiSuccess {String} code 返回码,10000为成功
  44. * @apiSuccess {String} message 返回消息
  45. * @apiSuccess {Object} result 返回数据
  46. * @apiSuccess {Object[]} result.goods_list 商品列表
  47. * @apiSuccess {Int} result.goods_list.evaluation_count 评论数
  48. * @apiSuccess {Float} result.goods_list.evaluation_good_star 评分
  49. * @apiSuccess {String} result.goods_list.goods_advword 广告词
  50. * @apiSuccess {Int} result.goods_list.goods_id 商品ID
  51. * @apiSuccess {String} result.goods_list.goods_image 商品图片名称
  52. * @apiSuccess {String} result.goods_list.goods_image_url 商品图片完整路径
  53. * @apiSuccess {Float} result.goods_list.goods_marketprice 商品市场价
  54. * @apiSuccess {String} result.goods_list.goods_name 商品名称
  55. * @apiSuccess {Float} result.goods_list.goods_price 商品价格
  56. * @apiSuccess {Float} result.goods_list.goods_promotion_price 商品促销价
  57. * @apiSuccess {String} result.goods_list.goods_promotion_type 促销类型
  58. * @apiSuccess {Int} result.goods_list.goods_salenum 商品销售量
  59. * @apiSuccess {Boolean} result.goods_list.group_flag 是否抢购 true是false否
  60. * @apiSuccess {Int} result.goods_list.is_goodsfcode 是否F码 1是0否
  61. * @apiSuccess {Int} result.goods_list.is_have_gift 是否含赠品 1是0否
  62. * @apiSuccess {Int} result.goods_list.is_platform_store 是否平台自营 1是0否
  63. * @apiSuccess {Int} result.goods_list.is_virtual 是否虚拟商品 1是0否
  64. * @apiSuccess {Int} result.goods_list.store_id 店铺ID
  65. * @apiSuccess {String} result.goods_list.store_name 店铺名称
  66. * @apiSuccess {Boolean} result.goods_list.xianshi_flag 是否秒杀 true是false否
  67. * @apiSuccess {Int} result.page_total 总页数
  68. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  69. */
  70. public function goods_list() {
  71. $goods_model = model('goods');
  72. $search_model = model('search');
  73. //查询条件
  74. $condition = array();
  75. $cate_id = intval(input('param.cate_id'));
  76. $keyword = $default_classid = input('param.keyword');
  77. $b_id = intval(input('param.b_id'));
  78. //获得经过属性过滤的商品信息
  79. $this->_model_search = model('search');
  80. list($goods_param, $brand_array, $initial_array, $attr_array, $checked_brand, $checked_attr) = $this->_model_search->getAttribute(input('param.'), $default_classid);
  81. if (isset($goods_param['class']['depth'])) {
  82. $condition[] = array('goodscommon.gc_id_' . $goods_param['class']['depth'], '=', $goods_param['class']['gc_id']);
  83. }
  84. if (isset($goods_param['goodsid_array'])) {
  85. $condition[] = array('goods.goods_id', 'in', $goods_param['goodsid_array']);
  86. }
  87. if ($cate_id > 0) {
  88. $condition=model('goods')->_getRecursiveClass($condition,$cate_id,'goodscommon');
  89. }
  90. if (!empty($keyword)) {
  91. $condition[] = array('goodscommon.goods_name|goodscommon.goods_advword', 'like', '%' . $keyword . '%');
  92. if (cookie('hisSearch') == '') {
  93. $his_sh_list = array();
  94. } else {
  95. $his_sh_list = explode('~', cookie('hisSearch'));
  96. }
  97. if (strlen($keyword) <= 20 && !in_array($keyword, $his_sh_list)) {
  98. if (array_unshift($his_sh_list, $keyword) > 8) {
  99. array_pop($his_sh_list);
  100. }
  101. }
  102. cookie('hisSearch', implode('~', $his_sh_list), 2592000);
  103. }
  104. if ($b_id > 0) {
  105. $condition[] = array('goodscommon.brand_id', '=', $b_id);
  106. }
  107. $price_from = input('param.price_from');
  108. $price_to = input('param.price_to');
  109. $price_from = preg_match('/^[\d.]{1,20}$/', $price_from) ? $price_from : null;
  110. $price_to = preg_match('/^[\d.]{1,20}$/', $price_to) ? $price_to : null;
  111. //所需字段
  112. $fieldstr = "goods.goods_id,goods.goods_storage,goodscommon.goods_commonid,goodscommon.store_id,goodscommon.goods_name,goodscommon.goods_advword,goodscommon.goods_price,goods.goods_promotion_price,goods.goods_promotion_type,goodscommon.goods_marketprice,goodscommon.goods_image,goods.goods_salenum,goods.evaluation_good_star,goods.evaluation_count";
  113. $fieldstr .= ',goodscommon.is_virtual,goodscommon.is_goodsfcode,goods.is_have_gift,goodscommon.store_name,goodscommon.is_platform_store';
  114. //排序方式
  115. $order = $this->_goods_list_order(input('param.sort_key'), input('param.sort_order'));
  116. if ($price_from && $price_to) {
  117. $condition[] = array('goods.goods_promotion_price', 'between', "{$price_from},{$price_to}");
  118. } elseif ($price_from) {
  119. $condition[] = array('goods.goods_promotion_price', '>=', $price_from);
  120. } elseif ($price_to) {
  121. $condition[] = array('goods.goods_promotion_price', '<=', $price_to);
  122. }
  123. if (input('param.gift') == 1) {
  124. $condition[] = array('goods.is_have_gift', '=', 1);
  125. }
  126. if (input('param.own_shop') == 1) {
  127. $condition[] = array('goodscommon.store_id', '=', 1);
  128. }
  129. if (intval(input('param.area_id')) > 0) {
  130. $condition[] = array('goodscommon.areaid_1', '=', intval(input('param.area_id')));
  131. }
  132. //抢购和秒杀搜索
  133. $_tmp = array();
  134. if (input('param.groupbuy') == 1) {
  135. $_tmp[] = 1;
  136. }
  137. if (input('param.xianshi') == 1) {
  138. $_tmp[] = 2;
  139. if(input('param.goods_price')=='goods_price'){
  140. $order='goods_promotion_price';
  141. if (input('param.sort_order') == 'asc') {
  142. $order .= ' asc';
  143. }else{
  144. $order .= ' desc';
  145. }
  146. }
  147. }
  148. if ($_tmp) {
  149. $condition[] = array('goods.goods_promotion_type', 'in', $_tmp);
  150. }
  151. unset($_tmp);
  152. //虚拟商品
  153. if (input('param.virtual') == 1) {
  154. $condition[] = array('goodscommon.is_virtual', '=', 1);
  155. }
  156. $goods_list = $goods_model->getGoodsUnionList($condition, $fieldstr, $order, 'goodscommon.goods_commonid', $this->pagesize);
  157. // }
  158. //处理商品列表(抢购、秒杀、商品图片)
  159. $goods_list = $this->_goods_list_extend($goods_list);
  160. $result = array_merge(array('goods_list' => $goods_list), mobile_page(is_object($goods_model->page_info) ? $goods_model->page_info : ''));
  161. ds_json_encode(10000, '', $result);
  162. }
  163. /**
  164. * @api {POST} api/Goods/get_attribute 获取分类下的属性
  165. * @apiVersion 1.0.0
  166. * @apiGroup Goods
  167. *
  168. * @apiParam {Int} cate_id 分类ID
  169. * @apiParam {String} a_id 已选择的属性
  170. * @apiParam {Int} b_id 已选择的品牌
  171. *
  172. * @apiSuccess {String} code 返回码,10000为成功
  173. * @apiSuccess {String} message 返回消息
  174. * @apiSuccess {Object} result 返回数据
  175. * @apiSuccess {Object} result.goods_param 商品数据集
  176. * @apiSuccess {Object} result.brand_array 品牌列表
  177. * @apiSuccess {Object} result.attr_array 属性列表
  178. * @apiSuccess {Object} result.checked_brand 已选择的品牌
  179. * @apiSuccess {Object} result.checked_attr 已选择的属性
  180. */
  181. public function get_attribute() {
  182. $this->_model_search = model('search');
  183. $default_classid = intval(input('param.cate_id'));
  184. //获得经过属性过滤的商品信息
  185. list($goods_param, $brand_array, $initial_array, $attr_array, $checked_brand, $checked_attr) = $this->_model_search->getAttribute(input('param.'), $default_classid);
  186. $result = array(
  187. 'goods_param' => $goods_param,
  188. 'brand_array' => $brand_array,
  189. 'initial_array' => $initial_array,
  190. 'attr_array' => $attr_array,
  191. 'checked_brand' => $checked_brand,
  192. 'checked_attr' => $checked_attr,
  193. );
  194. ds_json_encode(10000, '', $result);
  195. }
  196. /**
  197. * @api {POST} api/Goods/get_bundling 优惠套装
  198. * @apiVersion 1.0.0
  199. * @apiGroup Goods
  200. *
  201. * @apiParam {Int} goods_id 商品ID
  202. *
  203. * @apiSuccess {String} code 返回码,10000为成功
  204. * @apiSuccess {String} message 返回消息
  205. * @apiSuccess {Object} result 返回数据
  206. * @apiSuccess {Object} result.bundling_array 优惠套餐分类列表,键为分类ID
  207. * @apiSuccess {Float} result.bundling_array.freight 邮费
  208. * @apiSuccess {Int} result.bundling_array.id 优惠套餐分类ID
  209. * @apiSuccess {String} result.bundling_array.name 优惠套餐分类名称
  210. * @apiSuccess {Float} result.bundling_array.price 优惠套餐价
  211. * @apiSuccess {Float} result.bundling_array.storecost_price 原价
  212. * @apiSuccess {Object} result.b_goods_array 优惠套餐商品列表,键为分类ID
  213. * @apiSuccess {Int} result.b_goods_array.id 优惠套餐分类ID
  214. * @apiSuccess {String} result.b_goods_array.image 商品图片
  215. * @apiSuccess {String} result.b_goods_array.name 商品名称
  216. * @apiSuccess {Float} result.b_goods_array.price 优惠后价格
  217. * @apiSuccess {Float} result.b_goods_array.shop_price 原价
  218. */
  219. public function get_bundling() {
  220. $goods_id = intval(input('param.goods_id'));
  221. if ($goods_id <= 0) {
  222. ds_json_encode(10001, lang('param_error'));
  223. }
  224. // 优惠套装
  225. $array = model('pbundling')->getBundlingCacheByGoodsId($goods_id);
  226. if (!empty($array)) {
  227. $bundling_array = unserialize($array['bundling_array']);
  228. $b_goods_array = unserialize($array['b_goods_array']);
  229. ds_json_encode(10000, '', array('bundling_array' => !empty($bundling_array) ? $bundling_array : false, 'b_goods_array' => !empty($b_goods_array) ? $b_goods_array : false));
  230. } else {
  231. ds_json_encode(10001, lang('bundling_not_exist'));
  232. }
  233. }
  234. /**
  235. * 商品列表排序方式
  236. */
  237. private function _goods_list_order($sort_key, $sort_order) {
  238. $result = 'goodscommon.mall_goods_commend desc,goodscommon.mall_goods_sort asc';
  239. if (!empty($sort_key)) {
  240. $sequence = 'desc';
  241. if ($sort_order == 'asc') {
  242. $sequence = 'asc';
  243. }
  244. switch ($sort_key) {
  245. //销量
  246. case 'goods_salenum' :
  247. $result = 'goods.goods_salenum' . ' ' . $sequence;
  248. break;
  249. //浏览量
  250. case 'goods_click' :
  251. $result = 'goods.goods_click' . ' ' . $sequence;
  252. break;
  253. //价格
  254. case 'goods_price' :
  255. $result = 'goodscommon.goods_price' . ' ' . $sequence;
  256. break;
  257. //新品
  258. case 'goods_addtime' :
  259. $result = 'goodscommon.goods_addtime' . ' ' . $sequence;
  260. break;
  261. }
  262. }
  263. return $result;
  264. }
  265. private function _goods_list_extend($goods_list) {
  266. //获取商品列表编号数组
  267. $commonid_array = array();
  268. $goodsid_array = array();
  269. $goods_model=model('goods');
  270. foreach ($goods_list as $key => $value) {
  271. if(!$value['goods_storage']){
  272. $goods_info=$goods_model->getGoodsStorageByCommonId($value['goods_commonid']);
  273. if($goods_info){
  274. $goods_list[$key]['goods_id']=$value['goods_id']=$goods_info['goods_id'];
  275. $goods_list[$key]['goods_promotion_price']=$goods_info['goods_promotion_price'];
  276. }
  277. }
  278. $commonid_array[] = $value['goods_commonid'];
  279. $goodsid_array[] = $value['goods_id'];
  280. }
  281. //促销
  282. $store_model = model('store');
  283. $groupbuy_list = model('groupbuy')->getGroupbuyListByGoodsCommonIDString(implode(',', $commonid_array));
  284. $xianshi_list = model('pxianshigoods')->getXianshigoodsListByGoodsString(implode(',', $goodsid_array));
  285. foreach ($goods_list as $key => $value) {
  286. //抢购
  287. if (isset($groupbuy_list[$value['goods_commonid']])) {
  288. $goods_list[$key]['goods_price'] = $groupbuy_list[$value['goods_commonid']]['groupbuy_price'];
  289. $goods_list[$key]['group_flag'] = true;
  290. } else {
  291. $goods_list[$key]['group_flag'] = false;
  292. }
  293. //秒杀
  294. if (isset($xianshi_list[$value['goods_id']]) && !$goods_list[$key]['group_flag']) {
  295. $goods_list[$key]['goods_price'] = $xianshi_list[$value['goods_id']]['xianshigoods_price'];
  296. $goods_list[$key]['xianshi_flag'] = true;
  297. } else {
  298. $goods_list[$key]['xianshi_flag'] = false;
  299. }
  300. //商品图片url
  301. $goods_list[$key]['goods_image_url'] = goods_cthumb($value['goods_image'], 480, $value['store_id']);
  302. $store_info = $store_model->getStoreInfoByID($value['store_id']);
  303. $goods_list[$key]['store_name'] = $store_info['store_name'];
  304. unset($goods_list[$key]['goods_commonid']);
  305. unset($goods_list[$key]['nc_distinct']);
  306. }
  307. return $goods_list;
  308. }
  309. /**
  310. * @api {POST} api/Goods/goods_detail 商品详细页
  311. * @apiVersion 1.0.0
  312. * @apiGroup Goods
  313. *
  314. * @apiParam {Int} goods_id 商品ID
  315. *
  316. * @apiSuccess {String} code 返回码,10000为成功
  317. * @apiSuccess {String} message 返回消息
  318. * @apiSuccess {Object} result 返回数据
  319. * @apiSuccess {Object} result.consult_type 咨询类型列表,键为咨询类型ID
  320. * @apiSuccess {Int} result.consult_type.consulttype_id 咨询类型ID
  321. * @apiSuccess {Object} result.consult_type.consulttype_introduce 咨询介绍
  322. * @apiSuccess {Object} result.consult_type.consulttype_name 咨询类型标题
  323. * @apiSuccess {Int} result.consult_type.consulttype_sort 咨询类型排序
  324. * @apiSuccess {Object[]} result.gift_array 赠品列表
  325. * @apiSuccess {Int} result.gift_array.gift_id 赠品ID
  326. * @apiSuccess {Int} result.gift_array.gift_goodsid 赠品商品ID
  327. * @apiSuccess {Object} result.gift_array.gift_goodsname 主商品名称
  328. * @apiSuccess {Object} result.gift_array.gift_goodsimage 主商品图片名称
  329. * @apiSuccess {Object} result.gift_array.gift_goodsimage_url 主商品图片完整路径
  330. * @apiSuccess {Object} result.gift_array.gift_amount 赠品数量
  331. * @apiSuccess {Int} result.gift_array.goods_id 主商品ID
  332. * @apiSuccess {Int} result.gift_array.goods_commonid 主商品公共ID
  333. * @apiSuccess {Object[]} result.goods_commend_list 推荐商品列表
  334. * @apiSuccess {Int} result.goods_commend_list.goods_id 商品ID
  335. * @apiSuccess {Object} result.goods_commend_list.goods_image_url 商品图片
  336. * @apiSuccess {Object} result.goods_commend_list.goods_name 商品名称
  337. * @apiSuccess {Float} result.goods_commend_list.goods_price 商品价格
  338. * @apiSuccess {Float} result.goods_commend_list.goods_promotion_price 商品促销价
  339. * @apiSuccess {Object[]} result.goods_eval_list 商品评论列表
  340. * @apiSuccess {Int} result.goods_eval_list.geval_addtime 评论时间
  341. * @apiSuccess {String} result.goods_eval_list.geval_content 评论内容
  342. * @apiSuccess {String} result.goods_eval_list.geval_explain 店家解释
  343. * @apiSuccess {Int} result.goods_eval_list.geval_frommemberid 评论用户ID
  344. * @apiSuccess {String} result.goods_eval_list.geval_frommembername 评论用户名
  345. * @apiSuccess {Int} result.goods_eval_list.geval_goodsid 评论商品ID
  346. * @apiSuccess {String} result.goods_eval_list.geval_goodsimage 评论商品图片
  347. * @apiSuccess {String} result.goods_eval_list.geval_goodsname 评论商品名称
  348. * @apiSuccess {Float} result.goods_eval_list.geval_goodsprice 评论商品价格
  349. * @apiSuccess {Int} result.goods_eval_list.geval_id 评论ID
  350. * @apiSuccess {String} result.goods_eval_list.geval_image 评论图片
  351. * @apiSuccess {Int} result.goods_eval_list.geval_isanonymous 是否匿名 0:不是 1:匿名评价
  352. * @apiSuccess {Int} result.goods_eval_list.geval_ordergoodsid 订单商品ID
  353. * @apiSuccess {Int} result.goods_eval_list.geval_orderid 订单ID
  354. * @apiSuccess {String} result.goods_eval_list.geval_orderno 订单编号
  355. * @apiSuccess {String} result.goods_eval_list.geval_remark 管理员对评价的处理备注
  356. * @apiSuccess {Int} result.goods_eval_list.geval_scores 评分
  357. * @apiSuccess {Int} result.goods_eval_list.geval_state 评论状态 0为正常 1为禁止显示
  358. * @apiSuccess {Int} result.goods_eval_list.geval_storeid 商品店铺ID
  359. * @apiSuccess {String} result.goods_eval_list.geval_storename 商品店铺名称
  360. * @apiSuccess {Object} result.goods_evaluate_info 商品评论综合信息
  361. * @apiSuccess {Int} result.goods_evaluate_info.all 商品评论总数
  362. * @apiSuccess {Int} result.goods_evaluate_info.bad 差评数
  363. * @apiSuccess {Int} result.goods_evaluate_info.bad_percent 差评率
  364. * @apiSuccess {Int} result.goods_evaluate_info.good 好评数
  365. * @apiSuccess {Int} result.goods_evaluate_info.good_percent 好评率
  366. * @apiSuccess {Int} result.goods_evaluate_info.good_star 好评评分
  367. * @apiSuccess {Int} result.goods_evaluate_info.normal 中评数
  368. * @apiSuccess {Int} result.goods_evaluate_info.normal_percent 中评率
  369. * @apiSuccess {Int} result.goods_evaluate_info.star_average 平均评分
  370. * @apiSuccess {Object} result.goods_hair_info 商品运费信息
  371. * @apiSuccess {String} result.goods_hair_info.area_name 地区名称
  372. * @apiSuccess {String} result.goods_hair_info.content 运费描述
  373. * @apiSuccess {Boolean} result.goods_hair_info.if_store 是否有货 true是false否
  374. * @apiSuccess {String} result.goods_hair_info.if_store_cn 库存描述
  375. * @apiSuccess {String} result.goods_image 商品图片,用逗号分隔
  376. * @apiSuccess {Object} result.goods_info 商品信息
  377. * @apiSuccess {Int} result.goods_info.appoint_satedate 预约商品出售时间
  378. * @apiSuccess {Int} result.goods_info.areaid_1 一级地区id
  379. * @apiSuccess {Int} result.goods_info.areaid_2 二级地区id
  380. * @apiSuccess {Boolean} result.goods_info.cart 是否可以加入购物车
  381. * @apiSuccess {Int} result.goods_info.color_id 颜色规格值ID
  382. * @apiSuccess {Int} result.goods_info.evaluation_count 评论数
  383. * @apiSuccess {Int} result.goods_info.evaluation_good_star 好评评分
  384. * @apiSuccess {Int} result.goods_info.gc_id_1 一级分类ID
  385. * @apiSuccess {Int} result.goods_info.gc_id_2 二级分类ID
  386. * @apiSuccess {Int} result.goods_info.gc_id_3 三级分类ID
  387. * @apiSuccess {String} result.goods_info.goods_advword 广告词
  388. * @apiSuccess {String} result.goods_info.goods_attr 商品属性
  389. * @apiSuccess {Int} result.goods_info.goods_click 商品点击次数
  390. * @apiSuccess {Int} result.goods_info.goods_collect 收藏数
  391. * @apiSuccess {Int} result.goods_info.goods_commonid 商品公共ID
  392. * @apiSuccess {Float} result.goods_info.goods_costprice 商品成本价
  393. * @apiSuccess {Int} result.goods_info.goods_discount 商品折扣
  394. * @apiSuccess {Float} result.goods_info.goods_freight 运费
  395. * @apiSuccess {Int} result.goods_info.goods_id 商品ID
  396. * @apiSuccess {Float} result.goods_info.goods_marketprice 商品市场价
  397. * @apiSuccess {String} result.goods_info.goods_mgdiscount 会员等级折扣
  398. * @apiSuccess {String} result.goods_info.goods_name 商品名称
  399. * @apiSuccess {Float} result.goods_info.goods_price 商品价格
  400. * @apiSuccess {Float} result.goods_info.goods_promotion_price 商品促销价
  401. * @apiSuccess {String} result.goods_info.goods_promotion_type 商品促销类型
  402. * @apiSuccess {Int} result.goods_info.goods_salenum 销售量
  403. * @apiSuccess {String} result.goods_info.goods_serial 货号
  404. * @apiSuccess {String} result.goods_info.goods_spec 商品规格序列化
  405. * @apiSuccess {String} result.goods_info.goods_specname 规格名称序列化
  406. * @apiSuccess {String} result.goods_info.goods_stcids 店铺分类id 首尾用,隔开
  407. * @apiSuccess {Int} result.goods_info.goods_storage 库存
  408. * @apiSuccess {Int} result.goods_info.goods_storage_alarm 预警库存
  409. * @apiSuccess {Int} result.goods_info.goods_url 商品PC端连接
  410. * @apiSuccess {Int} result.goods_info.goods_vat 是否开具增值税发票 1:是 0:否
  411. * @apiSuccess {Object} result.goods_info.groupbuy_info 抢购信息
  412. * @apiSuccess {Float} result.goods_info.inviter_amount 商品已结算的分销佣金
  413. * @apiSuccess {Int} result.goods_info.inviter_open 是否开启分销 1是0否
  414. * @apiSuccess {Float} result.goods_info.inviter_ratio_1 一级分销比例
  415. * @apiSuccess {Float} result.goods_info.inviter_ratio_2 二级分销比例
  416. * @apiSuccess {Float} result.goods_info.inviter_ratio_3 三级分销比例
  417. * @apiSuccess {Float} result.goods_info.inviter_total_amount 总分销金额
  418. * @apiSuccess {Int} result.goods_info.inviter_total_quantity 总分销量
  419. * @apiSuccess {Int} result.goods_info.is_appoint 是否是预约商品 1:是 0:否
  420. * @apiSuccess {Int} result.goods_info.is_goodsfcode 是否是F码商品 1:是 0:否
  421. * @apiSuccess {Int} result.goods_info.is_have_gift 是否含赠品 1:是 0:否
  422. * @apiSuccess {Int} result.goods_info.is_platform_store 是否自营商品 1:是 0:否
  423. * @apiSuccess {Int} result.goods_info.is_virtual 是否是虚拟商品 1:是 0:否
  424. * @apiSuccess {Object} result.goods_info.mgdiscount_info 会员等级折扣信息
  425. * @apiSuccess {Object} result.goods_info.pintuan_info 拼团信息
  426. * @apiSuccess {Int} result.goods_info.pintuangroup_share_id 拼团ID
  427. * @apiSuccess {Int} result.goods_info.plateid_bottom 底部关联板式
  428. * @apiSuccess {Int} result.goods_info.plateid_top 顶部关联板式
  429. * @apiSuccess {Int} result.goods_info.region_id 地区ID
  430. * @apiSuccess {String} result.goods_info.spec_name 规格名称
  431. * @apiSuccess {Int} result.goods_info.spec_value 规格值
  432. * @apiSuccess {Int} result.goods_info.transport_id 商品售卖区域
  433. * @apiSuccess {String} result.goods_info.transport_title 商品售卖区域名称
  434. * @apiSuccess {Int} result.goods_info.virtual_indate 虚拟商品有效期
  435. * @apiSuccess {Int} result.goods_info.virtual_invalid_refund 是否允许过期退款 1:是 0:否
  436. * @apiSuccess {Int} result.goods_info.virtual_limit 虚拟商品购买上限
  437. * @apiSuccess {Object} result.goods_info.xianshi_info 秒杀信息
  438. * @apiSuccess {Object[]} result.mb_body 商品详情列表
  439. * @apiSuccess {String} result.mb_body.type 详情类型 text文字image图片
  440. * @apiSuccess {String} result.mb_body.value 详情值
  441. * @apiSuccess {Float} result.inviter_amount 分销佣金
  442. * @apiSuccess {Boolean} result.is_favorate 是否已收藏 true是false否
  443. * @apiSuccess {Object} result.spec_image 规格图片列表,键为规格ID,值为规格图片完整路径
  444. * @apiSuccess {Object} result.spec_list 规格商品ID列表,键为规格ID,值为商品ID
  445. * @apiSuccess {Object} result.store_info 店铺信息
  446. * @apiSuccess {Int} result.store_info.goods_count 商品数
  447. * @apiSuccess {Int} result.store_info.is_platform_store 是否平台自营 1是0否
  448. * @apiSuccess {Int} result.store_info.member_id 用户ID
  449. * @apiSuccess {String} result.store_info.member_name 用户名称
  450. * @apiSuccess {String} result.store_info.store_address 店铺地址
  451. * @apiSuccess {Object} result.store_info.store_credit 店铺信用信息
  452. * @apiSuccess {Object} result.store_info.store_credit.store_deliverycredit 发货信用信息
  453. * @apiSuccess {Int} result.store_info.store_credit.store_deliverycredit.credit 发货信用值
  454. * @apiSuccess {String} result.store_info.store_credit.store_deliverycredit.text 发货信用描述
  455. * @apiSuccess {Object} result.store_info.store_credit.store_desccredit 描述相符信用信息
  456. * @apiSuccess {Int} result.store_info.store_credit.store_desccredit.credit 描述相符信用值
  457. * @apiSuccess {String} result.store_info.store_credit.store_desccredit.text 描述相符信用描述
  458. * @apiSuccess {Object} result.store_info.store_credit.store_servicecredit 服务态度信用信息
  459. * @apiSuccess {Int} result.store_info.store_credit.store_servicecredit.credit 服务态度信用值
  460. * @apiSuccess {String} result.store_info.store_credit.store_servicecredit.text 服务态度信用描述
  461. * @apiSuccess {Int} result.store_info.store_id 店铺ID
  462. * @apiSuccess {String} result.store_info.store_logo 店铺logo
  463. * @apiSuccess {String} result.store_info.store_name 店铺名称
  464. * @apiSuccess {Object[]} result.voucher 店铺优惠券列表
  465. * @apiSuccess {String} result.voucher.vouchertemplate_enddate 优惠券过期时间描述
  466. * @apiSuccess {Int} result.voucher.vouchertemplate_id 优惠券模板ID
  467. * @apiSuccess {Float} result.voucher.vouchertemplate_limit 优惠券最低消费金额
  468. * @apiSuccess {Int} result.voucher.vouchertemplate_price 优惠金额
  469. */
  470. public function goods_detail() {
  471. $goods_id = intval(input('param.goods_id'));
  472. $area_id = intval(input('param.area_id'));
  473. $bargain_id = intval(input('param.bargain_id'));
  474. // 商品详细信息
  475. $goods_model = model('goods');
  476. $goods_detail = $goods_model->getGoodsDetail($goods_id);
  477. //halt($goods_detail);
  478. if (empty($goods_detail)) {
  479. ds_json_encode(10001, lang('goods_goods_not_exist'));
  480. }
  481. foreach ($goods_detail['gift_array'] as $k => $v) {
  482. $goods_detail['gift_array'][$k]['gift_goodsimage_url'] = goods_cthumb($v['gift_goodsimage'], '240', $goods_detail['goods_info']['store_id']);
  483. }
  484. //$goods_list = $goods_model->getGoodsContract(array(0=>$goods_detail['goods_info']));
  485. //$goods_detail['goods_info'] = $goods_list[0];
  486. //推荐商品
  487. $hot_sales = $goods_model->getGoodsCommendList($goods_detail['goods_info']['store_id'], 6);
  488. $goodsid_array = array();
  489. foreach ($hot_sales as $value) {
  490. $goodsid_array[] = $value['goods_id'];
  491. }
  492. $goods_commend_list = array();
  493. foreach ($hot_sales as $value) {
  494. $goods_commend = array();
  495. $goods_commend['goods_id'] = $value['goods_id'];
  496. $goods_commend['goods_name'] = $value['goods_name'];
  497. $goods_commend['goods_price'] = $value['goods_price'];
  498. $goods_commend['goods_promotion_price'] = $value['goods_promotion_price'];
  499. $goods_commend['goods_img_480'] = goods_cthumb($value['goods_image'], 240);
  500. $goods_commend['goods_salenum'] = $value['goods_salenum'];
  501. $goods_commend_list[] = $goods_commend;
  502. }
  503. $goods_detail['goods_commend_list'] = $goods_commend_list;
  504. $store_info = model('store')->getStoreInfoByID($goods_detail['goods_info']['store_id']);
  505. $goods_detail['store_info']['store_avatar'] = get_store_logo($store_info['store_avatar'], 'store_avatar');
  506. $goods_detail['store_info']['store_logo'] = get_store_logo($store_info['store_logo'], 'store_logo');
  507. $goods_detail['store_info']['store_id'] = $store_info['store_id'];
  508. $goods_detail['store_info']['store_name'] = $store_info['store_name'];
  509. $goods_detail['store_info']['member_id'] = $store_info['member_id'];
  510. $goods_detail['store_info']['member_name'] = $store_info['member_name'];
  511. $goods_detail['store_info']['is_platform_store'] = $store_info['is_platform_store'];
  512. $goods_detail['store_info']['store_address'] = $store_info['area_info'] . $store_info['store_address'];
  513. $goods_detail['store_info']['goods_count'] = $store_info['goods_count'];
  514. $goods_detail['store_info']['store_baozh'] = $store_info['store_baozh'];
  515. $goods_detail['store_info']['store_shiti'] = $store_info['store_shiti'];
  516. $goods_detail['store_info']['store_qtian'] = $store_info['store_qtian'];
  517. $goods_detail['store_info']['store_zhping'] = $store_info['store_zhping'];
  518. $goods_detail['store_info']['store_erxiaoshi'] = $store_info['store_erxiaoshi'];
  519. $goods_detail['store_info']['store_tuihuo'] = $store_info['store_tuihuo'];
  520. $goods_detail['store_info']['store_shiyong'] = $store_info['store_shiyong'];
  521. $goods_detail['store_info']['store_xiaoxie'] = $store_info['store_xiaoxie'];
  522. $goods_detail['store_info']['store_huodaofk'] = $store_info['store_huodaofk'];
  523. $goods_detail['store_info']['store_avaliable_deposit'] = $store_info['store_avaliable_deposit'];
  524. if ($store_info['is_platform_store']) {
  525. $goods_detail['store_info']['store_credit'] = array(
  526. 'store_desccredit' => array(
  527. 'text' => lang('store_desccredit'),
  528. 'credit' => 5,
  529. 'percent' => '----',
  530. 'percent_class' => 'equal',
  531. 'percent_text' => lang('percent_text_equal'),
  532. ),
  533. 'store_servicecredit' => array(
  534. 'text' => lang('store_servicecredit'),
  535. 'credit' => 5,
  536. 'percent' => '----',
  537. 'percent_class' => 'equal',
  538. 'percent_text' => lang('percent_text_equal'),
  539. ),
  540. 'store_deliverycredit' => array(
  541. 'text' => lang('store_deliverycredit'),
  542. 'credit' => 5,
  543. 'percent' => '----',
  544. 'percent_class' => 'equal',
  545. 'percent_text' => lang('percent_text_equal'),
  546. ),
  547. );
  548. } else {
  549. $storeCredit = array();
  550. $percentClassTextMap = array(
  551. 'equal' => lang('percent_text_equal'),
  552. 'high' => lang('percent_text_high'),
  553. 'low' => lang('percent_text_low'),
  554. );
  555. foreach ((array) $store_info['store_credit'] as $k => $v) {
  556. isset($v['percent_class']) && $v['percent_text'] = $percentClassTextMap[$v['percent_class']];
  557. $storeCredit[$k] = $v;
  558. }
  559. $goods_detail['store_info']['store_credit'] = $storeCredit;
  560. }
  561. //商品详细信息处理
  562. $goods_detail = $this->_goods_detail_extend($goods_detail);
  563. $goods_common_info = $goods_model->getGoodsCommonInfoByID($goods_detail['goods_info']['goods_commonid']);
  564. $goods_detail['mb_body'] = array();
  565. if ($goods_common_info['mobile_body'] != '') {
  566. $goods_detail['mb_body'] = unserialize($goods_common_info['mobile_body']);
  567. }
  568. //如果没有砍价id就不显示砍价
  569. if (!$bargain_id) {
  570. $goods_detail['goods_info']['bargain_info'] = '';
  571. }
  572. // 如果已登录 判断该商品是否已被收藏&&添加浏览记录
  573. if ($member_id = $this->getMemberIdIfExists()) {
  574. $c = (int) model('favorites')->getGoodsFavoritesCountByGoodsId($goods_id, $member_id);
  575. $goods_detail['is_favorate'] = $c > 0;
  576. $seller_model = model('seller');
  577. $seller_info = $seller_model->getSellerInfo(array('member_id' => $member_id));
  578. //判断是否是店主本人
  579. if (empty($seller_info) || $store_info['store_id'] != $seller_info['store_id']) {
  580. model('goodsbrowse')->addViewedGoods($goods_id, $member_id);
  581. }
  582. //如果有砍价,看当前用户是否已发起过砍价
  583. if ($goods_detail['goods_info']['bargain_info'] != '') {
  584. $pbargainorder_model = model('pbargainorder');
  585. //是否有正在进行的砍价
  586. $bargainorder_info = $pbargainorder_model->getOnePbargainorder(array('bargainorder_initiator_id' => $member_id, 'bargain_id' => $goods_detail['goods_info']['bargain_info']['bargain_id']));
  587. if ($bargainorder_info) {
  588. if (!$bargainorder_info['order_id']) {
  589. $goods_detail['goods_info']['bargainorder_info'] = $bargainorder_info;
  590. } else {//砍价成功就不能再下单了
  591. $goods_detail['goods_info']['bargain_info'] = '';
  592. }
  593. }
  594. }
  595. if (isset($goods_detail['goods_info']['pintuan_type']) && $goods_detail['goods_info']['pintuan_type']) {
  596. //不可以重复参加
  597. $order_id_list = Db::name('ppintuanorder')->where(array(array('pintuan_id' ,'=', $goods_detail['goods_info']['pintuan_id']), array('pintuanorder_state','<>', 0)))->column('order_id');
  598. if ($order_id_list) {
  599. if (!$goods_detail['goods_info']['is_virtual']) {
  600. if ($order_id=Db::name('order')->where(array(array('buyer_id', '=', $member_id), array('order_id', 'in', $order_id_list)))->value('order_id')) {
  601. $condition=array();
  602. $condition[]=array('pintuan_id' ,'=', $goods_detail['goods_info']['pintuan_id']);
  603. $condition[]=array('order_id' ,'=', $order_id);
  604. $condition[]=array('pintuanorder_state','<>', 0);
  605. $goods_detail['goods_info']['pintuanorder_state']=Db::name('ppintuanorder')->where($condition)->value('pintuanorder_state');
  606. }
  607. } else {
  608. if ($order_id=Db::name('vrorder')->where(array(array('buyer_id', '=', $member_id), array('order_id', 'in', $order_id_list)))->value('order_id')) {
  609. $condition=array();
  610. $condition[]=array('pintuan_id' ,'=', $goods_detail['goods_info']['pintuan_id']);
  611. $condition[]=array('order_id' ,'=', $order_id);
  612. $condition[]=array('pintuanorder_state','<>', 0);
  613. $goods_detail['goods_info']['pintuanorder_state']=Db::name('ppintuanorder')->where($condition)->value('pintuanorder_state');
  614. }
  615. }
  616. }
  617. }
  618. }
  619. // 店铺优惠券
  620. $condition = array();
  621. $condition[] = array('vouchertemplate_if_private', '=', 0);
  622. $condition[] = array('vouchertemplate_state', '=', 1);
  623. $condition[] = array('vouchertemplate_enddate', '>', TIMESTAMP);
  624. $condition[] = array('vouchertemplate_store_id', '=', $store_info['store_id']);
  625. $voucher_template = model('voucher')->getVouchertemplateList($condition);
  626. if (!empty($voucher_template)) {
  627. foreach ($voucher_template as $val) {
  628. $param = array();
  629. $param['vouchertemplate_id'] = $val['vouchertemplate_id'];
  630. $param['vouchertemplate_price'] = $val['vouchertemplate_price'];
  631. $param['vouchertemplate_points'] = $val['vouchertemplate_points'];
  632. $param['vouchertemplate_limit'] = $val['vouchertemplate_limit'];
  633. $param['vouchertemplate_enddate'] = $val['vouchertemplate_enddate'];
  634. $goods_detail['voucher'][] = $param;
  635. }
  636. }
  637. // 评价列表
  638. $goods_eval_list = model('evaluategoods')->getEvaluategoodsList(array('geval_goodsid' => $goods_id), '3');
  639. //$goods_eval_list = model('memberevaluate','logic')->evaluateListDity($goods_eval_list);
  640. $goods_detail['goods_eval_list'] = $goods_eval_list;
  641. //评价信息
  642. $goods_evaluate_info = model('evaluategoods')->getEvaluategoodsInfoByGoodsID($goods_id);
  643. $goods_detail['goods_evaluate_info'] = $goods_evaluate_info;
  644. $goods_detail['goods_hair_info'] = $this->_calc(0, $goods_id);
  645. $goods_detail['goods_info']['pintuangroup_share_id'] = intval(input('param.pintuangroup_share_id')); #获取分享拼团的用户ID
  646. $inviter_model = model('inviter');
  647. $goods_detail['inviter_money'] = 0;
  648. if (config('ds_config.inviter_show') && config('ds_config.inviter_open') && $goods_detail['goods_info']['inviter_open'] && $member_id && $inviter_model->getInviterInfo('i.inviter_id=' . $member_id . ' AND i.inviter_state=1')) {
  649. $inviter_money = round($goods_detail['goods_info']['inviter_ratio'] / 100 * $goods_detail['goods_info']['goods_price'] * floatval(config('ds_config.inviter_ratio_1')) / 100, 2);
  650. if ($inviter_money > 0) {
  651. $goods_detail['goods_info']['inviter_money'] = $inviter_money;
  652. }
  653. }
  654. if (empty($goods_detail['mansong_info'])) {
  655. $goods_detail['mansong_info'] = false;
  656. }
  657. // 咨询类型
  658. $consult_type = rkcache('consulttype', true);
  659. $goods_detail['consult_type'] = $consult_type;
  660. $storeplate_model = model('storeplate');
  661. // 顶部关联版式
  662. if ($goods_detail['goods_info']['plateid_top'] > 0) {
  663. $plate_top = $storeplate_model->getStoreplateInfoByID($goods_detail['goods_info']['plateid_top']);
  664. if ($plate_top) {
  665. $plate_top['storeplate_content'] = htmlspecialchars_decode($plate_top['storeplate_content']);
  666. }
  667. $goods_detail['goods_info']['plate_top'] = $plate_top;
  668. }
  669. // 底部关联版式
  670. if ($goods_detail['goods_info']['plateid_bottom'] > 0) {
  671. $plate_bottom = $storeplate_model->getStoreplateInfoByID($goods_detail['goods_info']['plateid_bottom']);
  672. if ($plate_bottom) {
  673. $plate_bottom['storeplate_content'] = htmlspecialchars_decode($plate_bottom['storeplate_content']);
  674. }
  675. $goods_detail['goods_info']['plate_bottom'] = $plate_bottom;
  676. }
  677. $cache_key='goods-live-'.$store_info['store_id'].'-'.date('H');
  678. $result = rcache($cache_key);
  679. if (empty($result)) {
  680. //获取店铺一小时内正在进行的直播
  681. $live_apply_model=model('live_apply');
  682. $condition=array();
  683. $condition[]=array('live_apply_state','=',1);
  684. $condition[]=array('live_apply_play_time','<',strtotime(date('Y-m-d H:0:0'))+3600);
  685. $condition[]=array('live_apply_end_time','>',TIMESTAMP);
  686. $condition[]=array('live_apply_type','=',LIVE_APPLY_TYPE_GOODS);
  687. $condition[]=array('live_apply_user_type','=',2);
  688. $condition[]=array('live_apply_user_id','=',$store_info['store_id']);
  689. $live_apply_list=$live_apply_model->getLiveApplyList($condition,'*',0);
  690. foreach($live_apply_list as $key => $val){
  691. $live_apply_list[$key]['goods_commonid_array']=Db::name('live_apply_goods')->where(array(array('live_apply_id','=',$val['live_apply_id'])))->column('goods_commonid');
  692. }
  693. $minute=60-intval(date('i'));
  694. $result=array('live_apply_list'=>$live_apply_list);
  695. wcache($cache_key, $result, $minute*60);
  696. }
  697. $live_apply_list=$result['live_apply_list'];
  698. foreach($live_apply_list as $val){
  699. if($val['live_apply_play_time']<TIMESTAMP && $val['live_apply_end_time']>TIMESTAMP){
  700. if(in_array($goods_detail['goods_info']['goods_commonid'],$val['goods_commonid_array'])){
  701. $goods_detail['goods_info']['live_apply_info']=$val;
  702. break;
  703. }
  704. }
  705. }
  706. $goods_detail['goods_info']['goodsvideo_url'] = goods_video($goods_detail['goods_info']['goodsvideo_name']);
  707. $chain_model=model('chain');
  708. $chain_ids=Db::name('chain_goods')->where(array(array('goods_id','=',$goods_id),array('goods_storage','>',0)))->column('chain_id');
  709. $chain_info=$chain_model->getChainOpenInfo(array(array('chain_if_pickup','=',1),array('chain_id','in',$chain_ids)));
  710. $goods_detail['goods_info']['if_chain']=$chain_info?1:0;
  711. if($goods_common_info['store_service_ids']){
  712. $store_service_model=model('store_service');
  713. $condition=array();
  714. $condition[]=array('store_id','=',$store_info['store_id']);
  715. $condition[]=array('store_service_id','in',explode(',',$goods_common_info['store_service_ids']));
  716. $goods_detail['goods_info']['store_service_list']=$store_service_model->getStoreServiceList($condition,'*',0);
  717. }
  718. ds_json_encode(10000, '', $goods_detail);
  719. }
  720. /**
  721. * @api {POST} api/Goods/consulting_list 产品咨询列表
  722. * @apiVersion 1.0.0
  723. * @apiGroup Goods
  724. *
  725. * @apiParam {Int} goods_id 商品ID
  726. * @apiParam {Int} page 页码
  727. * @apiParam {Int} per_page 每页显示数量
  728. *
  729. * @apiSuccess {String} code 返回码,10000为成功
  730. * @apiSuccess {String} message 返回消息
  731. * @apiSuccess {Object} result 返回数据
  732. * @apiSuccess {Object[]} result.consult_list 产品咨询列表
  733. * @apiSuccess {Int} result.consult_list.consult_id 产品咨询ID
  734. * @apiSuccess {Int} result.consult_list.goods_id 商品ID
  735. * @apiSuccess {String} result.consult_list.goods_name 商品名称
  736. * @apiSuccess {Int} result.consult_list.member_id 用户ID
  737. * @apiSuccess {String} result.consult_list.member_name 用户名称
  738. * @apiSuccess {Int} result.consult_list.store_id 店铺ID
  739. * @apiSuccess {String} result.consult_list.store_name 店铺名称
  740. * @apiSuccess {Int} result.consult_list.consulttype_id 咨询类型ID
  741. * @apiSuccess {String} result.consult_list.consult_content 咨询内容
  742. * @apiSuccess {Int} result.consult_list.consult_addtime 咨询时间,Unix时间戳
  743. * @apiSuccess {String} result.consult_list.consult_reply 回复内容
  744. * @apiSuccess {Int} result.consult_list.consult_replytime 回复时间,Unix时间戳
  745. * @apiSuccess {Int} result.consult_list.consult_isanonymous 是否匿名
  746. * @apiSuccess {Int} result.page_total 总页数
  747. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  748. */
  749. public function consulting_list() {
  750. $goods_id = intval(input('param.goods_id'));
  751. if ($goods_id <= 0) {
  752. ds_json_encode(10001, lang('param_error'));
  753. }
  754. //得到商品咨询信息
  755. $consult_model = model('consult');
  756. $condition = array();
  757. $condition[] = array('goods_id','=',$goods_id);
  758. if (intval(input('param.ctid')) > 0) {
  759. $condition[] = array('consulttype_id','=',intval(input('param.ctid')));
  760. }
  761. $consult_list = $consult_model->getConsultList($condition, '*');
  762. $result = array_merge(array('consult_list' => $consult_list), mobile_page($consult_model->page_info));
  763. ds_json_encode(10000, '', $result);
  764. }
  765. /**
  766. * @api {POST} api/Goods/save_consult 商品咨询添加
  767. * @apiVersion 1.0.0
  768. * @apiGroup Goods
  769. *
  770. * @apiParam {Int} goods_id 商品ID
  771. * @apiParam {String} goods_content 咨询内容
  772. * @apiParam {Int} consult_type_id 咨询类型ID
  773. * @apiParam {String} key 用户授权token
  774. *
  775. * @apiSuccess {String} code 返回码,10000为成功
  776. * @apiSuccess {String} message 返回消息
  777. */
  778. public function save_consult() {
  779. $member_id = $this->getMemberIdIfExists();
  780. //检查是否可以评论
  781. if (!config('ds_config.guest_comment') && !$member_id) {
  782. ds_json_encode(10001, lang('goods_index_goods_noallow'));
  783. }
  784. $goods_id = intval(input('post.goods_id'));
  785. if ($goods_id <= 0) {
  786. ds_json_encode(10001, lang('param_error'));
  787. }
  788. //咨询内容的非空验证
  789. if (trim(input('post.goods_content')) == "") {
  790. ds_json_encode(10001, lang('goods_index_input_consult'));
  791. }
  792. //表单验证
  793. $data = [
  794. 'goods_content' => input('post.goods_content')
  795. ];
  796. $res=word_filter($data['goods_content']);
  797. if(!$res['code']){
  798. ds_json_encode(10001,$res['msg']);
  799. }
  800. $data['goods_content']=$res['data']['text'];
  801. $goods_validate = ds_validate('goods');
  802. if (!$goods_validate->scene('save_consult')->check($data)) {
  803. ds_json_encode(10001, $goods_validate->getError());
  804. }
  805. //判断商品编号的存在性和合法性
  806. $goods = model('goods');
  807. $goods_info = $goods->getGoodsInfoByID($goods_id);
  808. if (empty($goods_info)) {
  809. ds_json_encode(10001, lang('goods_index_goods_not_exists'));
  810. }
  811. if ($member_id) {
  812. //查询会员信息
  813. $member_model = model('member');
  814. $member_info = $member_model->getMemberInfo(array('member_id' => $member_id));
  815. if (empty($member_info) || $member_info['is_allowtalk'] == 0) {
  816. ds_json_encode(10001, lang('goods_index_goods_noallow'));
  817. }
  818. $seller_model = model('seller');
  819. $seller_info = $seller_model->getSellerInfo(array('member_id' => $member_id));
  820. //判断是否是店主本人
  821. if ($seller_info && $goods_info['store_id'] == $seller_info['store_id']) {
  822. ds_json_encode(10001, lang('goods_index_consult_store_error'));
  823. }
  824. }
  825. //检查店铺状态
  826. $store_model = model('store');
  827. $store_info = $store_model->getStoreInfoByID($goods_info['store_id']);
  828. if ($store_info['store_state'] == '0' || intval($store_info['store_state']) == '2' || (intval($store_info['store_endtime']) != 0 && $store_info['store_endtime'] <= TIMESTAMP)) {
  829. ds_json_encode(10001, lang('goods_index_goods_store_closed'));
  830. }
  831. //接收数据并保存
  832. $input = array();
  833. $input['goods_id'] = $goods_id;
  834. $input['goods_name'] = $goods_info['goods_name'];
  835. $input['member_id'] = intval($member_id) > 0 ? $member_id : 0;
  836. $input['member_name'] = isset($member_info) ? $member_info['member_name'] : '';
  837. $input['store_id'] = $store_info['store_id'];
  838. $input['store_name'] = $store_info['store_name'];
  839. $input['consulttype_id'] = intval(input('post.consult_type_id', 1));
  840. $input['consult_addtime'] = TIMESTAMP;
  841. $input['consult_content'] = $data['goods_content'];
  842. $input['consult_isanonymous'] = input('post.hide_name') == 'hide' ? 1 : 0;
  843. $consult_model = model('consult');
  844. if ($consult_model->addConsult($input)) {
  845. ds_json_encode(10000, lang('goods_index_consult_success'));
  846. } else {
  847. ds_json_encode(10001, lang('goods_index_consult_fail'));
  848. }
  849. }
  850. /**
  851. * 记录浏览历史
  852. */
  853. public function addbrowse() {
  854. $goods_id = intval(input('param.gid'));
  855. model('goodsbrowse')->addViewedGoods($goods_id, $this->member_info['member_id'], $this->store_info['store_id']);
  856. exit();
  857. }
  858. /**
  859. * 商品详细信息处理
  860. */
  861. private function _goods_detail_extend($goods_detail) {
  862. //整理商品规格
  863. $goods_detail['spec_detail'] = json_decode($goods_detail['spec_list'],true);
  864. unset($goods_detail['spec_list']);
  865. $goods_detail['spec_list'] = $goods_detail['spec_list_mobile'];
  866. unset($goods_detail['spec_list_mobile']);
  867. //整理商品图片
  868. unset($goods_detail['goods_image']);
  869. $goods_detail['goods_image'] = $goods_detail['goods_image_mobile'];
  870. unset($goods_detail['goods_image_mobile']);
  871. //商品PC端详情信息
  872. $goods_detail['goods_info']['goods_body'] = htmlspecialchars_decode($goods_detail['goods_info']['goods_body']);
  873. //整理数据
  874. // unset($goods_detail['goods_info']['goods_commonid']);
  875. unset($goods_detail['goods_info']['gc_id']);
  876. unset($goods_detail['goods_info']['gc_name']);
  877. unset($goods_detail['goods_info']['store_id']);
  878. unset($goods_detail['goods_info']['store_name']);
  879. unset($goods_detail['goods_info']['brand_id']);
  880. unset($goods_detail['goods_info']['brand_name']);
  881. unset($goods_detail['goods_info']['type_id']);
  882. unset($goods_detail['goods_info']['goods_image']);
  883. unset($goods_detail['goods_info']['goods_stateremark']);
  884. unset($goods_detail['goods_info']['goods_verifyremark']);
  885. unset($goods_detail['goods_info']['goods_lock']);
  886. unset($goods_detail['goods_info']['goods_addtime']);
  887. unset($goods_detail['goods_info']['goods_edittime']);
  888. unset($goods_detail['goods_info']['goods_shelftime']);
  889. unset($goods_detail['goods_info']['goods_show']);
  890. unset($goods_detail['goods_info']['goods_commend']);
  891. unset($goods_detail['goods_info']['explain']);
  892. unset($goods_detail['goods_info']['buynow_text']);
  893. unset($goods_detail['groupbuy_info']);
  894. unset($goods_detail['xianshi_info']);
  895. return $goods_detail;
  896. }
  897. /**
  898. * @api {POST} api/Goods/goods_evaluate 商品评论
  899. * @apiVersion 1.0.0
  900. * @apiGroup Goods
  901. *
  902. * @apiParam {Int} goods_id 商品ID
  903. * @apiParam {Int} type 类型 1好评 2中评 3差评
  904. * @apiParam {Int} page 页码
  905. * @apiParam {Int} per_page 每页显示数量
  906. *
  907. * @apiSuccess {String} code 返回码,10000为成功
  908. * @apiSuccess {String} message 返回消息
  909. * @apiSuccess {Object} result 返回数据
  910. * @apiSuccess {Object[]} result.goods_eval_list 评论列表
  911. * @apiSuccess {Int} result.goods_eval_list.geval_addtime 评论时间
  912. * @apiSuccess {Int} result.goods_eval_list.geval_content 评论内容
  913. * @apiSuccess {Int} result.goods_eval_list.geval_explain 店主解释
  914. * @apiSuccess {Int} result.goods_eval_list.geval_frommemberid 评论用户ID
  915. * @apiSuccess {Int} result.goods_eval_list.geval_frommembername 评论用户名
  916. * @apiSuccess {Int} result.goods_eval_list.geval_goodsid 评论商品ID
  917. * @apiSuccess {Int} result.goods_eval_list.geval_goodsimage 评论商品图片
  918. * @apiSuccess {Int} result.goods_eval_list.geval_goodsname 评论商品名称
  919. * @apiSuccess {Int} result.goods_eval_list.geval_goodsprice 评论价格
  920. * @apiSuccess {Int} result.goods_eval_list.geval_id 评论ID
  921. * @apiSuccess {Int} result.goods_eval_list.geval_image 评论晒图
  922. * @apiSuccess {Int} result.goods_eval_list.geval_isanonymous 是否匿名
  923. * @apiSuccess {Int} result.goods_eval_list.geval_ordergoodsid 订单商品ID
  924. * @apiSuccess {Int} result.goods_eval_list.geval_orderid 订单ID
  925. * @apiSuccess {Int} result.goods_eval_list.geval_orderno 订单编号
  926. * @apiSuccess {Int} result.goods_eval_list.geval_remark 管理员对评价的处理备注
  927. * @apiSuccess {Int} result.goods_eval_list.geval_scores 评分
  928. * @apiSuccess {Int} result.goods_eval_list.geval_state 评价信息的状态 0为正常 1为禁止显示
  929. * @apiSuccess {Int} result.goods_eval_list.geval_storeid 店铺ID
  930. * @apiSuccess {Int} result.goods_eval_list.geval_storename 店铺名称
  931. * @apiSuccess {Int} result.goods_eval_list.member_avatar 用户头像
  932. * @apiSuccess {Int} result.page_total 总页数
  933. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  934. */
  935. public function goods_evaluate() {
  936. $goods_id = intval(input('param.goods_id'));
  937. $type = intval(input('param.type'));
  938. $condition = array();
  939. $condition[] = array('geval_goodsid', '=', $goods_id);
  940. switch ($type) {
  941. case '1':
  942. $condition[] = array('geval_scores', 'in', '5,4');
  943. break;
  944. case '2':
  945. $condition[] = array('geval_scores', 'in', '3,2');
  946. break;
  947. case '3':
  948. $condition[] = array('geval_scores', 'in', '1');
  949. break;
  950. case '4':
  951. //$condition[] = array('geval_image|geval_image_again','<>', ''); //追加评价带后续处理
  952. $condition[] = array('geval_image', '<>', '');
  953. break;
  954. case '5':
  955. $condition[] = array('geval_content_again', '<>', '');
  956. break;
  957. }
  958. //查询商品评分信息
  959. $evaluategoods_model = model('evaluategoods');
  960. $goods_eval_list = $evaluategoods_model->getEvaluategoodsList($condition, $this->pagesize);
  961. foreach ($goods_eval_list as $k => $val) {
  962. if ($val['geval_isanonymous']) {
  963. $goods_eval_list[$k]['member_avatar'] = get_member_avatar_for_id(0);
  964. $goods_eval_list[$k]['geval_frommembername'] = str_cut($val['geval_frommembername'], 2) . '***';
  965. }
  966. if (!empty($goods_eval_list[$k]['geval_image'])) {
  967. $goods_eval_list[$k]['geval_image'] = explode(',', $goods_eval_list[$k]['geval_image']);
  968. foreach ($goods_eval_list[$k]['geval_image'] as $kk => $vv) {
  969. $store_id = substr($vv, 0, strpos($vv, '_'));
  970. $goods_eval_list[$k]['geval_image'][$kk] = ds_get_pic(ATTACH_MALBUM . '/' . $store_id , $vv);
  971. }
  972. }
  973. }
  974. $goods_eval_list = model('memberevaluate', 'logic')->evaluateListDity($goods_eval_list);
  975. $result = array_merge(array('goods_eval_list' => $goods_eval_list), mobile_page(is_object($evaluategoods_model->page_info) ? $evaluategoods_model->page_info : 0));
  976. ds_json_encode(10000, '', $result);
  977. }
  978. /**
  979. * 商品详细页运费显示
  980. *
  981. * @return unknown
  982. */
  983. public function calc() {
  984. $area_id = intval(input('param.area_id'));
  985. $goods_id = intval(input('param.goods_id'));
  986. ds_json_encode(10000, '', $this->_calc($area_id, $goods_id));
  987. }
  988. public function _calc($area_id, $goods_id) {
  989. $goods_info = model('goods')->getGoodsInfo(array('goods_id' => $goods_id), 'transport_id,store_id,goods_freight');
  990. $store_info = model('store')->getStoreInfoByID($goods_info['store_id']);
  991. $if_store = true;
  992. $area_name = '';
  993. if ($area_id <= 0) {
  994. if (strpos($store_info['deliver_region'], '|')) {
  995. $store_info['deliver_region'] = explode('|', $store_info['deliver_region']);
  996. $store_info['deliver_region_ids'] = explode(' ', $store_info['deliver_region'][0]);
  997. }
  998. if (isset($store_info['deliver_region_ids'])) {
  999. $area_id = intval($store_info['deliver_region_ids'][0]);
  1000. $area_name = $store_info['deliver_region'][1];
  1001. }
  1002. }
  1003. if ($goods_info['transport_id']) {
  1004. $freight_total = model('transport')->calcTransport(intval($goods_info['transport_id']), $area_id);
  1005. if ($freight_total > 0) {
  1006. if ($store_info['store_free_price'] > 0) {
  1007. if ($freight_total >= $store_info['store_free_price']) {
  1008. $freight_total = lang('free_shipping');
  1009. } else {
  1010. $freight_total = lang('freight') . ':' . $freight_total . lang('shop_with') . $store_info['store_free_price'] . lang('goods_index_yuan') . lang('free_shipping');
  1011. }
  1012. } else {
  1013. $freight_total = lang('freight') . ':' . $freight_total . lang('goods_index_yuan');
  1014. }
  1015. } else {
  1016. if ($freight_total === false) {
  1017. $if_store = false;
  1018. }
  1019. $freight_total = lang('free_shipping');
  1020. }
  1021. } else {
  1022. $freight_total = $goods_info['goods_freight'] > 0 ? lang('freight') . ':' . $goods_info['goods_freight'] . lang('goods_index_yuan') : lang('free_shipping');
  1023. }
  1024. return array('content' => $freight_total, 'if_store_cn' => $if_store === false ? lang('goods_out_stock') : lang('goods_stock'), 'if_store' => $if_store === false ? false : true, 'area_name' => $area_name ? $area_name : lang('goods_index_trans_country'));
  1025. }
  1026. /**
  1027. * 经纬度转换
  1028. * @param unknown $bdLat
  1029. * @param unknown $bdLon
  1030. * @return multitype:number
  1031. */
  1032. public function bd_decrypt($bdLat, $bdLon) {
  1033. $x = $bdLon - 0.0065;
  1034. $y = $bdLat - 0.006;
  1035. $z = sqrt($x * $x + $y * $y) - 0.00002 * sin($y * $this->x_pi);
  1036. $theta = atan2($y, $x) - 0.000003 * cos($x * $this->x_pi);
  1037. $gcjLon = $z * cos($theta);
  1038. $gcjLat = $z * sin($theta);
  1039. return array('lat' => $gcjLat, 'lon' => $gcjLon);
  1040. }
  1041. /**
  1042. * @desc 根据两点间的经纬度计算距离
  1043. * @param float $lat 纬度值
  1044. * @param float $lng 经度值
  1045. */
  1046. private function getDistance($lat1, $lng1, $lat2, $lng2) {
  1047. $earthRadius = 6367000; //approximate radius of earth in meters
  1048. /*
  1049. Convert these degrees to radians
  1050. to work with the formula
  1051. */
  1052. $lat1 = ($lat1 * pi() ) / 180;
  1053. $lng1 = ($lng1 * pi() ) / 180;
  1054. $lat2 = ($lat2 * pi() ) / 180;
  1055. $lng2 = ($lng2 * pi() ) / 180;
  1056. /*
  1057. Using the
  1058. Haversine formula
  1059. http://en.wikipedia.org/wiki/Haversine_formula
  1060. calculate the distance
  1061. */
  1062. $calcLongitude = $lng2 - $lng1;
  1063. $calcLatitude = $lat2 - $lat1;
  1064. $stepOne = pow(sin($calcLatitude / 2), 2) + cos($lat1) * cos($lat2) * pow(sin($calcLongitude / 2), 2);
  1065. $stepTwo = 2 * asin(min(1, sqrt($stepOne)));
  1066. $calculatedDistance = $earthRadius * $stepTwo;
  1067. return round($calculatedDistance);
  1068. }
  1069. private function parseDistance($num = 0) {
  1070. $num = floatval($num);
  1071. if ($num >= 1000) {
  1072. $num = $num / 1000;
  1073. return str_replace('.0', '', number_format($num, 1, '.', '')) . 'km';
  1074. } else {
  1075. return $num . 'm';
  1076. }
  1077. }
  1078. /**
  1079. * 获取自提点
  1080. */
  1081. public function chain_list(){
  1082. $area_id=input('param.area_id');
  1083. $goods_id=input('param.goods_id');
  1084. $num=input('param.num');
  1085. if(!$num){
  1086. !$num=1;
  1087. }
  1088. $chain_model=model('chain');
  1089. $chain_ids=Db::name('chain_goods')->where(array(array('goods_id','=',$goods_id),array('goods_storage','>=',$num)))->column('chain_id');
  1090. $condition=array();
  1091. $condition[]=array('chain_if_pickup','=',1);
  1092. $condition[]=array('chain_id','in',$chain_ids);
  1093. if($area_id){
  1094. $condition[]=array('chain_area_2|chain_area_3','=',$area_id);
  1095. }
  1096. $chain_list=$chain_model->getChainOpenList($condition);
  1097. $chain_list=array_values($chain_list);
  1098. return ds_json_encode(10000, '',array('chain_list'=>$chain_list));
  1099. }
  1100. }