init commit

This commit is contained in:
2026-03-17 09:56:00 +08:00
commit e2c8ae752d
6827 changed files with 1211784 additions and 0 deletions

View File

@@ -0,0 +1,175 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh\member;
use app\common\controller\Backend;
use Exception;
use think\Db;
use think\exception\DbException;
use think\exception\PDOException;
use think\exception\ValidateException;
use think\response\Json;
/**
* 证书管理
*
* @icon fa fa-circle-o
*/
class Cert extends Backend
{
/**
* Cert模型对象
* @var \app\admin\model\wdsxh\member\Cert
*/
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\wdsxh\member\Cert;
$this->view->assign("channelList", $this->model->getChannelList());
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
/**
* 查看
*
* @return string|Json
* @throws \think\Exception
* @throws DbException
*/
public function index()
{
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
if (false === $this->request->isAjax()) {
return $this->view->fetch();
}
//如果发送的来源是 Selectpage则转发到 Selectpage
if ($this->request->request('keyField')) {
return $this->selectpage();
}
[$where, $sort, $order, $offset, $limit] = $this->buildparams();
$list = $this->model
->where($where)
// ->with(['member'])
->order($sort, $order)
->paginate($limit);
foreach ($list as $item){
$item->member_name = (new \app\admin\model\wdsxh\member\Member())->where('id',$item['member_id'])->value('name');
}
$result = ['total' => $list->total(), 'rows' => $list->items()];
return json($result);
}
/**
* 添加
*
* @return string
* @throws \think\Exception
*/
public function add()
{
if (false === $this->request->isPost()) {
return $this->view->fetch();
}
$params = $this->request->post('row/a');
if (empty($params)) {
$this->error(__('Parameter %s can not be empty', ''));
}
$params = $this->preExcludeFields($params);
if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
$params[$this->dataLimitField] = $this->auth->id;
}
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
$this->model->validateFailException()->validate($validate);
}
$params['wechat_id'] = (new \app\admin\model\wdsxh\Member())->where('id',$params['member_id'])->value('wechat_id');
$params['channel'] = 1;
$result = $this->model->allowField(true)->save($params);
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($result === false) {
$this->error(__('No rows were inserted'));
}
$this->success();
}
/**
* 编辑
*
* @param $ids
* @return string
* @throws DbException
* @throws \think\Exception
*/
public function edit($ids = null)
{
$row = $this->model->get($ids);
if (!$row) {
$this->error(__('No Results were found'));
}
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
$this->error(__('You have no permission'));
}
if (false === $this->request->isPost()) {
$this->view->assign('row', $row);
return $this->view->fetch();
}
$params = $this->request->post('row/a');
if (empty($params)) {
$this->error(__('Parameter %s can not be empty', ''));
}
$params = $this->preExcludeFields($params);
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
$row->validateFailException()->validate($validate);
}
$params['wechat_id'] = (new \app\admin\model\wdsxh\Member())->where('id',$params['member_id'])->value('wechat_id');
$params['channel'] = 1;
$result = $row->allowField(true)->save($params);
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if (false === $result) {
$this->error(__('No rows were updated'));
}
$this->success();
}
}

View File

@@ -0,0 +1,831 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh\member;
use app\admin\library\Auth;
use app\admin\model\wdsxh\member\Cert;
use app\admin\model\wdsxh\member\MemberApply;
use app\admin\model\wdsxh\user\UserWechat;
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Reader\Csv;
use PhpOffice\PhpSpreadsheet\Reader\Xls;
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use think\Db;
use think\db\exception\BindParamException;
use think\exception\DbException;
use think\exception\PDOException;
use think\exception\ValidateException;
use Exception;
/**
* 企业会员
*
* @icon fa fa-circle-o
*/
class Company extends Member
{
/**
* Company模型对象
* @var \app\admin\model\wdsxh\member\Company
*/
protected $model = null;
protected $noNeedRight = ['seluser', 'member'];
protected $industryCategoryModel = null;
protected $modelValidate = true;
protected $modelSceneValidate = true;
public function _initialize()
{
parent::_initialize();
$this->industryCategoryModel = new \app\admin\model\wdsxh\member\IndustryCategory();
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
/**
* 导入
*
* @return void
* @throws PDOException
* @throws BindParamException
*/
public function import()
{
list($person_fieldset,$company_fieldset) = \app\admin\model\wdsxh\member\JoinConfig::company_fieldset();
foreach ($person_fieldset as $k=>$v) {
if ($v['field'] == 'address') {
$person_fieldset[$k]['value'] = array(
'address'=>'',
'latitude'=>'',
'longitude'=>'',
);
} else {
$person_fieldset[$k]['value'] = '';
}
}
foreach ($company_fieldset as $k=>$v) {
$company_fieldset[$k]['value'] = '';
}
$file = $this->request->request('file');
if (!$file) {
$this->error(__('Parameter %s can not be empty', 'file'));
}
$filePath = ROOT_PATH . DS . 'public' . DS . $file;
if (!is_file($filePath)) {
$this->error(__('No results were found'));
}
//实例化reader
$ext = pathinfo($filePath, PATHINFO_EXTENSION);
if (!in_array($ext, ['csv', 'xls', 'xlsx'])) {
$this->error(__('Unknown data format'));
}
if ($ext === 'csv') {
$file = fopen($filePath, 'r');
$filePath = tempnam(sys_get_temp_dir(), 'import_csv');
$fp = fopen($filePath, 'w');
$n = 0;
while ($line = fgets($file)) {
$line = rtrim($line, "\n\r\0");
$encoding = mb_detect_encoding($line, ['utf-8', 'gbk', 'latin1', 'big5']);
if ($encoding !== 'utf-8') {
$line = mb_convert_encoding($line, 'utf-8', $encoding);
}
if ($n == 0 || preg_match('/^".*"$/', $line)) {
fwrite($fp, $line . "\n");
} else {
fwrite($fp, '"' . str_replace(['"', ','], ['""', '","'], $line) . "\"\n");
}
$n++;
}
fclose($file) || fclose($fp);
$reader = new Csv();
} elseif ($ext === 'xls') {
$reader = new Xls();
} else {
$reader = new Xlsx();
}
//导入文件首行类型,默认是注释,如果需要使用字段名称请使用name
$importHeadType = isset($this->importHeadType) ? $this->importHeadType : 'comment';
$table = $this->model->getQuery()->getTable();
$database = \think\Config::get('database.database');
$fieldArr = [];
$list = db()->query("SELECT COLUMN_NAME,COLUMN_COMMENT FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = ? AND TABLE_SCHEMA = ?", [$table, $database]);
foreach ($list as $k => $v) {
if ($importHeadType == 'comment') {
$v['COLUMN_COMMENT'] = explode(':', $v['COLUMN_COMMENT'])[0]; //字段备注有:时截取
$fieldArr[$v['COLUMN_COMMENT']] = $v['COLUMN_NAME'];
} else {
$fieldArr[$v['COLUMN_NAME']] = $v['COLUMN_NAME'];
}
}
$levelModel = new \app\admin\model\wdsxh\member\Level();
$industryModel = new \app\admin\model\wdsxh\member\IndustryCategory();
//加载文件
$insert = [];
try {
if (!$PHPExcel = $reader->load($filePath)) {
$this->error(__('Unknown data format'));
}
$currentSheet = $PHPExcel->getSheet(0); //读取文件中的第一个工作表
$allColumn = $currentSheet->getHighestDataColumn(); //取得最大的列号
$allRow = $currentSheet->getHighestRow(); //取得一共有多少行
$maxColumnNumber = Coordinate::columnIndexFromString($allColumn);
$fields = [];
for ($currentRow = 1; $currentRow <= 1; $currentRow++) {
for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) {
$val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue();
$fields[] = $val;
}
}
for ($currentRow = 2; $currentRow <= $allRow; $currentRow++) {
$mobile = 0;
$values = [];
$isEmptyRow = true; // 假设该行为空行
// 先检查整行是否为空行
for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) {
$val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue();
$val = trim($val);
// 如果某一列有值,则该行不为空
if (!empty($val)) {
$isEmptyRow = false;
}
}
// 如果该行为空行,则跳过
if ($isEmptyRow) {
continue;
}
// 如果不是空行,则处理每一列的数据
for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) {
$val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue();
$val = trim($val);
if ($currentColumn <= count($person_fieldset)) {
if ($currentColumn == 1) {//姓名
if (empty($val)) {
throw new Exception('姓名不能为空');
}
$found_key = array_search('name', array_column($person_fieldset, 'field'));
$person_fieldset[$found_key]['value'] = $val;
$mobile = $val;
} elseif ($currentColumn == 2) {//手机号
if (empty($val)) {
throw new Exception('手机号不能为空');
}
$found_key = array_search('mobile', array_column($person_fieldset, 'field'));
$person_fieldset[$found_key]['value'] = $val;
$mobile = $val;
} elseif ($currentColumn == 3) {//级别
if (empty($val)) {
throw new Exception('级别不能为空');
}
$found_key = array_search('member_level_id', array_column($person_fieldset, 'field'));
$person_fieldset[$found_key]['value'] = $levelModel->where('name',$val)->value('id');
}
} else {
$key = ($currentColumn - $maxColumnNumber) + ($maxColumnNumber - count($person_fieldset) -1);//11 person 8 company 0 1 2
$company_fieldset[$key]['value'] = is_null($val) ? '' : $val;
}
$values[] = is_null($val) ? '' : $val;
$total_values[] = array(
'field'=>$fields[$currentColumn-1],
'val'=>$val,
);
}
$row = [];
$temp = array_combine($fields, $values);
$mobileWhere['mobile'] = array('eq',$mobile);
$memberObj = $this->model->where($mobileWhere)->find();
$memberApplyModel = new MemberApply();
$memberApplyObj = $memberApplyModel->where($mobileWhere)->find();
if (empty($memberObj) && empty($memberApplyObj)) {
$userWechatModel = new UserWechat();
foreach ($temp as $k => $v) {
if (isset($fieldArr[$k]) && $k !== '') {
$row[$fieldArr[$k]] = $v;
}
}
if (isset($row['industry_category_id']) && !empty($row['industry_category_id'])) {
$row['industry_category_id'] = (new \app\admin\model\wdsxh\member\IndustryCategory())->where('name',$row['industry_category_id'])->value('id');
}
foreach ($person_fieldset as $k=>$v) {
if (isset($v['field']) && $v['field'] == 'industry_category_id' && !empty($row['industry_category_id'])) {
$person_fieldset[$k]['value'] = $row['industry_category_id'];
}
}
$person_fieldset = wdsxh_update_array_child_fieldset($person_fieldset, $total_values);
foreach ($company_fieldset as $k=>$v) {
if (!isset($v['field'])) {
unset($company_fieldset[$k]);
}
}
foreach ($person_fieldset as $k=>$v) {
if (!isset($v['field'])) {
unset($person_fieldset[$k]);
}
}
$company_fieldset = wdsxh_update_array_child_fieldset($company_fieldset, $total_values);
$custom_content = array(
'person'=>$person_fieldset,
'company'=>$company_fieldset,
);
$row['custom_content'] = json_encode($custom_content);
$row['type'] = $type = '2';
$row['join_time'] = date('Y-m-d',time());
$row['expire_time'] = \app\common\model\wdsxh\member\Member::get_expire_time($row['join_time']);
$row['status'] = 'hidden';
$userWechatObj = $userWechatModel->where($mobileWhere)->find();
if ($userWechatObj) {
$row['wechat_id'] = $userWechatObj['id'];
}
if ($row) {
$insert[] = $row;
}
}
}
} catch (Exception $exception) {
$this->error($exception->getMessage());
}
$apply_data = array();
foreach ($insert as $k=>$v) {
$level_name_id = $levelModel->where('name',$v['member_level_id'])->value('id');
if (!$level_name_id) {
$this->error('级别'.$v['member_level_id'].'不存在');
} else {
$insert[$k]['member_level_name'] = $v['member_level_id'];
$insert[$k]['member_level_id'] = $level_name_id;
}
$insert[$k]['letter'] = \app\common\model\wdsxh\member\Member::getFirstCharter($v['name']);
$apply = array(
'type'=>$type,
'name'=>$v['name'],
'mobile'=>$v['mobile'],
'member_level_id'=>$insert[$k]['member_level_id'],
'custom_content'=>$v['custom_content'],
'state'=>'2',
'channel'=>3,
'child_state'=>'6',
'pay_method'=>'1',
);
if (isset($v['wechat_id']) && !empty($v['wechat_id'])) {
$apply['wechat_id'] = $v['wechat_id'];
}
$apply_data[] = $apply;
unset($apply);
}
if (!$insert) {
$this->error(__('No rows were updated'));
}
$memberApplyModel = new MemberApply();
try {
//是否包含admin_id字段
$has_admin_id = false;
foreach ($fieldArr as $name => $key) {
if ($key == 'admin_id') {
$has_admin_id = true;
break;
}
}
if ($has_admin_id) {
$auth = Auth::instance();
foreach ($insert as &$val) {
if (!isset($val['admin_id']) || empty($val['admin_id'])) {
$val['admin_id'] = $auth->isLogin() ? $auth->id : 0;
}
}
}
$this->model->saveAll($insert);
$memberApplyModel->saveAll($apply_data);
} catch (PDOException $exception) {
$msg = $exception->getMessage();
if (preg_match("/.+Integrity constraint violation: 1062 Duplicate entry '(.+)' for key '(.+)'/is", $msg, $matches)) {
$msg = "导入失败,包含【{$matches[1]}】的记录已存在";
};
$this->error($msg);
} catch (Exception $e) {
$this->error($e->getMessage());
}
$this->success();
}
/**
* 查看
*/
public function index()
{
//当前是否为关联查询
$this->relationSearch = true;
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
if ($this->request->isAjax()) {
//如果发送的来源是Selectpage则转发到Selectpage
if ($this->request->request('keyField')) {
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$list = $this->model
->where('type','2')
->with(['level','industry'])
->where($where)
->order($sort, $order)
->paginate($limit);
foreach ($list as $row) {
if (empty($row['company_name'])) {
$row['company_name'] = '';
}
if (empty($row['company_position'])) {
$row['company_position'] = '';
}
}
$result = array("total" => $list->total(), "rows" => $list->items());
return json($result);
}
return $this->view->fetch();
}
/**
* 添加
*
* @return string
* @throws \think\Exception
*/
public function add()
{
list($person_fieldset,$company_fieldset) = \app\admin\model\wdsxh\member\JoinConfig::company_fieldset();
if (false === $this->request->isPost()) {
$this->assign('person_fieldset',$person_fieldset);
$this->assign('company_fieldset',$company_fieldset);
return $this->view->fetch();
}
$params = $this->request->post('row/a');
if (empty($params)) {
$this->error(__('Parameter %s can not be empty', ''));
}
$params = $this->preExcludeFields($params);
if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
$params[$this->dataLimitField] = $this->auth->id;
}
$params = \app\admin\model\wdsxh\member\Member::get_member_edit_params(2,json_encode($person_fieldset),$params,json_encode($company_fieldset));
$result = false;
$params['type'] = '2';
$params['expire_time'] = \app\common\model\wdsxh\member\Member::get_expire_time($params['join_time']);
$applyModel = new MemberApply();
$apply_data = $params;
$apply_data['channel'] = 3;
$apply_data['state'] = '2';//已通过
$apply_data['child_state'] = '6';//已通过
$params['channel'] = 3;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
$this->model->validateFailException()->validate($validate);
}
$applyModel->data($apply_data);
$applyModel->allowField(true)->save();
$result = $this->model->allowField(true)->save($params);
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($result === false) {
$this->error(__('No rows were inserted'));
}
$cert_data = \app\common\model\wdsxh\Cert::get_cert_data($params['type'],$applyModel,$this->model->id);
if(!empty($cert_data)) {
$certModel = new Cert();
$certModel->saveAll($cert_data);
}
$this->success();
}
/**
* 编辑
*
* @param $ids
* @return string
* @throws DbException
* @throws \think\Exception
*/
public function edit($ids = null)
{
$row = $this->model->get($ids);
$original_wechat_id = $row['wechat_id'];
$original_mobile = $row['mobile'];
if (!$row) {
$this->error(__('No Results were found'));
}
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
$this->error(__('You have no permission'));
}
if (false === $this->request->isPost()) {
$custom_content = json_decode($row['custom_content'],true);
$this->assign('person_fieldset',$custom_content['person']);
$this->assign('company_fieldset',$custom_content['company']);
$this->view->assign('row', $row);
return $this->view->fetch();
}
$params = $this->request->post('row/a');
if (empty($params)) {
$this->error(__('Parameter %s can not be empty', ''));
}
$params = $this->preExcludeFields($params);
$update_mobile = $params['person']['mobile'];
$result = false;
$tem_decode_json_custom_content = json_decode($row['custom_content'],true);
$params['custom_content'] = array_merge($params['person'],$params['company']);
$params['custom_content']['mobile'] = $update_mobile;
$params = \app\admin\model\wdsxh\member\Member::get_member_edit_params($row['type'],json_encode($tem_decode_json_custom_content['person']),$params,json_encode($tem_decode_json_custom_content['company']));
if (isset($params['join_time']) && !empty($params['join_time'])) {
$params['expire_time'] = \app\common\model\wdsxh\member\Member::get_expire_time($params['join_time']);
}
$params['id'] = $row['id'];
$queryMemberIsUserMobile = $this->model->where('mobile',$params['mobile'])
->where('id','<>',$row['id'])
->find();
if ($queryMemberIsUserMobile) {
$this->error('手机号已被其他会员使用');
}
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
$row->validateFailException()->validate($validate);
}
$result = $row->allowField(true)->save($params);
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if (false === $result) {
$this->error(__('No rows were updated'));
}
$applyModel = new MemberApply();
if(empty($original_wechat_id) && $params['wechat_id']) {//会员之前没有选中微信用户,编辑有选中微信用户
$applyObj = $applyModel->where('mobile',$original_mobile)->find();
if ($applyObj) {
$applyObj->mobile = $params['mobile'];
$applyObj->wechat_id = $params['wechat_id'];
$applyObj->save();
}
}
if(!empty($original_wechat_id) && ($original_wechat_id != $params['wechat_id'])) {//会员之前没有选中微信用户,编辑有选中微信用户
$applyObj = $applyModel->where('mobile',$original_mobile)->find();
if ($applyObj) {
$applyObj->mobile = $params['mobile'];
$applyObj->wechat_id = $params['wechat_id'];
$applyObj->save();
}
}
if ($original_mobile != $update_mobile) {
$applyObj = $applyModel->where('mobile',$original_mobile)->find();
$custom_content_array = json_decode($applyObj['custom_content'],true);
foreach ($custom_content_array['person'] as &$v) {
if (isset($v['field']) && $v['field'] == 'mobile') {
$v['value'] = $update_mobile;
}
}
$applyObj->custom_content = json_encode($custom_content_array);
$applyObj->mobile = $update_mobile;
$applyObj->save();
}
$this->success();
}
/**
* 导出
*/
public function export($ids = "")
{
if ($this->request->isPost()) {
set_time_limit(0);
ini_set('memory_limit', '2048M');
$search = $this->request->post('search');
$ids = $ids ? $ids : $this->request->post("ids");
$pk = $this->model->getPk();
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds)) {
$this->model->where($this->dataLimitField, 'in', $adminIds);
}
$op = $this->request->post('op');
$filter = $this->request->post('filter');
$columns = $this->request->post('columns');
// 兼容POST导出时筛选条件未生效的问题将筛选参数写入GET供buildparams读取
if (is_array($filter)) { $filter = json_encode($filter, JSON_UNESCAPED_UNICODE); }
if (is_array($op)) { $op = json_encode($op, JSON_UNESCAPED_UNICODE); }
$_GET['search'] = $search ?: '';
$_GET['ids'] = $ids ?: '';
$_GET['op'] = $op ?: '{}';
$_GET['filter'] = $filter ?: '{}';
$_GET['columns'] = $columns ?: '';
$this->relationSearch = true;
$this->request->get(['search' => $search, 'ids' => $ids,'op' => $op, 'filter' => $filter, 'columns' => $columns]);
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$baseWhere['type'] = array('eq','2');
if ($ids == 'all'){
$memberList = $this->model
->where($where)
->where($baseWhere)
->field('custom_content')
->select();
}else{
$memberList = $this->model
->where($pk, 'in', $ids)
->where($where)
->where($baseWhere)
->field('custom_content')
->select();
}
$memberList = collection($memberList)->toArray();
foreach ($memberList as $k=>$v){
if ($v['custom_content']){
$memberList[$k]['custom_content'] = json_decode($v['custom_content'],true);
}
}
$newExcel = new Spreadsheet(); //创建一个新的excel文档
$objSheet = $newExcel->getActiveSheet(); //获取当前操作sheet的对象
$type_name = (new \app\admin\model\wdsxh\member\JoinConfig())->where('type',2)->value('name');
if (empty($type_name)) {
$type_name = '企业会员';
}
$objSheet->setTitle($type_name); //设置当前sheet的标题
list($person_fieldset,$company_fieldset) = \app\admin\model\wdsxh\member\JoinConfig::company_fieldset();
$count_person_fieldset = count($person_fieldset);
$count_company_fieldset = count($company_fieldset);
$company_count = $count_person_fieldset + $count_company_fieldset; //16
$labels = $this->byNumReturnLabels($company_count);// 生成 A 到 Z 的数组作为列标的数组
// 设置列宽度
for ($i = 0; $i < count($labels); $i++) {
$column = $labels[$i];
$newExcel->getActiveSheet()->getColumnDimension($column)->setWidth(20);
}
list($person_fieldset,$company_fieldset) = \app\admin\model\wdsxh\member\JoinConfig::company_fieldset();
for ($i = 0; $i < count($person_fieldset); $i++) {//0-11
$label = isset($person_fieldset[$i]['label']) ? $person_fieldset[$i]['label'] : '';
$objSheet->setCellValue($labels[$i] . '1', $label);
}
$company_count = count($person_fieldset) + count($company_fieldset); //16
for ($i = count($person_fieldset); $i < $company_count; $i++) {//11 12 13 14 15 //从11开始 总共16
$key = $i - count($person_fieldset);
$label = isset($company_fieldset[$key]['label']) ? $company_fieldset[$key]['label'] : '';
$objSheet->setCellValue($labels[$i] . '1', $label);
}
$levelModel = new \app\admin\model\wdsxh\member\Level();
$industryModel = new \app\admin\model\wdsxh\member\IndustryCategory();
// 外部循环遍历会员列表
foreach ($memberList as $rowIndex => $row) {
// 将 custom_content['person'] 转换为以 field 为键的关联数组
$personByField = [];
if (!empty($row['custom_content']['person']) && is_array($row['custom_content']['person'])) {
foreach ($row['custom_content']['person'] as $item) {
if (isset($item['field'])) {
$personByField[$item['field']] = $item;
}
}
}
// 将 custom_content['company'] 转换为以 field 为键的关联数组
$companyByField = [];
if (!empty($row['custom_content']['company']) && is_array($row['custom_content']['company'])) {
foreach ($row['custom_content']['company'] as $item) {
if (isset($item['field'])) {
$companyByField[$item['field']] = $item;
}
}
}
// 内部循环遍历表头 person_fieldset确保个人数据与表头字段一致
for ($j = 0; $j < count($person_fieldset); $j++) {
$field = isset($person_fieldset[$j]['field']) ? $person_fieldset[$j]['field'] : '';
$value = '';
// 在 custom_content['person'] 中查找与表头对应的 field 数据
if ($field && isset($personByField[$field])) {
$item = $personByField[$field];
if (isset($item['type']) && $item['type'] == 'cert') {
$value = !empty($item['value']) ? wdsxh_full_url($item['value']['image']) : '';
} elseif ($field == 'address') {
$value = !empty($item['value']) ? $item['value']['address'] : '';
} else {
$value = isset($item['value']) ? $item['value'] : '';
if (isset($item['type']) && in_array($item['type'], ['image', 'video'])) {
$value = wdsxh_full_url($value);
if (is_array($value)) {
$value = implode(',', $value);
}
}
if ($field == 'member_level_id') {
$value = $levelModel->where('id', $value)->value('name');
}
if ($field == 'industry_category_id') {
$value = $industryModel->where('id', $value)->value('name');
}
}
}
if (is_array($value)) {
$value = '';
}
$objSheet->setCellValue($labels[$j] . ($rowIndex + 2), ' ' . $value);
}
// 内部循环遍历表头 company_fieldset确保企业数据与表头字段一致
for ($j = count($person_fieldset); $j < $company_count; $j++) {
$key = $j - count($person_fieldset);
$field = isset($company_fieldset[$key]['field']) ? $company_fieldset[$key]['field'] : '';
$value = '';
// 在 custom_content['company'] 中查找与表头对应的 field 数据
if ($field && isset($companyByField[$field])) {
$item = $companyByField[$field];
if (isset($item['type']) && $item['type'] == 'cert') {
$value = !empty($item['value']) ? wdsxh_full_url($item['value']['image']) : '';
} elseif ($field == 'address') {
$value = !empty($item['value']) ? $item['value']['address'] : '';
} else {
$value = isset($item['value']) ? $item['value'] : '';
if (isset($item['type']) && in_array($item['type'], ['image', 'video'])) {
$value = wdsxh_full_url($value);
if (is_array($value)) {
$value = implode(',', $value);
}
}
if ($field == 'member_level_id') {
$value = $levelModel->where('id', $value)->value('name');
}
if ($field == 'industry_category_id') {
$value = $industryModel->where('id', $value)->value('name');
}
}
}
$objSheet->setCellValue($labels[$j] . ($rowIndex + 2), ' ' . $value);
}
}
/*--------------下面是设置其他信息------------------*/
$title = date("Ymd-".$type_name);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="' . $title . '.xlsx"');
header('Cache-Control: max-age=0');
$objWriter = IOFactory::createWriter($newExcel, 'Xlsx');
$objWriter->save('php://output');
return;
}
}
/**
* 导出模板
*/
public function import_template()
{
if ($this->request->isPost()) {
set_time_limit(0);
ini_set('memory_limit', '2048M');
$newExcel = new Spreadsheet(); //创建一个新的excel文档
$objSheet = $newExcel->getActiveSheet(); //获取当前操作sheet的对象
$type_name = (new \app\admin\model\wdsxh\member\JoinConfig())->where('type',2)->value('name');
if (empty($type_name)) {
$type_name = '企业会员';
}
$objSheet->setTitle($type_name); //设置当前sheet的标题
$person_fieldset = array (
0 =>
array (
'show' => '1',
'required' => '1',
'type' => 'text',
'label' => '姓名',
'field' => 'name',
'option' => '请输入你的姓名',
),
1 =>
array (
'show' => '1',
'required' => '1',
'type' => 'number',
'label' => '手机号',
'field' => 'mobile',
'option' => '请输入你的手机号',
),
2 =>
array (
'show' => '1',
'required' => '1',
'type' => 'select',
'label' => '级别',
'field' => 'member_level_id',
'option' => '请选择会员级别',
),
);
$count_person_fieldset = count($person_fieldset);
$labels = $this->byNumReturnLabels($count_person_fieldset);// 生成 A 到 Z 的数组作为列标的数组
// 设置列宽度
for ($i = 0; $i < count($labels); $i++) {
$column = $labels[$i];
$newExcel->getActiveSheet()->getColumnDimension($column)->setWidth(20);
}
foreach ($person_fieldset as $k=>$v) {
if(in_array($v['type'],['image','video','cert']) || in_array($v['field'],['address'])) {
unset($person_fieldset[$k]);
}
}
$person_fieldset = array_values($person_fieldset);
for ($i = 0; $i < count($person_fieldset); $i++) {
$label = isset($person_fieldset[$i]['label']) ? $person_fieldset[$i]['label'] : '';
$objSheet->setCellValue($labels[$i] . '1', $label);
}
/*--------------下面是设置其他信息------------------*/
$title = date("Ymd-".$type_name."模板");
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="' . $title . '.xlsx"');
header('Cache-Control: max-age=0');
$objWriter = IOFactory::createWriter($newExcel, 'Xlsx');
$filename = $title.'.xlsx';
ob_start();
$objWriter->save('php://output');
$xlsData = ob_get_contents();
ob_end_clean();
$this->success('请求成功','',['filename' => $filename, 'file' => "data:application/vnd.ms-excel;base64," . base64_encode($xlsData)]);
}
}
public function seluser()
{
return;
}
public function member()
{
return;
}
public function activity_seluser()
{
return;
}
}

