dyjh 6 سال پیش
کامیت
ee6632f981
100فایلهای تغییر یافته به همراه8543 افزوده شده و 0 حذف شده
  1. 34 0
      .env.example
  2. 3 0
      .gitattributes
  3. 14 0
      .gitignore
  4. 7 0
      apidoc.json
  5. 40 0
      app/Console/Kernel.php
  6. 65 0
      app/Exceptions/Handler.php
  7. 126 0
      app/Helper/AttachmentHelper.php
  8. 71 0
      app/Helper/LogHelper.php
  9. 44 0
      app/Helper/SmsHelper.php
  10. 33 0
      app/Helper/constants.inc.php
  11. 736 0
      app/Helper/functions.inc.php
  12. 32 0
      app/Http/Controllers/Admin/Auth/ForgotPasswordController.php
  13. 101 0
      app/Http/Controllers/Admin/Auth/LoginController.php
  14. 71 0
      app/Http/Controllers/Admin/Auth/RegisterController.php
  15. 86 0
      app/Http/Controllers/Admin/Auth/ResetPasswordController.php
  16. 69 0
      app/Http/Controllers/Admin/Base/ActionlogController.php
  17. 168 0
      app/Http/Controllers/Admin/Base/AttachmentController.php
  18. 58 0
      app/Http/Controllers/Admin/Base/ClassController.php
  19. 97 0
      app/Http/Controllers/Admin/Base/CrudController.php
  20. 138 0
      app/Http/Controllers/Admin/Base/DictionaryController.php
  21. 66 0
      app/Http/Controllers/Admin/Base/IndexController.php
  22. 41 0
      app/Http/Controllers/Admin/Base/LogsController.php
  23. 120 0
      app/Http/Controllers/Admin/Base/MenusController.php
  24. 96 0
      app/Http/Controllers/Admin/Base/PhotosController.php
  25. 185 0
      app/Http/Controllers/Admin/Base/RoleController.php
  26. 41 0
      app/Http/Controllers/Admin/Base/SystemController.php
  27. 123 0
      app/Http/Controllers/Admin/Base/ToolController.php
  28. 195 0
      app/Http/Controllers/Admin/Base/UserController.php
  29. 167 0
      app/Http/Controllers/Admin/Controller.php
  30. 170 0
      app/Http/Controllers/Admin/Messages/InfoController.php
  31. 139 0
      app/Http/Controllers/Admin/Messages/TagController.php
  32. 178 0
      app/Http/Controllers/Admin/Payment/InfoController.php
  33. 18 0
      app/Http/Controllers/Admin/TestController.php
  34. 139 0
      app/Http/Controllers/Admin/User/InfoController.php
  35. 139 0
      app/Http/Controllers/Admin/Wechat/AppController.php
  36. 168 0
      app/Http/Controllers/Api/V1/AttachmentController.php
  37. 30 0
      app/Http/Controllers/Api/V1/AuthController.php
  38. 107 0
      app/Http/Controllers/Api/V1/Controller.php
  39. 354 0
      app/Http/Controllers/Api/V1/IndexController.php
  40. 117 0
      app/Http/Controllers/Api/V1/LoginController.php
  41. 236 0
      app/Http/Controllers/Api/V1/PayController.php
  42. 554 0
      app/Http/Controllers/Api/V1/UserController.php
  43. 13 0
      app/Http/Controllers/Controller.php
  44. 38 0
      app/Http/Controllers/Web/AttachmentController.php
  45. 23 0
      app/Http/Controllers/Web/AuthController.php
  46. 14 0
      app/Http/Controllers/Web/Controller.php
  47. 20 0
      app/Http/Controllers/Web/OrderController.php
  48. 65 0
      app/Http/Kernel.php
  49. 34 0
      app/Http/Middleware/Authenticate.php
  50. 41 0
      app/Http/Middleware/AuthenticateAdmin.php
  51. 47 0
      app/Http/Middleware/Cors.php
  52. 17 0
      app/Http/Middleware/EncryptCookies.php
  53. 26 0
      app/Http/Middleware/RedirectIfAuthenticated.php
  54. 18 0
      app/Http/Middleware/TrimStrings.php
  55. 20 0
      app/Http/Middleware/VerifyCsrfToken.php
  56. 89 0
      app/Models/AccountLog.php
  57. 74 0
      app/Models/AdminAccessModel.php
  58. 41 0
      app/Models/AdminMenusModel.php
  59. 38 0
      app/Models/AdminRoleModel.php
  60. 46 0
      app/Models/AdminUserModel.php
  61. 43 0
      app/Models/BaseAreaModel.php
  62. 32 0
      app/Models/BaseAttachmentModel.php
  63. 40 0
      app/Models/BaseDictionaryModel.php
  64. 41 0
      app/Models/BaseModel.php
  65. 22 0
      app/Models/ClassModel.php
  66. 44 0
      app/Models/FavoriteModel.php
  67. 49 0
      app/Models/MessagesFollowerModel.php
  68. 56 0
      app/Models/MessagesInfoModel.php
  69. 45 0
      app/Models/MessagesTagModel.php
  70. 42 0
      app/Models/MessagesTagRelationModel.php
  71. 52 0
      app/Models/PaymentInfoModel.php
  72. 50 0
      app/Models/UserInfoModel.php
  73. 41 0
      app/Models/WechatAppModel.php
  74. 28 0
      app/Providers/AppServiceProvider.php
  75. 31 0
      app/Providers/AuthServiceProvider.php
  76. 21 0
      app/Providers/BroadcastServiceProvider.php
  77. 32 0
      app/Providers/EventServiceProvider.php
  78. 82 0
      app/Providers/RouteServiceProvider.php
  79. 14 0
      app/Repositories/Base/Criteria.php
  80. 45 0
      app/Repositories/Base/Criteria/MultiWhere.php
  81. 52 0
      app/Repositories/Base/Criteria/OrderBy.php
  82. 21 0
      app/Repositories/Base/DictionaryRepository.php
  83. 358 0
      app/Repositories/Base/Repository.php
  84. 41 0
      app/Repositories/Contracts/CriteriaInterface.php
  85. 78 0
      app/Repositories/Contracts/RepositoryInterface.php
  86. 49 0
      app/Repositories/Messages/Criteria/MultiWhere.php
  87. 43 0
      app/Repositories/Messages/Criteria/TagWhere.php
  88. 21 0
      app/Repositories/Messages/InfoRepository.php
  89. 21 0
      app/Repositories/Messages/TagRepository.php
  90. 48 0
      app/Repositories/Payment/Criteria/MultiWhere.php
  91. 21 0
      app/Repositories/Payment/InfoRepository.php
  92. 48 0
      app/Repositories/User/Criteria/MultiWhere.php
  93. 21 0
      app/Repositories/User/InfoRepository.php
  94. 21 0
      app/Repositories/Wechat/AppRepository.php
  95. 45 0
      app/Repositories/Wechat/Criteria/MultiWhere.php
  96. 128 0
      app/Services/Admin/Acl.php
  97. 288 0
      app/Services/Admin/AdminUser.php
  98. 150 0
      app/Services/Admin/Menus.php
  99. 181 0
      app/Services/Admin/Role.php
  100. 58 0
      app/Services/Base/AbstractService.php

+ 34 - 0
.env.example

xqd
@@ -0,0 +1,34 @@
+APP_ENV=local
+APP_KEY=
+APP_DEBUG=true
+APP_LOG_LEVEL=debug
+APP_URL=http://localhost
+APP_ID=
+APP_SECRET=
+
+DB_CONNECTION=mysql
+DB_HOST=127.0.0.1
+DB_PORT=3306
+DB_DATABASE=homestead
+DB_USERNAME=homestead
+DB_PASSWORD=secret
+
+BROADCAST_DRIVER=log
+CACHE_DRIVER=file
+SESSION_DRIVER=file
+QUEUE_DRIVER=sync
+
+REDIS_HOST=127.0.0.1
+REDIS_PASSWORD=null
+REDIS_PORT=6379
+
+MAIL_DRIVER=smtp
+MAIL_HOST=smtp.mailtrap.io
+MAIL_PORT=2525
+MAIL_USERNAME=null
+MAIL_PASSWORD=null
+MAIL_ENCRYPTION=null
+
+PUSHER_APP_ID=
+PUSHER_APP_KEY=
+PUSHER_APP_SECRET=

+ 3 - 0
.gitattributes

xqd
@@ -0,0 +1,3 @@
+* text=auto
+*.css linguist-vendored
+*.scss linguist-vendored

+ 14 - 0
.gitignore

xqd
@@ -0,0 +1,14 @@
+/node_modules
+/public/storage
+/public/hot
+/storage/*.key
+/vendor
+/.idea
+Homestead.json
+Homestead.yaml
+.env
+.phpstorm.meta.php
+_ide_helper*
+*.lock
+/storage/logs
+/public/upload

+ 7 - 0
apidoc.json

xqd
@@ -0,0 +1,7 @@
+{
+  "name": "小程序",
+  "version": "0.1.0",
+  "description": "小程序接口",
+  "title": "XCX",
+  "url" : "https://t13.9026.com"
+}

+ 40 - 0
app/Console/Kernel.php

xqd
@@ -0,0 +1,40 @@
+<?php
+
+namespace App\Console;
+
+use Illuminate\Console\Scheduling\Schedule;
+use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
+
+class Kernel extends ConsoleKernel
+{
+    /**
+     * The Artisan commands provided by your application.
+     *
+     * @var array
+     */
+    protected $commands = [
+        //
+    ];
+
+    /**
+     * Define the application's command schedule.
+     *
+     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
+     * @return void
+     */
+    protected function schedule(Schedule $schedule)
+    {
+        // $schedule->command('inspire')
+        //          ->hourly();
+    }
+
+    /**
+     * Register the Closure based commands for the application.
+     *
+     * @return void
+     */
+    protected function commands()
+    {
+        require base_path('routes/console.php');
+    }
+}

+ 65 - 0
app/Exceptions/Handler.php

xqd
@@ -0,0 +1,65 @@
+<?php
+
+namespace App\Exceptions;
+
+use Exception;
+use Illuminate\Auth\AuthenticationException;
+use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
+
+class Handler extends ExceptionHandler
+{
+    /**
+     * A list of the exception types that should not be reported.
+     *
+     * @var array
+     */
+    protected $dontReport = [
+        \Illuminate\Auth\AuthenticationException::class,
+        \Illuminate\Auth\Access\AuthorizationException::class,
+        \Symfony\Component\HttpKernel\Exception\HttpException::class,
+        \Illuminate\Database\Eloquent\ModelNotFoundException::class,
+        \Illuminate\Session\TokenMismatchException::class,
+        \Illuminate\Validation\ValidationException::class,
+    ];
+
+    /**
+     * Report or log an exception.
+     *
+     * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
+     *
+     * @param  \Exception  $exception
+     * @return void
+     */
+    public function report(Exception $exception)
+    {
+        parent::report($exception);
+    }
+
+    /**
+     * Render an exception into an HTTP response.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @param  \Exception  $exception
+     * @return \Illuminate\Http\Response
+     */
+    public function render($request, Exception $exception)
+    {
+        return parent::render($request, $exception);
+    }
+
+    /**
+     * Convert an authentication exception into an unauthenticated response.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @param  \Illuminate\Auth\AuthenticationException  $exception
+     * @return \Illuminate\Http\Response
+     */
+    protected function unauthenticated($request, AuthenticationException $exception)
+    {
+        if ($request->expectsJson()) {
+            return response()->json(['error' => 'Unauthenticated.'], 401);
+        }
+
+        return redirect()->guest(route('login'));
+    }
+}

+ 126 - 0
app/Helper/AttachmentHelper.php

xqd
@@ -0,0 +1,126 @@
+<?php
+namespace App\Helper;
+
+use Illuminate\Http\Request;
+use Illuminate\Http\UploadedFile;
+use Symfony\Component\HttpFoundation\File\Exception\FileException;
+use App\Services\Base\ErrorCode;
+use App\Models\BaseAttachmentModel;
+
+trait AttachmentHelper
+{
+    /**
+     * 上传附件
+     *
+     * @param Request $request  laravel's http request
+     * @param string|array $key 文件key
+     * @param string $tag       文件tag
+     * @param int $size         文件size限制,默认2M
+     * @param array $mimeType   文件mime类型限制,默认不限
+     * @return array|string|int 返回:md5字串|ErrorCode或[md5字串|ErrorCode]
+     */
+    public function uploadAttachment(Request $request, $key, $tag = 'files', $size = 10 * 1024 * 1024, array $mimeType = []) {
+        if ($request->hasFile($key)) {
+            $rel_path = '/upload/' . $tag . '/' . date('Ymd');
+            $path = public_path() . $rel_path;
+            if (!file_exists($path)) {
+                if (!@mkdir($path, 0755, true)) {
+                    return ErrorCode::ATTACHMENT_MKDIR_FAILED;
+                }
+            }
+
+            $files = $request->file($key);
+            if ($files === null) {
+                return ErrorCode::ATTACHMENT_UPLOAD_INVALID;
+            }
+            if ($files instanceof UploadedFile) {
+                $files = [$files];
+            }
+
+            $result = [];
+            foreach ($files as $idx => $file) {
+                if (!$file->isValid()) {
+                    $result[$idx] = ErrorCode::ATTACHMENT_UPLOAD_INVALID;
+                    continue;
+                }
+
+                $fileSize = $file->getSize();
+                if ($fileSize > $size) {
+                    $result[$idx] = ErrorCode::ATTACHMENT_SIZE_EXCEEDED;
+                    continue;
+                }
+
+                $fileMimeType = $file->getMimeType();
+                \Log::info("fileMimeType:".$fileMimeType);
+                if (!empty($mimeType) && !in_array($fileMimeType, $mimeType)) {
+                    $result[$idx] = ErrorCode::ATTACHMENT_MIME_NOT_ALLOWED;
+                    continue;
+                }
+
+                $clientName = $file->getClientOriginalName();
+                $md5 = md5($clientName . time());
+                $md5_filename = $md5 . '.' . $file->getClientOriginalExtension();
+
+                try {
+                    $file->move($path, $md5_filename);
+
+                    $real_path = $path . '/' . $md5_filename;
+                    $url_path = $rel_path . '/' . $md5_filename;
+
+                    $attachment = new BaseAttachmentModel();
+                    $attachment->name = $clientName;
+                    $attachment->md5 = $md5;
+                    $attachment->path = $real_path;
+                    $attachment->url = $url_path;
+                    $attachment->size = $fileSize;
+                    $attachment->file_type = $fileMimeType;
+                    if ($attachment->save()) {
+                        //$result[$idx]['real'] = env('APP_URL').'/'.$real_path;
+                        $result[$idx] = env('APP_URL').'/'.$real_path;
+                        //$result[$idx] = $md5;
+                    } else {
+                        @unlink($real_path);
+                        $result[$idx] = ErrorCode::ATTACHMENT_SAVE_FAILED;
+                    }
+                } catch (FileException $e) {
+                    $result[$idx] = ErrorCode::ATTACHMENT_MOVE_FAILED;
+                }
+            }
+            if (count($result) == 1) {
+                return array_shift($result);
+            }
+            return $result;
+        } else {
+            return ErrorCode::ATTACHMENT_UPLOAD_INVALID;
+        }
+
+    }
+
+    /**
+     * 删除附件
+     *
+     * @param $md5 string 删除文件的md5码
+     * @return int 错误码or 0(成功)
+     */
+    public function deleteAttachment($md5) {
+        $attachment = Attachment::where(['md5' => $md5])->first();
+        if (!$attachment) {
+            return ErrorCode::ATTACHMENT_NOT_EXIST;
+        }
+        if (file_exists($attachment->path)) {
+            if (@unlink($attachment->path)) {
+                if ($attachment->delete()) {
+                    return 0;
+                } else {
+                    return ErrorCode::ATTACHMENT_RECORD_DELETE_FAILED;
+                }
+            } else {
+                return ErrorCode::ATTACHMENT_DELETE_FAILED;
+            }
+        } else {
+            return ErrorCode::ATTACHMENT_NOT_EXIST;
+        }
+
+    }
+
+}

+ 71 - 0
app/Helper/LogHelper.php

xqd
@@ -0,0 +1,71 @@
+<?php
+namespace App\Http\HelperTraits;
+
+use App\Models\AccountLog;
+
+trait LogHelper
+{
+    /**
+     * account log记录
+     * @param $data
+     * @return AccountLog
+     * @throws \Exception
+     */
+//    public function writeAccountLog($data) {
+//        if (!isset($data['obj_type']) || empty($data['obj_type'])) {
+//            throw new \Exception('obj_type must be supplied and cannot be empty');
+//        }
+//        if (!isset($data['obj_id']) || empty($data['obj_id'])) {
+//            throw new \Exception('obj_id must be supplied and cannot be empty');
+//        }
+//        if (!isset($data['direction'])) {
+//            $data['direction'] = 1;
+//        }
+//        if ($data['direction'] != 1 && $data['direction'] != 2) {
+//            throw new \Exception('direction must be 1 or 2');
+//        }
+//        if (isset($data['vm_type']) && !array_key_exists($data['vm_type'], AccountLog::getAllType())) {
+//            throw new \Exception('vm_type invalid');
+//        }
+//        if (isset($data['channel']) && !array_key_exists($data['channel'], AccountLog::getAllChannels())) {
+//            throw new \Exception('channel invalid');
+//        }
+//        if (isset($data['op']) && !array_key_exists($data['op'], AccountLog::getAllop())) {
+//            throw new \Exception('op invalid');
+//        }
+//
+//        return AccountLog::create($data);
+//    }
+//
+//    public function logAccount($objType, $objId, $objName, $op, $vmType, $amount, $direction, $balance, $channel, $note = null) {
+//        return $this->writeAccountLog([
+//            'obj_type'      => $objType,
+//            'obj_id'        => $objId,
+//            'obj_name'      => $objName,
+//            'vm_type'       => $vmType,
+//            'amount'        => $amount,
+//            'balance'       => $balance,
+//            'direction'     => $direction,
+//            'op'            => $op,
+//            'channel'       => $channel,
+//            'note'          => $note,
+//        ]);
+//    }
+
+    private function logAccount($fromType, $fromId, $fromName, $fromAmount,  $op, $toType, $toId, $toName, $toAmount) {
+        return AccountLog::create([
+            'from_type'     => $fromType,
+            'from_id'       => $fromId,
+            'from_name'     => $fromName,
+            'from_amount'   => $fromAmount,
+            'op'            => $op,
+            'to_type'       => $toType,
+            'to_id'         => $toId,
+            'to_name'       => $toName,
+            'to_amount'     => $toAmount,
+        ]);
+    }
+
+
+
+}

+ 44 - 0
app/Helper/SmsHelper.php

xqd
@@ -0,0 +1,44 @@
+<?php
+namespace App\Helper;
+
+use GuzzleHttp\Client as GuzzleHttpClient;
+use GuzzleHttp\Exception\RequestException;
+
+trait SmsHelper
+{
+    public function sendSms($msg, $mobile) {
+        $url = "http://api.106txt.com/smsGBK.aspx?";
+        $account = "swufecredit2017";
+        $password = "mask751002";
+        $password = strtoupper(md5($password));
+        $gwid = 53;
+        $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;
+            }
+        } catch (RequestException $re) {
+            \Log::info("发送短信错误:".$re->getMessage());
+            return false;
+        }
+        return false;
+    }
+
+}

+ 33 - 0
app/Helper/constants.inc.php

xqd
@@ -0,0 +1,33 @@
+<?php
+/**
+ *  全局的常量配置
+ */
+
+// ===================== 返回状态 ================== //
+define("SUCESS_CODE", 200);
+define("FAILURE_CODE", 400);
+define("SERVER_ERROR",500);
+define("NO_PERMISSION",401);
+define("APP_PATH", str_replace('\\', '/', substr(__DIR__, 0, -6)));
+define("SYSTEM_TIME", time());
+defined("PAGE_NUMS") || define("PAGE_NUMS", 10);
+define("PAGE_MAX_NUMS", 50);
+
+//网站登录SESSION
+define("LOGIN_OPENID_SESSION_KEY", 'LOGIN_OPENID_SESSION_KEY');
+define("AUTH_BACK_REDIRECT", 'AUTH_BACK_REDIRECT');
+
+//网站管理角色
+define("WEB_ADMIN_ROLE", 'ROLE_WEB_ADMIN');
+
+defined("LOGIN_MARK_SESSION_KEY") || define("LOGIN_MARK_SESSION_KEY", 'tewelwekrkjk34293423k4jnn');
+defined("USER_ROOT_ID") || define("USER_ROOT_ID", '0');
+defined("USER_ROOT_EMAIL") || define("USER_ROOT_EMAIL", 'root');
+
+/*
+ * 当前现有系统
+ */
+
+
+
+

+ 736 - 0
app/Helper/functions.inc.php

