WorkOrder.php 89 KB

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