Store.php 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893
  1. <?php
  2. namespace app\api\controller;
  3. use think\facade\View;
  4. use think\facade\Db;
  5. use think\facade\Lang;
  6. /**
  7. * ============================================================================
  8. *
  9. * ============================================================================
  10. *
  11. * ----------------------------------------------------------------------------
  12. *
  13. * ============================================================================
  14. * 店铺控制器
  15. */
  16. class Store extends MobileMall
  17. {
  18. public function initialize()
  19. {
  20. parent::initialize();
  21. Lang::load(base_path() . 'home/lang/' . config('lang.default_lang') . '/store.lang.php');
  22. }
  23. /**
  24. * @api {POST} api/Store/store_list 店铺列表
  25. * @apiVersion 1.0.0
  26. * @apiGroup Store
  27. *
  28. * @apiHeader {String} X-DS-KEY 卖家授权token
  29. *
  30. * @apiParam {Int} cate_id 分类ID
  31. * @apiParam {String} keyword 关键词
  32. * @apiParam {String} user_name 用户名
  33. * @apiParam {String} area_info 地区
  34. * @apiParam {String} order 排序 desc降序 asc升序
  35. * @apiParam {String} sort_key 排序字段 store_credit店铺信用 store_sales销量
  36. * @apiParam {Int} page 页码
  37. * @apiParam {Int} pagesize 每页显示数量
  38. *
  39. * @apiSuccess {String} code 返回码,10000为成功
  40. * @apiSuccess {String} message 返回消息
  41. * @apiSuccess {Object} result 返回数据
  42. * @apiSuccess {Object[]} result.store_list 店铺列表 (返回字段参考store)
  43. * @apiSuccess {Int} result.page_total 总页数
  44. * @apiSuccess {Boolean} result.hasmore 是否有更多 true是false否
  45. */
  46. public function store_list()
  47. {
  48. //店铺类目快速搜索
  49. $class_list = rkcache('storeclass', true, 'file');
  50. $cate_id = intval(input('param.cate_id'));
  51. if (!key_exists($cate_id, $class_list))
  52. $cate_id = 0;
  53. View::assign('class_list', $class_list);
  54. //店铺搜索
  55. $condition = array();
  56. $keyword = trim(input('param.keyword'));
  57. if ($keyword != '') {
  58. $condition[] = array('store_name|store_mainbusiness', 'like', '%' . $keyword . '%');
  59. }
  60. $user_name = trim(input('param.user_name'));
  61. if ($user_name != '') {
  62. $condition[] = array('member_name', '=', $user_name);
  63. }
  64. $area_info = trim(input('param.area_info'));
  65. if (!empty($area_info)) {
  66. //修复店铺按地区搜索
  67. $tabs = preg_split("#\s+#", $area_info, -1, PREG_SPLIT_NO_EMPTY);
  68. $len = count($tabs);
  69. $area_name = $tabs[$len - 1];
  70. if ($area_name) {
  71. $area_name = trim($area_name);
  72. $condition[] = array('area_info', 'like', '%' . $area_name . '%');
  73. }
  74. }
  75. if ($cate_id > 0) {
  76. $condition[] = array('storeclass_id', '=', $cate_id);
  77. }
  78. $condition[] = array('store_state', '=', 1);
  79. $order = trim(input('param.order'));
  80. if (!in_array($order, array('desc', 'asc'))) {
  81. unset($order);
  82. }
  83. $order_sort = 'store_sort asc';
  84. //信用度排序
  85. $key = trim(input('param.sort_key'));
  86. switch ($key) {
  87. case 'store_sales':
  88. $order_sort = 'store_sales desc';
  89. break;
  90. case 'store_credit':
  91. $order_sort = 'store_credit desc';
  92. break;
  93. }
  94. $store_model = model('store');
  95. $store_list = $store_model->getStoreList($condition, 10, $order_sort);
  96. //获取店铺商品数,推荐商品列表等信息
  97. $store_list = $store_model->getStoreSearchList($store_list);
  98. $memberId = $this->getMemberIdIfExists();
  99. foreach ($store_list as $key => $val) {
  100. // 如果已登录 判断该店铺是否已被收藏
  101. if ($memberId) {
  102. $c = (int) model('favorites')->getStoreFavoritesCountByStoreId($val['store_id'], $memberId);
  103. $store_list[$key]['is_favorate'] = $c > 0;
  104. } else {
  105. $store_list[$key]['is_favorate'] = false;
  106. }
  107. $store_list[$key]['goods_list'] = model('goods')->getGoodsListByColorDistinct(array(array('store_id', '=', $val['store_id']), array('goods_commend', '=', 1)), 'goods_image,goods_id,goods_price', 'goods_id desc', 0, 4);
  108. foreach ($store_list[$key]['goods_list'] as $k => $v) {
  109. $store_list[$key]['goods_list'][$k]['goods_image_url'] = goods_cthumb($v['goods_image'], 480, $val['store_id']);
  110. }
  111. $store_list[$key]['store_avatar'] = get_store_logo($store_list[$key]['store_avatar']);
  112. }
  113. $result = array_merge(array('store_list' => $store_list), mobile_page($store_model->page_info));
  114. ds_json_encode(10000, '', $result);
  115. }
  116. /**
  117. * @api {POST} api/Store/store_info 店铺信息
  118. * @apiVersion 1.0.0
  119. * @apiGroup Store
  120. *
  121. * @apiParam {Int} store_id 店铺ID
  122. *
  123. * @apiSuccess {String} code 返回码,10000为成功
  124. * @apiSuccess {String} message 返回消息
  125. * @apiSuccess {Object} result 返回数据
  126. * @apiSuccess {Object[]} result.rec_goods_list 推荐商品列表
  127. * @apiSuccess {Int} result.rec_goods_list.evaluation_count 评论数
  128. * @apiSuccess {Int} result.rec_goods_list.evaluation_good_star 评分
  129. * @apiSuccess {Int} result.rec_goods_list.goods_addtime 添加时间
  130. * @apiSuccess {Int} result.rec_goods_list.goods_id 商品ID
  131. * @apiSuccess {String} result.rec_goods_list.goods_image 商品图片名称
  132. * @apiSuccess {String} result.rec_goods_list.goods_image_url 商品图片完整路径
  133. * @apiSuccess {Float} result.rec_goods_list.goods_marketprice 市场价
  134. * @apiSuccess {String} result.rec_goods_list.goods_name 商品名称
  135. * @apiSuccess {Float} result.rec_goods_list.goods_price 商品价格
  136. * @apiSuccess {Int} result.rec_goods_list.goods_salenum 销量
  137. * @apiSuccess {Boolean} result.rec_goods_list.group_flag 是否抢购 false否true是
  138. * @apiSuccess {Int} result.rec_goods_list.is_goodsfcode 是否F码商品 0否1是
  139. * @apiSuccess {Int} result.rec_goods_list.is_have_gift 是否含赠品 0否1是
  140. * @apiSuccess {Int} result.rec_goods_list.is_virtual 是否虚拟商品 0否1是
  141. * @apiSuccess {Int} result.rec_goods_list.store_id 店铺ID
  142. * @apiSuccess {String} result.rec_goods_list.store_name 店铺名称
  143. * @apiSuccess {Boolean} result.rec_goods_list.xianshi_flag 是否显示 false否true是
  144. * @apiSuccess {Int} result.rec_goods_list_count 推荐商品数
  145. * @apiSuccess {Object} result.store_info 店铺信息
  146. * @apiSuccess {Int} result.store_info.goods_count 商品数
  147. * @apiSuccess {Boolean} result.store_info.is_favorate 已收藏 false否true是
  148. * @apiSuccess {Boolean} result.store_info.is_platform_store 是否自营 false否true是
  149. * @apiSuccess {String[]} result.store_info.mb_sliders 轮播图
  150. * @apiSuccess {String} result.store_info.mb_title_img 背景图
  151. * @apiSuccess {Int} result.store_info.member_id 用户ID
  152. * @apiSuccess {String} result.store_info.store_avatar 店铺图像
  153. * @apiSuccess {Int} result.store_info.store_collect 店铺收藏数
  154. * @apiSuccess {String} result.store_info.store_credit_text 信用描述
  155. * @apiSuccess {Int} result.store_info.store_id 店铺ID
  156. * @apiSuccess {String} result.store_info.store_name 店铺名称
  157. * @apiSuccess {Object[]} result.store_info.store_credit 店铺评分
  158. * @apiSuccess {String} result.store_info.store_company_name 店铺公司名称
  159. * @apiSuccess {String} result.store_info.area_info 店铺地址
  160. * @apiSuccess {String} result.store_info.store_phone 店铺商家电话
  161. * @apiSuccess {String} result.store_info.store_mainbusiness 店铺主营商品
  162. * @apiSuccess {String} result.store_info.seller_name 店铺店主用户名
  163. * @apiSuccess {String} result.store_info.store_qq 店铺QQ
  164. * @apiSuccess {String} result.store_info.store_ww 店铺旺旺
  165. */
  166. public function store_info()
  167. {
  168. $store_id = intval(input('param.store_id'));
  169. if ($store_id <= 0) {
  170. ds_json_encode(10001, lang('param_error'));
  171. }
  172. $store_online_info = model('store')->getStoreOnlineInfoByID($store_id);
  173. if (empty($store_online_info)) {
  174. ds_json_encode(10001, lang('show_store_index_store_not_exists'));
  175. }
  176. $store_info = array();
  177. $store_info['store_id'] = $store_online_info['store_id'];
  178. $store_info['store_name'] = $store_online_info['store_name'];
  179. $store_info['member_id'] = $store_online_info['member_id'];
  180. $store_info['store_credit'] = $store_online_info['store_credit'];
  181. $store_info['store_company_name'] = $store_online_info['store_company_name'];
  182. $store_info['area_info'] = $store_online_info['area_info'];
  183. $store_info['store_phone'] = $store_online_info['store_phone'];
  184. $store_info['store_mainbusiness'] = $store_online_info['store_mainbusiness'];
  185. $store_info['seller_name'] = $store_online_info['seller_name'];
  186. $store_info['store_qq'] = $store_online_info['store_qq'];
  187. $store_info['store_ww'] = $store_online_info['store_ww'];
  188. $store_info['store_longitude'] = $store_online_info['store_longitude'];
  189. $store_info['store_latitude'] = $store_online_info['store_latitude'];
  190. $store_info['store_address'] = $store_online_info['store_address'];
  191. $storejoinin_model = model('storejoinin');
  192. if (!$store_online_info['is_platform_store']) {
  193. $storejoinin_info = $storejoinin_model->getOneStorejoinin(array('member_id' => $store_info['member_id']));
  194. //营业执照
  195. if ($storejoinin_info) {
  196. $store_info['business_licence_number_electronic'] = ($storejoinin_info['business_licence_number_electronic'] && $storejoinin_info['store_type'] == 0) ? get_store_joinin_imageurl($storejoinin_info['business_licence_number_electronic']) : '';
  197. }
  198. }
  199. // 店铺头像
  200. $store_info['store_avatar'] = get_store_logo($store_online_info['store_avatar']);
  201. // 商品数
  202. $store_info['goods_count'] = (int) $store_online_info['goods_count'];
  203. // 店铺被收藏次数
  204. $store_info['store_collect'] = (int) $store_online_info['store_collect'];
  205. // 如果已登录 判断该店铺是否已被收藏
  206. if ($memberId = $this->getMemberIdIfExists()) {
  207. $c = (int) model('favorites')->getStoreFavoritesCountByStoreId($store_id, $memberId);
  208. $store_info['is_favorate'] = $c > 0;
  209. } else {
  210. $store_info['is_favorate'] = false;
  211. }
  212. // 是否官方店铺
  213. $store_info['is_platform_store'] = (bool) $store_online_info['is_platform_store'];
  214. // 动态评分
  215. if ($store_info['is_platform_store']) {
  216. $store_info['store_credit_text'] = lang('official_store');
  217. } else {
  218. $store_info['store_credit_text'] = sprintf(
  219. lang('store_credit_text'),
  220. $store_online_info['store_credit']['store_desccredit']['credit'],
  221. $store_online_info['store_credit']['store_servicecredit']['credit'],
  222. $store_online_info['store_credit']['store_deliverycredit']['credit']
  223. );
  224. }
  225. // 页头背景图
  226. $store_info['mb_title_img'] = !empty($store_online_info['mb_title_img']) ? ds_get_pic(ATTACH_STORE, $store_online_info['mb_title_img']) : '';
  227. // 轮播
  228. $store_info['mb_sliders'] = array();
  229. $mbSliders = @unserialize($store_online_info['mb_sliders']);
  230. if ($mbSliders) {
  231. foreach ((array) $mbSliders as $s) {
  232. if ($s['img']) {
  233. $s['imgUrl'] = ds_get_pic(ATTACH_STORE . DIRECTORY_SEPARATOR . 'mobileslide', $s['img']);
  234. $store_info['mb_sliders'][] = $s;
  235. }
  236. }
  237. }
  238. //店主推荐
  239. $where = array();
  240. $where[] = array('store_id', '=', $store_id);
  241. $where[] = array('goods_commend', '=', 1);
  242. $goods_model = model('goods');
  243. $goods_fields = $this->getGoodsFields();
  244. $goods_list = $goods_model->getGoodsListByColorDistinct($where, $goods_fields, 'goods_sort desc, goods_id desc', 0, 20);
  245. $goods_list = $this->_goods_list_extend($goods_list);
  246. $cache_key = 'goods-live-' . $store_info['store_id'] . '-' . date('H');
  247. $result = rcache($cache_key);
  248. if (empty($result)) {
  249. //获取店铺一小时内正在进行的直播
  250. $live_apply_model = model('live_apply');
  251. $condition = array();
  252. $condition[] = array('live_apply_state', '=', 1);
  253. $condition[] = array('live_apply_play_time', '<', strtotime(date('Y-m-d H:0:0')) + 3600);
  254. $condition[] = array('live_apply_end_time', '>', TIMESTAMP);
  255. $condition[] = array('live_apply_type', '=', LIVE_APPLY_TYPE_GOODS);
  256. $condition[] = array('live_apply_user_type', '=', 2);
  257. $condition[] = array('live_apply_user_id', '=', $store_info['store_id']);
  258. $live_apply_list = $live_apply_model->getLiveApplyList($condition, '*', 0);
  259. foreach ($live_apply_list as $key => $val) {
  260. $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');
  261. }
  262. $minute = 60 - intval(date('i'));
  263. $result = array('live_apply_list' => $live_apply_list);
  264. wcache($cache_key, $result, $minute * 60);
  265. }
  266. $live_apply_list = $result['live_apply_list'];
  267. foreach ($live_apply_list as $val) {
  268. if ($val['live_apply_play_time'] < TIMESTAMP && $val['live_apply_end_time'] > TIMESTAMP) {
  269. $val['live_apply_cover_image_url'] = ds_get_pic(ATTACH_COMMON, config('ds_config.default_goods_image'));
  270. if ($val['live_apply_cover_video']) {
  271. $val['live_apply_cover_video_url'] = ds_get_pic(ATTACH_LIVE_APPLY . '/' . $val['live_apply_user_id'], $val['live_apply_cover_video']);
  272. } elseif ($val['live_apply_cover_image']) {
  273. $val['live_apply_cover_image_url'] = ds_get_pic(ATTACH_LIVE_APPLY . '/' . $val['live_apply_user_id'], $val['live_apply_cover_image']);
  274. }
  275. $i = 0;
  276. $val['goods_list'] = array();
  277. foreach ($val['goods_commonid_array'] as $v) {
  278. $goods_info = $goods_model->getGoodsCommonInfoByID($v);
  279. if (!$goods_info || $goods_info['goods_state'] != 1 || $goods_info['goods_verify'] != 1) {
  280. continue;
  281. }
  282. $goods_info['goods_image_url'] = goods_cthumb($goods_info['goods_image'], 480, $goods_info['store_id']);
  283. $val['goods_list'][] = $goods_info;
  284. $i++;
  285. if ($i >= 3) {
  286. break;
  287. }
  288. }
  289. $store_info['live_apply_info'] = $val;
  290. break;
  291. }
  292. }
  293. $evaluatestore_model = model('evaluatestore');
  294. $store_evaluate_info = $evaluatestore_model->getEvaluatestoreInfoByStoreID($store_online_info['store_id'], $store_online_info['storeclass_id']);
  295. $store_info['store_credit_percent'] = $store_evaluate_info['store_credit_percent'];
  296. $result = array(
  297. 'store_info' => $store_info,
  298. 'rec_goods_list_count' => count($goods_list),
  299. 'rec_goods_list' => $goods_list,
  300. );
  301. ds_json_encode(10000, '', $result);
  302. }
  303. /**
  304. * @api {POST} api/Store/store_goods_class 店铺商品分类
  305. * @apiVersion 1.0.0
  306. * @apiGroup Store
  307. *
  308. * @apiParam {Int} store_id 店铺ID
  309. *
  310. * @apiSuccess {String} code 返回码,10000为成功
  311. * @apiSuccess {String} message 返回消息
  312. * @apiSuccess {Object} result 返回数据
  313. */
  314. public function store_goods_class()
  315. {
  316. $store_id = intval(input('param.store_id'));
  317. if ($store_id <= 0) {
  318. ds_json_encode(10001, lang('param_error'));
  319. }
  320. $store_online_info = model('store')->getStoreOnlineInfoByID($store_id);
  321. if (empty($store_online_info)) {
  322. ds_json_encode(10001, lang('show_store_index_store_not_exists'));
  323. }
  324. $store_info = array();
  325. $store_info['store_id'] = $store_online_info['store_id'];
  326. $store_info['store_name'] = $store_online_info['store_name'];
  327. $store_goods_class = model('storegoodsclass')->getStoregoodsclassList(array('store_id' => $store_id));
  328. if ($store_goods_class) {
  329. $tree = new \mall\Tree();
  330. $tree->setTree($store_goods_class, 'storegc_id', 'storegc_parent_id', 'storegc_name');
  331. $store_goods_class = $tree->getArrayList();
  332. }
  333. $result = array(
  334. 'store_info' => $store_info,
  335. 'store_goods_class' => $store_goods_class
  336. );
  337. ds_json_encode(10000, '', $result);
  338. }
  339. /**
  340. * @api {POST} api/Store/store_goods 店铺商品
  341. * @apiVersion 1.0.0
  342. * @apiGroup Store
  343. *
  344. * @apiParam {Int} store_id 店铺ID
  345. * @apiParam {Int} storegc_id 店铺分类ID
  346. * @apiParam {String} keyword 关键词
  347. * @apiParam {String} prom_type 促销类型 xianshi秒杀
  348. * @apiParam {Float} price_from 价格从
  349. * @apiParam {Float} price_to 价格到
  350. * @apiParam {Int} key 排序键 1商品id 2促销价 3销量 4收藏量 5点击量
  351. * @apiParam {Int} order 排序值 1升序 2降序
  352. *
  353. * @apiSuccess {String} code 返回码,10000为成功
  354. * @apiSuccess {String} message 返回消息
  355. * @apiSuccess {Object} result 返回数据
  356. */
  357. public function store_goods()
  358. {
  359. $param = input('param.');
  360. $store_id = (int) $param['store_id'];
  361. if ($store_id <= 0) {
  362. ds_json_encode(10001, lang('param_error'));
  363. }
  364. $storegc_id = isset($param['storegc_id']) ? (int) $param['storegc_id'] : '';
  365. $keyword = isset($param['keyword']) ? trim((string) $param['keyword']) : '';
  366. $condition = array();
  367. $condition[] = array('store_id', '=', $store_id);
  368. // 默认不显示预订商品
  369. if ($storegc_id > 0) {
  370. $condition[] = array('goods_stcids', 'like', '%,' . $storegc_id . ',%');
  371. }
  372. //促销类型
  373. if (isset($param['prom_type'])) {
  374. switch ($param['prom_type']) {
  375. case 'xianshi':
  376. $condition[] = array('goods_promotion_type', '=', 2);
  377. break;
  378. case 'groupbuy':
  379. $condition[] = array('goods_promotion_type', '=', 1);
  380. break;
  381. }
  382. }
  383. if ($keyword != '') {
  384. $condition[] = array('goods_name', 'like', '%' . $keyword . '%');
  385. }
  386. $price_from = preg_match('/^[\d.]{1,20}$/', isset($param['price_from'])) ? $param['price_from'] : null;
  387. $price_to = preg_match('/^[\d.]{1,20}$/', isset($param['price_to'])) ? $param['price_to'] : null;
  388. if ($price_from && $price_from) {
  389. $condition[] = array('goods_promotion_price', 'between', "{$price_from},{$price_to}");
  390. } elseif ($price_from) {
  391. $condition[] = array('goods_promotion_price', '>=', $price_from);
  392. } elseif ($price_to) {
  393. $condition[] = array('goods_promotion_price', '<=', $price_to);
  394. }
  395. // 排序
  396. $order = (isset($param['sort_order']) && (int) $param['sort_order'] == 1) ? 'asc' : 'desc';
  397. if (isset($param['sort_key'])) {
  398. switch (trim($param['sort_key'])) {
  399. case '1':
  400. $order = 'goods_id ' . $order;
  401. break;
  402. case '2':
  403. $order = 'goods_promotion_price ' . $order;
  404. break;
  405. case '3':
  406. $order = 'goods_salenum ' . $order;
  407. break;
  408. case '4':
  409. $order = 'goods_collect ' . $order;
  410. break;
  411. case '5':
  412. $order = 'goods_click ' . $order;
  413. break;
  414. default:
  415. $order = 'goods_id DESC';
  416. break;
  417. }
  418. } else {
  419. $order = 'goods_id DESC';
  420. }
  421. $goods_model = model('goods');
  422. $goods_fields = $this->getGoodsFields();
  423. $goods_list = $goods_model->getGoodsListByColorDistinct($condition, $goods_fields, $order, 10);
  424. $goods_list = $this->_goods_list_extend($goods_list);
  425. $result = array_merge(array('goods_list_count' => count($goods_list), 'goods_list' => $goods_list,), mobile_page($goods_model->page_info));
  426. ds_json_encode(10000, '', $result);
  427. }
  428. private function getGoodsFields()
  429. {
  430. return implode(',', array(
  431. 'goods_id',
  432. 'goods_commonid',
  433. 'store_id',
  434. 'store_name',
  435. 'goods_name',
  436. 'goods_price',
  437. 'goods_promotion_price',
  438. 'goods_promotion_type',
  439. 'goods_marketprice',
  440. 'goods_image',
  441. 'goods_salenum',
  442. 'evaluation_good_star',
  443. 'evaluation_count',
  444. 'is_virtual',
  445. 'is_goodsfcode',
  446. 'is_have_gift',
  447. 'goods_addtime',
  448. ));
  449. }
  450. /**
  451. * 处理商品列表(抢购、秒杀、商品图片)
  452. */
  453. private function _goods_list_extend($goods_list)
  454. {
  455. //获取商品列表编号数组
  456. $goodsid_array = array();
  457. foreach ($goods_list as $key => $value) {
  458. $goodsid_array[] = $value['goods_id'];
  459. }
  460. foreach ($goods_list as $key => $value) {
  461. $goods_list[$key]['group_flag'] = false;
  462. $goods_list[$key]['xianshi_flag'] = false;
  463. $goods_list[$key]['goods_price'] = $value['goods_promotion_price'];
  464. switch ($value['goods_promotion_type']) {
  465. case 1:
  466. $goods_list[$key]['group_flag'] = true;
  467. break;
  468. case 2:
  469. $goods_list[$key]['xianshi_flag'] = true;
  470. break;
  471. }
  472. //商品图片url
  473. $goods_list[$key]['goods_image_url'] = goods_cthumb($value['goods_image'], 480, $value['store_id']);
  474. unset($goods_list[$key]['goods_promotion_type']);
  475. unset($goods_list[$key]['goods_promotion_price']);
  476. unset($goods_list[$key]['goods_commonid']);
  477. unset($goods_list[$key]['nc_distinct']);
  478. }
  479. return $goods_list;
  480. }
  481. /**
  482. * 商品评价
  483. */
  484. public function store_credit()
  485. {
  486. $store_id = intval(input('param.store_id'));
  487. if ($store_id <= 0) {
  488. ds_json_encode(10001, lang('param_error'));
  489. }
  490. $store_online_info = model('store')->getStoreOnlineInfoByID($store_id);
  491. if (empty($store_online_info)) {
  492. ds_json_encode(10001, lang('show_store_index_store_not_exists'));
  493. }
  494. ds_json_encode(10000, '', array('store_credit' => $store_online_info['store_credit']));
  495. }
  496. /**
  497. * 店铺商品排行
  498. */
  499. public function store_goods_rank()
  500. {
  501. $store_id = intval(input('param.store_id'));
  502. if ($store_id <= 0) {
  503. ds_json_encode(10001, '查询出错');
  504. }
  505. $ordertype = ($t = trim(input('param.ordertype'))) ? $t : 'salenumdesc';
  506. $show_num = ($t = intval(input('param.num'))) > 0 ? $t : 10;
  507. $where = array();
  508. $where[] = array('store_id', '=', $store_id);
  509. // 排序
  510. switch ($ordertype) {
  511. case 'salenumdesc':
  512. $order = 'goods_salenum desc';
  513. break;
  514. case 'salenumasc':
  515. $order = 'goods_salenum asc';
  516. break;
  517. case 'collectdesc':
  518. $order = 'goods_collect desc';
  519. break;
  520. case 'collectasc':
  521. $order = 'goods_collect asc';
  522. break;
  523. case 'clickdesc':
  524. $order = 'goods_click desc';
  525. break;
  526. case 'clickasc':
  527. $order = 'goods_click asc';
  528. break;
  529. }
  530. if ($order) {
  531. $order .= ',goods_id desc';
  532. } else {
  533. $order = 'goods_id desc';
  534. }
  535. $goods_model = model('goods');
  536. $goods_fields = $this->getGoodsFields();
  537. $goods_list = $goods_model->getGoodsListByColorDistinct($where, $goods_fields, $order, 0, $show_num);
  538. $goods_list = $this->_goods_list_extend($goods_list);
  539. ds_json_encode(10000, '', array('goods_list' => $goods_list));
  540. }
  541. /**
  542. * 店铺商品上新
  543. */
  544. public function store_new_goods()
  545. {
  546. $store_id = intval(input('param.store_id'));
  547. if ($store_id <= 0) {
  548. ds_json_encode(10000, '', array('goods_list' => array()));
  549. }
  550. $show_day = ($t = intval(input('param.show_day'))) > 0 ? $t : 30;
  551. $where = array();
  552. $where[] = array('store_id', '=', $store_id);
  553. $stime = strtotime(date('Y-m-d', TIMESTAMP - 86400 * $show_day));
  554. $etime = $stime + 86400 * ($show_day + 1);
  555. $where[] = array('goods_addtime', 'between', array($stime, $etime));
  556. $order = 'goods_addtime desc, goods_id desc';
  557. $goods_model = model('goods');
  558. $goods_fields = $this->getGoodsFields();
  559. $goods_list = $goods_model->getGoodsListByColorDistinct($where, $goods_fields, $order, $this->pagesize);
  560. if ($goods_list) {
  561. $goods_list = $this->_goods_list_extend($goods_list);
  562. foreach ($goods_list as $k => $v) {
  563. $v['goods_addtime_text'] = $v['goods_addtime'] ? $this->checkTime($v['goods_addtime']) : '';
  564. $goods_list[$k] = $v;
  565. }
  566. }
  567. $result = array_merge(array('goods_list' => $goods_list), mobile_page($goods_model->page_info));
  568. ds_json_encode(10000, '', $result);
  569. }
  570. /**
  571. * 店铺简介
  572. */
  573. public function store_intro()
  574. {
  575. $store_id = intval(input('param.store_id'));
  576. if ($store_id <= 0) {
  577. ds_json_encode(10001, lang('param_error'));
  578. }
  579. $store_online_info = model('store')->getStoreOnlineInfoByID($store_id);
  580. if (empty($store_online_info)) {
  581. ds_json_encode(10001, lang('show_store_index_store_not_exists'));
  582. }
  583. $store_info = $store_online_info;
  584. //开店时间
  585. $store_info['store_time_text'] = $store_info['store_addtime'] ? @date('Y-m-d', $store_info['store_addtime']) : '';
  586. // 店铺头像
  587. $store_info['store_avatar'] = get_store_logo($store_online_info['store_avatar']);
  588. //商品数
  589. $store_info['goods_count'] = (int) $store_online_info['goods_count'];
  590. //店铺被收藏次数
  591. $store_info['store_collect'] = (int) $store_online_info['store_collect'];
  592. //店铺所属分类
  593. $store_class = model('storeclass')->getStoreclassInfo(array('storeclass_id' => $store_info['storeclass_id']));
  594. $store_info['storeclass_name'] = $store_class['storeclass_name'];
  595. //如果已登录 判断该店铺是否已被收藏
  596. if ($member_id = $this->getMemberIdIfExists()) {
  597. $c = (int) model('favorites')->getStoreFavoritesCountByStoreId($store_id, $member_id);
  598. $store_info['is_favorate'] = $c > 0 ? true : false;
  599. } else {
  600. $store_info['is_favorate'] = false;
  601. }
  602. // 是否官方店铺
  603. $store_info['is_platform_store'] = (bool) $store_online_info['is_platform_store'];
  604. // 页头背景图
  605. $store_info['mb_title_img'] = $store_online_info['mb_title_img'] ? ds_get_pic(ATTACH_STORE, $store_online_info['mb_title_img']) : '';
  606. // 轮播
  607. $store_info['mb_sliders'] = array();
  608. $mbSliders = @unserialize($store_online_info['mb_sliders']);
  609. if ($mbSliders) {
  610. foreach ((array) $mbSliders as $s) {
  611. if ($s['img']) {
  612. $s['imgUrl'] = ds_get_pic(ATTACH_STORE, $s['img']);
  613. $store_info['mb_sliders'][] = $s;
  614. }
  615. }
  616. }
  617. ds_json_encode(10000, '', array('store_info' => $store_info));
  618. }
  619. /**
  620. * @api {POST} api/Store/get_store_class 获取店铺分类
  621. * @apiVersion 1.0.0
  622. * @apiGroup Store
  623. *
  624. * @apiHeader {String} X-DS-KEY 卖家授权token
  625. *
  626. * @apiSuccess {String} code 返回码,10000为成功
  627. * @apiSuccess {String} message 返回消息
  628. * @apiSuccess {Object} result 返回数据
  629. * @apiSuccess {Object[]} result.store_class 返回数据
  630. * @apiSuccess {Int} result.store_class.storeclass_bail 店铺分类保证金数额
  631. * @apiSuccess {Int} result.store_class.storeclass_id 店铺分类ID
  632. * @apiSuccess {String} result.store_class.storeclass_name 店铺分类名
  633. * @apiSuccess {Int} result.store_class.storeclass_sort 排序
  634. */
  635. public function get_store_class()
  636. {
  637. $store_class = rkcache('storeclass', true);
  638. ds_json_encode(10000, '', array('store_class' => array_values($store_class)));
  639. }
  640. public function get_store_grade()
  641. {
  642. $storegrade_list = model('storegrade')->getStoregradeList();
  643. ds_json_encode(10000, '', array('storegrade_list' => array_values($storegrade_list)));
  644. }
  645. /**
  646. * 店铺活动
  647. */
  648. public function store_promotion()
  649. {
  650. $xianshi_array = model('pxianshi');
  651. $promotion['promotion'] = $condition = array();
  652. $condition[] = array('store_id', '=', intval(input('post.store_id')));
  653. $condition[] = array('xianshi_end_time', '>', TIMESTAMP);
  654. $condition[] = array('xianshi_state', '=', 1);
  655. $xianshi = $xianshi_array->getXianshiList($condition);
  656. if (!empty($xianshi)) {
  657. foreach ($xianshi as $key => $value) {
  658. $xianshi[$key]['start_time_text'] = date('Y-m-d', $value['xianshi_starttime']);
  659. $xianshi[$key]['end_time_text'] = date('Y-m-d', $value['xianshi_end_time']);
  660. $xianshi[$key]['goods_list'] = model('pxianshigoods')->getXianshigoodsExtendList(array('xianshi_id' => $value['xianshi_id']));
  661. }
  662. $promotion['promotion']['xianshi'] = $xianshi;
  663. }
  664. $mansong_array = model('pmansong');
  665. $condition = array();
  666. $condition[] = array('store_id', '=', intval(input('post.store_id')));
  667. $condition[] = array('mansong_endtime', '>', TIMESTAMP);
  668. $condition[] = array('mansong_state', '=', 1);
  669. $mansong = $mansong_array->getMansongList($condition);
  670. if (!empty($mansong)) {
  671. foreach ($mansong as $key => $value) {
  672. $mansong[$key]['start_time_text'] = date('Y-m-d', $value['mansong_starttime']);
  673. $mansong[$key]['end_time_text'] = date('Y-m-d', $value['mansong_endtime']);
  674. $mansong[$key]['rules'] = model('pmansongrule')->getMansongruleListByID($value['mansong_id']);
  675. }
  676. $promotion['promotion']['mansong'] = $mansong;
  677. }
  678. if (!empty($promotion['promotion'])) {
  679. ds_json_encode(10000, '', $promotion);
  680. }
  681. ds_json_encode(10001, lang('no_promotion_recent'));
  682. }
  683. /**
  684. * 取得的时间间隔
  685. */
  686. public function checkTime($time)
  687. {
  688. if ($time == '') {
  689. return false;
  690. }
  691. $catch_time = (TIMESTAMP - $time);
  692. if ($catch_time < 60) {
  693. return $catch_time . lang('second_ago');
  694. } elseif ($catch_time < 60 * 60) {
  695. return intval($catch_time / 60) . lang('minute_ago');
  696. } elseif ($catch_time < 60 * 60 * 24) {
  697. return intval($catch_time / 60 / 60) . lang('hour_ago');
  698. } elseif ($catch_time < 60 * 60 * 24 * 30) {
  699. return intval($catch_time / 60 / 60 / 24) . lang('day_ago');
  700. } elseif ($catch_time < 60 * 60 * 24 * 360) {
  701. return intval($catch_time / 60 / 60 / 24 / 30) . lang('month_ago');
  702. } elseif ($catch_time < 60 * 60 * 24 * 365 * 2) {
  703. return intval($catch_time / 60 / 60 / 24 / 365) . lang('year_ago');
  704. } else {
  705. return date('Y-m-d', $time);
  706. }
  707. }
  708. public function get_store_map()
  709. {
  710. $region = input('param.region');
  711. $o_name = input('param.o_name');
  712. $o_lng = input('param.o_lng');
  713. $o_lat = input('param.o_lat');
  714. $d_name = input('param.d_name');
  715. $d_lng = input('param.d_lng');
  716. $d_lat = input('param.d_lat');
  717. if (!$o_lng || !$o_lat || !$o_name || !$d_lng || !$d_lat || !$d_name) {
  718. ds_json_encode(10001, lang('param_error'));
  719. }
  720. $url = 'https://api.map.baidu.com/direction?region=' . urlencode($region) . '&origin=latlng:' . $o_lat . ',' . $o_lng . '|name:' . urlencode($o_name) . '&destination=latlng:' . $d_lat . ',' . $d_lng . '|name:' . urlencode($d_name) . '&mode=driving&output=html&src=' . urlencode(config('ds_config.h5_site_url'));
  721. $ci = curl_init();
  722. /* Curl settings */
  723. curl_setopt($ci, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
  724. curl_setopt($ci, CURLOPT_USERAGENT, "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1");
  725. curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 60); /* 在发起连接前等待的时间,如果设置为0,则无限等待 */
  726. curl_setopt($ci, CURLOPT_TIMEOUT, 7); /* 设置cURL允许执行的最长秒数 */
  727. curl_setopt($ci, CURLOPT_RETURNTRANSFER, true);
  728. curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'GET'); /* //设置请求方式 */
  729. curl_setopt($ci, CURLOPT_URL, $url);
  730. curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, FALSE); // https请求 不验证证书和hosts
  731. curl_setopt($ci, CURLOPT_SSL_VERIFYHOST, FALSE); // 不从证书中检查SSL加密算法是否存在
  732. //curl_setopt($ci, CURLOPT_HEADER, true); /*启用时会将头文件的信息作为数据流输出*/
  733. // curl_setopt($ci, CURLOPT_FOLLOWLOCATION, 1);
  734. curl_setopt($ci, CURLOPT_MAXREDIRS, 2);/*指定最多的HTTP重定向的数量,这个选项是和CURLOPT_FOLLOWLOCATION一起使用的*/
  735. curl_setopt($ci, CURLINFO_HEADER_OUT, true);
  736. /*curl_setopt($ci, CURLOPT_COOKIE, $Cookiestr); * *COOKIE带过去** */
  737. $response = curl_exec($ci);
  738. $requestinfo = curl_getinfo($ci);
  739. $http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE);
  740. if (isset($requestinfo['redirect_url']) && $requestinfo['redirect_url'] && strpos($requestinfo['redirect_url'], 'http://map.baidu.com/mobile/?third_party=uri_api#s') === 0) {
  741. ds_json_encode(10000, '', array('url' => str_replace("http://map.baidu.com/mobile/?third_party=uri_api#s", "https://map.baidu.com/mobile/webapp/search/search/qt", $requestinfo['redirect_url']) . '/vt=map/?third_party=uri_api'));
  742. } else {
  743. ds_json_encode(10001, lang('ds_common_op_fail'));
  744. }
  745. }
  746. /**
  747. * 店铺流量统计入库
  748. */
  749. public function flowstat_record()
  750. {
  751. $store_model = model('store');
  752. $store_id = intval(input('param.store_id'));
  753. $goods_id = intval(input('param.goods_id'));
  754. $controller_param = input('param.controller_param');
  755. $action_param = input('param.action_param');
  756. $memberId = $this->getMemberIdIfExists();
  757. $store_info = $store_model->getStoreInfo(array(array('member_id', '=', $memberId)));
  758. model('store')->flowstat_record($store_id, $goods_id, $controller_param, $action_param, $store_info);
  759. }
  760. }
  761. class sortClass
  762. {
  763. //升序
  764. public static function sortArrayAsc($preData, $sortType = 'store_sort')
  765. {
  766. $sortData = array();
  767. foreach ($preData as $key_i => $value_i) {
  768. $price_i = isset($value_i[$sortType]) ? $value_i[$sortType] : 0;
  769. $min_key = '';
  770. $sort_total = count($sortData);
  771. foreach ($sortData as $key_j => $value_j) {
  772. $value_j[$sortType] = isset($value_j[$sortType]) ? $value_j[$sortType] : 0;
  773. if ($price_i < $value_j[$sortType]) {
  774. $min_key = $key_j + 1;
  775. break;
  776. }
  777. }
  778. if (empty($min_key)) {
  779. array_push($sortData, $value_i);
  780. } else {
  781. $sortData1 = array_slice($sortData, 0, $min_key - 1);
  782. array_push($sortData1, $value_i);
  783. if (($min_key - 1) < $sort_total) {
  784. $sortData2 = array_slice($sortData, $min_key - 1);
  785. foreach ($sortData2 as $value) {
  786. array_push($sortData1, $value);
  787. }
  788. }
  789. $sortData = $sortData1;
  790. }
  791. }
  792. return $sortData;
  793. }
  794. //降序
  795. public static function sortArrayDesc($preData, $sortType = 'store_sort')
  796. {
  797. $sortData = array();
  798. foreach ($preData as $key_i => $value_i) {
  799. $price_i = isset($value_i[$sortType]) ? $value_i[$sortType] : 0;
  800. $min_key = '';
  801. $sort_total = count($sortData);
  802. foreach ($sortData as $key_j => $value_j) {
  803. $value_j[$sortType] = isset($value_j[$sortType]) ? $value_j[$sortType] : 0;
  804. if ($price_i > $value_j[$sortType]) {
  805. $min_key = $key_j + 1;
  806. break;
  807. }
  808. }
  809. if (empty($min_key)) {
  810. array_push($sortData, $value_i);
  811. } else {
  812. $sortData1 = array_slice($sortData, 0, $min_key - 1);
  813. array_push($sortData1, $value_i);
  814. if (($min_key - 1) < $sort_total) {
  815. $sortData2 = array_slice($sortData, $min_key - 1);
  816. foreach ($sortData2 as $value) {
  817. array_push($sortData1, $value);
  818. }
  819. }
  820. $sortData = $sortData1;
  821. }
  822. }
  823. return $sortData;
  824. }
  825. }