xqd
@@ -0,0 +1,736 @@
+<?php
+
+/**
+ * 二维数组去重
+ * @return array
+ */
+if (! function_exists('array_unique_two_dimensional')) {
+    function array_unique_multidimensional(array $input)
+    {
+        $unique = [];
+        foreach ($input as $item) {
+            if (! is_array($item)) {
+                return $input;
+            }
+
+            $str = implode(',', $item); //利用implode,将二维数组中的下层数组变成字符串
+            $strArr[] = $str;
+
+            $unique = array_unique($strArr); //去掉重复的字符串,也就是生成一个干净的一维数组
+        }
+
+        $output = [];
+        foreach ($unique as $item) {
+            $output[] = explode(',', $item);
+        }
+
+        return $output;
+    }
+}
+if( ! function_exists('cdn_asset'))
+{
+    function cdn_asset($path)
+    {
+        return env('CDN_URL', '') . $path;
+    }
+}
+
+
+if( ! function_exists('array_to_sort')) {
+    /**
+     * 对二维数组排序
+     * @param string $arr old数组
+     * @param string $keys 要排序的键
+     * @param string $type 排序类型[asc,desc]
+     * @param string $reset 重新排列数组key
+     * @return string 返回排序之后的数组
+     */
+    function array_to_sort($arr, $keys, $type = 'asc', $reset = false)
+    {
+        $keysvalue = $new_array = array();
+        foreach ($arr as $k => $v) {
+            $keysvalue[$k] = $v[$keys];
+        }
+        if ($type == 'asc') {
+            asort($keysvalue);
+        } else {
+            arsort($keysvalue);
+        }
+        reset($keysvalue);
+        foreach ($keysvalue as $k => $v) {
+            if ($reset) {
+                $new_array[] = $arr[$k];
+            } else {
+                $new_array[$k] = $arr[$k];
+            }
+        }
+        return $new_array;
+    }
+}
+
+
+/**
+ * 写作的时间人性化
+ *
+ * @param int $time 写作的时间
+ * @return string
+ */
+if( ! function_exists('showWriteTime'))
+{
+    function showWriteTime($time)
+    {
+        $interval = time() - $time;
+        $format = array(
+            '31536000'  => '年',
+            '2592000'   => '个月',
+            '604800'    => '星期',
+            '86400'     => '天',
+            '3600'      => '小时',
+            '60'        => '分钟',
+            '1'         => '秒'
+        );
+        foreach($format as $key => $value)
+        {
+            $match = floor($interval / (int) $key );
+            if(0 != $match)
+            {
+                return $match . $value . '前';
+            }
+        }
+        return date('Y-m-d', $time);
+    }
+}
+if( ! function_exists('pairList'))
+{
+    function pairList($list, $keyField, $valueField)
+    {
+        $pairList = array();
+        foreach ($list as $one) {
+            $pairList[$one[$keyField]] = $one[$valueField];
+        }
+        return $pairList;
+    }
+}
+
+
+/**
+ * 重新组装url ,如果没有host回自动添加当前host
+ * @param string $url
+ * @param array $query  key=>val
+ * @return string
+ */
+function U ($url, $query = [])
+{
+    $url = ltrim($url, '/');
+    $urlInfo = parse_url($url);
+    $aQuery = [];
+
+    if (isset($urlInfo['query']) && $urlInfo['query'] !== '') {
+        parse_str($urlInfo['query'],$aQuery);
+    }
+    $queryString = http_build_query(array_merge($aQuery, $query));
+    if(isset($urlInfo['host'])) {
+        $url = $urlInfo['scheme'] . '://' . $urlInfo['host'].'/admin/';
+    }else{
+        $url = request()->root() . '/admin/';
+    }
+    $url .= isset($urlInfo['path']) ? $urlInfo['path'] : '';
+    $url .= $queryString === '' ? '' : ('?'.$queryString);
+    return $url;
+}
+/**
+ * 验证角色菜单权限
+ *
+ * @param string $route 路由
+ * @param string $params 附带参数
+ * @return bool
+ */
+
+if( ! function_exists('role'))
+{
+    function role($route, $params = [])
+    {
+        $user = \Auth::guard('admin')->user();
+        $role = session()->get(LOGIN_MARK_SESSION_KEY);
+        if($user['is_root']) {
+            return true;
+        }
+        $route = trim($route);
+        $roles = $role['role'];
+        if(isset($roles[$route])){
+            return true;
+        }else{
+            return false;
+        }
+    }
+}
+if( ! function_exists('dict'))
+{
+    function dict()
+    {
+        return new App\Services\Base\Dictionary;
+    }
+}
+
+
+/**
+ * 隐藏部分手机号码
+ * @param $mobile
+ * @param $hide_length
+ * @return string
+ */
+if( ! function_exists('hidePartMobile'))
+{
+    function hidePartMobile($mobile, $hide_length = 5){
+        $hide_length = intval($hide_length);
+        $hide = '';
+        for($i = 0; $i < $hide_length; $i++){
+            $hide .= '*';
+        }
+        $pattern = "/(1\d{1,2})([0-9]{". $hide_length .",". $hide_length ."})(\d+)/";
+        $replacement = "\$1{$hide}\$3";
+        return preg_replace($pattern, $replacement, $mobile);
+    }
+}
+
+/**
+ * Function echo_log
+ * 输出调试日志
+ * @param $content 输出内容
+ */
+if( ! function_exists('echoLog'))
+{
+    function echoLog($content, $filename = '')
+    {
+        if(is_object($content) || is_array($content)) {
+            $content = var_export($content, true);
+        }
+        $log_path = storage_path() . DIRECTORY_SEPARATOR . "debug_log" . DIRECTORY_SEPARATOR;
+
+        if($filename){
+            $file_path = $log_path . $filename;
+        }else{
+            $file_path = $log_path . "debug_log_" . date("Ymd") . ".txt";
+        }
+
+        if(!file_exists($log_path)){
+            mkdir($log_path,0777);
+        }
+
+        $fp = fopen($file_path, "a");
+        flock($fp, LOCK_EX) ;
+        fwrite($fp,"执行日期:".date("Y-m-d H:i:s",time())."\n".$content."\n\n");
+        flock($fp, LOCK_UN);
+        fclose($fp);
+    }
+}
+if( ! function_exists('curlAjax'))
+{
+    function curlAjax($url) {
+        $cookieStr = '';
+        if($_COOKIE) {
+            foreach ($_COOKIE as $key=>$val) {
+                $cookieStr .= $key . '=' . $val . ';';
+            }
+            $cookieStr = substr($cookieStr, 0,-1);
+        }
+        $headers = array(
+            'Content-Type' => 'text/json;charset=utf-8', // 设置为Ajax方式
+            'X-Requested-With' => 'XMLHttpRequest', // 设置为Ajax方式
+            'User-Agent' => 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36', // 设置为Ajax方式
+            'Referer' => 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'],
+            'Cookie' => $cookieStr
+        );
+        $headerArr = array();
+        foreach( $headers as $n => $v ) {
+            $headerArr[] = $n .':' . $v;
+        }
+        $ch = curl_init($url);
+        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArr);
+        curl_setopt($ch, CURLOPT_HEADER, 0);
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+        $return = curl_exec($ch);
+        curl_close ( $ch );
+        return $return;
+    }
+}
+
+if( ! function_exists('img'))
+{
+    function img($system, $system_primary = NULL, $system_key = NULL, $first = false, $pagesize = PAGE_MAX_NUMS)
+    {
+        $paramArgs = func_get_args();
+        $key = "system_img" . md5(serialize($paramArgs));
+        if(!Cache::has($key) ||  request('no_cache') === 'true') {
+            $data =  \App\Services\Base\Images::getSrc($system, $system_primary, $system_key, $first, $pagesize);
+            \Cache::forever($key,$data);
+        }
+        $data = \Cache::get($key);
+        return $data;
+    }
+}
+
+/**
+ * 字符截取 支持UTF8/GBK
+ * @param $string
+ * @param $length
+ * @param $dot
+ */
+if( ! function_exists('str_cut'))
+{
+    function str_cut($string, $length, $dot = '...') {
+        $strlen = strlen($string);
+        if($strlen <= $length) return $string;
+        $string = str_replace(array(' ','&nbsp;', '&amp;', '&quot;', '&#039;', '&ldquo;', '&rdquo;', '&mdash;', '&lt;', '&gt;', '&middot;', '&hellip;'), array('∵',' ', '&', '"', "'", '“', '”', '—', '<', '>', '·', '…'), $string);
+        $strcut = '';
+        if(strtolower('utf-8') == 'utf-8') {
+            $length = intval($length-strlen($dot)-$length/3);
+            $n = $tn = $noc = 0;
+            while($n < strlen($string)) {
+                $t = ord($string[$n]);
+                if($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) {
+                    $tn = 1; $n++; $noc++;
+                } elseif(194 <= $t && $t <= 223) {
+                    $tn = 2; $n += 2; $noc += 2;
+                } elseif(224 <= $t && $t <= 239) {
+                    $tn = 3; $n += 3; $noc += 2;
+                } elseif(240 <= $t && $t <= 247) {
+                    $tn = 4; $n += 4; $noc += 2;
+                } elseif(248 <= $t && $t <= 251) {
+                    $tn = 5; $n += 5; $noc += 2;
+                } elseif($t == 252 || $t == 253) {
+                    $tn = 6; $n += 6; $noc += 2;
+                } else {
+                    $n++;
+                }
+                if($noc >= $length) {
+                    break;
+                }
+            }
+            if($noc > $length) {
+                $n -= $tn;
+            }
+            $strcut = substr($string, 0, $n);
+            $strcut = str_replace(array('∵', '&', '"', "'", '“', '”', '—', '<', '>', '·', '…'), array(' ', '&amp;', '&quot;', '&#039;', '&ldquo;', '&rdquo;', '&mdash;', '&lt;', '&gt;', '&middot;', '&hellip;'), $strcut);
+        } else {
+            $dotlen = strlen($dot);
+            $maxi = $length - $dotlen - 1;
+            $current_str = '';
+            $search_arr = array('&',' ', '"', "'", '“', '”', '—', '<', '>', '·', '…','∵');
+            $replace_arr = array('&amp;','&nbsp;', '&quot;', '&#039;', '&ldquo;', '&rdquo;', '&mdash;', '&lt;', '&gt;', '&middot;', '&hellip;',' ');
+            $search_flip = array_flip($search_arr);
+            for ($i = 0; $i < $maxi; $i++) {
+                $current_str = ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i];
+                if (in_array($current_str, $search_arr)) {
+                    $key = $search_flip[$current_str];
+                    $current_str = str_replace($search_arr[$key], $replace_arr[$key], $current_str);
+                }
+                $strcut .= $current_str;
+            }
+        }
+        return $strcut.$dot;
+    }
+}
+
+/**
+ * 取得文件扩展
+ *
+ * @param $filename 文件名
+ * @return 扩展名
+ */
+if( ! function_exists('fileExt'))
+{
+    function fileExt($filename)
+    {
+        return strtolower(trim(substr(strrchr($filename, '.'), 1, 10)));
+    }
+}
+
+/**
+ * 过滤参数
+ *
+ * @param $param    参数数组
+ * @param $allowKey 被允许的KEY集合数组
+ * @return 扩展名
+ */
+if( ! function_exists('filterParam'))
+{
+    function filterParam(array $param, array $allowKey)
+    {
+        $data = array();
+        foreach ($param AS $key => $val) {
+            if(in_array($key, $allowKey)) $data[$key] = $val;
+        }
+        return $data;
+    }
+}
+if(!function_exists('list_to_tree')) {
+    function list_to_tree($list, $pk='id',$pid = 'pid',$child = '_child',$root=0)
+    {
+        // 创建Tree
+        $tree = array();
+        if(is_array($list)) {
+            // 创建基于主键的数组引用
+            $refer = array();
+            foreach ($list as $key => $data) {
+                $refer[$data[$pk]] =& $list[$key];
+            }
+            foreach ($list as $key => $data) {
+                // 判断是否存在parent
+                $parentId = $data[$pid];
+                if ($root == $parentId) {
+                    $tree[] =& $list[$key];
+                }else{
+                    if (isset($refer[$parentId])) {
+                        $parent =& $refer[$parentId];
+                        $parent[$child][] =& $list[$key];
+                    }
+                }
+            }
+        }
+        return $tree;
+    }
+}
+
+
+/**
+ * 判断远程文件是否存在
+ * @param unknown $url
+ * @return boolean
+ */
+function check_remote_file_exists($url)
+{
+    $curl = curl_init($url);
+    curl_setopt($curl, CURLOPT_NOBODY, true);
+    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET');
+    $result = curl_exec($curl);
+    $found = false;
+    if ($result !== false)
+    {
+        $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
+        if ($statusCode == 200)
+        {
+            $found = true;
+        }
+    }
+    curl_close($curl);
+    return $found;
+}
+
+if( ! function_exists('getCacheKey')) {
+    /**
+     * 更具参数获取一个唯一的缓存KEY
+     * @param string $name 名称
+     * @param obj|array|string $data 参数
+     */
+    function getCacheKey($name,$data) {
+        return $name . md5(serialize($data));
+
+    }
+}
+
+function isMobile()
+{
+    // 如果有HTTP_X_WAP_PROFILE则一定是移动设备
+    if (isset ($_SERVER['HTTP_X_WAP_PROFILE']))
+    {
+        return true;
+    }
+    // 如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息
+    if (isset ($_SERVER['HTTP_VIA']))
+    {
+        // 找不到为false,否则为true
+        return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false;
+    }
+    // 脑残法,判断手机发送的客户端标志,兼容性有待提高
+    if (isset ($_SERVER['HTTP_USER_AGENT']))
+    {
+        $clientkeywords = array ('nokia',
+            'sony',
+            'ericsson',
+            'mot',
+            'samsung',
+            'htc',
+            'sgh',
+            'lg',
+            'sharp',
+            'sie-',
+            'philips',
+            'panasonic',
+            'alcatel',
+            'lenovo',
+            'iphone',
+            'ipod',
+            'blackberry',
+            'meizu',
+            'android',
+            'netfront',
+            'symbian',
+            'ucweb',
+            'windowsce',
+            'palm',
+            'operamini',
+            'operamobi',
+            'openwave',
+            'nexusone',
+            'cldc',
+            'midp',
+            'wap',
+            'mobile'
+        );
+        // 从HTTP_USER_AGENT中查找手机浏览器的关键字
+        if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT'])))
+        {
+            return true;
+        }
+    }
+    // 协议法,因为有可能不准确,放到最后判断
+    if (isset ($_SERVER['HTTP_ACCEPT']))
+    {
+        // 如果只支持wml并且不支持html那一定是移动设备
+        // 如果支持wml和html但是wml在html之前则是移动设备
+        if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html'))))
+        {
+            return true;
+        }
+    }
+    return false;
+}
+
+
+/**
+ * post 提交
+ * @param strint $url
+ * @param array $post_data
+ * @return mixed
+ */
+function formPost($url, $post_data=array(), $timeout=60, $userpwd = null)
+{
+    $ch = curl_init();
+    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+    curl_setopt($ch, CURLOPT_POST, 1);
+    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+    curl_setopt($ch, CURLOPT_HEADER, 0);
+    curl_setopt($ch, CURLOPT_URL, $url);
+    curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); // 设置超时限制防止死循环
+    curl_setopt($ch, CURLOPT_POST, 1);
+    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
+    // 		curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
+    if ($userpwd) {
+        curl_setopt($ch, CURLOPT_HTTPAUTH , CURLAUTH_BASIC);
+        curl_setopt($ch, CURLOPT_USERPWD  , $userpwd);
+    }
+    $result = curl_exec($ch);
+    if (curl_errno($ch)) {
+        // echo curl_error($ch);exit;
+    }
+    curl_close($ch); // 关键CURL会话
+    //	CBase::write_log('formPost' . date("Ymd") . ".log", $result);
+    return $result;
+}
+
+
+
+/**
+ *
+ * @param string $textareaid      编辑器ID
+ * @param unknown $getParam       上传参数
+ * @param unknown $options        编辑器自带参数,直接以php数组的形式传入即可,但不支持对象类型(eg.Function)
+ * @return string
+ */
+function editor() {
+
+    $editer = <<<HTML
+    <!-- 配置文件 -->
+    <script type="text/javascript" src="/base/neditor-1.5.3/neditor.config.js"></script>
+    <!-- 编辑器源码文件 -->
+    <script type="text/javascript" src="/base/neditor-1.5.3/neditor.all.js"></script>
+    <!-- 实例化编辑器 -->
+    <script type="text/javascript">
+        var ue = UE.getEditor('container',{
+             toolbars: [
+          ["fullscreen","source","autotypeset","bold", "italic","underline","forecolor", "paragraph","fontfamily","fontsize","indent","justifyleft", "justifycenter","justifyright","justifyjustify","link","unlink","insertimage","insertcode"
+          ]],
+           autoHeightEnabled: true,
+           autoFloatEnabled: true,
+           initialFrameHeight:320
+        });
+   
+        ue.ready(function(){
+        ue.execCommand('serverparam', '_token', '{{ csrf_token() }}');
+    })
+    </script>
+HTML;
+
+    return $editer;
+}
+
+
+if( ! function_exists('widget'))
+{
+    function widget($widgetName)
+    {
+        $widgetNameEx = explode('.', $widgetName);
+        if( ! isset($widgetNameEx[1])) return false;
+        $widgetClass = 'App\\Widget\\'.$widgetNameEx[0].'\\'.$widgetNameEx[1];
+        if(app()->bound($widgetName)) return app()->make($widgetName);
+        app()->singleton($widgetName, function() use ($widgetClass)
+        {
+            return new $widgetClass();
+        });
+        return app()->make($widgetName);
+    }
+}
+
+
+//
+//if( ! function_exists('sendSms')) {
+//    // return string 'success' 为成功
+//    function sendSms($msg, $mobile){
+//        $post_data = array();
+//        $post_data['un'] ="N9304000";
+//        $post_data['pw'] = "Mask751002@";
+//        $post_data['msg']="【小洲蔬菜】$msg";
+//        $post_data['phone'] =$mobile;
+//        $post_data['rd']=1;
+//
+//        $post_data['needstatus']='true';
+//        $url='https://sms.253.com/msg/send';
+//        $data=http_build_query($post_data);
+//
+//        if(function_exists('curl_init')){
+//            $curl = curl_init();
+//            curl_setopt($curl, CURLOPT_URL, $url);
+//
+//            if (!empty($data)){
+//                curl_setopt($curl, CURLOPT_POST, 1);
+//                curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
+//            }
+//            curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
+//            $output = curl_exec($curl);
+//            curl_close($curl);
+//            $result=preg_split("/[,\r\n]/",$output);
+//            if($result[1]==0){
+//                $res = "success";
+//            }else{
+//                $res = "curl error:".$result[1];
+//            }
+//        }elseif(function_exists('file_get_contents')){
+//            $output=file_get_contents($url.$data);
+//            $result=preg_split("/[,\r\n]/",$output);
+//            if($result[1]==0){
+//                $res = "success";
+//            }else{
+//                $res = "error:".$result[1];
+//            }
+//        }else{
+//            $res="error";
+//        }
+//        return $res;
+//    }
+//}
+//
+//if( ! function_exists('sendMultiSms')) {
+//    //  群发短信 $mobiles电话号码之间用英文逗号分割
+//    // return string 'success' 为成功
+//    function sendMultiSms($msg, $mobiles){
+//        $post_data = array();
+//        $post_data['un'] ="M3512322";
+//        $post_data['pw'] = "N8ecbXn0A7dc18";
+//        $post_data['msg']="【小洲蔬菜】$msg 回复TD退订";
+//        $post_data['phone'] =$mobiles;
+//        $post_data['rd']=1;
+//
+//        $post_data['needstatus']='true';
+//        $url='https://sms.253.com/msg/send';
+//        $data=http_build_query($post_data);
+//
+//        if(function_exists('curl_init')){
+//            $curl = curl_init();
+//            curl_setopt($curl, CURLOPT_URL, $url);
+//
+//            if (!empty($data)){
+//                curl_setopt($curl, CURLOPT_POST, 1);
+//                curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
+//            }
+//            curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
+//            $output = curl_exec($curl);
+//            curl_close($curl);
+//            $result=preg_split("/[,\r\n]/",$output);
+//            if($result[1]==0){
+//                $res = "success";
+//            }else{
+//                $res = "curl error:".$result[1];
+//            }
+//        }elseif(function_exists('file_get_contents')){
+//            $output=file_get_contents($url.$data);
+//            $result=preg_split("/[,\r\n]/",$output);
+//            if($result[1]==0){
+//                $res = "success";
+//            }else{
+//                $res = "error:".$result[1];
+//            }
+//        }else{
+//            $res="error";
+//        }
+//        return $res;
+//    }
+//}
+//
+//
+//if( ! function_exists('sendCaixin')) {
+//    //return  true or false
+//    function sendCaixin($mobile){
+//
+//        $post_data =$data =$msgdata = array();
+//
+//        $url ="http://www.baidu.com";//回调URL
+//        $key ="6MG5jNK4Q15907";//密码
+////文字body
+//        $data['frame']="1"; //文字标识
+//        $data['part']  ="1";//文字标识
+//        $data['type']="1" ;
+//        $data['content']=base64_encode('亲爱的朋友,“芜湖小洲蔬菜”,芜湖人的掌上菜篮子,已是我每天买菜必备工具。好东西首先想到了您,赶快关注使用吧!');
+//
+////图片body
+//        $msgdata['frame']="1";
+//        $msgdata['part']  ="2";//图片标识
+//        $msgdata['type']="2" ;//图片标识
+//        $msgdata['content']=base64_encode(file_get_contents(public_path('app/wap/images/')."qrcode.jpg"));//图片
+//
+//        $post_data['account'] ="C8636841";//账号
+//        $post_data['ext_id']="72175534217316595927";//自传参数
+//        $post_data['msg']=json_encode(array($data,$msgdata)) ;//json
+//        $post_data['phones']  = $mobile;//手机
+//        $post_data['timestamp'] = time();//时间戳
+//
+//        $post_data['title']= '芜湖小洲蔬菜'; //标题
+//
+//        $sign ='account=' . $post_data['account'].'ext_id=' . $post_data['ext_id'].'msg=' . $post_data['msg'].'phones=' . $post_data['phones'].'timestamp=' . $post_data['timestamp'].'title=' . $post_data['title'].'url=' . $url.'key=' . $key;
+//        $sign=md5($sign); //加密
+//        $post_data['sign']=$sign;
+//        $post_data['url']=$url;
+//
+//        $url='http://caixin.253.com/api/send?';
+//        $data = http_build_query($post_data);
+//
+//        if(function_exists('curl_init')){
+//            $curl = curl_init();
+//            curl_setopt($curl, CURLOPT_URL, $url);
+//
+//            if (!empty($data)){
+//                curl_setopt($curl, CURLOPT_POST, 1);
+//                curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
+//            }
+//            curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
+//            $output = curl_exec($curl);
+//            curl_close($curl);
+//            $res = json_decode($output);
+//            if(is_array($res)&&$res['code']==1){
+//                return true;
+//            }
+//
+//        }
+//        return false;
+//    }
+//}

+ 32 - 0
app/Http/Controllers/Admin/Auth/ForgotPasswordController.php

xqd
@@ -0,0 +1,32 @@
+<?php
+
+namespace App\Http\Controllers\Admin\Auth;
+
+use App\Http\Controllers\Admin\Controller;
+use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
+
+class ForgotPasswordController extends Controller
+{
+    /*
+    |--------------------------------------------------------------------------
+    | Password Reset Controller
+    |--------------------------------------------------------------------------
+    |
+    | This controller is responsible for handling password reset emails and
+    | includes a trait which assists in sending these notifications from
+    | your application to your users. Feel free to explore this trait.
+    |
+    */
+
+    use SendsPasswordResetEmails;
+
+    /**
+     * Create a new controller instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        $this->middleware('guest');
+    }
+}

+ 101 - 0
app/Http/Controllers/Admin/Auth/LoginController.php

xqd
@@ -0,0 +1,101 @@
+<?php
+
+namespace App\Http\Controllers\Admin\Auth;
+
+use App\Services\Admin\AdminUser;
+use App\Http\Controllers\Admin\Controller;
+use Illuminate\Foundation\Auth\AuthenticatesUsers;
+use Validator, Auth;
+
+class LoginController extends Controller
+{
+    /*
+    |--------------------------------------------------------------------------
+    | Login Controller
+    |--------------------------------------------------------------------------
+    |
+    | This controller handles authenticating users for the application and
+    | redirecting them to your home screen. The controller uses a trait
+    | to conveniently provide its functionality to your applications.
+    |
+    */
+
+    use AuthenticatesUsers;
+
+    /**
+     * Where to redirect users after login.
+     *
+     * @var string
+     */
+    protected $redirectTo = '/admin';
+
+    /**
+     * Create a new controller instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        $this->_service = new AdminUser();
+        $this->middleware('guest', ['except' => 'logout']);
+    }
+    /**
+     * 重写登录视图页面
+     * @author 晚黎
+     * @date   2016-09-05T23:06:16+0800
+     * @return [type]                   [description]
+     */
+    public function showLoginForm()
+    {
+        return view('admin.auth.login');
+    }
+    /**
+     * 自定义认证驱动
+     * @author 晚黎
+     * @date   2016-09-05T23:53:07+0800
+     * @return [type]                   [description]
+     */
+    protected function guard()
+    {
+        return auth()->guard('admin');
+    }
+
+    public function username()
+    {
+        return 'name';
+    }
+
+    public function login(\Illuminate\Http\Request $request)
+    {
+
+        $validator = Validator::make($data = $request->all(),
+            [
+                'name' => 'required', 'password' => 'required',
+            ],
+            [
+                'name.required'=>'请输入用户名',
+                'password.required'=>'请输入密码'
+            ]
+        );
+
+        if ($validator->fails()) {
+            $msg = $validator->messages()->first();
+            return $this->showWarning($msg);
+        }
+        $res = $this->_service->login($request->name, $request->password);
+        if($res) {
+            redirect('/admin/login');
+        }else{
+            $msg = $this->_service->getMsg();
+            $this->showWarning($msg);
+        }
+
+        return redirect('/admin');
+    }
+    public function logout()
+    {
+        Auth::guard('admin')->logout();
+        return redirect('/admin/login');
+
+    }
+}

+ 71 - 0
app/Http/Controllers/Admin/Auth/RegisterController.php

xqd
@@ -0,0 +1,71 @@
+<?php
+
+namespace App\Http\Controllers\Admin\Auth;
+
+use App\User;
+use App\Http\Controllers\Admin\Controller;
+use Illuminate\Support\Facades\Validator;
+use Illuminate\Foundation\Auth\RegistersUsers;
+
+class RegisterController extends Controller
+{
+    /*
+    |--------------------------------------------------------------------------
+    | Register Controller
+    |--------------------------------------------------------------------------
+    |
+    | This controller handles the registration of new users as well as their
+    | validation and creation. By default this controller uses a trait to
+    | provide this functionality without requiring any additional code.
+    |
+    */
+
+    use RegistersUsers;
+
+    /**
+     * Where to redirect users after registration.
+     *
+     * @var string
+     */
+    protected $redirectTo = '/home';
+
+    /**
+     * Create a new controller instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        $this->middleware('guest');
+    }
+
+    /**
+     * Get a validator for an incoming registration request.
+     *
+     * @param  array  $data
+     * @return \Illuminate\Contracts\Validation\Validator
+     */
+    protected function validator(array $data)
+    {
+        return Validator::make($data, [
+            'name' => 'required|max:255',
+            'email' => 'required|email|max:255|unique:users',
+            'password' => 'required|min:6|confirmed',
+        ]);
+    }
+
+    /**
+     * Create a new user instance after a valid registration.
+     *
+     * @param  array  $data
+     * @return User
+     */
+    protected function create(array $data)
+    {
+        return User::create([
+            'name' => $data['name'],
+            'email' => $data['email'],
+            'password' => bcrypt($data['password']),
+        ]);
+    }
+}

+ 86 - 0
app/Http/Controllers/Admin/Auth/ResetPasswordController.php

xqd
@@ -0,0 +1,86 @@
+<?php
+
+namespace App\Http\Controllers\Admin\Auth;
+
+use App\Http\Controllers\Admin\Controller;
+use Illuminate\Foundation\Auth\ResetsPasswords;
+use Validator, Auth,Hash;
+
+class ResetPasswordController extends Controller
+{
+    /*
+    |--------------------------------------------------------------------------
+    | Password Reset Controller
+    |--------------------------------------------------------------------------
+    |
+    | This controller is responsible for handling password reset requests
+    | and uses a simple trait to include this behavior. You're free to
+    | explore this trait and override any methods you wish to tweak.
+    |
+    */
+
+    use ResetsPasswords;
+
+    /**
+     * Where to redirect users after resetting their password.
+     *
+     * @var string
+     */
+    protected $redirectTo = '/home';
+
+    /**
+     * Create a new controller instance.
+     *
+     * @return void
+     */
+    public function __construct()
+    {
+        $this->middleware('guest');
+    }
+
+    public function showChangeForm()
+    {
+        return view('admin.auth.change');
+    }
+
+    public function changePassword(\Illuminate\Http\Request $request)
+    {
+
+        $validator = Validator::make($data = $request->all(),
+            [
+                'old_passwprd' => 'required', 'password' => 'required','password_confirmation'=> 'required'
+            ],
+            [
+                'old_passwprd.required'=>'请输入原密码',
+                'password.required'=>'请输入密码',
+                'password_confirmation.required'=>'请输入确认密码',
+            ]
+        );
+        if ($validator->fails()) {
+            $msg = $validator->messages()->first();
+            return $this->showWarning($msg);
+        }
+
+        $user = Auth::guard('admin')->user();
+        $oldpassword = $request->input('old_passwprd');
+        $newpassword = $request->input('password');
+        $password_confirmation= $request->input('password_confirmation');
+
+        if($newpassword!=$password_confirmation){
+            return $this->showWarning("两次密码一直");
+        }
+
+        if(!Hash::check($oldpassword, $user->password)){
+            return $this->showWarning("原密码不正确");
+        }
+
+        $user->password = bcrypt($newpassword);
+        $result = $user->save();
+
+        if($result){
+            return $this->showMessage("修改成功");
+        }else{
+            return $this->showWarning("修改密码失败");
+        }
+    }
+}

+ 69 - 0
app/Http/Controllers/Admin/Base/ActionlogController.php

xqd
@@ -0,0 +1,69 @@
+<?php
+/**
+ * 操作日志
+ *  @author  Mike <m@9026.com>
+ *  @version    1.0
+ *  @date 2015年10月15日
+ *
+ */
+namespace App\Http\Controllers\Admin\Base;
+
+use App\Http\Controllers\Admin\Controller;
+use Request;
+use App\Services\User\Payinfo;
+use App\Utils\AliLog;
+use Carbon\Carbon;
+
+class ActionlogController extends Controller {
+    private $_service;
+    private $_viewdata;
+    private $_aTopic = [ 'action-view-log'=>'访问日志','action-operate-log'=>'操作日志'];
+    /**
+     * 初始化Service
+     */
+    public function __construct()
+    {
+        parent::__construct();
+    
+        if(!$this->_service) $this->_service = new Payinfo();
+        
+        $this->_viewdata = array();
+    }
+    
+    /**
+     * 列表
+     */
+    function index()
+    {
+        $obj = new AliLog();
+        $this->_viewdata['aTopIc'] = $this->_aTopic;
+        $this->_viewdata['topic'] = Request::input('topic','action-view-log');
+        $this->_viewdata['aLine'] = [50=>'50行',100=>'100行',200=>'200行'];
+        $this->_viewdata['line']  = Request::input('line',50);
+        $this->_viewdata['start_time']  = Request::input('start_time',Carbon::yesterday());
+        $this->_viewdata['end_time']  = Request::input('end_time',Carbon::tomorrow());
+        $query = '';
+        $data = $obj->listLogs('admin-operate-log',
+                                strtotime($this->_viewdata['start_time']),
+                                strtotime($this->_viewdata['end_time']), 
+                                $this->_viewdata['topic'],
+                                $query,
+                                $this->_viewdata['line']
+                );
+        $request = Request::all();
+        $search['keyword'] = Request::input('keyword');
+        
+        $orderby = array();
+        if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
+            $orderby[$request['sort_field']] = $request['sort_field_by'];
+        }
+        $this->_viewdata['data'] = $data;
+    
+        return view('admin.base.actionlog.index', $this->_viewdata);
+    }
+    
+    
+    
+    
+    
+}

+ 168 - 0
app/Http/Controllers/Admin/Base/AttachmentController.php

xqd
@@ -0,0 +1,168 @@
+<?php
+
+namespace App\Http\Controllers\Admin\Base;
+
+use App\Http\Controllers\Admin\Controller;
+use App\Services\Base\Attachment;
+use App\Models\BaseAttachmentModel;
+use Request, Response;
+
+class AttachmentController extends Controller
+{
+    private $_serviceAttachment;
+    private $_serviceAttachmentBbs;
+    private $_serviceForumAttachment;
+    private $_serviceForumAttachmentUnused;
+
+    public function __construct()
+    {
+        if( !$this->_serviceAttachment ) $this->_serviceAttachment = new Attachment();
+
+    }
+
+
+    /**
+     * SWFUpload文件上传
+     */
+    public function upload()
+    {
+        $request = Request::all();
+
+        //通过上传控件ID,区分文件上传类型
+        if(isset($request['elementid']) && substr($request['elementid'], 0, 15) == 'upload_template'){
+
+            $this->_uploadTemplate($request);
+
+            //上传到本地
+        }elseif(isset($request['position']) && $request['position'] == 'local'){
+
+            $this->_uploadToServer($request);
+
+            //上传专题文件
+        }elseif(isset($request['position']) && $request['position'] == 'special'){
+
+            $this->_uploadSpecial($request);
+
+            //上传到阿里云
+        } else{
+
+            $this->_uploadToAlioss($request);
+
+        }
+    }
+
+
+    /**
+     * 上传到本地
+     */
+    private function _uploadToServer($request)
+    {
+        $return = $this->_serviceAttachment->localUpload('imgFile', $request);
+        if($return['code']=='200'){
+            echo json_encode(["error"=> 0,"url" => config('app.url').$return['fileurl']]);exit;
+        }else{
+
+            echo json_encode(["error" => 1,"message" =>  $return['message']]);exit;
+        }
+    }
+
+    /**
+     * 上传专题文件
+     */
+    private function _uploadSpecial($request)
+    {
+        $return = $this->_serviceAttachment->specialUpload('Filedata', $request);
+        echo json_encode($return);exit;
+    }
+
+    /**
+     * 上传到阿里云
+     */
+    private function _uploadToAlioss($request)
+    {
+        $return = [];
+        if(isset($request['KindEditor'])){
+            $data = $this->_serviceAttachment->aliUpload($request['field'], $request);
+            if($data['code'] === 200){
+                $return['error'] = 0;
+                $return['url']   = $data['fileurl'];
+            }else{
+                $return['error']    = 1;
+                $return['message']  = $data['message'];
+            }
+        }else{
+            $return = $this->_serviceAttachment->aliUpload('Filedata', $request);
+        }
+        echo json_encode($return);exit;
+    }
+
+    /**
+     * 控件上传
+     */
+    public function webupload()
+    {
+        $request = request()->all();
+        $data = $this->_serviceAttachment->localUpload('file', $request, 'files');
+//        return response()->json(array('data' => $data), 200);
+        echo json_encode($data);exit;
+    }
+
+
+    /**
+     * @api {get} /api/attachment/download/{md5} 下载文件(图片)
+     * @apiDescription 下载文件(图片)(get code)
+     * @apiGroup Attachment
+     * @apiPermission none
+     * @apiVersion 0.1.0
+     * @apiParam {string} md5   图片md5码
+     * @apiSuccessExample {json} Success-Response:
+     *     HTTP/1.1 200 OK
+     *     {
+     *       文件二进制码
+     *     }
+     * @apiErrorExample {json} Error-Response:
+     *     HTTP/1.1 404 Not found
+     */
+    public function download()
+    {
+        $request = Request::all();
+        $attachment = BaseAttachmentModel::where(['md5' => $request['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,
+        ]);
+    }
+
+
+
+
+    private function _createAttachmentRecord($data)
+    {
+        $uid = Request::input('uid');
+        $aid = $this->_serviceForumAttachment->create(['tid' => 0, 'pid' => 0, 'uid' => $uid, 'tableid' => 127]);
+        if($aid){
+            $info = [
+                'aid'           => $aid,
+                'uid'           => $uid,
+                'dateline'      => SYSTEM_TIME,
+                'filename'      => $data['filename'],
+                'filesize'      => $data['filesize'],
+                'attachment'    => $data['attachment'],
+                'isimage'       => (isset($data['width']) && $data['width']) ? 1 : 0,
+                'remote'        => 1,
+                'width'         => isset($data['width']) ? $data['width'] : 0,
+                'thumb'         => 0,
+            ];
+            if(!$this->_serviceForumAttachmentUnused->create($info)){
+                return 0;
+            }
+        }
+        return $aid;
+    }
+
+}

+ 58 - 0
app/Http/Controllers/Admin/Base/ClassController.php

xqd
@@ -0,0 +1,58 @@
+<?php
+
+namespace App\Http\Controllers\Admin\Base;
+
+use Illuminate\Http\Request as HttpRequest;
+use App\Http\Controllers\Admin\Controller;
+use App\Models\ClassModel;
+use App\Models\BaseAttachmentModel;
+use Request, Response, Validator, File;
+
+class ClassController extends Controller
+{
+    public function add(HttpRequest $request)
+    {
+    	if(! $request->has('class') || Request::method() != 'POST') {
+    		return back();
+    	}
+
+    	$validator = Validator::make($request->all(), [
+            'class' => 'required|string|max:100|unique:classes,class',
+        ]);
+    	if($validator->fails()) {
+    		$validator->errors()->add('my-error', '分类已存在!');
+    		return back()->withErrors($validator)->withInput();
+    	}
+    	
+    	$class = new ClassModel;
+    	$class->class = $request->input('class');
+    	if(! $class->save()) {
+    		$validator->errors()->add('my-error', '添加分类失败!');
+    		return back()->withErrors($validator)->withInput();
+    	}
+
+    	return back();
+    }
+
+    public function delete(HttpRequest $request)
+    {
+        if(Request::method() != 'POST') {
+            return back();
+        }
+
+        $class = null;
+        if($request->has('class') && ($class = ClassModel::find($request->input('class'))) != null) {
+            if($class->class == '未分类') {
+                return back();
+            }
+
+            $photos = BaseAttachmentModel::where('class', $class->class)->get();
+            foreach($photos as $photo) {
+                File::delete($photo->path);
+                $photo->delete();
+            }
+            $class->delete();
+        }
+        return redirect('admin/Base/Photos/index');
+    }
+}

+ 97 - 0
app/Http/Controllers/Admin/Base/CrudController.php

xqd
@@ -0,0 +1,97 @@
+<?php
+/**
+ * 创建增删改查
+ * User: Mike
+ * Email: m@9026.com
+ * Date: 2016/6/4
+ * Time: 17:14
+ */
+
+namespace App\Http\Controllers\Admin\Base;
+
+use App\Http\Controllers\Admin\Controller;
+use App\Services\CRUD\CRUD;
+use Illuminate\Support\Facades\DB;
+use App\Services\Admin\Menus;
+use Request;
+
+
+class CrudController extends Controller
+{
+    function create() {
+        if(Request::method() == 'POST') {
+            return $this->_createSave();
+        }
+        $schema = env("DB_DATABASE");
+
+        $tables = DB::select("SELECT TABLE_NAME,TABLE_COMMENT FROM information_schema.TABLES WHERE TABLE_SCHEMA='$schema'");
+
+        $MenusTrees = (new Menus())->getMenusTree();
+        return view('admin.base.crud.create',compact('tables','MenusTrees'));
+    }
+    private function _createSave() {
+        $data = Request::all();
+        $obj = new CRUD();
+        $ok = $obj->create($data);
+        if($ok) {
+            $this->showMessage("操作成功");
+        }else{
+            $this->showWarning("操作失败:" . $obj->getMessage());
+        }
+    }
+
+
+
+    public function getTable(){
+        $table = request()->get('table');
+        $schema = env("DB_DATABASE");
+        $data = DB::select("SELECT COLUMN_NAME,COLUMN_KEY FROM information_schema.COLUMNS WHERE TABLE_SCHEMA='{$schema}' AND TABLE_NAME='{$table}';");
+    }
+
+    public function checkModelPath($modelPath = null) {
+        if(!$modelPath) {
+            $modelPath = request()->get('path');
+        }
+        $modelPath = app_path() . "/Models/" . $modelPath . ".php";
+        if(file_exists($modelPath)) {
+            return json_encode(['status'=>FAILURE_CODE,'msg'=>'注意!!Model文件已存在,系统重复不会创建!!!']);
+        }else{
+            return json_encode(['status'=>SUCESS_CODE]);
+        }
+    }
+
+    public function checkServicePath($modelPath = null) {
+        if(!$modelPath) {
+            $modelPath = request()->get('path');
+        }
+        $modelPath = app_path() . "/Repositories/" . $modelPath . ".php";
+        if(file_exists($modelPath)) {
+            return json_encode(['status'=>FAILURE_CODE,'msg'=>'注意!!Service文件已存在,系统重复不会创建!!!']);
+        }else{
+            return json_encode(['status'=>SUCESS_CODE]);
+        }
+    }
+
+    public function checkControllerPath($modelPath = null) {
+        if(!$modelPath) {
+            $modelPath = request()->get('path');
+        }
+        $modelPath = app_path() . "/Http/Controllers/Admin/" . $modelPath . ".php";
+        if(file_exists($modelPath)) {
+            return json_encode(['status'=>FAILURE_CODE,'msg'=>'注意!!Controller文件已存在,系统重复不会创建!!!']);
+        }else{
+            return json_encode(['status'=>SUCESS_CODE]);
+        }
+    }
+    public function checkPath($modelPath = null) {
+        if(!$modelPath) {
+            $modelPath = request()->get('path');
+        }
+        $modelPath = app_path() . "/Http/Controllers/Admin/" . $modelPath . ".php";
+        if(file_exists($modelPath)) {
+            return json_encode(['status'=>FAILURE_CODE,'msg'=>'注意!!Controller文件已存在,系统重复不会创建!!!']);
+        }else{
+            return json_encode(['status'=>SUCESS_CODE]);
+        }
+    }
+}

+ 138 - 0
app/Http/Controllers/Admin/Base/DictionaryController.php

xqd
@@ -0,0 +1,138 @@
+<?php
+/**
+ *  字典管理
+ *  @author  system
+ *  @version    1.0
+ *  @date 2018-06-12 10:14:19
+ *
+ */
+namespace App\Http\Controllers\Admin\Base;
+use App\Http\Controllers\Admin\Controller;
+use Illuminate\Http\Request;
+use App\Repositories\Base\Criteria\OrderBy;
+use App\Repositories\Base\Criteria\MultiWhere;
+use App\Repositories\Base\DictionaryRepository;
+
+class DictionaryController extends Controller
+{
+    private $repository;
+
+    public function __construct(DictionaryRepository $repository) {
+        if(!$this->repository) $this->repository = $repository;
+    }
+
+    function index(Request $request) {
+        $search['keyword'] = $request->input('keyword');
+        $query = $this->repository->pushCriteria(new MultiWhere($search));
+
+        if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
+        $query = $query->pushCriteria(new OrderBy($request['sort_field'],$request['sort_field_by']));
+        }else{
+            $query = $query->pushCriteria(new OrderBy('id','DESC'));
+        }
+        $list = $query->paginate();
+        return view('admin.base.dictionary.index',compact('list'));
+    }
+
+
+    function check(Request $request) {
+        $request = $request->all();
+        $search['keyword'] = $request->input('keyword');
+        $orderby = array();
+        if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
+            $orderby[$request['sort_field']] = $request['sort_field_by'];
+        }
+        $list = $this->repository->search($search,$orderby);
+        return view('admin.base.dictionary.check',compact('list'));
+    }
+
+
+    /**
+     * 添加
+     * 
+     */
+    public function create(Request $request)
+    {
+        if($request->method() == 'POST') {
+            return $this->_createSave();
+        }
+        return view('admin.base.dictionary.edit');
+    }
+
+    /**
+     * 保存修改
+     */
+    private function _createSave(){
+        $data = (array) request('data');
+        $id = $this->repository->create($data);
+        if($id) {
+            $url[] = array('url'=>U( 'Base/Dictionary/index'),'title'=>'返回列表');
+            $url[] = array('url'=>U( 'Base/Dictionary/create'),'title'=>'继续添加');
+            $this->showMessage('添加成功',$url);
+        }else{
+            $url[] = array('url'=>U( 'Base/Dictionary/index'),'title'=>'返回列表');
+            return $this->showWarning('添加失败',$url);
+        }
+    }
+    
+    /**
+     * 
+     * 修改
+     * 
+     * 
+     */
+    public function update(Request $request) {
+        if($request->method() == 'POST') {
+            return $this->_updateSave();
+        }
+        $data = $this->repository->find($request->get('id'));
+        return view('admin.base.dictionary.edit',compact('data'));
+    }
+
+    /**
+     * 保存修改
+     */
+    private function _updateSave() {
+        $data = (array) request('data');
+        $ok = $this->repository->update(request('id'),$data);
+        if($ok) {
+            $url[] = array('url'=>U( 'Base/Dictionary/index'),'title'=>'返回列表');
+            return $this->showMessage('操作成功',urldecode(request('_referer')));
+        }else{
+            $url[] = array('url'=>U( 'Base/Dictionary/index'),'title'=>'返回列表');
+            return $this->showWarning('操作失败',$url);
+        }
+    }
+
+    public function view(Request $request) {
+        $data = $this->repository->find(request('id'));
+        return view('admin.base.dictionary.view',compact('data'));
+    }
+
+
+    /**
+     *
+     * 状态改变
+     *
+     */
+    public function status(Request $request) {
+        $ok = $this->repository->updateStatus(request('id'),request('status'));
+        if($ok) {
+            return $this->showMessage('操作成功');
+        }else{
+            return $this->showWarning('操作失败');
+        }
+    }
+    
+    /**
+     * 删除
+     */
+    public function destroy(Request $request) {
+        $bool = $this->repository->destroy($request->get('id'));
+        if($bool) {
+            return  $this->showMessage('操作成功');
+        }else{
+            return  $this->showWarning("操作失败");
+        }
+    }
+}

