WorkOrder.php 89 KB

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