const system = require("../../../system");
const ServiceBase = require("../../sve.base")
const settings = require("../../../../config/settings")
const moment = require("moment");

class IborderdkService extends ServiceBase {
  constructor() {
    super("order", ServiceBase.getDaoName(IborderdkService));

    this.baseDao = system.getObject("db.order.iborderbaseDao");
  }

  async addOrder(params) {
  }

  /**
   * 创建订单
   * @param {*} params
   */
  async createOrder(params, t) {
    try {
      if (!params.merchantId) {
        return system.getResult(null, `参数错误 商户ID不能为空`);
      }
      if (!params.businessmentId) {
        return system.getResult(null, `参数错误 个体户ID不能为空`);
      }
      if (!params.orderpayId) {
        return system.getResult(null, `参数错误 支付ID不能为空`);
      }
      if (!Number(params.price) < 0) {
        return system.getResult(null, `参数错误 订单金额格式错误`);
      }
      this.trimObject(params);
      let _ibOrderDk = await this.dao.create(params, t);
      return system.getResult(_ibOrderDk);
    } catch (error) {
      return system.getResult(null, `系统错误 错误信息 ${error}`);
    }
  }

  /**
   * 更新数据
   * @param {*} params 
   * @param {*} t 
   */
  async updateOrder(params,t){
    try {
      if(!params.id){
        return system.getResult(null, `参数错误 ID 不能为空`);
      }
      this.trimObject(params);
      return await this.dao.update(params,t);
    } catch (error) {
      return system.getResult(null,`系统错误 错误信息 ${error}`);
    }
  }
}

module.exports = IborderdkService;
