<?php
// +----------------------------------------------------------------------
// | Yershop 开源网店系统
// +----------------------------------------------------------------------
// | Copyright (c) 2014 http://www.yershop.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: liuwei <1010422715@qq.com>
// +----------------------------------------------------------------------
namespace app\seller\controller;
use think\Controller;
use think\Db;
class Pay extends Base{
    /**
     * 订单管理首页
     */
    public function index(){
		
		 if(isset($_GET['title'])){
            $map['title']  = array('like', '%'.(string)input('title').'%');
        }
		$map["shop_id"]=get_shop_id();
        $res= getLists('Pay',$map,10,'id desc');
        $this->assign( 'res', $res);
        $this->meta_title = '订单管理';
		$this->assign('meta_title', $this->meta_title);
        return $this->fetch(); 
    }
      /**
     * 订单编辑
     */
	public function edit($id){   
	    if($_POST){
		   $user =new \app\admin\model\Pay;
		   if(!check_model($id,"pay")){
		      $this->error("数据错误");
		   }
           $res=$user->save($_POST,['id' => $_POST['id']]);
	       if($res){
		      $this->success("更新成功！");
		   }else{
			   $this->success("更新失败！");
		   } 
	  }
	  else{
		 $map['id']=$id;
		 $map["shop_id"]=get_shop_id();
		 $info=Db::name("Pay")->where($map)->find();
	     $this->assign('info', $info);
		
		 $this->meta_title="编辑订单";
		 $this->assign('meta_title', $this->meta_title);
	     return $this->fetch();
	   }
	} 
	
	/**
     * 新增订单
     */
	  public function add($id=""){  
	  if($_POST){
		   $user =new \app\admin\model\Pay;
        // 过滤post数组中的非数据表字段数据
       $res=$user->allowField(true)->save($_POST);
	   if($res){
		   $this->success("新增成功！");
		}else{
			 $this->success("新增失败！");
		} 
	}
	  else{
		 
		  $this->meta_title="新增订单";
		  $this->assign('meta_title', $this->meta_title);
	      return $this->fetch("Pay/edit");
	  }
	}

	/**
     * 删除订单
     */
	 public function del(){   
	    $id=input("id");
	    $map['id']=array("in",$id);
		if(!$map["id"]){
			 $this->error("未选择数据！");
		} 
		$map["shop_id"]=get_shop_id();
		$res=Db::name("Pay")->where($map)->delete();
		if($res){
		   $this->success("删除成功！");
		}else{
			 $this->success("删除失败！");
		}
	}

}
