This commit is contained in:
aozhiwei 2020-08-26 11:10:54 +08:00
parent 59cae52fe8
commit 6913e409a9
2 changed files with 126 additions and 0 deletions

88
webapp/metatable/shop.php Normal file
View File

@ -0,0 +1,88 @@
<?php
namespace metatable;
use phpcommon;
/*
配置表规范
getXXXConf:获取表所有数据
getXxxById():通过id获取单个数据
_internalGetXXXConf:获取表所有数据内部实现不对外开放
使用方式
require_once 'metatable/XXXX.php';
!!!注意必须使用require_once
*/
function getShopConf()
{
return _internalGetShopConf();
}
function getShopById($shop_id)
{
$conf = getShopConf();
$shop_id = (int)$shop_id;
return array_key_exists($shop_id, $conf) ? $conf[$shop_id] : null;
}
function randGoods($shop_conf, $exclude_goods)
{
$num = $shop_conf['num'];
$goods_list = explode('|', $shop_conf['goods_list']);
$goods_weight = explode('|', $shop_conf['goods_weight']);
$discount_num = $shop_conf['discount_num'];
if (!empty($exclude_goods)) {
for ($i = count($goods_list) - 1; $i >= 0; --$i) {
if (array_key_exists($goods_list[$i], $exclude_goods)) {
array_splice($goods_list, $i, 1);
array_splice($goods_weight, $i, 1);
--$num;
}
}
}
$goods = array();
for ($i = 0; $i < $num; ++$i) {
$rand_space = 0;
foreach ($goods_weight as $value) {
$rand_space += $value;
}
if ($rand_space <= 0) {
break;
}
$rnd_val = rand(0, $rand_space);
$curr_val = 0;
$discount = false;
if ($discount_num != 0) {
$discount = true;
$discount_num--;
}
for ($ii = 0; $ii < count($goods_weight); ++$ii) {
$curr_val += $goods_weight[$ii];
if ($rnd_val <= $curr_val) {
array_push($goods, array(
'id' => $goods_list[$ii],
'active_time' => time(),
'status' => 0,
'isdiscount' => $discount,
));
array_splice($goods_list, $ii, 1);
array_splice($goods_weight, $ii, 1);
break;
}
}
}
return $goods;
}
function _internalGetShopConf()
{
global $g_shop_table;
if (!$g_shop_table) {
$g_shop_table = require(getConfigBaseDir() . 'shop@shop.php');
}
return $g_shop_table;
}

View File

@ -0,0 +1,38 @@
<?php
namespace metatable;
use phpcommon;
/*
配置表规范
getXXXConf:获取表所有数据
getXxxById():通过id获取单个数据
_internalGetXXXConf:获取表所有数据内部实现不对外开放
使用方式
require_once 'metatable/XXXX.php';
!!!注意必须使用require_once
*/
function getShopGoodsConf()
{
return _internalGetShopGoodsConf();
}
function getShopGoodsById($shop_id)
{
$conf = getShopGoodsConf();
$shop_id = (int)$shop_id;
return array_key_exists($shop_id, $conf) ? $conf[$shop_id] : null;
}
function _internalGetShopGoodsConf()
{
global $g_shopGoods_table;
if (!$g_shopGoods_table) {
$g_shopG_table = require(getConfigBaseDir() . 'shopGoods@shopGoods.php');
}
return $g_shopG_table;
}