| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 | 
							- <?php defined('BASEPATH') OR exit('No direct script access allowed');
 
- class Message extends Start_Controller {
 
- 	public function __construct(){
 
- 		parent::__construct();
 
- 		$this->load->library('session');
 
- 		$this->load->_model('Model_message','message');
 
- 		$this->load->_model('Model_express','express');
 
- 	}
 
- 	//定义方法的调用规则 获取URI第二段值
 
-     public function _remap($arg,$arg_array)
 
-     {
 
- 		if($arg == 'add')
 
-         {
 
-              $this->_add();
 
-         }
 
- 		else if($arg == 'edit')//修改
 
-         {
 
-              $this->_edit($arg_array);
 
-         }
 
- 		else if($arg == 'del')//修改
 
-         {
 
-              $this->_del();
 
-         }
 
- 		else
 
- 		{
 
- 			 $this->_index();
 
- 		}
 
-     }
 
- 	//管理
 
- 	public function _index()
 
- 	{
 
- 		$exdata = $this->express->find_all();
 
- 		$ex = array();
 
- 		foreach ($exdata as $v)
 
- 		{
 
- 			$ex[$v['id']] = $v['servicename'];
 
- 		}
 
- 		$post = $this->input->post(NULL, TRUE);
 
- 		if(isset($post['page']))  
 
- 		{
 
- 		    $page = $this->input->post('page',true);
 
- 		    $perpage = $this->input->post('perpage',true);
 
- 			$express = $this->input->post('express',true);
 
- 			$where = "1=1";
 
- 			if($express)
 
-             {
 
-                 $where  .= " and express like '%,$express,%'";
 
-             }
 
-             //数据排序
 
-             $order_str = "id desc";
 
-             if(empty($page))
 
- 		    {
 
-                 $start = 0;
 
- 		    	$perpage = 1;
 
-             }
 
- 		    else
 
- 		    {
 
-                 $start = ($page - 1)*$perpage;
 
-             }
 
-             //取得信息列表
 
-             $info_list = $this->message->find_all($where,'id,express,content',$order_str,$start,$perpage);
 
- 			foreach ($info_list as $k=>$v) 
 
- 		    {
 
- 				$e = '';
 
- 				foreach (explode(',',trim($v['express'],',')) as $val) 
 
- 		        {
 
- 					$e .= $ex[$val].',';
 
- 				}
 
- 				$info_list[$k]['express'] = rtrim($e,',');
 
- 		    }
 
- 		    $total = $this->message->find_count($where);
 
- 		    $pagenum = ceil($total/$perpage);
 
- 		    $over = $total-($start+$perpage);
 
- 		    $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
 
- 		    echo json_encode($rows);exit;
 
- 		}
 
- 		$this->_Template('message',$this->data);
 
- 	}
 
- 	//入库操作
 
- 	public function _add()
 
- 	{
 
- 		$post = $this->input->post(NULL);
 
- 		if(isset($post['content']))
 
- 		{
 
- 			$express = $this->input->post('express');
 
- 			$post['express'] = ','.$express;
 
- 			if($post['express'] == ',')
 
- 			{
 
- 				echo json_encode(array('msg'=>'请选择物流','success'=>false));exit;
 
- 			}
 
- 			if($this->message->insert($post))
 
- 			{
 
- 				echo json_encode(array('msg'=>'提交成功','success'=>true));exit;
 
- 			}
 
- 			else
 
- 			{
 
- 				echo json_encode(array('msg'=>'提交失败','success'=>false));exit;
 
- 			}
 
- 		}
 
- 		$this->_Template('message_add',$this->data);
 
- 	}
 
- 	//修改产品
 
- 	public function _edit($arg_array)
 
- 	{
 
- 		$post = $this->input->post(NULL);
 
- 		if(isset($post['content']))
 
- 		{
 
- 			$id = $this->input->post('id');
 
- 			$express = $this->input->post('express',true);
 
- 			$post['express'] = ','.$express;
 
- 			if($post['express'] == ',')
 
- 			{
 
- 				echo json_encode(array('msg'=>'请选择物流','success'=>false));exit;
 
- 			}
 
- 			if($this->message->save($post,$id))
 
- 			{
 
- 				echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
 
- 			}
 
- 			else
 
- 			{
 
- 				echo json_encode(array('msg'=>'修改失败','success'=>false));exit;
 
- 			}
 
- 			
 
- 		}
 
- 		$message = $this->message->read($arg_array[0]);
 
- 		$this->data['message'] = $message ;
 
- 		$this->_Template('message_edit',$this->data);
 
- 	}
 
- 	
 
- 	public function _del()
 
- 	{
 
- 		$post = $this->input->post(NULL, TRUE);
 
- 		if(isset($post['s']))  
 
- 		{
 
-             $id_arr = $this->input->post('s');
 
-             $id_arr =  explode(',',$id_arr);
 
-             if(!$id_arr)
 
-             {
 
-                 echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
 
-             }
 
-             //循环删除记录
 
-             foreach ($id_arr as $v) 
 
- 		    {
 
-                 $this->message->remove($v);
 
-             }
 
-             echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
 
- 		}
 
-     }
 
- 		
 
- }
 
 
  |