OrderModel.php 1.9 KB
<?php
/**
 * Created by PhpStorm.
 * User: yhbr
 * Date: 2018/9/29
 * Time: 13:42
 */

namespace app\order\model;
use think\Model;
use think\Db;

class OrderModel extends Model
{

    //订单列表的全部、待支付、代发货、待收货、已完成订单
    public function getAllOrders()
    {
        $all = Db::name('zj_order')
            ->field('id,order_num,step,is_evaluate,create_time')
            ->where(['uid' => session('user.id')])
            ->order('create_time DESC')
            ->select()
            ->toArray();
        $unpaid = [];
        $undelivered = [];
        $unreceived = [];
        $completed = [];
        $a = 0;
        $b = 0;
        $c = 0;
        $d = 0;
        foreach ($all as $key => $item) {
            $item['detail'] = Db::name('zj_order_goods')->alias('o')
                ->field('o.*,g.name,g.intro,o.price,g.thumb')
                ->join('zj_goods g', 'g.id=o.gid')
                ->where(['oid' => $item['id']])->select()->toArray();
            foreach ($item['detail'] as $k => $v) {
                $item['detail'][$k]['thumb'] = cmf_get_image_url($v['thumb']);
            }
            $all[$key] = $item;
            if ($item['step'] == 1) {
                $unpaid[$a] = $item;
                $a++;
            } elseif ($item['step'] == 2) {
                $undelivered[$b] = $item;
                $b++;
            } elseif ($item['step'] == 3) {
                $unreceived[$c] = $item;
                $c++;
            } elseif ($item['step'] >= 5 && $item['step'] <= 9) {
                $completed[$d] = $item;
                $d++;
            } else {
                continue;
            }
        }
        $data = [
            'all' => $all,
            'unpaid' => $unpaid,
            'undelivered' => $undelivered,
            'unreceived' => $unreceived,
            'completed' => $completed
        ];
        return $data;
    }

}