WorkOrder.php 100 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use Monolog\Handler\IFTTTHandler;
  5. use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
  6. use think\Db;
  7. use think\Request;
  8. use PhpOffice\PhpSpreadsheet\IOFactory;
  9. /**
  10. * 工单资料管理
  11. */
  12. class WorkOrder extends Api
  13. {
  14. protected $noNeedLogin = ['*'];
  15. protected $noNeedRight = ['*'];
  16. /**
  17. * 工单资料菜单列表
  18. *
  19. * @ApiMethod (GET)
  20. * @return false|string
  21. * @throws \think\Exception
  22. */
  23. public function DataList()
  24. {
  25. if ($this->request->isGet() === false){
  26. $this->error('请求错误');
  27. }
  28. $param = $this->request->param();
  29. if (isset($param['sort'])){
  30. $where['工单分类'] = 2;
  31. }else{
  32. $where['工单分类'] = ['in',[1,3]];
  33. }
  34. $where['行号'] = ['in',['1','10']];
  35. //获取总计划中数量和总生产中数量
  36. $productingAll = \db('工单_基本资料')->where($where)->where('成品代号','<>','')->where('行号','1')->where('gd_statu','2-生产中')->cache(true)->count();
  37. $progressAll = \db('工单_基本资料')->where($where)->where('成品代号','<>','')->where('行号','1')->where('gd_statu','3-计划中')->cache(true)->count();
  38. $data = [
  39. 'productingAll' => $productingAll,
  40. 'progressAll' => $progressAll,
  41. // '客户编号' => []
  42. ];
  43. $list = \db('产品_基本资料')
  44. ->where('客户编号','<>','')
  45. ->field('客户编号,客户名称')
  46. ->group('客户编号,客户名称')
  47. ->order('客户编号')
  48. ->select();
  49. if (empty($list)){
  50. $this->success('',[]);
  51. }
  52. $data['翌星工单']=$data['MN工单']=[];
  53. foreach ($list as $key=>$value){
  54. $value['客户编号'] = rtrim($value['客户编号']);
  55. //这条sql查出来的数据可能不对,试一下以下sql
  56. $productIng = \db('工单_基本资料')->where($where)->where('Gd_cpdh|成品代号','LIKE',rtrim($value['客户编号']).'%')->where('gd_statu','2-生产中')->count();
  57. $proGress = \db('工单_基本资料')->where($where)->where('Gd_cpdh|成品代号','LIKE',rtrim($value['客户编号']).'%')->where('gd_statu','3-计划中')->count();
  58. $string = '';
  59. if ($productIng != 0){
  60. $string = $string."生产中:".$productIng;
  61. }
  62. if ($proGress != 0){
  63. $string = $string."计划中:".$proGress;
  64. }
  65. if ($string !== ''){
  66. $name = $value['客户编号'].'【'.$string.'】'.rtrim($value['客户名称']);
  67. if (strpos($value['客户编号'],'J') !== false || strpos($value['客户编号'],'Y') !== false){
  68. array_push($data['翌星工单'],$name);
  69. }else{
  70. array_push($data['MN工单'],$name);
  71. }
  72. // array_push($data['客户编号'],$name);
  73. }
  74. // else{
  75. // $name = $value['客户编号'].$value['客户名称'];
  76. // if (strpos($value['客户编号'],'J') !== false){
  77. // array_push($data['糊盒工单'],$name);
  78. // }else{
  79. // array_push($data['印刷工单'],$name);
  80. // }
  81. // }
  82. }
  83. $this->success('成功',$data);
  84. }
  85. /**
  86. * 工单基本资料列表
  87. * @ApiMethod (GET)
  88. * @param string $limit 查询长度
  89. * @param string $Gd_khdh 客户代号
  90. * @param string $startTime 接单日期开始时间
  91. * @param string $endTime 接单日期结束时间
  92. * @return \think\response\Json
  93. * @throws \think\exception\DbException
  94. */
  95. public function WorkList()
  96. {
  97. if ($this->request->isGet() === false){
  98. $this->error('请求错误');
  99. }
  100. $search = input('search');
  101. $clientNumber = input('Gd_khdh');
  102. $startTime = input('start');
  103. $endTime = input('end');
  104. $page = input('page');
  105. $limit = input('limit');
  106. $param = $this->request->param();
  107. if (isset($param['sort'])){
  108. $sort = 2;
  109. }else{
  110. $sort = 1;
  111. }
  112. $where = [];
  113. if (!empty($clientNumber)){
  114. if (substr($clientNumber,0,1) !== 'Y' && substr($clientNumber,0,1) !== 'J')
  115. {
  116. $clientNumber = substr($clientNumber,0,4);
  117. }
  118. if ($clientNumber === 'Y1401'){
  119. $where['Gd_cpdh'] = ['like',$clientNumber.'%'];
  120. }else{
  121. $where['成品代号'] = ['like',$clientNumber.'%'];
  122. }
  123. }
  124. // if (substr($clientNumber,0,1) === 'Y'){
  125. // $where['工单分类'] = 1;
  126. // }elseif (substr($clientNumber,0,1) === 'J'){
  127. // $where['工单分类'] = 2;
  128. // }
  129. if (!empty($workOrder)){
  130. $where['Gd_gdbh'] = $workOrder;
  131. }
  132. if (!empty($productCode)){
  133. $where['Gd_cpdh'] = $productCode;
  134. }
  135. if (!empty($search)){
  136. $where['Gd_lx|Gd_gdbh|Gd_客户代号|Gd_客户名称|Gd_khdh|Gd_khmc|Gd_cpdh|Gd_cpmc|成品代号|成品名称|产品版本号'] = ['like','%'.$search.'%'];
  137. }
  138. if (!empty($startTime) && !empty($endTime)){
  139. $where['接单日期'] = ['between',[$startTime,$endTime]];
  140. }
  141. // $where['工单分类'] = $sort;
  142. // $where['行号'] = ['in',['1','10']];
  143. $total = \db('工单_基本资料')->where($where)->distinct(true)->field('Gd_gdbh')->count();
  144. $list = \db('工单_基本资料')
  145. ->where($where)
  146. ->order('Gd_statu desc')
  147. ->limit(($page-1)*$limit,$limit)
  148. ->group('Gd_gdbh')
  149. ->select();
  150. //工单基本资料数据整理
  151. $data = [];
  152. foreach ($list as $key=>$value){
  153. $data[$key] = [
  154. '工单编号' => rtrim($value['Gd_gdbh']),
  155. '生产分类' => rtrim($value['Gd_生产分类']),
  156. '销售订单号' => rtrim($value['销售订单号']),
  157. '产品代号' => rtrim($value['成品代号']),
  158. '产品名称' => rtrim($value['成品名称']),
  159. '订单数量' => floatval($value['订单数量']),
  160. '单位' => rtrim($value['计量单位']),
  161. '折合大箱' => rtrim((int)$value['投料大箱']),
  162. '投料率' => rtrim($value['投料率']),
  163. '平均合格率' => '',
  164. '开单日期' => date('Y-m-d',strtotime(rtrim($value['接单日期']))),
  165. '交货日期' => date('Y-m-d',strtotime(rtrim($value['交货日期']))),
  166. '工单类型' => rtrim($value['Gd_lx']),
  167. '工单状态' => rtrim($value['gd_statu']),
  168. '当前生产工序' => '',
  169. '产量提交时间' => '',
  170. '建档用户' => rtrim($value['Sys_id']),
  171. '建档时间' => rtrim($value['Sys_rq']),
  172. '更新时间' => rtrim($value['Mod_rq']),
  173. 'Uniqid' => rtrim($value['Uniqid'])
  174. ];
  175. $number = \db('工单_工艺资料')->where('Gy0_gdbh',$data[$key]['工单编号'])->count();
  176. if ($number === 0){
  177. $data[$key]['status'] = '*';
  178. }else{
  179. $data[$key]['status'] = '';
  180. }
  181. }
  182. $this->success('成功',['data'=>$data,'total'=>$total]);
  183. }
  184. /**
  185. * 工单详情
  186. * @ApiMethod (GET)
  187. * @param void
  188. * @return void
  189. * @throws \think\db\exception\DataNotFoundException
  190. * @throws \think\db\exception\ModelNotFoundException
  191. * @throws \think\exception\DbException
  192. */
  193. public function workOrderListDetail()
  194. {
  195. if ($this->request->isGet() === false){
  196. $this->error('请求错误');
  197. }
  198. $Gd_gdbh = input('Gd_gdbh');
  199. $param = $this->request->param();
  200. if (empty($Gd_gdbh)){
  201. $this->error('参数错误');
  202. }
  203. if (isset($param['sort'])){
  204. $where['yj_Yjno'] = ['>=','10'];
  205. }else{
  206. $where['yj_Yjno'] = ['<','10'];
  207. }
  208. $data = [];
  209. //印件资料
  210. $printList = \db('工单_印件资料')
  211. ->where('Yj_Gdbh',$Gd_gdbh)
  212. ->where($where)
  213. ->select();
  214. if (!empty($printList)){
  215. foreach ($printList as $key=>$value){
  216. $data['printList'][$key] = [
  217. '印件号' => rtrim($value['yj_Yjno']),
  218. '印件代号' => rtrim($value['yj_Yjdh']),
  219. '印件名称' => rtrim($value['yj_yjmc']),
  220. '纸张代号' => rtrim($value['yj_zzdh']),
  221. '纸张名称' => rtrim($value['yj_zzmc']),
  222. '投料规格' => rtrim($value['yj_tlgg']),
  223. '平张投料' => rtrim($value['yj_平张投料']),
  224. '开料规格' => rtrim($value['yj_klgg']),
  225. '开数*联数' => rtrim($value['yj_ks']).'*'.rtrim($value['yj_ls']),
  226. '建档用户' => rtrim($value['Sys_id']),
  227. '建档时间' => rtrim($value['Sys_rq']),
  228. '更新时间' => rtrim($value['Mod_rq']),
  229. 'zzdh1' => rtrim($value['yj_zzdh1']),
  230. 'zzdh2' => rtrim($value['yj_zzdh2']),
  231. 'zzdh3' => rtrim($value['yj_zzdh3']),
  232. 'zzdh4' => rtrim($value['yj_zzdh4']),
  233. 'zzmc1' => rtrim($value['yj_zzmc1']),
  234. 'zzmc2' => rtrim($value['yj_zzmc2']),
  235. 'zzmc3' => rtrim($value['yj_zzmc3']),
  236. 'zzmc4' => rtrim($value['yj_zzmc4']),
  237. '订单数量' => rtrim($value['yj_成品数量']),
  238. '万小张' => rtrim($value['yj_实际投料']),
  239. '开数' => rtrim($value['yj_ks']),
  240. '联数' => rtrim($value['yj_ls']),
  241. '核算规格' => rtrim($value['Yj_核算规格']),
  242. '备注' => rtrim($value['yj_desc']),
  243. 'Uniqid' => rtrim($value['Uniqid'])
  244. ];
  245. }
  246. }else{
  247. $data['printList'] = [];
  248. }
  249. //工艺资料
  250. if (isset($param['sort'])){
  251. $Prowhere['Gy0_yjno'] = ['>=','10'];
  252. }else{
  253. $Prowhere['Gy0_yjno'] = ['<','10'];
  254. }
  255. $processList = \db('工单_工艺资料')
  256. ->where('Gy0_gdbh',$Gd_gdbh)
  257. ->where($Prowhere)
  258. ->order('Gy0_yjno,Gy0_gxh')
  259. ->select();
  260. if (!empty($processList)){
  261. foreach ($processList as $key=>$value){
  262. if ($value['Gy0_yjno']<10){
  263. $value['Gy0_yjno'] = '0'.$value['Gy0_yjno'];
  264. }
  265. if ($value['Gy0_gxh']<10){
  266. $value['Gy0_gxh'] = '0'.$value['Gy0_gxh'];
  267. }
  268. if (rtrim($value['Gy0_shdh']) == '' || $value['Gy0_计划接货数'] == 0){
  269. $number = 0;
  270. }else{
  271. $number = round(((int)$value['Gy0_计划损耗']/(int)($value['Gy0_计划接货数']))*100,2).'%';
  272. }
  273. if ($value['PD_WG'] !== '1900-01-01 00:00:00'){
  274. $status = '已完工';
  275. }else{
  276. $status = '未完工';
  277. }
  278. $data['processList'][$key] = [
  279. '重点工序' => rtrim($value['重点工序']),
  280. '印件-工序' => rtrim($value['Gy0_yjno']).'-'.rtrim($value['Gy0_gxh']),
  281. '备选工序' => rtrim($value['备选工序']),
  282. '工序名称' => rtrim($value['Gy0_gxmc']).'【'.rtrim($value['Add_gxmc']).'】',
  283. '印件号' => rtrim($value['Gy0_yjno']),
  284. '工序号' => rtrim($value['Gy0_gxh']),
  285. '工艺名称' => rtrim($value['Gy0_gxmc']),
  286. 'gxmc' => rtrim($value['Add_gxmc']),
  287. '计划产量' => $value['Gy0_计划接货数'],
  288. '基础损耗' => rtrim($value['Gy0_Rate0']),
  289. '损耗率' => rtrim($value['Gy0_Rate1']),
  290. '机台编号' => rtrim($value['Gy0_sbbh']),
  291. '报废定额' => rtrim($value['Gy0_计划损耗']),
  292. '计损色数' => rtrim($value['Gy0_ms']),
  293. '允损比例' => $number,
  294. '难度系数' => isset($value['工价系数'])?rtrim($value['工价系数']):'',
  295. '损耗系数' => isset($value['损耗系数'])?rtrim($value['损耗系数']):'',
  296. '人工检_次品板' => (int)$value['人工检_次品板']=0?'':$value['人工检_次品板'],
  297. '人工检_废检' => (int)$value['人工检_废检']=0?'':$value['人工检_废检'],
  298. '机检_正品板' => (int)$value['机检_正品板']=0?'':$value['机检_正品板'],
  299. '机检_次品板' => (int)$value['机检_次品板']=0?'':$value['机检_次品板'],
  300. '机检_废检' => (int)$value['机检_废检']=0?'':$value['机检_废检'],
  301. '开数*联数' => rtrim($value['Gy0_ks']).'*'.rtrim($value['Gy0_ls']),
  302. '备注' => isset($value['工序备注'])?rtrim($value['工序备注']):'',
  303. '印刷方式' => isset($value['印刷方式'])?rtrim($value['印刷方式']):'',
  304. '版距' => isset($value['版距'])?rtrim($value['版距']):'',
  305. '建档用户' => rtrim($value['Sys_id']),
  306. '建档日期' => isset($value['Sys_rq'])?rtrim($value['Sys_rq']):'',
  307. '更新时间' => isset($value['Mod_rq'])?rtrim($value['Mod_rq']):'',
  308. '车间名称' => rtrim($value['Gy0_SITE']),
  309. '质量要求' => rtrim($value['质量要求']),
  310. '质量隐患' => rtrim($value['质量隐患']),
  311. '开数' => rtrim($value['Gy0_ks']),
  312. '联数' => rtrim($value['Gy0_ls']),
  313. 'UniqId' => rtrim($value['UniqId']),
  314. 'shdh' => rtrim($value['Gy0_shdh']),
  315. '辅助工时' => rtrim($value['Gy0_辅助工时']),
  316. '小时产能' => rtrim($value['Gy0_小时产能']),
  317. 'status' => $status
  318. ];
  319. }
  320. }else{
  321. $data['processList'] = [];
  322. }
  323. //BOM资料
  324. $field = 'rtrim(BOM_方案) as 方案,rtrim(BOM_物料编码) as 物料编号,rtrim(BOM_物料名称) as 物料名称,BOM_投料单位,
  325. BOM_投入数,BOM_产出数,BOM_产出单位,rtrim(BOM_计划用量) as 计划用量,rtrim(Sys_ID) as 建档用户,rtrim(Sys_rq) as 建档时间,rtrim(Mod_rq) as 更新时间';
  326. $bomList = \db('工单_bom资料')
  327. ->where('BOM_工单编号',$Gd_gdbh)
  328. ->field($field)
  329. ->select();
  330. if (!empty($bomList)){
  331. foreach ($bomList as $key=>$value){
  332. $bomList[$key]['消耗定量'] = rtrim($value['BOM_投入数']).rtrim($value['BOM_投料单位']).'/'.rtrim($value['BOM_产出数']).rtrim($value['BOM_产出单位']);
  333. unset($bomList[$key]['BOM_投料单位'],$bomList[$key]['BOM_投入数'],$bomList[$key]['BOM_产出数'],$bomList[$key]['BOM_产出单位']);
  334. $bomList[$key]['计划用量'] = rtrim((float)$value['计划用量']);
  335. }
  336. $data['BOM'] = $bomList;
  337. }else{
  338. $data['BOM'] = [];
  339. }
  340. //工单附件资料
  341. $jsRes = db('工单_相关附件')
  342. ->where('关联编号','like','%'.$Gd_gdbh.'%')
  343. ->select();
  344. if (!empty($jsRes)){
  345. foreach ($jsRes as $key=>&$value){
  346. if(mb_detect_encoding($value['附件内容'])!='ASCII'){
  347. $value['附件内容'] = '';
  348. }
  349. }
  350. $data['jsData'] = $jsRes;
  351. }else{
  352. $data['jsData'] = [];
  353. }
  354. $this->success('成功',$data);
  355. }
  356. /**
  357. * 编辑页面展示
  358. * @ApiMethod (GET)
  359. * @param string $workOrder 工单编号
  360. * @return void
  361. * @throws \think\db\exception\DataNotFoundException
  362. * @throws \think\db\exception\ModelNotFoundException
  363. * @throws \think\exception\DbException
  364. */
  365. public function DataCorrection()
  366. {
  367. if ($this->request->isGet() === false){
  368. $this->error('请求错误');
  369. }
  370. $workOrder = input('Gd_gdbh');
  371. if (empty($workOrder)){
  372. $this->error('参数错误');
  373. }
  374. $field = 'rtrim(Gd_lx) as 重点工单,rtrim(Gd_gdbh) as 工单编号,rtrim(Gd_生产分类) as 生产类型,rtrim(Gd_khdh) as 客户代号,rtrim(Gd_客户名称) as 客户名称,
  375. rtrim(Gd_cpdh) as 印件代号,rtrim(Gd_cpmc) as 印件名称,rtrim(成品代号) as 产品代号,rtrim(成品名称) as 产品名称,rtrim(接单日期) as 开单日期,rtrim(订单数量) as 订单数量,rtrim(交货日期) as 交货日期,
  376. rtrim(投料率) as 投料率,rtrim(实际投料) as 万小张,rtrim(计量单位) as 单位,rtrim(投料大箱) as 投料大箱,rtrim(排产时库存) as 库存大箱,rtrim(警语版面) as 警语版面,
  377. rtrim(销售订单号) as 销售订单号,rtrim(产品版本号) as 版本号,rtrim(客户ERP编码) as 客户ERP编码,rtrim(码源数量) as 码源数量,rtrim(进程备注) as 进程备注,rtrim(Gd_desc) as 备注,rtrim(Uniqid) as Uniqid,rtrim(计划投料) as 平张投料';
  378. $list = \db('工单_基本资料')->where('Gd_gdbh',$workOrder)->field($field)->find();
  379. if (empty($list)){
  380. $this->error('未找到该工单信息');
  381. }
  382. $printData = \db('工单_印件资料')
  383. ->where('Yj_Gdbh',$workOrder)
  384. ->field('rtrim(yj_yjmc) as 印件名称,rtrim(yj_Yjdh) as 印件代号,rtrim(Uniqid) as id')
  385. ->cache(true,84600)
  386. ->find();
  387. if (empty($printData)){
  388. $list['印件名称'] = '';
  389. $list['印件代号'] = '';
  390. $list['印件ID'] = '';
  391. }else{
  392. $list['印件名称'] = $printData['印件名称'];
  393. $list['印件代号'] = $printData['印件代号'];
  394. $list['印件ID'] = $printData['id'];
  395. }
  396. $this->success('成功',$list);
  397. }
  398. /**
  399. * 工单资料修改
  400. * @ApiMethod (POST)
  401. * @param void
  402. * @return void
  403. * @throws \think\Exception
  404. * @throws \think\exception\PDOException
  405. */
  406. public function WorkOrderEdit()
  407. {
  408. if (Request::instance()->isPost() === false){
  409. $this->error('请求错误');
  410. }
  411. $param = Request::instance()->post();
  412. if (empty($param) || isset($param['Uniqid']) === false){
  413. $this->error('参数错误');
  414. }
  415. $row = [
  416. 'Gd_lx' => isset($param['lx'])?$param['lx']:'',
  417. '开单日期' => isset($param['kdrq'])?$param['kdrq']:'',
  418. 'Gd_gdbh' => isset($param['gdbh'])?$param['gdbh']:'',
  419. 'Gd_生产分类' => isset($param['scfl'])?$param['scfl']:'',
  420. 'Gd_客户代号' => isset($param['khdh'])?$param['khdh']:'',
  421. 'Gd_客户名称' => isset($param['khmc'])?$param['khmc']:'',
  422. '成品代号' => isset($param['cpdh'])?$param['cpdh']:'',
  423. '成品名称' => isset($param['cpmc'])?$param['cpmc']:'',
  424. '订单数量' => isset($param['ddsl'])?$param['ddsl']:'',
  425. '交货日期' => isset($param['jhrq'])?$param['jhrq']:'',
  426. '投料率' => isset($param['tll'])?$param['tll']:'',
  427. '计划投料' => isset($param['jhtl'])?$param['jhtl']:'',
  428. '实际投料' => isset($param['sjtl'])?$param['sjtl']:'',
  429. '计量单位' => isset($param['jldw'])?$param['jldw']:'',
  430. '投料大箱' => isset($param['tldx'])?$param['tldx']:'',
  431. '销售订单号' => isset($param['xsddh'])?$param['xsddh']:'',
  432. '警语版面' => isset($param['jymb'])?$param['jymb']:'',
  433. '产品版本号' => isset($param['bbh'])?$param['bbh']:'',
  434. '客户ERP编码' => isset($param['erp'])?$param['erp']:'',
  435. '码源数量' => isset($param['ymsl'])?$param['ymsl']:'',
  436. '进程备注' => isset($param['jcbz'])?$param['jcbz']:'',
  437. 'Gd_desc' => isset($param['desc'])?$param['desc']:'',
  438. '排产时库存' => isset($param['kc'])?$param['kc']:'',
  439. '平均合格率' => isset($param['avg'])?$param['avg']:'',
  440. ];
  441. //获取印件资料
  442. $printCode = \db('工单_印件资料')
  443. ->where('Uniqid',$param['printID'])
  444. ->value('yj_Yjno');
  445. if (!empty($printCode)){
  446. if ((int)$param['jhtl'] >0){
  447. //修改工单工艺计划产量
  448. $result = $this->PlannedProcessYield($param['gdbh'],$printCode,0,$param['jhtl']);
  449. if ($result === false){
  450. $this->success('分配工序计划产量失败');
  451. }
  452. }
  453. //修改印件信息
  454. $printSql = \db('工单_印件资料')
  455. ->where('Uniqid',$param['printID'])
  456. ->fetchSql(true)
  457. ->update(['Yj_Gdbh'=>$param['gdbh'],'yj_yjmc'=>$param['yjmc'],'yj_Yjdh'=>$param['yjdh'],'yj_平张投料'=>$param['jhtl']]);
  458. $printRes = Db::query($printSql);
  459. }
  460. //修改工单信息
  461. $sql = \db('工单_基本资料')->where('Uniqid',$param['Uniqid'])->fetchSql(true)->update($row);
  462. $res = Db::query($sql);
  463. //修改订单数量该工单下的订单数量
  464. //1. 查询该id下的工单编号, 防止其手动修改工单编号导致条件错误
  465. $gdbh = \db('工单_基本资料')->where('Uniqid',$param['Uniqid'])->value('Gd_gdbh');
  466. //2. 根据查出的工单编号修改订单数量
  467. $sql = \db('工单_基本资料')->where('Gd_gdbh',$param['gdbh'])->fetchSql(true)->update(['订单数量'=>$row['订单数量']]);
  468. $res1 = Db::query($sql);
  469. if ($res !== false && $res1 !== false){
  470. $this->success('成功');
  471. }else{
  472. $this->error('失败');
  473. }
  474. }
  475. /**
  476. * U8投料试算
  477. * @ApiMethod (GET)
  478. * @param string $processCode 产品编号
  479. * @return void
  480. * @throws \think\db\exception\DataNotFoundException
  481. * @throws \think\db\exception\ModelNotFoundException
  482. * @throws \think\exception\DbException
  483. */
  484. public function U8Trial()
  485. {
  486. if ($this->request->isGet() === false)
  487. {
  488. $this->error('请求错误');
  489. }
  490. $productCode = input('productCode');
  491. if (empty($productCode)){
  492. $this->error('参数错误');
  493. }
  494. $field = 'rtrim(Gy0_cpdh) as 产品代号,rtrim(Gy0_yjno) as 印件号,rtrim(Gy0_gxh) as 工序号,rtrim(gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc,
  495. rtrim(Gy0_Ms) as 墨色数,rtrim(Gy0_shdh) as 损耗代号,rtrim(损耗系数) as 损耗系数,rtrim(Gy0_ls) as 加工联数';
  496. $list = \db('产品_工艺资料')->where('Gy0_cpdh',$productCode)->field($field)->select();
  497. if (empty($list)){
  498. $this->success('未找到该产品工序');
  499. }
  500. foreach ($list as $key=>$value){
  501. $data = \db('dic_lzsh')->where('sys_bh',$value['损耗代号'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->cache(true)->find();
  502. $list[$key]['调机损耗'] = isset($data['rate0'])?$data['rate0']:'';
  503. $list[$key]['运行损耗率'] = isset($data['rate1'])?$data['rate1']:'';
  504. if ($value['add_gxmc'] !== ''){
  505. $list[$key]['工序名称'] = $value['gxmc'].'【'.$value['add_gxmc'].'】';
  506. }else{
  507. $list[$key]['工序名称'] = $value['gxmc'];
  508. }
  509. unset($list[$key]['gxmc'],$list[$key]['add_gxmc']);
  510. }
  511. $this->success('成功',$list);
  512. }
  513. /**
  514. * 引用产品资料->获取产品资料
  515. * @ApiMethod (GET)
  516. * @param string $workOrder 工单编号
  517. * @return void
  518. * @throws \think\db\exception\DataNotFoundException
  519. * @throws \think\db\exception\ModelNotFoundException
  520. * @throws \think\exception\DbException
  521. */
  522. public function ProductInformation()
  523. {
  524. if ($this->request->isGet() === false)
  525. {
  526. $this->error('请求错误');
  527. }
  528. $workOrder = input('workOrder');
  529. if (empty($workOrder)){
  530. $this->error('参数错误');
  531. }
  532. $field = 'rtrim(Gd_gdbh) as 工单编号,rtrim(Gd_客户名称) as 客户名称,rtrim(成品代号) as 产品代号,rtrim(成品名称) as 产品名称';
  533. $Detail = \db('工单_基本资料')->where('Gd_gdbh',$workOrder)->field($field)->find();
  534. if (empty($Detail)){
  535. $this->success('未找到工单信息');
  536. }
  537. $Detail['客户代号'] = substr($Detail['产品代号'],0,4);
  538. $this->success('成功',$Detail);
  539. }
  540. /**
  541. * 引用产品资料->复制产品工艺资料
  542. * @ApiMethod (POST)
  543. * @param string $oldWorkOrder 被复制工单编号
  544. * @param string $newWorkOrder 复制工单编号
  545. * @return void
  546. * @throws \think\Exception
  547. * @throws \think\db\exception\DataNotFoundException
  548. * @throws \think\db\exception\ModelNotFoundException
  549. * @throws \think\exception\DbException
  550. * @throws \think\exception\PDOException
  551. */
  552. public function ProductInformationEdit()
  553. {
  554. if (Request::instance()->isPost() === false)
  555. {
  556. $this->error('请求错误');
  557. }
  558. $oldWorkOrder = input('oldWorkOrder');
  559. $newWorkOrder = input('newWorkOrder');
  560. if (empty($oldWorkOrder) || empty($newWorkOrder))
  561. {
  562. $this->error('参数错误');
  563. }
  564. $lastId = \db('工单_工艺资料')->order('UniqId desc')->value('UniqId');
  565. if ($lastId<10000000){
  566. $lastId = 10000000;
  567. }else{
  568. $lastId = $lastId + 1;
  569. }
  570. //获取原工单工艺资料
  571. $oldProcessData = \db('工单_工艺资料')->where('Gy0_gdbh',$newWorkOrder)->select();
  572. $ProsessUniqId = \db('工单_工艺资料')->field('UniqId')->order('UniqId desc')->find();
  573. foreach ($oldProcessData as $k=>$v){
  574. $oldProcessData[$k]['Gy0_gdbh'] = $oldWorkOrder;
  575. $oldProcessData[$k]['Sys_id'] = '';
  576. $oldProcessData[$k]['Gy0_sj1'] = '1900-01-01 00:00:00';
  577. $oldProcessData[$k]['Gy0_sj2'] = '1900-01-01 00:00:00';
  578. $oldProcessData[$k]['UniqId'] = $lastId + $k;
  579. $oldProcessData[$k]['PD_WG'] = '1900-01-01 00:00:00';
  580. }
  581. if (\db('工单_工艺资料')->where('Gy0_gdbh',$oldWorkOrder)->find()){
  582. \db('工单_工艺资料')->where('Gy0_gdbh',$oldWorkOrder)->delete();
  583. }
  584. //获取原工单印件资料
  585. $lastUniqId = \db('工单_印件资料')->order('UniqId desc')->value('UniqId');
  586. if ($lastUniqId<1000000){
  587. $lastUniqId = 1000000;
  588. }else{
  589. $lastUniqId = $lastUniqId + 1;
  590. }
  591. $oldPrintData = \db('工单_印件资料')->where('Yj_Gdbh',$newWorkOrder)->select();
  592. $PrintUniqId = \db('工单_印件资料')->field('Uniqid')->order('Uniqid desc')->find();
  593. foreach ($oldPrintData as $k=>$v){
  594. $oldPrintData[$k]['Yj_Gdbh'] = $oldWorkOrder;
  595. $oldPrintData[$k]['Sys_id'] = '';
  596. $oldPrintData[$k]['Uniqid'] = $lastUniqId +$k +1;
  597. }
  598. if (\db('工单_印件资料')->where('Yj_Gdbh',$oldWorkOrder)->find()){
  599. \db('工单_印件资料')->where('Yj_Gdbh',$oldWorkOrder)->delete();
  600. }
  601. //复制印件、工艺资料
  602. $ProcessSQL = \db('工单_工艺资料')->fetchSql(true)->insertAll($oldProcessData);
  603. $ProcessRes = Db::query($ProcessSQL);
  604. $PrintSQL = \db('工单_印件资料')->fetchSql(true)->insertAll($oldPrintData);
  605. $PrintRes = Db::query($PrintSQL);
  606. if ($ProcessRes !== false && $PrintRes !== false){
  607. $this->success('成功');
  608. }else{
  609. $this->error('失败');
  610. }
  611. }
  612. /**
  613. * 工艺流程调成->获取当前工单工艺资料
  614. * @ApiMethod (GET)
  615. * @param string $workorder 当前工单编号
  616. * @return void
  617. * @throws \think\db\exception\DataNotFoundException
  618. * @throws \think\db\exception\ModelNotFoundException
  619. * @throws \think\exception\DbException
  620. */
  621. public function ProcessFlow()
  622. {
  623. if ($this->request->isGet() === false){
  624. $this->error('请求错误');
  625. }
  626. $workOrder = input('workOrder');
  627. if (empty($workOrder)){
  628. $this->error('参数错误');
  629. }
  630. $list = \db('工单_基本资料')->where('Gd_gdbh',$workOrder)->field('rtrim(成品代号) as 成品编号,rtrim(成品名称) as 成品名称')->find();
  631. if (empty($list)){
  632. $this->success('未找到工单信息');
  633. }
  634. $filed = 'rtrim(Gy0_方案) as 方案,rtrim(Gy0_yjno) as 印件号,rtrim(Gy0_gxh) as 工序号,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc,
  635. rtrim(工价系数) as 工价系数,rtrim(损耗系数) as 损耗系数,rtrim(Gy0_ks) as ks,rtrim(Gy0_ls) as ls,rtrim(工序备注) as 备注,rtrim(Gy0_SITE) as 车间,
  636. rtrim(Gy0_sbbh) as 设备编号,rtrim(Gy0_sbmc) as 设备名称,rtrim(Sys_id) as 建档用户,rtrim(Sys_rq) as 建档时间,rtrim(Mod_rq) as 更新时间,rtrim(UniqId) as UniqId';
  637. $process = \db('工单_工艺资料')->where('Gy0_gdbh',$workOrder)->cache(true,84600)->field($filed)->select();
  638. if (empty($process)){
  639. $this->error('未找到该工单工艺资料');
  640. }
  641. foreach ($process as $key=>$value){
  642. if (isset($value['add_gxmc'])){
  643. $process[$key]['工序名称'] = $value['gxmc'] . '【'.$value['add_gxmc'].'】';
  644. }else{
  645. $process[$key]['工序名称'] = $value['gxmc'];
  646. }
  647. $process[$key]['工价系数'] = (float)$value['工价系数'];
  648. $process[$key]['损耗系数'] = (float)$value['损耗系数'];
  649. $process[$key]['开数*联数'] = $value['ks'].'*'.$value['ls'];
  650. }
  651. $list['process'] = $process;
  652. $this->success('成功',$list);
  653. }
  654. /**
  655. * 参照工单列表获取
  656. * @ApiMethod (GET)
  657. * @param string $workOrder 工单编号
  658. * @param string $productCode 产品代号
  659. * @return void
  660. */
  661. public function ReferenceWorkOrder()
  662. {
  663. if ($this->request->isGet() === false){
  664. $this->error('请求错误');
  665. }
  666. $productCode = input('productCode');
  667. $workOrder = input('workOrder');
  668. if (empty($productCode) || empty($workOrder)){
  669. $this->error('参数错误');
  670. }
  671. $list = \db('工单_基本资料')->where('成品代号',$productCode)->distinct(true)->where('Gd_gdbh','<>',$workOrder)->column('Gd_gdbh');
  672. if (empty($list)){
  673. $this->success('未获取该产品其他工单信息');
  674. }
  675. $this->success('成功',$list);
  676. }
  677. /**
  678. * 工艺资料复制
  679. * @ApiMethod (POST)
  680. * @param string $oldWorkOrder 被复制工单编号
  681. * @param string $newWorkOrder 复制工单编号
  682. * @return void
  683. * @throws \think\Exception
  684. * @throws \think\db\exception\DataNotFoundException
  685. * @throws \think\db\exception\ModelNotFoundException
  686. * @throws \think\exception\DbException
  687. * @throws \think\exception\PDOException
  688. *
  689. */
  690. public function ProcessCopy()
  691. {
  692. if (Request::instance()->isPost() === false){
  693. $this->error('请求错误');
  694. }
  695. $param = Request::instance()->post();
  696. if (empty($param)){
  697. $this->error('参数错误');
  698. }
  699. $i = 0;
  700. foreach ($param as $key => $value){
  701. $sql = \db('工单_工艺资料')
  702. ->where('UniqId',$value['UniqId'])
  703. ->fetchSql(true)
  704. ->update(['Gy0_gxh'=>$value['gxh']]);
  705. $res = \db()->query($sql);
  706. if ($res === false){
  707. $i++;
  708. }
  709. }
  710. if ($i === 0){
  711. $this->success('成功');
  712. }else{
  713. $this->error('失败');
  714. }
  715. // $UniqId = [];
  716. // $lastId = \db('工单_工艺资料')->field('rtrim(UniqId) as id')->order('UniqId desc')->find();
  717. // if ($lastId['id']>10000000){
  718. // $lastUniqId = $lastId['id'];
  719. // }else{
  720. // $lastUniqId = 10000000;
  721. // }
  722. // foreach ($param as $key=>$value){
  723. // $UniqId[$key] = $value['UniqId'];
  724. // }
  725. // $processList = \db('工单_工艺资料')->where('UniqId','in',$UniqId)->select();
  726. // if (empty($processList)){
  727. // $this->success('未找到工艺资料');
  728. // }
  729. // halt($processList);
  730. // $data = [];
  731. // foreach ($param as $key=>$value){
  732. // foreach ($processList as $k=>$v){
  733. // if ($value['UniqId'] = $v['UniqId']){
  734. // $data[$key] = $v;
  735. // $data[$key]['Gy0_gxh'] = $value['gxh'];
  736. // $data[$key]['Gy0_gdbh'] = $value['workOrder'];
  737. // $data[$key]['UniqId'] = $lastUniqId + $key + 1;
  738. // }
  739. // }
  740. // }
  741. // $res = \db('工单_工艺资料')->where(['Gy0_gdbh'=>$param[0]['workOrder']])->delete();
  742. // if ($res !== false){
  743. // $result = \db('工单_工艺资料')->insertAll($data);
  744. // if ($result !== false){
  745. // $this->success('成功');
  746. // }else{
  747. // $this->error('失败');
  748. // }
  749. // }else{
  750. // $this->error('失败');
  751. // }
  752. }
  753. /**
  754. * U8工单列表
  755. * @ApiMethod (GET)
  756. * @param void
  757. * @return void
  758. * @throws \think\db\exception\DataNotFoundException
  759. * @throws \think\db\exception\ModelNotFoundException
  760. * @throws \think\exception\DbException
  761. */
  762. public function U8workOrder()
  763. {
  764. if ($this->request->isGet() === false){
  765. $this->error('请求错误');
  766. }
  767. $param = $this->request->param();
  768. if (empty($param)){
  769. $this->error('参数错误');
  770. }
  771. $filed = 'rtrim(Gd_gdbh) as 工单编号,rtrim(行号) as 行号,rtrim(Gd_客户代号) as 客户代号,rtrim(Gd_客户名称) as 客户名称,
  772. rtrim(成品代号) as 成品代号,rtrim(成品名称) as 成品名称,rtrim(Mod_rq) as 获取日期,rtrim(Uniqid) as 序号';
  773. $list = \db('工单_基本资料')->where('Gd_gdbh',$param['workOrder'])->field($filed)->select();
  774. if (empty($list)){
  775. $this->success('未找到工单');
  776. }
  777. $this->success('成功',$list);
  778. }
  779. /**
  780. * U8工单资料删除
  781. * @param string $workOrder 工单编号
  782. * @return void
  783. * @throws \think\Exception
  784. * @throws \think\exception\PDOException
  785. */
  786. public function U8DataCorrection()
  787. {
  788. if($this->request->isGet() === false){
  789. $this->error('请求错误');
  790. }
  791. $workOrder = input('Uniqid');
  792. if (empty($workOrder)){
  793. $this->error('参数错误');
  794. }
  795. $data = [];
  796. if (strpos($workOrder,',')){
  797. $data = explode(',',$workOrder);
  798. }else{
  799. $data[0] = $workOrder;
  800. }
  801. $res = \db('工单_基本资料')->where('Uniqid','in',$data)->delete();
  802. if ($res !== false){
  803. $this->success('成功');
  804. }else{
  805. $this->error('失败');
  806. }
  807. }
  808. /**
  809. * 产品废检系数调整->质检工艺数据获取
  810. * @ApiMethod (GET)
  811. * @param string $workOrder 工单编号
  812. * @return void
  813. * @throws \think\db\exception\DataNotFoundException
  814. * @throws \think\db\exception\ModelNotFoundException
  815. * @throws \think\exception\DbException
  816. */
  817. public function TestCoefficient()
  818. {
  819. if ($this->request->isGet() === false){
  820. $this->error('请求错误');
  821. }
  822. $workOrder = input('workOrder');
  823. if (empty($workOrder)){
  824. $this->error('参数错误');
  825. }
  826. $where = [
  827. 'Gy0_gdbh' => $workOrder,
  828. 'Gy0_gxmc' => ['like','%检%']
  829. ];
  830. $filed = 'rtrim(Gy0_gdbh) as gdbh,rtrim(Gy0_yjno) as yjno,rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(人工检_正品板) as 人工正品板,
  831. rtrim(人工检_次品板) as 人工次品板,rtrim(人工检_废检) as 人工废检,rtrim(机检_正品板) as 机检正品板,rtrim(机检_次品板) as 机检次品板,
  832. rtrim(机检_废检) as 机检废检,rtrim(Gy0_sbbh) as 设备编号,rtrim(Uniqid) as Uniqid';
  833. $list = \db('工单_工艺资料')->where($where)->field($filed)->select();
  834. if (empty($list)){
  835. $this->success('未找到该工单工艺');
  836. }
  837. $name = \db('工单_基本资料')
  838. ->where('Gd_gdbh',$workOrder)
  839. ->field('rtrim(Gd_cpdh) as 产品代号,rtrim(Gd_khmc) as 客户名称,rtrim(Gd_cpmc) as 产品名称')
  840. ->find();
  841. if (empty($name)){
  842. $this->success('未找到该工单');
  843. }
  844. foreach ($list as $key=>$value){
  845. if ($value['yjno']<10){
  846. $value['yjno'] = '0'.$value['yjno'];
  847. }
  848. if ($value['gxh']<10){
  849. $value['gxh'] = '0'.$value['gxh'];
  850. }
  851. $list[$key]['印件工序及工艺'] = $value['gdbh'].'-'.$value['yjno'].'-'.$value['gxh'].'-'.$value['gxmc'];
  852. unset($list[$key]['gdbh'],$list[$key]['yjno'],$list[$key]['gxmc']);
  853. $list[$key]['产品编号'] = $name['产品代号'];
  854. $list[$key]['产品名称'] = $name['产品名称'];
  855. $list[$key]['客户名称'] = $name['客户名称'];
  856. }
  857. $this->success('成功',$list);
  858. }
  859. /**
  860. * 产品质检系数调整->系数修改
  861. * @ApiMethod (GET)
  862. * @param string $workorder 工单编号
  863. * @param string $processCode 工序号
  864. * @param float $code1 人工正品板
  865. * @param float $code2 人工次品板
  866. * @param float $code3 人工废检
  867. * @param float $code4 机检正品板
  868. * @param float $code5 机检次品板
  869. * @param float $code6 机检废检
  870. * @return void
  871. * @throws \think\Exception
  872. * @throws \think\exception\PDOException
  873. */
  874. public function TestCoefficientEdit()
  875. {
  876. if (Request::instance()->isPost() === false){
  877. $this->error('请求错误');
  878. }
  879. $workOrder = input('workOrder');
  880. $processCode = input('processCode');
  881. $row = [
  882. '人工检_正品板' => input('code1'),
  883. '人工检_次品板' => input('code2'),
  884. '人工检_废检' => input('code3'),
  885. '机检_正品板' => input('code4'),
  886. '机检_次品板' => input('code5'),
  887. '机检_废检' => input('code6'),
  888. ];
  889. if (empty($workOrder) || empty($processCode)){
  890. $this->error('参数错误');
  891. }
  892. $where = [
  893. 'Gy0_gdbh' => $workOrder,
  894. 'Gy0_gxh' => $processCode
  895. ];
  896. $sql = \db('工单_工艺资料')->where($where)->fetchSql(true)->update($row);
  897. $res = Db::query($sql);
  898. if ($res !== false){
  899. $this->success('成功');
  900. }else{
  901. $this->error('失败');
  902. }
  903. }
  904. /**
  905. * 修正工单核算参数->数据获取
  906. * @ApiMethod (GET)
  907. * @param string $workOrder 工单编号
  908. * @return void
  909. * @throws \think\db\exception\DataNotFoundException
  910. * @throws \think\db\exception\ModelNotFoundException
  911. * @throws \think\exception\DbException
  912. */
  913. public function AccountingParameter()
  914. {
  915. if ($this->request->isGet() === false){
  916. $this->error('请求错误');
  917. }
  918. $workOrder = input('workOrder');
  919. if (empty($workOrder)){
  920. $this->error('参数错误');
  921. }
  922. $field = 'rtrim(Gy0_方案) as 方案,rtrim(Gy0_yjno) as yjno,rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc,
  923. rtrim(Gy0_sbbh) as 参照设备,rtrim(工价系数) as 难度系数,rtrim(Gy0_shdh) as 损耗代号,rtrim(Gy0_Rate0) as 基础损耗,rtrim(Gy0_Rate1) as 损耗率,
  924. rtrim(印刷方式) as 印刷方式,rtrim(版距) as 版距,rtrim(Gy0_ms) as 计损色数,rtrim(损耗系数) as 损耗系数,rtrim(UniqId) as UniqId';
  925. $list = \db('工单_工艺资料')->where('Gy0_gdbh',$workOrder)->field($field)->select();
  926. if (empty($list)){
  927. $this->success('未找到该工单工艺资料');
  928. }
  929. foreach ($list as $key=>$value){
  930. if ($value['yjno']<10){
  931. $value['yjno'] = '0'.$value['yjno'];
  932. }
  933. if ($value['gxh']<10){
  934. $value['gxh'] = '0'.$value['gxh'];
  935. }
  936. $list[$key]['印件号及工序名称'] = $value['yjno'].'-'.$value['gxh'].$value['gxmc'].'('.$value['add_gxmc'].')';
  937. unset($list[$key]['yjno'],$list[$key]['gxmc'],$list[$key]['add_gxmc']);
  938. }
  939. $this->success('成功',$list);
  940. }
  941. /**
  942. * 修正工单核算参数->参数修改
  943. * @ApiMethod (POST)
  944. * @param void
  945. * @return void
  946. * @throws \think\Exception
  947. * @throws \think\db\exception\DataNotFoundException
  948. * @throws \think\db\exception\ModelNotFoundException
  949. * @throws \think\exception\DbException
  950. * @throws \think\exception\PDOException
  951. */
  952. public function AccountingParameterEdit()
  953. {
  954. if (Request::instance()->isPost() === false){
  955. $this->error('请求错误');
  956. }
  957. $param = Request::instance()->post();
  958. if (empty($param) || isset($param[0]['Uniqid']) === false){
  959. $this->error('参数错误');
  960. }
  961. $i = 0;
  962. foreach ($param as $key=>$value){
  963. $data['rate0'] = 0;
  964. $data['rate1'] = 0;
  965. $rate = \db('dic_lzsh')->where('sys_bh',$value['loss'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->find();
  966. if (!empty($rate)){
  967. $data['rate0'] = $rate['rate0'];
  968. $data['rate1'] = $rate['rate1'];
  969. }
  970. $row = [
  971. '工价系数' => $value['difficulty']?:'',
  972. 'Gy0_shdh' => $value['loss']?:'',
  973. '印刷方式' => $value['printMode']?:'',
  974. '版距' => $value['plate']?:'',
  975. 'Gy0_ms' => $value['chromatic']?:'',
  976. '损耗系数' => $value['wastage']?:'',
  977. 'Gy0_Rate0' => $data['rate0'],
  978. 'Gy0_Rate1' => $data['rate1']
  979. ];
  980. $sql = \db('工单_工艺资料')->where('Uniqid',$value['Uniqid'])->fetchSql(true)->update($row);
  981. $res = Db::query($sql);
  982. if ($res !== false){
  983. $i++;
  984. }
  985. }
  986. if ($i !== 0){
  987. $this->success('成功');
  988. }else{
  989. $this->error('失败');
  990. }
  991. }
  992. /**
  993. * 印件资料修改
  994. * @ApiMethod (POST)
  995. * @param void
  996. * @return void
  997. * @throws \think\Exception
  998. * @throws \think\exception\PDOException
  999. */
  1000. public function PrintedEdit()
  1001. {
  1002. if (Request::instance()->isPost() === false){
  1003. $this->error('请求错误');
  1004. }
  1005. $param = Request::instance()->post();
  1006. if (empty($param) || isset($param['Uniqid']) === false){
  1007. $this->error('参数错误');
  1008. }
  1009. $param['Yj_Gdbh'] = \db('工单_印件资料')->where('Uniqid',$param['Uniqid'])->value('Yj_Gdbh');
  1010. $data = [
  1011. 'Yj_Gdbh' =>$param['Yj_Gdbh'],
  1012. 'yj_Yjno' =>$param['yjno'],
  1013. 'yj_Yjdh' =>$param['yjdh'],
  1014. 'yj_yjmc' =>$param['yjmc'],
  1015. 'yj_zzdh' =>$param['zzdh'],
  1016. 'yj_zzdh1' =>$param['zzdh1'],
  1017. 'yj_zzdh2' =>$param['zzdh2'],
  1018. 'yj_zzdh3' =>$param['zzdh3'],
  1019. 'yj_zzdh4' =>$param['zzdh4'],
  1020. 'yj_zzmc' =>$param['zzmc'],
  1021. 'yj_zzmc1' =>$param['zzmc1'],
  1022. 'yj_zzmc2' =>$param['zzmc2'],
  1023. 'yj_zzmc3' =>$param['zzmc3'],
  1024. 'yj_zzmc4' =>$param['zzmc4'],
  1025. 'yj_tlgg' =>$param['tlgg'],
  1026. 'yj_klgg' =>$param['klgg'],
  1027. 'Yj_核算规格' =>$param['hsgg'],
  1028. 'yj_成品数量' =>$param['cpsl'],
  1029. 'yj_平张投料' =>$param['pztl'],
  1030. 'yj_ks' =>$param['ks'],
  1031. 'yj_ls' =>$param['ls'],
  1032. 'yj_desc' =>$param['desc'],
  1033. ];
  1034. $UniqId = $param['Uniqid'];
  1035. $sql = \db('工单_印件资料')->where('Uniqid',$UniqId)->fetchSql(true)->update($data);
  1036. $res = Db::query($sql);
  1037. $process = \db('工单_工艺资料')
  1038. ->where('Gy0_gdbh',$data['Yj_Gdbh'])
  1039. ->where('Gy0_yjno',$data['yj_Yjno'])
  1040. ->select();
  1041. if ((int)$data['yj_平张投料'] > 0 && !empty($process)){
  1042. //重新分配工序计划产量
  1043. $result = $this->PlannedProcessYield($data['Yj_Gdbh'],$data['yj_Yjno'],0,$data['yj_平张投料']);
  1044. if ($result === false){
  1045. $this->success('修改工序产量失败');
  1046. }
  1047. }
  1048. if ($res !== false){
  1049. $this->success('成功');
  1050. }else{
  1051. $this->error('失败');
  1052. }
  1053. }
  1054. /**
  1055. * 工艺资料修改
  1056. * @ApiMethod (POST)
  1057. * @param void
  1058. * @return void
  1059. * @throws \think\Exception
  1060. * @throws \think\db\exception\DataNotFoundException
  1061. * @throws \think\db\exception\ModelNotFoundException
  1062. * @throws \think\exception\DbException
  1063. * @throws \think\exception\PDOException
  1064. */
  1065. public function ProcessDetailEdit()
  1066. {
  1067. if (Request::instance()->isPost() === false){
  1068. $this->error('请求错误');
  1069. }
  1070. $param = Request::instance()->post();
  1071. if (empty($param) || isset($param['UniqId']) === false){
  1072. $this->error('参数错误');
  1073. }
  1074. if (empty($param['Gy0_shdh'])){
  1075. $rate['rate0'] = 0;
  1076. $rate['rate1'] = 0;
  1077. }else{
  1078. $rate = \db('dic_lzsh')->where('sys_bh',$param['Gy0_shdh'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->find();
  1079. }
  1080. if ($param['备选工序'] == ''){
  1081. $param['备选工序'] = null;
  1082. }
  1083. $param['Gy0_Rate0']= isset($rate['rate0'])?$rate['rate0']:0;
  1084. $param['Gy0_Rate1'] = isset($rate['rate1'])?$rate['rate1']:0;
  1085. $param['Mod_rq'] = date('Y-m-d H:i:s',time());
  1086. $UniqId = $param['UniqId'];
  1087. unset($param['UniqId']);
  1088. //获取工单第一道工艺编号
  1089. $minGxh = \db('工单_工艺资料')->where('Gy0_gdbh',$param['Gy0_gdbh'])->column('min(Gy0_gxh) as gxh');
  1090. //修改工艺资料
  1091. $sql = \db('工单_工艺资料')->where('UniqId',$UniqId)->fetchSql(true)->update($param);
  1092. $res = Db::query($sql);
  1093. //获取工艺资料数据
  1094. $list = \db('工单_工艺资料')->where('UniqId',$UniqId)->field('Gy0_yjno,Gy0_gxh,rtrim(Gy0_计划接货数) as 计划接货数')->find();
  1095. //如果是第一道工序需从印件资料中获取计划产量
  1096. $list['计划接货数'] = \db('工单_印件资料')->where('Yj_Gdbh',$param['Gy0_gdbh'])->where('yj_Yjno',$param['Gy0_yjno'])->column('yj_平张投料')[0];
  1097. //修改工单状态
  1098. $status = \db('工单_基本资料')->where('Gd_gdbh',$param['Gy0_gdbh'])->field('rtrim(gd_statu) as status')->find();
  1099. if ($status['status'] !== '2-生产中'){
  1100. $statusSql = \db('工单_基本资料')->where('Gd_gdbh',$param['Gy0_gdbh'])->fetchSql(true)->update(['gd_statu'=>'2-生产中']);
  1101. Db::query($statusSql);
  1102. }
  1103. //重新分配工序计划产量
  1104. if ((int)$list['计划接货数'] > 0){
  1105. $result = $this->PlannedProcessYield($param['Gy0_gdbh'],$list['Gy0_yjno'],0,$list['计划接货数']);
  1106. }
  1107. if ($res !== false){
  1108. $this->success('成功');
  1109. }else{
  1110. $this->error('失败');
  1111. }
  1112. }
  1113. /**
  1114. * 工艺资料编辑->机台列表获取
  1115. * @return void
  1116. * @throws \think\db\exception\DataNotFoundException
  1117. * @throws \think\db\exception\ModelNotFoundException
  1118. * @throws \think\exception\DbException
  1119. */
  1120. public function MachineList()
  1121. {
  1122. if ($this->request->isGet() === false){
  1123. $this->error('请求错误');
  1124. }
  1125. $param = $this->request->param();
  1126. if (empty($param)){
  1127. $this->error('参数错误');
  1128. }
  1129. $list = \db('设备_基本资料')
  1130. ->where('使用部门',$param['address'])
  1131. ->where('sys_sbID','<>','')
  1132. ->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')
  1133. ->order('设备编组,设备编号')
  1134. ->select();
  1135. if (empty($list)){
  1136. $this->success('未找到该车间机台');
  1137. }
  1138. $data = [];
  1139. foreach ($list as $key=>$value){
  1140. $data[$key] = $value['设备编号'].'-->'.$value['设备名称'];
  1141. }
  1142. $this->success('成功',$data);
  1143. }
  1144. /**
  1145. * 打印作业通知单->工单印件和工序获取
  1146. * @ApiMethod (GET)
  1147. * @return void
  1148. * @throws \think\db\exception\DataNotFoundException
  1149. * @throws \think\db\exception\ModelNotFoundException
  1150. * @throws \think\exception\DbException
  1151. */
  1152. public function PrintCodeList()
  1153. {
  1154. if ($this->request->isGet() === false){
  1155. $this->error('请求错误');
  1156. }
  1157. $param = $this->request->param();
  1158. if (empty($param)){
  1159. $this->error('参数错误');
  1160. }
  1161. $list = \db('工单_印件资料')
  1162. ->field([
  1163. 'rtrim(yj_Yjno)' => '印件号',
  1164. 'rtrim(yj_yjmc)' => '印件名称'
  1165. ])
  1166. ->where('Yj_Gdbh',$param['workOrder'])
  1167. ->select();
  1168. $this->success('成功',$list);
  1169. }
  1170. /**
  1171. * 打印作业通知单->工艺编号获取
  1172. * @ApiMethod (GET)
  1173. * @return void
  1174. * @throws \think\db\exception\DataNotFoundException
  1175. * @throws \think\db\exception\ModelNotFoundException
  1176. * @throws \think\exception\DbException
  1177. */
  1178. public function ProcessCodeList()
  1179. {
  1180. if ($this->request->isGet() === false){
  1181. $this->error('请求错误');
  1182. }
  1183. $param = $this->request->param();
  1184. if (empty($param)){
  1185. $this->error('参数错误');
  1186. }
  1187. $list = \db('工单_工艺资料')
  1188. ->field('rtrim(Gy0_gxh) as 工序号')
  1189. ->where([
  1190. 'Gy0_gdbh' => $param['workOrder'],
  1191. 'Gy0_yjno' => $param['yjno']
  1192. ])
  1193. ->select();
  1194. $this->success('成功',$list);
  1195. }
  1196. /**
  1197. * 打印作业通知单
  1198. * @ApiMethod (POST)
  1199. * @param void
  1200. * @return void
  1201. * @throws \think\db\exception\DataNotFoundException
  1202. * @throws \think\db\exception\ModelNotFoundException
  1203. * @throws \think\exception\DbException
  1204. */
  1205. public function PrintJobOrder()
  1206. {
  1207. if ($this->request->isGet() === false) {
  1208. $this->error('请求错误');
  1209. }
  1210. $param = $this->request->param();
  1211. if (empty($param)){
  1212. $this->error('参数错误');
  1213. }
  1214. $data = $this->workOrderDetailGet($param['workOrder'],$param['yjno']);
  1215. if (empty($data)){
  1216. $this->success('未找到工单信息');
  1217. }
  1218. $materiel = $this->MaterielDetailGet($param['workOrder']);
  1219. $printDetail = $this->PrintDetailGet($param['workOrder'],$param['yjno'],$param['gxh']);
  1220. if (empty($printDetail)){
  1221. $this->success('未找到工艺信息');
  1222. }
  1223. $number = 0;
  1224. foreach ($printDetail as $key=>$value){
  1225. $value['允损比例'] = (float)substr($value['允损比例'],0,-1);
  1226. $number = $number+$value['允损比例'];
  1227. }
  1228. $data['制单'] = $param['PrepareDocument'];
  1229. $data['审核'] = $param['examine'];
  1230. $data['目标合格率'] = 100-$number.'%';
  1231. $data['materiel'] = $materiel;
  1232. $data['printDetail'] = $printDetail;
  1233. $this->success('成功',$data);
  1234. }
  1235. /**
  1236. * 打印作业通知单->工单及印件资料获取
  1237. * @param $workOrder
  1238. * @return mixed
  1239. */
  1240. public function workOrderDetailGet($workOrder,$yjno)
  1241. {
  1242. $sql = "SELECT
  1243. RTRIM( a.Gd_lx) AS 工单类型,
  1244. RTRIM( a.Gd_gdbh ) AS 生产批次号,
  1245. RTRIM( a.销售订单号 ) AS 销售订单号,
  1246. RTRIM( a.Gd_客户代号 ) AS 客户代号,
  1247. RTRIM( a.Gd_客户名称 ) AS 客户名称,
  1248. RTRIM( a.成品代号 ) AS 产品代码,
  1249. RTRIM( a.成品名称 ) AS 产品名称,
  1250. RTRIM( a.产品版本号 ) AS 版本号,
  1251. RTRIM( a.警语版面 ) AS 警语版面,
  1252. RTRIM( a.码源数量 ) AS 码源数量,
  1253. RTRIM( a.客户ERP编码 ) AS 客户ERP编码,
  1254. RTRIM( a.接单日期 ) AS 开单日期,
  1255. RTRIM( a.交货日期 ) AS 交货日期,
  1256. RTRIM( a.Gd_desc ) AS 工单说明,
  1257. RTRIM( a.投料率 ) AS 投料率,
  1258. RTRIM( a.订单数量 ) AS 订单数量,
  1259. RTRIM( a.平均合格率 ) AS 平均合格率,
  1260. RTRIM( a.投料大箱 ) AS 订货数量,
  1261. RTRIM( a.排产时库存 ) AS 排产时库存,
  1262. RTRIM( b.yj_Yjno ) AS 印件,
  1263. RTRIM( b.yj_Yjdh ) AS 印件代号,
  1264. RTRIM( b.yj_yjmc ) AS 印件名称,
  1265. RTRIM( b.yj_平张投料 ) AS 平张投料量,
  1266. RTRIM( b.yj_zzmc ) AS 纸张名称,
  1267. RTRIM( b.yj_tlgg ) AS 投料规格,
  1268. RTRIM( b.yj_ks ) AS 开数,
  1269. RTRIM( b.yj_ls ) AS 联数,
  1270. RTRIM( b.yj_desc ) AS 印件备注
  1271. FROM
  1272. `工单_基本资料` AS a
  1273. JOIN `工单_印件资料` AS b ON b.Yj_Gdbh = a.Gd_gdbh
  1274. WHERE
  1275. a.Gd_gdbh = '{$workOrder}' AND b.yj_Yjno = '{$yjno}'";
  1276. $list = Db::query($sql);
  1277. if (empty($list)){
  1278. $this->success('未找到订单数据');
  1279. }
  1280. $list[0]['开单日期'] = date('Y-m-d',strtotime($list[0]['开单日期']));
  1281. $list[0]['交货日期'] = date('Y-m-d',strtotime($list[0]['交货日期']));
  1282. if (strpos($list[0]['产品名称'],'条') !== false){
  1283. $list[0]['订货数量'] = (int)$list[0]['订单数量']*40;
  1284. $list[0]['投料数量'] = intval($list[0]['平张投料量']*$list[0]['联数']/250);
  1285. }else{
  1286. $list[0]['订货数量'] = (int)$list[0]['订单数量']*4;
  1287. $list[0]['投料数量'] = intval($list[0]['平张投料量']*$list[0]['联数']/2500);
  1288. }
  1289. $list[0]['联数'] = (int)$list[0]['联数'];
  1290. $list[0]['印件代号及名称'] = $list[0]['印件代号'].' '.$list[0]['印件名称'];
  1291. // $list[0]['投料数量'] = $list[0]['订货数量'];
  1292. unset($list[0]['印件代号'],$list[0]['印件名称']);
  1293. return($list[0]);
  1294. }
  1295. /**打印作业流程单->物料资料获取
  1296. * @param $workOrder
  1297. * @return bool|\PDOStatement|string|\think\Collection
  1298. * @throws \think\db\exception\DataNotFoundException
  1299. * @throws \think\db\exception\ModelNotFoundException
  1300. * @throws \think\exception\DbException
  1301. */
  1302. public function MaterielDetailGet($workOrder)
  1303. {
  1304. $where = [
  1305. 'BOM_工单编号' => $workOrder,
  1306. ];
  1307. $filed = 'rtrim(BOM_物料编码) as 物料编码,rtrim(BOM_物料名称) as 物料名称,rtrim(BOM_投料单位) as 投料单位,rtrim(BOM_计划用量) as 计划用量';
  1308. $list = \db('工单_bom资料')->where($where)->field($filed)->select();
  1309. if (!empty($list)){
  1310. foreach ($list as $key=>$value){
  1311. $list[$key]['物料代码及名称'] = $value['物料编码'].' '.$value['物料名称'];
  1312. $list[$key]['计划用量'] = (float)$value['计划用量'];
  1313. unset($list[$key]['物料编码'],$list[$key]['物料名称']);
  1314. }
  1315. }
  1316. return $list;
  1317. }
  1318. /**
  1319. * 打印作业流程单->工艺资料获取
  1320. * @param $workOrder
  1321. * @return bool|\PDOStatement|string|\think\Collection
  1322. * @throws \think\db\exception\DataNotFoundException
  1323. * @throws \think\db\exception\ModelNotFoundException
  1324. * @throws \think\exception\DbException
  1325. */
  1326. public function PrintDetailGet($workOrder,$yjno,$gxh)
  1327. {
  1328. $where = [
  1329. 'Gy0_gdbh' => $workOrder,
  1330. 'Gy0_yjno' => $yjno,
  1331. 'Gy0_gxh' => ['<=',$gxh]
  1332. ];
  1333. $filed = 'rtrim(Gy0_yjno) as yjno,rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc,
  1334. rtrim(损耗系数) as 损耗系数,rtrim(Gy0_ls) as ls,rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_计划损耗) as 计划损耗,
  1335. rtrim(Gy0_辅助工时) as 装版工时,rtrim(Gy0_小时产能) as 小时定额,rtrim(Gy0_生产工时) as 生产工时,rtrim(工序备注) as 工序备注';
  1336. $list = \db('工单_工艺资料')
  1337. ->where($where)
  1338. ->field($filed)
  1339. ->select();
  1340. if (empty($list)){
  1341. $this->success('工单工艺为空');
  1342. }
  1343. foreach ($list as $key=>$value){
  1344. if ($value['yjno']<10){
  1345. $value['yjno'] = '0'.$value['yjno'];
  1346. }
  1347. if ($value['gxh']<10){
  1348. $value['gxh'] = '0'.$value['gxh'];
  1349. }
  1350. if ($value['add_gxmc'] !== null){
  1351. $list[$key]['印件及工序名称'] = $value['yjno'].'-'.$value['gxh'].'-->'.$value['gxmc'].'【'.$value['add_gxmc'].'】';
  1352. }else{
  1353. $list[$key]['印件及工序名称'] = $value['yjno'].'-'.$value['gxh'].'-->'.$value['gxmc'];
  1354. }
  1355. $list[$key]['转序数'] = (int)($value['计划接货数']/$value['ls']);
  1356. $list[$key]['报废定额'] = (int)($value['计划损耗']/$value['ls']);
  1357. if ((int)$value['计划接货数'] === 0){
  1358. $list[$key]['允损比例'] = 0;
  1359. }else{
  1360. $list[$key]['允损比例'] = round(($value['计划损耗']/$value['计划接货数'])*100,2).'%';
  1361. }
  1362. unset($list[$key]['yjno'],$list[$key]['gxh'],$list[$key]['gxmc'],$list[$key]['add_gxmc'],$list[$key]['计划接货数'],$list[$key]['计划损耗']);
  1363. }
  1364. return $list;
  1365. }
  1366. /**
  1367. * 获取小时产能
  1368. * @ApiMethod (GET)
  1369. * @param void
  1370. * @return void
  1371. * @throws \think\db\exception\DataNotFoundException
  1372. * @throws \think\db\exception\ModelNotFoundException
  1373. * @throws \think\exception\DbException
  1374. */
  1375. public function capacityList()
  1376. {
  1377. if ($this->request->isGet() === false){
  1378. $this->error('请求错误');
  1379. }
  1380. $param = $this->request->param();
  1381. if (empty($param)){
  1382. $this->error('参数错误');
  1383. }
  1384. $machine = explode(' ',$param['machine'])[0];
  1385. $number = \db('设备_基本资料')->where('设备编号',$machine)->field('rtrim(排单小时定额) as 小时产能')->find();
  1386. if (empty($number)){
  1387. $this->error('未找到小时产能');
  1388. }
  1389. $this->success('成功',$number['小时产能']);
  1390. }
  1391. /**
  1392. * 新增工单->添加工单
  1393. * @ApiMethod (POST)
  1394. * @param
  1395. * @return void
  1396. * @throws \think\Exception
  1397. * @throws \think\db\exception\BindParamException
  1398. * @throws \think\db\exception\DataNotFoundException
  1399. * @throws \think\db\exception\ModelNotFoundException
  1400. * @throws \think\exception\DbException
  1401. * @throws \think\exception\PDOException
  1402. */
  1403. public function WorkOrderAdd()
  1404. {
  1405. if (Request::instance()->isPost() === false){
  1406. $this->error('请求错误');
  1407. }
  1408. $param = Request::instance()->post();
  1409. if (empty($param)){
  1410. $this->error('参数错误');
  1411. }
  1412. if (isset($param['sort'])){
  1413. $sort = 2;
  1414. unset($param['sort']);
  1415. }else{
  1416. $sort = 1;
  1417. }
  1418. $num = \db('工单_基本资料')->where('Gd_gdbh',$param['gdbh'])->count();
  1419. //插入产品资料
  1420. $productData = \db('产品_基本资料')
  1421. ->where('产品编号',$param['cpdh'])
  1422. ->count();
  1423. if ($productData === 0) {
  1424. $clientCode = substr($param['cpdh'], 0, 5);
  1425. $product = [
  1426. '客户编号' => $clientCode,
  1427. '客户名称' => $param['khmc'],
  1428. '产品编号' => $param['cpdh'],
  1429. '产品名称' => $param['cpmc'],
  1430. '计量单位' => '万张',
  1431. '状态' => '',
  1432. 'Mod_rq' => date('Y-m-d H:i:s', time()),
  1433. 'UniqID' => \db('产品_基本资料')->order('UniqID desc')->value('UniqID') + 1,
  1434. ];
  1435. if (strpos($product['产品名称'], '小盒') === false) {
  1436. $product['产品类别'] = '条盒';
  1437. } else {
  1438. $product['产品类别'] = '小盒';
  1439. }
  1440. $productSql = \db('产品_基本资料')->fetchSql(true)->insert($product);
  1441. \db()->query($productSql);
  1442. }
  1443. //添加工单
  1444. $productDetail = \db('产品_基本资料')->where('产品编号',$param['cpdh'])->find();
  1445. if (empty($productDetail)){
  1446. $productDetail['客户料号'] = '';
  1447. }
  1448. $lastId = \db('工单_基本资料')->order('Uniqid desc')->value('Uniqid');
  1449. $data = [
  1450. 'Gd_lx' =>$param['zdgd'],
  1451. 'Gd_生产分类' =>$param['sclx'],
  1452. '成本处理类别' =>'',
  1453. 'Gd_gdbh' =>$param['gdbh'],
  1454. '行号' =>$num+1 ,
  1455. 'Gd_客户代号' =>$param['khdh'],
  1456. 'Gd_客户名称' =>$param['khmc'],
  1457. 'Gd_khdh' =>$param['khdh'],
  1458. 'Gd_khmc' =>$param['khmc'],
  1459. '客户料号' =>rtrim($productDetail['客户料号']),
  1460. '客户ERP编码' =>$param['erp'],
  1461. 'Gd_cpdh' =>'',
  1462. 'Gd_cpmc' =>'',
  1463. '成品代号' =>$param['cpdh'],
  1464. '成品名称' =>$param['cpmc'],
  1465. '产品版本号' =>$param['bbh'],
  1466. '销售订单号' =>$param['xsddh'],
  1467. '警语版面' =>$param['jybm'],
  1468. '码源数量' =>$param['mysl'],
  1469. '排产时库存' =>$param['kcdx'],
  1470. '投料大箱' =>$param['tldx'],
  1471. '投料率' =>$param['tll'],
  1472. '平均合格率' =>$param['hgl'],
  1473. '进程备注' =>$param['jcbz'],
  1474. 'Gd_desc' =>$param['remark'],
  1475. '开单日期' =>date('Y-m-d H:i:s',time()),
  1476. '接单日期' =>$param['start'],
  1477. '交货日期' =>$param['end'],
  1478. '订单数量' =>$param['number'],
  1479. '计量单位' =>$param['tldw'],
  1480. '计划投料' =>$param['pztl'],
  1481. '实际投料' =>$param['wxz'],
  1482. '产品单价' =>0,
  1483. '入仓日期' =>'1900-01-01 00:00:00',
  1484. '工单入仓数量' =>0,
  1485. '工单制程废品' => 0,
  1486. '工单质检废品' => 0,
  1487. '工单无形损' => 0,
  1488. '工单计划损耗' => 0,
  1489. '工单完工日期' => $param['end'],
  1490. '投料确认' => '',
  1491. 'gd_statu' => '3-计划中',
  1492. '直接人工' => 0,
  1493. '分摊人工' => 0,
  1494. '直接材料' => 0,
  1495. '考核直接材料' => 0,
  1496. '分摊材料' => 0,
  1497. '考核分摊材料' => 0,
  1498. '直接折旧' => 0,
  1499. '水电气费' => 0,
  1500. '分摊空调' => 0,
  1501. '分摊锅炉' => 0,
  1502. '分摊废气处理' => 0,
  1503. '分摊空压机' => 0,
  1504. '分摊鼓风机' => 0,
  1505. '分摊其他' => 0,
  1506. '待摊人工' => 0,
  1507. '待摊折旧' => 0,
  1508. '待摊场地租金' => 0,
  1509. '待摊其他费用' => 0,
  1510. '加工费' => 0,
  1511. '加工费单价' => 0,
  1512. '成本考核_胶印' => 1,
  1513. '成本考核_凹印' => 1,
  1514. '成本考核_丝印' => 1,
  1515. '成本考核_模切' => 1,
  1516. '成本考核_检验' => 1,
  1517. '印版费' => 0,
  1518. 'V23制造成本' => 0,
  1519. 'Prt_rq' => date('Y-m-d H:i:s',time()),
  1520. 'Sys_id' => $param['Sys_id'],
  1521. 'Sys_rq' => date('Y-m-d H:i:s',time()),
  1522. 'Mod_rq' => date('Y-m-d H:i:s',time()),
  1523. 'U8UID' => '',
  1524. 'Uniqid' => $lastId+1,
  1525. '工序加工费' => 0,
  1526. '工单分类' => $sort,
  1527. ];
  1528. $sql= \db('工单_基本资料')->fetchSql(true)->insert($data);
  1529. $res = \db()->query($sql);
  1530. if ($res !== false){
  1531. $this->success('成功');
  1532. }else{
  1533. $this->error('失败');
  1534. }
  1535. }
  1536. /**
  1537. * 新增工单->客户代号列表获取
  1538. * @return void
  1539. * @throws \think\db\exception\BindParamException
  1540. * @throws \think\exception\PDOException
  1541. */
  1542. public function ClientList()
  1543. {
  1544. if ($this->request->isGet() === false){
  1545. $this->error('请求错误');
  1546. }
  1547. $param = $this->request->param();
  1548. if (isset($param['search'])){
  1549. $where = $param['search'].'%';
  1550. $sql = "SELECT DISTINCT
  1551. (客户编号),rtrim(客户名称 ) as 客户名称
  1552. FROM
  1553. `产品_基本资料`
  1554. WHERE
  1555. 客户编号 LIKE "."'".$where."'"."
  1556. OR
  1557. 客户名称 LIKE "."'".$where."'"."
  1558. GROUP BY
  1559. 客户编号
  1560. order by
  1561. 客户编号";
  1562. }else{
  1563. $sql = "SELECT DISTINCT
  1564. (客户编号),rtrim(客户名称 ) as 客户名称
  1565. FROM
  1566. `产品_基本资料`
  1567. GROUP BY
  1568. 客户编号
  1569. order by
  1570. 客户编号";
  1571. }
  1572. $list = \db()->query($sql);
  1573. if (empty($list)){
  1574. $this->success('未找到客户列表');
  1575. }
  1576. foreach ($list as $key=>$value){
  1577. if (empty($value['客户编号'])){
  1578. unset($list[$key]);
  1579. }else{
  1580. $list[$key]['客户编号'] = rtrim($value['客户编号']);
  1581. $list[$key]['name'] = rtrim($value['客户编号']).'【'.$value['客户名称'].'】';
  1582. if ($value['客户编号'] == '1098'){
  1583. $list[$key]['客户名称'] = '打样专用';
  1584. }
  1585. }
  1586. }
  1587. $list = array_values($list);
  1588. $this->success('成功',$list);
  1589. }
  1590. /**
  1591. * 新增工单->产品代号获取
  1592. * @ApiMethod (GET)
  1593. * @param void
  1594. * @return void
  1595. * @throws \think\db\exception\DataNotFoundException
  1596. * @throws \think\db\exception\ModelNotFoundException
  1597. * @throws \think\exception\DbException
  1598. */
  1599. public function ProductCodeList()
  1600. {
  1601. if ($this->request->isGet() === false){
  1602. $this->error('请求错误');
  1603. }
  1604. $param = $this->request->param();
  1605. if (isset($param['cilent']) === false){
  1606. $this->error('参数错误');
  1607. }
  1608. $where = ['产品编号'=>['like',$param['cilent'].'%']];
  1609. $list = \db('产品_基本资料')
  1610. ->where($where)
  1611. ->field('rtrim(产品编号) as 产品编号,rtrim(产品名称) as 产品名称')
  1612. ->limit(50)
  1613. ->select();
  1614. if (empty($list)){
  1615. $this->success('未获取到产品数据');
  1616. }
  1617. $res = db('产品_工艺资料')->where('Gy0_cpdh',$list[0]['产品编号'])->distinct(true)->column('rtrim(Gy0_方案) as gy_plan');
  1618. $list[0]['gy'] = $res;
  1619. foreach ($list as $key=>$value){
  1620. $list[$key]['name'] = $value['产品编号'].'【'.$value['产品名称'].'】';
  1621. }
  1622. $this->success('成功',$list);
  1623. }
  1624. /**
  1625. * 新增印件资料->印件资料添加
  1626. * @return void
  1627. * @throws \think\db\exception\BindParamException
  1628. * @throws \think\exception\PDOException
  1629. */
  1630. public function PrintDetailAdd()
  1631. {
  1632. if (Request::instance()->isPost() === false){
  1633. $this->error('请求错误');
  1634. }
  1635. $param = Request::instance()->post();
  1636. if (empty($param)){
  1637. $this->error('参数错误');
  1638. }
  1639. $lastId = \db('工单_印件资料')->order('Uniqid desc')->value('Uniqid');
  1640. if (empty($lastId)){
  1641. $lastId = 0;
  1642. }else{
  1643. $lastId = $lastId + 1;
  1644. }
  1645. $param['Uniqid'] = $lastId;
  1646. $param['Sys_rq'] = date('Y-m-d H:i:s',time());
  1647. $param['Mod_rq'] = date('Y-m-d H:i:s',time());
  1648. //判断印件号是否存在在工单基本资料表中,存在不增加行号,不存在增加行号
  1649. if (empty(\db('工单_基本资料')->where('Gd_gdbh',$param['Yj_Gdbh'])->where('行号',$param['yj_Yjno'])->find())){
  1650. $list = \db('工单_基本资料')->where('Gd_gdbh',$param['Yj_Gdbh'])->find();
  1651. $list['行号'] = $param['yj_Yjno'];
  1652. $list['Gd_cpdh'] = $param['yj_Yjdh'];
  1653. $list['Gd_cpmc'] = $param['yj_yjmc'];
  1654. $list['Sys_id'] = $param['Sys_id'];
  1655. $list['Sys_rq'] = $param['Sys_rq'];
  1656. $list['Mod_rq'] = $param['Mod_rq'];
  1657. unset($list['Uniqid']);
  1658. $workSql = \db('工单_基本资料')->fetchSql(true)->insert($list);
  1659. }else{
  1660. $data['Gd_cpdh'] = $param['yj_Yjdh'];
  1661. $data['Gd_cpmc'] = $param['yj_yjmc'];
  1662. $workSql = \db('工单_基本资料')
  1663. ->where('Gd_gdbh',$param['Yj_Gdbh'])
  1664. ->where('行号',$param['yj_Yjno'])
  1665. ->fetchSql(true)
  1666. ->update($data);
  1667. }
  1668. //开启事务
  1669. Db::startTrans();
  1670. try{
  1671. $sql = \db('工单_印件资料')->fetchSql(true)->insert($param);
  1672. $res = \db()->query($sql);
  1673. $workRes = \db()->query($workSql);
  1674. //提交事务
  1675. \db()->commit();
  1676. } catch (\Exception $e) {
  1677. // 回滚事务
  1678. \db()->rollback();
  1679. }
  1680. if ($res !== false && $workRes !== false){
  1681. $this->success('成功');
  1682. }else{
  1683. $this->error('失败');
  1684. }
  1685. }
  1686. /**
  1687. * 新增工艺资料->工艺资料添加
  1688. * @return void
  1689. * @throws \think\db\exception\BindParamException
  1690. * @throws \think\exception\PDOException
  1691. */
  1692. public function ProcessDetailAdd()
  1693. {
  1694. if (Request::instance()->isPost() === false){
  1695. $this->error('请求错误');
  1696. }
  1697. $param = Request::instance()->post();
  1698. if (empty($param)){
  1699. $this->error('参数错误');
  1700. }
  1701. $lastId = \db('工单_工艺资料')->order('UniqId desc')->value('UniqId');
  1702. if (empty($lastId)){
  1703. $lastId = 0;
  1704. }else{
  1705. $lastId = $lastId + 1;
  1706. }
  1707. if (empty($param['Gy0_shdh'])){
  1708. $param['Gy0_Rate0'] = 0;
  1709. $param['Gy0_Rate1'] = 0;
  1710. }else{
  1711. $detail = \db('dic_lzsh')->field('sys_rate0,sys_rate1')->where('sys_bh',$param['Gy0_shdh'])->find();
  1712. $param['Gy0_Rate0'] = $detail['sys_rate0'];
  1713. $param['Gy0_Rate1'] = $detail['sys_rate1'];
  1714. }
  1715. $param['Sys_rq'] = date('Y-m-d H:i:s',time());
  1716. $param['Mod_rq'] = '1900-01-01 00:00:00';
  1717. $param['Gy0_sj1'] = '1900-01-01 00:00:00';
  1718. $param['Gy0_sj2'] = '1900-01-01 00:00:00';
  1719. $param['PD_WG'] = '1900-01-01 00:00:00';
  1720. $param['UniqId'] = $lastId;
  1721. //添加工序
  1722. $sql = \db('工单_工艺资料')
  1723. ->fetchSql(true)
  1724. ->insert($param);
  1725. $res = \db()->query($sql);
  1726. //获取平张投料
  1727. $number = \db('工单_印件资料')
  1728. ->where('Yj_Gdbh',$param['Gy0_gdbh'])
  1729. ->where('yj_Yjno',$param['Gy0_yjno'])
  1730. ->value('rtrim(yj_平张投料)');
  1731. //分配工艺计划产量
  1732. if ((int)$number >0){
  1733. $this->PlannedProcessYield($param['Gy0_gdbh'],$param['Gy0_yjno'],0,$number);
  1734. }
  1735. if ($res !== false){
  1736. $this->success('成功');
  1737. }else{
  1738. $this->error('失败');
  1739. }
  1740. }
  1741. /**
  1742. * 新增工艺资料->印件编号获取
  1743. * @return void
  1744. * @throws \think\db\exception\DataNotFoundException
  1745. * @throws \think\db\exception\ModelNotFoundException
  1746. * @throws \think\exception\DbException
  1747. */
  1748. public function PrintDetailList()
  1749. {
  1750. if ($this->request->isGet() === false){
  1751. $this->error('请求错误');
  1752. }
  1753. $param = $this->request->param();
  1754. if (empty($param)){
  1755. $this->error('参数错误');
  1756. }
  1757. $printList = \db('工单_印件资料')
  1758. ->where('Yj_Gdbh',$param['workOrder'])
  1759. ->order('yj_Yjno')
  1760. ->select();
  1761. if (empty($printList)){
  1762. $this->success('未找到该工单印件资料');
  1763. }
  1764. $list = [];
  1765. foreach ($printList as $key=>$value){
  1766. $list[$key]['name'] = rtrim($value['yj_Yjno']).'-->'.rtrim($value['yj_yjmc']);
  1767. $list[$key]['no'] = rtrim($value['yj_Yjno']);
  1768. }
  1769. $this->success('成功',$list);
  1770. }
  1771. /**
  1772. * 工单资料管理->印件资料删除
  1773. * @return void
  1774. * @throws \think\Exception
  1775. * @throws \think\exception\PDOException
  1776. */
  1777. public function PrintDetailDel()
  1778. {
  1779. if ($this->request->isGet() === false){
  1780. $this->error('请求错误');
  1781. }
  1782. $param = $this->request->param();
  1783. if (isset($param['UniqId']) === false){
  1784. $this->error('参数错误');
  1785. }
  1786. $printId = explode(',',$param['UniqId']);
  1787. $i = 0;
  1788. foreach ($printId as $value){
  1789. $res = \db('工单_印件资料')
  1790. ->where('Uniqid',$value)
  1791. ->delete();
  1792. if ($res === false){
  1793. $i++;
  1794. }
  1795. }
  1796. if ($i === 0){
  1797. $this->success('删除成功');
  1798. }else{
  1799. $this->error('删除失败');
  1800. }
  1801. }
  1802. /**
  1803. * 工单资料管理->工艺资料删除
  1804. * @return void
  1805. * @throws \think\Exception
  1806. * @throws \think\exception\PDOException
  1807. */
  1808. public function ProcessDetailDel()
  1809. {
  1810. if ($this->request->isGet() === false){
  1811. $this->error('请求错误');
  1812. }
  1813. $param = $this->request->param();
  1814. if (isset($param['UniqId']) === false){
  1815. $this->error('参数错误');
  1816. }
  1817. $printId = explode(',',$param['UniqId']);
  1818. $i = 0;
  1819. //获取工单编号、印件号
  1820. $codeList = \db('工单_工艺资料')
  1821. ->where('UniqId',$printId[0])
  1822. ->field('rtrim(Gy0_gdbh) as 工单编号,rtrim(Gy0_yjno) as 印件号')
  1823. ->find();
  1824. //获取平张投料数量
  1825. $number = \db('工单_印件资料')
  1826. ->where([
  1827. 'Yj_Gdbh' => $codeList['工单编号'],
  1828. 'yj_Yjno' => $codeList['印件号']
  1829. ])
  1830. ->value('rtrim(yj_平张投料)');
  1831. //循环删除工艺资料
  1832. foreach ($printId as $value){
  1833. $res = \db('工单_工艺资料')
  1834. ->where('UniqId',$value)
  1835. ->delete();
  1836. if ($res === false){
  1837. $i++;
  1838. }
  1839. }
  1840. //重新分配工艺计划产量
  1841. if ((int)$number>0){
  1842. $this->PlannedProcessYield($codeList['工单编号'],$codeList['印件号'],0,$number);
  1843. }
  1844. if ($i === 0){
  1845. $this->success('删除成功');
  1846. }else{
  1847. $this->error('删除失败');
  1848. }
  1849. }
  1850. /**
  1851. * 工艺资料添加->工序损耗代码
  1852. * @return void
  1853. * @throws \think\db\exception\DataNotFoundException
  1854. * @throws \think\db\exception\ModelNotFoundException
  1855. * @throws \think\exception\DbException
  1856. */
  1857. public function WastageList()
  1858. {
  1859. if ($this->request->isGet() === false){
  1860. $this->error('请求错误');
  1861. }
  1862. $param = $this->request->param();
  1863. if (empty($param['process'])){
  1864. $this->error('参数错误');
  1865. }
  1866. $order = \db('dic_lzsh')
  1867. ->where('sys_mc','like',$param['process'].'%')
  1868. ->value('rtrim(sys_bh) as 编号');
  1869. $this->success('成功',$order);
  1870. }
  1871. /**
  1872. * 获取产品附件列表
  1873. */
  1874. public function getAnnexTable(){
  1875. if(!$this->request->isGet()){
  1876. $this->error('请求方式错误');
  1877. }
  1878. $req = $this->request->param();
  1879. if (isset($req['cpdh']) && !empty($req['cpdh'])){
  1880. $where['关联产品'] = ['LIKE','%'.$req['cpdh'].'%'];
  1881. }else{
  1882. $this->error('参数错误');
  1883. }
  1884. $rows = db('产品_技术附件')
  1885. ->where($where)
  1886. ->select();
  1887. foreach ($rows as $key=>&$value){
  1888. if(mb_detect_encoding($value['附件内容'])!='ASCII'){
  1889. $value['附件内容'] = '';
  1890. }
  1891. }
  1892. $this->success('成功',$rows);
  1893. }
  1894. /**
  1895. * 产品附件新增
  1896. */
  1897. public function annexAdd(){
  1898. if(!$this->request->isPost()){
  1899. $this->error('请求方式错误');
  1900. }
  1901. $req = $this->request->param();
  1902. $arr = [
  1903. 'sys_id',
  1904. '序号',
  1905. '附件备注',
  1906. '附件内容',
  1907. '附件类型',
  1908. '适用工序',
  1909. '关联产品'
  1910. ];
  1911. $data = [];
  1912. foreach ($arr as $key => $value){
  1913. if (!isset($req[$value])){
  1914. $this->error('参数错误',$value,$key+1);
  1915. }
  1916. $data[$value] = $req[$value];
  1917. }
  1918. $data['sys_rq'] = date('Y-m-d H:i:s');
  1919. //查询UniqId
  1920. $UniqId = db('产品_技术附件')->max('UniqId');
  1921. $data['UniqId'] = $UniqId < 10000000 ? 10000000 : $UniqId + 1;
  1922. //开启事务
  1923. db()->startTrans();
  1924. try{
  1925. $sql = db('产品_技术附件')->fetchSql(true)->insert($data);
  1926. $bool = db()->query($sql);
  1927. // 提交事务
  1928. db()->commit();
  1929. } catch (\Exception $e) {
  1930. // 回滚事务
  1931. db()->rollback();
  1932. $this->error($e->getMessage());
  1933. }
  1934. if($bool===false) $this->error('失败');
  1935. $this->success('成功');
  1936. }
  1937. /**
  1938. * 产品附件修改
  1939. * @ApiMethod (GET)
  1940. * @param string 'UniqId'
  1941. */
  1942. public function annexDel()
  1943. {
  1944. if(!$this->request->isGet()){
  1945. $this->error('请求方式错误');
  1946. }
  1947. $req = $this->request->param();
  1948. if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
  1949. $this->error('参数错误','UniqId',100);
  1950. }
  1951. //开启事务
  1952. db()->startTrans();
  1953. try{
  1954. $bool = db('产品_技术附件')->where('UniqId',$req['UniqId'])->delete();
  1955. // 提交事务
  1956. db()->commit();
  1957. } catch (\Exception $e) {
  1958. // 回滚事务
  1959. db()->rollback();
  1960. $this->error($e->getMessage());
  1961. }
  1962. if($bool===false) $this->error('失败');
  1963. $this->success('成功');
  1964. }
  1965. /**
  1966. * 获取产品附件列表
  1967. */
  1968. public function getGdAnnexTable(){
  1969. if(!$this->request->isGet()){
  1970. $this->error('请求方式错误');
  1971. }
  1972. $req = $this->request->param();
  1973. if (isset($req['gdbh']) && !empty($req['gdbh'])){
  1974. $where['关联编号'] = ['LIKE','%'.$req['gdbh'].'%'];
  1975. }else{
  1976. $this->error('参数错误');
  1977. }
  1978. $rows = db('工单_相关附件')
  1979. ->where($where)
  1980. ->select();
  1981. foreach ($rows as $key=>&$value){
  1982. if(mb_detect_encoding($value['附件内容'])!='ASCII'){
  1983. $value['附件内容'] = '';
  1984. }
  1985. }
  1986. $this->success('成功',$rows);
  1987. }
  1988. /**
  1989. * 产品附件新增
  1990. */
  1991. public function gdAnnexAdd(){
  1992. if(!$this->request->isPost()){
  1993. $this->error('请求方式错误');
  1994. }
  1995. $req = $this->request->param();
  1996. $arr = [
  1997. 'sys_id',
  1998. '附件备注',
  1999. '附件内容',
  2000. '附件类型',
  2001. '关联编号'
  2002. ];
  2003. $data = [];
  2004. foreach ($arr as $key => $value){
  2005. if (!isset($req[$value])){
  2006. $this->error('参数错误',$value,$key+1);
  2007. }
  2008. $data[$value] = $req[$value];
  2009. }
  2010. $data['sys_rq'] = date('Y-m-d H:i:s');
  2011. //查询UniqId
  2012. $UniqId = db('工单_相关附件')->max('UniqId');
  2013. $data['UniqId'] = $UniqId < 10000000 ? 10000000 : $UniqId + 1;
  2014. //开启事务
  2015. db()->startTrans();
  2016. try{
  2017. $sql = db('工单_相关附件')->fetchSql(true)->insert($data);
  2018. $bool = db()->query($sql);
  2019. // 提交事务
  2020. db()->commit();
  2021. } catch (\Exception $e) {
  2022. // 回滚事务
  2023. db()->rollback();
  2024. $this->error($e->getMessage());
  2025. }
  2026. if($bool===false) $this->error('失败');
  2027. $this->success('成功');
  2028. }
  2029. /**
  2030. * 产品附件修改
  2031. * @ApiMethod (GET)
  2032. * @param string 'UniqId'
  2033. */
  2034. public function gdAnnexDel()
  2035. {
  2036. if(!$this->request->isGet()){
  2037. $this->error('请求方式错误');
  2038. }
  2039. $req = $this->request->param();
  2040. if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
  2041. $this->error('参数错误','UniqId',100);
  2042. }
  2043. //开启事务
  2044. db()->startTrans();
  2045. try{
  2046. $bool = db('工单_相关附件')->where('UniqId',$req['UniqId'])->delete();
  2047. // 提交事务
  2048. db()->commit();
  2049. } catch (\Exception $e) {
  2050. // 回滚事务
  2051. db()->rollback();
  2052. $this->error($e->getMessage());
  2053. }
  2054. if($bool===false) $this->error('失败');
  2055. $this->success('成功');
  2056. }
  2057. /**
  2058. * 引用工单资料数据查询
  2059. * @return void
  2060. * @throws \think\db\exception\DataNotFoundException
  2061. * @throws \think\db\exception\ModelNotFoundException
  2062. * @throws \think\exception\DbException
  2063. */
  2064. public function WorkOrderDetailCope()
  2065. {
  2066. if ($this->request->isGet() === false){
  2067. $this->error('请求错误');
  2068. }
  2069. $param = $this->request->param();
  2070. if (empty($param['search'])){
  2071. $this->error('参数错误');
  2072. }
  2073. $list = \Db('工单_基本资料')
  2074. ->alias('a')
  2075. ->field([
  2076. 'rtrim(a.Gd_gdbh)' => '工单编号',
  2077. 'rtrim(b.客户编号)' => '客户编号',
  2078. 'rtrim(b.客户名称)' => '客户名称',
  2079. 'rtrim(b.产品编号)' => '产品编号',
  2080. 'rtrim(b.产品名称)' => '产品名称'
  2081. ])
  2082. ->join('产品_基本资料 b', 'a.成品代号 = b.产品编号')
  2083. ->join('产品_工艺资料 c', 'a.成品代号 = c.Gy0_cpdh')
  2084. ->join('产品_印件资料 d', 'a.成品代号 = d.yj_cpdh')
  2085. ->where(function($query) use ($param) {
  2086. $query->where('a.Gd_gdbh', 'like', '%'.$param['search'].'%')
  2087. ->whereOr('a.成品名称', 'like', '%'.$param['search'].'%');
  2088. })
  2089. ->where(function($query) {
  2090. $query->where('c.Gy0_cpdh', '<>', '')
  2091. ->where('d.yj_cpdh', '<>', '')
  2092. ->where('b.状态', 'not like', '%停用%')
  2093. ->where('b.产品名称', 'not like', '%停用%');
  2094. })
  2095. ->group('a.Gd_gdbh')
  2096. ->order('a.Uniqid desc')
  2097. ->select();
  2098. if (empty($list)){
  2099. $this->success('未找到工单资料');
  2100. }else{
  2101. $this->success('成功',$list);
  2102. }
  2103. }
  2104. /**
  2105. * 引用产品印件、工艺资料
  2106. * @return void
  2107. * @throws \think\db\exception\BindParamException
  2108. * @throws \think\db\exception\DataNotFoundException
  2109. * @throws \think\db\exception\ModelNotFoundException
  2110. * @throws \think\exception\DbException
  2111. * @throws \think\exception\PDOException
  2112. */
  2113. public function WorkOrderDetailListCope()
  2114. {
  2115. if (Request::instance()->isPost() === false){
  2116. $this->error('请求错误');
  2117. }
  2118. $param = Request::instance()->post();
  2119. if (empty($param['workorder']) || empty($param['productCode']) || empty($param['option'])){
  2120. $this->error('参数错误');
  2121. }
  2122. if (isset($param['sort'])){
  2123. $priWhere['yj_yjno'] = ['>=',10];
  2124. $proWhere['a.Gy0_yjno'] = ['>=',10];
  2125. }else{
  2126. $priWhere['yj_yjno'] = ['<',10];
  2127. $proWhere['a.Gy0_yjno'] = ['<',10];
  2128. }
  2129. $list = \db('工单_基本资料')
  2130. ->where('Gd_gdbh',$param['workorder'])
  2131. // ->where('成品代号',$param['productCode'])
  2132. ->field('行号,Gd_cpdh')
  2133. ->select();
  2134. $cpdhList = \db('工单_基本资料')
  2135. ->where('Gd_gdbh',$param['workorder'])
  2136. ->column('Gd_cpdh');
  2137. //引用印件资料
  2138. $PrintList = \db('产品_印件资料')
  2139. ->where('yj_cpdh',$param['productCode'])
  2140. ->whereIn('yj_yjdh',$cpdhList)
  2141. ->where($priWhere)
  2142. ->select();
  2143. if (empty($PrintList)){
  2144. $this->error('未找到印件资料');
  2145. }
  2146. $number = \db('工单_基本资料')
  2147. ->where('Gd_gdbh',$param['workorder'])
  2148. ->where('成品代号',$param['productCode'])
  2149. ->value('rtrim(计划投料)');
  2150. $arr = [];
  2151. foreach ($PrintList as $key => $value){
  2152. foreach ($list as $k=>$v){
  2153. if (rtrim($value['yj_yjdh']) === $v['Gd_cpdh']){
  2154. $PrintList[$key]['Yj_Gdbh'] = $param['workorder'];
  2155. $PrintList[$key]['yj_Yjno'] = $value['yj_yjno'];
  2156. $PrintList[$key]['yj_Yjdh'] = $value['yj_yjdh'];
  2157. $PrintList[$key]['yj_ks'] = $value['yj_ks'];
  2158. $PrintList[$key]['yj_ls'] = $value['yj_ls'];
  2159. $PrintList[$key]['yj_平张投料'] = $number;
  2160. $PrintList[$key]['Sys_id'] = $value['sys_id'];
  2161. // $PrintList[$key]['Uniqid'] = $PrintLastId + $key + 1;
  2162. $PrintList[$key]['Sys_rq'] = date('Y-m-d H:i:s',time());
  2163. $PrintList[$key]['Mod_rq'] = date('Y-m-d H:i:s',time());
  2164. array_push($arr,[$value['yj_yjno'],$v['行号']]);
  2165. }
  2166. $sql = \db('工单_基本资料')
  2167. ->where('Gd_gdbh',$param['workorder'])
  2168. ->where('Gd_cpdh',$value['yj_yjdh'])
  2169. ->fetchSql(true)
  2170. ->update(['行号'=>$value['yj_yjno']]);
  2171. \db()->query($sql);
  2172. $bomSql = \db('工单_bom资料')
  2173. ->where('BOM_工单编号',$param['workorder'])
  2174. ->where('BOM_产品编号',$value['yj_yjdh'])
  2175. ->fetchSql(true)
  2176. ->update(['BOM_工单行号'=>$value['yj_yjno']]);
  2177. \db()->query($bomSql);
  2178. }
  2179. unset($PrintList[$key]['mod_rq'],$PrintList[$key]['sys_rq'],$PrintList[$key]['sys_id'],$PrintList[$key]['KgToPages'],$PrintList[$key]['yj_tll'],$PrintList[$key]['yj_yjdh'],$PrintList[$key]['yj_yjno'],$PrintList[$key]['UniqId']);
  2180. }
  2181. //引用工艺资料
  2182. $processWhere = [
  2183. 'a.Gy0_方案' => $param['option'],
  2184. 'a.Gy0_cpdh' => $param['productCode']
  2185. ];
  2186. $yjnolist = \db('工单_基本资料')
  2187. ->where('Gd_gdbh',$param['workorder'])
  2188. ->column('Gd_cpdh');
  2189. $ProcessList = \db('产品_工艺资料')
  2190. ->alias('a')
  2191. ->field('a.*')
  2192. ->join('产品_印件资料 b','a.Gy0_cpdh = b.yj_cpdh AND a.Gy0_yjno = yj_yjno')
  2193. ->where($processWhere)
  2194. ->where($proWhere)
  2195. ->whereIn('b.yj_yjdh',$yjnolist)
  2196. ->order('Gy0_yjno,Gy0_gxh')
  2197. ->select();
  2198. if (empty($ProcessList)){
  2199. $this->error('未找到产品工艺资料');
  2200. }
  2201. $ProcesslastId = \db('工单_工艺资料')->order('UniqId desc')->value('rtrim(UniqId)');
  2202. foreach ($ProcessList as $key=>$value){
  2203. if (empty(trim($value['Gy0_shdh']))){
  2204. $rate['rate0'] = 0;
  2205. $rate['rate1'] = 0;
  2206. }else{
  2207. $rate = \db('dic_lzsh')->where('sys_bh',$value['Gy0_shdh'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->find();
  2208. if (empty($rate)){
  2209. $this->error('该产品印件号'.$value['Gy0_yjno'].'工序号为'.$value['gy0_gxmc'].'的损耗代号错误,请调整之后再引用');
  2210. }
  2211. }
  2212. //设置默认机台
  2213. $machineList = \db('设备_基本资料')
  2214. ->where('生产工序','like','%'.$value['gy0_gxmc'].'%')
  2215. ->where('使用部门','<>','研发中心')
  2216. ->where('设备编组','<>','')
  2217. ->order('设备编号')
  2218. ->value('设备编号');
  2219. $ProcessList[$key]['Gy0_sbbh'] = '';
  2220. if (!empty($machineList)){
  2221. $ProcessList[$key]['Gy0_sbbh'] = $machineList;
  2222. }
  2223. $ProcessList[$key]['Gy0_yjno'] = $value['Gy0_yjno'];
  2224. $ProcessList[$key]['Gy0_gdbh'] = $param['workorder'];
  2225. $ProcessList[$key]['Gy0_gxmc'] = $value['gy0_gxmc'];
  2226. $ProcessList[$key]['Gy0_SITE'] = $value['Gy0_site'];
  2227. $ProcessList[$key]['Gy0_shdh'] = $value['Gy0_shdh'];
  2228. $ProcessList[$key]['Gy0_Rate0'] = $rate['rate0'];
  2229. $ProcessList[$key]['Gy0_Rate1'] = $rate['rate1'];
  2230. $ProcessList[$key]['Gy0_ks'] = $value['Gy0_Ks'];
  2231. $ProcessList[$key]['Gy0_ms'] = $value['Gy0_Ms'];
  2232. $ProcessList[$key]['Gy0_oil'] = $value['Gy0_Oil'];
  2233. $ProcessList[$key]['Gy0_计划接货数'] = 0;
  2234. $ProcessList[$key]['Gy0_计划损耗'] = 0;
  2235. $ProcessList[$key]['无形损承担比例'] = 0;
  2236. $ProcessList[$key]['超节损承担比例'] = 1;
  2237. $ProcessList[$key]['超节损核算单价'] = 0;
  2238. $ProcessList[$key]['Gy0_sj1'] = '1900-01-01 00:00:00';
  2239. $ProcessList[$key]['Gy0_sj2'] = '1900-01-01 00:00:00';
  2240. // $ProcessList[$key]['UniqId'] = $ProcesslastId + $key + 1;
  2241. $ProcessList[$key]['PD_WG'] = '1900-01-01 00:00:00';
  2242. $ProcessList[$key]['Sys_rq'] = date('Y-m-d H:i:s', time());
  2243. unset($ProcessList[$key]['Gy0_Oil'],$ProcessList[$key]['Gy0_Ms'],$ProcessList[$key]['Gy0_Ks'],$ProcessList[$key]['UniqID'],$ProcessList[$key]['Gy0_cpdh'],$ProcessList[$key]['gy0_gxmc'],$ProcessList[$key]['Gy0_site']);
  2244. }
  2245. //插入数据
  2246. \db()->startTrans();
  2247. try {
  2248. \db('工单_工艺资料')->where('Gy0_gdbh',$param['workorder'])->delete();
  2249. $processSql = \db('工单_工艺资料')->fetchSql(true)->insertAll($ProcessList);
  2250. \db()->query($processSql);
  2251. \db('工单_印件资料')->where('Yj_Gdbh',$param['workorder'])->delete();
  2252. $printSql = \db('工单_印件资料')->fetchSql(true)->insertAll($PrintList);
  2253. \db()->query($printSql);
  2254. \db()->commit();
  2255. }catch (\Exception $e){
  2256. \db()->rollback();
  2257. // echo $e->getMessage();
  2258. }
  2259. //计算工序计划生产数量
  2260. if ($number !== null){
  2261. $list = \db('工单_印件资料')->where('Yj_Gdbh',$param['workorder'])->field('yj_Yjno,yj_平张投料')->select();
  2262. foreach ($list as $value){
  2263. if ((int)$value['yj_平张投料'] >0){
  2264. $this->PlannedProcessYield($param['workorder'],$value['yj_Yjno'],0,$value['yj_平张投料']);
  2265. }
  2266. }
  2267. }
  2268. $this->success('成功');
  2269. }
  2270. /**
  2271. * 引用产品印件、工艺资料->信息获取
  2272. * @return void
  2273. * @throws \think\db\exception\DataNotFoundException
  2274. * @throws \think\db\exception\ModelNotFoundException
  2275. * @throws \think\exception\DbException
  2276. */
  2277. public function ProductCopeDetail()
  2278. {
  2279. if ($this->request->isGet() === false){
  2280. $this->error('请求错误');
  2281. }
  2282. $param = $this->request->param();
  2283. if (empty($param['workorder'])){
  2284. $this->error('参数错误');
  2285. }
  2286. $list = \db('工单_基本资料')
  2287. ->alias('a')
  2288. ->field([
  2289. 'rtrim(a.Gd_gdbh)' => '工单编号',
  2290. 'rtrim(b.客户编号)' => '客户编号',
  2291. 'rtrim(b.客户名称)' => '客户名称',
  2292. 'rtrim(b.产品编号)' => '产品编号',
  2293. 'rtrim(b.产品名称)' => '产品名称'
  2294. ])
  2295. ->join('产品_基本资料 b','a.成品代号 = b.产品编号')
  2296. ->where('a.Gd_gdbh',$param['workorder'])
  2297. ->find();
  2298. if (empty($list)){
  2299. $this->error('未找到工单信息');
  2300. }
  2301. $option = \db('产品_工艺资料')
  2302. ->field('rtrim(Gy0_方案) as 方案')
  2303. ->where('Gy0_cpdh',$list['产品编号'])
  2304. ->group('Gy0_方案')
  2305. ->select();
  2306. $list['方案'] = $option;
  2307. $this->success('成功',$list);
  2308. }
  2309. /**
  2310. * 工艺资料计划产量重新分配
  2311. * @param string $workOrder 工单
  2312. * @param int $yjno 印件号
  2313. * @param int $gxh 工序号
  2314. * @param int $feed 平张投料
  2315. * @return bool
  2316. * @throws \think\Exception
  2317. * @throws \think\db\exception\BindParamException
  2318. * @throws \think\db\exception\DataNotFoundException
  2319. * @throws \think\db\exception\ModelNotFoundException
  2320. * @throws \think\exception\DbException
  2321. * @throws \think\exception\PDOException
  2322. */
  2323. public function PlannedProcessYield($workOrder,$yjno,$gxh,$feed)
  2324. {
  2325. $where = [
  2326. 'Gy0_gdbh'=>$workOrder,
  2327. 'Gy0_yjno'=>$yjno,
  2328. ];
  2329. //获取工艺资料
  2330. $processList = \db('工单_工艺资料')
  2331. ->where($where)
  2332. ->field('Gy0_Rate0 as 损耗定额,Gy0_Rate1 as 损耗率,rtrim(损耗系数) as 损耗系数,Gy0_ms,Gy0_ls,UniqId')
  2333. ->order('Gy0_gxh')
  2334. ->select();
  2335. if (empty($processList)){
  2336. $this->success('未找到该工单工序资料');
  2337. }
  2338. //计算损耗定额和计划产量
  2339. $production = [];
  2340. $i = 0;
  2341. foreach ($processList as $key=>$value){
  2342. // if ($key === 0){
  2343. // array_push($production,$feed);
  2344. // }
  2345. // $wastage = 0;
  2346. // if ($value['损耗率'] !== 0 && !empty($value['损耗率'])){
  2347. // $wastage = ($production[$key]*$value['损耗率']+$value['损耗定额'])*$value['损耗系数'];
  2348. // }
  2349. //
  2350. // if ($value['Gy0_ms'] >0 && !empty($value['Gy0_ms'])){
  2351. // $wastage = round($wastage * $value['Gy0_ms']);
  2352. // }
  2353. // if ((int)$value['Gy0_ls'] === 1 && $key>=1){
  2354. // $number = $production[$key]*$processList[$key-1]['Gy0_ls'];
  2355. // }else{
  2356. // $number = $production[$key];
  2357. // }
  2358. // if ($key>=1 && (int)$processList[$key-1]['Gy0_ls'] === 1 && (int)$value['Gy0_ls'] > 1){
  2359. // $number = $number/(int)$value['Gy0_ls'];
  2360. // }
  2361. // array_push($production,ceil($number-$wastage));
  2362. if ($key === 0){
  2363. array_push($production,$feed);
  2364. }else{
  2365. $production[$key] = $production[$key]/$value['Gy0_ls'];
  2366. }
  2367. $wastage = 0;
  2368. if ($value['损耗率'] !== 0 && !empty($value['损耗率'])){
  2369. $wastage = ($production[$key]*$value['损耗率']+$value['损耗定额'])*$value['损耗系数'];
  2370. }
  2371. if ($value['Gy0_ms'] >0 && !empty($value['Gy0_ms'])){
  2372. $wastage = round($wastage * $value['Gy0_ms']);
  2373. }
  2374. array_push($production,ceil($production[$key]-$wastage)*$value['Gy0_ls']);
  2375. $processSql = \db('工单_工艺资料')
  2376. ->where('UniqId',$value['UniqId'])
  2377. ->fetchSql(true)
  2378. ->update(['Gy0_计划接货数'=>$production[$key],'Gy0_计划损耗'=>$wastage]);
  2379. $res = \db()->query($processSql);
  2380. if ($res === false){
  2381. $i++;
  2382. }
  2383. }
  2384. if ($i===0){
  2385. return true;
  2386. }else{
  2387. return false;
  2388. }
  2389. }
  2390. /**
  2391. * 工单资料删除
  2392. * @return void
  2393. * @throws \think\exception\PDOException
  2394. */
  2395. public function WorkOrderDel()
  2396. {
  2397. if ($this->request->isGet() === false){
  2398. $this->error('请求错误');
  2399. }
  2400. $param = $this->request->param();
  2401. if (isset($param['UniqId']) === false){
  2402. $this->error('参数错误');
  2403. }
  2404. $WorkOrderId = explode(',',$param['UniqId']);
  2405. $i = 0;
  2406. foreach ($WorkOrderId as $key=>$value){
  2407. //获取工单编号
  2408. $workorder = \db('工单_基本资料')
  2409. ->where('Uniqid',$value)
  2410. ->value('rtrim(Gd_gdbh)');
  2411. //删除工单资料、工艺资料、印件资料
  2412. \db()->startTrans();
  2413. try {
  2414. \db('工单_基本资料')->where('Gd_gdbh',$workorder)->delete();
  2415. if (!empty(\db('工单_工艺资料')->where('Gy0_gdbh',$workorder)->find())){
  2416. \db('工单_工艺资料')->where('Gy0_gdbh',$workorder)->delete();
  2417. }
  2418. if (!empty(\db('工单_印件资料')->where('Yj_Gdbh',$workorder)->find())){
  2419. \db('工单_印件资料')->where('Yj_Gdbh',$workorder)->delete();
  2420. }
  2421. if (!empty(\db('工单_bom资料')->where('BOM_工单编号',$workorder)->find())){
  2422. \db('工单_bom资料')->where('BOM_工单编号',$workorder)->delete();
  2423. }
  2424. \db()->commit();
  2425. }catch (\Exception $e){
  2426. \db()->rollback();
  2427. $i++;
  2428. }
  2429. }
  2430. if ($i === 0){
  2431. $this->success('删除成功');
  2432. }else{
  2433. $this->error('删除失败');
  2434. }
  2435. }
  2436. /**
  2437. * 修正核算参数-》工单产品信息获取
  2438. * @return void
  2439. * @throws \think\db\exception\DataNotFoundException
  2440. * @throws \think\db\exception\ModelNotFoundException
  2441. * @throws \think\exception\DbException
  2442. */
  2443. public function ProductNameData()
  2444. {
  2445. if ($this->request->isGet() === false){
  2446. $this->error('请求错误');
  2447. }
  2448. $workOrder = input('workOrder');
  2449. if (empty($workOrder)){
  2450. $this->error('参数错误');
  2451. }
  2452. $orderList = \db('工单_基本资料')
  2453. ->field('rtrim(Gd_cpdh) as 印件代号,rtrim(Gd_cpmc) as 印件名称,rtrim(成品代号) as 产品代号,rtrim(成品名称) as 产品名称')
  2454. ->where('Gd_gdbh',$workOrder)
  2455. ->find();
  2456. $this->success('成功',$orderList);
  2457. }
  2458. /**
  2459. * 获取联数
  2460. * @return void
  2461. * @throws \think\db\exception\DataNotFoundException
  2462. * @throws \think\db\exception\ModelNotFoundException
  2463. * @throws \think\exception\DbException
  2464. */
  2465. public function getCouplet()
  2466. {
  2467. if ($this->request->isGet() === false){
  2468. $this->error('请求错误');
  2469. }
  2470. $param = $this->request->param();
  2471. if (empty($param['gdbh']) || empty($param['yjno'])){
  2472. $this->error('参数错误');
  2473. }
  2474. $list = \db('工单_印件资料')
  2475. ->where('Yj_gdbh',$param['gdbh'])
  2476. ->where('yj_Yjno',$param['yjno'])
  2477. ->field('rtrim(yj_ks) as 开数,rtrim(yj_ls) as 联数')
  2478. ->find();
  2479. $process = \db('工单_工艺资料')
  2480. ->where('Gy0_gdbh',$param['gdbh'])
  2481. ->where('Gy0_yjno',$param['yjno'])
  2482. ->order('Gy0_gxh desc')
  2483. ->value('Gy0_gxh');
  2484. $list['工序号'] = $process + 1;
  2485. $this->success('成功',$list);
  2486. }
  2487. }