Store.php 39 KB

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