Commit f2a0519c by liuyingkang

feat: 添加laravel-log-viewer依赖并优化导入逻辑,新增合同导入,和合同导入模版下载

添加了dcat/laravel-log-viewer依赖以支持日志查看功能。优化了导入逻辑,包括处理日期数据、新增委托人和律师信息的自动插入,以及改进数据格式化。此外,在Covenant模型中添加了回避信息和备注字段。
parent 3b4f4080
...@@ -77,6 +77,8 @@ protected function grid() ...@@ -77,6 +77,8 @@ protected function grid()
return $val ? '已退案' : '未退案'; return $val ? '已退案' : '未退案';
}); });
$grid->column('return_fee', '退案结案费'); $grid->column('return_fee', '退案结案费');
$grid->column('avoid', '回避信息');
$grid->column('remark', '备注');
// $grid->column('created_at'); // $grid->column('created_at');
// $grid->column('updated_at')->sortable(); // $grid->column('updated_at')->sortable();
...@@ -150,6 +152,8 @@ protected function detail($id) ...@@ -150,6 +152,8 @@ protected function detail($id)
$show->field('amount'); $show->field('amount');
$show->field('payment_method'); $show->field('payment_method');
$show->field('case_reason'); $show->field('case_reason');
$show->field('avoid', '回避信息');
$show->field('remark', '备注');
$show->field('created_at'); $show->field('created_at');
$show->field('updated_at'); $show->field('updated_at');
}); });
...@@ -184,6 +188,9 @@ protected function form() ...@@ -184,6 +188,9 @@ protected function form()
$form->text('amount')->required(); $form->text('amount')->required();
$form->select('payment_method')->options(Covenant::PAYMENT_METHOD)->default(1)->required(); $form->select('payment_method')->options(Covenant::PAYMENT_METHOD)->default(1)->required();
$form->text('avoid', '回避信息' );
$form->text('remark', '备注');
$form->disableCreatingCheck(); $form->disableCreatingCheck();
$form->disableEditingCheck(); $form->disableEditingCheck();
$form->disableViewCheck(); $form->disableViewCheck();
......
...@@ -34,31 +34,45 @@ public function sheets(): array ...@@ -34,31 +34,45 @@ public function sheets(): array
*/ */
public function collection(Collection $rows) public function collection(Collection $rows)
{ {
// 设置脚本执行时间无限制
set_time_limit(0); set_time_limit(0);
// 去掉表头
// 移除Excel表头行(前两行)
unset($rows[0]); unset($rows[0]);
unset($rows[1]); unset($rows[1]);
$i = 0; $i = 0; // 计数器
foreach ($rows as $k => &$item) { foreach ($rows as $k => &$item) {
if (!$item[1] || !$item[2] || !$item[3] || !$item[4]) { //检查必填字段(第1-2-6列)是否为空
continue; if (!$item[0] || !$item[1] || !$item[5] ) {
continue; // 跳过空行
} }
$i++; $i++;
// 截取前21列数据
$item = array_slice($item->toArray(), 0, 21); $item = array_slice($item->toArray(), 0, 21);
// 调用模型类的静态方法处理单行数据
$result = $this->className::CreateImportData($item); $result = $this->className::CreateImportData($item);
if (!$result) { if (!$result) {
continue; Log::add('导入失败', $item);
continue; // 处理失败则跳过
} }
// 收集有效数据
$insert[] = $result; $insert[] = $result;
$key[] = $k; $key[] = $k; // 记录行号
// 每处理1000条数据执行一次批量插入
if (is_int($i / 1000)) { if (is_int($i / 1000)) {
DB::table($this->className::getTableName())->insert($insert); DB::table($this->className::getTableName())->insert($insert);
$insert = []; $insert = []; // 清空临时数组
unset($key); unset($key);
$key = []; $key = [];
} }
} }
// 处理剩余不足1000条的数据
if (!empty($insert)) { if (!empty($insert)) {
DB::table($this->className::getTableName())->insert($insert); DB::table($this->className::getTableName())->insert($insert);
} }
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use App\Command\Log; use App\Command\Log;
use App\Models\Principal;
use App\Models\Lawyer;
...@@ -34,6 +36,16 @@ class Covenant extends Model ...@@ -34,6 +36,16 @@ class Covenant extends Model
2 => '付款开票' 2 => '付款开票'
]; ];
/**
* 获取当前模型对应的数据库表名
* @return string
*/
public static function getTableName()
{
return with(new static)->getTable();
}
public function principal() public function principal()
{ {
return $this->belongsTo(Principal::class, 'principal_id', 'id'); return $this->belongsTo(Principal::class, 'principal_id', 'id');
...@@ -50,76 +62,79 @@ public function lawyer() ...@@ -50,76 +62,79 @@ public function lawyer()
* 创建导入数据格式 * 创建导入数据格式
* @param array $item 包含以下结构的原始数据数组: * @param array $item 包含以下结构的原始数据数组:
* [ * [
* 0 => 日期, * 0 => 签订日期,
* 1 => 客户姓名, * 1 => 客户姓名,
* 2 => 税号/个人(无), * 2 => 合同类型,
* 3 => 合同编号, * 3 => 合同编号,
* 4 => 面积范围, * 4 => 案由,
* 5 => 案 由, * 5 => 办案律师,
* 6 => 办案律师, * 6 => 合同金额,
* 7 => 合同金额, * 7 => 结算方式,
* 8 => 租金范围, * 8 => 被回避单位/个人
* 9 => 图片路径数组, * 9 => 备注
* 10 => 描述,
* 11 => 房源链接
* ] * ]
* @return array 格式化后的数据库字段数组 * @return array 格式化后的数据库字段数组
*/ */
public static function CreateImportData($item): array public static function CreateImportData($item): array
{ {
$result = $item; $result = $item;
$tags = $result[7];
if ($tags) {
$tagsArr = explode("|", $tags);
$tmp = [];
foreach ($tagsArr as $key => $val) {
//去除无标签
$exist = DB::table('tag')->where("title", $val)->first();
if ($exist) {
array_push($tmp, $val);
}
}
$tags = json_encode($tmp, JSON_UNESCAPED_UNICODE);
}
$imgs = '';
if ($item[9]) {
$imgs = json_encode($item[9], JSON_UNESCAPED_UNICODE);
}
$name = $result[0];
if ($result[0]) {
//$exist = self::where("name", $result[0])->first();
//$name = !$exist ? $name : '';
}
//租金
$rent = $result[8];
$rentArr = [];
if (stripos($rent, "~") != false) {
$rentArr = $rent ? explode('~', $rent) : [];
} else {
$rentArr = $rent ? explode('-', $rent) : [];
}
$price = isset($rentArr[0]) ? $rentArr[0] : 0;
Log::add('test', $name); // 处理日期数据(第1项)
$sign_at = date('Y-m-d', strtotime(str_replace('.', '-', $result[0])));
// 记录日志
Log::add('debug', $sign_at);
// 客户姓名-委托人
$principal = $result[1];
//查询委托人是否存在,不存在新增委托人
$principal_id= Principal::getIdByName($principal);
// 合同类型,默认其他
$ctype = array_search($result[7], self::CTYPE) ?: 8;
$number= $result[3];
$case_reason= $result[4];
$lawyer= $result[5];
$lawyer_id= Lawyer::getIdByName($lawyer);
$amount= $result[6];
// 结算方式 1:开票付款 2:付款开票
$payment_method = array_search($result[7], self::PAYMENT_METHOD) ?: 1;
$avoid= $result[8];//回避人
$remark= $result[9];//备注
// 构建最终数据数组
$data = [ $data = [
'name' => $name, 'number' => $number, // 合同编号
'area_id' => AreaModel::getIdByName($result[1]), 'cname' => $principal, // 合同名称
'position' => $result[2], 'principal' => $principal, // 委托人名称
'layout_house' => $result[3], 'lawyer' => $lawyer, // 律师 - 这里应该是$lawyer
'extent' => $result[4], 'ctype' => $ctype, // 合同类型
'lng' => $result[5], 'principal_type' => 2, // 委托人单位(目前导入只支持个人)
'lat' => $result[6], 'principal_id' => $principal_id, // 委托人id
'tags' => $tags, 'sign_at' => $sign_at, // 合同日期
'rent' => $rent, 'lawyer_id' => $lawyer_id, // 律师id
'price' => $price, 'payment_method' => $payment_method, // 结算方式
'imgs' => $imgs, 'amount' => $amount, // 金额
'describe' => $result[10], 'case_reason' => $case_reason, // 案由
'housing_link' => $result[11], 'is_closed' => 0, // 是否结案 1:是
'created_at' => date('Y-m-d H:i:s'), 'is_return' => 0, // 退回状态 1:是
'updated_at' => date('Y-m-d H:i:s'), 'avoid' => $avoid, // 回避人
'remark' => $remark, // 备注
'created_at' => date('Y-m-d H:i:s'), // 创建时间
'updated_at' => date('Y-m-d H:i:s'), // 更新时间
]; ];
// 记录日志
Log::add('debug', $data);
return $data; return $data;
} }
} }
...@@ -237,4 +237,22 @@ public static function getPayableAmount($lawyer_id, $year, $commission_rate, $re ...@@ -237,4 +237,22 @@ public static function getPayableAmount($lawyer_id, $year, $commission_rate, $re
$result = $receipt_money * ($commission_rate / 100) - $paid_amount; $result = $receipt_money * ($commission_rate / 100) - $paid_amount;
return $result; return $result;
} }
//不存在就新增
public static function getIdByName($title = '')
{
$id = 0;
$row = self::where("name", $title)->first();
if ($row) {
$id = $row->id;
}else{
$id = self::insertGetId([
'name' => $title,
'number' => mt_rand(10000, 99999),
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s'),
]);
}
return $id;
}
} }
...@@ -6,10 +6,31 @@ ...@@ -6,10 +6,31 @@
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
use App\Admin\Controllers\PrincipalController;
class Principal extends Model class Principal extends Model
{ {
use HasDateTimeFormatter; use HasDateTimeFormatter;
use SoftDeletes; use SoftDeletes;
protected $table = 'principal'; protected $table = 'principal';
//不存在就新增
public static function getIdByName($title = '')
{
$id = 0;
$row = self::where("name", $title)->first();
if ($row) {
$id = $row->id;
}else{
$id = self::insertGetId([
'name' => $title,
'number' => mt_rand(10000, 99999),
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s'),
]);
}
return $id;
}
} }
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
"php": "^8.0.2", "php": "^8.0.2",
"dcat/easy-excel": "^1.1", "dcat/easy-excel": "^1.1",
"dcat/laravel-admin": "2.*", "dcat/laravel-admin": "2.*",
"dcat/laravel-log-viewer": "^0.1.7",
"guzzlehttp/guzzle": "^7.2", "guzzlehttp/guzzle": "^7.2",
"intervention/image": "^2.7", "intervention/image": "^2.7",
"jacobcyl/ali-oss-storage": "^2.1", "jacobcyl/ali-oss-storage": "^2.1",
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "15db32d52aa0ccca67453b23c4cf4f5e", "content-hash": "c180d8c48f1a4c20111cbf758b98c9a8",
"packages": [ "packages": [
{ {
"name": "aliyuncs/oss-sdk-php", "name": "aliyuncs/oss-sdk-php",
...@@ -502,6 +502,64 @@ ...@@ -502,6 +502,64 @@
"time": "2023-02-15T08:59:42+00:00" "time": "2023-02-15T08:59:42+00:00"
}, },
{ {
"name": "dcat/laravel-log-viewer",
"version": "0.1.7",
"source": {
"type": "git",
"url": "https://github.com/jqhph/laravel-log-viewer.git",
"reference": "12d1bbbbf521e9c84b038c37069eec7f64d69584"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/jqhph/laravel-log-viewer/zipball/12d1bbbbf521e9c84b038c37069eec7f64d69584",
"reference": "12d1bbbbf521e9c84b038c37069eec7f64d69584",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"php": ">=7.0"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"Dcat\\LogViewer\\DcatLogViewerServiceProvider"
]
}
},
"autoload": {
"psr-4": {
"Dcat\\LogViewer\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "jqh",
"email": "841324345@qq.com"
}
],
"description": "Laravel Log Viewer",
"homepage": "https://github.com/jqhph/laravel-log-viewer",
"keywords": [
"laravel",
"log viewer"
],
"support": {
"issues": "https://github.com/jqhph/laravel-log-viewer/issues",
"source": "https://github.com/jqhph/laravel-log-viewer/tree/0.1.7"
},
"time": "2023-08-24T08:49:50+00:00"
},
{
"name": "dflydev/dot-access-data", "name": "dflydev/dot-access-data",
"version": "v3.0.2", "version": "v3.0.2",
"source": { "source": {
...@@ -10543,12 +10601,12 @@ ...@@ -10543,12 +10601,12 @@
], ],
"aliases": [], "aliases": [],
"minimum-stability": "dev", "minimum-stability": "dev",
"stability-flags": [], "stability-flags": {},
"prefer-stable": true, "prefer-stable": true,
"prefer-lowest": false, "prefer-lowest": false,
"platform": { "platform": {
"php": "^8.0.2" "php": "^8.0.2"
}, },
"platform-dev": [], "platform-dev": {},
"plugin-api-version": "2.3.0" "plugin-api-version": "2.6.0"
} }
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