UserCoinTransfer.php 2.5 KB

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