Index.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Controller;
  5. use think\Db;
  6. /**
  7. * 达成大屏数据接口
  8. */
  9. class Index extends Controller{
  10. protected $noNeedLogin = ['*'];
  11. protected $noNeedRight = ['*'];
  12. /**首页*/
  13. public function index(){$this->success('成功');}
  14. /**
  15. *近30天班组生产效率完成情况【缓存】
  16. * 查询近三十天车缝小组完成情况
  17. * 完成总数量
  18. */
  19. public function bzDbToRedis(){
  20. //存缓存Redis
  21. $redis = redis();
  22. $redis_key = md5('bzDbToRedis');
  23. // 获取当天的日期
  24. $todays = date('Y-m-d');//30天前
  25. $today = date('Y-m-d');//当天日期
  26. // $where['c.sczl_bh'] = ['like','%'.'车缝'.'%'];
  27. $where['mod_rq'] = null;
  28. $where['工序名称'] = '车缝';
  29. $res = db('设备_产量计酬')->alias('c')
  30. ->where($where)
  31. ->field('c.sczl_bh, SUM(c.数量) as 数量')
  32. ->group('c.sczl_bh')
  33. ->select();
  34. // echo "<pre>";
  35. // print_r($res);
  36. // echo "<pre>";die;
  37. $redis->set($redis_key, json_encode($res));
  38. echo date("Y-m-d H:i:s").'存进去了';
  39. return $res;
  40. }
  41. /**
  42. *近30天班组生产效率完成情况【接口】
  43. */
  44. public function bzDbTo(){
  45. $redis = redis();
  46. $row = json_decode($redis->get(md5('bzDbToRedis')), true);
  47. echo "<pre>";
  48. print_r($row);
  49. echo "<pre>";
  50. }
  51. /**
  52. *当日班组报工产量【缓存】
  53. */
  54. public function numDbToRedis(){
  55. //存缓存Redis
  56. $redis = redis();
  57. $redis_key = md5('numDbToRedis');
  58. // 获取当天的日期
  59. $todays = date('Y-8-d');
  60. $today = date('Y-m-d');
  61. // 查询设备_产量计酬表,当日班组报工产量情况,排除车缝班组,按班组和日期分组并累计数量
  62. $res = db('设备_产量计酬')
  63. ->alias('c')
  64. ->where('c.sczl_bh', 'not like', '%车缝%') // 排除车缝班组
  65. ->where('c.sys_rq', '>=', $todays . ' 00:00:00') // 当日开始时间
  66. ->where('c.sys_rq', '<=', $today . ' 23:59:59') // 当日结束时间
  67. ->whereNull('c.mod_rq')
  68. ->field('c.sczl_bh, SUM(c.ci_num) as total_num, DATE(c.sys_rq) as date') // 班组编号,数量累计,日期
  69. ->group('c.sczl_bh, DATE(c.sys_rq)') // 按班组编号和日期分组
  70. ->select();
  71. echo "<pre>";
  72. print_r($res);
  73. echo "<pre>";die;
  74. $redis->set($redis_key, json_encode($res));
  75. echo date("Y-m-d H:i:s").'存进去了';
  76. return $res;
  77. }
  78. /**
  79. *当日班组报工产量【接口】
  80. */
  81. public function getPczByRedis(){
  82. // $list=['categories'=>[$list2021['rq'],$list2022['rq'],$list2023['rq']],'series'=>[['name'=>'色令数',
  83. // 'data'=>[round($list2021['nyssl']/10000),round($list2022['nyssl']/10000),round($list2023['nyssl']/10000)]]]];
  84. // $res['status']=0;
  85. // $res['msg']='';
  86. // $res['data']=$list;
  87. // $redis->set($redis_key, json_encode($res));
  88. // return json_encode($res);
  89. $redis = redis();
  90. $row = json_decode($redis->get(md5('numDbToRedis')), true);
  91. echo "<pre>";
  92. print_r($row);
  93. echo "<pre>";
  94. }
  95. /**
  96. * 在产订单工序完工详情【缓存】
  97. */
  98. public function getJhzByRedis(){
  99. //存缓存Redis
  100. $redis = redis();
  101. $redis_key = md5('getJhzByRedis');
  102. $startTime = date('Y-m-d', strtotime('-30 days'));
  103. $endTime = date('Y-m-d');
  104. // 修改查询条件为近30天
  105. $where['b.Sys_rq'] = ['between', [$startTime, $endTime]];
  106. $list = \db('设备_产量计酬')
  107. ->alias('a')
  108. ->join('工单_基本资料 b','a.订单编号 = b.订单编号')
  109. ->join('工单_印件资料 c','a.订单编号 = c.订单编号 AND a.子订单编号 = c.子订单编号')
  110. ->field('c.订单编号,c.子订单编号,c.款号,c.颜色,c.zdtotal as 制单总数,c.sctotal as 裁切总数,c.ck_rq as 出库日期,
  111. SUM(a.数量) as 产量,a.工序名称,b.客户编号,b.单位')
  112. ->where($where)
  113. ->group('a.订单编号,a.工序名称')
  114. ->order('c.Uniqid')
  115. ->select();
  116. $orderList = \db('设备_产量计酬')
  117. ->alias('a')
  118. ->join('工单_基本资料 b','a.订单编号 = b.订单编号')
  119. ->join('工单_印件资料 c','a.订单编号 = c.订单编号 AND a.子订单编号 = c.子订单编号')
  120. ->field('c.订单编号,c.子订单编号,c.款号,c.颜色,c.zdtotal as 制单总数,c.sctotal as 裁切总数,c.ck_rq as 出库日期,b.客户编号,b.单位')
  121. ->where($where)
  122. ->group('a.子订单编号')
  123. ->order('c.Uniqid')
  124. ->select();
  125. foreach ($orderList as $key=>$value){
  126. $data[$key] = $value;
  127. foreach ($list as $k=>$v){
  128. if ($value['子订单编号'] === $v['子订单编号']){
  129. if (isset($data[$key][$v['工序名称']]) === false){
  130. $data[$key][$v['工序名称']] = $v['产量'];
  131. }
  132. }
  133. }
  134. }
  135. $redis->set($redis_key, json_encode($data));
  136. echo date("Y-m-d H:i:s").'存进去了';
  137. return $data;
  138. }
  139. /**
  140. * 在产订单工序完工详情【接口】
  141. */
  142. public function getZczByRedis(){
  143. $redis = redis();
  144. $row = json_decode($redis->get(md5('getJhzByRedis')), true);
  145. // 列定义
  146. $result['columns'] = [
  147. ['name' => '订单编号', 'id' => 'order', 'width' => '14', 'autoWrap' => "true", 'textAlign' => 'left'],
  148. ['name' => '客户', 'id' => 'kehu', 'width' => '16', 'textAlign' => 'left'],
  149. ['name' => '制单总数', 'id' => 'zdnum', 'width' => '20', 'autoWrap' => "true", 'textAlign' => 'left'],
  150. ['name' => '单位', 'id' => 'dw', 'width' => '16', 'autoWrap' => "true", 'textAlign' => 'left'],
  151. ['name' => '出库确认', 'id' => 'chuku', 'width' => '14', 'autoWrap' => "true", 'textAlign' => 'left'],
  152. ['name' => '裁切', 'id' => 'caiqie', 'width' => '14', 'autoWrap' => "true", 'textAlign' => 'center'],
  153. ['name' => '缝制小烫', 'id' => 'fegnzhi', 'width' => '14', 'autoWrap' => "true", 'textAlign' => 'center'],
  154. ['name' => '后道收样', 'id' => 'houdao', 'width' => '14', 'autoWrap' => "true", 'textAlign' => 'center'],
  155. ['name' => '大烫', 'id' => 'datang', 'width' => '14', 'autoWrap' => "true", 'textAlign' => 'center'],
  156. ['name' => '总检', 'id' => 'zongjian', 'width' => '14', 'autoWrap' => "true", 'textAlign' => 'center'],
  157. ['name' => '包装', 'id' => 'baozhaung', 'width' => '14', 'autoWrap' => "true", 'textAlign' => 'center'],
  158. ];
  159. if ($row) {
  160. foreach ($row as $k => $v) {
  161. $result['rows'][$k]['order'] = $v['订单编号'];
  162. $result['rows'][$k]['kehu'] = $v['客户编号'];
  163. $result['rows'][$k]['zdnum'] = $v['制单总数'];
  164. $result['rows'][$k]['dw'] = $v['单位'];
  165. // 判断出库日期,设置出库确认
  166. $result['rows'][$k]['chuku'] = isset($v['出库日期']) && !empty($v['出库日期']) ? '已出库' : '未出库';
  167. $result['rows'][$k]['caiqie'] = $v['裁切'] ?? '';
  168. $result['rows'][$k]['fegnzhi'] = $v['缝制小烫'] ?? '';
  169. $result['rows'][$k]['houdao'] = $v['后道收样'] ?? '';
  170. $result['rows'][$k]['datang'] = $v['大烫'] ?? '';
  171. $result['rows'][$k]['zongjian'] = $v['总检'] ?? '';
  172. $result['rows'][$k]['baozhaung'] = $v['包装'] ?? '';
  173. }
  174. } else {
  175. // 如果没有数据,初始化空行
  176. $result['rows'][0] = [
  177. 'order' => '', 'kehu' => '', 'zdnum' => '', 'dw' => '', 'chuku' => '',
  178. 'caiqie' => '', 'fegnzhi' => '', 'houdao' => '', 'datang' => '', 'zongjian' => '', 'baozhaung' => ''
  179. ];
  180. }
  181. // echo "<pre>";print_r($result);echo "<pre>";die;
  182. // 构造最终的返回数据
  183. $res['status'] = 0;
  184. $res['msg'] = '';
  185. $res['data'] = $result;
  186. return json($res);
  187. }
  188. /**
  189. *已制单样衣未审、已审核待生产、生产中未完成【缓存】
  190. */
  191. public function yscjDbToRedis(){
  192. //存缓存Redis
  193. $redis = redis();
  194. $redis_key = md5('yscjDbToRedis');
  195. $res = \db('工单_基本资料')
  196. ->where('sys_rq', '>=', date('Y-m-d', strtotime('-30 days')))
  197. ->select();
  198. $redis->set($redis_key, json_encode($res));
  199. echo date("Y-m-d H:i:s").'存进去了';
  200. return $res;
  201. }
  202. /**
  203. *已制单样衣未审【接口】
  204. * 订单已下单 未审核数量
  205. */
  206. public function yhcjDbToRedis(){
  207. $redis = redis();
  208. // 从 Redis 中获取数据
  209. $row = json_decode($redis->get(md5('yscjDbToRedis')), true);
  210. // 初始化计数器
  211. $count = 0;
  212. // 遍历数据,统计审核日期为空、mod_rq 为空、审核状态为空的数据
  213. foreach ($row as $item) {
  214. if (empty($item['审核日期']) && empty($item['Mod_rq']) && empty($item['审核'])) {
  215. $count++;
  216. }
  217. }
  218. // 构造返回数据
  219. $result = [
  220. 'name' => '已制单样衣未审',
  221. 'value' => $count,
  222. ];
  223. // 构造最终的返回结构
  224. $res = [
  225. 'status' => 0,
  226. 'msg' => '',
  227. 'data' => [$result],
  228. ];
  229. // 返回JSON格式的结果
  230. return json($res);
  231. }
  232. /**
  233. *已审核待生产【接口】
  234. */
  235. public function getYscjByRedis(){
  236. $redis = redis();
  237. // 从 Redis 中获取数据
  238. $row = json_decode($redis->get(md5('yscjDbToRedis')), true);
  239. // 初始化计数器
  240. $count = 0;
  241. // 遍历数据,统计审核日期为空、mod_rq 为空、审核状态为空的数据
  242. foreach ($row as $item) {
  243. if (empty($item['出库日期'])) {
  244. $count++;
  245. }
  246. }
  247. // 构造返回数据
  248. $result = [
  249. 'name' => '已审核待生产',
  250. 'value' => $count,
  251. ];
  252. // 构造最终的返回结构
  253. $res = [
  254. 'status' => 0,
  255. 'msg' => '',
  256. 'data' => [$result],
  257. ];
  258. // 返回JSON格式的结果
  259. return json($res);
  260. }
  261. /**
  262. *生产中未完成【缓存】
  263. */
  264. public function getJtClDbByRedis(){
  265. //存缓存Redis
  266. $redis = redis();
  267. $redis_key = md5('getJtClDbByRedis');
  268. $res = \db('工单_排程班次')
  269. ->alias('a')
  270. ->join('工单_印件资料 b','b.订单编号 = a.订单编号 AND a.子订单编号 = a.子订单编号')
  271. ->join('设备_产量计酬 c','a.订单编号 = c.订单编号 AND a.子订单编号 = c.子订单编号','LEFT')
  272. ->field('a.订单编号,a.子订单编号,b.款号,b.颜色,b.船样,b.zdtotal as 制单数,SUM(c.数量) as 已完成')
  273. ->where('a.mod_rq',null)
  274. ->select();
  275. $redis->set($redis_key, json_encode($res));
  276. echo date("Y-m-d H:i:s").'存进去了';
  277. return $res;
  278. }
  279. /**
  280. *生产中未完成【接口】
  281. */
  282. public function getYhcjByRedis(){
  283. $redis = redis();
  284. // 从 Redis 中获取数据
  285. $row = json_decode($redis->get(md5('getJtClDbByRedis')), true);
  286. // 初始化计数器
  287. $count = 0;
  288. // 遍历数据,统计未完成的记录条数
  289. foreach ($row as $item) {
  290. // 假设 '制单数' 是生产总数,'已完成' 是完成的数量
  291. if (isset($item['制单数']) && isset($item['已完成'])) {
  292. // 判断未完成数量是否大于0
  293. if ($item['制单数'] > $item['已完成']) {
  294. $count++;
  295. }
  296. }
  297. }
  298. // 构造返回数据
  299. $result = [
  300. 'name' => '生产中未完成',
  301. 'value' => $count,
  302. ];
  303. // 构造最终的返回结构
  304. $res = [
  305. 'status' => 0,
  306. 'msg' => '',
  307. 'data' => [$result],
  308. ];
  309. // 返回JSON格式的结果
  310. return json($res);
  311. }
  312. public function jtClDbToRedis(){
  313. }
  314. }