点赞,收藏,消息,分类图标
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\validate\MessageNoticeValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\common\model\MessageNotice;
|
||||
use support\Request;
|
||||
|
||||
class MessageNoticeService
|
||||
{
|
||||
|
||||
use CrudServiceTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = MessageNotice::class;
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected $validator = MessageNoticeValidate::class;
|
||||
|
||||
/**
|
||||
* 获取验证器
|
||||
*/
|
||||
public function getValidator()
|
||||
{
|
||||
return new $this->validator;
|
||||
}
|
||||
|
||||
/** 分页列表 */
|
||||
public function serviceSelfList(Request $request, string $scene = 'self')
|
||||
{
|
||||
$result = $this->cqyProcess(ucfirst($scene), $request);
|
||||
if ($result === false) {
|
||||
$config = $this->buildQueryConfig($request, $scene);
|
||||
$limit = (int)$request->get('size', 15);
|
||||
$page = (int)$request->get('current', 1);
|
||||
$result = $this->logicList($config, $limit, $page);
|
||||
}
|
||||
return $this->postProcess(ucfirst($scene), $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造 CrudUtil 查询配置
|
||||
*/
|
||||
protected function buildQueryConfig(Request $request, string $scene = 'default'): array
|
||||
{
|
||||
$p = $request->all();
|
||||
|
||||
$config = [];
|
||||
$config['model'] = $this->modelClass;
|
||||
switch ($scene) {
|
||||
case 'default':
|
||||
$config['order']['id'] = 'desc';
|
||||
break;
|
||||
case 'self':
|
||||
$config['where']['receiver_user_id'] = $request->user->uid;
|
||||
$config['order']['id'] = 'desc';
|
||||
break;
|
||||
case 'index':
|
||||
$config['order']['id'] = 'desc';
|
||||
break;
|
||||
case 'show':
|
||||
$config['where']['id'] = $p['id'];
|
||||
$config['where']['status'] = 1;
|
||||
break;
|
||||
case 'store':
|
||||
break;
|
||||
case 'update':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
case 'destroy':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加后置处理
|
||||
*/
|
||||
public function beforeServiceSelf($data, Request $request)
|
||||
{
|
||||
MessageNotice::where('receiver_user_id', $request->user->uid)->update(['is_read' => 1]);
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\model\MessageNotice;
|
||||
use app\common\model\Post;
|
||||
use app\common\validate\PostFavoriteValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\common\model\PostFavorite;
|
||||
use support\Request;
|
||||
|
||||
class PostFavoriteService
|
||||
{
|
||||
|
||||
use CrudServiceTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = PostFavorite::class;
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected $validator = PostFavoriteValidate::class;
|
||||
|
||||
/**
|
||||
* 获取验证器
|
||||
*/
|
||||
public function getValidator()
|
||||
{
|
||||
return new $this->validator;
|
||||
}
|
||||
|
||||
/** 分页列表 */
|
||||
public function serviceSelfList(Request $request, string $scene = 'self')
|
||||
{
|
||||
$result = $this->cqyProcess(ucfirst($scene), $request);
|
||||
if ($result === false) {
|
||||
$config = $this->buildQueryConfig($request, $scene);
|
||||
$limit = (int)$request->get('size', 15);
|
||||
$page = (int)$request->get('current', 1);
|
||||
$result = $this->logicList($config, $limit, $page);
|
||||
}
|
||||
return $this->postProcess(ucfirst($scene), $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造 CrudUtil 查询配置
|
||||
*/
|
||||
protected function buildQueryConfig(Request $request, string $scene = 'default'): array
|
||||
{
|
||||
$p = $request->all();
|
||||
|
||||
$config = [];
|
||||
$config['model'] = $this->modelClass;
|
||||
switch ($scene) {
|
||||
case 'default':
|
||||
$config['order']['id'] = 'desc';
|
||||
break;
|
||||
case 'self':
|
||||
$config['where']['user_id'] = $request->user->uid;
|
||||
$config['order']['id'] = 'desc';
|
||||
break;
|
||||
case 'index':
|
||||
$config['order']['id'] = 'desc';
|
||||
break;
|
||||
case 'show':
|
||||
$config['where']['id'] = $p['id'];
|
||||
$config['where']['status'] = 1;
|
||||
break;
|
||||
case 'store':
|
||||
break;
|
||||
case 'update':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
case 'destroy':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加前置处理
|
||||
*/
|
||||
public function beforeServiceStore($data, Request $request)
|
||||
{
|
||||
$data['user_id'] = $request->user->uid;;
|
||||
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['type'] = 2;
|
||||
MessageNotice::create($data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\model\MessageNotice;
|
||||
use app\common\model\Post;
|
||||
use app\common\model\PostMedia;
|
||||
use app\common\validate\PostLikeValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\common\model\PostLike;
|
||||
use support\Redis;
|
||||
use support\Request;
|
||||
|
||||
class PostLikeService
|
||||
{
|
||||
|
||||
use CrudServiceTrait;
|
||||
|
||||
/**
|
||||
* 指定当前要操作的模型
|
||||
*/
|
||||
protected string $modelClass = PostLike::class;
|
||||
|
||||
/**
|
||||
* 验证器
|
||||
*/
|
||||
protected $validator = PostLikeValidate::class;
|
||||
|
||||
/**
|
||||
* 获取验证器
|
||||
*/
|
||||
public function getValidator()
|
||||
{
|
||||
return new $this->validator;
|
||||
}
|
||||
|
||||
/** 分页列表 */
|
||||
public function serviceSelfList(Request $request, string $scene = 'self')
|
||||
{
|
||||
$result = $this->cqyProcess(ucfirst($scene), $request);
|
||||
if ($result === false) {
|
||||
$config = $this->buildQueryConfig($request, $scene);
|
||||
$limit = (int)$request->get('size', 15);
|
||||
$page = (int)$request->get('current', 1);
|
||||
$result = $this->logicList($config, $limit, $page);
|
||||
}
|
||||
return $this->postProcess(ucfirst($scene), $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造 CrudUtil 查询配置
|
||||
*/
|
||||
protected function buildQueryConfig(Request $request, string $scene = 'default'): array
|
||||
{
|
||||
$p = $request->all();
|
||||
|
||||
$config = [];
|
||||
$config['model'] = $this->modelClass;
|
||||
switch ($scene) {
|
||||
case 'default':
|
||||
$config['order']['id'] = 'desc';
|
||||
break;
|
||||
case 'self':
|
||||
$config['where']['user_id'] = $request->user->uid;
|
||||
$config['order']['id'] = 'desc';
|
||||
break;
|
||||
case 'index':
|
||||
$config['order']['id'] = 'desc';
|
||||
break;
|
||||
case 'show':
|
||||
$config['where']['id'] = $p['id'];
|
||||
$config['where']['status'] = 1;
|
||||
break;
|
||||
case 'store':
|
||||
break;
|
||||
case 'update':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
case 'destroy':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加前置处理
|
||||
*/
|
||||
public function beforeServiceStore($data, Request $request)
|
||||
{
|
||||
$data['user_id'] = $request->user->uid;;
|
||||
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['type'] = 1;
|
||||
MessageNotice::create($data);
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace app\common\service;
|
||||
|
||||
use app\common\logic\AuthLogic;
|
||||
use app\common\model\Corp;
|
||||
use app\common\validate\UserValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\common\model\User;
|
||||
@@ -178,7 +177,7 @@ class UserService
|
||||
|
||||
|
||||
/**
|
||||
* 获取微信小程序用户信息
|
||||
* 获取微信小程序用户信息(登录及获取手机号)
|
||||
*/
|
||||
public function wechatLogin(string $loginCode, string $phoneCode)
|
||||
{
|
||||
@@ -228,4 +227,46 @@ class UserService
|
||||
$refreshToken = (new AuthLogic())->generateRefreshToken($user->id, 'info');
|
||||
return array_merge($user->toArray(), ['access_token' => $token, 'is_bind' => true, 'refresh_token'=> $refreshToken, 'expires_in' => config('jwt.jwt_expiration')]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 小程序登录
|
||||
*/
|
||||
public function miniappLogin(array $data)
|
||||
{
|
||||
$logic = new UserLogic();
|
||||
$wechatService = new WechatService();
|
||||
$wxinfo = $wechatService->xcxOpenid($data['code']);
|
||||
|
||||
// 用户信息
|
||||
$user = User::firstOrCreate(
|
||||
['openid' => $wxinfo['openid']],
|
||||
['nickname' => '微信用户_'.$wxinfo['openid'], 'avatar' => getenv('MAIN_DOMAIN').'/avatar.png']
|
||||
);
|
||||
|
||||
|
||||
$jwt = new Jwt();
|
||||
$JwtPayload = $logic->buildJwtPayload($user);
|
||||
$JwtPayload['exp'] = $JwtPayload['exp'] + (86400 * 30);
|
||||
$token = $jwt->generateToken($JwtPayload);
|
||||
$refreshToken = (new AuthLogic())->generateRefreshToken($user->id, 'info');
|
||||
|
||||
return array_merge($user->toArray(), ['token' => $token, 'is_bind' => true, 'refresh_token'=> $refreshToken, 'expires_in' => config('jwt.jwt_expiration')]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取手机号
|
||||
*/
|
||||
public function miniappPhoneNumber(array $data)
|
||||
{
|
||||
// 手机号
|
||||
$wechatService = new WechatService();
|
||||
$wxinfo = $wechatService->xcxPhoneNumber($data['phone_code']);
|
||||
|
||||
$uinfo = User::where('id', $data['user_id'])->first();
|
||||
$uinfo->phone = $wxinfo['phone_info']['phoneNumber'];
|
||||
$uinfo->save();
|
||||
|
||||
return $wxinfo;
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ namespace app\common\service;
|
||||
|
||||
use app\common\model\User;
|
||||
|
||||
use EasyWeChat\MiniApp\Application as xcxApplication;
|
||||
use EasyWeChat\OpenPlatform\Application;
|
||||
use support\Redis;
|
||||
use GuzzleHttp\Client;
|
||||
@@ -178,4 +179,58 @@ class WechatService
|
||||
|
||||
return json_decode(file_get_contents($url, false, stream_context_create($options)), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序获取openid
|
||||
* @param string $code
|
||||
* @return array
|
||||
* @throws BusinessException
|
||||
*/
|
||||
public function xcxOpenid(string $code): array
|
||||
{
|
||||
|
||||
$config = [
|
||||
'app_id' => getenv('WECHAT_MINI_APPID'),
|
||||
'secret' => getenv('WECHAT_MINI_SECRET'),
|
||||
'response_type' => 'array',
|
||||
'log' => [
|
||||
'level' => 'debug',
|
||||
'file' => runtime_path().'/mzl/wechat.log',
|
||||
]
|
||||
];
|
||||
// 创建微信小程序对象
|
||||
$wechat = new xcxApplication($config);
|
||||
// 获取 session_key 和 openid
|
||||
return $wechat->getUtils()->codeToSession($code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序获取手机号
|
||||
* @param string $phone_code
|
||||
* @return mixed
|
||||
* @throws BusinessException
|
||||
*/
|
||||
public function xcxPhoneNumber(string $phone_code)
|
||||
{
|
||||
$config = [
|
||||
'app_id' => getenv('WECHAT_MINI_APPID'),
|
||||
'secret' => getenv('WECHAT_MINI_SECRET'),
|
||||
'response_type' => 'array',
|
||||
'log' => [
|
||||
'level' => 'debug',
|
||||
'file' => runtime_path().'/mzl/wechat.log',
|
||||
]
|
||||
];
|
||||
// 创建微信小程序对象
|
||||
$wechat = new xcxApplication($config);
|
||||
// getPhoneNumber
|
||||
$data = ['code' => $phone_code];
|
||||
$result = $wechat->getClient()->postJson('wxa/business/getuserphonenumber', $data);
|
||||
if (isset($result['phone_info'])) {
|
||||
// 业务处理 $result['phone_info']['phoneNumber']
|
||||
return $result;
|
||||
} else {
|
||||
throw new BusinessException($result['errmsg']);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user