FrontModel.class.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. * ==========================================================================
  6. * @link http://www.liofis.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license http://www.liofis.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author fish
  12. *
  13. */
  14. namespace Seller\Model;
  15. class FrontModel{
  16. public function get_member_community_info($member_id)
  17. {
  18. $head_info = M('lionfish_community_head')->where( array('member_id' => $member_id ) )->find();
  19. return $head_info;
  20. }
  21. public function get_community_byid($community_id)
  22. {
  23. $data = array();
  24. $data['communityId'] = $community_id;
  25. $community_info = M('lionfish_community_head')->where( array('id' => $community_id) )->find();
  26. $data['communityName'] = $community_info['community_name'];
  27. $province = $this->get_area_info($community_info['province_id']);
  28. $city = $this->get_area_info($community_info['city_id']);
  29. $area = $this->get_area_info($community_info['area_id']);
  30. $country = $this->get_area_info($community_info['country_id']);
  31. //address
  32. $full_name = $province['name'].$city['name'].$area['name'].$country['name'].$community_info['address'];
  33. $data['fullAddress'] = $full_name;
  34. $data['communityAddress'] = '';
  35. $mb_info = M('lionfish_comshop_member')->where( array('member_id' => $community_info['member_id'] ) )->find();
  36. $data['headImg'] = $mb_info['avatar'];
  37. $data['disUserHeadImg'] = $mb_info['avatar'];
  38. $data['disUserName'] = $community_info['head_name'];
  39. $data['head_mobile'] = $community_info['head_mobile'];
  40. $data['province'] = $province['name'];
  41. $data['city'] = $city['name'];
  42. return $data;
  43. }
  44. /**
  45. * 获取历史的社区
  46. */
  47. public function get_history_community($member_id)
  48. {
  49. $history_community = M('lionfish_community_history')->where( "head_id>0 and member_id={$member_id}" )->order('id desc')->find();
  50. $data = array();
  51. if(!empty($history_community))
  52. {
  53. $data['communityId'] = $history_community['head_id'];
  54. $community_info = M('lionfish_community_head')->where( array('id' => $history_community['head_id'] ) )->find();
  55. $data['communityName'] = $community_info['community_name'];
  56. $province = $this->get_area_info($community_info['province_id']);
  57. $city = $this->get_area_info($community_info['city_id']);
  58. $area = $this->get_area_info($community_info['area_id']);
  59. $country = $this->get_area_info($community_info['country_id']);
  60. //address
  61. $full_name = $province['name'].$city['name'].$area['name'].$country['name'].$community_info['address'];
  62. $data['fullAddress'] = $full_name;
  63. $data['communityAddress'] = '';
  64. $mb_info = M('lionfish_comshop_member')->field('avatar,username')->where( array('member_id' => $community_info['member_id'] ) )->find();
  65. $data['headImg'] = $mb_info['avatar'];
  66. $data['disUserHeadImg'] = $mb_info['avatar'];
  67. //$data['disUserName'] = $mb_info['username'];
  68. $data['disUserName'] = $community_info['head_name'];
  69. }
  70. return $data;
  71. }
  72. /**
  73. * 切换历史社区
  74. */
  75. public function update_history_community($member_id, $head_id){
  76. global $_W;
  77. global $_GPC;
  78. $uniacid = $_W['uniacid'];
  79. $history_community = M('lionfish_community_history')->where( array('member_id' => $member_id ) )->order('id desc')->find();
  80. if( empty($history_community) )
  81. {
  82. $ins_data = array();
  83. $ins_data['member_id'] = $member_id;
  84. $ins_data['head_id'] = $head_id;
  85. $ins_data['addtime'] = time();
  86. M('lionfish_community_history')->add($ins_data);
  87. }else{
  88. M('lionfish_community_history')->where( array('id' => $history_community['id']) )->save(array('head_id' => $head_id));
  89. }
  90. return "success";
  91. }
  92. /**
  93. 根据经纬度获取位置信息
  94. get_gps_area_info($longitude,$latitude,$limit);
  95. **/
  96. public function get_gps_area_info($longitude,$latitude,$limit=10,$keyword='',$city_id=0)
  97. {
  98. global $_W;
  99. global $_GPC;
  100. $where = " and state =1 ";
  101. if( $city_id != 0 )
  102. {
  103. $where = " and city_id = ".$city_id;
  104. }
  105. if( !empty($keyword) )
  106. {
  107. $where = " and community_name like '%{$keyword}%' ";
  108. }
  109. $sql = "select *, ROUND(6378.138*2*ASIN(SQRT(POW(SIN(({$latitude}*PI()/180-lat*PI()/180)/2),2)+COS({$latitude}*PI()/180)*COS(lat*PI()/180)*POW(SIN(({$longitude}*PI()/180-lon*PI()/180)/2),2)))*1000) AS distance
  110. FROM ".C('DB_PREFIX')."lionfish_community_head where member_id !=0 {$where} order by distance asc limit {$limit}";
  111. $list = M()->query($sql);
  112. $result = array();
  113. if( !empty($list) )
  114. {
  115. foreach($list as $val)
  116. {
  117. $mb_info = M('lionfish_comshop_member')->field('avatar,username')->where( array('member_id' => $val['member_id']) )->find();
  118. if(empty($mb_info)) continue;
  119. $tmp_arr = array();
  120. $tmp_arr['communityId'] = $val['id'];
  121. $tmp_arr['communityName'] = $val['community_name'];
  122. $province = $this->get_area_info($val['province_id']);
  123. $city = $this->get_area_info($val['city_id']);
  124. $area = $this->get_area_info($val['area_id']);
  125. $country = $this->get_area_info($val['country_id']);
  126. //address
  127. $full_name = $province['name'].$city['name'].$area['name'].$country['name'].$val['address'];
  128. $tmp_arr['fullAddress'] = $full_name;
  129. $tmp_arr['communityAddress'] = '';
  130. $tmp_arr['disUserName'] = $val['head_name'];
  131. //ims_
  132. $tmp_arr['headImg'] = $mb_info['avatar'];
  133. $tmp_arr['disUserHeadImg'] = '';
  134. $distance = $val['distance'];
  135. if($distance >1000)
  136. {
  137. $distance = round($distance/1000,2).'公里';
  138. }else{
  139. $distance = $distance.'米';
  140. }
  141. $tmp_arr['distance'] = $distance;
  142. $result[] = $tmp_arr;
  143. }
  144. }
  145. return $result;
  146. }
  147. public function get_area_info($id)
  148. {
  149. $area_info = M('lionfish_comshop_area')->where( array('id' => $id ) )->find();
  150. return $area_info;
  151. }
  152. public function get_area_ninfo_by_name($name)
  153. {
  154. $area_info = M('lionfish_comshop_area')->where( array('name' => $name ) )->find();
  155. return $area_info;
  156. // lionfish_comshop_area
  157. }
  158. public function get_config_by_name($name)
  159. {
  160. $info = M('lionfish_comshop_config')->where( array('name' => $name) )->find();
  161. return $info['value'];
  162. }
  163. //$order_comment_count = M('order_comment')->where( array('goods_id' => $id, 'state' => 1) )->count();
  164. public function get_goods_common_field($goods_id , $filed='*')
  165. {
  166. $info = M('lionfish_comshop_good_common')->field($filed)->where( array('goods_id' => $goods_id ) )->find();
  167. return $info;
  168. }
  169. /**
  170. 检查商品限购数量
  171. **/
  172. public function check_goods_user_canbuy_count($member_id, $goods_id)
  173. {
  174. $goods_desc = $this->get_goods_common_field($goods_id , 'total_limit_count,one_limit_count');
  175. if($goods_desc['total_limit_count'] > 0 || $goods_desc['one_limit_count'] > 0)
  176. {
  177. $sql = "SELECT sum(og.quantity) as count FROM " .C('DB_PREFIX'). "lionfish_comshop_order as o,
  178. " .C('DB_PREFIX'). "lionfish_comshop_order_goods as og where o.order_id = og.order_id and og.goods_id =" . (int)$goods_id ."
  179. and o.member_id = {$member_id} and o.order_status_id in (1,2,3,4,6,7,9,11,12,13,14)";
  180. $total_arr = M()->query($sql);
  181. $buy_count = $total_arr[0]['count'];
  182. if( $goods_desc['one_limit_count'] > 0 && $goods_desc['total_limit_count'] > 0)
  183. {
  184. if($buy_count >= $goods_desc['total_limit_count'])
  185. {
  186. return -1;
  187. }else{
  188. $total_max_count = $goods_desc['total_limit_count'] - $buy_count;
  189. $can_buy = $total_max_count < $goods_desc['one_limit_count'] ? $total_max_count : $goods_desc['one_limit_count'];
  190. return $can_buy;
  191. }
  192. }else if($goods_desc['one_limit_count'] > 0){
  193. return $goods_desc['one_limit_count'];
  194. }else if($goods_desc['total_limit_count'] > 0){
  195. if($buy_count >= $goods_desc['total_limit_count'])
  196. {
  197. return -1;
  198. } else {
  199. return ($goods_desc['total_limit_count'] - $buy_count);
  200. }
  201. }
  202. } else{
  203. return 0;
  204. }
  205. }
  206. /**
  207. 获取规格图片
  208. **/
  209. public function get_goods_sku_item_image($option_item_ids)
  210. {
  211. global $_W;
  212. global $_GPC;
  213. $option_item_ids = explode('_', $option_item_ids);
  214. $ids_str = implode(',', $option_item_ids);
  215. $image_info = M('lionfish_comshop_goods_option_item')->field('thumb')->where("id in ({$ids_str}) and thumb != ''")->find();
  216. return $image_info;
  217. }
  218. /**
  219. 获取商品规格图片
  220. **/
  221. public function get_goods_sku_image($snailfish_goods_option_item_value_id)
  222. {
  223. $info = M('lionfish_comshop_goods_option_item_value')->field('option_item_ids')->where( array('id' => $snailfish_goods_option_item_value_id) )->find();
  224. $option_item_ids = explode('_', $info['option_item_ids']);
  225. $ids_str = implode(',', $option_item_ids);
  226. $image_info = M('lionfish_comshop_goods_option_item')->field('thumb')->where("id in ({$ids_str}) and thumb != ''")->find();
  227. return $image_info;
  228. }
  229. }
  230. ?>