__('Status normal'),'hidden' => __('Status hidden')]; } public function getStatusTextAttr($value, $data) { $value = $value ? $value : $data['status']; $list = $this->getStatusList(); return isset($list[$value]) ? $list[$value] : ''; } /** * 清理缓存 * @param null $admin_id */ public function delCache($admin_id = null) { if ($admin_id) { $key = "WSDPS:".$admin_id; Redis::instance()->del($key); } $allKey = "WSDPS:0"; Redis::instance()->del($allKey); } /** * 获取配置缓存 * @param null $admin_id * @return array|bool|string */ public function getInfo($admin_id = null) { if ($admin_id) { $key = "WSDPS:".$admin_id; } else { $key = "WSDPS:0"; } if (isset($this->caches[$key])) { return $this->caches[$key]; } $data = Redis::instance()->get($key); if (!!!$data) { //取存 $data = []; $maps = [ 'status' => ['eq', 'normal'], ]; if ($admin_id) { //需要判断是否可以使用 $adminConfig = model("AdminConfig")->getAdminInfoAll($admin_id); if (!isset($adminConfig['subscribe_delay']) || $adminConfig['subscribe_delay'] != "2") { //不存在、未设置、未开启 直接返回空数组 Redis::instance()->set($key, json_encode($data), 600); $this->caches[$key] = $data; return $data; } //继续 $maps['admin_id'] = ['eq', $admin_id]; } $rows = model("SubscribeDelayPush")->field("id, admin_id, content, content_type, delay, type, updatetime, status")->where($maps)->select(); if ($rows) { $adminIds = array_unique(array_column($rows, 'admin_id')); //过滤未开启渠道 $adminIdRows = model("AdminConfig")->field('admin_id')->where('admin_id', 'in', $adminIds)->where('subscribe_delay', 'eq','2')->select(); $adminIdsArr = array_column($adminIdRows, 'admin_id'); foreach ($rows as $row) { if (in_array($row['admin_id'], $adminIdsArr)) { $content = json_decode($row['content'], true); // $custom_fields = ["description","image","title","url"]; $user_fields = ['user_type','mobile_system','sex']; $user_json = ['user_type' => 1,'mobile_system'=>0,'sex'=>0]; foreach ($content as $key=>$value) { if (in_array($key, $user_fields)) { $user_json[$key] = $value; unset($content[$key]); } } $data[] = [ 'id' => $row['id'], 'content' => json_encode($content, JSON_UNESCAPED_UNICODE), 'user_json' => json_encode($user_json, JSON_UNESCAPED_UNICODE), 'content_type'=>$row['content_type'], 'channel_id' => $row['admin_id'], 'delay_secs' => $row['type'] == 1 ? $row['delay'] * 60 : ($row['type'] == 2 ? $row['delay'] * 3600 : 0), 'update_time' => $row['updatetime'], 'status' => $row['status'] == 'normal' ? 1 : 0, ]; } } } Redis::instance()->set($key, json_encode($data), 600); } else { $data = json_decode($data, true); } $this->caches[$key] = $data; return $data; } }