196 lines
6.4 KiB
PHP
196 lines
6.4 KiB
PHP
<?php
|
|
|
|
/**
|
|
* 系统文章
|
|
*/
|
|
|
|
namespace app\home\controller;
|
|
use think\facade\View;
|
|
use think\facade\Lang;
|
|
|
|
class Csv extends BaseMall {
|
|
|
|
public function initialize() {
|
|
parent::initialize();
|
|
// $value[1] ? iconv("GB2312","UTF-8",$value[1]) : '',
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
echo 1;die;
|
|
/*var_dump(iconv("GB2312","UTF-8",'This course will investigate the contemporary concepts of "happiness," from a multi-disciplinary approach. The course will focus on applying happiness and mindfulness concepts to individual outcomes. Letter grade only'));die;*/
|
|
|
|
$csv = 'http://'.$_SERVER['SERVER_NAME'].'/lightcourse-2.csv';
|
|
|
|
$fp = fopen($csv,'r');
|
|
$tmp = [];
|
|
while($csv_line = fgetcsv($fp)) {
|
|
|
|
$tmp[] = $csv_line;
|
|
}
|
|
|
|
fclose($fp);
|
|
unset($tmp[0]);
|
|
|
|
|
|
//插入数据
|
|
$goods_model = model('goods');
|
|
$attr_model = model('goodsattrindex');
|
|
foreach ($tmp as $val) {
|
|
$val[9] = $val[9] ? iconv("GB2312","UTF-8//IGNORE",$val[9]) : '';
|
|
$class = explode(',', $val[4]);
|
|
$attr = $this->getAttr($val[1], $val[5], $val[12], $val[14]);
|
|
|
|
//插入common表
|
|
$common['goods_name'] = $val[7];
|
|
$common['goods_advword'] = $val[9];
|
|
$common['gc_id'] = $class[1];
|
|
$common['gc_id_1'] = $class[0];
|
|
$common['gc_id_2'] = $class[1];
|
|
$common['gc_id_3'] = 0;
|
|
$common['gc_name'] = $val[3];
|
|
$common['spec_name'] = 'N;';
|
|
$common['spec_value'] = 'N;';
|
|
$common['type_id'] = 1;
|
|
$common['goods_state'] = 1;
|
|
$common['goods_attr'] = serialize($attr);
|
|
$common['goods_addtime'] = time();
|
|
$common['goods_price'] = $val[10];
|
|
$common['goods_serial'] = $val[6];
|
|
|
|
$common['ke_college'] = $val[0];
|
|
$common['ke_simple_college'] = $val[2];
|
|
$common['ke_institution'] = $val[0];
|
|
$common['ke_period'] = $val[17];
|
|
$common['ke_credit'] = $val[8];
|
|
$common['ke_start_time'] = $val[15];
|
|
$common['ke_end_time'] = $val[16];
|
|
$common['ke_online'] = 'Online';
|
|
|
|
$common['ke_type'] = $val[11];
|
|
$common['ke_zone'] = $val[13];
|
|
|
|
$common['enroll_start_date'] = $val[18];
|
|
$common['enroll_end_date'] = $val[19];
|
|
$common_id = $goods_model->addGoodsCommon($common);
|
|
|
|
//插入goods表
|
|
$goods['goods_name'] = $val[7];
|
|
$goods['goods_commonid'] = $common_id;
|
|
$goods['goods_advword'] = $val[9];
|
|
$goods['gc_id'] = $class[1];
|
|
$goods['gc_id_1'] = $class[0];
|
|
$goods['gc_id_2'] = $class[1];
|
|
$goods['gc_id_3'] = 0;
|
|
//$goods['gc_name'] = $val[3];
|
|
$goods['goods_price'] = $val[10];
|
|
$goods['goods_serial'] = $val[6];
|
|
$goods['goods_storage'] = 999;
|
|
|
|
$goods['goods_addtime'] = time();
|
|
$goods['goods_edittime'] = time();
|
|
|
|
$goods['ke_college'] = $val[0];
|
|
$goods['ke_simple_college'] = $val[2];
|
|
$goods['ke_institution'] = $val[0];
|
|
$goods['ke_period'] = $val[17];
|
|
$goods['ke_credit'] = $val[8];
|
|
$goods['ke_start_time'] = $val[15];
|
|
$goods['ke_end_time'] = $val[16];
|
|
$goods['ke_online'] = 'Online';
|
|
|
|
$goods['ke_type'] = $val[11];
|
|
$goods['ke_zone'] = $val[13];
|
|
|
|
$goods['enroll_start_date'] = $val[18];
|
|
$goods['enroll_end_date'] = $val[19];
|
|
$goods_id = $goods_model->addGoods($goods);
|
|
//插入attr表
|
|
$list = $this->getList($val[1], $val[5], $val[12], $val[14]);
|
|
foreach ($list as $v) {
|
|
$index['goods_id'] = $goods_id;
|
|
$index['goods_commonid'] = $common_id;
|
|
$index['gc_id'] = $class[1];
|
|
$index['type_id'] = 1;
|
|
$index['attr_id'] = $v['attr_id'];
|
|
$index['attrvalue_id'] = $v['attrvalue_id'];
|
|
$attr_model->addattr($index);
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public function getAttr($a, $b, $c, $d)
|
|
{
|
|
|
|
$ta = $this->attr($a);
|
|
$tb = $this->attr($b);
|
|
$tc = $this->attr($c);
|
|
$td = $this->attr($d);
|
|
|
|
$data[1]['name'] = $ta['attr_name'];
|
|
$data[1][$ta['attrvalue_id']] = $ta['attrvalue_name'];
|
|
|
|
$data[2]['name'] = $tb['attr_name'];
|
|
$data[2][$tb['attrvalue_id']] = $tb['attrvalue_name'];
|
|
|
|
$data[3]['name'] = $tc['attr_name'];
|
|
$data[3][$tc['attrvalue_id']] = $tc['attrvalue_name'];
|
|
|
|
$data[4]['name'] = $td['attr_name'];
|
|
$data[4][$td['attrvalue_id']] = $td['attrvalue_name'];
|
|
|
|
return $data;
|
|
}
|
|
|
|
public function getList($a, $b, $c, $d)
|
|
{
|
|
$ta = $this->attr($a);
|
|
$tb = $this->attr($b);
|
|
$tc = $this->attr($c);
|
|
$td = $this->attr($d);
|
|
$data[1]['attr_id'] = $ta['attr_id'];
|
|
$data[1]['attrvalue_id'] = $ta['attrvalue_id'];
|
|
|
|
$data[2]['attr_id'] = $tb['attr_id'];
|
|
$data[2]['attrvalue_id'] = $tb['attrvalue_id'];
|
|
|
|
$data[3]['attr_id'] = $tc['attr_id'];
|
|
$data[3]['attrvalue_id'] = $tc['attrvalue_id'];
|
|
|
|
$data[4]['attr_id'] = $td['attr_id'];
|
|
$data[4]['attrvalue_id'] = $td['attrvalue_id'];
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
public function attr($id)
|
|
{
|
|
$model = model('attribute');
|
|
$t = $model->getAttributeValueList(['attrvalue_id' => $id]);
|
|
$aid = $t[0]['attr_id'];
|
|
|
|
$detail = $model->getAttributeList(['attr_id' => $aid]);
|
|
|
|
$data = [
|
|
'attr_name' => $detail[0]['attr_name'],
|
|
'attr_id' => $aid,
|
|
'attrvalue_id' => $id,
|
|
'attrvalue_name' => $t[0]['attrvalue_name'],
|
|
|
|
];
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|