06月08, 2020

thinkjs 初探

thinkjs 初探 链接文本

     /**
   * 订单发货
   * @param {order_id} order_id
   * @param {order_item_id} order_item_id
   * @param {express_id} 快递id
   * @param {express_number} 快递单号
   * @return Boolean![链接文本](http://zb.qinkeji.cn/static/upload/20200608/f23a5554-58d0-4607-ab04-5c7a459beef1.png)
   */
  async sendGoodsAction() {
    try {
      const order_id: any = this.post('order_id');
      const order_info = await this.model('order').where({id: order_id}).find();
      if (think.isEmpty(order_info)) {
        return this.fail(-1, '该订单不存在!');
      }
      /**
       * 状态不是 待发货 和 待收货 的时候
       */
      if (order_info.status != 2 && order_info.status != 3) {
        let msg: string = '';
        switch (order_info.status) {
          case 1:
            msg='该订单未支付!';
                break;
          case 4:
            msg='该订单已完成!';
                break;
          case -2:
            msg='该订单已关闭!';
            break;
        }
        return this.fail(-1, msg)
      }
      const order_item_id: any = this.post('order_item_id');
      const express_id: any = this.post('express_id');
      const express_number: any = this.post('express_number');
      let expressInfo = await this.model('express_list').where({express_id}).find();
      let send_time = think.datetime(  new Date().getTime(), 'YYYY-MM-DD HH:mm:ss');
      if (think.isEmpty(expressInfo)) {
        return this.fail(-1, '该快递不存在');
      }
      const express_name = expressInfo.express_name;
      let _item_status = '已发货';
      let sendGoods = await this.model('order_item').where({order_item_id:['in',order_item_id]}).update({_item_status, send_time,express_id, express_name, express_number, item_status:2});
      if (!sendGoods) {
          return this.fail(-1, '该订单商品不存在!')
      }
       let order_item = await this.model('order_item').where({order_id,item_status:1}).select();
      if (think.isEmpty(order_item)) {
        if(order_info.status == 2 ) {
          let _status = '商家已发货';
          let send_time = think.datetime(  new Date().getTime(), 'YYYY-MM-DD HH:mm:ss');
          await this.model('order').where({id:order_id}).update({_status, status:3,send_time,change_send_time:send_time});
        }
        if(order_info.status == 3 ) {
          let change_send_time = think.datetime(  new Date().getTime(), 'YYYY-MM-DD HH:mm:ss');
          await this.model('order').where({id:order_id}).update({change_send_time});
        }
      }
      return this.success([], '操作成功!');
    }catch (e) {
      return this.fail(-1, e);
    }
  }

本文链接:http://zb.qinkeji.cn/post/thinkjs chu-tan.html

-- EOF --

Comments