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,88 @@
<?php
namespace app\common\model;
use think\Cache;
use think\Model;
/**
* 地区数据模型
*/
class Area extends Model
{
/**
* 根据经纬度获取当前地区信息
*
* @param string $lng 经度
* @param string $lat 纬度
* @return Area 城市信息
*/
public static function getAreaFromLngLat($lng, $lat, $level = 3)
{
$namearr = [1 => 'geo:province', 2 => 'geo:city', 3 => 'geo:district'];
$rangearr = [1 => 15000, 2 => 1000, 3 => 200];
$geoname = $namearr[$level] ?? $namearr[3];
$georange = $rangearr[$level] ?? $rangearr[3];
// 读取范围内的ID
$redis = Cache::store('redis')->handler();
$georadiuslist = [];
if (method_exists($redis, 'georadius')) {
$georadiuslist = $redis->georadius($geoname, $lng, $lat, $georange, 'km', ['WITHDIST', 'COUNT' => 5, 'ASC']);
}
if ($georadiuslist) {
list($id, $distance) = $georadiuslist[0];
}
$id = isset($id) && $id ? $id : 3;
return self::get($id);
}
/**
* 根据经纬度获取省份
*
* @param string $lng 经度
* @param string $lat 纬度
* @return Area
*/
public static function getProvinceFromLngLat($lng, $lat)
{
$provincedata = null;
$citydata = self::getCityFromLngLat($lng, $lat);
if ($citydata) {
$provincedata = self::get($citydata['pid']);
}
return $provincedata;
}
/**
* 根据经纬度获取城市
*
* @param string $lng 经度
* @param string $lat 纬度
* @return Area
*/
public static function getCityFromLngLat($lng, $lat)
{
$citydata = null;
$districtdata = self::getDistrictFromLngLat($lng, $lat);
if ($districtdata) {
$citydata = self::get($districtdata['pid']);
}
return $citydata;
}
/**
* 根据经纬度获取地区
*
* @param string $lng 经度
* @param string $lat 纬度
* @return Area
*/
public static function getDistrictFromLngLat($lng, $lat)
{
$districtdata = self::getAreaFromLngLat($lng, $lat, 3);
return $districtdata;
}
}

View File

@@ -0,0 +1,98 @@
<?php
namespace app\common\model;
use think\Model;
class Attachment extends Model
{
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 定义字段类型
protected $type = [
];
protected $append = [
'thumb_style'
];
protected static function init()
{
// 如果已经上传该资源,则不再记录
self::beforeInsert(function ($model) {
if (self::where('url', '=', $model['url'])->where('storage', $model['storage'])->find()) {
return false;
}
});
self::beforeWrite(function ($row) {
if (isset($row['category']) && $row['category'] == 'unclassed') {
$row['category'] = '';
}
});
}
public function setUploadtimeAttr($value)
{
return is_numeric($value) ? $value : strtotime($value);
}
public function getCategoryAttr($value)
{
return $value == '' ? 'unclassed' : $value;
}
public function setCategoryAttr($value)
{
return $value == 'unclassed' ? '' : $value;
}
/**
* 获取云储存的缩略图样式字符
*/
public function getThumbStyleAttr($value, $data)
{
if (!isset($data['storage']) || $data['storage'] == 'local') {
return '';
} else {
$config = get_addon_config($data['storage']);
if ($config && isset($config['thumbstyle'])) {
return $config['thumbstyle'];
}
}
return '';
}
/**
* 获取Mimetype列表
* @return array
*/
public static function getMimetypeList()
{
$data = [
"image/*" => __("Image"),
"audio/*" => __("Audio"),
"video/*" => __("Video"),
"text/*" => __("Text"),
"application/*" => __("Application"),
"zip,rar,7z,tar" => __("Zip"),
];
return $data;
}
/**
* 获取定义的附件类别列表
* @return array
*/
public static function getCategoryList()
{
$data = config('site.attachmentcategory') ?? [];
foreach ($data as $index => &$datum) {
$datum = __($datum);
}
$data['unclassed'] = __('Unclassed');
return $data;
}
}

View File

@@ -0,0 +1,87 @@
<?php
namespace app\common\model;
use think\Model;
/**
* 分类模型
*/
class Category extends Model
{
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 追加属性
protected $append = [
'type_text',
'flag_text',
];
protected static function init()
{
self::afterInsert(function ($row) {
$row->save(['weigh' => $row['id']]);
});
}
public function setFlagAttr($value, $data)
{
return is_array($value) ? implode(',', $value) : $value;
}
/**
* 读取分类类型
* @return array
*/
public static function getTypeList()
{
$typeList = config('site.categorytype');
foreach ($typeList as $k => &$v) {
$v = __($v);
}
return $typeList;
}
public function getTypeTextAttr($value, $data)
{
$value = $value ? $value : $data['type'];
$list = $this->getTypeList();
return $list[$value] ?? '';
}
public function getFlagList()
{
return ['hot' => __('Hot'), 'index' => __('Index'), 'recommend' => __('Recommend')];
}
public function getFlagTextAttr($value, $data)
{
$value = $value ? $value : $data['flag'];
$valueArr = explode(',', $value);
$list = $this->getFlagList();
return implode(',', array_intersect_key($list, array_flip($valueArr)));
}
/**
* 读取分类列表
* @param string $type 指定类型
* @param string $status 指定状态
* @return array
*/
public static function getCategoryArray($type = null, $status = null)
{
$list = collection(self::where(function ($query) use ($type, $status) {
if (!is_null($type)) {
$query->where('type', '=', $type);
}
if (!is_null($status)) {
$query->where('status', '=', $status);
}
})->order('weigh', 'desc')->select())->toArray();
return $list;
}
}

