ConfigModel.class.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 Admin\Model;
  15. class ConfigModel{
  16. /**
  17. *显示分页
  18. */
  19. public function show_config_page($search){
  20. $sql="select * from ".C('DB_PREFIX')."config where 1 ";
  21. if(isset($search['name'])){
  22. $sql.=" and name like '%".$search['name']."%'";
  23. }
  24. if(isset($search['config_group'])){
  25. $sql.=" and config_group='".$search['config_group']."'";
  26. }
  27. $count=count(M()->query($sql));
  28. $Page = new \Think\Page($count,C('BACK_PAGE_NUM'));
  29. $show = $Page->show();// 分页显示输出
  30. $sql.=' order by config_group desc LIMIT '.$Page->firstRow.','.$Page->listRows;
  31. $list=M()->query($sql);
  32. return array(
  33. 'empty'=>'<tr><td colspan="20">~~暂无数据</td></tr>',
  34. 'list'=>$list,
  35. 'page'=>$show
  36. );
  37. }
  38. function validate($data,$status='update'){
  39. $error=array();
  40. if(empty($data['name'])){
  41. $error='名称必填';
  42. }
  43. if($status=='add'){
  44. if(M('config')->getByName($data['name'])){
  45. $error='该名称已经存在';
  46. }
  47. }else{
  48. if(M('config')->where('id!='.$data['id']." AND name='".$data['name']."'")->find()){
  49. $error='该名称已经存在';
  50. }
  51. }
  52. if($error){
  53. return array(
  54. 'status'=>'back',
  55. 'message'=>$error
  56. );
  57. }
  58. }
  59. public function add_config($data){
  60. $error=$this->validate($data,'add');
  61. if($error){
  62. return $error;
  63. }
  64. $r=M('config')->add($data);
  65. if($r){
  66. return array(
  67. 'status'=>'success',
  68. 'message'=>'新增成功',
  69. 'jump'=>U('config/index')
  70. );
  71. }else{
  72. return array(
  73. 'status'=>'fail',
  74. 'message'=>'新增失败',
  75. 'jump'=>U('config/index')
  76. );
  77. }
  78. }
  79. public function edit_config($data){
  80. $error=$this->validate($data);
  81. if($error){
  82. return $error;
  83. }
  84. $r=M('config')->save($data);
  85. if($r){
  86. return array(
  87. 'status'=>'success',
  88. 'message'=>'修改成功',
  89. 'jump'=>U('config/index')
  90. );
  91. }else{
  92. return array(
  93. 'status'=>'fail',
  94. 'message'=>'修改失败',
  95. 'jump'=>U('config/index')
  96. );
  97. }
  98. }
  99. public function del_config(){
  100. $r=M('config')->where(array('id'=>I('id')))->delete();
  101. if($r){
  102. return array(
  103. 'status'=>'success',
  104. 'message'=>'删除成功',
  105. 'jump'=>U('config/index')
  106. );
  107. }else{
  108. return array(
  109. 'status'=>'fail',
  110. 'message'=>'删除失败',
  111. 'jump'=>U('config/index')
  112. );
  113. }
  114. }
  115. }
  116. ?>