From caee99f429c433e5ba11cb3d524b74cc554706c7 Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Wed, 24 May 2023 16:26:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=97=E9=93=BA=E4=BA=91=E5=95=86=E5=93=81?= =?UTF-8?q?=E4=B8=8B=E5=8D=95=E8=AE=B0=E5=BD=95=E5=85=A5=E5=8F=A3=E5=BA=97?= =?UTF-8?q?=E9=93=BA=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/dao/store/order/StoreCartDao.php | 2 ++ .../store/order/StoreOrderCreateRepository.php | 2 ++ .../store/product/SpuRepository.php | 6 ++++++ app/controller/api/store/order/StoreCart.php | 17 ++++++++++++++++- app/controller/api/store/product/StoreSpu.php | 1 + 5 files changed, 27 insertions(+), 1 deletion(-) diff --git a/app/common/dao/store/order/StoreCartDao.php b/app/common/dao/store/order/StoreCartDao.php index b13dfe11..846f19d0 100644 --- a/app/common/dao/store/order/StoreCartDao.php +++ b/app/common/dao/store/order/StoreCartDao.php @@ -27,6 +27,8 @@ use think\model\Relation; class StoreCartDao extends BaseDao { + const SOURCE_CLOUD = 101; //店铺云商品 + protected function getModel(): string { return StoreCart::class; diff --git a/app/common/repositories/store/order/StoreOrderCreateRepository.php b/app/common/repositories/store/order/StoreOrderCreateRepository.php index 5fef10af..c55e2fcf 100644 --- a/app/common/repositories/store/order/StoreOrderCreateRepository.php +++ b/app/common/repositories/store/order/StoreOrderCreateRepository.php @@ -2,6 +2,7 @@ namespace app\common\repositories\store\order; +use app\common\dao\store\order\StoreCartDao; use app\common\repositories\store\coupon\StoreCouponRepository; use app\common\repositories\store\coupon\StoreCouponUserRepository; use app\common\repositories\store\product\ProductAssistSkuRepository; @@ -1324,6 +1325,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository 'integral' => $cart['integral'] ? bcdiv($cart['integral']['use'], $cart['cart_num'], 0) : 0, 'integral_total' => $cart['integral'] ? $cart['integral']['use'] : 0, 'product_type' => $cart['product_type'], + 'source_mer_id' => $cart['source'] == StoreCartDao::SOURCE_CLOUD ? $cart['source_id'] : 0, 'cart_info' => json_encode($order_cart) ]; } diff --git a/app/common/repositories/store/product/SpuRepository.php b/app/common/repositories/store/product/SpuRepository.php index c94bf4be..12556241 100644 --- a/app/common/repositories/store/product/SpuRepository.php +++ b/app/common/repositories/store/product/SpuRepository.php @@ -18,6 +18,7 @@ use crmeb\jobs\SendSmsJob; use crmeb\jobs\SyncProductTopJob; use crmeb\services\CopyCommand; use crmeb\services\RedisCacheService; +use Fastknife\Utils\AesUtils; use think\exception\ValidateException; use think\facade\Db; use think\facade\Log; @@ -174,6 +175,8 @@ class SpuRepository extends BaseRepository } unset($where['mer_id']); } + $entryMerId = $where['entry_mer_id']; + unset($where['entry_mer_id']); $query = $this->dao->search($where); $count = $query->count(); @@ -188,6 +191,9 @@ class SpuRepository extends BaseRepository $list->append($append); $list = $this->getBorderList($list); + foreach ($list as &$item) { + $item['referer'] = AesUtils::encrypt($entryMerId . '|' . time(), config('app.app_secret')); + } return compact('count', 'list'); } public function getBorderList($list) diff --git a/app/controller/api/store/order/StoreCart.php b/app/controller/api/store/order/StoreCart.php index 1ec93c24..43e6124b 100644 --- a/app/controller/api/store/order/StoreCart.php +++ b/app/controller/api/store/order/StoreCart.php @@ -12,6 +12,7 @@ namespace app\controller\api\store\order; +use app\common\dao\store\order\StoreCartDao; use app\common\repositories\store\order\StoreOrderRepository; use app\common\repositories\store\product\ProductAssistRepository; use app\common\repositories\store\product\ProductAssistSetRepository; @@ -23,6 +24,7 @@ use app\common\repositories\store\product\StoreDiscountProductRepository; use app\common\repositories\store\product\StoreDiscountRepository; use app\common\repositories\store\StoreSeckillActiveRepository; use app\common\repositories\user\UserRepository; +use Fastknife\Utils\AesUtils; use MongoDB\BSON\MaxKey; use think\App; use crmeb\basic\BaseController; @@ -67,6 +69,11 @@ class StoreCart extends BaseController public function create(validate $validate) { $data = $this->checkParams($validate); + if (!empty($data['referer'])) { + $decrypt = AesUtils::decrypt($data['referer'], config('app.app_secret')); + $decryptArray = explode('|', $decrypt); + } + $entryMerId = $decryptArray[0] ?? ''; if(!in_array($data['product_type'],[0,1,2,3,4,98])) return app('json')->fail('商品类型错误'); if ($data['cart_num'] <= 0) return app('json')->fail('购买数量有误'); $user = $this->request->userInfo(); @@ -109,11 +116,19 @@ class StoreCart extends BaseController //更新购物车 $cart_id = $cart['cart_id']; $cart_num = ['cart_num' => ($cart['cart_num'] + $data['cart_num'])]; + if ($entryMerId) { + $cart_num['source_id'] = $entryMerId; + $cart_num['source'] = StoreCartDao::SOURCE_CLOUD; + } $storeCart = $this->repository->update($cart_id,$cart_num); } else { //添加购物车 $data['uid'] = $this->request->uid(); $data['mer_id'] = $result['product']['mer_id']; + if ($entryMerId) { + $data['source_id'] = $entryMerId; + $data['source'] = StoreCartDao::SOURCE_CLOUD; + } $cart = $storeCart = $this->repository->create($data); } event('user.cart', compact('user','storeCart')); @@ -229,7 +244,7 @@ class StoreCart extends BaseController */ public function checkParams(validate $validate) { - $data = $this->request->params(['product_id','product_attr_unique','cart_num','is_new',['product_type',0],['group_buying_id',0],['spread_id',0]]); + $data = $this->request->params(['product_id','product_attr_unique','cart_num','is_new',['product_type',0],['group_buying_id',0],['spread_id',0], 'referer']); $validate->check($data); if ($data['spread_id']) { if ($data['spread_id'] !== $this->request->userInfo()->uid){ diff --git a/app/controller/api/store/product/StoreSpu.php b/app/controller/api/store/product/StoreSpu.php index 2242c530..31ffe100 100644 --- a/app/controller/api/store/product/StoreSpu.php +++ b/app/controller/api/store/product/StoreSpu.php @@ -109,6 +109,7 @@ class StoreSpu extends BaseController } $where['mer_id'] = $mer_id; + $where['entry_mer_id'] = $id; $where['is_gift_bag'] = 0; $where['order'] = $where['order'] ? $where['order'] : 'sort'; $data = $this->repository->getApiCloudSearch($where, $page, $limit);