徐总多门店
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

92 lines
3.2 KiB

<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\controller\api\v2\order;
use app\Request;
use app\services\order\StoreCartServices;
class StoreCart
{
protected $services;
public function __construct(StoreCartServices $services)
{
$this->services = $services;
}
/**
* 购物车重选
* @param Request $request
* @return mixed
*/
public function resetCart(Request $request)
{
[$id, $unique, $num, $product_id] = $request->postMore([
['id', 0],
['unique', ''],
['num', 1],
['product_id', 0]
], true);
$this->services->resetCart($id, $request->uid(), $product_id, $unique, $num);
return app('json')->successful('操作成功');
}
/**
* 获取用户购物车
* @param Request $request
* @return mixed
*/
public function getCartList(Request $request)
{
$uid = (int)$request->uid();
[$store_id] = $request->postMore([
['store_id',0]
],true);
if ($store_id) {
$where = ['uid' => $uid, 'is_del' => 0, 'is_new' => 0, 'is_pay' => 0, 'type' => 0, 'store_id' => $store_id, 'staff_id' => 0];
} else {
$where = ['uid' => $uid, 'is_del' => 0, 'is_new' => 0, 'is_pay' => 0, 'type' => 0, 'staff_id' => 0];
}
$data = $this->services->getCartList($where, 0, 0, ['productInfo', 'attrInfo']);
if($store_id) $this->services->setItem('store_id', (int)$store_id);
[$data, $valid, $invalid] = $this->services->handleCartList($uid, $data, [], -1);
$this->services->reset();
return app('json')->successful($valid);
}
/**
* 首页加入购物车
* @param Request $request
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function setCartNum(Request $request)
{
[$product_id, $num, $unique, $type] = $request->postMore([
['product_id', 0],
['num', 0],
['unique', ''],
['type', -1]
], true);
/** @var StoreCartServices $cartService */
$cartService = app()->make(StoreCartServices::class);
if (!$product_id || !is_numeric($product_id)) return app('json')->fail('参数错误');
if (!(int)$num) return app('json')->fail('请提交加入购物车商品数量');
$res = $cartService->setCartNum((int)$request->uid(), (int)$product_id, (int)$num, $unique, (int)$type);
if ($res) return app('json')->successful('操作成功');
return app('json')->fail('操作失败');
}
}