Goods.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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\Store;
  7. class Goods 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. 'api_num',
  19. 'price',
  20. 'user_group_price',
  21. 'unit',
  22. 'slide',
  23. 'category_id',
  24. 'title_initial',
  25. 'status',
  26. 'createtime',
  27. 'synopsis',
  28. 'description',
  29. 'is_wish',
  30. 'logo',
  31. );
  32. protected $default = array(
  33. 'type' => 0,
  34. 'title' => '',
  35. 'module' => '',
  36. 'module_group' => 0,
  37. 'user_group' => 0,
  38. 'account_num' => 0,
  39. 'wxapp_num' => 0,
  40. 'api_num' => 0,
  41. 'price' => 0,
  42. 'user_group_price' => '',
  43. 'unit' => '',
  44. 'slide' => '',
  45. 'category_id' => 0,
  46. 'title_initial' => '',
  47. 'status' => 0,
  48. 'createtime' => 0,
  49. 'synopsis' => '',
  50. 'description' => '',
  51. 'is_wish' => 0,
  52. 'logo' => '',
  53. );
  54. public function searchWithIswishAndStatus($is_wish, $status) {
  55. $this->query->where(array(
  56. 'is_wish' => $is_wish,
  57. 'status' => $status
  58. ));
  59. return $this;
  60. }
  61. public function searchWithTypeAndTitle($type = 0, $title = '') {
  62. if (!empty($type) && is_numeric($type)) {
  63. $this->query->where('type', $type);
  64. }
  65. if (!empty($title)) {
  66. $this->query->where('title LIKE', "%$title%");
  67. }
  68. return $this;
  69. }
  70. public function searchWithTypeGroup($group_name) {
  71. if (!empty($group_name) && !is_numeric($group_name)) {
  72. load()->model('store');
  73. $types = store_goods_type_info($group_name);
  74. $this->query->where('type', array_keys($types));
  75. }
  76. return $this;
  77. }
  78. public function getGoods($is_wish = 0, $status = 1) {
  79. $data = $this->query
  80. ->where(array('is_wish' => $is_wish, 'status' => $status))
  81. ->orderby('id', 'DESC')
  82. ->getall();
  83. if (!empty($data)) {
  84. load()->model('store');
  85. $types = store_goods_type_info();
  86. foreach ($data as &$item) {
  87. $item['user_group_price'] = iunserializer($item['user_group_price']);
  88. $item['slide'] = iunserializer($item['slide']);
  89. $item['type_info'] = $types[$item['type']];
  90. }
  91. }
  92. return $data;
  93. }
  94. }