php數據庫model

Model
<?php
//$_SERVER["PHP_SELF"];
/**
 * 1、酒店 2、控房 3、機票 4、水舞間 5、餐飲 6、租車 7、其它 8、太陽劇團 9、鑰匙房
 * Enter description here ...
 * @author soonestem
 *
 */
class model_base_history extends CI_Model {
/* (non-PHPdoc)
	 * @see CI_Model::__construct()
	 */
	public function __construct() {
		// TODO Auto-generated method stub
		parent::__construct();
	}
	
	
	/**
	 * 插入租車的歷史記錄
	 * Enter description here ...
	 * @param unknown_type $data
	 */
	public function insert($productId,$data){
		$tablename = $this -> JudgeTableName($productId);
		$this -> db -> insert($tablename,$data);
	}
	
	/**
	 * 符合條件的記錄大小
	 * Enter description here ...
	 * @param unknown_type $where
	 * @param unknown_type $conditon
	 */
	public function get_list_size($productId,$where,$conditon){
		$tablename = $this -> JudgeTableName($productId);
		$this -> db -> select(' count(*) as count');
		if($conditon != null){
			$this -> db -> like($conditon);
		}
		
		$query = $this -> db -> get_where($tablename,$where);
		$result = $query -> result();
		
		return $result[0] -> count;
	}
	
	/**
	 * 符合條件的資據
	 * Enter description here ...
	 * @param unknown_type $where
	 * @param unknown_type $condition
	 * @param unknown_type $offset
	 * @param unknown_type $limit
	 * @param unknown_type $orderby
	 */
	public function get_list($productId,$where,$condition = null,$offset = null,$limit = null,$orderby = null){
		$tablename = $this -> JudgeTableName($productId);
		
		if($condition != null){
			$this -> db -> like($condition);
		}
		
		if($orderby != null){
			$this -> db -> order_by($orderby,'DESC');
		}
		return $this -> db -> get_where($tablename,$where,$limit,$offset);
	}
	
	
	/**
	 * 刪除歷史記錄
	 * Enter description here ...
	 * @param unknown_type $id
	 */
	public function delete_history($productId,$id){
		$tablename = $this -> JudgeTableName($productId);
		$this -> db -> where('histroy_id',$id);
		$this -> db -> delete($tablename);
	}

	
	public function JudgeTableName($productId){
		if ($productId == 1 || $productId == 2 || $productId == 9) {
			return 'tp_history_hotel';
		}else if($productId == 3){
			return 'tp_history_air_ticket';
		}else if($productId == 4){
			return 'tp_history_dancing_water';
		}else if($productId == 5){
			return 'tp_history_buffet';
		}else if($productId == 6){
			return 'tp_history_rent_car';
		}else if($productId == 7){
			return 'tp_history_other';
		}else if($productId == 8){
			return 'tp_history_zaia';
		}
	}
}

?>


Control

<?php

class Controller_history extends MY_Controller {
	/* (non-PHPdoc)
	 * @see MY_Controller::__construct()
	 */
	public function __construct() {
		// TODO Auto-generated method stub
		parent::__construct ();
	}

	public function judgehistoryview($pid){
		$data['pid'] = $pid;
		if ($pid == 1) {
			$this -> load -> view('history/view_history_hotel',$data);
		}else if($pid == 2){
			$this -> load -> view('history/view_history_hotel',$data);
		}else if($pid == 3){
			$this -> load -> view('history/view_history_are_ticket');
		}else if($pid == 4){
			$this -> load -> view('history/view_history_dancing_water');
		}else if($pid == 5){
			$this -> load -> view('history/view_history_buffet');
		}else if($pid == 6){
			$this -> load -> view('history/view_history_rent_car');
		}else if($pid == 7){
			$this -> load -> view('history/view_history_other');
		}else if($pid == 8){
			$this -> load -> view('history/view_history_zaia');
		}else if($pid == 9){
			$this -> load -> view('history/view_history_hotel',$data);
		}
	}
	
	
	
