<?php
/** 退货退款
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author zhaoh <zhaoh@qq.com>
 */

namespace Shop\Model;
use Think\Model;
class ReturnGoodsModel extends Model{
	/**
	 * 退货列表
	 * @param $postdata mixed
	 * @return  mixed  
	*/
    public function return_list($page_num,$if_type=0,$param=''){
		$shops_info=session('shops_info');
		$map['shop_id']=$shops_info['shop_id'];
		if(!$if_type)$map['type']=0;//1019OrderController/back修改
		if(isset($param['shop_status']))$map['shop_status']=$param['shop_status'];
		if($param['order_sn']){
			$where['order_sn']=array('like','%'.$param['order_sn'].'%');
			$ids=M('OrderInfo')->where($where)->getField('id',true);
			if(!$ids){$ids=0;}
			$map['order_id']=array('in',$ids);
		}
		$page_num=$page_num?$page_num:10;
		$list=page_list('ReturnGoods',$map,'id desc',true,$page_num,'',1);
		// print_r($shops_info);exit;
		if($list['list']){
			foreach($list['list'] as $k=>$v){
				$goods_info=unserialize($v['goods_info']);
				if (count($goods_info) == count($goods_info, 1)) {
    				// 一维数组
    				$goods_info=[];
    				$goods_info[]=unserialize($v['goods_info']);
				} 
			   foreach($goods_info as $ke=>$vo){
					$goods_info[$ke]['img']=idtoname($vo['goods_id'],'Goods','img');
					$goods_info[$ke]['name']=idtoname($vo['goods_id'],'Goods','goods_name');
				}
				$list['list'][$k]['goods_info']=$goods_info;
				
			}
		}
		return $list;
    }
	/**
	 * 退款列表
	 * @param $postdata mixed
	 * @return  mixed  
	*/
    public function refund_list($page_num,$param=''){
		$shops_info=session('shops_info');
		$map['shop_id']=$shops_info['shop_id'];
		$map['type']=0;
		if(isset($param['status']))$map['status']=$param['status'];
		if($param['order_sn']){
			$where['order_sn']=array('like','%'.$param['order_sn'].'%');
			$ids=M('OrderInfo')->where($where)->getField('id',true);
			if(!$ids){$ids=0;}
			$map['order_id']=array('in',$ids);
		}
		$page_num=$page_num?$page_num:10;
		$list=page_list('refund_order',$map,'id desc',true,$page_num,'',1);
		return $list;
    }
	
}

?>