WorkOrder.php 89 KB

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