fecmall 和 fecify 本质区别是什么?有什么不同

作为跨境电商系统,fecify和fecmall有很多的不同,主要体现在:

1.fecmall的界面,产品更多的面向程序员,fecify项目团队出品,有专业的设计,前端,以及后端力量,共同协作而成

2.面向用户群体不同,对于fecmall而言,fecmall面向程序员,开源免费,无在线技术支持,而fecify面向非技术人员,需要付费授权,有更好的技术支持保障,

3.fecify一共有2个后台,一个服务端后台,用户创建独立站店铺,创建店铺管理员,给店铺绑定插件应用,设置模板,以及设置店铺logo等,另外一个就是店铺后台,该后台类似于fecmall的后台,也就是某个独立站的后台,您可以将某个账号绑定到多个独立站,那么多个独立站的商家后台的管理,用一个账号切换即可

4.产品架构的不同,fecmall是一款单站商城,如果您需要五个商城,需要安装五次,而fecify是一款saas产品,安装一次,即可搭建N个(多个)独立站商城,这也是本质的区别。

 

5.fecify的每个独立站,都可以绑定独立的域名,域名对应前台和商家后台,服务端后台只能使用授权域名,商家后台的域名不限制。

6.fecify对标的产品,是shopify,有强大的装修界面,非常适合小白用户使用。

您可以通过拖拽,手动diy装配商城模板,实现的媲美shopify的装修卡片

fecify十月份发版,初版支持14款插件,详细参看:

https://www.fecify.com/addons.html

centos6 安装go框架gin的步骤,以及中间遇到的坑

我的环境是centos 6,安装go语言的文档参看:

centos6 – 安装 golang 1.9

安装完go语言后,安装gin框架,github地址为:https://github.com/gin-gonic/gin

通过readme的介绍,通过命令行安装:

go get github.com/gin-gonic/gin

结果发现,一直卡住,无法通过go get完成安装,最后查阅了资料发现是git版本的问题,参看:https://github.com/go-playground/validator/issues/224#issuecomment-165324546

然后我重新安装了git,参看文档:

centos6 安装 git2.7

然后,重新执行安装

[root@iZ942k2d5ezZ go]# go get -v  github.com/gin-gonic/gin

github.com/gin-gonic/gin (download)
github.com/gin-contrib/sse (download)
github.com/golang/protobuf (download)
github.com/ugorji/go (download)
Fetching https://gopkg.in/go-playground/validator.v8?go-get=1
Parsing meta tags from https://gopkg.in/go-playground/validator.v8?go-get=1 (status code 200)
get "gopkg.in/go-playground/validator.v8": found meta tag get.metaImport{Prefix:"gopkg.in/go-playground/validator.v8", VCS:"git", RepoRoot:"https://gopkg.in/go-playground/validator.v8"} at https://gopkg.in/go-playground/validator.v8?go-get=1
gopkg.in/go-playground/validator.v8 (download)
Fetching https://gopkg.in/yaml.v2?go-get=1
Parsing meta tags from https://gopkg.in/yaml.v2?go-get=1 (status code 200)
get "gopkg.in/yaml.v2": found meta tag get.metaImport{Prefix:"gopkg.in/yaml.v2", VCS:"git", RepoRoot:"https://gopkg.in/yaml.v2"} at https://gopkg.in/yaml.v2?go-get=1
gopkg.in/yaml.v2 (download)
github.com/mattn/go-isatty (download)
github.com/gin-contrib/sse
github.com/gin-gonic/gin/json
github.com/golang/protobuf/proto
github.com/ugorji/go/codec
gopkg.in/go-playground/validator.v8
github.com/gin-gonic/gin/binding
gopkg.in/yaml.v2
github.com/gin-gonic/gin/render
github.com/mattn/go-isatty
github.com/gin-gonic/gin
[root@iZ942k2d5ezZ go]# 

然后,创建g3.go文件,内容如下:

package main

import "github.com/gin-gonic/gin"

