209 lines
6.0 KiB
PHP
209 lines
6.0 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @author Any
|
|
* @description KISS
|
|
* @date 2020-12-2
|
|
* @version 1.0.0
|
|
*
|
|
* _____LOG_____
|
|
*
|
|
*/
|
|
|
|
namespace app\modules\api\models;
|
|
|
|
use function AlibabaCloud\Client\value;
|
|
use app\components\FlashStorage;
|
|
use app\components\SiteHelper;
|
|
use app\components\SysConst;
|
|
use app\models\Box;
|
|
use app\models\Coach;
|
|
use app\models\Goods;
|
|
use app\models\GoodsHub;
|
|
use app\models\Order;
|
|
use app\models\OrderDetail;
|
|
use app\models\Store;
|
|
use app\models\User;
|
|
use app\components\auth\AToken;
|
|
use app\components\EncryptHelper;
|
|
use app\modules\api\components\ApiHelper;
|
|
use app\modules\api\components\DateHelp;
|
|
use app\modules\api\components\GetDistance;
|
|
use yii\data\Pagination;
|
|
|
|
|
|
class BoxForm extends ApiModel
|
|
{
|
|
|
|
public $limit;//条数
|
|
public $page; //页数
|
|
public $pageCount; // 总页数
|
|
|
|
public $store_id;
|
|
public $box_id;
|
|
public $interval = 1;
|
|
|
|
public $date;
|
|
public $user_id;
|
|
|
|
|
|
public function rules()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* 包厢列表
|
|
*/
|
|
public function search()
|
|
{
|
|
|
|
if (empty($this->box_id)) {
|
|
return $this->apiReturnError('包厢ID不能为空');
|
|
}
|
|
|
|
if (empty($this->date)) {
|
|
return $this->apiReturnError('预定日期不能为空');
|
|
}
|
|
$where = ['id' => $this->box_id, 'status' => 1, 'is_delete' => 0];
|
|
|
|
$list = Box::find()->where($where)
|
|
->select('id,name,notice,money,pic_urls,content,device')->asArray()->one();
|
|
|
|
$list['device'] = json_decode($list['device'], true);
|
|
|
|
if ($list['pic_urls']) {
|
|
$store_pics = json_decode($list['pic_urls'], true);
|
|
foreach ($store_pics as $k => $v) {
|
|
$list['pic_arr'][] = SiteHelper::getFullUrl($v);
|
|
}
|
|
unset($list['pic_urls']);
|
|
}
|
|
$s = strtotime($this->date); # 开始时间
|
|
$arr = [];
|
|
for ($i = 0; $i < 24; $i++) {
|
|
$arr[$s] = [
|
|
'start' => date('H:i', $s),
|
|
'stop' => date('H:i', $s + 60 * 60),
|
|
'scope' => date('H:i', $s) . "-" . date('H:i', $s + 60 * 60),
|
|
'status' => 0,
|
|
];
|
|
$s += 60 * 60;
|
|
}
|
|
$arr[$s - 60 * 60]['stop'] = date('H:59', $s - 60 * 60);
|
|
|
|
// 获取已下单数据
|
|
$query = Order::find()->alias('o')
|
|
->innerJoin(['rt' => OrderDetail::tableName()], 'o.id=rt.order_id')
|
|
->where(['o.store_id' => $this->store_id, 'coach_id' => $this->box_id, 'o.is_delete' => 0, 'o.cancel_status' => 0, 'o.plugin_sign' => 'box_book'])
|
|
->andWhere(['IN', 'o.status', [0, 1]])
|
|
->select('rt.start_at as start,rt.end_at as stop,o.user_id,o.is_pay')
|
|
->asArray()
|
|
->all();
|
|
if (!empty($query)) {
|
|
$t_arr = [];
|
|
foreach ($query as $key => $val) {
|
|
$t = strtotime(date('Y-m-d H:00', $val['start']));
|
|
while (true) {
|
|
if ($t >= $val['stop']) {
|
|
break;
|
|
}
|
|
// 如果是自己,可以继续选择,并且未支付
|
|
if ($val['user_id'] == $this->user_id && empty($val['is_pay'])) {
|
|
$t_arr[$t] = 0;
|
|
} else {
|
|
$t_arr[$t] = 1;
|
|
}
|
|
$t += 60 * 60;
|
|
}
|
|
}
|
|
foreach ($arr as $key => $val) {
|
|
if (!empty($t_arr[$key])) {
|
|
$arr[$key]['status'] = 1;
|
|
$arr[$key]['data'] = $t_arr;
|
|
}
|
|
}
|
|
}
|
|
return [
|
|
'code' => 0,
|
|
'msg' => 'ok',
|
|
'data' => $list,
|
|
'date_list' => array_merge($arr),
|
|
'data_res' => $query,
|
|
];
|
|
}
|
|
|
|
|
|
public function getBoxBookStatus($start_time, $end_time, $data)
|
|
{
|
|
$start_time = strtotime($start_time);
|
|
$end_time = strtotime($end_time);
|
|
|
|
$query = Order::find()->alias('o')
|
|
->innerJoin(['rt' => OrderDetail::tableName()], 'o.id=rt.order_id')
|
|
->where(['o.store_id' => $this->store_id, 'coach_id' => $this->box_id, 'o.is_delete' => 0, 'o.cancel_status' => 0])
|
|
->andWhere(['>=', 'rt.start_at', $start_time])
|
|
->andWhere(['<=', 'rt.end_at', $end_time])
|
|
->andWhere(['IN', 'o.status', [1, 3]])
|
|
->select('rt.start_at,rt.end_at')
|
|
->asArray()
|
|
// $count_query = clone $query;
|
|
->all();
|
|
//
|
|
// var_dump($query->createCommand()->getRawSql());
|
|
// die();
|
|
|
|
|
|
if (!isset($query)) {
|
|
return false;
|
|
}
|
|
|
|
//$beginTime1 订单预约的开始时间 $endTime1 订单预约的结束时间
|
|
//$beginTime2 下单的开始时间 $endTime2 下单的结束时间
|
|
|
|
foreach ($query as $key => $value) {
|
|
$beginTime1 = $value['start_at'];
|
|
$endTime1 = $value['end_at'];
|
|
$beginTime2 = $data['start'];
|
|
$endTime2 = $data['stop'];
|
|
$date_diff = $this->is_time_cross($beginTime1, $endTime1, $beginTime2, $endTime2);
|
|
if ($date_diff == true) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
|
|
function is_time_cross($beginTime1 = '', $endTime1 = '', $beginTime2 = '', $endTime2 = '')
|
|
{
|
|
$status = $beginTime2 - $beginTime1;
|
|
if ($status > 0) {
|
|
$status2 = $beginTime2 - $endTime1;
|
|
if ($status2 > 0) {
|
|
return false;
|
|
} elseif ($status2 < 0) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
} elseif ($status < 0) {
|
|
$status2 = $endTime2 - $beginTime1;
|
|
if ($status2 > 0) {
|
|
return true;
|
|
} else if ($status2 < 0) {
|
|
return false;
|
|
} else {
|
|
return false;
|
|
}
|
|
} else {
|
|
$status2 = $endTime2 - $beginTime1;
|
|
if ($status2 == 0) {
|
|
return false;
|
|
} else {
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
} |