ProcessDocument.php 7.6 KB

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