Money_buy_simplex.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. use Illuminate\Support\Facades\DB;
  11. use DB as DD;
  12. class Money_buy_simplex extends Model {
  13. // 对象表
  14. protected $table = 'money_buy_simplex';
  15. public $timestamps = false;
  16. /**
  17. * 投注记录
  18. *
  19. * @access public
  20. * @param mixed $select 查询字段
  21. * @param mixed $where 查询条件
  22. * @param mixed $between 查询条件区间 ['money_time' => [$startTime, $endTime], ...]
  23. * @param mixed $begin 起始查询位置
  24. * @param mixed $pageSize 分页大小
  25. * @param mixed $toArray 是否专为数组
  26. * @param mixed $orderBy 排序字段
  27. * @param mixed $join 关联关系 ['article' => 'oney_buy.info_identity = article.identity', ...]
  28. * @return array JsonString
  29. */
  30. public function moneyBuySimplex($select, $where = '', $between = '', $begin = '', $pageSize = '', $toArray = 0, $orderBy = ['money_time' => 'desc'], $join = '') {
  31. // 查询字段
  32. $result = $this -> select($select);
  33. // 循环关联
  34. if (!empty($join)) {
  35. foreach ($join as $key => $value) {
  36. $result = $result -> join($key, $value);
  37. }
  38. }
  39. // 查询条件
  40. if (!empty($where)) {
  41. $result = $result -> where($where);
  42. }
  43. // 循环获取查询区间
  44. if (!empty($between)) {
  45. foreach ($between as $key => $value) {
  46. $result = $result -> whereBetween($key, $value);
  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. if ($toArray) {
  64. $result = $result -> toArray();
  65. }
  66. return $result;
  67. }
  68. /**
  69. * 盈亏记录
  70. *
  71. * @access public
  72. * @param mixed $select 查询字段
  73. * @param mixed $where 查询条件
  74. * @param mixed $between 查询条件区间 ['money_time' => [$startTime, $endTime], ...]
  75. * @param mixed $begin 起始查询位置
  76. * @param mixed $pageSize 分页大小
  77. * @param mixed $toArray 是否专为数组
  78. * @param mixed $orderBy 排序字段
  79. * @param mixed $join 关联关系 ['article' => 'oney_buy.info_identity = article.identity', ...]
  80. * @return array JsonString
  81. */
  82. public function winLoseRecord($where, $between, $begin = '', $pageSize = '') {
  83. $select = ['money_time', 'gain_money', 'money', 'order_id'];
  84. $mnyBuyStrMdl = lm('Money_buy_str', "commons");
  85. $mnyBuyStrSql = $mnyBuyStrMdl->select($select)->where($where)->whereBetween('money_time', $between);
  86. $mnyBuySpxSql = $this
  87. ->select($select)
  88. ->where($where)
  89. ->whereBetween('money_time', $between)
  90. ->unionAll($mnyBuyStrSql)
  91. ->offset($begin)
  92. ->limit($pageSize)
  93. ->orderBy('money_time','DESC')
  94. ->get();
  95. foreach ($mnyBuySpxSql as $key => $value) {
  96. if ($value->gain_money >= $value->money) {
  97. $mnyBuySpxSql[$key]->money_type = 1;
  98. $mnyBuySpxSql[$key]->money = $value->gain_money - $value->money;
  99. } else {
  100. $mnyBuySpxSql[$key]->money = $value->money - $value->gain_money;
  101. }
  102. }
  103. return $mnyBuySpxSql;
  104. }
  105. /**
  106. * 盈亏总数
  107. *
  108. * @access public
  109. * @param mixed $select 查询字段
  110. * @param mixed $where 查询条件
  111. * @param mixed $between 查询条件区间 ['money_time' => [$startTime, $endTime], ...]
  112. * @param mixed $begin 起始查询位置
  113. * @param mixed $pageSize 分页大小
  114. * @param mixed $toArray 是否专为数组
  115. * @param mixed $orderBy 排序字段
  116. * @param mixed $join 关联关系 ['article' => 'oney_buy.info_identity = article.identity', ...]
  117. * @return array JsonString
  118. */
  119. public function winLoseCount($where, $between) {
  120. $select = ['order_id'];
  121. $mnyBuyStrMdl = lm('Money_buy_str', "commons");
  122. $mnyBuyStrSql = $mnyBuyStrMdl->select($select)->where($where)->whereBetween('money_time', $between);
  123. $mnyBuySpxSql = $this
  124. ->select($select)
  125. ->where($where)
  126. ->whereBetween('money_time', $between)
  127. ->unionAll($mnyBuyStrSql)
  128. ->get();
  129. return count($mnyBuySpxSql);
  130. }
  131. }