contractact.php 2.3 KB

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