View File

@@ -0,0 +1,46 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh\member;
use app\common\controller\Backend;
/**
* 行业分类
*
* @icon fa fa-circle-o
*/
class IndustryCategory extends Backend
{
/**
* IndustryCategory模型对象
* @var \app\admin\model\wdsxh\member\IndustryCategory
*/
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\wdsxh\member\IndustryCategory;
$this->view->assign("statusList", $this->model->getStatusList());
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
}

View File

@@ -0,0 +1,414 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh\member;
use app\common\controller\Backend;
use think\Db;
use think\exception\DbException;
use think\exception\PDOException;
use think\response\Json;
use Exception;
/**
* 入会类型设置
*
* @icon fa fa-circle-o
*/
class JoinConfig extends Backend
{
/**
* JoinConfig模型对象
* @var \app\admin\model\wdsxh\member\JoinConfig
*/
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\wdsxh\member\JoinConfig;
$this->view->assign("typeList", $this->model->getTypeList());
$this->view->assign("statusList", $this->model->getStatusList());
$list = $this->model->where('weigh',0)->field('id')->select();
if(count($list) == 3) {
$data = [
['id'=>1, 'weigh'=>1],
['id'=>2, 'weigh'=>2],
['id'=>3, 'weigh'=>3]
];
$this->model->saveAll($data);
}
$list = $this->model->select();
foreach ($list as &$row) {
if (empty($row['name']) && $row['type'] == 1) {
$row['name'] = '个人入会';
$row->save();
}
if (empty($row['name']) && $row['type'] == 2) {
$row['name'] = '企业入会';
$row->save();
}
if (empty($row['name']) && $row['type'] == 3) {
$row['name'] = '团体入会';
$row->save();
}
}
}
/**
* 查看
*
* @return string|Json
* @throws \think\Exception
* @throws DbException
*/
public function index()
{
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
if (false === $this->request->isAjax()) {
return $this->view->fetch();
}
//如果发送的来源是 Selectpage则转发到 Selectpage
if ($this->request->request('keyField')) {
return $this->selectpage();
}
[$where, $sort, $order, $offset, $limit] = $this->buildparams();
$list = $this->model
->where($where)
->order($sort, $order)
->paginate($limit);
$result = ['total' => $list->total(), 'rows' => $list->items()];
return json($result);
}
/**
* 批量更新
*
* @param $ids
* @return void
*/
public function multi($ids = null)
{
if (false === $this->request->isPost()) {
$this->error(__('Invalid parameters'));
}
$ids = $ids ?: $this->request->post('ids');
if (empty($ids)) {
$this->error(__('Parameter %s can not be empty', 'ids'));
}
if (false === $this->request->has('params')) {
$this->error(__('No rows were updated'));
}
parse_str($this->request->post('params'), $values);
$values = $this->auth->isSuperAdmin() ? $values : array_intersect_key($values, array_flip(is_array($this->multiFields) ? $this->multiFields : explode(',', $this->multiFields)));
if (empty($values)) {
$this->error(__('You have no permission'));
}
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds)) {
$this->model->where($this->dataLimitField, 'in', $adminIds);
}
$selectCount = count(explode(',',$ids));
if($values['status'] == 'hidden' && $selectCount == 3) {
$this->error('入会类型至少有一个需要展示,否则无法入会');
}
$count = 0;
Db::startTrans();
try {
$list = $this->model->where($this->model->getPk(), 'in', $ids)->select();
foreach ($list as $item) {
$count += $item->allowField(true)->isUpdate(true)->save($values);
}
Db::commit();
} catch (PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($count) {
$this->success();
}
$this->error(__('No rows were updated'));
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
public function fieldset($ids = null)
{
switch ($ids) {
case 1:
return $this->person_handle($ids);
break;
case 2:
return $this->company_handle($ids);
break;
case 3:
return $this->organize_handle($ids);
break;
}
}
private function person_handle($ids)
{
$row = $this->model->get($ids);
$person_fieldset = \app\admin\model\wdsxh\member\JoinConfig::person_fieldset();
if ($this->request->isPost()) {
$params = $this->request->param('row/a');
$status = $params['status'];
if ($status == 'hidden') {
$hiddenCount = $this->model->where('id','<>',$ids)->where('status','hidden')->count();
if ($hiddenCount && $hiddenCount == 2) {
$this->error('入会类型至少有一个需要展示,否则无法入会');
}
}
$row->status = $status;
$row->save();
if (empty($params['field']) || !is_array($params['field'])) {
$this->error('字段信息不能为空');
}
foreach ($params['field'] as &$v) {
$v['field'] = strtolower($v['field']);
if (strpos($v['field'], ' ') !== false) {
$this->error('字段信息'.$v['field'].',不能包含空格');
}
if (!preg_match('/^[a-z_]*$/', $v['field'])) {
$this->error('字段信息'.$v['field'].',规则必须是小写英文字母特殊字符可以用下划线_代替');
}
}
$temp = array();
foreach ($params['field'] as $row) {
if ($row['type'] == 'file' && $row['show'] == 1) {
$this->error('文件上传是否展示必须选择否');
}
$temp[] = $row;
}
$field_array = array_column($temp, 'field');
if (count($field_array) != count(array_unique($field_array))) {
$this->error('字段名不能重复');
}
file_put_contents(
ADDON_PATH . "wdsxh" . DS . 'config' . DS . "person.php",
'<?php' . "\n\nreturn " . var_export_short($temp) . ";\n"
);
$this->success('操作成功!');
}
$this->assign('person_fieldset', json_encode($person_fieldset));
$this->view->assign('row', $row);
return $this->view->fetch('person');
}
private function company_handle($ids)
{
$row = $this->model->get($ids);
list($person_fieldset,$company_fieldset) = \app\admin\model\wdsxh\member\JoinConfig::company_fieldset();
if ($this->request->isPost()) {
$params = $this->request->param('row/a');
$status = $params['status'];
if ($status == 'hidden') {
$hiddenCount = $this->model->where('id','<>',$ids)->where('status','hidden')->count();
if ($hiddenCount && $hiddenCount == 2) {
$this->error('入会类型至少有一个需要展示,否则无法入会');
}
}
$row->status = $status;
$row->save();
if (empty($params['person']) || !is_array($params['person'])) {
$this->error('个人信息字段信息不能为空');
}
if (empty($params['company']) || !is_array($params['company'])) {
$this->error('企业信息字段信息不能为空');
}
foreach ($params['person'] as &$v) {
$v['field'] = strtolower($v['field']);
if (strpos($v['field'], ' ') !== false) {
$this->error('字段信息'.$v['field'].',不能包含空格');
}
if (!preg_match('/^[a-z_]*$/', $v['field'])) {
$this->error('字段信息'.$v['field'].',规则必须是小写英文字母特殊字符可以用下划线_代替');
}
}
foreach ($params['company'] as &$v) {
$v['field'] = strtolower($v['field']);
if (strpos($v['field'], ' ') !== false) {
$this->error('字段信息'.$v['field'].',不能包含空格');
}
if (!preg_match('/^[a-z_]*$/', $v['field'])) {
$this->error('字段信息'.$v['field'].',规则必须是小写英文字母特殊字符可以用下划线_代替');
}
}
//个人信息
$temp = array();
foreach ($params['person'] as $row) {
if ($row['type'] == 'file' && $row['show'] == 1) {
$this->error('文件上传是否展示必须选择否');
}
$temp[] = $row;
}
$field_array = array_column($temp, 'field');
if (count($field_array) != count(array_unique($field_array))) {
$this->error('个人字段名不能重复');
}
//个人信息
//企业信息
$temp_company = array();
foreach ($params['company'] as $row) {
if ($row['type'] == 'file' && $row['show'] == 1) {
$this->error('文件上传是否展示必须选择否');
}
$temp_company[] = $row;
}
$company_field_array = array_column($temp_company, 'field');
if (count($company_field_array) != count(array_unique($company_field_array))) {
$this->error('企业字段名不能重复');
}
config('company', $temp_company);
$intersect_array = array_intersect($field_array,$company_field_array);
if (!empty($intersect_array)) {
$this->error('个人字段名和企业字段名不能重复');
}
//企业信息
$company_array = array(
'person'=>$temp,
'company'=> $temp_company,
);
file_put_contents(
ADDON_PATH . "wdsxh" . DS . 'config' . DS . "company.php",
'<?php' . "\n\nreturn " . var_export_short($company_array) . ";\n"
);
$this->success('操作成功!');
}
$this->assign('person_fieldset', json_encode($person_fieldset));
$this->assign('company_fieldset', json_encode($company_fieldset));
$this->view->assign('row', $row);
return $this->view->fetch('company');
}
private function organize_handle($ids)
{
$row = $this->model->get($ids);
list($person_fieldset,$organize_fieldset) = \app\admin\model\wdsxh\member\JoinConfig::organize_fieldset();
if ($this->request->isPost()) {
$params = $this->request->param('row/a');
$status = $params['status'];
if ($status == 'hidden') {
$hiddenCount = $this->model->where('id','<>',$ids)->where('status','hidden')->count();
if ($hiddenCount && $hiddenCount == 2) {
$this->error('入会类型至少有一个需要展示,否则无法入会');
}
}
$row->status = $status;
$row->save();
if (empty($params['person']) || !is_array($params['person'])) {
$this->error('个人信息字段信息不能为空');
}
if (empty($params['organize']) || !is_array($params['organize'])) {
$this->error('团体信息字段信息不能为空');
}
foreach ($params['person'] as &$v) {
$v['field'] = strtolower($v['field']);
if (strpos($v['field'], ' ') !== false) {
$this->error('字段信息'.$v['field'].',不能包含空格');
}
if (!preg_match('/^[a-z_]*$/', $v['field'])) {
$this->error('字段信息'.$v['field'].',规则必须是小写英文字母特殊字符可以用下划线_代替');
}
}
foreach ($params['organize'] as &$v) {
$v['field'] = strtolower($v['field']);
if (strpos($v['field'], ' ') !== false) {
$this->error('字段信息'.$v['field'].',不能包含空格');
}
if (!preg_match('/^[a-z_]*$/', $v['field'])) {
$this->error('字段信息'.$v['field'].',规则必须是小写英文字母特殊字符可以用下划线_代替');
}
}
//个人信息
$temp = array();
foreach ($params['person'] as $row) {
if ($row['type'] == 'file' && $row['show'] == 1) {
$this->error('文件上传是否展示必须选择否');
}
$temp[] = $row;
}
$field_array = array_column($temp, 'field');
if (count($field_array) != count(array_unique($field_array))) {
$this->error('个人字段名不能重复');
}
//个人信息
//团体信息
$temp_organize = array();
foreach ($params['organize'] as $row) {
if ($row['type'] == 'file' && $row['show'] == 1) {
$this->error('文件上传是否展示必须选择否');
}
$temp_organize[] = $row;
}
$organize_field_array = array_column($temp_organize, 'field');
if (count($organize_field_array) != count(array_unique($organize_field_array))) {
$this->error('团体字段名不能重复');
}
config('organize', $temp_organize);
$intersect_array = array_intersect($field_array,$organize_field_array);
if (!empty($intersect_array)) {
$this->error('个人字段名和团体字段名不能重复');
}
//团体信息
$organize_array = array(
'person'=>$temp,
'organize'=> $temp_organize,
);
file_put_contents(
ADDON_PATH . "wdsxh" . DS . 'config' . DS . "organize.php",
'<?php' . "\n\nreturn " . var_export_short($organize_array) . ";\n"
);
$this->success('操作成功!');
}
$this->assign('person_fieldset', json_encode($person_fieldset));
$this->assign('organize_fieldset', json_encode($organize_fieldset));
$this->view->assign('row', $row);
return $this->view->fetch('organize');
}
public function del($ids = null)
{
return;
}
public function add()
{
return;
}
}

