Apply.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. namespace app\common\model\plus\agent;
  3. use app\common\model\BaseModel;
  4. /**
  5. * 分销商申请模型
  6. */
  7. class Apply extends BaseModel
  8. {
  9. protected $name = 'agent_apply';
  10. protected $pk = 'apply_id';
  11. /**
  12. * 申请状态
  13. * @var array
  14. */
  15. public $applyStatus = [
  16. 10 => '待审核',
  17. 20 => '审核通过',
  18. 30 => '驳回',
  19. ];
  20. /**
  21. * 申请时间
  22. * @param $value
  23. * @return false|string
  24. */
  25. public function getApplyTimeAttr($value)
  26. {
  27. return date('Y-m-d H:i:s', $value);
  28. }
  29. /**
  30. * 审核时间
  31. * @param $value
  32. * @return false|int|string
  33. */
  34. public function getAuditTimeAttr($value)
  35. {
  36. return $value > 0 ? date('Y-m-d H:i:s', $value) : 0;
  37. }
  38. /**
  39. * 关联推荐人表
  40. * @return \think\model\relation\BelongsTo
  41. */
  42. public function referee()
  43. {
  44. return $this->belongsTo('app\common\model\user\User', 'referee_id')
  45. ->field(['user_id', 'nickName']);
  46. }
  47. /**
  48. * 销商申请记录详情
  49. * @param $where
  50. * @return array|\think\Model|null
  51. * @throws \think\db\exception\DataNotFoundException
  52. * @throws \think\db\exception\DbException
  53. * @throws \think\db\exception\ModelNotFoundException
  54. */
  55. public static function detail($where)
  56. {
  57. $filter = is_array($where) ? $where : ['apply_id' => $where];
  58. return (new static())->where($filter)->find();
  59. }
  60. /**
  61. * 购买指定商品成为分销商
  62. * @param $userId
  63. * @param $productIds
  64. * @param $appId
  65. * @return bool
  66. */
  67. public function becomeAgentUser($userId, $productIds, $appId)
  68. {
  69. // 验证是否设置
  70. $config = Setting::getItem('condition', $appId);
  71. if ($config['become__buy_product'] != '1' || empty($config['become__buy_product_ids'])) {
  72. return false;
  73. }
  74. // 判断商品是否在设置范围内
  75. $intersect = array_intersect($productIds, $config['become__buy_product_ids']);
  76. if (empty($intersect)) {
  77. return false;
  78. }
  79. // 新增分销商用户
  80. User::add($userId, [
  81. 'referee_id' => Referee::getRefereeUserId($userId, 1),
  82. 'app_id' => $appId,
  83. ]);
  84. return true;
  85. }
  86. /**
  87. * 审核状态
  88. * @param $value
  89. * @return array
  90. */
  91. public function getApplyStatusAttr($value)
  92. {
  93. $method = [10 => '待审核', 20 => '审核通过', '30' => '驳回'];
  94. return ['text' => $method[$value], 'value' => $value];
  95. }
  96. /**
  97. * 审核方式
  98. * @param $value
  99. * @return array
  100. */
  101. public function getApplyTypeAttr($value)
  102. {
  103. $method = [10 => '后台审核', 20 => '无需审核'];
  104. return ['text' => $method[$value], 'value' => $value];
  105. }
  106. }