1234567891011121314151617181920212223242526272829 |
- <?php
- use think\Db;
- use think\Exception;
- use app\common\model\MoneyLog;
- // 更新会员余额
- function user_rebate($user_id,$balance,$source,$related_id=0,$from_user= 0,$desc=''){
- $user_info = Db::table('fa_user')->find($user_id);
- $balance_data=[
- 'user_id' => $user_id ,
- 'money' => $balance ,
- 'before' => $user_info['money'] ,
- 'after' => bcadd($user_info['money'],$balance,2) ,
- 'source' => $source ,
- 'memo' => $desc ,
- 'create_time' => date('Y-m-d H:i:s'),
- 'related_id' => $related_id,
- 'from_user' => $from_user,
- ];
- Db::startTrans();
- try {
- Db::table('fa_user')->where('id',$user_id)->update(['money'=>$balance_data['surplus']]);
- MoneyLog::create($balance_data);
- }catch (Exception $e){
- Db::rollback();
- }
- }
|