WorkOrder.php 95 KB

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