You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
yanzong/app/api/controller/Shop.php

118 lines
4.1 KiB

<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
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'] ?? "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');
}
}