<?php
if (! defined ( 'APP_PATH' ) || ! defined ( 'I_PATH' )) {
	exit ( 'Access Denied' );
}

class ld_logistics extends controllerBase {
	function __construct() {
		parent::__construct ();
		$this->Gets = $this->sysParams ( 'a', 1 );
		$this->Class = syClass('ldi_logistics' );
		$this->Get_c='ld_logistics';
		$this->opers = '<a href="?c=ld_logistics">配送管理</a><a href="?c=ld_logistics&a=add">添加配送</a>';
		$this->newrow = array ( 
		'log_name' => $this->sysParams ( 'log_name', 1 ),
		 'log_desc' => $this->sysParams ( 'log_desc', 1 ), 
		 'price' => $this->sysParams ( 'price',3 ),
		 'overweight' => $this->sysParams ( 'overweight' ,3),
		 'cashondelivery' => $this->sysParams ( 'cashondelivery'),
		 'insure' => $this->sysParams ( 'insure' ), 
		 'insureproportion' => $this->sysParams ( 'insureproportion' ,1), 
		 'overweightprice' => $this->sysParams ( 'overweightprice' ,3) );	
	}
	function index() {
		$this->toptxt = '配送管理';
		$this->lists = syDB ('logistics' )->findAll ();
		$this->display ( "logistics.html" );
	}
	
	function add() {
		if ($this->sysParams ( 'run' ) == 1) {
			$newVerifier = $this->Class->syVerifier ( $this->newrow );
			if (false == $newVerifier) {
				if (syDB ( 'logistics' )->create ( $this->newrow )) {
					deleteDir ( func_get_iglobal(array('sp_cache')));
					message_a ( "配送方式添加成功", "?c=ld_logistics" );
				} else {
					message_a ( "配送方式添加成功，请重新提交" );
				}
			} else {
				message_b ( $newVerifier );
			}
		}
		$this->toptxt = '添加配送方式';
		$this->postgo = 'add';
		$this->display ( "logistics_edit.html" );
	}
	function edit() {
		$this->d = syDB ( 'logistics' )->find ( array ('log_id' => $this->sysParams ( 'log_id' ) ) );
		if ($this->sysParams ( 'run' ) == 1) {
			$newVerifier = $this->Class->syVerifier ( $this->newrow );
			if (false == $newVerifier) {
				if (syDB ( 'logistics' )->update ( array ('log_id' => $this->d ['log_id'] ), $this->newrow )) {
					deleteDir ( func_get_iglobal(array('sp_cache')));
					message_a ( "配送方式修改成功", "?c=ld_logistics" );
				} else {
					message_a ( "配送方式修改失败,请重新提交" );
				}
			} else {
				message_b ( $newVerifier );
			}
		}
		syDB("sysconfig")->update(array('code'=>set_logistics),array('value'=>1));//1代表已经设置完物流方式
		$this->toptxt = '修改配送方式';
		$this->postgo = 'edit';
		$this->display ( "logistics_edit.html" );
	}
	function del() {
		$this->toptxt = $this->moldname . '删除配送方式';
		$this->d = syDB ( 'logistics' )->find ( array ('log_id' => $this->sysParams ( 'log_id' ) ) );
		if ($this->sysParams ( 'run' ) == 1) {
			if (syDB ( 'logistics' )->delete ( array ('log_id' => $this->sysParams ( 'log_id' ) ) )) {
				deleteDir (func_get_iglobal(array('sp_cache')));
				message_a ( "配送方式删除成功", "?c=ld_logistics" );
			} else {
				message_a ( "配送方式删除失败,请重新提交" );
			}
		}
		$this->msgtitle = '确定要删配送方式 <strong>[' . $this->d ['log_name'] . ']</strong> 吗？';
		$this->msg = '';
		$this->msggo = '<a href="?c=ld_logistics&a=del&run=1&log_id=' . $this->d ['log_id'] . '">确定删除</a><a href="?c=ld_logistics">取消操作</a>';
		$this->display ( "msg.html" );
	}
}	