Orderuse.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. namespace app\admin\controller;
  3. use app\BaseController;
  4. use think\App;
  5. use think\facade\Db;
  6. class Orderuse extends BaseController
  7. {
  8. public $post="";
  9. public function __construct(App $app)
  10. {
  11. parent::__construct($app);
  12. $this->post=$this->request->post();
  13. }
  14. public function create(){
  15. $order_use = isset($this->post['order_use']) && $this->post['order_use']!=="" ? trim($this->post['order_use']):"";
  16. if($order_use==""){
  17. return error_show(1002,"参数order_use不能为空");
  18. }
  19. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  20. if($token==''){
  21. return error_show(1005,"参数token不能为空");
  22. }
  23. $user =GetUserInfo($token);
  24. if(empty($user)||$user['code']!=0){
  25. return error_show(1002,"创建人数据不存在");
  26. }
  27. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  28. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  29. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']):"0";
  30. $data =[
  31. "order_use"=>$order_use,
  32. "creater"=>$creater,
  33. "createrid"=>$createrid,
  34. "status"=>0,
  35. "is_del"=>0,
  36. "addtime"=>date("Y-m-d H:i:s"),
  37. "updatetime"=>date("Y-m-d H:i:s")
  38. ];
  39. $datainfo = Db::name('order_use')->insert($data);
  40. if($datainfo){
  41. return error_show(0,"新建成功");
  42. }else{
  43. return error_show(1002,"新建失败");
  44. }
  45. }
  46. public function list(){
  47. $page = isset($this->post['page']) && $this->post['page'] !=="" ? intval($this->post['page']):"1";
  48. $size = isset($this->post['size']) && $this->post['size'] !=="" ? intval($this->post['size']):"10";
  49. $where =[['is_del',"=",0]];
  50. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']):"";
  51. if($status !==""){
  52. $where [] = ['status',"=",$status];
  53. }
  54. $order_use = isset($this->post['order_use']) && $this->post['order_use'] !=="" ? trim($this->post['order_use']):"";
  55. if($order_use !==""){
  56. $where [] =['order_use',"like","%$order_use%"];
  57. }
  58. $creater = isset($this->post['creater']) && $this->post['creater'] !=="" ? trim($this->post['creater']):"";
  59. if($creater !==""){
  60. $where [] =['creater',"like","%$creater%"];
  61. }
  62. $start = isset($this->post['start']) && $this->post['start']!=="" ? $this->post['start']:"";
  63. if($start!==""){
  64. $where[]=['addtime',">=",date('Y-m-d H:i:s',strtotime($start))];
  65. }
  66. $end = isset($this->post['end']) && $this->post['end']!=="" ? $this->post['end']:"";
  67. if($end!==""){
  68. $where[]=['addtime',"<",date('Y-m-d H:i:s',strtotime($end)+24*3600)];
  69. }
  70. $count = Db::name('order_use')->where($where)->count();
  71. $total = ceil($count / $size);
  72. $page = $page >= $total ? $total :$page;
  73. $list = Db::name('order_use')->where($where)->page($page,$size)->order("addtime desc")->select();
  74. return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
  75. }
  76. public function edit(){
  77. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  78. if($id==""){
  79. return error_show(1002,"参数id不能为空");
  80. }
  81. $info =Db::name('order_use')->where(['id'=>$id,'is_del'=>0])->find();
  82. if($info==""){
  83. return error_show(1004,"未找到数据");
  84. }
  85. $order_use = isset($this->post['order_use']) && $this->post['order_use'] !==""? trim($this->post['order_use']):"";
  86. if ($order_use==""){
  87. return error_show(1002,"参数order_use不能为空");
  88. }
  89. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']):"0";
  90. $data =[
  91. "id"=>$id,
  92. "order_use"=>$order_use,
  93. "is_del"=>0,
  94. "updatetime"=>date("Y-m-d H:i:s")
  95. ];
  96. $datainfo = Db::name("order_use")->save($data);
  97. if($datainfo){
  98. return error_show(0,"编辑成功");
  99. }else{
  100. return error_show(1002,"编辑失败");
  101. }
  102. }
  103. public function dele(){
  104. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  105. if($id==""){
  106. return error_show(1002,"参数id不能为空");
  107. }
  108. $info = Db::name('order_use')->where(['id'=>$id,'is_del'=>0])->find();
  109. if(empty($info)){
  110. return error_show(1004,"未找到数据");
  111. }
  112. $item = Db::name('order_use')->update(['id'=>$id,'is_del'=>1,'updatetime'=>date("y-m-d H:i:s")]);
  113. if($item){
  114. return error_show(0,"删除成功");
  115. }else{
  116. return error_show(1002,"删除失败");
  117. }
  118. }
  119. public function status(){
  120. $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']):"";
  121. if($id==""){
  122. return error_show(1002,"参数id不能为空");
  123. }
  124. $info = Db::name("order_use")->where([["id","=",$id],["is_del","=",0]])->find();
  125. if(!$info){
  126. return error_show(1002,"未找到对应数据");
  127. }
  128. $msg = $info['status']==0? "启用":"禁用";
  129. $info['status'] = $info['status']==0?1:0;
  130. $info['updatetime'] =date("Y-m-d H:i:s");
  131. $in =Db::name("order_use")->save($info);
  132. if($in){
  133. return app_show(0,"{$msg}成功");
  134. }else{
  135. return error_show(1004,"{$msg}失败");
  136. }
  137. }
  138. public function info(){
  139. $id = isset($this->post['id']) && $this->post['id'] !=="" ? trim($this->post['id']) :"";
  140. if($id==""){
  141. return error_show(1002,"参数id不能为空");
  142. }
  143. $info = Db::name('order_use')->where(['id'=>$id,'is_del'=>0])->find();
  144. if(empty($info)){
  145. return error_show(1004,'未找到数据');
  146. }
  147. return app_show(0,"获取成功",$info);
  148. }
  149. }