| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\db\exception\BindParamException;
- use think\exception\PDOException;
- use \think\Request;
- use \think\Db;
- /**
- * 装版工时审核页面
- */
- class MountHours extends Api
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- /**
- * 装版工时审核页面左侧菜单
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function getTab()
- {
- if (!$this->request->isGet()) {
- $this->error('请求错误');
- }
- $data = $this->fetchAndFormatPlateChangeData();
- empty($data) ? $this->error('未找到换版数据') : $this->success('成功', $data);
- }
- /**
- * 获取并格式化装版数据
- */
- private function fetchAndFormatPlateChangeData()
- {
- $departments = ['胶印车间', '凹丝印车间', '印后车间', '检验车间'];
- $list = \db('设备_装版工时')
- ->alias('a')
- ->join('设备_基本资料 b', 'a.jtbh = b.设备编号')
- ->field([
- 'DATE_FORMAT(a.sys_rq, "%Y-%m-%d") as day',
- 'DATE_FORMAT(a.sys_rq, "%Y%m") as month',
- 'b.使用部门'
- ])
- ->where('b.使用部门', 'in', $departments)
- ->group('day, b.使用部门')
- ->order('day DESC')
- ->select();
- return array_reduce($list, function ($result, $item) {
- $month = $item['month'];
- $department = $item['使用部门'];
- $day = $item['day'];
- $result[$month][$department][] = $day;
- return $result;
- }, []);
- }
- /**
- * 装版工时审核数据
- * @return void
- */
- public function getMountList()
- {
- // 1. 请求验证
- if (!$this->request->isGet()) {
- $this->error('请求错误');
- }
- // 2. 参数验证
- $params = $this->validateParams($this->request->param());
- // 3. 获取数据
- $list = $this->fetchMountData($params);
- if (empty($list)) {
- $this->error('未找到数据');
- }
- // 4. 处理数据
- $processedList = $this->processListData($list);
- $this->success('成功', $processedList);
- }
- /**
- * 参数验证
- */
- private function validateParams($params)
- {
- if (empty($params['day']) || empty($params['sist'])) {
- $this->error('参数错误:day和sist不能为空');
- }
- // 验证日期格式
- if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $params['day'])) {
- $this->error('参数错误:日期格式不正确');
- }
- return [
- 'day' => $params['day'],
- 'sist' => $params['sist']
- ];
- }
- /**
- * 获取装版数据
- */
- private function fetchMountData($params)
- {
- $fields = [
- 'a.gdbh' => '工单编号',
- 'a.yjno' => '印件号',
- 'a.gxh' => '工序号',
- 'b.sczl_gxmc' => '工序名称',
- 'a.jtbh' => '机台编号',
- 'a.startTime' => '开始时间',
- 'a.endTime' => '结束时间',
- 'a.换版总工时' => '装版总工时',
- 'a.换版联拼数' => '装版联拼数',
- 'a.换版类型' => '装版类型',
- 'a.sys_rq' => '创建时间',
- 'a.coefficient' => '系数',
- 'a.装版补产工时',
- 'a.leader' => '班组长',
- 'a.leaderConfirm' => '班组长确认时间',
- 'a.statistics' => '统计人员',
- 'a.statisticsConfirm' => '统计确认时间',
- 'a.sys_id' => '上报机台',
- 'a.Uniqid',
- 'a.yieldUid' => '关联ID'
- ];
- return \db('设备_装版工时')
- ->alias('a')
- ->join('设备_产量计酬 b', 'a.yieldUid = b.UniqId')
- ->join('设备_基本资料 c', 'a.jtbh = c.设备编号')
- ->field($fields)
- ->where('a.sys_rq', 'like', $params['day'] . '%')
- ->where('c.使用部门', $params['sist'])
- ->group('a.gdbh, a.yjno, a.gxh, a.jtbh, a.换版类型')
- ->order('a.jtbh')
- ->select();
- }
- /**
- * 处理列表数据
- */
- private function processListData($list)
- {
- return array_map(function ($item) {
- return [
- '工单编号' => $item['工单编号'],
- '印件号' => $item['印件号'],
- '工序号' => $item['工序号'],
- '工序名称' => $item['工序名称'],
- '机台编号' => $item['机台编号'],
- '开始时间' => $item['开始时间'],
- '结束时间' => $item['结束时间'],
- '装版总工时' => $item['装版总工时'],
- '装版联拼数' => $item['装版联拼数'],
- '装版类型' => $item['装版类型'],
- '创建时间' => $item['创建时间'],
- '系数' => $item['系数'],
- '装版补产工时' => $item['装版补产工时'],
- '班组长' => $item['班组长'],
- '班组长确认时间' => $item['班组长确认时间'],
- '统计人员' => $item['统计人员'],
- '统计确认时间' => $item['统计确认时间'],
- '上报机台' => $item['上报机台'],
- 'Uniqid' => $item['Uniqid'],
- '班组长确认状态' => $this->getConfirmationStatus($item['班组长'], $item['班组长确认时间']),
- '统计确认状态' => $this->getConfirmationStatus($item['统计人员'], $item['统计确认时间'])
- ];
- }, $list);
- }
- /**
- * 获取确认状态
- */
- private function getConfirmationStatus($person, $confirmTime)
- {
- return !empty($person) && !empty($confirmTime) ? '已确认' : '未确认';
- }
- /**
- * 班组长审核
- * @return void
- * @throws BindParamException
- * @throws PDOException
- * @throws \think\Exception
- */
- public function leaderConfirm()
- {
- if (!$this->request->isPost()) {
- $this->error('请求错误');
- }
- $param = Request::instance()->post();
- if (empty($param)) {
- $this->error('参数错误');
- }
- $coefficient = $param['coefficient'];
- $leader = $param['leader'];
- $leaderConfirm = date('Y-m-d H:i:s');
- $sql = \db('设备_装版工时')
- ->where('Uniqid', $param['Uniqid'])
- ->fetchSql(true)
- ->update(['coefficient' => $coefficient, 'leaderConfirm' => $leaderConfirm, 'leader' => $leader]);
- $res = \db()->query($sql);
- if ($res) {
- $this->success('确认成功');
- }else{
- $this->error('确认失败');
- }
- }
- /**
- * 统计员审核
- * @return void
- * @throws BindParamException
- * @throws PDOException
- * @throws \think\Exception
- */
- public function statisticsConfirm()
- {
- if (!$this->request->isPost()) {
- $this->error('请求错误');
- }
- $param = Request::instance()->post();
- if (empty($param)) {
- $this->error('参数错误');
- }
- $sql = \db('设备_装版工时')
- ->where('Uniqid', $param['Uniqid'])
- ->fetchSql(true)
- ->update(['装版补产工时' => $param['装版补产工时'], 'statisticsConfirm' => $param['statisticsConfirm'], 'statistics' => $param['statistics']]);
- $res = \db()->query($sql);
- $clSql = \db('设备_产量计酬')
- ->where('UniqId', $param['yieldUid'])
- ->fetchSql(true)
- ->update(['sczl_装版工时' => $param['装版补产工时']]);
- $clRes = \db()->query($clSql);
- if ($res || $clRes) {
- $this->success('确认成功');
- }else{
- $this->error('确认失败');
- }
- }
- }
|