Agent.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace app\admin\model\shopro\commission;
  3. use app\admin\model\shopro\user\MoneyLog;
  4. use app\admin\model\shopro\user\ScoreLog;
  5. use addons\shopro\library\commission\Agent as AgentLibrary;
  6. use think\Model;
  7. use think\Db;
  8. class Agent extends Model
  9. {
  10. // 表名
  11. protected $name = 'shopro_commission_agent';
  12. // 自动写入时间戳字段
  13. protected $autoWriteTimestamp = 'int';
  14. // 定义时间戳字段名
  15. protected $createTime = 'createtime';
  16. protected $updateTime = 'updatetime';
  17. // 追加属性
  18. protected $append = [
  19. 'status_text',
  20. 'delay_money',
  21. 'level_status_text'
  22. ];
  23. public function getStatusTextAttr($value, $data)
  24. {
  25. $status_text = '';
  26. switch ($data['status']) {
  27. case AgentLibrary::AGENT_STATUS_NORMAL:
  28. $status_text = '正常';
  29. break;
  30. case AgentLibrary::AGENT_STATUS_PENDING:
  31. $status_text = '审核中';
  32. break;
  33. case AgentLibrary::AGENT_STATUS_FREEZE:
  34. $status_text = '冻结';
  35. break;
  36. case AgentLibrary::AGENT_STATUS_FORBIDDEN:
  37. $status_text = '禁用';
  38. break;
  39. case AgentLibrary::AGENT_STATUS_NEEDINFO:
  40. $status_text = '完善资料';
  41. break;
  42. case AgentLibrary::AGENT_STATUS_REJECT:
  43. $status_text = '审核驳回';
  44. break;
  45. }
  46. return $status_text;
  47. }
  48. // 获取分销商待入账佣金
  49. public function getDelayMoneyAttr($value, $data)
  50. {
  51. return number_format(Reward::waiting()->where('agent_id', $data['user_id'])->sum('commission'), 2, '.', '');
  52. }
  53. public function user()
  54. {
  55. return $this->belongsTo('\app\admin\model\shopro\user\User', 'user_id', 'id');
  56. }
  57. public function agentLevel()
  58. {
  59. return $this->belongsTo('\app\admin\model\shopro\commission\Level', 'level', 'level');
  60. }
  61. public function parentAgent()
  62. {
  63. return $this->belongsTo('\app\admin\model\shopro\user\User', 'parent_agent_id', 'id');
  64. }
  65. public function getChildAgentLevelAttr($value, $data){
  66. if(!empty($value)) {
  67. return json_decode($value, true);
  68. }
  69. return [];
  70. }
  71. public function setChildAgentLevelAttr($value, $data){
  72. return json_encode($value);
  73. }
  74. public function getChildAgentLevel_1Attr($value, $data){
  75. if(!empty($value)) {
  76. return json_decode($value, true);
  77. }
  78. return [];
  79. }
  80. public function setChildAgentLevel_1Attr($value, $data){
  81. return json_encode($value);
  82. }
  83. public function getLevelStatusTextAttr($value ,$data) {
  84. if($data['level_status'] != 0) {
  85. $text = Level::get($data['level_status']);
  86. if($text) {
  87. return $text->name;
  88. }
  89. }
  90. return '';
  91. }
  92. }