partylogic.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /*
  3. * @Author: wang jun
  4. * @Date: 2022-01-18 11:12:23
  5. * @Last Modified by: wang jun
  6. * @Last Modified time: 2022-01-19 15:51:59
  7. */
  8. namespace app\admin\logic;
  9. use app\admin\model\partymodel;
  10. use think\facade\Log;
  11. class partylogic extends baselogic
  12. {
  13. /**
  14. * 设置请求数据规则
  15. * 20220107
  16. * wj
  17. */
  18. protected function setrules()
  19. {
  20. $list = [
  21. 'saveinfo' => [
  22. ['name' => 'id', 'title' => 'id', 'type' => 'numeric'],
  23. ],
  24. 'getinfobyid' => [
  25. ['name' => 'id', 'title' => 'id', 'require' => true, 'type' => 'numeric'],
  26. ],
  27. 'getlistbywhere' => [
  28. ['name' => 'isactive', 'title' => 'isactive', 'type' => 'numeric', 'regex' => '/[0|1]{1}/'],
  29. ['name' => 'name', 'title' => 'name', 'type' => 'string'],
  30. ['name' => 'createdate', 'title' => 'createdate', 'type' => 'array'],
  31. ['name' => 'page', 'title' => 'page', 'type' => 'numeric'],
  32. ['name' => 'size', 'title' => 'size', 'type' => 'numeric'],
  33. ],
  34. ];
  35. return $list;
  36. }
  37. /**
  38. * 保存活动信息
  39. * 20220210
  40. * wj
  41. */
  42. public function saveinfo($arr)
  43. {
  44. $result = $this->checkparam(__FUNCTION__, $arr);
  45. if (1 != $result['status']) {
  46. return $result;
  47. }
  48. $id = $arr['id'];
  49. $m_p = new partymodel();
  50. $isupdate = false;
  51. if (empty($id)) {
  52. //创建
  53. unset($arr['id']);
  54. $insertData = [
  55. 'name' => $arr['name'],
  56. 'start_time' => $arr['createdate'][0],
  57. 'end_time' => $arr['createdate'][0],
  58. 'banner_photo' => $arr['bannerphoto'],
  59. ];
  60. $id = $m_p->insertData($insertData);
  61. if (empty($id)) {
  62. return backarr(0, "添加失败");
  63. }
  64. } else {
  65. //修改
  66. $isupdate = true;
  67. $where = ['id' => $id];
  68. $info = $m_p->getInfo($where);
  69. if (empty($info)) {
  70. return backarr(0, "数据不存在");
  71. }
  72. $fields = ['name', 'start_time', 'end_time', 'isactive', 'banner_photo'];
  73. $updateData = [];
  74. foreach ($arr as $key => $value) {
  75. if (in_array($key, $fields) && !empty($value) && $value != $info[$key]) {
  76. $updateData[$key] = $value;
  77. }
  78. }
  79. log::info($updateData);
  80. if (!empty($updateData)) {
  81. $m_p->updateinfo($where, $updateData);
  82. }
  83. }
  84. return backarr(1, "操作成功", ['id' => $id, 'isupdate' => $isupdate]);
  85. }
  86. /**
  87. * 根据id获取信息
  88. * 20220210
  89. * wj
  90. */
  91. public function getinfobyid($arr)
  92. {
  93. $result = $this->checkparam(__FUNCTION__, $arr);
  94. if (1 != $result['status']) {
  95. return $result;
  96. }
  97. $id = $arr['id'];
  98. $m_p = new partymodel();
  99. $where = ['id' => $id];
  100. $info = $m_p->getInfo($where);
  101. if (empty($info)) {
  102. return backarr(0, "数据不存在");
  103. }
  104. return backarr(1, "操作成功", $info);
  105. }
  106. /**
  107. * 根据条件获取列表
  108. * 20220210
  109. * wj
  110. */
  111. public function getlistbywhere($arr)
  112. {
  113. $result = $this->checkparam(__FUNCTION__, $arr);
  114. if (1 != $result['status']) {
  115. return $result;
  116. }
  117. if (isset($arr['isactive'])) {
  118. $where[] = ['isactive', '=', $arr['isactive']];
  119. }
  120. if (isset($arr['name'])) {
  121. $where[] = ['name', 'like', '%' . $arr['name'] . '%'];
  122. }
  123. if (isset($arr['createdate'])) {
  124. $createdate = $arr['createdate'];
  125. if (count($createdate) == count(array_filter($createdate))) {
  126. $where[] = ['create_time', '>=', $createdate[0]];
  127. $where[] = ['create_time', '<=', $createdate[1]];
  128. }
  129. }
  130. $m_p = new partymodel();
  131. $count = $m_p->getList($where, 'count');
  132. if ($count <= 0) {
  133. return backarr(0, "无数据");
  134. }
  135. $page = isset($arr['page']) && !empty($arr['page']) ? $arr['page'] : 1;
  136. $size = isset($arr['size']) && !empty($arr['size']) ? $arr['size'] : 10;
  137. $list = $m_p->getList($where, '*', $page, $size);
  138. $data = [
  139. 'list' => $list,
  140. 'total' => $count,
  141. ];
  142. return backarr(1, "查询成功", $data);
  143. }
  144. }