118 lines
3.6 KiB
PHP
118 lines
3.6 KiB
PHP
<?php
|
|
namespace app\controller\admin\user;
|
|
|
|
use app\common\repositories\user\VipExchangeCodeRepository;
|
|
use crmeb\basic\BaseController;
|
|
use think\App;
|
|
use think\exception\ValidateException;
|
|
|
|
class ExchangeCode extends BaseController{
|
|
|
|
protected $repository;
|
|
|
|
public function __construct(App $app, VipExchangeCodeRepository $repository){
|
|
parent::__construct($app);
|
|
$this->repository = $repository;
|
|
}
|
|
/**
|
|
* Common: 兑换码列表
|
|
* Author: wu-hui
|
|
* Time: 2024/03/02 14:21
|
|
* @return mixed
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function getList(){
|
|
[$page, $limit] = $this->getPage();
|
|
$params = $this->request->params(['is_export','batch_unique','status']);
|
|
$data = $this->repository->getList((array)$params,(int)$page,(int)$limit);
|
|
// 导出数据处理
|
|
if($params['is_export'] == 1){
|
|
// 处理其他导出信息
|
|
$data['title'] = [
|
|
'兑换码',
|
|
'生成时间:' . date('Y-m-d H:i:s',time())
|
|
];
|
|
// $data['header'] = ['批次名称','批次编号','兑换码', '小程序链接'];
|
|
$data['header'] = ['批次名称','批次编号','兑换码'];
|
|
$data['filename'] = '兑换码_'.time();
|
|
// 处理跳转路径
|
|
$data['list'] = array_map(function($item){
|
|
// $path = '/pages/annex/vip_center/index?ec='.$item['exchange_code'];
|
|
return [
|
|
$item['batch_title'] ?? '',
|
|
$item['batch_unique'] ?? '',
|
|
$item['exchange_code']
|
|
// $path,
|
|
];
|
|
}, $data['list']);
|
|
$data['list'] = array_reverse($data['list']);
|
|
}
|
|
|
|
return app('json')->success($data);
|
|
}
|
|
/**
|
|
* Common: 获取批次列表
|
|
* Author: wu-hui
|
|
* Time: 2024/03/02 14:45
|
|
* @return mixed
|
|
*/
|
|
public function getBatchList(){
|
|
$list = $this->repository->getSearchModel([])->column('batch_unique','batch_title');
|
|
|
|
return app('json')->success($list);
|
|
}
|
|
/**
|
|
* Common: 兑换码编辑表单
|
|
* Author: wu-hui
|
|
* Time: 2024/03/02 11:39
|
|
* @return mixed
|
|
* @throws \FormBuilder\Exception\FormBuilderException
|
|
*/
|
|
public function editForm(){
|
|
$data = $this->repository->getEditFormData();
|
|
|
|
return app('json')->success(formToData($data));
|
|
}
|
|
/**
|
|
* Common: 兑换码编辑提交信息
|
|
* Author: wu-hui
|
|
* Time: 2024/03/02 14:07
|
|
* @return mixed
|
|
*/
|
|
public function editInfo(){
|
|
$params = $this->request->params(['batch_title',['create_num', 0]]);
|
|
$this->repository->createExchangeCode($params);
|
|
|
|
return app('json')->success('添加成功');
|
|
}
|
|
/**
|
|
* Common: 激活表单
|
|
* Author: wu-hui
|
|
* Time: 2024/03/02 16:51
|
|
* @return mixed
|
|
* @throws \FormBuilder\Exception\FormBuilderException
|
|
*/
|
|
public function activateForm(){
|
|
$data = $this->repository->getActivateFormData();
|
|
|
|
return app('json')->success(formToData($data));
|
|
}
|
|
/**
|
|
* Common: 提交表单
|
|
* Author: wu-hui
|
|
* Time: 2024/03/02 16:56
|
|
* @return mixed
|
|
*/
|
|
public function activateInfo(){
|
|
$params = $this->request->params(['start_id','end_id',['mer_id', 0],['group_data_id',0]]);
|
|
$this->repository->activateExchangeCode($params);
|
|
|
|
return app('json')->success('激活成功');
|
|
}
|
|
|
|
|
|
|
|
}
|