| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\Controller;
- use think\Db;
- /**
- * 达成大屏数据接口
- */
- class Index extends Controller{
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- /**首页*/
- public function index(){$this->success('成功');}
- /**
- *近30天班组生产效率完成情况【缓存】
- * 查询近三十天车缝小组完成情况
- * 完成总数量
- */
- public function bzDbToRedis(){
- //存缓存Redis
- $redis = redis();
- $redis_key = md5('bzDbToRedis');
- // 获取当天的日期
- $todays = date('Y-m-d');//30天前
- $today = date('Y-m-d');//当天日期
- // $where['c.sczl_bh'] = ['like','%'.'车缝'.'%'];
- $where['mod_rq'] = null;
- $where['工序名称'] = '车缝';
- $res = db('设备_产量计酬')->alias('c')
- ->where($where)
- ->field('c.sczl_bh, SUM(c.数量) as 数量')
- ->group('c.sczl_bh')
- ->select();
- // echo "<pre>";
- // print_r($res);
- // echo "<pre>";die;
- $redis->set($redis_key, json_encode($res));
- echo date("Y-m-d H:i:s").'存进去了';
- return $res;
- }
- /**
- *近30天班组生产效率完成情况【接口】
- */
- public function bzDbTo(){
- $redis = redis();
- $row = json_decode($redis->get(md5('bzDbToRedis')), true);
- echo "<pre>";
- print_r($row);
- echo "<pre>";
- }
- /**
- *当日班组报工产量【缓存】
- */
- public function numDbToRedis(){
- //存缓存Redis
- $redis = redis();
- $redis_key = md5('numDbToRedis');
- // 获取当天的日期
- $todays = date('Y-8-d');
- $today = date('Y-m-d');
- // 查询设备_产量计酬表,当日班组报工产量情况,排除车缝班组,按班组和日期分组并累计数量
- $res = db('设备_产量计酬')
- ->alias('c')
- ->where('c.sczl_bh', 'not like', '%车缝%') // 排除车缝班组
- ->where('c.sys_rq', '>=', $todays . ' 00:00:00') // 当日开始时间
- ->where('c.sys_rq', '<=', $today . ' 23:59:59') // 当日结束时间
- ->whereNull('c.mod_rq')
- ->field('c.sczl_bh, SUM(c.ci_num) as total_num, DATE(c.sys_rq) as date') // 班组编号,数量累计,日期
- ->group('c.sczl_bh, DATE(c.sys_rq)') // 按班组编号和日期分组
- ->select();
- echo "<pre>";
- print_r($res);
- echo "<pre>";die;
- $redis->set($redis_key, json_encode($res));
- echo date("Y-m-d H:i:s").'存进去了';
- return $res;
- }
- /**
- *当日班组报工产量【接口】
- */
- public function getPczByRedis(){
- // $list=['categories'=>[$list2021['rq'],$list2022['rq'],$list2023['rq']],'series'=>[['name'=>'色令数',
- // 'data'=>[round($list2021['nyssl']/10000),round($list2022['nyssl']/10000),round($list2023['nyssl']/10000)]]]];
- // $res['status']=0;
- // $res['msg']='';
- // $res['data']=$list;
- // $redis->set($redis_key, json_encode($res));
- // return json_encode($res);
- $redis = redis();
- $row = json_decode($redis->get(md5('numDbToRedis')), true);
- echo "<pre>";
- print_r($row);
- echo "<pre>";
- }
- /**
- * 在产订单工序完工详情【缓存】
- */
- public function getJhzByRedis(){
- //存缓存Redis
- $redis = redis();
- $redis_key = md5('getJhzByRedis');
- $startTime = date('Y-m-d', strtotime('-30 days'));
- $endTime = date('Y-m-d');
- // 修改查询条件为近30天
- $where['b.Sys_rq'] = ['between', [$startTime, $endTime]];
- $list = \db('设备_产量计酬')
- ->alias('a')
- ->join('工单_基本资料 b','a.订单编号 = b.订单编号')
- ->join('工单_印件资料 c','a.订单编号 = c.订单编号 AND a.子订单编号 = c.子订单编号')
- ->field('c.订单编号,c.子订单编号,c.款号,c.颜色,c.zdtotal as 制单总数,c.sctotal as 裁切总数,c.ck_rq as 出库日期,
- SUM(a.数量) as 产量,a.工序名称,b.客户编号,b.单位')
- ->where($where)
- ->group('a.订单编号,a.工序名称')
- ->order('c.Uniqid')
- ->select();
- $orderList = \db('设备_产量计酬')
- ->alias('a')
- ->join('工单_基本资料 b','a.订单编号 = b.订单编号')
- ->join('工单_印件资料 c','a.订单编号 = c.订单编号 AND a.子订单编号 = c.子订单编号')
- ->field('c.订单编号,c.子订单编号,c.款号,c.颜色,c.zdtotal as 制单总数,c.sctotal as 裁切总数,c.ck_rq as 出库日期,b.客户编号,b.单位')
- ->where($where)
- ->group('a.子订单编号')
- ->order('c.Uniqid')
- ->select();
- foreach ($orderList as $key=>$value){
- $data[$key] = $value;
- foreach ($list as $k=>$v){
- if ($value['子订单编号'] === $v['子订单编号']){
- if (isset($data[$key][$v['工序名称']]) === false){
- $data[$key][$v['工序名称']] = $v['产量'];
- }
- }
- }
- }
- $redis->set($redis_key, json_encode($data));
- echo date("Y-m-d H:i:s").'存进去了';
- return $data;
- }
- /**
- * 在产订单工序完工详情【接口】
- */
- public function getZczByRedis(){
- $redis = redis();
- $row = json_decode($redis->get(md5('getJhzByRedis')), true);
- // 列定义
- $result['columns'] = [
- ['name' => '订单编号', 'id' => 'order', 'width' => '14', 'autoWrap' => "true", 'textAlign' => 'left'],
- ['name' => '客户', 'id' => 'kehu', 'width' => '16', 'textAlign' => 'left'],
- ['name' => '制单总数', 'id' => 'zdnum', 'width' => '20', 'autoWrap' => "true", 'textAlign' => 'left'],
- ['name' => '单位', 'id' => 'dw', 'width' => '16', 'autoWrap' => "true", 'textAlign' => 'left'],
- ['name' => '出库确认', 'id' => 'chuku', 'width' => '14', 'autoWrap' => "true", 'textAlign' => 'left'],
- ['name' => '裁切', 'id' => 'caiqie', 'width' => '14', 'autoWrap' => "true", 'textAlign' => 'center'],
- ['name' => '缝制小烫', 'id' => 'fegnzhi', 'width' => '14', 'autoWrap' => "true", 'textAlign' => 'center'],
- ['name' => '后道收样', 'id' => 'houdao', 'width' => '14', 'autoWrap' => "true", 'textAlign' => 'center'],
- ['name' => '大烫', 'id' => 'datang', 'width' => '14', 'autoWrap' => "true", 'textAlign' => 'center'],
- ['name' => '总检', 'id' => 'zongjian', 'width' => '14', 'autoWrap' => "true", 'textAlign' => 'center'],
- ['name' => '包装', 'id' => 'baozhaung', 'width' => '14', 'autoWrap' => "true", 'textAlign' => 'center'],
- ];
- if ($row) {
- foreach ($row as $k => $v) {
- $result['rows'][$k]['order'] = $v['订单编号'];
- $result['rows'][$k]['kehu'] = $v['客户编号'];
- $result['rows'][$k]['zdnum'] = $v['制单总数'];
- $result['rows'][$k]['dw'] = $v['单位'];
- // 判断出库日期,设置出库确认
- $result['rows'][$k]['chuku'] = isset($v['出库日期']) && !empty($v['出库日期']) ? '已出库' : '未出库';
- $result['rows'][$k]['caiqie'] = $v['裁切'] ?? '';
- $result['rows'][$k]['fegnzhi'] = $v['缝制小烫'] ?? '';
- $result['rows'][$k]['houdao'] = $v['后道收样'] ?? '';
- $result['rows'][$k]['datang'] = $v['大烫'] ?? '';
- $result['rows'][$k]['zongjian'] = $v['总检'] ?? '';
- $result['rows'][$k]['baozhaung'] = $v['包装'] ?? '';
- }
- } else {
- // 如果没有数据,初始化空行
- $result['rows'][0] = [
- 'order' => '', 'kehu' => '', 'zdnum' => '', 'dw' => '', 'chuku' => '',
- 'caiqie' => '', 'fegnzhi' => '', 'houdao' => '', 'datang' => '', 'zongjian' => '', 'baozhaung' => ''
- ];
- }
- // echo "<pre>";print_r($result);echo "<pre>";die;
- // 构造最终的返回数据
- $res['status'] = 0;
- $res['msg'] = '';
- $res['data'] = $result;
- return json($res);
- }
- /**
- *已制单样衣未审、已审核待生产、生产中未完成【缓存】
- */
- public function yscjDbToRedis(){
- //存缓存Redis
- $redis = redis();
- $redis_key = md5('yscjDbToRedis');
- $res = \db('工单_基本资料')
- ->where('sys_rq', '>=', date('Y-m-d', strtotime('-30 days')))
- ->select();
- $redis->set($redis_key, json_encode($res));
- echo date("Y-m-d H:i:s").'存进去了';
- return $res;
- }
- /**
- *已制单样衣未审【接口】
- * 订单已下单 未审核数量
- */
- public function yhcjDbToRedis(){
- $redis = redis();
- // 从 Redis 中获取数据
- $row = json_decode($redis->get(md5('yscjDbToRedis')), true);
- // 初始化计数器
- $count = 0;
- // 遍历数据,统计审核日期为空、mod_rq 为空、审核状态为空的数据
- foreach ($row as $item) {
- if (empty($item['审核日期']) && empty($item['Mod_rq']) && empty($item['审核'])) {
- $count++;
- }
- }
- // 构造返回数据
- $result = [
- 'name' => '已制单样衣未审',
- 'value' => $count,
- ];
- // 构造最终的返回结构
- $res = [
- 'status' => 0,
- 'msg' => '',
- 'data' => [$result],
- ];
- // 返回JSON格式的结果
- return json($res);
- }
- /**
- *已审核待生产【接口】
- */
- public function getYscjByRedis(){
- $redis = redis();
- // 从 Redis 中获取数据
- $row = json_decode($redis->get(md5('yscjDbToRedis')), true);
- // 初始化计数器
- $count = 0;
- // 遍历数据,统计审核日期为空、mod_rq 为空、审核状态为空的数据
- foreach ($row as $item) {
- if (empty($item['出库日期'])) {
- $count++;
- }
- }
- // 构造返回数据
- $result = [
- 'name' => '已审核待生产',
- 'value' => $count,
- ];
- // 构造最终的返回结构
- $res = [
- 'status' => 0,
- 'msg' => '',
- 'data' => [$result],
- ];
- // 返回JSON格式的结果
- return json($res);
- }
- /**
- *生产中未完成【缓存】
- */
- public function getJtClDbByRedis(){
- //存缓存Redis
- $redis = redis();
- $redis_key = md5('getJtClDbByRedis');
- $res = \db('工单_排程班次')
- ->alias('a')
- ->join('工单_印件资料 b','b.订单编号 = a.订单编号 AND a.子订单编号 = a.子订单编号')
- ->join('设备_产量计酬 c','a.订单编号 = c.订单编号 AND a.子订单编号 = c.子订单编号','LEFT')
- ->field('a.订单编号,a.子订单编号,b.款号,b.颜色,b.船样,b.zdtotal as 制单数,SUM(c.数量) as 已完成')
- ->where('a.mod_rq',null)
- ->select();
- $redis->set($redis_key, json_encode($res));
- echo date("Y-m-d H:i:s").'存进去了';
- return $res;
- }
- /**
- *生产中未完成【接口】
- */
- public function getYhcjByRedis(){
- $redis = redis();
- // 从 Redis 中获取数据
- $row = json_decode($redis->get(md5('getJtClDbByRedis')), true);
- // 初始化计数器
- $count = 0;
- // 遍历数据,统计未完成的记录条数
- foreach ($row as $item) {
- // 假设 '制单数' 是生产总数,'已完成' 是完成的数量
- if (isset($item['制单数']) && isset($item['已完成'])) {
- // 判断未完成数量是否大于0
- if ($item['制单数'] > $item['已完成']) {
- $count++;
- }
- }
- }
- // 构造返回数据
- $result = [
- 'name' => '生产中未完成',
- 'value' => $count,
- ];
- // 构造最终的返回结构
- $res = [
- 'status' => 0,
- 'msg' => '',
- 'data' => [$result],
- ];
- // 返回JSON格式的结果
- return json($res);
- }
- public function jtClDbToRedis(){
- }
- }
|