WorkOrder.php 103 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742
  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. if (!$this->request->isPost()) {
  1305. $this->error('请求方式错误');
  1306. }
  1307. // 获取请求参数
  1308. $req = $this->request->param();
  1309. $relateId = $req['关联编号'];
  1310. $attachmentContent = $req['附件内容'];
  1311. $uploadDir = 'uploads/' . date('Ymd') . '/' . $relateId;
  1312. // 检查并创建目录
  1313. if (!is_dir($uploadDir)) {
  1314. mkdir($uploadDir, 0777, true);
  1315. }
  1316. // 处理 Base64 附件内容
  1317. if (strpos($attachmentContent, 'base64,') !== false) {
  1318. $attachmentContent = explode('base64,', $attachmentContent)[1];
  1319. }
  1320. $fileContent = base64_decode($attachmentContent);
  1321. // 创建并写入 Excel 文件
  1322. $xlsxFilePath = $uploadDir . '/' . time() . '.xlsx';
  1323. file_put_contents($xlsxFilePath, $fileContent);
  1324. // 加载 Excel 文件
  1325. $spreadsheet = IOFactory::load($xlsxFilePath);
  1326. $pdfPaths = '';
  1327. // 转换每个工作表到 PDF
  1328. foreach ($spreadsheet->getAllSheets() as $index => $sheet) {
  1329. // 为每个工作表创建单独的 PDF 文件
  1330. $pdfSpreadsheet = new Spreadsheet();
  1331. $pdfSpreadsheet->addExternalSheet($sheet);
  1332. // 设置 PDF 写入器
  1333. $pdfWriter = new Tcpdf($pdfSpreadsheet);
  1334. $pdfOutputPath = $uploadDir . '/' . time() . ($index + 1) . '.pdf';
  1335. // 保存 PDF 文件
  1336. $pdfWriter->save($pdfOutputPath);
  1337. $pdfPaths .= $pdfOutputPath . ','; // 将 PDF 文件路径添加到 pdfPaths
  1338. }
  1339. // 组织数据
  1340. $data = [
  1341. '关联编号' => $relateId,
  1342. 'sys_id' => $req['sys_id'],
  1343. '附件备注' => $req['附件备注'],
  1344. '附件类型' => $req['附件类型'],
  1345. 'sys_rq' => date('Y-m-d H:i:s'),
  1346. 'url' => $xlsxFilePath, // 保存xlsx文件路径
  1347. 'pdf' => rtrim($pdfPaths, ',') // 保存pdf文件路径
  1348. ];
  1349. // 数据库事务处理
  1350. db()->startTrans();
  1351. try {
  1352. // 插入数据
  1353. $sql = db('工单_相关附件')->fetchSql(true)->insert($data);
  1354. $result = db()->query($sql);
  1355. db()->commit();
  1356. } catch (\Exception $e) {
  1357. // 回滚事务
  1358. db()->rollback();
  1359. $this->error($e->getMessage());
  1360. }
  1361. if ($result === false) {
  1362. $this->error('失败');
  1363. }
  1364. $this->success('成功');
  1365. }
  1366. // public function gdAnnexAdd(){
  1367. // if(!$this->request->isPost()){
  1368. // $this->error('请求方式错误');
  1369. // }
  1370. // // 获取请求参数
  1371. // $req = $this->request->param();
  1372. //
  1373. // // 检查附件备注是否为 '技术附件'
  1374. // if (isset($req['附件备注']) && $req['附件备注'] === '技术附件') {
  1375. // // 查询工单状态
  1376. // $order = \db('工单_基本资料')->where('订单编号', $req['关联编号'])->find();
  1377. // if ($order) {
  1378. // // 如果工单状态不是 '2-生产中',则更新工单状态
  1379. // if ($order['gd_statu'] !== '2-生产中') {
  1380. // // 更新工单状态为 '2-生产中'
  1381. // \db('工单_基本资料')->where('订单编号', $req['关联编号'])->update(['gd_statu' => '2-生产中']);
  1382. // }
  1383. // } else {
  1384. // // 工单不存在时返回错误信息
  1385. // return $this->error('订单不存在');
  1386. // }
  1387. // }
  1388. // $arr = [
  1389. // 'sys_id',
  1390. // '附件备注',
  1391. // '附件内容',
  1392. // '附件类型',
  1393. // '关联编号'
  1394. // ];
  1395. // $data = [];
  1396. // foreach ($arr as $key => $value){
  1397. // if (!isset($req[$value])){
  1398. // $this->error('参数错误',$value,$key+1);
  1399. // }
  1400. // $data[$value] = $req[$value];
  1401. // }
  1402. // $data['sys_rq'] = date('Y-m-d H:i:s');
  1403. // //检测目录是否存在
  1404. // if(is_dir(ROOT_PATH.'public/uploads/'.$req['关联编号']) == null)
  1405. // {
  1406. // mkdir(ROOT_PATH.'public/uploads/'.$req['关联编号'],0777,true);
  1407. // }
  1408. // $base64Data = $req['附件内容'];
  1409. // if (strpos($base64Data, 'base64,') !== false) {
  1410. // $base64Data = explode('base64,', $base64Data)[1]; // 去掉前缀
  1411. // }
  1412. // // 解码 Base64 数据
  1413. // $tempFileContent = base64_decode($base64Data);
  1414. //
  1415. // // 创建一个临时文件
  1416. // $tempFile = tempnam(sys_get_temp_dir(), 'excel_') . '.xlsx';
  1417. //
  1418. // // 将解码后的内容写入临时文件
  1419. // file_put_contents($tempFile, $tempFileContent);
  1420. //
  1421. // // 加载 Excel 文件
  1422. // $spreadsheet =IOFactory::load($tempFile);
  1423. // //储存pdf地址
  1424. // $address = '';
  1425. // // 遍历每个工作表
  1426. // foreach ($spreadsheet->getAllSheets() as $index => $sheet) {
  1427. // // 创建新 Spreadsheet 对象,仅包含当前工作表
  1428. // $pdfSpreadsheet = new Spreadsheet();
  1429. // $pdfSpreadsheet->addExternalSheet($sheet);
  1430. //
  1431. // // 设置 PDF 写入器
  1432. // $pdfWriter = new Tcpdf($pdfSpreadsheet);
  1433. //
  1434. // // 生成 PDF 文件名
  1435. // $pdfFileName = 'output_sheet_' . ($index + 1) . '.pdf';
  1436. //
  1437. // //设置保存地址
  1438. // $pdfOutputPath = ROOT_PATH.'public/uploads/'.$req['关联编号'] . $pdfFileName;
  1439. // // 保存到服务器指定目录
  1440. // $pdfWriter->save($pdfOutputPath);
  1441. // // 编辑pdf地址
  1442. // $address = $pdfOutputPath.',' . $address;
  1443. // }
  1444. // // 清理临时文件
  1445. // unlink($tempFile);;
  1446. // //开启事务
  1447. // db()->startTrans();
  1448. // try{
  1449. // $sql = db('工单_相关附件')->fetchSql(true)->insert($data);
  1450. // $bool = db()->query($sql);
  1451. // // 提交事务
  1452. // db()->commit();
  1453. // } catch (\Exception $e) {
  1454. // // 回滚事务
  1455. // db()->rollback();
  1456. // $this->error($e->getMessage());
  1457. // }
  1458. //
  1459. // if($bool===false) $this->error('失败');
  1460. //
  1461. // $this->success('成功');
  1462. // }
  1463. /**
  1464. * 产品附件修改
  1465. * @ApiMethod (GET)
  1466. * @param string 'UniqId'
  1467. */
  1468. // public function gdAnnexDel()
  1469. // {
  1470. // if(!$this->request->isGet()){
  1471. // $this->error('请求方式错误');
  1472. // }
  1473. // $req = $this->request->param();
  1474. //
  1475. // if (!(isset($req['UniqId']) && trim($req['UniqId'])!='')){
  1476. // $this->error('参数错误','UniqId',100);
  1477. // }
  1478. //
  1479. // //开启事务
  1480. // db()->startTrans();
  1481. // try{
  1482. // $bool = db('工单_相关附件')->where('UniqId',$req['UniqId'])->delete();
  1483. // // 提交事务
  1484. // db()->commit();
  1485. // } catch (\Exception $e) {
  1486. // // 回滚事务
  1487. // db()->rollback();
  1488. // $this->error($e->getMessage());
  1489. // }
  1490. //
  1491. // if($bool===false) $this->error('失败');
  1492. //
  1493. // $this->success('成功');
  1494. //
  1495. // }
  1496. /**
  1497. * 引用工单资料数据查询
  1498. * @return void
  1499. * @throws \think\db\exception\DataNotFoundException
  1500. * @throws \think\db\exception\ModelNotFoundException
  1501. * @throws \think\exception\DbException
  1502. */
  1503. // public function WorkOrderDetailCope()
  1504. // {
  1505. // if ($this->request->isGet() === false){
  1506. // $this->error('请求错误');
  1507. // }
  1508. // $param = $this->request->param();
  1509. // if (empty($param['search'])){
  1510. // $this->error('参数错误');
  1511. // }
  1512. // $list = \Db('工单_基本资料')
  1513. // ->alias('a')
  1514. // ->field([
  1515. // 'rtrim(a.Gd_gdbh)' => '工单编号',
  1516. // 'rtrim(b.客户编号)' => '客户编号',
  1517. // 'rtrim(b.客户名称)' => '客户名称',
  1518. // 'rtrim(b.产品编号)' => '产品编号',
  1519. // 'rtrim(b.产品名称)' => '产品名称'
  1520. // ])
  1521. // ->join('产品_基本资料 b', 'a.成品代号 = b.产品编号')
  1522. // ->join('产品_工艺资料 c', 'a.成品代号 = c.Gy0_cpdh')
  1523. // ->join('产品_印件资料 d', 'a.成品代号 = d.yj_cpdh')
  1524. // ->where(function($query) use ($param) {
  1525. // $query->where('a.Gd_gdbh', 'like', '%'.$param['search'].'%')
  1526. // ->whereOr('a.成品名称', 'like', '%'.$param['search'].'%');
  1527. // })
  1528. // ->where(function($query) {
  1529. // $query->where('c.Gy0_cpdh', '<>', '')
  1530. // ->where('d.yj_cpdh', '<>', '')
  1531. // ->where('b.状态', 'not like', '%停用%')
  1532. // ->where('b.产品名称', 'not like', '%停用%');
  1533. // })
  1534. // ->group('a.Gd_gdbh')
  1535. // ->order('a.Uniqid desc')
  1536. // ->select();
  1537. // if (empty($list)){
  1538. // $this->success('未找到工单资料');
  1539. // }else{
  1540. // $this->success('成功',$list);
  1541. // }
  1542. // }
  1543. //
  1544. /**
  1545. * 引用产品印件、工艺资料
  1546. * @return void
  1547. * @throws \think\db\exception\BindParamException
  1548. * @throws \think\db\exception\DataNotFoundException
  1549. * @throws \think\db\exception\ModelNotFoundException
  1550. * @throws \think\exception\DbException
  1551. * @throws \think\exception\PDOException
  1552. */
  1553. // public function WorkOrderDetailListCope()
  1554. // {
  1555. // if (Request::instance()->isPost() === false){
  1556. // $this->error('请求错误');
  1557. // }
  1558. //
  1559. // $param = Request::instance()->post();
  1560. // if (empty($param['workorder']) || empty($param['productCode']) || empty($param['option'])){
  1561. // $this->error('参数错误');
  1562. // }
  1563. // if (isset($param['sort'])){
  1564. // $priWhere['yj_yjno'] = ['>=',10];
  1565. // $proWhere['Gy0_yjno'] = ['>=',10];
  1566. // }else{
  1567. // $priWhere['yj_yjno'] = ['<',10];
  1568. // $proWhere['Gy0_yjno'] = ['<',10];
  1569. // }
  1570. // $list = \db('工单_基本资料')
  1571. // ->where('Gd_gdbh',$param['workorder'])
  1572. //// ->where('成品代号',$param['productCode'])
  1573. // ->field('行号,Gd_cpdh')
  1574. // ->select();
  1575. // //引用印件资料
  1576. // $PrintList = \db('产品_印件资料')
  1577. // ->where('yj_cpdh',$param['productCode'])
  1578. // ->where($priWhere)
  1579. // ->select();
  1580. // if (empty($PrintList)){
  1581. // $this->error('未找到印件资料');
  1582. // }
  1583. // $PrintLastId = \db('工单_印件资料')->order('Uniqid desc')->value('rtrim(Uniqid)');
  1584. // $number = \db('工单_基本资料')
  1585. // ->where('Gd_gdbh',$param['workorder'])
  1586. // ->where('成品代号',$param['productCode'])
  1587. // ->value('rtrim(计划投料)');
  1588. // $arr = [];
  1589. // foreach ($PrintList as $key => $value){
  1590. // foreach ($list as $k=>$v){
  1591. // if ($value['yj_yjdh'] === $v['Gd_cpdh']){
  1592. // $PrintList[$key]['Yj_Gdbh'] = $param['workorder'];
  1593. // $PrintList[$key]['yj_Yjno'] = $value['yj_yjno'];
  1594. // $PrintList[$key]['yj_Yjdh'] = $value['yj_yjdh'];
  1595. // $PrintList[$key]['yj_ks'] = $value['yj_ks'];
  1596. // $PrintList[$key]['yj_ls'] = $value['yj_ls'];
  1597. // $PrintList[$key]['yj_平张投料'] = $number;
  1598. // $PrintList[$key]['Sys_id'] = $value['sys_id'];
  1599. // $PrintList[$key]['Uniqid'] = $PrintLastId + $key + 1;
  1600. // $PrintList[$key]['Sys_rq'] = date('Y-m-d H:i:s',time());
  1601. // $PrintList[$key]['Mod_rq'] = date('Y-m-d H:i:s',time());
  1602. // array_push($arr,[$value['yj_yjno'],$v['行号']]);
  1603. // }
  1604. // $sql = \db('工单_基本资料')
  1605. // ->where('Gd_gdbh',$param['workorder'])
  1606. // ->where('Gd_cpdh',$value['yj_yjdh'])
  1607. // ->fetchSql(true)
  1608. // ->update(['行号'=>$value['yj_yjno']]);
  1609. // \db()->query($sql);
  1610. // }
  1611. // 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']);
  1612. // }
  1613. // //引用工艺资料
  1614. // $processWhere = [
  1615. // 'Gy0_方案' => $param['option'],
  1616. // 'Gy0_cpdh' => $param['productCode']
  1617. // ];
  1618. // $ProcessList = \db('产品_工艺资料')
  1619. // ->where($processWhere)
  1620. // ->where($proWhere)
  1621. // ->order('Gy0_yjno,Gy0_gxh')
  1622. // ->select();
  1623. // if (empty($ProcessList)){
  1624. // $this->error('未找到产品工艺资料');
  1625. // }
  1626. // $ProcesslastId = \db('工单_工艺资料')->order('UniqId desc')->value('rtrim(UniqId)');
  1627. // foreach ($ProcessList as $key=>$value){
  1628. // if (empty(trim($value['Gy0_shdh']))){
  1629. // $rate['rate0'] = 0;
  1630. // $rate['rate1'] = 0;
  1631. // }else{
  1632. // $rate = \db('dic_lzsh')->where('sys_bh',$value['Gy0_shdh'])->field('rtrim(sys_rate0) as rate0,rtrim(sys_rate1) as rate1')->find();
  1633. // if (empty($rate)){
  1634. // $this->error('该产品印件号'.$value['Gy0_yjno'].'工序号为'.$value['gy0_gxmc'].'的损耗代号错误,请调整之后再引用');
  1635. // }
  1636. // }
  1637. // //设置默认机台
  1638. // $machineList = \db('设备_基本资料')
  1639. // ->where('生产工序','like','%'.$value['gy0_gxmc'].'%')
  1640. // ->order('设备编号')
  1641. // ->value('设备编号');
  1642. // $ProcessList[$key]['Gy0_sbbh'] = '';
  1643. // if (!empty($machineList)){
  1644. // $ProcessList[$key]['Gy0_sbbh'] = $machineList;
  1645. // }
  1646. // $ProcessList[$key]['Gy0_yjno'] = $value['Gy0_yjno'];
  1647. // $ProcessList[$key]['Gy0_gdbh'] = $param['workorder'];
  1648. // $ProcessList[$key]['Gy0_gxmc'] = $value['gy0_gxmc'];
  1649. // $ProcessList[$key]['Gy0_SITE'] = $value['Gy0_site'];
  1650. // $ProcessList[$key]['Gy0_shdh'] = $value['Gy0_shdh'];
  1651. // $ProcessList[$key]['Gy0_Rate0'] = $rate['rate0'];
  1652. // $ProcessList[$key]['Gy0_Rate1'] = $rate['rate1'];
  1653. // $ProcessList[$key]['Gy0_ks'] = $value['Gy0_Ks'];
  1654. // $ProcessList[$key]['Gy0_ms'] = $value['Gy0_Ms'];
  1655. // $ProcessList[$key]['Gy0_oil'] = $value['Gy0_Oil'];
  1656. // $ProcessList[$key]['Gy0_计划接货数'] = 0;
  1657. // $ProcessList[$key]['Gy0_计划损耗'] = 0;
  1658. // $ProcessList[$key]['无形损承担比例'] = 0;
  1659. // $ProcessList[$key]['超节损承担比例'] = 1;
  1660. // $ProcessList[$key]['超节损核算单价'] = 0;
  1661. // $ProcessList[$key]['Gy0_sj1'] = '1900-01-01 00:00:00';
  1662. // $ProcessList[$key]['Gy0_sj2'] = '1900-01-01 00:00:00';
  1663. // $ProcessList[$key]['UniqId'] = $ProcesslastId + $key + 1;
  1664. // $ProcessList[$key]['PD_WG'] = '1900-01-01 00:00:00';
  1665. // $ProcessList[$key]['Sys_rq'] = date('Y-m-d H:i:s', time());
  1666. // 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']);
  1667. // }
  1668. // //插入数据
  1669. // \db()->startTrans();
  1670. // try {
  1671. // \db('工单_工艺资料')->where('Gy0_gdbh',$param['workorder'])->delete();
  1672. // $processSql = \db('工单_工艺资料')->fetchSql(true)->insertAll($ProcessList);
  1673. // \db()->query($processSql);
  1674. // \db('工单_印件资料')->where('Yj_Gdbh',$param['workorder'])->delete();
  1675. // $printSql = \db('工单_印件资料')->fetchSql(true)->insertAll($PrintList);
  1676. // \db()->query($printSql);
  1677. // \db()->commit();
  1678. // }catch (\Exception $e){
  1679. // \db()->rollback();
  1680. // }
  1681. // //计算工序计划生产数量
  1682. // if ($number !== null){
  1683. // $list = \db('工单_印件资料')->where('Yj_Gdbh',$param['workorder'])->field('yj_Yjno,yj_平张投料')->select();
  1684. // foreach ($list as $value){
  1685. // if ((int)$value['yj_平张投料'] >0){
  1686. // $this->PlannedProcessYield($param['workorder'],$value['yj_Yjno'],0,$value['yj_平张投料']);
  1687. // }
  1688. // }
  1689. // }
  1690. // $this->success('成功');
  1691. // }
  1692. /**
  1693. * 引用产品印件、工艺资料->信息获取
  1694. * @return void
  1695. * @throws \think\db\exception\DataNotFoundException
  1696. * @throws \think\db\exception\ModelNotFoundException
  1697. * @throws \think\exception\DbException
  1698. */
  1699. // public function ProductCopeDetail()
  1700. // {
  1701. // if ($this->request->isGet() === false){
  1702. // $this->error('请求错误');
  1703. // }
  1704. // $param = $this->request->param();
  1705. // if (empty($param['workorder'])){
  1706. // $this->error('参数错误');
  1707. // }
  1708. // $list = \db('工单_基本资料')
  1709. // ->alias('a')
  1710. // ->field([
  1711. // 'rtrim(a.Gd_gdbh)' => '工单编号',
  1712. // 'rtrim(b.客户编号)' => '客户编号',
  1713. // 'rtrim(b.客户名称)' => '客户名称',
  1714. // 'rtrim(b.产品编号)' => '产品编号',
  1715. // 'rtrim(b.产品名称)' => '产品名称'
  1716. // ])
  1717. // ->join('产品_基本资料 b','a.成品代号 = b.产品编号')
  1718. // ->where('a.Gd_gdbh',$param['workorder'])
  1719. // ->find();
  1720. // if (empty($list)){
  1721. // $this->error('未找到工单信息');
  1722. // }
  1723. // $option = \db('产品_工艺资料')
  1724. // ->field('rtrim(Gy0_方案) as 方案')
  1725. // ->where('Gy0_cpdh',$list['产品编号'])
  1726. // ->group('Gy0_方案')
  1727. // ->select();
  1728. // $list['方案'] = $option;
  1729. // $this->success('成功',$list);
  1730. // }
  1731. /**
  1732. * 工艺资料计划产量重新分配
  1733. * @param string $workOrder 工单
  1734. * @param int $yjno 印件号
  1735. * @param int $gxh 工序号
  1736. * @param int $feed 平张投料
  1737. * @return bool
  1738. * @throws \think\Exception
  1739. * @throws \think\db\exception\BindParamException
  1740. * @throws \think\db\exception\DataNotFoundException
  1741. * @throws \think\db\exception\ModelNotFoundException
  1742. * @throws \think\exception\DbException
  1743. * @throws \think\exception\PDOException
  1744. */
  1745. // public function PlannedProcessYield($workOrder,$yjno,$gxh,$feed)
  1746. // {
  1747. // if ($gxh === 0){
  1748. // $where = [
  1749. // 'Gy0_gdbh'=>$workOrder,
  1750. // 'Gy0_yjno'=>$yjno,
  1751. // ];
  1752. // }else{
  1753. // $where = [
  1754. // 'Gy0_gdbh'=>$workOrder,
  1755. // 'Gy0_yjno'=>$yjno,
  1756. // 'Gy0_gxh'=>['>=',$gxh]
  1757. // ];
  1758. // }
  1759. // //获取工艺资料
  1760. // $processList = \db('工单_工艺资料')
  1761. // ->where($where)
  1762. // ->field('Gy0_Rate0 as 损耗定额,Gy0_Rate1 as 损耗率,rtrim(损耗系数) as 损耗系数,Gy0_ms,Gy0_ls,UniqId')
  1763. // ->order('Gy0_gxh')
  1764. // ->select();
  1765. // if (empty($processList)){
  1766. // $this->success('未找到该工单工序资料');
  1767. // }
  1768. // //计算损耗定额和计划产量
  1769. // $production = [];
  1770. // $i = 0;
  1771. // foreach ($processList as $key=>$value){
  1772. // if ($key === 0){
  1773. // array_push($production,$feed);
  1774. // }
  1775. // $wastage = 0;
  1776. // if ($value['损耗率'] !== 0 && !empty($value['损耗率'])){
  1777. // $wastage = ($production[$key]*$value['损耗率']+$value['损耗定额'])*$value['损耗系数'];
  1778. // }
  1779. //
  1780. // if ($value['Gy0_ms'] >0 && !empty($value['Gy0_ms'])){
  1781. // $wastage = round($wastage * $value['Gy0_ms']);
  1782. // }
  1783. // if ((int)$value['Gy0_ls'] === 1 && $key>=1){
  1784. // $number = $production[$key]*$processList[$key-1]['Gy0_ls'];
  1785. // }else{
  1786. // $number = $production[$key];
  1787. // }
  1788. // if ($key>=1 && (int)$processList[$key-1]['Gy0_ls'] === 1 && (int)$value['Gy0_ls'] > 1){
  1789. // $number = $number/(int)$value['Gy0_ls'];
  1790. // }
  1791. // array_push($production,ceil($number-$wastage));
  1792. // $processSql = \db('工单_工艺资料')
  1793. // ->where('UniqId',$value['UniqId'])
  1794. // ->fetchSql(true)
  1795. // ->update(['Gy0_计划接货数'=>$production[$key],'Gy0_计划损耗'=>$wastage]);
  1796. // $res = \db()->query($processSql);
  1797. // if ($res === false){
  1798. // $i++;
  1799. // }
  1800. // }
  1801. // if ($i===0){
  1802. // return true;
  1803. // }else{
  1804. // return false;
  1805. // }
  1806. // }
  1807. /**
  1808. * 工单资料删除
  1809. * @return void
  1810. * @throws \think\exception\PDOException
  1811. */
  1812. // public function WorkOrderDel()
  1813. // {
  1814. // if ($this->request->isGet() === false){
  1815. // $this->error('请求错误');
  1816. // }
  1817. // $param = $this->request->param();
  1818. // if (isset($param['UniqId']) === false){
  1819. // $this->error('参数错误');
  1820. // }
  1821. // $WorkOrderId = explode(',',$param['UniqId']);
  1822. // $i = 0;
  1823. // foreach ($WorkOrderId as $key=>$value){
  1824. // //获取工单编号
  1825. // $workorder = \db('工单_基本资料')
  1826. // ->where('Uniqid',$value)
  1827. // ->value('rtrim(Gd_gdbh)');
  1828. // //删除工单资料、工艺资料、印件资料
  1829. // \db()->startTrans();
  1830. // try {
  1831. // \db('工单_基本资料')->where('Gd_gdbh',$workorder)->delete();
  1832. // if (!empty(\db('工单_工艺资料')->where('Gy0_gdbh',$workorder)->find())){
  1833. // \db('工单_工艺资料')->where('Gy0_gdbh',$workorder)->delete();
  1834. // }
  1835. // if (!empty(\db('工单_印件资料')->where('Yj_Gdbh',$workorder)->find())){
  1836. // \db('工单_印件资料')->where('Yj_Gdbh',$workorder)->delete();
  1837. // }
  1838. // if (!empty(\db('工单_bom资料')->where('BOM_工单编号',$workorder)->find())){
  1839. // \db('工单_bom资料')->where('BOM_工单编号',$workorder)->delete();
  1840. // }
  1841. // \db()->commit();
  1842. // }catch (\Exception $e){
  1843. // \db()->rollback();
  1844. // $i++;
  1845. // }
  1846. // }
  1847. // if ($i === 0){
  1848. // $this->success('删除成功');
  1849. // }else{
  1850. // $this->error('删除失败');
  1851. // }
  1852. // }
  1853. /**
  1854. * 修正核算参数-》工单产品信息获取
  1855. * @return void
  1856. * @throws \think\db\exception\DataNotFoundException
  1857. * @throws \think\db\exception\ModelNotFoundException
  1858. * @throws \think\exception\DbException
  1859. */
  1860. // public function ProductNameData()
  1861. // {
  1862. // if ($this->request->isGet() === false){
  1863. // $this->error('请求错误');
  1864. // }
  1865. // $workOrder = input('workOrder');
  1866. // if (empty($workOrder)){
  1867. // $this->error('参数错误');
  1868. // }
  1869. // $orderList = \db('工单_基本资料')
  1870. // ->field('rtrim(Gd_cpdh) as 印件代号,rtrim(Gd_cpmc) as 印件名称,rtrim(成品代号) as 产品代号,rtrim(成品名称) as 产品名称')
  1871. // ->where('Gd_gdbh',$workOrder)
  1872. // ->find();
  1873. // $this->success('成功',$orderList);
  1874. // }
  1875. /**
  1876. * 获取联数
  1877. * @return void
  1878. * @throws \think\db\exception\DataNotFoundException
  1879. * @throws \think\db\exception\ModelNotFoundException
  1880. * @throws \think\exception\DbException
  1881. */
  1882. // public function getCouplet()
  1883. // {
  1884. // if ($this->request->isGet() === false){
  1885. // $this->error('请求错误');
  1886. // }
  1887. // $param = $this->request->param();
  1888. // if (empty($param['gdbh']) || empty($param['yjno'])){
  1889. // $this->error('参数错误');
  1890. // }
  1891. // $list = \db('工单_印件资料')
  1892. // ->where('Yj_gdbh',$param['gdbh'])
  1893. // ->where('yj_Yjno',$param['yjno'])
  1894. // ->field('rtrim(yj_ks) as 开数,rtrim(yj_ls) as 联数')
  1895. // ->find();
  1896. // $process = \db('工单_工艺资料')
  1897. // ->where('Gy0_gdbh',$param['gdbh'])
  1898. // ->where('Gy0_yjno',$param['yjno'])
  1899. // ->order('Gy0_gxh desc')
  1900. // ->value('Gy0_gxh');
  1901. // $list['工序号'] = $process + 1;
  1902. // $this->success('成功',$list);
  1903. // }
  1904. /**
  1905. * 订单打印接口
  1906. * order:订单编号
  1907. * 通过订单编号获取订单表数据以及子订单数据
  1908. */
  1909. public function orderPrint(){
  1910. if ($this->request->isGet() === false){$this->error('请求错误');}
  1911. $param = $this->request->param();
  1912. if (empty($param['order'])){$this->error('参数错误');}
  1913. $where['Mod_rq'] = null;
  1914. //订单信息
  1915. $list = \db('工单_基本资料')
  1916. ->where('订单编号',$param['order'])
  1917. ->where($where)
  1918. ->field('订单编号,img,生产款号,客户编号,款式,落货日期,箱唛要求,面料,船样描述,船样合计,粘衬,订单数量,审核,审核日期,要求')
  1919. ->find();
  1920. //尺码表格表头
  1921. $xhdata = \db('工单_印件资料')->where('订单编号',$param['order'])->where($where)->select();
  1922. $arr = [];
  1923. foreach ($xhdata as $key => $value){
  1924. for($i=1;$i<=10;$i++){
  1925. if ($value['cm'.$i] !== '' && $value['cm'.$i] !== null){
  1926. array_push($arr,$value['cm'.$i]);
  1927. }
  1928. }
  1929. }
  1930. $arr = array_unique($arr);
  1931. //打印table数据表格
  1932. $porlis = \db('工单_印件资料')
  1933. ->where('订单编号',$param['order'])
  1934. ->where('船样',0)
  1935. ->where($where)
  1936. ->field('子订单编号')
  1937. ->select();
  1938. $count = count($porlis);
  1939. if($count == 1 || $count == 2 || $count == 3){
  1940. // 查询船样为0的数据
  1941. $processlist = \db('工单_印件资料')
  1942. ->where('订单编号', $param['order'])
  1943. ->where($where)
  1944. ->where('船样', 0)
  1945. ->select();
  1946. foreach ($processlist as $key => $value) {
  1947. // 将尺码和对应的数量从 cm1-cm10 和 cmsl1-cmsl10 转换为动态键值对
  1948. for ($i = 1; $i <= 10; $i++) {
  1949. if ($value['cm' . $i] !== '' && $value['cm' . $i] !== null) {
  1950. $processlist[$key][$value['cm' . $i]] = $value['cmsl' . $i];
  1951. }
  1952. // 移除原始的 cm 和 cmsl 字段
  1953. unset($processlist[$key]['cm' . $i], $processlist[$key]['cmsl' . $i]);
  1954. }
  1955. // 添加条码字段,值为子订单编号
  1956. $processlist[$key]['条码'] = $value['子订单编号'];
  1957. }
  1958. // 查询船样为1的数据
  1959. $chuanyang = \db('工单_印件资料')
  1960. ->where('订单编号', $param['order'])
  1961. ->where($where)
  1962. ->where('船样', 1)
  1963. ->select();
  1964. foreach ($chuanyang as $key => $value) {
  1965. // 将尺码和对应的数量从 cm1-cm10 和 cmsl1-cmsl10 转换为动态键值对
  1966. for ($i = 1; $i <= 10; $i++) {
  1967. if ($value['cm' . $i] !== '' && $value['cm' . $i] !== null) {
  1968. $chuanyang[$key][$value['cm' . $i]] = $value['cmsl' . $i];
  1969. }
  1970. unset($chuanyang[$key]['cm' . $i], $chuanyang[$key]['cmsl' . $i]);
  1971. }
  1972. $chuanyang[$key]['条码'] = $value['子订单编号'];
  1973. }
  1974. $counthz = \db('工单_印件资料')
  1975. ->where('订单编号', $param['order'])
  1976. ->where($where)
  1977. ->select();
  1978. // 初始化累计数组
  1979. $scslTotals = [
  1980. 'cmsl1' => 0,
  1981. 'cmsl2' => 0,
  1982. 'cmsl3' => 0,
  1983. 'cmsl4' => 0,
  1984. 'cmsl5' => 0,
  1985. 'cmsl6' => 0,
  1986. 'cmsl7' => 0,
  1987. 'cmsl8' => 0,
  1988. 'cmsl9' => 0,
  1989. 'cmsl10' => 0,
  1990. 'zdtotal' => 0,
  1991. ];
  1992. // 遍历 $counthz 数组,将每行的 scsl1 到 scsl10 累加
  1993. foreach ($counthz as $item) {
  1994. for ($i = 1; $i <= 10; $i++) {
  1995. $key = "cmsl{$i}";
  1996. if (!empty($item[$key])) { // 检查是否有值
  1997. $scslTotals[$key] += (int)$item[$key];
  1998. $scslTotals['zdtotal'] += (int)$item[$key];
  1999. }
  2000. }
  2001. }
  2002. $data['scslTotals'] = $scslTotals;
  2003. $data['process'] = array_merge($processlist, $chuanyang);
  2004. $data['order'] = $list;
  2005. $data['xhdata'] = $arr;
  2006. $this->success('成功', $data);
  2007. }
  2008. //合并后的子订单条码数据
  2009. $subOrder = $porlis[0]['子订单编号'];
  2010. // 找到子订单编号中的 '-' 位置
  2011. $dashPos = strpos($subOrder, '-');
  2012. if ($dashPos !== false) {
  2013. // 提取 '-' 后面的部分
  2014. $afterDash = substr($subOrder, $dashPos + 1);
  2015. // 判断长度是否等于2或等于4
  2016. if (strlen($afterDash) == 2) {
  2017. // 查询船样为0的数据
  2018. $processlist = \db('工单_印件资料')
  2019. ->where('订单编号', $param['order'])
  2020. ->where($where)
  2021. ->where('船样', 0)
  2022. ->field('子订单编号,颜色,款号,zdtotal,颜色备注,color_id,
  2023. cm1,cm2,cm3,cm4,cm5,cm6,cm7,cm8,cm9,cm10,
  2024. cmsl1,cmsl2,cmsl3,cmsl4,cmsl5,cmsl6,cmsl7,cmsl8,cmsl9,cmsl10,Uniqid')
  2025. ->select();
  2026. foreach ($processlist as $key => $value) {
  2027. // 将尺码和对应的数量从 cm1-cm10 和 cmsl1-cmsl10 转换为动态键值对
  2028. for ($i = 1; $i <= 10; $i++) {
  2029. if ($value['cm' . $i] !== '' && $value['cm' . $i] !== null) {
  2030. $processlist[$key][$value['cm' . $i]] = $value['cmsl' . $i];
  2031. }
  2032. // 移除原始的 cm 和 cmsl 字段
  2033. unset($processlist[$key]['cm' . $i], $processlist[$key]['cmsl' . $i]);
  2034. }
  2035. }
  2036. // 用于存储合并后的数据
  2037. $mergedData = [];
  2038. // 按颜色备注进行合并
  2039. foreach ($processlist as $item) {
  2040. $key = $item['颜色备注'];
  2041. if (!isset($mergedData[$key])) {
  2042. $mergedData[$key] = $item;
  2043. // 添加条码字段,值为子订单编号
  2044. $mergedData[$key]['条码'] = $item['子订单编号'];
  2045. } else {
  2046. // 合并尺码对应的数量
  2047. foreach ($item as $size => $quantity) {
  2048. if (is_numeric($size)) {
  2049. if (!isset($mergedData[$key][$size])) {
  2050. $mergedData[$key][$size] = 0;
  2051. }
  2052. $mergedData[$key][$size] += $quantity;
  2053. }
  2054. }
  2055. // 合并 zdtotal
  2056. $mergedData[$key]['zdtotal'] += $item['zdtotal'];
  2057. }
  2058. }
  2059. // 查询船样为1的数据
  2060. $chuanyang = \db('工单_印件资料')
  2061. ->where('订单编号', $param['order'])
  2062. ->where($where)
  2063. ->where('船样', 1)
  2064. ->field('子订单编号,颜色,款号,zdtotal,颜色备注,color_id,
  2065. cm1,cm2,cm3,cm4,cm5,cm6,cm7,cm8,cm9,cm10,
  2066. cmsl1,cmsl2,cmsl3,cmsl4,cmsl5,cmsl6,cmsl7,cmsl8,cmsl9,cmsl10,Uniqid')
  2067. ->select();
  2068. foreach ($chuanyang as $key => $value) {
  2069. // 将尺码和对应的数量从 cm1-cm10 和 cmsl1-cmsl10 转换为动态键值对
  2070. for ($i = 1; $i <= 10; $i++) {
  2071. if ($value['cm' . $i] !== '' && $value['cm' . $i] !== null) {
  2072. $chuanyang[$key][$value['cm' . $i]] = $value['cmsl' . $i];
  2073. }
  2074. // 移除原始的 cm 和 cmsl 字段
  2075. unset($chuanyang[$key]['cm' . $i], $chuanyang[$key]['cmsl' . $i]);
  2076. }
  2077. // 添加条码字段,值为子订单编号
  2078. $chuanyang[$key]['条码'] = $value['子订单编号'];
  2079. }
  2080. // 将合并后的数据插入到相应颜色备注的原始数据尾部
  2081. $finalList = [];
  2082. $groupedData = [];
  2083. // 将原始数据按颜色备注分组
  2084. foreach ($processlist as $item) {
  2085. $key = $item['颜色备注'];
  2086. if (!isset($groupedData[$key])) {
  2087. $groupedData[$key] = [];
  2088. }
  2089. $groupedData[$key][] = $item;
  2090. }
  2091. // 将合并后的数据插入到对应的颜色备注组的尾部
  2092. foreach ($groupedData as $key => $items) {
  2093. $finalList = array_merge($finalList, $items); // 先添加原始数据
  2094. if (isset($mergedData[$key])) {
  2095. $finalList[] = $mergedData[$key]; // 在组的尾部添加合并数据
  2096. }
  2097. }
  2098. // 将船样为1的数据添加到最终列表中
  2099. $finalList = array_merge($finalList, $chuanyang);
  2100. $data['process'] = $finalList;
  2101. $data['order'] = $list;
  2102. $data['xhdata'] = $arr;
  2103. $this->success('成功',$data);
  2104. } elseif (strlen($afterDash) == 4) {
  2105. // 获取印件资料
  2106. $processlist = \db('工单_印件资料')
  2107. ->where('订单编号', $param['order'])
  2108. ->where($where)
  2109. ->where('船样', 0)
  2110. ->field('子订单编号, 颜色, 款号, zdtotal, 颜色备注, color_id, 船样,
  2111. cm1, cm2, cm3, cm4, cm5, cm6, cm7, cm8, cm9, cm10,
  2112. cmsl1, cmsl2, cmsl3, cmsl4, cmsl5, cmsl6, cmsl7, cmsl8, cmsl9, cmsl10, Uniqid')
  2113. ->select();
  2114. // 保存格式化后的数据
  2115. $formattedData = [];
  2116. // 遍历数据进行尺码转换并添加到输出数组
  2117. foreach ($processlist as $item) {
  2118. for ($i = 1; $i <= 10; $i++) {
  2119. if (!empty($item['cm' . $i])) {
  2120. $item[$item['cm' . $i]] = $item['cmsl' . $i];
  2121. }
  2122. unset($item['cm' . $i], $item['cmsl' . $i]);
  2123. }
  2124. $formattedData[] = $item;
  2125. }
  2126. // 用于存储每个 color_id 和颜色备注的合并数据
  2127. $mergedData = [];
  2128. // 进行合并
  2129. foreach ($formattedData as $item) {
  2130. $key = $item['color_id'] . '|' . $item['颜色备注'];
  2131. if (!isset($mergedData[$key])) {
  2132. $mergedData[$key] = $item;
  2133. $mergedData[$key]['条码'] = $item['子订单编号']; // 初始化条码
  2134. } else {
  2135. // 合并 zdtotal 和尺码数量
  2136. $mergedData[$key]['zdtotal'] += $item['zdtotal'];
  2137. // 动态获取尺码字段,合并尺码数量
  2138. foreach ($item as $field => $value) {
  2139. // 只处理字段名为数字的尺码字段
  2140. if (is_numeric($field)) {
  2141. $mergedData[$key][$field] = ($mergedData[$key][$field] ?? 0) + $value;
  2142. }
  2143. }
  2144. // 优先选择以 "00" 结尾的条码
  2145. if (substr($item['子订单编号'], -2) == '00') {
  2146. $mergedData[$key]['条码'] = $item['子订单编号'];
  2147. }
  2148. }
  2149. }
  2150. // 将合并后的数据添加到原始数据的末尾,并排序
  2151. $finalOutput = $formattedData;
  2152. // 按 color_id 和 颜色备注 分组,并在每组末尾添加合并后的条码数据
  2153. foreach ($mergedData as $key => $mergeItem) {
  2154. $mergeItem['合并标记'] = true; // 用于标记这是合并后的数据
  2155. $finalOutput[] = $mergeItem;
  2156. }
  2157. // 对最终数组进行排序
  2158. usort($finalOutput, function($a, $b) {
  2159. // 先按 color_id 排序
  2160. $compare = strcmp($a['color_id'], $b['color_id']);
  2161. if ($compare === 0) {
  2162. // 在 color_id 相同的情况下,再按 颜色备注 排序
  2163. $compare = strcmp($a['颜色备注'], $b['颜色备注']);
  2164. if ($compare === 0) {
  2165. // 在 颜色备注相同的情况下,按 子订单编号 排序
  2166. // 如果一项是合并标记的条码数据,另一项不是,则合并标记的条码数据排在后面
  2167. if (isset($a['合并标记']) && !isset($b['合并标记'])) {
  2168. return 1;
  2169. } elseif (!isset($a['合并标记']) && isset($b['合并标记'])) {
  2170. return -1;
  2171. }
  2172. return strcmp($a['子订单编号'], $b['子订单编号']);
  2173. }
  2174. return $compare;
  2175. }
  2176. return $compare;
  2177. });
  2178. // 查询仅获取船样为 1 的数据
  2179. $chuanyang = \db('工单_印件资料')
  2180. ->where('订单编号', $param['order'])
  2181. ->where($where)
  2182. ->where('船样', 1)
  2183. ->field('子订单编号, 颜色, 款号, zdtotal, 颜色备注, color_id, 船样,
  2184. cm1, cm2, cm3, cm4, cm5, cm6, cm7, cm8, cm9, cm10,
  2185. cmsl1, cmsl2, cmsl3, cmsl4, cmsl5, cmsl6, cmsl7, cmsl8, cmsl9, cmsl10, Uniqid')
  2186. ->select();
  2187. $chuanyangvval = [];
  2188. // 遍历船样为 1 的数据,进行尺码转换
  2189. foreach ($chuanyang as $item) {
  2190. for ($i = 1; $i <= 10; $i++) {
  2191. if (!empty($item['cm' . $i])) {
  2192. $item[$item['cm' . $i]] = $item['cmsl' . $i];
  2193. }
  2194. unset($item['cm' . $i], $item['cmsl' . $i]);
  2195. }
  2196. $item['条码'] = $item['子订单编号'];
  2197. $chuanyangvval[] = $item;
  2198. }
  2199. // 合并船样和非船样的数据并去重
  2200. $final = array_map("unserialize", array_unique(array_map("serialize", array_merge($finalOutput, $chuanyangvval))));
  2201. $data['process'] = $final;
  2202. // 最后清除带有条码的数据中的子订单编号和颜色信息
  2203. foreach ($final as &$item) {
  2204. if (isset($item['条码']) && $item['船样'] == 0) {
  2205. $item['子订单编号'] = '';
  2206. $item['颜色'] = '';
  2207. $item['款号'] = '';
  2208. unset($item['子订单编号'], $item['颜色']);
  2209. }
  2210. }
  2211. $counthz = \db('工单_印件资料')
  2212. ->where('订单编号', $param['order'])
  2213. ->where($where)
  2214. ->select();
  2215. // 初始化累计数组
  2216. $scslTotals = [
  2217. 'cmsl1' => 0,
  2218. 'cmsl2' => 0,
  2219. 'cmsl3' => 0,
  2220. 'cmsl4' => 0,
  2221. 'cmsl5' => 0,
  2222. 'cmsl6' => 0,
  2223. 'cmsl7' => 0,
  2224. 'cmsl8' => 0,
  2225. 'cmsl9' => 0,
  2226. 'cmsl10' => 0,
  2227. 'zdtotal' => 0,
  2228. ];
  2229. // 遍历 $counthz 数组,将每行的 scsl1 到 scsl10 累加
  2230. foreach ($counthz as $item) {
  2231. for ($i = 1; $i <= 10; $i++) {
  2232. $key = "cmsl{$i}";
  2233. if (!empty($item[$key])) { // 检查是否有值
  2234. $scslTotals[$key] += (int)$item[$key];
  2235. $scslTotals['zdtotal'] += (int)$item[$key];
  2236. }
  2237. }
  2238. }
  2239. $data['scslTotals'] = $scslTotals;
  2240. $data['order'] = $list;
  2241. $data['xhdata'] = $arr;
  2242. $this->success('成功', $data);
  2243. } else {
  2244. echo "子订单编号 - 后不是2位也不是4位:$afterDash";
  2245. }
  2246. } else {
  2247. echo "子订单编号中没有找到'-'";
  2248. }
  2249. }
  2250. /**
  2251. * 订单编号自动获取
  2252. * @return void
  2253. * @throws \think\db\exception\DataNotFoundException
  2254. * @throws \think\db\exception\ModelNotFoundException
  2255. * @throws \think\exception\DbException
  2256. */
  2257. public function getWorkOrder()
  2258. {
  2259. if ($this->request->isGet() === false){
  2260. $this->error('请求错误');
  2261. }
  2262. $time =substr( date('Ym',time()),2);
  2263. $lastOrder = \db('工单_基本资料')
  2264. ->where('订单编号','like','%'.$time.'%')
  2265. ->order('Uniqid desc')
  2266. ->find();
  2267. if (empty($lastOrder)){
  2268. $newNumber = 1;
  2269. }else{
  2270. $lastNumber = substr($lastOrder['订单编号'],6);
  2271. $newNumber = (int)$lastNumber + 1;
  2272. }
  2273. if ($newNumber<10){
  2274. $newOrder = 'DC'.$time.'00'.$newNumber;
  2275. }elseif ($newNumber>=10 && $newNumber<100){
  2276. $newOrder = 'DC'.$time.'0'.$newNumber;
  2277. }else{
  2278. $newOrder = 'DC'.$time.$newNumber;
  2279. }
  2280. $this->success('成功',$newOrder);
  2281. }
  2282. /**
  2283. * 获取子订单编号
  2284. * @return void
  2285. * @throws \think\db\exception\DataNotFoundException
  2286. * @throws \think\db\exception\ModelNotFoundException
  2287. * @throws \think\exception\DbException
  2288. */
  2289. public function getSuborder(){
  2290. // 确保是GET请求
  2291. if ($this->request->isGet() === false) {
  2292. $this->error('请求错误');
  2293. }
  2294. $param = $this->request->param();
  2295. if (empty($param) || !isset($param['cy']) || !isset($param['order'])) {
  2296. $this->error('参数错误');
  2297. }
  2298. // 判断是否“船样”获取对应的子订单编号
  2299. if ($param['cy'] == '否') {
  2300. //1.通过色系名称查询对应的编号
  2301. $colorlist = \db('工单_颜色编号')
  2302. ->field('colorcode, colorname')
  2303. ->where('colorname', $param['colorname'] ?? '')
  2304. ->find();
  2305. if (empty($colorlist)) {
  2306. $this->error('未找到对应的颜色编号');
  2307. }
  2308. $num = $param['order'] . '-' . $colorlist['colorcode'];
  2309. // 查询子订单编号
  2310. $data = \db('工单_印件资料')
  2311. ->field('子订单编号,cm1,cm2,cm3,cm4,cm5,cm6,cm7,cm8,cm9,cm10')
  2312. ->where('子订单编号', 'like', '%' . $num . '%')
  2313. ->where('船样', '=', 0)
  2314. ->order('子订单编号', 'desc')
  2315. ->find();
  2316. if (empty($data)) {
  2317. // 如果没有找到数据,生成默认的订单编号,后两位从00开始
  2318. $order = $param['order'] . '-' . $colorlist['colorcode'] . '00';
  2319. } else {
  2320. if (strlen($data['子订单编号']) == 12) {
  2321. $data = \db('工单_印件资料')
  2322. ->where('订单编号',$param['order'])
  2323. ->where('船样',0)
  2324. ->order('子订单编号 desc')
  2325. ->find();
  2326. if(empty($data)){
  2327. $order = $param['order'].'-01';
  2328. }else{
  2329. $num = (int)substr($data['子订单编号'],10) + 1;
  2330. if ($num<10){
  2331. $order = $param['order'].'-0'.$num;
  2332. }else{
  2333. $order = $param['order'].'-'.$num;
  2334. }
  2335. }
  2336. }else{
  2337. // 如果找到数据,提取子订单编号并递增
  2338. $order = $data['子订单编号'];
  2339. if (preg_match('/(.*-' . $colorlist['colorcode'] . ')(\d{2})$/', $order, $matches)) {
  2340. $prefix = $matches[1]; // 前缀部分(包括订单编号和颜色代码)
  2341. $number = $matches[2]; // 数字部分(后两位)
  2342. // 循环生成子订单编号并检查数据库中是否存在相同编号
  2343. do {
  2344. $incrementedNumber = (int)$number + 1;
  2345. // 将数字部分补充为两位数,例如 1 -> 01,2 -> 02
  2346. $order = $prefix . str_pad($incrementedNumber, 2, '0', STR_PAD_LEFT);
  2347. $exists = \db('工单_印件资料')->where('子订单编号', '=', $order)->find();
  2348. $number = $incrementedNumber; // 更新 number 用于下一次循环
  2349. } while ($exists); // 如果存在相同编号则继续循环递增
  2350. } else {
  2351. $this->error('订单编号格式错误');
  2352. }
  2353. }
  2354. }
  2355. //2.获取色系名称信息
  2356. $colorlist = \db('工单_颜色编号')->select();
  2357. //3.获取历史尺码数据
  2358. $cm_list = \db('工单_印件资料')
  2359. ->where('订单编号', $param['order'])
  2360. ->group('订单编号')
  2361. ->find();
  2362. $cm_data = [];
  2363. if ($cm_list) {
  2364. // 精准筛选字段名以 "cm" 开头并跟1到2位数字的字段
  2365. foreach ($cm_list as $key => $value) {
  2366. if (preg_match('/^cm\d{1,2}$/', $key)) {
  2367. $cm_data[$key] = $value ?? ''; // 如果值为 null,设为空字符串
  2368. }
  2369. }
  2370. } else {
  2371. // 如果查询结果为空,将 cm1 到 cm10 都设置为空
  2372. for ($i = 1; $i <= 10; $i++) {
  2373. $cm_data["cm$i"] = '';
  2374. }
  2375. }
  2376. $result = ['order' => $order,'colorlist' => $colorlist,'cm' => $cm_data];
  2377. $this->success('成功', $result);
  2378. } else if ($param['cy'] == '是') {
  2379. //1.获取船样子订单编号
  2380. $data = \db('工单_印件资料')
  2381. ->where('订单编号', $param['order'])
  2382. ->where('船样', '=', 1)
  2383. ->order('子订单编号 asc')
  2384. ->find();
  2385. if (empty($data)) {
  2386. // 如果没有数据,初始子订单编号为 '99'
  2387. $order = $param['order'] . '-99';
  2388. } else {
  2389. // 提取子订单编号中的数字部分
  2390. $subOrder = $data['子订单编号']; // 例如 "DC2410006-99"
  2391. if (preg_match('/-(\d+)$/', $subOrder, $matches)) {
  2392. $numberPart = (int)$matches[1]; // 提取到的数字部分
  2393. $newNumber = $numberPart - 1; // 减 1
  2394. // 将新的数字拼接回订单编号
  2395. $order = preg_replace('/-\d+$/', '-' . $newNumber, $subOrder);
  2396. } else {
  2397. $this->error('订单编号格式错误');
  2398. }
  2399. }
  2400. $this->success('成功', $order);
  2401. }
  2402. }
  2403. /**
  2404. * 获取PO号 【代码展示未用到】
  2405. */
  2406. public function getPonumber() {
  2407. if ($this->request->isGet() === false){
  2408. $this->error('请求错误');
  2409. }
  2410. $param = $this->request->param();
  2411. if (empty($param)){
  2412. $this->error('参数错误');
  2413. }
  2414. // $num = substr($param['child_order'], 0, 12); // 如果需要,可以用这个方式截取子订单编号
  2415. // $sql = "SELECT * FROM `工单_印件资料` WHERE `子订单编号` LIKE '{$num}%' ORDER BY `子订单编号` DESC LIMIT 1";
  2416. // $data = \db()->query($sql);
  2417. $colorlist = \db('工单_颜色编号')
  2418. ->field('colorcode,colorname')
  2419. ->where('colorname',$param['child_order'])
  2420. ->find();
  2421. $num = $param['order'] . '-' . $colorlist['colorcode']; // 生成 num,用于模糊查询
  2422. $data = \db('工单_印件资料')
  2423. ->where('子订单编号', 'like', '%' . $num . '%')
  2424. ->order('子订单编号', 'desc')
  2425. ->find();
  2426. if(count($data) === 1){
  2427. $order = $num.'01';
  2428. }else{
  2429. $number = (int)substr($data['子订单编号'],12,14) + 1;
  2430. if ($num<10){
  2431. $order = $num.'0'.$number;
  2432. }else{
  2433. $order = $num.$number;
  2434. }
  2435. }
  2436. $this->success('成功',$order);
  2437. }
  2438. /**
  2439. * 订单资料修改
  2440. * @return void
  2441. * @throws \think\Exception
  2442. * @throws \think\db\exception\BindParamException
  2443. * @throws \think\exception\PDOException
  2444. */
  2445. public function WorkOrderEdit()
  2446. {
  2447. if (Request::instance()->isPost() === false){
  2448. $this->error('请求错误');
  2449. }
  2450. $param = Request::instance()->post();
  2451. if (empty($param)){
  2452. $this->error('参数错误');
  2453. }
  2454. $id = $param['id'];
  2455. unset($param['id']);
  2456. $sql = \db('工单_基本资料')
  2457. ->where('Uniqid',$id)
  2458. ->fetchSql(true)
  2459. ->update($param);
  2460. $res = \db()->query($sql);
  2461. if ($res === false){
  2462. $this->error('失败');
  2463. }else{
  2464. $this->success('成功');
  2465. }
  2466. }
  2467. /**
  2468. * 颜色资料修改
  2469. * @return void
  2470. * @throws \think\Exception
  2471. * @throws \think\db\exception\BindParamException
  2472. * @throws \think\exception\PDOException
  2473. */
  2474. public function PrintDataEdit()
  2475. {
  2476. if(Request::instance()->post() === false){
  2477. $this->error('请求错误');
  2478. }
  2479. $param = Request::instance()->post();
  2480. if (empty($param)){
  2481. $this->error('参数错误');
  2482. }
  2483. // $id = $param['id'];
  2484. // unset($param['id']);
  2485. // $findlist = \db('工单_印件资料')
  2486. // ->where('Uniqid', $param['id'])
  2487. // ->find();
  2488. $updata = [
  2489. '订单编号' => $param['订单编号'],
  2490. '子订单编号' => $param['子订单编号'],
  2491. '款号' => $param['款号'],
  2492. '船样' => $param['船样'],
  2493. '颜色' => $param['颜色'],
  2494. 'color_id' => $param['color_id'],
  2495. '颜色备注' => $param['颜色备注'],
  2496. 'zdtotal' => $param['zdtotal']
  2497. ];
  2498. for ($i = 1; $i <= 10; $i++) {
  2499. $updata["cmsl{$i}"] = isset($param["cmsl{$i}"]) ? $param["cmsl{$i}"] : '';
  2500. }
  2501. $sql = \db('工单_印件资料')
  2502. ->where('Uniqid', $param['id'])
  2503. ->fetchSql(true)
  2504. ->update($updata);
  2505. $res = \db()->query($sql);
  2506. if ($res !== false) {
  2507. $this->success('修改成功');
  2508. } else {
  2509. $this->error('修改失败');
  2510. }
  2511. }
  2512. /**
  2513. * 图片上传
  2514. * @return void
  2515. */
  2516. public function ImgUpload(){
  2517. $file = request()->file('image');
  2518. if($file){
  2519. $info = $file->validate(['size'=>10485760,'ext'=>'jpg,png'])->move(ROOT_PATH . 'public' . DS . 'uploads');
  2520. if($info){
  2521. $fileName = $info->getSaveName();
  2522. $imageUrl = '/uploads/' . str_replace('\\', '/', $fileName);
  2523. return json(['code' => 0, 'msg' => '成功', 'data' => ['url' => $imageUrl]]);
  2524. }else{
  2525. $res = $file->getError();
  2526. return json(['code' => 1, 'msg' => '失败', 'data' => $res]);
  2527. }
  2528. }
  2529. return json(['code' => 1, 'msg' => '没有文件上传', 'data' => null]);
  2530. }
  2531. /**
  2532. * 工单技术附件
  2533. * @return void
  2534. * @throws \think\db\exception\DataNotFoundException
  2535. * @throws \think\db\exception\ModelNotFoundException
  2536. * @throws \think\exception\DbException
  2537. */
  2538. public function OrderAttachments()
  2539. {
  2540. if ($this->request->isGet() === false){
  2541. $this->error('请求错误');
  2542. }
  2543. $param = $this->request->param();
  2544. if (empty($param)){
  2545. $this->error('参数错误');
  2546. }
  2547. $list = \db('工单_相关附件')
  2548. ->where('关联编号',$param['order'])
  2549. ->where('附件备注',$param['desc'])
  2550. ->whereNull('Mod_rq')
  2551. ->order('sys_rq desc')
  2552. ->limit(1)
  2553. ->select();
  2554. $this->success('成功',$list);
  2555. }
  2556. }