Files
oil/server-tp6/app/store/controller/Shop.php
T
2026-09-01 22:15:50 +08:00

169 lines
4.6 KiB
PHP

<?php
declare (strict_types=1);
namespace app\store\controller;
use app\common\model\store\Setting as SettingModel;
use app\store\controller\Controller;
use app\store\model\store\User;
use app\store\model\Shop as ShopModel;
use app\common\exception\BaseException;
use think\response\Json;
/**
* 店铺控制器
* Class StoreUser
* @package app\store\controller
*/
class Shop extends Controller
{
/**
* 店铺列表
* @return mixed
* @throws \think\exception\DbException
*/
public function index(): Json
{
$model = new ShopModel;
$list = $model->getList($this->request->param(), $this->store['user']);
$user = $this->store['user'];
return $this->renderSuccess(compact('list','user'));
}
/**
* 获取管理员
* @return mixed
* @throws \think\exception\DbException
*/
public function getAdmin(): Json
{
$user = $this->store['user'];
$admin = User::getAll($user);
return $this->renderSuccess(compact('admin','user'));
}
/**
* 获取所有店铺
* @return mixed
* @throws \think\exception\DbException
*/
public function all(): Json
{
$list = ShopModel::getAll($this->store['user']);
$expiration_time = SettingModel::getItem('trade')['expiration_time'];
return $this->renderSuccess(compact('list','expiration_time'));
}
/**
* 添加店铺
* @return array|mixed
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function add()
{
$model = new ShopModel;
// 新增记录
if ($model->add($this->postForm())) {
return $this->renderSuccess('添加成功');
}
return $this->renderError($model->getError() ?: '添加失败');
}
/**
* 店铺详情
* @param int $shopId
* @return Json
* @throws BaseException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @throws \cores\exception\BaseException
*/
public function detail(int $shopId): Json
{
$shopInfo = ShopModel::detail($shopId);
return $this->renderSuccess(compact('shopInfo'));
}
/**
* 编辑店铺
* @param int $shopId
* @return Json
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @throws \cores\exception\BaseException
*/
public function edit(int $shopId): Json
{
// 商品详情
$model = ShopModel::detail($shopId);
// 更新记录
if ($model->edit($this->postForm())) {
return $this->renderSuccess('更新成功');
}
return $this->renderError($model->getError() ?: '更新失败');
}
/**
* 删除店铺
* @return Json
* @throws \think\exception\DbException
*/
public function delete(): Json
{
$arr = $this->postData();
$model = new ShopModel();
if (!$model->update(['is_delete' => 1],[['shop_id','in',$arr]])) {
return $this->renderError($model->getError() ?: '删除失败');
}
return $this->renderSuccess('删除成功');
/*// 管理员详情
$model = ShopModel::detail($shop_id);
if (!$model->setDelete()) {
return $this->renderError($model->getError() ?: '删除失败');
}
return $this->renderSuccess('删除成功');*/
}
/**
* 修改店铺列表状态
* @return Json
*/
public function changeState(): Json
{
$post = $this->postData();
$status = $post['state']?1:2;
// 商品详情
foreach ((array)$post['shopIds'] as $shop_id) {
$model = ShopModel::detail($shop_id);
$warn = $model->changeStatus($status);
if ($warn !== true) {
return $this->renderError($warn);
}
}
return $this->renderSuccess($post);
}
/**
* 修改收款金额
* @param int $shopId
* @return Json
* @throws \think\exception\DbException
*/
public function updateMoney($shopId): Json
{
$postData = $this->postForm();
$model = ShopModel::detail($shopId);
if ($model->updateMoney($postData)) {
return $this->renderSuccess('修改成功');
}
return $this->renderError($model->getError() ?: '修改失败');
}
}