LengthClassModel.class.php 2.7 KB

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