Goods.php 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\Db;
  4. use think\facade\Lang;
  5. /**
  6. * 商品控制器
  7. */
  8. class Goods extends MobileMall
  9. {
  10. private $PI = 3.14159265358979324;
  11. private $x_pi = 0;
  12. public function initialize()
  13. {
  14. parent::initialize();
  15. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/goods.lang.php');
  16. $this->x_pi = 3.14159265358979324 * 3000.0 / 180.0;
  17. }
  18. /**
  19. * @api {POST} api/Goods/goods_list 商品列表
  20. * @apiVersion 1.0.0
  21. * @apiGroup Goods
  22. *
  23. * @apiParam {Int} cate_id 分类ID
  24. * @apiParam {String} keyword 关键词
  25. * @apiParam {String} b_id 品牌id
  26. * @apiParam {Float} price_from 价格从
  27. * @apiParam {Float} price_to 价格到
  28. * @apiParam {Int} sort_key 排序键 goods_salenum销量 goods_click浏览量 goods_price价格
  29. * @apiParam {Int} sort_order 排序值 1升序 2降序
  30. * @apiParam {Int} gift 是否有赠品 1有
  31. * @apiParam {Int} own_shop 自营 1是
  32. * @apiParam {Int} area_id 地区id
  33. * @apiParam {Int} xianshi 是否秒杀 1是
  34. * @apiParam {Int} page 页码
  35. * @apiParam {Int} per_page 每页显示数量
  36. *
  37. * @apiSuccess {String} code 返回码,10000为成功
  38. * @apiSuccess {String} message 返回消息
  39. * @apiSuccess {Object} result 返回数据
  40. * @apiSuccess {Object[]} result.goods_list 商品列表
  41. * @apiSuccess {Int} result.goods_list.evaluation_count 评论数
  42. * @apiSuccess {Float} result.goods_list.evaluation_good_star 评分
  43. * @apiSuccess {String} result.goods_list.goods_advword 广告词
  44. * @apiSuccess {Int} result.goods_list.goods_id 商品ID
  45. * @apiSuccess {String} result.goods_list.goods_image 商品图片名称
  46. * @apiSuccess {String} result.goods_list.goods_image_url 商品图片完整路径
  47. * @apiSuccess {Float} result.goods_list.goods_marketprice 商品市场价
  48. * @apiSuccess {String} result.goods_list.goods_name 商品名称
  49. * @apiSuccess {Float} result.goods_list.goods_price 商品价格
  50. * @apiSuccess {Float} result.goods_list.goods_promotion_price 商品促销价
  51. * @apiSuccess {String} result.goods_list.goods_promotion_type 促销类型
  52. * @apiSuccess {Int} result.goods_list.goods_salenum 商品销售量
  53. * @apiSuccess {Boolean} result.goods_list.group_flag 是否抢购 true是false否
  54. * @apiSuccess {Int} result.goods_list.is_goodsfcode 是否F码 1是0否
  55. * @apiSuccess {Int} result.goods_list.is_have_gift 是否含赠品 1是0否
  56. * @apiSuccess {Int} result.goods_list.is_platform_store 是否平台自营 1是0否
  57. * @apiSuccess {Int} result.goods_list.is_virtual 是否虚拟商品 1是0否
  58. * @apiSuccess {Int} result.goods_list.store_id 店铺ID
  59. * @apiSuccess {String} result.goods_list.store_name 店铺名称
  60. * @apiSuccess {Boolean} result.goods_list.xianshi_flag 是否秒杀 true是false否
  61. * @apiSuccess {Int} result.page_total 总页数
  62. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  63. */
  64. public function goods_list()
  65. {
  66. $goods_model = model('goods');
  67. $search_model = model('search');
  68. //查询条件
  69. $condition = array();
  70. $cate_id = intval(input('param.cate_id'));
  71. $keyword = $default_classid = input('param.keyword');
  72. $b_id = intval(input('param.b_id'));
  73. //获得经过属性过滤的商品信息
  74. $this->_model_search = model('search');
  75. list($goods_param, $brand_array, $initial_array, $attr_array, $checked_brand, $checked_attr) = $this->_model_search->getAttribute(input('param.'), $default_classid);
  76. if (isset($goods_param['class']['depth'])) {
  77. $condition[] = array('goodscommon.gc_id_' . $goods_param['class']['depth'], '=', $goods_param['class']['gc_id']);
  78. }
  79. if (isset($goods_param['goodsid_array'])) {
  80. $condition[] = array('goods.goods_id', 'in', $goods_param['goodsid_array']);
  81. }
  82. if ($cate_id > 0) {
  83. $condition = model('goods')->_getRecursiveClass($condition, $cate_id, 'goodscommon');
  84. }
  85. if (!empty($keyword)) {
  86. $condition[] = array('goodscommon.goods_name|goodscommon.goods_advword', 'like', '%' . $keyword . '%');
  87. if (cookie('hisSearch') == '') {
  88. $his_sh_list = array();
  89. } else {
  90. $his_sh_list = explode('~', cookie('hisSearch'));
  91. }
  92. if (strlen($keyword) <= 20 && !in_array($keyword, $his_sh_list)) {
  93. if (array_unshift($his_sh_list, $keyword) > 8) {
  94. array_pop($his_sh_list);
  95. }
  96. }
  97. cookie('hisSearch', implode('~', $his_sh_list), 2592000);
  98. }
  99. if ($b_id > 0) {
  100. $condition[] = array('goodscommon.brand_id', '=', $b_id);
  101. }
  102. $price_from = input('param.price_from');
  103. $price_to = input('param.price_to');
  104. $price_from = preg_match('/^[\d.]{1,20}$/', $price_from) ? $price_from : null;
  105. $price_to = preg_match('/^[\d.]{1,20}$/', $price_to) ? $price_to : null;
  106. //所需字段
  107. $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";
  108. $fieldstr .= ',goodscommon.is_virtual,goodscommon.is_goodsfcode,goods.is_have_gift,goodscommon.store_name,goodscommon.is_platform_store';
  109. //排序方式
  110. $order = $this->_goods_list_order(input('param.sort_key'), input('param.sort_order'));
  111. if ($price_from && $price_to) {
  112. $condition[] = array('goods.goods_promotion_price', 'between', "{$price_from},{$price_to}");
  113. } elseif ($price_from) {
  114. $condition[] = array('goods.goods_promotion_price', '>=', $price_from);
  115. } elseif ($price_to) {
  116. $condition[] = array('goods.goods_promotion_price', '<=', $price_to);
  117. }
  118. if (input('param.gift') == 1) {
  119. $condition[] = array('goods.is_have_gift', '=', 1);
  120. }
  121. if (input('param.own_shop') == 1) {
  122. $condition[] = array('goodscommon.store_id', '=', 1);
  123. }
  124. if (intval(input('param.area_id')) > 0) {
  125. $condition[] = array('goodscommon.areaid_1', '=', intval(input('param.area_id')));
  126. }
  127. //抢购和秒杀搜索
  128. $_tmp = array();
  129. if (input('param.groupbuy') == 1) {
  130. $_tmp[] = 1;
  131. }
  132. if (input('param.xianshi') == 1) {
  133. $_tmp[] = 2;
  134. if (input('param.goods_price') == 'goods_price') {
  135. $order = 'goods_promotion_price';
  136. if (input('param.sort_order') == 'asc') {
  137. $order .= ' asc';
  138. } else {
  139. $order .= ' desc';
  140. }
  141. }
  142. }
  143. if ($_tmp) {
  144. $condition[] = array('goods.goods_promotion_type', 'in', $_tmp);
  145. }
  146. unset($_tmp);
  147. //虚拟商品
  148. if (input('param.virtual') == 1) {
  149. $condition[] = array('goodscommon.is_virtual', '=', 1);
  150. }
  151. $goods_list = $goods_model->getGoodsUnionList($condition, $fieldstr, $order, 'goodscommon.goods_commonid', $this->pagesize);
  152. // }
  153. //处理商品列表(抢购、秒杀、商品图片)
  154. $goods_list = $this->_goods_list_extend($goods_list);
  155. $result = array_merge(array('goods_list' => $goods_list), mobile_page(is_object($goods_model->page_info) ? $goods_model->page_info : ''));
  156. ds_json_encode(10000, '', $result);
  157. }
  158. /**
  159. * @api {POST} api/Goods/get_attribute 获取分类下的属性
  160. * @apiVersion 1.0.0
  161. * @apiGroup Goods
  162. *
  163. * @apiParam {Int} cate_id 分类ID
  164. * @apiParam {String} a_id 已选择的属性
  165. * @apiParam {Int} b_id 已选择的品牌
  166. *
  167. * @apiSuccess {String} code 返回码,10000为成功
  168. * @apiSuccess {String} message 返回消息
  169. * @apiSuccess {Object} result 返回数据
  170. * @apiSuccess {Object} result.goods_param 商品数据集
  171. * @apiSuccess {Object} result.brand_array 品牌列表
  172. * @apiSuccess {Object} result.attr_array 属性列表
  173. * @apiSuccess {Object} result.checked_brand 已选择的品牌
  174. * @apiSuccess {Object} result.checked_attr 已选择的属性
  175. */
  176. public function get_attribute()
  177. {
  178. $this->_model_search = model('search');
  179. $default_classid = intval(input('param.cate_id'));
  180. //获得经过属性过滤的商品信息
  181. list($goods_param, $brand_array, $initial_array, $attr_array, $checked_brand, $checked_attr) = $this->_model_search->getAttribute(input('param.'), $default_classid);
  182. $result = array(
  183. 'goods_param' => $goods_param,
  184. 'brand_array' => $brand_array,
  185. 'initial_array' => $initial_array,
  186. 'attr_array' => $attr_array,
  187. 'checked_brand' => $checked_brand,
  188. 'checked_attr' => $checked_attr,
  189. );
  190. ds_json_encode(10000, '', $result);
  191. }
  192. /**
  193. * @api {POST} api/Goods/get_bundling 优惠套装
  194. * @apiVersion 1.0.0
  195. * @apiGroup Goods
  196. *
  197. * @apiParam {Int} goods_id 商品ID
  198. *
  199. * @apiSuccess {String} code 返回码,10000为成功
  200. * @apiSuccess {String} message 返回消息
  201. * @apiSuccess {Object} result 返回数据
  202. * @apiSuccess {Object} result.bundling_array 优惠套餐分类列表,键为分类ID
  203. * @apiSuccess {Float} result.bundling_array.freight 邮费
  204. * @apiSuccess {Int} result.bundling_array.id 优惠套餐分类ID
  205. * @apiSuccess {String} result.bundling_array.name 优惠套餐分类名称
  206. * @apiSuccess {Float} result.bundling_array.price 优惠套餐价
  207. * @apiSuccess {Float} result.bundling_array.storecost_price 原价
  208. * @apiSuccess {Object} result.b_goods_array 优惠套餐商品列表,键为分类ID
  209. * @apiSuccess {Int} result.b_goods_array.id 优惠套餐分类ID
  210. * @apiSuccess {String} result.b_goods_array.image 商品图片
  211. * @apiSuccess {String} result.b_goods_array.name 商品名称
  212. * @apiSuccess {Float} result.b_goods_array.price 优惠后价格
  213. * @apiSuccess {Float} result.b_goods_array.shop_price 原价
  214. */
  215. public function get_bundling()
  216. {
  217. $goods_id = intval(input('param.goods_id'));
  218. if ($goods_id <= 0) {
  219. ds_json_encode(10001, lang('param_error'));
  220. }
  221. // 优惠套装
  222. $array = model('pbundling')->getBundlingCacheByGoodsId($goods_id);
  223. if (!empty($array)) {
  224. $bundling_array = unserialize($array['bundling_array']);
  225. $b_goods_array = unserialize($array['b_goods_array']);
  226. ds_json_encode(10000, '', array('bundling_array' => !empty($bundling_array) ? $bundling_array : false, 'b_goods_array' => !empty($b_goods_array) ? $b_goods_array : false));
  227. } else {
  228. ds_json_encode(10001, lang('bundling_not_exist'));
  229. }
  230. }
  231. /**
  232. * 商品列表排序方式
  233. */
  234. private function _goods_list_order($sort_key, $sort_order)
  235. {
  236. $result = 'goodscommon.mall_goods_commend desc,goodscommon.mall_goods_sort asc';
  237. if (!empty($sort_key)) {
  238. $sequence = 'desc';
  239. if ($sort_order == 'asc') {
  240. $sequence = 'asc';
  241. }
  242. switch ($sort_key) {
  243. //销量
  244. case 'goods_salenum':
  245. $result = 'goods.goods_salenum' . ' ' . $sequence;
  246. break;
  247. //浏览量
  248. case 'goods_click':
  249. $result = 'goods.goods_click' . ' ' . $sequence;
  250. break;
  251. //价格
  252. case 'goods_price':
  253. $result = 'goodscommon.goods_price' . ' ' . $sequence;
  254. break;
  255. //新品
  256. case 'goods_addtime':
  257. $result = 'goodscommon.goods_addtime' . ' ' . $sequence;
  258. break;
  259. }
  260. }
  261. return $result;
  262. }
  263. private function _goods_list_extend($goods_list)
  264. {
  265. //获取商品列表编号数组
  266. $commonid_array = array();
  267. $goodsid_array = array();
  268. $goods_model = model('goods');
  269. foreach ($goods_list as $key => $value) {
  270. if (!$value['goods_storage']) {
  271. $goods_info = $goods_model->getGoodsStorageByCommonId($value['goods_commonid']);
  272. if ($goods_info) {
  273. $goods_list[$key]['goods_id'] = $value['goods_id'] = $goods_info['goods_id'];
  274. $goods_list[$key]['goods_promotion_price'] = $goods_info['goods_promotion_price'];
  275. }
  276. }
  277. $commonid_array[] = $value['goods_commonid'];
  278. $goodsid_array[] = $value['goods_id'];
  279. }
  280. //促销
  281. $store_model = model('store');
  282. $groupbuy_list = model('groupbuy')->getGroupbuyListByGoodsCommonIDString(implode(',', $commonid_array));
  283. $xianshi_list = model('pxianshigoods')->getXianshigoodsListByGoodsString(implode(',', $goodsid_array));
  284. foreach ($goods_list as $key => $value) {
  285. //抢购
  286. if (isset($groupbuy_list[$value['goods_commonid']])) {
  287. $goods_list[$key]['goods_price'] = $groupbuy_list[$value['goods_commonid']]['groupbuy_price'];
  288. $goods_list[$key]['group_flag'] = true;
  289. } else {
  290. $goods_list[$key]['group_flag'] = false;
  291. }
  292. //秒杀
  293. if (isset($xianshi_list[$value['goods_id']]) && !$goods_list[$key]['group_flag']) {
  294. $goods_list[$key]['goods_price'] = $xianshi_list[$value['goods_id']]['xianshigoods_price'];
  295. $goods_list[$key]['xianshi_flag'] = true;
  296. } else {
  297. $goods_list[$key]['xianshi_flag'] = false;
  298. }
  299. //商品图片url
  300. $goods_list[$key]['goods_image_url'] = goods_cthumb($value['goods_image'], 480, $value['store_id']);
  301. $store_info = $store_model->getStoreInfoByID($value['store_id']);
  302. $goods_list[$key]['store_name'] = $store_info['store_name'];
  303. unset($goods_list[$key]['goods_commonid']);
  304. unset($goods_list[$key]['nc_distinct']);
  305. }
  306. return $goods_list;
  307. }
  308. /**
  309. * @api {POST} api/Goods/goods_detail 商品详细页
  310. * @apiVersion 1.0.0
  311. * @apiGroup Goods
  312. *
  313. * @apiParam {Int} goods_id 商品ID
  314. *
  315. * @apiSuccess {String} code 返回码,10000为成功
  316. * @apiSuccess {String} message 返回消息
  317. * @apiSuccess {Object} result 返回数据
  318. * @apiSuccess {Object} result.consult_type 咨询类型列表,键为咨询类型ID
  319. * @apiSuccess {Int} result.consult_type.consulttype_id 咨询类型ID
  320. * @apiSuccess {Object} result.consult_type.consulttype_introduce 咨询介绍
  321. * @apiSuccess {Object} result.consult_type.consulttype_name 咨询类型标题
  322. * @apiSuccess {Int} result.consult_type.consulttype_sort 咨询类型排序
  323. * @apiSuccess {Object[]} result.gift_array 赠品列表
  324. * @apiSuccess {Int} result.gift_array.gift_id 赠品ID
  325. * @apiSuccess {Int} result.gift_array.gift_goodsid 赠品商品ID
  326. * @apiSuccess {Object} result.gift_array.gift_goodsname 主商品名称
  327. * @apiSuccess {Object} result.gift_array.gift_goodsimage 主商品图片名称
  328. * @apiSuccess {Object} result.gift_array.gift_goodsimage_url 主商品图片完整路径
  329. * @apiSuccess {Object} result.gift_array.gift_amount 赠品数量
  330. * @apiSuccess {Int} result.gift_array.goods_id 主商品ID
  331. * @apiSuccess {Int} result.gift_array.goods_commonid 主商品公共ID
  332. * @apiSuccess {Object[]} result.goods_commend_list 推荐商品列表
  333. * @apiSuccess {Int} result.goods_commend_list.goods_id 商品ID
  334. * @apiSuccess {Object} result.goods_commend_list.goods_image_url 商品图片
  335. * @apiSuccess {Object} result.goods_commend_list.goods_name 商品名称
  336. * @apiSuccess {Float} result.goods_commend_list.goods_price 商品价格
  337. * @apiSuccess {Float} result.goods_commend_list.goods_promotion_price 商品促销价
  338. * @apiSuccess {Object[]} result.goods_eval_list 商品评论列表
  339. * @apiSuccess {Int} result.goods_eval_list.geval_addtime 评论时间
  340. * @apiSuccess {String} result.goods_eval_list.geval_content 评论内容
  341. * @apiSuccess {String} result.goods_eval_list.geval_explain 店家解释
  342. * @apiSuccess {Int} result.goods_eval_list.geval_frommemberid 评论用户ID
  343. * @apiSuccess {String} result.goods_eval_list.geval_frommembername 评论用户名
  344. * @apiSuccess {Int} result.goods_eval_list.geval_goodsid 评论商品ID
  345. * @apiSuccess {String} result.goods_eval_list.geval_goodsimage 评论商品图片
  346. * @apiSuccess {String} result.goods_eval_list.geval_goodsname 评论商品名称
  347. * @apiSuccess {Float} result.goods_eval_list.geval_goodsprice 评论商品价格
  348. * @apiSuccess {Int} result.goods_eval_list.geval_id 评论ID
  349. * @apiSuccess {String} result.goods_eval_list.geval_image 评论图片
  350. * @apiSuccess {Int} result.goods_eval_list.geval_isanonymous 是否匿名 0:不是 1:匿名评价
  351. * @apiSuccess {Int} result.goods_eval_list.geval_ordergoodsid 订单商品ID
  352. * @apiSuccess {Int} result.goods_eval_list.geval_orderid 订单ID
  353. * @apiSuccess {String} result.goods_eval_list.geval_orderno 订单编号
  354. * @apiSuccess {String} result.goods_eval_list.geval_remark 管理员对评价的处理备注
  355. * @apiSuccess {Int} result.goods_eval_list.geval_scores 评分
  356. * @apiSuccess {Int} result.goods_eval_list.geval_state 评论状态 0为正常 1为禁止显示
  357. * @apiSuccess {Int} result.goods_eval_list.geval_storeid 商品店铺ID
  358. * @apiSuccess {String} result.goods_eval_list.geval_storename 商品店铺名称
  359. * @apiSuccess {Object} result.goods_evaluate_info 商品评论综合信息
  360. * @apiSuccess {Int} result.goods_evaluate_info.all 商品评论总数
  361. * @apiSuccess {Int} result.goods_evaluate_info.bad 差评数
  362. * @apiSuccess {Int} result.goods_evaluate_info.bad_percent 差评率
  363. * @apiSuccess {Int} result.goods_evaluate_info.good 好评数
  364. * @apiSuccess {Int} result.goods_evaluate_info.good_percent 好评率
  365. * @apiSuccess {Int} result.goods_evaluate_info.good_star 好评评分
  366. * @apiSuccess {Int} result.goods_evaluate_info.normal 中评数
  367. * @apiSuccess {Int} result.goods_evaluate_info.normal_percent 中评率
  368. * @apiSuccess {Int} result.goods_evaluate_info.star_average 平均评分
  369. * @apiSuccess {Object} result.goods_hair_info 商品运费信息
  370. * @apiSuccess {String} result.goods_hair_info.area_name 地区名称
  371. * @apiSuccess {String} result.goods_hair_info.content 运费描述
  372. * @apiSuccess {Boolean} result.goods_hair_info.if_store 是否有货 true是false否
  373. * @apiSuccess {String} result.goods_hair_info.if_store_cn 库存描述
  374. * @apiSuccess {String} result.goods_image 商品图片,用逗号分隔
  375. * @apiSuccess {Object} result.goods_info 商品信息
  376. * @apiSuccess {Int} result.goods_info.appoint_satedate 预约商品出售时间
  377. * @apiSuccess {Int} result.goods_info.areaid_1 一级地区id
  378. * @apiSuccess {Int} result.goods_info.areaid_2 二级地区id
  379. * @apiSuccess {Boolean} result.goods_info.cart 是否可以加入购物车
  380. * @apiSuccess {Int} result.goods_info.color_id 颜色规格值ID
  381. * @apiSuccess {Int} result.goods_info.evaluation_count 评论数
  382. * @apiSuccess {Int} result.goods_info.evaluation_good_star 好评评分
  383. * @apiSuccess {Int} result.goods_info.gc_id_1 一级分类ID
  384. * @apiSuccess {Int} result.goods_info.gc_id_2 二级分类ID
  385. * @apiSuccess {Int} result.goods_info.gc_id_3 三级分类ID
  386. * @apiSuccess {String} result.goods_info.goods_advword 广告词
  387. * @apiSuccess {String} result.goods_info.goods_attr 商品属性
  388. * @apiSuccess {Int} result.goods_info.goods_click 商品点击次数
  389. * @apiSuccess {Int} result.goods_info.goods_collect 收藏数
  390. * @apiSuccess {Int} result.goods_info.goods_commonid 商品公共ID
  391. * @apiSuccess {Float} result.goods_info.goods_costprice 商品成本价
  392. * @apiSuccess {Int} result.goods_info.goods_discount 商品折扣
  393. * @apiSuccess {Float} result.goods_info.goods_freight 运费
  394. * @apiSuccess {Int} result.goods_info.goods_id 商品ID
  395. * @apiSuccess {Float} result.goods_info.goods_marketprice 商品市场价
  396. * @apiSuccess {String} result.goods_info.goods_mgdiscount 会员等级折扣
  397. * @apiSuccess {String} result.goods_info.goods_name 商品名称
  398. * @apiSuccess {Float} result.goods_info.goods_price 商品价格
  399. * @apiSuccess {Float} result.goods_info.goods_promotion_price 商品促销价
  400. * @apiSuccess {String} result.goods_info.goods_promotion_type 商品促销类型
  401. * @apiSuccess {Int} result.goods_info.goods_salenum 销售量
  402. * @apiSuccess {String} result.goods_info.goods_serial 货号
  403. * @apiSuccess {String} result.goods_info.goods_spec 商品规格序列化
  404. * @apiSuccess {String} result.goods_info.goods_specname 规格名称序列化
  405. * @apiSuccess {String} result.goods_info.goods_stcids 店铺分类id 首尾用,隔开
  406. * @apiSuccess {Int} result.goods_info.goods_storage 库存
  407. * @apiSuccess {Int} result.goods_info.goods_storage_alarm 预警库存
  408. * @apiSuccess {Int} result.goods_info.goods_url 商品PC端连接
  409. * @apiSuccess {Int} result.goods_info.goods_vat 是否开具增值税发票 1:是 0:否
  410. * @apiSuccess {Object} result.goods_info.groupbuy_info 抢购信息
  411. * @apiSuccess {Float} result.goods_info.inviter_amount 商品已结算的分销佣金
  412. * @apiSuccess {Int} result.goods_info.inviter_open 是否开启分销 1是0否
  413. * @apiSuccess {Float} result.goods_info.inviter_ratio_1 一级分销比例
  414. * @apiSuccess {Float} result.goods_info.inviter_ratio_2 二级分销比例
  415. * @apiSuccess {Float} result.goods_info.inviter_ratio_3 三级分销比例
  416. * @apiSuccess {Float} result.goods_info.inviter_total_amount 总分销金额
  417. * @apiSuccess {Int} result.goods_info.inviter_total_quantity 总分销量
  418. * @apiSuccess {Int} result.goods_info.is_appoint 是否是预约商品 1:是 0:否
  419. * @apiSuccess {Int} result.goods_info.is_goodsfcode 是否是F码商品 1:是 0:否
  420. * @apiSuccess {Int} result.goods_info.is_have_gift 是否含赠品 1:是 0:否
  421. * @apiSuccess {Int} result.goods_info.is_platform_store 是否自营商品 1:是 0:否
  422. * @apiSuccess {Int} result.goods_info.is_virtual 是否是虚拟商品 1:是 0:否
  423. * @apiSuccess {Object} result.goods_info.mgdiscount_info 会员等级折扣信息
  424. * @apiSuccess {Object} result.goods_info.pintuan_info 拼团信息
  425. * @apiSuccess {Int} result.goods_info.pintuangroup_share_id 拼团ID
  426. * @apiSuccess {Int} result.goods_info.plateid_bottom 底部关联板式
  427. * @apiSuccess {Int} result.goods_info.plateid_top 顶部关联板式
  428. * @apiSuccess {Int} result.goods_info.region_id 地区ID
  429. * @apiSuccess {String} result.goods_info.spec_name 规格名称
  430. * @apiSuccess {Int} result.goods_info.spec_value 规格值
  431. * @apiSuccess {Int} result.goods_info.transport_id 商品售卖区域
  432. * @apiSuccess {String} result.goods_info.transport_title 商品售卖区域名称
  433. * @apiSuccess {Int} result.goods_info.virtual_indate 虚拟商品有效期
  434. * @apiSuccess {Int} result.goods_info.virtual_invalid_refund 是否允许过期退款 1:是 0:否
  435. * @apiSuccess {Int} result.goods_info.virtual_limit 虚拟商品购买上限
  436. * @apiSuccess {Object} result.goods_info.xianshi_info 秒杀信息
  437. * @apiSuccess {Object[]} result.mb_body 商品详情列表
  438. * @apiSuccess {String} result.mb_body.type 详情类型 text文字image图片
  439. * @apiSuccess {String} result.mb_body.value 详情值
  440. * @apiSuccess {Float} result.inviter_amount 分销佣金
  441. * @apiSuccess {Boolean} result.is_favorate 是否已收藏 true是false否
  442. * @apiSuccess {Object} result.spec_image 规格图片列表,键为规格ID,值为规格图片完整路径
  443. * @apiSuccess {Object} result.spec_list 规格商品ID列表,键为规格ID,值为商品ID
  444. * @apiSuccess {Object} result.store_info 店铺信息
  445. * @apiSuccess {Int} result.store_info.goods_count 商品数
  446. * @apiSuccess {Int} result.store_info.is_platform_store 是否平台自营 1是0否
  447. * @apiSuccess {Int} result.store_info.member_id 用户ID
  448. * @apiSuccess {String} result.store_info.member_name 用户名称
  449. * @apiSuccess {String} result.store_info.store_address 店铺地址
  450. * @apiSuccess {Object} result.store_info.store_credit 店铺信用信息
  451. * @apiSuccess {Object} result.store_info.store_credit.store_deliverycredit 发货信用信息
  452. * @apiSuccess {Int} result.store_info.store_credit.store_deliverycredit.credit 发货信用值
  453. * @apiSuccess {String} result.store_info.store_credit.store_deliverycredit.text 发货信用描述
  454. * @apiSuccess {Object} result.store_info.store_credit.store_desccredit 描述相符信用信息
  455. * @apiSuccess {Int} result.store_info.store_credit.store_desccredit.credit 描述相符信用值
  456. * @apiSuccess {String} result.store_info.store_credit.store_desccredit.text 描述相符信用描述
  457. * @apiSuccess {Object} result.store_info.store_credit.store_servicecredit 服务态度信用信息
  458. * @apiSuccess {Int} result.store_info.store_credit.store_servicecredit.credit 服务态度信用值
  459. * @apiSuccess {String} result.store_info.store_credit.store_servicecredit.text 服务态度信用描述
  460. * @apiSuccess {Int} result.store_info.store_id 店铺ID
  461. * @apiSuccess {String} result.store_info.store_logo 店铺logo
  462. * @apiSuccess {String} result.store_info.store_name 店铺名称
  463. * @apiSuccess {Object[]} result.voucher 店铺优惠券列表
  464. * @apiSuccess {String} result.voucher.vouchertemplate_enddate 优惠券过期时间描述
  465. * @apiSuccess {Int} result.voucher.vouchertemplate_id 优惠券模板ID
  466. * @apiSuccess {Float} result.voucher.vouchertemplate_limit 优惠券最低消费金额
  467. * @apiSuccess {Int} result.voucher.vouchertemplate_price 优惠金额
  468. */
  469. public function goods_detail()
  470. {
  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. {
  751. $goods_id = intval(input('param.goods_id'));
  752. if ($goods_id <= 0) {
  753. ds_json_encode(10001, lang('param_error'));
  754. }
  755. //得到商品咨询信息
  756. $consult_model = model('consult');
  757. $condition = array();
  758. $condition[] = array('goods_id', '=', $goods_id);
  759. if (intval(input('param.ctid')) > 0) {
  760. $condition[] = array('consulttype_id', '=', intval(input('param.ctid')));
  761. }
  762. $consult_list = $consult_model->getConsultList($condition, '*');
  763. $result = array_merge(array('consult_list' => $consult_list), mobile_page($consult_model->page_info));
  764. ds_json_encode(10000, '', $result);
  765. }
  766. /**
  767. * @api {POST} api/Goods/save_consult 商品咨询添加
  768. * @apiVersion 1.0.0
  769. * @apiGroup Goods
  770. *
  771. * @apiParam {Int} goods_id 商品ID
  772. * @apiParam {String} goods_content 咨询内容
  773. * @apiParam {Int} consult_type_id 咨询类型ID
  774. * @apiParam {String} key 用户授权token
  775. *
  776. * @apiSuccess {String} code 返回码,10000为成功
  777. * @apiSuccess {String} message 返回消息
  778. */
  779. public function save_consult()
  780. {
  781. $member_id = $this->getMemberIdIfExists();
  782. //检查是否可以评论
  783. if (!config('ds_config.guest_comment') && !$member_id) {
  784. ds_json_encode(10001, lang('goods_index_goods_noallow'));
  785. }
  786. $goods_id = intval(input('post.goods_id'));
  787. if ($goods_id <= 0) {
  788. ds_json_encode(10001, lang('param_error'));
  789. }
  790. //咨询内容的非空验证
  791. if (trim(input('post.goods_content')) == "") {
  792. ds_json_encode(10001, lang('goods_index_input_consult'));
  793. }
  794. //表单验证
  795. $data = [
  796. 'goods_content' => input('post.goods_content')
  797. ];
  798. $res = word_filter($data['goods_content']);
  799. if (!$res['code']) {
  800. ds_json_encode(10001, $res['msg']);
  801. }
  802. $data['goods_content'] = $res['data']['text'];
  803. $goods_validate = ds_validate('goods');
  804. if (!$goods_validate->scene('save_consult')->check($data)) {
  805. ds_json_encode(10001, $goods_validate->getError());
  806. }
  807. //判断商品编号的存在性和合法性
  808. $goods = model('goods');
  809. $goods_info = $goods->getGoodsInfoByID($goods_id);
  810. if (empty($goods_info)) {
  811. ds_json_encode(10001, lang('goods_index_goods_not_exists'));
  812. }
  813. if ($member_id) {
  814. //查询会员信息
  815. $member_model = model('member');
  816. $member_info = $member_model->getMemberInfo(array('member_id' => $member_id));
  817. if (empty($member_info) || $member_info['is_allowtalk'] == 0) {
  818. ds_json_encode(10001, lang('goods_index_goods_noallow'));
  819. }
  820. $seller_model = model('seller');
  821. $seller_info = $seller_model->getSellerInfo(array('member_id' => $member_id));
  822. //判断是否是店主本人
  823. if ($seller_info && $goods_info['store_id'] == $seller_info['store_id']) {
  824. ds_json_encode(10001, lang('goods_index_consult_store_error'));
  825. }
  826. }
  827. //检查店铺状态
  828. $store_model = model('store');
  829. $store_info = $store_model->getStoreInfoByID($goods_info['store_id']);
  830. if ($store_info['store_state'] == '0' || intval($store_info['store_state']) == '2' || (intval($store_info['store_endtime']) != 0 && $store_info['store_endtime'] <= TIMESTAMP)) {
  831. ds_json_encode(10001, lang('goods_index_goods_store_closed'));
  832. }
  833. //接收数据并保存
  834. $input = array();
  835. $input['goods_id'] = $goods_id;
  836. $input['goods_name'] = $goods_info['goods_name'];
  837. $input['member_id'] = intval($member_id) > 0 ? $member_id : 0;
  838. $input['member_name'] = isset($member_info) ? $member_info['member_name'] : '';
  839. $input['store_id'] = $store_info['store_id'];
  840. $input['store_name'] = $store_info['store_name'];
  841. $input['consulttype_id'] = intval(input('post.consult_type_id', 1));
  842. $input['consult_addtime'] = TIMESTAMP;
  843. $input['consult_content'] = $data['goods_content'];
  844. $input['consult_isanonymous'] = input('post.hide_name') == 'hide' ? 1 : 0;
  845. $consult_model = model('consult');
  846. if ($consult_model->addConsult($input)) {
  847. ds_json_encode(10000, lang('goods_index_consult_success'));
  848. } else {
  849. ds_json_encode(10001, lang('goods_index_consult_fail'));
  850. }
  851. }
  852. /**
  853. * 记录浏览历史
  854. */
  855. public function addbrowse()
  856. {
  857. $goods_id = intval(input('param.gid'));
  858. model('goodsbrowse')->addViewedGoods($goods_id, $this->member_info['member_id'], $this->store_info['store_id']);
  859. exit();
  860. }
  861. /**
  862. * 商品详细信息处理
  863. */
  864. private function _goods_detail_extend($goods_detail)
  865. {
  866. //整理商品规格
  867. $goods_detail['spec_detail'] = json_decode($goods_detail['spec_list'], true);
  868. unset($goods_detail['spec_list']);
  869. $goods_detail['spec_list'] = $goods_detail['spec_list_mobile'];
  870. unset($goods_detail['spec_list_mobile']);
  871. //整理商品图片
  872. unset($goods_detail['goods_image']);
  873. $goods_detail['goods_image'] = $goods_detail['goods_image_mobile'];
  874. unset($goods_detail['goods_image_mobile']);
  875. //商品PC端详情信息
  876. $goods_detail['goods_info']['goods_body'] = htmlspecialchars_decode($goods_detail['goods_info']['goods_body']);
  877. //整理数据
  878. // unset($goods_detail['goods_info']['goods_commonid']);
  879. unset($goods_detail['goods_info']['gc_id']);
  880. unset($goods_detail['goods_info']['gc_name']);
  881. unset($goods_detail['goods_info']['store_id']);
  882. unset($goods_detail['goods_info']['store_name']);
  883. unset($goods_detail['goods_info']['brand_id']);
  884. unset($goods_detail['goods_info']['brand_name']);
  885. unset($goods_detail['goods_info']['type_id']);
  886. unset($goods_detail['goods_info']['goods_image']);
  887. unset($goods_detail['goods_info']['goods_stateremark']);
  888. unset($goods_detail['goods_info']['goods_verifyremark']);
  889. unset($goods_detail['goods_info']['goods_lock']);
  890. unset($goods_detail['goods_info']['goods_addtime']);
  891. unset($goods_detail['goods_info']['goods_edittime']);
  892. unset($goods_detail['goods_info']['goods_shelftime']);
  893. unset($goods_detail['goods_info']['goods_show']);
  894. unset($goods_detail['goods_info']['goods_commend']);
  895. unset($goods_detail['goods_info']['explain']);
  896. unset($goods_detail['goods_info']['buynow_text']);
  897. unset($goods_detail['groupbuy_info']);
  898. unset($goods_detail['xianshi_info']);
  899. return $goods_detail;
  900. }
  901. /**
  902. * @api {POST} api/Goods/goods_evaluate 商品评论
  903. * @apiVersion 1.0.0
  904. * @apiGroup Goods
  905. *
  906. * @apiParam {Int} goods_id 商品ID
  907. * @apiParam {Int} type 类型 1好评 2中评 3差评
  908. * @apiParam {Int} page 页码
  909. * @apiParam {Int} per_page 每页显示数量
  910. *
  911. * @apiSuccess {String} code 返回码,10000为成功
  912. * @apiSuccess {String} message 返回消息
  913. * @apiSuccess {Object} result 返回数据
  914. * @apiSuccess {Object[]} result.goods_eval_list 评论列表
  915. * @apiSuccess {Int} result.goods_eval_list.geval_addtime 评论时间
  916. * @apiSuccess {Int} result.goods_eval_list.geval_content 评论内容
  917. * @apiSuccess {Int} result.goods_eval_list.geval_explain 店主解释
  918. * @apiSuccess {Int} result.goods_eval_list.geval_frommemberid 评论用户ID
  919. * @apiSuccess {Int} result.goods_eval_list.geval_frommembername 评论用户名
  920. * @apiSuccess {Int} result.goods_eval_list.geval_goodsid 评论商品ID
  921. * @apiSuccess {Int} result.goods_eval_list.geval_goodsimage 评论商品图片
  922. * @apiSuccess {Int} result.goods_eval_list.geval_goodsname 评论商品名称
  923. * @apiSuccess {Int} result.goods_eval_list.geval_goodsprice 评论价格
  924. * @apiSuccess {Int} result.goods_eval_list.geval_id 评论ID
  925. * @apiSuccess {Int} result.goods_eval_list.geval_image 评论晒图
  926. * @apiSuccess {Int} result.goods_eval_list.geval_isanonymous 是否匿名
  927. * @apiSuccess {Int} result.goods_eval_list.geval_ordergoodsid 订单商品ID
  928. * @apiSuccess {Int} result.goods_eval_list.geval_orderid 订单ID
  929. * @apiSuccess {Int} result.goods_eval_list.geval_orderno 订单编号
  930. * @apiSuccess {Int} result.goods_eval_list.geval_remark 管理员对评价的处理备注
  931. * @apiSuccess {Int} result.goods_eval_list.geval_scores 评分
  932. * @apiSuccess {Int} result.goods_eval_list.geval_state 评价信息的状态 0为正常 1为禁止显示
  933. * @apiSuccess {Int} result.goods_eval_list.geval_storeid 店铺ID
  934. * @apiSuccess {Int} result.goods_eval_list.geval_storename 店铺名称
  935. * @apiSuccess {Int} result.goods_eval_list.member_avatar 用户头像
  936. * @apiSuccess {Int} result.page_total 总页数
  937. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  938. */
  939. public function goods_evaluate()
  940. {
  941. $goods_id = intval(input('param.goods_id'));
  942. $type = intval(input('param.type'));
  943. $condition = array();
  944. $condition[] = array('geval_goodsid', '=', $goods_id);
  945. switch ($type) {
  946. case '1':
  947. $condition[] = array('geval_scores', 'in', '5,4');
  948. break;
  949. case '2':
  950. $condition[] = array('geval_scores', 'in', '3,2');
  951. break;
  952. case '3':
  953. $condition[] = array('geval_scores', 'in', '1');
  954. break;
  955. case '4':
  956. //$condition[] = array('geval_image|geval_image_again','<>', ''); //追加评价带后续处理
  957. $condition[] = array('geval_image', '<>', '');
  958. break;
  959. case '5':
  960. $condition[] = array('geval_content_again', '<>', '');
  961. break;
  962. }
  963. //查询商品评分信息
  964. $evaluategoods_model = model('evaluategoods');
  965. $goods_eval_list = $evaluategoods_model->getEvaluategoodsList($condition, $this->pagesize);
  966. foreach ($goods_eval_list as $k => $val) {
  967. if ($val['geval_isanonymous']) {
  968. $goods_eval_list[$k]['member_avatar'] = get_member_avatar_for_id(0);
  969. $goods_eval_list[$k]['geval_frommembername'] = str_cut($val['geval_frommembername'], 2) . '***';
  970. }
  971. if (!empty($goods_eval_list[$k]['geval_image'])) {
  972. $goods_eval_list[$k]['geval_image'] = explode(',', $goods_eval_list[$k]['geval_image']);
  973. foreach ($goods_eval_list[$k]['geval_image'] as $kk => $vv) {
  974. $store_id = substr($vv, 0, strpos($vv, '_'));
  975. $goods_eval_list[$k]['geval_image'][$kk] = ds_get_pic(ATTACH_MALBUM . '/' . $store_id, $vv);
  976. }
  977. }
  978. }
  979. $goods_eval_list = model('memberevaluate', 'logic')->evaluateListDity($goods_eval_list);
  980. $result = array_merge(array('goods_eval_list' => $goods_eval_list), mobile_page(is_object($evaluategoods_model->page_info) ? $evaluategoods_model->page_info : 0));
  981. ds_json_encode(10000, '', $result);
  982. }
  983. /**
  984. * 商品详细页运费显示
  985. *
  986. * @return unknown
  987. */
  988. public function calc()
  989. {
  990. $area_id = intval(input('param.area_id'));
  991. $goods_id = intval(input('param.goods_id'));
  992. ds_json_encode(10000, '', $this->_calc($area_id, $goods_id));
  993. }
  994. public function _calc($area_id, $goods_id)
  995. {
  996. $goods_info = model('goods')->getGoodsInfo(array('goods_id' => $goods_id), 'transport_id,store_id,goods_freight');
  997. $store_info = model('store')->getStoreInfoByID($goods_info['store_id']);
  998. $if_store = true;
  999. $area_name = '';
  1000. if ($area_id <= 0) {
  1001. if (strpos($store_info['deliver_region'], '|')) {
  1002. $store_info['deliver_region'] = explode('|', $store_info['deliver_region']);
  1003. $store_info['deliver_region_ids'] = explode(' ', $store_info['deliver_region'][0]);
  1004. }
  1005. if (isset($store_info['deliver_region_ids'])) {
  1006. $area_id = intval($store_info['deliver_region_ids'][0]);
  1007. $area_name = $store_info['deliver_region'][1];
  1008. }
  1009. }
  1010. if ($goods_info['transport_id']) {
  1011. $freight_total = model('transport')->calcTransport(intval($goods_info['transport_id']), $area_id);
  1012. if ($freight_total > 0) {
  1013. if ($store_info['store_free_price'] > 0) {
  1014. if ($freight_total >= $store_info['store_free_price']) {
  1015. $freight_total = lang('free_shipping');
  1016. } else {
  1017. $freight_total = lang('freight') . ':' . $freight_total . lang('shop_with') . $store_info['store_free_price'] . lang('goods_index_yuan') . lang('free_shipping');
  1018. }
  1019. } else {
  1020. $freight_total = lang('freight') . ':' . $freight_total . lang('goods_index_yuan');
  1021. }
  1022. } else {
  1023. if ($freight_total === false) {
  1024. $if_store = false;
  1025. }
  1026. $freight_total = lang('free_shipping');
  1027. }
  1028. } else {
  1029. $freight_total = $goods_info['goods_freight'] > 0 ? lang('freight') . ':' . $goods_info['goods_freight'] . lang('goods_index_yuan') : lang('free_shipping');
  1030. }
  1031. 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'));
  1032. }
  1033. /**
  1034. * 经纬度转换
  1035. * @param unknown $bdLat
  1036. * @param unknown $bdLon
  1037. * @return multitype:number
  1038. */
  1039. public function bd_decrypt($bdLat, $bdLon)
  1040. {
  1041. $x = $bdLon - 0.0065;
  1042. $y = $bdLat - 0.006;
  1043. $z = sqrt($x * $x + $y * $y) - 0.00002 * sin($y * $this->x_pi);
  1044. $theta = atan2($y, $x) - 0.000003 * cos($x * $this->x_pi);
  1045. $gcjLon = $z * cos($theta);
  1046. $gcjLat = $z * sin($theta);
  1047. return array('lat' => $gcjLat, 'lon' => $gcjLon);
  1048. }
  1049. /**
  1050. * @desc 根据两点间的经纬度计算距离
  1051. * @param float $lat 纬度值
  1052. * @param float $lng 经度值
  1053. */
  1054. private function getDistance($lat1, $lng1, $lat2, $lng2)
  1055. {
  1056. $earthRadius = 6367000; //approximate radius of earth in meters
  1057. /*
  1058. Convert these degrees to radians
  1059. to work with the formula
  1060. */
  1061. $lat1 = ($lat1 * pi()) / 180;
  1062. $lng1 = ($lng1 * pi()) / 180;
  1063. $lat2 = ($lat2 * pi()) / 180;
  1064. $lng2 = ($lng2 * pi()) / 180;
  1065. /*
  1066. Using the
  1067. Haversine formula
  1068. http://en.wikipedia.org/wiki/Haversine_formula
  1069. calculate the distance
  1070. */
  1071. $calcLongitude = $lng2 - $lng1;
  1072. $calcLatitude = $lat2 - $lat1;
  1073. $stepOne = pow(sin($calcLatitude / 2), 2) + cos($lat1) * cos($lat2) * pow(sin($calcLongitude / 2), 2);
  1074. $stepTwo = 2 * asin(min(1, sqrt($stepOne)));
  1075. $calculatedDistance = $earthRadius * $stepTwo;
  1076. return round($calculatedDistance);
  1077. }
  1078. private function parseDistance($num = 0)
  1079. {
  1080. $num = floatval($num);
  1081. if ($num >= 1000) {
  1082. $num = $num / 1000;
  1083. return str_replace('.0', '', number_format($num, 1, '.', '')) . 'km';
  1084. } else {
  1085. return $num . 'm';
  1086. }
  1087. }
  1088. /**
  1089. * 获取自提点
  1090. */
  1091. public function chain_list()
  1092. {
  1093. $area_id = input('param.area_id');
  1094. $goods_id = input('param.goods_id');
  1095. $num = input('param.num');
  1096. if (!$num) {
  1097. !$num = 1;
  1098. }
  1099. $chain_model = model('chain');
  1100. $chain_ids = Db::name('chain_goods')->where(array(array('goods_id', '=', $goods_id), array('goods_storage', '>=', $num)))->column('chain_id');
  1101. $condition = array();
  1102. $condition[] = array('chain_if_pickup', '=', 1);
  1103. $condition[] = array('chain_id', 'in', $chain_ids);
  1104. if ($area_id) {
  1105. $condition[] = array('chain_area_2|chain_area_3', '=', $area_id);
  1106. }
  1107. $chain_list = $chain_model->getChainOpenList($condition);
  1108. $chain_list = array_values($chain_list);
  1109. return ds_json_encode(10000, '', array('chain_list' => $chain_list));
  1110. }
  1111. }