123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- <?php
- namespace app\admin\model;
- use think\Log;
- use think\Model;
- class Notice extends Model
- {
- // 表名
- protected $table = 'notice';
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
- // 追加属性
- protected $append = [
- 'show_level_text',
- 'dialog_type_text',
- 'notice_type_text',
- 'status_text'
- ];
- public function getShowLevelList()
- {
- return ['1' => '超管可见', '2' => '超管、普管、客服、运营可见', '3' => '超管、普管、渠道商、客服、运营可见', '4' => '超管、普管、渠道商、代理商、客服、运营可见','5' => '代理商、客服、运营可见'];
- }
- public function getDialogTypeList()
- {
- return ['1' => '只弹一次', '2' => '每次登陆', '3' => '每天一次', '4' => '不弹窗','5'=>'自定义'];
- }
- public function getNoticeTypeList()
- {
- return ['1' => '常规公告', '2' => '新书推荐', '3' => '活动通知'];
- }
- public function getStatusList()
- {
- return ['normal' => '显示', 'hidden' => '隐藏'];
- }
- public function getImportantTypeList(){
- return ['0' => '普通', '1' => '标题标红'];
- }
- public function getShowLevelTextAttr($value, $data)
- {
- $value = $value ? $value : $data['show_level'];
- $list = $this->getShowLevelList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getDialogTypeTextAttr($value, $data)
- {
- $value = $value ? $value : $data['dialog_type'];
- $list = $this->getDialogTypeList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getNoticeTypeTextAttr($value, $data)
- {
- $value = $value ? $value : $data['notice_type'];
- $list = $this->getNoticeTypeList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getStatusTextAttr($value, $data)
- {
- $value = $value ? $value : $data['status'];
- $list = $this->getStatusList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- /**
- * 获取需要弹窗的公告ID
- * @return int
- */
- public function dialog($admin_id)
- {
- //级别过滤
- $group = model("AuthGroupAccess")->getGroupId($admin_id);
- // $showlevel = [];
- // switch ($group){
- // case 1://超管
- // $showlevel = [1,2,3,4];
- // break;
- // case 2://普管
- // $showlevel = [2,3,4];
- // break;
- // case 3://渠道商
- // $showlevel = [3,4];
- // break;
- // case 4://代理商
- // $showlevel = [4,5];
- // break;
- // case 5://客服
- // $showlevel = [2,3,4,5];
- // break;
- // case 6://运营
- // $showlevel = [2,3,4,5];
- // break;
- // }
- $n2Sql = $this
- ->alias('n')
- ->join('notice_log l', "n.dialog_type='1' and n.id=l.notice_id and l.admin_id='{$admin_id}'", 'left')
- ->field('n.id,l.admin_id')
- ->buildSql();
- $n3Sql = $this
- ->alias('n')
- ->join('notice_log l',
- "n.dialog_type='3' and n.id=l.notice_id and l.admin_id='{$admin_id}' and l.createtime>" . strtotime(date('Y-m-d 00:00:00')),
- 'left')
- ->field('n.id,l.admin_id')
- ->buildSql();
- $result = $this
- ->alias('n1')
- ->join($n2Sql . ' n2', "n1.id=n2.id and n2.admin_id IS NULL", 'inner')
- ->join($n3Sql . ' n3', "n1.id=n3.id and n3.admin_id IS NULL", 'inner')
- ->where('status', 'normal')
- ->where('dialog_type',"neq", '4')
- // ->where("show_level","in",$showlevel)
- ->field('n1.id,n1.groups,n1.pop_num,n1.dialog_type')
- ->order('id', 'desc')
- // ->limit(1)
- ->select();
- //计算自定义公告当天弹窗的次数
- $dialog5 = $this
- ->alias('n2')
- ->join("notice_log l2","n2.id=l2.notice_id and l2.admin_id='{$admin_id}' and l2.createtime>" . strtotime(date('Y-m-d 00:00:00')),'inner')
- ->where('n2.dialog_type=5')
- ->field('l2.notice_id,count(1) num')
- ->group('l2.notice_id')
- ->select();
- if (!empty($dialog5)){
- $dialog5 = array_column($dialog5,null,'notice_id');
- }
- foreach ($result as $v){
- if(strpos($v['groups'],(string)$group)!==false){
- if ($v['dialog_type'] == 5 && !empty($dialog5) && isset($dialog5[$v['id']]) && $dialog5[$v['id']]['num']>=$v['pop_num']){
- continue;
- }
- return $v['id'];
- }else{
- continue;
- }
- }
- return null;
- }
- }
|