Manufacture.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876
  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. ])
  194. ->where($where)
  195. ->whereNotExists(function ($query) {
  196. $query->table('工单_工艺资料')->alias('b2')
  197. ->where('b2.Gy0_gdbh = a.Gd_gdbh')
  198. ->where('b2.Gy0_sj1 <> "1900-01-01 00:00:00"');
  199. })
  200. ->group('a.Gd_gdbh')
  201. ->select();
  202. }else{
  203. $list = db('工单_基本资料')->alias('a')
  204. ->field([
  205. 'rtrim(a.Gd_gdbh)' => '工单编号',
  206. 'rtrim(a.Gd_cpdh)' => '产品代号',
  207. 'rtrim(a.Gd_cpmc)' => '产品名称',
  208. 'rtrim(a.接单日期)' => '接单日期',
  209. 'rtrim(a.交货日期)' => '交货日期',
  210. 'rtrim(a.订单数量)' => '订单数量',
  211. 'rtrim(a.计量单位)' => '计量单位',
  212. 'rtrim(a.销售订单号)' => '销售订单号',
  213. 'rtrim(a.Gd_客户代号)' => '客户编号',
  214. 'rtrim(a.Gd_客户名称)' => '客户名称',
  215. 'rtrim(a.客户料号)' => '客户料号',
  216. 'rtrim(a.Uniqid)' => 'GDUID',
  217. ])
  218. ->join('工单_工艺资料 b', 'a.Gd_gdbh = b.Gy0_gdbh')
  219. ->join('产品_基本资料 c', 'a.Gd_cpdh = c.产品编号')
  220. ->where([
  221. 'a.gd_statu' => '2-生产中',
  222. 'a.行号' => '1',
  223. 'b.PD_WG' => '1900-01-01 00:00:00',
  224. 'b.Gy0_sj1' => ['<>', '1900-01-01 00:00:00'],
  225. 'c.状态' => '',
  226. ])
  227. ->where($where)
  228. ->group('a.Gd_gdbh')
  229. ->select();
  230. }
  231. if (empty($list)){
  232. $this->success('未找到工单信息');
  233. }
  234. $this->success('成功',$list);
  235. }
  236. /**
  237. * 排程中/制程中工单->工序列表
  238. * @ApiMethod (GET)
  239. * @param string $Gd_gdbh 工单编号
  240. * @return \think\response\Json
  241. * @throws \think\db\exception\DataNotFoundException
  242. * @throws \think\db\exception\ModelNotFoundException
  243. * @throws \think\exception\DbException
  244. */
  245. public function ScheduleProcess()
  246. {
  247. if ($this->request->isGet() === false){
  248. $this->error('请求错误');
  249. }
  250. $Gd_gdbh = input('Gd_gdbh');
  251. if (empty($Gd_gdbh)){
  252. $this->error('参数错误');
  253. }
  254. $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 小时产能,
  255. rtrim(a.工价系数) as 产能系数,rtrim(a.Gy0_生产工时) as 生产工时,rtrim(a.Gy0_辅助工时) as 辅助工时,rtrim(a.Gy0_最早开工时间) as 最早开工时间,
  256. rtrim(a.Gy0_sj1) as 计划开工时间,rtrim(a.Gy0_sj2) as 计划完工时间,rtrim(a.Gy0_班次安排) as 班次安排,rtrim(a.工序备注) as 排单备注,
  257. rtrim(a.PD_WG) as 工序完工,rtrim(a.UniqId) as UniqId,COALESCE(b.cl, 0) AS 产量, c.设备名称,rtrim(d.计划投料) as 工序产量
  258. FROM `工单_工艺资料` AS a
  259. JOIN `设备_基本资料` AS c ON a.Gy0_sbbh = c.设备编号
  260. JOIN `工单_基本资料` As d ON a.Gy0_gdbh = d.Gd_Gdbh
  261. LEFT JOIN (
  262. SELECT sczl_gdbh, sczl_gxh, SUM(sczl_cl) AS cl
  263. FROM `设备_产量计酬`
  264. GROUP BY sczl_gdbh, sczl_gxh
  265. ) AS b ON a.Gy0_gdbh = b.sczl_gdbh AND (a.Gy0_gxh = b.sczl_gxh OR b.sczl_gxh IS NULL)
  266. WHERE a.Gy0_gdbh = '{$Gd_gdbh}' AND a.Gy0_sbbh != ''
  267. GROUP BY a.Gy0_gxh";
  268. $list = Db::query($sql);
  269. if (empty($list)){
  270. $this->success('未找到工序');
  271. }
  272. foreach ($list as $key=>$value){
  273. if ((int)$value['Gy0_yjno'] <10){
  274. $value['Gy0_yjno'] = '0'.rtrim($value['Gy0_yjno']);
  275. }
  276. if ((int)$value['Gy0_gxh'] <10){
  277. $value['Gy0_gxh'] = '0'.rtrim($value['Gy0_gxh']);
  278. }
  279. if (rtrim($value['Add_gxmc']) == ''){
  280. $list[$key]['印件工序及名称'] = $value['Gy0_yjno'].'-'.$value['Gy0_gxh'].'-->'.rtrim($value['Gy0_gxmc']);
  281. }else{
  282. $list[$key]['印件工序及名称'] = $value['Gy0_yjno'].'-'.$value['Gy0_gxh'].'-->'.rtrim($value['Gy0_gxmc']).'【'.rtrim($value['Add_gxmc']).'】';
  283. }
  284. unset($list[$key]['Gy0_gxmc'],$list[$key]['Add_gxmc']);
  285. $list[$key]['机组'] = $value['设备编号'];
  286. $list[$key]['剩余产量'] = (int)$list[$key]['工序产量']-(int)$list[$key]['产量'];
  287. }
  288. $this->success('成功',$list);
  289. }
  290. /**
  291. * 排单页面左侧车间和机台菜单
  292. * @ApiMethod (GET)
  293. * @return \think\response\Json
  294. * @throws \think\db\exception\DataNotFoundException
  295. * @throws \think\db\exception\ModelNotFoundException
  296. * @throws \think\exception\DbException
  297. */
  298. public function workbench()
  299. {
  300. if ($this->request->isGet() === false){
  301. $this->error('请求错误');
  302. }
  303. $data = [];
  304. $department = \db('设备_基本资料')
  305. ->distinct(true)
  306. ->where('使用部门','<>','研发中心')
  307. ->where('设备编组','<>','')
  308. ->order('设备编组')
  309. ->column('使用部门');
  310. if (empty($department)){
  311. $this->success('为获取到机台数据');
  312. }
  313. foreach ($department as $value){
  314. $benchClass = \db('设备_基本资料')->where('使用部门',$value)->distinct(true)->order('设备编组')->cache(true)->column('设备编组');
  315. foreach ($benchClass as $v){
  316. if (rtrim($v) !== ''){
  317. $machine = \db('设备_基本资料')->where('使用部门',$value)->where('设备编组',$v)->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->cache(true)->select();
  318. foreach ($machine as $kk=>$vv){
  319. $data[rtrim($value)][rtrim($v)][$kk] = $vv['设备编号'].'-->'.$vv['设备名称'];
  320. }
  321. }
  322. }
  323. }
  324. $this->success('成功',$data);
  325. }
  326. /**
  327. * 工单状态设置
  328. * @ApiMethod (GET)
  329. * @param string $workOrder 工单编号
  330. * @param string $status 工单状态
  331. * @return void
  332. * @throws \think\Exception
  333. * @throws \think\exception\PDOException
  334. */
  335. public function StatusEdit()
  336. {
  337. if (Request::instance()->isPost() === false){
  338. $this->error('请求错误');
  339. }
  340. $workOrder = input('workOrder');
  341. $status = input('status');
  342. if (empty($workOrder) || empty($status)){
  343. $this->error('参数错误');
  344. }
  345. $sql = \db('工单_基本资料')->where('Gd_gdbh',$workOrder)->fetchSql(true)->update(['gd_statu'=>$status]);
  346. $res = Db::query($sql);
  347. if ($res !== false){
  348. $this->success('成功');
  349. }else{
  350. $this->error('失败');
  351. }
  352. }
  353. /**
  354. * 更改工序状态
  355. * @ApiMethod (GET)
  356. * @param void
  357. * @return void
  358. * @throws \think\Exception
  359. * @throws \think\exception\PDOException
  360. */
  361. public function complete()
  362. {
  363. if ($this->request->isGet() === false){
  364. $this->error('请求错误');
  365. }
  366. $data = $this->request->param();
  367. if (empty($data)){
  368. $this->error('参数错误');
  369. }
  370. $where = [
  371. 'Gy0_gdbh' => $data['workOrder'],
  372. 'Gy0_gxh' => $data['processCode']
  373. ];
  374. $sql = \db('工单_工艺资料')->where($where)->fetchSql(true)->update(['PD_WG'=>date('Y-m-d H:i:s',time())]);
  375. $res = Db::query($sql);
  376. if ($res !== false){
  377. $this->success('成功');
  378. }else{
  379. $this->error('失败');
  380. }
  381. }
  382. /**
  383. * 加入排产
  384. * @ApiMethod (POST)
  385. * @param void $data
  386. * @return void
  387. * @throws \think\Exception
  388. * @throws \think\db\exception\DataNotFoundException
  389. * @throws \think\db\exception\ModelNotFoundException
  390. * @throws \think\exception\DbException
  391. * @throws \think\exception\PDOException
  392. */
  393. public function ProductionSchedulingAdd()
  394. {
  395. if (Request::instance()->isPost() === false){
  396. $this->error('请求错误');
  397. }
  398. $data = Request::instance()->post();
  399. if (empty($data)){
  400. $this->error('参数错误');
  401. }
  402. $where = [
  403. 'Gy0_gdbh' => $data['workOrder'],
  404. 'Gy0_sbbh' => ['like','%'.$data['machine'].'%'],
  405. 'Gy0_yjno' => $data['printCode'],
  406. 'Gy0_gxh' => $data['processCode']
  407. ];
  408. $result = \db('工单_工艺资料')->where($where)->field('rtrim(Gy0_sj1) as sj1')->find();
  409. if ($result['sj1'] != '1900-01-01 00:00:00'){
  410. $this->error('该工单已经是制程中');
  411. }
  412. $lastTime = \db('工单_工艺资料')
  413. ->where(['Gy0_sbbh'=>$where['Gy0_sbbh'],'Gy0_sj2'=>['<>','1900-01-01 00:00:00'],'Gy0_sj2'=>['<','2099-01-01 00:00:00']])
  414. ->field('rtrim(Gy0_sj2) as sj2')
  415. ->order('Gy0_sj2 desc')
  416. ->find();
  417. $date = date('Y-m-d H:i:s',time());
  418. if ($lastTime['sj2'] < $date){
  419. $newTime = $date;
  420. }else{
  421. $newTime = $lastTime['sj2'];
  422. }
  423. $row = \db('工单_工艺资料')
  424. ->where($where)
  425. ->field('rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_小时产能) as 小时产能,rtrim(Gy0_辅助工时) as 辅助工时')
  426. ->find();
  427. if (empty($row)){
  428. $this->success('未找到该工单工艺资料');
  429. }
  430. $endTime = date('Y-m-d H:i:s',strtotime($newTime) + ((int)round($row['计划接货数']/$row['小时产能'])+(int)$row['辅助工时'])*3600);
  431. $sql = \db('工单_工艺资料')
  432. ->where($where)
  433. ->fetchSql(true)
  434. ->update(['Gy0_sj1'=>$newTime,'Gy0_sj2'=>$endTime,'Mod_rq'=>date('Y-m-d H:i:s',time())]);
  435. $res = Db::query($sql);
  436. if ($res !== false){
  437. $this->success('成功');
  438. }else{
  439. $this->error('失败');
  440. }
  441. }
  442. /**
  443. * 暂停排产
  444. * @ApiMethod (POST)
  445. * @param void $data
  446. * @return void
  447. * @throws \think\Exception
  448. * @throws \think\db\exception\DataNotFoundException
  449. * @throws \think\db\exception\ModelNotFoundException
  450. * @throws \think\exception\DbException
  451. * @throws \think\exception\PDOException
  452. */
  453. public function ProductionSchedulingPause()
  454. {
  455. if (Request::instance()->isPost() === false){
  456. $this->error('请求错误');
  457. }
  458. $data = Request::instance()->post();
  459. if (empty($data)){
  460. $this->error('参数错误');
  461. }
  462. $where = [
  463. 'Gy0_gdbh' => $data['workOrder'],
  464. 'Gy0_sbbh' => ['like','%'.$data['machine'].'%'],
  465. 'Gy0_yjno' => $data['printCode'],
  466. 'Gy0_gxh' => $data['processCode']
  467. ];
  468. $machine = $data['machine'];
  469. $endTime = \db('工单_工艺资料')->where($where)->field('rtrim(Gy0_sj2) as sj2,rtrim(PD_WG) as wg')->find();
  470. if (empty($endTime)){
  471. $this->success('未找到该工序');
  472. }
  473. $time = $endTime['sj2'];
  474. if ($endTime['sj2'] == '1900-01-01 00:00:00' || $endTime['wg'] != '1900-01-01 00:00:00'){
  475. $this->error('该工单不是制程中工单');
  476. }
  477. $sql = \db('工单_工艺资料')
  478. ->where($where)
  479. ->fetchSql(true)
  480. ->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')]);
  481. $row = \db('工单_工艺资料')
  482. ->where($where)
  483. ->field('rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_小时产能) as 小时产能,rtrim(Gy0_辅助工时) as 辅助工时')
  484. ->find();
  485. if (empty($row)){
  486. $this->success('未找到该工序');
  487. }
  488. $number = -(int)round($row['计划接货数']/$row['小时产能'])+(int)$row['辅助工时'];
  489. $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'";
  490. $rechres = Db::query($rechSql);
  491. $res = Db::query($sql);
  492. if ($res !== false && $rechres !== false){
  493. $this->success('成功');
  494. }else{
  495. $this->error('失败');
  496. }
  497. }
  498. /**
  499. * 工序状态更正
  500. * @ApiMethod (GET)
  501. * @param void $param
  502. * @return void
  503. * @throws \think\db\exception\DataNotFoundException
  504. * @throws \think\db\exception\ModelNotFoundException
  505. * @throws \think\exception\DbException
  506. */
  507. public function ProcessStatusCorrection()
  508. {
  509. if ($this->request->isGet() === false){
  510. $this->error('请求错误');
  511. }
  512. $param = $this->request->param();
  513. if (empty($param)){
  514. $this->error('参数错误');
  515. }
  516. $where = [
  517. 'Gy0_gdbh' => $param['workOrder'],
  518. 'Gy0_sbbh' => ['<>','']
  519. ];
  520. $workOrder = $where['Gy0_gdbh'];
  521. $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';
  522. $list = \db('工单_工艺资料')->where($where)->field($field)->order('Gy0_gxh')->select();
  523. if (empty($list)){
  524. $this->success('未找到该工单工艺资料');
  525. }
  526. $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";
  527. $yield = Db::query($yieldSql);
  528. foreach ($list as $key=>$value){
  529. if ($value['yjno']<10){
  530. $value['yjno'] = '0'.$value['yjno'];
  531. }
  532. if ($value['gxh']<10){
  533. $value['gxh'] = '0'.$value['gxh'];
  534. }
  535. $list[$key]['印件及工序'] = $value['yjno'].'-'.$value['gxh'].'-->'.$value['gxmc'];
  536. foreach ($yield as $k=>$v){
  537. if ($v['gxh'] === $list[$key]['gxh']){
  538. $list[$key]['计划产量/已完成'] = (int)($value['计划接货数']/$value['ls']).'/'.$v['cl'];
  539. $list[$key]['完成率'] = number_format($v['cl']/($value['计划接货数']/$value['ls']),4)*100 . '%';
  540. }else{
  541. $list[$key]['计划产量/已完成'] = ($value['计划接货数']/$value['ls']).'/0';
  542. $list[$key]['完成率'] = '';
  543. }
  544. }
  545. if ($value['完工时间'] == '1900-01-01 00:00:00') {
  546. $list[$key]['完工时间'] = '';
  547. }
  548. unset($list[$key]['yjno'],$list[$key]['gxh'],$list[$key]['gxmc'],$list[$key]['计划接货数'],$list[$key]['ls']);
  549. }
  550. $this->success('成功',$list);
  551. }
  552. /**
  553. * 工序状态更正->工序状态编辑
  554. * @ApiMethod (POST)
  555. * @param void
  556. * @return void
  557. * @throws \think\Exception
  558. * @throws \think\exception\PDOException
  559. */
  560. public function ProcessStatusCorrectionEdit()
  561. {
  562. if (Request::instance()->isPost() === false){
  563. $this->error('请求错误');
  564. }
  565. $param = Request::instance()->post();
  566. if (empty($param)){
  567. $this->error('参数错误');
  568. }
  569. $i = 0;
  570. foreach ($param as $key=>$value){
  571. if ($value['PD_WG'] === null || $value['PD_WG'] === ''){
  572. $endTime = '1900-01-01 00:00:00';
  573. }else{
  574. $endTime = $value['PD_WG'];
  575. }
  576. $sql = \db('工单_工艺资料')
  577. ->where('UniqId',$value['UniqId'])
  578. ->fetchSql(true)
  579. ->update(['PD_WG'=>$endTime]);
  580. $res = Db::query($sql);
  581. if ($res !== false){
  582. $i++;
  583. }
  584. }
  585. if ($i !== 0){
  586. $this->success('成功');
  587. }else{
  588. $this->error('失败');
  589. }
  590. }
  591. /**
  592. * 班次选择
  593. * @ApiMethod (GET)
  594. * @return void
  595. * @throws \think\db\exception\DataNotFoundException
  596. * @throws \think\db\exception\ModelNotFoundException
  597. * @throws \think\exception\DbException
  598. */
  599. public function ScheduleSelection()
  600. {
  601. if ($this->request->isGet() === false){
  602. $this->error('请求错误');
  603. }
  604. $list = \db('工单_排程班次')->field('rtrim(bcdh) as 班次代号,rtrim(desc_) as desc_,rtrim(stdtime) as stdtime')->select();
  605. if (empty($list)){
  606. $this->success('未找到班次数据');
  607. }
  608. foreach ($list as $key=>$value){
  609. $list[$key]['detail'] = $value['班次代号'].'||'.$value['desc_'].'||'.$value['stdtime'];
  610. unset($list[$key]['desc_'],$list[$key]['stdtime']);
  611. }
  612. $this->success('成功',$list);
  613. }
  614. /**
  615. * 车间设备制程展示
  616. * @ApiMethod (GET)
  617. * @param void $param
  618. * @return void
  619. * @throws \think\db\exception\DataNotFoundException
  620. * @throws \think\db\exception\ModelNotFoundException
  621. * @throws \think\exception\DbException
  622. */
  623. public function EquipmentScheduling()
  624. {
  625. if ($this->request->isGet() === false){
  626. $this->error('参数错误');
  627. }
  628. $param = $this->request->param();
  629. if (empty($param)){
  630. $this->error('参数错误');
  631. }
  632. $machine = $param['machine'];
  633. $list = \db('工单_工艺资料')
  634. ->alias('a')
  635. ->field([
  636. 'rtrim(a.Gy0_gdbh)' => '工单编号',
  637. 'rtrim(a.Gy0_计划接货数)' => '计划接货数',
  638. 'rtrim(a.Gy0_小时产能)' => '小时产能',
  639. 'rtrim(a.Gy0_生产工时)' => '生产工时',
  640. 'rtrim(a.Gy0_辅助工时)' => '辅助工时',
  641. 'rtrim(a.Gy0_班次安排)' => '班次安排',
  642. 'rtrim(a.工序备注)' => '排单备注',
  643. 'rtrim(a.Gy0_最早开工时间)' => '最早开工时间',
  644. 'rtrim(a.Gy0_sj1)' => '计划开工时间',
  645. 'rtrim(a.Gy0_sj2)' => '计划完工时间',
  646. 'rtrim(a.Gy0_yjno)' => 'yjno',
  647. 'rtrim(a.Gy0_gxh)' => 'gxh',
  648. 'rtrim(a.Gy0_gxmc)' => 'gxmc',
  649. 'rtrim(a.Gy0_ls)' => 'ls',
  650. 'rtrim(a.UniqId)' => 'UniqId',
  651. 'SUM(b.sczl_cl)' => '已完成'
  652. ])
  653. ->join('设备_产量计酬 b','a.Gy0_gdbh = b.sczl_gdbh AND a.Gy0_gxh = b.sczl_gxh','LEFT')
  654. ->where([
  655. 'a.Gy0_sbbh' => $machine,
  656. 'a.Gy0_sj1' => ['>','1900-01-01 00:00:00'],
  657. 'a.PD_WG' => '1900-01-01 00:00:00'
  658. ])
  659. ->where('a.Gy0_sj1','<','2099-01-01 00:00:00')
  660. ->group('a.Gy0_gdbh')
  661. ->select();
  662. foreach ($list as $key=>$value){
  663. $list[$key]['计划接货数'] = (int)round($value['计划接货数']/$value['ls']);
  664. if ($value['yjno']<10){
  665. $value['yjno'] = '0'.$value['yjno'];
  666. }
  667. if ($value['gxh']<10){
  668. $value['gxh'] = '0'.$value['gxh'];
  669. }
  670. $list[$key]['印件/工序'] = $value['yjno'].'-'.$value['gxh'].'-'.$value['gxmc'];
  671. unset($list[$key]['yjno'],$list[$key]['gxh'],$list[$key]['gxmc'],$list[$key]['ls']);
  672. }
  673. $this->success('成功',$list);
  674. }
  675. /**
  676. * 车间设备排程编辑
  677. * @ApiMethod (POST)
  678. * @param void $param
  679. * @return void
  680. * @throws \think\Exception
  681. * @throws \think\exception\PDOException
  682. */
  683. public function EquipmentSchedulingEdit()
  684. {
  685. if (Request::instance()->isPost() === false){
  686. $this->error('请求错误');
  687. }
  688. $param = Request::instance()->post();
  689. if (empty($param)){
  690. $this->error('参数错误');
  691. }
  692. $i = 0;
  693. foreach ($param as $key=>$value){
  694. $data = [
  695. 'Gy0_小时产能' => $value['capacity'],
  696. 'Gy0_生产工时' => $value['ProductionHours'],
  697. 'Gy0_辅助工时' => $value['AuxiliaryHours'],
  698. 'Gy0_班次安排' => $value['shift'],
  699. '工序备注' => $value['remark'],
  700. 'Gy0_最早开工时间' => $value['start'] === ''?'1900-01-01 00:00:00':date('Y-m-d H:i:s',strtotime($value['start'])),
  701. 'Gy0_sj1' => date('Y-m-d H:i:s',strtotime($value['projectTime'])),
  702. 'Gy0_sj2' => date('Y-m-d H:i:s',strtotime($param[0]['projectTime'])+(ceil($param[0]['ProductionHours'])+ceil($param[0]['AuxiliaryHours']))*3600),
  703. ];
  704. $sql = \db('工单_工艺资料')
  705. ->where('UniqId',$value['UniqId'])
  706. ->fetchSql(true)
  707. ->update($data);
  708. $res = Db::query($sql);
  709. if ($res !== false){
  710. $i++;
  711. }
  712. }
  713. if ($i !== 0){
  714. $this->success('成功');
  715. }else{
  716. $this->error('失败');
  717. }
  718. }
  719. /**
  720. * 机台工单展示
  721. * @ApiMethod ()
  722. * @return void
  723. * @throws \think\db\exception\BindParamException
  724. * @throws \think\exception\PDOException
  725. */
  726. public function MachineWorkOrderList()
  727. {
  728. if ($this->request->isGet() === false){
  729. $this->error('请求失败');
  730. }
  731. $param = $this->request->param();
  732. if (empty($param)){
  733. $this->error('参数错误');
  734. }
  735. $where = '';
  736. if (isset($param['search'])){
  737. $where = "
  738. a.Gd_gdbh LIKE '%{$param['search']}%'
  739. OR a.`成品名称` LIKE '%{$param['search']}%'
  740. ";
  741. }
  742. $list = \db('工单_基本资料')
  743. ->alias('a')
  744. ->field([
  745. 'RTRIM( a.Gd_gdbh )' => '工单编号',
  746. 'RTRIM( a.`销售订单号` )' => '销售订单号',
  747. 'RTRIM( c.yj_yjmc )' => '印件名称',
  748. 'RTRIM( b.Gy0_yjno )' =>'yjno',
  749. 'RTRIM( b.Gy0_gxh )' => 'gxh',
  750. 'RTRIM( b.Gy0_gxmc )' => 'gxmc',
  751. 'RTRIM( b.Add_gxmc )' => 'Add_gxmc',
  752. 'RTRIM( b.`Gy0_计划接货数` )' => '计划接货数',
  753. 'RTRIM( b.`Gy0_小时产能` )' => '小时产能',
  754. 'RTRIM( b.`工价系数` )' => '产能系数',
  755. 'RTRIM( b.`Gy0_生产工时` )' => '生产工时',
  756. 'RTRIM( b.Gy0_ls )' => 'ls',
  757. 'RTRIM( b.`Gy0_辅助工时` )' => '辅助工时',
  758. 'RTRIM( b.`Gy0_最早开工时间` )' => '最早开工时间',
  759. 'RTRIM( b.Gy0_sj1 )' => '计划开工时间',
  760. 'RTRIM( b.Gy0_sj2 )' => '计划完工时间',
  761. 'RTRIM( b.`Gy0_班次安排` )' => '班次安排',
  762. 'RTRIM( b.`工序备注` )' => '排单备注',
  763. 'RTRIM( a.Gd_cpmc )' => '产品名称',
  764. 'RTRIM( a.`成品名称` )' => '成品名称',
  765. 'RTRIM( a.`订单数量` )' => '订单数量',
  766. 'RTRIM( a.`计量单位` )' => '计量单位',
  767. 'RTRIM( a.`交货日期` )' => '交货日期',
  768. 'RTRIM( a.Gd_cpdh )' => '产品代号',
  769. 'RTRIM( a.`成品代号` )' => '成品代号',
  770. 'RTRIM( b.Gy0_sbbh )' => '设备编号',
  771. 'RTRIM( b.Gy0_SITE )' => '车间名称',
  772. 'RTRIM( b.UniqId )' => 'GYUID',
  773. 'SUM( d.sczl_cl )' => '已完成产量'
  774. ])
  775. ->join('工单_工艺资料 b','a.Gd_gdbh = b.Gy0_gdbh')
  776. ->join('工单_印件资料 c','c.Yj_Gdbh = a.Gd_gdbh')
  777. ->join('设备_产量计酬 d','a.Gd_gdbh = d.sczl_gdbh AND b.Gy0_sbbh = d.sczl_jtbh','LEFT')
  778. ->where([
  779. 'a.gd_statu' => '2-生产中',
  780. 'a.行号'=> '1',
  781. 'b.Gy0_sbbh' => ['LIKE','%'.$param['machine'].'%'],
  782. 'b.PD_WG' => '1900-01-01 00:00:00'
  783. ])
  784. ->where($where)
  785. ->group('a.Gd_gdbh,b.Gy0_gxh')
  786. ->order('Gy0_sj1')
  787. ->select();
  788. if (empty($list)){
  789. $this->success('',[]);
  790. }
  791. $data['制程'] = $data['排程'] = [];
  792. foreach ($list as $key=>$value){
  793. if ((int)$value['yjno'] <10){
  794. $value['yjno'] = '0'.rtrim($value['yjno']);
  795. }
  796. if ((int)$value['gxh'] <10){
  797. $value['gxh'] = '0'.rtrim($value['gxh']);
  798. }
  799. if (rtrim($value['Add_gxmc']) == ''){
  800. $list[$key]['印件工序及名称'] = $value['yjno'].'-'.$value['gxh'].'-->'.rtrim($value['gxmc']);
  801. }else{
  802. $list[$key]['印件工序及名称'] = $value['yjno'].'-'.$value['gxh'].'-->'.rtrim($value['gxmc']).'【'.rtrim($value['Add_gxmc']).'】';
  803. }
  804. unset($list[$key]['gxmc'],$list[$key]['Add_gxmc']);
  805. if ($value['产品名称'] == ''){
  806. $list[$key]['产品名称'] = $value['成品名称'];
  807. }
  808. if ($value['产品代号'] == ''){
  809. $list[$key]['产品代号'] = $value['成品代号'];
  810. }
  811. unset($list[$key]['成品代号'],$list[$key]['成品名称']);
  812. if ($list[$key]['计划开工时间'] !== '1900-01-01 00:00:00'){
  813. array_push($data['制程'],$list[$key]);
  814. }else{
  815. array_push($data['排程'],$list[$key]);
  816. }
  817. }
  818. $this->success('成功',$data);
  819. }
  820. /**
  821. * 机组调整
  822. * @return void
  823. * @throws \think\Exception
  824. * @throws \think\db\exception\BindParamException
  825. * @throws \think\exception\PDOException
  826. */
  827. public function MachineTeamEdit()
  828. {
  829. if ($this->request->isGet() === false){
  830. $this->error('请求错误');
  831. }
  832. $param = $this->request->param();
  833. if (empty($param) || isset($param['UniqId']) === false){
  834. $this->error('参数错误');
  835. }
  836. $sql = \db('工单_工艺资料')
  837. ->where('UniqId',$param['UniqId'])
  838. ->fetchSql(true)
  839. ->update(['Gy0_sbbh'=>$param['machine']]);
  840. $res = \db()->query($sql);
  841. if ($res !== false){
  842. $this->success('修改成功');
  843. }else{
  844. $this->error('修改失败');
  845. }
  846. }
  847. }