feat(负责人接口): 新增 工人列表 工人评级
parent
27ce40f395
commit
7c7f822f59
|
@ -4,6 +4,7 @@ namespace app\controller\api\v1;
|
||||||
|
|
||||||
use app\controller\api\Base;
|
use app\controller\api\Base;
|
||||||
use app\model\Account;
|
use app\model\Account;
|
||||||
|
use app\model\AccountStar;
|
||||||
use app\model\AccountWorksite;
|
use app\model\AccountWorksite;
|
||||||
use app\model\CheckLog;
|
use app\model\CheckLog;
|
||||||
use app\model\ClockLog;
|
use app\model\ClockLog;
|
||||||
|
@ -14,6 +15,7 @@ use app\service\Math;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Lcobucci\Clock\Clock;
|
use Lcobucci\Clock\Clock;
|
||||||
use think\Collection;
|
use think\Collection;
|
||||||
|
use think\facade\Db;
|
||||||
use think\response\Json;
|
use think\response\Json;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -634,4 +636,111 @@ class Manager extends Base
|
||||||
|
|
||||||
return $this->json(0, 'success', $res);
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\model;
|
||||||
|
|
||||||
|
class AccountStar extends Base
|
||||||
|
{
|
||||||
|
public const TYPE_MANAGER = 'manager';//负责人
|
||||||
|
public const TYPE_WORKER = 'worker';//工人
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue