<?php
/**
 * 配送方式
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author xiaogg <xiaogg@sina.cn>
 */
 
namespace Admin\Controller;
class ShippingController extends BaseController{
	public function _before_edit(){
		$id=I('id');//print_r($id);
		$this->assign('id',$id);
	}
	public function shipping_template(){
		$shipping_id = !empty($_GET['id']) ? intval($_GET['id']) : 0;
		$where['id']=$shipping_id;
		$row = M('Shipping')->where($where)->find();
		if ($row){
			$row['shipping_print'] = !empty($row['shipping_print']) ? $row['shipping_print'] : '';
			$row['print_model'] = empty($row['print_model']) ? 1 : $row['print_model']; //兼容以前版本
            $row['config_lable'] =$row['config_lable']!='true' && is_string($row['config_lable'])?$row['config_lable']:'';
			$this->assign('shipping', $row);
		}
		$shipping_template_info = '订单模板变量说明:<br/>{$shop_name}表示店铺名称<br/>{$province}表示店铺所属省份<br/>{$city}表示店铺所属城市<br/>{$shop_address}表示店铺地址<br/>{$service_phone}表示店铺联系电话<br/>{$order.order_amount}表示订单金额<br/>{$order.region}表示收件人地区<br/>{$order.tel}表示收件人电话<br/>{$order.mobile}表示收件人手机<br/>{$order.zipcode}表示收件人邮编<br/>{$order.address}表示收件人详细地址<br/>{$order.consignee}表示收件人名称<br/>{$order.order_sn}表示订单号';
		$this->assign('shipping_template_info', $shipping_template_info);
		$this->assign('shipping_id', $shipping_id);
		$this->assign('print_model', $row['print_model']);
		$this->display();
	}
	public function print_index(){
		$shipping_id = !empty($_GET['shipping']) ? intval($_GET['shipping']) : 0;

		/* 检查该插件是否已经安装 取值 */
		$where['id']=$shipping_id;
		$row = M('Shipping')->where($where)->find();
		if ($row){
			$row['shipping_print'] = !empty($row['shipping_print']) ? $row['shipping_print'] : '';
            $row['config_lable'] =$row['config_lable']!='true' && is_string($row['config_lable'])?$row['config_lable']:'';
		}
	//	$con[1]['code']='shop_country';$con[1]['name']='店铺-国家';
		$con[2]['code']='shop_province';$con[2]['name'] = '店铺-省份';
		$con[3]['code']='shop_city';$con[3]['name'] = '店铺-城市';
		$con[4]['code']='shop_name';$con[4]['name'] = '店铺-名称';
		$con[5]['code']='shop_district';$con[5]['name'] = '店铺-区/县';
		$con[6]['code']='shop_tel';$con[6]['name'] = '店铺-联系电话';
		$con[7]['code']='shop_address';$con[7]['name'] = '店铺-地址';
	//	$con[8]['code']='customer_country';$con[8]['name'] = '收件人-国家';
		$con[9]['code']='customer_province';$con[9]['name'] = '收件人-省份';
		$con[10]['code']='customer_city';$con[10]['name'] = '收件人-城市';
		$con[11]['code']='customer_district';$con[11]['name'] = '收件人-区/县';
		$con[12]['code']='customer_tel';$con[12]['name'] = '收件人-电话';
		$con[13]['code']='customer_mobel';$con[13]['name'] = '收件人-手机';
		$con[14]['code']='customer_post';$con[14]['name'] = '收件人-邮编';
		$con[15]['code']='customer_address';$con[15]['name'] = '收件人-详细地址';
		$con[16]['code']='customer_name';$con[16]['name'] = '收件人-姓名';
		$con[17]['code']='year';$con[17]['name'] = '年-当日日期';
		$con[18]['code']='months';$con[18]['name'] = '月-当日日期';
		$con[19]['code']='day';$con[19]['name'] = '日-当日日期';
		$con[20]['code']='order_no';$con[20]['name'] = '订单号-订单';
		$con[21]['code']='order_postscript';$con[21]['name'] = '备注-订单';
		$con[22]['code']='order_best_time';$con[22]['name'] = '送货时间-订单';
		$con[23]['code']='pigeon';$con[23]['name'] = '√-对号';								
		$this->assign('con', $con);
		$this->assign('shipping', $row);
		$this->assign('shipping_id', $shipping_id);
		$this->display();
	}
	public function edit_shipping_template(){
        $postdata=I('post.');
		if ($postdata['act'] == 'do_edit_print_template'){
			$print_model = intval($postdata['print_model']);
			$shipping_id =intval($postdata['shipping']) ;
		
			/* 处理不同模式编辑的表单 */
			if ($print_model == 2){
				//所见即所得模式
				$data_2['config_lable']=$postdata['config_lable'];
				$data_2['print_model']=$print_model;
				$where_2['id']=$shipping_id;
				M('Shipping')->where($where_2)->save($data_2);
			}elseif ($print_model == 1){
				//代码模式
				$template =$postdata['shipping_print'];
				$data_1['shipping_print']=$template;
				$data_1['print_model']=$print_model;
				$where_1['id']=$shipping_id;
				M('Shipping')->where($where_1)->save($data_1);
			}
		}
		$this->redirect('Admin/Shipping/shipping_template', array('id' =>$shipping_id));
	}
}