|
@@ -1,11 +1,11 @@
|
|
|
import { Achievement } from '../../entity/platform/achievement.entity';
|
|
|
import { Collection } from '../../entity/platform/collection.entity';
|
|
|
import { User } from '../../entity/system/user.entity';
|
|
|
-import { get, pick } from 'lodash';
|
|
|
+import { get } from 'lodash';
|
|
|
import { BaseService } from '../../frame/BaseService';
|
|
|
import { Provide } from '@midwayjs/core';
|
|
|
import { InjectEntityModel } from '@midwayjs/typeorm';
|
|
|
-import { Between, Equal, In, MoreThanOrEqual, Repository } from 'typeorm';
|
|
|
+import { Between, Equal, In, Like, MoreThanOrEqual, Repository } from 'typeorm';
|
|
|
@Provide()
|
|
|
export class AchievementService extends BaseService<Achievement> {
|
|
|
@InjectEntityModel(Achievement)
|
|
@@ -14,64 +14,42 @@ export class AchievementService extends BaseService<Achievement> {
|
|
|
cModel: Repository<Collection>;
|
|
|
@InjectEntityModel(User)
|
|
|
uModel: Repository<User>;
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+ async fetchBrowse(data) {
|
|
|
+ const { num = 0, id } = data;
|
|
|
+ await this.model.update({ id }, { num: num + 1 });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
async list(query) {
|
|
|
- const { skip = 0, limit = 0, is_use, status, field, ...condition } = pick(query, ['skip', 'limit', 'is_use', 'field', 'status']);
|
|
|
- const { one, two, thr, four, five, six } = pick(query, ['one', 'two', 'thr', 'four', 'five', 'six']);
|
|
|
- const whereObject: any = { field };
|
|
|
-
|
|
|
-
|
|
|
- if (one) whereObject.technology = In(one);
|
|
|
- if (two) whereObject.field = In(two);
|
|
|
- if (thr) whereObject.mature = In(thr);
|
|
|
- if (four) whereObject.sell = In(four);
|
|
|
- if (five) {
|
|
|
- if (five === '1') whereObject.money = Equal('面议');
|
|
|
- if (five === '2') whereObject.money = Between('1', '10');
|
|
|
- if (five === '3') whereObject.money = Between('10', '20');
|
|
|
- if (five === '4') whereObject.money = Between('20', '100');
|
|
|
- if (five === '5') whereObject.money = Between('100', '500');
|
|
|
- if (five === '6') whereObject.money = Between('500', '1000');
|
|
|
- if (five === '7') whereObject.money = MoreThanOrEqual('1000');
|
|
|
+ const { skip = 0, limit = 0, is_use, status, name, cityList, fieldList, industryList, matureList, moneyList, sellList, ...condition } = query;
|
|
|
+ const whereObject: any = condition;
|
|
|
+ if (name) whereObject.name = { name: Like(`%${name}%`) };
|
|
|
+ if (industryList) whereObject.industry = In(industryList);
|
|
|
+ if (fieldList) whereObject.field = In(fieldList);
|
|
|
+ if (sellList) whereObject.sell = In(sellList);
|
|
|
+ if (matureList) whereObject.mature = In(matureList);
|
|
|
+ if (cityList) whereObject.area = In(cityList);
|
|
|
+ if (moneyList) {
|
|
|
+ const money = [];
|
|
|
+ for (const val of moneyList) {
|
|
|
+ if (val === '1') money.push(Equal('面议'));
|
|
|
+ if (val === '2') money.push(Between('1', '10'));
|
|
|
+ if (val === '3') money.push(Between('10', '20'));
|
|
|
+ if (val === '4') money.push(Between('20', '100'));
|
|
|
+ if (val === '5') money.push(Between('100', '500'));
|
|
|
+ if (val === '6') money.push(Between('500', '1000'));
|
|
|
+ if (val === '7') money.push(MoreThanOrEqual('1000'));
|
|
|
+ }
|
|
|
+ whereObject.money = In(money);
|
|
|
}
|
|
|
- if (six) whereObject.area = In(six);
|
|
|
const builder = this.model.createQueryBuilder().setFindOptions({ where: whereObject, skip, take: limit });
|
|
|
const data = await builder.getMany();
|
|
|
const total = await builder.getCount();
|
|
|
- for (const val of data) {
|
|
|
- if (get(val, 'user')) {
|
|
|
-
|
|
|
- const userData = await this.uModel.findOne({ where: { id: Equal(val.user) } });
|
|
|
- if (userData) Object.assign(val, { userName: userData.nick_name });
|
|
|
- }
|
|
|
- }
|
|
|
return { data, total };
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
+
|
|
|
|
|
|
async detail(id) {
|
|
|
const user = this.ctx.user;
|
|
@@ -89,6 +67,7 @@ export class AchievementService extends BaseService<Achievement> {
|
|
|
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 };
|
|
|
}
|
|
|
}
|