+ 66 - 0
app/Http/Controllers/Admin/Base/IndexController.php

xqd
@@ -0,0 +1,66 @@
+<?php
+/**
+ *  
+ *  @author  Mike <m@9026.com>
+ *  @version    1.0
+ *  @date 2015年10月12日
+ *
+ */
+namespace App\Http\Controllers\Admin\Base;
+
+use App\Http\Controllers\Admin\Controller;
+use App\Services\Base\Tree;
+use App\Services\Base\BaseArea;
+use App\Services\Admin\Menus;
+use App\Services\Admin\Acl;
+
+class IndexController extends Controller
+{
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    function index() {
+        if($this->_user['is_root']) {
+            $obj = new Menus();
+            $menus = $obj->search(array('level'=>2,'display'=>1),$orderby=array('sort'=>'desc'),$pagesize = 100000);
+            $menus = $menus->toArray();
+            $menus = list_to_tree($menus['data']);
+        }else{
+            $obj = new Acl();
+            $data = $obj->getRoleMenu($this->_user['admin_role_id']);
+            $menus = list_to_tree($data);
+        }
+        return view('admin.base.index.index',compact('menus'));
+    }
+    function welcome() {
+        return view('admin.base.index.welcome');
+    }
+    
+    function createAreaDate(){
+        //Base-index-createareadate.do
+        header("Content-type:text/html;charset=utf-8");
+        $areaObj = new BaseArea();
+        $data = $areaObj->getLevel();
+
+        $treeObj = new Tree();
+        $treeObj -> init($data);
+        $info = $treeObj -> getTree();
+        $output = array();
+        
+        foreach($info AS $key => $val){
+            if($val['id'] == '100000') continue;
+            $val['level'] = $val['level'] - 1;
+            unset($val['grade'], $val['spacer']);
+            $output[]= $val;
+        }
+        
+        $str = json_encode($output);
+        
+        $area_path = public_path() . '/base/js/areadata.js';
+        file_put_contents($area_path, $str);
+        
+        echo $str;exit;
+    }
+}

+ 41 - 0
app/Http/Controllers/Admin/Base/LogsController.php

xqd
@@ -0,0 +1,41 @@
+<?php
+/**
+ *  
+ *  @author  Mike <m@9026.com>
+ *  @version    1.0
+ *  @date 2015年10月30日
+ *
+ */
+namespace App\Http\Controllers\Admin\Base;
+use App\Http\Controllers\Admin\Controller;
+use App\Services\Base\Attachment;
+
+class LogsController extends Controller
+{
+   
+    //系统日志
+    public function nginx() {
+        $log_path = storage_path() . '/logs/' . "error-log" . date("Y-m-d") . ".log";
+        if(file_exists($log_path)) {
+            echo "<pre>" . file_get_contents($log_path) . "</pre>";
+        }else{
+            exit("没有错误日志");
+        }
+        
+    }
+    /**
+     * 初始化文件上传组件
+     */
+    private function _uploadControl($folder, $position = 'ali')
+    {
+        //初始化文件上传组件
+        $attachmentObj = new Attachment();
+        return $attachmentObj -> initupload([
+                'file_types' => 'jpg|jpeg|gif|png|bmp',
+        ], [
+                'position'   => $position,
+                'folder'     => $folder,
+        ]);
+    }
+    
+} 

+ 120 - 0
app/Http/Controllers/Admin/Base/MenusController.php

xqd
@@ -0,0 +1,120 @@
+<?php
+/**
+ *  文章
+ *  @author  Mike <m@9026.com>
+ *  @version    1.0
+ *  @date 2015年10月15日
+ *
+ */
+namespace App\Http\Controllers\Admin\Base;
+use App\Http\Controllers\Admin\Controller;
+use App\Services\Admin\Menus;
+use Request;
+
+class MenusController extends Controller
+{
+
+    private $_service;
+
+    public function __construct ()
+    {
+        if (!$this->_service) $this->_service = new Menus();
+    }
+
+    function index ()
+    {
+        $search['keyword'] = Request::input('keyword');
+        $list = $this->_service->getMenusTree($search);
+        return view('admin.base.menus.index', compact('list'));
+    }
+
+    public function _showEdit ()
+    {
+        $MenusTrees = $this->_service->getMenusTree();
+        view()->share("MenusTrees", $MenusTrees);
+    }
+
+    /**
+     * 添加
+     */
+    public function create ()
+    {
+        if (Request::method() == 'POST') {
+            return $this->_createSave();
+        }
+        $this->_showEdit();
+        return view('admin.base.menus.edit');
+    }
+
+    private function _createSave ()
+    {
+        $id = $this->_service->create(Request::input('data'));
+        if (isset($id->id)) {
+            //更新菜单层级关系
+            $level = $this->_service->getLevel($id->id);
+            $this->_service->update($id->id, ['level' => $level]);
+            
+            $url[] = array(
+                    'url' => U( 'Base/Menus/index'),
+                    'title' => '返回列表'
+            );
+            $url[] = array(
+                    'url' => U( 'Base/Menus/create'),
+                    'title' => '继续添加'
+            );
+            $this->showMessage('添加成功', $url);
+        } else {
+            $url[] = array(
+                    'url' => U( 'Base/Menus/index'),
+                    'title' => '返回列表'
+            );
+            $this->showWarning('添加失败', $url);
+        }
+    }
+
+    /**
+     * 修改
+     */
+    public function update ()
+    {
+        if (Request::method() == 'POST') {
+            return $this->_updateSave();
+        }
+        $this->_showEdit();
+        $data = $this->_service->find(Request::input('id'));
+        return view('admin.base.menus.edit', compact('data'));
+    }
+
+    private function _updateSave ()
+    {
+        $data = Request::input('data');
+        $data['level'] = $this->_service->getLevel(Request::input('id'));
+        $ok = $this->_service->update(Request::input('id'), $data);
+        if ($ok) {
+            $url[] = array(
+                    'url' => U( 'Base/Menus/index'),
+                    'title' => '返回列表'
+            );
+            $this->showMessage('操作成功', urldecode(Request::input('_referer')));
+        } else {
+            $url[] = array(
+                    'url' => U( 'Base/Menus/index'),
+                    'title' => '返回列表'
+            );
+            $this->showWarning('操作失败', $url);
+        }
+    }
+
+    /**
+     * 删除
+     */
+    public function destroy ()
+    {
+        $bool = $this->_service->destroy(Request::input('id'));
+        if ($bool) {
+            $this->showMessage('操作成功');
+        } else {
+            $this->showWarning("操作失败");
+        }
+    }
+}

+ 96 - 0
app/Http/Controllers/Admin/Base/PhotosController.php

xqd
@@ -0,0 +1,96 @@
+<?php
+
+namespace App\Http\Controllers\Admin\Base;
+
+use App\Http\Controllers\Admin\Controller;
+use App\Services\Base\Attachment;
+use App\Models\BaseAttachmentModel;
+use App\Models\ClassModel;
+use Illuminate\Http\Request as HttpRequest;
+use Request;
+use File;
+
+class PhotosController extends Controller
+{
+    private $_serviceAttachment;
+
+    public function __construct()
+    {
+        if( !$this->_serviceAttachment ) $this->_serviceAttachment = new Attachment();
+    }
+
+    public function index(HttpRequest $request)
+    {
+        $classes = ClassModel::all();
+        $a_class = $request->has('class') ? $request->input('class') : null;
+        if(($a_class = ClassModel::find($a_class)) == null) {
+            $a_class = ClassModel::first();
+        }
+        $photos = null;
+        $status = 'normal';
+        if($request->has('search')) {
+            $name = '%' . $request->input('search') . '%';
+            $photos = BaseAttachmentModel::where('name', 'like', $name)->get();
+            $status = 'search';
+        } else {
+            if($a_class){
+                $photos = BaseAttachmentModel::where('class', $a_class->class)->get();
+            }
+        }
+
+    	return view('admin.base.photos.index', compact('photos', 'classes', 'a_class', 'photos', 'status', 'photo_compress_quality'));
+    }
+
+    public function edit(HttpRequest $request)
+    {
+        if(Request::method() != 'POST') {
+            return back();
+        }
+
+        if($request->has('img-name') && $request->has('img-id')) {
+            $photo = BaseAttachmentModel::find($request->input('img-id'));
+            $photo->name = $request->input('img-name');
+            $photo->save();
+        }
+
+        return back();
+    }
+
+    public function move(HttpRequest $request)
+    {
+        if(Request::method() != 'POST') {
+            return back();
+        }
+
+        $ids = explode(',', $request->input('ids'));
+        $class = ClassModel::find($request->input('class'));
+        BaseAttachmentModel::whereIn('id', $ids)->update(['class' => $class->class]);
+        return back();
+    }
+
+    public function delete(HttpRequest $request)
+    {
+        if(Request::method() != 'POST') {
+            return back();
+        }
+
+        $ids = explode(',', $request->input('ids'));
+        $photos = BaseAttachmentModel::find($ids);
+        foreach($photos as $photo) {
+            File::delete($photo->path);
+            $photo->delete();
+        }
+        return back();
+    }
+
+    public function crop(HttpRequest $request)
+    {
+        if(Request::method() != 'POST') {
+            return back();
+        }
+
+        $this->_serviceAttachment->localUpload('file', $request->all());
+
+        return response()->json(['status' => 'ok'], 200);
+    }
+}

+ 185 - 0
app/Http/Controllers/Admin/Base/RoleController.php

xqd
@@ -0,0 +1,185 @@
+<?php
+
+namespace App\Http\Controllers\Admin\Base;
+
+use App\Http\Controllers\Admin\Controller;
+use App\Services\Admin\Role;
+use Request;
+use App\Services\Admin\Acl;
+
+class RoleController extends Controller
+{
+    private $level;
+    private $_service;
+    private $_serviceDepartments;
+
+    /**
+     * 初始化Service
+     */
+    public function __construct()
+    {
+        parent::__construct();
+        
+        if(!$this->_service) $this->_service = new Role();
+        $this->level = isset($this->_getRoleNode()->level)?$this->_getRoleNode()->level:'';
+    }
+    
+    /**
+     * 列表
+     */
+    function index()
+    {
+        if($this->_user['is_root']){
+            $search['level'] = 0;
+        }else{
+            $search['level'] = $this->level;
+        }
+        
+        $request = Request::all();
+        $search['keyword'] = Request::input('keyword');
+        
+        $orderby = array();
+        if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
+            $orderby[$request['sort_field']] = $request['sort_field_by'];
+        }
+        $list = $this->_service->search($search, $orderby);
+
+        return view('admin.base.role.index', compact('list'));
+    }
+
+    /**
+     * 创建
+     */
+    public function create()
+    {
+        if(Request::method() == 'POST'){
+            if(intval(Request::input('info.level')) < $this->level){
+                $this->showWarning('你无权创建该等级的角色!', urldecode(Request::input('_referer')));
+            }
+            if($this->_service->create(Request::input('info'))){
+                $this->showMessage('操作成功', U( 'Base/Role/index'));
+            }else{
+                $this->showMessage('操作失败', U( 'Base/Role/index'));
+            }
+        }
+        $level = $this->level;
+        return view('admin.base.role.edit', compact('level', 'Departments'));
+    }
+
+    /**
+     * 更新
+     */
+    public function update()
+    {
+        if(Request::method() == 'POST'){
+            if(intval(Request::input('info.level')) < $this->level){
+                $this->showWarning('你无权创建该等级的角色!', urldecode(Request::input('_referer')));
+            }
+            if($this->_service->update(Request::input('id'), Request::input('info'))){
+                $this->showMessage('操作成功', urldecode(Request::input('_referer')));
+            }else{
+                $this->showWarning('操作失败', urldecode(Request::input('_referer')));
+            }
+        }
+        $data = $this->_service->find(Request::input('id'));
+        $level = $this->level;
+        return view('admin.base.role.edit', compact('data', 'level', 'Departments'));
+    }
+    
+    /**
+     * 更新
+     */
+    public function auth()
+    {
+        $id = Request::input('id');
+        
+        $objAcl = new Acl();
+        
+        
+        if(Request::method() == 'POST'){
+           $menuIds = Request::input('menu_ids');
+           if($this->_user['is_root']) {
+               $allMenus = false;
+           }else{
+               $allMenus = array();
+               foreach ($this->_user['menus'] as $value) {
+                   $allMenus[] = $value['id'];
+               }
+           }
+           $ok = $objAcl->setRole($id, $menuIds,$allMenus);
+           if($ok) {
+               $arr['status'] = SUCESS_CODE;
+               
+           }else{
+               $arr['status'] = SERVER_ERROR;
+           }
+           exit(json_encode($arr));
+        }
+        
+        $hasPermissions = $objAcl->getAccessIDs($id);
+        
+        $role =  session(LOGIN_MARK_SESSION_KEY);
+        //为ztree做数据准备
+        $zTree = []; $all = [];
+        foreach($role['menus'] as $key => $value)
+        {
+            $arr = ['id' => $value['id'], 'pId' => $value['pid'], 
+                    'name' => $value['name'] . " (" . $value['path'] . ")",
+                    'open' => true];
+            if(in_array($value['id'], $hasPermissions)) $arr['checked'] = true;
+            $zTree[] = $arr;
+            $all[] = $value['id'];
+        }
+        $data = $this->_service->find($id);
+        return view('admin.base.role.auth', compact('data','zTree','all'));
+    }
+  
+    /**
+     * 更新状态
+     */
+    public function status()
+    {
+        $bool = $this->_service->updateStatus(Request::input('id'), Request::input('status'));
+        if($bool) {
+            $this->showMessage('操作成功');
+        }else{
+            $this->showWarning('操作失败');
+        }
+    }
+    
+    /**
+     * 删除
+     */
+    public function destroy()
+    {
+        $bool = $this->_service->destroy(Request::input('id'));
+        if($bool) {
+            $this->showMessage('操作成功');
+        }else{
+            $this->showWarning("操作失败");
+        }
+    }
+    
+    /**
+     * 获取角色权限节点(level越小权限越大)
+     */
+    private function _getRoleNode()
+    {
+        return $this->_service->getLevelNode($this->_user['admin_role_id']);
+    }
+
+
+    /**
+     * 获取树形结构
+     */
+    private function _getTreeByDepartmentId()
+    {
+        if($this->_user['is_root']){
+            $department_id = 0;
+        }else{
+            $department_id = intval($this->_user['department_id']);
+        }
+        return $this->_serviceDepartments->getTreeByDepartmentId($department_id);
+    }
+    
+}

+ 41 - 0
app/Http/Controllers/Admin/Base/SystemController.php

xqd
@@ -0,0 +1,41 @@
+<?php
+/**
+ *  
+ *  @author  Mike <m@9026.com>
+ *  @version    1.0
+ *  @date 2015年10月30日
+ *
+ */
+namespace App\Http\Controllers\Admin\Base;
+
+use App\Http\Controllers\Admin\Controller;
+use App\Services\Base\Attachment;
+use App\Services\Base\System;
+use Request;
+
+class SystemController extends Controller
+{
+   
+    //系统日志
+    public function config() {
+        if(Request::method() == 'POST') {
+            return $this->_counfigSave();
+        }
+        $obj = new System();
+        $data = $obj->getCoufig();
+        return view('admin.base.system.config', compact('data'));
+
+    }
+
+    private function _counfigSave() {
+        $data = (array) Request::input('data');
+        $obj = new System();
+        $ok = $obj->saveConfig($data);
+        if($ok) {
+            $this->showMessage('操作成功');
+        }else{
+            $this->showWarning('操作失败');
+        }
+    }
+
+} 

+ 123 - 0
app/Http/Controllers/Admin/Base/ToolController.php

xqd
@@ -0,0 +1,123 @@
+<?php
+/**
+ *  
+ *  @author  Mike <m@9026.com>
+ *  @version    1.0
+ *  @date 2015年10月30日
+ *
+ */
+namespace App\Http\Controllers\Admin\Base;
+
+use App\Http\Controllers\Admin\Controller;
+use App\Services\Base\Attachment;
+use Request;
+//use App\Utils\OSS\Alioss;
+//use App\Utils\DirUtil;
+
+class ToolController extends Controller
+{
+    private $_dirUtil;
+    private $_aliossService;
+    
+    public function __construct() {
+        if( !$this->_dirUtil ) $this->_dirUtil = new DirUtil();
+        if( !$this->_aliossService ) $this->_aliossService = new Alioss();
+    }
+    
+    /**
+     * 专题上传
+     */
+    function specialupload() {
+        $attachmentObj = new Attachment();
+        $uploadControl = $attachmentObj -> initupload([
+            'file_types' => 'php|htm|html',
+        ], [
+            'position'   => 'special',
+            'folder'     => 'at',
+        ]);
+        
+        //遍历专题目录
+        $data = array();
+        $dirList = $this->_dirUtil->dirTraverse(public_path('resources/views/web/special'));
+        if(!empty($dirList)){
+            foreach ($dirList AS $key => $val){
+                $data[$key]['name'] = trim(iconv("GBK", "UTF-8//IGNORE", substr(strrchr($val, '/'), 1, 50))) . '.html';
+                $data[$key]['url'] = 'http://' . config('sys.sys_www_domain') . '/at/' . $data[$key]['name'];
+            }
+        }
+        view()->share("uploadControl", $uploadControl);
+        return view('admin.base.tool.specialupload', compact('data'));
+    }
+    
+    /**
+     * 阿里云上传
+     */
+    function alimanage()
+    {
+        
+        $ok = $this->_aliossService->doesObjectExist("a/bg.jpg");
+        
+        $img_path = config('sys.sys_images_url');
+        $file_path = config('sys.sys_file_url');
+        $folder = trim(Request::input('folder'));
+        $dirname = trim(Request::input('dirname'));
+
+        //创建目录
+        if(Request::method() == 'POST'){
+            if($dirname){
+                $this->_createDir($dirname,  $folder);
+            }else{
+                $this->showWarning('目录名不能为空!');
+            }
+        }
+        
+        //构建路径
+        $folderPath = '/<a href="' . U( 'Base/Tool/alimanage') . '?folder=">根目录</a>/';
+        if($folder){
+            $dirPath = '';
+            $dirs = array_filter(explode('/', $folder));
+            foreach ($dirs AS $dir){
+                $dirPath .= $dir . '/';
+                $folderPath .= '<a href="' . U( 'Base/Tool/alimanage') . '?folder=' . $dirPath . '">'. $dir .'</a>/';
+            }
+        }
+        $itemObj = $this->_aliossService->listObjects(['prefix'=>$folder]);
+        $item['obj'] = $itemObj->getObjectList(); // 文件列表
+        $item['dir'] = $itemObj->getPrefixList(); // 目录列表
+       
+        $uploadControl = $this->_uploadControl('');
+        
+        return view('admin.base.tool.alimanage', compact('item', 'img_path', 'file_path', 'folderPath', 'uploadControl'));
+    }
+    
+    private function _createDir($dirname, $folder)
+    {
+        if(strpos($dirname, '/') === false && preg_match('/^([0-9a-zA-Z\_]+)$/is', $dirname)){
+            $newdir = $folder . $dirname;
+            $code = $this->_aliossService->createObjectDir($newdir);
+            if($code == null){
+                $this->showMessage('目录创建成功!', U( 'Base/Tool/alimanage') . '?folder=' . $newdir . '/');
+            }else{
+                $this->showWarning('目录创建失败!');
+            }
+        }else{
+            $this->showWarning('非法的目录名!');
+        }
+    }
+    
+    /**
+     * 初始化文件上传组件
+     */
+    private function _uploadControl($folder, $position = 'ali')
+    {
+        //初始化文件上传组件
+        $attachmentObj = new Attachment();
+        return $attachmentObj -> initupload([
+                'file_types' => 'jpg|jpeg|gif|png|bmp',
+        ], [
+                'position'   => $position,
+                'folder'     => $folder,
+        ]);
+    }
+    
+} 

+ 195 - 0
app/Http/Controllers/Admin/Base/UserController.php

xqd
@@ -0,0 +1,195 @@
+<?php
+/**
+ *  
+ *  @author  Mike <m@9026.com>
+ *  @version    1.0
+ *  @date 2015年10月12日
+ *
+ */
+namespace App\Http\Controllers\Admin\Base;
+
+use App\Http\Controllers\Admin\Controller;
+use App\Services\Admin\Role;
+use App\Services\Admin\AdminUser;
+use Request;
+
+class UserController extends Controller
+{
+    private $_service;
+    private $_role_service;
+
+    /**
+     * 初始化Service
+     */
+    public function __construct()
+    {
+        parent::__construct();
+        if(!$this->_service) $this->_service = new AdminUser();
+        if(!$this->_role_service) $this->_role_service = new Role();
+    }
+    
+    /**
+     * 列表
+     */
+    function index()
+    {
+        $request = Request::all();
+        $search['keyword'] = Request::input('keyword');
+
+        $orderby = array();
+        if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
+            $orderby[$request['sort_field']] = $request['sort_field_by'];
+        }
+        $list = $this->_service->search($search, $orderby);
+        $roles = pairList($this->_getRoles(), 'id', 'name');
+        return view('admin.base.user.index', compact('list', 'roles'));
+    }
+
+    /**
+     * 列表
+     */
+    function resetPwd()
+    {
+//        $pwd = '$2y$10$jRQGg4qdfDhdt.4TZpDaL.2pbgBJZqvdR.AMrE5rA2D3dgMyit8vS';
+//        var_dump(crypt('abcded', $pwd));exit;
+        $request = Request::all();
+        $search['keyword'] = Request::input('keyword');
+        $search['resetPwd'] =true;
+        $orderby = array();
+        if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
+            $orderby[$request['sort_field']] = $request['sort_field_by'];
+        }
+        $list = $this->_service->search($search, $orderby);
+        return view('admin.base.user.resetPwd', compact('list'));
+    }
+
+    function resetPwdPass()
+    {
+        $ok = $this->_service->resetPwdPass(Request::get('id'));
+        if($ok) {
+            $this->showMessage('操作成功');
+        }else{
+            $this->showWarning('操作失败');
+        }
+    }
+
+    function resetPwdReject()
+    {
+        $ok = $this->_service->resetPwdReject(Request::get('id'));
+        if($ok) {
+            $this->showMessage('操作成功');
+        }else{
+            $this->showWarning('操作失败');
+        }
+    }
+
+
+
+    /**
+     * 更新
+     */
+    public function create()
+    {
+        if(Request::method() == 'POST'){
+            $data = Request::input('info');
+            if(isset($data['admin_role_id']))$data['admin_role_id'] = implode(',', $data['admin_role_id']);
+            if($this->_service->create($data)){
+                $this->showMessage('操作成功', urldecode(Request::input('_referer')));
+            }else{
+                $this->showWarning('操作失败'  . $this->_service->getMsg(), urldecode(Request::input('_referer')));
+            }
+        }
+        $data = $this->_service->find(Request::input('id'));
+
+        if($this->_user['is_root']){
+            $roles = $this->_getRoles();
+        }else{
+            $roles = $this->_getCurrentRoles();
+        }
+        return view('admin.base.user.edit', compact('data', 'roles'));
+    }
+
+
+    /**
+     * 更新
+     */
+    public function update()
+    {
+        if(Request::method() == 'POST'){
+            $data = Request::input('info');
+            if(isset($data['admin_role_id']))$data['admin_role_id'] = implode(',', $data['admin_role_id']);
+            if($this->_service->update(Request::input('id'), $data)){
+                $this->showMessage('操作成功', urldecode(Request::input('_referer')));
+            }else{
+                $this->showWarning('操作失败' . $this->_service->getMsg(), urldecode(Request::input('_referer')));
+            }
+        }
+        $data = $this->_service->find(Request::input('id'));
+        
+        if($this->_user['is_root']){
+            $roles = $this->_getRoles();
+        }else{
+            $roles = $this->_getCurrentRoles();
+        }
+        return view('admin.base.user.edit', compact('data', 'roles'));
+    }
+    
+    public function auth() {
+        if(Request::method() == 'POST'){
+            $info = Request::input('info');
+            if(!empty($info['admin_role_id'])){
+                $info['admin_role_id'] = implode(',', $info['admin_role_id']);
+            }
+            if(!$info['id']) {
+                $this->showWarning('数据不全', urldecode(Request::input('_referer')));
+            }
+            if($this->_service->auth($info)){
+                $this->showMessage('操作成功', urldecode(Request::input('_referer')));
+            }else{
+                $this->showWarning('操作失败'. $this->_service->getMsg(), urldecode(Request::input('_referer')));
+            }
+        }
+        if($this->_user['is_root']){
+            $roles = $this->_getRoles();
+        }else{
+            $roles = $this->_getCurrentRoles();
+        }
+        return view('admin.base.user.auth', compact( 'roles'));
+    }
+
+    public function status() {
+        $ok = $this->_service->updateStatus(Request::get('id'),Request::get('status'));
+        if($ok) {
+            $this->showMessage('操作成功');
+        }else{
+            $this->showWarning('操作失败' . $this->_service->getMsg());
+        }
+    }
+
+
+    /**
+     * 得到当前角色所拥有的角色
+     */
+    private function _getCurrentRoles()
+    {
+        $_node = $this->_getRoleNode();
+        return $this->_role_service->getChildByLevel($_node['level'])->toArray();
+    }
+    
+    /**
+     * 获取角色权限节点(level越小权限越大)
+     */
+    private function _getRoleNode()
+    {
+        return $this->_role_service->getLevelNode($this->_user['admin_role_id'])->toArray();
+    }
+    
+    /**
+     * 得到所有角色
+     */
+    private function _getRoles()
+    {
+        return $this->_role_service->get()->toArray();
+    }
+    
+}

+ 167 - 0
app/Http/Controllers/Admin/Controller.php

