提交其他文件

This commit is contained in:
2026-03-11 18:24:59 +08:00
parent 4b490670f1
commit f0d7f60fd5
1377 changed files with 73456 additions and 0 deletions

View 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;
}
}
}