|
|
@@ -36,6 +36,8 @@ use common\models\forms\UserBindForm;
|
|
|
use common\models\forms\UserForm;
|
|
|
use common\models\Instalment;
|
|
|
use common\models\OpenBank;
|
|
|
+use common\models\OrderDec;
|
|
|
+use common\models\OriginDecPv;
|
|
|
use common\models\Period;
|
|
|
use common\models\ReceiveAddress;
|
|
|
use common\models\Region;
|
|
|
@@ -146,6 +148,50 @@ class UserController extends BaseController {
|
|
|
return static::notice($allData);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 当前用户的安置网络下线统计
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function actionNetworkStats() {
|
|
|
+ $userId = Yii::$app->user->id;
|
|
|
+ $networkInfo = UserNetwork::find()
|
|
|
+ ->select(['LOCATION_TAG', 'TOP_DEEP'])
|
|
|
+ ->where(['USER_ID' => $userId])
|
|
|
+ ->asArray()
|
|
|
+ ->one();
|
|
|
+
|
|
|
+ $descendants = [];
|
|
|
+ if ($networkInfo) {
|
|
|
+ $descendants = UserNetwork::find()
|
|
|
+ ->alias('N')
|
|
|
+ ->select(['N.USER_ID', 'N.PARENT_UID', 'N.TOP_DEEP'])
|
|
|
+ ->innerJoin(User::tableName() . ' U', 'U.ID = N.USER_ID')
|
|
|
+ ->where('N.LOCATION_TAG LIKE :LOCATION_TAG', [':LOCATION_TAG' => $networkInfo['LOCATION_TAG'] . '%'])
|
|
|
+ ->andWhere(['>', 'N.TOP_DEEP', $networkInfo['TOP_DEEP']])
|
|
|
+ ->andWhere(['U.DELETED' => 0])
|
|
|
+ ->asArray()
|
|
|
+ ->all();
|
|
|
+ }
|
|
|
+
|
|
|
+ $userIds = array_column($descendants, 'USER_ID');
|
|
|
+ $pcv = 0;
|
|
|
+ if ($userIds) {
|
|
|
+ $pcv += (float) DecOrder::find()->where(['TO_USER_ID' => $userIds, 'IS_DEL' => 0])->sum('DEC_PV');
|
|
|
+ $pcv += (float) OrderDec::find()->where(['USER_ID' => $userIds, 'IS_DELETE' => 0])->sum('PAY_PV');
|
|
|
+ $pcv += (float) OriginDecPv::find()->where(['USER_ID' => $userIds])->sum('DEC_PV');
|
|
|
+ }
|
|
|
+
|
|
|
+ $maxDeep = $descendants ? max(array_column($descendants, 'TOP_DEEP')) : $networkInfo['TOP_DEEP'] ?? 0;
|
|
|
+ return static::notice([
|
|
|
+ 'DOWNLINE_COUNT' => count($descendants),
|
|
|
+ 'DIRECT_DOWNLINE_COUNT' => count(array_filter($descendants, function ($downline) use ($userId) {
|
|
|
+ return $downline['PARENT_UID'] === $userId;
|
|
|
+ })),
|
|
|
+ 'MAX_DOWNLINE_DEEP' => max(0, (int) $maxDeep - (int) ($networkInfo['TOP_DEEP'] ?? 0)),
|
|
|
+ 'DOWNLINE_PCV' => $pcv,
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 上传身份证
|
|
|
* @return mixed
|