169 lines
5.4 KiB
PHP
169 lines
5.4 KiB
PHP
<?php
|
||
|
||
namespace app\api\logic;
|
||
|
||
use app\common\logic\BaseLogic;
|
||
use app\common\service\ConfigService;
|
||
use app\common\model\teastore\TeaStoreRoom;
|
||
use app\common\model\order\OrderStore;
|
||
use app\common\model\teastore\TeaStore;
|
||
use think\facade\Db;
|
||
use app\common\service\qrcode\QrcodeService;
|
||
use app\common\service\iot\DoorService;
|
||
|
||
|
||
class CommonLogic extends BaseLogic
|
||
{
|
||
public static function getCityAddress($data){
|
||
$map_key = ConfigService::get("map_setting","map_key");
|
||
$url ="https://apis.map.qq.com/ws/geocoder/v1/?location=".$data['latitude'].",".$data['longitude']."&key=".$map_key;
|
||
$map = file_get_contents($url);
|
||
$map_msg = json_decode($map, true);
|
||
return $map_msg;
|
||
}
|
||
|
||
public static function get7Time($params){
|
||
Db::startTrans();
|
||
try {
|
||
$room = TeaStoreRoom::where([
|
||
'id'=>$params['room_id'],
|
||
'del'=>0
|
||
])->find();
|
||
if (!$room) {
|
||
throw new \Exception('包间不存在');
|
||
}
|
||
|
||
$date = $params['date'];
|
||
if (strtotime($date) < strtotime(date('Y-m-d'))){
|
||
throw new \Exception('预约时间错误');
|
||
}
|
||
|
||
|
||
|
||
$list = OrderStore::where([
|
||
'room_id'=>$room['id'],
|
||
'is_transfer'=>0,
|
||
])->where('end_time','>',time()-60*40)
|
||
->where('order_status', 'in', [0, 1, 2])
|
||
->column('timeslot');
|
||
$start = strtotime(date("Y-m-d 00:00:00", strtotime($date)));
|
||
$times =[];
|
||
foreach ($list as $v) {
|
||
$times = array_merge($times, explode(',', $v));
|
||
}
|
||
|
||
|
||
|
||
$result = [];
|
||
$weekMap = ['日', '一', '二', '三', '四', '五', '六'];
|
||
|
||
for ($day = 0; $day < 30; $day++) {
|
||
$dayStart = $start + ($day * 86400);
|
||
$dateStr = date('Y-m-d', $dayStart);
|
||
$weekDay = date('w', $dayStart);
|
||
|
||
$dayData = [
|
||
'display' => date('n/j', $dayStart) . '周' . $weekMap[$weekDay],
|
||
'date' => $dateStr,
|
||
'timestamp' => $dayStart,
|
||
'time_slots' => []
|
||
];
|
||
|
||
// 生成当天的时间段(8:00-22:00)
|
||
$businessStart = strtotime($dateStr . ' 00:00:00');
|
||
$businessEnd = strtotime($dateStr . ' 24:00:00');
|
||
$currentTime = time();
|
||
|
||
for ($timeSlot = $businessStart; $timeSlot < $businessEnd; $timeSlot += 1800) {
|
||
// 跳过已过期的时间
|
||
if ($timeSlot < $currentTime-1800) {
|
||
continue;
|
||
}
|
||
|
||
// 判断类型和是否禁用
|
||
$type = '1'; // 默认类型
|
||
$disabled = 0;
|
||
|
||
// 如果是已预订的时间
|
||
if (in_array($timeSlot, $times)) {
|
||
$disabled = 1;
|
||
$type = '2';
|
||
}
|
||
|
||
$dayData['time_slots'][] = [
|
||
'key' => $timeSlot,
|
||
'start_time' => date('H:i', $timeSlot),
|
||
'time' => date('H:i', $timeSlot), // 与原始代码保持一致
|
||
'local_time' => date('Y/m/d', $timeSlot),
|
||
'datetime' => date('Y-m-d H:i', $timeSlot),
|
||
'timestamp' => $timeSlot,
|
||
'type' => $type,
|
||
'disabled' => $disabled ? 1 : 0
|
||
];
|
||
}
|
||
|
||
if (!empty($dayData['time_slots'])) {
|
||
$result[] = $dayData;
|
||
}
|
||
}
|
||
|
||
Db::commit();
|
||
return ['data' => ['time' => $result]];
|
||
|
||
} catch (\Exception $e) {
|
||
Db::rollback();
|
||
self::setError($e->getMessage());
|
||
return false;
|
||
}
|
||
}
|
||
|
||
public static function speaker(){
|
||
$notifyService = new \app\common\service\iot\SpeakerService();
|
||
$re = $notifyService->sendSpeakerNotify('3402211281486');
|
||
print_r($re);die;
|
||
}
|
||
|
||
public static function qrcode($qrcode){
|
||
$service = new QrcodeService();
|
||
// 保存图片
|
||
$result = $service->saveImage($qrcode);
|
||
return $result;
|
||
|
||
}
|
||
|
||
public static function ce_ttlock($data){
|
||
|
||
|
||
try {
|
||
$service = new DoorService();
|
||
$order = OrderStore::where(['id' => $data['order_id']])->whereIn('order_status',[1,2])->find();
|
||
|
||
if(!$order){
|
||
throw new \Exception('订单错误');
|
||
}
|
||
$store_id = $order->store_id;
|
||
$store =TeaStore::where('id',$store_id)->find();
|
||
$room = TeaStoreRoom::where('id',$order->room_id)->find();
|
||
|
||
if($data['type'] ==1){
|
||
$lock_no = $store->lock_no;
|
||
if($lock_no<=0){
|
||
throw new \Exception('请联系门店管理检查门锁配置');
|
||
}
|
||
}else{
|
||
$lock_no = $room->lock_no;
|
||
}
|
||
$result = $service->unlockByNetwork($lock_no);
|
||
if($result['errcode'] != 0){
|
||
throw new \Exception('请联系门店管理检查门锁配置');
|
||
}
|
||
|
||
|
||
return [];
|
||
}catch (\Exception $e) {
|
||
self::setError($e->getMessage());
|
||
return false;
|
||
}
|
||
|
||
}
|
||
} |