init commit
This commit is contained in:
462
application/admin/controller/Addon.php
Normal file
462
application/admin/controller/Addon.php
Normal file
@@ -0,0 +1,462 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use fast\Http;
|
||||
use think\addons\AddonException;
|
||||
use think\addons\Service;
|
||||
use think\Cache;
|
||||
use think\Config;
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
|
||||
/**
|
||||
* 插件管理
|
||||
*
|
||||
* @icon fa fa-cube
|
||||
* @remark 可在线安装、卸载、禁用、启用、配置、升级插件,插件升级前请做好备份。
|
||||
*/
|
||||
class Addon extends Backend
|
||||
{
|
||||
protected $model = null;
|
||||
protected $noNeedRight = ['get_table_list'];
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
if (!$this->auth->isSuperAdmin() && in_array($this->request->action(), ['install', 'uninstall', 'local', 'upgrade', 'authorization', 'testdata'])) {
|
||||
$this->error(__('Access is allowed only to the super management group'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 插件列表
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$addons = get_addon_list();
|
||||
foreach ($addons as $k => &$v) {
|
||||
$config = get_addon_config($v['name']);
|
||||
$v['config'] = $config ? 1 : 0;
|
||||
$v['url'] = str_replace($this->request->server('SCRIPT_NAME'), '', $v['url']);
|
||||
}
|
||||
$this->assignconfig(['addons' => $addons, 'api_url' => config('fastadmin.api_url'), 'faversion' => config('fastadmin.version'), 'domain' => request()->host(true)]);
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置
|
||||
*/
|
||||
public function config($name = null)
|
||||
{
|
||||
$name = $name ? $name : $this->request->get("name");
|
||||
if (!$name) {
|
||||
$this->error(__('Parameter %s can not be empty', 'name'));
|
||||
}
|
||||
if (!preg_match("/^[a-zA-Z0-9]+$/", $name)) {
|
||||
$this->error(__('Addon name incorrect'));
|
||||
}
|
||||
$info = get_addon_info($name);
|
||||
$config = get_addon_fullconfig($name);
|
||||
if (!$info) {
|
||||
$this->error(__('Addon not exists'));
|
||||
}
|
||||
if ($this->request->isPost()) {
|
||||
$params = $this->request->post("row/a", [], 'trim');
|
||||
if ($params) {
|
||||
foreach ($config as $k => &$v) {
|
||||
if (isset($params[$v['name']])) {
|
||||
if ($v['type'] == 'array') {
|
||||
$params[$v['name']] = is_array($params[$v['name']]) ? $params[$v['name']] : (array)json_decode($params[$v['name']], true);
|
||||
$value = $params[$v['name']];
|
||||
} else {
|
||||
$value = is_array($params[$v['name']]) ? implode(',', $params[$v['name']]) : $params[$v['name']];
|
||||
}
|
||||
$v['value'] = $value;
|
||||
}
|
||||
}
|
||||
try {
|
||||
$addon = get_addon_instance($name);
|
||||
//插件自定义配置实现逻辑
|
||||
if (method_exists($addon, 'config')) {
|
||||
$addon->config($name, $config);
|
||||
} else {
|
||||
//更新配置文件
|
||||
set_addon_fullconfig($name, $config);
|
||||
Service::refresh();
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$this->error(__($e->getMessage()));
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
$this->error(__('Parameter %s can not be empty', ''));
|
||||
}
|
||||
$tips = [];
|
||||
$groupList = [];
|
||||
$ungroupList = [];
|
||||
foreach ($config as $index => &$item) {
|
||||
//如果有设置分组
|
||||
if (isset($item['group']) && $item['group']) {
|
||||
if (!in_array($item['group'], $groupList)) {
|
||||
$groupList["custom" . (count($groupList) + 1)] = $item['group'];
|
||||
}
|
||||
} elseif ($item['name'] != '__tips__') {
|
||||
$ungroupList[] = $item['name'];
|
||||
}
|
||||
if ($item['name'] == '__tips__') {
|
||||
$tips = $item;
|
||||
unset($config[$index]);
|
||||
}
|
||||
}
|
||||
if ($ungroupList) {
|
||||
$groupList['other'] = '其它';
|
||||
}
|
||||
$this->view->assign("groupList", $groupList);
|
||||
$this->view->assign("addon", ['info' => $info, 'config' => $config, 'tips' => $tips]);
|
||||
$configFile = ADDON_PATH . $name . DS . 'config.html';
|
||||
$viewFile = is_file($configFile) ? $configFile : '';
|
||||
return $this->view->fetch($viewFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* 安装
|
||||
*/
|
||||
public function install()
|
||||
{
|
||||
$name = $this->request->post("name");
|
||||
$force = (int)$this->request->post("force");
|
||||
if (!$name) {
|
||||
$this->error(__('Parameter %s can not be empty', 'name'));
|
||||
}
|
||||
if (!preg_match("/^[a-zA-Z0-9]+$/", $name)) {
|
||||
$this->error(__('Addon name incorrect'));
|
||||
}
|
||||
|
||||
$info = [];
|
||||
try {
|
||||
$uid = $this->request->post("uid");
|
||||
$token = $this->request->post("token");
|
||||
$version = $this->request->post("version");
|
||||
$faversion = $this->request->post("faversion");
|
||||
$extend = [
|
||||
'uid' => $uid,
|
||||
'token' => $token,
|
||||
'version' => $version,
|
||||
'faversion' => $faversion
|
||||
];
|
||||
$info = Service::install($name, $force, $extend);
|
||||
} catch (AddonException $e) {
|
||||
$this->result($e->getData(), $e->getCode(), __($e->getMessage()));
|
||||
} catch (Exception $e) {
|
||||
$this->error(__($e->getMessage()), $e->getCode());
|
||||
}
|
||||
$this->success(__('Install successful'), '', ['addon' => $info]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 卸载
|
||||
*/
|
||||
public function uninstall()
|
||||
{
|
||||
$name = $this->request->post("name");
|
||||
$force = (int)$this->request->post("force");
|
||||
$droptables = (int)$this->request->post("droptables");
|
||||
if (!$name) {
|
||||
$this->error(__('Parameter %s can not be empty', 'name'));
|
||||
}
|
||||
if (!preg_match("/^[a-zA-Z0-9]+$/", $name)) {
|
||||
$this->error(__('Addon name incorrect'));
|
||||
}
|
||||
//只有开启调试且为超级管理员才允许删除相关数据库
|
||||
$tables = [];
|
||||
if ($droptables && Config::get("app_debug") && $this->auth->isSuperAdmin()) {
|
||||
$tables = get_addon_tables($name);
|
||||
}
|
||||
try {
|
||||
Service::uninstall($name, $force);
|
||||
if ($tables) {
|
||||
$prefix = Config::get('database.prefix');
|
||||
//删除插件关联表
|
||||
foreach ($tables as $index => $table) {
|
||||
//忽略非插件标识的表名
|
||||
if (!preg_match("/^{$prefix}{$name}/", $table)) {
|
||||
continue;
|
||||
}
|
||||
Db::execute("DROP TABLE IF EXISTS `{$table}`");
|
||||
}
|
||||
}
|
||||
} catch (AddonException $e) {
|
||||
$this->result($e->getData(), $e->getCode(), __($e->getMessage()));
|
||||
} catch (Exception $e) {
|
||||
$this->error(__($e->getMessage()));
|
||||
}
|
||||
$this->success(__('Uninstall successful'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 禁用启用
|
||||
*/
|
||||
public function state()
|
||||
{
|
||||
$name = $this->request->post("name");
|
||||
$action = $this->request->post("action");
|
||||
$force = (int)$this->request->post("force");
|
||||
if (!$name) {
|
||||
$this->error(__('Parameter %s can not be empty', 'name'));
|
||||
}
|
||||
if (!preg_match("/^[a-zA-Z0-9]+$/", $name)) {
|
||||
$this->error(__('Addon name incorrect'));
|
||||
}
|
||||
try {
|
||||
$action = $action == 'enable' ? $action : 'disable';
|
||||
//调用启用、禁用的方法
|
||||
Service::$action($name, $force);
|
||||
Cache::rm('__menu__');
|
||||
} catch (AddonException $e) {
|
||||
$this->result($e->getData(), $e->getCode(), __($e->getMessage()));
|
||||
} catch (Exception $e) {
|
||||
$this->error(__($e->getMessage()));
|
||||
}
|
||||
$this->success(__('Operate successful'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 本地上传
|
||||
*/
|
||||
public function local()
|
||||
{
|
||||
Config::set('default_return_type', 'json');
|
||||
|
||||
$info = [];
|
||||
$file = $this->request->file('file');
|
||||
try {
|
||||
$uid = $this->request->post("uid");
|
||||
$token = $this->request->post("token");
|
||||
$faversion = $this->request->post("faversion");
|
||||
$force = $this->request->post("force");
|
||||
if (!$uid || !$token) {
|
||||
throw new Exception(__('Please login and try to install'));
|
||||
}
|
||||
$extend = [
|
||||
'uid' => $uid,
|
||||
'token' => $token,
|
||||
'faversion' => $faversion
|
||||
];
|
||||
$info = Service::local($file, $extend, $force);
|
||||
} catch (AddonException $e) {
|
||||
$this->result($e->getData(), $e->getCode(), __($e->getMessage()));
|
||||
} catch (Exception $e) {
|
||||
$this->error(__($e->getMessage()));
|
||||
}
|
||||
$this->success(__('Offline installed tips'), '', ['addon' => $info]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新插件
|
||||
*/
|
||||
public function upgrade()
|
||||
{
|
||||
$name = $this->request->post("name");
|
||||
$addonTmpDir = RUNTIME_PATH . 'addons' . DS;
|
||||
if (!$name) {
|
||||
$this->error(__('Parameter %s can not be empty', 'name'));
|
||||
}
|
||||
if (!preg_match("/^[a-zA-Z0-9]+$/", $name)) {
|
||||
$this->error(__('Addon name incorrect'));
|
||||
}
|
||||
if (!is_dir($addonTmpDir)) {
|
||||
@mkdir($addonTmpDir, 0755, true);
|
||||
}
|
||||
|
||||
$info = [];
|
||||
try {
|
||||
$info = get_addon_info($name);
|
||||
$uid = $this->request->post("uid");
|
||||
$token = $this->request->post("token");
|
||||
$version = $this->request->post("version");
|
||||
$faversion = $this->request->post("faversion");
|
||||
$extend = [
|
||||
'uid' => $uid,
|
||||
'token' => $token,
|
||||
'version' => $version,
|
||||
'oldversion' => $info['version'] ?? '',
|
||||
'faversion' => $faversion
|
||||
];
|
||||
//调用更新的方法
|
||||
$info = Service::upgrade($name, $extend);
|
||||
Cache::rm('__menu__');
|
||||
} catch (AddonException $e) {
|
||||
$this->result($e->getData(), $e->getCode(), __($e->getMessage()));
|
||||
} catch (Exception $e) {
|
||||
$this->error(__($e->getMessage()));
|
||||
}
|
||||
$this->success(__('Operate successful'), '', ['addon' => $info]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试数据
|
||||
*/
|
||||
public function testdata()
|
||||
{
|
||||
$name = $this->request->post("name");
|
||||
if (!$name) {
|
||||
$this->error(__('Parameter %s can not be empty', 'name'));
|
||||
}
|
||||
if (!preg_match("/^[a-zA-Z0-9]+$/", $name)) {
|
||||
$this->error(__('Addon name incorrect'));
|
||||
}
|
||||
|
||||
try {
|
||||
Service::importsql($name, 'testdata.sql');
|
||||
} catch (AddonException $e) {
|
||||
$this->result($e->getData(), $e->getCode(), __($e->getMessage()));
|
||||
} catch (Exception $e) {
|
||||
$this->error(__($e->getMessage()), $e->getCode());
|
||||
}
|
||||
$this->success(__('Import successful'), '');
|
||||
}
|
||||
|
||||
/**
|
||||
* 已装插件
|
||||
*/
|
||||
public function downloaded()
|
||||
{
|
||||
$offset = (int)$this->request->get("offset");
|
||||
$limit = (int)$this->request->get("limit");
|
||||
$filter = $this->request->get("filter", '');
|
||||
$search = $this->request->get("search", '', 'strip_tags,htmlspecialchars');
|
||||
$onlineaddons = $this->getAddonList();
|
||||
$filter = (array)json_decode($filter, true);
|
||||
$addons = get_addon_list();
|
||||
$list = [];
|
||||
foreach ($addons as $k => $v) {
|
||||
if ($search && stripos($v['name'], $search) === false && stripos($v['title'], $search) === false && stripos($v['intro'], $search) === false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isset($onlineaddons[$v['name']])) {
|
||||
$v = array_merge($v, $onlineaddons[$v['name']]);
|
||||
$v['price'] = '-';
|
||||
} else {
|
||||
$v['category_id'] = 0;
|
||||
$v['flag'] = '';
|
||||
$v['banner'] = '';
|
||||
$v['image'] = '';
|
||||
$v['demourl'] = '';
|
||||
$v['price'] = __('None');
|
||||
$v['screenshots'] = [];
|
||||
$v['releaselist'] = [];
|
||||
$v['url'] = addon_url($v['name']);
|
||||
$v['url'] = str_replace($this->request->server('SCRIPT_NAME'), '', $v['url']);
|
||||
}
|
||||
$v['createtime'] = filemtime(ADDON_PATH . $v['name']);
|
||||
if ($filter && isset($filter['category_id']) && is_numeric($filter['category_id']) && $filter['category_id'] != $v['category_id']) {
|
||||
continue;
|
||||
}
|
||||
$list[] = $v;
|
||||
}
|
||||
$total = count($list);
|
||||
if ($limit) {
|
||||
$list = array_slice($list, $offset, $limit);
|
||||
}
|
||||
$result = array("total" => $total, "rows" => $list);
|
||||
|
||||
$callback = $this->request->get('callback') ? "jsonp" : "json";
|
||||
return $callback($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测
|
||||
*/
|
||||
public function isbuy()
|
||||
{
|
||||
$name = $this->request->post("name");
|
||||
$uid = $this->request->post("uid");
|
||||
$token = $this->request->post("token");
|
||||
$version = $this->request->post("version");
|
||||
$faversion = $this->request->post("faversion");
|
||||
$extend = [
|
||||
'uid' => $uid,
|
||||
'token' => $token,
|
||||
'version' => $version,
|
||||
'faversion' => $faversion
|
||||
];
|
||||
try {
|
||||
$result = Service::isBuy($name, $extend);
|
||||
} catch (Exception $e) {
|
||||
$this->error(__($e->getMessage()));
|
||||
}
|
||||
return json($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新授权
|
||||
*/
|
||||
public function authorization()
|
||||
{
|
||||
$params = [
|
||||
'uid' => $this->request->post('uid'),
|
||||
'token' => $this->request->post('token'),
|
||||
'faversion' => $this->request->post('faversion'),
|
||||
];
|
||||
try {
|
||||
Service::authorization($params);
|
||||
} catch (Exception $e) {
|
||||
$this->error(__($e->getMessage()));
|
||||
}
|
||||
$this->success(__('Operate successful'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取插件相关表
|
||||
*/
|
||||
public function get_table_list()
|
||||
{
|
||||
$name = $this->request->post("name");
|
||||
if (!preg_match("/^[a-zA-Z0-9]+$/", $name)) {
|
||||
$this->error(__('Addon name incorrect'));
|
||||
}
|
||||
$tables = get_addon_tables($name);
|
||||
$prefix = Config::get('database.prefix');
|
||||
foreach ($tables as $index => $table) {
|
||||
//忽略非插件标识的表名
|
||||
if (!preg_match("/^{$prefix}{$name}/", $table)) {
|
||||
unset($tables[$index]);
|
||||
}
|
||||
}
|
||||
$tables = array_values($tables);
|
||||
$this->success('', null, ['tables' => $tables]);
|
||||
}
|
||||
|
||||
protected function getAddonList()
|
||||
{
|
||||
$onlineaddons = Cache::get("onlineaddons");
|
||||
if (!is_array($onlineaddons) && config('fastadmin.api_url')) {
|
||||
$onlineaddons = [];
|
||||
$params = [
|
||||
'uid' => $this->request->post('uid'),
|
||||
'token' => $this->request->post('token'),
|
||||
'version' => config('fastadmin.version'),
|
||||
'faversion' => config('fastadmin.version'),
|
||||
];
|
||||
$json = [];
|
||||
try {
|
||||
$json = Service::addons($params);
|
||||
} catch (\Exception $e) {
|
||||
|
||||
}
|
||||
$rows = $json['rows'] ?? [];
|
||||
foreach ($rows as $index => $row) {
|
||||
if (!isset($row['name'])) {
|
||||
continue;
|
||||
}
|
||||
$onlineaddons[$row['name']] = $row;
|
||||
}
|
||||
Cache::set("onlineaddons", $onlineaddons, 600);
|
||||
}
|
||||
return $onlineaddons;
|
||||
}
|
||||
|
||||
}
|
||||
315
application/admin/controller/Ajax.php
Normal file
315
application/admin/controller/Ajax.php
Normal file
@@ -0,0 +1,315 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use app\common\exception\UploadException;
|
||||
use app\common\library\Upload;
|
||||
use fast\Random;
|
||||
use think\addons\Service;
|
||||
use think\Cache;
|
||||
use think\Config;
|
||||
use think\Db;
|
||||
use think\Lang;
|
||||
use think\Response;
|
||||
use think\Validate;
|
||||
|
||||
/**
|
||||
* Ajax异步请求接口
|
||||
* @internal
|
||||
*/
|
||||
class Ajax extends Backend
|
||||
{
|
||||
|
||||
protected $noNeedLogin = ['lang'];
|
||||
protected $noNeedRight = ['*'];
|
||||
protected $layout = '';
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
|
||||
//设置过滤方法
|
||||
$this->request->filter(['trim', 'strip_tags', 'htmlspecialchars']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载语言包
|
||||
*/
|
||||
public function lang()
|
||||
{
|
||||
$this->request->get(['callback' => 'define']);
|
||||
$header = ['Content-Type' => 'application/javascript'];
|
||||
if (!config('app_debug')) {
|
||||
$offset = 30 * 60 * 60 * 24; // 缓存一个月
|
||||
$header['Cache-Control'] = 'public';
|
||||
$header['Pragma'] = 'cache';
|
||||
$header['Expires'] = gmdate("D, d M Y H:i:s", time() + $offset) . " GMT";
|
||||
}
|
||||
|
||||
$controllername = input("controllername");
|
||||
//默认只加载了控制器对应的语言名,你还根据控制器名来加载额外的语言包
|
||||
$this->loadlang($controllername);
|
||||
return jsonp(Lang::get(), 200, $header, ['json_encode_param' => JSON_FORCE_OBJECT | JSON_UNESCAPED_UNICODE]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
*/
|
||||
public function upload()
|
||||
{
|
||||
Config::set('default_return_type', 'json');
|
||||
|
||||
//必须还原upload配置,否则分片及cdnurl函数计算错误
|
||||
Config::load(APP_PATH . 'extra/upload.php', 'upload');
|
||||
|
||||
$chunkid = $this->request->post("chunkid");
|
||||
if ($chunkid) {
|
||||
if (!Config::get('upload.chunking')) {
|
||||
$this->error(__('Chunk file disabled'));
|
||||
}
|
||||
$action = $this->request->post("action");
|
||||
$chunkindex = $this->request->post("chunkindex/d");
|
||||
$chunkcount = $this->request->post("chunkcount/d");
|
||||
$filename = $this->request->post("filename");
|
||||
$method = $this->request->method(true);
|
||||
if ($action == 'merge') {
|
||||
$attachment = null;
|
||||
//合并分片文件
|
||||
try {
|
||||
$upload = new Upload();
|
||||
$attachment = $upload->merge($chunkid, $chunkcount, $filename);
|
||||
} catch (UploadException $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$this->success(__('Uploaded successful'), '', ['url' => $attachment->url, 'fullurl' => cdnurl($attachment->url, true)]);
|
||||
} elseif ($method == 'clean') {
|
||||
//删除冗余的分片文件
|
||||
try {
|
||||
$upload = new Upload();
|
||||
$upload->clean($chunkid);
|
||||
} catch (UploadException $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$this->success();
|
||||
} else {
|
||||
//上传分片文件
|
||||
//默认普通上传文件
|
||||
$file = $this->request->file('file');
|
||||
try {
|
||||
$upload = new Upload($file);
|
||||
$upload->chunk($chunkid, $chunkindex, $chunkcount);
|
||||
} catch (UploadException $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
} else {
|
||||
$attachment = null;
|
||||
//默认普通上传文件
|
||||
$file = $this->request->file('file');
|
||||
try {
|
||||
$upload = new Upload($file);
|
||||
$attachment = $upload->upload();
|
||||
} catch (UploadException $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
|
||||
$this->success(__('Uploaded successful'), '', ['url' => $attachment->url, 'fullurl' => cdnurl($attachment->url, true)]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用排序
|
||||
*/
|
||||
public function weigh()
|
||||
{
|
||||
//排序的数组
|
||||
$ids = $this->request->post("ids");
|
||||
//拖动的记录ID
|
||||
$changeid = $this->request->post("changeid");
|
||||
//操作字段
|
||||
$field = $this->request->post("field");
|
||||
//操作的数据表
|
||||
$table = $this->request->post("table");
|
||||
if (!Validate::is($table, "alphaDash")) {
|
||||
$this->error();
|
||||
}
|
||||
//主键
|
||||
$pk = $this->request->post("pk");
|
||||
//排序的方式
|
||||
$orderway = strtolower($this->request->post("orderway", ""));
|
||||
$orderway = $orderway == 'asc' ? 'ASC' : 'DESC';
|
||||
$sour = $weighdata = [];
|
||||
$ids = explode(',', $ids);
|
||||
$prikey = $pk && preg_match("/^[a-z0-9\-_]+$/i", $pk) ? $pk : (Db::name($table)->getPk() ?: 'id');
|
||||
$pid = $this->request->post("pid", "");
|
||||
//限制更新的字段
|
||||
$field = in_array($field, ['weigh']) ? $field : 'weigh';
|
||||
|
||||
// 如果设定了pid的值,此时只匹配满足条件的ID,其它忽略
|
||||
if ($pid !== '') {
|
||||
$hasids = [];
|
||||
$list = Db::name($table)->where($prikey, 'in', $ids)->where('pid', 'in', $pid)->field("{$prikey},pid")->select();
|
||||
foreach ($list as $k => $v) {
|
||||
$hasids[] = $v[$prikey];
|
||||
}
|
||||
$ids = array_values(array_intersect($ids, $hasids));
|
||||
}
|
||||
|
||||
$list = Db::name($table)->field("$prikey,$field")->where($prikey, 'in', $ids)->order($field, $orderway)->select();
|
||||
foreach ($list as $k => $v) {
|
||||
$sour[] = $v[$prikey];
|
||||
$weighdata[$v[$prikey]] = $v[$field];
|
||||
}
|
||||
$position = array_search($changeid, $ids);
|
||||
$desc_id = isset($sour[$position]) ? $sour[$position] : end($sour); //移动到目标的ID值,取出所处改变前位置的值
|
||||
$sour_id = $changeid;
|
||||
$weighids = array();
|
||||
$temp = array_values(array_diff_assoc($ids, $sour));
|
||||
foreach ($temp as $m => $n) {
|
||||
if ($n == $sour_id) {
|
||||
$offset = $desc_id;
|
||||
} else {
|
||||
if ($sour_id == $temp[0]) {
|
||||
$offset = isset($temp[$m + 1]) ? $temp[$m + 1] : $sour_id;
|
||||
} else {
|
||||
$offset = isset($temp[$m - 1]) ? $temp[$m - 1] : $sour_id;
|
||||
}
|
||||
}
|
||||
if (!isset($weighdata[$offset])) {
|
||||
continue;
|
||||
}
|
||||
$weighids[$n] = $weighdata[$offset];
|
||||
Db::name($table)->where($prikey, $n)->update([$field => $weighdata[$offset]]);
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空系统缓存
|
||||
*/
|
||||
public function wipecache()
|
||||
{
|
||||
try {
|
||||
$type = $this->request->request("type");
|
||||
switch ($type) {
|
||||
case 'all':
|
||||
// no break
|
||||
case 'content':
|
||||
//内容缓存
|
||||
rmdirs(CACHE_PATH, false);
|
||||
Cache::clear();
|
||||
if ($type == 'content') {
|
||||
break;
|
||||
}
|
||||
case 'template':
|
||||
// 模板缓存
|
||||
rmdirs(TEMP_PATH, false);
|
||||
if ($type == 'template') {
|
||||
break;
|
||||
}
|
||||
case 'addons':
|
||||
// 插件缓存
|
||||
Service::refresh();
|
||||
if ($type == 'addons') {
|
||||
break;
|
||||
}
|
||||
case 'browser':
|
||||
// 浏览器缓存
|
||||
// 只有生产环境下才修改
|
||||
if (!config('app_debug')) {
|
||||
$version = config('site.version');
|
||||
$newversion = preg_replace_callback("/(.*)\.([0-9]+)\$/", function ($match) {
|
||||
return $match[1] . '.' . ($match[2] + 1);
|
||||
}, $version);
|
||||
if ($newversion && $newversion != $version) {
|
||||
Db::startTrans();
|
||||
try {
|
||||
\app\common\model\Config::where('name', 'version')->update(['value' => $newversion]);
|
||||
\app\common\model\Config::refreshFile();
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
exception($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($type == 'browser') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
|
||||
\think\Hook::listen("wipecache_after");
|
||||
$this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取分类数据,联动列表
|
||||
*/
|
||||
public function category()
|
||||
{
|
||||
$type = $this->request->get('type', '');
|
||||
$pid = $this->request->get('pid', '');
|
||||
$where = ['status' => 'normal'];
|
||||
$categorylist = null;
|
||||
if ($pid || $pid === '0') {
|
||||
$where['pid'] = $pid;
|
||||
}
|
||||
if ($type) {
|
||||
$where['type'] = $type;
|
||||
}
|
||||
|
||||
$categorylist = Db::name('category')->where($where)->field('id as value,name')->order('weigh desc,id desc')->select();
|
||||
|
||||
$this->success('', '', $categorylist);
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取省市区数据,联动列表
|
||||
*/
|
||||
public function area()
|
||||
{
|
||||
$params = $this->request->get("row/a");
|
||||
if (!empty($params)) {
|
||||
$province = isset($params['province']) ? $params['province'] : null;
|
||||
$city = isset($params['city']) ? $params['city'] : null;
|
||||
} else {
|
||||
$province = $this->request->get('province');
|
||||
$city = $this->request->get('city');
|
||||
}
|
||||
$where = ['pid' => 0, 'level' => 1];
|
||||
$provincelist = null;
|
||||
if ($province !== null) {
|
||||
$where['pid'] = $province;
|
||||
$where['level'] = 2;
|
||||
if ($city !== null) {
|
||||
$where['pid'] = $city;
|
||||
$where['level'] = 3;
|
||||
}
|
||||
}
|
||||
$provincelist = Db::name('area')->where($where)->field('id as value,name')->select();
|
||||
$this->success('', '', $provincelist);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成后缀图标
|
||||
*/
|
||||
public function icon()
|
||||
{
|
||||
$suffix = $this->request->request("suffix");
|
||||
$suffix = $suffix ? $suffix : "FILE";
|
||||
$data = build_suffix_image($suffix);
|
||||
$header = ['Content-Type' => 'image/svg+xml'];
|
||||
$offset = 30 * 60 * 60 * 24; // 缓存一个月
|
||||
$header['Cache-Control'] = 'public';
|
||||
$header['Pragma'] = 'cache';
|
||||
$header['Expires'] = gmdate("D, d M Y H:i:s", time() + $offset) . " GMT";
|
||||
$response = Response::create($data, '', 200, $header);
|
||||
return $response;
|
||||
}
|
||||
|
||||
}
|
||||
158
application/admin/controller/Category.php
Normal file
158
application/admin/controller/Category.php
Normal file
@@ -0,0 +1,158 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use app\common\model\Category as CategoryModel;
|
||||
use fast\Tree;
|
||||
|
||||
/**
|
||||
* 分类管理
|
||||
*
|
||||
* @icon fa fa-list
|
||||
* @remark 用于管理网站的所有分类,分类可进行无限级分类,分类类型请在常规管理->系统配置->字典配置中添加
|
||||
*/
|
||||
class Category extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* @var \app\common\model\Category
|
||||
*/
|
||||
protected $model = null;
|
||||
protected $categorylist = [];
|
||||
protected $noNeedRight = ['selectpage'];
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = model('app\common\model\Category');
|
||||
|
||||
$tree = Tree::instance();
|
||||
$tree->init(collection($this->model->order('weigh desc,id desc')->select())->toArray(), 'pid');
|
||||
$this->categorylist = $tree->getTreeList($tree->getTreeArray(0), 'name');
|
||||
$categorydata = [0 => ['type' => 'all', 'name' => __('None')]];
|
||||
foreach ($this->categorylist as $k => $v) {
|
||||
$categorydata[$v['id']] = $v;
|
||||
}
|
||||
$typeList = CategoryModel::getTypeList();
|
||||
$this->view->assign("flagList", $this->model->getFlagList());
|
||||
$this->view->assign("typeList", $typeList);
|
||||
$this->view->assign("parentList", $categorydata);
|
||||
$this->assignconfig('typeList', $typeList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//设置过滤方法
|
||||
$this->request->filter(['strip_tags']);
|
||||
if ($this->request->isAjax()) {
|
||||
$search = $this->request->request("search");
|
||||
$type = $this->request->request("type");
|
||||
|
||||
//构造父类select列表选项数据
|
||||
$list = [];
|
||||
|
||||
foreach ($this->categorylist as $k => $v) {
|
||||
if ($search) {
|
||||
if ($v['type'] == $type && stripos($v['name'], $search) !== false || stripos($v['nickname'], $search) !== false) {
|
||||
if ($type == "all" || $type == null) {
|
||||
$list = $this->categorylist;
|
||||
} else {
|
||||
$list[] = $v;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($type == "all" || $type == null) {
|
||||
$list = $this->categorylist;
|
||||
} elseif ($v['type'] == $type) {
|
||||
$list[] = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$total = count($list);
|
||||
$result = array("total" => $total, "rows" => $list);
|
||||
|
||||
return json($result);
|
||||
}
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$this->token();
|
||||
}
|
||||
return parent::add();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
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)) {
|
||||
if (!in_array($row[$this->dataLimitField], $adminIds)) {
|
||||
$this->error(__('You have no permission'));
|
||||
}
|
||||
}
|
||||
if ($this->request->isPost()) {
|
||||
$this->token();
|
||||
$params = $this->request->post("row/a");
|
||||
if ($params) {
|
||||
$params = $this->preExcludeFields($params);
|
||||
|
||||
if ($params['pid'] != $row['pid']) {
|
||||
$childrenIds = Tree::instance()->init(collection(\app\common\model\Category::select())->toArray())->getChildrenIds($row['id'], true);
|
||||
if (in_array($params['pid'], $childrenIds)) {
|
||||
$this->error(__('Can not change the parent to child or itself'));
|
||||
}
|
||||
}
|
||||
|
||||
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->validate($validate);
|
||||
}
|
||||
$result = $row->allowField(true)->save($params);
|
||||
if ($result !== false) {
|
||||
$this->success();
|
||||
} else {
|
||||
$this->error($row->getError());
|
||||
}
|
||||
} catch (\think\exception\PDOException $e) {
|
||||
$this->error($e->getMessage());
|
||||
} catch (\think\Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
$this->error(__('Parameter %s can not be empty', ''));
|
||||
}
|
||||
$this->view->assign("row", $row);
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Selectpage搜索
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public function selectpage()
|
||||
{
|
||||
return parent::selectpage();
|
||||
}
|
||||
}
|
||||
84
application/admin/controller/Dashboard.php
Normal file
84
application/admin/controller/Dashboard.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\admin\model\Admin;
|
||||
use app\admin\model\User;
|
||||
use app\common\controller\Backend;
|
||||
use app\common\model\Attachment;
|
||||
use fast\Date;
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* 控制台
|
||||
*
|
||||
* @icon fa fa-dashboard
|
||||
* @remark 用于展示当前系统中的统计数据、统计报表及重要实时数据
|
||||
*/
|
||||
class Dashboard extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* 查看
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
try {
|
||||
\think\Db::execute("SET @@sql_mode='';");
|
||||
} catch (\Exception $e) {
|
||||
|
||||
}
|
||||
$column = [];
|
||||
$starttime = Date::unixtime('day', -6);
|
||||
$endtime = Date::unixtime('day', 0, 'end');
|
||||
$joinlist = Db("user")->where('jointime', 'between time', [$starttime, $endtime])
|
||||
->field('jointime, status, COUNT(*) AS nums, DATE_FORMAT(FROM_UNIXTIME(jointime), "%Y-%m-%d") AS join_date')
|
||||
->group('join_date')
|
||||
->select();
|
||||
for ($time = $starttime; $time <= $endtime;) {
|
||||
$column[] = date("Y-m-d", $time);
|
||||
$time += 86400;
|
||||
}
|
||||
$userlist = array_fill_keys($column, 0);
|
||||
foreach ($joinlist as $k => $v) {
|
||||
$userlist[$v['join_date']] = $v['nums'];
|
||||
}
|
||||
|
||||
$dbTableList = Db::query("SHOW TABLE STATUS");
|
||||
$addonList = get_addon_list();
|
||||
$totalworkingaddon = 0;
|
||||
$totaladdon = count($addonList);
|
||||
foreach ($addonList as $index => $item) {
|
||||
if ($item['state']) {
|
||||
$totalworkingaddon += 1;
|
||||
}
|
||||
}
|
||||
$this->view->assign([
|
||||
'totaluser' => User::count(),
|
||||
'totaladdon' => $totaladdon,
|
||||
'totaladmin' => Admin::count(),
|
||||
'totalcategory' => \app\common\model\Category::count(),
|
||||
'todayusersignup' => User::whereTime('jointime', 'today')->count(),
|
||||
'todayuserlogin' => User::whereTime('logintime', 'today')->count(),
|
||||
'sevendau' => User::whereTime('jointime|logintime|prevtime', '-7 days')->count(),
|
||||
'thirtydau' => User::whereTime('jointime|logintime|prevtime', '-30 days')->count(),
|
||||
'threednu' => User::whereTime('jointime', '-3 days')->count(),
|
||||
'sevendnu' => User::whereTime('jointime', '-7 days')->count(),
|
||||
'dbtablenums' => count($dbTableList),
|
||||
'dbsize' => array_sum(array_map(function ($item) {
|
||||
return $item['Data_length'] + $item['Index_length'];
|
||||
}, $dbTableList)),
|
||||
'totalworkingaddon' => $totalworkingaddon,
|
||||
'attachmentnums' => Attachment::count(),
|
||||
'attachmentsize' => Attachment::sum('filesize'),
|
||||
'picturenums' => Attachment::where('mimetype', 'like', 'image/%')->count(),
|
||||
'picturesize' => Attachment::where('mimetype', 'like', 'image/%')->sum('filesize'),
|
||||
]);
|
||||
|
||||
$this->assignconfig('column', array_keys($userlist));
|
||||
$this->assignconfig('userdata', array_values($userlist));
|
||||
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
}
|
||||
141
application/admin/controller/Index.php
Normal file
141
application/admin/controller/Index.php
Normal file
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\admin\model\AdminLog;
|
||||
use app\common\controller\Backend;
|
||||
use think\Config;
|
||||
use think\Hook;
|
||||
use think\Session;
|
||||
use think\Validate;
|
||||
|
||||
/**
|
||||
* 后台首页
|
||||
* @internal
|
||||
*/
|
||||
class Index extends Backend
|
||||
{
|
||||
|
||||
protected $noNeedLogin = ['login'];
|
||||
protected $noNeedRight = ['index', 'logout'];
|
||||
protected $layout = '';
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
//移除HTML标签
|
||||
$this->request->filter('trim,strip_tags,htmlspecialchars');
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台首页
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$cookieArr = ['adminskin' => "/^skin\-([a-z\-]+)\$/i", 'multiplenav' => "/^(0|1)\$/", 'multipletab' => "/^(0|1)\$/", 'show_submenu' => "/^(0|1)\$/"];
|
||||
foreach ($cookieArr as $key => $regex) {
|
||||
$cookieValue = $this->request->cookie($key);
|
||||
if (!is_null($cookieValue) && preg_match($regex, $cookieValue)) {
|
||||
config('fastadmin.' . $key, $cookieValue);
|
||||
}
|
||||
}
|
||||
//左侧菜单
|
||||
list($menulist, $navlist, $fixedmenu, $referermenu) = $this->auth->getSidebar([
|
||||
'dashboard' => 'hot',
|
||||
'addon' => ['new', 'red', 'badge'],
|
||||
'auth/rule' => __('Menu'),
|
||||
], $this->view->site['fixedpage']);
|
||||
$action = $this->request->request('action');
|
||||
if ($this->request->isPost()) {
|
||||
if ($action == 'refreshmenu') {
|
||||
$this->success('', null, ['menulist' => $menulist, 'navlist' => $navlist]);
|
||||
}
|
||||
}
|
||||
$this->assignconfig('cookie', ['prefix' => config('cookie.prefix')]);
|
||||
$this->view->assign('menulist', $menulist);
|
||||
$this->view->assign('navlist', $navlist);
|
||||
$this->view->assign('fixedmenu', $fixedmenu);
|
||||
$this->view->assign('referermenu', $referermenu);
|
||||
$this->view->assign('title', __('Home'));
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理员登录
|
||||
*/
|
||||
public function login()
|
||||
{
|
||||
$url = $this->request->get('url', '', 'url_clean');
|
||||
$url = $url ?: 'index/index';
|
||||
if ($this->auth->isLogin()) {
|
||||
$this->success(__("You've logged in, do not login again"), $url);
|
||||
}
|
||||
//保持会话有效时长,单位:小时
|
||||
$keeyloginhours = 24;
|
||||
if ($this->request->isPost()) {
|
||||
$username = $this->request->post('username');
|
||||
$password = $this->request->post('password', '', null);
|
||||
$keeplogin = $this->request->post('keeplogin');
|
||||
$token = $this->request->post('__token__');
|
||||
$rule = [
|
||||
'username' => 'require|length:3,30',
|
||||
'password' => 'require|length:3,30',
|
||||
'__token__' => 'require|token',
|
||||
];
|
||||
$data = [
|
||||
'username' => $username,
|
||||
'password' => $password,
|
||||
'__token__' => $token,
|
||||
];
|
||||
if (Config::get('fastadmin.login_captcha')) {
|
||||
$rule['captcha'] = 'require|captcha';
|
||||
$data['captcha'] = $this->request->post('captcha');
|
||||
}
|
||||
$validate = new Validate($rule, [], ['username' => __('Username'), 'password' => __('Password'), 'captcha' => __('Captcha')]);
|
||||
$result = $validate->check($data);
|
||||
if (!$result) {
|
||||
$this->error($validate->getError(), $url, ['token' => $this->request->token()]);
|
||||
}
|
||||
AdminLog::setTitle(__('Login'));
|
||||
$result = $this->auth->login($username, $password, $keeplogin ? $keeyloginhours * 3600 : 0);
|
||||
if ($result === true) {
|
||||
Hook::listen("admin_login_after", $this->request);
|
||||
$this->success(__('Login successful'), $url, ['url' => $url, 'id' => $this->auth->id, 'username' => $username, 'avatar' => $this->auth->avatar]);
|
||||
} else {
|
||||
$msg = $this->auth->getError();
|
||||
$msg = $msg ? $msg : __('Username or password is incorrect');
|
||||
$this->error($msg, $url, ['token' => $this->request->token()]);
|
||||
}
|
||||
}
|
||||
|
||||
// 根据客户端的cookie,判断是否可以自动登录
|
||||
if ($this->auth->autologin()) {
|
||||
Session::delete("referer");
|
||||
$this->redirect($url);
|
||||
}
|
||||
$background = Config::get('fastadmin.login_background');
|
||||
$background = $background ? (stripos($background, 'http') === 0 ? $background : config('site.cdnurl') . $background) : '';
|
||||
$this->view->assign('keeyloginhours', $keeyloginhours);
|
||||
$this->view->assign('background', $background);
|
||||
$this->view->assign('title', __('Login'));
|
||||
Hook::listen("admin_login_init", $this->request);
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登录
|
||||
*/
|
||||
public function logout()
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$this->auth->logout();
|
||||
Hook::listen("admin_logout_after", $this->request);
|
||||
$this->success(__('Logout successful'), 'index/login');
|
||||
}
|
||||
$html = "<form id='logout_submit' name='logout_submit' action='' method='post'>" . token() . "<input type='submit' value='ok' style='display:none;'></form>";
|
||||
$html .= "<script>document.forms['logout_submit'].submit();</script>";
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
}
|
||||
297
application/admin/controller/auth/Admin.php
Normal file
297
application/admin/controller/auth/Admin.php
Normal file
@@ -0,0 +1,297 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\auth;
|
||||
|
||||
use app\admin\model\AuthGroup;
|
||||
use app\admin\model\AuthGroupAccess;
|
||||
use app\common\controller\Backend;
|
||||
use fast\Random;
|
||||
use fast\Tree;
|
||||
use think\Db;
|
||||
use think\Validate;
|
||||
|
||||
/**
|
||||
* 管理员管理
|
||||
*
|
||||
* @icon fa fa-users
|
||||
* @remark 一个管理员可以有多个角色组,左侧的菜单根据管理员所拥有的权限进行生成
|
||||
*/
|
||||
class Admin extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* @var \app\admin\model\Admin
|
||||
*/
|
||||
protected $model = null;
|
||||
protected $selectpageFields = 'id,username,nickname,avatar';
|
||||
protected $searchFields = 'id,username,nickname';
|
||||
protected $childrenGroupIds = [];
|
||||
protected $childrenAdminIds = [];
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = model('Admin');
|
||||
|
||||
$this->childrenAdminIds = $this->auth->getChildrenAdminIds($this->auth->isSuperAdmin());
|
||||
$this->childrenGroupIds = $this->auth->getChildrenGroupIds($this->auth->isSuperAdmin());
|
||||
|
||||
$groupList = collection(AuthGroup::where('id', 'in', $this->childrenGroupIds)->select())->toArray();
|
||||
|
||||
Tree::instance()->init($groupList);
|
||||
$groupdata = [];
|
||||
if ($this->auth->isSuperAdmin()) {
|
||||
$result = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0));
|
||||
foreach ($result as $k => $v) {
|
||||
$groupdata[$v['id']] = $v['name'];
|
||||
}
|
||||
} else {
|
||||
$result = [];
|
||||
$groups = $this->auth->getGroups();
|
||||
foreach ($groups as $m => $n) {
|
||||
$childlist = Tree::instance()->getTreeList(Tree::instance()->getTreeArray($n['id']));
|
||||
$temp = [];
|
||||
foreach ($childlist as $k => $v) {
|
||||
$temp[$v['id']] = $v['name'];
|
||||
}
|
||||
$result[__($n['name'])] = $temp;
|
||||
}
|
||||
$groupdata = $result;
|
||||
}
|
||||
|
||||
$this->view->assign('groupdata', $groupdata);
|
||||
$this->assignconfig("admin", ['id' => $this->auth->id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//设置过滤方法
|
||||
$this->request->filter(['strip_tags', 'trim']);
|
||||
if ($this->request->isAjax()) {
|
||||
//如果发送的来源是Selectpage,则转发到Selectpage
|
||||
if ($this->request->request('keyField')) {
|
||||
return $this->selectpage();
|
||||
}
|
||||
$childrenGroupIds = $this->childrenGroupIds;
|
||||
$groupName = AuthGroup::where('id', 'in', $childrenGroupIds)
|
||||
->column('id,name');
|
||||
$authGroupList = AuthGroupAccess::where('group_id', 'in', $childrenGroupIds)
|
||||
->field('uid,group_id')
|
||||
->select();
|
||||
|
||||
$adminGroupName = [];
|
||||
foreach ($authGroupList as $k => $v) {
|
||||
if (isset($groupName[$v['group_id']])) {
|
||||
$adminGroupName[$v['uid']][$v['group_id']] = $groupName[$v['group_id']];
|
||||
}
|
||||
}
|
||||
$groups = $this->auth->getGroups();
|
||||
foreach ($groups as $m => $n) {
|
||||
$adminGroupName[$this->auth->id][$n['id']] = $n['name'];
|
||||
}
|
||||
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
||||
|
||||
$list = $this->model
|
||||
->where($where)
|
||||
->where('id', 'in', $this->childrenAdminIds)
|
||||
->field(['password', 'salt', 'token'], true)
|
||||
->order($sort, $order)
|
||||
->paginate($limit);
|
||||
|
||||
foreach ($list as $k => &$v) {
|
||||
$groups = isset($adminGroupName[$v['id']]) ? $adminGroupName[$v['id']] : [];
|
||||
$v['groups'] = implode(',', array_keys($groups));
|
||||
$v['groups_text'] = implode(',', array_values($groups));
|
||||
}
|
||||
unset($v);
|
||||
$result = array("total" => $list->total(), "rows" => $list->items());
|
||||
|
||||
return json($result);
|
||||
}
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$this->token();
|
||||
$params = $this->request->post("row/a");
|
||||
if ($params) {
|
||||
Db::startTrans();
|
||||
try {
|
||||
if (!Validate::is($params['password'], '\S{6,30}')) {
|
||||
exception(__("Please input correct password"));
|
||||
}
|
||||
$params['salt'] = Random::alnum();
|
||||
$params['password'] = $this->auth->getEncryptPassword($params['password'], $params['salt']);
|
||||
$params['avatar'] = '/assets/img/avatar.png'; //设置新管理员默认头像。
|
||||
$result = $this->model->validate('Admin.add')->save($params);
|
||||
if ($result === false) {
|
||||
exception($this->model->getError());
|
||||
}
|
||||
$group = $this->request->post("group/a");
|
||||
|
||||
//过滤不允许的组别,避免越权
|
||||
$group = array_intersect($this->childrenGroupIds, $group);
|
||||
if (!$group) {
|
||||
exception(__('The parent group exceeds permission limit'));
|
||||
}
|
||||
|
||||
$dataset = [];
|
||||
foreach ($group as $value) {
|
||||
$dataset[] = ['uid' => $this->model->id, 'group_id' => $value];
|
||||
}
|
||||
model('AuthGroupAccess')->saveAll($dataset);
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
$this->error(__('Parameter %s can not be empty', ''));
|
||||
}
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit($ids = null)
|
||||
{
|
||||
$row = $this->model->get(['id' => $ids]);
|
||||
if (!$row) {
|
||||
$this->error(__('No Results were found'));
|
||||
}
|
||||
if (!in_array($row->id, $this->childrenAdminIds)) {
|
||||
$this->error(__('You have no permission'));
|
||||
}
|
||||
if ($this->request->isPost()) {
|
||||
$this->token();
|
||||
$params = $this->request->post("row/a");
|
||||
if ($params) {
|
||||
Db::startTrans();
|
||||
try {
|
||||
if ($params['password']) {
|
||||
if (!Validate::is($params['password'], '\S{6,30}')) {
|
||||
exception(__("Please input correct password"));
|
||||
}
|
||||
$params['salt'] = Random::alnum();
|
||||
$params['password'] = $this->auth->getEncryptPassword($params['password'], $params['salt']);
|
||||
} else {
|
||||
unset($params['password'], $params['salt']);
|
||||
}
|
||||
//这里需要针对username和email做唯一验证
|
||||
$adminValidate = \think\Loader::validate('Admin');
|
||||
$adminValidate->rule([
|
||||
'username' => 'require|regex:\w{3,30}|unique:admin,username,' . $row->id,
|
||||
'email' => 'require|email|unique:admin,email,' . $row->id,
|
||||
'mobile' => 'regex:1[3-9]\d{9}|unique:admin,mobile,' . $row->id,
|
||||
'password' => 'regex:\S{32}',
|
||||
]);
|
||||
$result = $row->validate('Admin.edit')->save($params);
|
||||
if ($result === false) {
|
||||
exception($row->getError());
|
||||
}
|
||||
|
||||
// 先移除所有权限
|
||||
model('AuthGroupAccess')->where('uid', $row->id)->delete();
|
||||
|
||||
$group = $this->request->post("group/a");
|
||||
|
||||
// 过滤不允许的组别,避免越权
|
||||
$group = array_intersect($this->childrenGroupIds, $group);
|
||||
if (!$group) {
|
||||
exception(__('The parent group exceeds permission limit'));
|
||||
}
|
||||
|
||||
$dataset = [];
|
||||
foreach ($group as $value) {
|
||||
$dataset[] = ['uid' => $row->id, 'group_id' => $value];
|
||||
}
|
||||
model('AuthGroupAccess')->saveAll($dataset);
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
$this->error(__('Parameter %s can not be empty', ''));
|
||||
}
|
||||
$grouplist = $this->auth->getGroups($row['id']);
|
||||
$groupids = [];
|
||||
foreach ($grouplist as $k => $v) {
|
||||
$groupids[] = $v['id'];
|
||||
}
|
||||
$this->view->assign("row", $row);
|
||||
$this->view->assign("groupids", $groupids);
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function del($ids = "")
|
||||
{
|
||||
if (!$this->request->isPost()) {
|
||||
$this->error(__("Invalid parameters"));
|
||||
}
|
||||
$ids = $ids ? $ids : $this->request->post("ids");
|
||||
if ($ids) {
|
||||
$ids = array_intersect($this->childrenAdminIds, array_filter(explode(',', $ids)));
|
||||
// 避免越权删除管理员
|
||||
$childrenGroupIds = $this->childrenGroupIds;
|
||||
$adminList = $this->model->where('id', 'in', $ids)->where('id', 'in', function ($query) use ($childrenGroupIds) {
|
||||
$query->name('auth_group_access')->where('group_id', 'in', $childrenGroupIds)->field('uid');
|
||||
})->select();
|
||||
if ($adminList) {
|
||||
$deleteIds = [];
|
||||
foreach ($adminList as $k => $v) {
|
||||
$deleteIds[] = $v->id;
|
||||
}
|
||||
$deleteIds = array_values(array_diff($deleteIds, [$this->auth->id]));
|
||||
if ($deleteIds) {
|
||||
Db::startTrans();
|
||||
try {
|
||||
$this->model->destroy($deleteIds);
|
||||
model('AuthGroupAccess')->where('uid', 'in', $deleteIds)->delete();
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
$this->error(__('No rows were deleted'));
|
||||
}
|
||||
}
|
||||
$this->error(__('You have no permission'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量更新
|
||||
* @internal
|
||||
*/
|
||||
public function multi($ids = "")
|
||||
{
|
||||
// 管理员禁止批量操作
|
||||
$this->error();
|
||||
}
|
||||
|
||||
/**
|
||||
* 下拉搜索
|
||||
*/
|
||||
public function selectpage()
|
||||
{
|
||||
$this->dataLimit = 'auth';
|
||||
$this->dataLimitField = 'id';
|
||||
return parent::selectpage();
|
||||
}
|
||||
}
|
||||
146
application/admin/controller/auth/Adminlog.php
Normal file
146
application/admin/controller/auth/Adminlog.php
Normal file
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\auth;
|
||||
|
||||
use app\admin\model\AuthGroup;
|
||||
use app\common\controller\Backend;
|
||||
|
||||
/**
|
||||
* 管理员日志
|
||||
*
|
||||
* @icon fa fa-users
|
||||
* @remark 管理员可以查看自己所拥有的权限的管理员日志
|
||||
*/
|
||||
class Adminlog extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* @var \app\admin\model\AdminLog
|
||||
*/
|
||||
protected $model = null;
|
||||
protected $childrenGroupIds = [];
|
||||
protected $childrenAdminIds = [];
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = model('AdminLog');
|
||||
|
||||
$this->childrenAdminIds = $this->auth->getChildrenAdminIds(true);
|
||||
$this->childrenGroupIds = $this->auth->getChildrenGroupIds(true);
|
||||
|
||||
$groupName = AuthGroup::where('id', 'in', $this->childrenGroupIds)
|
||||
->column('id,name');
|
||||
|
||||
$this->view->assign('groupdata', $groupName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//设置过滤方法
|
||||
$this->request->filter(['strip_tags', 'trim']);
|
||||
if ($this->request->isAjax()) {
|
||||
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
||||
$isSuperAdmin = $this->auth->isSuperAdmin();
|
||||
$childrenAdminIds = $this->childrenAdminIds;
|
||||
$list = $this->model
|
||||
->where($where)
|
||||
->where(function ($query) use ($isSuperAdmin, $childrenAdminIds) {
|
||||
if (!$isSuperAdmin) {
|
||||
$query->where('admin_id', 'in', $childrenAdminIds);
|
||||
}
|
||||
})
|
||||
->field('content,useragent', true)
|
||||
->order($sort, $order)
|
||||
->paginate($limit);
|
||||
|
||||
$result = array("total" => $list->total(), "rows" => $list->items());
|
||||
|
||||
return json($result);
|
||||
}
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 详情
|
||||
*/
|
||||
public function detail($ids)
|
||||
{
|
||||
$row = $this->model->get(['id' => $ids]);
|
||||
if (!$row) {
|
||||
$this->error(__('No Results were found'));
|
||||
}
|
||||
if (!$this->auth->isSuperAdmin()) {
|
||||
if (!$row['admin_id'] || !in_array($row['admin_id'], $this->childrenAdminIds)) {
|
||||
$this->error(__('You have no permission'));
|
||||
}
|
||||
}
|
||||
$this->view->assign("row", $row->toArray());
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* @internal
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$this->error();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @internal
|
||||
*/
|
||||
public function edit($ids = null)
|
||||
{
|
||||
$this->error();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function del($ids = "")
|
||||
{
|
||||
if (!$this->request->isPost()) {
|
||||
$this->error(__("Invalid parameters"));
|
||||
}
|
||||
$ids = $ids ? $ids : $this->request->post("ids");
|
||||
if ($ids) {
|
||||
$isSuperAdmin = $this->auth->isSuperAdmin();
|
||||
$childrenAdminIds = $this->childrenAdminIds;
|
||||
$adminList = $this->model->where('id', 'in', $ids)
|
||||
->where(function ($query) use ($isSuperAdmin, $childrenAdminIds) {
|
||||
if (!$isSuperAdmin) {
|
||||
$query->where('admin_id', 'in', $childrenAdminIds);
|
||||
}
|
||||
})
|
||||
->select();
|
||||
if ($adminList) {
|
||||
$deleteIds = [];
|
||||
foreach ($adminList as $k => $v) {
|
||||
$deleteIds[] = $v->id;
|
||||
}
|
||||
if ($deleteIds) {
|
||||
$this->model->destroy($deleteIds);
|
||||
$this->success();
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->error();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量更新
|
||||
* @internal
|
||||
*/
|
||||
public function multi($ids = "")
|
||||
{
|
||||
// 管理员禁止批量操作
|
||||
$this->error();
|
||||
}
|
||||
|
||||
}
|
||||
317
application/admin/controller/auth/Group.php
Normal file
317
application/admin/controller/auth/Group.php
Normal file
@@ -0,0 +1,317 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\auth;
|
||||
|
||||
use app\admin\model\AuthGroup;
|
||||
use app\common\controller\Backend;
|
||||
use fast\Tree;
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
|
||||
/**
|
||||
* 角色组
|
||||
*
|
||||
* @icon fa fa-group
|
||||
* @remark 角色组可以有多个,角色有上下级层级关系,如果子角色有角色组和管理员的权限则可以派生属于自己组别下级的角色组或管理员
|
||||
*/
|
||||
class Group extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* @var \app\admin\model\AuthGroup
|
||||
*/
|
||||
protected $model = null;
|
||||
//当前登录管理员所有子组别
|
||||
protected $childrenGroupIds = [];
|
||||
//当前组别列表数据
|
||||
protected $grouplist = [];
|
||||
protected $groupdata = [];
|
||||
//无需要权限判断的方法
|
||||
protected $noNeedRight = ['roletree'];
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = model('AuthGroup');
|
||||
|
||||
$this->childrenGroupIds = $this->auth->getChildrenGroupIds(true);
|
||||
|
||||
$groupList = collection(AuthGroup::where('id', 'in', $this->childrenGroupIds)->select())->toArray();
|
||||
|
||||
Tree::instance()->init($groupList);
|
||||
$groupList = [];
|
||||
if ($this->auth->isSuperAdmin()) {
|
||||
$groupList = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0));
|
||||
} else {
|
||||
$groups = $this->auth->getGroups();
|
||||
$groupIds = [];
|
||||
foreach ($groups as $m => $n) {
|
||||
if (in_array($n['id'], $groupIds) || in_array($n['pid'], $groupIds)) {
|
||||
continue;
|
||||
}
|
||||
$groupList = array_merge($groupList, Tree::instance()->getTreeList(Tree::instance()->getTreeArray($n['pid'])));
|
||||
foreach ($groupList as $index => $item) {
|
||||
$groupIds[] = $item['id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
$groupName = [];
|
||||
foreach ($groupList as $k => $v) {
|
||||
$groupName[$v['id']] = $v['name'];
|
||||
}
|
||||
|
||||
$this->grouplist = $groupList;
|
||||
$this->groupdata = $groupName;
|
||||
$this->assignconfig("admin", ['id' => $this->auth->id, 'group_ids' => $this->auth->getGroupIds()]);
|
||||
|
||||
$this->view->assign('groupdata', $this->groupdata);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
if ($this->request->isAjax()) {
|
||||
$list = $this->grouplist;
|
||||
$total = count($list);
|
||||
$result = array("total" => $total, "rows" => $list);
|
||||
|
||||
return json($result);
|
||||
}
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$this->token();
|
||||
$params = $this->request->post("row/a", [], 'strip_tags');
|
||||
$params['rules'] = explode(',', $params['rules']);
|
||||
if (!in_array($params['pid'], $this->childrenGroupIds)) {
|
||||
$this->error(__('The parent group exceeds permission limit'));
|
||||
}
|
||||
$parentmodel = model("AuthGroup")->get($params['pid']);
|
||||
if (!$parentmodel) {
|
||||
$this->error(__('The parent group can not found'));
|
||||
}
|
||||
// 父级别的规则节点
|
||||
$parentrules = explode(',', $parentmodel->rules);
|
||||
// 当前组别的规则节点
|
||||
$currentrules = $this->auth->getRuleIds();
|
||||
$rules = $params['rules'];
|
||||
// 如果父组不是超级管理员则需要过滤规则节点,不能超过父组别的权限
|
||||
$rules = in_array('*', $parentrules) ? $rules : array_intersect($parentrules, $rules);
|
||||
// 如果当前组别不是超级管理员则需要过滤规则节点,不能超当前组别的权限
|
||||
$rules = in_array('*', $currentrules) ? $rules : array_intersect($currentrules, $rules);
|
||||
$params['rules'] = implode(',', $rules);
|
||||
if ($params) {
|
||||
$this->model->create($params);
|
||||
$this->success();
|
||||
}
|
||||
$this->error();
|
||||
}
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit($ids = null)
|
||||
{
|
||||
if (!in_array($ids, $this->childrenGroupIds)) {
|
||||
$this->error(__('You have no permission'));
|
||||
}
|
||||
$row = $this->model->get(['id' => $ids]);
|
||||
if (!$row) {
|
||||
$this->error(__('No Results were found'));
|
||||
}
|
||||
if ($this->request->isPost()) {
|
||||
$this->token();
|
||||
$params = $this->request->post("row/a", [], 'strip_tags');
|
||||
//父节点不能是非权限内节点
|
||||
if (!in_array($params['pid'], $this->childrenGroupIds)) {
|
||||
$this->error(__('The parent group exceeds permission limit'));
|
||||
}
|
||||
// 父节点不能是它自身的子节点或自己本身
|
||||
if (in_array($params['pid'], Tree::instance()->getChildrenIds($row->id, true))) {
|
||||
$this->error(__('The parent group can not be its own child or itself'));
|
||||
}
|
||||
$params['rules'] = explode(',', $params['rules']);
|
||||
|
||||
$parentmodel = model("AuthGroup")->get($params['pid']);
|
||||
if (!$parentmodel) {
|
||||
$this->error(__('The parent group can not found'));
|
||||
}
|
||||
// 父级别的规则节点
|
||||
$parentrules = explode(',', $parentmodel->rules);
|
||||
// 当前组别的规则节点
|
||||
$currentrules = $this->auth->getRuleIds();
|
||||
$rules = $params['rules'];
|
||||
// 如果父组不是超级管理员则需要过滤规则节点,不能超过父组别的权限
|
||||
$rules = in_array('*', $parentrules) ? $rules : array_intersect($parentrules, $rules);
|
||||
// 如果当前组别不是超级管理员则需要过滤规则节点,不能超当前组别的权限
|
||||
$rules = in_array('*', $currentrules) ? $rules : array_intersect($currentrules, $rules);
|
||||
$params['rules'] = implode(',', $rules);
|
||||
if ($params) {
|
||||
Db::startTrans();
|
||||
try {
|
||||
$row->save($params);
|
||||
$children_auth_groups = model("AuthGroup")->all(['id' => ['in', implode(',', (Tree::instance()->getChildrenIds($row->id)))]]);
|
||||
$childparams = [];
|
||||
foreach ($children_auth_groups as $key => $children_auth_group) {
|
||||
$childparams[$key]['id'] = $children_auth_group->id;
|
||||
$childparams[$key]['rules'] = implode(',', array_intersect(explode(',', $children_auth_group->rules), $rules));
|
||||
}
|
||||
model("AuthGroup")->saveAll($childparams);
|
||||
Db::commit();
|
||||
$this->success();
|
||||
} catch (Exception $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
$this->error();
|
||||
return;
|
||||
}
|
||||
$this->view->assign("row", $row);
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function del($ids = "")
|
||||
{
|
||||
if (!$this->request->isPost()) {
|
||||
$this->error(__("Invalid parameters"));
|
||||
}
|
||||
$ids = $ids ? $ids : $this->request->post("ids");
|
||||
if ($ids) {
|
||||
$ids = explode(',', $ids);
|
||||
$grouplist = $this->auth->getGroups();
|
||||
$group_ids = array_map(function ($group) {
|
||||
return $group['id'];
|
||||
}, $grouplist);
|
||||
// 移除掉当前管理员所在组别
|
||||
$ids = array_diff($ids, $group_ids);
|
||||
|
||||
// 循环判断每一个组别是否可删除
|
||||
$grouplist = $this->model->where('id', 'in', $ids)->select();
|
||||
$groupaccessmodel = model('AuthGroupAccess');
|
||||
foreach ($grouplist as $k => $v) {
|
||||
// 当前组别下有管理员
|
||||
$groupone = $groupaccessmodel->get(['group_id' => $v['id']]);
|
||||
if ($groupone) {
|
||||
$ids = array_diff($ids, [$v['id']]);
|
||||
continue;
|
||||
}
|
||||
// 当前组别下有子组别
|
||||
$groupone = $this->model->get(['pid' => $v['id']]);
|
||||
if ($groupone) {
|
||||
$ids = array_diff($ids, [$v['id']]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (!$ids) {
|
||||
$this->error(__('You can not delete group that contain child group and administrators'));
|
||||
}
|
||||
$count = $this->model->where('id', 'in', $ids)->delete();
|
||||
if ($count) {
|
||||
$this->success();
|
||||
}
|
||||
}
|
||||
$this->error();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量更新
|
||||
* @internal
|
||||
*/
|
||||
public function multi($ids = "")
|
||||
{
|
||||
// 组别禁止批量操作
|
||||
$this->error();
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取角色权限树
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public function roletree()
|
||||
{
|
||||
$this->loadlang('auth/group');
|
||||
|
||||
$model = model('AuthGroup');
|
||||
$id = $this->request->post("id");
|
||||
$pid = $this->request->post("pid");
|
||||
$parentGroupModel = $model->get($pid);
|
||||
$currentGroupModel = null;
|
||||
if ($id) {
|
||||
$currentGroupModel = $model->get($id);
|
||||
}
|
||||
if (($pid || $parentGroupModel) && (!$id || $currentGroupModel)) {
|
||||
$id = $id ? $id : null;
|
||||
$ruleList = collection(model('AuthRule')->order('weigh', 'desc')->order('id', 'asc')->select())->toArray();
|
||||
//读取父类角色所有节点列表
|
||||
$parentRuleList = [];
|
||||
if (in_array('*', explode(',', $parentGroupModel->rules))) {
|
||||
$parentRuleList = $ruleList;
|
||||
} else {
|
||||
$parentRuleIds = explode(',', $parentGroupModel->rules);
|
||||
foreach ($ruleList as $k => $v) {
|
||||
if (in_array($v['id'], $parentRuleIds)) {
|
||||
$parentRuleList[] = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$ruleTree = new Tree();
|
||||
$groupTree = new Tree();
|
||||
//当前所有正常规则列表
|
||||
$ruleTree->init($parentRuleList);
|
||||
//角色组列表
|
||||
$groupTree->init(collection(model('AuthGroup')->where('id', 'in', $this->childrenGroupIds)->select())->toArray());
|
||||
|
||||
//读取当前角色下规则ID集合
|
||||
$adminRuleIds = $this->auth->getRuleIds();
|
||||
//是否是超级管理员
|
||||
$superadmin = $this->auth->isSuperAdmin();
|
||||
//当前拥有的规则ID集合
|
||||
$currentRuleIds = $id ? explode(',', $currentGroupModel->rules) : [];
|
||||
|
||||
if (!$id || !in_array($pid, $this->childrenGroupIds) || !in_array($pid, $groupTree->getChildrenIds($id, true))) {
|
||||
$parentRuleList = $ruleTree->getTreeList($ruleTree->getTreeArray(0), 'name');
|
||||
$hasChildrens = [];
|
||||
foreach ($parentRuleList as $k => $v) {
|
||||
if ($v['haschild']) {
|
||||
$hasChildrens[] = $v['id'];
|
||||
}
|
||||
}
|
||||
$parentRuleIds = array_map(function ($item) {
|
||||
return $item['id'];
|
||||
}, $parentRuleList);
|
||||
$nodeList = [];
|
||||
foreach ($parentRuleList as $k => $v) {
|
||||
if (!$superadmin && !in_array($v['id'], $adminRuleIds)) {
|
||||
continue;
|
||||
}
|
||||
if ($v['pid'] && !in_array($v['pid'], $parentRuleIds)) {
|
||||
continue;
|
||||
}
|
||||
$state = array('selected' => in_array($v['id'], $currentRuleIds) && !in_array($v['id'], $hasChildrens));
|
||||
$nodeList[] = array('id' => $v['id'], 'parent' => $v['pid'] ? $v['pid'] : '#', 'text' => __($v['title']), 'type' => 'menu', 'state' => $state);
|
||||
}
|
||||
$this->success('', null, $nodeList);
|
||||
} else {
|
||||
$this->error(__('Can not change the parent to child'));
|
||||
}
|
||||
} else {
|
||||
$this->error(__('Group not found'));
|
||||
}
|
||||
}
|
||||
}
|
||||
159
application/admin/controller/auth/Rule.php
Normal file
159
application/admin/controller/auth/Rule.php
Normal file
@@ -0,0 +1,159 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\auth;
|
||||
|
||||
use app\admin\model\AuthRule;
|
||||
use app\common\controller\Backend;
|
||||
use fast\Tree;
|
||||
use think\Cache;
|
||||
|
||||
/**
|
||||
* 规则管理
|
||||
*
|
||||
* @icon fa fa-list
|
||||
* @remark 规则通常对应一个控制器的方法,同时左侧的菜单栏数据也从规则中体现,通常建议通过控制台进行生成规则节点
|
||||
*/
|
||||
class Rule extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* @var \app\admin\model\AuthRule
|
||||
*/
|
||||
protected $model = null;
|
||||
protected $rulelist = [];
|
||||
protected $multiFields = 'ismenu,status';
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
if (!$this->auth->isSuperAdmin()) {
|
||||
$this->error(__('Access is allowed only to the super management group'));
|
||||
}
|
||||
$this->model = model('AuthRule');
|
||||
// 必须将结果集转换为数组
|
||||
$ruleList = \think\Db::name("auth_rule")->field('type,condition,remark,createtime,updatetime', true)->order('weigh DESC,id ASC')->select();
|
||||
foreach ($ruleList as $k => &$v) {
|
||||
$v['title'] = __($v['title']);
|
||||
}
|
||||
unset($v);
|
||||
Tree::instance()->init($ruleList)->icon = [' ', ' ', ' '];
|
||||
$this->rulelist = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0), 'title');
|
||||
$ruledata = [0 => __('None')];
|
||||
foreach ($this->rulelist as $k => &$v) {
|
||||
if (!$v['ismenu']) {
|
||||
continue;
|
||||
}
|
||||
$ruledata[$v['id']] = $v['title'];
|
||||
unset($v['spacer']);
|
||||
}
|
||||
unset($v);
|
||||
$this->view->assign('ruledata', $ruledata);
|
||||
$this->view->assign("menutypeList", $this->model->getMenutypeList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
if ($this->request->isAjax()) {
|
||||
$list = $this->rulelist;
|
||||
$total = count($this->rulelist);
|
||||
$result = array("total" => $total, "rows" => $list);
|
||||
|
||||
return json($result);
|
||||
}
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$this->token();
|
||||
$params = $this->request->post("row/a", [], 'strip_tags');
|
||||
if ($params) {
|
||||
if (!$params['ismenu'] && !$params['pid']) {
|
||||
$this->error(__('The non-menu rule must have parent'));
|
||||
}
|
||||
$result = $this->model->validate()->save($params);
|
||||
if ($result === false) {
|
||||
$this->error($this->model->getError());
|
||||
}
|
||||
Cache::rm('__menu__');
|
||||
$this->success();
|
||||
}
|
||||
$this->error();
|
||||
}
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit($ids = null)
|
||||
{
|
||||
$row = $this->model->get(['id' => $ids]);
|
||||
if (!$row) {
|
||||
$this->error(__('No Results were found'));
|
||||
}
|
||||
if ($this->request->isPost()) {
|
||||
$this->token();
|
||||
$params = $this->request->post("row/a", [], 'strip_tags');
|
||||
if ($params) {
|
||||
if (!$params['ismenu'] && !$params['pid']) {
|
||||
$this->error(__('The non-menu rule must have parent'));
|
||||
}
|
||||
if ($params['pid'] == $row['id']) {
|
||||
$this->error(__('Can not change the parent to self'));
|
||||
}
|
||||
if ($params['pid'] != $row['pid']) {
|
||||
$childrenIds = Tree::instance()->init(collection(AuthRule::select())->toArray())->getChildrenIds($row['id']);
|
||||
if (in_array($params['pid'], $childrenIds)) {
|
||||
$this->error(__('Can not change the parent to child'));
|
||||
}
|
||||
}
|
||||
//这里需要针对name做唯一验证
|
||||
$ruleValidate = \think\Loader::validate('AuthRule');
|
||||
$ruleValidate->rule([
|
||||
'name' => 'require|unique:AuthRule,name,' . $row->id,
|
||||
]);
|
||||
$result = $row->validate()->save($params);
|
||||
if ($result === false) {
|
||||
$this->error($row->getError());
|
||||
}
|
||||
Cache::rm('__menu__');
|
||||
$this->success();
|
||||
}
|
||||
$this->error();
|
||||
}
|
||||
$this->view->assign("row", $row);
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function del($ids = "")
|
||||
{
|
||||
if (!$this->request->isPost()) {
|
||||
$this->error(__("Invalid parameters"));
|
||||
}
|
||||
$ids = $ids ? $ids : $this->request->post("ids");
|
||||
if ($ids) {
|
||||
$delIds = [];
|
||||
foreach (explode(',', $ids) as $k => $v) {
|
||||
$delIds = array_merge($delIds, Tree::instance()->getChildrenIds($v, true));
|
||||
}
|
||||
$delIds = array_unique($delIds);
|
||||
$count = $this->model->where('id', 'in', $delIds)->delete();
|
||||
if ($count) {
|
||||
Cache::rm('__menu__');
|
||||
$this->success();
|
||||
}
|
||||
}
|
||||
$this->error();
|
||||
}
|
||||
}
|
||||
160
application/admin/controller/general/Attachment.php
Normal file
160
application/admin/controller/general/Attachment.php
Normal file
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\general;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
|
||||
/**
|
||||
* 附件管理
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
* @remark 主要用于管理上传到服务器或第三方存储的数据
|
||||
*/
|
||||
class Attachment extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* @var \app\common\model\Attachment
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
protected $searchFields = 'id,filename,url';
|
||||
protected $noNeedRight = ['classify'];
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = model('Attachment');
|
||||
$this->view->assign("mimetypeList", \app\common\model\Attachment::getMimetypeList());
|
||||
$this->view->assign("categoryList", \app\common\model\Attachment::getCategoryList());
|
||||
$this->assignconfig("categoryList", \app\common\model\Attachment::getCategoryList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//设置过滤方法
|
||||
$this->request->filter(['strip_tags', 'trim']);
|
||||
if ($this->request->isAjax()) {
|
||||
$mimetypeQuery = [];
|
||||
$filter = $this->request->request('filter');
|
||||
$filterArr = (array)json_decode($filter, true);
|
||||
if (isset($filterArr['category']) && $filterArr['category'] == 'unclassed') {
|
||||
$filterArr['category'] = ',unclassed';
|
||||
$this->request->get(['filter' => json_encode(array_diff_key($filterArr, ['category' => '']))]);
|
||||
}
|
||||
if (isset($filterArr['mimetype']) && preg_match("/(\/|\,|\*)/", $filterArr['mimetype'])) {
|
||||
$mimetype = $filterArr['mimetype'];
|
||||
$filterArr = array_diff_key($filterArr, ['mimetype' => '']);
|
||||
$mimetypeQuery = function ($query) use ($mimetype) {
|
||||
$mimetypeArr = array_filter(explode(',', $mimetype));
|
||||
foreach ($mimetypeArr as $index => $item) {
|
||||
$query->whereOr('mimetype', 'like', '%' . str_replace("/*", "/", $item) . '%');
|
||||
}
|
||||
};
|
||||
}
|
||||
$this->request->get(['filter' => json_encode($filterArr)]);
|
||||
|
||||
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
||||
|
||||
$list = $this->model
|
||||
->where($mimetypeQuery)
|
||||
->where($where)
|
||||
->order($sort, $order)
|
||||
->paginate($limit);
|
||||
|
||||
$cdnurl = preg_replace("/\/(\w+)\.php$/i", '', $this->request->root());
|
||||
foreach ($list as $k => &$v) {
|
||||
$v['fullurl'] = ($v['storage'] == 'local' ? $cdnurl : $this->view->config['upload']['cdnurl']) . $v['url'];
|
||||
}
|
||||
unset($v);
|
||||
$result = array("total" => $list->total(), "rows" => $list->items());
|
||||
|
||||
return json($result);
|
||||
}
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 选择附件
|
||||
*/
|
||||
public function select()
|
||||
{
|
||||
if ($this->request->isAjax()) {
|
||||
return $this->index();
|
||||
}
|
||||
$mimetype = $this->request->get('mimetype', '');
|
||||
$mimetype = substr($mimetype, -1) === '/' ? $mimetype . '*' : $mimetype;
|
||||
$this->view->assign('mimetype', $mimetype);
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
if ($this->request->isAjax()) {
|
||||
$this->error();
|
||||
}
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除附件
|
||||
* @param array $ids
|
||||
*/
|
||||
public function del($ids = "")
|
||||
{
|
||||
if (!$this->request->isPost()) {
|
||||
$this->error(__("Invalid parameters"));
|
||||
}
|
||||
$ids = $ids ? $ids : $this->request->post("ids");
|
||||
if ($ids) {
|
||||
\think\Hook::add('upload_delete', function ($params) {
|
||||
if ($params['storage'] == 'local') {
|
||||
$attachmentFile = ROOT_PATH . '/public' . $params['url'];
|
||||
if (is_file($attachmentFile)) {
|
||||
@unlink($attachmentFile);
|
||||
}
|
||||
}
|
||||
});
|
||||
$attachmentlist = $this->model->where('id', 'in', $ids)->select();
|
||||
foreach ($attachmentlist as $attachment) {
|
||||
\think\Hook::listen("upload_delete", $attachment);
|
||||
$attachment->delete();
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
$this->error(__('Parameter %s can not be empty', 'ids'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 归类
|
||||
*/
|
||||
public function classify()
|
||||
{
|
||||
if (!$this->auth->check('general/attachment/edit')) {
|
||||
\think\Hook::listen('admin_nopermission', $this);
|
||||
$this->error(__('You have no permission'), '');
|
||||
}
|
||||
if (!$this->request->isPost()) {
|
||||
$this->error(__("Invalid parameters"));
|
||||
}
|
||||
$category = $this->request->post('category', '');
|
||||
$ids = $this->request->post('ids');
|
||||
if (!$ids) {
|
||||
$this->error(__('Parameter %s can not be empty', 'ids'));
|
||||
}
|
||||
$categoryList = \app\common\model\Attachment::getCategoryList();
|
||||
if ($category && !isset($categoryList[$category])) {
|
||||
$this->error(__('Category not found'));
|
||||
}
|
||||
$category = $category == 'unclassed' ? '' : $category;
|
||||
\app\common\model\Attachment::where('id', 'in', $ids)->update(['category' => $category]);
|
||||
$this->success();
|
||||
}
|
||||
|
||||
}
|
||||
311
application/admin/controller/general/Config.php
Normal file
311
application/admin/controller/general/Config.php
Normal file
@@ -0,0 +1,311 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\general;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\Email;
|
||||
use app\common\model\Config as ConfigModel;
|
||||
use think\Cache;
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
use think\Validate;
|
||||
|
||||
/**
|
||||
* 系统配置
|
||||
*
|
||||
* @icon fa fa-cogs
|
||||
* @remark 可以在此增改系统的变量和分组,也可以自定义分组和变量,如果需要删除请从数据库中删除
|
||||
*/
|
||||
class Config extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* @var \app\common\model\Config
|
||||
*/
|
||||
protected $model = null;
|
||||
protected $noNeedRight = ['check', 'rulelist', 'selectpage', 'get_fields_list'];
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
// $this->model = model('Config');
|
||||
$this->model = new ConfigModel;
|
||||
ConfigModel::event('before_write', function ($row) {
|
||||
if (isset($row['name']) && $row['name'] == 'name' && preg_match("/fast" . "admin/i", $row['value'])) {
|
||||
throw new Exception(__("Site name incorrect"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$siteList = [];
|
||||
$groupList = ConfigModel::getGroupList();
|
||||
foreach ($groupList as $k => $v) {
|
||||
$siteList[$k]['name'] = $k;
|
||||
$siteList[$k]['title'] = $v;
|
||||
$siteList[$k]['list'] = [];
|
||||
}
|
||||
|
||||
foreach ($this->model->all() as $k => $v) {
|
||||
if (!isset($siteList[$v['group']])) {
|
||||
continue;
|
||||
}
|
||||
$value = $v->toArray();
|
||||
$value['title'] = __($value['title']);
|
||||
if (in_array($value['type'], ['select', 'selects', 'checkbox', 'radio'])) {
|
||||
$value['value'] = explode(',', $value['value']);
|
||||
}
|
||||
$value['content'] = json_decode($value['content'], true);
|
||||
if (in_array($value['name'], ['categorytype', 'configgroup', 'attachmentcategory'])) {
|
||||
$dictValue = (array)json_decode($value['value'], true);
|
||||
foreach ($dictValue as $index => &$item) {
|
||||
$item = __($item);
|
||||
}
|
||||
unset($item);
|
||||
$value['value'] = json_encode($dictValue, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
$value['tip'] = htmlspecialchars($value['tip']);
|
||||
if ($value['name'] == 'cdnurl') {
|
||||
//cdnurl不支持在线修改
|
||||
continue;
|
||||
}
|
||||
$siteList[$v['group']]['list'][] = $value;
|
||||
}
|
||||
$index = 0;
|
||||
foreach ($siteList as $k => &$v) {
|
||||
$v['active'] = !$index ? true : false;
|
||||
$index++;
|
||||
}
|
||||
$this->view->assign('siteList', $siteList);
|
||||
$this->view->assign('typeList', ConfigModel::getTypeList());
|
||||
$this->view->assign('ruleList', ConfigModel::getRegexList());
|
||||
$this->view->assign('groupList', ConfigModel::getGroupList());
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
if (!config('app_debug')) {
|
||||
$this->error(__('Only work at development environment'));
|
||||
}
|
||||
if ($this->request->isPost()) {
|
||||
$this->token();
|
||||
$params = $this->request->post("row/a", [], 'trim');
|
||||
if ($params) {
|
||||
foreach ($params as $k => &$v) {
|
||||
$v = is_array($v) && $k !== 'setting' ? implode(',', $v) : $v;
|
||||
}
|
||||
if (in_array($params['type'], ['select', 'selects', 'checkbox', 'radio', 'array'])) {
|
||||
$params['content'] = json_encode(ConfigModel::decode($params['content']), JSON_UNESCAPED_UNICODE);
|
||||
} else {
|
||||
$params['content'] = '';
|
||||
}
|
||||
try {
|
||||
$result = $this->model->create($params);
|
||||
} catch (Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
if ($result !== false) {
|
||||
try {
|
||||
ConfigModel::refreshFile();
|
||||
} catch (Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$this->success();
|
||||
} else {
|
||||
$this->error($this->model->getError());
|
||||
}
|
||||
}
|
||||
$this->error(__('Parameter %s can not be empty', ''));
|
||||
}
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @param null $ids
|
||||
*/
|
||||
public function edit($ids = null)
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$this->token();
|
||||
$row = $this->request->post("row/a", [], 'trim');
|
||||
if ($row) {
|
||||
$configList = [];
|
||||
foreach ($this->model->all() as $v) {
|
||||
if (isset($row[$v['name']])) {
|
||||
$value = $row[$v['name']];
|
||||
if (is_array($value) && isset($value['field'])) {
|
||||
$value = json_encode(ConfigModel::getArrayData($value), JSON_UNESCAPED_UNICODE);
|
||||
} else {
|
||||
$value = is_array($value) ? implode(',', $value) : $value;
|
||||
}
|
||||
$v['value'] = $value;
|
||||
$configList[] = $v->toArray();
|
||||
}
|
||||
}
|
||||
try {
|
||||
$this->model->allowField(true)->saveAll($configList);
|
||||
} catch (Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
try {
|
||||
ConfigModel::refreshFile();
|
||||
} catch (Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
$this->error(__('Parameter %s can not be empty', ''));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param string $ids
|
||||
*/
|
||||
public function del($ids = "")
|
||||
{
|
||||
if (!config('app_debug')) {
|
||||
$this->error(__('Only work at development environment'));
|
||||
}
|
||||
$name = $this->request->post('name');
|
||||
$config = ConfigModel::getByName($name);
|
||||
if ($name && $config) {
|
||||
try {
|
||||
$config->delete();
|
||||
ConfigModel::refreshFile();
|
||||
} catch (Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$this->success();
|
||||
} else {
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测配置项是否存在
|
||||
* @internal
|
||||
*/
|
||||
public function check()
|
||||
{
|
||||
$params = $this->request->post("row/a");
|
||||
if ($params) {
|
||||
$config = $this->model->get($params);
|
||||
if (!$config) {
|
||||
$this->success();
|
||||
} else {
|
||||
$this->error(__('Name already exist'));
|
||||
}
|
||||
} else {
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 规则列表
|
||||
* @internal
|
||||
*/
|
||||
public function rulelist()
|
||||
{
|
||||
//主键
|
||||
$primarykey = $this->request->request("keyField");
|
||||
//主键值
|
||||
$keyValue = $this->request->request("keyValue", "");
|
||||
|
||||
$keyValueArr = array_filter(explode(',', $keyValue));
|
||||
$regexList = \app\common\model\Config::getRegexList();
|
||||
$list = [];
|
||||
foreach ($regexList as $k => $v) {
|
||||
if ($keyValueArr) {
|
||||
if (in_array($k, $keyValueArr)) {
|
||||
$list[] = ['id' => $k, 'name' => $v];
|
||||
}
|
||||
} else {
|
||||
$list[] = ['id' => $k, 'name' => $v];
|
||||
}
|
||||
}
|
||||
return json(['list' => $list]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送测试邮件
|
||||
* @internal
|
||||
*/
|
||||
public function emailtest()
|
||||
{
|
||||
$row = $this->request->post('row/a');
|
||||
$receiver = $this->request->post("receiver");
|
||||
if ($receiver) {
|
||||
if (!Validate::is($receiver, "email")) {
|
||||
$this->error(__('Please input correct email'));
|
||||
}
|
||||
\think\Config::set('site', array_merge(\think\Config::get('site'), $row));
|
||||
$email = new Email;
|
||||
$result = $email
|
||||
->to($receiver)
|
||||
->subject(__("This is a test mail", config('site.name')))
|
||||
->message('<div style="min-height:550px; padding: 100px 55px 200px;">' . __('This is a test mail content', config('site.name')) . '</div>')
|
||||
->send();
|
||||
if ($result) {
|
||||
$this->success();
|
||||
} else {
|
||||
$this->error($email->getError());
|
||||
}
|
||||
} else {
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
}
|
||||
|
||||
public function selectpage()
|
||||
{
|
||||
$id = $this->request->get("id/d");
|
||||
$config = \app\common\model\Config::get($id);
|
||||
if (!$config) {
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
$setting = $config['setting'];
|
||||
//自定义条件
|
||||
$custom = isset($setting['conditions']) ? (array)json_decode($setting['conditions'], true) : [];
|
||||
$custom = array_filter($custom);
|
||||
|
||||
$this->request->request(['showField' => $setting['field'], 'keyField' => $setting['primarykey'], 'custom' => $custom, 'searchField' => [$setting['field'], $setting['primarykey']]]);
|
||||
$this->model = \think\Db::connect()->setTable($setting['table']);
|
||||
return parent::selectpage();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取表列表
|
||||
* @internal
|
||||
*/
|
||||
public function get_table_list()
|
||||
{
|
||||
$tableList = [];
|
||||
$dbname = \think\Config::get('database.database');
|
||||
$tableList = \think\Db::query("SELECT `TABLE_NAME` AS `name`,`TABLE_COMMENT` AS `title` FROM `information_schema`.`TABLES` where `TABLE_SCHEMA` = '{$dbname}';");
|
||||
$this->success('', null, ['tableList' => $tableList]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取表字段列表
|
||||
* @internal
|
||||
*/
|
||||
public function get_fields_list()
|
||||
{
|
||||
$table = $this->request->request('table');
|
||||
$dbname = \think\Config::get('database.database');
|
||||
//从数据库中获取表字段信息
|
||||
$sql = "SELECT `COLUMN_NAME` AS `name`,`COLUMN_COMMENT` AS `title`,`DATA_TYPE` AS `type` FROM `information_schema`.`columns` WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ? ORDER BY ORDINAL_POSITION";
|
||||
//加载主表的列
|
||||
$fieldList = Db::query($sql, [$dbname, $table]);
|
||||
$this->success("", null, ['fieldList' => $fieldList]);
|
||||
}
|
||||
}
|
||||
84
application/admin/controller/general/Profile.php
Normal file
84
application/admin/controller/general/Profile.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\general;
|
||||
|
||||
use app\admin\model\Admin;
|
||||
use app\common\controller\Backend;
|
||||
use fast\Random;
|
||||
use think\Session;
|
||||
use think\Validate;
|
||||
|
||||
/**
|
||||
* 个人配置
|
||||
*
|
||||
* @icon fa fa-user
|
||||
*/
|
||||
class Profile extends Backend
|
||||
{
|
||||
|
||||
protected $searchFields = 'id,title';
|
||||
|
||||
/**
|
||||
* 查看
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//设置过滤方法
|
||||
$this->request->filter(['strip_tags', 'trim']);
|
||||
if ($this->request->isAjax()) {
|
||||
$this->model = model('AdminLog');
|
||||
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
||||
|
||||
$list = $this->model
|
||||
->where($where)
|
||||
->where('admin_id', $this->auth->id)
|
||||
->order($sort, $order)
|
||||
->paginate($limit);
|
||||
|
||||
$result = array("total" => $list->total(), "rows" => $list->items());
|
||||
|
||||
return json($result);
|
||||
}
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新个人信息
|
||||
*/
|
||||
public function update()
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$this->token();
|
||||
$params = $this->request->post("row/a");
|
||||
$params = array_filter(array_intersect_key(
|
||||
$params,
|
||||
array_flip(array('email', 'nickname', 'password', 'avatar'))
|
||||
));
|
||||
unset($v);
|
||||
if (!Validate::is($params['email'], "email")) {
|
||||
$this->error(__("Please input correct email"));
|
||||
}
|
||||
if (isset($params['password'])) {
|
||||
if (!Validate::is($params['password'], "/^[\S]{6,30}$/")) {
|
||||
$this->error(__("Please input correct password"));
|
||||
}
|
||||
$params['salt'] = Random::alnum();
|
||||
$params['password'] = md5(md5($params['password']) . $params['salt']);
|
||||
}
|
||||
$exist = Admin::where('email', $params['email'])->where('id', '<>', $this->auth->id)->find();
|
||||
if ($exist) {
|
||||
$this->error(__("Email already exists"));
|
||||
}
|
||||
if ($params) {
|
||||
$admin = Admin::get($this->auth->id);
|
||||
$admin->save($params);
|
||||
//因为个人资料面板读取的Session显示,修改自己资料后同时更新Session
|
||||
Session::set("admin", $admin->toArray());
|
||||
Session::set("admin.safecode", $this->auth->getEncryptSafecode($admin));
|
||||
$this->success();
|
||||
}
|
||||
$this->error();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
52
application/admin/controller/user/Group.php
Normal file
52
application/admin/controller/user/Group.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\user;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
|
||||
/**
|
||||
* 会员组管理
|
||||
*
|
||||
* @icon fa fa-users
|
||||
*/
|
||||
class Group extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* @var \app\admin\model\UserGroup
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = model('UserGroup');
|
||||
$this->view->assign("statusList", $this->model->getStatusList());
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$this->token();
|
||||
}
|
||||
$nodeList = \app\admin\model\UserRule::getTreeList();
|
||||
$this->assign("nodeList", $nodeList);
|
||||
return parent::add();
|
||||
}
|
||||
|
||||
public function edit($ids = null)
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$this->token();
|
||||
}
|
||||
$row = $this->model->get($ids);
|
||||
if (!$row) {
|
||||
$this->error(__('No Results were found'));
|
||||
}
|
||||
$rules = explode(',', $row['rules']);
|
||||
$nodeList = \app\admin\model\UserRule::getTreeList($rules);
|
||||
$this->assign("nodeList", $nodeList);
|
||||
return parent::edit($ids);
|
||||
}
|
||||
|
||||
}
|
||||
108
application/admin/controller/user/Rule.php
Normal file
108
application/admin/controller/user/Rule.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\user;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use fast\Tree;
|
||||
|
||||
/**
|
||||
* 会员规则管理
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class Rule extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* @var \app\admin\model\UserRule
|
||||
*/
|
||||
protected $model = null;
|
||||
protected $rulelist = [];
|
||||
protected $multiFields = 'ismenu,status';
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = model('UserRule');
|
||||
$this->view->assign("statusList", $this->model->getStatusList());
|
||||
// 必须将结果集转换为数组
|
||||
$ruleList = collection($this->model->order('weigh', 'desc')->select())->toArray();
|
||||
foreach ($ruleList as $k => &$v) {
|
||||
$v['title'] = __($v['title']);
|
||||
$v['remark'] = __($v['remark']);
|
||||
}
|
||||
unset($v);
|
||||
Tree::instance()->init($ruleList)->icon = [' ', ' ', ' '];
|
||||
$this->rulelist = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0), 'title');
|
||||
$ruledata = [0 => __('None')];
|
||||
foreach ($this->rulelist as $k => &$v) {
|
||||
if (!$v['ismenu']) {
|
||||
continue;
|
||||
}
|
||||
$ruledata[$v['id']] = $v['title'];
|
||||
}
|
||||
$this->view->assign('ruledata', $ruledata);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
if ($this->request->isAjax()) {
|
||||
$list = $this->rulelist;
|
||||
$total = count($this->rulelist);
|
||||
|
||||
$result = array("total" => $total, "rows" => $list);
|
||||
|
||||
return json($result);
|
||||
}
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$this->token();
|
||||
}
|
||||
return parent::add();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit($ids = null)
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$this->token();
|
||||
}
|
||||
return parent::edit($ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function del($ids = "")
|
||||
{
|
||||
if (!$this->request->isPost()) {
|
||||
$this->error(__("Invalid parameters"));
|
||||
}
|
||||
$ids = $ids ? $ids : $this->request->post("ids");
|
||||
if ($ids) {
|
||||
$delIds = [];
|
||||
foreach (explode(',', $ids) as $k => $v) {
|
||||
$delIds = array_merge($delIds, Tree::instance()->getChildrenIds($v, true));
|
||||
}
|
||||
$delIds = array_unique($delIds);
|
||||
$count = $this->model->where('id', 'in', $delIds)->delete();
|
||||
if ($count) {
|
||||
$this->success();
|
||||
}
|
||||
}
|
||||
$this->error();
|
||||
}
|
||||
|
||||
}
|
||||
105
application/admin/controller/user/User.php
Normal file
105
application/admin/controller/user/User.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\user;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\Auth;
|
||||
|
||||
/**
|
||||
* 会员管理
|
||||
*
|
||||
* @icon fa fa-user
|
||||
*/
|
||||
class User extends Backend
|
||||
{
|
||||
|
||||
protected $relationSearch = true;
|
||||
protected $searchFields = 'id,username,nickname';
|
||||
|
||||
/**
|
||||
* @var \app\admin\model\User
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\User;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//设置过滤方法
|
||||
$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('group')
|
||||
->where($where)
|
||||
->order($sort, $order)
|
||||
->paginate($limit);
|
||||
foreach ($list as $k => $v) {
|
||||
$v->avatar = $v->avatar ? cdnurl($v->avatar, true) : letter_avatar($v->nickname);
|
||||
$v->hidden(['password', 'salt']);
|
||||
}
|
||||
$result = array("total" => $list->total(), "rows" => $list->items());
|
||||
|
||||
return json($result);
|
||||
}
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$this->token();
|
||||
}
|
||||
return parent::add();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*/
|
||||
public function edit($ids = null)
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$this->token();
|
||||
}
|
||||
$row = $this->model->get($ids);
|
||||
$this->modelValidate = true;
|
||||
if (!$row) {
|
||||
$this->error(__('No Results were found'));
|
||||
}
|
||||
$this->view->assign('groupList', build_select('row[group_id]', \app\admin\model\UserGroup::column('id,name'), $row['group_id'], ['class' => 'form-control selectpicker']));
|
||||
return parent::edit($ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function del($ids = "")
|
||||
{
|
||||
if (!$this->request->isPost()) {
|
||||
$this->error(__("Invalid parameters"));
|
||||
}
|
||||
$ids = $ids ? $ids : $this->request->post("ids");
|
||||
$row = $this->model->get($ids);
|
||||
$this->modelValidate = true;
|
||||
if (!$row) {
|
||||
$this->error(__('No Results were found'));
|
||||
}
|
||||
Auth::instance()->delete($row['id']);
|
||||
$this->success();
|
||||
}
|
||||
|
||||
}
|
||||
203
application/admin/controller/wdsxh/Album.php
Normal file
203
application/admin/controller/wdsxh/Album.php
Normal file
@@ -0,0 +1,203 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdsxh.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\controller\wdsxh;
|
||||
|
||||
use app\admin\model\wdsxh\AlbumConfig;
|
||||
use app\common\controller\Backend;
|
||||
use think\Db;
|
||||
use think\exception\DbException;
|
||||
use think\exception\PDOException;
|
||||
use think\exception\ValidateException;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* 相册管理
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class Album extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Album模型对象
|
||||
* @var \app\admin\model\wdsxh\Album
|
||||
*/
|
||||
protected $model = null;
|
||||
protected $modelConfig = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\Album;
|
||||
$this->modelConfig = new AlbumConfig();
|
||||
$this->view->assign("typeList", $this->model->getTypeList());
|
||||
$this->view->assign("statusList", $this->model->getStatusList());
|
||||
$this->view->assign("IsStatusList", $this->modelConfig->getIsStatusList());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
||||
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
||||
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
||||
*/
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
if ($params['type'] == 2){
|
||||
if ($params['image'] == ''){
|
||||
$this->error('请选择视频封面');
|
||||
}
|
||||
}
|
||||
if ($params['type'] == 1){
|
||||
$params['files'] = $params['images'];
|
||||
}else{
|
||||
$params['files'] = $params['video'];
|
||||
}
|
||||
$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 ($params['type'] == 2){
|
||||
if ($params['image'] == ''){
|
||||
$this->error('请选择视频封面');
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
if ($params['type'] == 1){
|
||||
$params['files'] = $params['images'];
|
||||
}else{
|
||||
$params['files'] = $params['video'];
|
||||
}
|
||||
$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 album_config(){
|
||||
$row = $this->modelConfig->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);
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
220
application/admin/controller/wdsxh/Banner.php
Normal file
220
application/admin/controller/wdsxh/Banner.php
Normal file
@@ -0,0 +1,220 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdsxh.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\controller\wdsxh;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use think\Db;
|
||||
use think\exception\DbException;
|
||||
use think\exception\PDOException;
|
||||
use think\exception\ValidateException;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* 轮播管理
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class Banner extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Banner模型对象
|
||||
* @var \app\admin\model\wdsxh\Banner
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\Banner;
|
||||
$this->view->assign("jumpTypeList", $this->model->getJumpTypeList());
|
||||
$this->view->assign("statusList", $this->model->getStatusList());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
||||
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
||||
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @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;
|
||||
switch ($params['jump_type']){
|
||||
case 2:
|
||||
if(empty($params['jump_link'])){
|
||||
$this->error('页面路径不能为空');
|
||||
}
|
||||
if(stripos($params['jump_link'],'?') !== false){
|
||||
$params['content']=empty($params['param'])?$params['jump_link']:$params['jump_link'].'&'.$params['param'];
|
||||
}else{
|
||||
$params['content']=empty($params['param'])?$params['jump_link']:$params['jump_link'].'?'.$params['param'];
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if(empty($params['content'])){
|
||||
$this->error('图文内容不能为空');
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if(empty($params['wxapp']['appid'])){
|
||||
$this->error('小程序Appid不能为空');
|
||||
}
|
||||
$params['content']=json_encode(array('appid'=>$params['wxapp']['appid'],'path'=>$params['wxapp']['path']));
|
||||
break;
|
||||
case 4:
|
||||
if(empty($params['jump_h5'])){
|
||||
$this->error('外部链接不能为空');
|
||||
}
|
||||
$params['content']=trim($params['jump_h5']);
|
||||
break;
|
||||
}
|
||||
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()) {
|
||||
$row=$row->toArray();
|
||||
switch ($row['jump_type']){
|
||||
case 2:
|
||||
$temp=explode('?',$row['content']);
|
||||
$row['jump_link']=$temp['0'];
|
||||
$row['param']=empty($temp['1'])?null:$temp['1'];
|
||||
$row['content']=null;
|
||||
break;
|
||||
case 3:
|
||||
$temp=json_decode($row['content'],true);
|
||||
$row['wxapp']['appid']=$temp['appid'];
|
||||
$row['wxapp']['path']=$temp['path'];
|
||||
$row['content']=null;
|
||||
break;
|
||||
case 4:
|
||||
$row['jump_h5']= $row['content'];
|
||||
$row['content']=null;
|
||||
break;
|
||||
}
|
||||
$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;
|
||||
switch ($params['jump_type']){
|
||||
case 2:
|
||||
if(empty($params['jump_link'])){
|
||||
$this->error('页面路径不能为空');
|
||||
}
|
||||
if(stripos($params['jump_link'],'?') !== false){
|
||||
$params['content']=empty($params['param'])?$params['jump_link']:$params['jump_link'].'&'.$params['param'];
|
||||
}else{
|
||||
$params['content']=empty($params['param'])?$params['jump_link']:$params['jump_link'].'?'.$params['param'];
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if(empty($params['content'])){
|
||||
$this->error('图文内容不能为空');
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if(empty($params['wxapp']['appid'])){
|
||||
$this->error('小程序Appid不能为空');
|
||||
}
|
||||
$params['content']=json_encode(array('appid'=>$params['wxapp']['appid'],'path'=>$params['wxapp']['path']));
|
||||
break;
|
||||
case 4:
|
||||
if(empty($params['jump_h5'])){
|
||||
$this->error('外部链接不能为空');
|
||||
}
|
||||
$params['content']=trim($params['jump_h5']);
|
||||
break;
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
84
application/admin/controller/wdsxh/CompanyGoods.php
Normal file
84
application/admin/controller/wdsxh/CompanyGoods.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\wdsxh;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use think\exception\DbException;
|
||||
use think\response\Json;
|
||||
|
||||
/**
|
||||
* 企业产品维护
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class CompanyGoods extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* CompanyGoods模型对象
|
||||
* @var \app\admin\model\wdsxh\CompanyGoods
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\CompanyGoods;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有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();
|
||||
$memberIdWhere = [];
|
||||
$param = $this->request->get();
|
||||
if(isset($param['member_id']) && !empty($param['member_id'])) {
|
||||
$memberIdWhere['member_id'] = array('eq',$param['member_id']);
|
||||
}
|
||||
$list = $this->model
|
||||
->where($where)
|
||||
->where($memberIdWhere)
|
||||
->order($sort, $order)
|
||||
->paginate($limit);
|
||||
$result = ['total' => $list->total(), 'rows' => $list->items()];
|
||||
return json($result);
|
||||
}
|
||||
|
||||
public function multi($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
public function add($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
143
application/admin/controller/wdsxh/Config.php
Normal file
143
application/admin/controller/wdsxh/Config.php
Normal file
@@ -0,0 +1,143 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdsxh.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\controller\wdsxh;
|
||||
use Exception;
|
||||
use app\common\controller\Backend;
|
||||
use think\Db;
|
||||
use think\exception\PDOException;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
/**
|
||||
* 系统配置
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class Config extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Config模型对象
|
||||
* @var \app\admin\model\wdsxh\Config
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\Config;
|
||||
$this->view->assign("organizeList", $this->model->getOrganizeList());
|
||||
$this->view->assign("jumpTypeList", $this->model->getJumpTypeList());
|
||||
$this->view->assign("securityTextSwitchList", $this->model->getSecurityTextSwitchList());//todo 腾讯校验增加开关
|
||||
$this->view->assign("DeliveryManagementList", $this->model->getDeliveryManagementList());
|
||||
$this->view->assign("dataScreenPasswordSwitchList", $this->model->getDataScreenPasswordSwitchList());
|
||||
}
|
||||
|
||||
public function index(){
|
||||
$row = $this->model->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);
|
||||
return $this->view->fetch();
|
||||
}
|
||||
$params = $this->request->post('row/a');
|
||||
if (empty($params)) {
|
||||
$this->error(__('Parameter %s can not be empty', ''));
|
||||
}
|
||||
// 新增后端必填校验
|
||||
if (empty($params['organize'])) {
|
||||
$this->error('适用组织不能为空');
|
||||
}
|
||||
if (empty($params['share_title'])) {
|
||||
$this->error('分享标题不能为空');
|
||||
}
|
||||
$params = $this->preExcludeFields($params);
|
||||
if (isset($params['jump_type'])) {
|
||||
$jump_type = $params['jump_type'];
|
||||
if ($jump_type == 2 && empty($params['call_mobile'])) {
|
||||
$this->error('请输入拨打的电话');
|
||||
}
|
||||
if ($jump_type == 3 && empty($params['jump_link'])) {
|
||||
$this->error('请输入外部链接');
|
||||
}
|
||||
if ($jump_type == 2) {
|
||||
$params['jump_link'] = '';
|
||||
}
|
||||
if ($jump_type == 3) {
|
||||
$params['call_mobile'] = '';
|
||||
}
|
||||
if ($jump_type == 1) {
|
||||
$params['jump_link'] = '';
|
||||
$params['call_mobile'] = '';
|
||||
}
|
||||
} else {
|
||||
$params['jump_link'] = '';
|
||||
$params['call_mobile'] = '';
|
||||
}
|
||||
if (isset($params['data_screen_password_switch']) && $params['data_screen_password_switch'] == 1 && isset($params['data_screen_password']) && empty($params['data_screen_password'])) {
|
||||
$this->error('数据大屏密码不能为空');
|
||||
}
|
||||
$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();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
||||
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
||||
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
||||
*/
|
||||
|
||||
public function multi($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function del($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function edit($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
107
application/admin/controller/wdsxh/Dashboard.php
Normal file
107
application/admin/controller/wdsxh/Dashboard.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\wdsxh;
|
||||
|
||||
use app\admin\model\User;
|
||||
use app\admin\model\wdsxh\member\MemberApply;
|
||||
use app\admin\model\wdsxh\member\Pay;
|
||||
use app\common\controller\Backend;
|
||||
use app\common\model\Attachment;
|
||||
use fast\Date;
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* 控制台
|
||||
*
|
||||
* @icon fa fa-dashboard
|
||||
* @remark 用于展示当前系统中的统计数据、统计报表及重要实时数据
|
||||
*/
|
||||
class Dashboard extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* 查看
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
try {
|
||||
\think\Db::execute("SET @@sql_mode='';");
|
||||
} catch (\Exception $e) {
|
||||
|
||||
}
|
||||
$column = [];
|
||||
$starttime = Date::unixtime('day', -6);
|
||||
$endtime = Date::unixtime('day', 0, 'end');
|
||||
$joinlist = Db("user")->where('jointime', 'between time', [$starttime, $endtime])
|
||||
->field('jointime, status, COUNT(*) AS nums, DATE_FORMAT(FROM_UNIXTIME(jointime), "%Y-%m-%d") AS join_date')
|
||||
->group('join_date')
|
||||
->select();
|
||||
for ($time = $starttime; $time <= $endtime;) {
|
||||
$column[] = date("Y-m-d", $time);
|
||||
$time += 86400;
|
||||
}
|
||||
$userlist = array_fill_keys($column, 0);
|
||||
foreach ($joinlist as $k => $v) {
|
||||
$userlist[$v['join_date']] = $v['nums'];
|
||||
}
|
||||
|
||||
$dbTableList = Db::query("SHOW TABLE STATUS");
|
||||
$totalworkingaddon = 0;
|
||||
$current_date = date('Y-m-d',time());
|
||||
$member_count = (new \app\api\model\wdsxh\member\Member())->where('expire_time','>=',$current_date)->count();
|
||||
$personal_count = (new \app\api\model\wdsxh\member\Member())->where('type',1)->where('expire_time','>=',$current_date)->count();
|
||||
$enterprise_count = (new \app\api\model\wdsxh\member\Member())->where('type',2)->where('expire_time','>=',$current_date)->count();
|
||||
$group_count = (new \app\api\model\wdsxh\member\Member())->where('type',3)->where('expire_time','>=',$current_date)->count();
|
||||
$memberPayModel = new Pay();
|
||||
$memberPayWhere['channel'] = array('in',['1','2']);
|
||||
$memberPayWhere['pay_method'] = array('in',['2','3','4']);
|
||||
$person_type_name = (new \app\admin\model\wdsxh\member\JoinConfig())->where('type',1)->value('name');
|
||||
if (empty($person_type_name)) {
|
||||
$person_type_name = '个人会员';
|
||||
}
|
||||
$company_type_name = (new \app\admin\model\wdsxh\member\JoinConfig())->where('type',2)->value('name');
|
||||
if (empty($person_type_name)) {
|
||||
$company_type_name = '企业会员';
|
||||
}
|
||||
$organize_type_name = (new \app\admin\model\wdsxh\member\JoinConfig())->where('type',3)->value('name');
|
||||
if (empty($person_type_name)) {
|
||||
$organize_type_name = '团体会员';
|
||||
}
|
||||
$this->view->assign([
|
||||
'totaluser' => User::count(),
|
||||
'member_count' => $member_count,
|
||||
'group_count' => $group_count,
|
||||
'enterprise_count' => $enterprise_count,
|
||||
'totalcategory' => \app\common\model\Category::count(),
|
||||
'todayusersignup' => User::whereTime('jointime', 'today')->count(),
|
||||
'todayuserlogin' => User::whereTime('logintime', 'today')->count(),
|
||||
'sevendau' => User::whereTime('jointime|logintime|prevtime', '-7 days')->count(),
|
||||
'thirtydau' => User::whereTime('jointime|logintime|prevtime', '-30 days')->count(),
|
||||
'threednu' => User::whereTime('jointime', '-3 days')->count(),
|
||||
'sevendnu' => User::whereTime('jointime', '-7 days')->count(),
|
||||
'dbtablenums' => count($dbTableList),
|
||||
'dbsize' => array_sum(array_map(function ($item) {
|
||||
return $item['Data_length'] + $item['Index_length'];
|
||||
}, $dbTableList)),
|
||||
'totalworkingaddon' => $totalworkingaddon,
|
||||
'attachmentnums' => Attachment::count(),
|
||||
'attachmentsize' => Attachment::sum('filesize'),
|
||||
'picturenums' => Attachment::where('mimetype', 'like', 'image/%')->count(),
|
||||
'picturesize' => Attachment::where('mimetype', 'like', 'image/%')->sum('filesize'),
|
||||
'personal_count' => $personal_count,
|
||||
'member_apply_pend_count'=>(new MemberApply())->where('child_state','in',['1','4'])->count(),
|
||||
'member_apply_pend_amount'=>$memberPayModel->where($memberPayWhere)->where('paid','1')->sum('fees'),
|
||||
'member_apply_paid_amount'=>$memberPayModel->where($memberPayWhere)->where('paid','2')->sum('fees'),
|
||||
'person_type_name'=>$person_type_name,
|
||||
'company_type_name'=>$company_type_name,
|
||||
'organize_type_name'=>$organize_type_name,
|
||||
|
||||
]);
|
||||
|
||||
$this->assignconfig('column', array_keys($userlist));
|
||||
$this->assignconfig('userdata', array_values($userlist));
|
||||
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
}
|
||||
44
application/admin/controller/wdsxh/Datascreen.php
Normal file
44
application/admin/controller/wdsxh/Datascreen.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力中小企业发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdadmin.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Wdadmin系统产品软件并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.wdadmin.cn
|
||||
// +----------------------------------------------------------------------
|
||||
/**
|
||||
* Class Datascreen
|
||||
* Desc 数据大屏控制器
|
||||
* Create on 2025/3/20 10:07
|
||||
* Create by wangyafang
|
||||
*/
|
||||
|
||||
namespace app\admin\controller\wdsxh;
|
||||
|
||||
|
||||
use app\common\controller\Backend;
|
||||
|
||||
class Datascreen extends Backend
|
||||
{
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
if (!is_dir(ROOT_PATH.'public'.DIRECTORY_SEPARATOR.'assets'.DIRECTORY_SEPARATOR.'addons'.DIRECTORY_SEPARATOR.'wdsxh'.DIRECTORY_SEPARATOR.'fullscreen')) {
|
||||
$this->error('请先部署数据大屏');
|
||||
} else {
|
||||
$this->redirect($this->request->domain().'/assets/addons/wdsxh/fullscreen/index.html#/?ref=addtabs',302);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
136
application/admin/controller/wdsxh/Demand.php
Normal file
136
application/admin/controller/wdsxh/Demand.php
Normal file
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdsxh.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\controller\wdsxh;
|
||||
|
||||
use app\admin\model\wdsxh\user\Wechat;
|
||||
use app\common\controller\Backend;
|
||||
use think\exception\DbException;
|
||||
use think\exception\PDOException;
|
||||
use think\exception\ValidateException;
|
||||
use think\response\Json;
|
||||
|
||||
/**
|
||||
* 需求反馈
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class Demand extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Demand模型对象
|
||||
* @var \app\admin\model\wdsxh\Demand
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\Demand;
|
||||
$this->view->assign("isAnonymityList", $this->model->getIsAnonymityList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看
|
||||
*
|
||||
* @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(['wechat'])
|
||||
->order($sort, $order)
|
||||
->paginate($limit);
|
||||
$result = ['total' => $list->total(), 'rows' => $list->items()];
|
||||
return json($result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
||||
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
||||
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
||||
*/
|
||||
|
||||
|
||||
public function details($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()) {
|
||||
$row['nickname'] = (new Wechat())->where('id',$row['wechat_id'])->value('nickname');
|
||||
if ($row['image']){
|
||||
$row['image'] = wdsxh_full_url($row['image']);
|
||||
}
|
||||
$this->view->assign('row', $row);
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function multi($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function edit($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc 处理
|
||||
* Create on 2025/3/12 16:47
|
||||
* Create by wangyafang
|
||||
*/
|
||||
public function processing($ids=null){
|
||||
$demandObj = $this->model->get($ids);
|
||||
if ($demandObj['status'] == 1) {
|
||||
$this->error('已处理');
|
||||
}
|
||||
try {
|
||||
$demandObj->status = 1;
|
||||
$demandObj->processing_time = time();
|
||||
$demandObj->save();
|
||||
$this->success('操作成功');
|
||||
} catch (ValidateException|PDOException|Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
320
application/admin/controller/wdsxh/DiyPage.php
Normal file
320
application/admin/controller/wdsxh/DiyPage.php
Normal file
@@ -0,0 +1,320 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\wdsxh;
|
||||
|
||||
use app\admin\model\wdsxh\article\Article;
|
||||
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;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* 首页diy
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class DiyPage extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* DiyPage模型对象
|
||||
* @var \app\admin\model\wdsxh\DiyPage
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\DiyPage;
|
||||
$this->view->assign("statusList", $this->model->getStatusList());
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function add()
|
||||
{
|
||||
if (false === $this->request->isPost()) {
|
||||
$defaultData = json_encode($this->model->getDefaultStyle($this->request->scheme()));
|
||||
$jsonPageData = json_encode(['page' => $this->model->getDefaultPageData(), 'items' => []]);
|
||||
$this->assign('defaultData',$defaultData);
|
||||
$this->assign('jsonPageData',$jsonPageData);
|
||||
$article_list = (new Article())->where('status','1')->order('weigh desc,id desc')->field('title,image')->limit(3)->select();
|
||||
foreach ($article_list as &$v) {
|
||||
$v->image = wdsxh_full_url($v->image);
|
||||
}
|
||||
$this->assign('article_list',$article_list);
|
||||
return $this->view->fetch();
|
||||
}
|
||||
$post = $this->request->post('data');
|
||||
if (empty($post)) {
|
||||
$this->error(__('Parameter %s can not be empty', ''));
|
||||
}
|
||||
if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
|
||||
$params[$this->dataLimitField] = $this->auth->id;
|
||||
}
|
||||
$result = false;
|
||||
$count = $this->model->count();
|
||||
$post = json_decode($post,true);
|
||||
$page_name = $post['page']['params']['name'];
|
||||
$post = json_encode($post);
|
||||
if ($count > 0){
|
||||
$params = [
|
||||
'status' => 'custom',
|
||||
'page_name' => $page_name,
|
||||
'page_data' => $post
|
||||
];
|
||||
}else{
|
||||
$params = [
|
||||
'status' => 'home',
|
||||
'page_name' => $page_name,
|
||||
'page_data' => $post
|
||||
];
|
||||
}
|
||||
|
||||
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'));
|
||||
}
|
||||
|
||||
if (!$this->request->isAjax()) {
|
||||
$defaultData = json_encode($this->model->getDefaultStyle($this->request->scheme()));
|
||||
$jsonPageData = $row['page_data'];
|
||||
$this->assign('defaultData',$defaultData);
|
||||
$this->assign('jsonPageData',$jsonPageData);
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
$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();
|
||||
}
|
||||
$post = $this->request->post('data');
|
||||
if (empty($post)) {
|
||||
$this->error(__('Parameter %s can not be empty', ''));
|
||||
}
|
||||
$post = json_decode($post,true);
|
||||
$page_name = $post['page']['params']['name'];
|
||||
$post = json_encode($post);
|
||||
$params['page_data'] = $post;
|
||||
$params['page_name'] = $page_name;
|
||||
$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('修改成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 选择URL
|
||||
*/
|
||||
public function select_url_pro()
|
||||
{
|
||||
$list = $this->model->getLinkUrl();
|
||||
$list['Inlay']['list'] = [];
|
||||
|
||||
$pagelist = $this->model->getInlayList();
|
||||
foreach ($pagelist as $k => $v) {
|
||||
array_push($list['Inlay']['list'], ['id' => $v['id'], 'title' => $v['page_name'], 'path' => '/pages/diy/index?page_id=' . $v['id']]);
|
||||
}
|
||||
$result = array("rows" => $list);
|
||||
return json($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 选择文章分类
|
||||
*/
|
||||
public function get_article_category()
|
||||
{
|
||||
$list = $this->model->getArticleCategory();
|
||||
$result = array("rows" => $list);
|
||||
return json($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 选择供需分类
|
||||
*/
|
||||
public function get_demand_category()
|
||||
{
|
||||
$list = $this->model->getDemandCategory();
|
||||
$result = array("rows" => $list);
|
||||
return json($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示富文本
|
||||
*/
|
||||
public function editor()
|
||||
{
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设为首页
|
||||
*/
|
||||
public function set_home()
|
||||
{
|
||||
$id = $this->request->param('ids');
|
||||
$result = false;
|
||||
$where['id'] = array('not in',[$id]);
|
||||
Db::startTrans();
|
||||
try {
|
||||
$this->model->where('id',$id)->update([
|
||||
'status'=>'home',
|
||||
]);
|
||||
$result = $this->model->where($where)->update([
|
||||
'status'=>'custom',
|
||||
]);
|
||||
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 select_home_mode(){
|
||||
$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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @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 = $this->model->count();
|
||||
if ($count == 1) {
|
||||
$this->error('装修页面至少要保留一个');
|
||||
}
|
||||
|
||||
$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'));
|
||||
}
|
||||
|
||||
}
|
||||
45
application/admin/controller/wdsxh/Faq.php
Normal file
45
application/admin/controller/wdsxh/Faq.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdsxh.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\controller\wdsxh;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
|
||||
/**
|
||||
* 常见问题
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class Faq extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Faq模型对象
|
||||
* @var \app\admin\model\wdsxh\Faq
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\Faq;
|
||||
$this->view->assign("statusList", $this->model->getStatusList());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
||||
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
||||
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
341
application/admin/controller/wdsxh/Jielong.php
Normal file
341
application/admin/controller/wdsxh/Jielong.php
Normal file
@@ -0,0 +1,341 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdsxh.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\controller\wdsxh;
|
||||
use app\admin\model\wdsxh\member\Member;
|
||||
use EasyWeChat\Factory;
|
||||
use Exception;
|
||||
use app\common\controller\Backend;
|
||||
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 Jielong extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Jielong模型对象
|
||||
* @var \app\admin\model\wdsxh\Jielong
|
||||
*/
|
||||
protected $model = null;
|
||||
protected $feedbackModel = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\Jielong;
|
||||
$this->feedbackModel = new \app\admin\model\wdsxh\JielongFeedback;
|
||||
$this->view->assign("typeList", $this->model->getTypeList());
|
||||
$this->view->assign("statusList", $this->model->getStatusList());
|
||||
$current_date = date('Y-m-d',time());
|
||||
$memberObj = (new Member())->where('expire_time','>=',$current_date)->field('id,name')->order('id desc')->select();
|
||||
$memberIdArray = array_map(function ($item) {
|
||||
return $item->toArray();
|
||||
}, $memberObj);
|
||||
$memberdata = [0 => ['id' => '-1', 'name' => '平台']];
|
||||
foreach ($memberIdArray as $k => $v) {
|
||||
$memberdata[$v['id']] = $v;
|
||||
}
|
||||
$this->view->assign("memberList", $memberdata);
|
||||
$this->view->assign("jielongAuthList", $this->model->getJielongAuthList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看
|
||||
*
|
||||
* @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);
|
||||
foreach ($list as $item){
|
||||
if ($item['member_id'] == -1){
|
||||
$item->member_name = '平台';
|
||||
}else{
|
||||
$item->member_name = (new Member())->where('id',$item['member_id'])->value('name');
|
||||
}
|
||||
}
|
||||
$result = ['total' => $list->total(), 'rows' => $list->items()];
|
||||
return json($result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
||||
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
||||
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @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 ($params['type'] == 2 && $params['member_ids'] == ''){
|
||||
$this->error('请选择接龙会员');
|
||||
}
|
||||
$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()) {
|
||||
$show_applet_jielong_qrcode = 2;
|
||||
$applet_jielong_qrcode_path = '';
|
||||
$save_path = '/uploads/wdsxh/applet_jielong_qrcode/'.$row['id'].'/'.$row['createtime'].'.png';
|
||||
if (is_file(ROOT_PATH."public".$save_path)) {
|
||||
$applet_jielong_qrcode_path = $this->request->domain().$save_path;
|
||||
$show_applet_jielong_qrcode = 1;
|
||||
} else {
|
||||
$configObj = (new \app\admin\model\wdsxh\Config())->where('id',1)->find();
|
||||
if (!empty($configObj['applet_appid']) && !empty($configObj['applet_secret'])) {
|
||||
$path = 'pagesTools/sequence/details';
|
||||
$config = [
|
||||
'app_id' => $configObj['applet_appid'],
|
||||
'secret' => $configObj['applet_secret'],
|
||||
'response_type' => 'array',
|
||||
'log' => [
|
||||
'level' => 'debug',
|
||||
],
|
||||
];
|
||||
|
||||
$app = Factory::miniProgram($config);
|
||||
|
||||
$response = $app->app_code->getUnlimit($ids, [
|
||||
'page' => $path,
|
||||
]);
|
||||
|
||||
if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) {
|
||||
$response->saveAs('uploads/wdsxh/applet_jielong_qrcode/'.$row['id'], $row['createtime'].'.png');
|
||||
$applet_jielong_qrcode_path = $this->request->domain().$save_path;
|
||||
$show_applet_jielong_qrcode = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->view->assign('show_applet_jielong_qrcode', $show_applet_jielong_qrcode);
|
||||
$this->view->assign('applet_jielong_qrcode_path', $applet_jielong_qrcode_path);
|
||||
$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 ($params['type'] == 2 && $params['member_ids'] == ''){
|
||||
$this->error('请选择接龙会员');
|
||||
}
|
||||
$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();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 复制接龙
|
||||
*/
|
||||
public function copy_relay($ids = null){
|
||||
if(!$this->request->isPost()) {
|
||||
$this->error('请求类型错误');
|
||||
}
|
||||
|
||||
$row = $this->model->get($ids);
|
||||
if (!$row) {
|
||||
$this->error(__('No Results were found'));
|
||||
}
|
||||
$data = [
|
||||
'name' => $row['name'],
|
||||
'member_id' => $row['member_id'],
|
||||
'type' => $row['type'],
|
||||
'expire_time' => $row['expire_time'],
|
||||
'member_ids' => $row['member_ids'],
|
||||
'content' => $row['content'],
|
||||
'createtime' => time(),
|
||||
];
|
||||
$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($data);
|
||||
Db::commit();
|
||||
} catch (ValidateException|PDOException|Exception $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
if ($result === false) {
|
||||
$this->error(__('No rows were inserted'));
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
|
||||
public function lists(){
|
||||
// 获取自定义按钮传递的questionnaire_id
|
||||
$jielong_id = input('jielong_id', 0, 'intval');
|
||||
//设置过滤方法
|
||||
$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->feedbackModel
|
||||
->where('jielong_id',$jielong_id)
|
||||
->order('id desc')
|
||||
->paginate($limit);
|
||||
$result = ['total' => $list->total(), 'rows' => $list->items()];
|
||||
return json($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc 分享图片
|
||||
* Create on 2024/4/8 16:08
|
||||
* Create by @小趴菜
|
||||
*/
|
||||
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);
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
45
application/admin/controller/wdsxh/Link.php
Normal file
45
application/admin/controller/wdsxh/Link.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdsxh.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\controller\wdsxh;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
|
||||
/**
|
||||
* 链接管理
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class Link extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Link模型对象
|
||||
* @var \app\admin\model\wdsxh\Link
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\Link;
|
||||
$this->view->assign("statusList", $this->model->getStatusList());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
||||
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
||||
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
46
application/admin/controller/wdsxh/PcBanner.php
Normal file
46
application/admin/controller/wdsxh/PcBanner.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdsxh.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\controller\wdsxh;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
|
||||
/**
|
||||
* 轮播管理
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class PcBanner extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* PcBanner模型对象
|
||||
* @var \app\admin\model\wdsxh\PcBanner
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\PcBanner;
|
||||
$this->view->assign("statusList", $this->model->getStatusList());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
||||
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
||||
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
109
application/admin/controller/wdsxh/PcBusinessAssociation.php
Normal file
109
application/admin/controller/wdsxh/PcBusinessAssociation.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdsxh.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\controller\wdsxh;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use think\Db;
|
||||
use think\exception\PDOException;
|
||||
use think\exception\ValidateException;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* 商协信息(pc端)
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class PcBusinessAssociation extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* PcBusinessAssociation模型对象
|
||||
* @var \app\admin\model\wdsxh\PcBusinessAssociation
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\PcBusinessAssociation;
|
||||
|
||||
}
|
||||
|
||||
public function index(){
|
||||
$row = $this->model->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);
|
||||
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);
|
||||
}
|
||||
$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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
||||
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
||||
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
||||
*/
|
||||
|
||||
public function multi($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function del($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function edit($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
123
application/admin/controller/wdsxh/PersonCenterDiyPage.php
Normal file
123
application/admin/controller/wdsxh/PersonCenterDiyPage.php
Normal file
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\wdsxh;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use think\Db;
|
||||
use think\exception\PDOException;
|
||||
use think\exception\ValidateException;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* 首页diy
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class PersonCenterDiyPage extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* PersonCenterDiyPage模型对象
|
||||
* @var \app\admin\model\wdsxh\PersonCenterDiyPage
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\PersonCenterDiyPage;
|
||||
$this->view->assign("statusList", $this->model->getStatusList());
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$row = $this->model->get(1);
|
||||
if (!$row) {
|
||||
$this->error(__('No Results were found'));
|
||||
}
|
||||
|
||||
if (!$this->request->isAjax()) {
|
||||
$defaultData = json_encode($this->model->getDefaultPageData($this->request->scheme()));
|
||||
$jsonPageData = $row['page_data'];
|
||||
if (empty($jsonPageData)) {
|
||||
$jsonPageData = json_encode($this->model->getDefaultPageData());
|
||||
}
|
||||
$this->assign('defaultData',$defaultData);
|
||||
$this->assign('jsonPageData',$jsonPageData);
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
$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();
|
||||
}
|
||||
$post = $this->request->post('data');
|
||||
if (empty($post)) {
|
||||
$this->error(__('Parameter %s can not be empty', ''));
|
||||
}
|
||||
$post = json_decode($post,true);
|
||||
$page_name = $post['pageTitle'];
|
||||
$post = json_encode($post);
|
||||
$params['page_data'] = $post;
|
||||
$params['page_name'] = $page_name;
|
||||
$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('修改成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 选择URL
|
||||
*/
|
||||
public function select_url_pro()
|
||||
{
|
||||
$list = $this->model->getLinkUrl();
|
||||
|
||||
$result = array("rows" => $list);
|
||||
return json($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示富文本
|
||||
*/
|
||||
public function editor()
|
||||
{
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function add()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function del($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function multi($ids = NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
258
application/admin/controller/wdsxh/Quickmenu.php
Normal file
258
application/admin/controller/wdsxh/Quickmenu.php
Normal file
@@ -0,0 +1,258 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdsxh.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\controller\wdsxh;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use Exception;
|
||||
use think\Db;
|
||||
use think\exception\DbException;
|
||||
use think\exception\PDOException;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
/**
|
||||
* 快速导航
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class Quickmenu extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Quickmenu模型对象
|
||||
* @var \app\admin\model\wdsxh\Quickmenu
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\Quickmenu;
|
||||
$this->view->assign("skipTypeList", $this->model->getSkipTypeList());
|
||||
$this->view->assign("statusList", $this->model->getStatusList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//当前是否为关联查询
|
||||
$this->relationSearch = false;
|
||||
//设置过滤方法
|
||||
$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($where)
|
||||
->order($sort, $order)
|
||||
->paginate($limit);
|
||||
|
||||
foreach ($list as $row) {
|
||||
$row->visible(['id','name','icon','skip_type','weigh','status','createtime']);
|
||||
|
||||
}
|
||||
|
||||
$result = array("total" => $list->total(), "rows" => $list->items());
|
||||
|
||||
return json($result);
|
||||
}
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
||||
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
||||
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
||||
*/
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
switch ($params['skip_type']){
|
||||
case 1:
|
||||
if(empty($params['path'])){
|
||||
$this->error('页面路径不能为空');
|
||||
}
|
||||
if(stripos($params['path'],'?') !== false){
|
||||
$params['content']=$params['path'].'&'.$params['param'];
|
||||
}else{
|
||||
$params['content']=$params['path'].'?'.$params['param'];
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if(empty($params['content'])){
|
||||
$this->error('图文内容不能为空');
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if(empty($params['wxapp']['appid'])){
|
||||
$this->error('小程序Appid不能为空');
|
||||
}
|
||||
if(empty($params['wxapp']['path'])){
|
||||
$this->error('小程序页面路径不能为空');
|
||||
}
|
||||
$params['content']=json_encode(array('appid'=>$params['wxapp']['appid'],'path'=>$params['wxapp']['path']));
|
||||
break;
|
||||
case 4:
|
||||
if(empty($params['url'])){
|
||||
$this->error('外部链接不能为空');
|
||||
}
|
||||
$params['content']=trim($params['url']);
|
||||
break;
|
||||
}
|
||||
|
||||
$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()) {
|
||||
$row=$row->toArray();
|
||||
switch ($row['skip_type']){
|
||||
case 1:
|
||||
$temp=explode('?',$row['content']);
|
||||
$row['path']=$temp['0'];
|
||||
$row['param']=empty($temp['1'])?null:$temp['1'];
|
||||
$row['content']=null;
|
||||
break;
|
||||
case 3:
|
||||
$temp=json_decode($row['content'],true);
|
||||
$row['wxapp']['appid']=$temp['appid'];
|
||||
$row['wxapp']['path']=$temp['path'];
|
||||
$row['content']=null;
|
||||
break;
|
||||
case 4:
|
||||
$row['url']= $row['content'];
|
||||
$row['content']=null;
|
||||
break;
|
||||
}
|
||||
$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);
|
||||
switch ($params['skip_type']){
|
||||
case 1:
|
||||
if(empty($params['path'])){
|
||||
$this->error('页面路径不能为空');
|
||||
}
|
||||
if(stripos($params['path'],'?') !== false){
|
||||
$params['content']=empty($params['param'])?$params['path']:$params['path'].'&'.$params['param'];
|
||||
}else{
|
||||
$params['content']=empty($params['param'])?$params['path']:$params['path'].'?'.$params['param'];
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if(empty($params['content'])){
|
||||
$this->error('图文内容不能为空');
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if(empty($params['wxapp']['appid'])){
|
||||
$this->error('小程序Appid不能为空');
|
||||
}
|
||||
if(empty($params['wxapp']['path'])){
|
||||
$this->error('小程序页面路径不能为空');
|
||||
}
|
||||
$params['content']=json_encode(array('appid'=>$params['wxapp']['appid'],'path'=>$params['wxapp']['path']));
|
||||
break;
|
||||
case 4:
|
||||
if(empty($params['url'])){
|
||||
$this->error('外部链接不能为空');
|
||||
}
|
||||
$params['content']=trim($params['url']);
|
||||
break;
|
||||
}
|
||||
$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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
216
application/admin/controller/wdsxh/Tabbar.php
Normal file
216
application/admin/controller/wdsxh/Tabbar.php
Normal file
@@ -0,0 +1,216 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdsxh.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\controller\wdsxh;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use think\Db;
|
||||
use think\exception\DbException;
|
||||
use think\exception\PDOException;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
/**
|
||||
* 底部导航
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class Tabbar extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Tabbar模型对象
|
||||
* @var \app\admin\model\wdsxh\Tabbar
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\Tabbar;
|
||||
$this->view->assign("statusList", $this->model->getStatusList());
|
||||
$this->view->assign("jumpTypeList", $this->model->getJumpTypeList());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
||||
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
||||
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
||||
*/
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @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;
|
||||
switch ($params['jump_type']){
|
||||
case 2:
|
||||
if(empty($params['jump_link'])){
|
||||
$this->error('页面路径不能为空');
|
||||
}
|
||||
if(stripos($params['jump_link'],'?') !== false){
|
||||
$params['path']=empty($params['param'])?$params['jump_link']:$params['jump_link'].'&'.$params['param'];
|
||||
}else{
|
||||
$params['path']=empty($params['param'])?$params['jump_link']:$params['jump_link'].'?'.$params['param'];
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if(empty($params['path'])){
|
||||
$this->error('图文内容不能为空');
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if(empty($params['wxapp']['appid'])){
|
||||
$this->error('小程序Appid不能为空');
|
||||
}
|
||||
$params['path']=json_encode(array('appid'=>$params['wxapp']['appid'],'path'=>$params['wxapp']['path']));
|
||||
break;
|
||||
case 3:
|
||||
if(empty($params['jump_h5'])){
|
||||
$this->error('外部链接不能为空');
|
||||
}
|
||||
$params['path']=trim($params['jump_h5']);
|
||||
break;
|
||||
}
|
||||
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()) {
|
||||
$row=$row->toArray();
|
||||
switch ($row['jump_type']){
|
||||
case 2:
|
||||
$temp=explode('?',$row['path']);
|
||||
$row['jump_link']=$temp['0'];
|
||||
$row['param']=empty($temp['1'])?null:$temp['1'];
|
||||
$row['path']=null;
|
||||
break;
|
||||
case 4:
|
||||
$temp=json_decode($row['path'],true);
|
||||
$row['wxapp']['appid']=$temp['appid'];
|
||||
$row['wxapp']['path']=$temp['path'];
|
||||
$row['path']=null;
|
||||
break;
|
||||
case 3:
|
||||
$row['jump_h5']= $row['path'];
|
||||
$row['path']=null;
|
||||
break;
|
||||
}
|
||||
$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;
|
||||
switch ($params['jump_type']){
|
||||
case 2:
|
||||
if(empty($params['jump_link'])){
|
||||
$this->error('页面路径不能为空');
|
||||
}
|
||||
if(stripos($params['jump_link'],'?') !== false){
|
||||
$params['path']=empty($params['param'])?$params['jump_link']:$params['jump_link'].'&'.$params['param'];
|
||||
}else{
|
||||
$params['path']=empty($params['param'])?$params['jump_link']:$params['jump_link'].'?'.$params['param'];
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if(empty($params['path'])){
|
||||
$this->error('图文内容不能为空');
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if(empty($params['wxapp']['appid'])){
|
||||
$this->error('小程序Appid不能为空');
|
||||
}
|
||||
$params['path']=json_encode(array('appid'=>$params['wxapp']['appid'],'path'=>$params['wxapp']['path']));
|
||||
break;
|
||||
case 3:
|
||||
if(empty($params['jump_h5'])){
|
||||
$this->error('外部链接不能为空');
|
||||
}
|
||||
$params['path']=trim($params['jump_h5']);
|
||||
break;
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
394
application/admin/controller/wdsxh/Upgrade.php
Normal file
394
application/admin/controller/wdsxh/Upgrade.php
Normal file
@@ -0,0 +1,394 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\controller\wdsxh;
|
||||
use Exception;
|
||||
use app\common\controller\Backend;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\TransferException;
|
||||
use think\addons\AddonException;
|
||||
use think\addons\Service;
|
||||
use think\Cache;
|
||||
|
||||
/**
|
||||
* 检查更新
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class Upgrade extends Backend
|
||||
{
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
}
|
||||
|
||||
public function index(){
|
||||
$name = 'wdsxh';
|
||||
$info = get_addon_info($name);
|
||||
$client = self::getClient();
|
||||
$domain = $client->get('/api/product/version/code', ['query' => array_merge(['domain' => $_SERVER['HTTP_HOST']])]);
|
||||
$body_domain = $domain->getBody();
|
||||
$content_domain = $body_domain->getContents();
|
||||
$content_domain = trim($content_domain, '"');
|
||||
$product_info = array(
|
||||
'product_name'=>'商协会系统',
|
||||
'version'=>$info['version'],
|
||||
'developers'=>'青岛麦沃德网络科技有限公司',
|
||||
'auth'=>'是',
|
||||
'code' => $content_domain,
|
||||
);
|
||||
$this->assign('product_info',$product_info);
|
||||
$this->assignconfig('old_version',$info['version']);
|
||||
$this->assignconfig('name',$info['name']);
|
||||
// $this->view->engine->layout(false);
|
||||
|
||||
$domain = $client->get('/api/product/version/update_log', ['query' => array_merge(['name' => $name,'version'=>$info['version']])]);
|
||||
$body_domain = $domain->getBody();
|
||||
$content = $body_domain->getContents();
|
||||
$content = json_decode($content,true);
|
||||
|
||||
// p(ROOT_PATH.'addons'.DIRECTORY_SEPARATOR.'wdsxh'.DIRECTORY_SEPARATOR.'uniapp'.DIRECTORY_SEPARATOR.'商协会');
|
||||
$domain = $this->request->domain();
|
||||
|
||||
foreach ($content['data'] as &$v) {
|
||||
if (is_file(ROOT_PATH.'addons'.DIRECTORY_SEPARATOR.'wdsxh'.DIRECTORY_SEPARATOR.'uniapp'.DIRECTORY_SEPARATOR.'uniapp-wdsxh'.$v['version'].'.zip')) {
|
||||
$zip_url = ROOT_PATH.'addons'.DIRECTORY_SEPARATOR.'wdsxh'.DIRECTORY_SEPARATOR.'uniapp'.DIRECTORY_SEPARATOR.'uniapp-wdsxh'.$v['version'].'.zip';
|
||||
} else {
|
||||
$zip_url = '';
|
||||
}
|
||||
$v['zip_url'] = $zip_url;
|
||||
}
|
||||
$version_list = $content['data'];
|
||||
$this->assign('version_list',$version_list);
|
||||
|
||||
return $this->fetch('index');
|
||||
}
|
||||
|
||||
public function down_mini_zip()
|
||||
{
|
||||
$version = $this->request->get('version');
|
||||
|
||||
// 文件路径
|
||||
$file_path = ROOT_PATH.'addons'.DIRECTORY_SEPARATOR .'wdsxh'.DIRECTORY_SEPARATOR .'uniapp'.DIRECTORY_SEPARATOR.'uniapp-wdsxh'.$version.'.zip';
|
||||
|
||||
|
||||
// 检查文件是否存在
|
||||
if (!file_exists($file_path)) {
|
||||
die('文件不存在');
|
||||
}
|
||||
|
||||
// 设置 HTTP 头
|
||||
header('Content-Description: File Transfer');
|
||||
header('Content-Type: application/octet-stream');
|
||||
header('Content-Disposition: attachment; filename="' . basename($file_path) . '"');
|
||||
header('Expires: 0');
|
||||
header('Cache-Control: must-revalidate');
|
||||
header('Pragma: public');
|
||||
header('Content-Length: ' . filesize($file_path));
|
||||
|
||||
// 输出文件
|
||||
readfile($file_path);
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc 检查最新版本
|
||||
* Create on 2024/7/4 8:54
|
||||
* Create by zhangwei
|
||||
*/
|
||||
public function check()
|
||||
{
|
||||
$old_version = $this->request->post('old_version');
|
||||
$name = $this->request->post('name');
|
||||
$extend = [
|
||||
'oldversion' => $old_version,
|
||||
'domain'=>$this->request->domain()
|
||||
];
|
||||
$client = self::getClient();
|
||||
$response = $client->get('/api/product/version/check', ['query' => array_merge(['name' => $name , 'authorized_version'=>'2','domain' => $_SERVER['HTTP_HOST']], $extend)]);
|
||||
$body = $response->getBody();
|
||||
$content = $body->getContents();
|
||||
$json = (array)json_decode($content, true);
|
||||
|
||||
return $json;
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc 更新最新版本
|
||||
* Create on 2024/7/4 11:17
|
||||
* Create by zhangwei
|
||||
*/
|
||||
public function update()
|
||||
{
|
||||
$old_version = $this->request->post("old_version");
|
||||
$name = $this->request->post("name");
|
||||
$addonTmpDir = RUNTIME_PATH . 'addons' . DS;
|
||||
$domain = $_SERVER['HTTP_HOST'];
|
||||
if (!$name) {
|
||||
$this->error(__('Parameter %s can not be empty', 'name'));
|
||||
}
|
||||
if (!preg_match("/^[a-zA-Z0-9]+$/", $name)) {
|
||||
$this->error(__('Addon name incorrect'));
|
||||
}
|
||||
if (!is_dir($addonTmpDir)) {
|
||||
@mkdir($addonTmpDir, 0755, true);
|
||||
}
|
||||
|
||||
$info = [];
|
||||
try {
|
||||
$info = get_addon_info($name);
|
||||
$uid = $this->request->post("uid");
|
||||
$token = $this->request->post("token");
|
||||
$version = $this->request->post("version");
|
||||
$faversion = $this->request->post("faversion");
|
||||
$extend = [
|
||||
'uid' => $uid,
|
||||
'token' => $token,
|
||||
'version' => $version,
|
||||
// 'oldversion' => $info['version'] ?? '',
|
||||
'oldversion' => $old_version,
|
||||
'faversion' => $faversion,
|
||||
'domain'=>$this->request->domain()
|
||||
];
|
||||
//调用更新的方法
|
||||
$info = self::upgrade($name, $extend);
|
||||
Cache::rm('__menu__');
|
||||
} catch (AddonException $e) {
|
||||
$this->result($e->getData(), $e->getCode(), __($e->getMessage()));
|
||||
} catch (\think\Exception $e) {
|
||||
$this->error(__($e->getMessage()));
|
||||
}
|
||||
|
||||
|
||||
$this->success(__('Operate successful'), '', ['addon' => $info]);
|
||||
}
|
||||
|
||||
public function code_edit()
|
||||
{
|
||||
$param = $this->request->param();
|
||||
$client = self::getClient();
|
||||
$domain = $client->post('/api/product/version/code_edit', ['query' => array_merge(['code' => $param['code'],'domain' => $_SERVER['HTTP_HOST'],'name' => $param['name']])]);
|
||||
$body_domain = $domain->getBody();
|
||||
$content_domain = $body_domain->getContents();
|
||||
$json = (array)json_decode($content_domain, true);
|
||||
return $json;
|
||||
}
|
||||
|
||||
/**
|
||||
* 升级插件
|
||||
*
|
||||
* @param string $name 插件名称
|
||||
* @param array $extend 扩展参数
|
||||
*/
|
||||
public static function upgrade($name, $extend = [], $tmpFile = false)
|
||||
{
|
||||
$info = get_addon_info($name);
|
||||
$config = get_addon_config($name);
|
||||
if ($config) {
|
||||
//备份配置
|
||||
}
|
||||
// 远程下载插件(如果为本地文件则使用本地文件)
|
||||
// $tmpFile = $tmpFile ? $tmpFile : self::download($name, $extend);
|
||||
$downloadResult = $tmpFile ? $tmpFile : self::download($name, $extend);
|
||||
$tmpFile = $downloadResult['tmpFile'];
|
||||
$new_version = $downloadResult['new_version'];
|
||||
$version_list = $downloadResult['version_list'];
|
||||
|
||||
// 备份插件文件
|
||||
Service::backup($name);
|
||||
|
||||
$addonDir = self::getAddonDir($name);
|
||||
|
||||
// 删除插件目录下的application和public
|
||||
$files = self::getCheckDirs();
|
||||
foreach ($files as $index => $file) {
|
||||
@rmdirs($addonDir . $file);
|
||||
}
|
||||
try {
|
||||
// 解压插件
|
||||
Service::unzip($name, $tmpFile);
|
||||
} catch (Exception $e) {
|
||||
throw new Exception($e->getMessage());
|
||||
} finally {
|
||||
// 移除临时文件
|
||||
@unlink($tmpFile);
|
||||
}
|
||||
|
||||
if ($config) {
|
||||
$configFile = ADDON_PATH . $name . DS . 'config.php';
|
||||
|
||||
$bakFile = ADDON_PATH . $name . DS . 'config_tmp.php';
|
||||
@copy($configFile, $bakFile);
|
||||
$fullConfig = include($bakFile);
|
||||
@unlink($bakFile);
|
||||
foreach ($fullConfig as $index => &$item) {
|
||||
if (isset($config[$item['name']])) {
|
||||
$item['value'] = $config[$item['name']];
|
||||
}
|
||||
}
|
||||
// 更新配置
|
||||
set_addon_fullconfig($name, $fullConfig);
|
||||
}
|
||||
|
||||
// 导入
|
||||
Service::importsql($name);
|
||||
|
||||
// 执行升级脚本
|
||||
try {
|
||||
$addonName = ucfirst($name);
|
||||
//创建临时类用于调用升级的方法
|
||||
$sourceFile = $addonDir . $addonName . ".php";
|
||||
$destFile = $addonDir . $addonName . "Upgrade.php";
|
||||
|
||||
$classContent = str_replace("class {$addonName} extends", "class {$addonName}Upgrade extends", file_get_contents($sourceFile));
|
||||
|
||||
//创建临时的类文件
|
||||
file_put_contents($destFile, $classContent);
|
||||
|
||||
$className = "\\addons\\" . $name . "\\" . $addonName . "Upgrade";
|
||||
$addon = new $className($name);
|
||||
|
||||
//调用升级的方法
|
||||
if (method_exists($addon, "upgrade")) {
|
||||
$addon->upgrade();
|
||||
}
|
||||
|
||||
//移除临时文件
|
||||
@unlink($destFile);
|
||||
} catch (Exception $e) {
|
||||
throw new Exception($e->getMessage());
|
||||
}
|
||||
|
||||
// 刷新
|
||||
Service::refresh();
|
||||
|
||||
//必须变更版本号
|
||||
$info['version'] = $extend['version'] ?? $info['version'];
|
||||
|
||||
$info['config'] = get_addon_config($name) ? 1 : 0;
|
||||
$info['bootstrap'] = is_file(Service::getBootstrapFile($name));
|
||||
|
||||
Service::enable($name, true);
|
||||
set_addon_info($name, ['version'=>$new_version]);
|
||||
|
||||
if (!empty($version_list)) {
|
||||
file_put_contents(
|
||||
ADDON_PATH . $name . DS . 'config' . DS . "upgrade.php",
|
||||
'<?php' . "\n\nreturn " . var_export_short($version_list) . ";\n"
|
||||
);
|
||||
}
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 远程下载插件
|
||||
*
|
||||
* @param string $name 插件名称
|
||||
* @param array $extend 扩展参数
|
||||
* @return string
|
||||
*/
|
||||
public static function download($name, $extend = [])
|
||||
{
|
||||
$addonsTempDir = Service::getAddonsBackupDir();
|
||||
$tmpFile = $addonsTempDir . $name . ".zip";
|
||||
$new_version = '';
|
||||
$version_list = array();
|
||||
try {
|
||||
$client = self::getClient();
|
||||
$response = $client->get('/api/product/version/upgrade', ['query' => array_merge(['name' => $name , 'authorized_version'=>'2'], $extend)]);
|
||||
$body = $response->getBody();
|
||||
$content = $body->getContents();
|
||||
|
||||
if (substr($content, 0, 1) === '{') {
|
||||
$json = (array)json_decode($content, true);
|
||||
//如果传回的是一个下载链接,则再次下载
|
||||
if ($json['data'] && isset($json['data']['url'])) {
|
||||
$new_version = $json['data']['new_version'];
|
||||
$version_list = $json['data']['version_list'];
|
||||
$response = $client->get($json['data']['url']);
|
||||
$body = $response->getBody();
|
||||
$content = $body->getContents();
|
||||
} else {
|
||||
//下载返回错误,抛出异常
|
||||
throw new AddonException($json['msg'], $json['code'], $json['data']);
|
||||
}
|
||||
}
|
||||
} catch (TransferException $e) {
|
||||
throw new \think\Exception("Addon package download failed");
|
||||
}
|
||||
|
||||
if ($write = fopen($tmpFile, 'w')) {
|
||||
fwrite($write, $content);
|
||||
fclose($write);
|
||||
//return $tmpFile;
|
||||
return [
|
||||
'tmpFile'=>$tmpFile,
|
||||
'new_version'=>$new_version,
|
||||
'version_list'=>$version_list,
|
||||
];
|
||||
}
|
||||
throw new Exception("No permission to write temporary files");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取请求对象
|
||||
* @return Client
|
||||
*/
|
||||
public static function getClient()
|
||||
{
|
||||
$options = [
|
||||
'base_uri' => 'http://www.wdadmin.cn/',
|
||||
'timeout' => 30,
|
||||
'connect_timeout' => 30,
|
||||
'verify' => false,
|
||||
'http_errors' => false,
|
||||
'headers' => [
|
||||
'X-REQUESTED-WITH' => 'XMLHttpRequest',
|
||||
'Referer' => dirname(request()->root(true)),
|
||||
'User-Agent' => 'FastAddon',
|
||||
]
|
||||
];
|
||||
static $client;
|
||||
if (empty($client)) {
|
||||
$client = new Client($options);
|
||||
}
|
||||
return $client;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定插件的目录
|
||||
*/
|
||||
public static function getAddonDir($name)
|
||||
{
|
||||
$dir = ADDON_PATH . $name . DS;
|
||||
return $dir;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取检测的全局文件夹目录
|
||||
* @return array
|
||||
*/
|
||||
protected static function getCheckDirs()
|
||||
{
|
||||
return [
|
||||
'application',
|
||||
'public'
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
98
application/admin/controller/wdsxh/Willbrand.php
Normal file
98
application/admin/controller/wdsxh/Willbrand.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\wdsxh;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
/**
|
||||
* 电子会牌
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class Willbrand extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Party模型对象
|
||||
* @var \app\admin\model\wdsxh\Willbrand
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model=new \app\admin\model\wdsxh\Willbrand;
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$row=$this->model->get(1);
|
||||
if ($this->request->isPost()) {
|
||||
$params=$this->request->param('row/a');
|
||||
|
||||
// 获取会员编号设置
|
||||
$memberNumberPrefix = $this->request->param('member_number_prefix', '');
|
||||
$memberNumberSuffix = $this->request->param('member_number_suffix', '');
|
||||
|
||||
// 如果params['data']存在,解析它
|
||||
if (isset($params['data']) && !empty($params['data'])) {
|
||||
$data = json_decode($params['data'], true);
|
||||
} else {
|
||||
$data = [];
|
||||
}
|
||||
|
||||
// 添加会员编号设置到数据中
|
||||
$data['member_number_settings'] = [
|
||||
'prefix' => $memberNumberPrefix,
|
||||
'suffix' => $memberNumberSuffix,
|
||||
'generateFunction' => 'generateMemberNumber'
|
||||
];
|
||||
|
||||
// 重新编码数据
|
||||
$params['data'] = json_encode($data);
|
||||
|
||||
if(empty($row)){
|
||||
\app\admin\model\wdsxh\Willbrand::create(array('data'=>$params['data']));
|
||||
}else{
|
||||
$row->data=$params['data'];
|
||||
$row->save();
|
||||
}
|
||||
$this->success('保存成功!');
|
||||
}
|
||||
$data=$row->data;
|
||||
if(!empty($data)){
|
||||
$data=json_decode($data,true);
|
||||
}
|
||||
|
||||
// 添加默认的自定义会员编号设置
|
||||
if (!isset($data['member_number_settings'])) {
|
||||
$data['member_number_settings'] = [
|
||||
'prefix' => '',
|
||||
'suffix' => ''
|
||||
];
|
||||
}
|
||||
|
||||
$this->assign('data',$data);
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
371
application/admin/controller/wdsxh/activity/Activity.php
Normal file
371
application/admin/controller/wdsxh/activity/Activity.php
Normal file
@@ -0,0 +1,371 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdsxh.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\controller\wdsxh\activity;
|
||||
|
||||
use addons\wdsxh\library\Encryptor;
|
||||
use app\admin\model\wdsxh\Config;
|
||||
use app\common\controller\Backend;
|
||||
use EasyWeChat\Factory;
|
||||
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;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* 活动列管理
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class Activity extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Activity模型对象
|
||||
* @var \app\admin\model\wdsxh\activity\Activity
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
protected $modelValidate = true;
|
||||
protected $modelSceneValidate = true;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\activity\Activity;
|
||||
$this->view->assign("organizingMethodList", $this->model->getOrganizingMethodList());
|
||||
$this->view->assign("stateList", $this->model->getStateList());
|
||||
$this->view->assign("isVerifyingList", $this->model->getIsVerifyingList());
|
||||
$this->view->assign("statusList", $this->model->getStatusList());
|
||||
$this->view->assign("activityAuthList", $this->model->getActivityAuthList());
|
||||
$this->view->assign("nonMemberRegistrationStatusList", $this->model->getNonMemberRegistrationStatusList());
|
||||
$this->view->assign("verificationMethodList", $this->model->getVerificationMethodList());
|
||||
$this->view->assign("pointsStatusList", $this->model->getPointsStatusList());
|
||||
$configObj = (new Config())->get(1);
|
||||
$this->assignconfig('wananchi_appid',$configObj['wananchi_appid']);
|
||||
$this->assignconfig('applet_appid',$configObj['applet_appid']);
|
||||
$this->view->assign("applyFieldStateList", $this->model->getApplyFieldStateList());
|
||||
$this->view->assign("certificateEnabledList", $this->model->getCertificateEnabledList());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
||||
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
||||
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
||||
*/
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @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 ($params['is_verifying'] == 2) {
|
||||
$params['verifying_wechat_ids'] = '';
|
||||
}
|
||||
$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()) {
|
||||
$show_applet_activity_qrcode = 2;
|
||||
$applet_activity_qrcode_path = '';
|
||||
$save_path = '/uploads/wdsxh/applet_activity_qrcode/'.$row['id'].'/'.$row['createtime'].'.png';
|
||||
if (is_file(ROOT_PATH."public".$save_path)) {
|
||||
$applet_activity_qrcode_path = $this->request->domain().$save_path;
|
||||
$show_applet_activity_qrcode = 1;
|
||||
} else {
|
||||
$configObj = (new \app\admin\model\wdsxh\Config())->where('id',1)->find();
|
||||
if (!empty($configObj['applet_appid']) && !empty($configObj['applet_secret'])) {
|
||||
$path = 'pagesActivity/index/details';
|
||||
$config = [
|
||||
'app_id' => $configObj['applet_appid'],
|
||||
'secret' => $configObj['applet_secret'],
|
||||
'response_type' => 'array',
|
||||
'log' => [
|
||||
'level' => 'debug',
|
||||
],
|
||||
];
|
||||
|
||||
$app = Factory::miniProgram($config);
|
||||
|
||||
$response = $app->app_code->getUnlimit($ids, [
|
||||
'page' => $path,
|
||||
'check_path' => false,
|
||||
]);
|
||||
|
||||
if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) {
|
||||
$response->saveAs('uploads/wdsxh/applet_activity_qrcode/'.$row['id'], $row['createtime'].'.png');
|
||||
$applet_activity_qrcode_path = $this->request->domain().$save_path;
|
||||
$show_applet_activity_qrcode = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->view->assign('show_applet_activity_qrcode', $show_applet_activity_qrcode);
|
||||
$this->view->assign('applet_activity_qrcode_path', $applet_activity_qrcode_path);
|
||||
$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 ($params['is_verifying'] == 2) {
|
||||
$params['verifying_wechat_ids'] = '';
|
||||
$params['verification_method'] = 0;
|
||||
}
|
||||
if ($params['verification_method'] == 1) {
|
||||
$params['verifying_wechat_ids'] = '';
|
||||
}
|
||||
if ($params['points_status'] == 2) {
|
||||
$params['points'] = 0;
|
||||
}
|
||||
$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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @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();
|
||||
|
||||
$activityApplyModel = new \app\admin\model\wdsxh\activity\ActivityApply();
|
||||
foreach ($list as $item) {
|
||||
if ($item['state'] == '2') {
|
||||
$this->error('活动:'.$item['name'].',进行中,无法删除');
|
||||
}
|
||||
$apply_count = $activityApplyModel->where('activity_id',$item['id'])->where('state','2')->count();
|
||||
if ($item['state'] == '1' && $apply_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'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc 公众号签到二维码
|
||||
* Create on 2025/3/6 17:49
|
||||
* Create by wangyafang
|
||||
*/
|
||||
public function verification_qr_code($ids)
|
||||
{
|
||||
if (false === $this->request->isPost()) {
|
||||
$qrcode_class = 1;
|
||||
$row = $this->model->get($ids);
|
||||
$this->view->assign('row', $row);
|
||||
if (!class_exists('\Endroid\QrCode\QrCode')) {
|
||||
$qrcode_class = 2;
|
||||
} else {
|
||||
$path = $this->create_qr_code($ids,$row);
|
||||
|
||||
$this->view->assign('path', $path);
|
||||
}
|
||||
$this->view->assign('qrcode_class', $qrcode_class);
|
||||
return $this->view->fetch();
|
||||
}
|
||||
}
|
||||
|
||||
private function create_qr_code($id,$activityObj)
|
||||
{
|
||||
$activity_wananchi_sign_path_path = '';
|
||||
$domain = $this->request->domain();
|
||||
$save_path = DIRECTORY_SEPARATOR.'uploads'.DIRECTORY_SEPARATOR.'wdsxh'.DIRECTORY_SEPARATOR.'activity_wananchi_sign_path'.DIRECTORY_SEPARATOR.$id.DIRECTORY_SEPARATOR.$activityObj['createtime'].'activity.png';
|
||||
if (is_file(ROOT_PATH."public".$save_path)) {
|
||||
$activity_wananchi_sign_path_path = $this->request->domain().$save_path;
|
||||
} else {
|
||||
$token_key = config('token.key');
|
||||
$encryptor = new Encryptor(substr($token_key,0,16),substr($token_key,16));
|
||||
$validate_value = $encryptor->encrypt($id);
|
||||
$params['text'] = $this->request->get('text', $domain.'/web/#/pagesActivity/order/details?scene='.$validate_value, 'trim');
|
||||
$qrCode = \addons\qrcode\library\Service::qrcode($params);
|
||||
$qrcodePath = ROOT_PATH . 'public'.DIRECTORY_SEPARATOR.'uploads'.DIRECTORY_SEPARATOR.'wdsxh'.DIRECTORY_SEPARATOR.'activity_wananchi_sign_path'.DIRECTORY_SEPARATOR.$id.DIRECTORY_SEPARATOR;
|
||||
if (!is_dir($qrcodePath)) {
|
||||
wdsxh_mkdirs($qrcodePath);
|
||||
}
|
||||
if (is_really_writable($qrcodePath)) {
|
||||
$filePath = $qrcodePath . $activityObj['createtime'].'activity.png';
|
||||
$qrCode->writeFile($filePath);
|
||||
$save_path = DIRECTORY_SEPARATOR.'uploads'.DIRECTORY_SEPARATOR.'wdsxh'.DIRECTORY_SEPARATOR.'activity_wananchi_sign_path'.DIRECTORY_SEPARATOR.$id.DIRECTORY_SEPARATOR.$activityObj['createtime'].'activity.png';
|
||||
$activity_wananchi_sign_path_path = $this->request->domain().$save_path;
|
||||
}
|
||||
}
|
||||
return $activity_wananchi_sign_path_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc 小程序签到二维码
|
||||
* Create on 2025/3/6 17:49
|
||||
* Create by wangyafang
|
||||
*/
|
||||
public function verification_applet_code($ids)
|
||||
{
|
||||
if (false === $this->request->isPost()) {
|
||||
$row = $this->model->get($ids);
|
||||
$this->view->assign('row', $row);
|
||||
$path = $this->create_applet_code($ids,$row);
|
||||
|
||||
$this->view->assign('path', $path);
|
||||
return $this->view->fetch();
|
||||
}
|
||||
}
|
||||
|
||||
private function create_applet_code($id,$activityObj)
|
||||
{
|
||||
$activity_qrcode_path = '';
|
||||
$row = $activityObj;
|
||||
$save_path = DIRECTORY_SEPARATOR.'uploads'.DIRECTORY_SEPARATOR.'wdsxh'.DIRECTORY_SEPARATOR.'activity_applet_sign_path'.DIRECTORY_SEPARATOR.$id.DIRECTORY_SEPARATOR.$activityObj['createtime'].'activity.png';
|
||||
if (is_file(ROOT_PATH."public".$save_path)) {
|
||||
$activity_qrcode_path = $this->request->domain().$save_path;
|
||||
} else {
|
||||
$ids = $row['id'];
|
||||
$configObj = (new \app\admin\model\wdsxh\Config())->where('id',1)->find();
|
||||
if (!empty($configObj['applet_appid']) && !empty($configObj['applet_secret'])) {
|
||||
$path = 'pagesActivity/order/details';
|
||||
$config = [
|
||||
'app_id' => $configObj['applet_appid'],
|
||||
'secret' => $configObj['applet_secret'],
|
||||
'response_type' => 'array',
|
||||
'log' => [
|
||||
'level' => 'debug',
|
||||
],
|
||||
];
|
||||
|
||||
$app = Factory::miniProgram($config);
|
||||
$token_key = config('token.key');
|
||||
$encryptor = new Encryptor(substr($token_key,0,16),substr($token_key,16));
|
||||
$scene = $validate_value = $encryptor->encrypt($id);
|
||||
|
||||
|
||||
$response = $app->app_code->getUnlimit($scene, [
|
||||
'page' => $path,
|
||||
'check_path' => false,
|
||||
]);
|
||||
|
||||
if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) {
|
||||
$response->saveAs('uploads/wdsxh/activity_applet_sign_path/'.$row['id'], $row['createtime'].'activity.png');
|
||||
$activity_qrcode_path = $this->request->domain().$save_path;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $activity_qrcode_path;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
299
application/admin/controller/wdsxh/activity/ActivityApply.php
Normal file
299
application/admin/controller/wdsxh/activity/ActivityApply.php
Normal file
@@ -0,0 +1,299 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdsxh.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\controller\wdsxh\activity;
|
||||
|
||||
use app\admin\model\wdsxh\activity\Order;
|
||||
use app\api\model\wdsxh\activity\ActivityApplyRecord;
|
||||
use app\common\controller\Backend;
|
||||
use think\Db;
|
||||
use think\exception\DbException;
|
||||
use think\exception\PDOException;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
/**
|
||||
* 活动报名
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class ActivityApply extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* ActivityApply模型对象
|
||||
* @var \app\admin\model\wdsxh\activity\ActivityApply
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\activity\ActivityApply;
|
||||
$this->view->assign("stateList", $this->model->getStateList());
|
||||
$this->view->assign("isSignInList", $this->model->getIsSignInList());
|
||||
$param = $this->request->get();
|
||||
$activity_id = isset($param['activity_id']) ? $param['activity_id'] : '';
|
||||
$this->assign('activity_id',$activity_id);
|
||||
$this->assignconfig('activity_id',$activity_id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有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();
|
||||
$activitiIdWhere = [];
|
||||
$param = $this->request->get();
|
||||
if(isset($param['activity_id']) && !empty($param['activity_id'])) {
|
||||
$activitiIdWhere[config('database.prefix').'wdsxh_activity.id'] = array('eq',$param['activity_id']);
|
||||
}
|
||||
$list = $this->model
|
||||
->where($activitiIdWhere)
|
||||
->with(['activity','wechat'])//todo 活动创建后,会员功能对外功能不可用,非会员无法报名
|
||||
->where($where)
|
||||
->order($sort, $order)
|
||||
->paginate($limit);
|
||||
|
||||
$orderModel = new Order();
|
||||
foreach ($list as $row) {
|
||||
$row->order_no = $orderModel
|
||||
->where('activity_id',$row['activity_id'])
|
||||
->where('apply_id',$row['id'])
|
||||
->where('wechat_id',$row['wechat_id'])
|
||||
->value('order_no');
|
||||
if (!empty($row['name'])) {
|
||||
$row->show_field_data = 1;
|
||||
$row->wechat->nickname = $row['name'];
|
||||
$row->wechat->mobile = $row['mobile'];
|
||||
} else {
|
||||
$row->show_field_data = 2;
|
||||
}
|
||||
$pay_time = $orderModel
|
||||
->where('activity_id',$row['activity_id'])
|
||||
->where('apply_id',$row['id'])
|
||||
->where('wechat_id',$row['wechat_id'])
|
||||
->value('pay_time');
|
||||
if (!empty($pay_time))
|
||||
$row->pay_time = date('Y-m-d H:i:s',$pay_time);
|
||||
else {
|
||||
$row->pay_time = '';
|
||||
}
|
||||
}
|
||||
|
||||
$result = array("total" => $list->total(), "rows" => $list->items());
|
||||
|
||||
return json($result);
|
||||
}
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
$activityObj = (new \app\admin\model\wdsxh\activity\Activity())->where('id',$params['activity_id'])->find();
|
||||
if (empty($activityObj)) {
|
||||
$this->error('活动不存在');
|
||||
}
|
||||
$current_date = date('Y-m-d',time());
|
||||
$memberObj = (new \app\admin\model\wdsxh\member\Member())->where('wechat_id',$params['wechat_id'])
|
||||
->where('expire_time','>=',$current_date)
|
||||
->find();
|
||||
if ($activityObj['non_member_registration_status'] == '2' && !$memberObj) {
|
||||
$this->error('只有会员才能报名');
|
||||
}
|
||||
if ($activityObj['apply_time'] < time()) {
|
||||
$this->error('活动报名时间已过,无法报名');
|
||||
}
|
||||
if ($activityObj['state'] == '2') {
|
||||
$this->error('活动进行中,无法报名');
|
||||
}
|
||||
if ($activityObj['state'] == '3') {
|
||||
$this->error('活动已结束,无法报名');
|
||||
}
|
||||
$queryActivityApplyObj = (new \app\admin\model\wdsxh\activity\ActivityApply())
|
||||
->where('activity_id',$params['activity_id'])
|
||||
->where('wechat_id',$params['wechat_id'])
|
||||
->where('state','<>','4')
|
||||
->find();
|
||||
if ($queryActivityApplyObj) {
|
||||
$this->error('用户后台已添加或者小程序已报名,请勿重复添加!');
|
||||
}
|
||||
|
||||
if (!empty($activityObj['apply_limit_number']) && $activityObj['apply_limit_number'] > 0) {
|
||||
$apply_count = $this->model->where('activity_id', $params['activity_id'])
|
||||
->where('state',2)
|
||||
->count();
|
||||
if ($apply_count >= $activityObj['apply_limit_number']) {
|
||||
$this->error('活动报名人数已满,无法报名');
|
||||
}
|
||||
}
|
||||
|
||||
if ($activityObj['is_verifying'] == '1') {//活动是否核销:1=是,2=否
|
||||
$is_sign_in = 2;
|
||||
} else {
|
||||
$is_sign_in = 3;//签到:1=已签到,2=未签到,3=无需签到
|
||||
}
|
||||
$member_id = $memberObj ? $memberObj->id : 0;
|
||||
$orderModel = new Order();
|
||||
$avtivityApplyRecordModel = new ActivityApplyRecord();
|
||||
$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);
|
||||
}
|
||||
$apply_data = array(
|
||||
'activity_id'=> $params['activity_id'],
|
||||
'wechat_id' => $params['wechat_id'],
|
||||
'member_id'=>$member_id,
|
||||
'is_sign_in'=>$is_sign_in,
|
||||
'state'=>'2',
|
||||
'createtime' => time(),
|
||||
);
|
||||
$this->model->data($apply_data);
|
||||
$result = $this->model->allowField(true)->save();
|
||||
|
||||
$order_data = array(
|
||||
'activity_id'=> $params['activity_id'],
|
||||
'apply_id'=> $this->model->id,
|
||||
'wechat_id' => $params['wechat_id'],
|
||||
'member_id'=>$member_id,
|
||||
'order_no'=> wdsxh_create_order(),
|
||||
'pay_amount'=>$activityObj['fees'],
|
||||
'channel'=>'3',
|
||||
'paid'=>'2',
|
||||
'pay_time' => time(),
|
||||
'complete_time' => date('Y-m-d H:i:s',time()),
|
||||
'createtime' => time(),
|
||||
);
|
||||
|
||||
$orderModel->data($order_data);
|
||||
$orderModel->allowField(true)->save();
|
||||
|
||||
$avtivity_apply_record_data = array(
|
||||
'activity_id'=> $params['activity_id'],
|
||||
'wechat_id' => $params['wechat_id'],
|
||||
'member_id'=>$member_id,
|
||||
);
|
||||
$avtivityApplyRecordModel->data($avtivity_apply_record_data);
|
||||
$avtivityApplyRecordModel->allowField(true)->save();
|
||||
|
||||
Db::commit();
|
||||
} catch (ValidateException|PDOException|Exception $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
if ($result === false) {
|
||||
$this->error(__('No rows were inserted'));
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
public function multi($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function del($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function edit($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 报名信息
|
||||
*
|
||||
* @param $ids
|
||||
* @return string
|
||||
* @throws DbException
|
||||
* @throws \think\Exception
|
||||
*/
|
||||
public function field_data_details($ids = null)
|
||||
{
|
||||
$row = $this->model->get($ids);
|
||||
if (!$row) {
|
||||
$this->error(__('No Results were found'));
|
||||
}
|
||||
$custom_content = json_decode($row['field_data'],true);
|
||||
$row['custom_content'] = $custom_content;
|
||||
|
||||
$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('请选择审核状态');
|
||||
}
|
||||
|
||||
$row = $this->model->get($ids);
|
||||
$result = $row->save(['state'=>$params['state']]);
|
||||
if ($result === false) {
|
||||
$this->error($row->getError());
|
||||
}
|
||||
$this->success('操作成功');
|
||||
}
|
||||
|
||||
}
|
||||
110
application/admin/controller/wdsxh/activity/ActivityConfig.php
Normal file
110
application/admin/controller/wdsxh/activity/ActivityConfig.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力中小企业发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdadmin.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Wdadmin系统产品软件并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.wdadmin.cn
|
||||
// +----------------------------------------------------------------------
|
||||
/**
|
||||
* Class ActivityConfig
|
||||
* Desc 活动配置控制器
|
||||
* Create on 2025/4/17 15:09
|
||||
* Create by wangyafang
|
||||
*/
|
||||
|
||||
namespace app\admin\controller\wdsxh\activity;
|
||||
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use think\Db;
|
||||
use think\exception\PDOException;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
class ActivityConfig extends Backend
|
||||
{
|
||||
/**
|
||||
* Config模型对象
|
||||
* @var \app\admin\model\wdsxh\activity\ActivityConfig
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\activity\ActivityConfig();
|
||||
$this->view->assign("expiredActivityShowList", $this->model->getExpiredActivityShowList());
|
||||
|
||||
}
|
||||
|
||||
public function config(){
|
||||
$row = $this->model->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);
|
||||
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 index()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function edit($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function del($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function multi($ids = NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\wdsxh\activity;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
/**
|
||||
* 活动电子证书
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class ActivityElectronicCertificate extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Party模型对象
|
||||
* @var \app\admin\model\wdsxh\activity\ActivityElectronicCertificate
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model=new \app\admin\model\wdsxh\activity\ActivityElectronicCertificate();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$row=$this->model->get(1);
|
||||
if ($this->request->isPost()) {
|
||||
$params=$this->request->param('row/a');
|
||||
|
||||
// 如果params['data']存在,解析它
|
||||
if (isset($params['data']) && !empty($params['data'])) {
|
||||
$data = json_decode($params['data'], true);
|
||||
} else {
|
||||
$data = [];
|
||||
}
|
||||
|
||||
// 重新编码数据
|
||||
$params['data'] = json_encode($data);
|
||||
|
||||
if(empty($row)){
|
||||
\app\admin\model\wdsxh\activity\ActivityElectronicCertificate::create(array('data'=>$params['data']));
|
||||
}else{
|
||||
$row->data=$params['data'];
|
||||
$row->save();
|
||||
}
|
||||
$this->success('保存成功!');
|
||||
}
|
||||
$data=$row->data;
|
||||
if(!empty($data)){
|
||||
$data=json_decode($data,true);
|
||||
}
|
||||
|
||||
|
||||
$this->assign('data',$data);
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
121
application/admin/controller/wdsxh/activity/ActivityFieldset.php
Normal file
121
application/admin/controller/wdsxh/activity/ActivityFieldset.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力中小企业发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdadmin.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Wdadmin系统产品软件并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.wdadmin.cn
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\controller\wdsxh\activity;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
|
||||
class ActivityFieldset extends Backend
|
||||
{
|
||||
/**
|
||||
* Config模型对象
|
||||
* @var \app\admin\model\wdsxh\activity\ActivityFieldset()
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\activity\ActivityFieldset();
|
||||
}
|
||||
|
||||
public function fieldset($ids = null)
|
||||
{
|
||||
$get_fieldset_data = $this->get_fieldset($ids);
|
||||
if ($this->request->isPost()) {
|
||||
$params = $this->request->param('row/a');
|
||||
|
||||
if (empty($params['field']) || !is_array($params['field'])) {
|
||||
$this->error('字段信息不能为空');
|
||||
}
|
||||
$temp = array();
|
||||
|
||||
foreach ($params['field'] as $row) {
|
||||
$temp[] = $row;
|
||||
}
|
||||
$field_array = array_column($temp, 'field');
|
||||
if (count($field_array) != count(array_unique($field_array))) {
|
||||
$this->error('字段名不能重复');
|
||||
}
|
||||
$fieldsetObj = $this->model->where('activity_id',$ids)->find();
|
||||
|
||||
$json = json_encode($temp);
|
||||
if ($fieldsetObj) {
|
||||
$fieldsetObj->json = $json;
|
||||
$fieldsetObj->save();
|
||||
} else {
|
||||
$this->model->save([
|
||||
'activity_id'=>$ids,
|
||||
'json'=>$json
|
||||
]);
|
||||
}
|
||||
$this->success('操作成功!');
|
||||
}
|
||||
$this->assign('get_fieldset_data', json_encode($get_fieldset_data));
|
||||
return $this->view->fetch('');
|
||||
}
|
||||
|
||||
private function get_fieldset($activity_id)
|
||||
{
|
||||
$fieldsetObj = $this->model->where('activity_id',$activity_id)->find();
|
||||
if ($fieldsetObj) {
|
||||
$get_fieldset_data = json_decode($fieldsetObj['json'],true);
|
||||
} else {
|
||||
$get_fieldset_data = 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' => '请输入你的手机号',
|
||||
),
|
||||
);;
|
||||
}
|
||||
|
||||
return $get_fieldset_data;
|
||||
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function multi($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function del($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function edit($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\wdsxh\activity;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
/**
|
||||
* 活动电子证书
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class CertificateDesign extends Backend
|
||||
{
|
||||
|
||||
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
}
|
||||
|
||||
public function index($ids = null)
|
||||
{
|
||||
$row=(new \app\admin\model\wdsxh\activity\Activity())->get($ids);
|
||||
if ($this->request->isPost()) {
|
||||
$params=$this->request->param('row/a');
|
||||
|
||||
// 如果params['data']存在,解析它
|
||||
if (isset($params['data']) && !empty($params['data'])) {
|
||||
$data = json_decode($params['data'], true);
|
||||
} else {
|
||||
$data = [];
|
||||
}
|
||||
|
||||
// 重新编码数据
|
||||
$params['data'] = json_encode($data);
|
||||
|
||||
$row->certificate_data=$params['data'];
|
||||
$row->save();
|
||||
|
||||
$this->success('保存成功!');
|
||||
}
|
||||
$data=$row->certificate_data;
|
||||
if(!empty($data)){
|
||||
$data=json_decode($data,true);
|
||||
}
|
||||
|
||||
|
||||
$this->assign('data',$data);
|
||||
return $this->view->fetch('admin@wdsxh/activity/activity_electronic_certificate/index');
|
||||
}
|
||||
|
||||
public function multi($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function del($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function edit($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
218
application/admin/controller/wdsxh/activity/Refund.php
Normal file
218
application/admin/controller/wdsxh/activity/Refund.php
Normal file
@@ -0,0 +1,218 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdsxh.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\controller\wdsxh\activity;
|
||||
|
||||
use addons\wdsxh\library\Wxapp;
|
||||
use app\admin\model\wdsxh\activity\Order;
|
||||
use app\admin\model\wdsxh\user\Wechat;
|
||||
use app\common\controller\Backend;
|
||||
use think\Db;
|
||||
use think\exception\PDOException;
|
||||
use think\exception\ValidateException;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* 活动退款
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class Refund extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Refund模型对象
|
||||
* @var \app\admin\model\wdsxh\activity\Refund
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\activity\Refund;
|
||||
$this->view->assign("stateList", $this->model->getStateList());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有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
|
||||
->with(['wechat','activity','order'])//todo 活动创建后,会员功能对外功能不可用,非会员无法报名
|
||||
->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();
|
||||
}
|
||||
|
||||
/*
|
||||
* 同意退款
|
||||
*/
|
||||
public function agree($ids=null){
|
||||
$refundObj = $this->model->get($ids);
|
||||
if(!$refundObj){
|
||||
$this->error('退款信息不存在');
|
||||
}
|
||||
$wechatObj = (new Wechat())->get($refundObj->wechat_id);
|
||||
if(!$wechatObj){
|
||||
$this->error('用户信息不存在');
|
||||
}
|
||||
|
||||
$orderWhere = array(
|
||||
'activity_id'=>$refundObj->activity_id,
|
||||
'apply_id'=>$refundObj->apply_id,
|
||||
'wechat_id'=>$refundObj->wechat_id,
|
||||
'id'=>$refundObj->order_id,
|
||||
'paid'=>'2'
|
||||
);
|
||||
$applyWhere = array(
|
||||
'activity_id'=>$refundObj->activity_id,
|
||||
'wechat_id'=>$refundObj->wechat_id,
|
||||
'state' =>'3',
|
||||
'id'=>$refundObj->apply_id,
|
||||
);
|
||||
|
||||
$applyObj = \app\admin\model\wdsxh\activity\ActivityApply::where($applyWhere)->find();
|
||||
if (!$applyObj) {
|
||||
$this->error('报名没有查询到退款记录');
|
||||
}
|
||||
$orderObj = (new Order())->where($orderWhere)->find();
|
||||
if(!$orderObj){
|
||||
$this->error('支付订单信息不存在');
|
||||
}
|
||||
|
||||
$refund_no = wdsxh_create_order();
|
||||
|
||||
$res=Wxapp::payRefund($orderObj->order_no,$refund_no,$orderObj->pay_amount,array('refund_desc'=>'活动报名退款'));
|
||||
if($res && $res['return_code'] == 'SUCCESS' && $res['result_code'] == 'SUCCESS'){
|
||||
$result = false;
|
||||
Db::startTrans();
|
||||
try {
|
||||
$refundObj->state = '2';
|
||||
$refundObj->dispose_time = time();
|
||||
$result = $refundObj->save();
|
||||
$orderObj->refund_no = $refund_no;
|
||||
$orderObj->refund_time = time();
|
||||
$orderObj->paid = '3';
|
||||
$orderObj->save();
|
||||
$applyObj->state = '4';
|
||||
$applyObj->save();
|
||||
Db::commit();
|
||||
} catch (ValidateException|PDOException|Exception $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
if ($result === false) {
|
||||
$this->error(__('No rows were inserted'));
|
||||
}
|
||||
$this->success('退款操作成功');
|
||||
}else{
|
||||
$this->error('退款失败,错误信息:'.$res['err_code_des']);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 拒绝退款
|
||||
*/
|
||||
public function refuse($ids=""){
|
||||
if (false === $this->request->isPost()) {
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
$refundObj = $this->model->get($ids);
|
||||
if(!$refundObj){
|
||||
$this->error('退款信息不存在');
|
||||
}
|
||||
|
||||
$applyWhere = array(
|
||||
'activity_id'=>$refundObj->activity_id,
|
||||
'wechat_id'=>$refundObj->wechat_id,
|
||||
'state' =>'3',
|
||||
'id'=>$refundObj->apply_id,
|
||||
);
|
||||
$applyObj = \app\admin\model\wdsxh\activity\ActivityApply::where($applyWhere)->find();
|
||||
if (!$applyObj) {
|
||||
$this->error('报名没有查询到退款记录');
|
||||
}
|
||||
$params = $this->request->post('row/a');
|
||||
|
||||
$result = false;
|
||||
Db::startTrans();
|
||||
try {
|
||||
$refundObj->state = '3';
|
||||
$refundObj->dispose_time = time();
|
||||
$refundObj->reject = $params['reject'];
|
||||
$result = $refundObj->save();
|
||||
$applyObj->state = '5';
|
||||
$applyObj->save();
|
||||
Db::commit();
|
||||
} catch (ValidateException|PDOException|Exception $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
if ($result === false) {
|
||||
$this->error(__('No rows were inserted'));
|
||||
}
|
||||
$this->success('操作成功');
|
||||
}
|
||||
|
||||
public function multi($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function del($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function edit($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
184
application/admin/controller/wdsxh/article/Article.php
Normal file
184
application/admin/controller/wdsxh/article/Article.php
Normal file
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdsxh.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\controller\wdsxh\article;
|
||||
|
||||
use app\admin\model\wdsxh\business\Association;
|
||||
use app\common\controller\Backend;
|
||||
use think\Db;
|
||||
use think\exception\DbException;
|
||||
use think\exception\PDOException;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
/**
|
||||
* 文章管理
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class Article extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Article模型对象
|
||||
* @var \app\admin\model\wdsxh\article\Article
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\article\Article;
|
||||
$this->view->assign("statusList", $this->model->getStatusList());
|
||||
$this->view->assign("typeList", $this->model->getTypeList());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有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
|
||||
->with(['wdsxharticlecat'])
|
||||
->where($where)
|
||||
->order($sort, $order)
|
||||
->paginate($limit);
|
||||
|
||||
foreach ($list as $row) {
|
||||
$row->visible(['id','cat_id','commerce_name','title','release','image','content','status','weigh','createtime','read_num']);
|
||||
$row->visible(['wdsxharticlecat']);
|
||||
$row->getRelation('wdsxharticlecat')->visible(['name']);
|
||||
if ($row['release'] == ''){
|
||||
$row->release = (new Association())->where('id',1)->value('name');
|
||||
}
|
||||
}
|
||||
|
||||
$result = array("total" => $list->total(), "rows" => $list->items());
|
||||
|
||||
return json($result);
|
||||
}
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @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 ($params['type'] == '2' && !empty($params['files'])) {
|
||||
$params['files'] = '';
|
||||
}
|
||||
$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 ($params['type'] == '2' && !empty($params['files'])) {
|
||||
$params['files'] = '';
|
||||
}
|
||||
$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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
42
application/admin/controller/wdsxh/article/ArticleCat.php
Normal file
42
application/admin/controller/wdsxh/article/ArticleCat.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdsxh.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\controller\wdsxh\article;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
|
||||
/**
|
||||
* 文章分类
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class ArticleCat extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* ArticleCat模型对象
|
||||
* @var \app\admin\model\wdsxh\article\ArticleCat
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\article\ArticleCat;
|
||||
$this->view->assign("statusList", $this->model->getStatusList());
|
||||
}
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
||||
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
||||
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
137
application/admin/controller/wdsxh/business/Association.php
Normal file
137
application/admin/controller/wdsxh/business/Association.php
Normal file
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdsxh.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\controller\wdsxh\business;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use think\Db;
|
||||
use think\exception\PDOException;
|
||||
use think\exception\ValidateException;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* 商协管理
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class Association extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Association模型对象
|
||||
* @var \app\admin\model\wdsxh\business\Association
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\business\Association;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
||||
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
||||
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
||||
*/
|
||||
|
||||
|
||||
public function index()
|
||||
{
|
||||
$row = $this->model->get(1);
|
||||
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 ($params) {
|
||||
$requiredFields = [
|
||||
'name' => '商协名称',
|
||||
'phone' => '电话',
|
||||
'mailbox' => '邮箱',
|
||||
'contacts' => '联系人',
|
||||
'address' => '地址',
|
||||
'lat' => '地址',
|
||||
'lng' => '地址',
|
||||
'logo' => '组织LOGO',
|
||||
'wananchi_qr_code' => '公众号二维码',
|
||||
'course' => '商协介绍',
|
||||
'notice' => '入会须知',
|
||||
];
|
||||
foreach ($requiredFields as $field => $label) {
|
||||
if (!isset($params[$field]) || trim($params[$field]) === '') {
|
||||
$this->error($label . '不能为空');
|
||||
}
|
||||
}
|
||||
$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(true)->validate($validate);
|
||||
}
|
||||
$result = $row->allowField(true)->save($params);
|
||||
Db::commit();
|
||||
} catch (ValidateException $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
} catch (PDOException $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
if ($result !== false) {
|
||||
$this->success();
|
||||
} else {
|
||||
$this->error(__('No rows were updated'));
|
||||
}
|
||||
}
|
||||
$this->error(__('Parameter %s can not be empty', ''));
|
||||
}
|
||||
$this->view->assign("row", $row);
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
328
application/admin/controller/wdsxh/business/Business.php
Normal file
328
application/admin/controller/wdsxh/business/Business.php
Normal file
@@ -0,0 +1,328 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdsxh.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\controller\wdsxh\business;
|
||||
|
||||
use app\admin\model\wdsxh\business\BusinessConfig;
|
||||
use app\admin\model\wdsxh\member\Member;
|
||||
use app\admin\model\wdsxh\points\PointsConfig;
|
||||
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;
|
||||
use think\response\Json;
|
||||
|
||||
/**
|
||||
* 商圈管理
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class Business extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Business模型对象
|
||||
* @var \app\admin\model\wdsxh\business\Business
|
||||
*/
|
||||
protected $model = null;
|
||||
protected $modelConfig = null;
|
||||
protected $relationSearch = true;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\business\Business;
|
||||
$this->modelConfig = new BusinessConfig();
|
||||
$this->view->assign("statusList", $this->model->getStatusList());
|
||||
$this->view->assign("stateList", $this->model->getStateList());
|
||||
$this->view->assign("IsStatusList", $this->modelConfig->getIsStatusList());
|
||||
$this->view->assign("IsExclusiveList", $this->modelConfig->getIsExclusiveList());
|
||||
$this->view->assign("IsProcessList", $this->modelConfig->getIsProcessList());
|
||||
|
||||
$current_date = date('Y-m-d',time());
|
||||
$memberObj = (new Member())->where('expire_time','>=',$current_date)->field('id,name')->order('id desc')->select();
|
||||
$memberIdArray = array_map(function ($item) {
|
||||
return $item->toArray();
|
||||
}, $memberObj);
|
||||
$memberdata = [0 => ['id' => '-1', 'name' => '平台']];
|
||||
foreach ($memberIdArray as $k => $v) {
|
||||
$memberdata[$v['id']] = $v;
|
||||
}
|
||||
$this->view->assign("memberList", $memberdata);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看
|
||||
*
|
||||
* @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(['category'])
|
||||
->order('state asc,id desc')
|
||||
->paginate($limit);
|
||||
$businessAssociationModel = new \app\admin\model\wdsxh\business\Association();
|
||||
$memberModel = new \app\admin\model\wdsxh\Member();
|
||||
foreach ($list as &$v) {
|
||||
if ($v['member_id'] == '-1') {
|
||||
$v->member = $businessAssociationModel->where('id',1)->find();
|
||||
} else {
|
||||
$v->member = $memberModel->where('id',$v['member_id'])->find();
|
||||
}
|
||||
|
||||
}
|
||||
$result = ['total' => $list->total(), 'rows' => $list->items()];
|
||||
return json($result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
||||
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
||||
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
||||
*/
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @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['number'] = wdsxh_create_order();
|
||||
$params['wechat_id'] = (new Member())->where('id',$params['member_id'])->value('wechat_id');
|
||||
$params['state'] = 2;
|
||||
$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 Member())->where('id',$params['member_id'])->value('wechat_id');
|
||||
$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 three_adopt($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();
|
||||
}
|
||||
$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['state'] = 2;
|
||||
$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'));
|
||||
}
|
||||
$add_points = (new PointsConfig())->where('id',1)->value('public_business_get_points');
|
||||
if($add_points>0){
|
||||
UserWechatPointsLog::addPoints(1,'需求发布',$row['wechat_id'],$add_points,3);
|
||||
}
|
||||
$this->success();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 驳回
|
||||
*/
|
||||
public function three_reject($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['state'] = 3;
|
||||
$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 business_config(){
|
||||
$row = $this->modelConfig->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);
|
||||
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();
|
||||
}
|
||||
}
|
||||
45
application/admin/controller/wdsxh/business/Category.php
Normal file
45
application/admin/controller/wdsxh/business/Category.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdsxh.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\controller\wdsxh\business;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
|
||||
/**
|
||||
* 商圈分类管理
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class Category extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Category模型对象
|
||||
* @var \app\admin\model\wdsxh\business\Category
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\business\Category;
|
||||
$this->view->assign("statusList", $this->model->getStatusList());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
||||
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
||||
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
129
application/admin/controller/wdsxh/corporate/Card.php
Normal file
129
application/admin/controller/wdsxh/corporate/Card.php
Normal file
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\wdsxh\corporate;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use think\Db;
|
||||
use think\exception\DbException;
|
||||
use think\exception\PDOException;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
/**
|
||||
* 名片
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class Card extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Card模型对象
|
||||
* @var \app\admin\model\wdsxh\corporate\Card
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
protected $searchFields = 'name,company_name,company_position';
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\corporate\Card;
|
||||
$this->view->assign("isDefaultList", $this->model->getIsDefaultList());
|
||||
$this->view->assign("isHideAvatarList", $this->model->getIsHideAvatarList());
|
||||
$this->view->assign("isWechatNumberPublicList", $this->model->getIsWechatNumberPublicList());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
||||
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
||||
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
||||
*/
|
||||
|
||||
/**
|
||||
* Desc 详情
|
||||
* Create on 2025/1/24 9:26
|
||||
* Create by wangyafang
|
||||
*/
|
||||
public function details($ids = null)
|
||||
{
|
||||
$row = $this->model->get($ids);
|
||||
$this->view->assign('row', $row);
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
public function multi($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @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()) {
|
||||
$main_business = $row['main_business'];
|
||||
$array = explode(',', $main_business);
|
||||
$main_business = json_encode($array, JSON_UNESCAPED_UNICODE);
|
||||
$row['main_business'] = $main_business;
|
||||
$this->view->assign('row', $row);
|
||||
return $this->view->fetch();
|
||||
}
|
||||
$params = $this->request->post('row/a');
|
||||
if (isset($params['main_business']) && is_string($params['main_business'])) {
|
||||
$main_business_arr = json_decode($params['main_business'], true);
|
||||
if (is_array($main_business_arr)) {
|
||||
foreach ($main_business_arr as $v) {
|
||||
if (mb_strlen($v, 'UTF-8') > 4) {
|
||||
$this->error($v . '内容超过4个字');
|
||||
}
|
||||
}
|
||||
$params['main_business'] = implode(',', $main_business_arr);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
$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();
|
||||
}
|
||||
|
||||
}
|
||||
132
application/admin/controller/wdsxh/corporate/CardBackground.php
Normal file
132
application/admin/controller/wdsxh/corporate/CardBackground.php
Normal file
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\wdsxh\corporate;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use think\Db;
|
||||
use think\exception\DbException;
|
||||
use think\exception\PDOException;
|
||||
use think\exception\ValidateException;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* 名片背景
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class CardBackground extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* CardBackground模型对象
|
||||
* @var \app\admin\model\wdsxh\corporate\CardBackground
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\corporate\CardBackground;
|
||||
$this->view->assign("statusList", $this->model->getStatusList());
|
||||
$this->view->assign("fontColorList", $this->model->getFontColorList());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
||||
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
||||
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
||||
*/
|
||||
|
||||
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['font_color'])) {
|
||||
$this->error('请选择字体颜色');
|
||||
}
|
||||
$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['font_color'])) {
|
||||
$this->error('请选择字体颜色');
|
||||
}
|
||||
$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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
147
application/admin/controller/wdsxh/institution/Institution.php
Normal file
147
application/admin/controller/wdsxh/institution/Institution.php
Normal file
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\wdsxh\institution;
|
||||
|
||||
use app\admin\model\wdsxh\institution\InstitutionConfig;
|
||||
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;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
/**
|
||||
* 机构列管理
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class Institution extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Institution模型对象
|
||||
* @var \app\admin\model\wdsxh\institution\Institution
|
||||
*/
|
||||
protected $model = null;
|
||||
protected $modelConfig = null;
|
||||
|
||||
protected $searchFields = 'id,name';
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\institution\Institution;
|
||||
$this->modelConfig = new InstitutionConfig();
|
||||
$this->view->assign("statusList", $this->model->getStatusList());
|
||||
$this->view->assign("IsStatusList", $this->modelConfig->getIsStatusList());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有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();
|
||||
|
||||
$levelModel = new \app\admin\model\wdsxh\institution\Level();
|
||||
$memberModel = new \app\admin\model\wdsxh\institution\Member();
|
||||
foreach ($list as $item) {
|
||||
$levelCount = $levelModel->where('institution_id',$item['id'])->count();
|
||||
if ($levelCount) {
|
||||
$this->error('机构:'.$item['name'].',有等级,无法删除');
|
||||
}
|
||||
unset($levelCount);
|
||||
|
||||
$memberCount = $memberModel->where('institution_id',$item['id'])->count();
|
||||
if ($memberCount) {
|
||||
$this->error('机构:'.$item['name'].',有成员,无法删除');
|
||||
}
|
||||
unset($memberCount);
|
||||
}
|
||||
|
||||
$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'));
|
||||
}
|
||||
|
||||
public function institution_config(){
|
||||
$row = $this->modelConfig->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);
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\wdsxh\institution;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
use think\exception\PDOException;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
/**
|
||||
* 机构成员申请
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class InstitutionMemberApply extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* InstitutionMemberApply模型对象
|
||||
* @var \app\admin\model\wdsxh\institution\InstitutionMemberApply
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\institution\InstitutionMemberApply;
|
||||
$this->view->assign("stateList", $this->model->getStateList());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有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
|
||||
->with(['institution','level','usermember'])
|
||||
->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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc 处理
|
||||
* Create on 2025/8/5 8:55
|
||||
* Create by wangyafang
|
||||
*/
|
||||
public function handle($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()) {
|
||||
$row = $this->model->get($ids);
|
||||
$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 (empty($params['state'])) {
|
||||
$this->error('请选择审核状态');
|
||||
}
|
||||
|
||||
if ($row['state'] == '2') {
|
||||
$this->error('已审核');
|
||||
}
|
||||
|
||||
if ($params['state'] == 2) {
|
||||
$this->pass($row);
|
||||
} else {
|
||||
if (empty($params['reject'])) {
|
||||
$this->error('请填写驳回原因');
|
||||
}
|
||||
$this->reject($row,$params);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc 驳回
|
||||
* Create on 2025/7/28 16:50
|
||||
* Create by wangyafang
|
||||
*/
|
||||
protected function reject($row,$params)
|
||||
{
|
||||
$result = false;
|
||||
Db::startTrans();
|
||||
try {
|
||||
$handleData = array(
|
||||
'handle_time'=>time(),
|
||||
'state'=>$params['state'],
|
||||
'reject'=>$params['reject'],
|
||||
);
|
||||
$result = $row->save($handleData);
|
||||
Db::commit();
|
||||
} catch (ValidateException|PDOException|Exception $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
if (false === $result) {
|
||||
$this->error(__('No rows were updated'));
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc 通过
|
||||
* Create on 2025/7/28 16:51
|
||||
* Create by wangyafang
|
||||
*/
|
||||
protected function pass($row)
|
||||
{
|
||||
$institutionMemberModel = new \app\admin\model\wdsxh\institution\Member();
|
||||
$result = false;
|
||||
Db::startTrans();
|
||||
try {
|
||||
$handleData = array(
|
||||
'handle_time'=>time(),
|
||||
'state'=>'2',
|
||||
);
|
||||
$result = $row->save($handleData);
|
||||
$institutionMemberModel->data([
|
||||
'institution_id' => $row['institution_id'],
|
||||
'wechat_id' => $row['wechat_id'],
|
||||
'member_id' => $row['member_id'],
|
||||
'level_id' => $row['level_id'],
|
||||
'introduction' => $row['introduction'],
|
||||
]);
|
||||
$institutionMemberModel->save();
|
||||
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;
|
||||
}
|
||||
|
||||
public function recyclebin($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function restore($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function destroy($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
139
application/admin/controller/wdsxh/institution/Level.php
Normal file
139
application/admin/controller/wdsxh/institution/Level.php
Normal file
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\wdsxh\institution;
|
||||
|
||||
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 Level extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Level模型对象
|
||||
* @var \app\admin\model\wdsxh\institution\Level
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
protected $searchFields = 'id,level_name';
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\institution\Level;
|
||||
|
||||
$param = $this->request->get();
|
||||
|
||||
$institution_id = isset($param['institution_id']) ? $param['institution_id'] : '';
|
||||
$this->assign('institution_id',$institution_id);
|
||||
$this->assignconfig('institution_id',$institution_id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有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();
|
||||
$institution_id = $this->request->get('institution_id');
|
||||
if (!empty($institution_id)) {
|
||||
$this->model = $this->model->where('institution_id',$institution_id);
|
||||
}
|
||||
|
||||
$list = $this->model
|
||||
->with(['institution'])
|
||||
->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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @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\institution\Member();
|
||||
foreach ($list as $item) {
|
||||
$memberCount = $memberModel->where('level_id',$item['id'])->count();
|
||||
if ($memberCount) {
|
||||
$this->error('级别:'.$item['level_name'].',有成员,无法删除');
|
||||
}
|
||||
unset($memberCount);
|
||||
}
|
||||
|
||||
$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'));
|
||||
}
|
||||
|
||||
}
|
||||
195
application/admin/controller/wdsxh/institution/Member.php
Normal file
195
application/admin/controller/wdsxh/institution/Member.php
Normal file
@@ -0,0 +1,195 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\wdsxh\institution;
|
||||
|
||||
|
||||
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 Member extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Member模型对象
|
||||
* @var \app\admin\model\wdsxh\institution\Member
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\institution\Member;
|
||||
$this->assign('date',date('Y-m-d'));
|
||||
|
||||
$param = $this->request->get();
|
||||
|
||||
$institution_id = isset($param['institution_id']) ? $param['institution_id'] : '';
|
||||
$this->assign('institution_id',$institution_id);
|
||||
$this->assignconfig('institution_id',$institution_id);
|
||||
|
||||
$level_id = isset($param['level_id']) ? $param['level_id'] : '';
|
||||
$this->assign('level_id',$level_id);
|
||||
$this->assignconfig('level_id',$level_id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有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();
|
||||
$institution_id = $this->request->get('institution_id');
|
||||
if (!empty($institution_id)) {
|
||||
$this->model = $this->model->where(config('database.prefix').'wdsxh_institution_member.institution_id',$institution_id);
|
||||
}
|
||||
$level_id = $this->request->get('level_id');
|
||||
if (!empty($level_id)) {
|
||||
$this->model = $this->model->where('level_id',$level_id);
|
||||
}
|
||||
$list = $this->model
|
||||
->with(['institution','level','usermember'])
|
||||
->where($where)
|
||||
->order($sort, $order)
|
||||
->paginate($limit);
|
||||
|
||||
$date = date('Y-m-d');
|
||||
foreach ($list as $row) {
|
||||
if ($row->usermember->expire_time < $date) {
|
||||
$row->member_expire_status = 2;
|
||||
} else {
|
||||
$row->member_expire_status = 1;
|
||||
}
|
||||
}
|
||||
|
||||
$result = array("total" => $list->total(), "rows" => $list->items());
|
||||
|
||||
return json($result);
|
||||
}
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @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 ($this->model->where('institution_id',$params['institution_id'])
|
||||
->where('member_id',$params['member_id'])->find()) {
|
||||
$this->error('已添加成员');
|
||||
}
|
||||
$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 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;
|
||||
$institutionMemberApplyModel = new \app\admin\model\wdsxh\institution\InstitutionMemberApply();
|
||||
Db::startTrans();
|
||||
try {
|
||||
foreach ($list as $item) {
|
||||
$institutionMemberApplyModel->where('institution_id',$item['institution_id'])
|
||||
->where('level_id',$item['level_id'])
|
||||
->where('wechat_id',$item['wechat_id'])
|
||||
->where('member_id',$item['member_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'));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
249
application/admin/controller/wdsxh/mall/Banner.php
Normal file
249
application/admin/controller/wdsxh/mall/Banner.php
Normal file
@@ -0,0 +1,249 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdsxh.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\controller\wdsxh\mall;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use Exception;
|
||||
use think\Db;
|
||||
use think\exception\DbException;
|
||||
use think\exception\PDOException;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
/**
|
||||
* 轮播管理(商城)
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class Banner extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Banner模型对象
|
||||
* @var \app\admin\model\wdsxh\mall\Banner
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\mall\Banner;
|
||||
$this->view->assign("jumpTypeList", $this->model->getJumpTypeList());
|
||||
$this->view->assign("statusList", $this->model->getStatusList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//当前是否为关联查询
|
||||
$type=$this->request->param('type');
|
||||
$this->relationSearch = false;
|
||||
//设置过滤方法
|
||||
$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($where)
|
||||
->order($sort, $order)
|
||||
->paginate($limit);
|
||||
foreach ($list as $row) {
|
||||
$row->visible(['id','pages','title','image','jump_type','status','weigh','createtime']);
|
||||
}
|
||||
$result = array("total" => $list->total(), "rows" => $list->items());
|
||||
|
||||
return json($result);
|
||||
}
|
||||
$this->assignconfig('type',$type);
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
||||
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
||||
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
||||
*/
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @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;
|
||||
switch ($params['jump_type']){
|
||||
case 2:
|
||||
if(empty($params['jump_link'])){
|
||||
$this->error('页面路径不能为空');
|
||||
}
|
||||
if(stripos($params['jump_link'],'?') !== false){
|
||||
$params['content']=empty($params['param'])?$params['jump_link']:$params['jump_link'].'&'.$params['param'];
|
||||
}else{
|
||||
$params['content']=empty($params['param'])?$params['jump_link']:$params['jump_link'].'?'.$params['param'];
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if(empty($params['content'])){
|
||||
$this->error('图文内容不能为空');
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if(empty($params['wxapp']['appid'])){
|
||||
$this->error('小程序Appid不能为空');
|
||||
}
|
||||
$params['content']=json_encode(array('appid'=>$params['wxapp']['appid'],'path'=>$params['wxapp']['path']));
|
||||
break;
|
||||
case 3:
|
||||
if(empty($params['jump_h5'])){
|
||||
$this->error('外部链接不能为空');
|
||||
}
|
||||
$params['content']=trim($params['jump_h5']);
|
||||
break;
|
||||
}
|
||||
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()) {
|
||||
$row=$row->toArray();
|
||||
switch ($row['jump_type']){
|
||||
case 2:
|
||||
$temp=explode('?',$row['content']);
|
||||
$row['jump_link']=$temp['0'];
|
||||
$row['param']=empty($temp['1'])?null:$temp['1'];
|
||||
$row['content']=null;
|
||||
break;
|
||||
case 4:
|
||||
$temp=json_decode($row['content'],true);
|
||||
$row['wxapp']['appid']=$temp['appid'];
|
||||
$row['wxapp']['path']=$temp['path'];
|
||||
$row['content']=null;
|
||||
break;
|
||||
case 3:
|
||||
$row['jump_h5']= $row['content'];
|
||||
$row['content']=null;
|
||||
break;
|
||||
}
|
||||
$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;
|
||||
switch ($params['jump_type']){
|
||||
case 2:
|
||||
if(empty($params['jump_link'])){
|
||||
$this->error('页面路径不能为空');
|
||||
}
|
||||
if(stripos($params['jump_link'],'?') !== false){
|
||||
$params['content']=empty($params['param'])?$params['jump_link']:$params['jump_link'].'&'.$params['param'];
|
||||
}else{
|
||||
$params['content']=empty($params['param'])?$params['jump_link']:$params['jump_link'].'?'.$params['param'];
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if(empty($params['content'])){
|
||||
$this->error('图文内容不能为空');
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if(empty($params['wxapp']['appid'])){
|
||||
$this->error('小程序Appid不能为空');
|
||||
}
|
||||
$params['content']=json_encode(array('appid'=>$params['wxapp']['appid'],'path'=>$params['wxapp']['path']));
|
||||
break;
|
||||
case 3:
|
||||
if(empty($params['jump_h5'])){
|
||||
$this->error('外部链接不能为空');
|
||||
}
|
||||
$params['content']=trim($params['jump_h5']);
|
||||
break;
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
45
application/admin/controller/wdsxh/mall/Express.php
Normal file
45
application/admin/controller/wdsxh/mall/Express.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdsxh.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\controller\wdsxh\mall;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
|
||||
/**
|
||||
* 快递公司
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class Express extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Express模型对象
|
||||
* @var \app\admin\model\wdsxh\mall\Express
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\mall\Express;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
||||
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
||||
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
47
application/admin/controller/wdsxh/mall/FreightRules.php
Normal file
47
application/admin/controller/wdsxh/mall/FreightRules.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdsxh.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\controller\wdsxh\mall;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
|
||||
/**
|
||||
* 商城运费规则
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class FreightRules extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* FreightRules模型对象
|
||||
* @var \app\admin\model\wdsxh\mall\FreightRules
|
||||
*/
|
||||
protected $model = null;
|
||||
protected $modelValidate = true;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\mall\FreightRules;
|
||||
$this->view->assign("statusList", $this->model->getStatusList());
|
||||
$this->view->assign("openAreaList", $this->model->getOpenAreaList());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
||||
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
||||
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
178
application/admin/controller/wdsxh/mall/Goods.php
Normal file
178
application/admin/controller/wdsxh/mall/Goods.php
Normal file
@@ -0,0 +1,178 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdsxh.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\controller\wdsxh\mall;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use think\Db;
|
||||
use think\exception\DbException;
|
||||
use think\exception\PDOException;
|
||||
use think\exception\ValidateException;
|
||||
use think\response\Json;
|
||||
use think\Exception;
|
||||
|
||||
/**
|
||||
* 商城商品管理
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class Goods extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Goods模型对象
|
||||
* @var \app\admin\model\wdsxh\mall\Goods
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
protected $relationSearch = true;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\mall\Goods;
|
||||
$this->view->assign("isHotList", $this->model->getIsHotList());
|
||||
$this->view->assign("statusList", $this->model->getStatusList());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有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(['category'])
|
||||
->order($sort, $order)
|
||||
->paginate($limit);
|
||||
$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 ($params['price'] == 0.00){
|
||||
$this->error('商品价格必须大于0');
|
||||
}
|
||||
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);
|
||||
}
|
||||
$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 ($params['price'] == 0.00){
|
||||
$this->error('商品价格必须大于0');
|
||||
}
|
||||
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);
|
||||
}
|
||||
$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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
144
application/admin/controller/wdsxh/mall/GoodsCategory.php
Normal file
144
application/admin/controller/wdsxh/mall/GoodsCategory.php
Normal file
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdsxh.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\controller\wdsxh\mall;
|
||||
|
||||
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\response\Json;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* 单商城分类管理
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class GoodsCategory extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* GoodsCategory模型对象
|
||||
* @var \app\admin\model\wdsxh\mall\GoodsCategory
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\mall\GoodsCategory;
|
||||
$this->view->assign("statusList", $this->model->getStatusList());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有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)
|
||||
->order($sort, $order)
|
||||
->paginate($limit);
|
||||
|
||||
foreach ($list as &$v) {
|
||||
if (!empty($v['pid'])) {
|
||||
$v['pid'] = $this->model->where('id',$v['pid'])->value('name');
|
||||
} else {
|
||||
$v['pid'] = '-';
|
||||
}
|
||||
}
|
||||
$result = ['total' => $list->total(), 'rows' => $list->items()];
|
||||
return json($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @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();
|
||||
|
||||
$goodsModel = new \app\admin\model\wdsxh\mall\Goods();
|
||||
foreach ($list as $item) {
|
||||
$childCategoryCount = $this->model->where('pid',$item['id'])->count();
|
||||
if ($childCategoryCount) {
|
||||
$this->error('请先删除父级分类:'.$item['name'].',下的子分类');
|
||||
}
|
||||
unset($childCategoryCount);
|
||||
|
||||
$goodsCount = $goodsModel->where('category_id',$item['id'])->count();
|
||||
if ($goodsCount) {
|
||||
$this->error('分类:'.$item['name'].',有商品,无法删除');
|
||||
}
|
||||
unset($childCategoryCount);
|
||||
}
|
||||
|
||||
$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'));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
309
application/admin/controller/wdsxh/mall/Order.php
Normal file
309
application/admin/controller/wdsxh/mall/Order.php
Normal file
@@ -0,0 +1,309 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdsxh.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\admin\controller\wdsxh\mall;
|
||||
use addons\wdsxh\library\Wxapp;
|
||||
use app\admin\model\wdsxh\mall\Express;
|
||||
use app\admin\model\wdsxh\mall\Logistics;
|
||||
use app\api\model\wdsxh\mall\OrderItem;
|
||||
use Exception;
|
||||
use app\common\controller\Backend;
|
||||
use think\Db;
|
||||
use think\exception\PDOException;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
/**
|
||||
* 【订单表】
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class Order extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Order模型对象
|
||||
* @var \app\admin\model\wdsxh\mall\Order
|
||||
*/
|
||||
protected $model = null;
|
||||
protected $logisticsModel = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\mall\Order;
|
||||
$this->logisticsModel = new Logistics;
|
||||
$expressObj = (new Express())->select();
|
||||
$this->view->assign('expressObj',$expressObj);
|
||||
$this->view->assign("buyNowList", $this->model->getBuyNowList());
|
||||
$this->view->assign("statusList", $this->model->getStateList());
|
||||
$this->view->assign("refundStatusList", $this->model->getRefundStatusList());
|
||||
$this->view->assign("paidList", $this->model->getPaidList());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
||||
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
||||
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
||||
*/
|
||||
|
||||
|
||||
public function delivery($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);
|
||||
$delivery_management = (new \app\admin\model\wdsxh\Config())->where('id',1)->value('delivery_management');
|
||||
if ($delivery_management == 1){
|
||||
$delivery_name = (new Express())->where('id',$params['delivery_id'])->value('brief_introduction');
|
||||
$goods_name = (new \app\admin\model\wdsxh\mall\Goods())->where('id',$row['goods_id'])->value('name');
|
||||
$delivery = Wxapp::upload_shipping_info(2,$row['trade_no'],1,1,$params['delivery_no'],$delivery_name,$goods_name,wdsxh_hide_phone_number($row['user_phone']),wdsxh_get_openid($row['wechat_id'],1));
|
||||
if ($delivery['code'] != 0){
|
||||
$this->error($delivery['errmsg']);
|
||||
}
|
||||
}
|
||||
$result = false;
|
||||
$send_time = time();
|
||||
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 = [
|
||||
'order_id' => $row['id'],
|
||||
'delivery_id' => $params['delivery_id'],
|
||||
'delivery_no' => $params['delivery_no'],
|
||||
'send_time' => $send_time
|
||||
];
|
||||
(new Logistics())->insert($params);
|
||||
$order_data['state'] = 3;
|
||||
$result = $row->allowField(true)->save($order_data);
|
||||
Db::commit();
|
||||
} catch (ValidateException|PDOException|Exception $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
if (false === $result) {
|
||||
$this->error(__('No rows were updated'));
|
||||
}
|
||||
|
||||
$openid = wdsxh_get_openid($row['wechat_id'],1);
|
||||
$applet_order_shipping_notification = (new \app\admin\model\wdsxh\Config())->where('id',1)->value('applet_order_shipping_notification');
|
||||
// 发送物流通知
|
||||
if ($row['delivery_method'] == 1 && !empty($openid) && !empty($applet_order_shipping_notification)){
|
||||
$goodsObj = (new \app\admin\model\wdsxh\mall\Goods())->where('id',$row['goods_id'])->find();
|
||||
try{
|
||||
$data=[
|
||||
'thing1'=>[
|
||||
'value'=>$goodsObj['name'],
|
||||
],
|
||||
'character_string2'=>[
|
||||
'value'=>$row['order_no'],
|
||||
],
|
||||
'date3'=>[
|
||||
'value'=>date('Y-m-d H:i:s',$send_time),
|
||||
],
|
||||
'character_string5'=>[
|
||||
'value'=>$params['delivery_no'],
|
||||
],
|
||||
'amount7'=>[
|
||||
'value'=>$row['total_price'].'元',
|
||||
]
|
||||
];
|
||||
$result = Wxapp::subscribeMessage($applet_order_shipping_notification,trim($openid),'/pagesMall/order/details?order_id='.$ids,$data);
|
||||
}catch (\think\Exception $e){
|
||||
error_log('Applet_order_shipping_notification send fail: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
|
||||
|
||||
public function goods_details($ids = null){
|
||||
$orderObj = $this->model->get($ids);
|
||||
$usermodel = (new \app\admin\model\wdsxh\user\Wechat())->where('id',$orderObj['wechat_id'])->find();
|
||||
$logisticsModel = (new Logistics())->where('order_id',$orderObj['id'])->find();
|
||||
if ($orderObj['buy_now'] == '1') {
|
||||
$goodsObj = (new \app\admin\model\wdsxh\mall\Goods())->withTrashed()->where('id',$orderObj['goods_id'])->select();
|
||||
foreach ($goodsObj as &$v) {
|
||||
$v->goods_num = $orderObj['number'];
|
||||
}
|
||||
} else {
|
||||
$order_item_goods_id_array = (new OrderItem())->where('order_id',$ids)->column('goods_id');
|
||||
$goodsObj = (new \app\admin\model\wdsxh\mall\Goods())->withTrashed()->where('id','in',$order_item_goods_id_array)->select();
|
||||
foreach ($goodsObj as &$v) {
|
||||
$v->goods_num = (new OrderItem())->where('order_id',$ids)->where('goods_id',$v['id'])->value('goods_num');
|
||||
}
|
||||
}
|
||||
$refundMode = (new \app\admin\model\wdsxh\mall\Refund())->where('order_id',$orderObj['id'])->find();
|
||||
$this->view->assign("refundMode", $refundMode);
|
||||
$this->view->assign("goodsObj", $goodsObj);
|
||||
$this->view->assign("usermodel", $usermodel);
|
||||
$this->view->assign("orderObj", $orderObj);
|
||||
$this->view->assign("logisticsModel", $logisticsModel);
|
||||
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;
|
||||
}
|
||||
|
||||
public function recyclebin($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function restore($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function destroy($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc 确认自提
|
||||
* Create on 2025/4/15 17:00
|
||||
* Create by wangyafang
|
||||
*/
|
||||
public function confirm_self_pickup($ids=null){
|
||||
if(!$this->request->isPost()) {
|
||||
$this->error('请求类型错误');
|
||||
}
|
||||
$row = $this->model->get($ids);
|
||||
if (!$row) {
|
||||
$this->error('订单不存在');
|
||||
}
|
||||
if ($row['state'] == 3) {
|
||||
$this->error('订单已自提,无需操作');
|
||||
}
|
||||
if ($row['state'] != 2) {
|
||||
$this->error('没有查到订单付款信息');
|
||||
}
|
||||
$delivery_management = (new \app\admin\model\wdsxh\Config())->where('id',1)->value('delivery_management');
|
||||
if ($delivery_management == 1){
|
||||
$delivery = Wxapp::upload_shipping_info(2,$row['trade_no'],1,4,'','','用户自提',wdsxh_hide_phone_number($row['user_phone']),wdsxh_get_openid($row['wechat_id'],1));
|
||||
if ($delivery['code'] != 0){
|
||||
$this->error($delivery['errmsg']);
|
||||
}
|
||||
}
|
||||
$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);
|
||||
}
|
||||
$order_data['state'] = 3;
|
||||
$result = $row->allowField(true)->save($order_data);
|
||||
Db::commit();
|
||||
} catch (ValidateException|PDOException|Exception $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
if (false === $result) {
|
||||
$this->error(__('No rows were updated'));
|
||||
}
|
||||
$this->success('操作成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc 确认收货
|
||||
* Create on 2025/8/14 下午4:59
|
||||
* Create by wangyafang
|
||||
*/
|
||||
public function confirm_receipt($ids=null){
|
||||
if(!$this->request->isPost()) {
|
||||
$this->error('请求类型错误');
|
||||
}
|
||||
$row = $this->model->get($ids);
|
||||
if (!$row) {
|
||||
$this->error('订单不存在');
|
||||
}
|
||||
if ($row['state'] == 4) {
|
||||
$this->error('已确认收获');
|
||||
}
|
||||
if ($row['state'] != 3) {
|
||||
$this->error('不是待收获状态,无法操作');
|
||||
}
|
||||
$delivery_management = (new \app\admin\model\wdsxh\Config())->where('id',1)->value('delivery_management');
|
||||
if ($delivery_management == 1){
|
||||
$get_order_result = Wxapp::get_order($row['trade_no']);
|
||||
if ($get_order_result['code'] != 0){
|
||||
$this->error($get_order_result['errmsg']);
|
||||
}
|
||||
if (!empty($get_order_result['order'])) {
|
||||
if (!in_array($get_order_result['order']['order_state'],[3,4,6])) {
|
||||
$this->error('订单状态不是:确认收货,交易完成,资金待结算;无法操作');
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
$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);
|
||||
}
|
||||
$order_data['state'] = 4;
|
||||
$result = $row->allowField(true)->save($order_data);
|
||||
Db::commit();
|
||||
} catch (ValidateException|PDOException|Exception $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
if (false === $result) {
|
||||
$this->error(__('No rows were updated'));
|
||||
}
|
||||
$this->success('操作成功');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
246
application/admin/controller/wdsxh/mall/Refund.php
Normal file
246
application/admin/controller/wdsxh/mall/Refund.php
Normal file
@@ -0,0 +1,246 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdsxh.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\controller\wdsxh\mall;
|
||||
|
||||
use app\admin\model\wdsxh\mall\OrderRefundLog;
|
||||
use app\admin\model\wdsxh\user\Wechat;
|
||||
use app\common\controller\Backend;
|
||||
use think\Db;
|
||||
use think\exception\DbException;
|
||||
use think\exception\PDOException;
|
||||
use think\exception\ValidateException;
|
||||
use think\response\Json;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* 订单退款管理
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class Refund extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Refund模型对象
|
||||
* @var \app\admin\model\wdsxh\mall\Refund
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\mall\Refund;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查看
|
||||
*
|
||||
* @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);
|
||||
foreach ($list as $item){
|
||||
$item->order_no = (new \app\admin\model\wdsxh\mall\Order())->where('id',$item['order_id'])->value('order_no');
|
||||
$item->real_name = (new \app\admin\model\wdsxh\mall\Order())->where('id',$item['order_id'])->value('real_name');
|
||||
$item->refund_status = (new \app\admin\model\wdsxh\mall\Order())->where('id',$item['order_id'])->value('refund_status');
|
||||
}
|
||||
$result = ['total' => $list->total(), 'rows' => $list->items()];
|
||||
return json($result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
||||
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
||||
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
||||
*/
|
||||
|
||||
/**
|
||||
* 通过
|
||||
*/
|
||||
public function three_adopt($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();
|
||||
}
|
||||
$order = (new \app\admin\model\wdsxh\mall\Order())->where('id',$row['order_id'])->find();
|
||||
if ($order['state'] == 2){
|
||||
$refundSn=wdsxh_create_order();
|
||||
$res=\addons\wdsxh\library\Wxapp::payRefund($order->order_no,$refundSn,$order->pay_price,array('refund_desc'=>'退款'));
|
||||
if($res && $res['return_code'] == 'SUCCESS' && $res['result_code'] == 'SUCCESS'){
|
||||
$order->complete_time=time();
|
||||
$order->state='-2';
|
||||
$order->refund_status='5';
|
||||
$order->save();
|
||||
$row->refund_time=time();
|
||||
$row->save();
|
||||
$this->success('退款操作成功');
|
||||
}else{
|
||||
$this->error('退款失败,错误信息:'.$res['err_code_des']);
|
||||
}
|
||||
}else{
|
||||
$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['refund_status'] = 3;
|
||||
$result = (new \app\admin\model\wdsxh\mall\Order())->allowField(true)->where('id',$row['order_id'])->update($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 three_reject($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();
|
||||
}
|
||||
$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['refund_status'] = 1;
|
||||
$params['state'] = $row['state'];
|
||||
(new \app\admin\model\wdsxh\mall\Order())->allowField(true)->where('id',$row['order_id'])->update($params);
|
||||
$result = $row->delete();
|
||||
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 refund($ids = null){
|
||||
$data = $this->model->get($ids);
|
||||
if(!$data){
|
||||
$this->error('退款信息不存在');
|
||||
}
|
||||
$user=Wechat::where('id',$data->wechat_id)->field('applet_openid')->find();
|
||||
if(!$user){
|
||||
$this->error('用户信息不存在');
|
||||
}
|
||||
$mep = array(
|
||||
'wechat_id'=>$data->wechat_id,
|
||||
'refund_status' =>'4',
|
||||
'id'=>$data->order_id,
|
||||
);
|
||||
$order = \app\admin\model\wdsxh\mall\Order::where($mep)->find();
|
||||
$refundModel = \app\admin\model\wdsxh\mall\Refund::where('id',$data->id)->find();
|
||||
if(!$order){
|
||||
$this->error('支付订单信息不存在');
|
||||
}
|
||||
$refundLogModel = [
|
||||
'order_sn' => $order['order_no'],
|
||||
'refund_sn'=>$data['refund_express_no'],
|
||||
'order_id' =>$order['id'],
|
||||
'status' => -1,
|
||||
'pay_fee'=>$order['pay_price'],
|
||||
'refund_fee' =>$order['refund_price'],
|
||||
'createtime'=> time()
|
||||
];
|
||||
$refundSn=wdsxh_create_order();
|
||||
$res=\addons\wdsxh\library\Wxapp::payRefund($order->order_no,$refundSn,$order->pay_price,array('refund_desc'=>'退款'));
|
||||
if($res && $res['return_code'] == 'SUCCESS' && $res['result_code'] == 'SUCCESS'){
|
||||
$order->complete_time=time();
|
||||
$order->state='-2';
|
||||
$order->refund_status='5';
|
||||
$order->save();
|
||||
$refundModel->refund_time=time();
|
||||
$refundModel->save();
|
||||
$this->success('退款操作成功');
|
||||
}else{
|
||||
(new OrderRefundLog())->save($refundLogModel);
|
||||
$this->error('退款失败,错误信息:'.$res['err_code_des']);
|
||||
}
|
||||
}
|
||||
|
||||
public function multi($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function edit($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
110
application/admin/controller/wdsxh/mall/SelfPickup.php
Normal file
110
application/admin/controller/wdsxh/mall/SelfPickup.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力中小企业发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdadmin.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Wdadmin系统产品软件并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.wdadmin.cn
|
||||
// +----------------------------------------------------------------------
|
||||
/**
|
||||
* Class SelfPickup
|
||||
* Desc 自提点控制器
|
||||
* Create on 2025/4/15 14:22
|
||||
* Create by wangyafang
|
||||
*/
|
||||
|
||||
namespace app\admin\controller\wdsxh\mall;
|
||||
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use think\Db;
|
||||
use think\exception\PDOException;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
class SelfPickup extends Backend
|
||||
{
|
||||
/**
|
||||
* Config模型对象
|
||||
* @var \app\admin\model\wdsxh\Config
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\mall\SelfPickup();
|
||||
$this->view->assign("IsStatusList", $this->model->getIsStatusList());
|
||||
|
||||
}
|
||||
|
||||
public function config(){
|
||||
$row = $this->model->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);
|
||||
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 index()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function edit($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function del($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function multi($ids = NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
175
application/admin/controller/wdsxh/member/Cert.php
Normal file
175
application/admin/controller/wdsxh/member/Cert.php
Normal file
@@ -0,0 +1,175 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
831
application/admin/controller/wdsxh/member/Company.php
Normal file
831
application/admin/controller/wdsxh/member/Company.php
Normal file
@@ -0,0 +1,831 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 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中对应的方法复制到当前控制器,然后进行修改
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
414
application/admin/controller/wdsxh/member/JoinConfig.php
Normal file
414
application/admin/controller/wdsxh/member/JoinConfig.php
Normal file
@@ -0,0 +1,414 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
202
application/admin/controller/wdsxh/member/Level.php
Normal file
202
application/admin/controller/wdsxh/member/Level.php
Normal file
@@ -0,0 +1,202 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
395
application/admin/controller/wdsxh/member/Member.php
Normal file
395
application/admin/controller/wdsxh/member/Member.php
Normal file
@@ -0,0 +1,395 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
824
application/admin/controller/wdsxh/member/Organize.php
Normal file
824
application/admin/controller/wdsxh/member/Organize.php
Normal file
@@ -0,0 +1,824 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
109
application/admin/controller/wdsxh/member/Pay.php
Normal file
109
application/admin/controller/wdsxh/member/Pay.php
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 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;
|
||||
}
|
||||
|
||||
}
|
||||
752
application/admin/controller/wdsxh/member/Person.php
Normal file
752
application/admin/controller/wdsxh/member/Person.php
Normal file
@@ -0,0 +1,752 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送会员消息通知
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
157
application/admin/controller/wdsxh/member/Promotion.php
Normal file
157
application/admin/controller/wdsxh/member/Promotion.php
Normal file
@@ -0,0 +1,157 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
133
application/admin/controller/wdsxh/member/Set.php
Normal file
133
application/admin/controller/wdsxh/member/Set.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
653
application/admin/controller/wdsxh/member/apply/Apply.php
Normal file
653
application/admin/controller/wdsxh/member/apply/Apply.php
Normal file
@@ -0,0 +1,653 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
113
application/admin/controller/wdsxh/member/apply/Company.php
Normal file
113
application/admin/controller/wdsxh/member/apply/Company.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 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;
|
||||
}
|
||||
|
||||
}
|
||||
113
application/admin/controller/wdsxh/member/apply/Organize.php
Normal file
113
application/admin/controller/wdsxh/member/apply/Organize.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 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;
|
||||
}
|
||||
|
||||
}
|
||||
133
application/admin/controller/wdsxh/member/apply/Person.php
Normal file
133
application/admin/controller/wdsxh/member/apply/Person.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\wdsxh\message;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use think\exception\DbException;
|
||||
use think\response\Json;
|
||||
|
||||
/**
|
||||
* 通知内容管理
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class MessageNotification extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* MessageNotification模型对象
|
||||
* @var \app\admin\model\wdsxh\message\MessageNotification
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\message\MessageNotification;
|
||||
$this->view->assign("typeList", $this->model->getTypeList());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有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();
|
||||
$typeWhere = [];
|
||||
$param = $this->request->get();
|
||||
if(isset($param['type']) && !empty($param['type'])) {
|
||||
$typeWhere['type'] = array('eq',$param['type']);
|
||||
}
|
||||
$list = $this->model
|
||||
->where($where)
|
||||
->where($typeWhere)
|
||||
->order($sort, $order)
|
||||
->paginate($limit);
|
||||
$result = ['total' => $list->total(), 'rows' => $list->items()];
|
||||
return json($result);
|
||||
}
|
||||
|
||||
public function multi($ids = NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function del($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function edit($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\wdsxh\message;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
|
||||
/**
|
||||
* 通知内容管理
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class MessageNotificationMemberId extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* MessageNotificationMemberId模型对象
|
||||
* @var \app\admin\model\wdsxh\message\MessageNotificationMemberId
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\message\MessageNotificationMemberId;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有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();
|
||||
|
||||
$notificationIdWhere = [];
|
||||
$param = $this->request->get();
|
||||
if(isset($param['notification_id']) && !empty($param['notification_id'])) {
|
||||
$notificationIdWhere['notification_id'] = array('eq',$param['notification_id']);
|
||||
}
|
||||
$list = $this->model
|
||||
->where($notificationIdWhere)
|
||||
->with(['member'])
|
||||
->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();
|
||||
}
|
||||
|
||||
public function multi($ids = NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function del($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function edit($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
98
application/admin/controller/wdsxh/points/Config.php
Normal file
98
application/admin/controller/wdsxh/points/Config.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\wdsxh\points;
|
||||
|
||||
use app\admin\model\wdsxh\points\PointsConfig;
|
||||
use app\common\controller\Backend;
|
||||
use think\Db;
|
||||
use Exception;
|
||||
use think\exception\PDOException;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
/**
|
||||
* 积分配置
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class Config extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Config模型对象
|
||||
* @var \app\admin\model\wdsxh\points\PointsConfig
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new PointsConfig();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 积分配置
|
||||
*/
|
||||
public function index(){
|
||||
$row = $this->model->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);
|
||||
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);
|
||||
}
|
||||
$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 del($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function edit($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function multi($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
41
application/admin/controller/wdsxh/points/Express.php
Normal file
41
application/admin/controller/wdsxh/points/Express.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\wdsxh\points;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
|
||||
/**
|
||||
* 积分商城快递公司
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class Express extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Express模型对象
|
||||
* @var \app\admin\model\wdsxh\points\Express
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\points\Express;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
||||
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
||||
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
||||
*/
|
||||
|
||||
public function multi($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
39
application/admin/controller/wdsxh/points/Goods.php
Normal file
39
application/admin/controller/wdsxh/points/Goods.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\wdsxh\points;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
|
||||
/**
|
||||
* 积分商品管理
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class Goods extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Goods模型对象
|
||||
* @var \app\admin\model\wdsxh\points\Goods
|
||||
*/
|
||||
protected $model = null;
|
||||
protected $modelValidate = true;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\points\Goods;
|
||||
$this->view->assign("statusList", $this->model->getStatusList());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
||||
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
||||
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
||||
*/
|
||||
|
||||
|
||||
|
||||
}
|
||||
142
application/admin/controller/wdsxh/points/Order.php
Normal file
142
application/admin/controller/wdsxh/points/Order.php
Normal file
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\wdsxh\points;
|
||||
|
||||
use app\admin\model\wdsxh\points\Express;
|
||||
use app\admin\model\wdsxh\points\Logistics;
|
||||
use app\common\controller\Backend;
|
||||
use think\Db;
|
||||
use think\exception\PDOException;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
/**
|
||||
* 兑换订单
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class Order extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Order模型对象
|
||||
* @var \app\admin\model\wdsxh\points\Order
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\points\Order;
|
||||
$this->view->assign("stateList", $this->model->getStateList());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
||||
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
||||
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
||||
*/
|
||||
|
||||
public function delivery($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;
|
||||
$send_time = time();
|
||||
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 = [
|
||||
'order_id' => $row['id'],
|
||||
'delivery_id' => $params['delivery_id'],
|
||||
'delivery_no' => $params['delivery_no'],
|
||||
'send_time' => $send_time
|
||||
];
|
||||
(new Logistics())->insert($params);
|
||||
$order_data['state'] = 3;
|
||||
$result = $row->allowField(true)->save($order_data);
|
||||
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 details($ids = null){
|
||||
$orderObj = $this->model->get($ids);
|
||||
$userObj = (new \app\admin\model\wdsxh\user\Wechat())->where('id',$orderObj['wechat_id'])->find();
|
||||
$logisticsObj = (new \app\admin\model\wdsxh\points\Logistics())->where('order_id',$orderObj['id'])->find();
|
||||
|
||||
|
||||
$this->view->assign("userObj", $userObj);
|
||||
$this->view->assign("orderObj", $orderObj);
|
||||
$this->view->assign("logisticsObj", $logisticsObj);
|
||||
|
||||
$expressObj = (new Express())->select();
|
||||
$this->view->assign('expressObj',$expressObj);
|
||||
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;
|
||||
}
|
||||
|
||||
public function recyclebin($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function restore($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function destroy($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
133
application/admin/controller/wdsxh/points/Ranking.php
Normal file
133
application/admin/controller/wdsxh/points/Ranking.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\wdsxh\points;
|
||||
|
||||
use app\admin\model\wdsxh\member\Member;
|
||||
use app\admin\model\wdsxh\user\UserWechat;
|
||||
use app\common\controller\Backend;
|
||||
use app\common\model\wdsxh\points\UserWechatPointsLog;
|
||||
use think\exception\DbException;
|
||||
use think\exception\PDOException;
|
||||
use think\exception\ValidateException;
|
||||
use think\response\Json;
|
||||
|
||||
/**
|
||||
* 微信用户积分变动管理
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class Ranking extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Ranking模型对象
|
||||
* @var \app\admin\model\wdsxh\points\Ranking
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\points\Ranking;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有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();
|
||||
}
|
||||
|
||||
$wechatIdArray = (new UserWechatPointsLog())->distinct(true)->column('wechat_id');
|
||||
$wechatIdArray = (new UserWechat())->where('id','in',$wechatIdArray)->where('points','>',0)->column('id');
|
||||
[$where, $sort, $order, $offset, $limit] = $this->buildparams();
|
||||
$list = (new Member())
|
||||
->with(['level','wechat'])
|
||||
->where('wechat_id','in',$wechatIdArray)
|
||||
->order('points desc')
|
||||
->paginate($limit);
|
||||
foreach ($list as &$v) {
|
||||
$v->id = $v->wechat_id;
|
||||
}
|
||||
$result = ['total' => $list->total(), 'rows' => $list->items()];
|
||||
return json($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc 一键清零
|
||||
* Create on 2025/3/12 11:13
|
||||
* Create by wangyafang
|
||||
*/
|
||||
public function one_click_reset($ids=null){
|
||||
if(!$this->request->isPost()) {
|
||||
$this->error('请求类型错误');
|
||||
}
|
||||
|
||||
try {
|
||||
$userWechatObj = (new UserWechat())->get($ids);
|
||||
|
||||
$pointsLogData = array(
|
||||
'wechat_id'=>$ids,
|
||||
'points'=>$userWechatObj['points'],
|
||||
'before'=>$userWechatObj['points'],
|
||||
'after'=>0,
|
||||
'memo'=>'积分清零',
|
||||
'change'=>2,
|
||||
);
|
||||
|
||||
$pointsLogModel = new UserWechatPointsLog();
|
||||
$pointsLogModel->data($pointsLogData);
|
||||
$pointsLogModel->allowField(true)->save();
|
||||
|
||||
$userWechatObj->points = 0;
|
||||
$userWechatObj->save();
|
||||
|
||||
$this->success('操作成功');
|
||||
} catch (ValidateException|PDOException|Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function multi($ids = NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function del($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function edit($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\wdsxh\points;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use think\exception\DbException;
|
||||
use think\response\Json;
|
||||
|
||||
/**
|
||||
* 微信用户积分变动管理
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class UserWechatPointsLog extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* UserWechatPointsLog模型对象
|
||||
* @var \app\admin\model\wdsxh\points\UserWechatPointsLog
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\points\UserWechatPointsLog;
|
||||
$this->view->assign("changeList", $this->model->getChangeList());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有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();
|
||||
$wechat_id = $this->request->param('wechat_id');
|
||||
$list = $this->model
|
||||
->where('wechat_id',$wechat_id)
|
||||
->order($sort, $order)
|
||||
->paginate($limit);
|
||||
$result = ['total' => $list->total(), 'rows' => $list->items()];
|
||||
return json($result);
|
||||
}
|
||||
|
||||
public function del($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function edit($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function multi($ids = NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\wdsxh\questionnaire;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* 问卷调查分类
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class Category extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Category模型对象
|
||||
* @var \app\admin\model\wdsxh\questionnaire\Category
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\questionnaire\Category;
|
||||
$this->view->assign("statusList", $this->model->getStatusList());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有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();
|
||||
|
||||
$questionnaireModel = new \app\admin\model\wdsxh\questionnaire\Questionnaire();
|
||||
$count = 0;
|
||||
Db::startTrans();
|
||||
try {
|
||||
foreach ($list as $item) {
|
||||
|
||||
if ($questionnaireModel->where('questionnaire_category_id',$item->id)->count()) {
|
||||
$this->error("分类【{$item->name}】下存在问卷,无法删除");
|
||||
}
|
||||
$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'));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,242 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdsxh.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\controller\wdsxh\questionnaire;
|
||||
use EasyWeChat\Factory;
|
||||
use Exception;
|
||||
use app\admin\model\wdsxh\member\Member;
|
||||
use app\common\controller\Backend;
|
||||
use think\Db;
|
||||
use think\exception\DbException;
|
||||
use think\exception\PDOException;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
/**
|
||||
* 问卷调查
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class Questionnaire extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Questionnaire模型对象
|
||||
* @var \app\admin\model\wdsxh\questionnaire\Questionnaire
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\questionnaire\Questionnaire;
|
||||
$this->view->assign("statusList", $this->model->getStatusList());
|
||||
$current_date = date('Y-m-d',time());
|
||||
$memberObj = (new Member())->where('expire_time','>=',$current_date)->field('id,name')->order('id desc')->select();
|
||||
$memberIdArray = array_map(function ($item) {
|
||||
return $item->toArray();
|
||||
}, $memberObj);
|
||||
$memberdata = [0 => ['id' => '-1', 'name' => '平台']];
|
||||
foreach ($memberIdArray as $k => $v) {
|
||||
$memberdata[$v['id']] = $v;
|
||||
}
|
||||
$this->view->assign("memberList", $memberdata);
|
||||
$this->view->assign("nonMemberAnswerSheetStatusList", $this->model->getNonMemberAnswerSheetStatusList());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
||||
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
||||
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
if ($params['member_id'] == -1){
|
||||
$params['wechat_id'] = -1;
|
||||
}else{
|
||||
$params['wechat_id'] = (new Member())->where('id',$params['member_id'])->value('wechat_id');
|
||||
}
|
||||
$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()) {
|
||||
$show_applet_questionnaire_qrcode = 2;
|
||||
$applet_questionnaire_qrcode_path = '';
|
||||
$save_path = '/uploads/wdsxh/applet_questionnaire_qrcode/'.$row['id'].'/'.$row['createtime'].'.png';
|
||||
if (is_file(ROOT_PATH."public".$save_path)) {
|
||||
$applet_questionnaire_qrcode_path = $this->request->domain().$save_path;
|
||||
$show_applet_questionnaire_qrcode = 1;
|
||||
} else {
|
||||
$configObj = (new \app\admin\model\wdsxh\Config())->where('id',1)->find();
|
||||
if (!empty($configObj['applet_appid']) && !empty($configObj['applet_secret'])) {
|
||||
$path = 'pagesTools/questionnaire/details';
|
||||
$config = [
|
||||
'app_id' => $configObj['applet_appid'],
|
||||
'secret' => $configObj['applet_secret'],
|
||||
'response_type' => 'array',
|
||||
'log' => [
|
||||
'level' => 'debug',
|
||||
],
|
||||
];
|
||||
|
||||
$app = Factory::miniProgram($config);
|
||||
|
||||
$response = $app->app_code->getUnlimit($ids, [
|
||||
'page' => $path,
|
||||
]);
|
||||
|
||||
if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) {
|
||||
$response->saveAs('uploads/wdsxh/applet_questionnaire_qrcode/'.$row['id'], $row['createtime'].'.png');
|
||||
$applet_questionnaire_qrcode_path = $this->request->domain().$save_path;
|
||||
$show_applet_questionnaire_qrcode = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->view->assign('show_applet_questionnaire_qrcode', $show_applet_questionnaire_qrcode);
|
||||
$this->view->assign('applet_questionnaire_qrcode_path', $applet_questionnaire_qrcode_path);
|
||||
$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);
|
||||
}
|
||||
if ($params['member_id'] == -1){
|
||||
$params['wechat_id'] = -1;
|
||||
}else{
|
||||
$params['wechat_id'] = (new Member())->where('id',$params['member_id'])->value('wechat_id');
|
||||
}
|
||||
$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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc 分享图片
|
||||
* Create on 2024/4/8 16:08
|
||||
* Create by @小趴菜
|
||||
*/
|
||||
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);
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
231
application/admin/controller/wdsxh/questionnaire/Render.php
Normal file
231
application/admin/controller/wdsxh/questionnaire/Render.php
Normal file
@@ -0,0 +1,231 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdsxh.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\controller\wdsxh\questionnaire;
|
||||
|
||||
use app\admin\model\wdsxh\user\Wechat;
|
||||
use app\common\controller\Backend;
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use think\exception\DbException;
|
||||
use think\response\Json;
|
||||
|
||||
/**
|
||||
* 问卷提交
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class Render extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Render模型对象
|
||||
* @var \app\admin\model\wdsxh\questionnaire\Render
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\questionnaire\Render;
|
||||
$questionnaire_id = input('questionnaire_id', 0, 'intval');
|
||||
$this->view->assign('questionnaire_id',$questionnaire_id);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看
|
||||
*
|
||||
* @return string|Json
|
||||
* @throws \think\Exception
|
||||
* @throws DbException
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$questionnaire_id = input('questionnaire_id', 0, 'intval');
|
||||
//设置过滤方法
|
||||
$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('questionnaire_id',$questionnaire_id)
|
||||
->order($sort, $order)
|
||||
->paginate($limit);
|
||||
foreach ($list as $item){
|
||||
$item->wechat_id = (new Wechat())->where('id',$item['wechat_id'])->value('nickname');
|
||||
}
|
||||
|
||||
$result = ['total' => $list->total(), 'rows' => $list->items()];
|
||||
return json($result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
||||
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
||||
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
||||
*/
|
||||
|
||||
public function details($ids = null){
|
||||
$row = $this->model->get($ids);
|
||||
$data = html_entity_decode($row->content_render);
|
||||
$formData = json_decode($data, true);
|
||||
foreach ($formData as $k=>$v){
|
||||
if ($v['type'] == 'images'){
|
||||
if ($v['content']){
|
||||
if (strpos($v['content'], ',') !== false) {
|
||||
$img = explode(',', $v['content']);
|
||||
} else {
|
||||
$img = array($v['content']);
|
||||
}
|
||||
$images = [];
|
||||
foreach ($img as $item){
|
||||
$images[] = wdsxh_full_url($item);
|
||||
}
|
||||
$formData[$k]['content'] = $images;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
$this->view->assign("content", $formData);
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Desc 问卷提交导出
|
||||
* Create on 2024/3/22 13:36
|
||||
* Create by @小趴菜
|
||||
*/
|
||||
public function export($ids = ""){
|
||||
|
||||
if ($this->request->isPost()) {
|
||||
$questionnaire_id = input('questionnaire_id', 0, 'intval');
|
||||
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');
|
||||
|
||||
$this->request->get(['search' => $search, 'ids' => $ids,'op' => $op]);
|
||||
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
||||
if ($ids == 'all'){
|
||||
$sql = $this->model
|
||||
->where($where)
|
||||
->where('questionnaire_id',$questionnaire_id)
|
||||
->field('content_render')
|
||||
->select();
|
||||
}else{
|
||||
$sql = $this->model
|
||||
->where($pk, 'in', $ids)
|
||||
->where($where)
|
||||
->where('questionnaire_id',$questionnaire_id)
|
||||
->field('content_render')
|
||||
->select();
|
||||
}
|
||||
$sql = collection($sql)->toArray();
|
||||
if (!$sql){
|
||||
$this->error('暂无数据导出');
|
||||
}
|
||||
foreach ($sql as $k=>$v){
|
||||
if ($v['content_render']){
|
||||
$data = html_entity_decode($v['content_render']);
|
||||
$sql[$k]['content_render'] = json_decode($data,true);
|
||||
}
|
||||
}
|
||||
$newExcel = new Spreadsheet(); //创建一个新的excel文档
|
||||
$objSheet = $newExcel->getActiveSheet(); //获取当前操作sheet的对象
|
||||
$questionnaire_name = (new \app\api\model\wdsxh\questionnaire\Questionnaire())->where('id',$questionnaire_id)->value('title');
|
||||
$objSheet->setTitle($questionnaire_name); //设置当前sheet的标题
|
||||
$topic = (new \app\admin\model\wdsxh\questionnaire\Topic())->where('questionnaire_id', $questionnaire_id)->order('weigh asc')->select();
|
||||
$topic_data = collection($topic)->toArray();
|
||||
$labels = range('A', 'Z'); // 生成 A 到 Z 的数组作为列标的数组
|
||||
|
||||
// 设置列宽度
|
||||
for ($i = 0; $i < count($labels); $i++) {
|
||||
$column = $labels[$i];
|
||||
$newExcel->getActiveSheet()->getColumnDimension($column)->setWidth(20);
|
||||
}
|
||||
|
||||
// 设置每一行的标签(label)
|
||||
for ($i = 0; $i < count($topic_data); $i++) {
|
||||
$label = isset($topic_data[$i]['topic']) ? $topic_data[$i]['topic'] : '';
|
||||
$objSheet->setCellValue($labels[$i] . '1', $label);
|
||||
}
|
||||
// 外部循环遍历 $sql 数组
|
||||
foreach ($sql as $rowIndex => $row) {
|
||||
// 内部循环遍历 content 数组,设置每一行的值
|
||||
for ($j = 0; $j < count($row['content_render']); $j++) {
|
||||
// 查询提交的数据是否开始说明
|
||||
if ($row['content_render'][$j]['is_explain'] == '1') {
|
||||
$value = $row['content_render'][$j]['content'] . '。' . '说明:' . $row['content_render'][$j]['explain'];
|
||||
} else {
|
||||
$value = isset($row['content_render'][$j]['content']) ? $row['content_render'][$j]['content'] : '';
|
||||
}
|
||||
|
||||
// 循环图片,拼接完整的链接
|
||||
if ($row['content_render'][$j]['type'] == 'images') {
|
||||
$array = explode(',', $row['content_render'][$j]['content']);
|
||||
foreach ($array as $k=>$v) {
|
||||
$array[$k] = wdsxh_full_url($v);
|
||||
}
|
||||
$value = implode(',',$array);
|
||||
}
|
||||
$objSheet->setCellValue($labels[$j] . ($rowIndex + 2), $value);
|
||||
}
|
||||
}
|
||||
/*--------------下面是设置其他信息------------------*/
|
||||
$title = date("Ymd-问卷调查");
|
||||
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 multi($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function del($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function edit($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
185
application/admin/controller/wdsxh/questionnaire/Topic.php
Normal file
185
application/admin/controller/wdsxh/questionnaire/Topic.php
Normal file
@@ -0,0 +1,185 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdsxh.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\controller\wdsxh\questionnaire;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use think\Db;
|
||||
use think\exception\DbException;
|
||||
use think\exception\PDOException;
|
||||
use think\exception\ValidateException;
|
||||
use think\response\Json;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* 问卷题目管理
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class Topic extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Topic模型对象
|
||||
* @var \app\admin\model\wdsxh\questionnaire\Topic
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\questionnaire\Topic;
|
||||
$this->view->assign("typeList", $this->model->getTypeList());
|
||||
$this->view->assign("isExplainList", $this->model->getIsExplainList());
|
||||
$this->view->assign("mustList", $this->model->getMustList());
|
||||
$this->view->assign("statusList", $this->model->getStatusList());
|
||||
// 获取自定义按钮传递的questionnaire_id
|
||||
$questionnaire_id = input('questionnaire_id', 0, 'intval');
|
||||
// 将questionnaire_id传递给模板
|
||||
$this->assignconfig('questionnaire_id', $questionnaire_id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有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()
|
||||
{
|
||||
// 获取自定义按钮传递的questionnaire_id
|
||||
$questionnaire_id = input('questionnaire_id', 0, 'intval');
|
||||
//设置过滤方法
|
||||
$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('questionnaire_id',$questionnaire_id)
|
||||
->order($sort, $order)
|
||||
->paginate($limit);
|
||||
$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();
|
||||
}
|
||||
// 从 URL 中获取 questionnaire_id 参数
|
||||
$questionnaire_id = $this->request->get('questionnaire_id');
|
||||
$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['questionnaire_id'] = $questionnaire_id;
|
||||
$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);
|
||||
}
|
||||
$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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
111
application/admin/controller/wdsxh/user/User.php
Normal file
111
application/admin/controller/wdsxh/user/User.php
Normal file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\wdsxh\user;
|
||||
|
||||
use app\admin\model\UserGroup;
|
||||
use app\admin\model\wdsxh\user\UserWechat;
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\Auth;
|
||||
|
||||
/**
|
||||
* 用户列表
|
||||
*
|
||||
* @icon fa fa-user
|
||||
*/
|
||||
class User extends Backend
|
||||
{
|
||||
|
||||
protected $relationSearch = true;
|
||||
protected $searchFields = 'id,username,nickname';
|
||||
|
||||
/**
|
||||
* @var \app\admin\model\User
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = model('User');
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//设置过滤方法
|
||||
$this->request->filter(['strip_tags', 'trim']);
|
||||
if ($this->request->isAjax()) {
|
||||
//如果发送的来源是Selectpage,则转发到Selectpage
|
||||
if ($this->request->request('keyField')) {
|
||||
return $this->selectpage();
|
||||
}
|
||||
$userData = $this->model
|
||||
->alias('u')
|
||||
->where('u.mobile','')
|
||||
->join(config('database.prefix').'wdsxh_user_wechat wechat','wechat.user_id = u.id')
|
||||
->where('wechat.mobile','<>','')
|
||||
->field('u.*')
|
||||
->select();
|
||||
if (!empty($userData)) {
|
||||
$userWechatModel = new UserWechat();
|
||||
foreach ($userData as $v) {
|
||||
$v->mobile = $userWechatModel->where('user_id',$v->id)->value('mobile');
|
||||
$v->save();
|
||||
}
|
||||
}
|
||||
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
||||
$list = $this->model
|
||||
->where($where)
|
||||
->order($sort, $order)
|
||||
->paginate($limit);
|
||||
$userGroupingModel = new UserGroup();
|
||||
foreach ($list as $k => $v) {
|
||||
$v->avatar = $v->avatar ? cdnurl($v->avatar, true) : letter_avatar($v->nickname);
|
||||
$v->hidden(['password', 'salt']);
|
||||
$v->channel = (new UserWechat())->where('user_id',$v['id'])->value('channel');
|
||||
$v->set_admin = (new UserWechat())->where('user_id',$v['id'])->value('set_admin');
|
||||
$v->group = $userGroupingModel->get($v['group_id']);
|
||||
}
|
||||
$result = array("total" => $list->total(), "rows" => $list->items());
|
||||
|
||||
return json($result);
|
||||
}
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
public function del($ids = "")
|
||||
{
|
||||
if (!$this->request->isPost()) {
|
||||
$this->error(__("Invalid parameters"));
|
||||
}
|
||||
$ids = $ids ? $ids : $this->request->post("ids");
|
||||
$row = $this->model->get($ids);
|
||||
$this->modelValidate = true;
|
||||
if (!$row) {
|
||||
$this->error(__('No Results were found'));
|
||||
}
|
||||
Auth::instance()->delete($row['id']);
|
||||
$this->success();
|
||||
}
|
||||
|
||||
public function multi($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function edit($ids = null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public function add()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
200
application/admin/controller/wdsxh/user/Wechat.php
Normal file
200
application/admin/controller/wdsxh/user/Wechat.php
Normal file
@@ -0,0 +1,200 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdsxh.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\controller\wdsxh\user;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use Exception;
|
||||
use think\Db;
|
||||
use think\exception\PDOException;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
/**
|
||||
* 微信管理
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
*/
|
||||
class Wechat extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Wechat模型对象
|
||||
* @var \app\admin\model\wdsxh\user\Wechat
|
||||
*/
|
||||
protected $model = null;
|
||||
protected $userModel = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\user\Wechat;
|
||||
$this->userModel = new \app\admin\model\User();
|
||||
$this->view->assign("setAdminList", $this->model->getSetAdminList());
|
||||
$this->view->assign("channelList", $this->model->getChannelList());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
||||
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
||||
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
||||
*/
|
||||
|
||||
|
||||
public function pass_through($ids = null){
|
||||
$row = $this->model->where('user_id',$ids)->find();
|
||||
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();
|
||||
}
|
||||
$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['set_admin'] = 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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function cancellation($ids = null){
|
||||
$row = $this->model->where('user_id',$ids)->find();
|
||||
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();
|
||||
}
|
||||
$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['set_admin'] = 2;
|
||||
$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 user()
|
||||
{
|
||||
//当前是否为关联查询
|
||||
$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');
|
||||
// 添加输入验证,防止SQL注入
|
||||
if (empty($parent_wechat_id)) {
|
||||
$result = array("total" => 0, "rows" => []);
|
||||
return $result;
|
||||
}
|
||||
|
||||
$memberModel = new \app\admin\model\wdsxh\Member();
|
||||
$all_id_array = $this->model->where('parent_wechat_id', $parent_wechat_id)->column('id');
|
||||
|
||||
// 防止空数组导致的SQL语法错误
|
||||
if (empty($all_id_array)) {
|
||||
$result = array("total" => 0, "rows" => []);
|
||||
return $result;
|
||||
}
|
||||
|
||||
$member_wechat_id_array = $memberModel->where('wechat_id', 'in', $all_id_array)->column('wechat_id');
|
||||
|
||||
$user_id_array = array_diff($all_id_array, $member_wechat_id_array);
|
||||
|
||||
// 防止空数组导致的SQL语法错误
|
||||
if (empty($user_id_array)) {
|
||||
$result = array("total" => 0, "rows" => []);
|
||||
return $result;
|
||||
}
|
||||
|
||||
$list = $this->model->where('id', 'in', $user_id_array)->order('id desc')
|
||||
->where($where)
|
||||
->field("id,nickname,avatar,createtime")->paginate($limit);
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user