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/store/controller/Shop.php

169 lines
5.2 KiB

11 months ago
<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\store\controller;
8 months ago
use app\common\model\store\ShopParking as ParkingModel;
9 months ago
use app\common\model\UploadFile;
11 months ago
use app\store\model\store\Shop as ShopModel;
8 months ago
use think\response\Json;
11 months ago
/**
* 门店管理
* Class Shop
* @package app\store\controller\store
*/
class Shop extends Controller
{
/**
* 门店列表
* @return Json
* @throws \think\db\exception\DbException
*/
public function list(): Json
{
$model = new ShopModel;
$list = $model->getList($this->request->param());
return $this->renderSuccess(compact('list'));
}
/**
* 全部记录
* @return Json
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function all(): Json
{
$model = new ShopModel;
$list = $model->getAll($this->request->param());
return $this->renderSuccess(compact('list'));
}
/**
* 获取详情记录
* @param int $shopId
* @return Json
*/
public function detail(int $shopId): Json
{
// 获取门店详情
$detail = ShopModel::detail($shopId);
8 months ago
if (!empty($detail['shop_hours'])) {
$shop_hours = explode('-', $detail['shop_hours']);
$detail['shop_hours_start'] = $shop_hours[0];
$detail['shop_hours_end'] = $shop_hours[1];
}
8 months ago
$file = UploadFile::whereIn('file_id', explode(',', $detail['shop_image_id']))->field('*')->select();
9 months ago
$detail['shop_image_url'] = $file;
11 months ago
// 获取logoImage (这里不能用with因为编辑页需要logoImage对象)
!empty($detail) && $detail['logoImage'];
return $this->renderSuccess(compact('detail'));
}
/**
* 添加门店
* @return Json
*/
public function add(): Json
{
// 新增记录
$model = new ShopModel;
8 months ago
$data = $this->postForm();
if (!empty($data['shop_hours_start']) && !empty($data['shop_hours_end'])) {
$data['shop_hours'] = $data['shop_hours_start'] . '-' . $data['shop_hours_end'];
8 months ago
unset($data['shop_hours_start']);
unset($data['shop_hours_end']);
8 months ago
}
if ($model->add($data)) {
11 months ago
return $this->renderSuccess('添加成功');
}
return $this->renderError($model->getError() ?: '添加失败');
}
/**
* 编辑门店
* @param int $shopId
* @return Json
*/
public function edit(int $shopId): Json
{
// 门店详情
$model = ShopModel::detail($shopId);
// 新增记录
8 months ago
$data = $this->postForm();
if (!empty($data['shop_hours_start']) && !empty($data['shop_hours_end'])) {
$data['shop_hours'] = $data['shop_hours_start'] . '-' . $data['shop_hours_end'];
8 months ago
unset($data['shop_hours_start']);
unset($data['shop_hours_end']);
8 months ago
}
if ($model->edit($data)) {
11 months ago
return $this->renderSuccess('更新成功');
}
return $this->renderError($model->getError() ?: '更新失败');
}
public function updateParking(int $shopId): Json
{
// 门店详情
$model = ShopModel::detail($shopId);
// 新增记录
if ($model->editParking($this->postForm())) {
return $this->renderSuccess('更新成功');
}
return $this->renderError($model->getError() ?: '更新失败');
}
11 months ago
/**
* 删除门店
* @param int $shopId
* @return Json
*/
public function delete(int $shopId): Json
{
// 门店详情
$model = ShopModel::detail($shopId);
if (!$model->setDelete()) {
return $this->renderError($model->getError() ?: '删除失败');
}
return $this->renderSuccess('删除成功');
}
10 months ago
//获取门店停车场
public function getParking(int $id): Json
{
// 获取门店详情
$detail = ParkingModel::detail($id);
return $this->renderSuccess(compact('detail'));
}
//添加,编辑门店停车场
8 months ago
public function editParking()
{
10 months ago
$model = new ParkingModel();
if ($model->edit($this->request->param())) {
return $this->renderSuccess('成功');
}
return $this->renderError($model->getError() ?: '失败');
}
9 months ago
8 months ago
public function test(int $shopId)
{
9 months ago
// 门店详情
$model = ShopModel::detail($shopId);
dd($model['logoImage']->toArray());
}
11 months ago
}