172 lines
5.1 KiB
PHP
Executable File
172 lines
5.1 KiB
PHP
Executable File
<?php
|
|
|
|
namespace app\api\controller;
|
|
|
|
use app\api\logic\LocalStoreGoodsCartLogic;
|
|
use app\api\logic\LocalStoreGoodsLogic;
|
|
use app\api\validate\LocalStoreGoodsCartValidate;
|
|
use app\api\validate\LocalStoreGoodsValidate;
|
|
use app\common\basics\Api;
|
|
use app\common\server\JsonServer;
|
|
|
|
class LocalStoreGoods extends Api
|
|
{
|
|
public $like_not_need_login = ['lists', 'addCart', 'getCartGoods', 'num', 'modifyCart', 'shopDetails'];
|
|
|
|
// 商品列表
|
|
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;
|
|
$get['keyword'] = $get['keyword'] ?? '';
|
|
$get['money_sort'] = $get['money_sort'] ?? '';
|
|
$get['user_id'] = $this->user_id;
|
|
$result = LocalStoreGoodsLogic::lists($get);
|
|
if ($result) {
|
|
return JsonServer::success('获取成功', $result);
|
|
}
|
|
|
|
return JsonServer::error('获取失败');
|
|
}
|
|
|
|
// 商家添加商品
|
|
public function saveGoods()
|
|
{
|
|
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());
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
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('获取失败');
|
|
}
|
|
|
|
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('获取失败');
|
|
}
|
|
|
|
public function setState()
|
|
{
|
|
$form = $this->request->post();
|
|
$result = LocalStoreGoodsLogic::setState($form);
|
|
if ($result) {
|
|
return JsonServer::success('操作成功');
|
|
}
|
|
return JsonServer::error('操作失败');
|
|
}
|
|
|
|
public function delGoods()
|
|
{
|
|
$form = $this->request->post();
|
|
$result = LocalStoreGoodsLogic::delGoods($form);
|
|
if ($result) {
|
|
return JsonServer::success('操作成功');
|
|
}
|
|
return JsonServer::error('操作失败');
|
|
}
|
|
|
|
// 将商品加入购物车
|
|
public function addCart()
|
|
{
|
|
$form = $this->request->post();
|
|
(new LocalStoreGoodsCartValidate())->goCheck('add', ['user_id' => $this->user_id]);
|
|
|
|
try {
|
|
$result = LocalStoreGoodsCartLogic::addCart($form, $this->user_id);
|
|
if ($result) {
|
|
return JsonServer::success('操作成功');
|
|
}
|
|
} catch (\Exception $e) {
|
|
return JsonServer::error($e->getMessage());
|
|
}
|
|
}
|
|
|
|
// 获取购物车商品
|
|
public function getCartGoods()
|
|
{
|
|
$form = $this->request->post();
|
|
return JsonServer::success('', LocalStoreGoodsCartLogic::getCartGoods($form, $this->user_id));
|
|
}
|
|
|
|
// 获取购物车数量
|
|
public function num()
|
|
{
|
|
$form = $this->request->post();
|
|
return JsonServer::success('', LocalStoreGoodsCartLogic::cartNum($form, $this->user_id));
|
|
}
|
|
|
|
public function modifyCart()
|
|
{
|
|
$form = $this->request->post();
|
|
(new LocalStoreGoodsCartValidate())->goCheck('change', ['user_id' => $this->user_id]);
|
|
|
|
try {
|
|
$result = LocalStoreGoodsCartLogic::modifyCart($form, $this->user_id);
|
|
if ($result) {
|
|
return JsonServer::success('操作成功', $result);
|
|
}
|
|
return JsonServer::error('操作失败');
|
|
} catch (\Exception $e) {
|
|
return JsonServer::error($e->getMessage());
|
|
}
|
|
}
|
|
|
|
public function clearCart()
|
|
{
|
|
$form = $this->request->post();
|
|
|
|
try {
|
|
$result = LocalStoreGoodsCartLogic::clearCart($form, $this->user_id);
|
|
if ($result) {
|
|
return JsonServer::success('操作成功', $result);
|
|
}
|
|
return JsonServer::error('操作失败');
|
|
} catch (\Exception $e) {
|
|
return JsonServer::error($e->getMessage());
|
|
}
|
|
}
|
|
|
|
// 获取返补
|
|
public function getSubsidy()
|
|
{
|
|
$result = LocalStoreGoodsLogic::getSubsidy();
|
|
if ($result) {
|
|
return JsonServer::success('操作成功', $result);
|
|
}
|
|
|
|
return JsonServer::error('操作失败');
|
|
}
|
|
} |