partymodel.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /*
  3. * @Author: wang jun
  4. * @Date: 2022-01-18 09:43:33
  5. * @Last Modified by: wang jun
  6. * @Last Modified time: 2022-01-19 16:39:15
  7. */
  8. namespace app\index\model;
  9. use think\Model;
  10. class partymodel extends Model
  11. {
  12. protected $table = 't_party';
  13. public function insertData($data)
  14. {
  15. if (!isset($data['crate_time']) || empty($data['crate_time']) || !is_string($data['crate_time'])) {
  16. $data['crate_time'] = date("Y-m-d H:i:s");
  17. }
  18. $data = $this->formatData($data);
  19. if (empty($data)) {
  20. return false;
  21. }
  22. $id = $this->insertGetId($data);
  23. return empty($id) ? false : $id;
  24. }
  25. /**
  26. * 校验入库数据
  27. * 20220119
  28. */
  29. private function formatData($data)
  30. {
  31. $useData = [];
  32. $fields = $this->getTableFields();
  33. foreach ($data as $key => $value) {
  34. if (in_array($key, $fields)) {
  35. $useData[$key] = $value;
  36. }
  37. }
  38. return $useData;
  39. }
  40. public function getInfo($where, $field = "*", $row = true)
  41. {
  42. $info = $this->field($field)->where($where);
  43. if ($row) {
  44. $info = $info->find();
  45. } else {
  46. $info = $info->select();
  47. }
  48. return empty($info) ? false : $info;
  49. }
  50. public function updateinfo($where, $updateData)
  51. {
  52. $row = $this->where($where)->update($updateData);
  53. return empty($row) ? false : $row;
  54. }
  55. public function deleteinfo($where)
  56. {
  57. $row = $this->where($where)->delete();
  58. return empty($row) ? false : $row;
  59. }
  60. public function getList($where = [], $field = "*", $page = 1, $size = 10, $order = "id desc", $group = "", $row = false)
  61. {
  62. $sqlObj = $this->where($where);
  63. if ("count" != $field) {
  64. $sqlObj = $sqlObj->field($field)->order($order)->group($group)->page($page, $size);
  65. if ($row) {
  66. $data = $sqlObj->find();
  67. } else {
  68. $data = $sqlObj->select();
  69. }
  70. } else {
  71. $data = $sqlObj = $sqlObj->count();
  72. }
  73. return $data;
  74. }
  75. /**
  76. * 根据时间获取活动
  77. * 20220119
  78. * wj
  79. */
  80. public function getinfobytime($time)
  81. {
  82. $where = [
  83. 'isactive' => 1,
  84. 'start_time' => ['<=', $time],
  85. 'end_time' => ['>=', $time],
  86. ];
  87. $order = "id asc";
  88. $info = $this->where($where)->order($order)->find();
  89. return empty($info) ? false : $info;
  90. }
  91. /**
  92. * 根据时间获取活动
  93. * 20220119
  94. * wj
  95. */
  96. public function getinfobyid($id)
  97. {
  98. $where = [
  99. 'id' => $id,
  100. 'isactive' => 1,
  101. ];
  102. $order = "id asc";
  103. $info = $this->where($where)->order($order)->find();
  104. return empty($info) ? false : $info;
  105. }
  106. }