WorkOrder.php 67 KB

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