func main() {
        r := gin.Default()
        r.GET("/ping", func(c *gin.Context) {
                c.JSON(200, gin.H{
                        "message": "pong",
                })
        })
        r.Run("120.24.37.249:3000") // listen and serve on 0.0.0.0:8080
}

注意:

1.ip换成您自己的ip

2.iptables 开放3000端口

/sbin/iptables -I INPUT -p tcp --dport 3000 -j ACCEPT
/etc/rc.d/init.d/iptables save

 

执行Log

[root@iZ942k2d5ezZ golang]# go run g3.go 

[GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.

[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
 - using env:	export GIN_MODE=release
 - using code:	gin.SetMode(gin.ReleaseMode)

[GIN-debug] GET    /ping                     --> main.main.func1 (3 handlers)
[GIN-debug] Environment variable PORT is undefined. Using port :8080 by default
[GIN-debug] Listening and serving HTTP on :8080

访问:http://120.24.37.249:3000/ping

页面返回:

{"message":"pong"}

 

OK,成功。

 

 

 

centos6 – 安装 golang 1.9

1.下载安装包,地址为:https://golang.org/dl/ , 我的操作系统为centos6,我下载的是:go1.9.2.linux-amd64.tar.gz

cd /tools
wget https://redirector.gvt1.com/edgedl/go/go1.9.2.linux-amd64.tar.gz
tar -C /usr/local -xzf /usr/local/go1.9.2.linux-amd64.tar.gz

2.写入环境变量

如果 /root/go 文件夹不存在,则新建该文件夹

vim /etc/profile ,在最后另起新行添加下面的环境变量

export GOROOT=/usr/local/go
export GOPATH=/root/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

让环境变量生效:

source /etc/profile

这样,go安装就完成了。

 

 

 

centos6 安装 git2.7

在使用 go get 安装gin框架的时候,遇到了坑,centos 6 默认的git是1.7.1,导致安装一直卡住,后来查阅文章:https://github.com/go-playground/validator/issues/224 ,

发现,是centos自带的git版本太低的问题导致的,于是,卸掉git ,重新安装2.7.2

卸载Centos自带的git1.7.1
通过git –version查看系统带的版本,Cento6.5应该自带的是git版本是1.7.1

yum remove git

安装依赖:

yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
yum install gcc perl-ExtUtils-MakeMaker

下载git最新版本

cd /tools
wget https://www.kernel.org/pub/software/scm/git/git-2.7.2.tar.gz
tar xzf git-2.7.2.tar.gz

 

安装git,然后将其添加到环境变量,命令操作如下:

cd git-2.7.2
make prefix=/usr/local/git all
make prefix=/usr/local/git install
vim /etc/profile
// 在末尾新开一行填写下面的代码
export PATH=$PATH:/usr/local/git/bin
// :wq保存退出,然后执行下面的命令,让其生效
source /etc/profile

 

到这里就安装成功了,查看git版本号
git –version
git version 2.7.2

yii2 amqp 接收和发送数据(和外部系统对接)

  1. 配置queue(amqp)
'bootstrap' => [
        'queue', // The component registers own console commands
    ],
    
    'components' => [
        'queue' => [
            'class' => 'zhuravljov\yii\queue\amqp\Queue',
            'host'  => '192.168.221.56',
            'port'  => 5672,
            'user'  => 'admin',
            'password' => 'admin',
            'queueName' => 'productDropshipQN',
            'exchangeName' => 'productDropshipEX',
        ],
    ],

 

2.console  controller

 

<?php
/**
 * FecShop file.
 *
 * @link http://www.fecshop.com/
 * @copyright Copyright (c) 2016 FecShop Software LLC
 * @license http://www.fecshop.com/license/
 */

namespace fecshop\app\console\modules\Amqp\controllers;

use Yii;
use yii\console\Controller;
use fecshop\app\console\modules\Amqp\block\PushTest;

use PhpAmqpLib\Channel\AMQPChannel;
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;

/**
 * @author Terry Zhao <2358269014@qq.com>
 * @since 1.0
 * 这是一个测试RabbitMq 的一个例子。这里作为消息生产方。
 * 你可以通过执行 ./yii amqp/test/test 来生产数据。
 */
class TestController extends Controller
{
    const EXCHANGE_DIRECT = 'direct';
    const EXCHANGE_TOPIC = 'topic';
    const EXCHANGE_FANOUT = 'fanout';
    
    public $host = '192.168.221.56';
    public $port = 5672;
    public $user = 'admin';
    public $password        = 'admin';
    
    public $queueName       = 'productDropshipQN';
    public $exchangeName    = 'productDropshipEX';
    public $routingKey      = 'productDropshipRT';
    public $exchangeType    = self::EXCHANGE_DIRECT;
    
    /**
     * @var AMQPStreamConnection
     */
    private $connection;
    /**
     * @var AMQPChannel
     */
    private $channel;
    
     /**
     * 生产数据
     */
    public function actionTest()
    {
        Yii::$app->queue->push([
            'name'  => 'water',
            'age'   => 331,
        ]);
    }
    /**
     * 接收数据
     */
    public function actionListen()
    {
        $this->open();
        $callback = function(AMQPMessage $message) {
            if ($this->handleMessage($message->body)) {
                $message->delivery_info['channel']->basic_ack($message->delivery_info['delivery_tag']);
            }
        };
        $this->channel->basic_qos(null, 1, null);
        $this->channel->basic_consume($this->queueName, '', false, false, false, false, $callback);
        while(count($this->channel->callbacks)) {
            $this->channel->wait();
        }
        
    }
    
    
    /**
     * Opens connection and channel
     */
    protected function open()
    {
        if ($this->channel) return;
        $this->connection = new AMQPStreamConnection($this->host, $this->port, $this->user, $this->password);
        $this->channel = $this->connection->channel();
        $this->channel->queue_declare($this->queueName,true, true);
        $this->channel->exchange_declare($this->exchangeName, $this->exchangeType, false, true, false);
        $this->channel->queue_bind($this->queueName, $this->exchangeName,$this->routingKey);
    }
    /**
     * 这里处理接收到的数据
     */
    protected function handleMessage($message)
    {
        // $message = unserialize($message);
        var_dump($message);
        //  do some thing ...
        // \Yii::info($message,'fecshop_debug');
        return true;
    }
    
    
    
    /*
    public function actionListen3()
    {
          Yii::$app->queue->listen();
        
    }
    */
    
}

 

 

 

 

vagrant 设置文件映射,将windows文件夹映射到linux中

首先,我们为什么要这样做?

我们用vagrant搭建起来了linux环境,也就是在windows下面虚拟出来的linux环境,但是,可以用如下的几种方式进行编辑:

1.如果我们用vim进行编辑,是非常费劲的,不提倡

2.通过编辑器的ftp直连,就像:

Linux 作为开发环境的方法分享

这种方式只能用notepad这种,只在连接的时候加载,而不能用phpstorm这种提前加载到本地,因为这种方式,用phpstorm会造成一定的问题,我的开发环境用的是阿里云主机,随便找个电脑安装个notepad就可以干活了,也就说这种方式比较适合远程。

3. 最通用的方式,就是本地window通过vagrant虚拟出来一个linux,然后,通过映射的方式,将windows下的文件夹映射到vagrant的linux中,然后,我们的编辑器(phpstorm)加载window下的这个文件夹,就可以了,当我们修改window下的这个文件夹,因为是挂载到linux的(有点像u盘的感觉),我们把nginx指向该文件夹,就可以进行开发了(上面说的有点啰嗦,不过意思说明白了),这也就是本文要讲述的方式。

另外需要注意的是:
vagrant虚拟的linux的文件是无法映射到windows中的,只能windows的文件映射到linux中,就像window环境中的某个文件夹挂载到vagrant 的 linux中的感觉,但是不能把linux的文件夹挂载到windows,具体操作如下:

打开Vagrantfile,修改配置内容如下(完全修改):

# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
  # The most common configuration options are documented and commented below.
  # For a complete reference, please see the online documentation at
  # https://docs.vagrantup.com.

  # Every Vagrant development environment requires a box. You can search for
  # boxes at https://atlas.hashicorp.com/search.
  config.vm.box = "centos-6.6-x86_64"
  
  config.vm.hostname = "dev"
  config.ssh.username = "root"
  config.ssh.password = "123456"
  config.ssh.insert_key = "true"
  config.ssh.shell = "bash -c 'BASH_ENV=/etc/profile exec bash'"
  config.ssh.forward_agent = true
  # Disable automatic box update checking. If you disable this, then
  # boxes will only be checked for updates when the user runs
  # `vagrant box outdated`. This is not recommended.
  # config.vm.box_check_update = false

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine. In the example below,
  # accessing "localhost:8080" will access port 80 on the guest machine.
   config.vm.network "forwarded_port", guest: 80, host: 80

  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
  config.vm.network "private_network", ip: "192.168.10.12"

  # Create a public network, which generally matched to bridged network.
  # Bridged networks make the machine appear as another physical device on
  # your network.
  config.vm.network "public_network"

  # Share an additional folder to the guest VM. The first argument is
  # the path on the host to the actual folder. The second argument is
  # the path on the guest to mount the folder. And the optional third
  # argument is a set of non-required options.
  # config.vm.synced_folder "../data", "/vagrant_data"
    config.vm.synced_folder "D:\\linux\\fecshop", "/www/web/develop/fecshop"
  # Provider-specific configuration so you can fine-tune various
  # backing providers for Vagrant. These expose provider-specific options.
  # Example for VirtualBox:
  #
  config.vm.provider "virtualbox" do |vb|
    # Display the VirtualBox GUI when booting the machine
    # vb.gui = true
    vb.name = "dev"
    # Customize the amount of memory on the VM:
    vb.memory = "2048"
  end
  #
  # View the documentation for the provider you are using for more
  # information on available options.

  # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
  # such as FTP and Heroku are also available. See the documentation at
  # https://docs.vagrantup.com/v2/push/atlas.html for more information.
  # config.push.define "atlas" do |push|
  #   push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
  # end

  # Enable provisioning with a shell script. Additional provisioners such as
  # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
  # documentation for more information about their specific syntax and use.
  # config.vm.provision "shell", inline: <<-SHELL
  #   apt-get update
  #   apt-get install -y apache2
  # SHELL
end

在上面的配置中可以看到如下:

config.vm.synced_folder “D:\\linux\\fecshop”, “/www/web/develop/fecshop”

第一个路径是window的路径,第二个是vagrant’中linux的路径

启动,如图:

 

注意:

1.如果 /www/web/develop/fecshop 这个文件夹在linux中存在,那么启动后,原来的文件夹将看不到。

2. 如果linux存在文件夹/www/web/develop/fecshop,您想把这个文件夹的内容复制到映射后的/www/web/develop/fecshop中,那么,您可以先将/www/web/develop/fecshop  改名为 /www/web/develop/fecshop_cp,然后,添加映射配置,重启(vagrant reload)vagrant,然后通过命令复制过去即可

\cp -rf /www/web/develop/fecshop_cp/*  /www/web/develop/fecshop/

 

安装 RabbitMQ – centos 6

 

1.安装Erlang环境

cd /usr/local/src/  
mkdir rabbitmq  
cd rabbitmq  
  
wget http://packages.erlang-solutions.com/erlang-solutions-1.0-1.noarch.rpm  
rpm -Uvh erlang-solutions-1.0-1.noarch.rpm  
  
rpm --import http://packages.erlang-solutions.com/rpm/erlang_solutions.asc  
  
sudo yum install erlang

2.安装RabbitMQ

上面都成功后 安装RabbitMQ

wget https://www.rabbitmq.com/releases/rabbitmq-server/v3.6.1/rabbitmq-server-3.6.1-1.noarch.rpm
rpm --import https://www.rabbitmq.com/rabbitmq-signing-key-public.asc
yum install rabbitmq-server-3.6.1-1.noarch.rpm

安装输出log如下:

Loaded plugins: security
Setting up Install Process
Examining rabbitmq-server-3.6.1-1.noarch.rpm: rabbitmq-server-3.6.1-1.noarch
Marking rabbitmq-server-3.6.1-1.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package rabbitmq-server.noarch 0:3.6.1-1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================================
 Package                    Arch              Version             Repository                                  Size
===================================================================================================================
Installing:
 rabbitmq-server            noarch            3.6.1-1             /rabbitmq-server-3.6.1-1.noarch            5.5 M

Transaction Summary
===================================================================================================================
Install       1 Package(s)

Total size: 5.5 M
Installed size: 5.5 M
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : rabbitmq-server-3.6.1-1.noarch                                                                  1/1 
  Verifying  : rabbitmq-server-3.6.1-1.noarch                                                                  1/1 

Installed:
  rabbitmq-server.noarch 0:3.6.1-1                                                                                 

Complete!

run the following command to allow SELinux to enable RabbitMQ service:

setsebool -P nis_enabled 1

开启端口,如果是本地测试,关掉iptables也可以

4369 (epmd), 25672 (Erlang distribution)
 5672, 5671 (AMQP 0-9-1 without and with TLS)
 15672 (if management plugin is enabled)
 61613, 61614 (if STOMP is enabled)
 1883, 8883 (if MQTT is enabled)

启动:

/etc/init.d/rabbitmq-server start

log如下:

[root@iZ942k2d5ezZ tools]# /etc/init.d/rabbitmq-server start
Starting rabbitmq-server: SUCCESS
rabbitmq-server.

加入浏览器界面:

rabbitmq-plugins enable rabbitmq_management
chown -R rabbitmq:rabbitmq /var/lib/rabbitmq/

然后访问:

http://120.24.37.249:15672

就可以看到界面了:

RabbitMQ Management - Google Chrome_005

增加账户:

rabbitmqctl add_user mqadmin 123456
rabbitmqctl set_user_tags mqadmin administrator
rabbitmqctl set_permissions -p / mqadmin ".*" ".*" ".*"

 

上面的命令中

mqadmin就是登陆的账户

123456就是登陆的密码

然后就可以看到界面了,如下:

RabbitMQ Management

php 7 环境安装

1.安装php:

yum 安装必备

yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel
yum  install ntp vim-enhanced gcc gcc-c++ gcc-g77 flex bison autoconf automake glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel libtool* zlib-devel libxml2-devel libjpeg-devel libpng-devel libtiff-devel fontconfig-devel freetype-devel libXpm-devel gettext-devel curl curl-devel pam-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers gzip  make bzip2bzip2-devel pcre-devel wget ncurses-devel cmake make perl

 

yum -y install gcc automake autoconf libtool make   gcc-c++ glibc  libmcrypt-devel mhash-devel libxslt-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel lib

上面的yum安装存在重复,不去细细排查了,您复制上面三个安装即可

wget -O php7.tar.gz http://cn2.php.net/get/php-7.1.1.tar.gz/from/this/mirror

解压

tar -xvf php7.tar.gz
cd php-7.1.1

编译:

./configure \
--prefix=/usr/local/php \
--with-config-file-path=/etc \
--enable-fpm \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-libxml-dir \
--with-xmlrpc \
--with-openssl \
--with-mcrypt \
--with-mhash \
--with-pcre-regex \
--with-sqlite3 \
--with-zlib \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--with-cdb \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--with-pcre-dir \
--enable-ftp \
--with-gd \
--with-openssl-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-freetype-dir \
--enable-gd-native-ttf \
--enable-gd-jis-conv \
--with-gettext \
--with-gmp \
--with-mhash \
--enable-json \
--enable-mbstring \
--enable-mbregex \
--enable-mbregex-backtrack \
--with-libmbfl \
--with-onig \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-zlib-dir \
--with-pdo-sqlite \
--with-readline \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--with-libxml-dir \
--with-xsl \
--enable-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-opcache

在centos7下面,会报错:Don’t know how to define struct flock on this system, set –enable-opcache=no

解决办法:vim /etc/ld.so.conf.d/local.conf # 编辑库文件
/usr/local/lib # 添加该行
:wq # 保存退出
ldconfig # 执行这个命令行,使之生效
!!记得编译完后不能移除这行,会导致php无法启动!!

 

make && make install

复制配置文件到/etc

cp php.ini-development /etc/php.ini

创建快捷方式:

ln -s /usr/local/php/bin/php  /usr/bin/php

配置php-fpm:

cp php.ini-production /etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm

启动:

/etc/init.d/php-fpm start

2.安装扩展:

oauth
imap
mongodb
redis  (Yii2 不安装redis扩展也是可以用的,可以不用安装)

2.1安装oauth扩展:

wget http://pecl.php.net/get/oauth-2.0.2.tgz
tar -zxf oauth-2.0.2.tgz 
cd oauth-2.0.2
/usr/local/php/bin/phpize  
./configure --with-php-config=/usr/local/php/bin/php-config  
make && make install  
vim /etc/php.ini  # 添加 extension=oauth.so
/etc/init.d/php-fpm restart

2.2 安装imap 扩展

cd php-7.1.1/ext/imap
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-imap=/usr/lib64 --with-imap-ssl --with-kerberos
make && make install
vim /etc/php.ini
extension=imap.so

如果报错:Cannot find imap library (libc-client.a)

 yum install libc-client-devel.x86_64
ln -s /usr/lib64/libc-client.so /usr/lib/libc-client.so

 

2.3 安装 mongodb

wget https://pecl.php.net/get/mongodb-1.2.5.tgz
tar zxvf mongodb-1.2.5.tgz
cd mongodb-1.2.5
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install

vim /etc/php.ini
extension=mongodb.so

 

3. 配置

3.1 mysql的配置,要使用127.0.0.1 不要使用localhost

localhost 会使用unix socket,而不是tcp连接。

4.到这里基本就都配置好了。

 

 

Yii2 中使用ElasticSearch – 所有

 

安装ElasticSearch ,以及在yii2中的使用

 

Yii2 elasticSearch – 配置部分

 

Yii2 elasticSearch – Model部分

 

Yii2 elasticSearch 进行查询

 

Yii2 ElasticSearch aggregate (group) 的例子

 

yii2 elasticSearch 传递数据到elasticSearch中

 

 

ElasticSearch 使用 – 传递数据规避重复数据

Yii2 elasticSearch 多值查询 和 查询数组字段

Yii2 elasticSearch 多值查询 和 查询数组字段

 

elasticSearch 批量传递数据,存在数据丢失的原因

 

 

 

yii2 elasticSearch 传递数据到elasticSearch中

 

代码如下:$data 是一个数组。

    
if(is_array($data) && !empty($data )){
  $elasticsearch = Yii::$app->elasticsearch;
  $bulkclient = $elasticsearch->createBulkCommand();
  # elasticSearch的index,相当于mysql的数据库
  $index_name = 'fecshop';
  # elasticSearch的type,相当于mysql的table
  $type_name = 'whole_free_sku_data';
  echo $index_name."###".$type_name." \n";
  foreach($data  as $one){
    $i++;
    $a = [];
    $a['sku_id'] = $one['_id'];
    $value = $one['value'];
    
    # 将多维数组部分进行序列化。
    if(is_array($value) && !empty($value )){
      foreach($value  as $k => $v){
        if(in_array($k,['devide','country_code','browser_name','operate'])){
          
          if(is_array($v) && !empty($v)){
            $vv = [];
            foreach($v as $vk => $o){
              $vv[] = serialize([$vk=>$o]);
            }
            $v = $vv;
          }
        }
        $a[$k] = $v;
      }
    }
    # 去掉_id字段。
    unset($a['_id']);
    $bulkclient->addAction(array(
      'index' => array(
        '_index'=> $index_name,
        '_type' => $type_name,
        '_id' 	=> $one['_id'],
      )
    ), $a);
    
  }
  $bulkclient->execute();
}