new-admin-api/app/controller/admin/user/UserInviteCode.php

142 lines
4.4 KiB
PHP

<?php
namespace app\controller\admin\user;
use app\common\repositories\store\service\StoreServiceRepository;
use app\common\repositories\system\groupData\GroupDataRepository;
use app\common\repositories\system\groupData\GroupRepository;
use app\common\repositories\system\merchant\MerchantRepository;
use app\common\repositories\user\UserInviteCodeRepository;
use crmeb\basic\BaseController;
use think\App;
class UserInviteCode extends BaseController{
protected $repository;
public function __construct(App $app, UserInviteCodeRepository $repository){
parent::__construct($app);
$this->repository = $repository;
}
/**
* Common: 列表信息
* Author: wu-hui
* Time: 2024/04/02 17:11
* @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','mer_id','staff_id','group_data_id']);
$params['mer_id'] = $this->request->merId();
$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'],
$item['qr_code_text']
// $path,
];
}, $data['list']);
$data['list'] = array_reverse($data['list']);
}
return app('json')->success($data);
}
/**
* Common: 获取批次列表
* Author: wu-hui
* Time: 2024/04/02 17:12
* @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/04/02 17:19
* @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/04/02 17:29
* @return mixed
*/
public function editInfo(){
$params = $this->request->params([
['generation_method', 0],
'prefix',
['start', 0],
['end', 0],
'batch_title',
['create_num', 0],
['group_data_id', 0]
]);
$this->repository->createExchangeCode($params);
return app('json')->success('添加成功');
}
/**
* Common: 作废表单
* Author: wu-hui
* Time: 2024/04/02 17:39
* @return mixed
* @throws \FormBuilder\Exception\FormBuilderException
*/
public function cancelForm(){
$data = $this->repository->cancelFormData();
return app('json')->success(formToData($data));
}
/**
* Common: 作废表单提交
* Author: wu-hui
* Time: 2024/04/02 17:39
* @return mixed
*/
public function cancelInfo(){
$params = $this->request->params(['start_id','end_id']);
$this->repository->cancelExchangeCode($params);
return app('json')->success('作废成功');
}
/**
* Common: 修改邀请码
* Author: wu-hui
* Time: 2024/04/02 17:45
* @return mixed
*/
public function updateCode(){
$params = $this->request->params(['id','new_exchange_code']);
$this->repository->updateExchangeCode($params);
return app('json')->success('修改成功');
}
}