提交其他文件

This commit is contained in:
2026-03-14 16:20:49 +08:00
parent a227deaecd
commit 0a19b334f8
1385 changed files with 73568 additions and 0 deletions

View File

@ -0,0 +1,19 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
return [
'middleware' => [
app\teamapi\http\middleware\InitMiddleware::class, // 初始化
app\teamapi\http\middleware\LoginMiddleware::class, // 登录验证
],
];

View File

@ -0,0 +1,31 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\teamapi\controller;
use app\common\controller\BaseLikeAdminController;
class BaseApiController extends BaseLikeAdminController
{
protected int $userId = 0;
protected array $userInfo = [];
public function initialize()
{
if (isset($this->request->userInfo) && $this->request->userInfo) {
$this->userInfo = $this->request->userInfo;
$this->userId = $this->request->userInfo['user_id'];
}
}
}

View File

@ -0,0 +1,183 @@
<?php
namespace app\teamapi\controller;
use app\teamapi\logic\OrderLogic;
class OrderController extends BaseApiController
{
public array $notNeedLogin = [];
/**
* @notes 茶艺师订单列表
* @return \think\response\Json
* @author Yzt
* @date 2025/12/31 15:03
* @data id
*/
public function orderTeamList(){
$userId = $this->userId;
$data = $this->request->post();
$result = OrderLogic::orderTeamList($data,$userId);
return $this->success('查询成功', $result, 1, 1);
}
/**
* @notes 茶艺师订单详情
* @return \think\response\Json
* @author Yzt
* @date 2025/12/31 15:03
* @data id
*/
public function orderDetails(){
$userId = $this->userId;
$data = $this->request->post();
$result = OrderLogic::orderDetails($data,$userId);
if ($result === false) {
return $this->fail(OrderLogic::getError());
}
return $this->success('', $result, 1, 1);
}
/**
* @notes 茶艺师接单
* @return \think\response\Json
* @author Yzt
* @date 2025/12/31 15:03
* @data id
*/
public function orderTake(){
$userId = $this->userId;
$data = $this->request->post();
$result = OrderLogic::orderTake($data,$userId);
if ($result === false) {
return $this->fail(OrderLogic::getError());
}
return $this->success('操作成功', [], 1, 1);
}
/**
* @notes 茶艺师取消接单
* @return \think\response\Json
* @author Yzt
* @date 2025/12/31 15:03
* @data idcancel
*/
public function orderCancel(){
$userId = $this->userId;
$data = $this->request->post();
$result = OrderLogic::orderCancel($data,$userId);
if ($result === false) {
return $this->fail(OrderLogic::getError());
}
return $this->success('操作成功', [], 1, 1);
}
/**
* @notes 茶艺师出发
* @return \think\response\Json
* @author Yzt
* @date 2025/12/31 15:03
* @data idcancel
*/
public function orderDepart(){
$userId = $this->userId;
$data = $this->request->post();
$result = OrderLogic::orderDepart($data,$userId);
if ($result === false) {
return $this->fail(OrderLogic::getError());
}
return $this->success('操作成功', [], 1, 1);
}
/**
* @notes 茶艺师到达
* @return \think\response\Json
* @author Yzt
* @date 2025/12/31 15:03
* @data idcancel
*/
public function orderArrive(){
$userId = $this->userId;
$data = $this->request->post();
$result = OrderLogic::orderArrive($data,$userId);
if ($result === false) {
return $this->fail(OrderLogic::getError());
}
return $this->success('操作成功', [], 1, 1);
}
/**
* @notes 茶艺师打卡
* @return \think\response\Json
* @author Yzt
* @date 2025/12/31 15:03
* @data idcancel
*/
public function orderImage(){
$userId = $this->userId;
$data = $this->request->post();
$result = OrderLogic::orderImage($data,$userId);
if ($result === false) {
return $this->fail(OrderLogic::getError());
}
return $this->success('操作成功', [], 1, 1);
}
/**
* @notes 完成订单
* @return \think\response\Json
* @author Yzt
* @date 2025/12/31 15:03
* @data idcancel
*/
public function orderFinish(){
$userId = $this->userId;
$data = $this->request->post();
$result = OrderLogic::orderFinish($data,$userId);
if ($result === false) {
return $this->fail(OrderLogic::getError());
}
return $this->success('操作成功', [], 1, 1);
}
/**
* @notes 删除订单
* @return \think\response\Json
* @author Yzt
* @date 2025/12/31 15:03
* @data idcancel
*/
public function orderDel(){
$userId = $this->userId;
$data = $this->request->post();
$result = OrderLogic::orderDel($data,$userId);
if ($result === false) {
return $this->fail(OrderLogic::getError());
}
return $this->success('操作成功', [], 1, 1);
}
/**
* @notes 费用明细
* @return \think\response\Json
* @author Yzt
* @date 2025/12/31 15:03
* @data idcancel
*/
public function amountDetails(){
$userId = $this->userId;
$data = $this->request->post();
$result = OrderLogic::amountDetails($data,$userId);
if ($result === false) {
return $this->fail(OrderLogic::getError());
}
return $this->success('', $result, 1, 1);
}
}

View File

@ -0,0 +1,49 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\storeapi\controller;
use app\api\logic\SmsLogic;
use app\api\validate\SendSmsValidate;
/**
* 短信
* Class SmsController
* @package app\api\controller
*/
class SmsController extends BaseApiController
{
public array $notNeedLogin = ['sendCode'];
/**
* @notes 发送短信验证码
* @return \think\response\Json
* @author 段誉
* @date 2022/9/15 16:17
*/
public function sendCode()
{
$params = (new SendSmsValidate())->post()->goCheck();
$result = SmsLogic::sendCode($params);
if (true === $result) {
return $this->success('发送成功');
}
return $this->fail(SmsLogic::getError());
}
}

View File

