WorkOrder.php 90 KB

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