123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- <?php
- declare (strict_types = 1);
- namespace app\admin\controller;
- use app\BaseController;
- use think\Request;
- use think\App;
- use think\facade\Db;
- class Log extends BaseController
- {
- public $post = "";
- public function __construct(App $app)
- {
- parent::__construct($app);
- $this->post = $this->request->post();
- $token = isset($this->post['token']) ? trim($this->post['token']) : "";
- if($token==""){
- return error_show(101,'token不能为空');
- }
- $effetc = VerifyTokens($token);
- if(!empty($effetc) && $effetc['code']!=0){
- return error_show($effetc['code'],$effetc['message']);
- }
- }
- /**
- * 显示资源列表
- *
- * @return \think\Response
- */
- public function index()
- {
- $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
- $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
- $condition = [['type',"=",1]];
- $count = Db::name("action_log")->where($condition)->count();
- $total = ceil($count/$size);
- $page = $page >= $total ? $total : $page;
- $list =Db::name("action_log")->where($condition)->page($page,$size)->select();
- return app_show(0,"获取成功",['list'=>$list,"count"=>$count]);
- }
- /**
- * 显示创建资源表单页.
- *
- * @return \think\Response
- */
- public function create()
- {
- }
- /**
- * 保存新建的资源
- *
- * @param \think\Request $request
- * @return \think\Response
- */
- public function save(Request $request)
- {
- //
- }
- /**
- * 显示指定的资源
- *
- * @param int $id
- * @return \think\Response
- */
- public function read()
- {
- $id = isset($this->post['id'])&&$this->post['id']!=="" ? intval($this->post['id']) :"";
- if($id===""){
- return error_show(1004,"参数 id 不能为空");
- }
- $info = Db::name("action_log")->where(["id"=>$id])->find();
- if(empty($info)){
- return error_show(1004,"未找到数据");
- }
- return app_show(0,"获取成功",$info);
- }
- /**
- * 显示编辑资源表单页.
- *
- * @param int $id
- * @return \think\Response
- */
- public function msglist()
- {
- $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
- $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
- $condition=[];
- $token = isset($this->post['token']) ? trim($this->post['token']) : "";
- $apply_id = GetUserInfo($token);
- if (empty($apply_id) || $apply_id['code'] != 0) {
- return error_show(1002, "用户数据不存在");
- }
- $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
- //$condition[]=["uid","=",$rm];
- $orderCode = isset($this->post['orderCode'])&&$this->post['orderCode']!=''?trim($this->post['orderCode']):'';
- if($orderCode!=""){
- $condition[]=["orderCode","like","%$orderCode%"];
- }
- $order_type = isset($this->post['order_type'])&&$this->post['order_type']!=''?trim($this->post['order_type']):'';
- if($order_type!=""){
- $condition[]=["order_type","=",$order_type];
- }
- $is_read = isset($this->post['is_read'])&&$this->post['is_read']!==''?intval($this->post['is_read']):'';
- if($is_read!==""){
- $condition[]=["is_read","=",$is_read];
- }
- $count = Db::name("order_msg")->where($condition)->count();
- $total = ceil($count/$size);
- $page = $page >= $total ? $total : $page;
- $list =Db::name("order_msg")->where($condition)->page($page,$size)->select();
- $data=[];
- $type = \think\facade\Config::get("order");
- foreach ($list as $value){
- $value['order_type_cn']=$type["order_type"][$value['order_type']];
- $data[]=$value;
- }
- return app_show(0,"获取成功",['list'=>$data,"count"=>$count]);
- }
- /**
- * 保存更新的资源
- *
- * @param \think\Request $request
- * @param int $id
- * @return \think\Response
- */
- public function update()
- {
- $id = isset($this->post['id'])&&$this->post['id']!=="" ? intval($this->post['id']) :"";
- if($id===""){
- return error_show(1004,"参数 id 不能为空");
- }
- $info = Db::name("order_msg")->where(["id"=>$id])->find();
- if(empty($info)){
- return error_show(1004,"未找到数据");
- }
- $token = isset($this->post['token']) ? trim($this->post['token']) : "";
- $apply_id = GetUserInfo($token);
- if (empty($apply_id) || $apply_id['code'] != 0) {
- return error_show(1002, "用户数据不存在");
- }
- $type = \think\facade\Config::get("order");
- $info['order_type_cn']=$type["order_type"][$info['order_type']];
- $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
- if($rm==$info['uid'] && $info['is_read']==0){
- Db::name("order_msg")->where(["id"=>$id])->save(["is_read"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
- }
- return app_show(0,"获取成功",$info);
- }
- public function limit()
- {
- $id = isset($this->post['id'])&&$this->post['id']!=="" ? $this->post['id'] :[];
- if(empty($id)){
- return error_show(1004,"参数 id 不能为空");
- }
- $info = Db::name("order_msg")->where(["id"=>$id])->select()->toArray();
- if(empty($info)){
- return error_show(1004,"未找到数据");
- }
- $token = isset($this->post['token']) ? trim($this->post['token']) : "";
- $apply_id = GetUserInfo($token);
- if (empty($apply_id) || $apply_id['code'] != 0) {
- return error_show(1002, "用户数据不存在");
- }
- $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
- $read= Db::name("order_msg")->where(["id"=>$id,"uid"=>$rm])->save(["is_read"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
- return $read?app_show(0,"已读成功"):app_show(1003,"已读失败");
- }
- public function allread()
- {
- $token = isset($this->post['token']) ? trim($this->post['token']) : "";
- $apply_id = GetUserInfo($token);
- if (empty($apply_id) || $apply_id['code'] != 0) {
- return error_show(1002, "用户数据不存在");
- }
- $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
- $info = Db::name("order_msg")->where(["uid"=>$rm,"is_read"=>0])->select()->toArray();
- if(empty($info)){
- return error_show(1004,"暂无未读数据");
- }
- $read=Db::name("order_msg")->where(["uid"=>$rm,"is_read"=>0])->save(["is_read"=>1,"updatetime"=>date("Y-m-d
- H:i:s")]);
- return $read?app_show(0,"全部已读成功"):app_show(1003,"全部已读失败");
- }
- }
|