|
@@ -358,4 +358,276 @@ class GluChronographSheet extends Api
|
|
|
$this->success('成功');
|
|
$this->success('成功');
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 糊盒班组计时报工
|
|
|
|
|
+ * @return void
|
|
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
|
|
+ * @throws \think\exception\DbException
|
|
|
|
|
+ * @throws \think\exception\PDOException
|
|
|
|
|
+ */
|
|
|
|
|
+ public function GluingReportClock()
|
|
|
|
|
+ {
|
|
|
|
|
+ if (!$this->request->isPost()) {
|
|
|
|
|
+ $this->error('请求错误');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $param = $this->request->post();
|
|
|
|
|
+
|
|
|
|
|
+ $validate = new \think\Validate([
|
|
|
|
|
+ 'sczl_rq' => 'require',
|
|
|
|
|
+ 'type' => 'require',
|
|
|
|
|
+ ], [
|
|
|
|
|
+ 'sczl_rq.require' => '请选择上报日期',
|
|
|
|
|
+ 'type.require' => '请选择计时类型',
|
|
|
|
|
+ ]);
|
|
|
|
|
+
|
|
|
|
|
+ if (!$validate->check($param)) {
|
|
|
|
|
+ $this->error($validate->getError());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $employeeFields = $this->parseGluingReportClockEmployeeFields($param);
|
|
|
|
|
+
|
|
|
|
|
+ $data = array_merge([
|
|
|
|
|
+ 'sczl_rq' => $param['sczl_rq'],
|
|
|
|
|
+ 'type' => $param['type'],
|
|
|
|
|
+ 'duration' => $param['duration'],
|
|
|
|
|
+ 'price' => $param['price'],
|
|
|
|
|
+ 'remark' => $param['remark'],
|
|
|
|
|
+ 'sys_id' => $param['sys_id'],
|
|
|
|
|
+ 'sys_rq' => date('Y-m-d H:i:s'),
|
|
|
|
|
+ ], $employeeFields);
|
|
|
|
|
+
|
|
|
|
|
+ if (\db('糊盒班组计时')->insert($data) === false) {
|
|
|
|
|
+ $this->error('报工失败');
|
|
|
|
|
+ }
|
|
|
|
|
+ $this->success('报工成功');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 糊盒班组计时报工删除
|
|
|
|
|
+ * @return void
|
|
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
|
|
+ * @throws \think\exception\DbException
|
|
|
|
|
+ * @throws \think\exception\PDOException
|
|
|
|
|
+ */
|
|
|
|
|
+ public function deleteGluingReportClock()
|
|
|
|
|
+ {
|
|
|
|
|
+ if (!$this->request->isPost()) {
|
|
|
|
|
+ $this->error('请求错误');
|
|
|
|
|
+ }
|
|
|
|
|
+ $params = $this->request->param();
|
|
|
|
|
+ if (!isset($params['id']) || empty($params['id'])){
|
|
|
|
|
+ $this->error('参数错误');
|
|
|
|
|
+ }
|
|
|
|
|
+ $ids = explode(',', $params['id']);
|
|
|
|
|
+ $res = \db('糊盒班组计时')->where('Uid', 'in', $ids)->delete();
|
|
|
|
|
+ if ($res === false) {
|
|
|
|
|
+ $this->error('删除失败');
|
|
|
|
|
+ }
|
|
|
|
|
+ $this->success('删除成功');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 糊盒班组计时报工修改
|
|
|
|
|
+ * @return void
|
|
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
|
|
+ * @throws \think\exception\DbException
|
|
|
|
|
+ * @throws \think\exception\PDOException
|
|
|
|
|
+ */
|
|
|
|
|
+ public function updateGluingReportClock()
|
|
|
|
|
+ {
|
|
|
|
|
+ if (!$this->request->isPost()) {
|
|
|
|
|
+ $this->error('请求错误');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $param = $this->request->post();
|
|
|
|
|
+ if (!isset($param['id']) || empty($param['id'])) {
|
|
|
|
|
+ $this->error('参数错误');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $validate = new \think\Validate([
|
|
|
|
|
+ 'sczl_rq' => 'require',
|
|
|
|
|
+ 'type' => 'require',
|
|
|
|
|
+ ], [
|
|
|
|
|
+ 'sczl_rq.require' => '请选择上报日期',
|
|
|
|
|
+ 'type.require' => '请选择计时类型',
|
|
|
|
|
+ ]);
|
|
|
|
|
+
|
|
|
|
|
+ if (!$validate->check($param)) {
|
|
|
|
|
+ $this->error($validate->getError());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $id = intval($param['id']);
|
|
|
|
|
+ $employeeFields = $this->parseGluingReportClockEmployeeFields($param);
|
|
|
|
|
+
|
|
|
|
|
+ $data = array_merge([
|
|
|
|
|
+ 'sczl_rq' => $param['sczl_rq'],
|
|
|
|
|
+ 'type' => $param['type'],
|
|
|
|
|
+ 'duration' => $param['duration'],
|
|
|
|
|
+ 'price' => $param['price'],
|
|
|
|
|
+ 'remark' => $param['remark'],
|
|
|
|
|
+ 'mod_rq' => date('Y-m-d H:i:s'),
|
|
|
|
|
+ ], $employeeFields);
|
|
|
|
|
+
|
|
|
|
|
+ $result = \db('糊盒班组计时')->where('Uid', $id)->update($data);
|
|
|
|
|
+ if ($result === false) {
|
|
|
|
|
+ $this->error('修改失败');
|
|
|
|
|
+ }
|
|
|
|
|
+ $this->success('修改成功');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 糊盒班组计时报工列表
|
|
|
|
|
+ * @return void
|
|
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
|
|
+ * @throws \think\exception\DbException
|
|
|
|
|
+ * @throws \think\exception\PDOException
|
|
|
|
|
+ */
|
|
|
|
|
+ public function getGluingReportClockList()
|
|
|
|
|
+ {
|
|
|
|
|
+ if (!$this->request->isPost()) {
|
|
|
|
|
+ $this->error('请求错误');
|
|
|
|
|
+ }
|
|
|
|
|
+ $params = $this->request->param();
|
|
|
|
|
+ if (empty($params['sczl_rq'])) {
|
|
|
|
|
+ $this->error('参数错误');
|
|
|
|
|
+ }
|
|
|
|
|
+ $bhFields = [];
|
|
|
|
|
+ for ($i = 1; $i <= 20; $i++) {
|
|
|
|
|
+ $bhFields[] = 'bh' . $i;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $list = \db('糊盒班组计时')
|
|
|
|
|
+ ->field(array_merge([
|
|
|
|
|
+ 'id as 编号',
|
|
|
|
|
+ 'sczl_rq as 上报日期',
|
|
|
|
|
+ 'type as 计时类型',
|
|
|
|
|
+ 'duration as 工时',
|
|
|
|
|
+ 'price as 单价',
|
|
|
|
|
+ 'remark as 备注',
|
|
|
|
|
+ 'sys_id as 创建人员',
|
|
|
|
|
+ 'sys_rq as 上报时间',
|
|
|
|
|
+ ], $bhFields))
|
|
|
|
|
+ ->where('sczl_rq', $params['sczl_rq'])
|
|
|
|
|
+ ->order('id desc')
|
|
|
|
|
+ ->select();
|
|
|
|
|
+
|
|
|
|
|
+ if (empty($list)) {
|
|
|
|
|
+ $this->error('未找到报工数据');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $employeeIds = [];
|
|
|
|
|
+ foreach ($list as $row) {
|
|
|
|
|
+ for ($i = 1; $i <= 20; $i++) {
|
|
|
|
|
+ $bh = isset($row['bh' . $i]) ? trim($row['bh' . $i]) : '';
|
|
|
|
|
+ if ($bh !== '' && $bh !== '000000') {
|
|
|
|
|
+ $employeeIds[$bh] = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $employeeNames = [];
|
|
|
|
|
+ if (!empty($employeeIds)) {
|
|
|
|
|
+ $employees = \db('人事_基本资料')
|
|
|
|
|
+ ->whereIn('员工编号', array_keys($employeeIds))
|
|
|
|
|
+ ->field('员工编号, rtrim(员工姓名) as 姓名')
|
|
|
|
|
+ ->select();
|
|
|
|
|
+ foreach ($employees as $employee) {
|
|
|
|
|
+ $employeeNames[$employee['员工编号']] = $employee['姓名'];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ foreach ($list as $key => $row) {
|
|
|
|
|
+ for ($i = 1; $i <= 20; $i++) {
|
|
|
|
|
+ $bh = isset($row['bh' . $i]) ? trim($row['bh' . $i]) : '';
|
|
|
|
|
+ $list[$key]['员工姓名' . $i] = ($bh !== '' && $bh !== '000000')
|
|
|
|
|
+ ? ($employeeNames[$bh] ?? '')
|
|
|
|
|
+ : '';
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $this->success('获取成功', $list);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 糊盒班组计时报工左侧日期菜单
|
|
|
|
|
+ * @return void
|
|
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
|
|
+ * @throws \think\exception\DbException
|
|
|
|
|
+ * @throws \think\exception\PDOException
|
|
|
|
|
+ */
|
|
|
|
|
+ public function getGluingReportClockDateMenu()
|
|
|
|
|
+ {
|
|
|
|
|
+ if (!$this->request->isGet()) {
|
|
|
|
|
+ $this->error('请求错误');
|
|
|
|
|
+ }
|
|
|
|
|
+ $list = \db('糊盒班组计时')
|
|
|
|
|
+ ->field('DISTINCT(sczl_rq) as sczl_rq')
|
|
|
|
|
+ ->order('sczl_rq desc')
|
|
|
|
|
+ ->select();
|
|
|
|
|
+
|
|
|
|
|
+ $data = [];
|
|
|
|
|
+ foreach ($list as $value) {
|
|
|
|
|
+ $timestamp = strtotime($value['sczl_rq']);
|
|
|
|
|
+ $month = date('Y-m', $timestamp);
|
|
|
|
|
+ $date = date('Y-m-d', $timestamp);
|
|
|
|
|
+ if (!isset($data[$month])) {
|
|
|
|
|
+ $data[$month] = [];
|
|
|
|
|
+ }
|
|
|
|
|
+ $data[$month][] = $date;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $this->success('获取成功', $data);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 解析糊盒班组计时报工员工编号
|
|
|
|
|
+ * @param array $param
|
|
|
|
|
+ * @return array
|
|
|
|
|
+ */
|
|
|
|
|
+ private function parseGluingReportClockEmployeeFields($param)
|
|
|
|
|
+ {
|
|
|
|
|
+ $employeeFields = [];
|
|
|
|
|
+ for ($i = 1; $i <= 20; $i++) {
|
|
|
|
|
+ $employeeFields['bh' . $i] = '';
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $hasEmployee = false;
|
|
|
|
|
+ for ($i = 1; $i <= 20; $i++) {
|
|
|
|
|
+ $bh = isset($param['bh' . $i]) ? trim($param['bh' . $i]) : '';
|
|
|
|
|
+ if ($bh !== '') {
|
|
|
|
|
+ if (!preg_match('/^[a-zA-Z0-9]+$/', $bh)) {
|
|
|
|
|
+ $this->error('员工' . $i . '编号只能由英文字母和数字组成');
|
|
|
|
|
+ }
|
|
|
|
|
+ $employeeFields['bh' . $i] = $bh;
|
|
|
|
|
+ $hasEmployee = true;
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for ($j = $i + 1; $j <= 20; $j++) {
|
|
|
|
|
+ $laterBh = isset($param['bh' . $j]) ? trim($param['bh' . $j]) : '';
|
|
|
|
|
+ if ($laterBh !== '') {
|
|
|
|
|
+ $this->error('员工编号不能间隔填报,请先填写员工' . $i . '编号');
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!$hasEmployee) {
|
|
|
|
|
+ $this->error('请至少填写一个员工编号');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return $employeeFields;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|