Manufacture.php 39 KB

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