dlh_test_server/app/api/controller/LocalStoreGoods.php

123 lines
3.6 KiB
PHP
Raw Normal View History

2024-08-22 13:59:35 +08:00
<?php
namespace app\api\controller;
use app\api\logic\LocalStoreGoodsLogic;
2024-10-28 14:53:43 +08:00
use app\api\validate\LocalStoreGoodsCartValidate;
2024-08-22 13:59:35 +08:00
use app\api\validate\LocalStoreGoodsValidate;
use app\common\basics\Api;
2024-10-28 14:53:43 +08:00
use app\common\model\localstore\LocalStoreGoodsCart;
2024-08-22 13:59:35 +08:00
use app\common\server\JsonServer;
class LocalStoreGoods extends Api
{
2024-10-28 14:57:04 +08:00
public $like_not_need_login = ['lists', 'addCart', 'num'];
2024-10-26 09:45:14 +08:00
2024-08-23 09:31:23 +08:00
// 商品列表
2024-08-22 14:11:04 +08:00
public function lists()
{
$get = $this->request->get();
$get['page_no'] = $get['page_no'] ?? $this->page_no;
$get['page_size'] = $get['page_size'] ?? $this->page_size;
$get['type'] = $get['type'] ?? 1;
2024-10-05 16:05:03 +08:00
$get['keyword'] = $get['keyword'] ?? '';
2024-10-17 16:07:44 +08:00
$get['money_sort'] = $get['money_sort'] ?? '';
2024-08-22 14:11:04 +08:00
$get['user_id'] = $this->user_id;
$result = LocalStoreGoodsLogic::lists($get);
if ($result) {
return JsonServer::success('获取成功', $result);
}
return JsonServer::error('获取失败');
2024-08-22 14:11:04 +08:00
}
2024-08-22 13:59:35 +08:00
// 商家添加商品
2024-08-23 10:10:57 +08:00
public function saveGoods()
2024-08-22 13:59:35 +08:00
{
2024-10-07 09:41:48 +08:00
try {
$form = $this->request->post();
(new LocalStoreGoodsValidate())->goCheck();
LocalStoreGoodsLogic::saveGoods($form, $this->user_id);
return JsonServer::success('提交成功', [], 1, 1);
} catch (\Exception $e) {
return JsonServer::error($e->getMessage());
2024-08-23 10:10:57 +08:00
}
2024-08-22 13:59:35 +08:00
}
2024-08-23 09:31:23 +08:00
2024-09-05 17:29:06 +08:00
public function editPrice()
{
$form = $this->request->post();
$result = LocalStoreGoodsLogic::editPrice($form, $this->user_id);
if ($result === false) {
return JsonServer::error('修改失败');
}
return JsonServer::success('修改成功', [], 1, 1);
}
2024-08-26 11:54:48 +08:00
public function shopDetails()
{
$get = $this->request->get();
$get['user_id'] = $this->user_id;
$result = LocalStoreGoodsLogic::shop_details($get);
if ($result) {
return JsonServer::success('获取成功', $result);
}
return JsonServer::error('获取失败');
}
2024-08-23 09:31:23 +08:00
public function details()
{
$get = $this->request->get();
$get['user_id'] = $this->user_id;
$result = LocalStoreGoodsLogic::details($get);
if ($result) {
return JsonServer::success('获取成功', $result);
}
return JsonServer::error('获取失败');
}
2024-08-23 14:13:52 +08:00
public function setState()
{
$form = $this->request->post();
$result = LocalStoreGoodsLogic::setState($form);
2024-08-23 14:24:34 +08:00
if ($result) {
return JsonServer::success('操作成功');
}
return JsonServer::error('操作失败');
2024-08-23 14:13:52 +08:00
}
2024-09-15 09:33:53 +08:00
public function delGoods()
{
$form = $this->request->post();
$result = LocalStoreGoodsLogic::delGoods($form);
2024-09-15 09:33:53 +08:00
if ($result) {
return JsonServer::success('操作成功');
}
return JsonServer::error('操作失败');
}
2024-10-28 14:53:43 +08:00
// 将商品加入购物车
public function addCart()
{
$form = $this->request->post();
(new LocalStoreGoodsCartValidate())->goCheck('add', ['user_id' => $this->user_id]);
try {
$result = LocalStoreGoodsLogic::addCart($form, $this->user_id);
if ($result) {
return JsonServer::success('操作成功');
}
} catch (\Exception $e) {
return JsonServer::error($e->getMessage());
}
}
// 获取购物车数量
public function num()
{
$form = $this->request->post();
return JsonServer::success('', LocalStoreGoodsLogic::cartNum($form, $this->user_id));
}
2024-08-22 13:59:35 +08:00
}