AgentGrade.php 2.1 KB

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