@ -0,0 +1,89 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\teamapi\controller;
use app\common\cache\StoreUserTokenCache;
use app\common\model\store\StoreUserSession;
use app\teamapi\logic\TeamLoginLogic;
use app\teamapi\validate\{LoginAccountValidate, PasswordValidate, WechatLoginValidate};
/**
* 登录注册
* Class LoginController
* @package app\api\controller
*/
class TeamLoginController extends BaseApiController
{
public array $notNeedLogin = [ 'account', 'logout', 'codeUrl','resetPassword'];
/**
* @notes 账号密码/手机号密码/手机号验证码登录
* @return \think\response\Json
* @author 段誉
* @date 2022/9/16 10:42
*/
public function account()
{
// $userTokenCache = new StoreUserTokenCache();
// $userSession = StoreUserSession::where([['user_id', '=', 1], ['terminal', '=', 1]])->find();
// $userTokenCache->deleteUserInfo($userSession->token);
$params = (new LoginAccountValidate())->post()->goCheck();
$result = TeamLoginLogic::login($params);
if (false === $result) {
return $this->fail(TeamLoginLogic::getError());
}
return $this->data($result);
}
/**
* @notes 重置密码
* @return \think\response\Json
* @author 胥聪
* @date 2025/12/16 14:30
*/
public function resetPassword()
{
$params = (new PasswordValidate())->post()->goCheck('resetPassword');
$result = TeamLoginLogic::resetPassword($params);
if (true === $result) {
return $this->success('操作成功', [], 1, 1);
}
return $this->fail(TeamLoginLogic::getError());
}
/**
* @notes 退出登录
* @return \think\response\Json
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author 段誉
* @date 2022/9/16 10:42
*/
public function logout()
{
TeamLoginLogic::logout($this->userInfo);
return $this->success();
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace app\teamapi\controller;
use app\teamapi\logic\TrainingLogic;
class TrainingController extends BaseApiController
{
/**
* @notes 茶艺师培训列表
* @return \think\response\Json
* @author 胥聪
* @date 2026/2/12 1:02
*/
public function trainingList(){
$data = $this->request->post();
$result = TrainingLogic::trainingList($data);
return $this->success('查询成功', $result, 1, 1);
}
/**
* @notes 茶艺师培训详情
* @return \think\response\Json
* @author 胥聪
* @date 2026/2/12 1:34
*/
public function trainingDetails(){
$data = $this->request->post();
$result = TrainingLogic::trainingDetails($data);
return $this->success('查询成功', $result, 1, 1);
}
}

View File

@ -0,0 +1,63 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\teamapi\controller;
use app\common\enum\FileEnum;
use app\common\service\UploadService;
use Exception;
use think\response\Json;
/** 上传文件
* Class UploadController
* @package app\api\controller
*/
class UploadController extends BaseApiController
{
/**
* @notes 上传图片
* @return Json
* @author 胥聪
* @date 2025/12/17 16:34
*/
public function image()
{
try {
$result = UploadService::image(0, $this->userId,FileEnum::SOURCE_USER);
return $this->success('上传成功', $result);
} catch (Exception $e) {
return $this->fail($e->getMessage());
}
}
/**
* @notes 上传视频
* @return Json
* @author 胥聪
* @date 2025/12/17 16:34
*/
public function video()
{
try {
$cid = $this->request->post('cid', 0);
$result = UploadService::video($cid);
return $this->success('上传成功', $result);
} catch (Exception $e) {
return $this->fail($e->getMessage());
}
}
}

View File

@ -0,0 +1,392 @@
<?php
namespace app\teamapi\controller;
use app\api\validate\SendSmsValidate;
use app\teamapi\logic\UserLogic;
use app\teamapi\validate\AddressValidate;
class UserController extends BaseApiController
{
public array $notNeedLogin = ['teaStoreCity'];
/**
* @notes 获取个人信息
* @return \think\response\Json
* @author Yzt
* @date 2025/12/28 19:46
*/
public function info()
{
$result = UserLogic::info($this->userId);
return $this->data($result);
}
/**
* @notes 修改头像
* @return \think\response\Json
* @author Yzt
* @date 2025/12/28 19:46
*/
public function editAvatar()
{
$data = $this->request->post();
$result = UserLogic::editAvatar($data,$this->userId);
return $this->data($result);
}
/**
* @notes 修改昵称
* @return \think\response\Json
* @author Yzt
* @date 2025/12/28 19:46
*/
public function editNickname()
{
$data = $this->request->post();
$result = UserLogic::editNickname($data,$this->userId);
return $this->data($result);
}
/**
* @notes 获取已开通城市列表
* @return \think\response\Json
* @author Yzt
* @date 2025/12/28 19:46
*/
public function teaStoreCity()
{
$result = UserLogic::getTeaStoreCity();
return $this->data($result);
}
public function editServer()
{
$data = $this->request->post();
$result = UserLogic::editServer($data,$this->userId);
return $this->data($result);
}
/**
* @notes 修改工作时间
* @return \think\response\Json
* @author Yzt
* @date 2025/12/28 19:46
*/
public function editWork()
{
$data = $this->request->post();
$result = UserLogic::editWork($data,$this->userId);
return $this->data($result);
}
/**
* @notes 茶艺师地址簿列表
* @return \think\response\Json
* @author Yzt
* @date 2025/12/28 19:46
*/
public function addressList()
{
$result = UserLogic::addressList($this->userId);
return $this->data($result);
}
/**
* @notes 茶艺师详情
* @return \think\response\Json
* @author Yzt
* @date 2025/12/28 19:46
*/
public function addressDetails()
{
$post = $this->request->post();
$result = UserLogic::addressDetails($post,$this->userId);
if (false === $result) {
return $this->fail(UserLogic::getError());
}
return $this->data($result);
}
/**
* @notes 茶艺师地址簿列表
* @return \think\response\Json
* @author Yzt
* @date 2025/12/28 19:46
*/
public function addAddress()
{
$params = (new AddressValidate())->post()->goCheck('addAddress');
$result = UserLogic::addAddress($params,$this->userId);
if (false === $result) {
return $this->fail(UserLogic::getError());
}
return $this->data($result);
}
/**
* @notes 茶艺师地址簿列表
* @return \think\response\Json
* @author Yzt
* @date 2025/12/28 19:46
*/
public function editAddress()
{
$post = $this->request->post();
$result = UserLogic::editAddress($post,$this->userId);
if (false === $result) {
return $this->fail(UserLogic::getError());
}
return $this->data($result);
}
/**
* @notes 茶艺师选择地址
* @return \think\response\Json
* @author Yzt
* @date 2025/12/28 19:46
*/
public function selAddress()
{
$post = $this->request->post();
$result = UserLogic::selAddress($post,$this->userId);
if (false === $result) {
return $this->fail(UserLogic::getError());
}
return $this->data($result);
}
/**
* @notes 茶艺师地址簿列表
* @return \think\response\Json
* @author Yzt
* @date 2025/12/28 19:46
*/
public function delAddress()
{
$post = $this->request->post();
$result = UserLogic::delAddress($post,$this->userId);
return $this->data($result);
}
/**
* @notes 茶艺师个人介绍页
* @return \think\response\Json
* @author Yzt
* @date 2025/12/28 19:46
*/
public function Introduction()
{
$result = UserLogic::Introduction($this->userId);
return $this->data($result);
}
/**
* @notes 茶艺师个人介绍页
* @return \think\response\Json
* @author Yzt
* @date 2025/12/28 19:46
*/
public function editIntrod()
{
$post = $this->request->post();
$result = UserLogic::editIntrod($post,$this->userId);
if (false === $result) {
return $this->fail(UserLogic::getError());
}
return $this->data($result);
}
/**
* @notes 茶艺师资质信息
* @return \think\response\Json
* @author Yzt
* @date 2025/12/28 19:46
*/
public function certDetails()
{
$post = $this->request->post();
$result = UserLogic::certDetails($post,$this->userId);
if (false === $result) {
return $this->fail(UserLogic::getError());
}
return $this->data($result);
}
/**
* @notes 茶艺师资质上传
* @return \think\response\Json
* @author Yzt
* @date 2025/12/28 19:46
*/
public function addCert()
{
$post = $this->request->post();
$result = UserLogic::addCert($post,$this->userId);
if (false === $result) {
return $this->fail(UserLogic::getError());
}
return $this->data($result);
}
/**
* @notes 茶艺师资质上传
* @return \think\response\Json
* @author Yzt
* @date 2025/12/28 19:46
*/
public function editCert()
{
$post = $this->request->post();
$result = UserLogic::editCert($post,$this->userId);
if (false === $result) {
return $this->fail(UserLogic::getError());
}
return $this->data($result);
}
/**
* @notes 新增银行卡
* @return \think\response\Json
* @author Yzt
* @date 2025/12/28 19:46
*/
public function addBank()
{
$post = (new SendSmsValidate())->post()->goCheck('addBank');
$result = UserLogic::addBank($post,$this->userId);
if (false === $result) {
return $this->fail(UserLogic::getError());
}
return $this->data($result);
}
/**
* @notes 银行卡列表
* @return \think\response\Json
* @author Yzt
* @date 2025/12/29 19:46
*/
public function checkBank()
{
$result = UserLogic::checkBank($this->userId);
return $this->data($result);
}
/**
* @notes 删除银行卡
* @return \think\response\Json
* @author Yzt
* @date 2025/12/29 19:46
*/
public function delBank()
{
$post = $this->request->post();
$result = UserLogic::delBank($post);
if (false === $result) {
return $this->fail(UserLogic::getError());
}
return $this->data($result);
}
/**
* @notes 流水明细列表
* @return \think\response\Json
* @author Yzt
* @date 2025/12/29 19:46
*/
public function checkAccountList()
{
$post = $this->request->post();
$result = UserLogic::checkAccountList($post,$this->userId);
if (false === $result) {
return $this->fail(UserLogic::getError());
}
return $this->data($result);
}
/**
* @notes 流水明细列表
* @return \think\response\Json
* @author Yzt
* @date 2025/12/29 19:46
*/
public function accounDetails()
{
$post = $this->request->post();
$result = UserLogic::accounDetails($post,$this->userId);
if (false === $result) {
return $this->fail(UserLogic::getError());
}
return $this->data($result);
}
/**
* @notes 流水明细列表
* @return \think\response\Json
* @author Yzt
* @date 2025/12/29 19:46
*/
public function reflectDetails()
{
$post = $this->request->post();
$result = UserLogic::reflectDetails($post,$this->userId);
if (false === $result) {
return $this->fail(UserLogic::getError());
}
return $this->data($result);
}
/**
* @notes 茶艺师提现
* @return \think\response\Json
* @author Yzt
* @date 2025/12/29 19:46
*/
public function submitReflect()
{
$post = $this->request->post();
$result = UserLogic::submitReflect($post,$this->userId);
if (false === $result) {
return $this->fail(UserLogic::getError());
}
return $this->data($result);
}
}

View File

@ -0,0 +1,56 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\teamapi\http\middleware;
use app\common\exception\ControllerExtendException;
use app\teamapi\controller\BaseApiController;
use think\exception\ClassNotFoundException;
use think\exception\HttpException;
class InitMiddleware
{
/**
* @notes 初始化
* @param $request
* @param \Closure $next
* @return mixed
* @throws ControllerExtendException
* @author 段誉
* @date 2022/9/6 18:17
*/
public function handle($request, \Closure $next)
{
//获取控制器
try {
$controller = str_replace('.', '\\', $request->controller());
$controller = '\\app\\teamapi\\controller\\' . $controller . 'Controller';
$controllerClass = invoke($controller);
if (($controllerClass instanceof BaseApiController) === false) {
throw new ControllerExtendException($controller, '404');
}
} catch (ClassNotFoundException $e) {
throw new HttpException(404, 'controller not exists:' . $e->getClass());
}
//创建控制器对象
$request->controllerObject = invoke($controller);
return $next($request);
}
}

View File

@ -0,0 +1,74 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\teamapi\http\middleware;
use app\common\cache\TeamUserTokenCache;
use app\common\service\JsonService;
use app\teamapi\service\TeamUserTokenService;
use think\facade\Config;
class LoginMiddleware
{
/**
* @notes 登录验证
* @param $request
* @param \Closure $next
* @return mixed|\think\response\Json
* @author 令狐冲
* @date 2021/7/1 17:33
*/
public function handle($request, \Closure $next)
{
$token = $request->header('token');
//判断接口是否免登录
$isNotNeedLogin = $request->controllerObject->isNotNeedLogin();
//不直接判断$isNotNeedLogin结果使不需要登录的接口通过为了兼容某些接口可以登录或不登录访问
if (empty($token) && !$isNotNeedLogin) {
//没有token并且该地址需要登录才能访问, 指定show为0前端不弹出此报错
return JsonService::fail('请求参数缺token', [], 0, 0);
}
$userInfo = (new TeamUserTokenCache())->getUserInfo($token);
if (empty($userInfo) && !$isNotNeedLogin) {
//token过期无效并且该地址需要登录才能访问
return JsonService::fail('登录超时,请重新登录', [], -1, 0);
}
//token临近过期自动续期
if ($userInfo) {
//获取临近过期自动续期时长
$beExpireDuration = Config::get('project.user_token.be_expire_duration');
//token续期
if (time() > ($userInfo['expire_time'] - $beExpireDuration)) {
$result = teamUserTokenService::overtimeToken($token);
//续期失败(数据表被删除导致)
if (empty($result)) {
return JsonService::fail('登录过期', [], -1);
}
}
}
//给request赋值用于控制器
$request->userInfo = $userInfo;
$request->userId = $userInfo['user_id'] ?? 0;
return $next($request);
}
}

View File

@ -0,0 +1,37 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\teamapi\lists;
use app\common\lists\BaseDataLists;
abstract class BaseApiDataLists extends BaseDataLists
{
protected array $userInfo = [];
protected int $userId = 0;
public string $export;
public function __construct()
{
parent::__construct();
if (isset($this->request->userInfo) && $this->request->userInfo) {
$this->userInfo = $this->request->userInfo;
$this->userId = $this->request->userId;
}
$this->export = $this->request->get('export', '');
}
}

View File

@ -0,0 +1,548 @@
<?php
namespace app\teamapi\logic;
use app\common\logic\BaseLogic;
use app\common\model\teamaster\Teamaster;
use app\common\model\teamaster\TeamasterUser;
use app\common\model\teamaster\TeamasterAddress;
use app\common\model\teastore\TeaStore;
use app\common\model\teastore\TeaStoreCity;
use app\common\model\teamaster\TeamasterCert;
use app\common\model\teamaster\TeamasterUserBank;
use app\common\model\teamaster\TeamasterLeaf;
use app\common\model\order\OrderTeamaster;
use app\common\model\order\OrderTeamasterLeaf;
use app\common\model\user\User;
use app\common\model\teamaster\TeamasterAccountLog;
use app\common\service\FileService;
use app\common\service\pay\WxRefundService;
use think\facade\Db;
use think\facade\Config;
class OrderLogic extends BaseLogic
{
public static function orderTeamList($post,$user_id){
$os = [28, 29, 30, 31, 32, 40, 41, 42, 43];
$od = "start_time desc";
// 优化判断逻辑:使用 !empty() 更简洁
if (!empty($post['order_status'])) {
$os = explode(",", $post['order_status']);
$od = "start_time asc";
}
// 优化:$s 应该初始化为空数组而不是空字符串
$s = [];
// 优化判断逻辑:使用 !empty() 更简洁
if (!empty($post['search'])) {
$a = $post['search'];
$s = ['address', 'like', '%' . $a . '%'];
}
$team_user = TeamasterUser::where('id', $user_id)->find();
$title = $team_user->nickname . '的预约单';
// 构建基础查询条件
$baseQuery = [
['del', '=', 0],
['team_user_id', '=', $user_id]
];
// 处理时间筛选逻辑
$timeQuery = [];
if (!empty($post['is_time']) && $post['is_time'] == 1) {
$todayStart = strtotime(date('Y-m-d'));
$tomorrowStart = $todayStart + 86400;
$timeQuery = [
['start_time', '>=', $todayStart],
['start_time', '<', $tomorrowStart]
];
}
// 优化count查询合并所有条件
$countQuery = OrderTeamaster::where($baseQuery)
->where($timeQuery)
->whereIn('order_status', $os);
// 如果有搜索条件,添加到查询
if (!empty($s)) {
$countQuery->where($s[0], $s[1], $s[2]);
}
$count = $countQuery->count();
// 优化数据查询:使用相同的查询条件
$listsQuery = OrderTeamaster::where($baseQuery)
->where($timeQuery)
->whereIn('order_status', $os);
// 如果有搜索条件,添加到查询
if (!empty($s)) {
$listsQuery->where($s[0], $s[1], $s[2]);
}
$lists = $listsQuery->field('id,server_type,day_time,address,order_status,longitude,latitude,start_time,end_time,store_id,team_income_price,pay_time')
->page($post['page'], $post['size'])
->order($od)
->select();
$timekeeping = 0;
// 支付时间 + 10分钟 = 固定的过期时间点
// 当前时间到过期时间点的剩余秒数
if ($lists) {
foreach ($lists as &$item) {
$expire_time = $item['pay_time'] + 600;
// 优化使用switch或更简洁的if结构
if ($item['order_status'] == 28) {
$timekeeping = $expire_time - time();
} elseif ($item['order_status'] == 29) {
$timekeeping = $item['start_time'] - time();
} elseif ($item['order_status'] == 30 || $item['order_status'] == 31) {
$timekeeping = $item['end_time'] - time();
}
// 优化:减少重复查询
if ($item['server_type'] == 1 && !empty($item['store_id'])) {
$store = TeaStore::where('id', $item['store_id'])->find();
$item['title'] = $store->name ?? '';
} elseif ($item['server_type'] == 2) {
$item['title'] = $title;
}
$item['timekeeping'] = $timekeeping;
$item['day_time'] = date('m-d', $item['day_time']);
$item['start_time'] = date('H:i', $item['start_time']); // 修正:应该是 H:i 而不是 H:s
$item['end_time'] = date('H:i', $item['end_time']); // 修正:应该是 H:i 而不是 H:s
}
}
$data = [
'list' => $lists,
'page' => $post['page'],
'size' => $post['size'],
'count' => $count,
'more' => is_more($count, $post['page'], $post['size'])
];
return $data;
}
public static function orderDetails($post,$user_id){
Db::startTrans();
try {
$team_user = TeamasterUser::where('id',$user_id)->find();
$item = OrderTeamaster::where('del',0)
->where('id',$post['id'])
->find();
if($item['server_type'] == 1){
$store = TeaStore::where('id',$item['store_id'])->find();
$item['title'] = $store->name;
}
$timekeeping = 0;
if($item['order_status'] == 28){
$timekeeping = time()-$item['pay_time'];
}elseif ($item['order_status'] == 29||$item['order_status'] == 30){
$timekeeping = $item['start_time']-time();
}elseif ($item['order_status'] == 31){
$timekeeping = $item['end_time']-time();
}
$order_leaf = OrderTeamasterLeaf::where('order_id',$item['id'])->select();
$leaf_name = [];
foreach ($order_leaf as &$v){
$leaf_name[] = $v['leaf_name'].'('.$v['num'].')泡';
}
$user = User::where('id',$item['user_id'])->find();
$item['user_mobile'] = $user['mobile'];
$item['timekeeping'] =$timekeeping;
$item['leaf_name'] = implode(',',$leaf_name);
$item['title'] = $team_user->nickname.'的预约单';
$item['day_time'] = date('m-d', $item['day_time']);
$item['start_time'] = date('H:i', $item['start_time']);
$item['end_time'] = date('H:i', $item['end_time']);
$item['pay_time'] = date('Y-m-d H:i', $item['pay_time']);
$item['dtime'] = date('Y-m-d H:i', $item['dtime']);
$item['refund_time'] = date('Y-m-d H:i', $item['refund_time']);
$item['take_order_time'] = date('Y-m-d H:i', $item['take_order_time']);
$item['img_time'] = date('Y-m-d H:i', $item['img_time']);
$item['img'] = FileService::getImgUrl($item['img']);
$item['pay_way_title'] = '';
if($item['pay_way'] == 1){
$item['pay_way_title'] = "平台余额支付";
}
if($item['pay_way'] == 2){
$item['pay_way_title'] = "微信支付";
}
Db::commit();
return $item->toarray();
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
public static function orderTake($post,$user_id){
Db::startTrans();
try {
$order = OrderTeamaster::where([
'id'=>$post['id'],
'order_status'=>28,
'del'=>0
])->find();
if(!$order){
throw new \Exception('订单错误,请刷新页面');
}
$order->order_status = 29;
$order->take_order_time =time();
$order->save();
Db::commit();
return [];
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
public static function orderCancel($post,$user_id){
Db::startTrans();
try {
$order = OrderTeamaster::where([
'id'=>$post['id'],
'order_status'=>28,
'del'=>0
])->find();
if(!$order){
throw new \Exception('订单错误');
}
$WxRefundService = new WxRefundService();
$result =$WxRefundService->Refund($order,10,40);
Db::commit();
return [];
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
public static function orderDepart($post,$user_id){
Db::startTrans();
try {
$order = OrderTeamaster::where([
'id'=>$post['id'],
'order_status'=>29,
'del'=>0
])->find();
if(!$order){
throw new \Exception('订单错误,请刷新页面');
}
$order->order_status = 30;
$order->travel_time =time();
$order->save();
Db::commit();
return [
];
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
public static function orderArrive($post,$user_id){
Db::startTrans();
try {
$order = OrderTeamaster::where([
'id'=>$post['id'],
'order_status'=>30,
'del'=>0
])->find();
if(!$order){
throw new \Exception('订单错误,请刷新页面');
}
$lat1 = $post['longitude'];
$lng1 = $post['latitude'];
$lat2 = $order['longitude'];
$lng2 = $order['latitude'];
$distance = self::getAccurateDistance($lat1, $lng1, $lat2, $lng2, 'km');
if($distance>2){
throw new \Exception('未到达打卡距离');
}
$order->order_status = 31;
$order->arrival_time =time();
$order->save();
Db::commit();
return [];
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
public static function orderImage($post,$user_id){
Db::startTrans();
try {
$order = OrderTeamaster::where([
'id'=>$post['id'],
'order_status'=>31,
'del'=>0
])->find();
if(!$order){
throw new \Exception('订单错误,请刷新页面');
}
if($order['is_img'] == 1){
throw new \Exception('已打卡');
}
$end_time = time()+(3600*($order->hours+$order->renew_hour));
$order->img_time =time();
$order->img = $post['img'];
$order->start_time = time();
$order->end_time = $end_time;
$order->is_img = 1;
$order->save();
Db::commit();
return [];
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
public static function orderFinish($post,$user_id){
Db::startTrans();
try {
$order = OrderTeamaster::where([
'id'=>$post['id'],
'order_status'=>31,
'del'=>0
])->find();
if(!$order){
throw new \Exception('订单错误');
}
if($order['end_time']>time()){
throw new \Exception('订单还未结束');
}
if($order['is_img'] == 0){
throw new \Exception('还未打卡,请先打卡');
}
$team_user = TeamasterUser::where('id',$user_id)->find();
$team_income_price = $order->team_income_price+(($order->renew_price+$order->renew_tea_price)*0.65);
$order->order_status = 32;
$order->save();
$reserve = [
'team_user_id'=>$user_id,
'user_id'=>$order->user_id,
'change_object'=>$order->pay_way,
'change_type'=>1,
'action'=>1,
'before_amount'=>$team_user->user_money,
'after_amount'=>$team_user->user_money+$order->team_income_price,
'amount'=>$order->team_income_price,
'source_sn'=>$order->order_sn,
'remark'=>'茶艺师预定订单',
'status'=>1,
'create_time'=>time()
];
TeamasterAccountLog::create($reserve);
$team_user->user_money = $team_user->user_money + round($team_income_price,2);
$team_user->save();
Db::commit();
return [];
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
public static function orderDel($post,$user_id){
Db::startTrans();
try {
$order = OrderTeamaster::where([
'id'=>$post['id'],
'del'=>0
])->find();
if(!$order){
throw new \Exception('订单错误,请刷新页面');
}
$order->uptime =time();
$order->del = 1;
$order->save();
Db::commit();
return [
];
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
public static function amountDetails($post,$user_id){
try {
$order = OrderTeamaster::where([
'id'=>$post['id'],
'del'=>0
])->find();
$all_amount = $order->order_amount+$order->renew_price+$order->renew_tea_price;
$team_income_price = $order->team_income_price+(($order->renew_price+$order->renew_tea_price)*0.65);
$data = [
'server_price'=>$order->server_price,
'mileage_price'=>$order->mileage_price,
'server_all_price'=>$order->server_all_price+$order->renew_price,
'mileage_server_price'=>$order->mileage_server_price,
'hours'=>$order->hours+$order->renew_hour,
'tea_price'=>$order->tea_price+$order->renew_tea_price,
'teacup_price'=>$order->teacup_price,
'renew_price'=>$order->renew_price,
'renew_tea_price'=>$order->renew_tea_price,
'handling_fee'=>round($all_amount-$team_income_price,2),
'team_income_price'=>round($team_income_price,2),
'distance'=>$order->distance,
'all_amount'=>$all_amount,
'coupon_price'=>$order->coupon_price,
'tea_all_price'=>$order->renew_tea_price+$order->tea_price+$order->teacup_price
];
return $data;
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
}
/**
* 使用WGS84椭球模型计算距离Vincenty公式
* 精度:毫米级
*/
public static function getAccurateDistance($lat1, $lng1, $lat2, $lng2, $unit = 'm')
{
// WGS84椭球参数
$a = 6378137.0; // 长半轴(米)
$b = 6356752.314245; // 短半轴(米)
$f = 1 / 298.257223563; // 扁率
// 转换为弧度
$U1 = atan((1 - $f) * tan(deg2rad($lat1)));
$U2 = atan((1 - $f) * tan(deg2rad($lat2)));
$L = deg2rad($lng2 - $lng1);
$sinU1 = sin($U1);
$cosU1 = cos($U1);
$sinU2 = sin($U2);
$cosU2 = cos($U2);
$lambda = $L;
$lambdaP = 2 * M_PI;
$iterLimit = 100;
$sinLambda = 0;
$cosLambda = 0;
$sinSigma = 0;
$cosSigma = 0;
$sigma = 0;
$sinAlpha = 0;
$cosSqAlpha = 0;
$cos2SigmaM = 0;
while (abs($lambda - $lambdaP) > 1e-12 && --$iterLimit > 0) {
$sinLambda = sin($lambda);
$cosLambda = cos($lambda);
$sinSigma = sqrt(
($cosU2 * $sinLambda) * ($cosU2 * $sinLambda) +
($cosU1 * $sinU2 - $sinU1 * $cosU2 * $cosLambda) *
($cosU1 * $sinU2 - $sinU1 * $cosU2 * $cosLambda)
);
if ($sinSigma == 0) {
return 0; // 重合点
}
$cosSigma = $sinU1 * $sinU2 + $cosU1 * $cosU2 * $cosLambda;
$sigma = atan2($sinSigma, $cosSigma);
$sinAlpha = $cosU1 * $cosU2 * $sinLambda / $sinSigma;
$cosSqAlpha = 1 - $sinAlpha * $sinAlpha;
$cos2SigmaM = $cosSigma - 2 * $sinU1 * $sinU2 / $cosSqAlpha;
if (is_nan($cos2SigmaM)) {
$cos2SigmaM = 0;
}
$C = $f / 16 * $cosSqAlpha * (4 + $f * (4 - 3 * $cosSqAlpha));
$lambdaP = $lambda;
$lambda = $L + (1 - $C) * $f * $sinAlpha *
($sigma + $C * $sinSigma *
($cos2SigmaM + $C * $cosSigma *
(-1 + 2 * $cos2SigmaM * $cos2SigmaM)));
}
if ($iterLimit == 0) {
return NAN; // 公式未收敛
}
$uSq = $cosSqAlpha * ($a * $a - $b * $b) / ($b * $b);
$A = 1 + $uSq / 16384 * (4096 + $uSq * (-768 + $uSq * (320 - 175 * $uSq)));
$B = $uSq / 1024 * (256 + $uSq * (-128 + $uSq * (74 - 47 * $uSq)));
$deltaSigma = $B * $sinSigma *
($cos2SigmaM + $B / 4 *
($cosSigma * (-1 + 2 * $cos2SigmaM * $cos2SigmaM) -
$B / 6 * $cos2SigmaM * (-3 + 4 * $sinSigma * $sinSigma) *
(-3 + 4 * $cos2SigmaM * $cos2SigmaM)));
$distance = $b * $A * ($sigma - $deltaSigma);
// 单位转换
switch (strtolower($unit)) {
case 'km':
return $distance / 1000;
case 'mile':
return $distance / 1609.344;
default:
return $distance;
}
}
}

View File

@ -0,0 +1,60 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\teamapi\logic;
use app\common\enum\notice\NoticeEnum;
use app\common\logic\BaseLogic;
/**
* 短信逻辑
* Class SmsLogic
* @package app\api\logic
*/
class SmsLogic extends BaseLogic
{
/**
* @notes 发送验证码
* @param $params
* @return false|mixed
* @author 段誉
* @date 2022/9/15 16:17
*/
public static function sendCode($params)
{
try {
$scene = NoticeEnum::getSceneByTag($params['scene']);
if (empty($scene)) {
throw new \Exception('场景值异常');
}
$result = event('Notice', [
'scene_id' => $scene,
'params' => [
'mobile' => $params['mobile'],
'code' => mt_rand(1000, 9999),
]
]);
return $result[0];
} catch (\Exception $e) {
self::$error = $e->getMessage();
return false;
}
}
}

View File

@ -0,0 +1,323 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\teamapi\logic;
use app\common\cache\WebScanLoginCache;
use app\common\logic\BaseLogic;
use app\common\model\store\StoreUser;
use app\teamapi\service\{TeamUserTokenService, WechatUserService};
use app\common\enum\{LoginEnum, notice\NoticeEnum, user\UserTerminalEnum, YesNoEnum};
use app\common\service\{ConfigService,
FileService,
sms\SmsDriver,
wechat\WeChatConfigService,
wechat\WeChatMnpService,
wechat\WeChatOaService,
wechat\WeChatRequestService};
//use app\common\model\teamster\{TeamasterUser, UserAuth};
use app\common\model\teamaster\TeamasterUser;
use think\facade\{Db, Config};
/**
* 登录逻辑
* Class LoginLogic
* @package app\api\logic
*/
class TeamLoginLogic extends BaseLogic
{
/**
* @notes 账号/手机号登录,手机号验证码
* @param $params
* @return array|false
* @author 段誉
* @date 2022/9/6 19:26
*/
public static function login($params)
{
Db::startTrans();
try {
// 账号/手机号 密码登录
$where = ['account|mobile' => $params['account']];
if ($params['scene'] == LoginEnum::MOBILE_CAPTCHA) {
//手机验证码登录
$where = ['mobile' => $params['mobile']];
}else{
$passwordSalt = Config::get('project.unique_identification');
$password = create_password($params['password'], $passwordSalt);
$where = ['mobile' => $params['account'],'password'=>$password];
}
$user = TeamasterUser::where($where)->findOrEmpty();
if ($user->isEmpty()) {
throw new \Exception('账号密码不正确');
}
//更新登录信息
$user->login_time = time();
$user->login_ip = request()->ip();
$user->save();
//设置token
$userInfo = TeamUserTokenService::setToken($user->id, $params['terminal']);
//返回登录信息
$avatar = $user->avatar ?: Config::get('project.default_image.user_avatar');
$avatar = FileService::getImgUrl($avatar);
Db::commit();
return [
'nickname' => $userInfo['nickname'],
'sn' => $userInfo['sn'],
'mobile' => $userInfo['mobile'],
'avatar' => $avatar,
'token' => $userInfo['token'],
];
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 退出登录
* @param $userInfo
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author 段誉
* @date 2022/9/16 17:56
*/
public static function logout($userInfo)
{
//token不存在不注销
if (!isset($userInfo['token'])) {
return false;
}
//设置token过期
return TeamUserTokenService::expireToken($userInfo['token']);
}
/**
* @notes 获取微信请求code的链接
* @param string $url
* @return string
* @author 段誉
* @date 2022/9/20 19:47
*/
public static function codeUrl(string $url)
{
return (new WeChatOaService())->getCodeUrl($url);
}
/**
* @notes 更新登录信息
* @param $userId
* @throws \Exception
* @author 段誉
* @date 2022/9/20 19:46
*/
public static function updateLoginInfo($userId)
{
$user = User::findOrEmpty($userId);
if ($user->isEmpty()) {
throw new \Exception('用户不存在');
}
$time = time();
$user->login_time = $time;
$user->login_ip = request()->ip();
$user->update_time = $time;
$user->save();
}
/**
* @notes 小程序端绑定微信
* @param array $params
* @return bool
* @author 段誉
* @date 2022/9/20 19:46
*/
public static function mnpAuthLogin(array $params)
{
try {
//通过code获取微信openid
$response = (new WeChatMnpService())->getMnpResByCode($params['code']);
$response['user_id'] = $params['user_id'];
$response['terminal'] = UserTerminalEnum::WECHAT_MMP;
return self::createAuth($response);
} catch (\Exception $e) {
self::$error = $e->getMessage();
return false;
}
}
/**
* @notes 公众号端绑定微信
* @param array $params
* @return bool
* @throws \GuzzleHttp\Exception\GuzzleException
* @author 段誉
* @date 2022/9/16 10:43
*/
public static function oaAuthLogin(array $params)
{
try {
//通过code获取微信openid
$response = (new WeChatOaService())->getOaResByCode($params['code']);
$response['user_id'] = $params['user_id'];
$response['terminal'] = UserTerminalEnum::WECHAT_OA;
return self::createAuth($response);
} catch (\Exception $e) {
self::$error = $e->getMessage();
return false;
}
}
/**
* @notes 生成授权记录
* @param $response
* @return bool
* @throws \Exception
* @author 段誉
* @date 2022/9/16 10:43
*/
public static function createAuth($response)
{
//先检查openid是否有记录
$isAuth = UserAuth::where('openid', '=', $response['openid'])->findOrEmpty();
if (!$isAuth->isEmpty()) {
throw new \Exception('该微信已被绑定');
}
if (isset($response['unionid']) && !empty($response['unionid'])) {
//在用unionid找记录防止生成两个账号同个unionid的问题
$userAuth = UserAuth::where(['unionid' => $response['unionid']])
->findOrEmpty();
if (!$userAuth->isEmpty() && $userAuth->user_id != $response['user_id']) {
throw new \Exception('该微信已被绑定');
}
}
//如果没有授权,直接生成一条微信授权记录
UserAuth::create([
'user_id' => $response['user_id'],
'openid' => $response['openid'],
'unionid' => $response['unionid'] ?? '',
'terminal' => $response['terminal'],
]);
return true;
}
/**
* @notes 获取扫码登录地址
* @return array|false
* @author 段誉
* @date 2022/10/20 18:23
*/
public static function getScanCode($redirectUri)
{
try {
$config = WeChatConfigService::getOpConfig();
$appId = $config['app_id'];
$redirectUri = UrlEncode($redirectUri);
// 设置有效时间标记状态, 超时扫码不可登录
$state = MD5(time().rand(10000, 99999));
(new WebScanLoginCache())->setScanLoginState($state);
// 扫码地址
$url = WeChatRequestService::getScanCodeUrl($appId, $redirectUri, $state);
return ['url' => $url];
} catch (\Exception $e) {
self::$error = $e->getMessage();
return false;
}
}
/**
* @notes 更新用户信息
* @param $params
* @param $userId
* @return User
* @author 段誉
* @date 2023/2/22 11:19
*/
public static function updateUser($params, $userId)
{
return TeamasterUser::where(['id' => $userId])->update([
'nickname' => $params['nickname'],
'avatar' => FileService::setFileUrl($params['avatar']),
'is_new_user' => YesNoEnum::NO
]);
}
/**
* @notes 重置登录密码
* @param $params
* @return bool
* @author 段誉
* @date 2022/9/16 18:06
*/
public static function resetPassword(array $params)
{
// Db::startTrans();
try {
// 校验验证码
$smsDriver = new SmsDriver();
if (!$smsDriver->verify($params['mobile'], $params['code'], NoticeEnum::FIND_MOBILE_CAPTCHA)) {
throw new \Exception('验证码错误');
}
// 重置密码
$passwordSalt = Config::get('project.unique_identification');
$password = create_password($params['password'], $passwordSalt);
if($params['password']!= $params['password_confirm']){
throw new \Exception('两次输入不正确');
}
// 更新
TeamasterUser::where('mobile', $params['mobile'])->update([
'password' => $password
]);
return true;
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
}
}

View File

@ -0,0 +1,158 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\storeapi\logic;
use app\common\{enum\notice\NoticeEnum,
enum\user\UserTerminalEnum,
enum\YesNoEnum,
logic\BaseLogic,
model\teamaster\TeamasterCollect,
model\store\StoreUser,
model\user\UserAddress,
model\user\UserAuth,
model\user\UserCoupon,
model\user\UserMoneyLog,
model\user\UserStoreMoney,
service\FileService,
service\sms\SmsDriver,
service\wechat\WeChatMnpService};
use think\facade\{Db, Config};
/**
* 会员逻辑层
* Class UserLogic
* @package app\shopapi\logic
*/
class TeamUserLogic extends BaseLogic
{
/**
* @notes 个人中心
* @param array $userInfo
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author 段誉
* @date 2022/9/16 18:04
*/
public static function center(array $userInfo): array
{
$user = StoreUser::where(['id' => $userInfo['user_id']])
->field('id,sn,sex,account,nickname,real_name,avatar,mobile,create_time,is_new_user,user_money,password')
->findOrEmpty();
if (in_array($userInfo['terminal'], [UserTerminalEnum::WECHAT_MMP, UserTerminalEnum::WECHAT_OA])) {
$auth = UserAuth::where(['user_id' => $userInfo['user_id'], 'terminal' => $userInfo['terminal']])->find();
$user['is_auth'] = $auth ? YesNoEnum::YES : YesNoEnum::NO;
}
$user['has_password'] = !empty($user['password']);
$user->hidden(['password']);
return $user->toArray();
}
/**
* @notes 个人信息
* @param $userId
* @return array
* @author 段誉
* @date 2022/9/20 19:45
*/
public static function info(int $userId)
{
$user = User::where(['id' => $userId])
->field('id,sn,sex,account,password,nickname,real_name,avatar,mobile,create_time,user_money,member')
->findOrEmpty();
$user['has_password'] = !empty($user['password']);
$user['has_auth'] = self::hasWechatAuth($userId);
$user['version'] = config('project.version');
$user['collect_count'] = TeamasterCollect::where("user_id",$userId)
->where("status",1)
->count();
$user['coupon_count'] = UserCoupon::where("user_id",$userId)
->where("status",0)
->count();
$user->hidden(['password']);
return $user->toArray();
}
/**
* @notes 设置用户信息
* @param int $userId
* @param array $params
* @return User|false
* @author 段誉
* @date 2022/9/21 16:53
*/
public static function setInfo(int $userId, array $params)
{
try {
if ($params['field'] == "avatar") {
$params['value'] = FileService::setFileUrl($params['value']);
}
return User::update([
'id' => $userId,
$params['field'] => $params['value']]
);
} catch (\Exception $e) {
self::$error = $e->getMessage();
return false;
}
}
/**
* @notes 重置登录密码
* @param $params
* @return bool
* @author 段誉
* @date 2022/9/16 18:06
*/
public static function resetPassword(array $params)
{
Db::startTrans();
try {
// 校验验证码
$smsDriver = new SmsDriver();
if (!$smsDriver->verify($params['mobile'], $params['code'], NoticeEnum::FIND_LOGIN_PASSWORD_CAPTCHA)) {
throw new \Exception('验证码错误');
}
// 重置密码
$passwordSalt = Config::get('project.unique_identification');
$password = create_password($params['password'], $passwordSalt);
if($params['password']!= $params['password_confirm']){
throw new \Exception('两次输入不正确');
}
// 更新
StoreUser::where('mobile', $params['mobile'])->update([
'password' => $password
]);
return true;
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
}
}

View File

@ -0,0 +1,48 @@
<?php
namespace app\teamapi\logic;
use app\common\logic\BaseLogic;
use app\common\model\Training;
use app\common\service\FileService;
class TrainingLogic extends BaseLogic
{
public static function trainingList($post){
$search = "";
if(isset($post['search'])){
if($post['search']!=""&&$post['search']!=null){
$a = $post['search'];
$search = "title like '%".$a."%'";
}
}
$count = Training::where("type_id",1)->where($search)->count();
$lists = Training::where("type_id",1)
->where($search)
->page($post['page'], $post['size'])
->order("id","desc")
->select()
->toarray();
foreach($lists as $key=>$value){
$lists[$key]['image'] = FileService::getImgUrl($value['image']);
$lists[$key]['dtime'] = date("Y-m-d H:i:s",$value['dtime']);
}
$data = [
'list' => $lists,
'page' => $post['page'],
'size' => $post['size'],
'count' => $count,
'more' => is_more($count, $post['page'], $post['size'])
];
return $data;
}
public static function trainingDetails($data){
$result = Training::where("id",$data['id'])
->find();
$result['image'] = FileService::getImgUrl($result['image']);
$result['dtime'] = date("Y-m-d H:i:s",$result['dtime']);
$d['details'] = $result;
return $d;
}
}

View File

@ -0,0 +1,931 @@
<?php
namespace app\teamapi\logic;
use app\common\enum\notice\NoticeEnum;
use app\common\logic\BaseLogic;
use app\common\model\teamaster\Teamaster;
use app\common\model\teamaster\TeamasterAccountLog;
use app\common\model\teamaster\TeamasterUser;
use app\common\model\teamaster\TeamasterAddress;
use app\common\model\teastore\TeaStoreCity;
use app\common\model\teamaster\TeamasterCert;
use app\common\model\teamaster\TeamasterUserBank;
use app\common\model\user\User;
use app\common\service\FileService;
use app\common\model\teamaster\TeamasterUserReflect;
use app\common\service\sms\SmsDriver;
use think\facade\Config;
use think\facade\Db;
class UserLogic extends BaseLogic
{
public static function info(int $userId)
{
$user = TeamasterUser::where(['id' => $userId])
->field('id,sn,sex,account,password,cert_id,nickname,server_type,real_name,avatar,mobile,create_time,user_money,no_reflect_amount,work_day,work_start,work_end,address_id,is_mileage')
->findOrEmpty();
$user['work_time'] = $user->work_start.'~'.$user->work_end;
$result = array_map(function($n) {
$week = ['一', '二', '三', '四', '五', '六', '日'];
return '周' . $week[$n-1];
}, explode(',', $user->work_day));
$user['address'] = '';
if($user['address_id'] !== 0){
$team_address = TeamasterAddress::where([
'id'=>$user->address_id,
'del'=>0
])->find();
if($team_address){
$user['address'] = $team_address['address'];
}else{
$user['address'] = '';
}
}
$user['work_day'] = $user->work_day;
$user['work'] = implode(',',$result);
$user['avatar'] = FileService::getImgUrl($user['avatar']);
return $user->toArray();
}
public static function editAvatar($post,$user_id){
TeamasterUser::where('id',$user_id)->update([
'avatar'=>$post['avatar']
]);
return [];
}
public static function editNickname($post,$user_id){
TeamasterUser::where('id',$user_id)->update([
'nickname'=>$post['nickname']
]);
return [];
}
public static function getTeaStoreCity(){
$lists = TeaStoreCity::where("status",1)
->where("del",0)
->select();
$data = [
'list' => $lists
];
return $data;
}
public static function editServer($post,$user_id){
TeamasterUser::where('id',$user_id)->update([
'is_mileage'=>$post['is_mileage']
]);
return [];
}
public static function editWork($post,$user_id){
TeamasterUser::where('id',$user_id)->update([
'work_day'=>$post['work_day'],
'work_start'=>$post['work_start'],
'work_end'=>$post['work_end'],
]);
return [];
}
public static function addressList($user_id){
$address_list = TeamasterAddress::where([
'team_user_id'=>$user_id,
'del'=>0
])->select()->toArray();
return $address_list;
}
public static function addressDetails($post, $user_id){
try {
$list = TeamasterAddress::where('id',$post['id'])->find();
if(!$list){
throw new \Exception('信息不存在');
}
$city_name =TeaStoreCity::where('id',$list['city_id'])->find();
$list['city_name'] = $city_name['name'];
return $list->toarray();
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
}
public static function addAddress($post, $user_id){
try {
$addressCount = TeamasterAddress::where([
'team_user_id' => $user_id,
'del' => 0
])->count();
if($addressCount >= 5){
throw new \Exception('地址簿最多添加5条');
}
$data = [
'team_user_id' => $user_id,
'city_id' => $post['city_id'],
'longitude' => $post['longitude'],
'latitude' => $post['latitude'],
'address' => $post['address'],
'dtime' => time()
];
// 如果是第一条地址,设为默认
if($addressCount == 0){
$data['status'] = 1;
}
$addressInsert = TeamasterAddress::create($data);
$addressId = $addressInsert->id;
// 如果是第一条地址,更新用户默认地址
if($addressCount == 0){
TeamasterUser::where('id', $user_id)->update([
'address_id' => $addressId
]);
}
return [];
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
}
public static function editAddress($post,$user_id){
try {
$address = TeamasterAddress::where(['id'=>$post['id'],'del'=>0])->find();
if(!$address){
throw new \Exception('地址蒲不存在');
}
$post['uptime']=time();
$address->allowField(['city_id', 'longitude', 'latitude','address','uptime'])
->save($post);
return [];
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
}
public static function selAddress($post,$user_id){
try {
TeamasterAddress::where('team_user_id',$user_id)->update([
'status'=>0,
'uptime' => time()
]);
TeamasterAddress::where('id',$post['id'])->update(['status'=>1]);
TeamasterUser::where('id',$user_id)->update([
'address_id'=>$post['id']
]);
return [];
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
}
public static function delAddress($post,$user_id){
$user = TeamasterAddress::where([
'team_user_id'=>$user_id,
'del'=>0
])->count();
if($user ==1){
TeamasterUser::where([
'id'=>$user_id
])->update(['address_id',0]);
}
TeamasterAddress::where('id',$post['id'])->update([
'del'=>1,
'uptime'=>time()
]);
return [];
}
public static function Introduction($user_id){
$user = TeamasterUser::where('id',$user_id)->find();
$result = Teamaster::where('team_user_id',$user_id)->find();
$img_arr = explode(",",$result['image']);
foreach($img_arr as $key=>$value){
// if (isset($value) && strpos($value, 'uploads') !== false) {
// // 包含 "uploads"
// $img_arr[$key]= !empty($value) ? FileService::getFileUrl($value) : '';
// } else {
// // 不包含 "uploads"
// $img_arr[$key]= !empty($value) ? FileService::getFileUrl("uploads".$value) : '';
// }
$img_arr[$key] = FileService::getImgUrl($value);
}
$result['image_arr'] = $img_arr;
$result['level'] =$user['level'];
$result['price'] = $user['price'];
$result['mileage_price'] = $user['mileage_price'];
$result['star'] =$user['star'];
$result['age'] = self::calculateAge($result['both']);
$result['age_range'] = substr($result['both'], 2, 1).'0';
return $result->toarray();
}
public static function editIntrod($post,$user_id){
try {
$teamaster = Teamaster::where(['team_user_id'=>$user_id])->find();
if(!$teamaster){
throw new \Exception('信息不存在');
}
$post['uptime']=time();
$teamaster->allowField(['name', 'sex', 'both','weight','height','hobby_introduce','image','uptime'])
->save($post);
return [];
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
}
public static function certDetails($post,$user_id){
try {
$lists = TeamasterCert::where('id',$post['cert_id'])->find();
if(!$lists){
throw new \Exception('未找到资质信息');
}
$lists['license_img'] = FileService::getFileUrl($lists['license_img']);
$lists['cert_img'] = FileService::getFileUrl($lists['cert_img']);
$lists['fitness_img'] = FileService::getFileUrl($lists['fitness_img']);
return $lists->toarray();
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
}
public static function addCert($post,$user_id){
try {
$list =TeamasterCert::where(['team_user_id'=>$user_id])->find();
if($list){
throw new \Exception('已经添加资质');
}
$data = [
'license_img'=>$post['license_img'],
'cert_img'=>$post['cert_img'],
'fitness_img'=>$post['fitness_img'],
'status'=>0,
'team_user_id'=>$user_id,
'dtime'=>time()
];
$cert = TeamasterCert::create($data);
$cert_id = $cert->id;
TeamasterUser::where('id',$user_id)->update([
'cert_id'=>$cert_id
]);
return [];
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
}
public static function editCert($post,$user_id){
try {
$list =TeamasterCert::where(['id'=>$post['id'],'del'=>0])->find();
if(!$list){
throw new \Exception('资质信息不存在');
}
$post['uptime']=time();
$list->allowField(['license_img', 'cert_img', 'fitness_img','uptime'])
->save($post);
return [];
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
}
public static function addBank($params,$user_id){
Db::startTrans();
try {
// 校验验证码
$smsDriver = new SmsDriver();
// if (!$smsDriver->verify($params['mobile'], $params['code'], NoticeEnum::FIND_MOBILE_CAPTCHA)) {
// throw new \Exception('验证码错误');
// }
// 新增
TeamasterUserBank::create([
"team_user_id"=>$user_id,
"name"=>$params['name'],
"bank_name"=>$params['bank_name'],
"bank_card"=>$params['bank_card'],
"bank_open_name"=>$params['bank_open_name'],
"mobile"=>$params['mobile'],
"dtime"=>time()
]);
Db::commit();
return [];
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
public static function checkBank($user_id){
$lists = TeamasterUserBank::where("team_user_id",$user_id)
->where("del",0)
->where("status",1)
->order("id","desc")
->select()
->toarray();
foreach($lists as $key=>$value){
$lists[$key]['bank_card'] = substr($value['bank_card'], -4);
}
$data = [
'list' => $lists
];
return $data;
}
public static function delBank($params){
Db::startTrans();
try {
$result = TeamasterUserBank::where("id",$params['id'])->find();
if (!$result) {
throw new \Exception('暂无数据');
}
// 删除
$r = TeamasterUserBank::where("id",$params['id'])->update(['del'=>1]);
Db::commit();
if($r){
return [];
}
throw new \Exception('数据错误');
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
public static function checkAccountList($data,$user_id){
Db::startTrans();
try {
$times = date("Y-m");
list($year, $month) = explode('-', $times);
$startTimestamp = strtotime($year . '-' . $month . '-01 00:00:00');
$endTimestamp = strtotime(date('Y-m-t 23:59:59', $startTimestamp));
if(isset($data['times'])){
if($data['times']!=""&&$data['times']!=null){
list($year, $month) = explode('-', $data['times']);
// 转换为日期范围
$startTimestamp = strtotime($year . '-' . $month . '-01 00:00:00');
$endTimestamp = strtotime(date('Y-m-t 23:59:59', $startTimestamp));
}
}
$count = TeamasterAccountLog::where("team_user_id",$user_id)
->whereBetween('create_time', [$startTimestamp, $endTimestamp])
->count();
$lists = TeamasterAccountLog::where("team_user_id",$user_id)
->whereBetween('create_time', [$startTimestamp, $endTimestamp])
->page($data['page'], $data['size'])
->order("id","desc")
->select()
->toarray();
foreach ($lists as &$item){
$item['mobile'] = '';
if($item['change_type'] == 1||$item['change_type'] == 2||$item['change_type'] == 3){
$user = User::where('id',$item['user_id'])->find();
$item['mobile'] = $user['mobile'];
}
}
$data = [
'list' => $lists,
'page' => $data['page'],
'size' => $data['size'],
'count' => $count,
'more' => is_more($count, $data['page'], $data['size'])
];
return $data;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
public static function reflectDetails($data){
$result = TeamasterAccountLog::where("id",$data['id'])->find();
$reflect = TeamasterUserReflect::where('order_sn',$result->source_sn)->find();
$back = TeamasterUserBank::where('id',$reflect['bank_id'])->find();
$data = [
'dtime'=>date('Y-m-d H:i:s',$reflect['dtime']),
'amount'=>$reflect['amount'],
'back_name'=>$back['bank_name'],
'status'=>$reflect['status'],
'bank_card'=>substr($back['bank_card'], -4),
'update_dtime'=>$reflect['update_dtime']
];
return $data;
}
public static function accounDetails($data){
$result = TeamasterAccountLog::where("id",$data['id'])->find();
$user = User::where('id',$result['user_id'])->find();
$result['user_name'] = $user->nickname;
$result['create_time'] = date('Y-m-d H:i:s');
if( $result['change_object'] == 1){
$result['pay_way_title'] = "余额支付";
}
if( $result['change_object'] == 2){
$result['pay_way_title'] = "微信支付";
}
return $result->toarray();
}
public static function submitReflect($params,$user_id){
Db::startTrans();
try {
// 查询是否余额充足
$team_user = TeamasterUser::where("id",$user_id)->where("del",0)->find();
if($team_user == null){
throw new \Exception('暂无数据');
}
if($team_user['user_money'] < $params['amount']){
throw new \Exception('余额不足');
}
// 新增提现记录
$order_sn = createSn("teamaster_user_reflect","order_sn");
TeamasterUserReflect::create([
"team_user_id"=>$user_id,
"order_sn"=>$order_sn,
"bank_id"=>$params['bank_id'],
"amount"=>$params['amount'],
"dtime"=>time()
]);
// 计算扣除余额
$user_money = round($team_user['user_money']-$params['amount'],2);
// 计算总提现金额
$reflect_money = round($team_user['total_reflect_amount']+$params['amount'],2);
$dt['user_money'] = $user_money;
$dt['total_reflect_amount'] = $reflect_money;
$rs = TeamasterUser::where("id",$user_id)->update($dt);
if(!$rs){
throw new \Exception('计算错误');
}
// 新增流水
$data = [
'sn' => createSn("store_user_account_log","sn"),
'team_user_id' => $team_user->id,
'user_id'=>0,
'change_type' => 5,
'action' => 2,
"amount"=>$params['amount'],
'before_amount' => $team_user['user_money'],
'after_amount' => $user_money,
'source_sn' => $order_sn,
'remark' => "茶艺师提现"
];
$r = TeamasterAccountLog::create($data);
Db::commit();
if($r){
return [];
}
throw new \Exception('提现失败');
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* 根据生日计算年龄
* @param string|int $birthday 生日(时间戳或日期字符串)
* @return int
*/
public static function calculateAge($birthday)
{
if (empty($birthday)) {
return 0;
}
// 转换为时间戳
$birthTimestamp = is_numeric($birthday) ? $birthday : strtotime($birthday);
if ($birthTimestamp === false) {
return 0;
}
// 计算年龄
$birthYear = date('Y', $birthTimestamp);
$birthMonth = date('m', $birthTimestamp);
$birthDay = date('d', $birthTimestamp);
$currentYear = date('Y');
$currentMonth = date('m');
$currentDay = date('d');
$age = $currentYear - $birthYear;
// 如果当前月日小于生日月日年龄减1
if ($currentMonth < $birthMonth ||
($currentMonth == $birthMonth && $currentDay < $birthDay)) {
$age--;
}
return max(0, $age); // 确保年龄不小于0
}
public static function balanceLogList($post,$user_id){
$t = "";
if(isset($post['end_time'])){
if($post['end_time']!=""&&$post['end_time']!=null){
$end_time = strtotime($post['end_time']);
$t = "create_time <= '".$end_time."'";
}
}
$count = StoreUserAccountLog::where($t)->where("user_id",$user_id)->count();
$lists = StoreUserAccountLog::where($t)
->where("user_id",$user_id)
->page($post['page'], $post['size'])
->order("id","desc")
->select()
->toarray();
foreach($lists as $key=>$value){
$lists[$key]['mobile'] = "";
$lists[$key]['reflect_status'] = "";
if($value['change_type'] != 3){
$order = OrderStore::where("order_sn",$value['source_sn'])->find();
if($order!=null){
$user = User::where("id",$order['user_id'])->find();
$lists[$key]['mobile'] = $user['mobile'];
}
}else{
$reflect_status = StoreUserReflect::where("order_sn",$value['source_sn'])->find();
if($reflect_status!= null){
$lists[$key]['reflect_status'] = $reflect_status['status'];
}
}
}
$data = [
'list' => $lists,
'page' => $post['page'],
'size' => $post['size'],
'count' => $count,
'more' => is_more($count, $post['page'], $post['size'])
];
return $data;
}
public static function balanceLogDetails($post){
$details = StoreUserAccountLog::where("id",$post['id'])->find();
if($details['change_type'] == 3){
$order = StoreUserReflect::where("order_sn",$details['source_sn'])->find();
if($order!=null){
$bank = StoreUserBank::where("id",$order['bank_id'])->find();
$order['bank_name'] = $bank['bank_name'];
$order['bank_card'] = substr($bank['bank_card'], -4);
$order['dtime'] = date("Y-m-d H:i:s",$order['dtime']);
$order['update_dtime'] = date("Y-m-d H:i:s",$order['update_dtime']);
}else{
$order = [];
$order['bank_name'] = "";
$order['bank_card'] = "";
}
$details['order'] = $order;
}else{
$details['store'] = "";
$store = TeaStore::where("id",$details['store_id'])->find();
if($store!=null){
$details['store'] = $store;
}
$details['room'] = "";
$room = TeaStoreRoom::where("id",$details['room_id'])->find();
if($room!=null){
$details['room'] = $room;
}
$order = OrderStore::where("order_sn",$details['source_sn'])->find();
if($order!=null){
$user = User::where("id",$order['user_id'])->find();
$order['nickname'] = "";
$order['mobile'] = "";
if($user!=null){
$order['nickname'] = $user['nickname'];
$order['mobile'] = $user['mobile'];
}
$order['pay_way_title'] = "";
if( $order['pay_way'] == 1){
$order['pay_way_title'] = "余额支付";
}
if( $order['pay_way'] == 2){
$order['pay_way_title'] = "微信支付";
}
if( $order['pay_way'] == 3){
$order['pay_way_title'] = "门店余额支付";
}
if( $order['pay_way'] == 4){
$order['pay_way_title'] = "管理员添加";
}
$order['group'] = [];
$user_group = UserGroup::where("id",$order['group_coupon_id'])->find();
if($user_group!=null){
$order['group'] = TeaStoreGroup::where("id",$user_group['group_id'])->find();
$order['group']['yanquan_dtime'] = $user_group['update_dtime'];
$order['group']['qr_sn'] = $user_group['qr_sn'];
$order['group']['yanquan_status'] = $user_group['status'];
}
}else{
$order = [];
$order['group'] = [];
$order['pay_way_title'] = "";
$order['nickname'] = "";
$order['mobile'] = "";
}
$details['order'] = $order;
}
$data = [
'details' => $details
];
return $data;
}
public static function checkMoney($data){
$result = TeaStore::where("id",$data['store_id'])->find();
$d['store_msg'] = $result;
return $d;
}
public static function checkStoreUserList($data){
$count = StoreMember::where("store_id",$data['store_id'])->count();
$lists = StoreMember::where("store_id",$data['store_id'])
->page($data['page'], $data['size'])
->order("id","desc")
->select()
->toarray();
foreach($lists as $key=>$value){
$lists[$key]['user'] = User::where("id",$value['user_id'])->find();
}
$data = [
'list' => $lists,
'page' => $data['page'],
'size' => $data['size'],
'count' => $count,
'more' => is_more($count, $data['page'], $data['size'])
];
return $data;
}
public static function checkStoreUserDetails($params){
// 门店用户基本信息
$store_user_member = StoreMember::where("user_id",$params['user_id'])
->where("store_id",$params['store_id'])
->find();
// 用户基本信息
$user = User::where("id",$params['user_id'])->find();
$user['remark'] = $store_user_member['remark'];
$user['store_user_id'] = $store_user_member['id'];
$user['create_time'] = date("Y-m-d",strtotime($user['create_time']));
$user_member = UserAccountLog::where("id",$params['user_id'])->where("store_id",$params['store_id'])->where("action",2)->find();
// 会员到期时间
$user['expiration_time'] = "";
if($user_member != null){
$user['expiration_time'] = $user_member['expiration_time'];
}
$user_store_money = UserStoreMoney::where("user_id",$params['user_id'])->where("store_id",$params['store_id'])->find();
if($user_store_money != null){
$user['user_store_money'] = $user_store_money['money'];
}
// 门店用户总消费
$user['order_amount'] = OrderStore::where("store_id",$params['store_id'])->where("user_id",$params['user_id'])->sum("order_amount");
$data = [
'user' => $user
];
return $data;
}
public static function editStoreUserRemark($data){
Db::startTrans();
try {
// 查询是否余额充足
$StoreMemberUser = StoreMember::where("id",$data['id'])->where("status",1)->find();
if($StoreMemberUser == null){
throw new \Exception('暂无用户');
}
$StoreMemberUser::where("id",$data['id'])->update(['remark'=>$data['remark']]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
public static function checkStoreUserBuyList($data){
$count = UserAccountLog::where("store_id",$data['store_id'])
->where("user_id",$data['user_id'])
->where("action",2)
->count();
$lists = UserAccountLog::where("store_id",$data['store_id'])
->where("user_id",$data['user_id'])
->where("action",2)
->page($data['page'], $data['size'])
->order("id","desc")
->select()
->toarray();
foreach($lists as $key=>$value){
$lists[$key]['pay_way_title'] = "";
if( $value['change_object'] == 1){
$lists[$key]['pay_way_title'] = "余额支付";
}
if( $value['change_object'] == 2){
$lists[$key]['pay_way_title'] = "微信支付";
}
if( $value['change_object'] == 3){
$lists[$key]['pay_way_title'] = "支付宝支付";
}
$lists[$key]['store_name'] = TeaStore::where("id",$value['store_id'])->value("name");
}
$data = [
'list' => $lists,
'page' => $data['page'],
'size' => $data['size'],
'count' => $count,
'more' => is_more($count, $data['page'], $data['size'])
];
return $data;
}
public static function checkStoreAccountList($data,$user_id){
$times = date("Y-m");
list($year, $month) = explode('-', $times);
$startTimestamp = strtotime($year . '-' . $month . '-01 00:00:00');
$endTimestamp = strtotime(date('Y-m-t 23:59:59', $startTimestamp));
if(isset($data['times'])){
if($data['times']!=""&&$data['times']!=null){
list($year, $month) = explode('-', $data['times']);
// 转换为日期范围
$startTimestamp = strtotime($year . '-' . $month . '-01 00:00:00');
$endTimestamp = strtotime(date('Y-m-t 23:59:59', $startTimestamp));
}
}
$count = StoreUserAccountLog::where("user_id",$user_id)
->where("store_id",$data['store_id'])
->whereBetween('create_time', [$startTimestamp, $endTimestamp])
->where("action",1)
->count();
$all_price = StoreUserAccountLog::where("user_id",$user_id)
->where("store_id",$data['store_id'])
->whereBetween('create_time', [$startTimestamp, $endTimestamp])
->where("action",1)
->sum("amount");
$lists = StoreUserAccountLog::where("user_id",$user_id)
->where("store_id",$data['store_id'])
->whereBetween('create_time', [$startTimestamp, $endTimestamp])
->where("action",1)
->page($data['page'], $data['size'])
->order("id","desc")
->select()
->toarray();
foreach($lists as $key=>$value){
$lists[$key]['store'] = TeaStore::where("id",$value['store_id'])->find();
$lists[$key]['room'] = TeaStoreRoom::where("id",$value['room_id'])->find();
$lists[$key]['order'] = "";
$lists[$key]['group'] = "";
if($value['action'] == 1){
$order = OrderStore::where("order_sn",$value['source_sn'])->find();
$lists[$key]['order'] = $order;
if($order!=null){
$order_group = UserGroup::where("id",$order['group_coupon_id'])->find();
if($order_group!=null){
$lists[$key]['group'] = TeaStoreGroup::where("id",$order_group['group_id'])->find();
}
}
}
}
$data = [
'list' => $lists,
'page' => $data['page'],
'size' => $data['size'],
"all_price"=>$all_price,
'count' => $count,
'more' => is_more($count, $data['page'], $data['size'])
];
return $data;
}
public static function checkMoth($data,$user_id){
// 本月收入
$times = date("Y-m");
list($year, $month) = explode('-', $times);
$startTimestamp = strtotime($year . '-' . $month . '-01 00:00:00');
$endTimestamp = strtotime(date('Y-m-t 23:59:59', $startTimestamp));
$result['month'] = StoreUserAccountLog::where("store_id",$data['store_id'])
->whereBetween('create_time', [$startTimestamp, $endTimestamp])
->where("action",1)
->sum("amount");
// 今日收入
$today = date('Y-m-d');
$startTime = strtotime($today . ' 00:00:00');
$endTime = strtotime($today . ' 23:59:59');
$result['today_price'] = StoreUserAccountLog::where("store_id",$data['store_id'])
->whereBetween('create_time', [$startTime, $endTime])
->where("change_type","in","1,2")
->where("action",1)
->sum("amount");
// 今日验券
$result['yan_price'] = StoreUserAccountLog::where("store_id",$data['store_id'])
->whereBetween('create_time', [$startTime, $endTime])
->where("change_type",4)
->where("action",1)
->sum("amount");
// 昨日收入
$yesterday = date('Y-m-d', strtotime('-1 day'));
// 计算时间戳范围
$startTime = strtotime($yesterday . ' 00:00:00');
$endTime = strtotime($yesterday . ' 23:59:59');
$result['yesterday_price'] = StoreUserAccountLog::where("store_id",$data['store_id'])
->whereBetween('create_time', [$startTime, $endTime])
->where("change_type","in","1,2")
->where("action",1)
->sum("amount");
// 昨日验券
$result['yesterday_yan_price'] = StoreUserAccountLog::where("store_id",$data['store_id'])
->whereBetween('create_time', [$startTime, $endTime])
->where("change_type",4)
->where("action",1)
->sum("amount");
$d = [
"result"=>$result
];
return $d;
}
}

View File

@ -0,0 +1,121 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\teamapi\service;
use app\common\cache\TeamUserTokenCache;
use app\common\model\teamaster\TeamasterUserSession;
use think\facade\Config;
class TeamUserTokenService
{
/**
* @notes 设置或更新用户token
* @param $userId
* @param $terminal
* @return array|false|mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author 段誉
* @date 2022/9/16 10:10
*/
public static function setToken($userId, $terminal)
{
$time = time();
$userSession = TeamasterUserSession::where([['user_id', '=', $userId], ['terminal', '=', $terminal]])->find();
//获取token延长过期的时间
$expireTime = $time + Config::get('project.user_token.expire_duration');
$userTokenCache = new TeamUserTokenCache();
//token处理
if ($userSession) {
//清空缓存
$userTokenCache->deleteUserInfo($userSession->token);
//重新获取token
$userSession->token = create_token($userId);
$userSession->expire_time = $expireTime;
$userSession->update_time = $time;
$userSession->save();
} else {
//找不到在该终端的token记录创建token记录
$userSession = TeamasterUserSession::create([
'user_id' => $userId,
'terminal' => $terminal,
'token' => create_token($userId),
'expire_time' => $expireTime
]);
}
return $userTokenCache->setUserInfo($userSession->token);
}
/**
* @notes 延长token过期时间
* @param $token
* @return array|false|mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author 段誉
* @date 2022/9/16 10:10
*/
public static function overtimeToken($token)
{
$time = time();
$userSession = TeamasterUserSession::where('token', '=', $token)->find();
if ($userSession->isEmpty()) {
return false;
}
//延长token过期时间
$userSession->expire_time = $time + Config::get('project.user_token.expire_duration');
$userSession->update_time = $time;
$userSession->save();
return (new TeamUserTokenCache())->setUserInfo($userSession->token);
}
/**
* @notes 设置token为过期
* @param $token
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author 段誉
* @date 2022/9/16 10:10
*/
public static function expireToken($token)
{
$userSession = TeamasterUserSession::where('token', '=', $token)
->find();
if (empty($userSession)) {
return false;
}
$time = time();
$userSession->expire_time = $time;
$userSession->update_time = $time;
$userSession->save();
return (new TeamUserTokenCache())->deleteUserInfo($token);
}
}

View File

@ -0,0 +1,24 @@
<?php
namespace app\teamapi\validate;
use app\common\validate\BaseValidate;
class AddressValidate extends BaseValidate
{
protected $rule = [
'city_id' => 'require',
'longitude' => 'require',
'latitude' => 'require',
'address' => 'require',
];
protected $message = [
'city_id.require' => '请选择开通城市',
'longitude.mobile' => '经度不能为空',
'latitude.require' => '纬度不能为空',
'address.require' => '请填写详细地址',
];
}

View File

@ -0,0 +1,161 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\teamapi\validate;
use app\common\cache\UserAccountSafeCache;
use app\common\enum\LoginEnum;
use app\common\enum\notice\NoticeEnum;
use app\common\enum\user\UserTerminalEnum;
use app\common\enum\YesNoEnum;
use app\common\service\ConfigService;
use app\common\service\sms\SmsDriver;
use app\common\validate\BaseValidate;
use app\common\model\user\User;
use think\facade\Config;
/**
* 账号密码登录校验
* Class LoginValidate
* @package app\api\validate
*/
class LoginAccountValidate extends BaseValidate
{
protected $rule = [
'terminal' => 'require|in:' . UserTerminalEnum::WECHAT_MMP . ',' . UserTerminalEnum::WECHAT_OA . ','
. UserTerminalEnum::H5 . ',' . UserTerminalEnum::PC . ',' . UserTerminalEnum::IOS .
',' . UserTerminalEnum::ANDROID,
// 'scene' => 'require|in:' . LoginEnum::ACCOUNT_PASSWORD . ',' . LoginEnum::MOBILE_CAPTCHA . '|checkConfig',
'account' => 'require',
];
protected $message = [
'terminal.require' => '终端参数缺失',
'terminal.in' => '终端参数状态值不正确',
'scene.require' => '场景不能为空',
// 'scene.in' => '场景值错误',
'account.require' => '请输入账号',
'password.require' => '请输入密码',
];
/**
* @notes 登录场景相关校验
* @param $scene
* @param $rule
* @param $data
* @return bool|string
* @author 段誉
* @date 2022/9/15 14:37
*/
public function checkConfig($scene, $rule, $data)
{
$config = ConfigService::get('login', 'login_way');
if (!in_array($scene, $config)) {
return '不支持的登录方式';
}
// 账号密码登录
if (LoginEnum::ACCOUNT_PASSWORD == $scene) {
if (!isset($data['password'])) {
return '请输入密码';
}
return $this->checkPassword($data['password'], [], $data);
}
// 手机验证码登录
if (LoginEnum::MOBILE_CAPTCHA == $scene) {
if (!isset($data['code'])) {
return '请输入手机验证码';
}
return $this->checkCode($data['code'], [], $data);
}
return true;
}
/**
* @notes 登录密码校验
* @param $password
* @param $other
* @param $data
* @return bool|string
* @author 段誉
* @date 2022/9/15 14:39
*/
public function checkPassword($password, $other, $data)
{
//账号安全机制,连续输错后锁定,防止账号密码暴力破解
$userAccountSafeCache = new UserAccountSafeCache();
if (!$userAccountSafeCache->isSafe()) {
return '密码连续' . $userAccountSafeCache->count . '次输入错误,请' . $userAccountSafeCache->minute . '分钟后重试';
}
$where = [];
if ($data['scene'] == LoginEnum::ACCOUNT_PASSWORD) {
// 手机号密码登录
$where = ['account|mobile' => $data['account']];
}
$userInfo = User::where($where)
->field(['password,is_disable'])
->findOrEmpty();
if ($userInfo->isEmpty()) {
return '用户不存在';
}
if ($userInfo['is_disable'] === YesNoEnum::YES) {
return '用户已禁用';
}
if (empty($userInfo['password'])) {
$userAccountSafeCache->record();
return '用户不存在';
}
$passwordSalt = Config::get('project.unique_identification');
if ($userInfo['password'] !== create_password($password, $passwordSalt)) {
$userAccountSafeCache->record();
return '密码错误';
}
$userAccountSafeCache->relieve();
return true;
}
/**
* @notes 校验验证码
* @param $code
* @param $rule
* @param $data
* @return bool|string
* @author Tab
* @date 2021/8/25 15:43
*/
public function checkCode($code, $rule, $data)
{
$smsDriver = new SmsDriver();
$result = $smsDriver->verify($data['account'], $code, NoticeEnum::LOGIN_CAPTCHA);
if ($result) {
return true;
}
return '验证码错误';
}
}

View File

@ -0,0 +1,69 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\teamapi\validate;
use app\common\validate\BaseValidate;
/**
* 密码校验
* Class PasswordValidate
* @package app\api\validate
*/
class PasswordValidate extends BaseValidate
{
protected $rule = [
'mobile' => 'require|mobile',
'code' => 'require',
'password' => 'require|length:6,20|alphaNum',
'password_confirm' => 'require|confirm',
];
protected $message = [
'mobile.require' => '请输入手机号',
'mobile.mobile' => '请输入正确手机号',
'code.require' => '请填写验证码',
'password.require' => '请输入密码',
'password.length' => '密码须在6-25位之间',
'password.alphaNum' => '密码须为字母数字组合',
'password_confirm.require' => '请确认密码',
'password_confirm.confirm' => '两次输入的密码不一致'
];
/**
* @notes 重置登录密码
* @return PasswordValidate
* @author 段誉
* @date 2022/9/16 18:11
*/
public function sceneResetPassword()
{
return $this->only(['mobile', 'code', 'password', 'password_confirm']);
}
/**
* @notes 修改密码场景
* @return PasswordValidate
* @author 段誉
* @date 2022/9/20 19:14
*/
public function sceneChangePassword()
{
return $this->only(['password', 'password_confirm']);
}
}

View File

@ -0,0 +1,39 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\teamapi\validate;
use app\common\validate\BaseValidate;
/**
* 短信验证
* Class SmsValidate
* @package app\api\validate
*/
class SendSmsValidate extends BaseValidate
{
protected $rule = [
'mobile' => 'require|mobile',
'scene' => 'require',
];
protected $message = [
'mobile.require' => '请输入手机号',
'mobile.mobile' => '请输入正确手机号',
'scene.require' => '请输入场景值',
];
}