View File

@@ -0,0 +1,227 @@
<?php
namespace app\common\model;
use think\Model;
/**
* 配置模型
*/
class Config extends Model
{
// 表名,不含前缀
protected $name = 'config';
// 自动写入时间戳字段
protected $autoWriteTimestamp = false;
// 定义时间戳字段名
protected $createTime = false;
protected $updateTime = false;
// 追加属性
protected $append = [
'extend_html'
];
protected $type = [
'setting' => 'json',
];
/**
* 读取配置类型
* @return array
*/
public static function getTypeList()
{
$typeList = [
'string' => __('String'),
'password' => __('Password'),
'text' => __('Text'),
'editor' => __('Editor'),
'number' => __('Number'),
'date' => __('Date'),
'time' => __('Time'),
'datetime' => __('Datetime'),
'datetimerange' => __('Datetimerange'),
'select' => __('Select'),
'selects' => __('Selects'),
'image' => __('Image'),
'images' => __('Images'),
'file' => __('File'),
'files' => __('Files'),
'switch' => __('Switch'),
'checkbox' => __('Checkbox'),
'radio' => __('Radio'),
'city' => __('City'),
'selectpage' => __('Selectpage'),
'selectpages' => __('Selectpages'),
'array' => __('Array'),
'custom' => __('Custom'),
];
return $typeList;
}
public static function getRegexList()
{
$regexList = [
'required' => '必选',
'digits' => '数字',
'letters' => '字母',
'date' => '日期',
'time' => '时间',
'email' => '邮箱',
'url' => '网址',
'qq' => 'QQ号',
'IDcard' => '身份证',
'tel' => '座机电话',
'mobile' => '手机号',
'zipcode' => '邮编',
'chinese' => '中文',
'username' => '用户名',
'password' => '密码'
];
return $regexList;
}
public function getExtendHtmlAttr($value, $data)
{
$result = preg_replace_callback("/\{([a-zA-Z]+)\}/", function ($matches) use ($data) {
if (isset($data[$matches[1]])) {
return $data[$matches[1]];
}
}, $data['extend']);
return $result;
}
/**
* 读取分类分组列表
* @return array
*/
public static function getGroupList()
{
$groupList = config('site.configgroup');
foreach ($groupList as $k => &$v) {
$v = __($v);
}
return $groupList;
}
public static function getArrayData($data)
{
if (!isset($data['value'])) {
$result = [];
foreach ($data as $index => $datum) {
$result['field'][$index] = $datum['key'];
$result['value'][$index] = $datum['value'];
}
$data = $result;
}
$fieldarr = $valuearr = [];
$field = $data['field'] ?? ($data['key'] ?? []);
$value = $data['value'] ?? [];
foreach ($field as $m => $n) {
if ($n != '') {
$fieldarr[] = $field[$m];
$valuearr[] = $value[$m];
}
}
return $fieldarr ? array_combine($fieldarr, $valuearr) : [];
}
/**
* 将字符串解析成键值数组
* @param string $text
* @return array
*/
public static function decode($text, $split = "\r\n")
{
$content = explode($split, $text);
$arr = [];
foreach ($content as $k => $v) {
if (stripos($v, "|") !== false) {
$item = explode('|', $v);
$arr[$item[0]] = $item[1];
}
}
return $arr;
}
/**
* 将键值数组转换为字符串
* @param array $array
* @return string
*/
public static function encode($array, $split = "\r\n")
{
$content = '';
if ($array && is_array($array)) {
$arr = [];
foreach ($array as $k => $v) {
$arr[] = "{$k}|{$v}";
}
$content = implode($split, $arr);
}
return $content;
}
/**
* 本地上传配置信息
* @return array
*/
public static function upload()
{
$uploadcfg = config('upload');
$uploadurl = request()->module() ? $uploadcfg['uploadurl'] : ($uploadcfg['uploadurl'] === 'ajax/upload' ? 'index/' . $uploadcfg['uploadurl'] : $uploadcfg['uploadurl']);
if (!preg_match("/^((?:[a-z]+:)?\/\/)(.*)/i", $uploadurl) && substr($uploadurl, 0, 1) !== '/') {
$uploadurl = url($uploadurl, '', false);
}
$uploadcfg['fullmode'] = isset($uploadcfg['fullmode']) && $uploadcfg['fullmode'];
$uploadcfg['thumbstyle'] = $uploadcfg['thumbstyle'] ?? '';
$upload = [
'cdnurl' => $uploadcfg['cdnurl'],
'uploadurl' => $uploadurl,
'bucket' => 'local',
'maxsize' => $uploadcfg['maxsize'],
'mimetype' => $uploadcfg['mimetype'],
'chunking' => $uploadcfg['chunking'],
'chunksize' => $uploadcfg['chunksize'],
'savekey' => $uploadcfg['savekey'],
'multipart' => [],
'multiple' => $uploadcfg['multiple'],
'fullmode' => $uploadcfg['fullmode'],
'thumbstyle' => $uploadcfg['thumbstyle'],
'storage' => 'local'
];
return $upload;
}
/**
* 刷新配置文件
*/
public static function refreshFile()
{
//如果没有配置权限无法进行修改
if (!\app\admin\library\Auth::instance()->check('general/config/edit')) {
return false;
}
$config = [];
$configList = self::all();
foreach ($configList as $k => $v) {
$value = $v->toArray();
if (in_array($value['type'], ['selects', 'checkbox', 'images', 'files'])) {
$value['value'] = explode(',', $value['value']);
}
if ($value['type'] == 'array') {
$value['value'] = (array)json_decode($value['value'], true);
}
$config[$value['name']] = $value['value'];
}
file_put_contents(
CONF_PATH . 'extra' . DS . 'site.php',
'<?php' . "\n\nreturn " . var_export_short($config) . ";\n"
);
return true;
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace app\common\model;
use think\Model;
/**
* 邮箱验证码
*/
class Ems extends Model
{
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = false;
// 追加属性
protected $append = [
];
}

View File

@@ -0,0 +1,35 @@
<?php
namespace app\common\model;
use think\Db;
use think\Model;
/**
* <20><><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3>
*/
class Invitation extends Model
{
// <20><><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD>д<EFBFBD><D0B4>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD>
protected $autoWriteTimestamp = 'int';
// <20><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD>
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
/**
* <20><>ȡ<EFBFBD><C8A1>֤<EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD>ֵ
* @param string $value
* @param array $data
* @return object
*/
public function getVerificationAttr($value, $data)
{
$value = array_filter((array)json_decode($value, true));
$value = array_merge(['mobile' => 0], $value);
return (object)$value;
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace app\common\model;
use think\Model;
/**
* 会员余额日志模型
*/
class MoneyLog extends Model
{
// 表名
protected $name = 'user_money_log';
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = '';
// 追加属性
protected $append = [
];
}

View File

@@ -0,0 +1,23 @@
<?php
namespace app\common\model;
use think\Model;
/**
* 会员积分日志模型
*/
class ScoreLog extends Model
{
// 表名
protected $name = 'user_score_log';
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = '';
// 追加属性
protected $append = [
];
}

View File

@@ -0,0 +1,21 @@
<?php
namespace app\common\model;
use think\Model;
/**
* 短信验证码
*/
class Sms extends Model
{
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = false;
// 追加属性
protected $append = [
];
}

View File

@@ -0,0 +1,151 @@
<?php
namespace app\common\model;
use think\Db;
use think\Model;
/**
* 会员模型
*/
class User extends Model
{
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 追加属性
protected $append = [
'url',
];
/**
* 获取个人URL
* @param string $value
* @param array $data
* @return string
*/
public function getUrlAttr($value, $data)
{
return "/u/" . $data['id'];
}
/**
* 获取头像
* @param string $value
* @param array $data
* @return string
*/
public function getAvatarAttr($value, $data)
{
if (!$value) {
//如果不需要启用首字母头像,请使用
//$value = '/assets/img/avatar.png';
$value = letter_avatar($data['nickname']);
}
return $value;
}
/**
* 获取会员的组别
*/
public function getGroupAttr($value, $data)
{
return UserGroup::get($data['group_id']);
}
/**
* 获取验证字段数组值
* @param string $value
* @param array $data
* @return object
*/
public function getVerificationAttr($value, $data)
{
$value = array_filter((array)json_decode($value, true));
$value = array_merge(['email' => 0, 'mobile' => 0], $value);
return (object)$value;
}
/**
* 设置验证字段
* @param mixed $value
* @return string
*/
public function setVerificationAttr($value)
{
$value = is_object($value) || is_array($value) ? json_encode($value) : $value;
return $value;
}
/**
* 变更会员余额
* @param int $money 余额
* @param int $user_id 会员ID
* @param string $memo 备注
*/
public static function money($money, $user_id, $memo)
{
Db::startTrans();
try {
$user = self::lock(true)->find($user_id);
if ($user && $money != 0) {
$before = $user->money;
//$after = $user->money + $money;
$after = function_exists('bcadd') ? bcadd($user->money, $money, 2) : $user->money + $money;
//更新会员信息
$user->save(['money' => $after]);
//写入日志
MoneyLog::create(['user_id' => $user_id, 'money' => $money, 'before' => $before, 'after' => $after, 'memo' => $memo]);
}
Db::commit();
} catch (\Exception $e) {
Db::rollback();
}
}
/**
* 变更会员积分
* @param int $score 积分
* @param int $user_id 会员ID
* @param string $memo 备注
*/
public static function score($score, $user_id, $memo)
{
Db::startTrans();
try {
$user = self::lock(true)->find($user_id);
if ($user && $score != 0) {
$before = $user->score;
$after = $user->score + $score;
$level = self::nextlevel($after);
//更新会员信息
$user->save(['score' => $after, 'level' => $level]);
//写入日志
ScoreLog::create(['user_id' => $user_id, 'score' => $score, 'before' => $before, 'after' => $after, 'memo' => $memo]);
}
Db::commit();
} catch (\Exception $e) {
Db::rollback();
}
}
/**
* 根据积分获取等级
* @param int $score 积分
* @return int
*/
public static function nextlevel($score = 0)
{
$lv = array(1 => 0, 2 => 30, 3 => 100, 4 => 500, 5 => 1000, 6 => 2000, 7 => 3000, 8 => 5000, 9 => 8000, 10 => 10000);
$level = 1;
foreach ($lv as $key => $value) {
if ($score >= $value) {
$level = $key;
}
}
return $level;
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace app\common\model;
use think\Model;
class UserGroup extends Model
{
// 表名
protected $name = 'user_group';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 追加属性
protected $append = [
];
}

View File

@@ -0,0 +1,21 @@
<?php
namespace app\common\model;
use think\Model;
class UserRule extends Model
{
// 表名
protected $name = 'user_rule';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 追加属性
protected $append = [
];
}

View File

@@ -0,0 +1,50 @@
<?php
namespace app\common\model;
use think\Model;
class Version extends Model
{
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 定义字段类型
protected $type = [
];
/**
* 检测版本号
*
* @param string $version 客户端版本号
* @return array
*/
public static function check($version)
{
$versionlist = self::where('status', 'normal')->cache('__version__')->order('weigh desc,id desc')->select();
foreach ($versionlist as $k => $v) {
// 版本正常且新版本号不等于验证的版本号且找到匹配的旧版本
if ($v['status'] == 'normal' && $v['newversion'] !== $version && \fast\Version::check($version, $v['oldversion'])) {
$updateversion = $v;
break;
}
}
if (isset($updateversion)) {
$search = ['{version}', '{newversion}', '{downloadurl}', '{url}', '{packagesize}'];
$replace = [$version, $updateversion['newversion'], $updateversion['downloadurl'], $updateversion['downloadurl'], $updateversion['packagesize']];
$upgradetext = str_replace($search, $replace, $updateversion['content']);
return [
"enforce" => $updateversion['enforce'],
"version" => $version,
"newversion" => $updateversion['newversion'],
"downloadurl" => $updateversion['downloadurl'],
"packagesize" => $updateversion['packagesize'],
"upgradetext" => $upgradetext
];
}
return null;
}
}

View File

@@ -0,0 +1,105 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\common\model\wdsxh;
/**
* Class Cert
* Desc 证书模型
* Create on 2024/3/20 15:10
* Create by wangyafang
*/
class Cert extends \think\Model
{
// 表名
protected $name = 'wdsxh_member_cert';
// 自动写入时间戳字段
protected $autoWriteTimestamp = false;
// 定义时间戳字段名
protected $createTime = false;
protected $updateTime = false;
protected $deleteTime = false;
public static function get_cert_data($type, $applyObj,$member_id) {
$custom_content = json_decode($applyObj['custom_content'],true);
$result = array();
if ($type == '1') {
foreach ($custom_content as $v) {
if ($v['type'] == 'cert' && isset($v['value']['image']) && !empty($v['value']['image'])) {
$result[] = array(
'name'=>$v['value']['name'],
'number'=>$v['value']['number'],
'image'=>$v['value']['image'],
'member_id'=>$member_id,
'wechat_id'=>$applyObj['wechat_id'],
'channel'=>$applyObj['channel'],
);
}
}
} elseif ($type == '2') {
foreach ($custom_content['person'] as $v) {
if ($v['type'] == 'cert' && isset($v['value']['image']) && !empty($v['value']['image'])) {
$result[] = array(
'name'=>$v['value']['name'],
'number'=>$v['value']['number'],
'image'=>$v['value']['image'],
'member_id'=>$member_id,
'wechat_id'=>$applyObj['wechat_id'],
'channel'=>$applyObj['channel'],
);
}
}
foreach ($custom_content['company'] as $v) {
if ($v['type'] == 'cert' && isset($v['value']['image']) && !empty($v['value']['image'])) {
$result[] = array(
'name'=>$v['value']['name'],
'number'=>$v['value']['number'],
'image'=>$v['value']['image'],
'member_id'=>$member_id,
'wechat_id'=>$applyObj['wechat_id'],
'channel'=>$applyObj['channel'],
);
}
}
} else {
foreach ($custom_content['person'] as $v) {
if ($v['type'] == 'cert' && isset($v['value']['image']) && !empty($v['value']['image'])) {
$result[] = array(
'name'=>$v['value']['name'],
'number'=>$v['value']['number'],
'image'=>$v['value']['image'],
'member_id'=>$member_id,
'wechat_id'=>$applyObj['wechat_id'],
'channel'=>$applyObj['channel'],
);
}
}
foreach ($custom_content['organize'] as $v) {
if ($v['type'] == 'cert' && isset($v['value']['image']) && !empty($v['value']['image'])) {
$result[] = array(
'name'=>$v['value']['name'],
'number'=>$v['value']['number'],
'image'=>$v['value']['image'],
'member_id'=>$member_id,
'wechat_id'=>$applyObj['wechat_id'],
'channel'=>$applyObj['channel'],
);
}
}
}
return $result;
}
}

View File

@@ -0,0 +1,401 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力商协会发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdsxh.cn All rights reserved.
// +----------------------------------------------------------------------
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
// +----------------------------------------------------------------------
namespace app\common\model\wdsxh\member;
use app\admin\model\wdsxh\member\IndustryCategory;
use app\admin\model\wdsxh\member\Level;
use think\Config;
/**
* Class Member
* Desc 会员模型
* Create on 2024/3/20 15:36
* Create by wangyafang
*/
class Member extends \think\Model
{
// 表名
protected $name = 'wdsxh_member';
// 自动写入时间戳字段
protected $autoWriteTimestamp = false;
// 定义时间戳字段名
protected $createTime = false;
protected $updateTime = false;
protected $deleteTime = false;
public static function get_member_data($memberApplyObj) {
$memberLevelModel = new Level();
$member_level_name = $memberLevelModel->where('id',$memberApplyObj['member_level_id'])->value('name');
$join_time = date('Y-m-d',time());
$nativePlaceArray = explode('/',$memberApplyObj['native_place']);
$member_data = array(
'type'=>$memberApplyObj['type'],
'wechat_id'=>$memberApplyObj['wechat_id'],
'name'=>$memberApplyObj['name'],
'avatar'=>$memberApplyObj['avatar'],
'mobile'=>$memberApplyObj['mobile'],
'member_level_id'=>$memberApplyObj['member_level_id'],
'member_level_name'=>$member_level_name,
'custom_content'=>$memberApplyObj['custom_content'],
'letter'=>self::getFirstCharter($memberApplyObj['name']),
'join_time'=>$join_time,
'industry_category_id'=>$memberApplyObj['industry_category_id'],
'industry_category_name'=>$memberApplyObj['industry_category_name'],
'native_place' => $memberApplyObj['native_place'],
'introduce_content' => $memberApplyObj['introduce_content'],
'area_letter'=>count($nativePlaceArray) == 3 ? self::getFirstCharter($nativePlaceArray[2]) : '',
);
if (!empty($memberApplyObj['address'])) {
$address_array = json_decode($memberApplyObj['address'],true);
if (isset($address_array['name']) && !empty($address_array['name'])) {
$member_data['address'] = $address_array['name'];
} elseif (isset($address_array['address']) && !empty($address_array['address'])) {
$member_data['address'] = $address_array['address'];
} else {
$member_data['address'] = '';
}
$member_data['longitude'] = isset($address_array['longitude']) ? $address_array['longitude'] : '';
$member_data['latitude'] = isset($address_array['latitude']) ? $address_array['latitude'] : '';
}
switch ($memberApplyObj['type']) {
case 2:
$member_data['company_name'] = $memberApplyObj['company_name'];
$member_data['company_logo'] = $memberApplyObj['company_logo'];
$member_data['company_introduction'] = $memberApplyObj['company_introduction'];
$member_data['company_position'] = $memberApplyObj['company_position'];
break;
case 3:
$member_data['organize_name'] = $memberApplyObj['organize_name'];
$member_data['organize_logo'] = $memberApplyObj['organize_logo'];
$member_data['organize_introduction'] = $memberApplyObj['organize_introduction'];
$member_data['organize_position'] = $memberApplyObj['organize_position'];
break;
}
$member_data['expire_time'] = self::get_expire_time($join_time);
return $member_data;
}
//获取到期时间
public static function get_expire_time($join_time)
{
$feesConfigObj = (new \app\admin\model\wdsxh\member\FeesConfig())->get(1);
if ($feesConfigObj['expire_time_type'] == '1') {//自由时间
$days = $feesConfigObj['days'];
$expire_time = date('Y-m-d',strtotime("{$join_time} +$days day"));
} else {
$expire_time = $feesConfigObj['fixed_date'];
}
return $expire_time;
}
//php获取中文字符拼音首字母
public static function getFirstCharter($str)
{
if (empty($str)) {
return '';
}
if (!preg_match('/[\x{4e00}-\x{9fa5}]/u', $str)) {
return '';
}
$fchar = ord($str[0]);
if ($fchar >= ord('A') && $fchar <= ord('z')) return strtoupper($str[0]);
$s1 = iconv('UTF-8', 'gbk', $str);
$s2 = iconv('gbk', 'UTF-8', $s1);
$s = $s2 == $str ? $s1 : $str;
$asc = ord($s[0]) * 256 + ord($s[1]) - 65536;
if ($asc >= -20319 && $asc <= -20284) return 'A';
if ($asc >= -20283 && $asc <= -19776) return 'B';
if ($asc >= -19775 && $asc <= -19219) return 'C';
if ($asc >= -19218 && $asc <= -18711) return 'D';
if ($asc >= -18710 && $asc <= -18527) return 'E';
if ($asc >= -18526 && $asc <= -18240) return 'F';
if ($asc >= -18239 && $asc <= -17923) return 'G';
if ($asc >= -17922 && $asc <= -17418) return 'H';
if ($asc>=-17417 && $asc<=-16475) return 'J';
if ($asc>=-16474 && $asc<=-16213) return 'K';
if ($asc>=-16212 && $asc<=-15641) return 'L';
if ($asc>=-15640 && $asc<=-15166) return 'M';
if ($asc>=-15165 && $asc<=-14923) return 'N';
if ($asc>=-14922 && $asc<=-14915) return 'O';
if ($asc>=-14914 && $asc<=-14631) return 'P';
if ($asc>=-14630 && $asc<=-14150) return 'Q';
if ($asc>=-14149 && $asc<=-14091) return 'R';
if ($asc>=-14090 && $asc<=-13319) return 'S';
if ($asc>=-13318 && $asc<=-12839) return 'T';
if ($asc>=-12838 && $asc<=-12557) return 'W';
if ($asc>=-12556 && $asc<=-11848) return 'X';
if ($asc>=-11847 && $asc<=-11056) return 'Y';
if ($asc>=-11055 && $asc<=-10247) return 'Z';
return null;
}
public static function get_custom_data($row)
{
$custom_content = array();
switch ($row['type']) {
case 1:
$custom_content = self::person_data($row['custom_content']);
break;
case 2:
$custom_content = self::company_data($row['custom_content']);
break;
case 3:
$custom_content = self::organize_data($row['custom_content']);
break;
}
return $custom_content;
}
public static function person_data($custom_content)
{
$uploadConfig = Config::get("upload");
$custom_content = json_decode($custom_content,true);
foreach ($custom_content as $k=>&$v) {
if ($v['field'] == 'member_level_id') {
$custom_content[$k]['value'] = (new Level())->where('id',$v['value'])->value('name');
}
if ($v['field'] == 'industry_category_id') {
$custom_content[$k]['value'] = (new IndustryCategory())->where('id',$v['value'])->value('name');
}
if ($v['field'] == 'address') {
$custom_content[$k]['value'] = $v['value']['address'];
}
if ($uploadConfig['storage'] != 'local') {
if (in_array($v['type'],['image','video','file'])) {
$v['value'] = self::get_string_full_url($v['value']);
}
if (in_array($v['type'],['cert'])) {
$v['value']['image'] = self::get_string_full_url($v['value']['image']);
}
}
}
return $custom_content;
}
public static function company_data($custom_content)
{
$uploadConfig = Config::get("upload");
$array = array();
$custom_content = json_decode($custom_content,true);
foreach ($custom_content['person'] as $k=>&$v) {
if ($v['field'] == 'member_level_id') {
$v['value'] = (new Level())->where('id',$v['value'])->value('name');
}
if ($v['field'] == 'industry_category_id') {
$v['value'] = (new IndustryCategory())->where('id',$v['value'])->value('name');
}
if ($v['field'] == 'address') {
$v['value'] = $v['value']['address'];
}
if ($uploadConfig['storage'] != 'local') {
if (in_array($v['type'],['image','video','file'])) {
$v['value'] = self::get_string_full_url($v['value']);
}
if (in_array($v['type'],['cert'])) {
$v['value']['image'] = self::get_string_full_url($v['value']['image']);
}
}
$array[] = $v;
}
foreach ($custom_content['company'] as $k=>&$v) {
if ($uploadConfig['storage'] != 'local') {
if (in_array($v['type'],['image','video','file'])) {
$v['value'] = self::get_string_full_url($v['value']);
}
if (in_array($v['type'],['cert'])) {
$v['value']['image'] = self::get_string_full_url($v['value']['image']);
}
}
$array[] = $v;
}
return $array;
}
public static function organize_data($custom_content)
{
$uploadConfig = Config::get("upload");
$array = array();
$custom_content = json_decode($custom_content,true);
foreach ($custom_content['person'] as $k=>&$v) {
if ($v['field'] == 'member_level_id') {
$v['value'] = (new Level())->where('id',$v['value'])->value('name');
}
if ($v['field'] == 'industry_category_id') {
$v['value'] = (new IndustryCategory())->where('id',$v['value'])->value('name');
}
if ($v['field'] == 'address') {
$v['value'] = $v['value']['address'];
}
if ($uploadConfig['storage'] != 'local') {
if (in_array($v['type'],['image','video','file'])) {
$v['value'] = self::get_string_full_url($v['value']);
}
if (in_array($v['type'],['cert'])) {
$v['value']['image'] = self::get_string_full_url($v['value']['image']);
}
}
$array[] = $v;
}
foreach ($custom_content['organize'] as $k=>&$v) {
if ($uploadConfig['storage'] != 'local') {
if (in_array($v['type'],['image','video','file'])) {
$v['value'] = self::get_string_full_url($v['value']);
}
if (in_array($v['type'],['cert'])) {
$v['value']['image'] = self::get_string_full_url($v['value']['image']);
}
}
$array[] = $v;
}
return $array;
}
public static function get_custom_content_full_image($type,$custom_content = '')
{
$custom_content = json_decode($custom_content,true);
if ($type == '1') {
return self::get_person_full_image($custom_content);
} elseif ($type == '2') {
$result = array(
'person'=>self::get_person_full_image($custom_content['person']),
'company'=>self::get_person_full_image($custom_content['company']),
);
return $result;
} elseif ($type == '3') {
$result = array(
'person'=>self::get_person_full_image($custom_content['person']),
'organize'=>self::get_person_full_image($custom_content['organize']),
);
return $result;
}
}
public static function get_person_full_image($custom_content = array())
{
foreach ($custom_content as $k=>$v) {
if (in_array($v['type'],array('image','video'))) {
$custom_content[$k]['value'] = wdsxh_full_url($v['value']);
if(is_array($custom_content[$k]['value'])){
$custom_content[$k]['value'] = implode(',',$custom_content[$k]['value']);
}
}
if ($v['type'] == 'cert' && !empty($v['value']['image'])) {
$custom_content[$k]['value']['image'] = wdsxh_full_url($v['value']['image']);
}
}
return $custom_content;
}
public static function remove_custom_content_full_image($type,$custom_content = '')
{
$result = array();
$custom_content = json_decode($custom_content,true);
if ($type == '1') {
$result = self::remove_person_full_image($custom_content);
} elseif ($type == '2') {
$result = array(
'person'=>self::remove_person_full_image($custom_content['person']),
'company'=>self::remove_person_full_image($custom_content['company']),
);
} elseif ($type == '3') {
$result = array(
'person'=>self::remove_person_full_image($custom_content['person']),
'organize'=>self::remove_person_full_image($custom_content['organize']),
);
}
return json_encode($result);
}
public static function remove_person_full_image($custom_content = array())
{
foreach ($custom_content as $k=>$v) {
if (in_array($v['type'],array('image','video'))) {
$custom_content[$k]['value'] = remove_wdsxh_full_url($v['value']);
}
if ($v['type'] == 'cert' && !empty($v['value']['image'])) {
$custom_content[$k]['value']['image'] = remove_wdsxh_full_url($v['value']['image']);
}
if ($v['field'] == 'avatar' && empty($v['value'])) {
$custom_content[$k]['value'] = '/assets/addons/wdsxh/img/avatar.png';
}
if ($v['field'] == 'company_logo' && empty($v['value'])) {
$custom_content[$k]['value'] = '/assets/addons/wdsxh/img/company_logo.png';
}
if ($v['field'] == 'organize_logo' && empty($v['value'])) {
$custom_content[$k]['value'] = '/assets/addons/wdsxh/img/organize_logo.png';
}
}
return $custom_content;
}
public static function get_string_full_url($url)
{
if(stripos($url,',') !== false){
$urls=explode(',',$url);
foreach ($urls as &$row){
$row=wdsxh_full_url($row);
}
return implode(',',$urls);
}
if (!wdsxh_is_url($url)){
$url = cdnurl($url, true);
if (!wdsxh_is_url($url)) {
$url = request()->domain() . $url;
}
}
return $url;
}
}

View File

@@ -0,0 +1,171 @@
<?php
// +----------------------------------------------------------------------
// | 麦沃德科技赋能开发者,助力中小企业发展
// +----------------------------------------------------------------------
// | Copyright (c) 20172024 www.wdadmin.cn All rights reserved.
// +----------------------------------------------------------------------
// | Wdadmin系统产品软件并不是自由软件不加密并不代表开源未经许可不可自由转售和商用
// +----------------------------------------------------------------------
// | Author: MY WORLD Team <bd@maiwd.cn> www.wdadmin.cn
// +----------------------------------------------------------------------
/**
* Class UserWechatPointsLog
* Desc 微信用户积分日志Model
* Create on 2025/3/11 8:47
* Create by wangyafang
*/
namespace app\common\model\wdsxh\points;
use app\api\model\wdsxh\UserWechat;
use think\Db;
use think\Exception;
use think\exception\PDOException;
use think\exception\ValidateException;
use think\Model;
class UserWechatPointsLog extends Model
{
// 表名
protected $name = 'wdsxh_user_wechat_points_log';
// 自动写入时间戳字段
protected $autoWriteTimestamp = true;
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = false;
protected $deleteTime = false;
protected $type = [
'createtime' => 'timestamp:Y-m-d H:i:s',
];
/**
* Desc 活动积分
* @param $change 1增加积分 2减少积分
* Create on 2025/3/11 9:10
* Create by wangyafang
*/
public static function activity($change, $avtivityApplyObj, $activityObj ,$memo)
{
$userWeachatObj = (new UserWechat())->get($avtivityApplyObj['wechat_id']);
if ($change == 1) {
$after = bcadd($userWeachatObj['points'],$activityObj['points']);
} else {
$after = bcsub($userWeachatObj['points'],$activityObj['points']);
}
$pointsLogData = array(
'wechat_id'=>$avtivityApplyObj['wechat_id'],
'points'=>$activityObj['points'],
'before'=>$userWeachatObj['points'],
'after'=>$after,
'memo'=>$memo,
'change'=>$change,
'activity_id'=>$activityObj['id'],
'source'=>1,
);
self::handle($pointsLogData,$userWeachatObj);
}
/**
* Desc 处理积分
* @param $pointsLogData 积分数据
* @param $userWeachatObj 微信用户数据
* Create on 2025/3/11 9:10
* Create by wangyafang
*/
private static function handle($pointsLogData,$userWeachatObj)
{
$pointsLogModel = new UserWechatPointsLog();
try{
$pointsLogModel->data($pointsLogData);
$pointsLogModel->allowField(true)->save();
$userWeachatObj->points = $pointsLogData['after'];
$userWeachatObj->save();
} catch (ValidateException|PDOException|Exception $e) {
Db::rollback();
error_log('PointsLog error: ' . $e->getMessage());
}
}
/**
* Desc 积分商城
* @param $change 1增加积分 2减少积分
* Create on 2025/3/11 9:10
* Create by wangyafang
*/
public static function pointsMall($change, $orderObj, $goodsObj ,$memo)
{
$userWeachatObj = (new UserWechat())->get($orderObj['wechat_id']);
$after = bcsub($userWeachatObj['points'],$orderObj['total_points']);
$pointsLogData = array(
'wechat_id'=>$orderObj['wechat_id'],
'points'=>$orderObj['total_points'],
'before'=>$userWeachatObj['points'],
'after'=>$after,
'memo'=>$memo,
'change'=>$change,
'points_mall_goods_id'=>$goodsObj['id'],
);
self::handle($pointsLogData,$userWeachatObj);
}
/**
* Desc 增加积分
* @param $change 1增加积分
* @param $source 积分来源:3发布供需4入会成功5邀请会员
* Create on 2025/11/22 14:11
* Create by wangyafang
*/
public static function addPoints($change, $memo , $wechat_id, $add_points , $source)
{
$userWeachatObj = (new UserWechat())->get($wechat_id);
$after = bcadd($userWeachatObj['points'],$add_points);
$pointsLogData = array(
'wechat_id'=>$wechat_id,
'points'=>$add_points,
'before'=>$userWeachatObj['points'],
'after'=>$after,
'memo'=>$memo,
'change'=>$change,
'source'=>$source,
);
self::handle($pointsLogData,$userWeachatObj);
}
/**
* Desc 增加积分
* @param $change 1增加积分
* @param $source 积分来源:3发布供需4入会成功5邀请会员
* Create on 2025/11/22 14:11
* Create by wangyafang
*/
public static function joinMemberAddPoints($change, $memo , $wechat_id, $add_points , $source)
{
$userWeachatObj = (new UserWechat())->get($wechat_id);
$after = bcadd($userWeachatObj['points'],$add_points);
$pointsLogData = array(
'wechat_id'=>$wechat_id,
'points'=>$add_points,
'before'=>$userWeachatObj['points'],
'after'=>$after,
'memo'=>$memo,
'change'=>$change,
'source'=>$source,
);
self::handle($pointsLogData,$userWeachatObj);
$parent_wechat_id = (new UserWechat())->where('id',$wechat_id)->value('parent_wechat_id');
$invite_member_get_points = (new \app\admin\model\wdsxh\points\PointsConfig())->where('id',1)->value('invite_member_get_points');
if($parent_wechat_id && $invite_member_get_points>0){
UserWechatPointsLog::addPoints(1,'邀请会员',$parent_wechat_id,$invite_member_get_points,5);
}
}
}