提交其他文件
This commit is contained in:
30
app/api/logic/AreaLogic.php
Normal file
30
app/api/logic/AreaLogic.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\area\City;
|
||||
use app\common\model\area\Area;
|
||||
class AreaLogic extends BaseLogic
|
||||
{
|
||||
public static function getArea(){
|
||||
$result = City::where('status',1)->with(['getArea'])->select()->toArray();
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function getDfaultArea($data){
|
||||
$result = Area::where("lng",$data['longitude'])->where("lat",$data['latitude'])->find();
|
||||
if($result == null){
|
||||
return self::getDfault();
|
||||
}
|
||||
// $r = City::where('city_id',$result['id'])->find();
|
||||
// if($r == null){
|
||||
// return self::getDfault();
|
||||
// }
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function getDfault(){
|
||||
return Area::where("lng","121.472644")->where("lat","31.231706")->find();
|
||||
}
|
||||
}
|
||||
111
app/api/logic/ArticleLogic.php
Normal file
111
app/api/logic/ArticleLogic.php
Normal file
@ -0,0 +1,111 @@
|
||||
<?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\api\logic;
|
||||
|
||||
use app\common\enum\YesNoEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\article\Article;
|
||||
use app\common\model\article\ArticleCate;
|
||||
use app\common\model\article\ArticleCollect;
|
||||
|
||||
|
||||
/**
|
||||
* 文章逻辑
|
||||
* Class ArticleLogic
|
||||
* @package app\api\logic
|
||||
*/
|
||||
class ArticleLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 文章详情
|
||||
* @param $articleId
|
||||
* @param $userId
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 17:09
|
||||
*/
|
||||
public static function detail($articleId, $userId)
|
||||
{
|
||||
// 文章详情
|
||||
$article = Article::getArticleDetailArr($articleId);
|
||||
// 关注状态
|
||||
$article['collect'] = ArticleCollect::isCollectArticle($userId, $articleId);
|
||||
|
||||
return $article;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 加入收藏
|
||||
* @param $userId
|
||||
* @param $articleId
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 16:52
|
||||
*/
|
||||
public static function addCollect($articleId, $userId)
|
||||
{
|
||||
$where = ['user_id' => $userId, 'article_id' => $articleId];
|
||||
$collect = ArticleCollect::where($where)->findOrEmpty();
|
||||
if ($collect->isEmpty()) {
|
||||
ArticleCollect::create([
|
||||
'user_id' => $userId,
|
||||
'article_id' => $articleId,
|
||||
'status' => YesNoEnum::YES
|
||||
]);
|
||||
} else {
|
||||
ArticleCollect::update([
|
||||
'id' => $collect['id'],
|
||||
'status' => YesNoEnum::YES
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 取消收藏
|
||||
* @param $articleId
|
||||
* @param $userId
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 16:59
|
||||
*/
|
||||
public static function cancelCollect($articleId, $userId)
|
||||
{
|
||||
ArticleCollect::update(['status' => YesNoEnum::NO], [
|
||||
'user_id' => $userId,
|
||||
'article_id' => $articleId,
|
||||
'status' => YesNoEnum::YES
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 文章分类
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/9/23 14:11
|
||||
*/
|
||||
public static function cate()
|
||||
{
|
||||
return ArticleCate::field('id,name')
|
||||
->where('is_show', '=', 1)
|
||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||
->select()->toArray();
|
||||
}
|
||||
|
||||
}
|
||||
169
app/api/logic/CommonLogic.php
Normal file
169
app/api/logic/CommonLogic.php
Normal file
@ -0,0 +1,169 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\service\ConfigService;
|
||||
use app\common\model\teastore\TeaStoreRoom;
|
||||
use app\common\model\order\OrderStore;
|
||||
use app\common\model\teastore\TeaStore;
|
||||
use think\facade\Db;
|
||||
use app\common\service\qrcode\QrcodeService;
|
||||
use app\common\service\iot\DoorService;
|
||||
|
||||
|
||||
class CommonLogic extends BaseLogic
|
||||
{
|
||||
public static function getCityAddress($data){
|
||||
$map_key = ConfigService::get("map_setting","map_key");
|
||||
$url ="https://apis.map.qq.com/ws/geocoder/v1/?location=".$data['latitude'].",".$data['longitude']."&key=".$map_key;
|
||||
$map = file_get_contents($url);
|
||||
$map_msg = json_decode($map, true);
|
||||
return $map_msg;
|
||||
}
|
||||
|
||||
public static function get7Time($params){
|
||||
Db::startTrans();
|
||||
try {
|
||||
$room = TeaStoreRoom::where([
|
||||
'id'=>$params['room_id'],
|
||||
'del'=>0
|
||||
])->find();
|
||||
if (!$room) {
|
||||
throw new \Exception('包间不存在');
|
||||
}
|
||||
|
||||
$date = $params['date'];
|
||||
if (strtotime($date) < strtotime(date('Y-m-d'))){
|
||||
throw new \Exception('预约时间错误');
|
||||
}
|
||||
|
||||
|
||||
|
||||
$list = OrderStore::where([
|
||||
'room_id'=>$room['id'],
|
||||
'is_transfer'=>0,
|
||||
])->where('end_time','>',time()-60*40)
|
||||
->where('order_status', 'in', [0, 1, 2])
|
||||
->column('timeslot');
|
||||
$start = strtotime(date("Y-m-d 00:00:00", strtotime($date)));
|
||||
$times =[];
|
||||
foreach ($list as $v) {
|
||||
$times = array_merge($times, explode(',', $v));
|
||||
}
|
||||
|
||||
|
||||
|
||||
$result = [];
|
||||
$weekMap = ['日', '一', '二', '三', '四', '五', '六'];
|
||||
|
||||
for ($day = 0; $day < 30; $day++) {
|
||||
$dayStart = $start + ($day * 86400);
|
||||
$dateStr = date('Y-m-d', $dayStart);
|
||||
$weekDay = date('w', $dayStart);
|
||||
|
||||
$dayData = [
|
||||
'display' => date('n/j', $dayStart) . '周' . $weekMap[$weekDay],
|
||||
'date' => $dateStr,
|
||||
'timestamp' => $dayStart,
|
||||
'time_slots' => []
|
||||
];
|
||||
|
||||
// 生成当天的时间段(8:00-22:00)
|
||||
$businessStart = strtotime($dateStr . ' 00:00:00');
|
||||
$businessEnd = strtotime($dateStr . ' 24:00:00');
|
||||
$currentTime = time();
|
||||
|
||||
for ($timeSlot = $businessStart; $timeSlot < $businessEnd; $timeSlot += 1800) {
|
||||
// 跳过已过期的时间
|
||||
if ($timeSlot < $currentTime-1800) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 判断类型和是否禁用
|
||||
$type = '1'; // 默认类型
|
||||
$disabled = 0;
|
||||
|
||||
// 如果是已预订的时间
|
||||
if (in_array($timeSlot, $times)) {
|
||||
$disabled = 1;
|
||||
$type = '2';
|
||||
}
|
||||
|
||||
$dayData['time_slots'][] = [
|
||||
'key' => $timeSlot,
|
||||
'start_time' => date('H:i', $timeSlot),
|
||||
'time' => date('H:i', $timeSlot), // 与原始代码保持一致
|
||||
'local_time' => date('Y/m/d', $timeSlot),
|
||||
'datetime' => date('Y-m-d H:i', $timeSlot),
|
||||
'timestamp' => $timeSlot,
|
||||
'type' => $type,
|
||||
'disabled' => $disabled ? 1 : 0
|
||||
];
|
||||
}
|
||||
|
||||
if (!empty($dayData['time_slots'])) {
|
||||
$result[] = $dayData;
|
||||
}
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return ['data' => ['time' => $result]];
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function speaker(){
|
||||
$notifyService = new \app\common\service\iot\SpeakerService();
|
||||
$re = $notifyService->sendSpeakerNotify('3402211281486');
|
||||
print_r($re);die;
|
||||
}
|
||||
|
||||
public static function qrcode($qrcode){
|
||||
$service = new QrcodeService();
|
||||
// 保存图片
|
||||
$result = $service->saveImage($qrcode);
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
public static function ce_ttlock($data){
|
||||
|
||||
|
||||
try {
|
||||
$service = new DoorService();
|
||||
$order = OrderStore::where(['id' => $data['order_id']])->whereIn('order_status',[1,2])->find();
|
||||
|
||||
if(!$order){
|
||||
throw new \Exception('订单错误');
|
||||
}
|
||||
$store_id = $order->store_id;
|
||||
$store =TeaStore::where('id',$store_id)->find();
|
||||
$room = TeaStoreRoom::where('id',$order->room_id)->find();
|
||||
|
||||
if($data['type'] ==1){
|
||||
$lock_no = $store->lock_no;
|
||||
if($lock_no<=0){
|
||||
throw new \Exception('请联系门店管理检查门锁配置');
|
||||
}
|
||||
}else{
|
||||
$lock_no = $room->lock_no;
|
||||
}
|
||||
$result = $service->unlockByNetwork($lock_no);
|
||||
if($result['errcode'] != 0){
|
||||
throw new \Exception('请联系门店管理检查门锁配置');
|
||||
}
|
||||
|
||||
|
||||
return [];
|
||||
}catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
36
app/api/logic/DouyinAfterVerifiLogic.php
Normal file
36
app/api/logic/DouyinAfterVerifiLogic.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use think\facade\Db;
|
||||
use app\common\service\DouyinVerifyService;
|
||||
|
||||
class DouyinAfterVerifiLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* @param $params
|
||||
* @return false|void
|
||||
* 抖音核销
|
||||
*/
|
||||
public static function setDouy($params){
|
||||
try {
|
||||
$service = new DouyinVerifyService();
|
||||
$result = $service->verify(
|
||||
$params['user_id'], $params['store_id'] ?? 0, $params['code'] ?? '', $params['type'] ?? 2
|
||||
);
|
||||
|
||||
|
||||
if ($result['success']) {
|
||||
return [];
|
||||
} else {
|
||||
throw new \Exception($result['message']);
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
170
app/api/logic/IndexLogic.php
Normal file
170
app/api/logic/IndexLogic.php
Normal file
@ -0,0 +1,170 @@
|
||||
<?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\api\logic;
|
||||
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\article\Article;
|
||||
use app\common\model\carousel\Carousel;
|
||||
use app\common\model\decorate\DecoratePage;
|
||||
use app\common\model\decorate\DecorateTabbar;
|
||||
use app\common\service\ConfigService;
|
||||
use app\common\service\FileService;
|
||||
|
||||
|
||||
/**
|
||||
* index
|
||||
* Class IndexLogic
|
||||
* @package app\api\logic
|
||||
*/
|
||||
class IndexLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 首页数据
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/9/21 19:15
|
||||
*/
|
||||
public static function getIndexData()
|
||||
{
|
||||
// 装修配置
|
||||
$decoratePage = DecoratePage::findOrEmpty(1);
|
||||
|
||||
// 首页文章
|
||||
$field = [
|
||||
'id', 'title', 'desc', 'abstract', 'image',
|
||||
'author', 'click_actual', 'click_virtual', 'create_time'
|
||||
];
|
||||
|
||||
$article = Article::field($field)
|
||||
->where(['is_show' => 1])
|
||||
->order(['id' => 'desc'])
|
||||
->limit(20)->append(['click'])
|
||||
->hidden(['click_actual', 'click_virtual'])
|
||||
->select()->toArray();
|
||||
|
||||
return [
|
||||
'page' => $decoratePage,
|
||||
'article' => $article
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取政策协议
|
||||
* @param string $type
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 20:00
|
||||
*/
|
||||
public static function getPolicyByType(string $type)
|
||||
{
|
||||
return [
|
||||
'title' => ConfigService::get('agreement', $type . '_title', ''),
|
||||
'content' => ConfigService::get('agreement', $type . '_content', ''),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 装修信息
|
||||
* @param $id
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/9/21 18:37
|
||||
*/
|
||||
public static function getDecorate($id)
|
||||
{
|
||||
return DecoratePage::field(['type', 'name', 'data', 'meta'])
|
||||
->findOrEmpty($id)->toArray();
|
||||
}
|
||||
public static function carouselLists(){
|
||||
$lists = Carousel::where("status",1)->order("id","desc")->select();
|
||||
return [
|
||||
'list' => $lists,
|
||||
'page' => 0,
|
||||
'size' => 0,
|
||||
'count' => 0,
|
||||
'more' => 0
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获取配置
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/9/21 19:38
|
||||
*/
|
||||
public static function getConfigData()
|
||||
{
|
||||
// 底部导航
|
||||
$tabbar = DecorateTabbar::getTabbarLists();
|
||||
// 导航颜色
|
||||
$style = ConfigService::get('tabbar', 'style', config('project.decorate.tabbar_style'));
|
||||
// 登录配置
|
||||
$loginConfig = [
|
||||
// 登录方式
|
||||
'login_way' => ConfigService::get('login', 'login_way', config('project.login.login_way')),
|
||||
// 注册强制绑定手机
|
||||
'coerce_mobile' => ConfigService::get('login', 'coerce_mobile', config('project.login.coerce_mobile')),
|
||||
// 政策协议
|
||||
'login_agreement' => ConfigService::get('login', 'login_agreement', config('project.login.login_agreement')),
|
||||
// 第三方登录 开关
|
||||
'third_auth' => ConfigService::get('login', 'third_auth', config('project.login.third_auth')),
|
||||
// 微信授权登录
|
||||
'wechat_auth' => ConfigService::get('login', 'wechat_auth', config('project.login.wechat_auth')),
|
||||
// qq授权登录
|
||||
'qq_auth' => ConfigService::get('login', 'qq_auth', config('project.login.qq_auth')),
|
||||
];
|
||||
// 网址信息
|
||||
$website = [
|
||||
'h5_favicon' => FileService::getFileUrl(ConfigService::get('website', 'h5_favicon')),
|
||||
'shop_name' => ConfigService::get('website', 'shop_name'),
|
||||
'shop_logo' => FileService::getFileUrl(ConfigService::get('website', 'shop_logo')),
|
||||
];
|
||||
// H5配置
|
||||
$webPage = [
|
||||
// 渠道状态 0-关闭 1-开启
|
||||
'status' => ConfigService::get('web_page', 'status', 1),
|
||||
// 关闭后渠道后访问页面 0-空页面 1-自定义链接
|
||||
'page_status' => ConfigService::get('web_page', 'page_status', 0),
|
||||
// 自定义链接
|
||||
'page_url' => ConfigService::get('web_page', 'page_url', ''),
|
||||
'url' => request()->domain() . '/mobile'
|
||||
];
|
||||
|
||||
// 备案信息
|
||||
$copyright = ConfigService::get('copyright', 'config', []);
|
||||
|
||||
return [
|
||||
'domain' => FileService::getFileUrl(),
|
||||
'style' => $style,
|
||||
'tabbar' => $tabbar,
|
||||
'login' => $loginConfig,
|
||||
'website' => $website,
|
||||
'webPage' => $webPage,
|
||||
'version'=> config('project.version'),
|
||||
'copyright' => $copyright,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
442
app/api/logic/LoginLogic.php
Normal file
442
app/api/logic/LoginLogic.php
Normal file
@ -0,0 +1,442 @@
|
||||
<?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\api\logic;
|
||||
|
||||
use app\common\cache\WebScanLoginCache;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\api\service\{UserTokenService, WechatUserService};
|
||||
use app\common\enum\{LoginEnum, user\UserTerminalEnum, YesNoEnum};
|
||||
use app\common\service\{
|
||||
ConfigService,
|
||||
FileService,
|
||||
wechat\WeChatConfigService,
|
||||
wechat\WeChatMnpService,
|
||||
wechat\WeChatOaService,
|
||||
wechat\WeChatRequestService
|
||||
};
|
||||
use app\common\model\user\{User, UserAuth};
|
||||
use think\facade\{Db, Config};
|
||||
|
||||
/**
|
||||
* 登录逻辑
|
||||
* Class LoginLogic
|
||||
* @package app\api\logic
|
||||
*/
|
||||
class LoginLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 账号密码注册
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2022/9/7 15:37
|
||||
*/
|
||||
public static function register(array $params)
|
||||
{
|
||||
try {
|
||||
$userSn = User::createUserSn();
|
||||
$passwordSalt = Config::get('project.unique_identification');
|
||||
$password = create_password($params['password'], $passwordSalt);
|
||||
$avatar = ConfigService::get('default_image', 'user_avatar');
|
||||
|
||||
User::create([
|
||||
'sn' => $userSn,
|
||||
'avatar' => $avatar,
|
||||
'nickname' => '用户' . $userSn,
|
||||
'account' => $params['account'],
|
||||
'password' => $password,
|
||||
'channel' => $params['channel'],
|
||||
]);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 账号/手机号登录,手机号验证码
|
||||
* @param $params
|
||||
* @return array|false
|
||||
* @author 段誉
|
||||
* @date 2022/9/6 19:26
|
||||
*/
|
||||
public static function login($params)
|
||||
{
|
||||
try {
|
||||
// 账号/手机号 密码登录
|
||||
$where = ['account|mobile' => $params['account']];
|
||||
if ($params['scene'] == LoginEnum::MOBILE_CAPTCHA) {
|
||||
//手机验证码登录
|
||||
$where = ['mobile' => $params['account']];
|
||||
}
|
||||
|
||||
$user = User::where($where)->findOrEmpty();
|
||||
if ($user->isEmpty()) {
|
||||
throw new \Exception('用户不存在');
|
||||
}
|
||||
|
||||
//更新登录信息
|
||||
$user->login_time = time();
|
||||
$user->login_ip = request()->ip();
|
||||
$user->save();
|
||||
|
||||
//设置token
|
||||
$userInfo = UserTokenService::setToken($user->id, $params['terminal']);
|
||||
|
||||
//返回登录信息
|
||||
$avatar = $user->avatar ?: Config::get('project.default_image.user_avatar');
|
||||
$avatar = FileService::getFileUrl($avatar);
|
||||
|
||||
return [
|
||||
'nickname' => $userInfo['nickname'],
|
||||
'sn' => $userInfo['sn'],
|
||||
'mobile' => $userInfo['mobile'],
|
||||
'avatar' => $avatar,
|
||||
'token' => $userInfo['token'],
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
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 UserTokenService::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 array $params
|
||||
* @return array|false
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 19:47
|
||||
*/
|
||||
public static function oaLogin(array $params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
//通过code获取微信 openid
|
||||
$response = (new WeChatOaService())->getOaResByCode($params['code']);
|
||||
$userServer = new WechatUserService($response, UserTerminalEnum::WECHAT_OA);
|
||||
$userInfo = $userServer->getResopnseByUserInfo()->authUserLogin()->getUserInfo();
|
||||
|
||||
// 更新登录信息
|
||||
self::updateLoginInfo($userInfo['id']);
|
||||
|
||||
Db::commit();
|
||||
return $userInfo;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 小程序-静默登录
|
||||
* @param array $params
|
||||
* @return array|false
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 19:47
|
||||
*/
|
||||
public static function silentLogin(array $params)
|
||||
{
|
||||
try {
|
||||
//通过code获取微信 openid
|
||||
$response = (new WeChatMnpService())->getMnpResByCode($params['code']);
|
||||
$userServer = new WechatUserService($response, UserTerminalEnum::WECHAT_MMP);
|
||||
$userInfo = $userServer->getResopnseByUserInfo('silent')->getUserInfo();
|
||||
|
||||
if (!empty($userInfo)) {
|
||||
// 更新登录信息
|
||||
self::updateLoginInfo($userInfo['id']);
|
||||
}
|
||||
|
||||
return $userInfo;
|
||||
} catch (\Exception $e) {
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 小程序-授权登录
|
||||
* @param array $params
|
||||
* @return array|false
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 19:47
|
||||
*/
|
||||
public static function mnpLogin(array $params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
//通过code获取微信 openid
|
||||
$response = (new WeChatMnpService())->getMnpResByCode($params['code']);
|
||||
$userServer = new WechatUserService($response, UserTerminalEnum::WECHAT_MMP);
|
||||
$userInfo = $userServer->getResopnseByUserInfo()->authUserLogin($params)->getUserInfo();
|
||||
|
||||
// 更新登录信息
|
||||
self::updateLoginInfo($userInfo['id'],$params);
|
||||
|
||||
Db::commit();
|
||||
return $userInfo;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 更新登录信息
|
||||
* @param $userId
|
||||
* @throws \Exception
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 19:46
|
||||
*/
|
||||
public static function updateLoginInfo($userId,$params="")
|
||||
{
|
||||
$user = User::findOrEmpty($userId);
|
||||
if ($user->isEmpty()) {
|
||||
throw new \Exception('用户不存在');
|
||||
}
|
||||
if($user->source==0){
|
||||
if($params!=""){
|
||||
if(isset($params['source'])){
|
||||
if($params['source']!=""&&$params['source']!=null){
|
||||
$user->source = $params['source'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$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
|
||||
* @return array|false
|
||||
* @author 段誉
|
||||
* @date 2022/10/21 10:28
|
||||
*/
|
||||
public static function scanLogin($params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
// 通过code 获取 access_token,openid,unionid等信息
|
||||
$userAuth = WeChatRequestService::getUserAuthByCode($params['code']);
|
||||
|
||||
if (empty($userAuth['openid']) || empty($userAuth['access_token'])) {
|
||||
throw new \Exception('获取用户授权信息失败');
|
||||
}
|
||||
|
||||
// 获取微信用户信息
|
||||
$response = WeChatRequestService::getUserInfoByAuth($userAuth['access_token'], $userAuth['openid']);
|
||||
|
||||
// 生成用户或更新用户信息
|
||||
$userServer = new WechatUserService($response, UserTerminalEnum::PC);
|
||||
$userInfo = $userServer->getResopnseByUserInfo()->authUserLogin()->getUserInfo();
|
||||
|
||||
// 更新登录信息
|
||||
self::updateLoginInfo($userInfo['id']);
|
||||
|
||||
Db::commit();
|
||||
return $userInfo;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
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 User::where(['id' => $userId])->update([
|
||||
'nickname' => $params['nickname'],
|
||||
'avatar' => FileService::setFileUrl($params['avatar']),
|
||||
'is_new_user' => YesNoEnum::NO
|
||||
]);
|
||||
}
|
||||
}
|
||||
979
app/api/logic/OrderLogic.php
Normal file
979
app/api/logic/OrderLogic.php
Normal file
@ -0,0 +1,979 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
use app\common\enum\RefundEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\order\Order;
|
||||
use app\common\model\order\OrderAll;
|
||||
use app\common\model\order\OrderGroup;
|
||||
use app\common\model\order\OrderStore;
|
||||
use app\common\model\order\OrderStoreRenew;
|
||||
use app\common\model\refund\RefundRecord;
|
||||
use app\common\model\store\Store;
|
||||
use app\common\model\teamaster\Tea;
|
||||
use app\common\model\teamaster\Teamaster;
|
||||
use app\common\model\teamaster\TeamasterLabel;
|
||||
use app\common\model\teastore\TeaStore;
|
||||
use app\common\model\teastore\TeaStoreGroup;
|
||||
use app\common\model\teastore\TeaStoreRecharge;
|
||||
use app\common\model\teastore\TeaStoreRoom;
|
||||
use app\common\model\user\User;
|
||||
use app\common\model\user\UserAddress;
|
||||
use app\common\model\user\UserCoupon;
|
||||
use app\common\model\user\UserCouponType;
|
||||
use app\common\model\user\UserGroup;
|
||||
use app\common\service\ConfigService;
|
||||
use app\common\service\FileService;
|
||||
use app\common\model\order\OrderStoreRecharge;
|
||||
use DateTime;
|
||||
use think\facade\{Db};
|
||||
|
||||
class OrderLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* @notes 茶艺师订单提交
|
||||
* @author 胥聪
|
||||
* @date 2025/10/14 17:01
|
||||
*/
|
||||
public static function addOrder($post)
|
||||
{
|
||||
$post['room_price'] = isset($post['room_price']) ? $post['room_price'] : 0;
|
||||
$post['address_id'] = isset($post['address_id']) ? $post['address_id'] : 0;
|
||||
$post['store_id'] = isset($post['store_id']) ? $post['store_id'] : 0;
|
||||
// 茶具价格
|
||||
$post['cup_price'] = 0;
|
||||
// $post['cup_price'] = ConfigService::get("gzh_setting","cup_price");
|
||||
// 茶艺服务价格计算
|
||||
$post['tea_price'] = Tea::where('id', 'in', [$post['tea_id']])->sum('tea_price');
|
||||
// 茶艺师费用
|
||||
$teamaster_msg = Teamaster::where("id", $post['teamaster_id'])->find();
|
||||
$post['teamaster_price'] = $teamaster_msg['price'];
|
||||
// 车马费
|
||||
$distance = calculateDistanceKm($teamaster_msg['latitude'], $teamaster_msg['longitude'], $post['latitude'], $post['longitude']);
|
||||
$distance = ceil($distance);
|
||||
$fare_price = ConfigService::get("gzh_setting", "fare_price");
|
||||
$post['fare_price'] = $distance * $fare_price;
|
||||
// 优惠券计算
|
||||
$coupon_msg = UserCoupon::where('id', 'in', [$post['coupon_id']])->select();
|
||||
$post['coupon_price'] = 0;
|
||||
foreach ($coupon_msg as $key => $value) {
|
||||
$post['coupon_price'] += UserCouponType::where('id', $value['coupon_id'])->value("coupon_price");
|
||||
}
|
||||
$amount_price = $post['cup_price'] + $post['tea_price'] + $post['fare_price'] + $post['teamaster_price'] + $post['room_price'] - $post['coupon_price'];
|
||||
$order_sn = createSn("order", "order_sn");
|
||||
$order = Order::create([
|
||||
'user_id' => $post['user_id'],
|
||||
'order_sn' => $order_sn,
|
||||
'service_type' => $post['service_type'],
|
||||
'teamaster_id' => $post['teamaster_id'],
|
||||
'address_id' => $post['address_id'],
|
||||
'store_id' => $post['store_id'],
|
||||
'start_time' => $post['start_time'],
|
||||
'end_time' => $post['end_time'],
|
||||
'nums' => $post['nums'],
|
||||
'tea_id' => $post['tea_id'],
|
||||
'tea_price' => $post['tea_price'],
|
||||
'fare_price' => $post['fare_price'],
|
||||
// 'cup_price'=>$post['cup_price'],
|
||||
'teamaster_price' => $post['teamaster_price'],
|
||||
'remark' => $post['remark'],
|
||||
'coupon_id' => $post['coupon_id'],
|
||||
'coupon_price' => $post['coupon_price'],
|
||||
'order_amount' => $amount_price,
|
||||
'longitude' => $post['longitude'],
|
||||
'latitude' => $post['latitude'],
|
||||
'hours' => $post['hours'],
|
||||
// 'pay_type'=>$post['pay_type'],
|
||||
'dtime' => date("Y-m-d H:i:s")
|
||||
]);
|
||||
return $order->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 茶艺师列表
|
||||
* @author 胥聪
|
||||
* @date 2025/10/14 17:01
|
||||
*/
|
||||
public static function orderList($post, $userId)
|
||||
{
|
||||
$os = $os1 = "";
|
||||
if (isset($post['order_status'])) {
|
||||
if ($post['order_status'] != "" || $post['order_status'] != null) {
|
||||
$os = "b.order_status = " . $post['order_status'] . "";
|
||||
$os1 = "order_status = " . $post['order_status'] . "";
|
||||
}
|
||||
}
|
||||
$s = $s1 = "";
|
||||
if (isset($post['search'])) {
|
||||
if ($post['search'] != "" || $post['search'] != null) {
|
||||
$a = $post['search'];
|
||||
$s = "a.name like '%" . $a . "%'";
|
||||
$s1 = "name like '%" . $a . "%'";
|
||||
}
|
||||
}
|
||||
$count = Order::where('user_id', $userId)
|
||||
->where('del', 0)
|
||||
->where($os1)
|
||||
->where($s1)
|
||||
->count();
|
||||
$lists = Teamaster::alias("a")
|
||||
->field('a.id as teamaster_id,a.level_id,a.label_id,a.sex,a.both,a.name,a.image,b.id,
|
||||
b.service_type,b.start_time,b.end_time,b.order_status')
|
||||
->join("order b", "b.teamaster_id = a.id", "left")
|
||||
->where('b.user_id', $userId)
|
||||
->where('b.del', 0)
|
||||
->where($os)
|
||||
->where($s)
|
||||
->with(['teamasterLevel'])
|
||||
->page($post['page'], $post['size'])
|
||||
->order('b.id desc')
|
||||
->select();
|
||||
foreach ($lists as $key => $value) {
|
||||
$a = array_filter(explode(",", $value['label_id']));
|
||||
// 标签
|
||||
$lists[$key]['teamasterlabel'] = TeamasterLabel::wherein("id", $a)->select()->toArray();
|
||||
|
||||
$lists[$key]['both'] = (new DateTime())->diff(new DateTime($value['both']))->y;
|
||||
}
|
||||
$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($data)
|
||||
{
|
||||
$details = Order::where("id", $data['id'])->find();
|
||||
$teamaster = Teamaster::where('id', $details['teamaster_id'])->with(['teamasterLevel'])->find();
|
||||
$teamaster['real'] = Teamaster::teamasterReal($teamaster['real_id']);
|
||||
$teamaster['collect'] = 0;
|
||||
$a = array_filter(explode(",", $teamaster['label_id']));
|
||||
$teamaster['teamasterlabel'] = TeamasterLabel::wherein("id", $a)->select()->toArray();
|
||||
$details['teamaster'] = $teamaster;
|
||||
$b = array_filter(explode(",", $details['tea_id']));
|
||||
$details['tea'] = Tea::wherein("id", $b)->select()->toArray();
|
||||
|
||||
// 订单过期时间
|
||||
$f = strtotime($details['dtime']) + 30 * 60;
|
||||
$current_timestamp = time();
|
||||
$details['time1'] = $f - $current_timestamp;
|
||||
// 按公里车马费
|
||||
$details['fare_distance_price'] = ConfigService::get("gzh_setting", "fare_price");
|
||||
// $details['distance'] = calculateDistanceKm($value['latitude'],$value['longitude'],$post['latitude'],$post['longitude']);
|
||||
// 距离多少分钟路程
|
||||
$details['customer_service_phone'] = ConfigService::get("gzh_setting", "customer_service_phone");
|
||||
$details['reach_time'] = 30;
|
||||
$details['store_address'] = Store::where("id", $details['store_id'])->find();
|
||||
$details['address'] = UserAddress::where("id", $details['address_id'])->find();
|
||||
$details['pay_way_title'] = "";
|
||||
if ($details['pay_way'] == 1) {
|
||||
$details['pay_way_title'] = "余额支付";
|
||||
}
|
||||
if ($details['pay_way'] == 2) {
|
||||
$details['pay_way_title'] = "微信支付";
|
||||
}
|
||||
if ($details['pay_way'] == 3) {
|
||||
$details['pay_way_title'] = "支付宝支付";
|
||||
}
|
||||
|
||||
return $details;
|
||||
}
|
||||
|
||||
public static function cancelOrder($data)
|
||||
{
|
||||
return Order::where("id", $data['id'])->update(["order_status" => 2]);
|
||||
}
|
||||
|
||||
public static function delOrder($data)
|
||||
{
|
||||
return Order::where("id", $data['id'])->update(["del" => 1]);
|
||||
}
|
||||
|
||||
public static function userConfirmOrder($data)
|
||||
{
|
||||
return Order::where("id", $data['id'])->update(["order_status" => 5]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 茶室订单提交
|
||||
* @author 胥聪
|
||||
* @date 2025/10/14 17:01
|
||||
*/
|
||||
public static function addStoreOrder($post, $userId)
|
||||
{
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
$hours = $post['hours'];
|
||||
$timeslot = $post['timeslot'];
|
||||
$day_time = $post['day_time'];
|
||||
$room_id = $post['room_id'];
|
||||
$group_coupon_id = $post['group_coupon_id'];
|
||||
$user_coupon_id = $post['user_coupon_id'];
|
||||
// 茶室包间价格计算
|
||||
$room_msg = TeaStoreRoom::where("id", $post['room_id'])->find();
|
||||
|
||||
if (!$room_msg) {
|
||||
throw new \Exception('茶室不存在');
|
||||
}
|
||||
$store_id = $room_msg->store_id;
|
||||
$timeslot = explode(',', $timeslot);
|
||||
|
||||
if ($hours != (count($timeslot) - 1) * 0.5) {
|
||||
throw new \Exception('参数错误,请重新下单');
|
||||
}
|
||||
if (empty($timeslot)) {
|
||||
throw new \Exception('时间段不能为空');
|
||||
}
|
||||
$start = $timeslot[0];
|
||||
$end = $timeslot[count($timeslot) - 1];
|
||||
|
||||
if ($room_msg['hours'] > $post['hours']) {
|
||||
throw new \Exception('起订小时数不能小于包间规定小时数');
|
||||
}
|
||||
$timeList = OrderStore::where([
|
||||
'room_id' => $room_id,
|
||||
'day_time' => $day_time,
|
||||
])->whereIn('order_status', [0, 1, 2])->column('timeslot');
|
||||
$times = [];
|
||||
foreach ($timeList as $v) {
|
||||
$times = array_merge($times, explode(',', $v));
|
||||
}
|
||||
$repeat = array_intersect($timeslot, $times);
|
||||
if ($repeat) {
|
||||
throw new \Exception('所选时间段存在不可选项');
|
||||
}
|
||||
|
||||
$room_all_price = round($room_msg['price'] * $post['hours'], 2);//价格
|
||||
$user_msg = User::where("id", $userId)->find();
|
||||
if ($user_msg == null) {
|
||||
throw new \Exception('用户不存在');
|
||||
}
|
||||
|
||||
$total_price = $hours * $room_msg->price;
|
||||
$actual_group_price = 0;//门店需要结算的套餐价格
|
||||
$discount_price = 0;//套餐实际价格
|
||||
$group_hours = 0;
|
||||
$coupon_price = 0;//优惠券价格
|
||||
if ($group_coupon_id > 0) {
|
||||
$groupData = self::getGroup($group_coupon_id, $userId, $store_id, $room_id);
|
||||
$actual_group_price = $groupData['actual_group_price'];
|
||||
$discount_price = $groupData['discount_price'];
|
||||
$group_hours = $groupData['group_hours'];
|
||||
$total_hours = $hours - $group_hours;
|
||||
if ($total_hours <= 0) {
|
||||
$total_price = 0;
|
||||
} else {
|
||||
$total_price = ($hours - $group_hours) * $room_msg->price;
|
||||
}
|
||||
}
|
||||
if ($user_coupon_id > 0) {
|
||||
$user_coupon = UserCoupon::where([
|
||||
'id' => $user_coupon_id,
|
||||
'status' => 0
|
||||
])->find();
|
||||
if (!$user_coupon) {
|
||||
throw new \Exception('当前优惠券不可用');
|
||||
}
|
||||
$coupon = UserCouponType::where([
|
||||
'id' => $user_coupon->coupon_id,
|
||||
// 'status' => 1,
|
||||
'type_id' => 2
|
||||
])->find();
|
||||
if (!$coupon) {
|
||||
throw new \Exception('当前优惠券不可用');
|
||||
}
|
||||
$use_price = $coupon['use_price'];
|
||||
$coupon_price = $coupon['coupon_price'];
|
||||
if ($total_price > $use_price) {
|
||||
$total_price = $total_price - $coupon_price;
|
||||
}
|
||||
}
|
||||
|
||||
$member_price = 0;
|
||||
if ($user_msg->member == 1) {
|
||||
$member_price = round($total_price - ($total_price * 0.9), 2);
|
||||
$total_price = $total_price * 0.9;
|
||||
}
|
||||
|
||||
$total_price = round($total_price, 2);
|
||||
$store_income_price = 0;
|
||||
if($total_price>0){
|
||||
$store_income_price = round($total_price - $actual_group_price, 2);
|
||||
}
|
||||
$order_sn = createSn("order_store", "order_sn");
|
||||
|
||||
$order = OrderStore::create([
|
||||
'order_sn' => $order_sn,
|
||||
'store_id' => $store_id,
|
||||
'room_id' => $post['room_id'],
|
||||
'user_id' => $userId,
|
||||
'day_title' => $post['day_title'],
|
||||
'day_time' => $post['day_time'],
|
||||
'start_time' => $start,
|
||||
'end_time' => $end,
|
||||
'timeslot' => $post['timeslot'],
|
||||
'hours' => $post['hours'],
|
||||
'group_coupon_id' => $post['group_coupon_id'],
|
||||
'room_price' => $room_msg['price'],
|
||||
'room_all_price' => $room_all_price,
|
||||
'user_coupon_id' => $post['user_coupon_id'],
|
||||
'coupon_price' => $coupon_price,
|
||||
'group_price' => $discount_price,
|
||||
'member_price' => $member_price,
|
||||
// 'cup_price'=>$post['cup_price'],
|
||||
'order_amount' => $total_price,
|
||||
'store_income_price' => $store_income_price,
|
||||
'dtime' => date("Y-m-d H:i:s")
|
||||
]);
|
||||
// type 0为茶艺师 1为茶室支付 2购买套餐 3购买会员 4充值
|
||||
OrderStore::orderAll("order_store", 1, $order_sn, $store_id, $store_income_price, $userId);
|
||||
Db::commit();
|
||||
return $order->id;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static function getGroup($group_coupon_id, $userId, $store_id, $room_id)
|
||||
{
|
||||
$user_group = UserGroup::where([
|
||||
'id' => $group_coupon_id,
|
||||
'status' => 0,
|
||||
'user_id' => $userId,
|
||||
'store_id' => $store_id
|
||||
])->find();
|
||||
if (!$user_group) {
|
||||
throw new \Exception('团购套餐券不可用');
|
||||
}
|
||||
$store_group = TeaStoreGroup::where('id', $user_group['group_id'])->find();
|
||||
if (!$store_group) {
|
||||
throw new \Exception('此团购券不可用,请联系门店内客服');
|
||||
}
|
||||
// 将 $roomArr 转换为整数数组
|
||||
$roomArr = array_map('intval', explode(',', $store_group['room_id']));
|
||||
$group_room = [0, (int)$room_id];
|
||||
$hasIntersection = !empty(array_intersect($group_room, $roomArr));
|
||||
|
||||
if (!$hasIntersection) {
|
||||
throw new \Exception('此团购券不适用此包间');
|
||||
}
|
||||
$actual_group_price = 0;
|
||||
if ($user_group->type == 1) {
|
||||
$actual_group_price = $store_group->discount_price;
|
||||
}
|
||||
$group_hours = $store_group->hour;
|
||||
$discount_price = $store_group->discount_price;
|
||||
return [
|
||||
'actual_group_price' => $actual_group_price,
|
||||
'group_hours' => $group_hours,
|
||||
'discount_price' => $discount_price
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public static function orderStoreList($post, $userId)
|
||||
{
|
||||
$os = "";
|
||||
if (isset($post['order_status'])) {
|
||||
if ($post['order_status'] != "" || $post['order_status'] != null) {
|
||||
$os = "a.order_status = " . $post['order_status'] . "";
|
||||
}
|
||||
}
|
||||
$s = "";
|
||||
if (isset($post['search'])) {
|
||||
if ($post['search'] != "" || $post['search'] != null) {
|
||||
$a = $post['search'];
|
||||
$s = "c.title like '%" . $a . "%'";
|
||||
}
|
||||
}
|
||||
$count = OrderStore::alias("a")
|
||||
->where("a.del", 0)
|
||||
->where('a.user_id', $userId)
|
||||
->join("tea_store b", "b.id = a.store_id", "left")
|
||||
->join("tea_store_room c", "c.id = a.room_id", "left")
|
||||
->where($os)
|
||||
->where($s)
|
||||
->count();
|
||||
$lists = OrderStore::alias("a")
|
||||
->field('a.day_title,a.group_coupon_id,b.operation_type,a.id,a.order_sn,a.store_id,a.room_id,a.day_time,a.start_time,a.end_time,a.hours,
|
||||
a.order_status,b.name as store_name,c.title as room_name,b.image,a.renew_hour')
|
||||
->join("tea_store b", "b.id = a.store_id", "left")
|
||||
->join("tea_store_room c", "c.id = a.room_id", "left")
|
||||
->where("a.del", 0)
|
||||
->where('a.user_id', $userId)
|
||||
->where($os)
|
||||
->where($s)
|
||||
->page($post['page'], $post['size'])
|
||||
->order('a.id desc')
|
||||
->select();
|
||||
foreach ($lists as $key => $value) {
|
||||
$lists[$key]['image'] = FileService::getImgUrl($value['image']);
|
||||
$lists[$key]['start_time'] = date("H:i", $value['start_time']);
|
||||
$lists[$key]['end_time'] = date("H:i", $value['end_time']);
|
||||
$lists[$key]['hours'] = $value['renew_hour']+$value['hours'];
|
||||
}
|
||||
$data = [
|
||||
'list' => $lists,
|
||||
'page' => $post['page'],
|
||||
'size' => $post['size'],
|
||||
'count' => $count,
|
||||
'more' => is_more($count, $post['page'], $post['size'])
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function orderStoreDetails($data)
|
||||
{
|
||||
$details = OrderStore::where("id", $data['id'])->find();
|
||||
$room_msg = TeaStoreRoom::where("id", $details['room_id'])->find();
|
||||
$room_img = explode(",",$room_msg['img']);
|
||||
$room_msg['img'] = FileService::getImgUrl($room_img[0]);
|
||||
$details['room_msg'] = $room_msg;
|
||||
$store_msg = TeaStore::where("id", $details['store_id'])->find();
|
||||
$store_msg['image'] = FileService::getImgUrl($store_msg['image']);
|
||||
$details['store_msg'] = $store_msg;
|
||||
$details['start_time'] = date("H:i", $details['start_time']);
|
||||
$details['end_time'] = date("H:i", $details['end_time']);
|
||||
if ($details['renew_dtime'] != null && $details['renew_dtime'] != "") {
|
||||
$renew_msg = explode(",", $details['renew_dtime']);
|
||||
foreach ($renew_msg as $key => $value) {
|
||||
// $r_msg = json_decode($value, true);
|
||||
$r_msg['start_time'] = date('H:i', $value);
|
||||
$r_msg['end_time'] = date('H:i', $value);
|
||||
$arr[$key] = $r_msg;
|
||||
}
|
||||
// $details['renew_dtime'] = $arr;
|
||||
$details['renew_dtime'] = array_slice($arr, -1)[0];
|
||||
}
|
||||
|
||||
// 订单过期时间
|
||||
$f = strtotime($details['dtime']) + 30 * 60;
|
||||
$current_timestamp = time();
|
||||
$details['time1'] = $f - $current_timestamp;
|
||||
$details['distance'] = calculateDistanceKm($store_msg['latitude'], $store_msg['longitude'], $data['latitude'], $data['longitude']);
|
||||
if ($details['pay_way'] == 1) {
|
||||
$details['pay_way_title'] = "余额支付";
|
||||
}
|
||||
if ($details['pay_way'] == 2) {
|
||||
$details['pay_way_title'] = "微信支付";
|
||||
}
|
||||
if ($details['pay_way'] == 3) {
|
||||
$details['pay_way_title'] = "门店余额支付";
|
||||
}
|
||||
|
||||
return $details;
|
||||
}
|
||||
|
||||
public static function getOrderAmount($data)
|
||||
{
|
||||
$details = OrderStore::where("id", $data['id'])->find();
|
||||
|
||||
$store_msg = TeaStore::where("id", $details['store_id'])->find();
|
||||
$details['store_name'] = $store_msg['name'];
|
||||
// 订单过期时间
|
||||
$f = strtotime($details['dtime']) + 5 * 60;
|
||||
$current_timestamp = time();
|
||||
$details['time1'] = $f - $current_timestamp;
|
||||
$details['order_amount'] = $details->order_amount;
|
||||
$details['is_member_price'] = $details->is_member_price;
|
||||
if($details['is_member_price'] == 0 &&$data['pay_way'] ==3){
|
||||
$details['order_amount'] = $details->order_amount+$details->member_price;
|
||||
$details['is_member_price'] = 1;
|
||||
}elseif ($details['is_member_price'] == 1 &&($data['pay_way'] ==1||$data['pay_way'] ==2)){
|
||||
$details['order_amount'] = $details->order_amount-$details->member_price;
|
||||
$details['is_member_price'] = 0;
|
||||
}
|
||||
OrderStore::where('id',$details['id'])->update([
|
||||
'order_amount'=>$details['order_amount'],
|
||||
'is_member_price'=>$details['is_member_price'],
|
||||
'store_income_price'=>$details['order_amount'],
|
||||
'update_dtime'=>date('Y-m-d H:i:s')
|
||||
]);
|
||||
|
||||
return $details;
|
||||
}
|
||||
|
||||
|
||||
public static function getOrderRenewAmount($data)
|
||||
{
|
||||
$details = OrderStoreRenew::where("id", $data['id'])->find();
|
||||
|
||||
|
||||
$details['order_amount'] = $details->price;
|
||||
$details['is_member_price'] = $details->is_member_price;
|
||||
if($details['is_member_price'] == 0 &&$data['pay_way'] ==3){
|
||||
$details['order_amount'] = $details->price+$details->member_price;
|
||||
$details['is_member_price'] = 1;
|
||||
}elseif ($details['is_member_price'] == 1 &&($data['pay_way'] ==1||$data['pay_way'] ==2)){
|
||||
$details['order_amount'] = $details->price-$details->member_price;
|
||||
$details['is_member_price'] = 0;
|
||||
}
|
||||
$details['price'] = $details['order_amount'];
|
||||
OrderStoreRenew::where('id',$details['id'])->update([
|
||||
'price'=>$details['order_amount'],
|
||||
'is_member_price'=>$details['is_member_price'],
|
||||
'uptime'=>time()
|
||||
]);
|
||||
|
||||
return $details;
|
||||
}
|
||||
|
||||
public static function cancelOrderStore($data)
|
||||
{
|
||||
return OrderStore::where("id", $data['id'])->update(["order_status" => 4]);
|
||||
}
|
||||
|
||||
public static function delOrderStore($data)
|
||||
{
|
||||
return OrderStore::where("id", $data['id'])->update(["del" => 1]);
|
||||
}
|
||||
|
||||
public static function userConfirmOrderStore($data)
|
||||
{
|
||||
return OrderStore::where("id", $data['id'])->update(["order_status" => 4]);
|
||||
}
|
||||
|
||||
public static function renewDtime($data, $userId)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$order = OrderStore::where("id", $data['id'])->find();
|
||||
if (!$order) {
|
||||
throw new \Exception('订单不存在,无法续订');
|
||||
}
|
||||
if ($order['order_status'] >= 3) {
|
||||
throw new \Exception('订单已结束,无法续订');
|
||||
}
|
||||
$source_id = $order->id;
|
||||
if ($order->is_transfer == 1) {
|
||||
$source_id = $order->transfer_order_id;
|
||||
}
|
||||
$hour = $data['renew_hour'];
|
||||
$timeList = explode(',', $order['timeslot']);
|
||||
$max = $hour * 2;
|
||||
$extra = [];
|
||||
for ($i = 0; $i < $max; $i++) {
|
||||
// 获取最近的一个时间
|
||||
$timeEnd = end($timeList);
|
||||
$end = $timeEnd + 1800;
|
||||
$extra[] = $end;
|
||||
array_push($timeList, (string)$end);
|
||||
}
|
||||
|
||||
foreach ($extra as &$v) {
|
||||
$info = OrderStore::where('room_id', $order['room_id'])->whereIn('order_status',[0,1,2])->where("find_in_set($v,timeslot)")->find();
|
||||
if ($info) {
|
||||
throw new \Exception('当前时间已被预定');
|
||||
}
|
||||
}
|
||||
|
||||
$order_sn = createSn("order_store_renew", "order_sn");
|
||||
$user =User::where('id',$userId)->find();
|
||||
$price = round($data['renew_hour'] * $order['room_price'], 2);
|
||||
$member_price = 0;
|
||||
if($user->member ==1){
|
||||
$member_price = round($price - ($price * 0.9), 2);
|
||||
$price =$price*0.9;
|
||||
}
|
||||
|
||||
$insert = [
|
||||
'order_sn' => $order_sn,
|
||||
'user_id' => $userId,
|
||||
'source_id' => $source_id,
|
||||
'member_price'=>$member_price,
|
||||
'timeslot' => implode(',', $extra),
|
||||
'dtime' => time(),
|
||||
'hour' => $hour,
|
||||
'pay_status' => 0,
|
||||
'price' => $price,
|
||||
'expire_time' => time() + 60 * 3
|
||||
];
|
||||
|
||||
$id = OrderStoreRenew::insertGetId($insert);
|
||||
Db::commit();
|
||||
return [
|
||||
'order_id' =>$id,
|
||||
'price'=>$price
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function addGroupOrder($post)
|
||||
{
|
||||
$group = TeaStoreGroup::where("id", $post['group_id'])->find();
|
||||
$order_sn = createSn("order_group", "order_sn");
|
||||
$order_amount = $group['discount_price'];
|
||||
$user = User::where('id',$post['user_id'])->find();
|
||||
if($user->member == 1){
|
||||
$order_amount = round($order_amount*0.9,2);
|
||||
}
|
||||
$order = OrderGroup::create([
|
||||
'user_id' => $post['user_id'],
|
||||
'order_sn' => $order_sn,
|
||||
'group_id' => $post['group_id'],
|
||||
'room_id' => $post['room_id'],
|
||||
'store_id' => $group['store_id'],
|
||||
'order_amount' => $order_amount,
|
||||
// 'pay_type'=>$post['pay_type'],
|
||||
'dtime' => date("Y-m-d H:i:s")
|
||||
]);
|
||||
// 0为茶艺师 1为茶室支付 2购买套餐 3购买会员 4充值 5团购退款
|
||||
OrderStore::orderAll("order_group", 2, $order_sn, $group['store_id'], $group['discount_price'], $post['user_id']);
|
||||
return [
|
||||
'id'=>$order->id,
|
||||
'order_amount'=>$order_amount
|
||||
];
|
||||
}
|
||||
|
||||
public static function orderGroupList($post, $userId)
|
||||
{
|
||||
$s = "";
|
||||
if (isset($post['search'])) {
|
||||
if ($post['search'] != "" || $post['search'] != null) {
|
||||
$a = $post['search'];
|
||||
$s = "b.title like '%" . $a . "%'";
|
||||
}
|
||||
}
|
||||
$st = "";
|
||||
if (isset($post['use_status'])) {
|
||||
if ($post['use_status'] != "" || $post['use_status'] != null) {
|
||||
$st = "a.status = " . $post['use_status'] . "";
|
||||
}
|
||||
}
|
||||
$o = "";
|
||||
if (isset($post['operation_type'])) {
|
||||
if ($post['operation_type'] != "" || $post['operation_type'] != null) {
|
||||
$o = "c.operation_type = " . $post['operation_type'] . "";
|
||||
}
|
||||
}
|
||||
$t = "";
|
||||
if (isset($post['type'])) {
|
||||
if ($post['type'] != "" || $post['type'] != null) {
|
||||
$t = "a.type = " . $post['type'] . "";
|
||||
}
|
||||
}
|
||||
$count = UserGroup::alias("a")
|
||||
->join("tea_store_group b", "a.group_id = b.id", "left")
|
||||
->join("tea_store c", "b.store_id = c.id", "left")
|
||||
->where('a.user_id', $userId)
|
||||
->join("order_group d", "a.order_id = d.id", "left")
|
||||
->where($t)
|
||||
->where($s)
|
||||
->where($st)
|
||||
->where($o)
|
||||
->count();
|
||||
$lists = UserGroup::alias("a")
|
||||
->field('a.*,b.title,b.img,c.name,b.hour,b.room_id,c.operation_type,d.id as order_id')
|
||||
->join("tea_store_group b", "a.group_id = b.id", "left")
|
||||
->join("tea_store c", "b.store_id = c.id", "left")
|
||||
->join("order_group d", "a.order_id = d.id", "left")
|
||||
->where('a.user_id', $userId)
|
||||
->where($t)
|
||||
->where($s)
|
||||
->where($st)
|
||||
->where($o)
|
||||
->page($post['page'], $post['size'])
|
||||
->order('a.id',"desc")
|
||||
->select();
|
||||
foreach ($lists as $key => $value) {
|
||||
$i = explode(",", $value['img']);
|
||||
$lists[$key]['image'] = FileService::getFileUrl($i[0]);
|
||||
$lists[$key]['room_title'] = "";
|
||||
if ($value['room_id'] == 0) {
|
||||
$lists[$key]['room_title'] = "通用";
|
||||
} else {
|
||||
$room = TeaStoreRoom::where("id", "in", $value['room_id'])->select();
|
||||
foreach ($room as $k => $v) {
|
||||
if ($k == 0) {
|
||||
$lists[$key]['room_title'] .= $v['title'];
|
||||
} else {
|
||||
$lists[$key]['room_title'] .= "," . $v['title'];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
$data = [
|
||||
'list' => $lists,
|
||||
'page' => $post['page'],
|
||||
'size' => $post['size'],
|
||||
'count' => $count,
|
||||
'more' => is_more($count, $post['page'], $post['size'])
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function orderGroupDetails($data)
|
||||
{
|
||||
$user_group = UserGroup::where("id", $data['id'])->find();
|
||||
$details = OrderGroup::where("id", $user_group['order_id'])->find();
|
||||
|
||||
if($details){
|
||||
if ($details['pay_way'] == 1) {
|
||||
$details['pay_way_title'] = "余额支付";
|
||||
}
|
||||
if ($details['pay_way'] == 2) {
|
||||
$details['pay_way_title'] = "微信支付";
|
||||
}
|
||||
if ($details['pay_way'] == 3) {
|
||||
$details['pay_way_title'] = "支付宝支付";
|
||||
}
|
||||
}else{
|
||||
$details['pay_way_title'] = "抖音核销";
|
||||
}
|
||||
|
||||
$details['user_group'] = $user_group;
|
||||
if ($details['user_group']['qr_url'] != null & $details['user_group']['qr_url'] != "") {
|
||||
$details['user_group']['qr_url'] = "https://76458.com/".$details['user_group']['qr_url'];
|
||||
}
|
||||
$store_msg = TeaStore::where("id", $user_group['store_id'])->find();
|
||||
$store_msg['image'] = FileService::getImgUrl($store_msg['image']);
|
||||
$store_msg['distance'] = calculateDistanceKm($store_msg['latitude'], $store_msg['longitude'], $data['latitude'], $data['longitude']);
|
||||
$details['store'] = $store_msg;
|
||||
$group = TeaStoreGroup::where("id", $user_group['group_id'])->find();
|
||||
$group_img_arr = explode(",", $group['img']);
|
||||
$group['img'] = FileService::getImgUrl($group_img_arr[0]);
|
||||
$details['group'] = $group;
|
||||
$details['room_name'] = "";
|
||||
if ($group['room_id'] == 0) {
|
||||
$group['room_name'] = "通用";
|
||||
} else {
|
||||
$room = TeaStoreRoom::where("id", "in", $user_group['room_id'])->select();
|
||||
foreach ($room as $key => $value) {
|
||||
if ($key == 0) {
|
||||
$group['room_name'] .= $value['title'];
|
||||
} else {
|
||||
$group['room_name'] .= "," . $value['title'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $details;
|
||||
}
|
||||
|
||||
public static function teaStoreGroupUseLists($post, $userId)
|
||||
{
|
||||
$lists = UserGroup::alias("a")->field("a.id,a.status,b.title,b.type,b.store_id,b.sku_id,b.img,b.hour,a.group_id")
|
||||
->join("tea_store_group b", "a.group_id=b.id", "left")
|
||||
->where("a.store_id", $post['store_id'])
|
||||
->where("a.status", 0)
|
||||
->where("a.user_id", $userId)
|
||||
->whereRaw("FIND_IN_SET(0, b.room_id) or FIND_IN_SET(" . $post['room_id'] . ", b.room_id)")
|
||||
->select();
|
||||
foreach ($lists as $key => $value) {
|
||||
$img = explode(",", $value['img']);
|
||||
$lists[$key]['img'] = FileService::getFileUrl($img[0]);
|
||||
$lists[$key]['store_msg'] = TeaStore::where("id", $value['store_id'])
|
||||
->where('status', 1)
|
||||
->where("del", 0)
|
||||
->find();
|
||||
}
|
||||
$data = [
|
||||
'list' => $lists
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function countPrice($data, $userId)
|
||||
{
|
||||
$user_msg = User::where("id", $userId)->find();
|
||||
$room_msg = TeaStoreRoom::where("id", $data['room_id'])->find();
|
||||
$arr['discount_room_price'] = 0;
|
||||
$arr['room_price'] = round($room_msg['price'] * $data['nums'], 2);
|
||||
$arr['nums'] = $data['nums'];
|
||||
// 优惠券
|
||||
$coupon_user_msg = UserCoupon::where("id", $data['coupon_id'])->find();
|
||||
$arr['coupon_price'] = 0;
|
||||
$discount = ConfigService::get("member", "discount");
|
||||
if ($coupon_user_msg != null) {
|
||||
$coupon_msg = UserCouponType::where("id", $coupon_user_msg['coupon_id'])->find();
|
||||
$arr['coupon_price'] = $coupon_msg['coupon_price'];
|
||||
}
|
||||
|
||||
// 团购券价格
|
||||
$arr['group_price'] = 0;
|
||||
$user_group = UserGroup::where("id", $data['group_coupon_id'])->find();
|
||||
if($user_group!=null){
|
||||
$order_group_msg = TeaStoreGroup::where("id", $user_group['group_id'])->find();
|
||||
if ($order_group_msg != null) {
|
||||
$arr['group_price'] = round($order_group_msg['hour']*$room_msg['price'] , 2);
|
||||
}
|
||||
}
|
||||
|
||||
if ($user_msg['member'] == 1) {
|
||||
$arr['discount_room_price'] = round(($arr['room_price']-$arr['group_price']- $arr['coupon_price']) * (1 - $discount), 2);
|
||||
}
|
||||
|
||||
if ($user_msg['member'] == 1) {
|
||||
$arr['order_amount'] = round(($arr['room_price'] - $arr['group_price'] - $arr['coupon_price']) * $discount, 2);
|
||||
} else {
|
||||
$arr['order_amount'] = round($arr['room_price'] - $arr['group_price'] - $arr['coupon_price'], 2);
|
||||
}
|
||||
if ($arr['order_amount'] < 0) {
|
||||
$arr['order_amount'] = 0;
|
||||
}
|
||||
$arr['discount_all_price'] = round($arr['discount_room_price'] + $arr['coupon_price'] + $arr['group_price'], 2);
|
||||
$data = [
|
||||
'details' => $arr
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function transferOrder(array $post, int $userId)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
// 1. 验证原订单
|
||||
$sourceOrder = OrderStore::find($post['order_id']);
|
||||
if (!$sourceOrder) {
|
||||
throw new \Exception('原订单不存在');
|
||||
}
|
||||
|
||||
// 2. 检查订单是否已转让
|
||||
if ($sourceOrder->is_transfer == 1) {
|
||||
// 如果已经是转让订单,找到原始订单
|
||||
$originalOrderId = $sourceOrder->transfer_order_id;
|
||||
|
||||
// 检查用户是否已接收过此订单
|
||||
$existsTransfer = OrderStore::where([
|
||||
"transfer_order_id" => $originalOrderId,
|
||||
'user_id' => $userId
|
||||
])->find();
|
||||
|
||||
if ($existsTransfer) {
|
||||
throw new \Exception('此账号已接收过此账单');
|
||||
}
|
||||
|
||||
$targetOrderId = $originalOrderId;
|
||||
} else {
|
||||
// 原始订单,检查用户是否已接收过
|
||||
$existsTransfer = OrderStore::where([
|
||||
"transfer_order_id" => $sourceOrder->id,
|
||||
'user_id' => $userId
|
||||
])->find();
|
||||
|
||||
if ($existsTransfer) {
|
||||
throw new \Exception('此账号已接收过此账单');
|
||||
}
|
||||
|
||||
$targetOrderId = $sourceOrder->id;
|
||||
}
|
||||
$countOrder = OrderStore::where('transfer_order_id', $targetOrderId)->count();
|
||||
if ($countOrder > 10) {
|
||||
throw new \Exception('此订单接收人数已超上限');
|
||||
}
|
||||
|
||||
// 3. 创建新订单记录(转让记录)
|
||||
$newOrderSn = createSn("order_store", "order_sn");
|
||||
|
||||
$sourceOrder->user_id = $userId;
|
||||
$sourceOrder->dtime = date('Y-m-d H:i:s'); // 使用完整时间格式
|
||||
$sourceOrder->remark = '转让订单';
|
||||
$sourceOrder->transfer_order_id = $targetOrderId;
|
||||
$sourceOrder->is_transfer = 1;
|
||||
$sourceOrder->order_sn = $newOrderSn;
|
||||
|
||||
$data = $sourceOrder->toArray();
|
||||
unset($data['id']);
|
||||
// 保存新订单
|
||||
$newOrderId = OrderStore::insertGetId($data);
|
||||
|
||||
if (!$newOrderId) {
|
||||
throw new \Exception('创建转让订单失败');
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
return [
|
||||
'order_id' => $newOrderId,
|
||||
];
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function addRechargeOrder(array $post, int $userId)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$id = $post['id'];
|
||||
$store_recharge = TeaStoreRecharge::where([
|
||||
'id'=>$id,
|
||||
'del'=>0
|
||||
])->find();
|
||||
if(!$store_recharge){
|
||||
throw new \Exception('此套餐不存在');
|
||||
}
|
||||
$data = [
|
||||
'recharge_id'=>$store_recharge->id,
|
||||
'order_sn'=>createSn("order_store_recharge", "order_sn"),
|
||||
'user_id'=>$userId,
|
||||
'store_id'=>$store_recharge->store_id,
|
||||
'recharge_price'=>$store_recharge->price,
|
||||
'gift_price'=>$store_recharge->gift_price,
|
||||
'order_amount'=>$store_recharge->price,
|
||||
'create_time'=>time()
|
||||
];
|
||||
|
||||
$recharge_order = OrderStoreRecharge::insertGetId($data);
|
||||
|
||||
Db::commit();
|
||||
return [
|
||||
'order_id' => $recharge_order,
|
||||
'order_amount'=>$store_recharge->price
|
||||
];
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function submitRefund($post,$user_id){
|
||||
// 0为茶艺师 1为茶室支付 2购买套餐 3购买会员 4充值 5团购退款 6茶室退款
|
||||
$id = 0;
|
||||
if($post['order_type'] == 5){
|
||||
$id = $post['id'];
|
||||
$user_group = UserGroup::where("id",$post['id'])->find();
|
||||
$post["order_id"] = $user_group["order_id"];
|
||||
$order = OrderGroup::where("id",$user_group["order_id"])->find();
|
||||
}
|
||||
$recordSn = generate_sn(RefundRecord::class, 'order_sn');
|
||||
$record = RefundRecord::create([
|
||||
'order_sn' => $recordSn,
|
||||
'user_id' => $user_id,
|
||||
'store_id'=>$order["store_id"],
|
||||
'order_id' => $post['order_id'],
|
||||
'content_id'=>$id,//关联相关id
|
||||
'source_sn' => $order['order_sn'],
|
||||
'order_type' => $post['order_type'],
|
||||
'order_amount' => $order['order_amount'],
|
||||
'refund_amount' => $order['order_amount'],
|
||||
'refund_type' => 1,
|
||||
'refund_way' => 1
|
||||
// 'refund_way' => RefundEnum::getRefundWayByPayWay($order['pay_way']),
|
||||
]);
|
||||
OrderStore::orderAll("refund_record",5,$recordSn,$order["store_id"],$order['order_amount'],$user_id);
|
||||
return $record->id;
|
||||
}
|
||||
}
|
||||
541
app/api/logic/PayLogic.php
Normal file
541
app/api/logic/PayLogic.php
Normal file
@ -0,0 +1,541 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\logic\RefundLogic;
|
||||
use app\common\model\order\Order;
|
||||
use app\common\model\order\OrderAll;
|
||||
use app\common\model\order\OrderGroup;
|
||||
use app\common\model\order\OrderStore;
|
||||
use app\common\model\order\OrderStoreRenew;
|
||||
use app\common\model\pay\Pay;
|
||||
use app\common\model\refund\RefundRecord;
|
||||
use app\common\model\store\Store;
|
||||
use app\common\model\store\StoreUserAccountLog;
|
||||
use app\common\model\teastore\TeaStore;
|
||||
use app\common\model\teastore\TeaStoreGroup;
|
||||
use app\common\model\teastore\TeaStoreRoom;
|
||||
use app\common\model\user\User;
|
||||
use app\common\model\user\UserAccountLog;
|
||||
use app\common\model\user\UserCoupon;
|
||||
use app\common\model\user\UserGroup;
|
||||
use app\common\model\user\UserStoreMoney;
|
||||
use app\common\service\FileService;
|
||||
use app\common\service\pay\WeChatPayService;
|
||||
use think\facade\{Db, Config};
|
||||
class PayLogic extends BaseLogic
|
||||
{
|
||||
// public static function yuePay($data,$user_id){
|
||||
// $result = Pay::where("id",$data['id'])->find();
|
||||
// $user = User::where("id",$user_id)->find();
|
||||
// if($user['user_money'] < $result['order_amount']){
|
||||
// throw new \Exception('余额不足');
|
||||
// }
|
||||
// $user->dec('user_money', $result['order_amount']);
|
||||
// $user->save();
|
||||
// $order_data['order_status'] = 1;
|
||||
// $order_data['pay_status'] = 1;
|
||||
// $order_data['update_dtime'] = date("Y-m-d H:i:s");
|
||||
// Order::where("id",$result['order_id'])->update($order_data);
|
||||
// $d['order_sn'] = createSn('pay','order_sn');
|
||||
// $d['create_time'] = date("Y-m-d H:i:s");
|
||||
// $d['pay_time'] = date("Y-m-d H:i:s");
|
||||
// $result = Pay::where("id",$data['id'])->update($d);
|
||||
// return $result;
|
||||
// }
|
||||
public static function yuePay($data, $user_id)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$payId = $data['id'];
|
||||
$currentTime = date("Y-m-d H:i:s");
|
||||
|
||||
// 1. 查询支付记录(悲观锁)
|
||||
$pay = Pay::where("id", $payId)->lock(true)->find();
|
||||
if (!$pay) {
|
||||
throw new \Exception('支付记录不存在');
|
||||
}
|
||||
|
||||
// 支付记录状态检查
|
||||
if ($pay['pay_status'] == 1) {
|
||||
throw new \Exception('该支付记录已完成支付');
|
||||
}
|
||||
// 2. 查询关联订单
|
||||
if($pay['order_type'] == 1){
|
||||
$order = OrderStore::where("id", $pay['order_id'])->find();
|
||||
}elseif($pay['order_type'] == 2){
|
||||
$order = OrderGroup::where("id", $pay['order_id'])->find();
|
||||
}elseif($pay['order_type'] == 7){
|
||||
$order = OrderStoreRenew::where("id", $pay['order_id'])->find();
|
||||
}
|
||||
if (!$order) {
|
||||
throw new \Exception('关联订单不存在');
|
||||
}
|
||||
// 3. 查询用户并检查余额(悲观锁)
|
||||
$user = User::where("id", $user_id)->lock(true)->find();
|
||||
if (!$user) {
|
||||
throw new \Exception('用户不存在');
|
||||
}
|
||||
|
||||
// 金额处理:保持数值类型用于计算,字符串类型用于显示
|
||||
$amount = (float)$pay['order_amount'];
|
||||
// 区分门店余额支付还是平台余额
|
||||
if($data['pay_way'] == 3){
|
||||
$user_store_money = UserStoreMoney::where("user_id",$user_id)->where("store_id",$data['store_id'])->find();
|
||||
$userMoney = (float)$user_store_money['money'];
|
||||
}else{
|
||||
$userMoney = (float)$user['user_money'];
|
||||
}
|
||||
|
||||
|
||||
// 用于显示的格式化金额
|
||||
$displayAmount = number_format($amount, 2);
|
||||
$displayUserMoney = number_format($userMoney, 2);
|
||||
|
||||
if ($userMoney < $amount) {
|
||||
throw new \Exception("余额不足,当前余额: {$displayUserMoney},需支付: {$displayAmount}");
|
||||
}
|
||||
|
||||
// 4. 扣减用户余额(使用数值类型的 $amount)
|
||||
// $userSave = User::where("id", $user_id)->setDec('user_money', $amount);
|
||||
$newBalance = round($userMoney - $amount, 2);
|
||||
if($data['pay_way'] == 3){
|
||||
$userSave = UserStoreMoney::where("user_id", $user_id)->where("store_id",$data['store_id'])->update(['money' => $newBalance,"update_dtime"=>date("Y-m-d H:i:s")]);
|
||||
}else{
|
||||
$userSave = User::where("id", $user_id)->update(['user_money' => $newBalance,"update_time"=>time()]);
|
||||
|
||||
}
|
||||
if (!$userSave) {
|
||||
throw new \Exception('用户余额扣减失败');
|
||||
}
|
||||
$change_type = 0;
|
||||
$sub_sn = 0;
|
||||
// 5. 更新订单状态
|
||||
if($pay['order_type'] == 1) {
|
||||
$change_type = 1;
|
||||
$type = 3;
|
||||
// 修改优惠券使用状态
|
||||
if($order['group_coupon_id']>=0){
|
||||
UserGroup::where("id", $order['group_coupon_id'])->update(["status"=>1]);
|
||||
}
|
||||
if($order['user_coupon_id']>=0){
|
||||
UserCoupon::where('id',$order['user_coupon_id'])->update(["status"=>1]);
|
||||
}
|
||||
|
||||
$amount = $order['order_amount'];
|
||||
$orderUpdate = OrderStore::where("id", $pay['order_id'])->update([
|
||||
'order_status' => 1,
|
||||
'pay_status' => 1,
|
||||
'update_dtime' => $currentTime
|
||||
]);
|
||||
if(isset($order['room_id'])){
|
||||
if($order['room_id']!=0&&$order['room_id']!=""&&$order['room_id']!=null){
|
||||
TeaStoreRoom::where('id', $order['room_id'])->inc('sold', 1)->update();
|
||||
}
|
||||
}
|
||||
|
||||
if (!$orderUpdate) {
|
||||
throw new \Exception('订单状态更新失败');
|
||||
}
|
||||
}elseif($pay['order_type'] == 2){
|
||||
$change_type = 4;
|
||||
$type = 6;
|
||||
$orderUpdate = OrderGroup::where("id", $pay['order_id'])->update([
|
||||
'order_status' => 1,
|
||||
'pay_status' => 1,
|
||||
'update_dtime' => $currentTime
|
||||
]);
|
||||
if (!$orderUpdate) {
|
||||
throw new \Exception('订单状态更新失败');
|
||||
}
|
||||
$qr_sn = createSn("user_group","qr_sn");
|
||||
$qr_url = CommonLogic::qrcode($qr_sn);
|
||||
$group = TeaStoreGroup::where('id', $order['group_id'])->find();
|
||||
UserGroup::create([
|
||||
"user_id"=>$user_id,
|
||||
"group_id"=>$order['group_id'],
|
||||
"qr_sn"=>$qr_sn,
|
||||
"qr_url"=>$qr_url['file_url'],
|
||||
"type"=>$group['type'],
|
||||
"order_id"=>$order['id'],
|
||||
"store_id"=>$order['store_id'],
|
||||
"dtime"=>date("Y-m-d H:i:s")
|
||||
]);
|
||||
if(isset($order['group_id'])){
|
||||
if($order['group_id']!=0&&$order['group_id']!=""&&$order['group_id']!=null){
|
||||
TeaStoreGroup::where('id', $order['group_id'])->inc('sold', 1)->update();
|
||||
}
|
||||
}
|
||||
}elseif($pay['order_type'] == 7){
|
||||
$renew_order = OrderStoreRenew::where('id',$pay['order_id'])->find();
|
||||
if(!$renew_order){
|
||||
throw new \Exception('付款失败,订单不存在');
|
||||
}
|
||||
$source_id = $renew_order->source_id;
|
||||
$store_order = OrderStore::where('id',$source_id)->find();
|
||||
if(!$store_order){
|
||||
throw new \Exception('包间订单错误,订单不存在');
|
||||
}
|
||||
$renew_timeslot = explode(',', $renew_order->timeslot);
|
||||
$store_timeslot = explode(',', $store_order->timeslot);
|
||||
$timeList = array_merge($store_timeslot, $renew_timeslot);
|
||||
$end = end($timeList);
|
||||
|
||||
$renew_price = $renew_order->price;
|
||||
$renew_order->pay_status = 1;
|
||||
$renew_order->pay_dtime = 1;
|
||||
$renew_order->save();
|
||||
|
||||
$transfer_order = OrderStore::where('transfer_order_id',$store_order['id'])->select();
|
||||
$ids = explode(',',$store_order->id);
|
||||
if($transfer_order->count() > 0){
|
||||
$orderIds = $transfer_order->column('id');
|
||||
$ids = array_merge($ids,$orderIds);
|
||||
}
|
||||
OrderStore::whereIn("id",$ids)->update([
|
||||
"end_time"=>$end,
|
||||
'timeslot'=>implode(',', $timeList),
|
||||
'renew_dtime'=>implode(',', $timeList),
|
||||
'is_renewal'=>1,
|
||||
'renew_price'=>$renew_order->price+$store_order->renew_price,
|
||||
'renew_hour'=>$renew_order->hour + $store_order->renew_hour,
|
||||
'store_income_price'=>$store_order->store_income_price+$renew_price
|
||||
|
||||
]);
|
||||
$change_type = 2;
|
||||
$type = 7;
|
||||
$sub_sn =$renew_order->order_sn;
|
||||
$order['order_sn'] =$store_order->order_sn;
|
||||
$order['store_id'] =$store_order->store_id;
|
||||
$order['room_id'] =$store_order->room_id;
|
||||
$amount = $renew_order->price;
|
||||
|
||||
}
|
||||
OrderAll::where("source_sn", $order['order_sn'])->where("type", $type)->update([
|
||||
'order_status' => 1,
|
||||
'pay_status' => 1,
|
||||
'pay_way'=>$order['pay_way'],
|
||||
'update_time' => time()
|
||||
]);
|
||||
|
||||
|
||||
// 6. 更新支付记录
|
||||
$payUpdate = Pay::where("id", $payId)->update([
|
||||
'order_sn' => createSn('pay', 'order_sn'),
|
||||
'pay_status' => 1,
|
||||
'pay_time' => $currentTime
|
||||
]);
|
||||
if (!$payUpdate) {
|
||||
throw new \Exception('支付记录更新失败');
|
||||
}
|
||||
|
||||
// 7. 记录资金流水(使用数值类型的金额)
|
||||
$moneyLog = self::addUserAccountLog(
|
||||
$user_id,
|
||||
$change_type,
|
||||
$amount,
|
||||
$userMoney,
|
||||
$newBalance,
|
||||
$order
|
||||
);
|
||||
$change_object = 1;
|
||||
if($data['pay_way'] == 3){
|
||||
$amount = 0;
|
||||
$change_object = 3;
|
||||
|
||||
}
|
||||
if($pay['order_type'] != 2){
|
||||
// 记录店家资金流水(使用数值类型的金额)
|
||||
self::addStoreUserAccountLog(
|
||||
$data['pay_way'],
|
||||
$pay['order_type'],
|
||||
$user_id,
|
||||
$change_object,
|
||||
$change_type,
|
||||
$amount,
|
||||
$order,
|
||||
$sub_sn
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
// 8. 记录支付日志
|
||||
self::addPayLog($payId, $user_id, $amount, 'success');
|
||||
|
||||
Db::commit();
|
||||
|
||||
// 9. 支付成功后的后续操作(可异步处理)
|
||||
self::afterPaySuccess($pay['order_id'], $user_id);
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
'pay_id' => $payId,
|
||||
'order_id' => $pay['order_id'],
|
||||
'order_sn' => $order['order_sn'],
|
||||
'amount' => $displayAmount, // 返回格式化后的金额用于显示
|
||||
'balance' => number_format($userMoney - $amount, 2) // 格式化余额
|
||||
];
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
// 记录支付失败日志
|
||||
if (isset($payId)) {
|
||||
self::addPayLog($payId, $user_id, $amount ?? 0, 'fail', $e->getMessage());
|
||||
}
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static function addUserAccountLog($user_id,$change_type, $amount,$userMoney, $newBalance,$order)
|
||||
{
|
||||
return Db::name('user_account_log')->insert([
|
||||
'sn'=>createSn("user_account_log","sn"),
|
||||
'user_id' => $user_id,
|
||||
'change_object'=>1,
|
||||
'change_type'=>$change_type,
|
||||
'action'=>2,
|
||||
'amount' => $amount,
|
||||
'before_amount'=>$userMoney,
|
||||
'after_amount' => $newBalance,
|
||||
'source_sn' => $order['order_sn'],
|
||||
'store_id'=>$order['store_id'],
|
||||
'create_time' => time()
|
||||
]);
|
||||
}
|
||||
private static function addStoreUserAccountLog($pay_way,$order_type,$user_id,$change_object,$change_type, $amount,$order,$sub_sn)
|
||||
{
|
||||
|
||||
|
||||
$tea_store = TeaStore::where("id",$order['store_id'])->find();
|
||||
// if($amount != 0){
|
||||
StoreUserAccountLog::create([
|
||||
'sn'=>createSn("store_user_account_log","sn"),
|
||||
'change_object'=>$change_object,
|
||||
'change_type'=>$change_type,
|
||||
'user_id'=>$user_id,
|
||||
'action'=>1,
|
||||
'amount' => $amount,
|
||||
'before_amount'=>$tea_store['balance'],
|
||||
'after_amount' => round($amount+$tea_store['balance'],2),
|
||||
'source_sn' => $order['order_sn'],
|
||||
'store_id'=>$order['store_id'],
|
||||
'sub_sn'=>$sub_sn,
|
||||
'room_id'=>$order['room_id'],
|
||||
'create_time' => time()
|
||||
]);
|
||||
|
||||
// if($order_type == 7 ){
|
||||
// TeaStore::where('id', $order['store_id'])->inc('total_amount', $amount)->update();
|
||||
// TeaStore::where('id', $order['store_id'])->inc('balance', $amount)->update();
|
||||
// }
|
||||
if($pay_way != 3){
|
||||
TeaStore::where('id', $order['store_id'])->inc('total_amount',$amount)->update();
|
||||
TeaStore::where('id', $order['store_id'])->inc('balance', $amount)->update();
|
||||
}
|
||||
// }
|
||||
|
||||
|
||||
if($order['group_coupon_id'] != 0&&$order_type == 1){
|
||||
$group = UserGroup::where("id",$order['group_coupon_id'])->find();
|
||||
$store_group = TeaStoreGroup::where("id",$group['group_id'])->find();
|
||||
$change_object = 4;
|
||||
|
||||
if($group['type'] == 2){
|
||||
$store_group['discount_price'] = 0;
|
||||
$change_object = 5;
|
||||
$amount = 0;
|
||||
}
|
||||
|
||||
StoreUserAccountLog::create([
|
||||
'sn'=>createSn("store_user_account_log","sn"),
|
||||
'change_object'=>$change_object,
|
||||
'change_type'=>1,
|
||||
'user_id'=>$user_id,
|
||||
'action'=>1,
|
||||
'amount' => $store_group['discount_price'],
|
||||
'before_amount'=>round($tea_store['balance']+$amount,2),
|
||||
'after_amount' => round($tea_store['balance']+$amount+$store_group['discount_price'],2),
|
||||
'source_sn' => $order['order_sn'],
|
||||
'store_id'=>$order['store_id'],
|
||||
'room_id'=>$order['room_id'],
|
||||
'remark'=>"团购套餐",
|
||||
'create_time' => time()
|
||||
]);
|
||||
TeaStore::where('id', $order['store_id'])->inc('total_amount', $store_group['discount_price'])->update();
|
||||
TeaStore::where('id', $order['store_id'])->inc('balance', $store_group['discount_price'])->update();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* 记录支付日志
|
||||
*/
|
||||
private static function addPayLog($pay_id, $user_id, $amount, $status, $message = '')
|
||||
{
|
||||
return Db::name('pay_log')->insert([
|
||||
'pay_id' => $pay_id,
|
||||
'user_id' => $user_id,
|
||||
'amount' => $amount,
|
||||
'status' => $status,
|
||||
'message' => $message,
|
||||
'create_time' => time()
|
||||
]);
|
||||
}
|
||||
|
||||
// 退款
|
||||
public static function refund($data, $user_id){
|
||||
$refund_msg = RefundRecord::where("id",$data['id'])->find();
|
||||
$remark = "";
|
||||
$change_type = 0;
|
||||
// 判断是否为微信支付
|
||||
// 0为茶艺师 1为茶室支付 2购买套餐 3购买会员 4充值 5团购退款 6茶室退款
|
||||
|
||||
if($refund_msg['order_type'] == 5){
|
||||
$order = OrderGroup::where("order_sn",$refund_msg['source_sn'])->find();
|
||||
$remark = "团购套餐退款";
|
||||
$order_amount = $order['order_amount'];
|
||||
}elseif($refund_msg['order_type'] == 1){
|
||||
$order = OrderStore::where("order_sn",$refund_msg['source_sn'])->find();
|
||||
$remark = "包间预定退款";
|
||||
$order_amount = $order['store_income_price'];
|
||||
$change_type = 1;
|
||||
}
|
||||
if(isset($order)){
|
||||
// 微信支付
|
||||
if($order['pay_way'] == 2){
|
||||
if($order['order_amount'] <= 0){
|
||||
//查询是否使用优惠券
|
||||
if($order['user_coupon_id'] != 0){
|
||||
$r = UserCoupon::where("id",$order['user_coupon_id'])->update(['status'=>0]);
|
||||
}
|
||||
//查询是否使用团购券
|
||||
if($order['group_coupon_id'] != 0){
|
||||
$r = UserGroup::where("id",$order['user_coupon_id'])->update(['status'=>0]);
|
||||
}
|
||||
if(!isset($r)){
|
||||
throw new \Exception('退款失败100001');
|
||||
}
|
||||
}else{
|
||||
if($refund_msg['order_type'] == 5){
|
||||
UserGroup::where('order_id',$order['id'])->update(['status'=>4]);
|
||||
}
|
||||
$refundData = [
|
||||
'transaction_id'=>$order->transaction_id,
|
||||
'refund_sn'=>$refund_msg->order_sn,
|
||||
'total_amount'=>$order->order_amount,
|
||||
'notify_url'=>FileService::getFileUrl('api/pay/notifyMnp'),
|
||||
];
|
||||
$payService = (new WeChatPayService(1, $user_id ?? null));
|
||||
$result = $payService->refund($refundData);
|
||||
if($result['status'] !=='PROCESSING'){
|
||||
throw new \Exception('押金退款失败请联系客服');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}else{
|
||||
|
||||
// 余额退款
|
||||
RefundRecord::where("id",$data['id'])->update(['refund_way'=>3,'refund_status'=>1]);
|
||||
// 更新总表状态
|
||||
OrderAll::where("source_sn",$refund_msg['order_sn'])->where("type",$refund_msg['order_type'])->update([
|
||||
"pay_way"=>$order['pay_way'],
|
||||
"order_status"=>5,
|
||||
"pay_status"=>1,
|
||||
"pay_time"=>time(),
|
||||
"update_time"=>time()
|
||||
]);
|
||||
$user = User::where("id",$user_id)->find();
|
||||
$money = 0;
|
||||
$user_money = 0;
|
||||
if($order['pay_way'] == 1){
|
||||
// 平台余额
|
||||
$money = $user['user_money'];
|
||||
$user_money = round($user['user_money']+$refund_msg['refund_amount'],2);
|
||||
User::where("id",$user_id)->update(['user_money'=>$user_money]);
|
||||
}else{
|
||||
// 门店余额
|
||||
$user_store_money = UserStoreMoney::where("user_id",$user_id)->where("store_id",$order['store_id'])->find();
|
||||
$money = $user_store_money['money'];
|
||||
$user_money = round($user_store_money['money']+$refund_msg['refund_amount'],2);
|
||||
UserStoreMoney::where("user_id",$user_id)->where("store_id",$order['store_id'])->update(['money'=>$user_money]);
|
||||
}
|
||||
|
||||
// 更新用户流水
|
||||
UserAccountLog::create([
|
||||
"sn"=>createSn("user_account_log","sn"),
|
||||
"user_id"=>$user_id,
|
||||
"change_object"=>1,
|
||||
"change_type"=>5,
|
||||
"action"=>1,
|
||||
"amount"=>$refund_msg['refund_amount'],
|
||||
"before_amount"=>$money,
|
||||
"after_amount"=>$user_money,
|
||||
"source_sn"=>$refund_msg['order_sn'],
|
||||
"store_id"=>$refund_msg['store_id'],
|
||||
"remark"=>$remark,
|
||||
"create_time"=>time()
|
||||
]);
|
||||
|
||||
}
|
||||
// 修改订单状态
|
||||
if($refund_msg['order_type'] == 5){
|
||||
$rs = OrderGroup::where("order_sn",$refund_msg['source_sn'])->update(['order_status'=>5]);
|
||||
UserGroup::where("id",$refund_msg['content_id'])->update(['status'=>3]);
|
||||
}elseif($refund_msg['order_type'] == 1){
|
||||
$rs = OrderStore::where("order_sn",$refund_msg['source_sn'])->update(['order_status'=>5]);
|
||||
}
|
||||
if(isset($rs)){
|
||||
if(!$rs){
|
||||
throw new \Exception('退款失败100002');
|
||||
}
|
||||
}else{
|
||||
throw new \Exception('退款失败100003');
|
||||
}
|
||||
// if($refund_msg['order_type'] == 5){
|
||||
// // 扣除店家余额
|
||||
// $tes_store = TeaStore::where('id', $order['store_id'])->find();
|
||||
// $total_amount = round($tes_store['total_amount'] - $order_amount,2);
|
||||
// $balance = round($tes_store['balance'] - $order_amount,2);
|
||||
// TeaStore::where('id', $order['store_id'])->update(['total_amount'=>$total_amount,'balance'=>$balance]);
|
||||
// // 添加店家流水
|
||||
// StoreUserAccountLog::create([
|
||||
// 'order_sn'=>createSn("store_user_account_log","order_sn"),
|
||||
// 'change_object'=>1,
|
||||
// 'change_type'=>$change_type,
|
||||
// 'action'=>2,
|
||||
// 'amount' => $order_amount,
|
||||
// 'before_amount'=>$tes_store['balance'],
|
||||
// 'after_amount' => $balance,
|
||||
// 'source_sn' => $order['order_sn'],
|
||||
// 'store_id'=>$order['store_id'],
|
||||
// 'room_id'=>$order['room_id'],
|
||||
// 'remark'=>$remark,
|
||||
// 'create_time' => time()
|
||||
// ]);
|
||||
// }
|
||||
|
||||
return true;
|
||||
}else{
|
||||
throw new \Exception('暂无订单信息');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 支付成功后置操作
|
||||
*/
|
||||
private static function afterPaySuccess($order_id, $user_id)
|
||||
{
|
||||
// 可以在这里处理:
|
||||
// 1. 发送通知
|
||||
// 2. 更新库存
|
||||
// 3. 记录日志
|
||||
// 4. 触发其他业务逻辑
|
||||
|
||||
// 示例:发送支付成功通知
|
||||
// NoticeService::sendPaySuccessNotice($user_id, $order_id);
|
||||
}
|
||||
|
||||
}
|
||||
246
app/api/logic/PcLogic.php
Normal file
246
app/api/logic/PcLogic.php
Normal file
@ -0,0 +1,246 @@
|
||||
<?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\api\logic;
|
||||
|
||||
|
||||
use app\common\enum\YesNoEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\article\Article;
|
||||
use app\common\model\article\ArticleCate;
|
||||
use app\common\model\article\ArticleCollect;
|
||||
use app\common\model\decorate\DecoratePage;
|
||||
use app\common\service\ConfigService;
|
||||
use app\common\service\FileService;
|
||||
|
||||
|
||||
/**
|
||||
* index
|
||||
* Class IndexLogic
|
||||
* @package app\api\logic
|
||||
*/
|
||||
class PcLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 首页数据
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/9/21 19:15
|
||||
*/
|
||||
public static function getIndexData()
|
||||
{
|
||||
// 装修配置
|
||||
$decoratePage = DecoratePage::findOrEmpty(4);
|
||||
// 最新资讯
|
||||
$newArticle = self::getLimitArticle('new', 7);
|
||||
// 全部资讯
|
||||
$allArticle = self::getLimitArticle('all', 5);
|
||||
// 热门资讯
|
||||
$hotArticle = self::getLimitArticle('hot', 8);
|
||||
|
||||
return [
|
||||
'page' => $decoratePage,
|
||||
'all' => $allArticle,
|
||||
'new' => $newArticle,
|
||||
'hot' => $hotArticle
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取文章
|
||||
* @param string $sortType
|
||||
* @param int $limit
|
||||
* @return mixed
|
||||
* @author 段誉
|
||||
* @date 2022/10/19 9:53
|
||||
*/
|
||||
public static function getLimitArticle(string $sortType, int $limit = 0, int $cate = 0, int $excludeId = 0)
|
||||
{
|
||||
// 查询字段
|
||||
$field = [
|
||||
'id', 'cid', 'title', 'desc', 'abstract', 'image',
|
||||
'author', 'click_actual', 'click_virtual', 'create_time'
|
||||
];
|
||||
|
||||
// 排序条件
|
||||
$orderRaw = 'sort desc, id desc';
|
||||
if ($sortType == 'new') {
|
||||
$orderRaw = 'id desc';
|
||||
}
|
||||
if ($sortType == 'hot') {
|
||||
$orderRaw = 'click_actual + click_virtual desc, id desc';
|
||||
}
|
||||
|
||||
// 查询条件
|
||||
$where[] = ['is_show', '=', YesNoEnum::YES];
|
||||
if (!empty($cate)) {
|
||||
$where[] = ['cid', '=', $cate];
|
||||
}
|
||||
if (!empty($excludeId)) {
|
||||
$where[] = ['id', '<>', $excludeId];
|
||||
}
|
||||
|
||||
$article = Article::field($field)
|
||||
->where($where)
|
||||
->append(['click'])
|
||||
->orderRaw($orderRaw)
|
||||
->hidden(['click_actual', 'click_virtual']);
|
||||
|
||||
if ($limit) {
|
||||
$article->limit($limit);
|
||||
}
|
||||
|
||||
return $article->select()->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取配置
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/9/21 19:38
|
||||
*/
|
||||
public static function getConfigData()
|
||||
{
|
||||
// 登录配置
|
||||
$loginConfig = [
|
||||
// 登录方式
|
||||
'login_way' => ConfigService::get('login', 'login_way', config('project.login.login_way')),
|
||||
// 注册强制绑定手机
|
||||
'coerce_mobile' => ConfigService::get('login', 'coerce_mobile', config('project.login.coerce_mobile')),
|
||||
// 政策协议
|
||||
'login_agreement' => ConfigService::get('login', 'login_agreement', config('project.login.login_agreement')),
|
||||
// 第三方登录 开关
|
||||
'third_auth' => ConfigService::get('login', 'third_auth', config('project.login.third_auth')),
|
||||
// 微信授权登录
|
||||
'wechat_auth' => ConfigService::get('login', 'wechat_auth', config('project.login.wechat_auth')),
|
||||
// qq授权登录
|
||||
'qq_auth' => ConfigService::get('login', 'qq_auth', config('project.login.qq_auth')),
|
||||
];
|
||||
|
||||
// 网站信息
|
||||
$website = [
|
||||
'shop_name' => ConfigService::get('website', 'shop_name'),
|
||||
'shop_logo' => FileService::getFileUrl(ConfigService::get('website', 'shop_logo')),
|
||||
'pc_logo' => FileService::getFileUrl(ConfigService::get('website', 'pc_logo')),
|
||||
'pc_title' => ConfigService::get('website', 'pc_title'),
|
||||
'pc_ico' => FileService::getFileUrl(ConfigService::get('website', 'pc_ico')),
|
||||
'pc_desc' => ConfigService::get('website', 'pc_desc'),
|
||||
'pc_keywords' => ConfigService::get('website', 'pc_keywords'),
|
||||
];
|
||||
|
||||
// 站点统计
|
||||
$siteStatistics = [
|
||||
'clarity_code' => ConfigService::get('siteStatistics', 'clarity_code'),
|
||||
];
|
||||
|
||||
// 备案信息
|
||||
$copyright = ConfigService::get('copyright', 'config', []);
|
||||
|
||||
// 公众号二维码
|
||||
$oaQrCode = ConfigService::get('oa_setting', 'qr_code', '');
|
||||
$oaQrCode = empty($oaQrCode) ? $oaQrCode : FileService::getFileUrl($oaQrCode);
|
||||
// 小程序二维码
|
||||
$mnpQrCode = ConfigService::get('mnp_setting', 'qr_code', '');
|
||||
$mnpQrCode = empty($mnpQrCode) ? $mnpQrCode : FileService::getFileUrl($mnpQrCode);
|
||||
|
||||
return [
|
||||
'domain' => FileService::getFileUrl(),
|
||||
'login' => $loginConfig,
|
||||
'website' => $website,
|
||||
'siteStatistics' => $siteStatistics,
|
||||
'version' => config('project.version'),
|
||||
'copyright' => $copyright,
|
||||
'admin_url' => request()->domain() . '/admin',
|
||||
'qrcode' => [
|
||||
'oa' => $oaQrCode,
|
||||
'mnp' => $mnpQrCode,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 资讯中心
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/10/19 16:55
|
||||
*/
|
||||
public static function getInfoCenter()
|
||||
{
|
||||
$data = ArticleCate::field(['id', 'name'])
|
||||
->with(['article' => function ($query) {
|
||||
$query->hidden(['content', 'click_virtual', 'click_actual'])
|
||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||
->append(['click'])
|
||||
->limit(10);
|
||||
}])
|
||||
->where(['is_show' => YesNoEnum::YES])
|
||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取文章详情
|
||||
* @param $userId
|
||||
* @param $articleId
|
||||
* @param string $source
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/10/20 15:18
|
||||
*/
|
||||
public static function getArticleDetail($userId, $articleId, $source = 'default')
|
||||
{
|
||||
// 文章详情
|
||||
$detail = Article::getArticleDetailArr($articleId);
|
||||
|
||||
// 根据来源列表查找对应列表
|
||||
$nowIndex = 0;
|
||||
$lists = self::getLimitArticle($source, 0, $detail['cid']);
|
||||
foreach ($lists as $key => $item) {
|
||||
if ($item['id'] == $articleId) {
|
||||
$nowIndex = $key;
|
||||
}
|
||||
}
|
||||
// 上一篇
|
||||
$detail['last'] = $lists[$nowIndex - 1] ?? [];
|
||||
// 下一篇
|
||||
$detail['next'] = $lists[$nowIndex + 1] ?? [];
|
||||
|
||||
// 最新资讯
|
||||
$detail['new'] = self::getLimitArticle('new', 8, $detail['cid'], $detail['id']);
|
||||
// 关注状态
|
||||
$detail['collect'] = ArticleCollect::isCollectArticle($userId, $articleId);
|
||||
// 分类名
|
||||
$detail['cate_name'] = ArticleCate::where('id', $detail['cid'])->value('name');
|
||||
|
||||
return $detail;
|
||||
}
|
||||
|
||||
}
|
||||
88
app/api/logic/RechargeLogic.php
Normal file
88
app/api/logic/RechargeLogic.php
Normal file
@ -0,0 +1,88 @@
|
||||
<?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\api\logic;
|
||||
|
||||
use app\common\enum\PayEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\order\OrderStore;
|
||||
use app\common\model\recharge\RechargeOrder;
|
||||
use app\common\model\user\User;
|
||||
use app\common\service\ConfigService;
|
||||
|
||||
|
||||
/**
|
||||
* 充值逻辑层
|
||||
* Class RechargeLogic
|
||||
* @package app\shopapi\logic
|
||||
*/
|
||||
class RechargeLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 充值
|
||||
* @param array $params
|
||||
* @return array|false
|
||||
* @author 段誉
|
||||
* @date 2023/2/24 10:43
|
||||
*/
|
||||
public static function recharge(array $params)
|
||||
{
|
||||
try {
|
||||
$order_sn = generate_sn(RechargeOrder::class, 'order_sn');
|
||||
$data = [
|
||||
'order_sn' => $order_sn,
|
||||
'order_terminal' => $params['terminal'],
|
||||
'user_id' => $params['user_id'],
|
||||
'pay_status' => PayEnum::UNPAID,
|
||||
'order_amount' => $params['money'],
|
||||
];
|
||||
$order = RechargeOrder::create($data);
|
||||
// 0为茶艺师 1为茶室支付 2购买套餐 3购买会员 4充值
|
||||
OrderStore::orderAll("recharge_order",4,$order_sn,0,$params['money'], $params['user_id']);
|
||||
return [
|
||||
'order_id' => (int)$order['id'],
|
||||
'from' => 'recharge'
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 充值配置
|
||||
* @param $userId
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2023/2/24 16:56
|
||||
*/
|
||||
public static function config($userId)
|
||||
{
|
||||
$userMoney = User::where(['id' => $userId])->value('user_money');
|
||||
$minAmount = ConfigService::get('recharge', 'min_amount', 0);
|
||||
$status = ConfigService::get('recharge', 'status', 0);
|
||||
|
||||
return [
|
||||
'status' => $status,
|
||||
'min_amount' => $minAmount,
|
||||
'user_money' => $userMoney,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
53
app/api/logic/SearchLogic.php
Normal file
53
app/api/logic/SearchLogic.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?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\api\logic;
|
||||
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\HotSearch;
|
||||
use app\common\service\ConfigService;
|
||||
|
||||
/**
|
||||
* 搜索逻辑
|
||||
* Class SearchLogic
|
||||
* @package app\api\logic
|
||||
*/
|
||||
class SearchLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 热搜列表
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/9/23 14:34
|
||||
*/
|
||||
public static function hotLists()
|
||||
{
|
||||
$data = HotSearch::field(['name', 'sort'])
|
||||
->order(['sort' => 'desc', 'id' => 'desc'])
|
||||
->select()->toArray();
|
||||
|
||||
return [
|
||||
// 功能状态 0-关闭 1-开启
|
||||
'status' => ConfigService::get('hot_search', 'status', 0),
|
||||
// 热门搜索数据
|
||||
'data' => $data,
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
60
app/api/logic/SmsLogic.php
Normal file
60
app/api/logic/SmsLogic.php
Normal 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\api\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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
35
app/api/logic/StoreLogic.php
Normal file
35
app/api/logic/StoreLogic.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\store\StoreUser;
|
||||
|
||||
class StoreLogic extends BaseLogic
|
||||
{
|
||||
public static function storeList($post){
|
||||
$s = "";
|
||||
if(isset($post['search'])){
|
||||
if($post['search'] != ""){
|
||||
$b = $post['search'];
|
||||
$s = "name like '%".$b."%'";
|
||||
}
|
||||
}
|
||||
$count = Store::where($s)->count();
|
||||
$lists = Store::where($s)
|
||||
->page($post['page'], $post['size'])
|
||||
->select()
|
||||
->toarray();
|
||||
foreach($lists as $key=>$value){
|
||||
$lists[$key]['distance'] = calculateDistanceKm($value['lat'],$value['lon'],$post['latitude'],$post['longitude']);
|
||||
}
|
||||
$data = [
|
||||
'list' => $lists,
|
||||
'page' => $post['page'],
|
||||
'size' => $post['size'],
|
||||
'count' => $count,
|
||||
'more' => is_more($count, $post['page'], $post['size'])
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
130
app/api/logic/SubmitFormLogic.php
Normal file
130
app/api/logic/SubmitFormLogic.php
Normal file
@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
use app\common\enum\notice\NoticeEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\teamaster\Teamaster;
|
||||
use app\common\model\teamaster\TeamasterUser;
|
||||
use app\common\model\teamaster\TeamasterReal;
|
||||
use app\common\model\teastore\TeaStoreReal;
|
||||
use app\common\service\sms\SmsDriver;
|
||||
use think\facade\Db;
|
||||
|
||||
class SubmitFormLogic extends BaseLogic
|
||||
{
|
||||
|
||||
public static function addTeamaster($data){
|
||||
Db::startTrans();
|
||||
try {
|
||||
// 校验验证码
|
||||
$smsDriver = new SmsDriver();
|
||||
if (!$smsDriver->verify($data['mobile'], $data['code'], NoticeEnum::FIND_MOBILE_CAPTCHA)) {
|
||||
throw new \Exception('验证码错误');
|
||||
}
|
||||
|
||||
$license_img = isset($data['license_img']) ? $data['license_img'] : '';
|
||||
$certificate = isset($data['certificate']) ? $data['certificate'] : '';
|
||||
$real = TeamasterReal::where([
|
||||
'mobile'=>$data['mobile'],
|
||||
])->whereIn('status',[0,1])->find();
|
||||
if($real){
|
||||
throw new \Exception('当前手机号已申请');
|
||||
}
|
||||
if($data['gender'] == "男"){
|
||||
$data['gender'] = 1;
|
||||
}elseif($data['gender'] == "女"){
|
||||
$data['gender'] = 2;
|
||||
}
|
||||
$data = [
|
||||
'license_img'=>$license_img,
|
||||
'username'=>$data['username'],
|
||||
'gender'=>$data['gender'],
|
||||
'both'=>$data['both'],
|
||||
'user_id'=>$data['user_id'],
|
||||
'height'=>$data['height'],
|
||||
'weight'=>$data['weight'],
|
||||
'hobby_introduce'=>$data['hobby_introduce'],
|
||||
'city_id'=>$data['city_id'],
|
||||
'avatar'=>$data['avatar'],
|
||||
'certificate'=>$certificate,
|
||||
'mobile'=>$data['mobile'],
|
||||
'create_time'=>time()
|
||||
];
|
||||
|
||||
TeamasterReal::create($data);
|
||||
Db::commit();
|
||||
return [];
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function addStore($data){
|
||||
Db::startTrans();
|
||||
try {
|
||||
// 校验验证码
|
||||
$smsDriver = new SmsDriver();
|
||||
if (!$smsDriver->verify($data['mobile'], $data['code'], NoticeEnum::FIND_MOBILE_CAPTCHA)) {
|
||||
throw new \Exception('验证码错误');
|
||||
}
|
||||
|
||||
$license_img = isset($data['license_img']) ? $data['license_img'] : '';
|
||||
$operation_type= isset($data['operation_type']) ? $data['operation_type'] : '';
|
||||
$real = TeaStoreReal::where([
|
||||
'mobile'=>$data['mobile'],
|
||||
])->whereIn('status',[0,1])->find();
|
||||
if($real){
|
||||
throw new \Exception('当前手机号已申请');
|
||||
}
|
||||
|
||||
$data = [
|
||||
'license_img'=>$license_img,
|
||||
'username'=>$data['username'],
|
||||
'address'=>$data['address'],
|
||||
'user_id'=>$data['user_id'],
|
||||
'suggest'=>$data['suggest'],
|
||||
'city_id'=>$data['city_id'],
|
||||
'operation_type'=>$operation_type,
|
||||
'mobile'=>$data['mobile'],
|
||||
'create_time'=>time()
|
||||
];
|
||||
|
||||
TeaStoreReal::create($data);
|
||||
Db::commit();
|
||||
return [];
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function teamasterRealStatus($data){
|
||||
$real = TeamasterReal::where([
|
||||
'user_id'=>$data['user_id'],
|
||||
])->find();
|
||||
$status = 3;
|
||||
if($real){
|
||||
$status = $real['status'];
|
||||
}
|
||||
return ['status'=>$status];
|
||||
}
|
||||
public static function StoreRealStatus($data){
|
||||
$real = TeaStoreReal::where([
|
||||
'user_id'=>$data['user_id'],
|
||||
])->find();
|
||||
$status = 3;
|
||||
if($real){
|
||||
$status = $real['status'];
|
||||
}
|
||||
|
||||
return ['status'=>$status];
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
261
app/api/logic/TaskLogic.php
Normal file
261
app/api/logic/TaskLogic.php
Normal file
@ -0,0 +1,261 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\order\OrderStore;
|
||||
use app\common\model\order\OrderTeamaster;
|
||||
use app\common\model\store\StoreUserAccountLog;
|
||||
use app\common\model\teastore\TeaStore;
|
||||
use app\common\model\teastore\TeaStoreRoom;
|
||||
use app\common\model\teamaster\TeamasterUser;
|
||||
use app\common\service\iot\IotService;
|
||||
use app\common\service\iot\DoorService;
|
||||
use app\common\model\user\User;
|
||||
use app\common\model\user\UserMember;
|
||||
use app\common\service\pay\WxRefundService;
|
||||
use app\common\service\VoiceNotifyService;
|
||||
use think\facade\Db;
|
||||
|
||||
|
||||
class TaskLogic extends BaseLogic
|
||||
{
|
||||
public static function run()
|
||||
{
|
||||
self::order();
|
||||
self::openlock();
|
||||
self::openLamp();
|
||||
self::closeLamp();
|
||||
self::speaker();
|
||||
self::openlock();
|
||||
self::orderCancel();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* 订单相关操作
|
||||
*/
|
||||
public static function order()
|
||||
{
|
||||
//预约订单取消
|
||||
|
||||
$fiveMinutesAgo = date('Y-m-d H:i:s', time() - 60*5);
|
||||
|
||||
OrderStore::where('order_status', 0)
|
||||
->where('dtime', '<', $fiveMinutesAgo)
|
||||
->update(['order_status' => 4]);
|
||||
|
||||
|
||||
//待使用->已使用
|
||||
OrderStore::where('order_status', 1)
|
||||
->where('start_time', '<', time())
|
||||
->update([
|
||||
'order_status' => 2
|
||||
]);
|
||||
//已使用->已完成
|
||||
// 获取所有需要处理的订单ID
|
||||
$orderArr = OrderStore::where("order_status = 2")
|
||||
->where('end_time', '<', time())
|
||||
->field('id,order_sn')->select()->toArray();
|
||||
|
||||
$orderIds =[];
|
||||
foreach ($orderArr as &$ids){
|
||||
$orderIds[] = $ids['id'];
|
||||
}
|
||||
|
||||
// 批量更新订单状态
|
||||
if (!empty($orderIds)) {
|
||||
OrderStore::whereIn('id', $orderIds)
|
||||
->update(['order_status' => 3]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
// 空开-打开
|
||||
public static function openLamp(){
|
||||
$orderList = OrderStore::where('order_status','1')->select();
|
||||
foreach ($orderList as $v){
|
||||
if (time() + 60 * 20 > $v['start_time']) {
|
||||
$roomInfo = TeaStoreRoom::where(['id' => $v['room_id']])->find();
|
||||
if ($roomInfo['is_open'] == 0) {
|
||||
$ty = new IotService();
|
||||
if ($roomInfo['device_id']) {
|
||||
$ty->controlDevice($roomInfo['device_id'],1);// 灯光开关
|
||||
TeaStoreRoom::where(['id' => $v['room_id']])->update(['is_open' => 1,'status'=>5]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
// 空开-关闭
|
||||
public static function closeLamp()
|
||||
{
|
||||
$orderList = OrderStore::where(['order_status'=>'3',"is_release"=>0])->select();
|
||||
|
||||
foreach ($orderList as $v) {
|
||||
$end_time = $v['end_time'];
|
||||
if ((time() >= $end_time + 60 *2) && (time() < $end_time + 60 *3)) {
|
||||
|
||||
$roomInfo = TeaStoreRoom::where(['id' => $v['room_id']])->find();
|
||||
if ($roomInfo['is_open'] == 1) {
|
||||
|
||||
$ty = new IotService();
|
||||
if ($roomInfo['device_id']) {
|
||||
$ty->controlDevice($roomInfo['device_id'],0);// 灯光开关
|
||||
TeaStoreRoom::where(['id' => $v['room_id']])->update(['is_open' => 0,'status'=>1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//音响提醒
|
||||
public static function speaker()
|
||||
{
|
||||
$room = TeaStoreRoom::select();
|
||||
foreach ($room as $v) {
|
||||
$orderInfo = OrderStore::where([
|
||||
'room_id' => $v['id'],
|
||||
'order_status'=>2,
|
||||
|
||||
])->order('id desc')->find();
|
||||
if ($v['speaker_id']&&$orderInfo) {
|
||||
// 结束前10分钟
|
||||
if ($orderInfo['order_status'] == 2 && ($orderInfo['end_time'] - 60 * 10 < time())&& ($orderInfo['end_time'] - 60 * 9 > time())) {
|
||||
$notifyService = new \app\common\service\iot\SpeakerService();
|
||||
$re = $notifyService->sendSpeakerNotify($v['speaker_id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function openlock(){
|
||||
|
||||
$order = OrderStore::where(['order_status'=>1,'is_lockpwd'=>0])->find();
|
||||
if(!$order){
|
||||
return [];
|
||||
}
|
||||
$store_id = $order->store_id;
|
||||
$room_id = $order->room_id;
|
||||
$store = TeaStore::where('id',$store_id)->find();
|
||||
$room = TeaStoreRoom::where('id',$room_id)->find();
|
||||
if(!$order){
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
$istime = $order['start_time'] - 30 * 60;
|
||||
$startTime = date('ymdHi', $istime);
|
||||
$isend = strtotime("+1 day", $order['end_time']);
|
||||
$endTime = date('ymdHi', $isend);
|
||||
$service = new DoorService();
|
||||
$keyboardPwdName = 'tt'.$order['id'];
|
||||
$get_key = '';
|
||||
$room_key = '';
|
||||
if($order->is_lockpwd == 0){
|
||||
|
||||
if($store->lock_no<=0){
|
||||
$get_key = '免密';
|
||||
$order->is_lockpwd = 1;
|
||||
$order->save();
|
||||
}else{
|
||||
|
||||
|
||||
$keyboardPwdstore = rand(100000,999999);
|
||||
$result = $service->createTempPassword($store->lock_no,$keyboardPwdstore,$keyboardPwdName,$istime,$isend);
|
||||
|
||||
$get_key = $keyboardPwdstore.'#';
|
||||
|
||||
}
|
||||
if($room->lock_no<=0){
|
||||
$room_key = '免密';
|
||||
}else{
|
||||
$keyboardPwdroom = rand(100000,999999);
|
||||
$service->createTempPassword($room->lock_no,$keyboardPwdroom,$keyboardPwdName,$istime,$isend);
|
||||
$room_key= $keyboardPwdroom.'#';
|
||||
}
|
||||
|
||||
}
|
||||
OrderStore::where('id',$order->id)->update([
|
||||
'room_key'=>$room_key,
|
||||
'gate_key'=>$get_key,
|
||||
'is_lockpwd'=>1,
|
||||
'update_dtime'=>date('Y-m-d H:i:s')
|
||||
]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//茶艺师自动放弃订单
|
||||
public static function orderCancel(){
|
||||
|
||||
$order = OrderTeamaster::where([
|
||||
'order_status'=>28,
|
||||
'del'=>0
|
||||
])->find();
|
||||
if(!$order){
|
||||
throw new \Exception('订单错误');
|
||||
}
|
||||
|
||||
if($order['pay_time']<time()-60*9){
|
||||
$WxRefundService = new WxRefundService();
|
||||
$result =$WxRefundService->Refund($order,10,40);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static function steVip(){
|
||||
$fiveMinutesAgo = date('Y-m-d H:i:s', time() - 60*5);
|
||||
|
||||
OrderStore::where('order_status', 0)
|
||||
->where('dtime', '<', $fiveMinutesAgo)
|
||||
->update(['order_status' => 4]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 发送简单语音通知
|
||||
*/
|
||||
public static function sendSimple()
|
||||
{
|
||||
|
||||
$order = OrderTeamaster::where([
|
||||
'order_status'=>28,
|
||||
'is_send'=>0
|
||||
])->find();
|
||||
|
||||
if($order){
|
||||
$team_user = TeamasterUser::where('id',$order->team_user_id)->find();
|
||||
$voiceService = new VoiceNotifyService();
|
||||
// 发送语音通知
|
||||
$result = $voiceService->send(
|
||||
$team_user['mobile'], // 被叫手机号
|
||||
'405547', // 模板ID(从文档示例中获取)
|
||||
[], // 模板参数
|
||||
[
|
||||
'displayNumber' => '02161704229', // 主显号码(可选)
|
||||
'replayTimes' => 1, // 重播次数(可选:1,2,3)
|
||||
'callRec' => 0, // 是否录音(可选:0关闭,1开启)
|
||||
]
|
||||
);
|
||||
|
||||
$order->is_send = 1;
|
||||
$order->save();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
538
app/api/logic/TeaStoreLogic.php
Normal file
538
app/api/logic/TeaStoreLogic.php
Normal file
@ -0,0 +1,538 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\service\FileService;
|
||||
use app\common\model\teastore\{TeaStore,
|
||||
TeaStoreCity,
|
||||
TeaStoreCollect,
|
||||
TeaStoreGroup,
|
||||
TeaStoreHistory,
|
||||
TeaStoreQual,
|
||||
TeaStoreRecharge,
|
||||
TeaStoreRoom,
|
||||
TeaStoreRoomLabel,
|
||||
TeaStoreRoomTime};
|
||||
use app\common\model\order\OrderStore;
|
||||
use think\facade\{Db, Config};
|
||||
class TeaStoreLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
public static function getTeaStoreLists($post){
|
||||
$s = "";
|
||||
$or = "distance asc";
|
||||
if(isset($post['search'])){
|
||||
if($post['search'] != ""&&$post['search'] != null){
|
||||
$b = $post['search'];
|
||||
$s = "name like '%".$b."%'";
|
||||
if(isset($post['user_id'])){
|
||||
$hostory = TeaStoreHistory::where("content",$b)
|
||||
->where("user_id",$post['user_id'])
|
||||
->find();
|
||||
if($hostory == null){
|
||||
TeaStoreHistory::create([
|
||||
"user_id"=>$post['user_id'],
|
||||
"content"=>$b,
|
||||
"dtime"=>time()
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$op = '';
|
||||
if(isset($post['open'])){
|
||||
if($post['open'] == 1){
|
||||
$op = "operation_type = 1";
|
||||
}
|
||||
}
|
||||
if(isset($post['sales'])){
|
||||
if($post['sales'] == 1){
|
||||
$or = "sales desc";
|
||||
}
|
||||
}
|
||||
$c = "";
|
||||
if(isset($post['city'])){
|
||||
if($post['city'] != ""&&$post['city'] != null){
|
||||
$ct = $post['city'];
|
||||
$c = "city like '%".$ct."%'";;
|
||||
}
|
||||
}
|
||||
$use = "";
|
||||
|
||||
if(isset($post['use'])&&isset($post['user_id'])){
|
||||
if($post['use'] == 1){
|
||||
$store_order = OrderStore::where("user_id",$post['user_id'])->group('store_id')->select();
|
||||
$ids = [];
|
||||
foreach ($store_order as $item){
|
||||
$ids[] = $item['store_id'];
|
||||
}
|
||||
if(!empty($ids)){
|
||||
$ids_string = implode(',', $ids);
|
||||
$use = "id in ($ids_string)";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
$ca = "";
|
||||
if(isset($post['city_area_id'])){
|
||||
if($post['city_area_id'] != ""&&$post['city_area_id'] != null&&$post['city_area_id'] != 0){
|
||||
$ca = "city_area_id = ".$post['city_area_id']."";
|
||||
}
|
||||
}
|
||||
$distance = "'--'";
|
||||
|
||||
$distance = "ROUND(
|
||||
6378.138 * 2 * ASIN(
|
||||
SQRT(
|
||||
POW(
|
||||
SIN(
|
||||
(
|
||||
{$post['latitude']} * PI() / 180 - latitude * PI() / 180
|
||||
) / 2
|
||||
),
|
||||
2
|
||||
) + COS({$post['latitude']} * PI() / 180) * COS(latitude * PI() / 180) * POW(
|
||||
SIN(
|
||||
(
|
||||
{$post['longitude']} * PI() / 180 - longitude * PI() / 180
|
||||
) / 2
|
||||
),
|
||||
2
|
||||
)
|
||||
)
|
||||
) * 1000
|
||||
)";
|
||||
|
||||
|
||||
// $distanceField = "ROUND(6378.138 * 2 * ASIN(SQRT(
|
||||
// POW(SIN(({$post['latitude']} * PI() / 180 - latitude * PI() / 180) / 2), 2) +
|
||||
// COS({$post['latitude']} * PI() / 180) * COS(latitude * PI() / 180) *
|
||||
// POW(SIN(({$post['longitude']} * PI() / 180 - longitude * PI() / 180) / 2), 2)
|
||||
// )) * 1000, 2) AS distance";
|
||||
$count = TeaStore::where('del',0)
|
||||
->where("status",1)
|
||||
->where($s)
|
||||
->where($c)
|
||||
->where($ca)
|
||||
->where($op)
|
||||
->where($use)
|
||||
->count();
|
||||
$lists = TeaStore::where('del',0)
|
||||
->field("*,{$distance} as distance")
|
||||
->where("status",1)
|
||||
->where($s)
|
||||
->where($c)
|
||||
->where($op)
|
||||
->where($ca)
|
||||
->where($use)
|
||||
->page($post['page'], $post['size'])
|
||||
->order($or)
|
||||
->select();
|
||||
|
||||
$time = date('Y-m-d');
|
||||
$startDate = date('Y-m-d', strtotime($time . ' -6 months'));
|
||||
$startTime = $startDate . ' 00:00:00';
|
||||
$endTime = $time . ' 23:59:59';
|
||||
$todaystartTime =$time . ' 00:00:00';
|
||||
$todayendTime = $time . ' 23:59:59';
|
||||
foreach($lists as $key=>$value){
|
||||
if ($lists[$key]['distance'] >= 1000) {
|
||||
$n = $lists[$key]['distance'] > 10000 ? 0 : 1;
|
||||
$lists[$key]['distance'] = round( $lists[$key]['distance'] / 1000, $n) . 'km';
|
||||
} elseif ($lists[$key]['distance']!= '--') {
|
||||
$lists[$key]['distance'] .= 'm';
|
||||
}
|
||||
// 距离
|
||||
// $lists[$key]['distance'] = calculateDistanceKm($value['latitude'],$value['longitude'],$post['latitude'],$post['longitude']);
|
||||
$lists[$key]['half_year_nums'] = $value['sales'];
|
||||
if($lists[$key]['half_year_nums']<50){
|
||||
$lists[$key]['half_year_nums'] = 50;
|
||||
}
|
||||
$lists[$key]['today'] = Db::name('order_store')
|
||||
->where('store_id',$value['store_id'])
|
||||
->whereBetween('dtime', [$todaystartTime, $todayendTime])
|
||||
->count();
|
||||
$lists[$key]['image']=FileService::getImgUrl($value['image']);
|
||||
}
|
||||
|
||||
$data = [
|
||||
'list' => $lists,
|
||||
'page' => $post['page'],
|
||||
'size' => $post['size'],
|
||||
'count' => $count,
|
||||
'more' => is_more($count, $post['page'], $post['size'])
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getTeaStoreDetails($data){
|
||||
$result = TeaStore::where('id',$data['id'])
|
||||
->find();
|
||||
if(isset($data['room_id'])){
|
||||
$room = TeaStoreRoom::where('id',$data['room_id'])
|
||||
->find();
|
||||
|
||||
$arr = explode(",", $room['img_arr'] ?? ''); // 使用 ?? 防止 $lists['image'] 为 null
|
||||
|
||||
|
||||
$labelIds = explode(',',$room['label_id']??'');
|
||||
|
||||
$labelList = TeaStoreRoomLabel::where('status', 1)
|
||||
->where('type', 1)
|
||||
->whereIn('id', $labelIds)
|
||||
->select()
|
||||
->toArray();
|
||||
$room['label'] = $labelList;
|
||||
|
||||
$room_arr = [];
|
||||
foreach ($arr as $key => $v) {
|
||||
if (!empty(trim($v))) {
|
||||
$room_arr[$key] = FileService::getImgUrl($v);
|
||||
} else {
|
||||
$room_arr[$key] = '';
|
||||
}
|
||||
}
|
||||
$room['room_arr'] = $room_arr;
|
||||
|
||||
$result['room'] = $room;
|
||||
|
||||
}
|
||||
$result['collect'] = 0;
|
||||
if(isset($data['user_id'])){
|
||||
if($data['user_id'] != "" &&$data['user_id']!=0){
|
||||
$result['collect'] = TeaStore::teaStoreCollect($result['id'],$data['user_id']);
|
||||
$result['collect'] = $result['collect']?1:0;
|
||||
}
|
||||
}
|
||||
$result['distance'] = calculateDistanceKm($result['latitude'],$result['longitude'],$data['latitude'],$data['longitude']);
|
||||
$result['rechange_times'] = 5;
|
||||
$d['details'] = $result;
|
||||
$arr = explode(",",$result['image_arr']);
|
||||
$image_arr = [];
|
||||
foreach($arr as $key=>$value){
|
||||
$image_arr[$key] =FileService::getImgUrl($value);
|
||||
}
|
||||
$result['image_arr'] = $image_arr;
|
||||
return $d;
|
||||
}
|
||||
|
||||
|
||||
public static function getTeaStoreSearchHistory($userId){
|
||||
$lists = TeaStoreHistory::where("user_id",$userId)
|
||||
->where("status",1)
|
||||
->where("del",0)
|
||||
->order("id","desc")
|
||||
->select();
|
||||
$data = [
|
||||
'list' => $lists
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
public static function delTeaStoreSearchHistory($userId){
|
||||
return TeaStoreHistory::where("user_id",$userId)
|
||||
->where("status",1)
|
||||
->where("del",0)
|
||||
->update(['del'=>1]);
|
||||
}
|
||||
public static function getTeaStoreCity(){
|
||||
$lists = TeaStoreCity::where("status",1)
|
||||
->where("del",0)
|
||||
->select();
|
||||
$data = [
|
||||
'list' => $lists
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
public static function getTeaStoreRoomLists($post) {
|
||||
$storeId = $post['id'];
|
||||
$page = $post['page'] ?? 1;
|
||||
$size = $post['size'] ?? 10;
|
||||
|
||||
// 1. 基础查询
|
||||
$query = TeaStoreRoom::where('del', 0)
|
||||
->where("store_id", $storeId);
|
||||
|
||||
$count = $query->count();
|
||||
|
||||
// 2. 获取房间列表
|
||||
$lists = $query->page($page, $size)
|
||||
->order('weight asc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
if (empty($lists)) {
|
||||
return [
|
||||
'list' => [],
|
||||
'page' => $page,
|
||||
'size' => $size,
|
||||
'count' => 0,
|
||||
'more' => false
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
// 3. 批量获取标签数据
|
||||
$roomIds = array_column($lists, 'id');
|
||||
$labelIds = [];
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 4. 批量获取订单时间数据
|
||||
$orderTimes = OrderStore::whereIn('room_id', $roomIds)
|
||||
->where('is_transfer', 0)
|
||||
->where('end_time', '>', time() - 60 * 40)
|
||||
->whereIn('order_status', [0, 1, 2])
|
||||
->where('is_transfer',0)
|
||||
->field('room_id, timeslot')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
|
||||
// 按房间ID分组订单时间
|
||||
$roomOrderTimes = [];
|
||||
foreach ($orderTimes as $order) {
|
||||
$roomId = $order['room_id'];
|
||||
if (!isset($roomOrderTimes[$roomId])) {
|
||||
$roomOrderTimes[$roomId] = [];
|
||||
}
|
||||
$roomOrderTimes[$roomId][] = $order['timeslot'];
|
||||
}
|
||||
|
||||
// 5. 准备时间数据(每个房间都一样,可以复用)
|
||||
$todayStart = strtotime(date("Y-m-d 00:00:00"));
|
||||
$todayEnd = $todayStart + 86400; // 24小时
|
||||
$now = time();
|
||||
|
||||
|
||||
// 6. 处理房间数据
|
||||
foreach ($lists as &$room) {
|
||||
$roomId = $room['id'];
|
||||
|
||||
$labelIds = explode(',',$room['label_id']);
|
||||
|
||||
|
||||
$labelList = TeaStoreRoomLabel::where('status', 1)
|
||||
->where('type', 1)
|
||||
->whereIn('id', $labelIds)
|
||||
->select()
|
||||
->toArray();
|
||||
$room['label'] = $labelList;
|
||||
|
||||
|
||||
|
||||
// 处理时间表
|
||||
$roomTimes = [];
|
||||
$currentOrderTimes = $roomOrderTimes[$roomId] ?? [];
|
||||
// 如果$currentOrderTimes是二维数组,需要扁平化成一维数组
|
||||
$flattenedOrderTimes = [];
|
||||
if (!empty($currentOrderTimes)) {
|
||||
// 扁平化处理,同时处理逗号分隔的字符串
|
||||
array_walk_recursive($currentOrderTimes, function($value) use (&$flattenedOrderTimes) {
|
||||
if (is_string($value) && strpos($value, ',') !== false) {
|
||||
// 如果是逗号分隔的字符串,分割成数组
|
||||
$timeArray = explode(',', $value);
|
||||
foreach ($timeArray as $time) {
|
||||
$flattenedOrderTimes[] = (int)trim($time);
|
||||
}
|
||||
} else {
|
||||
$flattenedOrderTimes[] = (int)$value;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
for ($time = $todayStart; $time < $todayEnd; $time += 1800) { // 30分钟
|
||||
$item = [
|
||||
'key' => $time,
|
||||
'time' => date('H:i', $time),
|
||||
'local_time' => date('Y/m/d H:i', $time),
|
||||
'type' => '1',
|
||||
'disabled' => 0
|
||||
];
|
||||
|
||||
// 已过时间
|
||||
if ($time < $now) {
|
||||
$item['disabled'] = 1;
|
||||
$item['type'] = '2';
|
||||
}
|
||||
|
||||
// 已被预订
|
||||
if (in_array($time, $flattenedOrderTimes)) {
|
||||
$item['disabled'] = 2;
|
||||
$item['type'] = '3';
|
||||
}
|
||||
|
||||
$roomTimes[] = $item;
|
||||
}
|
||||
|
||||
$room['room_time'] = $roomTimes;
|
||||
$room['img'] = FileService::getImgUrl($room['img']);
|
||||
unset($room['label_id']); // 清理不需要的字段
|
||||
}
|
||||
|
||||
// 7. 返回结果
|
||||
return [
|
||||
'list' => $lists,
|
||||
'page' => (int)$page,
|
||||
'size' => (int)$size,
|
||||
'count' => $count,
|
||||
'more' => $count > $page * $size
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function rechargeLists($post){
|
||||
try {
|
||||
|
||||
$store = TeaStore::where([
|
||||
'id'=>$post['store_id'],
|
||||
'recharge_state'=>0,
|
||||
'del'=>0
|
||||
])->find();
|
||||
if($store){
|
||||
throw new \Exception('当前门店暂无充值活动');
|
||||
}
|
||||
$store_recharge = TeaStoreRecharge::where([
|
||||
'store_id'=>$post['store_id'],
|
||||
'del'=>0
|
||||
])->select()->toArray();
|
||||
|
||||
return $store_recharge;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static function teaStoreCollect($post){
|
||||
if($post['status'] == 1){
|
||||
$result = TeaStoreCollect::where([
|
||||
"tea_store_id"=>$post['id'],
|
||||
"user_id"=>$post['user_id'],
|
||||
"status"=>1
|
||||
])->find();
|
||||
if($result){
|
||||
return false;
|
||||
}
|
||||
return TeaStoreCollect::create([
|
||||
"tea_store_id"=>$post['id'],
|
||||
"user_id"=>$post['user_id'],
|
||||
"dtime"=>date("Y-m-d H:i:s")
|
||||
]);
|
||||
}else{
|
||||
$d['status'] = 0;
|
||||
$d['update_dtime'] = date("Y-m-d H:i:s");
|
||||
return TeaStoreCollect::where('tea_store_id',$post['id'])
|
||||
->where("user_id",$post['user_id'])
|
||||
->update($d);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static function teaStoreCollectList($post,$userId){
|
||||
$count = TeaStoreCollect::where('status',1)->where('user_id',$userId)
|
||||
->count();
|
||||
$lists = TeaStoreCollect::with(['teaStore'])
|
||||
->where('status',1)
|
||||
->where('user_id',$userId)
|
||||
->page($post['page'], $post['size'])
|
||||
->order('id asc')
|
||||
->select();
|
||||
foreach($lists as $key=>$value){
|
||||
$lists[$key]['count'] = TeaStoreCollect::where('status',1)->where('tea_store_id',$value['tea_store_id'])->count();
|
||||
}
|
||||
$data = [
|
||||
'list' => $lists,
|
||||
'page' => $post['page'],
|
||||
'size' => $post['size'],
|
||||
'count' => $count,
|
||||
'more' => is_more($count, $post['page'], $post['size'])
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
public static function getTeaStoreGroupLists($post){
|
||||
$count = TeaStoreGroup::where('del',0)
|
||||
->where('status',1)
|
||||
->where("store_id",$post['id'])
|
||||
->count();
|
||||
$lists = TeaStoreGroup::where('del',0)
|
||||
->where('status',1)
|
||||
->where("store_id",$post['id'])
|
||||
->page($post['page'], $post['size'])
|
||||
->order('id desc')
|
||||
->select();
|
||||
foreach($lists as $key=>$value){
|
||||
$img_arr = explode(",",$value['img']);
|
||||
$lists[$key]['img'] =FileService::getImgUrl($img_arr[0]);
|
||||
$lists[$key]['discount'] = round($value['discount'],2);
|
||||
|
||||
if($value['room_id'] == 0){
|
||||
$lists[$key]['room_name'] = "通用";
|
||||
}else{
|
||||
$room = TeaStoreRoom::where("id","in",$value['room_id'])->select();
|
||||
foreach($room as $j=>$item){
|
||||
if($j == 0){
|
||||
$lists[$key]['room_name'].= $item['title'];
|
||||
}else{
|
||||
$lists[$key]['room_name'].=",".$item['title'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$data = [
|
||||
'list' => $lists,
|
||||
'page' => $post['page'],
|
||||
'size' => $post['size'],
|
||||
'count' => $count,
|
||||
'more' => is_more($count, $post['page'], $post['size'])
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getTeaStoreGroupDetails($data){
|
||||
$result = TeaStoreGroup::where('id',$data['id'])
|
||||
->find();
|
||||
$result['room_title'] = "";
|
||||
if($result['room_id'] == 0){
|
||||
$result['room_name'] = "通用";
|
||||
}else{
|
||||
$room = TeaStoreRoom::where("id","in",$result['room_id'])->select();
|
||||
foreach($room as $key=>$value){
|
||||
if($key == 0){
|
||||
$result['room_name'].= $value['title'];
|
||||
}else{
|
||||
$result['room_name'].=",".$value['title'];
|
||||
}
|
||||
}
|
||||
}
|
||||
$img_arr = explode(",",$result['img']);
|
||||
foreach($img_arr as $key=>$value){
|
||||
$img_arr[$key] = FileService::getImgUrl($value);
|
||||
}
|
||||
$result['img'] = $img_arr;
|
||||
$d['details'] = $result;
|
||||
return $d;
|
||||
}
|
||||
|
||||
public static function qualDetails($data){
|
||||
$result = TeaStoreQual::where('store_id',$data['store_id'])
|
||||
->find();
|
||||
if($result != null){
|
||||
$result['license_img'] = FileService::getImgUrl($result['license_img']);
|
||||
if($result['effective']){
|
||||
$result['start_time'] = date("Y-m-d",$result['start_time']);
|
||||
$result['end_time'] = date("Y-m-d",$result['end_time']);
|
||||
}
|
||||
}
|
||||
|
||||
$d['details'] = $result;
|
||||
return $d;
|
||||
}
|
||||
}
|
||||
890
app/api/logic/TeamasterLogic.php
Normal file
890
app/api/logic/TeamasterLogic.php
Normal file
@ -0,0 +1,890 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\order\OrderTeamaster;
|
||||
use app\common\model\order\OrderTeamasterLeaf;
|
||||
use app\common\model\teamaster\TeamasterAddress;
|
||||
use app\common\model\teastore\TeaStore;
|
||||
use app\common\model\user\User;
|
||||
use app\common\service\FileService;
|
||||
use DateTime;
|
||||
use think\facade\{Db, Config};
|
||||
use app\common\model\teamaster\Teamaster;
|
||||
use app\common\model\teamaster\TeamasterUser;
|
||||
use app\common\model\teamaster\TeamasterLeaf;
|
||||
use app\common\model\user\UserCoupon;
|
||||
use app\common\model\user\UserCouponType;
|
||||
use app\common\model\order\OrderTeamasterRenew;
|
||||
use app\common\service\pay\WxRefundService;
|
||||
|
||||
|
||||
|
||||
class TeamasterLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* @notes 茶艺师等级
|
||||
* @param array $params
|
||||
* @return array
|
||||
* @author Yzt
|
||||
* @date 2025/01/02 17:01
|
||||
*/
|
||||
public static function getTeaLevel(){
|
||||
return TeamasterLevel::where("status",1)->select()->toarray();
|
||||
}
|
||||
/**
|
||||
* @notes 茶艺师列表
|
||||
* @param array $params
|
||||
* @return array
|
||||
* @author Yzt
|
||||
* @date 2025/12/29 22:01
|
||||
*/
|
||||
public static function getTeamasterList($post){
|
||||
// 茶艺师等级多筛选
|
||||
$l = "";
|
||||
if(isset($post['level'])){
|
||||
$l = "a.level in (1,2,3,4,5)";
|
||||
if(!empty($post['level'])){
|
||||
$l = "a.level in (".$post['level'].")";
|
||||
}
|
||||
}
|
||||
$s = "";
|
||||
if(isset($post['search'])){
|
||||
if($post['search'] != ""){
|
||||
$b = $post['search'];
|
||||
$s = "b.name like '%".$b."%'";
|
||||
}
|
||||
}
|
||||
|
||||
$ca = "";
|
||||
if(isset($post['city_id'])){
|
||||
if($post['city_id'] != ""&&$post['city_id'] != null&&$post['city_id'] != 0){
|
||||
$ca = "c.ity_id = ".$post['city_id']."";
|
||||
}
|
||||
}
|
||||
$distance = "'--'";
|
||||
|
||||
$distance = "ROUND(
|
||||
6378.138 * 2 * ASIN(
|
||||
SQRT(
|
||||
POW(
|
||||
SIN(
|
||||
(
|
||||
{$post['latitude']} * PI() / 180 - c.latitude * PI() / 180
|
||||
) / 2
|
||||
),
|
||||
2
|
||||
) + COS({$post['latitude']} * PI() / 180) * COS(c.latitude * PI() / 180) * POW(
|
||||
SIN(
|
||||
(
|
||||
{$post['longitude']} * PI() / 180 - c.longitude * PI() / 180
|
||||
) / 2
|
||||
),
|
||||
2
|
||||
)
|
||||
)
|
||||
) * 1000
|
||||
)";
|
||||
|
||||
|
||||
$count = TeamasterUser::alias("a")
|
||||
->join("teamaster b", "b.team_user_id = a.id", "left")
|
||||
->join("teamaster_address c","a.address_id = c.id","left")
|
||||
->where($l)
|
||||
->where($ca)
|
||||
->where('a.del',0)
|
||||
->where('a.disable',0)
|
||||
->where('a.address_id','<>',0)
|
||||
->where($s)
|
||||
->count();
|
||||
$lists = TeamasterUser::alias("a")
|
||||
->join("teamaster b", "b.team_user_id = a.id", "left")
|
||||
->join("teamaster_address c","a.address_id = c.id","left")
|
||||
->where($l)
|
||||
->where($ca)
|
||||
->where('a.del',0)
|
||||
->where('a.disable',0)
|
||||
->where('a.address_id','<>',0)
|
||||
->where($s)
|
||||
->field("a.id as team_user_id,a.server_type,b.sex,b.both,b.name,b.image,a.level,a.price,c.latitude,c.longitude,a.state,a.avatar,
|
||||
a.work_start,a.work_end,{$distance} as distance")
|
||||
->page($post['page'], $post['size'])
|
||||
->order('distance asc')
|
||||
->select();
|
||||
|
||||
foreach($lists as $key=>$value){
|
||||
|
||||
$lists[$key]['distance'] = round( $lists[$key]['distance'] / 1000, 1);
|
||||
if($lists[$key]['distance']<10){
|
||||
$lists[$key]['is_time'] = '最快30分钟到达';
|
||||
}elseif($lists[$key]['distance']>10&&$lists[$key]['distance']<20){
|
||||
$lists[$key]['is_time'] = '最快一小时内到达';
|
||||
}else{
|
||||
$lists[$key]['is_time'] = '距离过远';
|
||||
}
|
||||
// if (isset($value['avatar']) && strpos($value['avatar'], 'uploads') !== false) {
|
||||
// // 包含 "uploads"
|
||||
// $lists[$key]['image']= !empty($value['avatar']) ? FileService::getFileUrl($value['avatar']) : '';
|
||||
// } else {
|
||||
// // 不包含 "uploads"
|
||||
// $lists[$key]['image']= !empty($value['avatar']) ? FileService::getFileUrl("uploads".$value['avatar']) : '';
|
||||
// }
|
||||
$lists[$key]['image']= !empty($value['avatar']) ? FileService::getImgUrl($value['avatar']) : '';
|
||||
$lists[$key]['both'] = (new DateTime())->diff(new DateTime($value['both']))->y;
|
||||
}
|
||||
$data = [
|
||||
'list' => $lists,
|
||||
'page' => $post['page'],
|
||||
'size' => $post['size'],
|
||||
'count' => $count,
|
||||
'more' => is_more($count, $post['page'], $post['size'])
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 茶艺师详情
|
||||
* @param array $params
|
||||
* @return array
|
||||
* @author 胥聪
|
||||
* @date 2025/10/14 17:01
|
||||
*/
|
||||
public static function getTeamasterDetails($post){
|
||||
$distance = "'--'";
|
||||
|
||||
$distance = "ROUND(
|
||||
6378.138 * 2 * ASIN(
|
||||
SQRT(
|
||||
POW(
|
||||
SIN(
|
||||
(
|
||||
{$post['latitude']} * PI() / 180 - c.latitude * PI() / 180
|
||||
) / 2
|
||||
),
|
||||
2
|
||||
) + COS({$post['latitude']} * PI() / 180) * COS(c.latitude * PI() / 180) * POW(
|
||||
SIN(
|
||||
(
|
||||
{$post['longitude']} * PI() / 180 - c.longitude * PI() / 180
|
||||
) / 2
|
||||
),
|
||||
2
|
||||
)
|
||||
)
|
||||
) * 1000
|
||||
)";
|
||||
|
||||
$lists = TeamasterUser::alias("a")
|
||||
->join("teamaster b", "b.team_user_id = a.id", "left")
|
||||
->join("teamaster_address c","a.address_id = c.id","left")
|
||||
->where('a.address_id','<>',0)
|
||||
->where('a.del',0)
|
||||
->where('a.id',$post['team_user_id'])
|
||||
->field("a.id as team_user_id,a.server_type,b.sex,b.both,b.name,b.image,a.level,a.price,a.mileage_price,b.weight,
|
||||
c.latitude,c.longitude,b.sex,a.is_mileage,a.star,b.height,hobby_introduce,a.sold,a.state,
|
||||
{$distance} as distance")
|
||||
->order('distance asc')
|
||||
->find();
|
||||
$lists['age_range'] = substr($lists['both'], 2, 1).'0';
|
||||
$lists['both'] = (new DateTime())->diff(new DateTime($lists['both']))->y;
|
||||
|
||||
$lists['distance'] = round( $lists['distance'] / 1000);
|
||||
|
||||
if($lists['distance']<10){
|
||||
$lists['is_time'] = '最快30分钟到达';
|
||||
}elseif($lists['distance']>10&&$lists['distance']<20){
|
||||
$lists['is_time'] = '最快一小时内到达';
|
||||
}else{
|
||||
$lists['is_time'] = '距离过远';
|
||||
}
|
||||
|
||||
$arr = explode(",", $lists['image'] ?? ''); // 使用 ?? 防止 $lists['image'] 为 null
|
||||
|
||||
$image_arr = [];
|
||||
foreach ($arr as $key => $value) {
|
||||
if (!empty(trim($value))) {
|
||||
// if (isset($value) && strpos($value, 'uploads') !== false) {
|
||||
// // 包含 "uploads"
|
||||
// $image_arr[$key]= !empty($value) ? FileService::getFileUrl($value) : '';
|
||||
// } else {
|
||||
// // 不包含 "uploads"
|
||||
// $image_arr[$key]= !empty($value) ? FileService::getFileUrl("uploads".$value) : '';
|
||||
// }
|
||||
$image_arr[$key] = FileService::getImgUrl($value);
|
||||
} else {
|
||||
$image_arr[$key] = '';
|
||||
}
|
||||
}
|
||||
$lists['image_arr'] = $image_arr;
|
||||
$lists['image'] = FileService::getImgUrl($arr[0]);
|
||||
|
||||
return $lists;
|
||||
}
|
||||
|
||||
public static function LeafList(){
|
||||
$left = TeamasterLeaf::where('del',0)->select();
|
||||
return $left->toArray();
|
||||
}
|
||||
|
||||
public static function addTeamOrder($post){
|
||||
Db::startTrans();
|
||||
try {
|
||||
$team_user = TeamasterUser::where([
|
||||
'id'=>$post['team_user_id'],
|
||||
'del'=>0
|
||||
])->find();
|
||||
if(!$team_user){
|
||||
throw new \Exception('茶艺师不存在');
|
||||
}
|
||||
if($post['hours']<2){
|
||||
throw new \Exception('最低2小时起订');
|
||||
}
|
||||
$currentTime = time();
|
||||
$oneHourLater = $currentTime + 1740;
|
||||
if ($post['start_time'] < $oneHourLater) {
|
||||
throw new \Exception('需要至少提前一小时预定');
|
||||
}
|
||||
if (!isset($post['tea_id']) || $post['tea_id'] === '') {
|
||||
throw new \Exception('须选择一种茶叶');
|
||||
}
|
||||
$tea_ids = explode(',',$post['tea_id']);
|
||||
|
||||
$tea_leaf = TeamasterLeaf::whereIn('id',$tea_ids)->select();
|
||||
$leaf_amount =0;
|
||||
$teacup_price = 0;
|
||||
$server_all_price = $team_user['price']*$post['hours'];
|
||||
$mileage_server_price = 0;
|
||||
$coupon_price = 0;
|
||||
$tea_arr = [];
|
||||
foreach ($tea_leaf as $key=>$value){
|
||||
$leaf_amount += $value['price'] ?? 0;
|
||||
$tea_arr[$key]['leaf_id'] = $value['id'];
|
||||
$tea_arr[$key]['leaf_name']=$value['name'];
|
||||
}
|
||||
if($post['is_teacup'] == 1){
|
||||
$teacup_price = 20;
|
||||
}
|
||||
|
||||
$distance = "'--'";
|
||||
|
||||
$distance = "ROUND(
|
||||
6378.138 * 2 * ASIN(
|
||||
SQRT(
|
||||
POW(
|
||||
SIN(
|
||||
(
|
||||
{$post['latitude']} * PI() / 180 - latitude * PI() / 180
|
||||
) / 2
|
||||
),
|
||||
2
|
||||
) + COS({$post['latitude']} * PI() / 180) * COS(latitude * PI() / 180) * POW(
|
||||
SIN(
|
||||
(
|
||||
{$post['longitude']} * PI() / 180 - longitude * PI() / 180
|
||||
) / 2
|
||||
),
|
||||
2
|
||||
)
|
||||
)
|
||||
) * 1000
|
||||
)";
|
||||
$team_user_address = TeamasterAddress::where('id',$team_user['address_id'])
|
||||
->field("id, address, latitude, longitude,{$distance} as distance")
|
||||
->find();
|
||||
|
||||
$team_user_address['distance'] = round( $team_user_address['distance'] / 1000);
|
||||
|
||||
|
||||
if($team_user->is_mileage == 0){
|
||||
$mileage_server_price = $team_user_address['distance']*$team_user['mileage_price'];
|
||||
}
|
||||
$amount_all = $teacup_price+$server_all_price+$leaf_amount+$mileage_server_price;
|
||||
if($post['user_coupon_id'] !=0){
|
||||
$user_coupon = UserCoupon::where([
|
||||
'id'=>$post['user_coupon_id'],
|
||||
'status'=>0,
|
||||
'type_id'=>1
|
||||
])->find();
|
||||
if(!$user_coupon){
|
||||
throw new \Exception('优惠券不可用或已使用');
|
||||
}
|
||||
$coupon_type =UserCouponType::where([
|
||||
'id'=>$user_coupon['coupon_id'],
|
||||
'status'=>0
|
||||
])->find();
|
||||
if(!$coupon_type){
|
||||
throw new \Exception('优惠券不可用');
|
||||
}
|
||||
if($amount_all>=$coupon_type['use_price']){
|
||||
$coupon_price = $coupon_type['coupon_price'];
|
||||
}
|
||||
}
|
||||
|
||||
$order_amount = $amount_all-$coupon_price;
|
||||
$data = [
|
||||
'order_sn'=>createSn("order_teamaster","order_sn"),
|
||||
'user_id'=>$post['user_id'],
|
||||
'team_user_id'=>$post['team_user_id'],
|
||||
'store_id'=>$post['store_id'],
|
||||
'day_time'=>$post['start_time'],
|
||||
'start_time'=>$post['start_time'],
|
||||
'distance'=>$team_user_address['distance'],
|
||||
'end_time'=>$post['end_time'],
|
||||
'hours'=>$post['hours'],
|
||||
'server_number'=>$post['server_number'],
|
||||
'server_type'=>$post['server_type'],
|
||||
'address'=>$post['address'],
|
||||
'longitude'=>$post['longitude'],
|
||||
'latitude'=>$post['latitude'],
|
||||
'is_teacup'=>$post['is_teacup'],
|
||||
'server_price'=>$team_user['price'],
|
||||
'mileage_price'=>$team_user['mileage_price'],
|
||||
'server_all_price'=>$server_all_price,
|
||||
'mileage_server_price'=>$mileage_server_price,
|
||||
'user_coupon_id'=>$post['user_coupon_id'],
|
||||
'tea_price'=>$leaf_amount,
|
||||
'teacup_price'=>$teacup_price,
|
||||
'coupon_price'=>$coupon_price,
|
||||
'order_amount'=>round($order_amount,2),
|
||||
'team_income_price'=>round(((($order_amount-$mileage_server_price)+$coupon_price)*0.65)+$mileage_server_price,2),
|
||||
'dtime'=>time()
|
||||
];
|
||||
|
||||
$order = OrderTeamaster::create($data);
|
||||
$orderId =$order->id;
|
||||
foreach ($tea_arr as &$item){
|
||||
$item['order_id'] = $orderId;
|
||||
}
|
||||
|
||||
$result = OrderTeamasterLeaf::insertAll($tea_arr);
|
||||
Db::commit();
|
||||
$data = [
|
||||
'order_id'=>$orderId,
|
||||
'order_amount'=>$order_amount
|
||||
];
|
||||
return $data;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function countTeamPrice($post){
|
||||
Db::startTrans();
|
||||
try {
|
||||
$team_user = TeamasterUser::where([
|
||||
'id'=>$post['team_user_id'],
|
||||
'del'=>0
|
||||
])->find();
|
||||
$hours = $post['hours'];
|
||||
$tea_id = $post['tea_id'];
|
||||
$server_price = $team_user->price;
|
||||
$server_all_price = $team_user['price']*$post['hours'];
|
||||
$mileage_price = 0;
|
||||
$team_user_distance = 0;
|
||||
$mileage_server_price = 0;
|
||||
$leaf_amount =0;
|
||||
$teacup_price = 0;
|
||||
$leaf_tea_all_price = 0;
|
||||
$coupon_price = 0;
|
||||
|
||||
if($tea_id !==0){
|
||||
$tea_ids = explode(',',$tea_id);
|
||||
$tea_leaf = TeamasterLeaf::whereIn('id',$tea_ids)->select();
|
||||
|
||||
$tea_arr = [];
|
||||
foreach ($tea_leaf as $key=>$value){
|
||||
$leaf_amount += $value['price'] ?? 0;
|
||||
$tea_arr[$key]['leaf_id'] = $value['id'];
|
||||
$tea_arr[$key]['leaf_name']=$value['name'];
|
||||
}
|
||||
}
|
||||
|
||||
if($post['is_teacup'] == 1){
|
||||
$teacup_price = 20;
|
||||
}
|
||||
|
||||
$distance = "'--'";
|
||||
|
||||
$distance = "ROUND(
|
||||
6378.138 * 2 * ASIN(
|
||||
SQRT(
|
||||
POW(
|
||||
SIN(
|
||||
(
|
||||
{$post['latitude']} * PI() / 180 - latitude * PI() / 180
|
||||
) / 2
|
||||
),
|
||||
2
|
||||
) + COS({$post['latitude']} * PI() / 180) * COS(latitude * PI() / 180) * POW(
|
||||
SIN(
|
||||
(
|
||||
{$post['longitude']} * PI() / 180 - longitude * PI() / 180
|
||||
) / 2
|
||||
),
|
||||
2
|
||||
)
|
||||
)
|
||||
) * 1000
|
||||
)";
|
||||
$team_user_address = TeamasterAddress::where('id',$team_user['address_id'])
|
||||
->field("id, address, latitude, longitude,{$distance} as distance")
|
||||
->find();
|
||||
|
||||
$team_user_address['distance'] = round( $team_user_address['distance'] / 1000);
|
||||
|
||||
$team_user_distance =$team_user_address['distance'];
|
||||
if($team_user->is_mileage == 0){
|
||||
$mileage_server_price = $team_user_address['distance']*$team_user['mileage_price'];
|
||||
|
||||
$mileage_price = $team_user['mileage_price'];
|
||||
}
|
||||
$amount_all = $teacup_price+$server_all_price+$leaf_amount+$mileage_server_price;
|
||||
if($post['user_coupon_id'] !=0){
|
||||
$user_coupon = UserCoupon::where([
|
||||
'id'=>$post['user_coupon_id'],
|
||||
])->find();
|
||||
$coupon_type =UserCouponType::where([
|
||||
'id'=>$user_coupon['coupon_id'],
|
||||
])->find();
|
||||
|
||||
if($amount_all>=$coupon_type['use_price']){
|
||||
$coupon_price = $coupon_type['coupon_price'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$order_amount = $amount_all-$coupon_price;
|
||||
$leaf_tea_all_price = $teacup_price+$leaf_amount;
|
||||
$data = [
|
||||
'order_amount'=>round($order_amount,2),
|
||||
'server_price'=>$server_price,
|
||||
'server_all_price'=>round($server_all_price,2),
|
||||
'mileage_price'=>round($mileage_price,2),
|
||||
'team_user_distance'=>$team_user_distance,
|
||||
'mileage_server_price'=>$mileage_server_price,
|
||||
'leaf_tea_all_price'=>$leaf_tea_all_price,
|
||||
'teacup_price'=>$teacup_price,
|
||||
'leaf_amount'=>$leaf_amount,
|
||||
'coupon_price'=>$coupon_price
|
||||
];
|
||||
|
||||
Db::commit();
|
||||
return $data;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function userCoupon($data){
|
||||
$user_coupon = UserCoupon::alias("a")
|
||||
->join("user_coupon_type b", "a.coupon_id = b.id", "left")
|
||||
->where('a.status',0)
|
||||
->where('a.type_id',1)
|
||||
->where('b.status',0)
|
||||
->where('a.user_id',$data['user_id'])
|
||||
->field("a.id,b.title,b.name,b.use_price,b.coupon_price,b.effect_time,b.status")
|
||||
->select()->toarray();
|
||||
return $user_coupon;
|
||||
}
|
||||
|
||||
public static function teamOrderList($post){
|
||||
$user_id =$post['user_id'];
|
||||
$os = [10,20,28,29,30,31,32,40,41,42,43];
|
||||
$od = "a.start_time desc";
|
||||
if(isset($post['order_status'])){
|
||||
if($post['order_status']!= "" || $post['order_status']!= null){
|
||||
|
||||
$os = explode(",",$post['order_status']);
|
||||
$od = "a.start_time asc";
|
||||
}
|
||||
}
|
||||
$s = "";
|
||||
if(isset($post['search'])){
|
||||
if($post['search']!= "" || $post['search']!= null){
|
||||
$a = $post['search'];
|
||||
$s = "c.name like '%".$a."%'";
|
||||
}
|
||||
}
|
||||
|
||||
$count = OrderTeamaster::alias("a")
|
||||
->join("teamaster_user b", "b.id = a.team_user_id", "left")
|
||||
->join("teamaster c", "c.team_user_id = a.team_user_id", "left")
|
||||
->where('a.del',0)
|
||||
->whereIn('a.order_status',$os)
|
||||
->where($s)
|
||||
->where('a.user_id',$user_id)
|
||||
->count();
|
||||
|
||||
$lists = OrderTeamaster::alias("a")
|
||||
->join("teamaster_user b", "b.id = a.team_user_id", "left")
|
||||
->join("teamaster c", "c.team_user_id = a.team_user_id", "left")
|
||||
->where('a.del',0)
|
||||
->whereIn('a.order_status',$os)
|
||||
->where($s)
|
||||
->where('a.user_id',$user_id)
|
||||
->field('a.id,c.name,b.level,a.server_type,c.sex,a.start_time,a.end_time,a.day_time,c.both,c.image,a.order_status,b.avatar')
|
||||
->page($post['page'], $post['size'])
|
||||
->order($od)
|
||||
->select();
|
||||
$timekeeping = 0;
|
||||
if($lists){
|
||||
foreach ($lists as &$item){
|
||||
if($item['order_status'] == 28){
|
||||
$timekeeping = $item['pay_time']-time();
|
||||
}
|
||||
$item['timekeeping'] =$timekeeping;
|
||||
$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']);
|
||||
$arr = explode(",",$item['image']);
|
||||
$item['image'] = !empty($item['avatar']) ? FileService::getImgUrl($item['avatar']) : '';
|
||||
$item['both'] = (new DateTime())->diff(new DateTime($item['both']))->y;
|
||||
|
||||
}
|
||||
$data = [
|
||||
'list' => $lists,
|
||||
'page' => $post['page'],
|
||||
'size' => $post['size'],
|
||||
'count' => $count,
|
||||
'more' => is_more($count, $post['page'], $post['size'])
|
||||
];
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static function teamOrderDetails($post){
|
||||
Db::startTrans();
|
||||
try {
|
||||
$item = OrderTeamaster::where('del',0)
|
||||
->where('id',$post['id'])
|
||||
->find();
|
||||
|
||||
$team = Teamaster::where('team_user_id',$item['team_user_id'])->find();
|
||||
$team_user = TeamasterUser::where('id',$team['team_user_id'])->find();
|
||||
|
||||
$timekeeping = 0;
|
||||
if($item['order_status'] == 28){
|
||||
$timekeeping = $item['pay_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'].')泡';
|
||||
}
|
||||
|
||||
$item['timekeeping'] =$timekeeping;
|
||||
$item['tea_amount_all'] = $item['tea_price']+$item['teacup_price']+$item['renew_tea_price']+$item['renew_tea_price'];
|
||||
$item['order_amount'] = $item['order_amount']+$item['renew_tea_price']+$item['renew_tea_price'];
|
||||
$item['leaf_name'] = implode(',',$leaf_name);
|
||||
$item['title'] = $team->name;
|
||||
$item['team_mobile'] = $team_user->mobile;
|
||||
$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']);
|
||||
$arr = explode(",",$team['image']);
|
||||
$item['image'] = !empty($team_user['avatar']) ? FileService::getImgUrl($team_user['avatar']) : '';
|
||||
$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 addTeamRenwOrder($post){
|
||||
Db::startTrans();
|
||||
try {
|
||||
$order = OrderTeamaster::where('id',$post['id'])->find();
|
||||
if(!$order){
|
||||
throw new \Exception('订单错误');
|
||||
}
|
||||
$hours = $post['hours'];
|
||||
$leaf_amount = 0;
|
||||
$tea_price =0;
|
||||
$renew_price = 0;
|
||||
$price = 0;
|
||||
$tea_arr = [];
|
||||
$tea_ids = explode(',',$post['tea_id']);
|
||||
$tea_leaf = TeamasterLeaf::whereIn('id',$tea_ids)->select();
|
||||
|
||||
if ($tea_leaf && !$tea_leaf->isEmpty()) {
|
||||
foreach ($tea_leaf as $value) {
|
||||
$leaf_amount += $value['price'] ?? 0;
|
||||
$tea_arr[] = [
|
||||
'leaf_id' => $value['id'],
|
||||
'leaf_name' => $value['name']
|
||||
];
|
||||
}
|
||||
}
|
||||
if($post['type'] == 1){
|
||||
$renew_price = $order->server_price*$hours;
|
||||
}elseif ($post['type']==2){
|
||||
$tea_price = $leaf_amount;
|
||||
foreach ($tea_arr as &$item){
|
||||
$item['order_id'] = $order->id;
|
||||
}
|
||||
$result = OrderTeamasterLeaf::insertAll($tea_arr);
|
||||
|
||||
}else{
|
||||
$renew_price = $order->server_price*$hours;
|
||||
$tea_price = $leaf_amount;
|
||||
foreach ($tea_arr as &$item){
|
||||
$item['order_id'] = $order->id;
|
||||
}
|
||||
$result = OrderTeamasterLeaf::insertAll($tea_arr);
|
||||
}
|
||||
$price = $tea_price+$renew_price;
|
||||
|
||||
$data = [
|
||||
'order_sn'=>createSn("order_teamaster_renew","order_sn"),
|
||||
'source_id'=>$order->id,
|
||||
'type'=>$post['type'],
|
||||
'user_id'=>$post['user_id'],
|
||||
'hours'=>$hours,
|
||||
'tea_price'=>$tea_price,
|
||||
'renew_price'=>$renew_price,
|
||||
'price'=>$price,
|
||||
'dtime'=>time()
|
||||
];
|
||||
$order_renew =OrderTeamasterRenew::create($data);
|
||||
|
||||
Db::commit();
|
||||
return [
|
||||
'order_id'=>$order_renew->id,
|
||||
'price'=>$price
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function cancelOrder($post){
|
||||
Db::startTrans();
|
||||
try {
|
||||
$order = OrderTeamaster::where([
|
||||
'id'=>$post['id'],
|
||||
'order_status'=>10
|
||||
])->find();
|
||||
if(!$order){
|
||||
throw new \Exception('订单错误');
|
||||
}
|
||||
$order->order_status = 20;
|
||||
$order->update_time = time();
|
||||
$order->save();
|
||||
Db::commit();
|
||||
return [];
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static function delOrder($post){
|
||||
Db::startTrans();
|
||||
try {
|
||||
$order = OrderTeamaster::where([
|
||||
'id'=>$post['id'],
|
||||
])->whereIn('order_status',[20,32,40,41,42])->find();
|
||||
if(!$order){
|
||||
throw new \Exception('订单错误');
|
||||
}
|
||||
$order->del = 1;
|
||||
$order->update_time = time();
|
||||
$order->save();
|
||||
Db::commit();
|
||||
return [];
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static function TeamRefund($post){
|
||||
Db::startTrans();
|
||||
try {
|
||||
$order = OrderTeamaster::where([
|
||||
'id'=>$post['id'],
|
||||
])->whereIn('order_status',[28,29,30])->find();
|
||||
if(!$order){
|
||||
throw new \Exception('订单错误');
|
||||
}
|
||||
$WxRefundService = new WxRefundService();
|
||||
$result =$WxRefundService->Refund($order,$post['order_type'],41);
|
||||
|
||||
Db::commit();
|
||||
return [];
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @notes 茶艺师收藏/取消
|
||||
* @author 胥聪
|
||||
* @date 2025/10/14 17:01
|
||||
*/
|
||||
public static function teamasterCollect($post){
|
||||
if($post['status'] == 1){
|
||||
$result = TeamasterCollect::where([
|
||||
"teamaster_id"=>$post['id'],
|
||||
"user_id"=>$post['user_id'],
|
||||
"status"=>1
|
||||
])->find();
|
||||
if($result){
|
||||
return false;
|
||||
}
|
||||
return TeamasterCollect::create([
|
||||
"teamaster_id"=>$post['id'],
|
||||
"user_id"=>$post['user_id'],
|
||||
"dtime"=>date("Y-m-d H:i:s")
|
||||
]);
|
||||
}else{
|
||||
$d['status'] = 0;
|
||||
$d['update_dtime'] = date("Y-m-d H:i:s");
|
||||
return TeamasterCollect::where('teamaster_id',$post['id'])
|
||||
->where("user_id",$post['user_id'])
|
||||
->update($d);
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* @notes 茶艺师收藏列表
|
||||
* @author 胥聪
|
||||
* @date 2025/10/14 17:01
|
||||
*/
|
||||
public static function teamasterCollectList($post,$userId){
|
||||
$count = TeamasterCollect::where('status',1)->where('user_id',$userId)
|
||||
->count();
|
||||
$lists = Teamaster::where('del',0)
|
||||
->alias("a")
|
||||
->field('a.id,a.authent_status,a.level_id,a.label_id,a.sex,a.both,a.name,a.image,a.price,a.star,a.status,a.dtime,a.update_dtime,a.up_status,a.longitude,a.latitude,a.del')
|
||||
->join("teamaster_collect b","a.id=b.teamaster_id","left")
|
||||
->with(['teamasterLevel'])
|
||||
->where('b.status',1)
|
||||
->where('b.user_id',$userId)
|
||||
->page($post['page'], $post['size'])
|
||||
->order('id asc')
|
||||
->select();
|
||||
foreach($lists as $key=>$value){
|
||||
$lists[$key]['count'] = TeamasterCollect::where('status',1)->where('teamaster_id',$value['id'])->count();
|
||||
$a = array_filter(explode(",",$value['label_id']));
|
||||
// 标签
|
||||
$lists[$key]['teamasterlabel'] = TeamasterLabel::wherein("id",$a)->select()->toArray();
|
||||
$lists[$key]['both'] = (new DateTime())->diff(new DateTime($value['both']))->y;
|
||||
}
|
||||
$data = [
|
||||
'list' => $lists,
|
||||
'page' => $post['page'],
|
||||
'size' => $post['size'],
|
||||
'count' => $count,
|
||||
'more' => is_more($count, $post['page'], $post['size'])
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 打赏金额查询
|
||||
* @param array $params
|
||||
* @return array
|
||||
* @author 胥聪
|
||||
* @date 2025/10/20 17:01
|
||||
*/
|
||||
public static function getTipAmount(){
|
||||
return TeamasterTipAmount::where('status',1)
|
||||
->select()
|
||||
->toArray();
|
||||
}
|
||||
/**
|
||||
* @notes 打赏
|
||||
* @author 胥聪
|
||||
* @date 2025/10/20 17:01
|
||||
* @data teamaster_id tip_price pay_type
|
||||
*/
|
||||
public static function giveTeamasterTipAmount($data,$user_id){
|
||||
$user_money = User::where("id",$user_id)->value("user_money");
|
||||
if($user_money < $data['tip_price']){
|
||||
throw new \Exception('余额账户不足');
|
||||
}
|
||||
return TeamasterTipAmountLog::create([
|
||||
"user_id"=>$user_id,
|
||||
"teamaster_id"=>$data['id'],
|
||||
"tip_price"=>$data['tip_price'],
|
||||
"pay_type"=>$data['pay_type'],
|
||||
"dtime"=>date("Y-m-d H:i:s")
|
||||
]);
|
||||
}
|
||||
public static function teaType(){
|
||||
return Tea::where("status",1)->select()->toArray();
|
||||
}
|
||||
|
||||
public static function invitation($post,$user_id){
|
||||
return TeamasterInvitation::create([
|
||||
'user_id'=>$user_id,
|
||||
'teamaster_id'=>$post['id'],
|
||||
'dtime'=>date("Y-m-d H:i:s")
|
||||
]);
|
||||
}
|
||||
public static function groupReservation($post,$user_id){
|
||||
return TeamasterGroupReservation::create([
|
||||
'user_id'=>$user_id,
|
||||
'numbers'=>$post['numbers'],
|
||||
'other_require'=>$post['other_require'],
|
||||
'res_time'=>$post['res_time'],
|
||||
'contact'=>$post['contact'],
|
||||
'phone'=>$post['phone'],
|
||||
'province'=>$post['province'],
|
||||
'city'=>$post['city'],
|
||||
'district'=>$post['district'],
|
||||
'address'=>$post['address'],
|
||||
'content'=>$post['content'],
|
||||
'dtime'=>date("Y-m-d H:i:s")
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
239
app/api/logic/UserCouponLogic.php
Normal file
239
app/api/logic/UserCouponLogic.php
Normal file
@ -0,0 +1,239 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\teamaster\Teamaster;
|
||||
use app\common\model\teastore\TeaStoreRoom;
|
||||
use app\common\service\ConfigService;
|
||||
use think\facade\{Db, Config};
|
||||
use app\common\model\user\{UserCoupon, UserCouponType};
|
||||
class UserCouponLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* @notes 用户优惠券列表
|
||||
* @param array $params
|
||||
* @return array
|
||||
* @author 胥聪
|
||||
* @date 2025/10/21 13:50
|
||||
*/
|
||||
public static function getUserCoupinList($data,$user_id){
|
||||
$type_id = $data['type_id'];
|
||||
$os = "a.type_id =".$type_id;
|
||||
if($type_id == 3){
|
||||
$os = '';
|
||||
}
|
||||
$result = UserCoupon::alias("a")
|
||||
->join("user_coupon_type b", "b.id = a.coupon_id", "left")
|
||||
->where("a.status",0)
|
||||
->where("a.user_id",$user_id)
|
||||
->field("a.id,b.title,b.name,b.use_price,b.coupon_price,b.effect_time,a.status")
|
||||
->where($os)
|
||||
->select()
|
||||
->toarray();
|
||||
$no_use = 0;
|
||||
$no_use2 = 0;
|
||||
$all_use = 0;
|
||||
if($result){
|
||||
foreach ($result as &$item){
|
||||
$item['is_use'] = 0; //等于0可用
|
||||
$all_use++;
|
||||
if($type_id == 1 ||$type_id == 2){
|
||||
if($item['use_price']>$data['price']){
|
||||
$item['is_use'] = 1;
|
||||
$no_use++;
|
||||
}
|
||||
}
|
||||
if($item['status'] == 1){
|
||||
$item['is_use'] = 1;
|
||||
$no_use2++;
|
||||
}
|
||||
}
|
||||
}
|
||||
$no_use = $no_use+$no_use2;
|
||||
|
||||
$count= [
|
||||
'all_use'=>$all_use,
|
||||
'no_use' => $no_use,
|
||||
'yes_use'=>$all_use-$no_use
|
||||
];
|
||||
$data = [
|
||||
'count'=>$count,
|
||||
'result'=>$result
|
||||
];
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
public static function isCoupin($user_id){
|
||||
$status = 0;
|
||||
$user_coupon = UserCoupon::where([
|
||||
'user_id'=>$user_id,
|
||||
'coupon_id'=>1
|
||||
])->find();
|
||||
if($user_coupon){
|
||||
$status =1;
|
||||
}
|
||||
$data = [
|
||||
'status'=>$status
|
||||
];
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static function receiveCoupon($post,$userId){
|
||||
try {
|
||||
$result = UserCouponType::where("id",$post['id'])->find();
|
||||
|
||||
$user_coupon = UserCoupon::where([
|
||||
'user_id'=>$userId,
|
||||
])->find();
|
||||
|
||||
if($post['id'] == 1 &&$user_coupon){
|
||||
throw new \Exception('此优惠券已领取');
|
||||
}elseif ($post['id'] == 3||$post['id'] == 4){
|
||||
$coup_count = UserCoupon::where('user_id',$userId)->whereIn('coupon_id',[3,4])->select();
|
||||
$count_3 = 0;
|
||||
$count_4 = 0;
|
||||
foreach ($coup_count as $item){
|
||||
if($item['coupon_id'] ==3){
|
||||
$count_3++;
|
||||
}elseif ($item['coupon_id']==4){
|
||||
$count_4++;
|
||||
}
|
||||
|
||||
}
|
||||
if ($post['id'] == 3&&$count_3 >= 10) {
|
||||
throw new \Exception('优惠券只能领取10张');
|
||||
}
|
||||
|
||||
if ($post['id'] == 4&&$count_4 >= 10) {
|
||||
throw new \Exception('优惠券只能领取10张');
|
||||
}
|
||||
|
||||
}
|
||||
return UserCoupon::create([
|
||||
'user_id'=>$userId,
|
||||
'coupon_id'=>$post['id'],
|
||||
'type_id'=>$result['type_id'],
|
||||
'dtime'=>date("Y-m-d H:i:s")
|
||||
]);
|
||||
return [];
|
||||
} catch (\Exception $e) {
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function shouyeCoupon($userId){
|
||||
try {
|
||||
$result = UserCouponType::where("id",1)->find();
|
||||
|
||||
$user_coupon = UserCoupon::where([
|
||||
'user_id'=>$userId,
|
||||
'coupon_id'=>1
|
||||
])->find();
|
||||
|
||||
if($user_coupon){
|
||||
throw new \Exception('此优惠券已领取');
|
||||
}
|
||||
return UserCoupon::create([
|
||||
'user_id'=>$userId,
|
||||
'coupon_id'=>1,
|
||||
'type_id'=>1,
|
||||
'dtime'=>date("Y-m-d H:i:s")
|
||||
]);
|
||||
return [];
|
||||
} catch (\Exception $e) {
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function getOrderCoupinList($data,$user_id){
|
||||
$expire_time = ConfigService::get("gzh_setting","user_coupon_expire_time");
|
||||
$threeDays = $expire_time * 24 * 60 * 60; // 转换时间戳
|
||||
$expireDate = date('Y-m-d', time() + ($expire_time * 24 * 60 * 60));
|
||||
// 状态为3的为快过期的 数据表中不做记录 只有筛选
|
||||
$s = "status = 0";
|
||||
$t = "";
|
||||
if(isset($data['status'])){
|
||||
if($data['status']!=0 || $data['status']!="" || $data['status'] != null){
|
||||
$s = "status = ".$data['status']."";
|
||||
}elseif($data['status'] == 3){
|
||||
$t = "dtime <= '".$expireDate."'";
|
||||
}
|
||||
}
|
||||
|
||||
// 获取过期时间
|
||||
$result = UserCoupon::with(['userCouponType'])
|
||||
->where("user_id",$user_id)
|
||||
->where("type_id",$data['type_id'])
|
||||
->where($s)
|
||||
->where($t)
|
||||
->select()
|
||||
->toarray();
|
||||
// 茶艺师价格
|
||||
// $teamaster_price = Teamaster::where("id",$data['id'])->value("price");
|
||||
// $all_price = $teamaster_price;
|
||||
foreach($result as $key=>$value){
|
||||
// // 可用不可用
|
||||
// if($all_price >= $value['userCouponType'][0]['use_price']){
|
||||
// $result[$key]['use'] = 1;
|
||||
// }else{
|
||||
// $result[$key]['no_use'] = 2;
|
||||
// }
|
||||
// 即将过期
|
||||
$targetTimestamp = strtotime($value['userCouponType'][0]['effect_time']); // 你的目标时间戳
|
||||
if (time() < $targetTimestamp && ($targetTimestamp - time()) <= $threeDays) {
|
||||
$result[$key]['expire'] = 2;
|
||||
} else {
|
||||
$result[$key]['expire'] = 1;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 个人中心券列表
|
||||
public static function coupinList($user_id){
|
||||
$result = UserCouponType::where("status",0)->select()->toarray();
|
||||
foreach($result as $key=>$value){
|
||||
$user_coupon = UserCoupon::where("user_id",$user_id)->where("coupon_id",$value['id'])->select();
|
||||
$result[$key]['use'] = 0;
|
||||
if($user_coupon){
|
||||
$count_3 = 0;
|
||||
$count_4 = 0;
|
||||
foreach ($user_coupon as $ucoupon){
|
||||
if($ucoupon['coupon_id'] == 1){
|
||||
$result[$key]['use'] = 1;
|
||||
}elseif($ucoupon['coupon_id'] == 3){
|
||||
$count_3 ++;
|
||||
}
|
||||
elseif($ucoupon['coupon_id'] == 4){
|
||||
$count_4 ++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($value['id'] == 3&&$count_3 >= 10) {
|
||||
$result[$key]['use'] = 1;
|
||||
}
|
||||
|
||||
if ($value['id'] == 4&&$count_4 >= 10) {
|
||||
$result[$key]['use'] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function expireCoupin(){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
548
app/api/logic/UserLogic.php
Normal file
548
app/api/logic/UserLogic.php
Normal file
@ -0,0 +1,548 @@
|
||||
<?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\api\logic;
|
||||
|
||||
|
||||
use app\common\{enum\notice\NoticeEnum,
|
||||
enum\user\UserTerminalEnum,
|
||||
enum\YesNoEnum,
|
||||
logic\BaseLogic,
|
||||
model\store\Store,
|
||||
model\teamaster\TeamasterCollect,
|
||||
model\teastore\TeaStore,
|
||||
model\user\User,
|
||||
model\user\UserAccountLog,
|
||||
model\user\UserAddress,
|
||||
model\user\UserAuth,
|
||||
model\user\UserCoupon,
|
||||
model\user\UserMember,
|
||||
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 UserLogic 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 = User::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();
|
||||
|
||||
$store_money = 0;
|
||||
$user['store_money'] =$store_money;
|
||||
$user_store_money = UserStoreMoney::where('user_id',$userId)->find();
|
||||
if($user_store_money){
|
||||
$user['store_money'] = $user_store_money->money;
|
||||
}
|
||||
$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();
|
||||
$lastMonthStart = date('Y-m-01 00:00:00', strtotime('-1 month'));
|
||||
$lastMonthEnd = date('Y-m-t 23:59:59', strtotime('-1 month'));
|
||||
$user['last_month'] = UserAccountLog::where("user_id",$userId)
|
||||
->where("action",2)
|
||||
->whereTime('create_time', 'between', [$lastMonthStart, $lastMonthEnd])
|
||||
->sum("amount");
|
||||
// $user['avatar'] = FileService::getFileUrl($user['avatar']);
|
||||
$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 $userId
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 19:36
|
||||
*/
|
||||
public static function hasWechatAuth(int $userId)
|
||||
{
|
||||
//是否有微信授权登录
|
||||
$terminal = [UserTerminalEnum::WECHAT_MMP, UserTerminalEnum::WECHAT_OA,UserTerminalEnum::PC];
|
||||
$auth = UserAuth::where(['user_id' => $userId])
|
||||
->whereIn('terminal', $terminal)
|
||||
->findOrEmpty();
|
||||
return !$auth->isEmpty();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 重置登录密码
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 18:06
|
||||
*/
|
||||
public static function resetPassword(array $params)
|
||||
{
|
||||
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);
|
||||
|
||||
// 更新
|
||||
User::where('mobile', $params['mobile'])->update([
|
||||
'password' => $password
|
||||
]);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 修稿密码
|
||||
* @param $params
|
||||
* @param $userId
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 19:13
|
||||
*/
|
||||
public static function changePassword(array $params, int $userId)
|
||||
{
|
||||
try {
|
||||
$user = User::findOrEmpty($userId);
|
||||
if ($user->isEmpty()) {
|
||||
throw new \Exception('用户不存在');
|
||||
}
|
||||
|
||||
// 密码盐
|
||||
$passwordSalt = Config::get('project.unique_identification');
|
||||
|
||||
if (!empty($user['password'])) {
|
||||
if (empty($params['old_password'])) {
|
||||
throw new \Exception('请填写旧密码');
|
||||
}
|
||||
$oldPassword = create_password($params['old_password'], $passwordSalt);
|
||||
if ($oldPassword != $user['password']) {
|
||||
throw new \Exception('原密码不正确');
|
||||
}
|
||||
}
|
||||
|
||||
// 保存密码
|
||||
$password = create_password($params['password'], $passwordSalt);
|
||||
$user->password = $password;
|
||||
$user->save();
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取小程序手机号
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
|
||||
* @author 段誉
|
||||
* @date 2023/2/27 11:49
|
||||
*/
|
||||
public static function getMobileByMnp(array $params)
|
||||
{
|
||||
try {
|
||||
$response = (new WeChatMnpService())->getUserPhoneNumber($params['code']);
|
||||
$phoneNumber = $response['phone_info']['purePhoneNumber'] ?? '';
|
||||
if (empty($phoneNumber)) {
|
||||
throw new \Exception('获取手机号码失败');
|
||||
}
|
||||
|
||||
$user = User::where([
|
||||
['mobile', '=', $phoneNumber],
|
||||
['id', '<>', $params['user_id']]
|
||||
])->findOrEmpty();
|
||||
|
||||
if (!$user->isEmpty()) {
|
||||
throw new \Exception('手机号已被其他账号绑定');
|
||||
}
|
||||
|
||||
// 绑定手机号
|
||||
User::update([
|
||||
'id' => $params['user_id'],
|
||||
'mobile' => $phoneNumber
|
||||
]);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 绑定手机号
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2022/9/21 17:28
|
||||
*/
|
||||
public static function bindMobile(array $params)
|
||||
{
|
||||
try {
|
||||
// 变更手机号场景
|
||||
$sceneId = NoticeEnum::CHANGE_MOBILE_CAPTCHA;
|
||||
$where = [
|
||||
['id', '=', $params['user_id']],
|
||||
['mobile', '=', $params['mobile']]
|
||||
];
|
||||
|
||||
// 绑定手机号场景
|
||||
if ($params['type'] == 'bind') {
|
||||
$sceneId = NoticeEnum::BIND_MOBILE_CAPTCHA;
|
||||
$where = [
|
||||
['mobile', '=', $params['mobile']]
|
||||
];
|
||||
}
|
||||
|
||||
// 校验短信
|
||||
$checkSmsCode = (new SmsDriver())->verify($params['mobile'], $params['code'], $sceneId);
|
||||
if (!$checkSmsCode) {
|
||||
throw new \Exception('验证码错误');
|
||||
}
|
||||
|
||||
$user = User::where($where)->findOrEmpty();
|
||||
if (!$user->isEmpty()) {
|
||||
throw new \Exception('该手机号已被使用');
|
||||
}
|
||||
|
||||
User::update([
|
||||
'id' => $params['user_id'],
|
||||
'mobile' => $params['mobile'],
|
||||
]);
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @notes 地址列表
|
||||
* @param $params
|
||||
* @return array|false
|
||||
* @author 胥聪
|
||||
* @date 2022/10/21 15:01
|
||||
*/
|
||||
public static function addressList(array $params)
|
||||
{
|
||||
try {
|
||||
$where = [
|
||||
['user_id', '=', $params['user_id']],
|
||||
['del', '=', 0]
|
||||
];
|
||||
if(isset($params['is_default'])){
|
||||
if ($params['is_default'] == 1) {
|
||||
$where = [
|
||||
['is_default', '=', $params['is_default']]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return UserAddress::where($where)->select()->toArray();
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @notes 地址列表
|
||||
* @param $params
|
||||
* @return array|false
|
||||
* @author 胥聪
|
||||
* @date 2022/10/21 15:01
|
||||
*/
|
||||
public static function addressDetails(array $params)
|
||||
{
|
||||
try {
|
||||
$where = [
|
||||
['id', '=', $params['id']],
|
||||
['del', '=', 0]
|
||||
];
|
||||
$result = UserAddress::where($where)->find();
|
||||
|
||||
if ($result == null) {
|
||||
throw new \Exception('地址不存在');
|
||||
}
|
||||
return [
|
||||
'address_details'=>$result
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @notes 创建地址
|
||||
* @param $params
|
||||
* @return array|bool
|
||||
* @author 胥聪
|
||||
* @date 2022/10/21 15:01
|
||||
*/
|
||||
public static function addAddress(array $params)
|
||||
{
|
||||
try {
|
||||
UserAddress::create([
|
||||
'user_id' => $params['user_id'],
|
||||
'contact' => $params['contact'],
|
||||
'telephone' => $params['telephone'],
|
||||
'city_id' => isset($params['city_id']) ? $params['city_id'] : 0,
|
||||
'address' => $params['address'],
|
||||
'longitude' => isset($params['longitude']) ? $params['longitude'] : 0,
|
||||
'latitude' => isset($params['latitude']) ? $params['latitude'] : 0,
|
||||
'is_default' => isset($params['is_default']) ? $params['is_default'] : 0,
|
||||
'create_time' => time()
|
||||
]);
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @notes 修改地址
|
||||
* @param array $params
|
||||
* @return array|bool
|
||||
* @throws \Exception
|
||||
* @author 胥聪
|
||||
* @date 2022/10/21 15:47
|
||||
*/
|
||||
public static function editAddress($params,$user_id)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$params['update_time'] = time();
|
||||
// 更新登录信息
|
||||
if(isset($params['is_default'])){
|
||||
if($params['is_default'] == 1){
|
||||
UserAddress::where("user_id",$user_id)->update(['is_default'=>0]);
|
||||
}
|
||||
}
|
||||
self::updateUserAddress($params);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @notes 修改地址
|
||||
* @param array $params
|
||||
* @return array|bool
|
||||
* @throws \Exception
|
||||
* @author 胥聪
|
||||
* @date 2022/10/21 15:47
|
||||
*/
|
||||
public static function delAddress(array $params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$params['del'] = 1;
|
||||
$params['update_time'] = time();
|
||||
// 更新登录信息
|
||||
self::updateUserAddress($params);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 更新地址
|
||||
* @param $userId
|
||||
* @return UserAddress|array|bool
|
||||
* @throws \Exception
|
||||
* @author 胥聪
|
||||
* @date 2022/10/21 15:47
|
||||
*/
|
||||
public static function updateUserAddress($params)
|
||||
{
|
||||
$userAddress = UserAddress::where("del",0)->findOrEmpty($params['id']);
|
||||
if ($userAddress->isEmpty()) {
|
||||
throw new \Exception('地址不存在');
|
||||
}
|
||||
$id = $params['id'];
|
||||
unset($params['id']);
|
||||
UserAddress::update($params, ['id' => $id]);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function getMoneyLogList($params,$user_id){
|
||||
if (isset($params['month']) && !empty($params['month'])) {
|
||||
// 将 "2025-11" 转换为时间戳范围
|
||||
$month = $params['month'];
|
||||
|
||||
// 计算该月的开始和结束时间戳
|
||||
$startTime = strtotime($month . '-01 00:00:00');
|
||||
$endTime = strtotime(date('Y-m-t 23:59:59', $startTime));
|
||||
|
||||
$where[] = ['create_time', 'between', [$startTime, $endTime]];
|
||||
}
|
||||
$count = UserAccountLog::where('user_id',$user_id)->where($where ?? [])->count();
|
||||
$lists = UserAccountLog::where('user_id',$user_id)
|
||||
->where($where ?? [])
|
||||
->page($params['page'], $params['size'])
|
||||
->order('id desc')
|
||||
->select();
|
||||
$data = [
|
||||
'list' => $lists,
|
||||
'page' => $params['page'],
|
||||
'size' => $params['size'],
|
||||
'count' => $count,
|
||||
'more' => is_more($count, $params['page'], $params['size'])
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getUserStoreMoney($params,$user_id){
|
||||
$result = UserStoreMoney::where("user_id",$user_id)
|
||||
->where("store_id",$params['store_id'])
|
||||
->find();
|
||||
if($result == null){
|
||||
$arr['money'] = 0;
|
||||
return [
|
||||
'data'=> $arr
|
||||
];
|
||||
}
|
||||
return [
|
||||
'data'=> $result
|
||||
];
|
||||
}
|
||||
|
||||
public static function userStoreMoneyList($user_id){
|
||||
$result = UserStoreMoney::where("user_id",$user_id)
|
||||
->select();
|
||||
if($result){
|
||||
foreach ($result as &$item){
|
||||
$store = TeaStore::where('id',$item['store_id'])->find();
|
||||
$item['store_name'] = $store->name;
|
||||
$item['address'] = $store->address;
|
||||
}
|
||||
}
|
||||
|
||||
return $result->toArray();
|
||||
}
|
||||
|
||||
public static function UserMember($user_id){
|
||||
$result = UserMember::where("user_id",$user_id)
|
||||
->where("status",1)
|
||||
->find();
|
||||
if($result!=null){
|
||||
$result['expiration_time'] = date("Y-m-d",$result['expiration_time']);
|
||||
}
|
||||
return [
|
||||
'data'=> $result
|
||||
];
|
||||
}
|
||||
public static function accountDetails($data){
|
||||
$result = UserAccountLog::where("id",$data['id'])->find();
|
||||
$result['store'] = TeaStore::where("id",$result['store_id'])->find();
|
||||
return [
|
||||
'data'=> $result
|
||||
];
|
||||
}
|
||||
}
|
||||
65
app/api/logic/WechatLogic.php
Normal file
65
app/api/logic/WechatLogic.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?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\api\logic;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\service\wechat\WeChatOaService;
|
||||
use EasyWeChat\Kernel\Exceptions\Exception;
|
||||
|
||||
/**
|
||||
* 微信
|
||||
* Class WechatLogic
|
||||
* @package app\api\logic
|
||||
*/
|
||||
class WechatLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 微信JSSDK授权接口
|
||||
* @param $params
|
||||
* @return false|mixed[]
|
||||
* @throws \Psr\SimpleCache\InvalidArgumentException
|
||||
* @throws \Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface
|
||||
* @throws \Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface
|
||||
* @throws \Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface
|
||||
* @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface
|
||||
* @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface
|
||||
* @author 段誉
|
||||
* @date 2023/3/1 11:49
|
||||
*/
|
||||
public static function jsConfig($params)
|
||||
{
|
||||
try {
|
||||
$url = urldecode($params['url']);
|
||||
return (new WeChatOaService())->getJsConfig($url, [
|
||||
'onMenuShareTimeline',
|
||||
'onMenuShareAppMessage',
|
||||
'onMenuShareQQ',
|
||||
'onMenuShareWeibo',
|
||||
'onMenuShareQZone',
|
||||
'openLocation',
|
||||
'getLocation',
|
||||
'chooseWXPay',
|
||||
'updateAppMessageShareData',
|
||||
'updateTimelineShareData',
|
||||
'openAddress',
|
||||
'scanQRCode'
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
self::setError('获取jssdk失败:' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user