Money_buy_match.php 8.0 KB

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