1
This commit is contained in:
parent
6a35185fdf
commit
404cc97468
@ -177,22 +177,25 @@ CREATE TABLE `t_dyndata` (
|
||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||
|
||||
--
|
||||
-- Table structure for table `t_shop_data`
|
||||
-- Table structure for table `t_shop_buy_record`
|
||||
--
|
||||
|
||||
DROP TABLE IF EXISTS `t_shop_data`;
|
||||
DROP TABLE IF EXISTS `t_shop_buy_record`;
|
||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `t_shop_data` (
|
||||
CREATE TABLE `t_shop_buy_record` (
|
||||
`idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id',
|
||||
`account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id',
|
||||
`shop_id` int(11) NOT NULL DEFAULT '0' COMMENT '商店id',
|
||||
`blobdata` mediumblob COMMENT '商店数据json',
|
||||
`create_time` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
|
||||
`modify_time` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
|
||||
`item_id` int(11) NOT NULL DEFAULT '0' COMMENT '道具id',
|
||||
`this_day_buy_times` int(11) NOT NULL DEFAULT '0' COMMENT '今日购买次数',
|
||||
`this_week_buy_times` int(11) NOT NULL DEFAULT '0' COMMENT '本周购买次数',
|
||||
`total_buy_times` int(11) NOT NULL DEFAULT '0' COMMENT '总购买次数',
|
||||
`last_buy_time` int(11) NOT NULL DEFAULT '0' COMMENT '最后一次购买时间',
|
||||
`createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
|
||||
`modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
|
||||
PRIMARY KEY (`idx`),
|
||||
KEY `account_id` (`account_id`),
|
||||
UNIQUE KEY `account_id_shop_id` (`account_id`, `shop_id`)
|
||||
UNIQUE KEY `account_id_item_id` (`account_id`, `item_id`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
|
||||
|
||||
-- Dump completed on 2015-08-19 18:51:22
|
||||
|
@ -36,6 +36,11 @@ class BaseController {
|
||||
return max(0, $this->_getNowDaySeconds() + 3600 * 24 - $this->_getNowTime());
|
||||
}
|
||||
|
||||
public function _getMondaySeconds()
|
||||
{
|
||||
return phpcommon\getMondaySeconds($this->_getNowTime());
|
||||
}
|
||||
|
||||
public function _rspErr($errcode, $errmsg)
|
||||
{
|
||||
echo json_encode(array(
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
require_once('mt/Shop.php');
|
||||
require_once('mt/ShopGoods.php');
|
||||
require_once('mt/Hero.php');
|
||||
require_once('mt/Item.php');
|
||||
require_once('mt/Parameter.php');
|
||||
@ -17,59 +18,32 @@ class ShopController extends BaseAuthedController {
|
||||
|
||||
public function info()
|
||||
{
|
||||
$shopId = getReqVal('sho_id', 0);
|
||||
$shopId = getReqVal('shop_id', 0);
|
||||
$goodsList = mt\ShopGoods::getGoodsList($shopId);
|
||||
if (!$goodsList) {
|
||||
$this->_rspData(array(
|
||||
'info' => array(
|
||||
'goods_list1' => array(),
|
||||
'goods_list2' => array(),
|
||||
)
|
||||
));
|
||||
return;
|
||||
}
|
||||
$goodsDtoList1 = array();
|
||||
$goodsDtoList2 = array();
|
||||
foreach ($goodsList as $goods) {
|
||||
|
||||
}
|
||||
$this->_rspData(array(
|
||||
'info' => array(
|
||||
'goods_list1' => $goodsDtoList1,
|
||||
'goods_list2' => $goodsDtoList2,
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
public function buyHero()
|
||||
public function buyGoods()
|
||||
{
|
||||
$heroId = getReqVal('hero_id', 0);
|
||||
$buyType = getReqVal('buy_type', 0);
|
||||
$heroMeta = mt\Hero::get($heroId);
|
||||
if (!$heroMeta) {
|
||||
$this->_rspErr(1, 'hero_id参数错误');
|
||||
return;
|
||||
}
|
||||
if (empty($heroMeta['itemid'])) {
|
||||
$this->_rspErr(2, 'hero.item_id配置错误');
|
||||
return;
|
||||
}
|
||||
if (!in_array($buyType, array(0, 1))) {
|
||||
$this->_rspErr(1, 'buy_type参数错误');
|
||||
return;
|
||||
}
|
||||
$shopMeta = mt\Shop::get(mt\Shop::HERO_SHOP_ID);
|
||||
if (!$shopMeta) {
|
||||
$this->_rspErr(2, '配置表错误1');
|
||||
return;
|
||||
}
|
||||
$goodsInfo = mt\Shop::getGoodsInfo($shopMeta, $heroMeta['itemid']);
|
||||
if (empty($goodsInfo)) {
|
||||
$this->_rspErr(2, '配置表错误2');
|
||||
return;
|
||||
}
|
||||
if (Hero::find($heroId)) {
|
||||
$this->_rspErr(3, '你已经有该英雄');
|
||||
return;
|
||||
}
|
||||
$costItems = array(
|
||||
'item_id' => $goodsInfo['costItemId'],
|
||||
'item_num' => $goodsInfo['costItemNum'],
|
||||
);
|
||||
$lackItem = null;
|
||||
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
||||
$this->_rspErr(3, '道具不足');
|
||||
return;
|
||||
}
|
||||
$this->_decItems($costItems);
|
||||
$this->internalAddItem($heroMeta);
|
||||
$awardService = new services\AwardService();
|
||||
$heroDb = Hero::find($heroId);
|
||||
if ($heroDb) {
|
||||
$awardService->addHero(Hero::toDto($heroDb));
|
||||
}
|
||||
$this->rspData(array(
|
||||
'award' => $awardService->toDto()
|
||||
));
|
||||
}
|
||||
|
||||
public function outsideBuy()
|
||||
@ -247,4 +221,9 @@ class ShopController extends BaseAuthedController {
|
||||
}
|
||||
}
|
||||
|
||||
private function updateBuyRecord($itemId, $itemNum)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
68
webapp/models/ShopBuyRecord.php
Normal file
68
webapp/models/ShopBuyRecord.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace models;
|
||||
|
||||
use mt;
|
||||
use phpcommon\SqlHelper;
|
||||
|
||||
class ShopBuyRecord extends BaseModel {
|
||||
|
||||
public static function find($heroId)
|
||||
{
|
||||
$row = SqlHelper::ormSelectOne(
|
||||
myself()->_getSelfMysql(),
|
||||
't_hero',
|
||||
array(
|
||||
'account_id' => myself()->_getAccountId(),
|
||||
'hero_id' => $heroId,
|
||||
)
|
||||
);
|
||||
return $row;
|
||||
}
|
||||
|
||||
public static function toDto($row)
|
||||
{
|
||||
return array(
|
||||
);
|
||||
}
|
||||
|
||||
public static function add($itemId, $itemNum)
|
||||
{
|
||||
SqlHelper::upsert(
|
||||
myself()->_getSelfMysql(),
|
||||
't_shop_buy_record',
|
||||
array(
|
||||
'account_id' => myself()->_getAccountId(),
|
||||
'item_id' => $itemId,
|
||||
),
|
||||
array(
|
||||
'this_day_buy_times' => function () {
|
||||
$nowDaySeconds = myself()->_getNowDaySeconds();
|
||||
$cond = " last_buy_time>=${nowDaySeconds} AND last_buy_time<=${nowDaySeconds} + 3600 * 24 ";
|
||||
return "CASE WHEN (${cond}) THEN this_day_buy_times + 1 ELSE 0 END";
|
||||
},
|
||||
'this_week_buy_times' => function () {
|
||||
$mondaySeconds = myself()->_getNowDaySeconds();
|
||||
$cond = " last_buy_time>=${mondaySeconds} AND last_buy_time<=${mondaySeconds} + 3600 * 24 * 7 ";
|
||||
return "CASE WHEN (${cond}) THEN this_week_buy_times + 1 ELSE 0 END";
|
||||
},
|
||||
'total_buy_times' => function () {
|
||||
return 'total_buy_times + 1';
|
||||
},
|
||||
'last_buy_time' => myself()->_getNowTime(),
|
||||
'modifytime' => myself()->_getNowTime(),
|
||||
),
|
||||
array(
|
||||
'account_id' => myself()->_getAccountId(),
|
||||
'item_id' => $itemId,
|
||||
'this_day_buy_times' => 1,
|
||||
'this_week_buy_times' => 1,
|
||||
'total_buy_times' => 1,
|
||||
'last_buy_time' => myself()->_getNowTime(),
|
||||
'createtime' => myself()->_getNowTime(),
|
||||
'modifytime' => myself()->_getNowTime(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -6,70 +6,15 @@ use phpcommon;
|
||||
|
||||
class Shop {
|
||||
|
||||
const HERO_SHOP_ID = 1;
|
||||
const HEROSKIN_SHOP_ID = 2;
|
||||
const GUNSKIN1_SHOP_ID = 3;
|
||||
const GUNSKIN2_SHOP_ID = 4;
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return getXVal(self::getMetaList(), $id);
|
||||
}
|
||||
|
||||
public static function getGoodsInfo($meta, $goodsId)
|
||||
{
|
||||
$goodsStrArr = explode("|", $meta['goods']);
|
||||
$priceStrArr = explode("|", $meta['price']);
|
||||
if (count($goodsStrArr) != count($priceStrArr)) {
|
||||
echo '111';
|
||||
return null;
|
||||
}
|
||||
$idx = -1;
|
||||
{
|
||||
$i = 0;
|
||||
array_filter($goodsStrArr, function($str) use(&$i, &$idx, $goodsId) {
|
||||
if ($idx == -1) {
|
||||
$strArr = explode(":", $str);
|
||||
if (count($strArr) >= 2) {
|
||||
if ($strArr[0] == $goodsId) {
|
||||
$idx = $i;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
++$i;
|
||||
return false;
|
||||
});
|
||||
}
|
||||
if ($idx < 0) {
|
||||
return null;
|
||||
}
|
||||
$info = array(
|
||||
'goodsId' => 0,
|
||||
'goodsNum' => 0,
|
||||
'costItemId' => 0,
|
||||
'costItemNum' => 0
|
||||
);
|
||||
{
|
||||
$strArr = explode(":", $goodsStrArr[$idx]);
|
||||
$info['goodsId'] = $strArr[0];
|
||||
$info['goodsNum'] = $strArr[1];
|
||||
}
|
||||
{
|
||||
$strArr = explode(":", $priceStrArr[$idx]);
|
||||
if (count($strArr) < 2) {
|
||||
return null;
|
||||
}
|
||||
$info['costItemId'] = $strArr[0];
|
||||
$info['costItemNum'] = $strArr[1];
|
||||
}
|
||||
return $info;
|
||||
}
|
||||
|
||||
protected static function getMetaList()
|
||||
{
|
||||
if (!self::$metaList) {
|
||||
self::$metaList = getMetaTable('newshop@newshop.php');
|
||||
self::$metaList = getMetaTable('shop@shop.php');
|
||||
}
|
||||
return self::$metaList;
|
||||
}
|
||||
|
62
webapp/mt/ShopGoods.php
Normal file
62
webapp/mt/ShopGoods.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace mt;
|
||||
|
||||
use phpcommon;
|
||||
|
||||
class ShopGoods {
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return getXVal(self::getMetaList(), $id);
|
||||
}
|
||||
|
||||
public static function getGoodsList($shopId)
|
||||
{
|
||||
self::mustBeShopGoodsHash();
|
||||
$shopData = getXVal(self::$shopGoodsHash, $shopId, null);
|
||||
if (!$shopData) {
|
||||
return null;
|
||||
}
|
||||
return $shopData['goodsList'];
|
||||
}
|
||||
|
||||
public static function getGoodsInfo($shopId, $goodsId)
|
||||
{
|
||||
self::mustBeShopGoodsHash();
|
||||
$shopData = getXVal(self::$shopGoodsHash, $shopId, null);
|
||||
if (!$shopData) {
|
||||
return null;
|
||||
}
|
||||
return getXVal($shopData['goodsHash'], $goodsId, null);
|
||||
}
|
||||
|
||||
protected static function mustBeShopGoodsHash()
|
||||
{
|
||||
if (!self::$shopGoodsHash) {
|
||||
self::$shopGoodsHash = array();
|
||||
foreach (self::getMetaList() as $meta) {
|
||||
if (!getXVal(self::$shopGoodsHash, $meta['shop_id'], null)){
|
||||
self::$shopGoodsHash[$meta['shop_id']] = array(
|
||||
'goodsList' => array(),
|
||||
'goodsHash' => array()
|
||||
);
|
||||
}
|
||||
self::$shopGoodsHash['shop_id']['goodsHash'][$meta['goods_id']] = $meta;
|
||||
array_push(self::$shopGoodsHash['shop_id']['goodsList'], $meta);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static function getMetaList()
|
||||
{
|
||||
if (!self::$metaList) {
|
||||
self::$metaList = getMetaTable('shopGoods@shopGoods.php');
|
||||
}
|
||||
return self::$metaList;
|
||||
}
|
||||
|
||||
protected static $shopGoodsHash;
|
||||
protected static $metaList;
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user