init commit

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

View File

@@ -0,0 +1,203 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh;
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();
}
}

View File

@@ -0,0 +1,220 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh;
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();
}
}

View 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;
}
}

View File

@@ -0,0 +1,143 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh;
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;
}
}

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

View File

@@ -0,0 +1,44 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力中小企业发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 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);
}
}
}

View File

@@ -0,0 +1,136 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh;
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());
}
}
}

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

View File

@@ -0,0 +1,45 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh;
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中对应的方法复制到当前控制器,然后进行修改
*/
}

View File

@@ -0,0 +1,341 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh;
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();
}
}

View File

@@ -0,0 +1,45 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh;
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中对应的方法复制到当前控制器,然后进行修改
*/
}

View File

@@ -0,0 +1,46 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh;
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中对应的方法复制到当前控制器,然后进行修改
*/
}

View File

@@ -0,0 +1,109 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh;
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;
}
}

View 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;
}
}

View File

@@ -0,0 +1,258 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh;
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();
}
}

View File

@@ -0,0 +1,216 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh;
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();
}
}

View File

@@ -0,0 +1,394 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 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'
];
}
}

View 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;
}
}

View File

@@ -0,0 +1,371 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh\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;
}
}

View File

@@ -0,0 +1,299 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh\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('操作成功');
}
}

View File

@@ -0,0 +1,110 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力中小企业发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 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;
}
}

View File

@@ -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;
}
}

View File

@@ -0,0 +1,121 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力中小企业发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 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;
}
}

View File

@@ -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;
}
}

View File

@@ -0,0 +1,218 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh\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;
}
}

View File

@@ -0,0 +1,184 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh\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();
}
}

View File

@@ -0,0 +1,42 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh\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中对应的方法复制到当前控制器,然后进行修改
*/
}

View File

@@ -0,0 +1,137 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh\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;
}
}

View File

@@ -0,0 +1,328 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh\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();
}
}

View File

@@ -0,0 +1,45 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh\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中对应的方法复制到当前控制器,然后进行修改
*/
}

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

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

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

View File

@@ -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;
}
}

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

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

View File

@@ -0,0 +1,249 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh\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();
}
}

View File

@@ -0,0 +1,45 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh\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中对应的方法复制到当前控制器,然后进行修改
*/
}

View File

@@ -0,0 +1,47 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh\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中对应的方法复制到当前控制器,然后进行修改
*/
}

View File

@@ -0,0 +1,178 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh\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();
}
}

View File

@@ -0,0 +1,144 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh\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'));
}
}

View File

@@ -0,0 +1,309 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh\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('操作成功');
}
}

View File

@@ -0,0 +1,246 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh\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;
}
}

View File

@@ -0,0 +1,110 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力中小企业发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 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;
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View 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;
}
}

View 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;
}
}

View 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中对应的方法复制到当前控制器,然后进行修改
*/
}

View 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;
}
}

View 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;
}
}

View File

@@ -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;
}
}

View File

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

View File

@@ -0,0 +1,242 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh\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();
}
}

View File

@@ -0,0 +1,231 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh\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;
}
}

View File

@@ -0,0 +1,185 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh\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();
}
}

View 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;
}
}

View File

@@ -0,0 +1,200 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\admin\controller\wdsxh\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;
}
}