common.php 833 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. use think\Db;
  3. use think\Exception;
  4. use app\common\model\MoneyLog;
  5. // 更新会员余额
  6. function user_rebate($user_id,$balance,$source,$related_id=0,$from_user= 0,$desc=''){
  7. $user_info = Db::table('fa_user')->find($user_id);
  8. $balance_data=[
  9. 'user_id' => $user_id ,
  10. 'money' => $balance ,
  11. 'before' => $user_info['money'] ,
  12. 'after' => bcadd($user_info['money'],$balance,2) ,
  13. 'source' => $source ,
  14. 'memo' => $desc ,
  15. 'create_time' => date('Y-m-d H:i:s'),
  16. 'related_id' => $related_id,
  17. 'from_user' => $from_user,
  18. ];
  19. Db::startTrans();
  20. try {
  21. Db::table('fa_user')->where('id',$user_id)->update(['money'=>$balance_data['surplus']]);
  22. MoneyLog::create($balance_data);
  23. }catch (Exception $e){
  24. Db::rollback();
  25. }
  26. }