|
@@ -1,19 +1,25 @@
|
|
|
import { Achievement } from '../../entity/platform/achievement.entity';
|
|
|
-import { Collection } from '../../entity/platform/collection.entity';
|
|
|
-import { User } from '../../entity/system/user.entity';
|
|
|
-import { get, isArray } from 'lodash';
|
|
|
+import { isArray } from 'lodash';
|
|
|
import { Provide } from '@midwayjs/core';
|
|
|
import { InjectEntityModel } from '@midwayjs/typeorm';
|
|
|
-import { Between, Equal, In, Like, MoreThanOrEqual, Repository } from 'typeorm';
|
|
|
+import { Between, Equal, In, MoreThanOrEqual, Repository } from 'typeorm';
|
|
|
import { BaseServiceV2 } from '../../frame/BaseServiceV2';
|
|
|
@Provide()
|
|
|
export class AchievementService extends BaseServiceV2 {
|
|
|
@InjectEntityModel(Achievement)
|
|
|
model: Repository<Achievement>;
|
|
|
- @InjectEntityModel(Collection)
|
|
|
- cModel: Repository<Collection>;
|
|
|
- @InjectEntityModel(User)
|
|
|
- uModel: Repository<User>;
|
|
|
+
|
|
|
+ getQueryColumnsOpera() {
|
|
|
+ const obj = {
|
|
|
+ name: this.Opera.Like,
|
|
|
+ industry: this.Opera.In,
|
|
|
+ field: this.Opera.In,
|
|
|
+ sell: this.Opera.In,
|
|
|
+ mature: this.Opera.In,
|
|
|
+ area: this.Opera.Json,
|
|
|
+ };
|
|
|
+ return obj;
|
|
|
+ }
|
|
|
|
|
|
// 加浏览量
|
|
|
async fetchBrowse(data) {
|
|
@@ -21,31 +27,9 @@ export class AchievementService extends BaseServiceV2 {
|
|
|
await this.model.update({ id }, { num: num + 1 });
|
|
|
}
|
|
|
|
|
|
- // 多条件查询列表
|
|
|
- async list(query) {
|
|
|
- const { skip = 0, limit = 0, is_use, status, name, area, field, industry, mature, money, sell, ...condition } = query;
|
|
|
- const whereObject: any = condition;
|
|
|
- if (name) whereObject.name = { name: Like(`%${name}%`) };
|
|
|
- if (industry) {
|
|
|
- if (!isArray(industry)) whereObject.industry = Equal(industry);
|
|
|
- else whereObject.industry = In(industry);
|
|
|
- }
|
|
|
- if (field) {
|
|
|
- if (!isArray(field)) whereObject.field = Equal(field);
|
|
|
- else whereObject.field = In(field);
|
|
|
- }
|
|
|
- if (sell) {
|
|
|
- if (!isArray(sell)) whereObject.sell = Equal(sell);
|
|
|
- else whereObject.sell = In(sell);
|
|
|
- }
|
|
|
- if (mature) {
|
|
|
- if (!isArray(mature)) whereObject.mature = Equal(mature);
|
|
|
- else whereObject.mature = In(mature);
|
|
|
- }
|
|
|
- if (area) {
|
|
|
- if (!isArray(area)) whereObject.area = Equal(area);
|
|
|
- else whereObject.area = In(area);
|
|
|
- }
|
|
|
+ // 处理金钱
|
|
|
+ async money(filter) {
|
|
|
+ const { money, ...info } = filter;
|
|
|
if (money) {
|
|
|
if (!isArray(money)) {
|
|
|
let money_title;
|
|
@@ -56,7 +40,7 @@ export class AchievementService extends BaseServiceV2 {
|
|
|
if (money === '5') money_title = Between('100', '500');
|
|
|
if (money === '6') money_title = Between('500', '1000');
|
|
|
if (money === '7') money_title = MoreThanOrEqual('1000');
|
|
|
- whereObject.money = money_title;
|
|
|
+ info.money = money_title;
|
|
|
} else {
|
|
|
const moneylist = [];
|
|
|
for (const val of money) {
|
|
@@ -68,33 +52,9 @@ export class AchievementService extends BaseServiceV2 {
|
|
|
if (val === '6') moneylist.push(Between('500', '1000'));
|
|
|
if (val === '7') moneylist.push(MoreThanOrEqual('1000'));
|
|
|
}
|
|
|
- whereObject.money = In(moneylist);
|
|
|
+ info.money = In(moneylist);
|
|
|
}
|
|
|
}
|
|
|
- const builder = this.model.createQueryBuilder().setFindOptions({ where: whereObject, skip, take: limit });
|
|
|
- const data = await builder.getMany();
|
|
|
- const total = await builder.getCount();
|
|
|
- return { data, total };
|
|
|
- }
|
|
|
-
|
|
|
- // 成果详情
|
|
|
- async detail(id) {
|
|
|
- const user = this.ctx.user;
|
|
|
- const data = { userInfo: {}, is_collection: false };
|
|
|
- const arr = await this.model.findOne({ where: { id: Equal(id) } });
|
|
|
- if (arr && get(arr, 'user')) {
|
|
|
- // 查询成果发布者
|
|
|
- // const userData = await this.uModel.findById(arr.user).lean();
|
|
|
- const userData = await this.uModel.findOne({ where: { id: Equal(arr.user) } });
|
|
|
- if (userData) data.userInfo = { name: userData.nick_name || '', phone: userData.phone || '' };
|
|
|
- }
|
|
|
- if (user && get(user, 'id')) {
|
|
|
- // 查询是否收藏该成果
|
|
|
- // const collection = await this.cModel.findOne({ user: user._id, source: arr.id }).lean();
|
|
|
- const collection = await this.cModel.findOne({ where: { user: Equal(user.id), source: Equal(arr.id) } });
|
|
|
- if (collection) data.is_collection = true;
|
|
|
- }
|
|
|
- await this.fetchBrowse(arr);
|
|
|
- return { ...arr, ...data };
|
|
|
+ return info;
|
|
|
}
|
|
|
}
|