<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace Module\Member\Util; use ModStart\Core\Dao\ModelUtil; use ModStart\Core\Exception\BizException; use ModStart\Core\Util\IdUtil; use Module\Member\Type\MemberMoneyCashStatus; use Module\Member\Type\MemberMoneyChargeStatus; class MemberMoneyUtil { public static function paginateLog($KJqKC, $JcqUq, $WrYIu, $iNhXN = array()) { goto iuZqG; ptIGb: $iNhXN['order'] = array('id', 'desc'); goto Q3TbZ; Q3TbZ: return ModelUtil::paginate('member_money_log', $JcqUq, $WrYIu, $iNhXN); goto ugFf2; iuZqG: $iNhXN['where']['memberUserId'] = $KJqKC; goto ptIGb; ugFf2: } public static function getTotal($KJqKC) { goto PsguK; QmKbg: return $Kwhgm['total']; goto nF3oH; PsguK: $Kwhgm = ModelUtil::get('member_money', array('memberUserId' => $KJqKC)); goto Zsq3N; Zsq3N: if (empty($Kwhgm)) { return '0.00'; } goto QmKbg; nF3oH: } public static function change($KJqKC, $Eesbt, $gvic0) { goto GuZ72; GuZ72: if (!$Eesbt) { BizException::throws('Member.MoneyChangeUtil -> change empty'); } goto BHfk2; XuR6n: ModelUtil::insert('member_money_log', array('memberUserId' => $KJqKC, 'change' => $Eesbt, 'remark' => $gvic0)); goto xqeQe; BHfk2: $Kwhgm = ModelUtil::getWithLock('member_money', array('memberUserId' => $KJqKC)); goto J1bt3; WuhuG: if ($Kwhgm['total'] < 0) { BizException::throws('Member.MoneyChangeUtil -> total empty'); } goto fZw_o; xqeQe: $Kwhgm = ModelUtil::update('member_money', array('id' => $Kwhgm['id']), array('total' => $Kwhgm['total'] + $Eesbt)); goto WuhuG; teZOK: if ($Eesbt < 0 && $Kwhgm['total'] + $Eesbt < 0) { BizException::throws('Member.MoneyChangeUtil -> total change to empty'); } goto XuR6n; J1bt3: if (empty($Kwhgm)) { $Kwhgm = ModelUtil::insert('member_money', array('memberUserId' => $KJqKC, 'total' => 0)); } goto teZOK; fZw_o: } public static function cash($KJqKC, $MgvDM, $SFlsO, $EpKdG, $LmjxW, $iF_Vi, $gvic0 = '余额提现') { self::change($KJqKC, -$MgvDM, '余额提现'); ModelUtil::insert('member_money_cash', array('memberUserId' => $KJqKC, 'status' => MemberMoneyCashStatus::VERIFYING, 'money' => $MgvDM, 'moneyAfterTax' => $SFlsO, 'type' => $EpKdG, 'realname' => $LmjxW, 'account' => $iF_Vi, 'remark' => $gvic0)); } public static function paginateCash($KJqKC, $JcqUq, $WrYIu, $iNhXN = array()) { $iNhXN['where']['memberUserId'] = $KJqKC; return ModelUtil::paginate('member_money_cash', $JcqUq, $WrYIu, $iNhXN); } public static function createCharge($KJqKC, $NFnZe) { return ModelUtil::insert('member_money_charge', array('sn' => IdUtil::generateSN(), 'status' => MemberMoneyChargeStatus::CREATED, 'memberUserId' => $KJqKC, 'fee' => $NFnZe)); } public static function processCharge($dG9Dm) { goto pFpm4; DnoHo: if (empty($KkPQv)) { throw new \Exception('member_money_charge empty -> ' . $dG9Dm); } goto UOIEz; UOIEz: if ($KkPQv['status'] != MemberMoneyChargeStatus::CREATED) { throw new \Exception('member_money_charge status error -> ' . $dG9Dm); } goto V11JU; V11JU: self::change($KkPQv['memberUserId'], $KkPQv['fee'], '充值'); goto EZ_qO; EZ_qO: ModelUtil::update('member_money_charge', array('id' => $dG9Dm), array('status' => MemberMoneyChargeStatus::SUCCESS)); goto mw0z_; pFpm4: $KkPQv = ModelUtil::getWithLock('member_money_charge', array('id' => $dG9Dm)); goto DnoHo; mw0z_: } }