Mike 8 年 前
コミット
205f590e86

+ 37 - 2
miaomiao/www/js/controllers/my.js

xqd
@@ -1,9 +1,44 @@
 (function (app) {
-    app.controller('myCtrl', ["$scope", "$state", "storage", "myService", "msg"
-        , function ($scope, $state, storage, myService, msg) {
+    app.controller('myCtrl', ["$scope", "$state", "$http", "storage", "myService", "common", "config", "msg"
+        , function ($scope, $state, $http, storage, myService, common, config, msg) {
         $scope.$on('$ionicView.beforeEnter', function (viewResult) {
             
         });
+
+
+        $scope.testuploadFile = function(files) {       //单次提交图片的函数
+          console.log(files[0]);
+          var formData = new FormData();
+          formData.append('file', files[0]);
+          formData.append('tag', 'avatar');
+
+          $http({
+              method: 'POST',
+              url: config.server + 'api/attachment/upload',
+              transformRequest: angular.identity,
+              data: formData,
+              // headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8' }
+              headers: {'Content-Type': undefined}
+          }).then(function (result) {
+              // alert(JSON.stringify(result));
+            console.log("attachment upload result:"+JSON.stringify(result));
+          }, function (erro) {
+            console.log("attachment upload erro:"+JSON.stringify(erro));
+              
+          })
+        }
+        $scope.setAvator = function () {
+            common.setAvator().then(function (result) {
+                var response = JSON.parse(result.response);
+                $timeout(function () {
+                    $scope.vm.user.avatar = response.data.md5;
+                });
+            }, function (erro) {
+                msg.erro(JSON.stringify(erro));
+            });
+        };
+
+
         $scope.toprofile = function () {
             $state.go('app.my_profile');
         }

+ 2 - 1
miaomiao/www/templates/my/index.html

xqd
@@ -1,7 +1,8 @@
 <ion-view view-title="我的"  hide-nav-bar="true">
     <ion-content>
         <div class="user-box">
-            <div class="myinfo">
+         <input type="file" id="one-input" accept="image/*" file-model="images" onchange="angular.element(this).scope().testuploadFile(this.files)"/>
+            <div class="myinfo" ng-click="setAvator()">
                 <img ng-src="img/demo/head5.jpg" />
                 <div>
                     喵喵喵喵酱

+ 5 - 3
server/app/Helper/AttachmentHelper.php

xqd xqd xqd
@@ -4,8 +4,8 @@ namespace App\Helper;
 use Illuminate\Http\Request;
 use Illuminate\Http\UploadedFile;
 use Symfony\Component\HttpFoundation\File\Exception\FileException;
-use App\Library\Protocol\ErrorCode;
-use App\Models\Attachment;
+use App\Services\Base\ErrorCode;
+use App\Models\BaseAttachmentModel;
 
 trait AttachmentHelper
 {
@@ -20,7 +20,9 @@ trait AttachmentHelper
      * @return array|string|int 返回:md5字串|ErrorCode或[md5字串|ErrorCode]
      */
     public function uploadAttachment(Request $request, $key, $tag = 'files', $size = 2 * 1024 * 1024, array $mimeType = []) {
+        \Log::info("key:".$request->hasFile($key));
         if ($request->hasFile($key)) {
+            \Log::info("key:".$key);
             $rel_path = '/upload/' . $tag . '/' . date('Ymd');
             $path = public_path() . $rel_path;
             if (!file_exists($path)) {
@@ -66,7 +68,7 @@ trait AttachmentHelper
                     $real_path = $path . '/' . $md5_filename;
                     $url_path = $rel_path . '/' . $md5_filename;
 
-                    $attachment = new Attachment();
+                    $attachment = new BaseAttachmentModel();
                     $attachment->name = $clientName;
                     $attachment->md5 = $md5;
                     $attachment->path = $real_path;

+ 1 - 1
server/app/Helper/SmsHelper.php

xqd
@@ -1,5 +1,5 @@
 <?php
-namespace App\Http\HelperTraits;
+namespace App\Helper;
 
 use GuzzleHttp\Client as GuzzleHttpClient;
 use GuzzleHttp\Exception\RequestException;

+ 2 - 1
server/app/Http/Controllers/Api/V1/AttachmentController.php

xqd xqd
@@ -47,7 +47,7 @@ class AttachmentController extends Controller
      * @apiGroup Attachment
      * @apiPermission none
      * @apiVersion 0.1.0
-     * @apiParam {string} tag 附件标签
+     * @apiParam {string} tag 附件标签 avatar video dream
      * @apiParam {File} file 附件(可以多个,使用file.xxx,可返回多个)[默认大小2M, 类型图片]
      * @apiSuccessExample {json} Success-Response:
      * HTTP/1.1 200 OK
@@ -85,6 +85,7 @@ class AttachmentController extends Controller
      *    1203    ATTACHMENT_NOT_EXIST            附件不存在
      */
     public function upload(Request $request) {
+        \Log::info($request->all());
         $validator = Validator::make($request->all(),
             [
                 'tag'         => 'required|alpha_dash',

+ 1 - 1
server/app/Http/Controllers/Api/V1/AuthController.php

xqd
@@ -2,7 +2,7 @@
 
 namespace App\Http\Controllers\Api\V1;
 
-use App\Http\HelperTraits\SmsHelper;
+use App\Helper\SmsHelper;
 use App\Models\UserBanks;
 use Illuminate\Foundation\Auth\AuthenticatesUsers;
 use App\Models\UserInfoModel;

+ 0 - 1
server/app/Http/Controllers/Api/V1/HomeController.php

xqd
@@ -2,7 +2,6 @@
 
 namespace App\Http\Controllers\Api\V1;
 
-use App\Http\Controllers\Api\V1\Controller;
 use App\Models\BaseSettingsModel;
 use App\Models\DreamImages;
 use App\Models\DreamInfoModel;

+ 39 - 0
server/app/Http/Controllers/Web/AttachmentController.php

xqd
@@ -0,0 +1,39 @@
+<?php
+
+namespace App\Http\Controllers\Web;
+
+use App\Models\BaseAttachmentModel;
+use Response;
+
+class AttachmentController extends Controller
+{
+
+    public function download($md5)
+    {
+        $attachment = BaseAttachmentModel::where(['md5' => $md5])->first();
+        if (!$attachment) {
+            return view('errors.404');
+        }
+
+        return Response::download($attachment->path, $attachment->name, [
+            'Content-type'  => $attachment->file_type,
+            'Accept-Ranges' => 'bytes',
+            'Accept-Length' => $attachment->size,
+        ]);
+    }
+
+    public function image($md5)
+    {
+        $attachment = BaseAttachmentModel::where(['md5' => $md5])->first();
+        if (!$attachment) {
+            return view('errors.404');
+        }
+
+        return Response::download($attachment->path, $attachment->name, [
+            'Content-type'  => $attachment->file_type,
+            'Accept-Ranges' => 'bytes',
+            'Accept-Length' => $attachment->size,
+        ], 'inline');
+    }
+
+}

+ 14 - 0
server/app/Http/Controllers/Web/Controller.php

xqd
@@ -0,0 +1,14 @@
+<?php
+
+namespace App\Http\Controllers\Web;
+
+use Illuminate\Routing\Controller as BaseController;
+use Illuminate\Foundation\Bus\DispatchesJobs;
+use Illuminate\Foundation\Validation\ValidatesRequests;
+use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
+
+class Controller extends BaseController
+{
+    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
+
+}

+ 0 - 46
server/app/Http/HelperTraits/SmsHelper.php

xqd
@@ -1,46 +0,0 @@
-<?php
-namespace App\Http\HelperTraits;
-
-use GuzzleHttp\Client as GuzzleHttpClient;
-use GuzzleHttp\Exception\RequestException;
-
-trait SmsHelper
-{
-    public function sendSms($msg, $mobile) {
-        $account = env('SMS_ACCOUNT');
-        $password = env('SMS_PASSWORD');
-        $password = strtoupper(md5($password));
-        $gwid = env('SMS_GWID');
-        $url = env('SMS_API_URL');
-        $message = iconv("UTF-8", "GB2312", $msg);
-
-        try {
-            $client = new GuzzleHttpClient();
-            $data = [
-                'action'      => 'Send',
-                'username'        => $account,
-                'password'       => $password,
-                'gwid'      => $gwid,
-                'mobile'    => $mobile,
-                'message'       => $message,
-            ];
-            $apiRequest = $client->post($url, [
-                'form_params'      => $data,
-            ]);
-            $resp = $apiRequest->getBody()->getContents();
-            $res = iconv("GB2312", "UTF-8", $resp);
-            $re = json_decode($res, true);
-            \Log::info("发送短信 到手机:$mobile 内容:$msg RESULT:".$re['RESULT']);
-            if (trim($re['CODE']) == '1') {
-                return true;
-            }
-//            print_r($resp);
-        } catch (RequestException $re) {
-            \Log::info("发送短信错误:".$re->getMessage());
-            return false;
-        }
-
-        return false;
-    }
-
-}

+ 0 - 1
server/app/Http/Kernel.php

xqd
@@ -41,7 +41,6 @@ class Kernel extends HttpKernel
         'api' => [
             'throttle:60,1',
             'bindings',
-            Cors::class,
         ],
     ];
 

+ 1 - 1
server/app/Services/Base/Attachment.php

xqd
@@ -13,7 +13,7 @@
 namespace App\Services\Base;
 
 use App\Models\BaseAttachmentModel;
-use Response;
+
 class Attachment
 {
     private $_model;

+ 6 - 6
server/resources/views/admin/user/info/edit.blade.php

xqd xqd xqd xqd xqd xqd
@@ -104,7 +104,7 @@
                  <label class="control-label col-sm-3">工作类型</label>
                                     
                    <div class="col-sm-9">
-                       @foreach(dict()->get('user_info','sex') as $key=>$val)
+                       @foreach(dict()->get('global','sex') as $key=>$val)
                            <label class="radio-inline">
                                <input type="radio" name="data[job]" value="{{$key}}" @if(isset($data['job']) && $data['job'] == $key)checked="checked" @endif/>{{$val}}
                            </label>
@@ -154,7 +154,7 @@
                  <label class="control-label col-sm-3">居住时长</label>
                                     
                    <div class="col-sm-9">
-                       @foreach(dict()->get('user_info','sex') as $key=>$val)
+                       @foreach(dict()->get('global','sex') as $key=>$val)
                                <label class="radio-inline">
                                    <input type="radio" name="data[address_time]" value="{{$key}}" @if(isset($data['address_time']) && $data['address_time'] == $key)checked="checked" @endif/>{{$val}}
                                </label>
@@ -194,7 +194,7 @@
                  <label class="control-label col-sm-3">学历</label>
                                     
                    <div class="col-sm-9">
-                       @foreach(dict()->get('user_info','sex') as $key=>$val)
+                       @foreach(dict()->get('global','sex') as $key=>$val)
                            <label class="radio-inline">
                                <input type="radio" name="data[educational]" value="{{$key}}" @if(isset($data['educational']) && $data['educational'] == $key)checked="checked" @endif/>{{$val}}
                            </label>
@@ -206,7 +206,7 @@
                                     
                  <label class="control-label col-sm-3">婚姻状况</label>
                                     
-                   <div class="col-sm-9"> @foreach(dict()->get('user_info','sex') as $key=>$val)
+                   <div class="col-sm-9"> @foreach(dict()->get('global','sex') as $key=>$val)
                                                    <label class="radio-inline">
                                                        <input type="radio" name="data[marital]" value="{{$key}}" @if(isset($data['marital']) && $data['marital'] == $key)checked="checked" @endif/>{{$val}}
                                                    </label>
@@ -218,7 +218,7 @@
                                     
                  <label class="control-label col-sm-3">直系亲属联系人关系</label>
 
-                   <div class="col-sm-9"> @foreach(dict()->get('user_info','sex') as $key=>$val)
+                   <div class="col-sm-9"> @foreach(dict()->get('global','sex') as $key=>$val)
                                                    <label class="radio-inline">
                                                        <input type="radio" name="data[contact_bind]" value="{{$key}}" @if(isset($data['contact_bind']) && $data['contact_bind'] == $key)checked="checked" @endif/>{{$val}}
                                                    </label>
@@ -248,7 +248,7 @@
                                     
                  <label class="control-label col-sm-3">其他联系人关系</label>
                                     
-                   <div class="col-sm-9"> @foreach(dict()->get('user_info','sex') as $key=>$val)
+                   <div class="col-sm-9"> @foreach(dict()->get('global','sex') as $key=>$val)
                                                    <label class="radio-inline">
                                                        <input type="radio" name="data[other_contact_bind]" value="{{$key}}" @if(isset($data['other_contact_bind']) && $data['other_contact_bind'] == $key)checked="checked" @endif/>{{$val}}
                                                    </label>

+ 19 - 0
server/routes/api.php

xqd
@@ -23,6 +23,25 @@ use Illuminate\Http\Request;
 $api = app('Dingo\Api\Routing\Router');
 
 $api->version('v1', ['namespace' => 'App\Http\Controllers\Api\V1'], function ($api) {
+
+
+    //附件下载
+    $api->get('attachment/download/{md5}', [
+        'as' => 'attachment.download',
+        'uses' => 'AttachmentController@download',
+    ]);
+    //附件上传
+    $api->post('attachment/upload', [
+        'as' => 'attachment.upload',
+        'uses' => 'AttachmentController@upload',
+    ]);
+    //附件删除
+    $api->get('attachment/delete/{md5}', [
+        'as' => 'attachment.delete',
+        'uses' => 'AttachmentController@delete',
+    ]);
+
+
     // test
     $api->get('test', [
         'as' => 'test',

+ 11 - 0
server/routes/web.php

xqd
@@ -14,6 +14,17 @@
 Route::get('/', function () {
     return view('welcome');
 });
+
+Route::get('attachment/{md5}', [
+    'as' => 'attachment.download',
+    'uses' => 'Web\AttachmentController@download',
+]);
+Route::get('image/{md5}', [
+    'as' => 'attachment.image',
+    'uses' => 'Web\AttachmentController@image',
+]);
+
+
 Route::get('/test',function() {
 
     $password = bcrypt('admin');