xqd
@@ -0,0 +1,167 @@
+<?php
+
+namespace App\Http\Controllers\Admin;
+
+use Illuminate\Routing\Controller as BaseController;
+use Request,Auth;
+/**
+ * 父控制类类
+ *
+ * @author wangzhoudong <m@9026.com>
+ */
+abstract class Controller extends BaseController
+{
+    protected $_user;
+    protected $_serviceAdminRole;
+
+    public function __construct() {
+        $this->middleware(function ($request, $next) {
+            $this->_user = Auth::guard('admin')->user();
+            view()->share('_user',$this->_user);
+            return $next($request);
+        });
+    }
+
+    /**
+     * 检测表单篡改
+     *
+     * @return true|exception
+     */
+    protected function checkFormHash()
+    {
+        return (new Formhash())->checkFormHash();
+    }
+
+    /**
+     * 启用操作日志记录
+     */
+    protected function setActionLog($extDatas = [])
+    {
+        return app()->make(Mark::BIND_NAME)->setMarkYes()->setExtDatas($extDatas);
+    }
+
+    /**
+     * 显示提示消息
+     */
+    public function showMessage($msg, $links = NULL, $data = NULL, $redirect = true)
+    {
+        $this->_showMessage($msg, $links, $data, SUCESS_CODE, $redirect);
+    }
+
+    /**
+     * 显示错误消息
+     */
+    public function showWarning($msg, $links = NULL, $data = NULL, $redirect = true)
+    {
+        $this->_showMessage($msg, $links, $data, FAILURE_CODE, $redirect);
+    }
+
+    /**
+     *    显示消息
+     */
+    public function _showMessage($msgs, $links, $data, $code, $redirect)
+    {
+        header("Content-type:text/html;charset=utf-8");
+        if(!is_array($msgs)) {
+            $msgs = array($msgs);
+        }
+        $urls = $links;
+        if(!is_array($links)) {
+            $urls = array();
+            if($links) {
+                $urls[0]['url']    =  $links;
+            }elseif(isset($_SERVER['HTTP_REFERER'])) {
+                $urls[0]['url'] = $_SERVER['HTTP_REFERER'];
+            }else{
+                $urls[0]['url']    =  'javascript:history.back();';
+
+            }
+            $urls[0]['title']  = '点击立即跳转';
+        }
+
+        if($redirect) {
+            $redirect = $urls[0]['url'];
+            $redirect = (strstr($redirect, 'javascript:') !== false) ? $redirect : "location.href='{$redirect}'";
+        } else {
+            $redirect = '';
+        }
+
+        if(Request::ajax()){
+            $retval['msg'] = $msgs;
+            $retval['redirect'] = $redirect;
+            $retval['data'] = $data;
+            $retval['status'] = $code;
+            echo json_encode($retval);exit;
+            return ;
+        }
+        if($links=="refresh") {
+            echo "<script>alert('{$msgs[0]}');</script>";
+            echo "<script>window.close();</script>";
+            echo "<script>opener.location.reload();</script>";
+            exit;
+        }
+        if($code==SUCESS_CODE) {
+            $ico = '<i class="fa fa-check"></i>';
+            $titleHtml = '信息提示';
+        }else{
+            $ico = '<i class="fa fa-warning"></i>';
+            $titleHtml = '错误警告';
+        }
+        $msgHtml = '';
+        foreach ($msgs as $msg) {
+            $msgHtml .= "<li>$msg</li>";
+        }
+        $urlHtml = '';
+        foreach ($urls as $url) {
+            if($url['url'] == 'history_back'){
+                $u = "javascript:history.back();";
+            }else{
+                $u = $url['url'];
+            }
+            $urlHtml .= '&nbsp;<a  class="btn btn-primary"  href="' . $u . '" >' . $url['title'] . '</a>';
+        }
+
+        $html ='<!DOCTYPE html>
+                <html>
+                <head>
+                    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+                    <meta name="renderer" content="webkit">
+                    <title>' . $titleHtml .'</title>
+                    <link href="/base/css/bootstrap.min.css?v=3.4.0.css"  rel="stylesheet">
+                    <link href="/base/css/font-awesome.min.css?v=4.3.0.css"  rel="stylesheet">
+                    <link href="/base/css/style.min.css?v=3.0.0.css"  rel="stylesheet">
+                    <script type="text/javascript">
+                            setTimeout(function(){
+                                var url = "' . $urls[0]['url'] . '";
+                                if(url == "history_back"){
+                                    window.location.href = history.back();
+                                }else{
+	                               window.location.href = url;
+	                            }
+	                        }, 3000);
+                    </script>
+                </head>
+                
+                <body class="gray-bg">
+                    <div class="ibox-content middle-box" style="width:600px; margin-top: 150px;">
+                        <h2 class="text-center">' . $ico . ' ' . $titleHtml . '</h2>
+                        <ul class="todo-list m-t ui-sortable">
+                           ' . $msgHtml . '
+                        </ul>
+                        <div class="text-center">
+                                                                             该页面将在 3 秒钟后自动转向
+                        </div>
+                        <div class="text-center" style="margin-top: 10px;">
+                           ' . $urlHtml . '
+                          
+                            <a href="javascript:history.back();" class="btn  btn-success">
+                                                                                 返回
+                            </a>
+                        </div>
+                    </div>
+                </body>
+                </html>';
+        exit($html);
+    }
+
+}

+ 170 - 0
app/Http/Controllers/Admin/Messages/InfoController.php

xqd
@@ -0,0 +1,170 @@
+<?php
+/**
+ *  信息列表
+ *  @author  system
+ *  @version    1.0
+ *  @date 2018-07-11 06:50:54
+ *
+ */
+namespace App\Http\Controllers\Admin\Messages;
+use App\Http\Controllers\Admin\Controller;
+use App\Models\MessagesFollowerModel;
+use App\Models\MessagesTagModel;
+use App\Models\UserInfoModel;
+use Illuminate\Http\Request;
+use App\Repositories\Base\Criteria\OrderBy;
+use App\Repositories\Messages\Criteria\MultiWhere;
+use App\Repositories\Messages\InfoRepository;
+
+class InfoController extends Controller
+{
+    private $repository;
+
+    public function __construct(InfoRepository $repository) {
+        if(!$this->repository) $this->repository = $repository;
+    }
+
+    function index(Request $request) {
+        $search['keyword'] = $request->input('keyword');
+        $query = $this->repository->pushCriteria(new MultiWhere($search));
+
+        if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
+        $query = $query->pushCriteria(new OrderBy($request['sort_field'],$request['sort_field_by']));
+        }else{
+            $query = $query->pushCriteria(new OrderBy('id','DESC'));
+        }
+        $list = $query->paginate();
+        foreach ($list as $key=>$val){
+            $list[$key]['count'] = MessagesFollowerModel::where([['messages_id',$val['id']]])->count();
+            $user = UserInfoModel::find($val['user_id']);
+            $list[$key]['user'] = $user->nickname;
+            switch ($val['type']) {
+                case '0':
+                    $list[$key]['type'] = '免费';
+                    $list[$key]['state'] = '--';
+                    break;
+                case '1':
+                    $list[$key]['type'] = '悬赏';
+                    if($val['state'] == 0){
+                        $list[$key]['state'] = '未完成';
+                    } else {
+                        $list[$key]['state'] = '已结束';
+                    }
+                    break;
+                case '2':
+                    $list[$key]['type'] = '收费';
+                    $list[$key]['state'] = '--';
+                    break;
+            }
+        }
+        return view('admin.messages.info.index',compact('list'));
+    }
+
+
+    function check(Request $request) {
+        $request = $request->all();
+        $search['keyword'] = $request->input('keyword');
+        $orderby = array();
+        if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
+            $orderby[$request['sort_field']] = $request['sort_field_by'];
+        }
+        $list = $this->repository->search($search,$orderby);
+        return view('admin.messages.info.check',compact('list'));
+    }
+
+
+    /**
+     * 添加
+     * 
+     */
+    public function create(Request $request)
+    {
+        if($request->method() == 'POST') {
+            return $this->_createSave();
+        }
+        $tags = MessagesTagModel::orderBy('sort','desc')->get();
+
+        return view('admin.messages.info.edit',compact('tags'));
+    }
+
+    /**
+     * 保存修改
+     */
+    private function _createSave(){
+        $data = (array) request('data');
+        $id = $this->repository->create($data);
+        if($id) {
+            $url[] = array('url'=>U( 'Messages/Info/index'),'title'=>'返回列表');
+            $url[] = array('url'=>U( 'Messages/Info/create'),'title'=>'继续添加');
+            $this->showMessage('添加成功',$url);
+        }else{
+            $url[] = array('url'=>U( 'Messages/Info/index'),'title'=>'返回列表');
+            return $this->showWarning('添加失败',$url);
+        }
+    }
+    
+    /**
+     * 
+     * 修改
+     * 
+     * 
+     */
+    public function update(Request $request) {
+        if($request->method() == 'POST') {
+            return $this->_updateSave();
+        }
+        $data = $this->repository->find($request->get('id'));
+        $tags = MessagesTagModel::orderBy('sort','desc')->get();
+
+        return view('admin.messages.info.edit',compact('data','tags'));
+    }
+
+    /**
+     * 保存修改
+     */
+    private function _updateSave() {
+        $data = (array) request('data');
+        $ok = $this->repository->update(request('id'),$data);
+        if($ok) {
+            $url[] = array('url'=>U( 'Messages/Info/index'),'title'=>'返回列表');
+            return $this->showMessage('操作成功',urldecode(request('_referer')));
+        }else{
+            $url[] = array('url'=>U( 'Messages/Info/index'),'title'=>'返回列表');
+            return $this->showWarning('操作失败',$url);
+        }
+    }
+
+    public function view(Request $request) {
+        $data = $this->repository->find(request('id'));
+        $pic = json_decode($data['pic_url']);
+        $data['pic'] = $pic;
+        return view('admin.messages.info.view',compact('data'));
+    }
+
+
+    /**
+     *
+     * 状态改变
+     *
+     */
+    public function status(Request $request) {
+        $ok = $this->repository->updateStatus(request('id'),request('status'));
+        if($ok) {
+            return $this->showMessage('操作成功');
+        }else{
+            return $this->showWarning('操作失败');
+        }
+    }
+    
+    /**
+     * 删除
+     */
+    public function destroy(Request $request) {
+        $bool = $this->repository->destroy($request->get('id'));
+        if($bool) {
+            return  $this->showMessage('操作成功');
+        }else{
+            return  $this->showWarning("操作失败");
+        }
+    }
+}

+ 139 - 0
app/Http/Controllers/Admin/Messages/TagController.php

xqd
@@ -0,0 +1,139 @@
+<?php
+/**
+ *  标签列表
+ *  @author  system
+ *  @version    1.0
+ *  @date 2018-07-11 06:51:31
+ *
+ */
+namespace App\Http\Controllers\Admin\Messages;
+use App\Http\Controllers\Admin\Controller;
+use App\Repositories\Messages\Criteria\TagWhere;
+use Illuminate\Http\Request;
+use App\Repositories\Base\Criteria\OrderBy;
+use App\Repositories\Messages\Criteria\MultiWhere;
+use App\Repositories\Messages\TagRepository;
+
+class TagController extends Controller
+{
+    private $repository;
+
+    public function __construct(TagRepository $repository) {
+        if(!$this->repository) $this->repository = $repository;
+    }
+
+    function index(Request $request) {
+        $search['keyword'] = $request->input('keyword');
+        $query = $this->repository->pushCriteria(new TagWhere($search));
+
+        if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
+        $query = $query->pushCriteria(new OrderBy($request['sort_field'],$request['sort_field_by']));
+        }else{
+            $query = $query->pushCriteria(new OrderBy('id','DESC'));
+        }
+        $list = $query->paginate();
+        return view('admin.messages.tag.index',compact('list'));
+    }
+
+
+    function check(Request $request) {
+        $request = $request->all();
+        $search['keyword'] = $request->input('keyword');
+        $orderby = array();
+        if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
+            $orderby[$request['sort_field']] = $request['sort_field_by'];
+        }
+        $list = $this->repository->search($search,$orderby);
+        return view('admin.messages.tag.check',compact('list'));
+    }
+
+
+    /**
+     * 添加
+     * 
+     */
+    public function create(Request $request)
+    {
+        if($request->method() == 'POST') {
+            return $this->_createSave();
+        }
+        return view('admin.messages.tag.edit');
+    }
+
+    /**
+     * 保存修改
+     */
+    private function _createSave(){
+        $data = (array) request('data');
+        $id = $this->repository->create($data);
+        if($id) {
+            $url[] = array('url'=>U( 'Messages/Tag/index'),'title'=>'返回列表');
+            $url[] = array('url'=>U( 'Messages/Tag/create'),'title'=>'继续添加');
+            $this->showMessage('添加成功',$url);
+        }else{
+            $url[] = array('url'=>U( 'Messages/Tag/index'),'title'=>'返回列表');
+            return $this->showWarning('添加失败',$url);
+        }
+    }
+    
+    /**
+     * 
+     * 修改
+     * 
+     * 
+     */
+    public function update(Request $request) {
+        if($request->method() == 'POST') {
+            return $this->_updateSave();
+        }
+        $data = $this->repository->find($request->get('id'));
+        return view('admin.messages.tag.edit',compact('data'));
+    }
+
+    /**
+     * 保存修改
+     */
+    private function _updateSave() {
+        $data = (array) request('data');
+        $ok = $this->repository->update(request('id'),$data);
+        if($ok) {
+            $url[] = array('url'=>U( 'Messages/Tag/index'),'title'=>'返回列表');
+            return $this->showMessage('操作成功',urldecode(request('_referer')));
+        }else{
+            $url[] = array('url'=>U( 'Messages/Tag/index'),'title'=>'返回列表');
+            return $this->showWarning('操作失败',$url);
+        }
+    }
+
+    public function view(Request $request) {
+        $data = $this->repository->find(request('id'));
+        return view('admin.messages.tag.view',compact('data'));
+    }
+
+
+    /**
+     *
+     * 状态改变
+     *
+     */
+    public function status(Request $request) {
+        $ok = $this->repository->updateStatus(request('id'),request('status'));
+        if($ok) {
+            return $this->showMessage('操作成功');
+        }else{
+            return $this->showWarning('操作失败');
+        }
+    }
+    
+    /**
+     * 删除
+     */
+    public function destroy(Request $request) {
+        $bool = $this->repository->destroy($request->get('id'));
+        if($bool) {
+            return  $this->showMessage('操作成功');
+        }else{
+            return  $this->showWarning("操作失败");
+        }
+    }
+}

+ 178 - 0
app/Http/Controllers/Admin/Payment/InfoController.php

xqd
@@ -0,0 +1,178 @@
+<?php
+/**
+ *  支付列表
+ *  @author  system
+ *  @version    1.0
+ *  @date 2018-07-11 06:53:04
+ *
+ */
+namespace App\Http\Controllers\Admin\Payment;
+use App\Http\Controllers\Admin\Controller;
+use App\Models\UserInfoModel;
+use Illuminate\Http\Request;
+use App\Repositories\Base\Criteria\OrderBy;
+use App\Repositories\Payment\Criteria\MultiWhere;
+use App\Repositories\Payment\InfoRepository;
+
+class InfoController extends Controller
+{
+    private $repository;
+
+    public function __construct(InfoRepository $repository) {
+        if(!$this->repository) $this->repository = $repository;
+    }
+
+    function index(Request $request) {
+        $search['keyword'] = $request->input('keyword');
+        $query = $this->repository->pushCriteria(new MultiWhere($search));
+
+        if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
+        $query = $query->pushCriteria(new OrderBy($request['sort_field'],$request['sort_field_by']));
+        }else{
+            $query = $query->pushCriteria(new OrderBy('id','DESC'));
+        }
+        $list = $query->paginate();
+        foreach ($list as $key=>$val) {
+            if($val['user_id'] == 0){
+                $list[$key]['user'] = '系统';
+            } else {
+                $user = UserInfoModel::find($val['user_id']);
+                $list[$key]['user'] = $user->nickname;
+            }
+            if($val['to_user'] == 0){
+                $list[$key]['to_user_name'] = '系统';
+            } else {
+                $user = UserInfoModel::find($val['to_user']);
+                $list[$key]['to_user_name'] = $user->nickname;
+            }
+            switch ($val['type']) {
+                case '0':
+                    $list[$key]['payment'] = '充值';
+                    break;
+                case '1':
+                    $list[$key]['payment'] = '提现';
+                    break;
+                case '3':
+                    $list[$key]['payment'] = '悬赏知识';
+                    break;
+                case '2':
+                    $list[$key]['payment'] = '付费知识';
+                    break;
+            }
+            switch ($val['state']) {
+                case '0':
+                    $list[$key]['state'] = '未处理';
+                    break;
+                case '1':
+                    $list[$key]['payment'] = '已通过';
+                    break;
+                case '2':
+                    $list[$key]['payment'] = '已拒绝';
+                    break;
+            }
+        }
+        return view('admin.payment.info.index',compact('list'));
+    }
+
+
+    function check(Request $request) {
+        $request = $request->all();
+        $search['keyword'] = $request->input('keyword');
+        $orderby = array();
+        if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
+            $orderby[$request['sort_field']] = $request['sort_field_by'];
+        }
+        $list = $this->repository->search($search,$orderby);
+        return view('admin.payment.info.check',compact('list'));
+    }
+
+
+    /**
+     * 添加
+     * 
+     */
+    public function create(Request $request)
+    {
+        if($request->method() == 'POST') {
+            return $this->_createSave();
+        }
+        return view('admin.payment.info.edit');
+    }
+
+    /**
+     * 保存修改
+     */
+    private function _createSave(){
+        $data = (array) request('data');
+        $id = $this->repository->create($data);
+        if($id) {
+            $url[] = array('url'=>U( 'Payment/Info/index'),'title'=>'返回列表');
+            $url[] = array('url'=>U( 'Payment/Info/create'),'title'=>'继续添加');
+            $this->showMessage('添加成功',$url);
+        }else{
+            $url[] = array('url'=>U( 'Payment/Info/index'),'title'=>'返回列表');
+            return $this->showWarning('添加失败',$url);
+        }
+    }
+    
+    /**
+     * 
+     * 修改
+     * 
+     * 
+     */
+    public function update(Request $request) {
+        if($request->method() == 'POST') {
+            return $this->_updateSave();
+        }
+        $data = $this->repository->find($request->get('id'));
+        return view('admin.payment.info.edit',compact('data'));
+    }
+
+    /**
+     * 保存修改
+     */
+    private function _updateSave() {
+        $data = (array) request('data');
+        $ok = $this->repository->update(request('id'),$data);
+        if($ok) {
+            $url[] = array('url'=>U( 'Payment/Info/index'),'title'=>'返回列表');
+            return $this->showMessage('操作成功',urldecode(request('_referer')));
+        }else{
+            $url[] = array('url'=>U( 'Payment/Info/index'),'title'=>'返回列表');
+            return $this->showWarning('操作失败',$url);
+        }
+    }
+
+    public function view(Request $request) {
+        $data = $this->repository->find(request('id'));
+        return view('admin.payment.info.view',compact('data'));
+    }
+
+
+    /**
+     *
+     * 状态改变
+     *
+     */
+    public function status(Request $request) {
+        $ok = $this->repository->updateStatus(request('id'),request('status'));
+        if($ok) {
+            return $this->showMessage('操作成功');
+        }else{
+            return $this->showWarning('操作失败');
+        }
+    }
+    
+    /**
+     * 删除
+     */
+    public function destroy(Request $request) {
+        $bool = $this->repository->destroy($request->get('id'));
+        if($bool) {
+            return  $this->showMessage('操作成功');
+        }else{
+            return  $this->showWarning("操作失败");
+        }
+    }
+}

+ 18 - 0
app/Http/Controllers/Admin/TestController.php

xqd
@@ -0,0 +1,18 @@
+<?php
+
+namespace App\Http\Controllers\Admin;
+
+use Illuminate\Http\Request;
+
+
+class TestController extends Controller
+{
+    public function index(Request $request)
+    {
+    	$option = [];
+    	foreach($option as $key => $val) {
+    		dd($key, $val);
+    	}
+    	return view('admin.test.index');
+    }
+}

+ 139 - 0
app/Http/Controllers/Admin/User/InfoController.php

xqd
@@ -0,0 +1,139 @@
+<?php
+/**
+ *  用户表
+ *  @author  system
+ *  @version    1.0
+ *  @date 2017-05-30 12:16:56
+ *
+ */
+namespace App\Http\Controllers\Admin\User;
+use App\Http\Controllers\Admin\Controller;
+use Illuminate\Http\Request;
+use App\Repositories\Base\Criteria\OrderBy;
+use App\Repositories\User\Criteria\MultiWhere;
+use App\Repositories\User\InfoRepository;
+
+class InfoController extends Controller
+{
+    private $repository;
+
+    public function __construct(InfoRepository $repository) {
+        if(!$this->repository) $this->repository = $repository;
+    }
+
+    function index(Request $request) {
+        $search['keyword'] = $request->input('keyword');
+        $query = $this->repository->pushCriteria(new MultiWhere($search));
+
+        if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
+            $query = $query->pushCriteria(new OrderBy($request['sort_field'],$request['sort_field_by']));
+        }else{
+            $query = $query->pushCriteria(new OrderBy('id','DESC'));
+        }
+        $list = $query->paginate();
+        return view('admin.user.info.index',compact('list'));
+    }
+
+
+    function check(Request $request) {
+        $request = $request->all();
+        $search['keyword'] = $request->input('keyword');
+        $orderby = array();
+        if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
+            $orderby[$request['sort_field']] = $request['sort_field_by'];
+        }
+        $list = $this->repository->search($search,$orderby);
+        return view('admin.user.info.check',compact('list'));
+    }
+
+
+    /**
+     * 添加
+     * 
+     */
+    public function create(Request $request)
+    {
+        if($request->method() == 'POST') {
+            return $this->_createSave();
+        }
+        return view('admin.user.info.edit');
+    }
+
+    /**
+     * 保存修改
+     */
+    private function _createSave(){
+        $data = (array) request('data');
+        $id = $this->repository->create($data);
+        if($id) {
+            $url[] = array('url'=>U( 'User/Info/index'),'title'=>'返回列表');
+            $url[] = array('url'=>U( 'User/Info/create'),'title'=>'继续添加');
+            $this->showMessage('添加成功',$url);
+        }else{
+            $url[] = array('url'=>U( 'User/Info/index'),'title'=>'返回列表');
+            return $this->showWarning('添加失败',$url);
+        }
+    }
+    
+    /**
+     * 
+     * 修改
+     * 
+     * 
+     */
+    public function update(Request $request) {
+        if($request->method() == 'POST') {
+            return $this->_updateSave();
+        }
+        $data = $this->repository->find($request->get('id'));
+        return view('admin.user.info.edit',compact('data'));
+    }
+
+    /**
+     * 保存修改
+     */
+    private function _updateSave() {
+        $data = (array) request('data');
+        dd($data);
+        $ok = $this->repository->update(request('id'),$data);
+        if($ok) {
+            $url[] = array('url'=>U( 'User/Info/index'),'title'=>'返回列表');
+            return $this->showMessage('操作成功',urldecode(request('_referer')));
+        }else{
+            $url[] = array('url'=>U( 'User/Info/index'),'title'=>'返回列表');
+            return $this->showWarning('操作失败',$url);
+        }
+    }
+
+    public function view(Request $request) {
+        $data = $this->repository->find(request('id'));
+        return view('admin.user.info.view',compact('data'));
+    }
+
+
+    /**
+     *
+     * 状态改变
+     *
+     */
+    public function status(Request $request) {
+        $ok = $this->repository->updateStatus(request('id'),request('status'));
+        if($ok) {
+            return $this->showMessage('操作成功');
+        }else{
+            return $this->showWarning('操作失败');
+        }
+    }
+    
+    /**
+     * 删除
+     */
+    public function destroy(Request $request) {
+        $bool = $this->repository->destroy($request->get('id'));
+        if($bool) {
+            return  $this->showMessage('操作成功');
+        }else{
+            return  $this->showWarning("操作失败");
+        }
+    }
+}

+ 139 - 0
app/Http/Controllers/Admin/Wechat/AppController.php

xqd
@@ -0,0 +1,139 @@
+<?php
+/**
+ *  11
+ *  @author  system
+ *  @version    1.0
+ *  @date 2018-07-26 01:43:25
+ *
+ */
+namespace App\Http\Controllers\Admin\Wechat;
+use App\Http\Controllers\Admin\Controller;
+use Illuminate\Http\Request;
+use App\Repositories\Base\Criteria\OrderBy;
+use App\Repositories\Wechat\Criteria\MultiWhere;
+use App\Repositories\Wechat\AppRepository;
+
+class AppController extends Controller
+{
+    private $repository;
+
+    public function __construct(AppRepository $repository) {
+        if(!$this->repository) $this->repository = $repository;
+    }
+
+    function index(Request $request) {
+        $search['keyword'] = $request->input('keyword');
+        $query = $this->repository->pushCriteria(new MultiWhere($search));
+
+        if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
+        $query = $query->pushCriteria(new OrderBy($request['sort_field'],$request['sort_field_by']));
+        }else{
+            $query = $query->pushCriteria(new OrderBy('id','DESC'));
+        }
+        $list = $query->paginate();
+        return view('admin.wechat.app.index',compact('list'));
+    }
+
+
+    function check(Request $request) {
+        $request = $request->all();
+        $search['keyword'] = $request->input('keyword');
+        $orderby = array();
+        if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
+            $orderby[$request['sort_field']] = $request['sort_field_by'];
+        }
+        $list = $this->repository->search($search,$orderby);
+        return view('admin.wechat.app.check',compact('list'));
+    }
+
+
+    /**
+     * 添加
+     * 
+     */
+    public function create(Request $request)
+    {
+        if($request->method() == 'POST') {
+            return $this->_createSave();
+        }
+        return view('admin.wechat.app.edit');
+    }
+
+    /**
+     * 保存修改
+     */
+    private function _createSave(){
+        $data = (array) request('data');
+        $id = $this->repository->create($data);
+        if($id) {
+            $url[] = array('url'=>U( 'Wechat/App/index'),'title'=>'返回列表');
+            $url[] = array('url'=>U( 'Wechat/App/create'),'title'=>'继续添加');
+            $this->showMessage('添加成功',$url);
+        }else{
+            $url[] = array('url'=>U( 'Wechat/App/index'),'title'=>'返回列表');
+            return $this->showWarning('添加失败',$url);
+        }
+    }
+    
+    /**
+     * 
+     * 修改
+     * 
+     * 
+     */
+    public function update(Request $request) {
+        if($request->method() == 'POST') {
+            return $this->_updateSave();
+        }
+        $data = $this->repository->find($request->get('id'));
+        //($request->get('id'));
+        return view('admin.wechat.app.edit',compact('data'));
+    }
+
+    /**
+     * 保存修改
+     */
+    private function _updateSave() {
+        $data = (array) request('data');
+        $ok = $this->repository->update(request('id'),$data);
+        if($ok) {
+            $url[] = array('url'=>U( 'Wechat/App/index'),'title'=>'返回列表');
+            return $this->showMessage('操作成功',urldecode(request('_referer')));
+        }else{
+            $url[] = array('url'=>U( 'Wechat/App/index'),'title'=>'返回列表');
+            return $this->showWarning('操作失败',$url);
+        }
+    }
+
+    public function view(Request $request) {
+        $data = $this->repository->find(request('id'));
+        return view('admin.wechat.app.view',compact('data'));
+    }
+
+
+    /**
+     *
+     * 状态改变
+     *
+     */
+    public function status(Request $request) {
+        $ok = $this->repository->updateStatus(request('id'),request('status'));
+        if($ok) {
+            return $this->showMessage('操作成功');
+        }else{
+            return $this->showWarning('操作失败');
+        }
+    }
+    
+    /**
+     * 删除
+     */
+    public function destroy(Request $request) {
+        $bool = $this->repository->destroy($request->get('id'));
+        if($bool) {
+            return  $this->showMessage('操作成功');
+        }else{
+            return  $this->showWarning("操作失败");
+        }
+    }
+}

+ 168 - 0
app/Http/Controllers/Api/V1/AttachmentController.php

xqd
@@ -0,0 +1,168 @@
+<?php
+
+namespace App\Http\Controllers\Api\V1;
+
+use App\Helper\AttachmentHelper;
+use App\Models\BaseAttachmentModel;
+use Illuminate\Http\Request;
+use App\Services\Base\Attachment;
+use App\Services\Base\ErrorCode;
+use Validator, Response;
+
+class AttachmentController extends Controller
+{
+    use AttachmentHelper;
+
+    /**
+     * @api {get} /api/attachment/download/{md5} 下载文件(图片)
+     * @apiDescription 下载文件(图片)(get code)
+     * @apiGroup Attachment
+     * @apiPermission none
+     * @apiVersion 0.1.0
+     * @apiParam {string} md5   图片md5码
+     * @apiSuccessExample {json} Success-Response:
+     *     HTTP/1.1 200 OK
+     *     {
+     *       文件二进制码
+     *     }
+     * @apiErrorExample {json} Error-Response:
+     *     HTTP/1.1 404 Not found
+     */
+    public function download($md5)
+    {
+        $attachment = Attachment::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,
+        ]);
+    }
+
+    /**
+     * @api {post} /api/attachment/upload 通用上传接口
+     * @apiDescription 通用上传接口
+     * @apiGroup Attachment
+     * @apiPermission none
+     * @apiVersion 0.1.0
+     * @apiParam {string} tag 附件标签 avatar video dream
+     * @apiParam {File} file 附件(可以多个,使用file.xxx,可返回多个)[默认大小【10M】, 类型图片png jpg gif,视频类型mp4]
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+     * {
+     *     "state": true,
+     *     "code": 0,
+     *     "message": "",
+     *     "data": [
+     *         "file": "f72e7dad80f597ed6621a009e82243ad",
+     *         "real": "真实路径"
+     *          //文件访问url http://localhost/attachment/f72e7dad80f597ed6621a009e82243ad
+     *     ]
+     * }
+     * @apiErrorExample {json} Error-Response:
+     * HTTP/1.1 400 Bad Request
+     * {
+     *     "state": false,
+     *     "code": 1000,
+     *     "message": "传入参数不正确",
+     *     "data": null or []
+     * }
+     * 可能出现的错误代码:
+     *    200     SAVE_USER_FAILED                保存用户数据失败
+     *    201     ATTACHMENT_MKDIR_FAILED         创建附件目录失败
+     *    202     ATTACHMENT_UPLOAD_INVALID       上传附件文件无效
+     *    203     ATTACHMENT_SAVE_FAILED          保存附件失败
+     *    204     ATTACHMENT_MOVE_FAILED          移动附件失败
+     *    205     ATTACHMENT_DELETE_FAILED        删除附件文件失败
+     *    206     ATTACHMENT_RECORD_DELETE_FAILED 删除附件记录失败
+     *    1000    CLIENT_WRONG_PARAMS             传入参数不正确
+     *    1101    INCORRECT_VERIFY_CODE           输入验证码错误
+     *    1105    USER_DOES_NOT_EXIST             用户不存在
+     *    1200    ATTACHMENT_UPLOAD_FAILED        附件上传失败
+     *    1201    ATTACHMENT_SIZE_EXCEEDED        附件大小超过限制
+     *    1202    ATTACHMENT_MIME_NOT_ALLOWED     附件类型不允许
+     *    1203    ATTACHMENT_NOT_EXIST            附件不存在
+     */
+    public function upload(Request $request) {
+        \Log::info($request->all());
+        $validator = Validator::make($request->all(),
+            [
+                'tag'         => 'required|alpha_dash',
+            ],
+            [
+                'tag.required'      => 'tag必填',
+                'tag.alpha_dash'    => 'tag只能为字母数字中/下划线',
+            ]
+        );
+
+        if ($validator->fails()) {
+            return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '', $validator->messages());
+        }
+
+        $result = $this->uploadAttachment($request, $request->get('file'), $request->get('tag'), 10 * 1024 * 1024, [
+            'image/jpeg',
+            'image/png',
+            'image/gif',
+            'video/mp4',
+        ]);
+        //dd($result);
+        if (is_array($result)) {
+            return $this->api($result);
+        } elseif (is_string($result)) {
+            return $this->api(['file' => $result]);
+        } else {
+            return $this->error($result);
+        }
+
+    }
+
+    /**
+     * @api {get} /api/attachment/delete/{md5} 删除文件(图片)
+     * @apiDescription 删除文件(图片)
+     * @apiGroup Attachment
+     * @apiPermission Passport
+     * @apiVersion 0.1.0
+     * @apiParam {string} md5   图片md5码
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+     * {
+     *     "state": true,
+     *     "code": 0,
+     *     "message": "",
+     *     "data": {
+     *         "result": true/false
+     *     }
+     * }
+     * @apiErrorExample {json} Error-Response:
+     * HTTP/1.1 400 Bad Request
+     * {
+     *     "state": false,
+     *     "code": 1000,
+     *     "message": "传入参数不正确",
+     *     "data": null or []
+     * }
+     * 可能出现的错误代码:
+     *    205     ATTACHMENT_DELETE_FAILED        删除附件文件失败
+     *    206     ATTACHMENT_RECORD_DELETE_FAILED 删除附件记录失败
+     *    1203    ATTACHMENT_NOT_EXIST            附件不存在
+     */
+    public function delete($md5) {
+        $result = $this->deleteAttachment($md5);
+        if ($result === 0) {
+            return $this->api(['result' => true]);
+        } else {
+            return $this->error($result);
+        }
+    }
+
+    public function index(){
+        $result = BaseAttachmentModel::all()->sortByDesc('id');
+        return $this->api($result);
+    }
+
+
+
+}

