|
|
@@ -293,32 +293,33 @@ class GoodsClass extends BaseClass
|
|
|
return $info;
|
|
|
}
|
|
|
|
|
|
- public static function getGoodsData($where,$params){
|
|
|
+ public static function getGoodsData($where, $params)
|
|
|
+ {
|
|
|
// 获取分页参数
|
|
|
$page = Yii::$app->request->get('page', 1);
|
|
|
$pageSize = Yii::$app->request->get('pageSize', 20);
|
|
|
-
|
|
|
+
|
|
|
$flowerNum = $params['flowerNum'] ?? 0;
|
|
|
// 查询某分类下有库存的商品
|
|
|
$query = GoodsCategory::find()
|
|
|
->where($where)
|
|
|
- ->joinWith(['goods' => function($query) use ($flowerNum) {
|
|
|
+ ->joinWith(['goods' => function ($query) use ($flowerNum) {
|
|
|
$query->andWhere(['delStatus' => 0]);
|
|
|
$query->andWhere(['>', 'stock', 0]);
|
|
|
- if(isset($flowerNum) && $flowerNum > 0){
|
|
|
- $query->andWhere(['flowerNum' => $flowerNum]);
|
|
|
+ if (isset($flowerNum) && $flowerNum > 0) {
|
|
|
+ $query->andWhere(['flowerNum' => $flowerNum]);
|
|
|
}
|
|
|
}])
|
|
|
->orderBy(['inTurn' => SORT_DESC]);
|
|
|
-
|
|
|
+
|
|
|
// 获取总数
|
|
|
$total = $query->count();
|
|
|
-
|
|
|
+
|
|
|
// 分页查询
|
|
|
$goodsList = $query->offset(($page - 1) * $pageSize)
|
|
|
->limit($pageSize)
|
|
|
->all();
|
|
|
-
|
|
|
+
|
|
|
// 整理结果,只要有库存的商品
|
|
|
$list = [];
|
|
|
foreach ($goodsList as $goodsCategory) {
|
|
|
@@ -326,7 +327,7 @@ class GoodsClass extends BaseClass
|
|
|
$list[] = $goodsCategory->goods->attributes;
|
|
|
}
|
|
|
}
|
|
|
- if(!empty($list)){
|
|
|
+ if (!empty($list)) {
|
|
|
$list = self::groupGoodsBaseInfo($list);
|
|
|
}
|
|
|
|
|
|
@@ -343,22 +344,22 @@ class GoodsClass extends BaseClass
|
|
|
}
|
|
|
|
|
|
//组装商品基本信息 ssh 2019.12.2
|
|
|
- public static function groupGoodsBaseInfo($list, $getItem = false, $sortIds= [])
|
|
|
+ public static function groupGoodsBaseInfo($list, $getItem = false, $sortIds = [])
|
|
|
{
|
|
|
$newList = [];
|
|
|
$arrNotEmpty = is_array($sortIds) && !empty($sortIds);
|
|
|
-
|
|
|
+
|
|
|
//注意这里涉及商家节日涨价的问题,不要去取不同商家的商品,确有必要另外起方法!!!!!!!!!!
|
|
|
$currentData = current($list);
|
|
|
$mainId = $currentData['mainId'] ?? 0;
|
|
|
$rise = GoodsSettingClass::getRise($mainId);
|
|
|
$sjHasCategory = CategoryClass::getCategory($mainId);
|
|
|
-
|
|
|
+
|
|
|
// 收集所有商品ID
|
|
|
$goodsIds = array_column($list, 'id');
|
|
|
// 一次性获取所有商品的分类关系
|
|
|
$allGoodsCategories = GoodsCategoryClass::getGoodsHasCategoryIdsBatch($goodsIds);
|
|
|
-
|
|
|
+
|
|
|
foreach ($list as $key => $val) {
|
|
|
$id = $val['id'];
|
|
|
//大中小图片转化
|
|
|
@@ -420,11 +421,11 @@ class GoodsClass extends BaseClass
|
|
|
$val['sortWeight'] = $sortIndex !== false ? $sortIndex : count($sortIds);
|
|
|
}
|
|
|
|
|
|
- $list[$key] = $val;
|
|
|
+ $list[$key] = $val;
|
|
|
}
|
|
|
|
|
|
if ($arrNotEmpty) {
|
|
|
- usort($list, function($a, $b) {
|
|
|
+ usort($list, function ($a, $b) {
|
|
|
return $a['sortWeight'] - $b['sortWeight'];
|
|
|
});
|
|
|
//return $newList;
|
|
|
@@ -598,14 +599,14 @@ class GoodsClass extends BaseClass
|
|
|
}
|
|
|
//精确处理分类变更:分别处理删除、新增、修改三种情况
|
|
|
$goodsHasCategoryIds = GoodsCategoryService::getGoodsHasCategoryIds($id);
|
|
|
-
|
|
|
+
|
|
|
// 1. 找出需要删除的分类:原有分类中不在新分类列表中的
|
|
|
$toDeleteCategoryIds = array_diff($goodsHasCategoryIds, $categoryIdList);
|
|
|
if (!empty($toDeleteCategoryIds)) {
|
|
|
GoodsCategoryClass::deleteByCondition(['gId' => $id, 'cId' => ['in', $toDeleteCategoryIds]]);
|
|
|
CategoryClass::counters(['goodsNum' => -1], ['id' => $toDeleteCategoryIds]);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 2. 找出需要新增的分类:新分类列表中不在原有分类中的
|
|
|
$toAddCategoryIds = array_diff($categoryIdList, $goodsHasCategoryIds);
|
|
|
if (!empty($toAddCategoryIds)) {
|
|
|
@@ -628,7 +629,7 @@ class GoodsClass extends BaseClass
|
|
|
GoodsCategoryClass::batchAdd($addCategory);
|
|
|
CategoryClass::counters(['goodsNum' => 1], ['id' => $toAddCategoryIds]);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 3. 处理需要修改的分类:既在原有分类中也在新分类列表中的
|
|
|
$toUpdateCategoryIds = array_intersect($goodsHasCategoryIds, $categoryIdList);
|
|
|
if (!empty($toUpdateCategoryIds)) {
|
|
|
@@ -644,7 +645,7 @@ class GoodsClass extends BaseClass
|
|
|
GoodsCategoryClass::updateByCondition(['gId' => $id, 'cId' => $categoryId], $updateData);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 兼容 cover 参数是数字
|
|
|
if (intval($data['cover']) > 0) {
|
|
|
// 如果是大于0的整数,说明是图片序号
|
|
|
@@ -804,84 +805,84 @@ class GoodsClass extends BaseClass
|
|
|
//改库存
|
|
|
$newStock = $goodsData['stock'] - $num;
|
|
|
|
|
|
- if ($newStock < 0) {
|
|
|
-
|
|
|
- $goodsName = $goodsData['name'] ?? '';
|
|
|
- if ($checkStock) {
|
|
|
- util::fail($goodsName . '库存不足,剩余:' . $goodsData['stock']);
|
|
|
- }
|
|
|
-
|
|
|
- $flower = $goodsData['flower'] ?? 0;
|
|
|
- if ($flower == 0) {
|
|
|
- util::complete('绿植盆栽资材类无法生成制作单');
|
|
|
- }
|
|
|
-
|
|
|
- //缺的库存生成制作单
|
|
|
- $sjId = $goodsData['sjId'] ?? 0;
|
|
|
- $orderSn = $params['orderSn'] ?? '';
|
|
|
- $orderId = $params['orderId'] ?? 0;
|
|
|
- $shopId = $params['shopId'] ?? 0;
|
|
|
- $orderPrice = $params['orderPrice'] ?? 0;
|
|
|
- $fromType = $params['fromType'] ?? 1;
|
|
|
- $remark = $params['remark'] ?? '';
|
|
|
- $orderDebtPrice = $params['orderDebtPrice'] ?? 0;
|
|
|
- $sendType = $params['sendType'] ?? 0;
|
|
|
- $thirdSn = $params['thirdSn'] ?? '';
|
|
|
- $cardInfo = $params['cardInfo'] ?? '';
|
|
|
- $anonymity = $params['anonymity'] ?? 0;
|
|
|
- $manyType = $params['manyType'] ?? 0;
|
|
|
- $sendNum = $params['sendNum'] ?? '';
|
|
|
- $hasReachTime = 0;
|
|
|
- $reachPeriod = 0;
|
|
|
- $reachDate = '0000-00-00';
|
|
|
- $staffName = '';
|
|
|
- $staffId = 0;
|
|
|
- $bookName = '';
|
|
|
- if (!empty($orderId)) {
|
|
|
- $order = OrderClass::getById($orderId, true);
|
|
|
- if (!empty($order)) {
|
|
|
- $reachDate = $order->reachDate ?? '';
|
|
|
- if (!empty($reachDate) && $reachDate != '0000-00-00') {
|
|
|
- $hasReachTime = 1;
|
|
|
- }
|
|
|
- $reachPeriod = $order->reachPeriod ?? 0;
|
|
|
- $staffName = $order->shopAdminName ?? '';
|
|
|
- $staffId = $order->shopAdminId ?? '';
|
|
|
- $bookName = $order->bookName ?? '';
|
|
|
+ //不管有没库存,都生成任务
|
|
|
+
|
|
|
+ $goodsName = $goodsData['name'] ?? '';
|
|
|
+ if ($checkStock) {
|
|
|
+ util::fail($goodsName . '库存不足,剩余:' . $goodsData['stock']);
|
|
|
+ }
|
|
|
+
|
|
|
+ $flower = $goodsData['flower'] ?? 0;
|
|
|
+ if ($flower == 0) {
|
|
|
+ util::complete('绿植盆栽资材类无法生成制作单');
|
|
|
+ }
|
|
|
+
|
|
|
+ //缺的库存生成制作单
|
|
|
+ $sjId = $goodsData['sjId'] ?? 0;
|
|
|
+ $orderSn = $params['orderSn'] ?? '';
|
|
|
+ $orderId = $params['orderId'] ?? 0;
|
|
|
+ $shopId = $params['shopId'] ?? 0;
|
|
|
+ $orderPrice = $params['orderPrice'] ?? 0;
|
|
|
+ $fromType = $params['fromType'] ?? 1;
|
|
|
+ $remark = $params['remark'] ?? '';
|
|
|
+ $orderDebtPrice = $params['orderDebtPrice'] ?? 0;
|
|
|
+ $sendType = $params['sendType'] ?? 0;
|
|
|
+ $thirdSn = $params['thirdSn'] ?? '';
|
|
|
+ $cardInfo = $params['cardInfo'] ?? '';
|
|
|
+ $anonymity = $params['anonymity'] ?? 0;
|
|
|
+ $manyType = $params['manyType'] ?? 0;
|
|
|
+ $sendNum = $params['sendNum'] ?? '';
|
|
|
+ $hasReachTime = 0;
|
|
|
+ $reachPeriod = 0;
|
|
|
+ $reachDate = '0000-00-00';
|
|
|
+ $staffName = '';
|
|
|
+ $staffId = 0;
|
|
|
+ $bookName = '';
|
|
|
+ if (!empty($orderId)) {
|
|
|
+ $order = OrderClass::getById($orderId, true);
|
|
|
+ if (!empty($order)) {
|
|
|
+ $reachDate = $order->reachDate ?? '';
|
|
|
+ if (!empty($reachDate) && $reachDate != '0000-00-00') {
|
|
|
+ $hasReachTime = 1;
|
|
|
}
|
|
|
+ $reachPeriod = $order->reachPeriod ?? 0;
|
|
|
+ $staffName = $order->shopAdminName ?? '';
|
|
|
+ $staffId = $order->shopAdminId ?? '';
|
|
|
+ $bookName = $order->bookName ?? '';
|
|
|
}
|
|
|
- $sh = $goodsData['sh'] ?? 0;
|
|
|
- $params = [
|
|
|
- 'goods' => [['productId' => $goodsId, 'num' => abs($num)]],
|
|
|
- 'sjId' => $sjId,
|
|
|
- 'mainId' => $mainId,
|
|
|
- 'orderSn' => $orderSn,
|
|
|
- 'orderId' => $orderId,
|
|
|
- 'hasReachTime' => $hasReachTime,
|
|
|
- 'reachPeriod' => $reachPeriod,
|
|
|
- 'reachDate' => $reachDate,
|
|
|
- 'shopId' => $shopId,
|
|
|
- 'staffName' => $staffName,
|
|
|
- 'staffId' => $staffId,
|
|
|
- 'bookName' => $bookName,
|
|
|
- 'orderPrice' => $orderPrice,
|
|
|
- 'orderDebtPrice' => $orderDebtPrice,
|
|
|
- 'fromType' => $fromType,
|
|
|
- 'sendType' => $sendType,
|
|
|
- 'remark' => $remark,
|
|
|
- 'thirdSn' => $thirdSn,
|
|
|
- 'cardInfo' => $cardInfo,
|
|
|
- 'anonymity' => $anonymity,
|
|
|
- 'sh' => $sh,
|
|
|
- 'manyType' => $manyType,
|
|
|
- 'sendNum' => $sendNum,
|
|
|
- ];
|
|
|
- $main = MainClass::getById($mainId, true);
|
|
|
- if (empty($main)) {
|
|
|
- util::fail('没有main信息37');
|
|
|
- }
|
|
|
- WorkClass::goodsCreateFinish($params, $main);
|
|
|
}
|
|
|
+ $sh = $goodsData['sh'] ?? 0;
|
|
|
+ $params = [
|
|
|
+ 'goods' => [['productId' => $goodsId, 'num' => abs($num)]],
|
|
|
+ 'sjId' => $sjId,
|
|
|
+ 'mainId' => $mainId,
|
|
|
+ 'orderSn' => $orderSn,
|
|
|
+ 'orderId' => $orderId,
|
|
|
+ 'hasReachTime' => $hasReachTime,
|
|
|
+ 'reachPeriod' => $reachPeriod,
|
|
|
+ 'reachDate' => $reachDate,
|
|
|
+ 'shopId' => $shopId,
|
|
|
+ 'staffName' => $staffName,
|
|
|
+ 'staffId' => $staffId,
|
|
|
+ 'bookName' => $bookName,
|
|
|
+ 'orderPrice' => $orderPrice,
|
|
|
+ 'orderDebtPrice' => $orderDebtPrice,
|
|
|
+ 'fromType' => $fromType,
|
|
|
+ 'sendType' => $sendType,
|
|
|
+ 'remark' => $remark,
|
|
|
+ 'thirdSn' => $thirdSn,
|
|
|
+ 'cardInfo' => $cardInfo,
|
|
|
+ 'anonymity' => $anonymity,
|
|
|
+ 'sh' => $sh,
|
|
|
+ 'manyType' => $manyType,
|
|
|
+ 'sendNum' => $sendNum,
|
|
|
+ ];
|
|
|
+ $main = MainClass::getById($mainId, true);
|
|
|
+ if (empty($main)) {
|
|
|
+ util::fail('没有main信息37');
|
|
|
+ }
|
|
|
+ WorkClass::goodsCreateFinish($params, $main);
|
|
|
+
|
|
|
|
|
|
$data['stock'] = $newStock;
|
|
|
self::updateById($goodsId, $data);
|