View File

@@ -0,0 +1,202 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh\member;
use app\admin\model\wdsxh\member\FeesConfig;
use app\common\controller\Backend;
use think\Db;
use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException;
use think\exception\DbException;
use think\exception\PDOException;
use think\exception\ValidateException;
/**
* 会员级别
*
* @icon fa fa-circle-o
*/
class Level extends Backend
{
/**
* Level模型对象
* @var \app\admin\model\wdsxh\member\Level
*/
protected $model = null;
protected $modelValidate = true;
protected $pay_method = null;
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\wdsxh\member\Level;
$this->view->assign("statusList", $this->model->getStatusList());
$pay_method = (new FeesConfig())->where('id',1)->value('pay_method');
$this->pay_method = $pay_method;
$this->assign('pay_method',$pay_method);
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
/**
* 删除
*
* @param $ids
* @return void
* @throws DbException
* @throws DataNotFoundException
* @throws ModelNotFoundException
*/
public function del($ids = null)
{
if (false === $this->request->isPost()) {
$this->error(__("Invalid parameters"));
}
$ids = $ids ?: $this->request->post("ids");
if (empty($ids)) {
$this->error(__('Parameter %s can not be empty', 'ids'));
}
$pk = $this->model->getPk();
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds)) {
$this->model->where($this->dataLimitField, 'in', $adminIds);
}
$list = $this->model->where($pk, 'in', $ids)->select();
$memberModel = new \app\admin\model\wdsxh\member\Member();
foreach ($list as $item) {
if ($memberModel->where('member_level_id',$item['id'])->count()) {
$this->error('级别:'.$item['name'].',有会员无法删除');
}
}
$count = 0;
Db::startTrans();
try {
foreach ($list as $item) {
$count += $item->delete();
}
Db::commit();
} catch (PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($count) {
$this->success();
}
$this->error(__('No rows were deleted'));
}
/**
* 添加
*
* @return string
* @throws \think\Exception
*/
public function add()
{
if (false === $this->request->isPost()) {
return $this->view->fetch();
}
$params = $this->request->post('row/a');
if (empty($params)) {
$this->error(__('Parameter %s can not be empty', ''));
}
$params = $this->preExcludeFields($params);
if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
$params[$this->dataLimitField] = $this->auth->id;
}
if (isset($params['fees']) && ($params['fees'] != 0.00) && $params['fees'] < 0.01) {
$this->error('会费不能小于0.01元');
}
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
$this->model->validateFailException()->validate($validate);
}
$result = $this->model->allowField(true)->save($params);
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($result === false) {
$this->error(__('No rows were inserted'));
}
$this->success();
}
/**
* 编辑
*
* @param $ids
* @return string
* @throws DbException
* @throws \think\Exception
*/
public function edit($ids = null)
{
$row = $this->model->get($ids);
if (!$row) {
$this->error(__('No Results were found'));
}
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
$this->error(__('You have no permission'));
}
if (false === $this->request->isPost()) {
$this->view->assign('row', $row);
return $this->view->fetch();
}
$params = $this->request->post('row/a');
if (empty($params)) {
$this->error(__('Parameter %s can not be empty', ''));
}
$params = $this->preExcludeFields($params);
if (isset($params['fees']) && $params['fees'] < 0.01) {
$this->error('会费不能小于0.01元');
}
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
$row->validateFailException()->validate($validate);
}
$result = $row->allowField(true)->save($params);
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if (false === $result) {
$this->error(__('No rows were updated'));
}
$this->success();
}
}

View File

