// +---------------------------------------------------------------------- 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); // var_dump($detail['shop_hours']); // exit; if (!empty($detail['shop_hours'])) { $shop_hours = explode(' ', $detail['shop_hours']); $shop_hours = explode('-', $shop_hours[1] ?? "00:00"); 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', (int)$timeOne), 'status' => $status, 'time' => date('Y-m-d H:i:s', (int)$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); } public function editShop(int $shopId): Json { $param = $this->request->param(); $upData = [ 'shop_name' => $param['shop_name']??"", 'address' => $param['address']??"", 'phone' => $param['phone']??"", 'wechat_img_id' => $param['wechat_img_id']??"", ]; ShopModel::where('shop_id',$param['shop_id'])->update($upData); return $this->renderSuccess('ok'); } public function getShopInfo(){ $banner_imgs = []; $share_imgs = []; $activity_imgs = []; $data = [ 'banner_imgs' => $banner_imgs, 'share_imgs' => $share_imgs, 'activity_imgs' => $activity_imgs, ]; return $this->renderSuccess('ok'); } }