61 lines
2.0 KiB
PHP
61 lines
2.0 KiB
PHP
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: zn
|
|
* Date: 2017/7/6
|
|
* Time: 17:28
|
|
*/
|
|
|
|
namespace common\services;
|
|
|
|
use common\modules\systemlog\SystemLogUtil;
|
|
|
|
/**
|
|
*费用
|
|
* Class ExpendServices
|
|
* @package common\services
|
|
*/
|
|
class ExpendServices
|
|
{
|
|
/**复合多项费用扣除
|
|
* @param $userID
|
|
* @param $field
|
|
* @param $logFromType
|
|
* @param array $logFromData
|
|
* @return bool|int
|
|
*/
|
|
public static function expend($userID, $field, $logFromType, $logFromData = [])
|
|
{
|
|
$list = GameConfigServices::parseExpendList($field);
|
|
if (count($list) == 0) return ResultStatusServices::RS_OPERATION_SUCCESS;
|
|
|
|
foreach ($list as $item) {
|
|
$itemConfig = GameConfigServices::getParamByPath('item_list.' . $item->itemID);
|
|
$type2 = $itemConfig['type2'];
|
|
|
|
if ($item->num == 0) continue;
|
|
|
|
if ($type2 == ItemServices::ITEM_TYPE2_GOLD) {//金币
|
|
|
|
$log = SystemLogUtil::get($userID, SystemLogUtil::TYPE_GOLD, -$item->num, 0, $logFromType, $logFromData);
|
|
$rs = UserService::checkAndModifyMoney($userID, false, -$item->num, 0, $log);
|
|
if ($rs != ResultStatusServices::RS_OPERATION_SUCCESS) return $rs;
|
|
|
|
} elseif ($type2 == ItemServices::ITEM_TYPE2_GEM) {//钻石
|
|
|
|
$log = SystemLogUtil::get($userID, SystemLogUtil::TYPE_GEM, -$item->num, 0, $logFromType, $logFromData);
|
|
$rs = UserService::checkAndModifyMoney($userID, false, 0, -$item->num, $log);
|
|
if ($rs != ResultStatusServices::RS_OPERATION_SUCCESS) return $rs;
|
|
|
|
} else {//物品
|
|
|
|
$log = SystemLogUtil::get($userID, SystemLogUtil::TYPE_ITEM, $item->itemID, -$item->num, $logFromType, $logFromData);
|
|
$rs = ItemServices::checkAndModifyNum($userID, $item->itemID, false, -$item->num, $log);
|
|
if ($rs != ResultStatusServices::RS_OPERATION_SUCCESS) return $rs;
|
|
|
|
}
|
|
}
|
|
|
|
return ResultStatusServices::RS_OPERATION_SUCCESS;
|
|
}
|
|
} |