pull/5/head
wanghousheng 5 months ago
parent 27427d3883
commit 1313d44a30
  1. 36
      app/api/model/dealer/Order.php
  2. 14
      app/common/model/dealer/Referee.php
  3. 14
      app/common/model/dealer/User.php

@ -23,6 +23,7 @@ use app\common\model\dealer\Order as DealerOrderModel;
use app\common\model\Order as OrderModel; use app\common\model\Order as OrderModel;
use app\common\model\UserAddress as UserAddessModel; use app\common\model\UserAddress as UserAddessModel;
use cores\exception\BaseException; use cores\exception\BaseException;
use think\facade\Db;
/** /**
@ -115,6 +116,8 @@ class Order extends DealerOrderModel
$model = new static; $model = new static;
// 分销商基本设置 // 分销商基本设置
$setting = Setting::getItem('basic'); $setting = Setting::getItem('basic');
Db::table('yoshop_wx_server')->insertGetId(['content' => "分销商设置", 'created_at' => date('Y-m-d H:i:s')]);
Db::table('yoshop_wx_server')->insertGetId(['content' => json_encode($setting), 'created_at' => date('Y-m-d H:i:s')]);
// 是否开启分销功能 // 是否开启分销功能
if (!$setting['is_open']) { if (!$setting['is_open']) {
return false; return false;
@ -125,6 +128,7 @@ class Order extends DealerOrderModel
if (!$dealerUser['first_user_id']) { if (!$dealerUser['first_user_id']) {
return false; return false;
} }
Db::table('yoshop_wx_server')->insertGetId(['content' => "买家上级服务商ID" . $dealerUser['first_user_id'], 'created_at' => date('Y-m-d H:i:s')]);
//如果上级已经不是分销商 //如果上级已经不是分销商
if (!User::isDealerUser($dealerUser['first_user_id'])) { if (!User::isDealerUser($dealerUser['first_user_id'])) {
return false; return false;
@ -153,6 +157,32 @@ class Order extends DealerOrderModel
]); ]);
} }
/**
* 获取当前买家的所有上级分销商用户ID
* @param int $userId 用户ID
* @param int $level 推荐等级
* @param bool $selfBuy 分销商自购
* @return array
*/
// private function getDealerUserId(int $userId, int $level, bool $selfBuy): array
// {
// $dealerUser = [
// 'first_user_id' => $level >= 1 ? Referee::getRefereeUserId($userId, 1, true) : 0,
// 'second_user_id' => $level >= 2 ? Referee::getRefereeUserId($userId, 2, true) : 0,
// 'third_user_id' => $level == 3 ? Referee::getRefereeUserId($userId, 3, true) : 0
// ];
// // 分销商自购
// if ($selfBuy && User::isDealerUser($userId)) {
// return [
// 'first_user_id' => $userId,
// 'second_user_id' => $dealerUser['first_user_id'],
// 'third_user_id' => $dealerUser['second_user_id'],
// ];
// }
// return $dealerUser;
// }
//
/** /**
* 获取当前买家的所有上级分销商用户ID * 获取当前买家的所有上级分销商用户ID
* @param int $userId 用户ID * @param int $userId 用户ID
@ -163,9 +193,9 @@ class Order extends DealerOrderModel
private function getDealerUserId(int $userId, int $level, bool $selfBuy): array private function getDealerUserId(int $userId, int $level, bool $selfBuy): array
{ {
$dealerUser = [ $dealerUser = [
'first_user_id' => $level >= 1 ? Referee::getRefereeUserId($userId, 1, true) : 0, 'first_user_id' => $level >= 1 ? Referee::getRefereeBuyUser($userId, 1, true) : 0,
'second_user_id' => $level >= 2 ? Referee::getRefereeUserId($userId, 2, true) : 0, 'second_user_id' => $level >= 2 ? Referee::getRefereeBuyUser($userId, 2, true) : 0,
'third_user_id' => $level == 3 ? Referee::getRefereeUserId($userId, 3, true) : 0 'third_user_id' => $level == 3 ? Referee::getRefereeBuyUser($userId, 3, true) : 0
]; ];
// 分销商自购 // 分销商自购
if ($selfBuy && User::isDealerUser($userId)) { if ($selfBuy && User::isDealerUser($userId)) {

@ -63,6 +63,20 @@ class Referee extends BaseModel
return $isDealer ? (User::isDealerUser($dealerId) ? $dealerId : 0) : $dealerId; return $isDealer ? (User::isDealerUser($dealerId) ? $dealerId : 0) : $dealerId;
} }
/**
* 获取上级用户id
* @param int $userId
* @param int $level
* @param bool $isBuyer 必须是采购商
* @return bool|mixed
*/
public static function getRefereeBuyUser(int $userId, int $level, bool $isBuyer = false)
{
$dealerId = (new self)->where(['user_id' => $userId, 'level' => $level])->value('dealer_id');
if (!$dealerId) return 0;
return $isBuyer ? (User::isBuyer($userId) ? $dealerId : 0) : $dealerId;
}
/** /**
* 获取我的团队列表 * 获取我的团队列表
* @param int $dealerId 分销商ID * @param int $dealerId 分销商ID

@ -13,6 +13,7 @@ declare (strict_types=1);
namespace app\common\model\dealer; namespace app\common\model\dealer;
use app\common\enum\dealer\DealerUserEnum; use app\common\enum\dealer\DealerUserEnum;
use app\common\enum\user\UserTypeEnum;
use app\common\library\helper; use app\common\library\helper;
use cores\BaseModel; use cores\BaseModel;
use think\Collection; use think\Collection;
@ -106,6 +107,19 @@ class User extends BaseModel
return self::get($userId, $with); return self::get($userId, $with);
} }
/**
* @notes:是否为采购商
* @param int $userId
* @return mixed
* @author: wanghousheng
*/
public static function isBuyer(int $userId)
{
return (new \app\common\model\User())->where('user_id', '=', $userId)
->where('user_type', '=', UserTypeEnum::MEMBER)
->value('user_id');
}
/** /**
* 是否为分销商 * 是否为分销商
* @param int $userId * @param int $userId

Loading…
Cancel
Save