作者 xiaohu

0823

正在显示 47 个修改的文件 包含 4747 行增加0 行删除

要显示太多修改。

为保证性能只显示 47 of 47+ 个文件。

<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/simplewind/vendor/composer" />
<excludeFolder url="file://$MODULE_DIR$/simplewind/vendor/dompdf/dompdf" />
<excludeFolder url="file://$MODULE_DIR$/simplewind/vendor/electrolinux/phpquery" />
<excludeFolder url="file://$MODULE_DIR$/simplewind/vendor/ezyang/htmlpurifier" />
<excludeFolder url="file://$MODULE_DIR$/simplewind/vendor/mindplay/annotations" />
<excludeFolder url="file://$MODULE_DIR$/simplewind/vendor/phenx/php-font-lib" />
<excludeFolder url="file://$MODULE_DIR$/simplewind/vendor/phenx/php-svg-lib" />
<excludeFolder url="file://$MODULE_DIR$/simplewind/vendor/phpmailer/phpmailer" />
<excludeFolder url="file://$MODULE_DIR$/simplewind/vendor/phpoffice/phpexcel" />
<excludeFolder url="file://$MODULE_DIR$/simplewind/vendor/qiniu/php-sdk" />
<excludeFolder url="file://$MODULE_DIR$/simplewind/vendor/sabberworm/php-css-parser" />
<excludeFolder url="file://$MODULE_DIR$/simplewind/vendor/topthink/think-captcha" />
<excludeFolder url="file://$MODULE_DIR$/simplewind/vendor/topthink/think-helper" />
<excludeFolder url="file://$MODULE_DIR$/simplewind/vendor/topthink/think-image" />
<excludeFolder url="file://$MODULE_DIR$/simplewind/vendor/topthink/think-installer" />
<excludeFolder url="file://$MODULE_DIR$/simplewind/vendor/topthink/think-queue" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="your-project-name" />
<orderEntry type="module" module-name="Zerg" />
</component>
</module>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
</project>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/07-08-qnbugbms.iml" filepath="$PROJECT_DIR$/.idea/07-08-qnbugbms.iml" />
<module fileurl="file://$USER_HOME$/Downloads/y0zdij/Zerg/.idea/Zerg.iml" filepath="$USER_HOME$/Downloads/y0zdij/Zerg/.idea/Zerg.iml" />
<module fileurl="file://$PROJECT_DIR$/../07-08-voyager/your-project-name/.idea/your-project-name.iml" filepath="$PROJECT_DIR$/../07-08-voyager/your-project-name/.idea/your-project-name.iml" />
</modules>
</component>
</project>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PhpIncludePathManager">
<include_path>
<path value="$PROJECT_DIR$/simplewind/vendor/phenx/php-font-lib" />
<path value="$PROJECT_DIR$/simplewind/vendor/qiniu/php-sdk" />
<path value="$PROJECT_DIR$/simplewind/vendor/phenx/php-svg-lib" />
<path value="$PROJECT_DIR$/simplewind/vendor/phpmailer/phpmailer" />
<path value="$PROJECT_DIR$/simplewind/vendor/dompdf/dompdf" />
<path value="$PROJECT_DIR$/simplewind/vendor/topthink/think-installer" />
<path value="$PROJECT_DIR$/simplewind/vendor/phpoffice/phpexcel" />
<path value="$PROJECT_DIR$/simplewind/vendor/mindplay/annotations" />
<path value="$PROJECT_DIR$/simplewind/vendor/ezyang/htmlpurifier" />
<path value="$PROJECT_DIR$/simplewind/vendor/topthink/think-queue" />
<path value="$PROJECT_DIR$/simplewind/vendor/topthink/think-captcha" />
<path value="$PROJECT_DIR$/simplewind/vendor/topthink/think-image" />
<path value="$PROJECT_DIR$/simplewind/vendor/topthink/think-helper" />
<path value="$PROJECT_DIR$/simplewind/vendor/sabberworm/php-css-parser" />
<path value="$PROJECT_DIR$/simplewind/vendor/electrolinux/phpquery" />
<path value="$PROJECT_DIR$/simplewind/vendor/composer" />
</include_path>
</component>
<component name="PhpProjectSharedConfiguration" php_language_level="5.4.0" />
</project>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="03b59864-5835-4588-bfae-54004809f199" name="Default" comment="" />
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="TRACKING_ENABLED" value="true" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="ComposerSettings" doNotAsk="true" synchronizationState="SYNCHRONIZE">
<pharConfigPath>$PROJECT_DIR$/composer.json</pharConfigPath>
</component>
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file leaf-file-name="PublicController.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/api/wxapp/controller/PublicController.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1365">
<caret line="74" column="32" selection-start-line="74" selection-start-column="32" selection-end-line="74" selection-end-column="32" />
<folding>
<element signature="e#497#510#0#PHP" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file leaf-file-name="database.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/data/conf/database.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="273">
<caret line="15" column="23" selection-start-line="15" selection-start-column="23" selection-end-line="15" selection-end-column="23" />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="admin_menu.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/data/lang/zh-cn/admin_menu.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="2961">
<caret line="141" column="2" selection-start-line="141" selection-start-column="2" selection-end-line="141" selection-end-column="2" />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="login.html" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/public/themes/admin_simpleboot3/admin/login.html">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="693">
<caret line="33" column="7" selection-start-line="33" selection-start-column="7" selection-end-line="33" selection-end-column="7" />
<folding>
<element signature="n#style#0;n#div#0;n#div#0;n#div#2;n#div#0;n#div#0;n#body#0;n#html#0;n#!!top" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file leaf-file-name="PublicController.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/app/admin/controller/PublicController.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="966">
<caret line="55" column="5" selection-start-line="55" selection-start-column="5" selection-end-line="55" selection-end-column="5" />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="header.html" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/public/themes/admin_simpleboot3/public/header.html">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="84">
<caret line="19" column="36" selection-start-line="19" selection-start-column="29" selection-end-line="19" selection-end-column="36" />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="WXBizDataCrypt.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/simplewind/extend/wxapp/aes/WXBizDataCrypt.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="714">
<caret line="34" column="20" selection-start-line="34" selection-start-column="20" selection-end-line="34" selection-end-column="20" />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="FavoritesController.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/api/user/controller/FavoritesController.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="126">
<caret line="12" column="27" selection-start-line="12" selection-start-column="27" selection-end-line="12" selection-end-column="27" />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="route.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/api/user/route.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="105">
<caret line="15" column="5" selection-start-line="15" selection-start-column="5" selection-end-line="15" selection-end-column="22" />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="common.php" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/simplewind/cmf/common.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="30093">
<caret line="1448" column="29" selection-start-line="1448" selection-start-column="29" selection-end-line="1448" selection-end-column="29" />
</state>
</provider>
</entry>
</file>
</leaf>
</component>
<component name="FindInProjectRecents">
<findStrings>
<find>captcha</find>
<find>useNoise</find>
<find>c</find>
<find>capt</find>
<find>Welcome to Voyager. The Missing Admin for Laravel</find>
<find>noty_modal</find>
<find>thinkcmf-notices</find>
<find>wxapp_settings</find>
<find>$wxUserData</find>
</findStrings>
<dirStrings>
<dir>$PROJECT_DIR$/../07-08-voyager/your-project-name</dir>
<dir>$PROJECT_DIR$</dir>
</dirStrings>
</component>
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/simplewind/vendor/topthink/think-captcha/src/Captcha.php" />
<option value="$PROJECT_DIR$/simplewind/cmf/controller/CaptchaController.php" />
<option value="$PROJECT_DIR$/../07-08-voyager/your-project-name/.env" />
<option value="$PROJECT_DIR$/../07-08-voyager/your-project-name/app/Providers/AppServiceProvider.php" />
<option value="$PROJECT_DIR$/../07-08-voyager/your-project-name/1.html" />
<option value="$PROJECT_DIR$/../07-08-voyager/your-project-name/2.html" />
<option value="$PROJECT_DIR$/../07-08-voyager/your-project-name/3.html" />
<option value="$PROJECT_DIR$/public/themes/admin_simpleboot3/admin/main/index.html" />
<option value="$PROJECT_DIR$/public/themes/admin_simpleboot3/admin/index/index.html" />
<option value="$PROJECT_DIR$/api/wxapp/route.php" />
<option value="$PROJECT_DIR$/api/config.php" />
<option value="$PROJECT_DIR$/api/wxapp/controller/PublicController.php" />
<option value="$PROJECT_DIR$/data/conf/database.php" />
<option value="$PROJECT_DIR$/data/lang/zh-cn/admin_menu.php" />
<option value="$PROJECT_DIR$/public/static/css/viyagerapp.css" />
<option value="$PROJECT_DIR$/public/themes/admin_simpleboot3/admin/login.html" />
<option value="$PROJECT_DIR$/app/admin/controller/PublicController.php" />
</list>
</option>
</component>
<component name="JsBuildToolGruntFileManager" detection-done="true" sorting="DEFINITION_ORDER" />
<component name="JsBuildToolPackageJson" detection-done="true" sorting="DEFINITION_ORDER" />
<component name="JsGulpfileManager">
<detection-done>true</detection-done>
<sorting>DEFINITION_ORDER</sorting>
</component>
<component name="NodePackageJsonFileManager">
<packageJsonPaths />
</component>
<component name="PhpWorkspaceProjectConfiguration">
<include_path>
<path value="$PROJECT_DIR$/simplewind/vendor/phenx/php-font-lib" />
<path value="$PROJECT_DIR$/simplewind/vendor/qiniu/php-sdk" />
<path value="$PROJECT_DIR$/simplewind/vendor/phenx/php-svg-lib" />
<path value="$PROJECT_DIR$/simplewind/vendor/phpmailer/phpmailer" />
<path value="$PROJECT_DIR$/simplewind/vendor/dompdf/dompdf" />
<path value="$PROJECT_DIR$/simplewind/vendor/topthink/think-installer" />
<path value="$PROJECT_DIR$/simplewind/vendor/phpoffice/phpexcel" />
<path value="$PROJECT_DIR$/simplewind/vendor/mindplay/annotations" />
<path value="$PROJECT_DIR$/simplewind/vendor/ezyang/htmlpurifier" />
<path value="$PROJECT_DIR$/simplewind/vendor/topthink/think-queue" />
<path value="$PROJECT_DIR$/simplewind/vendor/topthink/think-captcha" />
<path value="$PROJECT_DIR$/simplewind/vendor/topthink/think-image" />
<path value="$PROJECT_DIR$/simplewind/vendor/topthink/think-helper" />
<path value="$PROJECT_DIR$/simplewind/vendor/sabberworm/php-css-parser" />
<path value="$PROJECT_DIR$/simplewind/vendor/electrolinux/phpquery" />
<path value="$PROJECT_DIR$/simplewind/vendor/composer" />
</include_path>
</component>
<component name="ProjectFrameBounds" extendedState="6">
<option name="y" value="32" />
<option name="width" value="1366" />
<option name="height" value="687" />
</component>
<component name="ProjectView">
<navigator proportions="" version="1">
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="Scope" />
<pane id="ProjectPane">
<subPane>
<expand>
<path>
<item name="dm162jiajiao" type="b2602c69:ProjectViewProjectNode" />
<item name="dm162jiajiao" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="dm162jiajiao" type="b2602c69:ProjectViewProjectNode" />
<item name="dm162jiajiao" type="462c0819:PsiDirectoryNode" />
<item name="app" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="dm162jiajiao" type="b2602c69:ProjectViewProjectNode" />
<item name="dm162jiajiao" type="462c0819:PsiDirectoryNode" />
<item name="app" type="462c0819:PsiDirectoryNode" />
<item name="admin" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="dm162jiajiao" type="b2602c69:ProjectViewProjectNode" />
<item name="dm162jiajiao" type="462c0819:PsiDirectoryNode" />
<item name="app" type="462c0819:PsiDirectoryNode" />
<item name="admin" type="462c0819:PsiDirectoryNode" />
<item name="controller" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="dm162jiajiao" type="b2602c69:ProjectViewProjectNode" />
<item name="dm162jiajiao" type="462c0819:PsiDirectoryNode" />
<item name="public" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="dm162jiajiao" type="b2602c69:ProjectViewProjectNode" />
<item name="dm162jiajiao" type="462c0819:PsiDirectoryNode" />
<item name="public" type="462c0819:PsiDirectoryNode" />
<item name="themes" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="dm162jiajiao" type="b2602c69:ProjectViewProjectNode" />
<item name="dm162jiajiao" type="462c0819:PsiDirectoryNode" />
<item name="public" type="462c0819:PsiDirectoryNode" />
<item name="themes" type="462c0819:PsiDirectoryNode" />
<item name="admin_simpleboot3" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="dm162jiajiao" type="b2602c69:ProjectViewProjectNode" />
<item name="dm162jiajiao" type="462c0819:PsiDirectoryNode" />
<item name="public" type="462c0819:PsiDirectoryNode" />
<item name="themes" type="462c0819:PsiDirectoryNode" />
<item name="admin_simpleboot3" type="462c0819:PsiDirectoryNode" />
<item name="admin" type="462c0819:PsiDirectoryNode" />
</path>
</expand>
<select />
</subPane>
</pane>
</panes>
</component>
<component name="PropertiesComponent">
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/../lwyz" />
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
<property name="nodejs_npm_path_reset_for_default_project" value="true" />
<property name="nodejs_package_manager_path" value="npm" />
</component>
<component name="RecentsManager">
<key name="MoveFile.RECENT_KEYS">
<recent name="$PROJECT_DIR$/api/wxapp" />
</key>
</component>
<component name="RunDashboard">
<option name="ruleStates">
<list>
<RuleState>
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
</RuleState>
<RuleState>
<option name="name" value="StatusDashboardGroupingRule" />
</RuleState>
</list>
</option>
</component>
<component name="SvnConfiguration">
<configuration />
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="03b59864-5835-4588-bfae-54004809f199" name="Default" comment="" />
<created>1531052219895</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1531052219895</updated>
<workItem from="1531052221437" duration="3345000" />
<workItem from="1531061228213" duration="3029000" />
<workItem from="1531653353141" duration="7654000" />
<workItem from="1531747533208" duration="2488000" />
<workItem from="1531794895610" duration="20000" />
</task>
<servers />
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="16536000" />
</component>
<component name="ToolWindowManager">
<frame x="-8" y="-8" width="1382" height="744" extended-state="6" />
<layout>
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.21669106" />
<window_info anchor="bottom" id="TODO" order="6" />
<window_info anchor="bottom" id="Docker" order="7" show_stripe_button="false" />
<window_info anchor="bottom" id="Event Log" order="7" side_tool="true" />
<window_info anchor="right" id="Database" order="3" />
<window_info anchor="bottom" id="Database Changes" order="7" show_stripe_button="false" />
<window_info anchor="bottom" id="Version Control" order="7" show_stripe_button="false" />
<window_info anchor="bottom" id="Run" order="2" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info anchor="bottom" id="Terminal" order="7" />
<window_info id="Favorites" order="2" side_tool="true" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
<window_info id="npm" order="2" side_tool="true" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="bottom" id="Find" order="1" weight="0.32881355" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Message" order="0" />
</layout>
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="1" />
</component>
<component name="VcsContentAnnotationSettings">
<option name="myLimit" value="2678400000" />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/../07-08-voyager/your-project-name/vendor/tcg/voyager/publishable/lang/en/login.php" />
<entry file="file://$PROJECT_DIR$/../07-08-voyager/your-project-name/.env" />
<entry file="file://$PROJECT_DIR$/../07-08-voyager/your-project-name/1.html" />
<entry file="file://$PROJECT_DIR$/app/admin/controller/UserController.php" />
<entry file="file://$PROJECT_DIR$/../07-08-voyager/your-project-name/3.html" />
<entry file="file://$PROJECT_DIR$/../07-08-voyager/your-project-name/2.html" />
<entry file="file://$PROJECT_DIR$/public/static/js/noty/noty.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="247">
<caret line="10" column="3915" selection-start-line="10" selection-start-column="3915" selection-end-line="10" selection-end-column="3915" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/public/static/js/artDialog/artDialog.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="19">
<caret line="1" column="12" selection-start-line="1" selection-start-column="3" selection-end-line="1" selection-end-column="12" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/public/static/js/admin.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1653">
<caret line="87" column="28" selection-start-line="87" selection-start-column="28" selection-end-line="87" selection-end-column="28" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/public/themes/admin_simpleboot3/admin/main/index.html">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="95">
<caret line="5" column="44" selection-start-line="5" selection-start-column="44" selection-end-line="5" selection-end-column="44" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/public/themes/admin_simpleboot3/admin/index/index.html">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="4693">
<caret line="247" selection-start-line="247" selection-end-line="247" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/data/conf/route.php">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/api/home/controller/ThemeController.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-647" />
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/api/portal/route.php">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/api/tags.php">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/api/portal/validate/ArticlesValidate.php">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/api/portal/controller/UserController.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-21" />
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/public/api/index.php">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/api/home/controller/SlidesController.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-293" />
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/api/common/exception/Http.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-98" />
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/api/common/model/CommonModel.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-974" />
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/api/home/controller/IndexController.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="76">
<caret line="10" column="4" lean-forward="true" selection-start-line="10" selection-start-column="4" selection-end-line="10" selection-end-column="4" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/api/home/controller/RestController.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-280" />
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/api/home/route.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="76">
<caret line="4" column="18" selection-start-line="4" selection-start-column="17" selection-end-line="4" selection-end-column="28" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/api/route.php">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/api/release.php">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/api/debug.php">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/api/database.php">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/api/command.php">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/api/wxapp/controller/UserController.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="228">
<caret line="18" selection-start-line="18" selection-end-line="18" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/api/wxapp/route.php" />
<entry file="file://$PROJECT_DIR$/api/config.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="448">
<caret line="262" column="28" selection-start-line="262" selection-start-column="28" selection-end-line="262" selection-end-column="28" />
</state>
</provider>
</entry>
<entry file="file://$USER_HOME$/Downloads/y0zdij/Zerg/application/api/service/UserToken.php" />
<entry file="file://$USER_HOME$/Downloads/y0zdij/Zerg/application/route.php" />
<entry file="file://$PROJECT_DIR$/simplewind/cmf/controller/RestBaseController.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="126">
<caret line="20" column="24" selection-start-line="20" selection-start-column="6" selection-end-line="20" selection-end-column="24" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/api/user/controller/CommentsController.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="126">
<caret line="18" column="51" selection-start-line="18" selection-start-column="33" selection-end-line="18" selection-end-column="51" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/api/user/model/UserModel.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="420">
<caret line="30" column="22" selection-start-line="30" selection-start-column="22" selection-end-line="30" selection-end-column="22" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/api/user/model/UserFavoriteModel.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1827">
<caret line="93" column="28" selection-start-line="93" selection-start-column="28" selection-end-line="93" selection-end-column="28" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/api/user/route.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="105">
<caret line="15" column="5" selection-start-line="15" selection-start-column="5" selection-end-line="15" selection-end-column="22" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/api/user/controller/FavoritesController.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="126">
<caret line="12" column="27" selection-start-line="12" selection-start-column="27" selection-end-line="12" selection-end-column="27" />
</state>
</provider>
</entry>
<entry file="file://$USER_HOME$/Downloads/y0zdij/Zerg/application/api/controller/v1/Token.php" />
<entry file="file://$PROJECT_DIR$/simplewind/cmf/common.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="30093">
<caret line="1448" column="29" selection-start-line="1448" selection-start-column="29" selection-end-line="1448" selection-end-column="29" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/simplewind/extend/wxapp/aes/WXBizDataCrypt.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="714">
<caret line="34" column="20" selection-start-line="34" selection-start-column="20" selection-end-line="34" selection-end-column="20" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/api/wxapp/controller/PublicController.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1365">
<caret line="74" column="32" selection-start-line="74" selection-start-column="32" selection-end-line="74" selection-end-column="32" />
<folding>
<element signature="e#497#510#0#PHP" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/data/conf/database.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="273">
<caret line="15" column="23" selection-start-line="15" selection-start-column="23" selection-end-line="15" selection-end-column="23" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/public/themes/admin_simpleboot3/admin/user/add.html">
<provider selected="true" editor-type-id="text-editor" />
</entry>
<entry file="file://$PROJECT_DIR$/public/static/css/viyagerapp.css" />
<entry file="file://$PROJECT_DIR$/data/lang/zh-cn/admin_menu.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="2961">
<caret line="141" column="2" selection-start-line="141" selection-start-column="2" selection-end-line="141" selection-end-column="2" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/public/themes/admin_simpleboot3/admin/login.html">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="693">
<caret line="33" column="7" selection-start-line="33" selection-start-column="7" selection-end-line="33" selection-end-column="7" />
<folding>
<element signature="n#style#0;n#div#0;n#div#0;n#div#2;n#div#0;n#div#0;n#body#0;n#html#0;n#!!top" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/app/admin/controller/PublicController.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="966">
<caret line="55" column="5" selection-start-line="55" selection-start-column="5" selection-end-line="55" selection-end-column="5" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/public/themes/admin_simpleboot3/public/header.html">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="84">
<caret line="19" column="36" selection-start-line="19" selection-start-column="29" selection-end-line="19" selection-end-column="36" />
</state>
</provider>
</entry>
</component>
</project>
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace api\admin\controller;
use cmf\controller\RestBaseController;
use think\Db;
use think\Validate;
class PublicController extends RestBaseController
{
// 用户登录 TODO 增加最后登录信息记录,如 ip
public function login()
{
$validate = new Validate([
'username' => 'require',
'password' => 'require'
]);
$validate->message([
'username.require' => '请输入手机号,邮箱或用户名!',
'password.require' => '请输入您的密码!'
]);
$data = $this->request->param();
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$userQuery = Db::name("user");
if (Validate::is($data['username'], 'email')) {
$userQuery = $userQuery->where('user_email', $data['username']);
} else if (cmf_check_mobile($data['username'])) {
$userQuery = $userQuery->where('mobile', $data['username']);
} else {
$userQuery = $userQuery->where('user_login', $data['username']);
}
$findUser = $userQuery->find();
if (empty($findUser)) {
$this->error("用户不存在!");
} else {
switch ($findUser['user_status']) {
case 0:
$this->error('您已被拉黑!');
case 2:
$this->error('账户还没有验证成功!');
}
if (!cmf_compare_password($data['password'], $findUser['user_pass'])) {
$this->error("密码不正确!");
}
}
$allowedDeviceTypes = ['mobile', 'android', 'iphone', 'ipad', 'web', 'pc', 'mac'];
if (empty($data['device_type']) || !in_array($data['device_type'], $allowedDeviceTypes)) {
$this->error("请求错误,未知设备!");
}
$userTokenQuery = Db::name("user_token")
->where('user_id', $findUser['id'])
->where('device_type', $data['device_type']);
$findUserToken = $userTokenQuery->find();
$currentTime = time();
$expireTime = $currentTime + 24 * 3600 * 180;
$token = md5(uniqid()) . md5(uniqid());
if (empty($findUserToken)) {
$result = $userTokenQuery->insert([
'token' => $token,
'user_id' => $findUser['id'],
'expire_time' => $expireTime,
'create_time' => $currentTime,
'device_type' => $data['device_type']
]);
} else {
$result = $userTokenQuery
->where('user_id', $findUser['id'])
->where('device_type', $data['device_type'])
->update([
'token' => $token,
'expire_time' => $expireTime,
'create_time' => $currentTime
]);
}
if (empty($result)) {
$this->error("登录失败!");
}
$this->success("登录成功!", ['token' => $token]);
}
// 管理员退出
public function logout()
{
$userId = $this->getUserId();
Db::name('user_token')->where([
'token' => $this->token,
'user_id' => $userId,
'device_type' => $this->deviceType
])->update(['token' => '']);
$this->success("退出成功!");
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
$apps = cmf_scan_dir(APP_PATH . '*', GLOB_ONLYDIR);
$returnCommands = [];
foreach ($apps as $app) {
$commandFile = APP_PATH . $app . '/command.php';
if (file_exists($commandFile)) {
$commands = include $commandFile;
$returnCommands = array_merge($returnCommands, $commands);
}
}
return $returnCommands;
\ No newline at end of file
... ...
<?php
namespace api\common\exception;
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2017/11/28
* Time: 15:27
*/
use Exception;
use think\exception\Handle;
use think\exception\HttpException;
class Http extends Handle
{
public function render(Exception $e)
{
if (APP_DEBUG==true) {
return parent::render($e);
} elseif ($e instanceof ValidateException) {
$msg=$e->getMessage();
} else {
$msg= '系统错误!';
}
$code=0;
$httpCode=500;
$result = [
'code' => $code,
'msg' => $msg,
'data' => [],
];
return json($result, $httpCode);
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: pl125 <xskjs888@163.com>
// +----------------------------------------------------------------------
namespace api\common\model;
use think\Model;
use think\Loader;
class CommonModel extends Model
{
// 关联模型过滤
protected $relationFilter = [];
/**
* 内容查询
* @access public
* @param array $params 过滤参数
* @return array|false|\PDOStatement|string|\think\Collection|Model 查询结果
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getDatas($params = [])
{
if (empty($params)) {
return $this->select();
}
$this->setCondition($params);
if (!empty($params['id'])) {
$datas = $this->find();
} else {
$datas = $this->select();
}
if (!empty($params['relation'])) {
$allowedRelations = $this->allowedRelations($params['relation']);
if (!empty($allowedRelations)) {
if (!empty($params['id'])) {
if (!empty($datas)) {
$datas->append($allowedRelations);
}
} else {
if (count($datas) > 0) {
$datas->load($allowedRelations);
$datas->append($allowedRelations);
}
}
}
}
return $datas;
}
/**
* @access public
* @param array $params 过滤参数
* @return $this
*/
public function setCondition($params)
{
if (empty($params)) {
return $this;
}
if (!empty($params['relation'])) {
$allowedRelations = $this->allowedRelations($params['relation']);
if (!empty($allowedRelations)) {
if (!empty($params['id']) && count($allowedRelations) == 1) {
$this->paramsFilter($params);
} else {
$this->paramsFilter($params);//->with($allowedRelations);
}
}
} else {
$this->paramsFilter($params);
}
return $this;
}
/**
* @access public
* @param array $params 过滤参数
* @param model $model 关联模型
* @return model|array $this|链式查询条件数组
*/
public function paramsFilter($params, $model = null)
{
if (!empty($model)) {
$_this = $model;
} else {
$_this = $this;
}
if (isset($_this->visible)) {
$whiteParams = $_this->visible;
}
// 设置field字段过滤
if (!empty($params['field'])) {
$filterParams = $this->strToArr($params['field']);
if (!empty($whiteParams)) {
$mixedField = array_intersect($filterParams, $whiteParams);
} else {
$mixedField = $filterParams;
}
if (!empty($mixedField)) {
$_this->field($mixedField);
}
}
// 设置id,ids
if (!empty($params['ids'])) {
$ids = $this->strToArr($params['ids']);
foreach ($ids as $key => $value) {
$ids[$key] = intval($value);
}
}
if (!empty($params['where']) && !is_string($params['where'])) {
if (empty($model)) {
$_this->where($params['where']);
}
}
if (!empty($params['id'])) {
$id = intval($params['id']);
if (!empty($id)) {
return $_this->where('id', $id);
}
} elseif (!empty($ids)) {
$_this->where('id', 'in', $ids);
}
// 设置分页
if (!empty($params['page'])) {
$pageArr = $this->strToArr($params['page']);
$page = [];
foreach ($pageArr as $value) {
$page[] = intval($value);
}
if (count($page) == 1) {
$_this->page($page[0]);
} elseif (count($page) == 2) {
$_this->page($page[0], $page[1]);
}
} elseif (!empty($params['limit'])) { // 设置limit查询
$limitArr = $this->strToArr($params['limit']);
$limit = [];
foreach ($limitArr as $value) {
$limit[] = intval($value);
}
if (count($limit) == 1) {
$_this->limit($limit[0]);
} elseif (count($limit) == 2) {
$_this->limit($limit[0], $limit[1]);
}
} else {
$_this->limit(10);
}
//设置排序
if (!empty($params['order'])) {
$order = $this->strToArr($params['order']);
foreach ($order as $key => $value) {
$upDwn = substr($value, 0, 1);
$orderType = $upDwn == '-' ? 'desc' : 'asc';
$orderField = substr($value, 1);
if (!empty($whiteParams)) {
if (in_array($orderField, $whiteParams)) {
$orderWhere[$orderField] = $orderType;
}
} else {
$orderWhere[$orderField] = $orderType;
}
}
if (!empty($orderWhere)) {
$_this->order($orderWhere);
}
}
return $_this;
}
/**
* 设置链式查询
* @access public
* @param array $params 链式查询条件
* @param model $model 模型
* @return $this
*/
public function setParamsQuery($params, $model = null)
{
if (!empty($model)) {
$_this = $model;
} else {
$_this = $this;
}
$_this->alias('articles');
if (!empty($params['field'])) {
$_this->field($params['field']);
}
if (!empty($params['ids'])) {
$_this->where('articles.id', $params['ids'][1], $params['ids'][2]);
}
if (!empty($params['limit'])) {
$_this->limit($params['limit']);
}
if (!empty($params['page'])) {
$_this->page($params['page']);
}
if (!empty($params['order'])) {
$_this->order($params['order']);
}
return $_this;
}
public function allowedRelations($relations)
{
if (is_string($relations)) {
$relations = explode(',', $relations);
}
if (!is_array($relations)) {
return false;
}
return array_intersect($this->relationFilter, $relations);
}
/**
* 是否允许关联
* @access public
* @param string $relationName 模型关联方法名
* @return boolean
*/
public function isWhite($relationName)
{
if (!is_string($relationName)) {
return false;
}
$name = Loader::parseName($relationName, 1, false);
if (in_array($name, $this->relationFilter)) {
return true;
} else {
return false;
}
}
/**
* 懒人函数
* @access public
* @param string $value 字符串
* @return array
*/
public function strToArr($string)
{
return is_string($string) ? explode(',', $string) : $string;
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
return [
// +----------------------------------------------------------------------
// | 应用设置
// +----------------------------------------------------------------------
// 应用命名空间
'app_namespace' => 'api',
// 应用模式状态
'app_status' => APP_DEBUG ? 'debug' : 'release',
// 是否支持多模块
'app_multi_module' => true,
// 入口自动绑定模块
'auto_bind_module' => false,
// 注册的根命名空间
'root_namespace' => ['cmf' => CMF_PATH, 'plugins' => PLUGINS_PATH, 'app' => CMF_ROOT . 'app/'],
// 扩展函数文件
'extra_file_list' => [THINK_PATH . 'helper' . EXT, CMF_PATH . 'common' . EXT],
// 默认输出类型
'default_return_type' => 'json',
// 默认AJAX 数据返回格式,可选json xml ...
'default_ajax_return' => 'json',
// 默认JSONP格式返回的处理方法
'default_jsonp_handler' => 'jsonpReturn',
// 默认JSONP处理方法
'var_jsonp_handler' => 'callback',
// 默认时区
'default_timezone' => 'PRC',
// 是否开启多语言
'lang_switch_on' => false,
// 默认全局过滤方法 用逗号分隔多个
'default_filter' => 'htmlspecialchars',
// 默认语言
'default_lang' => 'zh-cn',
// 应用类库后缀
'class_suffix' => true,
// 控制器类后缀
'controller_suffix' => true,
// +----------------------------------------------------------------------
// | 模块设置
// +----------------------------------------------------------------------
// 默认模块名
'default_module' => 'home',
// 禁止访问模块
'deny_module_list' => ['common'],
// 默认控制器名
'default_controller' => 'Index',
// 默认操作名
'default_action' => 'index',
// 默认验证器
'default_validate' => '',
// 默认的空控制器名
'empty_controller' => 'Error',
// 自动搜索控制器
'controller_auto_search' => false,
// +----------------------------------------------------------------------
// | URL设置
// +----------------------------------------------------------------------
'pathinfo_depr' => '/',
// URL伪静态后缀
'url_html_suffix' => 'html',
// URL普通方式参数 用于自动生成
'url_common_param' => false,
// URL参数方式 0 按名称成对解析 1 按顺序解析
'url_param_type' => 0,
// 是否开启路由
'url_route_on' => true,
// 路由配置文件(支持配置多个)
'route_config_file' => ['route'],
// 是否强制使用路由
'url_route_must' => false,
// 域名部署
'url_domain_deploy' => false,
// 域名根,如thinkphp.cn
'url_domain_root' => '',
// 是否自动转换URL中的控制器和操作名
'url_convert' => true,
// 默认的访问控制器层
'url_controller_layer' => 'controller',
// 表单请求类型伪装变量
'var_method' => '_method',
// +----------------------------------------------------------------------
// | 模板设置
// +----------------------------------------------------------------------
'template' => [
// 模板引擎类型 支持 php think 支持扩展
'type' => 'Think',
// 视图根目录
'view_base' => '',
// 模板路径
'view_path' => '',
// 模板后缀
'view_suffix' => 'html',
// 模板文件名分隔符
'view_depr' => DS,
// 模板引擎普通标签开始标记
'tpl_begin' => '{',
// 模板引擎普通标签结束标记
'tpl_end' => '}',
// 标签库标签开始标记
'taglib_begin' => '<',
// 标签库标签结束标记
'taglib_end' => '>',
],
// 视图输出字符串内容替换
'view_replace_str' => [],
// 默认跳转页面对应的模板文件
'dispatch_success_tmpl' => THINK_PATH . 'tpl' . DS . 'dispatch_jump.tpl',
'dispatch_error_tmpl' => THINK_PATH . 'tpl' . DS . 'dispatch_jump.tpl',
// +----------------------------------------------------------------------
// | 异常及错误设置
// +----------------------------------------------------------------------
// 异常页面的模板文件
'exception_tmpl' => THINK_PATH . 'tpl' . DS . 'think_exception.tpl',
// 错误显示信息,非调试模式有效
'error_message' => '页面错误!请稍后再试~',
// 显示错误信息
'show_error_msg' => false,
// 异常处理handle类 留空使用 \think\exception\Handle
'exception_handle' => '\\api\\common\\exception\\Http',
// +----------------------------------------------------------------------
// | 日志设置
// +----------------------------------------------------------------------
'log' => [
// 日志记录方式,内置 file socket 支持扩展
'type' => 'File',
// 日志保存目录
'path' => LOG_PATH,
// 日志记录级别
'level' => [],
],
// +----------------------------------------------------------------------
// | Trace设置 开启 app_trace 后 有效
// +----------------------------------------------------------------------
'trace' => [
// 内置Html Console 支持扩展
'type' => 'Html',
],
// +----------------------------------------------------------------------
// | 缓存设置
// +----------------------------------------------------------------------
'cache' => [
// 驱动方式
'type' => 'File',
// 缓存保存目录
'path' => CACHE_PATH,
// 缓存前缀
'prefix' => '',
// 缓存有效期 0表示永久缓存
'expire' => 0,
],
// +----------------------------------------------------------------------
// | 会话设置
// +----------------------------------------------------------------------
'session' => [
'id' => '',
// SESSION_ID的提交变量,解决flash上传跨域
'var_session_id' => '',
// SESSION 前缀
'prefix' => 'think',
// 驱动方式 支持redis memcache memcached
'type' => '',
// 是否自动开启 SESSION
'auto_start' => true,
],
// +----------------------------------------------------------------------
// | Cookie设置
// +----------------------------------------------------------------------
'cookie' => [
// cookie 名称前缀
'prefix' => '',
// cookie 保存时间
'expire' => 0,
// cookie 保存路径
'path' => '/',
// cookie 有效域名
'domain' => '',
// cookie 启用安全传输
'secure' => false,
// httponly设置
'httponly' => '',
// 是否使用 setcookie
'setcookie' => true,
],
// +----------------------------------------------------------------------
// | 数据库设置
// +----------------------------------------------------------------------
'database' => [
// 数据库调试模式
'debug' => true,
// 数据集返回类型
'resultset_type' => 'collection',
// 自动写入时间戳字段
'auto_timestamp' => false,
// 时间字段取出后的默认时间格式
'datetime_format' => false,
// 是否需要进行SQL性能分析
'sql_explain' => false,
],
//分页配置
'paginate' => [
'type' => 'bootstrap',
'var_page' => 'page',
'list_rows' => 15,
],
//图片验证码
'captcha' => [
// 验证码字符集合
'codeSet' => '2345678abcdefhijkmnpqrstuvwxyzABCDEFGHJKLMNPQRTUVWXY',
// 验证码字体大小(px)
'fontSize' => 25,
// 是否画混淆曲线
'useCurve' => true,
// 验证码图片高度
'imageH' => 30,
// 验证码图片宽度
'imageW' => 100,
// 验证码位数
'length' => 5,
// 验证成功后是否重置
'reset' => true
],
// +----------------------------------------------------------------------
// | CMF 设置
// +----------------------------------------------------------------------
'cmf_theme_path' => 'themes/home/',
'cmf_default_theme' => 'simpleboot3',
'cmf_admin_theme_path' => 'themes/admin/',
'cmf_admin_default_theme' => 'simpleboot3',
// +----------------------------------------------------------------------
// | 微信小程序 设置
// +----------------------------------------------------------------------
'wxapp_appid' => 'wx12c837c7608c06d4',
'wxapp_appSecret' => 'ad70b5e1d5f25564e3aa5358d717ca25',
];
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
if(file_exists(ROOT_PATH."data/conf/database.php")){
$database=include ROOT_PATH."data/conf/database.php";
}else{
$database=[];
}
return $database;
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
return [
// 应用调试模式
'app_debug' => true,
// 应用Trace
'app_trace' => true,
];
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace api\home\controller;
use think\Db;
use think\Validate;
use cmf\controller\RestBaseController;
class IndexController extends RestBaseController
{
// api 首页
public function index()
{
$this->success("恭喜您,API访问成功!", [
'version' => '1.1.0',
'doc' => 'http://www.thinkcmf.com/cmf5api.html'
]);
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
// API 模板文件,可以复制
namespace api\home\controller;
use cmf\controller\RestBaseController;
class RestController extends RestBaseController
{
/**
* 显示资源列表
*/
public function index()
{
}
/**
* 保存新建的资源
*/
public function save()
{
}
/**
* 显示指定的资源
*
* @param int $id
*/
public function read($id)
{
}
/**
* 保存更新的资源
*
* @param int $id
*/
public function update($id)
{
}
/**
* 删除指定资源
*
* @param int $id
*/
public function delete($id)
{
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | 文件说明:幻灯片
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: wuwu <15093565100@163.com>
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Date: 2017-5-25
// +----------------------------------------------------------------------
namespace api\home\controller;
use api\home\model\SlideModel;
use cmf\controller\RestBaseController;
class SlidesController extends RestBaseController
{
/**
* [获取幻灯片]
* @Author: wuwu<15093565100@163.com>
* @DateTime: 2017-05-25T20:48:53+0800
* @since: 1.0
*/
public function read()
{
//slide为空或不存在抛出异常
$id = $this->request->param('id', 0, 'intval');
if (empty($id)) {
$this->error('缺少ID参数');
}
$map['id'] = $id;
$obj = new SlideModel();
$data = $obj->SlideList($map);
//剔除分类状态隐藏 剔除分类下显示数据为空
if (empty($data) || $data['items']->isEmpty()) {
$this->error('该组幻灯片显示数据为空');
}
if (empty($this->apiVersion) || $this->apiVersion == '1.0.0') {
$response = [$data];
} else {
$response = $data;
}
$this->success("该组幻灯片获取成功!", $response);
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace api\home\controller;
use api\home\model\ThemeFileModel;
use cmf\controller\RestBaseController;
class ThemeController extends RestBaseController
{
/**
* 获取模板扩展属性
*/
public function more()
{
$theme = $this->request->param('theme');
$themeFileModel = new ThemeFileModel();
$file = $this->request->param('file');
$file = $themeFileModel->where('theme', $theme)->where('file', $file)->find();
$vars = [];
$widgets = [];
$oldMore = $file['more'];
if (!empty($oldMore['vars'])) {
foreach ($oldMore['vars'] as $varName => $var) {
switch ($var['type']) {
case 'image':
$vars[$varName] = cmf_get_image_url($var['value']);
break;
case 'file':
$vars[$varName] = cmf_get_file_download_url($var['value']);
break;
case 'array':
foreach ($var['value'] as $varKey => $varValue) {
foreach ($varValue as $varValueKey => $varValueValue) {
switch ($var['item'][$varValueKey]['type']) {
case 'image':
$var['value'][$varKey][$varValueKey] = cmf_get_image_url($varValueValue);
break;
case 'file':
$var['value'][$varKey][$varValueKey] = cmf_get_file_download_url($varValueValue);
break;
default:
$var['value'][$varKey][$varValueKey] = $varValueValue;
}
}
}
$vars[$varName] = $var['value'];
break;
default:
$vars[$varName] = $var['value'];
}
}
}
if (!empty($oldMore['widgets'])) {
foreach ($oldMore['widgets'] as $widgetName => $widget) {
$widgetVars = [];
if (!empty($widget['vars'])) {
foreach ($widget['vars'] as $varName => $var) {
switch ($var['type']) {
case 'image':
$widgetVars[$varName] = cmf_get_image_url($var['value']);
break;
case 'file':
$widgetVars[$varName] = cmf_get_file_download_url($var['value']);
break;
case 'array':
foreach ($var['value'] as $varKey => $varValue) {
foreach ($varValue as $varValueKey => $varValueValue) {
switch ($var['item'][$varValueKey]['type']) {
case 'image':
$var['value'][$varKey][$varValueKey] = cmf_get_image_url($varValueValue);
break;
case 'file':
$var['value'][$varKey][$varValueKey] = cmf_get_file_download_url($varValueValue);
break;
default:
$var['value'][$varKey][$varValueKey] = $varValueValue;
}
}
}
$widgetVars[$varName]=$var['value'];
break;
default:
$widgetVars[$varName] = $var['value'];
}
}
}
$widget['vars'] = $widgetVars;
$widgets[$widgetName] = $widget;
}
}
$this->success('success', [
'vars' => $vars,
'widgets' => $widgets
]);
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | 文件说明:用户-幻灯片
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: wuwu <15093565100@163.com>
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Date: 2017-5-25
// +----------------------------------------------------------------------
namespace api\home\model;
use think\Model;
class SlideItemModel extends Model
{
/**
* [base 全局查询范围status=1显示状态]
* @Author: wuwu<15093565100@163.com>
* @DateTime: 2017-05-25T21:54:03+0800
* @since: 1.0
*/
protected function base($query)
{
$query->where('status', 1);
}
/**
* image 自动转化
* @param $value
* @return array
*/
public function getImageAttr($value)
{
return cmf_get_image_url($value);
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | 文件说明:用户-幻灯片
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: wuwu <15093565100@163.com>
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Date: 2017-5-25
// +----------------------------------------------------------------------
namespace api\home\model;
use think\Model;
class SlideModel extends Model
{
/**
* [base 全局查询范围status=1显示状态]
* @Author: wuwu<15093565100@163.com>
* @DateTime: 2017-05-25T21:54:03+0800
* @since: 1.0
*/
protected function base($query)
{
$query->where('status', 1)->where('delete_time', 0);
}
/**
* [SlideItemModel 一对一关联模型 关联分类下的幻灯片]
* @Author: wuwu<15093565100@163.com>
* @DateTime: 2017-05-25T23:30:27+0800
* @since: 1.0
*/
protected function items()
{
return $this->hasMany('SlideItemModel')->order('list_order ASC');
}
/**
* [SlideList 幻灯片获取]
* @Author: wuwu<15093565100@163.com>
* @DateTime: 2017-05-25T20:52:27+0800
* @since: 1.0
*/
public function SlideList($map)
{
$data = $this->relation('items')->field(true)->where($map)->find();
return $data;
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | 文件说明:用户-幻灯片
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: wuwu <15093565100@163.com>
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Date: 2017-5-25
// +----------------------------------------------------------------------
namespace api\home\model;
use think\Model;
class ThemeFileModel extends Model
{
//类型转换
protected $type = [
'more' => 'array',
];
}
... ...
<?php
use think\Route;
Route::resource('home/slides', 'home/Slides');
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: pl125 <xskjs888@163.com>
// +----------------------------------------------------------------------
namespace api\portal\controller;
use api\user\model\UserFavoriteModel;
use api\user\model\UserLikeModel;
use cmf\controller\RestBaseController;
use api\portal\model\PortalPostModel;
use think\Db;
class ArticlesController extends RestBaseController
{
protected $postModel;
public function __construct(PortalPostModel $postModel)
{
parent::__construct();
$this->postModel = $postModel;
}
/**
* 文章列表
*/
public function index()
{
$params = $this->request->get();
$params['where']['post_type'] = 1;
$data = $this->postModel->getDatas($params);
if (empty($this->apiVersion) || $this->apiVersion == '1.0.0') {
$response = $data;
} else {
$response = ['list' => $data,];
}
$this->success('请求成功!', $response);
}
/**
* 获取指定的文章
* @param int $id
*/
public function read($id)
{
if (intval($id) === 0) {
$this->error('无效的文章id!');
} else {
$params = $this->request->get();
$params['where']['post_type'] = 1;
$params['id'] = $id;
$data = $this->postModel->getDatas($params);
if (empty($data)) {
$this->error('文章不存在!');
} else {
$this->postModel->where('id', $id)->setInc('post_hits');
$url = cmf_url('portal/Article/index', ['id' => $id, 'cid' => $data['categories'][0]['id']], true, true);
$data = $data->toArray();
$data['url'] = $url;
$this->success('请求成功!', $data);
}
}
}
/**
* 我的文章列表
*/
public function my()
{
$params = $this->request->get();
$userId = $this->getUserId();
$data = $this->postModel->getUserArticles($userId, $params);
if (empty($this->apiVersion) || $this->apiVersion == '1.0.0') {
$response = [$data];
} else {
$response = ['list' => $data];
}
$this->success('请求成功!', $response);
}
/**
* 添加文章
*/
public function save()
{
$data = $this->request->post();
$data['user_id'] = $this->getUserId();
$result = $this->validate($data, 'Articles.article');
if ($result !== true) {
$this->error($result);
}
if (empty($data['published_time'])) {
$data['published_time'] = time();
}
$this->postModel->addArticle($data);
$this->success('添加成功!');
}
/**
* 更新文章
* @param int $id
*/
public function update($id)
{
$data = $this->request->put();
$result = $this->validate($data, 'Articles.article');
if ($result !== true) {
$this->error($result);
}
if (empty($id)) {
$this->error('无效的文章id');
}
$result = $this->postModel->editArticle($data, $id, $this->getUserId());
if ($result === false) {
$this->error('编辑失败!');
} else {
$this->success('编辑成功!');
}
}
/**
* 删除文章
* @param int $id
*/
public function delete($id)
{
if (empty($id)) {
$this->error('无效的文章id');
}
$result = $this->postModel->deleteArticle($id, $this->getUserId());
if ($result == -1) {
$this->error('文章已删除');
}
if ($result) {
$this->success('删除成功!');
} else {
$this->error('删除失败!');
}
}
/**
* 批量删除文章
*/
public function deletes()
{
$ids = $this->request->post('ids/a');
if (empty($ids)) {
$this->error('文章id不能为空');
}
$result = $this->postModel->deleteArticle($ids, $this->getUserId());
if ($result == -1) {
$this->error('文章已删除');
}
if ($result) {
$this->success('删除成功!');
} else {
$this->error('删除失败!');
}
}
public function search()
{
$params = $this->request->get();
if (!empty($params['keyword'])) {
$params['where'] = [
'post_type' => 1,
'post_title|post_keywords|post_excerpt' => ['like', '%' . $params['keyword'] . '%']
];
$data = $this->postModel->getDatas($params);
if (empty($this->apiVersion) || $this->apiVersion == '1.0.0') {
$response = $data;
} else {
$response = ['list' => $data,];
}
$this->success('请求成功!', $response);
} else {
$this->error('搜索关键词不能为空!');
}
}
public function doLike()
{
$userId = $this->getUserId();
$articleId = $this->request->param('id', 0, 'intval');
$userLikeModel = new UserLikeModel();
$findLikeCount = $userLikeModel->where([
'user_id' => $userId,
'object_id' => $articleId
])->where('table_name', 'portal_post')->count();
if (empty($findLikeCount)) {
$article = $this->postModel->where(['id' => $articleId])->field('id,post_title,post_excerpt,more')->find();
if (empty($article)) {
$this->error('文章不存在!');
}
Db::startTrans();
try {
$this->postModel->where(['id' => $articleId])->setInc('post_like');
$thumbnail = empty($article['more']['thumbnail']) ? '' : $article['more']['thumbnail'];
$userLikeModel->insert([
'user_id' => $userId,
'object_id' => $articleId,
'table_name' => 'portal_post',
'title' => $article['post_title'],
'thumbnail' => $thumbnail,
'description' => $article['post_excerpt'],
'url' => json_encode(['action' => 'portal/Article/index', 'param' => ['id' => $articleId, 'cid' => $article['categories'][0]['id']]]),
'create_time' => time()
]);
Db::commit();
} catch (\Exception $e) {
Db::rollback();
$this->error('点赞失败!');
}
$likeCount = $this->postModel->where('id', $articleId)->value('post_like');
$this->success("赞好啦!", ['post_like' => $likeCount]);
} else {
$this->error("您已赞过啦!");
}
}
/**
* 取消文章点赞
*/
public function cancelLike()
{
$userId = $this->getUserId();
$articleId = $this->request->param('id', 0, 'intval');
$userLikeModel = new UserLikeModel();
$findLikeCount = $userLikeModel->where([
'user_id' => $userId,
'object_id' => $articleId
])->where('table_name', 'portal_post')->count();
if (!empty($findLikeCount)) {
Db::startTrans();
try {
$this->postModel->where(['id' => $articleId])->setDec('post_like');
$userLikeModel->where([
'user_id' => $userId,
'object_id' => $articleId
])->where('table_name', 'portal_post')->delete();
Db::commit();
} catch (\Exception $e) {
Db::rollback();
$this->error('取消点赞失败!');
}
$likeCount = $this->postModel->where('id', $articleId)->value('post_like');
$this->success("取消点赞成功!", ['post_like' => $likeCount]);
} else {
$this->error("您还没赞过!");
}
}
/**
* 文章收藏
* @throws \think\Exception
*/
public function doFavorite()
{
$userId = $this->getUserId();
$articleId = $this->request->param('id', 0, 'intval');
$userFavoriteModel = new UserFavoriteModel();
$findFavoriteCount = $userFavoriteModel->where([
'user_id' => $userId,
'object_id' => $articleId
])->where('table_name', 'portal_post')->count();
if (empty($findFavoriteCount)) {
$article = $this->postModel->where(['id' => $articleId])->field('id,post_title,post_excerpt,more')->find();
if (empty($article)) {
$this->error('文章不存在!');
}
Db::startTrans();
try {
$this->postModel->where(['id' => $articleId])->setInc('post_favorites');
$thumbnail = empty($article['more']['thumbnail']) ? '' : $article['more']['thumbnail'];
$userFavoriteModel->insert([
'user_id' => $userId,
'object_id' => $articleId,
'table_name' => 'portal_post',
'thumbnail' => $thumbnail,
'title' => $article['post_title'],
'description' => $article['post_excerpt'],
'url' => json_encode(['action' => 'portal/Article/index', 'param' => ['id' => $articleId, 'cid' => $article['categories'][0]['id']]]),
'create_time' => time()
]);
Db::commit();
} catch (\Exception $e) {
Db::rollback();
$this->error('收藏失败!');
}
$favoriteCount = $this->postModel->where('id', $articleId)->value('post_favorites');
$this->success("收藏好啦!", ['post_favorites' => $favoriteCount]);
} else {
$this->error("您已收藏过啦!");
}
}
/**
* 取消文章收藏
*/
public function cancelFavorite()
{
$userId = $this->getUserId();
$articleId = $this->request->param('id', 0, 'intval');
$userFavoriteModel = new UserFavoriteModel();
$findFavoriteCount = $userFavoriteModel->where([
'user_id' => $userId,
'object_id' => $articleId
])->where('table_name', 'portal_post')->count();
if (!empty($findFavoriteCount)) {
Db::startTrans();
try {
$this->postModel->where(['id' => $articleId])->setDec('post_favorites');
$userFavoriteModel->where([
'user_id' => $userId,
'object_id' => $articleId
])->where('table_name', 'portal_post')->delete();
Db::commit();
} catch (\Exception $e) {
Db::rollback();
$this->error('取消失败!');
}
$favoriteCount = $this->postModel->where('id', $articleId)->value('post_favorites');
$this->success("取消成功!", ['post_favorites' => $favoriteCount]);
} else {
$this->error("您还没收藏过!");
}
}
/**
* 相关文章列表
*/
public function relatedArticles()
{
$articleId = $this->request->param('id', 0, 'intval');
$categoryId = Db::name('portal_category_post')->where('post_id', $articleId)->value('category_id');
$articles = $this->postModel->alias('post')->join('__PORTAL_CATEGORY_POST__ category_post', 'post.id=category_post.post_id')
->where(['post.delete_time' => 0, 'post.post_status' => 1, 'category_post.category_id' => $categoryId])
->order(Db::raw('rand()'))
->limit(5)
->select();
$this->success('success', ['list' => $articles]);
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: pl125 <xskjs888@163.com>
// +----------------------------------------------------------------------
namespace api\portal\controller;
use cmf\controller\RestBaseController;
use api\portal\model\PortalCategoryModel;
class CategoriesController extends RestBaseController
{
protected $categoryModel;
public function __construct(PortalCategoryModel $categoryModel)
{
parent::__construct();
$this->categoryModel = $categoryModel;
}
/**
* 获取分类列表
*/
public function index()
{
$params = $this->request->get();
$data = $this->categoryModel->getDatas($params);
if (empty($this->apiVersion) || $this->apiVersion == '1.0.0') {
$response = $data;
} else {
$response = ['list' => $data];
}
$this->success('请求成功!', $response);
}
/**
* 显示指定的分类
* @param int $id
*/
public function read($id)
{
$params = $this->request->get();
$params['id'] = $id;
$data = $this->categoryModel->getDatas($params);
$this->success('请求成功!', $data);
}
/**
* 获取指定分类的子分类列表
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function subCategories()
{
$id = $this->request->get('category_id', 0, 'intval');
$categories = $this->categoryModel->where(['parent_id' => $id])->select();
$this->success('请求成功', ['categories' => $categories]);
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: wuwu <15093565100@163.com>
// +----------------------------------------------------------------------
namespace api\portal\controller;
use api\portal\model\PortalCategoryModel;
use api\portal\model\PortalPostModel;
use cmf\controller\RestBaseController;
class ListsController extends RestBaseController
{
/**
* [推荐文章列表]
* @Author: wuwu<15093565100@163.com>
* @DateTime: 2017-07-17T11:36:51+0800
* @since: 1.0
*/
public function recommended()
{
$param = $this->request->param();
$portalPostModel = new PortalPostModel();
$param['where'] = ['recommended' => 1];
$articles = $portalPostModel->getDatas($param);
$this->success('ok', ['list' => $articles]);
}
/**
* [getCategoryPostLists 分类文章列表]
* @Author: wuwu<15093565100@163.com>
* @DateTime: 2017-07-17T15:22:41+0800
* @since: 1.0
*/
public function getCategoryPostLists()
{
$categoryId = $this->request->param('category_id', 0, 'intval');
$portalCategoryModel = new PortalCategoryModel();
$findCategory = $portalCategoryModel->where('id', $categoryId)->find();
//分类是否存在
if (empty($findCategory)) {
$this->error('分类不存在!');
}
$param = $this->request->param();
if(empty($param['order'])){
$param['order']='-post.published_time';
}
$articles = $portalCategoryModel->paramsFilter($param, $findCategory->articles()->alias('post'))->select();
if (!empty($param['relation'])) {
if (count($articles) > 0) {
$articles->load('user');
$articles->append(['user']);
}
}
$this->success('ok', ['list' => $articles]);
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: pl125 <xskjs888@163.com>
// +----------------------------------------------------------------------
namespace api\portal\controller;
use cmf\controller\RestBaseController;
use api\portal\model\PortalPostModel;
class PagesController extends RestBaseController
{
protected $postModel;
public function __construct(PortalPostModel $postModel)
{
parent::__construct();
$this->postModel = $postModel;
}
/**
* 页面列表
*/
public function index()
{
$params = $this->request->get();
$params['where']['post_type'] = 2;
$data = $this->postModel->getDatas($params);
if (empty($this->apiVersion) || $this->apiVersion == '1.0.0') {
$response = $data;
} else {
$response = ['list' => $data,];
}
$this->success('请求成功!', $response);
}
/**
* 获取页面
* @param int $id
*/
public function read($id)
{
$params = $this->request->get();
$params['where']['post_type'] = 2;
$params['id'] = $id;
$data = $this->postModel->getDatas($params);
$this->success('请求成功!', $data);
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: pl125 <xskjs888@163.com>
// +----------------------------------------------------------------------
namespace api\portal\controller;
use api\portal\model\PortalPostModel;
use cmf\controller\RestBaseController;
use api\portal\model\PortalTagModel;
class TagsController extends RestBaseController
{
protected $tagModel;
public function __construct(PortalTagModel $tagModel)
{
parent::__construct();
$this->tagModel = $tagModel;
}
/**
* 获取标签列表
*/
public function index()
{
$params = $this->request->get();
$data = $this->tagModel->getDatas($params);
if (empty($this->apiVersion) || $this->apiVersion == '1.0.0') {
$response = $data;
} else {
$response = ['list' => $data,];
}
$this->success('请求成功!', $response);
}
/**
* 获取热门标签列表
*/
public function hotTags()
{
$params = $this->request->get();
$params['where']['recommended'] = 1;
$data = $this->tagModel->getDatas($params);
if (empty($this->apiVersion) || $this->apiVersion == '1.0.0') {
$response = $data;
} else {
$response = ['list' => $data,];
}
$this->success('请求成功!', $response);
}
/**
* 获取标签文章列表
* @param int $id
*/
public function articles($id)
{
if (intval($id) === 0) {
$this->error('无效的标签id!');
} else {
$params = $this->request->param();
$params['id'] = $id;
$params['relation'] = 'articles';
$postModel = new PortalPostModel();
$articles = $postModel->setCondition($params)->alias('a')->join('__PORTAL_TAG_POST__ tp', 'a.id = tp.post_id')
->where(['tag_id' => $id])->select();
$this->success('请求成功!', ['articles' => $articles]);
}
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: pl125 <xskjs888@163.com>
// +----------------------------------------------------------------------
namespace api\portal\controller;
use cmf\controller\RestUserBaseController;
use api\portal\logic\PortalPostModel;
class UserArticlesController extends RestUserBaseController
{
protected $postModel;
public function __construct(PortalPostModel $postModel)
{
parent::__construct();
$this->postModel = $postModel;
}
/**
* 显示资源列表
*/
public function index()
{
$params = $this->request->get();
$userId = $this->getUserId();
$datas = $this->postModel->getUserArticles($userId,$params);
$this->success('请求成功!', $datas);
}
/**
* 保存新建的资源
*/
public function save()
{
$datas = $this->request->post();
$datas['user_id'] = $this->getUserId();
$result = $this->validate($datas, 'Articles.article');
if ($result !== true) {
$this->error($result);
}
if (empty($datas['published_time'])) {
$datas['published_time'] = time();
}
$this->postModel->addArticle($datas);
$this->success('添加成功!');
}
/**
* 显示指定的资源
*
* @param int $id
*/
public function read($id)
{
if (empty($id)) {
$this->error('无效的文章id');
}
$params = $this->request->get();
$params['id'] = $id;
$userId = $this->getUserId();
$datas = $this->postModel->getUserArticles($userId,$params);
$this->success('请求成功!', $datas);
}
/**
* 保存更新的资源
*
* @param int $id
*/
public function update($id)
{
$data = $this->request->put();
$result = $this->validate($data, 'Articles.article');
if ($result !== true) {
$this->error($result);
}
if (empty($id)) {
$this->error('无效的文章id');
}
$result = $this->postModel->editArticle($data,$id,$this->getUserId());
if ($result === false) {
$this->error('编辑失败!');
} else {
$this->success('编辑成功!');
}
}
/**
* 删除指定资源
*
* @param int $id
*/
public function delete($id)
{
if (empty($id)) {
$this->error('无效的文章id');
}
$result = $this->postModel->deleteArticle($id,$this->getUserId());
if ($result == -1) {
$this->error('文章已删除');
}
if ($result) {
$this->success('删除成功!');
} else {
$this->error('删除失败!');
}
}
/**
* 批量删除文章
*/
public function deletes()
{
$ids = $this->request->post('ids/a');
if (empty($ids)) {
$this->error('文章id不能为空');
}
$result = $this->postModel->deleteArticle($ids,$this->getUserId());
if ($result == -1) {
$this->error('文章已删除');
}
if ($result) {
$this->success('删除成功!');
} else {
$this->error('删除失败!');
}
}
/**
* 我的文章列表
*/
public function my()
{
$params = $this->request->get();
$userId = $this->getUserId();
$data = $this->postModel->getUserArticles($userId, $params);
$this->success('请求成功!', $data);
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: wuwu <15093565100@163.com>
// +----------------------------------------------------------------------
namespace api\portal\controller;
use api\portal\model\PortalPostModel;
use cmf\controller\RestBaseController;
class UserController extends RestBaseController
{
protected $postModel;
public function __construct(PortalPostModel $postModel)
{
parent::__construct();
$this->postModel = $postModel;
}
/**
* 会员文章列表
*/
public function articles()
{
$userId = $this->request->param('user_id', 0, 'intval');
if(empty($userId)){
$this->error('用户id不能空!');
}
$data = $this->request->param();
$articles = $this->postModel->setCondition($data)->where(['user_id' => $userId])->select();
if (count($articles) == 0) {
$this->error('没有数据');
} else {
$this->success('ok', ['list' => $articles]);
}
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: pl125 <xskjs888@163.com>
// +----------------------------------------------------------------------
namespace api\portal\logic;
use api\portal\model\PortalPostModel as PortalPost;
use think\Db;
class PortalPostModel extends PortalPost
{
/**
* 获取相关文章
* @param int|string|array $postIds 文章id
* @return array
*/
public function getRelationPosts($postIds)
{
$posts = $this->with('articleUser')
->field('id,post_title,user_id,is_top,post_hits,post_like,comment_count,more')
->whereIn('id', $postIds)
->select();
foreach ($posts as $post) {
$post->appendRelationAttr('articleUser', 'user_nickname');
}
return $posts;
}
/**
* 获取用户文章
*/
public function getUserArticles($userId, $params)
{
$where = [
'post_type' => 1,
'user_id' => $userId
];
if (!empty($params)) {
$this->paramsFilter($params);
}
return $this->where($where)->select();
}
/**
* 会员添加文章
* @param array $data 文章数据
* @return $this
*/
public function addArticle($data)
{
//设置图片附件,写入字段过滤
$dataField = $this->setMoreField($data);
$data = $dataField[0];
array_push($dataField[1],'user_id');
$this->readonly = array_diff(['user_id'],$this->readonly);
$this->allowField($dataField[1])->data($data, true)->isUpdate(false)->save();
$categories = $this->strToArr($data['categories']);
$this->categories()->attach($categories);
if (!empty($data['post_keywords']) && is_string($data['post_keywords'])) {
//加入标签
$data['post_keywords'] = str_replace(',', ',', $data['post_keywords']);
$keywords = explode(',', $data['post_keywords']);
$this->addTags($keywords, $this->id);
}
return $this;
}
/**
* 会员文章编辑
* @param array $data 文章数据
* @param int $id 文章id
* @param int $userId 文章所属用户id [可选]
* @return boolean 成功 true 失败 false
*/
public function editArticle($data, $id, $userId = '')
{
if (!empty($userId)) {
$isBelong = $this->isuserPost($id, $userId);
if ($isBelong === false) {
return $isBelong;
}
}
//设置图片附件,写入字段过滤
$dataField = $this->setMoreField($data);
$data = $dataField[0];
$data['id'] = $id;
$this->allowField($dataField[1])->data($data, true)->isUpdate(true)->save();
$categories = $this->strToArr($data['categories']);
$oldCategoryIds = $this->categories()->column('category_id');
$sameCategoryIds = array_intersect($categories, $oldCategoryIds);
$needDeleteCategoryIds = array_diff($oldCategoryIds, $sameCategoryIds);
$newCategoryIds = array_diff($categories, $sameCategoryIds);
if (!empty($needDeleteCategoryIds)) {
$this->categories()->detach($needDeleteCategoryIds);
}
if (!empty($newCategoryIds)) {
$this->categories()->attach(array_values($newCategoryIds));
}
if (!isset($data['post_keywords'])) {
$keywords = [];
} elseif (is_string($data['post_keywords'])) {
//加入标签
$data['post_keywords'] = str_replace(',', ',', $data['post_keywords']);
$keywords = explode(',', $data['post_keywords']);
}
$this->addTags($keywords, $data['id']);
return $this;
}
/**
* 根据文章关键字,增加标签
* @param array $keywords 文章关键字数组
* @param int $articleId 文章id
* @return void
*/
public function addTags($keywords, $articleId)
{
foreach ($keywords as $key => $value) {
$keywords[$key] = trim($value);
}
$continue = true;
$names = $this->tags()->column('name');
if (!empty($keywords) || !empty($names)) {
if (!empty($names)) {
$sameNames = array_intersect($keywords, $names);
$keywords = array_diff($keywords, $sameNames);
$shouldDeleteNames = array_diff($names, $sameNames);
if (!empty($shouldDeleteNames)) {
$tagIdNames = $this->tags()
->where('name', 'in', $shouldDeleteNames)
->column('pivot.id', 'tag_id');
$tagIds = array_keys($tagIdNames);
$tagPostIds = array_values($tagIdNames);
$tagPosts = DB::name('portal_tag_post')->where('tag_id', 'in', $tagIds)
->field('id,tag_id,post_id')
->select();
$keepTagIds = [];
foreach ($tagPosts as $key => $tagPost) {
if ($articleId != $tagPost['post_id']) {
array_push($keepTagIds, $tagPost['tag_id']);
}
}
$keepTagIds = array_unique($keepTagIds);
$shouldDeleteTagIds = array_diff($tagIds, $keepTagIds);
DB::name('PortalTag')->delete($shouldDeleteTagIds);
DB::name('PortalTagPost')->delete($tagPostIds);
}
} else {
$tagIdNames = DB::name('portal_tag')->where('name', 'in', $keywords)->column('name', 'id');
if (!empty($tagIdNames)) {
$tagIds = array_keys($tagIdNames);
$this->tags()->attach($tagIds);
$keywords = array_diff($keywords, array_values($tagIdNames));
if (empty($keywords)) {
$continue = false;
}
}
}
if ($continue) {
foreach ($keywords as $key => $value) {
if (!empty($value)) {
$this->tags()->attach(['name' => $value]);
}
}
}
}
}
/**
* 设置缩略图,图片,附件
* 懒人方法
* @param $data 表单数据
*/
public function setMoreField($data)
{
$allowField = [
'post_title','post_keywords','post_source',
'post_excerpt','post_content','more',
'published_time'
];
if (!empty($data['more'])) {
$data['more'] = $this->setMoreUrl($data['more']);
}
if (!empty($data['thumbnail'])) {
$data['more']['thumbnail'] = cmf_asset_relative_url($data['thumbnail']);
}
return [$data,$allowField];
}
/**
* 获取图片附件url相对地址
* 默认上传名字 *_names 地址 *_urls
* @param $annex 上传附件
* @return array
*/
public function setMoreUrl($annex)
{
$more = [];
if (!empty($annex)) {
foreach ($annex as $key => $value) {
$nameArr = $key . '_names';
$urlArr = $key . '_urls';
if (is_string($value[$nameArr]) && is_string($value[$urlArr])) {
$more[$key] = [$value[$nameArr], $value[$urlArr]];
} elseif (!empty($value[$nameArr]) && !empty($value[$urlArr])) {
$more[$key] = [];
foreach ($value[$urlArr] as $k => $url) {
$url = cmf_asset_relative_url($url);
array_push($more[$key], ['url' => $url, 'name' => $value[$nameArr][$k]]);
}
}
}
}
return $more;
}
/**
* 删除文章
* @param $ids int|array 文章id
* @param int $userId 文章所属用户id [可选]
* @return bool|int 删除结果 true 成功 false 失败 -1 文章不存在
*/
public function deleteArticle($ids, $userId)
{
$time = time();
$result = false;
$where = [];
if (!empty($userId)) {
if (is_numeric($ids)) {
$article = $this->find($ids);
if (!empty($article)) {
if ($this->isUserPost($ids, $userId) || $userId == 1) {
$where['id'] = $ids;
}
}
} else {
$ids = $this->strToArr($ids);
$articles = $this->where('id', 'in', $ids)->select();
if (!empty($articles)) {
$deleteIds = $this->isUserPosts($ids, $userId);
if (!empty($deleteIds)) {
$where['id'] = ['in', $deleteIds];
}
}
}
} else {
if (is_numeric($ids)) {
$article = $this->find($ids);
if (!empty($article)) {
$where['id'] = $ids;
}
} else {
$ids = $this->strToArr($ids);
$articles = $this->where('id', 'in', $ids)->select();
if (!empty($articles)) {
$where['id'] = ['in', $ids];
}
}
}
if (empty($article) && empty($articles)) {
return -1;
}
if (!empty($where)) {
$result = $this->useGlobalScope(false)
->where($where)
->setField('delete_time', $time);
}
if ($result) {
$data = [
'create_time' => $time,
'table_name' => 'portal_post'
];
if (!empty($article)) {
$data['name'] = $article['post_title'];
$article->recycleBin()->save($data);
}
if (!empty($articles)) {
foreach ($articles as $article) {
$data['name'] = $article['post_title'];
$article->recycleBin()->save($data);
}
}
}
return $result;
}
/**
* 判断文章所属用户是否为当前用户,超级管理员除外
* @params int $id 文章id
* @param int $userId 当前用户id
* @return boolean 是 true , 否 false
*/
public function isUserPost($id, $userId)
{
$postUserId = $this->useGlobalScope(false)
->getFieldById($id, 'user_id');
if ($postUserId != $userId || $userId != 1) {
return false;
} else {
return true;
}
}
/**
* 过滤属于当前用户的文章,超级管理员除外
* @params array $ids 文章id的数组
* @param int $userId 当前用户id
* @return array 属于当前用户的文章id
*/
public function isUserPosts($ids, $userId)
{
$postIds = $this->useGlobalScope(false)
->where('user_id', $userId)
->where('id', 'in', $ids)
->column('id');
return array_intersect($ids, $postIds);
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: pl125 <xskjs888@163.com>
// +----------------------------------------------------------------------
namespace api\portal\model;
use api\common\model\CommonModel;
class PortalCategoryModel extends CommonModel
{
//类型转换
protected $type = [
'more' => 'array',
];
//可查询字段
protected $visible = [
'id', 'name', 'description', 'post_count',
'seo_title', 'seo_keywords', 'seo_description',
'list_order','more', 'PostIds', 'articles'
];
//模型关联方法
protected $relationFilter = ['articles'];
/**
* 基础查询
*/
protected function base($query)
{
$query->alias('portal_category')->where('delete_time', 0)
->where('portal_category.status', 1);
}
/**
* more 自动转化
* @param $value
* @return array
*/
public function getMoreAttr($value)
{
$more = json_decode($value, true);
if (!empty($more['thumbnail'])) {
$more['thumbnail'] = cmf_get_image_url($more['thumbnail']);
}
if (!empty($more['photos'])) {
foreach ($more['photos'] as $key => $value) {
$more['photos'][$key]['url'] = cmf_get_image_url($value['url']);
}
}
return $more;
}
/**
* 关联文章表
* @return $this
*/
public function articles()
{
return $this->belongsToMany('PortalPostModel', 'portal_category_post', 'post_id', 'category_id');
}
/**
* [PostIds 关联]
* @Author: wuwu<15093565100@163.com>
* @DateTime: 2017-07-17T15:20:31+0800
* @since: 1.0
*/
public function PostIds()
{
return self::hasMany('PortalCategoryPostModel', 'category_id', 'id');
}
/**
* [categoryPostIds 此类文章id数组]
* @Author: wuwu<15093565100@163.com>
* @DateTime: 2017-07-17T15:21:08+0800
* @since: 1.0
* @param [type] $category_id [分类ID]
* @return [type] [文章id数组]
*/
public static function categoryPostIds($category_id)
{
$ids = [];
$post_ids = self::relation('PostIds')->field(true)->where('id', $category_id)->find();
foreach ($post_ids['PostIds'] as $key => $id) {
$ids[] = $id['post_id'];
}
$post_ids['PostIds'] = $ids;
return $post_ids;
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: wuwu <15093565100@163.com>
// +----------------------------------------------------------------------
namespace api\portal\model;
use think\Model;
class PortalCategoryPostModel extends Model
{
/**
* 基础查询
*/
protected function base($query)
{
$query->where('status', 1);
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: pl125 <xskjs888@163.com>
// +----------------------------------------------------------------------
namespace api\portal\model;
use think\Db;
use api\common\model\CommonModel;
class PortalPostModel extends CommonModel
{
//可查询字段
protected $visible = [
'id', 'articles.id', 'user_id', 'post_id', 'post_type', 'comment_status',
'is_top', 'recommended', 'post_hits', 'post_like', 'post_favorites','comment_count',
'create_time', 'update_time', 'published_time', 'post_title', 'post_keywords',
'post_excerpt', 'post_source', 'post_content', 'more', 'user_nickname',
'user', 'category_id'
];
//设置只读字段
protected $readonly = ['user_id'];
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = true;
//类型转换
protected $type = [
'more' => 'array',
];
//模型关联方法
protected $relationFilter = ['user', 'categories'];
/**
* 基础查询
*/
protected function base($query)
{
$query->where('delete_time', 0)
->where('post_status', 1)
->whereTime('published_time', 'between', [1, time()]);
}
/**
* 关联 user表
* @return $this
*/
public function user()
{
return $this->belongsTo('api\portal\model\UserModel', 'user_id');
}
/**
* 关联 user表
* @return $this
*/
public function articleUser()
{
return $this->belongsTo('api\portal\model\UserModel', 'user_id')->field('id,user_nickname');
}
/**
* 关联分类表
* @return $this
*/
public function categories()
{
return $this->belongsToMany('api\portal\model\PortalCategoryModel', 'portal_category_post', 'category_id', 'post_id');
}
/**
* 关联标签表
* @return $this
*/
public function tags()
{
return $this->belongsToMany('api\portal\model\PortalTagModel', 'portal_tag_post', 'tag_id', 'post_id');
}
/**
* 关联 回收站 表
*/
public function recycleBin()
{
return $this->hasOne('api\portal\model\RecycleBinModel', 'object_id');
}
/**
* published_time 自动转化
* @param $value
* @return string
*/
public function getPublishedTimeAttr($value)
{
// 兼容老版本 1.0.0的客户端
$apiVersion = request()->header('XX-Api-Version');
if (empty($apiVersion)) {
return date('Y-m-d H:i:s', $value);
} else {
return $value;
}
}
/**
* published_time 自动转化
* @param $value
* @return int
*/
public function setPublishedTimeAttr($value)
{
if (is_numeric($value)) {
return $value;
}
return strtotime($value);
}
public function getPostTitleAttr($value)
{
return htmlspecialchars_decode($value);
}
public function getPostExcerptAttr($value)
{
return htmlspecialchars_decode($value);
}
/**
* post_content 自动转化
* @param $value
* @return string
*/
public function getPostContentAttr($value)
{
return cmf_replace_content_file_url(htmlspecialchars_decode($value));
}
/**
* post_content 自动转化
* @param $value
* @return string
*/
public function setPostContentAttr($value)
{
return htmlspecialchars(cmf_replace_content_file_url(htmlspecialchars_decode($value), true));
}
/**
* more 自动转化
* @param $value
* @return array
*/
public function getMoreAttr($value)
{
$more = json_decode($value, true);
if (!empty($more['thumbnail'])) {
$more['thumbnail'] = cmf_get_image_url($more['thumbnail']);
}
if (!empty($more['photos'])) {
foreach ($more['photos'] as $key => $value) {
$more['photos'][$key]['url'] = cmf_get_image_url($value['url']);
}
}
if (!empty($more['files'])) {
foreach ($more['files'] as $key => $value) {
$more['files'][$key]['url'] = cmf_get_file_download_url($value['url']);
}
}
return $more;
}
/**
* 获取用户文章
*/
public function getUserArticles($userId, $params)
{
$where = [
'post_type' => 1,
'user_id' => $userId
];
$params['where'] = $where;
return $this->getDatas($params);;
}
/**
* 会员添加文章
* @param array $data 文章数据
* @return $this
*/
public function addArticle($data)
{
if (!empty($data['more'])) {
$data['more'] = $this->setMoreUrl($data['more']);
}
if (!empty($data['thumbnail'])) {
$data['more']['thumbnail'] = cmf_asset_relative_url($data['thumbnail']);
}
$this->allowField(true)->data($data, true)->isUpdate(false)->save();
$categories = $this->strToArr($data['categories']);
$this->categories()->attach($categories);
if (!empty($data['post_keywords']) && is_string($data['post_keywords'])) {
//加入标签
$data['post_keywords'] = str_replace(',', ',', $data['post_keywords']);
$keywords = explode(',', $data['post_keywords']);
$this->addTags($keywords, $this->id);
}
return $this;
}
/**
* 会员文章编辑
* @param array $data 文章数据
* @param int $id 文章id
* @param int $userId 文章所属用户id [可选]
* @return boolean 成功 true 失败 false
*/
public function editArticle($data, $id, $userId = '')
{
if (!empty($userId)) {
$isBelong = $this->isuserPost($id, $userId);
if ($isBelong === false) {
return $isBelong;
}
}
if (!empty($data['more'])) {
$data['more'] = $this->setMoreUrl($data['more']);
}
if (!empty($data['thumbnail'])) {
$data['more']['thumbnail'] = cmf_asset_relative_url($data['thumbnail']);
}
$data['id'] = $id;
$data['post_status'] = empty($data['post_status']) ? 0 : 1;
$data['is_top'] = empty($data['is_top']) ? 0 : 1;
$data['recommended'] = empty($data['recommended']) ? 0 : 1;
$this->allowField(true)->data($data, true)->isUpdate(true)->save();
$categories = $this->strToArr($data['categories']);
$oldCategoryIds = $this->categories()->column('category_id');
$sameCategoryIds = array_intersect($categories, $oldCategoryIds);
$needDeleteCategoryIds = array_diff($oldCategoryIds, $sameCategoryIds);
$newCategoryIds = array_diff($categories, $sameCategoryIds);
if (!empty($needDeleteCategoryIds)) {
$this->categories()->detach($needDeleteCategoryIds);
}
if (!empty($newCategoryIds)) {
$this->categories()->attach(array_values($newCategoryIds));
}
$keywords = [];
if (!empty($data['post_keywords'])) {
if (is_string($data['post_keywords'])) {
//加入标签
$data['post_keywords'] = str_replace(',', ',', $data['post_keywords']);
$keywords = explode(',', $data['post_keywords']);
}
}
$this->addTags($keywords, $data['id']);
return $this;
}
/**
* 根据文章关键字,增加标签
* @param array $keywords 文章关键字数组
* @param int $articleId 文章id
* @return void
*/
public function addTags($keywords, $articleId)
{
foreach ($keywords as $key => $value) {
$keywords[$key] = trim($value);
}
$continue = true;
$names = $this->tags()->column('name');
if (!empty($keywords) || !empty($names)) {
if (!empty($names)) {
$sameNames = array_intersect($keywords, $names);
$keywords = array_diff($keywords, $sameNames);
$shouldDeleteNames = array_diff($names, $sameNames);
if (!empty($shouldDeleteNames)) {
$tagIdNames = $this->tags()
->where('name', 'in', $shouldDeleteNames)
->column('pivot.id', 'tag_id');
$tagIds = array_keys($tagIdNames);
$tagPostIds = array_values($tagIdNames);
$tagPosts = DB::name('portal_tag_post')->where('tag_id', 'in', $tagIds)
->field('id,tag_id,post_id')
->select();
$keepTagIds = [];
foreach ($tagPosts as $key => $tagPost) {
if ($articleId != $tagPost['post_id']) {
array_push($keepTagIds, $tagPost['tag_id']);
}
}
$keepTagIds = array_unique($keepTagIds);
$shouldDeleteTagIds = array_diff($tagIds, $keepTagIds);
DB::name('PortalTag')->delete($shouldDeleteTagIds);
DB::name('PortalTagPost')->delete($tagPostIds);
}
} else {
$tagIdNames = DB::name('portal_tag')->where('name', 'in', $keywords)->column('name', 'id');
if (!empty($tagIdNames)) {
$tagIds = array_keys($tagIdNames);
$this->tags()->attach($tagIds);
$keywords = array_diff($keywords, array_values($tagIdNames));
if (empty($keywords)) {
$continue = false;
}
}
}
if ($continue) {
foreach ($keywords as $key => $value) {
if (!empty($value)) {
$this->tags()->attach(['name' => $value]);
}
}
}
}
}
/**
* 获取图片附件url相对地址
* 默认上传名字 *_names 地址 *_urls
* @param $annex 上传附件
* @return array
*/
public function setMoreUrl($annex)
{
$more = [];
if (!empty($annex)) {
foreach ($annex as $key => $value) {
$nameArr = $key . '_names';
$urlArr = $key . '_urls';
if (is_string($value[$nameArr]) && is_string($value[$urlArr])) {
$more[$key] = [$value[$nameArr], $value[$urlArr]];
} elseif (!empty($value[$nameArr]) && !empty($value[$urlArr])) {
$more[$key] = [];
foreach ($value[$urlArr] as $k => $url) {
$url = cmf_asset_relative_url($url);
array_push($more[$key], ['url' => $url, 'name' => $value[$nameArr][$k]]);
}
}
}
}
return $more;
}
/**
* 删除文章
* @param $ids int|array 文章id
* @param int $userId 文章所属用户id [可选]
* @return bool|int 删除结果 true 成功 false 失败 -1 文章不存在
*/
public function deleteArticle($ids, $userId = '')
{
$time = time();
$result = false;
$where = [];
if (!empty($userId)) {
if (is_numeric($ids)) {
$article = $this->find($ids);
if (!empty($article)) {
if ($this->isUserPost($ids, $userId) || $userId == 1) {
$where['id'] = $ids;
}
}
} else {
$ids = $this->strToArr($ids);
$articles = $this->where('id', 'in', $ids)->select();
if (!empty($articles)) {
$deleteIds = $this->isUserPosts($ids, $userId);
if (!empty($deleteIds)) {
$where['id'] = ['in', $deleteIds];
}
}
}
} else {
if (is_numeric($ids)) {
$article = $this->find($ids);
if (!empty($article)) {
$where['id'] = $ids;
}
} else {
$ids = $this->strToArr($ids);
$articles = $this->where('id', 'in', $ids)->select();
if (!empty($articles)) {
$where['id'] = ['in', $ids];
}
}
}
if (empty($article) && empty($articles)) {
return -1;
}
if (!empty($where)) {
$result = $this->useGlobalScope(false)
->where($where)
->setField('delete_time', $time);
}
if ($result) {
$data = [
'create_time' => $time,
'table_name' => 'portal_post'
];
if (!empty($article)) {
$data['name'] = $article['post_title'];
$article->recycleBin()->save($data);
}
if (!empty($articles)) {
foreach ($articles as $article) {
$data['name'] = $article['post_title'];
$article->recycleBin()->save($data);
}
}
}
return $result;
}
/**
* 判断文章所属用户是否为当前用户,超级管理员除外
* @params int $id 文章id
* @param int $userId 当前用户id
* @return boolean 是 true , 否 false
*/
public function isUserPost($id, $userId)
{
$postUserId = $this->useGlobalScope(false)
->getFieldById($id, 'user_id');
if ($postUserId == $userId || $userId == 1) {
return true;
} else {
return false;
}
}
/**
* 过滤属于当前用户的文章,超级管理员除外
* @params array $ids 文章id的数组
* @param int $userId 当前用户id
* @return array 属于当前用户的文章id
*/
public function isUserPosts($ids, $userId)
{
$postIds = $this->useGlobalScope(false)
->where('user_id', $userId)
->where('id', 'in', $ids)
->column('id');
return array_intersect($ids, $postIds);
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: pl125 <xskjs888@163.com>
// +----------------------------------------------------------------------
namespace api\portal\model;
use api\common\model\CommonModel;
class PortalTagModel extends CommonModel
{
//可查询字段
protected $visible = [
'id','articles.id','recommended', 'post_count', 'name','articles'
];
//模型关联方法
protected $relationFilter = ['articles'];
/**
* 基础查询
*/
protected function base($query)
{
$query->alias('post_tag')->where('post_tag.status', 1);
}
/**
* 关联 文章表
* @return $this
*/
public function articles()
{
return $this->belongsToMany('PortalPostModel','portal_tag_post','post_id','tag_id');
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: pl125 <xskjs888@163.com>
// +----------------------------------------------------------------------
namespace api\portal\model;
use think\Model;
class PortalTagPostModel extends Model
{
/**
* 获取指定id相关的文章id数组
* @param $post_id 文章id
* @return array 相关的文章id
*/
function getRelationPostIds($post_id)
{
$tagIds = $this->where('post_id', $post_id)
->column('tag_id');
$postIds = $this->whereIn('tag_id', $tagIds)
->column('post_id');
return array_unique($postIds);
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: pl125 <xskjs888@163.com>
// +----------------------------------------------------------------------
namespace api\portal\model;
use think\Model;
class RecycleBinModel extends Model
{
}
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: pl125 <xskjs888@163.com>
// +----------------------------------------------------------------------
namespace api\portal\model;
use api\common\model\CommonModel;
class UserModel extends CommonModel
{
//可查询字段
protected $visible = [
'user_nickname', 'avatar', 'signature','user_url','user_login','birthday','sex'
];
//模型关联方法
protected $relationFilter = ['user'];
/**
* 基础查询
*/
protected function base($query)
{
$query->alias('user')->where('user.user_status', 1);
}
/**
* more 自动转化
* @param $value
* @return array
*/
public function getAvatarAttr($value)
{
$value = !empty($value) ? cmf_get_image_url($value) : $value;
return $value;
}
/**
* 关联 user表
* @return $this
*/
public function user()
{
return $this->belongsTo('UserModel', 'user_id')->setEagerlyType(1);
}
}
... ...
<?php
use think\Route;
Route::resource('portal/categories', 'portal/Categories');
Route::get('portal/categories/subCategories', 'portal/Categories/subCategories');
Route::resource('portal/articles', 'portal/Articles');
Route::resource('portal/pages', 'portal/Pages');
Route::resource('portal/userArticles', 'portal/UserArticles');
Route::get('portal/search', 'portal/Articles/search');
Route::get('portal/articles/my', 'portal/Articles/my');
Route::get('portal/articles/relatedArticles', 'portal/Articles/relatedArticles');
Route::post('portal/articles/doLike', 'portal/Articles/doLike');
Route::post('portal/articles/cancelLike', 'portal/Articles/cancelLike');
Route::post('portal/articles/doFavorite', 'portal/Articles/doFavorite');
Route::post('portal/articles/cancelFavorite', 'portal/Articles/cancelFavorite');
Route::get('portal/tags/:id/articles', 'portal/Tags/articles');
Route::get('portal/tags', 'portal/Tags/index');
Route::get('portal/tags/hotTags', 'portal/Tags/hotTags');
Route::post('portal/userArticles/deletes', 'portal/UserArticles/deletes');
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: pl125 <xskjs888@163.com>
// +----------------------------------------------------------------------
namespace api\portal\service;
use api\portal\model\PortalPostModel as PortalPost;
use api\portal\model\PortalCategoryModel as PortalCategory;
class PortalPostModel extends PortalPost
{
protected $name = "portal_post";
/**
* [recommendedList 推荐列表]
* @Author: wuwu<15093565100@163.com>
* @DateTime: 2017-07-17T11:06:47+0800
* @since: 1.0
* @param integer $next_id [最后索引值]
* @param integer $num [一页多少条 默认10]
* @return [type] [数据]
*/
public static function recommendedList($next_id = 0, $num = 10)
{
$limit = "{$next_id},{$num}";
$field = 'id,recommended,user_id,post_like,post_hits,comment_count,create_time,update_time,published_time,post_title,post_excerpt,more';
$list = self::with('user')->field($field)->where('recommended', 1)->order('published_time DESC')->limit($limit)->select();
return $list;
}
/**
* [categoryPostList 分类文章列表]
* @Author: wuwu<15093565100@163.com>
* @DateTime: 2017-07-17T15:16:26+0800
* @since: 1.0
* @param [type] $category_id [分类ID]
* @param integer $next_id [limit索引]
* @param integer $num [limit每页数量]
* @return [type] [description]
*/
public static function categoryPostList($category_id, $next_id = 0, $num = 10)
{
$limit = "{$next_id},{$num}";
$Postlist = PortalCategory::categoryPostIds($category_id);
$field = 'id,recommended,user_id,post_like,post_hits,comment_count,create_time,update_time,published_time,post_title,post_excerpt,more';
$list = self::with('user')->field($field)->whereIn('id', $Postlist['PostIds'])->order('published_time DESC')->limit($limit)->select()->toJson();
return $list;
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 小夏 < 449134904@qq.com>
// +----------------------------------------------------------------------
namespace api\portal\validate;
use think\Validate;
class ArticlesValidate extends Validate
{
protected $rule = [
'post_title' => 'require',
'post_content' => 'require',
'categories' => 'require'
];
protected $message = [
'post_title.require' => '文章标题不能为空',
'post_content.require' => '内容不能为空',
'categories.require' => '文章分类不能为空'
];
protected $scene = [
'article' => [ 'post_title' , 'post_content' , 'categories' ],
'page' => ['post_title']
];
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
return [
// 应用调试模式
'app_debug' => false,
// 应用Trace
'app_trace' => false,
];
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
$apps = cmf_scan_dir(APP_PATH . '*', GLOB_ONLYDIR);
foreach ($apps as $app) {
$routeFile = APP_PATH . $app . '/route.php';
if (file_exists($routeFile)) {
include_once $routeFile;
}
}
if (file_exists(CMF_ROOT . "data/conf/route.php")) {
$runtimeRoutes = include CMF_ROOT . "data/conf/route.php";
} else {
$runtimeRoutes = [];
}
return $runtimeRoutes;
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
// 应用行为扩展定义文件
return [
// 应用初始化
'app_init' => [
'cmf\\behavior\\InitHookBehavior',
],
// 应用开始
'app_begin' => [
'cmf\\behavior\\LangBehavior',
],
// 模块初始化
'module_init' => [],
// 操作开始执行
'action_begin' => [],
// 视图内容过滤
'view_filter' => [],
// 日志写入
'log_write' => [],
// 应用结束
'app_end' => [],
];
... ...
<?php
// +----------------------------------------------------------------------
// | 文件说明:评论
// +----------------------------------------------------------------------
// | Copyright (c) 2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: wuwu <15093565100@163.com>
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Date: 2017-7-26
// +----------------------------------------------------------------------
namespace api\user\controller;
use api\user\model\CommentModel as Comment;
use api\user\model\UserModel as User;
use cmf\controller\RestBaseController;
class CommentsController extends RestBaseController
{
/**
* [getUserComments 获取用户评论]
* @Author: wuwu<15093565100@163.com>
* @DateTime: 2017-05-25T20:48:53+0800
* @since: 1.0
* @return [array_json] [获取Comment]
*/
public function getUserComments()
{
$input = $this->request->param();
$comment = new Comment();
$map['where']['user_id'] = $this->getUserId();
$map['order'] = '-create_time';
$map['relation'] = 'user,to_user';
if (!empty($input['page'])) {
$map['page'] = $input['page'];
}
//处理不同的情况
$data = $comment->getDatas($map);
if (empty($this->apiVersion) || $this->apiVersion == '1.0.0') {
$response = [$data];
} else {
$response = ['list' => $data];
}
$this->success('请求成功', $response);
}
/**
* [getComments 获取评论]
* @Author: wuwu<15093565100@163.com>
* @DateTime: 2017-05-25T20:48:53+0800
* @since: 1.0
* @return [array_json] [获取Comment]
*/
public function getComments()
{
$input = $this->request->param();
$id = $this->request->has('object_id') ? $input['object_id'] : $this->error('id参数不存在');
$table = $this->request->has('table_name') ? $input['table_name'] : $this->error('table参数不存在');
$comment = new Comment();
$map['where'] = [
'object_id' => $id,
'table_name' => $table
];
$map['relation'] = 'user,to_user';
if (!empty($input['page'])) {
$map['page'] = $input['page'];
}
$data = $comment->getDatas($map);
if (empty($this->apiVersion) || $this->apiVersion == '1.0.0') {
$response = [$data];
} else {
$response = ['list' => $data];
}
//数据是否存在
if ($data->isEmpty()) {
$this->error('评论数据为空');
} else {
$this->success('评论获取成功!', $response);
}
}
/**
* [delComments 删除评论]
* @Author: wuwu<15093565100@163.com>
* @DateTime: 2017-08-11T22:08:56+0800
* @since: 1.0
* @return
*/
public function delComments()
{
$input = $this->request->param();
$id = $this->request->has('id') ? intval($input['id']) : $this->error('id参数不存在');
$userId = $this->getUserId();
Comment::destroy(['id' => $id, 'user_id' => $userId]);
$this->success('删除成功');
}
/**
* [setComments 添加评论]
* @Author: wuwu<15093565100@163.com>
* @DateTime: 2017-08-16T01:07:44+0800
* @since: 1.0
*/
public function setComments()
{
$data = $this->_setComments();
if ($res = Comment::setComment($data)) {
$this->success('评论成功', $res);
} else {
$this->error('评论失败');
}
}
/**
* [_setComments 评论数据组织]
* @Author: wuwu<15093565100@163.com>
* @DateTime: 2017-08-16T01:00:02+0800
* @since: 1.0
*/
protected function _setComments()
{
$input = $this->request->param();
$data['object_id'] = $this->request->has('object_id') ? $input['object_id'] : $this->error('object_id参数不存在');
$data['table_name'] = $this->request->has('table_name') ? $input['table_name'] : $this->error('table_name参数不存在');
$data['url'] = $this->request->has('url') ? $input['url'] : $this->error('url参数不存在');
$data['content'] = $this->request->has('content') ? $input['content'] : $this->error('内容不为空');
$data['parent_id'] = $this->request->has('parent_id') ? $input['parent_id'] : 0;
$result = $this->validate($data,
[
'object_id' => 'require|number',
'content' => 'require',
]);
if (true !== $result) {
// 验证失败 输出错误信息
$this->error($result);
}
$data['delete_time'] = 0;
$data['create_time'] = time();
if ($data['parent_id']) {
$res = Comment::field(['parent_id', 'path', 'user_id'])->find($data['parent_id']);
if ($res) {
$data['path'] = $res['path'] . $data['parent_id'] . ',';
$data['to_user_id'] = $res['user_id'];
} else {
$this->error('回复的评论不存在');
}
} else {
$data['path'] = '0,';
}
$data['user_id'] = $this->getUserId();
$userData = User::field(true)->find($data['user_id']);
if (!$userData) {
$this->error('评论用户不存在');
}
$data['full_name'] = $userData['user_nickname'];
$data['email'] = $userData['user_email'];
return $data;
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: pl125 <xskjs888@163.com>
// +----------------------------------------------------------------------
namespace api\user\controller;
use api\user\model\UserFavoriteModel;
use cmf\controller\RestBaseController;
use think\Validate;
class FavoritesController extends RestBaseController
{
protected $userFavoriteModel;
public function __construct(UserFavoriteModel $userFavoriteModel)
{
parent::__construct();
$this->userFavoriteModel = $userFavoriteModel;
}
/**
* 显示收藏列表
*/
public function getFavorites()
{
$userId = $this->getUserId();
$param = $this->request->param();
$param['where'] = [
'user_id' => $userId
];
$param['order'] = '-create_time';
$favoriteData = $this->userFavoriteModel->getDatas($param);
if (empty($this->apiVersion) || $this->apiVersion == '1.0.0') {
$response = $favoriteData;
} else {
$response = ['list' => $favoriteData,];
}
$this->success('请求成功', $response);
}
/**
* [setFavorites 添加收藏]
* @Author: wuwu<15093565100@163.com>
* @DateTime: 2017-08-03T09:03:40+0800
* @since: 1.0
*/
public function setFavorites()
{
$input = $this->request->param();
//组装数据
$data = $this->_FavoritesObject($input['title'], $input['url'], $input['description'], $input['table_name'], $input['object_id']);
if (!$data) {
$this->error('收藏失败');
}
if ($this->userFavoriteModel->where(['user_id' => $this->getUserId(), 'object_id' => $input['object_id']])->where('table_name', $input['table_name'])->count() > 0) {
$this->error('已收藏', ['code' => 1]);
}
$favoriteId = $this->userFavoriteModel->setFavorite($data);
if ($favoriteId) {
$this->success('收藏成功', ['id' => $favoriteId]);
} else {
$this->error('收藏失败');
}
}
/**
* [_FavoritesObject 收藏数据组装]
* @Author: wuwu<15093565100@163.com>
* @DateTime: 2017-08-03T09:39:06+0800
* @since: 1.0
* @return [type] [description]
*/
protected function _FavoritesObject($title, $url, $description, $table_name, $object_id)
{
$data['user_id'] = $this->getUserId();
$data['create_time'] = THINK_START_TIME;
if (empty($title)) {
return false;
} else if (empty($url)) {
return false;
} elseif (empty($table_name)) {
return false;
} elseif (empty($object_id)) {
return false;
}
$data['title'] = $title;
$data['url'] = htmlspecialchars_decode($url);
$data['description'] = $description;
$data['table_name'] = $table_name;
$data['object_id'] = $object_id;
return $data;
}
/**
* [unsetFavorites 取消收藏]
* @Author: wuwu<15093565100@163.com>
* @DateTime: 2017-08-03T09:04:31+0800
* @since: 1.0
* @return [type] [description]
*/
public function unsetFavorites()
{
$id = $this->request->param('id', 0, 'intval');
$userId = $this->getUserId();
$count = $this->userFavoriteModel->where(['id' => $id, 'user_id' => $userId])->count();
if ($count == 0) {
$this->error('收藏不存在,无法取消');
}
$this->userFavoriteModel->where(['id' => $id])->delete();
$this->success('取消成功');
}
/**
* 判断是否已经收藏
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function hasFavorite()
{
$input = $this->request->param();
$validate = new Validate([
'table_name' => 'require',
'object_id' => 'require',
]);
if (!$validate->check($input)) {
$this->error($validate->getError());
}
$userId = $this->userId;
if (empty($this->userId)) {
$this->error('用户登录');
}
$findFavorite = $this->userFavoriteModel->where([
'table_name' => $input['table_name'],
'user_id' => $userId,
'object_id' => intval($input['object_id'])
])->find();
if ($findFavorite) {
$this->success('success', $findFavorite);
} else {
$this->error('用户未收藏');
}
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace api\user\controller;
use cmf\controller\RestUserBaseController;
use think\Db;
use think\Validate;
class ProfileController extends RestUserBaseController
{
// 用户密码修改
public function changePassword()
{
$validate = new Validate([
'old_password' => 'require',
'password' => 'require',
'confirm_password' => 'require|confirm:password'
]);
$validate->message([
'old_password.require' => '请输入您的旧密码!',
'password.require' => '请输入您的新密码!',
'confirm_password.require' => '请输入确认密码!',
'confirm_password.confirm' => '两次输入的密码不一致!'
]);
$data = $this->request->param();
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$userId = $this->getUserId();
$userPassword = Db::name("user")->where('id', $userId)->value('user_pass');
if (!cmf_compare_password($data['old_password'], $userPassword)) {
$this->error('旧密码不正确!');
}
Db::name("user")->where('id', $userId)->update(['user_pass' => cmf_password($data['password'])]);
$this->success("密码修改成功!");
}
// 用户绑定邮箱
public function bindingEmail()
{
$validate = new Validate([
'email' => 'require|email|unique:user,user_email',
'verification_code' => 'require'
]);
$validate->message([
'email.require' => '请输入您的邮箱!',
'email.email' => '请输入正确的邮箱格式!',
'email.unique' => '邮箱账号已存在!',
'verification_code.require' => '请输入数字验证码!'
]);
$data = $this->request->param();
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$userId = $this->getUserId();
$userEmail = Db::name("user")->where('id', $userId)->value('user_email');
if (!empty($userEmail)) {
$this->error("您已经绑定邮箱!");
}
$errMsg = cmf_check_verification_code($data['email'], $data['verification_code']);
if (!empty($errMsg)) {
$this->error($errMsg);
}
Db::name("user")->where('id', $userId)->update(['user_email' => $data['email']]);
$this->success("绑定成功!");
}
// 用户绑定手机号
public function bindingMobile()
{
$validate = new Validate([
'mobile' => 'require|unique:user,mobile',
'verification_code' => 'require'
]);
$validate->message([
'mobile.require' => '请输入您的手机号!',
'mobile.unique' => '手机号已经存在!',
'verification_code.require' => '请输入数字验证码!'
]);
$data = $this->request->param();
if (!$validate->check($data)) {
$this->error($validate->getError());
}
if (!cmf_check_mobile($data['mobile'])) {
$this->error("请输入正确的手机格式!");
}
$userId = $this->getUserId();
$mobile = Db::name("user")->where('id', $userId)->value('mobile');
if (!empty($mobile)) {
$this->error("您已经绑定手机!");
}
$errMsg = cmf_check_verification_code($data['mobile'], $data['verification_code']);
if (!empty($errMsg)) {
$this->error($errMsg);
}
Db::name("user")->where('id', $userId)->update(['mobile' => $data['mobile']]);
$this->success("绑定成功!");
}
/**
* 用户基本信息获取及修改
* @param 请求为GET 获取信息
* @param [string] $[field] [要获取的一个或多个字段名] 可选
* @return 带参数,返回某个或多个字段信息。不带参数,返回所有信息
* @param 请求为POST 修改信息
*/
public function userInfo($field = '')
{
//判断请求为GET,获取信息
if ($this->request->isGet()) {
$userId = $this->getUserId();
$fieldStr = 'user_type,user_login,mobile,user_email,user_nickname,avatar,signature,user_url,sex,birthday,score,coin,user_status,user_activation_key,create_time,last_login_time,last_login_ip';
if (empty($field)) {
$userData = Db::name("user")->field($fieldStr)->find($userId);
} else {
$fieldArr = explode(',', $fieldStr);
$postFieldArr = explode(',', $field);
$mixedField = array_intersect($fieldArr, $postFieldArr);
if (empty($mixedField)) {
$this->error('您查询的信息不存在!');
}
if (count($mixedField) > 1) {
$fieldStr = implode(',', $mixedField);
$userData = Db::name("user")->field($fieldStr)->find($userId);
} else {
$userData = Db::name("user")->where('id', $userId)->value($mixedField);
}
}
$this->success('获取成功!', $userData);
}
//判断请求为POST,修改信息
if ($this->request->isPost()) {
$userId = $this->getUserId();
$fieldStr = 'user_nickname,avatar,signature,user_url,sex,birthday';
$data = $this->request->post();
if (empty($data)) {
$this->error('修改失败,提交表单为空!');
}
if (!empty($data['birthday'])) {
$data['birthday'] = strtotime($data['birthday']);
}
$upData = Db::name("user")->where('id', $userId)->field($fieldStr)->update($data);
if ($upData !== false) {
$this->success('修改成功!');
} else {
$this->error('修改失败!');
}
}
}
public function apply_user()
{
//判断请求为POST,修改信息
if ($this->request->isPost()) {
$userId = $this->getUserId();
$data = $this->request->post();
if (empty($data)) {
$this->error('修改失败,提交表单为空!');
}
$datain['uid'] = $data['uid'];
$datain['type'] = $data['type'];
$datain['yid'] = $userId;
$datain['create_time'] = time();
$upData = Db::name("apply")->insert($datain);
if ($upData !== false) {
$this->success('申请成功!');
} else {
$this->error('申请失败!');
}
}
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace api\user\controller;
use think\Db;
use think\Validate;
use cmf\controller\RestBaseController;
class PublicController extends RestBaseController
{
// 用户注册
public function register()
{
$validate = new Validate([
'username' => 'require',
'password' => 'require',
'verification_code' => 'require'
]);
$validate->message([
'username.require' => '请输入手机号,邮箱!',
'password.require' => '请输入您的密码!',
'verification_code.require' => '请输入数字验证码!'
]);
$data = $this->request->param();
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$user = [];
$findUserWhere = [];
if (Validate::is($data['username'], 'email')) {
$user['user_email'] = $data['username'];
$findUserWhere['user_email'] = $data['username'];
} else if (cmf_check_mobile($data['username'])) {
$user['mobile'] = $data['username'];
$findUserWhere['mobile'] = $data['username'];
} else {
$this->error("请输入正确的手机或者邮箱格式!");
}
$errMsg = cmf_check_verification_code($data['username'], $data['verification_code']);
if (!empty($errMsg)) {
$this->error($errMsg);
}
$findUserCount = Db::name("user")->where($findUserWhere)->count();
if ($findUserCount > 0) {
$this->error("此账号已存在!");
}
$user['create_time'] = time();
$user['user_status'] = 1;
$user['user_type'] = 2;
$user['user_pass'] = cmf_password($data['password']);
$result = Db::name("user")->insert($user);
if (empty($result)) {
$this->error("注册失败,请重试!");
}
$this->success("注册并激活成功,请登录!");
}
// 用户登录 TODO 增加最后登录信息记录,如 ip
public function login()
{
$validate = new Validate([
'username' => 'require',
'password' => 'require'
]);
$validate->message([
'username.require' => '请输入手机号,邮箱或用户名!',
'password.require' => '请输入您的密码!'
]);
$data = $this->request->param();
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$findUserWhere = [];
if (Validate::is($data['username'], 'email')) {
$findUserWhere['user_email'] = $data['username'];
} else if (cmf_check_mobile($data['username'])) {
$findUserWhere['mobile'] = $data['username'];
} else {
$findUserWhere['user_login'] = $data['username'];
}
$findUser = Db::name("user")->where($findUserWhere)->find();
if (empty($findUser)) {
$this->error("用户不存在!");
} else {
switch ($findUser['user_status']) {
case 0:
$this->error('您已被拉黑!');
case 2:
$this->error('账户还没有验证成功!');
}
if (!cmf_compare_password($data['password'], $findUser['user_pass'])) {
$this->error("密码不正确!");
}
}
$allowedDeviceTypes = $this->allowedDeviceTypes;
if (empty($data['device_type']) || !in_array($data['device_type'], $allowedDeviceTypes)) {
$this->error("请求错误,未知设备!");
}
$userTokenQuery = Db::name("user_token")
->where('user_id', $findUser['id'])
->where('device_type', $data['device_type']);
$findUserToken = $userTokenQuery->find();
$currentTime = time();
$expireTime = $currentTime + 24 * 3600 * 180;
$token = md5(uniqid()) . md5(uniqid());
if (empty($findUserToken)) {
$result = $userTokenQuery->insert([
'token' => $token,
'user_id' => $findUser['id'],
'expire_time' => $expireTime,
'create_time' => $currentTime,
'device_type' => $data['device_type']
]);
} else {
$result = $userTokenQuery
->where('user_id', $findUser['id'])
->where('device_type', $data['device_type'])
->update([
'token' => $token,
'expire_time' => $expireTime,
'create_time' => $currentTime
]);
}
if (empty($result)) {
$this->error("登录失败!");
}
$this->success("登录成功!", ['token' => $token, 'user' => $findUser]);
}
// 用户退出
public function logout()
{
$userId = $this->getUserId();
Db::name('user_token')->where([
'token' => $this->token,
'user_id' => $userId,
'device_type' => $this->deviceType
])->update(['token' => '']);
$this->success("退出成功!");
}
// 用户密码重置
public function passwordReset()
{
$validate = new Validate([
'username' => 'require',
'password' => 'require',
'verification_code' => 'require'
]);
$validate->message([
'username.require' => '请输入手机号,邮箱!',
'password.require' => '请输入您的密码!',
'verification_code.require' => '请输入数字验证码!'
]);
$data = $this->request->param();
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$userWhere = [];
if (Validate::is($data['username'], 'email')) {
$userWhere['user_email'] = $data['username'];
} else if (cmf_check_mobile($data['username'])) {
$userWhere['mobile'] = $data['username'];
} else {
$this->error("请输入正确的手机或者邮箱格式!");
}
$errMsg = cmf_check_verification_code($data['username'], $data['verification_code']);
if (!empty($errMsg)) {
$this->error($errMsg);
}
$userPass = cmf_password($data['password']);
Db::name("user")->where($userWhere)->update(['user_pass' => $userPass]);
$this->success("密码重置成功,请使用新密码登录!");
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace api\user\controller;
use cmf\controller\RestUserBaseController;
use think\Db;
class UploadController extends RestUserBaseController
{
// 用户密码修改
public function one()
{
$file = $this->request->file('file');
// 移动到框架应用根目录/public/upload/ 目录下
$info = $file->validate([
/*'size' => 15678,*/
'ext' => 'jpg,png,gif'
]);
$fileMd5 = $info->md5();
$fileSha1 = $info->sha1();
$findFile = Db::name("asset")->where('file_md5', $fileMd5)->where('file_sha1', $fileSha1)->find();
if (!empty($findFile)) {
$this->success("上传成功!", ['url' => $findFile['file_path'], 'filename' => $findFile['filename']]);
}
$info = $info->move(ROOT_PATH . 'public' . DS . 'upload');
if ($info) {
$saveName = $info->getSaveName();
$originalName = $info->getInfo('name');//name,type,size
$fileSize = $info->getInfo('size');
$suffix = $info->getExtension();
$fileKey = $fileMd5 . md5($fileSha1);
$userId = $this->getUserId();
Db::name('asset')->insert([
'user_id' => $userId,
'file_key' => $fileKey,
'filename' => $originalName,
'file_size' => $fileSize,
'file_path' => $saveName,
'file_md5' => $fileMd5,
'file_sha1' => $fileSha1,
'create_time' => time(),
'suffix' => $suffix
]);
$this->success("上传成功!", ['url' => $saveName, 'filename' => $originalName]);
} else {
// 上传失败获取错误信息
$this->error($file->getError());
}
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace api\user\controller;
use cmf\controller\RestBaseController;
use think\Validate;
use think\View;
class VerificationCodeController extends RestBaseController
{
public function send()
{
$validate = new Validate([
'username' => 'require',
]);
$validate->message([
'username.require' => '请输入手机号或邮箱!',
]);
$data = $this->request->param();
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$accountType = '';
if (Validate::is($data['username'], 'email')) {
$accountType = 'email';
} else if (cmf_check_mobile($data['username'])) {
$accountType = 'mobile';
} else {
$this->error("请输入正确的手机或者邮箱格式!");
}
//TODO 限制 每个ip 的发送次数
$code = cmf_get_verification_code($data['username']);
if (empty($code)) {
$this->error("验证码发送过多,请明天再试!");
}
if ($accountType == 'email') {
$emailTemplate = cmf_get_option('email_template_verification_code');
$user = cmf_get_current_user();
$username = empty($user['user_nickname']) ? $user['user_login'] : $user['user_nickname'];
$message = htmlspecialchars_decode($emailTemplate['template']);
$view = new View();
$message = $view->display($message, ['code' => $code, 'username' => $username]);
$subject = empty($emailTemplate['subject']) ? 'ThinkCMF验证码' : $emailTemplate['subject'];
$result = cmf_send_email($data['username'], $subject, $message);
if (empty($result['error'])) {
cmf_verification_code_log($data['username'], $code);
$this->success("验证码已经发送成功!");
} else {
$this->error("邮箱验证码发送失败:" . $result['message']);
}
} else if ($accountType == 'mobile') {
$param = ['mobile' => $data['username'], 'code' => $code];
$result = hook_one("send_mobile_verification_code", $param);
if ($result !== false && !empty($result['error'])) {
$this->error($result['message']);
}
if ($result === false) {
$this->error('未安装验证码发送插件,请联系管理员!');
}
cmf_verification_code_log($data['username'], $code);
if (!empty($result['message'])) {
$this->success($result['message']);
} else {
$this->success('验证码已经发送成功!');
}
}
}
}
... ...