public function run() { if (false == $this->verifyUserAuth()) { return false; } $page = intval($this->getDataItem('page', 1)); $limit = $this->getConfig()->limit; $offset = ($page - 1) * $limit; $userId = $this->getUserAuth()->userId; $data = UserMessage::query()->columns(['message_id', 'message_content', 'message_state', 'message_addtime', 'push_type', 'shop_id'])->where('user_id = :uid:', ['uid' => $userId])->orderBy('message_id DESC')->limit($limit, $offset)->execute()->toArray(); $data = $data ? $data : []; $this->setResult($data); }
public function run() { if (false == $this->verifyUserAuth()) { return false; } //$UserId = $this->getDataItem('user_id'); $userId = $this->getUserAuth()->userId; $status = UserMessage::find("user_id = {$userId}")->delete(); if ($status) { $this->setResult(['success' => 1, 'message' => '清空成功!']); } else { return $this->errorLog(ResultStatus::DATABASE_ERROR, '数据库异常'); } }
public function push() { if ($this->param['type'] === null || $this->param['ispushservice'] === null || $this->param['phone'] === null || $this->param['content'] === null || $this->param['shop_id'] === null) { return $this->returnResult($this->DATAERROR, '数据错误!'); } if (strlen($this->param['phone']) != 11) { return $this->returnResult($this->DATAERROR, '数据错误!'); } if ($this->param['phone'] == '') { return $this->returnResult($this->DATAERROR, '数据错误!'); } $userinfo = UserBase::findFirst("user_account = " . $this->param['phone']); if (!$userinfo) { return $this->returnResult($this->DATAERROR, '数据错误!'); } $user_id = $userinfo->user_id; $usermessage = new UserMessage(); $usermessage->user_id = $user_id; if ($this->param['ispushservice'] == 1) { $usermessage->is_read_b = 0; } else { $usermessage->is_read_b = 1; } $usermessage->message_content = $this->param['content']; $usermessage->push_type = $this->param['type']; $usermessage->message_state = 1; $usermessage->shop_id = $this->param['shop_id']; $usermessage->from_user_name = 1; $usermessage->from_user_cover = 1; $this->db->begin(); $message_status = $usermessage->save(); //添加数据到user_message if (!$message_status) { $this->db->rollback(); return $this->returnResult($this->MYSQLERROR, "数据库错误"); } /*推送至APP代码*/ $config = $this->di->get('appConfig')->jpush; $app_key = $config->app_key; $master_secret = $config->master_secret; JPushLog::setLogHandlers([new StreamHandler('jpush.log', Logger::DEBUG)]); $client = new JPushClient($app_key, $master_secret); //easy push try { $result = $client->push()->setPlatform(M\all)->setAudience(M\alias([$user_id]))->setNotification(M\notification($this->param['content']))->setOptions(M\options(null, null, null, true, null))->send(); if ($result->isOk === true) { $this->db->commit(); return $this->returnResult($this->SUCCESS, "推送成功!"); } else { $this->db->rollback(); return $this->returnResult($this->PUSHFAIL, "推送失败!"); } } catch (APIRequestException $e) { /* echo 'Push Fail.' . '<br>'; echo 'Http Code : ' . $e->httpCode . '<br>'; echo 'code : ' . $e->code . '<br>'; echo 'message : ' . $e->message . '<br>'; echo 'Response JSON : ' . $e->json . '<br>'; echo 'rateLimitLimit : ' . $e->rateLimitLimit . '<br>'; echo 'rateLimitRemaining : ' . $e->rateLimitRemaining . '<br>'; echo 'rateLimitReset : ' . $e->rateLimitReset . '<br>'; exit; */ $this->db->rollback(); return $this->returnResult($this->PUSHFAIL, "推送失败!"); } catch (APIConnectionException $e) { $this->db->rollback(); return $this->returnResult($this->PUSHFAIL, "推送失败!"); } /*the end*/ }