Commit e4222f6a authored by clone's avatar clone

数据转换

parent f39d740b
......@@ -67,7 +67,7 @@ class AppointmentTime extends Basic
return $this->response("101", "楼盘信息不能为空");
}
//todo 参数校验
if (!isset($params["phone"]) || !preg_match('/1[345678]\d{9}/', $params["phone"])) {
if (!isset($params["phone"]) || !preg_match('/^1[345678]\d{9}$/', $params["phone"])) {
return $this->response("101", "手机号为空或手机号无效");
}
......
......@@ -4,7 +4,14 @@ namespace app\api\controller;
use app\api\extend\Basic;
use app\model\Applies;
use app\model\GHouses;
use app\model\OMarchInModel;
use app\model\OrderModel;
use app\model\OReportModel;
use app\model\RefundTables;
use app\model\Remarks;
use app\model\Users;
use function MongoDB\BSON\fromJSON;
use think\Request;
/**
......@@ -19,54 +26,122 @@ class ConvertOrder extends Basic
private $appliesModel;
private $userModel;
private $reportModel;
private $orderModel;
private $remarksModel;
private $marchInModel;
private $refundModel;
public function __construct($request = null)
{
$this->appliesModel = new Applies();
$this->userModel = new Users();
$this->reportModel = new OReportModel();
$this->orderModel = new OrderModel();
$this->remarksModel = new Remarks();
$this->marchInModel = new OMarchInModel();
$this->refundModel = new RefundTables();
parent::__construct($request);
}
/**
* 转换报备,订单,用户数据
*/
public function convertOrderByTime()
{
set_time_limit(0);
//todo old num convert new table. first select page report num.
//$params = $this->params;
$total = $this->appliesModel->getAppliesCount();
$pageSize = 200;
$pageTotal = $total / $pageSize;
$field = "a.id,a.phpone,a.agent_id,a.agent_shop_id,a.receptiontime ,a.house_id,a.customer,a.sex,a.vehicle,
$pageTotal = ceil($total / $pageSize);
$field = "a.id,a.phpone,a.agent_id,a.agent_shop_id,a.receptiontime ,a.house_id,a.customer,a.sex,a.vehicle,a.created,a.modified,
b.title as house_title,b.room_num_left,c.phone,c.realname";
for ($pageNo = 1; $pageNo <= $pageTotal; $pageNo++) {
sleep(5);
$appliesList = $this->appliesModel->getApplies($pageNo, $pageSize, $field);
if (count($appliesList) > 0) {
$reportArr = [];
$orderArr = [];
foreach ($appliesList as $item) {
$userInfo = $this->userModel->insertUserConvert($this->userBin($item["customer"], $item["customer"], $item["phpone"], $item["sex"]));
$userInfo = $this->userModel->insertUserConvert($this->userBin($item["customer"], $item["customer"],
$item["phpone"], $item["sex"], $item["created"]));
if (count($userInfo) <= 0) continue;
$param = $this->reportBin($item["id"], $item["agent_id"], $item["phone"], $item["realname"], $item["agent_shop_id"], $userInfo["id"], $userInfo["user_phone"]
, $userInfo["user_name"], $item["vehicle"], $item["agent_shop_id"]);
array_push($reportArr,$param);
$reportParam = $this->reportBin($item["id"], $item["agent_id"], $item["phone"], $item["realname"], $item["agent_shop_id"], $userInfo["id"], $userInfo["user_phone"]
, $userInfo["user_name"], $item["vehicle"], $item["agent_shop_id"], $item["receptiontime"], $item["created"], $item["modified"]);
$f_id = $this->reportModel->addReport($reportParam);
if ($f_id > 0) {
$orderParam = $this->orderBin($this->createOrderNumber(), $f_id, $item["house_id"]);
array_push($orderArr, $orderParam);
}
}
$this->orderModel->insertOrderByAll($orderArr);
}
ob_flush();
}
}
/* $house_arr = [];
foreach ($house_arr as $k => $v) {
//todo 批量插入到数据库
$order_no = $this->createOrderNumber();
array_push($order_arr, $this->orderBin($order_no, $id, $v));
}
//todo 保存order表
return $this->orderModel->insertOrderByAll($order_arr);*/
/**
* 进场数据转换
*/
public function convertMarchIn()
{
$total = $this->remarksModel->getRemarksCount();
$pageSize = 200;
$pageTotal = ceil($total / $pageSize);
$field = "a.shopuser_id,b.id as report_id,c.id as order_id,c.order_no,a.content,d.imagename,a.content_area,a.created,a.modified";
$marchInArr = [];
for ($pageNo = 1; $pageNo <= $pageTotal; $pageNo++) {
$marchInList = $this->remarksModel->getRemarksList($pageNo, $pageSize, $field);
foreach ($marchInList as $key => $item) {
$marchInParams = $this->marchInBin($item["shopuser_id"], $item["report_id"], $item["order_id"], $item["order_no"],
$item["content"], $item["imagename"], $item["content_area"], $item["created"], $item["modified"]);
array_push($marchInArr, $marchInParams);
}
sleep(5);
}
$this->marchInModel->addMarchInAll($marchInArr);
ob_flush();
}
/**
* 退款
*/
public function convertRefund()
{
/* $field = "a.apply_id,a.tui_money,a.name,a.bank,a.bank_card,a.content,a.transaction_status,a.time,a.admin,
b.id as report_id,c.id as order_id,c.order_no";
$refundList = $this->refundModel->getRefundList($field);
foreach ($refundList as $item) {
$this->refundBin();
}*/
}
//退款
private function refundBin()
{
/* $arr["agent_id"] = $report_id;
$arr["report_id"] = $father_id;
$arr["order_id"] = $order_no;
$arr["order_no"] = $order_id;
$arr["refund_money"] = $agent_id;
$arr["name"] = $collecting_arr["type"];
$arr["bank"] = $collecting_arr["pay_type"];
$arr["card_no"] = $collecting_arr["money"];
$arr["remark"] = $house_number;
$arr["remark_img"] = $industry_type;
$arr["create_time"] = date("Y-m-d H:i:s", time());
$arr["update_time"] = date("Y-m-d H:i:s", time());
return $arr;
//todo 判断此单是否有付款
$is_ok = $this->o_refund_model->addRefund($params);*/
}
private function reportBin($id, $report_agent_id, $report_agent_phone, $report_agent_name, $report_store_id, $user_id, $user_phone, $user_name,
$vehicle, $intro, $predict_see_time)
$vehicle, $intro, $predict_see_time, $create_time, $update_time)
{
if ($vehicle == 1) {
$vehicle = 10;
......@@ -83,10 +158,11 @@ class ConvertOrder extends Basic
$param["user_name"] = $user_name;
$param["vehicle"] = $vehicle;
$param["status"] = 0;
$param["intro"] = $intro;
$param["predict_see_time"] = date("Y-m-d H:i:s", $predict_see_time);
$param["create_time"] = date("Y-m-d H:i:s", time());
$param["update_time"] = date("Y-m-d H:i:s", time());
$param["intro"] = "";
$param["predict_see_time"] = $predict_see_time;
$param["is_old"] = 1;
$param["create_time"] = $create_time;
$param["update_time"] = $update_time;
return $param;
}
......@@ -186,43 +262,26 @@ class ConvertOrder extends Basic
return $arr;
}
//退款
private function refundBin()
{
$params = array(
"agent_id" => 1,//退款经纪人id
"report_id" => 1,//报备id
"order_id" => 1, //关联order表id
"order_no" => "12312312312312", //订单no
"refund_money" => 1200, //退款金额 存分
"name" => "qweqwe", //收款人姓名
"bank" => "asdasdasd", //收款人银行
"card_no" => "123123123123", //银行卡号
"remark" => "没什么备注",
"remark_img" => "12312312312"
);
//todo 判断此单是否有付款
$is_ok = $this->o_refund_model->addRefund($params);
}
private function marchInBin()
private function marchInBin($reception_id, $report_id, $order_id, $order_no, $march_in_remark, $march_in_img, $march_in_area, $create_time, $update_time)
{
$params = array(
"reception_id" => 1,//带看经纪人id
"report_id" => 1,//报备id
"order_id" => 1, //关联order表id
"order_no" => "123123123123123", //订单no
"march_in_remark" => "有意向购买", //进场备注
"march_in_img" => "123123", //备注图片
"march_in_area" => "上海市虹口区中山公园", //进场地址
);
// $params["reception_id"] = $this->agentName;
$params["reception_id"] = $reception_id;//带看经纪人id
$params["reception_name"] = "";//带看经纪人id
$params["report_id"] = $report_id;//报备id
$params["order_id"] = $order_id; //关联order表id
$params["order_no"] = $order_no; //订单no
$params["march_in_remark"] = $march_in_remark; //进场备注
$params["march_in_img"] = "old_img/march_in/" . $march_in_img;//备注图片
$params["march_in_area"] = $march_in_area; //进场地址
$params["create_time"] = $create_time; //进场地址
$params["update_time"] = $update_time; //进场地址
return $params;
$is_ok = $this->o_march_in_model->addMarchIn($params);
}
private function userBin($user_nick, $user_name, $user_phone, $sex)
private function userBin($user_nick, $user_name, $user_phone, $sex, $create)
{
if ($sex == "男") {
$sex = 1;
......@@ -237,8 +296,8 @@ class ConvertOrder extends Basic
$param["sex"] = $sex;
$param["status"] = -1;
$param["source"] = 30; //老数据转换
$param["create_time"] = date("Y-m-d H:i:s", time());
$param["update_time"] = date("Y-m-d H:i:s", time());
$param["create_time"] = $create;
$param["update_time"] = $create;
return $param;
}
......
......@@ -26,23 +26,25 @@ class Applies extends Model
public function getApplies($pageNo, $pageSize, $field)
{
$where_["transaction_status"] = 1;
return Db::table($this->table)
->field($field)
->alias("a")
->join('houseinfos b', 'a.house_id = b.id', 'LEFT')
->join('agents c', 'a.agent_id = c.id', 'LEFT')
->where($where_)
->limit($pageSize)
->page($pageNo)
->select();
}
public function getAppliesCount()
{
$where_["transaction_status"] = 1;
return $this
->field("a.id")
->alias("a")
->join('houseinfos b', 'a.house_id = b.id', 'LEFT')
->where($where_)
->count();
}
......
......@@ -42,6 +42,23 @@ class OMarchInModel extends Model
}
}
/**
* 新增跟进信息 批量
* @param $params
* @return int
*/
public function addMarchInAll($params)
{
Db::startTrans();
try {
$this->db_model->insertAll($params);
Db::commit();
return 1;
} catch (\Exception $e) {
Db::rollback();
return 0;
}
}
/**
* @param $filed
* @param $params
......
......@@ -2,10 +2,21 @@
namespace app\model;
use Think\Db;
use think\Model;
class RefundTables extends Model
{
// 设置当前模型对应的完整数据表名称
protected $table = 'refundtables';
public function getRefundList($field)
{
return Db::table($this->table)
->field($field)
->alias("a")
->join('o_report b', 'a.apply_id = b.id', 'LEFT')
->join('o_order c', 'b.id = c.f_id', 'LEFT')
->select();
}
}
......@@ -6,7 +6,7 @@ use think\Model;
use think\Db;
class Remarks extends Model
{
protected $table = "remarks";
/**
* 成交记录列表
*
......@@ -125,4 +125,31 @@ class Remarks extends Model
/****************************处理客户电话****************************************/
return $data;
}
public function getRemarksList($pageNo, $pageSize, $field)
{
$where_["a.isinstatus"] = 1;
return Db::table($this->table)
->field($field)
->alias("a")
->join('o_report b', 'a.apply_id = b.id', 'LEFT')
->join('o_order c', 'b.id = c.f_id', 'LEFT')
->join('remarksimgs d', 'a.id = d.remarks_id', 'LEFT')
->where($where_)
->limit($pageSize)
->page($pageNo)
->select();
}
public function getRemarksCount()
{
$where_["a.isinstatus"] = 1;
return Db::table($this->table)
->field("a.id")
->alias("a")
->join('o_report b', 'a.apply_id = b.id', 'LEFT')
->join('o_order c', 'b.id = c.f_id', 'LEFT')
->join('remarksimgs d', 'a.id = d.remarks_id', 'LEFT')
->where($where_)
->count();
}
}
......@@ -376,10 +376,11 @@ class Users extends Model
*/
public function insertUserConvert($params){
$where_ = [];
if(isset($params["user_phone"])){
$where_ ["user_phone"] = $params ["user_phone"];
if(!isset($params["user_phone"]) || !preg_match('/^1[345678]\d{9}$/', $params["user_phone"])){
return null;
}
$model = Db::table($this->table);
$where_ ["user_phone"] = $params ["user_phone"];
$model = Db::name($this->table);
$list = $model
->field("id,user_name,user_phone")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment