ProcessDocument.php 7.7 KB

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