ReportingWork.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use \think\Request;
  5. use \think\Db;
  6. /**
  7. * 车间报工接口
  8. */
  9. class ReportingWork extends Api
  10. {
  11. protected $noNeedLogin = ['*'];
  12. protected $noNeedRight = ['*'];
  13. /**
  14. * 首页
  15. *
  16. */
  17. public function index()
  18. {
  19. $this->success('请求成功');
  20. }
  21. /**
  22. * 设置机台状态
  23. * @ApiMethod POST
  24. * @params
  25. */
  26. public function setMachineStatus(){
  27. if (Request::instance()->isPost() == false){
  28. $this->error('非法请求');
  29. }
  30. $params = Request::instance()->post();
  31. if (!isset($params['machine']) || empty($params['machine'])){
  32. $this->error('参数不能为空');
  33. }
  34. $machine = $params['machine'].'#';
  35. $data = [];
  36. // $lastData = \db('设备_产量采集')->where('设备编号',$machine)->order('UniqId desc')->find();
  37. $lastData = \db('设备_产量采集')
  38. // ->where('设备编号',$machine)
  39. ->order('UniqId desc')
  40. ->find();
  41. if ($lastData['UniqId'] < 160000000){
  42. $id = 160000000;
  43. }else{
  44. $id = $lastData['UniqId'] + 1;
  45. }
  46. if (empty($params['order'])){
  47. unset($lastData['UniqId']);
  48. $data = $lastData;
  49. $data['当前状态'] = $params['status'];
  50. }else{
  51. $data['当前状态'] = $params['status'];
  52. $data['时间'] = date('Y-m-d H:i:s');
  53. $data['设备编号'] = $machine;
  54. $data['工单编号'] = $params['order'];
  55. $data['印件号'] = $params['yjno'];
  56. $data['工序号'] = (int)substr($params['gy_name'],0,2);
  57. $data['工序名称'] = $params['gy_name'];
  58. $data['当班产量'] = $params['production_now'];
  59. $data['累计产量'] = $params['production_all'];
  60. $class = explode(',',$params['class']);
  61. $where = [];
  62. $where['sczl_jtbh'] = $machine;
  63. for ($i=1;$i<=count($class);$i++){
  64. $where['sczl_bh'.$i] = $class[$i-1];
  65. }
  66. // $classData = \db('设备_班组资料')->where($where)->field('sczl_bzdh,UniqId')->find();
  67. $classData = \db('设备_班组资料')->where($where)->field('sczl_bzdh,UniqId')->find();
  68. $data['班组编号'] = $classData['sczl_bzdh'];
  69. $data['班组ID'] = $classData['UniqId'];
  70. // 获取当前时间
  71. $current_time = time();
  72. // 设置时间范围
  73. $start_time1 = strtotime(date('Y-m-d') . ' 08:30:00');
  74. $end_time1 = strtotime(date('Y-m-d') . ' 20:30:00');
  75. $end_time2 = strtotime(date('Y-m-d') . ' 24:00:00');
  76. $start_time3 = strtotime(date('Y-m-d', strtotime('+1 day')) . ' 08:30:00');
  77. // 判断当前时间属于哪个时间范围
  78. if ($current_time >= $start_time1 && $current_time <= $end_time1) {
  79. $data['开工时间'] = date('Y-m-d') . ' 08:30:00';
  80. } elseif ($current_time > $end_time1 && $current_time <= $end_time2) {
  81. $data['开工时间'] = date('Y-m-d') . ' 20:30:00';
  82. } elseif ($current_time > $end_time1 && $current_time <= $start_time3) {
  83. $data['开工时间'] = date('Y-m-d',strtotime('+1 day')) . ' 08:30:00';
  84. }
  85. $option['Gy0_gdbh'] = $params['order'];
  86. $option['Gy0_yjno'] = $params['yjno'];
  87. $option['Gy0_gxh'] = $data['工序号'];
  88. $data['任务ID'] = \db('工单_工艺资料')->where($option)->value('UniqId');
  89. }
  90. $data['UniqId'] = $id;
  91. // $sql = \db('设备_产量采集')->fetchSql(true)->insert($data);
  92. $sql = \db('设备_产量采集')->fetchSql(true)->insert($data);
  93. $res = Db::query($sql);
  94. if ($res === false){
  95. $this->error('设置失败');
  96. }else{
  97. $this->success('设置成功');
  98. }
  99. }
  100. /**
  101. * 设置工单工序完工
  102. * @ApiMethod POST
  103. * @params string order
  104. * @params string yjno
  105. * @params string gxh
  106. */
  107. public function setProcessStatus(){
  108. if (Request::instance()->isPost() == false){
  109. $this->error('非法请求');
  110. }
  111. $params = Request::instance()->post();
  112. if (!isset($params['order']) || empty($params['order'])){
  113. $this->error('参数不能为空');
  114. }
  115. if (!isset($params['yjno']) || empty($params['yjno'])){
  116. $this->error('参数不能为空');
  117. }
  118. if (!isset($params['gxh']) || empty($params['gxh'])){
  119. $this->error('参数不能为空');
  120. }
  121. $where['Gy0_gdbh'] = $params['order'];
  122. $where['Gy0_yjno'] = $params['yjno'];
  123. $where['Gy0_gxh'] = $params['gxh'];
  124. $date = date('Y-m-d H:i:s');
  125. $res = \db('工单_工艺资料')->where($where)->setField('PD_WG',$date);
  126. if ($res === false){
  127. $this->error('设置失败');
  128. }else{
  129. $this->success('设置成功');
  130. }
  131. }
  132. /**
  133. * 根据机台获取生产信息
  134. * @ApiMethod GET
  135. * @params string machine
  136. */
  137. public function getProduceInfo(){
  138. if (Request::instance()->isGet() == false) {
  139. $this->error('非法请求');
  140. }
  141. $params = Request::instance()->param();
  142. if (!isset($params['machine']) || empty($params['machine'])) {
  143. $this->error('参数错误');
  144. }
  145. $machine = $params['machine'].'#';
  146. $data = \db('设备_产量采集')->where('设备编号',$machine)->order('UniqId desc')->find();
  147. $list = [];
  148. $list['order'] = $data['工单编号'];
  149. $list['yjno'] = $data['印件号'];
  150. $name = \db('工单_基本资料')->where('Gd_Gdbh',$data['工单编号'])->value('成品名称');
  151. $list['product_name'] = rtrim($name);
  152. $where['Gy0_gdbh'] = $data['工单编号'];
  153. $where['Gy0_yjno'] = $data['印件号'];
  154. $where['Gy0_gxh'] = $data['工序号'];
  155. $gxmc = \db('工单_工艺资料')->where($where)->value('Gy0_gxmc');
  156. $list['gxmc'] = rtrim($gxmc);
  157. $this->success('请求成功',$list);
  158. }
  159. /**
  160. * 根据员工编号获取姓名
  161. * @ApiMethod GET
  162. * @params string code
  163. */
  164. public function getStaffName(){
  165. if (Request::instance()->isGet() == false) {
  166. $this->error('非法请求');
  167. }
  168. $params = Request::instance()->param();
  169. if (!isset($params['code']) || empty($params['code'])) {
  170. $this->error('参数错误');
  171. }
  172. if (substr($params['code'],0,2) == 'ZM'){
  173. $code = $params['code'];
  174. }else{
  175. if (strlen($params['code']) != 5){
  176. $length = strlen($params['code']);
  177. $len = 5 -$length;
  178. $str = '';
  179. for ($i=0;$i<$len;$i++){
  180. $str .= '0';
  181. }
  182. $code = 'ZM'.$str.$params['code'];
  183. }else{
  184. $code = 'ZM'.$params['code'];
  185. }
  186. }
  187. $data = \db('人事_基本资料')->where('员工编号',$code)->value('员工姓名');
  188. $this->success('请求成功',rtrim($data));
  189. }
  190. /**
  191. * 提交巡查记录
  192. * @ApiMethod POST
  193. * @params
  194. */
  195. public function submitPatrolRecord(){
  196. if (Request::instance()->isPost() == false){
  197. $this->error('非法请求');
  198. }
  199. $params = Request::instance()->post();
  200. if (empty($params['machine']) || empty($params['type']) || empty($params['order'])) {
  201. $this->error('参数错误');
  202. }
  203. if (empty($params['yjno']) || empty($params['process']) || empty($params['no'])) {
  204. $this->error('参数错误');
  205. }
  206. $data = [];
  207. $data['类别'] = $params['type'];
  208. $data['工单编号'] = $params['order'];
  209. $data['印件号'] = $params['yjno'];
  210. $data['工序名称'] = '';
  211. $data['班组编号'] = '';
  212. $data['开工时间'] = '';
  213. $data['流程单号'] = $params['process'];
  214. $data['设备编号'] = $params['machine'].'#';
  215. $data['检验项目'] = '['.$params['no'].'/'.$params['name'].']';
  216. $data['检验备注'] = $params['remark'];
  217. $data['提交时间'] = date('Y-m-d H:i:s');
  218. $data['sys_rq'] = date('Y-m-d H:i:s');
  219. $produce = \db('设备_产量采集')->where('设备编号',$params['machine'].'#')->where('工单编号',$params['order'])->order('UniqId desc')->find();
  220. // $produce = \db('设备_产量采集')->where('设备编号',$params['machine'].'#')->where('工单编号',$params['order'])->order('UniqId desc')->find();
  221. if (!empty($produce)){
  222. $data['工序名称'] = $produce['工序名称'];
  223. $data['班组编号'] = rtrim($produce['班组编号']);
  224. $data['开工时间'] = $produce['开工时间'];
  225. }
  226. // $res = \db('制程检验_记录')->field('UniqId')->order('UniqId desc')->find();
  227. $res = \db('制程检验_记录')->field('UniqId')->order('UniqId desc')->find();
  228. if ($res['UniqId'] < 100000000){
  229. $data['UniqId'] = 100000000;
  230. }else{
  231. $data['UniqId'] = $res['UniqId'] + 1;
  232. }
  233. // $sql = \db('制程检验_记录')->fetchSql(true)->insert($data);
  234. $sql = \db('制程检验_记录')->fetchSql(true)->insert($data);
  235. $result = Db::query($sql);
  236. if ($result === false){
  237. $this->error('提交失败');
  238. }else{
  239. $this->success('提交成功');
  240. }
  241. }
  242. /**
  243. * 获取报工单其他信息
  244. * @ApiMethod Get
  245. * @params string machine
  246. */
  247. public function getMachineReportInfo(){
  248. if (Request::instance()->isGet() == false) {
  249. $this->error('非法请求');
  250. }
  251. $params = Request::instance()->param();
  252. if (!isset($params['machine']) || empty($params['machine'])) {
  253. $this->error('参数错误');
  254. }
  255. $machine = $params['machine'].'#';
  256. $data = [];
  257. $produce = \db('设备_产量采集')->where('设备编号',$machine)->order('UniqId desc')->find();
  258. $data['order_info']['order'] = $produce['工单编号'];
  259. $data['order_info']['yjno'] = $produce['印件号'];
  260. $data['order_info']['gxh'] = $produce['工序号'];
  261. $data['order_info']['gxmc'] = $produce['工序名称'];
  262. $data['order_info']['dedh'] = \db('dic_lzde')->where('适用机型',$machine)->value('sys_bh');
  263. $product = \db('工单_基本资料')->alias('a')
  264. ->join('工单_工艺资料 b','a.Gd_Gdbh = b.Gy0_gdbh','left')
  265. ->join('工单_印件资料 c','a.Gd_Gdbh = c.Yj_gdbh','left')
  266. ->field('a.成品名称,b.Gy0_gxmc,c.yj_yjmc')
  267. ->where('a.Gd_Gdbh',$produce['工单编号'])
  268. ->where('b.Gy0_yjno',$produce['印件号'])
  269. ->where('b.Gy0_gxh',$produce['工序号'])
  270. ->where('c.Yj_yjno',$produce['印件号'])
  271. ->select();
  272. $data['order_info']['product_name'] = '';
  273. $data['order_info']['yj_name'] = '';
  274. $data['order_info']['gy_name'] = '';
  275. if (!empty($product)){
  276. $data['order_info']['product_name'] = rtrim($product[0]['成品名称']);
  277. $data['order_info']['yj_name'] = rtrim($product[0]['yj_yjmc']);
  278. $data['order_info']['gy_name'] = rtrim($product[0]['Gy0_gxmc']);
  279. }
  280. $class = \db('设备_班组资料')->where('UniqId',$produce['班组ID'])->find();
  281. for ($i=1;$i<11;$i++){
  282. $name = '';
  283. if (!empty($class['sczl_bh'.$i])){
  284. $name = \db('人事_基本资料')->where('员工编号',$class['sczl_bh'.$i])->value('员工姓名');
  285. }
  286. $class['sczl_name'.$i] = rtrim($name);
  287. }
  288. $data['class'] = $class;
  289. $where['st_gdbh'] = $produce['工单编号'];
  290. $machine = substr($machine,0,2);
  291. if ($machine == 'JY' || $machine == 'QZ'){
  292. $where['st_dpt'] = '胶印车间';
  293. }elseif ($machine == 'WY' || $machine == 'DW'){
  294. $where['st_dpt'] = '凹印车间';
  295. }elseif ($machine == 'SY' || $machine == 'PM'){
  296. $where['st_dpt'] = '丝印车间';
  297. }elseif ($machine == 'MQ' || $machine == 'TJ'){
  298. $where['st_dpt'] = '烫模车间';
  299. }elseif ($machine == 'JP'){
  300. $where['st_dpt'] = '检验车间';
  301. }
  302. $sql = "SELECT RTRIM(a.供方批次) as batch, rtrim(采购单号) as 采购单号,st_wlbh, MIN(a.Uniqid) AS Uniqid,rtrim(b.`BOM_物料名称`) as `BOM_物料名称`
  303. FROM `物料_收发记录` a
  304. LEFT JOIN `工单_bom资料` b ON a.st_gdbh = b.`BOM_工单编号` AND a.st_wlbh = b.`BOM_物料编码`
  305. WHERE a.st_gdbh = '{$where['st_gdbh']}' AND a.st_dpt = '{$where['st_dpt']}'
  306. GROUP BY batch ORDER BY a.st_wlbh";
  307. $material = Db::query($sql);
  308. $data['bom'] = $material;
  309. $this->success('请求成功',$data);
  310. }
  311. /**
  312. * 日产量上报
  313. * @ApiMethod POST
  314. * @params array data
  315. */
  316. public function submitDailyProduction(){
  317. if (Request::instance()->isPost() == false){
  318. $this->error('非法请求');
  319. }
  320. $params = Request::instance()->post();
  321. $machine = $params['sczl_jtbh'].'#';
  322. $batchData = []; //批次追踪数据
  323. $batch = $params['bom'];
  324. $data = $params;//产量数据
  325. $data['sczl_type'] = $params['sczl_gxmc'];
  326. $data['sczl_前工序废'] = $params['last_fp'];
  327. $data['sczl_来料少数'] = $params['less_sl'];
  328. $data['sczl_装版总工时'] = $params['zb_time'];
  329. $data['sczl_打样总工时'] = $params['dy_time'];
  330. $data['sczl_设备运行工时'] = $params['run_time'];
  331. $data['sczl_jtbh'] = $machine;
  332. $data['码包'] = $params['code'];
  333. $data['主电表'] = $params['main_meter'];
  334. $data['辅电表'] = $params['auxiliary_meter'];
  335. unset($data['last_fp']);
  336. unset($data['less_sl']);
  337. unset($data['zb_time']);
  338. unset($data['dy_time']);
  339. unset($data['run_time']);
  340. unset($data['code']);
  341. unset($data['main_meter']);
  342. unset($data['auxiliary_meter']);
  343. unset($data['bom']);
  344. $start_time = \db('设备_产量采集')->where('设备编号',$machine)->order('UniqId desc')->find();
  345. $data['开工时间'] = $start_time['开工时间'];
  346. $sys_id = \db('设备_基本资料')->where('设备编号',$machine)->value('sys_sbID');
  347. $data['sys_id'] = '['.$sys_id.'/'.$machine.']';
  348. $UniqId = \db('设备_产量计酬')->order('UniqId desc')->value('UniqId');
  349. if ($UniqId < 10000000){
  350. $data['UniqId'] = 10000000;
  351. }else{
  352. $data['UniqId'] = $UniqId + 1;
  353. }
  354. $data['sczl_Pgcl'] = 0;
  355. $data['sczl_oil'] = 0;
  356. $data['sczl_计产系数'] = 0;
  357. $data['sczl_工价系数'] = 0;
  358. $data['sczl_装版工时'] = 0;
  359. $data['sczl_保养工时'] = 0;
  360. $data['sczl_打样工时'] = 0;
  361. $data['sczl_异常停机工时'] = 0;
  362. $data['sczl_异常工时1'] = 0;
  363. $data['sczl_异常类型1'] = '';
  364. $data['sczl_废品率系数'] = '';
  365. $data['sczl_desc'] = '';
  366. $data['sczl_wgsj'] = '1900-01-01 00:00:00';
  367. $data['码开始行'] = 0;
  368. $data['码结束行'] = 0;
  369. $data['mod_rq'] = '1900-01-01 00:00:00';
  370. $data['sys_rq'] = date('Y-m-d H:i:s');
  371. if (!empty($batch)){
  372. $batchData = explode(',',$batch);
  373. $newData = [];
  374. $batchUniqId = \db('物料_批次跟踪')->order('UniqId desc')->value('UniqId');
  375. if ($batchUniqId < 10000000){
  376. $batchUniqId = 10000000;
  377. }
  378. foreach ($batchData as $key=>$item){
  379. $batchUniqId++;
  380. $val = explode('-',$item);
  381. $newData[$key]['wlbh'] = $val[0];
  382. $newData[$key]['wlBatch'] = $val[1];
  383. $newData[$key]['sczl_gdbh'] = $data['sczl_gdbh'];
  384. $newData[$key]['sczl_yjno'] = $data['sczl_yjno'];
  385. $newData[$key]['sczl_gxh'] = $data['sczl_gxh'];
  386. $newData[$key]['sczl_gxmc'] = $data['sczl_gxmc'];
  387. $newData[$key]['sczl_num'] = $data['sczl_num'];
  388. $newData[$key]['sys_id'] = $data['sys_id'];
  389. $newData[$key]['sys_rq'] = $data['sys_rq'];
  390. $newData[$key]['UniqID'] = $batchUniqId;
  391. }
  392. }
  393. $res = false;
  394. $batch_res = false;
  395. Db::startTrans();
  396. try {
  397. $sql = \db('设备_产量计酬')->fetchSql(true)->insert($data);
  398. $res = Db::query($sql);
  399. if (!empty($batch)){
  400. $batch_sql = \db('物料_批次跟踪')->fetchSql(true)->insertAll($newData);
  401. $batch_res = Db::query($batch_sql);
  402. }else{
  403. $batch_res = true;
  404. }
  405. Db::commit();
  406. cache('MachineProductReport-getList',null);
  407. }catch (\Exception $e){
  408. Db::rollback();
  409. }
  410. if ($res === false || $batch_res === false){
  411. $this->error('报工失败');
  412. }else{
  413. $this->success('报工成功');
  414. }
  415. }
  416. /**
  417. * 获取机台编号
  418. * @ApiMethod POST
  419. * @params string addr
  420. */
  421. public function getMachineMac(){
  422. if (Request::instance()->isGet() == false){
  423. $this->error('非法请求');
  424. }
  425. $params = Request::instance()->get();
  426. $data = \db('设备_基本资料')->where('sys_sbID',$params['addr'])->field('设备编号,rtrim(使用部门) as 使用部门')->find();
  427. $this->success('请求成功',$data);
  428. }
  429. /**
  430. * 6获取拉料人员
  431. * @ApiMethod GET
  432. * @params department
  433. */
  434. public function getMaterialStrippingPeople(){
  435. if (Request::instance()->isGet() == false) {
  436. $this->error('非法请求');
  437. }
  438. $params = Request::instance()->param();
  439. $where = [];
  440. if (!isset($params['department']) || empty($params['department'])) {
  441. $this->error('参数错误');
  442. }if (!isset($params['search']) || !empty($params['search'])) {
  443. $where['员工编号|员工姓名'] = array('like','%'.$params['search'].'%');
  444. }
  445. $where['职称职务'] = '拉纸工';
  446. $where['在职状态'] = '在职';
  447. $where['U8在职'] = '在职';
  448. if ($params['department'] == 1){
  449. $where['所在部门'] = '生产部';
  450. }else{
  451. $where['所在部门'] = '检验车间';
  452. }
  453. $list[0]['员工编号'] = '000000';
  454. $list[0]['员工姓名'] = '自备';
  455. $data = \db('人事_基本资料')->where($where)->field('rtrim(员工编号) as 员工编号,rtrim(员工姓名) as 员工姓名')->order('班组代号 desc')->select();
  456. if (!empty($data)){
  457. foreach ($data as $item){
  458. array_push($list,$item);
  459. }
  460. }
  461. $this->success('请求成功',$list);
  462. }
  463. }