php中try,请教我在php里这样使用try是否正确

在写一个开奖的时候,在开奖的时候,将中奖信息存入了redis,然后又写了如下代码调用,请教下使用方式是否正确

public function giveOutGoldFoins()

{

$object = new cache();

$userObj = new user();

$UserFundsLog = new UserFundsLog();

$cathectic = new cathectic();

while (true) {

try{

$data = $object->lpop('win_the_lottery');

if(false == $data){

break;

}

$logData = json_decode($data,true);

//将金币分配给用户,修改用户余额

$sql = 'UPDATE `ct_user` SET `gold` = gold+'.$logData['money'].' WHERE `id` = '.$logData['user_id'];

$result = $userObj->updateData($sql,[]);

//修改本期记录

$sql = 'UPDATE `ct_cathectic` SET `state`=1 WHERE id='.$logData['id'];

$res = $cathectic->updateData($sql,[]);

//记录中奖消息

$log = [

':user_id' => $logData['user_id'],

':classify'=> MONEY_FLOW_LOTTERY,

':number' => $logData['money'],

':before_num' => $logData['gold'],

':after_num' => $logData['gold']+$logData['money'],

':explain' => '恭喜您,第:'.$logData['issue'].'期特码,中奖'.$logData['money'].'金币',

':data' => $logData['data'],

':create_time'=> time(),

];

$sql = 'INSERT INTO `lottery`.`ct_user_funds_log` (`user_id`, `classify`, `number`, `before_num`, `after_num`, `explain`, `data`, `create_time`) VALUES (:user_id, :classify, :number, :before_num, :after_num, :explain, :data, :create_time)';

$UserFundsLog->addData($sql,$log);

}catch(Exception $e){

file_put_contents('开奖错误记录.log',$e->getMessage().PHP_EOL, FILE_APPEND);

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值