Wallet.php 822 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace app\api\model\user;
  3. use app\api\model\BaseModel;
  4. class Wallet extends BaseModel
  5. {
  6. // 表名
  7. protected $name = 'user_wallet';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'integer';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. static function UWKey($user_id)
  14. {
  15. return "u:w:update:$user_id";
  16. }
  17. function getUserWallet($user_id)
  18. {
  19. $w = $this->where("user_id", $user_id)->find();
  20. if ($w)
  21. return $w;
  22. return self::create([
  23. "user_id" => $user_id,
  24. "score" => 0,
  25. "money" => 0,
  26. "give_money" => 0,
  27. "createtime" => time(),
  28. "updatetime" => time()
  29. ]);
  30. }
  31. }