OrderDetailModel.class.php 1.8 KB
<?php
/**
 * Created by PhpStorm.
 * User: 29925
 * Date: 2018/3/13
 * Time: 18:26
 */

namespace Common\Model;

use Common\Model\CommonModel;

class OrderDetailModel extends CommonModel {

    // 自动验证
    protected $_validate = array(
        //array(验证字段,验证规则,错误提示,验证条件,附加规则,验证时间)
        array('order_sn', 'require', '订单号不能为空', 1, 'regex', CommonModel::MODEL_BOTH),
        array('goods_id', 'number', '商品ID不能为空', 1, 'regex', CommonModel::MODEL_BOTH),
        array('goods_name', 'require', '商品名称不能为空', 1, 'regex', CommonModel::MODEL_BOTH),
        array('goods_price', 'require', '商品现价不能为空', 1, 'regex', CommonModel::MODEL_BOTH),
        array('price', 'require', '商品原价不能为空', 1, 'regex', CommonModel::MODEL_BOTH),
        array('num', 'require', '购买数量不能为空', 1, 'regex', CommonModel::MODEL_BOTH),
        array('amount', 'require', '商品小计不能为空', 1, 'regex', CommonModel::MODEL_BOTH),
    );

    // 获取订单详细列表
    public function getList($order_sn) {
        $where['is_del'] = 0;
        $where['order_sn'] = $order_sn;
        return $this->where($where)->select();
    }

    // 获取订单商品列表(前台个人中心)
    public function getListByOrder($order_sn) {
        $where['od.order_sn'] = $order_sn;
        return $this->field(array('od.goods_id,od.goods_price,od.price,od.num,od.amount,g.goods_name,g.short_name,g.num as gnum,g.thumb,g.is_hidden,g.is_del'))
            ->alias('od')
            ->join('__GOODS__ as g on od.goods_id = g.id')
            ->where($where)
            ->select();
    }

    // 获取订单详细详情
    public function getInfo($id) {
        $where['is_del'] = 0;
        $where['id'] = $id;
        return $this->where($where)->find();
    }
}