兑换码后台逻辑所在位置plugins/exchange
创建兑换码的模型在plugins/exchange/forms/common/CreateCode.php
表zjhj_bd_exchange_code
字段status 0为禁用 1为可用 2为兑换 3为结束
新增禁用以后启用
前端修改:plugins/exchange/view/library/edit.php
- <el-button @click="opend(scope.row)" v-if="scope.row.status == 0" circle size="mini" type="text">
- <el-tooltip effect="dark" content="启用" placement="top">
- <img src="statics/img/mall/order/send.png" alt="">
- el-tooltip>
- el-button>
- opend(row) {
- this.$confirm('启用该条兑换码, 是否继续?', '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- }).then(() => {
- request({
- params: {
- r: 'plugin/exchange/mall/code/opend'
- },
- data: {
- id: row.id
- },
- method: 'post'
- }).then(e => {
- if (e.data.code === 0) {
- this.$message({
- message: e.data.msg,
- type: 'success'
- });
- this.listLoading = true;
- this.getCode();
- } else {
- this.$message.error(e.data.msg);
- }
- })
- })
- },
后端修改:plugins/exchange/Controller/mall/CodeController.php
- public function actionOpend()
- {
- if (\Yii::$app->request->isPost) {
- $form = new CodeEditForm();
- $form->id = \Yii::$app->request->post('id');
- return $this->asJson($form->opend());
- }
- }
后端模型修改plugins/exchange/forms/mall/CodeEditForm.php
- public function opend()
- {
- try {
- if (empty($this->id)) {
- throw new \Exception('请求错误');
- }
- $model = ExchangeCode::findOne([
- 'mall_id' => \Yii::$app->mall->id,
- 'id' => $this->id,
- 'status' => 0,
- ]);
- if (!$model) {
- throw new \Exception('数据不存在');
- }
- $model->status = 1;
- $model->save();
- return [
- 'code' => ApiCode::CODE_SUCCESS,
- 'msg' => '启用成功',
- ];
- } catch (\Exception $e) {
- return [
- 'code' => ApiCode::CODE_ERROR,
- 'msg' => $e->getMessage(),
- ];
- }
- }