Account_detailed.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Capsule\Manager as DB;
  4. /**
  5. *
  6. * @property mixed account_identity
  7. */
  8. class Account_detailed extends BaseModel {
  9. protected $table = "account_detailed";
  10. public $timestamps = false;
  11. //由identity获取用户信息
  12. function getInfoBy($u_id) {
  13. $data = $this->where('account_identity', $u_id)->first();
  14. if (!$data) {
  15. return -5040012022;
  16. }
  17. return $data->toArray();
  18. }
  19. protected function getInfoBys($u_id){
  20. return $this->getInfoBy($u_id);
  21. }
  22. function getUinfo(){
  23. DB::connection()->enableQueryLog();
  24. $data = $this->select('account_identity')->whereNull('register_url')->limit(1000)->offset(0)->get();
  25. // $queries = DB::getQueryLog();
  26. // print_r($queries);
  27. if (!$data) {
  28. return -5040012022;
  29. }
  30. return $data->toArray();
  31. }
  32. function updateInfo($data, $uid) {
  33. $res = $this->where('account_identity', $uid)->update($data);
  34. if (!$res) {
  35. return -5040012022;
  36. }
  37. return 1;
  38. }
  39. function updateInfos($data, $id) {
  40. $res = $this->where('id', $id)->update($data);
  41. if (!$res) {
  42. return -7010101202; //更新失败
  43. }
  44. return 1;
  45. }
  46. function addMoney($account_id,$money){
  47. $res1=$this->where('account_identity',$account_id)->increment('available_cash',$money);
  48. if(!$res1){
  49. return -5040022022;//增加约失败
  50. }
  51. $res2=$this->where('account_identity',$account_id)->increment('cash',$money);
  52. if(!$res2){
  53. return -5040022022;//增加约失败
  54. }
  55. return 1;
  56. }
  57. function costMoney($account_id,$money){
  58. $res1=$this->where('account_identity',$account_id)->decrement('available_cash',$money);
  59. if(!$res1){
  60. return -5040022022;//增加约失败
  61. }
  62. $res2=$this->where('account_identity',$account_id)->decrement('cash',$money);
  63. if(!$res2){
  64. return -5040022022;//增加约失败
  65. }
  66. return 1;
  67. }
  68. //统计在线用户
  69. function getOnlineUser(){
  70. $time=time();
  71. $timeZone=[date('Y-m-d H:i:s',$time-300),date('Y-m-d H:i:s')];
  72. $data=$this->select(DB::Raw('count(id) as value,last_url as name'))
  73. ->where('statuss',1)->whereNotNull('last_url')
  74. //->whereBetween('last_time',$timeZone)
  75. ->groupBy('last_url')
  76. ->get();
  77. if(!$data){
  78. return -2020032103;
  79. }
  80. return $data->toArray();
  81. }
  82. function getCashArray($id_array){
  83. $data=$this->whereIn('account_identity',$id_array)->get();
  84. if(!$data){
  85. return -5040012522;
  86. }
  87. $data=$data->toArray();
  88. $account_cash_array=array();
  89. foreach ($data as $k=>$v){
  90. $account_cash_array[$v['account_identity']]=$v['cash'];
  91. }
  92. return $account_cash_array;
  93. }
  94. //在线
  95. function Accountas($where){
  96. if (!empty($where)){
  97. $data=$this->rightJoin('account','account.identity',$this->table.'.account_identity')
  98. ->where('account_detailed'.'.'.'statuss',$where);
  99. $data=$data ->paginate();
  100. }else{
  101. $data=$this->rightJoin('account','account.identity',$this->table.'.account_identity');
  102. $data=$data ->paginate();
  103. }
  104. if (!$data){
  105. return -502030154202;
  106. }
  107. return $data->toArray();
  108. }
  109. //改变会员标签至1
  110. protected function changeToleve($group_codes,$data){
  111. // DB::connection()->enableQueryLog();
  112. $res=$this->where('group_code','like',"%{$group_codes}%")->update($data);
  113. // $queries = DB::getQueryLog();
  114. // print_r($queries);exit;
  115. return 1;
  116. }
  117. }
  118. ?>