Order.php 5.48 KB
<?php

namespace Home;

use LibModels\Wap\Home\OrderData;
use Plugin\Helpers;
use Plugin\Cache;
use Configs\CacheConfig;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Order
 * 
 */
class OrderModel
{
    /* 频道选择页取背景图片的位置码 */

    const CODE_PAYMENT = '04cf5abaa7c20178325a07c4a833782c'; //支付订单资源码
    const CODE_STROLL = 'a7989369aa86681c678bc40f171b8f1d'; //随便逛逛url地址资源码

    /**
     * 订单相关数据处理
     */

    static function getOrder($type, $page, $limit, $uid) {
        $result = array();
        if (USE_CACHE) {
            $key = CacheConfig::KEY_ACTION_HOME_ORDER_ORDER;
            // 先尝试获取一级缓存(master), 有数据则直接返回.
            $result = Cache::get($key, 'master');
            if (!empty($result)) {
                return $result;
            }
        }
        //调用接口获得数据
        $data = OrderData::getOrderData($type, $page, $limit, $uid);
        print_r($data);
        //检查数据返回是否正常,正常则处理数据
        if (!empty($data[0])) {
            $result = array();
           foreach($data as $key => $vo){
               $result[$key]['detailUrl'] = $vo[''];
               $result[$key]['orderNum'] = $vo['orderCode'];
               $result[$key]['orderStatus'] = $vo['status'];
               $result[$key]['count'] = count($vo['ordersGoodsList']);
               $result[$key]['sumCost'] = $vo['amount'];
               $result[$key]['sumCost'] = $vo['amount'];
               switch ($vo['status']) {
                   case 1:
                       $result[$key]['sumCost'] = $vo['amount'];

                       break;

                   default:
                       break;
               }
               $result[$key]['sumCost'] = $vo['amount'];
           }
        }

        if (USE_CACHE) {
            // 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
            if (empty($result)) {
                $result = Cache::get($key, 'slave');
            }
            // 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
            else {
                Cache::set($key, $result);
            }
        }
        return $result;
    }

    //格式化订单商品
    static function formatOrderGoods($orderGoods) {
        $arr = array();
        foreach ($orderGoods as $key => $vo) {
            $arr[$key]['thumb'] = Helpers::getImageUrl($vo['goods_image'], 90, 120);
            $arr[$key]['name'] = $vo['product_name'];
            $arr[$key]['color'] = $vo['color_name'];
            $arr[$key]['size'] = $vo['size_name'];
            $arr[$key]['price'] = $vo['goods_price'];
            $arr[$key]['count'] = $vo['buy_number'];
            //gift=>是否赠品,advanceBuy=>是否加价购;
            if ($vo['goods_type'] == 'gift') {
                $arr[$key]['gift'] = true;
            } elseif ($vo['goods_type'] == 'price_gift') {
                $arr[$key]['advanceBuy'] = true;
            }
        }
        return $arr;
    }

    //根据type值设置nav属性
    static function getNavs($type) {
        $nav = array(
            array(
                'name' => '全部',
                'typeId' => '1',
                'url' => '/home/order?type=1'
            ),
            array(
                'name' => '待付款',
                'typeId' => '2',
                'url' => '/home/order?type=2'
            ),
            array(
                'name' => '待发货',
                'typeId' => '3',
                'url' => '/home/order?type=3'
            ),
            array(
                'name' => '待收货',
                'typeId' => '4',
                'url' => '/home/order?type=4'
            )
        );
        foreach ($nav as $key => $vo) {
            switch ($type) {
                case 1:
                    if ($vo['typeId'] == 1) {
                        $nav[$key]['active'] = true;
                    }
                    break;
                case 2:
                    if ($vo['typeId'] == 2) {
                        $nav[$key]['active'] = true;
                    }
                    break;
                case 3:
                    if ($vo['typeId'] == 3) {
                        $nav[$key]['active'] = true;
                    }
                    break;
                case 4:
                    if ($vo['typeId'] == 4) {
                        $nav[$key]['active'] = true;
                    }
                    break;
                default:
                    break;
            }
        }
        return $nav;
    }

    //获得支付链接
    static function payment($gender, $yh_channel) {
        $code = self::CODE_PAYMENT;
        $data = OrderData::paymentData($gender, $yh_channel, $code);
    }

    //查看物流
//    static function Logistics(){
//        OrderData::LogisticsData();
//    }
    //随便逛逛url获取
    static function stroll($gender, $yh_channel) {
        //获取随便逛逛url资源码
        $code = self::CODE_STROLL;
        //调用接口获得数据
        $data = OrderData::strollData($gender, $yh_channel, $code);
        $stroll = 1;
        //检查数据返回是否正常,正常则处理数据
        if ($data['code'] == 200) {
            $strollUrl = $data['data'][0]['data'][0]['url'];
        }
        return $strollUrl;
    }

}