WeightClassModel.class.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. /**
  3. * 小梦科技资源nanodreamtech.com
  4. *
  5. * ==========================================================================
  6. * @link https://www.nanodreamtech.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license https://www.nanodreamtech.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author fish
  12. *
  13. */
  14. namespace Admin\Model;
  15. class WeightClassModel{
  16. /**
  17. *显示重量单位分页
  18. */
  19. public function show_weight_class_page(){
  20. $count=M('WeightClass')->count();
  21. $Page = new \Think\Page($count,C('BACK_PAGE_NUM'));
  22. $show = $Page->show();// 分页显示输出
  23. $list = M('WeightClass')->order('weight_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. }elseif(empty($data['unit'])){
  35. $error='重量单位必填';
  36. }elseif(empty($data['value'])){
  37. $error='重量值 必填';
  38. }
  39. if($status=='add'){
  40. if(M('WeightClass')->getByTitle($data['title'])){
  41. $error='该重量名称已经存在';
  42. }
  43. }else{
  44. if(M('WeightClass')->where('weight_class_id!='.$data['weight_class_id']." AND title='".$data['title']."'")->find()){
  45. $error='该重量名称已经存在';
  46. }
  47. }
  48. if($error){
  49. return array(
  50. 'status'=>'back',
  51. 'message'=>$error
  52. );
  53. }
  54. }
  55. public function add_weight_class($data){
  56. $error=$this->validate($data,'add');
  57. if($error){
  58. return $error;
  59. }
  60. $r=M('WeightClass')->add($data);
  61. if($r){
  62. return array(
  63. 'status'=>'success',
  64. 'message'=>'新增成功',
  65. 'jump'=>U('WeightClass/index')
  66. );
  67. }else{
  68. return array(
  69. 'status'=>'fail',
  70. 'message'=>'新增失败',
  71. 'jump'=>U('WeightClass/index')
  72. );
  73. }
  74. }
  75. public function edit_weight_class($data){
  76. $error=$this->validate($data);
  77. if($error){
  78. return $error;
  79. }
  80. $r=M('WeightClass')->save($data);
  81. if($r){
  82. return array(
  83. 'status'=>'success',
  84. 'message'=>'修改成功',
  85. 'jump'=>U('WeightClass/index')
  86. );
  87. }else{
  88. return array(
  89. 'status'=>'fail',
  90. 'message'=>'修改失败',
  91. 'jump'=>U('WeightClass/index')
  92. );
  93. }
  94. }
  95. public function del_weight_class(){
  96. $r=M('WeightClass')->where(array('weight_class_id'=>I('id')))->delete();
  97. if($r){
  98. return array(
  99. 'status'=>'success',
  100. 'message'=>'删除成功',
  101. 'jump'=>U('WeightClass/index')
  102. );
  103. }else{
  104. return array(
  105. 'status'=>'fail',
  106. 'message'=>'删除失败',
  107. 'jump'=>U('WeightClass/index')
  108. );
  109. }
  110. }
  111. }
  112. ?>