提交其他文件
This commit is contained in:
19
app/storeapi/config/route.php
Normal file
19
app/storeapi/config/route.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
return [
|
||||
'middleware' => [
|
||||
app\storeapi\http\middleware\InitMiddleware::class, // 初始化
|
||||
app\storeapi\http\middleware\LoginMiddleware::class, // 登录验证
|
||||
],
|
||||
];
|
||||
31
app/storeapi/controller/BaseApiController.php
Normal file
31
app/storeapi/controller/BaseApiController.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\storeapi\controller;
|
||||
|
||||
use app\common\controller\BaseLikeAdminController;
|
||||
|
||||
class BaseApiController extends BaseLikeAdminController
|
||||
{
|
||||
protected int $userId = 0;
|
||||
protected array $userInfo = [];
|
||||
|
||||
public function initialize()
|
||||
{
|
||||
if (isset($this->request->userInfo) && $this->request->userInfo) {
|
||||
$this->userInfo = $this->request->userInfo;
|
||||
$this->userId = $this->request->userInfo['user_id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
61
app/storeapi/controller/DeviceController.php
Normal file
61
app/storeapi/controller/DeviceController.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace app\storeapi\controller;
|
||||
|
||||
use app\storeapi\logic\DeviceLogic;
|
||||
use app\storeapi\validate\DeviceValidate;
|
||||
|
||||
class DeviceController extends BaseApiController
|
||||
{
|
||||
|
||||
public array $notNeedLogin = ['deviceOff_On'];
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* 门店设备列表
|
||||
*/
|
||||
public function deviceList(){
|
||||
|
||||
$params = (new DeviceValidate())->post()->goCheck('deviceList');
|
||||
|
||||
$result = DeviceLogic::getDeviceLists($params);
|
||||
if ($result === false) {
|
||||
return $this->fail(DeviceLogic::getError());
|
||||
}
|
||||
return $this->success('', $result, 1, 1);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* 空开控制
|
||||
*/
|
||||
public function deviceOff_On(){
|
||||
|
||||
$params = (new DeviceValidate())->post()->goCheck('deviceOff_On');
|
||||
|
||||
$result = DeviceLogic::deviceOff_On($params);
|
||||
if ($result === false) {
|
||||
return $this->fail(DeviceLogic::getError());
|
||||
}
|
||||
return $this->success('', $result, 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* 门锁控制
|
||||
*/
|
||||
public function lockOff_On(){
|
||||
|
||||
$params = (new DeviceValidate())->post()->goCheck('lockOff_On');
|
||||
|
||||
$result = DeviceLogic::lockOff_On($params);
|
||||
if ($result === false) {
|
||||
return $this->fail(DeviceLogic::getError());
|
||||
}
|
||||
return $this->success('', $result, 1, 1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
104
app/storeapi/controller/GroupController.php
Normal file
104
app/storeapi/controller/GroupController.php
Normal file
@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
namespace app\storeapi\controller;
|
||||
|
||||
use app\storeapi\logic\GroupLogic;
|
||||
use app\storeapi\validate\GroupValidate;
|
||||
|
||||
|
||||
class GroupController extends BaseApiController
|
||||
{
|
||||
public array $notNeedLogin = ['cancelCode'];
|
||||
|
||||
/**
|
||||
* @return \think\response\Json
|
||||
* 新增团购套餐
|
||||
*/
|
||||
public function addGroup(){
|
||||
$params = (new GroupValidate())->post()->goCheck('addGroup');
|
||||
$result = GroupLogic::addGroup($params);
|
||||
if ($result === false) {
|
||||
return $this->fail(GroupLogic::getError());
|
||||
}
|
||||
return $this->success('', $result, 1, 1);
|
||||
|
||||
}
|
||||
/**
|
||||
* @return \think\response\Json
|
||||
* 编辑团购套餐
|
||||
*/
|
||||
public function editGroup(){
|
||||
$params = (new GroupValidate())->post()->goCheck('editGroup');
|
||||
$result = GroupLogic::editGroup($params);
|
||||
if ($result === false) {
|
||||
return $this->fail(GroupLogic::getError());
|
||||
}
|
||||
return $this->success('', $result, 1, 1);
|
||||
}
|
||||
/**
|
||||
* @return \think\response\Json
|
||||
* 套餐列表
|
||||
*/
|
||||
public function groupLists(){
|
||||
$params = (new GroupValidate())->post()->goCheck('groupLists');
|
||||
$result = GroupLogic::groupLists($params);
|
||||
if ($result === false) {
|
||||
return $this->fail(GroupLogic::getError());
|
||||
}
|
||||
return $this->success('', $result, 1, 1);
|
||||
}
|
||||
/**
|
||||
* @return \think\response\Json
|
||||
* 删除套餐
|
||||
*/
|
||||
public function delGroup(){
|
||||
$params = (new GroupValidate())->post()->goCheck('delGroup');
|
||||
$result = GroupLogic::delGroup($params);
|
||||
if ($result === false) {
|
||||
return $this->fail(GroupLogic::getError());
|
||||
}
|
||||
return $this->success('', $result, 1, 1);
|
||||
}
|
||||
/**
|
||||
* @return \think\response\Json
|
||||
* 上下架套餐
|
||||
*/
|
||||
public function operateGroup(){
|
||||
$params = (new GroupValidate())->post()->goCheck('operateGroup');
|
||||
$result = GroupLogic::operateGroup($params);
|
||||
if ($result === false) {
|
||||
return $this->fail(GroupLogic::getError());
|
||||
}
|
||||
return $this->success('', $result, 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \think\response\Json
|
||||
* 套餐详情页
|
||||
*/
|
||||
public function groupDetails(){
|
||||
$params = (new GroupValidate())->post()->goCheck('groupDetails');
|
||||
$result = GroupLogic::groupDetails($params);
|
||||
if ($result === false) {
|
||||
return $this->fail(GroupLogic::getError());
|
||||
}
|
||||
return $this->success('', $result, 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \think\response\Json
|
||||
* 门店核销券码
|
||||
*/
|
||||
|
||||
public function cancelCode(){
|
||||
$params = (new GroupValidate())->post()->goCheck('cancelCode');
|
||||
$params['user_id'] = $this->userId;
|
||||
$result = GroupLogic::cancelCode($params);
|
||||
if ($result === false) {
|
||||
return $this->fail(GroupLogic::getError());
|
||||
}
|
||||
return $this->success('', $result, 1, 1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
146
app/storeapi/controller/OrderController.php
Normal file
146
app/storeapi/controller/OrderController.php
Normal file
@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
namespace app\storeapi\controller;
|
||||
|
||||
use app\storeapi\logic\DeviceLogic;
|
||||
use app\storeapi\logic\OrderLogic;
|
||||
|
||||
class OrderController extends BaseApiController
|
||||
{
|
||||
public array $notNeedLogin = [];
|
||||
|
||||
/**
|
||||
* @notes 包间订单列表
|
||||
* @return \think\response\Json
|
||||
* @author 胥聪
|
||||
* @date 2025/11/20 15:03
|
||||
* @data id
|
||||
*/
|
||||
public function orderStoreList(){
|
||||
$userId = $this->userId;
|
||||
$data = $this->request->post();
|
||||
$result = OrderLogic::orderStoreList($data,$userId);
|
||||
return $this->success('查询成功', $result, 1, 1);
|
||||
}
|
||||
/**
|
||||
* @notes 续单列表
|
||||
* @return \think\response\Json
|
||||
* @author 胥聪
|
||||
* @date 2025/11/25 18:03
|
||||
* @data id
|
||||
*/
|
||||
public function orderRenewList(){
|
||||
$data = $this->request->post();
|
||||
$result = OrderLogic::orderRenewList($data);
|
||||
return $this->success('查询成功', $result, 1, 1);
|
||||
}
|
||||
/**
|
||||
* @notes 茶室订单搜索历史
|
||||
* @return \think\response\Json
|
||||
* @author 胥聪
|
||||
* @date 2025/12/18 16:16
|
||||
*/
|
||||
public function orderStoreSearchHistory(){
|
||||
$userId = $this->userId;
|
||||
$result = OrderLogic::getOrderStoreSearchHistory($userId);
|
||||
return $this->success('查询成功', $result, 1, 1);
|
||||
}
|
||||
/**
|
||||
* @notes 一键清空茶室搜索历史
|
||||
* @return \think\response\Json
|
||||
* @author 胥聪
|
||||
* @date 2025/12/18 16:16
|
||||
*/
|
||||
public function delOrderStoreSearchHistory(){
|
||||
$userId = $this->userId;
|
||||
$result = OrderLogic::delOrderStoreSearchHistory($userId);
|
||||
return $this->success('操作成功', [], 1, 1);
|
||||
}
|
||||
/**
|
||||
* @notes 包间订单详情
|
||||
* @return \think\response\Json
|
||||
* @author 胥聪
|
||||
* @date 2025/12/18 16:16
|
||||
* @data
|
||||
*/
|
||||
public function orderStoreDetails(){
|
||||
$data = $this->request->post();
|
||||
$result = OrderLogic::orderStoreDetails($data);
|
||||
if($result){
|
||||
$d['details'] = $result;
|
||||
return $this->success('查询成功', $d, 1, 1);
|
||||
}
|
||||
return $this->fail(OrderLogic::getError());
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 取消包间订单
|
||||
* @return \think\response\Json
|
||||
* @author 胥聪
|
||||
* @date 2025/11/20 15:38
|
||||
* @data
|
||||
*/
|
||||
public function cancelOrderStore(){
|
||||
$data = $this->request->post();
|
||||
$result = OrderLogic::cancelOrderStore($data);
|
||||
return $this->success('操作成功', [], 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 删除包间订单
|
||||
* @return \think\response\Json
|
||||
* @author 胥聪
|
||||
* @date 2025/11/20 15:38
|
||||
* @data
|
||||
*/
|
||||
public function delOrderStore(){
|
||||
$data = $this->request->post();
|
||||
// $result = OrderLogic::delOrderStore($data);
|
||||
return $this->success('目前删除', [], 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 释放包间订单
|
||||
* @return \think\response\Json
|
||||
* @author 胥聪
|
||||
* @date 2025/11/20 15:38
|
||||
* @data
|
||||
*/
|
||||
public function releaseOrderStore(){
|
||||
$data = $this->request->post();
|
||||
$result = OrderLogic::releaseOrderStore($data);
|
||||
if ($result === false) {
|
||||
return $this->fail(OrderLogic::getError());
|
||||
}
|
||||
return $this->success('操作成功', [], 1, 1);
|
||||
}
|
||||
/**
|
||||
* 管理员预定
|
||||
*/
|
||||
|
||||
public function addOrder(){
|
||||
$userId = $this->userId;
|
||||
$data = $this->request->post();
|
||||
$result = OrderLogic::addOrder($data,$userId);
|
||||
if ($result === false) {
|
||||
return $this->fail(OrderLogic::getError());
|
||||
}
|
||||
return $this->success('操作成功', [], 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理员续订
|
||||
*/
|
||||
|
||||
public function renewOrder(){
|
||||
$userId = $this->userId;
|
||||
$data = $this->request->post();
|
||||
$result = OrderLogic::renewOrder($data,$userId);
|
||||
if ($result === false) {
|
||||
return $this->fail(OrderLogic::getError());
|
||||
}
|
||||
return $this->success('操作成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
49
app/storeapi/controller/SmsController.php
Normal file
49
app/storeapi/controller/SmsController.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\storeapi\controller;
|
||||
|
||||
|
||||
use app\api\logic\SmsLogic;
|
||||
use app\api\validate\SendSmsValidate;
|
||||
|
||||
|
||||
/**
|
||||
* 短信
|
||||
* Class SmsController
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class SmsController extends BaseApiController
|
||||
{
|
||||
|
||||
public array $notNeedLogin = ['sendCode'];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 发送短信验证码
|
||||
* @return \think\response\Json
|
||||
* @author 段誉
|
||||
* @date 2022/9/15 16:17
|
||||
*/
|
||||
public function sendCode()
|
||||
{
|
||||
$params = (new SendSmsValidate())->post()->goCheck();
|
||||
$result = SmsLogic::sendCode($params);
|
||||
if (true === $result) {
|
||||
return $this->success('发送成功');
|
||||
}
|
||||
return $this->fail(SmsLogic::getError());
|
||||
}
|
||||
|
||||
}
|
||||
341
app/storeapi/controller/StoreController.php
Normal file
341
app/storeapi/controller/StoreController.php
Normal file
@ -0,0 +1,341 @@
|
||||
<?php
|
||||
|
||||
namespace app\storeapi\controller;
|
||||
use app\storeapi\logic\StoreLogic;
|
||||
class StoreController extends BaseApiController
|
||||
{
|
||||
public array $notNeedLogin = [];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取归属人门店列表
|
||||
* @return \think\response\Json
|
||||
* @author 胥聪
|
||||
* @date 2025/12/16 14:54
|
||||
*/
|
||||
public function userStoreList(){
|
||||
$userId = $this->userId;
|
||||
$result = StoreLogic::getUserStoreList($userId);
|
||||
return $this->success('查询成功', $result, 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 门店详情数据
|
||||
* @return \think\response\Json
|
||||
* @author 胥聪
|
||||
* @date 2025/12/16 14:54
|
||||
*/
|
||||
public function userStoreDetails(){
|
||||
$data = $this->request->post();
|
||||
$result = StoreLogic::getUserStoreDetails($data);
|
||||
return $this->success('查询成功', $result, 1, 1);
|
||||
}
|
||||
/**
|
||||
* @notes 切换店铺
|
||||
* @return \think\response\Json
|
||||
* @author 胥聪
|
||||
* @date 2025/12/16 14:54
|
||||
*/
|
||||
public function switchStore(){
|
||||
$data = $this->request->post();
|
||||
$userId = $this->userId;
|
||||
$result = StoreLogic::switchStore($data,$userId);
|
||||
return $this->success('操作成功', [], 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 编辑门店
|
||||
* @return \think\response\Json
|
||||
* @author 胥聪
|
||||
* @date 2025/12/17 16:15
|
||||
*/
|
||||
public function editStore()
|
||||
{
|
||||
$data = $this->request->post();
|
||||
$result = StoreLogic::editStore($data);
|
||||
if($result){
|
||||
return $this->success('操作成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(StoreLogic::getError());
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 包间列表
|
||||
* @return \think\response\Json
|
||||
* @author 胥聪
|
||||
* @date 2025/12/17 17:21
|
||||
*/
|
||||
public function roomList()
|
||||
{
|
||||
$data = $this->request->post();
|
||||
$result = StoreLogic::roomList($data);
|
||||
return $this->success('', $result, 1, 1);
|
||||
}
|
||||
/**
|
||||
* @notes 包间选择列表
|
||||
* @return \think\response\Json
|
||||
* @author 胥聪
|
||||
* @date 2025/12/17 17:21
|
||||
*/
|
||||
public function roomSelectList()
|
||||
{
|
||||
$data = $this->request->post();
|
||||
$result = StoreLogic::roomSelectList($data);
|
||||
return $this->success('', $result, 1, 1);
|
||||
}
|
||||
/**
|
||||
* @notes 包间状态
|
||||
* @return \think\response\Json
|
||||
* @author 胥聪
|
||||
* @date 2025/12/17 17:37
|
||||
*/
|
||||
public function editRoom()
|
||||
{
|
||||
$data = $this->request->post();
|
||||
$result = StoreLogic::editRoom($data);
|
||||
if($result){
|
||||
return $this->success('操作成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(StoreLogic::getError());
|
||||
}
|
||||
/**
|
||||
* @notes 茶室详情页
|
||||
* @return \think\response\Json
|
||||
* @author 胥聪
|
||||
* @date 2025/11/11 10:53
|
||||
*/
|
||||
public function roomDetails(){
|
||||
$data = $this->request->post();
|
||||
$result = StoreLogic::roomDetails($data);
|
||||
return $this->success('查询成功', $result, 1, 1);
|
||||
}
|
||||
/**
|
||||
* @notes 获取加盟店套餐
|
||||
* @return \think\response\Json
|
||||
* @author 胥聪
|
||||
* @date 2026/2/3 16:30
|
||||
*/
|
||||
public function storeOperationGroup(){
|
||||
$data = $this->request->post();
|
||||
$result = StoreLogic::storeOperationGroup($data);
|
||||
return $this->success('', $result, 1, 1);
|
||||
}
|
||||
/**
|
||||
* @notes 加盟店套餐详情
|
||||
* @return \think\response\Json
|
||||
* @author 胥聪
|
||||
* @date 2026/2/3 16:30
|
||||
*/
|
||||
public function storeOperationGroupDetails(){
|
||||
$data = $this->request->post();
|
||||
$result = StoreLogic::storeOperationGroupDetails($data);
|
||||
if($result){
|
||||
$d['details'] = $result;
|
||||
return $this->success('查询成功', $d, 1, 1);
|
||||
}
|
||||
return $this->fail(StoreLogic::getError());
|
||||
}
|
||||
/**
|
||||
* @notes 包间标签列表
|
||||
* @return \think\response\Json
|
||||
* @author 胥聪
|
||||
* @date 2025/12/18 11:11
|
||||
*/
|
||||
public function roomLabelList()
|
||||
{
|
||||
$data = $this->request->post();
|
||||
$result = StoreLogic::roomLabelList($data);
|
||||
return $this->success('', $result, 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 添加标签
|
||||
* @return \think\response\Json
|
||||
* @author 胥聪
|
||||
* @date 2025/12/18 11:13
|
||||
*/
|
||||
public function addLabel()
|
||||
{
|
||||
$data = $this->request->post();
|
||||
$result = StoreLogic::addLabel($data);
|
||||
if($result){
|
||||
return $this->success('操作成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(StoreLogic::getError());
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 删除标签
|
||||
* @return \think\response\Json
|
||||
* @author 胥聪
|
||||
* @date 2025/12/18 12:18
|
||||
*/
|
||||
public function delLabel()
|
||||
{
|
||||
$data = $this->request->post();
|
||||
$result = StoreLogic::delLabel($data);
|
||||
if($result){
|
||||
return $this->success('操作成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(StoreLogic::getError());
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 预定包间订单信息
|
||||
* @return \think\response\Json
|
||||
* @author 胥聪
|
||||
* @date 2025/12/18 14:15
|
||||
* @data
|
||||
*/
|
||||
public function submitStoreOrder(){
|
||||
$data = $this->request->post();
|
||||
$userId = $this->userId;
|
||||
$result = StoreLogic::addStoreOrder($data,$userId);
|
||||
if($result){
|
||||
$d['id'] = $result;
|
||||
return $this->success('操作成功', $d, 1, 1);
|
||||
}
|
||||
return $this->fail(StoreLogic::getError());
|
||||
}
|
||||
/**
|
||||
* @notes 续订
|
||||
* @return \think\response\Json
|
||||
* @author 胥聪
|
||||
* @date 2025/12/18 14:36
|
||||
* @data
|
||||
*/
|
||||
public function renewDtime(){
|
||||
$data = $this->request->post();
|
||||
$result = StoreLogic::renewDtime($data);
|
||||
if($result){
|
||||
return $this->success('操作成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(StoreLogic::getError());
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 充值套餐列表
|
||||
* @return \think\response\Json
|
||||
* @author Yzt
|
||||
* @date 2026/01/09 14:36
|
||||
* @data
|
||||
*/
|
||||
public function rechargeLists(){
|
||||
$data = $this->request->post();
|
||||
$result = StoreLogic::rechargeLists($data);
|
||||
if($result){
|
||||
return $this->success('', $result, 1, 1);
|
||||
}
|
||||
return $this->fail(StoreLogic::getError());
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 添加充值套餐
|
||||
* @return \think\response\Json
|
||||
* @author Yzt
|
||||
* @date 2026/01/09 14:36
|
||||
* @data
|
||||
*/
|
||||
public function addRecharge(){
|
||||
$data = $this->request->post();
|
||||
$result = StoreLogic::addRecharge($data);
|
||||
if($result){
|
||||
return $this->success('成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(StoreLogic::getError());
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 编辑充值套餐
|
||||
* @return \think\response\Json
|
||||
* @author Yzt
|
||||
* @date 2026/01/09 14:36
|
||||
* @data
|
||||
*/
|
||||
public function editRecharge(){
|
||||
$data = $this->request->post();
|
||||
$result = StoreLogic::editRecharge($data);
|
||||
if($result){
|
||||
return $this->success('成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(StoreLogic::getError());
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 删除充值套餐
|
||||
* @return \think\response\Json
|
||||
* @author Yzt
|
||||
* @date 2026/01/09 14:36
|
||||
* @data
|
||||
*/
|
||||
public function delRecharge(){
|
||||
$data = $this->request->post();
|
||||
$result = StoreLogic::delRecharge($data);
|
||||
if($result){
|
||||
return $this->success('成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(StoreLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 开关充值套餐状态
|
||||
* @return \think\response\Json
|
||||
* @author Yzt
|
||||
* @date 2026/01/09 14:36
|
||||
* @data
|
||||
*/
|
||||
public function operateRecharge(){
|
||||
$data = $this->request->post();
|
||||
$result = StoreLogic::operateRecharge($data);
|
||||
if($result){
|
||||
return $this->success('成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(StoreLogic::getError());
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 资质上传
|
||||
* @return \think\response\Json
|
||||
* @author Yzt
|
||||
* @date 2026/02/11 14:46
|
||||
* @data
|
||||
*/
|
||||
public function addQual(){
|
||||
$data = $this->request->post();
|
||||
$result = StoreLogic::addQual($data);
|
||||
if($result){
|
||||
return $this->success('提交成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(StoreLogic::getError());
|
||||
}
|
||||
/**
|
||||
* @notes 资质详情
|
||||
* @return \think\response\Json
|
||||
* @author Yzt
|
||||
* @date 2026/02/11 15:03
|
||||
* @data
|
||||
*/
|
||||
public function qualDetails(){
|
||||
$data = $this->request->post();
|
||||
$result = StoreLogic::qualDetails($data);
|
||||
$d['details'] = $result;
|
||||
return $this->success('', $d, 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 编辑资质
|
||||
* @return \think\response\Json
|
||||
* @author Yzt
|
||||
* @date 2026/02/11 21:41
|
||||
* @data
|
||||
*/
|
||||
public function editQual(){
|
||||
$data = $this->request->post();
|
||||
$result = StoreLogic::editQual($data);
|
||||
if($result){
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(StoreLogic::getError());
|
||||
}
|
||||
}
|
||||
132
app/storeapi/controller/StoreLoginController.php
Normal file
132
app/storeapi/controller/StoreLoginController.php
Normal file
@ -0,0 +1,132 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\storeapi\controller;
|
||||
|
||||
use app\common\cache\StoreUserTokenCache;
|
||||
use app\common\model\store\StoreUserSession;
|
||||
use app\storeapi\logic\StoreUserLogic;
|
||||
use app\storeapi\validate\{LoginAccountValidate, PasswordValidate, WechatLoginValidate};
|
||||
use app\storeapi\logic\StoreLoginLogic;
|
||||
|
||||
/**
|
||||
* 登录注册
|
||||
* Class LoginController
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class StoreLoginController extends BaseApiController
|
||||
{
|
||||
|
||||
public array $notNeedLogin = [ 'account', 'logout', 'codeUrl','resetPassword'];
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @notes 账号密码/手机号密码/手机号验证码登录
|
||||
* @return \think\response\Json
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 10:42
|
||||
*/
|
||||
public function account()
|
||||
{
|
||||
// $userTokenCache = new StoreUserTokenCache();
|
||||
// $userSession = StoreUserSession::where([['user_id', '=', 1], ['terminal', '=', 1]])->find();
|
||||
// $userTokenCache->deleteUserInfo($userSession->token);
|
||||
$params = (new LoginAccountValidate())->post()->goCheck();
|
||||
$result = StoreLoginLogic::login($params);
|
||||
if (false === $result) {
|
||||
return $this->fail(StoreLoginLogic::getError());
|
||||
}
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 重置密码
|
||||
* @return \think\response\Json
|
||||
* @author 胥聪
|
||||
* @date 2025/12/16 14:30
|
||||
*/
|
||||
public function resetPassword()
|
||||
{
|
||||
$params = (new PasswordValidate())->post()->goCheck('resetPassword');
|
||||
$result = StoreUserLogic::resetPassword($params);
|
||||
if (true === $result) {
|
||||
return $this->success('操作成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(StoreUserLogic::getError());
|
||||
}
|
||||
/**
|
||||
* @notes 退出登录
|
||||
* @return \think\response\Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 10:42
|
||||
*/
|
||||
public function logout()
|
||||
{
|
||||
StoreLoginLogic::logout($this->userInfo);
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取微信请求code的链接
|
||||
* @return \think\response\Json
|
||||
* @author 段誉
|
||||
* @date 2022/9/15 18:27
|
||||
*/
|
||||
public function codeUrl()
|
||||
{
|
||||
$url = $this->request->get('url');
|
||||
$result = ['url' => LoginLogic::codeUrl($url)];
|
||||
return $this->success('获取成功', $result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @notes 小程序绑定微信
|
||||
* @return \think\response\Json
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 19:48
|
||||
*/
|
||||
public function mnpAuthBind()
|
||||
{
|
||||
$params = (new WechatLoginValidate())->post()->goCheck("wechatAuth");
|
||||
$params['user_id'] = $this->userId;
|
||||
$result = LoginLogic::mnpAuthLogin($params);
|
||||
if ($result === false) {
|
||||
return $this->fail(LoginLogic::getError());
|
||||
}
|
||||
return $this->success('绑定成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 更新用户头像昵称
|
||||
* @return \think\response\Json
|
||||
* @author 段誉
|
||||
* @date 2023/2/22 11:15
|
||||
*/
|
||||
public function updateUser()
|
||||
{
|
||||
$params = (new WechatLoginValidate())->post()->goCheck("updateUser");
|
||||
LoginLogic::updateUser($params, $this->userId);
|
||||
return $this->success('操作成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
30
app/storeapi/controller/TrainingController.php
Normal file
30
app/storeapi/controller/TrainingController.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace app\storeapi\controller;
|
||||
use app\storeapi\logic\TrainingLogic;
|
||||
class TrainingController extends BaseApiController
|
||||
{
|
||||
/**
|
||||
* @notes 获门店培训列表
|
||||
* @return \think\response\Json
|
||||
* @author 胥聪
|
||||
* @date 2026/2/12 1:02
|
||||
*/
|
||||
public function trainingList(){
|
||||
$data = $this->request->post();
|
||||
$result = TrainingLogic::trainingList($data);
|
||||
return $this->success('查询成功', $result, 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 获门店培训详情
|
||||
* @return \think\response\Json
|
||||
* @author 胥聪
|
||||
* @date 2026/2/12 1:34
|
||||
*/
|
||||
public function trainingDetails(){
|
||||
$data = $this->request->post();
|
||||
$result = TrainingLogic::trainingDetails($data);
|
||||
return $this->success('查询成功', $result, 1, 1);
|
||||
}
|
||||
}
|
||||
63
app/storeapi/controller/UploadController.php
Normal file
63
app/storeapi/controller/UploadController.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\storeapi\controller;
|
||||
|
||||
use app\common\enum\FileEnum;
|
||||
use app\common\service\UploadService;
|
||||
use Exception;
|
||||
use think\response\Json;
|
||||
|
||||
|
||||
/** 上传文件
|
||||
* Class UploadController
|
||||
* @package app\api\controller
|
||||
*/
|
||||
class UploadController extends BaseApiController
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 上传图片
|
||||
* @return Json
|
||||
* @author 胥聪
|
||||
* @date 2025/12/17 16:34
|
||||
*/
|
||||
public function image()
|
||||
{
|
||||
try {
|
||||
$result = UploadService::image(0, $this->userId,FileEnum::SOURCE_USER);
|
||||
return $this->success('上传成功', $result);
|
||||
} catch (Exception $e) {
|
||||
return $this->fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 上传视频
|
||||
* @return Json
|
||||
* @author 胥聪
|
||||
* @date 2025/12/17 16:34
|
||||
*/
|
||||
public function video()
|
||||
{
|
||||
try {
|
||||
$cid = $this->request->post('cid', 0);
|
||||
$result = UploadService::video($cid);
|
||||
return $this->success('上传成功', $result);
|
||||
} catch (Exception $e) {
|
||||
return $this->fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
244
app/storeapi/controller/UserController.php
Normal file
244
app/storeapi/controller/UserController.php
Normal file
@ -0,0 +1,244 @@
|
||||
<?php
|
||||
|
||||
namespace app\storeapi\controller;
|
||||
|
||||
use app\storeapi\logic\UserLogic;
|
||||
|
||||
class UserController extends BaseApiController
|
||||
{
|
||||
public array $notNeedLogin = [];
|
||||
/**
|
||||
* @notes 获取个人信息
|
||||
* @return \think\response\Json
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 19:46
|
||||
*/
|
||||
public function info()
|
||||
{
|
||||
$result = UserLogic::info($this->userId);
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @notes 更新用户头像昵称
|
||||
* @return \think\response\Json
|
||||
* @author 段誉
|
||||
* @date 2023/2/22 11:15
|
||||
*/
|
||||
public function updateUser()
|
||||
{
|
||||
$data = $this->request->post();
|
||||
$result = UserLogic::updateUser($data, $this->userId);
|
||||
if($result){
|
||||
return $this->success('操作成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(UserLogic::getError());
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 钱包明细
|
||||
* @return \think\response\Json
|
||||
* @author 胥聪
|
||||
* @date 2025/12/17 10:50
|
||||
*/
|
||||
public function balanceLogList()
|
||||
{
|
||||
$data = $this->request->post();
|
||||
$result = UserLogic::balanceLogList($data, $this->userId);
|
||||
if($result){
|
||||
return $this->success('', $result, 1, 1);
|
||||
}
|
||||
return $this->fail(UserLogic::getError());
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 钱包明细详情
|
||||
* @return \think\response\Json
|
||||
* @author 胥聪
|
||||
* @date 2025/12/17 15:44
|
||||
*/
|
||||
public function balanceLogDetails()
|
||||
{
|
||||
$data = $this->request->post();
|
||||
$result = UserLogic::balanceLogDetails($data);
|
||||
if($result){
|
||||
return $this->success('', $result, 1, 1);
|
||||
}
|
||||
return $this->fail(UserLogic::getError());
|
||||
}
|
||||
/**
|
||||
* @notes 查询余额
|
||||
* @return \think\response\Json
|
||||
* @author 胥聪
|
||||
* @date 2025/12/17 14:28
|
||||
*/
|
||||
public function checkMoney()
|
||||
{
|
||||
$data = $this->request->post();
|
||||
$result = UserLogic::checkMoney($data);
|
||||
if($result){
|
||||
return $this->success('', $result, 1, 1);
|
||||
}
|
||||
return $this->fail(UserLogic::getError());
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 添加到账方式
|
||||
* @return \think\response\Json
|
||||
* @author 胥聪
|
||||
* @date 2025/12/17 14:28
|
||||
*/
|
||||
public function addBank()
|
||||
{
|
||||
$data = $this->request->post();
|
||||
$result = UserLogic::addBank($data,$this->userId);
|
||||
if($result){
|
||||
return $this->success('操作成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(UserLogic::getError());
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 查询到账方式
|
||||
* @return \think\response\Json
|
||||
* @author 胥聪
|
||||
* @date 2025/12/17 14:58
|
||||
*/
|
||||
public function checkBank()
|
||||
{
|
||||
$result = UserLogic::checkBank($this->userId);
|
||||
if($result){
|
||||
return $this->success('', $result, 1, 1);
|
||||
}
|
||||
return $this->fail(UserLogic::getError());
|
||||
}
|
||||
/**
|
||||
* @notes 删除到账方式
|
||||
* @return \think\response\Json
|
||||
* @author 胥聪
|
||||
* @date 2025/12/17 16:15
|
||||
*/
|
||||
public function delBank()
|
||||
{
|
||||
$data = $this->request->post();
|
||||
$result = UserLogic::delBank($data);
|
||||
if($result){
|
||||
return $this->success('操作成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(UserLogic::getError());
|
||||
}
|
||||
/**
|
||||
* @notes 提交体现
|
||||
* @return \think\response\Json
|
||||
* @author 胥聪
|
||||
* @date 2025/12/17 15:07
|
||||
*/
|
||||
public function submitReflect()
|
||||
{
|
||||
$data = $this->request->post();
|
||||
$result = UserLogic::submitReflect($data,$this->userId);
|
||||
if($result){
|
||||
return $this->success('操作成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(UserLogic::getError());
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 查询门店用户
|
||||
* @return \think\response\Json
|
||||
* @author 胥聪
|
||||
* @date 2025/12/18 17:33
|
||||
*/
|
||||
public function checkStoreUserList()
|
||||
{
|
||||
$data = $this->request->post();
|
||||
$result = UserLogic::checkStoreUserList($data);
|
||||
return $this->success('', $result, 1, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 管理端余额充值明细
|
||||
* @return \think\response\Json
|
||||
* @author yzt
|
||||
* @date 2025/12/18 17:33
|
||||
*/
|
||||
public function storeRechargeLists()
|
||||
{
|
||||
$data = $this->request->post();
|
||||
$result = UserLogic::storeRechargeLists($data);
|
||||
return $this->success('', $result, 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 查询门店用户详情
|
||||
* @return \think\response\Json
|
||||
* @author 胥聪
|
||||
* @date 2025/12/19 13:52
|
||||
*/
|
||||
public function checkStoreUserDetails()
|
||||
{
|
||||
$data = $this->request->post();
|
||||
$result = UserLogic::checkStoreUserDetails($data);
|
||||
return $this->success('', $result, 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 编辑门店用户备注
|
||||
* @return \think\response\Json
|
||||
* @author 胥聪
|
||||
* @date 2025/12/19 13:53
|
||||
*/
|
||||
public function editStoreUserRemark()
|
||||
{
|
||||
$data = $this->request->post();
|
||||
$result = UserLogic::editStoreUserRemark($data);
|
||||
if($result){
|
||||
return $this->success('操作成功', [], 1, 1);
|
||||
}
|
||||
return $this->fail(UserLogic::getError());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 查询门店用户消费明细
|
||||
* @return \think\response\Json
|
||||
* @author 胥聪
|
||||
* @date 2025/12/19 14:00
|
||||
*/
|
||||
public function checkStoreUserBuyList()
|
||||
{
|
||||
$data = $this->request->post();
|
||||
$result = UserLogic::checkStoreUserBuyList($data);
|
||||
return $this->success('', $result, 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 查询门店财务管理流水列表
|
||||
* @return \think\response\Json
|
||||
* @author 胥聪
|
||||
* @date 2025/12/19 14:48
|
||||
*/
|
||||
public function checkStoreAccountList()
|
||||
{
|
||||
$data = $this->request->post();
|
||||
$result = UserLogic::checkStoreAccountList($data,$this->userId);
|
||||
return $this->success('', $result, 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 首页统计
|
||||
* @return \think\response\Json
|
||||
* @author 胥聪
|
||||
* @date 2025/12/19 14:48
|
||||
*/
|
||||
public function checkMoth()
|
||||
{
|
||||
$data = $this->request->post();
|
||||
$result = UserLogic::checkMoth($data,$this->userId);
|
||||
return $this->success('', $result, 1, 1);
|
||||
}
|
||||
}
|
||||
56
app/storeapi/http/middleware/InitMiddleware.php
Normal file
56
app/storeapi/http/middleware/InitMiddleware.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\storeapi\http\middleware;
|
||||
|
||||
|
||||
use app\common\exception\ControllerExtendException;
|
||||
use app\storeapi\controller\BaseApiController;
|
||||
use think\exception\ClassNotFoundException;
|
||||
use think\exception\HttpException;
|
||||
|
||||
|
||||
class InitMiddleware
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 初始化
|
||||
* @param $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
* @throws ControllerExtendException
|
||||
* @author 段誉
|
||||
* @date 2022/9/6 18:17
|
||||
*/
|
||||
public function handle($request, \Closure $next)
|
||||
{
|
||||
//获取控制器
|
||||
try {
|
||||
$controller = str_replace('.', '\\', $request->controller());
|
||||
$controller = '\\app\\storeapi\\controller\\' . $controller . 'Controller';
|
||||
$controllerClass = invoke($controller);
|
||||
if (($controllerClass instanceof BaseApiController) === false) {
|
||||
throw new ControllerExtendException($controller, '404');
|
||||
}
|
||||
} catch (ClassNotFoundException $e) {
|
||||
throw new HttpException(404, 'controller not exists:' . $e->getClass());
|
||||
}
|
||||
//创建控制器对象
|
||||
$request->controllerObject = invoke($controller);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
}
|
||||
74
app/storeapi/http/middleware/LoginMiddleware.php
Normal file
74
app/storeapi/http/middleware/LoginMiddleware.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\storeapi\http\middleware;
|
||||
|
||||
|
||||
use app\common\cache\StoreUserTokenCache;
|
||||
use app\common\service\JsonService;
|
||||
use app\storeapi\service\StoreUserTokenService;
|
||||
use think\facade\Config;
|
||||
|
||||
class LoginMiddleware
|
||||
{
|
||||
/**
|
||||
* @notes 登录验证
|
||||
* @param $request
|
||||
* @param \Closure $next
|
||||
* @return mixed|\think\response\Json
|
||||
* @author 令狐冲
|
||||
* @date 2021/7/1 17:33
|
||||
*/
|
||||
public function handle($request, \Closure $next)
|
||||
{
|
||||
$token = $request->header('token');
|
||||
//判断接口是否免登录
|
||||
$isNotNeedLogin = $request->controllerObject->isNotNeedLogin();
|
||||
|
||||
//不直接判断$isNotNeedLogin结果,使不需要登录的接口通过,为了兼容某些接口可以登录或不登录访问
|
||||
if (empty($token) && !$isNotNeedLogin) {
|
||||
//没有token并且该地址需要登录才能访问, 指定show为0,前端不弹出此报错
|
||||
return JsonService::fail('请求参数缺token', [], 0, 0);
|
||||
}
|
||||
|
||||
$userInfo = (new StoreUserTokenCache())->getUserInfo($token);
|
||||
|
||||
if (empty($userInfo) && !$isNotNeedLogin) {
|
||||
//token过期无效并且该地址需要登录才能访问
|
||||
return JsonService::fail('登录超时,请重新登录', [], -1, 0);
|
||||
}
|
||||
|
||||
//token临近过期,自动续期
|
||||
if ($userInfo) {
|
||||
//获取临近过期自动续期时长
|
||||
$beExpireDuration = Config::get('project.user_token.be_expire_duration');
|
||||
//token续期
|
||||
if (time() > ($userInfo['expire_time'] - $beExpireDuration)) {
|
||||
$result = StoreUserTokenService::overtimeToken($token);
|
||||
//续期失败(数据表被删除导致)
|
||||
if (empty($result)) {
|
||||
return JsonService::fail('登录过期', [], -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//给request赋值,用于控制器
|
||||
$request->userInfo = $userInfo;
|
||||
$request->userId = $userInfo['user_id'] ?? 0;
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
}
|
||||
37
app/storeapi/lists/BaseApiDataLists.php
Normal file
37
app/storeapi/lists/BaseApiDataLists.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\storeapi\lists;
|
||||
|
||||
use app\common\lists\BaseDataLists;
|
||||
|
||||
abstract class BaseApiDataLists extends BaseDataLists
|
||||
{
|
||||
protected array $userInfo = [];
|
||||
protected int $userId = 0;
|
||||
|
||||
public string $export;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
if (isset($this->request->userInfo) && $this->request->userInfo) {
|
||||
$this->userInfo = $this->request->userInfo;
|
||||
$this->userId = $this->request->userId;
|
||||
}
|
||||
$this->export = $this->request->get('export', '');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
136
app/storeapi/logic/DeviceLogic.php
Normal file
136
app/storeapi/logic/DeviceLogic.php
Normal file
@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
namespace app\storeapi\logic;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\teastore\TeaStore;
|
||||
use app\common\model\teastore\TeaStoreRoom;
|
||||
use app\common\model\teastore\TeaStoreRoom as roomModel;
|
||||
use app\common\service\iot\IotService;
|
||||
use app\common\service\iot\DoorService;
|
||||
|
||||
class DeviceLogic extends BaseLogic
|
||||
{
|
||||
/**
|
||||
* Class SmsLogic
|
||||
* @package app\api\logic
|
||||
* 设备管理逻辑
|
||||
*/
|
||||
|
||||
public static function getDeviceLists($params){
|
||||
try {
|
||||
$store_id = $params['store_id'];
|
||||
$data =[];
|
||||
$store = TeaStore::where([
|
||||
'id'=>$store_id,
|
||||
'del'=>0
|
||||
])->find();
|
||||
if(!$store){
|
||||
throw new \Exception('门店不存在或已删除');
|
||||
}
|
||||
$roomList = roomModel::where('store_id',$store_id)
|
||||
->where('del',0)
|
||||
->select()->toArray();
|
||||
$data['store_id'] = $store_id;
|
||||
$data['is_lock'] = $store->is_lock;
|
||||
$data['lock_no']= $store->lock_no;
|
||||
$data['roomDevice'] = array();
|
||||
if($roomList){
|
||||
$roomDevice = [];
|
||||
foreach ($roomList as $key=>$item){
|
||||
$data['roomDevice'][$key]['room_id'] = $item['id'];
|
||||
$data['roomDevice'][$key]['title'] = $item['title'];
|
||||
$data['roomDevice'][$key]['device_id']= $item['device_id'];
|
||||
$data['roomDevice'][$key]['lock_no'] = $item['lock_no'];
|
||||
$data['roomDevice'][$key]['is_open'] = $item['is_open'];
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
}catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static function deviceOff_On($params){
|
||||
try {
|
||||
$device_id = $params['device_id'];
|
||||
$state = $params['state'];
|
||||
$device = TeaStoreRoom::where('device_id',$device_id)->find();
|
||||
|
||||
if(!$device){
|
||||
throw new \Exception('空开id错误');
|
||||
}
|
||||
// 使用服务类
|
||||
$iotService = new IotService();
|
||||
$result = $iotService->controlDevice($device_id, $state);
|
||||
|
||||
TeaStoreRoom::where('id',$device['id'])->update(['is_open'=>$state]);
|
||||
|
||||
if($result['code']!==200){
|
||||
throw new \Exception('空开操作失败');
|
||||
}
|
||||
return [];
|
||||
|
||||
|
||||
}catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static function lockOff_On($params){
|
||||
try {
|
||||
$type = $params['type'];
|
||||
$lock_no = $params['lock_no'];
|
||||
$store_id = $params['store_id'];
|
||||
$room_id = $params['room_id'];
|
||||
|
||||
|
||||
if (!in_array($type, [1, 2])) {
|
||||
throw new \Exception('门锁类型不存在');
|
||||
}
|
||||
if($type == 1){
|
||||
$store = TeaStore::where([
|
||||
'lock_no'=>$lock_no,
|
||||
'id'=>$store_id,
|
||||
'del'=>0
|
||||
])->find();
|
||||
if(!$store){
|
||||
throw new \Exception('门店不存在或大门门锁编号不匹配');
|
||||
}
|
||||
}else{
|
||||
$room = TeaStoreRoom::where([
|
||||
'id'=>$room_id,
|
||||
'lock_no'=>$lock_no,
|
||||
'del'=>0
|
||||
])->find();
|
||||
|
||||
if(!$room){
|
||||
throw new \Exception('包间不存在或包间门锁编号不匹配');
|
||||
}
|
||||
}
|
||||
|
||||
$doorService = new DoorService();
|
||||
$result = $doorService->unlockByNetwork($lock_no);
|
||||
if($result['errcode'] !==0){
|
||||
throw new \Exception('开锁失败');
|
||||
}
|
||||
return [];
|
||||
|
||||
}catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
500
app/storeapi/logic/GroupLogic.php
Normal file
500
app/storeapi/logic/GroupLogic.php
Normal file
@ -0,0 +1,500 @@
|
||||
<?php
|
||||
|
||||
namespace app\storeapi\logic;
|
||||
|
||||
use app\api\controller\AccountLogController;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\teastore\TeaStore;
|
||||
use app\common\model\teastore\TeaStoreGroup;
|
||||
use app\common\model\teastore\TeaStoreRoom;
|
||||
use app\common\model\teastore\TeaStoreRoom as roomModel;
|
||||
use app\common\model\user\UserGroup;
|
||||
use app\common\model\store\StoreUserAccountLog;
|
||||
use app\common\model\order\OrderGroup;
|
||||
|
||||
use app\common\service\FileService;
|
||||
use think\facade\Db;
|
||||
class GroupLogic extends BaseLogic
|
||||
{
|
||||
public static function addGroup($params){
|
||||
Db::startTrans();
|
||||
try {
|
||||
$store = TeaStore::where([
|
||||
'id' => $params['store_id'],
|
||||
'del' => 0
|
||||
])->find();
|
||||
if(!$store){
|
||||
throw new \Exception('门店不存在');
|
||||
}
|
||||
if (!in_array($params['type'], [1, 2])) {
|
||||
throw new \Exception('套餐类型错误');
|
||||
}
|
||||
if($params['price']<$params['discount_price']){
|
||||
throw new \Exception('门市价不能小于团购价');
|
||||
}
|
||||
$discount = $params['discount_price']/$params['price'];
|
||||
$data = [
|
||||
'store_id'=>$params['store_id'],
|
||||
'type'=>$params['type'],
|
||||
'sku_id'=>$params['sku_id'],
|
||||
'title'=>$params['title'],
|
||||
'img'=>$params['img'],
|
||||
'hour'=>$params['hour'],
|
||||
'description'=>$params['description'],
|
||||
'introduce'=>$params['introduce'],
|
||||
'storepl_number'=>$params['pl_number'],
|
||||
'rests_introduce'=>$params['rests_introduce'],
|
||||
'price'=>$params['price'],
|
||||
'sold'=>$params['sold'],
|
||||
'pl_number'=>$params['pl_number'],
|
||||
'discount_price'=>$params['discount_price'],
|
||||
'returd_details'=>$params['returd_details'],
|
||||
'discount'=>$discount,
|
||||
'room_id'=>$params['room_id'],
|
||||
'status'=>$params['status'],
|
||||
'dtime'=>time()
|
||||
];
|
||||
TeaStoreGroup::create($data);
|
||||
Db::commit();
|
||||
return [];
|
||||
}catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static function editGroup($params){
|
||||
Db::startTrans();
|
||||
try {
|
||||
// 1. 查找记录
|
||||
$group = TeaStoreGroup::find($params['group_id']);
|
||||
if (!$group) {
|
||||
throw new \Exception('团购套餐不存在');
|
||||
}
|
||||
|
||||
// 2. 基础验证
|
||||
if (isset($params['type']) && !in_array($params['type'], [1, 2])) {
|
||||
throw new \Exception('套餐类型错误');
|
||||
}
|
||||
|
||||
// 3. 验证门店(如果修改门店)
|
||||
if (isset($params['store_id'])) {
|
||||
$storeExists = TeaStore::where([
|
||||
'id' => $params['store_id'],
|
||||
'del' => 0
|
||||
])->find();
|
||||
|
||||
if (!$storeExists) {
|
||||
throw new \Exception('门店不存在');
|
||||
}
|
||||
}
|
||||
|
||||
// 4. 价格验证
|
||||
$price = $params['price'] ?? $group->price;
|
||||
$discountPrice = $params['discount_price'] ?? $group->discount_price;
|
||||
|
||||
if ($price < $discountPrice) {
|
||||
throw new \Exception('门市价不能小于团购价');
|
||||
}
|
||||
|
||||
// 5. 准备更新数据
|
||||
$updateData = [];
|
||||
$fields = ['store_id', 'type', 'sku_id', 'title', 'img', 'hour',
|
||||
'description', 'introduce', 'rests_introduce', 'price','pl_number','discount_price',
|
||||
'returd_details', 'room_id', 'status','sold'];
|
||||
|
||||
foreach ($fields as $field) {
|
||||
if (isset($params[$field])) {
|
||||
$updateData[$field] = $params[$field];
|
||||
}
|
||||
}
|
||||
|
||||
// 计算折扣
|
||||
if (isset($params['price']) || isset($params['discount_price'])) {
|
||||
if ($params['price'] != 0 && $params['price'] > 0) {
|
||||
$updateData['discount'] = round(($discountPrice / $params['price']) * 10, 1);
|
||||
} else {
|
||||
$updateData['discount'] = 0;
|
||||
}
|
||||
}
|
||||
$updateData['update_dtime'] =time();
|
||||
TeaStoreGroup::where("id",$params['group_id'])->update($updateData);
|
||||
// 6. 更新记录
|
||||
// $group->save($updateData);
|
||||
|
||||
Db::commit();
|
||||
return [];
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function groupLists($params){
|
||||
// 验证状态参数
|
||||
$status = $params['status'];
|
||||
if (!in_array($params['status'], [0, 1, 2])) {
|
||||
throw new \Exception('状态参数错误');
|
||||
}
|
||||
// 构建查询条件
|
||||
$query = TeaStoreGroup::where('del', 0)
|
||||
->where([
|
||||
'status'=> $status,
|
||||
'store_id'=>$params['store_id']
|
||||
]);
|
||||
|
||||
|
||||
// 添加标题模糊查询(如果传入了search参数)
|
||||
if (!empty($params['search'])) {
|
||||
$query->where('title', 'like', '%' . $params['search'] . '%');
|
||||
}
|
||||
|
||||
// 查询并分页
|
||||
$list = $query->order('dtime', 'desc')
|
||||
->paginate([
|
||||
'page' => $params['page'],
|
||||
'list_rows' => $params['size']
|
||||
]);
|
||||
$statusCount = self::getGroupStatusCount($params['store_id']);
|
||||
// 处理列表数据中的图片
|
||||
$items = $list->items();
|
||||
|
||||
foreach ($items as &$item) {
|
||||
// 处理img字段:分割为数组并拼接URL
|
||||
$item['img_list'] = explode(",",$item['img']);
|
||||
$img = [];
|
||||
foreach($item['img_list'] as $k=>$v){
|
||||
$img[] = FileService::getImgUrl($v);
|
||||
}
|
||||
$item['img_list'] = $img;
|
||||
// 添加主图(第一张)
|
||||
$item['main_image'] = !empty($item['img_list']) ? $item['img_list'][0] : '';
|
||||
// 图片数量
|
||||
$item['img_count'] = count($item['img_list']);
|
||||
$item['code'] = $item['id'];
|
||||
$item['discount'] = round($item['discount'],2);
|
||||
|
||||
// 保留原始img字段(可选)
|
||||
// $item['img'] 保持原样
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 返回分页数据
|
||||
return [
|
||||
'offline'=>$statusCount['offline'],
|
||||
'online'=>$statusCount['online'],
|
||||
'draft'=>$statusCount['draft'],
|
||||
'list' => $list->items(),
|
||||
'total' => $list->total(),
|
||||
'per_page' => $list->listRows(),
|
||||
'current_page' => $list->currentPage(),
|
||||
'last_page' => $list->lastPage(),
|
||||
'more' => is_more($list->total(), $params['page'], $params['size'])
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取套餐统计(三个状态的计数)
|
||||
* @return array 统计结果
|
||||
*/
|
||||
public static function getGroupStatusCount($store_id)
|
||||
{
|
||||
$counts = TeaStoreGroup::where('del', 0)
|
||||
->where('store_id',$store_id)
|
||||
->field('status, COUNT(*) as count')
|
||||
->group('status')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
// 格式化结果
|
||||
$result = [
|
||||
'offline' => 0, // 已下架
|
||||
'online' => 0, // 已上架
|
||||
'draft' => 0, // 草稿箱
|
||||
'total' => 0 // 总数
|
||||
];
|
||||
|
||||
foreach ($counts as $count) {
|
||||
switch ($count['status']) {
|
||||
case 0:
|
||||
$result['offline'] = $count['count'];
|
||||
break;
|
||||
case 1:
|
||||
$result['online'] = $count['count'];
|
||||
break;
|
||||
case 2:
|
||||
$result['draft'] = $count['count'];
|
||||
break;
|
||||
}
|
||||
$result['total'] += $count['count'];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化图片列表
|
||||
* @param string $imgString 图片字符串,逗号分隔
|
||||
* @return array 拼接完整URL的图片数组
|
||||
*/
|
||||
private static function formatImageList($imgString)
|
||||
{
|
||||
if (empty($imgString)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// 用逗号分割字符串
|
||||
$images = explode(',', $imgString);
|
||||
|
||||
// 过滤空值
|
||||
$images = array_filter($images);
|
||||
|
||||
if (empty($images)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// 去除空白字符
|
||||
$images = array_map('trim', $images);
|
||||
|
||||
// 获取当前域名
|
||||
$domain = request()->domain();
|
||||
|
||||
$result = [];
|
||||
foreach ($images as $image) {
|
||||
// 如果已经是完整URL,直接返回
|
||||
if (strpos($image, 'http://') === 0 || strpos($image, 'https://') === 0) {
|
||||
$result[] = $image;
|
||||
continue;
|
||||
}
|
||||
|
||||
// 移除开头的斜杠
|
||||
$image = ltrim($image, '/');
|
||||
|
||||
// 拼接完整URL(假设图片放在uploads目录)
|
||||
$result[] = $domain . '/' . $image;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
public static function delGroup($params){
|
||||
Db::startTrans();
|
||||
try {
|
||||
// 1. 验证记录存在性且未删除
|
||||
$group = TeaStoreGroup::where([
|
||||
'id' => $params['group_id'],
|
||||
'del' => 0 // 只查找未删除的记录
|
||||
])->find();
|
||||
|
||||
if (!$group) {
|
||||
throw new \Exception('团购套餐不存在或已被删除');
|
||||
}
|
||||
|
||||
// 3. 执行逻辑删除
|
||||
$group->del = 1;
|
||||
$group->update_dtime = time();
|
||||
$result = $group->save();
|
||||
|
||||
if ($result === false) {
|
||||
throw new \Exception('删除失败');
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
return [];
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function operateGroup($params){
|
||||
Db::startTrans();
|
||||
try {
|
||||
// 1. 验证记录存在性且未删除
|
||||
$group = TeaStoreGroup::where([
|
||||
'id' => $params['group_id'],
|
||||
'del' => 0 // 只查找未删除的记录
|
||||
])->find();
|
||||
|
||||
if (!$group) {
|
||||
throw new \Exception('团购套餐不存在或已被删除');
|
||||
}
|
||||
|
||||
// 3. 执行逻辑删除
|
||||
$group->status = $params['status'];
|
||||
$group->update_dtime = time();
|
||||
$result = $group->save();
|
||||
|
||||
if ($result === false) {
|
||||
throw new \Exception('更新失败');
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
|
||||
|
||||
return [];
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function groupDetails($params){
|
||||
try{
|
||||
$group = TeaStoreGroup::where('id', $params['group_id'])
|
||||
->where('del', 0)
|
||||
->find();
|
||||
|
||||
if (!$group) {
|
||||
throw new \Exception('套餐不存在或已被删除');
|
||||
}
|
||||
|
||||
$data = $group->toArray();
|
||||
// $domain = request()->domain();
|
||||
// 处理多图
|
||||
$data['img_list'] = self::getImageList($data['img']);
|
||||
foreach ($data['img_list'] as &$items){
|
||||
// $fullImages[] = $domain . '/' . $items;
|
||||
$fullImages[] = FileService::getImgUrl($items);
|
||||
}
|
||||
$data['img_list']= $fullImages;
|
||||
// 添加状态文本
|
||||
$data['status_text'] = self::getStatusText($data['status']);
|
||||
$room_id = $data['room_id'];
|
||||
$data['room_title'] = '';
|
||||
if($room_id == 0){
|
||||
$data['room_title'] = '通用';
|
||||
}else{
|
||||
$roomData = explode(',',$room_id);
|
||||
$room = TeaStoreRoom::whereIn('id', $roomData)->field('title')
|
||||
->select()
|
||||
->toArray();
|
||||
$data['room_title'] = implode(',', array_column($room, 'title'));
|
||||
}
|
||||
|
||||
|
||||
return $data;
|
||||
}catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
// 查询套餐
|
||||
|
||||
}
|
||||
|
||||
public static function cancelCode($params){
|
||||
$qr_sn =$params['qr_sn'];
|
||||
$store_id =$params['store_id'];
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
|
||||
$user_group = UserGroup::where('qr_sn',$qr_sn)->find();
|
||||
if(!$user_group){
|
||||
throw new \Exception('券码错误,无效券码');
|
||||
}
|
||||
if($user_group['status'] !=0){
|
||||
throw new \Exception('已被核销或已过期');
|
||||
}
|
||||
$group_order = OrderGroup::where('id',$user_group['order_id'])->find();
|
||||
if(!$group_order){
|
||||
throw new \Exception('核销错误请联系客服');
|
||||
}
|
||||
if($group_order['store_id'] !=$store_id){
|
||||
throw new \Exception('此券码不属于当前门店');
|
||||
}
|
||||
$order_sn = $group_order['order_sn'];
|
||||
|
||||
$store = TeaStore::where([
|
||||
'id'=>$store_id,
|
||||
'del'=>0
|
||||
])->find();
|
||||
if(!$store){
|
||||
throw new \Exception('门店不存在');
|
||||
}
|
||||
$balance = $store['balance'];
|
||||
$after_amount = $balance+$group_order['order_amount'];
|
||||
|
||||
// 方法1:使用随机数组合
|
||||
$part1 = mt_rand(100000, 999999); // 6位
|
||||
$part2 = mt_rand(100000, 999999); // 6位
|
||||
$part3 = mt_rand(100000, 999999); // 6位
|
||||
|
||||
$sn = $part1 . $part2 . $part3;
|
||||
|
||||
// 组合成18位
|
||||
$number = $part1 . $part2 . $part3;
|
||||
$accountData = [
|
||||
'sn'=>$sn,
|
||||
'user_id'=>$params['user_id'],
|
||||
'change_object'=>4,
|
||||
'change_type'=>'4',
|
||||
'action'=>'1',
|
||||
'amount'=>$group_order['order_amount'],
|
||||
'before_amount'=>$after_amount,
|
||||
'source_sn'=>$order_sn,
|
||||
'store_id'=>$store_id,
|
||||
'room_id'=>'0',
|
||||
'remark'=>'门店核销',
|
||||
'create_time'=>time(),
|
||||
'status'=>'1'
|
||||
];
|
||||
StoreUserAccountLog::create($accountData);
|
||||
$store->balance = $after_amount;
|
||||
$store->save();
|
||||
$user_group->status = 1;
|
||||
$user_group->update_dtime = date('Y-m-d H:i');
|
||||
$user_group->save();
|
||||
|
||||
Db::commit();
|
||||
return [];
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static function getImageList($imgString)
|
||||
{
|
||||
if (empty($imgString)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// 用逗号分隔字符串
|
||||
$images = explode(',', $imgString);
|
||||
|
||||
// 去除空值和空白字符
|
||||
$images = array_filter(array_map('trim', $images));
|
||||
|
||||
return array_values($images); // 重新索引数组
|
||||
}
|
||||
|
||||
private static function getStatusText($status)
|
||||
{
|
||||
$statusMap = [
|
||||
0 => '已下架',
|
||||
1 => '已上架',
|
||||
2 => '草稿箱'
|
||||
];
|
||||
|
||||
return $statusMap[$status] ?? '未知状态';
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
561
app/storeapi/logic/OrderLogic.php
Normal file
561
app/storeapi/logic/OrderLogic.php
Normal file
@ -0,0 +1,561 @@
|
||||
<?php
|
||||
|
||||
namespace app\storeapi\logic;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\order\OrderGroup;
|
||||
use app\common\model\order\OrderStore;
|
||||
use app\common\model\order\OrderStoreHistory;
|
||||
use app\common\model\store\StoreUser;
|
||||
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\UserCoupon;
|
||||
use app\common\model\user\UserCouponType;
|
||||
use app\common\service\FileService;
|
||||
use app\common\service\iot\IotService;
|
||||
use app\common\model\user\UserStoreMoney;
|
||||
use app\common\model\user\UserAccountLog;
|
||||
use app\common\model\store\StoreUserAccountLog;
|
||||
use think\facade\{Db};
|
||||
use app\common\service\pay\WeChatPayService;
|
||||
use app\common\model\user\UserGroup;
|
||||
class OrderLogic extends BaseLogic
|
||||
{
|
||||
|
||||
public static function orderStoreList($post,$userId){
|
||||
$os = "";
|
||||
$od = "a.start_time desc";
|
||||
if(isset($post['order_status'])){
|
||||
if($post['order_status']!= "" || $post['order_status']!= null){
|
||||
$os = "a.order_status = ".$post['order_status']."";
|
||||
$od = "a.start_time asc";
|
||||
if($post['order_status'] == 3){
|
||||
$od = "a.start_time desc";
|
||||
}
|
||||
}
|
||||
}
|
||||
$s = "";
|
||||
if(isset($post['search'])){
|
||||
if($post['search']!= "" || $post['search']!= null){
|
||||
$a = $post['search'];
|
||||
$s = "c.title like '%".$a."%'";
|
||||
$hostory = OrderStoreHistory::where("content",$a)
|
||||
->where("user_id",$userId)
|
||||
->where("del",0)
|
||||
->where("status",1)
|
||||
->find();
|
||||
if($hostory == null){
|
||||
OrderStoreHistory::create([
|
||||
"user_id"=>$userId,
|
||||
"content"=>$a,
|
||||
"dtime"=>time()
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
$count = OrderStore::alias("a")
|
||||
->where("a.del",0)
|
||||
->where("a.is_transfer",0)
|
||||
->where('a.store_id',$post['store_id'])
|
||||
->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,c.img,a.user_id,a.renew_hour,order_amount,renew_price')
|
||||
->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.is_transfer",0)
|
||||
->where('a.store_id',$post['store_id'])
|
||||
->where($os)
|
||||
->where($s)
|
||||
->page($post['page'], $post['size'])
|
||||
->order($od)
|
||||
->select();
|
||||
foreach($lists as $key=>$value){
|
||||
$lists[$key]['user_mobile'] = "";
|
||||
$user = User::where("id",$value['user_id'])->find();
|
||||
if($user!=null){
|
||||
$lists[$key]['user_mobile'] = $user['mobile'];
|
||||
}
|
||||
$lists[$key]['img'] = FileService::getImgUrl($value['img']);
|
||||
$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'];
|
||||
$lists[$key]['price'] = $value['order_amount']+$value['renew_price'];
|
||||
}
|
||||
$data = [
|
||||
'list' => $lists,
|
||||
'page' => $post['page'],
|
||||
'size' => $post['size'],
|
||||
'count' => $count,
|
||||
'more' => is_more($count, $post['page'], $post['size'])
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
public static function orderRenewList($post){
|
||||
$count = OrderStore::alias("a")
|
||||
->where("a.del",0)
|
||||
->where("a.is_transfer",0)
|
||||
->where('a.store_id',$post['store_id'])
|
||||
->join("tea_store b","b.id = a.store_id","left")
|
||||
->join("tea_store_room c","c.id = a.room_id","left")
|
||||
->where("a.order_status","in","1,2")
|
||||
->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,c.img,a.user_id,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.is_transfer",0)
|
||||
->where('a.store_id',$post['store_id'])
|
||||
->where("a.order_status","in","1,2")
|
||||
->page($post['page'], $post['size'])
|
||||
->order('a.id asc')
|
||||
->select();
|
||||
foreach($lists as $key=>$value){
|
||||
$lists[$key]['user_mobile'] = "";
|
||||
$user = User::where("id",$value['user_id'])->find();
|
||||
if($user!=null){
|
||||
$lists[$key]['user_mobile'] = $user['mobile'];
|
||||
}
|
||||
$lists[$key]['img'] = FileService::getImgUrl($value['img']);
|
||||
$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 getOrderStoreSearchHistory($userId){
|
||||
$lists = OrderStoreHistory::where("user_id",$userId)
|
||||
->where("status",1)
|
||||
->where("del",0)
|
||||
->order("id","desc")
|
||||
->limit(15)
|
||||
->select();
|
||||
$data = [
|
||||
'list' => $lists
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
public static function delOrderStoreSearchHistory($userId){
|
||||
return OrderStoreHistory::where("user_id",$userId)
|
||||
->where("status",1)
|
||||
->where("del",0)
|
||||
->update(['del'=>1]);
|
||||
}
|
||||
public static function orderStoreDetails($data){
|
||||
$details = OrderStore::where("id",$data['id'])->find();
|
||||
$room_msg = TeaStoreRoom::where("id",$details['room_id'])->find();
|
||||
$room_msg['img'] = FileService::getImgUrl($room_msg['img'] );
|
||||
$details['room_msg'] = $room_msg;
|
||||
$store_msg = TeaStore::where("id",$details['store_id'])->find();
|
||||
$details['store_msg'] = $store_msg;
|
||||
$details['mobile'] = "";
|
||||
$user = User::where('id',$details['user_id'])->find();
|
||||
if($user != null){
|
||||
$details['mobile'] = $user['mobile'];
|
||||
}
|
||||
// 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', $r_msg['start_time']);
|
||||
// $r_msg['end_time'] = date('H:i', $r_msg['end_time']);
|
||||
// $arr[$key] =$r_msg;
|
||||
// }
|
||||
//// $details['renew_dtime'] = $arr;
|
||||
// $details['renew_dtime'] = array_slice($arr, -1)[0];
|
||||
// }
|
||||
$group_type = '';
|
||||
$details['pay_way_title'] = "";
|
||||
if($details['group_coupon_id']!==0){
|
||||
$user_group = UserGroup::where('id',$details['group_coupon_id'])->find();
|
||||
if($user_group['type'] ==1){
|
||||
$group_type = '本地套餐';
|
||||
}elseif($user_group['type'] ==2){
|
||||
$group_type = '抖音套餐';
|
||||
}
|
||||
}
|
||||
if($details->order_amount>0){
|
||||
if( $details['pay_way'] == 1){
|
||||
$details['pay_way_title'] = "平台余额支付".'+'.$group_type;
|
||||
}
|
||||
if( $details['pay_way'] == 2){
|
||||
$details['pay_way_title'] = "微信支付".'+'.$group_type;
|
||||
}
|
||||
if( $details['pay_way'] == 3){
|
||||
$details['pay_way_title'] = "门店余额支付".'+'.$group_type;
|
||||
}
|
||||
|
||||
}else{
|
||||
$details['pay_way_title'] = $group_type;
|
||||
if( $details['pay_way'] == 4){
|
||||
$details['pay_way_title'] = "管理员添加".'+'.$group_type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return $details;
|
||||
}
|
||||
public static function submitRefund($data){
|
||||
$order_store = OrderStore::where([
|
||||
'id'=>$data['order_id'],
|
||||
'is_transfer'=>0,
|
||||
])->whereIn('pay_status',[1,2])->find();
|
||||
|
||||
}
|
||||
public static function cancelOrderStore($data){
|
||||
|
||||
$order = OrderStore::where("id",$data['id'])->find();
|
||||
$tes_store = TeaStore::where('id', $order['store_id'])->find();
|
||||
//查询是否使用优惠券
|
||||
if($order['user_coupon_id'] != 0){
|
||||
UserCoupon::where("id",$order['user_coupon_id'])->update(['status'=>0]);
|
||||
}
|
||||
//查询是否使用团购券
|
||||
if($order['group_coupon_id'] != 0){
|
||||
UserGroup::where("id",$order['group_coupon_id'])->update(['status'=>0]);
|
||||
$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;
|
||||
}
|
||||
StoreUserAccountLog::create([
|
||||
'sn'=>createSn("store_user_account_log","sn"),
|
||||
'change_object'=>$change_object,
|
||||
'change_type'=>5,
|
||||
'user_id'=>$order->user_id,
|
||||
'action'=>2,
|
||||
'amount' => $store_group['discount_price'],
|
||||
'before_amount'=>$tes_store['balance'],
|
||||
'after_amount' => round($tes_store['balance']-$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'])->dec('total_amount', $store_group['discount_price'])->update();
|
||||
TeaStore::where('id', $order['store_id'])->dec('balance', $store_group['discount_price'])->update();
|
||||
|
||||
}
|
||||
$tes_store = TeaStore::where('id', $order['store_id'])->find();
|
||||
if($order['pay_way'] == 3){
|
||||
$user = UserStoreMoney::where("user_id",$order['user_id'])
|
||||
->where("store_id",$order['store_id'])
|
||||
->find();
|
||||
$money = round($user['money']+$order['order_amount'],2);
|
||||
UserStoreMoney::where("user_id",$order['user_id'])
|
||||
->where("store_id",$order['store_id'])
|
||||
->update(['money'=>$money]);
|
||||
UserAccountLog::create([
|
||||
"sn"=>createSn("user_account_log","sn"),
|
||||
"user_id"=>$order['user_id'],
|
||||
"change_object"=>3,
|
||||
"change_type"=>8,
|
||||
"action"=>1,
|
||||
"amount"=>$order['order_amount'],
|
||||
"before_amount"=>$user['money'],
|
||||
"after_amount"=>$money,
|
||||
"source_sn"=>$order['order_sn'],
|
||||
"store_id"=>$order['id'],
|
||||
"remark"=>'取消订单退款',
|
||||
"create_time"=>time()
|
||||
]);
|
||||
StoreUserAccountLog::create([
|
||||
'sn'=>createSn("store_user_account_log","sn"),
|
||||
'change_object'=>3,
|
||||
'change_type'=>5,
|
||||
'action'=>2,
|
||||
'amount' => 0,
|
||||
'before_amount'=>$tes_store['balance'],
|
||||
'after_amount' => $tes_store['balance'],
|
||||
'user_id' => $order['user_id'],
|
||||
'source_sn' => $order['order_sn'],
|
||||
'store_id'=>$order['store_id'],
|
||||
'room_id'=>$order['room_id'],
|
||||
'remark'=>"包间预定退款",
|
||||
'create_time' => time()
|
||||
]);
|
||||
}elseif($order['pay_way'] == 1 || $order['pay_way'] == 2){
|
||||
$user = User::where("id",$order['user_id'])->find();
|
||||
if($order['pay_way'] == 2&&$order['order_amount']>0){
|
||||
$refundData = [
|
||||
'transaction_id'=>$order['transaction_id'],
|
||||
'refund_sn'=>$order['order_sn'],
|
||||
'total_amount'=>$order['order_amount'],
|
||||
'notify_url'=>FileService::getFileUrl('api/pay/notifyRefundMnp')
|
||||
// FileService::getFileUrl('api/pay/notifyMnp')
|
||||
];
|
||||
|
||||
$payService = (new WeChatPayService(1, $user_id ?? null));
|
||||
$result = $payService->refund($refundData);
|
||||
if($result['status'] !=='PROCESSING'){
|
||||
throw new \Exception('押金退款失败请联系客服');
|
||||
}
|
||||
$change_object = 2;
|
||||
$change_type = 10;
|
||||
$money = $user['user_money'];
|
||||
}else{
|
||||
$change_object = 1;
|
||||
$change_type = 9;
|
||||
$money = round($user['user_money']+$order['order_amount'],2);
|
||||
User::where("id",$order['user_id'])->update(['user_money'=>$money]);
|
||||
}
|
||||
UserAccountLog::create([
|
||||
"sn"=>createSn("user_account_log","sn"),
|
||||
"user_id"=>$order['user_id'],
|
||||
"change_object"=>$change_object,
|
||||
"change_type"=>$change_type,
|
||||
"action"=>1,
|
||||
"amount"=>$order['order_amount'],
|
||||
"before_amount"=>$user['user_money'],
|
||||
"after_amount"=>$money,
|
||||
"source_sn"=>$order['order_sn'],
|
||||
"store_id"=>$order['id'],
|
||||
"remark"=>'取消订单退款',
|
||||
"create_time"=>time()
|
||||
]);
|
||||
// 扣除管理端门店余额
|
||||
|
||||
$order_amount = $order['order_amount'];
|
||||
$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]);
|
||||
$change_object = 1;
|
||||
if($order['pay_way'] == 2){
|
||||
$change_object = 2;
|
||||
}
|
||||
StoreUserAccountLog::create([
|
||||
'sn'=>createSn("store_user_account_log","sn"),
|
||||
'change_object'=>$change_object,
|
||||
'change_type'=>5,
|
||||
'action'=>2,
|
||||
'amount' => $order_amount,
|
||||
'before_amount'=>$tes_store['balance'],
|
||||
'after_amount' => $balance,
|
||||
'user_id' => $order['user_id'],
|
||||
'source_sn' => $order['order_sn'],
|
||||
'store_id'=>$order['store_id'],
|
||||
'room_id'=>$order['room_id'],
|
||||
'remark'=>"包间预定退款",
|
||||
'create_time' => time()
|
||||
]);
|
||||
}
|
||||
$ids = explode(',',$order->id);
|
||||
$transfer = OrderStore::where('transfer_order_id',$order->id)->select();
|
||||
if($transfer->count() > 0){
|
||||
$orderIds = $transfer->column('id');
|
||||
$ids = array_merge($ids,$orderIds);
|
||||
}
|
||||
OrderStore::whereIn("id",$ids)->update(["order_status"=>3]);
|
||||
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 releaseOrderStore($data){
|
||||
$result = OrderStore::where("id",$data['id'])->find();
|
||||
if(!$result){
|
||||
throw new \Exception('订单不存在');
|
||||
}
|
||||
$room = TeaStoreRoom::where("id",$result['room_id'])->find();
|
||||
$transfer = OrderStore::where('transfer_order_id',$result->id)->select();
|
||||
$ids = explode(',',$result->id);
|
||||
|
||||
if($transfer->count() > 0){
|
||||
$orderIds = $transfer->column('id');
|
||||
$ids = array_merge($ids,$orderIds);
|
||||
}
|
||||
$room->status = 1;
|
||||
$iot = new IotService();
|
||||
$iot->controlDevice($room['device_id'],0);
|
||||
TeaStoreRoom::where('id',$room['id'])->update([
|
||||
'status'=>$room->status,
|
||||
'is_open'=>0
|
||||
]);
|
||||
OrderStore::whereIn("id",$ids)->update(["order_status"=>3,"is_release"=>1]);
|
||||
return [];
|
||||
}
|
||||
|
||||
public static function addOrder($post,$user_id){
|
||||
Db::startTrans();
|
||||
try {
|
||||
$hours = $post['hours'];
|
||||
$timeslot = $post['timeslot'];
|
||||
$day_time = $post['day_time'];
|
||||
$room_id = $post['room_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];
|
||||
|
||||
$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('所选时间段存在不可选项');
|
||||
}
|
||||
|
||||
$store_user = StoreUser::where('id',$user_id)->find();
|
||||
$user_msg = User::where("id", $store_user->bind_user_id)->find();
|
||||
if ($user_msg == null) {
|
||||
throw new \Exception('用户不存在');
|
||||
}
|
||||
$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' => $user_msg['id'],
|
||||
'day_title' => $post['day_time'],
|
||||
'day_time' => $post['day_time'],
|
||||
'start_time' => $start,
|
||||
'end_time' => $end,
|
||||
'timeslot' => $post['timeslot'],
|
||||
'hours' => $post['hours'],
|
||||
'group_coupon_id' => 0,
|
||||
'room_price' => $room_msg['price'],
|
||||
'room_all_price' => 0,
|
||||
'user_coupon_id' => 0,
|
||||
'coupon_price' => 0,
|
||||
'group_price' => 0,
|
||||
'member_price' => 0,
|
||||
'store_user_order'=>1,
|
||||
'pay_way'=>4,
|
||||
'order_amount' => 0,
|
||||
'store_income_price' => 0,
|
||||
'dtime' => date("Y-m-d H:i:s"),
|
||||
'order_status'=>1
|
||||
]);
|
||||
Db::commit();
|
||||
return [];
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static function renewOrder($data,$user_id){
|
||||
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");
|
||||
$insert = [
|
||||
'order_sn' => $order_sn,
|
||||
'user_id' => 0,
|
||||
'source_id' => $source_id,
|
||||
'timeslot' => implode(',', $extra),
|
||||
'dtime' => time(),
|
||||
'hour' => $hour,
|
||||
'pay_status' => 0,
|
||||
'price' => 0,
|
||||
'pay_way'=>4,
|
||||
'expire_time' => time() + 60 * 3
|
||||
];
|
||||
$renew_timeslot = $extra;
|
||||
$store_timeslot = explode(',', $order->timeslot);
|
||||
$timeList = array_merge($store_timeslot, $renew_timeslot);
|
||||
$end = end($timeList);
|
||||
|
||||
$transfer = OrderStore::where('transfer_order_id',$order->id)->select();
|
||||
$ids = explode(',',$order->id);
|
||||
|
||||
if($transfer->count() > 0){
|
||||
$orderIds = $transfer->column('id');
|
||||
$ids = array_merge($ids,$orderIds);
|
||||
}
|
||||
|
||||
$uporder = OrderStore::whereIn('id',$ids)->update([
|
||||
'end_time'=>$end,
|
||||
'timeslot'=> implode(',', $timeList),
|
||||
'renew_dtime'=>time(),
|
||||
'is_renewal'=>1,
|
||||
'renew_price'=>0,
|
||||
'renew_hour'=>$hour+$order->renew_hour
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return [
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
60
app/storeapi/logic/SmsLogic.php
Normal file
60
app/storeapi/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\storeapi\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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
572
app/storeapi/logic/StoreLogic.php
Normal file
572
app/storeapi/logic/StoreLogic.php
Normal file
@ -0,0 +1,572 @@
|
||||
<?php
|
||||
|
||||
namespace app\storeapi\logic;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\order\OrderGroup;
|
||||
use app\common\model\order\OrderStore;
|
||||
use app\common\model\teastore\TeaStore;
|
||||
use app\common\model\teastore\TeaStoreGroup;
|
||||
use app\common\model\teastore\TeaStoreQual;
|
||||
use app\common\model\teastore\TeaStoreRoom;
|
||||
use app\common\model\teastore\TeaStoreRoomLabel;
|
||||
use app\common\service\FileService;
|
||||
use app\common\model\teastore\TeaStoreRecharge;
|
||||
use think\facade\Db;
|
||||
|
||||
class StoreLogic extends BaseLogic
|
||||
{
|
||||
public static function getUserStoreList($userId){
|
||||
$lists = TeaStore::whereRaw("find_in_set(?, store_user_id)", [$userId])
|
||||
->where("del", 0)
|
||||
->order("default","desc")
|
||||
->select()
|
||||
->toarray();
|
||||
foreach($lists as $key=>$value){
|
||||
$lists[$key]['image'] = FileService::getImgUrl($value['image']);
|
||||
}
|
||||
$data = [
|
||||
'list' => $lists
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getUserStoreDetails($data){
|
||||
$d = "";
|
||||
if(isset($data['default'])){
|
||||
if($data['default']!=""&&$data['default']!=null){
|
||||
$d = "default = ".$data['default']."";
|
||||
}
|
||||
}
|
||||
$details = TeaStore::where("id",$data['id'])
|
||||
->where("del", 0)
|
||||
->where($d)
|
||||
->find();
|
||||
$image_arr = explode(",",$details['image_arr']);
|
||||
|
||||
foreach($image_arr as $key=>$value){
|
||||
// $image_arr[$key] = "https://chaz.oss-cn-shanghai.aliyuncs.com/".$value;
|
||||
$image_arr[$key] = FileService::getImgUrl($value);
|
||||
}
|
||||
$details['image_arr'] = $image_arr;
|
||||
$data = [
|
||||
'details' => $details
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function switchStore($data,$userId){
|
||||
TeaStore::where("store_user_id",$userId)
|
||||
->update(['default'=>0]);
|
||||
$result = TeaStore::where("id",$data['id'])
|
||||
->update(['default'=>1]);
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function editStore($params){
|
||||
Db::startTrans();
|
||||
try {
|
||||
$result = TeaStore::where("id",$params['id'])->find();
|
||||
if ($result==null) {
|
||||
throw new \Exception('暂无数据');
|
||||
}
|
||||
$id = $params['id'];
|
||||
unset($params['id']);
|
||||
if($params['video']!=""){
|
||||
foreach($params['video'] as $key=>$value){
|
||||
if($key == 0){
|
||||
$params['video'] = $value;
|
||||
}else{
|
||||
$params['video'].=",".$value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach($params['image_arr'] as $key=>$value){
|
||||
if($key == 0){
|
||||
$params['image_arr'] = $value;
|
||||
$params['image'] = $value;
|
||||
}else{
|
||||
$params['image_arr'].=",".$value;
|
||||
}
|
||||
}
|
||||
$params['update_dtime'] = date("Y-m-d H:i:s");
|
||||
$r = TeaStore::where("id",$id)->update($params);
|
||||
Db::commit();
|
||||
if($r){
|
||||
return true;
|
||||
}
|
||||
throw new \Exception('数据错误');
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public static function roomList($post){
|
||||
$count = TeaStoreRoom::where("store_id",$post['store_id'])->count();
|
||||
$lists = TeaStoreRoom::where("store_id",$post['store_id'])
|
||||
->page($post['page'], $post['size'])
|
||||
->order("id","desc")
|
||||
->select()
|
||||
->toarray();
|
||||
foreach($lists as $key=>$value){
|
||||
$lists[$key]['img'] = FileService::getImgUrl($value['img']);
|
||||
}
|
||||
$data = [
|
||||
'list' => $lists,
|
||||
'page' => $post['page'],
|
||||
'size' => $post['size'],
|
||||
'count' => $count,
|
||||
'more' => is_more($count, $post['page'], $post['size'])
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
public static function roomSelectList($post){
|
||||
$lists = TeaStoreRoom::where("store_id",$post['store_id'])
|
||||
->order("id","desc")
|
||||
->select()
|
||||
->toarray();
|
||||
$data = [
|
||||
'list' => $lists,
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
public static function editRoom($params){
|
||||
Db::startTrans();
|
||||
try {
|
||||
$result = TeaStoreRoom::where("id",$params['id'])->find();
|
||||
if ($result==null) {
|
||||
throw new \Exception('暂无数据');
|
||||
}
|
||||
$id = $params['id'];
|
||||
unset($params['id']);
|
||||
$params['update_dtime'] = date("Y-m-d H:i:s");
|
||||
$r = TeaStoreRoom::where("id",$id)->update($params);
|
||||
Db::commit();
|
||||
if($r){
|
||||
return true;
|
||||
}
|
||||
throw new \Exception('数据错误');
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public static function roomDetails($data){
|
||||
$room= TeaStoreRoom::where('id',$data['id'])
|
||||
->find();
|
||||
$room['img'] = FileService::getImgUrl($room['img']);
|
||||
$result = TeaStore::where('id',$room['store_id'])
|
||||
->find();
|
||||
$result['label'] = TeaStoreRoomLabel::where('id',"in",$room['label_id'])
|
||||
->select();
|
||||
$result['collect'] = 0;
|
||||
$image_arr = explode(",",$result['image_arr']);
|
||||
|
||||
$arr = explode(",", $room['img_arr'] ?? ''); // 使用 ?? 防止 $lists['image'] 为 null
|
||||
|
||||
$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;
|
||||
|
||||
foreach($image_arr as $key=>$value){
|
||||
$image_arr[$key] = FileService::getImgUrl($value);
|
||||
}
|
||||
$result['image_arr'] = $image_arr;
|
||||
$result['room'] = $room;
|
||||
$d['details'] = $result;
|
||||
return $d;
|
||||
}
|
||||
public static function roomLabelList($post){
|
||||
$lists = TeaStoreRoomLabel::where("store_id",$post['store_id'])
|
||||
->where("del",0)
|
||||
->where("status",1)
|
||||
->order("id","desc")
|
||||
->select()
|
||||
->toarray();
|
||||
$data = [
|
||||
'list' => $lists
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
public static function addLabel($params){
|
||||
Db::startTrans();
|
||||
try {
|
||||
$result = TeaStoreRoomLabel::where("store_id",$params['store_id'])
|
||||
->where("label_name",$params['label_name'])
|
||||
->where("del",0)
|
||||
->where("status",1)
|
||||
->find();
|
||||
if ($result != null) {
|
||||
throw new \Exception('标签已存在');
|
||||
}
|
||||
// 新增
|
||||
$r = TeaStoreRoomLabel::create([
|
||||
"store_id"=>$params['store_id'],
|
||||
"label_name"=>$params['label_name']
|
||||
]);
|
||||
Db::commit();
|
||||
if($r){
|
||||
return true;
|
||||
}
|
||||
throw new \Exception('操作失败');
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public static function delLabel($params){
|
||||
Db::startTrans();
|
||||
try {
|
||||
$result = TeaStoreRoomLabel::where("id",$params['id'])
|
||||
->where("del",0)
|
||||
->where("status",1)
|
||||
->find();
|
||||
if ($result == null) {
|
||||
throw new \Exception('暂无数据');
|
||||
}
|
||||
// 新增
|
||||
$r = TeaStoreRoomLabel::where("id",$params['id'])->update(['del'=>1]);
|
||||
Db::commit();
|
||||
if($r){
|
||||
return true;
|
||||
}
|
||||
throw new \Exception('操作失败');
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function addStoreOrder($post,$userId){
|
||||
Db::startTrans();
|
||||
try {
|
||||
$timeslot = "";
|
||||
foreach($post['timeslot'] as $key=>$value){
|
||||
$rs = OrderStore::whereRaw("FIND_IN_SET(?, timeslot)", [$value])
|
||||
->where("store_id",$post['store_id'])
|
||||
->where("order_status","in",[0,1,2])
|
||||
->find();
|
||||
if($rs != null){
|
||||
throw new \Exception('时间已被预约');
|
||||
}
|
||||
if($key == 0){
|
||||
$timeslot = strtotime($value);
|
||||
}else{
|
||||
$timeslot.=",".strtotime($value);
|
||||
}
|
||||
}
|
||||
// 茶室包间价格计算
|
||||
$room_msg = TeaStoreRoom::where("id",$post['id'])->find();
|
||||
$order = OrderStore::create([
|
||||
'order_sn'=>createSn("order_store","order_sn"),
|
||||
'store_id'=>$room_msg['store_id'],
|
||||
'room_id'=>$post['id'],
|
||||
'user_id'=>0,
|
||||
'timeslot'=>$timeslot,
|
||||
'day_time'=>$post['day_time'],
|
||||
'day_title'=>$post['day_title'],
|
||||
'start_time'=>strtotime($post['start_time']),
|
||||
'end_time'=>strtotime($post['end_time']),
|
||||
'hours'=>$post['hours'],
|
||||
'dtime'=>date("Y-m-d H:i:s"),
|
||||
'order_status'=>1,
|
||||
'pay_way'=>4,
|
||||
'pay_status'=>1
|
||||
]);
|
||||
Db::commit();
|
||||
return $order->id;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function renewDtime($data){
|
||||
Db::startTrans();
|
||||
try {
|
||||
$order = OrderStore::where("id",$data['id'])->find();
|
||||
if($order['order_status'] >= 3){
|
||||
throw new \Exception('订单已结束,无法续订');
|
||||
}
|
||||
$d['renew_hour'] = $data['renew_hour'];
|
||||
// $d['renew_price'] = round($data['renew_hour']*$order['room_price'],2);
|
||||
$arr = array(
|
||||
// 'start_time'=>$data['start_time'],
|
||||
// 'end_time'=>$data['end_time'],
|
||||
'renew_price'=>round($data['renew_hour']*$order['room_price'],2)
|
||||
);
|
||||
if($order['renew_dtime'] != null && $order['renew_dtime'] != ""){
|
||||
$d['renew_dtime'] = $order['renew_dtime']."-".json_encode($arr,true);
|
||||
}else{
|
||||
$d['renew_dtime'] = json_encode($arr,true);
|
||||
}
|
||||
|
||||
OrderStore::where("id",$data['id'])->update($d);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function rechargeLists($data){
|
||||
Db::startTrans();
|
||||
try {
|
||||
$store = TeaStore::where('id',$data['store_id'])->find();
|
||||
|
||||
$store_recharge = TeaStoreRecharge::where([
|
||||
'store_id'=>$data['store_id'],
|
||||
'del'=>0
|
||||
])->select()->toArray();
|
||||
|
||||
$data = [
|
||||
'recharge_state'=>$store->recharge_state,
|
||||
'recharge'=>$store_recharge
|
||||
];
|
||||
|
||||
Db::commit();
|
||||
return $data;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function addRecharge($data){
|
||||
Db::startTrans();
|
||||
try {
|
||||
$data = [
|
||||
'store_id'=>$data['store_id'],
|
||||
'title'=>$data['title'],
|
||||
'price'=>$data['price'],
|
||||
'gift_price'=>$data['gift_price'],
|
||||
'dtime'=>time()
|
||||
];
|
||||
TeaStoreRecharge::create($data);
|
||||
Db::commit();
|
||||
return true;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function editRecharge($data){
|
||||
Db::startTrans();
|
||||
try {
|
||||
$id = $data['id'];
|
||||
|
||||
$store_recharge = TeaStoreRecharge::where([
|
||||
'id'=>$data['id'],
|
||||
'del'=>0
|
||||
])->find();
|
||||
if(!$store_recharge){
|
||||
throw new \Exception('充值套餐不存在');
|
||||
}
|
||||
$data['uptime'] = time();
|
||||
unset($data['id']);
|
||||
TeaStoreRecharge::where('id',$id)->update($data);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function delRecharge($data){
|
||||
Db::startTrans();
|
||||
try {
|
||||
$id = $data['id'];
|
||||
|
||||
$store_recharge = TeaStoreRecharge::where([
|
||||
'id'=>$data['id'],
|
||||
'del'=>0
|
||||
])->find();
|
||||
if(!$store_recharge){
|
||||
throw new \Exception('充值套餐不存在');
|
||||
}
|
||||
|
||||
TeaStoreRecharge::where('id',$id)->update([
|
||||
'del'=>1,
|
||||
'uptime'=>time()
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function operateRecharge($data){
|
||||
Db::startTrans();
|
||||
try {
|
||||
$store = TeaStore::where([
|
||||
'id'=>$data['store_id'],
|
||||
'del'=>0
|
||||
])->find();
|
||||
if(!$store){
|
||||
throw new \Exception('门店数据错误');
|
||||
}
|
||||
$store->recharge_state = $data['state'];
|
||||
$store->update_time = date('Y-m-d H:i;s');
|
||||
$store->save();
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public static function storeOperationGroup($data){
|
||||
$order_status = "";
|
||||
if(isset($data['order_status'])){
|
||||
if($data['order_status']!=""&&$data['order_status']!=null){
|
||||
$order_status = "order_status = ".$data['order_status']."";
|
||||
}
|
||||
}
|
||||
$count = OrderGroup::where("store_id",$data['store_id'])->where($order_status)->count();
|
||||
$lists = OrderGroup::where("store_id",$data['store_id'])
|
||||
->where($order_status)
|
||||
->page($data['page'], $data['size'])
|
||||
->order("id","desc")
|
||||
->select()
|
||||
->toarray();
|
||||
foreach($lists as $key=>$value){
|
||||
$tea_store = TeaStoreGroup::where("id",$value['group_id'])->find();
|
||||
$tea_store['start_day'] = date("Y-m-d H:i:s",$tea_store['start_day']);
|
||||
$tea_store['end_day'] = date("Y-m-d H:i:s",$tea_store['end_day']);
|
||||
$tea_store['img'] = FileService::getImgUrl($tea_store['img']);
|
||||
$lists[$key]['store_name'] = TeaStore::where("id",$data['store_id'])->value("name");
|
||||
$lists[$key]['tea_store_group'] = $tea_store;
|
||||
}
|
||||
$result = [
|
||||
'list' => $lists,
|
||||
'page' => $data['page'],
|
||||
'size' => $data['size'],
|
||||
'count' => $count,
|
||||
'more' => is_more($count, $data['page'], $data['size'])
|
||||
];
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function storeOperationGroupDetails($data)
|
||||
{
|
||||
$details = OrderGroup::where("id",$data['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'] = "抖音核销";
|
||||
}
|
||||
$teaStoreGroup = TeaStoreGroup::where("id",$details['group_id'])
|
||||
->find();
|
||||
$room_msg = explode(",",$teaStoreGroup['room_id']);
|
||||
$arr = [];
|
||||
foreach($room_msg as $key=>$value){
|
||||
$arr[] = TeaStoreRoom::where("id",$value)->find();
|
||||
}
|
||||
$details['room_list'] = $arr;
|
||||
$teaStoreGroup['start_day'] = date("Y-m-d H:i:s",$teaStoreGroup['start_day']);
|
||||
$teaStoreGroup['end_day'] = date("Y-m-d H:i:s",$teaStoreGroup['end_day']);
|
||||
$teaStoreGroup['img'] = FileService::getImgUrl($teaStoreGroup['img']);
|
||||
$details['teaStoreGroup'] = $teaStoreGroup;
|
||||
$details['store_msg'] = TeaStore::where("id",$details['store_id'])->find();
|
||||
|
||||
return $details;
|
||||
}
|
||||
|
||||
public static function addQual($data){
|
||||
Db::startTrans();
|
||||
try {
|
||||
$result = TeaStoreQual::create([
|
||||
"name"=>$data['name'],
|
||||
"card"=>$data['card'],
|
||||
"legal_person"=>$data['legal_person'],
|
||||
"license_img"=>$data['license_img'],
|
||||
"effective"=>$data['effective'],
|
||||
"start_time"=>isset($data['start_time'])?strtotime($data['start_time']):0,
|
||||
"end_time"=>isset($data['end_time'])?strtotime($data['end_time']):0,
|
||||
"store_id"=>$data['store_id'],
|
||||
"dtime"=>time(),
|
||||
]);
|
||||
if(!$result){
|
||||
throw new \Exception('企业资质上传失败');
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
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']);
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function editQual($data){
|
||||
Db::startTrans();
|
||||
try {
|
||||
$id = $data['id'];
|
||||
unset($data['id']);
|
||||
$data['update_dtime'] = time();
|
||||
$data['start_time'] = strtotime($data['start_time']);
|
||||
$data['end_time'] = strtotime($data['end_time']);
|
||||
$result = TeaStoreQual::where("id",$id)->update($data);
|
||||
if(!$result){
|
||||
throw new \Exception('企业资质编辑失败');
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
283
app/storeapi/logic/StoreLoginLogic.php
Normal file
283
app/storeapi/logic/StoreLoginLogic.php
Normal file
@ -0,0 +1,283 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\storeapi\logic;
|
||||
|
||||
use app\common\cache\WebScanLoginCache;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\api\service\{StoreUserTokenService, 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\store\{StoreUser, UserAuth};
|
||||
use think\facade\{Db, Config};
|
||||
|
||||
/**
|
||||
* 登录逻辑
|
||||
* Class LoginLogic
|
||||
* @package app\api\logic
|
||||
*/
|
||||
class StoreLoginLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @notes 账号/手机号登录,手机号验证码
|
||||
* @param $params
|
||||
* @return array|false
|
||||
* @author 段誉
|
||||
* @date 2022/9/6 19:26
|
||||
*/
|
||||
public static function login($params)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
// 账号/手机号 密码登录
|
||||
$where = ['account|mobile' => $params['account']];
|
||||
if ($params['scene'] == LoginEnum::MOBILE_CAPTCHA) {
|
||||
//手机验证码登录
|
||||
$where = ['mobile' => $params['mobile']];
|
||||
}else{
|
||||
$passwordSalt = Config::get('project.unique_identification');
|
||||
$password = create_password($params['password'], $passwordSalt);
|
||||
$where = ['mobile' => $params['account'],'password'=>$password];
|
||||
}
|
||||
|
||||
$user = StoreUser::where($where)->findOrEmpty();
|
||||
|
||||
if ($user->isEmpty()) {
|
||||
throw new \Exception('账号密码不正确');
|
||||
}
|
||||
|
||||
//更新登录信息
|
||||
$user->login_time = time();
|
||||
$user->login_ip = request()->ip();
|
||||
$user->save();
|
||||
|
||||
//设置token
|
||||
$userInfo = StoreUserTokenService::setToken($user->id, $params['terminal']);
|
||||
|
||||
//返回登录信息
|
||||
$avatar = $user->avatar ?: Config::get('project.default_image.user_avatar');
|
||||
$avatar = FileService::getImgUrl($avatar);
|
||||
Db::commit();
|
||||
return [
|
||||
'nickname' => $userInfo['nickname'],
|
||||
'sn' => $userInfo['sn'],
|
||||
'mobile' => $userInfo['mobile'],
|
||||
'avatar' => $avatar,
|
||||
'token' => $userInfo['token'],
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 退出登录
|
||||
* @param $userInfo
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 17:56
|
||||
*/
|
||||
public static function logout($userInfo)
|
||||
{
|
||||
//token不存在,不注销
|
||||
if (!isset($userInfo['token'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//设置token过期
|
||||
return StoreUserTokenService::expireToken($userInfo['token']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取微信请求code的链接
|
||||
* @param string $url
|
||||
* @return string
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 19:47
|
||||
*/
|
||||
public static function codeUrl(string $url)
|
||||
{
|
||||
return (new WeChatOaService())->getCodeUrl($url);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @notes 更新登录信息
|
||||
* @param $userId
|
||||
* @throws \Exception
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 19:46
|
||||
*/
|
||||
public static function updateLoginInfo($userId)
|
||||
{
|
||||
$user = User::findOrEmpty($userId);
|
||||
if ($user->isEmpty()) {
|
||||
throw new \Exception('用户不存在');
|
||||
}
|
||||
|
||||
$time = time();
|
||||
$user->login_time = $time;
|
||||
$user->login_ip = request()->ip();
|
||||
$user->update_time = $time;
|
||||
$user->save();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 小程序端绑定微信
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 19:46
|
||||
*/
|
||||
public static function mnpAuthLogin(array $params)
|
||||
{
|
||||
try {
|
||||
//通过code获取微信openid
|
||||
$response = (new WeChatMnpService())->getMnpResByCode($params['code']);
|
||||
$response['user_id'] = $params['user_id'];
|
||||
$response['terminal'] = UserTerminalEnum::WECHAT_MMP;
|
||||
|
||||
return self::createAuth($response);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 公众号端绑定微信
|
||||
* @param array $params
|
||||
* @return bool
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 10:43
|
||||
*/
|
||||
public static function oaAuthLogin(array $params)
|
||||
{
|
||||
try {
|
||||
//通过code获取微信openid
|
||||
$response = (new WeChatOaService())->getOaResByCode($params['code']);
|
||||
$response['user_id'] = $params['user_id'];
|
||||
$response['terminal'] = UserTerminalEnum::WECHAT_OA;
|
||||
|
||||
return self::createAuth($response);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 生成授权记录
|
||||
* @param $response
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 10:43
|
||||
*/
|
||||
public static function createAuth($response)
|
||||
{
|
||||
//先检查openid是否有记录
|
||||
$isAuth = UserAuth::where('openid', '=', $response['openid'])->findOrEmpty();
|
||||
if (!$isAuth->isEmpty()) {
|
||||
throw new \Exception('该微信已被绑定');
|
||||
}
|
||||
|
||||
if (isset($response['unionid']) && !empty($response['unionid'])) {
|
||||
//在用unionid找记录,防止生成两个账号,同个unionid的问题
|
||||
$userAuth = UserAuth::where(['unionid' => $response['unionid']])
|
||||
->findOrEmpty();
|
||||
if (!$userAuth->isEmpty() && $userAuth->user_id != $response['user_id']) {
|
||||
throw new \Exception('该微信已被绑定');
|
||||
}
|
||||
}
|
||||
|
||||
//如果没有授权,直接生成一条微信授权记录
|
||||
UserAuth::create([
|
||||
'user_id' => $response['user_id'],
|
||||
'openid' => $response['openid'],
|
||||
'unionid' => $response['unionid'] ?? '',
|
||||
'terminal' => $response['terminal'],
|
||||
]);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 获取扫码登录地址
|
||||
* @return array|false
|
||||
* @author 段誉
|
||||
* @date 2022/10/20 18:23
|
||||
*/
|
||||
public static function getScanCode($redirectUri)
|
||||
{
|
||||
try {
|
||||
$config = WeChatConfigService::getOpConfig();
|
||||
$appId = $config['app_id'];
|
||||
$redirectUri = UrlEncode($redirectUri);
|
||||
|
||||
// 设置有效时间标记状态, 超时扫码不可登录
|
||||
$state = MD5(time().rand(10000, 99999));
|
||||
(new WebScanLoginCache())->setScanLoginState($state);
|
||||
|
||||
// 扫码地址
|
||||
$url = WeChatRequestService::getScanCodeUrl($appId, $redirectUri, $state);
|
||||
return ['url' => $url];
|
||||
|
||||
} catch (\Exception $e) {
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 更新用户信息
|
||||
* @param $params
|
||||
* @param $userId
|
||||
* @return User
|
||||
* @author 段誉
|
||||
* @date 2023/2/22 11:19
|
||||
*/
|
||||
public static function updateUser($params, $userId)
|
||||
{
|
||||
return User::where(['id' => $userId])->update([
|
||||
'nickname' => $params['nickname'],
|
||||
'avatar' => FileService::setFileUrl($params['avatar']),
|
||||
'is_new_user' => YesNoEnum::NO
|
||||
]);
|
||||
}
|
||||
}
|
||||
159
app/storeapi/logic/StoreUserLogic.php
Normal file
159
app/storeapi/logic/StoreUserLogic.php
Normal file
@ -0,0 +1,159 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\storeapi\logic;
|
||||
|
||||
|
||||
use app\common\{enum\notice\NoticeEnum,
|
||||
enum\user\UserTerminalEnum,
|
||||
enum\YesNoEnum,
|
||||
logic\BaseLogic,
|
||||
model\teamaster\TeamasterCollect,
|
||||
model\store\StoreUser,
|
||||
model\user\UserAddress,
|
||||
model\user\UserAuth,
|
||||
model\user\UserCoupon,
|
||||
model\user\UserMoneyLog,
|
||||
model\user\UserStoreMoney,
|
||||
service\FileService,
|
||||
service\sms\SmsDriver,
|
||||
service\wechat\WeChatMnpService};
|
||||
use think\facade\{Db, Config};
|
||||
/**
|
||||
* 会员逻辑层
|
||||
* Class UserLogic
|
||||
* @package app\shopapi\logic
|
||||
*/
|
||||
class StoreUserLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 个人中心
|
||||
* @param array $userInfo
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 18:04
|
||||
*/
|
||||
public static function center(array $userInfo): array
|
||||
{
|
||||
$user = StoreUser::where(['id' => $userInfo['user_id']])
|
||||
->field('id,sn,sex,account,nickname,real_name,avatar,mobile,create_time,is_new_user,user_money,password')
|
||||
->findOrEmpty();
|
||||
|
||||
if (in_array($userInfo['terminal'], [UserTerminalEnum::WECHAT_MMP, UserTerminalEnum::WECHAT_OA])) {
|
||||
$auth = UserAuth::where(['user_id' => $userInfo['user_id'], 'terminal' => $userInfo['terminal']])->find();
|
||||
$user['is_auth'] = $auth ? YesNoEnum::YES : YesNoEnum::NO;
|
||||
}
|
||||
|
||||
$user['has_password'] = !empty($user['password']);
|
||||
$user->hidden(['password']);
|
||||
return $user->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 个人信息
|
||||
* @param $userId
|
||||
* @return array
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 19:45
|
||||
*/
|
||||
public static function info(int $userId)
|
||||
{
|
||||
$user = User::where(['id' => $userId])
|
||||
->field('id,sn,sex,account,password,nickname,real_name,avatar,mobile,create_time,user_money,member')
|
||||
->findOrEmpty();
|
||||
$user['has_password'] = !empty($user['password']);
|
||||
$user['has_auth'] = self::hasWechatAuth($userId);
|
||||
$user['version'] = config('project.version');
|
||||
$user['collect_count'] = TeamasterCollect::where("user_id",$userId)
|
||||
->where("status",1)
|
||||
->count();
|
||||
$user['coupon_count'] = UserCoupon::where("user_id",$userId)
|
||||
->where("status",0)
|
||||
->count();
|
||||
$user->hidden(['password']);
|
||||
return $user->toArray();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置用户信息
|
||||
* @param int $userId
|
||||
* @param array $params
|
||||
* @return User|false
|
||||
* @author 段誉
|
||||
* @date 2022/9/21 16:53
|
||||
*/
|
||||
public static function setInfo(int $userId, array $params)
|
||||
{
|
||||
|
||||
try {
|
||||
if ($params['field'] == "avatar") {
|
||||
$params['value'] = FileService::setFileUrl($params['value']);
|
||||
}
|
||||
|
||||
return User::update([
|
||||
'id' => $userId,
|
||||
$params['field'] => $params['value']]
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
self::$error = $e->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @notes 重置登录密码
|
||||
* @param $params
|
||||
* @return bool
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 18:06
|
||||
*/
|
||||
public static function resetPassword(array $params)
|
||||
{
|
||||
// Db::startTrans();
|
||||
try {
|
||||
// 校验验证码
|
||||
$smsDriver = new SmsDriver();
|
||||
// if (!$smsDriver->verify($params['mobile'], $params['code'], NoticeEnum::FIND_LOGIN_PASSWORD_CAPTCHA)) {
|
||||
// throw new \Exception('验证码错误');
|
||||
// }
|
||||
|
||||
// 重置密码
|
||||
$passwordSalt = Config::get('project.unique_identification');
|
||||
$password = create_password($params['password'], $passwordSalt);
|
||||
if($params['password']!= $params['password_confirm']){
|
||||
throw new \Exception('两次输入不正确');
|
||||
}
|
||||
// 更新
|
||||
$upstore_user = StoreUser::where('mobile', $params['mobile'])->update([
|
||||
'password' => $password
|
||||
]);
|
||||
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
48
app/storeapi/logic/TrainingLogic.php
Normal file
48
app/storeapi/logic/TrainingLogic.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace app\storeapi\logic;
|
||||
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\Training;
|
||||
use app\common\service\FileService;
|
||||
|
||||
class TrainingLogic extends BaseLogic
|
||||
{
|
||||
public static function trainingList($post){
|
||||
$search = "";
|
||||
if(isset($post['search'])){
|
||||
if($post['search']!=""&&$post['search']!=null){
|
||||
$a = $post['search'];
|
||||
$search = "title like '%".$a."%'";
|
||||
}
|
||||
}
|
||||
$count = Training::where("type_id",2)->where($search)->count();
|
||||
$lists = Training::where("type_id",2)
|
||||
->where($search)
|
||||
->page($post['page'], $post['size'])
|
||||
->order("id","desc")
|
||||
->select()
|
||||
->toarray();
|
||||
foreach($lists as $key=>$value){
|
||||
$lists[$key]['image'] = FileService::getImgUrl($value['image']);
|
||||
$lists[$key]['dtime'] = date("Y-m-d H:i:s",$value['dtime']);
|
||||
}
|
||||
$data = [
|
||||
'list' => $lists,
|
||||
'page' => $post['page'],
|
||||
'size' => $post['size'],
|
||||
'count' => $count,
|
||||
'more' => is_more($count, $post['page'], $post['size'])
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function trainingDetails($data){
|
||||
$result = Training::where("id",$data['id'])
|
||||
->find();
|
||||
$result['image'] = FileService::getImgUrl($result['image']);
|
||||
$result['dtime'] = date("Y-m-d H:i:s",$result['dtime']);
|
||||
$d['details'] = $result;
|
||||
return $d;
|
||||
}
|
||||
}
|
||||
682
app/storeapi/logic/UserLogic.php
Normal file
682
app/storeapi/logic/UserLogic.php
Normal file
@ -0,0 +1,682 @@
|
||||
<?php
|
||||
|
||||
namespace app\storeapi\logic;
|
||||
|
||||
use app\common\enum\notice\NoticeEnum;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\order\OrderStore;
|
||||
use app\common\model\store\StoreMember;
|
||||
use app\common\model\store\StoreUser;
|
||||
use app\common\model\store\StoreUserAccountLog;
|
||||
use app\common\model\store\StoreUserBank;
|
||||
use app\common\model\store\StoreUserReflect;
|
||||
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\UserGroup;
|
||||
use app\common\model\user\UserMember;
|
||||
use app\common\model\user\UserStoreMoney;
|
||||
use app\common\service\FileService;
|
||||
use app\common\service\sms\SmsDriver;
|
||||
use app\common\model\order\OrderStoreRecharge;
|
||||
use app\common\model\order\OrderGroup;
|
||||
use think\facade\Config;
|
||||
use think\facade\Db;
|
||||
|
||||
class UserLogic extends BaseLogic
|
||||
{
|
||||
public static function info(int $userId)
|
||||
{
|
||||
$user = StoreUser::where(['id' => $userId])
|
||||
->field('id,sn,sex,account,password,nickname,real_name,avatar,mobile,create_time,user_money,total_amount,total_reflect_amount')
|
||||
->find();
|
||||
// $user['avatar'] = FileService::getFileUrl($user['avatar']);
|
||||
return $user->toArray();
|
||||
}
|
||||
|
||||
public static function updateUser($params, $userId)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
if(isset($params['band_mobile'])){
|
||||
$user = User::where("mobile",$params['band_mobile'])
|
||||
->where("is_disable",0)
|
||||
->find();
|
||||
if(!$user){
|
||||
throw new \Exception('客户端用户不存在');
|
||||
}
|
||||
$params['bind_user_id'] = $user->id;
|
||||
}
|
||||
StoreUser::where(['id' => $userId])->update($params);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function balanceLogList($post,$user_id){
|
||||
$t = "";
|
||||
if(isset($post['end_time'])){
|
||||
if($post['end_time']!=""&&$post['end_time']!=null){
|
||||
$end_time = strtotime($post['end_time']);
|
||||
$t = "create_time <= '".$end_time."'";
|
||||
}
|
||||
}
|
||||
$count = StoreUserAccountLog::where($t)->where("user_id",$user_id)->count();
|
||||
$lists = StoreUserAccountLog::where($t)
|
||||
->where("user_id",$user_id)
|
||||
->page($post['page'], $post['size'])
|
||||
->order("id","desc")
|
||||
->select()
|
||||
->toarray();
|
||||
foreach($lists as $key=>$value){
|
||||
$lists[$key]['mobile'] = "";
|
||||
$lists[$key]['reflect_status'] = "";
|
||||
if($value['change_type'] != 3){
|
||||
$order = OrderStore::where("order_sn",$value['source_sn'])->find();
|
||||
if($order!=null){
|
||||
$user = User::where("id",$order['user_id'])->find();
|
||||
$lists[$key]['mobile'] = $user['mobile'];
|
||||
}
|
||||
}else{
|
||||
$reflect_status = StoreUserReflect::where("order_sn",$value['source_sn'])->find();
|
||||
if($reflect_status!= null){
|
||||
$lists[$key]['reflect_status'] = $reflect_status['status'];
|
||||
}
|
||||
}
|
||||
}
|
||||
$data = [
|
||||
'list' => $lists,
|
||||
'page' => $post['page'],
|
||||
'size' => $post['size'],
|
||||
'count' => $count,
|
||||
'more' => is_more($count, $post['page'], $post['size'])
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
public static function balanceLogDetails($post){
|
||||
$details = StoreUserAccountLog::where("id",$post['id'])->find();
|
||||
if($details['change_type'] == 3){
|
||||
$order = StoreUserReflect::where("order_sn",$details['source_sn'])->find();
|
||||
if($order!=null){
|
||||
$bank = StoreUserBank::where("id",$order['bank_id'])->find();
|
||||
$order['bank_name'] = $bank['bank_name'];
|
||||
$order['bank_card'] = substr($bank['bank_card'], -4);
|
||||
$order['dtime'] = date("Y-m-d H:i:s",$order['dtime']);
|
||||
$order['update_dtime'] = date("Y-m-d H:i:s",$order['update_dtime']);
|
||||
}else{
|
||||
$order = [];
|
||||
$order['bank_name'] = "";
|
||||
$order['bank_card'] = "";
|
||||
}
|
||||
$details['order'] = $order;
|
||||
}else{
|
||||
$details['store'] = "";
|
||||
$store = TeaStore::where("id",$details['store_id'])->find();
|
||||
if($store!=null){
|
||||
$details['store'] = $store;
|
||||
}
|
||||
$details['room'] = "";
|
||||
$room = TeaStoreRoom::where("id",$details['room_id'])->find();
|
||||
if($room!=null){
|
||||
$details['room'] = $room;
|
||||
}
|
||||
|
||||
if($details['change_type'] == 9){
|
||||
$order = OrderStoreRecharge::where("order_sn",$details['source_sn'])->find();
|
||||
$order['pay_time'] = date('Y-m-d H:i');
|
||||
$order['dtime'] = $order['create_time'];
|
||||
}elseif($details['change_type'] == 4){
|
||||
$order = OrderGroup::where("order_sn",$details['source_sn'])->find();
|
||||
$details['room'] = ["title"=>'到店核销'];
|
||||
}else{
|
||||
|
||||
$order = OrderStore::where("order_sn",$details['source_sn'])->find();
|
||||
}
|
||||
|
||||
|
||||
|
||||
if($order!=null){
|
||||
$user = User::where("id",$order['user_id'])->find();
|
||||
$order['nickname'] = "";
|
||||
$order['mobile'] = "";
|
||||
if($user!=null){
|
||||
$order['nickname'] = $user['nickname'];
|
||||
$order['mobile'] = $user['mobile'];
|
||||
}
|
||||
$order['pay_way_title'] = "";
|
||||
if( $order['pay_way'] == 1){
|
||||
$order['pay_way_title'] = "余额支付";
|
||||
}
|
||||
if( $order['pay_way'] == 2){
|
||||
$order['pay_way_title'] = "微信支付";
|
||||
}
|
||||
if( $order['pay_way'] == 3){
|
||||
$order['pay_way_title'] = "门店余额支付";
|
||||
}
|
||||
if( $order['pay_way'] == 4){
|
||||
$order['pay_way_title'] = "管理员添加";
|
||||
}
|
||||
$order['group'] = [];
|
||||
$user_group = UserGroup::where("id",$order['group_coupon_id'])->find();
|
||||
if($details['change_type'] == 4){
|
||||
$user_group = UserGroup::where("order_id",$order['id'])->find();
|
||||
}
|
||||
|
||||
|
||||
if($user_group!=null){
|
||||
$order['group'] = TeaStoreGroup::where("id",$user_group['group_id'])->find();
|
||||
$order['group']['yanquan_dtime'] = $user_group['update_dtime'];
|
||||
$order['group']['qr_sn'] = $user_group['qr_sn'];
|
||||
$order['group']['yanquan_status'] = $user_group['status'];
|
||||
|
||||
}
|
||||
|
||||
}else{
|
||||
$order = [];
|
||||
$order['group'] = [];
|
||||
$order['pay_way_title'] = "";
|
||||
$order['nickname'] = "";
|
||||
$order['mobile'] = "";
|
||||
|
||||
}
|
||||
$details['order'] = $order;
|
||||
}
|
||||
$data = [
|
||||
'details' => $details
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
public static function checkMoney($data){
|
||||
$result = TeaStore::where("id",$data['store_id'])->find();
|
||||
$d['store_msg'] = $result;
|
||||
return $d;
|
||||
}
|
||||
|
||||
public static function addBank($params,$user_id){
|
||||
Db::startTrans();
|
||||
try {
|
||||
// 校验验证码
|
||||
$smsDriver = new SmsDriver();
|
||||
if (!$smsDriver->verify($params['mobile'], $params['code'], NoticeEnum::FIND_MOBILE_CAPTCHA)) {
|
||||
throw new \Exception('验证码错误');
|
||||
}
|
||||
// 新增
|
||||
StoreUserBank::create([
|
||||
"user_id"=>$user_id,
|
||||
"name"=>$params['name'],
|
||||
"bank_name"=>$params['bank_name'],
|
||||
"bank_card"=>$params['bank_card'],
|
||||
"bank_open_name"=>$params['bank_open_name'],
|
||||
"mobile"=>$params['mobile'],
|
||||
"dtime"=>time()
|
||||
]);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public static function checkBank($user_id){
|
||||
$lists = StoreUserBank::where("user_id",$user_id)
|
||||
->where("del",0)
|
||||
->where("status",1)
|
||||
->order("id","desc")
|
||||
->select()
|
||||
->toarray();
|
||||
foreach($lists as $key=>$value){
|
||||
$lists[$key]['bank_card'] = substr($value['bank_card'], -4);
|
||||
}
|
||||
$data = [
|
||||
'list' => $lists
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
public static function delBank($params){
|
||||
Db::startTrans();
|
||||
try {
|
||||
$result = StoreUserBank::where("id",$params['id'])->find();
|
||||
if ($result!=null) {
|
||||
throw new \Exception('暂无数据');
|
||||
}
|
||||
// 删除
|
||||
$r = StoreUserBank::where("id",$params['id'])->update(['del'=>1]);
|
||||
Db::commit();
|
||||
if($r){
|
||||
return true;
|
||||
}
|
||||
throw new \Exception('数据错误');
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public static function submitReflect($params,$user_id){
|
||||
Db::startTrans();
|
||||
try {
|
||||
// 查询是否余额充足
|
||||
$store = TeaStore::where("id",$params['store_id'])->where("del",0)->find();
|
||||
if($store == null){
|
||||
throw new \Exception('暂无数据');
|
||||
}
|
||||
if($store['balance'] < $params['amount']){
|
||||
throw new \Exception('余额不足');
|
||||
}
|
||||
// 新增提现记录
|
||||
$order_sn = createSn("store_user_reflect","order_sn");
|
||||
StoreUserReflect::create([
|
||||
"user_id"=>$user_id,
|
||||
"store_id"=>$params['store_id'],
|
||||
"order_sn"=>$order_sn,
|
||||
"bank_id"=>$params['bank_id'],
|
||||
"amount"=>$params['amount'],
|
||||
"dtime"=>time()
|
||||
]);
|
||||
// 计算扣除余额
|
||||
$user_money = round($store['balance']-$params['amount'],2);
|
||||
// 计算总提现金额
|
||||
$reflect_money = round($store['total_reflect_amount']+$params['amount'],2);
|
||||
$dt['balance'] = $user_money;
|
||||
$dt['total_reflect_amount'] = $reflect_money;
|
||||
$rs = TeaStore::where("id",$params['store_id'])->update($dt);
|
||||
if(!$rs){
|
||||
throw new \Exception('计算错误');
|
||||
}
|
||||
// 新增流水
|
||||
$data = [
|
||||
'sn' => createSn("store_user_account_log","sn"),
|
||||
'user_id' => $user_id,
|
||||
'change_type' => 3,
|
||||
'action' => 2,
|
||||
"amount"=>$params['amount'],
|
||||
'before_amount' => $dt['balance'],
|
||||
'after_amount' => $user_money,
|
||||
'source_sn' => $order_sn,
|
||||
'remark' => "用户提现"
|
||||
];
|
||||
$r = StoreUserAccountLog::create($data);
|
||||
Db::commit();
|
||||
if($r){
|
||||
return true;
|
||||
}
|
||||
throw new \Exception('提现失败');
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function checkStoreUserList($data){
|
||||
|
||||
$s = "";
|
||||
if(isset($data['search'])){
|
||||
if($data['search'] != ""){
|
||||
$b = $data['search'];
|
||||
$s = "b.mobile like '%".$b."%'";
|
||||
}
|
||||
}
|
||||
|
||||
$count = StoreMember::alias("a")
|
||||
->join("user b", "b.id = a.user_id", "left")
|
||||
->where("a.store_id",$data['store_id'])
|
||||
->where($s)
|
||||
->count();
|
||||
$lists = StoreMember::alias("a")
|
||||
->join("user b", "b.id = a.user_id", "left")
|
||||
->where("a.store_id",$data['store_id'])
|
||||
->where($s)
|
||||
->field("a.id,a.remark,b.mobile,b.member,a.user_id,b.nickname,b.avatar")
|
||||
->page($data['page'], $data['size'])
|
||||
->order("a.id","desc")
|
||||
->select()
|
||||
->toarray();
|
||||
|
||||
|
||||
$totalMoney = UserStoreMoney::where([
|
||||
'store_id' => $data['store_id'],
|
||||
'status' => 1 // 根据业务需要,可能只统计有效状态的
|
||||
])->sum('money');
|
||||
$money = 0;
|
||||
foreach($lists as $key=>$value){
|
||||
$lists[$key]['avatar'] =!empty($value['avatar']) ? FileService::getFileUrl($value['avatar']) : FileService::getFileUrl('uploads/images/20260106/20260106104232ef02b9224.png');
|
||||
$StoreMoney = UserStoreMoney::where([
|
||||
'store_id'=>$data['store_id'],
|
||||
'user_id'=>$value['user_id']
|
||||
])->find();
|
||||
|
||||
|
||||
if($value['member'] ==1){
|
||||
$UserMember = UserMember::where([
|
||||
'user_id'=>$value['user_id']
|
||||
])->find();
|
||||
if($UserMember){
|
||||
$lists[$key]['expiration_time'] = date('Y-m-d',$UserMember->expiration_time);
|
||||
}else{
|
||||
$lists[$key]['expiration_time'] = '--';
|
||||
}
|
||||
|
||||
}else{
|
||||
$lists[$key]['expiration_time'] = '--';
|
||||
}
|
||||
|
||||
if($StoreMoney){
|
||||
$lists[$key]['store_money'] = $StoreMoney->money;
|
||||
}else{
|
||||
$lists[$key]['store_money'] = $money;
|
||||
}
|
||||
|
||||
}
|
||||
$data = [
|
||||
'list' => $lists,
|
||||
'page' => $data['page'],
|
||||
'size' => $data['size'],
|
||||
'count' => $count,
|
||||
'more' => is_more($count, $data['page'], $data['size']),
|
||||
'totalMoney'=>$totalMoney
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function storeRechargeLists($data){
|
||||
|
||||
$yearMonth = $data['month'] ?? date('Y-m'); // 默认当前月
|
||||
|
||||
// 生成月份的起始和结束时间
|
||||
$startTimestamp = strtotime(date('Y-m-01 00:00:00', strtotime($yearMonth)));
|
||||
$endTimestamp = strtotime(date('Y-m-t 23:59:59', strtotime($yearMonth)));
|
||||
|
||||
$count = OrderStoreRecharge::alias("a")
|
||||
->join("user b", "b.id = a.user_id", "left")
|
||||
->join("tea_store_recharge c", "c.id = a.recharge_id", "left")
|
||||
->where("a.store_id",$data['store_id'])
|
||||
->where("a.pay_status",1)
|
||||
->whereBetween("a.pay_time", [$startTimestamp, $endTimestamp])
|
||||
->count();
|
||||
$lists = OrderStoreRecharge::alias("a")
|
||||
->join("user b", "b.id = a.user_id", "left")
|
||||
->join("tea_store_recharge c", "c.id = a.recharge_id", "left")
|
||||
->where("a.store_id",$data['store_id'])
|
||||
->where("a.pay_status",1)
|
||||
->whereBetween("a.pay_time", [$startTimestamp, $endTimestamp])
|
||||
->field("a.order_amount,a.recharge_price,a.gift_price,b.mobile,b.nickname,a.pay_time,c.title")
|
||||
->page($data['page'], $data['size'])
|
||||
->order("a.id","desc")
|
||||
->select()
|
||||
->toarray();
|
||||
|
||||
$total_recharge_price= OrderStoreRecharge::where([
|
||||
'store_id' => $data['store_id'],
|
||||
'pay_status' => 1 // 根据业务需要,可能只统计有效状态的
|
||||
|
||||
])->whereBetween("pay_time", [$startTimestamp, $endTimestamp])->sum('recharge_price');
|
||||
|
||||
$total_gift_price= OrderStoreRecharge::where([
|
||||
'store_id' => $data['store_id'],
|
||||
'pay_status' => 1 // 根据业务需要,可能只统计有效状态的
|
||||
|
||||
])->whereBetween("pay_time", [$startTimestamp, $endTimestamp])->sum('gift_price');
|
||||
|
||||
foreach ($lists as &$item){
|
||||
$item['pay_time'] = date('Y-m-d H:i');
|
||||
}
|
||||
|
||||
|
||||
$data = [
|
||||
'total_recharge_price'=>$total_recharge_price,
|
||||
'total_gift_price'=>$total_gift_price,
|
||||
'list' => $lists,
|
||||
'page' => $data['page'],
|
||||
'size' => $data['size'],
|
||||
'count' => $count,
|
||||
'more' => is_more($count, $data['page'], $data['size']),
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
public static function checkStoreUserDetails($params){
|
||||
// 门店用户基本信息
|
||||
$store_user_member = StoreMember::where("user_id",$params['user_id'])
|
||||
->where("store_id",$params['store_id'])
|
||||
->find();
|
||||
// 用户基本信息
|
||||
$user = User::where("id",$params['user_id'])->find();
|
||||
$user['remark'] = $store_user_member['remark'];
|
||||
$user['store_user_id'] = $store_user_member['id'];
|
||||
$user['create_time'] = date("Y-m-d",strtotime($user['create_time']));
|
||||
$user_member = UserMember::where('user_id',$params['user_id'])->find();
|
||||
// 会员到期时间
|
||||
$user['expiration_time'] = "";
|
||||
if($user_member){
|
||||
$user['expiration_time'] = date('Y-m-d H:i',$user_member['expiration_time']);
|
||||
|
||||
}
|
||||
$user_store_money = UserStoreMoney::where("user_id",$params['user_id'])->where("store_id",$params['store_id'])->find();
|
||||
if($user_store_money != null){
|
||||
$user['user_store_money'] = $user_store_money['money'];
|
||||
}
|
||||
// 门店用户总消费
|
||||
$user['order_amount'] = OrderStore::where("store_id",$params['store_id'])->where("user_id",$params['user_id'])->sum("order_amount");
|
||||
$data = [
|
||||
'user' => $user
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
public static function editStoreUserRemark($data){
|
||||
Db::startTrans();
|
||||
try {
|
||||
// 查询是否余额充足
|
||||
$StoreMemberUser = StoreMember::where("id",$data['id'])->where("status",1)->find();
|
||||
if($StoreMemberUser == null){
|
||||
throw new \Exception('暂无用户');
|
||||
}
|
||||
$StoreMemberUser::where("id",$data['id'])->update(['remark'=>$data['remark']]);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function checkStoreUserBuyList($data){
|
||||
$count = UserAccountLog::where("store_id",$data['store_id'])
|
||||
->where("user_id",$data['user_id'])
|
||||
->where("action",2)
|
||||
->count();
|
||||
$lists = UserAccountLog::where("store_id",$data['store_id'])
|
||||
->where("user_id",$data['user_id'])
|
||||
->where("action",2)
|
||||
->page($data['page'], $data['size'])
|
||||
->order("id","desc")
|
||||
->select()
|
||||
->toarray();
|
||||
foreach($lists as $key=>$value){
|
||||
$lists[$key]['pay_way_title'] = "";
|
||||
if( $value['change_object'] == 1){
|
||||
$lists[$key]['pay_way_title'] = "余额支付";
|
||||
}
|
||||
if( $value['change_object'] == 2){
|
||||
$lists[$key]['pay_way_title'] = "微信支付";
|
||||
}
|
||||
if( $value['change_object'] == 3){
|
||||
$lists[$key]['pay_way_title'] = "支付宝支付";
|
||||
}
|
||||
|
||||
$lists[$key]['store_name'] = TeaStore::where("id",$value['store_id'])->value("name");
|
||||
}
|
||||
$data = [
|
||||
'list' => $lists,
|
||||
'page' => $data['page'],
|
||||
'size' => $data['size'],
|
||||
'count' => $count,
|
||||
'more' => is_more($count, $data['page'], $data['size'])
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function checkStoreAccountList($data){
|
||||
$times = date("Y-m");
|
||||
list($year, $month) = explode('-', $times);
|
||||
$startTimestamp = strtotime($year . '-' . $month . '-01 00:00:00');
|
||||
$endTimestamp = strtotime(date('Y-m-t 23:59:59', $startTimestamp));
|
||||
if(isset($data['times'])){
|
||||
if($data['times']!=""&&$data['times']!=null){
|
||||
list($year, $month) = explode('-', $data['times']);
|
||||
// 转换为日期范围
|
||||
$startTimestamp = strtotime($year . '-' . $month . '-01 00:00:00');
|
||||
$endTimestamp = strtotime(date('Y-m-t 23:59:59', $startTimestamp));
|
||||
}
|
||||
}
|
||||
$count = StoreUserAccountLog::where("store_id",$data['store_id'])
|
||||
->where("store_id",$data['store_id'])
|
||||
->whereBetween('create_time', [$startTimestamp, $endTimestamp])
|
||||
|
||||
->count();
|
||||
$all_price = StoreUserAccountLog::where("store_id",$data['store_id'])
|
||||
->where("store_id",$data['store_id'])
|
||||
->whereBetween('create_time', [$startTimestamp, $endTimestamp])
|
||||
->where("action",1)
|
||||
->sum("amount");
|
||||
$all_action_price = StoreUserAccountLog::where("store_id",$data['store_id'])
|
||||
->where("store_id",$data['store_id'])
|
||||
->whereBetween('create_time', [$startTimestamp, $endTimestamp])
|
||||
->where("action",2)
|
||||
->sum("amount");
|
||||
$lists = StoreUserAccountLog::where("store_id",$data['store_id'])
|
||||
->where("store_id",$data['store_id'])
|
||||
->whereBetween('create_time', [$startTimestamp, $endTimestamp])
|
||||
|
||||
->page($data['page'], $data['size'])
|
||||
->order("id","desc")
|
||||
->select()
|
||||
->toarray();
|
||||
foreach($lists as $key=>$value){
|
||||
$lists[$key]['store'] = TeaStore::where("id",$value['store_id'])->find();
|
||||
if($value['change_type'] == 4){
|
||||
$lists[$key]['room'] = ["title"=>'到店核销'];
|
||||
}else{
|
||||
$lists[$key]['room'] = TeaStoreRoom::where("id",$value['room_id'])->find();
|
||||
}
|
||||
|
||||
$lists[$key]['order'] = "";
|
||||
$lists[$key]['group'] = "";
|
||||
if($value['action'] == 1){
|
||||
$order = OrderStore::where("order_sn",$value['source_sn'])->find();
|
||||
$lists[$key]['order'] = $order;
|
||||
if($order!=null){
|
||||
$order_group = UserGroup::where("id",$order['group_coupon_id'])->find();
|
||||
if($order_group!=null){
|
||||
$lists[$key]['group'] = TeaStoreGroup::where("id",$order_group['group_id'])->find();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$data = [
|
||||
'list' => $lists,
|
||||
'page' => $data['page'],
|
||||
'size' => $data['size'],
|
||||
"all_price"=>round($all_price-$all_action_price,2),
|
||||
'count' => $count,
|
||||
'more' => is_more($count, $data['page'], $data['size'])
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function checkMoth($data,$user_id){
|
||||
// 本月收入
|
||||
$times = date("Y-m");
|
||||
list($year, $month) = explode('-', $times);
|
||||
$startTimestamp = strtotime($year . '-' . $month . '-01 00:00:00');
|
||||
$endTimestamp = strtotime(date('Y-m-t 23:59:59', $startTimestamp));
|
||||
$result['month'] = StoreUserAccountLog::where("store_id",$data['store_id'])
|
||||
->whereBetween('create_time', [$startTimestamp, $endTimestamp])
|
||||
->where("action",1)
|
||||
->sum("amount");
|
||||
$result['refund_month'] = StoreUserAccountLog::where("store_id",$data['store_id'])
|
||||
->whereBetween('create_time', [$startTimestamp, $endTimestamp])
|
||||
->where("action",2)
|
||||
->sum("amount");
|
||||
$result['month'] = $result['month']-$result['refund_month'];
|
||||
// 今日收入
|
||||
$today = date('Y-m-d');
|
||||
$startTime = strtotime($today . ' 00:00:00');
|
||||
$endTime = strtotime($today . ' 23:59:59');
|
||||
$result['today_price'] = StoreUserAccountLog::where("store_id",$data['store_id'])
|
||||
->whereBetween('create_time', [$startTime, $endTime])
|
||||
// ->where("change_type","in","1,2")
|
||||
->where("action",1)
|
||||
->sum("amount");
|
||||
|
||||
$result['refund_today_price'] = StoreUserAccountLog::where("store_id",$data['store_id'])
|
||||
->whereBetween('create_time', [$startTime, $endTime])
|
||||
// ->where("change_type","in","1,2")
|
||||
->where("action",2)
|
||||
->sum("amount");
|
||||
|
||||
$result['today_price'] = $result['today_price'] -$result['refund_today_price'];
|
||||
// 今日验券
|
||||
$result['yan_price'] = StoreUserAccountLog::where("store_id",$data['store_id'])
|
||||
->whereBetween('create_time', [$startTime, $endTime])
|
||||
->where("change_object",4)
|
||||
->where("action",1)
|
||||
->sum("amount");
|
||||
|
||||
$result['refund_yan_price'] = StoreUserAccountLog::where("store_id",$data['store_id'])
|
||||
->whereBetween('create_time', [$startTime, $endTime])
|
||||
->whereIn("change_object",[0,4])
|
||||
->where("action",2)
|
||||
->sum("amount");
|
||||
|
||||
$result['yan_price'] = $result['yan_price'] -$result['refund_yan_price'];
|
||||
|
||||
// 昨日收入
|
||||
$yesterday = date('Y-m-d', strtotime('-1 day'));
|
||||
// 计算时间戳范围
|
||||
$startTime = strtotime($yesterday . ' 00:00:00');
|
||||
$endTime = strtotime($yesterday . ' 23:59:59');
|
||||
$result['yesterday_price'] = StoreUserAccountLog::where("store_id",$data['store_id'])
|
||||
->whereBetween('create_time', [$startTime, $endTime])
|
||||
->where("change_type","in","1,2")
|
||||
->where("action",1)
|
||||
->sum("amount");
|
||||
|
||||
$result['refund_yesterday_price'] = StoreUserAccountLog::where("store_id",$data['store_id'])
|
||||
->whereBetween('create_time', [$startTime, $endTime])
|
||||
->where("change_type","in","1,2")
|
||||
->where("action",2)
|
||||
->sum("amount");
|
||||
$result['yesterday_price'] = $result['yesterday_price'] -$result['refund_yesterday_price'];
|
||||
|
||||
// 昨日验券
|
||||
$result['yesterday_yan_price'] = StoreUserAccountLog::where("store_id",$data['store_id'])
|
||||
->whereBetween('create_time', [$startTime, $endTime])
|
||||
->where("change_type",4)
|
||||
->where("action",1)
|
||||
->sum("amount");
|
||||
|
||||
$result['refund_yesterday_yan_price'] = StoreUserAccountLog::where("store_id",$data['store_id'])
|
||||
->whereBetween('create_time', [$startTime, $endTime])
|
||||
->where("change_type",4)
|
||||
->where("action",1)
|
||||
->sum("amount");
|
||||
$result['yesterday_yan_price'] = $result['yesterday_yan_price']-$result['refund_yesterday_yan_price'];
|
||||
|
||||
$d = [
|
||||
"result"=>$result
|
||||
];
|
||||
return $d;
|
||||
}
|
||||
}
|
||||
120
app/storeapi/service/StoreUserTokenService.php
Normal file
120
app/storeapi/service/StoreUserTokenService.php
Normal file
@ -0,0 +1,120 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
|
||||
namespace app\storeapi\service;
|
||||
|
||||
use app\common\cache\StoreUserTokenCache;
|
||||
use app\common\model\store\StoreUserSession;
|
||||
use think\facade\Config;
|
||||
|
||||
class StoreUserTokenService
|
||||
{
|
||||
|
||||
/**
|
||||
* @notes 设置或更新用户token
|
||||
* @param $userId
|
||||
* @param $terminal
|
||||
* @return array|false|mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 10:10
|
||||
*/
|
||||
public static function setToken($userId, $terminal)
|
||||
{
|
||||
$time = time();
|
||||
$userSession = StoreUserSession::where([['user_id', '=', $userId], ['terminal', '=', $terminal]])->find();
|
||||
|
||||
//获取token延长过期的时间
|
||||
$expireTime = $time + Config::get('project.user_token.expire_duration');
|
||||
$userTokenCache = new StoreUserTokenCache();
|
||||
|
||||
//token处理
|
||||
if ($userSession) {
|
||||
//清空缓存
|
||||
$userTokenCache->deleteUserInfo($userSession->token);
|
||||
//重新获取token
|
||||
$userSession->token = create_token($userId);
|
||||
$userSession->expire_time = $expireTime;
|
||||
$userSession->update_time = $time;
|
||||
$userSession->save();
|
||||
} else {
|
||||
//找不到在该终端的token记录,创建token记录
|
||||
$userSession = StoreUserSession::create([
|
||||
'user_id' => $userId,
|
||||
'terminal' => $terminal,
|
||||
'token' => create_token($userId),
|
||||
'expire_time' => $expireTime
|
||||
]);
|
||||
}
|
||||
|
||||
return $userTokenCache->setUserInfo($userSession->token);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 延长token过期时间
|
||||
* @param $token
|
||||
* @return array|false|mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 10:10
|
||||
*/
|
||||
public static function overtimeToken($token)
|
||||
{
|
||||
$time = time();
|
||||
$userSession = StoreUserSession::where('token', '=', $token)->find();
|
||||
if ($userSession->isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
//延长token过期时间
|
||||
$userSession->expire_time = $time + Config::get('project.user_token.expire_duration');
|
||||
$userSession->update_time = $time;
|
||||
$userSession->save();
|
||||
|
||||
return (new StoreUserTokenCache())->setUserInfo($userSession->token);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 设置token为过期
|
||||
* @param $token
|
||||
* @return bool
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 10:10
|
||||
*/
|
||||
public static function expireToken($token)
|
||||
{
|
||||
$userSession = StoreUserSession::where('token', '=', $token)
|
||||
->find();
|
||||
if (empty($userSession)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$time = time();
|
||||
$userSession->expire_time = $time;
|
||||
$userSession->update_time = $time;
|
||||
$userSession->save();
|
||||
|
||||
return (new StoreUserTokenCache())->deleteUserInfo($token);
|
||||
}
|
||||
|
||||
}
|
||||
56
app/storeapi/validate/DeviceValidate.php
Normal file
56
app/storeapi/validate/DeviceValidate.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace app\storeapi\validate;
|
||||
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
class DeviceValidate extends BaseValidate
|
||||
{
|
||||
protected $rule = [
|
||||
'store_id' => 'require',
|
||||
'device_id' => 'require',
|
||||
'state'=>'require',
|
||||
'type'=>'require',
|
||||
'lock_no'=>'require',
|
||||
'room_id'=>'require',
|
||||
|
||||
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'store_id.require' => '请选择门店',
|
||||
'device_id.require' => '请配置设备空开id错误',
|
||||
'state.require' => '缺少开关状态',
|
||||
'type.require' => '缺少门禁类型',
|
||||
'lock_no.require' => '请配置门锁编号',
|
||||
'room_id.require' => '包间id不能为空',
|
||||
];
|
||||
|
||||
/**
|
||||
* @notes 设备列表
|
||||
* @return PasswordValidate
|
||||
*/
|
||||
public function sceneDeviceList()
|
||||
{
|
||||
return $this->only(['store_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 控制空开设备
|
||||
* @return PasswordValidate
|
||||
*/
|
||||
public function sceneDeviceOff_On()
|
||||
{
|
||||
return $this->only(['device_id','state','room_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 控制门禁设备
|
||||
* @return PasswordValidate
|
||||
*/
|
||||
public function sceneLockOff_On()
|
||||
{
|
||||
return $this->only(['type','lock_no']);
|
||||
}
|
||||
|
||||
}
|
||||
116
app/storeapi/validate/GroupValidate.php
Normal file
116
app/storeapi/validate/GroupValidate.php
Normal file
@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace app\storeapi\validate;
|
||||
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
class GroupValidate extends BaseValidate
|
||||
{
|
||||
|
||||
protected $rule = [
|
||||
'group_id' => 'require',
|
||||
'store_id' => 'require',
|
||||
'title'=>'require',
|
||||
'img'=>'require',
|
||||
'hour'=>'require',
|
||||
'description'=>'require',
|
||||
'introduce'=>'require',
|
||||
'pl_number'=>'require',
|
||||
// 'rests_introduce'=>'require',
|
||||
'sold'=>'require',
|
||||
'discount_price'=>'require',
|
||||
'price'=>'require',
|
||||
'returd_details'=>'require',
|
||||
'room_id'=>'require',
|
||||
'status'=>'require',
|
||||
'type'=>'require',
|
||||
// 'sku_id'=>'require',
|
||||
'sn_type'=>'require',
|
||||
'qr_sn'=>'require',
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'group_id.require' => '套餐id不能为空',
|
||||
'store_id.require' => '缺少门店',
|
||||
'title.require' => '缺少套餐名称',
|
||||
'hour.require' => '缺少套餐适用时长',
|
||||
'img.require' => '请上传图片',
|
||||
'description.require' => '请填写环境描述',
|
||||
'introduce.require' => '请填写套餐介绍',
|
||||
'pl_number.require' => '请填写适用人数',
|
||||
// 'rests_introduce.require' => '请填写其他说明',
|
||||
'sold.require' => '请设置库存',
|
||||
'discount_price.require' => '请设置真实价格',
|
||||
'price.require' => '请填写展示价格',
|
||||
'returd_details.require' => '请添加退改说明',
|
||||
'room_id.require' => '请设置适用包间',
|
||||
'status.require' => '请设置套餐状态',
|
||||
'type.require' => '请选择套餐类型',
|
||||
// 'sku_id.require' => '缺少sku_Id',
|
||||
'qr_sn.require' => '请输入或扫描券码',
|
||||
];
|
||||
|
||||
/**
|
||||
* @notes 设备列表
|
||||
* @return PasswordValidate
|
||||
*/
|
||||
public function sceneAddGroup()
|
||||
{
|
||||
return $this->only(['store_id','title','hour','img','description','introduce','pl_number','sold','discount_price','price','returd_details','room_id','status','type','sku_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 编辑套餐
|
||||
* @return PasswordValidate
|
||||
*/
|
||||
public function sceneEditGroup()
|
||||
{
|
||||
return $this->only(['store_id','title','hour','img','description','introduce','pl_number','sold','discount_price','price','returd_details','room_id','status','type','sku_id','group_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 套餐列表
|
||||
* @return PasswordValidate
|
||||
*/
|
||||
public function sceneGroupLists()
|
||||
{
|
||||
return $this->only(['status','store_id']);
|
||||
}
|
||||
/**
|
||||
* @notes 删除套餐
|
||||
* @return PasswordValidate
|
||||
*/
|
||||
public function sceneDelGroup()
|
||||
{
|
||||
return $this->only(['group_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 上下架套餐
|
||||
* @return PasswordValidate
|
||||
*/
|
||||
public function sceneOperateGroup()
|
||||
{
|
||||
return $this->only(['group_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 套餐详情
|
||||
* @return PasswordValidate
|
||||
*/
|
||||
public function sceneGroupDetails()
|
||||
{
|
||||
return $this->only(['group_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 套餐详情
|
||||
* @return PasswordValidate
|
||||
*/
|
||||
public function sceneCancelCode()
|
||||
{
|
||||
return $this->only(['store_id','qr_sn']);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
161
app/storeapi/validate/LoginAccountValidate.php
Normal file
161
app/storeapi/validate/LoginAccountValidate.php
Normal file
@ -0,0 +1,161 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\storeapi\validate;
|
||||
|
||||
use app\common\cache\UserAccountSafeCache;
|
||||
use app\common\enum\LoginEnum;
|
||||
use app\common\enum\notice\NoticeEnum;
|
||||
use app\common\enum\user\UserTerminalEnum;
|
||||
use app\common\enum\YesNoEnum;
|
||||
use app\common\service\ConfigService;
|
||||
use app\common\service\sms\SmsDriver;
|
||||
use app\common\validate\BaseValidate;
|
||||
use app\common\model\user\User;
|
||||
use think\facade\Config;
|
||||
|
||||
/**
|
||||
* 账号密码登录校验
|
||||
* Class LoginValidate
|
||||
* @package app\api\validate
|
||||
*/
|
||||
class LoginAccountValidate extends BaseValidate
|
||||
{
|
||||
|
||||
protected $rule = [
|
||||
'terminal' => 'require|in:' . UserTerminalEnum::WECHAT_MMP . ',' . UserTerminalEnum::WECHAT_OA . ','
|
||||
. UserTerminalEnum::H5 . ',' . UserTerminalEnum::PC . ',' . UserTerminalEnum::IOS .
|
||||
',' . UserTerminalEnum::ANDROID,
|
||||
// 'scene' => 'require|in:' . LoginEnum::ACCOUNT_PASSWORD . ',' . LoginEnum::MOBILE_CAPTCHA . '|checkConfig',
|
||||
'account' => 'require',
|
||||
];
|
||||
|
||||
|
||||
protected $message = [
|
||||
'terminal.require' => '终端参数缺失',
|
||||
'terminal.in' => '终端参数状态值不正确',
|
||||
'scene.require' => '场景不能为空',
|
||||
// 'scene.in' => '场景值错误',
|
||||
'account.require' => '请输入账号',
|
||||
'password.require' => '请输入密码',
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 登录场景相关校验
|
||||
* @param $scene
|
||||
* @param $rule
|
||||
* @param $data
|
||||
* @return bool|string
|
||||
* @author 段誉
|
||||
* @date 2022/9/15 14:37
|
||||
*/
|
||||
public function checkConfig($scene, $rule, $data)
|
||||
{
|
||||
$config = ConfigService::get('login', 'login_way');
|
||||
if (!in_array($scene, $config)) {
|
||||
return '不支持的登录方式';
|
||||
}
|
||||
|
||||
// 账号密码登录
|
||||
if (LoginEnum::ACCOUNT_PASSWORD == $scene) {
|
||||
if (!isset($data['password'])) {
|
||||
return '请输入密码';
|
||||
}
|
||||
return $this->checkPassword($data['password'], [], $data);
|
||||
}
|
||||
|
||||
// 手机验证码登录
|
||||
if (LoginEnum::MOBILE_CAPTCHA == $scene) {
|
||||
if (!isset($data['code'])) {
|
||||
return '请输入手机验证码';
|
||||
}
|
||||
return $this->checkCode($data['code'], [], $data);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 登录密码校验
|
||||
* @param $password
|
||||
* @param $other
|
||||
* @param $data
|
||||
* @return bool|string
|
||||
* @author 段誉
|
||||
* @date 2022/9/15 14:39
|
||||
*/
|
||||
public function checkPassword($password, $other, $data)
|
||||
{
|
||||
//账号安全机制,连续输错后锁定,防止账号密码暴力破解
|
||||
$userAccountSafeCache = new UserAccountSafeCache();
|
||||
if (!$userAccountSafeCache->isSafe()) {
|
||||
return '密码连续' . $userAccountSafeCache->count . '次输入错误,请' . $userAccountSafeCache->minute . '分钟后重试';
|
||||
}
|
||||
|
||||
$where = [];
|
||||
if ($data['scene'] == LoginEnum::ACCOUNT_PASSWORD) {
|
||||
// 手机号密码登录
|
||||
$where = ['account|mobile' => $data['account']];
|
||||
}
|
||||
|
||||
$userInfo = User::where($where)
|
||||
->field(['password,is_disable'])
|
||||
->findOrEmpty();
|
||||
|
||||
if ($userInfo->isEmpty()) {
|
||||
return '用户不存在';
|
||||
}
|
||||
|
||||
if ($userInfo['is_disable'] === YesNoEnum::YES) {
|
||||
return '用户已禁用';
|
||||
}
|
||||
|
||||
if (empty($userInfo['password'])) {
|
||||
$userAccountSafeCache->record();
|
||||
return '用户不存在';
|
||||
}
|
||||
|
||||
$passwordSalt = Config::get('project.unique_identification');
|
||||
if ($userInfo['password'] !== create_password($password, $passwordSalt)) {
|
||||
$userAccountSafeCache->record();
|
||||
return '密码错误';
|
||||
}
|
||||
|
||||
$userAccountSafeCache->relieve();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 校验验证码
|
||||
* @param $code
|
||||
* @param $rule
|
||||
* @param $data
|
||||
* @return bool|string
|
||||
* @author Tab
|
||||
* @date 2021/8/25 15:43
|
||||
*/
|
||||
public function checkCode($code, $rule, $data)
|
||||
{
|
||||
$smsDriver = new SmsDriver();
|
||||
$result = $smsDriver->verify($data['account'], $code, NoticeEnum::LOGIN_CAPTCHA);
|
||||
if ($result) {
|
||||
return true;
|
||||
}
|
||||
return '验证码错误';
|
||||
}
|
||||
}
|
||||
69
app/storeapi/validate/PasswordValidate.php
Normal file
69
app/storeapi/validate/PasswordValidate.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\storeapi\validate;
|
||||
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
/**
|
||||
* 密码校验
|
||||
* Class PasswordValidate
|
||||
* @package app\api\validate
|
||||
*/
|
||||
class PasswordValidate extends BaseValidate
|
||||
{
|
||||
|
||||
protected $rule = [
|
||||
'mobile' => 'require|mobile',
|
||||
'code' => 'require',
|
||||
'password' => 'require|length:6,20|alphaNum',
|
||||
'password_confirm' => 'require|confirm',
|
||||
];
|
||||
|
||||
|
||||
protected $message = [
|
||||
'mobile.require' => '请输入手机号',
|
||||
'mobile.mobile' => '请输入正确手机号',
|
||||
'code.require' => '请填写验证码',
|
||||
'password.require' => '请输入密码',
|
||||
'password.length' => '密码须在6-25位之间',
|
||||
'password.alphaNum' => '密码须为字母数字组合',
|
||||
'password_confirm.require' => '请确认密码',
|
||||
'password_confirm.confirm' => '两次输入的密码不一致'
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 重置登录密码
|
||||
* @return PasswordValidate
|
||||
* @author 段誉
|
||||
* @date 2022/9/16 18:11
|
||||
*/
|
||||
public function sceneResetPassword()
|
||||
{
|
||||
return $this->only(['mobile', 'code', 'password', 'password_confirm']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 修改密码场景
|
||||
* @return PasswordValidate
|
||||
* @author 段誉
|
||||
* @date 2022/9/20 19:14
|
||||
*/
|
||||
public function sceneChangePassword()
|
||||
{
|
||||
return $this->only(['password', 'password_confirm']);
|
||||
}
|
||||
|
||||
}
|
||||
39
app/storeapi/validate/SendSmsValidate.php
Normal file
39
app/storeapi/validate/SendSmsValidate.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||||
// +----------------------------------------------------------------------
|
||||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||||
// | 开源版本可自由商用,可去除界面版权logo
|
||||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||||
// | 访问官网:https://www.likeadmin.cn
|
||||
// | likeadmin团队 版权所有 拥有最终解释权
|
||||
// +----------------------------------------------------------------------
|
||||
// | author: likeadminTeam
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\storeapi\validate;
|
||||
|
||||
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
|
||||
/**
|
||||
* 短信验证
|
||||
* Class SmsValidate
|
||||
* @package app\api\validate
|
||||
*/
|
||||
class SendSmsValidate extends BaseValidate
|
||||
{
|
||||
|
||||
protected $rule = [
|
||||
'mobile' => 'require|mobile',
|
||||
'scene' => 'require',
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'mobile.require' => '请输入手机号',
|
||||
'mobile.mobile' => '请输入正确手机号',
|
||||
'scene.require' => '请输入场景值',
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user