addGameLog($order['address'], "shopBuyNormal", "begin", array( 'param1' => $order['order_id'], 'param2' => json_encode(array( 'item_id' => $order['item_id'], 'item_num' => $order['item_num'], )), )); $this->_buyNormal($order, $ext_data); $itemService->addGameLog($order['address'], "shopBuyNormal", "end", array( 'param1' => $order['order_id'], 'param2' => json_encode(array( 'item_id' => $order['item_id'], 'item_num' => $order['item_num'], )), )); break; case SHOP_BUY_MODE_DAILY_SELECTION: $itemService->addGameLog($order['address'], "shopBuyDailySelection", "begin", array( 'param1' => $order['order_id'], 'param2' => json_encode(array( 'item_id' => $order['item_id'], 'item_num' => $order['item_num'], )), )); $this->_buyDailySelection($order, $ext_data); $itemService->addGameLog($order['address'], "shopBuyDailySelection", "end", array( 'param1' => $order['order_id'], 'param2' => json_encode(array( 'item_id' => $order['item_id'], 'item_num' => $order['item_num'], )), )); break; } } break; default: { } } } private function _buyNormal($order, $ext_data) { $self = myself(); if (!$self) { return; } $order_id = $order['order_id']; $address = $order['address']; $account_id = $this->getAccountId($address); $item_id = $order['item_id']; $item_num = $order['item_num']; $id = null; if (isset($ext_data['id'])) { $id = $ext_data['id']; } error_log("callback buynormal address: $address, order_id: $order_id, goods_id: $item_id, goods_num: $item_num"); if ($item_id == V_ITEM_DIAMOND) { $event = [ 'name' => LogService::CEBG_TO_DIAMOND, 'val' => $item_num ]; LogService::productDiamondCallback(['account_id' => $account_id], $event); } $this->_addGoods($address, array( 'goods_id' => $item_id, 'goods_num' => $item_num, 'id' => $id, )); } 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']; $account_id = $this->getAccountId($address); $idx = $ext_data['idx']; $grid = $ext_data['grid']; $count = $ext_data['count']; error_log("callback buyDailySelection address: $address, order_id: $order_id, item_id: $item_id, item_num: $item_num, idx: $idx, grid: $grid, count: $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, item_id: $item_id, item_num: $item_num, 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, item_id: $item_id, item_num: $item_num, idx: $idx, grid: $grid, count: $count"); } } private function _addGoods($address, $goods) { $itemService = new ShopAddItemService(); $item_id = $goods['goods_id']; $goods_num = $goods['goods_num']; $id = null; if ($goods['id']) { $id = $goods['id']; } error_log(json_encode($goods)); error_log('_addGoods ' . $address . ' item_id ' . $item_id . ' goods_num ' . $goods_num . ' id ' . $id); $itemService->addItem($address, $item_id, $goods_num); if ($id) { ShopBuyRecord::addWithAddress($address, $id, $goods_num); } } private function getAccountId($address) { $row = SqlHelper::ormSelectOne( myself()->_getMysql($address), 't_user', array( 'address' => $address ) ); return $row['account_id']; } }