12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace addons\qingdongams\controller;
- use addons\qingdongams\model\Notice as NoticeModel;
- use addons\qingdongams\model\NoticeRead;
- /**
- * @desc 操作文档:https://doc.fastadmin.net/qingdongams
- * @desc 软件介绍:https://www.fastadmin.net/store/qingdongams.html
- * @desc 售后微信:qingdong_crm
- */
- /**
- * 公告接口
- */
- class Notice extends StaffApi {
- protected $noNeedLogin = [];
- protected $noNeedRight = [];
- //公告列表
- public function getList() {
- $limit = input("limit/d", 10);
- $authid=$this->auth->id;
- $records = NoticeModel::where([
- ])->where(function ($query) use ($authid) {
- $query->where('owner_staff_ids', 'like', "%,$authid,%")->whereOr('owner_staff_ids', 'eq', "");
- })->order('id desc')->paginate($limit);
- $items = $records->items();
- foreach ($items as $k => $v) {
- $read_staff_ids = explode(',', $v['read_staff_ids']);
- $v['is_read'] = in_array($this->auth->id, $read_staff_ids)?0:1;
- $items[$k] = $v;
- }
- $this->success('请求成功', $records);
- }
- //获取公告详情
- public function getDetail() {
- $id = input('id', '', 'intval');
- $notice = NoticeModel::where(['id' => $id])->find();
- if (empty($notice)) {
- $this->error('公告不存在');
- }
- $read_staff_ids = explode(',', $notice['read_staff_ids']);
- if (!in_array($this->auth->id, $read_staff_ids)) {
- $read_staff_ids[] = $this->auth->id;
- NoticeModel::where(['id' => $notice['id']])->update(['read_staff_ids' => implode(',', $read_staff_ids).',']);
- }
- if(!NoticeRead::where(['notice_id'=>$id,'staff_id'=>$this->auth->id])->find()){
- //添加阅读记录
- NoticeRead::addRead($id, $this->auth->id);
- }
- preg_match_all('/<img.+src=\"?(.+\.(jpg|gif|bmp|bnp|png))\"?.+>/i',$notice['content'],$match);
- foreach ($match[1] as $v){
- $notice['content']=str_replace($v,cdnurl($v,true),$notice['content']);
- }
- $notice['is_edit'] = ($this->auth->id == $notice['create_staff_id']) ? 1 : 0;
- $this->success('请求成功', $notice);
- }
- //添加通告
- public function addNotice() {
- $params = $this->request->post();
- $params['owner_staff_ids'] = ',' . $params['owner_staff_ids'] . ',' . $this->auth->id . ',';
- $params['create_staff_id'] = $this->auth->id;
- $result = (new NoticeModel())->save($params);
- if (!$result) {
- $this->error('提交失败');
- }
- $this->success('提交成功');
- }
- //修改公告
- public function editNotice(){
- $params = $this->request->post();
- if(empty($params['id'])){
- $this->error('参数错误');
- }
- $result = (new NoticeModel())->save($params,['id'=>$params['id']]);
- if (!$result) {
- $this->error('提交失败');
- }
- $this->success('提交成功');
- }
- }
|