Procházet zdrojové kódy

调整会员最高聘级api

kevin_zhangl před 2 roky
rodič
revize
3761807bf5

+ 2 - 0
backendApi/config/menu.php

@@ -145,6 +145,8 @@ return [
 //            ['name'=>'会员历史年度最高聘级表', 'class'=>'', 'icon'=>'', 'controller'=>'user', 'action'=>'year-highest-emp-lv', 'routePath'=>'user/year-highest-emp-lv', 'show'=>1,],
 //            ['name'=>'会员历史年度最高聘级表导出', 'class'=>'', 'icon'=>'', 'controller'=>'user', 'action'=>'user/year-highest-emp-lv-export', 'routePath'=>'user/user/year-highest-emp-lv-export', 'show'=>0,],
             //['name'=>'修改会员前台显示聘级', 'class'=>'', 'icon'=>'', 'controller'=>'user', 'action'=>'change-show-emp-level', 'routePath'=>'user/change-show-emp-level', 'show'=>1,],
+            ['name'=>'会员最高聘级调整', 'class'=>'', 'icon'=>'', 'controller'=>'user', 'action'=>'change-user-dec-level', 'routePath'=>'user/change-highest-emp-level-list', 'show'=>1, 'wiki' => 'memberHighestEmpLevelAdjustment'],
+            ['name'=>'修改会员最高聘级', 'class'=>'', 'icon'=>'', 'controller'=>'user', 'action'=>'change-user-dec-level', 'routePath'=>'user/change-highest-emp-level', 'show'=>0,],
         ]
     ],
     'atlas'=>[

+ 2 - 0
backendApi/config/urlManagerRules.php

@@ -180,6 +180,8 @@ return [
             'POST ba-modify-profile' => 'ba-modify-profile',
             'POST ba-modify-status' => 'ba-modify-status',
             'POST ba-is-modify-password-status' => 'ba-is-modify-password-status',
+            'GET change-highest-emp-level-list' => 'change-highest-emp-level-list',
+            'POST change-highest-emp-level' => 'change-highest-emp-level',
         ],
     ],
     [

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

@@ -14,6 +14,7 @@ use backendApi\modules\v1\models\exportForms\BaUserExportForm;
 use backendApi\modules\v1\models\exportForms\UserExportForm;
 use backendApi\modules\v1\models\lists\shop\BaUserList;
 use backendApi\modules\v1\models\lists\user\BindList;
+use backendApi\modules\v1\models\lists\user\ChangeHighestEmpLevelList;
 use backendApi\modules\v1\models\lists\user\DecLevelList;
 use backendApi\modules\v1\models\lists\user\GroupList;
 use backendApi\modules\v1\models\lists\user\IndexList;
@@ -42,6 +43,7 @@ use common\models\forms\CloseDecForm;
 use common\models\forms\CloseLoginForm;
 use common\models\forms\DecLevelLogForm;
 use common\models\forms\DecRoleLogForm;
+use common\models\forms\HighestEmpLevelLogForm;
 use common\models\forms\NetMoveForm;
 use common\models\forms\RechargeForm;
 use common\models\forms\ReconsumeForm;
@@ -2371,4 +2373,39 @@ class UserController extends BaseController
         }
         return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
     }
+
+    /**
+     * 会员最高聘级变动记录.
+     * @return mixed
+     * @throws \yii\base\Exception
+     * @throws \yii\web\HttpException
+     */
+    public function actionChangeHighestEmpLevelList()
+    {
+        $filter = $this->filterCondition([
+            'USER_NAME' => 'CU.USER_NAME',
+            'CREATED_AT' => 'LL.CREATED_AT',
+            'ADMIN_NAME' => 'ADM.ADMIN_NAME',
+        ]);
+        $condition = $filter['condition'];
+        $params = $filter['params'];
+        $listObj = new ChangeHighestEmpLevelList();
+        $data = $listObj->getList(['condition' => $condition, 'params' => $params]);
+
+        return static::notice($data);
+    }
+    /**
+     * 调整会员最高聘级.
+     * @return mixed
+     * @throws \yii\web\HttpException
+     */
+    public function actionChangeHighestEmpLevel()
+    {
+        if (Yii::$app->request->isPost) {
+            return parent::edit(HighestEmpLevelLogForm::class, Yii::t('ctx', 'successfully'), 'adminChange', ['adminChange',], null, function ($form, $result) {
+
+            });
+        }
+        return static::notice('无效请求', 400);
+    }
 }