+ 30 - 0
app/Http/Controllers/Api/V1/AuthController.php

xqd
@@ -0,0 +1,30 @@
+<?php
+
+namespace App\Http\Controllers\Api\V1;
+
+use App\Models\Merchant;
+use App\Models\MemberMerchant;
+use App\Models\UserBanks;
+use App\Models\Setting;
+
+use Illuminate\Http\Request;
+//use App\Http\HelperTraits\AttachmentHelper;
+use App\Services\Base\ErrorCode;
+use App\User;
+use Illuminate\Support\Facades\Hash;
+use Validator, Auth, Cache;
+
+class AuthController extends Controller
+{
+
+    private $expireTime     = 1;
+    private $keySmsCode     = 'auth:sms:';
+    private $keySmsCodeExist     = 'auth:sms:exist';
+    private $expireTimeExist     = 24*60;
+
+    public function test(){
+//        return $this->error(ErrorCode::SAVE_USER_FAILED);
+        return $this->api(['test' => 'test']);
+    }
+
+}

+ 107 - 0
app/Http/Controllers/Api/V1/Controller.php

xqd
@@ -0,0 +1,107 @@
+<?php
+
+namespace App\Http\Controllers\Api\V1;
+
+use Illuminate\Foundation\Bus\DispatchesJobs;
+use Illuminate\Routing\Controller as BaseController;
+use Illuminate\Foundation\Validation\ValidatesRequests;
+use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
+use App\Services\Base\ErrorCode;
+use Request, Response, Auth,Log;
+
+class Controller extends BaseController
+{
+    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
+
+//    protected $_data = null;
+    protected $_user = null;
+
+    public function __construct() {
+
+        $this->middleware('auth:api', [
+            'except' => [
+                'upload', 'getCode', 'reset', 'login', 'get', 'register', 'alipayNotify', 'wechatpayNotify',
+                'get', 'area', 'get_province', 'get_city', 'get_county', 'test', 'indexMenu', 'userRelease', 'indexTag', 'indexMessage', 'indexGetMessage', 'userEditFavorite', 'userFavorite', 'userMyMessage', 'userMessageDetail', 'userGetMessages', 'recharge', 'cash'
+            ]
+        ]);
+
+//        \DB::connection()->enableQueryLog();
+//        $queries = \DB::getQueryLog();
+//        dd($queries);
+
+//        $this->_user = Auth::user();
+//        if ($this->_user !== null) {
+//            $this->_user->last_ip = Request::ip();
+//        }
+//        $data = $this->rawPostData();
+//        if (!$this->checkSignature($data, env('APP_SECRET'))) {
+//            $this->rawError(ErrorCode::CLIENT_APP_CHECKSUM_ERROR);
+//        }
+//        unset($data['nonce_str'], $data['timestamp'], $data['sig']);
+
+//        $this->_data = $data;
+    }
+
+//    public function saveLastIp() {
+//        if ($this->_user !== null) {
+//            $this->_user->save();
+//        }
+//    }
+
+    public function getUserId()
+    {
+        return 1;
+        return session('user_id');
+    }
+
+    public function rawPostData() {
+        $request = Request::instance();
+        $data = $request->getContent();
+        return json_decode($data, true);
+    }
+
+    public function rawApi($data, $code = 0, $message = '') {
+        $ret = $this->genApiData($data, $code, $message);
+        return json_encode($ret);
+    }
+
+    public function api($data, $code = 0, $message = '') {
+        $ret = $this->genApiData($data, $code, $message);
+        $status = $code === 0 ? 200 : 400;
+        return Response::json($ret, $status);
+    }
+
+    public function validatorError($arr, $code = 0, $message = '') {
+        Log::info($arr);
+        foreach ($arr as $val){
+            if($val&&$message==''){
+                $message = $val;
+            }
+        }
+        $ret = $this->genApiData(null, $code, $message);
+        $status = $code === 0 ? 200 : 400;
+        return Response::json($ret, $status);
+    }
+
+    public function error($code, $message = '', $data = null) {
+        return $this->api($data, $code, $message);
+    }
+
+    public function rawError($code, $message = '') {
+        echo $this->rawApi(null, $code, $message);
+        exit;
+    }
+
+    private function genApiData($data, $code = 0, $message = '') {
+        if ($code !== 0 && ErrorCode::CLIENT_WRONG_PARAMS && empty($message)) {
+            $message = ErrorCode::message($code);
+        }
+        $ret = [
+            'status'     => $code == 0,
+            'status_code'      => $code,
+            'message'   => $message,
+            'data'      => $data
+        ];
+        return $ret;
+    }
+}

+ 354 - 0
app/Http/Controllers/Api/V1/IndexController.php

xqd
@@ -0,0 +1,354 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: 思维定制
+ * Date: 2018/7/12
+ * Time: 16:03
+ */
+
+namespace App\Http\Controllers\Api\V1;
+
+
+use App\Models\MessagesFollowerModel;
+use App\Models\MessagesInfoModel;
+use App\Models\MessagesTagModel;
+use App\Models\PaymentInfoModel;
+use App\Models\SeenModel;
+use App\Models\UserInfoModel;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\DB;
+use Validator,Auth;
+use App\Services\Base\ErrorCode;
+
+class IndexController extends Controller
+{
+
+    /**
+     * @api {get} /api/index/tag 筛选标签(indexTag)
+     * @apiDescription 筛选标签(indexTag)indexTag
+     * @apiGroup Index
+     * @apiPermission none
+     * @apiVersion 0.1.0
+     * @apiParam {string}  keywords   关键词
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+     * {
+     *     "status": true,
+     *     "status_code": 0,
+     *     "message": "",
+     *     "data": [
+     *        {
+     *            "id": 1,
+     *            "name": "标签1",
+     *            "sort": 1,
+     *            "deleted_at": null,
+     *            "created_at": "2018-07-12 17:03:07",
+     *            "updated_at": "2018-07-12 17:03:11"
+     *         }
+     *     ]
+     * }
+     * @apiErrorExample {json} Error-Response:
+     * HTTP/1.1 400 Bad Request
+     * {
+     *     "state": false,
+     *     "code": 1000,
+     *     "message": "传入参数不正确",
+     *     "data": null or []
+     * }
+     */
+
+    public function indexTag(Request $request)
+    {
+
+        $keywords = $request->input('keywords');
+        $keywords = '%'.$keywords.'%';
+        $data = MessagesTagModel::where([['name','like',$keywords]])->get();
+        return $this->api($data);
+    }
+
+
+    /**
+     * @api {get} /api/index/menu 知识列表(indexMenu)
+     * @apiDescription 知识列表(indexMenu)indexMenu
+     * @apiGroup Index
+     * @apiPermission none
+     * @apiVersion 0.1.0
+     * @apiParam {string}  tag_id   标签ID
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+     * {
+     * "status": true,
+     * "status_code": 0,
+     * "message": "",
+     * "data": {
+     *       "menu": [
+     *           {
+     *               "id": 4,
+     *               "name": "标签4",
+     *               "sort": 4,
+     *               "deleted_at": null,
+     *               "created_at": "2018-07-12 17:04:31",
+     *               "updated_at": "2018-07-12 17:04:34"
+     *           }
+     *       ],
+     *       "message": {
+     *       "current_page": 1,
+     *       "data": [
+     *           {
+     *               "id": 1,
+     *               "title": "爱我的",
+     *               "type": 0,
+     *               "owner": "Richod"
+     *           }
+     *       ],
+     *       "first_page_url": "http://zsff.xcx.com/api/index/menu?page=1",
+     *       "from": 1,
+     *       "last_page": 1,
+     *       "last_page_url": "http://zsff.xcx.com/api/index/menu?page=1",
+     *       "next_page_url": null,
+     *       "path": "http://zsff.xcx.com/api/index/menu",
+     *       "per_page": 1,
+     *       "prev_page_url": null,
+     *       "to": 1,
+     *       "total": 1
+     *       }
+     *   }
+     *}
+     * @apiErrorExample {json} Error-Response:
+     * HTTP/1.1 400 Bad Request
+     * {
+     *     "state": false,
+     *     "code": 1000,
+     *     "message": "传入参数不正确",
+     *     "data": null or []
+     * }
+     */
+    public function indexMenu(Request $request)
+    {
+        $validator = Validator::make($request->all(),
+            [
+                'tag_id' => 'integer'
+            ],
+            [
+                'tag_id.integer' => '标签参数格式不对!'
+            ]
+        );
+        if ($validator->fails()) {
+            return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
+        }
+        $data = $request->input();
+        $menu = MessagesTagModel::orderBy('sort','Desc')->take(3)->get();
+        if(!isset($data['tag_id']) || $data['tag_id'] == 0){
+            $message = MessagesInfoModel::where('state',0)->select('id','title','type')->orderBy('id','Desc')->paginate(1);
+        } else {;
+            $message = MessagesTagModel::find($data['tag_id'])->messgaes()->where('state',0)->select('id','title','type')->orderBy('id','Desc')->paginate(1);
+            //dd($message);
+        }
+        foreach ($message as $item){
+            $user = UserInfoModel::find($item->user_id);
+            if($user){
+                $item->owner = $user->nickname;
+            }
+        }
+        return $this->api(compact('menu','message'));
+    }
+
+
+    /**
+     * @api {get} /api/index/message 知识详情(indexMessage)
+     * @apiDescription 知识详情(indexMenu)indexMessage
+     * @apiGroup Index
+     * @apiPermission none
+     * @apiVersion 0.1.0
+     * @apiParam {int}  id   知识ID
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+     * {
+     * "status": true,
+     * "status_code": 0,
+     * "message": "",
+     * "data": {
+     *       "message": {
+     *              "id": 1,
+     *              "title": "爱我的",
+     *              "content": "爱我的",
+     *              "user_id": 1,
+     *              "price": 0,
+     *              "phone": "18228068397",
+     *              "comment": "瓦坎达入口",
+     *              "type": 0,
+     *              "sort": 1,
+     *              "deleted_at": null,
+     *              "created_at": "2018-07-12 17:06:23",
+     *              "updated_at": "2018-07-12 17:06:26",
+     *              "state": 0,
+     *              "is_pay": "是否需要付费 0 需要付费 1 不需要"
+     *          }
+     *      }
+     *}
+     * @apiErrorExample {json} Error-Response:
+     * HTTP/1.1 400 Bad Request
+     * {
+     *     "state": false,
+     *     "code": 1000,
+     *     "message": "传入参数不正确",
+     *     "data": null or []
+     * }
+     */
+    public function indexMessage(Request $request)
+    {
+        $validator = Validator::make($request->all(),
+            [
+                'id' => 'required'
+            ],
+            [
+                'id.required' => 'id不能为空!'
+            ]
+        );
+        if ($validator->fails()) {
+            return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
+        }
+        $userAuth = Auth('api')->user();
+        if(!$userAuth){
+            $msg = 'token已过期,请重新登录';
+            return $this->api($msg);
+        }
+        //echo 111;
+        $id = $request->input('id');
+
+        $message = MessagesInfoModel::where([['state',0],['id',$id]])->first();
+        if(!$message){
+            $msg = '该信息不存在或者已完成';
+            return $this->api($msg);
+        }
+
+        if($message->type ==0) {
+            $user = UserInfoModel::find($userAuth->id);
+            $followers['messages_id'] = $message->id;
+            $followers['user_id'] = $user->id;
+            $followers['username'] = $user->nickname;
+            $followers['mobile'] = $user->mobile;
+            $followers['state'] = 2;
+            MessagesFollowerModel::create($followers);
+        }
+
+        if($message->type == 2){
+            if($message->user_id != $this->getUserId()) {
+                $check_message = MessagesFollowerModel::where([['message_id',$message->id],['user_id',$userAuth->id],['type',1]])->first();
+                if(!$check_message){
+                    $message->is_pay = 0;
+                } else {
+                    $message->is_pay = 1;
+                }
+            } else {
+                $message->is_pay = 1;
+            }
+
+        } else {
+            $message->is_pay = '';
+        }
+        return $this->api(compact('message'));
+    }
+
+
+
+    /**
+     * @api {get} /api/index/get_message 获取知识(indexGetMessage)
+     * @apiDescription 获取知识(indexMenu)indexGetMessage
+     * @apiGroup Index
+     * @apiPermission none
+     * @apiVersion 0.1.0
+     * @apiParam {int}  id    知识ID
+     * @apiParam {int}  type  知识类型 1 悬赏 2 付费
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+     * "data": {
+     *      "code": 1
+     *      "msg": "添加成功"
+     *    }
+     * @apiErrorExample {json} Error-Response:
+     * HTTP/1.1 400 Bad Request
+     * {
+     *     "state": false,
+     *     "code": 1000,
+     *     "message": "传入参数不正确",
+     *     "data": null or []
+     * }
+     */
+    public function indexGetMessage(Request $request)
+    {
+        $validator = Validator::make($request->all(),
+            [
+                'id' => 'required',
+                'type' => 'required',
+            ],
+            [
+                'id.required' => 'id不能为空!',
+                'type.required' => 'type不能为空!'
+            ]
+        );
+        if ($validator->fails()) {
+            return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
+        }
+        $userAuth = Auth('api')->user();
+        if(!$userAuth){
+            $msg = 'token已过期,请重新登录';
+            return $this->api($msg);
+        }
+        $id = $request->input('id');
+        $type = $request->input('type');
+        $message = MessagesInfoModel::where([['id',$id],['type',$type],['state',0]])->first();
+        if(!$message){
+            $msg = '该信息不存在或者已完成';
+            return $this->api($msg);
+        }
+
+        $check_is_buy = MessagesFollowerModel::where([['user_id',$userAuth->id],['messages_id',$message->id]])->first();
+        if($check_is_buy){
+            $msg = '您已获取该知识,请勿重复操作';
+            return $this->api($msg);
+        }
+        $user = UserInfoModel::find($userAuth->id);
+        if($type == 2) {
+            DB::beginTransaction();
+            $out_trade_no = 'We'.date('YmdHis').rand(1000,9999);
+            $user->money -= $message->price;
+            if($user->money<0){
+                $msg = '您的余额已不足,请先充值';
+                return $this->api($msg);
+            }
+            if(!$user->save()){
+                $msg = '购买失败';
+                DB::rollback();
+                return $this->api($msg);
+            }
+            //dd(111);
+            $save['openid'] = $user->openid;
+            $save['out_trade_no'] = $out_trade_no;
+            $save['user_id'] = $userAuth->id;
+            $save['to_user'] = $message->user_id;
+            $save['price'] = $message->price;
+            $save['type'] = 2;
+            $res = PaymentInfoModel::create($save);
+            if(!$res) {
+                $msg = '购买失败';
+                DB::rollback();
+                return $this->api($msg);
+            }
+
+        }
+        $followers['messages_id'] = $message->id;
+        $followers['user_id'] = $user->id;
+        $followers['username'] = $user->nickname;
+        $followers['mobile'] = $user->mobile;
+        $followers['state'] = $type == 1?0:1;
+        if(MessagesFollowerModel::create($followers)){
+            $msg = '获取成功';
+            DB::commit();
+        } else {
+            $msg = '购买失败';
+            DB::rollback();
+        }
+        return $this->api($msg);
+    }
+}

+ 117 - 0
app/Http/Controllers/Api/V1/LoginController.php

xqd
@@ -0,0 +1,117 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: 思维定制
+ * Date: 2018/7/11
+ * Time: 15:59
+ */
+
+namespace App\Http\Controllers\Api\V1;
+
+use App\Models\UserInfoModel;
+use App\Models\WechatAppModel;
+use EasyWeChat\Factory;
+use Illuminate\Http\Request;
+use Auth;
+
+class LoginController extends Controller
+{
+    private $config;
+
+    public function __construct()
+    {
+        $wechat_app = WechatAppModel::find(1);
+        //dd($wechat_app);
+        $this->config = [
+            'app_id' => $wechat_app->appId,
+            'secret' => $wechat_app->appSecret,
+            'response_type' => 'array',
+        ];
+    }
+
+    /**
+     * @api {post} /api/login 登陆(login)
+     * @apiDescription 登陆(login)login
+     * @apiGroup Login
+     * @apiPermission none
+     * @apiVersion 0.1.0
+     * @apiParam {string}  nickname   手机号码
+     * @apiParam {string} avatar
+     * @apiParam {string} password   password
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+     * {
+     *     "state": true,
+     *     "code": 0,
+     *     "message": {
+     *         "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IjdjYWUyYzFmYTUwMTIyZDI0ZTRiYTZhZGZhNmQxYmZlOWNiMzIxMTBmYWJlZjNjYzIyNmViZjRmNGExNWM3NjllNmU2ZTNiYWE5OGNhOWUzIn0.eyJhdWQiOiIxIiwianRpIjoiN2NhZTJjMWZhNTAxMjJkMjRlNGJhNmFkZmE2ZDFiZmU5Y2IzMjExMGZhYmVmM2NjMjI2ZWJmNGY0YTE1Yzc2OWU2ZTZlM2JhYTk4Y2E5ZTMiLCJpYXQiOjE0NzU0MTE1NTgsIm5iZiI6MTQ3NTQxMTU1OCwiZXhwIjo0NjMxMDg1MTU4LCJzdWIiOiIxIiwic2NvcGVzIjpbXX0.E9YGEzuRUOk02aV1EiWLJ_pD0hKoCyW0k_sGy63hM3u5X8K_HI1kVhaU6JNLqLZeszIAroTEDB8XMgZKAqTLlwtL8PLCJcuDoxfk1BRHbfjhDheTsahBysKGalvNEpzRCrGlao0mS0Cg9qDpEsndtypPFS8sfaflToOzbJjiSK2DvQiHSH8xZI3zHJTezgZMz-pB_hPTxp8ajdv0ve1gWtWjs3vERr0Y91X4hngO8X7LuXtAYtfxGZRIye12YE7TuLBMYzj8CCfiRt7Smhyf4palNW5mzKlZpa2l87n6NQ14Iy4oMzQ2PON1j_swrosuE2yZohGOn6fDdSCBRdJ6dLD_emjBdQCQOoB63R7BbhFZgvFX25TjzFJ7r9AdVMiGmebuRKEVSZV_JCGu1C71OIbQk-UK35s00gSr2fmJGBbN2cZTXBRTJpfuMZ_ihFYEZrvVq_Ih2X0xkd36JUuxaUld1BXRgPZvH-9jBuhe0YW2OOlgwpdm6ZB8BMcuS4ftLoi6FipgzFqfIuy-0ZqPMDnJaG7Gycrdpxza00mgOFxYxJtqwZNsUWFRZEVU881l6VC_cy294YXSPQxUwEoyKg-G5Pm8AEB9bqv5z4EU4B8-XTd3zKNqtNba_snHbc711i4EytCiZfYSjNB1hwenq45YYOAhPTwOpFI0kxyRazc",
+     *         "msg": '登录成功'
+     *     }
+     * }
+     * @apiErrorExample {json} Error-Response:
+     * HTTP/1.1 400 Bad Request
+     * {
+     *     "state": false,
+     *     "code": 1000,
+     *     "message": "传入参数不正确",
+     *     "data": null or []
+     * }
+     * 可能出现的错误代码:
+     *    1000    CLIENT_WRONG_PARAMS             传入参数不正确
+     *    1102    INCORRECT_USER_OR_PASS          用户名或密码不正确
+     */
+    public function login(Request $request)
+    {
+        $data = $request->input();
+        $app = Factory::miniProgram($this->config);
+        $res = $app->auth->session($data['code']);
+        if (!$res || empty($res['openid'])) {
+            $message= [
+                'code' => 1,
+                'msg' => '获取用户OpenId失败',
+                'data' => $res,
+            ];
+            return $this->api($message);
+        }
+        $check_user = UserInfoModel::where('openid',$res['openid'])->first();
+        //dd($check_user);
+        if($check_user && Auth::loginUsingId($check_user->id)) {
+            $user = Auth::user();
+            $success['token'] =  $user->createToken($user->id . '-' . $user->openid)->accessToken;
+            $save['nickname'] = preg_replace('/[\xf0-\xf7].{3}/', '', $data['nickname']);
+            $save['avatar'] = $data['avatar'];
+            $query = UserInfoModel::where('openid',$res['openid'])->update($save);
+            //echo 111;die;
+            if($query){
+                $message = [
+                    'msg'=>'登录成功',
+                    'token'=>$success['token'],
+                ];
+                //dd($message);
+                return $this->api($message);
+            }
+        }else {
+           // dd($res);
+            $add['nickname'] = preg_replace('/[\xf0-\xf7].{3}/', '', $data['nickname']);
+            $add['openid'] = $res['openid'];
+            $add['avatar'] = $data['avatar'];
+            $res_add = UserInfoModel::create($add);
+            if($res_add){
+                $data_user = UserInfoModel::where('openid',$res['openid'])->first();
+                if(Auth::loginUsingId($data_user->id)){
+                    $user = Auth::user();
+                    $success['token'] =  $user->createToken($user->id . '-' . $user->openid)->accessToken;
+                    $message = [
+                        'msg'=>'登录成功',
+                        'token'=>$success['token'],
+                    ];
+                }
+            } else {
+                $message= [
+                    'msg' => '登陆失败',
+                ];
+            }
+            return $this->api($message);
+        }
+    }
+}

+ 236 - 0
app/Http/Controllers/Api/V1/PayController.php

xqd
@@ -0,0 +1,236 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: 思维定制
+ * Date: 2018/7/16
+ * Time: 18:09
+ */
+
+namespace App\Http\Controllers\Api\V1;
+
+
+use App\Models\PaymentInfoModel;
+use App\Models\UserInfoModel;
+use App\Models\WechatAppModel;
+use App\User;
+use EasyWeChat\Factory;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Log;
+use Auth,Validator;
+use App\Services\Base\ErrorCode;
+
+class PayController extends Controller
+{
+    private $config;
+    private $wechat;
+    public function __construct()
+    {
+        parent::__construct();
+        $wechat = WechatAppModel::find(1);
+        $this->wechat = $wechat;
+        $this->config = [
+            // 必要配置
+            'app_id'             => $wechat->appId,
+            'mch_id'             => $wechat->mchId,
+            'key'                => $wechat->key,   // API 密钥0
+
+            // 如需使用敏感接口(如退款、发送红包等)需要配置 API 证书路径(登录商户平台下载 API 证书)
+            //'cert_path'          => public_path().'/pem/', // XXX: 绝对路径!!!!
+            //'key_path'           => public_path().'/pem/',      // XXX: 绝对路径!!!!
+
+            'notify_url'         => '/pay/notify',     // 你也可以在下单时单独设置来想覆盖它
+        ];
+    }
+
+
+    /**
+     * @api {post} /api/pay/recharge 充值(recharge)
+     * @apiDescription 充值(recharge)recharge
+     * @apiGroup Pay
+     * @apiPermission none
+     * @apiVersion 0.1.0
+     * @apiParam {decimal}  price  金额
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+     * {
+     * "status": true,
+     * "status_code": 0,
+     * "message": "",
+     * "data": {
+     *      "json": "{\"appId\":\"wx92066f7587c34617\",\"timeStamp\":\"1532584373\",\"nonceStr\":\"5b5961b537a27\",\"package\":\"prepay_id=wx2613525320101170a0f42d941994171920\",\"signType\":\"MD5\",\"paySign\":\"B4E50A4610F3AC4AE2E12EF2A45D8109\"}"
+     *    }
+     *}
+     * @apiErrorExample {json} Error-Response:
+     * HTTP/1.1 400 Bad Request
+     * {
+     *     "state": false,
+     *     "code": 1000,
+     *     "message": "传入参数不正确",
+     *     "data": null or []
+     * }
+     */
+    public function recharge(Request $request)
+    {
+        $validator = Validator::make($request->all(),
+            [
+                'price' => 'required',
+            ],[
+                'price.required' => 'price不能为空!',
+
+            ]
+        );
+        if ($validator->fails()) {
+            return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
+        }
+        $userAuth = Auth('api')->user();
+        $money = $request->input('price');
+        $trade_no = 'Pay'.date('YmdHis').rand(1000,9999);
+        $order['user_id'] = $userAuth->id;
+        $order['out_trade_no'] = $trade_no;
+        $order['price'] = $money;
+        $order['to_user'] = 0;
+        $order['state'] = 0;
+        $order['msg_id'] = 0;
+        $order['poundage'] = 0;
+        $order['openid'] = $userAuth->openid;
+        $order['type'] = 0;
+        PaymentInfoModel::create($order);
+        $app = Factory::payment($this->config);
+
+        $result = $app->order->unify([
+            'body' => '知识付费充值余额',
+            'out_trade_no' => $trade_no,
+            'total_fee' => $money * 100,
+            'trade_type' => 'JSAPI',
+            'notify_url' => url('/api/home/notify'),
+            'openid' => $userAuth->openid
+        ]);
+        //dd($result);
+
+
+        if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') {
+            $payment = Factory::payment($this->config);
+            $jssdk = $payment->jssdk;
+
+            $json = $jssdk->bridgeConfig($result['prepay_id']);
+            //dd($json);
+            return $this->api(compact('json'));
+        }else{
+            $msg = "签名失败,请稍后再试!";
+
+            return $this->api(compact('msg'));
+        }
+    }
+
+
+//下面是回调函数
+    public function notify()
+    {
+        $app = Factory::payment($this->config);
+        \Log::info("wechat notify start!");
+        $response = $app->handlePaidNotify(function ($notify, $successful) {
+            \Log::info($notify);
+            if ($notify['result_code'] == 'SUCCESS') {
+                $user = UserInfoModel::where('openid',$notify['openid'])->first();
+                $data['order_no'] = $notify['out_trade_no'];
+                $data['price'] = $notify['total_fee'] / 100;
+                $wechat_pay = PaymentInfoModel::where([['user_id',$user->id],['out_trade_no',$notify['out_trade_no']],['state',0]])->first();
+                if($wechat_pay){
+                    $user->money += $data['price'];
+                    $user->save();
+                    $wechat_pay->state = 1;
+                    $wechat_pay->save();
+                }
+            } else {
+                return $successful('通信失败,请稍后再通知我');
+            }
+            return true;
+        });
+        return $response->send();
+    }
+
+
+    /**
+     * @api {post} /api/pay/cash 提现(cash)
+     * @apiDescription 提现(cash)cash
+     * @apiGroup Pay
+     * @apiPermission none
+     * @apiVersion 0.1.0
+     * @apiParam {decimal}  price    金额
+     * @apiParam {string}  name    真实姓名
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+     * {
+     * "status": true,
+     * "status_code": 0,
+     * "message": "",
+     * "data": {
+     *      "msg": "已成功发起提现,请等待后台审核"
+     *    }
+     *}
+     * @apiErrorExample {json} Error-Response:
+     * HTTP/1.1 400 Bad Request
+     * {
+     *     "state": false,
+     *     "code": 1000,
+     *     "message": "传入参数不正确",
+     *     "data": null or []
+     * }
+     */
+
+    public function cash(Request $request)
+    {
+        $validator = Validator::make($request->all(),
+            [
+                'price' => 'required',
+                'name' => 'required',
+            ],[
+                'price.required' => 'price不能为空!',
+                'name.required' => 'name不能为空!'
+            ]
+        );
+        if ($validator->fails()) {
+            return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
+        }
+        $data = $request->input();
+        $userAuth = Auth('api')->user();
+        $trade_no = 'Cash'.date('YmdHis').rand(1000,9999);
+        $poundage = $this->wechat->poundage * $data['price'];
+        $total = $data['price'] + $poundage;
+        if($userAuth->money < $total){
+            $msg = '您的余额不足';
+            return $this->api($msg);
+        }
+        DB::beginTransaction();
+        $user = UserInfoModel::find($userAuth->id);
+        $user->money -= $total;
+        $res = $user->save();
+        if($res){
+            $order['user_id'] = 0;
+            $order['out_trade_no'] = $trade_no;
+            $order['price'] = $data['price'];
+            $order['to_user'] = $userAuth->id;
+            $order['state'] = 0;
+            $order['name'] = $data['name'];
+            $order['msg_id'] = 0;
+            $order['poundage'] = 0;
+            $order['openid'] = $userAuth->openid;
+            $order['type'] = 1;
+            $query = PaymentInfoModel::create($order);
+            if($query){
+                $msg = '已成功发起提现,请等待后台审核';
+                DB::commit();
+            } else {
+                $msg = '提现失败';
+                DB::rollback();
+            }
+        } else {
+            $msg = '提现失败';
+            DB::rollback();
+        }
+        return $this->api($msg);
+
+    }
+
+}

+ 554 - 0
app/Http/Controllers/Api/V1/UserController.php

