feat(接口): 平台公告和工地公告完成

master
yin5th 2023-01-11 18:28:16 +08:00
parent 48045f0701
commit 2e2b5bc9fc
6 changed files with 131 additions and 34 deletions

View File

@ -15,6 +15,7 @@ use think\Collection;
use think\db\exception\DataNotFoundException; use think\db\exception\DataNotFoundException;
use think\db\exception\DbException; use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException; use think\db\exception\ModelNotFoundException;
use think\facade\Config;
use think\response\Json; use think\response\Json;
class Common extends Base class Common extends Base
@ -100,7 +101,11 @@ class Common extends Base
return $this->json(4002, "参数错误"); return $this->json(4002, "参数错误");
} }
return $this->json(0, 'success', Worksite::getNearest($lng, $lat, 200)); Config::load('extra/base', 'base');
$baseConfig = config('base');
$signArea = $baseConfig['sign_area'] ?? 200;
return $this->json(0, 'success', Worksite::getNearest($lng, $lat, $signArea));
} }
// 工地列表 todo 如果有相关用户 则获取该用户相关的工地列表 如工人 则只获取其参与过的工地列表 需要添加一个字段来确认是否根据用户过滤 // 工地列表 todo 如果有相关用户 则获取该用户相关的工地列表 如工人 则只获取其参与过的工地列表 需要添加一个字段来确认是否根据用户过滤

View File

