zs 1 year ago
parent
commit
bd35dff633

+ 8 - 0
src/controller/ShopSetting.controller.ts

@@ -21,16 +21,22 @@ import {
 } from '../interface/ShopSetting.interface';
 import { ApiResponse, ApiTags, ApiQuery } from '@midwayjs/swagger';
 import { Validate } from '@midwayjs/validate';
+import { UserUtilService } from '../service/util/user.util';
 @ApiTags(['采购审批设置'])
 @Controller('/ShopSetting')
 export class ShopSettingController extends BaseController {
   @Inject()
   service: ShopSettingService;
 
+  @Inject()
+  userUtil: UserUtilService;
+
   @Post('/')
   @Validate()
   @ApiResponse({ type: CVO_ShopSetting })
   async create(@Body() data: CDTO_ShopSetting) {
+    await this.userUtil.checkOffice(data);
+    // 检查街道/社区
     const dbData = await this.service.create(data);
     const result = new CVO_ShopSetting(dbData);
     return result;
@@ -65,6 +71,8 @@ export class ShopSettingController extends BaseController {
   @Validate()
   @ApiResponse({ type: UVAO_ShopSetting })
   async update(@Param('id') id: string, @Body() body: UDTO_ShopSetting) {
+    // 检查街道/社区
+    await this.userUtil.checkUpdateOffice(id, body);
     const result = await this.service.updateOne(id, body);
     return result;
   }

+ 2 - 0
src/entity/Order.entity.ts

@@ -15,6 +15,8 @@ export class Order extends BaseModel {
   total_money: Decimal128;
   @prop({ required: false, index: true, zh: '下单时间' })
   buy_time: string;
+  @prop({ required: false, index: false, zh: '审核记录' })
+  record: Array<any>;
   @prop({
     required: false,
     index: true,

+ 2 - 0
src/entity/OrderDetail.entity.ts

@@ -18,6 +18,8 @@ export class OrderDetail extends BaseModel {
   address: string;
   @prop({ required: false, index: true, zh: '下单时间' })
   buy_time: string;
+  @prop({ required: false, index: false, zh: '审核记录' })
+  record: Array<any>;
   @prop({
     required: false,
     index: true,

+ 2 - 4
src/entity/ShopSetting.entity.ts

@@ -4,10 +4,8 @@ import { BaseModel } from 'free-midway-component';
   schemaOptions: { collection: 'ShopSetting' },
 })
 export class ShopSetting extends BaseModel {
-  @prop({ required: false, index: true, zh: '街道' })
-  street: string;
-  @prop({ required: false, index: true, zh: '社区' })
-  community: string;
+  @prop({ required: true, index: false, zh: '街道/社区' })
+  office: string;
   @prop({ required: false, index: false, zh: '领导' })
   leader: Array<any>;
   @prop({ required: false, index: false, zh: '会计' })

+ 5 - 0
src/interface/Order.interface.ts

@@ -24,6 +24,8 @@ export class FVO_Order {
   'total_money': number = undefined;
   @ApiProperty({ description: '下单时间' })
   'buy_time': string = undefined;
+  @ApiProperty({ description: '审核记录' })
+  'record': Array<any> = undefined;
   @ApiProperty({ description: '订单状态' })
   'status': string = undefined;
 }
@@ -66,6 +68,9 @@ export class CDTO_Order {
   @ApiProperty({ description: '下单时间' })
   @Rule(RuleType['string']().empty(''))
   'buy_time': string = undefined;
+  @ApiProperty({ description: '审核记录' })
+  @Rule(RuleType['array']().empty(''))
+  'record': Array<any> = undefined;
   @ApiProperty({ description: '订单状态' })
   @Rule(RuleType['string']().empty(''))
   'status': string = undefined;

+ 5 - 0
src/interface/OrderDetail.interface.ts

@@ -28,6 +28,8 @@ export class FVO_OrderDetail {
   'address': string = undefined;
   @ApiProperty({ description: '下单时间' })
   'buy_time': string = undefined;
+  @ApiProperty({ description: '审核记录' })
+  'record': Array<any> = undefined;
   @ApiProperty({ description: '状态' })
   'status': string = undefined;
 }
@@ -92,6 +94,9 @@ export class CDTO_OrderDetail {
   @ApiProperty({ description: '下单时间' })
   @Rule(RuleType['string']().empty(''))
   'buy_time': string = undefined;
+  @ApiProperty({ description: '审核记录' })
+  @Rule(RuleType['array']().empty(''))
+  'record': Array<any> = undefined;
   @ApiProperty({ description: '状态' })
   @Rule(RuleType['string']().empty(''))
   'status': string = undefined;

+ 27 - 18
src/interface/ShopSetting.interface.ts

@@ -1,6 +1,10 @@
 import { Rule, RuleType } from '@midwayjs/validate';
 import { ApiProperty } from '@midwayjs/swagger';
-import { SearchBase } from 'free-midway-component';
+import {
+  FrameworkErrorEnum,
+  SearchBase,
+  ServiceError,
+} from 'free-midway-component';
 import get = require('lodash/get');
 const dealVO = (cla, data) => {
   for (const key in cla) {
@@ -14,10 +18,8 @@ export class FVO_ShopSetting {
   }
   @ApiProperty({ description: '数据id' })
   _id: string = undefined;
-  @ApiProperty({ description: '街道' })
-  'street': string = undefined;
-  @ApiProperty({ description: '社区' })
-  'community': string = undefined;
+  @ApiProperty({ description: '街道/社区' })
+  'office': string = undefined;
   @ApiProperty({ description: '领导' })
   'leader': Array<any> = undefined;
   @ApiProperty({ description: '会计' })
@@ -29,14 +31,12 @@ export class FVO_ShopSetting {
 export class QDTO_ShopSetting extends SearchBase {
   constructor() {
     const like_prop = [];
-    const props = ['street', 'community', 'is_use'];
+    const props = ['office', 'is_use'];
     const mapping = [];
     super({ like_prop, props, mapping });
   }
-  @ApiProperty({ description: '街道' })
-  'street': string = undefined;
-  @ApiProperty({ description: '社区' })
-  'community': string = undefined;
+  @ApiProperty({ description: '街道/社区' })
+  'office': string = undefined;
   @ApiProperty({ description: '是否使用' })
   'is_use': string = undefined;
 }
@@ -49,17 +49,26 @@ export class QVO_ShopSetting extends FVO_ShopSetting {
 }
 
 export class CDTO_ShopSetting {
-  @ApiProperty({ description: '街道' })
-  @Rule(RuleType['string']().empty(''))
-  'street': string = undefined;
-  @ApiProperty({ description: '社区' })
-  @Rule(RuleType['string']().empty(''))
-  'community': string = undefined;
+  @ApiProperty({ description: '街道/社区' })
+  @Rule(
+    RuleType['string']()
+      .required()
+      .error(new ServiceError('缺少街道/社区', FrameworkErrorEnum.NEED_BODY))
+  )
+  'office': string = undefined;
   @ApiProperty({ description: '领导' })
-  @Rule(RuleType['array']().empty(''))
+  @Rule(
+    RuleType['array']()
+      .required()
+      .error(new ServiceError('缺少领导', FrameworkErrorEnum.NEED_BODY))
+  )
   'leader': Array<any> = undefined;
   @ApiProperty({ description: '会计' })
-  @Rule(RuleType['array']().empty(''))
+  @Rule(
+    RuleType['array']()
+      .required()
+      .error(new ServiceError('缺少会计', FrameworkErrorEnum.NEED_BODY))
+  )
   'accounting': Array<any> = undefined;
   @ApiProperty({ description: '是否使用' })
   @Rule(RuleType['string']().empty(''))

+ 4 - 0
src/interface/util/user.util.interface.ts

@@ -7,3 +7,7 @@ export interface checkPhoneAndPid {
   name?: string;
   openid?: string;
 }
+
+export interface checkOffice {
+  office?: string;
+}

+ 8 - 7
src/service/Cart.service.ts

@@ -134,16 +134,17 @@ export class CartService extends BaseService<modelType> {
       obj.goods = goods;
       const result = await this.userModel.findById(list[0].user).lean();
       if (result) {
+        let res;
         obj.user = result._id;
         if (result.community) {
-          const res = await this.offModel.findById(result.community).lean();
-          obj.address = res.address;
+          order = await this.shopModel.findOne({ office: result.community });
+          res = await this.offModel.findById(result.community).lean();
         } else if (result.street) {
-          const res = await this.offModel.findById(result.street).lean();
-          obj.address = res.address;
-        } else {
-          assert(result.street, '缺少街道信息或社区信息!');
-        }
+          order = await this.shopModel.findOne({ office: result.street });
+          res = await this.offModel.findById(result.street).lean();
+        } else assert(result.street, '缺少街道信息或社区信息!');
+        if (res) obj.address = res.address;
+        if (!order) obj.status = '2';
         obj.total_money = data.totalMoney;
         obj.buy_time = moment().format('YYYY-MM-DD HH:mm:ss');
         order = await this.orderModel.create(obj);

+ 41 - 0
src/service/util/user.util.ts

@@ -6,13 +6,54 @@ import { User } from '../../entity/User.entity';
 import {
   CheckUpdateCardAndPid,
   checkPhoneAndPid,
+  checkOffice,
 } from '../../interface/util/user.util.interface';
+import { ShopSetting } from '../../entity/ShopSetting.entity';
 
 @Provide()
 export class UserUtilService {
   @InjectEntityModel(User)
   UserModel: ReturnModelType<typeof User>;
 
+  @InjectEntityModel(ShopSetting)
+  shopModel: ReturnModelType<typeof ShopSetting>;
+  /**
+   * 检查创建时,是否创建改街道/社区设置
+   * @param data 参数
+   */
+  async checkOffice(data: checkOffice) {
+    if (data.office) {
+      // 检查街道/社区
+      const useran = await this.shopModel.count({ office: data.office });
+      if (useran > 0) {
+        throw new ServiceError(
+          '已有该街道/社区 采购设置!',
+          FrameworkErrorEnum.BAD_BODY
+        );
+      }
+    }
+  }
+
+  /**
+   * 检查修改时,是否创建改街道/社区设置
+   * @param data 参数
+   */
+  async checkUpdateOffice(id, data: checkOffice) {
+    const { office } = data;
+    if (office) {
+      // 检查街道/社区
+      const useran = await this.shopModel.count({
+        _id: { $ne: id },
+        office,
+      });
+      if (useran > 0) {
+        throw new ServiceError(
+          '已有该街道/社区 采购设置!',
+          FrameworkErrorEnum.BAD_BODY
+        );
+      }
+    }
+  }
   /**
    * 检查创建时,检查手机号和姓名
    * @param data 参数