lrf402788946 4 years ago
parent
commit
028e066a1e
5 changed files with 48 additions and 12 deletions
  1. 28 0
      app/controller/order/.order.js
  2. 1 1
      app/model/client.js
  3. 1 1
      app/model/driver.js
  4. 2 0
      app/router/order.js
  5. 16 10
      app/service/order/order.js

+ 28 - 0
app/controller/order/.order.js

@@ -110,4 +110,32 @@ module.exports = {
       count: true,
     },
   },
+  toTransport: {
+    parameters: {
+      query: {
+        order_no: "%order_no%",
+        owner: "owner",
+        principal: "principal",
+        client: "client",
+        treaty: "treaty",
+        item: "item",
+        route: "route",
+        "rq_send_time@start": "rq_send_time@start",
+        "rq_send_time@end": "rq_send_time@end",
+        "rq_arrive_time@start": "rq_arrive_time@start",
+        is_js: "is_js",
+        status: "status",
+      },
+      options: {
+        "split.status": 0, // 只显含有未发货物的订单
+      },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
 };

+ 1 - 1
app/model/client.js

@@ -20,7 +20,7 @@ const Client = {
     type: String,
     required: true,
     maxLength: 200,
-    field: { label: '联系电话', filter: true, required: true },
+    field: { label: '联系电话', filter: true, required: true, options: { maxLength: 11 } },
   },
   address: {
     type: String,

+ 1 - 1
app/model/driver.js

@@ -5,7 +5,7 @@ const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
 // 司机表
 const Driverchema = {
   name: { type: String, required: true, maxLength: 200, field: { required: true, label: '姓名', filter: true } }, // 姓名
-  tel: { type: String, required: true, maxLength: 200, field: { required: true, label: '联系电话', filter: true } }, // 电话/固定电话
+  tel: { type: String, required: true, maxLength: 200, field: { required: true, label: '联系电话', filter: true, options: { maxLength: 11 } } }, // 电话/固定电话
   id_card: { type: String, required: true, maxLength: 200, field: { required: true, label: '身份证', filter: true, options: { maxLength: 18, minLength: 18 } } }, // 身份证
   drive_card: { type: String, required: true, maxLength: 200, field: { required: true, label: '驾驶证号' } }, // 驾驶证号
   fhc_time: { type: String, required: false, maxLength: 200, field: { label: '初次领证时间', type: 'date', notable: true } }, // 初次领证时间=年月日

+ 2 - 0
app/router/order.js

@@ -20,6 +20,8 @@ module.exports = app => {
   router.post('order', `${prefix}/order/split`, controller[index].order.splitGoods);
   // 支出
   router.post('order', `${prefix}/order/outBill`, controller[index].order.outBill);
+  // 装车查询
+  router.get('order', `${prefix}/order/transport`, controller[index].order.toTransport);
   // 订单
   router.resources(`${prefix}/order`, controller[index].order); // index、create、show、destroy
   router.post('order', `${prefix}/order/update/:id`, controller[index].order.update);

+ 16 - 10
app/service/order/order.js

@@ -12,6 +12,7 @@ class OrderService extends CrudService {
     this.model = this.ctx.model.Order;
     this.util = this.ctx.service.util.util;
   }
+
   /**
    * 新添订单
    * @param {Object} data 订单数据
@@ -184,7 +185,6 @@ class OrderService extends CrudService {
       // 修改该货物的状态
       const good = order.split.id(split_id);
       good.status = '1';
-      console.log(good);
       order.goods_status = await this.checkGoodsStatus(order.split);
       await this.model.update({ _id: order._id }, order);
       // 更新记录
@@ -426,7 +426,6 @@ class OrderService extends CrudService {
    */
   async clientExport(query) {
     const { ids } = query;
-    console.log(ids);
     let list = await this.model
       .find({ _id: ids.map(i => ObjectId(i)) })
       .populate([
@@ -482,7 +481,7 @@ class OrderService extends CrudService {
       const res = i.replace(reg, '');
       return res;
     });
-    let lastData = arr.map(i => ({ content: i }));// this.toResetExcelData(pkeys, arr);
+    let lastData = arr.map(i => ({ content: i })); // this.toResetExcelData(pkeys, arr);
     lastData.push({ content: header });
     const alignment = { vertical: 'middle', horizontal: 'center' };
     lastData = lastData.map(i => ({ ...i, alignment }));
@@ -625,7 +624,6 @@ class OrderService extends CrudService {
     for (const oin of inList) {
       const { key, item, value } = oin;
       const r = in_bill.find(f => f.item === item);
-      // console.log(key, item, value, r);
       if (r) {
         obj[`${key}${os}`] = _.get(r, value);
       }
@@ -718,8 +716,15 @@ class OrderService extends CrudService {
     assert(client, '缺少客户信息');
     assert(owner, '缺少创建人信息');
     const params = { ids, client, owner };
-    const bill = await this.ctx.model.Bill.create({ params, client, owner, ...info });
-    if (!bill) { throw new BusinessError(ErrorCode.DATABASE_FAULT, '结算单创建失败'); }
+    const bill = await this.ctx.model.Bill.create({
+      params,
+      client,
+      owner,
+      ...info,
+    });
+    if (!bill) {
+      throw new BusinessError(ErrorCode.DATABASE_FAULT, '结算单创建失败');
+    }
     const res = await this.model.updateMany(
       { _id: ids.map(i => ObjectId(i)) },
       { is_js: true }
@@ -733,13 +738,14 @@ class OrderService extends CrudService {
     }
   }
 
-
   /**
    * 支出结算
    * @param {Object} {ids,client,car_no} ids:订单id列表,client:客户id,car_no:车牌号(第三方)/车辆id(自运)
    */
   async outJs({ ids, client, car_no }) {
-    const orderList = await this.model.find({ _id: ids.map(i => ObjectId(i)) });
+    const orderList = await this.model.find({
+      _id: ids.map(i => ObjectId(i)),
+    });
     for (const order of orderList) {
       const { out_bill, _id } = order;
       let target;
@@ -747,7 +753,7 @@ class OrderService extends CrudService {
       if (client) {
         res = out_bill.filter(f => f.client === client);
         const cInfo = await this.ctx.model.Client.findById(client);
-        if (!cInfo) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到指定供应商');
+        if (!cInfo) { throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到指定供应商'); }
         target = _.get(cInfo, 'name');
       } else {
         res = out_bill.filter(f => f.car_no === car_no);
@@ -756,7 +762,7 @@ class OrderService extends CrudService {
           target = car_no;
         } else {
           const cInfo = await this.ctx.model.Car.findById(car_no);
-          if (!cInfo) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到指定车辆');
+          if (!cInfo) { throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到指定车辆'); }
           target = cInfo.car_no;
         }
       }