Manufacture.php 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use Monolog\Handler\IFTTTHandler;
  5. use Overtrue\Socialite\Providers\WeWorkProvider;
  6. use think\Db;
  7. use think\Request;
  8. use function fast\e;
  9. /**
  10. *
  11. * 生产排单管理
  12. */
  13. class Manufacture extends Api
  14. {
  15. protected $noNeedLogin = ['*'];
  16. protected $noNeedRight = ['*'];
  17. /**
  18. * 计划中工单
  19. * @ApiMethod (GET)
  20. * @return \think\response\Json
  21. * @throws \think\db\exception\DataNotFoundException
  22. * @throws \think\db\exception\ModelNotFoundException
  23. * @throws \think\exception\DbException
  24. */
  25. public function Project()
  26. {
  27. if ($this->request->isGet() === false){
  28. $this->error('请求错误');
  29. }
  30. $param = $this->request->param();
  31. if (empty($param)){
  32. $this->error('参数错误');
  33. }
  34. if ($param['status'] === '计划中'){
  35. $status = '3-计划中';
  36. }else{
  37. $status = '1-已完工';
  38. }
  39. $page = 0;
  40. $limit = 15;
  41. if (isset($param['page'])){
  42. $page = $param['page'];
  43. }
  44. if (isset($param['limit'])){
  45. $limit = $param['limit'];
  46. }
  47. $where = [
  48. 'gd_statu' => $status,
  49. '行号' => '1',
  50. ];
  51. if (isset($param['search'])){
  52. $where['Gd_lx|Gd_gdbh|Gd_客户代号|Gd_客户名称|Gd_khdh|Gd_khmc|Gd_cpdh|Gd_cpmc|成品代号|成品名称|产品版本号'] = ['like','%'.$param['search'].'%'];
  53. }
  54. $field = 'rtrim(Gd_生产分类) as 生产分类,rtrim(Gd_gdbh) as 工单编号,rtrim(Gd_cpdh) as 产品代号,rtrim(Gd_cpmc) as 产品名称,rtrim(成品名称) as 成品名称,
  55. rtrim(接单日期) as 接单日期,rtrim(交货日期) as 交货日期,rtrim(订单数量) as 订单数量,rtrim(计量单位) as 计量单位,rtrim(Gd_khmc) as 客户名称,
  56. rtrim(Gd_客户代号) as 客户编号,rtrim(Gd_desc) as 备注,rtrim(客户料号) as 客户料号,rtrim(Sys_id) as 创建用户,rtrim(Sys_rq) as 创建时间,
  57. rtrim(Mod_rq) as 修改时间,rtrim(Uniqid) as UNIQID,rtrim(投料率) as 投料率,rtrim(销售订单号) as 销售订单号';
  58. $list = \db('工单_基本资料')->where($where)->field($field)->limit(($page-1)*$limit,$limit)->order('Uniqid desc')->select();
  59. $total = \db('工单_基本资料')->where($where)->count();
  60. if (empty($list)){
  61. $this->success('',[]);
  62. }
  63. foreach ($list as $key=>$value){
  64. $list[$key]['订单数量'] = rtrim((float)$value['订单数量']);
  65. $list[$key]['产品名称'] = $value['产品名称'] != '' ? $value['产品名称']:$value['成品名称'];
  66. $number = \db('工单_工艺资料')->where('Gy0_gdbh',$value['工单编号'])->count();
  67. if ($number === 0){
  68. $list[$key]['status'] = 0;
  69. }else{
  70. $list[$key]['status'] = 1;
  71. }
  72. unset($list[$key]['成品名称']);
  73. }
  74. $this->success('成功',['data'=>$list,'total'=>$total]);
  75. }
  76. /**
  77. * 计划中工单->工艺资料
  78. * @ApiMethod (GET)
  79. * @param string $Gd_gdbh 工单编号
  80. * @return \think\response\Json
  81. * @throws \think\db\exception\DataNotFoundException
  82. * @throws \think\db\exception\ModelNotFoundException
  83. * @throws \think\exception\DbException
  84. */
  85. public function projectCraft()
  86. {
  87. if ($this->request->isGet() === false){
  88. $this->error('请求错误');
  89. }
  90. $Gd_gdbh = input('Gd_gdbh');
  91. if (empty($Gd_gdbh)){
  92. $this->error('参数错误');
  93. }
  94. $where = [
  95. 'Gy0_gdbh' => $Gd_gdbh
  96. ];
  97. $filed = 'rtrim(Gy0_gdbh) as 工单编号,rtrim(重点工序) as 重点工序,Gy0_yjno,Gy0_gxh,Gy0_gxmc,Add_gxmc,rtrim(工序备注) as 工序备注,
  98. rtrim(Gy0_sbbh) as 机组,rtrim(Gy0_小时产能) as 小时产能,rtrim(Gy0_生产工时) as 生产工时,rtrim(Gy0_辅助工时) as 辅助工时,
  99. rtrim(印刷方式) as 印刷方式,rtrim(版距) as 版距,rtrim(Sys_id) as 创建用户,rtrim(Sys_rq) as 创建时间,rtrim(Mod_rq) as 修改时间,rtrim(UniqId) as UNIQID';
  100. $list = \db('工单_工艺资料')->where($where)->field($filed)->select();
  101. if (empty($list)){
  102. $this->success('',[]);
  103. }
  104. foreach ($list as $key=>$value){
  105. if ((int)$value['Gy0_yjno'] <10){
  106. $value['Gy0_yjno'] = '0'.rtrim($value['Gy0_yjno']);
  107. }
  108. if ((int)$value['Gy0_gxh'] <10){
  109. $value['Gy0_gxh'] = '0'.rtrim($value['Gy0_gxh']);
  110. }
  111. if (rtrim($value['Add_gxmc']) == ''){
  112. $list[$key]['印件工序及名称'] = $value['Gy0_yjno'].'-'.$value['Gy0_gxh'].'-->'.rtrim($value['Gy0_gxmc']);
  113. }else{
  114. $list[$key]['印件工序及名称'] = $value['Gy0_yjno'].'-'.$value['Gy0_gxh'].'-->'.rtrim($value['Gy0_gxmc']).'【'.rtrim($value['Add_gxmc']).'】';
  115. }
  116. unset($list[$key]['Gy0_gxmc'],$list[$key]['Add_gxmc']);
  117. }
  118. $this->success('成功',$list);
  119. }
  120. /**
  121. * 计划中工单->印件资料
  122. * @ApiMethod (GET)
  123. * @param string $Gd_gdbh 工单编号
  124. * @return \think\response\Json
  125. * @throws \think\db\exception\DataNotFoundException
  126. * @throws \think\db\exception\ModelNotFoundException
  127. * @throws \think\exception\DbException
  128. */
  129. public function projectPrint()
  130. {
  131. if ($this->request->isGet() === false){
  132. $this->error('请求错误');
  133. }
  134. $Gd_gdbh = input('Gd_gdbh');
  135. if (empty($Gd_gdbh)){
  136. $this->error('参数错误');
  137. }
  138. $where = [
  139. 'Yj_Gdbh' => $Gd_gdbh,
  140. ];
  141. $field = 'rtrim(Yj_Gdbh) as 工单编号,rtrim(yj_Yjno) as 印件号,rtrim(yj_Yjdh) as 印件代号,rtrim(yj_yjmc) as 印件名称,
  142. rtrim(yj_zzmc) as 纸张名称,rtrim(yj_tlgg) as 投料规格,rtrim(yj_成品数量) as 成品数量,rtrim(yj_实际投料) as 实际投料,
  143. rtrim(yj_Dw) as 投料单位,rtrim(yj_平张投料) as 平张投料,rtrim(yj_ls) as 联数,rtrim(yj_ks) as 开数,rtrim(Sys_id) as 创建用户,
  144. rtrim(Sys_rq) as 创建时间,rtrim(Mod_rq) as 修改时间,rtrim(Uniqid) as UNIQID';
  145. $list = \db('工单_印件资料')->where($where)->field($field)->select();
  146. if (empty($list)){
  147. $this->success('');
  148. }
  149. foreach ($list as $key=>$value){
  150. $list[$key]['成品数量'] = rtrim((float)$value['成品数量']);
  151. $list[$key]['实际投料'] = rtrim((float)$value['实际投料']);
  152. }
  153. $this->success('成功',$list);
  154. }
  155. /**
  156. * 排程中/制程中工单
  157. */
  158. public function Schedule(){
  159. if ($this->request->isGet() === false){
  160. $this->error('请求错误');
  161. }
  162. $param = $this->request->param();
  163. if (empty($param)){
  164. $this->error('参数错误');
  165. }
  166. $where = '';
  167. if (!empty($param['search'])){
  168. $where = "
  169. a.Gd_gdbh LIKE '%{$param['search']}%'
  170. OR a.`成品名称` LIKE '%{$param['search']}%'
  171. ";
  172. }
  173. if ($param['status'] === '排程中'){
  174. $list = db('工单_基本资料')->alias('a')
  175. ->field([
  176. 'rtrim(a.Gd_gdbh)' => '工单编号',
  177. 'rtrim(a.Gd_cpdh)' => '产品代号',
  178. 'rtrim(a.Gd_cpmc)' => '产品名称',
  179. 'rtrim(a.接单日期)' => '接单日期',
  180. 'rtrim(a.交货日期)' => '交货日期',
  181. 'rtrim(a.订单数量)' => '订单数量',
  182. 'rtrim(a.计量单位)' => '计量单位',
  183. 'rtrim(a.销售订单号)' => '销售订单号',
  184. 'rtrim(a.Gd_客户代号)' => '客户编号',
  185. 'rtrim(a.Gd_客户名称)' => '客户名称',
  186. 'rtrim(a.客户料号)' => '客户料号',
  187. 'rtrim(a.Uniqid)' => 'GDUID',
  188. ])
  189. ->join('工单_工艺资料 b', 'a.Gd_gdbh = b.Gy0_gdbh')
  190. ->where([
  191. 'a.gd_statu' => '2-生产中',
  192. 'a.行号' => '1',
  193. 'b.PD_WG' => '1900-01-01 00:00:00',
  194. ])
  195. ->where($where)
  196. // ->whereNotExists(function ($query) {
  197. // $query->table('工单_工艺资料')->alias('b2')
  198. // ->where('b2.Gy0_gdbh = a.Gd_gdbh')
  199. // ->where('b2.Gy0_sj1 <> "1900-01-01 00:00:00"');
  200. // })
  201. ->group('a.Gd_gdbh')
  202. ->select();
  203. }else{
  204. $list = db('工单_基本资料')->alias('a')
  205. ->field([
  206. 'rtrim(a.Gd_gdbh)' => '工单编号',
  207. 'rtrim(a.Gd_cpdh)' => '产品代号',
  208. 'rtrim(a.Gd_cpmc)' => '产品名称',
  209. 'rtrim(a.接单日期)' => '接单日期',
  210. 'rtrim(a.交货日期)' => '交货日期',
  211. 'rtrim(a.订单数量)' => '订单数量',
  212. 'rtrim(a.计量单位)' => '计量单位',
  213. 'rtrim(a.销售订单号)' => '销售订单号',
  214. 'rtrim(a.Gd_客户代号)' => '客户编号',
  215. 'rtrim(a.Gd_客户名称)' => '客户名称',
  216. 'rtrim(a.客户料号)' => '客户料号',
  217. 'rtrim(a.Uniqid)' => 'GDUID',
  218. ])
  219. ->join('工单_工艺资料 b', 'a.Gd_gdbh = b.Gy0_gdbh')
  220. ->where([
  221. 'a.gd_statu' => '2-生产中',
  222. 'a.行号' => '1',
  223. 'b.PD_WG' => '1900-01-01 00:00:00',
  224. 'b.Gy0_sj1' => ['<>', '1900-01-01 00:00:00'],
  225. ])
  226. ->where($where)
  227. ->group('a.Gd_gdbh')
  228. ->select();
  229. }
  230. if (empty($list)){
  231. $this->success('未找到工单信息');
  232. }
  233. $this->success('成功',$list);
  234. }
  235. /**
  236. * 排程中/制程中工单->工序列表
  237. * @ApiMethod (GET)
  238. * @param string $Gd_gdbh 工单编号
  239. * @return \think\response\Json
  240. * @throws \think\db\exception\DataNotFoundException
  241. * @throws \think\db\exception\ModelNotFoundException
  242. * @throws \think\exception\DbException
  243. */
  244. public function ScheduleProcess()
  245. {
  246. if ($this->request->isGet() === false){
  247. $this->error('请求错误');
  248. }
  249. $Gd_gdbh = input('Gd_gdbh');
  250. if (empty($Gd_gdbh)){
  251. $this->error('参数错误');
  252. }
  253. $sql = "SELECT rtrim(a.Gy0_gdbh) as 工单编号,a.Gy0_yjno,a.Gy0_gxh,a.Gy0_gxmc,a.Add_gxmc,rtrim(a.Gy0_sbbh) as 设备编号,rtrim(a.Gy0_小时产能) as 小时产能,
  254. rtrim(a.工价系数) as 产能系数,rtrim(a.Gy0_生产工时) as 生产工时,rtrim(a.Gy0_辅助工时) as 辅助工时,rtrim(a.Gy0_最早开工时间) as 最早开工时间,
  255. rtrim(a.Gy0_sj1) as 计划开工时间,rtrim(a.Gy0_sj2) as 计划完工时间,rtrim(a.Gy0_班次安排) as 班次安排,rtrim(a.工序备注) as 排单备注,
  256. rtrim(a.PD_WG) as 工序完工,rtrim(a.UniqId) as UniqId,COALESCE(b.cl, 0) AS 产量, c.设备名称,rtrim(d.计划投料) as 工序产量
  257. FROM `工单_工艺资料` AS a
  258. JOIN `设备_基本资料` AS c ON a.Gy0_sbbh = c.设备编号
  259. JOIN `工单_基本资料` As d ON a.Gy0_gdbh = d.Gd_Gdbh
  260. LEFT JOIN (
  261. SELECT sczl_gdbh, sczl_gxh, SUM(sczl_cl) AS cl
  262. FROM `设备_产量计酬`
  263. GROUP BY sczl_gdbh, sczl_gxh
  264. ) AS b ON a.Gy0_gdbh = b.sczl_gdbh AND (a.Gy0_gxh = b.sczl_gxh OR b.sczl_gxh IS NULL)
  265. WHERE a.Gy0_gdbh = '{$Gd_gdbh}' AND a.Gy0_sbbh != ''
  266. GROUP BY a.Gy0_yjno,a.Gy0_gxh";
  267. $list = Db::query($sql);
  268. if (empty($list)){
  269. $this->success('未找到工序');
  270. }
  271. foreach ($list as $key=>$value){
  272. if ((int)$value['Gy0_yjno'] <10){
  273. $value['Gy0_yjno'] = '0'.rtrim($value['Gy0_yjno']);
  274. }
  275. if ((int)$value['Gy0_gxh'] <10){
  276. $value['Gy0_gxh'] = '0'.rtrim($value['Gy0_gxh']);
  277. }
  278. if (rtrim($value['Add_gxmc']) == ''){
  279. $list[$key]['印件工序及名称'] = $value['Gy0_yjno'].'-'.$value['Gy0_gxh'].'-->'.rtrim($value['Gy0_gxmc']);
  280. }else{
  281. $list[$key]['印件工序及名称'] = $value['Gy0_yjno'].'-'.$value['Gy0_gxh'].'-->'.rtrim($value['Gy0_gxmc']).'【'.rtrim($value['Add_gxmc']).'】';
  282. }
  283. unset($list[$key]['Gy0_gxmc'],$list[$key]['Add_gxmc']);
  284. $list[$key]['机组'] = $value['设备编号'];
  285. $list[$key]['剩余产量'] = (int)$list[$key]['工序产量']-(int)$list[$key]['产量'];
  286. }
  287. $this->success('成功',$list);
  288. }
  289. /**
  290. * 排单页面左侧车间和机台菜单
  291. * @ApiMethod (GET)
  292. * @return \think\response\Json
  293. * @throws \think\db\exception\DataNotFoundException
  294. * @throws \think\db\exception\ModelNotFoundException
  295. * @throws \think\exception\DbException
  296. */
  297. public function workbench()
  298. {
  299. if ($this->request->isGet() === false){
  300. $this->error('请求错误');
  301. }
  302. $param = $this->request->param();
  303. if (isset($param['sort'])){
  304. $where['使用部门'] = '智能车间';
  305. }else{
  306. $where['使用部门'] = ['in',['印刷车间','印后车间']];
  307. }
  308. $data = [];
  309. $department = \db('设备_基本资料')
  310. ->distinct(true)
  311. ->where('使用部门','<>','研发中心')
  312. ->where('设备编组','<>','')
  313. ->where($where)
  314. ->order('设备编组')
  315. ->column('使用部门');
  316. if (empty($department)){
  317. $this->success('为获取到机台数据');
  318. }
  319. foreach ($department as $value){
  320. $benchClass = \db('设备_基本资料')->where('使用部门',$value)->distinct(true)->order('设备编组')->column('设备编组');
  321. foreach ($benchClass as $v){
  322. if (rtrim($v) !== ''){
  323. $machine = \db('设备_基本资料')->where('使用部门',$value)->where('设备编组',$v)->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->select();
  324. foreach ($machine as $kk=>$vv){
  325. $data[rtrim($value)][rtrim($v)][$kk] = $vv['设备编号'].'-->'.$vv['设备名称'];
  326. }
  327. }
  328. }
  329. }
  330. $this->success('成功',$data);
  331. }
  332. /**
  333. * 工单状态设置
  334. * @ApiMethod (GET)
  335. * @param string $workOrder 工单编号
  336. * @param string $status 工单状态
  337. * @return void
  338. * @throws \think\Exception
  339. * @throws \think\exception\PDOException
  340. */
  341. public function StatusEdit()
  342. {
  343. if (Request::instance()->isPost() === false){
  344. $this->error('请求错误');
  345. }
  346. $workOrder = input('workOrder');
  347. $status = input('status');
  348. if (empty($workOrder) || empty($status)){
  349. $this->error('参数错误');
  350. }
  351. $sql = \db('工单_基本资料')->where('Gd_gdbh',$workOrder)->fetchSql(true)->update(['gd_statu'=>$status]);
  352. $res = Db::query($sql);
  353. if ($res !== false){
  354. $this->success('成功');
  355. }else{
  356. $this->error('失败');
  357. }
  358. }
  359. /**
  360. * 更改工序状态
  361. * @ApiMethod (GET)
  362. * @param void
  363. * @return void
  364. * @throws \think\Exception
  365. * @throws \think\exception\PDOException
  366. */
  367. public function complete()
  368. {
  369. if ($this->request->isGet() === false){
  370. $this->error('请求错误');
  371. }
  372. $data = $this->request->param();
  373. if (empty($data)){
  374. $this->error('参数错误');
  375. }
  376. $where = [
  377. 'Gy0_gdbh' => $data['workOrder'],
  378. 'Gy0_gxh' => $data['processCode']
  379. ];
  380. $sql = \db('工单_工艺资料')->where($where)->fetchSql(true)->update(['PD_WG'=>date('Y-m-d H:i:s',time())]);
  381. $res = Db::query($sql);
  382. if ($res !== false){
  383. $this->success('成功');
  384. }else{
  385. $this->error('失败');
  386. }
  387. }
  388. /**
  389. * 加入排产
  390. * @ApiMethod (POST)
  391. * @param void $data
  392. * @return void
  393. * @throws \think\Exception
  394. * @throws \think\db\exception\DataNotFoundException
  395. * @throws \think\db\exception\ModelNotFoundException
  396. * @throws \think\exception\DbException
  397. * @throws \think\exception\PDOException
  398. */
  399. public function ProductionSchedulingAdd()
  400. {
  401. if (Request::instance()->isPost() === false){
  402. $this->error('请求错误');
  403. }
  404. $data = Request::instance()->post();
  405. if (empty($data)){
  406. $this->error('参数错误');
  407. }
  408. $where = [
  409. 'Gy0_gdbh' => $data['workOrder'],
  410. 'Gy0_sbbh' => ['like','%'.$data['machine'].'%'],
  411. 'Gy0_yjno' => $data['printCode'],
  412. 'Gy0_gxh' => $data['processCode']
  413. ];
  414. $result = \db('工单_工艺资料')->where($where)->field('rtrim(Gy0_sj1) as sj1')->find();
  415. if ($result['sj1'] != '1900-01-01 00:00:00'){
  416. $this->error('该工单已经是制程中');
  417. }
  418. $lastTime = \db('工单_工艺资料')
  419. ->where(['Gy0_sbbh'=>$where['Gy0_sbbh'],'Gy0_sj2'=>['<>','1900-01-01 00:00:00'],'Gy0_sj2'=>['<','2099-01-01 00:00:00']])
  420. ->field('rtrim(Gy0_sj2) as sj2')
  421. ->order('Gy0_sj2 desc')
  422. ->find();
  423. $date = date('Y-m-d H:i:s',time());
  424. if ($lastTime['sj2'] < $date){
  425. $newTime = $date;
  426. }else{
  427. $newTime = $lastTime['sj2'];
  428. }
  429. $row = \db('工单_工艺资料')
  430. ->where($where)
  431. ->field('rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_小时产能) as 小时产能,rtrim(Gy0_辅助工时) as 辅助工时')
  432. ->find();
  433. if (empty($row)){
  434. $this->success('未找到该工单工艺资料');
  435. }
  436. $endTime = date('Y-m-d H:i:s',strtotime($newTime) + ((int)round($row['计划接货数']/$row['小时产能'])+(int)$row['辅助工时'])*3600);
  437. $sql = \db('工单_工艺资料')
  438. ->where($where)
  439. ->fetchSql(true)
  440. ->update(['Gy0_sj1'=>$newTime,'Gy0_sj2'=>$endTime,'Mod_rq'=>date('Y-m-d H:i:s',time())]);
  441. $res = Db::query($sql);
  442. if ($res !== false){
  443. $this->success('成功');
  444. }else{
  445. $this->error('失败');
  446. }
  447. }
  448. /**
  449. * 暂停排产
  450. * @ApiMethod (POST)
  451. * @param void $data
  452. * @return void
  453. * @throws \think\Exception
  454. * @throws \think\db\exception\DataNotFoundException
  455. * @throws \think\db\exception\ModelNotFoundException
  456. * @throws \think\exception\DbException
  457. * @throws \think\exception\PDOException
  458. */
  459. public function ProductionSchedulingPause()
  460. {
  461. if (Request::instance()->isPost() === false){
  462. $this->error('请求错误');
  463. }
  464. $data = Request::instance()->post();
  465. if (empty($data)){
  466. $this->error('参数错误');
  467. }
  468. $where = [
  469. 'Gy0_gdbh' => $data['workOrder'],
  470. 'Gy0_sbbh' => ['like','%'.$data['machine'].'%'],
  471. 'Gy0_yjno' => $data['printCode'],
  472. 'Gy0_gxh' => $data['processCode']
  473. ];
  474. $machine = $data['machine'];
  475. $endTime = \db('工单_工艺资料')->where($where)->field('rtrim(Gy0_sj2) as sj2,rtrim(PD_WG) as wg')->find();
  476. if (empty($endTime)){
  477. $this->success('未找到该工序');
  478. }
  479. $time = $endTime['sj2'];
  480. if ($endTime['sj2'] == '1900-01-01 00:00:00' || $endTime['wg'] != '1900-01-01 00:00:00'){
  481. $this->error('该工单不是制程中工单');
  482. }
  483. $sql = \db('工单_工艺资料')
  484. ->where($where)
  485. ->fetchSql(true)
  486. ->update(['Gy0_sj1'=>'1900-01-01 00:00:00','Gy0_sj2'=>'1900-01-01 00:00:00','Mod_rq'=>date('Y-m-d H:i:s')]);
  487. $row = \db('工单_工艺资料')
  488. ->where($where)
  489. ->field('rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_小时产能) as 小时产能,rtrim(Gy0_辅助工时) as 辅助工时')
  490. ->find();
  491. if (empty($row)){
  492. $this->success('未找到该工序');
  493. }
  494. $number = -(int)round($row['计划接货数']/$row['小时产能'])+(int)$row['辅助工时'];
  495. $rechSql = "UPDATE `工单_工艺资料` SET Gy0_sj1 = DATE_ADD(Gy0_sj1, INTERVAL {$number} HOUR),Gy0_sj2 = DATE_ADD(Gy0_sj2, INTERVAL {$number} HOUR) WHERE Gy0_sbbh LIKE '%{$machine}%' AND Gy0_sj1 >= '{$time}' AND Gy0_sj1 < '2099-01-01 00:00:00'";
  496. $rechres = Db::query($rechSql);
  497. $res = Db::query($sql);
  498. if ($res !== false && $rechres !== false){
  499. $this->success('成功');
  500. }else{
  501. $this->error('失败');
  502. }
  503. }
  504. /**
  505. * 工序状态更正
  506. * @ApiMethod (GET)
  507. * @param void $param
  508. * @return void
  509. * @throws \think\db\exception\DataNotFoundException
  510. * @throws \think\db\exception\ModelNotFoundException
  511. * @throws \think\exception\DbException
  512. */
  513. public function ProcessStatusCorrection()
  514. {
  515. if ($this->request->isGet() === false){
  516. $this->error('请求错误');
  517. }
  518. $param = $this->request->param();
  519. if (empty($param)){
  520. $this->error('参数错误');
  521. }
  522. $where = [
  523. 'Gy0_gdbh' => $param['workOrder'],
  524. ];
  525. $workOrder = $where['Gy0_gdbh'];
  526. $field = 'rtrim(Gy0_yjno) as yjno,rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Gy0_sbbh) as 设备代号,rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_ls) as ls,rtrim(PD_WG) as 完工时间,rtrim(UniqId) as UniqId';
  527. $list = \db('工单_工艺资料')->where($where)->field($field)->order('Gy0_yjno,Gy0_gxh')->select();
  528. if (empty($list)){
  529. $this->success('未找到该工单工艺资料');
  530. }
  531. $yieldSql = "SELECT
  532. a.Gy0_yjno AS yjno,
  533. a.Gy0_gxh AS gxh,
  534. SUM( b.sczl_cl ) AS cl
  535. FROM
  536. `工单_工艺资料` AS a
  537. JOIN `设备_产量计酬` AS b ON a.Gy0_gxh = b.sczl_gxh AND a.Gy0_yjno = b.sczl_yjno
  538. WHERE
  539. a.Gy0_gdbh = '{$workOrder}'
  540. GROUP BY
  541. a.Gy0_yjno,a.Gy0_gxh";
  542. $yield = Db::query($yieldSql);
  543. foreach ($list as $key=>$value){
  544. if ($value['yjno']<10){
  545. $value['yjno'] = '0'.$value['yjno'];
  546. }
  547. if ($value['gxh']<10){
  548. $value['gxh'] = '0'.$value['gxh'];
  549. }
  550. $list[$key]['印件及工序'] = $value['yjno'].'-'.$value['gxh'].'-->'.$value['gxmc'];
  551. foreach ($yield as $k=>$v){
  552. if ($v['yjno'] === $list[$key]['yjno']) {
  553. if ($v['gxh'] === $list[$key]['gxh']){
  554. $list[$key]['计划产量/已完成'] = (int)$value['计划接货数'] . '/' . $v['cl'];
  555. if ($value['计划接货数'] !== 0 && $value['计划接货数'] !== '' && !empty($value['计划接货数'])) {
  556. $num = (float)number_format(intval($v['cl']) / intval($value['计划接货数']), 4);
  557. $list[$key]['完成率'] = $num * 100 . '%';
  558. } else {
  559. $list[$key]['完成率'] = '';
  560. }
  561. }else{
  562. $list[$key]['计划产量/已完成'] = $value['计划接货数'].'/0';
  563. $list[$key]['完成率'] = '';
  564. }
  565. }
  566. }
  567. if ($value['完工时间'] == '1900-01-01 00:00:00') {
  568. $list[$key]['完工时间'] = '';
  569. }
  570. unset($list[$key]['yjno'],$list[$key]['gxh'],$list[$key]['gxmc'],$list[$key]['计划接货数'],$list[$key]['ls']);
  571. }
  572. $this->success('成功',$list);
  573. }
  574. /**
  575. * 工序状态更正->工序状态编辑
  576. * @ApiMethod (POST)
  577. * @param void
  578. * @return void
  579. * @throws \think\Exception
  580. * @throws \think\exception\PDOException
  581. */
  582. public function ProcessStatusCorrectionEdit()
  583. {
  584. if (Request::instance()->isPost() === false){
  585. $this->error('请求错误');
  586. }
  587. $param = Request::instance()->post();
  588. if (empty($param)){
  589. $this->error('参数错误');
  590. }
  591. $i = 0;
  592. foreach ($param as $key=>$value){
  593. if ($value['PD_WG'] === null || $value['PD_WG'] === ''){
  594. $endTime = '1900-01-01 00:00:00';
  595. }else{
  596. $endTime = $value['PD_WG'];
  597. }
  598. $sql = \db('工单_工艺资料')
  599. ->where('UniqId',$value['UniqId'])
  600. ->fetchSql(true)
  601. ->update(['PD_WG'=>$endTime]);
  602. $res = Db::query($sql);
  603. if ($res !== false){
  604. $i++;
  605. }
  606. }
  607. if ($i !== 0){
  608. $this->success('成功');
  609. }else{
  610. $this->error('失败');
  611. }
  612. }
  613. /**
  614. * 班次选择
  615. * @ApiMethod (GET)
  616. * @return void
  617. * @throws \think\db\exception\DataNotFoundException
  618. * @throws \think\db\exception\ModelNotFoundException
  619. * @throws \think\exception\DbException
  620. */
  621. public function ScheduleSelection()
  622. {
  623. if ($this->request->isGet() === false){
  624. $this->error('请求错误');
  625. }
  626. $list = \db('工单_排程班次')->field('rtrim(bcdh) as 班次代号,rtrim(desc_) as desc_,rtrim(stdtime) as stdtime')->select();
  627. if (empty($list)){
  628. $this->success('未找到班次数据');
  629. }
  630. foreach ($list as $key=>$value){
  631. $list[$key]['detail'] = $value['班次代号'].'||'.$value['desc_'].'||'.$value['stdtime'];
  632. unset($list[$key]['desc_'],$list[$key]['stdtime']);
  633. }
  634. $this->success('成功',$list);
  635. }
  636. /**
  637. * 车间设备制程展示
  638. * @ApiMethod (GET)
  639. * @param void $param
  640. * @return void
  641. * @throws \think\db\exception\DataNotFoundException
  642. * @throws \think\db\exception\ModelNotFoundException
  643. * @throws \think\exception\DbException
  644. */
  645. public function EquipmentScheduling()
  646. {
  647. if ($this->request->isGet() === false){
  648. $this->error('参数错误');
  649. }
  650. $param = $this->request->param();
  651. if (empty($param)){
  652. $this->error('参数错误');
  653. }
  654. $machine = $param['machine'];
  655. $list = \db('工单_基本资料')
  656. ->alias('a')
  657. ->field([
  658. 'rtrim(b.Gy0_gdbh)' => '工单编号',
  659. 'rtrim(b.Gy0_计划接货数)' => '计划接货数',
  660. 'rtrim(b.Gy0_小时产能)' => '小时产能',
  661. 'rtrim(b.Gy0_生产工时)' => '生产工时',
  662. 'rtrim(b.Gy0_辅助工时)' => '辅助工时',
  663. 'rtrim(b.Gy0_班次安排)' => '班次安排',
  664. 'rtrim(b.工序备注)' => '排单备注',
  665. 'rtrim(b.Gy0_最早开工时间)' => '最早开工时间',
  666. 'rtrim(b.Gy0_sj1)' => '计划开工时间',
  667. 'rtrim(b.Gy0_sj2)' => '计划完工时间',
  668. 'rtrim(b.Gy0_yjno)' => 'yjno',
  669. 'rtrim(b.Gy0_gxh)' => 'gxh',
  670. 'rtrim(b.Gy0_gxmc)' => 'gxmc',
  671. 'rtrim(b.Gy0_ls)' => 'ls',
  672. 'rtrim(b.UniqId)' => 'UniqId',
  673. 'SUM(c.sczl_cl)' => '已完成'
  674. ])
  675. ->join('工单_工艺资料 b','a.Gd_gdbh = b.Gy0_gdbh')
  676. ->join('设备_产量计酬 c','a.Gd_gdbh = c.sczl_gdbh AND b.Gy0_yjno = c.sczl_yjno AND b.Gy0_gxh = c.sczl_gxh','LEFT')
  677. ->where([
  678. 'b.Gy0_sbbh' => $machine,
  679. 'b.Gy0_sj1' => ['>','1900-01-01 00:00:00'],
  680. 'b.PD_WG' => '1900-01-01 00:00:00',
  681. 'a.gd_statu' => '2-生产中'
  682. ])
  683. ->where('b.Gy0_sj1','<','2099-01-01 00:00:00')
  684. ->group('a.Gd_gdbh')
  685. ->select();
  686. foreach ($list as $key=>$value){
  687. $list[$key]['计划接货数'] = (int)round($value['计划接货数']/$value['ls']);
  688. if ($value['yjno']<10){
  689. $value['yjno'] = '0'.$value['yjno'];
  690. }
  691. if ($value['gxh']<10){
  692. $value['gxh'] = '0'.$value['gxh'];
  693. }
  694. $list[$key]['印件/工序'] = $value['yjno'].'-'.$value['gxh'].'-'.$value['gxmc'];
  695. unset($list[$key]['yjno'],$list[$key]['gxh'],$list[$key]['gxmc'],$list[$key]['ls']);
  696. }
  697. $this->success('成功',$list);
  698. }
  699. /**
  700. * 车间设备排程编辑
  701. * @ApiMethod (POST)
  702. * @param void $param
  703. * @return void
  704. * @throws \think\Exception
  705. * @throws \think\exception\PDOException
  706. */
  707. public function EquipmentSchedulingEdit()
  708. {
  709. if (Request::instance()->isPost() === false){
  710. $this->error('请求错误');
  711. }
  712. $param = Request::instance()->post();
  713. if (empty($param)){
  714. $this->error('参数错误');
  715. }
  716. $i = 0;
  717. foreach ($param as $key=>$value){
  718. $data = [
  719. 'Gy0_小时产能' => $value['capacity'],
  720. 'Gy0_生产工时' => $value['ProductionHours'],
  721. 'Gy0_辅助工时' => $value['AuxiliaryHours'],
  722. 'Gy0_班次安排' => $value['shift'],
  723. '工序备注' => $value['remark'],
  724. 'Gy0_最早开工时间' => $value['start'] === ''?'1900-01-01 00:00:00':date('Y-m-d H:i:s',strtotime($value['start'])),
  725. 'Gy0_sj1' => date('Y-m-d H:i:s',strtotime($value['projectTime'])),
  726. // 'Gy0_sj2' => date('Y-m-d H:i:s',strtotime($value['projectTime'])+(ceil($value['ProductionHours'])+ceil($value['AuxiliaryHours']))*3600),
  727. 'Gy0_sj2' => date('Y-m-d H:i:s',strtotime($value['endTime'])),
  728. ];
  729. $sql = \db('工单_工艺资料')
  730. ->where('UniqId',$value['UniqId'])
  731. ->fetchSql(true)
  732. ->update($data);
  733. $res = Db::query($sql);
  734. if ($res !== false){
  735. $i++;
  736. }
  737. }
  738. if ($i !== 0){
  739. $this->success('成功');
  740. }else{
  741. $this->error('失败');
  742. }
  743. }
  744. /**
  745. * 机台工单展示
  746. * @ApiMethod ()
  747. * @return void
  748. * @throws \think\db\exception\BindParamException
  749. * @throws \think\exception\PDOException
  750. */
  751. public function MachineWorkOrderList()
  752. {
  753. if ($this->request->isGet() === false){
  754. $this->error('请求失败');
  755. }
  756. $param = $this->request->param();
  757. if (empty($param)){
  758. $this->error('参数错误');
  759. }
  760. $where = '';
  761. if (isset($param['search'])){
  762. $where = "
  763. b.Gd_gdbh LIKE '%{$param['search']}%'
  764. OR b.`成品名称` LIKE '%{$param['search']}%'
  765. ";
  766. }
  767. $list = \db('工单_工艺资料')
  768. ->alias('a')
  769. ->field([
  770. 'RTRIM( a.Gy0_yjno )' =>'yjno',
  771. 'RTRIM( a.Gy0_gxh )' => 'gxh',
  772. 'RTRIM( a.Gy0_gxmc )' => 'gxmc',
  773. 'RTRIM( a.Add_gxmc )' => 'Add_gxmc',
  774. 'RTRIM( c.yj_yjmc )' => '印件名称',
  775. 'RTRIM( a.`Gy0_计划接货数` )' => '计划接货数',
  776. 'RTRIM( a.`Gy0_小时产能` )' => '小时产能',
  777. 'RTRIM( a.`工价系数` )' => '产能系数',
  778. 'RTRIM( a.`Gy0_生产工时` )' => '生产工时',
  779. 'RTRIM( a.Gy0_ls )' => 'ls',
  780. 'RTRIM( a.`Gy0_辅助工时` )' => '辅助工时',
  781. 'RTRIM( a.`Gy0_最早开工时间` )' => '最早开工时间',
  782. 'RTRIM( a.Gy0_sj1 )' => '计划开工时间',
  783. 'RTRIM( a.Gy0_sj2 )' => '计划完工时间',
  784. 'RTRIM( a.`Gy0_班次安排` )' => '班次安排',
  785. 'RTRIM( a.`工序备注` )' => '排单备注',
  786. 'RTRIM( b.Gd_cpmc )' => '产品名称',
  787. 'RTRIM( b.`成品名称` )' => '成品名称',
  788. 'RTRIM( b.`订单数量` )' => '订单数量',
  789. 'RTRIM( b.`计量单位` )' => '计量单位',
  790. 'RTRIM( b.`交货日期` )' => '交货日期',
  791. 'RTRIM( b.Gd_cpdh )' => '产品代号',
  792. 'RTRIM( b.`成品代号` )' => '成品代号',
  793. 'RTRIM( a.Gy0_sbbh )' => '设备编号',
  794. 'RTRIM( a.Gy0_SITE )' => '车间名称',
  795. 'RTRIM( a.UniqId )' => 'GYUID',
  796. 'RTRIM( b.Uniqid )' => 'UNIQID',
  797. 'SUM( d.sczl_cl )' => '已完成产量',
  798. 'RTRIM( b.Gd_gdbh )' => '工单编号',
  799. 'RTRIM( b.`销售订单号` )' => '销售订单号',
  800. ])
  801. ->join('工单_印件资料 c','c.Yj_Gdbh = a.Gy0_gdbh AND c.yj_Yjno = a.Gy0_yjno')
  802. ->join('工单_基本资料 b','b.Gd_gdbh = a.Gy0_gdbh')
  803. ->join('设备_产量计酬 d','a.Gy0_gdbh = d.sczl_gdbh AND a.Gy0_yjno = d.sczl_yjno AND a.Gy0_gxh = d.sczl_gxh AND a.Gy0_sbbh = d.sczl_jtbh','LEFT')
  804. ->where([
  805. 'b.gd_statu' => '2-生产中',
  806. 'a.Gy0_sbbh' => ['LIKE','%'.$param['machine'].'%'],
  807. 'a.PD_WG' => '1900-01-01 00:00:00',
  808. ])
  809. ->where($where)
  810. ->group('a.Gy0_gdbh,a.Gy0_yjno,a.Gy0_gxh')
  811. ->order('Gy0_sj1')
  812. ->select();
  813. if (empty($list)){
  814. $this->success('',[]);
  815. }
  816. $data['制程'] = $data['排程'] = [];
  817. foreach ($list as $key=>$value){
  818. $list[$key]['设备编号'] = $param['machine'];
  819. if ((int)$value['yjno'] <10){
  820. $value['yjno'] = '0'.rtrim($value['yjno']);
  821. }
  822. if ((int)$value['gxh'] <10){
  823. $value['gxh'] = '0'.rtrim($value['gxh']);
  824. }
  825. if (rtrim($value['Add_gxmc']) == ''){
  826. $list[$key]['印件工序及名称'] = $value['yjno'].'-'.$value['gxh'].'-->'.rtrim($value['gxmc']);
  827. }else{
  828. $list[$key]['印件工序及名称'] = $value['yjno'].'-'.$value['gxh'].'-->'.rtrim($value['gxmc']).'【'.rtrim($value['Add_gxmc']).'】';
  829. }
  830. unset($list[$key]['Add_gxmc']);
  831. if ($value['产品名称'] == ''){
  832. $list[$key]['产品名称'] = $value['成品名称'];
  833. }
  834. if ($value['产品代号'] == ''){
  835. $list[$key]['产品代号'] = $value['成品代号'];
  836. }
  837. unset($list[$key]['成品代号'],$list[$key]['成品名称']);
  838. if ($list[$key]['计划开工时间'] !== '1900-01-01 00:00:00'){
  839. array_push($data['制程'],$list[$key]);
  840. }else{
  841. array_push($data['排程'],$list[$key]);
  842. }
  843. }
  844. $this->success('成功',$data);
  845. }
  846. /**
  847. * 机组调整
  848. * @return void
  849. * @throws \think\Exception
  850. * @throws \think\db\exception\BindParamException
  851. * @throws \think\exception\PDOException
  852. */
  853. public function MachineTeamEdit()
  854. {
  855. if ($this->request->isGet() === false){
  856. $this->error('请求错误');
  857. }
  858. $param = $this->request->param();
  859. if (empty($param) || isset($param['UniqId']) === false){
  860. $this->error('参数错误');
  861. }
  862. $sql = \db('工单_工艺资料')
  863. ->where('UniqId',$param['UniqId'])
  864. ->fetchSql(true)
  865. ->update(['Gy0_sbbh'=>$param['machine']]);
  866. $res = \db()->query($sql);
  867. if ($res !== false){
  868. $this->success('修改成功');
  869. }else{
  870. $this->error('修改失败');
  871. }
  872. }
  873. /**
  874. * 子订单领料派单
  875. * @return void
  876. * @throws \think\db\exception\BindParamException
  877. * @throws \think\exception\PDOException
  878. */
  879. public function processAdd()
  880. {
  881. if (Request::instance()->post() === false){
  882. $this->error('参数错误');
  883. }
  884. $param = Request::instance()->post();
  885. if (empty($param)){
  886. $this->error('参数错误');
  887. }
  888. $data['班组编号'] = $param['班组'];
  889. $data['订单编号'] = $param['订单编号'];
  890. $data['子订单编号'] = $param['子订单编号'];
  891. $data['sys_id'] = $param['Sys_id'];
  892. $data['sys_rq'] = date('Y-m-d H:i:s',time());
  893. $sql = \db('工单_排程班次')->fetchSql(true)->insert($data);
  894. $res = \db()->query($sql);
  895. if ($res !== false){
  896. $this->success('成功');
  897. }else{
  898. $this->error('失败');
  899. }
  900. }
  901. /**
  902. * 月度车间报工汇总-菜单显示
  903. */
  904. public function MachineList() {
  905. // 检查请求是否为 GET
  906. if (!$this->request->isGet()) {
  907. $this->error('请求错误');
  908. }
  909. // 定义要查询的生产工序及排序顺序
  910. $processList = ['裁剪', '车缝', '手工', '大烫', '总检', '包装'];
  911. // 查询所有数据
  912. $results = \db('设备_产量计酬')
  913. ->alias('a')
  914. ->join('设备_基本资料 b', 'a.sczl_jtbh = b.设备编号')
  915. ->field([
  916. 'DATE_FORMAT(a.sczl_rq, "%Y-%m-%d")' => '时间', // 转化为 "YYYY-MM-DD" 格式
  917. 'DATE_FORMAT(a.sczl_rq, "%Y-%m")' => '年月', // 转化为 "YYYY-MM" 格式
  918. 'RTRIM(a.sczl_jtbh)' => '机台编号',
  919. 'b.设备编号',
  920. 'b.设备编组',
  921. 'b.生产工序'
  922. ])
  923. ->whereNull('a.mod_rq') // 筛选无修改日期的数据
  924. ->whereIn('b.生产工序', $processList) // 筛选指定的生产工序
  925. ->order('a.sczl_rq ASC') // 按时间升序排序
  926. ->select();
  927. // 初始化按年月分组的结果
  928. $formattedData = [];
  929. // 遍历查询结果并分组
  930. foreach ($results as $row) {
  931. $yearMonth = $row['年月']; // 获取年月 "YYYY-MM"
  932. $monthDay = substr($row['时间'], 5, 5); // 获取月份和日期 "MM-DD"
  933. $process = $row['生产工序'];
  934. $machineKey = $row['设备编号'] . '--' . $row['设备编组'];
  935. // 初始化年份和工序结构
  936. if (!isset($formattedData[$yearMonth])) {
  937. $formattedData[$yearMonth] = array_fill_keys($processList, []); // 初始化月份,所有工序为空数组
  938. }
  939. if (!isset($formattedData[$yearMonth][$process][$machineKey])) {
  940. $formattedData[$yearMonth][$process][$machineKey] = [];
  941. }
  942. // 添加日期,避免重复
  943. if (!in_array($monthDay, $formattedData[$yearMonth][$process][$machineKey])) {
  944. $formattedData[$yearMonth][$process][$machineKey][] = $monthDay;
  945. }
  946. }
  947. // 对年份和月份进行排序(按年月降序排序)
  948. krsort($formattedData);
  949. // 按生产工序排序
  950. foreach ($formattedData as $yearMonth => &$processData) {
  951. // 1. 确保每个月的工序顺序符合 $processList(即使为空也保留顺序)
  952. $sortedProcessData = array_fill_keys($processList, []);
  953. // 将原有数据合并到排序后的结构中
  954. $processData = array_merge($sortedProcessData, $processData);
  955. // 2. 对每个工序下的设备组进行日期倒序排序
  956. foreach ($processData as $process => &$machines) {
  957. if (is_array($machines)) { // 确保 $machines 是数组
  958. foreach ($machines as $machineKey => &$dates) {
  959. if (is_array($dates) && !empty($dates)) { // 确保 $dates 存在并且是非空数组
  960. rsort($dates); // 每台设备的日期倒序排序
  961. }
  962. }
  963. }
  964. }
  965. }
  966. $this->success('成功', $formattedData);
  967. // // 按生产工序排序
  968. // foreach ($formattedData as $yearMonth => &$processData) {
  969. // // 确保每个月的工序顺序符合 $processList(即使为空也保留顺序)
  970. // $sortedProcessData = array_fill_keys($processList, []);
  971. //
  972. // // 合并原有数据
  973. // foreach ($processData as $process => $machines) {
  974. // $sortedProcessData[$process] = $machines;
  975. // }
  976. //
  977. // // 更新排序后的数据
  978. // $processData = $sortedProcessData;
  979. //
  980. // // 对每组内的设备日期倒序排列
  981. // foreach ($processData as $process => &$machines) {
  982. // foreach ($machines as $machineKey => &$dates) {
  983. // rsort($dates); // 每台设备的日期倒序排序
  984. // }
  985. // }
  986. //
  987. // }
  988. //
  989. // // 返回成功结果
  990. // $this->success('成功', $formattedData);
  991. }
  992. /**
  993. * 月度车间报工汇总-列表数据
  994. */
  995. // public function MachineDetail()
  996. // {
  997. // if ($this->request->isGet() === false) {
  998. // $this->error('请求错误');
  999. // }
  1000. //
  1001. // $param = $this->request->param();
  1002. // if (empty($param)) {
  1003. // $this->error('参数错误');
  1004. // }
  1005. //
  1006. // $where = [];
  1007. //
  1008. // // 获取当前年份
  1009. // $currentYear = date('Y');
  1010. //
  1011. // // 处理日期参数(可选)
  1012. // if (!empty($param['date'])) {
  1013. // if (preg_match('/^\d{4}-\d{2}$/', $param['date'])) {
  1014. // $where['a.sys_rq'] = ['like', "{$param['date']}%"];
  1015. // } elseif (preg_match('/^\d{2}-\d{2}$/', $param['date'])) {
  1016. // $monthDay = $param['date'];
  1017. // $where['a.sys_rq'] = ['like', "%-$monthDay%"];
  1018. // } elseif (preg_match('/^\d{2}$/', $param['date'])) {
  1019. // $where['a.sys_rq'] = ['like', "{$currentYear}-{$param['date']}%"];
  1020. // }
  1021. // }
  1022. //
  1023. // // 订单编号筛选
  1024. // if (!empty($param['order'])) {
  1025. // $where['b.订单编号|b.款号|b.子订单编号'] = ['like', '%' . $param['order'] . '%'];
  1026. // }
  1027. //
  1028. // // 机台号筛选
  1029. // if (!empty($param['machine'])) {
  1030. // $machineMapping = [
  1031. // '裁剪' => 'CQ', '车缝' => 'CF', '手工' => 'HD',
  1032. // '大烫' => 'DT', '总检' => 'ZJ', '包装' => 'BZ'
  1033. // ];
  1034. //
  1035. // if (isset($machineMapping[$param['machine']])) {
  1036. // $where['a.sczl_jtbh'] = ['like', '%' . $machineMapping[$param['machine']] . '%'];
  1037. // } elseif (preg_match('/^\d{4}-\d{2}$/', $param['machine'])) {
  1038. // $where['a.sczl_jtbh'] = ''; // 若为日期格式,清空该字段
  1039. // } else {
  1040. // $where['a.sczl_jtbh'] = $param['machine'];
  1041. // }
  1042. // }
  1043. //
  1044. // // 查询数据
  1045. // $list = \db('设备_产量计酬')->alias('a')
  1046. // ->join('工单_印件资料 b', 'b.订单编号 = a.订单编号 AND a.子订单编号 = a.子订单编号')
  1047. // ->join('工单_基本资料 j', 'b.订单编号 = j.订单编号', 'LEFT')
  1048. // ->field('
  1049. // a.工序名称, b.订单编号, b.子订单编号, b.款号, b.颜色, b.船样, a.尺码, b.zdtotal as 制单数, b.颜色备注,
  1050. // a.数量, MIN(a.sys_rq) as 上报时间, a.UniqId,
  1051. // j.客户编号, j.生产款号, j.款式
  1052. // ')
  1053. // ->where($where)
  1054. // ->where('a.mod_rq', null)
  1055. // ->order('a.sys_rq desc, a.UniqId desc')
  1056. // ->group('a.UniqId')
  1057. // ->select();
  1058. //
  1059. // // 提取所有的尺码,并去重,去除空格
  1060. // $sizeList = array_values(array_unique(array_map('trim', array_column($list, '尺码'))));
  1061. //
  1062. // // 自定义排序规则(已存在的排序逻辑)
  1063. // $sizeOrder = ['XXS', 'XS', 'S', 'M', 'L', 'XL', 'XXL', 'XXXL', 'XXXXL'];
  1064. // usort($sizeList, function ($a, $b) use ($sizeOrder) {
  1065. // // 数字优先比较
  1066. // if (is_numeric($a) && is_numeric($b)) {
  1067. // return $a - $b;
  1068. // }
  1069. // if (in_array($a, $sizeOrder) && in_array($b, $sizeOrder)) {
  1070. // return array_search($a, $sizeOrder) - array_search($b, $sizeOrder);
  1071. // }
  1072. // if (is_numeric($a)) return -1;
  1073. // if (is_numeric($b)) return 1;
  1074. //
  1075. // return strcmp($a, $b);
  1076. // });
  1077. //
  1078. // // 不合并相同的子订单编号,而是按 "子订单编号 + 工序名称" 作为唯一键
  1079. // $mergedList = [];
  1080. // foreach ($list as $item) {
  1081. // $uniqueKey = $item['子订单编号'] . '-' . $item['工序名称']; // 关键点:加入工序名称
  1082. //
  1083. // if (!isset($mergedList[$uniqueKey])) {
  1084. // $mergedList[$uniqueKey] = $item;
  1085. // } else {
  1086. // // 汇总数量
  1087. // foreach ($sizeList as $size) {
  1088. // // 如果当前行有这个尺码,累加数量
  1089. // if (isset($item['尺码']) && $item['尺码'] == $size) {
  1090. // $mergedList[$uniqueKey][$size] = isset($mergedList[$uniqueKey][$size])
  1091. // ? $mergedList[$uniqueKey][$size] + $item['数量']
  1092. // : $item['数量'];
  1093. // }
  1094. // }
  1095. // }
  1096. // }
  1097. //
  1098. // // 转换合并后的数组为列表
  1099. // $finalList = array_values($mergedList);
  1100. //
  1101. // // 将合并后的结果转换为列表形式
  1102. // $finalList = array_values($mergedList);
  1103. //
  1104. // // 返回结果
  1105. // $this->success('请求成功', [
  1106. // 'table' => $finalList,
  1107. // 'length' => count($finalList),
  1108. // 'headers' => $sizeList // 返回所有的尺码作为表头
  1109. // ]);
  1110. // }
  1111. /**
  1112. * 月度车间报工汇总-列表详情数据
  1113. */
  1114. public function MachineDetail()
  1115. {
  1116. if ($this->request->isGet() === false) {
  1117. $this->error('请求错误');
  1118. }
  1119. $param = $this->request->param();
  1120. if (empty($param)) {
  1121. $this->error('参数错误');
  1122. }
  1123. $where = [];
  1124. // 获取当前年份
  1125. $currentYear = date('Y');
  1126. // 处理日期参数(可选)
  1127. if (!empty($param['date'])) {
  1128. // 日期参数的格式处理
  1129. if (preg_match('/^\d{4}-\d{2}$/', $param['date'])) {
  1130. $where['a.sys_rq'] = ['like', "{$param['date']}%"];
  1131. } elseif (preg_match('/^\d{2}-\d{2}$/', $param['date'])) {
  1132. $monthDay = $param['date'];
  1133. $where['a.sys_rq'] = ['like', "%-$monthDay%"];
  1134. } elseif (preg_match('/^\d{2}$/', $param['date'])) {
  1135. $where['a.sys_rq'] = ['like', "{$currentYear}-{$param['date']}%"];
  1136. }
  1137. }
  1138. // 订单编号筛选
  1139. if (!empty($param['order'])) {
  1140. $where['b.订单编号|b.款号|b.子订单编号'] = ['like', '%' . $param['order'] . '%'];
  1141. }
  1142. // 机台号筛选
  1143. if (!empty($param['machine'])) {
  1144. // 针对机台号的特定条件判断
  1145. $machineMapping = [
  1146. '裁剪' => 'CQ', '车缝' => 'CF', '手工' => 'HD',
  1147. '大烫' => 'DT', '总检' => 'ZJ', '包装' => 'BZ'
  1148. ];
  1149. if (isset($machineMapping[$param['machine']])) {
  1150. $where['a.sczl_jtbh'] = ['like', '%' . $machineMapping[$param['machine']] . '%'];
  1151. } elseif (preg_match('/^\d{4}-\d{2}$/', $param['machine'])) {
  1152. $where['a.sczl_jtbh'] = ''; // 若为日期格式,清空该字段
  1153. } else {
  1154. $where['a.sczl_jtbh'] = $param['machine'];
  1155. }
  1156. }
  1157. // 查询数据
  1158. $list = \db('设备_产量计酬')->alias('a')
  1159. ->join('工单_印件资料 b', 'b.订单编号 = a.订单编号 AND a.子订单编号 = a.子订单编号')
  1160. ->join('工单_基本资料 j', 'b.订单编号 = j.订单编号', 'LEFT')
  1161. ->field('
  1162. a.工序名称, b.订单编号, b.子订单编号, b.款号, b.颜色, b.船样, a.尺码, b.zdtotal as 制单数, b.颜色备注,
  1163. a.数量, MIN(a.sys_rq) as 上报时间, a.UniqId,
  1164. j.客户编号, j.生产款号, j.款式
  1165. ')
  1166. ->where($where)
  1167. ->where('a.mod_rq', null)
  1168. ->order('a.sys_rq desc, a.UniqId desc')
  1169. ->group('a.UniqId')
  1170. ->select();
  1171. // 提取所有的尺码,并去重,去除空格
  1172. $sizeList = array_values(array_unique(array_map('trim', array_column($list, '尺码'))));
  1173. // 自定义排序规则(已存在的排序逻辑)
  1174. $sizeOrder = ['XXS', 'XS', 'S', 'M', 'L', 'XL', 'XXL', 'XXXL', 'XXXXL'];
  1175. usort($sizeList, function ($a, $b) use ($sizeOrder) {
  1176. // 数字优先比较
  1177. if (is_numeric($a) && is_numeric($b)) {
  1178. return $a - $b;
  1179. }
  1180. if (in_array($a, $sizeOrder) && in_array($b, $sizeOrder)) {
  1181. return array_search($a, $sizeOrder) - array_search($b, $sizeOrder);
  1182. }
  1183. if (is_numeric($a)) return -1;
  1184. if (is_numeric($b)) return 1;
  1185. return strcmp($a, $b);
  1186. });
  1187. // 动态将尺码的数量添加到每个订单中,并替换已完成字段
  1188. foreach ($list as &$item) {
  1189. $size = $item['尺码'];
  1190. $item[$size] = $item['数量'];
  1191. }
  1192. // 返回结果
  1193. $this->success('请求成功', [
  1194. 'table' => $list,
  1195. 'length' => count($list),
  1196. 'headers' => $sizeList // 返回所有的尺码作为表头
  1197. ]);
  1198. }
  1199. // public function MachineDetail()
  1200. // {
  1201. // if ($this->request->isGet() === false) {$this->error('请求错误');}
  1202. // $param = $this->request->param();
  1203. // if (empty($param)) {$this->error('参数错误');}
  1204. //
  1205. // $where = [];
  1206. //
  1207. // // 获取当前年份
  1208. // $currentYear = date('Y');
  1209. //
  1210. // // 处理日期参数(可选)
  1211. // if (!empty($param['date'])) {
  1212. // // 检查 `date` 的格式是否为 "YYYY-MM"、"MM-DD" 或仅为月份 "MM"
  1213. // if (preg_match('/^\d{4}-\d{2}$/', $param['date'])) {
  1214. // // 如果格式为 "YYYY-MM",查询当月数据
  1215. // $where['a.sys_rq'] = ['like', "{$param['date']}%"];
  1216. // } elseif (preg_match('/^\d{2}-\d{2}$/', $param['date'])) {
  1217. // // 如果格式为 "MM-DD",查询指定的月份和日期
  1218. // $monthDay = $param['date'];
  1219. // $where['a.sys_rq'] = ['like', "%-$monthDay%"];
  1220. // } elseif (preg_match('/^\d{2}$/', $param['date'])) {
  1221. // // 如果格式为 "MM"(仅月份),自动补全为 "YYYY-MM"
  1222. // $where['a.sys_rq'] = ['like', "{$currentYear}-{$param['date']}%"];
  1223. // }
  1224. // }
  1225. //
  1226. // // 判断是否传入订单编号参数(可选)
  1227. // if (!empty($param['order'])) {
  1228. // $where['b.订单编号|b.款号|b.子订单编号'] = ['like', '%' . $param['order'] . '%'];
  1229. // }
  1230. //
  1231. // // 处理机台号参数(可选)
  1232. // if (!empty($param['machine'])) {
  1233. // // 判断是否为年-月格式(2025-02)
  1234. // if (preg_match('/^\d{4}-\d{2}$/', $param['machine'])) {
  1235. // // 如果是日期格式,则设为空
  1236. // $where['a.sczl_jtbh'] = '';
  1237. // } else {
  1238. // // 如果不是日期格式,则正常赋值
  1239. // $where['a.sczl_jtbh'] = $param['machine'];
  1240. // }
  1241. // }
  1242. //
  1243. // if($param['machine'] === '裁剪'){
  1244. // $where['a.sczl_jtbh'] = ['like', '%' . 'CQ' . '%'];
  1245. // }else if($param['machine'] === '车缝'){
  1246. // $where['a.sczl_jtbh'] = ['like', '%' . 'CF' . '%'];
  1247. // }else if($param['machine'] === '手工'){
  1248. // $where['a.sczl_jtbh'] = ['like', '%' . 'HD' . '%'];
  1249. // }else if($param['machine'] === '大烫'){
  1250. // $where['a.sczl_jtbh'] = ['like', '%' . 'DT' . '%'];
  1251. // }else if($param['machine'] === '总检'){
  1252. // $where['a.sczl_jtbh'] = ['like', '%' . 'ZJ' . '%'];
  1253. // }else if($param['machine'] === '包装'){
  1254. // $where['a.sczl_jtbh'] = ['like', '%' . 'BZ' . '%'];
  1255. // }
  1256. //
  1257. //
  1258. // // 查询数据
  1259. // $list = \db('设备_产量计酬')->alias('a')
  1260. // ->join('工单_印件资料 b', 'b.订单编号 = a.订单编号 AND a.子订单编号 = a.子订单编号')
  1261. // ->join('工单_基本资料 j', 'b.订单编号 = j.订单编号', 'LEFT')
  1262. // ->field('
  1263. // a.工序名称,b.订单编号, b.子订单编号, b.款号, b.颜色, b.船样, a.尺码, b.zdtotal as 制单数, b.颜色备注,
  1264. // a.数量, MIN(a.sys_rq) as 上报时间, a.UniqId,
  1265. // j.客户编号, j.生产款号, j.款式
  1266. // ')
  1267. // ->where($where)
  1268. // ->where('a.mod_rq', null)
  1269. // ->order('a.sys_rq desc, a.UniqId desc')
  1270. // ->group('a.UniqId')
  1271. // ->select();
  1272. //
  1273. // // 提取所有的尺码,并去重
  1274. // $sizeList = array_values(array_unique(array_column($list, '尺码')));
  1275. //
  1276. // // **自定义排序规则**
  1277. // $sizeOrder = ['XXS', 'XS', 'S', 'M', 'L', 'XL', 'XXL']; // 定义字母尺码的顺序
  1278. //
  1279. // usort($sizeList, function ($a, $b) use ($sizeOrder) {
  1280. // // 如果是数字,直接比较大小
  1281. // if (is_numeric($a) && is_numeric($b)) {
  1282. // return $a - $b;
  1283. // }
  1284. // // 如果是字母,按 $sizeOrder 的索引排序
  1285. // if (in_array($a, $sizeOrder) && in_array($b, $sizeOrder)) {
  1286. // return array_search($a, $sizeOrder) - array_search($b, $sizeOrder);
  1287. // }
  1288. // // 如果一个是数字,一个是字母,数字排在前面
  1289. // if (is_numeric($a)) return -1;
  1290. // if (is_numeric($b)) return 1;
  1291. //
  1292. // // 如果都不符合,按字典顺序(备用)
  1293. // return strcmp($a, $b);
  1294. // });
  1295. //
  1296. // // 动态将尺码的数量添加到每个订单中,并替换已完成字段
  1297. // foreach ($list as &$item) {
  1298. // $size = $item['尺码'];
  1299. // $item[$size] = $item['数量'];
  1300. // // unset($item['数量']); // 如果不需要保留原字段,可以取消注释
  1301. // }
  1302. //
  1303. // // 返回结果
  1304. // $this->success('请求成功', [
  1305. // 'table' => $list,
  1306. // 'length' => count($list),
  1307. // 'headers' => $sizeList // 返回所有的尺码作为表头
  1308. // ]);
  1309. // }
  1310. /**
  1311. * 工单审核
  1312. * @return void
  1313. * @throws \think\Exception
  1314. * @throws \think\db\exception\BindParamException
  1315. * @throws \think\exception\PDOException
  1316. */
  1317. public function Approval()
  1318. {
  1319. if ($this->request->isPost() === false) {
  1320. $this->error('请求错误');
  1321. }
  1322. $param = Request::instance()->post();
  1323. if (empty($param)) {
  1324. $this->error('参数错误');
  1325. }
  1326. // 判断sys_id是否为多个,多个以逗号分隔
  1327. $sys_ids = strpos($param['sys_id'], ',') !== false ? explode(',', $param['sys_id']) : [$param['sys_id']];
  1328. $data['审核日期'] = date('Y-m-d H:i:s');
  1329. // 遍历所有sys_id进行更新
  1330. foreach ($sys_ids as $sys_id) {
  1331. $data['审核'] = $sys_id;
  1332. $sql = \db('工单_基本资料')
  1333. ->where('Uniqid', $param['Uniqid'])
  1334. ->fetchSql(true)
  1335. ->update($data);
  1336. // 执行SQL语句
  1337. $res = \db()->query($sql);
  1338. if ($res === false) {
  1339. $this->error('审核失败');
  1340. }
  1341. }
  1342. $this->success('审核成功');
  1343. }
  1344. /**
  1345. * 订单未审核列表
  1346. * @return void
  1347. * @throws \think\db\exception\DataNotFoundException
  1348. * @throws \think\db\exception\ModelNotFoundException
  1349. * @throws \think\exception\DbException
  1350. */
  1351. public function UnapprovalList()
  1352. {
  1353. if ($this->request->isGet() === false){
  1354. $this->error('请求错误');
  1355. }
  1356. $param = $this->request->param();
  1357. if (isset($param)){
  1358. $where['订单编号|生产款号'] = ['like','%'.$param['search'].'%'];
  1359. }
  1360. // $where['审核'] = null;
  1361. // $where['审核日期'] = null;
  1362. $where['Mod_rq'] = null;
  1363. $list = \db('工单_基本资料')
  1364. ->where($where)
  1365. ->orderRaw("FIELD(gd_statu, '1-计划中', '2-生产中')")
  1366. ->order('订单编号 desc')
  1367. ->select();
  1368. // 提取所有订单编号
  1369. $orderIds = array_column($list, '订单编号');
  1370. // 查询相关附件中是否存在这些订单编号
  1371. $relatedOrders = \db('工单_相关附件')
  1372. ->whereIn('关联编号', $orderIds)
  1373. ->whereIn('附件备注', '技术附件')
  1374. ->column('关联编号');
  1375. $orderAttachments = \db('工单_相关附件')
  1376. ->whereIn('关联编号', $orderIds)
  1377. ->whereIn('附件备注', '订单资料附件')
  1378. ->column('关联编号');
  1379. // 遍历数据,为每个订单设置 status,并替换字段名
  1380. foreach ($list as &$value) {
  1381. // 设置订单状态
  1382. if (in_array($value['订单编号'], $relatedOrders)) {
  1383. $value['status'] = '';
  1384. } else {
  1385. $value['status'] = '*';
  1386. }
  1387. if (in_array($value['订单编号'], $orderAttachments)) {
  1388. $value['orderstatus'] = '';
  1389. } else {
  1390. $value['orderstatus'] = '*';
  1391. }
  1392. // 将「工单入仓数量」字段替换为「工单完工数量」
  1393. if (isset($value['工单入仓数量'])) {
  1394. $value['工单完工数量'] = $value['工单入仓数量'];
  1395. unset($value['工单入仓数量']);
  1396. }
  1397. }
  1398. $data['total'] = count($list);
  1399. $data['table'] = $list;
  1400. $this->success('成功',$data);
  1401. }
  1402. // public function UnapprovalList()
  1403. // {
  1404. // if ($this->request->isGet() === false){
  1405. // $this->error('请求错误');
  1406. // }
  1407. //
  1408. // $param = $this->request->param();
  1409. // if (isset($param)){
  1410. // $where['订单编号|生产款号'] = ['like','%'.$param['search'].'%'];
  1411. // }
  1412. //
  1413. // // 其他条件
  1414. // $where['Mod_rq'] = null;
  1415. //
  1416. // // 查询工单基本资料
  1417. // $list = \db('工单_基本资料')
  1418. // ->where($where)
  1419. // ->orderRaw("FIELD(gd_statu, '1-计划中', '2-生产中')")
  1420. // ->order('订单编号 desc')
  1421. // ->select();
  1422. //
  1423. // // 提取所有订单编号
  1424. // $orderIds = array_column($list, '订单编号');
  1425. //
  1426. // // 查询相关附件(技术附件和订单附件)
  1427. // $relatedOrders = \db('工单_相关附件')
  1428. // ->whereIn('关联编号', $orderIds)
  1429. // ->whereIn('附件备注', ['技术附件', '订单资料附件']) // 查询技术附件和订单附件
  1430. // ->select();
  1431. //
  1432. // $techAttachments = []; // 存储技术附件的订单编号
  1433. // $orderAttachments = []; // 存储订单附件的订单编号
  1434. // foreach ($relatedOrders as $attachment) {
  1435. // if ($attachment['附件备注'] == '技术附件') {
  1436. // $techAttachments[] = $attachment['关联编号'];
  1437. // } elseif ($attachment['附件备注'] == '订单资料附件') {
  1438. // $orderAttachments[] = $attachment['关联编号'];
  1439. // }
  1440. // }
  1441. // // 遍历工单基本资料,设置相应的状态
  1442. // foreach ($list as &$value) {
  1443. // // 判断是否是技术附件相关的订单
  1444. // if (in_array($value['订单编号'], $techAttachments)) {
  1445. // $value['status'] = ''; // 技术附件的状态为空
  1446. // } else {
  1447. // $value['status'] = '*'; // 没有技术附件的订单状态为 *
  1448. // }
  1449. // // 判断是否是订单附件相关的订单
  1450. // if (in_array($value['订单编号'], $orderAttachments)) {
  1451. // $value['orderstatus'] = ''; // 订单附件的状态为空
  1452. // } else {
  1453. // $value['orderstatus'] = '*'; // 没有订单附件的订单状态为 *
  1454. // }
  1455. // // 将「工单入仓数量」字段替换为「工单完工数量」
  1456. // if (isset($value['工单入仓数量'])) {
  1457. // $value['工单完工数量'] = $value['工单入仓数量'];
  1458. // unset($value['工单入仓数量']);
  1459. // }
  1460. // }
  1461. //
  1462. // // 返回成功的结果
  1463. // $data['total'] = count($list);
  1464. // $data['table'] = $list;
  1465. // $this->success('成功', $data);
  1466. // }
  1467. /**
  1468. * 月度客户订单汇总
  1469. */
  1470. public function OrderYieldList(){
  1471. // 获取前端传来的参数
  1472. $param = $this->request->param();
  1473. // 初始化查询条件
  1474. $where = [];
  1475. // 处理搜索条件
  1476. if (isset($param['search']) && !empty($param['search'])) {
  1477. $where['j.订单编号|j.生产款号'] = ['like', '%' . $param['search'] . '%'];
  1478. }
  1479. if (isset($param['client']) && !empty($param['client'])) {
  1480. $where['j.客户编号'] = $param['client'];
  1481. }
  1482. if (isset($param['date']) && !empty($param['date'])) {
  1483. $year = substr($param['date'], 0, 4);
  1484. $month = substr($param['date'], 4, 2);
  1485. $where['j.Sys_rq'] = ['like', "$year-$month%"];
  1486. }
  1487. // 只查询生产中的工单
  1488. // $where['j.gd_statu'] = '2-生产中';
  1489. $where['j.Mod_rq'] = null;
  1490. // 执行查询
  1491. $orderList = \db('工单_基本资料')->alias('j')
  1492. ->join('工单_印件资料 y', 'j.订单编号 = y.订单编号')
  1493. ->field('j.Sys_rq, y.订单编号, j.落货日期, j.生产款号, j.款式, SUM(y.sctotal) as 裁剪总数, SUM(y.zdtotal) as 制单总数,j.gd_statu,j.客户编号')
  1494. ->group('y.订单编号')
  1495. ->where($where)
  1496. ->select();
  1497. $orderIds = array_column($orderList, '订单编号');
  1498. // 通过订单编号关联设备_产量计酬表,获取工序名称和数量,并进行分组和汇总
  1499. $wheres['a.mod_rq'] = null;
  1500. $processList = \db('设备_产量计酬')
  1501. ->alias('a')
  1502. ->join('工单_基本资料 j', 'a.订单编号 = j.订单编号')
  1503. ->whereIn('a.订单编号', $orderIds) // 只查询符合条件的订单编号
  1504. ->field('a.订单编号, a.工序名称, SUM(a.数量) as 总数量,SUM(a.s_num) as 上报数量,a.mod_rq')
  1505. ->where($wheres)
  1506. ->group('a.订单编号, a.工序名称') // 按订单编号和工序名称分组
  1507. ->select();
  1508. // 合并两个结果
  1509. $data = [];
  1510. foreach ($orderList as $key => $order) {
  1511. // 去掉落货日期的时间部分,只保留日期
  1512. $orderDate = substr($order['落货日期'], 0, 10); // 提取前10位
  1513. //放入结果
  1514. $data[$key] = [
  1515. '订单编号' => $order['订单编号'],
  1516. '落货日期' => $order['落货日期'],
  1517. '生产款号' => $order['生产款号'],
  1518. '款式' => $order['款式'],
  1519. '客户编号' => $order['客户编号'],
  1520. '订单状态' => $order['gd_statu'],
  1521. '裁剪总数' => $order['裁剪总数'],
  1522. '制单总数' => $order['制单总数'],
  1523. ];
  1524. //找到该订单编号对应的工序名称和数量
  1525. //裁剪、车缝计算数量,其他计算s_num合计
  1526. foreach ($processList as $process) {
  1527. if($process['工序名称'] == '裁剪' || $process['工序名称'] == '车缝'){
  1528. if ($process['订单编号'] === $order['订单编号']) {
  1529. // 将工序名称和数量加入到结果中
  1530. $data[$key][$process['工序名称']] = $process['总数量'];
  1531. }
  1532. }else{
  1533. if ($process['订单编号'] === $order['订单编号']) {
  1534. // 将工序名称和数量加入到结果中
  1535. $data[$key][$process['工序名称']] = $process['上报数量'];
  1536. }
  1537. }
  1538. }
  1539. }
  1540. // 返回最终结果
  1541. $this->success('成功', $data);
  1542. }
  1543. /**
  1544. * 订单状态及样衣批核-左侧菜单
  1545. */
  1546. public function dateList()
  1547. {
  1548. }
  1549. /**
  1550. * 车缝派单菜单
  1551. * @return void
  1552. */
  1553. public function CfmachineList()
  1554. {
  1555. if ($this->request->isGet() === false) {
  1556. $this->error('请求错误');
  1557. }
  1558. // 查询所有生产工序为"车缝"的设备编号和设备编组
  1559. $machineList = \db('设备_基本资料')
  1560. ->where('生产工序', '车缝')
  1561. ->field('设备编号, 设备编组')
  1562. ->order('设备编号') // 按设备编号排序
  1563. ->select();
  1564. $result = [];
  1565. foreach ($machineList as $machine) {
  1566. $machineCode = $machine['设备编号'];
  1567. $machineGroup = $machine['设备编组'];
  1568. // 查询该设备编号在 设备_产量计酬 表中的订单编号及日期
  1569. $orders = \db('设备_产量计酬')
  1570. ->where('sczl_jtbh', $machineCode)
  1571. ->where('mod_rq', null)
  1572. ->order('sys_rq asc') // 按生产日期升序排序
  1573. ->select();
  1574. // 根据月份分组统计订单数量
  1575. $monthlyOrders = [];
  1576. foreach ($orders as $order) {
  1577. $yearMonth = date('Ym', strtotime($order['sys_rq']));
  1578. if (!isset($monthlyOrders[$yearMonth])) {
  1579. $monthlyOrders[$yearMonth] = [];
  1580. }
  1581. $monthlyOrders[$yearMonth][] = $order['订单编号'];
  1582. }
  1583. // 构建返回数据,格式为:设备编号【设备编组 生产中:工单数量】
  1584. foreach ($monthlyOrders as $yearMonth => $orderList) {
  1585. $workOrderCount = count(array_unique($orderList));
  1586. if (!isset($result[$yearMonth])) {
  1587. $result[$yearMonth] = [];
  1588. }
  1589. // 使用集合来去重设备编号
  1590. $deviceKey = $machineCode . '【' . $machineGroup . ' 生产中:' . $workOrderCount . '】';
  1591. if (!in_array($deviceKey, $result[$yearMonth])) {
  1592. $result[$yearMonth][] = $deviceKey;
  1593. }
  1594. }
  1595. }
  1596. // 按月份排序,确保最新的月份在前面
  1597. krsort($result);
  1598. $this->success('成功', $result);
  1599. }
  1600. /**
  1601. * 车缝派单列表
  1602. */
  1603. public function CfdataList()
  1604. {
  1605. if ($this->request->isGet() === false) {
  1606. $this->error('请求错误');
  1607. }
  1608. $param = $this->request->param();
  1609. if (empty($param['machine']) || empty($param['date'])) {
  1610. $this->error('参数错误');
  1611. }
  1612. // 将传入的 YYYYMM 格式日期转换为 YYYY-MM-01
  1613. $year = substr($param['date'], 0, 4);
  1614. $month = substr($param['date'], 4, 2);
  1615. $startDate = "$year-$month-01 00:00:00";
  1616. $endDate = date("Y-m-t 23:59:59", strtotime($startDate)); // 获取该月的最后一天
  1617. // 查询设备产量计酬与工单基本资料的关联数据
  1618. $list = \db('设备_产量计酬')->alias('c')
  1619. ->join('工单_基本资料 j', 'c.订单编号 = j.订单编号', 'left')
  1620. ->where('c.sczl_jtbh', $param['machine'])
  1621. ->where('c.mod_rq', null)
  1622. ->where('c.sczl_rq', '>=', $startDate)
  1623. ->where('c.sczl_rq', '<=', $endDate)
  1624. ->field('
  1625. c.订单编号, c.款号 as 生产款号, j.款式, j.客户编号, j.订单数量,
  1626. LEFT(j.落货日期, 10) as 落货日期,j.工单入仓数量 as 工单完工数量,j.订单数量,
  1627. c.sczl_rq as 创建时间, j.gd_statu as 工单状态
  1628. ')
  1629. ->group('c.订单编号')
  1630. ->select();
  1631. // 返回数组结果
  1632. $this->success('请求成功', ['table' => $list, 'length' => count($list)]);
  1633. }
  1634. //
  1635. // /**车缝派单菜单
  1636. // * @return void
  1637. // */
  1638. // public function CfmachineList()
  1639. // {
  1640. // if ($this->request->isGet() === false) {
  1641. // $this->error('请求错误');
  1642. // }
  1643. //
  1644. // // 查询所有生产工序为"车缝"的设备编号和设备编组
  1645. // $machineList = \db('设备_基本资料')
  1646. // ->where('生产工序', '车缝')
  1647. // ->field('设备编号, 设备编组')
  1648. // ->order('设备编号') // 按设备编号排序
  1649. // ->select();
  1650. //
  1651. // $result = [];
  1652. // $addedMachineCodes = []; // 用于跟踪已经添加的设备编号
  1653. //
  1654. // foreach ($machineList as $machine) {
  1655. // $machineCode = $machine['设备编号'];
  1656. // $machineGroup = $machine['设备编组'];
  1657. //
  1658. // // 检查是否已经添加过该设备编号
  1659. // if (in_array($machineCode, $addedMachineCodes)) {
  1660. // continue; // 跳过已添加的设备
  1661. // }
  1662. //
  1663. // // 查询该设备编号在 设备_产量计酬 表中的订单编号
  1664. // $orders = \db('设备_产量计酬')
  1665. // ->where('sczl_jtbh', $machineCode)
  1666. // ->order('sys_rq desc')
  1667. // ->where('mod_rq', null)
  1668. // ->column('订单编号');
  1669. //
  1670. // // 去重统计订单编号数量
  1671. // $workOrderCount = count(array_unique($orders));
  1672. //
  1673. // // 构建返回数据,格式为:设备编号【设备编组 生产中:工单数量】
  1674. // $result[] = $machineCode . '【' . $machineGroup . ' 生产中:' . $workOrderCount . '】';
  1675. //
  1676. // // 将设备编号添加到跟踪数组中
  1677. // $addedMachineCodes[] = $machineCode;
  1678. // }
  1679. //
  1680. // $yearMonth = date('Ym');
  1681. // $finalResult = [
  1682. // $yearMonth => $result
  1683. // ];
  1684. //
  1685. // $this->success('成功', $finalResult);
  1686. // }
  1687. //
  1688. //
  1689. // /**
  1690. // * 车缝派单列表
  1691. // */
  1692. // public function CfdataList()
  1693. // {
  1694. // if ($this->request->isGet() === false) {
  1695. // $this->error('请求错误');
  1696. // }
  1697. //
  1698. // $param = $this->request->param();
  1699. // if (empty($param)) {
  1700. // $this->error('参数错误');
  1701. // }
  1702. //
  1703. // // 查询设备产量计酬与工单基本资料的关联数据
  1704. // $list = \db('设备_产量计酬')->alias('c')
  1705. // ->join('工单_基本资料 j', 'c.订单编号 = j.订单编号', 'left')
  1706. // ->where('c.sczl_jtbh', $param['machine'])
  1707. // ->where('c.mod_rq', null)
  1708. // ->field('
  1709. // c.订单编号, c.款号, j.款式, j.客户编号, j.订单数量,
  1710. // LEFT(j.落货日期, 10) as 落货日期,
  1711. // j.Sys_rq as 创建时间, j.gd_statu as 工单状态
  1712. // ')
  1713. // ->group('c.订单编号')
  1714. // ->select();
  1715. //
  1716. //
  1717. // // 返回数组结果
  1718. // $this->success('请求成功', ['table' => $list, 'length' => count($list)]);
  1719. // }
  1720. //车缝派单删除
  1721. public function CfdataDel()
  1722. {
  1723. if ($this->request->isGet() === false)
  1724. {
  1725. $this->error('请求错误');
  1726. }
  1727. $param = $this->request->param();
  1728. if (empty($param)){
  1729. $this->error('参数错误');
  1730. }
  1731. $sql = \db('工单_排程班次')
  1732. ->where('UniqId',$param['UniqId'])
  1733. ->fetchSql(true)
  1734. ->update(['mod_rq'=>date('Y-m-d H:i:s',time())]);
  1735. $res = \db()->query($sql);
  1736. if ($res !== false){
  1737. $this->success('删除成功');
  1738. }else{
  1739. $this->error('删除失败');
  1740. }
  1741. }
  1742. //车缝派单数据
  1743. public function CfdataAllList()
  1744. {
  1745. if ($this->request->isGet() === false){
  1746. $this->error('请求错误');
  1747. }
  1748. $list = \db('工单_排程班次')
  1749. ->where('mod_rq',null)
  1750. ->order('sys_rq desc')
  1751. ->field('订单编号,子订单编号,班组编号,sys_rq as 创建时间,sys_id as 创建人员,UniqId')
  1752. ->group('子订单编号')
  1753. ->select();
  1754. $this->success('成功',$list);
  1755. }
  1756. }