Bläddra i källkod

Merge branch 'feature/2838-ajustHighestEmpLv' of ssh://16.162.42.175:8013/guanli/aklast into feature/3378-order-tracking

tyler 2 år sedan
förälder
incheckning
a0c1ba59cd

+ 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,],
+            ['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

@@ -170,6 +170,8 @@ return [
             'GET status-audit-export' => 'status-audit-export',
             'GET year-highest-emp-lv-export' => 'year-highest-emp-lv-export',
             'POST recharge-to-user' => 'recharge-to-user',
+            'GET change-highest-emp-level-list' => 'change-highest-emp-level-list',
+            'POST change-highest-emp-level' => 'change-highest-emp-level',
         ],
     ],
     [

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

@@ -12,6 +12,8 @@ use backendApi\modules\v1\components\UserAuth;
 use backendApi\modules\v1\models\Admin;
 use backendApi\modules\v1\models\exportForms\UserExportForm;
 use backendApi\modules\v1\models\lists\user\BindList;
+use backendApi\modules\v1\models\lists\user\ChangeEmpLevelList;
+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;
@@ -37,6 +39,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;
@@ -2229,4 +2232,39 @@ class UserController extends BaseController
         }
         return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
     }
+
+    /**
+     * 会员最高聘级变动记录.
+     * @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, '修改会员最高聘级成功', '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'=>'编辑体系'],
                 ['id'=>'恢复体系','name'=>'恢复体系'],
                 ['id'=>'调整业绩','name'=>'调整业绩'],
+                ['id'=>'调整会员最高聘级','name'=>'调整会员最高聘级'],
             ];
             $this->filterTypes = [
                 'opt_type' => ['isUserTable'=>false, 'name'=>'操作类型', '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' => '会员编号',
+                ],
+                'FROM_HIGHEST_EMP_LV_NAME' => [
+                    'header' => '调整前聘级',
+                    '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' => '调整后聘级',
+                    'value' => function($row) use($empLevelConfig) {
+                        return $empLevelConfig[$row['TO_ID']]['LEVEL_NAME'] ?? '';
+                    },
+                    'valueOther' => [
+                        'tag'=>['type'=>'warning', 'size' => 'small', 'class'=>'no-border']
+                    ],
+                ],
+                'ADMIN_NAME' => [
+                    'header' => '操作管理员',
+                ],
+                'CREATED_AT' => [
+                    'header' => '创建时间',
+                    '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'=> '会员编号'],
+                'CREATED_AT' => ['isUserTable' => false, 'name' => '创建时间', 'other' => 'date'],
+                'ADMIN_NAME' => ['isUserTable' => false, 'name' => '操作管理员'],
+            ];
+        }
+        return $this->filterTypes;
+    }
+}

+ 13 - 1
backendEle/src/router/index.js

@@ -531,7 +531,19 @@ export const constantRouterMap = [
             {title: '会员管理', path: '/user/index'}
           ]
         }
-      }
+      },
+      {
+        path: '/user/change-highest-emp-level-list',
+        component: _import('user/change-highest-emp-level-list'),
+        name: 'change-highest-emp-level-list',
+        meta: {
+          title: '会员最高聘级调整',
+          breadcrumb: [
+            {title: '首页', path: '/dashboard/index'},
+            {title: '会员管理', path: '/user/index'}
+          ]
+        }
+      },
     ]
   },
   {

+ 201 - 0
backendEle/src/views/user/change-highest-emp-level-list.vue

@@ -0,0 +1,201 @@
+<template>
+  <div v-loading="loading">
+    <div class="white-box">
+      <div class="filter-box">
+        <filter-user ref="filterUser" :filter-types="filterTypes" @select-value="handleFilterUser"></filter-user>
+      </div>
+
+      <el-table :data="tableData" stripe style="width: 100%;" :height="tool.getTableHeight(true)">
+        <el-table-column v-for="(tableHeader, key) in tableHeaders" :key="key" :label="tableHeader.header" :width="tableHeader.other.width ? tableHeader.other.width : ''">
+          <template slot-scope="{row}">
+            <template v-if="row[tableHeader.index].other.tag" >
+              <el-tag :type="row[tableHeader.index].other.tag.type ? row[tableHeader.index].other.tag.type : null" :size="row[tableHeader.index].other.tag.size ? row[tableHeader.index].other.tag.size : null" :class="row[tableHeader.index].other.tag.class ? row[tableHeader.index].other.tag.class : null" >{{ row[tableHeader.index].value }}</el-tag>
+            </template>
+            <template v-else>
+              <div v-html="row[tableHeader.index].value"></div>
+            </template>
+          </template>
+        </el-table-column>
+      </el-table>
+
+      <div class="white-box-footer">
+        <el-button type="primary" size="small" @click="dialog = true" icon="el-icon-plus" v-show="permission.hasPermission(`user/change-user-dec-level`)">调整最高聘级</el-button>
+
+        <pagination :total="totalCount" :page_size="pageSize" @size-change="handleSizeChange" @current-change="handleCurrentChange"></pagination>
+      </div>
+    </div>
+
+    <el-dialog title="调整最高聘级" :visible.sync="dialog" width="450px" :before-close="handleClose">
+      <el-form ref="form" :model="form" label-width="100px" class="form-dialog" size="mini">
+        <el-form-item label="会员编号" required>
+          <el-input placeholder="请输入会员编号" v-model.trim="form.userName" class="input-with-select">
+            <el-button slot="append" icon="el-icon-search" @click="handleQuery">查询</el-button>
+          </el-input>
+
+          <el-tag v-show="userInfo.REAL_NAME !== null" style="margin-top: 5px;">
+            会员姓名:{{ userInfo.REAL_NAME }}
+          </el-tag>
+          <el-tag v-show="userInfo.REAL_NAME !== null" v-for="(item,key) in empLevels" :label="item.LEVEL_NAME" :value="item.ID" :key="key" v-if="key === userInfo.EMP_LV" style="margin-top: 5px;">
+            最高聘级:{{item.LEVEL_NAME}}
+          </el-tag>
+        </el-form-item>
+        <el-form-item label="调整后聘级" required>
+          <el-select v-model="form.levelId" placeholder="请选择调整后聘级">
+            <el-option v-for="(item,key) in empLevels" :label="item.LEVEL_NAME" :value="item.ID" :key="key" :disabled="key === userInfo.EMP_LV"></el-option>
+          </el-select>
+        </el-form-item>
+        <el-form-item label="备注">
+          <el-input type="textarea" :rows="2" placeholder="" v-model="form.remark">
+          </el-input>
+        </el-form-item>
+        <el-form-item>
+          <el-button size="mini" type="primary" @click="onSubmit" :loading="submitButtonStat">保 存</el-button>
+        </el-form-item>
+      </el-form>
+    </el-dialog>
+  </div>
+</template>
+
+<script>
+  import network from '@/utils/network'
+  import tool from '@/utils/tool'
+  import FilterUser from '@/components/FilterUser'
+  import baseInfo from '@/utils/baseInfo'
+  import permission from '@/utils/permission'
+  import Pagination from '@/components/Pagination'
+  import filterHelper from '@/utils/filterHelper'
+
+  export default {
+    name: 'change-highest-emp-level-list',
+    components: {FilterUser,Pagination},
+    mounted() {
+      this.getData()
+    },
+    data() {
+      return {
+        tableHeaders: null,
+        tableData: null,
+        loading: true,
+        currentPage: 1,
+        totalPages: 1,
+        totalCount: 1,
+        pageSize: 20,
+        tool: tool,
+        permission: permission,
+        empLevels: baseInfo.empLevels(),
+        filterTypes: {},
+        filterModel: {},
+        filterStatus: '0',
+        dialog: false,
+        form: {
+          userName: null,
+          periodNum: null,
+          levelId: null,
+          remark: null
+        },
+        disabled: 0,
+        submitButtonStat: false,
+        userInfo: {
+          REAL_NAME: null,
+          EMP_LV: null
+        },
+      }
+    },
+    methods: {
+      handleCurrentChange(page) {
+        this.getData(page, this.pageSize)
+      },
+      handleSizeChange(pageSize) {
+        this.getData(this.currentPage, pageSize)
+      },
+      handleFilterUser(filterData) {
+        filterHelper.handleFilterUser(this, filterData)
+      },
+      getData(page, pageSize) {
+        let filterData = this.filterModel
+        let vueObj = this
+        filterData.filterStatus = this.filterStatus != -1 ? `=,${this.filterStatus}` : ''
+        network.getPageData(this, 'user/change-highest-emp-level-list', page, pageSize, filterData, function (response) {
+            vueObj.allData = response
+            vueObj.filterTypes = response.filterTypes
+        })
+      },
+      handleClose() {
+        this._clearData()
+        this.dialog = false
+      },
+      handleQuery() {
+        if (!this.form.userName.length) {
+          this.$message({
+            message: '请输入会员编号',
+            type: 'warning'
+          })
+          return false
+        }
+        network.getData('user/full-info', { userName: this.form.userName }).then(response => {
+          this.userInfo = response
+        })
+      },
+      onSubmit() {
+        if (!this.form.userName.length) {
+          this.$message({
+            message: '请输入会员编号',
+            type: 'warning'
+          })
+          return false
+        }
+        if (!this.form.levelId) {
+          this.$message({
+            message: '请选择调整后的最高聘级',
+            type: 'warning'
+          })
+          return false
+        }
+
+        let thisObj = this
+        thisObj.$confirm('是否要调整会员的最高聘级?', '提示', {
+          confirmButtonText: '确定',
+          cancelButtonText: '取消',
+          type: 'warning'
+        }).then(() => {
+          thisObj._handleSubmit()
+        }).catch(() => {
+          this._clearData()
+        })
+      },
+      _handleSubmit() {
+        this.submitButtonStat = true
+        network.postData('user/change-highest-emp-level', this.form).then(response => {
+          this.$message({
+            message: response,
+            type: 'success'
+          })
+          this.submitButtonStat = false
+          this.dialog = false
+          this._clearData()
+          this.getData()
+        }).catch(() => {
+          this.submitButtonStat = false
+        })
+      },
+      _clearData() {
+        this.form = {
+          userName: null,
+          periodNum: null,
+          levelId: null,
+          remark: null
+        }
+        this.userInfo = {
+          REAL_NAME: null,
+          EMP_LV: null
+        }
+      }
+    }
+  }
+</script>
+
+<style scoped>
+.form-dialog .el-form-item > .el-form-item__content > .el-input, .form-dialog .el-form-item > .el-form-item__content > .el-cascader, .form-dialog .el-form-item > .el-form-item__content > .el-select, .form-dialog .el-form-item > .el-form-item__content > .el-textarea, .form-dialog .el-form-item > .el-form-item__content > .el-slider {
+  width: 300px !important;
+}
+</style>

+ 62 - 0
common/models/HighestEmpLevelLog.php

@@ -0,0 +1,62 @@
+<?php
+
+namespace common\models;
+
+/**
+ * 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' => '创建时间',
+        ];
+    }
+}

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

@@ -0,0 +1,146 @@
+<?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\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, '会员不存在');
+        }
+    }
+
+    /**
+     * 查看级别是否有变化
+     * @param $attribute
+     * @throws \yii\db\Exception
+     */
+    public function isLevel($attribute){
+        $this->_fromId = Info::getEmpLv($this->_userId);
+        if ($this->levelId == $this->_fromId) {
+            $this->addError($attribute, '级别没有变化无需调整');
+        }
+    }
+
+    /**
+     * 更改最高聘级.
+     * @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;
+    }
+}