积分转让和我的团队

main
ztt 10 months ago
parent b40ac41a5c
commit 38137ef641
  1. 122
      addons/shopro/controller/commission/Agent.php
  2. 20
      addons/shopro/controller/user/WalletLog.php
  3. 16
      addons/shopro/job/trade/OrderPaid.php

@ -2,6 +2,7 @@
namespace addons\shopro\controller\commission;
use addons\shopro\controller\Pay;
use think\Db;
use app\admin\model\shopro\user\User as UserModel;
use app\admin\model\shopro\commission\Agent as AgentModel;
@ -148,4 +149,125 @@ class Agent extends Commission
});
$this->success('');
}
/**
* 我的团队
*/
public function myTeam() {
$user = auth_user();
$list = [];
//团队总数
$team_total = 0;
//好友总数
$son_total = 0;
$user_id = $user->id;
$son_total = UserModel::where('parent_user_id', $user_id)->count('id');
$team_total = UserModel::with(['parentUser' => function($query) use ($user_id) {
// $query->where('');
}])->where('parent_user_id', $user_id)->count('id');
$list = UserModel::with('agent.levelInfo')->where('id', $user_id)->select();
$result = [
'team_total' => $team_total,
'son_total' => $son_total ?? 0,
'list' => $list
];
foreach ($list as &$item) {
$item['nextUserCount'] = 0;
}
$this->success('success', $result);
}
public function test() {
$result = $this->runNextUser( $this->getTestData(1));
$this->success('success', $result);
}
/**
* 测试数据
*/
public function getTestData($id) {
$data = [
['id' => 1, 'pid' => 0],
['id' => 2, 'pid' => 1],
['id' => 3, 'pid' => 1],
['id' => 4, 'pid' => 2],
['id' => 5, 'pid' => 4],
['id' => 6, 'pid' => 5],
['id' => 7, 'pid' => 6],
['id' => 8, 'pid' => 2],
['id' => 9, 'pid' => 2],
['id' => 10, 'pid' => 7],
['id' => 11, 'pid' => 3],
];
$data = array_column($data, null, 'id');
$new_data = [];
foreach ($data as $key => $val) {
if ($id == $val['pid']) {
$new_data[] = $val;
}
}
return $new_data;
}
/**
* 递归处理用户的下级人数
* @param $list
* @param $pid
* @return mixed
*/
public function runNextUser($user) {
static $data = [];
$nextUser = $user;
// return $nextUser;
// $nextUserCount = count($this->getTestData($user_id));
foreach ($nextUser as $k => $v) {
// if($v['pid'] == $user_id) {
// $data[] = $v;
$v['son'] = $this->runNextUser($v['id']);
!empty($son)&& $v['son'] = $this->runNextUser($v['id']);
$data[] = $v;
unset($nextUser[$k]);
// }
}
return $data;
}
public function getParent($pid) {
return UserModel::where('parent_user_id', $pid)->select();
}
/**
* 返回树形结构
* @param $list
* @param $pid
* @return array
*/
public function getTreeData($list, $pid = 0) {
static $data = [];
foreach ($list as $key => $item) {
if ($item['user_id'] == $pid) {
$children = $this->getTreeData($item, $item['user_id']);
!empty($children) && $item['children'] = $children;
$data[] = $item;
unset($list[$key]);
}
}
return $data;
}
}

@ -72,24 +72,28 @@ class WalletLog extends Common
$user = auth_user();
$user_id = $user->id;
if (!Sms::check($params['exchange_phone'], $params['code'], 'score')) {
$this->error('验证码不正确');
if ($user->mobile == $params['exchange_phone']) {
$this->error('转让人不能是自己');
}
$exchange_user = UserModel::getByMobile($params['exchange_phone']);
if ($user) {
if ($user->status != 'normal') {
$this->error(__('账户已经被锁定'));
if ($exchange_user) {
if ($exchange_user->status != 'normal') {
$this->error(__('转让账户已经被锁定'));
}
}else {
$this->error('该手机号暂未注册');
$this->error('未查到转让用户');
}
if (!Sms::check($params['exchange_phone'], $params['code'], 'score')) {
$this->error('验证码不正确');
}
$exchange_user_id = $exchange_user->id;
$result = Db::transaction(function () use ($params, $exchange_user_id, $user_id) {
WalletService::change($user_id, $params['type'], -$params['amount'], 'user_exchange', [], '积分转让');
return WalletService::change($exchange_user_id, $params['type'], $params['amount'], 'user_exchange', [], '积分转让');
WalletService::change($user_id, $params['type'], -$params['exchange_amount'], 'user_exchange', [], '积分转让');
return WalletService::change($exchange_user_id, $params['type'], $params['exchange_amount'], 'user_exchange', [], '积分转让');
});
if ($result) {
$this->success('转让成功');

@ -42,18 +42,18 @@ class OrderPaid extends BaseJob
$gift = (isset($rule['gift']) && $rule['gift'] > 0) ? $rule['gift'] : 0;
if ($money > 0) {
// 增加余额
// WalletService::change($user, 'money', $money, 'order_recharge', [
// 'order_id' => $order->id,
// 'order_sn' => $order->order_sn,
// 'order_type' => 'trade_order',
// ]);
// 增加积分
WalletService::change($user, 'score', $money, 'order_recharge', [
WalletService::change($user, 'money', $money, 'order_recharge', [
'order_id' => $order->id,
'order_sn' => $order->order_sn,
'order_type' => 'trade_order',
]);
// 增加积分
// WalletService::change($user, 'score', $money, 'order_recharge', [
// 'order_id' => $order->id,
// 'order_sn' => $order->order_sn,
// 'order_type' => 'trade_order',
// ]);
}
if ($gift > 0) {

Loading…
Cancel
Save