AppMgr.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. use think\Model;
  6. class AppMgr extends Model
  7. {
  8. public function add(){
  9. $data = [
  10. 'id' => input('id/d',0),
  11. 'path' => input('path','','trim'),
  12. 'content' => input('content','','trim'),
  13. 'appver' => input('appver','','trim'),
  14. 'enable' => 0,
  15. 'ver' => input('ver/d',0),
  16. 'type' => input('type/d',1),
  17. ];
  18. $result = validate('AppMgr')->check($data,[],'');
  19. if(true !== $result){
  20. HelpHander::error(validate('AppMgr')->getError());
  21. }
  22. $id = $data['id'];
  23. unset($data['id']);
  24. if($id > 0){
  25. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  26. }else{
  27. $data['create_time'] = date('Y-m-d H:i:s');
  28. $ret = $this->allowField(true)->save($data);
  29. }
  30. if(!$ret){
  31. HelpHander::error('操作失败');
  32. }
  33. return true;
  34. }
  35. public function info($id){
  36. $info = $this->where('id',$id)->where('del',0)->find();
  37. if(!$info){
  38. HelpHander::error('数据不存在');
  39. }
  40. return $info->toArray();
  41. }
  42. public function lists($page,$size,$type){
  43. if(in_array($type,[1,2])){
  44. $map[] = ['type','=',$type];
  45. }
  46. $map[] = ['del','=',0];
  47. $lists = $this
  48. ->where($map)
  49. ->page($page,$size)
  50. ->order('id desc')
  51. ->select();
  52. $total = $this->where($map)->count();
  53. $data = [
  54. 'total' => $total,
  55. 'list' => $lists?$lists->toArray():[]
  56. ];
  57. return $data;
  58. }
  59. public function del($id){
  60. $ret = $this->where('id',$id)->setField('del',1);
  61. if(!$ret){
  62. HelpHander::error('删除失败');
  63. }
  64. return true;
  65. }
  66. public function changeStatus($id,$enable,$orgId){
  67. $info = Db::name('app_mgr')->where('id',$id)->find();
  68. if(!$info){
  69. HelpHander::error('数据不存在');
  70. }
  71. $ret = $this->where('id',$id)->setField('enable',$enable);
  72. if(!$ret){
  73. HelpHander::error('操作失败');
  74. }
  75. // 检查是否已生成过消息
  76. $msg = Db::name('message')->where('type',4)->where('bus_type',5)->where('bus_id',$id)->find();
  77. // 启用时生成系统消息
  78. if($info['enable'] == 0 && $enable == 1 && !$msg){
  79. trace('sssss');
  80. if($info['type'] == 1){
  81. $context = "京宜安OA[安卓]".$info['appver'].'主要更新';
  82. }else{
  83. $context = "京宜安OA[苹果]".$info['appver'].'主要更新';
  84. }
  85. $userids = model('User')->getUserByAuths($orgId,'');
  86. trace($userids);
  87. foreach ($userids as $k=>$v){
  88. // TODO::当人数过多时需要优化,推送及短信都是比较耗时的
  89. model('Message')->add(4,$id,5,$v,$orgId,$context);
  90. }
  91. }
  92. return true;
  93. }
  94. public function appMgr($type){
  95. $map[] = ['type','=',$type];
  96. $map[] = ['del','=',0];
  97. $map[] = ['enable','=',1];
  98. $info = Db::name('app_mgr')->where($map)->order('id desc')->find();
  99. return $info?$info:[];
  100. }
  101. }