WorkOrder.php 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931
  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. {
  284. if ($this->request->isGet() === false) {
  285. $this->error('请求错误');
  286. }
  287. // 查询生产中和未生产的数据,使用 CASE WHEN 进行分类统计
  288. $data = \db('工单_基本资料')->alias('j')
  289. ->field('
  290. j.客户编号,
  291. REPLACE(DATE_FORMAT(j.Sys_rq, "%Y-%m"), "-", "") as 年月,
  292. SUM(CASE WHEN j.gd_statu = "2-生产中" THEN 1 ELSE 0 END) as 生产中数量,
  293. SUM(CASE WHEN j.gd_statu = "1-计划中" THEN 1 ELSE 0 END) as 未生产数量
  294. ')
  295. ->where('j.Mod_rq', null) // 统一的查询条件
  296. ->group('j.客户编号, 年月')
  297. ->order('j.客户编号 asc')
  298. ->select();
  299. // 格式化数据
  300. $result = [];
  301. foreach ($data as $item) {
  302. $result[$item['年月']][] = $item['客户编号'] . '【生产中' . $item['生产中数量'] . ',计划中' . $item['未生产数量'] . '】';
  303. }
  304. $this->success('请求成功', ['data' => $result]);
  305. }
  306. // public function ProductInformation(){
  307. // if ($this->request->isGet() === false) {
  308. // $this->error('请求错误');
  309. // }
  310. // $where['j.gd_statu'] = '2-生产中';
  311. // $where['j.Mod_rq'] = null;
  312. //
  313. // $data = \db('工单_基本资料')->alias('j')
  314. // ->field('j.客户编号, REPLACE(DATE_FORMAT(j.Sys_rq, "%Y-%m"), "-", "") as 年月, GROUP_CONCAT(DISTINCT j.订单编号) as 订单编号')
  315. // ->where($where)
  316. // ->order('j.客户编号 asc')
  317. // ->group('j.客户编号, 年月')
  318. // ->select();
  319. // $result = [];
  320. // foreach ($data as $item) {
  321. // $orderlist = count(explode(',', $item['订单编号']));
  322. // $result[$item['年月']][] = [$item['客户编号'] . '【生产中:' . $orderlist . '】',
  323. // ];
  324. // }
  325. //
  326. // $this->success('请求成功', ['data' => $result]);
  327. // }
  328. /**
  329. * 引用产品资料->复制产品工艺资料
  330. * @ApiMethod (POST)
  331. * @param string $oldWorkOrder 被复制工单编号
  332. * @param string $newWorkOrder 复制工单编号
  333. * @return void
  334. * @throws \think\Exception
  335. * @throws \think\db\exception\DataNotFoundException
  336. * @throws \think\db\exception\ModelNotFoundException
  337. * @throws \think\exception\DbException
  338. * @throws \think\exception\PDOException
  339. */
  340. // public function ProductInformationEdit()
  341. // {
  342. // if (Request::instance()->isPost() === false)
  343. // {
  344. // $this->error('请求错误');
  345. // }
  346. // $oldWorkOrder = input('oldWorkOrder');
  347. // $newWorkOrder = input('newWorkOrder');
  348. // if (empty($oldWorkOrder) || empty($newWorkOrder))
  349. // {
  350. // $this->error('参数错误');
  351. // }
  352. // $lastId = \db('工单_工艺资料')->order('UniqId desc')->value('UniqId');
  353. // if ($lastId<10000000){
  354. // $lastId = 10000000;
  355. // }else{
  356. // $lastId = $lastId + 1;
  357. // }
  358. // //获取原工单工艺资料
  359. // $oldProcessData = \db('工单_工艺资料')->where('Gy0_gdbh',$newWorkOrder)->select();
  360. // $ProsessUniqId = \db('工单_工艺资料')->field('UniqId')->order('UniqId desc')->find();
  361. // foreach ($oldProcessData as $k=>$v){
  362. // $oldProcessData[$k]['Gy0_gdbh'] = $oldWorkOrder;
  363. // $oldProcessData[$k]['Sys_id'] = '';
  364. // $oldProcessData[$k]['Gy0_sj1'] = '1900-01-01 00:00:00';
  365. // $oldProcessData[$k]['Gy0_sj2'] = '1900-01-01 00:00:00';
  366. // $oldProcessData[$k]['UniqId'] = $lastId + $k;
  367. // $oldProcessData[$k]['PD_WG'] = '1900-01-01 00:00:00';
  368. // }
  369. // if (\db('工单_工艺资料')->where('Gy0_gdbh',$oldWorkOrder)->find()){
  370. // \db('工单_工艺资料')->where('Gy0_gdbh',$oldWorkOrder)->delete();
  371. // }
  372. // //获取原工单印件资料
  373. // $lastUniqId = \db('工单_印件资料')->order('UniqId desc')->value('UniqId');
  374. // if ($lastUniqId<1000000){
  375. // $lastUniqId = 1000000;
  376. // }else{
  377. // $lastUniqId = $lastUniqId + 1;
  378. // }
  379. // $oldPrintData = \db('工单_印件资料')->where('Yj_Gdbh',$newWorkOrder)->select();
  380. // $PrintUniqId = \db('工单_印件资料')->field('Uniqid')->order('Uniqid desc')->find();
  381. // foreach ($oldPrintData as $k=>$v){
  382. // $oldPrintData[$k]['Yj_Gdbh'] = $oldWorkOrder;
  383. // $oldPrintData[$k]['Sys_id'] = '';
  384. // $oldPrintData[$k]['Uniqid'] = $lastUniqId +$k +1;
  385. // }
  386. // if (\db('工单_印件资料')->where('Yj_Gdbh',$oldWorkOrder)->find()){
  387. // \db('工单_印件资料')->where('Yj_Gdbh',$oldWorkOrder)->delete();
  388. // }
  389. // //复制印件、工艺资料
  390. // $ProcessSQL = \db('工单_工艺资料')->fetchSql(true)->insertAll($oldProcessData);
  391. // $ProcessRes = Db::query($ProcessSQL);
  392. // $PrintSQL = \db('工单_印件资料')->fetchSql(true)->insertAll($oldPrintData);
  393. // $PrintRes = Db::query($PrintSQL);
  394. // if ($ProcessRes !== false && $PrintRes !== false){
  395. // $this->success('成功');
  396. // }else{
  397. // $this->error('失败');
  398. // }
  399. // }
  400. /**
  401. * 工艺流程调成->获取当前工单工艺资料
  402. * @ApiMethod (GET)
  403. * @param string $workorder 当前工单编号
  404. * @return void
  405. * @throws \think\db\exception\DataNotFoundException
  406. * @throws \think\db\exception\ModelNotFoundException
  407. * @throws \think\exception\DbException
  408. */
  409. // public function ProcessFlow()
  410. // {
  411. // if ($this->request->isGet() === false){
  412. // $this->error('请求错误');
  413. // }
  414. // $workOrder = input('workOrder');
  415. // if (empty($workOrder)){
  416. // $this->error('参数错误');
  417. // }
  418. // $list = \db('工单_基本资料')->where('Gd_gdbh',$workOrder)->field('rtrim(成品代号) as 成品编号,rtrim(成品名称) as 成品名称')->find();
  419. // if (empty($list)){
  420. // $this->success('未找到工单信息');
  421. // }
  422. // $filed = 'rtrim(Gy0_方案) as 方案,rtrim(Gy0_yjno) as 印件号,rtrim(Gy0_gxh) as 工序号,rtrim(Gy0_gxmc) as gxmc,rtrim(Add_gxmc) as add_gxmc,
  423. // rtrim(工价系数) as 工价系数,rtrim(损耗系数) as 损耗系数,rtrim(Gy0_ks) as ks,rtrim(Gy0_ls) as ls,rtrim(工序备注) as 备注,rtrim(Gy0_SITE) as 车间,
  424. // rtrim(Gy0_sbbh) as 设备编号,rtrim(Gy0_sbmc) as 设备名称,rtrim(Sys_id) as 建档用户,rtrim(Sys_rq) as 建档时间,rtrim(Mod_rq) as 更新时间,rtrim(UniqId) as UniqId';
  425. // $process = \db('工单_工艺资料')->where('Gy0_gdbh',$workOrder)->cache(true,84600)->field($filed)->select();
  426. // if (empty($process)){
  427. // $this->error('未找到该工单工艺资料');
  428. // }
  429. // foreach ($process as $key=>$value){
  430. // if (isset($value['add_gxmc'])){
  431. // $process[$key]['工序名称'] = $value['gxmc'] . '【'.$value['add_gxmc'].'】';
  432. // }else{
  433. // $process[$key]['工序名称'] = $value['gxmc'];
  434. // }
  435. // $process[$key]['工价系数'] = (float)$value['工价系数'];
  436. // $process[$key]['损耗系数'] = (float)$value['损耗系数'];
  437. // $process[$key]['开数*联数'] = $value['ks'].'*'.$value['ls'];
  438. // }
  439. // $list['process'] = $process;
  440. // $this->success('成功',$list);
  441. // }
  442. /**
  443. * 参照工单列表获取
  444. * @ApiMethod (GET)
  445. * @param string $workOrder 工单编号
  446. * @param string $productCode 产品代号
  447. * @return void
  448. */
  449. // public function ReferenceWorkOrder()
  450. // {
  451. // if ($this->request->isGet() === false){
  452. // $this->error('请求错误');
  453. // }
  454. // $productCode = input('productCode');
  455. // $workOrder = input('workOrder');
  456. // if (empty($productCode) || empty($workOrder)){
  457. // $this->error('参数错误');
  458. // }
  459. // $list = \db('工单_基本资料')->where('成品代号',$productCode)->distinct(true)->where('Gd_gdbh','<>',$workOrder)->column('Gd_gdbh');
  460. // if (empty($list)){
  461. // $this->success('未获取该产品其他工单信息');
  462. // }
  463. // $this->success('成功',$list);
  464. // }
  465. /**
  466. * 工艺资料复制
  467. * @ApiMethod (POST)
  468. * @param string $oldWorkOrder 被复制工单编号
  469. * @param string $newWorkOrder 复制工单编号
  470. * @return void
  471. * @throws \think\Exception
  472. * @throws \think\db\exception\DataNotFoundException
  473. * @throws \think\db\exception\ModelNotFoundException
  474. * @throws \think\exception\DbException
  475. * @throws \think\exception\PDOException
  476. *
  477. */
  478. // public function ProcessCopy()
  479. // {
  480. // if (Request::instance()->isPost() === false){
  481. // $this->error('请求错误');
  482. // }
  483. // $param = Request::instance()->post();
  484. // if (empty($param)){
  485. // $this->error('参数错误');
  486. // }
  487. // $UniqId = [];
  488. // $lastId = \db('工单_工艺资料')->field('rtrim(UniqId) as id')->order('UniqId desc')->find();
  489. // if ($lastId['id']>10000000){
  490. // $lastUniqId = $lastId['id'];
  491. // }else{
  492. // $lastUniqId = 10000000;
  493. // }
  494. // foreach ($param as $key=>$value){
  495. // $UniqId[$key] = $value['UniqId'];
  496. // }
  497. // $processList = \db('工单_工艺资料')->where('UniqId','in',$UniqId)->select();
  498. // if (empty($processList)){
  499. // $this->success('未找到工艺资料');
  500. // }
  501. // $data = [];
  502. // foreach ($param as $key=>$value){
  503. // foreach ($processList as $k=>$v){
  504. // if ($value['UniqId'] = $v['UniqId']){
  505. // $data[$key] = $v;
  506. // $data[$key]['Gy0_gxh'] = $value['gxh'];
  507. // $data[$key]['Gy0_gdbh'] = $value['workOrder'];
  508. // $data[$key]['UniqId'] = $lastUniqId + $key + 1;
  509. // }
  510. // }
  511. // }
  512. // $res = \db('工单_工艺资料')->where(['Gy0_gdbh'=>$param[0]['workOrder']])->delete();
  513. // if ($res !== false){
  514. // $result = \db('工单_工艺资料')->insertAll($data);
  515. // if ($result !== false){
  516. // $this->success('成功');
  517. // }else{
  518. // $this->error('失败');
  519. // }
  520. // }else{
  521. // $this->error('失败');
  522. // }
  523. // }
  524. /**
  525. * U8工单列表
  526. * @ApiMethod (GET)
  527. * @param void
  528. * @return void
  529. * @throws \think\db\exception\DataNotFoundException
  530. * @throws \think\db\exception\ModelNotFoundException
  531. * @throws \think\exception\DbException
  532. */
  533. // public function U8workOrder()
  534. // {
  535. // if ($this->request->isGet() === false){
  536. // $this->error('请求错误');
  537. // }
  538. // $param = $this->request->param();
  539. // if (empty($param)){
  540. // $this->error('参数错误');
  541. // }
  542. // $filed = 'rtrim(Gd_gdbh) as 工单编号,rtrim(行号) as 行号,rtrim(Gd_客户代号) as 客户代号,rtrim(Gd_客户名称) as 客户名称,
  543. // rtrim(成品代号) as 成品代号,rtrim(成品名称) as 成品名称,rtrim(Mod_rq) as 获取日期,rtrim(Uniqid) as 序号';
  544. // $list = \db('工单_基本资料')->where('Gd_gdbh',$param['workOrder'])->field($filed)->select();
  545. // if (empty($list)){
  546. // $this->success('未找到工单');
  547. // }
  548. // $this->success('成功',$list);
  549. // }
  550. /**
  551. * U8工单资料删除
  552. * @param string $workOrder 工单编号
  553. * @return void
  554. * @throws \think\Exception
  555. * @throws \think\exception\PDOException
  556. */
  557. public function orderDataDel()
  558. {
  559. if($this->request->isGet() === false){
  560. $this->error('请求错误');
  561. }
  562. $workOrder = input('Uniqid');
  563. if (empty($workOrder)){
  564. $this->error('参数错误');
  565. }
  566. $order = \db('工单_基本资料')->where('UniqId',$workOrder)->find();
  567. \db()->startTrans();
  568. try {
  569. \db('工单_印件资料')->where('订单编号',$order['订单编号'])->update(['Mod_rq'=>date('Y-m-d H:i:s')]);
  570. \db('工单_工艺资料')->where('订单编号',$order['订单编号'])->update(['Mod_rq'=>date('Y-m-d H:i:s')]);
  571. $res = \db('工单_基本资料')->where('UniqId',$workOrder)->update(['Mod_rq'=>date('Y-m-d H:i:s')]);
  572. \db()->commit();
  573. } catch (\Exception $e){
  574. \db()->rollback();
  575. }
  576. if ($res !== false){
  577. $this->success('成功');
  578. }else{
  579. $this->error('失败');
  580. }
  581. }
  582. /**
  583. *
  584. */
  585. // public function TestCoefficient()
  586. // {
  587. // }
  588. /**
  589. *
  590. */
  591. // public function TestCoefficientEdit()
  592. // {
  593. // }
  594. /**
  595. *
  596. */
  597. // public function AccountingParameter()
  598. // {
  599. // }
  600. /**
  601. *
  602. */
  603. // public function AccountingParameterEdit()
  604. // {
  605. // }
  606. /**
  607. * 印件资料修改
  608. * @ApiMethod (POST)
  609. * @param void
  610. * @return void
  611. * @throws \think\Exception
  612. * @throws \think\exception\PDOException
  613. */
  614. public function PrintedEdit()
  615. {
  616. if (Request::instance()->isPost() === false){
  617. $this->error('请求错误');
  618. }
  619. $param = Request::instance()->post();
  620. if (empty($param) || isset($param['Uniqid']) === false){
  621. $this->error('参数错误');
  622. }
  623. $param['Yj_Gdbh'] = \db('工单_印件资料')->where('Uniqid',$param['Uniqid'])->value('Yj_Gdbh');
  624. $data = [
  625. 'Yj_Gdbh' =>$param['Yj_Gdbh'],
  626. 'yj_Yjno' =>$param['yjno'],
  627. 'yj_Yjdh' =>$param['yjdh'],
  628. 'yj_yjmc' =>$param['yjmc'],
  629. 'yj_zzdh' =>$param['zzdh'],
  630. 'yj_zzdh1' =>$param['zzdh1'],
  631. 'yj_zzdh2' =>$param['zzdh2'],
  632. 'yj_zzdh3' =>$param['zzdh3'],
  633. 'yj_zzdh4' =>$param['zzdh4'],
  634. 'yj_zzmc' =>$param['zzmc'],
  635. 'yj_zzmc1' =>$param['zzmc1'],
  636. 'yj_zzmc2' =>$param['zzmc2'],
  637. 'yj_zzmc3' =>$param['zzmc3'],
  638. 'yj_zzmc4' =>$param['zzmc4'],
  639. 'yj_tlgg' =>$param['tlgg'],
  640. 'yj_klgg' =>$param['klgg'],
  641. 'Yj_核算规格' =>$param['hsgg'],
  642. 'yj_成品数量' =>$param['cpsl'],
  643. 'yj_平张投料' =>$param['pztl'],
  644. 'yj_ks' =>$param['ks'],
  645. 'yj_ls' =>$param['ls'],
  646. 'yj_desc' =>$param['desc'],
  647. ];
  648. $UniqId = $param['Uniqid'];
  649. $sql = \db('工单_印件资料')->where('Uniqid',$UniqId)->fetchSql(true)->update($data);
  650. $res = Db::query($sql);
  651. $process = \db('工单_工艺资料')
  652. ->where('Gy0_gdbh',$data['Yj_Gdbh'])
  653. ->where('Gy0_yjno',$data['yj_Yjno'])
  654. ->select();
  655. if ((int)$data['yj_平张投料'] > 0 && !empty($process)){
  656. //重新分配工序计划产量
  657. $result = $this->PlannedProcessYield($data['Yj_Gdbh'],$data['yj_Yjno'],0,$data['yj_平张投料']);
  658. if ($result === false){
  659. $this->success('修改工序产量失败');
  660. }
  661. }
  662. if ($res !== false){
  663. $this->success('成功');
  664. }else{
  665. $this->error('失败');
  666. }
  667. }
  668. /**
  669. * 工艺资料修改
  670. * @ApiMethod (POST)
  671. */
  672. public function ProcessDetailEdit()
  673. {
  674. if (Request::instance()->isPost() === false){
  675. $this->error('请求错误');
  676. }
  677. $param = Request::instance()->post();
  678. if (empty($param) || isset($param['UniqId']) === false){
  679. $this->error('参数错误');
  680. }
  681. if (empty($param['Gy0_shdh'])){
  682. $rate['rate0'] = 0;
  683. $rate['rate1'] = 0;
  684. }else{
  685. $rate = \db('dic_lzsh')->where('sys_bh',$param['Gy0_shdh'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->find();
  686. }
  687. $param['Gy0_Rate0']= isset($rate['rate0'])?$rate['rate0']:0;
  688. $param['Gy0_Rate1'] = isset($rate['rate1'])?$rate['rate1']:0;
  689. $param['Mod_rq'] = date('Y-m-d H:i:s',time());
  690. $UniqId = $param['UniqId'];
  691. unset($param['UniqId']);
  692. //修改工艺资料
  693. $sql = \db('工单_工艺资料')->where('UniqId',$UniqId)->fetchSql(true)->update($param);
  694. $res = Db::query($sql);
  695. //获取工艺资料数据
  696. $list = \db('工单_工艺资料')->where('UniqId',$UniqId)->field('Gy0_yjno,Gy0_gxh,rtrim(Gy0_计划接货数) as 计划接货数')->find();
  697. // //修改工单状态
  698. // $status = \db('工单_基本资料')->where('Gd_gdbh',$param['Gy0_gdbh'])->field('rtrim(gd_statu) as status')->find();
  699. // if ($status['status'] !== '2-生产中'){
  700. // $statusSql = \db('工单_基本资料')->where('Gd_gdbh',$param['Gy0_gdbh'])->fetchSql(true)->update(['gd_statu'=>'2-生产中']);
  701. // Db::query($statusSql);
  702. // }
  703. //重新分配工序计划产量
  704. if ((int)$list['计划接货数'] > 0){
  705. $result = $this->PlannedProcessYield($param['Gy0_gdbh'],$list['Gy0_yjno'],$list['Gy0_gxh'],$list['计划接货数']);
  706. }
  707. if ($res !== false){
  708. $this->success('成功');
  709. }else{
  710. $this->error('失败');
  711. }
  712. }
  713. /**
  714. *
  715. */
  716. // public function MachineList()
  717. // {
  718. // }
  719. /**
  720. *
  721. */
  722. // public function PrintCodeList()
  723. // {
  724. // }
  725. /**
  726. *
  727. */
  728. // public function ProcessCodeList()
  729. // {
  730. // }
  731. /**
  732. *
  733. */
  734. // public function PrintJobOrder()
  735. // {
  736. // }
  737. /**
  738. *
  739. */
  740. // public function workOrderDetailGet($workOrder,$yjno)
  741. // {
  742. // }
  743. /**
  744. */
  745. // public function MaterielDetailGet($workOrder)
  746. // {
  747. // }
  748. /**
  749. */
  750. // public function PrintDetailGet($workOrder,$yjno,$gxh)
  751. // {
  752. // }
  753. /**
  754. *
  755. */
  756. // public function capacityList(){
  757. // }
  758. /**
  759. * 新增工单->添加工单
  760. * @ApiMethod (POST)
  761. * @param
  762. */
  763. public function WorkOrderAdd()
  764. {
  765. // var_dump(1);exit;
  766. if (Request::instance()->isPost() === false){
  767. $this->error('请求错误');
  768. }
  769. $param = Request::instance()->post();
  770. if (empty($param)){
  771. $this->error('参数错误');
  772. }
  773. $param['Sys_rq'] = date('Y-m-d H:i:s');
  774. $param['gd_statu'] = '1-计划中';
  775. $prefix = substr($param['订单编号'], 0, 2); // e.g., "DC"
  776. $maxOrder = \db('工单_基本资料')
  777. ->where('订单编号', 'like', "{$prefix}%")
  778. ->order('订单编号', 'desc')
  779. ->limit(1)
  780. ->value('订单编号');
  781. if ($maxOrder) {
  782. $numericPart = substr($maxOrder, 2);
  783. $newNumericPart = str_pad((int)$numericPart + 1, strlen($numericPart), '0', STR_PAD_LEFT);
  784. $param['订单编号'] = $prefix . $newNumericPart;
  785. } else {
  786. $param['订单编号'] = $param['订单编号'];
  787. }
  788. $sql= \db('工单_基本资料')->fetchSql(true)->insert($param);
  789. $res = \db()->query($sql);
  790. if ($res !== false){
  791. $this->success('成功');
  792. }else{
  793. $this->error('失败');
  794. }
  795. }
  796. /**
  797. *
  798. */
  799. // public function ClientList(){
  800. // }
  801. /**
  802. *
  803. */
  804. // public function ProductCodeList(){
  805. // }
  806. /**
  807. * 新增印件资料->印件资料添加
  808. * @return void
  809. * @throws \think\db\exception\BindParamException
  810. * @throws \think\exception\PDOException
  811. */
  812. public function PrintDetailAdd()
  813. {
  814. if (Request::instance()->isPost() === false){
  815. $this->error('请求错误');
  816. }
  817. $param = Request::instance()->post();
  818. if (empty($param)){
  819. $this->error('参数错误');
  820. }
  821. $param['Sys_rq'] = date('Y-m-d H:i:s',time());
  822. $process = [
  823. ['1','仓库出库'],['2','裁剪'],['3','车缝'],['4','后道收样'],['5','大烫'],['6','总检'],['7','包装']
  824. ];
  825. $processDetail = [];
  826. foreach ($process as $key=>$value){
  827. $total = null;
  828. if ($key !== 0){
  829. $total = $param['zdtotal'];
  830. }
  831. $processDetail[$key] = [
  832. '订单编号' => $param['订单编号'],
  833. '子订单编号' => $param['子订单编号'],
  834. '款号' => $param['款号'],
  835. '颜色' => $param['颜色'],
  836. '颜色备注' => $param['颜色备注'],
  837. '工序编号' => $value[0],
  838. '工序名称' => $value[1],
  839. '计划产量' => $total,
  840. 'Sys_id' => $param['Sys_id'],
  841. 'Sys_rq' => $param['Sys_rq']
  842. ];
  843. }
  844. //开启事务
  845. db()->startTrans();
  846. try{
  847. $priSql = \db('工单_印件资料')->fetchSql(true)->insert($param);
  848. $priRes = \db()->query($priSql);
  849. $proSql = \db('工单_工艺资料')->fetchSql(true)->insertAll($processDetail);
  850. $proRes = \db()->query($proSql);
  851. // 提交事务
  852. db()->commit();
  853. } catch (\Exception $e) {
  854. // 回滚事务
  855. db()->rollback();
  856. $this->error($e->getMessage());
  857. }
  858. if ($priRes !== false && $proRes !== false){
  859. $this->success('成功');
  860. }else{
  861. $this->error('失败');
  862. }
  863. }
  864. /**
  865. *
  866. */
  867. // public function ProcessDetailAdd(){
  868. // }
  869. /**
  870. *
  871. */
  872. // public function PrintDetailList(){
  873. // }
  874. /**
  875. * 子订单列表
  876. * @return null
  877. * @throws \think\db\exception\DataNotFoundException
  878. * @throws \think\db\exception\ModelNotFoundException
  879. * @throws \think\exception\DbException
  880. */
  881. public function PrintListData()
  882. {
  883. // 检查请求方式
  884. if ($this->request->isGet() === false) {
  885. $this->error('请求错误');
  886. }
  887. $param = $this->request->param();
  888. // 检查参数是否存在
  889. if (isset($param) === false) {
  890. $this->error('参数错误');
  891. }
  892. // 查询型号
  893. $where['Mod_rq'] = null;
  894. $xhdata = \db('工单_印件资料')
  895. ->where('订单编号', $param['order'])
  896. ->where($where)
  897. ->field('cm1,cm2,cm3,cm4,cm5,cm6,cm7,cm8,cm9,cm10')
  898. ->select();
  899. $arr = [];
  900. // 收集cm1到cm10的非空非null值
  901. foreach ($xhdata as $key => $value) {
  902. for ($i = 1; $i <= 10; $i++) {
  903. if ($value['cm' . $i] !== '' && $value['cm' . $i] !== null) {
  904. array_push($arr, $value['cm' . $i]);
  905. }
  906. }
  907. }
  908. $arr = array_unique($arr);
  909. sort($arr);
  910. // 查询详细列表
  911. $list = \db('工单_印件资料')
  912. ->where('订单编号', $param['order'])
  913. ->where($where)
  914. ->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')
  915. ->select();
  916. // 遍历列表并处理cm和cmsl字段
  917. foreach ($list as $key => $value) {
  918. for ($i = 1; $i <= 10; $i++) {
  919. if ($value['cm' . $i] !== '') {
  920. // 如果 cmsl 的值为 0,则设置为空字符串
  921. $list[$key][$value['cm' . $i]] = ($value['cmsl' . $i] === 0) ? '' : $value['cmsl' . $i];
  922. }
  923. // 删除原有的 cm 和 cmsl 字段
  924. // unset($list[$key]['cm' . $i], $list[$key]['cmsl' . $i]);
  925. }
  926. }
  927. // 自定义型号排序
  928. $customOrder = array('XXS','XS','S', 'M', 'L', 'XL','XXL', '2XL', '3XL', '4XL');
  929. usort($arr, function ($a, $b) use ($customOrder) {
  930. $posA = array_search($a, $customOrder);
  931. $posB = array_search($b, $customOrder);
  932. return $posA - $posB;
  933. });
  934. // 返回结果
  935. $data['型号'] = $arr;
  936. $data['列表'] = $list;
  937. $this->success('成功', $data);
  938. }
  939. /**
  940. * 工单资料管理->印件资料删除
  941. * @return void
  942. * @throws \think\Exception
  943. * @throws \think\exception\PDOException
  944. */
  945. public function PrintDetailDel()
  946. {
  947. if ($this->request->isGet() === false){
  948. $this->error('请求错误');
  949. }
  950. $param = $this->request->param();
  951. if (isset($param['UniqId']) === false){
  952. $this->error('参数错误');
  953. }
  954. $printId = explode(',',$param['UniqId']);
  955. $i = 0;
  956. foreach ($printId as $value){
  957. $res = \db('工单_印件资料')
  958. ->where('Uniqid',$value)
  959. ->update(['Mod_rq'=>date('Y-m-d H:i:s',time())]);
  960. if ($res === false){
  961. $i++;
  962. }
  963. }
  964. if ($i === 0){
  965. $this->success('删除成功');
  966. }else{
  967. $this->error('删除失败');
  968. }
  969. }
  970. /**
  971. * 月度车间报工汇总->报工删除记录
  972. */
  973. public function ProcessDetailDel()
  974. {
  975. if ($this->request->isGet() === false){
  976. $this->error('请求错误');
  977. }
  978. $where['a.mod_rq'] = ['neq', ''];
  979. $list = \db('设备_产量计酬')->alias('a')
  980. ->join('工单_印件资料 b', 'b.订单编号 = a.订单编号 AND a.子订单编号 = a.子订单编号')
  981. ->join('工单_基本资料 j', 'b.订单编号 = j.订单编号', 'LEFT')
  982. ->field('
  983. b.订单编号, b.子订单编号, b.款号, b.颜色, b.船样, a.尺码, b.zdtotal as 制单数,b.颜色备注,
  984. a.数量, a.sys_rq as 上报时间,a.UniqId,a.mod_rq,a.delsys_id,a.sczl_bh,
  985. j.客户编号,j.生产款号,j.款式
  986. ')
  987. ->where($where)
  988. ->order('a.mod_rq desc')
  989. ->group('a.UniqId')
  990. ->select();
  991. // 提取所有的尺码,并去重
  992. $sizeList = array_values(array_unique(array_column($list, '尺码')));
  993. // 动态将尺码的数量添加到每个订单中,并替换已完成字段
  994. foreach ($list as &$item) {
  995. $size = $item['尺码'];
  996. $item[$size] = $item['数量']; // 动态添加尺码字段,值为数量
  997. // unset($item['数量']); // 移除原来的已完成字段
  998. }
  999. $data['total'] = count($list);
  1000. $data['table'] = $list;
  1001. $this->success('成功',$data);
  1002. }
  1003. /**
  1004. *
  1005. */
  1006. // public function WastageList(){
  1007. // }
  1008. /**
  1009. *
  1010. */
  1011. // public function getAnnexTable(){
  1012. // }
  1013. /**
  1014. *
  1015. */
  1016. // public function annexAdd(){
  1017. // }
  1018. /**
  1019. *
  1020. */
  1021. // public function annexDel(){
  1022. // }
  1023. /**
  1024. *
  1025. */
  1026. // public function getGdAnnexTable(){
  1027. // }
  1028. /**
  1029. * 产品附件新增
  1030. * 1.前端进行上传xlsx文件表格
  1031. * 2.接口接受数据文件进行保存xlsx文件以及pdf转换
  1032. * 3.前端进行预览pdf图片显示文件中的内容再页面上
  1033. */
  1034. public function gdAnnexAdd() {
  1035. ini_set('display_errors', 'On');
  1036. ini_set('error_reporting', E_ALL);
  1037. if (!$this->request->isPost()) {
  1038. $this->error('请求方式错误');
  1039. }
  1040. // 获取请求参数
  1041. $req = $this->request->param();
  1042. $relateId = $req['关联编号'];
  1043. $attachmentContent = $req['附件内容'];
  1044. $attachmentType = $req['附件类型'];
  1045. $prefixDir = ROOT_PATH . '/public/';
  1046. $uploadDir = ''.'uploads/' . date('Ymd') . '/' . $relateId;
  1047. DB::name('工单_基本资料')
  1048. ->where('订单编号', $relateId)
  1049. ->update(['gd_statu' => '2-生产中']);
  1050. // 检查并创建目录
  1051. if (!is_dir($prefixDir . $uploadDir)) {
  1052. mkdir($prefixDir . $uploadDir, 0777, true);
  1053. }
  1054. // 处理 Base64 附件内容
  1055. if (strpos($attachmentContent, 'base64,') !== false) {
  1056. $attachmentContent = explode('base64,', $attachmentContent)[1];
  1057. }
  1058. $fileContent = base64_decode($attachmentContent);
  1059. $filename = time();
  1060. // 初始化文件路径变量
  1061. $xlsxFilePath = '';
  1062. $pdfFilePath = '';
  1063. if ($attachmentType === 'pdf') {
  1064. // 保存 PDF 文件
  1065. $pdfFilePath = $uploadDir . '/' . $filename . '.pdf';
  1066. file_put_contents($prefixDir . $pdfFilePath, $fileContent);
  1067. } elseif ($attachmentType === 'xlsx') {
  1068. // 保存 Excel 文件
  1069. $xlsxFilePath = $uploadDir . '/' . $filename . '.xlsx';
  1070. file_put_contents($prefixDir . $xlsxFilePath, $fileContent);
  1071. // 转换为 PDF 文件
  1072. $pdfFilePath = $uploadDir . '/' . $filename . '.pdf';
  1073. $cmd = sprintf(
  1074. 'libreoffice --headless --convert-to pdf --outdir %s %s',
  1075. escapeshellarg($prefixDir . $uploadDir),
  1076. escapeshellarg($prefixDir . $xlsxFilePath)
  1077. );
  1078. exec($cmd, $out, $retval);
  1079. if ($retval !== 0) {
  1080. $this->error('Excel 转 PDF 失败');
  1081. }
  1082. } else {
  1083. $this->error('不支持的附件类型');
  1084. }
  1085. // 组织数据
  1086. $data = [
  1087. '关联编号' => $relateId,
  1088. 'sys_id' => $req['sys_id'],
  1089. '附件备注' => $req['附件备注'],
  1090. '附件类型' => $attachmentType,
  1091. 'sys_rq' => date('Y-m-d H:i:s'),
  1092. 'url' => $xlsxFilePath, // 保存 xlsx 文件路径(如果存在)
  1093. 'pdf' => $pdfFilePath // 保存 pdf 文件路径
  1094. ];
  1095. // 数据库事务处理
  1096. db()->startTrans();
  1097. try {
  1098. // 插入数据
  1099. $sql = db('工单_相关附件')->fetchSql(true)->insert($data);
  1100. $result = db()->query($sql);
  1101. db()->commit();
  1102. } catch (\Exception $e) {
  1103. // 回滚事务
  1104. db()->rollback();
  1105. $this->error($e->getMessage());
  1106. }
  1107. if ($result === false) {
  1108. $this->error('失败');
  1109. }
  1110. $this->success('成功');
  1111. }
  1112. /**
  1113. *
  1114. */
  1115. // public function gdAnnexDel()
  1116. // {
  1117. // }
  1118. /**
  1119. *
  1120. */
  1121. // public function WorkOrderDetailCope()
  1122. // {
  1123. // }
  1124. //
  1125. /**
  1126. *
  1127. */
  1128. // public function WorkOrderDetailListCope()
  1129. // {
  1130. // }
  1131. /**
  1132. *
  1133. */
  1134. // public function ProductCopeDetail()
  1135. // {
  1136. // }
  1137. /**
  1138. *
  1139. */
  1140. // public function PlannedProcessYield($workOrder,$yjno,$gxh,$feed)
  1141. // {
  1142. // }
  1143. /**
  1144. *
  1145. */
  1146. // public function WorkOrderDel()
  1147. // {
  1148. // }
  1149. /**
  1150. *
  1151. */
  1152. // public function ProductNameData()
  1153. // {
  1154. // }
  1155. /**
  1156. *
  1157. */
  1158. // public function getCouplet()
  1159. // }
  1160. /**
  1161. * 订单打印接口
  1162. * order:订单编号
  1163. * 通过订单编号获取订单表数据以及子订单数据
  1164. */
  1165. public function orderPrint(){
  1166. if ($this->request->isGet() === false){$this->error('请求错误');}
  1167. $param = $this->request->param();
  1168. if (empty($param['order'])){$this->error('参数错误');}
  1169. $where['Mod_rq'] = null;
  1170. //订单信息
  1171. $list = \db('工单_基本资料')
  1172. ->where('订单编号',$param['order'])
  1173. ->where($where)
  1174. ->field('订单编号,img,生产款号,客户编号,款式,落货日期,箱唛要求,面料,船样描述,船样合计,粘衬,订单数量,审核,审核日期,要求,water')
  1175. ->find();
  1176. //尺码表格表头
  1177. $xhdata = \db('工单_印件资料')->where('订单编号', $param['order'])->where($where)->select();
  1178. $arr = [];
  1179. foreach ($xhdata as $key => $value) {
  1180. for ($i = 1; $i <= 10; $i++) {
  1181. if ($value['cm' . $i] !== '' && $value['cm' . $i] !== null) {
  1182. array_push($arr, $value['cm' . $i]);
  1183. }
  1184. }
  1185. }
  1186. // 去重并重新索引
  1187. $arr = array_unique($arr);
  1188. $arr = array_values($arr);
  1189. // 自定义排序函数
  1190. usort($arr, function($a, $b) {
  1191. // 判断是否为数字
  1192. $isNumericA = is_numeric($a);
  1193. $isNumericB = is_numeric($b);
  1194. if ($isNumericA && $isNumericB) {
  1195. // 如果都是数字,按从小到大排序
  1196. return $a - $b;
  1197. } elseif (!$isNumericA && !$isNumericB) {
  1198. // 如果都是字母,按字母顺序排序(可以自定义顺序)
  1199. $sizeOrder = ['XXS', 'XS', 'S', 'M', 'L', 'XL', 'XXL', 'XXXL'];
  1200. $posA = array_search($a, $sizeOrder);
  1201. $posB = array_search($b, $sizeOrder);
  1202. return $posA - $posB;
  1203. } else {
  1204. // 如果一个是数字一个是字母,数字排在前
  1205. return $isNumericA ? -1 : 1;
  1206. }
  1207. });
  1208. //打印table数据表格
  1209. $porlis = \db('工单_印件资料')
  1210. ->where('订单编号',$param['order'])
  1211. ->where('船样',0)
  1212. ->where($where)
  1213. ->field('子订单编号')
  1214. ->select();
  1215. //合并后的子订单条码数据
  1216. $subOrder = $porlis[0]['子订单编号'];
  1217. // 找到子订单编号中的 '-' 位置
  1218. $dashPos = strpos($subOrder, '-');
  1219. if ($dashPos !== false) {
  1220. // 提取 '-' 后面的部分
  1221. $afterDash = substr($subOrder, $dashPos + 1);
  1222. // 判断长度是否等于2或等于4
  1223. if (strlen($afterDash) == 2) {
  1224. // 查询船样为0的数据
  1225. $processlist = \db('工单_印件资料')
  1226. ->where('订单编号', $param['order'])
  1227. ->where($where)
  1228. ->where('船样', 0)
  1229. ->field('子订单编号,颜色,款号,zdtotal,颜色备注,color_id,
  1230. cm1,cm2,cm3,cm4,cm5,cm6,cm7,cm8,cm9,cm10,
  1231. cmsl1,cmsl2,cmsl3,cmsl4,cmsl5,cmsl6,cmsl7,cmsl8,cmsl9,cmsl10,Uniqid')
  1232. ->select();
  1233. // 初始化汇总数组
  1234. $scslTotals = [
  1235. "cmsl1" => 0,
  1236. "cmsl2" => 0,
  1237. "cmsl3" => 0,
  1238. "cmsl4" => 0,
  1239. "cmsl5" => 0,
  1240. "cmsl6" => 0,
  1241. "cmsl7" => 0,
  1242. "cmsl8" => 0,
  1243. "cmsl9" => 0,
  1244. "cmsl10" => 0,
  1245. "zdtotal" => 0, // 总计数量
  1246. ];
  1247. // 遍历数据集进行汇总
  1248. foreach ($processlist as $item) {
  1249. // 遍历每个尺码字段(cmsl1 到 cmsl10)
  1250. for ($i = 1; $i <= 10; $i++) {
  1251. // 获取当前字段的数量
  1252. $sizeQty = $item['cmsl' . $i];
  1253. // 判断数量是否有效(非空且大于0)
  1254. if (!empty($sizeQty)) {
  1255. // 累加当前字段的数量
  1256. $scslTotals['cmsl' . $i] += $sizeQty;
  1257. // 累加到总计字段
  1258. $scslTotals['zdtotal'] += $sizeQty;
  1259. }
  1260. }
  1261. }
  1262. $data['scslTotals'] = $scslTotals;
  1263. foreach ($processlist as $key => $value) {
  1264. // 将尺码和对应的数量从 cm1-cm10 和 cmsl1-cmsl10 转换为动态键值对
  1265. for ($i = 1; $i <= 10; $i++) {
  1266. if ($value['cm' . $i] !== '' && $value['cm' . $i] !== null) {
  1267. $processlist[$key][$value['cm' . $i]] = $value['cmsl' . $i];
  1268. }
  1269. // 移除原始的 cm 和 cmsl 字段
  1270. unset($processlist[$key]['cm' . $i], $processlist[$key]['cmsl' . $i]);
  1271. }
  1272. }
  1273. // 用于存储合并后的数据
  1274. $mergedData = [];
  1275. // 按颜色备注进行合并
  1276. foreach ($processlist as $item) {
  1277. $key = $item['颜色备注'];
  1278. if (!isset($mergedData[$key])) {
  1279. $mergedData[$key] = $item;
  1280. // 添加条码字段,值为子订单编号
  1281. $mergedData[$key]['条码'] = $item['子订单编号'];
  1282. } else {
  1283. // 合并尺码对应的数量
  1284. foreach ($item as $size => $quantity) {
  1285. if (is_numeric($size)) {
  1286. if (!isset($mergedData[$key][$size])) {
  1287. $mergedData[$key][$size] = 0;
  1288. }
  1289. $mergedData[$key][$size] += $quantity;
  1290. }
  1291. }
  1292. // 合并 zdtotal
  1293. $mergedData[$key]['zdtotal'] += $item['zdtotal'];
  1294. }
  1295. }
  1296. // 查询船样为1的数据
  1297. $chuanyang = \db('工单_印件资料')
  1298. ->where('订单编号', $param['order'])
  1299. ->where($where)
  1300. ->where('船样', 1)
  1301. ->field('子订单编号,颜色,款号,zdtotal,颜色备注,color_id,
  1302. cm1,cm2,cm3,cm4,cm5,cm6,cm7,cm8,cm9,cm10,
  1303. cmsl1,cmsl2,cmsl3,cmsl4,cmsl5,cmsl6,cmsl7,cmsl8,cmsl9,cmsl10,Uniqid')
  1304. ->select();
  1305. foreach ($chuanyang as $key => $value) {
  1306. // 将尺码和对应的数量从 cm1-cm10 和 cmsl1-cmsl10 转换为动态键值对
  1307. for ($i = 1; $i <= 10; $i++) {
  1308. if ($value['cm' . $i] !== '' && $value['cm' . $i] !== null) {
  1309. $chuanyang[$key][$value['cm' . $i]] = $value['cmsl' . $i];
  1310. }
  1311. // 移除原始的 cm 和 cmsl 字段
  1312. unset($chuanyang[$key]['cm' . $i], $chuanyang[$key]['cmsl' . $i]);
  1313. }
  1314. // 添加条码字段,值为子订单编号
  1315. $chuanyang[$key]['条码'] = $value['子订单编号'];
  1316. }
  1317. // 将合并后的数据插入到相应颜色备注的原始数据尾部
  1318. $finalList = [];
  1319. $groupedData = [];
  1320. // 将原始数据按颜色备注分组
  1321. foreach ($processlist as $item) {
  1322. $key = $item['颜色备注'];
  1323. if (!isset($groupedData[$key])) {
  1324. $groupedData[$key] = [];
  1325. }
  1326. $groupedData[$key][] = $item;
  1327. }
  1328. // 将合并后的数据插入到对应的颜色备注组的尾部
  1329. foreach ($groupedData as $key => $items) {
  1330. $finalList = array_merge($finalList, $items); // 先添加原始数据
  1331. if (isset($mergedData[$key])) {
  1332. $finalList[] = $mergedData[$key]; // 在组的尾部添加合并数据
  1333. }
  1334. }
  1335. // 将船样为1的数据添加到最终列表中
  1336. $finalList = array_merge($finalList, $chuanyang);
  1337. $data['process'] = $finalList;
  1338. $data['order'] = $list;
  1339. $data['xhdata'] = $arr;
  1340. $this->success('成功',$data);
  1341. } elseif (strlen($afterDash) == 4) {
  1342. //一条子订单编号一个条码,统计颜色
  1343. // $processlist = \db('工单_印件资料')
  1344. // ->where('订单编号', $param['order'])
  1345. // ->whereNull('Mod_rq') // 查询未删除数据
  1346. // ->select();
  1347. //
  1348. // $table = [];
  1349. // foreach ($processlist as $item) {
  1350. // // 当前子订单编号的数据
  1351. // $subOrder = [
  1352. // '颜色备注' => $item['颜色备注'],
  1353. // '色系名称' => $item['颜色'],
  1354. // '订单编号' => $item['订单编号'],
  1355. // '子订单编号' => $item['子订单编号'],
  1356. // '条码' => $item['子订单编号'],
  1357. // '款号' => $item['款号'],
  1358. // ];
  1359. // // 当前子订单编号的合计
  1360. // $subOrderTotal = 0;
  1361. // for ($i = 1; $i <= 10; $i++) {
  1362. // if (!empty($item['cm' . $i])) {
  1363. // $subOrder[$item['cm' . $i]] = $item['cmsl' . $i];
  1364. // // 累加每个尺码的数量
  1365. // $subOrderTotal += $item['cmsl' . $i];
  1366. // }
  1367. // unset($item['cm' . $i], $item['cmsl' . $i]);
  1368. // }
  1369. // $subOrder['合计'] = $subOrderTotal; // 添加合计
  1370. // $table[] = $subOrder; // 将当前子订单的数据添加到 $table 中
  1371. // }
  1372. $processlist = \db('工单_印件资料')
  1373. ->where('订单编号', $param['order'])
  1374. ->whereNull('Mod_rq') // 查询未删除数据
  1375. ->select();
  1376. $table = [];
  1377. foreach ($processlist as $item) {
  1378. // 当前子订单编号的数据
  1379. $subOrder = [
  1380. '颜色备注' => $item['颜色备注'],
  1381. '色系名称' => $item['颜色'],
  1382. '订单编号' => $item['订单编号'],
  1383. '子订单编号' => $item['子订单编号'],
  1384. '条码' => $item['子订单编号'],
  1385. '款号' => $item['款号'],
  1386. ];
  1387. // 当前子订单编号的合计
  1388. $subOrderTotal = 0;
  1389. for ($i = 1; $i <= 10; $i++) {
  1390. // 判断 cm 和 cmsl 是否有值,空值不显示,0 则显示
  1391. if (isset($item['cm' . $i]) && $item['cm' . $i] !== '') {
  1392. $subOrder[$item['cm' . $i]] = $item['cmsl' . $i] ?? 0; // 默认数量为 0
  1393. // 累加每个尺码的数量
  1394. $subOrderTotal += (int)$item['cmsl' . $i]; // 确保是数值类型
  1395. }
  1396. // 清理字段
  1397. unset($item['cm' . $i], $item['cmsl' . $i]);
  1398. }
  1399. $subOrder['合计'] = $subOrderTotal; // 添加合计
  1400. $table[] = $subOrder; // 将当前子订单的数据添加到 $table 中
  1401. }
  1402. // 初始化汇总数组
  1403. $scslTotals = [
  1404. "cmsl1" => 0,
  1405. "cmsl2" => 0,
  1406. "cmsl3" => 0,
  1407. "cmsl4" => 0,
  1408. "cmsl5" => 0,
  1409. "cmsl6" => 0,
  1410. "cmsl7" => 0,
  1411. "cmsl8" => 0,
  1412. "cmsl9" => 0,
  1413. "cmsl10" => 0,
  1414. "zdtotal" => 0, // 总计数量
  1415. ];
  1416. // 遍历数据集进行汇总
  1417. foreach ($processlist as $item) {
  1418. // 遍历每个尺码字段(cmsl1 到 cmsl10)
  1419. for ($i = 1; $i <= 10; $i++) {
  1420. // 获取当前字段的数量
  1421. $sizeQty = $item['cmsl' . $i];
  1422. // 判断数量是否有效(非空且大于0)
  1423. if (!empty($sizeQty)) {
  1424. // 累加当前字段的数量
  1425. $scslTotals['cmsl' . $i] += $sizeQty;
  1426. // 累加到总计字段
  1427. $scslTotals['zdtotal'] += $sizeQty;
  1428. }
  1429. }
  1430. }
  1431. $data['scslTotals'] = $scslTotals;
  1432. $data['process'] = $table;//汇总数据集
  1433. $data['order'] = $list;//表格数据
  1434. $data['xhdata'] = $arr;//尺码表头
  1435. $this->success('成功', $data);
  1436. // }
  1437. } else {
  1438. echo "子订单编号 - 后不是2位也不是4位:$afterDash";
  1439. }
  1440. } else {
  1441. echo "子订单编号中没有找到'-'";
  1442. }
  1443. }
  1444. /**
  1445. * 订单编号自动获取
  1446. * @return void
  1447. * @throws \think\db\exception\DataNotFoundException
  1448. * @throws \think\db\exception\ModelNotFoundException
  1449. * @throws \think\exception\DbException
  1450. */
  1451. public function getWorkOrder()
  1452. {
  1453. if ($this->request->isGet() === false){
  1454. $this->error('请求错误');
  1455. }
  1456. $time =substr( date('Ym',time()),2);
  1457. $lastOrder = \db('工单_基本资料')
  1458. ->where('订单编号','like','%'.$time.'%')
  1459. ->order('Uniqid desc')
  1460. ->find();
  1461. if (empty($lastOrder)){
  1462. $newNumber = 1;
  1463. }else{
  1464. $lastNumber = substr($lastOrder['订单编号'],6);
  1465. $newNumber = (int)$lastNumber + 1;
  1466. }
  1467. if ($newNumber<10){
  1468. $newOrder = 'DC'.$time.'00'.$newNumber;
  1469. }elseif ($newNumber>=10 && $newNumber<100){
  1470. $newOrder = 'DC'.$time.'0'.$newNumber;
  1471. }else{
  1472. $newOrder = 'DC'.$time.$newNumber;
  1473. }
  1474. $this->success('成功',$newOrder);
  1475. }
  1476. /**
  1477. * 获取子订单编号
  1478. * @return void
  1479. * @throws \think\db\exception\DataNotFoundException
  1480. * @throws \think\db\exception\ModelNotFoundException
  1481. * @throws \think\exception\DbException
  1482. */
  1483. public function getSuborder(){
  1484. // 确保是GET请求
  1485. if ($this->request->isGet() === false) {
  1486. $this->error('请求错误');
  1487. }
  1488. $param = $this->request->param();
  1489. if (empty($param) || !isset($param['cy']) || !isset($param['order'])) {
  1490. $this->error('参数错误');
  1491. }
  1492. // 判断是否“船样”获取对应的子订单编号
  1493. if ($param['cy'] == '否') {
  1494. //1.通过色系名称查询对应的编号
  1495. $colorlist = \db('工单_颜色编号')
  1496. ->field('colorcode, colorname')
  1497. ->where('colorname', $param['colorname'] ?? '')
  1498. ->find();
  1499. if (empty($colorlist)) {
  1500. $this->error('未找到对应的颜色编号');
  1501. }
  1502. $num = $param['order'] . '-' . $colorlist['colorcode'];
  1503. // 查询子订单编号
  1504. $data = \db('工单_印件资料')
  1505. ->field('子订单编号,cm1,cm2,cm3,cm4,cm5,cm6,cm7,cm8,cm9,cm10')
  1506. ->where('子订单编号', 'like', '%' . $num . '%')
  1507. ->where('船样', '=', 0)
  1508. ->order('子订单编号', 'desc')
  1509. ->find();
  1510. if (empty($data)) {
  1511. // 如果没有找到数据,生成默认的订单编号,后两位从00开始
  1512. $order = $param['order'] . '-' . $colorlist['colorcode'] . '00';
  1513. } else {
  1514. if (strlen($data['子订单编号']) == 12) {
  1515. $data = \db('工单_印件资料')
  1516. ->where('订单编号',$param['order'])
  1517. ->where('船样',0)
  1518. ->order('子订单编号 desc')
  1519. ->find();
  1520. if(empty($data)){
  1521. $order = $param['order'].'-01';
  1522. }else{
  1523. $num = (int)substr($data['子订单编号'],10) + 1;
  1524. if ($num<10){
  1525. $order = $param['order'].'-0'.$num;
  1526. }else{
  1527. $order = $param['order'].'-'.$num;
  1528. }
  1529. }
  1530. }else{
  1531. // 如果找到数据,提取子订单编号并递增
  1532. $order = $data['子订单编号'];
  1533. if (preg_match('/(.*-' . $colorlist['colorcode'] . ')(\d{2})$/', $order, $matches)) {
  1534. $prefix = $matches[1]; // 前缀部分(包括订单编号和颜色代码)
  1535. $number = $matches[2]; // 数字部分(后两位)
  1536. // 循环生成子订单编号并检查数据库中是否存在相同编号
  1537. do {
  1538. $incrementedNumber = (int)$number + 1;
  1539. // 将数字部分补充为两位数,例如 1 -> 01,2 -> 02
  1540. $order = $prefix . str_pad($incrementedNumber, 2, '0', STR_PAD_LEFT);
  1541. $exists = \db('工单_印件资料')->where('子订单编号', '=', $order)->find();
  1542. $number = $incrementedNumber; // 更新 number 用于下一次循环
  1543. } while ($exists); // 如果存在相同编号则继续循环递增
  1544. } else {
  1545. $this->error('订单编号格式错误');
  1546. }
  1547. }
  1548. }
  1549. //2.获取色系名称信息
  1550. $colorlist = \db('工单_颜色编号')->select();
  1551. //3.获取历史尺码数据
  1552. $cm_list = \db('工单_印件资料')
  1553. ->where('订单编号', $param['order'])
  1554. ->group('订单编号')
  1555. ->find();
  1556. $cm_data = [];
  1557. if ($cm_list) {
  1558. // 精准筛选字段名以 "cm" 开头并跟1到2位数字的字段
  1559. foreach ($cm_list as $key => $value) {
  1560. if (preg_match('/^cm\d{1,2}$/', $key)) {
  1561. $cm_data[$key] = $value ?? ''; // 如果值为 null,设为空字符串
  1562. }
  1563. }
  1564. } else {
  1565. // 如果查询结果为空,将 cm1 到 cm10 都设置为空
  1566. for ($i = 1; $i <= 10; $i++) {
  1567. $cm_data["cm$i"] = '';
  1568. }
  1569. }
  1570. $result = ['order' => $order,'colorlist' => $colorlist,'cm' => $cm_data];
  1571. $this->success('成功', $result);
  1572. } else if ($param['cy'] == '是') {
  1573. //1.获取船样子订单编号
  1574. $data = \db('工单_印件资料')
  1575. ->where('订单编号', $param['order'])
  1576. ->where('船样', '=', 1)
  1577. ->order('子订单编号 asc')
  1578. ->find();
  1579. if (empty($data)) {
  1580. // 如果没有数据,初始子订单编号为 '99'
  1581. $order = $param['order'] . '-99';
  1582. } else {
  1583. // 提取子订单编号中的数字部分
  1584. $subOrder = $data['子订单编号']; // 例如 "DC2410006-99"
  1585. if (preg_match('/-(\d+)$/', $subOrder, $matches)) {
  1586. $numberPart = (int)$matches[1]; // 提取到的数字部分
  1587. $newNumber = $numberPart - 1; // 减 1
  1588. // 将新的数字拼接回订单编号
  1589. $order = preg_replace('/-\d+$/', '-' . $newNumber, $subOrder);
  1590. } else {
  1591. $this->error('订单编号格式错误');
  1592. }
  1593. }
  1594. $this->success('成功', $order);
  1595. }
  1596. }
  1597. /**
  1598. * 获取PO号 【代码展示未用到】
  1599. */
  1600. public function getPonumber() {
  1601. if ($this->request->isGet() === false){
  1602. $this->error('请求错误');
  1603. }
  1604. $param = $this->request->param();
  1605. if (empty($param)){
  1606. $this->error('参数错误');
  1607. }
  1608. // $num = substr($param['child_order'], 0, 12); // 如果需要,可以用这个方式截取子订单编号
  1609. // $sql = "SELECT * FROM `工单_印件资料` WHERE `子订单编号` LIKE '{$num}%' ORDER BY `子订单编号` DESC LIMIT 1";
  1610. // $data = \db()->query($sql);
  1611. $colorlist = \db('工单_颜色编号')
  1612. ->field('colorcode,colorname')
  1613. ->where('colorname',$param['child_order'])
  1614. ->find();
  1615. $num = $param['order'] . '-' . $colorlist['colorcode']; // 生成 num,用于模糊查询
  1616. $data = \db('工单_印件资料')
  1617. ->where('子订单编号', 'like', '%' . $num . '%')
  1618. ->order('子订单编号', 'desc')
  1619. ->find();
  1620. if(count($data) === 1){
  1621. $order = $num.'01';
  1622. }else{
  1623. $number = (int)substr($data['子订单编号'],12,14) + 1;
  1624. if ($num<10){
  1625. $order = $num.'0'.$number;
  1626. }else{
  1627. $order = $num.$number;
  1628. }
  1629. }
  1630. $this->success('成功',$order);
  1631. }
  1632. /**
  1633. * 订单资料修改
  1634. * @return void
  1635. * @throws \think\Exception
  1636. * @throws \think\db\exception\BindParamException
  1637. * @throws \think\exception\PDOException
  1638. */
  1639. public function WorkOrderEdit()
  1640. {
  1641. if (Request::instance()->isPost() === false){
  1642. $this->error('请求错误');
  1643. }
  1644. $param = Request::instance()->post();
  1645. if (empty($param)){
  1646. $this->error('参数错误');
  1647. }
  1648. $id = $param['id'];
  1649. unset($param['id']);
  1650. $sql = \db('工单_基本资料')
  1651. ->where('Uniqid',$id)
  1652. ->fetchSql(true)
  1653. ->update($param);
  1654. $res = \db()->query($sql);
  1655. if ($res === false){
  1656. $this->error('失败');
  1657. }else{
  1658. $this->success('成功');
  1659. }
  1660. }
  1661. /**
  1662. * 颜色资料修改
  1663. * @return void
  1664. * @throws \think\Exception
  1665. * @throws \think\db\exception\BindParamException
  1666. * @throws \think\exception\PDOException
  1667. */
  1668. public function PrintDataEdit()
  1669. {
  1670. if(Request::instance()->post() === false){
  1671. $this->error('请求错误');
  1672. }
  1673. $param = Request::instance()->post();
  1674. if (empty($param)){
  1675. $this->error('参数错误');
  1676. }
  1677. // $id = $param['id'];
  1678. // unset($param['id']);
  1679. // $findlist = \db('工单_印件资料')
  1680. // ->where('Uniqid', $param['id'])
  1681. // ->find();
  1682. $updata = [
  1683. '订单编号' => $param['订单编号'],
  1684. '子订单编号' => $param['子订单编号'],
  1685. '款号' => $param['款号'],
  1686. '船样' => $param['船样'],
  1687. '颜色' => $param['颜色'],
  1688. 'color_id' => $param['color_id'],
  1689. '颜色备注' => $param['颜色备注'],
  1690. 'zdtotal' => $param['zdtotal']
  1691. ];
  1692. for ($i = 1; $i <= 10; $i++) {
  1693. $updata["cmsl{$i}"] = isset($param["cmsl{$i}"]) ? $param["cmsl{$i}"] : '';
  1694. }
  1695. $sql = \db('工单_印件资料')
  1696. ->where('Uniqid', $param['id'])
  1697. ->fetchSql(true)
  1698. ->update($updata);
  1699. $res = \db()->query($sql);
  1700. if ($res !== false) {
  1701. $this->success('修改成功');
  1702. } else {
  1703. $this->error('修改失败');
  1704. }
  1705. }
  1706. /**
  1707. * 图片上传
  1708. * @return void
  1709. */
  1710. public function ImgUpload(){
  1711. $file = request()->file('image');
  1712. if($file){
  1713. $info = $file->validate(['size'=>10485760,'ext'=>'jpg,png'])->move(ROOT_PATH . 'public' . DS . 'uploads');
  1714. if($info){
  1715. $fileName = $info->getSaveName();
  1716. // $ymd = date('Ymd');
  1717. // $imageUrl = '/uploads/' . $ymd.'/'.$fileName;
  1718. $imageUrl = '/uploads/' . str_replace('\\', '/', $fileName);
  1719. return json(['code' => 0, 'msg' => '成功', 'data' => ['url' => $imageUrl]]);
  1720. }else{
  1721. $res = $file->getError();
  1722. return json(['code' => 1, 'msg' => '失败', 'data' => $res]);
  1723. }
  1724. }
  1725. return json(['code' => 1, 'msg' => '没有文件上传', 'data' => null]);
  1726. }
  1727. /**
  1728. * 工单技术附件
  1729. * @return void
  1730. * @throws \think\db\exception\DataNotFoundException
  1731. * @throws \think\db\exception\ModelNotFoundException
  1732. * @throws \think\exception\DbException
  1733. */
  1734. public function OrderAttachments()
  1735. {
  1736. if ($this->request->isGet() === false){
  1737. $this->error('请求错误');
  1738. }
  1739. $param = $this->request->param();
  1740. if (empty($param)){
  1741. $this->error('参数错误');
  1742. }
  1743. $list = \db('工单_相关附件')
  1744. ->where('关联编号',$param['order'])
  1745. ->where('附件备注',$param['desc'])
  1746. ->whereNull('Mod_rq')
  1747. ->order('sys_rq desc')
  1748. ->limit(1)
  1749. ->select();
  1750. $this->success('成功',$list);
  1751. }
  1752. }