WorkOrder.php 72 KB

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