@@ -0,0 +1,395 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh\member;
use app\admin\model\wdsxh\activity\ActivityApply;
use app\admin\model\wdsxh\activity\Order;
use app\admin\model\wdsxh\activity\Refund;
use app\admin\model\wdsxh\business\Business;
use app\admin\model\wdsxh\member\MemberApply;
use app\admin\model\wdsxh\member\Cert;
use app\admin\model\wdsxh\message\MessageNotificationMemberId;
use app\api\model\wdsxh\activity\ActivityApplyRecord;
use app\api\model\wdsxh\member\Visitor;
use app\api\model\wdsxh\UserWechat;
use app\common\controller\Backend;
use think\Db;
use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException;
use think\exception\DbException;
use think\exception\PDOException;
use Exception;
/**
* 会员列表
*
* @icon fa fa-circle-o
*/
class Member extends Backend
{
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\wdsxh\member\Member();
$this->view->assign("statusList", $this->model->getStatusList());
$expire_time_type = (new \app\admin\model\wdsxh\member\FeesConfig())->where('id',1)->value('expire_time_type');
$this->assign('expire_time_type',$expire_time_type);
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
public function index()
{
$current_date = date('Y-m-d',time());
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
if (false === $this->request->isAjax()) {
return $this->view->fetch();
}
//如果发送的来源是 Selectpage则转发到 Selectpage
if ($this->request->request('keyField')) {
return $this->selectpage();
}
[$where, $sort, $order, $offset, $limit] = $this->buildparams();
$list = $this->model
->where('expire_time','>=',$current_date)
->where($where)
->order($sort, $order)
->paginate($limit);
$result = ['total' => $list->total(), 'rows' => $list->items()];
return json($result);
}
public function member()
{
//当前是否为关联查询
$this->relationSearch = true;
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
if ($this->request->isAjax()) {
//如果发送的来源是Selectpage则转发到Selectpage
if ($this->request->request('keyField')) {
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$parent_wechat_id = $this->request->get('wechat_id');
// 添加空值检查
if (empty($parent_wechat_id)) {
$list = [];
} else {
// 优化为单次联表查询
$list = $this->model
->where($where)
->alias('member')
->join('wdsxh_member_level level','level.id = member.member_level_id')
->join('wdsxh_user_wechat wechat','wechat.id = member.wechat_id')
->join('wdsxh_user_wechat parent_wechat','parent_wechat.id = wechat.parent_wechat_id')
->where('parent_wechat.id', $parent_wechat_id)
->field("member.id,member.name,member.avatar,level.name level_name,member.join_time,FROM_UNIXTIME(wechat.createtime, '%Y-%m-%d') as createtime")
->order('member.id desc')
->paginate($limit);
}
// 保持原有的循环处理虽然已优化到SQL中但保留以确保兼容性
foreach ($list as &$v) {
if (!isset($v->createtime) || !$v->createtime) {
$v->createtime = date('Y-m-d', $v->createtime);
}
}
$result = array("total" => $list->total(), "rows" => $list->items());
return json($result);
}
return $this->view->fetch();
}
/**
* 普通用户列表
*/
public function seluser(){
$this->request->filter(['strip_tags', 'trim']);
if ($this->request->isAjax()) {
//如果发送的来源是Selectpage则转发到Selectpage
if ($this->request->request('keyField')) {
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$wechat_id_array = (new MemberApply())->where('wechat_id','<>',0)->column('wechat_id');
$userWechatModel = new UserWechat();
$list = $userWechatModel
->where($where)
->where('id','not in',$wechat_id_array)
->where( 'user_id','in' ,function($query) {
$query->name('user')->field('id');
})
->order($sort, $order)
->paginate($limit);
$result = array("total" => $list->total(), "rows" => $list->items());
return json($result);
}
return $this->view->fetch();
}
public function activity_seluser(){
$this->request->filter(['strip_tags', 'trim']);
if ($this->request->isAjax()) {
//如果发送的来源是Selectpage则转发到Selectpage
if ($this->request->request('keyField')) {
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$param = $this->request->get();
$wechat_id_array = (new ActivityApply())->where('activity_id',$param['activity_id'])->column('wechat_id');
$userWechatModel = new UserWechat();
$list = $userWechatModel
->where($where)
->where('id','not in',$wechat_id_array)
->where( 'user_id','in' ,function($query) {
$query->name('user')->field('id');
})
->order($sort, $order)
->paginate($limit);
$result = array("total" => $list->total(), "rows" => $list->items());
return json($result);
}
return $this->view->fetch();
}
/**
* 删除
*
* @param $ids
* @return void
* @throws DbException
* @throws DataNotFoundException
* @throws ModelNotFoundException
*/
public function del($ids = null)
{
if (false === $this->request->isPost()) {
$this->error(__("Invalid parameters"));
}
$ids = $ids ?: $this->request->post("ids");
if (empty($ids)) {
$this->error(__('Parameter %s can not be empty', 'ids'));
}
$pk = $this->model->getPk();
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds)) {
$this->model->where($this->dataLimitField, 'in', $adminIds);
}
$list = $this->model->where($pk, 'in', $ids)->select();
$count = 0;
Db::startTrans();
try {
foreach ($list as $item) {
\app\admin\model\wdsxh\member\Pay::where('member_id',$item->id)->delete();
MemberApply::where('mobile',$item->mobile)->delete();
Business::where('wechat_id',$item->wechat_id)->delete();
Visitor::where('wechat_id',$item->wechat_id)->delete();
ActivityApply::where('wechat_id',$item->wechat_id)->delete();//活动报名
ActivityApplyRecord::where('wechat_id',$item->wechat_id)->delete();//活动报名记录
Order::where('wechat_id',$item->wechat_id)->delete();//活动订单
Refund::where('wechat_id',$item->wechat_id)->delete();//活动退款
Cert::where('wechat_id',$item->wechat_id)->delete();//证书管理
\app\admin\model\wdsxh\institution\Member::where('wechat_id',$item->wechat_id)->delete();
\app\admin\model\wdsxh\institution\InstitutionMemberApply::where('wechat_id',$item->wechat_id)->delete();
$count += $item->delete();
}
Db::commit();
} catch (PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($count) {
$this->success();
}
$this->error(__('No rows were deleted'));
}
/**
* Desc 获取列字母
* Create on 2024/4/9 16:05
* Create by wangyafang
*/
protected function getColumnZimu($num)
{
if ($num>= 0 && $num< 26) {
// 如果是 A 到 Z 之间的列,直接返回对应的字母
return chr(65 + $num);
} else {
// 针对 AA、AB、AC ... ZZ 这样的列,使用类似递归的方式计算出对应的字母组合
$result = '';
while ($num>= 26) {
$result .= chr(65 + ($num% 26));
$num= intval($num/ 26) - 1;
}
$result .= chr(65 + $num);
return strrev($result); // 需要反转列名字母组合
}
}
/**
* Desc 获取excel所有列
* Create on 2024/4/9 16:05
* Create by wangyafang
*/
protected function byNumReturnLabels($num)
{
$labels = range('A', 'Z');
if ($num <= 26) {
return $labels;
} else {
$for_count = $num - 26;
for ($i = 0; $i < $for_count; $i++) {
$labels[] = $this->getColumnZimu(26 + $i);
}
return $labels;
}
}
public function edit($ids = null)
{
return;
}
public function add()
{
return;
}
public function send_notification()
{
$ids = $this->request->param('ids');
if ($this->request->isPost()) {
// 获取 ids可能是数组或字符串
$ids = $this->request->post('ids');
// 如果是字符串,转换为数组
if (is_string($ids)) {
$ids = array_filter(explode(',', $ids));
}
$title = $this->request->post('title');
$content = $this->request->post('content');
if (empty($ids)) {
$this->error('请选择要通知的会员');
}
if (empty($title)) {
$this->error('请输入通知标题');
}
if (empty($content)) {
$this->error('请输入通知内容');
}
Db::startTrans();
try {
// 检查队列配置
$queueConfig = \think\Config::get('queue');
if (empty($queueConfig)) {
throw new Exception('队列配置未找到,请检查 application/extra/queue.php 文件');
}
// 获取会员列表
$current_date = date('Y-m-d');
$memberList = $this->model
->where('id', 'in', $ids)
->where('expire_time', '>', $current_date)
->select();
if (empty($memberList) || count($memberList) == 0) {
throw new Exception('未找到要通知的会员');
}
// 创建通知内容记录
$messageNotificationModel = new \app\admin\model\wdsxh\message\MessageNotification();
$messageNotificationModel->title = $title;
$messageNotificationModel->content = $content;
$messageNotificationModel->admin_id = $this->auth->id;
$messageNotificationModel->type = (new \app\admin\model\wdsxh\Member())->where('id', $ids[0])->value('type'); // 假设所有会员类型相同,取第一个会员的类型
$messageNotificationModel->save();
$notificationId = $messageNotificationModel->id;
$messageNotificationMemberIdData = array();
foreach ($ids as $v) {
$messageNotificationMemberIdData[] = [
'notification_id' => $notificationId,
'member_id' => $v,
];
}
(new MessageNotificationMemberId())->saveAll($messageNotificationMemberIdData);
// 将每个会员的通知任务加入队列
$successCount = 0;
foreach ($memberList as $member) {
$jobData = [
'notification_id' => $notificationId,
'member_id' => $member->id,
'title' => $title,
'content' => $content,
];
// 将任务推送到队列
$result = \think\Queue::push('app\\admin\\job\\SendMemberNotification@fire', $jobData, 'MemberNotification');
if ($result !== false) {
$successCount++;
}
}
Db::commit();
} catch (Exception $e) {
Db::rollback();
$this->error('发送失败:' . $e->getMessage());
}
$this->success('通知已加入队列,正在发送中...(共' . count($memberList) . '个会员)');
}
$this->view->assign('ids', $ids);
return $this->view->fetch();
}
}

View File

@@ -0,0 +1,824 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh\member;
use app\admin\model\wdsxh\member\Cert;
use app\admin\model\wdsxh\member\MemberApply;
use app\admin\model\wdsxh\user\UserWechat;
use think\Db;
use think\exception\DbException;
use think\exception\PDOException;
use think\exception\ValidateException;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Reader\Csv;
use PhpOffice\PhpSpreadsheet\Reader\Xls;
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use Exception;
use app\common\library\Auth;
/**
* 团体会员
*
* @icon fa fa-circle-o
*/
class Organize extends Member
{
/**
* Organize模型对象
* @var \app\admin\model\wdsxh\member\Organize
*/
protected $model = null;
protected $noNeedRight = ['seluser', 'member'];
protected $industryCategoryModel = null;
protected $modelValidate = true;
protected $modelSceneValidate = true;
public function _initialize()
{
parent::_initialize();
$this->industryCategoryModel = new \app\admin\model\wdsxh\member\IndustryCategory();
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
/**
* 导入
*
* @return void
* @throws PDOException
*/
public function import()
{
list($person_fieldset,$organize_fieldset) = \app\admin\model\wdsxh\member\JoinConfig::organize_fieldset();
foreach ($person_fieldset as $k=>$v) {
if ($v['field'] == 'address') {
$person_fieldset[$k]['value'] = array(
'address'=>'',
'latitude'=>'',
'longitude'=>'',
);
} else {
$person_fieldset[$k]['value'] = '';
}
}
foreach ($organize_fieldset as $k=>$v) {
$organize_fieldset[$k]['value'] = '';
}
$file = $this->request->request('file');
if (!$file) {
$this->error(__('Parameter %s can not be empty', 'file'));
}
$filePath = ROOT_PATH . DS . 'public' . DS . $file;
if (!is_file($filePath)) {
$this->error(__('No results were found'));
}
//实例化reader
$ext = pathinfo($filePath, PATHINFO_EXTENSION);
if (!in_array($ext, ['csv', 'xls', 'xlsx'])) {
$this->error(__('Unknown data format'));
}
if ($ext === 'csv') {
$file = fopen($filePath, 'r');
$filePath = tempnam(sys_get_temp_dir(), 'import_csv');
$fp = fopen($filePath, 'w');
$n = 0;
while ($line = fgets($file)) {
$line = rtrim($line, "\n\r\0");
$encoding = mb_detect_encoding($line, ['utf-8', 'gbk', 'latin1', 'big5']);
if ($encoding !== 'utf-8') {
$line = mb_convert_encoding($line, 'utf-8', $encoding);
}
if ($n == 0 || preg_match('/^".*"$/', $line)) {
fwrite($fp, $line . "\n");
} else {
fwrite($fp, '"' . str_replace(['"', ','], ['""', '","'], $line) . "\"\n");
}
$n++;
}
fclose($file) || fclose($fp);
$reader = new Csv();
} elseif ($ext === 'xls') {
$reader = new Xls();
} else {
$reader = new Xlsx();
}
//导入文件首行类型,默认是注释,如果需要使用字段名称请使用name
$importHeadType = isset($this->importHeadType) ? $this->importHeadType : 'comment';
$table = $this->model->getQuery()->getTable();
$database = \think\Config::get('database.database');
$fieldArr = [];
$list = db()->query("SELECT COLUMN_NAME,COLUMN_COMMENT FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = ? AND TABLE_SCHEMA = ?", [$table, $database]);
foreach ($list as $k => $v) {
if ($importHeadType == 'comment') {
$v['COLUMN_COMMENT'] = explode(':', $v['COLUMN_COMMENT'])[0]; //字段备注有:时截取
$fieldArr[$v['COLUMN_COMMENT']] = $v['COLUMN_NAME'];
} else {
$fieldArr[$v['COLUMN_NAME']] = $v['COLUMN_NAME'];
}
}
$levelModel = new \app\admin\model\wdsxh\member\Level();
//加载文件
$insert = [];
try {
if (!$PHPExcel = $reader->load($filePath)) {
$this->error(__('Unknown data format'));
}
$currentSheet = $PHPExcel->getSheet(0); //读取文件中的第一个工作表
$allColumn = $currentSheet->getHighestDataColumn(); //取得最大的列号
$allRow = $currentSheet->getHighestRow(); //取得一共有多少行
$maxColumnNumber = Coordinate::columnIndexFromString($allColumn);
$fields = [];
for ($currentRow = 1; $currentRow <= 1; $currentRow++) {
for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) {
$val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue();
$fields[] = $val;
}
}
for ($currentRow = 2; $currentRow <= $allRow; $currentRow++) {
$mobile = 0;
$values = [];
$isEmptyRow = true; // 假设该行为空行
// 先检查整行是否为空行
for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) {
$val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue();
$val = trim($val);
// 如果某一列有值,则该行不为空
if (!empty($val)) {
$isEmptyRow = false;
}
}
// 如果该行为空行,则跳过
if ($isEmptyRow) {
continue;
}
// 如果不是空行,则处理每一列的数据
for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) {
$val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue();
$val = trim($val);
if ($currentColumn <= count($person_fieldset)) {
if ($currentColumn == 1) {//姓名
if (empty($val)) {
throw new Exception('姓名不能为空');
}
$found_key = array_search('name', array_column($person_fieldset, 'field'));
$person_fieldset[$found_key]['value'] = $val;
} elseif ($currentColumn == 2) {//手机号
if (empty($val)) {
throw new Exception('手机号不能为空');
}
$found_key = array_search('mobile', array_column($person_fieldset, 'field'));
$person_fieldset[$found_key]['value'] = $val;
$mobile = $val;
} elseif ($currentColumn == 3) {//级别
if (empty($val)) {
throw new Exception('级别不能为空');
}
$found_key = array_search('member_level_id', array_column($person_fieldset, 'field'));
$person_fieldset[$found_key]['value'] = $levelModel->where('name',$val)->value('id');
}
} else {
$key = ($currentColumn - $maxColumnNumber) + ($maxColumnNumber - count($person_fieldset) -1);//11 person 8 organize 0 1 2
$organize_fieldset[$key]['value'] = is_null($val) ? '' : $val;
}
$values[] = is_null($val) ? '' : $val;
$total_values[] = array(
'field'=>$fields[$currentColumn-1],
'val'=>$val,
);
}
$row = [];
$temp = array_combine($fields, $values);
$mobileWhere['mobile'] = array('eq',$mobile);
$memberObj = $this->model->where($mobileWhere)->find();
$memberApplyModel = new MemberApply();
$memberApplyObj = $memberApplyModel->where($mobileWhere)->find();
if (empty($memberObj) && empty($memberApplyObj)) {
$userWechatModel = new UserWechat();
foreach ($temp as $k => $v) {
if (isset($fieldArr[$k]) && $k !== '') {
$row[$fieldArr[$k]] = $v;
}
}
if (isset($row['industry_category_id']) && !empty($row['industry_category_id'])) {
$row['industry_category_id'] = (new \app\admin\model\wdsxh\member\IndustryCategory())->where('name',$row['industry_category_id'])->value('id');
}
foreach ($person_fieldset as $k=>$v) {
if (isset($v['field']) && $v['field'] == 'industry_category_id' && !empty($row['industry_category_id'])) {
$person_fieldset[$k]['value'] = $row['industry_category_id'];
}
}
$person_fieldset = wdsxh_update_array_child_fieldset($person_fieldset, $total_values);
foreach ($organize_fieldset as $k=>$v) {
if (!isset($v['field'])) {
unset($organize_fieldset[$k]);
}
}
foreach ($person_fieldset as $k=>$v) {
if (!isset($v['field'])) {
unset($person_fieldset[$k]);
}
}
$organize_fieldset = wdsxh_update_array_child_fieldset($organize_fieldset, $total_values);
$custom_content = array(
'person'=>$person_fieldset,
'organize'=>$organize_fieldset,
);
$row['custom_content'] = json_encode($custom_content);
$row['type'] = $type = '3';
$row['join_time'] = date('Y-m-d',time());
$row['expire_time'] = \app\common\model\wdsxh\member\Member::get_expire_time($row['join_time']);
$row['status'] = 'hidden';
$userWechatObj = $userWechatModel->where($mobileWhere)->find();
if ($userWechatObj) {
$row['wechat_id'] = $userWechatObj['id'];
}
if ($row) {
$insert[] = $row;
}
}
}
} catch (Exception $exception) {
$this->error($exception->getMessage());
}
$apply_data = array();
foreach ($insert as $k=>$v) {
$level_name_id = $levelModel->where('name',$v['member_level_id'])->value('id');
if (!$level_name_id) {
$this->error('级别'.$v['member_level_id'].'不存在');
} else {
$insert[$k]['member_level_name'] = $v['member_level_id'];
$insert[$k]['member_level_id'] = $level_name_id;
}
$insert[$k]['letter'] = \app\common\model\wdsxh\member\Member::getFirstCharter($v['name']);
$apply = array(
'type'=>$type,
'name'=>$v['name'],
'mobile'=>$v['mobile'],
'member_level_id'=>$insert[$k]['member_level_id'],
'custom_content'=>$v['custom_content'],
'state'=>'2',
'channel'=>3,
'child_state'=>'6',
'pay_method'=>'1',
);
if (isset($v['wechat_id']) && !empty($v['wechat_id'])) {
$apply['wechat_id'] = $v['wechat_id'];
}
$apply_data[] = $apply;
unset($apply);
}
if (!$insert) {
$this->error(__('No rows were updated'));
}
$memberApplyModel = new MemberApply();
try {
//是否包含admin_id字段
$has_admin_id = false;
foreach ($fieldArr as $name => $key) {
if ($key == 'admin_id') {
$has_admin_id = true;
break;
}
}
if ($has_admin_id) {
$auth = Auth::instance();
foreach ($insert as &$val) {
if (!isset($val['admin_id']) || empty($val['admin_id'])) {
$val['admin_id'] = $auth->isLogin() ? $auth->id : 0;
}
}
}
$this->model->saveAll($insert);
$memberApplyModel->saveAll($apply_data);
} catch (PDOException $exception) {
$msg = $exception->getMessage();
if (preg_match("/.+Integrity constraint violation: 1062 Duplicate entry '(.+)' for key '(.+)'/is", $msg, $matches)) {
$msg = "导入失败,包含【{$matches[1]}】的记录已存在";
};
$this->error($msg);
} catch (Exception $e) {
$this->error($e->getMessage());
}
$this->success();
}
/**
* 查看
*/
public function index()
{
//当前是否为关联查询
$this->relationSearch = true;
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
if ($this->request->isAjax()) {
//如果发送的来源是Selectpage则转发到Selectpage
if ($this->request->request('keyField')) {
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$list = $this->model
->where('type','3')
->with(['level','industry'])
->where($where)
->order($sort, $order)
->paginate($limit);
foreach ($list as $row) {
if (empty($row['organize_name'])) {
$row['organize_name'] = '';
}
if (empty($row['organize_position'])) {
$row['organize_position'] = '';
}
}
$result = array("total" => $list->total(), "rows" => $list->items());
return json($result);
}
return $this->view->fetch();
}
/**
* 添加
*
* @return string
* @throws \think\Exception
*/
public function add()
{
list($person_fieldset,$organize_fieldset) = \app\admin\model\wdsxh\member\JoinConfig::organize_fieldset();
if (false === $this->request->isPost()) {
$this->assign('person_fieldset',$person_fieldset);
$this->assign('organize_fieldset',$organize_fieldset);
return $this->view->fetch();
}
$params = $this->request->post('row/a');
if (empty($params)) {
$this->error(__('Parameter %s can not be empty', ''));
}
$params = $this->preExcludeFields($params);
if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
$params[$this->dataLimitField] = $this->auth->id;
}
$params = \app\admin\model\wdsxh\member\Member::get_member_edit_params(3,json_encode($person_fieldset),$params,'',json_encode($organize_fieldset));
$result = false;
$params['type'] = '3';
$params['expire_time'] = \app\common\model\wdsxh\member\Member::get_expire_time($params['join_time']);
$applyModel = new MemberApply();
$apply_data = $params;
$apply_data['channel'] = 3;
$apply_data['state'] = '2';//已通过
$apply_data['child_state'] = '6';//已通过
$params['channel'] = 3;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
$this->model->validateFailException()->validate($validate);
}
$applyModel->data($apply_data);
$applyModel->allowField(true)->save();
$result = $this->model->allowField(true)->save($params);
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($result === false) {
$this->error(__('No rows were inserted'));
}
$cert_data = \app\common\model\wdsxh\Cert::get_cert_data($params['type'],$applyModel,$this->model->id);
if(!empty($cert_data)) {
$certModel = new Cert();
$certModel->saveAll($cert_data);
}
$this->success();
}
/**
* 编辑
*
* @param $ids
* @return string
* @throws DbException
* @throws \think\Exception
*/
public function edit($ids = null)
{
$row = $this->model->get($ids);
$original_wechat_id = $row['wechat_id'];
$original_mobile = $row['mobile'];
if (!$row) {
$this->error(__('No Results were found'));
}
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
$this->error(__('You have no permission'));
}
if (false === $this->request->isPost()) {
$custom_content = json_decode($row['custom_content'],true);
$this->assign('person_fieldset',$custom_content['person']);
$this->assign('organize_fieldset',$custom_content['organize']);
$this->view->assign('row', $row);
return $this->view->fetch();
}
$params = $this->request->post('row/a');
if (empty($params)) {
$this->error(__('Parameter %s can not be empty', ''));
}
$params = $this->preExcludeFields($params);
$update_mobile = $params['person']['mobile'];
$result = false;
$tem_decode_json_custom_content = json_decode($row['custom_content'],true);
$params['custom_content'] = array_merge($params['person'],$params['organize']);
$params['custom_content']['mobile'] = $update_mobile;
$params = \app\admin\model\wdsxh\member\Member::get_member_edit_params($row['type'],json_encode($tem_decode_json_custom_content['person']),$params,'',json_encode($tem_decode_json_custom_content['organize']));
if (isset($params['join_time']) && !empty($params['join_time'])) {
$params['expire_time'] = \app\common\model\wdsxh\member\Member::get_expire_time($params['join_time']);
}
$params['id'] = $row['id'];
$queryMemberIsUserMobile = $this->model->where('mobile',$params['mobile'])
->where('id','<>',$row['id'])
->find();
if ($queryMemberIsUserMobile) {
$this->error('手机号已被其他会员使用');
}
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
$row->validateFailException()->validate($validate);
}
$result = $row->allowField(true)->save($params);
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if (false === $result) {
$this->error(__('No rows were updated'));
}
$applyModel = new MemberApply();
if(empty($original_wechat_id) && $params['wechat_id']) {//会员之前没有选中微信用户,编辑有选中微信用户
$applyObj = $applyModel->where('mobile',$original_mobile)->find();
if ($applyObj) {
$applyObj->mobile = $params['mobile'];
$applyObj->wechat_id = $params['wechat_id'];
$applyObj->save();
}
}
if(!empty($original_wechat_id) && ($original_wechat_id != $params['wechat_id'])) {//会员之前没有选中微信用户,编辑有选中微信用户
$applyObj = $applyModel->where('mobile',$original_mobile)->find();
if ($applyObj) {
$applyObj->mobile = $params['mobile'];
$applyObj->wechat_id = $params['wechat_id'];
$applyObj->save();
}
}
if ($original_mobile != $update_mobile) {
$applyObj = $applyModel->where('mobile',$original_mobile)->find();
$custom_content_array = json_decode($applyObj['custom_content'],true);
foreach ($custom_content_array['person'] as &$v) {
if (isset($v['field']) && $v['field'] == 'mobile') {
$v['value'] = $update_mobile;
}
}
$applyObj->custom_content = json_encode($custom_content_array);
$applyObj->mobile = $update_mobile;
$applyObj->save();
}
$this->success();
}
/**
* 导出
*/
public function export($ids = "")
{
if ($this->request->isPost()) {
set_time_limit(0);
ini_set('memory_limit', '2048M');
$search = $this->request->post('search');
$ids = $ids ? $ids : $this->request->post("ids");
$pk = $this->model->getPk();
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds)) {
$this->model->where($this->dataLimitField, 'in', $adminIds);
}
$op = $this->request->post('op');
$filter = $this->request->post('filter');
$columns = $this->request->post('columns');
// 兼容POST导出时筛选条件未生效的问题将筛选参数写入GET供buildparams读取
if (is_array($filter)) { $filter = json_encode($filter, JSON_UNESCAPED_UNICODE); }
if (is_array($op)) { $op = json_encode($op, JSON_UNESCAPED_UNICODE); }
$_GET['search'] = $search ?: '';
$_GET['ids'] = $ids ?: '';
$_GET['op'] = $op ?: '{}';
$_GET['filter'] = $filter ?: '{}';
$_GET['columns'] = $columns ?: '';
$this->relationSearch = true;
$this->request->get(['search' => $search, 'ids' => $ids,'op' => $op, 'filter' => $filter, 'columns' => $columns]);
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$baseWhere['type'] = array('eq','3');
if ($ids == 'all'){
$memberList = $this->model
->where($where)
->where($baseWhere)
->field('custom_content')
->select();
}else{
$memberList = $this->model
->where($pk, 'in', $ids)
->where($where)
->where($baseWhere)
->field('custom_content')
->select();
}
$memberList = collection($memberList)->toArray();
foreach ($memberList as $k=>$v){
if ($v['custom_content']){
$memberList[$k]['custom_content'] = json_decode($v['custom_content'],true);
}
}
$newExcel = new Spreadsheet(); //创建一个新的excel文档
$objSheet = $newExcel->getActiveSheet(); //获取当前操作sheet的对象
$type_name = (new \app\admin\model\wdsxh\member\JoinConfig())->where('type',3)->value('name');
if (empty($type_name)) {
$type_name = '团体会员';
}
$objSheet->setTitle($type_name); //设置当前sheet的标题
list($person_fieldset,$organize_fieldset) = \app\admin\model\wdsxh\member\JoinConfig::organize_fieldset();
$count_person_fieldset = count($person_fieldset);
$organize_count = $count_person_fieldset + count($organize_fieldset); //16
$labels = $this->byNumReturnLabels($organize_count);// 生成 A 到 Z 的数组作为列标的数组
// 设置列宽度
for ($i = 0; $i < count($labels); $i++) {
$column = $labels[$i];
$newExcel->getActiveSheet()->getColumnDimension($column)->setWidth(20);
}
for ($i = 0; $i < $count_person_fieldset; $i++) {//0-11
$label = isset($person_fieldset[$i]['label']) ? $person_fieldset[$i]['label'] : '';
$objSheet->setCellValue($labels[$i] . '1', $label);
}
for ($i = $count_person_fieldset; $i < $organize_count; $i++) {//11 12 13 14 15 //从11开始 总共16
$key = $i - count($person_fieldset);
$label = isset($organize_fieldset[$key]['label']) ? $organize_fieldset[$key]['label'] : '';
$objSheet->setCellValue($labels[$i] . '1', $label);
}
$levelModel = new \app\admin\model\wdsxh\member\Level();
$industryModel = new \app\admin\model\wdsxh\member\IndustryCategory();
// 外部循环遍历会员列表
foreach ($memberList as $rowIndex => $row) {
// 将 custom_content['person'] 转换为以 field 为键的关联数组
$personByField = [];
if (!empty($row['custom_content']['person']) && is_array($row['custom_content']['person'])) {
foreach ($row['custom_content']['person'] as $item) {
if (isset($item['field'])) {
$personByField[$item['field']] = $item;
}
}
}
// 将 custom_content['organize'] 转换为以 field 为键的关联数组
$organizeByField = [];
if (!empty($row['custom_content']['organize']) && is_array($row['custom_content']['organize'])) {
foreach ($row['custom_content']['organize'] as $item) {
if (isset($item['field'])) {
$organizeByField[$item['field']] = $item;
}
}
}
// 内部循环遍历表头 person_fieldset确保个人数据与表头字段一致
for ($j = 0; $j < count($person_fieldset); $j++) {
$field = isset($person_fieldset[$j]['field']) ? $person_fieldset[$j]['field'] : '';
$value = '';
// 在 custom_content['person'] 中查找与表头对应的 field 数据
if ($field && isset($personByField[$field])) {
$item = $personByField[$field];
if (isset($item['type']) && $item['type'] == 'cert') {
$value = !empty($item['value']) ? wdsxh_full_url($item['value']['image']) : '';
} elseif ($field == 'address') {
$value = !empty($item['value']) ? $item['value']['address'] : '';
} else {
$value = isset($item['value']) ? $item['value'] : '';
if (isset($item['type']) && in_array($item['type'], ['image', 'video'])) {
$value = wdsxh_full_url($value);
if (is_array($value)) {
$value = implode(',', $value);
}
}
if ($field == 'member_level_id') {
$value = $levelModel->where('id', $value)->value('name');
}
if ($field == 'industry_category_id') {
$value = $industryModel->where('id', $value)->value('name');
}
}
}
if (is_array($value)) {
$value = '';
}
$objSheet->setCellValue($labels[$j] . ($rowIndex + 2), ' ' . $value);
}
// 内部循环遍历表头 organize_fieldset确保团体数据与表头字段一致
for ($j = count($person_fieldset); $j < $organize_count; $j++) {
$key = $j - count($person_fieldset);
$field = isset($organize_fieldset[$key]['field']) ? $organize_fieldset[$key]['field'] : '';
$value = '';
// 在 custom_content['organize'] 中查找与表头对应的 field 数据
if ($field && isset($organizeByField[$field])) {
$item = $organizeByField[$field];
if (isset($item['type']) && $item['type'] == 'cert') {
$value = !empty($item['value']) ? wdsxh_full_url($item['value']['image']) : '';
} elseif ($field == 'address') {
$value = !empty($item['value']) ? $item['value']['address'] : '';
} else {
$value = isset($item['value']) ? $item['value'] : '';
if (isset($item['type']) && in_array($item['type'], ['image', 'video'])) {
$value = wdsxh_full_url($value);
if (is_array($value)) {
$value = implode(',', $value);
}
}
if ($field == 'member_level_id') {
$value = $levelModel->where('id', $value)->value('name');
}
if ($field == 'industry_category_id') {
$value = $industryModel->where('id', $value)->value('name');
}
}
}
$objSheet->setCellValue($labels[$j] . ($rowIndex + 2), ' ' . $value);
}
}
/*--------------下面是设置其他信息------------------*/
$title = date("Ymd-".$type_name);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="' . $title . '.xlsx"');
header('Cache-Control: max-age=0');
$objWriter = IOFactory::createWriter($newExcel, 'Xlsx');
$objWriter->save('php://output');
return;
}
}
/**
* 导出模板
*/
public function import_template()
{
if ($this->request->isPost()) {
set_time_limit(0);
ini_set('memory_limit', '2048M');
$newExcel = new Spreadsheet(); //创建一个新的excel文档
$objSheet = $newExcel->getActiveSheet(); //获取当前操作sheet的对象
$type_name = (new \app\admin\model\wdsxh\member\JoinConfig())->where('type',3)->value('name');
if (empty($type_name)) {
$type_name = '团体会员';
}
$objSheet->setTitle($type_name); //设置当前sheet的标题
$person_fieldset = array (
0 =>
array (
'show' => '1',
'required' => '1',
'type' => 'text',
'label' => '姓名',
'field' => 'name',
'option' => '请输入你的姓名',
),
1 =>
array (
'show' => '1',
'required' => '1',
'type' => 'number',
'label' => '手机号',
'field' => 'mobile',
'option' => '请输入你的手机号',
),
2 =>
array (
'show' => '1',
'required' => '1',
'type' => 'select',
'label' => '级别',
'field' => 'member_level_id',
'option' => '请选择会员级别',
),
);
$count_person_fieldset = count($person_fieldset);
$labels = $this->byNumReturnLabels($count_person_fieldset);// 生成 A 到 Z 的数组作为列标的数组
// 设置列宽度
for ($i = 0; $i < count($labels); $i++) {
$column = $labels[$i];
$newExcel->getActiveSheet()->getColumnDimension($column)->setWidth(20);
}
foreach ($person_fieldset as $k=>$v) {
if(in_array($v['type'],['image','video','cert']) || in_array($v['field'],['address'])) {
unset($person_fieldset[$k]);
}
}
$person_fieldset = array_values($person_fieldset);
for ($i = 0; $i < count($person_fieldset); $i++) {
$label = isset($person_fieldset[$i]['label']) ? $person_fieldset[$i]['label'] : '';
$objSheet->setCellValue($labels[$i] . '1', $label);
}
/*--------------下面是设置其他信息------------------*/
$title = date("Ymd-".$type_name."模板");
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="' . $title . '.xlsx"');
header('Cache-Control: max-age=0');
$objWriter = IOFactory::createWriter($newExcel, 'Xlsx');
$filename = $title.'.xlsx';
ob_start();
$objWriter->save('php://output');
$xlsData = ob_get_contents();
ob_end_clean();
$this->success('请求成功','',['filename' => $filename, 'file' => "data:application/vnd.ms-excel;base64," . base64_encode($xlsData)]);
}
}
public function seluser()
{
return;
}
public function member()
{
return;
}
public function activity_seluser()
{
return;
}
}

