From f32e982a1332cff90266101cf58af06ef13cf4b4 Mon Sep 17 00:00:00 2001 From: lqmac Date: Thu, 13 Jun 2024 10:35:30 +0800 Subject: [PATCH] 1 --- app/admin/controller/Goods.php | 64 +++++++++++++++++++-- app/api/controller/Category.php | 11 +++- app/api/service/Goods.php | 3 +- app/command/SyncStoreBasicData.php | 8 +-- app/common/library/wxserver/Server.php | 6 +- app/common/library/wxserver/Wholesaler.php | 6 +- app/common/model/Goods.php | 47 ++++++++------- app/job/controller/goods/GoodsDelete.php | 49 ++++++++++++++++ app/job/controller/goods/GoodsOffline.php | 49 ++++++++++++++++ app/job/controller/goods/GoodsOnline.php | 49 ++++++++++++++++ app/job/service/goods/AdminImport.php | 9 --- app/job/service/goods/Collector.php | 10 +--- app/job/service/goods/GoodsAddPrice.php | 10 +--- app/job/service/goods/GoodsDelete.php | 49 ++++++++++++++++ app/job/service/goods/GoodsOffline.php | 52 +++++++++++++++++ app/job/service/goods/GoodsOnline.php | 50 ++++++++++++++++ app/job/service/goods/GoodsStoreImport.php | 10 +--- app/job/service/goods/GoodsUpdateImport.php | 10 +--- 18 files changed, 408 insertions(+), 84 deletions(-) create mode 100644 app/job/controller/goods/GoodsDelete.php create mode 100644 app/job/controller/goods/GoodsOffline.php create mode 100644 app/job/controller/goods/GoodsOnline.php create mode 100644 app/job/service/goods/GoodsDelete.php create mode 100644 app/job/service/goods/GoodsOffline.php create mode 100644 app/job/service/goods/GoodsOnline.php diff --git a/app/admin/controller/Goods.php b/app/admin/controller/Goods.php index 8d1410d4..163a91e6 100644 --- a/app/admin/controller/Goods.php +++ b/app/admin/controller/Goods.php @@ -20,6 +20,9 @@ use app\store\model\GoodsCategoryRel; use app\store\model\GoodsSku; use app\store\model\goods\Import as ImportModel; use app\job\controller\goods\GoodsAddPrice as GoodsAddPriceJob; +use app\job\controller\goods\GoodsOffline as GoodsOfflineJob; +use app\job\controller\goods\GoodsOnline as GoodsOnlineJob; +use app\job\controller\goods\GoodsDelete as GoodsDeleteJob; /** * 商品管理控制器 @@ -48,7 +51,7 @@ class Goods extends Controller $params['store_id'] = 0; //$params['role'] = $this->admin['user']['role']; $platform = $this->getUserPlatform(); - $params['channels'] = $platform ? array_column($platform->toArray(), "code") : []; + $params['channels'] = $this->admin['user']['role'] == 0 ? [] :($platform ? array_column($platform->toArray(), "code") : []); $list= $model->getAdminList($params, $pageSize); return $this->renderSuccess(compact('list')); } @@ -175,11 +178,13 @@ class Goods extends Controller // 'is_sale' => $goods_sku->is_sale, 'update_time' => time(), ]; - if ($goods_sku->is_pool == 0 || $goods_sku->is_sale == 0) { + if ($goods_sku->is_pool != 1 || $goods_sku->is_sale == 0) { $goods_data['status'] = 20; + $goods_data['is_jd_remove'] = 1; } if ($goods_sku->is_pool == 1 && $goods_sku->is_sale == 1) { $goods_data['status'] = 10; + $goods_data['is_jd_remove'] = 0; } GoodsModel::where('origin_goods_id', $goodsId)->update($goods_data); $goods_sku_data = [ @@ -207,20 +212,57 @@ class Goods extends Controller if (!$model->setIsPool($goodsIds, $is_pool)) { return $this->renderError($model->getError() ?: '操作失败'); } + // 分批每次导入20条 + $limit = 20; + // 根据商品总数量计算需要的队列任务数量 + $jobCount = \count($goodsIds) / $limit; + // 逐次发布队列任务 + for ($i = 0; $i < $jobCount; $i++) { + $data = array_slice($goodsIds, $i * $limit, $limit); + if ($is_pool == 2) { + GoodsOfflineJob::dispatch([ + 'list' => $data, + ]); + + } elseif ($is_pool == 1) { + GoodsOnlineJob::dispatch([ + 'list' => $data, + ]); + } + } return $this->renderSuccess('操作成功'); } /** - * 修改商品状态(上下架) + * 修改商品状态(在售、停售) * @param array $goodsIds 商品id集 * @param bool $state 为true表示上架 * @return Json */ public function sale(array $goodsIds, int $is_sale): Json { + $model = new GoodsModel; if (!$model->setIsSale($goodsIds, $is_sale)) { return $this->renderError($model->getError() ?: '操作失败'); } + // 分批每次导入20条 + $limit = 20; + // 根据商品总数量计算需要的队列任务数量 + $jobCount = \count($goodsIds) / $limit; + // 逐次发布队列任务 + for ($i = 0; $i < $jobCount; $i++) { + $data = array_slice($goodsIds, $i * $limit, $limit); + if ($is_sale == 0) { + GoodsOfflineJob::dispatch([ + 'list' => $data, + ]); + + } elseif ($is_sale == 1) { + GoodsOnlineJob::dispatch([ + 'list' => $data, + ]); + } + } return $this->renderSuccess('操作成功'); } /** @@ -238,7 +280,7 @@ class Goods extends Controller return $this->renderSuccess('操作成功'); } /** - * 修改商品状态(上下架) + * 商品归类 * @param array $goodsIds 商品id集 * @param bool $state 为true表示上架 * @return Json @@ -263,8 +305,20 @@ class Goods extends Controller { $model = new GoodsModel; if (!$model->setDelete($goodsIds)) { + return $this->renderError($model->getError() ?: '删除失败'); } + // 分批每次导入20条 + $limit = 20; + // 根据商品总数量计算需要的队列任务数量 + $jobCount = \count($goodsIds) / $limit; + // 逐次发布队列任务 + for ($i = 0; $i < $jobCount; $i++) { + $data = array_slice($goodsIds, $i * $limit, $limit); + GoodsDeleteJob::dispatch([ + 'list' => $data, + ]); + } return $this->renderSuccess('删除成功'); } public function export(){ @@ -372,7 +426,7 @@ class Goods extends Controller return $this->renderSuccess('没有需要加价的商品'); } // 分批每次导入20条 - $limit = 50; + $limit = 20; // 根据商品总数量计算需要的队列任务数量 $jobCount = \count($goodsList) / $limit; // 逐次发布队列任务 diff --git a/app/api/controller/Category.php b/app/api/controller/Category.php index 13267978..1ab340fd 100644 --- a/app/api/controller/Category.php +++ b/app/api/controller/Category.php @@ -46,9 +46,16 @@ class Category extends Controller public function childrenList(): Json { - + $param = $this->request->param(); + $cache_key = "childrenList".json_encode($param).$this->storeId; + if(Cache::has($cache_key)) { + $list = Cache::get($cache_key); + return $this->renderSuccess(compact('list')); + } + $model = new CategoryModel; - $list = $model->getChildrenList($this->request->param()); + $list = $model->getChildrenList($param); + Cache::set($cache_key, $list, 86400); return $this->renderSuccess(compact('list')); } diff --git a/app/api/service/Goods.php b/app/api/service/Goods.php index e4e433f9..9de7aca7 100644 --- a/app/api/service/Goods.php +++ b/app/api/service/Goods.php @@ -160,7 +160,8 @@ class Goods extends GoodsService 'status' => 10, 'categoryId' => $setting['params']['auto']['category'], 'sortType' => $setting['params']['auto']['goodsSort'], - ], $setting['params']['auto']['showNum']); + ], 50); + // ], $setting['params']['auto']['showNum']); $goodsList = $goodsList ? $goodsList->toArray()['data'] : []; } //if (empty($goodsList) && $goodsList->isEmpty()) { diff --git a/app/command/SyncStoreBasicData.php b/app/command/SyncStoreBasicData.php index 34ffbc59..3d2df4bb 100644 --- a/app/command/SyncStoreBasicData.php +++ b/app/command/SyncStoreBasicData.php @@ -26,7 +26,7 @@ use app\store\model\Setting; // /www/server/php/74/bin/php /server/wwwroot/yanzong/think test class SyncStoreBasicData extends Command { - const DEFAULT_STORE_ID = 10045; + const DEFAULT_STORE_ID = 10048; protected function configure() { @@ -45,7 +45,6 @@ class SyncStoreBasicData extends Command protected function execute(Input $input, Output $output) { - exit(); $store_id = $input->getArgument("store_id"); $isSyncMaintenanceData = $input->getArgument("isSyncMaintenanceData"); $isSyncHelpData = $input->getArgument("isSyncHelpData"); @@ -115,13 +114,14 @@ class SyncStoreBasicData extends Command $expressList = Express::where('store_id',self::DEFAULT_STORE_ID)->select()->toArray(); if ($expressList) { foreach ($expressList as &$express) { - $info = Express::where('store_id', $store['store_id'])->where('original_id', $express['express_id'])->find(); + $info = Express::where('store_id', $store['store_id'])->where('kuaidi100_code', $express['kuaidi100_code'])->where('kdniao_code', $express['kdniao_code'])->find(); if ($info) { echo $express['express_id']."物流公司已存在".PHP_EOL; - $ret = Express::where('store_id', $store['store_id'])->where('original_id', $express['express_id'])->update([ + $ret = Express::where('store_id', $store['store_id'])->where('express_id', $info['express_id'])->update([ 'express_name' => $express['express_name'], 'kuaidi100_code' => $express['kuaidi100_code'], 'kdniao_code' => $express['kdniao_code'], + 'original_id' => $express['express_id'], ]); var_dump($ret); continue; diff --git a/app/common/library/wxserver/Server.php b/app/common/library/wxserver/Server.php index 830ee6d2..3b57dd3a 100644 --- a/app/common/library/wxserver/Server.php +++ b/app/common/library/wxserver/Server.php @@ -514,9 +514,9 @@ class Server if ($token) { $url = "https://api.weixin.qq.com/wxa/modify_domain_directly?access_token=$token"; $data['action'] = 'set'; - $data['requestdomain'] = [$domain, 'https://apis.map.gg.com']; - $data['uploaddomain'] = $domain; - $data['downloaddomain'] = $domain; + $data['requestdomain'] = [$domain, 'https://apis.map.gg.com','https://qiniu.shop.royaum.com.cn']; + $data['uploaddomain'] = [$domain,'https://qiniu.shop.royaum.com.cn']; + $data['downloaddomain'] = [$domain,'https://qiniu.shop.royaum.com.cn']; $result = $this->curlPost($url, json_encode($data)); $result = json_decode($result, true); if ($result && !empty($result['errmsg']) && $result['errmsg'] == 'ok') { diff --git a/app/common/library/wxserver/Wholesaler.php b/app/common/library/wxserver/Wholesaler.php index ae975a19..7568d1b6 100644 --- a/app/common/library/wxserver/Wholesaler.php +++ b/app/common/library/wxserver/Wholesaler.php @@ -508,9 +508,9 @@ class Wholesaler if ($token) { $url = "https://api.weixin.qq.com/wxa/modify_domain_directly?access_token=$token"; $data['action'] = 'set'; - $data['requestdomain'] = [$domain, 'https://apis.map.gg.com']; - $data['uploaddomain'] = $domain; - $data['downloaddomain'] = $domain; + $data['requestdomain'] = [$domain, 'https://apis.map.gg.com','https://qiniu.shop.royaum.com.cn']; + $data['uploaddomain'] = [$domain,'https://qiniu.shop.royaum.com.cn']; + $data['downloaddomain'] = [$domain,'https://qiniu.shop.royaum.com.cn']; $result = $this->curlPost($url, json_encode($data)); Db::table('yoshop_wx_server')->insertGetId(['content' => "设置域名信息", 'created_at' => date('Y-m-d H:i:s')]); Db::table('yoshop_wx_server')->insertGetId(['content' => $result, 'created_at' => date('Y-m-d H:i:s')]); diff --git a/app/common/model/Goods.php b/app/common/model/Goods.php index f68e8954..571eb105 100644 --- a/app/common/model/Goods.php +++ b/app/common/model/Goods.php @@ -347,8 +347,10 @@ class Goods extends BaseModel if (isset($param['fliter_condition']) && $param['fliter_condition']) { $fliter_condition = json_decode($param['fliter_condition'], true); + $categorys = []; $str = ""; foreach ($fliter_condition as $value) { + $categorys = array_merge($categorys, $value['category']); $strConditon = "("; $strConditon .= "goods_category_rel.category_id in (".implode(",", $value['category']).")"; $strConditon .= " and goods.profit >= ".$value['profit']; @@ -356,15 +358,28 @@ class Goods extends BaseModel $str .= $strConditon; } $str = trim($str, "or "); - // 执行查询 - $list = $query->with(['images.file']) - ->alias($this->name) - ->field($field) - ->where('is_delete', '=', 0) - ->where($str) - ->group("goods.goods_id") - ->order($sort) - ->paginate($listRows); + //筛选的分类不在当前筛选条件里面就无需带上过滤条件 + if (in_array($param['categoryId'], $categorys)) { + // 执行查询 + $list = $query->with(['images.file']) + ->alias($this->name) + ->field($field) + ->where('is_delete', '=', 0) + ->where($str) + ->group("goods.goods_id") + ->order($sort) + ->paginate($listRows); + } else { + // 执行查询 + $list = $query->with(['images.file']) + ->alias($this->name) + ->field($field) + ->where('is_delete', '=', 0) + ->group("goods.goods_id") + ->order($sort) + ->paginate($listRows); + } + } else { // 执行查询 $list = $query->with(['images.file']) @@ -467,7 +482,7 @@ class Goods extends BaseModel // 商品状态 $params['status'] > 0 && $filter[] = ['status', '=', (int)$params['status']]; - $a = 1; + //$a = 1; // 商品分类 if ($params['categoryId'] > 0 || (isset($params['fliter_condition']) && $params['fliter_condition'])) { // 关联商品与分类关系记录表 @@ -638,17 +653,7 @@ class Goods extends BaseModel if (in_array($goodsInfo['channel'], ['sn','sn1']) && $goodsInfo['link_other']) { $goodsInfo['link'] = $goodsInfo['link_other']; } -// //商品价格判断 -// if (UserService::isLogin()) { -// if (UserService::isStore()) {//店主 -// $goodsInfo['goods_price_min_plus'] = 0; -// $goodsInfo['goods_price_min_dealer'] = 0; -// } elseif (UserService::isDealerMember()) { //分销商 -// $goodsInfo['goods_price_min_dealer'] = 0; -// } elseif (UserService::isPlusMember()) {//升级会员 -// $goodsInfo['goods_price_min_plus'] = 0; -// } -// } + // 回调函数 is_callable($callback) && call_user_func($callback, $goodsInfo); return $goodsInfo; diff --git a/app/job/controller/goods/GoodsDelete.php b/app/job/controller/goods/GoodsDelete.php new file mode 100644 index 00000000..2ad7ce79 --- /dev/null +++ b/app/job/controller/goods/GoodsDelete.php @@ -0,0 +1,49 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\job\controller\goods; + +use app\job\service\goods\GoodsDelete as GoodsDeleteService; +use cores\BaseJob; +use cores\traits\QueueTrait; +use cores\exception\BaseException; +use think\db\exception\DataNotFoundException; +use think\db\exception\DbException; +use think\db\exception\ModelNotFoundException; + +/** + * 队列任务:商品批量导入 + * Class Import + * @package app\job\controller + */ +class GoodsDelete extends BaseJob +{ + use QueueTrait; + + /** + * 消费队列任务:商品导入 + * @param array $data 参数 [index队列顺序;totalCount商品总数量;list商品列表;storeId商城ID] + * @return bool 返回结果 + * @throws BaseException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + */ + public function handle(array $data): bool + { + $time = date('H:i:s'); + echo "\n ---- GoodsDelete ---- {$time} ---- \n"; + + $service = new GoodsDeleteService; + return $service->batch($data['list']); + } +} \ No newline at end of file diff --git a/app/job/controller/goods/GoodsOffline.php b/app/job/controller/goods/GoodsOffline.php new file mode 100644 index 00000000..3f251365 --- /dev/null +++ b/app/job/controller/goods/GoodsOffline.php @@ -0,0 +1,49 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\job\controller\goods; + +use app\job\service\goods\GoodsOffline as GoodsOfflineService; +use cores\BaseJob; +use cores\traits\QueueTrait; +use cores\exception\BaseException; +use think\db\exception\DataNotFoundException; +use think\db\exception\DbException; +use think\db\exception\ModelNotFoundException; + +/** + * 队列任务:商品批量导入 + * Class Import + * @package app\job\controller + */ +class GoodsOffline extends BaseJob +{ + use QueueTrait; + + /** + * 消费队列任务:商品导入 + * @param array $data 参数 [index队列顺序;totalCount商品总数量;list商品列表;storeId商城ID] + * @return bool 返回结果 + * @throws BaseException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + */ + public function handle(array $data): bool + { + $time = date('H:i:s'); + echo "\n ---- GoodsOffline ---- {$time} ---- \n"; + + $service = new GoodsOfflineService; + return $service->batch($data['list']); + } +} \ No newline at end of file diff --git a/app/job/controller/goods/GoodsOnline.php b/app/job/controller/goods/GoodsOnline.php new file mode 100644 index 00000000..7dda50eb --- /dev/null +++ b/app/job/controller/goods/GoodsOnline.php @@ -0,0 +1,49 @@ + +// +---------------------------------------------------------------------- +declare (strict_types=1); + +namespace app\job\controller\goods; + +use app\job\service\goods\GoodsOnline as GoodsOnlineService; +use cores\BaseJob; +use cores\traits\QueueTrait; +use cores\exception\BaseException; +use think\db\exception\DataNotFoundException; +use think\db\exception\DbException; +use think\db\exception\ModelNotFoundException; + +/** + * 队列任务:商品批量导入 + * Class Import + * @package app\job\controller + */ +class GoodsOnline extends BaseJob +{ + use QueueTrait; + + /** + * 消费队列任务:商品导入 + * @param array $data 参数 [index队列顺序;totalCount商品总数量;list商品列表;storeId商城ID] + * @return bool 返回结果 + * @throws BaseException + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + */ + public function handle(array $data): bool + { + $time = date('H:i:s'); + echo "\n ---- GoodsOnline ---- {$time} ---- \n"; + + $service = new GoodsOnlineService; + return $service->batch($data['list']); + } +} \ No newline at end of file diff --git a/app/job/service/goods/AdminImport.php b/app/job/service/goods/AdminImport.php index 784cda48..67fd99a1 100644 --- a/app/job/service/goods/AdminImport.php +++ b/app/job/service/goods/AdminImport.php @@ -1,13 +1,4 @@ -// +---------------------------------------------------------------------- declare (strict_types=1); namespace app\job\service\goods; diff --git a/app/job/service/goods/Collector.php b/app/job/service/goods/Collector.php index 35da573f..9e13cb7b 100644 --- a/app/job/service/goods/Collector.php +++ b/app/job/service/goods/Collector.php @@ -1,13 +1,5 @@ -// +---------------------------------------------------------------------- + declare (strict_types=1); namespace app\job\service\goods; diff --git a/app/job/service/goods/GoodsAddPrice.php b/app/job/service/goods/GoodsAddPrice.php index dabd7ded..595d42d0 100644 --- a/app/job/service/goods/GoodsAddPrice.php +++ b/app/job/service/goods/GoodsAddPrice.php @@ -1,13 +1,5 @@ -// +---------------------------------------------------------------------- + declare (strict_types=1); namespace app\job\service\goods; diff --git a/app/job/service/goods/GoodsDelete.php b/app/job/service/goods/GoodsDelete.php new file mode 100644 index 00000000..46b6dae9 --- /dev/null +++ b/app/job/service/goods/GoodsDelete.php @@ -0,0 +1,49 @@ +where('is_delete',1) + ->field(['goods_id','is_sale','is_pool']) + ->select(); + if ($goods_list->isEmpty()) { + return true; + } + $goodsIds = array_column($goods_list->toArray(), "goods_id"); + GoodsModel::whereIn('origin_goods_id', $goodsIds)->update(['is_delete' => 1, 'update_time' => time()]); + + return true; + } + + +} \ No newline at end of file diff --git a/app/job/service/goods/GoodsOffline.php b/app/job/service/goods/GoodsOffline.php new file mode 100644 index 00000000..718cd850 --- /dev/null +++ b/app/job/service/goods/GoodsOffline.php @@ -0,0 +1,52 @@ +where('is_delete',0) + ->where(function($query){ + $query->where('is_pool',2)->whereOr('is_sale',0); + }) + ->field(['goods_id','is_sale','is_pool']) + ->select(); + if ($goods_list->isEmpty()) { + return true; + } + $goodsIds = array_column($goods_list->toArray(), "goods_id"); + GoodsModel::whereIn('origin_goods_id', $goodsIds)->update(['status' => 20, 'is_jd_remove' => 1, 'update_time' => time()]); + + return true; + } + + +} \ No newline at end of file diff --git a/app/job/service/goods/GoodsOnline.php b/app/job/service/goods/GoodsOnline.php new file mode 100644 index 00000000..2aa1321c --- /dev/null +++ b/app/job/service/goods/GoodsOnline.php @@ -0,0 +1,50 @@ +where('is_delete',0) + ->where('is_sale',1) + ->where('is_pool',1) + ->field(['goods_id','is_sale','is_pool']) + ->select(); + if ($goods_list->isEmpty()) { + return true; + } + $goodsIds = array_column($goods_list->toArray(), "goods_id"); + GoodsModel::whereIn('origin_goods_id', $goodsIds)->update(['status' => 10, 'is_jd_remove' => 0, 'update_time' => time()]); + return true; + } + + +} \ No newline at end of file diff --git a/app/job/service/goods/GoodsStoreImport.php b/app/job/service/goods/GoodsStoreImport.php index 0e65135f..208b95c2 100644 --- a/app/job/service/goods/GoodsStoreImport.php +++ b/app/job/service/goods/GoodsStoreImport.php @@ -1,13 +1,5 @@ -// +---------------------------------------------------------------------- + declare (strict_types=1); namespace app\job\service\goods; diff --git a/app/job/service/goods/GoodsUpdateImport.php b/app/job/service/goods/GoodsUpdateImport.php index abda8277..ead18bb7 100644 --- a/app/job/service/goods/GoodsUpdateImport.php +++ b/app/job/service/goods/GoodsUpdateImport.php @@ -1,13 +1,5 @@ -// +---------------------------------------------------------------------- + declare (strict_types=1); namespace app\job\service\goods;