分类图标,是否点赞,小程序登录
This commit is contained in:
@@ -0,0 +1,8 @@
|
|||||||
|
/runtime
|
||||||
|
/.idea
|
||||||
|
/.vscode
|
||||||
|
/vendor
|
||||||
|
*.log
|
||||||
|
.env
|
||||||
|
/tests/tmp
|
||||||
|
/tests/.phpunit.result.cache
|
||||||
@@ -54,6 +54,9 @@ class PostCategoryController extends BaseController
|
|||||||
if (!empty($data['icon_inactive'])){
|
if (!empty($data['icon_inactive'])){
|
||||||
$data['icon_inactive_pull'] = $ossservice->generatePrivateUrl($data['icon_inactive']);
|
$data['icon_inactive_pull'] = $ossservice->generatePrivateUrl($data['icon_inactive']);
|
||||||
}
|
}
|
||||||
|
if (!empty($data['icon_preset'])){
|
||||||
|
$data['icon_preset_pull'] = $ossservice->generatePrivateUrl($data['icon_preset']);
|
||||||
|
}
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,9 +2,13 @@
|
|||||||
namespace app\common\controller;
|
namespace app\common\controller;
|
||||||
|
|
||||||
use app\common\controller\BaseController;
|
use app\common\controller\BaseController;
|
||||||
|
use app\common\model\PostComment;
|
||||||
|
use app\common\model\PostFavorite;
|
||||||
|
use app\common\model\PostLike;
|
||||||
use app\common\model\PostMedia;
|
use app\common\model\PostMedia;
|
||||||
use app\common\traits\crud\CrudControllerTrait;
|
use app\common\traits\crud\CrudControllerTrait;
|
||||||
use app\common\service\PostService;
|
use app\common\service\PostService;
|
||||||
|
use support\Request;
|
||||||
|
|
||||||
class PostController extends BaseController
|
class PostController extends BaseController
|
||||||
{
|
{
|
||||||
@@ -16,6 +20,31 @@ class PostController extends BaseController
|
|||||||
{
|
{
|
||||||
$this->service = new PostService();
|
$this->service = new PostService();
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 获取列表
|
||||||
|
*
|
||||||
|
* @param Request $request 请求对象
|
||||||
|
* @return mixed 返回分页数据及总数
|
||||||
|
*/
|
||||||
|
public function index(Request $request)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$raw = $this->service->serviceList($request);
|
||||||
|
$data = $this->transformData($raw, method_exists($this, 'indexFormat')
|
||||||
|
? [$this, 'indexFormat']
|
||||||
|
: null);
|
||||||
|
$records = $data['records'];
|
||||||
|
foreach ($records as $record) {
|
||||||
|
$data['is_like'] = PostLike::where('post_id', $record['id'])->where('user_id', $request->user->id)->count();
|
||||||
|
$data['is_favorite'] = PostFavorite::where('post_id', $record['id'])->where('user_id', $request->user->id)->count();
|
||||||
|
$data['is_comment'] = PostComment::where('post_id', $record['id'])->where('user_id', $request->user->id)->count();
|
||||||
|
}
|
||||||
|
$data['records'] = $records;
|
||||||
|
return $this->success($data);
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
return $this->error($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 列表页数据格式化
|
* 列表页数据格式化
|
||||||
@@ -29,8 +58,10 @@ class PostController extends BaseController
|
|||||||
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||||
if (isset($data['updated_at']))
|
if (isset($data['updated_at']))
|
||||||
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||||
if (isset($data['id']))
|
if (isset($data['id'])){
|
||||||
$data['media'] = PostMedia::where('post_id', $data['id'])->get();
|
$data['media'] = PostMedia::where('post_id', $data['id'])->get();
|
||||||
|
|
||||||
|
}
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ class PostCategory extends Model
|
|||||||
/**
|
/**
|
||||||
* 允许自动填充模型字段
|
* 允许自动填充模型字段
|
||||||
*/
|
*/
|
||||||
protected $fillable = ['id', 'parent_id', 'icon_active', 'icon_inactive', 'name', 'level', 'path', 'sort', 'status', 'created_at', 'updated_at'];
|
protected $fillable = ['id', 'parent_id', 'icon_active', 'icon_inactive', 'icon_preset', 'name', 'level', 'path', 'sort', 'status', 'created_at', 'updated_at'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 不允许自动填充模型字段
|
* 不允许自动填充模型字段
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace app\common\service;
|
namespace app\common\service;
|
||||||
|
|
||||||
|
use app\common\model\MessageNotice;
|
||||||
|
use app\common\model\Post;
|
||||||
use app\common\validate\PostCommentValidate;
|
use app\common\validate\PostCommentValidate;
|
||||||
use app\common\traits\crud\CrudServiceTrait;
|
use app\common\traits\crud\CrudServiceTrait;
|
||||||
use app\common\model\PostComment;
|
use app\common\model\PostComment;
|
||||||
@@ -102,4 +104,23 @@ class PostCommentService
|
|||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加后置处理
|
||||||
|
*/
|
||||||
|
public function afterServiceStore($res)
|
||||||
|
{
|
||||||
|
$data = [];
|
||||||
|
$data['post_id'] = $res['post_id'];
|
||||||
|
$data['receiver_user_id'] = Post::where(['id' => $data['post_id']])->value('user_id');
|
||||||
|
$data['sender_user_id'] = $res['user_id'];
|
||||||
|
$data['comment_id'] = $res['id'];
|
||||||
|
$data['type'] = 3;
|
||||||
|
MessageNotice::create($data);
|
||||||
|
$post = Post::where(['id' => $data['post_id']])->first();
|
||||||
|
$post['comment'] = $post['comment']+1;
|
||||||
|
$post->save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -103,5 +103,8 @@ class PostFavoriteService
|
|||||||
$data['sender_user_id'] = $res['user_id'];
|
$data['sender_user_id'] = $res['user_id'];
|
||||||
$data['type'] = 2;
|
$data['type'] = 2;
|
||||||
MessageNotice::create($data);
|
MessageNotice::create($data);
|
||||||
|
$post = Post::where(['id' => $data['post_id']])->first();
|
||||||
|
$post['favorite'] = $post['favorite']+1;
|
||||||
|
$post->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -105,5 +105,8 @@ class PostLikeService
|
|||||||
$data['sender_user_id'] = $res['user_id'];
|
$data['sender_user_id'] = $res['user_id'];
|
||||||
$data['type'] = 1;
|
$data['type'] = 1;
|
||||||
MessageNotice::create($data);
|
MessageNotice::create($data);
|
||||||
|
$post = Post::where(['id' => $data['post_id']])->first();
|
||||||
|
$post['like'] = $post['like']+1;
|
||||||
|
$post->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -237,11 +237,12 @@ class UserService
|
|||||||
$logic = new UserLogic();
|
$logic = new UserLogic();
|
||||||
$wechatService = new WechatService();
|
$wechatService = new WechatService();
|
||||||
$wxinfo = $wechatService->xcxOpenid($data['code']);
|
$wxinfo = $wechatService->xcxOpenid($data['code']);
|
||||||
|
var_dump($wxinfo);
|
||||||
|
|
||||||
// 用户信息
|
// 用户信息
|
||||||
$user = User::firstOrCreate(
|
$user = User::firstOrCreate(
|
||||||
['openid' => $wxinfo['openid']],
|
['openid' => $wxinfo['openid']],
|
||||||
['nickname' => '微信用户_'.$wxinfo['openid'], 'avatar' => getenv('MAIN_DOMAIN').'/avatar.png']
|
['nickname' => '微信用户_'.$wxinfo['openid'], 'name' => '', 'avatar' => getenv('MAIN_DOMAIN').'/avatar.png']
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -82,6 +82,11 @@ Route::group('/common', function () {
|
|||||||
Route::group('/messageNotice', function () {
|
Route::group('/messageNotice', function () {
|
||||||
Route::any('/list', [app\common\controller\MessageNoticeController::class, 'index']);
|
Route::any('/list', [app\common\controller\MessageNoticeController::class, 'index']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 帖子分类
|
||||||
|
Route::group('/category', function () {
|
||||||
|
Route::any('/list', [app\admin\controller\PostCategoryController::class, 'index']);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
//协议
|
//协议
|
||||||
|
|||||||
Reference in New Issue
Block a user