Goods.php 58 KB

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