Manufacture.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. *
  7. * 生产排单管理
  8. */
  9. class Manufacture extends Api
  10. {
  11. protected $noNeedLogin = ['*'];
  12. protected $noNeedRight = ['*'];
  13. /**
  14. * 计划中工单
  15. * @ApiMethod (GET)
  16. * @return \think\response\Json
  17. * @throws \think\db\exception\DataNotFoundException
  18. * @throws \think\db\exception\ModelNotFoundException
  19. * @throws \think\exception\DbException
  20. */
  21. public function Project()
  22. {
  23. if ($this->request->isGet() === false){
  24. $this->error('请求错误');
  25. }
  26. $where = [
  27. 'gd_statu' => '3-计划中',
  28. '行号' => '1',
  29. ];
  30. $field = 'rtrim(Gd_生产分类) as 生产分类,rtrim(Gd_gdbh) as 工单编号,rtrim(Gd_cpdh) as 产品代号,rtrim(Gd_cpmc) as 产品名称,
  31. rtrim(接单日期) as 接单日期,rtrim(交货日期) as 交货日期,rtrim(订单数量) as 订单数量,rtrim(计量单位) as 计量单位,rtrim(Gd_khmc) as 客户名称,
  32. rtrim(Gd_客户代号) as 客户编号,rtrim(Gd_desc) as 备注,rtrim(客户料号) as 客户料号,rtrim(Sys_id) as 创建用户,rtrim(Sys_rq) as 创建时间,
  33. rtrim(Mod_rq) as 修改时间,rtrim(Uniqid) as UNIQID,rtrim(投料率) as 投料率,rtrim(销售订单号) as 销售订单号';
  34. $list = Db::table('工单_基本资料')->where($where)->field($field)->select();
  35. if (empty($list)){
  36. $this->error('失败');
  37. }
  38. foreach ($list as $key=>$value){
  39. // $cateGory = Db::table('产品_基本资料')->where('产品编号',$value['产品代号'])->find();
  40. // $list[$key]['产品类别'] = $cateGory['产品类别'];
  41. $list[$key]['订单数量'] = rtrim((float)$value['订单数量']);
  42. }
  43. $this->success('成功',$list);
  44. }
  45. /**
  46. * 计划中工单->工艺资料
  47. * @ApiMethod (GET)
  48. * @param string $Gd_gdbh 工单编号
  49. * @return \think\response\Json
  50. * @throws \think\db\exception\DataNotFoundException
  51. * @throws \think\db\exception\ModelNotFoundException
  52. * @throws \think\exception\DbException
  53. */
  54. public function projectCraft()
  55. {
  56. if ($this->request->isGet() === false){
  57. $this->error('请求错误');
  58. }
  59. $Gd_gdbh = input('Gd_gdbh');
  60. if (empty($Gd_gdbh)){
  61. $this->error('参数错误');
  62. }
  63. $where = [
  64. 'Gy0_gdbh' => $Gd_gdbh
  65. ];
  66. $filed = 'rtrim(Gy0_gdbh) as 工单编号,rtrim(重点工序) as 重点工序,Gy0_yjno,Gy0_gxh,Gy0_gxmc,Add_gxmc,rtrim(工序备注) as 工序备注,
  67. rtrim(Gy0_sbbh) as 机组,rtrim(Gy0_小时产能) as 小时产能,rtrim(Gy0_生产工时) as 生产工时,rtrim(Gy0_辅助工时) as 辅助工时,
  68. rtrim(印刷方式) as 印刷方式,rtrim(版距) as 版距,rtrim(Sys_id) as 创建用户,rtrim(Sys_rq) as 创建时间,rtrim(Mod_rq) as 修改时间,rtrim(UniqId) as UNIQID';
  69. $list = Db::table('工单_工艺资料')->where($where)->field($filed)->select();
  70. if (empty($list)){
  71. $this->error('失败');
  72. }
  73. foreach ($list as $key=>$value){
  74. if ((int)$value['Gy0_yjno'] <10){
  75. $value['Gy0_yjno'] = '0'.rtrim($value['Gy0_yjno']);
  76. }
  77. if ((int)$value['Gy0_gxh'] <10){
  78. $value['Gy0_gxh'] = '0'.rtrim($value['Gy0_gxh']);
  79. }
  80. if (rtrim($value['Add_gxmc']) == ''){
  81. $list[$key]['印件工序及名称'] = $value['Gy0_yjno'].'-'.$value['Gy0_gxh'].'-->'.rtrim($value['Gy0_gxmc']);
  82. }else{
  83. $list[$key]['印件工序及名称'] = $value['Gy0_yjno'].'-'.$value['Gy0_gxh'].'-->'.rtrim($value['Gy0_gxmc']).'【'.rtrim($value['Add_gxmc']).'】';
  84. }
  85. unset($list[$key]['Gy0_yjno'],$list[$key]['Gy0_gxh'],$list[$key]['Gy0_gxmc'],$list[$key]['Add_gxmc']);
  86. }
  87. $this->success('成功',$list);
  88. }
  89. /**
  90. * 计划中工单->印件资料
  91. * @ApiMethod (GET)
  92. * @param string $Gd_gdbh 工单编号
  93. * @return \think\response\Json
  94. * @throws \think\db\exception\DataNotFoundException
  95. * @throws \think\db\exception\ModelNotFoundException
  96. * @throws \think\exception\DbException
  97. */
  98. public function projectPrint()
  99. {
  100. if ($this->request->isGet() === false){
  101. $this->error('请求错误');
  102. }
  103. $Gd_gdbh = input('Gd_gdbh');
  104. if (empty($Gd_gdbh)){
  105. $this->error('参数错误');
  106. }
  107. $where = [
  108. 'Yj_Gdbh' => $Gd_gdbh,
  109. ];
  110. $field = 'rtrim(Yj_Gdbh) as 工单编号,rtrim(yj_Yjno) as 印件号,rtrim(yj_Yjdh) as 印件代号,rtrim(yj_yjmc) as 印件名称,
  111. rtrim(yj_zzmc) as 纸张名称,rtrim(yj_tlgg) as 投料规格,rtrim(yj_成品数量) as 成品数量,rtrim(yj_实际投料) as 实际投料,
  112. rtrim(yj_Dw) as 投料单位,rtrim(yj_平张投料) as 平张投料,rtrim(yj_ls) as 联数,rtrim(yj_ks) as 开数,rtrim(Sys_id) as 创建用户,
  113. rtrim(Sys_rq) as 创建时间,rtrim(Mod_rq) as 修改时间,rtrim(Uniqid) as UNIQID';
  114. $list = Db::table('工单_印件资料')->where($where)->field($field)->select();
  115. if ($list){
  116. $this->error('失败');
  117. }
  118. foreach ($list as $key=>$value){
  119. $list[$key]['成品数量'] = rtrim((float)$value['成品数量']);
  120. $list[$key]['实际投料'] = rtrim((float)$value['实际投料']);
  121. }
  122. $this->success('成功',$list);
  123. }
  124. /**
  125. * 排程中/制程中工单
  126. */
  127. public function Schedule(){
  128. if ($this->request->isGet() === false){
  129. $this->error('请求错误');
  130. }
  131. $where = [
  132. 'gd_statu' => '2-生产中',
  133. '行号' => 1
  134. ];
  135. $field = 'rtrim(Gd_gdbh) as 工单编号,rtrim(Gd_cpdh) as 产品代号,rtrim(Gd_cpmc) as 产品名称,rtrim(接单日期) as 接单日期,
  136. rtrim(交货日期) as 交货日期,rtrim(订单数量) as 订单数量,rtrim(计量单位) as 计量单位,rtrim(销售订单号) as 销售订单号,rtrim(Gd_客户代号) as 客户编号,
  137. rtrim(Gd_客户名称) as 客户名称,rtrim(客户料号) as 客户料号,rtrim(Uniqid) as GDUID';
  138. $list = Db::table('工单_基本资料')->where($where)->field($field)->select();
  139. $this->success('成功',$list);
  140. }
  141. /**
  142. * 排程中/制程中工单->工序列表
  143. * @ApiMethod (GET)
  144. * @param string $Gd_gdbh 工单编号
  145. * @return \think\response\Json
  146. * @throws \think\db\exception\DataNotFoundException
  147. * @throws \think\db\exception\ModelNotFoundException
  148. * @throws \think\exception\DbException
  149. */
  150. public function ScheduleProcess()
  151. {
  152. if ($this->request->isGet() === false){
  153. $this->error('请求错误');
  154. }
  155. $Gd_gdbh = input('Gd_gdbh');
  156. if (empty($Gd_gdbh)){
  157. $this->error('参数错误');
  158. }
  159. $where = [
  160. 'Gy0_gdbh' => $Gd_gdbh,
  161. 'Gy0_sbbh' =>['neq',''],
  162. ];
  163. $field = 'rtrim(Gy0_gdbh) as 工单编号,Gy0_yjno,Gy0_gxh,Gy0_gxmc,Add_gxmc,rtrim(Gy0_sbbh) as 设备编号,rtrim(Gy0_小时产能) as 小时产能,
  164. rtrim(工价系数) as 产能系数,rtrim(Gy0_生产工时) as 生产工时,rtrim(Gy0_辅助工时) as 辅助工时,rtrim(Gy0_最早开工时间) as 最早开工时间,
  165. rtrim(Gy0_sj1) as 计划开工时间,rtrim(Gy0_sj2) as 计划完工时间,rtrim(Gy0_班次安排) as 班次安排,rtrim(工序备注) as 排单备注,
  166. rtrim(PD_WG) as 工序完工,rtrim(UniqId) as UNIQID';
  167. $list = Db::table('工单_工艺资料')->where($where)->field($field)->select();
  168. if (empty($list)){
  169. $this->error('未找到工序');
  170. }
  171. foreach ($list as $key=>$value){
  172. if ((int)$value['Gy0_yjno'] <10){
  173. $value['Gy0_yjno'] = '0'.rtrim($value['Gy0_yjno']);
  174. }
  175. if ((int)$value['Gy0_gxh'] <10){
  176. $value['Gy0_gxh'] = '0'.rtrim($value['Gy0_gxh']);
  177. }
  178. if (rtrim($value['Add_gxmc']) == ''){
  179. $list[$key]['印件工序及名称'] = $value['Gy0_yjno'].'-'.$value['Gy0_gxh'].'-->'.rtrim($value['Gy0_gxmc']);
  180. }else{
  181. $list[$key]['印件工序及名称'] = $value['Gy0_yjno'].'-'.$value['Gy0_gxh'].'-->'.rtrim($value['Gy0_gxmc']).'【'.rtrim($value['Add_gxmc']).'】';
  182. }
  183. unset($list[$key]['Gy0_yjno'],$list[$key]['Gy0_gxh'],$list[$key]['Gy0_gxmc'],$list[$key]['Add_gxmc']);
  184. $list[$key]['机组'] = $value['设备编号'];
  185. $orderDetail = Db::table('工单_基本资料')->where('Gd_gdbh',$list[$key]['工单编号'])->field('rtrim(计划投料) as 计划投料')->find();
  186. $list[$key]['工序产量'] = $orderDetail['计划投料'];
  187. $end = Db::table('设备_产量计酬')->where('sczl_gdbh',$value['工单编号'])->where('sczl_jtbh',$value['设备编号'])
  188. ->field('SUM(sczl_cl) as 已完成产量')->select();
  189. $list[$key]['已完成产量'] = (int)$end[0]['已完成产量'];
  190. $list[$key]['剩余产量'] = (int)$list[$key]['工序产量']-(int)$list[$key]['已完成产量'];
  191. }
  192. $this->success('成功',$list);
  193. }
  194. /**
  195. * 排单页面左侧车间和机台菜单
  196. * @ApiMethod (GET)
  197. * @return \think\response\Json
  198. * @throws \think\db\exception\DataNotFoundException
  199. * @throws \think\db\exception\ModelNotFoundException
  200. * @throws \think\exception\DbException
  201. */
  202. public function workbench()
  203. {
  204. if ($this->request->isGet() === false){
  205. $this->error('请求错误');
  206. }
  207. $data = [];
  208. $department = Db::table('设备_基本资料')->distinct(true)->column('使用部门');
  209. if (empty($department)){
  210. $this->error('为获取到机台数据');
  211. }
  212. foreach ($department as $value){
  213. if (rtrim($value) !== '研发中心'){
  214. $benchClass = Db::table('设备_基本资料')->where('使用部门',$value)->distinct(true)->column('设备编组');
  215. foreach ($benchClass as $v){
  216. if (rtrim($v) !== ''){
  217. $machine = Db::table('设备_基本资料')->where('使用部门',$value)->where('设备编组',$v)->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->select();
  218. foreach ($machine as $kk=>$vv){
  219. $data[rtrim($value)][rtrim($v)][$kk] = $vv['设备编号'].'-->'.$vv['设备名称'];
  220. }
  221. }
  222. }
  223. }
  224. }
  225. $this->success('成功',$data);
  226. }
  227. }