Money_record.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. *------Create thems Model------
  4. *------SCWPHP Version 1.0.0------
  5. *------Dev Model Jions------
  6. *------Create Time 2019-04-16 13:05:26------
  7. */
  8. namespace App\Commons\Model;
  9. use \System\Model;
  10. class Money_record extends Model {
  11. // 对象表
  12. protected $table = 'money_details';
  13. public $timestamps = false;
  14. /**
  15. * 盈亏记录
  16. *
  17. * @access public
  18. * @param mixed $moneyRecordSelect 查询参数
  19. * @param mixed $moneyRecordWhere 查询条件
  20. * @param mixed $moneyRecordBetween 查询条件区间
  21. * @param mixed $begin 起始查询位置
  22. * @param mixed $pageSize 分页大小
  23. * @param mixed $orderBy 排序字段
  24. * @return array JsonString
  25. */
  26. public function moneyRecord($moneyRecordSelect, $moneyRecordWhere, $moneyRecordBetween, $begin, $pageSize, $orderBy = 'money_time') {
  27. $result = $this
  28. -> select($moneyRecordSelect)
  29. -> where($moneyRecordWhere)
  30. -> whereBetween('money_time', $moneyRecordBetween)
  31. -> offset($begin)
  32. -> limit($pageSize)
  33. -> orderBy($orderBy)
  34. -> get();
  35. return $result;
  36. }
  37. /**
  38. * 盈亏记录总数
  39. *
  40. * @access public
  41. * @param mixed $moneyRecordWhere 查询条件
  42. * @param mixed $moneyRecordBetween 查询条件区间
  43. * @return array JsonString
  44. */
  45. public function moneyRecordTotal($moneyRecordWhere, $moneyRecordBetween) {
  46. $result = $this
  47. -> where($moneyRecordWhere)
  48. -> whereBetween('money_time', $moneyRecordBetween)
  49. -> count();
  50. return $result;
  51. }
  52. /**
  53. * 盈亏记录
  54. *
  55. * @access public
  56. * @param mixed $moneyRecordSelect 查询参数
  57. * @param mixed $moneyRecordWhere 查询条件
  58. * @param mixed $moneyRecordBetween 查询条件区间
  59. * @param mixed $orWhere or查询
  60. * @return array JsonString
  61. */
  62. public function moneyRecordAll($moneyRecordSelect, $moneyRecordWhere, $moneyRecordBetween, $orWhere=[]) {
  63. $result = $this
  64. -> select($moneyRecordSelect)
  65. -> where($moneyRecordWhere);
  66. if ($moneyRecordBetween) {
  67. $result = $result-> whereBetween('money_time', $moneyRecordBetween);
  68. }
  69. if ($orWhere) {
  70. // 循环获取or查询.
  71. foreach ($orWhere as $value) {
  72. $result = $result->where(
  73. function ($query) use ($value) {
  74. foreach ($value as $k => $v) {
  75. if ($k === 0) {
  76. $query = $query->where([$v[0] => $v[1]]);
  77. } else {
  78. $query = $query->orWhere([$v[0] => $v[1]]);
  79. }
  80. }
  81. }
  82. );
  83. }
  84. }
  85. $result = $result->get()->toArray();
  86. return $result;
  87. }
  88. }