usercfo.php 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace WY\app\controller\derpay;
  3. use WY\app\libs\Controller;
  4. if (!defined('WY_ROOT')) {
  5. exit;
  6. }
  7. class usercfo extends CheckAdmin
  8. {
  9. public function index()
  10. {
  11. $data = array('title' => '代收款登记记录');
  12. $uname = $this->req->get('uname');
  13. $fdate = $this->req->get('fdate');
  14. $tdate = $this->req->get('tdate');
  15. $cons = $consOr = '';
  16. $consArr = array();
  17. if ($uname) {
  18. $consOr .= $consOr ? ' or ' : '';
  19. $consOr .= 'a.userid =?';
  20. $consArr[] = $uname;
  21. }
  22. if ($uname) {
  23. $user = $this->model()->select('id')->from('users')->where(array('fields' => 'username=?', 'values' => array($uname)))->fetchRow();
  24. if ($user) {
  25. $consOr .= $consOr ? ' or ' : '';
  26. $consOr .= 'a.userid=?';
  27. $consArr[] = $user['id'];
  28. }
  29. }
  30. if ($fdate) {
  31. $cons .= $cons ? ' AND ' : '';
  32. $cons .= 'a.addtime >= ?';
  33. $consArr[] = strtotime($fdate);
  34. }
  35. if ($tdate) {
  36. $cons .= $cons ? ' AND ' : '';
  37. $cons .= 'a.addtime <= ?';
  38. $consArr[] = strtotime($tdate . ' 23:59:59');
  39. }
  40. $page = $this->req->get('p');
  41. $page = $page ? $page : 1;
  42. $pagesize = 15;
  43. $lists = array();
  44. $totalsize = $this->model()->from('cfo a')->where(array('fields' => $cons, 'values' => $consArr))->count();
  45. if ($totalsize) {
  46. $totalpage = ceil($totalsize / $pagesize);
  47. $page = $page > $totalpage ? $totalpage : $page;
  48. $offset = ($page - 1) * $pagesize;
  49. $lists = $this->model()->select('a.*,c.username')->from('cfo a')->limit($pagesize)->left('users c')->on('c.id=a.userid')->join()->offset($offset)->orderby('a.id desc')->where(array('fields' => $cons, 'values' => $consArr))->fetchAll();
  50. }
  51. $pagelist = $this->page->put(array('page' => $page, 'pagesize' => $pagesize, 'totalsize' => $totalsize, 'url' => '?uname=' . $uname . '&fdate=' . $fdate . '&tdate=' . $tdate . '&p='));
  52. $data += array('lists' => $lists, 'pagelist' => $pagelist, 'search' => array('uname' => $uname, 'fdate' => $fdate, 'tdate' => $tdate));
  53. $this->put('usercfo.php', $data);
  54. }
  55. public function del()
  56. {
  57. $id = $this->req->get('id');
  58. if ($id) {
  59. if ($this->model()->from('cfo')->where(array('fields' => 'id=?', 'values' => array($id)))->delete()) {
  60. echo json_encode(array('status' => 1));
  61. exit;
  62. }
  63. }
  64. echo json_encode(array('status' => 0));
  65. exit;
  66. }
  67. public function edit()
  68. {
  69. $id = isset($this->action[3]) ? intval($this->action[3]) : 0;
  70. if ($data = $this->model()->select()->from('cfo')->where(array('fields' => 'id=?', 'values' => array($id)))->fetchRow()) {
  71. $this->put('usercfoedit.php', $data);
  72. }
  73. }
  74. public function save()
  75. {
  76. $id = isset($this->action[3]) ? intval($this->action[3]) : 0;
  77. $bankname = $this->req->post('bankname');
  78. $provice = $this->req->post('provice');
  79. $city = $this->req->post('city');
  80. $branchname = $this->req->post('branchname');
  81. $accountname = $this->req->post('accountname');
  82. $cardno = $this->req->post('cardno');
  83. $sfz = $this->req->post('sfz');
  84. $shouji = $this->req->post('shouji');
  85. if ($id == '' && $bankname == '' || $provice == '' || $city == '' || $branchname == '' || $accountname == '' || $cardno == '' || $sfz == '' || $shouji == '') {
  86. echo json_encode(array('status' => 0));
  87. exit;
  88. }
  89. $data = array('bankname' => $bankname, 'sfz' => $sfz, 'shouji' => $shouji, 'provice' => str_replace('省', '', $provice), 'city' => str_replace('市', '', $city), 'branchname' => $branchname, 'accountname' => $accountname, 'cardno' => $cardno);
  90. if ($this->model()->from('cfo')->updateSet($data)->where(array('fields' => 'id=?', 'values' => array($id)))->update()) {
  91. echo json_encode(array('status' => 1));
  92. exit;
  93. }
  94. echo json_encode(array('status' => 0));
  95. }
  96. }