| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470 |
- <?php
- /**
- * Created by PhpStorm.
- * User: 芸众网
- * Date: 2019/7/1
- * Time: 13:43
- */
- namespace app\backend\modules\setting\controllers;
- use app\common\components\BaseController;
- use app\common\facades\Setting;
- use app\common\helpers\ImageHelper;
- use app\common\helpers\Url;
- use app\common\models\WebSiteInfo;
- use Illuminate\Support\Facades\Storage;
- use Ixudra\Curl\Facades\Curl;
- class WorkOrderController extends BaseController
- {
- // 工单管理
- public function index()
- {
- $key = Setting::get('shop.key')['key'];
- $secret = Setting::get('shop.key')['secret'];
- $post_data = [
- 'page' => 1,
- 'post_data' => [
- 'category_id' => 0,
- 'status' => 0,
- 'work_order_sn' => 0,
- 'has_time_limit' => 0,
- 'start_time' => 0,
- 'end_time' => 0,
- 'show_all' => 0,
- 'domain' => $_SERVER['HTTP_HOST'],
- ],
- ];
- $url = config('auto-update.workOrderUrl') . '/api/work-order/get-work-order-list/';
- $data = Curl::to($url)
- ->withHeader("Authorization: Basic " . base64_encode("{$key}:{$secret}"))
- ->withData($post_data)
- ->asJsonResponse(true)
- ->post();
- if ($data && $data['result'] == 1) {
- return view('setting.work-order.list', [
- 'data' => json_encode($data['data']),
- 'category_list' => json_encode($this->category()),
- 'status_list' => json_encode($this->status()),
- ])->render();
- } else {
- return view('setting.work-order.list', [
- 'data' => json_encode([]),
- 'category_list' => json_encode($this->category()),
- 'status_list' => json_encode($this->status()),
- ])->render();
- }
- }
- /**
- * 工单检索
- * @return \Illuminate\Http\JsonResponse
- */
- public function search()
- {
- $data = request()->input('data');
- $post_data = [
- 'page' => $data['page'],
- 'post_data' => [
- 'category_id' => $data['category_id'],
- 'status' => $data['status'],
- 'work_order_sn' => $data['work_order_sn'],
- 'has_time_limit' => $data['has_time_limit'],
- 'start_time' => $data['start_time'] / 1000,
- 'end_time' => $data['end_time'] / 1000,
- 'show_all' => $data['show_all'],
- 'domain' => $_SERVER['HTTP_HOST'],
- ],
- ];
- $key = Setting::get('shop.key')['key'];
- $secret = Setting::get('shop.key')['secret'];
- $url = config('auto-update.workOrderUrl') . '/api/work-order/get-work-order-list/';
- $data = Curl::to($url)
- ->withHeader("Authorization: Basic " . base64_encode("{$key}:{$secret}"))
- ->withData($post_data)
- ->asJsonResponse(true)
- ->post();
- if ($data && $data['result'] == 1) {
- return $this->successJson('成功', $data['data']);
- } else {
- return $this->errorJson('失败');
- }
- }
- private function getFileType()
- {
- return ['docx','ai','avi','txt','jpg','png','jpeg','bmp','cdr','doc','eps','gif','html','mp3','mp4','pdf','ppt','pr','psd','rar','svg','gif','xlsx','zip'];
- }
- /**
- * 上传
- * @return \Illuminate\Http\JsonResponse
- */
- public function uploadFile()
- {
- $file = request()->file('file');
- if (!$file) {
- return $this->errorJson('请传入正确参数.');
- }
- if ($file->isValid()) {
- $ext = $file->getClientOriginalExtension();
- if(!in_array($ext,$this->getFileType())){
- return $this->errorJson('请检查文件后缀是否支持');exit();
- }
- // 获取文件相关信息
- $originalName = $file->getClientOriginalName(); // 文件原名
- $realPath = $file->getRealPath(); //临时文件的绝对路径
- $newOriginalName = md5($originalName . str_random(6)) . '.' . $ext;
- Storage::disk('image')->put($newOriginalName, file_get_contents($realPath));
- if (config('APP_Framework') == 'platform') {
- $attachment = 'static/upload/';
- } else {
- $attachment = 'attachment/';
- }
- return $this->successJson('上传成功', [
- 'thumb' => \Storage::disk('image')->url($newOriginalName),
- 'thumb_url' => ImageHelper::getImageUrl($attachment . substr(\Storage::disk('image')->url($newOriginalName), strripos(\Storage::disk('image')->url($newOriginalName), "image"))),
- ]);
- }
- return $this->errorJson($file->getErrorMessage());
- }
- /**
- * base64图片上传
- * @return \Illuminate\Http\JsonResponse
- */
- public function base64Upload()
- {
- $base_img = request()->input('file');
- $base_img = str_replace('data:image/jpg;base64,', '', $base_img);
- $newOriginalName = time() . rand(100, 999) . '.png';
- Storage::disk('image')->put($newOriginalName, file_get_contents($base_img));
- if (config('APP_Framework') == 'platform') {
- $attachment = 'static/upload/';
- } else {
- $attachment = 'attachment/';
- }
- return $this->successJson('上传成功', [
- 'thumb' => \Storage::disk('image')->url($newOriginalName),
- 'thumb_url' => ImageHelper::getImageUrl($attachment . substr(\Storage::disk('image')->url($newOriginalName), strripos(\Storage::disk('image')->url($newOriginalName), "image"))),
- ]);
- }
- /**
- * 详情
- * @return mixed|string
- */
- public function details()
- {
- $id = request()->input('id');
- $key = Setting::get('shop.key')['key'];
- $secret = Setting::get('shop.key')['secret'];
- $data = Curl::to(config('auto-update.workOrderUrl') . '/work-order/details/' . $id)
- ->withHeader("Authorization: Basic " . base64_encode("{$key}:{$secret}"))
- ->asJsonResponse(true)
- ->get();
- if ($data && $data['result'] == 1) {
- foreach ($data['data']['has_many_comment'] as $key => $value) {
- $data['data']['has_many_comment'][$key]['thumb_url'] = json_decode($value['thumb_url']);
- }
- $data['data']['thumb_url'] = json_decode($data['data']['thumb_url']);
- return view('setting.work-order.details', ['data' => json_encode($data['data'])])->render();
- } else {
- return $this->message('ID不存在', Url::absoluteWeb('setting.work-order.index'));
- }
- }
- /**
- * 评论接口
- * @return \Illuminate\Http\JsonResponse
- */
- public function comment()
- {
- $postData = request()->input();
- $this->validateCommentParam();
- $data = [
- 'work_order_id' => $postData['work_order_id'],
- 'content' => $postData['content'],
- 'thumb_url' => json_encode($postData['thumb_url']),
- 'work_order' => 1,
- 'domain' => $_SERVER['HTTP_HOST'],
- ];
- $key = Setting::get('shop.key')['key'];
- $secret = Setting::get('shop.key')['secret'];
- $data = Curl::to(config('auto-update.workOrderUrl') . '/work-order/comment')
- ->withHeader("Authorization: Basic " . base64_encode("{$key}:{$secret}"))
- ->withData($data)
- ->asJsonResponse(true)
- ->post();
- if (!$data) {
- $this->errorJson('远端服务器异常');
- }
- if ($data['result'] == 0) {
- return $this->errorJson('提交失败');
- } else {
- return $this->successJson('提交成功');
- }
- }
- /**
- * 页面
- * @return string
- */
- public function storePage()
- {
- return view('setting.work-order.store-page', [
- 'site_url' => json_encode($_SERVER['HTTP_HOST']),
- 'category_list' => json_encode($this->category()),
- 'first_list' => json_encode($this->firstList()),
- ])->render();
- }
- /**
- * 获取秘钥
- */
- private function getKey()
- {
- $key = Setting::get('shop.key')['key'];
- $secret = Setting::get('shop.key')['secret'];
- $data = Curl::to(config('auto-update.workOrderUrl') . '/work-order/get-user-key')
- ->withHeader("Authorization: Basic " . base64_encode("{$key}:{$secret}"))
- ->withData(['domain' => $_SERVER['HTTP_HOST'], 'work_order' => 1])
- ->asJsonResponse(true)
- ->post();
- if ($data['result'] == 1 && $data) {
- return $data['data'];
- } else {
- return false;
- }
- }
- /**
- * 第一次提交数据
- * @return array
- */
- private function firstList()
- {
- $webSiteInfo = WebSiteInfo::where('website_url', $_SERVER['HTTP_HOST'])->first();
- $key = $this->getKey();
- if ($key == false) {
- return [
- "website_url" => $_SERVER['HTTP_HOST'],
- ];
- }
- return [
- "id" => $webSiteInfo->id,
- "uniacid" => $webSiteInfo->uniacid,
- "website_url" => $webSiteInfo->website_url,
- "founder_account" => $this->decryption($webSiteInfo->founder_account, $key),
- "founder_password" => $this->decryption($webSiteInfo->founder_password, $key),
- "server_ip" => $this->decryption($webSiteInfo->server_ip, $key),
- "root_password" => $this->decryption($webSiteInfo->root_password, $key),
- "root_username" => $this->decryption($webSiteInfo->root_username, $key),
- "ssh_port" => $this->decryption($webSiteInfo->ssh_port, $key),
- "database_address" => $this->decryption($webSiteInfo->database_address, $key),
- "database_username" => $this->decryption($webSiteInfo->database_username, $key),
- "database_password" => $this->decryption($webSiteInfo->database_password, $key),
- "root_directory" => $this->decryption($webSiteInfo->root_directory, $key),
- "qq" => $this->decryption($webSiteInfo->qq, $key),
- "mobile" => $this->decryption($webSiteInfo->mobile, $key),
- ];
- }
- /**
- * 解密
- * @param $string
- * @param $key
- * @return string
- */
- private function encipherment($string, $key)
- {
- return openssl_encrypt($string, 'DES-ECB', $key, 0);
- }
- /**
- * 加密
- * @param $string
- * @param $key
- * @return string
- */
- private function decryption($string, $key)
- {
- return openssl_decrypt($string, 'DES-ECB', $key, 0);
- }
- /**
- * 生成获取秘钥
- * @return bool
- */
- private function getEncryptionKey()
- {
- $key = Setting::get('shop.key')['key'];
- $secret = Setting::get('shop.key')['secret'];
- $data = Curl::to(config('auto-update.workOrderUrl') . '/work-order/get-key')
- ->withHeader("Authorization: Basic " . base64_encode("{$key}:{$secret}"))
- ->withData(['domain' => $_SERVER['HTTP_HOST'], 'work_order' => 1])
- ->asJsonResponse(true)
- ->post();
- if ($data['result'] == 1 && $data) {
- return $data['data'];
- } else {
- return false;
- }
- }
- /**
- * 工单提交接口
- * @return \Illuminate\Http\JsonResponse
- */
- public function store()
- {
- $encryptionKey = $this->getEncryptionKey();
- if ($encryptionKey == false) {
- $this->errorJson('获取秘钥失败');
- }
- $postData = request()->input('data');
- $this->validateParam();
- $data = [
- 'work_order' => '1',
- 'domain' => $_SERVER['HTTP_HOST'],
- 'category_id' => $postData['category_id'],
- 'question_title' => $postData['question_title'],
- 'question_describe' => $postData['question_describe'],
- 'thumb_url' => json_encode($postData['thumb_url']),
- 'user_data' => [
- 'website_url' => $_SERVER['HTTP_HOST'],
- 'founder_account' => $this->encipherment($postData['first_list']['founder_account'], $encryptionKey),
- 'founder_password' => $this->encipherment($postData['first_list']['founder_password'], $encryptionKey),
- 'server_ip' => $this->encipherment($postData['first_list']['server_ip'], $encryptionKey),
- 'root_username' => $this->encipherment($postData['first_list']['root_username'], $encryptionKey),
- 'root_password' => $this->encipherment($postData['first_list']['root_password'], $encryptionKey),
- 'ssh_port' => $this->encipherment($postData['first_list']['ssh_port'], $encryptionKey),
- 'database_address' => $this->encipherment($postData['first_list']['database_address'], $encryptionKey),
- 'database_username' => $this->encipherment($postData['first_list']['database_username'], $encryptionKey),
- 'database_password' => $this->encipherment($postData['first_list']['database_password'], $encryptionKey),
- 'root_directory' => $this->encipherment($postData['first_list']['root_directory'], $encryptionKey),
- 'qq' => $this->encipherment($postData['first_list']['qq'], $encryptionKey),
- 'mobile' => $this->encipherment($postData['first_list']['mobile'], $encryptionKey),
- ],
- ];
- $userData = $data['user_data'];
- $userData['uniacid'] = \YunShop::app()->uniacid;
- WebSiteInfo::updateOrCreate(['website_url' => $userData['website_url']], $userData);
- $key = Setting::get('shop.key')['key'];
- $secret = Setting::get('shop.key')['secret'];
- $data = Curl::to(config('auto-update.workOrderUrl') . '/work-order/index')
- ->withHeader("Authorization: Basic " . base64_encode("{$key}:{$secret}"))
- ->withData($data)
- ->asJsonResponse(true)
- ->post();
- if (!$data) {
- $this->errorJson('远端服务器异常');
- }
- if ($data['result'] == 0) {
- return $this->errorJson($data['msg']);
- } else {
- return $this->successJson('提交成功');
- }
- }
- /**
- * 状态
- * @return array
- */
- private function status()
- {
- return [
- 0 => [
- 'id' => 0,
- 'name' => '全部',
- ],
- 1 => [
- 'id' => 1,
- 'name' => '未处理',
- ],
- 2 => [
- 'id' => 2,
- 'name' => '处理中',
- ],
- 3 => [
- 'id' => 3,
- 'name' => '已处理',
- ],
- ];
- }
- /**
- * 验证
- */
- protected function validateParam()
- {
- $this->validate([
- 'data.category_id' => 'required | integer',
- 'data.question_title' => 'required',
- 'data.question_describe' => 'required | max:80',
- 'data.first_list.founder_account' => 'required | max:80',
- 'data.first_list.founder_password' => 'required | max:80',
- 'data.first_list.server_ip' => 'required | max:80',
- 'data.first_list.ssh_port' => 'required | max:80',
- 'data.first_list.database_address' => 'required | max:80',
- 'data.first_list.database_username' => 'required | max:80',
- 'data.first_list.root_password' => 'required | max:80',
- 'data.first_list.qq' => 'required | max:80',
- 'data.first_list.mobile' => 'required | max:80',
- ]);
- }
- /**
- * 验证评论参数
- */
- protected function validateCommentParam()
- {
- $this->validate([
- 'content' => 'required',
- 'work_order_id' => 'required | integer',
- ]);
- }
- /**
- * 分类
- * @return array
- */
- private function category()
- {
- return [
- 0 => [
- 'id' => 0,
- 'name' => '全部',
- ],
- 1 => [
- 'id' => 1,
- 'name' => 'bug提交',
- ],
- 2 => [
- 'id' => 2,
- 'name' => '优化建议',
- ],
- 3 => [
- 'id' => '3',
- 'name' => '开发需求',
- ],
- 4 => [
- 'id' => 4,
- 'name' => '其他',
- ],
- ];
- }
- }
|