1
This commit is contained in:
parent
0e247ac87d
commit
de97c91d2a
@ -126,6 +126,7 @@ CREATE TABLE `t_gun_skin` (
|
|||||||
`idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id',
|
`idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id',
|
||||||
`account_id` varchar(60) CHARACTER SET utf8 NOT NULL COMMENT 'account_id',
|
`account_id` varchar(60) CHARACTER SET utf8 NOT NULL COMMENT 'account_id',
|
||||||
`skin_id` int(11) NOT NULL DEFAULT '0' COMMENT '皮肤ID',
|
`skin_id` int(11) NOT NULL DEFAULT '0' COMMENT '皮肤ID',
|
||||||
|
`skin_state` int(11) NOT NULL DEFAULT '0' COMMENT '状态(0=已经购,1 = 试用状态)',
|
||||||
`try_expire_at` int(11) NOT NULL DEFAULT '0' COMMENT '试用截止时间',
|
`try_expire_at` int(11) NOT NULL DEFAULT '0' COMMENT '试用截止时间',
|
||||||
`createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
|
`createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
|
||||||
`modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
|
`modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
|
||||||
@ -155,13 +156,13 @@ CREATE TABLE `t_gun_talent` (
|
|||||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Table structure for table `dyndata`
|
-- Table structure for table `t_dyndata`
|
||||||
--
|
--
|
||||||
|
|
||||||
DROP TABLE IF EXISTS `dyndata`;
|
DROP TABLE IF EXISTS `t_dyndata`;
|
||||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||||
/*!40101 SET character_set_client = utf8 */;
|
/*!40101 SET character_set_client = utf8 */;
|
||||||
CREATE TABLE `dyndata` (
|
CREATE TABLE `t_dyndata` (
|
||||||
`idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id',
|
`idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id',
|
||||||
`account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id(channel + "_" + gameid + "_" + openid)',
|
`account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id(channel + "_" + gameid + "_" + openid)',
|
||||||
`x` int(11) NOT NULL DEFAULT '0' COMMENT 'x',
|
`x` int(11) NOT NULL DEFAULT '0' COMMENT 'x',
|
||||||
@ -175,10 +176,14 @@ CREATE TABLE `dyndata` (
|
|||||||
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
|
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
|
||||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||||
|
|
||||||
DROP TABLE IF EXISTS `shop_data`;
|
--
|
||||||
|
-- Table structure for table `t_shop_data`
|
||||||
|
--
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS `t_shop_data`;
|
||||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||||
/*!40101 SET character_set_client = utf8 */;
|
/*!40101 SET character_set_client = utf8 */;
|
||||||
CREATE TABLE `shop_data` (
|
CREATE TABLE `t_shop_data` (
|
||||||
`idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id',
|
`idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id',
|
||||||
`account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id',
|
`account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id',
|
||||||
`shop_id` int(11) NOT NULL DEFAULT '0' COMMENT '商店id',
|
`shop_id` int(11) NOT NULL DEFAULT '0' COMMENT '商店id',
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
require_once('models/Bag.php');
|
require_once('models/Bag.php');
|
||||||
|
require_once('mt/Item.php');
|
||||||
|
|
||||||
use phpcommon\SqlHelper;
|
use phpcommon\SqlHelper;
|
||||||
use models\Bag;
|
use models\Bag;
|
||||||
@ -251,4 +252,20 @@ class BaseAuthedController extends BaseController {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function _getLackItemErrMsg($lackItem)
|
||||||
|
{
|
||||||
|
if (!$lackItem) {
|
||||||
|
return '道具不足';
|
||||||
|
}
|
||||||
|
$itemMeta = mt\Item::get($lackItem['item_id']);
|
||||||
|
if (!$itemMeta) {
|
||||||
|
return '道具不足';
|
||||||
|
}
|
||||||
|
if (SERVER_ENV != __ONLINE) {
|
||||||
|
return "${itemMeta['name']}不足 库存:${itemMeta['inventory']} 需求:${itemMeta['item_num']}";
|
||||||
|
} else {
|
||||||
|
return "${itemMeta['name']}不足";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -61,14 +61,14 @@ class ShopController extends BaseAuthedController {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->_decItems($costItems);
|
$this->_decItems($costItems);
|
||||||
Hero::addHero($heroMeta);
|
$this->internalAddItem($heroMeta);
|
||||||
$awardService = new services\AwardService();
|
$awardService = new services\AwardService();
|
||||||
$heroDb = Hero::find($heroId);
|
$heroDb = Hero::find($heroId);
|
||||||
if ($heroDb) {
|
if ($heroDb) {
|
||||||
$awardService->addHero(Hero::toDto($heroDb));
|
$awardService->addHero(Hero::toDto($heroDb));
|
||||||
}
|
}
|
||||||
$this->rspData(array(
|
$this->rspData(array(
|
||||||
'award' => $awardService->toData()
|
'award' => $awardService->toDto()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,6 +77,90 @@ class ShopController extends BaseAuthedController {
|
|||||||
$itemId = getReqVal('item_id', 0);
|
$itemId = getReqVal('item_id', 0);
|
||||||
$itemNum = getReqVal('item_num', 0);
|
$itemNum = getReqVal('item_num', 0);
|
||||||
$costItemId = getReqVal('cost_item_id', 0);
|
$costItemId = getReqVal('cost_item_id', 0);
|
||||||
|
|
||||||
|
$itemMeta = mt\Item::get($itemId);
|
||||||
|
if (!$itemMeta) {
|
||||||
|
$this->_rspErr(1, 'item_id参数错误');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ($itemNum != 1) {
|
||||||
|
$this->_rspErr(1, 'item_num参数必须等于1');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$costItemMeta = mt\Item::get($costItemId);
|
||||||
|
if (!$costItemMeta) {
|
||||||
|
$this->_rspErr(1, 'cost_item_id参数错误');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$types = array(mt\Item::HERO_TYPE,
|
||||||
|
mt\Item::HERO_SKIN_TYPE,
|
||||||
|
mt\Item::GUN_SKIN_TYPE);
|
||||||
|
if (!mt\Item::inTypes($itemMeta, $types)) {
|
||||||
|
$this->_rspErr(1, 'cost_item_id参数错误');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
switch ($itemMeta['type']) {
|
||||||
|
case mt\Item::HERO_TYPE:
|
||||||
|
{
|
||||||
|
$heroDb = Hero::find($itemMeta['id']);
|
||||||
|
if (!$heroDb) {
|
||||||
|
$this->_rspErr(4, '你已经拥有该英雄');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case mt\Item::HERO_SKIN_TYPE:
|
||||||
|
{
|
||||||
|
$heroSkinDb = HeroSkin::find($itemMeta['id']);
|
||||||
|
if (!$heroSkinDb) {
|
||||||
|
$this->_rspErr(4, '你已经拥有该皮肤');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case mt\Item::GUN_SKIN_TYPE:
|
||||||
|
{
|
||||||
|
$gunSkinDb = GunSkin::find($itemMeta['id']);
|
||||||
|
if (!$gunSkinDb) {
|
||||||
|
$this->_rspErr(4, '你已经拥有该皮肤');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
$this->_rspErr(1, 'cost_item_id参数错误');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$priceInfo = mt\Item::getPriceInfo($itemMeta);
|
||||||
|
if (empty($priceInfo)) {
|
||||||
|
$this->_rspErr(2, '配置表错误');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$costItems = $this->getCostTimes($priceInfo, $costItemId);
|
||||||
|
if (empty($costItems)) {
|
||||||
|
$this->_rspErr(2, '配置表错误2');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$lackItem = null;
|
||||||
|
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
||||||
|
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$this->_decItems($costItems);
|
||||||
|
$this->internalAddItem($itemMeta);
|
||||||
|
$awardService = new services\AwardService();
|
||||||
|
$awardService->addItem($itemId, $itemNum);
|
||||||
|
$this->rspData(array(
|
||||||
|
'award' => $awardService->toDto(),
|
||||||
|
'property_chg' => array(
|
||||||
|
'user_info' => User::info($this->_getOrmUserInfo())
|
||||||
|
)
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getOutsidePriceInfo()
|
public function getOutsidePriceInfo()
|
||||||
@ -87,7 +171,7 @@ class ShopController extends BaseAuthedController {
|
|||||||
mt\Item::HERO_SKIN_TYPE,
|
mt\Item::HERO_SKIN_TYPE,
|
||||||
mt\Item::GUN_SKIN_TYPE);
|
mt\Item::GUN_SKIN_TYPE);
|
||||||
mt\Item::filter(function ($meta) use(&$items, &$types) {
|
mt\Item::filter(function ($meta) use(&$items, &$types) {
|
||||||
if (in_array($meta['type'], $types)) {
|
if (mt\Item::inTypes($meta, $types)) {
|
||||||
array_push($items, $meta);
|
array_push($items, $meta);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -102,4 +186,65 @@ class ShopController extends BaseAuthedController {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getCostItems($priceInfo, $costItemId)
|
||||||
|
{
|
||||||
|
$costGroup = null;
|
||||||
|
array_walk($priceInfo['cost_list'], function ($val) use(&$costGroup, $costItemId) {
|
||||||
|
if ($costGroup) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (count($val) > 0 && $val[0]['cost_item_id'] == $costItemId) {
|
||||||
|
$costGroup = $val;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (!$costGroup) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
$costItems = array();
|
||||||
|
array_walk($costGroup, function ($val) use (&$costItems, $priceInfo) {
|
||||||
|
if ($val['cost_item_is_discount'] &&
|
||||||
|
$priceInfo['discount'] > 0 &&
|
||||||
|
$this->_getNowTime() >= $priceInfo['discount_begin_time'] &&
|
||||||
|
$this->_getNowTime() <= $priceInfo['discount_end_time']
|
||||||
|
) {
|
||||||
|
array_push($costItems, array(
|
||||||
|
'item_id' => $val['cost_item_id'],
|
||||||
|
'item_num' => (int)($val['cost_item_num'] * ($priceInfo['discount'] / 100)),
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
array_push($costItems, array(
|
||||||
|
'item_id' => $val['cost_item_id'],
|
||||||
|
'item_num' => $val['cost_item_num'],
|
||||||
|
));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return $costItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function internalAddItem($itemMeta)
|
||||||
|
{
|
||||||
|
switch ($itemMeta['type']) {
|
||||||
|
case mt\Item::HERO_TYPE:
|
||||||
|
{
|
||||||
|
Hero::addHero($itemMeta);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case mt\Item::HERO_SKIN_TYPE:
|
||||||
|
{
|
||||||
|
HeroSkin::addSkin($itemMeta);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case mt\Item::GUN_SKIN_TYPE:
|
||||||
|
{
|
||||||
|
GunSkin::addSkin($itemMeta);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -32,4 +32,28 @@ class GunSkin extends BaseModel {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function addSkin($skinId)
|
||||||
|
{
|
||||||
|
SqlHelper::upsert(
|
||||||
|
myself()->_getSelfMysql(),
|
||||||
|
't_gun_skin',
|
||||||
|
array(
|
||||||
|
'account_id' => myself()->_getAccountId(),
|
||||||
|
'skin_id' => $skinId
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'skin_state' => self::GETED_STATE,
|
||||||
|
'modifytime' => myself()->_getNowTime()
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'account_id' => myself()->_getAccountId(),
|
||||||
|
'skin_id' => $skinId,
|
||||||
|
'skin_state' => self::GETED_STATE,
|
||||||
|
'try_expire_at' => 0,
|
||||||
|
'createtime' => myself()->_getNowTime(),
|
||||||
|
'modifytime' => myself()->_getNowTime()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -63,6 +63,11 @@ class Item {
|
|||||||
return $meta['type'] == $type;
|
return $meta['type'] == $type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function inTypes($meta, $types)
|
||||||
|
{
|
||||||
|
return in_array($meta['type'], $types);
|
||||||
|
}
|
||||||
|
|
||||||
public static function filter($cb)
|
public static function filter($cb)
|
||||||
{
|
{
|
||||||
foreach (self::getMetaList() as $meta) {
|
foreach (self::getMetaList() as $meta) {
|
||||||
@ -87,14 +92,16 @@ class Item {
|
|||||||
array_push($info['price_info']['cost_list'],
|
array_push($info['price_info']['cost_list'],
|
||||||
array(
|
array(
|
||||||
'cost_item_id' => V_ITEM_GOLD,
|
'cost_item_id' => V_ITEM_GOLD,
|
||||||
'cost_item_num' => $meta['gold']
|
'cost_item_num' => $meta['gold'],
|
||||||
|
'cost_item_is_discount' => 1
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
if ($meta['diamond_price'] > 0) {
|
if ($meta['diamond_price'] > 0) {
|
||||||
array_push($info['price_info']['cost_list'],
|
array_push($info['price_info']['cost_list'],
|
||||||
array(
|
array(
|
||||||
'cost_item_id' => V_ITEM_DIAMOND,
|
'cost_item_id' => V_ITEM_DIAMOND,
|
||||||
'cost_item_num' => $meta['diamond_price']
|
'cost_item_num' => $meta['diamond_price'],
|
||||||
|
'cost_item_is_discount' => 1
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
return $info;
|
return $info;
|
||||||
|
@ -4,31 +4,14 @@ namespace services;
|
|||||||
|
|
||||||
class AwardService extends BaseService {
|
class AwardService extends BaseService {
|
||||||
|
|
||||||
const ITEM_TYPE = 1;
|
|
||||||
const HERO_TYPE = 2;
|
|
||||||
const HEROSKIN_TYPE = 3;
|
|
||||||
const GUNSKIN_TYPE = 4;
|
|
||||||
|
|
||||||
private $items = array();
|
private $items = array();
|
||||||
|
|
||||||
public function addItem($itemDto)
|
public function addItem($itemId, $itemNum)
|
||||||
{
|
{
|
||||||
$this->internalAdd(self::ITEM_TYPE, $itemDto);
|
array_push($items, array(
|
||||||
}
|
'item_id' => $itemId,
|
||||||
|
'item_num' => $itemNum
|
||||||
public function addHero($heroDto)
|
));
|
||||||
{
|
|
||||||
$this->internalAdd(self::HERO_TYPE, $heroDto);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addHeroSkin($heroSkinDto)
|
|
||||||
{
|
|
||||||
$this->internalAdd(self::HEROSKIN_TYPE, $heroSkinDto);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addGunSkin($gunSkinDto)
|
|
||||||
{
|
|
||||||
$this->internalAdd(self::GUNSKIN_TYPE, $gunSkinDto);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toDto()
|
public function toDto()
|
||||||
@ -38,12 +21,4 @@ class AwardService extends BaseService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function internalAdd($type, $dto)
|
|
||||||
{
|
|
||||||
array_push($items, array(
|
|
||||||
'type' => $type,
|
|
||||||
"union_${type}" => $dto
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user