OrderStatusModel.class.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 OrderStatusModel{
  16. /**
  17. *显示订单状态单位分页
  18. */
  19. public function show_order_status_page(){
  20. $count=M('OrderStatus')->count();
  21. $Page = new \Think\Page($count,C('BACK_PAGE_NUM'));
  22. $show = $Page->show();// 分页显示输出
  23. $list = M('OrderStatus')->order('order_status_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['name'])){
  33. $error='订单状态名称必填';
  34. }
  35. if($status=='add'){
  36. if(M('OrderStatus')->getByName($data['name'])){
  37. $error='该订单状态名称已经存在';
  38. }
  39. }else{
  40. if(M('OrderStatus')->where('order_status_id!='.$data['order_status_id']." AND name='".$data['name']."'")->find()){
  41. $error='该订单状态名称已经存在';
  42. }
  43. }
  44. if($error){
  45. return array(
  46. 'status'=>'back',
  47. 'message'=>$error
  48. );
  49. }
  50. }
  51. public function add_order_status($data){
  52. $error=$this->validate($data,'add');
  53. if($error){
  54. return $error;
  55. }
  56. $r=M('OrderStatus')->add($data);
  57. if($r){
  58. return array(
  59. 'status'=>'success',
  60. 'message'=>'新增成功',
  61. 'jump'=>U('OrderStatus/index')
  62. );
  63. }else{
  64. return array(
  65. 'status'=>'fail',
  66. 'message'=>'新增失败',
  67. 'jump'=>U('OrderStatus/index')
  68. );
  69. }
  70. }
  71. public function edit_order_status($data){
  72. $error=$this->validate($data);
  73. if($error){
  74. return $error;
  75. }
  76. $r=M('OrderStatus')->save($data);
  77. if($r){
  78. return array(
  79. 'status'=>'success',
  80. 'message'=>'修改成功',
  81. 'jump'=>U('OrderStatus/index')
  82. );
  83. }else{
  84. return array(
  85. 'status'=>'fail',
  86. 'message'=>'修改失败',
  87. 'jump'=>U('OrderStatus/index')
  88. );
  89. }
  90. }
  91. public function del_order_status(){
  92. $r=M('OrderStatus')->where(array('order_status_id'=>I('id')))->delete();
  93. if($r){
  94. return array(
  95. 'status'=>'success',
  96. 'message'=>'删除成功',
  97. 'jump'=>U('OrderStatus/index')
  98. );
  99. }else{
  100. return array(
  101. 'status'=>'fail',
  102. 'message'=>'删除失败',
  103. 'jump'=>U('OrderStatus/index')
  104. );
  105. }
  106. }
  107. }
  108. ?>