groupbuy_price_range.model.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. /**
  3. * 抢购搜索价格区间模型
  4. *
  5. *
  6. *
  7. *
  8. */
  9. defined('InShopNC') or exit('Access Invalid!');
  10. class groupbuy_price_rangeModel{
  11. //表名
  12. const TABLE_NAME = 'groupbuy_price_range';
  13. //主键
  14. const PK = 'range_id';
  15. /**
  16. * 构造检索条件
  17. *
  18. * @param array $condition 检索条件
  19. * @return string
  20. */
  21. private function getCondition($condition){
  22. $condition_str = '';
  23. if (!empty($condition['range_id'])){
  24. $condition_str .= " AND range_id = '".$condition['range_id']."'";
  25. }
  26. if (!empty($condition['in_range_id'])){
  27. $condition_str .= " AND range_id in (". $condition['in_range_id'] .")";
  28. }
  29. return $condition_str;
  30. }
  31. /**
  32. * 读取列表
  33. *
  34. */
  35. public function getList($condition = array(), $page = ''){
  36. $param = array() ;
  37. $param['table'] = self::TABLE_NAME ;
  38. $param['where'] = $this->getCondition($condition);
  39. $param['order'] = $condition['order'] ? $condition['order']: ' '.self::PK.' desc ';
  40. return Db::select($param,$page);
  41. }
  42. /**
  43. * 根据编号获取单个内容
  44. *
  45. * @param int 主键编号
  46. * @return array 数组类型的返回结果
  47. */
  48. public function getOne($id){
  49. if (intval($id) > 0){
  50. $param = array();
  51. $param['table'] = self::TABLE_NAME;
  52. $param['field'] = self::PK;
  53. $param['value'] = intval($id);
  54. $result = Db::getRow($param);
  55. return $result;
  56. }else {
  57. return false;
  58. }
  59. }
  60. /*
  61. * 判断是否存在
  62. * @param array $condition
  63. * @param obj $page //分页对象
  64. * @return array
  65. */
  66. public function isExist($condition='') {
  67. $param = array() ;
  68. $param['table'] = self::TABLE_NAME ;
  69. $param['where'] = $this->getCondition($condition);
  70. $list = Db::select($param);
  71. if(empty($list)) {
  72. return false;
  73. }
  74. else {
  75. return true;
  76. }
  77. }
  78. /*
  79. * 增加
  80. * @param array $param
  81. * @return bool
  82. */
  83. public function save($param){
  84. return Db::insert(self::TABLE_NAME,$param) ;
  85. }
  86. /*
  87. * 更新
  88. * @param array $update_array
  89. * @param array $where_array
  90. * @return bool
  91. */
  92. public function update($update_array, $where_array){
  93. $where = $this->getCondition($where_array) ;
  94. return Db::update(self::TABLE_NAME,$update_array,$where) ;
  95. }
  96. /*
  97. * 删除
  98. * @param array $param
  99. * @return bool
  100. */
  101. public function drop($param){
  102. $where = $this->getCondition($param) ;
  103. return Db::delete(self::TABLE_NAME, $where) ;
  104. }
  105. }