Apply.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /**
  3. *
  4. * @copyright ©2020 点小铺
  5. * @author hanj
  6. * @link: https://dyuit.com
  7. * Created by VSCode
  8. */
  9. namespace app\common\model\dealer;
  10. use app\common\model\BaseModel;
  11. /**
  12. * 分销商申请模型
  13. * Class Apply
  14. * @package app\common\model\dealer
  15. */
  16. class Apply extends BaseModel
  17. {
  18. protected $name = 'dealer_apply';
  19. /**
  20. * 申请状态
  21. * @var array
  22. */
  23. public $applyStatus = [
  24. 10 => '待审核',
  25. 20 => '审核通过',
  26. 30 => '驳回',
  27. ];
  28. /**
  29. * 获取器:申请时间
  30. * @param $value
  31. * @return false|string
  32. */
  33. public function getApplyTimeAttr($value)
  34. {
  35. return date('Y-m-d H:i:s', $value);
  36. }
  37. /**
  38. * 获取器:审核时间
  39. * @param $value
  40. * @return false|string
  41. */
  42. public function getAuditTimeAttr($value)
  43. {
  44. return $value > 0 ? date('Y-m-d H:i:s', $value) : 0;
  45. }
  46. /**
  47. * 关联推荐人表
  48. * @return \think\model\relation\BelongsTo
  49. */
  50. public function referee()
  51. {
  52. return $this->belongsTo('app\common\model\User', 'referee_id')
  53. ->field(['user_id', 'nickName']);
  54. }
  55. /**
  56. * 销商申请记录详情
  57. * @param $where
  58. * @return Apply|static
  59. * @throws \think\exception\DbException
  60. */
  61. public static function detail($where)
  62. {
  63. return self::get($where);
  64. }
  65. /**
  66. * 购买指定商品成为分销商
  67. * @param $userId
  68. * @param $goodsIds
  69. * @param $wxappId
  70. * @return bool
  71. * @throws \think\exception\DbException
  72. */
  73. public function becomeDealerUser($userId, $goodsIds, $wxappId)
  74. {
  75. // 验证是否设置
  76. $config = Setting::getItem('condition', $wxappId);
  77. if ($config['become__buy_goods'] != '1' || empty($config['become__buy_goods_ids'])) {
  78. return false;
  79. }
  80. // 判断商品是否在设置范围内
  81. $intersect = array_intersect($goodsIds, $config['become__buy_goods_ids']);
  82. if (empty($intersect)) {
  83. return false;
  84. }
  85. // 新增分销商用户
  86. User::add($userId, [
  87. 'referee_id' => Referee::getRefereeUserId($userId, 1),
  88. 'wxapp_id' => $wxappId,
  89. ]);
  90. return true;
  91. }
  92. }