WorkOrder.php 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352
  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. ->order('子订单编号 desc')
  2198. ->find();
  2199. if(empty($data)){
  2200. $order = $param['order'].'-01';
  2201. }else{
  2202. $num = (int)substr($data['子订单编号'],10) + 1;
  2203. if ($num<10){
  2204. $order = $param['order'].'-0'.$num;
  2205. }else{
  2206. $order = $param['order'].'-'.$num;
  2207. }
  2208. }
  2209. $this->success('成功',$order);
  2210. }
  2211. /**
  2212. * 订单资料修改
  2213. * @return void
  2214. * @throws \think\Exception
  2215. * @throws \think\db\exception\BindParamException
  2216. * @throws \think\exception\PDOException
  2217. */
  2218. public function WorkOrderEdit()
  2219. {
  2220. if (Request::instance()->isPost() === false){
  2221. $this->error('请求错误');
  2222. }
  2223. $param = Request::instance()->post();
  2224. if (empty($param)){
  2225. $this->error('参数错误');
  2226. }
  2227. $id = $param['id'];
  2228. unset($param['id']);
  2229. $sql = \db('工单_基本资料')
  2230. ->where('Uniqid',$id)
  2231. ->fetchSql(true)
  2232. ->update($param);
  2233. $res = \db()->query($sql);
  2234. if ($res === false){
  2235. $this->error('失败');
  2236. }else{
  2237. $this->success('成功');
  2238. }
  2239. }
  2240. /**
  2241. * 颜色资料修改
  2242. * @return void
  2243. * @throws \think\Exception
  2244. * @throws \think\db\exception\BindParamException
  2245. * @throws \think\exception\PDOException
  2246. */
  2247. public function PrintDataEdit()
  2248. {
  2249. if(Request::instance()->post() === false){
  2250. $this->error('请求错误');
  2251. }
  2252. $param = Request::instance()->post();
  2253. if (empty($param)){
  2254. $this->error('参数错误');
  2255. }
  2256. $id = $param['id'];
  2257. unset($param['id']);
  2258. $sql = \db('工单_印件资料')
  2259. ->where('Uniqid',$id)
  2260. ->fetchSql(true)
  2261. ->update($param);
  2262. $res = \db()->query($sql);
  2263. if ($res === false){
  2264. $this->error('修改失败');
  2265. }else{
  2266. $this->success('修改成功');
  2267. }
  2268. }
  2269. }