View File

@@ -0,0 +1,109 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh\member;
use app\admin\model\wdsxh\member\MemberApply;
use app\common\controller\Backend;
/**
* 会员缴费记录
*
* @icon fa fa-circle-o
*/
class Pay extends Backend
{
/**
* Pay模型对象
* @var \app\admin\model\wdsxh\member\Pay
*/
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\wdsxh\member\Pay;
$this->view->assign("paidList", $this->model->getPaidList());
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
/**
* 查看
*/
public function index()
{
//当前是否为关联查询
$this->relationSearch = true;
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
if ($this->request->isAjax()) {
//如果发送的来源是Selectpage则转发到Selectpage
if ($this->request->request('keyField')) {
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$list = $this->model
->where('pay_method','in',['2','3','4'])
->with(['level','wechat','member'])
->where($where)
->order($sort, $order)
->paginate($limit);
$memberApplyModel = new MemberApply();
foreach ($list as $row) {
if ($row['pay_method'] == '3') {
$row->pay_voucher = $memberApplyModel->where('wechat_id',$row['wechat_id'])->value('pay_voucher');
}
if ($row['pay_method'] == '2') {
$row->pay_voucher = '/assets/addons/wdsxh/img/wechat_pay.png';
}
if ($row['pay_method'] == '4') {
$row->paid = 4;
}
}
$result = array("total" => $list->total(), "rows" => $list->items());
return json($result);
}
return $this->view->fetch();
}
public function multi($ids = null)
{
return;
}
public function del($ids = null)
{
return;
}
public function edit($ids = null)
{
return;
}
public function add()
{
return;
}
}

View File

@@ -0,0 +1,752 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh\member;
use app\admin\library\Auth;
use app\admin\model\wdsxh\member\Cert;
use app\admin\model\wdsxh\member\MemberApply;
use app\admin\model\wdsxh\user\UserWechat;
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Reader\Csv;
use PhpOffice\PhpSpreadsheet\Reader\Xls;
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use think\Db;
use think\db\exception\BindParamException;
use think\exception\DbException;
use think\exception\PDOException;
use think\exception\ValidateException;
use Exception;
/**
* 会员管理
*
* @icon fa fa-circle-o
*/
class Person extends Member
{
/**
* Person模型对象
* @var \app\admin\model\wdsxh\member\Person
*/
protected $model = null;
protected $noNeedRight = ['seluser','member'];
protected $industryCategoryModel = null;
protected $modelValidate = true;
protected $modelSceneValidate = true;
public function _initialize()
{
parent::_initialize();
$this->industryCategoryModel = new \app\admin\model\wdsxh\member\IndustryCategory();
}
/**
* 导出
*/
public function export($ids = "")
{
if ($this->request->isPost()) {
set_time_limit(0);
ini_set('memory_limit', '2048M');
$search = $this->request->post('search');
$ids = $ids ? $ids : $this->request->post("ids");
$pk = $this->model->getPk();
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds)) {
$this->model->where($this->dataLimitField, 'in', $adminIds);
}
$op = $this->request->post('op');
$filter = $this->request->post('filter');
$columns = $this->request->post('columns');
// 兼容POST导出时筛选条件未生效的问题将筛选参数写入GET供buildparams读取
if (is_array($filter)) { $filter = json_encode($filter, JSON_UNESCAPED_UNICODE); }
if (is_array($op)) { $op = json_encode($op, JSON_UNESCAPED_UNICODE); }
$_GET['search'] = $search ?: '';
$_GET['ids'] = $ids ?: '';
$_GET['op'] = $op ?: '{}';
$_GET['filter'] = $filter ?: '{}';
$_GET['columns'] = $columns ?: '';
$this->relationSearch = true;
$this->request->get(['search' => $search, 'ids' => $ids,'op' => $op, 'filter' => $filter, 'columns' => $columns]);
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$baseWhere['type'] = array('eq','1');
if ($ids == 'all'){
$memberList = $this->model
->where($where)
->where($baseWhere)
->field('custom_content')
->select();
}else{
$memberList = $this->model
->where($pk, 'in', $ids)
->where($where)
->where($baseWhere)
->field('custom_content')
->select();
}
$memberList = collection($memberList)->toArray();
foreach ($memberList as $k=>$v){
if ($v['custom_content']){
$memberList[$k]['custom_content'] = json_decode($v['custom_content'],true);
}
}
$newExcel = new Spreadsheet(); //创建一个新的excel文档
$objSheet = $newExcel->getActiveSheet(); //获取当前操作sheet的对象
$type_name = (new \app\admin\model\wdsxh\member\JoinConfig())->where('type',1)->value('name');
if (empty($type_name)) {
$type_name = '个人会员';
}
$objSheet->setTitle($type_name); //设置当前sheet的标题
$person_fieldset = \app\admin\model\wdsxh\member\JoinConfig::person_fieldset();
$count_person_fieldset = count($person_fieldset);
$labels = $this->byNumReturnLabels($count_person_fieldset);// 生成 A 到 Z 的数组作为列标的数组
// 设置列宽度
for ($i = 0; $i < count($labels); $i++) {
$column = $labels[$i];
$newExcel->getActiveSheet()->getColumnDimension($column)->setWidth(20);
}
$person_fieldset = \app\admin\model\wdsxh\member\JoinConfig::person_fieldset();
for ($i = 0; $i < $count_person_fieldset; $i++) {
$label = isset($person_fieldset[$i]['label']) ? $person_fieldset[$i]['label'] : '';
$objSheet->setCellValue($labels[$i] . '1', $label);
}
$levelModel = new \app\admin\model\wdsxh\member\Level();
$industryModel = new \app\admin\model\wdsxh\member\IndustryCategory();
// 外部循环遍历会员列表
foreach ($memberList as $rowIndex => $row) {
// 将 custom_content 转换为以 field 为键的关联数组,便于按表头顺序查找
$contentByField = [];
if (!empty($row['custom_content']) && is_array($row['custom_content'])) {
foreach ($row['custom_content'] as $item) {
if (isset($item['field'])) {
$contentByField[$item['field']] = $item;
}
}
}
// 内部循环遍历表头 person_fieldset确保数据与表头字段一致
for ($j = 0; $j < count($person_fieldset); $j++) {
$field = isset($person_fieldset[$j]['field']) ? $person_fieldset[$j]['field'] : '';
$value = '';
// 在 custom_content 中查找与表头对应的 field 数据
if ($field && isset($contentByField[$field])) {
$item = $contentByField[$field];
if (isset($item['type']) && $item['type'] == 'cert') {
$value = !empty($item['value']) ? wdsxh_full_url($item['value']['image']) : '';
} elseif ($field == 'address') {
$value = !empty($item['value']) ? $item['value']['address'] : '';
} else {
$value = isset($item['value']) ? $item['value'] : '';
if (isset($item['type']) && in_array($item['type'], ['image', 'video'])) {
$value = wdsxh_full_url($value);
if (is_array($value)) {
$value = implode(',', $value);
}
}
if ($field == 'member_level_id') {
$value = $levelModel->where('id', $value)->value('name');
}
if ($field == 'industry_category_id') {
$value = $industryModel->where('id', $value)->value('name');
}
}
}
$objSheet->setCellValue($labels[$j] . ($rowIndex + 2), ' ' . $value);
}
}
/*--------------下面是设置其他信息------------------*/
$title = date("Ymd-".$type_name);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="' . $title . '.xlsx"');
header('Cache-Control: max-age=0');
$objWriter = IOFactory::createWriter($newExcel, 'Xlsx');
$objWriter->save('php://output');
return;
}
}
/**
* 导出模板
*/
public function import_template()
{
if ($this->request->isPost()) {
set_time_limit(0);
ini_set('memory_limit', '2048M');
$newExcel = new Spreadsheet(); //创建一个新的excel文档
$objSheet = $newExcel->getActiveSheet(); //获取当前操作sheet的对象
$type_name = (new \app\admin\model\wdsxh\member\JoinConfig())->where('type',1)->value('name');
if (empty($type_name)) {
$type_name = '个人会员';
}
$objSheet->setTitle($type_name); //设置当前sheet的标题
$person_fieldset = array (
0 =>
array (
'show' => '1',
'required' => '1',
'type' => 'text',
'label' => '姓名',
'field' => 'name',
'option' => '请输入你的姓名',
),
1 =>
array (
'show' => '1',
'required' => '1',
'type' => 'number',
'label' => '手机号',
'field' => 'mobile',
'option' => '请输入你的手机号',
),
2 =>
array (
'show' => '1',
'required' => '1',
'type' => 'select',
'label' => '级别',
'field' => 'member_level_id',
'option' => '请选择会员级别',
),
);
$count_person_fieldset = count($person_fieldset);
$labels = $this->byNumReturnLabels($count_person_fieldset);// 生成 A 到 Z 的数组作为列标的数组
// 设置列宽度
for ($i = 0; $i < count($labels); $i++) {
$column = $labels[$i];
$newExcel->getActiveSheet()->getColumnDimension($column)->setWidth(20);
}
foreach ($person_fieldset as $k=>$v) {
if(in_array($v['type'],['image','video','cert']) || in_array($v['field'],['address'])) {
unset($person_fieldset[$k]);
}
}
$person_fieldset = array_values($person_fieldset);
for ($i = 0; $i < count($person_fieldset); $i++) {
$label = isset($person_fieldset[$i]['label']) ? $person_fieldset[$i]['label'] : '';
$objSheet->setCellValue($labels[$i] . '1', $label);
}
/*--------------下面是设置其他信息------------------*/
$title = date("Ymd-".$type_name."模板");
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="' . $title . '.xlsx"');
header('Cache-Control: max-age=0');
$objWriter = IOFactory::createWriter($newExcel, 'Xlsx');
$filename = $title.'.xlsx';
ob_start();
$objWriter->save('php://output');
$xlsData = ob_get_contents();
ob_end_clean();
$this->success('请求成功','',['filename' => $filename, 'file' => "data:application/vnd.ms-excel;base64," . base64_encode($xlsData)]);
}
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
/**
* 导入
*
* @return void
* @throws PDOException
* @throws BindParamException
*/
public function import()
{
$person_fieldset = \app\admin\model\wdsxh\member\JoinConfig::person_fieldset();
foreach ($person_fieldset as $k=>$v) {
if ($v['field'] == 'address') {
$person_fieldset[$k]['value'] = array(
'address'=>'',
'latitude'=>'',
'longitude'=>'',
);
} else {
$person_fieldset[$k]['value'] = '';
}
}
$file = $this->request->request('file');
if (!$file) {
$this->error(__('Parameter %s can not be empty', 'file'));
}
$filePath = ROOT_PATH . DS . 'public' . DS . $file;
if (!is_file($filePath)) {
$this->error(__('No results were found'));
}
//实例化reader
$ext = pathinfo($filePath, PATHINFO_EXTENSION);
if (!in_array($ext, ['csv', 'xls', 'xlsx'])) {
$this->error(__('Unknown data format'));
}
if ($ext === 'csv') {
$file = fopen($filePath, 'r');
$filePath = tempnam(sys_get_temp_dir(), 'import_csv');
$fp = fopen($filePath, 'w');
$n = 0;
while ($line = fgets($file)) {
$line = rtrim($line, "\n\r\0");
$encoding = mb_detect_encoding($line, ['utf-8', 'gbk', 'latin1', 'big5']);
if ($encoding !== 'utf-8') {
$line = mb_convert_encoding($line, 'utf-8', $encoding);
}
if ($n == 0 || preg_match('/^".*"$/', $line)) {
fwrite($fp, $line . "\n");
} else {
fwrite($fp, '"' . str_replace(['"', ','], ['""', '","'], $line) . "\"\n");
}
$n++;
}
fclose($file) || fclose($fp);
$reader = new Csv();
} elseif ($ext === 'xls') {
$reader = new Xls();
} else {
$reader = new Xlsx();
}
$type = '1';
//导入文件首行类型,默认是注释,如果需要使用字段名称请使用name
$importHeadType = isset($this->importHeadType) ? $this->importHeadType : 'comment';
$table = $this->model->getQuery()->getTable();
$database = \think\Config::get('database.database');
$fieldArr = [];
$list = db()->query("SELECT COLUMN_NAME,COLUMN_COMMENT FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = ? AND TABLE_SCHEMA = ?", [$table, $database]);
foreach ($list as $k => $v) {
if ($importHeadType == 'comment') {
$v['COLUMN_COMMENT'] = explode(':', $v['COLUMN_COMMENT'])[0]; //字段备注有:时截取
$fieldArr[$v['COLUMN_COMMENT']] = $v['COLUMN_NAME'];
} else {
$fieldArr[$v['COLUMN_NAME']] = $v['COLUMN_NAME'];
}
}
$levelModel = new \app\admin\model\wdsxh\member\Level();
//加载文件
$insert = [];
try {
if (!$PHPExcel = $reader->load($filePath)) {
$this->error(__('Unknown data format'));
}
$currentSheet = $PHPExcel->getSheet(0); //读取文件中的第一个工作表
$allColumn = $currentSheet->getHighestDataColumn(); //取得最大的列号
$allRow = $currentSheet->getHighestRow(); //取得一共有多少行
$maxColumnNumber = Coordinate::columnIndexFromString($allColumn);
$fields = [];
for ($currentRow = 1; $currentRow <= 1; $currentRow++) {
for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) {
$val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue();
$fields[] = $val;
}
}
for ($currentRow = 2; $currentRow <= $allRow; $currentRow++) {
$mobile = 0;
$values = [];
$isEmptyRow = true; // 假设该行为空行
// 先检查整行是否为空行
for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) {
$val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue();
$val = trim($val);
// 如果某一列有值,则该行不为空
if (!empty($val)) {
$isEmptyRow = false;
}
}
// 如果该行为空行,则跳过
if ($isEmptyRow) {
continue;
}
// 如果不是空行,则处理每一列的数据
for ($currentColumn = 1; $currentColumn <= $maxColumnNumber; $currentColumn++) {
$val = $currentSheet->getCellByColumnAndRow($currentColumn, $currentRow)->getValue();
$val = trim($val);
if ($currentColumn == 1) {//姓名
if (empty($val)) {
throw new Exception('姓名不能为空');
}
$found_key = array_search('name', array_column($person_fieldset, 'field'));
$person_fieldset[$found_key]['value'] = $val;
$mobile = $val;
} elseif ($currentColumn == 2) {//手机号
if (empty($val)) {
throw new Exception('手机号不能为空');
}
$found_key = array_search('mobile', array_column($person_fieldset, 'field'));
$person_fieldset[$found_key]['value'] = $val;
$mobile = $val;
} elseif ($currentColumn == 3) {//级别
if (empty($val)) {
throw new Exception('级别不能为空');
}
$found_key = array_search('member_level_id', array_column($person_fieldset, 'field'));
$person_fieldset[$found_key]['value'] = $levelModel->where('name',$val)->value('id');
}
$values[] = is_null($val) ? '' : $val;
$total_values[] = array(
'field'=>$fields[$currentColumn-1],
'val'=>$val,
);
}
$row = [];
$temp = array_combine($fields, $values);
$mobileWhere['mobile'] = array('eq',$mobile);
$memberObj = $this->model->where($mobileWhere)->find();
$memberApplyModel = new MemberApply();
$memberApplyObj = $memberApplyModel->where($mobileWhere)->find();
if (empty($memberObj) && empty($memberApplyObj)) {
$userWechatModel = new UserWechat();
foreach ($temp as $k => $v) {
if (isset($fieldArr[$k]) && $k !== '') {
$row[$fieldArr[$k]] = $v;
}
}
$row['type'] = $type;
$join_time = date('Y-m-d',time());
$row['join_time'] = $join_time;
$row['expire_time'] = \app\common\model\wdsxh\member\Member::get_expire_time($join_time);
$row['status'] = 'hidden';
$userWechatObj = $userWechatModel->where($mobileWhere)->find();
if ($userWechatObj) {
$row['wechat_id'] = $userWechatObj['id'];
}
if (isset($row['industry_category_id']) && !empty($row['industry_category_id'])) {
$row['industry_category_id'] = (new \app\admin\model\wdsxh\member\IndustryCategory())->where('name',$row['industry_category_id'])->value('id');
}
if ($row) {
foreach ($person_fieldset as $k=>$v) {
if (isset($v['field']) && $v['field'] == 'industry_category_id' && !empty($row['industry_category_id'])) {
$person_fieldset[$k]['value'] = $row['industry_category_id'];
}
}
foreach ($person_fieldset as $k=>$v) {
if (!isset($v['field'])) {
unset($person_fieldset[$k]);
}
}
// 调用函数并传入数据
$person_fieldset = wdsxh_update_array_child_fieldset($person_fieldset, $total_values);
$row['custom_content'] = json_encode($person_fieldset);
$insert[] = $row;
}
}
}
} catch (Exception $exception) {
$this->error($exception->getMessage());
}
$apply_data = array();
foreach ($insert as $k=>$v) {
$level_name_id = $levelModel->where('name',$v['member_level_id'])->value('id');
if (!$level_name_id) {
$this->error('级别'.$v['member_level_id'].'不存在');
} else {
$insert[$k]['member_level_name'] = $v['member_level_id'];
$insert[$k]['member_level_id'] = $level_name_id;
}
$insert[$k]['letter'] = \app\common\model\wdsxh\member\Member::getFirstCharter($v['name']);
$apply = array(
'type'=>$type,
'name'=>$v['name'],
'mobile'=>$v['mobile'],
'member_level_id'=>$insert[$k]['member_level_id'],
'custom_content'=>$v['custom_content'],
'state'=>'2',
'channel'=>3,
'child_state'=>'6',
'pay_method'=>'1',
);
if (isset($v['wechat_id']) && !empty($v['wechat_id'])) {
$apply['wechat_id'] = $v['wechat_id'];
}
$apply_data[] = $apply;
unset($apply);
}
if (!$insert) {
$this->error(__('No rows were updated'));
}
$memberApplyModel = new MemberApply();
try {
//是否包含admin_id字段
$has_admin_id = false;
foreach ($fieldArr as $name => $key) {
if ($key == 'admin_id') {
$has_admin_id = true;
break;
}
}
if ($has_admin_id) {
$auth = Auth::instance();
foreach ($insert as &$val) {
if (!isset($val['admin_id']) || empty($val['admin_id'])) {
$val['admin_id'] = $auth->isLogin() ? $auth->id : 0;
}
}
}
$this->model->saveAll($insert);
$memberApplyModel->saveAll($apply_data);
} catch (PDOException $exception) {
$msg = $exception->getMessage();
if (preg_match("/.+Integrity constraint violation: 1062 Duplicate entry '(.+)' for key '(.+)'/is", $msg, $matches)) {
$msg = "导入失败,包含【{$matches[1]}】的记录已存在";
};
$this->error($msg);
} catch (Exception $e) {
$this->error($e->getMessage());
}
$this->success();
}
/**
* 查看
*/
public function index()
{
//当前是否为关联查询
$this->relationSearch = true;
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
if ($this->request->isAjax()) {
//如果发送的来源是Selectpage则转发到Selectpage
if ($this->request->request('keyField')) {
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$list = $this->model
->where('type','1')
->with(['level','industry'])
->where($where)
->order($sort, $order)
->paginate($limit);
foreach ($list as $row) {
}
$result = array("total" => $list->total(), "rows" => $list->items());
return json($result);
}
return $this->view->fetch();
}
/**
* 添加
*
* @return string
* @throws \think\Exception
*/
public function add()
{
$person_fieldset = \app\admin\model\wdsxh\member\JoinConfig::person_fieldset();
if (false === $this->request->isPost()) {
$this->assign('person_fieldset',$person_fieldset);
return $this->view->fetch();
}
$params = $this->request->post('row/a');
if (empty($params)) {
$this->error(__('Parameter %s can not be empty', ''));
}
$params = $this->preExcludeFields($params);
if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
$params[$this->dataLimitField] = $this->auth->id;
}
$params = \app\admin\model\wdsxh\member\Member::get_member_edit_params(1,json_encode($person_fieldset),$params);
$result = false;
$params['type'] = '1';
$params['expire_time'] = \app\common\model\wdsxh\member\Member::get_expire_time($params['join_time']);
$applyModel = new MemberApply();
$apply_data = $params;
$apply_data['channel'] = 3;
$apply_data['state'] = '2';//已通过
$apply_data['child_state'] = '6';//已通过
$params['channel'] = 3;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
$this->model->validateFailException()->validate($validate);
}
$applyModel->data($apply_data);
$applyModel->allowField(true)->save();
$result = $this->model->allowField(true)->save($params);
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($result === false) {
$this->error(__('No rows were inserted'));
}
$cert_data = \app\common\model\wdsxh\Cert::get_cert_data($params['type'],$applyModel,$this->model->id);
if(!empty($cert_data)) {
$certModel = new Cert();
$certModel->saveAll($cert_data);
}
$this->success();
}
/**
* 编辑
*
* @param $ids
* @return string
* @throws DbException
* @throws \think\Exception
*/
public function edit($ids = null)
{
$row = $this->model->get($ids);
$original_wechat_id = $row['wechat_id'];
$original_mobile = $row['mobile'];
if (!$row) {
$this->error(__('No Results were found'));
}
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
$this->error(__('You have no permission'));
}
if (false === $this->request->isPost()) {
$custom_content = json_decode($row['custom_content'],true);
$row['custom_content'] = $custom_content;
$this->view->assign('row', $row);
return $this->view->fetch();
}
$params = $this->request->post('row/a');
$params['person']['mobile'] = $row['mobile'];
if (empty($params)) {
$this->error(__('Parameter %s can not be empty', ''));
}
$params = $this->preExcludeFields($params);
$result = false;
$params = \app\admin\model\wdsxh\member\Member::get_member_edit_params($row['type'],$row['custom_content'],$params);
if (isset($params['join_time']) && !empty($params['join_time'])) {
$params['expire_time'] = \app\common\model\wdsxh\member\Member::get_expire_time($params['join_time']);
}
$params['id'] = $row['id'];
$queryMemberIsUserMobile = $this->model->where('mobile',$params['mobile'])
->where('id','<>',$row['id'])
->find();
if ($queryMemberIsUserMobile) {
$this->error('手机号已被其他会员使用');
}
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
$row->validateFailException()->validate($validate);
}
$result = $row->allowField(true)->save($params);
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if (false === $result) {
$this->error(__('No rows were updated'));
}
$applyModel = new MemberApply();
if(empty($original_wechat_id) && $params['wechat_id']) {//会员之前没有选中微信用户,编辑有选中微信用户
$applyObj = $applyModel->where('mobile',$original_mobile)->find();
if ($applyObj) {
$applyObj->mobile = $params['mobile'];
$applyObj->wechat_id = $params['wechat_id'];
$applyObj->save();
}
}
if(!empty($original_wechat_id) && ($original_wechat_id != $params['wechat_id'])) {//会员之前没有选中微信用户,编辑有选中微信用户
$applyObj = $applyModel->where('mobile',$original_mobile)->find();
if ($applyObj) {
$applyObj->mobile = $params['mobile'];
$applyObj->wechat_id = $params['wechat_id'];
$applyObj->save();
}
}
if ($original_mobile != $params['mobile']) {
$applyObj = $applyModel->where('mobile',$original_mobile)->find();
$custom_content_array = json_decode($applyObj['custom_content'],true);
foreach ($custom_content_array as &$v) {
if (isset($v['field']) && $v['field'] == 'mobile') {
$v['value'] = $params['mobile'];
}
}
$applyObj->custom_content = json_encode($custom_content_array);
$applyObj->mobile = $params['mobile'];
$applyObj->save();
}
$this->success();
}
public function seluser()
{
return;
}
public function member()
{
return;
}
public function activity_seluser()
{
return;
}
/**
* 发送会员消息通知
*/
}

