更新目录结构
This commit is contained in:
@@ -64,7 +64,7 @@ abstract class BaseController
|
||||
* @return array|string|true
|
||||
* @throws ValidateException
|
||||
*/
|
||||
protected function validate(array $data, $validate, array $message = [], bool $batch = false)
|
||||
protected function validate(array $data, string|array $validate, array $message = [], bool $batch = false)
|
||||
{
|
||||
if (is_array($validate)) {
|
||||
$v = new Validate();
|
||||
|
||||
@@ -20,4 +20,4 @@ class Request extends \think\Request{
|
||||
public function static(){
|
||||
return $this->domain() . '/storage/';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,37 +1,2 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
use think\facade\Cache;
|
||||
use sent\tree\Tree;
|
||||
|
||||
function getDepartmentChild($pid = 0){
|
||||
$department = Cache::get('department');
|
||||
if(!$department){
|
||||
$department = \app\model\auth\Departments::where('status', '=', 1)->column('id,parent_id,title', 'id');
|
||||
Cache::set('department', $department);
|
||||
}
|
||||
$res = getChilds($department, $pid, 'id', 'parent_id');
|
||||
$res[] = (int) $pid; //把自己包含在内
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得所有的子
|
||||
* @param [type] $id [description]
|
||||
* @return [type] [description]
|
||||
*/
|
||||
function getChilds($data, $id = 0, $pk = 'id', $pid = 'parent_id') {
|
||||
$array = [];
|
||||
foreach ($data as $k => $v) {
|
||||
if ($v[$pid] == $id) {
|
||||
$array[] = $v[$pk];
|
||||
$array = array_merge($array, getChilds($data, $v[$pk]));
|
||||
}
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
// 应用公共文件
|
||||
|
||||
@@ -24,16 +24,14 @@ class Index extends Base{
|
||||
if(request()->isAjax()){
|
||||
return ['code' => 1, 'data' => 'SentOS'];
|
||||
}else{
|
||||
return view('/index');
|
||||
return `<!doctype html><html lang="zh-CN"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible"content="IE=edge"><meta name="viewport"content="width=device-width, initial-scale=1"><title>SentOS</title><style>html,body{background-color:#fff;color:#3c4042;font-family:'Raleway',sans-serif;font-weight:100;height:80vh;margin:0}.top{text-align:right;line-height:35px;padding:0 20px}.top a{color:#333333;padding:0 10px}.full-height{height:90vh}.flex-center{align-items:center;display:flex;justify-content:center}.position-ref{position:relative}.top-right{position:absolute;right:10px;top:18px}.content{text-align:center}.title{font-size:84px}.links>a{color:#3c4042;padding:0 25px;font-size:12px;font-weight:600;letter-spacing:.1rem;text-decoration:none;text-transform:uppercase}.m-b-md{margin-bottom:30px}</style></head><body><div class="flex-center position-ref full-height"><div class="content"><div class="title m-b-md">SentOS</div><div class="links"></div></div></div><div style="text-align: center; font-size: 12px;"><p><a href="https://beian.miit.gov.cn/"target="_blank"style="color: #333333; text-decoration: none;">赣ICP备13006622号-1</a></p><p>技术支持:<a href="https://www.tensent.cn"target="_blank"style="color: #333333; text-decoration: none;">腾速科技</a></p></div></body></html>`;
|
||||
}
|
||||
}
|
||||
|
||||
public function test(){
|
||||
// $area = \think\facade\Db::name('areas')->select();
|
||||
// $save = [];
|
||||
// foreach($area as $val){
|
||||
// $save[] = ['title' => $val['area'], 'code' => $val['area_id'], 'parent_id' => $val['city_id'], 'first' => '', 'create_time' => time(), 'update_time' => time()];
|
||||
// }
|
||||
// \think\facade\Db::name('area')->insertAll($save);
|
||||
}
|
||||
|
||||
public function miss(){
|
||||
return '404 Not Found!';
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ namespace app\controller\auth;
|
||||
use think\facade\Request;
|
||||
use app\model\auth\Departments;
|
||||
use app\services\auth\DepartmentService;
|
||||
use sent\tree\Tree;
|
||||
use Xin\Support\Arr;
|
||||
use app\controller\Base;
|
||||
|
||||
class Department extends Base {
|
||||
@@ -35,7 +35,7 @@ class Department extends Base {
|
||||
}
|
||||
}
|
||||
}
|
||||
$tree = (new Tree())->listToTree($list, 'id', 'parent_id', 'children', $root);
|
||||
$tree = Arr::tree($list, null, 0, ['id'=>'id', 'parent' => 'parent_id', 'child' => 'children']);
|
||||
if(empty($tree)){
|
||||
$this->data['data'] = $list;
|
||||
}else{
|
||||
|
||||
@@ -11,9 +11,6 @@ namespace app\controller\auth;
|
||||
use app\controller\Base;
|
||||
use app\services\auth\AuthService;
|
||||
use app\services\SocialiteService;
|
||||
use app\model\Member;
|
||||
use app\model\auth\Users;
|
||||
use app\model\auth\RolesAccess;
|
||||
|
||||
class Index extends Base{
|
||||
|
||||
@@ -28,21 +25,6 @@ class Index extends Base{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function member(){
|
||||
// $output = $this->app->console->call('migrate:run');
|
||||
// return $output->fetch();
|
||||
// $map = [];
|
||||
// $member = Member::where($map)->select();
|
||||
// $save = [];
|
||||
// foreach($member as $item){
|
||||
// $user = Users::where('username', '=', $item->username)->findOrEmpty();
|
||||
// if($user->isEmpty()){
|
||||
// $save[] = ['uid' => $item['uid'], 'username' => $item['username'], 'password' => '123456', 'nickname' => $item['nickname'], 'email' => $item['email'], 'department_id' => $item['department']];
|
||||
// }
|
||||
// }
|
||||
// (new Users())->saveAll($save);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 第三方账号登录
|
||||
*/
|
||||
|
||||
71
app/controller/customer/Company.php
Normal file
71
app/controller/customer/Company.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\controller\customer;
|
||||
|
||||
use app\controller\Base;
|
||||
use app\services\company\CompanyService;
|
||||
|
||||
/**
|
||||
* @title 企业信息模型
|
||||
*/
|
||||
class Company extends Base{
|
||||
|
||||
/**
|
||||
* @title 企业列表
|
||||
*
|
||||
* @time 2020年01月09日
|
||||
* @param CompanyService $service
|
||||
* @return Array
|
||||
*/
|
||||
public function index(CompanyService $service) {
|
||||
$data = $service->getCompanyList($this->request);
|
||||
|
||||
$this->data['data'] = $data;
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 企业详情
|
||||
*
|
||||
* @time 2020年01月09日
|
||||
* @param CompanyService $service
|
||||
* @return Array
|
||||
*/
|
||||
public function detail(CompanyService $service) {
|
||||
$data = $service->getCompanyDetail($this->request);
|
||||
|
||||
$this->data['data'] = $data;
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 修改企业
|
||||
*
|
||||
* @time 2020年01月09日
|
||||
* @param CompanyService $service
|
||||
* @return Array
|
||||
*/
|
||||
public function edit(CompanyService $service) {
|
||||
$data = $service->editCompany($this->request);
|
||||
|
||||
$this->data['data'] = $data;
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 导入企业信息
|
||||
*
|
||||
* @param CompanyService $service
|
||||
* @return void
|
||||
*/
|
||||
public function insert(CompanyService $service){
|
||||
$this->data['data'] = $service->insertCompanyData($this->request);
|
||||
return $this->data;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,13 @@
|
||||
<?php
|
||||
// 全局中间件定义文件
|
||||
return [
|
||||
// 全局请求缓存
|
||||
// \think\middleware\CheckRequestCache::class,
|
||||
// 多语言加载
|
||||
// \think\middleware\LoadLangPack::class,
|
||||
// Session初始化
|
||||
// \think\middleware\SessionInit::class
|
||||
\app\middleware\AllowCrossDomain::class,
|
||||
\app\middleware\Api::class,
|
||||
\app\middleware\Validate::class,
|
||||
];
|
||||
];
|
||||
|
||||
@@ -16,6 +16,7 @@ use think\Request;
|
||||
class AllowCrossDomain{
|
||||
|
||||
protected $header = [
|
||||
'Access-Control-Allow-Origin' => '*',
|
||||
'Access-Control-Allow-Credentials' => 'true',
|
||||
'Access-Control-Max-Age' => 1800,
|
||||
'Access-Control-Allow-Methods' => 'GET, POST, PATCH, PUT, DELETE, OPTIONS',
|
||||
|
||||
@@ -12,7 +12,6 @@ namespace app\middleware;
|
||||
|
||||
use think\App;
|
||||
use think\Response;
|
||||
use xiaodi\JWTAuth\Exception\JWTException;
|
||||
|
||||
class Check{
|
||||
protected $app;
|
||||
@@ -31,26 +30,16 @@ class Check{
|
||||
*/
|
||||
public function handle($request, \Closure $next, $store = null){
|
||||
try {
|
||||
$verify = $this->app->get('jwt')->store($store)->verify();
|
||||
$verify = \leruge\facade\JWT::validate();;
|
||||
if (true === $verify) {
|
||||
if ($this->app->get('jwt.user')->getBind()) {
|
||||
if ($user = $this->app->get('jwt.user')->find()) {
|
||||
// 路由注入
|
||||
$request->user = $user;
|
||||
|
||||
// 绑定当前用户模型
|
||||
$class = $this->app->get('jwt.user')->getClass();
|
||||
$this->app->bind($class, $user);
|
||||
|
||||
// 绑定用户后一些业务处理
|
||||
$this->bindUserAfter($request);
|
||||
} else {
|
||||
return Response::create(['message' => '登录校验已失效, 请重新登录', 'code' => 2000], 'json', 401);
|
||||
}
|
||||
$user = \leruge\facade\JWT::auth();
|
||||
if ($user->uid) {
|
||||
// 路由注入
|
||||
$request->user = $user;
|
||||
}
|
||||
return $next($request);
|
||||
}
|
||||
} catch (JWTException $e) {
|
||||
} catch (\think\Exception $e) {
|
||||
return Response::create(['message' => $e->getMessage(), 'code' => 2000], 'json', 401);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ namespace app\model\auth;
|
||||
|
||||
use app\model\BaseModel;
|
||||
use think\facade\Config;
|
||||
use xiaodi\JWTAuth\Facade\Jwt;
|
||||
|
||||
class Users extends BaseModel{
|
||||
|
||||
@@ -28,7 +27,7 @@ class Users extends BaseModel{
|
||||
}
|
||||
|
||||
public function getTokenAttr($value, $data){
|
||||
$token = Jwt::store('api')->token($data)->__toString();
|
||||
$token = \leruge\facade\JWT::builder($data, false);
|
||||
return $token;
|
||||
}
|
||||
|
||||
|
||||
67
app/model/customer/Company.php
Normal file
67
app/model/customer/Company.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\model\customer;
|
||||
|
||||
use app\model\BaseModel;
|
||||
use think\model\concern\SoftDelete;
|
||||
use think\facade\Cache;
|
||||
|
||||
class Company extends BaseModel{
|
||||
|
||||
use SoftDelete;
|
||||
protected $deleteTime = 'delete_time';
|
||||
protected $defaultSoftDelete = 0;
|
||||
|
||||
|
||||
public $insertFieldAlis = [
|
||||
'企业编号' => ['name' => 'org_code', 'table' => 'company'],
|
||||
'公司名称' => ['name' => 'name', 'table' => 'company'],
|
||||
'网址' => ['name' => 'web_site', 'table' => 'company'],
|
||||
'一级行业' => ['name' => 'industry', 'table' => 'company'],
|
||||
'二级行业' => ['name' => 'industry_sub', 'table' => 'company'],
|
||||
'三级行业' => ['name' => 'industry_three', 'table' => 'company'],
|
||||
'省份' => ['name' => 'province', 'table' => 'company'],
|
||||
'城市' => ['name' => 'city', 'table' => 'company'],
|
||||
'区县' => ['name' => 'area', 'table' => 'company'],
|
||||
'年营业额' => ['name' => 'turnover_text', 'table' => 'company',],
|
||||
'员工人数' => ['name' => 'staff_num_text', 'table' => 'company'],
|
||||
'注册资金' => ['name' => 'reg_capital', 'table' => 'company'],
|
||||
'资金类型' => ['name' => 'reg_capital_type', 'table' => 'company'],
|
||||
'PC数量' => ['name' => 'pc_num_text', 'table' => 'company'],
|
||||
'营收规模' => ['name' => 'turnover', 'table' => 'company'],
|
||||
'社保人数' => ['name' => 'social_insurance', 'table' => 'company'],
|
||||
'企业性质' => ['name' => 'company_type', 'table' => 'company'],
|
||||
'是否上市' => ['name' => 'is_ipo_text', 'table' => 'company'],
|
||||
'融资信息' => ['name' => 'finance_info', 'table' => 'company'],
|
||||
'企业标签' => ['name' => 'tags', 'table' => 'company'],
|
||||
'企业状态' => ['name' => 'status', 'table' => 'company'],
|
||||
'成立时间' => ['name' => 'reg_date', 'table' => 'company'],
|
||||
'注册地址' => ['name' => 'reg_address', 'table' => 'company'],
|
||||
'联系人' => ['name' => 'name', 'table' => 'contact'],
|
||||
'岗位' => ['name' => 'job','table' => 'contact'],
|
||||
'固定电话' => ['name' => 'phone', 'table' => 'contact'],
|
||||
'手机号码' => ['name' => 'mobile', 'table' => 'contact'],
|
||||
'邮箱' => ['name' => 'email', 'table' => 'contact'],
|
||||
'是否法人' => ['name' => 'is_faren', 'table' => 'contact']
|
||||
];
|
||||
|
||||
public function getAreaTAttr($value, $data){
|
||||
$text = [$data['province'], $data['city'], $data['area']];
|
||||
return implode(",", array_filter($text));
|
||||
}
|
||||
|
||||
public function getIndustryTAttr($value, $data){
|
||||
$text = [$data['industry'], $data['industry_sub'], $data['industry_three']];
|
||||
return implode(",", array_filter($text));
|
||||
}
|
||||
|
||||
public function contact(){
|
||||
return $this->hasMany(Contact::class);
|
||||
}
|
||||
}
|
||||
21
app/model/customer/Contact.php
Normal file
21
app/model/customer/Contact.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\model\customer;
|
||||
|
||||
use app\model\BaseModel;
|
||||
use think\model\concern\SoftDelete;
|
||||
|
||||
class Contact extends BaseModel{
|
||||
|
||||
use SoftDelete;
|
||||
protected $deleteTime = 'delete_time';
|
||||
protected $defaultSoftDelete = 0;
|
||||
protected $name = "company_contact";
|
||||
|
||||
}
|
||||
@@ -10,7 +10,7 @@ namespace app\services\auth;
|
||||
|
||||
use app\model\auth\Users;
|
||||
use app\model\auth\Permissions;
|
||||
use sent\tree\Tree;
|
||||
use Xin\Support\Arr;
|
||||
use think\facade\Env;
|
||||
|
||||
class AuthService{
|
||||
@@ -52,7 +52,7 @@ class AuthService{
|
||||
public function getAuthMenu(){
|
||||
$order = "sort asc, id desc";
|
||||
$map = [];
|
||||
if(request()->user['uid'] != Env::get('admin_root')){
|
||||
if(request()->user['uid'] != Env::get('ADMIN')){
|
||||
$map[] = ['name', 'IN', request()->auth()['permission']];
|
||||
}
|
||||
$map[] = ['type', '<>', 'button'];
|
||||
@@ -62,7 +62,7 @@ class AuthService{
|
||||
$item->hiddenBreadcrumb = (int) $item['hiddenBreadcrumb'];
|
||||
})->toArray();
|
||||
|
||||
return (new Tree())->listToTree($list, 'id', 'parent_id', 'children');
|
||||
return Arr::tree($list, null, 0, ['id'=>'id', 'parent' => 'parent_id', 'child' => 'children']);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,7 +72,7 @@ class AuthService{
|
||||
*/
|
||||
public function getAuthPermissions(){
|
||||
$map = [];
|
||||
if(request()->user['uid'] != Env::get('admin_root')){
|
||||
if(request()->user['uid'] != Env::get('ADMIN')){
|
||||
$map[] = ['name', 'IN', request()->auth()['permission']];
|
||||
}
|
||||
$list = Permissions::where($map)->select();
|
||||
|
||||
@@ -9,8 +9,7 @@
|
||||
namespace app\services\auth;
|
||||
|
||||
use app\model\auth\Permissions;
|
||||
use sent\tree\Tree;
|
||||
use think\facade\Env;
|
||||
use Xin\Support\Arr;
|
||||
|
||||
class MenuService{
|
||||
|
||||
@@ -21,10 +20,9 @@ class MenuService{
|
||||
* @return void
|
||||
*/
|
||||
public function getSystemMenu($is_menu = true, $is_tree = true){
|
||||
$rootid = Env::get('admin_root');
|
||||
$order = "sort asc, id desc";
|
||||
$map = [];
|
||||
if(request()->user['uid'] != $rootid){
|
||||
if(request()->user['uid'] != env('ADMIN')){
|
||||
$map[] = ['name', 'IN', request()->auth()['permission']];
|
||||
}
|
||||
if($is_menu){
|
||||
@@ -37,7 +35,7 @@ class MenuService{
|
||||
$item->hiddenBreadcrumb = (int) $item['hiddenBreadcrumb'];
|
||||
})->toArray();
|
||||
if($is_tree){
|
||||
$menu = (new Tree())->listToTree($list, 'id', 'parent_id', 'children');
|
||||
$menu = Arr::tree($list, null, 0, ['id'=>'id', 'parent' => 'parent_id', 'child' => 'children']);
|
||||
|
||||
return $menu;
|
||||
}else{
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace app\services\auth;
|
||||
use app\model\auth\Roles;
|
||||
use app\model\auth\PermissionAccess;
|
||||
use app\model\auth\RolesAccess;
|
||||
use sent\tree\Tree;
|
||||
use Xin\Support\Arr;
|
||||
|
||||
class RoleService{
|
||||
/**
|
||||
@@ -36,7 +36,7 @@ class RoleService{
|
||||
$item->permission_id = $permission_id;
|
||||
});
|
||||
if($is_tree){
|
||||
return (new Tree())->listToTree($list->toArray(), 'id', 'parent_id', 'children');
|
||||
return Arr::tree($list->toArray(), null, 0, ['id'=>'id', 'parent' => 'parent_id', 'child' => 'children']);
|
||||
}else{
|
||||
return $list;
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ namespace app\services\auth;
|
||||
|
||||
use app\model\auth\Users;
|
||||
use app\model\auth\UsersLog;
|
||||
use xin\helper\Server;
|
||||
use xin\helper\Time;
|
||||
use Xin\Support\Server;
|
||||
use Xin\Support\Time;
|
||||
|
||||
class UsersLogService{
|
||||
|
||||
@@ -133,7 +133,7 @@ class UsersLogService{
|
||||
}
|
||||
|
||||
protected static function Parser($text) {
|
||||
$doc = new \doc\Doc();
|
||||
return $doc->parse($text);
|
||||
$service = app()->make(\sent\services\DocService::class);
|
||||
return $service->parse($text);
|
||||
}
|
||||
}
|
||||
119
app/services/company/CompanyService.php
Normal file
119
app/services/company/CompanyService.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\services\company;
|
||||
|
||||
use app\model\customer\Company;
|
||||
use app\model\customer\Contact;
|
||||
|
||||
/**
|
||||
* Undocumented class
|
||||
*/
|
||||
class CompanyService {
|
||||
|
||||
/**
|
||||
* @title 获取企业列表
|
||||
*
|
||||
* @param [type] $request
|
||||
* @return void
|
||||
*/
|
||||
public function getCompanyList($request) {
|
||||
$param = $request->param();
|
||||
$map = [];
|
||||
if (isset($param['name']) && $param['name']) {
|
||||
$map[] = ['name', 'LIKE', '%' . $param['name'] . '%'];
|
||||
}
|
||||
if (isset($param['org_code']) && $param['org_code']) {
|
||||
$map[] = ['org_code', '=', $param['org_code']];
|
||||
}
|
||||
$list = Company::with(['contact'])->where($map)->order('id desc')->paginate($request->pageConfig);
|
||||
return $list->append(['area_t', 'industry_t']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 获取企业详情
|
||||
*
|
||||
* @param [type] $request
|
||||
* @return void
|
||||
*/
|
||||
public function getCompanyDetail($request) {
|
||||
$param = $request->param();
|
||||
if (!isset($param['id'])) {
|
||||
return [];
|
||||
}
|
||||
$map = [];
|
||||
$map[] = ['id', '=', $param['id']];
|
||||
$data = Company::with(['contact'])->where($map)->find();
|
||||
return $data->append(['area_t', 'industry_t']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 导入数据
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function insertCompanyData($request) {
|
||||
$data = $request->post('data');
|
||||
$company = new Company();
|
||||
$contactM = new Contact();
|
||||
|
||||
$resultData = [];
|
||||
foreach ($data as $k => $item) {
|
||||
$info = [];
|
||||
if (!is_array($item)) {
|
||||
continue;
|
||||
}
|
||||
foreach ($item as $key => $value) {
|
||||
if (isset($company->insertFieldAlis[$key])) {
|
||||
$info[$company->insertFieldAlis[$key]['table']][$company->insertFieldAlis[$key]['name']] = trim($value);
|
||||
}
|
||||
}
|
||||
$info['company']['uid'] = $info['contact']['uid'] = request()->user['uid'];
|
||||
|
||||
if (isset($info['company']) && isset($info['company']['name'])) {
|
||||
$customer = $company->where('name', '=', trim($info['company']['name']))->find();
|
||||
$company_id = isset($customer['id']) ? $customer['id'] : 0;
|
||||
if (!$company_id) {
|
||||
$info['company']['turnover'] = '';
|
||||
$info['company']['staff_num'] = '';
|
||||
$info['company']['come_from'] = '';
|
||||
$info['company']['company_type'] = '';
|
||||
$info['company']['pc_count'] = '';
|
||||
$customer = Company::create($info['company']);
|
||||
$company_id = $customer->id;
|
||||
} else {
|
||||
$save_coustomer = $info['company'];
|
||||
if (!empty($save_coustomer)) {
|
||||
$save_coustomer['id'] = $company_id;
|
||||
$result = $customer->save($save_coustomer);
|
||||
}
|
||||
}
|
||||
if (isset($info['contact']['name'])) {
|
||||
$map = [];
|
||||
$map[] = ['name', '=', $info['contact']['name']];
|
||||
$map[] = ['mobile', '=', isset($info['contact']['mobile']) ? $info['contact']['mobile'] : ''];
|
||||
$map[] = ['company_id', '=', $company_id];
|
||||
$contact = $contactM->where($map)->find(); //每次查询重新实例化
|
||||
$contact_id = isset($contact['id']) ? $contact['id'] : 0;
|
||||
if (!$contact_id) {
|
||||
$info['contact']['company_id'] = $company_id;
|
||||
$res = Contact::create($info['contact']);
|
||||
$contact_id = $res->id;
|
||||
} else {
|
||||
$info['contact']['id'] = $contact_id;
|
||||
$contact->save($info['contact']);
|
||||
}
|
||||
} else {
|
||||
$contact_id = 0;
|
||||
}
|
||||
$resultData[] = ['company_id' => $company_id, 'contact_id' => (int) $contact_id, 'company' => $info['company'], 'contact' => $info['contact']];
|
||||
}
|
||||
}
|
||||
return empty($resultData) ? false : $resultData;
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ namespace app\services\system;
|
||||
|
||||
use app\model\system\Dictionary;
|
||||
use app\model\system\DictionaryType;
|
||||
use sent\tree\Tree;
|
||||
use Xin\Support\Arr;
|
||||
|
||||
class DictionaryService{
|
||||
/**
|
||||
@@ -53,7 +53,7 @@ class DictionaryService{
|
||||
public function getTree($request){
|
||||
$list = DictionaryType::select()->toArray();
|
||||
|
||||
$tree = (new Tree())->listToTree($list, 'id', 'parent_id', 'children');
|
||||
$tree = Arr::tree($list, null, 0, ['id'=>'id', 'parent' => 'parent_id', 'child' => 'children']);
|
||||
return $tree;
|
||||
}
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user