game2006api/webapp/services/callback/BuyShopGoodsCbService.php
songliang a95cebf7d6 ...
2023-06-20 16:42:44 +08:00

100 lines
2.5 KiB
PHP

<?php
namespace services;
require_once('mt/Dailyselection.php');
require_once('ShopAddItemService.php');
define('V_ORDER_TYPE_BUY_SHOP_GOODS', 1);
use phpcommon\SqlHelper;
use mt\Dailyselection;
use mt\Shop;
class BuyShopGoodsCbService
{
public function process($order)
{
switch ($order['order_type']) {
case V_ORDER_TYPE_BUY_SHOP_GOODS: {
$ext_data = json_decode($order['ext_data'], true);
switch ($ext_data['mode']) {
case SHOP_BUY_MODE_NORMAL:
$this->_buyNormal($order, $ext_data);
break;
case SHOP_BUY_MODE_DAILY_SELECTION:
$this->_buyDailySelection($order, $ext_data);
break;
}
}
break;
default: {
}
}
}
private function _buyNormal($order, $ext_data)
{
$self = myself();
if (!$self) {
return;
}
$address = $order['address'];
$ext_data = $order['ext_data'];
$goods_id = $order['item_id'];
$goods_num = $order['item_num'];
$this->_addGoods($address, array(
'goods_id' => $goods_id,
'goods_num' => $goods_num,
));
}
private function _buyDailySelection($order, $ext_data)
{
$self = myself();
if (!$self) {
return;
}
$order_id = $order['order_id'];
$item_id = $order['item_id'];
$item_num = $order['item_num'];
$address = $order['address'];
$idx = $ext_data['idx'];
$grid = $ext_data['grid'];
$count = $ext_data['count'];
$conn = $self->_getMysql($address);
$sql = "SELECT count_$grid FROM t_shop_dailyselection WHERE idx = $idx";
$chk = $conn->execQuery($sql);
if (!$chk) {
return;
}
if ($chk[0]['count_' . $grid] < $count) {
error_log("BuyShopGoodsCbService::_buyDailySelection() count not enough, address: $address, order_id: $order_id, idx: $idx, grid: $grid, count: $count");
return;
}
$sql = "UPDATE t_shop_dailyselection SET count_$grid = count_$grid - $count WHERE idx = $idx";
$chk = $conn->execScript($sql);
if ($chk) {
$this->_addGoods($address, array(
'goods_id' => $item_id,
'goods_num' => $item_num,
));
} else {
error_log("BuyShopGoodsCbService::_buyDailySelection() decDailySelectionItem failed, address: $address, order_id: $order_id, idx: $idx, grid: $grid, count: $count");
}
}
private function _addGoods($address, $goods)
{
$itemService = new ShopAddItemService();
$itemService->addItem($address, $goods['goods_id'], $goods['goods_num']);
}
}