Просмотр исходного кода

Merge branch 'master' of https://git.7in6.com/Minong/mes-server-api

曹鹤洋 1 год назад
Родитель
Сommit
865b83fcab

+ 13 - 13
application/api/controller/Facility.php

@@ -608,8 +608,8 @@ class Facility extends Api
         $lastId = \db('设备_班组资料')
             ->order('UniqId desc')
             ->value('UniqId');
-        if ($lastId<100000){
-            $lastId = 1000000;
+        if (empty($lastId)){
+            $lastId = 0;
         }
         $param['sys_rq'] = date('Y-m-d H:i:s',time());
         $param['UniqId'] = $lastId + 1;
@@ -854,10 +854,10 @@ class Facility extends Api
             $this->error('参数错误');
         }
         $lastNumber =  \db("设备_点检记录")->field('Uniqid as ID')->order('Uniqid desc')->find()['ID'];
-        if ((int)$lastNumber>10000000){
-            $lastId = $lastNumber;
+        if (empty($lastNumber)){
+            $lastId = 0;
         }else{
-            $lastId = 10000000;
+            $lastId = $lastNumber;
         }
         $row = [];
         foreach ($param as $key=>$value){
@@ -1376,8 +1376,8 @@ class Facility extends Api
             $this->error('参数错误');
         }
         $startID = \db('制程检验_记录')->order('UniqId desc')->value('UniqId');
-        if ($startID<100000000){
-            $startID = 100000000;
+        if (empty($startID)){
+            $startID = 0;
         }
         $process = \db('工单_工艺资料')
             ->where('Gy0_gdbh',$param[0]['workOrder'])
@@ -1450,8 +1450,8 @@ class Facility extends Api
             $this->error('参数错误');
         }
         $startID = \db('制程检验_记录附加')->order('UniqId desc')->value('UniqId');
-        if ($startID<100000000){
-            $startID = 100000000;
+        if (empty($startID)){
+            $startID = 0;
         }
         $process = \db('工单_工艺资料')
             ->where('Gy0_gdbh',$param[0]['workOrder'])
@@ -1557,10 +1557,10 @@ class Facility extends Api
         $lastData = \db('设备_产量采集')
             ->order('UniqId desc')
             ->find();
-        if ($lastData['UniqId'] < 160000000) {
-            $id = 160000000;
-        } else {
-            $id = $lastData['UniqId'] + 1;
+        if (empty($lastData)){
+            $id = 1;
+        }else{
+            $id = $lastData['UniqId']+1;
         }
         $data['当前状态'] = $params['status'];
         $data['时间'] = date('Y-m-d H:i:s');

+ 2 - 4
application/api/controller/Manufacture.php

@@ -193,11 +193,9 @@ class Manufacture extends Api
                     'rtrim(a.Uniqid)' => 'GDUID',
                 ])
                 ->join('工单_工艺资料 b', 'a.Gd_gdbh = b.Gy0_gdbh')
-                ->join('产品_基本资料 c', 'a.Gd_cpdh = c.产品编号')
                 ->where([
                     'a.gd_statu' => '2-生产中',
                     'a.行号' => '1',
-                    'c.状态' => '',
                     'b.PD_WG' => '1900-01-01 00:00:00',
                 ])
                 ->where($where)
@@ -322,10 +320,10 @@ class Manufacture extends Api
             $this->success('为获取到机台数据');
         }
         foreach ($department as $value){
-            $benchClass = \db('设备_基本资料')->where('使用部门',$value)->distinct(true)->order('设备编组')->cache(true)->column('设备编组');
+            $benchClass = \db('设备_基本资料')->where('使用部门',$value)->distinct(true)->order('设备编组')->column('设备编组');
             foreach ($benchClass as $v){
                 if (rtrim($v) !== ''){
-                    $machine = \db('设备_基本资料')->where('使用部门',$value)->where('设备编组',$v)->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->cache(true)->select();
+                    $machine = \db('设备_基本资料')->where('使用部门',$value)->where('设备编组',$v)->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->select();
                     foreach ($machine as $kk=>$vv){
                         $data[rtrim($value)][rtrim($v)][$kk] = $vv['设备编号'].'-->'.$vv['设备名称'];
                     }

+ 12 - 12
application/api/controller/Product.php

@@ -609,27 +609,27 @@ class Product extends Api
         $params = Request::instance()->get();
         $search = $params['search'];
         $num = config('product_code_digit');
-        $start_num = $num - 3;
         if (!empty($search)){
-            $sql = "SELECT DISTINCT rtrim(a.`物料代码`) as `物料代码`, rtrim(a.`物料名称`) as `物料名称`,rtrim(b.客户编号) as 客户编号,rtrim(b.客户名称) as 客户名称
-                FROM `物料_存货编码` a
-                JOIN `产品_基本资料` b ON SUBSTRING(a.`物料代码`, 5, 2) = SUBSTRING(b.`客户编号`, 3, 2)
-                WHERE SUBSTRING (a.`物料代码`,$start_num,$num) IN ('1401', '1402') AND a.`物料名称` LIKE '%{$search}%'
-                ORDER BY a.`物料代码` ASC;";
+            $sql = "SELECT DISTINCT rtrim(a.`物料代码`) AS `物料代码`,rtrim(a.`物料名称`) AS `物料名称`,rtrim(b.`客户编号`) AS `客户编号`,rtrim(b.`客户名称`) AS `客户名称` FROM
+                    `物料_存货编码` a
+                    JOIN `产品_基本资料` b ON LEFT(a.`物料代码`,$num) = LEFT(b.`客户编号`,$num)
+                    WHERE  a.`物料名称` LIKE '%{$search}%' or a.物料代码 LIKE '%{$search}%'
+                    ORDER BY a.`物料代码` ASC";
         }else{
             $sql = "SELECT DISTINCT rtrim(a.`物料代码`) as `物料代码`, rtrim(a.`物料名称`) as `物料名称`,rtrim(b.客户编号) as 客户编号,rtrim(b.客户名称) as 客户名称
                 FROM `物料_存货编码` a
-                JOIN `产品_基本资料` b ON SUBSTRING(a.`物料代码`, 5, 2) = SUBSTRING(b.`客户编号`, 3, 2)
-                WHERE SUBSTRING(a.`物料代码`,$start_num, $num) IN ('1401', '1402') 
-                ORDER BY a.`物料代码` ASC;";
+                JOIN `产品_基本资料` b ON LEFT(a.`物料代码`,$num) = LEFT(b.`客户编号`,$num)
+               
+                ORDER BY a.`物料代码` ASC";
         }
+//        halt($sql);
         $data = Db::query($sql);
         // 初始化一个关联数组,用于存储相同客户编号的数据
         $groupedData = [];
         foreach ($data as $row) {
             $customerCode = substr($row['物料代码'],0,$num).substr($row['客户编号'],2,2).'/'.$row['客户名称'];
             $materialCodePrefix = substr($row['物料代码'], 0, $num);
-            if ($materialCodePrefix == '1401' || $materialCodePrefix == 'Y1401' ){
+            if ($materialCodePrefix == 'Y1401' ){
                 $materialCodePrefix = $materialCodePrefix.'/糊盒类产品(含贴码)';
             }else{
                 $materialCodePrefix = $materialCodePrefix.'/直接领用产品';
@@ -669,7 +669,7 @@ class Product extends Api
                 LEFT JOIN `物料_存货结构` b ON LEFT(a.物料代码,$num-2) = b.编号
                 LEFT JOIN `物料_存货结构` c ON LEFT(a.物料代码,$num) = c.编号
                 LEFT JOIN `物料_存货结构` d ON LEFT(a.物料代码,$num+2) = d.编号
-                WHERE a.物料名称 LIKE '%{$search}%' AND (a.物料代码 LIKE '00%' or a.物料代码 LIKE '01%' or a.物料代码 LIKE '30%')";
+                WHERE a.物料名称 LIKE '%{$search}%' AND (a.物料代码 LIKE 'J00%' or a.物料代码 LIKE 'J01%' or a.物料代码 LIKE 'J30%')";
         }else{
             $sql = "SELECT rtrim(a.`物料代码`) as 物料代码,rtrim(a.`物料名称`) as 物料名称,rtrim(a.`规格`) as 规格,rtrim(b.编号) as oneCode,rtrim(b.名称) as oneName,
                 rtrim(c.`编号`) as twoCode,rtrim(c.`名称`) as twoName,rtrim(d.`编号`) as thrCode,rtrim(d.`名称`) as thrName
@@ -677,7 +677,7 @@ class Product extends Api
                 LEFT JOIN `物料_存货结构` b ON LEFT(a.物料代码,$num-2) = b.编号
                 LEFT JOIN `物料_存货结构` c ON LEFT(a.物料代码,$num) = c.编号
                 LEFT JOIN `物料_存货结构` d ON LEFT(a.物料代码,$num+2) = d.编号
-                WHERE  a.物料代码 LIKE '00%' or a.物料代码 LIKE '01%' or a.物料代码 LIKE '30%'";
+                WHERE  a.物料代码 LIKE 'J00%' or a.物料代码 LIKE 'J01%' or a.物料代码 LIKE 'J30%'";
         }
         $data = Db::query($sql);
         $mergedArray = [];

+ 15 - 7
application/api/controller/ReportingWork.php

@@ -259,6 +259,9 @@ class ReportingWork extends Api
         $machine = $params['machine'].'#';
         $data = [];
         $produce = \db('设备_产量采集')->where('设备编号',$machine)->order('UniqId desc')->find();
+        if (empty($produce)){
+            $this->error('无此设备数据');
+        }
         $data['order_info']['order'] = $produce['工单编号'];
         $data['order_info']['yjno'] = $produce['印件号'];
         $data['order_info']['gxh'] = $produce['工序号'];
@@ -273,6 +276,9 @@ class ReportingWork extends Api
             ->where('b.Gy0_gxh',$produce['工序号'])
             ->where('c.Yj_yjno',$produce['印件号'])
             ->select();
+        if (empty($product)){
+            $this->error('无此工单数据');
+        }
         $data['order_info']['product_name'] = '';
         $data['order_info']['yj_name'] = '';
         $data['order_info']['gy_name'] = '';
@@ -305,12 +311,14 @@ class ReportingWork extends Api
         }elseif ($machine == 'JP'){
             $where['st_dpt'] = '检验车间';
         }
-        $sql = "SELECT RTRIM(a.供方批次) as batch, rtrim(采购单号) as 采购单号,st_wlbh, MIN(a.Uniqid) AS Uniqid,rtrim(b.`BOM_物料名称`) as `BOM_物料名称`
-                FROM `物料_收发记录` a
-                LEFT JOIN `工单_bom资料` b ON a.st_gdbh = b.`BOM_工单编号` AND a.st_wlbh = b.`BOM_物料编码`
-                WHERE a.st_gdbh = '{$where['st_gdbh']}' AND a.st_dpt = '{$where['st_dpt']}'
-                GROUP BY batch ORDER BY a.st_wlbh";
-        $material = Db::query($sql);
+        $material = \db('物料_收发记录')
+            ->alias('a')
+            ->join('工单_bom资料 b', 'a.st_gdbh = b.BOM_工单编号 AND a.st_wlbh = b.BOM_物料编码','left')
+            ->where($where)
+            ->field('RTRIM(a.供方批次) as batch, rtrim(采购单号) as 采购单号, st_wlbh, MIN(a.Uniqid) AS Uniqid, rtrim(b.BOM_物料名称) as BOM_物料名称')
+            ->group('batch')
+            ->order('a.st_wlbh')
+            ->select();
         $data['bom'] = $material;
         $this->success('请求成功',$data);
     }
@@ -514,7 +522,7 @@ class ReportingWork extends Api
         if ($start < date('Y-m-d H:15:00', time())) {
             $start = date('Y-m-d H:00:00', time());
         } elseif ($start > date('Y-m-d H:45:00', time())) {
-            $start = date('Y-m-d H+1:00:00', time());
+            $start = date('Y-m-d H:00:00', time());
         } else {
             $start = date('Y-m-d H:30:00', time());
         }

+ 4 - 4
application/api/controller/Staff.php

@@ -82,13 +82,13 @@ class Staff extends Api
         if (Request::instance()->isGet() == false){
             $this->error('非法请求');
         }
-        $sql = "select rtrim(编号) as 编号,rtrim(名称) as 名称 from 人事_组织结构 where  状态 = ''    ";
+        $sql = "select rtrim(编号) as 编号,rtrim(名称) as 名称 from 人事_组织结构 where  状态 = '' order by 编号 asc  ";
         $list = Db::query($sql);
         $data = [];
         foreach ($list as $key => $value){
             $number = $value['编号'];
-            if (strlen($number) ==  1 ){//一级菜单
-                $sql = "select count(*) as total from 人事_基本资料 where SUBSTRING(部门编码,1,1)='{$number}' and 在职状态 = '在职' and U8在职 = '在职'";
+            if (strlen($number) ==  2 ){//一级菜单
+                $sql = "select count(*) as total from 人事_基本资料 where LEFT(部门编码,2)='{$number}' and 在职状态 = '在职' and U8在职 = '在职'";
                 $res = Db::query($sql);
                 $value['num'] = $res[0]['total'];
                 $list[$key] = $value;
@@ -114,7 +114,7 @@ class Staff extends Api
             $data[$k]['children'] = [];
             foreach ($list as $item){
                 $num = $item['编号'];
-                if (strlen($num) >= 3 && substr($num,0,1) == $k){
+                if (strlen($num) >= 4 && substr($num,0,2) == $k){
                     if ($item['num'] > 0){
                         $data[$k]['children'][$i] = $item;
                         $i++;

+ 27 - 13
application/api/controller/StaffSalary.php

@@ -7,6 +7,7 @@ use think\Db;
 use app\job\InsertDataJob;
 use think\Queue;
 use think\Cache;
+use think\cache\driver\Redis;
 /**
  * 员工计件工资核算
 */
@@ -52,6 +53,22 @@ class StaffSalary extends Api
         if (!$startDateInRange || !$endDateInRange) {
            $this->error('日期参数错误');
         }
+        $options = [
+            'host'       => '127.0.0.1',
+            'port'       => 6379,
+            'password'   => '',
+            'select'     => 15,
+            'timeout'    => 0,
+            'expire'     => 0,
+            'persistent' => false,
+            'prefix'     => '',
+        ];
+        $redis = new Redis($options);
+        $taskIdentifier = md5(json_encode('date'));
+        $queueKey =  $redis->get($taskIdentifier);
+        if ($queueKey){
+            $this->success('数据正在处理中,请等待...');
+        }
         $vacationOneArr = [];
         if (!empty($params['vacation_one_start']) && !empty($params['vacation_one_end'])){
             $vacationOneStart = strtotime($params['vacation_one_start']);
@@ -479,19 +496,16 @@ class StaffSalary extends Api
             $data[$key]['法定天数'] = $params['days'];
             $data[$key]['sczl_type'] = trim($item['sczl_type']);
         }
-//        $num = round(count($data)/10000);
-//        for ($i = 0; $i <= $num; $i++){
-//            $start = $i * 10000;
-//            $res = array_slice($data,$start,10000);
-//            $job = new InsertDataJob($res); // 创建任务实例
-//            Queue::push($job,'','default'.$i); // 推送任务到队列
-//        }
-
-        $job = new InsertDataJob($data); // 创建任务实例
-        Queue::push($job,'','default'); // 推送任务到队列
-        $this->success('数据正在处理中,请等待...');
-
-
+        $taskIdentifier = md5(json_encode('date'));
+        // 检查任务是否已经存在于队列中,如果不存在则推送任务到队列
+        if (!$redis->has($taskIdentifier)) {
+            $job = new InsertDataJob($data); // 创建任务实例
+            // 推送任务到队列
+            Queue::push($job,'','default'); // 推送任务到队列
+            // 设置任务的标识符到缓存中,并设置有效期,有效期为队列执行时间的两倍
+            $redis->set($taskIdentifier, true,60*5);
+            $this->success('数据正在处理中,请等待...');
+        }
     }
 
 }

+ 648 - 0
application/api/controller/Synchronization.php

@@ -296,4 +296,652 @@ class Synchronization extends Api
             $this->success('存货结构同步成功');
         }
     }
+
+    /**
+     * 人事基本资料同步
+     * @return void
+     * @throws \think\Exception
+     * @throws \think\db\exception\BindParamException
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     * @throws \think\exception\PDOException
+     */
+    public function PersonnelData()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $db3 = \db()->connect(config('database.db3'));
+        $PersonnelDataList = $db3->name('U8_02人事资料')
+            ->where('MES接收时间',null)
+            ->where('MES接收状态','0')
+            ->select();
+        if (empty($PersonnelDataList)){
+            $this->success('未找到新的人事资料');
+        }
+        $i = 0;
+        foreach ($PersonnelDataList as $key=>$value){
+            $data = [
+                '工卡编号'=>'',
+                '卡钟设定'=>'',
+                '打卡设置'=>'',
+                '员工编号'=>$value['员工编号'],
+                '员工姓名'=>$value['员工姓名'],
+                '性别'=>$value['性别'],
+                '聘用日期'=>$value['聘用日期'],
+                '转正日期'=>$value['转正日期'],
+                'U8离职日期'=>$value['离职日期'],
+                'MES离职日期'=>$value['离职日期'],
+                '扣减司龄'=>0,
+                '部门编码'=>$value['部门编码'],
+                '所在部门'=>$value['所在部门'],
+                '人员类别'=>$value['人员类别'],
+                '人员性质'=>$value['人员性质'],
+                '班次类型'=>'',
+                '标准工时制'=>'',
+                '职称职务'=>$value['职称职务'],
+                '薪资级别'=>$value['级别'],
+                '工资表类别'=>'',
+                '基本工资'=>'',
+                '绩效工资1'=>'',
+                '绩效工资2'=>'',
+                '技能工资'=>'',
+                '岗位津贴'=>'',
+                '竞业补贴'=>'',
+                '专业技术津贴'=>'',
+                '技工技师津贴'=>'',
+                '特殊工种津贴'=>'',
+                '各类奖项津贴'=>'',
+                '职危津贴'=>'',
+                '夜班津贴'=>'',
+                '全勤津贴'=>'',
+                '住房津贴'=>'',
+                '高温津贴'=>'',
+                '用餐津贴'=>'',
+                '司龄津贴'=>'',
+                '联系电话'=>$value['联系电话'],
+                '合同类型'=>'',
+                '合同起始日期'=>'1900-01-01 00:00:00',
+                '合同终止日期'=>'1900-01-01 00:00:00',
+                '合同备注'=>'',
+                '出生日期'=>$value['出生日期'],
+                'pycode'=>$value['pycode'],
+                '籍贯'=>'',
+                '民族'=>'',
+                '身份证号'=>$value['身份证号'],
+                '证件有效日期'=>'1900-01-01 00:00:00',
+                '发证机关'=>'',
+                '家庭住址'=>'',
+                '学历'=>'',
+                '婚姻状况'=>'',
+                '社保开始日期'=>'1900-01-01 00:00:00',
+                '开户银行'=>$value['开户银行'],
+                '开户账号'=>$value['开户账号'],
+                '存折办理日期'=>'1900-01-01 00:00:00',
+                '紧急电话'=>'',
+                '照片ID'=>'',
+                '在职状态'=>$value['在职状态'],
+                'U8在职'=>$value['在职状态'],
+                '薪酬核算分组'=>'',
+                '考勤类型'=>'',
+                '班组代号'=>'',
+                'sys_id'=>'[272/超级用户]',
+                'sys_rq'=>date('Y-m-d H:i:s',time()),
+                'mod_rq'=>'1900-01-01 00:00:00',
+                'U8UID'=>$value['U8_UID'],
+                'UniqID'=>$value['UniqId']
+            ];
+            $number = \db('人事_基本资料')
+                ->where('Uniqid',$value['UniqId'])
+                ->count();
+            if ($number === 0){
+                $sql = \db('人事_基本资料')->fetchSql(true)->insert($data);
+                $res = \db()->query($sql);
+                if ($res === false){
+                    $i++;
+                }else{
+                    $sqlString = $db3->name('U8_02人事资料')
+                        ->where('UniqId', $value['UniqId'])
+                        ->fetchSql(true)
+                        ->update([
+                            'MES接收时间' => date('Y-m-d H:i:s', time()),
+                            'MES接收状态' => '1'
+                        ]);
+                    $db3->execute($sqlString);
+                }
+            }else{
+                $sql = \db('人事_基本资料')
+                    ->fetchSql(true)
+                    ->where('UniqId',$value['UniqId'])
+                    ->update($data);
+                $res = \db()->query($sql);
+                if ($res === false){
+                    $i++;
+                }else{
+
+                    $sqlString = $db3->name('U8_02人事资料')
+                        ->where('UniqId', $value['UniqId'])
+                        ->fetchSql(true)
+                        ->update([
+                            'MES接收时间' => date('Y-m-d H:i:s', time()),
+                            'MES接收状态' => '1'
+                        ]);
+                    $db3->execute($sqlString);
+
+                }
+            }
+        }
+        if ($i !== 0){
+            $this->error('人事资料同步失败');
+        }else{
+            $this->success('人事资料同步成功');
+        }
+    }
+
+    /**
+     * 人事组织结构
+     * @return void
+     * @throws \think\Exception
+     * @throws \think\db\exception\BindParamException
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     * @throws \think\exception\PDOException
+     */
+    public function OrganizationalStructureData()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $db3 = \db()->connect(config('database.db3'));
+        $OrganizationalDataList = $db3->name('U8_01组织结构')
+            ->where('MES接收时间',null)
+            ->where('MES接收状态','0')
+            ->select();
+        if (empty($OrganizationalDataList)){
+            $this->success('未找到新的组织结构');
+        }
+        $i = 0;
+        foreach ($OrganizationalDataList as $key=>$value){
+            $data = [
+                '编号'=>$value['编号'],
+                '名称'=>$value['名称'],
+                '状态'=>$value['状态'],
+                'Sys_id'=>'[272/超级用户]',
+                'Sys_rq'=>date('Y-m-d H:i:s',time()),
+                'Mod_rq'=>'1900-01-01 00:00:00',
+                'U8UID'=>$value['U8_UID'],
+                'UNIQID'=>$value['UniqId'],
+            ];
+            $number = \db('人事_组织结构')
+                ->where('Uniqid',$value['UniqId'])
+                ->count();
+            if ($number === 0){
+                $sql = \db('人事_组织结构')->fetchSql(true)->insert($data);
+                $res = \db()->query($sql);
+                if ($res === false){
+                    $i++;
+                }else{
+                    $sqlString = $db3->name('U8_01组织结构')
+                        ->where('UniqId', $value['UniqId'])
+                        ->fetchSql(true)
+                        ->update([
+                            'MES接收时间' => date('Y-m-d H:i:s', time()),
+                            'MES接收状态' => '1'
+                        ]);
+                    $db3->execute($sqlString);
+                }
+            }else{
+                $sql = \db('人事_组织结构')
+                    ->fetchSql(true)
+                    ->where('UniqId',$value['UniqId'])
+                    ->update($data);
+                $res = \db()->query($sql);
+                if ($res === false){
+                    $i++;
+                }else{
+
+                    $sqlString = $db3->name('U8_01组织结构')
+                        ->where('UniqId', $value['UniqId'])
+                        ->fetchSql(true)
+                        ->update([
+                            'MES接收时间' => date('Y-m-d H:i:s', time()),
+                            'MES接收状态' => '1'
+                        ]);
+                    $db3->execute($sqlString);
+
+                }
+            }
+        }
+        if ($i !== 0){
+            $this->error('人事组织结构同步失败');
+        }else{
+            $this->success('人事组织结构同步成功');
+        }
+    }
+
+    /**
+     * 物料存货编码数据同步
+     * @return void
+     * @throws \think\Exception
+     * @throws \think\db\exception\BindParamException
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     * @throws \think\exception\PDOException
+     */
+    public function InventoryCodeData()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $db3 = \db()->connect(config('database.db3'));
+        $OrganizationalDataList = $db3->name('U8_04物料编码')
+            ->where('MES接收时间',null)
+            ->where('MES接收状态','0')
+            ->select();
+        if (empty($OrganizationalDataList)){
+            $this->success('未找到新的物料编码');
+        }
+        $i = 0;
+        foreach ($OrganizationalDataList as $key=>$value){
+            $data = [
+                '物料代码'=>$value['物料代码'],
+                '物料名称'=>$value['物料名称'],
+                '规格'=>$value['规格'],
+                '采购单位'=>$value['采购单位'],
+                '领用单位'=>$value['领用单位'],
+                '单位换算率'=>$value['单位换算率'],
+                '单价'=>$value['单价'],
+                '币种'=>$value['币种'],
+                '物料备注'=>$value['物料备注'],
+                '状态'=>$value['状态'],
+                'Sys_id'=>'[272/超级用户]',
+                'Sys_rq'=>date('Y-m-d H:i:s',time()),
+                'Mod_rq'=>'1900-01-01 00:00:00',
+                'U8UID'=>$value['U8_UID'],
+                'UniqId'=>$value['UniqId'],
+            ];
+            $number = \db('物料_存货编码')
+                ->where('Uniqid',$value['UniqId'])
+                ->count();
+            if ($number === 0){
+                $sql = \db('物料_存货编码')->fetchSql(true)->insert($data);
+                $res = \db()->query($sql);
+                if ($res === false){
+                    $i++;
+                }else{
+                    $sqlString = $db3->name('U8_04物料编码')
+                        ->where('UniqId', $value['UniqId'])
+                        ->fetchSql(true)
+                        ->update([
+                            'MES接收时间' => date('Y-m-d H:i:s', time()),
+                            'MES接收状态' => '1'
+                        ]);
+                    $db3->execute($sqlString);
+                }
+            }else{
+                $sql = \db('物料_存货编码')
+                    ->fetchSql(true)
+                    ->where('UniqId',$value['UniqId'])
+                    ->update($data);
+                $res = \db()->query($sql);
+                if ($res === false){
+                    $i++;
+                }else{
+                    $sqlString = $db3->name('U8_04物料编码')
+                        ->where('UniqId', $value['UniqId'])
+                        ->fetchSql(true)
+                        ->update([
+                            'MES接收时间' => date('Y-m-d H:i:s', time()),
+                            'MES接收状态' => '1'
+                        ]);
+                    $db3->execute($sqlString);
+                }
+            }
+        }
+        if ($i !== 0){
+            $this->error('物料编码同步失败');
+        }else{
+            $this->success('物料编码同步成功');
+        }
+    }
+
+    /**
+     * 客户供应商数据同步
+     * @return void
+     * @throws \think\Exception
+     * @throws \think\db\exception\BindParamException
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     * @throws \think\exception\PDOException
+     */
+    public function CustomerSupplierData()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $db3 = \db()->connect(config('database.db3'));
+        $OrganizationalDataList = $db3->name('U8_03客户供应商')
+            ->where('MES接收时间',null)
+            ->where('MES接收状态','0')
+            ->select();
+        if (empty($OrganizationalDataList)){
+            $this->success('未找到新的客户供应商');
+        }
+        $i = 0;
+        foreach ($OrganizationalDataList as $key=>$value){
+            $data = [
+                '类型'=>$value['类型'],
+                '编号'=>$value['编号'],
+                '名称'=>$value['名称'],
+                '简称'=>$value['简称'],
+                '地址'=>$value['地址'],
+                '对口部门'=>$value['对口部门'],
+                '联系人'=>$value['联系人'],
+                '电话'=>$value['电话'],
+                '业务员'=>$value['业务员'],
+                '币种'=>$value['币种'],
+                'Sys_id'=>'[272/超级用户]',
+                'Sys_rq'=>date('Y-m-d H:i:s',time()),
+                'Mod_rq'=>'1900-01-01 00:00:00',
+                'U8UID'=>$value['U8_UID'],
+                'UniqId'=>$value['UniqId'],
+            ];
+            $number = \db('erp_客户供应商')
+                ->where('Uniqid',$value['UniqId'])
+                ->count();
+            if ($number === 0){
+                $sql = \db('erp_客户供应商')->fetchSql(true)->insert($data);
+                $res = \db()->query($sql);
+                if ($res === false){
+                    $i++;
+                }else{
+                    $sqlString = $db3->name('U8_03客户供应商')
+                        ->where('UniqId', $value['UniqId'])
+                        ->fetchSql(true)
+                        ->update([
+                            'MES接收时间' => date('Y-m-d H:i:s', time()),
+                            'MES接收状态' => '1'
+                        ]);
+                    $db3->execute($sqlString);
+                }
+            }else{
+                $sql = \db('erp_客户供应商')
+                    ->fetchSql(true)
+                    ->where('UniqId',$value['UniqId'])
+                    ->update($data);
+                $res = \db()->query($sql);
+                if ($res === false){
+                    $i++;
+                }else{
+                    $sqlString = $db3->name('U8_03客户供应商')
+                        ->where('UniqId', $value['UniqId'])
+                        ->fetchSql(true)
+                        ->update([
+                            'MES接收时间' => date('Y-m-d H:i:s', time()),
+                            'MES接收状态' => '1'
+                        ]);
+                    $db3->execute($sqlString);
+                }
+            }
+        }
+        if ($i !== 0){
+            $this->error('客户供应商同步失败');
+        }else{
+            $this->success('客户供应商同步成功');
+        }
+    }
+
+    /**
+     * 物料领用记录数据同步
+     * @return void
+     * @throws \think\Exception
+     * @throws \think\db\exception\BindParamException
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     * @throws \think\exception\PDOException
+     */
+    public function ReceiptRecordData()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $db3 = \db()->connect(config('database.db3'));
+        $OrganizationalDataList = $db3->name('U8_07物料领用')
+            ->where('MES接收时间',null)
+            ->where('MES接收状态','0')
+            ->select();
+        if (empty($OrganizationalDataList)){
+            $this->success('未找到新的物料领用记录');
+        }
+        $i = 0;
+        foreach ($OrganizationalDataList as $key=>$value){
+            $data = [
+                'st_rq'=>$value['日期'],
+                'st_jylb'=>$value['交易类别'],
+                'st_gdbh'=>$value['工单编号'],
+                '采购单号'=>$value['采购单号'],
+                '供方批次'=>$value['供方批次'],
+                'st_wlbh'=>$value['物料编号'],
+                'st_sl'=>$value['领用数量'],
+                'st_dw'=>$value['领用单位'],
+                '领用单价'=>$value['领用单价'],
+                'st_desc'=>$value['备注'],
+                '仓库编号'=>$value['仓库编号'],
+                'st_dpt'=>$value['采购单号'],
+                'st_jtbh'=>$value['机台编号'],
+                'sys_id'=>'[272/超级用户]',
+                'sys_rq'=>date('Y-m-d H:i:s',time()),
+                'mod_rq'=>'1900-01-01 00:00:00',
+                'U8UID'=>$value['U8_UID'],
+                'Uniqid'=>$value['UniqId'],
+            ];
+            $number = \db('物料_收发记录')
+                ->where('Uniqid',$value['UniqId'])
+                ->count();
+            if ($number === 0){
+                $sql = \db('物料_收发记录')->fetchSql(true)->insert($data);
+                $res = \db()->query($sql);
+                if ($res === false){
+                    $i++;
+                }else{
+                    $sqlString = $db3->name('U8_07物料领用')
+                        ->where('UniqId', $value['UniqId'])
+                        ->fetchSql(true)
+                        ->update([
+                            'MES接收时间' => date('Y-m-d H:i:s', time()),
+                            'MES接收状态' => '1'
+                        ]);
+                    $db3->execute($sqlString);
+                }
+            }else{
+                $sql = \db('物料_收发记录')
+                    ->fetchSql(true)
+                    ->where('UniqId',$value['UniqId'])
+                    ->update($data);
+                $res = \db()->query($sql);
+                if ($res === false){
+                    $i++;
+                }else{
+                    $sqlString = $db3->name('U8_07物料领用')
+                        ->where('UniqId', $value['UniqId'])
+                        ->fetchSql(true)
+                        ->update([
+                            'MES接收时间' => date('Y-m-d H:i:s', time()),
+                            'MES接收状态' => '1'
+                        ]);
+                    $db3->execute($sqlString);
+                }
+            }
+        }
+        if ($i !== 0){
+            $this->error('物料领用记录同步失败');
+        }else{
+            $this->success('物料领用记录同步成功');
+        }
+    }
+
+    /**
+     * 仓库信息数据同步
+     * @return void
+     * @throws \think\Exception
+     * @throws \think\db\exception\BindParamException
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     * @throws \think\exception\PDOException
+     */
+    public function WarehouseInformationData()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $db3 = \db()->connect(config('database.db3'));
+        $OrganizationalDataList = $db3->name('U8_12仓库信息')
+            ->where('MES接收时间',null)
+            ->where('MES接收状态','0')
+            ->select();
+        if (empty($OrganizationalDataList)){
+            $this->success('未找到新的仓库信息');
+        }
+        $i = 0;
+        foreach ($OrganizationalDataList as $key=>$value){
+            $data = [
+                '编号'=>$value['编号'],
+                '名称'=>$value['名称'],
+                'Sys_id'=>'[272/超级用户]',
+                'Sys_rq'=>date('Y-m-d H:i:s',time()),
+                'Mod_rq'=>'1900-01-01 00:00:00',
+                'U8UID'=>$value['U8_UID'],
+                'UniqId'=>$value['UniqId'],
+            ];
+            $number = \db('物料_仓库信息')
+                ->where('Uniqid',$value['UniqId'])
+                ->count();
+            if ($number === 0){
+                $sql = \db('物料_仓库信息')->fetchSql(true)->insert($data);
+                $res = \db()->query($sql);
+                if ($res === false){
+                    $i++;
+                }else{
+                    $sqlString = $db3->name('U8_12仓库信息')
+                        ->where('UniqId', $value['UniqId'])
+                        ->fetchSql(true)
+                        ->update([
+                            'MES接收时间' => date('Y-m-d H:i:s', time()),
+                            'MES接收状态' => '1'
+                        ]);
+                    $db3->execute($sqlString);
+                }
+            }else{
+                $sql = \db('物料_仓库信息')
+                    ->fetchSql(true)
+                    ->where('UniqId',$value['UniqId'])
+                    ->update($data);
+                $res = \db()->query($sql);
+                if ($res === false){
+                    $i++;
+                }else{
+                    $sqlString = $db3->name('U8_12仓库信息')
+                        ->where('UniqId', $value['UniqId'])
+                        ->fetchSql(true)
+                        ->update([
+                            'MES接收时间' => date('Y-m-d H:i:s', time()),
+                            'MES接收状态' => '1'
+                        ]);
+                    $db3->execute($sqlString);
+                }
+            }
+        }
+        if ($i !== 0){
+            $this->error('仓库信息同步失败');
+        }else{
+            $this->success('仓库信息同步成功');
+        }
+    }
+
+    /**
+     * 职位编码数据同步
+     * @return void
+     * @throws \think\Exception
+     * @throws \think\db\exception\BindParamException
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     * @throws \think\exception\PDOException
+     */
+    public function PositionData()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $db3 = \db()->connect(config('database.db3'));
+        $OrganizationalDataList = $db3->name('U8_13职位编码')
+            ->where('MES接收时间',null)
+            ->where('MES接收状态','0')
+            ->select();
+        if (empty($OrganizationalDataList)){
+            $this->success('未找到新的职位编码');
+        }
+        $i = 0;
+        foreach ($OrganizationalDataList as $key=>$value){
+            $data = [
+                '职位编码'=>$value['职位编码'],
+                '职位名称'=>$value['职位名称'],
+                '定编人数'=>0,
+                '备注说明'=>'',
+                'sys_id'=>'[272/超级用户]',
+                'sys_rq'=>date('Y-m-d H:i:s',time()),
+                'Mod_rq'=>'1900-01-01 00:00:00',
+                'U8UID'=>$value['U8_UID'],
+                'UniqID'=>$value['UniqID'],
+            ];
+            $number = \db('人事_职位编码')
+                ->where('Uniqid',$value['UniqID'])
+                ->count();
+            if ($number === 0){
+                $sql = \db('人事_职位编码')->fetchSql(true)->insert($data);
+                $res = \db()->query($sql);
+                if ($res === false){
+                    $i++;
+                }else{
+                    $sqlString = $db3->name('U8_13职位编码')
+                        ->where('UniqID', $value['UniqID'])
+                        ->fetchSql(true)
+                        ->update([
+                            'MES接收时间' => date('Y-m-d H:i:s', time()),
+                            'MES接收状态' => '1'
+                        ]);
+                    $db3->execute($sqlString);
+                }
+            }else{
+                $sql = \db('人事_职位编码')
+                    ->fetchSql(true)
+                    ->where('UniqID',$value['UniqID'])
+                    ->update($data);
+                $res = \db()->query($sql);
+                if ($res === false){
+                    $i++;
+                }else{
+                    $sqlString = $db3->name('U8_13职位编码')
+                        ->where('UniqID', $value['UniqID'])
+                        ->fetchSql(true)
+                        ->update([
+                            'MES接收时间' => date('Y-m-d H:i:s', time()),
+                            'MES接收状态' => '1'
+                        ]);
+                    $db3->execute($sqlString);
+                }
+            }
+        }
+        if ($i !== 0){
+            $this->error('职位编码同步失败');
+        }else{
+            $this->success('职位编码同步成功');
+        }
+    }
 }

