WorkOrder.php 73 KB

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