Manufacture.php 10 KB

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