Manufacture.php 36 KB

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