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['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(); } }