购物车模块
This commit is contained in:
parent
cca85a62b4
commit
614950f36c
@ -91,6 +91,9 @@ class StoreOrderDao extends BaseDao
|
|||||||
->when(isset($where['activity_type']) && $where['activity_type'] != '', function ($query) use ($where) {
|
->when(isset($where['activity_type']) && $where['activity_type'] != '', function ($query) use ($where) {
|
||||||
$query->where('activity_type', $where['activity_type']);
|
$query->where('activity_type', $where['activity_type']);
|
||||||
})
|
})
|
||||||
|
->when(isset($where['product_type']) && $where['product_type'] != 0, function ($query) use ($where) {
|
||||||
|
$query->where('is_virtual', $where['product_type']);
|
||||||
|
})
|
||||||
->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) {
|
->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) {
|
||||||
switch ($where['status']) {
|
switch ($where['status']) {
|
||||||
case 0 :
|
case 0 :
|
||||||
|
@ -83,7 +83,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($cart['product_type'] > 0) $order_type = $cart['product_type'];
|
if ($cart['product_type'] > 0) $order_type = $cart['product_type'];
|
||||||
if ($cart['product_type'] > 0 && (($cart['product_type'] != 10 && count($merchantCart['list']) != 1) || count($merchantCartList) != 1)) {
|
if ($cart['product_type']<98 &&$cart['product_type'] > 0 && (($cart['product_type'] != 10 && count($merchantCart['list']) != 1) || count($merchantCartList) != 1)) {
|
||||||
throw new ValidateException('活动商品必须单独购买');
|
throw new ValidateException('活动商品必须单独购买');
|
||||||
}
|
}
|
||||||
if ($cart['product']['type'] && (count($merchantCart['list']) != 1 || count($merchantCartList) != 1)) {
|
if ($cart['product']['type'] && (count($merchantCart['list']) != 1 || count($merchantCartList) != 1)) {
|
||||||
@ -896,7 +896,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
|||||||
) + ['allow_address' => !$allow_no_address, 'order_delivery_status' => $orderDeliveryStatus];
|
) + ['allow_address' => !$allow_no_address, 'order_delivery_status' => $orderDeliveryStatus];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function v2CreateOrder(int $pay_type, $user, array $cartId, array $extend, array $mark, array $receipt_data, array $takes = null, array $useCoupon = null, bool $useIntegral = false, int $addressId = null, array $post, $source)
|
public function v2CreateOrder(int $pay_type, $user, array $cartId, array $extend, array $mark, array $receipt_data, array $takes = null, array $useCoupon = null, bool $useIntegral = false, int $addressId = null, array $post, $source,int $product_type=0)
|
||||||
{
|
{
|
||||||
$uid = $user->uid;
|
$uid = $user->uid;
|
||||||
$orderInfo = $this->v2CartIdByOrderInfo($user, $cartId, $takes, $useCoupon, $useIntegral, $addressId, true);
|
$orderInfo = $this->v2CartIdByOrderInfo($user, $cartId, $takes, $useCoupon, $useIntegral, $addressId, true);
|
||||||
@ -920,7 +920,8 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
|||||||
$extend = [];
|
$extend = [];
|
||||||
}
|
}
|
||||||
$orderType = $orderInfo['order_type'];
|
$orderType = $orderInfo['order_type'];
|
||||||
if ($orderType && (count($orderInfo['order']) > 1 || ($orderType != 10 && count($orderInfo['order'][0]['list']) > 1))) {
|
|
||||||
|
if ($orderType && $orderType< 98 && (count($orderInfo['order']) > 1 || ($orderType != 10 && count($orderInfo['order'][0]['list']) > 1))) {
|
||||||
throw new ValidateException('活动商品请单独购买');
|
throw new ValidateException('活动商品请单独购买');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -972,7 +973,6 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
|||||||
$cartIds = [];
|
$cartIds = [];
|
||||||
$orderList = [];
|
$orderList = [];
|
||||||
$user_address = isset($address) ? ($address['province'] . $address['city'] . $address['district'] . $address['street'] . $address['detail']) : '';
|
$user_address = isset($address) ? ($address['province'] . $address['city'] . $address['district'] . $address['street'] . $address['detail']) : '';
|
||||||
|
|
||||||
// 验证下单来源,如果是普通来源,则执行分销推广佣金分配
|
// 验证下单来源,如果是普通来源,则执行分销推广佣金分配
|
||||||
if($source == 2) // 普通商品
|
if($source == 2) // 普通商品
|
||||||
{
|
{
|
||||||
@ -1093,13 +1093,17 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
|||||||
$rate = bcmul($merchantCart['merchantCategory']['commission_rate'], 100, 4);
|
$rate = bcmul($merchantCart['merchantCategory']['commission_rate'], 100, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$is_virtual=$order_model ? 1 : 0;
|
||||||
|
if ($product_type!=0){
|
||||||
|
$is_virtual=$product_type;
|
||||||
|
}
|
||||||
//整理订单数据
|
//整理订单数据
|
||||||
$_order = [
|
$_order = [
|
||||||
'cartInfo' => $merchantCart,
|
'cartInfo' => $merchantCart,
|
||||||
'activity_type' => $orderInfo['order_type'],
|
'activity_type' => $orderInfo['order_type'],
|
||||||
'commission_rate' => (float)$rate,
|
'commission_rate' => (float)$rate,
|
||||||
'order_type' => $merchantCart['order']['isTake'] ? 1 : 0,
|
'order_type' => $merchantCart['order']['isTake'] ? 1 : 0,
|
||||||
'is_virtual' => $order_model ? 1 : 0,
|
'is_virtual' => $is_virtual,
|
||||||
'extension_one' => $total_extension_one,
|
'extension_one' => $total_extension_one,
|
||||||
'extension_two' => $total_extension_two,
|
'extension_two' => $total_extension_two,
|
||||||
'order_sn' => $this->getNewOrderId() . ($k + 1),
|
'order_sn' => $this->getNewOrderId() . ($k + 1),
|
||||||
|
@ -67,6 +67,10 @@ class StoreOrder extends BaseController
|
|||||||
{
|
{
|
||||||
[$page, $limit] = $this->getPage();
|
[$page, $limit] = $this->getPage();
|
||||||
$where['status'] = $this->request->param('status');
|
$where['status'] = $this->request->param('status');
|
||||||
|
$where['product_type'] = $this->request->param('product_type',0);
|
||||||
|
if ($where['product_type']==0){
|
||||||
|
unset($where['product_type']);
|
||||||
|
}
|
||||||
$where['is_verify'] = $this->request->param('is_verify');
|
$where['is_verify'] = $this->request->param('is_verify');
|
||||||
$where['search'] = $this->request->param('store_name');
|
$where['search'] = $this->request->param('store_name');
|
||||||
$where['mer_id'] = $merId;
|
$where['mer_id'] = $merId;
|
||||||
|
@ -74,7 +74,7 @@ class StoreCart extends BaseController
|
|||||||
switch ($data['product_type'])
|
switch ($data['product_type'])
|
||||||
{
|
{
|
||||||
case 0: //普通商品
|
case 0: //普通商品
|
||||||
case 98: //普通商品
|
case 98: //供应链商品
|
||||||
$result = app()->make(ProductRepository::class)->cartCheck($data,$this->request->userInfo());
|
$result = app()->make(ProductRepository::class)->cartCheck($data,$this->request->userInfo());
|
||||||
[$source, $sourceId, $pid] = explode(':', $this->request->param('source', '0'), 3) + ['', '', ''];
|
[$source, $sourceId, $pid] = explode(':', $this->request->param('source', '0'), 3) + ['', '', ''];
|
||||||
$data['source'] = (in_array($source, [0, 1]) && $pid == $data['product_id']) ? $source : 0;
|
$data['source'] = (in_array($source, [0, 1]) && $pid == $data['product_id']) ? $source : 0;
|
||||||
|
@ -91,7 +91,7 @@ class StoreMicropayOrder extends BaseController
|
|||||||
}
|
}
|
||||||
$product=Db::name('store_product')->where('product_id',$find['product_id'])->find();
|
$product=Db::name('store_product')->where('product_id',$find['product_id'])->find();
|
||||||
event('user.cart', compact('user','storeCart'));
|
event('user.cart', compact('user','storeCart'));
|
||||||
return app('json')->success(['product'=>$product,'product_attr' => $cart]);
|
return app('json')->success(['product'=>$product,'attrValue' => $cart]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function v2CreateOrder(StoreCartRepository $cartRepository, StoreOrderCreateRepository $orderCreateRepository)
|
public function v2CreateOrder(StoreCartRepository $cartRepository, StoreOrderCreateRepository $orderCreateRepository)
|
||||||
|
@ -93,6 +93,7 @@ class StoreOrder extends BaseController
|
|||||||
$is_dg = $this->request->param('is_dg',0);
|
$is_dg = $this->request->param('is_dg',0);
|
||||||
$source = $this->request->param('source'); // 1 小组服务 2 普通来源
|
$source = $this->request->param('source'); // 1 小组服务 2 普通来源
|
||||||
$source = !isset($source)?2:$source; // 默认来源为2 普通商品订单
|
$source = !isset($source)?2:$source; // 默认来源为2 普通商品订单
|
||||||
|
$product_type=$this->request->param('product_type',0); // 98 供应链商品 0 普通商品 100 扫码枪支付
|
||||||
$isPc = $payType === 'pc';
|
$isPc = $payType === 'pc';
|
||||||
if ($isPc) {
|
if ($isPc) {
|
||||||
$payType = 'balance';
|
$payType = 'balance';
|
||||||
@ -121,8 +122,8 @@ class StoreOrder extends BaseController
|
|||||||
// if (!$addressId)
|
// if (!$addressId)
|
||||||
// return app('json')->fail('请选择地址');
|
// return app('json')->fail('请选择地址');
|
||||||
|
|
||||||
$groupOrder = app()->make(LockService::class)->exec('order.create', function () use ($orderCreateRepository, $receipt_data, $mark, $extend, $cartId, $payType, $takes, $couponIds, $useIntegral, $addressId, $post,$source) {
|
$groupOrder = app()->make(LockService::class)->exec('order.create', function () use ($orderCreateRepository, $receipt_data, $mark, $extend, $cartId, $payType, $takes, $couponIds, $useIntegral, $addressId, $post,$source,$product_type) {
|
||||||
return $orderCreateRepository->v2CreateOrder(array_search($payType, StoreOrderRepository::PAY_TYPE), $this->request->userInfo(), $cartId, $extend, $mark, $receipt_data, $takes, $couponIds, $useIntegral, $addressId, $post,$source);
|
return $orderCreateRepository->v2CreateOrder(array_search($payType, StoreOrderRepository::PAY_TYPE), $this->request->userInfo(), $cartId, $extend, $mark, $receipt_data, $takes, $couponIds, $useIntegral, $addressId, $post,$source,$product_type);
|
||||||
});
|
});
|
||||||
|
|
||||||
if ($groupOrder['pay_price'] == 0) {
|
if ($groupOrder['pay_price'] == 0) {
|
||||||
@ -151,6 +152,7 @@ class StoreOrder extends BaseController
|
|||||||
{
|
{
|
||||||
[$page, $limit] = $this->getPage();
|
[$page, $limit] = $this->getPage();
|
||||||
$where['status'] = $this->request->param('status');
|
$where['status'] = $this->request->param('status');
|
||||||
|
$where['product_type'] = $this->request->param('product_type',0);
|
||||||
$where['search'] = $this->request->param('store_name');
|
$where['search'] = $this->request->param('store_name');
|
||||||
$source = $this->request->param('source');
|
$source = $this->request->param('source');
|
||||||
$source = !isset($source)?2:$source; // 默认来源为2 普通商品订单
|
$source = !isset($source)?2:$source; // 默认来源为2 普通商品订单
|
||||||
|
54
app/controller/api/store/product/StoreMicro.php
Normal file
54
app/controller/api/store/product/StoreMicro.php
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
namespace app\controller\api\store\product;
|
||||||
|
use think\exception\ValidateException;
|
||||||
|
use think\facade\Db;
|
||||||
|
use crmeb\basic\BaseController;
|
||||||
|
|
||||||
|
class StoreMicro extends BaseController
|
||||||
|
{
|
||||||
|
function seach_bar_code($code){
|
||||||
|
$user = $this->request->userInfo();
|
||||||
|
$mer_id =Db::name('store_service')->where('uid',$user['uid'])->where('status',1)->value('mer_id');
|
||||||
|
$find=Db::name('store_product')->where('mer_id',$mer_id)->where('bar_code',$code)->find();
|
||||||
|
if (!$find){
|
||||||
|
$store_product=Db::name('store_product')->where('product_type',98)->where('bar_code',$code)->find();
|
||||||
|
if (!$store_product){
|
||||||
|
return app('json')->fail('平台没有该条形码,请自行录入');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return app('json')->success(['data'=>$find]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function eadtProduct(){
|
||||||
|
$product_id = $this->request->param('id', 0);
|
||||||
|
if ($product_id==0) return app('json')->fail('商品id不能为空');
|
||||||
|
$price = $this->request->param('price', 0);
|
||||||
|
if ($price==0) return app('json')->fail('价格不能为空');
|
||||||
|
$stock = $this->request->param('stock', 0);
|
||||||
|
if ($stock==0) return app('json')->fail('库存不能为空');
|
||||||
|
$user = $this->request->userInfo();
|
||||||
|
$mer_id =Db::name('store_service')->where('uid',$user['uid'])->where('status',1)->value('mer_id');
|
||||||
|
if ($mer_id==0) return app('json')->fail('商户id不能为空');
|
||||||
|
$data = [
|
||||||
|
'price'=>$price,
|
||||||
|
'stock'=>$stock,
|
||||||
|
];
|
||||||
|
Db::startTrans();
|
||||||
|
try {
|
||||||
|
Db::name('store_product')->where('mer_id',$mer_id)->where('product_id',$product_id)->update($data);
|
||||||
|
Db::name('store_product_attr_value')->where('mer_id',$mer_id)->where('product_id',$product_id)->update($data);
|
||||||
|
// 提交事务
|
||||||
|
Db::commit();
|
||||||
|
return app('json')->success(['data'=>'','msg'=>'更新成功']);
|
||||||
|
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
// 回滚事务
|
||||||
|
Db::rollback();
|
||||||
|
return app('json')->fail($e->getMessage());
|
||||||
|
}
|
||||||
|
Db::transaction(function () use ($mer_id,$product_id,$data) {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -23,6 +23,12 @@ Route::group('api/', function () {
|
|||||||
Route::any('test', 'api.Auth/test');
|
Route::any('test', 'api.Auth/test');
|
||||||
//强制登录
|
//强制登录
|
||||||
Route::group(function () {
|
Route::group(function () {
|
||||||
|
|
||||||
|
Route::group('micro', function () {
|
||||||
|
Route::get('seach_bar_code', '/seach_bar_code');
|
||||||
|
Route::post('eadt_product', '/eadtProduct');
|
||||||
|
})->prefix('api.store.product.StoreMicro');
|
||||||
|
|
||||||
Route::group('v2', function () {
|
Route::group('v2', function () {
|
||||||
//新的下单接口,支持分账
|
//新的下单接口,支持分账
|
||||||
Route::group('order', function () {
|
Route::group('order', function () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user