|
|
@@ -131,13 +131,248 @@ class MachineProductionReportAdd extends Api
|
|
|
$this->error('参数错误');
|
|
|
}
|
|
|
|
|
|
- $rows = db()->table('db_sczl')->alias('d')
|
|
|
- ->field('d.*, ')
|
|
|
- ->join('工单_基本资料 g', 'd.')
|
|
|
+ $rows = db()->table('db_sczladd')->alias('d')
|
|
|
+ ->field('LEFT(d.sczl_rq, 10) as sczl_rq, d.sczl_jtbh, rtrim(g.设备名称) as 设备名称, d.sczl_bzdh, d.sczl_设备运行工时, d.sczl_desc')
|
|
|
+ ->join('设备_基本资料 g', 'd.sczl_jtbh=g.设备编号')
|
|
|
->where('d.UniqId',$UniqId)
|
|
|
->select();
|
|
|
|
|
|
-
|
|
|
$this->success('成功',$rows);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询机台
|
|
|
+ * @ApiMethod (GET)
|
|
|
+ */
|
|
|
+ public function getJtbh()
|
|
|
+ {
|
|
|
+ //get请求
|
|
|
+ if(!$this->request->isGet()){
|
|
|
+ $this->error('请求方式错误');
|
|
|
+ }
|
|
|
+ $req = $this->request->param();
|
|
|
+ if (isset($req['sys_mc'])){
|
|
|
+ $sys_mc = $req['sys_mc'];
|
|
|
+ }else{
|
|
|
+ $this->error('参数错误');
|
|
|
+ }
|
|
|
+ $rows = db()->table('设备_基本资料')
|
|
|
+ ->field('rtrim(使用部门) as 使用部门, rtrim(设备编号) as jtbh, rtrim(设备名称) as 设备名称')
|
|
|
+ ->where('设备编号|设备名称','like','%'.$sys_mc.'%')
|
|
|
+ ->order('设备编号 asc')
|
|
|
+ ->select();
|
|
|
+ $arr = ['胶印车间', '凹印车间', '丝印车间', '烫模车间', '检验车间', '研发中心'];
|
|
|
+ $data = [];
|
|
|
+ $data['使用部门'] = $arr;
|
|
|
+ foreach ($arr as $value) {
|
|
|
+ $data[$value] = [];
|
|
|
+ foreach ($rows as $row){
|
|
|
+ if($row['使用部门']==$value){
|
|
|
+ unset($row['使用部门']);
|
|
|
+ array_push($data[$value], $row);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $this->success('成功',[$data]);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增
|
|
|
+ * @ApiMethod (POST)
|
|
|
+ * @param string
|
|
|
+ */
|
|
|
+ public function add()
|
|
|
+ {
|
|
|
+ if(!$this->request->isPost()){
|
|
|
+ $this->error('请求方式错误');
|
|
|
+ }
|
|
|
+ $req = $this->request->param();
|
|
|
+ $arr = [
|
|
|
+ 'sys_id','sczl_rq','sczl_jtbh',
|
|
|
+ 'sczl_bzdh','sczl_设备运行工时',
|
|
|
+ 'sczl_desc'
|
|
|
+ ];
|
|
|
+ $data = [];
|
|
|
+ foreach ($arr as $key => $value){
|
|
|
+ if (!(isset($req[$value]))){
|
|
|
+ $this->error('参数错误',$value,$key+1);
|
|
|
+ }
|
|
|
+ $data[$value] = $req[$value];
|
|
|
+ }
|
|
|
+ $data['sys_rq'] = date('Y-m-d H:i:s');
|
|
|
+
|
|
|
+ //开启事务
|
|
|
+ db()->startTrans();
|
|
|
+ try{
|
|
|
+ $sql = db()->table('db_sczladd')->fetchSql(true)->insert($data);
|
|
|
+ $bool = db()->query($sql);
|
|
|
+ // 提交事务
|
|
|
+ db()->commit();
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ // 回滚事务
|
|
|
+ db()->rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ if($bool===false) $this->error('失败');
|
|
|
+
|
|
|
+ $this->success('成功');
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增
|
|
|
+ * @ApiMethod (POST)
|
|
|
+ * @param string
|
|
|
+ */
|
|
|
+ public function edit()
|
|
|
+ {
|
|
|
+ if(!$this->request->isPost()){
|
|
|
+ $this->error('请求方式错误');
|
|
|
+ }
|
|
|
+ $req = $this->request->param();
|
|
|
+ $arr = [
|
|
|
+ 'sys_id','sczl_rq','sczl_jtbh',
|
|
|
+ 'sczl_bzdh','sczl_设备运行工时',
|
|
|
+ 'sczl_desc'
|
|
|
+ ];
|
|
|
+ $data = [];
|
|
|
+ foreach ($arr as $key => $value){
|
|
|
+ if (!(isset($req[$value]))){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $data[$value] = $req[$value];
|
|
|
+ }
|
|
|
+ if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
|
|
|
+ $this->error('参数错误','UniqId',100);
|
|
|
+ }
|
|
|
+ $data['mod_rq'] = date('Y-m-d H:i:s');
|
|
|
+
|
|
|
+ //开启事务
|
|
|
+ db()->startTrans();
|
|
|
+ try{
|
|
|
+ $sql = db()->table('db_sczladd')->where('UniqId',$req['UniqId'])->fetchSql(true)->update($data);
|
|
|
+ $bool = db()->query($sql);
|
|
|
+ // 提交事务
|
|
|
+ db()->commit();
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ // 回滚事务
|
|
|
+ db()->rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ if($bool===false) $this->error('失败');
|
|
|
+
|
|
|
+ $this->success('成功');
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改
|
|
|
+ * @ApiMethod (POST)
|
|
|
+ * @param string 'UniqId'
|
|
|
+ */
|
|
|
+ public function del()
|
|
|
+ {
|
|
|
+ if(!$this->request->isPost()){
|
|
|
+ $this->error('请求方式错误');
|
|
|
+ }
|
|
|
+ $req = $this->request->param();
|
|
|
+
|
|
|
+ if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
|
|
|
+ $this->error('参数错误','UniqId',100);
|
|
|
+ }
|
|
|
+
|
|
|
+ //开启事务
|
|
|
+ db()->startTrans();
|
|
|
+ try{
|
|
|
+ $bool = db()->table('db_sczladd')->where('UniqId',$req['UniqId'])->delete();
|
|
|
+
|
|
|
+ // 提交事务
|
|
|
+ db()->commit();
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ // 回滚事务
|
|
|
+ db()->rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ if($bool===false) $this->error('失败');
|
|
|
+
|
|
|
+ $this->success('成功');
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * excel导出
|
|
|
+ * @ApiMethod (GET)
|
|
|
+ * @param string file_name
|
|
|
+ * @param string date
|
|
|
+ * @param string sys_id
|
|
|
+ * @param array fields
|
|
|
+ */
|
|
|
+ public function export(){
|
|
|
+ if(!$this->request->isGet()){
|
|
|
+ $this->error('请求方式错误');
|
|
|
+ }
|
|
|
+ $req = $this->request->param();
|
|
|
+
|
|
|
+ $where = [];
|
|
|
+ if (!isset($req['date']) || empty($req['date'])) $this->error('参数缺失');
|
|
|
+
|
|
|
+ if (!(isset($req['fields']) && count($req['fields'])!=0)){
|
|
|
+ $this->error('参数错误','fields',100);
|
|
|
+ }
|
|
|
+ if(strpos($req['date'],'-')){
|
|
|
+ $where = ['a.sys_rq'=>['like','%'.$req['date'].'%']];
|
|
|
+ }else{
|
|
|
+ $where = ['a.sczl_gdbh'=>$req['date']];
|
|
|
+ }
|
|
|
+ if (isset($req['sys_id']) && !empty($req['sys_id'])){
|
|
|
+ $where['a.sys_id'] = ['LIKE','%'.$req['sys_id'].'%'];
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $field = '';
|
|
|
+ $arr = [
|
|
|
+ 'sczl_rq' =>['生产日期','LEFT(a.sczl_rq, 10) as sczl_rq'],
|
|
|
+ 'sczl_jtbh' =>['设备编号','a.sczl_jtbh'],
|
|
|
+ '设备名称' =>['设备名称','rtrim(b.设备名称) as 设备名称'],
|
|
|
+ 'sczl_bzdh' =>['班组','rtrim(a.sczl_bzdh) as sczl_bzdh'],
|
|
|
+ 'sczl_设备运行工时' =>['排班工时','a.sczl_设备运行工时'],
|
|
|
+ 'sczl_desc' =>['备注','rtrim(a.sczl_desc) as sczl_desc']
|
|
|
+ ];
|
|
|
+ $data[0] = [];
|
|
|
+ foreach ($req['fields'] as $k=>$v){
|
|
|
+ if(array_key_exists($v,$arr)){
|
|
|
+ if ($k==0){
|
|
|
+ $field .= $arr[$v][1];
|
|
|
+ }else{
|
|
|
+ $field .= ','.$arr[$v][1];
|
|
|
+ }
|
|
|
+ array_push($data[0],$arr[$v][0]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $rows = db()->table('db_sczladd')->alias('a')
|
|
|
+ ->join('设备_基本资料 b','a.sczl_jtbh = b.设备编号','left')
|
|
|
+ ->field($field)
|
|
|
+ ->where($where)
|
|
|
+ ->order('a.UniqId asc')
|
|
|
+ ->select();
|
|
|
+
|
|
|
+ foreach ($rows as $key=>$value) {
|
|
|
+ if (isset($value['sczl_设备运行工时'])) $value['sczl_设备运行工时'] = floatval($value['sczl_设备运行工时']);
|
|
|
+ $subArray = [];
|
|
|
+ foreach ($req['fields'] as $k=>$v){
|
|
|
+ if(array_key_exists($v,$arr)){
|
|
|
+ if($value[$v]){
|
|
|
+ array_push($subArray,$value[$v]);
|
|
|
+ }else{
|
|
|
+ array_push($subArray,'');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ array_push($data,$subArray);
|
|
|
+ }
|
|
|
+ $this->success('成功',['file_name'=>$req['file_name'],'data'=>$data]);
|
|
|
+ }
|
|
|
}
|