我想在管理面板中输入一个输入,您可以使用它在 db 中的几个表中增加/减少价格 %

I want to make an input in the admin panel with which you can increase / decrease prices in several tables in db by %

我想在管理面板中进行输入,您可以使用它在数 table 秒内以 % 为单位增加/减少价格。 目前,我是通过过滤器

    {
        return [
            new TwigSimpleFilter('price_kiev', [$this, 'formatPriceKiev'])
        ];
    }
    public function getPriceEditKiev()
    {
        $result =  DB::table('another_pricelist_edit')->select('price_edit_kiev')->where('id', 1)->first();
        return $result->price_edit_kiev;
    }
    public function formatPriceKiev($number)
    {
        $a =  $this->getPriceEditKiev();
        if ($a >= 1) {
            $price = $number + $number / 100 * $a;
            return round($price, -1);
        }else{
            return $number;
        }
    }

标记:

<td class="column-3">
{{ item.price_kiev_1 | price_kiev | number_format(0, '', ' ' ) }}</td>

管理面板 tables: 在我输入过滤器编号的地方输入,我想重新制作它以便使用它按百分比更改 table 中的价格:

简而言之,我如何在管理面板中进行输入以更新数据库中 table 中的价格? 也许有类似的攻略,不胜感激

sql 像这样:

update 
  table1 
set 
  table1.price = (price + price)/100 * input;
select 
  * 
from 
  table1;

哪里 -> 输入:num %

您只需要在控制器中执行一项专用操作和 ajax 处理程序。

  1. 渲染操作HTML
  2. ajax 提交表单时处理请求的处理程序

注: Please change all the paths and the name according to your plugin

Add action and ajax handler plugins/hardiksatasiya/so/controllers/Items.php

class Items extends Controller
{
    // other code ....

    public function updateTable() {
        // we want to show our menu as active
        BackendMenu::setContext('HardikSatasiya.SO', 'main-menu-item-main', 'side-menu-item-update-items');
    }

    public function onUpdateTableAjax() {
        $value = post('update_value');

        if(!$value) {
            Flash::error("please enter value");    
            return;
        }

        // write your table with your logic
        Item::query()->update([
            'value' => \DB::raw("value * $value") 
             // please sanitize post input and use here we just used it here as demo
        ]);

        Flash::success("Successfuly updated tabel with value: $value");
    }

}

Add HTML markup plugins/hardiksatasiya/so/controllers/items/updatetable.htm

<form 
    class="form-elements" 
    data-request="onUpdateTableAjax" 
    data-request-flash
>
  <div class="form-group span-left">
      <label>Update Table</label>
      <input type="text" name="update_value" value="" class="form-control" />
  </div>

  <div class="form-group span-left">
    <button type="submit" class="btn btn-default">Update Table</button>
  </div>
</form>

现在你还需要在前端显示这个action/html这样用户就可以去那里所以我们设置菜单项

update plugins/hardiksatasiya/so/plugin.yaml : side-menu-item-update-items <- we are adding this menu item

plugin:
    name: 'hardiksatasiya.so::lang.plugin.name'
    description: 'hardiksatasiya.so::lang.plugin.description'
    author: hardikSatasiya
    icon: oc-icon-star
    homepage: ''
navigation:
    main-menu-item-main:
        label: Items
        url: hardiksatasiya/so/items
        icon: icon-star
        sideMenu:
            side-menu-item-main:
                label: Items
                url: hardiksatasiya/so/items
                icon: icon-star
            side-menu-item-update-items:
                label: Settings
                url: hardiksatasiya/so/items/updatetable
                icon: icon-sliders

Please check the video for the output result

如有疑问请评论。