add 用户推广分润
This commit is contained in:
parent
ce8ad27cda
commit
ad57a58001
|
@ -3,6 +3,7 @@
|
||||||
namespace app\api\controller;
|
namespace app\api\controller;
|
||||||
|
|
||||||
use app\adminapi\logic\user\UserLogic;
|
use app\adminapi\logic\user\UserLogic;
|
||||||
|
use app\common\logic\ShopRequestLogic;
|
||||||
use think\exception\ValidateException;
|
use think\exception\ValidateException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -11,7 +12,7 @@ use think\exception\ValidateException;
|
||||||
class ShopCallController extends BaseApiController
|
class ShopCallController extends BaseApiController
|
||||||
{
|
{
|
||||||
public array $notNeedLogin = ['user_first_order_share_profit', 'user_order_share_profit'];
|
public array $notNeedLogin = ['user_first_order_share_profit', 'user_order_share_profit'];
|
||||||
|
public string $apiSecret = '';
|
||||||
|
|
||||||
public function initialize()
|
public function initialize()
|
||||||
{
|
{
|
||||||
|
@ -30,14 +31,16 @@ class ShopCallController extends BaseApiController
|
||||||
}
|
}
|
||||||
$timestamp = $params['timestamp'];
|
$timestamp = $params['timestamp'];
|
||||||
$iv = substr(md5($this->apiSecret.$timestamp), 5, 16);
|
$iv = substr(md5($this->apiSecret.$timestamp), 5, 16);
|
||||||
$secretData = encrypt($params['data'], $this->apiSecret, $iv);
|
// $secretData = encrypt($params['data'], $this->apiSecret, $iv); halt($secretData);
|
||||||
$requestDatas = decrypt($secretData, $this->apiSecret, $iv);
|
$requestDatas = decrypt($params['data'], $this->apiSecret, $iv);
|
||||||
|
|
||||||
if (null === $requestDatas) {
|
if (null === $requestDatas) {
|
||||||
return $this->fail('非法访问,解析失败');
|
return $this->fail('非法访问,解析失败');
|
||||||
}
|
}
|
||||||
$inviteCode = $requestDatas['promotion_code']; // 推广码
|
$inviteCode = $requestDatas['promotion_code']; // 推广码
|
||||||
$orderMoney= $requestDatas['order_money']; // 订单金额
|
$orderMoney= $requestDatas['order_money']; // 订单金额
|
||||||
$orderNo = $requestDatas['order_no']; // 订单金额
|
$orderNo = $requestDatas['order_no']; // 订单金额
|
||||||
|
$orderId = $requestDatas['order_id']; // 订单id
|
||||||
|
|
||||||
// 推广人
|
// 推广人
|
||||||
$userSelf = UserLogic::getUserByInviteCode($inviteCode);
|
$userSelf = UserLogic::getUserByInviteCode($inviteCode);
|
||||||
|
@ -45,9 +48,7 @@ class ShopCallController extends BaseApiController
|
||||||
return $this->fail('推广人不存在');
|
return $this->fail('推广人不存在');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 推广人用户角色
|
// 推广人角色 - 小队/小区队长
|
||||||
|
|
||||||
// 小队/小区队长
|
|
||||||
if (in_array($userSelf['group_id'] , [2, 18])) {
|
if (in_array($userSelf['group_id'] , [2, 18])) {
|
||||||
|
|
||||||
//村/社区合伙人
|
//村/社区合伙人
|
||||||
|
@ -64,11 +65,18 @@ class ShopCallController extends BaseApiController
|
||||||
// 首单金额记录
|
// 首单金额记录
|
||||||
UserLogic::firstOrderLog([$userSelf['id'], $villageUser['id'], $streetUser['id']], $orderMoney, $orderNo);
|
UserLogic::firstOrderLog([$userSelf['id'], $villageUser['id'], $streetUser['id']], $orderMoney, $orderNo);
|
||||||
|
|
||||||
return $this->success('成功', [
|
$request['user'] = [
|
||||||
['user_id' => $userSelf['id'], 'account' => $userSelf['account'], 'user_profit' => bcmul($orderMoney, 0.03, 2)],
|
['type' => 1, 'account' => $userSelf['account'], 'user_profit' => bcmul($orderMoney, 0.03, 2)],
|
||||||
['user_id' => $villageUser['id'], 'account' => $villageUser['account'], 'user_profit' => bcmul($orderMoney, 0.03, 2)],
|
['type' => 2, 'account' => $villageUser['account'], 'user_profit' => bcmul($orderMoney, 0.03, 2)],
|
||||||
['user_id' => $streetUser['id'], 'account' => $streetUser['account'], 'user_profit' => bcmul($orderMoney, 0.01, 2)],
|
['type' => 3, 'account' => $streetUser['account'], 'user_profit' => bcmul($orderMoney, 0.01, 2)],
|
||||||
]);
|
];
|
||||||
|
$request['order_id'] = $orderId;
|
||||||
|
$timestamp = time();
|
||||||
|
$iv1 = substr(md5($this->apiSecret.$timestamp), 5, 16);
|
||||||
|
$encryptStr = encrypt($request, $this->apiSecret, $iv1);
|
||||||
|
|
||||||
|
// 通知商城
|
||||||
|
$res = ShopRequestLogic::userProfitNotice(['data' => $encryptStr, 'timestamp' => $timestamp]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 村/社区合伙人
|
// 村/社区合伙人
|
||||||
|
@ -87,11 +95,18 @@ class ShopCallController extends BaseApiController
|
||||||
// 首单金额记录
|
// 首单金额记录
|
||||||
UserLogic::firstOrderLog([$userSelf['id'], $bridgeUser['id'], $streetUser['id']], $orderMoney, $orderNo);
|
UserLogic::firstOrderLog([$userSelf['id'], $bridgeUser['id'], $streetUser['id']], $orderMoney, $orderNo);
|
||||||
|
|
||||||
return $this->success('成功', [
|
$request['user'] = [
|
||||||
['user_id' => $bridgeUser['id'], 'account' => $bridgeUser['account'], 'user_profit' => bcmul($orderMoney, 0.03, 2)],
|
['type' => 1, 'account' => $bridgeUser['account'], 'user_profit' => bcmul($orderMoney, 0.03, 2)],
|
||||||
['user_id' => $userSelf['id'], 'account' => $userSelf['account'], 'user_profit' => bcmul($orderMoney, 0.03, 2)],
|
['type' => 2, 'account' => $userSelf['account'], 'user_profit' => bcmul($orderMoney, 0.03, 2)],
|
||||||
['user_id' => $streetUser['id'], 'account' => $streetUser['account'], 'user_profit' => bcmul($orderMoney, 0.01, 2)],
|
['type' => 3, 'account' => $streetUser['account'], 'user_profit' => bcmul($orderMoney, 0.01, 2)],
|
||||||
]);
|
];
|
||||||
|
$request['order_id'] = $orderId;
|
||||||
|
$timestamp = time();
|
||||||
|
$iv1 = substr(md5($this->apiSecret.$timestamp), 5, 16);
|
||||||
|
$encryptStr = encrypt($request, $this->apiSecret, $iv1);
|
||||||
|
|
||||||
|
// 通知商城
|
||||||
|
$res = ShopRequestLogic::userProfitNotice(['data' => $encryptStr, 'timestamp' => $timestamp]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 镇/街道合伙人
|
// 镇/街道合伙人
|
||||||
|
@ -110,12 +125,22 @@ class ShopCallController extends BaseApiController
|
||||||
// 首单金额记录
|
// 首单金额记录
|
||||||
UserLogic::firstOrderLog([$userSelf['id'], $villageUser['id'], $userSelf['id']], $orderMoney, $orderNo);
|
UserLogic::firstOrderLog([$userSelf['id'], $villageUser['id'], $userSelf['id']], $orderMoney, $orderNo);
|
||||||
|
|
||||||
return $this->success('成功', [
|
$request['user'] = [
|
||||||
['user_id' => $bridgeUser['id'], 'account' => $bridgeUser['account'], 'user_profit' => bcmul($orderMoney, 0.03, 2)],
|
['type' => 1, 'account' => $bridgeUser['account'], 'user_profit' => bcmul($orderMoney, 0.03, 2)],
|
||||||
['user_id' => $villageUser['id'], 'account' => $villageUser['account'], 'user_profit' => bcmul($orderMoney, 0.03, 2)],
|
['type' => 2, 'account' => $villageUser['account'], 'user_profit' => bcmul($orderMoney, 0.03, 2)],
|
||||||
['user_id' => $userSelf['id'], 'account' => $userSelf['account'], 'user_profit' => bcmul($orderMoney, 0.01, 2)],
|
['type' => 3, 'account' => $userSelf['account'], 'user_profit' => bcmul($orderMoney, 0.01, 2)],
|
||||||
]);
|
];
|
||||||
|
$request['order_id'] = $orderId;
|
||||||
|
$timestamp = time();
|
||||||
|
$iv1 = substr(md5($this->apiSecret.$timestamp), 5, 16);
|
||||||
|
$encryptStr = encrypt($request, $this->apiSecret, $iv1);
|
||||||
|
|
||||||
|
// 通知商城
|
||||||
|
$res = ShopRequestLogic::userProfitNotice(['data' => $encryptStr, 'timestamp' => $timestamp]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return $this->success('成功');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -127,47 +152,36 @@ class ShopCallController extends BaseApiController
|
||||||
$params = $this->request->param();
|
$params = $this->request->param();
|
||||||
$timestamp = $params['timestamp'];
|
$timestamp = $params['timestamp'];
|
||||||
$iv = substr(md5($this->apiSecret.$timestamp), 5, 16);
|
$iv = substr(md5($this->apiSecret.$timestamp), 5, 16);
|
||||||
$secretData = encrypt($params['data'], $this->apiSecret, $iv);
|
$requestDatas = decrypt($params['data'], $this->apiSecret, $iv);
|
||||||
$requestDatas = decrypt($secretData, $this->apiSecret, $iv);
|
|
||||||
if (null === $requestDatas) {
|
if (null === $requestDatas) {
|
||||||
return $this->fail('非法访问,解析失败');
|
return $this->fail('非法访问,解析失败');
|
||||||
}
|
}
|
||||||
$inviteCode = $requestDatas['promotion_code']; // 推广码
|
$streetCode = $requestDatas['street_code']; // 镇街地区码
|
||||||
$orderMoney = $requestDatas['order_money']; // 订单金额 分
|
$orderMoney = $requestDatas['order_money']; // 订单金额 分
|
||||||
$orderNo = $requestDatas['order_no']; // 订单金额
|
$orderNo = $requestDatas['order_no']; // 订单金额
|
||||||
|
$orderId = $requestDatas['order_id']; // 订单id
|
||||||
|
|
||||||
// 推广人
|
// 镇合伙人
|
||||||
$userSelf = UserLogic::getUserByInviteCode($inviteCode);
|
$userSelf = UserLogic::getUser(['street'=>$streetCode, 'group_id'=>15]);
|
||||||
if (empty($userSelf)) {
|
if (empty($userSelf)) {
|
||||||
return $this->fail('推广人不存在');
|
return $this->fail('镇合伙人不存在');
|
||||||
}
|
}
|
||||||
|
|
||||||
$proportion = 0.01; // 比例
|
$proportion = 0.01; // 比例
|
||||||
|
|
||||||
// 镇/街道合伙人
|
|
||||||
if ($userSelf['group_id'] == 15) {
|
|
||||||
// 计算分润
|
// 计算分润
|
||||||
UserLogic::userProfit($userSelf, $orderMoney, $proportion, $orderNo);
|
UserLogic::userProfit($userSelf, $orderMoney, $proportion, $orderNo);
|
||||||
}
|
|
||||||
|
|
||||||
// 小队/小区队长
|
// 通知商城
|
||||||
if (in_array($userSelf['group_id'] , [2, 18])) {
|
$request['user'] = [
|
||||||
//镇/街道合伙人
|
['type' => 3, 'account' => $userSelf['account'], 'user_profit' => bcmul($orderMoney, 0.01, 2)],
|
||||||
$where1 = ['group_id' => 15, 'street'=>$userSelf['street']];
|
];
|
||||||
$streetUser = UserLogic::getUser($where1);
|
$request['order_id'] = $orderId;
|
||||||
// 计算分润
|
$timestamp = time();
|
||||||
UserLogic::userProfit($streetUser, $orderMoney, 0.01, $orderNo);
|
$iv1 = substr(md5($this->apiSecret.$timestamp), 5, 16);
|
||||||
}
|
$encryptStr = encrypt($request, $this->apiSecret, $iv1);
|
||||||
|
$res = ShopRequestLogic::userProfitNotice(['data' => $encryptStr, 'timestamp' => $timestamp]);
|
||||||
// 村/社区合伙人
|
|
||||||
if ($userSelf['group_id'] == 3) {
|
|
||||||
//镇/街道合伙人
|
|
||||||
$where = ['group_id' => 15, 'village'=>$userSelf['village']];
|
|
||||||
$streetUser = UserLogic::getUser($where);
|
|
||||||
|
|
||||||
// 计算分润
|
|
||||||
UserLogic::userProfit($streetUser, $orderMoney, 0.01, $orderNo);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->success('成功', ['user_id' => $userSelf['id'], 'account' => $userSelf['account'], 'user_profit' => bcmul($orderMoney, $proportion, 2)]);
|
return $this->success('成功', ['user_id' => $userSelf['id'], 'account' => $userSelf['account'], 'user_profit' => bcmul($orderMoney, $proportion, 2)]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -244,4 +244,17 @@ class ShopRequestLogic extends BaseLogic
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function userProfitNotice($param)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$requestResponse = HttpClient::create()->request('POST', env('url.shop_prefix'). '/api/open/activityCommission', [
|
||||||
|
'body' => $param
|
||||||
|
]);
|
||||||
|
return json_decode($requestResponse->getContent(), true);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
self::setError($e->getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue