SyncMjWarehouse(); } public function SyncMjWarehouse(){ $params = array(); $params['eshopCode'] = config('constants.ESHOP_CODE'); $params['warehouseCode'] = config('constants.WAREHOUSE_CODE'); //仓库编码 $params['pageIndex'] = '1'; $params['pageSize'] = $this->limit; $mjRes = OrderScript::mjWarehouseSkuGet($params); if($mjRes == false){ exit('获取卖家云数据出错'); } //插入第一页: $this->insertData( $mjRes['resultSet']['skuList'] ); $count = $mjRes['resultSet']['totalNum']; $pages = ceil($count / $this->limit); //插入其他页面 for($i=2; $i<=$pages; $i++){ $params['pageIndex'] = $i; $mjRes = OrderScript::mjWarehouseSkuGet($params); $this->insertData( $mjRes['resultSet']['skuList'] ); } } /** * 获取订单信息,可用来判断订单是否存在,同步订单状态 */ public function insertData($data){ foreach($data as $k=>$sku){ $code = $sku['skuProductCode']; $up = array(); //1.更新商品库存数量(有可能为负数,有可能为0) //2.更新商品库存总成本(有可能为空) //3.计算商品真实价格 //4.计算商品外部价格 $cost = DB::table('goods_skus')->where('code', $code)->select('referenceCost', 'is_weigh')->first(); //获取规格成本/是否称重 if($cost){ $quantity = $cost->is_weigh == 1 ? $sku['quantity']/2 : $sku['quantity']; //对应规格数量 //实际库存=库存-冻结 $real_quantity = $sku['quantity'] - $sku['fi']; $real_quantity = $cost->is_weigh == 1 ? $real_quantity/2 : $real_quantity; //对应规格数量 $up['quantity'] = $quantity; $up['totalCost'] = isset($sku['totalCost']) ? $sku['totalCost'] : 0; if($up['quantity'] != 0 ){ $up['realPrice'] = $up['totalCost'] / $up['quantity']; // $up['outPrice'] = ceil($up['realPrice'] * 1.15); } else { // $up['realPrice'] = 0; // $up['outPrice'] = 0; } if(!$cost->outPrice){ if(isset($up['realPrice'])){ $up['outPrice'] = ceil($up['realPrice']*1.15); } } $up['cost'] = isset($sku['cost']) ? $sku['cost'] : 0; //实际库存=库存-冻结 $up['quantity'] = $real_quantity; $up_re = DB::table('goods_skus')->where('code', $code)->update($up); } } return true; } }