ProcessDocument.php 6.9 KB

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