request->isGet() === false) { $this->error('请求错误'); } $param = $this->request->param(); //获取最后上传日期 $lastDay = db('物料_电化铝领用记录') ->order('Uniqid desc') ->value('st_rq'); $nextDay = date('Y-m-d', strtotime($lastDay . ' -1 month')); if ($param['type'] == 1){ $list = db('物料_电化铝领用记录') ->field('DATE(st_rq) as st_rq, sys_id, COUNT(*) as count') ->where('st_rq', '>=', $nextDay . ' 00:00:00') // 最小值 ->where('st_rq', '<=', $lastDay) // 最大值 ->group('st_rq, sys_id') ->order('st_rq DESC') ->select(); $data = []; if (!empty($list)){ foreach ($list as $k=>$v){ if (isset($data[$v['st_rq']]) == false){ $data[$v['st_rq']] = []; } $data[$v['st_rq']][] = $v['sys_id'].'【记录数'.$v['count'].'】'; } } }else{ $list = db('物料_电化铝领用记录') ->field('st_gdbh, sys_id, COUNT(*) as count') ->where('st_rq', '>=', $nextDay . ' 00:00:00') // 最小值 ->where('st_rq', '<=', $lastDay) // 最大值 ->group('st_gdbh, sys_id') ->order('st_rq DESC') ->select(); $data = []; if (!empty($list)){ foreach ($list as $k=>$v){ if (isset($data[$v['st_gdbh']]) == false){ $data[$v['st_gdbh']] = []; } $data[$v['st_gdbh']][] = $v['sys_id'].'【记录数'.$v['count'].'】'; } } } $this->success('成功',$data); } /** * 电化铝领用列表 * @return void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function getElectroplatedList() { if ($this->request->isGet() === false) { $this->error('请求错误'); } $params = $this->request->param(); if (empty($params) || !isset($params['search'])) { $this->error('参数错误'); } if ($params['type'] == 1){ $where['a.st_rq'] = ['like',$params['search'].'%']; }else{ $where['a.st_gdbh'] = $params['search']; } if (isset($params['sys_id'])) { $where['a.sys_id'] = $params['sys_id']; } $list = \db('物料_电化铝领用记录') ->alias('a') ->join('工单_印件资料 b', 'a.st_gdbh = b.Yj_Gdbh and a.st_yjno = yj_Yjno') ->join('物料_存货编码 c', 'a.st_wlbh = c.物料代码') ->join('工单_基本资料 d', 'a.st_gdbh = d.Gd_gdbh') ->field('a.st_gdbh, a.st_yjno, a.st_wlbh, a.st_rq,a.st_jylb,a.采购单号,a.供方批次,a.卷宽,a.卷长,a.领用宽度,a.st_sl as 领用数量, a.机台,a.st_desc as 备注,a.Uniqid,rtrim(d.成品名称) as 成品名称,rtrim(b.yj_yjmc) as 印件名称,rtrim(c.物料名称) as 物料名称, rtrim(c.领用单位) as 单位,b.yj_Yjdh as 印件代号,a.sys_rq as 创建时间,rtrim(d.成品代号) as 成品代号') ->where($where) ->select(); if (empty($list)) { $this->error('未找到数据'); }else{ $this->success('成功',$list); } } /** * 电化铝领用记录详情 * @return void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function getElectroplatedDetail() { if ($this->request->isGet() === false) { $this->error('请求错误'); } $params = $this->request->param(); if (empty($params) || !isset($params['Uniqid'])) { $this->error('参数错误'); } $list = \db('物料_电化铝领用记录') ->alias('a') ->join('工单_印件资料 b', 'a.st_gdbh = b.Yj_Gdbh and a.st_yjno = yj_Yjno') ->join('物料_存货编码 c', 'a.st_wlbh = c.物料代码') ->join('工单_基本资料 d', 'a.st_gdbh = d.Gd_gdbh') ->field('a.st_gdbh, a.st_yjno, a.st_wlbh, a.st_rq,a.st_jylb,a.采购单号,a.供方批次,a.卷宽,a.卷长,a.领用宽度,a.st_sl as 领用数量, a.机台,a.st_desc as 备注,a.Uniqid,rtrim(d.成品名称) as 成品名称,rtrim(b.yj_yjmc) as 印件名称,rtrim(c.物料名称) as 物料名称,rtrim(c.领用单位) as 单位') ->where('a.Uniqid', $params['Uniqid']) ->find(); if(empty($list)){ $this->error('未找到数据'); }else{ $this->success('成功',$list); } } /** * 电化铝领用记录修改 * @return void * @throws \think\Exception * @throws \think\db\exception\BindParamException * @throws \think\exception\PDOException */ public function getElectroplatedUpdate() { if ($this->request->isPost() === false) { $this->error('请求错误'); } $params = Request::instance()->param(); if (empty($params) || !isset($params['Uniqid'])) { $this->error('参数错误'); } $data = $params; unset($params['Uniqid']); $params['mod_rq'] = date('Y-m-d H:i:s',time()); $sql = \db('物料_电化铝领用记录') ->where('Uniqid', $data['Uniqid']) ->fetchSql(true) ->update($params); $res = \db()->query($sql); if ($res === false){ $this->error('修改失败'); }else{ $this->success('修改成功'); } } /** * 电化铝领用记录添加 * @return void * @throws \think\db\exception\BindParamException * @throws \think\exception\PDOException */ public function getElectroplatedAdd() { if ($this->request->isPost() === false) { $this->error('请求错误'); } $params = Request::instance()->param(); if (empty($params)) { $this->error('参数错误'); } $params['sys_rq'] = date('Y-m-d H:i:s', time()); $sql = db('物料_电化铝领用记录') ->fetchSql(true) ->insert($params); $res = db()->query($sql); if ($res === false) { $this->error('新增失败'); }else{ $this->success('添加成功'); } } /** * 电化铝领用记录删除 * @return void * @throws \think\Exception * @throws \think\exception\PDOException */ public function getElectroplatedDelete() { if ($this->request->isGet() === false) { $this->error('请求错误'); } $params = $this->request->param(); if (empty($params) || !isset($params['UniqId'])) { $this->error('参数错误'); } $id = explode(',', $params['UniqId']); $res = db('物料_电化铝领用记录') ->whereIn('id', $id) ->delete(); if ($res === false) { $this->error('删除失败'); }else{ $this->success('删除成功'); } } /** * 获取物料信息 * @return void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function getMaterials() { if ($this->request->isGet() === false) { $this->error('请求错误'); } $params = $this->request->param(); if (empty($params) || !isset($params['gdbh']) || !isset($params['yjno'])) { $this->error('参数错误'); } $list = db('工单_印件资料') ->alias('a') ->join('物料_收发记录 b', 'a.Yj_Gdbh = b.st_gdbh and yj_Yjdh = b.cpdh', 'left') ->join('物料_存货编码 c', 'b.st_wlbh = c.物料代码', 'left') ->field('b.st_wlbh as 物料代码,b.供方批次,rtrim(c.物料名称) as 物料名称,rtrim(c.领用单位) as 单位') ->where('a.Yj_Gdbh', $params['gdbh']) ->where('a.yj_Yjno', $params['yjno']) ->where(function ($query) { $query->where('b.仓库编号', '203') ->whereOr('b.仓库编号', 'Y203'); }) ->group('b.供方批次') ->select(); if (empty($list)) { $this->error('未找到数据'); }else{ $this->success('成功', $list); } } /** * 查询机台编号 * @return void */ public function getMachine() { if ($this->request->isGet() === false) { $this->error('请求错误'); } $params = $this->request->param(); if (empty($params)) { $this->error('未输入关键字'); } $machineList = db('设备_基本资料') ->where('设备编号','like', '%'.$params['search'].'%') ->where('sys_sbID','<>','') ->whereNotNull('sys_sbID') ->order('设备编号 asc') ->column('rtrim(设备编号) as 设备编号'); if (empty($machineList)) { $this->error('未找到数据'); }else{ $this->success('成功', $machineList); } } }