80 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
		
		
			
		
	
	
			80 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| 
								 | 
							
								<?php
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								namespace app\api\controller\backend;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								use app\common\controller\Api;
							 | 
						||
| 
								 | 
							
								use think\Db;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * 站内信控制器
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								class Mail extends Api
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    protected $noNeedLogin = ['*'];
							 | 
						||
| 
								 | 
							
								    protected $noNeedRight = ['*'];
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    /**
							 | 
						||
| 
								 | 
							
								     * 首页
							 | 
						||
| 
								 | 
							
								     *
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								    public function getMailData()
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        // 从数据库中获取所有数据
							 | 
						||
| 
								 | 
							
								        $page = $this->request->post('page',1);
							 | 
						||
| 
								 | 
							
								        $size = $this->request->post('size',10);
							 | 
						||
| 
								 | 
							
								        $data = Db::name('mail')
							 | 
						||
| 
								 | 
							
								                ->field('a.*,w.nickname')
							 | 
						||
| 
								 | 
							
								                ->alias('a')
							 | 
						||
| 
								 | 
							
								                ->join('user w','a.user_id = w.id','LEFT')
							 | 
						||
| 
								 | 
							
								                ->page($page,$size)
							 | 
						||
| 
								 | 
							
								                ->order('a.id asc')
							 | 
						||
| 
								 | 
							
								                ->select();
							 | 
						||
| 
								 | 
							
								        $count = Db::name('mail')
							 | 
						||
| 
								 | 
							
								                ->field('a.*,w.nickname')
							 | 
						||
| 
								 | 
							
								                ->alias('a')
							 | 
						||
| 
								 | 
							
								                ->join('user w','a.user_id = w.id','LEFT')
							 | 
						||
| 
								 | 
							
								                ->count();
							 | 
						||
| 
								 | 
							
								        $res = [
							 | 
						||
| 
								 | 
							
								                'count' => $count,
							 | 
						||
| 
								 | 
							
								                'data' => $data,
							 | 
						||
| 
								 | 
							
								                ];
							 | 
						||
| 
								 | 
							
								        return $this->success('请求成功',$res);
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    /**
							 | 
						||
| 
								 | 
							
								     *添加数据
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								    public static function createMail($user_id,$notification_content)
							 | 
						||
| 
								 | 
							
								    {
							 | 
						||
| 
								 | 
							
								        $data['createtime'] = date('Y-m-d H:i:s');
							 | 
						||
| 
								 | 
							
								        $data['user_id'] = $user_id;
							 | 
						||
| 
								 | 
							
								        $data['notify_status'] = 1;
							 | 
						||
| 
								 | 
							
								        $data['notification_content'] = $notification_content;
							 | 
						||
| 
								 | 
							
								        $result = Db::name('mail')->strict(false)->insert($data);
							 | 
						||
| 
								 | 
							
								       
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								    
							 | 
						||
| 
								 | 
							
								    /**
							 | 
						||
| 
								 | 
							
								     *修改
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								    public  function updateMail()
							 | 
						||
| 
								 | 
							
								    {   
							 | 
						||
| 
								 | 
							
								        $id = $this->request->post('id');
							 | 
						||
| 
								 | 
							
								        if (!$id) {
							 | 
						||
| 
								 | 
							
								            $this->error(__('Invalid parameters'));
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								        $data = [];
							 | 
						||
| 
								 | 
							
								        $data['createtime'] = date('Y-m-d H:i:s');
							 | 
						||
| 
								 | 
							
								        $data['notify_status'] = 2;
							 | 
						||
| 
								 | 
							
								        $result = Db::name('mail')->where('id', $id)->update($data);
							 | 
						||
| 
								 | 
							
								         if ($result) {
							 | 
						||
| 
								 | 
							
								            return $this->success('更新成功',$result);
							 | 
						||
| 
								 | 
							
								        } else {
							 | 
						||
| 
								 | 
							
								            return $this->error('更新失败',$result);
							 | 
						||
| 
								 | 
							
								        }
							 | 
						||
| 
								 | 
							
								       
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								}
							 |