NagentGrade.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. namespace App\Models;
  3. use DB;
  4. /**
  5. *
  6. */
  7. class NagentGrade extends BaseModel {
  8. protected $table = 'nagent_grade';
  9. public $timestamps = false;
  10. //获取等级列表信息
  11. function getList($where='',$list=10){
  12. //DB::connection()->enableQueryLog();
  13. $data=$this;
  14. if(!empty($where) && count($where)){
  15. $data = $data->where($where);
  16. }
  17. $data=$data->orderBy('sort','desc')->paginate($list);
  18. if(!$data){
  19. return -8040411022;//没有数据
  20. }
  21. return $data->toArray();
  22. }
  23. //获取代理金额设置
  24. function getRatio(){
  25. $data=$this->get();
  26. if(!$data){
  27. return -8005144322;
  28. }
  29. return $data->toArray();
  30. }
  31. //更新比例
  32. function updateRatio($data,$id){
  33. $res=$this->where('id',$id)->update($data);
  34. if(!$res){
  35. return -8005344322;
  36. }
  37. return 1;
  38. }
  39. //获取全部等级列表
  40. function getAllGrade($where=''){
  41. $data=$this;
  42. if(!empty($where) && count($where)){
  43. $data->where($where);
  44. }
  45. $data=$data->orderBy('grade_code','asc')->get();
  46. if(!$data){
  47. return -8040411022;//没有数据
  48. }
  49. return $data->toArray();
  50. }
  51. //获取代理默认提成比例
  52. protected function getGradeRatio($money){
  53. //DB::connection()->enableQueryLog();
  54. $ratio=$this->select('water_ratio','profit_ratio')->where('first_amount','<',$money)->orderBy('first_amount','desc')->first();
  55. //$queries = DB::getQueryLog();
  56. //print_r($queries);
  57. if(!$ratio){
  58. return -8060010022;//没有默认提成比例
  59. }
  60. $ratio=$ratio->toArray();
  61. //没有修改内容
  62. return $ratio;
  63. /*if($type==1){
  64. return $ratio['profit_ratio'];
  65. }else{
  66. return $ratio['water_ratio'];
  67. }*/
  68. }
  69. //获取代理提成比例
  70. protected function getGrades(){
  71. $grades = \App\Models\NagentGrade::select('grade_name','grade_code','water_ratio','first_amount')->orderBy('first_amount','desc')->get();
  72. $grades = !$grades?array():$grades->toArray();
  73. return $grades;
  74. }
  75. //获取代理对应额度等级
  76. protected function getGradeBymoney($money,$grade){
  77. foreach ($grade as $k => $v) {
  78. if($money>=$v['first_amount'])return $v;
  79. }
  80. return $v;
  81. }
  82. //代理名称获取
  83. function getGradeInfo($value,$num){
  84. $fild=$this->getFild($num);
  85. $data=$this->where($fild,$value)->first();
  86. if(!$data){
  87. return -8040411022;//没有数据
  88. }
  89. return $data->toArray();
  90. }
  91. //获取字段
  92. function getFild($num){
  93. $fild=array(
  94. '1'=>'id',
  95. '2'=>'grade_name',
  96. '3'=>'grade_code',
  97. );
  98. return $fild[$num];
  99. }
  100. }