Printingone.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;javascript:;
  5. use Think\Exception;
  6. /** 首页接口*/
  7. class Printingone extends Api{
  8. protected $noNeedLogin = ['*'];
  9. protected $noNeedRight = ['*'];
  10. /** 首页 */
  11. public function index(){$this->success('湖州油墨api接口成功访问');}
  12. //车间列表表头字段
  13. function generateColumns() {
  14. return [
  15. ['name' => '批次号', 'id' => 'bach', 'width' => '10', 'autoWrap' => "true", 'textAlign' => 'left'],
  16. ['name' => '配方名称', 'id' => 'name', 'width' => '20', 'textAlign' => 'left'],
  17. ['name' => '机台', 'id' => 'machine', 'width' => '10', 'autoWrap' => "true", 'textAlign' => 'left'],
  18. ['name' => '生产量(kg)', 'id' => 'number', 'width' => '10', 'autoWrap' => "true", 'textAlign' => 'left'],
  19. ['name' => '扩单重量', 'id' => 'kuodan', 'width' => '13', 'autoWrap' => "true", 'textAlign' => 'left'],
  20. ['name' => '创建时间', 'id' => 'create', 'width' => '17', 'autoWrap' => "true", 'textAlign' => 'left'],
  21. ['name' => '是否投料', 'id' => 'fedding_status', 'width' => '10', 'autoWrap' => "true",'textAlign' => 'left'],
  22. ];
  23. }
  24. // 通用的作业票列表方法
  25. public function generateWorkshopList($machineType) {
  26. // 获取当前日期
  27. $today = date('Y-m-d 23:59:59');
  28. // 计算五天前的日期
  29. $fiveDaysAgo = date('Y-m-d 00:00:00');
  30. $result = Db::connect('minnongyun')->table('mn_task')->alias('t')
  31. ->field('
  32. t.name,
  33. t.bach,
  34. t.machine,
  35. t.number,
  36. t.create,
  37. t.kuodan,
  38. CASE WHEN f.bach IS NULL THEN \'未投料\' ELSE \'已投料\' END AS fedding_status
  39. ')
  40. ->join('mn_feeding f','t.bach = f.bach','LEFT')
  41. ->where('t.machine', 'like', '%' . $machineType . '%')
  42. ->where('t.create', '>=', $fiveDaysAgo)
  43. ->where('t.create', '<=', $today)
  44. ->group('t.create')
  45. ->order('t.create', 'desc')
  46. ->select();
  47. //echo "<pre>";print_r($result);echo "<pre>";
  48. $new_result = [];
  49. $new_result['columns'] = $this->generateColumns();
  50. if (empty($result)) {
  51. $res['status'] = 0;
  52. $res['msg'] = '';
  53. // 手动创建一个空的行数据
  54. $new_result['rows'][] = [
  55. 'name' => '-',
  56. 'bach' => '-',
  57. 'machine' => '-',
  58. 'number' => '-',
  59. 'kuodan' => '-',
  60. 'create' => '-',
  61. 'fedding_status' => '-',
  62. ];
  63. $res['data'] = $new_result;
  64. return json($res);
  65. }
  66. $color = 'rgb(91, 197, 106)';
  67. foreach ($result as $key => $value) {
  68. $new_result['rows'][$key]['name'] = $value['name'];
  69. $new_result['rows'][$key]['bach'] = '24-'.$value['bach'];
  70. $new_result['rows'][$key]['machine'] = mb_substr($value['machine'], 3);
  71. $new_result['rows'][$key]['number'] = $value['number'];
  72. $new_result['rows'][$key]['kuodan'] = $value['kuodan'];
  73. $new_result['rows'][$key]['create'] = $value['create'];
  74. $new_result['rows'][$key]['fedding_status'] = $value['fedding_status'];
  75. if($value['fedding_status'] == '已投料'){
  76. $new_result['rows'][$key]['name_color'] = $color;
  77. $new_result['rows'][$key]['bach_color'] = $color;
  78. $new_result['rows'][$key]['machine_color'] = $color;
  79. $new_result['rows'][$key]['number_color'] = $color;
  80. $new_result['rows'][$key]['kuodan_color'] = $color;
  81. $new_result['rows'][$key]['create_color'] = $color;
  82. $new_result['rows'][$key]['fedding_status_color'] = $color;
  83. }
  84. }
  85. $res['status'] = 0;
  86. $res['msg'] = '';
  87. $res['data'] = $new_result;
  88. return json($res);
  89. }
  90. // 甲类车间作业票列表->接口
  91. public function jl_workshops() {
  92. return $this->generateWorkshopList('甲类');
  93. }
  94. //甲类作业票数量->接口
  95. public function jl_zypsl(){
  96. // 获取当前日期
  97. $today = date('Y-m-d 23:59:59');
  98. // 计算五天前的日期
  99. $fiveDaysAgo = date('Y-m-d 00:00:00');
  100. $result = Db::connect('minnongyun')->table('mn_task')->alias('t')
  101. ->field('
  102. t.name,
  103. t.bach,
  104. t.machine,
  105. t.number,
  106. t.create,
  107. t.kuodan,
  108. CASE WHEN f.bach IS NULL THEN \'未投料\' ELSE \'已投料\' END AS fedding_status
  109. ')
  110. ->join('mn_feeding f','t.bach = f.bach','LEFT')
  111. ->where('t.machine', 'like', '%' . '甲类' . '%')
  112. ->where('t.create', '>=', $fiveDaysAgo)
  113. ->where('t.create', '<=', $today)
  114. ->group('t.create')
  115. ->order('t.create', 'desc')
  116. ->count('t.bach');
  117. if($result==[]){
  118. $res['data']=[['name'=>'作业票','value'=>0]];
  119. }else{
  120. $res['data']=[['name'=>'作业票','value'=>$result]];
  121. }
  122. $res['status']=0;
  123. $res['msg']='';
  124. return json($res);
  125. }
  126. //甲类未投料数量->接口
  127. public function jl_weitsl(){
  128. // 获取当前日期
  129. $today = date('Y-m-d 23:59:59');
  130. // 计算五天前的日期
  131. $fiveDaysAgo = date('Y-m-d 00:00:00');
  132. $result = Db::connect('minnongyun')->table('mn_task')->alias('t')
  133. ->field('
  134. t.name,
  135. t.bach,
  136. t.machine,
  137. t.number,
  138. t.create,
  139. t.kuodan,
  140. CASE WHEN f.bach IS NULL THEN \'未投料\' ELSE \'已投料\' END AS fedding_status
  141. ')
  142. ->join('mn_feeding f','t.bach = f.bach','LEFT')
  143. ->where('t.machine', 'like', '%' . '甲类' . '%')
  144. ->where('t.create', '>=', $fiveDaysAgo)
  145. ->where('t.create', '<=', $today)
  146. ->group('t.create')
  147. ->order('t.create', 'desc')
  148. ->select();
  149. $Count = 0;
  150. foreach ($result as $item) {
  151. if ($item['fedding_status'] === '未投料') {
  152. $Count++;
  153. }
  154. }
  155. if($result==[]){
  156. $res['data']=[['name'=>'未投料','value'=>0]];
  157. }else{
  158. $res['data']=[['name'=>'未投料','value'=>$Count]];
  159. }
  160. $res['status']=0;
  161. $res['msg']='';
  162. return json($res);
  163. }
  164. //甲类已投料数量->接口
  165. public function jl_yitsl(){
  166. // 获取当前日期
  167. $today = date('Y-m-d 23:59:59');
  168. // 计算五天前的日期
  169. $fiveDaysAgo = date('Y-m-d 00:00:00');
  170. $result = Db::connect('minnongyun')->table('mn_task')->alias('t')
  171. ->field('
  172. t.name,
  173. t.bach,
  174. t.machine,
  175. t.number,
  176. t.create,
  177. t.kuodan,
  178. CASE WHEN f.bach IS NULL THEN \'未投料\' ELSE \'已投料\' END AS fedding_status
  179. ')
  180. ->join('mn_feeding f','t.bach = f.bach','LEFT')
  181. ->where('t.machine', 'like', '%' . '甲类' . '%')
  182. ->where('t.create', '>=', $fiveDaysAgo)
  183. ->where('t.create', '<=', $today)
  184. ->group('t.create')
  185. ->order('t.create', 'desc')
  186. ->select();
  187. $Count = 0;
  188. foreach ($result as $item) {
  189. if ($item['fedding_status'] === '已投料') {
  190. $Count++;
  191. }
  192. }
  193. if($result==[]){
  194. $res['data']=[['name'=>'已投料','value'=>0]];
  195. }else{
  196. $res['data']=[['name'=>'已投料','value'=>$Count]];
  197. }
  198. $res['status']=0;
  199. $res['msg']='';
  200. return json($res);
  201. }
  202. // 丙类车间作业票列表->接口
  203. public function bl_workshops() {
  204. return $this->generateWorkshopList('丙类');
  205. }
  206. //丙类作业票数量->接口
  207. public function bl_zypsl(){
  208. // 获取当前日期
  209. $today = date('Y-m-d 23:59:59');
  210. // 计算五天前的日期
  211. $fiveDaysAgo = date('Y-m-d 00:00:00');
  212. $result = Db::connect('minnongyun')->table('mn_task')->alias('t')
  213. ->field('
  214. t.name,
  215. t.bach,
  216. t.machine,
  217. t.number,
  218. t.create,
  219. t.kuodan,
  220. CASE WHEN f.bach IS NULL THEN \'未投料\' ELSE \'已投料\' END AS fedding_status
  221. ')
  222. ->join('mn_feeding f','t.bach = f.bach','LEFT')
  223. ->where('t.machine', 'like', '%' . '丙类' . '%')
  224. ->where('t.create', '>=', $fiveDaysAgo)
  225. ->where('t.create', '<=', $today)
  226. ->group('t.create')
  227. ->order('t.create', 'desc')
  228. ->count('t.bach');
  229. if($result==[]){
  230. $res['data']=[['name'=>'作业票','value'=>0]];
  231. }else{
  232. $res['data']=[['name'=>'作业票','value'=>$result]];
  233. }
  234. $res['status']=0;
  235. $res['msg']='';
  236. return json($res);
  237. }
  238. //丙类未投料数量->接口
  239. public function bl_weitsl(){
  240. // 获取当前日期
  241. $today = date('Y-m-d 23:59:59');
  242. // 计算五天前的日期
  243. $fiveDaysAgo = date('Y-m-d 00:00:00');
  244. $result = Db::connect('minnongyun')->table('mn_task')->alias('t')
  245. ->field('
  246. t.name,
  247. t.bach,
  248. t.machine,
  249. t.number,
  250. t.create,
  251. t.kuodan,
  252. CASE WHEN f.bach IS NULL THEN \'未投料\' ELSE \'已投料\' END AS fedding_status
  253. ')
  254. ->join('mn_feeding f','t.bach = f.bach','LEFT')
  255. ->where('t.machine', 'like', '%' . '丙类' . '%')
  256. ->where('t.create', '>=', $fiveDaysAgo)
  257. ->where('t.create', '<=', $today)
  258. ->group('t.create')
  259. ->order('t.create', 'desc')
  260. ->select();
  261. $Count = 0;
  262. foreach ($result as $item) {
  263. if ($item['fedding_status'] === '未投料') {
  264. $Count++;
  265. }
  266. }
  267. if($result==[]){
  268. $res['data']=[['name'=>'未投料','value'=>0]];
  269. }else{
  270. $res['data']=[['name'=>'未投料','value'=>$Count]];
  271. }
  272. $res['status']=0;
  273. $res['msg']='';
  274. return json($res);
  275. }
  276. //丙类已投料数量->接口
  277. public function bl_yitsl(){
  278. // 获取当前日期
  279. $today = date('Y-m-d 23:59:59');
  280. // 计算五天前的日期
  281. $fiveDaysAgo = date('Y-m-d 00:00:00');
  282. $result = Db::connect('minnongyun')->table('mn_task')->alias('t')
  283. ->field('
  284. t.name,
  285. t.bach,
  286. t.machine,
  287. t.number,
  288. t.create,
  289. t.kuodan,
  290. CASE WHEN f.bach IS NULL THEN \'未投料\' ELSE \'已投料\' END AS fedding_status
  291. ')
  292. ->join('mn_feeding f','t.bach = f.bach','LEFT')
  293. ->where('t.machine', 'like', '%' . '丙类' . '%')
  294. ->where('t.create', '>=', $fiveDaysAgo)
  295. ->where('t.create', '<=', $today)
  296. ->group('t.create')
  297. ->order('t.create', 'desc')
  298. ->select();
  299. $Count = 0;
  300. foreach ($result as $item) {
  301. if ($item['fedding_status'] === '已投料') {
  302. $Count++;
  303. }
  304. }
  305. if($result==[]){
  306. $res['data']=[['name'=>'已投料','value'=>0]];
  307. }else{
  308. $res['data']=[['name'=>'已投料','value'=>$Count]];
  309. }
  310. $res['status']=0;
  311. $res['msg']='';
  312. return json($res);
  313. }
  314. }