Log.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 BaseController
  10. {
  11. public $post = "";
  12. public function __construct(App $app)
  13. {
  14. parent::__construct($app);
  15. $this->post = $this->request->post();
  16. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  17. if($token==""){
  18. return error_show(101,'token不能为空');
  19. }
  20. $effetc = VerifyTokens($token);
  21. if(!empty($effetc) && $effetc['code']!=0){
  22. return error_show($effetc['code'],$effetc['message']);
  23. }
  24. }
  25. /**
  26. * 显示资源列表
  27. *
  28. * @return \think\Response
  29. */
  30. public function index()
  31. {
  32. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  33. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  34. $condition = [['type',"=",1]];
  35. $count = Db::name("action_log")->where($condition)->count();
  36. $total = ceil($count/$size);
  37. $page = $page >= $total ? intval($total) : $page;
  38. $list =Db::name("action_log")->where($condition)->page($page,$size)->order("addtime desc")->select();
  39. return app_show(0,"获取成功",['list'=>$list,"count"=>$count]);
  40. }
  41. /**
  42. * 显示创建资源表单页.
  43. *
  44. * @return \think\Response
  45. */
  46. public function create()
  47. {
  48. }
  49. /**
  50. * 保存新建的资源
  51. *
  52. * @param \think\Request $request
  53. * @return \think\Response
  54. */
  55. public function save(Request $request)
  56. {
  57. //
  58. }
  59. /**
  60. * 显示指定的资源
  61. *
  62. * @param int $id
  63. * @return \think\Response
  64. */
  65. public function read()
  66. {
  67. $id = isset($this->post['id'])&&$this->post['id']!=="" ? intval($this->post['id']) :"";
  68. if($id===""){
  69. return error_show(1004,"参数 id 不能为空");
  70. }
  71. $info = Db::name("action_log")->where(["id"=>$id])->find();
  72. if(empty($info)){
  73. return error_show(1004,"未找到数据");
  74. }
  75. return app_show(0,"获取成功",$info);
  76. }
  77. /**
  78. * 显示编辑资源表单页.
  79. *
  80. * @param int $id
  81. * @return \think\Response
  82. */
  83. public function msglist()
  84. {
  85. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  86. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  87. $condition=[];
  88. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  89. $apply_id = GetUserInfo($token);
  90. if (empty($apply_id) || $apply_id['code'] != 0) {
  91. return error_show(1002, "用户数据不存在");
  92. }
  93. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  94. //$condition[]=["uid","=",$rm];
  95. $orderCode = isset($this->post['orderCode'])&&$this->post['orderCode']!=''?trim($this->post['orderCode']):'';
  96. if($orderCode!=""){
  97. $condition[]=["orderCode","like","%$orderCode%"];
  98. }
  99. $order_type = isset($this->post['order_type'])&&$this->post['order_type']!=''?trim($this->post['order_type']):'';
  100. if($order_type!=""){
  101. $condition[]=["order_type","=",$order_type];
  102. }
  103. $is_read = isset($this->post['is_read'])&&$this->post['is_read']!==''?intval($this->post['is_read']):'';
  104. if($is_read!==""){
  105. $condition[]=["is_read","=",$is_read];
  106. }
  107. $count = Db::name("order_msg")->where($condition)->count();
  108. $total = ceil($count/$size);
  109. $page = $page >= $total ? $total : $page;
  110. $list =Db::name("order_msg")->where($condition)->page(intval($page),$size)->order("addtime desc")->select();
  111. $data=[];
  112. $type = \think\facade\Config::get("order");
  113. foreach ($list as $value){
  114. $value['order_type_cn']=$type["order_type"][$value['order_type']];
  115. $data[]=$value;
  116. }
  117. return app_show(0,"获取成功",['list'=>$data,"count"=>$count]);
  118. }
  119. /**
  120. * 保存更新的资源
  121. *
  122. * @param \think\Request $request
  123. * @param int $id
  124. * @return \think\Response
  125. */
  126. public function update()
  127. {
  128. $id = isset($this->post['id'])&&$this->post['id']!=="" ? intval($this->post['id']) :"";
  129. if($id===""){
  130. return error_show(1004,"参数 id 不能为空");
  131. }
  132. $info = Db::name("order_msg")->where(["id"=>$id])->find();
  133. if(empty($info)){
  134. return error_show(1004,"未找到数据");
  135. }
  136. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  137. $apply_id = GetUserInfo($token);
  138. if (empty($apply_id) || $apply_id['code'] != 0) {
  139. return error_show(1002, "用户数据不存在");
  140. }
  141. $type = \think\facade\Config::get("order");
  142. $info['order_type_cn']=$type["order_type"][$info['order_type']];
  143. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  144. if($rm==$info['uid'] && $info['is_read']==0){
  145. Db::name("order_msg")->where(["id"=>$id])->save(["is_read"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  146. }
  147. return app_show(0,"获取成功",$info);
  148. }
  149. public function limit()
  150. {
  151. $id = isset($this->post['id'])&&$this->post['id']!=="" ? $this->post['id'] :[];
  152. if(empty($id)){
  153. return error_show(1004,"参数 id 不能为空");
  154. }
  155. $info = Db::name("order_msg")->where(["id"=>$id])->select()->toArray();
  156. if(empty($info)){
  157. return error_show(1004,"未找到数据");
  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. $read= Db::name("order_msg")->where(["id"=>$id,"uid"=>$rm])->save(["is_read"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  166. return $read?app_show(0,"已读成功"):app_show(1003,"已读失败");
  167. }
  168. public function allread()
  169. {
  170. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  171. $apply_id = GetUserInfo($token);
  172. if (empty($apply_id) || $apply_id['code'] != 0) {
  173. return error_show(1002, "用户数据不存在");
  174. }
  175. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  176. $info = Db::name("order_msg")->where(["uid"=>$rm,"is_read"=>0])->select()->toArray();
  177. if(empty($info)){
  178. return error_show(1004,"暂无未读数据");
  179. }
  180. $read=Db::name("order_msg")->where(["uid"=>$rm,"is_read"=>0])->save(["is_read"=>1,"updatetime"=>date("Y-m-d
  181. H:i:s")]);
  182. return $read?app_show(0,"全部已读成功"):app_show(1003,"全部已读失败");
  183. }
  184. }