NagentChild.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Support\Facades\DB;
  4. /**
  5. *
  6. */
  7. class NagentChild extends BaseModel {
  8. protected $table = 'nagent_child';
  9. public $timestamps = false;
  10. //获取下级信息
  11. function getChild($identity,$where,$list=50){
  12. // echo $status;
  13. // exit;
  14. // DB::connection()->enableQueryLog();
  15. $data=$this->rightJoin('account_detailed','account_detailed.account_identity',$this->table.'.account_identity')
  16. ->where('agent_identity',$identity);
  17. if(!empty($where)&&count($where)>0){
  18. $data->where($where);
  19. }
  20. $data=$data ->paginate($list);
  21. // $queries = DB::getQueryLog();
  22. // print_r($queries);
  23. // exit;
  24. if(!$data){
  25. return -8005444322;
  26. }
  27. return $data->toArray();
  28. }
  29. //获取代理信息
  30. //代理详情
  31. function getAgentChild($identity,$where,$list=50){
  32. $data=$this->rightJoin('nagent_detailed','nagent_detailed.nagent_detailed',$this->table.'.nagent_detailed')
  33. ->where('agent_identity',$identity);
  34. if(!empty($where)&&count($where)>0){
  35. $data->where($where);
  36. }
  37. $data=$data ->paginate($list);
  38. if(!$data){
  39. return -8005444322;
  40. }
  41. return $data->toArray();
  42. }
  43. //获取会员存取报表
  44. function getMoneyList($where){
  45. DB::connection()->enableQueryLog();
  46. $sql="SELECT SUM(money) as money,trade_type,money_type, agent_name,min(num) as num FROM money_details b
  47. RIGHT JOIN (
  48. SELECT a.agent_identity,num,a.account_identity,a.agent_name FROM nagent_child as a
  49. LEFT JOIN (
  50. SELECT agent_identity,COUNT(account_name) as num FROM nagent_child GROUP BY agent_identity
  51. ) as d on d.agent_identity=a.agent_identity
  52. ) c on c.account_identity=b.account_identity";
  53. if(!empty($where)){
  54. $sql.=$where;
  55. }
  56. $sql.=" GROUP BY b.trade_type,b.money_type,agent_name";
  57. $data=DB::select($sql);
  58. // $queries = DB::getQueryLog();
  59. // print_r($queries);
  60. if (!$data) {
  61. return -8020052003; //没有
  62. }
  63. $data = json_encode($data);
  64. $data = json_decode($data,1);
  65. return $data;
  66. }
  67. //获取会员下级会员
  68. function getChildStr($agent_name){
  69. $data=$this->select('account_name')->where('agent_name',$agent_name)->get();
  70. $arr='';
  71. if(!$data){
  72. return $arr;
  73. }
  74. $data=$data->toArray();
  75. foreach ($data as $v){
  76. $arr.=$v['account_name'].',';
  77. }
  78. return $arr;
  79. }
  80. //获取下级用户名数组
  81. function getChildArray($value,$num){
  82. $key=$this->getfild($num);
  83. $data=$this->select('account_name')->where($key,$value)->get();
  84. $arr=array();
  85. if(!$data){
  86. return $arr;
  87. }
  88. $data=$data->toArray();
  89. foreach ($data as $v){
  90. $arr[]=$v['account_name'];
  91. }
  92. return $arr;
  93. }
  94. //获取
  95. function getfild($num){
  96. $arr=array(
  97. '1'=>'agent_identity',
  98. '2'=>'agent_name',
  99. );
  100. return $arr[$num];
  101. }
  102. //获取代理id键对下级人数的数组
  103. function getChildSumArray($agent_identity_arr){
  104. $return_arr=array();
  105. $data=$this->select(DB::raw('count(id) as sum_child,agent_identity'))
  106. ->whereIn('agent_identity',$agent_identity_arr)
  107. ->groupBy('agent_identity')
  108. ->get();
  109. if(!$data){
  110. return $return_arr;
  111. }
  112. $data=$data->toArray();
  113. foreach ($data as $k=>$v){
  114. $return_arr[$v['agent_identity']]=$v['sum_child'];
  115. }
  116. return $return_arr;
  117. }
  118. }