anotice.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 2017/4/6
  6. * Time: 上午10:50
  7. */
  8. namespace user_session;
  9. require_once (BASE_ROOT_PATH . '/helper/algorithm.php');
  10. require_once (BASE_ROOT_PATH . '/helper/session_helper.php');
  11. use algorithm;
  12. use session_helper;
  13. class anotice
  14. {
  15. private $mGoods;
  16. private $mDirty;
  17. public function __construct()
  18. {
  19. $this->mGoods = [];
  20. $this->mDirty = false;
  21. if(isset($_SESSION['arrival_notice'])) {
  22. $this->mGoods = $_SESSION['arrival_notice'];
  23. } else {
  24. $this->onStatus();
  25. }
  26. }
  27. public function __destruct()
  28. {
  29. if($this->mDirty) {
  30. $_SESSION['arrival_notice'] = $this->mGoods;
  31. }
  32. $this->mDirty = false;
  33. }
  34. public function onStatus()
  35. {
  36. $this->mGoods = [];
  37. $this->mDirty = true;
  38. $mod_anotice = Model('arrival_notice');
  39. $notices = $mod_anotice->getArrivalNoticeList(['member_id' => $_SESSION['member_id']]);
  40. foreach ($notices as $item)
  41. {
  42. $goods_id = intval($item['goods_id']);
  43. if($goods_id > 0) {
  44. $this->mGoods[] = $goods_id;
  45. }
  46. }
  47. sort($this->mGoods);
  48. }
  49. public function add($goods_id)
  50. {
  51. $goods_id = intval($goods_id);
  52. if(algorithm::binary_search($this->mGoods,$goods_id) == false) {
  53. $pos = algorithm::lower_bonud($this->mGoods,$goods_id);
  54. algorithm::array_insert($this->mGoods,$pos,$goods_id);
  55. $this->mDirty = true;
  56. }
  57. }
  58. public function del($goods_id)
  59. {
  60. $goods_id = intval($goods_id);
  61. if(algorithm::binary_search($this->mGoods,$goods_id) == true) {
  62. $pos = algorithm::lower_bonud($this->mGoods,$goods_id);
  63. algorithm::array_erase($this->mGoods,$pos);
  64. $this->mDirty = true;
  65. }
  66. }
  67. public function noticed($goods_id)
  68. {
  69. if(!session_helper::logined()) return false;
  70. $goods_id = intval($goods_id);
  71. return algorithm::binary_search($this->mGoods,$goods_id);
  72. }
  73. }