Orderuse.php 6.9 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. ->field('ou.*,u.itemid')
  82. ->leftJoin("depart_user u", "u.uid=ou.createrid AND u.is_del=0")
  83. ->where($where)
  84. ->page($page, $size)
  85. ->append(['company_name'])
  86. ->withAttr('company_name', function ($val, $data) {
  87. return implode('/', array_column(GetPart($data['itemid']), 'name'));
  88. })
  89. ->order("addtime desc")
  90. ->select()
  91. ->toArray();
  92. return app_show(0, "获取成功", ["list" => $list, "count" => $count]);
  93. }
  94. public function edit(){
  95. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  96. if($id==""){
  97. return error_show(1002,"参数id不能为空");
  98. }
  99. $info =Db::name('order_use')->where(['id'=>$id,'is_del'=>0])->find();
  100. if($info==""){
  101. return error_show(1004,"未找到数据");
  102. }
  103. $order_use = isset($this->post['order_use']) && $this->post['order_use'] !==""? trim($this->post['order_use']):"";
  104. if ($order_use==""){
  105. return error_show(1002,"参数order_use不能为空");
  106. }
  107. $status = isset($this->post['status']) && $this->post['status'] !=="" ? intval($this->post['status']):"0";
  108. $data =[
  109. "id"=>$id,
  110. "order_use"=>$order_use,
  111. "is_del"=>0,
  112. "updatetime"=>date("Y-m-d H:i:s")
  113. ];
  114. $datainfo = Db::name("order_use")->save($data);
  115. if($datainfo){
  116. return error_show(0,"编辑成功");
  117. }else{
  118. return error_show(1002,"编辑失败");
  119. }
  120. }
  121. public function dele(){
  122. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) :"";
  123. if($id==""){
  124. return error_show(1002,"参数id不能为空");
  125. }
  126. $info = Db::name('order_use')->where(['id'=>$id,'is_del'=>0])->find();
  127. if(empty($info)){
  128. return error_show(1004,"未找到数据");
  129. }
  130. $item = Db::name('order_use')->update(['id'=>$id,'is_del'=>1,'updatetime'=>date("y-m-d H:i:s")]);
  131. if($item){
  132. return error_show(0,"删除成功");
  133. }else{
  134. return error_show(1002,"删除失败");
  135. }
  136. }
  137. public function status(){
  138. $id = isset($this->post['id']) && $this->post['id'] !==""? intval($this->post['id']):"";
  139. if($id==""){
  140. return error_show(1002,"参数id不能为空");
  141. }
  142. $info = Db::name("order_use")->where([["id","=",$id],["is_del","=",0]])->find();
  143. if(!$info){
  144. return error_show(1002,"未找到对应数据");
  145. }
  146. $msg = $info['status']==0? "启用":"禁用";
  147. $info['status'] = $info['status']==0?1:0;
  148. $info['updatetime'] =date("Y-m-d H:i:s");
  149. $in =Db::name("order_use")->save($info);
  150. if($in){
  151. return app_show(0,"{$msg}成功");
  152. }else{
  153. return error_show(1004,"{$msg}失败");
  154. }
  155. }
  156. public function info(){
  157. $id = isset($this->post['id']) && $this->post['id'] !=="" ? trim($this->post['id']) :"";
  158. if($id==""){
  159. return error_show(1002,"参数id不能为空");
  160. }
  161. $info = Db::name('order_use')->where(['id'=>$id,'is_del'=>0])->find();
  162. if(empty($info)){
  163. return error_show(1004,'未找到数据');
  164. }
  165. return app_show(0,"获取成功",$info);
  166. }
  167. }