UserMoneyLog.php 901 B

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