WorkOrder.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 工单资料管理
  7. */
  8. class WorkOrder extends Api
  9. {
  10. protected $noNeedLogin = ['*'];
  11. protected $noNeedRight = ['*'];
  12. /**
  13. * 工单资料菜单列表
  14. *
  15. * @ApiMethod (GET)
  16. * @return false|string
  17. * @throws \think\Exception
  18. */
  19. public function DataList()
  20. {
  21. if ($this->request->isGet() === false){
  22. $this->error('请求错误');
  23. }
  24. //客户列表
  25. $ClientList = Db::table('erp_客户供应商')->where('类型','客户')->column('简称','编号');
  26. //获取总计划中数量和总生产中数量
  27. $productingAll = Db::table('工单_基本资料')->where('gd_statu','2-生产中')->count();
  28. $progressAll = Db::table('工单_基本资料')->where('gd_statu','3-计划中')->count();
  29. $data = [
  30. 'productingAll' => $productingAll,
  31. 'progressAll' => $progressAll
  32. ];
  33. //按客户编号查询生产中,计划中数量
  34. foreach ($ClientList as $key=>$value){
  35. $order = Db::table('工单_基本资料')->where('Gd_客户代号',$key)->count();
  36. if ($order !== 0){
  37. $productIng = Db::table('工单_基本资料')->where('Gd_客户代号',$key)->where('gd_statu','2-生产中')->count();
  38. $proGress = Db::table('工单_基本资料')->where('Gd_客户代号',$key)->where('gd_statu','3-计划中')->count();
  39. $Detail = [
  40. 'Gd_khdh' => rtrim($key),
  41. 'Gd_khmc' => rtrim($value),
  42. 'producting' => rtrim($productIng),
  43. 'progress' => rtrim($proGress),
  44. ];
  45. array_push($data,$Detail);
  46. }
  47. }
  48. $this->success('成功',$data);
  49. }
  50. /**
  51. * 工单基本资料列表
  52. * @ApiMethod (GET)
  53. * @param string $limit 查询长度
  54. * @param string $Gd_khdh 客户代号
  55. * @param string $startTime 接单日期开始时间
  56. * @param string $endTime 接单日期结束时间
  57. * @return \think\response\Json
  58. * @throws \think\exception\DbException
  59. */
  60. public function WorkList()
  61. {
  62. if ($this->request->isGet() === false){
  63. $this->error('请求错误');
  64. }
  65. $limit = input('limit');
  66. $clientNumber = input('Gd_khdh');
  67. $startTime = input('start');
  68. $endTime = input('end');
  69. $where = [
  70. 'Gd_khdh' => $clientNumber
  71. ];
  72. if (isset($startTime) && isset($endTime)){
  73. $where['接单日期'] = ['between',[$startTime,$endTime]];
  74. }
  75. $list = Db::table('工单_基本资料')
  76. ->where($where)
  77. ->order('接单日期 desc')
  78. ->paginate($limit);
  79. //工单基本资料数据整理
  80. $data = [];
  81. foreach ($list->items() as $key=>$value){
  82. $data[$key] = [
  83. '工单编号' => rtrim($value['Gd_gdbh']),
  84. '生产分类' => rtrim($value['Gd_生产分类']),
  85. '销售订单号' => rtrim($value['销售订单号']),
  86. '产品代号' => rtrim($value['Gd_cpdh']),
  87. '产品名称' => rtrim($value['Gd_cpmc']),
  88. '订单数量' => rtrim($value['订单数量']),
  89. '单位' => rtrim($value['计量单位']),
  90. '折合大箱' => rtrim((int)$value['投料大箱']),
  91. '投料率' => rtrim($value['投料率']),
  92. '平均合格率' => '',
  93. '开单日期' => date('Y-m-d',strtotime(rtrim($value['接单日期']))),
  94. '交货日期' => date('Y-m-d',strtotime(rtrim($value['交货日期']))),
  95. '工单类型' => rtrim($value['Gd_lx']),
  96. '工单状态' => rtrim($value['gd_statu']),
  97. '当前生产工序' => '',
  98. '产量提交时间' => '',
  99. '建档用户' => rtrim($value['Sys_id']),
  100. '建档时间' => rtrim($value['Sys_rq']),
  101. '更新时间' => rtrim($value['Mod_rq']),
  102. ];
  103. }
  104. $this->success('成功',$data);
  105. }
  106. /**
  107. * 印件资料
  108. * @ApiMethod (GET)
  109. * @param string $Gd_gdbh 工单编号
  110. * @return \think\response\Json
  111. * @throws \think\db\exception\DataNotFoundException
  112. * @throws \think\db\exception\ModelNotFoundException
  113. * @throws \think\exception\DbException
  114. */
  115. public function Printed()
  116. {
  117. if ($this->request->isGet() === false){
  118. $this->error('请求错误');
  119. }
  120. $Gd_gdbh = input('Gd_gdbh');
  121. if (empty($Gd_gdbh)){
  122. $this->error('参数错误');
  123. }
  124. $list = Db::table('工单_印件资料')->where('Yj_Gdbh',$Gd_gdbh)->select();
  125. $data = [];
  126. if ($list){
  127. foreach ($list as $key=>$value){
  128. $data[$key] = [
  129. '印件号' => rtrim($value['yj_Yjno']),
  130. '印件代号' => rtrim($value['yj_Yjdh']),
  131. '印件名称' => rtrim($value['yj_yjmc']),
  132. '纸张代号' => rtrim($value['yj_zzdh']),
  133. '纸张名称' => rtrim($value['yj_zzmc']),
  134. '投料规格' => rtrim($value['yj_tlgg']),
  135. '平张投料' => rtrim($value['yj_平张投料']),
  136. '开料规格' => rtrim($value['yj_klgg']),
  137. '开数*联数' => rtrim($value['yj_ks']).'*'.rtrim($value['yj_ls']),
  138. '建档用户' => rtrim($value['Sys_id']),
  139. '建档时间' => rtrim($value['Sys_rq']),
  140. '更新时间' => rtrim($value['Mod_rq']),
  141. ];
  142. }
  143. }
  144. $this->success('成功',$data);
  145. }
  146. /**
  147. * 工艺资料
  148. * @ApiMethod (GET)
  149. * @param string $Gd_gdbh 工单编号
  150. * @return \think\response\Json
  151. * @throws \think\db\exception\DataNotFoundException
  152. * @throws \think\db\exception\ModelNotFoundException
  153. * @throws \think\exception\DbException
  154. */
  155. public function Craft()
  156. {
  157. if ($this->request->isGet() === false){
  158. $this->error('请求错误');
  159. }
  160. $Gd_gdbh = input('Gd_gdbh');
  161. if (empty($Gd_gdbh)){
  162. $this->error('参数错误');
  163. }
  164. $list = Db::table('工单_工艺资料')
  165. ->where('Gy0_gdbh',$Gd_gdbh)
  166. ->select();
  167. $Gd_cpdh = Db::table('工单_基本资料')->where('Gd_gdbh',$Gd_gdbh)->field('Gd_cpdh')->find();
  168. $data = [];
  169. if ($list){
  170. foreach ($list as $key=>$value){
  171. if ($value['Gy0_yjno']<10){
  172. $value['Gy0_yjno'] = '0'.$value['Gy0_yjno'];
  173. }
  174. if ($value['Gy0_gxh']<10){
  175. $value['Gy0_gxh'] = '0'.$value['Gy0_gxh'];
  176. }
  177. $where = [
  178. 'Gy0_cpdh' => $Gd_cpdh['Gd_cpdh'],
  179. 'Gy0_yjno' => $value['Gy0_yjno'],
  180. 'Gy0_gxh' => $value['Gy0_gxh'],
  181. ];
  182. $product = Db::table('产品_工艺资料')->where($where)->field('工价系数,损耗系数')->find();
  183. $data[$key] = [
  184. '重点工序' => rtrim($value['重点工序']),
  185. '印件-工序' => rtrim($value['Gy0_yjno']).'-'.rtrim($value['Gy0_gxh']),
  186. '备选工序' => '',
  187. '工序名称' => rtrim($value['Gy0_gxmc']).'【'.rtrim($value['Add_gxmc']).'】',
  188. '计划产量' => '',
  189. '基础损耗' => rtrim($value['Gy0_Rate0']),
  190. '损耗率' => rtrim($value['Gy0_Rate1']),
  191. '报废定额' => '',
  192. '允损比例' => '',
  193. '难度系数' => rtrim($product['工价系数']),
  194. '损耗系数' => rtrim($product['损耗系数']),
  195. '人工检_次品板' => (int)$value['人工检_次品板']=0?'':$value['人工检_次品板'],
  196. '人工检_废检' => (int)$value['人工检_废检']=0?'':$value['人工检_废检'],
  197. '机检_正品板' => (int)$value['机检_正品板']=0?'':$value['机检_正品板'],
  198. '机检_次品板' => (int)$value['机检_次品板']=0?'':$value['机检_次品板'],
  199. '机检_废检' => (int)$value['机检_废检']=0?'':$value['机检_废检'],
  200. '开数*联数' => rtrim($value['Gy0_ks']).'*'.rtrim($value['Gy0_ls']),
  201. '备注' => rtrim($value['工序备注']),
  202. '印刷方式' => rtrim($value['印刷方式']),
  203. '版距' => rtrim($value['版距']),
  204. '建档用户' => rtrim($value['Sys_id']),
  205. '建档日期' => rtrim($value['Sys_rq']),
  206. '更新时间' => rtrim($value['Mod_rq']),
  207. ];
  208. }
  209. }
  210. $this->success('成功',$data);
  211. }
  212. /**
  213. * BOM资料
  214. * @ApiMethod (GET)
  215. * @param string $Gd_gdbh 工单编号
  216. * @return \think\response\Json
  217. * @throws \think\db\exception\DataNotFoundException
  218. * @throws \think\db\exception\ModelNotFoundException
  219. * @throws \think\exception\DbException
  220. */
  221. public function Bom()
  222. {
  223. if ($this->request->isGet() === false){
  224. $this->error('请求错误');
  225. }
  226. $Gd_gdbh = input('Gd_gdbh');
  227. if (empty($Gd_gdbh)){
  228. $this->error('参数错误');
  229. }
  230. $field = 'rtrim(BOM_方案) as 方案,rtrim(BOM_物料编码) as 物料编号,rtrim(BOM_物料名称) as 物料名称,BOM_投料单位,
  231. BOM_投入数,BOM_产出数,BOM_产出单位,rtrim(BOM_计划用量) as 计划用量,rtrim(Sys_ID) as 建档用户,rtrim(Sys_rq) as 建档时间,rtrim(Mod_rq) as 更新时间';
  232. $list = Db::table('工单_bom资料')
  233. ->where('BOM_工单编号',$Gd_gdbh)
  234. ->field($field)
  235. ->select();
  236. foreach ($list as $key=>$value){
  237. $list[$key]['消耗定量'] = rtrim($value['BOM_投入数']).rtrim($value['BOM_投料单位']).'/'.rtrim($value['BOM_产出数']).rtrim($value['BOM_产出单位']);
  238. unset($list[$key]['BOM_投料单位'],$list[$key]['BOM_投入数'],$list[$key]['BOM_产出数'],$list[$key]['BOM_产出单位']);
  239. $list[$key]['计划用量'] = rtrim((float)$value['计划用量']);
  240. }
  241. $this->success('成功',$list);
  242. }
  243. }