From 0129bdb5730e4a68dcd6334044c2eb5dbc601426 Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Wed, 24 May 2023 14:10:59 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=BA=97=E9=93=BA?= =?UTF-8?q?=E4=BA=91=E5=95=86=E5=93=81=E5=88=97=E8=A1=A8=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/store/product/StoreSpu.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controller/api/store/product/StoreSpu.php b/app/controller/api/store/product/StoreSpu.php index 41853699..2242c530 100644 --- a/app/controller/api/store/product/StoreSpu.php +++ b/app/controller/api/store/product/StoreSpu.php @@ -10,6 +10,7 @@ // +---------------------------------------------------------------------- namespace app\controller\api\store\product; +use app\common\model\system\merchant\Merchant; use app\common\repositories\store\product\ProductRepository; use app\common\repositories\store\StoreCategoryRepository; use app\common\repositories\system\merchant\MerchantRepository; @@ -101,8 +102,8 @@ class StoreSpu extends BaseController 'keyword', 'cate_id', 'order', 'price_on', 'price_off', 'brand_id', 'pid', 'mer_cate_id', ['product_type', 0], 'action', 'common' ]); if ($where['action']) unset($where['product_type']); -// $category_id=Db::name('merchant')->where('mer_id',$id)->value('category_id');->where('category_id',$category_id) - $mer_id=Db::name('merchant')->where('mer_state',1)->where('status',1)->where('type_id',11)->value('mer_id'); + $category_id=Db::name('merchant')->where('mer_id',$id)->value('category_id'); + $mer_id=Db::name('merchant')->where('mer_state',1)->where('status',1)->where('category_id',$category_id)->where('type_id',Merchant::TypeCloudWarehouse)->value('mer_id'); if (!$mer_id){ return app('json')->success(['count'=>0,'list'=>[]]); 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 2/4] =?UTF-8?q?=E5=BA=97=E9=93=BA=E4=BA=91=E5=95=86?= =?UTF-8?q?=E5=93=81=E4=B8=8B=E5=8D=95=E8=AE=B0=E5=BD=95=E5=85=A5=E5=8F=A3?= =?UTF-8?q?=E5=BA=97=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); From fb50a7accdc4f72d2bd3a1bdba44056e052f4d05 Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Wed, 24 May 2023 16:40:09 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BA=91=E4=BB=93=E5=95=86=E5=93=81?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=85=B3=E9=94=AE=E5=AD=97=E6=A3=80=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repositories/store/product/SpuRepository.php | 16 +++++++++++++++- .../api/store/product/CloudWarehouse.php | 4 +++- config/app.php | 2 ++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/common/repositories/store/product/SpuRepository.php b/app/common/repositories/store/product/SpuRepository.php index 12556241..dd4ca0be 100644 --- a/app/common/repositories/store/product/SpuRepository.php +++ b/app/common/repositories/store/product/SpuRepository.php @@ -34,6 +34,9 @@ class SpuRepository extends BaseRepository public $dao; public $merchantFiled = 'mer_id,mer_name,mer_avatar,is_trader,mer_info,mer_keyword,type_id'; public $productFiled = 'P.bar_code,S.product_id,S.store_name,S.image,activity_id,S.keyword,S.price,S.mer_id,spu_id,S.status,store_info,brand_id,cate_id,unit_name,S.star,S.rank,S.sort,sales,S.product_type,rate,reply_count,extension_type,S.sys_labels,S.mer_labels,P.delivery_way,P.delivery_free,P.ot_price,svip_price_type,stock,mer_svip_status'; + + public $userInfo; + public function __construct(SpuDao $dao) { $this->dao = $dao; @@ -163,6 +166,17 @@ class SpuRepository extends BaseRepository { $where['spu_status'] = 1; $where['mer_status'] = 1; + if (!empty($where['keyword'])) { + if (preg_match('/^(\/@[1-9]{1}).*\*\//', $where['keyword'])) { + $command = app()->make(CopyCommand::class)->getMassage($where['keyword']); + if (!$command || in_array($command['type'], [30, 40])) return ['count' => 0, 'list' => []]; + if ($this->userInfo && $command['uid']) app()->make(UserRepository::class)->bindSpread($this->userInfo, $command['uid']); + $where['spu_id'] = $command['id']; + unset($where['keyword']); + } else { + app()->make(UserVisitRepository::class)->searchProduct($this->userInfo ? $this->userInfo['uid'] : 0, $where['keyword'], (int)($where['mer_id'] ?? 0)); + } + } if ($rand) { $RedisCacheService = app()->make(RedisCacheService::class); $exists=$RedisCacheService->exists('CloudMerchantSpu'.$where['mer_id']); @@ -175,7 +189,7 @@ class SpuRepository extends BaseRepository } unset($where['mer_id']); } - $entryMerId = $where['entry_mer_id']; + $entryMerId = $where['entry_mer_id'] ?? ''; unset($where['entry_mer_id']); $query = $this->dao->search($where); diff --git a/app/controller/api/store/product/CloudWarehouse.php b/app/controller/api/store/product/CloudWarehouse.php index 605ecd6b..5a262d7f 100644 --- a/app/controller/api/store/product/CloudWarehouse.php +++ b/app/controller/api/store/product/CloudWarehouse.php @@ -36,6 +36,7 @@ class CloudWarehouse extends BaseController $this->repository = $repository; $this->merchantDao = $merchantDao; $this->spuRepository = $spuRepository; + $this->spuRepository->userInfo = $this->request->isLogin() ? $this->request->userInfo() : null; } /** @@ -44,7 +45,7 @@ class CloudWarehouse extends BaseController */ public function index() { - $params = $this->request->params(['category_id', 'street_code', 'order', ['product_type', 0]]); + $params = $this->request->params(['category_id', 'street_code', 'order', ['product_type', 0], 'keyword']); $search = [ 'street_id' => $params['street_code'], 'type_id' => Merchant::TypeStore, @@ -55,6 +56,7 @@ class CloudWarehouse extends BaseController if (empty($merchantIds)) { return app('json')->success(['count' => 0, 'list' => []]); } + $where['keyword'] = $params['keyword']; $where['mer_ids'] = $merchantIds; $where['product_type'] = $params['product_type']; $where['is_gift_bag'] = 0; diff --git a/config/app.php b/config/app.php index 5270a42e..0cc46466 100644 --- a/config/app.php +++ b/config/app.php @@ -44,4 +44,6 @@ return [ 'error_message' => '页面错误!请稍后再试~', // 显示错误信息 'show_error_msg' => false, + //应用加解密秘钥 + 'app_secret' => '789XH80PTSb8pHjH', ]; From 70b1a91b169a724623c2bf62be518e0c645be5db Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Wed, 24 May 2023 17:17:21 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=BA=97=E9=93=BA?= =?UTF-8?q?=E4=BA=91=E5=95=86=E5=93=81=E4=B8=8B=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repositories/store/order/StoreOrderCreateRepository.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/common/repositories/store/order/StoreOrderCreateRepository.php b/app/common/repositories/store/order/StoreOrderCreateRepository.php index c55e2fcf..278f7847 100644 --- a/app/common/repositories/store/order/StoreOrderCreateRepository.php +++ b/app/common/repositories/store/order/StoreOrderCreateRepository.php @@ -1325,7 +1325,6 @@ 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) ]; }