ProcessDocument.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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 ProcessDocument 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. *
  24. * @ApiMethod GET
  25. * @params string order
  26. */
  27. public function getData(){
  28. if (Request::instance()->isGet() == false){
  29. $this->error('非法请求');
  30. }
  31. $params = Request::instance()->param();
  32. $order = $params['order'];
  33. if (!isset($order)){
  34. $this->error('参数不能为空');
  35. }
  36. $map = array();
  37. $map['a.Gd_gdbh'] = $order;
  38. //查询工单资料,修改BOM资料行号
  39. $orderList = \db('工单_基本资料')
  40. ->where('Gd_gdbh',$order)
  41. ->field('Gd_gdbh,行号,Gd_cpdh')
  42. ->select();
  43. foreach ($orderList as $value){
  44. $sql = \db('工单_bom资料')
  45. ->where('BOM_工单编号',$value['Gd_gdbh'])
  46. ->where('BOM_产品编号',$value['Gd_cpdh'])
  47. ->fetchSql(true)
  48. ->update(['BOM_工单行号'=>$value['行号']]);
  49. \db()->query($sql);
  50. }
  51. //胶印车间计量单位为”张“,凹印车间计量单位一般为”吨“
  52. $info = db('工单_基本资料')->alias('a')
  53. ->join('工单_bom资料 b ',' a.Gd_gdbh=b.BOM_工单编号 AND a.行号 = b.BOM_工单行号','left')
  54. ->field('DISTINCT(b.BOM_物料名称),a.成品代号,a.产品版本号,b.BOM_计划用量')
  55. ->where($map)
  56. ->where('b.BOM_产出单位',['eq','张'],['eq','吨'],'or')
  57. ->select();
  58. if(empty($info)){
  59. $data = db('工单_基本资料')->alias('a')
  60. ->join('工单_印件资料 b ',' a.Gd_gdbh=b.Yj_Gdbh AND a.行号 = b.yj_Yjno','left')
  61. ->field('b.yj_zzmc as yj_zzmc0,b.yj_zzmc1,b.yj_zzmc2,b.yj_zzmc3,b.yj_zzmc4,a.成品代号,a.产品版本号,b.yj_平张投料')
  62. ->where($map)
  63. ->select();
  64. $info = [];
  65. for ($i=0 ; $i < 5; $i++){
  66. if ($data[0]['yj_zzmc'.$i] !== ''){
  67. $list['BOM_物料名称'] = $data[0]['yj_zzmc'.$i];
  68. $list['成品代号'] = $data[0]['成品代号'];
  69. $list['产品版本号'] = $data[0]['产品版本号'];
  70. $list['BOM_计划用量'] = number_format((int)$data[0]['yj_平张投料']/10000,4);
  71. array_push($info,$list);
  72. }
  73. }
  74. }
  75. $res =array();
  76. $res['yjData'] = \db('工单_印件资料')->where('Yj_gdbh',$order)->field('yj_Yjno,yj_Yjdh,yj_yjmc')->order('yj_Yjno')->select();
  77. if (count($info) > 1){
  78. foreach ($info as $k=>$v){
  79. $str = rtrim($v['BOM_物料名称']);
  80. $res['paper'][$k] ['bom_物料名称'] = $str;
  81. $res['paper'][$k] ['产品版本号'] = rtrim($v['产品版本号']);
  82. $res['paper'][$k] ['bom_计划用量'] = $v['BOM_计划用量'];
  83. }
  84. }else{
  85. $res['paper'][0]['bom_物料名称'] = rtrim($info[0]['BOM_物料名称']);
  86. $res['paper'][0]['产品版本号'] = rtrim($info[0]['产品版本号']);
  87. $res['paper'][0]['bom_计划用量'] = $info[0]['BOM_计划用量'];
  88. }
  89. $res['num'] = count($info);
  90. $this->success('请求成功',$res);
  91. }
  92. /**
  93. * 获取历史工艺信息
  94. *
  95. * @ApiMethod GET
  96. * @params string order
  97. */
  98. public function getHistory(){
  99. if (Request::instance()->isGet() == false){
  100. $this->error('非法请求');
  101. }
  102. $params = Request::instance()->param();
  103. if (!isset($params['yjdh'])){
  104. $this->error('参数不能为空');
  105. }
  106. $where = array();
  107. //印件代号
  108. $where['product_number'] = $params['yjdh'];
  109. $db2 = \db()->connect(config('database.db2'));
  110. $res = $db2->name('qr_history')->where($where)->order('id desc')->field('data,update')->find();
  111. $result = array();
  112. $result['update'] = '暂无';
  113. $result['data'] = '';
  114. $result['num'] = 0;
  115. $result['department'] = '车间';
  116. if ($res){
  117. $data = explode(',',$res['data']);
  118. $result['num'] = 1;
  119. $result['data'] = $data;
  120. $result['update'] = $res['update'];
  121. }
  122. $this->success('请求成功',$result);
  123. }
  124. /**
  125. * 保存产品工艺信息
  126. *
  127. * @ApiMethod POST
  128. * @params
  129. */
  130. public function saveData(){
  131. if (Request::instance()->isPost() == false){
  132. $this->error('非法请求');
  133. }
  134. $params = Request::instance()->param();
  135. if (empty($params['order'])){
  136. $this->error('参数不能为空');
  137. }
  138. $db2 = \db()->connect(config('database.db2'));
  139. $ip = request()->ip();
  140. //定义各部门ip地址
  141. $JYarray=array('20.0.3.253','60.190.242.28','127.0.0.1');
  142. $WYarray=array('20.0.3.110','60.190.242.26');
  143. $MQarray=array('20.0.2.200','60.190.242.29');
  144. $department = -1;
  145. //确认是不是凹印车间,ip确认部门不准
  146. $explode_data = explode(',',$params['data']);
  147. if (in_array($ip,$MQarray)){
  148. $department = 3;
  149. }elseif (in_array($ip,$WYarray) || $explode_data[0] == '卷凹' || $explode_data[0] == '凹印'){
  150. $department = 2;
  151. }else{
  152. $department = 1;
  153. }
  154. $data = [];
  155. $data['department'] = $department;
  156. $data['data'] = substr($params['data'],0,-1);
  157. $data['product_number'] = rtrim($params['yjdh']);
  158. $map['product_number'] = $data['product_number'];
  159. $data['update'] = date('Y-m-d H:i:s');
  160. $data['ip'] =$ip;
  161. $isNull = $db2->name('qr_history')->where($map)->find();
  162. if ($isNull){//去更新工艺及时间
  163. $res = $db2->name('qr_history')->where('id',$isNull['id'])->update($data);
  164. }else{//新增
  165. $res = $db2->name('qr_history')->insert($data);
  166. }
  167. if ($res){
  168. $this->success('更新成功');
  169. }else{
  170. $this->error('更新失败');
  171. }
  172. }
  173. /**
  174. * 获取流程单头部信息
  175. *
  176. * @ApiMethod POST
  177. * @params string order
  178. */
  179. public function getInfo(){
  180. if (Request::instance()->isPost() == false){
  181. $this->error('非法请求');
  182. }
  183. $data = Request::instance()->param();
  184. if (!isset($data['order'])){
  185. $this->error('参数不能为空');
  186. }
  187. $str = '原纸';
  188. $where = [
  189. 'a.Gd_gdbh'=> $data['order'],
  190. 'b.yj_yjmc'=> $data['yjmc']
  191. ];
  192. $field = 'a.Gd_gdbh,rtrim(a.销售订单号) as 销售订单号,rtrim(a.Gd_cpmc) as Gd_cpmc,rtrim(a.成品名称) as 成品名称,a.计划投料,a.实际投料,rtrim(a.产品版本号) as 产品版本号,rtrim(a.警语版面) as 警语版面,
  193. rtrim(a.Gd_desc) as Gd_desc';
  194. $gdinfo = db('工单_基本资料')
  195. ->alias('a')
  196. ->join('工单_印件资料 b','a.Gd_gdbh = b.Yj_Gdbh AND a.Gd_cpdh = b.yj_Yjdh')
  197. ->where($where)
  198. ->field($field)
  199. ->select();
  200. $length = count($gdinfo);
  201. if (!empty($data['num'])){
  202. $gdinfo[0]['计划投料'] = $data['num'];
  203. }
  204. if (rtrim($gdinfo[0]['成品名称']) == ''){
  205. $cpmc = trim($gdinfo[0]['Gd_cpmc']);
  206. $gdinfo[0]['成品名称'] = $cpmc;
  207. }
  208. $gdinfo[0]['mabao'] = $data['mabao'];
  209. $gdinfo[0]['version'] = $data['version'];
  210. $gdinfo[0]['liucheng_num'] = '';
  211. $newdata = explode(',',$data['string']);
  212. $gdinfo['gy_data'] = array_filter($newdata);
  213. $gdinfo['technique_sequence'] = trim($gdinfo[0]['version']).'、'.trim($gdinfo[0]['警语版面']).'、'.trim($gdinfo[0]['Gd_desc']);
  214. $gdinfo['total_liuchen'] = ceil(($gdinfo[0]['计划投料']?$gdinfo[0]['计划投料']:$gdinfo[0]['实际投料']*10000)/$data['tldx']); //总的流程数
  215. $gdinfo['length'] = $length;
  216. $this->success('请求成功',$gdinfo);
  217. }
  218. }