+ 36 - 28
application/api/controller/WorkOrder.php

@@ -35,25 +35,17 @@ class WorkOrder extends Api
         $progressAll = \db('工单_基本资料')->where('成品代号','<>','')->where('行号','1')->where('gd_statu','3-计划中')->cache(true)->count();
         $data = [
             'productingAll' => $productingAll,
-            'progressAll' => $progressAll
+            'progressAll' => $progressAll,
+            '印刷工单' => [],
+            '糊盒工单' => []
+
         ];
-//        $sql = "SELECT
-//                    SUBSTRING( `成品代号`, 1, 4 ) AS prefix,
-//                    rtrim( Gd_khmc ) AS khmc,
-//                    RTRIM( `Gd_客户名称` ) AS 客户名称
-//                FROM
-//                    `工单_基本资料`
-//                WHERE
-//                    `成品代号` <> ''
-//                    AND ( `Gd_客户名称` <> '' OR Gd_khmc <> '' )
-//                GROUP BY
-//                    prefix
-//                ORDER BY
-//                    prefix";
         $sql = "SELECT DISTINCT
                     (客户编号),rtrim(客户名称 ) as 客户名称
                 FROM
                     `产品_基本资料` 
+                WHERE 
+                    客户编号 <> ''
                 GROUP BY
                     客户编号
                 order by 
