Money_buy_str.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. /**
  3. *------Create thems Model------
  4. *------SCWPHP Version 1.0.0------
  5. *------Dev Model Jions------
  6. *------Create Time 2019-04-15 16:05:26------
  7. */
  8. namespace App\Commons\Model;
  9. use \System\Model;
  10. class Money_buy_str extends Model {
  11. // 对象表
  12. protected $table = 'money_buy_str';
  13. public $timestamps = false;
  14. /**
  15. * 投注记录
  16. *
  17. * @access public
  18. * @param mixed $select 查询字段
  19. * @param mixed $where 查询条件
  20. * @param mixed $between 查询条件区间 ['money_time' => [$startTime, $endTime], ...]
  21. * @param mixed $begin 起始查询位置
  22. * @param mixed $pageSize 分页大小
  23. * @param mixed $toArray 是否专为数组
  24. * @param mixed $orderBy 排序字段
  25. * @param mixed $join 关联关系 ['article' => 'oney_buy.info_identity = article.identity', ...]
  26. * @return array JsonString
  27. */
  28. public function moneyBuyStr($select, $where = '', $between = '', $begin = '', $pageSize = '', $toArray = 0, $orderBy = ['money_time' => 'desc'], $join = '') {
  29. // 查询字段
  30. $result = $this -> select($select);
  31. // 循环关联
  32. if (!empty($join)) {
  33. foreach ($join as $key => $value) {
  34. $result = $result -> join($key, $value);
  35. }
  36. }
  37. // 查询条件
  38. if (!empty($where)) {
  39. $result = $result -> where($where);
  40. }
  41. // 循环获取查询区间
  42. if (!empty($between)) {
  43. foreach ($between as $key => $value) {
  44. $result = $result -> whereBetween($key, $value);
  45. }
  46. }
  47. // 查询起始
  48. if (strlen($begin)) {
  49. $result = $result -> offset($begin);
  50. }
  51. // 分页大小
  52. if (strlen($pageSize)) {
  53. $result = $result -> limit($pageSize);
  54. }
  55. // 循环排序规则
  56. foreach ($orderBy as $key => $value) {
  57. $result = $result -> orderBy($key, $value);
  58. }
  59. // 获取数据
  60. $result = $result -> get();
  61. if ($toArray) {
  62. $result = $result -> toArray();
  63. }
  64. return $result;
  65. }
  66. /**
  67. * 投注记录总数
  68. *
  69. * @access public
  70. * @param mixed $where 查询条件
  71. * @param mixed $between 查询条件区间
  72. * @return array JsonString
  73. */
  74. public function moneyBuyStrTotal($where, $between) {
  75. $result = $this;
  76. // 查询条件
  77. if (!empty($where)) {
  78. $result = $result -> where($where);
  79. }
  80. // 循环获取查询区间
  81. if (!empty($between)) {
  82. foreach ($between as $key => $value) {
  83. $result = $result -> whereBetween($key, $value);
  84. }
  85. }
  86. // 获取数据
  87. $result = $result -> count();
  88. return $result;
  89. }
  90. /**
  91. * 投注记录联合查询
  92. *
  93. * @access public
  94. * @param mixed $select 查询字段
  95. * @param mixed $moneyBuyWhere 查询条件
  96. * @param mixed $orderBy 排序字段
  97. * @return array JsonString
  98. */
  99. public function moneyBuyStrUnion($select, $moneyBuyWhere, $orderBy = 'money_time') {
  100. if (empty($moneyBuyWhere)) {
  101. return;
  102. }
  103. $count = count($moneyBuyWhere);
  104. $result = [];
  105. $unionAll = [];
  106. foreach ($moneyBuyWhere as $key => $value) {
  107. if ($key === 0) {
  108. $unionAll[0] = $this
  109. -> select($select)
  110. -> join('st_bet_str','money_buy_str.bet_str_id','=','st_bet_str.id')
  111. -> where(['order_id' => $value]);
  112. } elseif ($key + 1 === $count) {
  113. $result = $this
  114. -> select($select)
  115. -> join('st_bet_str','money_buy_str.bet_str_id','=','st_bet_str.id')
  116. -> where(['order_id' => $value])
  117. -> unionAll($unionAll[$key - 1])
  118. -> orderBy($orderBy)
  119. -> get();
  120. } else {
  121. $unionAll[$key] = $this
  122. -> select($select)
  123. -> join('st_bet_str','money_buy_str.bet_str_id','=','st_bet_str.id')
  124. -> unionAll($unionAll[$key - 1])
  125. -> where(['order_id' => $value]);
  126. }
  127. }
  128. return $result;
  129. }
  130. /**
  131. *
  132. * @access public
  133. * @param mixed $batch_id 批次ID
  134. * @return array JsonString
  135. *
  136. * */
  137. public function getByBatchId($batch_id){
  138. $result = $this->where(['batch_id',$batch_id])->get();
  139. return $result ;
  140. }
  141. }