Evaluate.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Evaluate extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_evaluate','evaluate');
  7. }
  8. //定义方法的调用规则 获取URI第二段值
  9. public function _remap($arg,$arg_array)
  10. {
  11. if($arg == 'add')//添加
  12. {
  13. $this->_add();
  14. }
  15. else
  16. {
  17. $this->_index();
  18. }
  19. }
  20. //管理
  21. public function _index()
  22. {
  23. $post = $this->input->post(NULL, TRUE);
  24. if(isset($post['page']))
  25. {
  26. $page = $this->input->post('page',true);
  27. $perpage = $this->input->post('perpage',true);
  28. $shop = $this->input->post('shop',true);
  29. $orderinfo = $this->input->post('orderinfo',true);
  30. $name = $this->input->post('name',true);
  31. $grade = $this->input->post('grade',true);
  32. $where = "1=1";
  33. if($shop)
  34. {
  35. $where .= " and shop = '$shop'";
  36. }
  37. if($orderinfo)
  38. {
  39. $where .= " and orderinfo = '$orderinfo'";
  40. }
  41. if($name)
  42. {
  43. $where .= " and name = '$name'";
  44. }
  45. if($grade != "")
  46. {
  47. $where .= " and grade = '$grade'";
  48. }
  49. //数据排序
  50. $order_str = "id desc";
  51. if(empty($page))
  52. {
  53. $start = 0;
  54. $perpage = 1;
  55. }
  56. else
  57. {
  58. $start = ($page - 1)*$perpage;
  59. }
  60. //取得信息列表
  61. $info_list = $this->evaluate->find_all($where,'id,shopname,shopid,orderinfo,name,grade,content,time',$order_str,$start,$perpage);
  62. //格式化数据
  63. foreach ($info_list as $key=>$value)
  64. {
  65. if($value['grade'] == 0)
  66. {
  67. $info_list[$key]['grade'] = "未评价";
  68. }
  69. else
  70. {
  71. $info_list[$key]['grade'] = $value['grade']."星";
  72. }
  73. $info_list[$key]['time'] = date('Y-m-d H:i:s',$value['time']);
  74. }
  75. $total = $this->evaluate->find_count($where);
  76. $pagenum = ceil($total/$perpage);
  77. $over = $total-($start+$perpage);
  78. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  79. echo json_encode($rows);exit;
  80. }
  81. $this->_Template('evaluate',$this->data);
  82. }
  83. //添加
  84. public function _add()
  85. {
  86. $post = $this->input->post(NULL, TRUE);
  87. if(isset($post['grade']))
  88. {
  89. $post['grade'] = $this->input->post('grade',true);
  90. $post['content'] = $this->input->post('content',true);
  91. /** 接口提交
  92. if($this->evaluate->insert($post))
  93. {
  94. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  95. }
  96. else
  97. {
  98. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  99. }
  100. **/
  101. }
  102. $this->_Template('evaluate_add',$this->data);
  103. }
  104. }