<?php
// +----------------------------------------------------------------------
// | Sunnyi 多语商城建站系统 (Build on ThinkPHP)
// +----------------------------------------------------------------------
// | Copyright (c) 2009 http://www.sunnyi.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 商易网络(admin@sunnyi.cn)
// +----------------------------------------------------------------------

// 订单商品
class OrderGoodsAction extends CommonAction{
	public function foreverdelete() {
		//删除指定记录
		$name=$this->getActionName();
		$model = D ($name);
		if (! empty ( $model )) {
			$pk = $model->getPk ();
			$id = $_REQUEST [$pk];
			$order_id = D("OrderGoods")->where("id=".$id)->getField("order_id");
			if (isset ( $id )) {
				$condition = array ($pk => array ('in', explode ( ',', $id ) ) );
				if (false !== $model->where ( $condition )->delete ()) {
					//echo $model->getlastsql();
					$model->where(array ("pid" => array ('in', explode ( ',', $id ) ) ))->delete();  //同步删除礼包
					//重新计算订单总价
					$total_price = D("OrderGoods")->where("order_id=".$order_id)->sum("total_price");
					D("Order")->where("id=".$order_id)->setField("total_price",$total_price);
					$this->saveLog(1);
					$this->success (L('DEL_SUCCESS'));
				} else {
					$this->saveLog(0);
					$this->error (L('DEL_FAILED'));
				}
			} else {
				$this->saveLog(0);
				$this->error ( L('INVALID_OP') );
			}
		}
		$this->forward ();
	}
	
	public function edit()
	{
		$name=$this->getActionName();
		$model = M ( $name );
		$id = $_REQUEST [$model->getPk ()];
		$vo = $model->getById ( $id );
		$this->assign ( 'vo', $vo );
		$this->assign('back_param',array('id'=>$vo['order_id']));  //返回定单页用到的参数
		$this->display ();
	}
	
	
	function update() {
		//B('FilterString');
		$order_id = D("OrderGoods")->where("id=".intval($_REQUEST['id']))->getField("order_id");
		$name=$this->getActionName();
		$model = D ( $name );
		if (false === $model->create ()) {
			$this->error ( $model->getError () );
		}
		// 更新数据
		$list=$model->save ();
		if (false !== $list) {
			//成功提示
			//重新计算订单总价
					$total_price = D("OrderGoods")->where("order_id=".$order_id)->sum("total_price");
					D("Order")->where("id=".$order_id)->setField("total_price",$total_price);
			$this->saveLog(1);
			$this->success (L('EDIT_SUCCESS'));
		} else {
			//错误提示
			$this->saveLog(0);
			$this->error (L('EDIT_FAILED'));
		}
	}
}
?>