getCustomAmount($uid); // 返回配置数据 return isset($balance['amount']) ? $balance['amount'] : 0; } /** * 获取用户账户余额信息 * 如果没有余额账户,将创建对应的账户 * * @param int $uid 用户ID * * @return array 余额信息 * */ public function getCustomAmount($uid){ // 查询数据 $cash = $this->query()->where([['custom_uid','=',$uid]])->first(['amount','use_amount']); // 如果没有数据,创建账号 $cash = $cash ? $cash->toArray() : $this->createCustomScore($uid); // 返回查询结果 return $cash; } /** * 创建账号 * * @param int $uid 用户ID * @param array $values 需要修改的数据 * */ public function createCustomAmount($uid){ // 如果没有余额信息的话,需要新增账户,默认数据 $cash = ['amount'=>0,'use_amount'=>0]; // 尝试执行 try { $result = $this->query()->insert(['custom_uid'=>$uid,'insert_time'=>time(),'update_time'=>time()]); // 如果成功 if( $result ) return $cash; } catch (\Throwable $th) { // 如果失败的话,返回默认数据 return $cash; } // 返回用户余额数据,默认都是账户余额为0 return $cash; } }