Manufacture.php 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use Monolog\Handler\IFTTTHandler;
  5. use Overtrue\Socialite\Providers\WeWorkProvider;
  6. use think\Db;
  7. use think\Request;
  8. use function fast\e;
  9. /**
  10. *
  11. * 生产排单管理
  12. */
  13. class Manufacture extends Api
  14. {
  15. protected $noNeedLogin = ['*'];
  16. protected $noNeedRight = ['*'];
  17. /**
  18. * 计划中工单
  19. * @ApiMethod (GET)
  20. * @return \think\response\Json
  21. * @throws \think\db\exception\DataNotFoundException
  22. * @throws \think\db\exception\ModelNotFoundException
  23. * @throws \think\exception\DbException
  24. */
  25. public function Project()
  26. {
  27. if ($this->request->isGet() === false){
  28. $this->error('请求错误');
  29. }
  30. $param = $this->request->param();
  31. if (empty($param)){
  32. $this->error('参数错误');
  33. }
  34. if ($param['status'] === '计划中'){
  35. $status = '3-计划中';
  36. }else{
  37. $status = '1-已完工';
  38. }
  39. $page = 0;
  40. $limit = 15;
  41. if (isset($param['page'])){
  42. $page = $param['page'];
  43. }
  44. if (isset($param['limit'])){
  45. $limit = $param['limit'];
  46. }
  47. $where = [
  48. 'gd_statu' => $status,
  49. '行号' => '1',
  50. ];
  51. if (isset($param['search'])){
  52. $where['Gd_lx|Gd_gdbh|Gd_客户代号|Gd_客户名称|Gd_khdh|Gd_khmc|Gd_cpdh|Gd_cpmc|成品代号|成品名称|产品版本号'] = ['like','%'.$param['search'].'%'];
  53. }
  54. $field = 'rtrim(Gd_生产分类) as 生产分类,rtrim(Gd_gdbh) as 工单编号,rtrim(Gd_cpdh) as 产品代号,rtrim(Gd_cpmc) as 产品名称,rtrim(成品名称) as 成品名称,
  55. rtrim(接单日期) as 接单日期,rtrim(交货日期) as 交货日期,rtrim(订单数量) as 订单数量,rtrim(计量单位) as 计量单位,rtrim(Gd_khmc) as 客户名称,
  56. rtrim(Gd_客户代号) as 客户编号,rtrim(Gd_desc) as 备注,rtrim(客户料号) as 客户料号,rtrim(Sys_id) as 创建用户,rtrim(Sys_rq) as 创建时间,
  57. rtrim(Mod_rq) as 修改时间,rtrim(Uniqid) as UNIQID,rtrim(投料率) as 投料率,rtrim(销售订单号) as 销售订单号';
  58. $list = \db('工单_基本资料')->where($where)->field($field)->limit(($page-1)*$limit,$limit)->order('Uniqid desc')->select();
  59. $total = \db('工单_基本资料')->where($where)->count();
  60. if (empty($list)){
  61. $this->success('',[]);
  62. }
  63. foreach ($list as $key=>$value){
  64. $list[$key]['订单数量'] = rtrim((float)$value['订单数量']);
  65. $list[$key]['产品名称'] = $value['产品名称'] != '' ? $value['产品名称']:$value['成品名称'];
  66. $number = \db('工单_工艺资料')->where('Gy0_gdbh',$value['工单编号'])->count();
  67. if ($number === 0){
  68. $list[$key]['status'] = 0;
  69. }else{
  70. $list[$key]['status'] = 1;
  71. }
  72. unset($list[$key]['成品名称']);
  73. }
  74. $this->success('成功',['data'=>$list,'total'=>$total]);
  75. }
  76. /**
  77. * 计划中工单->工艺资料
  78. * @ApiMethod (GET)
  79. * @param string $Gd_gdbh 工单编号
  80. * @return \think\response\Json
  81. * @throws \think\db\exception\DataNotFoundException
  82. * @throws \think\db\exception\ModelNotFoundException
  83. * @throws \think\exception\DbException
  84. */
  85. public function projectCraft()
  86. {
  87. if ($this->request->isGet() === false){
  88. $this->error('请求错误');
  89. }
  90. $Gd_gdbh = input('Gd_gdbh');
  91. if (empty($Gd_gdbh)){
  92. $this->error('参数错误');
  93. }
  94. $where = [
  95. 'Gy0_gdbh' => $Gd_gdbh
  96. ];
  97. $filed = 'rtrim(Gy0_gdbh) as 工单编号,rtrim(重点工序) as 重点工序,Gy0_yjno,Gy0_gxh,Gy0_gxmc,Add_gxmc,rtrim(工序备注) as 工序备注,
  98. rtrim(Gy0_sbbh) as 机组,rtrim(Gy0_小时产能) as 小时产能,rtrim(Gy0_生产工时) as 生产工时,rtrim(Gy0_辅助工时) as 辅助工时,
  99. rtrim(印刷方式) as 印刷方式,rtrim(版距) as 版距,rtrim(Sys_id) as 创建用户,rtrim(Sys_rq) as 创建时间,rtrim(Mod_rq) as 修改时间,rtrim(UniqId) as UNIQID';
  100. $list = \db('工单_工艺资料')->where($where)->field($filed)->select();
  101. if (empty($list)){
  102. $this->success('',[]);
  103. }
  104. foreach ($list as $key=>$value){
  105. if ((int)$value['Gy0_yjno'] <10){
  106. $value['Gy0_yjno'] = '0'.rtrim($value['Gy0_yjno']);
  107. }
  108. if ((int)$value['Gy0_gxh'] <10){
  109. $value['Gy0_gxh'] = '0'.rtrim($value['Gy0_gxh']);
  110. }
  111. if (rtrim($value['Add_gxmc']) == ''){
  112. $list[$key]['印件工序及名称'] = $value['Gy0_yjno'].'-'.$value['Gy0_gxh'].'-->'.rtrim($value['Gy0_gxmc']);
  113. }else{
  114. $list[$key]['印件工序及名称'] = $value['Gy0_yjno'].'-'.$value['Gy0_gxh'].'-->'.rtrim($value['Gy0_gxmc']).'【'.rtrim($value['Add_gxmc']).'】';
  115. }
  116. unset($list[$key]['Gy0_gxmc'],$list[$key]['Add_gxmc']);
  117. }
  118. $this->success('成功',$list);
  119. }
  120. /**
  121. * 计划中工单->印件资料
  122. * @ApiMethod (GET)
  123. * @param string $Gd_gdbh 工单编号
  124. * @return \think\response\Json
  125. * @throws \think\db\exception\DataNotFoundException
  126. * @throws \think\db\exception\ModelNotFoundException
  127. * @throws \think\exception\DbException
  128. */
  129. public function projectPrint()
  130. {
  131. if ($this->request->isGet() === false){
  132. $this->error('请求错误');
  133. }
  134. $Gd_gdbh = input('Gd_gdbh');
  135. if (empty($Gd_gdbh)){
  136. $this->error('参数错误');
  137. }
  138. $where = [
  139. 'Yj_Gdbh' => $Gd_gdbh,
  140. ];
  141. $field = 'rtrim(Yj_Gdbh) as 工单编号,rtrim(yj_Yjno) as 印件号,rtrim(yj_Yjdh) as 印件代号,rtrim(yj_yjmc) as 印件名称,
  142. rtrim(yj_zzmc) as 纸张名称,rtrim(yj_tlgg) as 投料规格,rtrim(yj_成品数量) as 成品数量,rtrim(yj_实际投料) as 实际投料,
  143. rtrim(yj_Dw) as 投料单位,rtrim(yj_平张投料) as 平张投料,rtrim(yj_ls) as 联数,rtrim(yj_ks) as 开数,rtrim(Sys_id) as 创建用户,
  144. rtrim(Sys_rq) as 创建时间,rtrim(Mod_rq) as 修改时间,rtrim(Uniqid) as UNIQID';
  145. $list = \db('工单_印件资料')->where($where)->field($field)->select();
  146. if (empty($list)){
  147. $this->success('');
  148. }
  149. foreach ($list as $key=>$value){
  150. $list[$key]['成品数量'] = rtrim((float)$value['成品数量']);
  151. $list[$key]['实际投料'] = rtrim((float)$value['实际投料']);
  152. }
  153. $this->success('成功',$list);
  154. }
  155. /**
  156. * 排程中/制程中工单
  157. */
  158. public function Schedule(){
  159. if ($this->request->isGet() === false){
  160. $this->error('请求错误');
  161. }
  162. $param = $this->request->param();
  163. if (empty($param)){
  164. $this->error('参数错误');
  165. }
  166. $where = '';
  167. if (!empty($param['search'])){
  168. $where = "
  169. a.Gd_gdbh LIKE '%{$param['search']}%'
  170. OR a.`成品名称` LIKE '%{$param['search']}%'
  171. ";
  172. }
  173. if ($param['status'] === '排程中'){
  174. $list = db('工单_基本资料')->alias('a')
  175. ->field([
  176. 'rtrim(a.Gd_gdbh)' => '工单编号',
  177. 'rtrim(a.Gd_cpdh)' => '产品代号',
  178. 'rtrim(a.Gd_cpmc)' => '产品名称',
  179. 'rtrim(a.接单日期)' => '接单日期',
  180. 'rtrim(a.交货日期)' => '交货日期',
  181. 'rtrim(a.订单数量)' => '订单数量',
  182. 'rtrim(a.计量单位)' => '计量单位',
  183. 'rtrim(a.销售订单号)' => '销售订单号',
  184. 'rtrim(a.Gd_客户代号)' => '客户编号',
  185. 'rtrim(a.Gd_客户名称)' => '客户名称',
  186. 'rtrim(a.客户料号)' => '客户料号',
  187. 'rtrim(a.Uniqid)' => 'GDUID',
  188. ])
  189. ->join('工单_工艺资料 b', 'a.Gd_gdbh = b.Gy0_gdbh')
  190. ->where([
  191. 'a.gd_statu' => '2-生产中',
  192. 'a.行号' => '1',
  193. 'b.PD_WG' => '1900-01-01 00:00:00',
  194. ])
  195. ->where($where)
  196. // ->whereNotExists(function ($query) {
  197. // $query->table('工单_工艺资料')->alias('b2')
  198. // ->where('b2.Gy0_gdbh = a.Gd_gdbh')
  199. // ->where('b2.Gy0_sj1 <> "1900-01-01 00:00:00"');
  200. // })
  201. ->group('a.Gd_gdbh')
  202. ->select();
  203. }else{
  204. $list = db('工单_基本资料')->alias('a')
  205. ->field([
  206. 'rtrim(a.Gd_gdbh)' => '工单编号',
  207. 'rtrim(a.Gd_cpdh)' => '产品代号',
  208. 'rtrim(a.Gd_cpmc)' => '产品名称',
  209. 'rtrim(a.接单日期)' => '接单日期',
  210. 'rtrim(a.交货日期)' => '交货日期',
  211. 'rtrim(a.订单数量)' => '订单数量',
  212. 'rtrim(a.计量单位)' => '计量单位',
  213. 'rtrim(a.销售订单号)' => '销售订单号',
  214. 'rtrim(a.Gd_客户代号)' => '客户编号',
  215. 'rtrim(a.Gd_客户名称)' => '客户名称',
  216. 'rtrim(a.客户料号)' => '客户料号',
  217. 'rtrim(a.Uniqid)' => 'GDUID',
  218. ])
  219. ->join('工单_工艺资料 b', 'a.Gd_gdbh = b.Gy0_gdbh')
  220. ->where([
  221. 'a.gd_statu' => '2-生产中',
  222. 'a.行号' => '1',
  223. 'b.PD_WG' => '1900-01-01 00:00:00',
  224. 'b.Gy0_sj1' => ['<>', '1900-01-01 00:00:00'],
  225. ])
  226. ->where($where)
  227. ->group('a.Gd_gdbh')
  228. ->select();
  229. }
  230. if (empty($list)){
  231. $this->success('未找到工单信息');
  232. }
  233. $this->success('成功',$list);
  234. }
  235. /**
  236. * 排程中/制程中工单->工序列表
  237. * @ApiMethod (GET)
  238. * @param string $Gd_gdbh 工单编号
  239. * @return \think\response\Json
  240. * @throws \think\db\exception\DataNotFoundException
  241. * @throws \think\db\exception\ModelNotFoundException
  242. * @throws \think\exception\DbException
  243. */
  244. public function ScheduleProcess()
  245. {
  246. if ($this->request->isGet() === false){
  247. $this->error('请求错误');
  248. }
  249. $Gd_gdbh = input('Gd_gdbh');
  250. if (empty($Gd_gdbh)){
  251. $this->error('参数错误');
  252. }
  253. $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 小时产能,
  254. rtrim(a.工价系数) as 产能系数,rtrim(a.Gy0_生产工时) as 生产工时,rtrim(a.Gy0_辅助工时) as 辅助工时,rtrim(a.Gy0_最早开工时间) as 最早开工时间,
  255. rtrim(a.Gy0_sj1) as 计划开工时间,rtrim(a.Gy0_sj2) as 计划完工时间,rtrim(a.Gy0_班次安排) as 班次安排,rtrim(a.工序备注) as 排单备注,
  256. rtrim(a.PD_WG) as 工序完工,rtrim(a.UniqId) as UniqId,COALESCE(b.cl, 0) AS 产量, c.设备名称,rtrim(d.计划投料) as 工序产量
  257. FROM `工单_工艺资料` AS a
  258. JOIN `设备_基本资料` AS c ON a.Gy0_sbbh = c.设备编号
  259. JOIN `工单_基本资料` As d ON a.Gy0_gdbh = d.Gd_Gdbh
  260. LEFT JOIN (
  261. SELECT sczl_gdbh, sczl_gxh, SUM(sczl_cl) AS cl
  262. FROM `设备_产量计酬`
  263. GROUP BY sczl_gdbh, sczl_gxh
  264. ) AS b ON a.Gy0_gdbh = b.sczl_gdbh AND (a.Gy0_gxh = b.sczl_gxh OR b.sczl_gxh IS NULL)
  265. WHERE a.Gy0_gdbh = '{$Gd_gdbh}' AND a.Gy0_sbbh != ''
  266. GROUP BY a.Gy0_yjno,a.Gy0_gxh";
  267. $list = Db::query($sql);
  268. if (empty($list)){
  269. $this->success('未找到工序');
  270. }
  271. foreach ($list as $key=>$value){
  272. if ((int)$value['Gy0_yjno'] <10){
  273. $value['Gy0_yjno'] = '0'.rtrim($value['Gy0_yjno']);
  274. }
  275. if ((int)$value['Gy0_gxh'] <10){
  276. $value['Gy0_gxh'] = '0'.rtrim($value['Gy0_gxh']);
  277. }
  278. if (rtrim($value['Add_gxmc']) == ''){
  279. $list[$key]['印件工序及名称'] = $value['Gy0_yjno'].'-'.$value['Gy0_gxh'].'-->'.rtrim($value['Gy0_gxmc']);
  280. }else{
  281. $list[$key]['印件工序及名称'] = $value['Gy0_yjno'].'-'.$value['Gy0_gxh'].'-->'.rtrim($value['Gy0_gxmc']).'【'.rtrim($value['Add_gxmc']).'】';
  282. }
  283. unset($list[$key]['Gy0_gxmc'],$list[$key]['Add_gxmc']);
  284. $list[$key]['机组'] = $value['设备编号'];
  285. $list[$key]['剩余产量'] = (int)$list[$key]['工序产量']-(int)$list[$key]['产量'];
  286. }
  287. $this->success('成功',$list);
  288. }
  289. /**
  290. * 排单页面左侧车间和机台菜单
  291. * @ApiMethod (GET)
  292. * @return \think\response\Json
  293. * @throws \think\db\exception\DataNotFoundException
  294. * @throws \think\db\exception\ModelNotFoundException
  295. * @throws \think\exception\DbException
  296. */
  297. public function workbench()
  298. {
  299. if ($this->request->isGet() === false){
  300. $this->error('请求错误');
  301. }
  302. $param = $this->request->param();
  303. if (isset($param['sort'])){
  304. $where['使用部门'] = '智能车间';
  305. }else{
  306. $where['使用部门'] = ['in',['印刷车间','印后车间']];
  307. }
  308. $data = [];
  309. $department = \db('设备_基本资料')
  310. ->distinct(true)
  311. ->where('使用部门','<>','研发中心')
  312. ->where('设备编组','<>','')
  313. ->where($where)
  314. ->order('设备编组')
  315. ->column('使用部门');
  316. if (empty($department)){
  317. $this->success('为获取到机台数据');
  318. }
  319. foreach ($department as $value){
  320. $benchClass = \db('设备_基本资料')->where('使用部门',$value)->distinct(true)->order('设备编组')->column('设备编组');
  321. foreach ($benchClass as $v){
  322. if (rtrim($v) !== ''){
  323. $machine = \db('设备_基本资料')->where('使用部门',$value)->where('设备编组',$v)->field('rtrim(设备编号) as 设备编号,rtrim(设备名称) as 设备名称')->select();
  324. foreach ($machine as $kk=>$vv){
  325. $data[rtrim($value)][rtrim($v)][$kk] = $vv['设备编号'].'-->'.$vv['设备名称'];
  326. }
  327. }
  328. }
  329. }
  330. $this->success('成功',$data);
  331. }
  332. /**
  333. * 工单状态设置
  334. * @ApiMethod (GET)
  335. * @param string $workOrder 工单编号
  336. * @param string $status 工单状态
  337. * @return void
  338. * @throws \think\Exception
  339. * @throws \think\exception\PDOException
  340. */
  341. public function StatusEdit()
  342. {
  343. if (Request::instance()->isPost() === false){
  344. $this->error('请求错误');
  345. }
  346. $workOrder = input('workOrder');
  347. $status = input('status');
  348. if (empty($workOrder) || empty($status)){
  349. $this->error('参数错误');
  350. }
  351. $sql = \db('工单_基本资料')->where('Gd_gdbh',$workOrder)->fetchSql(true)->update(['gd_statu'=>$status]);
  352. $res = Db::query($sql);
  353. if ($res !== false){
  354. $this->success('成功');
  355. }else{
  356. $this->error('失败');
  357. }
  358. }
  359. /**
  360. * 更改工序状态
  361. * @ApiMethod (GET)
  362. * @param void
  363. * @return void
  364. * @throws \think\Exception
  365. * @throws \think\exception\PDOException
  366. */
  367. public function complete()
  368. {
  369. if ($this->request->isGet() === false){
  370. $this->error('请求错误');
  371. }
  372. $data = $this->request->param();
  373. if (empty($data)){
  374. $this->error('参数错误');
  375. }
  376. $where = [
  377. 'Gy0_gdbh' => $data['workOrder'],
  378. 'Gy0_gxh' => $data['processCode']
  379. ];
  380. $sql = \db('工单_工艺资料')->where($where)->fetchSql(true)->update(['PD_WG'=>date('Y-m-d H:i:s',time())]);
  381. $res = Db::query($sql);
  382. if ($res !== false){
  383. $this->success('成功');
  384. }else{
  385. $this->error('失败');
  386. }
  387. }
  388. /**
  389. * 加入排产
  390. * @ApiMethod (POST)
  391. * @param void $data
  392. * @return void
  393. * @throws \think\Exception
  394. * @throws \think\db\exception\DataNotFoundException
  395. * @throws \think\db\exception\ModelNotFoundException
  396. * @throws \think\exception\DbException
  397. * @throws \think\exception\PDOException
  398. */
  399. public function ProductionSchedulingAdd()
  400. {
  401. if (Request::instance()->isPost() === false){
  402. $this->error('请求错误');
  403. }
  404. $data = Request::instance()->post();
  405. if (empty($data)){
  406. $this->error('参数错误');
  407. }
  408. $where = [
  409. 'Gy0_gdbh' => $data['workOrder'],
  410. 'Gy0_sbbh' => ['like','%'.$data['machine'].'%'],
  411. 'Gy0_yjno' => $data['printCode'],
  412. 'Gy0_gxh' => $data['processCode']
  413. ];
  414. $result = \db('工单_工艺资料')->where($where)->field('rtrim(Gy0_sj1) as sj1')->find();
  415. if ($result['sj1'] != '1900-01-01 00:00:00'){
  416. $this->error('该工单已经是制程中');
  417. }
  418. $lastTime = \db('工单_工艺资料')
  419. ->where(['Gy0_sbbh'=>$where['Gy0_sbbh'],'Gy0_sj2'=>['<>','1900-01-01 00:00:00'],'Gy0_sj2'=>['<','2099-01-01 00:00:00']])
  420. ->field('rtrim(Gy0_sj2) as sj2')
  421. ->order('Gy0_sj2 desc')
  422. ->find();
  423. $date = date('Y-m-d H:i:s',time());
  424. if ($lastTime['sj2'] < $date){
  425. $newTime = $date;
  426. }else{
  427. $newTime = $lastTime['sj2'];
  428. }
  429. $row = \db('工单_工艺资料')
  430. ->where($where)
  431. ->field('rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_小时产能) as 小时产能,rtrim(Gy0_辅助工时) as 辅助工时')
  432. ->find();
  433. if (empty($row)){
  434. $this->success('未找到该工单工艺资料');
  435. }
  436. $endTime = date('Y-m-d H:i:s',strtotime($newTime) + ((int)round($row['计划接货数']/$row['小时产能'])+(int)$row['辅助工时'])*3600);
  437. $sql = \db('工单_工艺资料')
  438. ->where($where)
  439. ->fetchSql(true)
  440. ->update(['Gy0_sj1'=>$newTime,'Gy0_sj2'=>$endTime,'Mod_rq'=>date('Y-m-d H:i:s',time())]);
  441. $res = Db::query($sql);
  442. if ($res !== false){
  443. $this->success('成功');
  444. }else{
  445. $this->error('失败');
  446. }
  447. }
  448. /**
  449. * 暂停排产
  450. * @ApiMethod (POST)
  451. * @param void $data
  452. * @return void
  453. * @throws \think\Exception
  454. * @throws \think\db\exception\DataNotFoundException
  455. * @throws \think\db\exception\ModelNotFoundException
  456. * @throws \think\exception\DbException
  457. * @throws \think\exception\PDOException
  458. */
  459. public function ProductionSchedulingPause()
  460. {
  461. if (Request::instance()->isPost() === false){
  462. $this->error('请求错误');
  463. }
  464. $data = Request::instance()->post();
  465. if (empty($data)){
  466. $this->error('参数错误');
  467. }
  468. $where = [
  469. 'Gy0_gdbh' => $data['workOrder'],
  470. 'Gy0_sbbh' => ['like','%'.$data['machine'].'%'],
  471. 'Gy0_yjno' => $data['printCode'],
  472. 'Gy0_gxh' => $data['processCode']
  473. ];
  474. $machine = $data['machine'];
  475. $endTime = \db('工单_工艺资料')->where($where)->field('rtrim(Gy0_sj2) as sj2,rtrim(PD_WG) as wg')->find();
  476. if (empty($endTime)){
  477. $this->success('未找到该工序');
  478. }
  479. $time = $endTime['sj2'];
  480. if ($endTime['sj2'] == '1900-01-01 00:00:00' || $endTime['wg'] != '1900-01-01 00:00:00'){
  481. $this->error('该工单不是制程中工单');
  482. }
  483. $sql = \db('工单_工艺资料')
  484. ->where($where)
  485. ->fetchSql(true)
  486. ->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')]);
  487. $row = \db('工单_工艺资料')
  488. ->where($where)
  489. ->field('rtrim(Gy0_计划接货数) as 计划接货数,rtrim(Gy0_小时产能) as 小时产能,rtrim(Gy0_辅助工时) as 辅助工时')
  490. ->find();
  491. if (empty($row)){
  492. $this->success('未找到该工序');
  493. }
  494. $number = -(int)round($row['计划接货数']/$row['小时产能'])+(int)$row['辅助工时'];
  495. $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'";
  496. $rechres = Db::query($rechSql);
  497. $res = Db::query($sql);
  498. if ($res !== false && $rechres !== false){
  499. $this->success('成功');
  500. }else{
  501. $this->error('失败');
  502. }
  503. }
  504. /**
  505. * 工序状态更正
  506. * @ApiMethod (GET)
  507. * @param void $param
  508. * @return void
  509. * @throws \think\db\exception\DataNotFoundException
  510. * @throws \think\db\exception\ModelNotFoundException
  511. * @throws \think\exception\DbException
  512. */
  513. public function ProcessStatusCorrection()
  514. {
  515. if ($this->request->isGet() === false){
  516. $this->error('请求错误');
  517. }
  518. $param = $this->request->param();
  519. if (empty($param)){
  520. $this->error('参数错误');
  521. }
  522. $where = [
  523. 'Gy0_gdbh' => $param['workOrder'],
  524. ];
  525. $workOrder = $where['Gy0_gdbh'];
  526. $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';
  527. $list = \db('工单_工艺资料')->where($where)->field($field)->order('Gy0_yjno,Gy0_gxh')->select();
  528. if (empty($list)){
  529. $this->success('未找到该工单工艺资料');
  530. }
  531. $yieldSql = "SELECT
  532. a.Gy0_yjno AS yjno,
  533. a.Gy0_gxh AS gxh,
  534. SUM( b.sczl_cl ) AS cl
  535. FROM
  536. `工单_工艺资料` AS a
  537. JOIN `设备_产量计酬` AS b ON a.Gy0_gxh = b.sczl_gxh AND a.Gy0_yjno = b.sczl_yjno
  538. WHERE
  539. a.Gy0_gdbh = '{$workOrder}'
  540. GROUP BY
  541. a.Gy0_yjno,a.Gy0_gxh";
  542. $yield = Db::query($yieldSql);
  543. foreach ($list as $key=>$value){
  544. if ($value['yjno']<10){
  545. $value['yjno'] = '0'.$value['yjno'];
  546. }
  547. if ($value['gxh']<10){
  548. $value['gxh'] = '0'.$value['gxh'];
  549. }
  550. $list[$key]['印件及工序'] = $value['yjno'].'-'.$value['gxh'].'-->'.$value['gxmc'];
  551. foreach ($yield as $k=>$v){
  552. if ($v['yjno'] === $list[$key]['yjno']) {
  553. if ($v['gxh'] === $list[$key]['gxh']){
  554. $list[$key]['计划产量/已完成'] = (int)$value['计划接货数'] . '/' . $v['cl'];
  555. if ($value['计划接货数'] !== 0 && $value['计划接货数'] !== '' && !empty($value['计划接货数'])) {
  556. $num = (float)number_format(intval($v['cl']) / intval($value['计划接货数']), 4);
  557. $list[$key]['完成率'] = $num * 100 . '%';
  558. } else {
  559. $list[$key]['完成率'] = '';
  560. }
  561. }else{
  562. $list[$key]['计划产量/已完成'] = $value['计划接货数'].'/0';
  563. $list[$key]['完成率'] = '';
  564. }
  565. }
  566. }
  567. if ($value['完工时间'] == '1900-01-01 00:00:00') {
  568. $list[$key]['完工时间'] = '';
  569. }
  570. unset($list[$key]['yjno'],$list[$key]['gxh'],$list[$key]['gxmc'],$list[$key]['计划接货数'],$list[$key]['ls']);
  571. }
  572. $this->success('成功',$list);
  573. }
  574. /**
  575. * 工序状态更正->工序状态编辑
  576. * @ApiMethod (POST)
  577. * @param void
  578. * @return void
  579. * @throws \think\Exception
  580. * @throws \think\exception\PDOException
  581. */
  582. public function ProcessStatusCorrectionEdit()
  583. {
  584. if (Request::instance()->isPost() === false){
  585. $this->error('请求错误');
  586. }
  587. $param = Request::instance()->post();
  588. if (empty($param)){
  589. $this->error('参数错误');
  590. }
  591. $i = 0;
  592. foreach ($param as $key=>$value){
  593. if ($value['PD_WG'] === null || $value['PD_WG'] === ''){
  594. $endTime = '1900-01-01 00:00:00';
  595. }else{
  596. $endTime = $value['PD_WG'];
  597. }
  598. $sql = \db('工单_工艺资料')
  599. ->where('UniqId',$value['UniqId'])
  600. ->fetchSql(true)
  601. ->update(['PD_WG'=>$endTime]);
  602. $res = Db::query($sql);
  603. if ($res !== false){
  604. $i++;
  605. }
  606. }
  607. if ($i !== 0){
  608. $this->success('成功');
  609. }else{
  610. $this->error('失败');
  611. }
  612. }
  613. /**
  614. * 班次选择
  615. * @ApiMethod (GET)
  616. * @return void
  617. * @throws \think\db\exception\DataNotFoundException
  618. * @throws \think\db\exception\ModelNotFoundException
  619. * @throws \think\exception\DbException
  620. */
  621. public function ScheduleSelection()
  622. {
  623. if ($this->request->isGet() === false){
  624. $this->error('请求错误');
  625. }
  626. $list = \db('工单_排程班次')->field('rtrim(bcdh) as 班次代号,rtrim(desc_) as desc_,rtrim(stdtime) as stdtime')->select();
  627. if (empty($list)){
  628. $this->success('未找到班次数据');
  629. }
  630. foreach ($list as $key=>$value){
  631. $list[$key]['detail'] = $value['班次代号'].'||'.$value['desc_'].'||'.$value['stdtime'];
  632. unset($list[$key]['desc_'],$list[$key]['stdtime']);
  633. }
  634. $this->success('成功',$list);
  635. }
  636. /**
  637. * 车间设备制程展示
  638. * @ApiMethod (GET)
  639. * @param void $param
  640. * @return void
  641. * @throws \think\db\exception\DataNotFoundException
  642. * @throws \think\db\exception\ModelNotFoundException
  643. * @throws \think\exception\DbException
  644. */
  645. public function EquipmentScheduling()
  646. {
  647. if ($this->request->isGet() === false){
  648. $this->error('参数错误');
  649. }
  650. $param = $this->request->param();
  651. if (empty($param)){
  652. $this->error('参数错误');
  653. }
  654. $machine = $param['machine'];
  655. $list = \db('工单_基本资料')
  656. ->alias('a')
  657. ->field([
  658. 'rtrim(b.Gy0_gdbh)' => '工单编号',
  659. 'rtrim(b.Gy0_计划接货数)' => '计划接货数',
  660. 'rtrim(b.Gy0_小时产能)' => '小时产能',
  661. 'rtrim(b.Gy0_生产工时)' => '生产工时',
  662. 'rtrim(b.Gy0_辅助工时)' => '辅助工时',
  663. 'rtrim(b.Gy0_班次安排)' => '班次安排',
  664. 'rtrim(b.工序备注)' => '排单备注',
  665. 'rtrim(b.Gy0_最早开工时间)' => '最早开工时间',
  666. 'rtrim(b.Gy0_sj1)' => '计划开工时间',
  667. 'rtrim(b.Gy0_sj2)' => '计划完工时间',
  668. 'rtrim(b.Gy0_yjno)' => 'yjno',
  669. 'rtrim(b.Gy0_gxh)' => 'gxh',
  670. 'rtrim(b.Gy0_gxmc)' => 'gxmc',
  671. 'rtrim(b.Gy0_ls)' => 'ls',
  672. 'rtrim(b.UniqId)' => 'UniqId',
  673. 'SUM(c.sczl_cl)' => '已完成'
  674. ])
  675. ->join('工单_工艺资料 b','a.Gd_gdbh = b.Gy0_gdbh')
  676. ->join('设备_产量计酬 c','a.Gd_gdbh = c.sczl_gdbh AND b.Gy0_yjno = c.sczl_yjno AND b.Gy0_gxh = c.sczl_gxh','LEFT')
  677. ->where([
  678. 'b.Gy0_sbbh' => $machine,
  679. 'b.Gy0_sj1' => ['>','1900-01-01 00:00:00'],
  680. 'b.PD_WG' => '1900-01-01 00:00:00',
  681. 'a.gd_statu' => '2-生产中'
  682. ])
  683. ->where('b.Gy0_sj1','<','2099-01-01 00:00:00')
  684. ->group('a.Gd_gdbh')
  685. ->select();
  686. foreach ($list as $key=>$value){
  687. $list[$key]['计划接货数'] = (int)round($value['计划接货数']/$value['ls']);
  688. if ($value['yjno']<10){
  689. $value['yjno'] = '0'.$value['yjno'];
  690. }
  691. if ($value['gxh']<10){
  692. $value['gxh'] = '0'.$value['gxh'];
  693. }
  694. $list[$key]['印件/工序'] = $value['yjno'].'-'.$value['gxh'].'-'.$value['gxmc'];
  695. unset($list[$key]['yjno'],$list[$key]['gxh'],$list[$key]['gxmc'],$list[$key]['ls']);
  696. }
  697. $this->success('成功',$list);
  698. }
  699. /**
  700. * 车间设备排程编辑
  701. * @ApiMethod (POST)
  702. * @param void $param
  703. * @return void
  704. * @throws \think\Exception
  705. * @throws \think\exception\PDOException
  706. */
  707. public function EquipmentSchedulingEdit()
  708. {
  709. if (Request::instance()->isPost() === false){
  710. $this->error('请求错误');
  711. }
  712. $param = Request::instance()->post();
  713. if (empty($param)){
  714. $this->error('参数错误');
  715. }
  716. $i = 0;
  717. foreach ($param as $key=>$value){
  718. $data = [
  719. 'Gy0_小时产能' => $value['capacity'],
  720. 'Gy0_生产工时' => $value['ProductionHours'],
  721. 'Gy0_辅助工时' => $value['AuxiliaryHours'],
  722. 'Gy0_班次安排' => $value['shift'],
  723. '工序备注' => $value['remark'],
  724. 'Gy0_最早开工时间' => $value['start'] === ''?'1900-01-01 00:00:00':date('Y-m-d H:i:s',strtotime($value['start'])),
  725. 'Gy0_sj1' => date('Y-m-d H:i:s',strtotime($value['projectTime'])),
  726. // 'Gy0_sj2' => date('Y-m-d H:i:s',strtotime($value['projectTime'])+(ceil($value['ProductionHours'])+ceil($value['AuxiliaryHours']))*3600),
  727. 'Gy0_sj2' => date('Y-m-d H:i:s',strtotime($value['endTime'])),
  728. ];
  729. $sql = \db('工单_工艺资料')
  730. ->where('UniqId',$value['UniqId'])
  731. ->fetchSql(true)
  732. ->update($data);
  733. $res = Db::query($sql);
  734. if ($res !== false){
  735. $i++;
  736. }
  737. }
  738. if ($i !== 0){
  739. $this->success('成功');
  740. }else{
  741. $this->error('失败');
  742. }
  743. }
  744. /**
  745. * 机台工单展示
  746. * @ApiMethod ()
  747. * @return void
  748. * @throws \think\db\exception\BindParamException
  749. * @throws \think\exception\PDOException
  750. */
  751. public function MachineWorkOrderList()
  752. {
  753. if ($this->request->isGet() === false){
  754. $this->error('请求失败');
  755. }
  756. $param = $this->request->param();
  757. if (empty($param)){
  758. $this->error('参数错误');
  759. }
  760. $where = '';
  761. if (isset($param['search'])){
  762. $where = "
  763. b.Gd_gdbh LIKE '%{$param['search']}%'
  764. OR b.`成品名称` LIKE '%{$param['search']}%'
  765. ";
  766. }
  767. $list = \db('工单_工艺资料')
  768. ->alias('a')
  769. ->field([
  770. 'RTRIM( a.Gy0_yjno )' =>'yjno',
  771. 'RTRIM( a.Gy0_gxh )' => 'gxh',
  772. 'RTRIM( a.Gy0_gxmc )' => 'gxmc',
  773. 'RTRIM( a.Add_gxmc )' => 'Add_gxmc',
  774. 'RTRIM( c.yj_yjmc )' => '印件名称',
  775. 'RTRIM( a.`Gy0_计划接货数` )' => '计划接货数',
  776. 'RTRIM( a.`Gy0_小时产能` )' => '小时产能',
  777. 'RTRIM( a.`工价系数` )' => '产能系数',
  778. 'RTRIM( a.`Gy0_生产工时` )' => '生产工时',
  779. 'RTRIM( a.Gy0_ls )' => 'ls',
  780. 'RTRIM( a.`Gy0_辅助工时` )' => '辅助工时',
  781. 'RTRIM( a.`Gy0_最早开工时间` )' => '最早开工时间',
  782. 'RTRIM( a.Gy0_sj1 )' => '计划开工时间',
  783. 'RTRIM( a.Gy0_sj2 )' => '计划完工时间',
  784. 'RTRIM( a.`Gy0_班次安排` )' => '班次安排',
  785. 'RTRIM( a.`工序备注` )' => '排单备注',
  786. 'RTRIM( b.Gd_cpmc )' => '产品名称',
  787. 'RTRIM( b.`成品名称` )' => '成品名称',
  788. 'RTRIM( b.`订单数量` )' => '订单数量',
  789. 'RTRIM( b.`计量单位` )' => '计量单位',
  790. 'RTRIM( b.`交货日期` )' => '交货日期',
  791. 'RTRIM( b.Gd_cpdh )' => '产品代号',
  792. 'RTRIM( b.`成品代号` )' => '成品代号',
  793. 'RTRIM( a.Gy0_sbbh )' => '设备编号',
  794. 'RTRIM( a.Gy0_SITE )' => '车间名称',
  795. 'RTRIM( a.UniqId )' => 'GYUID',
  796. 'RTRIM( b.Uniqid )' => 'UNIQID',
  797. 'SUM( d.sczl_cl )' => '已完成产量',
  798. 'RTRIM( b.Gd_gdbh )' => '工单编号',
  799. 'RTRIM( b.`销售订单号` )' => '销售订单号',
  800. ])
  801. ->join('工单_印件资料 c','c.Yj_Gdbh = a.Gy0_gdbh AND c.yj_Yjno = a.Gy0_yjno')
  802. ->join('工单_基本资料 b','b.Gd_gdbh = a.Gy0_gdbh')
  803. ->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')
  804. ->where([
  805. 'b.gd_statu' => '2-生产中',
  806. 'a.Gy0_sbbh' => ['LIKE','%'.$param['machine'].'%'],
  807. 'a.PD_WG' => '1900-01-01 00:00:00',
  808. ])
  809. ->where($where)
  810. ->group('a.Gy0_gdbh,a.Gy0_yjno,a.Gy0_gxh')
  811. ->order('Gy0_sj1')
  812. ->select();
  813. if (empty($list)){
  814. $this->success('',[]);
  815. }
  816. $data['制程'] = $data['排程'] = [];
  817. foreach ($list as $key=>$value){
  818. $list[$key]['设备编号'] = $param['machine'];
  819. if ((int)$value['yjno'] <10){
  820. $value['yjno'] = '0'.rtrim($value['yjno']);
  821. }
  822. if ((int)$value['gxh'] <10){
  823. $value['gxh'] = '0'.rtrim($value['gxh']);
  824. }
  825. if (rtrim($value['Add_gxmc']) == ''){
  826. $list[$key]['印件工序及名称'] = $value['yjno'].'-'.$value['gxh'].'-->'.rtrim($value['gxmc']);
  827. }else{
  828. $list[$key]['印件工序及名称'] = $value['yjno'].'-'.$value['gxh'].'-->'.rtrim($value['gxmc']).'【'.rtrim($value['Add_gxmc']).'】';
  829. }
  830. unset($list[$key]['Add_gxmc']);
  831. if ($value['产品名称'] == ''){
  832. $list[$key]['产品名称'] = $value['成品名称'];
  833. }
  834. if ($value['产品代号'] == ''){
  835. $list[$key]['产品代号'] = $value['成品代号'];
  836. }
  837. unset($list[$key]['成品代号'],$list[$key]['成品名称']);
  838. if ($list[$key]['计划开工时间'] !== '1900-01-01 00:00:00'){
  839. array_push($data['制程'],$list[$key]);
  840. }else{
  841. array_push($data['排程'],$list[$key]);
  842. }
  843. }
  844. $this->success('成功',$data);
  845. }
  846. /**
  847. * 机组调整
  848. * @return void
  849. * @throws \think\Exception
  850. * @throws \think\db\exception\BindParamException
  851. * @throws \think\exception\PDOException
  852. */
  853. public function MachineTeamEdit()
  854. {
  855. if ($this->request->isGet() === false){
  856. $this->error('请求错误');
  857. }
  858. $param = $this->request->param();
  859. if (empty($param) || isset($param['UniqId']) === false){
  860. $this->error('参数错误');
  861. }
  862. $sql = \db('工单_工艺资料')
  863. ->where('UniqId',$param['UniqId'])
  864. ->fetchSql(true)
  865. ->update(['Gy0_sbbh'=>$param['machine']]);
  866. $res = \db()->query($sql);
  867. if ($res !== false){
  868. $this->success('修改成功');
  869. }else{
  870. $this->error('修改失败');
  871. }
  872. }
  873. /**
  874. * 子订单领料派单
  875. */
  876. public function processAdd()
  877. {
  878. if (Request::instance()->post() === false){
  879. $this->error('参数错误');
  880. }
  881. $param = Request::instance()->post();
  882. if (empty($param)){
  883. $this->error('参数错误');
  884. }
  885. $data['班组编号'] = $param['班组'];
  886. $data['订单编号'] = $param['订单编号'];
  887. $data['子订单编号'] = $param['子订单编号'];
  888. $data['sys_id'] = $param['Sys_id'];
  889. $data['sys_rq'] = date('Y-m-d H:i:s',time());
  890. $sql = \db('工单_排程班次')->fetchSql(true)->insert($data);
  891. $res = \db()->query($sql);
  892. if ($res !== false){
  893. $this->success('成功');
  894. }else{
  895. $this->error('失败');
  896. }
  897. }
  898. /**
  899. * 月度车间报工汇总-菜单显示
  900. */
  901. public function MachineList() {
  902. // 检查请求是否为 GET
  903. if (!$this->request->isGet()) {
  904. $this->error('请求错误');
  905. }
  906. // 定义要查询的生产工序及排序顺序
  907. $processList = ['裁剪', '车缝', '手工', '大烫', '总检', '包装'];
  908. // 查询所有数据
  909. $results = \db('设备_产量计酬')
  910. ->alias('a')
  911. ->join('设备_基本资料 b', 'a.sczl_jtbh = b.设备编号')
  912. ->field([
  913. 'DATE_FORMAT(a.sczl_rq, "%Y-%m-%d")' => '时间', // 转化为 "YYYY-MM-DD" 格式
  914. 'DATE_FORMAT(a.sczl_rq, "%Y-%m")' => '年月', // 转化为 "YYYY-MM" 格式
  915. 'RTRIM(a.sczl_jtbh)' => '机台编号',
  916. 'b.设备编号',
  917. 'b.设备编组',
  918. 'b.生产工序'
  919. ])
  920. ->whereNull('a.mod_rq') // 筛选无修改日期的数据
  921. ->whereIn('b.生产工序', $processList) // 筛选指定的生产工序
  922. ->order('a.sczl_rq ASC') // 按时间升序排序
  923. ->select();
  924. // 初始化按年月分组的结果
  925. $formattedData = [];
  926. // 遍历查询结果并分组
  927. foreach ($results as $row) {
  928. $yearMonth = $row['年月']; // 获取年月 "YYYY-MM"
  929. $monthDay = $row['时间']; // 获取月份和日期 "MM-DD"
  930. // $monthDay = substr($row['时间'], 0, 5); // 获取月份和日期 "MM-DD"
  931. $process = $row['生产工序'];
  932. $machineKey = $row['设备编号'] . '--' . $row['设备编组'];
  933. // 初始化年份和工序结构
  934. if (!isset($formattedData[$yearMonth])) {
  935. $formattedData[$yearMonth] = array_fill_keys($processList, []); // 初始化月份,所有工序为空数组
  936. }
  937. if (!isset($formattedData[$yearMonth][$process][$machineKey])) {
  938. $formattedData[$yearMonth][$process][$machineKey] = [];
  939. }
  940. // 添加日期,避免重复
  941. if (!in_array($monthDay, $formattedData[$yearMonth][$process][$machineKey])) {
  942. $formattedData[$yearMonth][$process][$machineKey][] = $monthDay;
  943. }
  944. }
  945. // 对年份和月份进行排序(按年月降序排序)
  946. krsort($formattedData);
  947. // 按生产工序排序
  948. foreach ($formattedData as $yearMonth => &$processData) {
  949. // 1. 确保每个月的工序顺序符合 $processList(即使为空也保留顺序)
  950. $sortedProcessData = array_fill_keys($processList, []);
  951. // 将原有数据合并到排序后的结构中
  952. $processData = array_merge($sortedProcessData, $processData);
  953. // 2. 对每个工序下的设备组进行日期倒序排序
  954. foreach ($processData as $process => &$machines) {
  955. if (is_array($machines)) { // 确保 $machines 是数组
  956. foreach ($machines as $machineKey => &$dates) {
  957. if (is_array($dates) && !empty($dates)) { // 确保 $dates 存在并且是非空数组
  958. rsort($dates); // 每台设备的日期倒序排序
  959. }
  960. }
  961. }
  962. }
  963. }
  964. $this->success('成功', $formattedData);
  965. }
  966. /**
  967. * 月度车间报工汇总-列表详情数据
  968. */
  969. public function MachineDetail()
  970. {
  971. if ($this->request->isGet() === false) {
  972. $this->error('请求错误');
  973. }
  974. $param = $this->request->param();
  975. if (empty($param)) {
  976. $this->error('参数错误');
  977. }
  978. $where = [];
  979. // 获取当前年份
  980. $currentYear = date('Y');
  981. // 处理日期参数(可选)
  982. if (!empty($param['date'])) {
  983. // 日期参数的格式处理
  984. $where['a.sys_rq'] = ['like', "%{$param['date']}%"];
  985. }
  986. // 订单编号筛选
  987. if (!empty($param['order'])) {
  988. $where['b.订单编号|a.款号|b.子订单编号'] = ['like', '%' . $param['order'] . '%'];
  989. }
  990. // 机台号筛选
  991. if (!empty($param['machine'])) {
  992. // 针对机台号的特定条件判断
  993. $machineMapping = [
  994. '裁剪' => 'CQ', '车缝' => 'CF', '手工' => 'HD',
  995. '大烫' => 'DT', '总检' => 'ZJ', '包装' => 'BZ'
  996. ];
  997. if (isset($machineMapping[$param['machine']])) {
  998. $where['a.sczl_jtbh'] = ['like', '%' . $machineMapping[$param['machine']] . '%'];
  999. } elseif (preg_match('/^\d{4}-\d{2}$/', $param['machine'])) {
  1000. $where['a.sczl_jtbh'] = ''; // 若为日期格式,清空该字段
  1001. } else {
  1002. $where['a.sczl_jtbh'] = $param['machine'];
  1003. }
  1004. }
  1005. // 查询数据
  1006. $offset = ($param['page'] - 1) * $param['limit'];
  1007. $list = \db('设备_产量计酬')->alias('a')
  1008. ->join('工单_印件资料 b', 'b.订单编号 = a.订单编号 AND a.子订单编号 = b.子订单编号')
  1009. ->join('工单_基本资料 j', 'b.订单编号 = j.订单编号', 'LEFT')
  1010. ->field('
  1011. a.工序名称,a.sczl_bh,a.订单编号, a.子订单编号, b.款号, b.颜色, b.船样, a.尺码, b.zdtotal as 制单数, b.颜色备注,
  1012. CASE
  1013. WHEN a.工序名称 IN ("裁剪", "车缝") THEN a.数量
  1014. ELSE a.s_num
  1015. END as 数量,
  1016. MIN(a.sys_rq) as 上报时间, a.UniqId,
  1017. j.客户编号, j.生产款号, j.款式
  1018. ')
  1019. ->where($where)
  1020. ->where('a.mod_rq', null)
  1021. ->order('a.sys_rq desc, a.UniqId desc')
  1022. ->limit($offset, $param['limit'])
  1023. ->group('a.UniqId')
  1024. ->select();
  1025. $count = \db('设备_产量计酬')->alias('a')
  1026. ->join('工单_印件资料 b', 'b.订单编号 = a.订单编号 AND a.子订单编号 = a.子订单编号')
  1027. ->join('工单_基本资料 j', 'b.订单编号 = j.订单编号', 'LEFT')
  1028. ->field('
  1029. a.工序名称,a.sczl_bh,b.订单编号, b.子订单编号, b.款号, b.颜色, b.船样, a.尺码, b.zdtotal as 制单数, b.颜色备注,
  1030. CASE
  1031. WHEN a.工序名称 IN ("裁剪", "车缝") THEN a.数量
  1032. ELSE a.s_num
  1033. END as 数量,
  1034. MIN(a.sys_rq) as 上报时间, a.UniqId,
  1035. j.客户编号, j.生产款号, j.款式
  1036. ')
  1037. ->where($where)
  1038. ->where('a.mod_rq', null)
  1039. ->order('a.sys_rq desc, a.UniqId desc')
  1040. ->group('a.UniqId')
  1041. ->select();
  1042. // 提取所有的尺码,并去重,去除空格
  1043. $sizeList = array_values(array_unique(array_map('trim', array_column($list, '尺码'))));
  1044. // 自定义排序规则(已存在的排序逻辑)
  1045. $sizeOrder = ['XXS', 'XS', 'S', 'M', 'L', 'XL', 'XXL', 'XXXL', 'XXXXL'];
  1046. usort($sizeList, function ($a, $b) use ($sizeOrder) {
  1047. // 数字优先比较
  1048. if (is_numeric($a) && is_numeric($b)) {
  1049. return $a - $b;
  1050. }
  1051. if (in_array($a, $sizeOrder) && in_array($b, $sizeOrder)) {
  1052. return array_search($a, $sizeOrder) - array_search($b, $sizeOrder);
  1053. }
  1054. if (is_numeric($a)) return -1;
  1055. if (is_numeric($b)) return 1;
  1056. return strcmp($a, $b);
  1057. });
  1058. // 动态将尺码的数量添加到每个订单中,并替换已完成字段
  1059. foreach ($list as &$item) {
  1060. $size = $item['尺码'];
  1061. $item[$size] = $item['数量'];
  1062. }
  1063. // 返回结果
  1064. $this->success('请求成功', [
  1065. 'table' => $list,
  1066. 'length' => count($count),
  1067. 'headers' => $sizeList // 返回所有的尺码作为表头
  1068. ]);
  1069. }
  1070. /**
  1071. * 样衣核批
  1072. */
  1073. public function Approval(){
  1074. if ($this->request->isPost() === false) {
  1075. $this->error('请求错误');
  1076. }
  1077. $param = Request::instance()->post();
  1078. if (empty($param)) {
  1079. $this->error('参数错误');
  1080. }
  1081. // 判断Uniqid是否为多个,多个以逗号分隔
  1082. $uniqids = strpos($param['Uniqid'], ',') !== false ? explode(',', $param['Uniqid']) : [$param['Uniqid']];
  1083. if (!empty($param['rq'])) {
  1084. // 准备更新数据
  1085. $data = [
  1086. '审核日期' => $param['rq'],
  1087. '审核' => $param['sys_id'],
  1088. ];
  1089. }else{
  1090. // 准备更新数据
  1091. $data = [
  1092. '审核日期' => date('Y-m-d H:i:s'),
  1093. '审核' => $param['sys_id'],
  1094. ];
  1095. }
  1096. // 遍历所有Uniqid进行更新
  1097. foreach ($uniqids as $uniqid) {
  1098. $list = \db('工单_基本资料')
  1099. ->where('Uniqid', $uniqid)
  1100. ->fetchSql(true)
  1101. ->update($data);
  1102. $res = \db()->query($list);
  1103. // 如果更新失败,直接返回错误
  1104. if ($res === false) {
  1105. $this->error('审核失败');
  1106. }
  1107. }
  1108. // 所有更新操作都成功时,返回成功
  1109. $this->success('审核成功');
  1110. }
  1111. /**
  1112. * 订单状态及样衣批核
  1113. */
  1114. public function UnapprovalList()
  1115. {
  1116. if ($this->request->isGet() === false) {
  1117. $this->error('请求错误');
  1118. }
  1119. $param = $this->request->param();
  1120. // 设置查询条件
  1121. $where = [
  1122. 'Mod_rq' => null,
  1123. '订单编号|生产款号' => ['like', '%' . $param['search'] . '%'],
  1124. ];
  1125. $page = isset($param['page']) ? $param['page'] : 1;
  1126. $limit = isset($param['limit']) ? $param['limit'] : 20;
  1127. // 获取工单列表
  1128. $list = \db('工单_基本资料')
  1129. ->where($where)
  1130. ->order('订单编号 desc')
  1131. ->limit(($page - 1) * $limit, $limit)
  1132. ->select();
  1133. // 获取总记录数
  1134. $count = \db('工单_基本资料')
  1135. ->where($where)
  1136. ->count(); // 使用 count() 方法优化
  1137. $orderIds = array_column($list, '订单编号');
  1138. // 合并查询相关附件
  1139. $relatedOrders = \db('工单_相关附件')
  1140. ->whereIn('关联编号', $orderIds)
  1141. ->whereIn('附件备注', ['技术附件', '订单资料附件'])
  1142. ->column('关联编号,附件备注');
  1143. // 重新组织附件数据
  1144. $groupedRelatedOrders = [
  1145. 'technical' => [],
  1146. 'order' => []
  1147. ];
  1148. foreach ($relatedOrders as $orderNumber => $attachmentRemark) {
  1149. if ($attachmentRemark === '技术附件') {
  1150. $groupedRelatedOrders['technical'][] = $orderNumber;
  1151. } elseif ($attachmentRemark === '订单资料附件') {
  1152. $groupedRelatedOrders['order'][] = $orderNumber;
  1153. }
  1154. }
  1155. // 遍历工单列表并设置状态
  1156. foreach ($list as &$value) {
  1157. // 设置订单状态
  1158. $value['status'] = in_array($value['订单编号'], $groupedRelatedOrders['technical']) ? '' : '*';
  1159. $value['orderstatus'] = in_array($value['订单编号'], $groupedRelatedOrders['order']) ? '' : '*';
  1160. // 定义工序编号数组
  1161. $processIds = [
  1162. 2 => '裁剪完工数量',
  1163. 3 => '车缝完工数量',
  1164. 4 => '手工完工数量',
  1165. 5 => '大烫完工数量',
  1166. 6 => '总检完工数量',
  1167. 7 => '工单完工数量'
  1168. ];
  1169. // 遍历工序编号,获取对应的完工数量
  1170. foreach ($processIds as $processId => $fieldName) {
  1171. if ($processId === 2 || $processId === 3) {
  1172. // 查询所有记录
  1173. $records = \db('设备_产量计酬')
  1174. ->where('订单编号', $value['订单编号'])
  1175. ->where('工序编号', $processId)
  1176. ->select(); // 获取所有匹配记录
  1177. // 计算数量总和
  1178. $num_sum = 0;
  1179. foreach ($records as $record) {
  1180. $num_sum += $record['数量']; // 手动累加数量
  1181. }
  1182. $value[$fieldName] = $num_sum; // 裁剪和车缝存储数量
  1183. } else {
  1184. // 其他工序是 s_num,总和计算
  1185. $s_num_sum = \db('设备_产量计酬')
  1186. ->where('订单编号', $value['订单编号'])
  1187. ->where('工序编号', $processId)
  1188. ->sum('s_num'); // 继续使用 s_num 字段
  1189. $value[$fieldName] = $s_num_sum; // 其他工序存储 s_num 总和
  1190. }
  1191. }
  1192. if ($value['落货日期']) {
  1193. $value['落货日期'] = date('Y-m-d', strtotime($value['落货日期']));
  1194. }
  1195. // 格式化接单日期,去掉时间部分
  1196. if ($value['接单日期']) {
  1197. $value['接单日期'] = date('Y-m-d', strtotime($value['接单日期']));
  1198. }
  1199. }
  1200. // 返回数据
  1201. $data = [
  1202. 'total' => $count,
  1203. 'table' => $list,
  1204. ];
  1205. $this->success('成功', $data);
  1206. }
  1207. /**
  1208. * 出货大货报表:辅料计划入库时间 / 计划生产小组(同一入口,按参数区分)
  1209. * 辅料计划入库时间:Uniqid + rq + sys_id
  1210. * 计划生产小组: Uniqid + 计划生产小组 + sys_id(不传 rq)
  1211. */
  1212. public function AccessoriesInboundTime()
  1213. {
  1214. if (!$this->request->isPost()) {
  1215. return $this->error('请求错误');
  1216. }
  1217. $param = $this->request->post();
  1218. // 必传参数
  1219. if (empty($param['Uniqid']) || empty($param['sys_id'])) {
  1220. return $this->error('参数错误');
  1221. }
  1222. $uniqids = strpos($param['Uniqid'], ',') !== false
  1223. ? explode(',', $param['Uniqid'])
  1224. : [$param['Uniqid']];
  1225. // ===================== 最简逻辑 =====================
  1226. // 有 rq → 更新时间
  1227. if (!empty($param['rq'])) {
  1228. $data = [
  1229. '辅料计划入库时间' => trim($param['rq']),
  1230. '辅料计划入库操作人' => $param['sys_id'],
  1231. ];
  1232. }
  1233. // 没有 rq → 更新小组
  1234. else {
  1235. $data = [
  1236. '计划生产小组' => trim($param['计划生产小组'] ?? ''),
  1237. '计划生产小组操作人' => $param['sys_id'],
  1238. '计划生产小组时间' => date('Y-m-d H:i:s'),
  1239. ];
  1240. }
  1241. foreach ($uniqids as $uniqid) {
  1242. $uniqid = trim($uniqid);
  1243. if ($uniqid) {
  1244. $list = \db('工单_基本资料')
  1245. ->where('Uniqid', $uniqid)
  1246. ->fetchSql(true)
  1247. ->update($data);
  1248. $res = \db()->query($list);
  1249. if ($res === false) {
  1250. $this->error('操作失败');
  1251. }
  1252. }
  1253. }
  1254. return $this->success('操作成功');
  1255. }
  1256. // /**
  1257. // * 辅料计划入库时间更新
  1258. // */
  1259. // public function AccessoriesInboundTime(){
  1260. // if ($this->request->isPost() === false) {
  1261. // $this->error('请求错误');
  1262. // }
  1263. // $param = Request::instance()->post();
  1264. // if (empty($param)) {
  1265. // $this->error('参数错误');
  1266. // }
  1267. // // 判断Uniqid是否为多个,多个以逗号分隔
  1268. // $uniqids = strpos($param['Uniqid'], ',') !== false ? explode(',', $param['Uniqid']) : [$param['Uniqid']];
  1269. //
  1270. // if (!empty($param['rq'])) {
  1271. // // 准备更新数据
  1272. // $data = [
  1273. // '辅料计划入库时间' => $param['rq'],
  1274. // '辅料计划入库操作人' => $param['sys_id'],
  1275. // ];
  1276. // }else{
  1277. // // 准备更新数据
  1278. // $data = [
  1279. // '辅料计划入库时间' => date('Y-m-d H:i:s'),
  1280. // '辅料计划入库操作人' => $param['sys_id'],
  1281. // ];
  1282. // }
  1283. // // 遍历所有Uniqid进行更新
  1284. // foreach ($uniqids as $uniqid) {
  1285. // $list = \db('工单_基本资料')
  1286. // ->where('Uniqid', $uniqid)
  1287. // ->fetchSql(true)
  1288. // ->update($data);
  1289. // $res = \db()->query($list);
  1290. // // 如果更新失败,直接返回错误
  1291. // if ($res === false) {
  1292. // $this->error('更新辅料计划入库时间失败');
  1293. // }
  1294. // }
  1295. // // 所有更新操作都成功时,返回成功
  1296. // $this->success('更新成功');
  1297. // }
  1298. /**
  1299. * 月度客户订单汇总
  1300. */
  1301. public function OrderYieldList(){
  1302. // 获取前端传来的参数
  1303. $param = $this->request->param();
  1304. // 初始化查询条件
  1305. $where = [];
  1306. // 处理搜索条件
  1307. if (isset($param['search']) && !empty($param['search'])) {
  1308. $where['j.订单编号|j.生产款号'] = ['like', '%' . $param['search'] . '%'];
  1309. }
  1310. if (isset($param['client']) && !empty($param['client'])) {
  1311. $where['j.客户编号'] = $param['client'];
  1312. }
  1313. if (isset($param['date']) && !empty($param['date'])) {
  1314. $year = substr($param['date'], 0, 4);
  1315. $month = substr($param['date'], 4, 2);
  1316. $where['j.Sys_rq'] = ['like', "$year-$month%"];
  1317. }
  1318. // 只查询生产中的工单
  1319. // $where['j.gd_statu'] = '2-生产中';
  1320. $where['j.Mod_rq'] = null;
  1321. $where['y.Mod_rq'] = null;
  1322. // 执行查询
  1323. $orderList = \db('工单_基本资料')->alias('j')
  1324. ->join('工单_印件资料 y', 'j.订单编号 = y.订单编号')
  1325. ->field('j.Sys_rq, y.订单编号, j.落货日期, j.生产款号, j.款式, SUM(y.sctotal) as 裁剪总数, SUM(y.zdtotal) as 制单总数,j.gd_statu,j.客户编号')
  1326. ->group('y.订单编号')
  1327. ->order('y.订单编号 desc')
  1328. ->where($where)
  1329. ->select();
  1330. $orderIds = array_column($orderList, '订单编号');
  1331. // 通过订单编号关联设备_产量计酬表,获取工序名称和数量,并进行分组和汇总
  1332. $wheres['a.mod_rq'] = null;
  1333. $wheres['j.Mod_rq'] = null;
  1334. $processList = \db('设备_产量计酬')
  1335. ->alias('a')
  1336. ->join('工单_基本资料 j', 'a.订单编号 = j.订单编号')
  1337. ->whereIn('a.订单编号', $orderIds) // 只查询符合条件的订单编号
  1338. ->field('a.订单编号, a.工序名称,
  1339. SUM(a.数量) as 总数量,SUM(a.s_num) as 上报数量,a.mod_rq')
  1340. ->where($wheres)
  1341. ->order('a.订单编号 desc')
  1342. ->group('a.订单编号, a.工序名称') // 按订单编号和工序名称分组
  1343. ->select();
  1344. // 合并两个结果
  1345. $data = [];
  1346. foreach ($orderList as $key => $order) {
  1347. // 去掉落货日期的时间部分,只保留日期
  1348. $orderDate = substr($order['落货日期'], 0, 10); // 提取前10位
  1349. //放入结果
  1350. $data[$key] = [
  1351. '订单编号' => $order['订单编号'],
  1352. '落货日期' => $order['落货日期'],
  1353. '生产款号' => $order['生产款号'],
  1354. '款式' => $order['款式'],
  1355. '客户编号' => $order['客户编号'],
  1356. '订单状态' => $order['gd_statu'],
  1357. '裁剪总数' => $order['裁剪总数'],
  1358. '制单总数' => $order['制单总数'],
  1359. '日期' => substr($order['Sys_rq'], 0, 7)
  1360. ];
  1361. //找到该订单编号对应的工序名称和数量
  1362. //裁剪、车缝计算数量,其他计算s_num合计
  1363. foreach ($processList as $process) {
  1364. if($process['工序名称'] == '裁剪' || $process['工序名称'] == '车缝'){
  1365. if ($process['订单编号'] === $order['订单编号']) {
  1366. // 将工序名称和数量加入到结果中
  1367. $data[$key][$process['工序名称']] = $process['总数量'];
  1368. }
  1369. }else{
  1370. if ($process['订单编号'] === $order['订单编号']) {
  1371. // 将工序名称和数量加入到结果中
  1372. $data[$key][$process['工序名称']] = $process['上报数量'];
  1373. }
  1374. }
  1375. }
  1376. }
  1377. $this->success('成功', $data);
  1378. }
  1379. /**
  1380. * 订单状态及样衣批核-左侧菜单
  1381. */
  1382. public function dateList()
  1383. {
  1384. }
  1385. /**
  1386. * 车缝派单菜单
  1387. * @return void
  1388. */
  1389. public function CfmachineList()
  1390. {
  1391. if ($this->request->isGet() === false) {
  1392. $this->error('请求错误');
  1393. }
  1394. // 查询所有生产工序为"车缝"的设备编号和设备编组
  1395. $machineList = \db('设备_基本资料')
  1396. ->where('生产工序', '车缝')
  1397. ->field('设备编号, 设备编组')
  1398. ->order('设备编号') // 按设备编号排序
  1399. ->select();
  1400. // 如果没有设备,直接返回空结果
  1401. if (empty($machineList)) {
  1402. $this->success('成功', []);
  1403. }
  1404. // 提取所有设备编号
  1405. $machineCodes = array_column($machineList, '设备编号');
  1406. // 将设备列表转换为关联数组,便于快速查找设备编组
  1407. $machineMap = [];
  1408. foreach ($machineList as $machine) {
  1409. $machineMap[$machine['设备编号']] = $machine['设备编组'];
  1410. }
  1411. // 一次性查询所有设备的产量计酬数据
  1412. $allOrders = \db('设备_产量计酬')
  1413. ->where('sczl_jtbh', 'in', $machineCodes)
  1414. ->where('mod_rq', null)
  1415. ->field('sczl_jtbh, 订单编号, sys_rq')
  1416. ->select();
  1417. // 按设备编号和月份分组统计订单数量
  1418. $machineMonthlyOrders = [];
  1419. foreach ($allOrders as $order) {
  1420. $machineCode = $order['sczl_jtbh'];
  1421. $yearMonth = date('Ym', strtotime($order['sys_rq']));
  1422. if (!isset($machineMonthlyOrders[$machineCode])) {
  1423. $machineMonthlyOrders[$machineCode] = [];
  1424. }
  1425. if (!isset($machineMonthlyOrders[$machineCode][$yearMonth])) {
  1426. $machineMonthlyOrders[$machineCode][$yearMonth] = [];
  1427. }
  1428. // 使用数组键自动去重订单编号
  1429. $machineMonthlyOrders[$machineCode][$yearMonth][$order['订单编号']] = true;
  1430. }
  1431. // 构建返回结果
  1432. $result = [];
  1433. foreach ($machineMonthlyOrders as $machineCode => $monthlyOrders) {
  1434. $machineGroup = $machineMap[$machineCode];
  1435. foreach ($monthlyOrders as $yearMonth => $orderMap) {
  1436. $workOrderCount = count($orderMap); // 自动去重后的订单数量
  1437. if (!isset($result[$yearMonth])) {
  1438. $result[$yearMonth] = [];
  1439. }
  1440. // 使用关联数组键自动去重设备
  1441. $deviceKey = $machineCode . '【' . $machineGroup . ' 生产中:' . $workOrderCount . '】';
  1442. $result[$yearMonth][$deviceKey] = true;
  1443. }
  1444. }
  1445. // 转换为索引数组
  1446. foreach ($result as &$monthDevices) {
  1447. $monthDevices = array_keys($monthDevices);
  1448. // 按设备编号排序
  1449. sort($monthDevices);
  1450. }
  1451. // 按月份排序,确保最新的月份在前面
  1452. krsort($result);
  1453. $this->success('成功', $result);
  1454. }
  1455. /**
  1456. * 车缝派单列表
  1457. */
  1458. public function CfdataList(){
  1459. if ($this->request->isGet() === false) {
  1460. $this->error('请求错误');
  1461. }
  1462. $param = $this->request->param();
  1463. $search = input('search', '');
  1464. // 只有当没有搜索参数时,才验证machine和date参数
  1465. if (empty($search) && (empty($param['machine']) || empty($param['date']))) {
  1466. $this->error('参数错误');
  1467. }
  1468. $where = [];
  1469. // 添加搜索条件
  1470. if (!empty($search)) {
  1471. $where['c.订单编号|j.生产款号|j.款式'] = ['like', '%' . $search . '%'];
  1472. }
  1473. // 查询设备产量计酬与工单基本资料的关联数据
  1474. $query = \db('设备_产量计酬')->alias('c')
  1475. ->join('工单_基本资料 j', 'c.订单编号 = j.订单编号', 'left')
  1476. ->where('c.mod_rq', null)
  1477. ->where('j.Mod_rq', null)
  1478. ->where('c.工序名称', '车缝') // 只统计工序名称为车缝的数据
  1479. ->where($where);
  1480. // 添加machine条件(如果提供)
  1481. if (!empty($param['machine'])) {
  1482. $query->where('c.sczl_jtbh', $param['machine']);
  1483. }
  1484. // 添加日期范围条件(如果提供)
  1485. if (!empty($param['date'])) {
  1486. // 将传入的 YYYYMM 格式日期转换为 YYYY-MM-01
  1487. $year = substr($param['date'], 0, 4);
  1488. $month = substr($param['date'], 4, 2);
  1489. $startDate = "$year-$month-01 00:00:00";
  1490. $endDate = date("Y-m-t 23:59:59", strtotime($startDate)); // 获取该月的最后一天
  1491. $query->where('c.sczl_rq', '>=', $startDate)
  1492. ->where('c.sczl_rq', '<=', $endDate);
  1493. }
  1494. // 执行查询
  1495. $list = $query->field('
  1496. c.订单编号, c.款号 as 生产款号, j.款式, j.客户编号,
  1497. CASE
  1498. WHEN c.工序名称 IN ("裁剪", "车缝") THEN sum(c.数量)
  1499. ELSE sum(c.s_num )
  1500. END as 完工数量,
  1501. LEFT(j.落货日期, 10) as 落货日期,j.订单数量 as 制单数,
  1502. LEFT(c.sczl_rq, 7) as 创建时间, j.gd_statu as 工单状态
  1503. ')
  1504. ->group('c.订单编号')
  1505. ->select();
  1506. $this->success('请求成功', ['table' => $list, 'length' => count($list)]);
  1507. }
  1508. //车缝派单删除
  1509. public function CfdataDel()
  1510. {
  1511. if ($this->request->isGet() === false)
  1512. {
  1513. $this->error('请求错误');
  1514. }
  1515. $param = $this->request->param();
  1516. if (empty($param)){
  1517. $this->error('参数错误');
  1518. }
  1519. $sql = \db('工单_排程班次')
  1520. ->where('UniqId',$param['UniqId'])
  1521. ->fetchSql(true)
  1522. ->update(['mod_rq'=>date('Y-m-d H:i:s',time())]);
  1523. $res = \db()->query($sql);
  1524. if ($res !== false){
  1525. $this->success('删除成功');
  1526. }else{
  1527. $this->error('删除失败');
  1528. }
  1529. }
  1530. //车缝派单数据
  1531. public function CfdataAllList()
  1532. {
  1533. if ($this->request->isGet() === false){
  1534. $this->error('请求错误');
  1535. }
  1536. $list = \db('工单_排程班次')
  1537. ->where('mod_rq',null)
  1538. ->order('sys_rq desc')
  1539. ->field('订单编号,子订单编号,班组编号,sys_rq as 创建时间,sys_id as 创建人员,UniqId')
  1540. ->group('子订单编号')
  1541. ->select();
  1542. $this->success('成功',$list);
  1543. }
  1544. //获取产量计酬日期节点(用于菜单栏)
  1545. public function getDateNodes()
  1546. {
  1547. if ($this->request->isGet() === false) {
  1548. $this->error('请求错误');
  1549. }
  1550. //获取所有不重复的年份
  1551. $yearList = \db('设备_产量计酬')
  1552. ->field("DISTINCT DATE_FORMAT(sczl_rq, '%Y') as year")
  1553. ->where('sczl_rq', 'not null')
  1554. ->order('year', 'desc')
  1555. ->select();
  1556. foreach ($yearList as $key => $year) {
  1557. //根据年份获取不重复的月份
  1558. $monthList = \db('设备_产量计酬')
  1559. ->field("DISTINCT DATE_FORMAT(sczl_rq, '%m') as month")
  1560. ->where('sczl_rq', 'not null')
  1561. ->where("DATE_FORMAT(sczl_rq, '%Y') = '{$year['year']}'")
  1562. ->order('month', 'asc')
  1563. ->select();
  1564. foreach ($monthList as $k => $month) {
  1565. //根据年份和月份获取不重复的日期
  1566. $dayList = \db('设备_产量计酬')
  1567. ->field("DISTINCT DATE_FORMAT(sczl_rq, '%d') as day")
  1568. ->where('sczl_rq', 'not null')
  1569. ->where("DATE_FORMAT(sczl_rq, '%Y') = '{$year['year']}'")
  1570. ->where("DATE_FORMAT(sczl_rq, '%m') = '{$month['month']}'")
  1571. ->order('day', 'asc')
  1572. ->select();
  1573. $monthList[$k]['day_list'] = $dayList;
  1574. }
  1575. $yearList[$key]['month_list'] = $monthList;
  1576. }
  1577. $this->success('获取成功', $yearList);
  1578. }
  1579. //获取产量计酬详情数据
  1580. public function getCfdataDetail()
  1581. {
  1582. if ($this->request->isGet() === false) {
  1583. $this->error('请求错误');
  1584. }
  1585. $param = $this->request->param();
  1586. if (empty($param['year']) || empty($param['month']) || empty($param['day'])) {
  1587. $this->error('请选择日期');
  1588. }
  1589. //拼接日期进行筛选
  1590. $date = $param['year'] . '-' . $param['month'] . '-' . $param['day'];
  1591. //查询数据
  1592. $list = \db('设备_产量计酬')
  1593. ->where("DATE_FORMAT(sczl_rq, '%Y-%m-%d') = '{$date}'")
  1594. ->field('订单编号, 子订单编号, 款号, 尺码, 数量, sczl_bh')
  1595. ->select();
  1596. if (empty($list)) {
  1597. $this->success('暂无数据', []);
  1598. }
  1599. $this->success('获取成功', $list);
  1600. }
  1601. }