This commit is contained in:
mkm 2023-11-18 13:42:08 +08:00
parent ee6829fd18
commit 637047894e
2 changed files with 23 additions and 17 deletions

View File

@ -90,7 +90,7 @@ class SpuRepository extends BaseRepository
'keyword' => $param['keyword'] ?? '', 'keyword' => $param['keyword'] ?? '',
'image' => $param['image'], 'image' => $param['image'],
'price' => $param['price'], 'price' => $param['price'],
'status' => 0, 'status' => $param['status']??0,
'rank' => $param['rank'] ?? 0, 'rank' => $param['rank'] ?? 0,
'temp_id' => $param['temp_id'], 'temp_id' => $param['temp_id'],
'sort' => $param['sort'] ?? 0, 'sort' => $param['sort'] ?? 0,

View File

@ -39,12 +39,7 @@ class OrderTake
$product_arr = Db::name('store_order_product')->where('order_id', $order['order_id'])->where('is_refund', 'in', [0, 2])->field('product_id,product_sku,refund_num')->select(); $product_arr = Db::name('store_order_product')->where('order_id', $order['order_id'])->where('is_refund', 'in', [0, 2])->field('product_id,product_sku,refund_num')->select();
foreach ($product_arr as $k => $v) { foreach ($product_arr as $k => $v) {
$this->import($v, $order); $this->import($v, $order);
// app(ProductRepository::class)->create($find, 0);
} }
// $productId = $this->import($params['order_product_id'], request()->userInfo());
// $product = $this->get($productId);
// $attrValue = ProductAttrValue::where('mer_id', $merId)->where('product_id', $productId)->find();
} }
} catch (\Exception $e) { } catch (\Exception $e) {
Log::error($e->getMessage() . 'lien:' . $e->getLine()); Log::error($e->getMessage() . 'lien:' . $e->getLine());
@ -73,6 +68,7 @@ class OrderTake
Log::error('采购导入商品:已经导入过该规格了'); Log::error('采购导入商品:已经导入过该规格了');
return false; return false;
} }
/**查询原始商品的规格 */
$attrValue = Db::name('store_product_attr_value')->where(['product_id' => $find['product_id']]) $attrValue = Db::name('store_product_attr_value')->where(['product_id' => $find['product_id']])
->where('unique', $product['product_sku']) ->where('unique', $product['product_sku'])
->field('image,price,cost,ot_price,svip_price,stock,bar_code,weight,volume,detail,sku') ->field('image,price,cost,ot_price,svip_price,stock,bar_code,weight,volume,detail,sku')
@ -81,18 +77,21 @@ class OrderTake
}) })
->find(); ->find();
$find['attr'] = []; $find['attr'] = [];
$is_update=false;
if ($attrValue['detail']) { if ($attrValue['detail']) {
foreach ($attrValue['detail'] as $kk => $vv) { foreach ($attrValue['detail'] as $kk => $vv) {
/**查询当前规格是否存在 */
$attr_values = Db::name('store_product_attr')->where('product_id', $exist['product_id'])->where('attr_name', $kk) $attr_values_find = Db::name('store_product_attr')->where('product_id', $exist['product_id'])->where('attr_name', $kk)
->value('attr_values'); ->find();
if ($attr_values) { if ($attr_values_find) {
$attr_values= $attr_values_find['attr_values'];
$attr_values = explode('-!-', $attr_values); $attr_values = explode('-!-', $attr_values);
if (!in_array($vv, $attr_values)) { if (!in_array($vv, $attr_values)) {
$attr_values[] = $vv; $attr_values[] = $vv;
$attr_values = implode('-!-', $attr_values); $attr_values = implode('-!-', $attr_values);
Db::name('store_product_attr')->where('product_id', $exist['product_id'])->where('attr_name', $kk)->update(['attr_values' => $attr_values]); Db::name('store_product_attr')->where('product_id', $exist['product_id'])->where('attr_name', $kk)->update(['attr_values' => $attr_values]);
} }
$is_update=true;
} else { } else {
$attr_values = $vv; $attr_values = $vv;
@ -105,13 +104,20 @@ class OrderTake
} }
} }
} }
$attrValue['stock'] = $product['refund_num']; /**规格新增还是更新 */
$unique = app(ProductRepository::class)->setUnique($exist['product_id'], $attrValue['sku'], 0); if($is_update==false){
$attrValue['unique'] = $unique; $attrValue['stock'] = $product['refund_num'];
$attrValue['detail'] = json_encode($attrValue['detail']); $unique = app(ProductRepository::class)->setUnique($exist['product_id'], $attrValue['sku'], 0);
$attrValue['product_id'] = $exist['product_id']; $attrValue['unique'] = $unique;
$attrValue['mer_id'] = $mer_id; $attrValue['detail'] = json_encode($attrValue['detail']);
Db::name('store_product_attr_value')->insert($attrValue); $attrValue['product_id'] = $exist['product_id'];
$attrValue['mer_id'] = $mer_id;
Db::name('store_product_attr_value')->insert($attrValue);
}else{
Db::name('store_product_attr_value')->where(['unique'=>$attr_values_find['unique'],'product_id',
$attr_values_find['product_id'],'mer_id'=>$mer_id,])->update(['stock'=>$product['refund_num']+$attr_values_find['stock']]);
}
Db::name('store_product')->where('product_id',$exist['product_id'])->update(['stock'=>$product['refund_num']+$exist['stock']]); Db::name('store_product')->where('product_id',$exist['product_id'])->update(['stock'=>$product['refund_num']+$exist['stock']]);
$data = [ $data = [
'order_id' => $order['order_id'], 'order_product_id' => $order['product_id'], 'order_id' => $order['order_id'], 'order_product_id' => $order['product_id'],