xqd
@@ -0,0 +1,554 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: 思维定制
+ * Date: 2018/7/13
+ * Time: 15:08
+ */
+
+namespace App\Http\Controllers\Api\V1;
+
+
+use App\Models\FavoriteModel;
+use App\Models\MessagesFollowerModel;
+use App\Models\MessagesInfoModel;
+use App\Models\MessagesTagModel;
+use App\Models\PaymentInfoModel;
+use App\Models\SeenModel;
+use App\Models\UserInfoModel;
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\DB;
+use Validator;
+use App\Services\Base\ErrorCode;
+
+class UserController extends Controller
+{
+
+    /**
+     * @api {post} /api/user/release 发布知识(userRelease)
+     * @apiDescription 发布知识(userRelease)userRelease
+     * @apiGroup User
+     * @apiPermission none
+     * @apiVersion 0.1.0
+     * @apiParam {text}  content    内容
+     * @apiParam {string}  title    标题
+     * @apiParam {number}  price  价格
+     * @apiParam {int}  type  知识类型 1 悬赏 2 付费 0免费
+     * @apiParam {text}  pic_url   图片
+     * @apiParam {array}  tag['id']   标签ID  tag['name']  标签内容
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+     * {
+     * "status": true,
+     * "status_code": 0,
+     * "message": "",
+     * "data": {
+     *      "msg": "添加成功"
+     *    }
+     *}
+     * @apiErrorExample {json} Error-Response:
+     * HTTP/1.1 400 Bad Request
+     * {
+     *     "state": false,
+     *     "code": 1000,
+     *     "message": "传入参数不正确",
+     *     "data": null or []
+     * }
+     */
+    public function userRelease(Request $request)
+    {
+        $validator = Validator::make($request->all(),
+            [
+                'content' => 'required',
+                'type' => 'required',
+                'title' => 'required',
+            ],
+            [
+                'content.required' => '内容不能为空!',
+                'type.required' => 'type不能为空!',
+                'title.required' => '标题不能为空!'
+            ]
+        );
+        if ($validator->fails()) {
+            return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
+        }
+        $userAuth = Auth('api')->user();
+        if(!$userAuth){
+            $msg = 'token已过期,请重新登录';
+            return $this->api($msg);
+        }
+        DB::beginTransaction();
+        $data = $request->input();
+        $tag = $data['tag'];
+        /*$tag[0]['name'] = 'asd';
+        $tag[0]['id'] = 0;
+        $tag[1]['id'] = 0;
+        $tag[1]['name'] = 'dfse';*/
+        $content['content'] = $data['content'];
+        $content['title'] = $data['title'];
+        $content['price'] = $data['price'];
+        $content['type']  = $data['type'];
+        $content['pic_url']  = $data['pic_url'];
+        $content['sort'] = 1;
+        $content['state'] = 0;
+        $user = UserInfoModel::find($userAuth->id);
+        $content['phone'] = $user->mobile;
+        $content['user_id'] = $user->id;
+        $create_res = MessagesInfoModel::create($content);
+        if($data['type'] == 1){
+            $out_trade_no = 'We'.date('YmdHis').rand(1000,9999);
+            $user->money -= $data['price'];
+            if($user->money<0){
+                $msg = '您的余额已不足,请先充值';
+                DB::rollback();
+                return $this->api(compact('msg'));
+            }
+            if(!$user->save()){
+                $msg = '购买失败';
+                DB::rollback();
+                return $this->api(compact('msg'));
+            }
+            $save['openid'] = $user->openid;
+            $save['out_trade_no'] = $out_trade_no;
+            $save['to_user'] = 0;
+            $save['msg_id'] = $create_res->id;
+            $save['user_id'] = $userAuth->id;
+            $save['price'] = $data['price'];
+            $save['type'] = 3;
+            $res = PaymentInfoModel::create($save);
+            if(!$res) {
+                $msg = '购买失败';
+                DB::rollback();
+                return $this->api(compact('msg'));
+            }
+        }
+        foreach($tag as $key=>$val) {
+            if($val['id'] == 0){
+                $save['name'] = $val['name'];
+                $save['sort'] = 0;
+                $res = MessagesTagModel::create($save);
+                $id = $res->id;
+            } else {
+                $id = $val['id'];
+            }
+            $relation['messages_id'] = $create_res->id;
+            $relation['tag_id'] = $id;
+            DB::table('messages_tag_relation')->insert($relation);
+        }
+        $msg = '添加成功';
+        DB::commit();
+        return $this->api(compact('msg'));
+    }
+
+
+    /**
+     * @api {get} /api/user/edit_favorite 添加/删除收藏(userEditFavorite)
+     * @apiDescription 添加/删除收藏(userEditFavorite)userEditFavorite
+     * @apiGroup User
+     * @apiPermission none
+     * @apiVersion 0.1.0
+     * @apiParam {int}  message_id  知识id
+     * @apiParam {int}  type  操作类型 1 添加 0 删除
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+     * {
+     * "status": true,
+     * "status_code": 0,
+     * "message": "",
+     * "data": {
+     *      "msg": "添加成功"
+     *    }
+     *}
+     * @apiErrorExample {json} Error-Response:
+     * HTTP/1.1 400 Bad Request
+     * {
+     *     "state": false,
+     *     "code": 1000,
+     *     "message": "传入参数不正确",
+     *     "data": null or []
+     * }
+     */
+    public function userEditFavorite(Request $request)
+    {
+        $validator = Validator::make($request->all(),
+            [
+                'messages_id' => 'required',
+                'type' => 'required',
+            ],
+            [
+                'messages_id.required' => '信息id不能为空!',
+                'type.required' => 'type不能为空!',
+            ]
+        );
+        if ($validator->fails()) {
+            return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
+        }
+        $userAuth = Auth('api')->user();
+        if(!$userAuth){
+            $msg = 'token已过期,请重新登录';
+            return $this->api($msg);
+        }
+        $data = $request->input();
+        //dd($data);
+        $check = FavoriteModel::where([['user_id',$userAuth->id],['messages_id',$data['messages_id']]])->first();
+        if($data['type'] == 1) {
+            if($check){
+                $msg = '已添加收藏,请勿重复操作';
+                return $this->api(compact('msg'));
+            }
+            $save['user_id'] = $userAuth->id;
+            $save['messages_id'] = $data['messages_id'];
+            $res = FavoriteModel::create($save);
+            if($res){
+                $msg = '添加成功';
+            } else {
+                $msg = '添加失败';
+            }
+            return $this->api(compact('msg'));
+        } else {
+            if(!$check){
+                $msg = '已移除收藏,请勿重复操作';
+                return $this->api(compact('msg'));
+            }
+            $favorite = FavoriteModel::find($check->id);
+            $res = $favorite->delete();
+            if($res){
+                $msg = '删除成功';
+            } else {
+                $msg = '删除失败';
+            }
+            return $this->api(compact('msg'));
+        }
+
+    }
+
+
+    /**
+     * @api {get} /api/user/favorite 添加/删除收藏(userFavorite)
+     * @apiDescription 添加/删除收藏(userFavorite)userFavorite
+     * @apiGroup User
+     * @apiPermission none
+     * @apiVersion 0.1.0
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+     * {
+     * "status": true,
+     * "status_code": 0,
+     * "message": "",
+     * "data": {
+     *       "messages": {
+     *              "id": 1,
+     *              "title": "爱我的",
+     *              "type": 0,
+     *          }
+     *    }
+     *}
+     * @apiErrorExample {json} Error-Response:
+     * HTTP/1.1 400 Bad Request
+     * {
+     *     "state": false,
+     *     "code": 1000,
+     *     "message": "传入参数不正确",
+     *     "data": null or []
+     * }
+     */
+
+    public function userFavorite(Request $request)
+    {
+        $userAuth = Auth('api')->user();
+        if(!$userAuth){
+            $msg = 'token已过期,请重新登录';
+            return $this->api($msg);
+        }
+        $data = FavoriteModel::where('user_id',$userAuth->id)->paginate(5);
+        $messages = array();
+        foreach ($data as $key=>$val){
+            $messages[] = MessagesInfoModel::where('id',$val['messages_id'])->select('id','title','type')->first();
+        }
+        return $this->api(compact('messages'));
+    }
+
+    /**
+     * @api {get} /api/user/my_message 我的发布(userMyMessage)
+     * @apiDescription 我的发布(userMyMessage)userMyMessage
+     * @apiGroup User
+     * @apiPermission none
+     * @apiVersion 0.1.0
+     * @apiParam {int}  state  类型 -1 全部 0 免费 1 悬赏 2 付费
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+     * {
+     * "status": true,
+     * "status_code": 0,
+     * "message": "",
+     * "data": {
+     *       "messages": {
+     *              "id": 1,
+     *              "title": "爱我的",
+     *              "type": 0,
+     *          }
+     *    }
+     *}
+     * @apiErrorExample {json} Error-Response:
+     * HTTP/1.1 400 Bad Request
+     * {
+     *     "state": false,
+     *     "code": 1000,
+     *     "message": "传入参数不正确",
+     *     "data": null or []
+     * }
+     */
+
+    public function userMyMessage(Request $request)
+    {
+        $validator = Validator::make($request->all(),
+            [
+                'state' => 'integer',
+            ],
+            [
+                'state.integer' => 'state参数错误!',
+            ]
+        );
+        if ($validator->fails()) {
+            return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
+        }
+        $userAuth = Auth('api')->user();
+        if(!$userAuth){
+            $msg = 'token已过期,请重新登录';
+            return $this->api($msg);
+        }
+        $state = $request->input('state');
+        if(!empty($state)){
+            $messages = MessagesInfoModel::where([['user_id',$userAuth->id],['type',$state]])->select('id','title','type')->paginate(5);
+        } else {
+            $messages = MessagesInfoModel::where([['user_id',$userAuth->id]])->select('id','title','type')->paginate(5);
+        }
+        return $this->api(compact('messages'));
+    }
+
+    /**
+     * @api {get} /api/user/get_message 我的参与(userGetMessages)
+     * @apiDescription 我的参与(userGetMessages)userGetMessages
+     * @apiGroup User
+     * @apiPermission none
+     * @apiVersion 0.1.0
+     * @apiParam {int}  state  类型 -1 全部 0 免费 1 悬赏 2 付费
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+     * {
+     * "status": true,
+     * "status_code": 0,
+     * "message": "",
+     * "data": {
+     *       "messages": {
+     *              "id": 1,
+     *              "title": "爱我的",
+     *              "type": 0,
+     *          }
+     *    }
+     *}
+     * @apiErrorExample {json} Error-Response:
+     * HTTP/1.1 400 Bad Request
+     * {
+     *     "state": false,
+     *     "code": 1000,
+     *     "message": "传入参数不正确",
+     *     "data": null or []
+     * }
+     */
+
+    public function userGetMessages(Request $request)
+    {
+        $validator = Validator::make($request->all(),
+            [
+                'state' => 'integer',
+            ],
+            [
+                'state.integer' => 'state参数错误!',
+            ]
+        );
+        if ($validator->fails()) {
+            return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
+        }
+        $userAuth = Auth('api')->user();
+        if(!$userAuth){
+            $msg = 'token已过期,请重新登录';
+            return $this->api($msg);
+        }
+        $state = $request->input('state');
+        if(!empty($state)){
+            $messages = MessagesFollowerModel::where([['user_id',$userAuth->id]])->infos()->where('type',$state)->paginate(5);
+        } else {
+            $messages = MessagesFollowerModel::where([['user_id',$userAuth->id]])->infos()->paginate(5);
+        }
+        return $this->api(compact('messages'));
+    }
+
+    /**
+     * @api {get} /api/user/message_detail 我的发布详情(userMessageDetail)
+     * @apiDescription 我的发布详情(userMessageDetail)userMessageDetail
+     * @apiGroup User
+     * @apiPermission none
+     * @apiVersion 0.1.0
+     * @apiParam {int}  id 信息id
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+     * {
+     * "status": true,
+     * "status_code": 0,
+     * "message": "",
+     *      "data": {
+     *          "messages": {
+     *              "id": 1,
+     *              "title": "爱我的",
+     *              "content": "爱我的",
+     *              "user_id": 1,
+     *              "price": 1,
+     *              "phone": "18228068397",
+     *              "comment": "瓦坎达入口",
+     *              "type": 1,
+     *              "sort": 1,
+     *              "deleted_at": null,
+     *              "created_at": "2018-07-12 17:06:23",
+     *              "updated_at": "2018-07-12 17:06:26",
+     *              "state": 0,
+     *              "pic_url": "",
+     *              "followers_num": 1,
+     *              "followers": [
+     *                  {
+     *                      "id": 5,
+     *                      "messages_id": 1,
+     *                      "user_id": 1,
+     *                      "username": "Richod",
+     *                      "mobile": "1111",
+     *                      "deleted_at": null,
+     *                      "created_at": "2018-07-17 09:21:18",
+     *                      "updated_at": "2018-07-17 09:21:18",
+     *                      "state": 0
+     *                      }
+     *                  ],
+     *              "income": ""
+     *            }
+     *      }
+     *}
+     * @apiErrorExample {json} Error-Response:
+     * HTTP/1.1 400 Bad Request
+     * {
+     *     "state": false,
+     *     "code": 1000,
+     *     "message": "传入参数不正确",
+     *     "data": null or []
+     * }
+     */
+
+    public function userMessageDetail(Request $request)
+    {
+        $id = $request->input('id');
+        $messages = MessagesInfoModel::find($id);
+        $messages->followers_num = MessagesFollowerModel::where([['messages_id',$messages->id]])->count();
+        $messages->followers = array();
+        if($messages->type == 1){
+            $followers = MessagesFollowerModel::where([['messages_id',$messages->id]])->get();
+            $messages->followers = $followers;
+            $messages->income = '';
+        }
+
+        if($messages->type == 2){
+            $followers = MessagesFollowerModel::where([['messages_id',$messages->id]])->get();
+            $messages->followers = $followers;
+            $messages->income = $messages->followers_num * $messages->price;
+        }
+
+        if($messages->type == 0) {
+            $messages->followers = '';
+            $messages->income = '';
+        }
+        return $this->api(compact('messages'));
+    }
+
+
+    /**
+     * @api {get} /api/user/complete_message 结束悬赏(userCompleteMessages)
+     * @apiDescription 结束悬赏(userCompleteMessages)userCompleteMessages
+     * @apiGroup User
+     * @apiPermission none
+     * @apiVersion 0.1.0
+     * @apiParam {int}  message_id  知识id
+     * @apiParam {int}  follower_id  悬赏者信息id
+     * @apiParam {int}  type  操作类型 1 添加 0 删除
+     * @apiSuccessExample {json} Success-Response:
+     * HTTP/1.1 200 OK
+     * "data": {
+     *      "code": 1
+     *      "msg": "添加成功"
+     *    }
+     * @apiErrorExample {json} Error-Response:
+     * HTTP/1.1 400 Bad Request
+     * {
+     *     "state": false,
+     *     "code": 1000,
+     *     "message": "传入参数不正确",
+     *     "data": null or []
+     * }
+     */
+
+    public function userCompleteMessages(Request $request)
+    {
+        $validator = Validator::make($request->all(),
+            [
+                'message_id' => 'require|integer',
+                'follower_id' => 'require|integer',
+            ],
+            [
+                'message_id.require|integer' => 'message_id参数错误!',
+                'follower_id.require|integer' => 'follower_id参数错误!',
+            ]
+        );
+        if ($validator->fails()) {
+            return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
+        }
+        $userAuth = Auth('api')->user();
+        if(!$userAuth){
+            $msg = 'token已过期,请重新登录';
+            return $this->api($msg);
+        }
+        $followers_id = $request->input('follower_id');
+        $message_id = $request->input('message_id');
+        $messages_followers = MessagesFollowerModel::find($followers_id);
+        $messages = MessagesInfoModel::where([['id'=>$messages_followers->messages_id],['type',1],['state',0],['user_id',$userAuth->id]])->first();
+        if(!$messages||$message_id!=$messages->id){
+            $data['msg'] = '该知识不存在,或者已完成';
+            $data['code'] = 0;
+            return $this->api($data);
+        }
+        $user = UserInfoModel::find($messages_followers->user_id);
+        $out_trade_no = 'We'.date('YmdHis').rand(1000,9999);
+        $user->money += $messages->price;
+
+        if(!$user->save()){
+            $data['msg'] = '确认失败';
+            $data['code'] = 0;
+            return $this->api($data);
+        }
+        $save['openid'] = $user->openid;
+        $save['out_trade_no'] = $out_trade_no;
+        $save['to_user'] = $messages_followers->user_id;
+        $save['user_id'] = 0;
+        $save['msg_id'] = $messages->id;
+        $save['price'] = $messages->price;
+        $save['type'] = 3;
+        $res = PaymentInfoModel::create($save);
+        if(!$res) {
+            $data['msg'] = '确认失败';
+            $data['code'] = 1;
+        } else {
+            $data['msg'] = '确认成功';
+            $data['code'] = 0;
+        }
+        $messages->state = 1;
+        $messages->save();
+        $messages_followers->state = 1;
+        $messages_followers->save();
+        return $this->api($data);
+    }
+}

+ 13 - 0
app/Http/Controllers/Controller.php

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

+ 38 - 0
app/Http/Controllers/Web/AttachmentController.php

xqd
@@ -0,0 +1,38 @@
+<?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');
+    }
+
+}

+ 23 - 0
app/Http/Controllers/Web/AuthController.php

xqd
@@ -0,0 +1,23 @@
+<?php
+
+namespace App\Http\Controllers\Web;
+
+
+use App\Models\UserInfoModel;
+use Auth;
+
+class AuthController extends Controller
+{
+
+
+    public function test(){
+        $user = UserInfoModel::find(1);
+        Auth::login($user);
+        dd(Auth::user());
+
+//        return $this->error(ErrorCode::SAVE_USER_FAILED);
+        return $this->api(['test' => 'test']);
+    }
+
+
+}

+ 14 - 0
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;
+
+}

+ 20 - 0
app/Http/Controllers/Web/OrderController.php

xqd
@@ -0,0 +1,20 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: 思维定制
+ * Date: 2018/9/5
+ * Time: 18:03
+ */
+
+namespace App\Http\Controllers\Web;
+
+
+class OrderController extends Controller
+{
+    public function index(){
+        return view('web.order.index');
+    }
+    public function post(){
+        return view('web.order.post');
+    }
+}

+ 65 - 0
app/Http/Kernel.php

xqd
@@ -0,0 +1,65 @@
+<?php
+
+namespace App\Http;
+
+use Illuminate\Foundation\Http\Kernel as HttpKernel;
+
+class Kernel extends HttpKernel
+{
+    /**
+     * The application's global HTTP middleware stack.
+     *
+     * These middleware are run during every request to your application.
+     *
+     * @var array
+     */
+    protected $middleware = [
+        \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
+        \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
+        \App\Http\Middleware\TrimStrings::class,
+        \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
+
+        \App\Http\Middleware\Cors::class, //跨域问题
+    ];
+
+    /**
+     * The application's route middleware groups.
+     *
+     * @var array
+     */
+    protected $middlewareGroups = [
+        'web' => [
+            \App\Http\Middleware\EncryptCookies::class,
+            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
+            \Illuminate\Session\Middleware\StartSession::class,
+            // \Illuminate\Session\Middleware\AuthenticateSession::class,
+            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
+            \App\Http\Middleware\VerifyCsrfToken::class,
+            \Illuminate\Routing\Middleware\SubstituteBindings::class,
+        ],
+
+        'api' => [
+            'throttle:60,1',
+            'bindings',
+        ],
+    ];
+
+    /**
+     * The application's route middleware.
+     *
+     * These middleware may be assigned to groups or used individually.
+     *
+     * @var array
+     */
+    protected $routeMiddleware = [
+        'auth' => \App\Http\Middleware\Authenticate::class,
+        'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
+        'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
+        'can' => \Illuminate\Auth\Middleware\Authorize::class,
+        'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
+        'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
+
+        //后台
+        'auth.admin' => \App\Http\Middleware\AuthenticateAdmin::class,
+    ];
+}

+ 34 - 0
app/Http/Middleware/Authenticate.php

xqd
@@ -0,0 +1,34 @@
+<?php
+
+namespace App\Http\Middleware;
+
+use Closure;
+use Illuminate\Support\Facades\Auth;
+
+class Authenticate
+{
+    /**
+     * Handle an incoming request.
+     *
+     * @param  \Illuminate\Http\Request $request
+     * @param  \Closure $next
+     * @param  string|null $guard
+     * @return mixed
+     */
+    public function handle($request, Closure $next, $guard = null)
+    {
+        if(Auth::guard($guard)->guest()) {
+            if($request->ajax()|| $request->wantsJson()||$guard=="api") {
+                \Log::info('Unauthorized Unauthorized ');
+                return response('Unauthorized .', 401);
+            } else {
+                if($guard == 'admin') {
+                    return redirect()->guest('admin/login');
+                }
+                return redirect()->guest('web/login');
+            }
+        }
+
+        return $next($request);
+    }
+}

+ 41 - 0
app/Http/Middleware/AuthenticateAdmin.php

xqd
@@ -0,0 +1,41 @@
+<?php
+
+namespace App\Http\Middleware;
+
+use Closure,Auth;
+
+class AuthenticateAdmin
+{
+    /**
+     * Handle an incoming request.
+     *
+     * @param  \Illuminate\Http\Request $request
+     * @param  \Closure $next
+     * @param  string|null $guard
+     * @return mixed
+     */
+    public function handle($request, Closure $next)
+    {
+        if(Auth::guard('admin')->guest()){
+            exit("你没有登录<a target='_parent' href='/admin/logout?returnUrl=" . urlencode('http://'.$_SERVER['HTTP_HOST']) . "'>请登录</a>");
+        }
+        $path = $request->path();
+        if ($path == 'admin') {
+            $path = str_replace('admin' ,'/', $path);
+        }else{
+            $path = str_replace('admin/' ,'', $path);
+        }
+        $role = session(LOGIN_MARK_SESSION_KEY);
+        $user =Auth::guard('admin')->user();
+        if(!$user['is_root']) {
+            if(!isset($role['role']) || !$role['role']) {
+                exit("你没有操作权限<a target='_parent' href='/admin/logout?returnUrl=" . urlencode('http://'.$_SERVER['HTTP_HOST']) . "'>重新登录</a>");
+            }
+            if(!array_key_exists($path,$role['role'])) {
+                exit("你没有操作权限<a target='_parent' href='/admin/logout?returnUrl=" . urlencode('http://'.$_SERVER['HTTP_HOST']) . "'>重新登录</a>");
+            }
+        }
+
+        return $next($request);
+    }
+}

+ 47 - 0
app/Http/Middleware/Cors.php

xqd
@@ -0,0 +1,47 @@
+<?php
+
+namespace App\Http\Middleware;
+
+use Closure;
+
+class Cors
+{
+    /**
+     * Create a new middleware instance.
+     *
+     * @param \Illuminate\Contracts\Auth\Factory $auth
+     */
+    public function __construct()
+    {
+    }
+
+    /**
+     * Handle an incoming request.
+     *
+     * @param \Illuminate\Http\Request $request
+     * @param \Closure                 $next
+     * @param string|null              $guard
+     *
+     * @return mixed
+     */
+    public function handle($request, Closure $next)
+    {
+        $headers = [
+            'Access-Control-Allow-Origin'      => '*',
+            'Access-Control-Allow-Methods'     => 'GET, HEAD, POST, PUT, DELETE ,OPTIONS',
+            'Access-Control-Allow-Credentials' => 'true',
+            'Access-Control-Max-Age'           => (60 * 60 * 24),
+            'Access-Control-Allow-Headers'     => 'Content-Type, Accept, Authorization, X-Requested-With, Application',
+        ];
+
+        if ($request->isMethod('OPTIONS')) {
+            return response(null, 200, $headers);
+        }
+
+        $response = $next($request);
+        foreach ($headers as $key => $value) {
+            $response->headers->set($key, $value);
+        }
+        return $response;
+    }
+}

+ 17 - 0
app/Http/Middleware/EncryptCookies.php

xqd
@@ -0,0 +1,17 @@
+<?php
+
+namespace App\Http\Middleware;
+
+use Illuminate\Cookie\Middleware\EncryptCookies as BaseEncrypter;
+
+class EncryptCookies extends BaseEncrypter
+{
+    /**
+     * The names of the cookies that should not be encrypted.
+     *
+     * @var array
+     */
+    protected $except = [
+        //
+    ];
+}

+ 26 - 0
app/Http/Middleware/RedirectIfAuthenticated.php

xqd
@@ -0,0 +1,26 @@
+<?php
+
+namespace App\Http\Middleware;
+
+use Closure;
+use Illuminate\Support\Facades\Auth;
+
+class RedirectIfAuthenticated
+{
+    /**
+     * Handle an incoming request.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @param  \Closure  $next
+     * @param  string|null  $guard
+     * @return mixed
+     */
+    public function handle($request, Closure $next, $guard = null)
+    {
+        if (Auth::guard($guard)->check()) {
+            return redirect('/home');
+        }
+
+        return $next($request);
+    }
+}

+ 18 - 0
app/Http/Middleware/TrimStrings.php

xqd
@@ -0,0 +1,18 @@
+<?php
+
+namespace App\Http\Middleware;
+
+use Illuminate\Foundation\Http\Middleware\TrimStrings as BaseTrimmer;
+
+class TrimStrings extends BaseTrimmer
+{
+    /**
+     * The names of the attributes that should not be trimmed.
+     *
+     * @var array
+     */
+    protected $except = [
+        'password',
+        'password_confirmation',
+    ];
+}

+ 20 - 0
app/Http/Middleware/VerifyCsrfToken.php

xqd
@@ -0,0 +1,20 @@
+<?php
+
+namespace App\Http\Middleware;
+
+use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;
+
+class VerifyCsrfToken extends BaseVerifier
+{
+    /**
+     * The URIs that should be excluded from CSRF verification.
+     *
+     * @var array
+     */
+    protected $except = [
+        //
+        "notify",
+        "admin/Base/Attachment/*"
+    ];
+
+}

+ 89 - 0
app/Models/AccountLog.php

xqd
@@ -0,0 +1,89 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+class AccountLog extends Model
+{
+    public $table = 'account_logs';
+
+    //交易行为定义
+    const OP_CHARGE         = 'CHARGE';
+    const OP_REMOVE_M       = 'REMOVE_M';
+    const OP_CHARGE_M       = 'CHARGE_M';
+    const OP_CHARGE_M_GIFT  = 'CHARGE_M_GIFT';
+    const OP_CC             = 'CC';
+    const OP_CC_BONUS       = 'CC_BONUS';
+    const OP_CONSUME        = 'CONSUME';
+    const OP_WITHDRAW       = 'WITHDRAW';
+    const OP_CHANGE         = 'CHANGE';
+
+    //货币类型定义
+    const TYPE_BALANCE      = 1;
+    const TYPE_COIN       = 2;
+    const TYPE_CASH         = 3;
+
+    //交易渠道定义
+    const CHANNEL_PLATFORM  = 'platform';
+    const CHANNEL_ALIPAY    = 'alipay';
+    const CHANNEL_WECHATPAY = 'wechatpay';
+
+    //交易方向
+    const DIRECTION_INC     = 1; //增加
+    const DIRECTION_DEC     = 2; //减少
+
+    //交易行为枚举
+    private static $_op = [
+        self::OP_CHARGE         => '充值',
+        self::OP_REMOVE_M       => '商户给会员扣除',
+        self::OP_CHARGE_M       => '商户给会员充值',
+        self::OP_CHARGE_M_GIFT  => '商户充值赠送',
+        self::OP_CC             => '续消',
+        self::OP_CC_BONUS       => '续消分成',
+        self::OP_CONSUME        => '消耗',
+        self::OP_WITHDRAW       => '提现',
+        self::OP_CHANGE         => '卡金换余额',
+    ];
+
+    //货币类型枚举
+    private static $_type = [
+        self::TYPE_BALANCE      => '余额',
+        self::TYPE_CREDIT       => '卡金',
+        self::TYPE_CASH         => '现金',
+        self::TYPE_BALANCE_M    => '商户余额',
+    ];
+
+    //交易渠道枚举
+    private static $_channels = [
+        self::CHANNEL_PLATFORM  => '平台内交易',
+        self::CHANNEL_ALIPAY    => '支付宝',
+        self::CHANNEL_WECHATPAY => '微信支付',
+    ];
+
+    // 交易流向
+    private static $_direction = [
+        self::DIRECTION_INC => '收入',
+        self::DIRECTION_DEC => '支出'
+    ];
+
+    // 获取所有操作
+    public static function getAllop() {
+        return self::$_op;
+    }
+
+    // 获取所有类型
+    public static function getAllType() {
+        return self::$_type;
+    }
+
+    //获取所有渠道
+    public static function getAllChannels() {
+        return self::$_channels;
+    }
+
+    // 获取交易流向
+    public static function getAllDirections() {
+        return self::$_direction;
+    }
+}

+ 74 - 0
app/Models/AdminAccessModel.php

xqd
@@ -0,0 +1,74 @@
+<?php
+namespace App\Models;
+use App\Models\BaseModel;
+/**
+ *  @description 权限表
+ *  @author  wangzhoudong  <admin@yijinba.com>;
+ *  @version    1.0
+ *  @date 2015-11-13
+ *
+ */
+class AdminAccessModel extends BaseModel
+{
+    /**
+     * 数据表名
+     * 
+     * @var string
+     *
+     */
+    protected $table = 'admin_access';
+    /**
+                主键
+     */
+    protected $primaryKey = 'id';
+
+    //分页
+    protected $perPage = PAGE_NUMS;
+    
+    /**
+     * 可以被集体附值的表的字段
+     *
+     * @var string
+     */
+    protected $fillable = [
+        'role_id',
+        'menu_id'
+    ];
+    
+    public function menus() {
+        return $this->hasOne('App\Models\AdminMenusModel','id','menu_id');
+    }
+    
+    public $timestamps = false;
+    /**
+     * 取得用户组的权限信息
+     * 
+     * @param intval $groupId
+     * @return array
+     */
+    public function getRoleAccessMenu($roleIds,$isMenu = false)
+    {
+        if(is_string($roleIds)) {
+            $roleIds = explode(',', $roleIds);
+        }
+        $info = $this->select('admin_menus.id',
+                               'admin_menus.pid',
+                              'admin_menus.path',
+                            'admin_menus.name',
+                             'admin_menus.ico',
+                             'admin_menus.display',
+                            'admin_menus.sort')
+                     ->leftJoin('admin_menus', 'admin_access.menu_id', '=', 'admin_menus.id')
+                     ->leftjoin("admin_roles","admin_access.role_id","=","admin_roles.id")
+                    ->whereIn('role_id',$roleIds)
+                    ->where("admin_roles.status",1);
+        if($isMenu) {
+            $info = $info->where("admin_menus.display",1);
+        }
+        $info = $info
+                     ->orderBy('admin_menus.sort', 'desc')->orderBy('admin_menus.id', 'asc')
+                     ->groupby(\DB::raw("admin_menus.id"))
+                     ->get();
+        return $info->toArray();
+    }
+}

+ 41 - 0
app/Models/AdminMenusModel.php

xqd
@@ -0,0 +1,41 @@
+<?php
+/**
+ *------------------------------------------------------
+ * AdminMenusModel.php
+ *------------------------------------------------------
+ *
+ * @author    m@9026.com
+ * @date      2017/03/20 11:43
+ * @version   V1.0
+ *
+ */
+
+namespace App\Models;
+
+class AdminMenusModel extends BaseModel
+{
+    /**
+     * 数据表名
+     */
+    protected $table = "admin_menus";
+
+    /**
+     * 主键
+     */
+    protected $primaryKey = "id";
+
+    /**
+     * 可以被集体附值的表的字段
+     */
+    protected $fillable = [
+        'pid',
+        'path',
+        'name',
+        'display',
+        'sort',
+        'level',
+        'ico',
+        'mark'
+    ];
+
+}

+ 38 - 0
app/Models/AdminRoleModel.php

