Files
CompanyProject/金壶/ydyd_service/application/api/controller/CartController.php
2024-09-27 01:32:49 +08:00

214 lines
6.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\api\controller;
use app\common\service\UserCartService;
use app\ydyd_service\service\ShopCartService;
use think\Exception;
class CartController extends CommonController
{
protected $noAuth = [];
/**
* @apiDefine Cart 购物车
*/
/**
* @apiVersion 1.0.0
* @api {post} /cart/add 1.添加购物车(丁超)
* @apiName add
* @apiGroup Cart
* @apiHeader {String} authentication 验证
* @apiParam {Int} gba_id 商品价格id
* @apiParam {Int} batch_id 商品批次id
* @apiParam {Int} goods_number 商品数量
* @apiParam {String} add_type 是否立即购买buy,否:传空)
* @apiSuccessExample Success-Response:
*{
"code": 200,
"message": "成功",
"data":{
uc_id:1,
errcode:0,
errmsg:"操作成功",
}
*/
public function add() {
try{
$param = input('param.');//暂不使用验证器校验
$user_data = $this->getUserInfo();
$data = model(UserCartService::class)->addGoods($user_data,$param);
return self::returnMsg(self::SUCCESS, self::getMessage('SUCCESS'),$data);
}catch (Exception $exception){
return self::returnMsg(self::ERR_NONE, $exception->getMessage());
}
}
/**
* @apiVersion 1.0.0
* @api {post} /cart/update 2.购物车商品数量(朱晓伟)
* @apiName update
* @apiGroup Cart
* @apiHeader {String} authentication 验证
* @apiParam {Int} id 购物车id
* @apiParam {Int} goods_number 商品数量
* @apiSuccessExample Success-Response:
*{
"code": 200,
"message": "成功",
"data":{
errcode:0,
errmsg:"操作成功",
}
*/
public function update() {
try{
$parames['user_id'] = $this->uid;
$parames['is_app'] = 1;//兼容pc处理机制(pc return错误app 抛出异常)
$parames['user_info'] = $this->getUserInfo();
$data = model(ShopCartService::class)->ChangeCart($parames);
// unset($data['errcode']);
return self::returnMsg(self::SUCCESS, self::getMessage('SUCCESS'),$data);
}catch (Exception $exception){
return self::returnMsg(self::ERR_NONE, $exception->getMessage());
}
}
/**
* @apiVersion 1.0.0
* @api {post} /cart/del 3.删除购物车(朱晓伟)
* @apiName del
* @apiGroup Cart
* @apiHeader {String} authentication 验证
* @apiParam {Int} id 购物车id
* @apiParam {Int} batch_id 商品批次id
* @apiSuccessExample Success-Response:
*{
"code": 200,
"message": "成功",
"data":{
errcode:0,
errmsg:"操作成功",
}
*/
public function del() {
try{
$parames['user_id'] = $this->uid;
$data = model(ShopCartService::class)->delCartProduct($parames);
return self::returnMsg(self::SUCCESS, self::getMessage('SUCCESS'),$data);
}catch (Exception $exception){
return self::returnMsg(self::ERR_NONE, $exception->getMessage());
}
}
/**
* @apiVersion 1.0.0
* @api {post} /cart/multiDel 4.批量删除购物车(朱晓伟)
* @apiName multiDel
* @apiGroup Cart
* @apiHeader {String} authentication 验证
* @apiParam {String} id_group 购物车id 例如1,2,3,4,5
* @apiSuccessExample Success-Response:
*{
"code": 200,
"message": "成功",
"data":{
errcode:0,
errmsg:"操作成功",
}
*/
public function multiDel() {
try{
$parames['user_id'] = $this->uid;
$data = model(ShopCartService::class)->multiDeleteCartProduct($parames);
return self::returnMsg(self::SUCCESS, self::getMessage('SUCCESS'),$data);
}catch (Exception $exception){
return self::returnMsg(self::ERR_NONE, $exception->getMessage());
}
}
/**
* @apiVersion 1.0.0
* @api {post} /cart/getList 5.购物车列表(丁超)
* @apiName getList
* @apiGroup Cart
* @apiHeader {String} authentication 验证
* @apiSuccessExample Success-Response:
*{
"code": 200,
"message": "成功",
"data": {
"errcode": 0,
"data": {
"available_goods": [{
"id": 102,
"price_id": 12104,
"price": "50.0000",
"price_type": 0,
"batch_id": 869,
"goods_id": 470,
"name": "匹多莫德口服溶液",
"spec_desc": "10ml:0.4g*6支",
"unit": "盒",
"pc_thumb": "ydyd-develop-file.oss-cn-hangzhou.aliyuncs.com\/pc_shop_thumb_url_1545011228838.jpg",
"status": 1,
"manufacturer_name": "江苏吴中医药集团有限公司苏州制药厂",
"supplier_user_id": 3,
"batch_number": "2017071008",
"batch_status": 1,
"stock_num": 640,
"retail_flag": 1,
"retail_num": 10,
"entirety_num": 80,
"batch_type": 1,
"term_validity": "2019-07-09",
"is_collect": 0,
"num": 80,
"can_select": 1,
"total_price": "4000.00"
}, {
"id": 101,
"price_id": 12110,
"price": "10.4000",
"price_type": 0,
"batch_id": 2142,
"goods_id": 1741,
"name": "心脏病药",
"spec_desc": "2*12ml",
"unit": "支",
"pc_thumb": "ydyd-develop-file.oss-cn-hangzhou.aliyuncs.com\/pc_shop_thumb_url_1562315863518.png",
"status": 1,
"manufacturer_name": "安徽仁和药业有限公司",
"supplier_user_id": 3,
"batch_number": "987654",
"batch_status": 1,
"stock_num": 20,
"retail_flag": 0,
"retail_num": 20,
"entirety_num": 200,
"batch_type": 1,
"term_validity": "2019-08-10",
"is_collect": 0,
"num": 20,
"can_select": 0,
"warn_info": "库存不足",
"total_price": "208.00"
}],
"inavailable_goods": []
}
}
}
*/
public function getList() {
try{
$user_data = $this->getUserInfo();
$data = model(UserCartService::class)->getAll($user_data);
return self::returnMsg(self::SUCCESS, self::getMessage('SUCCESS'),$data);
}catch (Exception $exception){
return self::returnMsg(self::ERR_NONE, $exception->getMessage());
}
}
}