123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- namespace app\common\model;
- use app\hander\HelpHander;
- use think\Db;
- use think\Model;
- class AppMgr extends Model
- {
- public function add(){
- $data = [
- 'id' => input('id/d',0),
- 'path' => input('path','','trim'),
- 'content' => input('content','','trim'),
- 'appver' => input('appver','','trim'),
- 'enable' => 0,
- 'ver' => input('ver/d',0),
- 'type' => input('type/d',1),
- ];
- $result = validate('AppMgr')->check($data,[],'');
- if(true !== $result){
- HelpHander::error(validate('AppMgr')->getError());
- }
- $id = $data['id'];
- unset($data['id']);
- if($id > 0){
- $ret = $this->allowField(true)->save($data,['id'=>$id]);
- }else{
- $data['create_time'] = date('Y-m-d H:i:s');
- $ret = $this->allowField(true)->save($data);
- }
- if(!$ret){
- HelpHander::error('操作失败');
- }
- return true;
- }
- public function info($id){
- $info = $this->where('id',$id)->where('del',0)->find();
- if(!$info){
- HelpHander::error('数据不存在');
- }
- return $info->toArray();
- }
- public function lists($page,$size,$type){
- if(in_array($type,[1,2])){
- $map[] = ['type','=',$type];
- }
- $map[] = ['del','=',0];
- $lists = $this
- ->where($map)
- ->page($page,$size)
- ->order('id desc')
- ->select();
- $total = $this->where($map)->count();
- $data = [
- 'total' => $total,
- 'list' => $lists?$lists->toArray():[]
- ];
- return $data;
- }
- public function del($id){
- $ret = $this->where('id',$id)->setField('del',1);
- if(!$ret){
- HelpHander::error('删除失败');
- }
- return true;
- }
- public function changeStatus($id,$enable,$orgId){
- $info = Db::name('app_mgr')->where('id',$id)->find();
- if(!$info){
- HelpHander::error('数据不存在');
- }
- $ret = $this->where('id',$id)->setField('enable',$enable);
- if(!$ret){
- HelpHander::error('操作失败');
- }
- // 检查是否已生成过消息
- $msg = Db::name('message')->where('type',4)->where('bus_type',5)->where('bus_id',$id)->find();
- // 启用时生成系统消息
- if($info['enable'] == 0 && $enable == 1 && !$msg){
- trace('sssss');
- if($info['type'] == 1){
- $context = "京宜安OA[安卓]".$info['appver'].'主要更新';
- }else{
- $context = "京宜安OA[苹果]".$info['appver'].'主要更新';
- }
- $userids = model('User')->getUserByAuths($orgId,'');
- trace($userids);
- foreach ($userids as $k=>$v){
- // TODO::当人数过多时需要优化,推送及短信都是比较耗时的
- model('Message')->add(4,$id,5,$v,$orgId,$context);
- }
- }
- return true;
- }
- public function appMgr($type){
- $map[] = ['type','=',$type];
- $map[] = ['del','=',0];
- $map[] = ['enable','=',1];
- $info = Db::name('app_mgr')->where($map)->order('id desc')->find();
- return $info?$info:[];
- }
- }
|