xqd
@@ -0,0 +1,38 @@
+<?php
+/**
+ *------------------------------------------------------
+ * AdminRoleModel.php
+ *------------------------------------------------------
+ *
+ * @author    m@9026.com
+ * @date      2017/03/20 11:43
+ * @version   V1.0
+ *
+ */
+
+namespace App\Models;
+
+class AdminRoleModel extends BaseModel
+{
+    /**
+     * 数据表名
+     */
+    protected $table = "admin_roles";
+
+    /**
+     * 主键
+     */
+    protected $primaryKey = "id";
+
+    /**
+     * 可以被集体附值的表的字段
+     */
+    protected $fillable = [
+        'name',
+        'mark',
+        'status',
+        'level',
+        'department_id'
+    ];
+
+}

+ 46 - 0
app/Models/AdminUserModel.php

xqd
@@ -0,0 +1,46 @@
+<?php
+/**
+ *------------------------------------------------------
+ * AdminUserModel.php
+ *------------------------------------------------------
+ *
+ * @author    m@9026.com
+ * @date      2017/03/21 10:15
+ * @version   V1.0
+ *
+ */
+
+namespace App\Models;
+
+use Illuminate\Foundation\Auth\User as Authenticatable;
+
+class AdminUserModel extends Authenticatable
+{
+    /**
+     * 数据表名
+     */
+    protected $table = "admin_users";
+
+    /**
+     * 主键
+     */
+    protected $primaryKey = "id";
+
+    /**
+     * 可以被集体附值的表的字段
+     */
+    protected $fillable = [
+        'name',
+        'real_name',
+        'password',
+        'email',
+        'mobile',
+        'avatar',
+        'type',
+        'last_login_time',
+        'status',
+        'is_root',
+        'admin_role_id'
+    ];
+
+}

+ 43 - 0
app/Models/BaseAreaModel.php

xqd
@@ -0,0 +1,43 @@
+<?php
+/**
+ *------------------------------------------------------
+ * BaseAreaModel.php
+ *------------------------------------------------------
+ *
+ * @author    m@9026.com
+ * @date      2017/03/20 13:09
+ * @version   V1.0
+ *
+ */
+
+namespace App\Models;
+
+class BaseAreaModel extends BaseModel
+{
+    /**
+     * 数据表名
+     */
+    protected $table = "base_area";
+
+    /**
+     * 主键
+     */
+    protected $primaryKey = "id";
+
+    /**
+     * 可以被集体附值的表的字段
+     */
+    protected $fillable = [
+        'name',
+        'pid',
+        'short_name',
+        'grade',
+        'city_code',
+        'zip_code',
+        'merger_name',
+        'lng',
+        'lat',
+        'pinyin'
+    ];
+
+}

+ 32 - 0
app/Models/BaseAttachmentModel.php

xqd
@@ -0,0 +1,32 @@
+<?php
+/**
+ *------------------------------------------------------
+ * BaseAttachmentModel.php
+ *------------------------------------------------------
+ *
+ * @author    m@9026.com
+ * @date      2017/03/20 13:09
+ * @version   V1.0
+ *
+ */
+
+namespace App\Models;
+
+class BaseAttachmentModel extends BaseModel
+{
+    //
+    /**
+     * 数据表名
+     *
+     * @var string
+     *
+     */
+    protected $table = 'base_attachments';
+    /**
+    主键
+     */
+    protected $primaryKey = 'id';
+
+    //分页
+    protected $perPage = PAGE_NUMS;
+}

+ 40 - 0
app/Models/BaseDictionaryModel.php

xqd
@@ -0,0 +1,40 @@
+<?php
+/**
+ *------------------------------------------------------
+ * BaseDictionaryOptionModel.php
+ *------------------------------------------------------
+ *
+ * @author    m@9026.com
+ * @date      2017/03/20 13:09
+ * @version   V1.0
+ *
+ */
+
+namespace App\Models;
+
+class BaseDictionaryModel extends BaseModel
+{
+    /**
+     * 数据表名
+     */
+    protected $table = "base_dictionary";
+
+    /**
+     * 主键
+     */
+    protected $primaryKey = "id";
+
+    /**
+     * 可以被集体附值的表的字段
+     */
+    protected $fillable = [
+        'dictionary_table_code',
+        'dictionary_code',
+        'key',
+        'value',
+        'name',
+        'input_code',
+        'sort'
+    ];
+
+}

+ 41 - 0
app/Models/BaseModel.php

xqd
@@ -0,0 +1,41 @@
+<?php
+/**
+ *------------------------------------------------------
+ * Model层基类
+ *------------------------------------------------------
+ *
+ * @author    qqiu@qq.com
+ * @date      2016/05/26 09:22
+ * @version   V1.0
+ *
+ */
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Model;
+
+class BaseModel extends Model
+{
+    /**
+     * 维护数据表中 created_at 和 updated_at 字段
+     */
+    public $timestamps = true;
+
+    /**
+     * 多个Where
+     * @param Object $query
+     * @param array $arr ['status' => 1, 'type' => 2]
+     * @return Object $query
+     */
+    public function multiwhere($query, $arr)
+    {
+        if ( !is_array($arr) ) {
+            return $query;
+        }
+        foreach ($arr as $key => $value) {
+            $query = $query->where($key, $value);
+        }
+        return $query;
+    }
+
+}

+ 22 - 0
app/Models/ClassModel.php

xqd
@@ -0,0 +1,22 @@
+<?php
+
+namespace App\Models;
+use App\Models\BaseModel;
+
+class ClassModel extends BaseModel
+{
+    /**
+     * 数据表名
+     *
+     * @var string
+     *
+     */
+    protected $table = 'classes';
+    /**
+    主键
+     */
+    protected $primaryKey = 'id';
+
+    //分页
+    protected $perPage = PAGE_NUMS;
+}

+ 44 - 0
app/Models/FavoriteModel.php

xqd
@@ -0,0 +1,44 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: 思维定制
+ * Date: 2018/7/13
+ * Time: 17:52
+ */
+
+namespace App\Models;
+
+
+
+use Illuminate\Database\Eloquent\SoftDeletes;
+
+class FavoriteModel extends BaseModel
+{
+    use SoftDeletes;
+    protected $dates = ['delete_at'];
+
+    /**
+     * 数据表名
+     *
+     * @var string
+     *
+     */
+    protected $table = 'favorite';
+    /**
+     * 主键
+     */
+    protected $primaryKey = 'id';
+
+    //分页
+    protected $perPage = PAGE_NUMS;
+
+    /**
+     * 可以被集体附值的表的字段
+     *
+     * @var string
+     */
+    protected $fillable = [
+        'messages_id',
+        'user_id'
+    ];
+}

+ 49 - 0
app/Models/MessagesFollowerModel.php

xqd
@@ -0,0 +1,49 @@
+<?php
+
+namespace App\Models;
+
+use App\Models\BaseModel;
+
+/**
+ * @description 标签列表
+ * @author  system;
+ * @version    1.0
+ * @date 2018-07-11 06:51:31
+ *
+ */
+class MessagesFollowerModel extends BaseModel
+{
+    /**
+     * 数据表名
+     *
+     * @var string
+     *
+     */
+    protected $table = 'messages_followers';
+    /**
+     * 主键
+     */
+    protected $primaryKey = 'id';
+
+    //分页
+    protected $perPage = PAGE_NUMS;
+
+    /**
+     * 可以被集体附值的表的字段
+     *
+     * @var string
+     */
+    protected $fillable = [
+        'site_id',
+        'messages_id',
+        'user_id',
+        'username',
+        'mobile',
+        'state'
+    ];
+
+    public function infos()
+    {
+        return $this->belongsTo('App\Models\MessagesInfoModel',  'messages_id', 'id');
+    }
+}

+ 56 - 0
app/Models/MessagesInfoModel.php

xqd
@@ -0,0 +1,56 @@
+<?php
+
+namespace App\Models;
+
+use App\Models\BaseModel;
+use Illuminate\Database\Eloquent\SoftDeletes;
+
+/**
+ * @description 信息列表
+ * @author  system;
+ * @version    1.0
+ * @date 2018-07-11 06:50:54
+ *
+ */
+class MessagesInfoModel extends BaseModel
+{
+    use SoftDeletes;
+    /**
+     * 数据表名
+     *
+     * @var string
+     *
+     */
+    protected $table = 'messages_info';
+    /**
+     * 主键
+     */
+    protected $primaryKey = 'id';
+
+    //分页
+    protected $perPage = PAGE_NUMS;
+
+    /**
+     * 可以被集体附值的表的字段
+     *
+     * @var string
+     */
+    protected $fillable = [
+        'site_id',
+        'title',
+        'content',
+        'user_id',
+        'price',
+        'phone',
+        'comment',
+        'type',
+        'sort',
+        'pic_url'
+    ];
+
+    public function tags()
+    {
+        return $this->belongsToMany('App\Models\MessagesTagModel', 'messages_tag_relation', 'messages_id', 'tag_id');
+    }
+
+}

+ 45 - 0
app/Models/MessagesTagModel.php

xqd
@@ -0,0 +1,45 @@
+<?php
+namespace App\Models;
+use App\Models\BaseModel;
+/**
+ *  @description 标签列表
+ *  @author  system;
+ *  @version    1.0
+ *  @date 2018-07-11 06:51:31
+ *
+ */
+class MessagesTagModel extends BaseModel
+{
+    /**
+     * 数据表名
+     *
+     * @var string
+     *
+     */
+    protected $table = 'messages_tag';
+    /**
+    主键
+     */
+    protected $primaryKey = 'id';
+
+    //分页
+    protected $perPage = PAGE_NUMS;
+
+    /**
+     * 可以被集体附值的表的字段
+     *
+     * @var string
+     */
+    protected $fillable = [
+                           'site_id',
+                           'name',
+                           'sort'
+                          ];
+
+
+    public function messgaes()
+    {
+        return $this->belongsToMany('App\Models\MessagesInfoModel', 'messages_tag_relation',  'tag_id', 'messages_id');
+    }
+
+}

+ 42 - 0
app/Models/MessagesTagRelationModel.php

xqd
@@ -0,0 +1,42 @@
+<?php
+
+namespace App\Models;
+
+use App\Models\BaseModel;
+
+/**
+ * @description 标签列表
+ * @author  system;
+ * @version    1.0
+ * @date 2018-07-11 06:51:31
+ *
+ */
+class MessagesTagRelationModel extends BaseModel
+{
+    /**
+     * 数据表名
+     *
+     * @var string
+     *
+     */
+    protected $table = 'messages_tag_relation';
+    /**
+     * 主键
+     */
+    protected $primaryKey = 'id';
+
+    //分页
+    protected $perPage = PAGE_NUMS;
+
+    /**
+     * 可以被集体附值的表的字段
+     *
+     * @var string
+     */
+    protected $fillable = [
+        'site_id',
+        'messages_id',
+        'tag_id'
+    ];
+
+}

+ 52 - 0
app/Models/PaymentInfoModel.php

xqd
@@ -0,0 +1,52 @@
+<?php
+
+namespace App\Models;
+
+use App\Models\BaseModel;
+use Illuminate\Database\Eloquent\SoftDeletes;
+
+/**
+ * @description 支付列表
+ * @author  system;
+ * @version    1.0
+ * @date 2018-07-11 06:53:04
+ *
+ */
+class PaymentInfoModel extends BaseModel
+{
+    use SoftDeletes;
+    /**
+     * 数据表名
+     *
+     * @var string
+     *
+     */
+    protected $table = 'payment_info';
+    /**
+     * 主键
+     */
+    protected $primaryKey = 'id';
+
+    //分页
+    protected $perPage = PAGE_NUMS;
+
+    /**
+     * 可以被集体附值的表的字段
+     *
+     * @var string
+     */
+    protected $fillable = [
+        'site_id',
+        'user_id',
+        'openid',
+        'out_trade_no',
+        'price',
+        'type',
+        'msg_id',
+        'to_user',
+        'state',
+        'poundage',
+        'name'
+    ];
+
+}

+ 50 - 0
app/Models/UserInfoModel.php

xqd
@@ -0,0 +1,50 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\SoftDeletes;
+use Illuminate\Foundation\Auth\User as Authenticatable;
+use Laravel\Passport\HasApiTokens;
+use Illuminate\Notifications\Notifiable;
+/**
+ * @description 用户表
+ * @author  system;
+ * @version    1.0
+ * @date 2017-05-30 12:16:56
+ *
+ */
+class UserInfoModel extends Authenticatable
+{
+    use HasApiTokens, Notifiable;
+    use SoftDeletes;
+    /**
+     * 数据表名
+     *
+     * @var string
+     *
+     */
+    protected $table = 'user_info';
+    /**W
+     * 主键
+     */
+    protected $primaryKey = 'id';
+
+    //分页
+    protected $perPage = PAGE_NUMS;
+
+    /**
+     * 可以被集体附值的表的字段
+     *
+     * @var string
+     */
+    protected $fillable = [
+        'nickname',
+        'openid',
+        'mobile',
+        'avatar',
+        'lost_login_time',
+        'remember_token',
+        'money'
+    ];
+
+}

+ 41 - 0
app/Models/WechatAppModel.php

xqd
@@ -0,0 +1,41 @@
+<?php
+namespace App\Models;
+use App\Models\BaseModel;
+/**
+ *  @description 11
+ *  @author  system;
+ *  @version    1.0
+ *  @date 2018-07-26 01:43:25
+ *
+ */
+class WechatAppModel extends BaseModel
+{
+    /**
+     * 数据表名
+     *
+     * @var string
+     *
+     */
+    protected $table = 'wechat_app';
+    /**
+    主键
+     */
+    protected $primaryKey = 'id';
+
+    //分页
+    protected $perPage = PAGE_NUMS;
+
+    /**
+     * 可以被集体附值的表的字段
+     *
+     * @var string
+     */
+    protected $fillable = [
+                           'appId',
+                           'appSecret',
+                           'mchId',
+                           'key',
+                           'poundage'
+                          ];
+
+}

+ 28 - 0
app/Providers/AppServiceProvider.php

xqd
@@ -0,0 +1,28 @@
+<?php
+
+namespace App\Providers;
+
+use Illuminate\Support\ServiceProvider;
+
+class AppServiceProvider extends ServiceProvider
+{
+    /**
+     * Bootstrap any application services.
+     *
+     * @return void
+     */
+    public function boot()
+    {
+        //
+    }
+
+    /**
+     * Register any application services.
+     *
+     * @return void
+     */
+    public function register()
+    {
+        //
+    }
+}

+ 31 - 0
app/Providers/AuthServiceProvider.php

xqd
@@ -0,0 +1,31 @@
+<?php
+
+namespace App\Providers;
+
+use Illuminate\Support\Facades\Gate;
+use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
+use Laravel\Passport\Passport;
+
+class AuthServiceProvider extends ServiceProvider
+{
+    /**
+     * The policy mappings for the application.
+     *
+     * @var array
+     */
+    protected $policies = [
+        'App\Model' => 'App\Policies\ModelPolicy',
+    ];
+
+    /**
+     * Register any authentication / authorization services.
+     *
+     * @return void
+     */
+    public function boot()
+    {
+        $this->registerPolicies();
+        Passport::routes();
+        //
+    }
+}

+ 21 - 0
app/Providers/BroadcastServiceProvider.php

xqd
@@ -0,0 +1,21 @@
+<?php
+
+namespace App\Providers;
+
+use Illuminate\Support\ServiceProvider;
+use Illuminate\Support\Facades\Broadcast;
+
+class BroadcastServiceProvider extends ServiceProvider
+{
+    /**
+     * Bootstrap any application services.
+     *
+     * @return void
+     */
+    public function boot()
+    {
+        Broadcast::routes();
+
+        require base_path('routes/channels.php');
+    }
+}

+ 32 - 0
app/Providers/EventServiceProvider.php

xqd
@@ -0,0 +1,32 @@
+<?php
+
+namespace App\Providers;
+
+use Illuminate\Support\Facades\Event;
+use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
+
+class EventServiceProvider extends ServiceProvider
+{
+    /**
+     * The event listener mappings for the application.
+     *
+     * @var array
+     */
+    protected $listen = [
+        'App\Events\SomeEvent' => [
+            'App\Listeners\EventListener',
+        ],
+    ];
+
+    /**
+     * Register any events for your application.
+     *
+     * @return void
+     */
+    public function boot()
+    {
+        parent::boot();
+
+        //
+    }
+}

+ 82 - 0
app/Providers/RouteServiceProvider.php

xqd
@@ -0,0 +1,82 @@
+<?php
+
+namespace App\Providers;
+
+use Illuminate\Support\Facades\Route;
+use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
+
+class RouteServiceProvider extends ServiceProvider
+{
+    /**
+     * This namespace is applied to your controller routes.
+     *
+     * In addition, it is set as the URL generator's root namespace.
+     *
+     * @var string
+     */
+    protected $namespace = 'App\Http\Controllers';
+
+    /**
+     * Define your route model bindings, pattern filters, etc.
+     *
+     * @return void
+     */
+    public function boot()
+    {
+        //
+
+        parent::boot();
+    }
+
+    /**
+     * Define the routes for the application.
+     *
+     * @return void
+     */
+    public function map()
+    {
+        $this->mapApiRoutes();
+
+        $this->mapWebRoutes();
+
+        //后台路由
+        $this->mapAdminRoutes();
+    }
+
+    public function mapAdminRoutes()
+    {
+        Route::prefix('admin')
+            ->middleware('web')
+            ->namespace($this->namespace. '\Admin')
+            ->group(base_path('routes/admin.php'));
+    }
+
+    /**
+     * Define the "web" routes for the application.
+     *
+     * These routes all receive session state, CSRF protection, etc.
+     *
+     * @return void
+     */
+    protected function mapWebRoutes()
+    {
+        Route::middleware('web')
+             ->namespace($this->namespace)
+             ->group(base_path('routes/web.php'));
+    }
+
+    /**
+     * Define the "api" routes for the application.
+     *
+     * These routes are typically stateless.
+     *
+     * @return void
+     */
+    protected function mapApiRoutes()
+    {
+        Route::prefix('api')
+             ->middleware('api')
+             ->namespace($this->namespace)
+             ->group(base_path('routes/api.php'));
+    }
+}

+ 14 - 0
app/Repositories/Base/Criteria.php

xqd
@@ -0,0 +1,14 @@
+<?php
+namespace App\Repositories\Base;
+
+use App\Repositories\Contracts\RepositoryInterface as BaseRepository;
+
+abstract class Criteria {
+
+    /**
+     * @param $model
+     * @param Repository $repository
+     * @return mixed
+     */
+    public abstract function apply($model, BaseRepository $repository);
+}

+ 45 - 0
app/Repositories/Base/Criteria/MultiWhere.php

xqd
@@ -0,0 +1,45 @@
+<?php
+/**
+ * User: Mike
+ * Email: m@9026.com
+ * Date: 2017/1/12
+ * Time: 17:52
+ */
+
+namespace App\Repositories\Base\Criteria;
+
+
+
+
+use App\Repositories\Base\Criteria;
+use App\Repositories\Contracts\RepositoryInterface as Repository;
+
+class MultiWhere extends Criteria {
+
+    private $search = [];
+
+    /**
+     * MultiWhere constructor.
+     * @param array $search
+     *
+     */
+    public function __construct(array $search)
+    {
+        $this->search = $search;
+    }
+
+    /**
+    * @param $model
+    * @param RepositoryInterface $repository
+    * @return mixed
+    */
+    public function apply($model, Repository $repository)
+    {
+          if(isset($this->search['deleted_at']) && $this->search['deleted_at']) {
+                                    $model = $model->where('deleted_at',$this->search['deleted_at']);
+                                 }
+
+         return $model;
+    }
+
+}

+ 52 - 0
app/Repositories/Base/Criteria/OrderBy.php

xqd
@@ -0,0 +1,52 @@
+<?php
+/**
+ * User: Mike
+ * Email: m@9026.com
+ * Date: 2017/1/12
+ * Time: 17:52
+ */
+
+namespace App\Repositories\Base\Criteria;
+
+
+
+
+use App\Repositories\Base\Criteria;
+use App\Repositories\Contracts\RepositoryInterface as Repository;
+
+class OrderBy extends Criteria {
+
+    private $field = '';
+    private $sort = 'ASC';
+
+    /**
+     * MultiWhere constructor.
+     * @param array $search
+     *
+     *               id  商品ID
+     *               name 商品名称(模糊查询)
+     *               cate_id 分类ID
+     *               store_id 商家ID
+     *               store_name 商家名称(模糊查询)
+     *
+     *
+     *
+     */
+    public function __construct($field,$sort="ASC")
+    {
+        $this->field = $field;
+        $this->sort = $sort;
+    }
+
+    /**
+     * @param $model
+     * @param RepositoryInterface $repository
+     * @return mixed
+     */
+    public function apply($model, Repository $repository)
+    {
+        $model = $model->orderBy($this->field,$this->sort);
+        return $model;
+    }
+
+}

+ 21 - 0
app/Repositories/Base/DictionaryRepository.php

xqd
@@ -0,0 +1,21 @@
+<?php
+/**
+ *   字典管理
+ *  @author  system
+ *  @version    1.0
+ *  @date 2018-06-12 10:14:19
+ *
+ */
+namespace App\Repositories\Base;
+
+use App\Repositories\Base\Repository;
+
+
+class DictionaryRepository extends Repository {
+
+    public function model() {
+        return \App\Models\BaseDictionaryModel::class;
+    }
+
+    
+}

+ 358 - 0
app/Repositories/Base/Repository.php

xqd
@@ -0,0 +1,358 @@
+<?php
+
+namespace App\Repositories\Base;
+
+use Illuminate\Support\Collection;
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Container\Container as App;
+use App\Repositories\Contracts\RepositoryInterface;
+use App\Repositories\Exceptions\RepositoryException;
+use App\Repositories\Contracts\CriteriaInterface;
+use App\Repositories\Base\Criteria;
+
+/**
+ * Class Repository
+ * @package Bosnadev\Repositories\Eloquent
+ */
+abstract class Repository implements RepositoryInterface, CriteriaInterface
+{
+
+    /**
+     * @var App
+     */
+    private $app;
+
+    /**
+     * @var Model
+     */
+    protected $model;
+
+    protected $newModel;
+
+    /**
+     * @var Collection
+     */
+    protected $criteria;
+
+    /**
+     * @var bool
+     */
+    protected $skipCriteria = false;
+
+    /**
+     * Prevents from overwriting same criteria in chain usage
+     * @var bool
+     */
+    protected $preventCriteriaOverwriting = true;
+
+    /**
+     * @param App $app
+     * @param Collection $collection
+     * @throws Exceptions\RepositoryException
+     */
+    public function __construct(App $app, Collection $collection)
+    {
+        $this->app = $app;
+        $this->criteria = $collection;
+        $this->resetScope();
+        $this->makeModel();
+    }
+
+    /**
+     * Specify Model class name
+     *
+     * @return mixed
+     */
+    public abstract function model();
+
+    /**
+     * @param array $columns
+     * @return mixed
+     */
+    public function all($columns = array('*'))
+    {
+        $this->applyCriteria();
+        return $this->model->get($columns);
+    }
+
+    /**
+     * @param array $relations
+     * @return $this
+     */
+    public function with(array $relations)
+    {
+        $this->model = $this->model->with($relations);
+        return $this;
+    }
+
+    /**
+     * @param  string $value
+     * @param  string $key
+     * @return array
+     */
+    public function lists($value, $key = null)
+    {
+        $this->applyCriteria();
+        $lists = $this->model->lists($value, $key);
+        if (is_array($lists)) {
+            return $lists;
+        }
+        return $lists->all();
+    }
+
+    /**
+     * @param int $perPage
+     * @param array $columns
+     * @return mixed
+     */
+    public function paginate($perPage = 25, $columns = array('*'))
+    {
+        $this->applyCriteria();
+        return $this->model->paginate($perPage, $columns);
+    }
+
+    /**
+     * @param array $data
+     * @return mixed
+     */
+    public function create(array $data)
+    {
+        return $this->model->create($data);
+    }
+
+    /**
+     * save a model without massive assignment
+     *
+     * @param array $data
+     * @return bool
+     */
+    public function saveModel(array $data)
+    {
+        foreach ($data as $k => $v) {
+            $this->model->$k = $v;
+        }
+        return $this->model->save();
+    }
+
+    /**
+     * @param array $data
+     * @param $id
+     * @param string $attribute
+     * @return mixed
+     */
+    public function update($id,array $data, $attribute = "id")
+    {
+        return $this->model->where($attribute, '=', $id)->update($data);
+    }
+
+    /**
+     * @param  array $data
+     * @param  $id
+     * @return mixed
+     */
+    public function updateRich( $id,array $data)
+    {
+        if (!($model = $this->model->find($id))) {
+            return false;
+        }
+
+        return $model->fill($data)->save();
+    }
+
+    /**
+     * @param $id
+     * @return mixed
+     */
+    public function delete($id)
+    {
+        return $this->model->destroy($id);
+    }
+    /**
+     * @param $id
+     * @return mixed
+     */
+    public function destroy($id)
+    {
+        $data = $this->model->find($id);
+        if ( $data->delete()) {
+            return true;
+        }else
+            return false;
+    }
+    /**
+     * @param $id
+     * @param array $columns
+     * @return mixed
+     */
+    public function find($id, $columns = array('*'))
+    {
+        $this->applyCriteria();
+        return $this->model->find($id, $columns);
+    }
+
+    /**
+     * @param $attribute
+     * @param $value
+     * @param array $columns
+     * @return mixed
+     */
+    public function findBy($attribute, $value, $columns = array('*'))
+    {
+        $this->applyCriteria();
+        return $this->model->where($attribute, '=', $value)->first($columns);
+    }
+
+    /**
+     * @param $attribute
+     * @param $value
+     * @param array $columns
+     * @return mixed
+     */
+    public function findAllBy($attribute, $value, $columns = array('*'))
+    {
+        $this->applyCriteria();
+        return $this->model->where($attribute, '=', $value)->get($columns);
+    }
+
+    /**
+     * Find a collection of models by the given query conditions.
+     *
+     * @param array $where
+     * @param array $columns
+     * @param bool $or
+     *
+     * @return \Illuminate\Database\Eloquent\Collection|null
+     */
+    public function findWhere($where, $columns = ['*'], $or = false)
+    {
+        $this->applyCriteria();
+
+        $model = $this->model;
+
+        foreach ($where as $field => $value) {
+            if ($value instanceof \Closure) {
+                $model = (!$or)
+                    ? $model->where($value)
+                    : $model->orWhere($value);
+            } elseif (is_array($value)) {
+                if (count($value) === 3) {
+                    list($field, $operator, $search) = $value;
+                    $model = (!$or)
+                        ? $model->where($field, $operator, $search)
+                        : $model->orWhere($field, $operator, $search);
+                } elseif (count($value) === 2) {
+                    list($field, $search) = $value;
+                    $model = (!$or)
+                        ? $model->where($field, '=', $search)
+                        : $model->orWhere($field, '=', $search);
+                }
+            } else {
+                $model = (!$or)
+                    ? $model->where($field, '=', $value)
+                    : $model->orWhere($field, '=', $value);
+            }
+        }
+        return $model->get($columns);
+    }
+
+    /**
+     * @return \Illuminate\Database\Eloquent\Builder
+     * @throws RepositoryException
+     */
+    public function makeModel()
+    {
+        return $this->setModel($this->model());
+    }
+
+    /**
+     * Set Eloquent Model to instantiate
+     *
+     * @param $eloquentModel
+     * @return Model
+     * @throws RepositoryException
+     */
+    public function setModel($eloquentModel)
+    {
+        $this->newModel = $this->app->make($eloquentModel);
+
+        if (!$this->newModel instanceof Model)
+            throw new RepositoryException("Class {$this->newModel} must be an instance of Illuminate\\Database\\Eloquent\\Model");
+
+        return $this->model = $this->newModel;
+    }
+
+    /**
+     * @return $this
+     */
+    public function resetScope()
+    {
+        $this->skipCriteria(false);
+        return $this;
+    }
+
+    /**
+     * @param bool $status
+     * @return $this
+     */
+    public function skipCriteria($status = true)
+    {
+        $this->skipCriteria = $status;
+        return $this;
+    }
+
+    /**
+     * @return mixed
+     */
+    public function getCriteria()
+    {
+        return $this->criteria;
+    }
+
+    /**
+     * @param Criteria $criteria
+     * @return $this
+     */
+    public function getByCriteria(Criteria $criteria)
+    {
+        $this->model = $criteria->apply($this->model, $this);
+        return $this;
+    }
+
+    /**
+     * @param Criteria $criteria
+     * @return $this
+     */
+    public function pushCriteria(Criteria $criteria)
+    {
+        if ($this->preventCriteriaOverwriting) {
+            // Find existing criteria
+            $key = $this->criteria->search(function ($item) use ($criteria) {
+                return (is_object($item) && (get_class($item) == get_class($criteria)));
+            });
+
+            // Remove old criteria
+            if (is_int($key)) {
+                $this->criteria->offsetUnset($key);
+            }
+        }
+
+        $this->criteria->push($criteria);
+        return $this;
+    }
+
+    /**
+     * @return $this
+     */
+    public function applyCriteria()
+    {
+        if ($this->skipCriteria === true)
+            return $this;
+
+        foreach ($this->getCriteria() as $criteria) {
+            if ($criteria instanceof Criteria)
+                $this->model = $criteria->apply($this->model, $this);
+        }
+
+        return $this;
+    }
+}

+ 41 - 0
app/Repositories/Contracts/CriteriaInterface.php

xqd
@@ -0,0 +1,41 @@
+<?php
+
+namespace App\Repositories\Contracts;
+
+use App\Repositories\Base\Criteria;
+
+/**
+ * Interface CriteriaInterface
+ * @package Bosnadev\Repositories\Contracts
+ */
+interface CriteriaInterface {
+
+    /**
+     * @param bool $status
+     * @return $this
+     */
+    public function skipCriteria($status = true);
+
+    /**
+     * @return mixed
+     *
+     */
+    public function getCriteria();
+
+    /**
+     * @param Criteria $criteria
+     * @return $this
+     */
+    public function getByCriteria(Criteria $criteria);
+
+    /**
+     * @param Criteria $criteria
+     * @return $this
+     */
+    public function pushCriteria(Criteria $criteria);
+
+    /**
+     * @return $this
+     */
+    public function  applyCriteria();
+}

+ 78 - 0
app/Repositories/Contracts/RepositoryInterface.php

xqd
@@ -0,0 +1,78 @@
+<?php
+namespace App\Repositories\Contracts;
+
+/**
+ * Interface RepositoryInterface
+ * @package Bosnadev\Repositories\Contracts
+ */
+interface RepositoryInterface {
+
+//    /**
+//     * @param array $columns
+//     * @return mixed
+//     */
+    public function all($columns = array('*'));
+//
+//    /**
+//     * @param $perPage
+//     * @param array $columns
+//     * @return mixed
+//     */
+    public function paginate($perPage = 1, $columns = array('*'));
+//
+//    /**
+//     * @param array $data
+//     * @return mixed
+//     */
+//    public function create(array $data);
+//
+//    /**
+//     * @param array $data
+//     * @return bool
+//     */
+//    public function saveModel(array $data);
+//
+//    /**
+//     * @param array $data
+//     * @param $id
+//     * @return mixed
+//     */
+    public function update($id,array $data);
+//
+//    /**
+//     * @param $id
+//     * @return mixed
+//     */
+//    public function delete($id);
+//
+//    /**
+//     * @param $id
+//     * @param array $columns
+//     * @return mixed
+//     */
+    public function find($id, $columns = array('*'));
+//
+//    /**
+//     * @param $field
+//     * @param $value
+//     * @param array $columns
+//     * @return mixed
+//     */
+    public function findBy($field, $value, $columns = array('*'));
+//
+//    /**
+//     * @param $field
+//     * @param $value
+//     * @param array $columns
+//     * @return mixed
+//     */
+//    public function findAllBy($field, $value, $columns = array('*'));
+//
+//    /**
+//     * @param $where
+//     * @param array $columns
+//     * @return mixed
+//     */
+//    public function findWhere($where, $columns = array('*'));
+
+}

