This commit is contained in:
songliang 2023-06-21 11:32:36 +08:00
parent a3df8fba49
commit 0ba8a1f2fa
3 changed files with 81 additions and 6 deletions

View File

@ -96,6 +96,24 @@ class Shop(object):
['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',
'desc': '直接购买(充值,gold)',

View File

@ -5,7 +5,8 @@ namespace models;
use mt;
use phpcommon\SqlHelper;
class ShopBuyRecord extends BaseModel {
class ShopBuyRecord extends BaseModel
{
public static function find($itemId)
{
@ -29,7 +30,7 @@ class ShopBuyRecord extends BaseModel {
'account_id' => myself()->_getAccountId(),
)
);
return array_map(function($row) {
return array_map(function ($row) {
$nowDaySeconds = myself()->_getNowDaySeconds();
if (!($row['last_buy_time'] >= $nowDaySeconds && $row['last_buy_time'] <= $nowDaySeconds)) {
$row['this_day_buy_times'] = 0;
@ -46,7 +47,7 @@ class ShopBuyRecord extends BaseModel {
{
$rows = self::all();
$buyRecordHash = array();
array_walk($rows, function ($row) use(&$buyRecordHash) {
array_walk($rows, function ($row) use (&$buyRecordHash) {
$buyRecordHash[$row['item_id']] = $row;
});
return $buyRecordHash;
@ -54,8 +55,7 @@ class ShopBuyRecord extends BaseModel {
public static function toDto($row)
{
return array(
);
return array();
}
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'];
}
}

View File

@ -5,12 +5,14 @@ namespace services;
require_once('mt/Dailyselection.php');
require_once('ShopAddItemService.php');
require_once('models/ShopBuyRecord.php');
define('V_ORDER_TYPE_BUY_SHOP_GOODS', 1);
use phpcommon\SqlHelper;
use mt\Dailyselection;
use mt\Shop;
use models\ShopBuyRecord;
class BuyShopGoodsCbService
{
@ -94,6 +96,9 @@ class BuyShopGoodsCbService
private function _addGoods($address, $goods)
{
$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);
}
}