	public function get_history_json_data(){
		
		$limit = isset($_POST['limit']) ? $_POST['limit'] : 12;
		$offset =  isset($_POST['start']) ? $_POST['start'] : 0;
		$productId = isset($_POST['productId']) ? $_POST['productId'] : 1;
		
		$where = null;
		if(isset($_POST['where'])){
			$where = array('pid' => trim($_POST['where']));
		}
		$condition = null;
		if(isset($_POST['search_order_number']) && trim($_POST['search_order_number']) != ''){
			$condition = array('confirmation_number' => trim($_POST['search_order_number']));
		}
		
		
		
		$this -> load -> model('history/model_base_history','m_history');
		
		$dscount = $this -> m_history -> get_list_size($productId,$where,$condition);
		
		$ds = $this -> m_history -> get_list($productId,$where,$condition,$offset,$limit,null);
		
		$json = json_encode($ds -> result());
		
		$json = "{totalProperty:".$dscount.",root:".$json."}";
		
		echo $json;
		
	}
}

?>


ExtJs

	Ext.onReady(pageExt);// 執行Ext讀取

	 var ds =null;
	 var systemFormCI =null;
	 var grid =null;
	 var order_number_text = '';
	 var productId = 6;
	 
	 // 加載表模型
	 function pageExt(){	
		 var start =0;
		 var limit =12;
		 					
		 var cm = new Ext.grid.ColumnModel([
			 new Ext.grid.RowNumberer(
			 {header:'序號',dataIndex:'history_id',sortable : true,width:40}),
			 {header:'確認單號',dataIndex:'confirmation_number',sortable:true,width:100},
			 {header:'顧客姓名',dataIndex:'creater_username',sortable:true,width:70},
			 {header:'租車公司',dataIndex:'rent_car_company_name',sortable:true,width:70},	
	         {header:'供應商',dataIndex:'supplier_name',sortable:true,width:150},	
	         {header:'預定日期',dataIndex:'booking_datetime',sortable:true,width:100},
	         {header:'車輛類型',dataIndex:'rent_car_type',sortable:true,width:100},
	         {header:'車輛數',dataIndex:'num_of_car',sortable:true,width:100},
	         {header:'路線',dataIndex:'route',sortable:true,width:100},
	         {header:'備註',dataIndex:'remark',sortable:true,width:100},
	         {header:'收款狀態',dataIndex:'receivable_status',renderer:function(value){
	        	 if(value == 1){
	        		 return "未收";
	        	 }else if(value == 2){
	        		 return "已收";
	        	 }else if(value == 3){
	        		 return "已收部份";
	        	 }
	        	 return "";
	        		 
	         },sortable:true,width:100},
	         {header:'付款狀態',dataIndex:'payment_status',renderer:function(value){
	        	 if(value == 1){
	        		 return "未收";
	        	 }else if(value == 2){
	        		 return "已收";
	        	 }else if(value == 3){
	        		 return "已收部份";
	        	 }
	        	 return "";
	        		 
	         },sortable:true,width:100},
	         {header:'應收',dataIndex:'receivable',sortable:true,width:75},
	         {header:'應付',dataIndex:'pay',sortable:true,width:75},
	         {header:'已收',dataIndex:'received',sortable:true,width:75},
	         {header:'已付',dataIndex:'paid',sortable:true,width:75},
	         {header:'操作行為',dataIndex:'operation_id',renderer:function(value){
	        	 if(value == 1){
	        		 return "創建";
	        	 }else if(value == 2){
	        		 return "更新";
	        	 }else if(value == 3){
	        		 return "刪除";
	        	 }
	        	 return "";
	        		 
	         },sortable:true,width:100},
	         {header:'操作時間',dataIndex:'operate_time',sortable:true,width:100},
	         {header:'操作人員',dataIndex:'operate_username',sortable:true,width:100}
	      ]);
		 
		 
		 function JudgeOperation(value){
			 if(value == 1){
				 return "創建"
			 }else if(value == 2){
				 return "修改"
			 }else if(value == 3){
				 return "刪除"
			 }
		 }
		 
		// 加載內容
		  ds = new Ext.data.Store({
	        proxy: new Ext.data.HttpProxy({url:base_url+'histories/Controller_history/get_history_json_data'}),   
	        reader: new Ext.data.JsonReader({
	        totalProperty: 'totalProperty', 
	    	root: 'root'
			}, [
			    {name:'history_id'},
			    {name:'confirmation_number'},
			    {name:'creater_username'},
			    {name:'rent_car_company_name'},
			    {name:'supplier_name'},
			    {name:'booking_datetime'},
			    {name:'rent_car_type'},
			    {name:'num_of_car'},
			    {name:'route'},
			    {name:'remark'},
			    {name:'receivable_status'},
			    {name:'payment_status'},
			    {name:'receivable'},
			    {name:'pay'},
			    {name:'received'},
			    {name:'paid'},
			    {name:'operation_id'},
			    {name:'operate_time'},
			    {name:'operate_username'}
			])
	     });

		 var pagingbar = new Ext.PagingToolbar({
			 pageSize: limit,
			 store: ds,
			 displayInfo: true,
			 displayMsg: '顯示第 {0} 條到 {1} 條記錄,共 {2} 條',
			 emptyMsg: "No topics to display"
		 });
		  
		 grid = new Ext.grid.GridPanel({
			 id : 'history_other_list_id',
			 width: 725,
		 	 height:425,
		 	 title : '訂單修改記錄',
		 	 region : "center",
		 	 ds:ds,
		     cm:cm,
		     trackMouseOver:false,
	         disableSelection:false,
	         loadMask: true,
	         tbar:[
	             {
	            	xtype : 'label',
	            	text : '訂單編號',
	            	width: 60
	             },{
	            	 xtype : 'textfield',
	            	 id : 'order_number_id',
	            	 width: 80,
	            	 listeners:{
	                     'specialkey': function(f,e){
			                if (e.getKey() == e.ENTER) {
			                  	order_number_text=this.getValue();
			                  	ds.reload({params:{start:start,limit:limit,productId:productId,search_order_number:order_number_text}});
			                }
		              	 } 
	                 }
	             },{
					xtype : 'label',
					text : '修改時間',
					width : 60
				 },{
					xtype : 'datefield',
					format : 'Y-m-d',
					width : 90,
					id : 'update_time_id',
					editable : false,
					name : 'e_datetime',
					listeners :{
						'select':function(){
							var order = Ext.getCmp('order_number_id').getValue();
							var times = Ext.getCmp('update_time_id').getValue();
							alert(times + order);
						}
					} 
		         },'-',
		         {
			        	xtype : 'combo',
			        	width : 50,
			        	store : [[1,'創建'],[2,'修改'],[3,'刪除']],
			        	editable : false,
			        	emptyText : '操作',
			        	mode : 'local',
						triggerAction : 'all',
			        	id : 'opreate_id'	
			      },'-',{
			    	  xtype : 'button',
			    	  text : '重新載入',
			    	  handler : function(){
			    		  Ext.getCmp('order_number_id').setValue('');
						  Ext.getCmp('update_time_id').setValue('');
						  ds.load({params:{start:start,limit:limit}});
			    	  }
			      }
		         ],
		 	  viewConfig: {forceFit:false,enableRowBody:true,showPreview:true},
		 	  bbar:pagingbar
		 });
		 
		 //條件分頁
		 ds.on('beforeload', function(){
		 Ext.apply(this.baseParams,{
			  'search_order_number': Ext.getCmp('order_number_id').getValue(),
			  'productId':productId,
			  });
		 });
		 grid.render("grid");
		 ds.load({params:{start:start,limit:limit,productId:productId}});
	}



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章