Wallet.php 970 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace app\api\model\massager;
  3. use app\api\model\BaseModel;
  4. class Wallet extends BaseModel
  5. {
  6. // 表名
  7. protected $name = 'massager_wallet';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'integer';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. static function MWKey($m_id) {
  14. return "massager:w:update:{$m_id}";
  15. }
  16. public function massager()
  17. {
  18. return $this->hasOne(Massager::class, 'id', 'massager_id');
  19. }
  20. function getWallet($m_id)
  21. {
  22. $w = $this->where("massager_id", $m_id)->find();
  23. if ($w)
  24. return $w;
  25. return self::create([
  26. "massager_id" => $m_id,
  27. "score" => 0,
  28. "profit_amount" => 0,
  29. "total_profit_amount" => 0,
  30. "createtime" => time(),
  31. "updatetime" => time()
  32. ]);
  33. }
  34. }