UserCoinTransfer.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace app\models\coin;
  3. use crmeb\traits\ModelTrait;
  4. use crmeb\basic\BaseModel;
  5. class UserCoinTransfer extends BaseModel
  6. {
  7. use ModelTrait;
  8. /**
  9. * 增加一条挖矿记录
  10. *
  11. * @param $uid
  12. * @param $orderId
  13. * @param $symbol
  14. * @param $amount
  15. * @return UserCoinTransfer|\think\Model
  16. */
  17. public static function addMining($uid, $orderId, $symbol, $amount)
  18. {
  19. $data = [
  20. 'uid' => $uid,
  21. 'order_id' => $orderId,
  22. 'symbol' => $symbol,
  23. 'amount' => $amount,
  24. 'ts' => time(),
  25. ];
  26. return self::create($data);
  27. }
  28. /**
  29. * 增加一条提现记录
  30. *
  31. * @param $uid
  32. * @param $symbol
  33. * @param $amount
  34. */
  35. public static function withdrawal($uid, $symbol, $to, $amount)
  36. {
  37. return self::create([
  38. 'uid' => $uid,
  39. 'symbol' => $symbol,
  40. 'to' => $to,
  41. 'amount' => $amount,
  42. 'ts' => time(),
  43. 'out' => 1,
  44. 'status' => 1,
  45. ]);
  46. }
  47. /**
  48. * 确认提币操作
  49. *
  50. * @param $id
  51. * @return UserCoinTransfer
  52. */
  53. public static function confirmWithdrawal($id)
  54. {
  55. return self::where('id', $id)->update(['status' => 0]);
  56. }
  57. /**
  58. * 取得用户币变动记录
  59. *
  60. * @param $uid
  61. * @param $page
  62. * @param int $limit
  63. * @return array
  64. * @throws \think\db\exception\DataNotFoundException
  65. * @throws \think\db\exception\DbException
  66. * @throws \think\db\exception\ModelNotFoundException
  67. */
  68. public static function getUserTransferred($uid, $page, $limit = 20)
  69. {
  70. $res = self::where('uid', $uid)->order('ts desc')
  71. ->alias('t')->join('dict_coin c', 'c.symbol=t.symbol')
  72. ->field('t.order_id, t.symbol, c.icon, t.from, t.to, t.amount, t.out, t.ts, FROM_UNIXTIME(t.ts,"%Y-%m-%d") as stime')
  73. ->page(intval($page), intval($limit))->select()->toArray();
  74. //echo self::getLastSql();
  75. return $res;
  76. }
  77. /**
  78. * $uid 的 $symbol 币, $addr 这个地址是否提现过
  79. *
  80. * @param $uid
  81. * @param $symbol
  82. * @param $addr
  83. * @return object|null
  84. * @throws \think\db\exception\DataNotFoundException
  85. * @throws \think\db\exception\DbException
  86. * @throws \think\db\exception\ModelNotFoundException
  87. */
  88. public static function hasTransferred($uid, $symbol, $addr)
  89. {
  90. $row = self::where(['uid' => $uid, 'symbol' => $symbol, 'to' => $addr, 'out' => 1])->limit(1)->find();
  91. return $row;
  92. }
  93. }