Money_buy_match.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <?php
  2. /**
  3. *------Create thems Model------
  4. *------SCWPHP Version 1.0.0------
  5. *------Dev Model Jions------
  6. *------Create Time 2017-06-13 18:45:24------
  7. */
  8. namespace App\Commons\Model;
  9. use \System\Model;
  10. class Money_buy_match extends Model {
  11. protected $table = 'money_buy_match';
  12. /**
  13. * 投注记录
  14. *
  15. * @access public
  16. * @param mixed $select 查询字段
  17. * @param mixed $where 查询条件
  18. * @param mixed $orWhere 关联关系 [[['batch_id', '191'], ['batch_id', '186']],[['id', '55'], ['id', '59']]];
  19. * @param mixed $begin 起始查询位置
  20. * @param mixed $pageSize 分页大小
  21. * @param mixed $orderBy 排序字段
  22. * @return array JsonString
  23. */
  24. public function moneyBuyMatch($select, $where = '', $orWhere = '', $begin = '', $pageSize = '', $orderBy = ['batch_id' => 'desc']) {
  25. // 查询字段
  26. $result = $this -> select($select)
  27. -> join('st_odds_code', 'money_buy_match.odds_code', 'st_odds_code.odds_code');
  28. // 查询条件
  29. if (!empty($where)) {
  30. $result = $result -> where($where);
  31. }
  32. // 循环获取or查询
  33. if (!empty($orWhere)) {
  34. foreach ($orWhere as $value) {
  35. $result = $result -> where(function($query) use ($value) {
  36. foreach ($value as $k => $v) {
  37. if ($k == 0) {
  38. $query = $query -> where([$v[0] => $v[1]]);
  39. } else {
  40. $query = $query -> orWhere([$v[0] => $v[1]]);
  41. }
  42. }
  43. });
  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. return $result;
  61. }
  62. /**
  63. * 投注记录
  64. *
  65. * @access public
  66. * @param mixed $select 查询字段
  67. * @param mixed $where 查询条件
  68. * @param mixed $orWhere 关联关系 [[['batch_id', '191'], ['batch_id', '186']],[['id', '55'], ['id', '59']]];
  69. * @param mixed $begin 起始查询位置
  70. * @param mixed $pageSize 分页大小
  71. * @param mixed $orderBy 排序字段
  72. * @return array JsonString
  73. */
  74. public function moneyBuyMatchAll($select, $where = '', $orWhere = '', $begin = '', $pageSize = '', $orderBy = ['batch_id' => 'desc']) {
  75. // 查询字段
  76. $result = $this -> select($select);
  77. // 查询条件
  78. if (!empty($where)) {
  79. $result = $result -> where($where);
  80. }
  81. // 循环获取or查询
  82. if (!empty($orWhere)) {
  83. foreach ($orWhere as $value) {
  84. $result = $result -> where(function($query) use ($value) {
  85. foreach ($value as $k => $v) {
  86. if ($k == 0) {
  87. $query = $query -> where([$v[0] => $v[1]]);
  88. } else {
  89. $query = $query -> orWhere([$v[0] => $v[1]]);
  90. }
  91. }
  92. });
  93. }
  94. }
  95. // 查询起始
  96. if (strlen($begin)) {
  97. $result = $result -> offset($begin);
  98. }
  99. // 分页大小
  100. if (strlen($pageSize)) {
  101. $result = $result -> limit($pageSize);
  102. }
  103. // 循环排序规则
  104. foreach ($orderBy as $key => $value) {
  105. $result = $result -> orderBy($key, $value);
  106. }
  107. // 获取数据
  108. $result = $result -> get();
  109. return $result;
  110. }
  111. /**
  112. * 投注记录
  113. *
  114. * @access public
  115. * @param mixed $where 查询条件
  116. * @param mixed $orWhere 关联关系 [[['batch_id', '191'], ['batch_id', '186']],[['id', '55'], ['id', '59']]];
  117. * @return array JsonString
  118. */
  119. public function moneyBuyMatchTotal($where = '', $orWhere = '') {
  120. // 查询字段
  121. $result = $this;
  122. // 查询条件
  123. if (!empty($where)) {
  124. $result = $result -> where($where);
  125. }
  126. // 循环获取or查询
  127. if (!empty($orWhere)) {
  128. foreach ($orWhere as $value) {
  129. $result = $result -> where(function($query) use ($value) {
  130. foreach ($value as $k => $v) {
  131. if ($k == 0) {
  132. $query = $query -> where([$v[0] => $v[1]]);
  133. } else {
  134. $query = $query -> orWhere([$v[0] => $v[1]]);
  135. }
  136. }
  137. });
  138. }
  139. }
  140. // 获取数据
  141. $result = $result -> count();
  142. return $result;
  143. }
  144. public function getByDetail($Detailid){
  145. $ret = $this->where('money_buy_detail_id' ,$Detailid)->find();
  146. return $ret;
  147. }
  148. public function getByTypeMatch($type,$matchId){
  149. $rets = $this->where(['game_code'=>$type,'match_id'=>$matchId])->find();
  150. return $rets;
  151. }
  152. //查找某个订单下是否还有未处理完的订单情况
  153. public function FindByTypeOrderResult($type,$OrderId,$result=0){
  154. if (is_string($result)){
  155. $ret = $this->where(['game_code'=>$type,'order_id'=>$OrderId,'result'=>$result])->find();
  156. }else{
  157. $ret = $this->where(['game_code'=>$type,'order_id'=>$OrderId])->whereIn('result',$result)->find();
  158. }
  159. return $ret;
  160. }
  161. public function getByBatchId($batch_id){
  162. $ret = $this->where('batch_id',$batch_id)->find();
  163. return $ret;
  164. }
  165. }