代码提交
This commit is contained in:
parent
50556a4936
commit
8826db43bd
@ -51,21 +51,21 @@ export class ChickensController {
|
|||||||
return SuccessResult(init);
|
return SuccessResult(init);
|
||||||
}
|
}
|
||||||
|
|
||||||
//小鸡信息查询
|
// //小鸡信息查询
|
||||||
@ApiOperation({ summary: '小鸡信息查询' })
|
// @ApiOperation({ summary: '小鸡信息查询' })
|
||||||
@UsePipes(new HttpValidationPipe())
|
// @UsePipes(new HttpValidationPipe())
|
||||||
@UseInterceptors(LoggingInterceptor)
|
// @UseInterceptors(LoggingInterceptor)
|
||||||
@ApiImplicitQuery({
|
// @ApiImplicitQuery({
|
||||||
name: 'userid',
|
// name: 'userid',
|
||||||
required: true,
|
// required: true,
|
||||||
description: '当前用户ID',
|
// description: '当前用户ID',
|
||||||
type: Number,
|
// type: Number,
|
||||||
})
|
// })
|
||||||
@Get()
|
// @Get()
|
||||||
async query(@Query('userid') userid: number) {
|
// async query(@Query('userid') userid: number) {
|
||||||
//小鸡数据初始化
|
// //小鸡数据初始化
|
||||||
const res = await this.chickensService.chickensInfo(userid);
|
// const res = await this.chickensService.chickensInfo(userid);
|
||||||
return SuccessResult(res);
|
// return SuccessResult(res);
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7,14 +7,18 @@ import { UserModule } from 'src/user/user.module';
|
|||||||
import { CacheService } from 'src/redis/redis';
|
import { CacheService } from 'src/redis/redis';
|
||||||
import { OrderlogService } from 'src/orderlog/orderlog.service';
|
import { OrderlogService } from 'src/orderlog/orderlog.service';
|
||||||
import { OrderlogEntity } from 'src/orderlog/entities/orderlog.entity';
|
import { OrderlogEntity } from 'src/orderlog/entities/orderlog.entity';
|
||||||
|
import { UserService } from 'src/user/user.service';
|
||||||
|
import { UserEntity } from 'src/user/entities/user.entity';
|
||||||
|
import { GoodsService } from 'src/goods/goods.service';
|
||||||
|
import { GoodsEntity } from 'src/goods/entities/good.entity';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
TypeOrmModule.forFeature([ChickenEntity,OrderlogEntity]),
|
TypeOrmModule.forFeature([ChickenEntity,OrderlogEntity,UserEntity,GoodsEntity]),
|
||||||
UserModule,
|
UserModule,
|
||||||
],
|
],
|
||||||
controllers: [ChickensController],
|
controllers: [ChickensController],
|
||||||
exports: [ChickensService],
|
exports: [ChickensService],
|
||||||
providers: [ChickensService, CacheService,OrderlogService]
|
providers: [ChickensService, CacheService,OrderlogService,UserService,GoodsService]
|
||||||
})
|
})
|
||||||
export class ChickensModule { }
|
export class ChickensModule { }
|
||||||
|
@ -30,12 +30,11 @@ export class ChickensService {
|
|||||||
//小鸡信息
|
//小鸡信息
|
||||||
const info = await this.chickensRepository.createQueryBuilder(prefix)
|
const info = await this.chickensRepository.createQueryBuilder(prefix)
|
||||||
.select().where(`userid=:userid`, { userid: userid }).getRawOne();
|
.select().where(`userid=:userid`, { userid: userid }).getRawOne();
|
||||||
console.log(info);
|
|
||||||
if (!info) return CustomResult(CODE.CODE_PLAYER_INFO_ERR);
|
if (!info) return CustomResult(CODE.CODE_PLAYER_INFO_ERR);
|
||||||
//小鸡穿戴套装信息
|
//小鸡穿戴套装信息
|
||||||
if (info.chick_ck_suitid == 0) info['suit_info'] = {};
|
if (info.chick_ck_suitid == 0) info['suit_info'] = {};
|
||||||
const suit = await this.orderService.paidGoodsInfo(info.chick_suitid, info.chick_userid);
|
const suit = await this.orderService.paidGoodsInfo(info.chick_suitid, info.chick_userid);
|
||||||
console.log(suit);
|
info['suit_info'] = suit;
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,7 +42,4 @@ export class ChickensService {
|
|||||||
return `This action updates a #${id} chicken`;
|
return `This action updates a #${id} chicken`;
|
||||||
}
|
}
|
||||||
|
|
||||||
remove(id: number) {
|
|
||||||
return `This action removes a #${id} chicken`;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ export class LoggingInterceptor implements NestInterceptor {
|
|||||||
const userid = request.query.userid;
|
const userid = request.query.userid;
|
||||||
|
|
||||||
const token = await this.cacheRedis.get(getUserTokenKey(userid));
|
const token = await this.cacheRedis.get(getUserTokenKey(userid));
|
||||||
console.log(token)
|
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
if (!token) {
|
if (!token) {
|
||||||
return throwError(new HttpException('登录信息错误', HttpStatus.SEE_OTHER))
|
return throwError(new HttpException('登录信息错误', HttpStatus.SEE_OTHER))
|
||||||
|
@ -51,7 +51,7 @@ export class GoodsController {
|
|||||||
})
|
})
|
||||||
@Get(':id')
|
@Get(':id')
|
||||||
async findOne(@Query('id') id: number) {
|
async findOne(@Query('id') id: number) {
|
||||||
return this.goodsService.findOne(+id, GoodsStatus.HIDE);
|
return this.goodsService.findOne(+id, [GoodsStatus.SELLING,GoodsStatus.SELLEND]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -40,10 +40,10 @@ export class GoodsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** 查询商品详情 */
|
/** 查询商品详情 */
|
||||||
async findOne(id: number, status?: string) {
|
async findOne(id: number, status?: string[]) {
|
||||||
let findBuilder = this.goodsRepository.createQueryBuilder(prefix);
|
let findBuilder = this.goodsRepository.createQueryBuilder(prefix);
|
||||||
//商品状态(API接口排除隐藏的)
|
//商品状态(API接口排除隐藏的)
|
||||||
if (status) findBuilder = findBuilder.andWhere(`status != :status`, { status: status });
|
if (status) findBuilder = findBuilder.andWhere(`status IN (:status)`, { status: status });
|
||||||
const returnData = await findBuilder.select().andWhere(`id=:id`, { id: id }).getRawOne();
|
const returnData = await findBuilder.select().andWhere(`id=:id`, { id: id }).getRawOne();
|
||||||
if (!returnData) return CustomResult(CODE.CODE_GOODS_INFO_ERR);
|
if (!returnData) return CustomResult(CODE.CODE_GOODS_INFO_ERR);
|
||||||
return SuccessResult(returnData);
|
return SuccessResult(returnData);
|
||||||
|
@ -9,28 +9,28 @@ import { ApiTags } from '@nestjs/swagger';
|
|||||||
export class InvitedstatisticsController {
|
export class InvitedstatisticsController {
|
||||||
constructor(private readonly invitedstatisticsService: InvitedstatisticsService) {}
|
constructor(private readonly invitedstatisticsService: InvitedstatisticsService) {}
|
||||||
|
|
||||||
@Post()
|
// @Post()
|
||||||
create(@Body() createInvitedstatisticDto: CreateInvitedstatisticDto) {
|
// create(@Body() createInvitedstatisticDto: CreateInvitedstatisticDto) {
|
||||||
return this.invitedstatisticsService.create(createInvitedstatisticDto);
|
// return this.invitedstatisticsService.create(createInvitedstatisticDto);
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Get()
|
// @Get()
|
||||||
findAll() {
|
// findAll() {
|
||||||
return this.invitedstatisticsService.findAll();
|
// return this.invitedstatisticsService.findAll();
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Get(':id')
|
// @Get(':id')
|
||||||
findOne(@Param('id') id: string) {
|
// findOne(@Param('id') id: string) {
|
||||||
return this.invitedstatisticsService.findOne(+id);
|
// return this.invitedstatisticsService.findOne(+id);
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Patch(':id')
|
// @Patch(':id')
|
||||||
update(@Param('id') id: string, @Body() updateInvitedstatisticDto: UpdateInvitedstatisticDto) {
|
// update(@Param('id') id: string, @Body() updateInvitedstatisticDto: UpdateInvitedstatisticDto) {
|
||||||
return this.invitedstatisticsService.update(+id, updateInvitedstatisticDto);
|
// return this.invitedstatisticsService.update(+id, updateInvitedstatisticDto);
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Delete(':id')
|
// @Delete(':id')
|
||||||
remove(@Param('id') id: string) {
|
// remove(@Param('id') id: string) {
|
||||||
return this.invitedstatisticsService.remove(+id);
|
// return this.invitedstatisticsService.remove(+id);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { IsNotEmpty, IsInt, IsIn } from "class-validator";
|
import { IsNotEmpty, IsInt, IsIn, IsString } from "class-validator";
|
||||||
import { GoodsTypes } from "src/common/const";
|
import { GoodsTypes } from "src/common/const";
|
||||||
|
|
||||||
export class CreateOrderlogDto {
|
export class CreateOrderlogDto {
|
||||||
@ -22,6 +22,12 @@ export class CreateOrderlogDto {
|
|||||||
@IsInt()
|
@IsInt()
|
||||||
goods_attribute: number;
|
goods_attribute: number;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
goods_desc: string;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
goods_url: string;
|
||||||
|
|
||||||
buy_time?: Date;
|
buy_time?: Date;
|
||||||
create_time?: Date;
|
create_time?: Date;
|
||||||
update_time?: Date;
|
update_time?: Date;
|
||||||
|
@ -28,6 +28,12 @@ export class OrderlogEntity {
|
|||||||
@Column({ comment: '商品属性(如:饲料(克),背景/道具/套装(天)', type: 'bigint' })
|
@Column({ comment: '商品属性(如:饲料(克),背景/道具/套装(天)', type: 'bigint' })
|
||||||
goods_attribute: number;
|
goods_attribute: number;
|
||||||
|
|
||||||
|
@Column({ comment: '商品描述', type: 'varchar', default: '' })
|
||||||
|
goods_desc: string;
|
||||||
|
|
||||||
|
@Column({ comment: '商品地址(图片路径)', type: 'varchar', default: '' })
|
||||||
|
goods_url: string;
|
||||||
|
|
||||||
@CreateDateColumn({ comment: '购买时间', type: 'timestamp' })
|
@CreateDateColumn({ comment: '购买时间', type: 'timestamp' })
|
||||||
buy_time: Date;
|
buy_time: Date;
|
||||||
|
|
||||||
|
@ -9,19 +9,19 @@ import { ApiTags } from '@nestjs/swagger';
|
|||||||
export class OrderlogController {
|
export class OrderlogController {
|
||||||
constructor(private readonly orderlogService: OrderlogService) {}
|
constructor(private readonly orderlogService: OrderlogService) {}
|
||||||
|
|
||||||
@Post()
|
// @Post()
|
||||||
create(@Body() createOrderlogDto: CreateOrderlogDto) {
|
// create(@Body() createOrderlogDto: CreateOrderlogDto) {
|
||||||
return this.orderlogService.create(createOrderlogDto);
|
// return this.orderlogService.create(createOrderlogDto);
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
@Patch(':id')
|
// @Patch(':id')
|
||||||
update(@Param('id') id: string, @Body() updateOrderlogDto: UpdateOrderlogDto) {
|
// update(@Param('id') id: string, @Body() updateOrderlogDto: UpdateOrderlogDto) {
|
||||||
return this.orderlogService.update(+id, updateOrderlogDto);
|
// return this.orderlogService.update(+id, updateOrderlogDto);
|
||||||
}
|
// }
|
||||||
|
|
||||||
@Delete(':id')
|
// @Delete(':id')
|
||||||
remove(@Param('id') id: string) {
|
// remove(@Param('id') id: string) {
|
||||||
return this.orderlogService.remove(+id);
|
// return this.orderlogService.remove(+id);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,8 @@ import { UserOnlieStatus } from 'src/common/const';
|
|||||||
import { CreateUserDto } from './create-user.dto';
|
import { CreateUserDto } from './create-user.dto';
|
||||||
|
|
||||||
export class UpdateUserDto extends PartialType(CreateUserDto) {
|
export class UpdateUserDto extends PartialType(CreateUserDto) {
|
||||||
@IsNotEmpty({ message: '用户状态不能为空' })
|
|
||||||
@IsIn(Object.values(UserOnlieStatus))
|
@IsIn(Object.values(UserOnlieStatus))
|
||||||
online_status: string;
|
online_status?: string;
|
||||||
|
|
||||||
update_time?:Date;
|
update_time?:Date;
|
||||||
}
|
}
|
||||||
|
@ -9,14 +9,16 @@ import { OrderlogEntity } from 'src/orderlog/entities/orderlog.entity';
|
|||||||
import { OrderlogService } from 'src/orderlog/orderlog.service';
|
import { OrderlogService } from 'src/orderlog/orderlog.service';
|
||||||
import { ConfigModule } from '@nestjs/config';
|
import { ConfigModule } from '@nestjs/config';
|
||||||
import { CacheService } from 'src/redis/redis';
|
import { CacheService } from 'src/redis/redis';
|
||||||
|
import { ChickensService } from 'src/chickens/chickens.service';
|
||||||
|
import { ChickenEntity } from 'src/chickens/entities/chicken.entity';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
ConfigModule,
|
ConfigModule,
|
||||||
TypeOrmModule.forFeature([UserEntity, GoodsEntity, OrderlogEntity])
|
TypeOrmModule.forFeature([UserEntity, GoodsEntity, OrderlogEntity,ChickenEntity])
|
||||||
],
|
],
|
||||||
controllers: [UserController],
|
controllers: [UserController],
|
||||||
exports: [UserService],
|
exports: [UserService],
|
||||||
providers: [UserService, GoodsService, OrderlogService,CacheService]
|
providers: [UserService, GoodsService, OrderlogService,CacheService,ChickensService]
|
||||||
})
|
})
|
||||||
export class UserModule { }
|
export class UserModule { }
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { Injectable, Logger } from '@nestjs/common';
|
import { Injectable, Logger } from '@nestjs/common';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
|
import { ChickensService } from 'src/chickens/chickens.service';
|
||||||
import { CODE } from 'src/common/code';
|
import { CODE } from 'src/common/code';
|
||||||
import { GoodsStatus, GoodsTypes, UserOnlieStatus } from 'src/common/const';
|
import { GoodsStatus, GoodsTypes, UserOnlieStatus } from 'src/common/const';
|
||||||
import { ExternalApiService } from 'src/common/utils/external-api';
|
import { ExternalApiService } from 'src/common/utils/external-api';
|
||||||
@ -9,7 +10,7 @@ import { CreateOrderlogDto } from 'src/orderlog/dto/create-orderlog.dto';
|
|||||||
import { OrderlogService } from 'src/orderlog/orderlog.service';
|
import { OrderlogService } from 'src/orderlog/orderlog.service';
|
||||||
import { getUserShoppingKey, getUserTokenKey } from 'src/redis/keys';
|
import { getUserShoppingKey, getUserTokenKey } from 'src/redis/keys';
|
||||||
import { CacheService } from 'src/redis/redis';
|
import { CacheService } from 'src/redis/redis';
|
||||||
import { Repository } from 'typeorm';
|
import { getManager, Repository } from 'typeorm';
|
||||||
import { BuyGoodsUserDto } from './dto/buygoods-user.dto';
|
import { BuyGoodsUserDto } from './dto/buygoods-user.dto';
|
||||||
import { CreateUserDto } from './dto/create-user.dto';
|
import { CreateUserDto } from './dto/create-user.dto';
|
||||||
import { UpdateUserDto } from './dto/update-user.dto';
|
import { UpdateUserDto } from './dto/update-user.dto';
|
||||||
@ -26,6 +27,7 @@ export class UserService {
|
|||||||
private readonly goodsService: GoodsService,
|
private readonly goodsService: GoodsService,
|
||||||
private readonly orderLogService: OrderlogService,
|
private readonly orderLogService: OrderlogService,
|
||||||
private readonly cacheService: CacheService,
|
private readonly cacheService: CacheService,
|
||||||
|
private readonly chickensService: ChickensService,
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
/**查询用户信息,没有则初始化 */
|
/**查询用户信息,没有则初始化 */
|
||||||
@ -34,7 +36,13 @@ export class UserService {
|
|||||||
await this.initToken(createUserDto);
|
await this.initToken(createUserDto);
|
||||||
//查询用户信息
|
//查询用户信息
|
||||||
const userInfo = await this.findOne(createUserDto.userid);
|
const userInfo = await this.findOne(createUserDto.userid);
|
||||||
if (userInfo) return SuccessResult(userInfo);
|
if (userInfo) {
|
||||||
|
//小鸡信息
|
||||||
|
userInfo['chickens'] = {};
|
||||||
|
const chick = await this.chickensService.chickensInfo(createUserDto.userid);
|
||||||
|
if (chick) userInfo['chickens'] = chick;
|
||||||
|
return SuccessResult(userInfo);
|
||||||
|
}
|
||||||
//有信息则返回
|
//有信息则返回
|
||||||
const appUserInfo = await ExternalApiService.getAppUserInfo(createUserDto.userid, createUserDto.token);
|
const appUserInfo = await ExternalApiService.getAppUserInfo(createUserDto.userid, createUserDto.token);
|
||||||
//用户信息异常处理
|
//用户信息异常处理
|
||||||
@ -96,31 +104,36 @@ export class UserService {
|
|||||||
|
|
||||||
/** 用户购买商品逻辑 */
|
/** 用户购买商品逻辑 */
|
||||||
async buy(buyGoodsUserDto: BuyGoodsUserDto) {
|
async buy(buyGoodsUserDto: BuyGoodsUserDto) {
|
||||||
|
const { userid, goodsid, goods_count } = buyGoodsUserDto;
|
||||||
//查询APP用户信息
|
//查询APP用户信息
|
||||||
const token = await this.cacheService.get(getUserTokenKey(buyGoodsUserDto.userid));
|
const token = await this.cacheService.get(getUserTokenKey(userid));
|
||||||
const appUserInfo = await ExternalApiService.getAppUserInfo(buyGoodsUserDto.userid, token);
|
const appUserInfo = await ExternalApiService.getAppUserInfo(userid, token);
|
||||||
if (appUserInfo?.code != 200) return appUserInfo;
|
if (appUserInfo?.code != 200) return appUserInfo;
|
||||||
const user = appUserInfo.data;
|
const user = appUserInfo.data;
|
||||||
|
|
||||||
//查询商品信息
|
//查询商品信息
|
||||||
const goodsInfo: any = await this.goodsService.findOne(buyGoodsUserDto.goodsid, GoodsStatus.HIDE);
|
const goodsInfo: any = await this.goodsService.findOne(goodsid, [GoodsStatus.SELLING]);
|
||||||
if (goodsInfo?.code != 200) return CustomResult(CODE.CODE_GOODS_INFO_ERR);
|
if (goodsInfo?.code != 200) return CustomResult(CODE.CODE_GOODS_INFO_ERR);
|
||||||
const goods = goodsInfo.data;
|
const goods = goodsInfo.data;
|
||||||
|
|
||||||
//判断用户金额是否满足条件 (商品价格*商品数量)
|
//判断用户金额是否满足条件 (商品价格*商品数量)
|
||||||
const payCoin = goods.goods_price * buyGoodsUserDto.goods_count;//应支付价格
|
const payCoin = goods.goods_price * goods_count;//应支付价格
|
||||||
if (user.coin < payCoin) return CustomResult(CODE.CODE_APPUSER_COIN_NOT_ENOUGHT_ERR);
|
if (user.coin < payCoin) return CustomResult(CODE.CODE_APPUSER_COIN_NOT_ENOUGHT_ERR);
|
||||||
|
|
||||||
//扣减加锁 锁几秒
|
//扣减加锁 锁几秒
|
||||||
const locKeys = getUserShoppingKey(buyGoodsUserDto.userid, buyGoodsUserDto.goodsid);
|
const locKeys = getUserShoppingKey(userid, goodsid);
|
||||||
const queryLock = await this.cacheService.get(locKeys);
|
const queryLock = await this.cacheService.get(locKeys);
|
||||||
if (queryLock) return CustomResult(CODE.CODE_USER_PAY_LOCK_ERR);
|
if (queryLock) return CustomResult(CODE.CODE_USER_PAY_LOCK_ERR);
|
||||||
await this.cacheService.set(locKeys, true, 5);
|
await this.cacheService.set(locKeys, true, 3);
|
||||||
|
|
||||||
//用户金额扣减
|
//用户金额扣减
|
||||||
const subUserInfo = await ExternalApiService.subAppUserCoin(buyGoodsUserDto.userid, token, payCoin);
|
const subUserInfo = await ExternalApiService.subAppUserCoin(userid, token, payCoin);
|
||||||
|
|
||||||
if (subUserInfo?.code != 200) return CustomResult(CODE.CODE_APPUSER_SUB_COIN_ERR);
|
if (subUserInfo?.code != 200) return CustomResult(CODE.CODE_APPUSER_SUB_COIN_ERR);
|
||||||
|
// 购买饲料则要发放饲料
|
||||||
|
if (goods.goods_type === GoodsTypes.FODDER) {
|
||||||
|
await this.insertFodder(userid, goods.goods_attribute * goods_count);
|
||||||
|
}
|
||||||
|
|
||||||
//发放完成记录日志
|
//发放完成记录日志
|
||||||
const orderInfo: CreateOrderlogDto = {
|
const orderInfo: CreateOrderlogDto = {
|
||||||
@ -128,14 +141,31 @@ export class UserService {
|
|||||||
goods_id: goods.goods_id,
|
goods_id: goods.goods_id,
|
||||||
goods_type: goods.goods_type,
|
goods_type: goods.goods_type,
|
||||||
goods_price: goods.goods_price,
|
goods_price: goods.goods_price,
|
||||||
|
goods_desc: goods.goods_desc || '',
|
||||||
|
goods_url: goods.goods_image || '',
|
||||||
goods_attribute: goods.goods_attribute
|
goods_attribute: goods.goods_attribute
|
||||||
}
|
}
|
||||||
const orderRes = await this.orderLogService.create(orderInfo);
|
const orderRes = await this.orderLogService.create(orderInfo);
|
||||||
logger.debug(`购买订单日志结果: ${JSON.stringify(orderRes)}`);
|
logger.debug(`购买订单日志结果: ${JSON.stringify(orderRes)}`);
|
||||||
if (orderRes.code != 200) return CustomResult(CODE.CODE_GOODS_DEAL_ERR);
|
if (orderRes.code != 200) return CustomResult(CODE.CODE_GOODS_DEAL_ERR);
|
||||||
|
|
||||||
return SuccessResult(orderRes.data);
|
//返回用户信息
|
||||||
|
const userInfo = await this.userRepository.createQueryBuilder(prefix).select().where('userid=:userid', { userid: userid }).getRawOne();
|
||||||
|
return SuccessResult(userInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 饲料领取
|
||||||
|
*/
|
||||||
|
private async insertFodder(userid: number, fodder: number) {
|
||||||
|
await getManager().transaction(async manager => {
|
||||||
|
const user = await manager.findOne(UserEntity, { userid: userid });
|
||||||
|
if (user) {
|
||||||
|
user.update_time = new Date();
|
||||||
|
user.fodder_balance = Number(user.fodder_balance) + fodder;
|
||||||
|
await manager.save(user);
|
||||||
|
logger.debug(`用户 ${userid} 购买了 ${fodder} g饲料`);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user