shareact.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. Doo::loadModel('share');
  3. Doo::loadClass('Hashids/Hashids');
  4. /**
  5. * Description of Users
  6. *
  7. * @author zongheng
  8. */
  9. class Shareact
  10. {
  11. private $__share, $__hashids, $__timetmp;
  12. function __construct()
  13. {
  14. $this->__share = new Share();
  15. $this->__hashids = new Hashids\Hashids('zhhashsalt');
  16. }
  17. public function insertHashcode($ids, $idtype)
  18. {
  19. $this->__timetmp = gettimeofday();
  20. $this->__share->endtime = time();
  21. $this->__share->intime = time();
  22. $this->__share->hashcode = $this->__hashids->encode($this->__timetmp['sec']);
  23. $this->__share->ids = $ids;
  24. $this->__share->idtype = $idtype;
  25. return array('status' => $this->__share->insert(), 'hashcode' => $this->__share->hashcode);
  26. }
  27. public function updateHashcode($ids, $idtype)
  28. {
  29. $this->__timetmp = gettimeofday();
  30. $this->__share->hashcode = $this->__hashids->encode($this->__timetmp['sec']);
  31. return array('status' => $this->__share->update(array('where' => 'ids=? AND idtype=?', 'param' => array($ids, $idtype))), 'hashcode' => $this->__share->hashcode);
  32. }
  33. public function deleteHashcode($ids,$idtype)
  34. {
  35. $hashcode = $this->getHashCode($ids,$idtype);
  36. return $this->__share->delete(array('where' => 'sid=?', 'param' => array($hashcode['sid'])));
  37. }
  38. public function getCount($ids, $idtype)
  39. {
  40. return $this->__share->Count(array('where' => 'ids=? AND idtype=?', 'param' => array($ids, $idtype)));
  41. }
  42. public function getHashCode($ids,$idtype)
  43. {
  44. return $this->__share->getOne(array('where' => 'ids=? AND idtype=?', 'param' => array($ids, $idtype), 'asArray' => true));
  45. }
  46. public function getSectionCount($ids)
  47. {
  48. return $this->__share->getOne(array('where' => 'ids=? AND idtype=2', 'param' => array($ids), 'asArray' => true));
  49. }
  50. public function getCountByKey($key)
  51. {
  52. return $this->__share->Count(array('where' => 'hashcode=?', 'param' => array($key)));
  53. }
  54. public function getOne($key)
  55. {
  56. return $this->__share->getOne(array('where' => 'hashcode=?', 'param' => array($key), 'asArray' => true));
  57. }
  58. }