agentship.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace WY\app\controller\derpay;
  3. use WY\app\libs\Controller;
  4. use WY\app\model\Bill;
  5. if (!defined('WY_ROOT')) {
  6. exit;
  7. }
  8. class agentship extends CheckAdmin
  9. {
  10. public function index()
  11. {
  12. $kw = $this->req->get('kw');
  13. $cons = 'is_state=? and is_agent=?';
  14. $consOR = '';
  15. $consArr = array('1', 1);
  16. if ($kw) {
  17. $consOR .= $consOR ? ' or ' : '';
  18. $consOR .= 'username like ?';
  19. $consArr[] = '%' . $kw . '%';
  20. }
  21. if ($kw) {
  22. $consOR .= $consOR ? ' or ' : '';
  23. $consOR .= 'id = ?';
  24. $consArr[] = $kw;
  25. }
  26. if ($consOR) {
  27. $cons .= $cons ? ' and ' : '';
  28. $cons .= '(' . $consOR . ')';
  29. }
  30. $orderby = 'id desc';
  31. $sort = $this->req->get('sort');
  32. $sort = isset($_GET['sort']) ? $sort : 0;
  33. $by = $this->req->get('by');
  34. if ($by) {
  35. $sort2 = $sort ? ' desc' : ' asc';
  36. $orderby = $by . $sort2;
  37. }
  38. $page = $this->req->get('p');
  39. $page = $page ? $page : 1;
  40. $pagesize = 20;
  41. $totalsize = $this->model()->select()->from('users')->where(array('fields' => $cons, 'values' => $consArr))->count();
  42. $lists = array();
  43. if ($totalsize) {
  44. $totalpage = ceil($totalsize / $pagesize);
  45. $page = $page > $totalpage ? $totalpage : $page;
  46. $offset = ($page - 1) * $pagesize;
  47. $lists = $this->model()->select()->from('users')->offset($offset)->limit($pagesize)->orderby($orderby)->where(array('fields' => $cons, 'values' => $consArr))->fetchAll();
  48. }
  49. $pagelist = $this->page->put(array('page' => $page, 'pagesize' => $pagesize, 'totalsize' => $totalsize, 'url' => '?kw=' . $kw . '&sort=' . $sort . '&by=' . $by . '&p='));
  50. $data = array('title' => '用户列表', 'lists' => $lists, 'pagelist' => $pagelist, 'search' => array('kw' => $kw), 'sort' => $sort, 'by' => $by);
  51. $this->put('agentship.php', $data);
  52. }
  53. public function ship()
  54. {
  55. $bill = new Bill();
  56. $userid = isset($this->action[3]) ? $this->action[3] : 0;
  57. $users = $this->model()->select('unpaid')->from('users')->where(array('fields' => 'id=?', 'values' => array($userid)))->fetchRow();
  58. $newMoney = $users['unpaid'];
  59. $income = $bill->beforeAgentIncome($userid, 0);
  60. if ($income > 0) {
  61. $newMoney += $income;
  62. $data = array('unpaid' => $newMoney);
  63. if ($this->model()->from('users')->updateSet($data)->where(array('fields' => 'id=?', 'values' => array($userid)))->update()) {
  64. $where = array('fields' => 'is_state=? and is_ship_agent=? and agentid=? and gprice>? and addtime<?', 'values' => array(1, 0, $userid, 0, strtotime(date('Y-m-d'))));
  65. $this->model()->from('orders')->updateSet(array('is_ship_agent' => 1))->where($where)->update();
  66. $data = array('userid' => $userid, 'is_agent' => 1, 'before_money' => $users['unpaid'], 'money' => $income, 'after_money' => $newMoney, 'ctype' => '结算', 'addtime' => time());
  67. $this->model()->from('paylogs')->insertData($data)->insert();
  68. }
  69. }
  70. $userinfo = $this->model()->select()->from('userinfo')->where(array('fields' => 'userid=?', 'values' => array($userid)))->fetchRow();
  71. $userinfo += array('money' => $newMoney, 'fee' => $bill->fee($newMoney));
  72. $this->put('agentshippay.php', $userinfo);
  73. exit;
  74. }
  75. public function savepay()
  76. {
  77. $userid = isset($this->action[3]) ? $this->action[3] : 0;
  78. $data = isset($_POST) ? $_POST : false;
  79. if (!$data || !$userid) {
  80. $this->put('woodyapp.php', array('msg' => '数据出现错误'));
  81. exit;
  82. }
  83. $users = $this->model()->select('paid,unpaid')->from('users')->where(array('fields' => 'id=?', 'values' => array($userid)))->fetchRow();
  84. if (!$users) {
  85. $this->put('woodyapp.php', array('msg' => '用户不存在'));
  86. exit;
  87. }
  88. if ($users['unpaid'] < $data['money'] || $data['money'] <= 0) {
  89. $this->put('woodyapp.php', array('msg' => '账户余额不足'));
  90. exit;
  91. }
  92. $data += array('addtime' => time(), 'lastime' => time(), 'userid' => $userid, 'is_agent' => 1);
  93. if ($this->model()->from('payments')->insertData($data)->insert()) {
  94. $newMoney = $users['unpaid'] - $data['money'];
  95. $data = array('userid' => $userid, 'is_agent' => 1, 'before_money' => $users['unpaid'], 'money' => $data['money'], 'after_money' => $newMoney, 'ctype' => '付款', 'addtime' => time());
  96. $this->model()->from('paylogs')->insertData($data)->insert();
  97. $newData = array('paid' => $users['paid'] + $data['money'], 'unpaid' => $newMoney);
  98. $this->model()->from('users')->updateSet($newData)->where(array('fields' => 'id=?', 'values' => array($userid)))->update();
  99. $this->put('woodyapp.php', array('msg' => '付款记录已成功创建'));
  100. exit;
  101. }
  102. $this->put('woodyapp.php', array('msg' => '付款失败'));
  103. exit;
  104. }
  105. }