Money_buy_match.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 $where 查询条件
  67. * @param mixed $orWhere 关联关系 [[['batch_id', '191'], ['batch_id', '186']],[['id', '55'], ['id', '59']]];
  68. * @return array JsonString
  69. */
  70. public function moneyBuyMatchTotal($where = '', $orWhere = '') {
  71. // 查询字段
  72. $result = $this;
  73. // 查询条件
  74. if (!empty($where)) {
  75. $result = $result -> where($where);
  76. }
  77. // 循环获取or查询
  78. if (!empty($orWhere)) {
  79. foreach ($orWhere as $value) {
  80. $result = $result -> where(function($query) use ($value) {
  81. foreach ($value as $k => $v) {
  82. if ($k == 0) {
  83. $query = $query -> where([$v[0] => $v[1]]);
  84. } else {
  85. $query = $query -> orWhere([$v[0] => $v[1]]);
  86. }
  87. }
  88. });
  89. }
  90. }
  91. // 获取数据
  92. $result = $result -> count();
  93. return $result;
  94. }
  95. public function getByDetail($Detailid){
  96. $ret = $this->where('money_buy_detail_id' ,$Detailid)->find();
  97. return $ret;
  98. }
  99. public function getByTypeMatch($type,$matchId){
  100. $rets = $this->where(['game_code'=>$type,'match_id'=>$matchId])->find();
  101. return $rets;
  102. }
  103. //查找某个订单下是否还有未处理完的订单情况
  104. public function FindByTypeOrderResult($type,$OrderId,$result=0){
  105. if (is_string($result)){
  106. $ret = $this->where(['game_code'=>$type,'order_id'=>$OrderId,'result'=>$result])->find();
  107. }else{
  108. $ret = $this->where(['game_code'=>$type,'order_id'=>$OrderId])->whereIn('result',$result)->find();
  109. }
  110. return $ret;
  111. }
  112. public function getByBatchId($batch_id){
  113. $ret = $this->where('batch_id',$batch_id)->find();
  114. return $ret;
  115. }
  116. }