创建版本

This commit is contained in:
2021-02-22 12:17:00 +08:00
commit af555f49c3
2332 changed files with 369202 additions and 0 deletions
@@ -0,0 +1,183 @@
<?php namespace Gdoo\Index\Services;
use Request;
use DB;
use Auth;
class AttachmentService
{
public static function files($name, $path = 'default')
{
$files = Request::file($name);
$path = $path.'/'.date('Ym');
$upload_path = upload_path().'/'.$path;
$res = [];
foreach ($files as $file) {
if ($file->isValid()) {
// 文件后缀名
$extension = $file->getClientOriginalExtension();
// 兼容do客户端上传
if ($extension == 'do') {
$clientName = $file->getClientOriginalName();
$extension = pathinfo(substr($clientName, 0, -3), PATHINFO_EXTENSION);
}
// 文件新名字
$name = date('dhis_').str_random(4).'.'.$extension;
$name = mb_strtolower($name);
if ($file->move($upload_path, $name)) {
$res[] = DB::table('attachment')->insertGetId([
'name' => $name,
'path' => $path.'/'.$name,
'type' => $extension,
'size' => $file->getClientSize(),
'status' => 1,
]);
}
}
}
return join(',', array_filter($res));
}
public static function base64($images, $path = 'default', $extension = 'jpg')
{
$path = $path.date('/Ym');
$directory = upload_path().'/'.$path;
if (!is_dir($directory)) {
@mkdir($directory, 0777, true);
}
$res = [];
foreach ($images as $image) {
$name = date('dhis_').str_random(4).'.'.$extension;
$name = mb_strtolower($name);
$image = base64_decode(str_replace(' ', '+', $image));
$size = file_put_contents($directory.'/'.$name, $image);
if ($size) {
$res[] = DB::table('attachment')->insertGetId([
'name' => $name,
'path' => $path.'/'.$name,
'type' => $extension,
'size' => $size,
'status' => 1,
]);
}
}
return join(',', array_filter($res));
}
/**
* 将ids字符串转换为数组
*/
public static function getIds($ids)
{
if (is_array($ids)) {
return $ids;
}
$ids = array_filter(explode("\n", $ids));
return (array)$ids;
}
/**
* 获取指定编号附件列表
*/
public static function get($ids)
{
$ids = self::getIds($ids);
return DB::table('attachment')
->whereIn('id', $ids)
->where('status', 1)->get();
}
/**
* 获取当前ID附件和草稿
*/
public static function edit($ids, $key)
{
$res['rows'] = self::get($ids);
$res['draft'] = self::draft($key);
return $res;
}
/**
* 获取当前ID附件
*/
public static function show($ids)
{
$res['rows'] = self::get($ids);
return $res;
}
/**
* 发布附件,改成状态为可用
*/
public static function publish($ids)
{
$ids = self::getIds($ids);
$rows = DB::table('attachment')
->whereIn('id', $ids)
->where('status', 0)
->get();
foreach ($rows as $row) {
DB::table('attachment')->where('id', $row['id'])->update([
'status' => 1,
]);
}
return true;
}
/**
* 发布附件,改成状态为可用
*/
public static function store($key)
{
$rows = self::draft($key);
foreach ($rows as $row) {
DB::table('attachment')->where('id', $row['id'])->update([
'status' => 1,
]);
}
return true;
}
/**
* 获取草稿文件
*/
public static function draft($key, $user_id = 0)
{
if ($user_id == 0) {
$user_id = auth()->id();
}
return DB::table('attachment')
->where('created_id', $user_id)
->where('key', $key)
->where('status', '0')
->get();
}
/**
* 删除附件和文件
*/
public static function remove($ids)
{
$ids = self::getIds($ids);
$rows = DB::table('attachment')->whereIn('id', $ids)->get();
foreach ($rows as $row) {
// 删除文件
$file = upload_path().'/'.$row['path'];
if (is_file($file)) {
unlink($file);
}
DB::table('attachment')->where('id', $row['id'])->delete();
}
return 1;
}
}
+27
View File
@@ -0,0 +1,27 @@
<?php namespace Gdoo\Index\Services;
use DB;
class BadgeService
{
/**
* 获取待办事项
*/
public static function getModelTodo($table)
{
$master = DB::table('model')->where('table', $table)->first();
$rows = DB::table('model_run_log')
->leftJoin('model_run', 'model_run.id', '=', 'model_run_log.run_id')
->leftJoin($table, $table.'.id', '=', 'model_run.data_id')
->leftJoin('user as run_log_user', 'run_log_user.id', '=', 'model_run_log.user_id')
->where('model_run_log.updated_id', 0)
->where('model_run_log.user_id', auth()->id())
->where('model_run_log.bill_id', $master['id'])
->where($table.'.id', '>', 0)
->get(['model_run_log.*']);
$ret['total'] = sizeof($rows);
$ret['data'] = $rows;
return $ret;
}
}
+149
View File
@@ -0,0 +1,149 @@
<?php namespace Gdoo\Index\Services;
use DB;
use Auth;
use Gdoo\System\Models\Widget;
use Gdoo\User\Models\UserWidget;
use Request;
class InfoService
{
/**
* 获取季度日期
*/
public static function getSeason($interval = 0) {
$season = ceil(date('n') / 3) + $interval;
$a = date('Y-m-d', mktime(0, 0, 0, $season * 3 - 3 + 1, 1, date('Y')));
$b = date('Y-m-d', mktime(23, 59, 59, $season * 3, date('t', mktime(0, 0, 0, $season * 3, 1, date("Y"))), date('Y')));
return [$a, $b];
}
public static function getInfo($table)
{
$auth = auth()->user();
$gets = Request::all();
$dates = [
'day' => '昨天',
'day2' => '前天',
'week' => '上周',
'week2' => '前周',
'month' => '上月',
'month2' => '前月',
'quarter' => '上季度',
'quarter2' => '前季度',
'year' => '去年',
'year2' => '前年',
];
$user_info = UserWidget::where('user_id', $auth['id'])
->where('id', $gets['id'])->first();
$info = Widget::where('id', $user_info['node_id'])
->first();
if (not_empty($user_info)) {
$info['id'] = $user_info['id'];
if ($user_info['name']) {
$info['name'] = $user_info['name'];
}
if ($user_info['color']) {
$info['color'] = $user_info['color'];
}
if ($user_info['icon']) {
$info['icon'] = $user_info['icon'];
}
$info['params'] = json_decode($user_info['params'], true);
}
$params = $info['params'];
$permission = empty($params['permission']) ? 'department' : $params['permission'];
$date = empty($params['date']) ? 'month' : $params['date'];
switch ($date) {
case 'day':
case 'day2':
// 天
$day = date('Y-m-d');
$day2 = strtotime('-1 day '.$day);
$day3 = strtotime('-2 day '.$day);
break;
case 'week':
case 'week2':
// 周
$week[] = date('Y-m-d', strtotime('this week'));
$week[] = date('Y-m-d', strtotime('this week +6 day'));
$week2[] = date('Y-m-d', strtotime('next week'));
$week2[] = date('Y-m-d', strtotime('next week +6 day'));
$week3[] = date('Y-m-d', strtotime('monday -2 week'));
$week3[] = date('Y-m-d', strtotime('sunday -1 week'));
break;
case 'month':
case 'month2':
// 月
$month = date('Y-m');
$month2 = date('Y-m', strtotime("-1 month"));
$month3 = date('Y-m', strtotime("-2 month"));
break;
case 'season':
case 'season2':
// 季度
$season = static::getSeason();
$season2 = static::getSeason(-1);
$season3 = static::getSeason(-2);
break;
case 'year':
case 'year2':
// 年
$year = date('Y');
$year2 = $year - 1;
$year3 = $year - 2;
break;
}
$sql = $sql2 = '';
switch ($date) {
case 'day':
$sql = sql_year_month_day($table.'created_at','ts')."='$day'";
$sql2 = sql_year_month_day($table.'created_at','ts')."='$day2'";
break;
case 'day2':
$sql = sql_year_month_day($table.'.created_at','ts')."='$day2'";
$sql2 = sql_year_month_day($table.'.created_at','ts')."='$day3'";
break;
case 'week':
$sql = sql_year_month_day($table.'.created_at','ts')." between '$week[0]' and '$week[1]'";
$sql2 = sql_year_month_day($table.'.created_at','ts')." between '$week2[0]' and '$week2[1]'";
break;
case 'week2':
$sql = sql_year_month_day($table.'.created_at','ts')." between '$week2[0]' and '$week2[1]'";
$sql2 = sql_year_month_day($table.'.created_at','ts')." between '$week3[0]' and '$week3[1]'";
break;
case 'month':
$sql = sql_year_month($table.'.created_at','ts')."='$month'";
$sql2 = sql_year_month($table.'.created_at','ts')."='$month2'";
break;
case 'month2':
$sql = sql_year_month($table.'.created_at','ts')."='$month2'";
$sql2 = sql_year_month($table.'.created_at','ts')."='$month3'";
break;
case 'season':
$sql = sql_year_month_day($table.'.created_at','ts')." between '$season[0]' and '$season[1]'";
$sql2 = sql_year_month_day($table.'.created_at','ts')." between '$season2[0]' and '$season2[1]'";
break;
case 'season2':
$sql = sql_year_month_day($table.'.created_at','ts')." between '$season2[0]' and '$season2[1]'";
$sql2 = sql_year_month_day($table.'.created_at','ts')." between '$season3[0]' and '$season3[1]'";
break;
case 'year':
$sql = sql_year($table.'.created_at','ts')."='$year'";
$sql2 = sql_year($table.'.created_at','ts')."='$year2'";
break;
case 'year2':
$sql = sql_year($table.'.created_at','ts')."='$year2'";
$sql2 = sql_year($table.'.created_at','ts')."='$year3'";
break;
}
return ['info' => $info, 'dates' => $dates, 'sql' => $sql, 'sql2' => $sql2, 'gets' => $gets, 'params' => $params, 'auth' => $auth];
}
}
+70
View File
@@ -0,0 +1,70 @@
<?php namespace Gdoo\Index\Services;
use Auth;
use DB;
use Gdoo\User\Services\UserAssetService;
class MenuService
{
/**
* 取得菜单列表
*/
public static function getItems()
{
static $data = [];
if ($data) {
return $data;
}
$assets = UserAssetService::getRoleAuthorise(Auth::user()->role_id);
$menus = DB::table('menu')->where('status', 1)->orderBy('lft', 'asc')->get();
$menus = array_tree($menus);
$positions = [];
foreach ($menus as $menuId => &$menu) {
if ($menu['children']) {
// 二级菜单
foreach ($menu['children'] as $groupId => &$group) {
$group['url'] = str_replace('.', '/', $group['url']);
if (substr_count($group['url'], '/') < 2) {
$group['url'] = '';
}
if ($group['url']) {
$group['url'] = str_replace('.', '/', $group['url']);
$group['key'] = str_replace('/', '_', $group['url']);
if ($group['access'] == 0 || isset($assets[$group['url']])) {
$menu['selected'] = 1;
$group['selected'] = 1;
}
}
if ($group['children']) {
// 三级菜单
foreach ($group['children'] as $actionId => &$action) {
$action['url'] = str_replace('.', '/', $action['url']);
$action['key'] = str_replace('/', '_', $action['url']);
$positions[$action['url']] = $menuId.','.$groupId.','.$actionId;
if ($action['access'] == 0 || isset($assets[$action['url']])) {
if (empty($group['url'])) {
$group['url'] = $action['url'];
$group['key'] = $action['key'];
}
$menu['selected'] = 1;
$group['selected'] = 1;
$action['selected'] = 1;
}
}
}
}
}
}
$data['children'] = $menus;
return $data;
}
}
@@ -0,0 +1,155 @@
<?php namespace Gdoo\Index\Services;
use Log;
use DB;
use Mail;
use Gdoo\System\Models\Setting;
use Gdoo\Wechat\Services\WechatService;
use Gdoo\System\Services\SmsService;
class NotificationService
{
/**
* 微信公众号模板消息
*/
public static function wechatTemplate($users, $content)
{
if (env('WECHAT_MESSAGE_PUSH_STATUS') === false) {
return false;
}
if (empty($users) || empty($content)) {
return false;
}
try {
$tousers = DB::table('wechat_user')->whereIn('user_id', $users)->pluck('openid');
if ($tousers) {
$app = WechatService::getApp();
foreach ($tousers as $touser) {
$content['touser'] = $touser;
$app->template_message->send($content);
}
}
return true;
} catch(\Exception $e) {
system_log('notification.wechat', '微信消息', $e->getMessage(), 'error');
return false;
}
}
/**
* 站内通知
*/
public static function site($users, $subject, $content, $url)
{
if (empty($subject) || empty($content) || empty($users)) {
return false;
}
try {
foreach ($users as $user_id) {
DB::table('user_message')->insert([
'content' => $subject.$content,
'url' => $url,
'read_id' => $user_id,
'created_id' => auth()->id(),
]);
}
return true;
} catch(\Exception $e) {
system_log('notification.site', '站内消息', $e->getMessage(), 'error');
return false;
}
}
/**
* 添加新通知
*/
public static function sms($users, $subject, $content = '')
{
if (empty($subject) || empty($users)) {
return false;
}
try {
// 短信群发一次最大条数
$users = array_chunk($users, 500);
foreach ($users as $user) {
$user = join(',', $user);
if ($user) {
// 记录发送结果
$res = SmsService::send($user, $subject.$content);
if ($res['code'] <> 0) {
abort_error($res['msg']);
}
foreach ($res['data'] as $row) {
$data = json_encode([
'msg' => $row['msg'],
'code' => $row['code'],
'count' => $row['count'],
], JSON_UNESCAPED_UNICODE);
$log = [
'content' => $subject.$content,
'data' => $data,
'phone' => $row['mobile'],
'status' => $row['code'] == 0 ? 1 : 0,
];
DB::table('sms_log')->insert($log);
}
}
}
return true;
} catch(\Exception $e) {
system_log('notification.sms', '短信消息', $e->getMessage(), 'error');
return false;
}
}
/**
* 邮件通知
*/
public static function mail($view, $users, $subject, $content)
{
if ($subject == '' || $content == '' || empty($users)) {
return false;
}
$setting = Setting::where('type', 'system')->pluck('value', 'key');
$mail = DB::table('mail')->where('status', 1)->orderBy('sort', 'asc')->first();
$config = config('mail');
config([
'mail' => array_merge($config, [
'host' => $mail['smtp'],
'port' => $mail['port'],
'encryption' => $mail['secure'],
'username' => $mail['user'],
'password' => $mail['password'],
'from' => [
'address' => $mail['user'],
'name' => $mail['name'],
],
])
]);
$data['subject'] = $subject;
$data['content'] = $content;
try {
return Mail::send('emails.'.$view, $data, function ($message) use ($setting, $users, $subject) {
foreach ($users as $user) {
$message->to($user);
}
$message->subject($setting['title']);
});
} catch(\Exception $e) {
system_log('notification.mail', '邮件消息', $e->getMessage(), 'error');
return false;
}
}
}
+39
View File
@@ -0,0 +1,39 @@
<?php namespace Gdoo\Index\Services;
class RetService
{
public $data = null;
public static function make($data = null)
{
$me = new static();
$me->data = collect();
$me->set($data);
return $me;
}
public function set($key, $value = null)
{
if (empty($key)) {
return;
}
if (empty($value)) {
$this->data = $this->data->merge($key);
} else {
$this->data[$key] = $value;
}
}
public function error($msg)
{
$this->data['msg'] = $msg;
$this->data['success'] = false;
return json_encode($this->data, JSON_UNESCAPED_UNICODE);
}
public function success($msg)
{
$this->data['msg'] = $msg;
$this->data['success'] = true;
return json_encode($this->data, JSON_UNESCAPED_UNICODE);
}
}
+91
View File
@@ -0,0 +1,91 @@
<?php namespace Gdoo\Index\Services;
use Gdoo\Index\Models\Share;
use Gdoo\User\Models\User;
class ShareService
{
/**
* 获取分享数据
*/
public static function getItemsSourceBy(array $source_type, $user_id)
{
$user = User::find($user_id);
return Share::leftJoin('user', 'share.created_id', '=', 'user.id')
->permission('share.receive_id', $user)
->whereIn('share.source_type', $source_type)
->get(['share.*', 'user.name', 'user.username']);
}
/**
* 获取分享数据
*/
public static function getItemsCreatedBy(array $source_type, $user_id)
{
return Share::where('created_id', $user_id)
->whereIn('source_type', $source_type)
->get();
}
/**
* 添加分享数据
*/
public static function getItemsSourceId($source_type, $source_id)
{
return Share::where('source_id', $source_id)
->where('source_type', $source_type)
->get();
}
/**
* 添加分享数据
*/
public static function getItem($source_type, $source_id)
{
return Share::where('source_id', $source_id)
->where('source_type', $source_type)
->first();
}
/**
* 删除一条分享数据
*/
public static function removeItem($source_type, $source_id)
{
return Share::where('source_id', $source_id)
->where('source_type', $source_type)
->delete();
}
/**
* 添加分享数据
*/
public static function addItem($data)
{
if ($data['receive_id'] == '') {
return;
}
if (empty($data['source_id']) || empty($data['source_type'])) {
return;
}
Share::insert($data);
}
/**
* 编辑分享数据
*/
public static function editItem($source_type, $source_id, $data)
{
if ($data['receive_id'] == '') {
// 共享对象为空删除共享记录
static::removeItem($source_type, $source_id);
return;
}
if (empty($source_id) || empty($source_type)) {
return;
}
return Share::where('source_id', $source_id)
->where('source_type', $source_type)
->update($data);
}
}