dlh_test_server/app/admin/controller/groupbuy/GroupBuy.php

119 lines
3.4 KiB
PHP
Raw Normal View History

2024-09-24 15:11:00 +08:00
<?php
namespace app\admin\controller\groupbuy;
use app\common\basics\AdminBase;
use app\common\server\JsonServer;
use app\admin\logic\groupbuy\GroupbuyLogic;
use app\admin\validate\groupbuy\GroupbuyValidate;
use think\exception\ValidateException;
class GroupBuy extends AdminBase
{
public function Lists(){
if($this->request->isAjax()){
$get = $this->request->get();
$list = GroupbuyLogic::goodsList($get);
return JsonServer::success('获取成功', $list);
}
return View('', [
'config' => GroupbuyLogic::getConfig()
]);
2024-09-24 15:11:00 +08:00
}
public function add(){
if($this->request->isAjax()){
$post = $this->request->post();
$post['item'] = form_to_linear($post);
try{
validate(GroupbuyValidate::class)->scene('add')->check($post);
}catch(ValidateException $e) {
return JsonServer::error($e->getError());
}
$result = GroupbuyLogic::add($post);
if($result === true) {
return JsonServer::success('新增成功');
}
return JsonServer::error(GroupbuyLogic::getError());
}
return view('');
}
public function edit(){
if($this->request->isAjax()){
$post = $this->request->post();
$post['item'] = form_to_linear($post);
try{
validate(GroupbuyValidate::class)->scene('edit')->check($post);
}catch(ValidateException $e) {
return JsonServer::error($e->getError());
}
$result = GroupbuyLogic::edit($post);
if($result === true) {
return JsonServer::success('编辑成功');
}
return JsonServer::error(GroupbuyLogic::getError());
}
$id = $this->request->get('id');
$detail = GroupbuyLogic::getEditGoods($id);
return view('', [
'detail' => $detail
]);
}
public function del(){
if($this->request->isAjax()){
$id = $this->request->post('id');
$result = GroupbuyLogic::del($id);
if($result === true) {
return JsonServer::success('删除成功');
}
return JsonServer::error(GroupbuyLogic::getError());
}
}
public function switchStatus(){
if($this->request->isAjax()){
$post = $this->request->post();
$result = GroupbuyLogic::switchStatus($post);
if($result === true) {
return JsonServer::success('操作成功');
}
return JsonServer::error(GroupbuyLogic::getError());
}
}
public function goodsLists(){
if ($this->request->isAjax()){
$get = $this->request->get();
$goods_list = GroupbuyLogic::getGoodsList($get,true);
return JsonServer::success('', $goods_list);
}
$category_list = GroupbuyLogic::listAll();
return view('', [
'category_list' => $category_list
]);
}
public function setConfig()
{
if ($this->request->isAjax()){
$post = $this->request->post();
2024-11-28 16:03:13 +08:00
$result = GroupbuyLogic::setConfig($post);
if ($result) {
return JsonServer::success('操作成功');
}
return JsonServer::error(GroupbuyLogic::getError());
}
}
2024-09-24 15:11:00 +08:00
}