Pay.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Pay extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_typeclass','typeclass');
  7. $this->load->_model('Model_pay','pay');
  8. }
  9. //定义方法的调用规则 获取URI第二段值
  10. public function _remap($arg,$arg_array)
  11. {
  12. if($arg == 'add')//添加
  13. {
  14. $this->_add();
  15. }
  16. else if($arg == 'edit')//修改
  17. {
  18. $this->_edit($arg_array);
  19. }
  20. else if($arg == 'del')//修改
  21. {
  22. $this->_del();
  23. }
  24. else
  25. {
  26. $this->_index();
  27. }
  28. }
  29. //管理
  30. public function _index()
  31. {
  32. $post = $this->input->post(NULL, TRUE);
  33. if(isset($post['page']))
  34. {
  35. $page = $this->input->post('page',true);
  36. $perpage = $this->input->post('perpage',true);
  37. $where = "1=1 ";
  38. //数据排序
  39. $order_str = "id asc";
  40. if(empty($page))
  41. {
  42. $start = 0;
  43. $perpage = 1;
  44. }
  45. else
  46. {
  47. $start = ($page - 1)*$perpage;
  48. }
  49. //取得信息列表
  50. $info_list = $this->pay->find_all($where,'id,typeclass,estimaterate',$order_str,$start,$perpage);
  51. //格式化数据
  52. foreach ($info_list as $key=>$value)
  53. {
  54. $type = $this->typeclass->read($value['typeclass']);
  55. $info_list[$key]['typeclass'] = $type['title'];
  56. }
  57. $total = $this->pay->find_count($where);
  58. $pagenum = ceil($total/$perpage);
  59. $over = $total-($start+$perpage);
  60. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  61. echo json_encode($rows);exit;
  62. }
  63. $this->_Template('pay',$this->data);
  64. }
  65. //添加
  66. public function _add()
  67. {
  68. $post = $this->input->post(NULL, TRUE);
  69. if(isset($post['typeclass']))
  70. {
  71. $d = $this->pay->get_typeclass($post['typeclass']);
  72. if($d)
  73. {
  74. echo json_encode(array('msg'=>'此支付方式已有设置数据','success'=>false));exit;
  75. }
  76. if($this->pay->insert($post))
  77. {
  78. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  79. }
  80. else
  81. {
  82. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  83. }
  84. }
  85. $this->_Template('pay_add',$this->data);
  86. }
  87. //修改
  88. public function _edit($arg_array)
  89. {
  90. $post = $this->input->post(NULL, TRUE);
  91. if(isset($post['id']))
  92. {
  93. $id = $this->input->post('id',true);
  94. if($this->pay->save($post,$id))
  95. {
  96. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  97. }
  98. else
  99. {
  100. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  101. }
  102. }
  103. $arg_array = $arg_array[0];
  104. $pay = $this->pay->read($arg_array);
  105. $this->data['pay'] = $pay;
  106. $this->_Template('pay_edit',$this->data);
  107. }
  108. //删除
  109. public function _del()
  110. {
  111. $post = $this->input->post(NULL, TRUE);
  112. if(isset($post['s']))
  113. {
  114. $id_arr = $this->input->post('s');
  115. $id_arr = explode(',',$id_arr);
  116. if(!$id_arr)
  117. {
  118. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  119. }
  120. //循环删除记录
  121. foreach ($id_arr as $v)
  122. {
  123. $this->pay->remove($v);
  124. }
  125. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  126. }
  127. }
  128. }