【VUE】 导出excel,Export2Excel样式修改,复杂表头,多级表头

Continue Read..
<el-form-item>
<el-button size="small" type="success" @click="outExe()"><i class="el-icon-search"/>导出</el-button>
</el-form-item>

outExe() {
  this.$confirm('此操作将导出excel文件, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
  }).then(() => {
this.listLoading = true
getList({ actiontype: 'order_count_exp',ctype:this.search.ctype,counttime:this.search.counttime}, this.listQuery).then(response => {
  if (response.resultCode == 200) {
import('@/vendor/Export2ExcelStyle').then(excel => {
  const multiHeader = response.data.multiHeader
  const tHeader = response.data.headArr
  const filterVal = response.data.filterVal
  const list = response.data.list
  if (list.length == 0) {
this.$message.error('没有数据,不能导出');
return;
  }
  const merges = ['A1:A2', 'B1:B2', 'C1:C2', 'D1:D2', 'E1:E2', 'F1:F2', 'G1:G2', 'H1:K1', 'L1:P1']
  // const title = 'titile'
  // console.log(filterVal, list);
  const data = this.formatJson(filterVal, list)
  excel.export_json_to_excel({
// title,
multiHeader,
header: tHeader, 
data: data,
filename: response.data.fileName,
merges, 
autoWidth: false,
bookType: 'xlsx',
  })
})
  }else{
this.$message({
  message: response.data,
  type: 'error'
})
  }
  this.listLoading = false
}).catch(error => {
  console.log(error)
})
  }).catch(() => {

  });
},
formatJson(filterVal, jsonData) {
  return jsonData.map(v => filterVal.map(j => {
if (j === 'timestamp') {
  return parseTime(v[j])
} else {
  return v[j]
}
  }))
},



$data['fileName'] = 'love_order_count_exp_' . date("Y-m-d");
$data['filterVal'] = ['id', 'ctype_name', 'counttime', 'orderfee', 'payfee', 'refundfee', 'truefee', 'otype_1', 'otype_2', 'otype_3', 'otype_4', 'ptype_1', 'ptype_2', 'ptype_3', 'ptype_4', 'ptype_5'];
$data['multiHeader'] = [['序号', '类型', '日期', '订单总额', '实收', '退款', '净收入', '类型', '',  '',  '', '来源']];
$data['headArr'] = ['', '', '', '', '', '', '', '活动', '会员', '认证', '一周CP', '微信', '小程序', '后台', '触屏', 'APP'];

这里要注意multiHeader数组中,类型后面空了3个,是因为类型这栏合并了4列,下面子类有4列,如果不空的话,会吧来源覆盖
headArr前面空了7列,是因为前7个不需要多级表头


点击查看原图

 

参考网址 

https://blog.csdn.net/weixin_43965143/article/details/106572755

https://www.jianshu.com/p/06521a9c75d8

 

js附件

Export2ExcelStyle.zip



声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

【nginx】得到IP地址

Continue Read..

nginx 

  proxy_set_header X-Real-IP $remote_addr;

  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

  proxy_set_header Host $host;

  real_ip_header    X-Forwarded-For;

  real_ip_recursive on;

 

php 

<?php

echo long2ip(_get_ip());

function _get_ip($full = false) {

        if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) {

            if ($full == true)

                return sprintf("%u\n", ip2long($_SERVER["HTTP_X_FORWARDED_FOR"]));

            $tmp_ips = explode(',', $_SERVER["HTTP_X_FORWARDED_FOR"]);

            $ip = array_shift($tmp_ips);

        }

        else if (isset($_SERVER["HTTP_CLIENT_IP"]))

            $ip = $_SERVER["HTTP_CLIENT_IP"];

        else if (isset($_SERVER["REMOTE_ADDR"]))

            $ip = $_SERVER["REMOTE_ADDR"];

        else if (getenv("HTTP_X_FORWARDED_FOR"))

            $ip = getenv("HTTP_X_FORWARDED_FOR");

        else if (getenv("HTTP_CLIENT_IP"))

            $ip = getenv("HTTP_CLIENT_IP");

        else if (getenv("REMOTE_ADDR"))

            $ip = getenv("REMOTE_ADDR");

        else

            $ip = "Unknown";

        return sprintf("%u\n", ip2long($ip));

    }