@@ -64,11 +56,7 @@ class WorkOrder extends Api
         }
         foreach ($list as $key=>$value){
             $value['客户编号'] = rtrim($value['客户编号']);
-            if ($value['客户编号'] == '1098'){
-                $value['客户名称'] = '打样专用';
-            }
             //这条sql查出来的数据可能不对,试一下以下sql
-            //SELECT COUNT(*) FROM `工单_基本资料` WHERE (SUBSTRING( `成品代号`, 1, 4 ) = '1001' OR (`Gd_客户名称`='浙江中烟' AND `Gd_客户代号` = '1001')) AND gd_statu = '2-生产中' AND `行号` = '1'
             $productIng = \db('工单_基本资料')->where('行号','1')->where('成品代号','LIKE',rtrim($value['客户编号']).'%')->where('gd_statu','2-生产中')->count();
             $proGress = \db('工单_基本资料')->where('行号','1')->where('成品代号','LIKE',rtrim($value['客户编号']).'%')->where('gd_statu','3-计划中')->count();
             $string = '';
@@ -79,11 +67,19 @@ class WorkOrder extends Api
                 $string = $string."计划中:".$proGress;
             }
             if ($string !== ''){
-//                $data[$key] = $value['prefix'].'【'.$string.'】'.($value['客户名称']!==''?$value['客户名称']:$value['khmc']);
-                $data[$key] = $value['客户编号'].'【'.$string.'】'.$value['客户名称'];
+                $name = $value['客户编号'].'【'.$string.'】'.$value['客户名称'];
+                if (strpos($value['客户编号'],'J') !== false){
+                    array_push($data['糊盒工单'],$name);
+                }else{
+                    array_push($data['印刷工单'],$name);
+                }
             }else{
-//                $data[$key] = $value['prefix'].($value['客户名称']!==''?$value['客户名称']:$value['khmc']);
-                $data[$key] = $value['客户编号'].$value['客户名称'];
+                $name = $value['客户编号'].$value['客户名称'];
+                if (strpos($value['客户编号'],'J') !== false){
+                    array_push($data['糊盒工单'],$name);
+                }else{
+                    array_push($data['印刷工单'],$name);
+                }
             }
         }
         $this->success('成功',$data);
