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

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

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

@ -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);
@ -37,7 +37,7 @@ class Config extends Base
$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');
@ -52,7 +52,7 @@ class Config extends Base
$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');
@ -67,7 +67,7 @@ class Config extends Base
$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');
@ -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 {
@ -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">