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