Orderuse.php 6.1 KB

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