Store.php 39 KB

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