UserJewelLog.php 967 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. /**
  5. * 用户钻石流水记录模型
  6. */
  7. class UserJewelLog extends Model
  8. {
  9. // 开启自动写入时间戳字段
  10. protected $autoWriteTimestamp = 'int';
  11. // 定义时间戳字段名
  12. protected $createTime = 'createtime';
  13. /**
  14. * 用户钻石余额变更
  15. */
  16. public function addUserJewelLog($user_id, $money, $mode, $before, $detail, $type = 1)
  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["value"] = $money;
  28. $data["mode"] = $mode;
  29. $data["before"] = $before;
  30. $data["balance"] = $balance;
  31. $data["detail"] = $detail;
  32. $data["createtime"] = time();
  33. return $this->insertGetId($data);
  34. }
  35. }