WorkOrder.php 90 KB

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