FrontModel.class.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. <?php
  2. namespace Home\Model;
  3. use Think\Model;
  4. /**
  5. * 圈子模型
  6. * @author fish
  7. *
  8. */
  9. class FrontModel {
  10. public $table = 'pin';
  11. public function get_member_community_info($member_id)
  12. {
  13. $head_info = M('lionfish_community_head')->where( array('member_id' => $member_id) )->find();
  14. return $head_info;
  15. }
  16. public function get_community_byid($community_id, $where="")
  17. {
  18. $data = array();
  19. $data['communityId'] = $community_id;
  20. $community_info = M('lionfish_community_head')->where( "id=".$community_id.' '.$where )->find();
  21. if(!empty($community_info)){
  22. $data['communityName'] = $community_info['community_name'];
  23. $province = $this->get_area_info($community_info['province_id']);
  24. $city = $this->get_area_info($community_info['city_id']);
  25. $area = $this->get_area_info($community_info['area_id']);
  26. $country = $this->get_area_info($community_info['country_id']);
  27. //address
  28. $full_name = $province['name'].$city['name'].$area['name'].$country['name'].$community_info['address'];
  29. $data['fullAddress'] = $full_name;
  30. $data['communityAddress'] = '';
  31. $mb_info = M('lionfish_comshop_member')->field('avatar,username')->where( array('member_id' => $community_info['member_id'] ) )->find();
  32. $data['headImg'] = $mb_info['avatar'];
  33. $data['disUserHeadImg'] = $mb_info['avatar'];
  34. $data['disUserName'] = $community_info['head_name'];
  35. $data['head_mobile'] = $community_info['head_mobile'];
  36. $data['province'] = $province['name'];
  37. $data['city'] = $city['name'];
  38. $data['lon'] = $community_info['lon'];
  39. $data['lat'] = $community_info['lat'];
  40. $data['headDoorphoto'] = $community_info['head_doorphoto']?tomedia($community_info['head_doorphoto']):"";
  41. return $data;
  42. } else {
  43. return '';
  44. }
  45. }
  46. /**
  47. * 获取历史的社区
  48. */
  49. public function get_history_community($member_id)
  50. {
  51. $history_community = M('lionfish_community_history')->where( "head_id>0 and member_id={$member_id}" )->order('addtime desc')->find();
  52. $data = array();
  53. if(!empty($history_community))
  54. {
  55. $data['communityId'] = $history_community['head_id'];
  56. $community_info = M('lionfish_community_head')->where( array('id' => $history_community['head_id'] ) )->find();
  57. $data['communityName'] = $community_info['community_name'];
  58. $province = $this->get_area_info($community_info['province_id']);
  59. $city = $this->get_area_info($community_info['city_id']);
  60. $area = $this->get_area_info($community_info['area_id']);
  61. $country = $this->get_area_info($community_info['country_id']);
  62. //address
  63. $full_name = $province['name'].$city['name'].$area['name'].$country['name'].$community_info['address'];
  64. $data['fullAddress'] = $full_name;
  65. $data['communityAddress'] = '';
  66. $mb_info = M('lionfish_comshop_member')->field('avatar,username')->where( array('member_id' => $community_info['member_id'] ) )->find();
  67. $data['headImg'] = $mb_info['avatar'];
  68. $data['disUserHeadImg'] = $mb_info['avatar'];
  69. //$data['disUserName'] = $mb_info['username'];
  70. $data['disUserName'] = $community_info['head_name'];
  71. $data['disUserMobile'] = $community_info['head_mobile'];
  72. $data['lon'] = $community_info['lon'];
  73. $data['lat'] = $community_info['lat'];
  74. $data['headDoorphoto'] = $community_info['head_doorphoto']?tomedia($community_info['head_doorphoto']):"";
  75. }
  76. return $data;
  77. }
  78. /**
  79. * 切换历史社区
  80. */
  81. public function update_history_community($member_id, $head_id){
  82. $history_community = M('lionfish_community_history')->where( array('member_id' => $member_id) )->order('id desc')->find();
  83. if( empty($history_community) )
  84. {
  85. $ins_data = array();
  86. $ins_data['member_id'] = $member_id;
  87. $ins_data['head_id'] = $head_id;
  88. $ins_data['addtime'] = time();
  89. M('lionfish_community_history')->add($ins_data);
  90. }else{
  91. M('lionfish_community_history')->where( array('id' => $history_community['id']) )->save( array('addtime' => time() , 'head_id' => $head_id ) );
  92. }
  93. return "success";
  94. }
  95. /**
  96. 根据经纬度获取位置信息
  97. get_gps_area_info($longitude,$latitude,$limit);
  98. **/
  99. public function get_gps_area_info($longitude,$latitude,$limit=10,$keyword='',$city_id=0, $rest=0)
  100. {
  101. //$where = " and state =1 ";
  102. $where = " and state =1 and enable =1 ";
  103. if( $city_id != 0 )
  104. {
  105. $where .= " and city_id = ".$city_id;
  106. }
  107. if( $rest != 0 )
  108. {
  109. $where .= " and rest != 1";
  110. }
  111. if( !empty($keyword) )
  112. {
  113. $where .= " and community_name like '%{$keyword}%' ";
  114. }
  115. // having distance <= 10000距离限制 default_comunity_limit_mile
  116. $limit_mile = $this->get_config_by_name('default_comunity_limit_mile');
  117. $limit_where = '';
  118. if(isset($limit_mile) && !empty($limit_mile) && floatval($limit_mile>0))
  119. $limit_where = 'having distance <= '.floatval($limit_mile)*1000;
  120. $sql = "select a.*,b.avatar,b.username, 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
  121. FROM ".C('DB_PREFIX')."lionfish_community_head as a, ".C('DB_PREFIX')."lionfish_comshop_member as b where a.member_id = b.member_id {$where}{$limit_where} order by distance asc limit {$limit}";
  122. $list = M()->query($sql);
  123. $result = array();
  124. if( !empty($list) )
  125. {
  126. foreach($list as $val)
  127. {
  128. // $mb_info = M('lionfish_comshop_member')->field('avatar,username')->where( array('member_id' => $val['member_id'] ) )->find();
  129. // if(empty($mb_info)) continue;
  130. $tmp_arr = array();
  131. $tmp_arr['communityId'] = $val['id'];
  132. $tmp_arr['communityName'] = $val['community_name'];
  133. $province = $this->get_area_info($val['province_id']);
  134. $city = $this->get_area_info($val['city_id']);
  135. $area = $this->get_area_info($val['area_id']);
  136. $country = $this->get_area_info($val['country_id']);
  137. //address
  138. $full_name = $province['name'].$city['name'].$area['name'].$country['name'].$val['address'];
  139. $tmp_arr['fullAddress'] = $full_name;
  140. $tmp_arr['communityAddress'] = '';
  141. $tmp_arr['disUserName'] = $val['head_name'];
  142. //ims_
  143. $tmp_arr['headImg'] = $val['avatar'];
  144. $tmp_arr['disUserHeadImg'] = '';
  145. $tmp_arr['rest'] = $val['rest'];
  146. $tmp_arr['lat'] = $val['lat'];
  147. $tmp_arr['lon'] = $val['lon'];
  148. $distance = $val['distance'];
  149. if($distance >1000)
  150. {
  151. $distance = round($distance/1000,2).'公里';
  152. }else{
  153. $distance = $distance.'米';
  154. }
  155. $tmp_arr['distance'] = $distance;
  156. $result[] = $tmp_arr;
  157. }
  158. }
  159. return $result;
  160. }
  161. public function get_area_info($id)
  162. {
  163. $area_info = M('lionfish_comshop_area')->where( array('id' => $id) )->find();
  164. return $area_info;
  165. }
  166. public function get_area_ninfo_by_name($name)
  167. {
  168. $area_info = M('lionfish_comshop_area')->where( array('name' => $name) )->find();
  169. return $area_info;
  170. }
  171. //$order_comment_count = M('order_comment')->where( array('goods_id' => $id, 'state' => 1) )->count();
  172. /**
  173. 检查商品限购数量
  174. **/
  175. public function check_goods_user_canbuy_count($member_id, $goods_id, $unlimit_wait_pay = false)
  176. {
  177. //per_number
  178. global $_W;
  179. global $_GPC;
  180. $goods_desc = $this->get_goods_common_field($goods_id , 'total_limit_count,one_limit_count');
  181. //$per_number = $goods_desc['per_number'];
  182. if($goods_desc['total_limit_count'] > 0 || $goods_desc['one_limit_count'] > 0)
  183. {
  184. $limit_state = '1,2,3,4,6,7,9,11,12,13,14';
  185. if($unlimit_wait_pay)
  186. {
  187. $limit_state = '1,2,4,6,7,9,11,12,13,14';
  188. }
  189. $sql = "SELECT sum(og.quantity) as count FROM " .C('DB_PREFIX') . "lionfish_comshop_order as o,
  190. " .C('DB_PREFIX') . "lionfish_comshop_order_goods as og where o.order_id = og.order_id and og.goods_id =" . (int)$goods_id ."
  191. and o.member_id = {$member_id} and o.order_status_id in ({$limit_state}) ";
  192. $buy_count_arr = M()->query($sql);
  193. $buy_count = $buy_count_arr[0]['count'];
  194. if( $goods_desc['one_limit_count'] > 0 && $goods_desc['total_limit_count'] > 0)
  195. {
  196. if($buy_count >= $goods_desc['total_limit_count'])
  197. {
  198. return -1;
  199. }else{
  200. $total_max_count = $goods_desc['total_limit_count'] - $buy_count;
  201. $can_buy = $total_max_count < $goods_desc['one_limit_count'] ? $total_max_count : $goods_desc['one_limit_count'];
  202. return $can_buy;
  203. }
  204. }else if($goods_desc['one_limit_count'] > 0){
  205. return $goods_desc['one_limit_count'];
  206. }else if($goods_desc['total_limit_count'] > 0){
  207. if($buy_count >= $goods_desc['total_limit_count'])
  208. {
  209. return -1;
  210. } else {
  211. return ($goods_desc['total_limit_count'] - $buy_count);
  212. }
  213. }
  214. } else{
  215. return 0;
  216. }
  217. }
  218. /**
  219. 检查商品历史限购数量
  220. **/
  221. public function check_goods_user_canbuy_all_count($member_id, $goods_id, $unlimit_wait_pay = false)
  222. {
  223. //per_number
  224. global $_W;
  225. global $_GPC;
  226. $goods_desc = $this->get_goods_common_field($goods_id , 'total_limit_count,one_limit_count');
  227. if($goods_desc['total_limit_count'] > 0)
  228. {
  229. $limit_state = '1,2,3,4,6,7,9,11,12,13,14';
  230. if($unlimit_wait_pay)
  231. {
  232. $limit_state = '1,2,4,6,7,9,11,12,13,14';
  233. }
  234. $sql = "SELECT sum(og.quantity) as count FROM " .C('DB_PREFIX') . "lionfish_comshop_order as o,
  235. " .C('DB_PREFIX') . "lionfish_comshop_order_goods as og where o.order_id = og.order_id and og.goods_id =" . (int)$goods_id ."
  236. and o.member_id = {$member_id} and o.order_status_id in ({$limit_state}) ";
  237. $buy_count_arr = M()->query($sql);
  238. $buy_count = $buy_count_arr[0]['count'];
  239. if($buy_count >= $goods_desc['total_limit_count'])
  240. {
  241. return -1;
  242. }else{
  243. $total_max_count = $goods_desc['total_limit_count'] - $buy_count;
  244. return $total_max_count;
  245. }
  246. } else{
  247. return 0;
  248. }
  249. }
  250. /**
  251. * 检查每单商品限购数量
  252. * @param $member_id
  253. * @param $goods_id
  254. * @param bool|false $unlimit_wait_pay
  255. */
  256. public function check_goods_user_canbuy_one_count($member_id, $goods_id, $unlimit_wait_pay = false){
  257. //per_number
  258. global $_W;
  259. global $_GPC;
  260. $goods_desc = $this->get_goods_common_field($goods_id , 'one_limit_count');
  261. if($goods_desc['one_limit_count'] > 0)
  262. {
  263. $limit_state = '1,2,3,4,6,7,9,11,12,13,14';
  264. if($unlimit_wait_pay)
  265. {
  266. $limit_state = '1,2,4,6,7,9,11,12,13,14';
  267. }
  268. $sql = "SELECT sum(og.quantity) as count FROM " .C('DB_PREFIX') . "lionfish_comshop_order as o,
  269. " .C('DB_PREFIX') . "lionfish_comshop_order_goods as og where o.order_id = og.order_id and og.goods_id =" . (int)$goods_id ."
  270. and o.member_id = {$member_id} and o.order_status_id in ({$limit_state}) ";
  271. $buy_count_arr = M()->query($sql);
  272. $buy_count = $buy_count_arr[0]['count'];
  273. if($buy_count >= $goods_desc['one_limit_count']){
  274. return -1;
  275. }else{
  276. return ($goods_desc['one_limit_count'] - $buy_count);
  277. }
  278. } else{
  279. return 0;
  280. }
  281. }
  282. /**
  283. 检查每日商品限购数量
  284. **/
  285. public function check_goods_user_canbuy_day_count($member_id, $goods_id, $unlimit_wait_pay = false)
  286. {
  287. //per_number
  288. global $_W;
  289. global $_GPC;
  290. $goods_desc = $this->get_goods_common_field($goods_id , 'oneday_limit_count');
  291. if($goods_desc['oneday_limit_count'] > 0)
  292. {
  293. $limit_state = '1,2,3,4,6,7,9,11,12,13,14';
  294. if($unlimit_wait_pay)
  295. {
  296. $limit_state = '1,2,4,6,7,9,11,12,13,14';
  297. }
  298. $time = strtotime("today");
  299. $sql = "SELECT sum(og.quantity) as count FROM " .C('DB_PREFIX') . "lionfish_comshop_order as o,
  300. " .C('DB_PREFIX') . "lionfish_comshop_order_goods as og where o.order_id = og.order_id and og.goods_id =" . (int)$goods_id ."
  301. and o.member_id = {$member_id} and o.order_status_id in ({$limit_state}) and date_added >= {$time} ";
  302. $buy_day_count_arr = M()->query($sql);
  303. $buy_day_count = isset($buy_day_count_arr[0]['count']) ? $buy_day_count_arr[0]['count'] : 0;
  304. if($buy_day_count >= $goods_desc['oneday_limit_count'])
  305. {
  306. return -1;
  307. }else{
  308. return $goods_desc['oneday_limit_count'] - $buy_day_count;
  309. }
  310. } else{
  311. return 0;
  312. }
  313. }
  314. /**
  315. 获取规格图片
  316. **/
  317. public function get_goods_sku_item_image($option_item_ids)
  318. {
  319. $option_item_ids = explode('_', $option_item_ids);
  320. $ids_str = implode(',', $option_item_ids);
  321. $image_info = M('lionfish_comshop_goods_option_item')->field('thumb')->where("id in ({$ids_str}) and thumb != ''")->find();
  322. return $image_info;
  323. }
  324. /**
  325. 获取商品规格图片
  326. **/
  327. public function get_goods_sku_image($snailfish_goods_option_item_value_id)
  328. {
  329. $info = M('lionfish_comshop_goods_option_item_value')->field('option_item_ids')->where( array('id' => $snailfish_goods_option_item_value_id) )->find();
  330. $option_item_ids = explode('_', $info['option_item_ids']);
  331. $ids_str = implode(',', $option_item_ids);
  332. $image_info = M('lionfish_comshop_goods_option_item')->field('thumb')->where("id in ({$ids_str}) and uniacid=:uniacid and thumb != ''")->find();
  333. return $image_info;
  334. }
  335. public function get_goods_supply_id($goods_id)
  336. {
  337. $supply_id = 0;
  338. $gd_info = $this->get_goods_common_field($goods_id , 'supply_id');
  339. if(!empty($gd_info))
  340. {
  341. return $gd_info['supply_id'];
  342. }else{
  343. return 0;
  344. }
  345. }
  346. public function get_supply_info($supply_id)
  347. {
  348. $supply_info = M('lionfish_comshop_supply')->where( array('id' => $supply_id ) )->find();
  349. return $supply_info;
  350. }
  351. public function get_config_by_name($name)
  352. {
  353. //oscshop_lionfish_comshop_config
  354. $data = $caceh_data = S('_get_all_config');
  355. if( !empty($data) && isset($data[$name]) )
  356. {
  357. return $data[$name];
  358. }else{
  359. $info = M('lionfish_comshop_config')->where( array('name' => $name) )->find();
  360. return $info['value'];
  361. }
  362. }
  363. public function get_supply_config_by_name($name,$supply_id)
  364. {
  365. //oscshop_lionfish_comshop_config
  366. $data = $caceh_data = S('_get_all_supply_config_'.$supply_id);
  367. if( !empty($data) && isset($data[$name]) )
  368. {
  369. return $data[$name];
  370. }else{
  371. $info = M('lionfish_comshop_supply_config')->where( array('name' => $name,'supply_id' => $supply_id) )->find();
  372. return $info['value'];
  373. }
  374. }
  375. public function get_goods_common_field($goods_id , $filed='*')
  376. {
  377. $info = M('lionfish_comshop_good_common')->field($filed)->where( array('goods_id' => $goods_id) )->find();
  378. return $info;
  379. }
  380. /*
  381. * 获取全部满减数据
  382. */
  383. public function get_fullreduction(){
  384. $list = array();
  385. $data = D('Seller/Config')->get_all_config();
  386. for($i = 1;$i <= 5;$i++){
  387. $fulls = array();
  388. if($i == 1){
  389. $fulls['full_money'] = $data['full_money'];
  390. $fulls['full_reducemoney'] = $data['full_reducemoney'];
  391. $list[] = $fulls;
  392. }else{
  393. if(isset($data['full_money_'.$i]) && !empty($data['full_money_'.$i])){
  394. $fulls['full_money'] = $data['full_money_'.$i];
  395. $fulls['full_reducemoney'] = $data['full_reducemoney_'.$i];
  396. $list[] = $fulls;
  397. }
  398. }
  399. }
  400. return $list;
  401. }
  402. /**
  403. * 获取金额对应满减金额或者差额
  404. */
  405. public function get_reduce_money($man_total_free){
  406. $result = array();
  407. $cha_reduce_money = 0;
  408. $reduce_money = 0;
  409. $full_list = $this->get_fullreduction();
  410. for($i = 0;$i < count($full_list);$i++){
  411. if($i == 0 && $man_total_free < $full_list[$i]['full_money']){
  412. $cha_reduce_money = $full_list[$i]['full_money'] - $man_total_free;
  413. break;
  414. }else{
  415. if($i < count($full_list)-1){
  416. if($man_total_free >= $full_list[$i]['full_money'] && $man_total_free < $full_list[$i+1]['full_money']){
  417. $reduce_money = $full_list[$i]['full_reducemoney'];
  418. break;
  419. }
  420. }else{
  421. if($man_total_free >= $full_list[$i]['full_money']){
  422. $reduce_money = $full_list[$i]['full_reducemoney'];
  423. break;
  424. }
  425. }
  426. }
  427. }
  428. $result['cha_reduce_money'] = $cha_reduce_money;
  429. $result['reduce_money'] = $reduce_money;
  430. return $result;
  431. }
  432. /**
  433. * @author cy 2021-04-27
  434. * @desc 判断是否使用货到付款方式
  435. * @param $buy_type
  436. * @param $seller_goodss
  437. * @return array
  438. */
  439. public function getCashonDeliveryAction($buy_type, $seller_goodss){
  440. $cashondelivery_data = array();
  441. $is_supply = 0;
  442. foreach($seller_goodss as $k=>$v){
  443. if($k > 0){
  444. $is_supply = 1;
  445. break;
  446. }
  447. }
  448. if($buy_type == 'dan' && $is_supply == 0){//普通订单且没有独立供应商商品 可以使用 货到付款 支付方式
  449. $isopen_cashondelivery = $this->get_config_by_name('isopen_cashondelivery');//是否开启货到付款
  450. $isopen_cashondelivery = empty($isopen_cashondelivery) ? 0 : 1;
  451. $isopen_cashondelivery_communityhead = $this->get_config_by_name('isopen_cashondelivery_communityhead');//团长配送模式
  452. $isopen_cashondelivery_communityhead = empty($isopen_cashondelivery_communityhead) ? 0 : 1;
  453. $isopen_cashondelivery_ziti = empty($isopen_cashondelivery_communityhead) ? 0 : 1;
  454. $isopen_cashondelivery_express = $this->get_config_by_name('isopen_cashondelivery_express');//仅快递模式
  455. $isopen_cashondelivery_express = empty($isopen_cashondelivery_express) ? 0 : 1;
  456. $isopen_cashondelivery_localtown = $this->get_config_by_name('isopen_cashondelivery_localtown');//同城配送模式
  457. $isopen_cashondelivery_localtown = empty($isopen_cashondelivery_localtown) ? 0 : 1;
  458. $isopen_cashondelivery_hexiao = $this->get_config_by_name('isopen_cashondelivery_hexiao');//到店核销
  459. $isopen_cashondelivery_hexiao = empty($isopen_cashondelivery_hexiao) ? 0 : 1;
  460. }else{
  461. $isopen_cashondelivery = 0;
  462. $isopen_cashondelivery_communityhead = 0;
  463. $isopen_cashondelivery_express = 0;
  464. $isopen_cashondelivery_localtown = 0;
  465. $isopen_cashondelivery_hexiao = 0;
  466. $isopen_cashondelivery_ziti = 0;
  467. }
  468. $cashondelivery_data['isopen_cashondelivery'] = $isopen_cashondelivery;
  469. $cashondelivery_data['isopen_cashondelivery_communityhead'] = $isopen_cashondelivery_communityhead;
  470. $cashondelivery_data['isopen_cashondelivery_express'] = $isopen_cashondelivery_express;
  471. $cashondelivery_data['isopen_cashondelivery_localtown'] = $isopen_cashondelivery_localtown;
  472. $cashondelivery_data['isopen_cashondelivery_hexiao'] = $isopen_cashondelivery_hexiao;
  473. $cashondelivery_data['isopen_cashondelivery_ziti'] = $isopen_cashondelivery_ziti;
  474. return $cashondelivery_data;
  475. }
  476. /**
  477. * @author cy 2021-04-28
  478. * @desc 获取货到付款码
  479. * @return string
  480. */
  481. public function getCashonDeliveryCode(){
  482. $code_img = "";
  483. //$isopen_cashondelivery = $this->get_config_by_name('isopen_cashondelivery');//是否开启货到付款
  484. $isopen_cashondelivery_code = $this->get_config_by_name('isopen_cashondelivery_code');//是否开启“货到付款”收款码
  485. $cashondelivery_code_img = $this->get_config_by_name('cashondelivery_code_img');//“货到付款”收款码图片
  486. if($isopen_cashondelivery_code == 1 && !empty($cashondelivery_code_img)){
  487. $code_img = tomedia($cashondelivery_code_img);
  488. }
  489. return $code_img;
  490. }
  491. }