Oggame_transfer_record.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: ikeke
  5. * Date: 2018/12/4
  6. * Time: 18:24
  7. */
  8. namespace App\Models;
  9. class Oggame_transfer_record extends BaseModel
  10. {
  11. protected $table = "oggame_transfer_record";
  12. public $timestamps = false;
  13. /**
  14. * 获取所有游戏记录
  15. * @param string $where
  16. * @param int $limit
  17. * @return mixed
  18. */
  19. public function recordlist($where='',$limit=15)
  20. {
  21. $data = $this->orderBy('id','desc');
  22. if(is_array($where)&&count($where)>0){
  23. $data = $data->where($where);
  24. }
  25. $data=$data->paginate($limit);
  26. return $data->toArray();
  27. }
  28. /**
  29. * 插入数据
  30. * @param $data
  31. * @return int
  32. */
  33. public function insertRec($data)
  34. {
  35. $res = $this->insert($data);
  36. if(!$res)
  37. {
  38. return -1;
  39. }
  40. return 1;
  41. }
  42. /**
  43. * 更新转账状态
  44. */
  45. public function setTransferCredit($where='',$d)
  46. {
  47. $res = $this->where($where)->update($d);
  48. if(!$res)
  49. {
  50. return -1;
  51. }
  52. else
  53. {
  54. return 1;
  55. }
  56. }
  57. /**
  58. * 转账记录统计
  59. * @param $where
  60. * @return array
  61. */
  62. public function getSum($where)
  63. {
  64. $arr = array();
  65. if(is_array($where)&&count($where)>0)
  66. {
  67. //查询总投注金额
  68. $sum = $this->where($where)->sum('transfer_money');
  69. //查询转账数
  70. $count = $this->where($where)->count();
  71. //查询转账人数
  72. $person = $this->where($where)->select('local_user')->distinct()->get()->toArray();
  73. //查询余额转入到游戏总金额
  74. $in = $this->where($where)->where('transfer_type', 1)->sum('transfer_money');
  75. //查询游戏转出到余额总金额
  76. $out = $this->where($where)->where('transfer_type', 2)->sum('transfer_money');
  77. }
  78. $arr['total'] = $sum;
  79. $arr['count'] = $count;
  80. $arr['person'] = count($person);
  81. $arr['in'] = $in;
  82. $arr['out'] = $out;
  83. return $arr;
  84. }
  85. /**
  86. * 转账成功记录统计
  87. * @param $where
  88. * @return array
  89. */
  90. public function getSuccessSum($where, $gametype)
  91. {
  92. $arr = array();
  93. if(is_array($where)&&count($where)>0)
  94. {
  95. //成功转入笔数
  96. $arr['suc_in_sum'] = $this->where($where)->where('transfer_type', 1)->where('type', 1)->where('game_type', $gametype)->count();
  97. //成功转入总金额
  98. $arr['suc_in_money'] = $this->where($where)->where('transfer_type', 1)->where('type', 1)->where('game_type', $gametype)->sum('transfer_money');
  99. //成功转出笔数
  100. $arr['suc_out_sum'] = $this->where($where)->where('transfer_type', 2)->where('type', 1)->where('game_type', $gametype)->count();
  101. //成功转出总金额
  102. $arr['suc_out_money'] = $this->where($where)->where('transfer_type', 2)->where('type', 1)->where('game_type', $gametype)->sum('transfer_money');
  103. //成功总笔数
  104. $arr['suc_sum'] = $this->where($where)->where('type', 1)->where('game_type', $gametype)->count();
  105. //盈利金额
  106. $arr['profit_money'] = $arr['suc_in_money'] - $arr['suc_out_money'];
  107. }
  108. return $arr;
  109. }
  110. }