声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

【thinkphp5】ThinkPHP5如何使用build.php

Continue Read..

进入application

php ../think build --config ..\build.php

 

 

build.php里面写需要生成的配置

 

 

return [
    // 生成应用公共文件
    '__file__' => ['common.php''config.php''database.php'],

    // 定义demo模块的自动生成 (按照实际定义的文件名生成)
    'xxx'     => [
        '__file__'   => ['common.php'],
        '__dir__'    => ['behavior''controller''model''view'],
        'controller' => ['Index''Test''UserType'],
        'model'      => ['User''UserType'],
        'view'       => ['index/index'],
    ],
    // 其他更多的模块定义
];

声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

【php】RabbitMQ+supervisord+php消息队列

Continue Read..
CentOS7安装RabbitMQ

由于rabbitmq是基于erlang语言开发的,所以必须先安装erlang。
安装依赖
yum -y install gcc glibc-devel make ncurses-devel openssl-devel xmlto perl wget gtk2-devel binutils-devel

erlang官网:

https://www.erlang.org/downloads

下载(会比较慢,请耐心等待)

wget http://erlang.org/download/otp_src_22.0.tar.gz

移走

mv otp_src_22.0 /usr/local/

切换目录

cd /usr/local/otp_src_22.0/
 

创建即将安装的目录

mkdir ../erlang
 

配置安装路径

./configure --prefix=/usr/local/erlang

如果遇到这个错 你就假装没看到

点击查看原图
安装

make install

 

查看一下是否安装成功

ll /usr/local/erlang/bin
 

添加环境变量

echo 'export PATH=$PATH:/usr/local/erlang/bin' >> /etc/profile
 

刷新环境变量

source /etc/profile
 

甩一条命令

erl
 
点击查看原图
瞬间进入了一个未知的世界

在里面输入halt().命令退出来(那个点号别忘记)

点击查看原图



安装RabbitMQ
rabbitmq下载地址:

https://github.com/rabbitmq/rabbitmq-server/releases/tag/v3.7.15

 

下载

wget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.7.15/rabbitmq-server-generic-unix-3.7.15.tar.xz
 

由于是tar.xz格式的所以需要用到xz,没有的话就先安装 

yum install -y xz
 

第一次解压

/bin/xz -d rabbitmq-server-generic-unix-3.7.15.tar.xz
 

第二次解压

tar -xvf rabbitmq-server-generic-unix-3.7.15.tar
 

移走

mv rabbitmq_server-3.7.15/ /usr/local/
 

改名

mv /usr/local/rabbitmq_server-3.7.15  rabbitmq
 

配置环境变量

echo 'export PATH=$PATH:/usr/local/rabbitmq/sbin' >> /etc/profile
 

刷新环境变量

source /etc/profile
 

创建配置目录

mkdir /etc/rabbitmq
 

回到顶部
启动命令
启动:

rabbitmq-server -detached
 

停止:

rabbitmqctl stop
 

状态:

rabbitmqctl status
 

防火墙之类的请自行处理(5672和15672端口),反正我是从来不开防火墙。

 

回到顶部
WEB管理
开启web插件

rabbitmq-plugins enable rabbitmq_management
 

访问:http://127.0.0.1:15672/
点击查看原图 

默认账号密码:guest guest(这个账号只允许本机访问)

 

回到顶部
用户管理
查看所有用户

rabbitmqctl list_users
 

添加一个用户

rabbitmqctl add_user admin 123456
 

配置权限

rabbitmqctl set_permissions -p "/" admin ".*" ".*" ".*"
 

查看用户权限

rabbitmqctl list_user_permissions admin
 

