|
@@ -0,0 +1,26 @@
|
|
|
+import { Provide } from "@midwayjs/core";
|
|
|
+import { InjectEntityModel } from "@midwayjs/typeorm";
|
|
|
+import { Repository } from "typeorm";
|
|
|
+import { PageView } from "../../entityV2/pageView.entity";
|
|
|
+import { get } from "lodash";
|
|
|
+
|
|
|
+@Provide()
|
|
|
+export class PageViewService {
|
|
|
+ @InjectEntityModel(PageView, 'v2')
|
|
|
+ model: Repository<PageView>;
|
|
|
+ /**查询浏览量,直接把当前的添加上 */
|
|
|
+ async fetch(content_id) {
|
|
|
+ const data = await this.model.createQueryBuilder().where(`content_id=:content_id`, { content_id }).getOne()
|
|
|
+ let num = 1;
|
|
|
+ if (!data) {
|
|
|
+ const body = { content_id }
|
|
|
+ await this.model.save(body);
|
|
|
+ } else {
|
|
|
+ const id = get(data, 'id')
|
|
|
+ num = get(data, 'num', 1);
|
|
|
+ num = num + 1
|
|
|
+ await this.model.update({ id }, { num })
|
|
|
+ }
|
|
|
+ return num
|
|
|
+ }
|
|
|
+}
|