WorkOrder.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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' => $productIng = 0?'':"生产中:".$productIng,
  43. 'progress' => $proGress=0?'':'计划中:'.$proGress,
  44. ];
  45. $menu = $Detail['Gd_khdh'].'【'.$Detail['producting'].$Detail['progress'].'】'.'【'.$Detail['Gd_khmc'].'】';
  46. array_push($data,$menu);
  47. }
  48. }
  49. $this->success('成功',$data);
  50. }
  51. /**
  52. * 工单基本资料列表
  53. * @ApiMethod (GET)
  54. * @param string $limit 查询长度
  55. * @param string $Gd_khdh 客户代号
  56. * @param string $startTime 接单日期开始时间
  57. * @param string $endTime 接单日期结束时间
  58. * @return \think\response\Json
  59. * @throws \think\exception\DbException
  60. */
  61. public function WorkList()
  62. {
  63. if ($this->request->isGet() === false){
  64. $this->error('请求错误');
  65. }
  66. $limit = input('limit');
  67. // $page = input('page');
  68. $clientNumber = input('Gd_khdh');
  69. $startTime = input('start');
  70. $endTime = input('end');
  71. $where = [
  72. 'Gd_khdh' => $clientNumber
  73. ];
  74. if (isset($startTime) && isset($endTime)){
  75. $where['接单日期'] = ['between',[$startTime,$endTime]];
  76. }
  77. // $config = [
  78. // 'page_param' => $page,
  79. // 'per_page' => $limit
  80. // ];
  81. $list = Db::table('工单_基本资料')
  82. ->where($where)
  83. ->order('接单日期 desc')
  84. ->paginate($limit);
  85. //工单基本资料数据整理
  86. $data = [];
  87. foreach ($list->items() as $key=>$value){
  88. $data[$key] = [
  89. '工单编号' => rtrim($value['Gd_gdbh']),
  90. '生产分类' => rtrim($value['Gd_生产分类']),
  91. '销售订单号' => rtrim($value['销售订单号']),
  92. '产品代号' => rtrim($value['Gd_cpdh']),
  93. '产品名称' => rtrim($value['Gd_cpmc']),
  94. '订单数量' => rtrim($value['订单数量']),
  95. '单位' => rtrim($value['计量单位']),
  96. '折合大箱' => rtrim((int)$value['投料大箱']),
  97. '投料率' => rtrim($value['投料率']),
  98. '平均合格率' => '',
  99. '开单日期' => date('Y-m-d',strtotime(rtrim($value['接单日期']))),
  100. '交货日期' => date('Y-m-d',strtotime(rtrim($value['交货日期']))),
  101. '工单类型' => rtrim($value['Gd_lx']),
  102. '工单状态' => rtrim($value['gd_statu']),
  103. '当前生产工序' => '',
  104. '产量提交时间' => '',
  105. '建档用户' => rtrim($value['Sys_id']),
  106. '建档时间' => rtrim($value['Sys_rq']),
  107. '更新时间' => rtrim($value['Mod_rq']),
  108. ];
  109. }
  110. $this->success('成功',$data);
  111. }
  112. /**
  113. * 印件资料
  114. * @ApiMethod (GET)
  115. * @param string $Gd_gdbh 工单编号
  116. * @return \think\response\Json
  117. * @throws \think\db\exception\DataNotFoundException
  118. * @throws \think\db\exception\ModelNotFoundException
  119. * @throws \think\exception\DbException
  120. */
  121. public function Printed()
  122. {
  123. if ($this->request->isGet() === false){
  124. $this->error('请求错误');
  125. }
  126. $Gd_gdbh = input('Gd_gdbh');
  127. if (empty($Gd_gdbh)){
  128. $this->error('参数错误');
  129. }
  130. $list = Db::table('工单_印件资料')->where('Yj_Gdbh',$Gd_gdbh)->select();
  131. $data = [];
  132. if ($list){
  133. foreach ($list as $key=>$value){
  134. $data[$key] = [
  135. '印件号' => rtrim($value['yj_Yjno']),
  136. '印件代号' => rtrim($value['yj_Yjdh']),
  137. '印件名称' => rtrim($value['yj_yjmc']),
  138. '纸张代号' => rtrim($value['yj_zzdh']),
  139. '纸张名称' => rtrim($value['yj_zzmc']),
  140. '投料规格' => rtrim($value['yj_tlgg']),
  141. '平张投料' => rtrim($value['yj_平张投料']),
  142. '开料规格' => rtrim($value['yj_klgg']),
  143. '开数*联数' => rtrim($value['yj_ks']).'*'.rtrim($value['yj_ls']),
  144. '建档用户' => rtrim($value['Sys_id']),
  145. '建档时间' => rtrim($value['Sys_rq']),
  146. '更新时间' => rtrim($value['Mod_rq']),
  147. ];
  148. }
  149. }
  150. $this->success('成功',$data);
  151. }
  152. /**
  153. * 工艺资料
  154. * @ApiMethod (GET)
  155. * @param string $Gd_gdbh 工单编号
  156. * @return \think\response\Json
  157. * @throws \think\db\exception\DataNotFoundException
  158. * @throws \think\db\exception\ModelNotFoundException
  159. * @throws \think\exception\DbException
  160. */
  161. public function Craft()
  162. {
  163. if ($this->request->isGet() === false){
  164. $this->error('请求错误');
  165. }
  166. $Gd_gdbh = input('Gd_gdbh');
  167. if (empty($Gd_gdbh)){
  168. $this->error('参数错误');
  169. }
  170. $list = Db::table('工单_工艺资料')
  171. ->where('Gy0_gdbh',$Gd_gdbh)
  172. ->select();
  173. $Gd_cpdh = Db::table('工单_基本资料')->where('Gd_gdbh',$Gd_gdbh)->field('Gd_cpdh')->find();
  174. $data = [];
  175. if ($list){
  176. foreach ($list as $key=>$value){
  177. if ($value['Gy0_yjno']<10){
  178. $value['Gy0_yjno'] = '0'.$value['Gy0_yjno'];
  179. }
  180. if ($value['Gy0_gxh']<10){
  181. $value['Gy0_gxh'] = '0'.$value['Gy0_gxh'];
  182. }
  183. $where = [
  184. 'Gy0_cpdh' => $Gd_cpdh['Gd_cpdh'],
  185. 'Gy0_yjno' => $value['Gy0_yjno'],
  186. 'Gy0_gxh' => $value['Gy0_gxh'],
  187. ];
  188. $product = Db::table('产品_工艺资料')->where($where)->field('工价系数,损耗系数')->find();
  189. $data[$key] = [
  190. '重点工序' => rtrim($value['重点工序']),
  191. '印件-工序' => rtrim($value['Gy0_yjno']).'-'.rtrim($value['Gy0_gxh']),
  192. '备选工序' => '',
  193. '工序名称' => rtrim($value['Gy0_gxmc']).'【'.rtrim($value['Add_gxmc']).'】',
  194. '计划产量' => '',
  195. '基础损耗' => rtrim($value['Gy0_Rate0']),
  196. '损耗率' => rtrim($value['Gy0_Rate1']),
  197. '报废定额' => '',
  198. '允损比例' => '',
  199. '难度系数' => isset($product['工价系数'])?rtrim($product['工价系数']):'',
  200. '损耗系数' => isset($product['损耗系数'])?rtrim($product['损耗系数']):'',
  201. '人工检_次品板' => (int)$value['人工检_次品板']=0?'':$value['人工检_次品板'],
  202. '人工检_废检' => (int)$value['人工检_废检']=0?'':$value['人工检_废检'],
  203. '机检_正品板' => (int)$value['机检_正品板']=0?'':$value['机检_正品板'],
  204. '机检_次品板' => (int)$value['机检_次品板']=0?'':$value['机检_次品板'],
  205. '机检_废检' => (int)$value['机检_废检']=0?'':$value['机检_废检'],
  206. '开数*联数' => rtrim($value['Gy0_ks']).'*'.rtrim($value['Gy0_ls']),
  207. '备注' => isset($value['工序备注'])?rtrim($value['工序备注']):'',
  208. '印刷方式' => isset($value['印刷方式'])?rtrim($value['印刷方式']):'',
  209. '版距' => isset($value['版距'])?rtrim($value['版距']):'',
  210. '建档用户' => rtrim($value['Sys_id']),
  211. '建档日期' => isset($value['Sys_rq'])?rtrim($value['Sys_rq']):'',
  212. '更新时间' => isset($value['Mod_rq'])?rtrim($value['Mod_rq']):'',
  213. ];
  214. }
  215. }
  216. $this->success('成功',$data);
  217. }
  218. /**
  219. * BOM资料
  220. * @ApiMethod (GET)
  221. * @param string $Gd_gdbh 工单编号
  222. * @return \think\response\Json
  223. * @throws \think\db\exception\DataNotFoundException
  224. * @throws \think\db\exception\ModelNotFoundException
  225. * @throws \think\exception\DbException
  226. */
  227. public function Bom()
  228. {
  229. if ($this->request->isGet() === false){
  230. $this->error('请求错误');
  231. }
  232. $Gd_gdbh = input('Gd_gdbh');
  233. if (empty($Gd_gdbh)){
  234. $this->error('参数错误');
  235. }
  236. $field = 'rtrim(BOM_方案) as 方案,rtrim(BOM_物料编码) as 物料编号,rtrim(BOM_物料名称) as 物料名称,BOM_投料单位,
  237. BOM_投入数,BOM_产出数,BOM_产出单位,rtrim(BOM_计划用量) as 计划用量,rtrim(Sys_ID) as 建档用户,rtrim(Sys_rq) as 建档时间,rtrim(Mod_rq) as 更新时间';
  238. $list = Db::table('工单_bom资料')
  239. ->where('BOM_工单编号',$Gd_gdbh)
  240. ->field($field)
  241. ->select();
  242. foreach ($list as $key=>$value){
  243. $list[$key]['消耗定量'] = rtrim($value['BOM_投入数']).rtrim($value['BOM_投料单位']).'/'.rtrim($value['BOM_产出数']).rtrim($value['BOM_产出单位']);
  244. unset($list[$key]['BOM_投料单位'],$list[$key]['BOM_投入数'],$list[$key]['BOM_产出数'],$list[$key]['BOM_产出单位']);
  245. $list[$key]['计划用量'] = rtrim((float)$value['计划用量']);
  246. }
  247. $this->success('成功',$list);
  248. }
  249. /**
  250. * 编辑页面展示
  251. * @ApiMethod (GET)
  252. * @param string $workOrder 工单编号
  253. * @return void
  254. * @throws \think\db\exception\DataNotFoundException
  255. * @throws \think\db\exception\ModelNotFoundException
  256. * @throws \think\exception\DbException
  257. */
  258. public function DataCorrection()
  259. {
  260. if ($this->request->isGet() === false){
  261. $this->error('请求错误');
  262. }
  263. $workOrder = input('Gd_gdbh');
  264. if (empty($workOrder)){
  265. $this->error('参数错误');
  266. }
  267. $field = 'rtrim(Gd_lx) as 重点工单,rtrim(Gd_gdbh) as 工单编号,rtrim(Gd_生产分类) as 生产类型,rtrim(Gd_khdh) as 客户代号,rtrim(Gd_客户名称) as 客户名称,
  268. rtrim(Gd_cpdh) as 产品代号,rtrim(Gd_cpmc) as 产品名称,rtrim(开单日期) as 开单日期,rtrim(订单数量) as 订单数量,rtrim(交货日期) as 交货日期,
  269. rtrim(投料率) as 投料率,rtrim(实际投料) as 万小张,rtrim(计量单位) as 单位,rtrim(投料大箱) as 投料大箱,rtrim(排产时库存) as 库存大箱,rtrim(警语版面) as 警语版面,
  270. rtrim(销售订单号) as 销售订单号,rtrim(产品版本号) as 版本号,rtrim(客户ERP编码) as 客户ERP编码,rtrim(码源数量) as 码源数量,rtrim(进程备注) as 进程备注,rtrim(Gd_desc) as 备注';
  271. $list = Db::table('工单_基本资料')->where('Gd_gdbh',$workOrder)->field($field)->find();
  272. if (empty($list)){
  273. $this->error('未找到该工单信息');
  274. }
  275. $printData = Db::table('工单_印件资料')
  276. ->where('Yj_Gdbh',$workOrder)
  277. ->field('rtrim(yj_yjmc) as 印件名称,rtrim(yj_Yjdh) as 印件代号,rtrim(yj_平张投料) as 平张投料')
  278. ->find();
  279. if (empty($printData)){
  280. $this->error('未找到该工单印件资料');
  281. }
  282. $list['印件名称'] = $printData['印件名称'];
  283. $list['印件代号'] = $printData['印件代号'];
  284. $list['平张投料'] = $printData['平张投料'];
  285. $this->success('成功',$list);
  286. }
  287. }