search_param.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 2017/3/19
  6. * Time: 下午10:46
  7. */
  8. require_once (BASE_ROOT_PATH . '/helper/history_helper.php');
  9. class search_param
  10. {
  11. private $mKeyWord;
  12. private $mBrandId;
  13. private $mHotId;
  14. private $mOrder;
  15. private $mSort;
  16. public function __construct($param)
  17. {
  18. $this->mKeyWord = '';
  19. $this->mBrandId = 0;
  20. $this->mHotId = 0;
  21. if (!empty(trim($param['keyword']))) {
  22. $keywod = trim(urldecode($param['keyword']));
  23. if ($this->check($keywod)) {
  24. $this->mKeyWord = trim(urldecode($param['keyword']));
  25. $helper = new history_helper();
  26. $helper->add_word($this->mKeyWord);
  27. }
  28. }
  29. if (intval($param['brand_id']) > 0) {
  30. $this->mBrandId = intval($param['brand_id']);
  31. }
  32. if (!empty(trim($param['hot_id']))) {
  33. $this->mHotId = intval($param['hot_id']);
  34. }
  35. //下面两个参数和客户端定义反了
  36. $this->mOrder = 'click';
  37. if (!empty($param['sort']))
  38. {
  39. $order = strtolower(trim($param['sort']));
  40. if(in_array($order,array('click','salenum','price'))) {
  41. $this->mOrder = $order;
  42. }
  43. }
  44. $this->mSort = 'desc';
  45. if (!empty($param['order']))
  46. {
  47. $sort = strtolower(trim($param['order']));
  48. if(in_array($sort,array('asc','desc'))) {
  49. $this->mSort = $sort;
  50. }
  51. }
  52. }
  53. public function format($page_no = null,$page_size = null)
  54. {
  55. if (empty($this->mKeyWord) && $this->mBrandId == 0 && $this->mHotId == 0) {
  56. return false;
  57. } else {
  58. $result = [];
  59. $result['keyword'] = $this->mKeyWord;
  60. $result['brand_id'] = $this->mBrandId;
  61. $result['hot_id'] = $this->mHotId;
  62. $result['order'] = $this->mOrder;
  63. $result['sort'] = $this->mSort;
  64. $result['page_no'] = $page_no;
  65. $result['page_size'] = $page_size;
  66. return $result;
  67. }
  68. }
  69. public function brand_id()
  70. {
  71. return $this->mBrandId;
  72. }
  73. private function check($keyword)
  74. {
  75. $words = search\word_segment::filter($keyword);
  76. if (empty($words)) {
  77. return false;
  78. } else {
  79. return true;
  80. }
  81. }
  82. }