WorkOrder.php 108 KB

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