View File

@@ -0,0 +1,157 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh\member;
use app\common\controller\Backend;
use think\Db;
use think\exception\PDOException;
use think\exception\ValidateException;
use Exception;
/**
* 推广会员
*
* @icon fa fa-circle-o
*/
class Promotion extends Backend
{
/**
* Promotion模型对象
* @var \app\admin\model\wdsxh\member\Promotion
*/
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = new \app\admin\model\wdsxh\member\Promotion;
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
/**
* 查看
*/
public function index()
{
try {
\think\Db::execute("SET @@sql_mode='';");
} catch (\Exception $e) {
$this->error($e->getMessage());
}
//当前是否为关联查询
$this->relationSearch = true;
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
if ($this->request->isAjax()) {
//如果发送的来源是Selectpage则转发到Selectpage
if ($this->request->request('keyField')) {
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$list = $this->model
->with(['member'])
->group('member_id')
->where($where)
->order($sort, $order)
->paginate($limit);
$levelModel = new \app\admin\model\wdsxh\member\Level();
foreach ($list as &$row) {
$row->level_name = $levelModel->where('id',$row['member']['member_level_id'])->value('name');
}
$result = array("total" => $list->total(), "rows" => $list->items());
return json($result);
}
return $this->view->fetch();
}
/**
* Desc 设置海报推广
* Create on 2024/4/7 9:04
* Create by wangyafang
*/
public function config(){
$row = (new \app\admin\model\wdsxh\Config())->get(1);
if (!$row) {
$this->error(__('No Results were found'));
}
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
$this->error(__('You have no permission'));
}
if (false === $this->request->isPost()) {
$this->view->assign('row', $row);
$this->view->assign("select_home_mode", ['1' => __('固定样式'), '2' => __('装修自定义')]);
return $this->view->fetch();
}
$params = $this->request->post('row/a');
if (empty($params)) {
$this->error(__('Parameter %s can not be empty', ''));
}
$params = $this->preExcludeFields($params);
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->modelConfig));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
$row->validateFailException()->validate($validate);
}
$result = $row->allowField(true)->save($params);
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if (false === $result) {
$this->error(__('No rows were updated'));
}
$this->success();
}
public function multi($ids = null)
{
return;
}
public function del($ids = null)
{
return;
}
public function edit($ids = null)
{
return;
}
public function add()
{
return;
}
}

