Orderuse.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 =[['ou.is_del',"=",0]];
  51. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']):"";
  52. if($status !==""){
  53. $where [] = ['ou.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 [] =['ou.order_use',"like","%$order_use%"];
  58. }
  59. $creater = isset($this->post['creater']) && $this->post['creater'] !=="" ? trim($this->post['creater']):"";
  60. if($creater !==""){
  61. $where [] =['ou.creater',"like","%$creater%"];
  62. }
  63. $start = isset($this->post['start']) && $this->post['start']!=="" ? $this->post['start']:"";
  64. if($start!==""){
  65. $where[]=['ou.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[]=['ou.addtime',"<",date('Y-m-d H:i:s',strtotime($end)+24*3600)];
  70. }
  71. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  72. if ($company_name !== "") $where[] = ["ou.createrid", 'in', get_company_item_user_by_name($company_name)];
  73. $count = Db::name('order_use')
  74. ->alias('ou')
  75. ->where($where)
  76. ->count();
  77. $total = ceil($count / $size);
  78. $page = $page >= $total ? $total :$page;
  79. $list = Db::name('order_use')
  80. ->alias('ou')
  81. ->where($where)
  82. ->page($page, $size)
  83. ->order("addtime desc")
  84. ->select()
  85. ->toArray();
  86. $all_createrid = array_column($list,'createrid');
  87. $item = get_company_name_by_uid($all_createrid);
  88. foreach ($list as &$value){
  89. $val['company_name']=$item[$value['createrid']]??'';
  90. }
  91. return app_show(0, "获取成功", ["list" => $list, "count" => $count]);
  92. }
  93. public function edit(){
  94. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  95. if($id==""){
  96. return error_show(1002,"参数id不能为空");
  97. }
  98. $info =Db::name('order_use')->where(['id'=>$id,'is_del'=>0])->find();
  99. if($info==""){
  100. return error_show(1004,"未找到数据");
  101. }
  102. $order_use = isset($this->post['order_use']) && $this->post['order_use'] !==""? trim($this->post['order_use']):"";
  103. if ($order_use==""){
  104. return error_show(1002,"参数order_use不能为空");
  105. }
  106. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']):"0";
  107. $data =[
  108. "id"=>$id,
  109. "order_use"=>$order_use,
  110. "is_del"=>0,
  111. "updatetime"=>date("Y-m-d H:i:s")
  112. ];
  113. $datainfo = Db::name("order_use")->save($data);
  114. if($datainfo){
  115. return error_show(0,"编辑成功");
  116. }else{
  117. return error_show(1002,"编辑失败");
  118. }
  119. }
  120. public function dele(){
  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(empty($info)){
  127. return error_show(1004,"未找到数据");
  128. }
  129. $item = Db::name('order_use')->update(['id'=>$id,'is_del'=>1,'updatetime'=>date("y-m-d H:i:s")]);
  130. if($item){
  131. return error_show(0,"删除成功");
  132. }else{
  133. return error_show(1002,"删除失败");
  134. }
  135. }
  136. public function status(){
  137. $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']):"";
  138. if($id==""){
  139. return error_show(1002,"参数id不能为空");
  140. }
  141. $info = Db::name("order_use")->where([["id","=",$id],["is_del","=",0]])->find();
  142. if(!$info){
  143. return error_show(1002,"未找到对应数据");
  144. }
  145. $msg = $info['status']==0? "启用":"禁用";
  146. $info['status'] = $info['status']==0?1:0;
  147. $info['updatetime'] =date("Y-m-d H:i:s");
  148. $in =Db::name("order_use")->save($info);
  149. if($in){
  150. return app_show(0,"{$msg}成功");
  151. }else{
  152. return error_show(1004,"{$msg}失败");
  153. }
  154. }
  155. public function info(){
  156. $id = isset($this->post['id']) && $this->post['id'] !=="" ? trim($this->post['id']) :"";
  157. if($id==""){
  158. return error_show(1002,"参数id不能为空");
  159. }
  160. $info = Db::name('order_use')->where(['id'=>$id,'is_del'=>0])->find();
  161. if(empty($info)){
  162. return error_show(1004,'未找到数据');
  163. }
  164. return app_show(0,"获取成功",$info);
  165. }
  166. }