lqmac 4 months ago
parent 5c8eb7cb89
commit 80b46c3d28
  1. 1
      app/admin/controller/Goods.php
  2. 1
      app/api/controller/Goods.php
  3. 2
      app/api/controller/GoodsNew.php
  4. 14
      app/api/model/Goods.php
  5. 5
      app/api/service/Cart.php
  6. 18
      app/common/model/Goods.php
  7. 8
      app/common/service/GoodsCateEs.php
  8. 41
      app/job/controller/goods/StoreGoodsDelete.php
  9. 40
      app/job/controller/goods/StoreGoodsOffline.php
  10. 40
      app/job/controller/goods/StoreGoodsOnline.php
  11. 28
      app/job/service/goods/Collector.php
  12. 54
      app/job/service/goods/GoodsOfflineStore.php
  13. 7
      app/job/service/goods/GoodsUpdateImport.php
  14. 50
      app/job/service/goods/StoreGoodsDelete.php
  15. 52
      app/job/service/goods/StoreGoodsOnline.php
  16. 47
      app/store/controller/Controller.php
  17. 4
      app/store/controller/Goods.php
  18. 6
      app/store/model/Category.php
  19. 17
      app/store/model/Goods.php

@ -359,6 +359,7 @@ class Goods extends Controller
['is_check'=>'是否审单(是填1 否填0)'],
['is_use_jd_stock'=>'是否使用京东库存(是填1 否填0)'],
['video_id'=>'是否覆盖商品(是填1 否填0)'],
['video_id'=>'商品分类ID集'],
];
downLoadExcel('导出数据-'.date('Y-m-d', time()),$titles,$data['data']);

