[ 'name' => '商品', 'class' => 'addon\v3tov4\model\Goods', 'is_show' => 1, 'introduction' => '迁移商品、商品分类、商品标签等数据', 'desc' => << [ 'name' => '会员', 'class' => 'addon\v3tov4\model\Member', 'is_show' => 1, 'introduction' => '迁移会员、等级、标签、收货地址、商品收藏、足迹、账户流水等数据', 'desc' => << ns_member 1、member_id 由 v3 sys_user uid对应转入 2、source_member 来源会员id 查询v3 nfx_shop_member_association 3、fenxiao_id 分销商id 查询会员是否是分销商 是则为自身分销商id 否查询上级分销商 4、username 由 v3 sys_user user_name 字段对应转入 5、nickname 由 v3 sys_user nick_name 字段对应转入 6、mobile 由 v3 sys_user user_tel 字段对应转入 7、email 由 v3 sys_user user_email 字段对应转入 8、password 由 v3 sys_user user_password 字段对应转入 9、headimg 头像需从v3站点进行拉取 10、member_level、member_level_name、member_label、member_label_name 这些字段需关联v3 ns_member 查询到 会员等级 会员标签 去这两表中查询 11、wx_openid 公众号openid v3 sys_user wx_openid 字段对应转入 12、weapp_openid 小程序openid v3 sys_user wx_applet_openid 字段对应转入 13、realname 由v3 sys_user real_name 字段对应转入 14、sex 由v3 sys_user sex 字段对应转入 15、location 由v3 sys_user location 字段对应转入 16、birthday 由v3 sys_user birthday 字段对应转入 17、reg_time 由v3 sys_user reg_time 字段对应转入 18、point 积分 由v3 ns_member_account point 字段对应转入 19、balance 储值余额 由v3 ns_member_account balance 字段对应转入 EOT ], 'fenxiao' => [ 'name' => '分销', 'class' => 'addon\v3tov4\model\Fenxiao', 'introduction' => '迁移分销商、分销商等级等数据', 'is_show' => 0, 'desc' => << ns_fenxiao 1、fenxiao_id 由v3 nfx_promoter promoter_id 字段对应转入 2、fenxiao_no 按v4分销商编号生成规则生成 3、fenxiao_name 由v3 nfx_promoter promoter_shop_name 字段对应转入 4、mobile 由v3 nfx_promoter balance 字段对应转入 5、member_id 由v3 nfx_promoter uid 字段对应转入 6、level_id 由v3 nfx_promoter promoter_level 字段对应转入 7、level_name 查询对应分销商等级名称 8、parent 由v3 nfx_promoter parent_promoter 字段对应转入 9、grand_parent 查询上上级分销商id 10、account 当前佣金 由v3 nfx_promoter (commossion_total - commission_cash) 总佣金 - 已提现佣金 11、account_withdraw 已提现佣金 由v3 nfx_promoter commission_cash 字段对应转入 12、create_time 由v3 nfx_promoter audit_time 字段对应转入 13、total_commission 累计佣金 由v3 nfx_promoter commossion_total 字段对应转入 2、分销商申请 数据表:nfx_promoter -> ns_fenxiao_apply 1、fenxiao_name 由v3 nfx_promoter promoter_shop_name 字段对应转入 2、parent 由v3 nfx_promoter parent_promoter 字段对应转入 3、member_id 由v3 nfx_promoter uid 字段对应转入 4、mobile 查询会员相应数据 5、nickname 查询会员相应数据 6、headimg 查询会员相应数据 7、level_id 由v3 nfx_promoter promoter_level 字段对应转入 8、level_name 查询相应分销商等级名称 9、create_time 由v3 nfx_promoter regidter_time 字段对应转入 3、分销等级数据表:nfx_promoter_level -> ns_fenxiao_level 1、level_id 由v3 nfx_promoter_level level_id 字段对应转入 2、level_name 由v3 nfx_promoter_level level_name 字段对应转入 3、one_rate 由v3 nfx_promoter_level level_0 字段对应转入 4、two_rate 由v3 nfx_promoter_level level_1 字段对应转入 5、three_rate 由v3 nfx_promoter_level level_2 字段对应转入 6、create_time 由v3 nfx_promoter_level create_time 字段对应转入 4、分销商品 (规则不同不做迁移) EOT ], // 'order' => [ // 'name' => '订单', // 'class' => 'addon\v3tov4\model\Goods' // ] ]; private $page_size = 10; /** * 获取数据迁移项 * @return array */ public function getTaskClass() { return $this->task_class; } /** * 获取分页 * @return int */ public function getPageSize() { return $this->page_size; } /** * 获取分页列表 * @param $table * @param $where * @param $page * @param $page_size * @param $ailas * @param $join */ final protected function getPageList($table, $where = [], $field = '*', $page = 1, $page_size = 10, $alias = '', $join = null) { $table = Db::connect($this->db)->table($table); if (!empty($join)) { $table = $this->parseJoin($table, $join); } $list = $table->alias($alias)->where($where)->field($field)->limit($page_size)->page($page)->select()->toArray(); return $list; } /** * 获取列表 * @param $table * @param array $where * @param string $field * @param string $alias * @param null $join * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ final protected function getList($table, $where = [], $field = '*', $order = "", $alias = '', $join = null) { $table = Db::connect($this->db)->table($table); if (!empty($join)) { $table = $this->parseJoin($table, $join); } $list = $table->alias($alias)->where($where)->order($order)->field($field)->select()->toArray(); return $list; } /** * 查询单条数据 * @param $table * @param array $where * @param string $field * @param string $alias * @param null $join * @return mixed */ final protected function getInfo($table, $where = [], $field = '*', $alias = 'a', $join = null) { $table = Db::connect($this->db)->table($table); if (!empty($join)) { $table = $this->parseJoin($table, $join); } $info = $table->alias($alias)->where($where)->field($field)->find(); return $info; } /** * sql查询 * @param $sql * @return mixed */ final protected function query($sql) { $res = Db::connect($this->db)->query($sql); return $res; } /** * 查询数量 * @param $table * @param array $where * @param string $field */ final protected function getCount($table, $where = [], $field = '*') { $table = Db::connect($this->db)->table($table); $count = $table->where($where)->count($field); return $count; } /** * join分析 * @access protected * @param array $join * @param array $options 查询条件 * @return string */ final protected function parseJoin($db_obj, $join) { foreach ($join as $item) { list($table, $on, $type) = $item; $type = strtolower($type); switch ( $type ) { case "left": $db_obj = $db_obj->leftJoin($table, $on); break; case "inner": $db_obj = $db_obj->join($table, $on); break; case "right": $db_obj = $db_obj->rightjoin($table, $on); break; case "full": $db_obj = $db_obj->fulljoin($table, $on); break; default: break; } } return $db_obj; } /** * 获取数据同步任务列表 */ public function getSyncTask($class) { $task_class = []; $class_array = explode(',', $class); foreach ($class_array as $item) { if (isset($this->task_class[ $item ])) { array_push($task_class, $this->task_class[ $item ][ 'class' ]); if ($item == 'member') { array_push($task_class, $this->task_class[ 'fenxiao' ][ 'class' ]); } } } try { $methods = $this->getTaskMethod($task_class); $task = []; foreach ($methods as $method => $class_name) { $class = new $class_name(); $count = $class->$method(); if ($count > 0) { for ($i = 0; $i < ceil(( $count / $this->page_size )); $i++) { array_push($task, [ 'class' => $class_name, 'method' => str_replace('Count', 'List', $method), 'page' => $i + 1, 'page_size' => $this->page_size ]); } } } return $task; } catch (\Exception $e) { return $this->error('', $e->getMessage()); } } /** * 执行任务 */ public function run($task) { try { [ 'class' => $class_name, 'method' => $method, 'page' => $page, 'page_size' => $page_size ] = $task; $class = new $class_name(); $res = $class->$method($page, $page_size); return $res; } catch (\Exception $e) { return $this->error('', $e->getMessage()); } } /** * 获取类中的方法 * @param $class_array * @return array * @throws \ReflectionException */ private function getTaskMethod($class_array) { $method_array = []; foreach ($class_array as $class_name) { $class = new \ReflectionClass($class_name); $methods = $class->getMethods(); foreach ($methods as $method) { if (strpos($method->name, 'Count') !== false && $method->name != 'getCount') { $method_array[ $method->name ] = $method->class; } } } return $method_array; } }