contractact.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. Doo::loadModel('contract');
  3. /**
  4. * Description of Users
  5. *
  6. * @author zongheng
  7. */
  8. class Contractact
  9. {
  10. private $__mcontract;
  11. function __construct()
  12. {
  13. $this->__mcontract = new Contract();
  14. }
  15. public function insertContract($pid, $uid, $stname)
  16. {
  17. if (!isset($pid))
  18. return FALSE;
  19. $this->__mcontract->pid = filter_var($pid, FILTER_VALIDATE_INT);
  20. $this->__mcontract->uid = filter_var($uid, FILTER_VALIDATE_INT);
  21. $this->__mcontract->stname = filter_var($stname, FILTER_SANITIZE_STRING);
  22. $this->__mcontract->stkey = $this->create_randomstr(10);
  23. $this->__mcontract->intime = time();
  24. return $this->__mcontract->insert();
  25. }
  26. public function getAll()
  27. {
  28. return $this->__mcontract->find(array('asArray' => TRUE));
  29. }
  30. public function getPidWithKey($stkey)
  31. {
  32. return $this->__mcontract->getOne(array('where' => 'stkey=?', 'param' => array($stkey), 'asArray' => TRUE));
  33. }
  34. public function getRowByPid($pid)
  35. {
  36. return $this->__mcontract->find(array('where' => 'pid=?', 'param' => array($pid), 'asArray' => TRUE));
  37. }
  38. public function getRowByStid($stid)
  39. {
  40. return $this->__mcontract->getOne(array('where' => 'stid=?', 'param' => array($stid), 'asArray' => TRUE));
  41. }
  42. public function getRow($uid)
  43. {
  44. return $this->__mcontract->find(array('where' => 'uid=?', 'groupby' => 'pid', 'param' => array($uid), 'asArray' => TRUE));
  45. }
  46. public function getUserRow($uid)
  47. {
  48. return $this->__mcontract->find(array('where' => 'uid=?', 'param' => array($uid), 'asArray' => TRUE));
  49. }
  50. public function updateStName($stid, $stname)
  51. {
  52. $this->__mcontract->stname = filter_var($stname, FILTER_SANITIZE_STRING);
  53. return $this->__mcontract->update(array('where' => 'stid=?', 'param' => array($stid)));
  54. }
  55. /**
  56. * 随机字符串函数
  57. * @param $password 密码
  58. * @param $random 随机数
  59. */
  60. function random($length, $chars = '0123456789')
  61. {
  62. $hash = '';
  63. $max = strlen($chars) - 1;
  64. for ($i = 0; $i < $length; $i++) {
  65. $hash .= $chars[mt_rand(0, $max)];
  66. }
  67. return $hash;
  68. }
  69. /**
  70. * 生成随机字符串
  71. * @param string $lenth 长度
  72. * @return string 字符串
  73. */
  74. function create_randomstr($lenth = 6)
  75. {
  76. return $this->random($lenth, '123456789abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ');
  77. }
  78. public function getNumRow($pid)
  79. {
  80. return $this->__mcontract->count(array('where' => 'pid=?', 'param' => array($pid), 'asArray' => TRUE));
  81. }
  82. public function del($stid)
  83. {
  84. return $this->__mcontract->delete(array('where' => 'stid=?', 'param' => array($stid)));
  85. }
  86. }