@ -40,6 +40,7 @@ class Goods extends Controller
$param = $this->request->param();
//限制过滤条件-渠道
$param['channels'] = $this->storeInfo['open_channel'] ? array_merge(['zy'], explode(",", $this->storeInfo['open_channel'])) : [];
$param['p_store_id'] = $this->storeInfo->p_store_id;
//分类利润-利润率
$param['fliter_condition'] = $this->storeInfo['fliter_condition'];
if (isset($param['keyword']) && $param['keyword']) {

@ -25,7 +25,7 @@ class GoodsNew extends Controller
$param['channels'] = $this->storeInfo['open_channel'] ? array_merge(['zy'], explode(",", $this->storeInfo['open_channel'])) : [];
$param['fliter_condition'] = $this->storeInfo['fliter_condition'];
$param['status'] = 10;
$param['store_id'] = $this->storeId;
$param['store_id'] = 10038;//$this->storeId;
$goodsService = new GoodsCateEs();
$data = $goodsService->list($param, $page, $pageSize);

@ -715,21 +715,21 @@ class Goods extends GoodsModel
$catService = new GoodsCategoryRel();
$catIds = $catService->where(['goods_id' => $goods->goods_id])->column('category_id');
$goods['line_price_min'] = $goods['goods_price_min'];//划线价格等于市场价
//$goods['discount'] = 0.0;
$goods['discount'] = 0.0;
//价格判断
if (UserService::isstore()) {
$priceArr = \app\common\model\PriceSet::distributionPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds);
$goods['goods_price_min_plus'] = $priceArr['membershipPrice'];
$goods['goods_price_min_dealer'] = $priceArr['distributionPrice'];
$goods['goods_price_min'] = $goods['goods_price_min_plus'];//$goods['cost_price_min'];//店长售价,展示为成本价
$goods['discount'] = bcdiv((string)($priceArr['distributionPrice'] * 10), (string)$goods['goods_price_min'], 1);
} elseif (UserService::isPlusMember()) {
$membershipPrice = \app\common\model\PriceSet::membershipPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds);
//$goods['discount'] = bcdiv((string)($membershipPrice * 10), (string)$goods['goods_price_min'], 1);
$goods['discount'] = bcdiv((string)($membershipPrice * 10), (string)$goods['goods_price_min'], 1);
$goods['goods_price_min'] = $membershipPrice;
} elseif (UserService::isDealerMember()) {
$priceArr = \app\common\model\PriceSet::distributionPrice($goods['goods_price_min'], $goods['cost_price_min'], $catIds);
//$goods['discount'] = bcdiv((string)($priceArr['distributionPrice'] * 10), (string)$goods['goods_price_min'], 1);
$goods['discount'] = bcdiv((string)($priceArr['distributionPrice'] * 10), (string)$goods['goods_price_min'], 1);
//$goods['goods_price_min'] = $membershipPrice;
$goods['goods_price_min'] = $priceArr['distributionPrice'];
}
@ -738,9 +738,9 @@ class Goods extends GoodsModel
$goods['goods_price_min'] = $goods['seckill_price'];
}
// if ($goods['discount'] == 10) {
// $goods['discount'] = 0.0;
// }
if ($goods['discount'] == 10) {
$goods['discount'] = 0.0;
}
// 会员折扣价: 商品sku列表
if ($goods->getRelation('skuList') || $goods->getRelation('skuList1')) {

@ -50,6 +50,9 @@ class Cart extends BaseService
foreach ($cartList as $cartIdx => $item) {
// 查找商品, 商品不存在则删除该购物车记录
$result = $this->findGoods($goodsList, $item, $enableGradeMoney);
if ($result !== false) {
$cartList[$cartIdx]['goods'] = $result;
//商户信息处理
if ($result['merchant_id'] && !in_array($result['channel'], config('app.not_show_merchant'))) {
$merchant = \app\common\model\Merchant::detail($result['merchant_id'], $result['store_id']);
@ -59,8 +62,6 @@ class Cart extends BaseService
$result['merchant'] = null;
}
if ($result !== false) {
$cartList[$cartIdx]['goods'] = $result;
} else {
$this->clear([$item['id']]);
unset($cartList[$cartIdx]);

@ -279,7 +279,10 @@ class Goods extends BaseModel
*/
public function getList(array $param = [], int $listRows = 15)
{
$storeId = self::$storeId;
//去掉where条件store_id
self::$storeId = 0;
app()->request->setStoreId(0);
// 筛选条件
$query = $this->getQueryFilter($param);
// 设置显示的销量 goods_sales
@ -319,6 +322,10 @@ class Goods extends BaseModel
$query = $query->whereRaw('goods_name like ? or goods_no like ?', ["%{$val}%", "%{$val}%"]);
}
}
$storeIds = [$storeId];
if (isset($param['p_store_id']) && $param['p_store_id']) {
$storeIds[] = $param['p_store_id'];
}
//数据渠道过滤特殊处理
if (isset($param['fliter_condition']) && $param['fliter_condition']) {
$fliter_condition = json_decode($param['fliter_condition'], true);
@ -340,6 +347,7 @@ class Goods extends BaseModel
$list = $query->with(['images.file'])
->alias($this->name)
->field($field)
->whereIn('goods.store_id', $storeIds)
->where('is_delete', '=', 0)
->where($str)
->group("goods.goods_id")
@ -350,6 +358,7 @@ class Goods extends BaseModel
$list = $query->with(['images.file'])
->alias($this->name)
->field($field)
->whereIn('goods.store_id', $storeIds)
->where('is_delete', '=', 0)
->group("goods.goods_id")
->order($sort)
@ -361,6 +370,7 @@ class Goods extends BaseModel
$list = $query->with(['images.file'])
->alias($this->name)
->field($field)
->whereIn('goods.store_id', $storeIds)
->where('is_delete', '=', 0)
->group("goods.goods_id")
->order($sort)
@ -475,7 +485,11 @@ class Goods extends BaseModel
$filter[] = ['goods.goods_id', 'in', explode(",", $param['goodsIds'])];
}
// 商品名称
!empty($params['goodsName']) && $filter[] = ['goods_name', 'like', "%{$params['goodsName']}%"];
if (!empty($params['goodsName'])) {
$goods_name = str_replace(" ", "", $params['goodsName']);
$query->where("REPLACE(`goods_name`, ' ', '') LIKE '%". $goods_name . "%'");
//$filter[] = ["REPLACE(`goods_name`, ' ', '')", 'like', "%{$goods_name}%"];
}
// 商品编码
!empty($params['goodsNo']) && $filter[] = ['goods_no', 'like', "%{$params['goodsNo']}%"];

@ -42,10 +42,14 @@ class GoodsCateEs
$equal[] = ['is_delete' => 0];
//等于查询
if (isset($params['status']) && $params['status']) {
$equal[] = ['status' => $params['status'] ?? 0];
$equal[] = ['status' => $params['status']];
}
if (isset($params['store_id']) && $params['store_id']) {
$equal[] = ['store_id' => $params['store_id'] ?? 0];
$storeIds = [$params['store_id']];
if (isset($params['p_store_id']) && $params['p_store_id']) {
$storeIds[] = $params['p_store_id'];
}
$ins[] = ['store_id' => $storeIds];
}
if (isset($params['merchantId']) && $params['merchantId']) {
$equal[] = ['merchant_id' => $params['merchantId'] ?? 0];

@ -0,0 +1,41 @@
<?php
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']);
}
}

@ -0,0 +1,40 @@
<?php
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']);
}
}

