AgentLevelTask.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\model\agent;
  13. use crmeb\basic\BaseModel;
  14. use crmeb\traits\ModelTrait;
  15. use think\Model;
  16. /**
  17. * 分销员等级任务
  18. * Class AgentLevelTask
  19. * @package app\model\agent
  20. */
  21. class AgentLevelTask extends BaseModel
  22. {
  23. use ModelTrait;
  24. /**
  25. * 数据表主键
  26. * @var string
  27. */
  28. protected $pk = 'id';
  29. /**
  30. * 模型名称
  31. * @var string
  32. */
  33. protected $name = 'agent_level_task';
  34. /**
  35. * 关联分销员等级
  36. * @return \think\model\relation\HasOne
  37. */
  38. public function level()
  39. {
  40. return $this->hasOne(AgentLevel::class, 'id', 'level_id');
  41. }
  42. /**
  43. * 关联任务完成记录
  44. * @return \think\model\relation\HasMany
  45. */
  46. public function record()
  47. {
  48. return $this->hasMany(AgentLevelTaskRecord::class, 'task_id', 'id');
  49. }
  50. /**
  51. * 关键词搜索器
  52. * @param $query Model
  53. * @param $value
  54. */
  55. public function searchKeywordAttr($query, $value)
  56. {
  57. if ($value !== '') $query->where('id|name|desc', 'like', '%' . $value . '%');
  58. }
  59. /**
  60. * 任务类型搜索器
  61. * @param $query Model
  62. * @param $value
  63. */
  64. public function searchTypeAttr($query, $value)
  65. {
  66. if (is_array($value)) {
  67. $query->whereIn('type', $value);
  68. } else {
  69. if ($value !== '') $query->where('type', $value);
  70. }
  71. }
  72. /**
  73. * 分销员等级搜索器
  74. * @param $query Model
  75. * @param $value
  76. */
  77. public function searchLevelIdAttr($query, $value)
  78. {
  79. if (is_array($value)) {
  80. $query->whereIn('Level_id', $value);
  81. } else {
  82. if ($value !== '') $query->where('Level_id', $value);
  83. }
  84. }
  85. /**
  86. * 状态搜索器
  87. * @param $query Model
  88. * @param $value
  89. */
  90. public function searchStatusAttr($query, $value)
  91. {
  92. if ($value !== '') $query->where('status', $value);
  93. }
  94. /**
  95. * 是否删除搜索器
  96. * @param $query Model
  97. * @param $value
  98. */
  99. public function searchIsDelAttr($query, $value)
  100. {
  101. if ($value !== '') $query->where('is_del', $value);
  102. }
  103. }