UserSoundcoinLog.php 1021 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. /**
  5. * 用户声币流水记录模型
  6. */
  7. class UserSoundcoinLog extends Model
  8. {
  9. // 开启自动写入时间戳字段
  10. protected $autoWriteTimestamp = 'int';
  11. // 定义时间戳字段名
  12. protected $createTime = 'createtime';
  13. /**
  14. * 用户声币余额变更
  15. */
  16. public function addUserSoundcoinLog($user_id, $money, $mode, $before, $detail, $type = 1, $objId = 0)
  17. {
  18. if ($mode == "+") {
  19. $balance = $before + $money;
  20. } else {
  21. $balance = $before - $money;
  22. }
  23. // 添加当前用户钻石流水记录
  24. $data = [];
  25. $data["user_id"] = $user_id;
  26. $data['type'] = $type;
  27. $data['obj_id'] = $objId;
  28. $data["value"] = $money;
  29. $data["mode"] = $mode;
  30. $data["before"] = $before;
  31. $data["balance"] = $balance;
  32. $data["detail"] = $detail;
  33. $data["createtime"] = time();
  34. return $this->insertGetId($data);
  35. }
  36. }