Money_buy_match.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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', function ($join) {
  28. $join->on('money_buy_match.odds_code', '=','st_odds_code.odds_code')->on('money_buy_match.game_code', '=','st_odds_code.game_code');
  29. });
  30. // 查询条件
  31. if (!empty($where)) {
  32. $result = $result -> where($where);
  33. }
  34. // 循环获取or查询
  35. if (!empty($orWhere)) {
  36. foreach ($orWhere as $value) {
  37. $result = $result -> where(function($query) use ($value) {
  38. foreach ($value as $k => $v) {
  39. if ($k == 0) {
  40. $query = $query -> where([$v[0] => $v[1]]);
  41. } else {
  42. $query = $query -> orWhere([$v[0] => $v[1]]);
  43. }
  44. }
  45. });
  46. }
  47. }
  48. // 查询起始
  49. if (strlen($begin)) {
  50. $result = $result -> offset($begin);
  51. }
  52. // 分页大小
  53. if (strlen($pageSize)) {
  54. $result = $result -> limit($pageSize);
  55. }
  56. // 循环排序规则
  57. foreach ($orderBy as $key => $value) {
  58. $result = $result -> orderBy($key, $value);
  59. }
  60. // 获取数据
  61. $result = $result -> get();
  62. return $result;
  63. }
  64. /**
  65. * 投注记录
  66. *
  67. * @access public
  68. * @param mixed $select 查询字段
  69. * @param mixed $where 查询条件
  70. * @param mixed $orWhere 关联关系 [[['batch_id', '191'], ['batch_id', '186']],[['id', '55'], ['id', '59']]];
  71. * @param mixed $begin 起始查询位置
  72. * @param mixed $pageSize 分页大小
  73. * @param mixed $orderBy 排序字段
  74. * @return array JsonString
  75. */
  76. public function moneyBuyMatchAll($select, $where = '', $orWhere = '', $begin = '', $pageSize = '', $orderBy = ['batch_id' => 'desc']) {
  77. // 查询字段
  78. $result = $this -> select($select);
  79. // 查询条件
  80. if (!empty($where)) {
  81. $result = $result -> where($where);
  82. }
  83. // 循环获取or查询
  84. if (!empty($orWhere)) {
  85. foreach ($orWhere as $value) {
  86. $result = $result -> where(function($query) use ($value) {
  87. foreach ($value as $k => $v) {
  88. if ($k == 0) {
  89. $query = $query -> where([$v[0] => $v[1]]);
  90. } else {
  91. $query = $query -> orWhere([$v[0] => $v[1]]);
  92. }
  93. }
  94. });
  95. }
  96. }
  97. // 查询起始
  98. if (strlen($begin)) {
  99. $result = $result -> offset($begin);
  100. }
  101. // 分页大小
  102. if (strlen($pageSize)) {
  103. $result = $result -> limit($pageSize);
  104. }
  105. // 循环排序规则
  106. foreach ($orderBy as $key => $value) {
  107. $result = $result -> orderBy($key, $value);
  108. }
  109. // 获取数据
  110. $result = $result -> get();
  111. return $result;
  112. }
  113. /**
  114. * 投注记录
  115. *
  116. * @access public
  117. * @param mixed $where 查询条件
  118. * @param mixed $orWhere 关联关系 [[['batch_id', '191'], ['batch_id', '186']],[['id', '55'], ['id', '59']]];
  119. * @return array JsonString
  120. */
  121. public function moneyBuyMatchTotal($where = '', $orWhere = '') {
  122. // 查询字段
  123. $result = $this;
  124. // 查询条件
  125. if (!empty($where)) {
  126. $result = $result -> where($where);
  127. }
  128. // 循环获取or查询
  129. if (!empty($orWhere)) {
  130. foreach ($orWhere as $value) {
  131. $result = $result -> where(function($query) use ($value) {
  132. foreach ($value as $k => $v) {
  133. if ($k == 0) {
  134. $query = $query -> where([$v[0] => $v[1]]);
  135. } else {
  136. $query = $query -> orWhere([$v[0] => $v[1]]);
  137. }
  138. }
  139. });
  140. }
  141. }
  142. // 获取数据
  143. $result = $result -> count();
  144. return $result;
  145. }
  146. public function getByDetail($Detailid){
  147. $ret = $this->where('money_buy_detail_id' ,$Detailid)->find();
  148. return $ret;
  149. }
  150. public function getByTypeMatch($type,$matchId){
  151. $rets = $this->where(['game_code'=>$type,'match_id'=>$matchId])->find();
  152. return $rets;
  153. }
  154. //查找某个订单下是否还有未处理完的订单情况
  155. public function FindByTypeOrderResult($type,$OrderId,$result=0){
  156. if (is_string($result)){
  157. $ret = $this->where(['game_code'=>$type,'order_id'=>$OrderId,'result'=>$result])->find();
  158. }else{
  159. $ret = $this->where(['game_code'=>$type,'order_id'=>$OrderId])->whereIn('result',$result)->find();
  160. }
  161. return $ret;
  162. }
  163. public function getByBatchId($batch_id){
  164. $ret = $this->where('batch_id',$batch_id)->find();
  165. return $ret;
  166. }
  167. }