设置tag

rabbitmqctl set_user_tags admin administrator
 

删除用户(安全起见,删除默认用户)

rabbitmqctl delete_user guest
 

回到顶部
登陆
配置好用户之后重启一下rabbit

然后就可以用新账号进行登陆

点击查看原图

 

 

安装supervisord

yum install epel-release

yum install -y supervisor

 

#yum -y install python-setuptools zlib

easy_install supervisor

echo_supervisord_conf > /etc/supervisord.conf

 

mkdir -p /data/etc/supervisord/

mkdir -p /data2/logs/supervisord/

chmod 777 /data2/logs/supervisord/

 

修改 /etc/supervisord.conf

sed -i -e "s#logfile=/tmp/supervisord.log#logfile=/data2/logs/supervisord/supervisord.log#g" /etc/supervisord.conf

sed -i -e "s#file=/tmp/supervisor.sock#file=/var/run/supervisor.sock#g" /etc/supervisord.conf

sed -i -e "s#pidfile=/tmp/supervisord.pid#pidfile=/var/run/supervisord.pid#g" /etc/supervisord.conf

sed -i -e "s#serverurl=unix:///tmp/supervisor.sock#serverurl=unix:///var/run/supervisor.sock#g" /etc/supervisord.conf

echo "[include]" >> /etc/supervisord.conf

echo "files = /data/www/supervisord/*.ini" >> /etc/supervisord.conf

 

 

 

操作脚本:

vi /usr/lib/systemd/system/supervisord.service

 

#输入下面内容,并保存

[Unit]

Description=Supervisord

After=network.target

 

[Service]

Type=forking

PIDFile=/var/run/supervisord.pid

ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf

ExecStop=/bin/kill -TERM $MAINPID

ExecReload=/bin/kill -HUP $MAINPID

Restart=always

 

[Install]

WantedBy=multi-user.target

保存

 

#修改权限

chmod +x /usr/lib/systemd/system/supervisord.service

 

systemctl enable supervisord.service

启用:systemctl start supervisord

 

#其它控制命令

systemctl stop supervisord

systemctl reload supervisord

 

查看进程列表:

systemctl status supervisord

#supervisorctl status

停止进程 mq_test_worker:

supervisorctl stop mq_test_worker:

开始进程 mq_test_worker::

supervisorctl start mq_test_worker:

 

 

启动程序如果提示:Starting supervisor: Error: Another program is already listening on a port that one of our HTTP servers is configured to use.  Shut this program down first before starting supervisord.

unlink /var/run/supervisor.sock

 

 

 

sudo chmod 777 /run

sudo chmod 777 /var/log

sudo touch /var/run/supervisor.sock

sudo chmod 777 /var/run/supervisor.sock

supervisord -c /etc/supervisord.conf

ps aux | grep supervisord

 

 

 

最后效果

supervisord -c /etc/supervisord.conf 开启supervisord服务

supervisorctl start mq_test_worker 开启需要常驻的脚本服务

执行脚本test.php

然后tail -f mq_test_worker.log 里面可以看到队列的数据

 

点击查看原图

 

 

代码附件 : msg_broker.zip

 

 参考网站

RabbitMQ:https://www.cnblogs.com/fengyumeng/p/11133924.html

supervisord(碰到的坑):

https://www.missshi.cn/api/view/blog/5aafcf405b925d681e000000

https://www.cnblogs.com/ruanraun/p/supervisor.html

https://blog.csdn.net/weixin_41762173/article/details/88901970

 

声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

【小程序】小程序页面定位(类似html锚点)

