getGoodsList(); $this->handleGoodsList($list); } catch (\Exception $e) { Log::scriptLog('line:'.$e->getLine().' message:'.$e->getMessage(),[],"order/syncGoods",0,''); } } /** * 获取商品以及库存列表 */ public function getGoodsList() { $goodsList = DB::table('seafood.goods')->get(); $data = json_decode(json_encode($goodsList),true); return $data; } public function handleGoodsList($list) { foreach($list as $key=>$goods){ //查询现在商品表中是否有该商品 $info = DB::table(env('DB_DATABASE').'.goods')->where('productCode',$goods['productCode'])->first(); if($info){ //有商品信息则更新店铺商品信息 //卖家云必要参数拼接转化 $mjArr = array(); $mjArr['eshopCode'] = config('constants.ESHOP_CODE'); $mjArr['outerCode'] = config('constants.GOODS_PREFIX').$goods['id']; $mjArr['name'] = $goods['name']; $mjArr['description'] = $goods['description']; $mj = OrderScript::mjGoodsUpdate($mjArr); if($mj == false){ // Log::errorLog(json_encode($mjArr),[],"order/syncGoods",0,''); die; } //查询规格信息,更新规格信息 $result = DB::table('seafood.goods_skus')->where('goodsCode', $goods['id'])->get(); $result = json_decode(json_encode($result),true); foreach ($result as $sku){ //查询规格信息 $skuInfo = DB::table(env('DB_DATABASE').'.goods_skus')->where('code',$sku['code'])->first(); if(!$skuInfo){ //增加shop sku $shopArr = array(); $shopArr['outerCode'] = config('constants.GOODS_PREFIX').$sku['id']; $shopArr['eshopCode'] = config('constants.ESHOP_CODE'); $shopArr['goodsCode'] = config('constants.GOODS_PREFIX').$sku['goodsCode']; $shopArr['propsName'] = $sku['propsName']; $shopArr['price'] = $sku['price']; $shopArr['skuProductCode'] = $sku['code']; $shopArr['createTime'] = $sku['createTime']; $shopArr['modifyTime'] = $sku['modifyTime']; $sku_add = OrderScript::mjSkuAdd($shopArr); if($sku_add == false){ // Log::errorLog(json_encode($shopArr),[],"order/syncGoods",0,''); die; } //更新商品信息以及添加库存 $sku['goodsCode'] = $info->id; $skus_ad = DB::table(env('DB_DATABASE').'.goods_skus')->insert($sku); } else { # eshop sku更新 $shopArr = array(); $shopArr['eshopCode'] = config('constants.ESHOP_CODE'); $shopArr['goodsCode'] = config('constants.GOODS_PREFIX').$sku['goodsCode']; $shopArr['outerCode'] = config('constants.GOODS_PREFIX').$sku['id']; $shopArr['propsName'] = $sku['propsName']; $shopArr['price'] = $sku['price']; $sku_up = OrderScript::mjSkuUpdate($shopArr); if($sku_up == false){ // Log::errorLog(json_encode($shopArr),[],"order/syncGoods",0,''); die; } $code = $sku['code']; unset($sku['id']); unset($sku['code']); unset($sku['goodsCode']); $sku_update = DB::table(env('DB_DATABASE').'.goods_skus')->where('code',$code)->update($sku); } $productCode = $info->productCode; unset($goods['id']); unset($goods['productCode']); $goods_up = DB::table(env('DB_DATABASE').'.goods')->where('productCode',$productCode)->update($goods); } } else { //没有商品,直接同步店铺商品信息以及库存信息 $result = DB::table('seafood.goods_skus')->where('goodsCode', $goods['id'])->get(); $result = json_decode(json_encode($result),true); $mjArr = array(); $skuArr = array(); if(count($result) > 0){ foreach ($result as $k=>$sku){ $skuArr[$k]['propsName'] = $sku['propsName']; $skuArr[$k]['eShopCode'] = config('constants.ESHOP_CODE'); $skuArr[$k]['price'] = $sku['price']; $skuArr[$k]['skuProductCode'] = $sku['code']; $skuArr[$k]['outerCode'] = config('constants.GOODS_PREFIX').$sku['id']; $skuArr[$k]['createTime'] = $sku['createTime']; $skuArr[$k]['modifyTime'] = $sku['modifyTime']; } } $mjArr['name'] = $goods['name']; $mjArr['description'] = $goods['description']; $mjArr['eshopCode'] = config('constants.ESHOP_CODE'); $mjArr['productCode'] = $goods['productCode']; $mjArr['goodsCategoryName'] = $goods['goodsCategoryName']; $mjArr['picUrl'] = $goods['picUrl']; $mjArr['outerCode'] = config('constants.GOODS_PREFIX').$goods['id']; $mjArr['skuList'] = $skuArr; $mj = OrderScript::mjGoodsAdd($mjArr); if($mj == false){ // Log::errorLog(json_encode($mjArr),[],"order/syncGoods",0,''); die; } //数据表中插入商品信息以及规格信息 unset($goods['id']); $goods_id = DB::table(env('DB_DATABASE').'.goods')->insertGetId($goods); if($goods_id > 0 && count($result)>0 ){ foreach ($result as $skus){ $skus['goodsCode'] = $goods_id; $sku_ad = DB::table(env('DB_DATABASE').'.goods_skus')->insert($skus); } } } } echo 'SUCCESS';die; } }