pay.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. Doo::loadCore('db/DooModel');
  3. /**
  4. * Description of newPHPClass
  5. *
  6. * @author zongheng
  7. */
  8. class Pay extends DooModel {
  9. public $id;
  10. public $trade_sn;
  11. public $userid;
  12. public $username;
  13. public $contactname;
  14. public $email;
  15. public $telephone;
  16. public $discount;
  17. public $money;
  18. public $quantity;
  19. public $addtime;
  20. public $paytime;
  21. public $usernote;
  22. public $pay_id;
  23. public $pay_type;
  24. public $payment;
  25. public $type;
  26. public $ip;
  27. public $status;
  28. public $adminnote;
  29. public $checker;
  30. public $_table = 'wk_pay_account';
  31. public $_primarykey = 'id';
  32. public $_fields = array('id', 'trade_sn', 'userid', 'username', 'contactname', 'email', 'telephone', 'discount', 'money', 'quantity', 'addtime', 'paytime', 'usernote', 'pay_id', 'pay_type', 'payment', 'type', 'ip', 'status', 'adminnote','checker');
  33. public function __construct() {
  34. parent::setupModel(__CLASS__);
  35. }
  36. public function add($array) {
  37. if (!is_array($array))
  38. return FALSE;
  39. foreach ($array as $key => $value) {
  40. $this->$key = $value;
  41. }
  42. return $this->insert();
  43. }
  44. public function getAll($limit) {
  45. return $this->find(array(
  46. 'limit' => $limit,
  47. 'asArray' => TRUE));
  48. }
  49. public function getRowsBySN($sn) {
  50. if (empty($sn))
  51. return FALSE;
  52. return $this->getOne(array('select' => 'id,userid,money,status', 'where' => 'trade_sn=?', 'param' => array($sn), 'limit' => '1', 'asArray' => TRUE));
  53. }
  54. private function _ExsitTheUser($uid) {
  55. $arruser = $this->getOne(array('select' => 'uid', 'where' => 'uid=?', 'param' => array($uid), 'limit' => '1', 'asArray' => TRUE));
  56. if (empty($arruser) && is_array($arruser)) {
  57. $this->uid = intval($uid);
  58. return $this->insert();
  59. } else {
  60. return FALSE;
  61. }
  62. }
  63. public function getRowByUid($id) {
  64. return $this->getOne(array('where' => 'id=?', 'param' => array($id), 'asArray' => TRUE));
  65. }
  66. public function getWidthAndLevel($uid, $level) {
  67. $userz = $this->getRowByUid($uid);
  68. $level[] = $userz['totalintegral'];
  69. sort($level);
  70. $thekey = array_search($userz['totalintegral'], $level);
  71. if (isset($level[$thekey - 1])) {
  72. $tmplevel = $userz['totalintegral'] - $level[$thekey - 1];
  73. } else {
  74. $tmplevel = $userz['totalintegral'];
  75. }
  76. $width = round($tmplevel / $level[$thekey + 1], 2) * 100 . '%';
  77. return array('width' => $width, 'currlevel' => $thekey + 1, 'currinte' => $tmplevel, 'levelup' => $level[$thekey + 1]);
  78. }
  79. public function updateRowbyUid($uid, $array) {
  80. if ($uid)
  81. $this->_ExsitTheUser($uid);
  82. if (!is_array($array))
  83. return FALSE;
  84. foreach ($array as $key => $val) {
  85. $this->$key = $val;
  86. }
  87. return $this->update(array('where' => 'uid=' . $uid));
  88. }
  89. public function updateRowbySN($sn, $array) {
  90. if (!is_array($array))
  91. return FALSE;
  92. foreach ($array as $key => $val) {
  93. $this->$key = $val;
  94. }
  95. return $this->update(array('where' => 'trade_sn=' . $sn));
  96. }
  97. public function get_all_posts($limit = NULL) {
  98. if (!empty($limit)) {
  99. $postArray = $this->limit($limit, null, 'id', array('asArray' => TRUE));
  100. } else {
  101. $postArray = $this->find(array('select' => 'id, trade_sn, userid, username, contactname, email, telephone, discount, money, quantity, addtime, paytime, usernote, pay_id, pay_type, payment, type, ip, status, adminnote', 'desc' => 'id', 'asArray' => true));
  102. }
  103. return $postArray;
  104. }
  105. public function get_all_posts_status($limit = NULL,$status="") {
  106. $postArray = $this->limit($limit, null, 'id', array('where' => $status , 'desc' => 'id', 'asArray' => true));
  107. return $postArray;
  108. }
  109. public function setToSucc($sn) {
  110. if (!$sn)
  111. return FALSE;
  112. $this->status = 'succ';
  113. return $this->update(array('where' => 'trade_sn=' . $sn));
  114. }
  115. public function get_sum_succ_posts($payment,$start,$end){
  116. return $this->getOne(array('select' => 'sum(money) as sum', 'where' => 'pay_type="'. $payment .'" and status="succ" and paytime between '. $start .' and '. $end, 'asArray' => TRUE));
  117. }
  118. }
  119. ?>