| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?php
- namespace App\Models;
- use DB;
- class Manager extends BaseModel {
- protected $table = "message";
- public $timestamps = false;
- function getlist($list = 10, $where = '') {
- $data = $this->orderBy('add_time', 'desc');
- if (!empty($where) && is_array($where)) {
- $data = $data->where($where);
- }
- $data = $data->paginate($list);
- if (!$data) {
- return -4010010022; //没有数据
- }
- return $data->toArray();
- }
- //获取信息
- function getMsg($value, $type) {
- $fild = $this->getfild($type);
- $data = $this->where($fild, $value)->orderBy('add_time', 'desc')->limit(10)->get();
- if (!$data) {
- return -4010010122; //没有数据
- }
- return $data->toArray();
- }
- function getDmsg($value, $type) {
- $fild = $this->getfild($type);
- $data = $this->where($fild, $value)->first();
- if (!$data) {
- return -4010010122; //没有数据
- }
- return $data->toArray();
- }
- function getfild($k) {
- $a = array(
- 1 => 'id',
- 2 => 'type',
- );
- return $a[$k];
- }
- function updateMsg($data, $id) {
- $res = $this->where('id', $id)->update($data);
- if (!$res) {
- return -4010011122;
- }
- return 1;
- }
- function updateMessage($sender, $reciver, $title, $content, $type)
- {
- $data['add_time']=date('Y-m-d H:i:s');
- $data['formname']=$sender;
- $data['toname']=$reciver;
- $data['title'] = $title;
- $data['type'] =$type;
- $data['content'] = $content;
- //普通消息
- if ($data['type'] == 2){
- $dataName=explode(',',$data['toname']);
- foreach ($dataName as $v){
- $data['toname']=$v;
- $this->addNotice($data);
- }
- }
- //系统消息
- if ($data['type'] == 1){
- $data['formname']='system';
- $data['toname']='all';
- $this->addNotice($data);
- }
- //系统通知
- if ($data['type'] == 3){
- $data['formname']='notice';
- $data['toname']='all';
- $this->addNotice($data);
- }
- //系统通知
- if ($data['type'] == 4){
- $data['formname']='admin';
- $data['toname']='admin_all';
- $this->addNotice($data);
- }
- }
- //添加公告数据
- function addNotice($data){
- // DB::connection()->enableQueryLog();
- $res = $this->insertGetId ($data);
- // $queries = DB::getQueryLog();
- // print_r($queries);
- if(!$res){
- return -6030001222;
- }
- return $res;
- }
- function getlistd($where) {
- $data = $this->where($where[0], $where[1])->orderBy('add_time', 'desc')->limit(5)->get();
- if (!$data) {
- return -4010011122;
- }
- return $data->toArray();
- }
- }
|