作者 zhl

v5 get hr list

@@ -10,10 +10,15 @@ namespace App\Console\Commands\Test; @@ -10,10 +10,15 @@ namespace App\Console\Commands\Test;
10 use App\Models\Blog\Blog; 10 use App\Models\Blog\Blog;
11 use App\Models\Devops\ServerConfig; 11 use App\Models\Devops\ServerConfig;
12 use App\Models\File\Image; 12 use App\Models\File\Image;
  13 +use App\Models\Manage\BelongingGroup;
  14 +use App\Models\Manage\Dept;
  15 +use App\Models\Manage\EntryPosition;
  16 +use App\Models\Manage\ManageHr;
13 use App\Services\ProjectServer; 17 use App\Services\ProjectServer;
14 use GuzzleHttp\Client; 18 use GuzzleHttp\Client;
15 use Illuminate\Console\Command; 19 use Illuminate\Console\Command;
16 use Illuminate\Support\Facades\DB; 20 use Illuminate\Support\Facades\DB;
  21 +use Illuminate\Support\Facades\Log;
17 22
18 class Demo extends Command 23 class Demo extends Command
19 { 24 {
@@ -41,11 +46,185 @@ class Demo extends Command @@ -41,11 +46,185 @@ class Demo extends Command
41 parent::__construct(); 46 parent::__construct();
42 } 47 }
43 48
  49 + public function curlRequest($url, $data, $method = 'POST', $header = [], $time_out = 60)
  50 + {
  51 +
  52 + $ch = curl_init();
  53 + curl_setopt($ch, CURLOPT_TIMEOUT, $time_out);
  54 + curl_setopt($ch, CURLOPT_URL, $url);
  55 + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  56 + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  57 + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  58 + if ($data)
  59 + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
  60 + curl_setopt($ch, CURLOPT_HTTPHEADER, array_merge([
  61 + 'Expect:',
  62 + 'Content-type: application/json',
  63 + 'Accept: application/json',
  64 + ], $header)
  65 + );
  66 + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
  67 + $response = curl_exec($ch);
  68 + $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  69 + curl_close($ch);
  70 + return [$code, $response];
  71 + }
  72 +
