2024-12-11 19:03:47 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace app\common\library;
|
|
|
|
|
|
|
|
use app\common\model\school\Area;
|
|
|
|
use app\common\model\school\classes\Cate;
|
|
|
|
use app\common\model\school\classes\ClassesLib;
|
|
|
|
use app\common\model\school\classes\ClassesSpec;
|
|
|
|
use app\common\model\school\classes\Type;
|
|
|
|
use app\common\model\school\classes\VirtualHead;
|
|
|
|
use app\common\model\school\classes\VirtualUser;
|
|
|
|
use think\Db;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sql脚本类
|
|
|
|
*/
|
|
|
|
class Sqlscript
|
|
|
|
{
|
|
|
|
|
|
|
|
public static function importClasses($page=1,$limit=1000){
|
|
|
|
$kechengs = Db::table("kecheng")
|
|
|
|
->page($page,$limit)->select();
|
|
|
|
|
|
|
|
//默认机构id
|
2024-12-13 18:37:50 +08:00
|
|
|
$manystore_id = 1;
|
|
|
|
$shop_id = 1;
|
|
|
|
$user_id = 72;
|
|
|
|
$teacher_id = 15;
|
2024-12-11 19:03:47 +08:00
|
|
|
|
|
|
|
foreach ($kechengs as $k=>$v){
|
|
|
|
$classes_cate_ids = Cate::where( "name",$v["gongyi"])->value("id");
|
|
|
|
if(!$classes_cate_ids)$classes_cate_ids="";
|
|
|
|
$classes_label_ids = "";
|
|
|
|
$classes_type = Type::where( "name",$v["kecheng_type"])->value("id");
|
|
|
|
$add_type = "2";
|
|
|
|
$add_id = 0;
|
|
|
|
$title = $v["name"];
|
|
|
|
$headimage = $v["img"];
|
|
|
|
if(!$headimage)continue;
|
|
|
|
$images = Db::table("kecheng_img")->where("ke_id",$v["id"])->column("path");
|
|
|
|
$images = implode(",",$images);
|
|
|
|
$type = "in";
|
|
|
|
$classes_num = 1;
|
|
|
|
$address_type = "2";
|
|
|
|
// "address_city": "河南省/洛阳市",
|
|
|
|
// "province": "河南省",
|
|
|
|
// "city": "洛阳市",
|
|
|
|
// "area": null,
|
|
|
|
// "province_code": 410000,
|
|
|
|
// "city_code": 410300,
|
|
|
|
// "area_code": 0
|
|
|
|
$address_city = "河南省/洛阳市"."/".$v["district"];
|
|
|
|
$address = $v["district"];
|
|
|
|
$address_detail = $v["shangkedidian"];
|
|
|
|
$province = 410000;
|
|
|
|
$city = 410300;
|
|
|
|
$district = Area::where( "name","like","%".$v["district"]."%")
|
|
|
|
->where("level",3)
|
|
|
|
->where("pid",$city)
|
|
|
|
->value("id");
|
|
|
|
$longitude = $v["longitude"];
|
|
|
|
$latitude = $v["latitude"];
|
|
|
|
//html解码
|
|
|
|
$content = html_entity_decode($v["blurb"]);
|
|
|
|
$notice = html_entity_decode($v["experience"]);
|
|
|
|
$price = 0;
|
|
|
|
$status = "1";
|
|
|
|
$weigh = 0;
|
|
|
|
$recommend = ''.($v["por"] ?:0);
|
|
|
|
$hot = ''.($v["hot"] ?:0);
|
|
|
|
$new = ''.($v["top"] ?:0);
|
|
|
|
$auth_status = 1;
|
|
|
|
$feel = "1";
|
|
|
|
//如果不存在开始和结束时间
|
|
|
|
//随机生成个至少过去一个月的开始和结束时间, 结束时间至少过去一个月
|
|
|
|
if(!$v["start_time"]||!$v["end_time"]){
|
|
|
|
$v["start_time"] = time()-rand(2592000,2592000*10);
|
|
|
|
$v["end_time"] = rand($v["start_time"]+24536,$v["start_time"] + time()-$v["start_time"]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//开始时间和结束时间如果是毫秒级时间戳,截取成秒级
|
|
|
|
$v["start_time"] = substr($v["start_time"],0,10);
|
|
|
|
$v["end_time"] = substr($v["end_time"],0,10);
|
|
|
|
|
|
|
|
$spec = [
|
|
|
|
"classes_lib_id"=>0,
|
|
|
|
"name"=>"单课时默认课时",
|
|
|
|
"start_time"=>$v["start_time"],
|
|
|
|
"end_time"=>$v["end_time"],
|
|
|
|
"limit_num"=>100,
|
|
|
|
"status"=>"1",
|
|
|
|
"weigh"=>0
|
|
|
|
];
|
|
|
|
$classes_lib = ClassesLib::where("title",$title)->find();
|
|
|
|
if(!$classes_lib){
|
|
|
|
$classes_lib = ClassesLib::create(compact("feel","auth_status","manystore_id", "shop_id", "user_id", "teacher_id", "classes_cate_ids","classes_label_ids","classes_type","add_type","add_id","title","headimage","images","type","classes_num","address_type","address_city","address","address_detail","province","city","district","longitude","latitude","content","notice","price","status","weigh","recommend","hot","new"));
|
|
|
|
$spec["classes_lib_id"] = $classes_lib->id;
|
|
|
|
$spec = ClassesSpec::create($spec);
|
|
|
|
// \app\common\model\school\classes\ClassesLib::add_virtual_init($classes_lib->id);
|
|
|
|
\app\common\model\school\classes\ClassesLib::update_classes($classes_lib->id);
|
|
|
|
}else{
|
|
|
|
$classes_lib->save(compact("feel","auth_status","manystore_id", "shop_id", "user_id", "teacher_id", "classes_cate_ids","classes_label_ids","classes_type","add_type","add_id","title","headimage","images","type","classes_num","address_type","address_city","address","address_detail","province","city","district","longitude","latitude","content","notice","price","status","weigh","recommend","hot","new"));
|
|
|
|
$spec["classes_lib_id"] = $classes_lib->id;
|
|
|
|
$ClassesSpec = ClassesSpec::where("classes_lib_id",$classes_lib->id)->find();
|
|
|
|
if($ClassesSpec){
|
|
|
|
ClassesSpec::where("classes_lib_id",$classes_lib->id)->update($spec);
|
|
|
|
}else{
|
|
|
|
ClassesSpec::create($spec);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// \app\common\model\school\classes\ClassesLib::add_virtual_init($classes_lib->id);
|
|
|
|
\app\common\model\school\classes\ClassesLib::update_classes($classes_lib->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|