@@ -189,7 +185,7 @@ class WorkOrder extends Api
         $data = [];
         //印件资料
         $printList = \db('工单_印件资料')
-            ->where('Yj_Gdbh',$Gd_gdbh) 
+            ->where('Yj_Gdbh',$Gd_gdbh)
             ->select();
         if (!empty($printList)){
             foreach ($printList as $key=>$value){
@@ -1975,7 +1971,7 @@ class WorkOrder extends Api
         if (empty($param['search'])){
             $this->error('参数错误');
         }
-        $list = \db('工单_基本资料')
+        $list = \Db('工单_基本资料')
             ->alias('a')
             ->field([
                 'rtrim(a.Gd_gdbh)' => '工单编号',
@@ -1984,9 +1980,19 @@ class WorkOrder extends Api
                 'rtrim(b.产品编号)' => '产品编号',
                 'rtrim(b.产品名称)' => '产品名称'
             ])
-            ->join('产品_基本资料 b','a.成品代号 = b.产品编号')
-            ->where('a.Gd_gdbh','like','%'.$param['search'].'%')
-            ->whereOr('a.成品名称','like','%'.$param['search'].'%')
+            ->join('产品_基本资料 b', 'a.成品代号 = b.产品编号')
+            ->join('产品_工艺资料 c', 'a.成品代号 = c.Gy0_cpdh')
+            ->join('产品_印件资料 d', 'a.成品代号 = d.yj_cpdh')
+            ->where(function($query) use ($param) {
+                $query->where('a.Gd_gdbh', 'like', '%'.$param['search'].'%')
+                    ->whereOr('a.成品名称', 'like', '%'.$param['search'].'%');
+            })
+            ->where(function($query) {
+                $query->where('c.Gy0_cpdh', '<>', '')
+                    ->where('d.yj_cpdh', '<>', '')
+                    ->where('b.状态', 'not like', '%停用%')
+                    ->where('b.产品名称', 'not like', '%停用%');
+            })
             ->group('a.Gd_gdbh')
             ->order('a.Uniqid desc')
             ->select();
@@ -2015,7 +2021,7 @@ class WorkOrder extends Api
         if (empty($param['workorder']) || empty($param['productCode']) || empty($param['option'])){
             $this->error('参数错误');
         }
-        //引用印件资料
+        //引用工艺资料
         $processWhere = [
             'Gy0_方案' => $param['option'],
             'Gy0_cpdh' => $param['productCode']
@@ -2034,6 +2040,8 @@ class WorkOrder extends Api
             $ProcessList[$key]['Gy0_ks'] = $value['Gy0_Ks'];
             $ProcessList[$key]['Gy0_ms'] = $value['Gy0_Ms'];
             $ProcessList[$key]['Gy0_oil'] = $value['Gy0_Oil'];
+            $ProcessList[$key]['Gy0_sj1'] = '1900-01-01 00:00:00';
+            $ProcessList[$key]['Gy0_sj2'] = '1900-01-01 00:00:00';
             $ProcessList[$key]['UniqId'] = $ProcesslastId + $key + 1;
             $ProcessList[$key]['PD_WG'] = '1900-01-01 00:00:00';
             $ProcessList[$key]['Sys_rq'] = date('Y-m-d H:i:s',time());

+ 1 - 1
application/job/InsertDataJob.php

@@ -55,7 +55,7 @@ class InsertDataJob
         $res = Db::query($sql);
         if ($res !== false){
             // 获取队列的键名
-            $queueKey = 'default0';
+            $queueKey = 'default';
             // 删除队列
             Cache::store('redis')->handler()->del($queueKey);
         }