Log.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  76. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  77. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  78. $apply_id = GetUserInfo($token);
  79. if (empty($apply_id) || $apply_id['code'] != 0) {
  80. return error_show(1002, "用户数据不存在");
  81. }
  82. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : 0;
  83. $condition=[["uid","=",$rm]];
  84. $orderCode = isset($this->post['orderCode'])&&$this->post['orderCode']!=''?trim($this->post['orderCode']):'';
  85. if($orderCode!=""){
  86. $condition[]=["orderCode","like","%$orderCode%"];
  87. }
  88. $order_type = isset($this->post['order_type'])&&$this->post['order_type']!=''?trim($this->post['order_type']):'';
  89. if($order_type!=""){
  90. $condition[]=["order_type","=",$order_type];
  91. }
  92. $is_read = isset($this->post['is_read'])&&$this->post['is_read']!==''?intval($this->post['is_read']):'';
  93. if($is_read!==""){
  94. $condition[]=["is_read","=",$is_read];
  95. }
  96. $count = Db::name("order_msg")->where($condition)->count();
  97. $total = ceil($count/$size);
  98. $page = $page >= $total ? $total : $page;
  99. $list =Db::name("order_msg")->where($condition)->page(intval($page),$size)->order("addtime desc")->select();
  100. $data=[];
  101. $type = \think\facade\Config::get("order");
  102. foreach ($list as $value){
  103. $value['order_type_cn']=$type["order_type"][$value['order_type']];
  104. $data[]=$value;
  105. }
  106. return app_show(0,"获取成功",['list'=>$data,"count"=>$count]);
  107. }
  108. /**
  109. * 保存更新的资源
  110. *
  111. * @param \think\Request $request
  112. * @param int $id
  113. * @return \think\Response
  114. */
  115. public function update()
  116. {
  117. $id = isset($this->post['id'])&&$this->post['id']!=="" ? intval($this->post['id']) :"";
  118. if($id===""){
  119. return error_show(1004,"参数 id 不能为空");
  120. }
  121. $info = Db::name("order_msg")->where(["id"=>$id])->find();
  122. if(empty($info)){
  123. return error_show(1004,"未找到数据");
  124. }
  125. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  126. $apply_id = GetUserInfo($token);
  127. if (empty($apply_id) || $apply_id['code'] != 0) {
  128. return error_show(1002, "用户数据不存在");
  129. }
  130. $type = \think\facade\Config::get("order");
  131. $info['order_type_cn']=$type["order_type"][$info['order_type']];
  132. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  133. if($rm==$info['uid'] && $info['is_read']==0){
  134. Db::name("order_msg")->where(["id"=>$id])->save(["is_read"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  135. }
  136. return app_show(0,"获取成功",$info);
  137. }
  138. public function limit()
  139. {
  140. $id = isset($this->post['id'])&&$this->post['id']!=="" ? $this->post['id'] :[];
  141. if(empty($id)){
  142. return error_show(1004,"参数 id 不能为空");
  143. }
  144. $info = Db::name("order_msg")->where(["id"=>$id])->select()->toArray();
  145. if(empty($info)){
  146. return error_show(1004,"未找到数据");
  147. }
  148. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  149. $apply_id = GetUserInfo($token);
  150. if (empty($apply_id) || $apply_id['code'] != 0) {
  151. return error_show(1002, "用户数据不存在");
  152. }
  153. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  154. $read= Db::name("order_msg")->where(["id"=>$id,"uid"=>$rm])->save(["is_read"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  155. return $read?app_show(0,"已读成功"):app_show(1003,"已读失败");
  156. }
  157. public function allread()
  158. {
  159. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  160. $apply_id = GetUserInfo($token);
  161. if (empty($apply_id) || $apply_id['code'] != 0) {
  162. return error_show(1002, "用户数据不存在");
  163. }
  164. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  165. $info = Db::name("order_msg")->where(["uid"=>$rm,"is_read"=>0])->select()->toArray();
  166. if(empty($info)){
  167. return error_show(1004,"暂无未读数据");
  168. }
  169. $read=Db::name("order_msg")->where(["uid"=>$rm,"is_read"=>0])->save(["is_read"=>1,"updatetime"=>date("Y-m-d
  170. H:i:s")]);
  171. return $read?app_show(0,"全部已读成功"):app_show(1003,"全部已读失败");
  172. }
  173. }