WorkOrder.php 90 KB

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