| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- namespace app\api\controller;
- use app\api\model\UserDynamic as UserDynamicModel;
- use app\api\service\User as UserService;
- /**
- * 动态控制器
- * Class Dynamic
- * @package app\api\controller
- */
- class Dynamic extends Controller
- {
- public function list()
- {
- // 获取列表数据
- $model = new UserDynamicModel();
- $pageSize = $this->request->param('pageSize', 15);
- $params = $this->request->param();
- $userInfo = UserService::getCurrentLoginUser(true);
- $accessUserId = isset($userInfo['user_id'])? intval($userInfo['user_id']) : 0;
- $userId = isset($params['user_id'])? intval($params['user_id']) : 0;
- $params['access_user_id'] = $accessUserId;
- if($userId<=0){
- $params['user_id'] = $accessUserId;
- }
- $list = $model->getList($params, (int)$pageSize);
- return $this->renderSuccess(compact('list'));
- }
- /**
- * 推荐动态
- * @return \think\response\Json
- * @throws \think\db\exception\DbException
- */
- public function index()
- {
- // 获取列表数据
- $model = new UserDynamicModel();
- $pageSize = $this->request->param('pageSize', 15);
- $userInfo = UserService::getCurrentLoginUser(true);
- $userId = isset($userInfo['user_id'])? intval($userInfo['user_id']) : 0;
- $list = $model->getIndexList($userId,$this->request->param(), (int)$pageSize);
- return $this->renderSuccess(compact('list'));
- }
- /**
- * 动态发布
- * @return \think\response\Json
- */
- public function publish()
- {
- $model = new UserDynamicModel();
- if(!$model->publish($this->request->param())){
- return $this->renderError($model->getError() ?: '动态发布失败');
- }
- $info = ['dynamic_id'=> $model['id'],'message'=>'发布成功'];
- return $this->renderSuccess(compact('info'));
- }
- /**
- * 动态详情
- * @return \think\response\Json
- */
- public function detail()
- {
- $model = new UserDynamicModel();
- $info = $model->getDetail((int)$this->request->param('id'));
- return $this->renderSuccess(compact('info'));
- }
- }
|