+ 1 - 0
backendApi/modules/v1/models/lists/log/AdminHandleList.php

@@ -156,6 +156,7 @@ class AdminHandleList extends \common\libs\dataList\DataList implements DataList
                 ['id'=>'编辑体系','name'=>\Yii::t('ctx', 'editSystem')],
                 ['id'=>'恢复体系','name'=>\Yii::t('ctx', 'recoverySystem')],
                 ['id'=>'perf adjustment','name'=>'perf adjustment'],
+                ['id'=>'调整会员最高聘级','name'=>'调整会员最高聘级'],
             ];
             $this->filterTypes = [
                 'opt_type' => ['isUserTable'=>false, 'name'=>\Yii::t('ctx', 'operatingType'), 'other'=> 'select', 'selectData'=> $selectData],

+ 102 - 0
backendApi/modules/v1/models/lists/user/ChangeHighestEmpLevelList.php

@@ -0,0 +1,102 @@
+<?php
+namespace backendApi\modules\v1\models\lists\user;
+
+use backendApi\modules\v1\models\Admin;
+use common\helpers\Cache;
+use common\libs\dataList\DataListInterface;
+use common\models\HighestEmpLevelLog;
+use common\models\User;
+use common\libs\dataList\column\DateTime;
+use Yii;
+
+class ChangeHighestEmpLevelList extends \common\libs\dataList\DataList implements DataListInterface
+{
+    /**
+     * 列表名称
+     * @return string
+     */
+    public function getListName(){
+        return '会员最高聘级调整列表';
+    }
+
+    /**
+     * 列表筛选到的数据
+     */
+    public function dataHandle()
+    {
+        $this->listData = HighestEmpLevelLog::lists($this->condition, $this->params, [
+            'select' => 'LL.*, CU.USER_NAME, ADM.ADMIN_NAME',
+            'orderBy' => 'LL.CREATED_AT DESC, LL.ID DESC',
+            'from' => HighestEmpLevelLog::tableName() . ' AS LL',
+            'join' => [
+                ['LEFT JOIN', Admin::tableName() . ' AS ADM', 'LL.ADMIN_ID=ADM.ID'],
+                ['LEFT JOIN', User::tableName() . ' AS CU', 'LL.USER_ID=CU.ID'],
+            ],
+            'page' => $this->page,
+            'pageSize' => $this->pageSize,
+        ]);
+    }
+
+    /**
+     * 要展示和导出的所有字段
+     * @return array
+     */
+    public function getColumn() {
+        $empLevelConfig = Cache::getEmpLevelConfig();
+        if (!$this->columns) {
+            $this->columns = [
+                'ID' => null,
+                'USER_ID' => null,
+                'USER_NAME' => [
+                    'header' => Yii::t('ctx', 'memberCode'),
+                ],
+                'FROM_HIGHEST_EMP_LV_NAME' => [
+                    'header' => Yii::t('ctx', 'levelBeforeModification'),
+                    'value' => function($row) use($empLevelConfig) {
+                        return $empLevelConfig[$row['FROM_ID']]['LEVEL_NAME'] ?? '';
+                    },
+                    'valueOther' => [
+                        'tag'=>['type'=>'warning', 'size' => 'small', 'class'=>'no-border']
+                    ],
+                ],
+                'TO_HIGHEST_EMP_LV_NAME' => [
+                    'header' => Yii::t('ctx', 'modifiedLevel'),
+                    'value' => function($row) use($empLevelConfig) {
+                        return $empLevelConfig[$row['TO_ID']]['LEVEL_NAME'] ?? '';
+                    },
+                    'valueOther' => [
+                        'tag'=>['type'=>'warning', 'size' => 'small', 'class'=>'no-border']
+                    ],
+                ],
+                'ADMIN_NAME' => [
+                    'header' => Yii::t('ctx', 'operationAdministrator'),
+                ],
+                'CREATED_AT' => [
+                    'header' => Yii::t('ctx', 'createAt'),
+                    'value' => function($row) {
+                        return (new DateTime([
+                            'value' => $row['CREATED_AT'],
+                        ]))->result();
+                    },
+                ],
+            ];
+        }
+        return $this->columns;
+    }
+
+    /**
+     * 前台用于筛选的类型集合
+     * @return mixed
+     */
+    public function getFilterTypes()
+    {
+        if (!$this->filterTypes) {
+            $this->filterTypes = [
+                'USER_NAME'=> ['isUserTable' => false,'name'=> Yii::t('ctx', 'memberCode')],
+                'CREATED_AT' => ['isUserTable' => false, 'name' => Yii::t('ctx', 'createAt'), 'other' => 'date'],
+                'ADMIN_NAME' => ['isUserTable' => false, 'name' => Yii::t('ctx', 'operationAdministrator')],
+            ];
+        }
+        return $this->filterTypes;
+    }
+}

+ 1 - 0
common/messages/en-US/ctx.php

@@ -578,6 +578,7 @@ return [
     'userMoveAuditStatus:1' => 'Approved',
     'userMoveAuditStatus:2' => 'Failed',
     'userMoveAuditStatus:3' => 'Audit reject',
+    'levelNoChange' => '级别没有变化无需调整',
 
     # Network
     'placementNetwork' => 'Placement Network',

+ 1 - 0
common/messages/zh-CN/ctx.php

@@ -576,6 +576,7 @@ return [
     'userMoveAuditStatus:1' => '审核通过',
     'userMoveAuditStatus:2' => '审核失败',
     'userMoveAuditStatus:3' => '拒绝',
+    'levelNoChange' => '级别没有变化无需调整',
 
     # 网络
     'placementNetwork' => '安置网络',

+ 67 - 0
common/models/HighestEmpLevelLog.php

@@ -0,0 +1,67 @@
+<?php
+
+namespace common\models;
+
+use common\helpers\Date;
+use common\helpers\Form;
+use Exception;
+use Yii;
+
+/**
+ * This is the model class for table "{{%HIGHEST_EMP_LEVEL_LOG}}".
+ *
+ * @property string $ID
+ * @property string $USER_ID 会员ID
+ * @property string $FROM_ID 变动前的级别
+ * @property string $TO_ID 变动后的级别
+ * @property string $ADMIN_ID admin id
+ * @property int $PERIOD_NUM 变动的期数
+ * @property string $CALC_MONTH 变动的结算月
+ * @property string $REMARK 备注
+ * @property int $STATUS 状态
+ * @property int $CREATED_AT 创建时间
+ * @property int $DEC_TYPE 变动类型: 1管理后台调整级别 2奖金计算调整
+ */
+class HighestEmpLevelLog extends \common\components\ActiveRecord
+{
+    /**
+     * {@inheritdoc}
+     */
+    public static function tableName()
+    {
+        return '{{%HIGHEST_EMP_LEVEL_LOG}}';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+            [['USER_ID', 'FROM_ID', 'TO_ID', 'PERIOD_NUM', 'CALC_MONTH', 'CREATED_AT'], 'required'],
+            [['PERIOD_NUM', 'CALC_MONTH', 'STATUS', 'CREATED_AT'], 'integer'],
+            [['ID', 'USER_ID', 'FROM_ID', 'TO_ID', 'ADMIN_ID'], 'string', 'max' => 32],
+            [['REMARK'], 'string', 'max' => 4000],
+            [['ID'], 'unique'],
+        ];
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function attributeLabels()
+    {
+        return [
+            'ID' => 'ID',
+            'USER_ID' => '会员ID',
+            'FROM_ID' => '变动前的级别',
+            'TO_ID' => '变动后的级别',
+            'ADMIN_ID' => '管理员id',
+            'PERIOD_NUM' => '变动的期数',
+            'CALC_MONTH' => '变动的结算月',
+            'REMARK' => '备注',
+            'STATUS' => '状态',
+            'CREATED_AT' => '创建时间',
+        ];
+    }
+}

+ 147 - 0
common/models/forms/HighestEmpLevelLogForm.php

@@ -0,0 +1,147 @@
+<?php
+namespace common\models\forms;
+
+use common\helpers\Date;
+use common\components\Model;
+use common\helpers\Form;
+use common\helpers\user\Info;
+use common\libs\logging\operate\AdminOperate;
+use common\models\EmployLevel;
+use common\models\HighestEmpLevelLog;
+use common\models\Period;
+use common\models\User;
+use Yii;
+use yii\base\Exception;
+
+/**
+ * Login form
+ */
+class HighestEmpLevelLogForm extends Model
+{
+    public $userName;
+    public $levelId;
+    public $periodNum;
+    public $remark;
+    private $_userId;
+    private $_fromId;
+
+    public function init() {
+        parent::init();
+        $this->adminOperateLogger = new AdminOperate([
+            'fetchClass' => User::class,
+        ]);
+    }
+
+    /**
+     * @inheritdoc
+     */
+    public function rules()
+    {
+        return [
+            [['userName', 'levelId', 'periodNum', 'remark'], 'trim'],
+            [['userName', 'levelId', 'periodNum'], 'required'],
+            [['userName'], 'exist', 'targetClass' => User::class, 'targetAttribute' => 'USER_NAME'],
+            [['levelId'], 'exist', 'targetClass' => EmployLevel::class, 'targetAttribute' => 'ID'],
+            [['userName'], 'isUser'],
+            [['levelId'], 'isLevel'],
+            [['periodNum'], 'integer'],
+        ];
+    }
+
+    public function attributeLabels()
+    {
+        return [
+            'userName' => '会员编号',
+            'levelId' => '级别',
+            'periodNum' => '期数',
+            'remark' => '备注',
+        ];
+    }
+
+    /**
+     * 指定校验场景
+     * @return array
+     */
+    public function scenarios()
+    {
+        $parentScenarios =  parent::scenarios();
+        $customScenarios = [
+            'adminChange' => ['userName', 'levelId', 'remark'],
+        ];
+        return array_merge($parentScenarios, $customScenarios);
+    }
+
+    /**
+     * 赋值UserId并校验会员是否存在
+     * @param $attribute
+     */
+    public function isUser($attribute){
+        $this->_userId = Info::getUserIdByUserName($this->userName);
+        if(!$this->_userId){
+            $this->addError($attribute, Yii::t('ctx', 'memberDoesNotExist'));
+        }
+    }
+
+    /**
+     * 查看级别是否有变化
+     * @param $attribute
+     * @throws \yii\db\Exception
+     */
+    public function isLevel($attribute){
+        $this->_fromId = Info::getEmpLv($this->_userId);
+        if ($this->levelId == $this->_fromId) {
+            $this->addError($attribute, Yii::t('ctx', 'levelNoChange'));
+        }
+    }
+
+    /**
+     * 更改最高聘级.
+     * @return HighestEmpLevelLog|null
+     */
+    public function adminChange()
+    {
+        if (!$this->validate()) {
+            return null;
+        }
+        $this->adminOperateLogger->beforeUpdate($this->_userId,'ID',['select'=>'ID,EMP_LV']);
+
+        $model = new HighestEmpLevelLog();
+
+        $db = \Yii::$app->db;
+        $transaction = $db->beginTransaction();
+        try {
+            $period = Period::instance();
+            // 新增数据
+            $model->USER_ID = $this->_userId;
+            $model->FROM_ID = $this->_fromId;
+            $model->TO_ID = $this->levelId;
+            $model->PERIOD_NUM = $period->getNowPeriodNum();
+            $model->CALC_MONTH = $period->getYearMonth($period->getNowPeriodNum());
+            $model->REMARK = $this->remark ?? '';
+            $model->STATUS = 1;
+            $model->ADMIN_ID = \Yii::$app->user->id;
+            $model->CREATED_AT = Date::nowTime();
+            if (!$model->save()) {
+                throw new Exception(Form::formatErrorsForApi($model->getErrors()));
+            }
+
+            // 修改最高聘级
+            User::updateAll(['EMP_LV' => $this->levelId], 'ID=:USER_ID', [':USER_ID' => $this->_userId]);
+
+            $transaction->commit();
+        } catch (Exception $e) {
+            $transaction->rollBack();
+            $this->addError('adminChange', $e->getMessage());
+            return null;
+        }
+
+        $this->adminOperateLogger->afterUpdate($this->_userId,'ID',['select'=>'ID,EMP_LV'])->clean()->save([
+            'optType' => '调整会员最高聘级',
+            'userId' => $this->_userId,
+            'userName' => Info::getUserNameByUserId($this->_userId),
+            'remark' => $this->remark
+        ]);
+
+        return $model;
+    }
+}