Log.php 7.0 KB

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