### 通过ERPSKUID获取SKU的网店可售库存(电商库存同步用)
**位置:**
Common\Lib\EcGoodsLib.class.php
**参数:**
* @param $sku_id Int ERPSKU的ID
* @return $result Int 电商可用库存数
**调用:**
* $stock_lib = new EcGoodsLib;
* $stock_lib ->getSkuInventory($sku_id) ;
**完整代码:**
~~~
/**
* 通过ERPSKUID获取SKU的网店可售库存(电商库存同步用)
* qjm 2022-05-16 add 添加了排除掉库存不需要同步到线上的门店的逻辑
* @param $sku_id
* @return int
*/
public function getSkuInventory($sku_id) {
// 查询不需要进行电商库存同步的门店
$map_shop['open_status'] = array('eq', 1); // 是否常用店铺:1是2否
$map_shop['need_sync'] = array('eq', 2); // 库存是否需要同步到网店1表示需要,2表示不需要,默认2
$map_shop['is_delete'] = 0; // 是否删除,0未删除(默认),1删除
$shop_list = M('shops')
->field('id')
->where($map_shop)
->select();
$need_shops = array_column($shop_list,'id');
// 库存查询条件中要排除掉库存不需要同步到网店的门店
// 如果需要排除的门店数组不为空
if (!empty($need_shops)) {
$where['it.shops_id'] = array('not in', $need_shops); // 库存需要同步到网店的门店
}
$where['it.sku_id'] = array('eq', $sku_id); // 唯一码对应的SKU ID
$where['it.inventory_status'] = array('in', array(1, 3)); // 库存状态:0.不可销售、1.可销售、2.门店可销售、3.网店可销售、4.已销售、5.已停售
$where['it.delivery_status'] = array('in', array(1, 2)); // 物流状态 1已入库 2已入店 不包括物流中商品 2020-09-04 jig add
$where['it.is_delete'] = array('eq', 0); // 伪删除状态: 0(未删除)、1(已删除)
$where['it.is_flaw'] = array('eq', '0'); // 瑕疵品
$count = M('goods_item as it')->where($where)->count(); // 统计唯一码库存
//进行锁库查询
$goods_sku = M('goods_sku')->where('id='.$sku_id)->getField('goods_sku'); // 通过ID获取SKU编码
$lock_info = M('goods_sku_lock')
->field('lock_num')
->where(array('goods_sku'=>$goods_sku,'lock_status'=>0))
->select();
if ($lock_info) {
$lock_num = 0;
foreach ($lock_info as $key => $value) {
$lock_num += $value['lock_num'];
}
}
// 计算可售库存
$result = $count-$lock_num;
// 判断是否小于0,若是则等于0
if ($result < 0) {
$result = 0;
}
return $result;
}
~~~
- 模版
- 前言
- 项目架构
- 项目规范
- HTML
- CSS
- Javascript
- PHP
- MySQL
- 注意规范
- 开发版本管理
- 开发流程
- 系统配置
- 阿里云服务器配置
- 计划任务配置说明
- 开发示例
- Page分页
- Search_param搜索结果赋值
- Add新增
- Edit编辑
- Ajax表单验证
- Ajax二级联动
- Excel 导出数据首位不去0的方法
- POS总部控制
- 下载CSV格式的模板
- 订单唯一码表和订单SKU表实收金额生成
- 快捷日期选择
- JS函数
- ajax_send
- ajax_result
- createQrCodes
- createBarCodes
- printTpl
- JS插件
- BootstrapValidator表单验证插件
- Address省市区插件
- Bootstrap-datepicker日期插件
- Bootstrap-select多选框插件
- Toastr消息提示插件
- PalyAudit扫描声音提示插件
- WebUploader多图片上传插件
- Ueditor富文本编辑器插件
- Function
- alert
- object_to_array
- array_to_object
- get_address
- set_param_url
- get_shops_name
- get_user_name
- get_warehouse
- get_cheapest_sku
- print_attr(新)
- print_img(新)
- get_spu_no(新)
- get_type_name(新)
- get_brand_en(新)
- get_cat_name(新)
- get_attr_name(新)
- spu_cat_info(新)
- get_time_event_price
- get_vendors
- check_total_reduce
- check_total_discount
- get_inventory
- get_delivery
- get_sale_inventory
- get_customer_name
- phone_protection
- get_order_no
- get_event_name
- get_order_status
- get_item_status
- get_ditch_name
- get_card_no
- get_shop_sales
- get_pay_name
- get_season
- amt_format
- get_cat_parent
- print_attr_id
- round_bcadd
- round_bcsub
- round_bcmul
- round_bcdiv
- get_account_name
- Controller
- Common_BaseController
- check_membership_card
- get_menu_list
- importErrorMassage
- Wpos_IndexController
- get_customer_vip_card
- get_shops_id
- calculate_active_integral
- check_numbers_active
- check_goods_active
- Woms_IndexController
- Model
- View
- category
- cycle_date.html
- shop_select门店多选搜索框
- 品牌A-Z排序多选brand_mc.html
- 供应商代码A-Z排序vendor_no_mc.html
- Lib
- BuyerLib
- WarehouseLib
- EventLib
- getTimeEventPrice
- getVipType
- getEvent
- orderTotalEvent
- orderTimeEvent
- getTotalReduce
- getTotalDiscount
- SaleLib
- CustomerLib
- addCustomerService
- GiftcardLib
- WechatLib
- wxRefund
- OrdersLib
- orderLog
- calculatePayinAmount
- calculateSubtotal
- correctPayinAmount
- saveOrderAddress
- getOrderAddress
- setDeliveryNo
- SyncLib
- updateOuterStock
- UserLib
- createCommission
- FlowLib
- orderList
- addOrder
- addLog
- orderInfo
- checkSku
- orderSave
- orderStop
- orderExecute
- skuEdit
- orderPrinta
- scanGoods
- boxClose
- orderOut
- take
- bview
- check
- deliveryStatus
- checkGoods
- GoodsLib
- createGoodsNo
- createNewGoodsNo
- getSystemStyleNo
- getDim
- MallLib
- smsLog
- GoodsBaseLib
- getBrandInfo
- getBrandsInfo
- getAttrIdArray
- getPrintAttr
- getMustAttr
- getCatIdInfo
- valTypeId
- valsTypeId
- getCatNoInfo
- getCatInfo
- getAttrArr
- getAttrInfo
- getValInfo
- getAttrId
- getValId
- getAttrSeaon
- getValueId
- PointsLog
- pointsIn
- pointsUp
- EcGoodsLib
- getSkuInventory
- Tools
- CsvTools
- csvImport
- csvExport
- ExcelTools
- importExcel
- exportExcel
- exportHeadExcel
- MailTools
- SmsTools
- sendMessage
- UploadTools
- ExportTools
- exportData
- TaobaoTools
- getOnsaleItems
- getSkusItems
- PicturesTools
- uploadPicture
- Plugins
- WxBase
- Taobao
- 问题反馈