Log.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\admin\controller;
  4. use app\BaseController;
  5. use think\Request;
  6. use think\App;
  7. use think\facade\Db;
  8. //日志
  9. class Log extends Base
  10. {
  11. public function __construct(App $app)
  12. {
  13. parent::__construct($app);
  14. }
  15. /**
  16. * 显示资源列表
  17. *
  18. * @return \think\Response
  19. */
  20. public function index()
  21. {
  22. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  23. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  24. $condition = [['type',"=",1]];
  25. $count = Db::name("action_log")->where($condition)->count();
  26. $total = ceil($count/$size);
  27. $page = $page >= $total ? intval($total) : $page;
  28. $list =Db::name("action_log")->where($condition)->page($page,$size)->order("addtime desc")->select();
  29. return app_show(0,"获取成功",['list'=>$list,"count"=>$count]);
  30. }
  31. /**
  32. * 显示创建资源表单页.
  33. *
  34. * @return \think\Response
  35. */
  36. public function create()
  37. {
  38. }
  39. /**
  40. * 保存新建的资源
  41. *
  42. * @param \think\Request $request
  43. * @return \think\Response
  44. */
  45. public function save(Request $request)
  46. {
  47. //
  48. }
  49. /**
  50. * 显示指定的资源
  51. *
  52. * @param int $id
  53. * @return \think\Response
  54. */
  55. public function read()
  56. {
  57. $id = isset($this->post['id'])&&$this->post['id']!=="" ? intval($this->post['id']) :"";
  58. if($id===""){
  59. return error_show(1004,"参数 id 不能为空");
  60. }
  61. $info = Db::name("action_log")->where(["id"=>$id])->find();
  62. if(empty($info)){
  63. return error_show(1004,"未找到数据");
  64. }
  65. return app_show(0,"获取成功",$info);
  66. }
  67. /**
  68. * 显示编辑资源表单页.
  69. *
  70. * @param int $id
  71. * @return \think\Response
  72. */
  73. public function msglist()
  74. {
  75. $param = $this->request->only(['token' => '', 'orderCode' => '', 'page' => 1, 'size' => 10, 'order_type' => '', 'is_read' => ''], 'post', 'trim');
  76. $apply_id = GetUserInfo($param['token']);
  77. if (empty($apply_id) || $apply_id['code'] != 0) return error_show(1002, "用户数据不存在");
  78. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : 0;
  79. $condition = [['om.uid', '=', $rm]];//自己看到自己的消息
  80. if ($param['orderCode'] != "") $condition[] = ["om.orderCode", "like", "%{$param['orderCode']}%"];
  81. if ($param['order_type'] != "") $condition[] = ["om.order_type", "=", $param['order_type']];
  82. if ($param['is_read'] !== "") $condition[] = ["om.is_read", "=", $param['is_read']];
  83. $count = Db::name("order_msg")
  84. ->alias('om')
  85. ->where($condition)
  86. ->count();
  87. $total = ceil($count / $param['size']);
  88. $page = $param['page'] >= $total ? $total : $param['page'];
  89. $list = Db::name("order_msg")
  90. ->alias('om')
  91. ->field('om.*,ap.order_name,p.process_name')
  92. ->where($condition)
  93. ->leftJoin('action_process ap', 'ap.order_type=om.order_type AND ap.order_process=om.order_status')
  94. ->leftJoin('process p', 'p.id=ap.pid')
  95. ->page(intval($page), intval($param['size']))
  96. ->order("om.addtime desc")
  97. ->select()
  98. ->toArray();
  99. return app_show(0, "获取成功", ['list' => $list, "count" => $count]);
  100. }
  101. /**
  102. * 保存更新的资源
  103. *
  104. * @param \think\Request $request
  105. * @param int $id
  106. * @return \think\Response
  107. */
  108. public function update()
  109. {
  110. $id = isset($this->post['id'])&&$this->post['id']!=="" ? intval($this->post['id']) :"";
  111. if($id===""){
  112. return error_show(1004,"参数 id 不能为空");
  113. }
  114. $info = Db::name("order_msg")->where(["id"=>$id])->find();
  115. if(empty($info)){
  116. return error_show(1004,"未找到数据");
  117. }
  118. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  119. $apply_id = GetUserInfo($token);
  120. if (empty($apply_id) || $apply_id['code'] != 0) {
  121. return error_show(1002, "用户数据不存在");
  122. }
  123. $type = \think\facade\Config::get("order");
  124. $info['order_type_cn']=$type["order_type"][$info['order_type']];
  125. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  126. if($rm==$info['uid'] && $info['is_read']==0){
  127. Db::name("order_msg")->where(["id"=>$id])->save(["is_read"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  128. }
  129. return app_show(0,"获取成功",$info);
  130. }
  131. public function limit()
  132. {
  133. $id = isset($this->post['id'])&&$this->post['id']!=="" ? $this->post['id'] :[];
  134. if(empty($id)){
  135. return error_show(1004,"参数 id 不能为空");
  136. }
  137. $info = Db::name("order_msg")->where(["id"=>$id])->select()->toArray();
  138. if(empty($info)){
  139. return error_show(1004,"未找到数据");
  140. }
  141. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  142. $apply_id = GetUserInfo($token);
  143. if (empty($apply_id) || $apply_id['code'] != 0) {
  144. return error_show(1002, "用户数据不存在");
  145. }
  146. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  147. $read= Db::name("order_msg")->where(["id"=>$id,"uid"=>$rm])->save(["is_read"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  148. return $read?app_show(0,"已读成功"):app_show(1003,"已读失败");
  149. }
  150. public function allread()
  151. {
  152. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  153. $apply_id = GetUserInfo($token);
  154. if (empty($apply_id) || $apply_id['code'] != 0) {
  155. return error_show(1002, "用户数据不存在");
  156. }
  157. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  158. $info = Db::name("order_msg")->where(["uid"=>$rm,"is_read"=>0])->select()->toArray();
  159. if(empty($info)){
  160. return error_show(1004,"暂无未读数据");
  161. }
  162. $read=Db::name("order_msg")->where(["uid"=>$rm,"is_read"=>0])->save(["is_read"=>1,"updatetime"=>date("Y-m-d
  163. H:i:s")]);
  164. return $read?app_show(0,"全部已读成功"):app_show(1003,"全部已读失败");
  165. }
  166. }