+ 49 - 0
app/Repositories/Messages/Criteria/MultiWhere.php

xqd
@@ -0,0 +1,49 @@
+<?php
+/**
+ * User: Mike
+ * Email: m@9026.com
+ * Date: 2017/1/12
+ * Time: 17:52
+ */
+
+namespace App\Repositories\Messages\Criteria;
+
+
+
+
+use App\Repositories\Base\Criteria;
+use App\Repositories\Contracts\RepositoryInterface as Repository;
+
+class MultiWhere extends Criteria {
+
+    private $search = [];
+
+    /**
+     * MultiWhere constructor.
+     * @param array $search
+     *
+     */
+    public function __construct(array $search)
+    {
+        $this->search = $search;
+    }
+
+    /**
+    * @param $model
+    * @param RepositoryInterface $repository
+    * @return mixed
+    */
+    public function apply($model, Repository $repository)
+    {
+        if(isset($this->search['keyword']) && ! empty($this->search['keyword'])) {
+            $keywords = '%' . $this->search['keyword'] . '%';
+            $model = $model->where(function ($query) use ($keywords) {
+                $query->where('id'  , 'like', $keywords)
+                    ->orwhere('title', 'like', $keywords)
+                    ->orwhere('phone', 'like', $keywords);
+            });
+        }
+         return $model;
+    }
+
+}

+ 43 - 0
app/Repositories/Messages/Criteria/TagWhere.php

xqd
@@ -0,0 +1,43 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: 思维定制
+ * Date: 2018/7/19
+ * Time: 18:39
+ */
+
+namespace App\Repositories\Messages\Criteria;
+
+use App\Repositories\Base\Criteria;
+use App\Repositories\Contracts\RepositoryInterface as Repository;
+class TagWhere extends Criteria {
+
+    private $search = [];
+
+    /**
+     * MultiWhere constructor.
+     * @param array $search
+     *
+     */
+    public function __construct(array $search)
+    {
+        $this->search = $search;
+    }
+
+    /**
+     * @param $model
+     * @param RepositoryInterface $repository
+     * @return mixed
+     */
+    public function apply($model, Repository $repository)
+    {
+        if(isset($this->search['keyword']) && ! empty($this->search['keyword'])) {
+            $keywords = '%' . $this->search['keyword'] . '%';
+            $model = $model->where(function ($query) use ($keywords) {
+                $query->where('id'  , 'like', $keywords)
+                    ->orwhere('name', 'like', $keywords);
+            });
+        }
+        return $model;
+    }
+}

+ 21 - 0
app/Repositories/Messages/InfoRepository.php

xqd
@@ -0,0 +1,21 @@
+<?php
+/**
+ *   信息列表
+ *  @author  system
+ *  @version    1.0
+ *  @date 2018-07-11 06:50:54
+ *
+ */
+namespace App\Repositories\Messages;
+
+use App\Repositories\Base\Repository;
+
+
+class InfoRepository extends Repository {
+
+    public function model() {
+        return \App\Models\MessagesInfoModel::class;
+    }
+
+    
+}

+ 21 - 0
app/Repositories/Messages/TagRepository.php

xqd
@@ -0,0 +1,21 @@
+<?php
+/**
+ *   标签列表
+ *  @author  system
+ *  @version    1.0
+ *  @date 2018-07-11 06:51:31
+ *
+ */
+namespace App\Repositories\Messages;
+
+use App\Repositories\Base\Repository;
+
+
+class TagRepository extends Repository {
+
+    public function model() {
+        return \App\Models\MessagesTagModel::class;
+    }
+
+    
+}

+ 48 - 0
app/Repositories/Payment/Criteria/MultiWhere.php

xqd
@@ -0,0 +1,48 @@
+<?php
+/**
+ * User: Mike
+ * Email: m@9026.com
+ * Date: 2017/1/12
+ * Time: 17:52
+ */
+
+namespace App\Repositories\Payment\Criteria;
+
+
+
+
+use App\Repositories\Base\Criteria;
+use App\Repositories\Contracts\RepositoryInterface as Repository;
+
+class MultiWhere extends Criteria {
+
+    private $search = [];
+
+    /**
+     * MultiWhere constructor.
+     * @param array $search
+     *
+     */
+    public function __construct(array $search)
+    {
+        $this->search = $search;
+    }
+
+    /**
+    * @param $model
+    * @param RepositoryInterface $repository
+    * @return mixed
+    */
+    public function apply($model, Repository $repository)
+    {
+        if(isset($this->search['keyword']) && ! empty($this->search['keyword'])) {
+            $keywords = '%' . $this->search['keyword'] . '%';
+            $model = $model->where(function ($query) use ($keywords) {
+                $query->where('id'  , 'like', $keywords)
+                    ->orwhere('out_trade_no', 'like', $keywords);
+            });
+        }
+         return $model;
+    }
+
+}

+ 21 - 0
app/Repositories/Payment/InfoRepository.php

xqd
@@ -0,0 +1,21 @@
+<?php
+/**
+ *   支付列表
+ *  @author  system
+ *  @version    1.0
+ *  @date 2018-07-11 06:53:04
+ *
+ */
+namespace App\Repositories\Payment;
+
+use App\Repositories\Base\Repository;
+
+
+class InfoRepository extends Repository {
+
+    public function model() {
+        return \App\Models\PaymentInfoModel::class;
+    }
+
+    
+}

+ 48 - 0
app/Repositories/User/Criteria/MultiWhere.php

xqd
@@ -0,0 +1,48 @@
+<?php
+/**
+ * User: Mike
+ * Email: m@9026.com
+ * Date: 2017/1/12
+ * Time: 17:52
+ */
+
+namespace App\Repositories\User\Criteria;
+
+
+
+
+use App\Repositories\Base\Criteria;
+use App\Repositories\Contracts\RepositoryInterface as Repository;
+
+class MultiWhere extends Criteria {
+
+    private $search = [];
+
+    /**
+     * MultiWhere constructor.
+     * @param array $search
+     *
+     */
+    public function __construct(array $search)
+    {
+        $this->search = $search;
+    }
+
+    /**
+    * @param $model
+    * @param RepositoryInterface $repository
+    * @return mixed
+    */
+    public function apply($model, Repository $repository)
+    {
+        if(isset($this->search['keyword']) && ! empty($this->search['keyword'])) {
+            $keywords = '%' . $this->search['keyword'] . '%';
+            $model = $model->where(function ($query) use ($keywords) {
+                $query->where('id'  , 'like', $keywords)
+                    ->orwhere('mobile', 'like', $keywords);
+            });
+        }
+        return $model;
+    }
+
+}

+ 21 - 0
app/Repositories/User/InfoRepository.php

xqd
@@ -0,0 +1,21 @@
+<?php
+/**
+ *   用户表
+ *  @author  system
+ *  @version    1.0
+ *  @date 2017-05-30 12:16:56
+ *
+ */
+namespace App\Repositories\User;
+
+use App\Repositories\Base\Repository;
+
+
+class InfoRepository extends Repository {
+
+    public function model() {
+        return \App\Models\UserInfoModel::class;
+    }
+
+    
+}

+ 21 - 0
app/Repositories/Wechat/AppRepository.php

xqd
@@ -0,0 +1,21 @@
+<?php
+/**
+ *   11
+ *  @author  system
+ *  @version    1.0
+ *  @date 2018-07-26 01:43:25
+ *
+ */
+namespace App\Repositories\Wechat;
+
+use App\Repositories\Base\Repository;
+
+
+class AppRepository extends Repository {
+
+    public function model() {
+        return \App\Models\WechatAppModel::class;
+    }
+
+    
+}

+ 45 - 0
app/Repositories/Wechat/Criteria/MultiWhere.php

xqd
@@ -0,0 +1,45 @@
+<?php
+/**
+ * User: Mike
+ * Email: m@9026.com
+ * Date: 2017/1/12
+ * Time: 17:52
+ */
+
+namespace App\Repositories\Wechat\Criteria;
+
+
+
+
+use App\Repositories\Base\Criteria;
+use App\Repositories\Contracts\RepositoryInterface as Repository;
+
+class MultiWhere extends Criteria {
+
+    private $search = [];
+
+    /**
+     * MultiWhere constructor.
+     * @param array $search
+     *
+     */
+    public function __construct(array $search)
+    {
+        $this->search = $search;
+    }
+
+    /**
+    * @param $model
+    * @param RepositoryInterface $repository
+    * @return mixed
+    */
+    public function apply($model, Repository $repository)
+    {
+          if(isset($this->search['poundage']) && $this->search['poundage']) {
+                                    $model = $model->where('poundage',$this->search['poundage']);
+                                 }
+
+         return $model;
+    }
+
+}

+ 128 - 0
app/Services/Admin/Acl.php

xqd
@@ -0,0 +1,128 @@
+<?php
+/**
+ *  
+ *  @author  Mike <m@9026.com>
+ *  @version    1.0
+ *  @date 2015年11月13日
+ *
+ */
+namespace App\Services\Admin;
+
+use App\Services\Base\BaseProcess;
+use App\Models\AdminAccessModel;
+use App\Models\AdminMenusModel;
+
+class Acl extends BaseProcess {
+    
+    private $objModel;
+    private $menusModel;
+    /**
+     * 初始化
+     *
+     * @access public
+     *
+     */
+    public function __construct()
+    {
+        if( ! $this->objModel) $this->objModel = new AdminAccessModel();
+        if( ! $this->menusModel) $this->menusModel = new AdminMenusModel();
+    }
+    
+    public function checkFunc($module,$contrl,$action) {
+        
+    }
+    
+    
+    public function getRoleFunc($roleIds) {
+        $data =$this->objModel->getRoleAccessMenu($roleIds);
+        if(!$data) {
+              return array('menus'=>array(),'func'=>array());
+        }
+        $arr = array('/'=>'0','Foundation/Index/index'=>501,'Foundation/Index/welcome'=>502,'Foundation/Login/logout'=>503);
+        foreach ($data as $val) {
+            $arr[$val['path']] = $val['id'];
+        }
+        return array('menus'=>$data,'func'=>$arr);
+            ;
+    }
+    
+    public function getRoleMenu($roleIds) {
+        $data =$this->objModel->getRoleAccessMenu($roleIds,true);
+        if(!$data) {
+            return array();
+        }
+        return $data;
+    }
+    
+    
+    public function getRootFunc() {
+        $data =$this->menusModel->select('id','pid','path','name','display','level','ico')->orderBy('sort','desc')->get()->toArray();
+        if(!$data) {
+            return array('menus'=>array(),'func'=>array());
+        }
+        $arr = array('/'=>'0','Foundation/Index/index'=>501,'Foundation/Index/welcome'=>502,'Foundation/Login/logout'=>503);
+        foreach ($data as $val) {
+            $arr[$val['path']] = $val['id'];
+        }
+        return array('menus'=>$data,'func'=>$arr);
+    }
+    /**
+     * 获取角色权限ID
+     * @param unknown $roleId
+     */
+   public function getAccessIDs($roleId) {
+       $data = $this->objModel->select("menu_id")->where("role_id",$roleId)->get();
+       $arr = array();
+       if($data) {
+            foreach ($data as $val) {
+                $arr[] = $val['menu_id'];
+            }
+       }
+       return $arr;
+   }
+   /**
+    * 
+    * @param unknown $roleId
+    * @param unknown $menuIds
+    * @param string $allMenus 权限范围,如果为false不验证
+    */
+   public function setRole($roleId,$menuIds,$allMenus=false) {
+       
+       try
+       {
+           $result = \DB::transaction(function() use ($roleId, $menuIds,$allMenus)
+           {
+               $ok = $this->objModel->where("role_id",$roleId)->delete();
+               if($ok===false) {
+                  throwException("删除出错");
+               }
+               foreach ($menuIds as $menu_id) {
+                   if($allMenus !== false) {
+                       if(!in_array($menu_id, $allMenus)) {
+                           throwException("涉及到越权操作");
+                       }
+                   }
+                   $add['role_id'] = $roleId;
+                   $add['menu_id'] = $menu_id;
+                   
+                   $ok = $this->objModel->create($add);
+                   if(!$ok) {
+                       throwException("添加出错");
+                   }
+               }
+              
+               return true;
+           });
+       }
+       catch (\Exception $e)
+       {
+           $result = false;
+       }
+       
+       if( ! $result) return $this->setMsg('操作失败');
+       
+       return true;
+   }
+   
+    
+}

+ 288 - 0
app/Services/Admin/AdminUser.php

xqd
@@ -0,0 +1,288 @@
+<?php
+/**
+ *  用户操作
+ *  @author  Mike <m@9026.com>
+ *  @version    1.0
+ *  @date 2015年11月13日
+ *
+ */
+namespace App\Services\Admin;
+use App\Models\AdminUserModel;
+use Hash;
+use App\Services\Base\BaseProcess;
+
+class AdminUser extends BaseProcess
+{
+    /**
+     * 模型
+     *
+     * @var object
+     *
+     */
+    private $objModel;
+
+    /**
+     * 初始化
+     */
+    public function __construct()
+    {
+        if( !$this->objModel) $this->objModel = new AdminUserModel();
+    }
+
+    public function model()
+    {
+        $this->setSucessCode();
+        return $this->objModel;
+    }
+
+    /**
+     * 搜索
+     * @param $search
+     * @param $pagesize
+     */
+    public function search($search, $orderby = array(), $pagesize = PAGE_NUMS)
+    {
+        $currentQuery = $this->objModel;
+        if(isset($search['keyword']) && !empty($search['keyword'])) {
+            $keywords = '%' . $search['keyword'] . '%';
+            $currentQuery = $currentQuery->where(function ($query) use ($keywords) {
+                $query->where('name'  , 'like', $keywords)
+                    ->orwhere('email', 'like', $keywords)
+                    ->orwhere('mobile', 'like', $keywords);
+            });
+        }
+        if(isset($search['resetPwd']) && $search['resetPwd']) {
+
+            $currentQuery = $currentQuery->where('reset_password', '<>', '');
+        }
+
+        if($orderby && is_array($orderby)){
+            foreach ($orderby AS $field => $value){
+                $currentQuery = $currentQuery -> orderBy($field, $value);
+            }
+        }else{
+            $currentQuery = $currentQuery->orderBy('id', 'DESC');
+        }
+        $currentQuery = $currentQuery->paginate($pagesize);
+        return $currentQuery;
+    }
+
+    /**
+     * 添加
+     * @param $data
+     */
+    public function create($data)
+    {
+        // 判断是否唯一
+        if($this->objModel->where('name', '=', $data['name'])->count()){
+            $this->setMsg("已经存在【{$data['name']}】用户!");
+            return false;
+        }
+        $data['name'] = isset($data['name']) ? $data['name'] : "";
+        $data['email'] = isset($data['email']) ? $data['email'] : "";
+        $data['mobile'] = isset($data['mobile']) ? $data['mobile'] : "";
+        $data['real_name'] = isset($data['real_name']) ? $data['real_name'] : "";
+        if($data['name']== "" && $data['email']=="" && $data['mobile']=="") {
+            $this->setMsg("至少有一个登陆凭证");
+            return false;
+        }
+        if(isset($data['name']) && $data['name']) {
+            if(is_numeric($data['name'])) {
+                $this->setMsg("用户名不能是全数字!");
+                return false;
+            }
+            if(strpos($data['name'],"@")) {
+                $this->setMsg("用户名不能有@符号!");
+                return false;
+            }
+            if($this->objModel->where('name', '=', $data['name'])->count()){
+                $this->setMsg("已经存在的用户名!");
+                return false;
+            }
+        }
+        if(isset($data['email']) && $data['email']) {
+            if($this->objModel->where('email', '=', $data['email'])->count()){
+                $this->setMsg("已经存在的邮箱!");
+                return false;
+            }
+        }
+        if(isset($data['mobile']) && $data['mobile']) {
+            if($this->objModel->where('mobile', '=', $data['mobile'])->count()){
+                $this->setMsg("已经存在的手机号!");
+                return false;
+            }
+        }
+        if(isset($data['password']) && $data['password']){
+            $data['password'] = bcrypt($data['password']);
+        }
+
+        return $this->objModel->create($data);
+    }
+
+    /**
+     * 更新
+     * @param $id
+     * @param $data
+     */
+    public function update($id, $data)
+    {
+        $obj = $this->objModel->find($id);
+        if(!$obj) {
+            return false;
+        }
+        if(isset($data['real_name']) && $data['real_name']){
+            $data['real_name'] = $data['real_name'];
+        }
+        if(isset($data['password']) && $data['password']){
+            $data['password'] = bcrypt($data['password']);
+        }
+        if(isset($data['name']) && $data['name']) {
+            if(is_numeric($data['name'])) {
+                $this->setMsg("用户名不能是全数字!");
+                return false;
+            }
+            if(strpos($data['name'],"@")) {
+                $this->setMsg("用户名不能有@符号!");
+                return false;
+            }
+            if($this->objModel->where('name', '=', $data['name'])->where('id',"<>",$id)->count()){
+                $this->setMsg("已经存在的用户名!");
+                return false;
+            }
+        }
+        if(isset($data['email']) && $data['email']) {
+            if($this->objModel->where('email', '=', $data['email'])->where('id',"<>",$id)->count()){
+                $this->setMsg("已经存在的邮箱!");
+                return false;
+            }
+        }
+        if(isset($data['mobile']) && $data['mobile']) {
+            if($this->objModel->where('mobile', '=', $data['mobile'])->where('id',"<>",$id)->count()){
+                $this->setMsg("已经存在的手机号!");
+                return false;
+            }
+        }
+        $ok = $obj->update($data);
+        return $ok;
+    }
+
+    /**
+     * 更新状态
+     * @param $id
+     * @param $status
+     */
+    public function updateStatus($id, $status)
+    {
+        $data = $this->objModel->find($id);
+        //禁用
+        $mobile = $data->mobile;
+        $data->status = $status;
+        return $data->save();
+    }
+
+    /**
+     * 删除
+     * @param $id
+     */
+    public function destroy($id)
+    {
+        return $this->objModel->destroy($id);
+    }
+
+    /**
+     * 获取一行数据
+     * @param $where
+     * @return
+     */
+    public function find($id)
+    {
+        return $this->objModel->find($id);
+    }
+
+
+    public function login($login,$password) {
+        if(is_numeric($login)) {
+            $loginField = "mobile";
+        }elseif(strpos($login,"@")) {
+            $loginField = "email";
+        }else{
+            $loginField = "name";
+        }
+        if (\Auth::guard('admin')->attempt(array($loginField => $login, 'password' =>$password)))
+        {
+            $data =  \Auth::guard('admin')->user();
+            if($data->status==0) {
+                $this->setMsg('账号正在努力审核中...');
+                return false;
+            }
+            if(!$data->status) {
+                $this->setMsg('账号被禁用');
+                return false;
+            }
+            $role = [];
+            if($data->is_root) {
+                $aclObj = new Acl();
+                $data =  $aclObj->getRootFunc();
+                $role['role'] =$data['func'];
+                $role['menus'] =$data['menus'];
+            }elseif($data->admin_role_id) {
+                $aclObj = new Acl();
+                $data =  $aclObj->getRoleFunc($data->admin_role_id);
+                $role['role'] =$data['func'];
+                $role['menus'] =$data['menus'];
+            }
+            session()->put(LOGIN_MARK_SESSION_KEY, $role);
+            session()->save();
+            return true;
+        }else{
+            $this->setMsg('用户密码错误');
+            return false;
+        }
+    }
+
+    /**
+     * 重设密码
+     * @param $loginName
+     * @param $data
+     */
+    public function resetPwd($loginName,$data) {
+        if(is_numeric($loginName)) {
+            $loginField = "mobile";
+        }elseif(strpos($loginName,"@")) {
+            $loginField = "email";
+        }else{
+            $loginField = "username";
+        }
+        $user = $this->objModel->where($loginField,$loginName)->first();
+        if(!$user) {
+            $this->setMsg('没有找到用户');
+            return false;
+        }
+        $user->reset_password = bcrypt($data['reset_password']);
+        $user->reset_password_img = $data['reset_password_img'];
+        $ok = $user->save();
+        if(!$ok) {
+            $this->setMsg('操作失败');
+            return false;
+        }
+        return true;
+    }
+
+
+    /**
+     * 查询多条数据
+     */
+    public function get($pagesize = PAGE_NUMS) {
+        return $this->objModel->take($pagesize)->orderBy('id', 'DESC')->get();
+    }
+
+
+    /**
+     * 查询多条数据并分页
+     */
+    public function getPage($pagesize = PAGE_NUMS) {
+        return $this->objModel->orderBy('id', 'DESC')->paginate($pagesize);
+    }
+
+
+}

+ 150 - 0
app/Services/Admin/Menus.php

xqd
@@ -0,0 +1,150 @@
+<?php
+/**
+ *------------------------------------------------------
+ * Menus.php
+ *------------------------------------------------------
+ *
+ * @author    qqiu@qq.com
+ * @date      2016/12/19 11:31
+ * @version   V1.0
+ *
+ */
+
+namespace App\Services\Admin;
+
+use App\Services\Base\BaseProcess;
+use App\Models\AdminMenusModel;
+use App\Services\Base\Tree;
+
+class Menus extends BaseProcess {
+
+    /**
+     * 模型
+     */
+    private $_model;
+
+    /**
+     * 初始化
+     */
+    public function __construct()
+    {
+        if( ! $this->_model) $this->_model = new AdminMenusModel();
+    }
+
+    public function model() {
+        $this->setSucessCode();
+        return $this->_model;
+    }
+
+    public function find($id) {
+        return $this->_model->find($id);
+    }
+
+    /**
+     * 添加
+     * @param unknown $data
+     */
+    public function create($data)
+    {
+        return $this->_model->create($data);
+    }
+
+    /**
+     * 更新
+     * @param unknown $id
+     * @param unknown $data
+     */
+    public function update($id,$data)
+    {
+        $obj = $this->_model->find($id);
+        if(!$obj) {
+            return false;
+        }
+        $ok = $obj->update($data);
+        return $ok;
+    }
+
+    /**
+     * 删除
+     * @param unknown $id
+     */
+    public function destroy($id)
+    {
+        return $this->_model->destroy($id);
+    }
+
+    /**
+     * 获取当前菜单层级
+     * @param $pid
+     * @return level
+     */
+    public function getLevel($id)
+    {
+        $tree = new Tree();
+        $MenusArr = $this->_model->orderBy('sort', 'DESC')->get()->toArray();
+        $tree->init($MenusArr);
+        $allParents = $tree->getPos($id);
+        return count($allParents);
+    }
+
+    /**
+     * 获取菜单树状结构
+     */
+    public function getMenusTree($search = array()){
+
+        $currentQuery = $this->_model;
+        if(isset($search['keyword']) && !empty($search['keyword'])) {
+            $keywords = '%' . $search['keyword'] . '%';
+            $currentQuery = $currentQuery->where(function ($query) use ($keywords) {
+                $query->where('name'  , 'like', $keywords)
+//                    ->orwhere('module', 'like', $keywords)
+                    ->orwhere('path', 'like', $keywords)
+                    ->orwhere('mark', 'like', $keywords);
+            });
+        }
+
+        $MenusArr = $currentQuery->orderBy('sort', 'DESC')->get()->toArray();
+        $tree = new Tree();
+        $tree->icon = array('&nbsp;&nbsp;&nbsp;│ ', '&nbsp;&nbsp;&nbsp;├─ ', '&nbsp;&nbsp;&nbsp;└─ ');
+        $tree->nbsp = '&nbsp;&nbsp;&nbsp;';
+        $tree->init($MenusArr);
+        return $tree->getTree();
+    }
+
+    /**
+     * 搜索
+     * @param $search
+     * @param $pagesize
+     */
+    public function search($search,$orderby=array('sort'=>'desc'),$pagesize = PAGE_NUMS)
+    {
+        $currentQuery = $this->_model;
+        if(isset($search['keyword']) && !empty($search['keyword'])) {
+            $keywords = '%' . $search['keyword'] . '%';
+            $currentQuery = $currentQuery->where(function ($query) use ($keywords) {
+                $query->where('name'  , 'like', $keywords)
+                    ->orwhere('module', 'like', $keywords)
+                    ->orwhere('contrl', 'like', $keywords);
+            });
+        }
+        if(isset($search['min_level']) && !empty($search['min_level'])) {
+            $currentQuery = $currentQuery->where('level','<=',$search['min_level']);
+        }
+        if(isset($search['display']) && !empty($search['display'])) {
+            $currentQuery = $currentQuery->where('display',$search['display']);
+        }
+        if($orderby) {
+            foreach ($orderby as $key=>$sort) {
+                $currentQuery = $currentQuery->orderBy($key,$sort);
+            }
+        }
+        if($pagesize){
+            $currentQuery = $currentQuery->paginate($pagesize);
+        }else{
+            $currentQuery = $currentQuery->get();
+        }
+        return $currentQuery;
+    }
+
+
+}

+ 181 - 0
app/Services/Admin/Role.php

xqd
@@ -0,0 +1,181 @@
+<?php
+/**
+ *  用户角色
+ *  @author  qqiu@qq.com
+ *  @version    1.0
+ *  @date 2015年10月9日
+ *
+ */
+namespace App\Services\Admin;
+
+use App\Services\Base\BaseProcess;
+use App\Models\AdminRoleModel;
+
+class Role extends BaseProcess
+{
+    /**
+     * 模型
+     *
+     * @var object
+     * 
+     */
+    private $objModel;
+    
+    /**
+     * 初始化
+     */
+    public function __construct()
+    {
+        if( !$this->objModel) $this->objModel = new AdminRoleModel();
+    }
+    
+    public function model()
+    {
+        $this->setSucessCode();
+        return $this->objModel;
+    }
+    
+    /**
+     * 搜索
+     * @param $search
+     * @param $pagesize
+     */
+    public function search($search, $orderby, $pagesize = PAGE_NUMS)
+    {
+        $currentQuery = $this->objModel;
+        if(isset($search['keyword']) && !empty($search['keyword'])) {
+            $keywords = '%' . $search['keyword'] . '%';
+            $currentQuery = $currentQuery->where(function ($query) use ($keywords) {
+                $query->where('name'  , 'like', $keywords)
+                ->orwhere('mark', 'like', $keywords);
+            });
+        }
+        
+        if(isset($search['department_ids']) && !empty($search['department_ids'])) {
+            $department_ids = $search['department_ids'];
+            $currentQuery = $currentQuery->where(function ($query) use ($department_ids) {
+                $query->whereIn('department_id', $department_ids);
+            });
+        }
+        
+        if($orderby && is_array($orderby)){
+            foreach ($orderby AS $field => $value){
+                $currentQuery = $currentQuery -> orderBy($field, $value);
+            }
+        }else{
+            $currentQuery = $currentQuery->orderBy('id', 'DESC');
+        }
+        
+        $currentQuery = $currentQuery->where('level', '>=', $search['level'])->paginate($pagesize);
+        return $currentQuery;
+    }
+
+    /**
+     * 添加
+     * @param $data
+     */
+    public function create($data)
+    {
+        return $this->objModel->create($data);
+    }
+    
+    /**
+     * 更新
+     * @param $id
+     * @param $data
+     */
+    public function update($id, $data)
+    {
+        $obj = $this->objModel->find($id);
+        if(!$obj) {
+            return false;
+        }
+        $ok = $obj->update($data);
+        return $ok;
+    }
+    
+    /**
+     * 更新状态
+     * @param $id
+     * @param $status
+     */
+    public function updateStatus($id, $status)
+    {
+        $data = $this->objModel->find($id);
+        $data->status = $status;
+        return $data->save();
+    }
+    
+    /**
+     * 删除
+     * @param $id
+     */
+    public function destroy($id)
+    {
+        return $this->objModel->destroy($id);
+    }
+    
+    /**
+     * 获取一行数据
+     * @param $where
+     * @return
+     */
+    public function find($id)
+    {
+        return $this->objModel->find($id);
+    }
+    
+    /**
+     * 获取角色权限节点(level越小权限越大)
+     */
+    public function getLevelNode($role_ids)
+    {
+        $role_ids = is_array($role_ids) ? $role_ids : explode(',', $role_ids);
+        return $this->objModel->whereIn('id', $role_ids)->take(1)->orderBy('level', 'ASC')->first();
+    }
+    
+    /**
+     * 根据状态查询数据
+     */
+    public function getValidData($status = 1)
+    {
+        return $this->objModel->where('status', $status)->orderBy('id', 'DESC')->get();
+    }
+    
+    /**
+     * 查询多条数据
+     */
+    public function get($pagesize = PAGE_NUMS) {
+        return $this->objModel->take($pagesize)->orderBy('level', 'ASC')->get();
+    }
+    
+    /**
+     * 查询多条数据并分页
+     */
+    public function getPage($pagesize = PAGE_NUMS) {
+        return $this->objModel->orderBy('id', 'DESC')->paginate($pagesize);
+    }
+    
+    /**
+     * 获取子等级数据
+     */
+    public function getChildByLevel($level, $departmentIds=array())
+    {
+        $currentQuery = $this->objModel;
+        $currentQuery = $currentQuery->where('level', '>=', $level);
+        $currentQuery = $currentQuery->where('status', '=', 1);
+        if($departmentIds){
+            $currentQuery = $currentQuery->whereIn('department_id', $departmentIds);
+        }
+        return $currentQuery = $currentQuery->orderBy('level', 'ASC')->get();
+    }
+    
+    /**
+     * 根据部门ID获取角色个数
+     */
+    public function getCountByDepartmentId($department_id)
+    {
+        return $this->objModel->where('department_id', '=', $department_id)->count();
+    }
+    
+}

+ 58 - 0
app/Services/Base/AbstractService.php

xqd
@@ -0,0 +1,58 @@
+<?php
+/**
+ *------------------------------------------------------
+ * AbstractService.php
+ *------------------------------------------------------
+ *
+ * @author    qqiu@qq.com
+ * @date      2016/5/26 11:17
+ * @version   V1.0
+ *
+ */
+
+namespace App\Services\Base;
+
+abstract class AbstractService
+{
+
+    protected $_code = FAILURE_CODE;
+
+    /**
+     * 错误的信息载体
+     */
+    protected $_msg;
+
+    /**
+     * 取回错误的信息
+     */
+    public function getMsg()
+    {
+        return $this->_msg;
+    }
+
+    /**
+     * 设置错误的信息
+     */
+    public function setMsg($msg)
+    {
+        $this->_msg = $msg;
+        return false;
+    }
+
+    /**
+     * 设置状态码
+     */
+    public function setCode($code)
+    {
+        $this->_code = $code;
+    }
+
+    /**
+     * 标记为成功
+     */
+    public function setSucessCode()
+    {
+        $this->setCode(SUCESS_CODE);
+    }
+
+}

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است