View File

@@ -0,0 +1,133 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
/**
* Class Set
* Desc 会员设置
* Create on 2024/3/28 16:39
* Create by wangyafang
*/
namespace app\admin\controller\wdsxh\member;
use app\common\controller\Backend;
use think\Db;
use think\exception\PDOException;
use think\exception\ValidateException;
use Exception;
class Set extends Backend
{
protected $model = null;
protected $feesConfigmodel = null;
protected $authConfigmodel = null;
protected $modelValidate = true;
public function _initialize()
{
parent::_initialize();
$this->feesConfigmodel = new \app\admin\model\wdsxh\member\FeesConfig;
$this->view->assign("expireTimeTypeList", $this->feesConfigmodel->getExpireTimeTypeList());
$this->view->assign("payMethodList", $this->feesConfigmodel->getPayMethodList());
$this->authConfigmodel = new \app\admin\model\wdsxh\member\AuthConfig;
$this->view->assign("addressBookIsOpennessList", $this->authConfigmodel->getAddressBookIsOpennessList());
$this->view->assign("addressBookIsExclusiveList", $this->authConfigmodel->getAddressBookIsExclusiveList());
$this->view->assign("memberDetailsList", $this->authConfigmodel->getMemberDetailsList());
$this->view->assign("addressBookSortOrderList", $this->authConfigmodel->getAddressBookSortOrderList());
}
public function index()
{
$authConfigObj = (new \app\admin\model\wdsxh\member\AuthConfig())->get(1);
$authConfigData = $authConfigObj->toArray();
$feesConfigObj = (new \app\admin\model\wdsxh\member\FeesConfig())->get(1);
$feesConfigData = $feesConfigObj->toArray();
$row = array_merge($authConfigData,$feesConfigData);
if (!$row) {
$this->error(__('No Results were found'));
}
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds)) {
if (!in_array($row[$this->dataLimitField], $adminIds)) {
$this->error(__('You have no permission'));
}
}
if ($this->request->isPost()) {
$params = $this->request->post("row/a");
if (empty($params)) {
$this->error(__('Parameter %s can not be empty', ''));
}
if ($params) {
$params = $this->preExcludeFields($params);
if (empty($params['days'])) {
unset($params['days']);
}
if (empty($params['fixed_date'])) {
unset($params['fixed_date']);
}
$row = (new \app\admin\model\wdsxh\member\FeesConfig())->get(1);
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$validate = 'app\admin\validate\wdsxh\member\FeesConfig';
$row->validateFailException()->validate($validate);
}
$result = $row->allowField(true)->save($params);
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if (false === $result) {
$this->error(__('No rows were updated'));
}
$row = (new \app\admin\model\wdsxh\member\AuthConfig())->get(1);
$result = false;
Db::startTrans();
try {
//是否采用模型验证
$result = $row->allowField(true)->save($params);
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if (false === $result) {
$this->error(__('No rows were updated'));
}
if ($params['expire_time_type'] == '2') {
$current_date = date('Y-m-d', time());
$where['expire_time'] = array('>=', $current_date);
$memberModel = new \app\admin\model\wdsxh\member\Member();
$member_id_array = $memberModel->where($where)->column('id');
// 检查数组是否为空避免潜在的SQL问题
if (!empty($member_id_array)) {
$fixed_date = $params['fixed_date'];
$memberModel->where('id', 'in', $member_id_array)->update(['expire_time' => $fixed_date]);
}
}
$this->success();
}
}
$this->view->assign("row", $row);
return $this->view->fetch();
}
}

View File

