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