| | |
| | | "remark": "自动确认收货时间,从支付成功起算,单位:天" |
| | | }, |
| | | { |
| | | "keyName": "carbonratio", |
| | | "name": "碳积分兑换比例", |
| | | "data": "100", |
| | | "dataType": 0, |
| | | "remark": "商城碳积分支付:所需积分 = 订单金额 * carbonratio,默认 100" |
| | | }, |
| | | { |
| | | "keyName": "userAgreement", |
| | | "name": "用户协议", |
| | | "data": "<h3 style=\"text-align: center;\"><strong>用户协议</strong></h3><p><br></p><p>xxxxxx</p>", |
| | |
| | | export class MarketCouponUserEntity extends BaseEntity { |
| | | @Index() |
| | | @Column({ comment: '用户ID' }) |
| | | userId: number; |
| | | userId: string; |
| | | |
| | | @Index() |
| | | @Column({ comment: '优惠券ID' }) |
| | |
| | | * @param couponId |
| | | * @param userId |
| | | */ |
| | | async receive(couponId: number, userId: number) { |
| | | async receive(couponId: number, userId: string) { |
| | | // 检查优惠券 |
| | | await this.check(couponId); |
| | | // 检查用户是否已领取 |
| | |
| | | * @param userId |
| | | * @param order |
| | | */ |
| | | async checkAndUse(couponId: number, userId: number, order: OrderInfoEntity) { |
| | | async checkAndUse(couponId: number, userId: string, order: OrderInfoEntity) { |
| | | // 判断优惠券 |
| | | const couponInfo = await this.check(couponId); |
| | | // 判断用户 |
| | |
| | | * @param idcouponId |
| | | * @param userId |
| | | */ |
| | | async save(couponId: number, userId: number) { |
| | | async save(couponId: number, userId: string) { |
| | | const couponUser = new MarketCouponUserEntity(); |
| | | couponUser.userId = userId; |
| | | couponUser.couponId = couponId; |
| | |
| | | * @param couponId |
| | | * @param userId |
| | | */ |
| | | async check(couponId: number, userId: number) { |
| | | async check(couponId: number, userId: string) { |
| | | const info = await this.marketCouponUserEntity.findOneBy({ |
| | | couponId: Equal(couponId), |
| | | userId: Equal(userId), |
| | |
| | | * @param couponId |
| | | * @param userId |
| | | */ |
| | | async checkExist(couponId: number, userId: number) { |
| | | async checkExist(couponId: number, userId: string) { |
| | | const info = await this.marketCouponUserEntity.findOneBy({ |
| | | couponId: Equal(couponId), |
| | | userId: Equal(userId), |
| | |
| | | * @param couponId |
| | | * @param userId |
| | | */ |
| | | async use(couponId: number, userId: number) { |
| | | async use(couponId: number, userId: string) { |
| | | await this.marketCouponUserEntity.update( |
| | | { couponId: Equal(couponId), userId: Equal(userId) }, |
| | | { status: 1, useTime: new Date() } |
| | |
| | | entity: OrderInfoEntity, |
| | | service: OrderInfoService, |
| | | pageQueryOp: { |
| | | fieldEq: ['status'], |
| | | fieldEq: ['status','userId'], |
| | | where: ctx => { |
| | | return [ |
| | | // 过滤用户ID |
| | |
| | | remark: string; |
| | | title: string; |
| | | couponId: number; |
| | | payType?: number; |
| | | } |
| | | ) { |
| | | return this.ok( |
| | |
| | | await this.orderPayService.wxAppPay(orderId, this.ctx.user.id) |
| | | ); |
| | | } |
| | | |
| | | @Post('/carbonPay', { summary: '碳积分支付' }) |
| | | async carbonPay(@Body('orderId') orderId) { |
| | | return this.ok( |
| | | await this.orderPayService.carbonPay(orderId, this.ctx.user.id) |
| | | ); |
| | | } |
| | | } |
| | |
| | | export class OrderInfoEntity extends BaseEntity { |
| | | @Index() |
| | | @Column({ comment: '用户ID' }) |
| | | userId: number; |
| | | userId: string; |
| | | |
| | | @Column({ comment: '标题', nullable: true }) |
| | | title: string; |
| | | |
| | | @Column({ comment: '支付方式 0-待支付 1-微信 2-支付宝', default: 0 }) |
| | | @Column({ comment: '支付方式 0-待支付 1-微信 2-支付宝 3-碳积分', default: 0 }) |
| | | payType: number; |
| | | |
| | | @Column({ comment: '支付时间', type: 'datetime', nullable: true }) |
| | |
| | | * @param data |
| | | */ |
| | | async create(data: { |
| | | userId: number; |
| | | userId: string; |
| | | goodsList: OrderGoodsEntity[]; |
| | | addressId: number; |
| | | remark: string; |
| | | title: string; |
| | | couponId?: number; |
| | | payType?: number; |
| | | }) { |
| | | const address = await this.userAddressService.info(data.addressId); |
| | | const payType = Number(data.payType) || 0; |
| | | const order = { |
| | | userId: data.userId, |
| | | address, |
| | | remark: data.remark, |
| | | title: data.title, |
| | | goodsList: data.goodsList, |
| | | payType, |
| | | } as OrderInfoEntity; |
| | | // 检查库存 |
| | | await this.checkStock(data.goodsList); |
| | |
| | | // 生成订单号 |
| | | const orderNum = await this.generateOrderNum(order.id); |
| | | |
| | | // 更新订单 |
| | | await this.orderInfoEntity.update(order.id, { |
| | | orderNum, |
| | | payType, |
| | | }); |
| | | |
| | | // 保存订单商品 |
| | |
| | | * 物流信息 |
| | | * @param orderId |
| | | */ |
| | | async logistics(orderId: number, userId?: number) { |
| | | async logistics(orderId: number, userId?: string) { |
| | | const order: OrderInfoEntity = await this.info(orderId); |
| | | if (userId && order.userId != userId) { |
| | | throw new CoolCommException('非法操作'); |
| | |
| | | import { Init, Inject, Provide } from '@midwayjs/core'; |
| | | import { BaseService, CoolCommException } from '@cool-midway/core'; |
| | | import { BaseService, CoolCommException, CoolTransaction } from '@cool-midway/core'; |
| | | import { PluginService } from '../../plugin/service/info'; |
| | | import { OrderInfoService } from './info'; |
| | | import { UserWxService } from '../../user/service/wx'; |
| | | import BigNumber from 'bignumber.js'; |
| | | import { OrderInfoEntity } from '../entity/info'; |
| | | import { InjectEntityModel } from '@midwayjs/typeorm'; |
| | | import { Repository } from 'typeorm'; |
| | | import { QueryRunner, Repository } from 'typeorm'; |
| | | import { Action, OrderQueue } from '../queue/order'; |
| | | import { BaseSysParamService } from '../../base/service/sys/param'; |
| | | import { UserInfoEntity } from '../../user/entity/info'; |
| | | import { RecycleTransactionEntity } from '../../shop/entity/transaction'; |
| | | |
| | | /** |
| | | * 支付 |
| | |
| | | export class OrderPayService extends BaseService { |
| | | @InjectEntityModel(OrderInfoEntity) |
| | | orderInfoEntity: Repository<OrderInfoEntity>; |
| | | |
| | | @InjectEntityModel(UserInfoEntity) |
| | | userInfoEntity: Repository<UserInfoEntity>; |
| | | |
| | | @InjectEntityModel(RecycleTransactionEntity) |
| | | recycleTransactionEntity: Repository<RecycleTransactionEntity>; |
| | | |
| | | @Inject() |
| | | pluginService: PluginService; |
| | |
| | | /** |
| | | * 支付成功 |
| | | * @param orderNum 订单号 |
| | | * @param payType 支付方式 0-待支付 1-微信 2-支付宝 |
| | | * @param payType 支付方式 0-待支付 1-微信 2-支付宝 3-碳积分 |
| | | */ |
| | | async paySuccess(orderNum: string, payType: number) { |
| | | const order = await this.orderInfoService.getByOrderNum(orderNum); |
| | |
| | | await this.orderInfoEntity.update(order.id, { |
| | | payType, |
| | | status: 1, |
| | | payTime: order.payTime, |
| | | payTime: new Date(), |
| | | }); |
| | | // 发送自动确认收货队列 |
| | | const orderConfirm = await this.baseSysParamService.dataByKey( |
| | |
| | | * @param userId |
| | | * @param orderId |
| | | */ |
| | | async wxMiniPay(orderId: number, userId: number) { |
| | | async wxMiniPay(orderId: number, userId: string) { |
| | | await this.orderInfoEntity.update(orderId, { wxType: 0 }); |
| | | return await this.wxJSAPI(orderId, userId, 0); |
| | | } |
| | |
| | | * @param userId |
| | | * @param orderId |
| | | */ |
| | | async wxMpPay(orderId: number, userId: number) { |
| | | async wxMpPay(orderId: number, userId: string) { |
| | | await this.orderInfoEntity.update(orderId, { wxType: 1 }); |
| | | return await this.wxJSAPI(orderId, userId, 1); |
| | | } |
| | |
| | | * @param userId |
| | | * @returns |
| | | */ |
| | | async wxAppPay(orderId: number, userId: number) { |
| | | async wxAppPay(orderId: number, userId: string) { |
| | | const appid = await this.getAppidByType(2); |
| | | |
| | | const { config, instance } = await this.wxPayInstance(appid); |
| | |
| | | * @param userId |
| | | * @returns |
| | | */ |
| | | async getOrder(orderId: number, userId: number) { |
| | | async getOrder(orderId: number, userId: string) { |
| | | const order: OrderInfoEntity = await this.orderInfoService.info(orderId); |
| | | if (!order || order.status != 0 || order.userId != userId) { |
| | | throw new CoolCommException('订单不存在或不是可以支付的状态'); |
| | |
| | | * @param type 0-小程序 1-公众号 2-App |
| | | * @returns |
| | | */ |
| | | async wxJSAPI(orderId: number, userId: number, type = 0) { |
| | | async wxJSAPI(orderId: number, userId: string, type = 0) { |
| | | const order = await this.getOrder(orderId, userId); |
| | | const openid = await this.userWxService.getOpenid(userId, type); |
| | | |
| | |
| | | } |
| | | throw new CoolCommException(result.message); |
| | | } |
| | | |
| | | /** |
| | | * 读取碳积分兑换比例,默认 100 |
| | | */ |
| | | async getCarbonRatio() { |
| | | try { |
| | | const value = await this.baseSysParamService.dataByKey('carbonratio'); |
| | | const ratio = Number(value); |
| | | if (ratio > 0) { |
| | | return ratio; |
| | | } |
| | | } catch (e) {} |
| | | return 100; |
| | | } |
| | | |
| | | /** |
| | | * 碳积分支付:不调用外部渠道 |
| | | * 扣减积分 = 订单实付金额 * carbonratio |
| | | */ |
| | | @CoolTransaction() |
| | | async carbonPay(orderId: number, userId: string, queryRunner?: QueryRunner) { |
| | | if (!queryRunner) { |
| | | throw new CoolCommException('事务启动失败'); |
| | | } |
| | | |
| | | const manager = queryRunner.manager; |
| | | const order = await manager.findOne(OrderInfoEntity, { |
| | | where: { id: orderId }, |
| | | }); |
| | | if (!order || order.status != 0 || order.userId != userId) { |
| | | throw new CoolCommException('订单不存在或不是可以支付的状态'); |
| | | } |
| | | |
| | | const user = await manager.findOne(UserInfoEntity, { |
| | | where: { unionid: userId }, |
| | | }); |
| | | if (!user) { |
| | | throw new CoolCommException('用户不存在'); |
| | | } |
| | | |
| | | const ratio = await this.getCarbonRatio(); |
| | | const payAmount = new BigNumber(order.price).minus(order.discountPrice || 0); |
| | | const carbonCost = payAmount.multipliedBy(ratio).toNumber(); |
| | | |
| | | if (Number(user.carbonBalance || 0) < carbonCost) { |
| | | throw new CoolCommException('碳积分不足'); |
| | | } |
| | | |
| | | const dec = await manager |
| | | .createQueryBuilder() |
| | | .update(UserInfoEntity) |
| | | .set({ carbonBalance: () => `carbonBalance - ${carbonCost}` }) |
| | | .where('id = :id AND carbonBalance >= :cost', { |
| | | id: userId, |
| | | cost: carbonCost, |
| | | }) |
| | | .execute(); |
| | | if (!dec.affected) { |
| | | throw new CoolCommException('碳积分不足'); |
| | | } |
| | | |
| | | await manager.update(OrderInfoEntity, order.id, { |
| | | payType: 3, |
| | | status: 1, |
| | | payTime: new Date(), |
| | | }); |
| | | |
| | | await manager.save(RecycleTransactionEntity, { |
| | | userId: user.unionid || String(userId), |
| | | departmentId: user.departmentId, |
| | | type: '支出', |
| | | amount: carbonCost, |
| | | sourceType: '商城', |
| | | remark: `商城订单 ${order.orderNum} 碳积分支付`, |
| | | orderId: order.orderNum, |
| | | }); |
| | | |
| | | const orderConfirm = await this.baseSysParamService.dataByKey('orderConfirm'); |
| | | this.orderQueue.add( |
| | | { orderId: order.id, action: Action.CONFIRM }, |
| | | { |
| | | delay: orderConfirm * 60 * 60 * 1000, |
| | | } |
| | | ); |
| | | |
| | | return true; |
| | | } |
| | | } |
| New file |
| | |
| | | import { Inject } from "@midwayjs/core"; |
| | | import { CoolController, BaseController } from "@cool-midway/core"; |
| | | import { RecycleAppointmentEntity } from "../../entity/recycleappointment"; |
| | | import { RecycleAppointmentService } from "../../service/recycleappointment"; |
| | | |
| | | /** |
| | | * 回收预约-应用端 |
| | | */ |
| | | @CoolController({ |
| | | api: ["add", "info", "page"], |
| | | entity: RecycleAppointmentEntity, |
| | | service: RecycleAppointmentService, |
| | | pageQueryOp: { |
| | | fieldEq: ["a.status", "a.campusUserId"], |
| | | addOrderBy: { |
| | | createTime: "DESC", |
| | | }, |
| | | where: async (ctx) => { |
| | | const { tab } = ctx.request.body; |
| | | if (tab === "done") { |
| | | return [["a.status = :st", { st: "已完成" }]]; |
| | | } |
| | | if (tab === "booked") { |
| | | return [["a.status != :st", { st: "已完成" }]]; |
| | | } |
| | | return []; |
| | | }, |
| | | }, |
| | | }) |
| | | export class AppRecycleAppointmentController extends BaseController { |
| | | @Inject() |
| | | recycleAppointmentService: RecycleAppointmentService; |
| | | } |
| | |
| | | entity: RecycleOrderEntity, |
| | | service: RecycleOrderService, |
| | | pageQueryOp: { |
| | | fieldEq: ["a.status"], |
| | | where: async (ctx) => { |
| | | return [ |
| | | ["a.campusUserId = :userId", { userId: ctx.user.id }] |
| | | ]; |
| | | } |
| | | fieldEq: ["a.status","a.campusUserId","a.orderType"], |
| | | addOrderBy:{createTime:'DESC'} |
| | | } |
| | | }) |
| | | export class AppRecycleOrderController extends BaseController { |
| | |
| | | import { CoolController, BaseController } from "@cool-midway/core"; |
| | | import { RecycleOrderItemEntity } from "../../entity/recycleorderitem"; |
| | | import { RecycleOrderItemService } from "../../service/recycleorderitem"; |
| | | import { RecycleItemEntity } from "../../entity/recycleitem"; |
| | | |
| | | /** |
| | | * 回收订单条目-应用端 |
| | |
| | | entity: RecycleOrderItemEntity, |
| | | service: RecycleOrderItemService, |
| | | pageQueryOp: { |
| | | select: ["a.*", "b.mainPic"], |
| | | fieldEq: ["a.orderId"], |
| | | join: [ |
| | | { |
| | | entity: RecycleItemEntity, |
| | | alias: "b", |
| | | condition: "a.itemId = b.id", |
| | | }, |
| | | ], |
| | | fieldEq: ["a.orderId"] |
| | | }, |
| | | }) |
| | | export class AppRecycleOrderitemController extends BaseController { |
| New file |
| | |
| | | import { Body, Inject, Post } from '@midwayjs/core'; |
| | | import { CoolController, BaseController } from '@cool-midway/core'; |
| | | import { RecycleTransactionEntity } from '../../entity/transaction'; |
| | | import { RecycleTransactionService } from '../../service/transaction'; |
| | | |
| | | /** |
| | | * 碳积分流水-应用端 |
| | | */ |
| | | @CoolController({ |
| | | api: ['page'], |
| | | entity: RecycleTransactionEntity, |
| | | service: RecycleTransactionService, |
| | | pageQueryOp: { |
| | | addOrderBy: { |
| | | createTime: 'DESC', |
| | | }, |
| | | }, |
| | | }) |
| | | export class AppRecycleTransactionController extends BaseController { |
| | | @Inject() |
| | | recycleTransactionService: RecycleTransactionService; |
| | | |
| | | @Post('/checkUser', { summary: '校验转赠接收人' }) |
| | | async checkUser(@Body('unionid') unionid: string) { |
| | | return this.ok(await this.recycleTransactionService.checkUser(unionid)); |
| | | } |
| | | |
| | | @Post('/transfer', { summary: '碳积分转赠' }) |
| | | async transfer( |
| | | @Body() |
| | | body: { |
| | | fromUnionid: string; |
| | | toUnionid: string; |
| | | amount: number; |
| | | } |
| | | ) { |
| | | return this.ok(await this.recycleTransactionService.transfer(body)); |
| | | } |
| | | } |
| | |
| | | }); |
| | | |
| | | if (order?.campusUserId) { |
| | | await UserInfoEntity.update( |
| | | await UserInfoEntity.getRepository().increment( |
| | | { unionid: order.campusUserId }, |
| | | { |
| | | carbonBalance: () => `carbonBalance + ${totalCarbonPoint}` |
| | | } |
| | | 'carbonBalance', |
| | | totalCarbonPoint |
| | | ); |
| | | } |
| | | |
| | |
| | | import { Provide } from '@midwayjs/core'; |
| | | import { BaseService } from '@cool-midway/core'; |
| | | import { BaseService, CoolCommException, CoolTransaction } from '@cool-midway/core'; |
| | | import { InjectEntityModel } from '@midwayjs/typeorm'; |
| | | import { Repository } from 'typeorm'; |
| | | import { QueryRunner, Repository } from 'typeorm'; |
| | | import { RecycleTransactionEntity } from '../entity/transaction'; |
| | | import { UserInfoEntity } from '../../user/entity/info'; |
| | | |
| | | /** |
| | | * 碳积分流转记录 |
| | |
| | | @InjectEntityModel(RecycleTransactionEntity) |
| | | recycleTransactionEntity: Repository<RecycleTransactionEntity>; |
| | | |
| | | } |
| | | @InjectEntityModel(UserInfoEntity) |
| | | userInfoEntity: Repository<UserInfoEntity>; |
| | | |
| | | /** |
| | | * App 端分页:转赠 tab 只看赠送/接受,收支 tab 看其余类型 |
| | | */ |
| | | async page(query: any) { |
| | | const { userId, tab, page = 1, size = 10 } = query || {}; |
| | | const find = this.recycleTransactionEntity.createQueryBuilder('a'); |
| | | |
| | | if (userId) { |
| | | find.andWhere('a.userId = :uid', { uid: String(userId) }); |
| | | } |
| | | |
| | | if (tab === 'io') { |
| | | find.andWhere('(a.sourceType != :t1 AND a.sourceType != :t2)', { |
| | | t1: '赠送', |
| | | t2: '接受', |
| | | }); |
| | | } else { |
| | | find.andWhere('(a.sourceType = :t1 OR a.sourceType = :t2)', { |
| | | t1: '赠送', |
| | | t2: '接受', |
| | | }); |
| | | } |
| | | |
| | | find.orderBy('a.createTime', 'DESC'); |
| | | find.addOrderBy('a.id', 'DESC'); |
| | | |
| | | console.log(find) |
| | | |
| | | return this.entityRenderPage(find, { ...query, page, size }, false); |
| | | } |
| | | |
| | | async checkUser(unionid: string) { |
| | | if (!unionid) { |
| | | throw new CoolCommException('请选择系统用户作为接受转赠对象'); |
| | | } |
| | | const user = await this.userInfoEntity.findOneBy({ unionid }); |
| | | if (!user) { |
| | | throw new CoolCommException('请选择系统用户作为接受转赠对象'); |
| | | } |
| | | return { |
| | | unionid: user.unionid, |
| | | nickName: user.nickName, |
| | | phone: user.phone, |
| | | }; |
| | | } |
| | | |
| | | @CoolTransaction() |
| | | async transfer( |
| | | param: { fromUnionid: string; toUnionid: string; amount: number }, |
| | | queryRunner?: QueryRunner |
| | | ) { |
| | | if (!queryRunner) { |
| | | throw new CoolCommException('事务启动失败'); |
| | | } |
| | | |
| | | const fromUnionid = String(param.fromUnionid || '').trim(); |
| | | const toUnionid = String(param.toUnionid || '').trim(); |
| | | const amount = Number(param.amount); |
| | | |
| | | if (!fromUnionid || !toUnionid) { |
| | | throw new CoolCommException('转赠参数不完整'); |
| | | } |
| | | if (fromUnionid === toUnionid) { |
| | | throw new CoolCommException('不能转赠给自己'); |
| | | } |
| | | if (!amount || amount <= 0) { |
| | | throw new CoolCommException('转赠金额必须大于0'); |
| | | } |
| | | |
| | | const manager = queryRunner.manager; |
| | | const fromUser = await manager.findOne(UserInfoEntity, { |
| | | where: { unionid: fromUnionid }, |
| | | }); |
| | | const toUser = await manager.findOne(UserInfoEntity, { |
| | | where: { unionid: toUnionid }, |
| | | }); |
| | | |
| | | if (!toUser) { |
| | | throw new CoolCommException('请选择系统用户作为接受转赠对象'); |
| | | } |
| | | if (!fromUser) { |
| | | throw new CoolCommException('当前用户不存在'); |
| | | } |
| | | if (Number(fromUser.carbonBalance || 0) < amount) { |
| | | throw new CoolCommException('碳积分不足'); |
| | | } |
| | | |
| | | const dec = await manager |
| | | .createQueryBuilder() |
| | | .update(UserInfoEntity) |
| | | .set({ carbonBalance: () => `carbonBalance - ${amount}` }) |
| | | .where('unionid = :unionid AND carbonBalance >= :amount', { |
| | | unionid: fromUnionid, |
| | | amount, |
| | | }) |
| | | .execute(); |
| | | |
| | | if (!dec.affected) { |
| | | throw new CoolCommException('碳积分不足'); |
| | | } |
| | | |
| | | await manager |
| | | .createQueryBuilder() |
| | | .update(UserInfoEntity) |
| | | .set({ carbonBalance: () => `carbonBalance + ${amount}` }) |
| | | .where('unionid = :unionid', { unionid: toUnionid }) |
| | | .execute(); |
| | | |
| | | const fromName = fromUser.nickName || fromUser.phone || fromUnionid; |
| | | const toName = toUser.nickName || toUser.phone || toUnionid; |
| | | |
| | | await manager.save(RecycleTransactionEntity, [ |
| | | { |
| | | userId: fromUnionid, |
| | | departmentId: fromUser.departmentId, |
| | | type: '支出', |
| | | amount, |
| | | sourceType: '赠送', |
| | | remark: `转赠给${toName}`, |
| | | }, |
| | | { |
| | | userId: toUnionid, |
| | | departmentId: toUser.departmentId, |
| | | type: '收入', |
| | | amount, |
| | | sourceType: '接受', |
| | | remark: `从${fromName}获赠`, |
| | | }, |
| | | ]); |
| | | |
| | | return true; |
| | | } |
| | | } |
| | |
| | | ) |
| | | ); |
| | | } |
| | | |
| | | @Post('/dashboard', { summary: '获取用户碳积分信息' }) |
| | | async dashboard(@Body() body) { |
| | | console.log(body) |
| | | const {unionid} = body; |
| | | return this.ok( |
| | | await this.userInfoService.dashboard( |
| | | unionid |
| | | ) |
| | | ); |
| | | } |
| | | } |
| | |
| | | import { UserInfoEntity } from '../entity/info'; |
| | | import { UserSmsService } from './sms'; |
| | | import { UserWxService } from './wx'; |
| | | import { RecycleOrderEntity } from '../../shop/entity/recycleorder'; |
| | | |
| | | |
| | | /** |
| | | * 用户信息 |
| | |
| | | export class UserInfoService extends BaseService { |
| | | @InjectEntityModel(UserInfoEntity) |
| | | userInfoEntity: Repository<UserInfoEntity>; |
| | | |
| | | @InjectEntityModel(RecycleOrderEntity) |
| | | recycleOrderEntity: Repository<RecycleOrderEntity>; |
| | | |
| | | @Inject() |
| | | pluginService: PluginService; |
| | |
| | | uuid() + '.png' |
| | | ); |
| | | } |
| | | } catch (err) {} |
| | | } catch (err) { } |
| | | try { |
| | | return await this.userInfoEntity.update({ id }, param); |
| | | } catch (err) { |
| | |
| | | } |
| | | await this.userInfoEntity.update({ id: userId }, { phone }); |
| | | } |
| | | |
| | | /** |
| | | * 获取用户的碳积分信息 |
| | | * @param unionid |
| | | */ |
| | | async dashboard(unionid) { |
| | | const info = await this.userInfoEntity.findOneBy({ unionid: unionid }); |
| | | if (!info) { |
| | | throw new CoolCommException('查询无结果'); |
| | | } |
| | | |
| | | const count_ = await this.recycleOrderEntity.countBy({ |
| | | campusUserId: unionid |
| | | }); |
| | | |
| | | |
| | | return { carbonPoints: info.carbonBalance, recycleCount:count_, overPercent: 90 } |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | |
| | | }; |
| | | await this.userInfoEntity.insert(user); |
| | | } |
| | | return this.token({ id: user.id }); |
| | | return this.token({ id: user.unionid }); |
| | | } |
| | | |
| | | /** |
| | |
| | | const find: any = { openid: wxUserInfo.openid }; |
| | | let wxInfo: any = await this.userWxEntity.findOneBy(find); |
| | | if (wxInfo) { |
| | | wxUserInfo.id = wxInfo.id; |
| | | wxUserInfo.id = wxInfo.unionid; |
| | | } |
| | | return this.userWxEntity.save({ |
| | | ...wxUserInfo, |
| | |
| | | }; |
| | | await this.userInfoEntity.insert(userInfo); |
| | | } |
| | | return this.token({ id: userInfo.id }); |
| | | return this.token({ id: userInfo.unionid }); |
| | | } |
| | | |
| | | /** |
| | |
| | | const userInfo = await this.userInfoEntity.findOneBy({ |
| | | id: info['id'], |
| | | }); |
| | | return this.token({ id: userInfo.id }); |
| | | return this.token({ id: userInfo?.unionid }); |
| | | } catch (e) { |
| | | throw new CoolCommException( |
| | | '刷新token失败,请检查refreshToken是否正确或过期' |
| | |
| | | |
| | | if (user && user.password == md5(password)) { |
| | | return this.token({ |
| | | id: user.id, |
| | | id: user.unionid, |
| | | }); |
| | | } else { |
| | | throw new CoolCommException('账号或密码错误'); |
| | |
| | | */ |
| | | async generateToken(info, isRefresh = false) { |
| | | const { expire, refreshExpire, secret } = this.jwtConfig; |
| | | const user = await this.userInfoEntity.findOneBy({ id: Equal(info.id) }); |
| | | const user = await this.userInfoEntity.findOneBy({ unionid: Equal(info.unionid) }); |
| | | const tokenInfo = { |
| | | isRefresh, |
| | | ...info, |
| | |
| | | */ |
| | | async generateSorterToken(info, isRefresh = false) { |
| | | const { expire, refreshExpire, secret } = this.jwtConfig; |
| | | const user = await this.basicdataSorterEntity.findOneBy({ businessId: Equal(info.id) }); |
| | | const user = await this.basicdataSorterEntity.findOneBy({ businessId: Equal(info.unionid) }); |
| | | const tokenInfo = { |
| | | isRefresh, |
| | | ...info, |
| | |
| | | * @param userId |
| | | * @param type 0-小程序 1-公众号 2-App |
| | | */ |
| | | async getOpenid(userId: number, type = 0) { |
| | | async getOpenid(userId: string, type = 0) { |
| | | const user = await this.userInfoEntity.findOneBy({ |
| | | id: Equal(userId), |
| | | unionid: Equal(userId), |
| | | status: 1, |
| | | }); |
| | | if (!user) { |