Manufacture.php 36 KB

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