Manufacture.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use Monolog\Handler\IFTTTHandler;
  5. use think\Db;
  6. use think\Request;
  7. /**
  8. *
  9. * 生产排单管理
  10. */
  11. class Manufacture extends Api
  12. {
  13. protected $noNeedLogin = ['*'];
  14. protected $noNeedRight = ['*'];
  15. /**
  16. * 计划中工单
  17. * @ApiMethod (GET)
  18. * @return \think\response\Json
  19. * @throws \think\db\exception\DataNotFoundException
  20. * @throws \think\db\exception\ModelNotFoundException
  21. * @throws \think\exception\DbException
  22. */
  23. public function Project()
  24. {
  25. if ($this->request->isGet() === false){
  26. $this->error('请求错误');
  27. }
  28. $param = $this->request->param();
  29. if (empty($param)){
  30. $this->error('参数错误');
  31. }
  32. if ($param['status'] === '计划中'){
  33. $status = '3-计划中';
  34. }else{
  35. $status = '1-已完工';
  36. }
  37. $page = 0;
  38. $limit = 15;
  39. if (isset($param['page'])){
  40. $page = $param['page'];
  41. }
  42. if (isset($param['limit'])){
  43. $limit = $param['limit'];
  44. }
  45. $where = [
  46. 'gd_statu' => $status,
  47. '行号' => '1',
  48. ];
  49. if (isset($param['search'])){
  50. $where['Gd_lx|Gd_gdbh|Gd_客户代号|Gd_客户名称|Gd_khdh|Gd_khmc|Gd_cpdh|Gd_cpmc|成品代号|成品名称|产品版本号'] = ['like','%'.$param['search'].'%'];
  51. }
  52. $field = 'rtrim(Gd_生产分类) as 生产分类,rtrim(Gd_gdbh) as 工单编号,rtrim(Gd_cpdh) as 产品代号,rtrim(Gd_cpmc) as 产品名称,rtrim(成品名称) as 成品名称,
  53. rtrim(接单日期) as 接单日期,rtrim(交货日期) as 交货日期,rtrim(订单数量) as 订单数量,rtrim(计量单位) as 计量单位,rtrim(Gd_khmc) as 客户名称,
  54. rtrim(Gd_客户代号) as 客户编号,rtrim(Gd_desc) as 备注,rtrim(客户料号) as 客户料号,rtrim(Sys_id) as 创建用户,rtrim(Sys_rq) as 创建时间,
  55. rtrim(Mod_rq) as 修改时间,rtrim(Uniqid) as UNIQID,rtrim(投料率) as 投料率,rtrim(销售订单号) as 销售订单号';
  56. $list = \db('工单_基本资料')->where($where)->field($field)->limit(($page-1)*$limit,$limit)->order('Uniqid desc')->select();
  57. $total = \db('工单_基本资料')->where($where)->count();
  58. if (empty($list)){
  59. $this->success('',[]);
  60. }
  61. foreach ($list as $key=>$value){
  62. $list[$key]['订单数量'] = rtrim((float)$value['订单数量']);
  63. $list[$key]['产品名称'] = $value['产品名称'] != '' ? $value['产品名称']:$value['成品名称'];
  64. $number = \db('工单_工艺资料')->where('Gy0_gdbh',$value['工单编号'])->count();
  65. if ($number === 0){
  66. $list[$key]['status'] = 0;
  67. }else{
  68. $list[$key]['status'] = 1;
  69. }
  70. unset($list[$key]['成品名称']);
  71. }
  72. $this->success('成功',['data'=>$list,'total'=>$total]);
  73. }
  74. /**
  75. * 计划中工单->工艺资料
  76. * @ApiMethod (GET)
  77. * @param string $Gd_gdbh 工单编号
  78. * @return \think\response\Json
  79. * @throws \think\db\exception\DataNotFoundException
  80. * @throws \think\db\exception\ModelNotFoundException
  81. * @throws \think\exception\DbException
  82. */
  83. public function projectCraft()
  84. {
  85. if ($this->request->isGet() === false){
  86. $this->error('请求错误');
  87. }
  88. $Gd_gdbh = input('Gd_gdbh');
  89. if (empty($Gd_gdbh)){
  90. $this->error('参数错误');
  91. }
  92. $where = [
  93. 'Gy0_gdbh' => $Gd_gdbh
  94. ];
  95. $filed = 'rtrim(Gy0_gdbh) as 工单编号,rtrim(重点工序) as 重点工序,Gy0_yjno,Gy0_gxh,Gy0_gxmc,Add_gxmc,rtrim(工序备注) as 工序备注,
  96. rtrim(Gy0_sbbh) as 机组,rtrim(Gy0_小时产能) as 小时产能,rtrim(Gy0_生产工时) as 生产工时,rtrim(Gy0_辅助工时) as 辅助工时,
  97. rtrim(印刷方式) as 印刷方式,rtrim(版距) as 版距,rtrim(Sys_id) as 创建用户,rtrim(Sys_rq) as 创建时间,rtrim(Mod_rq) as 修改时间,rtrim(UniqId) as UNIQID';
  98. $list = \db('工单_工艺资料')->where($where)->field($filed)->select();
  99. if (empty($list)){
  100. $this->success('',[]);
  101. }
  102. foreach ($list as $key=>$value){
  103. if ((int)$value['Gy0_yjno'] <10){
  104. $value['Gy0_yjno'] = '0'.rtrim($value['Gy0_yjno']);
  105. }
  106. if ((int)$value['Gy0_gxh'] <10){
  107. $value['Gy0_gxh'] = '0'.rtrim($value['Gy0_gxh']);
  108. }
  109. if (rtrim($value['Add_gxmc']) == ''){
  110. $list[$key]['印件工序及名称'] = $value['Gy0_yjno'].'-'.$value['Gy0_gxh'].'-->'.rtrim($value['Gy0_gxmc']);
  111. }else{
  112. $list[$key]['印件工序及名称'] = $value['Gy0_yjno'].'-'.$value['Gy0_gxh'].'-->'.rtrim($value['Gy0_gxmc']).'【'.rtrim($value['Add_gxmc']).'】';
  113. }
  114. unset($list[$key]['Gy0_gxmc'],$list[$key]['Add_gxmc']);
  115. }
  116. $this->success('成功',$list);
  117. }
  118. /**
  119. * 计划中工单->印件资料
  120. * @ApiMethod (GET)
  121. * @param string $Gd_gdbh 工单编号
  122. * @return \think\response\Json
  123. * @throws \think\db\exception\DataNotFoundException
  124. * @throws \think\db\exception\ModelNotFoundException
  125. * @throws \think\exception\DbException
  126. */
  127. public function projectPrint()
  128. {
  129. if ($this->request->isGet() === false){
  130. $this->error('请求错误');
  131. }
  132. $Gd_gdbh = input('Gd_gdbh');
  133. if (empty($Gd_gdbh)){
  134. $this->error('参数错误');
  135. }
  136. $where = [
  137. 'Yj_Gdbh' => $Gd_gdbh,
  138. ];
  139. $field = 'rtrim(Yj_Gdbh) as 工单编号,rtrim(yj_Yjno) as 印件号,rtrim(yj_Yjdh) as 印件代号,rtrim(yj_yjmc) as 印件名称,
  140. rtrim(yj_zzmc) as 纸张名称,rtrim(yj_tlgg) as 投料规格,rtrim(yj_成品数量) as 成品数量,rtrim(yj_实际投料) as 实际投料,
  141. rtrim(yj_Dw) as 投料单位,rtrim(yj_平张投料) as 平张投料,rtrim(yj_ls) as 联数,rtrim(yj_ks) as 开数,rtrim(Sys_id) as 创建用户,
  142. rtrim(Sys_rq) as 创建时间,rtrim(Mod_rq) as 修改时间,rtrim(Uniqid) as UNIQID';
  143. $list = \db('工单_印件资料')->where($where)->field($field)->select();
  144. if (empty($list)){
  145. $this->success('');
  146. }
  147. foreach ($list as $key=>$value){
  148. $list[$key]['成品数量'] = rtrim((float)$value['成品数量']);
  149. $list[$key]['实际投料'] = rtrim((float)$value['实际投料']);
  150. }
  151. $this->success('成功',$list);
  152. }
  153. /**
  154. * 排程中/制程中工单
  155. */
  156. public function Schedule(){
  157. if ($this->request->isGet() === false){
  158. $this->error('请求错误');
  159. }
  160. $param = $this->request->param();
  161. if (empty($param)){
  162. $this->error('参数错误');
  163. }
  164. $where = '';
  165. if (!empty($param['search'])){
  166. $where = "
  167. a.Gd_gdbh LIKE '%{$param['search']}%'
  168. OR a.`成品名称` LIKE '%{$param['search']}%'
  169. ";
  170. }
  171. if ($param['status'] === '排程中'){
  172. $list = db('工单_基本资料')->alias('a')
  173. ->field([
  174. 'rtrim(a.Gd_gdbh)' => '工单编号',
  175. 'rtrim(a.Gd_cpdh)' => '产品代号',
  176. 'rtrim(a.Gd_cpmc)' => '产品名称',
  177. 'rtrim(a.接单日期)' => '接单日期',
  178. 'rtrim(a.交货日期)' => '交货日期',
  179. 'rtrim(a.订单数量)' => '订单数量',
  180. 'rtrim(a.计量单位)' => '计量单位',
  181. 'rtrim(a.销售订单号)' => '销售订单号',
  182. 'rtrim(a.Gd_客户代号)' => '客户编号',
  183. 'rtrim(a.Gd_客户名称)' => '客户名称',
  184. 'rtrim(a.客户料号)' => '客户料号',
  185. 'rtrim(a.Uniqid)' => 'GDUID',
  186. ])
  187. ->join('工单_工艺资料 b', 'a.Gd_gdbh = b.Gy0_gdbh')
  188. ->join('产品_基本资料 c', 'a.Gd_cpdh = c.产品编号')
  189. ->where([
  190. 'a.gd_statu' => '2-生产中',
  191. 'a.行号' => '1',
  192. 'c.状态' => '',
  193. 'b.PD_WG' => '1900-01-01 00:00:00',
  194. ])
  195. ->where($where)
  196. ->whereNotExists(function ($query) {
  197. $query->table('工单_工艺资料')->alias('b2')
  198. ->where('b2.Gy0_gdbh = a.Gd_gdbh')
  199. ->where('b2.Gy0_sj1 <> "1900-01-01 00:00:00"');
  200. })
  201. ->group('a.Gd_gdbh')
  202. ->select();
  203. }else{
  204. $list = db('工单_基本资料')->alias('a')
  205. ->field([
  206. 'rtrim(a.Gd_gdbh)' => '工单编号',
  207. 'rtrim(a.Gd_cpdh)' => '产品代号',
  208. 'rtrim(a.Gd_cpmc)' => '产品名称',
  209. 'rtrim(a.接单日期)' => '接单日期',
  210. 'rtrim(a.交货日期)' => '交货日期',
  211. 'rtrim(a.订单数量)' => '订单数量',
  212. 'rtrim(a.计量单位)' => '计量单位',
  213. 'rtrim(a.销售订单号)' => '销售订单号',
  214. 'rtrim(a.Gd_客户代号)' => '客户编号',
  215. 'rtrim(a.Gd_客户名称)' => '客户名称',
  216. 'rtrim(a.客户料号)' => '客户料号',
  217. 'rtrim(a.Uniqid)' => 'GDUID',
  218. ])
  219. ->join('工单_工艺资料 b', 'a.Gd_gdbh = b.Gy0_gdbh')
  220. ->join('产品_基本资料 c', 'a.Gd_cpdh = c.产品编号')
  221. ->where([
  222. 'a.gd_statu' => '2-生产中',
  223. 'a.行号' => '1',
  224. 'b.PD_WG' => '1900-01-01 00:00:00',
  225. 'b.Gy0_sj1' => ['<>', '1900-01-01 00:00:00'],
  226. 'c.状态' => '',
  227. ])
  228. ->where($where)
  229. ->group('a.Gd_gdbh')
  230. ->select();
  231. }
  232. if (empty($list)){
  233. $this->success('未找到工单信息');
  234. }
  235. $this->success('成功',$list);
  236. }
  237. /**
  238. * 排程中/制程中工单->工序列表
  239. * @ApiMethod (GET)
  240. * @param string $Gd_gdbh 工单编号
  241. * @return \think\response\Json
  242. * @throws \think\db\exception\DataNotFoundException
  243. * @throws \think\db\exception\ModelNotFoundException
  244. * @throws \think\exception\DbException
  245. */
  246. public function ScheduleProcess()
  247. {
  248. if ($this->request->isGet() === false){
  249. $this->error('请求错误');
  250. }
  251. $Gd_gdbh = input('Gd_gdbh');
  252. if (empty($Gd_gdbh)){
  253. $this->error('参数错误');
  254. }
  255. $sql = "SELECT rtrim(a.Gy0_gdbh) as 工单编号,a.Gy0_yjno,a.Gy0_gxh,a.Gy0_gxmc,a.Add_gxmc,rtrim(a.Gy0_sbbh) as 设备编号,rtrim(a.Gy0_小时产能) as 小时产能,
  256. rtrim(a.工价系数) as 产能系数,rtrim(a.Gy0_生产工时) as 生产工时,rtrim(a.Gy0_辅助工时) as 辅助工时,rtrim(a.Gy0_最早开工时间) as 最早开工时间,
  257. rtrim(a.Gy0_sj1) as 计划开工时间,rtrim(a.Gy0_sj2) as 计划完工时间,rtrim(a.Gy0_班次安排) as 班次安排,rtrim(a.工序备注) as 排单备注,
  258. rtrim(a.PD_WG) as 工序完工,rtrim(a.UniqId) as UniqId,COALESCE(b.cl, 0) AS 产量, c.设备名称,rtrim(d.计划投料) as 工序产量
  259. FROM `工单_工艺资料` AS a
  260. JOIN `设备_基本资料` AS c ON a.Gy0_sbbh = c.设备编号
  261. JOIN `工单_基本资料` As d ON a.Gy0_gdbh = d.Gd_Gdbh
  262. LEFT JOIN (
  263. SELECT sczl_gdbh, sczl_gxh, SUM(sczl_cl) AS cl
  264. FROM `设备_产量计酬`
  265. GROUP BY sczl_gdbh, sczl_gxh
  266. ) AS b ON a.Gy0_gdbh = b.sczl_gdbh AND (a.Gy0_gxh = b.sczl_gxh OR b.sczl_gxh IS NULL)
  267. WHERE a.Gy0_gdbh = '{$Gd_gdbh}' AND a.Gy0_sbbh != ''
  268. GROUP BY a.Gy0_gxh";
  269. $list = Db::query($sql);
  270. if (empty($list)){
  271. $this->success('未找到工序');
  272. }
  273. foreach ($list as $key=>$value){
  274. if ((int)$value['Gy0_yjno'] <10){
  275. $value['Gy0_yjno'] = '0'.rtrim($value['Gy0_yjno']);
  276. }
  277. if ((int)$value['Gy0_gxh'] <10){
  278. $value['Gy0_gxh'] = '0'.rtrim($value['Gy0_gxh']);
  279. }
  280. if (rtrim($value['Add_gxmc']) == ''){
  281. $list[$key]['印件工序及名称'] = $value['Gy0_yjno'].'-'.$value['Gy0_gxh'].'-->'.rtrim($value['Gy0_gxmc']);
  282. }else{
  283. $list[$key]['印件工序及名称'] = $value['Gy0_yjno'].'-'.$value['Gy0_gxh'].'-->'.rtrim($value['Gy0_gxmc']).'【'.rtrim($value['Add_gxmc']).'】';
  284. }
  285. unset($list[$key]['Gy0_gxmc'],$list[$key]['Add_gxmc']);
  286. $list[$key]['机组'] = $value['设备编号'];
  287. $list[$key]['剩余产量'] = (int)$list[$key]['工序产量']-(int)$list[$key]['产量'];
  288. }
  289. $this->success('成功',$list);
  290. }
  291. /**
  292. * 排单页面左侧车间和机台菜单
  293. * @ApiMethod (GET)
  294. * @return \think\response\Json
  295. * @throws \think\db\exception\DataNotFoundException
  296. * @throws \think\db\exception\ModelNotFoundException
  297. * @throws \think\exception\DbException
  298. */
  299. public function workbench()
  300. {
  301. if ($this->request->isGet() === false){
  302. $this->error('请求错误');
  303. }
  304. $data = [];
  305. $department = \db('设备_基本资料')
  306. ->distinct(true)
  307. ->where('使用部门','<>','研发中心')
  308. ->where('设备编组','<>','')
  309. ->order('设备编组')
  310. ->column('使用部门');
  311. if (empty($department)){
  312. $this->success('为获取到机台数据');
  313. }
  314. foreach ($department as $value){
  315. $benchClass = \db('设备_基本资料')->where('使用部门',$value)->distinct(true)->order('设备编组')->cache(true)->column('设备编组');
  316. foreach ($benchClass as $v){
  317. if (rtrim($v) !== ''){
  318. $machine = \db('设备_基本资料')->where('使用部门',$value)->where('设备编组',$v)->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->cache(true)->select();
  319. foreach ($machine as $kk=>$vv){
  320. $data[rtrim($value)][rtrim($v)][$kk] = $vv['设备编号'].'-->'.$vv['设备名称'];
  321. }
  322. }
  323. }
  324. }
  325. $this->success('成功',$data);
  326. }
  327. /**
  328. * 工单状态设置
  329. * @ApiMethod (GET)
  330. * @param string $workOrder 工单编号
  331. * @param string $status 工单状态
  332. * @return void
  333. * @throws \think\Exception
  334. * @throws \think\exception\PDOException
  335. */
  336. public function StatusEdit()
  337. {
  338. if (Request::instance()->isPost() === false){
  339. $this->error('请求错误');
  340. }
  341. $workOrder = input('workOrder');
  342. $status = input('status');
  343. if (empty($workOrder) || empty($status)){
  344. $this->error('参数错误');
  345. }
  346. $sql = \db('工单_基本资料')->where('Gd_gdbh',$workOrder)->fetchSql(true)->update(['gd_statu'=>$status]);
  347. $res = Db::query($sql);
  348. if ($res !== false){
  349. $this->success('成功');
  350. }else{
  351. $this->error('失败');
  352. }
  353. }
  354. /**
  355. * 更改工序状态
  356. * @ApiMethod (GET)
  357. * @param void
  358. * @return void
  359. * @throws \think\Exception
  360. * @throws \think\exception\PDOException
  361. */
  362. public function complete()
  363. {
  364. if ($this->request->isGet() === false){
  365. $this->error('请求错误');
  366. }
  367. $data = $this->request->param();
  368. if (empty($data)){
  369. $this->error('参数错误');
  370. }
  371. $where = [
  372. 'Gy0_gdbh' => $data['workOrder'],
  373. 'Gy0_gxh' => $data['processCode']
  374. ];
  375. $sql = \db('工单_工艺资料')->where($where)->fetchSql(true)->update(['PD_WG'=>date('Y-m-d H:i:s',time())]);
  376. $res = Db::query($sql);
  377. if ($res !== false){
  378. $this->success('成功');
  379. }else{
  380. $this->error('失败');
  381. }
  382. }
  383. /**
  384. * 加入排产
  385. * @ApiMethod (POST)
  386. * @param void $data
  387. * @return void
  388. * @throws \think\Exception
  389. * @throws \think\db\exception\DataNotFoundException
  390. * @throws \think\db\exception\ModelNotFoundException
  391. * @throws \think\exception\DbException
  392. * @throws \think\exception\PDOException
  393. */
  394. public function ProductionSchedulingAdd()
  395. {
  396. if (Request::instance()->isPost() === false){
  397. $this->error('请求错误');
  398. }
  399. $data = Request::instance()->post();
  400. if (empty($data)){
  401. $this->error('参数错误');
  402. }
  403. $where = [
  404. 'Gy0_gdbh' => $data['workOrder'],
  405. 'Gy0_sbbh' => ['like','%'.$data['machine'].'%'],
  406. 'Gy0_yjno' => $data['printCode'],
  407. 'Gy0_gxh' => $data['processCode']
  408. ];
  409. $result = \db('工单_工艺资料')->where($where)->field('rtrim(Gy0_sj1) as sj1')->find();
  410. if ($result['sj1'] != '1900-01-01 00:00:00'){
  411. $this->error('该工单已经是制程中');
  412. }
  413. $lastTime = \db('工单_工艺资料')
  414. ->where(['Gy0_sbbh'=>$where['Gy0_sbbh'],'Gy0_sj2'=>['<>','1900-01-01 00:00:00'],'Gy0_sj2'=>['<','2099-01-01 00:00:00']])
  415. ->field('rtrim(Gy0_sj2) as sj2')
  416. ->order('Gy0_sj2 desc')
  417. ->find();
  418. $date = date('Y-m-d H:i:s',time());
  419. if ($lastTime['sj2'] < $date){
  420. $newTime = $date;
  421. }else{
  422. $newTime = $lastTime['sj2'];
  423. }
  424. $row = \db('工单_工艺资料')
  425. ->where($where)
  426. ->field('rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_小时产能) as 小时产能,rtrim(Gy0_辅助工时) as 辅助工时')
  427. ->find();
  428. if (empty($row)){
  429. $this->success('未找到该工单工艺资料');
  430. }
  431. $endTime = date('Y-m-d H:i:s',strtotime($newTime) + ((int)round($row['计划接货数']/$row['小时产能'])+(int)$row['辅助工时'])*3600);
  432. $sql = \db('工单_工艺资料')
  433. ->where($where)
  434. ->fetchSql(true)
  435. ->update(['Gy0_sj1'=>$newTime,'Gy0_sj2'=>$endTime,'Mod_rq'=>date('Y-m-d H:i:s',time())]);
  436. $res = Db::query($sql);
  437. if ($res !== false){
  438. $this->success('成功');
  439. }else{
  440. $this->error('失败');
  441. }
  442. }
  443. /**
  444. * 暂停排产
  445. * @ApiMethod (POST)
  446. * @param void $data
  447. * @return void
  448. * @throws \think\Exception
  449. * @throws \think\db\exception\DataNotFoundException
  450. * @throws \think\db\exception\ModelNotFoundException
  451. * @throws \think\exception\DbException
  452. * @throws \think\exception\PDOException
  453. */
  454. public function ProductionSchedulingPause()
  455. {
  456. if (Request::instance()->isPost() === false){
  457. $this->error('请求错误');
  458. }
  459. $data = Request::instance()->post();
  460. if (empty($data)){
  461. $this->error('参数错误');
  462. }
  463. $where = [
  464. 'Gy0_gdbh' => $data['workOrder'],
  465. 'Gy0_sbbh' => ['like','%'.$data['machine'].'%'],
  466. 'Gy0_yjno' => $data['printCode'],
  467. 'Gy0_gxh' => $data['processCode']
  468. ];
  469. $machine = $data['machine'];
  470. $endTime = \db('工单_工艺资料')->where($where)->field('rtrim(Gy0_sj2) as sj2,rtrim(PD_WG) as wg')->find();
  471. if (empty($endTime)){
  472. $this->success('未找到该工序');
  473. }
  474. $time = $endTime['sj2'];
  475. if ($endTime['sj2'] == '1900-01-01 00:00:00' || $endTime['wg'] != '1900-01-01 00:00:00'){
  476. $this->error('该工单不是制程中工单');
  477. }
  478. $sql = \db('工单_工艺资料')
  479. ->where($where)
  480. ->fetchSql(true)
  481. ->update(['Gy0_sj1'=>'1900-01-01 00:00:00','Gy0_sj2'=>'1900-01-01 00:00:00','Mod_rq'=>date('Y-m-d H:i:s')]);
  482. $row = \db('工单_工艺资料')
  483. ->where($where)
  484. ->field('rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_小时产能) as 小时产能,rtrim(Gy0_辅助工时) as 辅助工时')
  485. ->find();
  486. if (empty($row)){
  487. $this->success('未找到该工序');
  488. }
  489. $number = -(int)round($row['计划接货数']/$row['小时产能'])+(int)$row['辅助工时'];
  490. $rechSql = "UPDATE `工单_工艺资料` SET Gy0_sj1 = DATE_ADD(Gy0_sj1, INTERVAL {$number} HOUR),Gy0_sj2 = DATE_ADD(Gy0_sj2, INTERVAL {$number} HOUR) WHERE Gy0_sbbh LIKE '%{$machine}%' AND Gy0_sj1 >= '{$time}' AND Gy0_sj1 < '2099-01-01 00:00:00'";
  491. $rechres = Db::query($rechSql);
  492. $res = Db::query($sql);
  493. if ($res !== false && $rechres !== false){
  494. $this->success('成功');
  495. }else{
  496. $this->error('失败');
  497. }
  498. }
  499. /**
  500. * 工序状态更正
  501. * @ApiMethod (GET)
  502. * @param void $param
  503. * @return void
  504. * @throws \think\db\exception\DataNotFoundException
  505. * @throws \think\db\exception\ModelNotFoundException
  506. * @throws \think\exception\DbException
  507. */
  508. public function ProcessStatusCorrection()
  509. {
  510. if ($this->request->isGet() === false){
  511. $this->error('请求错误');
  512. }
  513. $param = $this->request->param();
  514. if (empty($param)){
  515. $this->error('参数错误');
  516. }
  517. $where = [
  518. 'Gy0_gdbh' => $param['workOrder'],
  519. 'Gy0_sbbh' => ['<>','']
  520. ];
  521. $workOrder = $where['Gy0_gdbh'];
  522. $field = 'rtrim(Gy0_yjno) as yjno,rtrim(Gy0_gxh) as gxh,rtrim(Gy0_gxmc) as gxmc,rtrim(Gy0_sbbh) as 设备代号,rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_ls) as ls,rtrim(PD_WG) as 完工时间,rtrim(UniqId) as UniqId';
  523. $list = \db('工单_工艺资料')->where($where)->field($field)->order('Gy0_gxh')->select();
  524. if (empty($list)){
  525. $this->success('未找到该工单工艺资料');
  526. }
  527. $yieldSql = "SELECT a.Gy0_gxh as gxh,SUM(b.sczl_cl) as cl FROM `工单_工艺资料` AS a JOIN `设备_产量计酬` as b ON a.Gy0_gxh = b.sczl_gxh WHERE a.Gy0_gdbh = '{$workOrder}' AND b.sczl_gdbh = '{$workOrder}' GROUP BY a.Gy0_gxh";
  528. $yield = Db::query($yieldSql);
  529. foreach ($list as $key=>$value){
  530. if ($value['yjno']<10){
  531. $value['yjno'] = '0'.$value['yjno'];
  532. }
  533. if ($value['gxh']<10){
  534. $value['gxh'] = '0'.$value['gxh'];
  535. }
  536. $list[$key]['印件及工序'] = $value['yjno'].'-'.$value['gxh'].'-->'.$value['gxmc'];
  537. foreach ($yield as $k=>$v){
  538. if ($v['gxh'] === $list[$key]['gxh']){
  539. $list[$key]['计划产量/已完成'] = (int)($value['计划接货数']/$value['ls']).'/'.$v['cl'];
  540. $list[$key]['完成率'] = number_format($v['cl']/($value['计划接货数']/$value['ls']),4)*100 . '%';
  541. }else{
  542. $list[$key]['计划产量/已完成'] = ($value['计划接货数']/$value['ls']).'/0';
  543. $list[$key]['完成率'] = '';
  544. }
  545. }
  546. if ($value['完工时间'] == '1900-01-01 00:00:00') {
  547. $list[$key]['完工时间'] = '';
  548. }
  549. unset($list[$key]['yjno'],$list[$key]['gxh'],$list[$key]['gxmc'],$list[$key]['计划接货数'],$list[$key]['ls']);
  550. }
  551. $this->success('成功',$list);
  552. }
  553. /**
  554. * 工序状态更正->工序状态编辑
  555. * @ApiMethod (POST)
  556. * @param void
  557. * @return void
  558. * @throws \think\Exception
  559. * @throws \think\exception\PDOException
  560. */
  561. public function ProcessStatusCorrectionEdit()
  562. {
  563. if (Request::instance()->isPost() === false){
  564. $this->error('请求错误');
  565. }
  566. $param = Request::instance()->post();
  567. if (empty($param)){
  568. $this->error('参数错误');
  569. }
  570. $i = 0;
  571. foreach ($param as $key=>$value){
  572. if ($value['PD_WG'] === null || $value['PD_WG'] === ''){
  573. $endTime = '1900-01-01 00:00:00';
  574. }else{
  575. $endTime = $value['PD_WG'];
  576. }
  577. $sql = \db('工单_工艺资料')
  578. ->where('UniqId',$value['UniqId'])
  579. ->fetchSql(true)
  580. ->update(['PD_WG'=>$endTime]);
  581. $res = Db::query($sql);
  582. if ($res !== false){
  583. $i++;
  584. }
  585. }
  586. if ($i !== 0){
  587. $this->success('成功');
  588. }else{
  589. $this->error('失败');
  590. }
  591. }
  592. /**
  593. * 班次选择
  594. * @ApiMethod (GET)
  595. * @return void
  596. * @throws \think\db\exception\DataNotFoundException
  597. * @throws \think\db\exception\ModelNotFoundException
  598. * @throws \think\exception\DbException
  599. */
  600. public function ScheduleSelection()
  601. {
  602. if ($this->request->isGet() === false){
  603. $this->error('请求错误');
  604. }
  605. $list = \db('工单_排程班次')->field('rtrim(bcdh) as 班次代号,rtrim(desc_) as desc_,rtrim(stdtime) as stdtime')->select();
  606. if (empty($list)){
  607. $this->success('未找到班次数据');
  608. }
  609. foreach ($list as $key=>$value){
  610. $list[$key]['detail'] = $value['班次代号'].'||'.$value['desc_'].'||'.$value['stdtime'];
  611. unset($list[$key]['desc_'],$list[$key]['stdtime']);
  612. }
  613. $this->success('成功',$list);
  614. }
  615. /**
  616. * 车间设备制程展示
  617. * @ApiMethod (GET)
  618. * @param void $param
  619. * @return void
  620. * @throws \think\db\exception\DataNotFoundException
  621. * @throws \think\db\exception\ModelNotFoundException
  622. * @throws \think\exception\DbException
  623. */
  624. public function EquipmentScheduling()
  625. {
  626. if ($this->request->isGet() === false){
  627. $this->error('参数错误');
  628. }
  629. $param = $this->request->param();
  630. if (empty($param)){
  631. $this->error('参数错误');
  632. }
  633. $machine = $param['machine'];
  634. $list = \db('工单_工艺资料')
  635. ->alias('a')
  636. ->field([
  637. 'rtrim(a.Gy0_gdbh)' => '工单编号',
  638. 'rtrim(a.Gy0_计划接货数)' => '计划接货数',
  639. 'rtrim(a.Gy0_小时产能)' => '小时产能',
  640. 'rtrim(a.Gy0_生产工时)' => '生产工时',
  641. 'rtrim(a.Gy0_辅助工时)' => '辅助工时',
  642. 'rtrim(a.Gy0_班次安排)' => '班次安排',
  643. 'rtrim(a.工序备注)' => '排单备注',
  644. 'rtrim(a.Gy0_最早开工时间)' => '最早开工时间',
  645. 'rtrim(a.Gy0_sj1)' => '计划开工时间',
  646. 'rtrim(a.Gy0_sj2)' => '计划完工时间',
  647. 'rtrim(a.Gy0_yjno)' => 'yjno',
  648. 'rtrim(a.Gy0_gxh)' => 'gxh',
  649. 'rtrim(a.Gy0_gxmc)' => 'gxmc',
  650. 'rtrim(a.Gy0_ls)' => 'ls',
  651. 'rtrim(a.UniqId)' => 'UniqId',
  652. 'SUM(b.sczl_cl)' => '已完成'
  653. ])
  654. ->join('设备_产量计酬 b','a.Gy0_gdbh = b.sczl_gdbh AND a.Gy0_gxh = b.sczl_gxh','LEFT')
  655. ->where([
  656. 'a.Gy0_sbbh' => $machine,
  657. 'a.Gy0_sj1' => ['>','1900-01-01 00:00:00'],
  658. 'a.PD_WG' => '1900-01-01 00:00:00'
  659. ])
  660. ->where('a.Gy0_sj1','<','2099-01-01 00:00:00')
  661. ->group('a.Gy0_gdbh')
  662. ->select();
  663. foreach ($list as $key=>$value){
  664. $list[$key]['计划接货数'] = (int)round($value['计划接货数']/$value['ls']);
  665. if ($value['yjno']<10){
  666. $value['yjno'] = '0'.$value['yjno'];
  667. }
  668. if ($value['gxh']<10){
  669. $value['gxh'] = '0'.$value['gxh'];
  670. }
  671. $list[$key]['印件/工序'] = $value['yjno'].'-'.$value['gxh'].'-'.$value['gxmc'];
  672. unset($list[$key]['yjno'],$list[$key]['gxh'],$list[$key]['gxmc'],$list[$key]['ls']);
  673. }
  674. $this->success('成功',$list);
  675. }
  676. /**
  677. * 车间设备排程编辑
  678. * @ApiMethod (POST)
  679. * @param void $param
  680. * @return void
  681. * @throws \think\Exception
  682. * @throws \think\exception\PDOException
  683. */
  684. public function EquipmentSchedulingEdit()
  685. {
  686. if (Request::instance()->isPost() === false){
  687. $this->error('请求错误');
  688. }
  689. $param = Request::instance()->post();
  690. if (empty($param)){
  691. $this->error('参数错误');
  692. }
  693. $i = 0;
  694. foreach ($param as $key=>$value){
  695. $data = [
  696. 'Gy0_小时产能' => $value['capacity'],
  697. 'Gy0_生产工时' => $value['ProductionHours'],
  698. 'Gy0_辅助工时' => $value['AuxiliaryHours'],
  699. 'Gy0_班次安排' => $value['shift'],
  700. '工序备注' => $value['remark'],
  701. 'Gy0_最早开工时间' => $value['start'] === ''?'1900-01-01 00:00:00':date('Y-m-d H:i:s',strtotime($value['start'])),
  702. 'Gy0_sj1' => date('Y-m-d H:i:s',strtotime($value['projectTime'])),
  703. 'Gy0_sj2' => date('Y-m-d H:i:s',strtotime($param[0]['projectTime'])+(ceil($param[0]['ProductionHours'])+ceil($param[0]['AuxiliaryHours']))*3600),
  704. ];
  705. $sql = \db('工单_工艺资料')
  706. ->where('UniqId',$value['UniqId'])
  707. ->fetchSql(true)
  708. ->update($data);
  709. $res = Db::query($sql);
  710. if ($res !== false){
  711. $i++;
  712. }
  713. }
  714. if ($i !== 0){
  715. $this->success('成功');
  716. }else{
  717. $this->error('失败');
  718. }
  719. }
  720. /**
  721. * 机台工单展示
  722. * @ApiMethod ()
  723. * @return void
  724. * @throws \think\db\exception\BindParamException
  725. * @throws \think\exception\PDOException
  726. */
  727. public function MachineWorkOrderList()
  728. {
  729. if ($this->request->isGet() === false){
  730. $this->error('请求失败');
  731. }
  732. $param = $this->request->param();
  733. if (empty($param)){
  734. $this->error('参数错误');
  735. }
  736. $where = '';
  737. if (isset($param['search'])){
  738. $where = "
  739. a.Gd_gdbh LIKE '%{$param['search']}%'
  740. OR a.`成品名称` LIKE '%{$param['search']}%'
  741. ";
  742. }
  743. $list = \db('工单_基本资料')
  744. ->alias('a')
  745. ->field([
  746. 'RTRIM( a.Gd_gdbh )' => '工单编号',
  747. 'RTRIM( a.`销售订单号` )' => '销售订单号',
  748. 'RTRIM( c.yj_yjmc )' => '印件名称',
  749. 'RTRIM( b.Gy0_yjno )' =>'yjno',
  750. 'RTRIM( b.Gy0_gxh )' => 'gxh',
  751. 'RTRIM( b.Gy0_gxmc )' => 'gxmc',
  752. 'RTRIM( b.Add_gxmc )' => 'Add_gxmc',
  753. 'RTRIM( b.`Gy0_计划接货数` )' => '计划接货数',
  754. 'RTRIM( b.`Gy0_小时产能` )' => '小时产能',
  755. 'RTRIM( b.`工价系数` )' => '产能系数',
  756. 'RTRIM( b.`Gy0_生产工时` )' => '生产工时',
  757. 'RTRIM( b.Gy0_ls )' => 'ls',
  758. 'RTRIM( b.`Gy0_辅助工时` )' => '辅助工时',
  759. 'RTRIM( b.`Gy0_最早开工时间` )' => '最早开工时间',
  760. 'RTRIM( b.Gy0_sj1 )' => '计划开工时间',
  761. 'RTRIM( b.Gy0_sj2 )' => '计划完工时间',
  762. 'RTRIM( b.`Gy0_班次安排` )' => '班次安排',
  763. 'RTRIM( b.`工序备注` )' => '排单备注',
  764. 'RTRIM( a.Gd_cpmc )' => '产品名称',
  765. 'RTRIM( a.`成品名称` )' => '成品名称',
  766. 'RTRIM( a.`订单数量` )' => '订单数量',
  767. 'RTRIM( a.`计量单位` )' => '计量单位',
  768. 'RTRIM( a.`交货日期` )' => '交货日期',
  769. 'RTRIM( a.Gd_cpdh )' => '产品代号',
  770. 'RTRIM( a.`成品代号` )' => '成品代号',
  771. 'RTRIM( b.Gy0_sbbh )' => '设备编号',
  772. 'RTRIM( b.Gy0_SITE )' => '车间名称',
  773. 'RTRIM( b.UniqId )' => 'GYUID',
  774. 'SUM( d.sczl_cl )' => '已完成产量'
  775. ])
  776. ->join('工单_工艺资料 b','a.Gd_gdbh = b.Gy0_gdbh')
  777. ->join('工单_印件资料 c','c.Yj_Gdbh = a.Gd_gdbh')
  778. ->join('设备_产量计酬 d','a.Gd_gdbh = d.sczl_gdbh AND b.Gy0_sbbh = d.sczl_jtbh','LEFT')
  779. ->where([
  780. 'a.gd_statu' => '2-生产中',
  781. 'a.行号'=> '1',
  782. 'b.Gy0_sbbh' => ['LIKE','%'.$param['machine'].'%'],
  783. 'b.PD_WG' => '1900-01-01 00:00:00'
  784. ])
  785. ->where($where)
  786. ->group('a.Gd_gdbh,b.Gy0_gxh')
  787. ->order('Gy0_sj1')
  788. ->select();
  789. if (empty($list)){
  790. $this->success('',[]);
  791. }
  792. $data['制程'] = $data['排程'] = [];
  793. foreach ($list as $key=>$value){
  794. if ((int)$value['yjno'] <10){
  795. $value['yjno'] = '0'.rtrim($value['yjno']);
  796. }
  797. if ((int)$value['gxh'] <10){
  798. $value['gxh'] = '0'.rtrim($value['gxh']);
  799. }
  800. if (rtrim($value['Add_gxmc']) == ''){
  801. $list[$key]['印件工序及名称'] = $value['yjno'].'-'.$value['gxh'].'-->'.rtrim($value['gxmc']);
  802. }else{
  803. $list[$key]['印件工序及名称'] = $value['yjno'].'-'.$value['gxh'].'-->'.rtrim($value['gxmc']).'【'.rtrim($value['Add_gxmc']).'】';
  804. }
  805. unset($list[$key]['gxmc'],$list[$key]['Add_gxmc']);
  806. if ($value['产品名称'] == ''){
  807. $list[$key]['产品名称'] = $value['成品名称'];
  808. }
  809. if ($value['产品代号'] == ''){
  810. $list[$key]['产品代号'] = $value['成品代号'];
  811. }
  812. unset($list[$key]['成品代号'],$list[$key]['成品名称']);
  813. if ($list[$key]['计划开工时间'] !== '1900-01-01 00:00:00'){
  814. array_push($data['制程'],$list[$key]);
  815. }else{
  816. array_push($data['排程'],$list[$key]);
  817. }
  818. }
  819. $this->success('成功',$data);
  820. }
  821. /**
  822. * 机组调整
  823. * @return void
  824. * @throws \think\Exception
  825. * @throws \think\db\exception\BindParamException
  826. * @throws \think\exception\PDOException
  827. */
  828. public function MachineTeamEdit()
  829. {
  830. if ($this->request->isGet() === false){
  831. $this->error('请求错误');
  832. }
  833. $param = $this->request->param();
  834. if (empty($param) || isset($param['UniqId']) === false){
  835. $this->error('参数错误');
  836. }
  837. $sql = \db('工单_工艺资料')
  838. ->where('UniqId',$param['UniqId'])
  839. ->fetchSql(true)
  840. ->update(['Gy0_sbbh'=>$param['machine']]);
  841. $res = \db()->query($sql);
  842. if ($res !== false){
  843. $this->success('修改成功');
  844. }else{
  845. $this->error('修改失败');
  846. }
  847. }
  848. }