YxworkOrder.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. /**
  5. * 翌星工单资料管理
  6. */
  7. class YxworkOrder extends Api
  8. {
  9. protected $noNeedLogin = ['*'];
  10. protected $noNeedRight = ['*'];
  11. /**
  12. * 工单资料菜单列表
  13. *
  14. * @ApiMethod (GET)
  15. * @return false|string
  16. * @throws \think\Exception
  17. */
  18. public function DataList()
  19. {
  20. if ($this->request->isGet() === false){
  21. $this->error('请求错误');
  22. }
  23. $where['工单分类'] = ['in',[1,3]];
  24. $where['行号'] = '1';
  25. //获取总计划中数量和总生产中数量
  26. $productingAll = \db('工单_基本资料')
  27. ->where($where)
  28. ->where('成品代号','<>','')
  29. ->where('gd_statu','2-生产中')
  30. ->count();
  31. $progressAll = \db('工单_基本资料')
  32. ->where($where)
  33. ->where('成品代号','<>','')
  34. ->where('gd_statu','3-计划中')
  35. ->count();
  36. $data = [
  37. 'productingAll' => $productingAll,
  38. 'progressAll' => $progressAll,
  39. ];
  40. $list = \db('产品_基本资料')
  41. ->where('客户编号','<>','')
  42. ->field('客户编号,客户名称')
  43. ->group('客户编号,客户名称')
  44. ->order('客户编号')
  45. ->select();
  46. if (empty($list)){
  47. $this->success('',[]);
  48. }
  49. $data['翌星工单']=[];
  50. foreach ($list as $key=>$value){
  51. $value['客户编号'] = rtrim($value['客户编号']);
  52. //这条sql查出来的数据可能不对,试一下以下sql
  53. $productIng = \db('工单_基本资料')
  54. ->where($where)
  55. ->where('Gd_cpdh|成品代号','LIKE',rtrim($value['客户编号']).'%')
  56. ->where('gd_statu','2-生产中')
  57. ->count();
  58. $proGress = \db('工单_基本资料')
  59. ->where($where)
  60. ->where('Gd_cpdh|成品代号','LIKE',rtrim($value['客户编号']).'%')
  61. ->where('gd_statu','3-计划中')
  62. ->count();
  63. $string = '';
  64. if ($productIng != 0){
  65. $string = $string."生产中:".$productIng;
  66. }
  67. if ($proGress != 0){
  68. $string = $string."计划中:".$proGress;
  69. }
  70. if ($string !== ''){
  71. $name = $value['客户编号'].'【'.$string.'】'.rtrim($value['客户名称']);
  72. if (strpos($value['客户编号'],'J') !== false || strpos($value['客户编号'],'Y') !== false){
  73. array_push($data['翌星工单'],$name);
  74. }
  75. }
  76. }
  77. $this->success('成功',$data);
  78. }
  79. /**
  80. * 工单基本资料列表
  81. * @ApiMethod (GET)
  82. * @param string $limit 查询长度
  83. * @param string $Gd_khdh 客户代号
  84. * @param string $startTime 接单日期开始时间
  85. * @param string $endTime 接单日期结束时间
  86. * @return \think\response\Json
  87. * @throws \think\exception\DbException
  88. */
  89. public function WorkList()
  90. {
  91. if ($this->request->isGet() === false){
  92. $this->error('请求错误');
  93. }
  94. $search = input('search');
  95. $clientNumber = input('Gd_khdh');
  96. $startTime = input('start');
  97. $endTime = input('end');
  98. $page = input('page');
  99. $limit = input('limit');
  100. $param = $this->request->param();
  101. if (isset($param['sort'])){
  102. $sort = 2;
  103. }else{
  104. $sort = 1;
  105. }
  106. $where = [];
  107. if (!empty($clientNumber)){
  108. if (substr($clientNumber,0,1) !== 'Y' && substr($clientNumber,0,1) !== 'J')
  109. {
  110. $clientNumber = substr($clientNumber,0,4);
  111. }
  112. if ($clientNumber === 'Y1401'){
  113. $where['Gd_cpdh'] = ['like',$clientNumber.'%'];
  114. }else{
  115. $where['成品代号'] = ['like',$clientNumber.'%'];
  116. }
  117. }
  118. if (!empty($workOrder)){
  119. $where['Gd_gdbh'] = $workOrder;
  120. }
  121. if (!empty($productCode)){
  122. $where['Gd_cpdh'] = $productCode;
  123. }
  124. if (!empty($search)){
  125. $where['Gd_lx|Gd_gdbh|Gd_客户代号|Gd_客户名称|Gd_khdh|Gd_khmc|Gd_cpdh|Gd_cpmc|成品代号|成品名称|产品版本号'] = ['like','%'.$search.'%'];
  126. }
  127. if (!empty($startTime) && !empty($endTime)){
  128. $where['接单日期'] = ['between',[$startTime,$endTime]];
  129. }
  130. $total = \db('工单_基本资料')->where($where)->distinct(true)->field('Gd_gdbh')->count();
  131. $list = \db('工单_基本资料')
  132. ->where($where)
  133. ->order('Gd_statu desc')
  134. ->limit(($page-1)*$limit,$limit)
  135. ->group('Gd_gdbh')
  136. ->select();
  137. //工单基本资料数据整理
  138. $data = [];
  139. foreach ($list as $key=>$value){
  140. $data[$key] = [
  141. '工单编号' => rtrim($value['Gd_gdbh']),
  142. '生产分类' => rtrim($value['Gd_生产分类']),
  143. '销售订单号' => rtrim($value['销售订单号']),
  144. '产品代号' => rtrim($value['成品代号']),
  145. '产品名称' => rtrim($value['成品名称']),
  146. '订单数量' => floatval($value['订单数量']),
  147. '单位' => rtrim($value['计量单位']),
  148. '折合大箱' => rtrim((int)$value['投料大箱']),
  149. '投料率' => rtrim($value['投料率']),
  150. '平均合格率' => '',
  151. '开单日期' => date('Y-m-d',strtotime(rtrim($value['接单日期']))),
  152. '交货日期' => date('Y-m-d',strtotime(rtrim($value['交货日期']))),
  153. '工单类型' => rtrim($value['Gd_lx']),
  154. '工单状态' => rtrim($value['gd_statu']),
  155. '当前生产工序' => '',
  156. '产量提交时间' => '',
  157. '建档用户' => rtrim($value['Sys_id']),
  158. '建档时间' => rtrim($value['Sys_rq']),
  159. '更新时间' => rtrim($value['Mod_rq']),
  160. 'Uniqid' => rtrim($value['Uniqid'])
  161. ];
  162. $number = \db('工单_工艺资料')->where('Gy0_gdbh',$data[$key]['工单编号'])->count();
  163. if ($number === 0){
  164. $data[$key]['status'] = '*';
  165. }else{
  166. $data[$key]['status'] = '';
  167. }
  168. }
  169. $this->success('成功',['data'=>$data,'total'=>$total]);
  170. }
  171. /**
  172. * 工单详情
  173. * @ApiMethod (GET)
  174. * @param void
  175. * @return void
  176. * @throws \think\db\exception\DataNotFoundException
  177. * @throws \think\db\exception\ModelNotFoundException
  178. * @throws \think\exception\DbException
  179. */
  180. public function workOrderListDetail()
  181. {
  182. if ($this->request->isGet() === false){
  183. $this->error('请求错误');
  184. }
  185. $Gd_gdbh = input('Gd_gdbh');
  186. $param = $this->request->param();
  187. if (empty($Gd_gdbh)){
  188. $this->error('参数错误');
  189. }
  190. if (isset($param['sort'])){
  191. $where['yj_Yjno'] = ['>=','10'];
  192. }else{
  193. $where['yj_Yjno'] = ['<','10'];
  194. }
  195. $data = [];
  196. //印件资料
  197. $printList = \db('工单_印件资料')
  198. ->where('Yj_Gdbh',$Gd_gdbh)
  199. ->where($where)
  200. ->select();
  201. if (!empty($printList)){
  202. foreach ($printList as $key=>$value){
  203. $data['printList'][$key] = [
  204. '印件号' => rtrim($value['yj_Yjno']),
  205. '印件代号' => rtrim($value['yj_Yjdh']),
  206. '印件名称' => rtrim($value['yj_yjmc']),
  207. '纸张代号' => rtrim($value['yj_zzdh']),
  208. '纸张名称' => rtrim($value['yj_zzmc']),
  209. '投料规格' => rtrim($value['yj_tlgg']),
  210. '平张投料' => rtrim($value['yj_平张投料']),
  211. '开料规格' => rtrim($value['yj_klgg']),
  212. '开数*联数' => rtrim($value['yj_ks']).'*'.rtrim($value['yj_ls']),
  213. '建档用户' => rtrim($value['Sys_id']),
  214. '建档时间' => rtrim($value['Sys_rq']),
  215. '更新时间' => rtrim($value['Mod_rq']),
  216. 'zzdh1' => rtrim($value['yj_zzdh1']),
  217. 'zzdh2' => rtrim($value['yj_zzdh2']),
  218. 'zzdh3' => rtrim($value['yj_zzdh3']),
  219. 'zzdh4' => rtrim($value['yj_zzdh4']),
  220. 'zzmc1' => rtrim($value['yj_zzmc1']),
  221. 'zzmc2' => rtrim($value['yj_zzmc2']),
  222. 'zzmc3' => rtrim($value['yj_zzmc3']),
  223. 'zzmc4' => rtrim($value['yj_zzmc4']),
  224. '订单数量' => rtrim($value['yj_成品数量']),
  225. '万小张' => rtrim($value['yj_实际投料']),
  226. '开数' => rtrim($value['yj_ks']),
  227. '联数' => rtrim($value['yj_ls']),
  228. '核算规格' => rtrim($value['Yj_核算规格']),
  229. '备注' => rtrim($value['yj_desc']),
  230. 'Uniqid' => rtrim($value['Uniqid'])
  231. ];
  232. }
  233. }else{
  234. $data['printList'] = [];
  235. }
  236. //工艺资料
  237. if (isset($param['sort'])){
  238. $Prowhere['Gy0_yjno'] = ['>=','10'];
  239. }else{
  240. $Prowhere['Gy0_yjno'] = ['<','10'];
  241. }
  242. $processList = \db('工单_工艺资料')
  243. ->where('Gy0_gdbh',$Gd_gdbh)
  244. ->where($Prowhere)
  245. ->order('Gy0_yjno,Gy0_gxh')
  246. ->select();
  247. if (!empty($processList)){
  248. foreach ($processList as $key=>$value){
  249. if ($value['Gy0_yjno']<10){
  250. $value['Gy0_yjno'] = '0'.$value['Gy0_yjno'];
  251. }
  252. if ($value['Gy0_gxh']<10){
  253. $value['Gy0_gxh'] = '0'.$value['Gy0_gxh'];
  254. }
  255. if (rtrim($value['Gy0_shdh']) == '' || $value['Gy0_计划接货数'] == 0){
  256. $number = 0;
  257. }else{
  258. $number = round(((int)$value['Gy0_计划损耗']/(int)($value['Gy0_计划接货数']))*100,2).'%';
  259. }
  260. if ($value['PD_WG'] !== '1900-01-01 00:00:00'){
  261. $status = '已完工';
  262. }else{
  263. $status = '未完工';
  264. }
  265. $data['processList'][$key] = [
  266. '重点工序' => rtrim($value['重点工序']),
  267. '印件-工序' => rtrim($value['Gy0_yjno']).'-'.rtrim($value['Gy0_gxh']),
  268. '备选工序' => rtrim($value['备选工序']),
  269. '工序名称' => rtrim($value['Gy0_gxmc']).'【'.rtrim($value['Add_gxmc']).'】',
  270. '印件号' => rtrim($value['Gy0_yjno']),
  271. '工序号' => rtrim($value['Gy0_gxh']),
  272. '工艺名称' => rtrim($value['Gy0_gxmc']),
  273. 'gxmc' => rtrim($value['Add_gxmc']),
  274. '计划产量' => $value['Gy0_计划接货数'],
  275. '基础损耗' => rtrim($value['Gy0_Rate0']),
  276. '损耗率' => rtrim($value['Gy0_Rate1']),
  277. '机台编号' => rtrim($value['Gy0_sbbh']),
  278. '报废定额' => rtrim($value['Gy0_计划损耗']),
  279. '计损色数' => rtrim($value['Gy0_ms']),
  280. '允损比例' => $number,
  281. '难度系数' => isset($value['工价系数'])?rtrim($value['工价系数']):'',
  282. '损耗系数' => isset($value['损耗系数'])?rtrim($value['损耗系数']):'',
  283. '人工检_次品板' => (int)$value['人工检_次品板']=0?'':$value['人工检_次品板'],
  284. '人工检_废检' => (int)$value['人工检_废检']=0?'':$value['人工检_废检'],
  285. '机检_正品板' => (int)$value['机检_正品板']=0?'':$value['机检_正品板'],
  286. '机检_次品板' => (int)$value['机检_次品板']=0?'':$value['机检_次品板'],
  287. '机检_废检' => (int)$value['机检_废检']=0?'':$value['机检_废检'],
  288. '开数*联数' => rtrim($value['Gy0_ks']).'*'.rtrim($value['Gy0_ls']),
  289. '备注' => isset($value['工序备注'])?rtrim($value['工序备注']):'',
  290. '印刷方式' => isset($value['印刷方式'])?rtrim($value['印刷方式']):'',
  291. '版距' => isset($value['版距'])?rtrim($value['版距']):'',
  292. '建档用户' => rtrim($value['Sys_id']),
  293. '建档日期' => isset($value['Sys_rq'])?rtrim($value['Sys_rq']):'',
  294. '更新时间' => isset($value['Mod_rq'])?rtrim($value['Mod_rq']):'',
  295. '车间名称' => rtrim($value['Gy0_SITE']),
  296. '质量要求' => rtrim($value['质量要求']),
  297. '质量隐患' => rtrim($value['质量隐患']),
  298. '开数' => rtrim($value['Gy0_ks']),
  299. '联数' => rtrim($value['Gy0_ls']),
  300. 'UniqId' => rtrim($value['UniqId']),
  301. 'shdh' => rtrim($value['Gy0_shdh']),
  302. '辅助工时' => rtrim($value['Gy0_辅助工时']),
  303. '小时产能' => rtrim($value['Gy0_小时产能']),
  304. 'status' => $status
  305. ];
  306. }
  307. }else{
  308. $data['processList'] = [];
  309. }
  310. //BOM资料
  311. $field = 'rtrim(BOM_方案) as 方案,rtrim(BOM_物料编码) as 物料编号,rtrim(BOM_物料名称) as 物料名称,BOM_投料单位,
  312. BOM_投入数,BOM_产出数,BOM_产出单位,rtrim(BOM_计划用量) as 计划用量,rtrim(Sys_ID) as 建档用户,rtrim(Sys_rq) as 建档时间,rtrim(Mod_rq) as 更新时间';
  313. $bomList = \db('工单_bom资料')
  314. ->where('BOM_工单编号',$Gd_gdbh)
  315. ->field($field)
  316. ->select();
  317. if (!empty($bomList)){
  318. foreach ($bomList as $key=>$value){
  319. $bomList[$key]['消耗定量'] = rtrim($value['BOM_投入数']).rtrim($value['BOM_投料单位']).'/'.rtrim($value['BOM_产出数']).rtrim($value['BOM_产出单位']);
  320. unset($bomList[$key]['BOM_投料单位'],$bomList[$key]['BOM_投入数'],$bomList[$key]['BOM_产出数'],$bomList[$key]['BOM_产出单位']);
  321. $bomList[$key]['计划用量'] = rtrim((float)$value['计划用量']);
  322. }
  323. $data['BOM'] = $bomList;
  324. }else{
  325. $data['BOM'] = [];
  326. }
  327. //工单附件资料
  328. $jsRes = db('工单_相关附件')
  329. ->where('关联编号','like','%'.$Gd_gdbh.'%')
  330. ->select();
  331. if (!empty($jsRes)){
  332. foreach ($jsRes as $key=>&$value){
  333. if(mb_detect_encoding($value['附件内容'])!='ASCII'){
  334. $value['附件内容'] = '';
  335. }
  336. }
  337. $data['jsData'] = $jsRes;
  338. }else{
  339. $data['jsData'] = [];
  340. }
  341. $this->success('成功',$data);
  342. }
  343. /**
  344. * 获取产品附件列表
  345. */
  346. public function getAnnexTable(){
  347. if(!$this->request->isGet()){
  348. $this->error('请求方式错误');
  349. }
  350. $req = $this->request->param();
  351. if (isset($req['cpdh']) && !empty($req['cpdh'])){
  352. $where['关联产品'] = ['LIKE','%'.$req['cpdh'].'%'];
  353. }else{
  354. $this->error('参数错误');
  355. }
  356. $rows = db('产品_技术附件')
  357. ->where($where)
  358. ->select();
  359. foreach ($rows as $key=>&$value){
  360. if(mb_detect_encoding($value['附件内容'])!='ASCII'){
  361. $value['附件内容'] = '';
  362. }
  363. }
  364. $this->success('成功',$rows);
  365. }
  366. /**
  367. * 获取产品附件列表
  368. */
  369. public function getGdAnnexTable(){
  370. if(!$this->request->isGet()){
  371. $this->error('请求方式错误');
  372. }
  373. $req = $this->request->param();
  374. if (isset($req['gdbh']) && !empty($req['gdbh'])){
  375. $where['关联编号'] = ['LIKE','%'.$req['gdbh'].'%'];
  376. }else{
  377. $this->error('参数错误');
  378. }
  379. $rows = db('工单_相关附件')
  380. ->where($where)
  381. ->select();
  382. foreach ($rows as $key=>&$value){
  383. if(mb_detect_encoding($value['附件内容'])!='ASCII'){
  384. $value['附件内容'] = '';
  385. }
  386. }
  387. $this->success('成功',$rows);
  388. }
  389. }