Continue Read..
goTo:function (id) {
        const q =wx.createSelectorQuery();
        q.select("#"+id).boundingClientRect();
        q.selectViewport().scrollOffset();
        q.exec((res)=>{
            if(res[0] && res[1]){
                console.log("跳转",res[0].top+res[1].scrollTop);
                wx.pageScrollTo({
                    scrollTop:res[0].top+res[1].scrollTop -100,
                    duration:300
                })
            }
        })
    },
    setToView:function (room_id, bed_id) {
        var toView = 'room_bed_'+ room_id + '_' + bed_id;
        console.log("toView===", toView);

        this.setData({
            toView: toView
        });
        var self = this;
        setTimeout(function () {
            console.log("self.data.toView===", self.data.toView);
            self.goTo(self.data.toView);
        }, 1000);

    }


声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

【php】win修改php-cgi.exe启动接口

Continue Read..
1、先要运行起php的cgi,由于本人用的win7系统,所以cmd先进的c盘(之前全扔c盘这就简单了~),访问到php路径中,输入
php-cgi.exe -b 127.0.0.1:9000
注意这里的-b 127.0.0.1:9000是指定cgi的监听端口,与上文中的Nginx配置要一致,如果有其他配置不记得之前php-cgi是那个端口,可以使用php-cgi.exe -h命令来查看配置(查看-b 后面的<address:port>)。想要查看所有被监听的端口则输入netstat -na

声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

【go】操作数据库

Continue Read..

目录结构

点击查看原图

 

@GOPATH

点击查看原图

 

 

CREATE TABLE `userinfo` (

  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,

  `name` varchar(20) NOT NULL DEFAULT '',

  `uid` int(10) unsigned NOT NULL DEFAULT '0',

  PRIMARY KEY (`id`)

) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8


 

1.go

package main
 
import (
	"conf"
	"fmt"
	// 或者
	// myDbConf "conf"
)
 
func main() {
	opend, db := conf.OpenDB()
	//opend, db := myDbConf.OpenDB()
 
	fmt.Println(db)
	if opend {
		fmt.Println("open success")
	} else {
		fmt.Println("open faile:")
	}
	// DeleteFromDB(db, 10)
	//QueryFromDB(db)
	//DeleteFromDB(db, 1)
	//UpdateDB(db, 5)
	conf.InsertToDB(db)
	//myDbConf.InsertToDB(db)
 
	//UpdateUID(db, 5)T
	//UpdateTime(db, 4)
 
}

 
 
 
dbConf.go
package dbConf
 
import (
	"crypto/md5"
	"database/sql"
	"encoding/hex"
	"fmt"
	"strconv"
	"time"
 
	_ "github.com/go-sql-driver/mysql"
)
 
const (
	DB_Driver = "root:root@tcp(127.0.0.1:3306)/test?charset=utf8"
)
 
func OpenDB() (success bool, db *sql.DB) {
	var isOpen bool
	db, err := sql.Open("mysql", DB_Driver)
	// fmt.Println(db)
	if err != nil {
		isOpen = false
	} else {
		isOpen = true
	}
	CheckErr(err)
	return isOpen, db
}
 
func InsertToDB(db *sql.DB) {
	uid := GetNowtimeMD5()
	// nowTimeStr := GetTime()
	stmt, err := db.Prepare("insert userinfo set name=?,uid=?")
	CheckErr(err)
	res, err := stmt.Exec("wangbiao", uid)
	CheckErr(err)
	id, err := res.LastInsertId()
	CheckErr(err)
	if err != nil {
		fmt.Println("插入数据失败")
	} else {
		fmt.Println("插入数据成功:", id)
	}
}
 
func QueryFromDB(db *sql.DB) {
	rows, err := db.Query("SELECT * FROM userinfo")
	CheckErr(err)
	if err != nil {
		fmt.Println("error:", err)
	} else {
	}
	for rows.Next() {
		var uid string
		var name string
 
		CheckErr(err)
		err = rows.Scan(&uid, &name)
		fmt.Println(name)
		fmt.Println(uid)
	}
}
 
