Agent_detailed.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Support\Facades\DB;
  4. /**
  5. *
  6. */
  7. class Agent_detailed extends BaseModel {
  8. protected $table = 'agent_detailed';
  9. public $timestamps = false;
  10. /**
  11. * 代理列表数据
  12. * [agent description]
  13. * @param [type] $page [description]
  14. * @return [type] [description]
  15. */
  16. function agent($list,$page,$where='') {
  17. $data=$this->select('id', 'agent_user', 'grade', 'start_time', 'phone','bank_number', 'email', 'type', 'status','agent_identity', 'state','child_bet','child_profit','sum_child','ratio','money_total')
  18. ->orderBy('start_time', 'desc');
  19. if(!empty($where)&&is_array($where)){
  20. $data ->where($where);
  21. }
  22. $data=$data->paginate($list);
  23. if (!$data < 0) {
  24. return -2021026003; //没有代理用户
  25. }
  26. return $data->toArray();
  27. }
  28. //查找代理id
  29. function findId($data){
  30. $datas = $this->select('id','agent_identity')->whereIn('agent_identity',$data)->get();
  31. if (!$datas < 0) {
  32. return -2021026003; //没有代理用户
  33. }
  34. return $datas->toArray();
  35. }
  36. /**
  37. *代理审核
  38. * [agency description]
  39. * @param [type] $page [description]
  40. * @return [type] [description]
  41. */
  42. function agency($list,$page,$where='') {
  43. if(!empty($where)&&is_array($where)){
  44. $data = $this->select('id','agent_user', 'start_time', 'phone', 'email', 'status')
  45. ->orderBy('start_time', 'desc')
  46. ->where('status', 0)
  47. ->where($where)
  48. ->paginate($list);
  49. }else{
  50. $data = $this->select('id','agent_user', 'start_time', 'phone', 'email', 'status')
  51. ->orderBy('start_time', 'desc')
  52. ->where('status', 0)
  53. ->paginate($list);
  54. }
  55. if (!$data < 0) {
  56. return -2021026003; //没有代理用户
  57. }
  58. return $data->toArray();
  59. }
  60. //代理审批
  61. function passOrNo($id,$status){
  62. if($status==1){
  63. $res=$this->where('id',$id)->update(['status'=>$status,'grade'=>1]);
  64. }else{
  65. $res=$this->where('id',$id)->delete();
  66. }
  67. if(!$res){
  68. return -8005013322;
  69. }
  70. return 1;
  71. }
  72. //代理信息获取
  73. function agentInfo($id){
  74. $data=$this->where('id',$id)->first();
  75. if(!$data){
  76. return -8005014322;
  77. }
  78. return $data->toArray();
  79. }
  80. //代理信息更新
  81. function updateInfo($data,$id){
  82. $res=$this->where('id',$id)->update($data);
  83. if(!$res){
  84. return -8005034322;
  85. }
  86. return 1;
  87. }
  88. //获取代理
  89. function getInfo($val,$num){
  90. $fild=$this->getFild($num);
  91. $data=$this->where($fild,$val)->first();
  92. if(!$data){
  93. return -8005014322;
  94. }
  95. return $data->toArray();
  96. }
  97. //获取字段
  98. function getFild($num){
  99. //
  100. $data=array(
  101. '1'=>'id',
  102. '2'=>'agent_user',
  103. );
  104. return $data[$num];
  105. }
  106. //代理统计非六合彩
  107. function totalSum($time,$where){
  108. $sql="select agent_name,total_money,grade,total_money_profit from agent_detailed f
  109. INNER JOIN(SELECT agent_name,sum(money) as total_money,SUM(get_money) as total_money_profit
  110. FROM (
  111. SELECT SUM(money) as money,sum(get_money) as get_money,b.account_identity,min(c.agent_name) as agent_name FROM money_buy b
  112. RIGHT JOIN agent_child c on c.account_identity = b.account_identity and game_name != 'sixlottery'";
  113. // and game_name != 'sixlottery'
  114. if(!empty($time)){
  115. $sql.=''.$time;
  116. }
  117. $sql.="GROUP BY b.account_identity) as d GROUP BY d.agent_name) e ON e.agent_name=f.agent_user";
  118. if(!empty($where)){
  119. $sql.=' '.$where;
  120. }
  121. $data=DB::select($sql);
  122. if (!$data) {
  123. return -8020052003; //没有用户会员
  124. }
  125. $data = json_encode($data);
  126. $data = json_decode($data,1);
  127. return $data;
  128. }
  129. //代理统计六合彩
  130. function totalSumSix($time,$where){
  131. $sql="select agent_name,six_money,grade,six_money_profit from agent_detailed f
  132. INNER JOIN(SELECT agent_name,sum(money) as six_money,SUM(get_money) as six_money_profit
  133. FROM (
  134. SELECT SUM(money) as money,sum(get_money) as get_money,b.account_identity,min(c.agent_name) as agent_name FROM money_buy b
  135. RIGHT JOIN agent_child c on c.account_identity=b.account_identity WHERE game_name = 'sixlottery'";
  136. if(!empty($time)){
  137. $sql.=' '.$time;
  138. }
  139. $sql.=" GROUP BY b.account_identity) as d GROUP BY d.agent_name) e ON e.agent_name=f.agent_user";
  140. if(!empty($where)){
  141. $sql.=' '.$where;
  142. }
  143. $data=DB::select($sql);
  144. if (!$data) {
  145. return -8020052003; //没有
  146. }
  147. $data = json_encode($data);
  148. $data = json_decode($data,1);
  149. return $data;
  150. }
  151. protected function addMoneyCopy($agent_identity,$money){
  152. return $this->addMoney($agent_identity,$money);
  153. }
  154. //代理加钱
  155. function addMoney($agent_identity,$money){
  156. $res=$this->where('agent_identity',$agent_identity)->increment('money_total',$money);
  157. if(!$res){
  158. return -8005466322;
  159. }
  160. return 1;
  161. }
  162. //代理提成统计
  163. function sumMoney($time,$agent_name=''){
  164. $sql="select agent_name,money,get_money,grade from agent_detailed f
  165. INNER JOIN(SELECT agent_name,sum(money) as money,SUM(get_money) as get_money
  166. FROM (
  167. SELECT SUM(money) as money,sum(get_money) as get_money,b.account_identity,min(c.agent_name) as agent_name FROM money_buy b
  168. RIGHT JOIN agent_child c on c.account_identity=b.account_identity and settle_status = 1 and game_status <> 0 and status <> 4";
  169. if(!empty($time)){
  170. $sql.=$time;
  171. }
  172. // if(!empty($agent_name)){
  173. // $sql.=' and agent_name ='.$agent_name;
  174. // }
  175. $sql.=" GROUP BY b.account_identity) as d GROUP BY d.agent_name) e ON e.agent_name=f.agent_user";
  176. // echo $sql;die;
  177. $data=DB::select($sql);
  178. if (!$data) {
  179. return -8020052003; //没有
  180. }
  181. $data = json_encode($data);
  182. $data = json_decode($data,1);
  183. return $data;
  184. }
  185. }
  186. ?>