瀏覽代碼

1,新增产能负载

cloud 1 月之前
父節點
當前提交
8ea5ed9ec0

+ 24 - 0
application/admin/controller/CapacityLoad.php

@@ -0,0 +1,24 @@
+<?php
+
+namespace app\admin\controller;
+
+use app\common\controller\Backend;
+
+/**
+ * 产能负载管理
+ *
+ * @icon fa fa-bar-chart
+ */
+class CapacityLoad extends Backend
+{
+    /**
+     * @var \app\admin\model\CapacityLoad
+     */
+    protected $model = null;
+
+    public function _initialize()
+    {
+        parent::_initialize();
+        $this->model = new \app\admin\model\CapacityLoad;
+    }
+}

+ 10 - 0
application/admin/lang/zh-cn/capacity_load.php

@@ -0,0 +1,10 @@
+<?php
+
+return [
+    'Name'       => '名称',
+    'Capacity'   => '产能',
+    'Percentage' => '百分比',
+    'Weigh'      => '排序',
+    'Createtime' => '创建时间',
+    'Updatetime' => '更新时间',
+];

+ 14 - 0
application/admin/model/CapacityLoad.php

@@ -0,0 +1,14 @@
+<?php
+
+namespace app\admin\model;
+
+use think\Model;
+
+class CapacityLoad extends Model
+{
+    protected $name = 'capacity_load';
+    protected $autoWriteTimestamp = 'integer';
+    protected $createTime = 'createtime';
+    protected $updateTime = 'updatetime';
+    protected $deleteTime = false;
+}

+ 32 - 0
application/admin/view/capacity_load/add.html

@@ -0,0 +1,32 @@
+<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Name')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-name" class="form-control" name="row[name]" type="text" data-rule="required">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Capacity')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-capacity" class="form-control" name="row[capacity]" type="text" data-rule="required" placeholder="例如:300K">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Percentage')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-percentage" min="0" max="100" step="0.01" class="form-control" name="row[percentage]" type="number" data-rule="required" placeholder="0 - 100">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Weigh')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-weigh" class="form-control" name="row[weigh]" type="number" value="0">
+        </div>
+    </div>
+    <div class="form-group layer-footer">
+        <label class="control-label col-xs-12 col-sm-2"></label>
+        <div class="col-xs-12 col-sm-8">
+            <button type="submit" class="btn btn-primary btn-embossed disabled">{:__('OK')}</button>
+        </div>
+    </div>
+</form>

+ 32 - 0
application/admin/view/capacity_load/edit.html

@@ -0,0 +1,32 @@
+<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Name')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-name" class="form-control" name="row[name]" type="text" value="{$row.name|htmlentities}" data-rule="required">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Capacity')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-capacity" class="form-control" name="row[capacity]" type="text" value="{$row.capacity|htmlentities}" data-rule="required">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Percentage')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-percentage" min="0" max="100" step="0.01" class="form-control" name="row[percentage]" type="number" value="{$row.percentage|htmlentities}" data-rule="required">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Weigh')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-weigh" class="form-control" name="row[weigh]" type="number" value="{$row.weigh|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group layer-footer">
+        <label class="control-label col-xs-12 col-sm-2"></label>
+        <div class="col-xs-12 col-sm-8">
+            <button type="submit" class="btn btn-primary btn-embossed disabled">{:__('OK')}</button>
+        </div>
+    </div>
+</form>

+ 18 - 0
application/admin/view/capacity_load/index.html

@@ -0,0 +1,18 @@
+<div class="panel panel-default panel-intro">
+    {:build_heading()}
+
+    <div class="panel-body">
+        <div class="widget-body no-padding">
+            <div id="toolbar" class="toolbar">
+                <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}"><i class="fa fa-refresh"></i></a>
+                <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('capacity_load/add')?'':'hide'}" title="{:__('Add')}"><i class="fa fa-plus"></i> {:__('Add')}</a>
+                <a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('capacity_load/edit')?'':'hide'}" title="{:__('Edit')}"><i class="fa fa-pencil"></i> {:__('Edit')}</a>
+                <a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('capacity_load/del')?'':'hide'}" title="{:__('Delete')}"><i class="fa fa-trash"></i> {:__('Delete')}</a>
+            </div>
+            <table id="table" class="table table-striped table-bordered table-hover table-nowrap"
+                   data-operate-edit="{:$auth->check('capacity_load/edit')}"
+                   data-operate-del="{:$auth->check('capacity_load/del')}" width="100%">
+            </table>
+        </div>
+    </div>
+</div>

