diff --git a/addons/shopro/controller/commission/Agent.php b/addons/shopro/controller/commission/Agent.php index 81465a3..6ae66a8 100755 --- a/addons/shopro/controller/commission/Agent.php +++ b/addons/shopro/controller/commission/Agent.php @@ -161,26 +161,16 @@ class Agent extends Commission //好友总数 $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(); - - + $list = UserModel::with('agent.levelInfo')->where('parent_user_id', $user_id)->select(); $result = [ - 'team_total' => $team_total, - 'son_total' => $son_total ?? 0, + 'team_total' => $this->runNextUserCount($this->getParent($user_id)), + 'son_total' => $son_total, 'list' => $list ]; - foreach ($list as &$item) { - $item['nextUserCount'] = 0; + $item['nextUserCount'] = $this->runNextUserCount($this->getParent($item['id'])); } $this->success('success', $result); @@ -188,7 +178,8 @@ class Agent extends Commission } public function test() { - $result = $this->runNextUser( $this->getTestData(1)); + $son = $this->getTestData(1); + $result = $this->runNextUser($son); $this->success('success', $result); } @@ -203,10 +194,10 @@ class Agent extends Commission ['id' => 2, 'pid' => 1], ['id' => 3, 'pid' => 1], ['id' => 4, 'pid' => 2], - ['id' => 5, 'pid' => 4], - ['id' => 6, 'pid' => 5], + ['id' => 5, 'pid' => 3], + ['id' => 6, 'pid' => 1], ['id' => 7, 'pid' => 6], - ['id' => 8, 'pid' => 2], + ['id' => 8, 'pid' => 1], ['id' => 9, 'pid' => 2], ['id' => 10, 'pid' => 7], ['id' => 11, 'pid' => 3], @@ -224,25 +215,67 @@ class Agent extends Commission /** * 递归处理用户的下级人数 * @param $list - * @param $pid + * @param int $pid * @return mixed */ - public function runNextUser($user) { - static $data = []; - $nextUser = $user; -// return $nextUser; -// $nextUserCount = count($this->getTestData($user_id)); + public function runNextUserCount($user) { + $count = 0; + if (count($user) > 0) { + $count += count($user); + } + foreach ($user as $item) { + $nexUserData = $this->getParent($item['id']); + if (is_array($nexUserData)) { + $this->runNextUser($nexUserData); + } + } + return $count; + } - 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]); -// } + /** + * @param $user + * @return array + */ + public function runNextUser($user) { + $count = 0; + $data = []; + if (count($user) > 0) { + $count += count($user); + } + foreach ($user as $item) { + $nexUserData = $this->getParent($item['id']); + if (is_array($nexUserData)) { + $item['son'] = $this->runNextUser($nexUserData); + } + $data[] = $item; + } + return ['list'=> $data, 'count'=> $count]; + } + function getTree($data, $pId) + { + $tree = []; + foreach($data as $v) + { + if(strcmp($v['condition'], $pId) == 0) + { + $v['children'] = $this->getTree($data, $v['task_id']); + $tree[] = $v; + } + } + return $tree; + } + function format($tree,$parent = [],$data = []) + { + foreach ($tree as $v) { + $tmp = $parent; + $tmp[] = $v['task_id']; + if (empty($v['children'])) { + $data[] = $tmp; + } else { + $data = $this->format($v['children'],$tmp,$data); + } } return $data; } diff --git a/addons/shopro/controller/user/WalletLog.php b/addons/shopro/controller/user/WalletLog.php index 3f88168..d20df9b 100755 --- a/addons/shopro/controller/user/WalletLog.php +++ b/addons/shopro/controller/user/WalletLog.php @@ -37,7 +37,12 @@ class WalletLog extends Common $income = UserWalletLogModel::where('user_id', $user->id)->{$type}()->where('amount', '>', 0)->whereTime('createtime', 'between', $date)->sum('amount'); $expense = UserWalletLogModel::where('user_id', $user->id)->{$type}()->where('amount', '<', 0)->whereTime('createtime', 'between', $date)->sum('amount'); $logs = UserWalletLogModel::where($where)->{$type}()->whereTime('createtime', 'between', $date)->order('createtime', 'desc')->paginate($list_rows); - $this->success('获取成功', ['list' => $logs, 'income' => $income, 'expense' => $expense]); +// dd($logs->toArray()); + $data = $logs->toArray(); + foreach ($data['data'] as &$row) { + $row['oper_type'] = UserModel::get($row['oper_id'])['nickname'] ?? ''; + } + $this->success('获取成功', ['list' => $data, 'income' => $income, 'expense' => $expense]); } /** @@ -85,7 +90,7 @@ class WalletLog extends Common $this->error('未查到转让用户'); } - if (!Sms::check($params['exchange_phone'], $params['code'], 'score')) { + if (!Sms::check($user->mobile, $params['code'], 'score')) { $this->error('验证码不正确'); } diff --git a/application/common.php b/application/common.php index e1c5a84..c47c368 100755 --- a/application/common.php +++ b/application/common.php @@ -564,3 +564,9 @@ EOT; function formatImage($url) { return request()->domain().$url; } + +function dd($data) { + echo '
';
+    print_r($data);
+    exit();
+}