| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?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;
- }
- //获取用户余额 冻结金额 和 折合金额 frozen_amount convert_mount
- public static function getUserAmount(int $uid): float
- {
- return self::where('id', $uid)->sum("balance-frozen_amount");
- }
-
- /**
- * 余额更新数据
- * @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);
- }
- }
-
- }
|