+ 13 - 0
application/api/controller/Index.php

@@ -3,6 +3,7 @@
 namespace app\api\controller;
 
 use app\admin\model\BannerModel;
+use app\admin\model\CapacityLoad;
 use app\admin\model\CompanyInfo;
 use app\admin\model\FactoryCategoryModel;
 use app\admin\model\FactoryModel;
@@ -108,6 +109,18 @@ class Index extends Api
         $this->success('ok', $companyInfo->toArray());
     }
 
+    /**
+     * 获取产能负载列表
+     */
+    public function capacity_load()
+    {
+        $list = CapacityLoad::field('id,name,capacity,percentage')
+            ->order('weigh', 'desc')
+            ->order('id', 'asc')
+            ->select();
+        $this->success('ok', collection($list)->toArray());
+    }
+
     public function factory_category(){
         $page = $this->request->param("page", 1);
         $limit = $this->request->param("limit", 10);

+ 39 - 0
database/migrations/20260814_create_capacity_load.sql

@@ -0,0 +1,39 @@
+CREATE TABLE IF NOT EXISTS `fa_capacity_load` (
+    `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
+    `name` VARCHAR(100) NOT NULL COMMENT '名称',
+    `capacity` VARCHAR(100) NOT NULL COMMENT '产能',
+    `percentage` DECIMAL(5,2) UNSIGNED NOT NULL COMMENT '百分比',
+    `weigh` INT NOT NULL DEFAULT 0 COMMENT '排序',
+    `createtime` BIGINT NULL DEFAULT NULL COMMENT '创建时间',
+    `updatetime` BIGINT NULL DEFAULT NULL COMMENT '更新时间',
+    PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='产能负载';
+
+INSERT IGNORE INTO `fa_auth_rule`
+(`type`, `pid`, `name`, `title`, `icon`, `url`, `condition`, `remark`, `ismenu`, `menutype`, `extend`, `py`, `pinyin`, `createtime`, `updatetime`, `weigh`, `status`)
+VALUES
+('file', 0, 'capacity_load', '产能负载', 'fa fa-bar-chart', '', '', '', 1, NULL, '', 'cnfz', 'channengfuza', UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), 0, 'normal');
+
+SET @capacity_load_pid = (SELECT `id` FROM `fa_auth_rule` WHERE `name` = 'capacity_load' LIMIT 1);
+
+INSERT IGNORE INTO `fa_auth_rule`
+(`type`, `pid`, `name`, `title`, `icon`, `url`, `condition`, `remark`, `ismenu`, `menutype`, `extend`, `py`, `pinyin`, `createtime`, `updatetime`, `weigh`, `status`)
+VALUES
+('file', @capacity_load_pid, 'capacity_load/index', '查看', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), 0, 'normal'),
+('file', @capacity_load_pid, 'capacity_load/add', '添加', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), 0, 'normal'),
+('file', @capacity_load_pid, 'capacity_load/edit', '编辑', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), 0, 'normal'),
+('file', @capacity_load_pid, 'capacity_load/del', '删除', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), 0, 'normal'),
+('file', @capacity_load_pid, 'capacity_load/multi', '批量更新', 'fa fa-circle-o', '', '', '', 0, NULL, '', '', '', UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), 0, 'normal');
+
+SET @capacity_load_rules = (
+    SELECT GROUP_CONCAT(`id` ORDER BY `id` SEPARATOR ',')
+    FROM `fa_auth_rule`
+    WHERE `name` IN ('capacity_load', 'capacity_load/index', 'capacity_load/add', 'capacity_load/edit', 'capacity_load/del', 'capacity_load/multi')
+);
+UPDATE `fa_auth_group`
+SET `rules` = CONCAT_WS(',', NULLIF(CONVERT(`rules` USING utf8mb4), ''), CONVERT(@capacity_load_rules USING utf8mb4))
+WHERE `id` = 2
+  AND FIND_IN_SET(
+      CONVERT(@capacity_load_pid USING utf8mb4) COLLATE utf8mb4_unicode_ci,
+      CONVERT(`rules` USING utf8mb4) COLLATE utf8mb4_unicode_ci
+  ) = 0;

+ 6 - 2
database/migrations/20260814_create_company_info.sql

@@ -63,5 +63,9 @@ SET @company_info_rules = (
     WHERE `name` IN ('company_info', 'company_info/index', 'company_info/add', 'company_info/edit', 'company_info/del', 'company_info/multi')
 );
 UPDATE `fa_auth_group`
-SET `rules` = CONCAT_WS(',', NULLIF(`rules`, ''), @company_info_rules)
-WHERE `id` = 2 AND FIND_IN_SET(@company_info_pid, `rules`) = 0;
+SET `rules` = CONCAT_WS(',', NULLIF(CONVERT(`rules` USING utf8mb4), ''), CONVERT(@company_info_rules USING utf8mb4))
+WHERE `id` = 2
+  AND FIND_IN_SET(
+      CONVERT(@company_info_pid USING utf8mb4) COLLATE utf8mb4_unicode_ci,
+      CONVERT(`rules` USING utf8mb4) COLLATE utf8mb4_unicode_ci
+  ) = 0;

+ 6 - 2
database/migrations/20260814_create_company_info_only.sql

@@ -37,5 +37,9 @@ SET @company_info_rules = (
     WHERE `name` IN ('company_info', 'company_info/index', 'company_info/add', 'company_info/edit', 'company_info/del', 'company_info/multi')
 );
 UPDATE `fa_auth_group`
-SET `rules` = CONCAT_WS(',', NULLIF(`rules`, ''), @company_info_rules)
-WHERE `id` = 2 AND FIND_IN_SET(@company_info_pid, `rules`) = 0;
+SET `rules` = CONCAT_WS(',', NULLIF(CONVERT(`rules` USING utf8mb4), ''), CONVERT(@company_info_rules USING utf8mb4))
+WHERE `id` = 2
+  AND FIND_IN_SET(
+      CONVERT(@company_info_pid USING utf8mb4) COLLATE utf8mb4_unicode_ci,
+      CONVERT(`rules` USING utf8mb4) COLLATE utf8mb4_unicode_ci
+  ) = 0;

+ 47 - 0
public/assets/js/backend/capacity_load.js

@@ -0,0 +1,47 @@
+define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
+    var Controller = {
+        index: function () {
+            Table.api.init({
+                extend: {
+                    index_url: 'capacity_load/index' + location.search,
+                    add_url: 'capacity_load/add',
+                    edit_url: 'capacity_load/edit',
+                    del_url: 'capacity_load/del',
+                    multi_url: 'capacity_load/multi',
+                    table: 'capacity_load'
+                }
+            });
+
+            var table = $('#table');
+            table.bootstrapTable({
+                url: $.fn.bootstrapTable.defaults.extend.index_url,
+                pk: 'id',
+                sortName: 'weigh',
+                columns: [[
+                    {checkbox: true},
+                    {field: 'id', title: __('Id')},
+                    {field: 'name', title: __('Name'), operate: 'LIKE'},
+                    {field: 'capacity', title: __('Capacity'), operate: 'LIKE'},
+                    {field: 'percentage', title: __('Percentage'), operate: false, formatter: function (value) { return value + '%'; }},
+                    {field: 'weigh', title: __('Weigh'), operate: false},
+                    {field: 'createtime', title: __('Createtime'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime},
+                    {field: 'updatetime', title: __('Updatetime'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime},
+                    {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
+                ]]
+            });
+            Table.api.bindevent(table);
+        },
+        add: function () {
+            Controller.api.bindevent();
+        },
+        edit: function () {
+            Controller.api.bindevent();
+        },
+        api: {
+            bindevent: function () {
+                Form.api.bindevent($('form[role=form]'));
+            }
+        }
+    };
+    return Controller;
+});