@ -3,7 +3,9 @@
namespace app\controller\api\v1; namespace app\controller\api\v1;
use app\controller\api\Base; use app\controller\api\Base;
use app\controller\manager\Worksite;
use app\exception\RepositoryException; use app\exception\RepositoryException;
use app\model\Account;
use app\repository\AccountRepository; use app\repository\AccountRepository;
use app\service\ExtraConfig; use app\service\ExtraConfig;
use app\service\order\Compute; use app\service\order\Compute;
@ -24,6 +26,7 @@ class Index extends Base
'handbook', 'handbook',
'computeDay', 'computeDay',
'computeMonth', 'computeMonth',
'worksiteNotice',
]; ];
public function index(): Json public function index(): Json
@ -112,7 +115,7 @@ class Index extends Base
} }
/** /**
* 安全 * 安全
* *
* @return Json * @return Json
*/ */
@ -145,6 +148,29 @@ class Index extends Base
} }
} }
/**
* 工地公告
*
* @return \think\response\Json
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function worksiteNotice(): Json
{
$worksiteId = input('worksite_id/d', 0);
$worksiteId = $worksiteId ?: 0;
$data = [];
if (!$worksite = \app\model\Worksite::findById($worksiteId, ['id', 'notice'])) {
return $this->json(0, 'success', $data);
}
$data = json_decode($worksite['notice'], true);
return $this->json(0, 'success', $data);
}
/** /**
* 员工手册 * 员工手册
* *

View File

@ -441,9 +441,9 @@ class Manager extends Base
} }
OvertimeLog::whereIn('id', $ids)->where('status', ClockLog::COMMON_OFF)->update([ OvertimeLog::whereIn('id', $ids)->where('status', ClockLog::COMMON_OFF)->update([
'status' => $type == 1 ? 1 : -1, 'status' => $type == 1 ? 1 : -1,
'check_at' => date('Y-m-d H:i:s'), 'check_at' => date('Y-m-d H:i:s'),
'check_by' => $accountId, 'check_by' => $accountId,
]); ]);
return $this->json(); return $this->json();
} catch (Exception $e) { } catch (Exception $e) {
@ -780,9 +780,9 @@ class Manager extends Base
} }
AccountDimission::whereIn('id', $ids)->where('status', AccountDimission::COMMON_OFF)->update([ AccountDimission::whereIn('id', $ids)->where('status', AccountDimission::COMMON_OFF)->update([
'status' => $type == 1 ? 1 : -1, 'status' => $type == 1 ? 1 : -1,
'operated_at' => date('Y-m-d H:i:s'), 'operated_at' => date('Y-m-d H:i:s'),
'operated_by' => $accountId, 'operated_by' => $accountId,
'refuse_reason' => $reason, 'refuse_reason' => $reason,
]); ]);
@ -804,7 +804,7 @@ class Manager extends Base
$page = input('page/d', 1); $page = input('page/d', 1);
$size = input('size/d', 20); $size = input('size/d', 20);
$keyword = input('keyword/s'); $keyword = input('keyword/s');
// $status = input('status/d', 0);//状态 0=待审核 1=已审核包含1通过 -1不通过 // $status = input('status/d', 0);//状态 0=待审核 1=已审核包含1通过 -1不通过
$accountId = $this->request->user['user_id'] ?? 0; $accountId = $this->request->user['user_id'] ?? 0;
@ -822,11 +822,11 @@ class Manager extends Base
$where[] = ['cl.real_name|cl.mobile', 'like', '%'.$keyword.'%']; $where[] = ['cl.real_name|cl.mobile', 'like', '%'.$keyword.'%'];
} }
// if ($status == 0) { // if ($status == 0) {
// $where[] = ['cl.status', '=', 0]; // $where[] = ['cl.status', '=', 0];
// } else { // } else {
// $where[] = ['cl.status', 'in', [1, -1]]; // $where[] = ['cl.status', 'in', [1, -1]];
// } // }
// 负责工地 // 负责工地
$worksiteIds = AccountWorksite::where('account_id', $accountId)->column('worksite_id'); $worksiteIds = AccountWorksite::where('account_id', $accountId)->column('worksite_id');
@ -850,12 +850,52 @@ class Manager extends Base
if ($total > 0) { if ($total > 0) {
$res['list'] = $query->page($page, $size)->order('cl.id', 'desc')->select(); $res['list'] = $query->page($page, $size)->order('cl.id', 'desc')->select();
// $res['list']->each(function ($item) { // $res['list']->each(function ($item) {
// $item->created_at = date('Y年m月d日 H:i:s', strtotime($item->created_at)); // $item->created_at = date('Y年m月d日 H:i:s', strtotime($item->created_at));
// }); // });
$res['list'] = arrayNullToString($res['list']->toArray()); $res['list'] = arrayNullToString($res['list']->toArray());
} }
return $this->json(0, 'success', $res); return $this->json(0, 'success', $res);
} }
// 保存|编辑公告
public function saveNotice(): Json
{
$status = input('status/d', 0);
$content = input('content/s');
$accountId = $this->request->user['user_id'] ?? 0;
if (!$account = Account::findById($accountId, ['id, role, worksite_id'])) {
return $this->json(6001, '请先登录');
}
if ($account['role'] <= Account::COMMON_ON) {
// 工地负责人才能操作
return $this->json(4003, '无此权限');
}
if (!$worksite = Worksite::findById($account['worksite_id'])) {
return $this->json(4004, '工地异常');
}
$update = [
'status' => $status,
'content' => $content,
];
$oldNotice = json_decode($worksite['notice'], true);
if ($oldNotice) {
$update['version'] = $oldNotice['content'] == $content ? $oldNotice['version'] : time();
} else {
$update['version'] = time();
}
$worksite->save([
'notice' => json_encode($update, JSON_UNESCAPED_UNICODE)
]);
return $this->json();
}
} }

View File

@ -472,10 +472,12 @@ class User extends Base
*/ */
public function monthSignLog(): Json public function monthSignLog(): Json
{ {
$accountId = $this->request->user['user_id'] ?? 0; $accountId = $this->request->user['user_id'] ?? 0;
$date = input('date/s', ''); $date = input('date/s', '');
$date = $date ?: date('Y-m'); $worksiteId = input('worksite_id/d', 0);
$ym = str_replace('-', '', $date); $worksiteId = $worksiteId ?: 0;
$date = $date ?: date('Y-m');
$ym = str_replace('-', '', $date);
$res = [ $res = [
'ok' => [], //正常打卡:普通用户当天有打卡=正常 工人和负责人打满4次=正常 'ok' => [], //正常打卡:普通用户当天有打卡=正常 工人和负责人打满4次=正常
@ -492,6 +494,7 @@ class User extends Base
$where[] = ['cl.day', 'like', $ym.'%']; $where[] = ['cl.day', 'like', $ym.'%'];
$where[] = ['cl.account_id', '=', $accountId]; $where[] = ['cl.account_id', '=', $accountId];
$where[] = ['cl.role', '=', $account['role']]; $where[] = ['cl.role', '=', $account['role']];
$where[] = ['cl.worksite_id', '=', $worksiteId];
$list = \app\model\ClockLog::alias('cl') $list = \app\model\ClockLog::alias('cl')
->where($where) ->where($where)
->select(); ->select();

View File

@ -19,7 +19,7 @@ class Config extends Base
{ {
parent::initialize(); parent::initialize();
$this->extraPath = config_path() . 'extra/'; $this->extraPath = config_path().'extra/';
if (!is_dir($this->extraPath)) { if (!is_dir($this->extraPath)) {
if (is_writable(config_path())) { if (is_writable(config_path())) {
mkdir($this->extraPath, 0777, true); mkdir($this->extraPath, 0777, true);
@ -36,8 +36,8 @@ class Config extends Base
if ($this->request->isPost()) { if ($this->request->isPost()) {
$data = input("post."); $data = input("post.");
unset($data['_token']); unset($data['_token']);
$php = var_export($data, true); $php = var_export($data, true);
file_put_contents($this->extraPath . 'other.php', '<?php' . PHP_EOL . 'return ' . $php . ';'); file_put_contents($this->extraPath.'other.php', '<?php'.PHP_EOL.'return '.$php.';');
return $this->json(); return $this->json();
} else { } else {
CConfig::load('extra/other', 'other'); CConfig::load('extra/other', 'other');
@ -51,8 +51,8 @@ class Config extends Base
if ($this->request->isPost()) { if ($this->request->isPost()) {
$data = input("post."); $data = input("post.");
unset($data['_token']); unset($data['_token']);
$php = var_export($data, true); $php = var_export($data, true);
file_put_contents($this->extraPath . 'wechat.php', '<?php' . PHP_EOL . 'return ' . $php . ';'); file_put_contents($this->extraPath.'wechat.php', '<?php'.PHP_EOL.'return '.$php.';');
return $this->json(); return $this->json();
} else { } else {
CConfig::load('extra/wechat', 'wechat'); CConfig::load('extra/wechat', 'wechat');
@ -66,8 +66,8 @@ class Config extends Base
if ($this->request->isPost()) { if ($this->request->isPost()) {
$data = input("post."); $data = input("post.");
unset($data['_token']); unset($data['_token']);
$php = var_export($data, true); $php = var_export($data, true);
file_put_contents($this->extraPath . 'alipay.php', '<?php' . PHP_EOL . 'return ' . $php . ';'); file_put_contents($this->extraPath.'alipay.php', '<?php'.PHP_EOL.'return '.$php.';');
return $this->json(); return $this->json();
} else { } else {
CConfig::load('extra/alipay', 'alipay'); CConfig::load('extra/alipay', 'alipay');
@ -88,9 +88,9 @@ class Config extends Base
// 字符串与数组转换 // 字符串与数组转换
$data['poster'] = empty($data['poster'] ?? '') ? [] : explode(',', $data['poster']); $data['poster'] = empty($data['poster'] ?? '') ? [] : explode(',', $data['poster']);
$footBarList = array_values($data['footBar'] ?? []); $footBarList = array_values($data['footBar'] ?? []);
foreach ($footBarList as &$item) { foreach ($footBarList as &$item) {
$icons = empty($item['icon']) ? [] : explode(',', $item['icon']); $icons = empty($item['icon']) ? [] : explode(',', $item['icon']);
$item['icon'] = array_filter($icons); $item['icon'] = array_filter($icons);
} }
unset($item); unset($item);
@ -104,7 +104,7 @@ class Config extends Base
$data['recommend'] = array_values($recommendList); $data['recommend'] = array_values($recommendList);
$php = var_export($data, true); $php = var_export($data, true);
file_put_contents($this->extraPath . 'mini_program.php', '<?php' . PHP_EOL . 'return ' . $php . ';'); file_put_contents($this->extraPath.'mini_program.php', '<?php'.PHP_EOL.'return '.$php.';');
return $this->json(); return $this->json();
} else { } else {
@ -112,7 +112,7 @@ class Config extends Base
$data = config('mini_program'); $data = config('mini_program');
if ($data) { if ($data) {
$data['poster'] = implode(',', $data['poster'] ?? []); $data['poster'] = implode(',', $data['poster'] ?? []);
$footBarList = $data['footBar'] ?? []; $footBarList = $data['footBar'] ?? [];
foreach ($footBarList as &$item) { foreach ($footBarList as &$item) {
$item['icon'] = implode(',', $item['icon'] ?? []); $item['icon'] = implode(',', $item['icon'] ?? []);
} }
@ -126,7 +126,7 @@ class Config extends Base
['key' => 'my', 'name' => '我的', 'aux' => '图标大小为 40 * 40 第1图为默认图第2图为高亮图', 'multi' => 1], ['key' => 'my', 'name' => '我的', 'aux' => '图标大小为 40 * 40 第1图为默认图第2图为高亮图', 'multi' => 1],
['key' => 'cart', 'name' => '购物车', 'aux' => '图标大小为 120 * 120', 'multi' => 0], ['key' => 'cart', 'name' => '购物车', 'aux' => '图标大小为 120 * 120', 'multi' => 0],
]; ];
$this->data = array_merge($this->data, $data); $this->data = array_merge($this->data, $data);
return $this->view(); return $this->view();
} }
} }
@ -137,7 +137,7 @@ class Config extends Base
if ($this->request->isPost()) { if ($this->request->isPost()) {
try { try {
$data = input("post."); $data = input("post.");
$php = var_export($data, true); $php = var_export($data, true);
file_put_contents(config_path().'extra/'.$name.'.php', '<?php'.PHP_EOL.'return '.$php.';'); file_put_contents(config_path().'extra/'.$name.'.php', '<?php'.PHP_EOL.'return '.$php.';');
return $this->json(); return $this->json();
} catch (Exception $e) { } catch (Exception $e) {
@ -150,4 +150,25 @@ class Config extends Base
return $this->view('manager/config/'.unCamelize($name, '_')); return $this->view('manager/config/'.unCamelize($name, '_'));
} }
} }
public function notice()
{
CConfig::load('extra/notice', 'notice');
$oldData = config('notice');;
if ($this->request->isPost()) {
try {
$data = input("post.");
if ($data['content'] != $oldData['content']) {
$data['version'] = time();
}
$php = var_export($data, true);
file_put_contents(config_path().'extra/notice.php', '<?php'.PHP_EOL.'return '.$php.';');
return $this->json();
} catch (Exception $e) {
return $this->json(4001, $e->getMessage());
}
}
$this->data['item'] = $oldData;
return $this->view();
}
} }

View File

@ -12,6 +12,8 @@
</div> </div>
</div> </div>
<input type="hidden" name="version" value="{$item.version ?? ''}">
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">内容</label> <label class="layui-form-label">内容</label>
<div class="layui-input-block editor-text"> <div class="layui-input-block editor-text">