44 /** 73 /**
45 * @return bool 74 * @return bool
46 */ 75 */
47 public function handle() 76 public function handle()
48 { 77 {
  78 + $data = [];
  79 + dd(isset($data['a']['b']));
  80 + $url = 'https://demo.globalso.site/';
  81 + $action = 'api/updateHtmlNotify/';
  82 + $data = [
  83 + 'project_id' => 1,
  84 + 'type' => 1,
  85 + 'route' => 1
  86 + ];;
  87 + $method = 'GET';
  88 + $result = $this->curlRequest($url . $action, $data, $method);
  89 + dd($result);
  90 +
  91 + $context = stream_context_create([
  92 + 'ssl' => [
  93 + 'capture_peer_cert' => true,
  94 + 'capture_peer_cert_chain' => false,
  95 + ],
  96 + ]);
  97 +
  98 + $stream = stream_socket_client('ssl://oa.quanqiusou.cn:443', $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context);
  99 +
  100 + if(!$stream) {
  101 + die("Failed to connect: $errno - $errstr");
  102 + }
  103 +
  104 + $remote_cert = stream_context_get_params($stream)['options']['ssl']['peer_certificate'];
  105 +
  106 + if(!$remote_cert) {
  107 + die("Failed to retrieve certificate");
  108 + }
  109 +
  110 + $valid_from = date('Y-m-d H:i:s', openssl_x509_parse($remote_cert)['validFrom_time_t']);
  111 + $valid_to = date('Y-m-d H:i:s', openssl_x509_parse($remote_cert)['validTo_time_t']);
  112 +
  113 + fclose($stream);
  114 +
  115 + echo "Certificate Valid From: $valid_from<br>";
  116 + echo "Certificate Valid To: $valid_to<br>";
  117 +
  118 + dd('end');
  119 + $dept_array = [
  120 + '品牌部',
  121 + '综合部',
  122 + '渠道部',
  123 + '广告推广部',
  124 + 'AICC运营部',
  125 + '黑格运营部',
  126 + '直营运营部',
  127 + '直营销售部',
  128 + '深圳跨境部',
  129 + '外贸部',
  130 + '研发部',
  131 + '技术部',
  132 + '售后部',
  133 + ];
  134 + foreach ($dept_array as $v) {
  135 + $dept = Dept::where(['title' => $v])->first();
  136 + if (FALSE == empty($dept))
  137 + continue;
  138 + $dept = new Dept();
  139 + $dept->title = $v;
  140 + $dept->save();
  141 + }
  142 +// dd('dept end');
  143 + $dept_map = Dept::pluck('title', 'id')->toArray();
  144 + $belonging_map = BelongingGroup::pluck('name', 'id')->toArray();
  145 +// dd($belonging_map);
  146 +
  147 + $filename = storage_path('logs/oa_hr.txt');
  148 + $string = file_get_contents($filename);
  149 + $data = explode("\r\n", $string);
  150 + $data = array_filter($data);
  151 + $dept = '';
  152 + foreach ($data as $k=>$v) {
  153 +// var_dump($v) . PHP_EOL;
  154 + if ($k == 1)
  155 + continue;
  156 + $tmp = explode("\t", $v);
  157 + if (count($tmp) == 3) {
  158 + $dept = $tmp[0] ? : $dept;
  159 + $position = $tmp[1];
  160 + $name = $tmp[2];
  161 + } else if (count($tmp) == 2) {
  162 + $position = $tmp[0];
  163 + $name = $tmp[1];
  164 + } else {
  165 + Log::info($v . PHP_EOL);
  166 + continue;
  167 + }
  168 +
  169 +
  170 +// Log::info($dept . '---' . $position . '---' . $name . PHP_EOL);
  171 +// continue;
  172 +
  173 + $dept_id = array_search($dept, $dept_map);
  174 + $belonging_id = 17;
  175 + if (FALSE !== strpos($dept,'技术部')) {
  176 + $belonging_string = str_replace('技术部', '', $dept);
  177 + if ($belonging_string) {
  178 + $belonging_string = $belonging_string . '组';
  179 + $belonging_id = array_search($belonging_string, $belonging_map);
  180 + }
  181 +
  182 + $dept_tmp = '技术部';
  183 + $dept_id = array_search($dept_tmp, $dept_map);
  184 + }
  185 + if (FALSE !== strpos($dept,'售后')) {
  186 + $belonging_string = str_replace('售后', '', $dept);
  187 + if ($belonging_string)
  188 + $belonging_id = array_search($belonging_string, $belonging_map);
  189 + $dept_tmp = '售后部';
  190 + $dept_id = array_search($dept_tmp, $dept_map);
  191 + }
  192 +
  193 + $position_log = EntryPosition::where(['name' => $position])->first();
  194 + if (empty($position_log)) {
  195 + $position_log = new EntryPosition();
  196 + $position_log->name = $position;
  197 + $position_log->save();
  198 + }
  199 + $position_id = $position_log->id;
  200 +
  201 + $hr = ManageHr::where(['name' => $name])->first();
  202 + if (empty($hr)) {
  203 + Log::info($k . '-' . $name . '-' . $dept . '-' . $dept_id . '-' . $position . '-' . $position_id);
  204 + continue;
  205 + }
  206 +
  207 + $hr->belong_group = $belonging_id;
  208 + $hr->dept_id = $dept_id;
  209 + $hr->entry_position = $position_id;
  210 + $hr->save();
  211 + echo $k . '-' . $name . '-' . $dept . '-' . $dept_id . '-' . $position . '-' . $position_id . '-' . '组' . '-' . $belonging_id . PHP_EOL;
  212 +
  213 + }
  214 + dd('end');
  215 + exit;
  216 +
  217 + if (($handle = fopen($filename, 'r')) !== false) {
  218 + while (($data = fgetcsv($handle, 1000, ',')) !== false) {
  219 + // 处理每行数据
  220 + Log::info(var_export($data, true));
  221 + }
  222 + fclose($handle);
  223 + }
  224 + exit;
  225 +
  226 + $group = BelongingGroup::get();
  227 + dd($group->toArray());
49 $domain = parse_url('https//:dev.golbalso.site/'); 228 $domain = parse_url('https//:dev.golbalso.site/');
50 dd($domain); 229 dd($domain);
51 echo time() . PHP_EOL; 230 echo time() . PHP_EOL;
@@ -75,4 +75,26 @@ class HrController extends BaseController @@ -75,4 +75,26 @@ class HrController extends BaseController
75 $this->response('success',Code::SUCCESS,$list); 75 $this->response('success',Code::SUCCESS,$list);
76 } 76 }
77 77
  78 + /**
  79 + * @param HrLogic $hrLogic
  80 + * @return \Illuminate\Http\JsonResponse
  81 + */
  82 + public function getHrList(HrLogic $hrLogic)
  83 + {
  84 + $page_size = intval(request()->input('page_size', 15));
  85 + $list = $hrLogic->getHrListForV5($page_size);
  86 + $result = [];
  87 + foreach ($list as $v) {
  88 + $result[] = [
  89 + 'name' => $v->name,
  90 + 'id_card' => $v->id_card,
  91 + 'mobile' => $v->mobile,
  92 + 'dept_title' => $v->dept_title = $v->dept ? $v->dept->title : '',
  93 + 'position_title' => $v->position = $v->position ? $v->position->name : '',
  94 + 'status' => $v->status,
  95 + ];
  96 + }
  97 + return $this->response('success',Code::SUCCESS, $result);
  98 + }
  99 +
