Explorar el Código

Merge branch 'master' into feature/NG-15

# Conflicts:
#	backendApi/config/params.php
#	common/models/forms/ApproachDeclarationUpgradeForm.php
#	common/models/forms/ApproachOrderForm.php
#	common/models/forms/DeclarationUpgradeForm.php
#	common/models/forms/OrderForm.php
#	frontendApi/config/params.php
kevin hace 1 año
padre
commit
18335a6beb

+ 1 - 0
backendApi/config/menu.php

@@ -208,6 +208,7 @@ return [
         'child'=>[
             ['name'=>'Closure period', 'class'=>'', 'icon'=>'', 'controller'=>'bonus', 'action'=>'period', 'routePath'=>'bonus/period', 'show'=>1, 'wiki' => 'closurePeriod'],//封期管理
             ['name'=>'封期操作', 'class'=>'', 'icon'=>'', 'controller'=>'bonus', 'action'=>'close-period', 'routePath'=>'bonus/close-period', 'show'=>0,],
+            ['name'=>'自动计算', 'class'=>'', 'icon'=>'', 'controller'=>'bonus', 'action'=>'auto-calc', 'routePath'=>'bonus/auto-calc', 'show'=>0,],
             ['name'=>'生成业绩单', 'class'=>'', 'icon'=>'', 'controller'=>'bonus', 'action'=>'perf-period', 'routePath'=>'bonus/perf-period', 'show'=>0,],
             ['name'=>'结算操作', 'class'=>'', 'icon'=>'', 'controller'=>'bonus', 'action'=>'calc-period', 'routePath'=>'bonus/calc-period', 'show'=>0,],
             ['name'=>'挂网操作', 'class'=>'', 'icon'=>'', 'controller'=>'bonus', 'action'=>'send-period', 'routePath'=>'bonus/send-period', 'show'=>0,],

+ 16 - 0
backendApi/config/params.php

@@ -17,6 +17,14 @@ return [
         'v1/ad/sort',
         'v1/article/detail',
         'v1/admin/change-language',
+        'v1/bonus/auto-calc',
+        'v1/bonus/calc-period',
+        'v1/bonus/close-period',
+        'v1/bonus/period',
+        'v1/bonus/calc-period',
+        'v1/calc/record-list',
+        'v1/calc/auto-calc',
+        'v1/shop/order-detail'
     ],
     'noCheckPermissionActions' => [
         'oauth/login',
@@ -80,5 +88,13 @@ return [
         'currency/set-currencies-conversions',
         'transportation/transportation',
         'transportation/set-transportation',
+        'bonus/auto-calc',
+        'bonus/calc-period',
+        'bonus/close-period',
+        'bonus/period',
+        'bonus/calc-period',
+        'calc/record-list',
+        'calc/auto-calc',
+        'shop/order-detail'
     ],
 ];

+ 43 - 10
common/helpers/bonus/Calc/CalcConsole.php

@@ -132,7 +132,8 @@ class CalcConsole extends BaseBusiness
                 Period::updatePeriodIsProcessing($period['PERIOD_NUM'], Period::NOT_PROCESSING);
                 \Yii::$app->$db->createCommand()->update('AR_PERIOD', ['CALC_ID' => ''], 'PERIOD_NUM=:PERIOD_NUM', ['PERIOD_NUM' => $period['PERIOD_NUM']])->execute();
                 CalcOperation::closeOperation($businessPeriod['CALC_ID']);
-                CalcRecord::record($period['PERIOD_NUM'], '【奖金计算】第' . $period['PERIOD_NUM'] . '期的奖金数据获取失败,原因:' . $res['msg']);
+//                CalcRecord::record($period['PERIOD_NUM'], '【奖金计算】第' . $period['PERIOD_NUM'] . '期的奖金数据获取失败,原因:' . $res['msg']);
+                CalcRecord::record($period['PERIOD_NUM'], '【奖金计算】第' . $period['PERIOD_NUM'] . '期的奖金数据获取失败');
                 //设置计算进行中标识
                 Period::updatePeriodIsPreparing($period['PERIOD_NUM'], Period::NOT_PREPARING);
                 //设置redis开关
@@ -151,9 +152,9 @@ class CalcConsole extends BaseBusiness
         $periodNum = $currentPeriod['PERIOD_NUM'];
         $prevPeriodNum = $periodNum - 1;    // 121
         $prevPeriod = Period::find()->where('PERIOD_NUM = :PERIOD_NUM',[':PERIOD_NUM'=>$prevPeriodNum])->asArray()->one();
-        if($prevPeriod['IS_SENT']==0){
-            return;
-        }
+//        if($prevPeriod['IS_SENT']==0) {
+//            return;
+//        }
         if (
             Period::isPreparing($periodNum)
 //            || $currentPeriod['IS_MONTH'] == 0
@@ -174,17 +175,49 @@ class CalcConsole extends BaseBusiness
             return;
         }
 
-        if( 1 < $nowDate && 10 >= $nowDate ){ // 10号及以前,不是0点,则跳过
-            if( $nowHour != 0) {
+        // 如果上一期没有挂网,则1-5号以及26~月底,每小时执行一次
+        if ($prevPeriod['IS_SENT'] == 0) {
+            echo('autoPrePerf: IS_SENT=0 当前期:' . $periodNum . ', 上一期:' . $prevPeriodNum . PHP_EOL);
+            // 每小时整点执行一次
+            if ($nowMin != 0) {
+                echo('autoPrePerf: IS_SENT=0(e-1) 当前期:' . $periodNum . ', 上一期:' . $prevPeriodNum . ', 时间:' . $nowMin . PHP_EOL);
                 return;
             }
-        }
-
-        if( 15 < $nowDate && 25 >= $nowDate ){ // 下半月前10天,不是0点,则跳过
-            if( $nowHour != 0) {
+            // 10~25不执行
+            if ($nowDate >= 10 && $nowDate <= 25) {
+                echo('autoPrePerf: IS_SENT=0(e-2) 当前期:' . $periodNum . ', 上一期:' . $prevPeriodNum . ', 日期:' . $nowDate . PHP_EOL);
                 return;
             }
+        } else {
+            echo('autoPrePerf: IS_SENT=1 当前期:' . $periodNum . PHP_EOL);
+            if( 1 < $nowDate && 10 >= $nowDate ){ // 10号及以前,不是0点,则跳过
+                echo('autoPrePerf: IS_SENT=1(e-1) 当前期:' . $periodNum . ', 日期:' . $nowDate . PHP_EOL);
+                if( $nowHour != 0) {
+                    echo('autoPrePerf: IS_SENT=1(e-2) 当前期:' . $periodNum . ', 日期:' . $nowDate . ', 时间:' . $nowHour . PHP_EOL);
+                    return;
+                }
+            }
+
+            if( 15 < $nowDate && 25 >= $nowDate ){ // 下半月前10天,不是0点,则跳过
+                echo('autoPrePerf: IS_SENT=1(e-3) 当前期:' . $periodNum . ', 日期:' . $nowDate . ', 时间:' . $nowHour . PHP_EOL);
+                if( $nowHour != 0) {
+                    echo('autoPrePerf: IS_SENT=1(e-4) 当前期:' . $periodNum . ', 日期:' . $nowDate . ', 时间:' . $nowHour . PHP_EOL);
+                    return;
+                }
+            }
         }
+
+//        if( 1 < $nowDate && 10 >= $nowDate ){ // 10号及以前,不是0点,则跳过
+//            if( $nowHour != 0) {
+//                return;
+//            }
+//        }
+//
+//        if( 15 < $nowDate && 25 >= $nowDate ){ // 下半月前10天,不是0点,则跳过
+//            if( $nowHour != 0) {
+//                return;
+//            }
+//        }
 //        if($nowDate >1 && $nowDate <= 15 || (($nowMin!=0 || $nowSec >= 5 ) || Period::isPreparing($periodNum)) ){ // 当不是整点小时,当计算中,不计算
 //            return;
 //        }

+ 0 - 1
common/models/CalcRecord.php

@@ -30,7 +30,6 @@ class CalcRecord extends \common\components\ActiveRecord
         return [
             [['PERIOD_NUM', 'TEXT'], 'required'],
             [['PERIOD_NUM'], 'number'],
-            [['TEXT'], 'string', 'max' => 2000],
             [['ID'], 'unique'],
         ];
     }

+ 13 - 0
common/models/Instalment.php

@@ -44,6 +44,19 @@ class Instalment extends \common\components\ActiveRecord
         return $user['STAGE'];
     }
 
+    /**
+     * @param $userId
+     * @param $orderType
+     * @return integer
+     */
+    public static function getOneStage($userId, $orderType) {
+        $user = static::findOneAsArray("USER_ID = :USER_ID AND ORDER_TYPE=:ORDER_TYPE", [':USER_ID' => $userId, ':ORDER_TYPE' => $orderType]);
+        if(!$user){
+            return 0;
+        }
+        return $user['STAGE'];
+    }
+
     public static function getInfo($userId) {
         $userInfo = static::findOneAsArray("USER_ID = :USER_ID", [':USER_ID' => $userId]);
         if(!$userInfo){

+ 5 - 3
common/models/forms/ApproachDeclarationForm.php

@@ -86,6 +86,7 @@ class ApproachDeclarationForm extends Model
     private $_orderGoods;
     private $_standardAmount;
     private $_decAmountStandard;
+    public $period;
 
     // 批量报单时添加会员的REDIS里面缓存的添加的会员资料
     const REDIS_WAIT_ADD_USER = 'user:dec:waitAdd';
@@ -759,7 +760,8 @@ class ApproachDeclarationForm extends Model
      * @throws \yii\db\Exception
      */
     public function addUser($allData){
-        $period = Period::instance();
+        $periodObj = Period::instance();
+        $nowPeriodNum = $this->period ?: $periodObj->getNowPeriodNum();
         // 增加会员
         $user = new User();
         $user->USER_NAME = $this->insertUserName;
@@ -791,7 +793,7 @@ class ApproachDeclarationForm extends Model
         $user->IS_DEC = 0;
         $user->DEC_ID = $this->_decId ?? null;
         $user->DEC_ROLE_ID = $this->decRoleId ?? null;
-        $user->PERIOD_AT = $period->getNowPeriodNum();
+        $user->PERIOD_AT = $nowPeriodNum;
         $user->IS_DIRECT_SELLER = 0;
         $user->VERIFIED = 1;
         $user->VERIFIED_AT = Date::nowTime();
@@ -831,7 +833,7 @@ class ApproachDeclarationForm extends Model
      */
     public function addDecOrder(){
         $periodObj = Period::instance();
-        $nowPeriodNum = $periodObj->getNowPeriodNum();
+        $nowPeriodNum = $this->period ?: $periodObj->getNowPeriodNum();
         $nowCalcMonth = $periodObj->getYearMonth($nowPeriodNum);
 
         $ord = date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 10);

+ 2 - 3
common/models/forms/ApproachOrderForm.php

@@ -55,6 +55,7 @@ class ApproachOrderForm extends Model
     public $payPassword;
     public $email;
     public $exchangeRate;
+    public $period;
 
     public $userName;
     public $decUserName;
@@ -75,7 +76,6 @@ class ApproachOrderForm extends Model
     private $_orderGoods;
     private $_standardAmount;
     private $_decAmountStandard;
-    private $_userName;
 
     /**
      * @var ApproachOrder
@@ -554,7 +554,7 @@ class ApproachOrderForm extends Model
     public function addOrder()
     {
         $periodObj = Period::instance();
-        $nowPeriodNum = $periodObj->getNowPeriodNum();
+        $nowPeriodNum = $this->period ?: $periodObj->getNowPeriodNum();
         $nowCalcMonth = $periodObj->getYearMonth($nowPeriodNum);
 
         $userId = \Yii::$app->user->id;
@@ -566,7 +566,6 @@ class ApproachOrderForm extends Model
         $userEmail = Info::getUserEmailByUserId($userId);
         $country = Countries::getById($user['COUNTRY_ID']);
 
-        $exchangeRate = floatval(Cache::getSystemConfig()['exchangeRate']['VALUE'] ?? 0);
         // 加入订单信息
         if ($this->_address['PROVINCE'] != 1) {
             $warehouse = Region::getWarehouseByCode($this->_address['PROVINCE']);//仓库

+ 5 - 3
common/models/forms/DeclarationForm.php

@@ -83,6 +83,7 @@ class DeclarationForm extends Model
     private $_orderGoods;
     private $_standardAmount;
     private $_decAmountStandard;
+    public $period;
 
     // 批量报单时添加会员的REDIS里面缓存的添加的会员资料
     const REDIS_WAIT_ADD_USER = 'user:dec:waitAdd';
@@ -798,7 +799,8 @@ class DeclarationForm extends Model
      * @throws \yii\db\Exception
      */
     public function addUser($allData){
-        $period = Period::instance();
+        $periodObj = Period::instance();
+        $nowPeriodNum = $this->period ?: $periodObj->getNowPeriodNum();
         // 增加会员
         $user = new User();
         $user->USER_NAME = $this->insertUserName;
@@ -830,7 +832,7 @@ class DeclarationForm extends Model
         $user->IS_DEC = 0;
         $user->DEC_ID = $this->_decId ?? null;
         $user->DEC_ROLE_ID = $this->decRoleId ?? null;
-        $user->PERIOD_AT = $period->getNowPeriodNum();
+        $user->PERIOD_AT = $nowPeriodNum;
         $user->IS_DIRECT_SELLER = 0;
         $user->VERIFIED = 1;
         $user->VERIFIED_AT = Date::nowTime();
@@ -873,7 +875,7 @@ class DeclarationForm extends Model
      */
     public function addDecOrder(){
         $periodObj = Period::instance();
-        $nowPeriodNum = $periodObj->getNowPeriodNum();
+        $nowPeriodNum = $this->period ?: $periodObj->getNowPeriodNum();
         $nowCalcMonth = $periodObj->getYearMonth($nowPeriodNum);
 
         $ord = date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 10);

+ 3 - 3
common/models/forms/OrderForm.php

@@ -49,6 +49,7 @@ class OrderForm extends Model
     public $payPassword;
     public $email;
     public $exchangeRate;
+    public $period;
 
     public $userName;
     public $decUserName;
@@ -69,7 +70,6 @@ class OrderForm extends Model
     private $_orderGoods;
     private $_standardAmount;
     private $_decAmountStandard;
-    private $_exchangeRate;
     private $_remainPv;
     private $_realPv;
 
@@ -144,7 +144,7 @@ class OrderForm extends Model
             // 管理员修改备注
             'adminRemark' => ['sn', 'remark'],
             // 会员下单
-            'userOrder' => ['type','addressId', 'payType','goodsId','goodsNum', 'remark', 'payPassword'],
+            'userOrder' => ['type','addressId', 'payType','goodsId','goodsNum', 'remark', 'payPassword', 'period'],
             // 帮会员复消下单
             'reconsumeOrder' => ['type','userName', 'payType','goodsId','goodsNum', 'remark', 'payPassword','consignee','acceptMobile','province','cityName','lgaName','detailaddress'],
             // 管理员退款
@@ -711,7 +711,7 @@ class OrderForm extends Model
      */
     public function addOrder(){
         $periodObj = Period::instance();
-        $nowPeriodNum = $periodObj->getNowPeriodNum();
+        $nowPeriodNum = $this->period ?: $periodObj->getNowPeriodNum();
         $nowCalcMonth = $periodObj->getYearMonth($nowPeriodNum);
 
         $userId = \Yii::$app->user->id;

+ 1 - 0
frontendApi/config/params.php

@@ -21,6 +21,7 @@ return [
         'v1/site/get-instance',
         'v1/site/languages',
         'v1/site/countries',
+        'v1/bonus/period',
         ],
     'noCheckPermissionActions' => [],
 ];

+ 1 - 0
frontendApi/config/urlManagerRules.php

@@ -156,6 +156,7 @@ return [
             'GET dec-period' => 'dec-period',
             'GET fc-point' => 'fc-point',
             'GET historical-cumulative-bonus' => 'historical-cumulative-bonus',
+            'GET period' => 'period',
         ],
     ],
     [

+ 21 - 0
frontendApi/modules/v1/controllers/BonusController.php

@@ -52,6 +52,7 @@ use common\models\UserRelation;
 use common\models\Withdraw;
 use frontendApi\modules\v1\models\User;
 use Yii;
+use yii\web\HttpException;
 use yii\web\UploadedFile;
 
 class BonusController extends BaseController {
@@ -1090,4 +1091,24 @@ class BonusController extends BaseController {
         ]);
         return static::notice($data);
     }
+
+    /**
+     * 查询可用期数
+     * @return mixed
+     * @throws HttpException
+     */
+    public function actionPeriod() {
+        $nowTs = time();
+        // 当前期
+        $currentPeriod = Period::find()->where('START_TIME<:NOW_TIME', ['NOW_TIME' => $nowTs])->where('END_TIME>=:NOW_TIME', ['NOW_TIME' => $nowTs - 6])->asArray()->one();
+        $data[] = $currentPeriod['PERIOD_NUM'];
+        // 上一期是否封期
+        $prevPeriodNum = $currentPeriod['PERIOD_NUM'] - 1;
+        $prevPeriod = Period::find()->where('PERIOD_NUM=:PERIOD_NUM AND IS_SENT=0', [':PERIOD_NUM' => $prevPeriodNum])->asArray()->one();
+        if ($prevPeriod) {
+            $data[] = $prevPeriod['PERIOD_NUM'];
+        }
+
+        return static::notice(['data' => $data]);
+    }
 }

+ 18 - 0
frontendApi/modules/v1/controllers/ShopController.php

@@ -72,6 +72,24 @@ class ShopController extends BaseController {
         $condition .= ") AND S.CATEGORY_TYPE = :CATEGORY_TYPE";
         $params[':CATEGORY_TYPE'] = intval($categoryType);
 
+        $userId = \Yii::$app->user->id;
+        // 分期的总期数
+        $instalmentConfig = intval(Cache::getSystemConfig()['instalment']['VALUE'] ?? 3);
+        // 查询是否有BD的分期订单
+        $stageBD = Instalment::getOneStage($userId, 'BD');
+        if ($stageBD && $stageBD < $instalmentConfig) {
+            $condition .= " AND INSTALMENT = 0";
+        } else {
+            // 查询是否有FX的分期订单
+            $stageFX = Instalment::getOneStage($userId, 'FX');
+            if ($stageFX && $stageFX < $instalmentConfig) {
+                $condition .= " AND (INSTALMENT = 0 OR INSTALMENT=" . ($stageFX + 1) . ")";
+            } else {
+                $condition .= " AND (INSTALMENT = 0 OR INSTALMENT=1)";
+            }
+        }
+
+
         $data = ShopGoods::lists($condition, $params, [
             'select' => 'S.*,N.MARKET_PRICE,N.SELL_PRICE,N.TAX_RATE,N.LOCAL_CURRENCY_ID,N.COUNTRY_ID',
             'from' => ShopGoods::tableName() . ' AS S',

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

@@ -254,6 +254,25 @@ class UserController extends BaseController {
         if ($maxDecId == $userDecId) {
             $isMax = true;
         }
+
+        // 分期的总期数
+        $instalmentConfig = intval(Cache::getSystemConfig()['instalment']['VALUE'] ?? 3);
+        // 查询是否有FX的分期订单
+        $stageFX = Instalment::getOneStage($baseInfo['ID'], 'FX');
+        if ($stageFX && $stageFX < $instalmentConfig) {
+            $instalment = false;
+        } else {
+            // 是否有未完成的BD类型的分期订单
+            $stage = Instalment::getOneStage($userId, 'BD');
+            if ($stage && $stage < $instalmentConfig) {
+                $instalment = true;
+            } else if ($isMax && $stage == $instalmentConfig) {
+                $instalment = false;
+            } else {
+                $instalment = false;
+            }
+        }
+
         // 如果用户已经是最高级别,则只展示用户信息
         $userInfo = [
             'DEC_NAME' => $baseInfo['DEC_LV_NAME'], // 用户级别中文
@@ -263,6 +282,8 @@ class UserController extends BaseController {
             'COUNTRY_NAME' => $baseInfo['COUNTRY_NAME'], // 国家
             'IS_OBSERVE' => $isObserve, // 是否是观察期  true为是观察期
             'IS_MAX' => $isMax, // 是否已是最大级别 最大级别不需要判断报单总PV是多少 只展示基本信息
+            'INSTALMENT' => $instalment,
+            'NOW_PERF' => User::sumDevPvByUserId($userId), // 用户所有报单PV总和
         ];
 
         // 如果是最高级别了,则无需升级
@@ -311,6 +332,9 @@ class UserController extends BaseController {
 
     // 会员升级管理
     public function actionUpgrade() {
+        $isMax = \Yii::$app->request->get('isMax');
+        $userNumber = \Yii::$app->request->get('userName');
+
         $isSwitchUpgrade = Config::find()
         ->where("CONFIG_NAME='isOpenUpgrade'")
         ->asArray()
@@ -354,6 +378,36 @@ class UserController extends BaseController {
             $levelName = $decLevels[$v['LEVEL_ID']]['LEVEL_NAME'] ?? '';
             $allDecPackage[$k]['LEVEL_NAME'] = $levelName;
         }
+
+        $baseInfo = Info::baseInfoZhByUserName($userNumber);
+        // 分期的总期数
+        $instalmentConfig = intval(Cache::getSystemConfig()['instalment']['VALUE'] ?? 3);
+        // 查询是否有FX的分期订单
+        $stageFX = Instalment::getOneStage($baseInfo['ID'], 'FX');
+        if ($stageFX && $stageFX < $instalmentConfig) {
+            if ($isMax === "true") {
+                $condition = ") AND INSTALMENT = 1000";
+            } else {
+                $condition = ") AND (INSTALMENT = 0 OR INSTALMENT = 1000)";
+            }
+        } else {
+            // 是否有未完成的BD类型的分期订单
+            $stageBD = Instalment::getOneStage($baseInfo['ID'], 'BD');
+            if ($isMax === "true") {
+                if ($stageBD > 0 && $stageBD < $instalmentConfig) {
+                    $condition = ") AND (INSTALMENT = " . ($stageBD + 1) . ")";
+                } else {
+                    $condition = ") AND INSTALMENT = 0";
+                }
+            } else {
+                if ($stageBD > 0 && $stageBD < $instalmentConfig) {
+                    $condition = ") AND (INSTALMENT = 0 OR INSTALMENT = " . ($stageBD + 1) . ")";
+                } else {
+                    $condition = ") AND (INSTALMENT = 0 OR INSTALMENT = 1)";
+                }
+            }
+        }
+
         //所有自选商品
         $isDecReg = Cache::getSystemConfig()['isDecReg']['VALUE'];
         $isDec = User::getEnCodeInfo(\Yii::$app->user->id)['IS_DEC'];
@@ -366,7 +420,8 @@ class UserController extends BaseController {
         if($isStudio==1){
             $query_condition.= " OR FIND_IN_SET(3,GIFT_TYPE)>0";
         }
-        $query_condition.= ")";
+
+        $query_condition .= $condition;
 
         $allGoods = ShopGoods::find()
             ->alias('S')
@@ -508,7 +563,7 @@ class UserController extends BaseController {
         if($isStudio==1){
             $query_condition.= " OR FIND_IN_SET(3,GIFT_TYPE)>0";
         }
-        $query_condition.= ")";
+        $query_condition.= ") AND (INSTALMENT=0 OR INSTALMENT=1)";
         // 只查询普通商品
         $allGoods = ShopGoods::find()
             ->alias('S')