mirror of
https://gitee.com/ShopeX/OMS
synced 2026-03-22 10:25:35 +08:00
125 lines
4.1 KiB
PHP
125 lines
4.1 KiB
PHP
<?php
|
|
/**
|
|
* Copyright 2012-2026 ShopeX (https://www.shopex.cn)
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
class inventorydepth_offline_stock extends inventorydepth_logic_abstract
|
|
{
|
|
|
|
public function getStock($product_bn, $branch_id, $shop_id)
|
|
{
|
|
# 读取商品要执行的规则
|
|
$iocObj = kernel::single('inventorydepth_offline_calculation');
|
|
$quantity = $iocObj->get_actual_stock($product_bn, $shop_id, $branch_id);
|
|
if ($quantity === false) {return false;}
|
|
$stock = array(
|
|
'store_code' => $iocObj->get_branch_bn($branch_id),
|
|
'bn' => $product_bn,
|
|
'quantity' => $quantity,
|
|
'regulation' => $iocObj->get_actual_stock_make($product_bn, $shop_id, $branch_id)
|
|
);
|
|
|
|
return $stock;
|
|
}
|
|
|
|
public function dealWithRegu($pbn, $shop_id, $branch_id, $type)
|
|
{
|
|
$regu = $this->getRegu($shop_id);
|
|
$this->regulationShow = '';
|
|
foreach ($regu as $r) {
|
|
if (empty($r['regulation'])) {
|
|
continue;
|
|
}
|
|
# 判断是否满足规则
|
|
$params = array(
|
|
'shop_product_bn' => $pbn,
|
|
'shop_id' => $shop_id,
|
|
'branch_id' => $branch_id
|
|
);
|
|
|
|
if ($r['regulation']['content']['stockupdate'] != 1) {
|
|
return false;
|
|
}
|
|
|
|
$quantity = kernel::single('inventorydepth_stock',[app::get('inventorydepth'), 3])->formulaRun($r['regulation']['content']['result'], $params, $msg, $type);
|
|
|
|
if ($quantity === false) {continue;}
|
|
|
|
$this->regulationShow = $msg;
|
|
|
|
break;
|
|
}
|
|
|
|
return is_null($quantity) ? false : $quantity;
|
|
}
|
|
|
|
public function getPkgStock($product_bn, $branch_id, $shop_id)
|
|
{
|
|
# 读取商品要执行的规则
|
|
$quantity = $this->dealWithRegu($product_bn, $shop_id, $branch_id, 'pkg_');
|
|
if ($quantity === false) {return false;}
|
|
$stock = array(
|
|
'store_code' => kernel::single('inventorydepth_offline_calculation')->get_branch_bn($branch_id),
|
|
'bn' => $product_bn,
|
|
'quantity' => $quantity,
|
|
'regulation' => $this->regulationShow
|
|
);
|
|
|
|
return $stock;
|
|
}
|
|
|
|
/**
|
|
* @description 获取指定店铺的所有规则
|
|
* @access public
|
|
* @param void
|
|
* @return void
|
|
*/
|
|
public function getRegu($shop_id)
|
|
{
|
|
static $regu;
|
|
|
|
if ($regu[$shop_id]) {
|
|
return $regu[$shop_id];
|
|
}
|
|
|
|
$filter = array(
|
|
'using' => 'true',
|
|
'al_exec' => 'false',
|
|
'condition' => 'stock',
|
|
'type' => ['3'],
|
|
'filter_sql' => "(shop_id='_ALL_' || FIND_IN_SET('{$shop_id}',shop_id) )",
|
|
);
|
|
$rows = app::get('inventorydepth')->model('regulation_apply')->getList('*', $filter, 0, -1, 'type desc,priority desc');
|
|
|
|
foreach ($rows as $key => $value) {
|
|
$rows[$key]['shop_id'] = explode(',', $value['shop_id']);
|
|
$rows[$key]['apply_goods'] = explode(',', $value['apply_goods']);
|
|
$rows[$key]['regulation'] = &$regulation[$value['regulation_id']];
|
|
}
|
|
|
|
if ($regulation) {
|
|
$rr = app::get('inventorydepth')->model('regulation')->getList('*', array('regulation_id' => array_keys($regulation), 'using' => 'true'));
|
|
foreach ($rr as $r) {
|
|
$regulation[$r['regulation_id']] = $r;
|
|
}
|
|
}
|
|
|
|
$regu[$shop_id] = $rows;
|
|
|
|
return $regu[$shop_id];
|
|
}
|
|
|
|
}
|