Account_news.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. *------Create thems Model------
  4. *------SCWPHP Version 1.0.0------
  5. *------Dev Model Jions------
  6. *------Create Time 2017-06-23 09:58:34------
  7. */
  8. namespace App\Commons\Model;
  9. use \System\Model;
  10. class Account_news extends Model {
  11. public $timestamps = false;
  12. protected $table = 'account_news';
  13. /**
  14. * 用户消息
  15. *
  16. * @access public
  17. * @param mixed $select 查询字段
  18. * @param mixed $where 查询条件
  19. * @param mixed $between 查询条件区间 ['money_time' => [$startTime, $endTime], ...]
  20. * @param mixed $begin 起始查询位置
  21. * @param mixed $pageSize 分页大小
  22. * @param mixed $toArray 是否专为数组
  23. * @param mixed $orderBy 排序字段
  24. * @param mixed $join 关联关系 ['article' => 'oney_buy.info_identity = article.identity', ...]
  25. * @return array JsonString
  26. */
  27. public function accountNews($select, $where = '', $between = '', $begin = '', $pageSize = '', $toArray = 0, $orderBy = ['write_time' => 'desc'], $join = '') {
  28. // 查询字段
  29. $result = $this -> select($select);
  30. // 循环关联
  31. if (!empty($join)) {
  32. foreach ($join as $key => $value) {
  33. $result = $result -> join($key, $value);
  34. }
  35. }
  36. // 查询条件
  37. if (!empty($where)) {
  38. $result = $result -> where($where);
  39. }
  40. // 循环获取查询区间
  41. if (!empty($between)) {
  42. foreach ($between as $key => $value) {
  43. $result = $result -> whereBetween($key, $value);
  44. }
  45. }
  46. // 查询起始
  47. if (strlen($begin)) {
  48. $result = $result -> offset($begin);
  49. }
  50. // 分页大小
  51. if (strlen($pageSize)) {
  52. $result = $result -> limit($pageSize);
  53. }
  54. // 循环排序规则
  55. foreach ($orderBy as $key => $value) {
  56. $result = $result -> orderBy($key, $value);
  57. }
  58. // 获取数据
  59. $result = $result -> get();
  60. if ($toArray) {
  61. $result = $result -> toArray();
  62. }
  63. return $result;
  64. }
  65. /**
  66. * 用户消息条数
  67. *
  68. * @access public
  69. * @param mixed $where 查询条件
  70. * @param mixed $between 查询条件区间
  71. * @return array JsonString
  72. */
  73. public function accountNewsTotal($where, $between) {
  74. $result = $this;
  75. // 查询条件
  76. if (!empty($where)) {
  77. $result = $result -> where($where);
  78. }
  79. // 循环获取查询区间
  80. if (!empty($between)) {
  81. foreach ($between as $key => $value) {
  82. $result = $result -> whereBetween($key, $value);
  83. }
  84. }
  85. // 获取数据
  86. $result = $result -> count();
  87. return $result;
  88. }
  89. }