...
This commit is contained in:
parent
a3df8fba49
commit
0ba8a1f2fa
18
doc/Shop.py
18
doc/Shop.py
@ -96,6 +96,24 @@ class Shop(object):
|
|||||||
['goods_chg', _common.NewGoods(), '购买后更新商品的最新信息(可能为null客户端需要做容错处理)'],
|
['goods_chg', _common.NewGoods(), '购买后更新商品的最新信息(可能为null客户端需要做容错处理)'],
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
'name': 'buyGoodsNormal',
|
||||||
|
'desc': '购买商品(正式)',
|
||||||
|
'group': 'Shop',
|
||||||
|
'url': 'webapp/index.php?c=Shop&a=buyGoodsNew',
|
||||||
|
'params': [
|
||||||
|
_common.ReqHead(),
|
||||||
|
['id', 0, '商品唯一id,参见shopGoods表'],
|
||||||
|
['token_type', '', "选用币种"],
|
||||||
|
['goods_num', 0, '商品数量'],
|
||||||
|
],
|
||||||
|
'response': [
|
||||||
|
_common.RspHead(),
|
||||||
|
['award', _common.Award(), '奖励信息'],
|
||||||
|
['property_chg', _common.PropertyChg(), '属性变更'],
|
||||||
|
['goods_chg', _common.NewGoods(), '购买后更新商品的最新信息(可能为null客户端需要做容错处理)'],
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
'name': 'buyGoodsDirect',
|
'name': 'buyGoodsDirect',
|
||||||
'desc': '直接购买(充值,gold)',
|
'desc': '直接购买(充值,gold)',
|
||||||
|
@ -5,7 +5,8 @@ namespace models;
|
|||||||
use mt;
|
use mt;
|
||||||
use phpcommon\SqlHelper;
|
use phpcommon\SqlHelper;
|
||||||
|
|
||||||
class ShopBuyRecord extends BaseModel {
|
class ShopBuyRecord extends BaseModel
|
||||||
|
{
|
||||||
|
|
||||||
public static function find($itemId)
|
public static function find($itemId)
|
||||||
{
|
{
|
||||||
@ -29,7 +30,7 @@ class ShopBuyRecord extends BaseModel {
|
|||||||
'account_id' => myself()->_getAccountId(),
|
'account_id' => myself()->_getAccountId(),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
return array_map(function($row) {
|
return array_map(function ($row) {
|
||||||
$nowDaySeconds = myself()->_getNowDaySeconds();
|
$nowDaySeconds = myself()->_getNowDaySeconds();
|
||||||
if (!($row['last_buy_time'] >= $nowDaySeconds && $row['last_buy_time'] <= $nowDaySeconds)) {
|
if (!($row['last_buy_time'] >= $nowDaySeconds && $row['last_buy_time'] <= $nowDaySeconds)) {
|
||||||
$row['this_day_buy_times'] = 0;
|
$row['this_day_buy_times'] = 0;
|
||||||
@ -46,7 +47,7 @@ class ShopBuyRecord extends BaseModel {
|
|||||||
{
|
{
|
||||||
$rows = self::all();
|
$rows = self::all();
|
||||||
$buyRecordHash = array();
|
$buyRecordHash = array();
|
||||||
array_walk($rows, function ($row) use(&$buyRecordHash) {
|
array_walk($rows, function ($row) use (&$buyRecordHash) {
|
||||||
$buyRecordHash[$row['item_id']] = $row;
|
$buyRecordHash[$row['item_id']] = $row;
|
||||||
});
|
});
|
||||||
return $buyRecordHash;
|
return $buyRecordHash;
|
||||||
@ -54,8 +55,7 @@ class ShopBuyRecord extends BaseModel {
|
|||||||
|
|
||||||
public static function toDto($row)
|
public static function toDto($row)
|
||||||
{
|
{
|
||||||
return array(
|
return array();
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function add($itemId, $itemNum)
|
public static function add($itemId, $itemNum)
|
||||||
@ -97,4 +97,56 @@ class ShopBuyRecord extends BaseModel {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function addWithAddress($address, $itemId, $itemNum)
|
||||||
|
{
|
||||||
|
$account_id = ShopBuyRecord::getAccountId($address);
|
||||||
|
SqlHelper::upsert(
|
||||||
|
myself()->_getMysql($address),
|
||||||
|
't_shop_buy_record',
|
||||||
|
array(
|
||||||
|
'account_id' => $account_id,
|
||||||
|
'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()->_getMondaySeconds();
|
||||||
|
$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' => $account_id,
|
||||||
|
'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(),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function getAccountId($address)
|
||||||
|
{
|
||||||
|
$row = SqlHelper::ormSelectOne(
|
||||||
|
myself()->_getMysql($address),
|
||||||
|
't_user',
|
||||||
|
array(
|
||||||
|
'address' => $address
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return $row['account_id'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,12 +5,14 @@ namespace services;
|
|||||||
|
|
||||||
require_once('mt/Dailyselection.php');
|
require_once('mt/Dailyselection.php');
|
||||||
require_once('ShopAddItemService.php');
|
require_once('ShopAddItemService.php');
|
||||||
|
require_once('models/ShopBuyRecord.php');
|
||||||
|
|
||||||
define('V_ORDER_TYPE_BUY_SHOP_GOODS', 1);
|
define('V_ORDER_TYPE_BUY_SHOP_GOODS', 1);
|
||||||
|
|
||||||
use phpcommon\SqlHelper;
|
use phpcommon\SqlHelper;
|
||||||
use mt\Dailyselection;
|
use mt\Dailyselection;
|
||||||
use mt\Shop;
|
use mt\Shop;
|
||||||
|
use models\ShopBuyRecord;
|
||||||
|
|
||||||
class BuyShopGoodsCbService
|
class BuyShopGoodsCbService
|
||||||
{
|
{
|
||||||
@ -94,6 +96,9 @@ class BuyShopGoodsCbService
|
|||||||
private function _addGoods($address, $goods)
|
private function _addGoods($address, $goods)
|
||||||
{
|
{
|
||||||
$itemService = new ShopAddItemService();
|
$itemService = new ShopAddItemService();
|
||||||
$itemService->addItem($address, $goods['goods_id'], $goods['goods_num']);
|
$item_id = $goods['goods_id'];
|
||||||
|
$goods_num = $goods['goods_num'];
|
||||||
|
$itemService->addItem($address, $item_id, $goods_num);
|
||||||
|
ShopBuyRecord::addWithAddress($address, $item_id, $goods_num);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user