Server : nginx/1.20.1
System : Linux iZ2ze9ojcl78uluczwag69Z 4.18.0-240.22.1.el8_3.x86_64 #1 SMP Thu Apr 8 19:01:30 UTC 2021 x86_64
User : www ( 1000)
PHP Version : 7.3.28
Disable Function : passthru,exec,system,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Directory :  /www/wwwroot/0531yanglao.com/app/admin/controller/
Upload File :
Current Directory [ Writeable ] Root Directory [ Writeable ]


Current File : /www/wwwroot/0531yanglao.com/app/admin/controller/Controller.php
<?php
declare (strict_types = 1);

namespace app\admin\controller;


use app\common\model\Recommend;
use think\helper\Arr;
use think\Request;

class Controller
{
    
    protected $request;
    //分页
    protected $page;
    //每页条数
    protected $limit;

    function __construct(Request $request)
    {
        
        $this->request = $request;
        $this->page = $this->request->param('page/d', 1);
        $this->limit = $this->request->param('limit/d', 15);

        //登录用户
        define('UID', admin_user_id());

        $this->request->filter(['trim']);//htmlspecialchars

        $this->init();
    }

    public function init(){}
    
    protected function _url($action = null, $param = [])
    {
        $action = is_null($action) ? 'index' : $action;
        
        return (string)url("/{$this->request->controller()}/$action", $param);
    }

    /**
     * 更新排序
     * @param unknown $model
     * @param array $data
     * @param string $field
     */
    //protected function _sort($model, array $data, $field = 'sort') {
    public function updateSort()
    {
        $data = $this->request->param('data/a');
        $table = $this->request->param('table');
        $recommend_position = $this->request->has('recommend_position') ? $this->request->param('recommend_position') : 0;
        $dir= '';
        if(strpos($table, '.')) {
            $tableArr = explode('.', $table);
            $table = end($tableArr);
            array_pop($tableArr);
            foreach ($tableArr as $item) {
                $dir .= $item . "\\";
            }
        }
        try {
            $ids = \phpTools\ArrayTools::array_col_values($data, 'id');
            $sorts = \phpTools\ArrayTools::array_col_values($data, 'sort');
            if($recommend_position) {
                $model = new Recommend();
                $table_type = strtolower($table);
                //清空原有数据
                //$model->where('table_type',$table_type)->where('r_id', $recommend_position)->
                $where = [];
                $where[] = ['table_type', '=', $table_type];
                $where[] = ['r_id', '=', $recommend_position];
                Recommend::del($where);
                $create_data = [];
                foreach($ids as $key=>$id) {
                    $create_data[] = [
                        'table_id' => $id,
                        'table_type' => $table_type,
                        'r_id' => $recommend_position,
                        'sort'  =>  intval($sorts[$key]),
                    ];

                }
                $model->saveAll($create_data);
            }else {
                $model = invoke("\\app\common\\model\\{$dir}" . ucfirst($table));
                $pk = $model->getPk();
                $updata_data = [];
                foreach($ids as $key=>$id) {
                    //$updata_data[] = [$pk => $id,'sort' => intval($sorts[$key])];
                    $info = $model::detail($id);
                    $info->sort = intval($sorts[$key]);
                    $info->save();
                }
                //$model->saveAll($updata_data);
            }

        }catch(\Exception $e) {
            return error($e->getMessage());
        }

        return success();
    }

    public function updateStatus()
    {
        $data = $this->request->param();
        $table = $this->request->param('table');
        $field = $this->request->param('field');

        try {
            $model = invoke("\\app\common\\model\\{$table}");
            $pk = $model->getPk();
            $info = $model::detail($data[$pk]);
            $info->$field = $data[$field];
            $info->save();

        }catch(\Exception $e) {
            return error($e->getMessage());
        }

        return success();
    }
}