WorkOrder.php 96 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\library\Upload;
  5. use Monolog\Handler\IFTTTHandler;
  6. use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
  7. use think\Config;
  8. use think\Db;
  9. use think\Request;
  10. use PhpOffice\PhpSpreadsheet\IOFactory;
  11. use PhpOffice\PhpSpreadsheet\Writer\Pdf\Tcpdf;
  12. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  13. /**
  14. * 工单资料管理
  15. */
  16. class WorkOrder extends Api
  17. {
  18. protected $noNeedLogin = ['*'];
  19. protected $noNeedRight = ['*'];
  20. public function _initialize()
  21. {
  22. if (isset($_SERVER['HTTP_ORIGIN'])) {
  23. header('Access-Control-Expose-Headers: __token__');//跨域让客户端获取到
  24. }
  25. //跨域检测
  26. check_cors_request();
  27. if (!isset($_COOKIE['PHPSESSID'])) {
  28. Config::set('session.id', $this->request->server("HTTP_SID"));
  29. }
  30. parent::_initialize();
  31. }
  32. /**
  33. * 工单资料菜单列表
  34. *
  35. * @ApiMethod (GET)
  36. * @return false|string
  37. * @throws \think\Exception
  38. */
  39. public function DataList()
  40. {
  41. if ($this->request->isGet() === false){
  42. $this->error('请求错误');
  43. }
  44. $data = \db('erp_客户供应商')
  45. ->column('rtrim(编号) as 编号');
  46. $this->success('成功',$data);
  47. }
  48. /**
  49. * 工单基本资料列表
  50. * @ApiMethod (GET)
  51. * @param string $limit 查询长度
  52. * @param string $Gd_khdh 客户代号
  53. * @param string $startTime 接单日期开始时间
  54. * @param string $endTime 接单日期结束时间
  55. * @return \think\response\Json
  56. * @throws \think\exception\DbException
  57. */
  58. public function WorkOrderList()
  59. {
  60. if ($this->request->isGet() === false){
  61. $this->error('请求错误');
  62. }
  63. $search = input('search');
  64. $page = input('page');
  65. $limit = input('limit');
  66. $param = $this->request->param();
  67. $where = [];
  68. if (!empty($search)){
  69. $where['订单编号|生产款号|客户编号|款式|审核|Sys_id'] = ['like','%'.$search.'%'];
  70. }
  71. $total = \db('工单_基本资料')->where($where)->distinct(true)->count();
  72. $list = \db('工单_基本资料')
  73. ->where($where)
  74. ->order('订单编号 desc,Gd_statu desc,Sys_rq desc')
  75. ->limit(($page-1)*$limit,$limit)
  76. ->select();
  77. foreach ($list as $key=>$value){
  78. $number = \db('工单_工艺资料')->where('订单编号',$value['订单编号'])->count();
  79. if ($number === 0){
  80. $list[$key]['status'] = '*';
  81. }else{
  82. $list[$key]['status'] = '';
  83. }
  84. }
  85. $this->success('成功',['data'=>$list,'total'=>$total]);
  86. }
  87. /**
  88. * 编辑页面展示
  89. * @ApiMethod (GET)
  90. * @param string $workOrder 工单编号
  91. * @return void
  92. * @throws \think\db\exception\DataNotFoundException
  93. * @throws \think\db\exception\ModelNotFoundException
  94. * @throws \think\exception\DbException
  95. */
  96. // public function DataCorrection()
  97. // {
  98. // if ($this->request->isGet() === false){
  99. // $this->error('请求错误');
  100. // }
  101. // $workOrder = input('Gd_gdbh');
  102. // if (empty($workOrder)){
  103. // $this->error('参数错误');
  104. // }
  105. // $field = 'rtrim(Gd_lx) as 重点工单,rtrim(Gd_gdbh) as 工单编号,rtrim(Gd_生产分类) as 生产类型,rtrim(Gd_khdh) as 客户代号,rtrim(Gd_客户名称) as 客户名称,
  106. // rtrim(Gd_cpdh) as 印件代号,rtrim(Gd_cpmc) as 印件名称,rtrim(成品代号) as 产品代号,rtrim(成品名称) as 产品名称,rtrim(接单日期) as 开单日期,rtrim(订单数量) as 订单数量,rtrim(交货日期) as 交货日期,
  107. // rtrim(投料率) as 投料率,rtrim(实际投料) as 万小张,rtrim(计量单位) as 单位,rtrim(投料大箱) as 投料大箱,rtrim(排产时库存) as 库存大箱,rtrim(警语版面) as 警语版面,
  108. // rtrim(销售订单号) as 销售订单号,rtrim(产品版本号) as 版本号,rtrim(客户ERP编码) as 客户ERP编码,rtrim(码源数量) as 码源数量,rtrim(进程备注) as 进程备注,rtrim(Gd_desc) as 备注,rtrim(Uniqid) as Uniqid,rtrim(计划投料) as 平张投料';
  109. // $list = \db('工单_基本资料')->where('Gd_gdbh',$workOrder)->field($field)->find();
  110. // if (empty($list)){
  111. // $this->error('未找到该工单信息');
  112. // }
  113. // $printData = \db('工单_印件资料')
  114. // ->where('Yj_Gdbh',$workOrder)
  115. // ->field('rtrim(yj_yjmc) as 印件名称,rtrim(yj_Yjdh) as 印件代号,rtrim(Uniqid) as id')
  116. // ->cache(true,84600)
  117. // ->find();
  118. // if (empty($printData)){
  119. // $list['印件名称'] = '';
  120. // $list['印件代号'] = '';
  121. // $list['印件ID'] = '';
  122. // }else{
  123. // $list['印件名称'] = $printData['印件名称'];
  124. // $list['印件代号'] = $printData['印件代号'];
  125. // $list['印件ID'] = $printData['id'];
  126. // }
  127. // $this->success('成功',$list);
  128. // }
  129. /**
  130. * 工单资料修改
  131. * @ApiMethod (POST)
  132. * @param void
  133. * @return void
  134. * @throws \think\Exception
  135. * @throws \think\exception\PDOException
  136. */
  137. // public function WorkOrderEdit()
  138. // {
  139. // if (Request::instance()->isPost() === false){
  140. // $this->error('请求错误');
  141. // }
  142. // $param = Request::instance()->post();
  143. // if (empty($param) || isset($param['Uniqid']) === false){
  144. // $this->error('参数错误');
  145. // }
  146. // $row = [
  147. // 'Gd_lx' => isset($param['lx'])?$param['lx']:'',
  148. // '开单日期' => isset($param['kdrq'])?$param['kdrq']:'',
  149. // 'Gd_gdbh' => isset($param['gdbh'])?$param['gdbh']:'',
  150. // 'Gd_生产分类' => isset($param['scfl'])?$param['scfl']:'',
  151. // 'Gd_客户代号' => isset($param['khdh'])?$param['khdh']:'',
  152. // 'Gd_客户名称' => isset($param['khmc'])?$param['khmc']:'',
  153. // '成品代号' => isset($param['cpdh'])?$param['cpdh']:'',
  154. // '成品名称' => isset($param['cpmc'])?$param['cpmc']:'',
  155. // '订单数量' => isset($param['ddsl'])?$param['ddsl']:'',
  156. // '交货日期' => isset($param['jhrq'])?$param['jhrq']:'',
  157. // '投料率' => isset($param['tll'])?$param['tll']:'',
  158. // '计划投料' => isset($param['jhtl'])?$param['jhtl']:'',
  159. // '实际投料' => isset($param['sjtl'])?$param['sjtl']:'',
  160. // '计量单位' => isset($param['jldw'])?$param['jldw']:'',
  161. // '投料大箱' => isset($param['tldx'])?$param['tldx']:'',
  162. // '销售订单号' => isset($param['xsddh'])?$param['xsddh']:'',
  163. // '警语版面' => isset($param['jymb'])?$param['jymb']:'',
  164. // '产品版本号' => isset($param['bbh'])?$param['bbh']:'',
  165. // '客户ERP编码' => isset($param['erp'])?$param['erp']:'',
  166. // '码源数量' => isset($param['ymsl'])?$param['ymsl']:'',
  167. // '进程备注' => isset($param['jcbz'])?$param['jcbz']:'',
  168. // 'Gd_desc' => isset($param['desc'])?$param['desc']:'',
  169. // '排产时库存' => isset($param['kc'])?$param['kc']:'',
  170. // '平均合格率' => isset($param['avg'])?$param['avg']:'',
  171. // ];
  172. // //获取印件资料
  173. // $printCode = \db('工单_印件资料')
  174. // ->where('Uniqid',$param['printID'])
  175. // ->value('yj_Yjno');
  176. // if (!empty($printCode)){
  177. // if ((int)$param['jhtl'] >0){
  178. // //修改工单工艺计划产量
  179. // $result = $this->PlannedProcessYield($param['gdbh'],$printCode,0,$param['jhtl']);
  180. // if ($result === false){
  181. // $this->success('分配工序计划产量失败');
  182. // }
  183. // }
  184. //
  185. // //修改印件信息
  186. // $printSql = \db('工单_印件资料')
  187. // ->where('Uniqid',$param['printID'])
  188. // ->fetchSql(true)
  189. // ->update(['Yj_Gdbh'=>$param['gdbh'],'yj_yjmc'=>$param['yjmc'],'yj_Yjdh'=>$param['yjdh'],'yj_平张投料'=>$param['jhtl']]);
  190. // $printRes = Db::query($printSql);
  191. // }
  192. // //修改工单信息
  193. // $sql = \db('工单_基本资料')->where('Uniqid',$param['Uniqid'])->fetchSql(true)->update($row);
  194. // $res = Db::query($sql);
  195. // //修改订单数量该工单下的订单数量
  196. // //1. 查询该id下的工单编号, 防止其手动修改工单编号导致条件错误
  197. // $gdbh = \db('工单_基本资料')->where('Uniqid',$param['Uniqid'])->value('Gd_gdbh');
  198. // //2. 根据查出的工单编号修改订单数量
  199. // $sql = \db('工单_基本资料')->where('Gd_gdbh',$param['gdbh'])->fetchSql(true)->update(['订单数量'=>$row['订单数量']]);
  200. // $res1 = Db::query($sql);
  201. // if ($res !== false && $res1 !== false){
  202. // $this->success('成功');
  203. // }else{
  204. // $this->error('失败');
  205. // }
  206. // }
  207. /**
  208. * U8投料试算
  209. * @ApiMethod (GET)
  210. * @param string $processCode 产品编号
  211. * @return void
  212. * @throws \think\db\exception\DataNotFoundException
  213. * @throws \think\db\exception\ModelNotFoundException
  214. * @throws \think\exception\DbException
  215. */
  216. // public function U8Trial()
  217. // {
  218. // if ($this->request->isGet() === false)
  219. // {
  220. // $this->error('请求错误');
  221. // }
  222. // $productCode = input('productCode');
  223. // if (empty($productCode)){
  224. // $this->error('参数错误');
  225. // }
  226. // $field = 'rtrim(Gy0_cpdh) as 产品代号,rtrim(Gy0_yjno) as 印件号,rtrim(Gy0_gxh) as 工序号,rtrim(gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc,
  227. // rtrim(Gy0_Ms) as 墨色数,rtrim(Gy0_shdh) as 损耗代号,rtrim(损耗系数) as 损耗系数,rtrim(Gy0_ls) as 加工联数';
  228. // $list = \db('产品_工艺资料')->where('Gy0_cpdh',$productCode)->field($field)->select();
  229. // if (empty($list)){
  230. // $this->success('未找到该产品工序');
  231. // }
  232. // foreach ($list as $key=>$value){
  233. // $data = \db('dic_lzsh')->where('sys_bh',$value['损耗代号'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->cache(true)->find();
  234. // $list[$key]['调机损耗'] = isset($data['rate0'])?$data['rate0']:'';
  235. // $list[$key]['运行损耗率'] = isset($data['rate1'])?$data['rate1']:'';
  236. // if ($value['add_gxmc'] !== ''){
  237. // $list[$key]['工序名称'] = $value['gxmc'].'【'.$value['add_gxmc'].'】';
  238. // }else{
  239. // $list[$key]['工序名称'] = $value['gxmc'];
  240. // }
  241. // unset($list[$key]['gxmc'],$list[$key]['add_gxmc']);
  242. // }
  243. // $this->success('成功',$list);
  244. // }
  245. /**
  246. * 引用产品资料->获取产品资料
  247. * @ApiMethod (GET)
  248. * @param string $workOrder 工单编号
  249. * @return void
  250. * @throws \think\db\exception\DataNotFoundException
  251. * @throws \think\db\exception\ModelNotFoundException
  252. * @throws \think\exception\DbException
  253. */
  254. // public function ProductInformation()
  255. // {
  256. // if ($this->request->isGet() === false)
  257. // {
  258. // $this->error('请求错误');
  259. // }
  260. // $workOrder = input('workOrder');
  261. // if (empty($workOrder)){
  262. // $this->error('参数错误');
  263. // }
  264. // $field = 'rtrim(Gd_gdbh) as 工单编号,rtrim(Gd_客户名称) as 客户名称,rtrim(成品代号) as 产品代号,rtrim(成品名称) as 产品名称';
  265. // $Detail = \db('工单_基本资料')->where('Gd_gdbh',$workOrder)->field($field)->find();
  266. // if (empty($Detail)){
  267. // $this->success('未找到工单信息');
  268. // }
  269. // $Detail['客户代号'] = substr($Detail['产品代号'],0,4);
  270. // $this->success('成功',$Detail);
  271. // }
  272. /**
  273. * 引用产品资料->复制产品工艺资料
  274. * @ApiMethod (POST)
  275. * @param string $oldWorkOrder 被复制工单编号
  276. * @param string $newWorkOrder 复制工单编号
  277. * @return void
  278. * @throws \think\Exception
  279. * @throws \think\db\exception\DataNotFoundException
  280. * @throws \think\db\exception\ModelNotFoundException
  281. * @throws \think\exception\DbException
  282. * @throws \think\exception\PDOException
  283. */
  284. // public function ProductInformationEdit()
  285. // {
  286. // if (Request::instance()->isPost() === false)
  287. // {
  288. // $this->error('请求错误');
  289. // }
  290. // $oldWorkOrder = input('oldWorkOrder');
  291. // $newWorkOrder = input('newWorkOrder');
  292. // if (empty($oldWorkOrder) || empty($newWorkOrder))
  293. // {
  294. // $this->error('参数错误');
  295. // }
  296. // $lastId = \db('工单_工艺资料')->order('UniqId desc')->value('UniqId');
  297. // if ($lastId<10000000){
  298. // $lastId = 10000000;
  299. // }else{
  300. // $lastId = $lastId + 1;
  301. // }
  302. // //获取原工单工艺资料
  303. // $oldProcessData = \db('工单_工艺资料')->where('Gy0_gdbh',$newWorkOrder)->select();
  304. // $ProsessUniqId = \db('工单_工艺资料')->field('UniqId')->order('UniqId desc')->find();
  305. // foreach ($oldProcessData as $k=>$v){
  306. // $oldProcessData[$k]['Gy0_gdbh'] = $oldWorkOrder;
  307. // $oldProcessData[$k]['Sys_id'] = '';
  308. // $oldProcessData[$k]['Gy0_sj1'] = '1900-01-01 00:00:00';
  309. // $oldProcessData[$k]['Gy0_sj2'] = '1900-01-01 00:00:00';
  310. // $oldProcessData[$k]['UniqId'] = $lastId + $k;
  311. // $oldProcessData[$k]['PD_WG'] = '1900-01-01 00:00:00';
  312. // }
  313. // if (\db('工单_工艺资料')->where('Gy0_gdbh',$oldWorkOrder)->find()){
  314. // \db('工单_工艺资料')->where('Gy0_gdbh',$oldWorkOrder)->delete();
  315. // }
  316. // //获取原工单印件资料
  317. // $lastUniqId = \db('工单_印件资料')->order('UniqId desc')->value('UniqId');
  318. // if ($lastUniqId<1000000){
  319. // $lastUniqId = 1000000;
  320. // }else{
  321. // $lastUniqId = $lastUniqId + 1;
  322. // }
  323. // $oldPrintData = \db('工单_印件资料')->where('Yj_Gdbh',$newWorkOrder)->select();
  324. // $PrintUniqId = \db('工单_印件资料')->field('Uniqid')->order('Uniqid desc')->find();
  325. // foreach ($oldPrintData as $k=>$v){
  326. // $oldPrintData[$k]['Yj_Gdbh'] = $oldWorkOrder;
  327. // $oldPrintData[$k]['Sys_id'] = '';
  328. // $oldPrintData[$k]['Uniqid'] = $lastUniqId +$k +1;
  329. // }
  330. // if (\db('工单_印件资料')->where('Yj_Gdbh',$oldWorkOrder)->find()){
  331. // \db('工单_印件资料')->where('Yj_Gdbh',$oldWorkOrder)->delete();
  332. // }
  333. // //复制印件、工艺资料
  334. // $ProcessSQL = \db('工单_工艺资料')->fetchSql(true)->insertAll($oldProcessData);
  335. // $ProcessRes = Db::query($ProcessSQL);
  336. // $PrintSQL = \db('工单_印件资料')->fetchSql(true)->insertAll($oldPrintData);
  337. // $PrintRes = Db::query($PrintSQL);
  338. // if ($ProcessRes !== false && $PrintRes !== false){
  339. // $this->success('成功');
  340. // }else{
  341. // $this->error('失败');
  342. // }
  343. // }
  344. /**
  345. * 工艺流程调成->获取当前工单工艺资料
  346. * @ApiMethod (GET)
  347. * @param string $workorder 当前工单编号
  348. * @return void
  349. * @throws \think\db\exception\DataNotFoundException
  350. * @throws \think\db\exception\ModelNotFoundException
  351. * @throws \think\exception\DbException
  352. */
  353. // public function ProcessFlow()
  354. // {
  355. // if ($this->request->isGet() === false){
  356. // $this->error('请求错误');
  357. // }
  358. // $workOrder = input('workOrder');
  359. // if (empty($workOrder)){
  360. // $this->error('参数错误');
  361. // }
  362. // $list = \db('工单_基本资料')->where('Gd_gdbh',$workOrder)->field('rtrim(成品代号) as 成品编号,rtrim(成品名称) as 成品名称')->find();
  363. // if (empty($list)){
  364. // $this->success('未找到工单信息');
  365. // }
  366. // $filed = 'rtrim(Gy0_方案) as 方案,rtrim(Gy0_yjno) as 印件号,rtrim(Gy0_gxh) as 工序号,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc,
  367. // rtrim(工价系数) as 工价系数,rtrim(损耗系数) as 损耗系数,rtrim(Gy0_ks) as ks,rtrim(Gy0_ls) as ls,rtrim(工序备注) as 备注,rtrim(Gy0_SITE) as 车间,
  368. // rtrim(Gy0_sbbh) as 设备编号,rtrim(Gy0_sbmc) as 设备名称,rtrim(Sys_id) as 建档用户,rtrim(Sys_rq) as 建档时间,rtrim(Mod_rq) as 更新时间,rtrim(UniqId) as UniqId';
  369. // $process = \db('工单_工艺资料')->where('Gy0_gdbh',$workOrder)->cache(true,84600)->field($filed)->select();
  370. // if (empty($process)){
  371. // $this->error('未找到该工单工艺资料');
  372. // }
  373. // foreach ($process as $key=>$value){
  374. // if (isset($value['add_gxmc'])){
  375. // $process[$key]['工序名称'] = $value['gxmc'] . '【'.$value['add_gxmc'].'】';
  376. // }else{
  377. // $process[$key]['工序名称'] = $value['gxmc'];
  378. // }
  379. // $process[$key]['工价系数'] = (float)$value['工价系数'];
  380. // $process[$key]['损耗系数'] = (float)$value['损耗系数'];
  381. // $process[$key]['开数*联数'] = $value['ks'].'*'.$value['ls'];
  382. // }
  383. // $list['process'] = $process;
  384. // $this->success('成功',$list);
  385. // }
  386. /**
  387. * 参照工单列表获取
  388. * @ApiMethod (GET)
  389. * @param string $workOrder 工单编号
  390. * @param string $productCode 产品代号
  391. * @return void
  392. */
  393. // public function ReferenceWorkOrder()
  394. // {
  395. // if ($this->request->isGet() === false){
  396. // $this->error('请求错误');
  397. // }
  398. // $productCode = input('productCode');
  399. // $workOrder = input('workOrder');
  400. // if (empty($productCode) || empty($workOrder)){
  401. // $this->error('参数错误');
  402. // }
  403. // $list = \db('工单_基本资料')->where('成品代号',$productCode)->distinct(true)->where('Gd_gdbh','<>',$workOrder)->column('Gd_gdbh');
  404. // if (empty($list)){
  405. // $this->success('未获取该产品其他工单信息');
  406. // }
  407. // $this->success('成功',$list);
  408. // }
  409. /**
  410. * 工艺资料复制
  411. * @ApiMethod (POST)
  412. * @param string $oldWorkOrder 被复制工单编号
  413. * @param string $newWorkOrder 复制工单编号
  414. * @return void
  415. * @throws \think\Exception
  416. * @throws \think\db\exception\DataNotFoundException
  417. * @throws \think\db\exception\ModelNotFoundException
  418. * @throws \think\exception\DbException
  419. * @throws \think\exception\PDOException
  420. *
  421. */
  422. // public function ProcessCopy()
  423. // {
  424. // if (Request::instance()->isPost() === false){
  425. // $this->error('请求错误');
  426. // }
  427. // $param = Request::instance()->post();
  428. // if (empty($param)){
  429. // $this->error('参数错误');
  430. // }
  431. // $UniqId = [];
  432. // $lastId = \db('工单_工艺资料')->field('rtrim(UniqId) as id')->order('UniqId desc')->find();
  433. // if ($lastId['id']>10000000){
  434. // $lastUniqId = $lastId['id'];
  435. // }else{
  436. // $lastUniqId = 10000000;
  437. // }
  438. // foreach ($param as $key=>$value){
  439. // $UniqId[$key] = $value['UniqId'];
  440. // }
  441. // $processList = \db('工单_工艺资料')->where('UniqId','in',$UniqId)->select();
  442. // if (empty($processList)){
  443. // $this->success('未找到工艺资料');
  444. // }
  445. // $data = [];
  446. // foreach ($param as $key=>$value){
  447. // foreach ($processList as $k=>$v){
  448. // if ($value['UniqId'] = $v['UniqId']){
  449. // $data[$key] = $v;
  450. // $data[$key]['Gy0_gxh'] = $value['gxh'];
  451. // $data[$key]['Gy0_gdbh'] = $value['workOrder'];
  452. // $data[$key]['UniqId'] = $lastUniqId + $key + 1;
  453. // }
  454. // }
  455. // }
  456. // $res = \db('工单_工艺资料')->where(['Gy0_gdbh'=>$param[0]['workOrder']])->delete();
  457. // if ($res !== false){
  458. // $result = \db('工单_工艺资料')->insertAll($data);
  459. // if ($result !== false){
  460. // $this->success('成功');
  461. // }else{
  462. // $this->error('失败');
  463. // }
  464. // }else{
  465. // $this->error('失败');
  466. // }
  467. // }
  468. /**
  469. * U8工单列表
  470. * @ApiMethod (GET)
  471. * @param void
  472. * @return void
  473. * @throws \think\db\exception\DataNotFoundException
  474. * @throws \think\db\exception\ModelNotFoundException
  475. * @throws \think\exception\DbException
  476. */
  477. // public function U8workOrder()
  478. // {
  479. // if ($this->request->isGet() === false){
  480. // $this->error('请求错误');
  481. // }
  482. // $param = $this->request->param();
  483. // if (empty($param)){
  484. // $this->error('参数错误');
  485. // }
  486. // $filed = 'rtrim(Gd_gdbh) as 工单编号,rtrim(行号) as 行号,rtrim(Gd_客户代号) as 客户代号,rtrim(Gd_客户名称) as 客户名称,
  487. // rtrim(成品代号) as 成品代号,rtrim(成品名称) as 成品名称,rtrim(Mod_rq) as 获取日期,rtrim(Uniqid) as 序号';
  488. // $list = \db('工单_基本资料')->where('Gd_gdbh',$param['workOrder'])->field($filed)->select();
  489. // if (empty($list)){
  490. // $this->success('未找到工单');
  491. // }
  492. // $this->success('成功',$list);
  493. // }
  494. /**
  495. * U8工单资料删除
  496. * @param string $workOrder 工单编号
  497. * @return void
  498. * @throws \think\Exception
  499. * @throws \think\exception\PDOException
  500. */
  501. public function orderDataDel()
  502. {
  503. if($this->request->isGet() === false){
  504. $this->error('请求错误');
  505. }
  506. $workOrder = input('Uniqid');
  507. if (empty($workOrder)){
  508. $this->error('参数错误');
  509. }
  510. $order = \db('工单_基本资料')->where('Uniqid',$workOrder)->find();
  511. \db()->startTrans();
  512. try {
  513. \db('工单_印件资料')->where('订单编号',$order['订单编号'])->update(['Mod_rq'=>date('Y-m-d H:i:s')]);
  514. \db('工单_工艺资料')->where('订单编号',$order['订单编号'])->update(['Mod_rq'=>date('Y-m-d H:i:s')]);
  515. $res = \db('工单_基本资料')->where('Uniqid',$workOrder)->update(['Mod_rq'=>date('Y-m-d H:i:s')]);
  516. \db()->commit();
  517. } catch (\Exception $e){
  518. \db()->rollback();
  519. }
  520. if ($res !== false){
  521. $this->success('成功');
  522. }else{
  523. $this->error('失败');
  524. }
  525. }
  526. /**
  527. * 产品废检系数调整->质检工艺数据获取
  528. * @ApiMethod (GET)
  529. * @param string $workOrder 工单编号
  530. * @return void
  531. * @throws \think\db\exception\DataNotFoundException
  532. * @throws \think\db\exception\ModelNotFoundException
  533. * @throws \think\exception\DbException
  534. */
  535. // public function TestCoefficient()
  536. // {
  537. // if ($this->request->isGet() === false){
  538. // $this->error('请求错误');
  539. // }
  540. // $workOrder = input('workOrder');
  541. // if (empty($workOrder)){
  542. // $this->error('参数错误');
  543. // }
  544. // $where = [
  545. // 'Gy0_gdbh' => $workOrder,
  546. // 'Gy0_gxmc' => ['like','%检%']
  547. // ];
  548. // $filed = 'rtrim(Gy0_gdbh) as gdbh,rtrim(Gy0_yjno) as yjno,rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(人工检_正品板) as 人工正品板,
  549. // rtrim(人工检_次品板) as 人工次品板,rtrim(人工检_废检) as 人工废检,rtrim(机检_正品板) as 机检正品板,rtrim(机检_次品板) as 机检次品板,
  550. // rtrim(机检_废检) as 机检废检,rtrim(Gy0_sbbh) as 设备编号,rtrim(Uniqid) as Uniqid';
  551. // $list = \db('工单_工艺资料')->where($where)->field($filed)->select();
  552. // if (empty($list)){
  553. // $this->success('未找到该工单工艺');
  554. // }
  555. // $name = \db('工单_基本资料')
  556. // ->where('Gd_gdbh',$workOrder)
  557. // ->field('rtrim(Gd_cpdh) as 产品代号,rtrim(Gd_khmc) as 客户名称,rtrim(Gd_cpmc) as 产品名称')
  558. // ->find();
  559. // if (empty($name)){
  560. // $this->success('未找到该工单');
  561. // }
  562. // foreach ($list as $key=>$value){
  563. // if ($value['yjno']<10){
  564. // $value['yjno'] = '0'.$value['yjno'];
  565. // }
  566. // if ($value['gxh']<10){
  567. // $value['gxh'] = '0'.$value['gxh'];
  568. // }
  569. // $list[$key]['印件工序及工艺'] = $value['gdbh'].'-'.$value['yjno'].'-'.$value['gxh'].'-'.$value['gxmc'];
  570. // unset($list[$key]['gdbh'],$list[$key]['yjno'],$list[$key]['gxmc']);
  571. // $list[$key]['产品编号'] = $name['产品代号'];
  572. // $list[$key]['产品名称'] = $name['产品名称'];
  573. // $list[$key]['客户名称'] = $name['客户名称'];
  574. // }
  575. // $this->success('成功',$list);
  576. // }
  577. /**
  578. * 产品质检系数调整->系数修改
  579. * @ApiMethod (GET)
  580. * @param string $workorder 工单编号
  581. * @param string $processCode 工序号
  582. * @param float $code1 人工正品板
  583. * @param float $code2 人工次品板
  584. * @param float $code3 人工废检
  585. * @param float $code4 机检正品板
  586. * @param float $code5 机检次品板
  587. * @param float $code6 机检废检
  588. * @return void
  589. * @throws \think\Exception
  590. * @throws \think\exception\PDOException
  591. */
  592. // public function TestCoefficientEdit()
  593. // {
  594. // if (Request::instance()->isPost() === false){
  595. // $this->error('请求错误');
  596. // }
  597. // $workOrder = input('workOrder');
  598. // $processCode = input('processCode');
  599. // $row = [
  600. // '人工检_正品板' => input('code1'),
  601. // '人工检_次品板' => input('code2'),
  602. // '人工检_废检' => input('code3'),
  603. // '机检_正品板' => input('code4'),
  604. // '机检_次品板' => input('code5'),
  605. // '机检_废检' => input('code6'),
  606. // ];
  607. // if (empty($workOrder) || empty($processCode)){
  608. // $this->error('参数错误');
  609. // }
  610. // $where = [
  611. // 'Gy0_gdbh' => $workOrder,
  612. // 'Gy0_gxh' => $processCode
  613. // ];
  614. // $sql = \db('工单_工艺资料')->where($where)->fetchSql(true)->update($row);
  615. // $res = Db::query($sql);
  616. // if ($res !== false){
  617. // $this->success('成功');
  618. // }else{
  619. // $this->error('失败');
  620. // }
  621. // }
  622. /**
  623. * 修正工单核算参数->数据获取
  624. * @ApiMethod (GET)
  625. * @param string $workOrder 工单编号
  626. * @return void
  627. * @throws \think\db\exception\DataNotFoundException
  628. * @throws \think\db\exception\ModelNotFoundException
  629. * @throws \think\exception\DbException
  630. */
  631. // public function AccountingParameter()
  632. // {
  633. // if ($this->request->isGet() === false){
  634. // $this->error('请求错误');
  635. // }
  636. // $workOrder = input('workOrder');
  637. // if (empty($workOrder)){
  638. // $this->error('参数错误');
  639. // }
  640. // $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,
  641. // rtrim(Gy0_sbbh) as 参照设备,rtrim(工价系数) as 难度系数,rtrim(Gy0_shdh) as 损耗代号,rtrim(Gy0_Rate0) as 基础损耗,rtrim(Gy0_Rate1) as 损耗率,
  642. // rtrim(印刷方式) as 印刷方式,rtrim(版距) as 版距,rtrim(Gy0_ms) as 计损色数,rtrim(损耗系数) as 损耗系数,rtrim(UniqId) as UniqId';
  643. // $list = \db('工单_工艺资料')->where('Gy0_gdbh',$workOrder)->field($field)->select();
  644. // if (empty($list)){
  645. // $this->success('未找到该工单工艺资料');
  646. // }
  647. // foreach ($list as $key=>$value){
  648. // if ($value['yjno']<10){
  649. // $value['yjno'] = '0'.$value['yjno'];
  650. // }
  651. // if ($value['gxh']<10){
  652. // $value['gxh'] = '0'.$value['gxh'];
  653. // }
  654. // $list[$key]['印件号及工序名称'] = $value['yjno'].'-'.$value['gxh'].$value['gxmc'].'('.$value['add_gxmc'].')';
  655. // unset($list[$key]['yjno'],$list[$key]['gxmc'],$list[$key]['add_gxmc']);
  656. // }
  657. // $this->success('成功',$list);
  658. // }
  659. /**
  660. * 修正工单核算参数->参数修改
  661. * @ApiMethod (POST)
  662. * @param void
  663. * @return void
  664. * @throws \think\Exception
  665. * @throws \think\db\exception\DataNotFoundException
  666. * @throws \think\db\exception\ModelNotFoundException
  667. * @throws \think\exception\DbException
  668. * @throws \think\exception\PDOException
  669. */
  670. // public function AccountingParameterEdit()
  671. // {
  672. // if (Request::instance()->isPost() === false){
  673. // $this->error('请求错误');
  674. // }
  675. // $param = Request::instance()->post();
  676. // if (empty($param) || isset($param[0]['Uniqid']) === false){
  677. // $this->error('参数错误');
  678. // }
  679. // $i = 0;
  680. // foreach ($param as $key=>$value){
  681. // $data['rate0'] = 0;
  682. // $data['rate1'] = 0;
  683. // $rate = \db('dic_lzsh')->where('sys_bh',$value['loss'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->find();
  684. // if (!empty($rate)){
  685. // $data['rate0'] = $rate['rate0'];
  686. // $data['rate1'] = $rate['rate1'];
  687. // }
  688. // $row = [
  689. // '工价系数' => $value['difficulty']?:'',
  690. // 'Gy0_shdh' => $value['loss']?:'',
  691. // '印刷方式' => $value['printMode']?:'',
  692. // '版距' => $value['plate']?:'',
  693. // 'Gy0_ms' => $value['chromatic']?:'',
  694. // '损耗系数' => $value['wastage']?:'',
  695. // 'Gy0_Rate0' => $data['rate0'],
  696. // 'Gy0_Rate1' => $data['rate1']
  697. // ];
  698. // $sql = \db('工单_工艺资料')->where('Uniqid',$value['Uniqid'])->fetchSql(true)->update($row);
  699. // $res = Db::query($sql);
  700. // if ($res !== false){
  701. // $i++;
  702. // }
  703. // }
  704. // if ($i !== 0){
  705. // $this->success('成功');
  706. // }else{
  707. // $this->error('失败');
  708. // }
  709. // }
  710. /**
  711. * 印件资料修改
  712. * @ApiMethod (POST)
  713. * @param void
  714. * @return void
  715. * @throws \think\Exception
  716. * @throws \think\exception\PDOException
  717. */
  718. public function PrintedEdit()
  719. {
  720. if (Request::instance()->isPost() === false){
  721. $this->error('请求错误');
  722. }
  723. $param = Request::instance()->post();
  724. if (empty($param) || isset($param['Uniqid']) === false){
  725. $this->error('参数错误');
  726. }
  727. $param['Yj_Gdbh'] = \db('工单_印件资料')->where('Uniqid',$param['Uniqid'])->value('Yj_Gdbh');
  728. $data = [
  729. 'Yj_Gdbh' =>$param['Yj_Gdbh'],
  730. 'yj_Yjno' =>$param['yjno'],
  731. 'yj_Yjdh' =>$param['yjdh'],
  732. 'yj_yjmc' =>$param['yjmc'],
  733. 'yj_zzdh' =>$param['zzdh'],
  734. 'yj_zzdh1' =>$param['zzdh1'],
  735. 'yj_zzdh2' =>$param['zzdh2'],
  736. 'yj_zzdh3' =>$param['zzdh3'],
  737. 'yj_zzdh4' =>$param['zzdh4'],
  738. 'yj_zzmc' =>$param['zzmc'],
  739. 'yj_zzmc1' =>$param['zzmc1'],
  740. 'yj_zzmc2' =>$param['zzmc2'],
  741. 'yj_zzmc3' =>$param['zzmc3'],
  742. 'yj_zzmc4' =>$param['zzmc4'],
  743. 'yj_tlgg' =>$param['tlgg'],
  744. 'yj_klgg' =>$param['klgg'],
  745. 'Yj_核算规格' =>$param['hsgg'],
  746. 'yj_成品数量' =>$param['cpsl'],
  747. 'yj_平张投料' =>$param['pztl'],
  748. 'yj_ks' =>$param['ks'],
  749. 'yj_ls' =>$param['ls'],
  750. 'yj_desc' =>$param['desc'],
  751. ];
  752. $UniqId = $param['Uniqid'];
  753. $sql = \db('工单_印件资料')->where('Uniqid',$UniqId)->fetchSql(true)->update($data);
  754. $res = Db::query($sql);
  755. $process = \db('工单_工艺资料')
  756. ->where('Gy0_gdbh',$data['Yj_Gdbh'])
  757. ->where('Gy0_yjno',$data['yj_Yjno'])
  758. ->select();
  759. if ((int)$data['yj_平张投料'] > 0 && !empty($process)){
  760. //重新分配工序计划产量
  761. $result = $this->PlannedProcessYield($data['Yj_Gdbh'],$data['yj_Yjno'],0,$data['yj_平张投料']);
  762. if ($result === false){
  763. $this->success('修改工序产量失败');
  764. }
  765. }
  766. if ($res !== false){
  767. $this->success('成功');
  768. }else{
  769. $this->error('失败');
  770. }
  771. }
  772. /**
  773. * 工艺资料修改
  774. * @ApiMethod (POST)
  775. * @param void
  776. * @return void
  777. * @throws \think\Exception
  778. * @throws \think\db\exception\DataNotFoundException
  779. * @throws \think\db\exception\ModelNotFoundException
  780. * @throws \think\exception\DbException
  781. * @throws \think\exception\PDOException
  782. */
  783. public function ProcessDetailEdit()
  784. {
  785. if (Request::instance()->isPost() === false){
  786. $this->error('请求错误');
  787. }
  788. $param = Request::instance()->post();
  789. if (empty($param) || isset($param['UniqId']) === false){
  790. $this->error('参数错误');
  791. }
  792. if (empty($param['Gy0_shdh'])){
  793. $rate['rate0'] = 0;
  794. $rate['rate1'] = 0;
  795. }else{
  796. $rate = \db('dic_lzsh')->where('sys_bh',$param['Gy0_shdh'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->find();
  797. }
  798. $param['Gy0_Rate0']= isset($rate['rate0'])?$rate['rate0']:0;
  799. $param['Gy0_Rate1'] = isset($rate['rate1'])?$rate['rate1']:0;
  800. $param['Mod_rq'] = date('Y-m-d H:i:s',time());
  801. $UniqId = $param['UniqId'];
  802. unset($param['UniqId']);
  803. //修改工艺资料
  804. $sql = \db('工单_工艺资料')->where('UniqId',$UniqId)->fetchSql(true)->update($param);
  805. $res = Db::query($sql);
  806. //获取工艺资料数据
  807. $list = \db('工单_工艺资料')->where('UniqId',$UniqId)->field('Gy0_yjno,Gy0_gxh,rtrim(Gy0_计划接货数) as 计划接货数')->find();
  808. //修改工单状态
  809. $status = \db('工单_基本资料')->where('Gd_gdbh',$param['Gy0_gdbh'])->field('rtrim(gd_statu) as status')->find();
  810. if ($status['status'] !== '2-生产中'){
  811. $statusSql = \db('工单_基本资料')->where('Gd_gdbh',$param['Gy0_gdbh'])->fetchSql(true)->update(['gd_statu'=>'2-生产中']);
  812. Db::query($statusSql);
  813. }
  814. //重新分配工序计划产量
  815. if ((int)$list['计划接货数'] > 0){
  816. $result = $this->PlannedProcessYield($param['Gy0_gdbh'],$list['Gy0_yjno'],$list['Gy0_gxh'],$list['计划接货数']);
  817. }
  818. if ($res !== false){
  819. $this->success('成功');
  820. }else{
  821. $this->error('失败');
  822. }
  823. }
  824. /**
  825. * 工艺资料编辑->机台列表获取
  826. * @return void
  827. * @throws \think\db\exception\DataNotFoundException
  828. * @throws \think\db\exception\ModelNotFoundException
  829. * @throws \think\exception\DbException
  830. */
  831. // public function MachineList()
  832. // {
  833. // if ($this->request->isGet() === false){
  834. // $this->error('请求错误');
  835. // }
  836. // $param = $this->request->param();
  837. // if (empty($param)){
  838. // $this->error('参数错误');
  839. // }
  840. // $list = \db('设备_基本资料')
  841. // ->where('存放地点',$param['address'])
  842. // ->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')
  843. // ->select();
  844. // if (empty($list)){
  845. // $this->success('未找到该车间机台');
  846. // }
  847. // $data = [];
  848. // foreach ($list as $key=>$value){
  849. // $data[$key] = $value['设备编号'].'-->'.$value['设备名称'];
  850. // }
  851. // $this->success('成功',$data);
  852. // }
  853. /**
  854. * 打印作业通知单->工单印件和工序获取
  855. * @ApiMethod (GET)
  856. * @return void
  857. * @throws \think\db\exception\DataNotFoundException
  858. * @throws \think\db\exception\ModelNotFoundException
  859. * @throws \think\exception\DbException
  860. */
  861. // public function PrintCodeList()
  862. // {
  863. // if ($this->request->isGet() === false){
  864. // $this->error('请求错误');
  865. // }
  866. // $param = $this->request->param();
  867. // if (empty($param)){
  868. // $this->error('参数错误');
  869. // }
  870. // $list = \db('工单_印件资料')
  871. // ->field([
  872. // 'rtrim(yj_Yjno)' => '印件号',
  873. // 'rtrim(yj_yjmc)' => '印件名称'
  874. // ])
  875. // ->where('Yj_Gdbh',$param['workOrder'])
  876. // ->select();
  877. // $this->success('成功',$list);
  878. // }
  879. /**
  880. * 打印作业通知单->工艺编号获取
  881. * @ApiMethod (GET)
  882. * @return void
  883. * @throws \think\db\exception\DataNotFoundException
  884. * @throws \think\db\exception\ModelNotFoundException
  885. * @throws \think\exception\DbException
  886. */
  887. // public function ProcessCodeList()
  888. // {
  889. // if ($this->request->isGet() === false){
  890. // $this->error('请求错误');
  891. // }
  892. // $param = $this->request->param();
  893. // if (empty($param)){
  894. // $this->error('参数错误');
  895. // }
  896. // $list = \db('工单_工艺资料')
  897. // ->field('rtrim(Gy0_gxh) as 工序号')
  898. // ->where([
  899. // 'Gy0_gdbh' => $param['workOrder'],
  900. // 'Gy0_yjno' => $param['yjno']
  901. // ])
  902. // ->select();
  903. // $this->success('成功',$list);
  904. // }
  905. /**
  906. * 打印作业通知单
  907. * @ApiMethod (POST)
  908. * @param void
  909. * @return void
  910. * @throws \think\db\exception\DataNotFoundException
  911. * @throws \think\db\exception\ModelNotFoundException
  912. * @throws \think\exception\DbException
  913. */
  914. // public function PrintJobOrder()
  915. // {
  916. // if ($this->request->isGet() === false) {
  917. // $this->error('请求错误');
  918. // }
  919. // $param = $this->request->param();
  920. // if (empty($param)){
  921. // $this->error('参数错误');
  922. // }
  923. // $data = $this->workOrderDetailGet($param['workOrder'],$param['yjno']);
  924. // if (empty($data)){
  925. // $this->success('未找到工单信息');
  926. // }
  927. // $materiel = $this->MaterielDetailGet($param['workOrder']);
  928. // $printDetail = $this->PrintDetailGet($param['workOrder'],$param['yjno'],$param['gxh']);
  929. // if (empty($printDetail)){
  930. // $this->success('未找到工艺信息');
  931. // }
  932. // $number = 0;
  933. // foreach ($printDetail as $key=>$value){
  934. // $value['允损比例'] = (float)substr($value['允损比例'],0,-1);
  935. // $number = $number+$value['允损比例'];
  936. // }
  937. // $data['制单'] = $param['PrepareDocument'];
  938. // $data['审核'] = $param['examine'];
  939. // $data['目标合格率'] = 100-$number.'%';
  940. // $data['materiel'] = $materiel;
  941. // $data['printDetail'] = $printDetail;
  942. // $this->success('成功',$data);
  943. // }
  944. /**
  945. * 打印作业通知单->工单及印件资料获取
  946. * @param $workOrder
  947. * @return mixed
  948. */
  949. // public function workOrderDetailGet($workOrder,$yjno)
  950. // {
  951. // $sql = "SELECT
  952. // RTRIM( a.Gd_lx) AS 工单类型,
  953. // RTRIM( a.Gd_gdbh ) AS 生产批次号,
  954. // RTRIM( a.销售订单号 ) AS 销售订单号,
  955. // RTRIM( a.Gd_客户代号 ) AS 客户代号,
  956. // RTRIM( a.Gd_客户名称 ) AS 客户名称,
  957. // RTRIM( a.成品代号 ) AS 产品代码,
  958. // RTRIM( a.成品名称 ) AS 产品名称,
  959. // RTRIM( a.产品版本号 ) AS 版本号,
  960. // RTRIM( a.警语版面 ) AS 警语版面,
  961. // RTRIM( a.码源数量 ) AS 码源数量,
  962. // RTRIM( a.客户ERP编码 ) AS 客户ERP编码,
  963. // RTRIM( a.接单日期 ) AS 开单日期,
  964. // RTRIM( a.交货日期 ) AS 交货日期,
  965. // RTRIM( a.Gd_desc ) AS 工单说明,
  966. // RTRIM( a.投料率 ) AS 投料率,
  967. // RTRIM( a.订单数量 ) AS 订单数量,
  968. // RTRIM( a.平均合格率 ) AS 平均合格率,
  969. // RTRIM( a.投料大箱 ) AS 订货数量,
  970. // RTRIM( a.排产时库存 ) AS 排产时库存,
  971. // RTRIM( b.yj_Yjno ) AS 印件,
  972. // RTRIM( b.yj_Yjdh ) AS 印件代号,
  973. // RTRIM( b.yj_yjmc ) AS 印件名称,
  974. // RTRIM( b.yj_平张投料 ) AS 平张投料量,
  975. // RTRIM( b.yj_zzmc ) AS 纸张名称,
  976. // RTRIM( b.yj_tlgg ) AS 投料规格,
  977. // RTRIM( b.yj_ks ) AS 开数,
  978. // RTRIM( b.yj_ls ) AS 联数,
  979. // RTRIM( b.yj_desc ) AS 印件备注
  980. // FROM
  981. // `工单_基本资料` AS a
  982. // JOIN `工单_印件资料` AS b ON b.Yj_Gdbh = a.Gd_gdbh
  983. // WHERE
  984. // a.Gd_gdbh = '{$workOrder}' AND a.行号 = 1 AND b.yj_Yjno = '{$yjno}'";
  985. // $list = Db::query($sql);
  986. // if (empty($list)){
  987. // $this->success('未找到订单数据');
  988. // }
  989. // $list[0]['开单日期'] = date('Y-m-d',strtotime($list[0]['开单日期']));
  990. // $list[0]['交货日期'] = date('Y-m-d',strtotime($list[0]['交货日期']));
  991. // if (strpos($list[0]['产品名称'],'条') !== false){
  992. // $list[0]['订货数量'] = (int)$list[0]['订单数量']*40;
  993. // $list[0]['投料数量'] = intval($list[0]['平张投料量']*$list[0]['联数']/250);
  994. // }else{
  995. // $list[0]['订货数量'] = (int)$list[0]['订单数量']*4;
  996. // $list[0]['投料数量'] = intval($list[0]['平张投料量']*$list[0]['联数']/2500);
  997. // }
  998. // $list[0]['联数'] = (int)$list[0]['联数'];
  999. // $list[0]['印件代号及名称'] = $list[0]['印件代号'].' '.$list[0]['印件名称'];
  1000. //// $list[0]['投料数量'] = $list[0]['订货数量'];
  1001. // unset($list[0]['印件代号'],$list[0]['印件名称']);
  1002. // return($list[0]);
  1003. // }
  1004. /**打印作业流程单->物料资料获取
  1005. * @param $workOrder
  1006. * @return bool|\PDOStatement|string|\think\Collection
  1007. * @throws \think\db\exception\DataNotFoundException
  1008. * @throws \think\db\exception\ModelNotFoundException
  1009. * @throws \think\exception\DbException
  1010. */
  1011. // public function MaterielDetailGet($workOrder)
  1012. // {
  1013. // $where = [
  1014. // 'BOM_工单编号' => $workOrder,
  1015. // ];
  1016. // $filed = 'rtrim(BOM_物料编码) as 物料编码,rtrim(BOM_物料名称) as 物料名称,rtrim(BOM_投料单位) as 投料单位,rtrim(BOM_计划用量) as 计划用量';
  1017. // $list = \db('工单_bom资料')->where($where)->field($filed)->select();
  1018. // if (!empty($list)){
  1019. // foreach ($list as $key=>$value){
  1020. // $list[$key]['物料代码及名称'] = $value['物料编码'].' '.$value['物料名称'];
  1021. // $list[$key]['计划用量'] = (float)$value['计划用量'];
  1022. // unset($list[$key]['物料编码'],$list[$key]['物料名称']);
  1023. // }
  1024. // }
  1025. // return $list;
  1026. // }
  1027. /**
  1028. * 打印作业流程单->工艺资料获取
  1029. * @param $workOrder
  1030. * @return bool|\PDOStatement|string|\think\Collection
  1031. * @throws \think\db\exception\DataNotFoundException
  1032. * @throws \think\db\exception\ModelNotFoundException
  1033. * @throws \think\exception\DbException
  1034. */
  1035. // public function PrintDetailGet($workOrder,$yjno,$gxh)
  1036. // {
  1037. // $where = [
  1038. // 'Gy0_gdbh' => $workOrder,
  1039. // 'Gy0_yjno' => $yjno,
  1040. // 'Gy0_gxh' => ['<=',$gxh]
  1041. // ];
  1042. // $filed = 'rtrim(Gy0_yjno) as yjno,rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc,
  1043. // rtrim(损耗系数) as 损耗系数,rtrim(Gy0_ls) as ls,rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_计划损耗) as 计划损耗,
  1044. // rtrim(Gy0_辅助工时) as 装版工时,rtrim(Gy0_小时产能) as 小时定额,rtrim(Gy0_生产工时) as 生产工时,rtrim(工序备注) as 工序备注';
  1045. // $list = \db('工单_工艺资料')
  1046. // ->where($where)
  1047. // ->field($filed)
  1048. // ->select();
  1049. // if (empty($list)){
  1050. // $this->success('工单工艺为空');
  1051. // }
  1052. // foreach ($list as $key=>$value){
  1053. // if ($value['yjno']<10){
  1054. // $value['yjno'] = '0'.$value['yjno'];
  1055. // }
  1056. // if ($value['gxh']<10){
  1057. // $value['gxh'] = '0'.$value['gxh'];
  1058. // }
  1059. // if ($value['add_gxmc'] !== null){
  1060. //
  1061. // $list[$key]['印件及工序名称'] = $value['yjno'].'-'.$value['gxh'].'-->'.$value['gxmc'].'【'.$value['add_gxmc'].'】';
  1062. // }else{
  1063. // $list[$key]['印件及工序名称'] = $value['yjno'].'-'.$value['gxh'].'-->'.$value['gxmc'];
  1064. // }
  1065. // $list[$key]['转序数'] = (int)($value['计划接货数']/$value['ls']);
  1066. // $list[$key]['报废定额'] = (int)($value['计划损耗']/$value['ls']);
  1067. // if ((int)$value['计划接货数'] === 0){
  1068. // $list[$key]['允损比例'] = 0;
  1069. // }else{
  1070. // $list[$key]['允损比例'] = round(($value['计划损耗']/$value['计划接货数'])*100,2).'%';
  1071. // }
  1072. // unset($list[$key]['yjno'],$list[$key]['gxh'],$list[$key]['gxmc'],$list[$key]['add_gxmc'],$list[$key]['计划接货数'],$list[$key]['计划损耗']);
  1073. // }
  1074. // return $list;
  1075. // }
  1076. /**
  1077. * 获取小时产能
  1078. * @ApiMethod (GET)
  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 capacityList()
  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. // $machine = explode(' ',$param['machine'])[0];
  1095. // $number = \db('设备_基本资料')->where('设备编号',$machine)->field('rtrim(排单小时定额) as 小时产能')->find();
  1096. // if (empty($number)){
  1097. // $this->error('未找到小时产能');
  1098. // }
  1099. // $this->success('成功',$number['小时产能']);
  1100. // }
  1101. /**
  1102. * 新增工单->添加工单
  1103. * @ApiMethod (POST)
  1104. * @param
  1105. * @return void
  1106. * @throws \think\Exception
  1107. * @throws \think\db\exception\BindParamException
  1108. * @throws \think\db\exception\DataNotFoundException
  1109. * @throws \think\db\exception\ModelNotFoundException
  1110. * @throws \think\exception\DbException
  1111. * @throws \think\exception\PDOException
  1112. */
  1113. public function WorkOrderAdd()
  1114. {
  1115. // var_dump(1);exit;
  1116. if (Request::instance()->isPost() === false){
  1117. $this->error('请求错误');
  1118. }
  1119. $param = Request::instance()->post();
  1120. if (empty($param)){
  1121. $this->error('参数错误');
  1122. }
  1123. $param['Sys_rq'] = date('Y-m-d H:i:s');
  1124. $param['gd_statu'] = '1-计划中';
  1125. $prefix = substr($param['订单编号'], 0, 2); // e.g., "DC"
  1126. $maxOrder = \db('工单_基本资料')
  1127. ->where('订单编号', 'like', "{$prefix}%")
  1128. ->order('订单编号', 'desc')
  1129. ->limit(1)
  1130. ->value('订单编号');
  1131. if ($maxOrder) {
  1132. $numericPart = substr($maxOrder, 2);
  1133. $newNumericPart = str_pad((int)$numericPart + 1, strlen($numericPart), '0', STR_PAD_LEFT);
  1134. $param['订单编号'] = $prefix . $newNumericPart;
  1135. } else {
  1136. $param['订单编号'] = $param['订单编号'];
  1137. }
  1138. $sql= \db('工单_基本资料')->fetchSql(true)->insert($param);
  1139. $res = \db()->query($sql);
  1140. if ($res !== false){
  1141. $this->success('成功');
  1142. }else{
  1143. $this->error('失败');
  1144. }
  1145. }
  1146. /**
  1147. * 新增工单->客户代号列表获取
  1148. * @return void
  1149. * @throws \think\db\exception\BindParamException
  1150. * @throws \think\exception\PDOException
  1151. */
  1152. // public function ClientList()
  1153. // {
  1154. // if ($this->request->isGet() === false){
  1155. // $this->error('请求错误');
  1156. // }
  1157. // $param = $this->request->param();
  1158. // if (isset($param['search'])){
  1159. // $where = $param['search'].'%';
  1160. // $sql = "SELECT DISTINCT
  1161. // (客户编号),rtrim(客户名称 ) as 客户名称
  1162. // FROM
  1163. // `产品_基本资料`
  1164. // WHERE
  1165. // 客户编号 LIKE "."'".$where."'"."
  1166. // OR
  1167. // 客户名称 LIKE "."'".$where."'"."
  1168. // GROUP BY
  1169. // 客户编号
  1170. // order by
  1171. // 客户编号";
  1172. // }else{
  1173. // $sql = "SELECT DISTINCT
  1174. // (客户编号),rtrim(客户名称 ) as 客户名称
  1175. // FROM
  1176. // `产品_基本资料`
  1177. // GROUP BY
  1178. // 客户编号
  1179. // order by
  1180. // 客户编号";
  1181. // }
  1182. // $list = \db()->query($sql);
  1183. // if (empty($list)){
  1184. // $this->success('未找到客户列表');
  1185. // }
  1186. // foreach ($list as $key=>$value){
  1187. // if (empty($value['客户编号'])){
  1188. // unset($list[$key]);
  1189. // }else{
  1190. // $list[$key]['客户编号'] = rtrim($value['客户编号']);
  1191. // $list[$key]['name'] = rtrim($value['客户编号']).'【'.$value['客户名称'].'】';
  1192. // if ($value['客户编号'] == '1098'){
  1193. // $list[$key]['客户名称'] = '打样专用';
  1194. // }
  1195. // }
  1196. // }
  1197. // $list = array_values($list);
  1198. // $this->success('成功',$list);
  1199. // }
  1200. /**
  1201. * 新增工单->产品代号获取
  1202. * @ApiMethod (GET)
  1203. * @param void
  1204. * @return void
  1205. * @throws \think\db\exception\DataNotFoundException
  1206. * @throws \think\db\exception\ModelNotFoundException
  1207. * @throws \think\exception\DbException
  1208. */
  1209. // public function ProductCodeList()
  1210. // {
  1211. // if ($this->request->isGet() === false){
  1212. // $this->error('请求错误');
  1213. // }
  1214. // $param = $this->request->param();
  1215. // if (isset($param['cilent']) === false){
  1216. // $this->error('参数错误');
  1217. // }
  1218. // $where = ['产品编号'=>['like',$param['cilent'].'%']];
  1219. // $list = \db('产品_基本资料')
  1220. // ->where($where)
  1221. // ->field('rtrim(产品编号) as 产品编号,rtrim(产品名称) as 产品名称')
  1222. // ->select();
  1223. // if (empty($list)){
  1224. // $this->success('未获取到产品数据');
  1225. // }
  1226. // foreach ($list as $key=>$value){
  1227. // $list[$key]['name'] = $value['产品编号'].'【'.$value['产品名称'].'】';
  1228. // }
  1229. // $this->success('成功',$list);
  1230. // }
  1231. /**
  1232. * 新增印件资料->印件资料添加
  1233. * @return void
  1234. * @throws \think\db\exception\BindParamException
  1235. * @throws \think\exception\PDOException
  1236. */
  1237. public function PrintDetailAdd()
  1238. {
  1239. if (Request::instance()->isPost() === false){
  1240. $this->error('请求错误');
  1241. }
  1242. $param = Request::instance()->post();
  1243. if (empty($param)){
  1244. $this->error('参数错误');
  1245. }
  1246. $param['Sys_rq'] = date('Y-m-d H:i:s',time());
  1247. $process = [
  1248. ['1','仓库出库'],['2','裁切'],['3','车缝'],['4','后道收样'],['5','大烫'],['6','总检'],['7','包装']
  1249. ];
  1250. $processDetail = [];
  1251. foreach ($process as $key=>$value){
  1252. $total = null;
  1253. if ($key !== 0){
  1254. $total = $param['zdtotal'];
  1255. }
  1256. $processDetail[$key] = [
  1257. '订单编号' => $param['订单编号'],
  1258. '子订单编号' => $param['子订单编号'],
  1259. '款号' => $param['款号'],
  1260. '颜色' => $param['颜色'],
  1261. '工序编号' => $value[0],
  1262. '工序名称' => $value[1],
  1263. '计划产量' => $total,
  1264. 'Sys_id' => $param['Sys_id'],
  1265. 'Sys_rq' => $param['Sys_rq']
  1266. ];
  1267. }
  1268. //开启事务
  1269. db()->startTrans();
  1270. try{
  1271. $priSql = \db('工单_印件资料')->fetchSql(true)->insert($param);
  1272. $priRes = \db()->query($priSql);
  1273. $proSql = \db('工单_工艺资料')->fetchSql(true)->insertAll($processDetail);
  1274. $proRes = \db()->query($proSql);
  1275. // 提交事务
  1276. db()->commit();
  1277. } catch (\Exception $e) {
  1278. // 回滚事务
  1279. db()->rollback();
  1280. $this->error($e->getMessage());
  1281. }
  1282. if ($priRes !== false && $proRes !== false){
  1283. $this->success('成功');
  1284. }else{
  1285. $this->error('失败');
  1286. }
  1287. }
  1288. /**
  1289. * 新增工艺资料->工艺资料添加
  1290. * @return void
  1291. * @throws \think\db\exception\BindParamException
  1292. * @throws \think\exception\PDOException
  1293. */
  1294. // public function ProcessDetailAdd()
  1295. // {
  1296. // if (Request::instance()->isPost() === false){
  1297. // $this->error('请求错误');
  1298. // }
  1299. // $param = Request::instance()->post();
  1300. // if (empty($param)){
  1301. // $this->error('参数错误');
  1302. // }
  1303. // $lastId = \db('工单_工艺资料')->order('UniqId desc')->value('UniqId');
  1304. // if (empty($lastId)){
  1305. // $lastId = 0;
  1306. // }else{
  1307. // $lastId = $lastId + 1;
  1308. // }
  1309. // if (empty($param['Gy0_shdh'])){
  1310. // $param['Gy0_Rate0'] = 0;
  1311. // $param['Gy0_Rate1'] = 0;
  1312. // }else{
  1313. // $detail = \db('dic_lzsh')->field('sys_rate0,sys_rate1')->where('sys_bh',$param['Gy0_shdh'])->find();
  1314. // $param['Gy0_Rate0'] = $detail['sys_rate0'];
  1315. // $param['Gy0_Rate1'] = $detail['sys_rate1'];
  1316. // }
  1317. // $param['Sys_rq'] = date('Y-m-d H:i:s',time());
  1318. // $param['Mod_rq'] = '1900-01-01 00:00:00';
  1319. // $param['Gy0_sj1'] = '1900-01-01 00:00:00';
  1320. // $param['Gy0_sj2'] = '1900-01-01 00:00:00';
  1321. // $param['PD_WG'] = '1900-01-01 00:00:00';
  1322. // $param['UniqId'] = $lastId;
  1323. // $sql = \db('工单_工艺资料')
  1324. // ->fetchSql(true)
  1325. // ->insert($param);
  1326. // $res = \db()->query($sql);
  1327. // //获取平张投料
  1328. // $number = \db('工单_印件资料')
  1329. // ->where('Yj_Gdbh',$param['Gy0_gdbh'])
  1330. // ->where('yj_Yjno',$param['Gy0_yjno'])
  1331. // ->value('rtrim(yj_平张投料)');
  1332. // //分配工艺计划产量
  1333. // if ((int)$number >0){
  1334. // $this->PlannedProcessYield($param['Gy0_gdbh'],$param['Gy0_yjno'],$param['Gy0_gxh'],$number);
  1335. // }
  1336. // if ($res !== false){
  1337. // $this->success('成功');
  1338. // }else{
  1339. // $this->error('失败');
  1340. // }
  1341. //
  1342. // }
  1343. /**
  1344. * 新增工艺资料->印件编号获取
  1345. * @return void
  1346. * @throws \think\db\exception\DataNotFoundException
  1347. * @throws \think\db\exception\ModelNotFoundException
  1348. * @throws \think\exception\DbException
  1349. */
  1350. // public function PrintDetailList()
  1351. // {
  1352. // if ($this->request->isGet() === false){
  1353. // $this->error('请求错误');
  1354. // }
  1355. // $param = $this->request->param();
  1356. // if (empty($param)){
  1357. // $this->error('参数错误');
  1358. // }
  1359. // $printList = \db('工单_印件资料')
  1360. // ->where('Yj_Gdbh',$param['workOrder'])
  1361. // ->order('yj_Yjno')
  1362. // ->select();
  1363. // if (empty($printList)){
  1364. // $this->success('未找到该工单印件资料');
  1365. // }
  1366. // $list = [];
  1367. // foreach ($printList as $key=>$value){
  1368. // $list[$key]['name'] = rtrim($value['yj_Yjno']).'-->'.rtrim($value['yj_yjmc']);
  1369. // $list[$key]['no'] = rtrim($value['yj_Yjno']);
  1370. // }
  1371. // $this->success('成功',$list);
  1372. // }
  1373. /**
  1374. * 子订单列表
  1375. * @return null
  1376. * @throws \think\db\exception\DataNotFoundException
  1377. * @throws \think\db\exception\ModelNotFoundException
  1378. * @throws \think\exception\DbException
  1379. */
  1380. public function PrintListData()
  1381. {
  1382. if ($this->request->isGet() === false){
  1383. $this->error('请求错误');
  1384. }
  1385. $param = $this->request->param();
  1386. if (isset($param) === false){
  1387. $this->error('参数错误');
  1388. }
  1389. $where['Mod_rq'] = null;
  1390. $xhdata = \db('工单_印件资料')
  1391. ->where('订单编号',$param['order'])
  1392. ->where($where)
  1393. ->field('cm1,cm2,cm3,cm4,cm5,cm6,cm7,cm8,cm9,cm10')
  1394. ->select();
  1395. $arr = [];
  1396. foreach ($xhdata as $key => $value){
  1397. for($i=1;$i<=10;$i++){
  1398. if ($value['cm'.$i] !== '' && $value['cm'.$i] !== null){
  1399. array_push($arr,$value['cm'.$i]);
  1400. }
  1401. }
  1402. }
  1403. $arr = array_unique($arr);
  1404. sort($arr);
  1405. $list = \db('工单_印件资料')
  1406. ->where('订单编号',$param['order'])
  1407. ->where($where)
  1408. ->field('订单编号,子订单编号,款号,颜色,船样,zdtotal,Sys_id,Sys_rq,ck_rq,sc_rq,cm1,cm2,cm3,cm4,cm5,cm6,
  1409. cm7,cm8,cm9,cm10,cmsl1,cmsl2,cmsl3,cmsl4,cmsl5,cmsl6,cmsl7,cmsl8,cmsl9,cmsl10,Uniqid')
  1410. ->select();
  1411. foreach ($list as $key=>$value){
  1412. for($i=1;$i<=10;$i++){
  1413. if ($value['cm'.$i] !== ''){
  1414. $list[$key][$value['cm'.$i]] = $value['cmsl'.$i];
  1415. }
  1416. unset($list[$key]['cm'.$i],$list[$key]['cmsl'.$i]);
  1417. }
  1418. }
  1419. $data['型号'] = $arr;
  1420. $data['列表'] = $list;
  1421. $this->success('成功',$data);
  1422. }
  1423. /**
  1424. * 工单资料管理->印件资料删除
  1425. * @return void
  1426. * @throws \think\Exception
  1427. * @throws \think\exception\PDOException
  1428. */
  1429. public function PrintDetailDel()
  1430. {
  1431. if ($this->request->isGet() === false){
  1432. $this->error('请求错误');
  1433. }
  1434. $param = $this->request->param();
  1435. if (isset($param['UniqId']) === false){
  1436. $this->error('参数错误');
  1437. }
  1438. $printId = explode(',',$param['UniqId']);
  1439. $i = 0;
  1440. foreach ($printId as $value){
  1441. $res = \db('工单_印件资料')
  1442. ->where('Uniqid',$value)
  1443. ->update(['Mod_rq'=>date('Y-m-d H:i:s',time())]);
  1444. if ($res === false){
  1445. $i++;
  1446. }
  1447. }
  1448. if ($i === 0){
  1449. $this->success('删除成功');
  1450. }else{
  1451. $this->error('删除失败');
  1452. }
  1453. }
  1454. /**
  1455. * 工单资料管理->工艺资料删除
  1456. * @return void
  1457. * @throws \think\Exception
  1458. * @throws \think\exception\PDOException
  1459. */
  1460. // public function ProcessDetailDel()
  1461. // {
  1462. // if ($this->request->isGet() === false){
  1463. // $this->error('请求错误');
  1464. // }
  1465. // $param = $this->request->param();
  1466. // if (isset($param['UniqId']) === false){
  1467. // $this->error('参数错误');
  1468. // }
  1469. // $printId = explode(',',$param['UniqId']);
  1470. // $i = 0;
  1471. // //获取工单编号、印件号
  1472. // $codeList = \db('工单_工艺资料')
  1473. // ->where('UniqId',$printId[0])
  1474. // ->field('rtrim(Gy0_gdbh) as 工单编号,rtrim(Gy0_yjno) as 印件号')
  1475. // ->find();
  1476. // //获取平张投料数量
  1477. // $number = \db('工单_印件资料')
  1478. // ->where([
  1479. // 'Yj_Gdbh' => $codeList['工单编号'],
  1480. // 'yj_Yjno' => $codeList['印件号']
  1481. // ])
  1482. // ->value('rtrim(yj_平张投料)');
  1483. // //循环删除工艺资料
  1484. // foreach ($printId as $value){
  1485. // $res = \db('工单_工艺资料')
  1486. // ->where('UniqId',$value)
  1487. // ->delete();
  1488. // if ($res === false){
  1489. // $i++;
  1490. // }
  1491. // }
  1492. // //重新分配工艺计划产量
  1493. // if ((int)$number>0){
  1494. // $this->PlannedProcessYield($codeList['工单编号'],$codeList['印件号'],0,$number);
  1495. // }
  1496. // if ($i === 0){
  1497. // $this->success('删除成功');
  1498. // }else{
  1499. // $this->error('删除失败');
  1500. // }
  1501. // }
  1502. /**
  1503. * 工艺资料添加->工序损耗代码
  1504. * @return void
  1505. * @throws \think\db\exception\DataNotFoundException
  1506. * @throws \think\db\exception\ModelNotFoundException
  1507. * @throws \think\exception\DbException
  1508. */
  1509. // public function WastageList()
  1510. // {
  1511. // if ($this->request->isGet() === false){
  1512. // $this->error('请求错误');
  1513. // }
  1514. // $param = $this->request->param();
  1515. // if (empty($param['process'])){
  1516. // $this->error('参数错误');
  1517. // }
  1518. // $order = \db('dic_lzsh')
  1519. // ->where('sys_mc','like',$param['process'].'%')
  1520. // ->value('rtrim(sys_bh) as 编号');
  1521. // $this->success('成功',$order);
  1522. // }
  1523. /**
  1524. * 获取产品附件列表
  1525. */
  1526. // public function getAnnexTable(){
  1527. // if(!$this->request->isGet()){
  1528. // $this->error('请求方式错误');
  1529. // }
  1530. // $req = $this->request->param();
  1531. // if (isset($req['cpdh']) && !empty($req['cpdh'])){
  1532. // $where['关联产品'] = ['LIKE','%'.$req['cpdh'].'%'];
  1533. // }else{
  1534. // $this->error('参数错误');
  1535. // }
  1536. // $rows = db('产品_技术附件')
  1537. // ->where($where)
  1538. // ->select();
  1539. // foreach ($rows as $key=>&$value){
  1540. // if(mb_detect_encoding($value['附件内容'])!='ASCII'){
  1541. // $value['附件内容'] = '';
  1542. // }
  1543. // }
  1544. // $this->success('成功',$rows);
  1545. // }
  1546. /**
  1547. * 产品附件新增
  1548. */
  1549. // public function annexAdd(){
  1550. // if(!$this->request->isPost()){
  1551. // $this->error('请求方式错误');
  1552. // }
  1553. // $req = $this->request->param();
  1554. //
  1555. // $arr = [
  1556. // 'sys_id',
  1557. // '序号',
  1558. // '附件备注',
  1559. // '附件内容',
  1560. // '附件类型',
  1561. // '适用工序',
  1562. // '关联产品'
  1563. // ];
  1564. // $data = [];
  1565. // foreach ($arr as $key => $value){
  1566. // if (!isset($req[$value])){
  1567. // $this->error('参数错误',$value,$key+1);
  1568. // }
  1569. // $data[$value] = $req[$value];
  1570. // }
  1571. // $data['sys_rq'] = date('Y-m-d H:i:s');
  1572. //
  1573. // //开启事务
  1574. // db()->startTrans();
  1575. // try{
  1576. // $sql = db('产品_技术附件')->fetchSql(true)->insert($data);
  1577. // $bool = db()->query($sql);
  1578. // // 提交事务
  1579. // db()->commit();
  1580. // } catch (\Exception $e) {
  1581. // // 回滚事务
  1582. // db()->rollback();
  1583. // $this->error($e->getMessage());
  1584. // }
  1585. //
  1586. // if($bool===false) $this->error('失败');
  1587. //
  1588. // $this->success('成功');
  1589. // }
  1590. /**
  1591. * 产品附件修改
  1592. * @ApiMethod (GET)
  1593. * @param string 'UniqId'
  1594. */
  1595. // public function annexDel()
  1596. // {
  1597. // if(!$this->request->isGet()){
  1598. // $this->error('请求方式错误');
  1599. // }
  1600. // $req = $this->request->param();
  1601. //
  1602. // if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
  1603. // $this->error('参数错误','UniqId',100);
  1604. // }
  1605. //
  1606. // //开启事务
  1607. // db()->startTrans();
  1608. // try{
  1609. // $bool = db('产品_技术附件')->where('UniqId',$req['UniqId'])->delete();
  1610. // // 提交事务
  1611. // db()->commit();
  1612. // } catch (\Exception $e) {
  1613. // // 回滚事务
  1614. // db()->rollback();
  1615. // $this->error($e->getMessage());
  1616. // }
  1617. //
  1618. // if($bool===false) $this->error('失败');
  1619. //
  1620. // $this->success('成功');
  1621. //
  1622. // }
  1623. /**
  1624. * 获取产品附件列表
  1625. */
  1626. // public function getGdAnnexTable(){
  1627. // if(!$this->request->isGet()){
  1628. // $this->error('请求方式错误');
  1629. // }
  1630. // $req = $this->request->param();
  1631. // if (isset($req['gdbh']) && !empty($req['gdbh'])){
  1632. // $where['关联编号'] = ['LIKE','%'.$req['gdbh'].'%'];
  1633. // }else{
  1634. // $this->error('参数错误');
  1635. // }
  1636. // $rows = db('工单_相关附件')
  1637. // ->where($where)
  1638. // ->select();
  1639. // foreach ($rows as $key=>&$value){
  1640. // if(mb_detect_encoding($value['附件内容'])!='ASCII'){
  1641. // $value['附件内容'] = '';
  1642. // }
  1643. // }
  1644. // $this->success('成功',$rows);
  1645. // }
  1646. /**
  1647. * 产品附件新增
  1648. */
  1649. public function gdAnnexAdd(){
  1650. if(!$this->request->isPost()){
  1651. $this->error('请求方式错误');
  1652. }
  1653. $req = $this->request->param();
  1654. $arr = [
  1655. 'sys_id',
  1656. '附件备注',
  1657. '附件内容',
  1658. '附件类型',
  1659. '关联编号'
  1660. ];
  1661. $data = [];
  1662. foreach ($arr as $key => $value){
  1663. if (!isset($req[$value])){
  1664. $this->error('参数错误',$value,$key+1);
  1665. }
  1666. $data[$value] = $req[$value];
  1667. }
  1668. $data['sys_rq'] = date('Y-m-d H:i:s');
  1669. //检测目录是否存在
  1670. if(is_dir(ROOT_PATH.'public/uploads/'.$req['关联编号']) == null)
  1671. {
  1672. mkdir(ROOT_PATH.'public/uploads/'.$req['关联编号'],0777,true);
  1673. }
  1674. $base64Data = $req['附件内容'];
  1675. if (strpos($base64Data, 'base64,') !== false) {
  1676. $base64Data = explode('base64,', $base64Data)[1]; // 去掉前缀
  1677. }
  1678. // 解码 Base64 数据
  1679. $tempFileContent = base64_decode($base64Data);
  1680. // 创建一个临时文件
  1681. $tempFile = tempnam(sys_get_temp_dir(), 'excel_') . '.xlsx';
  1682. // 将解码后的内容写入临时文件
  1683. file_put_contents($tempFile, $tempFileContent);
  1684. // 加载 Excel 文件
  1685. $spreadsheet =IOFactory::load($tempFile);
  1686. //储存pdf地址
  1687. $address = '';
  1688. // 遍历每个工作表
  1689. foreach ($spreadsheet->getAllSheets() as $index => $sheet) {
  1690. // 创建新 Spreadsheet 对象,仅包含当前工作表
  1691. $pdfSpreadsheet = new Spreadsheet();
  1692. $pdfSpreadsheet->addExternalSheet($sheet);
  1693. // 设置 PDF 写入器
  1694. $pdfWriter = new Tcpdf($pdfSpreadsheet);
  1695. // 生成 PDF 文件名
  1696. $pdfFileName = 'output_sheet_' . ($index + 1) . '.pdf';
  1697. //设置保存地址
  1698. $pdfOutputPath = ROOT_PATH.'public/uploads/'.$req['关联编号'] . $pdfFileName;
  1699. // 保存到服务器指定目录
  1700. $pdfWriter->save($pdfOutputPath);
  1701. // 编辑pdf地址
  1702. $address = $pdfOutputPath.',' . $address;
  1703. }
  1704. // 清理临时文件
  1705. unlink($tempFile);;
  1706. //开启事务
  1707. db()->startTrans();
  1708. try{
  1709. $sql = db('工单_相关附件')->fetchSql(true)->insert($data);
  1710. $bool = db()->query($sql);
  1711. // 提交事务
  1712. db()->commit();
  1713. } catch (\Exception $e) {
  1714. // 回滚事务
  1715. db()->rollback();
  1716. $this->error($e->getMessage());
  1717. }
  1718. if($bool===false) $this->error('失败');
  1719. $this->success('成功');
  1720. }
  1721. /**
  1722. * 产品附件修改
  1723. * @ApiMethod (GET)
  1724. * @param string 'UniqId'
  1725. */
  1726. // public function gdAnnexDel()
  1727. // {
  1728. // if(!$this->request->isGet()){
  1729. // $this->error('请求方式错误');
  1730. // }
  1731. // $req = $this->request->param();
  1732. //
  1733. // if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
  1734. // $this->error('参数错误','UniqId',100);
  1735. // }
  1736. //
  1737. // //开启事务
  1738. // db()->startTrans();
  1739. // try{
  1740. // $bool = db('工单_相关附件')->where('UniqId',$req['UniqId'])->delete();
  1741. // // 提交事务
  1742. // db()->commit();
  1743. // } catch (\Exception $e) {
  1744. // // 回滚事务
  1745. // db()->rollback();
  1746. // $this->error($e->getMessage());
  1747. // }
  1748. //
  1749. // if($bool===false) $this->error('失败');
  1750. //
  1751. // $this->success('成功');
  1752. //
  1753. // }
  1754. /**
  1755. * 引用工单资料数据查询
  1756. * @return void
  1757. * @throws \think\db\exception\DataNotFoundException
  1758. * @throws \think\db\exception\ModelNotFoundException
  1759. * @throws \think\exception\DbException
  1760. */
  1761. // public function WorkOrderDetailCope()
  1762. // {
  1763. // if ($this->request->isGet() === false){
  1764. // $this->error('请求错误');
  1765. // }
  1766. // $param = $this->request->param();
  1767. // if (empty($param['search'])){
  1768. // $this->error('参数错误');
  1769. // }
  1770. // $list = \Db('工单_基本资料')
  1771. // ->alias('a')
  1772. // ->field([
  1773. // 'rtrim(a.Gd_gdbh)' => '工单编号',
  1774. // 'rtrim(b.客户编号)' => '客户编号',
  1775. // 'rtrim(b.客户名称)' => '客户名称',
  1776. // 'rtrim(b.产品编号)' => '产品编号',
  1777. // 'rtrim(b.产品名称)' => '产品名称'
  1778. // ])
  1779. // ->join('产品_基本资料 b', 'a.成品代号 = b.产品编号')
  1780. // ->join('产品_工艺资料 c', 'a.成品代号 = c.Gy0_cpdh')
  1781. // ->join('产品_印件资料 d', 'a.成品代号 = d.yj_cpdh')
  1782. // ->where(function($query) use ($param) {
  1783. // $query->where('a.Gd_gdbh', 'like', '%'.$param['search'].'%')
  1784. // ->whereOr('a.成品名称', 'like', '%'.$param['search'].'%');
  1785. // })
  1786. // ->where(function($query) {
  1787. // $query->where('c.Gy0_cpdh', '<>', '')
  1788. // ->where('d.yj_cpdh', '<>', '')
  1789. // ->where('b.状态', 'not like', '%停用%')
  1790. // ->where('b.产品名称', 'not like', '%停用%');
  1791. // })
  1792. // ->group('a.Gd_gdbh')
  1793. // ->order('a.Uniqid desc')
  1794. // ->select();
  1795. // if (empty($list)){
  1796. // $this->success('未找到工单资料');
  1797. // }else{
  1798. // $this->success('成功',$list);
  1799. // }
  1800. // }
  1801. //
  1802. /**
  1803. * 引用产品印件、工艺资料
  1804. * @return void
  1805. * @throws \think\db\exception\BindParamException
  1806. * @throws \think\db\exception\DataNotFoundException
  1807. * @throws \think\db\exception\ModelNotFoundException
  1808. * @throws \think\exception\DbException
  1809. * @throws \think\exception\PDOException
  1810. */
  1811. // public function WorkOrderDetailListCope()
  1812. // {
  1813. // if (Request::instance()->isPost() === false){
  1814. // $this->error('请求错误');
  1815. // }
  1816. //
  1817. // $param = Request::instance()->post();
  1818. // if (empty($param['workorder']) || empty($param['productCode']) || empty($param['option'])){
  1819. // $this->error('参数错误');
  1820. // }
  1821. // if (isset($param['sort'])){
  1822. // $priWhere['yj_yjno'] = ['>=',10];
  1823. // $proWhere['Gy0_yjno'] = ['>=',10];
  1824. // }else{
  1825. // $priWhere['yj_yjno'] = ['<',10];
  1826. // $proWhere['Gy0_yjno'] = ['<',10];
  1827. // }
  1828. // $list = \db('工单_基本资料')
  1829. // ->where('Gd_gdbh',$param['workorder'])
  1830. //// ->where('成品代号',$param['productCode'])
  1831. // ->field('行号,Gd_cpdh')
  1832. // ->select();
  1833. // //引用印件资料
  1834. // $PrintList = \db('产品_印件资料')
  1835. // ->where('yj_cpdh',$param['productCode'])
  1836. // ->where($priWhere)
  1837. // ->select();
  1838. // if (empty($PrintList)){
  1839. // $this->error('未找到印件资料');
  1840. // }
  1841. // $PrintLastId = \db('工单_印件资料')->order('Uniqid desc')->value('rtrim(Uniqid)');
  1842. // $number = \db('工单_基本资料')
  1843. // ->where('Gd_gdbh',$param['workorder'])
  1844. // ->where('成品代号',$param['productCode'])
  1845. // ->value('rtrim(计划投料)');
  1846. // $arr = [];
  1847. // foreach ($PrintList as $key => $value){
  1848. // foreach ($list as $k=>$v){
  1849. // if ($value['yj_yjdh'] === $v['Gd_cpdh']){
  1850. // $PrintList[$key]['Yj_Gdbh'] = $param['workorder'];
  1851. // $PrintList[$key]['yj_Yjno'] = $value['yj_yjno'];
  1852. // $PrintList[$key]['yj_Yjdh'] = $value['yj_yjdh'];
  1853. // $PrintList[$key]['yj_ks'] = $value['yj_ks'];
  1854. // $PrintList[$key]['yj_ls'] = $value['yj_ls'];
  1855. // $PrintList[$key]['yj_平张投料'] = $number;
  1856. // $PrintList[$key]['Sys_id'] = $value['sys_id'];
  1857. // $PrintList[$key]['Uniqid'] = $PrintLastId + $key + 1;
  1858. // $PrintList[$key]['Sys_rq'] = date('Y-m-d H:i:s',time());
  1859. // $PrintList[$key]['Mod_rq'] = date('Y-m-d H:i:s',time());
  1860. // array_push($arr,[$value['yj_yjno'],$v['行号']]);
  1861. // }
  1862. // $sql = \db('工单_基本资料')
  1863. // ->where('Gd_gdbh',$param['workorder'])
  1864. // ->where('Gd_cpdh',$value['yj_yjdh'])
  1865. // ->fetchSql(true)
  1866. // ->update(['行号'=>$value['yj_yjno']]);
  1867. // \db()->query($sql);
  1868. // }
  1869. // unset($PrintList[$key]['mod_rq'],$PrintList[$key]['sys_rq'],$PrintList[$key]['sys_id'],$PrintList[$key]['KgToPages'],$PrintList[$key]['yj_tll'],$PrintList[$key]['yj_yjdh'],$PrintList[$key]['yj_yjno'],$PrintList[$key]['UniqId']);
  1870. // }
  1871. // //引用工艺资料
  1872. // $processWhere = [
  1873. // 'Gy0_方案' => $param['option'],
  1874. // 'Gy0_cpdh' => $param['productCode']
  1875. // ];
  1876. // $ProcessList = \db('产品_工艺资料')
  1877. // ->where($processWhere)
  1878. // ->where($proWhere)
  1879. // ->order('Gy0_yjno,Gy0_gxh')
  1880. // ->select();
  1881. // if (empty($ProcessList)){
  1882. // $this->error('未找到产品工艺资料');
  1883. // }
  1884. // $ProcesslastId = \db('工单_工艺资料')->order('UniqId desc')->value('rtrim(UniqId)');
  1885. // foreach ($ProcessList as $key=>$value){
  1886. // if (empty(trim($value['Gy0_shdh']))){
  1887. // $rate['rate0'] = 0;
  1888. // $rate['rate1'] = 0;
  1889. // }else{
  1890. // $rate = \db('dic_lzsh')->where('sys_bh',$value['Gy0_shdh'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->find();
  1891. // if (empty($rate)){
  1892. // $this->error('该产品印件号'.$value['Gy0_yjno'].'工序号为'.$value['gy0_gxmc'].'的损耗代号错误,请调整之后再引用');
  1893. // }
  1894. // }
  1895. // //设置默认机台
  1896. // $machineList = \db('设备_基本资料')
  1897. // ->where('生产工序','like','%'.$value['gy0_gxmc'].'%')
  1898. // ->order('设备编号')
  1899. // ->value('设备编号');
  1900. // $ProcessList[$key]['Gy0_sbbh'] = '';
  1901. // if (!empty($machineList)){
  1902. // $ProcessList[$key]['Gy0_sbbh'] = $machineList;
  1903. // }
  1904. // $ProcessList[$key]['Gy0_yjno'] = $value['Gy0_yjno'];
  1905. // $ProcessList[$key]['Gy0_gdbh'] = $param['workorder'];
  1906. // $ProcessList[$key]['Gy0_gxmc'] = $value['gy0_gxmc'];
  1907. // $ProcessList[$key]['Gy0_SITE'] = $value['Gy0_site'];
  1908. // $ProcessList[$key]['Gy0_shdh'] = $value['Gy0_shdh'];
  1909. // $ProcessList[$key]['Gy0_Rate0'] = $rate['rate0'];
  1910. // $ProcessList[$key]['Gy0_Rate1'] = $rate['rate1'];
  1911. // $ProcessList[$key]['Gy0_ks'] = $value['Gy0_Ks'];
  1912. // $ProcessList[$key]['Gy0_ms'] = $value['Gy0_Ms'];
  1913. // $ProcessList[$key]['Gy0_oil'] = $value['Gy0_Oil'];
  1914. // $ProcessList[$key]['Gy0_计划接货数'] = 0;
  1915. // $ProcessList[$key]['Gy0_计划损耗'] = 0;
  1916. // $ProcessList[$key]['无形损承担比例'] = 0;
  1917. // $ProcessList[$key]['超节损承担比例'] = 1;
  1918. // $ProcessList[$key]['超节损核算单价'] = 0;
  1919. // $ProcessList[$key]['Gy0_sj1'] = '1900-01-01 00:00:00';
  1920. // $ProcessList[$key]['Gy0_sj2'] = '1900-01-01 00:00:00';
  1921. // $ProcessList[$key]['UniqId'] = $ProcesslastId + $key + 1;
  1922. // $ProcessList[$key]['PD_WG'] = '1900-01-01 00:00:00';
  1923. // $ProcessList[$key]['Sys_rq'] = date('Y-m-d H:i:s', time());
  1924. // unset($ProcessList[$key]['Gy0_Oil'],$ProcessList[$key]['Gy0_Ms'],$ProcessList[$key]['Gy0_Ks'],$ProcessList[$key]['UniqID'],$ProcessList[$key]['Gy0_cpdh'],$ProcessList[$key]['gy0_gxmc'],$ProcessList[$key]['Gy0_site']);
  1925. // }
  1926. // //插入数据
  1927. // \db()->startTrans();
  1928. // try {
  1929. // \db('工单_工艺资料')->where('Gy0_gdbh',$param['workorder'])->delete();
  1930. // $processSql = \db('工单_工艺资料')->fetchSql(true)->insertAll($ProcessList);
  1931. // \db()->query($processSql);
  1932. // \db('工单_印件资料')->where('Yj_Gdbh',$param['workorder'])->delete();
  1933. // $printSql = \db('工单_印件资料')->fetchSql(true)->insertAll($PrintList);
  1934. // \db()->query($printSql);
  1935. // \db()->commit();
  1936. // }catch (\Exception $e){
  1937. // \db()->rollback();
  1938. // }
  1939. // //计算工序计划生产数量
  1940. // if ($number !== null){
  1941. // $list = \db('工单_印件资料')->where('Yj_Gdbh',$param['workorder'])->field('yj_Yjno,yj_平张投料')->select();
  1942. // foreach ($list as $value){
  1943. // if ((int)$value['yj_平张投料'] >0){
  1944. // $this->PlannedProcessYield($param['workorder'],$value['yj_Yjno'],0,$value['yj_平张投料']);
  1945. // }
  1946. // }
  1947. // }
  1948. // $this->success('成功');
  1949. // }
  1950. /**
  1951. * 引用产品印件、工艺资料->信息获取
  1952. * @return void
  1953. * @throws \think\db\exception\DataNotFoundException
  1954. * @throws \think\db\exception\ModelNotFoundException
  1955. * @throws \think\exception\DbException
  1956. */
  1957. // public function ProductCopeDetail()
  1958. // {
  1959. // if ($this->request->isGet() === false){
  1960. // $this->error('请求错误');
  1961. // }
  1962. // $param = $this->request->param();
  1963. // if (empty($param['workorder'])){
  1964. // $this->error('参数错误');
  1965. // }
  1966. // $list = \db('工单_基本资料')
  1967. // ->alias('a')
  1968. // ->field([
  1969. // 'rtrim(a.Gd_gdbh)' => '工单编号',
  1970. // 'rtrim(b.客户编号)' => '客户编号',
  1971. // 'rtrim(b.客户名称)' => '客户名称',
  1972. // 'rtrim(b.产品编号)' => '产品编号',
  1973. // 'rtrim(b.产品名称)' => '产品名称'
  1974. // ])
  1975. // ->join('产品_基本资料 b','a.成品代号 = b.产品编号')
  1976. // ->where('a.Gd_gdbh',$param['workorder'])
  1977. // ->find();
  1978. // if (empty($list)){
  1979. // $this->error('未找到工单信息');
  1980. // }
  1981. // $option = \db('产品_工艺资料')
  1982. // ->field('rtrim(Gy0_方案) as 方案')
  1983. // ->where('Gy0_cpdh',$list['产品编号'])
  1984. // ->group('Gy0_方案')
  1985. // ->select();
  1986. // $list['方案'] = $option;
  1987. // $this->success('成功',$list);
  1988. // }
  1989. /**
  1990. * 工艺资料计划产量重新分配
  1991. * @param string $workOrder 工单
  1992. * @param int $yjno 印件号
  1993. * @param int $gxh 工序号
  1994. * @param int $feed 平张投料
  1995. * @return bool
  1996. * @throws \think\Exception
  1997. * @throws \think\db\exception\BindParamException
  1998. * @throws \think\db\exception\DataNotFoundException
  1999. * @throws \think\db\exception\ModelNotFoundException
  2000. * @throws \think\exception\DbException
  2001. * @throws \think\exception\PDOException
  2002. */
  2003. // public function PlannedProcessYield($workOrder,$yjno,$gxh,$feed)
  2004. // {
  2005. // if ($gxh === 0){
  2006. // $where = [
  2007. // 'Gy0_gdbh'=>$workOrder,
  2008. // 'Gy0_yjno'=>$yjno,
  2009. // ];
  2010. // }else{
  2011. // $where = [
  2012. // 'Gy0_gdbh'=>$workOrder,
  2013. // 'Gy0_yjno'=>$yjno,
  2014. // 'Gy0_gxh'=>['>=',$gxh]
  2015. // ];
  2016. // }
  2017. // //获取工艺资料
  2018. // $processList = \db('工单_工艺资料')
  2019. // ->where($where)
  2020. // ->field('Gy0_Rate0 as 损耗定额,Gy0_Rate1 as 损耗率,rtrim(损耗系数) as 损耗系数,Gy0_ms,Gy0_ls,UniqId')
  2021. // ->order('Gy0_gxh')
  2022. // ->select();
  2023. // if (empty($processList)){
  2024. // $this->success('未找到该工单工序资料');
  2025. // }
  2026. // //计算损耗定额和计划产量
  2027. // $production = [];
  2028. // $i = 0;
  2029. // foreach ($processList as $key=>$value){
  2030. // if ($key === 0){
  2031. // array_push($production,$feed);
  2032. // }
  2033. // $wastage = 0;
  2034. // if ($value['损耗率'] !== 0 && !empty($value['损耗率'])){
  2035. // $wastage = ($production[$key]*$value['损耗率']+$value['损耗定额'])*$value['损耗系数'];
  2036. // }
  2037. //
  2038. // if ($value['Gy0_ms'] >0 && !empty($value['Gy0_ms'])){
  2039. // $wastage = round($wastage * $value['Gy0_ms']);
  2040. // }
  2041. // if ((int)$value['Gy0_ls'] === 1 && $key>=1){
  2042. // $number = $production[$key]*$processList[$key-1]['Gy0_ls'];
  2043. // }else{
  2044. // $number = $production[$key];
  2045. // }
  2046. // if ($key>=1 && (int)$processList[$key-1]['Gy0_ls'] === 1 && (int)$value['Gy0_ls'] > 1){
  2047. // $number = $number/(int)$value['Gy0_ls'];
  2048. // }
  2049. // array_push($production,ceil($number-$wastage));
  2050. // $processSql = \db('工单_工艺资料')
  2051. // ->where('UniqId',$value['UniqId'])
  2052. // ->fetchSql(true)
  2053. // ->update(['Gy0_计划接货数'=>$production[$key],'Gy0_计划损耗'=>$wastage]);
  2054. // $res = \db()->query($processSql);
  2055. // if ($res === false){
  2056. // $i++;
  2057. // }
  2058. // }
  2059. // if ($i===0){
  2060. // return true;
  2061. // }else{
  2062. // return false;
  2063. // }
  2064. // }
  2065. /**
  2066. * 工单资料删除
  2067. * @return void
  2068. * @throws \think\exception\PDOException
  2069. */
  2070. // public function WorkOrderDel()
  2071. // {
  2072. // if ($this->request->isGet() === false){
  2073. // $this->error('请求错误');
  2074. // }
  2075. // $param = $this->request->param();
  2076. // if (isset($param['UniqId']) === false){
  2077. // $this->error('参数错误');
  2078. // }
  2079. // $WorkOrderId = explode(',',$param['UniqId']);
  2080. // $i = 0;
  2081. // foreach ($WorkOrderId as $key=>$value){
  2082. // //获取工单编号
  2083. // $workorder = \db('工单_基本资料')
  2084. // ->where('Uniqid',$value)
  2085. // ->value('rtrim(Gd_gdbh)');
  2086. // //删除工单资料、工艺资料、印件资料
  2087. // \db()->startTrans();
  2088. // try {
  2089. // \db('工单_基本资料')->where('Gd_gdbh',$workorder)->delete();
  2090. // if (!empty(\db('工单_工艺资料')->where('Gy0_gdbh',$workorder)->find())){
  2091. // \db('工单_工艺资料')->where('Gy0_gdbh',$workorder)->delete();
  2092. // }
  2093. // if (!empty(\db('工单_印件资料')->where('Yj_Gdbh',$workorder)->find())){
  2094. // \db('工单_印件资料')->where('Yj_Gdbh',$workorder)->delete();
  2095. // }
  2096. // if (!empty(\db('工单_bom资料')->where('BOM_工单编号',$workorder)->find())){
  2097. // \db('工单_bom资料')->where('BOM_工单编号',$workorder)->delete();
  2098. // }
  2099. // \db()->commit();
  2100. // }catch (\Exception $e){
  2101. // \db()->rollback();
  2102. // $i++;
  2103. // }
  2104. // }
  2105. // if ($i === 0){
  2106. // $this->success('删除成功');
  2107. // }else{
  2108. // $this->error('删除失败');
  2109. // }
  2110. // }
  2111. /**
  2112. * 修正核算参数-》工单产品信息获取
  2113. * @return void
  2114. * @throws \think\db\exception\DataNotFoundException
  2115. * @throws \think\db\exception\ModelNotFoundException
  2116. * @throws \think\exception\DbException
  2117. */
  2118. // public function ProductNameData()
  2119. // {
  2120. // if ($this->request->isGet() === false){
  2121. // $this->error('请求错误');
  2122. // }
  2123. // $workOrder = input('workOrder');
  2124. // if (empty($workOrder)){
  2125. // $this->error('参数错误');
  2126. // }
  2127. // $orderList = \db('工单_基本资料')
  2128. // ->field('rtrim(Gd_cpdh) as 印件代号,rtrim(Gd_cpmc) as 印件名称,rtrim(成品代号) as 产品代号,rtrim(成品名称) as 产品名称')
  2129. // ->where('Gd_gdbh',$workOrder)
  2130. // ->find();
  2131. // $this->success('成功',$orderList);
  2132. // }
  2133. /**
  2134. * 获取联数
  2135. * @return void
  2136. * @throws \think\db\exception\DataNotFoundException
  2137. * @throws \think\db\exception\ModelNotFoundException
  2138. * @throws \think\exception\DbException
  2139. */
  2140. // public function getCouplet()
  2141. // {
  2142. // if ($this->request->isGet() === false){
  2143. // $this->error('请求错误');
  2144. // }
  2145. // $param = $this->request->param();
  2146. // if (empty($param['gdbh']) || empty($param['yjno'])){
  2147. // $this->error('参数错误');
  2148. // }
  2149. // $list = \db('工单_印件资料')
  2150. // ->where('Yj_gdbh',$param['gdbh'])
  2151. // ->where('yj_Yjno',$param['yjno'])
  2152. // ->field('rtrim(yj_ks) as 开数,rtrim(yj_ls) as 联数')
  2153. // ->find();
  2154. // $process = \db('工单_工艺资料')
  2155. // ->where('Gy0_gdbh',$param['gdbh'])
  2156. // ->where('Gy0_yjno',$param['yjno'])
  2157. // ->order('Gy0_gxh desc')
  2158. // ->value('Gy0_gxh');
  2159. // $list['工序号'] = $process + 1;
  2160. // $this->success('成功',$list);
  2161. // }
  2162. public function orderPrint()
  2163. {
  2164. if ($this->request->isGet() === false){
  2165. $this->error('请求错误');
  2166. }
  2167. $param = $this->request->param();
  2168. if (empty($param['order'])){
  2169. $this->error('参数错误');
  2170. }
  2171. $where['Mod_rq'] = null;
  2172. $list = \db('工单_基本资料')
  2173. ->where('订单编号',$param['order'])
  2174. ->where($where)
  2175. ->field('订单编号,生产款号,要求,客户编号,款式,落货日期,箱唛要求,面料,船样描述,船样合计,粘衬,订单数量,审核,审核日期,img')
  2176. ->find();
  2177. $xhdata = \db('工单_印件资料')
  2178. ->where('订单编号',$param['order'])
  2179. ->where('船样',0)
  2180. ->where($where)
  2181. ->field('cm1,cm2,cm3,cm4,cm5,cm6,cm7,cm8,cm9,cm10,款号')
  2182. ->select();
  2183. $arr = [];
  2184. foreach ($xhdata as $key => $value){
  2185. for($i=1;$i<=10;$i++){
  2186. if ($value['cm'.$i] !== '' && $value['cm'.$i] !== null){
  2187. array_push($arr,$value['cm'.$i]);
  2188. }
  2189. }
  2190. }
  2191. $arr = array_unique($arr);
  2192. $processlist = \db('工单_印件资料')
  2193. ->where('订单编号',$param['order'])
  2194. ->where($where)
  2195. // ->where('船样',0)
  2196. ->field('子订单编号,颜色,款号,zdtotal,cm1,cm2,cm3,cm4,cm5,cm6,
  2197. cm7,cm8,cm9,cm10,cmsl1,cmsl2,cmsl3,cmsl4,cmsl5,cmsl6,cmsl7,cmsl8,cmsl9,cmsl10,Uniqid')
  2198. ->select();
  2199. foreach ($processlist as $key=>$value){
  2200. for($i=1;$i<=10;$i++){
  2201. if ($value['cm'.$i] !== '' && $value['cm'.$i] !== null){
  2202. $processlist[$key][$value['cm'.$i]] = $value['cmsl'.$i];
  2203. }
  2204. unset($processlist[$key]['cm'.$i],$processlist[$key]['cmsl'.$i]);
  2205. }
  2206. }
  2207. $data['order'] = $list;
  2208. sort($arr);
  2209. $data['xhdata'] = $arr;
  2210. $data['process'] = $processlist;
  2211. $this->success('成功',$data);
  2212. }
  2213. /**
  2214. * 订单编号自动获取
  2215. * @return void
  2216. * @throws \think\db\exception\DataNotFoundException
  2217. * @throws \think\db\exception\ModelNotFoundException
  2218. * @throws \think\exception\DbException
  2219. */
  2220. public function getWorkOrder()
  2221. {
  2222. if ($this->request->isGet() === false){
  2223. $this->error('请求错误');
  2224. }
  2225. $time =substr( date('Ym',time()),2);
  2226. $lastOrder = \db('工单_基本资料')
  2227. ->where('订单编号','like','%'.$time.'%')
  2228. ->order('Uniqid desc')
  2229. ->find();
  2230. if (empty($lastOrder)){
  2231. $newNumber = 1;
  2232. }else{
  2233. $lastNumber = substr($lastOrder['订单编号'],6);
  2234. $newNumber = (int)$lastNumber + 1;
  2235. }
  2236. if ($newNumber<10){
  2237. $newOrder = 'DC'.$time.'00'.$newNumber;
  2238. }elseif ($newNumber>=10 && $newNumber<100){
  2239. $newOrder = 'DC'.$time.'0'.$newNumber;
  2240. }else{
  2241. $newOrder = 'DC'.$time.$newNumber;
  2242. }
  2243. $this->success('成功',$newOrder);
  2244. }
  2245. /**
  2246. * 获取子订单编号
  2247. * @return void
  2248. * @throws \think\db\exception\DataNotFoundException
  2249. * @throws \think\db\exception\ModelNotFoundException
  2250. * @throws \think\exception\DbException
  2251. */
  2252. public function getSuborder()
  2253. {
  2254. if ($this->request->isGet() === false){
  2255. $this->error('请求错误');
  2256. }
  2257. $param = $this->request->param();
  2258. if (empty($param)){
  2259. $this->error('参数错误');
  2260. }
  2261. if($param['cy'] == '否'){
  2262. $data = \db('工单_印件资料')
  2263. ->where('订单编号', $param['order'])
  2264. ->where('船样', '=', 0)
  2265. ->order('子订单编号 desc')
  2266. ->find();
  2267. if (empty($data)) {
  2268. $order = $param['order'] . '-01';
  2269. } else {
  2270. $num = (int)substr($data['子订单编号'], 10) + 1;
  2271. if ($num < 10) {
  2272. $order = $param['order'] . '-0' . $num;
  2273. } else {
  2274. $order = $param['order'] . '-' . $num;
  2275. }
  2276. }
  2277. $cm_data = [
  2278. 'cm1' => $data['cm1'] ?? '',
  2279. 'cm2' => $data['cm2'] ?? '',
  2280. 'cm3' => $data['cm3'] ?? '',
  2281. 'cm4' => $data['cm4'] ?? '',
  2282. 'cm5' => $data['cm5'] ?? '',
  2283. 'cm6' => $data['cm6'] ?? '',
  2284. 'cm7' => $data['cm7'] ?? '',
  2285. 'cm8' => $data['cm8'] ?? '',
  2286. 'cm9' => $data['cm9'] ?? '',
  2287. 'cm10' => $data['cm10'] ?? ''
  2288. ];
  2289. $result = [
  2290. 'order' => $order,
  2291. 'cm' => $cm_data
  2292. ];
  2293. $this->success('成功', $result);
  2294. }else if ($param['cy'] == '是') {
  2295. // 获取工单信息
  2296. $data = \db('工单_印件资料')
  2297. ->where('订单编号', $param['order'])
  2298. ->where('船样', '=', 1)
  2299. ->order('子订单编号 asc')
  2300. ->find();
  2301. if(empty($data)){
  2302. $order = $param['order'].'-99';
  2303. }else{
  2304. // 提取子订单编号中的数字部分
  2305. $subOrder = $data['子订单编号']; // 例如 "DC2410006-99"
  2306. // 使用正则匹配找到 "-数字" 的部分,并减去 1
  2307. if (preg_match('/-(\d+)$/', $subOrder, $matches)) {
  2308. $numberPart = (int)$matches[1]; // 提取到的数字部分,转换为整数
  2309. $newNumber = $numberPart - 1; // 减 1
  2310. // 将新的数字拼接回订单编号
  2311. $order = preg_replace('/-\d+$/', '-' . $newNumber, $subOrder);
  2312. } else {
  2313. // 如果没有找到子订单中的数字部分,保持原订单编号不变
  2314. $order = $subOrder;
  2315. }
  2316. }
  2317. $this->success('成功', $order);
  2318. }
  2319. // $data = \db('工单_印件资料')
  2320. // ->where('订单编号',$param['order'])
  2321. // ->where('船样',0)
  2322. // ->order('子订单编号 desc')
  2323. // ->find();
  2324. // if(empty($data)){
  2325. // $order = $param['order'].'-01';
  2326. // }else{
  2327. // $num = (int)substr($data['子订单编号'],10) + 1;
  2328. // if ($num<10){
  2329. // $order = $param['order'].'-0'.$num;
  2330. // }else{
  2331. // $order = $param['order'].'-'.$num;
  2332. // }
  2333. // }
  2334. // $this->success('成功',$order);
  2335. }
  2336. /**
  2337. * 订单资料修改
  2338. * @return void
  2339. * @throws \think\Exception
  2340. * @throws \think\db\exception\BindParamException
  2341. * @throws \think\exception\PDOException
  2342. */
  2343. public function WorkOrderEdit()
  2344. {
  2345. if (Request::instance()->isPost() === false){
  2346. $this->error('请求错误');
  2347. }
  2348. $param = Request::instance()->post();
  2349. if (empty($param)){
  2350. $this->error('参数错误');
  2351. }
  2352. $id = $param['id'];
  2353. unset($param['id']);
  2354. $sql = \db('工单_基本资料')
  2355. ->where('Uniqid',$id)
  2356. ->fetchSql(true)
  2357. ->update($param);
  2358. $res = \db()->query($sql);
  2359. if ($res === false){
  2360. $this->error('失败');
  2361. }else{
  2362. $this->success('成功');
  2363. }
  2364. }
  2365. /**
  2366. * 颜色资料修改
  2367. * @return void
  2368. * @throws \think\Exception
  2369. * @throws \think\db\exception\BindParamException
  2370. * @throws \think\exception\PDOException
  2371. */
  2372. public function PrintDataEdit()
  2373. {
  2374. if(Request::instance()->post() === false){
  2375. $this->error('请求错误');
  2376. }
  2377. $param = Request::instance()->post();
  2378. if (empty($param)){
  2379. $this->error('参数错误');
  2380. }
  2381. $id = $param['id'];
  2382. unset($param['id']);
  2383. $param['updatatime'] = date('Y-m-d H:i:s');
  2384. $sql = \db('工单_印件资料')
  2385. ->where('Uniqid',$id)
  2386. ->fetchSql(true)
  2387. ->update($param);
  2388. $res = \db()->query($sql);
  2389. if ($res === false){
  2390. $this->error('修改失败');
  2391. }else{
  2392. $this->success('修改成功');
  2393. }
  2394. }
  2395. /**
  2396. * 图片上传
  2397. * @return void
  2398. */
  2399. // public function ImgUpload(){
  2400. // $file = request()->file('image');
  2401. // if($file){
  2402. // $info = $file->validate(['size'=>10485760,'ext'=>'jpg,png'])->move(ROOT_PATH . 'public' . DS . 'uploads');
  2403. // if($info){
  2404. // $fileName = $info->getSaveName();
  2405. // $this->success('成功','public' . DS . 'uploads'. DS . $fileName);
  2406. // }else{
  2407. // $res = $file->getError();
  2408. // $this->error('失败',$res);
  2409. // }
  2410. // }
  2411. // }
  2412. public function ImgUpload(){
  2413. $file = request()->file('image');
  2414. if($file){
  2415. $info = $file->validate(['size'=>10485760,'ext'=>'jpg,png'])->move(ROOT_PATH . 'public' . DS . 'uploads');
  2416. if($info){
  2417. $fileName = $info->getSaveName();
  2418. $imageUrl = '/uploads/' . str_replace('\\', '/', $fileName);
  2419. return json(['code' => 0, 'msg' => '成功', 'data' => ['url' => $imageUrl]]);
  2420. }else{
  2421. $res = $file->getError();
  2422. return json(['code' => 1, 'msg' => '失败', 'data' => $res]);
  2423. }
  2424. }
  2425. return json(['code' => 1, 'msg' => '没有文件上传', 'data' => null]);
  2426. }
  2427. /**
  2428. * 工单技术附件
  2429. * @return void
  2430. * @throws \think\db\exception\DataNotFoundException
  2431. * @throws \think\db\exception\ModelNotFoundException
  2432. * @throws \think\exception\DbException
  2433. */
  2434. public function OrderAttachments()
  2435. {
  2436. if ($this->request->isGet() === false){
  2437. $this->error('请求错误');
  2438. }
  2439. $param = $this->request->param();
  2440. if (empty($param)){
  2441. $this->error('参数错误');
  2442. }
  2443. $list = \db('工单_相关附件')
  2444. ->where('关联编号',$param['order'])
  2445. ->where('附件备注',$param['desc'])
  2446. ->whereNull('Mod_rq')
  2447. ->select();
  2448. $this->success('成功',$list);
  2449. }
  2450. }