| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- namespace app\models\coin;
- use crmeb\traits\ModelTrait;
- use crmeb\basic\BaseModel;
- class UserCoinTransfer extends BaseModel {
- use ModelTrait;
- /**
- * 增加一条挖矿记录
- *
- * @param $uid
- * @param $orderId
- * @param $symbol
- * @param $amount
- * @return UserCoinTransfer|\think\Model
- */
- public static function addMining($uid, $orderId, $symbol, $amount) {
- $data = [
- 'uid' => $uid,
- 'order_id' => $orderId,
- 'symbol' => $symbol,
- 'amount' => $amount,
- 'ts' => time(),
- ];
- return self::create($data);
- }
- /**
- * 增加一条提现记录
- *
- * @param $uid
- * @param $symbol
- * @param $amount
- */
- public static function withdrawal($uid, $symbol, $to, $amount) {
- return self::create([
- 'uid' => $uid,
- 'symbol' => $symbol,
- 'to' => $to,
- 'amount' => $amount,
- 'ts' => time(),
- 'out' => 1,
- 'status' => 1,
- ]);
- }
- /**
- * 确认提币操作
- *
- * @param $id
- * @return UserCoinTransfer
- */
- public static function confirmWithdrawal($id) {
- return self::where('id', $id)->update(['status'=>0]);
- }
- /**
- * 取得用户记录
- *
- * @param $uid
- * @param $page
- * @param int $limit
- * @return array
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public static function getUserTransferred($uid, $page, $limit=20) {
- $res = self::where('uid', $uid)->order('ts desc')
- ->alias('t')->join('dict_coin c', 'c.symbol=t.symbol')
- ->field('t.symbol, c.icon, t.from, t.to, t.amount, t.out, t.ts')
- ->limit(($page-1) * $limit, $limit)->select();
- return $res ? $res->toArray() : [];
- }
- /**
- * @param $uid
- * @param $symbol
- * @return \think\Collection
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public static function hasTransferred($uid, $symbol, $addr) {
- $row = self::where(['uid'=>$uid, 'symbol'=>$symbol, 'to'=>$addr, 'out'=>1])->limit(1)->select();
- return $row;
- }
- }
|