78 } 100 }
@@ -222,4 +222,14 @@ class HrLogic extends BaseLogic @@ -222,4 +222,14 @@ class HrLogic extends BaseLogic
222 ]; 222 ];
223 return $managerModel->addReturnId($data); 223 return $managerModel->addReturnId($data);
224 } 224 }
  225 +
  226 + /**
  227 + * @param $page_size
  228 + * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
  229 + */
  230 + public function getHrListForV5($page_size)
  231 + {
  232 + $list = $this->model->with('dept')->with('position')->select(['name', 'id_card', 'mobile', 'dept_id', 'entry_position', 'status'])->orderBy('id', 'desc')->paginate($page_size);
  233 + return $list;
  234 + }
225 } 235 }
@@ -161,4 +161,22 @@ class ManageHr extends Base @@ -161,4 +161,22 @@ class ManageHr extends Base
161 2 => '否', 161 2 => '否',
162 ]; 162 ];
163 } 163 }
  164 +
  165 + /**
  166 + * @return \Illuminate\Database\Eloquent\Relations\HasOne
  167 + */
  168 + public function dept()
  169 + {
  170 + return $this->hasOne(Dept::class, 'id', 'dept_id');
  171 + }
  172 +
  173 + public function position()
  174 + {
  175 + return $this->hasOne(EntryPosition::class, 'id', 'entry_position');
  176 + }
  177 +
  178 + public function getDeptNameAttribute()
  179 + {
  180 + return $this->dept->name;
  181 + }
164 } 182 }
@@ -323,6 +323,8 @@ Route::group([], function () { @@ -323,6 +323,8 @@ Route::group([], function () {
323 Route::any('/sendLoginSms', [Aside\LoginController::class, 'sendLoginSms'])->name('admin.sendLoginSms');//发送验证码 323 Route::any('/sendLoginSms', [Aside\LoginController::class, 'sendLoginSms'])->name('admin.sendLoginSms');//发送验证码
324 Route::any('/getProjectInService', [Aside\Project\ProjectController::class, 'getProjectInService'])->name('admin.getProjectInService');//获取项目服务状态 324 Route::any('/getProjectInService', [Aside\Project\ProjectController::class, 'getProjectInService'])->name('admin.getProjectInService');//获取项目服务状态
325 Route::any('/getProjectByChannel', [Aside\Project\ProjectController::class, 'getProjectByChannel'])->name('admin.getProjectByChannel');//获取渠道商的项目 325 Route::any('/getProjectByChannel', [Aside\Project\ProjectController::class, 'getProjectByChannel'])->name('admin.getProjectByChannel');//获取渠道商的项目
  326 + // 提供接口 同步人事信息到5.0后台
  327 + Route::any('/get_hr_list', [Aside\Manage\HrController::class , 'getHrList'])->name('admin.get_hr_list');
326 }); 328 });
327 329
328 330