StoreGoods.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. namespace We7\Table\Site;
  7. class StoreGoods extends \We7Table {
  8. protected $tableName = 'site_store_goods';
  9. protected $primaryKey = 'id';
  10. protected $field = array(
  11. 'type',
  12. 'title',
  13. 'module',
  14. 'module_group',
  15. 'user_group',
  16. 'account_num',
  17. 'wxapp_num',
  18. 'price',
  19. 'user_group_price',
  20. 'unit',
  21. 'slide',
  22. 'category_id',
  23. 'title_initial',
  24. 'status',
  25. 'createtime',
  26. 'synopsis',
  27. 'description',
  28. 'account_group',
  29. 'api_num',
  30. 'is_wish',
  31. 'logo',
  32. );
  33. protected $default = array(
  34. 'type' => '',
  35. 'title' => '',
  36. 'module' => '',
  37. 'module_group' => 0,
  38. 'user_group' => '',
  39. 'account_num' => '',
  40. 'wxapp_num' => '',
  41. 'price' => '',
  42. 'user_group_price' => '',
  43. 'unit' => '',
  44. 'slide' => '',
  45. 'category_id' => '',
  46. 'title_initial' => '',
  47. 'status' => '',
  48. 'createtime' => '',
  49. 'synopsis' => '',
  50. 'description' => '',
  51. 'account_group' => 0,
  52. 'api_num' => '',
  53. 'is_wish' => 0,
  54. 'logo' => '',
  55. );
  56. public function searchWithKeyword($title) {
  57. if (!empty($title)) {
  58. $this->where('title LIKE', "%{$title}%");
  59. }
  60. return $this;
  61. }
  62. public function searchWithIswishAndStatus($is_wish, $status) {
  63. $this->query->where(array(
  64. 'is_wish' => $is_wish,
  65. 'status' => $status
  66. ));
  67. return $this;
  68. }
  69. public function searchWithTypeAndTitle($type = 0, $title = '') {
  70. if (!empty($type) && is_numeric($type)) {
  71. $this->query->where('type', $type);
  72. }
  73. if (!empty($title)) {
  74. $this->query->where('title LIKE', "%$title%");
  75. }
  76. return $this;
  77. }
  78. public function searchWithTypeGroup($group_name) {
  79. if (!empty($group_name) && !is_numeric($group_name)) {
  80. load()->model('store');
  81. $types = store_goods_type_info($group_name);
  82. $this->query->where('type', array_keys($types));
  83. }
  84. return $this;
  85. }
  86. public function getByModuleName($module_name, $is_wish = 0) {
  87. return $this->query->where(array('module' => $module_name, 'is_wish' => $is_wish))->get();
  88. }
  89. public function getGoods($is_wish = 0, $status = 1) {
  90. $data = $this->query
  91. ->where(array('is_wish' => $is_wish, 'status' => $status))
  92. ->orderby('id', 'DESC')
  93. ->getall();
  94. if (!empty($data)) {
  95. load()->model('store');
  96. $types = store_goods_type_info();
  97. foreach ($data as &$item) {
  98. $item['user_group_price'] = iunserializer($item['user_group_price']);
  99. $item['slide'] = iunserializer($item['slide']);
  100. $item['type_info'] = $types[$item['type']];
  101. }
  102. }
  103. return $data;
  104. }
  105. }