flea_favorites.model.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /**
  3. * 买家收藏
  4. *by 3 3hao .com
  5. */
  6. defined('InShopNC') or exit('Access Invalid!');
  7. class flea_favoritesModel{
  8. /**
  9. * 收藏列表
  10. *
  11. * @param array $condition 检索条件
  12. * @param obj $obj_page 分页对象
  13. * @return array 数组类型的返回结果
  14. */
  15. public function getFavoritesList($condition,$page = ''){
  16. $condition_str = $this->_condition($condition);
  17. $param = array(
  18. 'table'=>'flea_favorites',
  19. 'where'=>$condition_str,
  20. 'order'=>$condition['order'] ? $condition['order'] : 'fav_time desc'
  21. );
  22. $result = Db::select($param,$page);
  23. return $result;
  24. }
  25. /**
  26. * 构造检索条件
  27. *
  28. * @param array $condition 检索条件
  29. * @return string 字符串类型的返回结果
  30. */
  31. public function _condition($condition){
  32. $condition_str = '';
  33. if ($condition['member_id'] != ''){
  34. $condition_str .= " and member_id = '{$condition['member_id']}'";
  35. }
  36. if ($condition['fav_type'] != ''){
  37. $condition_str .= " and fav_type = '{$condition['fav_type']}'";
  38. }
  39. return $condition_str;
  40. }
  41. /**
  42. * 取单个收藏的内容
  43. *
  44. * @param int $fav_id 收藏ID
  45. * @param string $fav_type 收藏类型
  46. * @return array 数组类型的返回结果
  47. */
  48. public function getOneFavorites($fav_id,$type,$member_id){
  49. if (intval($fav_id) > 0){
  50. $param = array();
  51. $param['table'] = 'flea_favorites';
  52. $param['field'] = array('fav_id','fav_type','member_id');
  53. $param['value'] = array(intval($fav_id),$type,$member_id);
  54. $result = Db::getRow($param);
  55. return $result;
  56. }else {
  57. return false;
  58. }
  59. }
  60. /**
  61. * 新增收藏
  62. *
  63. * @param array $param 参数内容
  64. * @return bool 布尔类型的返回结果
  65. */
  66. public function addFavorites($param){
  67. if (empty($param)){
  68. return false;
  69. }
  70. if (is_array($param)){
  71. $tmp = array();
  72. foreach ($param as $k => $v){
  73. $tmp[$k] = $v;
  74. }
  75. $result = Db::insert('flea_favorites',$tmp);
  76. return $result;
  77. }else {
  78. return false;
  79. }
  80. }
  81. /**
  82. * 验证是否为当前用户收藏
  83. *
  84. * @param array $param 条件数据
  85. * @return bool 布尔类型的返回结果
  86. */
  87. public function checkFavorites($fav_id,$fav_type,$member_id){
  88. if (intval($fav_id) == 0 || empty($fav_type) || intval($member_id) == 0){
  89. return true;
  90. }
  91. $result = self::getOneFavorites($fav_id,$fav_type,$member_id);
  92. if ($result['member_id'] == $member_id){
  93. return true;
  94. }else {
  95. return false;
  96. }
  97. }
  98. /**
  99. * 删除
  100. *
  101. * @param int $id 记录ID
  102. * @return array $rs_row 返回数组形式的查询结果
  103. */
  104. public function delFavorites($id,$type){
  105. if (intval($id) > 0 && !empty($type) && self::checkFavorites($id,$type,$_SESSION['member_id'])){
  106. $where = ' `fav_id` = '. intval($id) ." and `fav_type` = '{$type}'";
  107. $result = Db::delete('flea_favorites',$where);
  108. return $result;
  109. }else {
  110. return false;
  111. }
  112. }
  113. }