CmsWing源码分析(12) 客户订单(一)

2021SC@SDUSC

今天分析的是订单功能

文件位于

网页的初始化几乎没有

indexAction() {
    return this.display();
  }

 非常的简洁

订单列表

首先需要接收状态参数

同时初始化一个map数组

当成功接收到一个状态参数后,将status的内容赋值给map数组

async listAction() {
    const status = this.get('status');
    const map = {};
    if (!think.isEmpty(status)) {
      map.status = status;
      this.assign('status', status);
    }

同理,再接收一个参数q,

q中应该包含订单的编号、用户id、收件人、手机号等信息集合

设置一下map的类型和存在属性

const q = this.get('q');
   if (!think.isEmpty(q)) {
     map['order_no|user_id|accept_name|mobile'] = ['like', q];
   }
    map.is_del = 0;
    map.type = 0;

然后分类展示每个订单的各项内容,新增订单的支付状态

将此页面命名为“订单管理”

const data = await this.model('order').where(map).page(this.get('page') || 1, 20).order('create_time DESC').countSelect();
    const html = this.pagination(data);
    this.assign('pagerData', html); // 分页展示使用
    // console.log(data.data);
    this.active = 'admin/order/list';
    for (const val of data.data) {
      switch (val.payment) {
        case 100:
          val.channel = '预付款支付';
          break;
        case 1001:
          val.channel = '货到付款';
          break;
        case 1002:
          val.channel = '银行汇款';
          break;
        default:
          val.channel = await this.model('pingxx').where({id: val.payment}).getField('title', true);
      }
    }
    this.assign('list', data.data);
    this.meta_title = '订单管理';
    return this.display();
  }

审核订单

让客户端发送一个订单

服务器端等待并接受这个订单的id,

再发送订单的模型,并实例化里面的各个参数

然后管理员可以开始对看到的数据作出反应:

审核成功或是失败

async auditAction() {
    if (this.isPost) {
      const id = this.post('id');
      const admin_remark = this.post('admin_remark');
      const audit = await this.model('order').where({id: id}).update({status: 3, admin_remark: admin_remark});
      if (audit) {
        return this.success({name: '审核成功!', url: this.referer()});
      } else {
        return this.fail('审核失败!');
      }
    } else {
      const id = this.get('id');
      this.assign('id', id);
      this.meta_title = '审核订单';
      return this.display();
    }
  }

没发送成功就不用凑热闹了,会直接变成审核订单页面的形状

删除、作废订单

此处的逻辑是,订单需要先作废才能被删除

那么先看复杂一点的作废订单

循规蹈矩地向服务器发送id、订单内容属性

当这个订单地void属性为真时,说明这个订单能够被删除

此时,在数据库中删除这个项,释放库存

否则,提示操作失败

async voidAction() {
    if (this.isPost) {
      const id = this.post('id');
      const admin_remark = this.post('admin_remark');
      const voids = true;
      if (voids) {
        await this.model('cmswing/order').stock(id, false);
        return this.success({name: '操作成功!', url: this.referer()});
      } else {
        return this.fail('操作失败!');
      }
    } else {
      const id = this.get('id');
      this.assign('id', id);
      this.meta_title = '审核订单';
      return this.display();
    }
  }

再来看删除订单

非常简洁,

就只是在订单类中执行删除方法

 async delAction() {
    const id = this.get('id');
    const res = await this.model('order').where({id: id, status: 6}).delete();
    if (res) {
      return this.success({name: '删除成功!'});
    } else {
      return this.fail('删除失败!');
    }
  }

完成、备注订单

对订单类地实例对象执行更新方法,

将完成状态更新为“已完成”

其他方面逻辑都一样,没什么好说的

async finishAction() {
    if (this.isPost) {
      const id = this.post('id');
      const admin_remark = this.post('admin_remark');
      const finish = await this.model('order').where({id: id}).update({status: 4, admin_remark: admin_remark});
      if (finish) {
        return this.success({name: '操作成功!', url: this.referer()});
      } else {
        return this.fail('操作失败!');
      }
    } else {
      const id = this.get('id');
      this.assign('id', id);
      this.meta_title = '完成订单';
      return this.display();
    }
  }

备注订单也是执行更新方法,此处甚至不放代码了

剩下的下一周讲

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值