UserCoinTransfer.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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();
  69. return $res ? $res->toArray() : [];
  70. }
  71. /**
  72. * @param $uid
  73. * @param $symbol
  74. * @return \think\Collection
  75. * @throws \think\db\exception\DataNotFoundException
  76. * @throws \think\db\exception\DbException
  77. * @throws \think\db\exception\ModelNotFoundException
  78. */
  79. public static function hasTransferred($uid, $symbol, $addr) {
  80. $row = self::where(['uid'=>$uid, 'symbol'=>$symbol, 'to'=>$addr, 'out'=>1])->limit(1)->select();
  81. return $row;
  82. }
  83. }