store_grade.model.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. /**
  3. * 店铺等级模型
  4. *
  5. *
  6. *
  7. *
  8. */
  9. defined('InShopNC') or exit('Access Invalid!');
  10. class store_gradeModel{
  11. /**
  12. * 列表
  13. *
  14. * @param array $condition 检索条件
  15. * @return array 数组结构的返回结果
  16. */
  17. public function getGradeList($condition = array()){
  18. $condition_str = $this->_condition($condition);
  19. $param = array();
  20. $param['table'] = 'store_grade';
  21. $param['where'] = $condition_str;
  22. //$param['order'] = 'sg_id';
  23. $param['order'] = $condition['order']?$condition['order']:'sg_id';
  24. $result = Db::select($param);
  25. return $result;
  26. }
  27. /**
  28. * 构造检索条件
  29. *
  30. * @param int $id 记录ID
  31. * @return string 字符串类型的返回结果
  32. */
  33. private function _condition($condition){
  34. $condition_str = '';
  35. if ($condition['like_sg_name'] != ''){
  36. $condition_str .= " and sg_name like '%". $condition['like_sg_name'] ."%'";
  37. }
  38. if ($condition['no_sg_id'] != ''){
  39. $condition_str .= " and sg_id != '". intval($condition['no_sg_id']) ."'";
  40. }
  41. if ($condition['sg_name'] != ''){
  42. $condition_str .= " and sg_name = '". $condition['sg_name'] ."'";
  43. }
  44. if ($condition['sg_id'] != ''){
  45. $condition_str .= " and store_grade.sg_id = '". $condition['sg_id'] ."'";
  46. }
  47. /*if($condition['store_id'] != '') {
  48. $condition_str .= " and store.store_id=".$condition['store_id'];
  49. }*/
  50. if(isset($condition['store_id'])) {
  51. $condition_str .= " and store.store_id = '{$condition['store_id']}' ";
  52. }
  53. if (isset($condition['sg_sort'])){
  54. if ($condition['sg_sort'] == ''){
  55. $condition_str .= " and sg_sort = '' ";
  56. }else {
  57. $condition_str .= " and sg_sort = '{$condition['sg_sort']}'";
  58. }
  59. }
  60. return $condition_str;
  61. }
  62. /**
  63. * 取单个内容
  64. *
  65. * @param int $id 分类ID
  66. * @return array 数组类型的返回结果
  67. */
  68. public function getOneGrade($id){
  69. if (intval($id) > 0){
  70. $param = array();
  71. $param['table'] = 'store_grade';
  72. $param['field'] = 'sg_id';
  73. $param['value'] = intval($id);
  74. $result = Db::getRow($param);
  75. return $result;
  76. }else {
  77. return false;
  78. }
  79. }
  80. /**
  81. * 新增
  82. *
  83. * @param array $param 参数内容
  84. * @return bool 布尔类型的返回结果
  85. */
  86. public function add($param){
  87. if (empty($param)){
  88. return false;
  89. }
  90. if (is_array($param)){
  91. $tmp = array();
  92. foreach ($param as $k => $v){
  93. $tmp[$k] = $v;
  94. }
  95. $result = Db::insert('store_grade',$tmp);
  96. return $result;
  97. }else {
  98. return false;
  99. }
  100. }
  101. /**
  102. * 更新信息
  103. *
  104. * @param array $param 更新数据
  105. * @return bool 布尔类型的返回结果
  106. */
  107. public function update($param){
  108. if (empty($param)){
  109. return false;
  110. }
  111. if (is_array($param)){
  112. $tmp = array();
  113. foreach ($param as $k => $v){
  114. $tmp[$k] = $v;
  115. }
  116. $where = " sg_id = '{$param['sg_id']}'";
  117. $result = Db::update('store_grade',$tmp,$where);
  118. return $result;
  119. }else {
  120. return false;
  121. }
  122. }
  123. /**
  124. * 删除分类
  125. *
  126. * @param int $id 记录ID
  127. * @return bool 布尔类型的返回结果
  128. */
  129. public function del($id){
  130. if (intval($id) > 0){
  131. $where = " sg_id = '". intval($id) ."'";
  132. $result = Db::delete('store_grade',$where);
  133. return $result;
  134. }else {
  135. return false;
  136. }
  137. }
  138. /**
  139. * 等级对应的店铺列表
  140. *
  141. * @param array $condition 检索条件
  142. * @param obj $page 分页
  143. * @return array 数组结构的返回结果
  144. */
  145. public function getGradeShopList($condition,$page=''){
  146. $condition_str = $this->_condition($condition);
  147. $param = array(
  148. 'table'=>'store_grade,store',
  149. 'field'=>'store_grade.*,store.*',
  150. 'where'=>$condition_str,
  151. 'join_type'=>'left join',
  152. 'join_on'=>array(
  153. 'store_grade.sg_id = store.grade_id',
  154. )
  155. );
  156. $result = Db::select($param,$page);
  157. return $result;
  158. }
  159. }