diff --git a/app/adminapi/logic/user/UserLogic.php b/app/adminapi/logic/user/UserLogic.php index f1103e82..64a56048 100644 --- a/app/adminapi/logic/user/UserLogic.php +++ b/app/adminapi/logic/user/UserLogic.php @@ -303,10 +303,8 @@ class UserLogic extends BaseLogic return AccountLogLogic::add($data[0], $data[1], $data[2], $data[3], $data[4], $data[5], $data[6], $data[7]); } - public static function firstOrderLog($userIds, $orderMoney, $orderNo) + public static function firstOrderLog($userId, $orderMoney, $orderNo) { - foreach ($userIds as $userId) { - Db::name('user_invite_first_order_log')->insert(['user_id' => $userId, 'order_money' => $orderMoney, 'order_no' => $orderNo, 'create_time' => time()]); - } + return Db::name('user_invite_first_order_log')->insert(['user_id' => $userId, 'order_money' => $orderMoney, 'order_no' => $orderNo, 'create_time' => time()]); } } \ No newline at end of file diff --git a/app/api/controller/ShopCallController.php b/app/api/controller/ShopCallController.php index d097d8b3..5be6e119 100644 --- a/app/api/controller/ShopCallController.php +++ b/app/api/controller/ShopCallController.php @@ -47,100 +47,126 @@ class ShopCallController extends BaseApiController if (empty($userSelf)) { return $this->fail('推广人不存在'); } + $proportion = 0.03; + // 计算分润 + UserLogic::userProfit($userSelf, $orderMoney, $proportion, $orderNo); + + // 首单金额记录 + UserLogic::firstOrderLog($userSelf['id'], $orderMoney, $orderNo); - // 推广人角色 - 小队/小区队长 if (in_array($userSelf['group_id'] , [2, 18])) { - - //村/社区合伙人 - $where = ['group_id' => 3, 'village'=>$userSelf['village']]; - $villageUser = UserLogic::getUser($where); - - //镇/街道合伙人 - $where1 = ['group_id' => 15, 'street'=>$userSelf['street']]; - $streetUser = UserLogic::getUser($where1); - - // 计算分润 - UserLogic::shareProfit($userSelf, $villageUser, $streetUser, $orderMoney, $orderNo); - - // 首单金额记录 - UserLogic::firstOrderLog([$userSelf['id'], $villageUser['id'], $streetUser['id']], $orderMoney, $orderNo); - - $request['user'] = [ - ['type' => 1, 'account' => $userSelf['account'], 'user_profit' => bcmul($orderMoney, 0.03, 2)], - ['type' => 2, 'account' => $villageUser['account'], 'user_profit' => bcmul($orderMoney, 0.03, 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]); + $type = 1; } - - // 村/社区合伙人 if ($userSelf['group_id'] == 3) { - // 查下级 小队 - $where = ['group_id' => [2, 18], 'village'=>$userSelf['village']]; - $bridgeUser = UserLogic::getUser($where); - - //镇/街道合伙人 - $where = ['group_id' => 15, 'village'=>$userSelf['village']]; - $streetUser = UserLogic::getUser($where); - - // 计算分润 - UserLogic::shareProfit($bridgeUser, $userSelf, $streetUser, $orderMoney); - - // 首单金额记录 - UserLogic::firstOrderLog([$userSelf['id'], $bridgeUser['id'], $streetUser['id']], $orderMoney, $orderNo); - - $request['user'] = [ - ['type' => 1, 'account' => $bridgeUser['account'], 'user_profit' => bcmul($orderMoney, 0.03, 2)], - ['type' => 2, 'account' => $userSelf['account'], 'user_profit' => bcmul($orderMoney, 0.03, 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]); + $type = 2; } - - // 镇/街道合伙人 if ($userSelf['group_id'] == 15) { - // 查下级村 - $where = ['group_id' => 3, 'village'=>$userSelf['village']]; - $villageUser = UserLogic::getUser($where); - - //和小队 - $where = ['group_id' => [2, 18], 'village'=>$userSelf['village']]; - $bridgeUser = UserLogic::getUser($where); - - // 计算分润 - UserLogic::shareProfit($bridgeUser, $villageUser, $userSelf, $orderMoney); - - // 首单金额记录 - UserLogic::firstOrderLog([$userSelf['id'], $villageUser['id'], $userSelf['id']], $orderMoney, $orderNo); - - $request['user'] = [ - ['type' => 1, 'account' => $bridgeUser['account'], 'user_profit' => bcmul($orderMoney, 0.03, 2)], - ['type' => 2, 'account' => $villageUser['account'], 'user_profit' => bcmul($orderMoney, 0.03, 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]); + $type = 3; } - + // 通知商城 + $request['user'] = [ + ['type' => $type, 'account' => $userSelf['account'], 'user_profit' => bcmul($orderMoney, 0.03, 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('成功'); + + // 推广人角色 - 小队/小区队长 +// if (in_array($userSelf['group_id'] , [2, 18])) { +// +// //村/社区合伙人 +// $where = ['group_id' => 3, 'village'=>$userSelf['village']]; +// $villageUser = UserLogic::getUser($where); +// +// //镇/街道合伙人 +// $where1 = ['group_id' => 15, 'street'=>$userSelf['street']]; +// $streetUser = UserLogic::getUser($where1); +// +// // 计算分润 +// UserLogic::shareProfit($userSelf, $villageUser, $streetUser, $orderMoney, $orderNo); +// +// // 首单金额记录 +// UserLogic::firstOrderLog([$userSelf['id'], $villageUser['id'], $streetUser['id']], $orderMoney, $orderNo); +// +// $request['user'] = [ +// ['type' => 1, 'account' => $userSelf['account'], 'user_profit' => bcmul($orderMoney, 0.03, 2)], +// ['type' => 2, 'account' => $villageUser['account'], 'user_profit' => bcmul($orderMoney, 0.03, 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]); +// } +// +// // 村/社区合伙人 +// if ($userSelf['group_id'] == 3) { +// // 查下级 小队 +// $where = ['group_id' => [2, 18], 'village'=>$userSelf['village']]; +// $bridgeUser = UserLogic::getUser($where); +// +// //镇/街道合伙人 +// $where = ['group_id' => 15, 'village'=>$userSelf['village']]; +// $streetUser = UserLogic::getUser($where); +// +// // 计算分润 +// UserLogic::shareProfit($bridgeUser, $userSelf, $streetUser, $orderMoney); +// +// // 首单金额记录 +// UserLogic::firstOrderLog([$userSelf['id'], $bridgeUser['id'], $streetUser['id']], $orderMoney, $orderNo); +// +// $request['user'] = [ +// ['type' => 1, 'account' => $bridgeUser['account'], 'user_profit' => bcmul($orderMoney, 0.03, 2)], +// ['type' => 2, 'account' => $userSelf['account'], 'user_profit' => bcmul($orderMoney, 0.03, 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]); +// } +// +// // 镇/街道合伙人 +// if ($userSelf['group_id'] == 15) { +// // 查下级村 +// $where = ['group_id' => 3, 'village'=>$userSelf['village']]; +// $villageUser = UserLogic::getUser($where); +// +// //和小队 +// $where = ['group_id' => [2, 18], 'village'=>$userSelf['village']]; +// $bridgeUser = UserLogic::getUser($where); +// +// // 计算分润 +// UserLogic::shareProfit($bridgeUser, $villageUser, $userSelf, $orderMoney); +// +// // 首单金额记录 +// UserLogic::firstOrderLog([$userSelf['id'], $villageUser['id'], $userSelf['id']], $orderMoney, $orderNo); +// +// $request['user'] = [ +// ['type' => 1, 'account' => $bridgeUser['account'], 'user_profit' => bcmul($orderMoney, 0.03, 2)], +// ['type' => 2, 'account' => $villageUser['account'], 'user_profit' => bcmul($orderMoney, 0.03, 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]); +// } + + } /** diff --git a/app/api/controller/UserController.php b/app/api/controller/UserController.php index 67d1e30f..092f6cae 100644 --- a/app/api/controller/UserController.php +++ b/app/api/controller/UserController.php @@ -317,4 +317,18 @@ class UserController extends BaseApiController return bcmul(bcmul($userMonthTotalMoney, $rate, 2), 1, 2); } } + + public function getFirstOrderLog() + { + $page = $this->request->param('page_no', 1); + $limit = $this->request->param('page_size', 15); + $firstOrderLogList = Db::name('user_invite_first_order_log')->where('user_id', $this->userId)->page($page, $limit)->select(); + $data = [ + 'lists' => $firstOrderLogList, + 'count' => Db::name('user_invite_first_order_log')->where('user_id', $this->userId)->count(), + 'page_no' => $page, + 'page_size' => $limit, + ]; + return $this->success('成功', $data); + } }