From 2e2b5bc9fc8e134d58c2d419e01a4f44154fa51a Mon Sep 17 00:00:00 2001 From: yin5th <541304803@qq.com> Date: Wed, 11 Jan 2023 18:28:16 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=8E=A5=E5=8F=A3):=20=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E5=85=AC=E5=91=8A=E5=92=8C=E5=B7=A5=E5=9C=B0=E5=85=AC=E5=91=8A?= =?UTF-8?q?=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/v1/Common.php | 7 +++- app/controller/api/v1/Index.php | 28 ++++++++++++- app/controller/api/v1/Manager.php | 70 ++++++++++++++++++++++++------- app/controller/api/v1/User.php | 11 +++-- app/controller/manager/Config.php | 47 +++++++++++++++------ view/manager/config/notice.html | 2 + 6 files changed, 131 insertions(+), 34 deletions(-) diff --git a/app/controller/api/v1/Common.php b/app/controller/api/v1/Common.php index 1c91b3c..1aa715c 100644 --- a/app/controller/api/v1/Common.php +++ b/app/controller/api/v1/Common.php @@ -15,6 +15,7 @@ use think\Collection; use think\db\exception\DataNotFoundException; use think\db\exception\DbException; use think\db\exception\ModelNotFoundException; +use think\facade\Config; use think\response\Json; class Common extends Base @@ -100,7 +101,11 @@ class Common extends Base 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 如果有相关用户 则获取该用户相关的工地列表 如工人 则只获取其参与过的工地列表 需要添加一个字段来确认是否根据用户过滤 diff --git a/app/controller/api/v1/Index.php b/app/controller/api/v1/Index.php index 5b76a4b..6f68bfb 100644 --- a/app/controller/api/v1/Index.php +++ b/app/controller/api/v1/Index.php @@ -3,7 +3,9 @@ namespace app\controller\api\v1; use app\controller\api\Base; +use app\controller\manager\Worksite; use app\exception\RepositoryException; +use app\model\Account; use app\repository\AccountRepository; use app\service\ExtraConfig; use app\service\order\Compute; @@ -24,6 +26,7 @@ class Index extends Base 'handbook', 'computeDay', 'computeMonth', + 'worksiteNotice', ]; public function index(): Json @@ -112,7 +115,7 @@ class Index extends Base } /** - * 安全公告 + * 安全告知 * * @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); + } + /** * 员工手册 * diff --git a/app/controller/api/v1/Manager.php b/app/controller/api/v1/Manager.php index 15f6ea5..7521bb9 100644 --- a/app/controller/api/v1/Manager.php +++ b/app/controller/api/v1/Manager.php @@ -441,9 +441,9 @@ class Manager extends Base } OvertimeLog::whereIn('id', $ids)->where('status', ClockLog::COMMON_OFF)->update([ - 'status' => $type == 1 ? 1 : -1, - 'check_at' => date('Y-m-d H:i:s'), - 'check_by' => $accountId, + 'status' => $type == 1 ? 1 : -1, + 'check_at' => date('Y-m-d H:i:s'), + 'check_by' => $accountId, ]); return $this->json(); } catch (Exception $e) { @@ -780,9 +780,9 @@ class Manager extends Base } AccountDimission::whereIn('id', $ids)->where('status', AccountDimission::COMMON_OFF)->update([ - 'status' => $type == 1 ? 1 : -1, - 'operated_at' => date('Y-m-d H:i:s'), - 'operated_by' => $accountId, + 'status' => $type == 1 ? 1 : -1, + 'operated_at' => date('Y-m-d H:i:s'), + 'operated_by' => $accountId, 'refuse_reason' => $reason, ]); @@ -804,7 +804,7 @@ class Manager extends Base $page = input('page/d', 1); $size = input('size/d', 20); $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; @@ -822,11 +822,11 @@ class Manager extends Base $where[] = ['cl.real_name|cl.mobile', 'like', '%'.$keyword.'%']; } -// if ($status == 0) { -// $where[] = ['cl.status', '=', 0]; -// } else { -// $where[] = ['cl.status', 'in', [1, -1]]; -// } + // if ($status == 0) { + // $where[] = ['cl.status', '=', 0]; + // } else { + // $where[] = ['cl.status', 'in', [1, -1]]; + // } // 负责工地 $worksiteIds = AccountWorksite::where('account_id', $accountId)->column('worksite_id'); @@ -850,12 +850,52 @@ class Manager extends Base if ($total > 0) { $res['list'] = $query->page($page, $size)->order('cl.id', 'desc')->select(); -// $res['list']->each(function ($item) { -// $item->created_at = date('Y年m月d日 H:i:s', strtotime($item->created_at)); -// }); + // $res['list']->each(function ($item) { + // $item->created_at = date('Y年m月d日 H:i:s', strtotime($item->created_at)); + // }); $res['list'] = arrayNullToString($res['list']->toArray()); } 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(); + } } diff --git a/app/controller/api/v1/User.php b/app/controller/api/v1/User.php index f2ae213..348b5e1 100644 --- a/app/controller/api/v1/User.php +++ b/app/controller/api/v1/User.php @@ -472,10 +472,12 @@ class User extends Base */ public function monthSignLog(): Json { - $accountId = $this->request->user['user_id'] ?? 0; - $date = input('date/s', ''); - $date = $date ?: date('Y-m'); - $ym = str_replace('-', '', $date); + $accountId = $this->request->user['user_id'] ?? 0; + $date = input('date/s', ''); + $worksiteId = input('worksite_id/d', 0); + $worksiteId = $worksiteId ?: 0; + $date = $date ?: date('Y-m'); + $ym = str_replace('-', '', $date); $res = [ 'ok' => [], //正常打卡:普通用户当天有打卡=正常 工人和负责人:打满4次=正常 @@ -492,6 +494,7 @@ class User extends Base $where[] = ['cl.day', 'like', $ym.'%']; $where[] = ['cl.account_id', '=', $accountId]; $where[] = ['cl.role', '=', $account['role']]; + $where[] = ['cl.worksite_id', '=', $worksiteId]; $list = \app\model\ClockLog::alias('cl') ->where($where) ->select(); diff --git a/app/controller/manager/Config.php b/app/controller/manager/Config.php index e836406..aa7a200 100644 --- a/app/controller/manager/Config.php +++ b/app/controller/manager/Config.php @@ -19,7 +19,7 @@ class Config extends Base { parent::initialize(); - $this->extraPath = config_path() . 'extra/'; + $this->extraPath = config_path().'extra/'; if (!is_dir($this->extraPath)) { if (is_writable(config_path())) { mkdir($this->extraPath, 0777, true); @@ -36,8 +36,8 @@ class Config extends Base if ($this->request->isPost()) { $data = input("post."); unset($data['_token']); - $php = var_export($data, true); - file_put_contents($this->extraPath . 'other.php', 'extraPath.'other.php', 'json(); } else { CConfig::load('extra/other', 'other'); @@ -51,8 +51,8 @@ class Config extends Base if ($this->request->isPost()) { $data = input("post."); unset($data['_token']); - $php = var_export($data, true); - file_put_contents($this->extraPath . 'wechat.php', 'extraPath.'wechat.php', 'json(); } else { CConfig::load('extra/wechat', 'wechat'); @@ -66,8 +66,8 @@ class Config extends Base if ($this->request->isPost()) { $data = input("post."); unset($data['_token']); - $php = var_export($data, true); - file_put_contents($this->extraPath . 'alipay.php', 'extraPath.'alipay.php', 'json(); } else { CConfig::load('extra/alipay', 'alipay'); @@ -88,9 +88,9 @@ class Config extends Base // 字符串与数组转换 $data['poster'] = empty($data['poster'] ?? '') ? [] : explode(',', $data['poster']); - $footBarList = array_values($data['footBar'] ?? []); + $footBarList = array_values($data['footBar'] ?? []); foreach ($footBarList as &$item) { - $icons = empty($item['icon']) ? [] : explode(',', $item['icon']); + $icons = empty($item['icon']) ? [] : explode(',', $item['icon']); $item['icon'] = array_filter($icons); } unset($item); @@ -104,7 +104,7 @@ class Config extends Base $data['recommend'] = array_values($recommendList); $php = var_export($data, true); - file_put_contents($this->extraPath . 'mini_program.php', 'extraPath.'mini_program.php', 'json(); } else { @@ -112,7 +112,7 @@ class Config extends Base $data = config('mini_program'); if ($data) { $data['poster'] = implode(',', $data['poster'] ?? []); - $footBarList = $data['footBar'] ?? []; + $footBarList = $data['footBar'] ?? []; foreach ($footBarList as &$item) { $item['icon'] = implode(',', $item['icon'] ?? []); } @@ -126,7 +126,7 @@ class Config extends Base ['key' => 'my', 'name' => '我的', 'aux' => '图标大小为 40 * 40; 第1图为默认图,第2图为高亮图', 'multi' => 1], ['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(); } } @@ -137,7 +137,7 @@ class Config extends Base if ($this->request->isPost()) { try { $data = input("post."); - $php = var_export($data, true); + $php = var_export($data, true); file_put_contents(config_path().'extra/'.$name.'.php', 'json(); } catch (Exception $e) { @@ -150,4 +150,25 @@ class Config extends Base 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', 'json(); + } catch (Exception $e) { + return $this->json(4001, $e->getMessage()); + } + } + $this->data['item'] = $oldData; + return $this->view(); + } } \ No newline at end of file diff --git a/view/manager/config/notice.html b/view/manager/config/notice.html index 9f92e4b..0e08580 100644 --- a/view/manager/config/notice.html +++ b/view/manager/config/notice.html @@ -12,6 +12,8 @@ + +