| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\Db;javascript:;
- use Think\Exception;
- /** 首页接口*/
- class Printingone extends Api{
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- /** 首页 */
- public function index(){$this->success('湖州油墨api接口成功访问');}
- //车间列表表头字段
- function generateColumns() {
- return [
- ['name' => '批次号', 'id' => 'bach', 'width' => '10', 'autoWrap' => "true", 'textAlign' => 'left'],
- ['name' => '配方名称', 'id' => 'name', 'width' => '20', 'textAlign' => 'left'],
- ['name' => '机台', 'id' => 'machine', 'width' => '10', 'autoWrap' => "true", 'textAlign' => 'left'],
- ['name' => '生产量(kg)', 'id' => 'number', 'width' => '10', 'autoWrap' => "true", 'textAlign' => 'left'],
- ['name' => '扩单重量', 'id' => 'kuodan', 'width' => '13', 'autoWrap' => "true", 'textAlign' => 'left'],
- ['name' => '创建时间', 'id' => 'create', 'width' => '17', 'autoWrap' => "true", 'textAlign' => 'left'],
- ['name' => '是否投料', 'id' => 'fedding_status', 'width' => '10', 'autoWrap' => "true",'textAlign' => 'left'],
- ];
- }
- // 通用的作业票列表方法
- public function generateWorkshopList($machineType) {
- // 获取当前日期
- $today = date('Y-m-d 23:59:59');
- // 计算五天前的日期
- $fiveDaysAgo = date('Y-m-d 00:00:00');
- $result = Db::connect('minnongyun')->table('mn_task')->alias('t')
- ->field('
- t.name,
- t.bach,
- t.machine,
- t.number,
- t.create,
- t.kuodan,
- CASE WHEN f.bach IS NULL THEN \'未投料\' ELSE \'已投料\' END AS fedding_status
- ')
- ->join('mn_feeding f','t.bach = f.bach','LEFT')
- ->where('t.machine', 'like', '%' . $machineType . '%')
- ->where('t.create', '>=', $fiveDaysAgo)
- ->where('t.create', '<=', $today)
- ->group('t.create')
- ->order('t.create', 'desc')
- ->select();
- //echo "<pre>";print_r($result);echo "<pre>";
- $new_result = [];
- $new_result['columns'] = $this->generateColumns();
- if (empty($result)) {
- $res['status'] = 0;
- $res['msg'] = '';
- // 手动创建一个空的行数据
- $new_result['rows'][] = [
- 'name' => '-',
- 'bach' => '-',
- 'machine' => '-',
- 'number' => '-',
- 'kuodan' => '-',
- 'create' => '-',
- 'fedding_status' => '-',
- ];
- $res['data'] = $new_result;
- return json($res);
- }
- $color = 'rgb(91, 197, 106)';
- foreach ($result as $key => $value) {
- $new_result['rows'][$key]['name'] = $value['name'];
- $new_result['rows'][$key]['bach'] = '24-'.$value['bach'];
- $new_result['rows'][$key]['machine'] = mb_substr($value['machine'], 3);
- $new_result['rows'][$key]['number'] = $value['number'];
- $new_result['rows'][$key]['kuodan'] = $value['kuodan'];
- $new_result['rows'][$key]['create'] = $value['create'];
- $new_result['rows'][$key]['fedding_status'] = $value['fedding_status'];
- if($value['fedding_status'] == '已投料'){
- $new_result['rows'][$key]['name_color'] = $color;
- $new_result['rows'][$key]['bach_color'] = $color;
- $new_result['rows'][$key]['machine_color'] = $color;
- $new_result['rows'][$key]['number_color'] = $color;
- $new_result['rows'][$key]['kuodan_color'] = $color;
- $new_result['rows'][$key]['create_color'] = $color;
- $new_result['rows'][$key]['fedding_status_color'] = $color;
- }
- }
- $res['status'] = 0;
- $res['msg'] = '';
- $res['data'] = $new_result;
- return json($res);
- }
- // 甲类车间作业票列表->接口
- public function jl_workshops() {
- return $this->generateWorkshopList('甲类');
- }
- //甲类作业票数量->接口
- public function jl_zypsl(){
- // 获取当前日期
- $today = date('Y-m-d 23:59:59');
- // 计算五天前的日期
- $fiveDaysAgo = date('Y-m-d 00:00:00');
- $result = Db::connect('minnongyun')->table('mn_task')->alias('t')
- ->field('
- t.name,
- t.bach,
- t.machine,
- t.number,
- t.create,
- t.kuodan,
- CASE WHEN f.bach IS NULL THEN \'未投料\' ELSE \'已投料\' END AS fedding_status
- ')
- ->join('mn_feeding f','t.bach = f.bach','LEFT')
- ->where('t.machine', 'like', '%' . '甲类' . '%')
- ->where('t.create', '>=', $fiveDaysAgo)
- ->where('t.create', '<=', $today)
- ->group('t.create')
- ->order('t.create', 'desc')
- ->count('t.bach');
- if($result==[]){
- $res['data']=[['name'=>'作业票','value'=>0]];
- }else{
- $res['data']=[['name'=>'作业票','value'=>$result]];
- }
- $res['status']=0;
- $res['msg']='';
- return json($res);
- }
- //甲类未投料数量->接口
- public function jl_weitsl(){
- // 获取当前日期
- $today = date('Y-m-d 23:59:59');
- // 计算五天前的日期
- $fiveDaysAgo = date('Y-m-d 00:00:00');
- $result = Db::connect('minnongyun')->table('mn_task')->alias('t')
- ->field('
- t.name,
- t.bach,
- t.machine,
- t.number,
- t.create,
- t.kuodan,
- CASE WHEN f.bach IS NULL THEN \'未投料\' ELSE \'已投料\' END AS fedding_status
- ')
- ->join('mn_feeding f','t.bach = f.bach','LEFT')
- ->where('t.machine', 'like', '%' . '甲类' . '%')
- ->where('t.create', '>=', $fiveDaysAgo)
- ->where('t.create', '<=', $today)
- ->group('t.create')
- ->order('t.create', 'desc')
- ->select();
- $Count = 0;
- foreach ($result as $item) {
- if ($item['fedding_status'] === '未投料') {
- $Count++;
- }
- }
- if($result==[]){
- $res['data']=[['name'=>'未投料','value'=>0]];
- }else{
- $res['data']=[['name'=>'未投料','value'=>$Count]];
- }
- $res['status']=0;
- $res['msg']='';
- return json($res);
- }
- //甲类已投料数量->接口
- public function jl_yitsl(){
- // 获取当前日期
- $today = date('Y-m-d 23:59:59');
- // 计算五天前的日期
- $fiveDaysAgo = date('Y-m-d 00:00:00');
- $result = Db::connect('minnongyun')->table('mn_task')->alias('t')
- ->field('
- t.name,
- t.bach,
- t.machine,
- t.number,
- t.create,
- t.kuodan,
- CASE WHEN f.bach IS NULL THEN \'未投料\' ELSE \'已投料\' END AS fedding_status
- ')
- ->join('mn_feeding f','t.bach = f.bach','LEFT')
- ->where('t.machine', 'like', '%' . '甲类' . '%')
- ->where('t.create', '>=', $fiveDaysAgo)
- ->where('t.create', '<=', $today)
- ->group('t.create')
- ->order('t.create', 'desc')
- ->select();
- $Count = 0;
- foreach ($result as $item) {
- if ($item['fedding_status'] === '已投料') {
- $Count++;
- }
- }
- if($result==[]){
- $res['data']=[['name'=>'已投料','value'=>0]];
- }else{
- $res['data']=[['name'=>'已投料','value'=>$Count]];
- }
- $res['status']=0;
- $res['msg']='';
- return json($res);
- }
- // 丙类车间作业票列表->接口
- public function bl_workshops() {
- return $this->generateWorkshopList('丙类');
- }
- //丙类作业票数量->接口
- public function bl_zypsl(){
- // 获取当前日期
- $today = date('Y-m-d 23:59:59');
- // 计算五天前的日期
- $fiveDaysAgo = date('Y-m-d 00:00:00');
- $result = Db::connect('minnongyun')->table('mn_task')->alias('t')
- ->field('
- t.name,
- t.bach,
- t.machine,
- t.number,
- t.create,
- t.kuodan,
- CASE WHEN f.bach IS NULL THEN \'未投料\' ELSE \'已投料\' END AS fedding_status
- ')
- ->join('mn_feeding f','t.bach = f.bach','LEFT')
- ->where('t.machine', 'like', '%' . '丙类' . '%')
- ->where('t.create', '>=', $fiveDaysAgo)
- ->where('t.create', '<=', $today)
- ->group('t.create')
- ->order('t.create', 'desc')
- ->count('t.bach');
- if($result==[]){
- $res['data']=[['name'=>'作业票','value'=>0]];
- }else{
- $res['data']=[['name'=>'作业票','value'=>$result]];
- }
- $res['status']=0;
- $res['msg']='';
- return json($res);
- }
- //丙类未投料数量->接口
- public function bl_weitsl(){
- // 获取当前日期
- $today = date('Y-m-d 23:59:59');
- // 计算五天前的日期
- $fiveDaysAgo = date('Y-m-d 00:00:00');
- $result = Db::connect('minnongyun')->table('mn_task')->alias('t')
- ->field('
- t.name,
- t.bach,
- t.machine,
- t.number,
- t.create,
- t.kuodan,
- CASE WHEN f.bach IS NULL THEN \'未投料\' ELSE \'已投料\' END AS fedding_status
- ')
- ->join('mn_feeding f','t.bach = f.bach','LEFT')
- ->where('t.machine', 'like', '%' . '丙类' . '%')
- ->where('t.create', '>=', $fiveDaysAgo)
- ->where('t.create', '<=', $today)
- ->group('t.create')
- ->order('t.create', 'desc')
- ->select();
- $Count = 0;
- foreach ($result as $item) {
- if ($item['fedding_status'] === '未投料') {
- $Count++;
- }
- }
- if($result==[]){
- $res['data']=[['name'=>'未投料','value'=>0]];
- }else{
- $res['data']=[['name'=>'未投料','value'=>$Count]];
- }
- $res['status']=0;
- $res['msg']='';
- return json($res);
- }
- //丙类已投料数量->接口
- public function bl_yitsl(){
- // 获取当前日期
- $today = date('Y-m-d 23:59:59');
- // 计算五天前的日期
- $fiveDaysAgo = date('Y-m-d 00:00:00');
- $result = Db::connect('minnongyun')->table('mn_task')->alias('t')
- ->field('
- t.name,
- t.bach,
- t.machine,
- t.number,
- t.create,
- t.kuodan,
- CASE WHEN f.bach IS NULL THEN \'未投料\' ELSE \'已投料\' END AS fedding_status
- ')
- ->join('mn_feeding f','t.bach = f.bach','LEFT')
- ->where('t.machine', 'like', '%' . '丙类' . '%')
- ->where('t.create', '>=', $fiveDaysAgo)
- ->where('t.create', '<=', $today)
- ->group('t.create')
- ->order('t.create', 'desc')
- ->select();
- $Count = 0;
- foreach ($result as $item) {
- if ($item['fedding_status'] === '已投料') {
- $Count++;
- }
- }
- if($result==[]){
- $res['data']=[['name'=>'已投料','value'=>0]];
- }else{
- $res['data']=[['name'=>'已投料','value'=>$Count]];
- }
- $res['status']=0;
- $res['msg']='';
- return json($res);
- }
- }
|