Goods.php 61 KB

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