@@ -0,0 +1,653 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh\member\apply;
use addons\wdsxh\library\AlibabaCloudSms;
use addons\wdsxh\library\Wxapp;
use app\admin\model\wdsxh\member\Cert;
use app\admin\model\wdsxh\member\FeesConfig;
use app\admin\model\wdsxh\member\Level;
use app\admin\model\wdsxh\member\Member;
use app\admin\model\wdsxh\member\MemberApply;
use app\admin\model\wdsxh\member\Pay;
use app\admin\model\wdsxh\points\PointsConfig;
use app\api\model\wdsxh\business\Association;
use app\common\controller\Backend;
use app\common\model\wdsxh\points\UserWechatPointsLog;
use think\Db;
use think\exception\DbException;
use think\exception\PDOException;
use think\exception\ValidateException;
use Exception;
/**
* 入会申请
*
* @icon fa fa-circle-o
*/
class Apply extends Backend
{
protected $model = null;
protected $domain = null;
public function _initialize()
{
parent::_initialize();
$this->model = new MemberApply();
$this->view->assign("typeList", $this->model->getTypeList());
$this->view->assign("stateList", $this->model->getStateExamineList());
$domain = cdnurl('',true);
$this->assign('domain',$domain);
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
/**
* 入会审核
*
* @param $ids
* @return string
* @throws DbException
* @throws \think\Exception
*/
public function examine($ids = null)
{
$row = $this->model->get($ids);
if (!$row) {
$this->error(__('No Results were found'));
}
if (!isset($row['type'])) {
$this->error('参数错误');
}
switch ($row['type']) {
case '1':
$custom_content = json_decode($row['custom_content'],true);
$row['custom_content'] = $custom_content;
break;
case '2':
$custom_content = json_decode($row['custom_content'],true);
$this->assign('person_fieldset',$custom_content['person']);
$this->assign('company_fieldset',$custom_content['company']);
break;
case '3':
$custom_content = json_decode($row['custom_content'],true);
$this->assign('person_fieldset',$custom_content['person']);
$this->assign('organize_fieldset',$custom_content['organize']);
break;
}
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
$this->error(__('You have no permission'));
}
if (false === $this->request->isPost()) {
if ($row['state'] == '2') {
$memberPayObj = (new Pay())->where('wechat_id',$row['wechat_id'])
->where('paid','2')
->order('id desc')
->field('pay_method,fees')
->find();
$row['pay'] = $memberPayObj;
}
$this->view->assign('row', $row);
return $this->view->fetch();
}
$params = $this->request->post('row/a');
if (empty($params)) {
$this->error(__('Parameter %s can not be empty', ''));
}
if (!isset($params['state'])) {
$this->error('请选择审核状态');
}
if ($params['state'] == 3 && empty($params['reject'])) {
$this->error('请填写驳回原因');
}
$params = $this->preExcludeFields($params);
$row = $this->model->get($ids);
switch ($row['type']) {
case '1':
$params = \app\admin\model\wdsxh\member\Member::get_member_edit_params($row['type'],$row['custom_content'],$params);
break;
case '2':
$tem_decode_json_custom_content = json_decode($row['custom_content'],true);
$params['custom_content'] = array_merge($params['person'],$params['company']);
$params['custom_content']['mobile'] = $row['mobile'];
$params = \app\admin\model\wdsxh\member\Member::get_member_edit_params($row['type'],json_encode($tem_decode_json_custom_content['person']),$params,json_encode($tem_decode_json_custom_content['company']));
break;
case '3':
$tem_decode_json_custom_content = json_decode($row['custom_content'],true);
$params['custom_content'] = array_merge($params['person'],$params['organize']);
$params['custom_content']['mobile'] = $row['mobile'];
$params = \app\admin\model\wdsxh\member\Member::get_member_edit_params($row['type'],json_encode($tem_decode_json_custom_content['person']),$params,'',json_encode($tem_decode_json_custom_content['organize']));
break;
}
$params['address'] = json_encode(array(
'address'=>$params['address'],
'latitude'=>$params['latitude'],
'longitude'=>$params['longitude'],
));
if ($params['state'] == '2') {
$this->pass($row,$params);
} else {
$this->reject($row,$params);
}
}
/**
* 线下审核
*
* @param $ids
* @return string
* @throws DbException
* @throws \think\Exception
*/
public function offline_examine($ids = null)
{
$row = $this->model->get($ids);
switch ($row['type']) {
case '1':
$custom_content = json_decode($row['custom_content'],true);
$row['custom_content'] = $custom_content;
break;
case '2':
$custom_content = json_decode($row['custom_content'],true);
$this->assign('person_fieldset',$custom_content['person']);
$this->assign('company_fieldset',$custom_content['company']);
break;
case '3':
$custom_content = json_decode($row['custom_content'],true);
$this->assign('person_fieldset',$custom_content['person']);
$this->assign('organize_fieldset',$custom_content['organize']);
break;
}
if (!$row) {
$this->error(__('No Results were found'));
}
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
$this->error(__('You have no permission'));
}
if (false === $this->request->isPost()) {
$this->view->assign('row', $row);
return $this->view->fetch();
}
$params = $this->request->post('row/a');
if (empty($params)) {
$this->error(__('Parameter %s can not be empty', ''));
}
if (!isset($params['state'])) {
$this->error('请选择审核状态');
}
if ($params['state'] == 3 && empty($params['reject'])) {
$this->error('请填写驳回原因');
}
$params = $this->preExcludeFields($params);
$row = $this->model->get($ids);
switch ($row['type']) {
case '1':
$params = \app\admin\model\wdsxh\member\Member::get_member_edit_params($row['type'],$row['custom_content'],$params);
break;
case '2':
$tem_decode_json_custom_content = json_decode($row['custom_content'],true);
$params['custom_content'] = array_merge($params['person'],$params['company']);
$params['custom_content']['mobile'] = $row['mobile'];
$params = \app\admin\model\wdsxh\member\Member::get_member_edit_params($row['type'],json_encode($tem_decode_json_custom_content['person']),$params,json_encode($tem_decode_json_custom_content['company']));
break;
case '3':
$tem_decode_json_custom_content = json_decode($row['custom_content'],true);
$params['custom_content'] = array_merge($params['person'],$params['organize']);
$params['custom_content']['mobile'] = $row['mobile'];
$params = \app\admin\model\wdsxh\member\Member::get_member_edit_params($row['type'],json_encode($tem_decode_json_custom_content['person']),$params,'',json_encode($tem_decode_json_custom_content['organize']));
break;
}
$params['address'] = json_encode(array(
'address'=>$params['address'],
'latitude'=>$params['latitude'],
'longitude'=>$params['longitude'],
));
if ($params['state'] == '2') {
$this->offline_pass($row,$params);
} else {
$this->offline_reject($row,$params);
}
}
/**
* Desc 通过
* Create on 2024/3/7 15:56
* Create by wangyafang
*/
protected function pass($row = '',$params = [])
{
$feesConfigObj = (new FeesConfig())->where('id',1)->find();
$params = array_merge($row->toArray(),$params);
$member_data = \app\common\model\wdsxh\member\Member::get_member_data($params);
$memberModel = new Member();
$memberObj = $memberModel->where('wechat_id',$row['wechat_id'])->find();
$conf = (new \app\admin\model\wdsxh\Config())->where('id', 1)->find();
$params['examine_role'] = 1;
$params['examine_admin_id'] = $this->auth->id;
$params['examine_time'] = time();
if ($feesConfigObj['pay_method'] == 1) {//免费入会
$params['state'] = '2';//已通过
$params['child_state'] = '6';//已通过
$result = false;
$member_data['pay_method'] = 1;
Db::startTrans();
try {
$result = $row->allowField(true)->save($params);
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if (false === $result) {
$this->error(__('No rows were updated'));
}
if ($memberObj) {
$memberObj->expire_time = $member_data['expire_time'];
$memberObj->save();
} else {
$memberModel->data($member_data);
$memberModel->allowField(true)->save();
$cert_data = \app\common\model\wdsxh\Cert::get_cert_data($row['type'],$row,$memberModel->id);
if(!empty($cert_data)) {
$certModel = new Cert();
$certModel->saveAll($cert_data);
}
}
if ($row['channel'] == '1') {
//入会审核成功通知
try {
$data = [
'thing1' => [
'value' => $row['name'],
],
'time3' => [
'value' => date('Y-m-d H:i:s'),
],
'phrase4' => [
'value' => '审核通过',
],
'thing5' => [
'value' => '恭喜成功加入会员',
],
];
$result = Wxapp::subscribeMessage($conf['applet_initiation_audit'], trim(wdsxh_get_openid($row['wechat_id'],1)), '/pages/mine/index', $data);
} catch (\think\Exception $e) {
$this->error($e->getMessage());
}
//入会申请成功通知
$businessAssociationObj = (new Association())->get(1);
try {
$conf = (new \app\admin\model\wdsxh\Config())->where('id', 1)->find();
$data = [
'thing3' => [
'value' => mb_substr($businessAssociationObj['name'], 0, 20)
],
'time2' => [
'value' => date('Y-m-d H:i:s'),
],
'thing1' => [
'value' => mb_substr('恭喜您已成功加入' . $businessAssociationObj['name'], 0, 20),
]
];
$result = Wxapp::subscribeMessage($conf['applet_initiation_success'], trim(wdsxh_get_openid($row['wechat_id'],1)), '/pages/mine/index', $data);
} catch (\think\Exception $e) {
$this->error($e->getMessage());
}
}
$join_member_get_points = (new PointsConfig())->where('id',1)->value('join_member_get_points');
$queryMemberObj = (new Member())->where('wechat_id',$row['wechat_id'])->find();
if ($join_member_get_points > 0 && !$queryMemberObj) {
UserWechatPointsLog::joinMemberAddPoints(1,'入会成功',$row['wechat_id'],$join_member_get_points,4);
}
$this->initiation_success_notify($member_data['mobile'],$member_data['member_level_name']);
} else {
$params['state'] = '4';//待付款
$params['child_state'] = '3';//待付款
$row->allowField(true)->save($params);
if ($row['channel'] == '1') {
//入会审核成功通知
try {
$conf = (new \app\admin\model\wdsxh\Config())->where('id', 1)->find();
$data = [
'thing1' => [
'value' => $row['name'],
],
'time3' => [
'value' => date('Y-m-d H:i:s'),
],
'phrase4' => [
'value' => '审核通过',
],
'thing5' => [
'value' => '通过审核,请前往小程序缴纳会费!',
],
];
$result = Wxapp::subscribeMessage($conf['applet_initiation_audit'], trim(wdsxh_get_openid($row['wechat_id'],1)), '/pages/mine/index', $data);
} catch (\think\Exception $e) {
$this->error($e->getMessage());
}
}
}
$this->success();
}
private function initiation_success_notify($phoneNumbers,$level_name)
{
$configObj = (new \app\admin\model\wdsxh\Config())->where('id', 1)->find();
if (!empty($configObj['alibaba_cloud_sign_name'])
&& !empty($configObj['alibaba_cloud_access_key_id'])
&& !empty($configObj['alibaba_cloud_access_key_secret'])
&& !empty($configObj['alibaba_initiation_success_notify'])
&& !empty($phoneNumbers)
) {
$level_name = preg_replace('/[^\x{4e00}-\x{9fa5}]/u', '',$level_name);
if (empty($level_name)) {
$level_name = '用户';
}
$userSendSmsRequestParam = [
"phoneNumbers" => $phoneNumbers,
"templateCode" => $configObj['alibaba_initiation_success_notify'],
"templateParam" => "{'leavelname':'$level_name'}"
];
AlibabaCloudSms::main($userSendSmsRequestParam);
}
}
/**
* Desc 驳回
* Create on 2024/3/7 15:56
* Create by wangyafang
*/
protected function reject($row = '',$params = [])
{
$params['child_state'] = '2';
$params['examine_role'] = 1;
$params['examine_admin_id'] = $this->auth->id;
$params['examine_time'] = time();
$result = false;
Db::startTrans();
try {
$result = $row->allowField(true)->save($params);
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if (false === $result) {
$this->error(__('No rows were updated'));
}
$conf = (new \app\admin\model\wdsxh\Config())->where('id', 1)->find();
if ($row['channel'] == 1) {
//入会审核成功通知
try {
$data = [
'thing1' => [
'value' => $row['name'],
],
'time3' => [
'value' => date('Y-m-d H:i:s'),
],
'phrase4' => [
'value' => '审核未通过',
],
'thing5' => [
'value' => '原因:' . $params['reject'],
],
];
$result = Wxapp::subscribeMessage($conf['applet_initiation_audit'], trim(wdsxh_get_openid($row['wechat_id'],1)), '/pages/mine/index', $data);
} catch (\think\Exception $e) {
$this->error($e->getMessage());
}
}
$this->success();
}
/**
* Desc 线下通过
* Create on 2024/3/21 9:01
* Create by wangyafang
*/
protected function offline_pass($row = '',$params = [])
{
$member_data = \app\common\model\wdsxh\member\Member::get_member_data($row);
$params['state'] = '2';//已通过
$params['child_state'] = '6';//已通过
$params['examine_role'] = 1;
$params['examine_admin_id'] = $this->auth->id;
$params['examine_time'] = time();
$memberModel = new Member();
$memberObj = $memberModel->where('wechat_id',$row['wechat_id'])->find();
if ($memberObj) {
$memberObj->expire_time = $member_data['expire_time'];
$memberObj->save();
$member_id = $memberObj['id'];
} else {
$memberModel->data($member_data);
$memberModel->allowField(true)->save();
$member_id = $memberModel->id;
}
$payModel = new Pay();
$result = false;
Db::startTrans();
try {
$result = $row->allowField(true)->save($params);
$pay_data = array(
'member_id'=>$member_id,
'wechat_id'=>$row['wechat_id'],
'order_no'=> wdsxh_create_order(),
'fees'=>(new Level())->where('id',$row['member_level_id'])->value('fees'),
'level_id'=>$row['member_level_id'],
'channel'=>$row['channel'],
'pay_method'=>'3',
'paid'=>'2',
'pay_time'=>time(),
);
$payModel->data($pay_data);
$payModel->allowField(true)->save();
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if (false === $result) {
$this->error(__('No rows were updated'));
}
$cert_data = \app\common\model\wdsxh\Cert::get_cert_data($row['type'],$row,$member_id);
if(!empty($cert_data)) {
$certModel = new Cert();
$certModel->saveAll($cert_data);
}
//入会审核成功通知
try {
$conf = (new \app\admin\model\wdsxh\Config())->where('id', 1)->find();
$data = [
'thing1' => [
'value' => $row['name'],
],
'time3' => [
'value' => date('Y-m-d H:i:s'),
],
'phrase4' => [
'value' => '审核通过',
],
'thing5' => [
'value' => '恭喜成功加入会员',
],
];
$result = Wxapp::subscribeMessage($conf['applet_initiation_audit'], trim(wdsxh_get_openid($row['wechat_id'],1)), '/pages/mine/index', $data);
} catch (\think\Exception $e) {
$this->error($e->getMessage());
}
$join_member_get_points = (new PointsConfig())->where('id',1)->value('join_member_get_points');
$queryMemberObj = (new Member())->where('wechat_id',$row['wechat_id'])->find();
if ($join_member_get_points > 0 && !$queryMemberObj) {
UserWechatPointsLog::joinMemberAddPoints(1,'入会成功',$row['wechat_id'],$join_member_get_points,4);
}
//入会申请成功通知
$businessAssociationObj = (new Association())->get(1);
try {
$conf = (new \app\admin\model\wdsxh\Config())->where('id', 1)->find();
$data = [
'thing3' => [
'value' => mb_substr($businessAssociationObj['name'], 0, 20)
],
'time2' => [
'value' => date('Y-m-d H:i:s'),
],
'thing1' => [
'value' => mb_substr('恭喜您已成功加入' . $businessAssociationObj['name'], 0, 20),
]
];
$result = Wxapp::subscribeMessage($conf['applet_initiation_success'], trim(wdsxh_get_openid($row['wechat_id'],1)), '/pages/mine/index', $data);
} catch (\think\Exception $e) {
$this->error($e->getMessage());
}
$this->initiation_success_notify($member_data['mobile'],$member_data['member_level_name']);
$this->success();
}
/**
* Desc 线下驳回
* Create on 2024/3/21 8:56
* Create by wangyafang
*/
protected function offline_reject($row = '',$params = [])
{
$params['child_state'] = '5';
$params['examine_role'] = 1;
$params['examine_admin_id'] = $this->auth->id;
$params['examine_time'] = time();
$result = false;
Db::startTrans();
try {
$result = $row->allowField(true)->save($params);
Db::commit();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if (false === $result) {
$this->error(__('No rows were updated'));
}
if ($row['channel'] == 1) {
//入会审核成功通知
try {
$conf = (new \app\admin\model\wdsxh\Config())->where('id', 1)->find();
$data = [
'thing1' => [
'value' => $row['name'],
],
'time3' => [
'value' => date('Y-m-d H:i:s'),
],
'phrase4' => [
'value' => '审核未通过',
],
'thing5' => [
'value' => '原因:' . $params['reject'],
],
];
$result = Wxapp::subscribeMessage($conf['applet_initiation_audit'], trim(wdsxh_get_openid($row['wechat_id'],1)), '/pages/mine/index', $data);
} catch (\think\Exception $e) {
$this->error($e->getMessage());
}
} else {//todo 公众号通知
}
$this->success();
}
public function multi($ids = null)
{
return;
}
//todo 缴费会员审核通过不缴费,待缴费状态时可以删除入会信息,入会成功以后没有删除功能
public function del($ids = null)
{
if (false === $this->request->isPost()) {
$this->error(__("Invalid parameters"));
}
if (empty($ids)) {
$this->error(__('Parameter %s can not be empty', 'ids'));
}
$adminIds = $this->getDataLimitAdminIds();
if (is_array($adminIds)) {
$this->model->where($this->dataLimitField, 'in', $adminIds);
}
$row = $this->model->get($ids);
$memberPayObj = (new Pay())->where('paid','1')
->where('wechat_id',$row['wechat_id'])
->find();
$result = false;
Db::startTrans();
try {
$result = $row->delete();
Db::commit();
} catch (PDOException|Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($result === false) {
$this->error('删除失败');
}
if ($memberPayObj) {
$memberPayObj->delete();
}
$this->success();
}
public function edit($ids = null)
{
return;
}
public function add()
{
return;
}
public function index()
{
return;
}
}

View File

@@ -0,0 +1,113 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh\member\apply;
use app\admin\model\Admin;
use app\admin\model\wdsxh\user\UserWechat;
/**
* 入会申请
*
* @icon fa fa-circle-o
*/
class Company extends Apply
{
protected $model = null;
protected $noNeedRight = ['examine','offline_examine'];
public function _initialize()
{
parent::_initialize();
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
/**
* 查看
*/
public function index()
{
//当前是否为关联查询
$this->relationSearch = true;
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
if ($this->request->isAjax()) {
//如果发送的来源是Selectpage则转发到Selectpage
if ($this->request->request('keyField')) {
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$list = $this->model
->where('state','in',['1','2','3','4'])
->where('type','2')
->with(['level'])
->where($where)
->order($sort, $order)
->paginate($limit);
$adminModel = new Admin();
$userWechatModel = new UserWechat();
foreach ($list as &$row) {
if (in_array($row['child_state'],array('3','6'))) {
if (!empty($row['examine_admin_id']) && !empty($row['examine_wechat_id'])) {
$adminUserName = $adminModel->where('id',$row['examine_admin_id'])->value('username');
$wechatNickname = $userWechatModel->where('id',$row['examine_wechat_id'])->value('nickname');
if (!empty($adminUserName)) {
$adminUserName = $adminUserName.'(后台审核)';
}
$row->examine_name = $wechatNickname.'(小程序审核)'.$adminUserName;
} elseif (!empty($row['examine_admin_id'])) {
$examineAdminIdArray = explode(',',$row['examine_admin_id']);
$adminArray = $adminModel->where('id','in',$examineAdminIdArray)->column('username');
$row->examine_name = count($adminArray) == 1 ? $adminArray[0].'(后台审核)' : $adminArray[0].''.$adminArray[1].'(后台审核)';
} elseif (!empty($row['examine_wechat_id'])) {
$examineWechatIdArray = explode(',',$row['examine_wechat_id']);
$wechatArray = $userWechatModel->where('id','in',$examineWechatIdArray)->column('nickname');
$row->examine_name = count($wechatArray) == 1 ? $wechatArray[0].'(小程序审核)' : $wechatArray[0].''.$wechatArray[1].'(小程序审核)';
} else {
$row->examin_name = '';
}
} else {
$row->examin_name = '';
}
}
$result = array("total" => $list->total(), "rows" => $list->items());
return json($result);
}
return $this->view->fetch();
}
public function examine($ids = null)
{
return;
}
public function offline_examine($ids = null)
{
return;
}
}

View File

@@ -0,0 +1,113 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh\member\apply;
use app\admin\model\Admin;
use app\admin\model\wdsxh\user\UserWechat;
/**
* 入会申请
*
* @icon fa fa-circle-o
*/
class Organize extends Apply
{
protected $model = null;
protected $noNeedRight = ['examine','offline_examine'];
public function _initialize()
{
parent::_initialize();
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
/**
* 查看
*/
public function index()
{
//当前是否为关联查询
$this->relationSearch = true;
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
if ($this->request->isAjax()) {
//如果发送的来源是Selectpage则转发到Selectpage
if ($this->request->request('keyField')) {
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$list = $this->model
->where('state','in',['1','2','3','4'])
->where('type','3')
->with(['level'])
->where($where)
->order($sort, $order)
->paginate($limit);
$adminModel = new Admin();
$userWechatModel = new UserWechat();
foreach ($list as &$row) {
if (in_array($row['child_state'],array('3','6'))) {
if (!empty($row['examine_admin_id']) && !empty($row['examine_wechat_id'])) {
$adminUserName = $adminModel->where('id',$row['examine_admin_id'])->value('username');
$wechatNickname = $userWechatModel->where('id',$row['examine_wechat_id'])->value('nickname');
if (!empty($adminUserName)) {
$adminUserName = $adminUserName.'(后台审核)';
}
$row->examine_name = $wechatNickname.'(小程序审核)'.$adminUserName;
} elseif (!empty($row['examine_admin_id'])) {
$examineAdminIdArray = explode(',',$row['examine_admin_id']);
$adminArray = $adminModel->where('id','in',$examineAdminIdArray)->column('username');
$row->examine_name = count($adminArray) == 1 ? $adminArray[0].'(后台审核)' : $adminArray[0].''.$adminArray[1].'(后台审核)';
} elseif (!empty($row['examine_wechat_id'])) {
$examineWechatIdArray = explode(',',$row['examine_wechat_id']);
$wechatArray = $userWechatModel->where('id','in',$examineWechatIdArray)->column('nickname');
$row->examine_name = count($wechatArray) == 1 ? $wechatArray[0].'(小程序审核)' : $wechatArray[0].''.$wechatArray[1].'(小程序审核)';
} else {
$row->examin_name = '';
}
} else {
$row->examin_name = '';
}
}
$result = array("total" => $list->total(), "rows" => $list->items());
return json($result);
}
return $this->view->fetch();
}
public function examine($ids = null)
{
return;
}
public function offline_examine($ids = null)
{
return;
}
}

View File

@@ -0,0 +1,133 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh\member\apply;
use app\admin\model\Admin;
use app\admin\model\wdsxh\user\UserWechat;
/**
* 入会申请
*
* @icon fa fa-circle-o
*/
class Person extends Apply
{
protected $model = null;
protected $noNeedRight = ['examine','offline_examine','pass','reject','offline_pass','offline_reject'];
public function _initialize()
{
parent::_initialize();
}
/**
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
*/
/**
* 查看
*/
public function index()
{
//当前是否为关联查询
$this->relationSearch = true;
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
if ($this->request->isAjax()) {
//如果发送的来源是Selectpage则转发到Selectpage
if ($this->request->request('keyField')) {
return $this->selectpage();
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$list = $this->model
->where('state','in',['1','2','3','4'])
->where('type','1')
->with(['level'])
->where($where)
->order($sort, $order)
->paginate($limit);
$adminModel = new Admin();
$userWechatModel = new UserWechat();
foreach ($list as &$row) {
if (in_array($row['child_state'],array('3','6'))) {
if (!empty($row['examine_admin_id']) && !empty($row['examine_wechat_id'])) {
$adminUserName = $adminModel->where('id',$row['examine_admin_id'])->value('username');
$wechatNickname = $userWechatModel->where('id',$row['examine_wechat_id'])->value('nickname');
if (!empty($adminUserName)) {
$adminUserName = $adminUserName.'(后台审核)';
}
$row->examine_name = $wechatNickname.'(小程序审核)'.$adminUserName;
} elseif (!empty($row['examine_admin_id'])) {
$examineAdminIdArray = explode(',',$row['examine_admin_id']);
$adminArray = $adminModel->where('id','in',$examineAdminIdArray)->column('username');
$row->examine_name = count($adminArray) == 1 ? $adminArray[0].'(后台审核)' : $adminArray[0].''.$adminArray[1].'(后台审核)';
} elseif (!empty($row['examine_wechat_id'])) {
$examineWechatIdArray = explode(',',$row['examine_wechat_id']);
$wechatArray = $userWechatModel->where('id','in',$examineWechatIdArray)->column('nickname');
$row->examine_name = count($wechatArray) == 1 ? $wechatArray[0].'(小程序审核)' : $wechatArray[0].''.$wechatArray[1].'(小程序审核)';
} else {
$row->examin_name = '';
}
} else {
$row->examin_name = '';
}
}
$result = array("total" => $list->total(), "rows" => $list->items());
return json($result);
}
return $this->view->fetch();
}
public function examine($ids = null)
{
return;
}
public function offline_examine($ids = null)
{
return;
}
public function pass($row = '',$params = [])
{
return;
}
public function reject($row = '',$params = [])
{
return;
}
public function offline_pass($row = '',$params = [])
{
return;
}
public function offline_reject($row = '',$params = [])
{
return;
}
}