Przeglądaj źródła

增加蓝星奖代码

kevin_zhangl 3 lat temu
rodzic
commit
c752db64e6
64 zmienionych plików z 2376 dodań i 404 usunięć
  1. 9 0
      backendApi/config/menu.php
  2. 4 0
      backendApi/config/urlManagerRules.php
  3. 22 0
      backendApi/modules/v1/controllers/BaseController.php
  4. 117 0
      backendApi/modules/v1/controllers/BonusController.php
  5. 18 10
      backendApi/modules/v1/controllers/DashboardController.php
  6. 3 0
      backendApi/modules/v1/controllers/ShopController.php
  7. 1 0
      backendApi/modules/v1/controllers/UserController.php
  8. 6 6
      backendApi/modules/v1/models/Admin.php
  9. 23 2
      backendApi/modules/v1/models/AdminForm.php
  10. 5 4
      backendApi/modules/v1/models/AdminRole.php
  11. 4 0
      backendApi/modules/v1/models/LoginForm.php
  12. 15 0
      backendApi/modules/v1/models/lists/bonus/BalanceList.php
  13. 226 0
      backendApi/modules/v1/models/lists/bonus/FlowBalanceList.php
  14. 207 0
      backendApi/modules/v1/models/lists/bonus/FlowExchangePointsList.php
  15. 169 131
      backendApi/modules/v1/models/lists/bonus/PeriodBonusList.php
  16. 3 1
      backendApi/modules/v1/models/lists/bonus/TraceUpQyList.php
  17. 23 7
      backendApi/modules/v1/models/lists/shop/GoodsList.php
  18. 3 1
      common/components/ActiveRecord.php
  19. 5 0
      common/config/params.php
  20. 363 28
      common/helpers/bonus/BonusCalc.php
  21. 119 8
      common/helpers/bonus/BonusSend.php
  22. 2 0
      common/helpers/bonus/CalcCache.php
  23. 122 11
      common/helpers/bonus/PerfCalc.php
  24. 128 2
      common/helpers/user/Balance.php
  25. 17 0
      common/helpers/user/Info.php
  26. 2 1
      common/libs/logging/operate/AdminOperate.php
  27. 4 4
      common/models/Ad.php
  28. 8 4
      common/models/BalanceAudit.php
  29. 7 2
      common/models/CalcBonus.php
  30. 78 0
      common/models/CalcBonusBS.php
  31. 6 4
      common/models/DealType.php
  32. 77 11
      common/models/EmployLevel.php
  33. 82 0
      common/models/FlowExchangePoints.php
  34. 77 0
      common/models/PerfActiveUser.php
  35. 4 4
      common/models/PerfAudit.php
  36. 14 1
      common/models/Period.php
  37. 4 4
      common/models/ReconsumeAudit.php
  38. 1 0
      common/models/User.php
  39. 4 4
      common/models/UserBind.php
  40. 4 1
      common/models/UserBonus.php
  41. 4 4
      common/models/UserMove.php
  42. 20 10
      common/models/UserNetwork.php
  43. 59 0
      common/models/UserPeriodExchangePoints.php
  44. 4 4
      common/models/UserStatusAudit.php
  45. 4 4
      common/models/UserSystem.php
  46. 4 4
      common/models/UserTeamwork.php
  47. 7 2
      common/models/forms/ChangeBalanceForm.php
  48. 3 1
      common/models/forms/ConfigPeriodForm.php
  49. 33 11
      common/models/forms/OrderForm.php
  50. 1 1
      common/models/forms/RechargeForm.php
  51. 22 9
      common/models/forms/ShopGoodsForm.php
  52. 1 1
      common/models/forms/TransferForm.php
  53. 2 2
      common/models/forms/WithdrawForm.php
  54. 19 0
      console/controllers/BonusController.php
  55. 1 1
      frontendApi/config/menu.php
  56. 23 0
      frontendApi/modules/v1/controllers/BaseController.php
  57. 130 84
      frontendApi/modules/v1/controllers/BonusController.php
  58. 9 4
      frontendApi/modules/v1/controllers/SiteController.php
  59. 22 2
      frontendApi/modules/v1/controllers/UserController.php
  60. 4 0
      frontendApi/modules/v1/models/LoginForm.php
  61. 6 1
      frontendEle/src/utils/baseInfo.js
  62. 5 5
      frontendEle/src/utils/config_development_example.js
  63. 3 3
      frontendEle/src/utils/config_production_example.js
  64. 4 0
      frontendEle/src/utils/tool.js

+ 9 - 0
backendApi/config/menu.php

