点赞,收藏,消息,分类图标
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
namespace app\common\controller;
|
||||
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\model\Post;
|
||||
use app\common\model\PostMedia;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\common\service\MessageNoticeService;
|
||||
use support\Request;
|
||||
|
||||
class MessageNoticeController extends BaseController
|
||||
{
|
||||
use CrudControllerTrait;
|
||||
|
||||
protected $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->service = new MessageNoticeService();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
*
|
||||
* @param Request $request 请求对象
|
||||
* @return mixed 返回分页数据及总数
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
try {
|
||||
$raw = $this->service->serviceSelfList($request);
|
||||
$data = $this->transformData($raw, method_exists($this, 'indexFormat')
|
||||
? [$this, 'indexFormat']
|
||||
: null);
|
||||
return $this->success($data);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表页数据格式化
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
protected function indexFormat($data)
|
||||
{
|
||||
if (isset($data['created_at']))
|
||||
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||
if (isset($data['updated_at']))
|
||||
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||
if (isset($data['post_id'])){
|
||||
$data['post'] = Post::where('id', $data['post_id'])->first();
|
||||
$data['post']['media'] = PostMedia::where('post_id', $data['post_id'])->get();
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
namespace app\common\controller;
|
||||
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\service\OssService;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\common\service\PostCategoryService;
|
||||
|
||||
@@ -22,12 +23,16 @@ class PostCategoryController extends BaseController
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
// protected function indexFormat($data)
|
||||
// {
|
||||
// if (isset($data['created_at']))
|
||||
// $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||
// if (isset($data['updated_at']))
|
||||
// $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||
// return $data;
|
||||
// }
|
||||
protected function indexFormat($data)
|
||||
{
|
||||
if (isset($data['created_at']))
|
||||
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||
if (isset($data['updated_at']))
|
||||
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||
if (!empty($data['icon'])){
|
||||
$ossservice = new OssService();
|
||||
$data['icon_pull'] = $ossservice->generatePrivateUrl($data['icon']);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
namespace app\common\controller;
|
||||
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\common\service\PostFavoriteService;
|
||||
use support\Request;
|
||||
|
||||
class PostFavoriteController extends BaseController
|
||||
{
|
||||
use CrudControllerTrait;
|
||||
|
||||
protected $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->service = new PostFavoriteService();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
*
|
||||
* @param Request $request 请求对象
|
||||
* @return mixed 返回分页数据及总数
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
try {
|
||||
$raw = $this->service->serviceSelfList($request);
|
||||
$data = $this->transformData($raw, method_exists($this, 'indexFormat')
|
||||
? [$this, 'indexFormat']
|
||||
: null);
|
||||
return $this->success($data);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表页数据格式化
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
protected function indexFormat($data)
|
||||
{
|
||||
if (isset($data['created_at']))
|
||||
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||
if (isset($data['updated_at']))
|
||||
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
namespace app\common\controller;
|
||||
|
||||
use app\common\controller\BaseController;
|
||||
use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\common\service\PostLikeService;
|
||||
use support\Request;
|
||||
|
||||
class PostLikeController extends BaseController
|
||||
{
|
||||
use CrudControllerTrait;
|
||||
|
||||
protected $service;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->service = new PostLikeService();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
*
|
||||
* @param Request $request 请求对象
|
||||
* @return mixed 返回分页数据及总数
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
try {
|
||||
$raw = $this->service->serviceSelfList($request);
|
||||
$data = $this->transformData($raw, method_exists($this, 'indexFormat')
|
||||
? [$this, 'indexFormat']
|
||||
: null);
|
||||
return $this->success($data);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表页数据格式化
|
||||
*
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
protected function indexFormat($data)
|
||||
{
|
||||
if (isset($data['created_at']))
|
||||
$data['created_at'] = date('Y-m-d H:i:s', $data['created_at']);
|
||||
if (isset($data['updated_at']))
|
||||
$data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']);
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ use app\common\traits\crud\CrudControllerTrait;
|
||||
use app\common\service\UserService;
|
||||
use app\common\service\WechatService;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
|
||||
class UserController extends BaseController
|
||||
{
|
||||
@@ -143,51 +144,30 @@ class UserController extends BaseController
|
||||
|
||||
|
||||
|
||||
|
||||
public function wechatLogin1($request)
|
||||
/**
|
||||
* 小程序登录
|
||||
*/
|
||||
public function miniappLogin(Request $request): Response
|
||||
{
|
||||
$loginCode = $request->post('login_code');
|
||||
$phoneCode = $request->post('phone_code');
|
||||
|
||||
if (!$loginCode || !$phoneCode) {
|
||||
return json(['code'=>0, 'msg'=>'缺少参数']);
|
||||
try {
|
||||
$result = $this->service->miniappLogin($request->all());
|
||||
return $this->success($result);
|
||||
} catch (\Throwable $th) {
|
||||
return $this->error($th->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// 1) code2Session
|
||||
$session = $this->code2Session($loginCode);
|
||||
if (!isset($session['openid'])) {
|
||||
return json(['code'=>0, 'msg'=>'登录失败', 'data'=>$session]);
|
||||
|
||||
/**
|
||||
* 获取手机号
|
||||
*/
|
||||
public function miniappPhoneNumber(Request $request): Response
|
||||
{
|
||||
try {
|
||||
$result = $this->service->miniappPhoneNumber($request->all());
|
||||
return $this->success($result);
|
||||
} catch (\Throwable $th) {
|
||||
return $this->error($th->getMessage());
|
||||
}
|
||||
|
||||
$openid = $session['openid'];
|
||||
|
||||
// 2) access_token
|
||||
$tokenData = $this->getAccessToken();
|
||||
$token = $tokenData['access_token'];
|
||||
|
||||
// 3) 换手机号
|
||||
$phoneData = $this->getPhoneNumber($token, $phoneCode);
|
||||
|
||||
if (!isset($phoneData['phone_info']['phoneNumber'])) {
|
||||
return json(['code'=>0, 'msg'=>'获取手机号失败', 'data'=>$phoneData]);
|
||||
}
|
||||
|
||||
$phone = $phoneData['phone_info']['phoneNumber'];
|
||||
|
||||
// 4) 写入数据库或登录逻辑
|
||||
// 比如自动注册
|
||||
$user = User::firstOrCreate(['openid'=>$openid], [
|
||||
'phone' => $phone
|
||||
]);
|
||||
|
||||
return json([
|
||||
'code' => 1,
|
||||
'msg' => '登录成功',
|
||||
'data' => [
|
||||
'openid' => $openid,
|
||||
'phone' => $phone,
|
||||
'token' => md5($openid.time()), // 你自己的登录 token
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user