@ -0,0 +1,40 @@
<?php
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']);
}
}

@ -14,7 +14,7 @@ use app\store\model\GoodsImage as GoodsImageModel1;
use app\common\model\store\Setting as SettingModel;
use app\common\model\GoodsSpecRel as GoodsSpecRelModel;
use app\common\model\goods\Collector as GoodsCollectorModel;
use app\common\model\GoodsCategoryRel as GoodsCategoryRelModel;
use app\store\model\GoodsCategoryRel as GoodsCategoryRelModel;
use app\common\enum\Setting as SettingEnum;
use app\common\enum\file\FileType as FileTypeEnum;
use app\common\enum\goods\SpecType as GoodsSpecTypeEnum;
@ -253,7 +253,7 @@ class Collector extends BaseService
$model->transaction(function () use ($model, $data, $storeId) {
// 添加商品
$model->save($data);
$model->where('goods_id', (int)$model['goods_id'])->update(['spu_id' => (int)$model['goods_id']]);
//$model->where('goods_id', (int)$model['goods_id'])->update(['spu_id' => (int)$model['goods_id']]);
// 新增商品与分类关联
GoodsCategoryRelModel::increased((int)$model['goods_id'], $data['categoryIds'], $storeId);
// 新增商品与图片关联
@ -326,8 +326,12 @@ class Collector extends BaseService
// exit;
tre($e->getTraceAsString());
$errorLog = ['goodsSn' => $form['goods_id'], 'message' => trim($url).$e->getMessage()];
return [true, $errorLog];
return [false, $errorLog];
} catch (\Exception $e){
$errorLog = ['goodsSn' => $form['goods_id'], 'message' => trim($url).$e->getMessage()];
return [false, $errorLog];
}
// if ($original['goods_price'] == 0) {
// return false;
// }
@ -337,6 +341,12 @@ class Collector extends BaseService
$data['content'] = $original['content'];
if ($original['content']) {
$data['is_has_detail'] = 1;
}
if ($original['imagesIds']) {
$data['is_has_banner'] = 1;
}
//重新计算利润和利润率
$data['goods_source'] = $form['goods_source'];
@ -344,6 +354,8 @@ class Collector extends BaseService
$data['delivery_time'] = $form['delivery_time'];
$data['is_check'] = $form['is_check'];
$data['is_use_jd_stock'] = $form['is_use_jd_stock'];
$data['categoryIds'] = $form['categoryIds'];
$data['cate_status'] = $form['categoryIds'] ? 1 : 0;
$data['goods_price_min'] = $original['goods_price'];
$data['goods_price_max'] = $original['goods_price'];
$data['line_price_min'] = $original['goods_price'];
@ -388,11 +400,16 @@ class Collector extends BaseService
// var_dump($data);
// var_dump($goodsSku);
// exit();
$model->transaction(function () use ($form, $data, $original, $goodsSku) {
$model->transaction(function () use ($goods, $form, $data, $original, $goodsSku) {
$data['update_time'] = time();
$data['import_time'] = time();
//$data['goods_id'] = $form['goods_id'];
// 添加商品
GoodsModel::where('goods_id', $form['goods_id'])->update($data);
$goods->save($data);
//GoodsModel::where('goods_id', $form['goods_id'])->update($data);
// 新增商品与分类关联
GoodsCategoryRelModel::updates((int)$form['goods_id'], $data['categoryIds']);
// 新增商品与图片关联
GoodsImageModel1::updates((int)$form['goods_id'], $original['imagesIds']);
//更新sku信息
@ -568,6 +585,7 @@ class Collector extends BaseService
'status' => $form['goods_status'],
'imagesIds' => $original['imagesIds'],
'categoryIds' => $form['categoryIds'],
'cate_status' => $form['categoryIds'] ? 1 : 0,
// 下面是默认数据, 没有会报错
'alone_grade_equity' => [],
'newSpecList' => [],

@ -0,0 +1,54 @@
<?php
declare (strict_types=1);
namespace app\job\service\goods;
use app\common\library\helper;
use app\common\service\BaseService;
use app\common\model\Goods as GoodsModel;
use app\common\model\GoodsSku;
use app\store\model\GoodsCategoryRel;
use cores\exception\BaseException;
use think\facade\Log;
use app\common\model\Channel;
use app\common\model\Region;
/**
* 服务类:商品批量导入
* Class Import
* @package app\job\service\goods
*/
class GoodsOffline extends BaseService
{
/**
* 批量导入商品
* @param array $list
* @param int $recordId
* @param int $storeId
* @return bool
* @throws BaseException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function batch(array $goodsIds): bool
{
$goods_list = GoodsModel::whereIn('goods_id', $goodsIds)
->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()]);
GoodsModel::whereIn('origin_goods_id', $goodsIds)->update(['is_delete' => 1, 'update_time' => time()]);
//下架批发商城的商品
return true;
}
}

@ -134,8 +134,15 @@ class GoodsUpdateImport extends BaseService
'is_check' => $original['L'] ?? 0,
'is_use_jd_stock' => $original['M'] ?? 0,
'is_cover' => $original['N'] ?? 0,//是否覆盖
'categoryIds' => $this->ids2array($original["O"]),
];
$data['categoryIds'] = CategoryModel::filterCategoryIds($data['categoryIds'], $storeId);
//处理分类,设置最后一级一直往上查找
$model = new \app\store\model\Goods();
$data['categoryIds'] = $model->dealCategory($data['categoryIds']);
return $data;
}

@ -0,0 +1,50 @@
<?php
declare (strict_types=1);
namespace app\job\service\goods;
use app\common\library\helper;
use app\common\service\BaseService;
use app\common\model\Goods as GoodsModel;
use app\common\model\GoodsSku;
use app\store\model\GoodsCategoryRel;
use cores\exception\BaseException;
use think\facade\Log;
use app\common\model\Channel;
use app\common\model\Region;
/**
* 服务类:商品批量导入
* Class Import
* @package app\job\service\goods
*/
class GoodsDelete extends BaseService
{
/**
* 批量导入商品
* @param array $list
* @param int $recordId
* @param int $storeId
* @return bool
* @throws BaseException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function batch(array $goodsIds): bool
{
$goods_list = GoodsModel::whereIn('goods_id', $goodsIds)
->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;
}
}

@ -0,0 +1,52 @@
<?php
declare (strict_types=1);
namespace app\job\service\goods;
use app\common\library\helper;
use app\common\service\BaseService;
use app\common\model\Goods as GoodsModel;
use app\common\model\GoodsSku;
use app\store\model\GoodsCategoryRel;
use cores\exception\BaseException;
use think\facade\Log;
use app\common\model\Channel;
use app\common\model\Region;
/**
* 服务类:商品批量导入
* Class Import
* @package app\job\service\goods
*/
class GoodsOnline extends BaseService
{
/**
* 批量导入商品
* @param array $list
* @param int $recordId
* @param int $storeId
* @return bool
* @throws BaseException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function batch(array $goodsIds): bool
{
$goods_list = GoodsModel::whereIn('goods_id', $goodsIds)
->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(), 'is_delete' => 0]);
//上架批发商城的商品
return true;
}
}

@ -33,7 +33,7 @@ class Controller extends BaseController
// 当前商城ID
protected int $storeId;
// protected $storeInfo;
protected $storeInfo;
// 当前商户ID
protected int $merchantId = 0;
@ -88,7 +88,7 @@ class Controller extends BaseController
$this->getMerchantId();
// 验证当前商城状态
// $this->checkStore();
$this->checkStore();
}
/**
@ -194,26 +194,29 @@ class Controller extends BaseController
throwError('illegal request method');
}
// /**
// * 验证当前商城状态
// * @return void
// * @throws BaseException
// */
// private function checkStore(): void
// {
// // 获取当前商城信息
// $store = StoreModel::detail($this->storeId);
// if (empty($store)) {
// throwError('很抱歉,当前商城信息不存在');
// }
// if ($store['is_recycle'] || $store['is_delete']) {
// throwError('很抱歉,当前商城已删除');
// }
// if($store['effective_time']<time()){
// throwError('很抱歉,当前商城已过期');
// }
// $this->storeInfo = $store;
// }
/**
* 验证当前商城状态
* @return void
* @throws BaseException
*/
private function checkStore(): void
{
if (!$this->storeId) {
return;
}
// 获取当前商城信息
$store = StoreModel::detail($this->storeId);
if (empty($store)) {
throwError('很抱歉,当前商城信息不存在');
}
if ($store['is_recycle'] || $store['is_delete']) {
throwError('很抱歉,当前商城已删除');
}
if($store['effective_time']<time()){
throwError('很抱歉,当前商城已过期');
}
$this->storeInfo = $store;
}
}

@ -40,6 +40,10 @@ class Goods extends Controller
if (!isset($params['merchant_id']) || !$params['merchant_id']) {
$params['merchant_id'] = $this->merchantId;
}
$params['p_store_id'] = $this->storeInfo->p_store_id;
// echo "<pre>";
// print_r($this->storeInfo->p_store_id);
// exit();
$list = $model->getList($params, (int)$this->request->param('pageSize', 15));
if ($list->isEmpty()) {
return $this->renderSuccess(compact('list'));

@ -44,17 +44,19 @@ class Category extends CategoryModel
*/
public function edit($data): bool
{
ini_set('memory_limit', '1024M');
set_time_limit(0);
// 判断上级分类是否为当前子级
if ($data['parent_id'] > 0) {
// 获取所有上级id集
$parentIds = $this->getTopCategoryIds($data['parent_id']);
if (in_array($this['category_id'], $parentIds)) {
$this->error = '上级分类不允许设置为当前子分类';
return false;
}
$cate = $this->where('category_id', $data['parent_id'])->find();
// var_dump($cate['level']);
// exit();
$data['level'] = $cate ? $cate['level'] + 1 : 1;
}

@ -155,7 +155,11 @@ class Goods extends GoodsModel
if ($data['spec_type'] == GoodsSpecTypeEnum::MULTI) {
$data['spu_id'] = $this['goods_id'];
//取消之前所有的商品组商品
} else {
$data['spu_id'] = 0;
}
// 更新商品
$this->save($data);
// 更新商品与分类关联
@ -415,6 +419,19 @@ class Goods extends GoodsModel
}
if ($data['categoryIds']) {
$data['cate_status'] = 1;
} else {
$data['cate_status'] = 0;
}
if ($data['content']) {
$data['is_has_detail'] = 1;
} else {
$data['is_has_detail'] = 0;
}
if ($data['imagesIds']) {
$data['is_has_banner'] = 1;
} else {
$data['is_has_banner'] = 0;
}
return $data;

Loading…
Cancel
Save