StockStatusModel.class.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 StockStatusModel{
  16. /**
  17. *显示库存状态单位分页
  18. */
  19. public function show_stock_status_page(){
  20. $count=M('StockStatus')->count();
  21. $Page = new \Think\Page($count,C('BACK_PAGE_NUM'));
  22. $show = $Page->show();// 分页显示输出
  23. $list = M('StockStatus')->order('stock_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('StockStatus')->getByName($data['name'])){
  37. $error='该库存状态名称已经存在';
  38. }
  39. }else{
  40. if(M('StockStatus')->where('stock_status_id!='.$data['stock_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_stock_status($data){
  52. $error=$this->validate($data,'add');
  53. if($error){
  54. return $error;
  55. }
  56. $r=M('StockStatus')->add($data);
  57. if($r){
  58. return array(
  59. 'status'=>'success',
  60. 'message'=>'新增成功',
  61. 'jump'=>U('StockStatus/index')
  62. );
  63. }else{
  64. return array(
  65. 'status'=>'fail',
  66. 'message'=>'新增失败',
  67. 'jump'=>U('StockStatus/index')
  68. );
  69. }
  70. }
  71. public function edit_stock_status($data){
  72. $error=$this->validate($data);
  73. if($error){
  74. return $error;
  75. }
  76. $r=M('StockStatus')->save($data);
  77. if($r){
  78. return array(
  79. 'status'=>'success',
  80. 'message'=>'修改成功',
  81. 'jump'=>U('StockStatus/index')
  82. );
  83. }else{
  84. return array(
  85. 'status'=>'fail',
  86. 'message'=>'修改失败',
  87. 'jump'=>U('StockStatus/index')
  88. );
  89. }
  90. }
  91. public function del_stock_status(){
  92. $r=M('StockStatus')->where(array('stock_status_id'=>I('id')))->delete();
  93. if($r){
  94. return array(
  95. 'status'=>'success',
  96. 'message'=>'删除成功',
  97. 'jump'=>U('StockStatus/index')
  98. );
  99. }else{
  100. return array(
  101. 'status'=>'fail',
  102. 'message'=>'删除失败',
  103. 'jump'=>U('StockStatus/index')
  104. );
  105. }
  106. }
  107. }
  108. ?>