| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- namespace app\common\model;
- use think\db\exception\DataNotFoundException;
- use think\db\exception\ModelNotFoundException;
- use think\Exception;
- use think\exception\DbException;
- use think\Model;
- /**
- * 会员模型
- */
- class UserModel extends Model
- {
- // // 开启自动写入时间戳字段
- // protected $autoWriteTimestamp = 'int';
- // // 定义时间戳字段名
- // protected $createTime = 'createtime';
- // protected $updateTime = 'updatetime';
- // // 追加属性
- // protected $append = [
- // 'url',
- // ];.
- protected $name = 'user';
- public function getById($userID)
- {
- return $this->where('id', $userID)->find();
- }
- public function getByAddress($address)
- {
- return $this->where("address", $address)->find();
- }
- public function getAllAddress()
- {
- $all_list = $this->field('id,address')->select();
- $arr = [];
- foreach ($all_list as $item){
- $arr[$item['address']] = $item['id'];
- }
- return $arr;
- }
- //获取用户余额 冻结金额 和 折合金额
- public static function getUserAmount(int $uid): float
- {
- return self::where('id', $uid)->sum("balance-frozen_amount");
- }
-
- //获取用户RWA
- public static function getUserRwaNum(int $uid): int
- {
- return self::where('id', $uid)->value("rwa_num");
- }
-
- /**
- * RWA更新数据
- * @param int $uid
- * @param string $power
- * @return void
- */
- public static function updateForRwaNum(int $uid, string $score, string $action)
- {
- if($action == '+'){
- return self::where('id', $uid)->setInc('rwa_num', $score);
- }else{
- return self::where('id', $uid)->setDec('rwa_num', $score);
- }
- }
- /**
- * 余额更新数据
- * @param int $uid
- * @param string $power
- * @return void
- */
- public static function updateForRBalance(int $uid, string $score, string $action)
- {
- if($action == '+'){
- return self::where('id', $uid)->setInc('balance', $score);
- }else{
- return self::where('id', $uid)->setDec('balance', $score);
- }
- }
-
- }
|