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

@ -858,4 +858,44 @@ class Manager extends Base
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

@ -474,6 +474,8 @@ class User extends Base
{ {
$accountId = $this->request->user['user_id'] ?? 0; $accountId = $this->request->user['user_id'] ?? 0;
$date = input('date/s', ''); $date = input('date/s', '');
$worksiteId = input('worksite_id/d', 0);
$worksiteId = $worksiteId ?: 0;
$date = $date ?: date('Y-m'); $date = $date ?: date('Y-m');
$ym = str_replace('-', '', $date); $ym = str_replace('-', '', $date);
@ -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

@ -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">