From 7c7f822f59ea5714def38af41aeba1e3a9e0a7b1 Mon Sep 17 00:00:00 2001 From: yin5th <541304803@qq.com> Date: Mon, 9 Jan 2023 19:24:43 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E8=B4=9F=E8=B4=A3=E4=BA=BA=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3):=20=E6=96=B0=E5=A2=9E=20=E5=B7=A5=E4=BA=BA=E5=88=97?= =?UTF-8?q?=E8=A1=A8=20=E5=B7=A5=E4=BA=BA=E8=AF=84=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/v1/Manager.php | 109 ++++++++++++++++++++++++++++++ app/model/AccountStar.php | 10 +++ 2 files changed, 119 insertions(+) create mode 100644 app/model/AccountStar.php diff --git a/app/controller/api/v1/Manager.php b/app/controller/api/v1/Manager.php index 5ad980c..7f7de3e 100644 --- a/app/controller/api/v1/Manager.php +++ b/app/controller/api/v1/Manager.php @@ -4,6 +4,7 @@ namespace app\controller\api\v1; use app\controller\api\Base; use app\model\Account; +use app\model\AccountStar; use app\model\AccountWorksite; use app\model\CheckLog; use app\model\ClockLog; @@ -14,6 +15,7 @@ use app\service\Math; use Exception; use Lcobucci\Clock\Clock; use think\Collection; +use think\facade\Db; use think\response\Json; /** @@ -634,4 +636,111 @@ class Manager extends Base return $this->json(0, 'success', $res); } + + // 工人列表 + public function workerList(): Json + { + $page = input('page/d', 1); + $size = input('size/d', 20); + $keyword = input('keyword/s'); + + $accountId = $this->request->user['user_id'] ?? 0; + + if (!$account = Account::findById($accountId, ['id, role'])) { + return $this->json(6001, '请先登录'); + } + + if ($account['role'] <= Account::COMMON_ON) { + return $this->json(4003, '无查看权限'); + } + + $where = []; + + if (!empty($keyword)) { + $where[] = ['a.real_name|a.mobile', 'like', '%'.$keyword.'%']; + } + + // 负责工地 + $worksiteIds = AccountWorksite::where('account_id', $accountId)->column('worksite_id'); + $where[] = ['a.worksite_id', 'in', $worksiteIds]; + $where[] = ['a.role', '=', Account::ROLE_WORKER]; + + $query = Account::alias('a') + ->leftJoin('worksite w', 'a.worksite_id = w.id') + ->field('a.id,a.real_name,a.work_at,w.name as worksite_name') + ->where($where); + + $total = $query->count(); + + $res = [ + 'total' => $total, + 'current' => $page ?: 1, + 'size' => $size ?: 20, + 'list' => new Collection(), + ]; + + if ($total > 0) { + $list = $query->page($page, $size)->order('a.id', 'desc')->select(); + $accountList = $list->column('id'); + $starList = Db::query("SELECT `star`,`account_id` FROM `bee_account_star` WHERE `id` IN (SELECT max(id) FROM `bee_account_star` WHERE FIND_IN_SET(account_id, ?) GROUP BY `account_id`)", [implode(',', $accountList)]); + + $starArr = []; + foreach ($starList as $l) { + $starArr[$l['account_id']] = $l['star']; + } + + $res['list'] = $list; + $res['list']->each(function ($item) use ($starArr) { + $item->star = $starArr[$item->id] ?? 0; + }); + $res['list'] = arrayNullToString($res['list']->toArray()); + } + + return $this->json(0, 'success', $res); + } + + /** + * 工人评定 + * + * @return Json + */ + public function star(): Json + { + try { + $accountId = $this->request->user['user_id'] ?? 0; + $star = input('star/d', 5);//星级 默认5 + $id = input('id/s'); + + if (!in_array($star, [1, 2, 3, 4, 5])) { + return $this->json(4001, '参数错误'); + } + + if (!$account = Account::findById($accountId, ['id, role'])) { + return $this->json(6001, '请先登录'); + } + + if ($account['role'] <= Account::COMMON_ON) { + // 工地负责人才能操作 + return $this->json(4003, '无此权限'); + } + + $ym = date('Ym'); + if (AccountStar::where('ym', $ym)->where('type', AccountStar::TYPE_WORKER)->where('account_id', $id)->count() > 0) { + return $this->json(4001, '本月已评'); + } + + AccountStar::create([ + 'type' => AccountStar::TYPE_WORKER, + 'star' => $star, + 'account_id' => $id, + 'year' => date('Y'), + 'month' => date('m'), + 'ym' => $ym, + 'operated_by' => $accountId, + ]); + return $this->json(); + } catch (Exception $e) { + return $this->json(5000, '评定失败'.$e->getMessage()); + } + } } diff --git a/app/model/AccountStar.php b/app/model/AccountStar.php new file mode 100644 index 0000000..7a263f5 --- /dev/null +++ b/app/model/AccountStar.php @@ -0,0 +1,10 @@ +