func UpdateDB(db *sql.DB, uid string) {
	stmt, err := db.Prepare("update userinfo set name=? where uid=?")
	CheckErr(err)
	res, err := stmt.Exec("zhangqi", uid)
	affect, err := res.RowsAffected()
	fmt.Println("更新数据:", affect)
	CheckErr(err)
}
func DeleteFromDB(db *sql.DB, id int) {
	stmt, err := db.Prepare("delete from userinfo where id=?")
	CheckErr(err)
	res, err := stmt.Exec(id)
	affect, err := res.RowsAffected()
	fmt.Println("删除数据:", affect)
}
 
func CheckErr(err error) {
	if err != nil {
		panic(err)
		fmt.Println("err:", err)
	}
}
 
func GetTime() string {
	const shortForm = "2006-01-02 15:04:05"
	t := time.Now()
	temp := time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), t.Nanosecond(), time.Local)
	str := temp.Format(shortForm)
	fmt.Println(t)
	return str
}
 
func GetMD5Hash(text string) string {
	haser := md5.New()
	haser.Write([]byte(text))
	return hex.EncodeToString(haser.Sum(nil))
}
 
func GetNowtimeMD5() string {
	t := time.Now()
	timestamp := strconv.FormatInt(t.UTC().UnixNano(), 10)
	return GetMD5Hash(timestamp)
}
 mysql.zip

 

声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

【php】mysql跨库回滚

Continue Read..
CREATE TABLE afu.`test2` (
  `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  `name` VARCHAR(50) DEFAULT '',
  PRIMARY KEY (`id`)
) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
CREATE TABLE trade.`test2` (
  `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  `name` VARCHAR(50) DEFAULT '',
  PRIMARY KEY (`id`)
) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
<?php
/**
 * Created by PhpStorm.
 * User: cuzn
 * Date: 2018/12/28
 * Time: 19:10
 */


namespace app\afu\cron\department;

use app\afu\api\model\afu\Test2Model;
use app\afu\api\model\trade\Test1Model;
use PhpOffice\PhpSpreadsheet\Exception;

require_once __DIR__ . '/../../conf/config.inc.php';

echo "exec at " . date('Y-m-d H:i:s') . "\n";


$Test1Model = Test1Model::getInstance();


function addTest2($isBack = false){
    $Test2Model = Test2Model::getInstance();
    try {
        $Test2Model->begin();
    
        $ret = $Test2Model->insert([
            'name' => 'bbbbbbb'
        ]);
        if (!$isBack) {
            $Test2Model->commit();
            return true;
        } else {
            $Test2Model->rollback();
            return false;
        }
    } catch (Exception $e) {
        $Test2Model->rollback();
        throw $e;
        //return false;
    }
}


try {
    $Test1Model->begin();
    
    $ret = $Test1Model->insert([
        'name' => 'aaaaaa'
    ]);
    $ret2 = addTest2(false);
    var_dump($ret, $ret2);
    if ($ret && $ret2) {
        $Test1Model->commit();
    }else {
        $Test1Model->rollback();
    }
} catch (Exception $e) {
    //addTest2(1);
    $Test1Model->rollback();
    throw $e;
}


声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

【ajax】jquery.ajax上传文件

Continue Read..

Simple HTML

<input type="file" id="one-specific-file" name="one-specific-file">

Use as little as

$('#one-specific-file').ajaxfileupload({
  action: '/upload.php'
});

or as much as

$('input[type="file"]').ajaxfileupload({
  action: '/upload.php',
  valid_extensions : ['md','csv'],
  params: {
    extra: 'info'
  },
  onComplete: function(response) {
    console.log('custom handler for file:');
    alert(JSON.stringify(response));
  },
  onStart: function() {
    if(weWantedTo) return false; // cancels upload
  },
  onCancel: function() {
    console.log('no file selected');
  }

});

参考网址 https://github.com/jfeldstein/jQuery.AjaxFileUpload.js

jquery.ajaxfileupload.zip

【jquery】单选框选中事件

Continue Read..
$(function(){
$("input[name='level']").click(function(){
console.log(123);
getPriceAndRatio($('input[name="level"]:checked').val(), 0, 0);
});
});

声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权