feat: 购物车商品数量限制为100个,超出时无法添加更多商品 fix: 修复订单创建时支付方式验证错误 refactor: 重构订单创建逻辑,优化代码结构 style: 修改金额计算方式,保留两位小数 test: 增加购物车列表接口测试用例 docs: 更新购物车相关接口文档 build: 更新依赖包版本
85 lines
2.5 KiB
PHP
85 lines
2.5 KiB
PHP
<?php
|
||
|
||
namespace app\store\controller\cart;
|
||
|
||
use app\api\logic\order\CartLogic;
|
||
use app\api\validate\CartValidate;
|
||
use app\store\lists\cart\CartList;
|
||
use app\common\model\order\Cart;
|
||
use app\store\controller\BaseAdminController;
|
||
use hg\apidoc\annotation as ApiDoc;
|
||
|
||
#[ApiDoc\NotParse()]
|
||
class CartController extends BaseAdminController
|
||
{
|
||
public function list()
|
||
{
|
||
return $this->dataLists(new CartList());
|
||
}
|
||
|
||
/**
|
||
* @notes 添加购物车
|
||
*/
|
||
public function create()
|
||
{
|
||
$params = (new CartValidate())->post()->goCheck('StoreAdd');
|
||
$adminInfo = $this->adminInfo;
|
||
$params['uid'] = 0;
|
||
$params['staff_id'] = $adminInfo['admin_id'];
|
||
$params['store_id'] = $adminInfo['store_id'];
|
||
$result = Cart::where(['uid' => 0,'staff_id'=>$adminInfo['admin_id'], 'store_id' => $adminInfo['store_id'], 'product_id' => $params['product_id'], 'is_fail' => 0, 'is_pay' => 0])->find();
|
||
$count = Cart::where(['uid' => $params['uid'], 'is_pay' => 0])->count();
|
||
if ($count > 100) {
|
||
return $this->fail('购物车商品不能大于100个,请先结算');
|
||
}
|
||
if ($result) {
|
||
$res = CartLogic::edit($params);
|
||
} else {
|
||
$res = CartLogic::add($params);
|
||
}
|
||
if ($res) {
|
||
return $this->success('添加成功');
|
||
} else {
|
||
return $this->fail(CartLogic::getError());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @notes 修改购物车
|
||
*/
|
||
public function change()
|
||
{
|
||
$params = (new CartValidate())->post()->goCheck('StoreChange');
|
||
$adminInfo = $this->adminInfo;
|
||
$params['uid'] = 0;
|
||
$params['staff_id'] = $adminInfo['admin_id'];
|
||
$params['store_id'] = $adminInfo['store_id'];
|
||
$res = CartLogic::edit($params, 'dec');
|
||
if ($res) {
|
||
return $this->success('修改成功');
|
||
} else {
|
||
return $this->fail(CartLogic::getError());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @notes 删除购物车
|
||
*/
|
||
public function delete()
|
||
{
|
||
$params = (new CartValidate())->post()->goCheck('delete');
|
||
$adminInfo = $this->adminInfo;
|
||
$params['uid'] = 0;
|
||
$params['staff_id'] = $adminInfo['admin_id'];
|
||
$params['store_id'] = $adminInfo['store_id'];
|
||
$res = CartLogic::delete($params);
|
||
if ($res) {
|
||
return $this->success('删除成功');
|
||
} else {
|
||
return $this->fail(CartLogic::getError());
|
||
}
|
||
}
|
||
|
||
|
||
}
|