@@ -35,6 +35,11 @@ return [
         'show'=>1,
         'child'=>[
             ['name'=>'商品列表', 'class'=>'', 'icon'=>'', 'controller'=>'shop', 'action'=>'index', 'routePath'=>'shop/index', 'show'=>1,],
+            // 新添加的商品操作  --- stat
+            ['name'=>'添加商品', 'class'=>'', 'icon'=>'', 'controller'=>'shop', 'action'=>'goods-add', 'routePath'=>'shop/goods-add', 'show'=>0,],
+            ['name'=>'编辑商品', 'class'=>'', 'icon'=>'', 'controller'=>'shop', 'action'=>'goods-edit', 'routePath'=>'shop/goods-edit', 'show'=>0,],
+            ['name'=>'删除商品', 'class'=>'', 'icon'=>'', 'controller'=>'shop', 'action'=>'goods-delete', 'routePath'=>'shop/goods-delete', 'show'=>0,],
+            // 新添加的商品操作 ---stop
             ['name'=>'商品列表导出', 'class'=>'', 'icon'=>'', 'controller'=>'shop', 'action'=>'goods-list-export', 'routePath'=>'shop/goods-list-export', 'show'=>0,],
             ['name'=>'套餐管理', 'class'=>'', 'icon'=>'', 'controller'=>'shop', 'action'=>'package', 'routePath'=>'shop/package', 'show'=>1,],
             ['name'=>'报单列表', 'class'=>'', 'icon'=>'', 'controller'=>'shop', 'action'=>'dec-order-list', 'routePath'=>'shop/dec-order-list', 'show'=>1,],
@@ -202,6 +207,10 @@ return [
 //            ['name'=>'领袖分红奖流水导出', 'class'=>'', 'icon'=>'', 'controller'=>'bonus', 'action'=>'flow-lx-export', 'routePath'=>'bonus/flow-lx-export', 'show'=>0,],
             ['name'=>'复消积分流水', 'class'=>'', 'icon'=>'', 'controller'=>'bonus', 'action'=>'flow-rp', 'routePath'=>'bonus/flow-rp', 'show'=>1,],
             ['name'=>'复消积分流水导出', 'class'=>'', 'icon'=>'', 'controller'=>'bonus', 'action'=>'flow-rp-export', 'routePath'=>'bonus/flow-rp-export', 'show'=>0,],
+            ['name'=>'兑换积分流水', 'class'=>'', 'icon'=>'', 'controller'=>'bonus', 'action'=>'flow-exchange', 'routePath'=>'bonus/flow-exchange', 'show'=>1,],
+            ['name'=>'兑换积分流水导出', 'class'=>'', 'icon'=>'', 'controller'=>'bonus', 'action'=>'flow-exchange-export', 'routePath'=>'bonus/flow-exchange-export', 'show'=>0,],
+            ['name'=>'会员余额流水', 'class'=>'', 'icon'=>'', 'controller'=>'bonus', 'action'=>'flow-balance', 'routePath'=>'bonus/flow-balance', 'show'=>1,],
+            ['name'=>'会员余额流水导出', 'class'=>'', 'icon'=>'', 'controller'=>'bonus', 'action'=>'flow-balance-export', 'routePath'=>'bonus/flow-balance-export', 'show'=>0,],
 //            ['name'=>'区域津贴核算', 'class'=>'', 'icon'=>'', 'controller'=>'bonus', 'action'=>'calc-qy', 'routePath'=>'bonus/calc-qy', 'show'=>1,],
 //            ['name'=>'区域津贴补发列表', 'class'=>'', 'icon'=>'', 'controller'=>'bonus', 'action'=>'resend-qy-list', 'routePath'=>'bonus/resend-qy-list', 'show'=>1,],
 //            ['name'=>'区域津贴补发列表导出', 'class'=>'', 'icon'=>'', 'controller'=>'bonus', 'action'=>'resend-qy-list-export', 'routePath'=>'bonus/resend-qy-list-export', 'show'=>0,],

+ 4 - 0
backendApi/config/urlManagerRules.php

@@ -367,6 +367,10 @@ return [
             'GET flow-cf-export' => 'flow-cf-export',
             'GET flow-rp' => 'flow-rp',
             'GET flow-rp-export' => 'flow-rp-export',
+            'GET flow-balance' => 'flow-balance',
+            'GET flow-balance-export' => 'flow-balance-export',
+            'GET flow-exchange' => 'flow-exchange',
+            'GET flow-exchange-export' => 'flow-exchange-export',
             'GET flow-lx' => 'flow-lx',
             'GET flow-lx-export' => 'flow-lx-export',
             'GET cf-lx-audit-list' => 'cf-lx-audit-list',

+ 22 - 0
backendApi/modules/v1/controllers/BaseController.php

@@ -37,6 +37,28 @@ class BaseController extends \yii\rest\ActiveController {
      */
     public function beforeAction($action) {
         $parentBeforeAction = parent::beforeAction($action);
+
+        // 增加的判断用户登录后未操作后的超时
+        if (Yii::$app->getUser()->getUserInfo()){
+            $adminId = Yii::$app->getUser()->getUserInfo()['id'];
+            $redisKey = 'admin:timeOut';
+
+            $lastTime = '';
+            if (!Yii::$app->tokenRedis->hget($redisKey, $adminId)) {
+                $lastTime = time();
+            }else{
+                $lastTime = Yii::$app->tokenRedis->hget($redisKey, $adminId);
+            }
+
+            $currentTime = time();
+            $timeOut = Yii::$app->params['operationTimeOut'];
+            if ($currentTime - $lastTime > $timeOut) {
+                return self::notice('Connection not operated for too long', 402);
+            } else {
+                Yii::$app->tokenRedis->hset($redisKey, $adminId, time());
+            }
+        }
+
         // 校验用户权限
         if (!Yii::$app->user->validateAdminAction($this->id, $this->action->id)) {
             return self::notice('权限不足', 403);

+ 117 - 0
backendApi/modules/v1/controllers/BonusController.php

@@ -11,7 +11,9 @@ namespace backendApi\modules\v1\controllers;
 use backendApi\modules\v1\models\Admin;
 use backendApi\modules\v1\models\exportForms\BonusExportForm;
 use backendApi\modules\v1\models\lists\bonus\BalanceList;
+use backendApi\modules\v1\models\lists\bonus\FlowBalanceList;
 use backendApi\modules\v1\models\lists\bonus\FlowBonusList;
+use backendApi\modules\v1\models\lists\bonus\FlowExchangePointsList;
 use backendApi\modules\v1\models\lists\bonus\FlowReconsumePointsList;
 use backendApi\modules\v1\models\lists\bonus\FlowWalletList;
 use backendApi\modules\v1\models\lists\bonus\PerfMonthList;
@@ -38,6 +40,7 @@ use backendApi\modules\v1\models\lists\bonus\TraceUpYcList;
 use backendApi\modules\v1\models\lists\bonus\TraceUpYjList;
 use backendApi\modules\v1\models\lists\bonus\UserPerfList;
 use common\helpers\Cache;
+use common\helpers\Date;
 use common\helpers\Tool;
 use common\helpers\user\Info;
 use common\helpers\user\Perf;
@@ -54,9 +57,12 @@ use common\models\UserInfo;
 use common\models\UserNetwork;
 use Yii;
 use common\helpers\Form;
+use common\models\Config;
 use common\models\FlowBonus;
+use common\models\FlowExchangePoints;
 use common\models\forms\PeriodForm;
 use common\models\Period;
+use Exception;
 
 class BonusController extends BaseController {
     public $modelClass = FlowBonus::class;
@@ -338,6 +344,114 @@ class BonusController extends BaseController {
         return static::notice('导出开始,请到文件管理-导出文件查看');
     }
 
+
+    /**
+     * 会员余额流水 
+     * @return mixed
+     * @throws \yii\base\Exception
+     * @throws \yii\web\HttpException
+     */
+    public function actionFlowBalance() {
+        $filter = $this->filterCondition([
+            'USER_NAME' => 'USER_NAME',
+            'REAL_NAME' => 'REAL_NAME',
+            'CALC_MONTH' => 'CALC_MONTH',
+            'PERIOD_NUM' => 'PERIOD_NUM',
+            'TRANSFER_SN' => 'TRANSFER_SN',
+            'CREATED_AT' => 'FW.CREATED_AT',
+            'AMOUNT' => 'AMOUNT',
+            'TOTAL' => 'TOTAL',
+            'REMARK' => 'REMARK',
+        ]);
+        $condition = $filter['condition'];
+        $params = $filter['params'];
+        $listObj = new FlowBalanceList();
+        $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
+        return static::notice($data);
+    }
+
+    /**
+     * 会员余额流水导出
+     * @return mixed
+     * @throws \yii\db\Exception
+     * @throws \yii\web\HttpException
+     */
+    public function actionFlowBalanceExport() {
+        $filter = $this->filterCondition([
+            'USER_NAME' => 'USER_NAME',
+            'REAL_NAME' => 'REAL_NAME',
+            'CALC_MONTH' => 'CALC_MONTH',
+            'PERIOD_NUM' => 'PERIOD_NUM',
+            'TRANSFER_SN' => 'TRANSFER_SN',
+            'CREATED_AT' => 'FW.CREATED_AT',
+            'AMOUNT' => 'AMOUNT',
+            'TOTAL' => 'TOTAL',
+            'REMARK' => 'REMARK',
+        ]);
+        $form = new BonusExportForm();
+        $result = $form->run($filter, '会员余额流水');
+        if (!$result) {
+            return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
+        }
+        return static::notice('导出开始,请到文件管理-导出文件查看');
+    }
+
+
+    /**
+     * 兑换积分流水
+     * @return mixed
+     * @throws \yii\base\Exception
+     * @throws \yii\web\HttpException
+     */
+    public function actionFlowExchange() {
+        $filter = $this->filterCondition([
+            'userIds' => 'USER_ID',
+            'CREATED_AT' => 'CREATED_AT',
+            'PERIOD_NUM' => 'PERIOD_NUM',
+            'CALC_MONTH' => 'CALC_MONTH',
+            'DEAL_TYPE_NAME' => 'DEAL_TYPE_ID',
+            'LAST_DEC_LV_NAME' => 'LAST_DEC_LV',
+            'LAST_EMP_LV_NAME' => 'LAST_EMP_LV',
+            'AMOUNT' => 'AMOUNT',
+            'TOTAL' => 'TOTAL',
+            'ADMIN_NAME' => 'ADMIN_NAME',
+            'REMARK' => 'REMARK',
+        ]);
+        $condition = $filter['condition'];
+        $params = $filter['params'];
+        $listObj = new FlowExchangePointsList();
+        $data = $listObj->getList(['condition'=>$condition, 'params'=>$params]);
+        return static::notice($data);
+    }
+
+    /**
+     * 兑换积分流水导出
+     * @return mixed
+     * @throws \yii\db\Exception
+     * @throws \yii\web\HttpException
+     */
+    public function actionFlowExchangeExport() {
+        $filter = $this->filterCondition([
+            'userIds' => 'USER_ID',
+            'CREATED_AT' => 'CREATED_AT',
+            'PERIOD_NUM' => 'PERIOD_NUM',
+            'CALC_MONTH' => 'CALC_MONTH',
+            'DEAL_TYPE_NAME' => 'DEAL_TYPE_ID',
+            'LAST_DEC_LV_NAME' => 'LAST_DEC_LV',
+            'LAST_EMP_LV_NAME' => 'LAST_EMP_LV',
+            'AMOUNT' => 'AMOUNT',
+            'TOTAL' => 'TOTAL',
+            'ADMIN_NAME' => 'ADMIN_NAME',
+            'REMARK' => 'REMARK',
+        ]);
+        $form = new BonusExportForm();
+        $result = $form->run($filter, '兑换积分流水');
+        if (!$result) {
+            return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
+        }
+        return static::notice('导出开始,请到文件管理-导出文件查看');
+    }
+
     /**
      * 现金钱包流水
      * @return mixed
@@ -684,6 +798,7 @@ class BonusController extends BaseController {
             'BONUS_TG' => 'CB.BONUS_TG',
             'BONUS_YJ' => 'CB.BONUS_YJ',
             'BONUS_GX' => 'CB.BONUS_GX',
+            // 'BONUS_GL' => 'CB.BONUS_BS',
             'BONUS_GL' => 'CB.BONUS_GL',
             'BONUS_QY' => 'CB.BONUS_QY',
             'BONUS_YC' => 'CB.BONUS_YC',
@@ -757,6 +872,7 @@ class BonusController extends BaseController {
             'BONUS_YJ' => 'CB.BONUS_YJ',
             'BONUS_GX' => 'CB.BONUS_GX',
             'BONUS_GL' => 'CB.BONUS_GL',
+            // 'BONUS_GL' => 'CB.BONUS_BS',
             'BONUS_QY' => 'CB.BONUS_QY',
             'BONUS_YC' => 'CB.BONUS_YC',
             'PV_1L' => 'CB.PV_1L',
@@ -831,6 +947,7 @@ class BonusController extends BaseController {
             'BONUS_YJ' => 'CB.BONUS_YJ',
             'BONUS_GX' => 'CB.BONUS_GX',
             'BONUS_GL' => 'CB.BONUS_GL',
+            // 'BONUS_GL' => 'CB.BONUS_BS',
             'BONUS_QY' => 'CB.BONUS_QY',
             'BONUS_YC' => 'CB.BONUS_YC',
             'ORI_BONUS_STANDARD' => 'CB.ORI_BONUS_STANDARD',

+ 18 - 10
backendApi/modules/v1/controllers/DashboardController.php

@@ -45,13 +45,15 @@ class DashboardController extends BaseController
      * @return array
      */
     public function actionTotalItem(){
-        $chart = ChartData::instance();
-        return [
-            'totalBonus' => $chart->totalBonus(),
-            'totalPerf' => $chart->totalPerf(),
-            'totalWithdraw' => $chart->totalWithdraw(),
-            'totalUser' => $chart->totalUser(),
-        ];
+        // $chart = ChartData::instance();
+        // return [
+        //     'totalBonus' => $chart->totalBonus(),
+        //     'totalPerf' => $chart->totalPerf(),
+        //     'totalWithdraw' => $chart->totalWithdraw(),
+        //     'totalUser' => $chart->totalUser(),
+        // ];
+
+        return [];
     }
 
     /**
@@ -61,7 +63,9 @@ class DashboardController extends BaseController
      */
     public function actionRegNum(){
         $chartData = ChartData::instance();
-        return static::notice($chartData->getUserData());
+        //$data = $chartData->getUserData();
+        $data = [];
+        return static::notice($data);
     }
 
     /**
@@ -71,7 +75,9 @@ class DashboardController extends BaseController
      */
     public function actionBonusNum(){
         $chartData = ChartData::instance();
-        return static::notice($chartData->getBonusData());
+        // $data = $chartData->getBonusData();
+        $data = [];
+        return static::notice($data);
     }
 
     /**
@@ -81,6 +87,8 @@ class DashboardController extends BaseController
      */
     public function actionWithdrawNum(){
         $chartData = ChartData::instance();
-        return static::notice($chartData->getWithdrawData());
+        // $data = $chartData->getWithdrawData();
+        $data = [];
+        return static::notice($data);
     }
 }

+ 3 - 0
backendApi/modules/v1/controllers/ShopController.php

@@ -137,6 +137,9 @@ class ShopController extends BaseController {
         $data = ShopGoods::findOneAsArray('ID=:ID', [':ID' => $id]);
         $data['SELL_TYPE'] = explode(',',$data['SELL_TYPE']);
         $data['GIFT_TYPE'] = explode(',',$data['GIFT_TYPE']);
+        if ($data['TYPE'] == 1 || $data['TYPE'] == 2) {
+            $data['SELL_DISCOUNT'] = ShopGoods::GOODS_TYPE[$data['TYPE']]['discount']/100;
+        }
         return static::notice(['goodsInfo'=>$data,'sellType' => ShopGoods::SALE_TYPE, 'goodsType' => ShopGoods::GOODS_TYPE, 'giftType' => ShopGoods::GIFT_TYPE]);
     }
 

+ 1 - 0
backendApi/modules/v1/controllers/UserController.php

@@ -884,6 +884,7 @@ class UserController extends BaseController
             $userInfo['BONUS'] = Balance::getAvailableBalance($userInfo['ID']);
             $userInfo['CASH'] = Cash::getAvailableBalance($userInfo['ID']);
             $userInfo['RECONSUME_POINTS'] = Balance::getBalanceReconsumePoints($userInfo['ID']);
+            $userInfo['EXCHANGE_POINTS'] = Balance::getBalanceExchangePoints($userInfo['ID']);
             return static::notice($userInfo);
         }else{
             return static::notice('会员编号不存在', 400);

+ 6 - 6
backendApi/modules/v1/models/Admin.php

@@ -142,9 +142,9 @@ class Admin extends ActiveRecord
             'ROLE_ID' => [
                 'label' => '角色名称',
                 'type' => function($data){
-                    $value = $data['value'];
+                    $value = isset($data['value']) ? $data['value'] : '';
                     $result = AdminRole::findOneAsArray('ID=:ID', [':ID'=>$value], 'ROLE_NAME');
-                    return $result['ROLE_NAME'];
+                    return !empty($result) ? $result['ROLE_NAME'] : '';
                 },
             ],
             'IS_ENABLE' => [
@@ -155,17 +155,17 @@ class Admin extends ActiveRecord
             'CREATE_ADMIN' => [
                 'label' => '创建人',
                 'type' => function($data){
-                    $value = $data['value'];
+                    $value = isset($data['value']) ? $data['value'] : '';
                     $result = Admin::findOneAsArray('ID=:ID', [':ID'=>$value], 'ADMIN_NAME');
-                    return $result['ADMIN_NAME'];
+                    return !empty($result) ? $result['ADMIN_NAME'] : '';
                 },
             ],
             'UPDATE_ADMIN' => [
                 'label' => '更新人',
                 'type' => function($data){
-                    $value = $data['value'];
+                    $value = isset($data['value']) ? $data['value'] : '';
                     $result = Admin::findOneAsArray('ID=:ID', [':ID'=>$value], 'ADMIN_NAME');
-                    return $result['ADMIN_NAME'];
+                    return !empty($result) ? $result['ADMIN_NAME'] : '';
                 },
             ],
             'CREATED_AT' => [

+ 23 - 2
backendApi/modules/v1/models/AdminForm.php

@@ -89,7 +89,7 @@ class AdminForm extends Model
 
         if($this->scenario == 'add'){
             $model = new Admin();
-            $model->ADMIN_NAME = $this->adminName;
+            $model->ADMIN_NAME = strtolower($this->adminName);
             $model->REAL_NAME = $this->realName;
             $model->ROLE_ID = $this->roleId;
             $model->REMARK = $this->remark;
@@ -130,14 +130,33 @@ class AdminForm extends Model
             $this->addError('id', '提交场景不存在');
             return null;
         }
+
+        // 给密码进行加密 ,如果需要添加验证密码安全验证时 ,可以在这个地方加
         if($this->password){
+            if ($this->scenario == 'changePassword' || $this->scenario == 'noLoginModifyPassword'){
+                if (strlen($this->password) < 8){
+                    $this->addError($this->scenario, '登录密码不能小于8位');
+                    return null;
+                }
+//               $symbol = '!#$%^&*';
+               $symbol = '`~!@#$^&*()=|{}\'\":;\',\\[\\].<>\/?~!@#¥……&*()——|{}【】‘;:”。,、?';
+               $passwordRules = '/^(?![\d]+$)(?![a-z]+$)(?![A-Z]+$)(?!['.$symbol.']+$)[\da-zA-z'.$symbol.']{8,}$/';
+               $verificationResults = preg_match($passwordRules,$this->password);
+               if (!$verificationResults){
+                   $this->addError($this->scenario, '登录密码中需要包含数字、大写字母、小写字母、特殊字符至少两种');
+                   return null;
+               }
+            }
             $model->PASSWORD_HASH = \Yii::$app->security->generatePasswordHash($this->password);
         }
 
+        // 执行修改或添加 , 如果执行不成功就在这里报出错误
         if(!$model->save()){
             $this->addErrors($model->getErrors());
             return null;
         }
+
+        // 执行完成后根据对应的类型写入日志
         if($this->scenario == 'add'){
             $this->adminOperateLogger->afterInsert($model)->clean()->save([
                 'optType' => '添加管理员',
@@ -154,7 +173,8 @@ class AdminForm extends Model
         } elseif($this->scenario == 'noLoginModifyPassword') {
             $this->adminOperateLogger->clean()->save([
                 'optType' => '不登录重置密码',
-                'userName' => $this->adminName,
+                'userName' => $model->ADMIN_NAME,
+                'adminName' => $model->ADMIN_NAME,
                 'remark' => '不登录重置密码',
             ]);
         }else{
@@ -164,6 +184,7 @@ class AdminForm extends Model
                 'remark' => $this->remark,
             ]);
         }
+
         return $model;
     }
 

+ 5 - 4
backendApi/modules/v1/models/AdminRole.php

@@ -64,6 +64,7 @@ class AdminRole extends \common\components\ActiveRecord
             'UPDATE_ADMIN' => '更新管理员',
             'CREATED_AT' => '创建时间',
             'UPDATED_AT' => '更新时间',
+            'ADMIN_NAME' => '管理员名字'
         ];
     }
 
@@ -133,17 +134,17 @@ class AdminRole extends \common\components\ActiveRecord
             'CREATE_ADMIN' => [
                 'label' => '创建人',
                 'type' => function($data){
-                    $value = $data['value'];
+                    $value = is_array($data) && isset($data['value']) ? $data['value'] : '';
                     $result = Admin::findOneAsArray('ID=:ID', [':ID'=>$value], 'ADMIN_NAME');
-                    return $result['ADMIN_NAME'];
+                    return !empty($result) ? $result['ADMIN_NAME'] : '';
                 },
             ],
             'UPDATE_ADMIN' => [
                 'label' => '修改人',
                 'type' => function($data){
-                    $value = $data['value'];
+                    $value = isset($data['value']) ? $data['value']:'';
                     $result = Admin::findOneAsArray('ID=:ID', [':ID'=>$value], 'ADMIN_NAME');
-                    return $result['ADMIN_NAME'];
+                    return !empty($result) ? $result['ADMIN_NAME'] : 'ADMIN';
                 },
             ],
             'CREATED_AT' => [

+ 4 - 0
backendApi/modules/v1/models/LoginForm.php

@@ -137,6 +137,10 @@ class LoginForm extends Model {
             $this->_updateSuccessTimes();
             $transaction->commit();
             AdminLoginLogger::success($this->_user);
+
+            // 把用户的登录时间存在操作时间里
+            Yii::$app->tokenRedis->hset('admin:timeOut', $this->_user->getId(), time());
+
             return Yii::$app->user->loginWithUAndP($this->_user);
         }catch(\Exception $e){
             $transaction->rollBack();

+ 15 - 0
backendApi/modules/v1/models/lists/bonus/BalanceList.php

@@ -162,6 +162,21 @@ class BalanceList extends \common\libs\dataList\DataList implements DataListInte
                         'tag'=>['type'=>'danger', 'size' => 'small', 'class'=>'no-border'],
                     ],
                 ],
+                'EXCHANGE_POINTS' => [
+                    'header' => '兑换积分',
+                    'value' => function($row) {
+                        return (new Price([
+                            'value' => $row['EXCHANGE_POINTS'],
+                        ]))->result();
+                    },
+                    'headerOther' => [
+                        'width' => '150',
+                        'prop'=>'BONUS',
+                    ],
+                    'valueOther' => [
+                        'tag'=>['type'=>'danger', 'size' => 'small', 'class'=>'no-border'],
+                    ],
+                ],
                 'CASH' => [
                     'header' => '会员余额',
                     'value' => function($row) {

+ 226 - 0
backendApi/modules/v1/models/lists/bonus/FlowBalanceList.php

@@ -0,0 +1,226 @@
+<?php
+
+namespace backendApi\modules\v1\models\lists\bonus;
+
+use common\helpers\Cache;
+use common\helpers\user\Info;
+use common\libs\dataList\column\Price;
+use common\libs\dataList\column\YesNo;
+use common\libs\dataList\DataListInterface;
+use common\models\DealType;
+use common\models\FlowWallet;
+use common\libs\dataList\column\DateTime;
+use Yii;
+
+class FlowBalanceList extends \common\libs\dataList\DataList implements DataListInterface {
+    /**
+     * 列表名称
+     * @return string
+     */
+    public function getListName() {
+        return '会员余额流水';
+    }
+
+    /**
+     * 列表筛选到的数据
+     * @throws \yii\base\Exception
+     */
+    public function dataHandle() {
+        
+        $this->listData = FlowWallet::lists($this->condition, $this->params, [
+            'select' => 'FW.TRANSFER_SN,FW.USER_ID,FW.AMOUNT,FW.TOTAL,FW.IS_INCR,FW.REMARK,FW.PERIOD_NUM,FW.CALC_MONTH,FW.CREATED_AT,
+            U.USER_NAME,U.REAL_NAME,U.IS_DEC',
+            'orderBy' => 'FW.CREATED_AT DESC,FW.SORT DESC',
+            'from' => FlowWallet::tableName() . ' AS FW',
+            'join' => [
+                ['INNER JOIN', \common\models\User::tableName() . ' AS U', 'FW.USER_ID=U.ID'],
+            ],
+            'page' => $this->page,
+            'pageSize' => $this->pageSize,
+        ]);
+        // foreach ($this->listData['list'] as $key => $value) {
+        //     //$userInfo = Info::baseInfoZh($value['USER_ID']);
+        //     //$this->listData['list'][$key] = array_merge($userInfo, $value);
+        //     //$this->listData['list'][$key]['DEAL_TYPE_NAME'] = DealType::getAllTypesForShow()[$value['DEAL_TYPE_ID']]['TYPE_NAME'] ?? '';
+        //     // $this->listData['list'][$key]['LAST_DEC_LV_NAME'] = Cache::getDecLevelConfig()[$value['LAST_DEC_LV']]['LEVEL_NAME'] ?? '';
+        //     // $this->listData['list'][$key]['LAST_EMP_LV_NAME'] = Cache::getEmpLevelConfig()[$value['LAST_EMP_LV']]['LEVEL_NAME'] ?? '';
+        //     // $this->listData['list'][$key]['LAST_STATUS_NAME'] = \Yii::$app->params['userStatus'][$value['LAST_STATUS']]['label'] ?? '';
+        // }
+
+    }
+
+    /**
+     * 要展示和导出的所有字段
+     * @return array
+     */
+    public function getColumn() {
+        if (!$this->columns) {
+            $this->columns = [
+                // 'ID' => null,
+                'CREATED_AT' => [
+                    'header' => '创建时间',
+                    'value' => function ($row) {
+                        return (new DateTime([
+                            'value' => $row['CREATED_AT'],
+                        ]))->result();
+                    },
+                    'headerOther' => ['width' => '170'],
+                ],
+                'PERIOD_NUM' => '期数',
+                'CALC_MONTH' => '结算月',
+                'USER_NAME' => [
+                    'header' => '会员编号',
+                    'headerOther' => [
+                        'width' => '150',
+                    ],
+                    'valueOther' => [
+                        'tag' => ['type' => 'info', 'size' => 'small', 'class' => 'no-border']
+                    ],
+                ],
+                'REAL_NAME' => [
+                    'header' => '会员姓名',
+                    'headerOther' => [
+                        'width' => '120',
+                    ],
+                    'valueOther' => [
+                        'tag' => ['type' => 'success', 'size' => 'small', 'class' => 'no-border']
+                    ],
+                ],
+                // 'LAST_DEC_LV_NAME' => [
+                //     'header' => '会员级别',
+                //     'headerOther' => [
+                //         'width' => '110',
+                //     ],
+                //     'valueOther' => [
+                //         'tag' => ['type' => 'warning', 'size' => 'small', 'class' => 'no-border']
+                //     ],
+                // ],
+                // 'LAST_EMP_LV_NAME' => [
+                //     'header' => '聘级',
+                //     'headerOther' => [
+                //         'width' => '130',
+                //     ],
+                //     'valueOther' => [
+                //         'tag' => ['type' => 'warning', 'size' => 'small', 'class' => 'no-border']
+                //     ],
+                // ],
+//                'LAST_STATUS_NAME' => [
+//                    'header' => '会员状态',
+//                    'headerOther' => ['width' => '110'],
+//                ],
+//                'SYSTEM_NAME' => [
+//                    'header' => '体系',
+//                    'headerOther' => ['width' => '200'],
+//                ],
+                'IS_DEC' => [
+                    'header' => '是否报单中心',
+                    'value' => function ($row) {
+                        return (new YesNo([
+                            'value' => $row['IS_DEC'],
+                        ]))->result();
+                    },
+                    'headerOther' => function ($row) {
+                        return [
+                            'width' => '120',
+                        ];
+                    },
+                    'valueOther' => function ($row) {
+                        return [
+                            'tag' => ['type' => (isset($row['IS_DEC']) && $row['IS_DEC']) ? 'success' : 'info', 'size' => 'small']
+                        ];
+                    },
+                ],
+                'BEFORE_BALANCE' => [
+                    'header' => '交易前余额',
+                    'value' => function ($row) {
+                        return (new Price([
+                            'value' => $row['TOTAL'] - $row['AMOUNT'],
+                        ]))->result();
+                    },
+                    'headerOther' => [
+                        'width' => '150',
+                    ],
+                ],
+                'AMOUNT' => [
+                    'header' => '交易额',
+                    'value' => function ($row) {
+                        $result = (new Price([
+                            'value' => $row['AMOUNT'],
+                        ]))->result();
+                        return $row['IS_INCR'] > 0 ? '+' . $result : $result;
+                    },
+                    'headerOther' => [
+                        'width' => '150',
+                        'prop' => 'BONUS',
+                    ],
+                    'valueOther' => function ($row) {
+                        if ($row['IS_INCR'] > 0) {
+                            $type = 'success';
+                        } elseif ($row['IS_INCR'] == 0) {
+                            $type = 'danger';
+                        } else {
+                            $type = 'info';
+                        }
+                        return [
+                            'tag' => ['type' => $type, 'size' => 'small']
+                        ];
+                    },
+                ],
+                'TOTAL' => [
+                    'header' => '交易后余额',
+                    'value' => function ($row) {
+                        return (new Price([
+                            'value' => $row['TOTAL'],
+                        ]))->result();
+                    },
+                    'headerOther' => [
+                        'width' => '150',
+                    ],
+                ],
+                // 'ADMIN_NAME' => [
+                //     'header' => '操作人',
+                //     'headerOther' => ['width' => '110'],
+                // ],
+                'REMARK' => [
+                    'header' => '备注',
+                    'headerOther' => ['width' => '250'],
+                ],
+                'TRANSFER_SN' => [
+                    'header' => '流水号',
+                    'headerOther' => ['width' => '250'],
+                ],
+            ];
+        }
+        return $this->columns;
+    }
+
+    /**
+     * 前台用于筛选的类型集合
+     * @return mixed
+     */
+    public function getFilterTypes() {
+        if (!$this->filterTypes) {
+            $this->filterTypes = [
+                'CREATED_AT' => ['isUserTable' => false, 'name' => '创建时间', 'other' => 'date'],
+                'PERIOD_NUM' => ['isUserTable' => false, 'name' => '期数'],
+                'CALC_MONTH' => ['isUserTable' => false, 'name' => '结算月', 'other' => 'month'],
+                'DEAL_TYPE_NAME' => ['isUserTable' => false, 'name' => '交易类型', 'other' => 'dealTypes'],
+                'USER_NAME' => ['isUserTable' => false, 'name' => '会员编号'],
+                'REAL_NAME' => ['isUserTable' => false, 'name' => '会员姓名'],
+//                 'LAST_DEC_LV_NAME' => ['isUserTable' => false, 'name' => '会员级别', 'other' => 'decLevel'],
+//                 'LAST_EMP_LV_NAME' => ['isUserTable' => false, 'name' => '聘级', 'other' => 'empLevel'],
+// //                'LAST_STATUS_NAME' => ['isUserTable' => false, 'name' => '会员状态', 'other' => 'status'],
+// //                'SYSTEM_NAME' => ['isUserTable' => true, 'name' => '体系', 'other' => 'systems'],
+//                 'IS_DEC' => ['isUserTable' => false, 'name' => '是否报单中心', 'other' => 'yesOrNo'],
+//                'DEC_ROLE_NAME' => ['isUserTable' => true, 'name' => '报单中心级别', 'other' => 'decRole'],
+//                'IS_DIRECT_SELLER' => ['isUserTable' => true, 'name' => '是否直销员', 'other' => 'yesOrNo'],
+                'AMOUNT' => ['isUserTable' => false, 'name' => '交易额'],
+                'TOTAL' => ['isUserTable' => false, 'name' => '交易后余额'],
+                'ADMIN_NAME' => ['isUserTable' => false, 'name' => '操作人'],
+                'REMARK' => ['isUserTable' => false, 'name' => '备注'],
+                'TRANSFER_SN' => ['isUserTable' => false, 'name' => '流水号'],
+            ];
+        }
+        return $this->filterTypes;
+    }
+}

+ 207 - 0
backendApi/modules/v1/models/lists/bonus/FlowExchangePointsList.php

@@ -0,0 +1,207 @@
+<?php
+
+namespace backendApi\modules\v1\models\lists\bonus;
+
+use common\helpers\Cache;
+use common\helpers\user\Info;
+use common\libs\dataList\column\Price;
+use common\libs\dataList\column\YesNo;
+use common\libs\dataList\DataListInterface;
+use common\models\DealType;
+use common\libs\dataList\column\DateTime;
+use common\models\FlowExchangePoints;
+use Yii;
+
+class FlowExchangePointsList extends \common\libs\dataList\DataList implements DataListInterface {
+    /**
+     * 列表名称
+     * @return string
+     */
+    public function getListName() {
+        return '兑换积分流水';
+    }
+
+    /**
+     * 列表筛选到的数据
+     * @throws \yii\base\Exception
+     */
+    public function dataHandle() {
+        $this->listData = FlowExchangePoints::lists($this->condition, $this->params, [
+            'orderBy' => 'CREATED_AT DESC, ID DESC',
+            'page' => $this->page,
+            'pageSize' => $this->pageSize,
+        ]);
+        foreach ($this->listData['list'] as $key => $value) {
+            $userInfo = Info::baseInfoZh($value['USER_ID']);
+            $this->listData['list'][$key] = array_merge($userInfo, $value);
+            $this->listData['list'][$key]['DEAL_TYPE_NAME'] = DealType::getAllTypesForShow()[$value['DEAL_TYPE_ID']]['TYPE_NAME'] ?? '';
+            $this->listData['list'][$key]['LAST_DEC_LV_NAME'] = Cache::getDecLevelConfig()[$value['LAST_DEC_LV']]['LEVEL_NAME'] ?? '';
+            $this->listData['list'][$key]['LAST_EMP_LV_NAME'] = Cache::getEmpLevelConfig()[$value['LAST_EMP_LV']]['LEVEL_NAME'] ?? '';
+            $this->listData['list'][$key]['LAST_STATUS_NAME'] = \Yii::$app->params['userStatus'][$value['LAST_STATUS']]['label'] ?? '';
+        }
+    }
+
+    /**
+     * 要展示和导出的所有字段
+     * @return array
+     */
+    public function getColumn() {
+        if (!$this->columns) {
+            $this->columns = [
+                'ID' => null,
+                'CREATED_AT' => [
+                    'header' => '创建时间',
+                    'value' => function ($row) {
+                        return (new DateTime([
+                            'value' => $row['CREATED_AT'],
+                        ]))->result();
+                    },
+                    'headerOther' => ['width' => '170'],
+                ],
+                'PERIOD_NUM' => '期数',
+                'CALC_MONTH' => '结算月',
+                'DEAL_TYPE_NAME' => [
+                    'header' => '交易类型',
+                    'headerOther' => [
+                        'width' => '150',
+                    ],
+                ],
+                'USER_NAME' => [
+                    'header' => '会员编号',
+                    'headerOther' => [
+                        'width' => '150',
+                    ],
+                    'valueOther' => [
+                        'tag' => ['type' => 'info', 'size' => 'small', 'class' => 'no-border']
+                    ],
+                ],
+                'REAL_NAME' => [
+                    'header' => '会员姓名',
+                    'headerOther' => [
+                        'width' => '120',
+                    ],
+                    'valueOther' => [
+                        'tag' => ['type' => 'success', 'size' => 'small', 'class' => 'no-border']
+                    ],
+                ],
+                'LAST_DEC_LV_NAME' => [
+                    'header' => '会员级别',
+                    'headerOther' => [
+                        'width' => '110',
+                    ],
+                    'valueOther' => [
+                        'tag' => ['type' => 'warning', 'size' => 'small', 'class' => 'no-border']
+                    ],
+                ],
+                'LAST_EMP_LV_NAME' => [
+                    'header' => '聘级',
+                    'headerOther' => [
+                        'width' => '130',
+                    ],
+                    'valueOther' => [
+                        'tag' => ['type' => 'warning', 'size' => 'small', 'class' => 'no-border']
+                    ],
+                ],
+                'IS_DEC' => [
+                    'header' => '是否报单中心',
+                    'value' => function ($row) {
+                        return (new YesNo([
+                            'value' => $row['IS_DEC'],
+                        ]))->result();
+                    },
+                    'headerOther' => function ($row) {
+                        return [
+                            'width' => '120',
+                        ];
+                    },
+                    'valueOther' => function ($row) {
+                        return [
+                            'tag' => ['type' => (isset($row['IS_DEC']) && $row['IS_DEC']) ? 'success' : 'info', 'size' => 'small']
+                        ];
+                    },
+                ],
+                'BEFORE_BALANCE' => [
+                    'header' => '交易前余额',
+                    'value' => function ($row) {
+                        return (new Price([
+                            'value' => $row['TOTAL'] - $row['AMOUNT'],
+                        ]))->result();
+                    },
+                    'headerOther' => [
+                        'width' => '150',
+                    ],
+                ],
+                'AMOUNT' => [
+                    'header' => '交易额',
+                    'value' => function ($row) {
+                        $result = (new Price([
+                            'value' => $row['AMOUNT'],
+                        ]))->result();
+                        return $row['IS_INCR'] > 0 ? '+' . $result : $result;
+                    },
+                    'headerOther' => [
+                        'width' => '150',
+                        'prop' => 'BONUS',
+                    ],
+                    'valueOther' => function ($row) {
+                        if ($row['IS_INCR'] > 0) {
+                            $type = 'success';
+                        } elseif ($row['IS_INCR'] == 0) {
+                            $type = 'danger';
+                        } else {
+                            $type = 'info';
+                        }
+                        return [
+                            'tag' => ['type' => $type, 'size' => 'small']
+                        ];
+                    },
+                ],
+                'TOTAL' => [
+                    'header' => '交易后余额',
+                    'value' => function ($row) {
+                        return (new Price([
+                            'value' => $row['TOTAL'],
+                        ]))->result();
+                    },
+                    'headerOther' => [
+                        'width' => '150',
+                    ],
+                ],
+                'ADMIN_NAME' => [
+                    'header' => '操作人',
+                    'headerOther' => ['width' => '110'],
+                ],
+                'REMARK' => [
+                    'header' => '备注',
+                    'headerOther' => ['width' => '250'],
+                ],
+            ];
+        }
+        return $this->columns;
+    }
+
+    /**
+     * 前台用于筛选的类型集合
+     * @return mixed
+     */
+    public function getFilterTypes() {
+        if (!$this->filterTypes) {
+            $this->filterTypes = [
+                'CREATED_AT' => ['isUserTable' => false, 'name' => '创建时间', 'other' => 'date'],
+                'PERIOD_NUM' => ['isUserTable' => false, 'name' => '期数'],
+                'CALC_MONTH' => ['isUserTable' => false, 'name' => '结算月', 'other' => 'month'],
+                'DEAL_TYPE_NAME' => ['isUserTable' => false, 'name' => '交易类型', 'other' => 'dealTypes'],
+                'USER_NAME' => ['isUserTable' => true, 'name' => '会员编号'],
+                'REAL_NAME' => ['isUserTable' => true, 'name' => '会员姓名'],
+                'LAST_DEC_LV_NAME' => ['isUserTable' => false, 'name' => '会员级别', 'other' => 'decLevel'],
+                'LAST_EMP_LV_NAME' => ['isUserTable' => false, 'name' => '聘级', 'other' => 'empLevel'],
+                'IS_DEC' => ['isUserTable' => true, 'name' => '是否报单中心', 'other' => 'yesOrNo'],
+                'AMOUNT' => ['isUserTable' => false, 'name' => '交易额'],
+                'TOTAL' => ['isUserTable' => false, 'name' => '交易后余额'],
+                'ADMIN_NAME' => ['isUserTable' => false, 'name' => '操作人'],
+                'REMARK' => ['isUserTable' => false, 'name' => '备注'],
+            ];
+        }
+        return $this->filterTypes;
+    }
+}

+ 169 - 131
backendApi/modules/v1/models/lists/bonus/PeriodBonusList.php

@@ -275,30 +275,6 @@ class PeriodBonusList extends \common\libs\dataList\DataList implements DataList
 //                        'prop'=>'UP_SURPLUS_3L',
 //                    ],
 //                ],
-                'BONUS_BD' => [
-                    'header' => '服务奖',
-                    'value' => function($row) {
-                        return (new Price([
-                            'value' => $row['BONUS_BD'],
-                        ]))->result();
-                    },
-                    'headerOther' => [
-                        'width' => '120',
-                        'prop'=>'BONUS_BD',
-                    ],
-                ],
-                'ORI_BONUS_BD' => [
-                    'header' => '服务奖原金额',
-                    'value' => function($row) {
-                        return (new Price([
-                            'value' => $row['ORI_BONUS_BD'],
-                        ]))->result();
-                    },
-                    'headerOther' => [
-                        'width' => '120',
-                        'prop'=>'ORI_BONUS_BD',
-                    ],
-                ],
                 'BONUS_TG' => [
                     'header' => '推广奖',
                     'value' => function($row) {
@@ -323,54 +299,78 @@ class PeriodBonusList extends \common\libs\dataList\DataList implements DataList
                         'prop'=>'ORI_BONUS_TG',
                     ],
                 ],
-                'BONUS_XF' => [
-                    'header' => '消费奖',
+                'BONUS_QY' => [
+                    'header' => '团队奖',
                     'value' => function($row) {
                         return (new Price([
-                            'value' => $row['BONUS_XF'],
+                            'value' => $row['BONUS_QY'],
                         ]))->result();
                     },
                     'headerOther' => [
                         'width' => '120',
-                        'prop'=>'BONUS_XF',
+                        'prop'=>'BONUS_QY',
                     ],
                 ],
-                'ORI_BONUS_XF' => [
-                    'header' => '消费奖原金额',
+                'ORI_BONUS_QY' => [
+                    'header' => '团队奖原金额',
                     'value' => function($row) {
                         return (new Price([
-                            'value' => $row['ORI_BONUS_XF'],
+                            'value' => $row['ORI_BONUS_QY'],
                         ]))->result();
                     },
                     'headerOther' => [
                         'width' => '120',
-                        'prop'=>'ORI_BONUS_XF',
+                        'prop'=>'ORI_BONUS_QY',
                     ],
                 ],
-                'BONUS_YJ' => [
-                    'header' => '业绩奖',
+                'ORI_BONUS_QY_BD' => [
+                    'header' => '报单团队奖原金额',
                     'value' => function($row) {
                         return (new Price([
-                            'value' => $row['BONUS_YJ'],
+                            'value' => $row['ORI_BONUS_QY_BD'],
                         ]))->result();
                     },
                     'headerOther' => [
                         'width' => '120',
-                        'prop'=>'BONUS_YJ',
+                        'prop'=>'ORI_BONUS_QY_BD',
                     ],
                 ],
-                'ORI_BONUS_YJ' => [
-                    'header' => '业绩奖原金额',
+                'BONUS_BS' => [
+                    'header' => '蓝星管理奖',
                     'value' => function($row) {
                         return (new Price([
-                            'value' => $row['ORI_BONUS_YJ'],
+                            'value' => $row['BONUS_BS'],
                         ]))->result();
                     },
                     'headerOther' => [
                         'width' => '120',
-                        'prop'=>'ORI_BONUS_YJ',
+                        'prop'=>'BONUS_BS',
                     ],
                 ],
+                'ORI_BONUS_BS' => [
+                    'header' => '蓝星管理奖原金额',
+                    'value' => function($row) {
+                        return (new Price([
+                            'value' => $row['ORI_BONUS_BS'],
+                        ]))->result();
+                    },
+                    'headerOther' => [
+                        'width' => '120',
+                        'prop'=>'ORI_BONUS_BS',
+                    ],
+                ],
+                // 'REAL_BONUS_BS' => [
+                //     'header' => '实发蓝星管理奖',
+                //     'value' => function($row) {
+                //         return (new Price([
+                //             'value' => $row['REAL_BONUS_BS'],
+                //         ]))->result();
+                //     },
+                //     'headerOther' => [
+                //         'width' => '120',
+                //         'prop'=>'REAL_BONUS_BS',
+                //     ],
+                // ],
                 'BONUS_GX' => [
                     'header' => '共享奖',
                     'value' => function($row) {
@@ -407,228 +407,266 @@ class PeriodBonusList extends \common\libs\dataList\DataList implements DataList
                         'prop'=>'REAL_BONUS_GX',
                     ],
                 ],
-                'BONUS_GL' => [
-                    'header' => '管理奖',
+                'BONUS_BD' => [
+                    'header' => '服务奖',
                     'value' => function($row) {
                         return (new Price([
-                            'value' => $row['BONUS_GL'],
+                            'value' => $row['BONUS_BD'],
                         ]))->result();
                     },
                     'headerOther' => [
                         'width' => '120',
-                        'prop'=>'BONUS_GL',
+                        'prop'=>'BONUS_BD',
                     ],
                 ],
-                'ORI_BONUS_GL' => [
-                    'header' => '管理奖原金额',
+                'ORI_BONUS_BD' => [
+                    'header' => '服务奖原金额',
                     'value' => function($row) {
                         return (new Price([
-                            'value' => $row['ORI_BONUS_GL'],
+                            'value' => $row['ORI_BONUS_BD'],
                         ]))->result();
                     },
                     'headerOther' => [
                         'width' => '120',
-                        'prop'=>'ORI_BONUS_GL',
+                        'prop'=>'ORI_BONUS_BD',
                     ],
                 ],
-                'REAL_BONUS_GL' => [
-                    'header' => '实发管理奖',
+                'BONUS_REAL' => [
+                    'header' => '实发奖',
                     'value' => function($row) {
                         return (new Price([
-                            'value' => $row['REAL_BONUS_GL'],
+                            'value' => $row['BONUS_REAL'],
                         ]))->result();
                     },
                     'headerOther' => [
                         'width' => '120',
-                        'prop'=>'REAL_BONUS_GL',
+                        'prop'=>'BONUS_REAL',
                     ],
                 ],
-                'BONUS_QY' => [
-                    'header' => '团队奖',
+                'BONUS_TOTAL' => [
+                    'header' => '总奖金',
                     'value' => function($row) {
                         return (new Price([
-                            'value' => $row['BONUS_QY'],
+                            'value' => $row['BONUS_TOTAL'],
                         ]))->result();
                     },
                     'headerOther' => [
                         'width' => '120',
-                        'prop'=>'BONUS_QY',
+                        'prop'=>'BONUS_TOTAL',
                     ],
                 ],
-                'ORI_BONUS_QY' => [
-                    'header' => '团队奖原金额',
+                'MANAGE_TAX' => [
+                    'header' => '管理费',
                     'value' => function($row) {
                         return (new Price([
-                            'value' => $row['ORI_BONUS_QY'],
+                            'value' => $row['MANAGE_TAX'],
                         ]))->result();
                     },
                     'headerOther' => [
                         'width' => '120',
-                        'prop'=>'ORI_BONUS_QY',
+                        'prop'=>'MANAGE_TAX',
                     ],
                 ],
-                'ORI_BONUS_QY_BD' => [
-                    'header' => '报单团队奖原金额',
+                'RECONSUME_POINTS' => [
+                    'header' => '复销积分',
                     'value' => function($row) {
                         return (new Price([
-                            'value' => $row['ORI_BONUS_QY_BD'],
+                            'value' => $row['RECONSUME_POINTS'],
                         ]))->result();
                     },
                     'headerOther' => [
                         'width' => '120',
-                        'prop'=>'ORI_BONUS_QY_BD',
+                        'prop'=>'RECONSUME_POINTS',
                     ],
                 ],
-//                'BONUS_FW' => [
-//                    'header' => '服务奖',
-//                    'value' => function($row) {
-//                        return (new Price([
-//                            'value' => $row['BONUS_FW'],
-//                        ]))->result();
-//                    },
-//                    'headerOther' => [
-//                        'width' => '120',
-//                        'prop'=>'BONUS_FW',
-//                    ],
-//                ],
-//                'ORI_BONUS_FW' => [
-//                    'header' => '服务奖原金额',
-//                    'value' => function($row) {
-//                        return (new Price([
-//                            'value' => $row['ORI_BONUS_FW'],
-//                        ]))->result();
-//                    },
-//                    'headerOther' => [
-//                        'width' => '120',
-//                        'prop'=>'ORI_BONUS_FW',
-//                    ],
-//                ],
-                'BONUS_YC' => [
-                    'header' => '荣衔奖',
+                'BONUS_INCOME' => [
+                    'header' => '总收入',
                     'value' => function($row) {
                         return (new Price([
-                            'value' => $row['BONUS_YC'],
+                            'value' => $row['BONUS_INCOME'],
                         ]))->result();
                     },
                     'headerOther' => [
                         'width' => '120',
-                        'prop'=>'BONUS_YC',
+                        'prop'=>'BONUS_INCOME',
                     ],
                 ],
-                'ORI_BONUS_YC' => [
-                    'header' => '荣衔奖原金额',
+                'ORI_BONUS_STANDARD' => [
+                    'header' => '团队成长奖',
                     'value' => function($row) {
                         return (new Price([
-                            'value' => $row['ORI_BONUS_YC'],
+                            'value' => $row['ORI_BONUS_STANDARD'],
                         ]))->result();
                     },
                     'headerOther' => [
                         'width' => '120',
-                        'prop'=>'ORI_BONUS_YC',
+                        'prop'=>'ORI_BONUS_STANDARD',
                     ],
                 ],
-                'BONUS_VIP' => [
-                    'header' => 'VIP奖',
+                'CALC_MONTH' => [
+                    'header' => '结算月',
+                    'headerOther' => [
+                        'width' => '100',
+                    ],
+                ],
+                'BONUS_XF' => [
+                    'header' => '消费奖',
                     'value' => function($row) {
                         return (new Price([
-                            'value' => $row['BONUS_VIP'],
+                            'value' => $row['BONUS_XF'],
                         ]))->result();
                     },
                     'headerOther' => [
                         'width' => '120',
-                        'prop'=>'BONUS_VIP',
+                        'prop'=>'BONUS_XF',
                     ],
                 ],
-                'ORI_BONUS_VIP' => [
-                    'header' => 'VIP奖原金额',
+                'ORI_BONUS_XF' => [
+                    'header' => '消费奖原金额',
                     'value' => function($row) {
                         return (new Price([
-                            'value' => $row['ORI_BONUS_VIP'],
+                            'value' => $row['ORI_BONUS_XF'],
                         ]))->result();
                     },
                     'headerOther' => [
                         'width' => '120',
-                        'prop'=>'ORI_BONUS_VIP',
+                        'prop'=>'ORI_BONUS_XF',
                     ],
                 ],
-                'BONUS_REAL' => [
-                    'header' => '实发奖金',
+                'BONUS_YJ' => [
+                    'header' => '业绩奖',
                     'value' => function($row) {
                         return (new Price([
-                            'value' => $row['BONUS_REAL'],
+                            'value' => $row['BONUS_YJ'],
                         ]))->result();
                     },
                     'headerOther' => [
                         'width' => '120',
-                        'prop'=>'BONUS_REAL',
+                        'prop'=>'BONUS_YJ',
                     ],
                 ],
-                'BONUS_TOTAL' => [
-                    'header' => '总奖金',
+                'ORI_BONUS_YJ' => [
+                    'header' => '业绩奖原金额',
                     'value' => function($row) {
                         return (new Price([
-                            'value' => $row['BONUS_TOTAL'],
+                            'value' => $row['ORI_BONUS_YJ'],
                         ]))->result();
                     },
                     'headerOther' => [
                         'width' => '120',
-                        'prop'=>'BONUS_TOTAL',
+                        'prop'=>'ORI_BONUS_YJ',
                     ],
                 ],
-                'MANAGE_TAX' => [
-                    'header' => '管理费',
+                'BONUS_YC' => [
+                    'header' => '荣衔奖',
                     'value' => function($row) {
                         return (new Price([
-                            'value' => $row['MANAGE_TAX'],
+                            'value' => $row['BONUS_YC'],
                         ]))->result();
                     },
                     'headerOther' => [
                         'width' => '120',
-                        'prop'=>'MANAGE_TAX',
+                        'prop'=>'BONUS_YC',
                     ],
                 ],
-                'RECONSUME_POINTS' => [
-                    'header' => '复销积分',
+                'ORI_BONUS_YC' => [
+                    'header' => '荣衔奖原金额',
                     'value' => function($row) {
                         return (new Price([
-                            'value' => $row['RECONSUME_POINTS'],
+                            'value' => $row['ORI_BONUS_YC'],
                         ]))->result();
                     },
                     'headerOther' => [
                         'width' => '120',
-                        'prop'=>'RECONSUME_POINTS',
+                        'prop'=>'ORI_BONUS_YC',
                     ],
                 ],
-                'BONUS_INCOME' => [
-                    'header' => '总收入',
+                'BONUS_VIP' => [
+                    'header' => 'VIP奖',
                     'value' => function($row) {
                         return (new Price([
-                            'value' => $row['BONUS_INCOME'],
+                            'value' => $row['BONUS_VIP'],
                         ]))->result();
                     },
                     'headerOther' => [
                         'width' => '120',
-                        'prop'=>'BONUS_INCOME',
+                        'prop'=>'BONUS_VIP',
                     ],
                 ],
-                'ORI_BONUS_STANDARD' => [
-                    'header' => '团队成长奖',
+                'ORI_BONUS_VIP' => [
+                    'header' => 'VIP奖原金额',
                     'value' => function($row) {
                         return (new Price([
-                            'value' => $row['ORI_BONUS_STANDARD'],
+                            'value' => $row['ORI_BONUS_VIP'],
                         ]))->result();
                     },
                     'headerOther' => [
                         'width' => '120',
-                        'prop'=>'ORI_BONUS_STANDARD',
+                        'prop'=>'ORI_BONUS_VIP',
                     ],
                 ],
-                'CALC_MONTH' => [
-                    'header' => '结算月',
+                'BONUS_GL' => [
+                    'header' => '管理奖',
+                    'value' => function($row) {
+                        return (new Price([
+                            'value' => $row['BONUS_GL'],
+                        ]))->result();
+                    },
                     'headerOther' => [
-                        'width' => '100',
+                        'width' => '120',
+                        'prop'=>'BONUS_GL',
                     ],
                 ],
+                'ORI_BONUS_GL' => [
+                    'header' => '管理奖原金额',
+                    'value' => function($row) {
+                        return (new Price([
+                            'value' => $row['ORI_BONUS_GL'],
+                        ]))->result();
+                    },
+                    'headerOther' => [
+                        'width' => '120',
+                        'prop'=>'ORI_BONUS_GL',
+                    ],
+                ],
+                'REAL_BONUS_GL' => [
+                    'header' => '实发管理奖',
+                    'value' => function($row) {
+                        return (new Price([
+                            'value' => $row['REAL_BONUS_GL'],
+                        ]))->result();
+                    },
+                    'headerOther' => [
+                        'width' => '120',
+                        'prop'=>'REAL_BONUS_GL',
+                    ],
+                ],
+//                'BONUS_FW' => [
+//                    'header' => '服务奖',
+//                    'value' => function($row) {
+//                        return (new Price([
+//                            'value' => $row['BONUS_FW'],
+//                        ]))->result();
+//                    },
+//                    'headerOther' => [
+//                        'width' => '120',
+//                        'prop'=>'BONUS_FW',
+//                    ],
+//                ],
+//                'ORI_BONUS_FW' => [
+//                    'header' => '服务奖原金额',
+//                    'value' => function($row) {
+//                        return (new Price([
+//                            'value' => $row['ORI_BONUS_FW'],
+//                        ]))->result();
+//                    },
+//                    'headerOther' => [
+//                        'width' => '120',
+//                        'prop'=>'ORI_BONUS_FW',
+//                    ],
+//                ],
+                
+                
             ];
         }
         return $this->columns;

+ 3 - 1
backendApi/modules/v1/models/lists/bonus/TraceUpQyList.php

@@ -42,7 +42,7 @@ class TraceUpQyList extends \common\libs\dataList\DataList implements DataListIn
         $userId = $this->others['userId'];
         $periodNum = $this->others['periodNum'];
         $data = UserNetwork::getAllParentFromPeriodWithPage($userId, $periodNum);
-        if ($data['list']) {
+        if (isset($data['list']) && $data['list']) {
             $decTotal = CalcCache::nowPeriodPerf($userId, $periodNum);
             foreach ($data['list'] as $key => $value) {
                 $perfPeriod = PerfPeriod::findOneAsArray('USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM',[':USER_ID'=>$value['USER_ID'],':PERIOD_NUM'=>$periodNum]);
@@ -73,6 +73,8 @@ class TraceUpQyList extends \common\libs\dataList\DataList implements DataListIn
                 $data['list'][$key]['QY_5L'] = $data['list'][$key]['PV_5L_TOUCH'] + $pervSurplusPerf['SURPLUS_5L'];
                 unset($bonus,$bigLocation);
             }
+        } else {
+            $data['list'] = [];
         }
         $this->listData = $data;
     }

+ 23 - 7
backendApi/modules/v1/models/lists/shop/GoodsList.php

@@ -45,10 +45,26 @@ class GoodsList extends \common\libs\dataList\DataList implements DataListInterf
                     'header' => '商品编号',
                     'headerOther' => ['width' => '200'],
                 ],
-                'TYPE' => [
-                    'header' => '商品来源',
-                    'value' => function($row){
-                        return ShopGoods::GOODS_TYPE[$row['TYPE']]['name'];
+                // 'TYPE' => [
+                //     'header' => '商品来源',
+                //     'value' => function($row){
+                //         return ShopGoods::GOODS_TYPE[$row['TYPE']]['name'];
+                //     },
+                //     'headerOther' => ['width' => '150'],
+                // ],
+                'SELL_DISCOUNT' => [
+                    'header' => '商品折扣',
+                    'value' => function($row) {
+                        $discount = 0;
+                        if ($row['TYPE'] == 1) {
+                            $discount = '0.5';
+                        } else if($row['TYPE'] == 2) {
+                            $discount = '0.6';
+                        } else {
+                            $discount = $row['SELL_DISCOUNT'];
+                        }
+
+                        return $discount;
                     },
                     'headerOther' => ['width' => '150'],
                 ],
@@ -67,7 +83,7 @@ class GoodsList extends \common\libs\dataList\DataList implements DataListInterf
                     'headerOther' => ['width' => '150'],
                 ],
                 'SELL_TYPE' => [
-                    'header' => '出售方式',
+                    'header' => '复消购买方式',
                     'value' => function($row){
                         $sellType = ShopGoods::SALE_TYPE;
                         $sel = explode(',',$row['SELL_TYPE']);
@@ -144,12 +160,12 @@ class GoodsList extends \common\libs\dataList\DataList implements DataListInterf
     {
         if(!$this->filterTypes){
             $this->filterTypes = [
-                'TYPE' => ['isUserTable' => false, 'name' => '商品来源', 'other' => 'select', 'selectData' => [['id' => 1, 'name' => '国内商品'], ['id' => 2, 'name' => '进口商品']]],
+                //'TYPE' => ['isUserTable' => false, 'name' => '商品来源', 'other' => 'select', 'selectData' => [['id' => 1, 'name' => '国内商品'], ['id' => 2, 'name' => '进口商品']]],
                 'GIFT_TYPE' => ['isUserTable' => false, 'name' => '商品类型', 'other' => 'select', 'selectData' => [['id' => 1, 'name' => '报单区'], ['id' => 2, 'name' => '复消区'], ['id' => 3, 'name' => '工作室报单'], ['id' => 4, 'name' => '工作室复消']]],
                 'STATUS'=> ['name'=> '状态', 'other'=> 'select', 'selectData'=> [['id'=> 0, 'name'=> '已下架'],['id'=> 1, 'name'=> '已上架']]],
                 'GOODS_NAME'=> ['name'=> '商品名称'],
                 'GOODS_NO'=> ['name'=> '商品编号'],
-                'SELL_TYPE'=> ['name'=> '出售方式', 'other'=> 'select', 'selectData'=> [['id'=> 1, 'name'=> '余额购买'],['id'=> 2, 'name'=> '积分购买']]],
+                'SELL_TYPE'=> ['name'=> '复消购买方式', 'other'=> 'select', 'selectData'=> [['id'=> 1, 'name'=> '余额购买'],['id'=> 2, 'name'=> '积分购买']]],
                 'SELL_PRICE'=> ['name'=> '销售价格'],
                 'PRICE_PV'=> ['name'=> '销售PV'],
             ];

+ 3 - 1
common/components/ActiveRecord.php

@@ -284,6 +284,8 @@ class ActiveRecord extends \yii\db\ActiveRecord {
         self::prepare($condition, $params, $argv, true);
         unset($condition, $params, $argv);
         $countQuery = clone self::$query;
+        // self::$rawSql = self::$query->createCommand()->getRawSql();
+        // var_dump(self::$rawSql);exit;
         $count = $countQuery->count(self::$argv['count']); // 得到总数
         $pagination = new Pagination(['totalCount' => $count]);
         $pagination->setPageSize(self::$argv['pageSize']);
@@ -295,7 +297,7 @@ class ActiveRecord extends \yii\db\ActiveRecord {
             self::$query->asArray();
         }
         $lists = self::$query->all();
-        //self::$rawSql = self::$query->createCommand()->getRawSql();
+        
         self::$query = null;
         unset($countQuery);
         $startNum = $pagination->page * $pagination->pageSize + 1;

+ 5 - 0
common/config/params.php

@@ -9,6 +9,7 @@ return [
     'frontAccessTokenExpiresIn' => 3000 * 60,
     'frontRefreshTokenExpiresIn' => 3000 * 60 * 60,
     'user.passwordResetTokenExpire' => 3600,
+    'operationTimeOut' => 15 * 60,     // 这里设置的15分钟超时
     'pageSize' => 20,
     'http' => [
         'shopApi' => [
@@ -196,6 +197,10 @@ return [
             'name' => 'cash',
             'label' => '会员账户余额',
         ],
+        'exchange_points' => [
+            'name' => 'bonus',
+            'label' => '兑换积分余额',
+        ]
 //        'cf' => [
 //            'name' => 'cf',
 //            'label' => '车房养老奖余额',

+ 363 - 28
common/helpers/bonus/BonusCalc.php

@@ -14,6 +14,7 @@ use common\helpers\snowflake\SnowFake;
 use common\helpers\Tool;
 use common\models\CalcBonus;
 use common\models\CalcBonusBD;
+use common\models\CalcBonusBS;
 use common\models\CalcBonusBT;
 use common\models\CalcBonusCF;
 use common\models\CalcBonusFL;
@@ -32,6 +33,7 @@ use common\models\CalcBonusXF;
 use common\models\CalcBonusYC;
 use common\models\CalcBonusYJ;
 use common\models\CalcMonthBonusUser;
+use common\models\Config;
 use common\models\FlowDeductZR;
 use common\models\PerfCompany;
 use common\models\PerfMonth;
@@ -41,6 +43,8 @@ use common\models\ResendQY;
 use common\models\DeclarationLevel;
 use common\models\DecOrder;
 use common\models\EmployLevel;
+use common\models\FlowBonus;
+use common\models\PerfActiveUser;
 use common\models\ScoreMonth;
 use common\models\User;
 use common\models\UserInfo;
@@ -84,6 +88,8 @@ class BonusCalc extends BaseObject {
 
     const LOOP_FINISH = 1;
     const LOOP_CONTINUE = 2;
+    const GX_FLOOR_LIMIT = 5; // 共享奖向上找的最大层级
+    const GX_LIMIT_SWITCH = true; // 是否开启共享奖向上找的最大限制  true 为开启 false 关闭  
 
     const ORDER_TYPE_TO_FW_COEFFICIENT = [
         'ZC' => 'fwCoefficientFromZc',
@@ -224,7 +230,7 @@ class BonusCalc extends BaseObject {
             }
             $t9 = microtime(true);
             echo('计算团队奖'.($this->_sysConfig['openQY']['VALUE']?'完成':'关闭').',耗时:' . round($t9 - $t8, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
-            $this->_updatePercent(40);
+            $this->_updatePercent(65);
 
             if($this->_sysConfig['openGX']['VALUE']) {
                 $this->calcBonusGXBefore();
@@ -232,7 +238,7 @@ class BonusCalc extends BaseObject {
             }
             $t11 = microtime(true);
             echo('计算共享奖'.($this->_sysConfig['openGX']['VALUE']?'完成':'关闭').',耗时:' . round($t11 - $t9, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
-            $this->_updatePercent(45);
+            $this->_updatePercent(68);
 
             if($this->_sysConfig['openGL']['VALUE']) {
                 $this->calcBonusBdGL();
@@ -270,6 +276,15 @@ class BonusCalc extends BaseObject {
             echo('计算达标奖'.($this->_sysConfig['openJXS']['VALUE']?'完成':'关闭').',耗时:' . round($t18 - $t17, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
             $this->_updatePercent(65);
 
+            // 蓝星奖入库,实际上是插入有奖金会员数据缓存中.
+            // 调用存储过程,计算蓝星管理奖金
+            $this->calcBsProcedure();
+            // 将有蓝星管理奖金的用户加入到有奖金缓存用户中
+            $this->calcBonusBsGL();
+            $t18temp = microtime(true);
+            echo('计算蓝星管理奖'.($this->_sysConfig['openGL']['VALUE']?'完成':'关闭').',耗时:' . round($t18temp - $t18, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
+            $this->_updatePercent(65);
+
             //把奖金会员写入缓存
             $this->loopMonthBonusUserFromDbToCache();
             $t19 = microtime(true);
@@ -277,13 +292,16 @@ class BonusCalc extends BaseObject {
             $this->_updatePercent(70);
 
             //奖金写库
+            // 这里增加新的奖金入库操作.
             $this->loopBonusUsers();
+            // 入库完成,将各个奖金计算流水会员聘级,更新成蓝星奖当时计算的聘级
+            $this->loopCalcBlueEmpLv();
             $this->_updatePercent(75);
             unset($calcWrite);
             $t20 = microtime(true);
             echo('奖金写库操作完成,耗时:' . round($t20 - $t19, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
 
-            //把本期奖金会员入库
+            //把本期奖金会员入库 - 把缓存中的月奖用户信息存到数据库.存储过程的入库不在这里进行,这里代码取的缓存,存储过程没有缓存,在上面进行入库
             $this->loopMonthBonusUserToDb();
             $t21 = microtime(true);
             echo('奖金会员入库完成,耗时:' . round($t21 - $t20, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
@@ -1395,8 +1413,14 @@ class BonusCalc extends BaseObject {
             foreach ($allData as $userId) {
                 //判断$userId 能否得共享奖
 
-                //判断 是否本期小市场(安置关系)新增980pv 能否得奖
-                if ( !$this->checkSmallMarketPerf($userId) ) {
+                // //判断 是否本期小市场(安置关系)新增980pv 能否得奖
+                // if ( !$this->checkSmallMarketPerf($userId) ) {
+                //     unset($userId);
+                //     continue;
+                // }
+
+                // 20220407 小市场980判断->改成判断此期用户是否有原报单团队奖金
+                if ( !$this->checkHasOriBonusQyBd($userId) ) {
                     unset($userId);
                     continue;
                 }
@@ -1441,6 +1465,12 @@ class BonusCalc extends BaseObject {
         if ($allData) {
             echo sprintf("时间:[%s]共享奖,当前offset为:【%s】" . PHP_EOL, date('Y-m-d H:i:s', time()) , $offset);
             $insertBonusData = [];
+            // 获取线上找几层和是否开启找几层的限制
+            $configsGx = Config::find()->where(
+                'CONFIG_NAME="gxNoPvFindLimitSwitch" OR CONFIG_NAME="gxNoPvFindLimitTimes"'
+            )->orderBy('SORT ASC')->indexBy('CONFIG_NAME')->asArray()->all();
+            $openFindLimit = isset($configsGx['gxNoPvFindLimitSwitch']) ? $configsGx['gxNoPvFindLimitSwitch']['VALUE'] : 1; // 是否开放了 得奖人不满足980就找一个满足980的人来得这个奖 的最大向上循环次数
+            $findLimitTimes = isset($configsGx['gxNoPvFindLimitTimes']) ? $configsGx['gxNoPvFindLimitTimes']['VALUE'] : 5 ; // 开放的限制层数
             foreach ($allData as $userId) {
                 $bonusUserData = [];
                 $bonusPercentOne = $this->_sysConfig['shareRecPercent']['VALUE'] / 100;
@@ -1496,12 +1526,14 @@ class BonusCalc extends BaseObject {
                 $userEmpLevel = $userBaseInfo['EMP_LV'];
                 foreach ($bonusUserData as $bonusUserDataEvery) {
                     $bonusUserId = $bonusUserDataEvery['bonusUid'];
-                    //判断 是否本期小市场(安置关系)新增980pv 能否得奖
-                    if ( $bonusUserDataEvery['validMinPv'] && !$this->checkSmallMarketPerf($bonusUserId) ) {
-//                        unset($bonusUserDataEvery, $bonusUserId);
+                    //判断 是否本期小市场(安置关系)新增980pv 能否得奖->20220407改成判断得奖人此期是否有报单团队奖金
+                    // if ( $bonusUserDataEvery['validMinPv'] && !$this->checkSmallMarketPerf($bonusUserId) ) { 20220407
+                    if ( $bonusUserDataEvery['validMinPv'] && !$this->checkHasOriBonusQyBd($bonusUserId) ) {
+//                        unset($bonusUserDataEvery, $bonusUserId); 
 //                        continue;
                         //得奖人不满足980就找一个满足980的人来得这个奖
-                        $bonusUserId = $this->getMinBdPvNetworkParent($bonusUserId);
+                        // 20220407改成判断得奖人此期是否有报单团队奖金,如果没有则找一个此期有报单团队奖金得人
+                        $bonusUserId = $this->getMinBdPvNetworkParent($bonusUserId, $openFindLimit, $findLimitTimes);
                         if ( !$bonusUserId ) {
                             unset($bonusUserDataEvery, $bonusUserId);
                             continue;
@@ -1566,6 +1598,60 @@ class BonusCalc extends BaseObject {
         return true;
     }
 
+    // 执行蓝星管理奖金的存储过程
+    public function calcBsProcedure() {
+        if( !$this->_isCalcMonth ) {
+            // 不是结算月,则不进行计算
+            return false;
+        }
+        $result = \Yii::$app->db->createCommand("CALL CalcBlue(:periodNum)") 
+                      ->bindValue(':periodNum' , $this->_periodNum )
+                      ->execute();
+                      
+        return $result;
+    }
+
+    /**
+     * 蓝星管理奖金
+     * @param int $offset
+     * @return bool
+     * @throws \yii\db\Exception
+     */
+    public function calcBonusBsGL(int $offset = 0) {
+        if( !$this->_isCalcMonth ) {
+            // 不是结算月,则不进行计算
+            return false;
+        }
+        // 从缓存获取分页有收入的会员信息
+        $allData = CalcBonusBS::findUseDbCalc()
+            ->where('PERIOD_NUM=:PERIOD_NUM', [':PERIOD_NUM' => $this->_periodNum])
+            ->groupBy('USER_ID')
+            ->offset($offset)
+            ->limit($this->_limit)
+            ->asArray()
+            ->all();
+        if ($allData) {
+            foreach ($allData as $user) {
+                // 添加到有奖励信息的数据中
+                CalcCache::addHasBonusUsers($user['USER_ID'], $this->_periodNum);
+                //CalcCache::addHasMonthBonusUsers($user['USER_ID'], $this->_periodNum);
+                //扣除相应的复消积分和管理费
+                $deductData = $this->deduct($user['USER_ID'], $user['ORI_BONUS']);
+                // 把对碰后的奖金存入缓存中
+                CalcCache::bonus($user['USER_ID'], $this->_periodNum, 'BONUS_BS', $user['ORI_BONUS'], $deductData);
+                $realBonusBs = $deductData['surplus']; // 扣除管理费和复消积分后的实发蓝星奖金
+                $manageTax = $deductData['manageTax']; // 管理费
+                $point = $deductData['reConsumePoints'];// 复消积分
+                // 更新蓝星奖金存储过程的实发金额数据
+                CalcBonusBS::updateAll(['AMOUNT' => $realBonusBs, 'MANAGE_TAX' => $manageTax, 'RECONSUME_POINTS' => $point], 
+                'USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM', 
+                [':USER_ID' => $user['USER_ID'], ':PERIOD_NUM' => $this->_periodNum]);
+            }
+            return $this->calcBonusBsGL($offset + $this->_limit);
+        }
+        unset($allData);
+        return true;
+    }
 
     /**
      * 报单管理奖
@@ -2651,6 +2737,19 @@ class BonusCalc extends BaseObject {
         return true;
     }
 
+    /**
+     * 共享奖,判断当期此用户,是否有原报单团队奖金
+     */
+    public function checkHasOriBonusQyBd($userId) {
+        //判断$parent是否有首单团队奖
+        $bonus = CalcCache::bonus($userId, $this->_periodNum);
+        if( isset($bonus['ORI_BONUS_QY_BD']) && $bonus['ORI_BONUS_QY_BD'] > 0 ) {
+            return true;
+        }
+
+        return false;
+    }
+
     /**
      * 判断除大市场外 其它市场的报单业绩
      * @param $userId
@@ -2712,26 +2811,56 @@ class BonusCalc extends BaseObject {
     }
 
     /**
-     * 获取有最小报单PV的用效父级
+     * 获取有最小报单PV的用效父级 20220407修改成是否此期此用户有原报单团队奖金
      * @param $userId
      * @return string
      */
-    public function getMinBdPvNetworkParent($userId) {
+    public function getMinBdPvNetworkParent($userId, $openFindLimit = 1, $findLimitTimes = 5) {
         $validParentId = '';
-        $this->loopNetworkParentDo($userId, function ($parent) use(&$validParentId) {
-            if ( $this->checkSmallMarketPerf($parent['PARENT_UID']) ) {
+        $validDeep = 1;
+        $this->loopNetworkParentDo($userId, function ($parent) use(&$validParentId,&$validDeep,$openFindLimit,$findLimitTimes) {
+            if ( $this->checkHasOriBonusQyBd($parent['PARENT_UID']) ) {
                 $validParentId = $parent['PARENT_UID'];
                 unset($parent);
                 return self::LOOP_FINISH;
             }
+            // 只找5层
+            if ( $openFindLimit && $validDeep >= $findLimitTimes ) {
+                unset($parent);
+                return self::LOOP_FINISH;
+            }
+
+            $validDeep += 1;
             unset($parent);
         });
 
         return$validParentId;
     }
+    // public function getMinBdPvNetworkParent($userId, $openFindLimit = 1, $findLimitTimes = 5) {
+    //     $validParentId = '';
+    //     $validDeep = 1;
+    //     $this->loopNetworkParentDo($userId, function ($parent) use(&$validParentId,&$validDeep,$openFindLimit,$findLimitTimes) {
+    //         if ( $this->checkSmallMarketPerf($parent['PARENT_UID']) ) {
+    //             $validParentId = $parent['PARENT_UID'];
+    //             unset($parent);
+    //             return self::LOOP_FINISH;
+    //         }
+    //         // 只找5层
+    //         if ( $openFindLimit && $validDeep >= $findLimitTimes ) {
+    //             unset($parent);
+    //             return self::LOOP_FINISH;
+    //         }
+
+    //         $validDeep += 1;
+    //         unset($parent);
+    //     });
+
+    //     return$validParentId;
+    // }
 
     /**
      * 按级别的收入上限
+     * 新的需求调整: 改成不按月进行限制,并且去掉vip奖
      * @param $bonus
      * @param $userId
      * @param $declarationLevel
@@ -2741,18 +2870,7 @@ class BonusCalc extends BaseObject {
         $decLevelConfig = $this->_decLevelConfig;
         $nowDecLevelConfig = $decLevelConfig[$declarationLevel];
         unset($decLevelConfig);
-
-        //本月往期奖金 这里执行速度可能慢一些,但需求如此没有办法
-        $lastData = CalcCache::lastPeriodMonthCalcBonus($userId, $this->_periodNum, $this->_calcMonth);
-        $lastTotal = $lastData['ORI_BONUS_QY_SUM'] + $lastData['ORI_BONUS_VIP_SUM'];
-
-        // 从缓存中获取用户的奖金
-        $bonusData = CalcCache::bonus($userId, $this->_periodNum);
-        $thisTotal = $bonusData['ORI_BONUS_QY'] + $bonusData['ORI_BONUS_VIP'];
-        $maxGetBonus = $nowDecLevelConfig['INCOME_CAP'] * $this->_calcMonthPeriodNumCount - $lastTotal - $thisTotal;
-        unset($lastData, $lastTotal, $bonusData, $thisTotal);
-        if( $maxGetBonus <= 0 ) return 0.00;
-
+        $maxGetBonus = $nowDecLevelConfig['INCOME_CAP'];
         if( $bonus <= $maxGetBonus) {
             return $bonus;
         }else {
@@ -2760,6 +2878,29 @@ class BonusCalc extends BaseObject {
         }
     }
 
+    // public function declarationLevelCap($bonus, $userId, $declarationLevel) {
+    //     $decLevelConfig = $this->_decLevelConfig;
+    //     $nowDecLevelConfig = $decLevelConfig[$declarationLevel];
+    //     unset($decLevelConfig);
+
+    //     //本月往期奖金 这里执行速度可能慢一些,但需求如此没有办法
+    //     $lastData = CalcCache::lastPeriodMonthCalcBonus($userId, $this->_periodNum, $this->_calcMonth);
+    //     $lastTotal = $lastData['ORI_BONUS_QY_SUM'] + $lastData['ORI_BONUS_VIP_SUM'];
+
+    //     // 从缓存中获取用户的奖金
+    //     $bonusData = CalcCache::bonus($userId, $this->_periodNum);
+    //     $thisTotal = $bonusData['ORI_BONUS_QY'] + $bonusData['ORI_BONUS_VIP'];
+    //     $maxGetBonus = $nowDecLevelConfig['INCOME_CAP'] * $this->_calcMonthPeriodNumCount - $lastTotal - $thisTotal;
+    //     unset($lastData, $lastTotal, $bonusData, $thisTotal);
+    //     if( $maxGetBonus <= 0 ) return 0.00;
+
+    //     if( $bonus <= $maxGetBonus) {
+    //         return $bonus;
+    //     }else {
+    //         return $maxGetBonus;
+    //     }
+    // }
+
     /**
      * 总奖金限制
      * @param $bonus
@@ -2934,6 +3075,10 @@ class BonusCalc extends BaseObject {
     public function loopBonusUsers($offset = 0) {
         echo sprintf("时间:[%s]缓存奖金数据入库,当前offset为:【%s】" . PHP_EOL, date('Y-m-d H:i:s', time()) , $offset);
         // 从缓存列表里面从底层往上倒序获取会员
+
+        // 这里有问题,因为蓝星奖,是存储过程计算的,并没有加入缓存,这里需要修改.
+        // 给用户发送兑换积分,也需要进行调整查看。
+        // CalcCache::addHasBonusUsers($everyData['USER_ID'], $this->_periodNum);
         $allData = CalcCache::getHasBonusUsers($this->_periodNum, $offset, $this->_limit);
         if($allData){
             $insertDataBonus = [];
@@ -2953,6 +3098,93 @@ class BonusCalc extends BaseObject {
         return true;
     }
 
+    // 奖金入库完成,将各个奖金计算流水会员聘级,更新成蓝星奖当时计算的聘级
+    public function loopCalcBlueEmpLv($offset = 0) {
+        if( !$this->_isCalcMonth ) {
+            // 不是结算月,则不需要进行聘级调整
+            return false;
+        }
+        // 从缓存获取分页有收入的会员信息
+        $allData = CalcBonusBS::findUseDbCalc()
+            ->where('PERIOD_NUM=:PERIOD_NUM', [':PERIOD_NUM' => $this->_periodNum])
+            ->groupBy('USER_ID')
+            ->offset($offset)
+            ->limit($this->_limit)
+            ->asArray()
+            ->all();
+        if ($allData) {
+            foreach ($allData as $data) {
+                $nowBsEmpLv = $data['LEVEL_ID']; // 当前蓝星奖计算(即管理奖) 的等级
+                // 修改AR_CALC_BONUS的LAST_EMP_LV聘级,修改奖金流水的聘级AR_FLOW_BONUS表的LAST_EMP_LV
+                // 期结算结果
+                CalcBonus::updateAll(['LAST_EMP_LV' => $nowBsEmpLv], 'USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM', 
+                    [
+                        ':USER_ID' => $data['USER_ID'],
+                        ':PERIOD_NUM' => $this->_periodNum
+                    ]
+                );
+                // 奖金流水
+                FlowBonus::updateAll(['LAST_EMP_LV' => $nowBsEmpLv], 'USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM', 
+                    [
+                        ':USER_ID' => $data['USER_ID'],
+                        ':PERIOD_NUM' => $this->_periodNum
+                    ]
+                );
+                // 共享奖流水
+                CalcBonusGX::updateAll(['LAST_EMP_LV' => $nowBsEmpLv], 'USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM', 
+                    [
+                        ':USER_ID' => $data['USER_ID'],
+                        ':PERIOD_NUM' => $this->_periodNum
+                    ]
+                );
+                // 推广奖流水
+                CalcBonusTG::updateAll(['LAST_EMP_LV' => $nowBsEmpLv], 'USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM', 
+                    [
+                        ':USER_ID' => $data['USER_ID'],
+                        ':PERIOD_NUM' => $this->_periodNum
+                    ]
+                );
+                // 团队奖流水
+                CalcBonusQY::updateAll(['LAST_EMP_LV' => $nowBsEmpLv], 'USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM', 
+                    [
+                        ':USER_ID' => $data['USER_ID'],
+                        ':PERIOD_NUM' => $this->_periodNum
+                    ]
+                );
+                // 服务奖流水
+                CalcBonusBD::updateAll(['LAST_EMP_LV' => $nowBsEmpLv], 'USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM', 
+                    [
+                        ':USER_ID' => $data['USER_ID'],
+                        ':PERIOD_NUM' => $this->_periodNum
+                    ]
+                );
+                // 更新form的聘级
+                CalcBonusGX::updateAll(['LAST_FROM_EMP_LV' => $nowBsEmpLv], 'FROM_USER_ID=:FROM_USER_ID AND PERIOD_NUM=:PERIOD_NUM', 
+                    [
+                        ':FROM_USER_ID' => $data['USER_ID'],
+                        ':PERIOD_NUM' => $this->_periodNum
+                    ]
+                );
+                CalcBonusTG::updateAll(['LAST_FROM_EMP_LV' => $nowBsEmpLv], 'FROM_USER_ID=:FROM_USER_ID AND PERIOD_NUM=:PERIOD_NUM', 
+                    [
+                        ':FROM_USER_ID' => $data['USER_ID'],
+                        ':PERIOD_NUM' => $this->_periodNum
+                    ]
+                );
+                CalcBonusBD::updateAll(['LAST_FROM_EMP_LV' => $nowBsEmpLv], 'FROM_USER_ID=:FROM_USER_ID AND PERIOD_NUM=:PERIOD_NUM', 
+                    [
+                        ':FROM_USER_ID' => $data['USER_ID'],
+                        ':PERIOD_NUM' => $this->_periodNum
+                    ]
+                );
+            }
+            unset($allData);
+            return $this->loopCalcBlueEmpLv($offset + $this->_limit);
+        }
+        unset($allData);
+        return true;
+    }
+
     /**
      * 奖金
      * @param $userId
@@ -2971,24 +3203,123 @@ class BonusCalc extends BaseObject {
 //        }
         $pervSurplusPerf = CalcCache::surplusPerf($userId, $this->_periodNum);
 
+        // //没有共享和管理奖 以前的管理奖和共享奖逻辑
+        // $bonusReal = $bonus['BONUS_BD'] + $bonus['BONUS_TG'] + $bonus['BONUS_XF'] + $bonus['BONUS_YJ'] + $bonus['BONUS_QY'] + $bonus['BONUS_YC'] + $bonus['BONUS_YC_EXTRA'] + $bonus['BONUS_VIP'] + $standardBonus;
+        // $realBonusGx = 0;
+        // $realBonusGl = 0;
+        // if( $this->_isCalcMonth ) {
+        //     //查看是否复消300
+        //     $monthPerfData = CalcCache::nowMonthPerf($userId, $this->_periodNum);
+        //     $fxPvStatus = $monthPerfData['PV_PCS_FX'] >= $this->_sysConfig['monthPcsPvFxCondition']['VALUE'];
+        //     if ( $fxPvStatus ) {//加上本期和往期的共享和管理奖
+        //         $monthSumData = CalcBonus::findUseSlaves()->select('SUM(BONUS_GX) AS BONUS_GX_SUM, SUM(BONUS_GL) AS BONUS_GL_SUM')->where('USER_ID=:USER_ID AND CALC_MONTH=:CALC_MONTH', ['USER_ID'=>$userId, 'CALC_MONTH'=>$this->_calcYearMonth])->asArray()->one();
+        //         $bonusGxSum = $monthSumData['BONUS_GX_SUM'] ?? 0;
+        //         $bonusGlSum = $monthSumData['BONUS_GL_SUM'] ?? 0;
+        //         $realBonusGx += $bonusGxSum + $bonus['BONUS_GX'];
+        //         $realBonusGl += $bonusGlSum + $bonus['BONUS_GL'];
+        //         $bonusReal += $realBonusGx + $realBonusGl;
+        //         unset($monthSumData, $bonusGxSum, $bonusGlSum);
+        //     }
+        // }
+
+
         //没有共享和管理奖
         $bonusReal = $bonus['BONUS_BD'] + $bonus['BONUS_TG'] + $bonus['BONUS_XF'] + $bonus['BONUS_YJ'] + $bonus['BONUS_QY'] + $bonus['BONUS_YC'] + $bonus['BONUS_YC_EXTRA'] + $bonus['BONUS_VIP'] + $standardBonus;
         $realBonusGx = 0;
         $realBonusGl = 0;
+        $realBonusBs = 0; // 蓝星管理奖. BlueStar
+        $blueStartAmount = 0;
+        $buleStartOriBonus = 0;
+        $buleStartManageTax = 0;
+        $exchangePoints = 0; // 蓝星奖管理奖. 产生的兑换积分
         if( $this->_isCalcMonth ) {
             //查看是否复消300
             $monthPerfData = CalcCache::nowMonthPerf($userId, $this->_periodNum);
             $fxPvStatus = $monthPerfData['PV_PCS_FX'] >= $this->_sysConfig['monthPcsPvFxCondition']['VALUE'];
-            if ( $fxPvStatus ) {//加上本期和往期的共享和管理奖
-                $monthSumData = CalcBonus::findUseSlaves()->select('SUM(BONUS_GX) AS BONUS_GX_SUM, SUM(BONUS_GL) AS BONUS_GL_SUM')->where('USER_ID=:USER_ID AND CALC_MONTH=:CALC_MONTH', ['USER_ID'=>$userId, 'CALC_MONTH'=>$this->_calcYearMonth])->asArray()->one();
+            // BONUS_REAL 字段是发到用户的真实奖金
+            if ( $fxPvStatus ) {
+                // 管理奖改成了蓝星奖,但是对于用户来说依旧叫管理奖.字段改成bs.
+                // 因为管理奖(即蓝星奖,是用存储过程计算的,则此处直接取AR_CALC_BONUS_BS表中计算的结果数据使用,
+                // 并将管理奖结果同步到当前结算月的CalcBonus中)
+                // 由于单独奖金流水记录每次都插入,所以倒叙找最新的数据.
+                $userBS = CalcBonusBS::find()
+                ->where(
+                    'PERIOD_NUM=:PERIOD_NUM AND USER_ID=:USER_ID',
+                    [
+                        ':PERIOD_NUM' => $this->_periodNum,
+                        ':USER_ID' => $userId
+                    ]
+                )
+                ->select('AMOUNT,ORI_BONUS,MANAGE_TAX,LEVEL_ID,PRODUCT_POINT')
+                ->limit(1)
+                ->orderBy('CREATED_AT DESC')
+                ->asArray()
+                ->all();
+                $userBS = is_array($userBS) ? reset($userBS) : [];
+                $blueStartAmount = isset($userBS['AMOUNT']) && !empty($userBS['AMOUNT']) ? $userBS['AMOUNT'] : 0; // 奖金
+                $buleStartOriBonus = isset($userBS['ORI_BONUS']) && !empty($userBS['ORI_BONUS']) ? $userBS['ORI_BONUS'] : 0; // 原奖金
+                // $buleStartManageTax = isset($userBS['MANAGE_TAX']) && !empty($userBS['MANAGE_TAX']) ? $userBS['MANAGE_TAX'] : 0; // 管理费
+                $monthSumData = CalcBonus::findUseSlaves()
+                ->select('SUM(BONUS_GX) AS BONUS_GX_SUM, SUM(BONUS_GL) AS BONUS_GL_SUM')
+                ->where('USER_ID=:USER_ID AND CALC_MONTH=:CALC_MONTH', 
+                    [
+                        'USER_ID'=>$userId, 
+                        'CALC_MONTH'=>$this->_calcYearMonth
+                    ]
+                )
+                ->asArray()
+                ->one();
                 $bonusGxSum = $monthSumData['BONUS_GX_SUM'] ?? 0;
                 $bonusGlSum = $monthSumData['BONUS_GL_SUM'] ?? 0;
                 $realBonusGx += $bonusGxSum + $bonus['BONUS_GX'];
                 $realBonusGl += $bonusGlSum + $bonus['BONUS_GL'];
-                $bonusReal += $realBonusGx + $realBonusGl;
+                $realBonusBs = $blueStartAmount; // 蓝星奖直接取数据库中算好的值PRODUCT_POINT
+                $bonusReal += $realBonusGx + $realBonusBs + $realBonusGl;
+                $exchangePoints = isset($userBS['PRODUCT_POINT']) && !empty($userBS['PRODUCT_POINT']) ? $userBS['PRODUCT_POINT'] : 0; // 兑换积分
+
+                $bonus['BONUS_TOTAL'] = $bonus['BONUS_TOTAL'] + $buleStartOriBonus; // 管理奖在存储过程计算,这里单独加上管理奖(即蓝星奖)
                 unset($monthSumData, $bonusGxSum, $bonusGlSum);
             }
         }
+        // if( $this->_isCalcMonth ) {
+        //     // 将查看是否复消300的逻辑,改成月结时判断当前月有一周活跃则本月活跃
+        //     // 1. 获取此业绩期的月份
+        //     $periodInfo = Period::getInfoByPeriodNum($this->_periodNum);
+            
+        //     $calcMonth = $periodInfo['CALC_YEAR'].'-'.$periodInfo['CALC_MONTH']; // 2025-7
+        //     // 获取此月的第一天和最后一天时间戳
+        //     $fday = date('Y-m-01', strtotime($calcMonth));
+        //     $lday = date('Y-m-d', strtotime("$fday +1 month -1 day"));
+        //     $ftime = strtotime($fday);
+        //     $ltime = strtotime($lday.' 23:59:59');
+        //     // 2. 根据业绩期的月份,判断用户是否是活跃状态.
+        //     $fxPvStatus = PerfActiveUser::findUseDbCalc()
+        //     ->select('USER_ID')
+        //     ->where("USER_ID=:USER_ID ", [':USER_ID' => $userId])
+        //     ->andWhere(['or',
+        //         [
+        //             'and',
+        //             ['>=', 'SRATR_AT', $ftime],
+        //             ['<=', 'SRATR_AT', $ltime]
+        //         ],
+        //         [
+        //             'and',
+        //             ['>=', 'END_AT', $ftime],
+        //             ['<=', 'END_AT', $ltime]
+        //         ]
+        //     ])
+        //     ->asArray()
+        //     ->all();
+        //     if ( !empty($fxPvStatus) ) {//加上本期和往期的共享和管理奖
+        //         $monthSumData = CalcBonus::findUseSlaves()->select('SUM(BONUS_GX) AS BONUS_GX_SUM, SUM(BONUS_GL) AS BONUS_GL_SUM')->where('USER_ID=:USER_ID AND CALC_MONTH=:CALC_MONTH', ['USER_ID'=>$userId, 'CALC_MONTH'=>$this->_calcYearMonth])->asArray()->one();
+        //         $bonusGxSum = $monthSumData['BONUS_GX_SUM'] ?? 0;
+        //         $bonusGlSum = $monthSumData['BONUS_GL_SUM'] ?? 0;
+        //         $realBonusGx += $bonusGxSum + $bonus['BONUS_GX'];
+        //         $realBonusGl += $bonusGlSum + $bonus['BONUS_GL'];
+        //         $bonusReal += $realBonusGx + $realBonusGl;
+        //         unset($monthSumData, $bonusGxSum, $bonusGlSum);
+        //     }
+        // }
 
         $result = [
             'USER_ID' => $userId,
@@ -3010,6 +3341,7 @@ class BonusCalc extends BaseObject {
             'LAST_REC_REAL_NAME' => $baseInfo['REC_REAL_NAME'],
             'LAST_CON_USER_NAME' => $baseInfo['CON_USER_NAME'],
             'LAST_CON_REAL_NAME' => $baseInfo['CON_REAL_NAME'],
+            'EXCHANGE_POINTS' => $exchangePoints, // 兑换积分
 //            'LAST_LOCATION' => $baseInfo['LOCATION'] ? $baseInfo['LOCATION'] : 1,
             //@todo
             'LAST_LOCATION' => 1,
@@ -3037,6 +3369,9 @@ class BonusCalc extends BaseObject {
             'REAL_BONUS_GX' => $realBonusGx,
             'ORI_BONUS_GL' => $bonus['ORI_BONUS_GL'],
             'REAL_BONUS_GL' => $realBonusGl,
+            'BONUS_BS' => $realBonusBs, // 新的管理奖金,即蓝星管理奖
+            'ORI_BONUS_BS' => $buleStartOriBonus, // 蓝星管理奖金原奖金,即包含管理费
+            'REAL_BONUS_BS' => $realBonusBs, // 实发蓝星管理奖金
             'ORI_BONUS_GL_BD' => $bonus['ORI_BONUS_GL_BD'],
             'ORI_BONUS_GL_FX' => $bonus['ORI_BONUS_GL_FX'],
             'ORI_BONUS_QY' => $bonus['ORI_BONUS_QY'],

+ 119 - 8
common/helpers/bonus/BonusSend.php

@@ -36,6 +36,13 @@ use yii\base\StaticInstanceTrait;
 use common\helpers\Cache;
 use common\helpers\Date;
 use common\models\CalcBonus;
+use common\models\CalcBonusBD;
+use common\models\CalcBonusBS;
+use common\models\CalcBonusGX;
+use common\models\CalcBonusQY;
+use common\models\CalcBonusTG;
+use common\models\FlowBonus;
+use common\models\PerfActiveUser;
 use common\models\PerfMonth;
 use common\models\User;
 use Yii;
@@ -156,6 +163,12 @@ class BonusSend extends BaseObject {
             $t8 = microtime(true);
             echo('更新会员累计月业绩完成,耗时:' . round($t8 - $t7, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
 
+            // 更新活跃用户状态,更新为已处理
+            // $this->updateActiveUser();
+            // $this->_updatePercent(95);
+            // $t9 = microtime(true);
+            // echo('更新会员累计月业绩完成,耗时:' . round($t9 - $t8, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
+            
             // 开启子进程去完成下面的循环发放和循环改聘级和循环更新累计业绩
             /*$process = new Process('sendBonus', 3);
             $process->run(function($workId, $pmid){
@@ -271,7 +284,15 @@ class BonusSend extends BaseObject {
         echo sprintf("时间:[%s]数据库发奖,当前page为:【%s】" . PHP_EOL, date('Y-m-d H:i:s', time()), $page);
         $periodNum = $this->_periodNum;
         // 从奖金结算表中获取当期未发放的所有数据
-        $allData = CalcBonus::findUseDbCalc()->yearMonth($this->_calcYearMonth)->where('(IS_SENT=0 OR IS_SENT=2) AND CALC_MONTH=:CALC_MONTH AND PERIOD_NUM=:PERIOD_NUM', [':CALC_MONTH' => $this->_calcYearMonth, ':PERIOD_NUM' => $periodNum])->limit($this->_limit)->asArray()->all();
+        $allData = CalcBonus::findUseDbCalc()
+        ->yearMonth($this->_calcYearMonth)
+        ->where(
+            '(IS_SENT=0 OR IS_SENT=2) AND CALC_MONTH=:CALC_MONTH AND PERIOD_NUM=:PERIOD_NUM', 
+            [':CALC_MONTH' => $this->_calcYearMonth, ':PERIOD_NUM' => $periodNum]
+        )
+        ->limit($this->_limit)
+        ->asArray()
+        ->all();
         if ($allData) {
             $transaction = Yii::$app->db->beginTransaction();
             try {
@@ -296,6 +317,7 @@ class BonusSend extends BaseObject {
                             'YJ' => $data['BONUS_YJ'],
                             'GX' => $data['BONUS_GX'],
                             'GL' => $data['BONUS_GL'],
+                            'BS' => $data['BONUS_BS'],
 
                             'ORI_QY' => $data['ORI_BONUS_QY'],
                             'ORI_YC' => $data['ORI_BONUS_YC'],
@@ -306,8 +328,10 @@ class BonusSend extends BaseObject {
                             'ORI_YJ' => $data['ORI_BONUS_YJ'],
                             'ORI_GX' => $data['ORI_BONUS_GX'],
                             'ORI_GL' => $data['ORI_BONUS_GL'],
+                            'ORI_BS' => $data['ORI_BONUS_BS'],
 
                             'RECONSUME_POINTS_TOTAL' => $data['RECONSUME_POINTS'],
+                            'EXCHANGE_POINTS_TOTAL' => $data['EXCHANGE_POINTS'],
                             'MANAGE_TAX' => $data['MANAGE_TAX'],
 
                             'BONUS_TOTAL' => $data['BONUS_TOTAL'],
@@ -328,6 +352,17 @@ class BonusSend extends BaseObject {
                             'DEAL_TYPE_ID' => DealType::RECONSUME_POINTS_SEND,
                         ]);
                     }
+
+                    //发放兑换积分
+                    if ($data['EXCHANGE_POINTS'] > 0) {
+                        Balance::changeUserBonus($data['USER_ID'], 'exchange_points', $data['EXCHANGE_POINTS'], [
+                            'CALC_ID' => $data['ID'],
+                            'REMARK' => 'From ' . $periodNum . '期',
+                            'PERIOD_NUM' => $periodNum,
+                            'EXCHANGE_POINTS' => $data['EXCHANGE_POINTS'],
+                            'DEAL_TYPE_ID' => DealType::EXCHANGE_POINTS_SEND,
+                        ]);
+                    }
                     // 把记录标记为已发放状态
                     CalcBonus::updateAll(['IS_SENT' => 1, 'SENT_AT' => Date::nowTime()], 'ID=:ID', [':ID' => $data['ID']]);
 
@@ -350,14 +385,28 @@ class BonusSend extends BaseObject {
     }
 
     /**
-     * 更新会员聘级
+     * 蓝星奖金(即新的管理奖),更新会员聘级
      * @param int $offset
      * @return bool
      * @throws \yii\db\Exception
      */
     public function updateEmpLevel(int $offset = 0) {
         if ($this->_isCalcMonth) {
-            $allData = PerfMonth::findUseDbCalc()->yearMonth($this->_calcYearMonth)->where('CALC_MONTH=:CALC_MONTH', [':CALC_MONTH' => $this->_calcYearMonth])->offset($offset)->limit($this->_limit)->all();
+            $empLv = EmployLevel::getIdConvertLevelSortCache();
+            $allData = CalcBonusBS::findUseDbCalc()
+            ->yearMonth($this->_calcYearMonth)
+            ->where(
+                'CALC_MONTH=:CALC_MONTH AND PERIOD_NUM=:PERIOD_NUM', 
+                [
+                    ':CALC_MONTH' => $this->_calcYearMonth,
+                    ':PERIOD_NUM' =>$this->_periodNum
+                ]
+            )
+            ->orderBy('CREATED_AT DESC')
+            ->groupBy('USER_ID')
+            ->offset($offset)
+            ->limit($this->_limit)
+            ->all();
             //@todo 用户级别不变则不更新
             $defaultEmpLv = EmployLevel::getDefaultLevelId();
             if ($allData) {
@@ -365,11 +414,20 @@ class BonusSend extends BaseObject {
                 try {
                     foreach ($allData as $data) {
                         //@todo 用户级别不变则不更新
-                        if( $data['LAST_EMP_LV'] === $defaultEmpLv ) continue;
-
-                        User::updateAll(['EMP_LV' => $data['LAST_EMP_LV']], 'ID=:USER_ID', [':USER_ID' => $data['USER_ID']]);
-                        User::deleteBaseInfoFromRedis($data['USER_ID']);
-                        unset($data);
+                        if( $data['LEVEL_ID'] === $defaultEmpLv ) continue;
+                        $nowBsEmpLv = $data['LEVEL_ID']; // 当前蓝星奖计算(即管理奖) 的等级
+                        $user = CalcCache::getUserInfo($data['USER_ID'], $this->_periodNum);
+                        $userEmpLv = $user['EMP_LV']; // 用户的历史最高聘级
+                        $userEmpLvSort = $empLv[$userEmpLv]; // 历史最高聘级的 级别值
+                        $nowBsEmpLvSort = $empLv[$nowBsEmpLv]; // 当前蓝星计算的聘级 级别值
+                        if ($nowBsEmpLvSort > $userEmpLvSort) {
+                            // 如果当前期的级别值大于历史最高级别,则更新用户表里的最高聘级
+                            User::updateAll(['EMP_LV' => $data['LEVEL_ID']], 'ID=:USER_ID', [':USER_ID' => $data['USER_ID']]);
+                            User::deleteBaseInfoFromRedis($data['USER_ID']);
+                            unset($data);
+                        } else {
+                            continue;
+                        }
                     }
                     $transaction->commit();
                 } catch (Exception $e) {
@@ -385,6 +443,59 @@ class BonusSend extends BaseObject {
         return true;
     }
 
+    // /**
+    //  * 更新会员聘级
+    //  * @param int $offset
+    //  * @return bool
+    //  * @throws \yii\db\Exception
+    //  */
+    // public function updateEmpLevel(int $offset = 0) {
+    //     if ($this->_isCalcMonth) {
+    //         $allData = PerfMonth::findUseDbCalc()->yearMonth($this->_calcYearMonth)->where('CALC_MONTH=:CALC_MONTH', [':CALC_MONTH' => $this->_calcYearMonth])->offset($offset)->limit($this->_limit)->all();
+    //         //@todo 用户级别不变则不更新
+    //         $defaultEmpLv = EmployLevel::getDefaultLevelId();
+    //         if ($allData) {
+    //             $transaction = Yii::$app->db->beginTransaction();
+    //             try {
+    //                 foreach ($allData as $data) {
+    //                     //@todo 用户级别不变则不更新
+    //                     if( $data['LAST_EMP_LV'] === $defaultEmpLv ) continue;
+
+    //                     User::updateAll(['EMP_LV' => $data['LAST_EMP_LV']], 'ID=:USER_ID', [':USER_ID' => $data['USER_ID']]);
+    //                     User::deleteBaseInfoFromRedis($data['USER_ID']);
+    //                     unset($data);
+    //                 }
+    //                 $transaction->commit();
+    //             } catch (Exception $e) {
+    //                 $transaction->rollBack();
+    //                 $this->addError('updateEmpLevel', '更新聘级失败,原因:' . $e->getMessage());
+    //                 return false;
+    //             }
+    //             unset($transaction, $allData, $defaultEmpLv);
+    //             return $this->updateEmpLevel($offset + $this->_limit);
+    //         }
+    //         unset($allData);
+    //     }
+    //     return true;
+    // }
+
+    // 更活跃会员,将is_send改成1
+    public function updateActiveUser() {
+        try {
+            $ret = PerfActiveUser::updateAll(
+                ['IS_SENT' => 1], 
+                'PERIOD_NUM=:PERIOD_NUM AND IS_SENT=:IS_SENT', 
+                ['IS_SENT'=>0, 'PERIOD_NUM'=>$this->_periodNum]
+            );
+
+            return $ret;
+        } catch(Exception $e) {
+
+            $this->addError('updateActiveUser', '更新活跃会员业绩期处理状态失败,原因:' . $e->getMessage());
+            return false;
+        }
+    }
+
     /**
      * 更新会员的累计业绩
      * @param int $offset

+ 2 - 0
common/helpers/bonus/CalcCache.php

@@ -1429,8 +1429,10 @@ class CalcCache {
             'BONUS_QY' => 0,
             'BONUS_YC' => 0,
             'BONUS_VIP' => 0,
+            'BONUS_BS' => 0,
             'BONUS_YC_EXTRA' => 0,
             'ORI_BONUS_BD' => 0,
+            'ORI_BONUS_BS' => 0,
             'ORI_BONUS_TG' => 0,
             'ORI_BONUS_XF' => 0,
             'ORI_BONUS_YJ' => 0,

+ 122 - 11
common/helpers/bonus/PerfCalc.php

@@ -31,6 +31,7 @@ use common\models\PerfStandard;
 use common\models\Period;
 use common\models\DecOrder;
 use common\models\EmployLevel;
+use common\models\PerfActiveUser;
 use common\models\UserRelation;
 use yii\base\Exception;
 use yii\base\StaticInstanceTrait;
@@ -160,27 +161,34 @@ class PerfCalc {
             $this->_updatePercent(80);
 
             //每月计算聘级
-            $this->loopCalcEmpLevel();
+            // modify 聘级字段改成蓝星奖的  奖衔级别(蓝星奖的等级).不在使用荣衔奖金.聘级的等级切换成蓝星奖等级,
+            // 此等级会影响团队将的封顶.
+            // $this->loopCalcEmpLevel();
             $t8 = microtime(true);
-            echo('计算聘级完成,耗时:' . round($t8 - $t7, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
-            $this->_updatePercent(90);
+            // echo('计算聘级完成,耗时:' . round($t8 - $t7, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
+            //$this->_updatePercent(90);
 
             //本月业绩入库
             $this->loopWriteMonthPerf();
             $t7 = microtime(true);
             echo('本月业绩入库完成,耗时:' . round($t7 - $t6, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
-            $this->_updatePercent(95);
+            $this->_updatePercent(90);
 
-            //达标业绩
+            // //达标业绩
             $this->loopCalcPerfByStandardFXOrder();
-            //达标业绩入库
+            // //达标业绩入库
             $this->loopWriteStandardPerf();
-            $t8 = microtime(true);
-            echo('本月业绩入库完成,耗时:' . round($t8 - $t7, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
-            $this->_updatePercent(100);
+            $t9 = microtime(true);
+            echo('本月业绩入库完成,耗时:' . round($t9 - $t7, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
+            $this->_updatePercent(95);
 
+            
+            // 通过插入到perforder中的业绩订单数据,生成此业绩期活跃用户数据
+            // $this->loopWriteActiveUser();
+            $this->_updatePercent(100);
+            $t10 = microtime(true);
 
-            echo('结算全部完成,共耗时:' . round($t8 - $t1, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
+            echo('业绩结算全部完成,共耗时:' . round($t10 - $t9, 3) . ',内存使用:' . (round(memory_get_usage() / 1024 / 1024, 3)) . 'MB' . PHP_EOL);
         } catch (\Exception $e) {
             $this->errorCalcTask();
             $this->addError('calc', $e->getMessage());
@@ -280,6 +288,8 @@ class PerfCalc {
         PerfPeriod::pageDeleteAll('PERIOD_NUM='.$this->_periodNum);
         // 业绩单
         PerfOrder::pageDeleteAll('PERIOD_NUM='.$this->_periodNum);
+        // 删除活跃用户
+        // PerfActiveUser::pageDeleteAll('PERIOD_NUM='.$this->_periodNum.'  AND IS_SENT=0 ');
         // 月结时要清空的数据
         if ($this->_isCalcMonth) {
             // 月业绩表
@@ -289,6 +299,103 @@ class PerfCalc {
         }
     }
 
+    /**
+     * 循环判断活跃会员,并入库
+     * @param int $offset
+     * @return bool
+     * @throws \yii\db\Exception
+     */
+    public function loopWriteActiveUser($offset = 0) {
+        echo sprintf("时间:[%s]本期活跃用户PerfOrder表中,当前offset为:【%s】" . PHP_EOL, date('Y-m-d H:i:s', time()) , $offset);
+        // 从PerfOrder表中获取此周期的用户数据
+        $data = PerfPeriod::findUseDbCalc()
+        ->select('USER_ID')
+        ->where('PERIOD_NUM=:PERIOD_NUM',[
+            ':PERIOD_NUM' => $this->_periodNum
+        ])->offset($offset)->limit($this->_limit)->asArray()->all();
+        if ($data) {
+            foreach ($data as $upv) {
+                $userId = $upv['USER_ID'];
+                // 判断用户每周是否是活跃用户
+                $allData = PerfOrder::findUseDbCalc()
+                ->select('USER_ID,PV,DEC_AMOUNT,PERIOD_NUM,CALC_MONTH,P_CALC_MONTH, DEC_SN,ORDER_CREATED_AT')
+                ->where('PERIOD_NUM=:PERIOD_NUM AND USER_ID=:USER_ID',[
+                    ':PERIOD_NUM' => $this->_periodNum,
+                    ':USER_ID' => $userId
+                ])
+                ->orderBy('ORDER_CREATED_AT DESC')
+                ->asArray()
+                ->all();
+               
+                if($allData) {
+                    $this->weekMonthOrder($allData);
+
+                    unset($insertDataPeriodPerf, $allData);
+                }
+
+                unset($allData);
+            }
+            
+            unset($data);
+            return $this->loopWriteActiveUser($offset + $this->_limit);
+        }
+
+        return true;
+    }
+
+    // 活跃判断
+    public function weekMonthOrder($data) {
+        // 获取每个订单是周几,把他们分别放到各自的周里面.
+        // 因为是自然月,所以需要知道是此月的几号,是此月的第几周.然后往前和往后推出时间戳范围内pv的累计之和是多少
+        $one = 24*60*60; // 一天的时间戳
+        $time_arr = [];
+        foreach ($data as $orders) {
+            $day = intval(date('d', $orders['ORDER_CREATED_AT'])); // 当月第多少号
+            $weekDay = (date('w', $orders['ORDER_CREATED_AT']) == 0) ? 7 : date('w', $orders['ORDER_CREATED_AT']);// 周几 1-7
+            $format = date('Y-m-d', $orders['ORDER_CREATED_AT']);
+            $orderDayStart = strtotime($format.' 0:0:0');
+            $orderDayEnd = strtotime($format.' 23:59:59');
+            $startCaluc = $weekDay-1;
+            $endCaluc = 7-$weekDay;
+            $calucWeekStart = $orderDayStart - $startCaluc*$one;
+            $calucWeekEnd = $orderDayEnd + $endCaluc*$one;
+            if (!isset($time_arr[$calucWeekStart])) {
+                $time_arr[$calucWeekStart] = array_merge($orders, [
+                    'temp_start' => $calucWeekStart,
+                    'temp_end' => $calucWeekEnd,
+                    'calculate_total_pv' => $orders['PV']
+                ]);
+            } else {
+                $time_arr[$calucWeekStart]['calculate_total_pv'] = $time_arr[$calucWeekStart]['calculate_total_pv'] + $orders['PV'];
+            }
+        }
+        unset($data);
+        $insert = [];
+        // 循环判断,当周pv累计是否达到400
+        foreach ($time_arr as $k => $v) {
+            if ($v['calculate_total_pv'] >= $this->_sysConfig['activeUserPvCondition']['VALUE']) {
+                // 如果个人业累计绩达400PV,取得连续四周活跃
+                // 取出周末再增加三周的时间戳
+                $insert[] = [
+                    'ID' => SnowFake::instance()->generateId(),
+                    'USER_ID' => $v['USER_ID'],
+                    'PERIOD_NUM' => $v['PERIOD_NUM'],
+                    'CALC_MONTH' => $v['CALC_MONTH'],
+                    'P_CALC_MONTH' => $v['P_CALC_MONTH'],
+                    'SRATR_AT' => $v['temp_start'],
+                    'END_AT' => $v['temp_end']+(3*7*24*60*60),
+                    'CREATED_AT' => time(),
+                    'PV' => $v['calculate_total_pv'],
+                ];
+            }
+        }
+        PerfActiveUser::batchInsert($insert);
+        
+        unset($insert);
+
+        return true;
+    }
+
     /**
      * 周结,向上级算业绩,并计入业绩单
      * @param int $offset
@@ -390,6 +497,7 @@ class PerfCalc {
                     'P_CALC_MONTH' => Date::ociToDate($this->_calcYearMonth, Date::OCI_TIME_FORMAT_SHORT_MONTH),
                     'CREATED_AT' => Date::nowTime(),
                     'CLOSED_AT' => 0,
+                    'ORDER_CREATED_AT' => $data['CREATED_AT'],
                 ];
                 unset($data, $decInfo, $sn, $toInfo);
             }
@@ -409,7 +517,7 @@ class PerfCalc {
      */
     public function loopCalcPeriodPerfByOrderDec($offset = 0) {
         // 循环获取全部报单
-        $allData = OrderDec::findUseDbCalc()->select('ID,SN,USER_ID,ORDER_TYPE,ORDER_AMOUNT,PV,PAY_AMOUNT,PAY_PV,PERIOD_NUM,PAY_TYPE')->where("PERIOD_NUM=:PERIOD_NUM AND IS_DELETE=0 AND ORDER_TYPE=:ORDER_TYPE", [':PERIOD_NUM' => $this->_periodNum, ':ORDER_TYPE'=>'ZC'])->orderBy('ID DESC')->offset($offset)->limit($this->_limit)->asArray()->all();
+        $allData = OrderDec::findUseDbCalc()->select('CREATED_AT,ID,SN,USER_ID,ORDER_TYPE,ORDER_AMOUNT,PV,PAY_AMOUNT,PAY_PV,PERIOD_NUM,PAY_TYPE')->where("PERIOD_NUM=:PERIOD_NUM AND IS_DELETE=0 AND ORDER_TYPE=:ORDER_TYPE", [':PERIOD_NUM' => $this->_periodNum, ':ORDER_TYPE'=>'ZC'])->orderBy('ID DESC')->offset($offset)->limit($this->_limit)->asArray()->all();
         if ($allData) {
             $insertPerfOrderData = [];
             foreach ($allData as $data) {
@@ -491,6 +599,7 @@ class PerfCalc {
                     'P_CALC_MONTH' => Date::ociToDate($this->_calcYearMonth, Date::OCI_TIME_FORMAT_SHORT_MONTH),
                     'CREATED_AT' => Date::nowTime(),
                     'CLOSED_AT' => 0,
+                    'ORDER_CREATED_AT' => $data['CREATED_AT']
                 ];
                 unset($data, $decInfo, $sn, $toInfo);
             }
@@ -613,6 +722,7 @@ class PerfCalc {
                     'P_CALC_MONTH' => Date::ociToDate($this->_calcYearMonth, Date::OCI_TIME_FORMAT_SHORT_MONTH),
                     'CREATED_AT' => Date::nowTime(),
                     'CLOSED_AT' => 0,
+                    'ORDER_CREATED_AT' => $data['CREATED_AT']
                 ];
                 unset($data, $baseInfo, $sn, $orderCashAmount, $payPv, $cacheDataKey);
             }
@@ -728,6 +838,7 @@ class PerfCalc {
                     'P_CALC_MONTH' => Date::ociToDate($this->_calcYearMonth, Date::OCI_TIME_FORMAT_SHORT_MONTH),
                     'CREATED_AT' => Date::nowTime(),
                     'CLOSED_AT' => 0,
+                    'ORDER_CREATED_AT' => $data['CREATED_AT']
                 ];
                 unset($data, $baseInfo, $sn, $orderCashAmount, $payPv, $cacheDataKey);
             }

+ 128 - 2
common/helpers/user/Balance.php

@@ -21,10 +21,12 @@ use common\models\InvoiceFlow;
 use common\models\Period;
 use common\models\DeclarationLevel;
 use common\models\DecRole;
+use common\models\FlowExchangePoints;
 use common\models\UserPeriodPoints;
 use common\models\UserWallet;
 use common\models\UserBonus;
 use common\models\UserInfo;
+use common\models\UserPeriodExchangePoints;
 use yii\base\Exception;
 use yii\db\Expression;
 
@@ -36,6 +38,7 @@ class Balance {
 
     const BONUS_BALANCE_LOCK_KEY = 'Bonus';
     const RECONSUME_POINTS_BALANCE_LOCK_KEY = 'reconsumePoints';
+    const EXCHANGE_POINTS_BALANCE_LOCK_KEY = 'exchangePoints';
     const CF_BALANCE_LOCK_KEY = 'CF';
     const LX_BALANCE_LOCK_KEY = 'LX';
     const INVOICE_BALANCE_LOCK_KEY = 'Invoice';
@@ -151,6 +154,20 @@ class Balance {
         }
     }
 
+    /**
+     * 获取当前兑换积分余额
+     * @param $userId
+     * @return int|mixed
+     */
+    public static function getBalanceExchangePoints($userId) {
+        $oneData = UserBonus::find()->where('USER_ID=:USER_ID', [':USER_ID' => $userId])->asArray()->one();
+        if ($oneData) {
+            return $oneData['EXCHANGE_POINTS'];
+        } else {
+            return 0;
+        }
+    }
+
     /**
      * 获取当前车房养老奖余额
      * @param $userId
@@ -196,6 +213,9 @@ class Balance {
             case 'RECONSUME_POINTS':
                 $lockKey = self::RECONSUME_POINTS_BALANCE_LOCK_KEY . $userId;
                 break;
+            case 'EXCHANGE_POINTS':
+                $lockKey = self::EXCHANGE_POINTS_BALANCE_LOCK_KEY . $userId;
+                break;
             case 'CF':
                 $lockKey = self::CF_BALANCE_LOCK_KEY . $userId;
                 break;
@@ -252,10 +272,18 @@ class Balance {
                     $paramData['GL_TOTAL'] = new Expression('GL_TOTAL + '.$params['GL']);
                     //$oneUserBonusModel->GL_TOTAL += $params['GL'];
                 }
+                if (isset($params['BS'])) {
+                    $paramData['BS_TOTAL'] = new Expression('BS_TOTAL + '.$params['BS']);
+                    //$oneUserBonusModel->GL_TOTAL += $params['GL'];
+                }
                 if (isset($params['RECONSUME_POINTS_TOTAL'])) {
                     $paramData['RECONSUME_POINTS_TOTAL'] = new Expression('RECONSUME_POINTS_TOTAL + '.$params['RECONSUME_POINTS_TOTAL']);
                     //$oneUserBonusModel->RECONSUME_POINTS_TOTAL += $params['RECONSUME_POINTS_TOTAL'];
                 }
+                if (isset($params['EXCHANGE_POINTS_TOTAL'])) {
+                    $paramData['EXCHANGE_POINTS_TOTAL'] = new Expression('EXCHANGE_POINTS_TOTAL + '.$params['EXCHANGE_POINTS_TOTAL']);
+                    //$oneUserBonusModel->RECONSUME_POINTS_TOTAL += $params['RECONSUME_POINTS_TOTAL'];
+                }
                 if (isset($params['MANAGE_TAX'])) {
                     $paramData['MANAGE_TAX'] = new Expression('MANAGE_TAX + '.$params['MANAGE_TAX']);
                     //$oneUserBonusModel->MANAGE_TAX += $params['MANAGE_TAX'];
@@ -297,6 +325,10 @@ class Balance {
                     $paramData['ORI_GL_TOTAL'] = new Expression('ORI_GL_TOTAL + '.$params['ORI_GL']);
                     //$oneUserBonusModel->ORI_GL_TOTAL += $params['ORI_GL'];
                 }
+                if (isset($params['ORI_BS'])) {
+                    $paramData['ORI_BS_TOTAL'] = new Expression('ORI_BS_TOTAL + '.$params['ORI_BS']);
+                    //$oneUserBonusModel->ORI_GL_TOTAL += $params['ORI_GL'];
+                }
 
                 if (isset($params['BONUS_TOTAL'])) {
                     $paramData['BONUS_TOTAL'] = new Expression('BONUS_TOTAL + '.$params['BONUS_TOTAL']);
@@ -348,6 +380,10 @@ class Balance {
 //                    $paramData['GL_TOTAL'] = new Expression('GL_TOTAL + '.$params['GL']);
                     $paramData['GL_TOTAL'] = $params['GL'];
                 }
+                if (isset($params['BS'])) {
+                    $paramData['BS_TOTAL'] = $params['BS'];
+                    //$oneUserBonusModel->GL_TOTAL += $params['GL'];
+                }
                 if (isset($params['RECONSUME_POINTS_TOTAL'])) {
 //                    $paramData['RECONSUME_POINTS_TOTAL'] = new Expression('RECONSUME_POINTS_TOTAL + '.$params['RECONSUME_POINTS_TOTAL']);
                     $paramData['RECONSUME_POINTS_TOTAL'] = $params['RECONSUME_POINTS_TOTAL'];
@@ -396,6 +432,10 @@ class Balance {
 //                    $paramData['ORI_GL_TOTAL'] = new Expression('ORI_GL_TOTAL + '.$params['ORI_GL']);
                     $paramData['ORI_GL_TOTAL'] = $params['ORI_GL'];
                 }
+                if (isset($params['ORI_BS'])) {
+                    $paramData['ORI_BS_TOTAL'] = $params['ORI_BS'];
+                    //$oneUserBonusModel->ORI_GL_TOTAL += $params['ORI_GL'];
+                }
 
                 if (isset($params['BONUS_TOTAL'])) {
 //                    $paramData['BONUS_TOTAL'] = new Expression('BONUS_TOTAL + '.$params['BONUS_TOTAL']);
@@ -431,7 +471,9 @@ class Balance {
                 'SORT' => $params['SORT'] ?? 0,
             ];
             unset($userInfo, $oneUserBonus);
-            if (strtolower($type) == 'reconsume_points' || strtolower($type) == 'cf' || strtolower($type) == 'lx') {
+            if (strtolower($type) == 'reconsume_points' || strtolower($type) == 'cf' || strtolower($type) == 'lx' 
+                || strtolower($type) == 'exchange_points'
+            ) {
                 unset($flowInsertData['CALC_ID']);
                 unset($flowInsertData['TRANSFER_SN']);
                 unset($flowInsertData['SORT']);
@@ -446,6 +488,14 @@ class Balance {
                     self::deductPeriodReconsumePoints($userId, abs($amount));
                 }
                 FlowReconsumePoints::insertOne($flowInsertData);
+            } elseif (strtolower($type) == 'exchange_points') {
+                //记录和扣除期数的积分
+                if( $amount > 0 ) {
+                    self::addPeriodExchangePoints($userId, $periodNum, $amount);
+                }else {
+                    self::deductPeriodExchangePoints($userId, abs($amount));
+                }
+                FlowExchangePoints::insertOne($flowInsertData);
             } elseif (strtolower($type) == 'cf') {
                 FlowCF::insertOne($flowInsertData);
             } elseif (strtolower($type) == 'lx') {
@@ -495,6 +545,42 @@ class Balance {
         return true;
     }
 
+    /**
+     * 添加对应期数的兑换积分
+     * @param $userId
+     * @param $periodNum
+     * @param $amount
+     * @throws \yii\db\Exception
+     * @return boolean
+     */
+    public static function addPeriodExchangePoints($userId, $periodNum, $amount) {
+        if($amount <= 0) return false;
+        $exists = UserPeriodExchangePoints::find()->where('USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM', [
+            'USER_ID' => $userId,
+            'PERIOD_NUM' => $periodNum,
+        ])->asArray()->exists();
+        if( $exists ) {
+            UserPeriodExchangePoints::updateAllCounters([
+                'EXCHANGE_POINTS' => $amount,
+                'REMAINDER_POINTS' => $amount,
+            ], 'USER_ID=:USER_ID AND PERIOD_NUM=:PERIOD_NUM', [
+                'USER_ID' => $userId,
+                'PERIOD_NUM' => $periodNum,
+            ]);
+        }else {
+            UserPeriodExchangePoints::insertOne([
+                'USER_ID' => $userId,
+                'PERIOD_NUM' => $periodNum,
+                'EXCHANGE_POINTS' => $amount,
+                'REMAINDER_POINTS' => $amount,
+                'EXPIRED' => 0,
+                'CREATED_AT' => Date::nowTime()
+            ]);
+        }
+
+        return true;
+    }
+
 
     /**
      * 减少
@@ -535,6 +621,45 @@ class Balance {
         return true;
     }
 
+    /**
+     * 减少
+     * @param $userId
+     * @param $amount
+     * @return bool
+     */
+    public static function deductPeriodExchangePoints($userId, $amount) {
+        if( $amount <= 0 ) return false;
+        $avalidList = UserPeriodExchangePoints::find()->where('USER_ID=:USER_ID AND EXPIRED=:EXPIRED AND REMAINDER_POINTS>0', [
+            'USER_ID' => $userId,
+            'EXPIRED'=>0
+        ])->orderBy('PERIOD_NUM ASC')->asArray()->all();
+        if( !$avalidList ) return false;
+
+        foreach ($avalidList as $everyData) {
+            if( $amount <= 0 ) break;
+
+            $remainderPoints = floatval($everyData['REMAINDER_POINTS']);
+            if( $amount >= $remainderPoints ) {
+                UserPeriodExchangePoints::updateAllCounters([
+                    'REMAINDER_POINTS' => (-1) * $remainderPoints
+                ], 'ID=:ID', ['ID'=>$everyData['ID']]);
+
+                $amount -= $remainderPoints;
+            }else {
+                UserPeriodExchangePoints::updateAllCounters([
+                    'REMAINDER_POINTS' => (-1) * $amount
+                ], 'ID=:ID', ['ID'=>$everyData['ID']]);
+
+                $amount = 0;
+            }
+
+            unset($everyData, $remainderPoints);
+        }
+        if( $amount > 0 ) return false;
+
+        return true;
+    }
+
     /**
      * 冻结用户余额
      * @param $userId
@@ -712,10 +837,11 @@ class Balance {
      */
     public static function getLogData($userId){
         $userWallet = UserWallet::findOne(['USER_ID' => $userId]);
+        $cash = !empty($userWallet) ? $userWallet['CASH'] : '';
         $userName = Info::getUserNameByUserId($userId);
         $data = [];
         $data[$userId]['label'] = $userName.'余额';
-        $data[$userId]['value'] = '奖金'.self::getAvailableBalance($userId).',现金'.$userWallet['CASH'];
+        $data[$userId]['value'] = '奖金'.self::getAvailableBalance($userId).',现金'.$cash;
         return $data;
     }
 }

+ 17 - 0
common/helpers/user/Info.php

@@ -401,6 +401,23 @@ class Info {
         return $result;
     }
 
+    /**
+     * 新增加的 生成前端姓名里用户名
+     * @param string $prefix
+     * @param int $length
+     * @return string
+     */
+    public static function generateWebUserName(string $prefix = 'HZ', int $length = 10) {
+        $result = Tool::randomString($length, $prefix).array_rand([0,1,2,3,5,6,7,8,9],1);
+        if (substr($result ,-1) == '4'){
+            return self::generateWebUserName($prefix, $length);
+        }
+        if (User::find()->where('USER_NAME=:USER_NAME', [':USER_NAME' => $result])->exists()) {
+            return self::generateWebUserName($prefix, $length);
+        }
+        return $result;
+    }
+
     /**
      * 定位会员的子公司
      * @param $userArea

+ 2 - 1
common/libs/logging/operate/AdminOperate.php

@@ -40,6 +40,7 @@ class AdminOperate extends AbstractOperate {
         if(!isset($params['optType'])){
             throw new \Exception('请设置操作类型');
         }
+
         $period = Period::instance();
         $periodNum = $period->getNowPeriodNum();
         $this->columns[] = [
@@ -49,7 +50,7 @@ class AdminOperate extends AbstractOperate {
             'save_before_content' => $this->saveBeforeContent,
             'save_after_content' => $this->saveAfterContent,
             'admin_id' => Yii::$app->user->id,
-            'admin_name' => \Yii::$app->user->getUserInfo()['adminName'],
+            'admin_name' => isset(\Yii::$app->user->getUserInfo()['adminName']) ?\Yii::$app->user->getUserInfo()['adminName'] :$params['adminName'],
             'ip' => Yii::$app->request->getUserIP(),
             'request_route' => Yii::$app->requestedRoute,
             'opt_type' => $params['optType'],

+ 4 - 4
common/models/Ad.php

@@ -100,17 +100,17 @@ class Ad extends \common\components\ActiveRecord
             'CREATE_ADMIN' => [
                 'label' => '创建人',
                 'type' => function($data){
-                    $value = $data['value'];
+                    $value = is_array($data) && isset($data['value']) ? $data['value'] : '';
                     $result = Admin::findOneAsArray('ID=:ID', [':ID'=>$value], 'ADMIN_NAME');
-                    return $result['ADMIN_NAME'];
+                    return !empty($result) ? $result['ADMIN_NAME'] : '';
                 },
             ],
             'UPDATE_ADMIN' => [
                 'label' => '修改人',
                 'type' => function($data){
-                    $value = $data['value'];
+                    $value = is_array($data) && isset($data['value']) ? $data['value'] : '';
                     $result = Admin::findOneAsArray('ID=:ID', [':ID'=>$value], 'ADMIN_NAME');
-                    return $result['ADMIN_NAME'];
+                    return !empty($result) ? $result['ADMIN_NAME'] : '';
                 },
             ],
             'CREATED_AT' => [

+ 8 - 4
common/models/BalanceAudit.php

@@ -38,6 +38,10 @@ class BalanceAudit extends \common\components\ActiveRecord
             'name' => 'reconsume_points',
             'label' => '复消积分',
         ],
+        'exchange_points' => [
+            'name' => 'exchange_points',
+            'label' => '兑换积分',
+        ],
         'cash' => [
             'name' => 'cash',
             'label' => '会员账户余额',
@@ -131,17 +135,17 @@ class BalanceAudit extends \common\components\ActiveRecord
             'UPDATE_ADMIN_ID' => [
                 'label' => '变更管理员',
                 'type' => function($data){
-                    $value = $data['value'];
+                    $value = is_array($data) && isset($data['value']) ? $data['value'] : '';
                     $result = Admin::findOneAsArray('ID=:ID', [':ID'=>$value], 'ADMIN_NAME');
-                    return $result['ADMIN_NAME'];
+                    return !empty($result) ? $result['ADMIN_NAME'] : '';
                 },
             ],
             'AUDIT_ADMIN_ID' => [
                 'label' => '审核管理员',
                 'type' => function($data){
-                    $value = $data['value'];
+                    $value = is_array($data) && isset($data['value']) ? $data['value'] : '';
                     $result = Admin::findOneAsArray('ID=:ID', [':ID'=>$value], 'ADMIN_NAME');
-                    return $result['ADMIN_NAME'];
+                    return !empty($result) ? $result['ADMIN_NAME'] : '';
                 },
             ],
             'CREATE_REMARK' => '备注',

+ 7 - 2
common/models/CalcBonus.php

@@ -100,7 +100,9 @@ use Yii;
  * @property string $ORI_BONUS_GL_BD 报单管理奖原奖金
  * @property string $ORI_BONUS_GL_FX 复消管理奖原奖金
  * @property string $RECONSUME_POINTS 复消积分
- * @property string $MANAGE_TAX 管理费
+ * @property string $MANAGE_TAX 管理费 
+ * @property string $BONUS_BS 蓝星奖金(即新的管理奖)
+ * @property string $ORI_BONUS_BS 蓝星原奖金(即新的管理奖,原奖金)
  */
 class CalcBonus extends \common\components\ActiveRecord
 {
@@ -120,7 +122,7 @@ class CalcBonus extends \common\components\ActiveRecord
         return [
             [['USER_ID', 'LAST_USER_NAME', 'LAST_REAL_NAME', 'LAST_MOBILE', 'LAST_SYSTEM_ID','LAST_LOCATION', 'PERIOD_NUM', 'CALC_YEAR', 'CALC_MONTH', 'CALCULATED_AT', 'P_CALC_MONTH', 'CREATED_AT'], 'required'],
             [['LAST_STATUS', 'LAST_PERIOD_AT', 'LAST_CREATED_AT', 'LAST_PROVINCE', 'LAST_CITY', 'LAST_COUNTY', 'LAST_IS_DIRECT_SELLER', 'LAST_LOCATION', 'PERIOD_NUM', 'CALC_YEAR', 'CALC_MONTH', 'CALCULATED_AT', 'IS_SENT', 'SENT_AT', 'CREATED_AT'], 'integer'],
-            [['BONUS_QY', 'BONUS_YC', 'BONUS_VIP', 'BONUS_FX', 'BONUS_LS', 'BONUS_FW', 'BONUS_BT', 'BONUS_BT_PROD', 'BONUS_BT_TOOL', 'DEDUCT_ZR', 'BONUS_FL', 'BONUS_CF', 'BONUS_LX', 'SHOULD_QY', 'SHOULD_DEDUCT_ZR', 'PV_1L', 'QY_1L', 'SURPLUS_1L', 'PV_2L', 'QY_2L', 'SURPLUS_2L', 'PV_3L', 'QY_3L', 'SURPLUS_3L', 'PV_4L', 'QY_4L', 'SURPLUS_4L', 'PV_5L', 'QY_5L', 'SURPLUS_5L', 'PV_PCS', 'PV_LS_TOUCH', 'SURPLUS_LS', 'QY_LS', 'PV_TOUCH', 'BONUS_REAL', 'BONUS_TOTAL', 'BONUS_INCOME', 'ORI_BONUS_QY','ORI_BONUS_QY_BD','ORI_BONUS_QY_FX','ORI_BONUS_YC', 'ORI_BONUS_VIP','ORI_BONUS_STANDARD','BONUS_BD','ORI_BONUS_BD','BONUS_TG','ORI_BONUS_TG','BONUS_XF','ORI_BONUS_XF','BONUS_YJ','ORI_BONUS_YJ','ORI_BONUS_YJ_BD','ORI_BONUS_YJ_FX','BONUS_GX','ORI_BONUS_GX','REAL_BONUS_GX','BONUS_GL','ORI_BONUS_GL','REAL_BONUS_GL','ORI_BONUS_GL_BD','ORI_BONUS_GL_FX','RECONSUME_POINTS','MANAGE_TAX'], 'number'],
+            [['ORI_BONUS_BS','EXCHANGE_POINTS','BONUS_BS','BONUS_QY', 'BONUS_YC', 'BONUS_VIP', 'BONUS_FX', 'BONUS_LS', 'BONUS_FW', 'BONUS_BT', 'BONUS_BT_PROD', 'BONUS_BT_TOOL', 'DEDUCT_ZR', 'BONUS_FL', 'BONUS_CF', 'BONUS_LX', 'SHOULD_QY', 'SHOULD_DEDUCT_ZR', 'PV_1L', 'QY_1L', 'SURPLUS_1L', 'PV_2L', 'QY_2L', 'SURPLUS_2L', 'PV_3L', 'QY_3L', 'SURPLUS_3L', 'PV_4L', 'QY_4L', 'SURPLUS_4L', 'PV_5L', 'QY_5L', 'SURPLUS_5L', 'PV_PCS', 'PV_LS_TOUCH', 'SURPLUS_LS', 'QY_LS', 'PV_TOUCH', 'BONUS_REAL', 'BONUS_TOTAL', 'BONUS_INCOME', 'ORI_BONUS_QY','ORI_BONUS_QY_BD','ORI_BONUS_QY_FX','ORI_BONUS_YC', 'ORI_BONUS_VIP','ORI_BONUS_STANDARD','BONUS_BD','ORI_BONUS_BD','BONUS_TG','ORI_BONUS_TG','BONUS_XF','ORI_BONUS_XF','BONUS_YJ','ORI_BONUS_YJ','ORI_BONUS_YJ_BD','ORI_BONUS_YJ_FX','BONUS_GX','ORI_BONUS_GX','REAL_BONUS_GX','BONUS_GL','ORI_BONUS_GL','REAL_BONUS_GL','ORI_BONUS_GL_BD','ORI_BONUS_GL_FX','RECONSUME_POINTS','MANAGE_TAX'], 'number'],
             [['ID', 'USER_ID', 'LAST_DEC_LV', 'LAST_EMP_LV', 'LAST_SUB_COM_ID', 'LAST_SYSTEM_ID'], 'string', 'max' => 32],
             [['LAST_USER_NAME', 'LAST_REC_USER_NAME', 'LAST_CON_USER_NAME'], 'string', 'max' => 16],
             [['LAST_REAL_NAME', 'LAST_REC_REAL_NAME', 'LAST_CON_REAL_NAME'], 'string', 'max' => 128],
@@ -229,6 +231,9 @@ class CalcBonus extends \common\components\ActiveRecord
             'ORI_BONUS_GL_FX'=> '复消管理奖原奖金',
             'RECONSUME_POINTS'=> '复消积分',
             'MANAGE_TAX'=> '管理费',
+            'EXCHANGE_POINTS' => '兑换积分',
+            'BONUS_BS' => '蓝星奖',
+            'ORI_BONUS_BS' => '蓝星原奖金'
         ];
     }
 

+ 78 - 0
common/models/CalcBonusBS.php

@@ -0,0 +1,78 @@
+<?php
+
+namespace common\models;
+
+use Yii;
+
+/**
+ * This is the model class for table "{{%CALC_BONUS_BS}}".
+ *
+ * @property string $ID
+ * @property string $USER_ID 会员ID
+ * @property string $LAST_DEC_LV 结算时会员级别
+ * @property string $LAST_EMP_LV 结算时会员聘级
+ * @property int $LAST_STATUS 结算时状态
+ * @property string $FROM_USER_ID 来源会员ID
+ * @property string $LAST_FROM_DEC_LV 结算时来源会员级别
+ * @property string $LAST_FROM_EMP_LV 结算时来源会员聘级
+ * @property int $LAST_FROM_STATUS 结算时来源状态
+ * @property string $AMOUNT 金额
+ * @property int $PERIOD_NUM 结算期数
+ * @property int $CALC_MONTH 所在结算月
+ * @property int $CALCULATED_AT 结算时间
+ * @property int $CREATED_AT 创建时间
+ * @property string $LOGS 日志
+ * @property $ORI_BONUS 原奖金
+ * @property $MANAGE_TAX 管理费
+ */
+class CalcBonusBS extends \common\components\ActiveRecord
+{
+    /**
+     * @inheritdoc
+     */
+    public static function tableName()
+    {
+        return '{{%CALC_BONUS_BS}}';
+    }
+
+    /**
+     * @inheritdoc
+     */
+    public function rules()
+    {
+        return [
+            [['USER_ID', 'PERIOD_NUM', 'CALC_MONTH', 'CALCULATED_AT', 'CREATED_AT'], 'required'],
+            [['AMOUNT', 'ORI_BONUS', 'MANAGE_TAX'], 'number'],
+            [['LAST_STATUS', 'PERIOD_NUM', 'CALC_MONTH', 'CALCULATED_AT', 'CREATED_AT', 'LAST_FROM_STATUS'], 'integer'],
+            [['ID', 'USER_ID', 'LAST_DEC_LV', 'LAST_EMP_LV', 'FROM_USER_ID',  'LAST_FROM_DEC_LV', 'LAST_FROM_EMP_LV'], 'string', 'max' => 32],
+            [['LOGS'], 'string', 'max' => 2000],
+            [['ID'], 'unique'],
+        ];
+    }
+
+    /**
+     * @inheritdoc
+     */
+    public function attributeLabels()
+    {
+        return [
+            'ID' => 'ID',
+            'USER_ID' => '会员ID',
+            'LAST_DEC_LV' => '结算时会员级别',
+            'LAST_EMP_LV' => '结算时会员聘级',
+            'LAST_STATUS' => '结算时状态',
+            'FROM_USER_ID' => '来源会员ID',
+            'LAST_FROM_DEC_LV' => '结算时来源会员级别',
+            'LAST_FROM_EMP_LV' => '结算时来源会员聘级',
+            'LAST_FROM_STATUS' => '结算时来源状态',
+            'AMOUNT' => '金额',
+            'PERIOD_NUM' => '结算期数',
+            'CALC_MONTH' => '所在结算月',
+            'CALCULATED_AT' => '结算时间',
+            'CREATED_AT' => '创建时间',
+            'LOGS' => '日志',
+            'ORI_BONUS' => '原奖金',
+            'MANAGE_TAX' => '管理费',
+        ];
+    }
+}

+ 6 - 4
common/models/DealType.php

@@ -35,6 +35,7 @@ class DealType extends \common\components\ActiveRecord
 //    CONST TEAMWORK_TRANSFER_OUT = '38EB53BCAAF24BA38B2E5FDA313EC928';//点位合作转出
 //    CONST TEAMWORK_TRANSFER_IN = '64198F701D374D2996AA8EF1D37769AB';//点位合作转入
     CONST RECONSUME_POINTS_SEND = 'A6BDF8A2E5F7450B80CBF3B28D8010D2';//复消积分发放
+    CONST EXCHANGE_POINTS_SEND = '316868755701501952';//兑换积分发放
 //    CONST LX_SEND = '12840830348E456696834E0624FE2331';//领袖分红发放
     CONST RECONSUME_POINTS_OUT = '01C2916A2ECA4D1B9C29AA333C6D13E7';//复消积分转出
 //    CONST LX_TRANSFER_OUT = '3CD904D1D0764A3FA3E9114DA1D930BD';//领袖分红转出
@@ -45,6 +46,7 @@ class DealType extends \common\components\ActiveRecord
     CONST DEDUCT_CLOSE = '37EFF25E5E3F46A6BB84B8C55997F276';//永久关停扣除
     CONST DEDUCT_LOGOUT = 'A1F1E76F34EE4981AB3BF4F8D20BB53E';//注销扣除
     CONST RECONSUME_POINTS_EXCHANGE = 'YA627DTHN81OBO7NIQ1OP8N3PGZX5C66';//复消积分兑换
+    CONST EXCHANGE_POINTS_EXCHANGE = '316872011148300288';//兑换积分兑换
 
 
     /**
@@ -132,9 +134,9 @@ class DealType extends \common\components\ActiveRecord
             'CREATE_ADMIN' => [
                 'label' => '创建人',
                 'type' => function($data){
-                    $value = $data['value'];
+                    $value = is_array($data) && isset($data['value']) ? $data['value'] : '';
                     $result = Admin::findOneAsArray('ID=:ID', [':ID'=>$value], 'ADMIN_NAME');
-                    return $result['ADMIN_NAME'];
+                    return !empty($result) ? $result['ADMIN_NAME'] : '';
                 },
             ],
             'CREATED_AT' => [
@@ -144,9 +146,9 @@ class DealType extends \common\components\ActiveRecord
             'UPDATE_ADMIN' => [
                 'label' => '修改人',
                 'type' => function($data){
-                    $value = $data['value'];
+                    $value = is_array($data) && isset($data['value']) ? $data['value'] : '';
                     $result = Admin::findOneAsArray('ID=:ID', [':ID'=>$value], 'ADMIN_NAME');
-                    return $result['ADMIN_NAME'];
+                    return !empty($result) ? $result['ADMIN_NAME'] : '';
                 },
             ],
             'UPDATED_AT' => [

+ 77 - 11
common/models/EmployLevel.php

@@ -38,18 +38,46 @@ class EmployLevel extends \common\components\ActiveRecord
 
     const NO_LEVEL_ID = '67BE1C6C21F81B32E055736AECE8644D';
     const JX_ZR_LEVEL_ID = 'E121497617216708615';
-    const SHX_ZJ_LEVEL_ID = '67BE82019BE524CAE055736AECE8644D';
+    const SHX_ZJ_LEVEL_ID = '99BE5FE7857C216AE000223AECE8644D';
+
+    // CONST EMP_LEVEL_SORT = [
+    //     'NO_LEVEL' => 0,//无聘级
+    //     'JX_ZR_LEVEL' => 1,//见习主任
+    //     'ZR_LEVEL' => 2,//主任
+    //     'GJ_ZR_LEVEL' => 3,//高级主任
+    //     'JL_LEVEL' => 4,//经理
+    //     'GJ_JL_LEVEL' => 5,//高级经理
+    //     'ZJ_LEVEL' => 6,//总监
+    //     'GJ_ZJ_LEVEL' => 7,//高级总监
+    //     'SHX_ZJ_LEVEL' => 8,//首席总监
+    // ];
+
+    // CONST EMP_LEVEL_SORT = [
+    //     'NO_LEVEL' => 0,//无聘级
+    //     'BS_LEVEL' => 1, // 蓝星
+    //     'JX_ZR_LEVEL' => 2,//见习主任
+    //     'ZR_LEVEL' => 3,//主任
+    //     'GJ_ZR_LEVEL' => 4,//高级主任
+    //     'JL_LEVEL' => 5,//经理
+    //     'GJ_JL_LEVEL' => 6,//高级经理
+    //     'ZJ_LEVEL' => 7,//总监
+    //     'GJ_ZJ_LEVEL' => 8,//高级总监
+    //     'SHX_ZJ_LEVEL' => 9,//首席总监
+    // ];
 
     CONST EMP_LEVEL_SORT = [
         'NO_LEVEL' => 0,//无聘级
-        'JX_ZR_LEVEL' => 1,//见习主任
-        'ZR_LEVEL' => 2,//主任
-        'GJ_ZR_LEVEL' => 3,//高级主任
-        'JL_LEVEL' => 4,//经理
-        'GJ_JL_LEVEL' => 5,//高级经理
-        'ZJ_LEVEL' => 6,//总监
-        'GJ_ZJ_LEVEL' => 7,//高级总监
-        'SHX_ZJ_LEVEL' => 8,//首席总监
+        'JX_ZR_LEVEL' => 1,//见习主任->专员
+        'ZR_LEVEL' => 2,//主任->高级专员
+        'GJ_ZR_LEVEL' => 3,//高级主任->主任
+        'JL_LEVEL' => 4,//经理->高级主任
+        'GJ_JL_LEVEL' => 5,//高级经理->副理
+        'GJFL_LEVEL' => 6,//总监->高级副理
+        'JL_LEVEL' => 7,//高级总监->经理
+        'GJ_JL_LEVEL' => 8,//首席总监->高级经理
+        'ZJ_LEVEL' => 9,// 总监
+        'GJ_ZJ_LEVEL' => 10,// 高级总监
+        'SHX_ZJ_LEVEL' => 11// 首席总监
     ];
 
     /**
@@ -115,7 +143,7 @@ class EmployLevel extends \common\components\ActiveRecord
     public static function getAllDataWithNumIndex(){
         $allData = static::find()->where('1=1')->orderBy('SORT ASC, CREATED_AT ASC')->indexBy('SORT')->asArray()->all();
         foreach($allData as $key=>$data){
-            if($data['YC_PERCENT_ARR']){
+            if(isset($data['YC_PERCENT_ARR'])){
                 $allData[$key]['YC_PERCENT_ARR'] = Json::decode($data['YC_PERCENT_ARR']);
             } else{
                 $allData[$key]['YC_PERCENT_ARR'] = [0,0,0,0,0,0,0,0,0,0];
@@ -140,6 +168,34 @@ class EmployLevel extends \common\components\ActiveRecord
         return $allData;
     }
 
+    // 获取级别配置一维度数组,id为键,级别等级为值
+    public static function getIdConvertLevelSort(){
+        $ret = [];
+        $allData = static::find()->where('1=1')->orderBy('SORT ASC, CREATED_AT ASC')->indexBy('ID')->asArray()->all();
+        foreach($allData as $data) {
+            $ret[$data['ID']] = $data['LEVEL_SORT'];
+        }
+        return $ret;
+    }
+
+    /**
+     * 从缓存获取信息
+     * @return array|mixed|\yii\db\ActiveRecord[]
+     */
+    public static function getIdConvertLevelSortCache(){
+        $key = Cache::EMP_LEVEL_CONFIG_KEY.':idsort';
+        $data = Yii::$app->cache->get($key);
+        if(!$data){
+            // 获取信息
+            $data = self::getIdConvertLevelSort();
+            Yii::$app->cache->set($key, $data);
+        }
+
+        return $data;
+    }
+
+    
+
     /**
      * 从缓存获取信息
      * @return array|mixed|\yii\db\ActiveRecord[]
@@ -207,13 +263,23 @@ class EmployLevel extends \common\components\ActiveRecord
         return $empLevels[$id]['SORT']??0;
     }
 
+    // /**
+    //  * 是否合格高级经理及以上级别
+    //  * @param $id
+    //  * @return bool
+    //  */
+    // public static function chkSenior($id) {
+    //     if (self::getSortById($id) >= 2) return true;
+    //     return false;
+    // }
+
     /**
      * 是否合格高级经理及以上级别
      * @param $id
      * @return bool
      */
     public static function chkSenior($id) {
-        if (self::getSortById($id) >= 2) return true;
+        if (self::getSortById($id) >= 3) return true;
         return false;
     }
 

+ 82 - 0
common/models/FlowExchangePoints.php

@@ -0,0 +1,82 @@
+<?php
+
+namespace common\models;
+
+use Yii;
+
+/**
+ * This is the model class for table "{{%FLOW_RECONSUME_POINTS}}".
+ *
+ * @property string $ID
+ * @property string $USER_ID 会员ID
+ * @property string $LAST_DEC_LV 记录时会员级别
+ * @property string $LAST_EMP_LV 记录时会员聘级
+ * @property int $LAST_STATUS 记录时状态
+ * @property string $AMOUNT 金额
+ * @property string $TOTAL 当前总金额
+ * @property int $IS_INCR 是否增加
+ * @property string $REMARK 备注
+ * @property int $REMARK_IS_SHOW 备注是否显示
+ * @property string $DEAL_TYPE_ID 交易类型名称
+ * @property int $DEAL_TYPE_IS_PRESET 交易类型是否预置
+ * @property string $ADMIN_NAME 操作人名称
+ * @property int $PERIOD_NUM 所在期数
+ * @property int $CALC_MONTH 所在结算月
+ * @property string $P_MONTH 表分区的日期索引
+ * @property int $CREATED_AT 创建时间
+ * @property int $DELETED 是否删除
+ * @property int $DELETED_AT 删除时间
+ */
+class FlowExchangePoints extends \common\components\ActiveRecord
+{
+    /**
+     * {@inheritdoc}
+     */
+    public static function tableName()
+    {
+        return '{{%FLOW_EXCHANGE_POINTS}}';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+            [['USER_ID', 'REMARK', 'PERIOD_NUM', 'CALC_MONTH', 'P_MONTH', 'CREATED_AT'], 'required'],
+            [['AMOUNT', 'TOTAL'], 'number'],
+            [['LAST_STATUS', 'IS_INCR', 'PERIOD_NUM', 'CALC_MONTH', 'CREATED_AT', 'REMARK_IS_SHOW', 'DELETED', 'DELETED_AT', 'DEAL_TYPE_IS_PRESET'], 'integer'],
+            [['ID', 'USER_ID', 'ADMIN_NAME', 'LAST_DEC_LV', 'LAST_EMP_LV', 'DEAL_TYPE_ID'], 'string', 'max' => 32],
+            [['REMARK'], 'string', 'max' => 255],
+            [['ID'], 'unique'],
+        ];
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function attributeLabels()
+    {
+        return [
+            'ID' => 'ID',
+            'USER_ID' => '会员ID',
+            'LAST_DEC_LV' => '记录时会员级别',
+            'LAST_EMP_LV' => '记录时会员聘级',
+            'LAST_STATUS' => '记录时状态',
+            'AMOUNT' => '金额',
+            'TOTAL' => '当前总金额',
+            'IS_INCR' => '是否增加',
+            'REMARK' => '备注',
+            'REMARK_IS_SHOW' => '备注是否显示',
+            'DEAL_TYPE_ID' => '交易类型ID',
+            'DEAL_TYPE_IS_PRESET' => '交易类型是否预置',
+            'ADMIN_NAME' => '操作人名称',
+            'PERIOD_NUM' => '所在期数',
+            'CALC_MONTH' => '所在结算月',
+            'P_MONTH' => '表分区的日期索引',
+            'CREATED_AT' => '创建时间',
+            'DELETED' => '是否删除',
+            'DELETED_AT' => '删除时间',
+        ];
+    }
+}

+ 77 - 0
common/models/PerfActiveUser.php

@@ -0,0 +1,77 @@
+<?php
+
+namespace common\models;
+
+use common\helpers\snowflake\SnowFake;
+use common\helpers\Tool;
+use Yii;
+use yii\base\Exception;
+
+/**
+ * This is the model class for table "{{%PERF_ACTIVE_USER}}".
+ *
+ * 
+ * 
+ * @property string $ID
+ * @property string $USER_ID 用户id
+ * @property string $IS_ACTIVE 是否活跃 1活跃
+ * @property string $IS_SENT 是否已挂网,已官网不能删除 1已挂网
+ * @property int $PERIOD_NUM 业绩期,是第几期
+ * @property string $CALC_MONTH 结算年月202110
+ * @property string $P_CALC_MONTH 结算年月日2021-12-10
+ * @property string $WHICH_WEEK 当月第几周
+ * @property int $WHICH_MONTH 当年第几月
+ * @property string $WHICH_YEAR 结算周期年份
+ * @property int $CREATED_AT 创建时间
+ */
+class PerfActiveUser extends \common\components\ActiveRecord
+{
+    /**
+     * {@inheritdoc}
+     */
+    public static function tableName()
+    {
+        return '{{%PERF_ACTIVE_USER}}';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+            [['IS_ACTIVE', 'USER_ID', 'PERIOD_NUM', 'CALC_MONTH', 'P_CALC_MONTH', 'CREATED_AT', 'SRATR_AT', 'END_AT'], 'required'],
+            [['PERIOD_NUM', 'CALC_MONTH', 'CREATED_AT'], 'integer'],
+            [['ID', 'USER_ID'], 'string', 'max' => 32],
+            [['P_CALC_MONTH'], 'string', 'max' => 7],
+            [['ID'], 'unique'],
+        ];
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function attributeLabels()
+    {
+        return [
+            'ID' => 'ID',
+            'USER_ID' => '用户ID',
+            'IS_ACTIVE' => '是否活跃',
+            'IS_SENT' => '是否已挂网',
+            'PERIOD_NUM' => '业绩期',
+            'CALC_MONTH' => '结算年月',
+            'P_CALC_MONTH' => '结算年月日',
+            'SRATR_AT' => '活跃开始时间',
+            'END_AT' => '活跃结束时间',
+            'CREATED_AT' => '创建时间'
+        ];
+    }
+
+    /**
+     * 生成sn
+     * @return string
+     */
+    public static function generateSN() {
+        return  SnowFake::instance()->generateId();
+    }
+}

+ 4 - 4
common/models/PerfAudit.php

@@ -178,18 +178,18 @@ class PerfAudit extends \common\components\ActiveRecord
             'CREATE_ADMIN' => [
                 'label' => '创建管理员',
                 'type' => function($data){
-                    $value = $data['value'];
+                    $value = is_array($data) && isset($data['value']) ? $data['value'] : '';
                     $result = Admin::findOneAsArray('ID=:ID', [':ID'=>$value], 'ADMIN_NAME');
-                    return $result['ADMIN_NAME'];
+                    return !empty($result) ? $result['ADMIN_NAME'] : '';
                 },
             ],
             'REMARK' => '备注',
             'AUDIT_ADMIN' => [
                 'label' => '审核管理员',
                 'type' => function($data){
-                    $value = $data['value'];
+                    $value = is_array($data) && isset($data['value']) ? $data['value'] : '';
                     $result = Admin::findOneAsArray('ID=:ID', [':ID'=>$value], 'ADMIN_NAME');
-                    return $result['ADMIN_NAME'];
+                    return !empty($result) ? $result['ADMIN_NAME'] : '';
                 },
             ],
             'CREATED_AT' => [

+ 14 - 1
common/models/Period.php

@@ -146,6 +146,12 @@ class Period extends \common\components\ActiveRecord
         return $this->periodArr;
     }
 
+    // 通过期数,获取此期数据
+    public static function getInfoByPeriodNum($periodNum) {
+        
+        return static::findOneAsArray(['PERIOD_NUM'=>$periodNum]);
+    }
+
     /**
      * 是否存在所传期数
      * @param int $periodNum
@@ -553,7 +559,14 @@ class Period extends \common\components\ActiveRecord
      */
     public function isLastSent($periodNum){
         $period = $this->setPeriodNum($periodNum-1);
-        if($period['IS_SENT'] == self::SEND_FINISH) return true;
+        if ($period) {
+            if($period['IS_SENT'] == self::SEND_FINISH) { 
+                return true;
+            } else {
+                return false;
+            }
+        }
+        
         return false;
     }
 

+ 4 - 4
common/models/ReconsumeAudit.php

@@ -98,17 +98,17 @@ class ReconsumeAudit extends \common\components\ActiveRecord
             'CREATE_ADMIN' => [
                 'label' => '申请人',
                 'type' => function($data){
-                    $value = $data['value'];
+                    $value = is_array($data) && isset($data['value']) ? $data['value'] : '';
                     $result = Admin::findOneAsArray('ID=:ID', [':ID'=>$value], 'ADMIN_NAME');
-                    return $result['ADMIN_NAME'];
+                    return !empty($result) ? $result['ADMIN_NAME'] : '';
                 },
             ],
             'AUDIT_ADMIN' => [
                 'label' => '审核人',
                 'type' => function($data){
-                    $value = $data['value'];
+                    $value = is_array($data) && isset($data['value']) ? $data['value'] : '';
                     $result = Admin::findOneAsArray('ID=:ID', [':ID'=>$value], 'ADMIN_NAME');
-                    return $result['ADMIN_NAME'];
+                    return !empty($result) ? $result['ADMIN_NAME'] : '';
                 },
             ],
             'CREATE_REMARK' => '备注',

+ 1 - 0
common/models/User.php

@@ -274,6 +274,7 @@ class User extends \common\components\ActiveRecord
             'ID' => $userId,
             'USER_NAME' => $userInfo['USER_NAME'],
             'NATION' => \Yii::$app->params['nation'][$userInfo['NATION']]['name']??'',
+            'NATION_ID' => \Yii::$app->params['nation'][$userInfo['NATION']]['id']??'',
             'REAL_NAME' => $userInfo['REAL_NAME'],
             'ID_CARD' => $userInfo['ID_CARD'],
 //            'ID_CARD' => Tool::hideIdCard($userInfo['ID_CARD']),

+ 4 - 4
common/models/UserBind.php

@@ -294,17 +294,17 @@ class UserBind extends \common\components\ActiveRecord {
             'CREATE_ADMIN' => [
                 'label' => '创建管理员',
                 'type' => function($data){
-                    $value = $data['value'];
+                    $value = is_array($data) && isset($data['value']) ? $data['value'] : '';
                     $result = Admin::findOneAsArray('ID=:ID', [':ID'=>$value], 'ADMIN_NAME');
-                    return $result['ADMIN_NAME'];
+                    return !empty($result) ? $result['ADMIN_NAME'] : '';
                 },
             ],
             'UPDATE_ADMIN' => [
                 'label' => '修改管理员',
                 'type' => function($data){
-                    $value = $data['value'];
+                    $value = is_array($data) && isset($data['value']) ? $data['value'] : '';
                     $result = Admin::findOneAsArray('ID=:ID', [':ID'=>$value], 'ADMIN_NAME');
-                    return $result['ADMIN_NAME'];
+                    return !empty($result) ? $result['ADMIN_NAME'] : '';
                 },
             ],
             'CREATED_AT' => [

+ 4 - 1
common/models/UserBonus.php

@@ -68,7 +68,7 @@ class UserBonus extends \common\components\ActiveRecord
     {
         return [
             [['USER_ID', 'CREATED_AT'], 'required'],
-            [['BONUS', 'BONUS_FREEZE', 'CF', 'LX', 'QY_TOTAL', 'YC_TOTAL', 'VIP_TOTAL', 'FX_TOTAL', 'LS_TOTAL', 'FW_TOTAL', 'BT_TOTAL', 'BT_PROD_TOTAL', 'BT_TOOL_TOTAL', 'CF_TOTAL', 'LX_TOTAL', 'DEDUCT_ZR_TOTAL', 'FL_TOTAL', 'BD_TOTAL','TG_TOTAL','YJ_TOTAL','GX_TOTAL','GL_TOTAL', 'ORI_QY_TOTAL','ORI_YC_TOTAL','ORI_YC_TOTAL','ORI_BD_TOTAL','ORI_TG_TOTAL','ORI_YJ_TOTAL','ORI_GX_TOTAL','ORI_GL_TOTAL','RECONSUME_POINTS','MANAGE_TAX', 'RECONSUME_POINTS_EXPIRED', 'RECONSUME_POINTS_TOTAL', 'BONUS_TOTAL'], 'number'],
+            [['BS_TOTAL','ORI_BS_TOTAL','BS','BONUS', 'BONUS_FREEZE', 'CF', 'LX', 'QY_TOTAL', 'YC_TOTAL', 'VIP_TOTAL', 'FX_TOTAL', 'LS_TOTAL', 'FW_TOTAL', 'BT_TOTAL', 'BT_PROD_TOTAL', 'BT_TOOL_TOTAL', 'CF_TOTAL', 'LX_TOTAL', 'DEDUCT_ZR_TOTAL', 'FL_TOTAL', 'BD_TOTAL','TG_TOTAL','YJ_TOTAL','GX_TOTAL','GL_TOTAL', 'ORI_QY_TOTAL','ORI_YC_TOTAL','ORI_YC_TOTAL','ORI_BD_TOTAL','ORI_TG_TOTAL','ORI_YJ_TOTAL','ORI_GX_TOTAL','ORI_GL_TOTAL','RECONSUME_POINTS','MANAGE_TAX', 'RECONSUME_POINTS_EXPIRED', 'RECONSUME_POINTS_TOTAL', 'BONUS_TOTAL'], 'number'],
             [['VER', 'CREATED_AT'], 'integer'],
             [['ID','USER_ID'], 'string', 'max' => 32],
             [['USER_ID'], 'unique'],
@@ -120,6 +120,9 @@ class UserBonus extends \common\components\ActiveRecord
             'RECONSUME_POINTS_EXPIRED' => '复消积分过期',
             'MANAGE_TAX' => '管理费累计',
             'BONUS_TOTAL' => '总奖金累计',
+            'BS' => '蓝星奖(即新的管理奖)',
+            'BS_TOTAL' => '蓝星(管理)累计',
+            'ORI_BS_TOTAL' => '蓝星原奖金累计'
         ];
     }
 

+ 4 - 4
common/models/UserMove.php

@@ -144,17 +144,17 @@ class UserMove extends \common\components\ActiveRecord
             'MOVE_ADMIN_ID' => [
                 'label' => '创建人',
                 'type' => function($data){
-                    $value = $data['value'];
+                    $value = is_array($data) && isset($data['value']) ? $data['value'] : '';
                     $result = Admin::findOneAsArray('ID=:ID', [':ID'=>$value], 'ADMIN_NAME');
-                    return $result['ADMIN_NAME'];
+                    return !empty($result) ? $result['ADMIN_NAME'] : '';
                 },
             ],
             'AUDIT_ADMIN_ID' => [
                 'label' => '审核人',
                 'type' => function($data){
-                    $value = $data['value'];
+                    $value = is_array($data) && isset($data['value']) ? $data['value'] : '';
                     $result = Admin::findOneAsArray('ID=:ID', [':ID'=>$value], 'ADMIN_NAME');
-                    return $result['ADMIN_NAME'];
+                    return !empty($result) ? $result['ADMIN_NAME'] : '';
                 },
             ],
             'CREATE_REMARK' => '备注',

+ 20 - 10
common/models/UserNetwork.php

@@ -7,6 +7,7 @@ use common\helpers\Cache;
 use common\helpers\NetPoint;
 use common\helpers\user\Info;
 use common\helpers\user\Perf;
+use Exception;
 use Yii;
 use yii\data\Pagination;
 use yii\helpers\Json;
@@ -104,16 +105,25 @@ class UserNetwork extends \common\components\ActiveRecord
         unset($parentUidsArr);
         $parentList = [];
         foreach ($pageParentUids as $parentUid) {
-            $parentNetInfo = static::find($isSlaves, $db)->select(['TOP_DEEP', 'LOCATION_TAG'])->where('USER_ID=:USER_ID', ['USER_ID'=>$parentUid])->asArray()->one();
-            $parentList[] = [
-                'USER_ID' => $userId,
-                'TOP_DEEP' => $userNetInfo['TOP_DEEP'],
-                'PARENT_UID' => $parentUid,
-                'PARENT_DEEP' => $parentNetInfo['TOP_DEEP'],
-//                'LOCATION_TAG' => $userNetInfo['LOCATION_TAG'],
-//                'PARENT_LOCATION_TAG' => $parentNetInfo['LOCATION_TAG'],
-                'LOCATION' => substr($userNetInfo['LOCATION_TAG'], strlen($parentNetInfo['LOCATION_TAG']), 1),
-            ];
+            try {
+                $parentNetInfo = static::find($isSlaves, $db)->select(['TOP_DEEP', 'LOCATION_TAG'])->where('USER_ID=:USER_ID', ['USER_ID'=>$parentUid])->asArray()->one();
+                $parentList[] = [
+                    'USER_ID' => $userId,
+                    'TOP_DEEP' => $userNetInfo['TOP_DEEP'],
+                    'PARENT_UID' => $parentUid,
+                    'PARENT_DEEP' => $parentNetInfo['TOP_DEEP'],
+    //                'LOCATION_TAG' => $userNetInfo['LOCATION_TAG'],
+    //                'PARENT_LOCATION_TAG' => $parentNetInfo['LOCATION_TAG'],
+                    'LOCATION' => substr($userNetInfo['LOCATION_TAG'], strlen($parentNetInfo['LOCATION_TAG']), 1),
+                ];
+            } catch (Exception $e) {
+                $file_name = date('Y-m-d', time()).'_usernetwork.php_error.log';
+                file_put_contents($file_name, var_export([
+                    '$parentUid' => $parentUid,
+                    '$userId' => $userId,
+                    'error' => $e->getMessage()
+                ],true), FILE_APPEND);
+            }
 
             unset($parentUid, $parentNetInfo);
         }

+ 59 - 0
common/models/UserPeriodExchangePoints.php

@@ -0,0 +1,59 @@
+<?php
+
+namespace common\models;
+
+use Yii;
+
+/**
+ * This is the model class for table "{{%USER_PERIOD_POINTS}}".
+ *
+ * @property string $ID
+ * @property string $USER_ID 会员ID
+ * @property int $PERIOD_NUM 报单期数
+ * @property string $EXCHANGE_POINTS 兑换积分
+ * @property string $REMAINDER_POINTS 剩余积分
+ * @property int EXPIRED 是否过期
+ * @property int EXPIRED_PERIOD 过期期数
+ * @property int EXPIRED_AT 过期时间
+ * @property int $CREATED_AT 创建时间
+ */
+class UserPeriodExchangePoints extends \common\components\ActiveRecord
+{
+    /**
+     * {@inheritdoc}
+     */
+    public static function tableName()
+    {
+        return '{{%USER_PERIOD_EXCHANGE_POINTS}}';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+            [['USER_ID', 'PERIOD_NUM', 'CREATED_AT'], 'required'],
+            [['PERIOD_NUM', 'CREATED_AT', 'EXPIRED', 'EXPIRED_PERIOD', 'EXPIRED_AT'], 'integer'],
+            [['EXCHANGE_POINTS', 'REMAINDER_POINTS'], 'number'],
+            [['ID', 'USER_ID'], 'string', 'max' => 32],
+        ];
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function attributeLabels()
+    {
+        return [
+            'ID' => 'ID',
+            'USER_ID' => '会员ID',
+            'EXCHANGE_POINTS' => '兑换积分',
+            'REMAINDER_POINTS' => '剩余积分',
+            'EXPIRED' => '是否过期',
+            'EXPIRED_PERIOD' => '过期期数',
+            'EXPIRED_AT' => '过期时间',
+            'CREATED_AT' => '创建时间',
+        ];
+    }
+}

+ 4 - 4
common/models/UserStatusAudit.php

@@ -152,17 +152,17 @@ class UserStatusAudit extends \common\components\ActiveRecord
             'CREATE_ADMIN' => [
                 'label' => '创建人',
                 'type' => function($data){
-                    $value = $data['value'];
+                    $value = is_array($data) && isset($data['value']) ? $data['value'] : '';
                     $result = Admin::findOneAsArray('ID=:ID', [':ID'=>$value], 'ADMIN_NAME');
-                    return $result['ADMIN_NAME'];
+                    return !empty($result) ? $result['ADMIN_NAME'] : '';
                 },
             ],
             'AUDIT_ADMIN' => [
                 'label' => '审核人',
                 'type' => function($data){
-                    $value = $data['value'];
+                    $value = is_array($data) && isset($data['value']) ? $data['value'] : '';
                     $result = Admin::findOneAsArray('ID=:ID', [':ID'=>$value], 'ADMIN_NAME');
-                    return $result['ADMIN_NAME'];
+                    return !empty($result) ? $result['ADMIN_NAME'] : '';
                 },
             ],
             'CREATE_REMARK' => '创建备注',

+ 4 - 4
common/models/UserSystem.php

@@ -156,17 +156,17 @@ class UserSystem extends \common\components\ActiveRecord {
             'CREATE_ADMIN' => [
                 'label' => '创建人',
                 'type' => function($data){
-                    $value = $data['value'];
+                    $value = is_array($data) && isset($data['value']) ? $data['value'] : '';
                     $result = Admin::findOneAsArray('ID=:ID', [':ID'=>$value], 'ADMIN_NAME');
-                    return $result['ADMIN_NAME'];
+                    return !empty($result) ? $result['ADMIN_NAME'] : '';
                 },
             ],
             'UPDATE_ADMIN' => [
                 'label' => '修改人',
                 'type' => function($data){
-                    $value = $data['value'];
+                    $value = is_array($data) && isset($data['value']) ? $data['value'] : '';
                     $result = Admin::findOneAsArray('ID=:ID', [':ID'=>$value], 'ADMIN_NAME');
-                    return $result['ADMIN_NAME'];
+                    return !empty($result) ? $result['ADMIN_NAME'] : '';
                 },
             ],
             'CREATE_REMARK' => '备注',

+ 4 - 4
common/models/UserTeamwork.php

@@ -91,17 +91,17 @@ class UserTeamwork extends \common\components\ActiveRecord
             'CREATE_ADMIN' => [
                 'label' => '操作人',
                 'type' => function($data){
-                    $value = $data['value'];
+                    $value = is_array($data) && isset($data['value']) ? $data['value'] : '';
                     $result = Admin::findOneAsArray('ID=:ID', [':ID'=>$value], 'ADMIN_NAME');
-                    return $result['ADMIN_NAME'];
+                    return !empty($result) ? $result['ADMIN_NAME'] : '';
                 },
             ],
             'UPDATE_ADMIN' => [
                 'label' => '修改人',
                 'type' => function($data){
-                    $value = $data['value'];
+                    $value = is_array($data) && isset($data['value']) ? $data['value'] : '';
                     $result = Admin::findOneAsArray('ID=:ID', [':ID'=>$value], 'ADMIN_NAME');
-                    return $result['ADMIN_NAME'];
+                    return !empty($result) ? $result['ADMIN_NAME'] : '';
                 },
             ],
             'CREATED_AT' => [

+ 7 - 2
common/models/forms/ChangeBalanceForm.php

@@ -178,14 +178,19 @@ class ChangeBalanceForm extends Model {
     public function isStatus($attribute) {
         // 获取当前提现单的状态
         $oneData = BalanceAudit::findOneAsArray(['ID' => $this->id]);
+        if (empty($oneData) && empty($this->id) && !empty($this->selected)) {
+            if (is_array($this->selected) && count($this->selected) == 1) {
+                $oneData = BalanceAudit::findOneAsArray(['ID' => $this->selected[0]]);
+            }
+        }
         switch ($this->auditStatus) {
             case 'un':
                 $this->addError($attribute, '不能设置为待审核状态' . $this->auditStatus);
                 break;
             case 'true':
-                if ($oneData['AUDIT_STATUS'] == \Yii::$app->params['auditStatus']['true']['value']) {
+                if (isset($oneData['AUDIT_STATUS']) && $oneData['AUDIT_STATUS'] == \Yii::$app->params['auditStatus']['true']['value']) {
                     $this->addError($attribute, '已经审核通过不能重复审核');
-                } elseif ($oneData['AUDIT_STATUS'] == \Yii::$app->params['auditStatus']['reject']['value']) {
+                } elseif (isset($oneData['AUDIT_STATUS']) && $oneData['AUDIT_STATUS'] == \Yii::$app->params['auditStatus']['reject']['value']) {
                     $this->addError($attribute, '已经审核拒绝不能重复审核');
                 }
                 break;

+ 3 - 1
common/models/forms/ConfigPeriodForm.php

@@ -75,8 +75,10 @@ class ConfigPeriodForm extends Model
             if(!Config::updateAll(['VALUE'=>$this->closeTime, 'UPDATED_AT'=>Date::nowTime()], "CONFIG_NAME='closeTime'")){
                 throw new Exception('封期时间更新失败');
             }
+            // 异步重新生成业绩期先注释掉
             // 异步处理添加任务
-            $taskKey = \Yii::$app->swooleAsyncTimer->asyncHandle('config/update-period', \Yii::$app->request->post());
+            //$taskKey = \Yii::$app->swooleAsyncTimer->asyncHandle('config/update-period', \Yii::$app->request->post());
+            $taskKey = true;
             if($taskKey === false){
                 throw new Exception('请求异步服务器失败');
             }

+ 33 - 11
common/models/forms/OrderForm.php

@@ -288,9 +288,15 @@ class OrderForm extends Model
             if ($v) {
                 $goods = ShopGoods::findOneAsArray('ID=:ID AND STATUS=1',[':ID'=> $ids[$k]]);
                 if($goods['STORE_NUMS']>0){
-                    $discount = $goodsType[$goods['TYPE']]['discount'];
-                    $realPrice = $goods['SELL_PRICE'] * $discount/100;
-                    $realPv = $goods['PRICE_PV'] * $discount/100;
+                    if ($goods['TYPE'] == 1 || $goods['TYPE'] == 2) {
+                        $discount = $goodsType[$goods['TYPE']]['discount'];
+                        $realPrice = $goods['SELL_PRICE'] * $discount/100;
+                        $realPv = $goods['PRICE_PV'] * $discount/100;
+                    } else {
+                        $discount = $goods['SELL_DISCOUNT'];
+                        $realPrice = $goods['SELL_PRICE'] * $discount;
+                        $realPv = $goods['PRICE_PV'] * $discount;
+                    }
                     $totalAmount += $realPrice * intval($v);
                     $totalPv += $realPv * intval($v);
 //                    if($this->payType=='cash') {
@@ -334,7 +340,11 @@ class OrderForm extends Model
                 if (Cash::getAvailableBalance($loginUserId) < $this->_payAmount) {
                     throw new Exception('余额不足,无法购买商品');
                 }
-            }else{
+            } else if ($this->payType =='exchange') {
+                if ($this->_payAmount > Balance::getBalanceExchangePoints($loginUserId)) {
+                    throw new Exception('兑换积分不足,无法购买商品');
+                }
+            } else{
                 if ($this->_payAmount > Balance::getBalanceReconsumePoints($loginUserId)) {
                     throw new Exception('复消积分不足,无法购买商品');
                 }
@@ -376,9 +386,9 @@ class OrderForm extends Model
         $orderModel->USER_ID = $userId;
         $orderModel->USER_NAME = $userName;
         $orderModel->ORDER_AMOUNT = $this->_decAmount;
-        $orderModel->PV = $this->_decPv;
+        $orderModel->PV = $this->payType =='exchange' ? 0 : $this->_decPv;
         $orderModel->PAY_AMOUNT = $this->_payAmount;
-        $orderModel->PAY_PV = $this->_decPv;
+        $orderModel->PAY_PV = $this->payType =='exchange' ? 0 : $this->_decPv; // 兑换积分不能算业绩
         $orderModel->PAY_AT = Date::nowTime();
         $orderModel->PAY_TYPE = $this->payType;
         $orderModel->PERIOD_NUM = $nowPeriodNum;
@@ -402,6 +412,10 @@ class OrderForm extends Model
         }
         // 加入商品到订单商品表
         foreach($this->_orderGoods as $key=>$value){
+            // 增加判断,如果订单是兑换券购买,则AR_ORDER_GOODS中的REAL_PV真实PV应该是0
+            if ($orderModel->PAY_TYPE == 'exchange') {
+                $this->_orderGoods[$key]['REAL_PV'] = 0;
+            }
             $this->_orderGoods[$key]['ORDER_SN'] = $orderModel->SN;
             $this->_orderGoods[$key]['P_CALC_MONTH'] = Date::ociToDate($nowCalcMonth, Date::OCI_TIME_FORMAT_SHORT_MONTH);
         }
@@ -410,7 +424,9 @@ class OrderForm extends Model
         //扣除会员余额/积分
         if($this->payType=='cash') {
             Cash::changeUserCash(\Yii::$app->user->id, 'CASH', -abs($this->_payAmount), ['REMARK' => '会员复销余额支付']);
-        }else{
+        } else if ($this->payType=='exchange') {
+            Balance::changeUserBonus(\Yii::$app->user->id,'exchange_points', -abs($this->_payAmount),['DEAL_TYPE_ID' => DealType::EXCHANGE_POINTS_EXCHANGE,'REMARK' => '会员兑换积分兑换']);
+        } else{
             Balance::changeUserBonus(\Yii::$app->user->id,'reconsume_points', -abs($this->_payAmount),['DEAL_TYPE_ID' => DealType::RECONSUME_POINTS_EXCHANGE,'REMARK' => '会员复销积分兑换']);
         }
         return $orderModel;
@@ -434,9 +450,15 @@ class OrderForm extends Model
             if ($v) {
                 $goods = ShopGoods::findOneAsArray('ID=:ID AND STATUS=1',[':ID'=> $ids[$k]]);
                 if($goods['STORE_NUMS']>0){
-                    $discount = $goodsType[$goods['TYPE']]['discount'];
-                    $realPrice = $goods['SELL_PRICE'] * $discount/100;
-                    $realPv = $goods['PRICE_PV'] * $discount/100;
+                    if ($goods['TYPE'] == 1 || $goods['TYPE'] == 2) {
+                        $discount = $goodsType[$goods['TYPE']]['discount'];
+                        $realPrice = $goods['SELL_PRICE'] * $discount/100;
+                        $realPv = $goods['PRICE_PV'] * $discount/100;
+                    } else {
+                        $discount = $goods['SELL_DISCOUNT'];
+                        $realPrice = $goods['SELL_PRICE'] * $discount;
+                        $realPv = $goods['PRICE_PV'] * $discount;
+                    }
                     $totalAmount += $realPrice * intval($v);
                     $totalPv += $realPv * intval($v);
                     $this->_orderGoods[] = [
@@ -581,7 +603,7 @@ class OrderForm extends Model
         $hash = '';
         $max = strlen($seed) - 1;
         for ($i = 0; $i < $length; $i++) {
-            $hash .= $seed{mt_rand(0, $max)};
+            $hash .= $seed[mt_rand(0, $max)];
         }
         return $hash;
     }

+ 1 - 1
common/models/forms/RechargeForm.php

@@ -242,7 +242,7 @@ class RechargeForm extends Model {
         $hash = '';
         $max = strlen($seed) - 1;
         for ($i = 0; $i < $length; $i++) {
-            $hash .= $seed{mt_rand(0, $max)};
+            $hash .= $seed[mt_rand(0, $max)];
         }
         return $hash;
     }

+ 22 - 9
common/models/forms/ShopGoodsForm.php

@@ -17,6 +17,7 @@ class ShopGoodsForm extends Model
     public $id;
     public $goodsName;
     public $type;
+    public $sellDiscount;
     public $giftType;
     public $sellType;
     public $goodsNo;
@@ -46,14 +47,15 @@ class ShopGoodsForm extends Model
     public function rules()
     {
         return [
-            [['id','type','giftType','sellType','goodsNo', 'goodsName', 'unit', 'sellPrice', 'marketPrice', 'pricePv', 'storeNums', 'content', 'sort','status','cover'], 'trim'],
-            [['goodsName','type','giftType','sellType','goodsNo', 'storeNums','sellPrice','marketPrice','pricePv', 'sort','status','cover'], 'required'],
+            [['id','sellDiscount','giftType','sellType','goodsNo', 'goodsName', 'unit', 'sellPrice', 'marketPrice', 'pricePv', 'storeNums', 'content', 'sort','status','cover'], 'trim'],
+            [['goodsName','sellDiscount','giftType','goodsNo', 'storeNums','sellPrice','marketPrice','pricePv', 'sort','status','cover'], 'required'],
             [['id'], 'required', 'on'=>'edit'],
             [['id'], 'exist', 'targetClass'=>ShopGoods::class, 'targetAttribute'=>'ID'],
             [['sellPrice','marketPrice','pricePv'], 'price'],
             [['id'], 'initModel'],
             [['selectedIds'], 'isSelected'],
             [['sort'], 'isSort'],
+            [['sellDiscount'], 'isDiscount']
         ];
     }
 
@@ -63,7 +65,7 @@ class ShopGoodsForm extends Model
             'selectedIds' => '商品ID',
             'id' => '产品ID',
             'goodsName' => '商品名称',
-            'type' => '商品来源',
+            'sellDiscount' => '会员折扣',
             'giftType' => '商品类型',
             'sellType' => '出售方式',
             'goodsNo' => '产品编号',
@@ -87,8 +89,8 @@ class ShopGoodsForm extends Model
     {
         $parentScenarios =  parent::scenarios();
         $customScenarios = [
-            'add' => ['goodsName','type','giftType', 'sellType','goodsNo','unit','sellPrice','marketPrice','pricePv','storeNums', 'content','sort','cover'],
-            'edit' => ['id','goodsName','type','giftType', 'sellType','goodsNo','unit','sellPrice','marketPrice','pricePv', 'storeNums', 'content','sort','cover'],
+            'add' => ['goodsName','sellDiscount','giftType', 'sellType','goodsNo','unit','sellPrice','marketPrice','pricePv','storeNums', 'content','sort','cover'],
+            'edit' => ['id','goodsName','sellDiscount','giftType', 'sellType','goodsNo','unit','sellPrice','marketPrice','pricePv', 'storeNums', 'content','sort','cover'],
             'changeStatus' => ['selectedIds', 'status'],
         ];
         return array_merge($parentScenarios, $customScenarios);
@@ -126,6 +128,13 @@ class ShopGoodsForm extends Model
         }
     }
 
+    // 折扣为0-1
+    public function isDiscount($attributes) {
+        if ($this->sellDiscount < 0 || $this->sellDiscount > 1 || !is_numeric($this->sellDiscount)) {
+            $this->addError($attributes, '折扣请填写0-1之间的数');
+        }
+    }
+
     /**
      * 添加
      * @return ShopGoods|null
@@ -140,9 +149,11 @@ class ShopGoodsForm extends Model
             // 添加商品
             $shopGoods = new ShopGoods();
             $shopGoods->GOODS_NAME = $this->goodsName;
-            $shopGoods->TYPE = $this->type;
+            //$shopGoods->TYPE = $this->type;
+            $shopGoods->SELL_DISCOUNT = $this->sellDiscount;
             $shopGoods->GIFT_TYPE = implode(',',$this->giftType);
-            $shopGoods->SELL_TYPE = implode(',',$this->sellType);
+            // $shopGoods->SELL_TYPE = implode(',',$this->sellType);
+            $shopGoods->SELL_TYPE = '1,2,3';
             $shopGoods->GOODS_NO = $this->goodsNo;
             $shopGoods->UNIT = $this->unit ? $this->unit : '个';
             $shopGoods->COVER = $this->cover ? $this->cover : '';
@@ -182,9 +193,11 @@ class ShopGoodsForm extends Model
         try {
             $model = $this->_model;
             $model->GOODS_NAME = $this->goodsName;
-            $model->TYPE = $this->type;
+            $model->TYPE = 0;
+            $model->SELL_DISCOUNT = $this->sellDiscount;
             $model->GIFT_TYPE = implode(',',$this->giftType);
-            $model->SELL_TYPE = implode(',',$this->sellType);
+            // $model->SELL_TYPE = implode(',',$this->sellType);
+            $model->SELL_TYPE = '1,2,3';
             $model->GOODS_NO = $this->goodsNo;
             $model->UNIT = $this->unit ? $this->unit : '个';
             $model->COVER = $this->cover ? $this->cover : '';

+ 1 - 1
common/models/forms/TransferForm.php

@@ -284,7 +284,7 @@ class TransferForm extends Model {
         $hash = '';
         $max = strlen($seed) - 1;
         for ($i = 0; $i < $length; $i++) {
-            $hash .= $seed{mt_rand(0, $max)};
+            $hash .= $seed[mt_rand(0, $max)];
         }
         return $hash;
     }

+ 2 - 2
common/models/forms/WithdrawForm.php

@@ -423,7 +423,7 @@ class WithdrawForm extends Model {
         $hash = '';
         $max = strlen($seed) - 1;
         for ($i = 0; $i < $length; $i++) {
-            $hash .= $seed{mt_rand(0, $max)};
+            $hash .= $seed[mt_rand(0, $max)];
         }
         return $hash;
     }
@@ -440,7 +440,7 @@ class WithdrawForm extends Model {
         $hash = '';
         $max = strlen($seed) - 1;
         for ($i = 0; $i < $length; $i++) {
-            $hash .= $seed{mt_rand(0, $max)};
+            $hash .= $seed[mt_rand(0, $max)];
         }
         return $hash;
     }

+ 19 - 0
console/controllers/BonusController.php

@@ -9,8 +9,10 @@ namespace console\controllers;
 
 use backendApi\modules\v1\models\lists\bonus\BalanceList;
 use backendApi\modules\v1\models\lists\bonus\CfLxAuditList;
+use backendApi\modules\v1\models\lists\bonus\FlowBalanceList;
 use backendApi\modules\v1\models\lists\bonus\FlowBonusList;
 use backendApi\modules\v1\models\lists\bonus\FlowCfList;
+use backendApi\modules\v1\models\lists\bonus\FlowExchangePointsList;
 use backendApi\modules\v1\models\lists\bonus\FlowLxList;
 use backendApi\modules\v1\models\lists\bonus\FlowReconsumePointsList;
 use backendApi\modules\v1\models\lists\bonus\OtherPeriodBonusList;
@@ -210,6 +212,14 @@ class BonusController extends BaseController
         return $this->_export($taskId, FlowBonusList::class, '奖金流水列表');
     }
 
+    /**
+     * 余额流水导出
+     * @param $taskId
+     * @return bool
+     */
+    public function actionFlowBalanceExport($taskId){
+        return $this->_export($taskId, FlowBalanceList::class, '复消积分流水列表');
+    }
 
     /**
      * 复消积分流水导出
@@ -220,6 +230,15 @@ class BonusController extends BaseController
         return $this->_export($taskId, FlowReconsumePointsList::class, '复消积分流水列表');
     }
 
+    /**
+     * 兑换积分流水导出
+     * @param $taskId
+     * @return bool
+     */
+    public function actionFlowExchangeExport($taskId){
+        return $this->_export($taskId, FlowExchangePointsList::class, '兑换积分流水列表');
+    }
+
     /**
      * 车房养老奖流水导出
      * @param $taskId

+ 1 - 1
frontendApi/config/menu.php

@@ -76,7 +76,7 @@ return [
             ['name'=>'最新奖金', 'class'=>'', 'icon'=>'', 'controller'=>'bonus', 'action'=>'new', 'routePath'=>'bonus/new', 'show'=>1,'allow'=>'newBonusSwitch'],
             ['name'=>'往期奖金', 'class'=>'', 'icon'=>'', 'controller'=>'bonus', 'action'=>'other', 'routePath'=>'bonus/other', 'show'=>1,'allow'=>'pastBonusSwitch'],
             //['name'=>'实时业绩', 'class'=>'', 'icon'=>'', 'controller'=>'bonus', 'action'=>'real-time-perf', 'routePath'=>'bonus/real-time-perf', 'show'=>1,],
-            ['name'=>'房产积分', 'class'=>'', 'icon'=>'', 'controller'=>'bonus', 'action'=>'fc-point', 'routePath'=>'bonus/fc-point', 'show'=>1,],
+           // ['name'=>'房产积分', 'class'=>'', 'icon'=>'', 'controller'=>'bonus', 'action'=>'fc-point', 'routePath'=>'bonus/fc-point', 'show'=>1,],
 //            ['name'=>'报单中心补助明细查询', 'class'=>'', 'icon'=>'', 'controller'=>'bonus', 'action'=>'flow-bt', 'routePath'=>'bonus/flow-bt', 'show'=>1,],
 //            ['name'=>'报单中心货补追溯', 'class'=>'', 'icon'=>'', 'controller'=>'bonus', 'action'=>'trace-fl', 'routePath'=>'bonus/trace-fl', 'show'=>1,],
         ]

+ 23 - 0
frontendApi/modules/v1/controllers/BaseController.php

@@ -46,6 +46,29 @@ class BaseController extends \yii\rest\ActiveController {
      */
     public function beforeAction($action) {
         $this->forbiddenQuicklyUser();
+
+        // 增加的判断用户登录后未操作后的超时 和 快速登录的逻辑
+        $isQuickly = User::isQuicklyLogin();
+        if ($isQuickly != 1 && Yii::$app->getUser()->getUserInfo()){
+            $userId = Yii::$app->getUser()->getUserInfo()['id'];
+            $redisKey = 'user:timeOut';
+
+            $lastTime = '';
+            if (!Yii::$app->tokenRedis->hget($redisKey, $userId)) {
+                $lastTime = time();
+            }else{
+                $lastTime = Yii::$app->tokenRedis->hget($redisKey, $userId);
+            }
+
+            $currentTime = time();
+            $timeOut = Yii::$app->params['operationTimeOut'];
+            if ($currentTime - $lastTime > $timeOut) {
+                return self::notice('Connection not operated for too long', 402);
+            } else {
+                Yii::$app->tokenRedis->hset($redisKey, $userId, time());
+            }
+        }
+
         return parent::beforeAction($action);
     }
 

+ 130 - 84
frontendApi/modules/v1/controllers/BonusController.php

@@ -28,6 +28,7 @@ use common\models\PerfMonth;
 use common\models\Period;
 use common\models\DecRole;
 use common\models\EmployLevel;
+use common\models\FlowExchangePoints;
 use common\models\ScoreMonth;
 use common\models\UserBonus;
 use common\models\UserWallet;
@@ -43,11 +44,12 @@ class BonusController extends BaseController {
      */
     public function actionIndex() {
         $userId = \Yii::$app->user->id;
-        $data = UserBonus::findUseSlaves()->select('BONUS,RECONSUME_POINTS')->where('USER_ID=:USER_ID', [':USER_ID' => $userId])->asArray()->one();
+        $data = UserBonus::findUseSlaves()->select('BONUS,RECONSUME_POINTS,EXCHANGE_POINTS')->where('USER_ID=:USER_ID', [':USER_ID' => $userId])->asArray()->one();
         if (!$data) {
             $data = [
                 'BONUS' => 0,
                 'RECONSUME_POINTS' => 0,
+                'EXCHANGE_POINTS' => 0,
             ];
         }
         $data['CASH'] = 0;
@@ -67,6 +69,7 @@ class BonusController extends BaseController {
         $wallet[] = ['walletType' => 'bonus', 'walletName' => '会员奖金', 'amount' => Tool::formatPrice($data['BONUS'])];
         $wallet[] = ['walletType' => 'cash', 'walletName' => '会员余额', 'amount' => Tool::formatPrice($data['CASH'])];
         $wallet[] = ['walletType' => 'point', 'walletName' => '会员积分', 'amount' => Tool::formatPrice($data['RECONSUME_POINTS'])];
+        $wallet[] = ['walletType' => 'exchange', 'walletName' => '兑换积分', 'amount' => Tool::formatPrice($data['EXCHANGE_POINTS'])];
 //        if ($showCFLX) {
 //            $wallet[] = ['walletType' => 'cf', 'walletName' => '福利积分一', 'amount' => Tool::formatPrice($data['CF'])];
 //            $wallet[] = ['walletType' => 'lx', 'walletName' => '福利积分二', 'amount' => Tool::formatPrice($data['LX'])];
@@ -86,7 +89,7 @@ class BonusController extends BaseController {
 //            if ($decRole['GOODS_SUBSIDY'] <= 0) $showFl = false;
 //        }
 
-        $dealSwitch = Cache::getSystemConfig()['dealSwitch']['VALUE'];
+        $dealSwitch = isset(Cache::getSystemConfig()['dealSwitch']) ? Cache::getSystemConfig()['dealSwitch']['VALUE'] : '';
 
         return static::notice(['wallet' => $wallet,'dealSwitch'=>$dealSwitch]);
     }
@@ -98,7 +101,7 @@ class BonusController extends BaseController {
      */
     public function actionWalletFlow(){
         $walletType = \Yii::$app->request->get('walletType');
-        if(!in_array($walletType,['bonus','point','cash'])) return static::notice('错误的账户类型',400);
+        if(!in_array($walletType,['bonus','point','cash','exchange'])) return static::notice('错误的账户类型',400);
         $dealType = \Yii::$app->request->get('dealType');
         $createAt = \Yii::$app->request->get('createAt');
         $remark = \Yii::$app->request->get('remark');
@@ -149,6 +152,13 @@ class BonusController extends BaseController {
                 'select' => 'AMOUNT,TOTAL,IS_INCR,REMARK,PERIOD_NUM,CALC_MONTH,CREATED_AT',
                 'orderBy' => 'CREATED_AT DESC',
             ]);
+        }else if ($walletType == 'exchange') {
+            $dealLists = FlowExchangePoints::find()->groupBy('DEAL_TYPE_ID')->select('DEAL_TYPE_ID')->where('USER_ID=:USER_ID',[':USER_ID'=>\Yii::$app->user->id])->asArray()->all();
+            $data = FlowExchangePoints::lists($condition, $params, [
+                'useSlaves' => true,
+                'select' => 'AMOUNT,TOTAL,IS_INCR,REMARK,REMARK_IS_SHOW,PERIOD_NUM,CALC_MONTH,CREATED_AT,DEAL_TYPE_ID,DEAL_TYPE_IS_PRESET',
+                'orderBy' => 'CREATED_AT DESC',
+            ]);
         }
         if($data) {
             if($walletType != 'cash') {
@@ -226,54 +236,71 @@ class BonusController extends BaseController {
             $data[] = ['name' => '期数', 'value' => $periodNum];
             $data[] = ['name' => '级别', 'value' => Cache::getDecLevelConfig()[$calcBonus['LAST_DEC_LV']]['LEVEL_NAME']];
             $data[] = ['name' => '荣誉', 'value' => Cache::getEmpLevelConfig()[$calcBonus['LAST_EMP_LV']]['LEVEL_NAME']];
-            if ($sysConfig['openQY']['VALUE']) {
-                $data[] = ['name' => '团队奖', 'value' => Tool::formatPrice($calcBonus['ORI_BONUS_QY'])];
-            }
-            if ($sysConfig['openYC']['VALUE']) {
-                $data[] = ['name' => '荣衔奖', 'value' => Tool::formatPrice($calcBonus['ORI_BONUS_YC'])];
-            }
-            if ($sysConfig['openVIP']['VALUE']) {
-                $data[] = ['name' => 'VIP奖', 'value' => Tool::formatPrice($calcBonus['ORI_BONUS_VIP'])];
-            }
-            if ($sysConfig['openFW']['VALUE']) {
-                $data[] = ['name' => '服务奖', 'value' => Tool::formatPrice($calcBonus['ORI_BONUS_BD'])];
-            }
             if ($sysConfig['openTG']['VALUE']) {
-                $data[] = ['name' => '推广奖', 'value' => Tool::formatPrice($calcBonus['ORI_BONUS_TG'])];
+                // 销售奖金 就是 原来的推广奖
+                $data[] = ['name' => '销售奖金', 'value' => Tool::formatPrice($calcBonus['ORI_BONUS_TG'])];
             }
-            if ($sysConfig['openXF']['VALUE']) {
-                $data[] = ['name' => '消费奖', 'value' => Tool::formatPrice($calcBonus['ORI_BONUS_XF'])];
-            }
-            if ($sysConfig['openYJ']['VALUE']) {
-                $data[] = ['name' => '业绩奖', 'value' => Tool::formatPrice($calcBonus['ORI_BONUS_YJ'])];
+            if ($sysConfig['openQY']['VALUE']) {
+                // 业绩奖金  就是原来的团队奖 并将业绩奖金改成绩效奖金
+                // $data[] = ['name' => '团队奖', 'value' => Tool::formatPrice($calcBonus['ORI_BONUS_QY'])];
+                $data[] = ['name' => '绩效奖金', 'value' => Tool::formatPrice($calcBonus['ORI_BONUS_QY'])];
             }
+            // 管理奖金 就是新的蓝星奖
+            $data[] = ['name' => '管理奖金', 'value' => Tool::formatPrice($calcBonus['ORI_BONUS_BS'])];
             if ($sysConfig['openGX']['VALUE']) {
-                $data[] = ['name' => '共享奖', 'value' => Tool::formatPrice($calcBonus['ORI_BONUS_GX'])];
+                $data[] = ['name' => '共享奖', 'value' => Tool::formatPrice($calcBonus['ORI_BONUS_GX'])];
             }
-            if ($sysConfig['openGL']['VALUE']) {
-                $data[] = ['name' => '管理奖', 'value' => Tool::formatPrice($calcBonus['ORI_BONUS_GL'])];
-            }
-            if ($sysConfig['openJXS']['VALUE']) {
-                $data[] = ['name' => '团队成长奖', 'value' => Tool::formatPrice($calcBonus['ORI_BONUS_STANDARD'])];
+            if ($sysConfig['openFW']['VALUE']) {
+                $data[] = ['name' => '服务奖金', 'value' => Tool::formatPrice($calcBonus['ORI_BONUS_BD'])];
             }
-//        if($sysConfig['openLS']['VALUE']) {
-//            $data[] = ['name' => '零售奖', 'value' => Tool::formatPrice($calcBonus['BONUS_LS'])];
-//        }
-//        $data[]=['name'=>'责任业绩扣除','value'=>Tool::formatPrice($calcBonus['DEDUCT_ZR'])];
             $data[] = ['name' => '总奖金', 'value' => Tool::formatPrice($calcBonus['BONUS_TOTAL'])];
             $data[] = ['name' => '管理费', 'value' => Tool::formatPrice($calcBonus['MANAGE_TAX'])];
             $data[] = ['name' => '实发奖金', 'value' => Tool::formatPrice($calcBonus['BONUS_REAL'])];
-//        $data[]=['name'=>'总奖金','value'=>Tool::formatPrice($calcBonus['BONUS_TOTAL'])];
             $data[] = ['name' => '复消积分', 'value' => Tool::formatPrice($calcBonus['RECONSUME_POINTS'])];
-//        if($sysConfig['openLX']['VALUE']) {
-//            $data[] = ['name' => '福利积分二', 'value' => Tool::formatPrice($calcBonus['BONUS_LX'])];
-//        }
+            $data[] = ['name' => '兑换积分', 'value' => Tool::formatPrice($calcBonus['EXCHANGE_POINTS'])];
             $data[] = ['name' => '一市场新增业绩', 'value' => Tool::formatFrontPerf($calcBonus['PV_1L'])];
             $data[] = ['name' => '二市场新增业绩', 'value' => Tool::formatFrontPerf($calcBonus['PV_2L'])];
             $data[] = ['name' => '三市场新增业绩', 'value' => Tool::formatFrontPerf($calcBonus['PV_3L'])];
             $data[] = ['name' => '一市场结余业绩', 'value' => Tool::formatFrontPerf($calcBonus['SURPLUS_1L'])];
             $data[] = ['name' => '二市场结余业绩', 'value' => Tool::formatFrontPerf($calcBonus['SURPLUS_2L'])];
             $data[] = ['name' => '三市场结余业绩', 'value' => Tool::formatFrontPerf($calcBonus['SURPLUS_3L'])];
+
+
+
+            // if ($sysConfig['openYC']['VALUE']) {
+            //     $data[] = ['name' => '荣衔奖', 'value' => Tool::formatPrice($calcBonus['ORI_BONUS_YC'])];
+            // }
+            // if ($sysConfig['openVIP']['VALUE']) {
+            //     $data[] = ['name' => 'VIP奖', 'value' => Tool::formatPrice($calcBonus['ORI_BONUS_VIP'])];
+            // }
+            
+            
+            // if ($sysConfig['openXF']['VALUE']) {
+            //     $data[] = ['name' => '消费奖', 'value' => Tool::formatPrice($calcBonus['ORI_BONUS_XF'])];
+            // }
+            // if ($sysConfig['openYJ']['VALUE']) {
+            //     $data[] = ['name' => '业绩奖', 'value' => Tool::formatPrice($calcBonus['ORI_BONUS_YJ'])];
+            // }
+            
+            // if ($sysConfig['openGL']['VALUE']) {
+            //     $data[] = ['name' => '管理奖', 'value' => Tool::formatPrice($calcBonus['ORI_BONUS_GL'])];
+            // }
+            
+            // if ($sysConfig['openJXS']['VALUE']) {
+            //     $data[] = ['name' => '团队成长奖', 'value' => Tool::formatPrice($calcBonus['ORI_BONUS_STANDARD'])];
+            // }
+//        if($sysConfig['openLS']['VALUE']) {
+//            $data[] = ['name' => '零售奖', 'value' => Tool::formatPrice($calcBonus['BONUS_LS'])];
+//        }
+//        $data[]=['name'=>'责任业绩扣除','value'=>Tool::formatPrice($calcBonus['DEDUCT_ZR'])];
+            
+            
+//        $data[]=['name'=>'总奖金','value'=>Tool::formatPrice($calcBonus['BONUS_TOTAL'])];
+            
+//        if($sysConfig['openLX']['VALUE']) {
+//            $data[] = ['name' => '福利积分二', 'value' => Tool::formatPrice($calcBonus['BONUS_LX'])];
+//        }
+            
 //        $data[]=['name'=>'四市场新增业绩','value'=>Tool::formatFrontPerf($calcBonus['PV_4L'])];
 //        $data[]=['name'=>'五市场新增业绩','value'=>Tool::formatFrontPerf($calcBonus['PV_5L'])];
 //        $data[]=['name'=>'虚拟市场新增业绩','value'=>Tool::formatFrontPerf($calcBonus['PV_LS_TOUCH'])];
@@ -298,7 +325,14 @@ class BonusController extends BaseController {
     public function actionOther(){
         //获取可以查看几期奖金
         $showBonusPeriodNum = Cache::getSystemConfig()['showBonusPeriodNum']['VALUE'];
-        $calcBonus = CalcBonus::find()->where('USER_ID=:USER_ID AND IS_SENT=1', [':USER_ID' => \Yii::$app->user->id])->select('PERIOD_NUM,ORI_BONUS_QY,ORI_BONUS_YC,ORI_BONUS_VIP,ORI_BONUS_STANDARD,ORI_BONUS_BD,ORI_BONUS_TG,ORI_BONUS_XF,BONUS_TOTAL,MANAGE_TAX,BONUS_REAL,BONUS_INCOME,ORI_BONUS_YJ,ORI_BONUS_GX,ORI_BONUS_GL,RECONSUME_POINTS,LAST_DEC_LV,LAST_EMP_LV')->limit($showBonusPeriodNum)->orderBy('PERIOD_NUM DESC')->asArray()->all();
+        $calcBonus = CalcBonus::find()->where('USER_ID=:USER_ID AND IS_SENT=1', [':USER_ID' => \Yii::$app->user->id])
+        ->select('PERIOD_NUM,ORI_BONUS_QY,ORI_BONUS_YC,ORI_BONUS_VIP,ORI_BONUS_STANDARD,ORI_BONUS_BD,ORI_BONUS_TG,
+        ORI_BONUS_XF,BONUS_TOTAL,MANAGE_TAX,BONUS_REAL,BONUS_INCOME,ORI_BONUS_YJ,ORI_BONUS_GX,ORI_BONUS_GL,RECONSUME_POINTS,
+        LAST_DEC_LV,LAST_EMP_LV,EXCHANGE_POINTS,ORI_BONUS_BS')
+        ->limit($showBonusPeriodNum)
+        ->orderBy('PERIOD_NUM DESC')
+        ->asArray()
+        ->all();
         $sysConfig = Cache::getSystemConfig();
 
         //增加明细开关控制(0 只显示总奖金 1 全部显示)
@@ -310,41 +344,48 @@ class BonusController extends BaseController {
                 $calcBonus[$key]['LAST_DEC_NAME'] = ['name' => '级别', 'value' => Cache::getDecLevelConfig()[$calcBonus[$key]['LAST_DEC_LV']]['LEVEL_NAME']];
                 $calcBonus[$key]['LAST_EMP_NAME'] = ['name' => '聘级', 'value' => Cache::getEmpLevelConfig()[$calcBonus[$key]['LAST_EMP_LV']]['LEVEL_NAME']];
 
-                if ($sysConfig['openQY']['VALUE']) {
-                    $calcBonus[$key]['BONUS_QY'] = ['name' => '团队奖', 'value' => Tool::formatPrice($calcBonus[$key]['ORI_BONUS_QY'])];
-                }
-                if ($sysConfig['openYC']['VALUE']) {
-                    $calcBonus[$key]['BONUS_YC'] = ['name' => '荣衔奖', 'value' => Tool::formatPrice($calcBonus[$key]['ORI_BONUS_YC'])];
-                }
-                if ($sysConfig['openVIP']['VALUE']) {
-                    $calcBonus[$key]['BONUS_VIP'] = ['name' => 'VIP奖', 'value' => Tool::formatPrice($calcBonus[$key]['ORI_BONUS_VIP'])];
-                }
-                if ($sysConfig['openFW']['VALUE']) {
-                    $calcBonus[$key]['BONUS_BD'] = ['name' => '服务奖', 'value' => Tool::formatPrice($calcBonus[$key]['ORI_BONUS_BD'])];
-                }
+                // 销售奖金,就是原来的推广奖金
                 if ($sysConfig['openTG']['VALUE']) {
-                    $calcBonus[$key]['BONUS_TG'] = ['name' => '推广奖', 'value' => Tool::formatPrice($calcBonus[$key]['ORI_BONUS_TG'])];
+                    $calcBonus[$key]['BONUS_TG'] = ['name' => '销售奖金', 'value' => Tool::formatPrice($calcBonus[$key]['ORI_BONUS_TG'])];
                 }
-                if ($sysConfig['openXF']['VALUE']) {
-                    $calcBonus[$key]['BONUS_XF'] = ['name' => '消费奖', 'value' => Tool::formatPrice($calcBonus[$key]['ORI_BONUS_XF'])];
-                }
-                if ($sysConfig['openYJ']['VALUE']) {
-                    $calcBonus[$key]['BONUS_YJ'] = ['name' => '业绩奖', 'value' => Tool::formatPrice($calcBonus[$key]['ORI_BONUS_YJ'])];
+                // 业绩奖金,就是原来的团队奖  并将业绩奖金改成绩效奖金
+                if ($sysConfig['openQY']['VALUE']) {
+                    $calcBonus[$key]['BONUS_QY'] = ['name' => '绩效奖金', 'value' => Tool::formatPrice($calcBonus[$key]['ORI_BONUS_QY'])];
                 }
+                // 管理奖金 就是新的蓝星奖金
+                $calcBonus[$key]['BONUS_BS'] = ['name' => '管理奖金', 'value' => Tool::formatPrice($calcBonus[$key]['ORI_BONUS_BS'])];
+                //共享奖
                 if ($sysConfig['openGX']['VALUE']) {
-                    $calcBonus[$key]['BONUS_GX'] = ['name' => '共享奖', 'value' => Tool::formatPrice($calcBonus[$key]['ORI_BONUS_GX'])];
+                    $calcBonus[$key]['BONUS_GX'] = ['name' => '共享奖', 'value' => Tool::formatPrice($calcBonus[$key]['ORI_BONUS_GX'])];
                 }
-                if ($sysConfig['openGL']['VALUE']) {
-                    $calcBonus[$key]['BONUS_GL'] = ['name' => '管理奖', 'value' => Tool::formatPrice($calcBonus[$key]['ORI_BONUS_GL'])];
-                }
-                if ($sysConfig['openJXS']['VALUE']) {
-                    $calcBonus[$key]['BONUS_STANDARD'] = ['name' => '团队成长奖', 'value' => Tool::formatPrice($calcBonus[$key]['ORI_BONUS_STANDARD'])];
+                //服务奖
+                if ($sysConfig['openFW']['VALUE']) {
+                    $calcBonus[$key]['BONUS_BD'] = ['name' => '服务奖金', 'value' => Tool::formatPrice($calcBonus[$key]['ORI_BONUS_BD'])];
                 }
+                // 总奖金
                 $calcBonus[$key]['BONUS_TOTAL'] = ['name' => '总奖金', 'value' => Tool::formatPrice($calcBonus[$key]['BONUS_TOTAL'])];
+                $calcBonus[$key]['RECONSUME_POINTS'] = ['name' => '复销积分', 'value' => Tool::formatPrice($calcBonus[$key]['RECONSUME_POINTS'])];
+                $calcBonus[$key]['EXCHANGE_POINTS'] = ['name' => '兑换积分', 'value' => Tool::formatPrice($calcBonus[$key]['EXCHANGE_POINTS'])];
                 $calcBonus[$key]['MANAGE_TAX'] = ['name' => '管理费', 'value' => Tool::formatPrice($calcBonus[$key]['MANAGE_TAX'])];
                 $calcBonus[$key]['BONUS_REAL'] = ['name' => '实发奖金', 'value' => Tool::formatPrice($calcBonus[$key]['BONUS_REAL'])];
-                $calcBonus[$key]['RECONSUME_POINTS'] = ['name' => '复消积分', 'value' => Tool::formatPrice($calcBonus[$key]['RECONSUME_POINTS'])];
-
+                // if ($sysConfig['openYC']['VALUE']) {
+                //     $calcBonus[$key]['BONUS_YC'] = ['name' => '荣衔奖', 'value' => Tool::formatPrice($calcBonus[$key]['ORI_BONUS_YC'])];
+                // }
+                // if ($sysConfig['openVIP']['VALUE']) {
+                //     $calcBonus[$key]['BONUS_VIP'] = ['name' => 'VIP奖', 'value' => Tool::formatPrice($calcBonus[$key]['ORI_BONUS_VIP'])];
+                // }
+                // if ($sysConfig['openXF']['VALUE']) {
+                //     $calcBonus[$key]['BONUS_XF'] = ['name' => '消费奖', 'value' => Tool::formatPrice($calcBonus[$key]['ORI_BONUS_XF'])];
+                // }
+                // if ($sysConfig['openYJ']['VALUE']) {
+                //     $calcBonus[$key]['BONUS_YJ'] = ['name' => '业绩奖', 'value' => Tool::formatPrice($calcBonus[$key]['ORI_BONUS_YJ'])];
+                // }
+                // if ($sysConfig['openGL']['VALUE']) {
+                //     $calcBonus[$key]['BONUS_GL'] = ['name' => '管理奖', 'value' => Tool::formatPrice($calcBonus[$key]['ORI_BONUS_GL'])];
+                // }
+                // if ($sysConfig['openJXS']['VALUE']) {
+                //     $calcBonus[$key]['BONUS_STANDARD'] = ['name' => '团队成长奖', 'value' => Tool::formatPrice($calcBonus[$key]['ORI_BONUS_STANDARD'])];
+                // }
             }else{
 
                 $calcBonus[$key]['BONUS_TOTAL'] = ['name' => '总奖金', 'value' => Tool::formatPrice($calcBonus[$key]['BONUS_TOTAL'])];
@@ -354,38 +395,43 @@ class BonusController extends BaseController {
 
         if($flowBonusSwitch) {
             $tableKey[] = 'PERIOD_NUM';
-            if ($sysConfig['openQY']['VALUE']) {
-                $tableKey[] = 'BONUS_QY';
-            }
-            if ($sysConfig['openYC']['VALUE']) {
-                $tableKey[] = 'BONUS_YC';
-            }
-            if ($sysConfig['openVIP']['VALUE']) {
-                $tableKey[] = 'BONUS_VIP';
-            }
-            if ($sysConfig['openFW']['VALUE']) {
-                $tableKey[] = 'BONUS_BD';
-            }
             if ($sysConfig['openTG']['VALUE']) {
                 $tableKey[] = 'BONUS_TG';
             }
-            if ($sysConfig['openXF']['VALUE']) {
-                $tableKey[] = 'BONUS_XF';
-            }
-            if ($sysConfig['openYJ']['VALUE']) {
-                $tableKey[] = 'BONUS_YJ';
+            if ($sysConfig['openQY']['VALUE']) {
+                $tableKey[] = 'BONUS_QY';
             }
+            $tableKey[] = 'BONUS_BS';
             if ($sysConfig['openGX']['VALUE']) {
                 $tableKey[] = 'BONUS_GX';
             }
-            if ($sysConfig['openGL']['VALUE']) {
-                $tableKey[] = 'BONUS_GL';
-            }
-            if ($sysConfig['openJXS']['VALUE']) {
-                $tableKey[] = 'BONUS_STANDARD';
+            // if ($sysConfig['openYC']['VALUE']) {
+            //     $tableKey[] = 'BONUS_YC';
+            // }
+            // if ($sysConfig['openVIP']['VALUE']) {
+            //     $tableKey[] = 'BONUS_VIP';
+            // }
+            if ($sysConfig['openFW']['VALUE']) {
+                $tableKey[] = 'BONUS_BD';
             }
+            
+            // if ($sysConfig['openXF']['VALUE']) {
+            //     $tableKey[] = 'BONUS_XF';
+            // }
+            // if ($sysConfig['openYJ']['VALUE']) {
+            //     $tableKey[] = 'BONUS_YJ';
+            // }
+            
+            // if ($sysConfig['openGL']['VALUE']) {
+            //     $tableKey[] = 'BONUS_GL';
+            // }
+            // if ($sysConfig['openJXS']['VALUE']) {
+            //     $tableKey[] = 'BONUS_STANDARD';
+            // }
+           
             $tableKey[] = 'BONUS_TOTAL';
             $tableKey[] = 'RECONSUME_POINTS';
+            $tableKey[] = 'EXCHANGE_POINTS';
             $tableKey[] = 'MANAGE_TAX';
             $tableKey[] = 'BONUS_REAL';
         }else{

+ 9 - 4
frontendApi/modules/v1/controllers/SiteController.php

@@ -198,22 +198,27 @@ class SiteController extends BaseController
         }
 
         if($menu['allow']=='transferRecordSwitch'){
-            $transferRecordSwitch = Cache::getSystemConfig()['transferRecordSwitch']['VALUE'];
+            $transferRecordSwitch = isset(Cache::getSystemConfig()['transferRecordSwitch']) ? Cache::getSystemConfig()['transferRecordSwitch']['VALUE'] : '';
             if($transferRecordSwitch) return false;
         }
 
         if($menu['allow']=='transferSwitch'){
-            $transferSwitch = Cache::getSystemConfig()['transferSwitch']['VALUE'];
+            $transferSwitch = isset(Cache::getSystemConfig()['transferSwitch']) ? Cache::getSystemConfig()['transferSwitch']['VALUE'] : '';
             if($transferSwitch) return false;
         }
 
         if($menu['allow']=='pastBonusSwitch'){
-            $pastBonusSwitch = Cache::getSystemConfig()['pastBonusSwitch']['VALUE'];
+            $pastBonusSwitch = isset(Cache::getSystemConfig()['pastBonusSwitch']) 
+                ? Cache::getSystemConfig()['pastBonusSwitch']['VALUE'] 
+                : '';
             if($pastBonusSwitch) return false;
         }
 
         if($menu['allow']=='newBonusSwitch'){
-            $newBonusSwitch = Cache::getSystemConfig()['newBonusSwitch']['VALUE'];
+            // ??? 
+            $newBonusSwitch = isset(Cache::getSystemConfig()['newBonusSwitch']) 
+                ? Cache::getSystemConfig()['newBonusSwitch']['VALUE'] 
+                : '';
             if($newBonusSwitch) return false;
         }
 

+ 22 - 2
frontendApi/modules/v1/controllers/UserController.php

@@ -41,6 +41,7 @@ class UserController extends BaseController {
         $data['allNation'] = $allNation;
         $data['allOpenBank'] = $allOpenBank;
         $data['userInfo'] = User::getEnCodeInfo(\Yii::$app->user->id);
+        $data['userInfo']['NATION'] = $data['userInfo']['NATION_ID'];
         return static::notice($data);
     }
 
@@ -202,11 +203,26 @@ class UserController extends BaseController {
      * 报单管理
      */
     public function actionDec() {
+        // 生成随机码 , 初始化redis
+        $userName = Info::generateWebUserName('CQ',9);
+        $redis = \Yii::$app->redis;
+
         if (\Yii::$app->request->isPost) {
             $formModel = new DeclarationLoopForm();
             $formModel->scenario = 'userDec';
             $post = \Yii::$app->request->post();
-            $post['insertUserName'] = strtoupper($post['insertUserName']);
+
+            // 针对于会员编号的判断
+            $insertUserName = strtoupper($post['insertUserName']);
+            $getRedisUserName = $redis->get('key_'.$insertUserName);
+            if (!$getRedisUserName){
+                return static::notice('会员编号过期',400);
+            }
+            if ($insertUserName != $getRedisUserName){
+                return static::notice('会员编号不符合',400);
+            }
+
+            $post['insertUserName'] = $insertUserName;
             $post['type'] = DeclarationForm::TYPE_ZC;
             $allData['data'][] = $post;
             if ($formModel->load($allData, '') && $formModel->add()) {
@@ -215,6 +231,7 @@ class UserController extends BaseController {
                 return static::notice(Form::formatErrorsForApi($formModel->getErrors()),400);
             }
         }
+
         //所有报单套餐
         $allDecPackage = DeclarationPackage::getAllData();
         $decLevels = Cache::getDecLevelConfig();
@@ -240,9 +257,12 @@ class UserController extends BaseController {
         //$allGoods = ShopGoods::findAllAsArray('STATUS=1');
         // 所有开户行
         $allOpenBank = OpenBank::find()->where('STATUS=1')->orderBy('LIST_ORDER ASC')->asArray()->all();
-        if (!$userName = Info::generateUserName('LA',9)) {
+        if (!$userName) {
             return static::notice('会员编号生成失败', 400);
         }
+        //随机码保存在redis中方便进行比对
+        $msg = $redis->setex('key_'.$userName , 1800 , $userName);
+
         return static::notice(['allDecPackage' => $allDecPackage,'allGoods' => $allGoods,'allOpenBank' => $allOpenBank, 'userName' => $userName]);
     }
 

+ 4 - 0
frontendApi/modules/v1/models/LoginForm.php

@@ -169,6 +169,10 @@ class LoginForm extends Model
             $transaction->commit();
 
             UserLoginLogger::success($this->_userInfo);
+
+            // 把用户的登录时间存在操作时间里
+            Yii::$app->tokenRedis->hset('user:timeOut', $this->_userInfo['USER_ID'], time());
+
             return Yii::$app->user->loginWithUAndP($this->_user);
         }catch(\Exception $e){
             $transaction->rollBack();

+ 6 - 1
frontendEle/src/utils/baseInfo.js

@@ -3,7 +3,12 @@ const baseInfo = {
     localStorage.setItem('baseInfo', JSON.stringify(info))
   },
   get (...arg) {
-    let baseInfo = JSON.parse(localStorage.getItem('baseInfo'))
+    let baseInfo = null
+    try {
+      baseInfo = JSON.parse(localStorage.getItem('baseInfo'))
+    } catch(err) {
+      return null
+    }
     if (baseInfo === null) {
       return null
     }

+ 5 - 5
frontendEle/src/utils/config_development_example.js

@@ -1,16 +1,16 @@
 const APP_NAME = '奖金结算系统'
-const SERVER_API_DOMAIN = 'api.anran.leo'
+const SERVER_API_DOMAIN = '16.163.228.151:8026'
 const SERVER_API_HTTP_TYPE = 'http://'
-const SERVER_API_PORT = ''  // ':8102'
+const SERVER_API_PORT = ''  // ':8026'
 const SERVER_API_VERSION = 'v1'
 const REQUEST_URL = `${SERVER_API_HTTP_TYPE}${SERVER_API_DOMAIN}${SERVER_API_PORT}/${SERVER_API_VERSION}/`
-const WEBSOCKET_HOST = 'ws://127.0.0.1:9512'
+const WEBSOCKET_HOST = 'ws://127.0.0.1:9513'
 const DEVICE_TYPE = 'pc'
 const ACCESS_TOKEN_PREFIX = 'Bearer '
-const CDN_BASE_URL = 'http://abc.anran.io'
+const CDN_BASE_URL = 'http://16.163.228.151:8016'
 const CDN_IMG_URL = `${CDN_BASE_URL}/cdn/`
 const PRICE_IS_ROUND = true
-const REGION_URL = `${CDN_BASE_URL}/cdn/jsdata/ar_region_data.js?ver=0.1`
+const REGION_URL = 'http://16.163.228.151:8016/cdn/jsdata/ar_region_data.js?ver=0.1'
 
 export {
   APP_NAME,

+ 3 - 3
frontendEle/src/utils/config_production_example.js

@@ -1,13 +1,13 @@
 const APP_NAME = '奖金结算系统'
-const SERVER_API_DOMAIN = 'api.bonus.ar.wqcms.com'
+const SERVER_API_DOMAIN = '16.163.228.151:8026'
 const SERVER_API_HTTP_TYPE = 'http://'
 const SERVER_API_PORT = ''  // ':8102'
 const SERVER_API_VERSION = 'v1'
 const REQUEST_URL = `${SERVER_API_HTTP_TYPE}${SERVER_API_DOMAIN}${SERVER_API_PORT}/${SERVER_API_VERSION}/`
-const WEBSOCKET_HOST = 'ws://39.104.27.110:9513'
+const WEBSOCKET_HOST = 'ws://127.0.0.1:9513'
 const DEVICE_TYPE = 'pc'
 const ACCESS_TOKEN_PREFIX = 'Bearer '
-const CDN_BASE_URL = 'http://upload.ar.wqcms.com'
+const CDN_BASE_URL = 'http://16.163.228.151:8016'
 const CDN_IMG_URL = `${CDN_BASE_URL}/cdn/`
 const PRICE_IS_ROUND = true
 const REGION_URL = `${CDN_BASE_URL}/cdn/jsdata/ar_region_data.js?ver=0.1`

+ 4 - 0
frontendEle/src/utils/tool.js

@@ -81,6 +81,10 @@ let tool = {
       message = todo?'未获得授权,请重新登录':(message==='Your request was made with invalid credentials.'?'未获得授权,请重新登录':message)
       userInfo.logout()
     }
+    if (todo || status === 402) {
+      message = todo?'长时间未进行操作,请重新登录':(message==='Connection not operated for too long' ?'长时间未进行操作,请重新登录' :message)
+      userInfo.logout()
+    }
     return {message, todo, status}
   },
   /**