// +---------------------------------------------------------------------- declare (strict_types=1); namespace app\api\controller; use app\api\model\store\Shop as ShopModel; use think\response\Json; /** * 门店列表 * Class Shop * @package app\api\controller */ class Shop extends Controller { /** * 门店列表 * @return Json * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function list(): Json { $model = new ShopModel; $list = $model->getList($this->request->param()); return $this->renderSuccess(compact('list')); } /** * 门店详情 * @param int $shopId * @return Json */ public function detail(int $shopId): Json { $detail = ShopModel::detail($shopId, ['logoImage']); return $this->renderSuccess(compact('detail')); } public function stopTimes(): Json { $data = []; $shopId = intval($this->request->post('shop_id')); if (!$shopId) { return $this->renderError('缺少必要参数'); } $detail = ShopModel::detail($shopId); if (!empty($detail['shop_hours'])) { $shop_hours = explode('-', $detail['shop_hours']); if (count($shop_hours) == 2) { $array = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"]; for ($i = 0; $i < 3; $i++) { $start_time = date('Y-m-d', strtotime('+' . $i . ' day', time())) . ' ' . $shop_hours[0]; $end_time = date('Y-m-d', strtotime('+' . $i . ' day', time())) . ' ' . $shop_hours[1]; $timeOne = strtotime($start_time); $timeTwo = strtotime($end_time); $times = []; while ($timeOne < $timeTwo) { $status = 0; if ($timeOne > time()) { $status = 1; } $times[] = [ 'value' => date('H:i', $timeOne), 'status' => $status, 'time' => date('Y-m-d H:i:s', $timeOne) ]; $timeOne = $timeOne + 30 * 60; } $data[] = [ 'name' => $array[date("w", strtotime($start_time))], 'date' => date('m-d', strtotime($start_time)), 'list' => $times, ]; } } } return $this->renderSuccess($data); } }