mirror of
https://github.com/crmeb/CRMEB.git
synced 2026-03-19 04:04:08 +00:00
上传3.0开源
This commit is contained in:
parent
dba37af54d
commit
4a4ae6370f
3
.constant
Normal file
3
.constant
Normal file
@ -0,0 +1,3 @@
|
||||
<?php
|
||||
define('INSTALL_DATE',1566873827);
|
||||
define('SERIALNUMBER','FmQliB');
|
||||
1
.example.env
Normal file
1
.example.env
Normal file
@ -0,0 +1 @@
|
||||
APP_DEBUG = true
[APP]
DEFAULT_TIMEZONE = Asia/Shanghai
[DATABASE]
TYPE = mysql
HOSTNAME = 192.168.0.108
DATABASE = www_crmeb32_net
USERNAME = www_crmeb32_net
PASSWORD = BEknpBWesr
HOSTPORT = 3306
CHARSET = utf8
DEBUG = true
[LANG]
default_lang = zh-cn
|
||||
8
.gitignore
vendored
Normal file
8
.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
/.idea
|
||||
/.vscode
|
||||
*.log
|
||||
/.env
|
||||
**/*.pid
|
||||
runtime/
|
||||
install.lock
|
||||
public/uploads
|
||||
7
.htaccess
Normal file
7
.htaccess
Normal file
@ -0,0 +1,7 @@
|
||||
<IfModule mod_rewrite.c>
|
||||
Options +FollowSymlinks -Multiviews
|
||||
RewriteEngine On
|
||||
RewriteCond %{REQUEST_FILENAME} !-d
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
|
||||
</IfModule>
|
||||
42
.travis.yml
Normal file
42
.travis.yml
Normal file
@ -0,0 +1,42 @@
|
||||
sudo: false
|
||||
|
||||
language: php
|
||||
|
||||
branches:
|
||||
only:
|
||||
- stable
|
||||
|
||||
cache:
|
||||
directories:
|
||||
- $HOME/.composer/cache
|
||||
|
||||
before_install:
|
||||
- composer self-update
|
||||
|
||||
install:
|
||||
- composer install --no-dev --no-interaction --ignore-platform-reqs
|
||||
- zip -r --exclude='*.git*' --exclude='*.zip' --exclude='*.travis.yml' ThinkPHP_Core.zip .
|
||||
- composer require --update-no-dev --no-interaction "topthink/think-image:^1.0"
|
||||
- composer require --update-no-dev --no-interaction "topthink/think-migration:^1.0"
|
||||
- composer require --update-no-dev --no-interaction "topthink/think-captcha:^1.0"
|
||||
- composer require --update-no-dev --no-interaction "topthink/think-mongo:^1.0"
|
||||
- composer require --update-no-dev --no-interaction "topthink/think-worker:^1.0"
|
||||
- composer require --update-no-dev --no-interaction "topthink/think-helper:^1.0"
|
||||
- composer require --update-no-dev --no-interaction "topthink/think-queue:^1.0"
|
||||
- composer require --update-no-dev --no-interaction "topthink/think-angular:^1.0"
|
||||
- composer require --dev --update-no-dev --no-interaction "topthink/think-testing:^1.0"
|
||||
- zip -r --exclude='*.git*' --exclude='*.zip' --exclude='*.travis.yml' ThinkPHP_Full.zip .
|
||||
|
||||
script:
|
||||
- php think unit
|
||||
|
||||
deploy:
|
||||
provider: releases
|
||||
api_key:
|
||||
secure: TSF6bnl2JYN72UQOORAJYL+CqIryP2gHVKt6grfveQ7d9rleAEoxlq6PWxbvTI4jZ5nrPpUcBUpWIJHNgVcs+bzLFtyh5THaLqm39uCgBbrW7M8rI26L8sBh/6nsdtGgdeQrO/cLu31QoTzbwuz1WfAVoCdCkOSZeXyT/CclH99qV6RYyQYqaD2wpRjrhA5O4fSsEkiPVuk0GaOogFlrQHx+C+lHnf6pa1KxEoN1A0UxxVfGX6K4y5g4WQDO5zT4bLeubkWOXK0G51XSvACDOZVIyLdjApaOFTwamPcD3S1tfvuxRWWvsCD5ljFvb2kSmx5BIBNwN80MzuBmrGIC27XLGOxyMerwKxB6DskNUO9PflKHDPI61DRq0FTy1fv70SFMSiAtUv9aJRT41NQh9iJJ0vC8dl+xcxrWIjU1GG6+l/ZcRqVx9V1VuGQsLKndGhja7SQ+X1slHl76fRq223sMOql7MFCd0vvvxVQ2V39CcFKao/LB1aPH3VhODDEyxwx6aXoTznvC/QPepgWsHOWQzKj9ftsgDbsNiyFlXL4cu8DWUty6rQy8zT2b4O8b1xjcwSUCsy+auEjBamzQkMJFNlZAIUrukL/NbUhQU37TAbwsFyz7X0E/u/VMle/nBCNAzgkMwAUjiHM6FqrKKBRWFbPrSIixjfjkCnrMEPw=
|
||||
file:
|
||||
- ThinkPHP_Core.zip
|
||||
- ThinkPHP_Full.zip
|
||||
skip_cleanup: true
|
||||
on:
|
||||
tags: true
|
||||
674
LICENSE
Normal file
674
LICENSE
Normal file
@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <2017> <西安众邦网络科技有限公司>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||
33
LICENSE.txt
Normal file
33
LICENSE.txt
Normal file
@ -0,0 +1,33 @@
|
||||
版权所有 (c)2017-2027,西安众邦网络科技有限公司 保留所有权利。
|
||||
感谢您选择CrmEb开源客户管理+电商系统(简称CRMEB),CRMEB是国内最稳定、最强大、最先进的互联网电商平台解决方案之一,CRMEB基于 PHP + MySQL 的技术,采用ThinkPHP5.0框架开发。
|
||||
为了使你正确并合法的使用本软件,请你在使用前务必阅读清楚下面的协议条款:
|
||||
本授权协议适用且仅适用于CRMEB任何版本,CRMEB官方对本授权协议的最终解释权和修改权。
|
||||
|
||||
一、协议许可的权利
|
||||
1、您可以在完全遵守本最终用户授权协议的基础上,将本软件应用于非商业用途,而不必支付软件版权授权费用。
|
||||
2、您可以在协议规定的约束和限制范围内修改 CRMEB 源代码或界面风格以适应您的网站要求。
|
||||
3、您拥有使用本软件构建的网站全部内容所有权,并独立承担与这些内容的相关法律义务。
|
||||
4、获得商业授权之后,您可以将本软件应用于商业用途,同时依据所购买的授权类型中确定的技术支持内容。商业授权用户享有反映和提出意见的权力,相关意见将被作为首要考虑,但没有一定被采纳的承诺或保证。
|
||||
|
||||
二、协议许可的权利和限制
|
||||
1、未获商业授权之前,不得删除网站底部及相应的官方版权信息和链接。购买商业授权请联系西安众邦网络科技有限公司了解最新说明。CRMEB著作权已在中华人民共和国国家版权局注册(中国国家版权局著作权登记号 2018SR024463),著作权受到法律和国际公约保护。
|
||||
2、未经官方许可,不得对本软件或与之关联的商业授权进行出租、出售、抵押或发放子许可证。
|
||||
3、不管你的网站是否整体使用 CRMEB ,还是部份栏目使用 CRMEB,在你使用了 CRMEB 的网站主页上必须加上 CRMEB 官方网址(www.crmeb.com)的链接。
|
||||
4、未经官方许可,禁止在 CRMEB 的整体或任何部分基础上以发展任何派生版本、修改版本或第三方版本用于重新分发。
|
||||
5、如果您未能遵守本协议的条款,您的授权将被终止,所被许可的权利将被收回,并承担相应法律责任。
|
||||
|
||||
三、有限担保和免责声明
|
||||
1、本软件及所附带的文件是作为不提供任何明确的或隐含的赔偿或担保的形式提供的。
|
||||
2、用户出于自愿而使用本软件,您必须了解使用本软件的风险,在尚未购买产品技术服务之前,我们不承诺对免费用户提供任何形式的技术支持、使用担保,也不承担任何因使用本软件而产生问题的相关责任。
|
||||
3、电子文本形式的授权协议如同双方书面签署的协议一样,具有完全的和等同的法律效力。您一旦开始确认本协议并安装 CRMEB,即被视为完全理解并接受本协议的各项条款,在享有上述条款授予的权力的同时,受到相关的约束和限制。协议许可范围以外的行为,将直接违反本授权协议并构成侵权,我们有权随时终止授权,责令停止损害,并保留追究相关责任的权力。
|
||||
|
||||
协议发布时间: 2017年8月01日
|
||||
版本最新更新: 2019年8月15日 By CRMEB
|
||||
|
||||
CRMEB官方网站:http://www.crmeb.com
|
||||
CRMEB演示站:http://demo.crmeb.com
|
||||
-----------------------------------------------------
|
||||
运营团队: 众邦科技
|
||||
电 话: 400-8888-794
|
||||
邮 箱: admin@xazbkj.com
|
||||
网 址: http://www.xazbkj.com
|
||||
252
README.md
252
README.md
@ -10,37 +10,82 @@
|
||||
<img src="https://img.shields.io/badge/Licence-GPL3.0-green.svg?style=flat" />
|
||||
</a>
|
||||
<a href="http://www.crmeb.com">
|
||||
<img src="https://img.shields.io/badge/Edition-2.6-blue.svg" />
|
||||
<img src="https://img.shields.io/badge/Edition-3.0-blue.svg" />
|
||||
</a>
|
||||
<a href="https://gitee.com/ZhongBangKeJi/CRMEB/repository/archive/master.zip">
|
||||
<img src="https://img.shields.io/badge/download-81m-red.svg" />
|
||||
<img src="https://img.shields.io/badge/download-80m-red.svg" />
|
||||
</a>
|
||||
</p>
|
||||
|
||||
## 本项目还在不断开发完善中,如有建议或问题请[在这里提出](https://github.com/xazbkj/CRMEB/issues)
|
||||
### 如果对您有帮助,您可以点右上角 "Star" 支持一下 谢谢!
|
||||
+ CRMEB后端程序下载地址
|
||||
|
||||
## 码云项目地址:https://gitee.com/ZhongBangKeJi/CRMEB
|
||||
+ 码云:https://gitee.com/ZhongBangKeJi/CRMEB.git
|
||||
|
||||
+ github:https://github.com/crmeb/CRMEB
|
||||
|
||||
## 纯小程序版:https://github.com/crmeb/CRMEB_WeChatMiniProgram
|
||||
+ 微信小程序版前端界面
|
||||
|
||||
+ github:https://github.com/crmeb/CRMEB_WechatApplet_v3.0
|
||||
|
||||
+ 码云:https://gitee.com/ZhongBangKeJi/CRMEB_WechatApplet_v3.0
|
||||
|
||||
+ H5版前端界面
|
||||
|
||||
+ github:https://github.com/crmeb/CRMEB-H5-v3.0
|
||||
|
||||
+ 码云:https://gitee.com/ZhongBangKeJi/CRMEB-H5-v3.0
|
||||
|
||||
### 帮助文档:
|
||||
https://help.crmeb.net/crmeb
|
||||
### 论坛地址:
|
||||
http://bbs.crmeb.net
|
||||
|
||||
## 帮助文档:http://help.crmeb.net
|
||||
|
||||
## 论坛地址: http://bbs.crmeb.net
|
||||
|
||||
QQ群: 710729856
|
||||
QQ群: 710729856 <a target="_blank" href="//shang.qq.com/wpa/qunwpa?idkey=1794ec6e9fd6ac21bd6519d459d4495e824553693ab0a98a9899e61d68a494d0"><img border="0" src="//pub.idqqimg.com/wpa/images/group.png" alt="CRMEB微信开发四群" title="CRMEB微信开发四群"></a>
|
||||
|
||||
## 获得荣誉
|
||||

|
||||
|
||||
### 如果对您有帮助,您可以点右上角 "Star" 支持一下 谢谢!
|
||||
|
||||
## 演示地址
|
||||
演示站后台:[<a href='http://demo25.crmeb.net' target="_blank"> crmeb_v2.6 </a>]
|
||||
<a href='http://demo25.crmeb.net' target="_blank">http://demo25.crmeb.net</a>
|
||||
<a href='http://demo25.crmeb.net' target="_blank">http://demo26.crmeb.net</a>
|
||||
账号:demo
|
||||
密码:crmeb.com
|
||||
|
||||

|
||||
## CRMEB推荐服务器配置
|
||||
|
||||
<table><tr><td>
|
||||
|
||||
入门级配置
|
||||
```
|
||||
CPU:1核
|
||||
内存:1G
|
||||
实例规格:突发性能t5实例
|
||||
带宽:1M
|
||||
系统:CentOS 7.4 64位(推荐)
|
||||
价格:366元/年 933.3 元/三年
|
||||
```
|
||||
<a href="https://promotion.aliyun.com/ntms/yunparter/invite.html?userCode=dligum2z">查看服务器详情</a>
|
||||
</td>
|
||||
<td>
|
||||
|
||||
标准级配置
|
||||
```
|
||||
CPU:2核
|
||||
内存:4G
|
||||
实例规格:突发性能t5实例
|
||||
带宽:2M
|
||||
系统:CentOS 7.4 64位(推荐)
|
||||
价格:936元/年 2386.8 元/三年
|
||||
```
|
||||
<a href="https://promotion.aliyun.com/ntms/yunparter/invite.html?userCode=dligum2z">查看服务器详情</a>
|
||||
|
||||
</td></tr></table>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## 项目介绍
|
||||
基于ThinkPhp5.0+Vue+EasyWeChat 开发的一套CRMEB新零售商城系统
|
||||
@ -48,14 +93,7 @@ QQ群: 710729856
|
||||
CRMEB系统就是集客户关系管理+营销电商系统,能够真正帮助企业基于微信公众号、小程序、wap、pc、app等,实现会员管理、数据分析,精准营销的电子商务管理系统。可满足企业新零售、批发、分销、预约、O2O、多店等各种业务需求
|
||||
|
||||
CRMEB的优势:快速积累客户、会员数据分析、智能转化客户、有效提高销售、会员维护;
|
||||
|
||||
1.本源码遵循GPL-3.0开源协议,系统采用TP5.0框架;
|
||||
|
||||
2.后台采用form-builder组件和后台多任务操作框架,方便快速开发增删改、封装layui.table 可快速开发数据列表页面、PHPExcel数据导出、数据库在线词典、日志小工具、系统参数配置、系统强大完善的权限控制、系统菜单配置、组合数据模型等这些都是为了方便二次开发而准备的;
|
||||
|
||||
3.前台vue封装了常用小工具,以及所有数据接口;
|
||||
|
||||
|
||||
|
||||
## 技术亮点
|
||||
~~~
|
||||
1.后台应用form-builder PHP快速生成现代化表单;
|
||||
@ -87,18 +125,154 @@ QQ群: 710729856
|
||||
|
||||
5.订单:能够完成用户的订单管理(发货、订单详情、修改订单、订单备注、订单记录、订单退款) 、售后服务 (评论的回复与删除)
|
||||
|
||||
6.分销:后台有分销统计管理,分销可以设置人人分销和指定人分销,也可以自己稍微开发一下修改规
|
||||
6.分销:后台有分销统计管理,分销可以设置人人分销和指定人分销,也可以自己稍微开发一下修改规则,例如下单后成为分销等
|
||||
|
||||
7.数据统计图表统计分析(财务统计、产品统计、会员统计、营销统计、分销统计、交易统计等)
|
||||
|
||||
|
||||
8.设置:能够完成管理员对网站的商品资料(添加大类、添加小类、商品添加、属性快速生成、商品审查)、商品交易(外理订单、发货查询)、会员管理(会员审查)、操作管理(管理员添加、管理员审查、管理员退出)、系统配置、后台通知等功能
|
||||
|
||||
|
||||
9.内容:管理文章分类 (添加分类、删除分类、修改分类) 、 管理文章
|
||||
|
||||
|
||||
10.维护:查看系统日志、文件变动效验、刷新网站缓存、在线更新系统、清除数据、文件管理等功能
|
||||
|
||||
11.权限管理:可以创建不同身份,不同管理员,同一个管理员可以拥有多重身份,权限可以控制到每一个控制器函数,例如:张三 1.可以控制他可以查看产品,但不能编辑产品; 2.可以添加产品,但不能删除产品; 3.可以查看用户但不能给用户发信息、加积分、开通分销等等; 。。。灵活应用,权限想怎么配就怎么配
|
||||
11.权限管理:可以创建不同身份,不同管理员,同一个管理员可以拥有多重身份,权限可以控制到每一个控制器函数,例如:张三
|
||||
1.可以控制他可以查看产品,但不能编辑产品;
|
||||
2.可以添加产品,但不能删除产品;
|
||||
3.可以查看用户但不能给用户发信息、加积分、开通分销等等;
|
||||
。。。灵活应用,权限想怎么配就怎么配
|
||||
|
||||
CRMEB 3.0
|
||||
===============
|
||||
|
||||
> 运行环境要求PHP7.1+。
|
||||
|
||||
## 主要特性
|
||||
|
||||
### 开源无加密
|
||||
源码开源无加密,有详细的代码注释,有完整系统手册...
|
||||
### TP6框架
|
||||
使用最新的 ThinkPHP 6.0框架开发
|
||||
### 前端采用Vue CLI框架
|
||||
前端使用Vue CLI框架nodejs打包,页面加载更流畅,用户体验更好
|
||||
### 标准接口
|
||||
标准接口、前后端分离,二次开发更方便
|
||||
### 支持队列
|
||||
降低流量高峰,解除耦合,高可用
|
||||
### 长连接
|
||||
减少CPU及内存使用及网络堵塞,减少请求响应时长
|
||||
### 无缝事件机制
|
||||
行为扩展更方便,方便二次开发
|
||||
### 后台快速生成表单
|
||||
后台应用form-builder 无需写页面快速增删改查
|
||||
### 数据表格导出
|
||||
PHPExcel数据导出,导出表格更加美观可视;
|
||||
### 数据统计分析
|
||||
后台使用ECharts图表统计,实现用户、产品、订单、资金等统计分析
|
||||
### 强大的后台权限管理
|
||||
后台多种角色、多重身份权限管理,权限可以控制到每一步操作
|
||||
### 一件安装
|
||||
自动检查系统环境一键安装
|
||||
|
||||
## 安装
|
||||
|
||||
## 一键安装
|
||||
上传你的代码,站点入口目录设置/public
|
||||
在浏览器中输入你的域名或IP(例如:www.yourdomain.com),
|
||||
安装程序会自动执行安装。期间系统会提醒你输入数据库信息以完成安装,安装完成后建议删除install目录下index.php文件或将其改名。
|
||||
|
||||
后台访问地址:
|
||||
1.域名/admin
|
||||
2.域名/index.php/admin
|
||||
3.域名/index.php?s=/admin
|
||||
公众号和H5首页访问地址:
|
||||
1.域名/
|
||||
提示:正常访问是第一中模式,第一种访问不了请检测[URL重写](http://help.crmeb.net/895486)是否配置好
|
||||
安装过程中请牢记您的账号密码!
|
||||
|
||||
## 重新安装
|
||||
1. 清除数据库
|
||||
2. 删除/public/install/install.lock 文件
|
||||
|
||||
## 手动安装
|
||||
1.创建数据库,倒入数据库文件
|
||||
数据库文件目录/public/install/crmeb.sql
|
||||
2.修改数据库连接文件
|
||||
配置文件路径/.env
|
||||
~~~
|
||||
APP_DEBUG = true
|
||||
|
||||
[APP]
|
||||
DEFAULT_TIMEZONE = Asia/Shanghai
|
||||
|
||||
[DATABASE]
|
||||
TYPE = mysql
|
||||
HOSTNAME = 127.0.0.1 #数据库连接地址
|
||||
DATABASE = test #数据库名称
|
||||
USERNAME = username #数据库登录账号
|
||||
PASSWORD = password #数据库登录密码
|
||||
HOSTPORT = 3306 #数据库端口
|
||||
CHARSET = utf8
|
||||
DEBUG = true
|
||||
|
||||
[LANG]
|
||||
default_lang = zh-cn
|
||||
~~~
|
||||
3.修改目录权限(linux系统)777
|
||||
/public
|
||||
/runtime
|
||||
4.后台登录:
|
||||
http://域名/admin
|
||||
默认账号:admin 密码:crmeb.com
|
||||
|
||||
## 定时任务
|
||||
在自动收货,库存预警等功能使用到
|
||||
```sh
|
||||
php think timer [ status ] [ --d ]
|
||||
```
|
||||
参数
|
||||
- status: 状态
|
||||
- start: 启动
|
||||
- stop: 关闭
|
||||
- restart: 重启
|
||||
- --d : 后台执行
|
||||
## 长连接服务
|
||||
在h5聊天,后台管理员消息通知等功能使用到
|
||||
```sh
|
||||
php think workerman [ status ] [ server ] [ --d ]
|
||||
```
|
||||
windows环境下需要分三步执行
|
||||
```sh
|
||||
# 内部通讯服务
|
||||
php think workerman start channel
|
||||
# h5端聊天服务
|
||||
php think workerman start chat
|
||||
# 后台管理员通知
|
||||
php think workerman start admin
|
||||
```
|
||||
参数
|
||||
- status: 状态
|
||||
- start: 启动
|
||||
- stop: 关闭
|
||||
- restart: 重启
|
||||
- server: 服务 (windows)
|
||||
- channel: 内部通讯
|
||||
- chat: h5
|
||||
- admin: 后台
|
||||
|
||||
- --d : 后台执行
|
||||
|
||||
## 文档
|
||||
|
||||
[使用手册](https://help.crmeb.net)
|
||||
[TP6开发手册](https://www.kancloud.cn/manual/thinkphp6_0/content)
|
||||
|
||||
|
||||
## 参与开发
|
||||
|
||||
请参阅 [CRMEB](https://github.com/crmeb/CRMEB)。
|
||||
|
||||
## 付费版
|
||||
|
||||
付费版
|
||||
淘宝超值版:
|
||||
|
||||
CRMEB微信公众号小程序打通v2.6版:除了以上功能还带砍价、拼团功能,永久免费升级提供升级包
|
||||
@ -109,17 +283,17 @@ CRMEB微信公众号小程序打通v2.6版:除了以上功能还带砍价、
|
||||
|
||||
[.gif")](https://s.click.taobao.com/W7hVkLw)
|
||||
|
||||
用法下载:
|
||||
```
|
||||
Git clone https://github.com/crmeb/CRMEB.git
|
||||
```
|
||||
小程序前端目录:view/crmebNewUI
|
||||
官网线下定制服务版:http://www.crmeb.com
|
||||
|
||||
系统组件开源项目
|
||||
form-builder
|
||||
tp5 PHP表单生成器,快速生成现代化的form表单。包含复选框、单选框、输入框、下拉选择框等元素以及,省市区三级联动,时间选择,日期选择,颜色选择,文件/图片上传等功能。 form-builder : https://github.com/xaboy/form-builder
|
||||
|
||||
特别鸣谢
|
||||
## 系统组件开源项目
|
||||
|
||||
#### form-builder
|
||||
|
||||
tp5 PHP表单生成器,快速生成现代化的form表单。包含复选框、单选框、输入框、下拉选择框等元素以及,省市区三级联动,时间选择,日期选择,颜色选择,文件/图片上传等功能。
|
||||
form-builder : https://github.com/xaboy/form-builder
|
||||
|
||||
## 特别鸣谢
|
||||
感谢以下的项目,排名不分先后
|
||||
|
||||
ThinkPHP:http://www.thinkphp.cn
|
||||
@ -138,10 +312,14 @@ requirejs: http://requirejs.org/
|
||||
|
||||
umeditor:http://ueditor.baidu.com/website/umeditor.html
|
||||
|
||||
版权信息 CRMEB v2.6.* 遵循GPL3.0开源协议发布,并提供免费使用。
|
||||
|
||||
## 版权信息
|
||||
|
||||
|
||||
本项目包含的第三方源码和二进制文件之版权信息另行标注。
|
||||
|
||||
版权所有Copyright © 2017-2019 by CRMEB (http://www.crmeb.com)
|
||||
|
||||
All rights reserved。
|
||||
|
||||
CRMEB® 商标和著作权所有者为西安众邦网络科技有限公司。
|
||||
|
||||
57
Upgrade.md
Normal file
57
Upgrade.md
Normal file
@ -0,0 +1,57 @@
|
||||
# 升级指导
|
||||
**环境要求php7.1+**
|
||||
**升级前请注意备份站点和数据库!!!**
|
||||
建议备份目录
|
||||
```
|
||||
backup/
|
||||
public/uploads/
|
||||
```
|
||||
|
||||
1. 修改微信服务授权地址: `/api/wechat/serve`
|
||||
2. 公众号菜单商城首页地址去掉wap,直接填写网址即可,例如:原来http://www.abc.com/wap 改为 http://www.abc.com
|
||||
3. 修改nginx或 mysql 项目根目录为`项目目录/public/`
|
||||
4. 升级 PHP至 `7.1+`
|
||||
5. 修改公众号微信支付目录为网站域名
|
||||
例如网站域名为`http://www.crmeb.com`则修改为`www.crmeb.com/`
|
||||
6. 在数据库中执行数据库更新文件`update.sql`
|
||||
7. 复制根目录`.example.env`另存为`.env`,重新配置数据库连接信息
|
||||
~~~
|
||||
APP_DEBUG = true
|
||||
|
||||
[APP]
|
||||
DEFAULT_TIMEZONE = Asia/Shanghai
|
||||
|
||||
[DATABASE]
|
||||
TYPE = mysql
|
||||
HOSTNAME = 127.0.0.1 #数据库连接地址
|
||||
DATABASE = test #数据库名称
|
||||
USERNAME = username #数据库登录账号
|
||||
PASSWORD = password #数据库登录密码
|
||||
HOSTPORT = 3306 #数据库端口
|
||||
CHARSET = utf8
|
||||
DEBUG = true
|
||||
|
||||
[LANG]
|
||||
default_lang = zh-cn
|
||||
~~~
|
||||
|
||||
8. 开启服务器 `20002`,`20003`端口, 用于长连接服务.如果是云服务器需要在安全组中开启端口
|
||||
9. h5端
|
||||
调试
|
||||
```sh
|
||||
npm run serve
|
||||
```
|
||||
打包
|
||||
```sh
|
||||
npm run build
|
||||
```
|
||||
配置 `.env.production` 文件
|
||||
```
|
||||
VUE_APP_API_URL= #接口地址,例如 http://www.abc.com/api
|
||||
VUE_APP_WS_URL= #长连接服务地址,例如 ws://www.abc.com:20003
|
||||
```
|
||||
打包好的页面文件,上传至public目录下
|
||||
10、数据库批量替换图片路径
|
||||
11、组合数据需要重新配置,例如:个人中心菜单,首页导航链接
|
||||
|
||||
|
||||
1
app/.htaccess
Normal file
1
app/.htaccess
Normal file
@ -0,0 +1 @@
|
||||
deny from all
|
||||
20
app/AppService.php
Normal file
20
app/AppService.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace app;
|
||||
|
||||
use crmeb\utils\Json;
|
||||
use think\facade\Db;
|
||||
use think\Service;
|
||||
|
||||
class AppService extends Service
|
||||
{
|
||||
|
||||
public $bind = [
|
||||
'json' => Json::class
|
||||
];
|
||||
|
||||
public function boot()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
68
app/ExceptionHandle.php
Normal file
68
app/ExceptionHandle.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app;
|
||||
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\exception\Handle;
|
||||
use think\exception\HttpException;
|
||||
use think\exception\HttpResponseException;
|
||||
use think\exception\ValidateException;
|
||||
use think\Response;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* 应用异常处理类
|
||||
*/
|
||||
class ExceptionHandle extends Handle
|
||||
{
|
||||
/**
|
||||
* 不需要记录信息(日志)的异常类列表
|
||||
* @var array
|
||||
*/
|
||||
protected $ignoreReport = [
|
||||
HttpException::class,
|
||||
HttpResponseException::class,
|
||||
ModelNotFoundException::class,
|
||||
DataNotFoundException::class,
|
||||
ValidateException::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* 记录异常信息(包括日志或者其它方式记录)
|
||||
*
|
||||
* @access public
|
||||
* @param Throwable $exception
|
||||
* @return void
|
||||
*/
|
||||
public function report(Throwable $exception): void
|
||||
{
|
||||
// 使用内置的方式记录异常日志
|
||||
parent::report($exception);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an exception into an HTTP response.
|
||||
*
|
||||
* @access public
|
||||
* @param \think\Request $request
|
||||
* @param Throwable $e
|
||||
* @return Response
|
||||
*/
|
||||
public function render($request, Throwable $e): Response
|
||||
{
|
||||
// 添加自定义异常处理机制
|
||||
|
||||
// 其他错误交给系统处理
|
||||
return parent::render($request, $e);
|
||||
}
|
||||
}
|
||||
19
app/Request.php
Normal file
19
app/Request.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app;
|
||||
|
||||
use Spatie\Macroable\Macroable;
|
||||
|
||||
class Request extends \think\Request
|
||||
{
|
||||
use Macroable;
|
||||
}
|
||||
119
app/admin/common.php
Normal file
119
app/admin/common.php
Normal file
@ -0,0 +1,119 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 流年 <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
// 应用公共文件
|
||||
|
||||
/**
|
||||
* 格式化属性
|
||||
* @param $arr
|
||||
* @return array
|
||||
*/
|
||||
function attrFormat($arr){
|
||||
$data = [];
|
||||
$res = [];
|
||||
if(count($arr) > 1){
|
||||
for ($i=0; $i < count($arr)-1; $i++) {
|
||||
if($i == 0) $data = $arr[$i]['detail'];
|
||||
//替代变量1
|
||||
$rep1 = [];
|
||||
foreach ($data as $v) {
|
||||
foreach ($arr[$i+1]['detail'] as $g) {
|
||||
//替代变量2
|
||||
$rep2 = ($i!=0?'':$arr[$i]['value']."_").$v."-".$arr[$i+1]['value']."_".$g;
|
||||
$tmp[] = $rep2;
|
||||
if($i==count($arr)-2){
|
||||
foreach (explode('-', $rep2) as $k => $h) {
|
||||
//替代变量3
|
||||
$rep3 = explode('_', $h);
|
||||
//替代变量4
|
||||
$rep4['detail'][$rep3[0]] = isset($rep3[1]) ? $rep3[1] : '';
|
||||
}
|
||||
$res[] = $rep4;
|
||||
}
|
||||
}
|
||||
}
|
||||
$data = isset($tmp) ? $tmp : [];
|
||||
}
|
||||
}else{
|
||||
$dataArr = [];
|
||||
foreach ($arr as $k=>$v){
|
||||
foreach ($v['detail'] as $kk=>$vv){
|
||||
$dataArr[$kk] = $v['value'].'_'.$vv;
|
||||
$res[$kk]['detail'][$v['value']] = $vv;
|
||||
}
|
||||
}
|
||||
$data[] = implode('-',$dataArr);
|
||||
}
|
||||
return [$data,$res];
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化月份
|
||||
* @param string $time
|
||||
* @param int $ceil
|
||||
* @return array
|
||||
*/
|
||||
function getMonth($time='',$ceil=0){
|
||||
if(empty($time)){
|
||||
$firstday = date("Y-m-01",time());
|
||||
$lastday = date("Y-m-d",strtotime("$firstday +1 month -1 day"));
|
||||
}else if($time=='n'){
|
||||
if($ceil!=0)
|
||||
$season = ceil(date('n') /3)-$ceil;
|
||||
else
|
||||
$season = ceil(date('n') /3);
|
||||
$firstday=date('Y-m-01',mktime(0,0,0,($season - 1) *3 +1,1,date('Y')));
|
||||
$lastday=date('Y-m-t',mktime(0,0,0,$season * 3,1,date('Y')));
|
||||
}else if($time=='y'){
|
||||
$firstday=date('Y-01-01');
|
||||
$lastday=date('Y-12-31');
|
||||
}else if($time=='h'){
|
||||
$firstday = date('Y-m-d', strtotime('this week +'.$ceil.' day')) . ' 00:00:00';
|
||||
$lastday = date('Y-m-d', strtotime('this week +'.($ceil+1).' day')) . ' 23:59:59';
|
||||
}
|
||||
return array($firstday,$lastday);
|
||||
}
|
||||
/**删除目录下所有文件
|
||||
* @param $path 目录或者文件路径
|
||||
* @param string $ext
|
||||
* @return bool
|
||||
*/
|
||||
function clearfile($path,$ext = '*.log')
|
||||
{
|
||||
$files = (array) glob($path.DS.'*');
|
||||
foreach ($files as $path) {
|
||||
if (is_dir($path)) {
|
||||
$matches = glob($path . '/'.$ext);
|
||||
if (is_array($matches)) {
|
||||
array_map('unlink', $matches);
|
||||
}
|
||||
rmdir($path);
|
||||
} else {
|
||||
unlink($path);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**获取当前类方法
|
||||
* @param $class
|
||||
* @return array
|
||||
*/
|
||||
function get_this_class_methods($class,$unarray = []) {
|
||||
$arrayall = get_class_methods($class);
|
||||
if ($parent_class = get_parent_class($class)) {
|
||||
$arrayparent = get_class_methods($parent_class);
|
||||
$arraynow = array_diff($arrayall, $arrayparent);//去除父级的
|
||||
} else {
|
||||
$arraynow = $arrayall;
|
||||
}
|
||||
return array_diff($arraynow, $unarray);//去除无用的
|
||||
}
|
||||
25
app/admin/config/route.php
Normal file
25
app/admin/config/route.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
// +----------------------------------------------------------------------
|
||||
// | 应用设置
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
return [
|
||||
// 是否强制使用路由
|
||||
'url_route_must' => false,
|
||||
// 合并路由规则
|
||||
'route_rule_merge' => true,
|
||||
// 路由是否完全匹配
|
||||
'route_complete_match' => false,
|
||||
// 是否自动转换URL中的控制器和操作名
|
||||
'url_convert' => true,
|
||||
];
|
||||
18
app/admin/config/template.php
Normal file
18
app/admin/config/template.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 模板设置
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
return [
|
||||
// 模板后缀
|
||||
'view_suffix' => 'php',
|
||||
// 视图输出字符串内容替换
|
||||
'tpl_replace_string' => [
|
||||
'{__PUBLIC_PATH}' => '/', //public 目录
|
||||
'{__STATIC_PATH}' => '/static/', //全局静态目录
|
||||
'{__PLUG_PATH}' => '/static/plug/', //全局静态插件
|
||||
'{__ADMIN_PATH}' => '/system/', //后台目录
|
||||
'{__FRAME_PATH}' => '/system/frame/', //后台框架
|
||||
'{__MODULE_PATH}' => '/system/module/', //后台模块
|
||||
]
|
||||
];
|
||||
43
app/admin/controller/AdminException.php
Normal file
43
app/admin/controller/AdminException.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2018/01/10
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\exception\Handle;
|
||||
use think\exception\ValidateException;
|
||||
use think\Response;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* 后台异常处理
|
||||
*
|
||||
* Class AdminException
|
||||
* @package app\admin\controller
|
||||
*/
|
||||
class AdminException extends Handle
|
||||
{
|
||||
|
||||
public function render($request, Throwable $e): Response
|
||||
{
|
||||
// 参数验证错误
|
||||
if ($e instanceof ValidateException) {
|
||||
return app('json')->make(422, $e->getError());
|
||||
}
|
||||
// 请求异常
|
||||
if (env("APP_DEBUG") == true) { //如是开启调试,就走原来的方法
|
||||
return parent::render($request, $e);
|
||||
} else {
|
||||
if ($e instanceof \Exception && request()->isAjax()) {
|
||||
return app('json')->fail(['code' => $e->getCode(), 'message' => $e->getMessage(), 'file' => $e->getFile()]);
|
||||
} else {
|
||||
$title = '系统错误';
|
||||
$msg = addslashes($e->getMessage());
|
||||
return \response(view('public/500', compact('title', 'msg'))->getContent());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
87
app/admin/controller/AuthController.php
Normal file
87
app/admin/controller/AuthController.php
Normal file
@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\admin\model\system\SystemAdmin;
|
||||
use app\admin\model\system\SystemMenus;
|
||||
use app\admin\model\system\SystemRole;
|
||||
use think\facade\Route as Url;
|
||||
|
||||
/**
|
||||
* 基类 所有控制器继承的类
|
||||
* Class AuthController
|
||||
* @package app\admin\controller
|
||||
*/
|
||||
class AuthController extends SystemBasic
|
||||
{
|
||||
/**
|
||||
* 当前登陆管理员信息
|
||||
* @var
|
||||
*/
|
||||
protected $adminInfo;
|
||||
|
||||
/**
|
||||
* 当前登陆管理员ID
|
||||
* @var
|
||||
*/
|
||||
protected $adminId;
|
||||
|
||||
/**
|
||||
* 当前管理员权限
|
||||
* @var array
|
||||
*/
|
||||
protected $auth = [];
|
||||
|
||||
protected $skipLogController = ['index','common'];
|
||||
|
||||
protected function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
if(!SystemAdmin::hasActiveAdmin()) return $this->redirect('Login/index');
|
||||
try{
|
||||
$adminInfo = SystemAdmin::activeAdminInfoOrFail();
|
||||
}catch (\Exception $e){
|
||||
return $this->failed(SystemAdmin::getErrorInfo($e->getMessage()),Url::buildUrl('Login/index'));
|
||||
}
|
||||
$this->adminInfo = $adminInfo;
|
||||
$this->adminId = $adminInfo['id'];
|
||||
$this->getActiveAdminInfo();
|
||||
$this->auth = SystemAdmin::activeAdminAuthOrFail();
|
||||
$this->adminInfo->level === 0 || $this->checkAuth();
|
||||
$this->assign('_admin',$this->adminInfo);
|
||||
$type = 'system';
|
||||
event('AdminVisit',[$this->adminInfo,$type]);
|
||||
}
|
||||
|
||||
|
||||
protected function checkAuth($action = null,$controller = null,$module = null,array $route = [])
|
||||
{
|
||||
static $allAuth = null;
|
||||
if($allAuth === null) $allAuth = SystemRole::getAllAuth();
|
||||
if($module === null) $module = $this->request->app();
|
||||
if($controller === null) $controller = $this->request->controller();
|
||||
if($action === null) $action = $this->request->action();
|
||||
if(!count($route)) $route = $this->request->route();
|
||||
if(in_array(strtolower($controller),$this->skipLogController,true)) return true;
|
||||
$nowAuthName = SystemMenus::getAuthName($action,$controller,$module,$route);
|
||||
$baseNowAuthName = SystemMenus::getAuthName($action,$controller,$module,[]);
|
||||
if((in_array($nowAuthName,$allAuth) && !in_array($nowAuthName,$this->auth)) || (in_array($baseNowAuthName,$allAuth) && !in_array($baseNowAuthName,$this->auth)))
|
||||
exit($this->failed('没有权限访问!'));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获得当前用户最新信息
|
||||
* @return SystemAdmin
|
||||
*/
|
||||
protected function getActiveAdminInfo()
|
||||
{
|
||||
$adminId = $this->adminId;
|
||||
$adminInfo = SystemAdmin::getValidAdminInfoOrFail($adminId);
|
||||
if(!$adminInfo) $this->failed(SystemAdmin::getErrorInfo('请登陆!'));
|
||||
$this->adminInfo = $adminInfo;
|
||||
SystemAdmin::setLoginInfo($adminInfo);
|
||||
return $adminInfo;
|
||||
}
|
||||
}
|
||||
587
app/admin/controller/Index.php
Normal file
587
app/admin/controller/Index.php
Normal file
@ -0,0 +1,587 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use app\admin\model\store\StoreProduct;
|
||||
use app\admin\model\system\SystemConfig;
|
||||
use app\admin\model\system\SystemMenus;
|
||||
use app\admin\model\system\SystemRole;
|
||||
use app\admin\model\order\StoreOrder as StoreOrderModel;//订单
|
||||
use app\admin\model\user\User;
|
||||
use app\admin\model\user\UserExtract as UserExtractModel;//分销
|
||||
use app\admin\model\user\User as UserModel;//用户
|
||||
use app\admin\model\store\StoreProductReply as StoreProductReplyModel;//评论
|
||||
use app\admin\model\store\StoreProduct as ProductModel;//产品
|
||||
use crmeb\services\SystemConfigService;
|
||||
use FormBuilder\Json;
|
||||
|
||||
/**
|
||||
* 首页控制器
|
||||
* Class Index
|
||||
* @package app\admin\controller
|
||||
*
|
||||
*/
|
||||
class Index extends AuthController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
//获取当前登录后台的管理员信息
|
||||
$adminInfo = $this->adminInfo->toArray();
|
||||
$roles = explode(',',$adminInfo['roles']);
|
||||
$site_logo = SystemConfig::getOneConfig('menu_name','site_logo')->toArray();
|
||||
// dump(SystemMenus::menuList());
|
||||
// exit();
|
||||
$this->assign([
|
||||
'menuList'=>SystemMenus::menuList(),
|
||||
'site_logo'=>json_decode($site_logo['value'],true),
|
||||
'new_order_audio_link'=>SystemConfigService::get('new_order_audio_link'),
|
||||
'role_name'=>SystemRole::where('id',$roles[0])->field('role_name')->find()
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
//后台首页内容
|
||||
public function main()
|
||||
{
|
||||
/*首页第一行统计*/
|
||||
$now_month = strtotime(date('Y-m'));//本月
|
||||
$pre_month = strtotime(date('Y-m',strtotime('-1 month')));//上月
|
||||
$now_day = strtotime(date('Y-m-d'));//今日
|
||||
$pre_day = strtotime(date('Y-m-d',strtotime('-1 day')));//昨天时间戳
|
||||
$beforyester_day = strtotime(date('Y-m-d',strtotime('-2 day')));//前天时间戳
|
||||
//待发货数量
|
||||
$topData['orderDeliveryNum'] = StoreOrderModel::where('status',0)
|
||||
->where('paid',1)
|
||||
->where('refund_status',0)
|
||||
->count();
|
||||
//退换货订单数
|
||||
$topData['orderRefundNum'] = StoreOrderModel::where('paid',1)
|
||||
->where('refund_status','IN','1')
|
||||
->count();
|
||||
//库存预警
|
||||
$replenishment_num = SystemConfig::getConfigValue('store_stock') > 0 ? SystemConfig::getConfigValue('store_stock') : 20;//库存预警界限
|
||||
$topData['stockProduct'] = StoreProduct::where('stock','<=',$replenishment_num)->where('is_show',1)->where('is_del',0)->count();
|
||||
//待处理提现
|
||||
$topData['treatedExtract'] = UserExtractModel::where('status',0)->count();
|
||||
|
||||
|
||||
//订单数->昨日
|
||||
$now_day_order_p = StoreOrderModel::where('paid',1)->whereTime('pay_time','yesterday')->count();
|
||||
$pre_day_order_p = StoreOrderModel::where('paid',1)->where('pay_time','>',$pre_day)->where('pay_time','<',$now_day)->count();
|
||||
$first_line['d_num'] = [
|
||||
'data' => $now_day_order_p ? $now_day_order_p : 0,
|
||||
'percent' => abs($now_day_order_p - $pre_day_order_p),
|
||||
'is_plus' => $now_day_order_p - $pre_day_order_p > 0 ? 1 : ($now_day_order_p - $pre_day_order_p == 0 ? -1 : 0)
|
||||
];
|
||||
|
||||
//交易额->昨天
|
||||
$now_month_order_p = StoreOrderModel::where('paid',1)->whereTime('pay_time','yesterday')->sum('pay_price');
|
||||
$pre_month_order_p = StoreOrderModel::where('paid',1)->where('pay_time','>',$beforyester_day)->where('pay_time','<',$pre_day)->sum('pay_price');
|
||||
$first_line['d_price'] = [
|
||||
'data' => $now_month_order_p > 0 ? $now_month_order_p : 0,
|
||||
'percent' => abs($now_month_order_p - $pre_month_order_p),
|
||||
'is_plus' => $now_month_order_p - $pre_month_order_p > 0 ? 1 : ($now_month_order_p - $pre_month_order_p == 0 ? -1 : 0)
|
||||
];
|
||||
|
||||
//交易额->月
|
||||
$now_month_order_p = StoreOrderModel::where('paid',1)->whereTime('pay_time','month')->sum('pay_price');
|
||||
$pre_month_order_p = StoreOrderModel::where('paid',1)->where('pay_time','>',$pre_month)->where('pay_time','<',$now_month)->value('sum(pay_price)');
|
||||
$first_line['m_price'] = [
|
||||
'data' => $now_month_order_p > 0 ? $now_month_order_p : 0,
|
||||
'percent' => abs($now_month_order_p - $pre_month_order_p),
|
||||
'is_plus' => $now_month_order_p - $pre_month_order_p > 0 ? 1 : ($now_month_order_p - $pre_month_order_p == 0 ? -1 : 0)
|
||||
];
|
||||
|
||||
//新粉丝->日
|
||||
$now_day_user = User::where('add_time','>',$now_day)->count();
|
||||
$pre_day_user = User::where('add_time','>',$pre_day)->where('add_time','<',$now_day)->count();
|
||||
$pre_day_user = $pre_day_user ? $pre_day_user : 0;
|
||||
$first_line['day'] = [
|
||||
'data' => $now_day_user ? $now_day_user : 0,
|
||||
'percent' => abs($now_day_user - $pre_day_user),
|
||||
'is_plus' => $now_day_user - $pre_day_user > 0 ? 1 : ($now_day_user - $pre_day_user == 0 ? -1 : 0)
|
||||
];
|
||||
|
||||
//新粉丝->月
|
||||
$now_month_user = User::where('add_time','>',$now_month)->count();
|
||||
$pre_month_user = User::where('add_time','>',$pre_month)->where('add_time','<',$now_month)->count();
|
||||
$first_line['month'] = [
|
||||
'data' => $now_month_user ? $now_month_user : 0,
|
||||
'percent' => abs($now_month_user - $pre_month_user),
|
||||
'is_plus' => $now_month_user - $pre_month_user > 0 ? 1 : ($now_month_user - $pre_month_user == 0 ? -1 : 0)
|
||||
];
|
||||
|
||||
//本月订单总数
|
||||
$now_order_info_c = StoreOrderModel::where('add_time','>',$now_month)->count();
|
||||
$pre_order_info_c = StoreOrderModel::where('add_time','>',$pre_month)->where('add_time','<',$now_month)->count();
|
||||
$order_info['first'] = [
|
||||
'data' => $now_order_info_c ? $now_order_info_c : 0,
|
||||
'percent' => abs($now_order_info_c - $pre_order_info_c),
|
||||
'is_plus' => $now_order_info_c - $pre_order_info_c > 0 ? 1 : ($now_order_info_c - $pre_order_info_c == 0 ? -1 : 0)
|
||||
];
|
||||
|
||||
//上月订单总数
|
||||
$second_now_month = strtotime(date('Y-m',strtotime('-1 month')));
|
||||
$second_pre_month = strtotime(date('Y-m',strtotime('-2 month')));
|
||||
$now_order_info_c = StoreOrderModel::where('add_time','>',$pre_month)->where('add_time','<',$now_month)->count();
|
||||
$pre_order_info_c = StoreOrderModel::where('add_time','>',$second_pre_month)->where('add_time','<',$second_now_month)->count();
|
||||
$order_info["second"] = [
|
||||
'data' => $now_order_info_c ? $now_order_info_c : 0,
|
||||
'percent' => abs($now_order_info_c - $pre_order_info_c),
|
||||
'is_plus' => $now_order_info_c - $pre_order_info_c > 0 ? 1 : ($now_order_info_c - $pre_order_info_c == 0 ? -1 : 0)
|
||||
];
|
||||
$second_line['order_info'] = $order_info;
|
||||
|
||||
|
||||
$this->assign([
|
||||
'first_line' => $first_line,
|
||||
'second_line' => $second_line,
|
||||
'topData' => $topData,
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单图表
|
||||
*/
|
||||
public function orderchart(){
|
||||
header('Content-type:text/json');
|
||||
$cycle = $this->request->param('cycle')?:'thirtyday';//默认30天
|
||||
$datalist = [];
|
||||
switch ($cycle){
|
||||
case 'thirtyday':
|
||||
$datebefor = date('Y-m-d',strtotime('-30 day'));
|
||||
$dateafter = date('Y-m-d');
|
||||
//上期
|
||||
$pre_datebefor = date('Y-m-d',strtotime('-60 day'));
|
||||
$pre_dateafter = date('Y-m-d',strtotime('-30 day'));
|
||||
for($i=-30;$i < 0;$i++){
|
||||
$datalist[date('m-d',strtotime($i.' day'))] = date('m-d',strtotime($i.' day'));
|
||||
}
|
||||
$order_list = StoreOrderModel::where('add_time','between time',[$datebefor,$dateafter])
|
||||
->field("FROM_UNIXTIME(add_time,'%m-%d') as day,count(*) as count,sum(pay_price) as price")
|
||||
->group("FROM_UNIXTIME(add_time, '%Y%m%d')")
|
||||
->order('add_time asc')
|
||||
->select()->toArray();
|
||||
if(empty($order_list)) return Json::fail('无数据');
|
||||
foreach ($order_list as $k=>&$v){
|
||||
$order_list[$v['day']] = $v;
|
||||
}
|
||||
$cycle_list = [];
|
||||
foreach ($datalist as $dk=>$dd){
|
||||
if(!empty($order_list[$dd])){
|
||||
$cycle_list[$dd] = $order_list[$dd];
|
||||
}else{
|
||||
$cycle_list[$dd] = ['count'=>0,'day'=>$dd,'price'=>''];
|
||||
}
|
||||
}
|
||||
$chartdata = [];
|
||||
$data = [];//临时
|
||||
$chartdata['yAxis']['maxnum'] = 0;//最大值数量
|
||||
$chartdata['yAxis']['maxprice'] = 0;//最大值金额
|
||||
foreach ($cycle_list as $k=>$v){
|
||||
$data['day'][] = $v['day'];
|
||||
$data['count'][] = $v['count'];
|
||||
$data['price'][] = round($v['price'],2);
|
||||
if($chartdata['yAxis']['maxnum'] < $v['count'])
|
||||
$chartdata['yAxis']['maxnum'] = $v['count'];//日最大订单数
|
||||
if($chartdata['yAxis']['maxprice'] < $v['price'])
|
||||
$chartdata['yAxis']['maxprice'] = $v['price'];//日最大金额
|
||||
}
|
||||
$chartdata['legend'] = ['订单金额','订单数'];//分类
|
||||
$chartdata['xAxis'] = $data['day'];//X轴值
|
||||
//,'itemStyle'=>$series
|
||||
$series= ['normal'=>['label'=>['show'=>true,'position'=>'top']]];
|
||||
$chartdata['series'][] = ['name'=>$chartdata['legend'][0],'type'=>'bar','itemStyle'=>$series,'data'=>$data['price']];//分类1值
|
||||
$chartdata['series'][] = ['name'=>$chartdata['legend'][1],'type'=>'bar','itemStyle'=>$series,'data'=>$data['count']];//分类2值
|
||||
//统计总数上期
|
||||
$pre_total = StoreOrderModel::where('add_time','between time',[$pre_datebefor,$pre_dateafter])
|
||||
->field("count(*) as count,sum(pay_price) as price")
|
||||
->find();
|
||||
if($pre_total){
|
||||
$chartdata['pre_cycle']['count'] = [
|
||||
'data' => $pre_total['count']? : 0
|
||||
];
|
||||
$chartdata['pre_cycle']['price'] = [
|
||||
'data' => $pre_total['price']? : 0
|
||||
];
|
||||
}
|
||||
//统计总数
|
||||
$total = StoreOrderModel::where('add_time','between time',[$datebefor,$dateafter])
|
||||
->field("count(*) as count,sum(pay_price) as price")
|
||||
->find();
|
||||
if($total){
|
||||
$cha_count = intval($pre_total['count']) - intval($total['count']);
|
||||
$pre_total['count'] = $pre_total['count']==0 ? 1 : $pre_total['count'];
|
||||
$chartdata['cycle']['count'] = [
|
||||
'data' => $total['count']? : 0,
|
||||
'percent' => round((abs($cha_count)/intval($pre_total['count'])*100),2),
|
||||
'is_plus' => $cha_count > 0 ? -1 : ($cha_count == 0 ? 0 : 1)
|
||||
];
|
||||
$cha_price = round($pre_total['price'],2) - round($total['price'],2);
|
||||
$pre_total['price'] = $pre_total['price']==0 ? 1 : $pre_total['price'];
|
||||
$chartdata['cycle']['price'] = [
|
||||
'data' => $total['price']? : 0,
|
||||
'percent' => round(abs($cha_price)/$pre_total['price']*100,2),
|
||||
'is_plus' => $cha_price > 0 ? -1 : ($cha_price == 0 ? 0 : 1)
|
||||
];
|
||||
}
|
||||
return app('json')->success('ok',$chartdata);
|
||||
break;
|
||||
case 'week':
|
||||
$weekarray=array(['周日'],['周一'],['周二'],['周三'],['周四'],['周五'],['周六']);
|
||||
$datebefor = date('Y-m-d',strtotime('-1 week Monday'));
|
||||
$dateafter = date('Y-m-d',strtotime('-1 week Sunday'));
|
||||
$order_list = StoreOrderModel::where('add_time','between time',[$datebefor,$dateafter])
|
||||
->field("FROM_UNIXTIME(add_time,'%w') as day,count(*) as count,sum(pay_price) as price")
|
||||
->group("FROM_UNIXTIME(add_time, '%Y%m%e')")
|
||||
->order('add_time asc')
|
||||
->select()->toArray();
|
||||
//数据查询重新处理
|
||||
$new_order_list = [];
|
||||
foreach ($order_list as $k=>$v){
|
||||
$new_order_list[$v['day']] = $v;
|
||||
}
|
||||
$now_datebefor = date('Y-m-d', (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600));
|
||||
$now_dateafter = date('Y-m-d',strtotime("+1 day"));
|
||||
$now_order_list = StoreOrderModel::where('add_time','between time',[$now_datebefor,$now_dateafter])
|
||||
->field("FROM_UNIXTIME(add_time,'%w') as day,count(*) as count,sum(pay_price) as price")
|
||||
->group("FROM_UNIXTIME(add_time, '%Y%m%e')")
|
||||
->order('add_time asc')
|
||||
->select()->toArray();
|
||||
//数据查询重新处理 key 变为当前值
|
||||
$new_now_order_list = [];
|
||||
foreach ($now_order_list as $k=>$v){
|
||||
$new_now_order_list[$v['day']] = $v;
|
||||
}
|
||||
foreach ($weekarray as $dk=>$dd){
|
||||
if(!empty($new_order_list[$dk])){
|
||||
$weekarray[$dk]['pre'] = $new_order_list[$dk];
|
||||
}else{
|
||||
$weekarray[$dk]['pre'] = ['count'=>0,'day'=>$weekarray[$dk][0],'price'=>'0'];
|
||||
}
|
||||
if(!empty($new_now_order_list[$dk])){
|
||||
$weekarray[$dk]['now'] = $new_now_order_list[$dk];
|
||||
}else{
|
||||
$weekarray[$dk]['now'] = ['count'=>0,'day'=>$weekarray[$dk][0],'price'=>'0'];
|
||||
}
|
||||
}
|
||||
$chartdata = [];
|
||||
$data = [];//临时
|
||||
$chartdata['yAxis']['maxnum'] = 0;//最大值数量
|
||||
$chartdata['yAxis']['maxprice'] = 0;//最大值金额
|
||||
foreach ($weekarray as $k=>$v){
|
||||
$data['day'][] = $v[0];
|
||||
$data['pre']['count'][] = $v['pre']['count'];
|
||||
$data['pre']['price'][] = round($v['pre']['price'],2);
|
||||
$data['now']['count'][] = $v['now']['count'];
|
||||
$data['now']['price'][] = round($v['now']['price'],2);
|
||||
if($chartdata['yAxis']['maxnum'] < $v['pre']['count'] || $chartdata['yAxis']['maxnum'] < $v['now']['count']){
|
||||
$chartdata['yAxis']['maxnum'] = $v['pre']['count']>$v['now']['count']?$v['pre']['count']:$v['now']['count'];//日最大订单数
|
||||
}
|
||||
if($chartdata['yAxis']['maxprice'] < $v['pre']['price'] || $chartdata['yAxis']['maxprice'] < $v['now']['price']){
|
||||
$chartdata['yAxis']['maxprice'] = $v['pre']['price']>$v['now']['price']?$v['pre']['price']:$v['now']['price'];//日最大金额
|
||||
}
|
||||
}
|
||||
$chartdata['legend'] = ['上周金额','本周金额','上周订单数','本周订单数'];//分类
|
||||
$chartdata['xAxis'] = $data['day'];//X轴值
|
||||
//,'itemStyle'=>$series
|
||||
$series= ['normal'=>['label'=>['show'=>true,'position'=>'top']]];
|
||||
$chartdata['series'][] = ['name'=>$chartdata['legend'][0],'type'=>'bar','itemStyle'=>$series,'data'=>$data['pre']['price']];//分类1值
|
||||
$chartdata['series'][] = ['name'=>$chartdata['legend'][1],'type'=>'bar','itemStyle'=>$series,'data'=>$data['now']['price']];//分类1值
|
||||
$chartdata['series'][] = ['name'=>$chartdata['legend'][2],'type'=>'line','itemStyle'=>$series,'data'=>$data['pre']['count']];//分类2值
|
||||
$chartdata['series'][] = ['name'=>$chartdata['legend'][3],'type'=>'line','itemStyle'=>$series,'data'=>$data['now']['count']];//分类2值
|
||||
|
||||
//统计总数上期
|
||||
$pre_total = StoreOrderModel::where('add_time','between time',[$datebefor,$dateafter])
|
||||
->field("count(*) as count,sum(pay_price) as price")
|
||||
->find();
|
||||
if($pre_total){
|
||||
$chartdata['pre_cycle']['count'] = [
|
||||
'data' => $pre_total['count']? : 0
|
||||
];
|
||||
$chartdata['pre_cycle']['price'] = [
|
||||
'data' => $pre_total['price']? : 0
|
||||
];
|
||||
}
|
||||
//统计总数
|
||||
$total = StoreOrderModel::where('add_time','between time',[$now_datebefor,$now_dateafter])
|
||||
->field("count(*) as count,sum(pay_price) as price")
|
||||
->find();
|
||||
if($total){
|
||||
$cha_count = intval($pre_total['count']) - intval($total['count']);
|
||||
$pre_total['count'] = $pre_total['count']==0 ? 1 : $pre_total['count'];
|
||||
$chartdata['cycle']['count'] = [
|
||||
'data' => $total['count']? : 0,
|
||||
'percent' => round((abs($cha_count)/intval($pre_total['count'])*100),2),
|
||||
'is_plus' => $cha_count > 0 ? -1 : ($cha_count == 0 ? 0 : 1)
|
||||
];
|
||||
$cha_price = round($pre_total['price'],2) - round($total['price'],2);
|
||||
$pre_total['price'] = $pre_total['price']==0 ? 1 : $pre_total['price'];
|
||||
$chartdata['cycle']['price'] = [
|
||||
'data' => $total['price']? : 0,
|
||||
'percent' => round(abs($cha_price)/$pre_total['price']*100,2),
|
||||
'is_plus' => $cha_price > 0 ? -1 : ($cha_price == 0 ? 0 : 1)
|
||||
];
|
||||
}
|
||||
return app('json')->success('ok',$chartdata);
|
||||
break;
|
||||
case 'month':
|
||||
$weekarray=array('01'=>['1'],'02'=>['2'],'03'=>['3'],'04'=>['4'],'05'=>['5'],'06'=>['6'],'07'=>['7'],'08'=>['8'],'09'=>['9'],'10'=>['10'],'11'=>['11'],'12'=>['12'],'13'=>['13'],'14'=>['14'],'15'=>['15'],'16'=>['16'],'17'=>['17'],'18'=>['18'],'19'=>['19'],'20'=>['20'],'21'=>['21'],'22'=>['22'],'23'=>['23'],'24'=>['24'],'25'=>['25'],'26'=>['26'],'27'=>['27'],'28'=>['28'],'29'=>['29'],'30'=>['30'],'31'=>['31']);
|
||||
|
||||
$datebefor = date('Y-m-01',strtotime('-1 month'));
|
||||
$dateafter = date('Y-m-d',strtotime(date('Y-m-01')));
|
||||
$order_list = StoreOrderModel::where('add_time','between time',[$datebefor,$dateafter])
|
||||
->field("FROM_UNIXTIME(add_time,'%d') as day,count(*) as count,sum(pay_price) as price")
|
||||
->group("FROM_UNIXTIME(add_time, '%Y%m%e')")
|
||||
->order('add_time asc')
|
||||
->select()->toArray();
|
||||
//数据查询重新处理
|
||||
$new_order_list = [];
|
||||
foreach ($order_list as $k=>$v){
|
||||
$new_order_list[$v['day']] = $v;
|
||||
}
|
||||
$now_datebefor = date('Y-m-01');
|
||||
$now_dateafter = date('Y-m-d',strtotime("+1 day"));
|
||||
$now_order_list = StoreOrderModel::where('add_time','between time',[$now_datebefor,$now_dateafter])
|
||||
->field("FROM_UNIXTIME(add_time,'%d') as day,count(*) as count,sum(pay_price) as price")
|
||||
->group("FROM_UNIXTIME(add_time, '%Y%m%e')")
|
||||
->order('add_time asc')
|
||||
->select()->toArray();
|
||||
//数据查询重新处理 key 变为当前值
|
||||
$new_now_order_list = [];
|
||||
foreach ($now_order_list as $k=>$v){
|
||||
$new_now_order_list[$v['day']] = $v;
|
||||
}
|
||||
foreach ($weekarray as $dk=>$dd){
|
||||
if(!empty($new_order_list[$dk])){
|
||||
$weekarray[$dk]['pre'] = $new_order_list[$dk];
|
||||
}else{
|
||||
$weekarray[$dk]['pre'] = ['count'=>0,'day'=>$weekarray[$dk][0],'price'=>'0'];
|
||||
}
|
||||
if(!empty($new_now_order_list[$dk])){
|
||||
$weekarray[$dk]['now'] = $new_now_order_list[$dk];
|
||||
}else{
|
||||
$weekarray[$dk]['now'] = ['count'=>0,'day'=>$weekarray[$dk][0],'price'=>'0'];
|
||||
}
|
||||
}
|
||||
$chartdata = [];
|
||||
$data = [];//临时
|
||||
$chartdata['yAxis']['maxnum'] = 0;//最大值数量
|
||||
$chartdata['yAxis']['maxprice'] = 0;//最大值金额
|
||||
foreach ($weekarray as $k=>$v){
|
||||
$data['day'][] = $v[0];
|
||||
$data['pre']['count'][] = $v['pre']['count'];
|
||||
$data['pre']['price'][] = round($v['pre']['price'],2);
|
||||
$data['now']['count'][] = $v['now']['count'];
|
||||
$data['now']['price'][] = round($v['now']['price'],2);
|
||||
if($chartdata['yAxis']['maxnum'] < $v['pre']['count'] || $chartdata['yAxis']['maxnum'] < $v['now']['count']){
|
||||
$chartdata['yAxis']['maxnum'] = $v['pre']['count']>$v['now']['count']?$v['pre']['count']:$v['now']['count'];//日最大订单数
|
||||
}
|
||||
if($chartdata['yAxis']['maxprice'] < $v['pre']['price'] || $chartdata['yAxis']['maxprice'] < $v['now']['price']){
|
||||
$chartdata['yAxis']['maxprice'] = $v['pre']['price']>$v['now']['price']?$v['pre']['price']:$v['now']['price'];//日最大金额
|
||||
}
|
||||
|
||||
}
|
||||
$chartdata['legend'] = ['上月金额','本月金额','上月订单数','本月订单数'];//分类
|
||||
$chartdata['xAxis'] = $data['day'];//X轴值
|
||||
//,'itemStyle'=>$series
|
||||
$series= ['normal'=>['label'=>['show'=>true,'position'=>'top']]];
|
||||
$chartdata['series'][] = ['name'=>$chartdata['legend'][0],'type'=>'bar','itemStyle'=>$series,'data'=>$data['pre']['price']];//分类1值
|
||||
$chartdata['series'][] = ['name'=>$chartdata['legend'][1],'type'=>'bar','itemStyle'=>$series,'data'=>$data['now']['price']];//分类1值
|
||||
$chartdata['series'][] = ['name'=>$chartdata['legend'][2],'type'=>'line','itemStyle'=>$series,'data'=>$data['pre']['count']];//分类2值
|
||||
$chartdata['series'][] = ['name'=>$chartdata['legend'][3],'type'=>'line','itemStyle'=>$series,'data'=>$data['now']['count']];//分类2值
|
||||
|
||||
//统计总数上期
|
||||
$pre_total = StoreOrderModel::where('add_time','between time',[$datebefor,$dateafter])
|
||||
->field("count(*) as count,sum(pay_price) as price")
|
||||
->find();
|
||||
if($pre_total){
|
||||
$chartdata['pre_cycle']['count'] = [
|
||||
'data' => $pre_total['count']? : 0
|
||||
];
|
||||
$chartdata['pre_cycle']['price'] = [
|
||||
'data' => $pre_total['price']? : 0
|
||||
];
|
||||
}
|
||||
//统计总数
|
||||
$total = StoreOrderModel::where('add_time','between time',[$now_datebefor,$now_dateafter])
|
||||
->field("count(*) as count,sum(pay_price) as price")
|
||||
->find();
|
||||
if($total){
|
||||
$cha_count = intval($pre_total['count']) - intval($total['count']);
|
||||
$pre_total['count'] = $pre_total['count']==0 ? 1 : $pre_total['count'];
|
||||
$chartdata['cycle']['count'] = [
|
||||
'data' => $total['count']? : 0,
|
||||
'percent' => round((abs($cha_count)/intval($pre_total['count'])*100),2),
|
||||
'is_plus' => $cha_count > 0 ? -1 : ($cha_count == 0 ? 0 : 1)
|
||||
];
|
||||
$cha_price = round($pre_total['price'],2) - round($total['price'],2);
|
||||
$pre_total['price'] = $pre_total['price']==0 ? 1 : $pre_total['price'];
|
||||
$chartdata['cycle']['price'] = [
|
||||
'data' => $total['price']? : 0,
|
||||
'percent' => round(abs($cha_price)/$pre_total['price']*100,2),
|
||||
'is_plus' => $cha_price > 0 ? -1 : ($cha_price == 0 ? 0 : 1)
|
||||
];
|
||||
}
|
||||
return app('json')->success('ok',$chartdata);
|
||||
break;
|
||||
case 'year':
|
||||
$weekarray=array('01'=>['一月'],'02'=>['二月'],'03'=>['三月'],'04'=>['四月'],'05'=>['五月'],'06'=>['六月'],'07'=>['七月'],'08'=>['八月'],'09'=>['九月'],'10'=>['十月'],'11'=>['十一月'],'12'=>['十二月']);
|
||||
$datebefor = date('Y-01-01',strtotime('-1 year'));
|
||||
$dateafter = date('Y-12-31',strtotime('-1 year'));
|
||||
$order_list = StoreOrderModel::where('add_time','between time',[$datebefor,$dateafter])
|
||||
->field("FROM_UNIXTIME(add_time,'%m') as day,count(*) as count,sum(pay_price) as price")
|
||||
->group("FROM_UNIXTIME(add_time, '%Y%m')")
|
||||
->order('add_time asc')
|
||||
->select()->toArray();
|
||||
//数据查询重新处理
|
||||
$new_order_list = [];
|
||||
foreach ($order_list as $k=>$v){
|
||||
$new_order_list[$v['day']] = $v;
|
||||
}
|
||||
$now_datebefor = date('Y-01-01');
|
||||
$now_dateafter = date('Y-m-d');
|
||||
$now_order_list = StoreOrderModel::where('add_time','between time',[$now_datebefor,$now_dateafter])
|
||||
->field("FROM_UNIXTIME(add_time,'%m') as day,count(*) as count,sum(pay_price) as price")
|
||||
->group("FROM_UNIXTIME(add_time, '%Y%m')")
|
||||
->order('add_time asc')
|
||||
->select()->toArray();
|
||||
//数据查询重新处理 key 变为当前值
|
||||
$new_now_order_list = [];
|
||||
foreach ($now_order_list as $k=>$v){
|
||||
$new_now_order_list[$v['day']] = $v;
|
||||
}
|
||||
foreach ($weekarray as $dk=>$dd){
|
||||
if(!empty($new_order_list[$dk])){
|
||||
$weekarray[$dk]['pre'] = $new_order_list[$dk];
|
||||
}else{
|
||||
$weekarray[$dk]['pre'] = ['count'=>0,'day'=>$weekarray[$dk][0],'price'=>'0'];
|
||||
}
|
||||
if(!empty($new_now_order_list[$dk])){
|
||||
$weekarray[$dk]['now'] = $new_now_order_list[$dk];
|
||||
}else{
|
||||
$weekarray[$dk]['now'] = ['count'=>0,'day'=>$weekarray[$dk][0],'price'=>'0'];
|
||||
}
|
||||
}
|
||||
$chartdata = [];
|
||||
$data = [];//临时
|
||||
$chartdata['yAxis']['maxnum'] = 0;//最大值数量
|
||||
$chartdata['yAxis']['maxprice'] = 0;//最大值金额
|
||||
foreach ($weekarray as $k=>$v){
|
||||
$data['day'][] = $v[0];
|
||||
$data['pre']['count'][] = $v['pre']['count'];
|
||||
$data['pre']['price'][] = round($v['pre']['price'],2);
|
||||
$data['now']['count'][] = $v['now']['count'];
|
||||
$data['now']['price'][] = round($v['now']['price'],2);
|
||||
if($chartdata['yAxis']['maxnum'] < $v['pre']['count'] || $chartdata['yAxis']['maxnum'] < $v['now']['count']){
|
||||
$chartdata['yAxis']['maxnum'] = $v['pre']['count']>$v['now']['count']?$v['pre']['count']:$v['now']['count'];//日最大订单数
|
||||
}
|
||||
if($chartdata['yAxis']['maxprice'] < $v['pre']['price'] || $chartdata['yAxis']['maxprice'] < $v['now']['price']){
|
||||
$chartdata['yAxis']['maxprice'] = $v['pre']['price']>$v['now']['price']?$v['pre']['price']:$v['now']['price'];//日最大金额
|
||||
}
|
||||
}
|
||||
$chartdata['legend'] = ['去年金额','今年金额','去年订单数','今年订单数'];//分类
|
||||
$chartdata['xAxis'] = $data['day'];//X轴值
|
||||
//,'itemStyle'=>$series
|
||||
$series= ['normal'=>['label'=>['show'=>true,'position'=>'top']]];
|
||||
$chartdata['series'][] = ['name'=>$chartdata['legend'][0],'type'=>'bar','itemStyle'=>$series,'data'=>$data['pre']['price']];//分类1值
|
||||
$chartdata['series'][] = ['name'=>$chartdata['legend'][1],'type'=>'bar','itemStyle'=>$series,'data'=>$data['now']['price']];//分类1值
|
||||
$chartdata['series'][] = ['name'=>$chartdata['legend'][2],'type'=>'line','itemStyle'=>$series,'data'=>$data['pre']['count']];//分类2值
|
||||
$chartdata['series'][] = ['name'=>$chartdata['legend'][3],'type'=>'line','itemStyle'=>$series,'data'=>$data['now']['count']];//分类2值
|
||||
|
||||
//统计总数上期
|
||||
$pre_total = StoreOrderModel::where('add_time','between time',[$datebefor,$dateafter])
|
||||
->field("count(*) as count,sum(pay_price) as price")
|
||||
->find();
|
||||
if($pre_total){
|
||||
$chartdata['pre_cycle']['count'] = [
|
||||
'data' => $pre_total['count']? : 0
|
||||
];
|
||||
$chartdata['pre_cycle']['price'] = [
|
||||
'data' => $pre_total['price']? : 0
|
||||
];
|
||||
}
|
||||
//统计总数
|
||||
$total = StoreOrderModel::where('add_time','between time',[$now_datebefor,$now_dateafter])
|
||||
->field("count(*) as count,sum(pay_price) as price")
|
||||
->find();
|
||||
if($total){
|
||||
$cha_count = intval($pre_total['count']) - intval($total['count']);
|
||||
$pre_total['count'] = $pre_total['count']==0 ? 1 : $pre_total['count'];
|
||||
$chartdata['cycle']['count'] = [
|
||||
'data' => $total['count']? : 0,
|
||||
'percent' => round((abs($cha_count)/intval($pre_total['count'])*100),2),
|
||||
'is_plus' => $cha_count > 0 ? -1 : ($cha_count == 0 ? 0 : 1)
|
||||
];
|
||||
$cha_price = round($pre_total['price'],2) - round($total['price'],2);
|
||||
$pre_total['price'] = $pre_total['price']==0 ? 1 : $pre_total['price'];
|
||||
$chartdata['cycle']['price'] = [
|
||||
'data' => $total['price']? : 0,
|
||||
'percent' => round(abs($cha_price)/$pre_total['price']*100,2),
|
||||
'is_plus' => $cha_price > 0 ? -1 : ($cha_price == 0 ? 0 : 1)
|
||||
];
|
||||
}
|
||||
return app('json')->success('ok',$chartdata);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
/**
|
||||
* 用户图表
|
||||
*/
|
||||
public function userchart(){
|
||||
header('Content-type:text/json');
|
||||
|
||||
$starday = date('Y-m-d',strtotime('-30 day'));
|
||||
$yesterday = date('Y-m-d');
|
||||
|
||||
$user_list = UserModel::where('add_time','between time',[$starday,$yesterday])
|
||||
->field("FROM_UNIXTIME(add_time,'%m-%e') as day,count(*) as count")
|
||||
->group("FROM_UNIXTIME(add_time, '%Y%m%e')")
|
||||
->order('add_time asc')
|
||||
->select()->toArray();
|
||||
$chartdata = [];
|
||||
$data = [];
|
||||
$chartdata['legend'] = ['用户数'];//分类
|
||||
$chartdata['yAxis']['maxnum'] = 0;//最大值数量
|
||||
$chartdata['xAxis'] = [date('m-d')];//X轴值
|
||||
$chartdata['series'] = [0];//分类1值
|
||||
if(!empty($user_list)) {
|
||||
foreach ($user_list as $k=>$v){
|
||||
$data['day'][] = $v['day'];
|
||||
$data['count'][] = $v['count'];
|
||||
if($chartdata['yAxis']['maxnum'] < $v['count'])
|
||||
$chartdata['yAxis']['maxnum'] = $v['count'];
|
||||
}
|
||||
$chartdata['xAxis'] = $data['day'];//X轴值
|
||||
$chartdata['series'] = $data['count'];//分类1值
|
||||
}
|
||||
return app('json')->success('ok',$chartdata);
|
||||
}
|
||||
|
||||
/**
|
||||
* 待办事统计
|
||||
* @param int $newTime
|
||||
* @return false|string
|
||||
*/
|
||||
public function Jnotice($newTime=30)
|
||||
{
|
||||
header('Content-type:text/json');
|
||||
$data = [];
|
||||
$data['ordernum'] = StoreOrderModel::statusByWhere(1)->count();//待发货
|
||||
$replenishment_num = SystemConfig::getConfigValue('store_stock') > 0 ? SystemConfig::getConfigValue('store_stock') : 2;//库存预警界限
|
||||
$data['inventory'] = ProductModel::where('stock','<=',$replenishment_num)->where('is_show',1)->where('is_del',0)->count();//库存
|
||||
$data['commentnum'] = StoreProductReplyModel::where('is_reply',0)->count();//评论
|
||||
$data['reflectnum'] = UserExtractModel::where('status',0)->count();;//提现
|
||||
$data['msgcount'] = intval($data['ordernum'])+intval($data['inventory'])+intval($data['commentnum'])+intval($data['reflectnum']);
|
||||
//新订单提醒
|
||||
$data['newOrderId']=StoreOrderModel::statusByWhere(1)->where('is_remind',0)->column('order_id','id');
|
||||
if(count($data['newOrderId'])) StoreOrderModel::where('order_id','in',$data['newOrderId'])->update(['is_remind'=>1]);
|
||||
return app('json')->success('ok',$data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
65
app/admin/controller/Login.php
Normal file
65
app/admin/controller/Login.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
|
||||
use app\admin\model\system\SystemAdmin;
|
||||
use crmeb\services\UtilService;
|
||||
use think\facade\Session;
|
||||
use think\facade\Route as Url;
|
||||
|
||||
/**
|
||||
* 登录验证控制器
|
||||
* Class Login
|
||||
* @package app\admin\controller
|
||||
*/
|
||||
class Login extends SystemBasic
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 登录验证 + 验证码验证
|
||||
*/
|
||||
public function verify()
|
||||
{
|
||||
if(!request()->isPost()) return $this->failed('请登陆!');
|
||||
list($account,$pwd,$verify) = UtilService::postMore([
|
||||
'account','pwd','verify'
|
||||
], null,true);
|
||||
//检验验证码
|
||||
if(!captcha_check($verify)) return $this->failed('验证码错误,请重新输入');
|
||||
$error = Session::get('login_error')?:['num'=>0,'time'=>time()];
|
||||
$error['num'] = 0;
|
||||
if($error['num'] >=5 && $error['time'] > strtotime('- 5 minutes'))
|
||||
return $this->failed('错误次数过多,请稍候再试!');
|
||||
//检验帐号密码
|
||||
$res = SystemAdmin::login($account,$pwd);
|
||||
if($res){
|
||||
Session::set('login_error',null);
|
||||
return $this->redirect(Url::buildUrl('Index/index'));
|
||||
}else{
|
||||
$error['num'] += 1;
|
||||
$error['time'] = time();
|
||||
Session::set('login_error',$error);
|
||||
return $this->failed(SystemAdmin::getErrorInfo('用户名错误,请重新输入'));
|
||||
}
|
||||
}
|
||||
|
||||
public function captcha()
|
||||
{
|
||||
ob_clean();
|
||||
return captcha();
|
||||
}
|
||||
|
||||
/**
|
||||
* 退出登陆
|
||||
*/
|
||||
public function logout()
|
||||
{
|
||||
SystemAdmin::clearLoginInfo();
|
||||
$this->redirect('Login/index');
|
||||
}
|
||||
}
|
||||
117
app/admin/controller/SystemBasic.php
Normal file
117
app/admin/controller/SystemBasic.php
Normal file
@ -0,0 +1,117 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/10/09
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use crmeb\services\JsonService;
|
||||
use crmeb\basic\BaseController;
|
||||
|
||||
|
||||
class SystemBasic extends BaseController
|
||||
{
|
||||
/**
|
||||
* 操作失败提示框
|
||||
* @param string $msg 提示信息
|
||||
* @param string $backUrl 跳转地址
|
||||
* @param string $title 标题
|
||||
* @param int $duration 持续时间
|
||||
* @return mixed
|
||||
*/
|
||||
protected function failedNotice($msg = '操作失败', $backUrl = 0, $info = '', $duration = 3)
|
||||
{
|
||||
$type = 'error';
|
||||
$this->assign(compact('msg','backUrl','info','duration','type'));
|
||||
return $this->fetch('public/notice');
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败提示一直持续
|
||||
* @param $msg
|
||||
* @param int $backUrl
|
||||
* @param string $title
|
||||
* @return mixed
|
||||
*/
|
||||
protected function failedNoticeLast($msg = '操作失败', $backUrl = 0, $info = '')
|
||||
{
|
||||
return $this->failedNotice($msg,$backUrl,$info,0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 操作成功提示框
|
||||
* @param string $msg 提示信息
|
||||
* @param string $backUrl 跳转地址
|
||||
* @param string $title 标题
|
||||
* @param int $duration 持续时间
|
||||
* @return mixed
|
||||
*/
|
||||
protected function successfulNotice($msg = '操作成功',$backUrl = 0,$info = '',$duration = 3)
|
||||
{
|
||||
$type = 'success';
|
||||
$this->assign(compact('msg','backUrl','info','duration','type'));
|
||||
return $this->fetch('public/notice');
|
||||
}
|
||||
|
||||
/**
|
||||
* 成功提示一直持续
|
||||
* @param $msg
|
||||
* @param int $backUrl
|
||||
* @param string $title
|
||||
* @return mixed
|
||||
*/
|
||||
protected function successfulNoticeLast($msg = '操作成功',$backUrl = 0,$info = '')
|
||||
{
|
||||
return $this->successfulNotice($msg,$backUrl,$info,0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 错误提醒页面
|
||||
* @param string $msg
|
||||
* @param int $url
|
||||
*/
|
||||
protected function failed($msg = '哎呀…亲…您访问的页面出现错误', $url = 0)
|
||||
{
|
||||
if($this->request->isAjax()){
|
||||
exit(JsonService::fail($msg,$url)->getContent());
|
||||
}else{
|
||||
$this->assign(compact('msg','url'));
|
||||
exit($this->fetch('public/error'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 成功提醒页面
|
||||
* @param string $msg
|
||||
* @param int $url
|
||||
*/
|
||||
protected function successful($msg, $url = 0)
|
||||
{
|
||||
if($this->request->isAjax()){
|
||||
exit(JsonService::successful($msg,$url)->getContent());
|
||||
}else{
|
||||
$this->assign(compact('msg','url'));
|
||||
exit($this->fetch('public/success'));
|
||||
}
|
||||
}
|
||||
/**异常抛出
|
||||
* @param $name
|
||||
*/
|
||||
protected function exception($msg = '无法打开页面')
|
||||
{
|
||||
$this->assign(compact('msg'));
|
||||
exit($this->fetch('public/exception'));
|
||||
}
|
||||
|
||||
/**找不到页面
|
||||
* @param $name
|
||||
*/
|
||||
public function _empty($name)
|
||||
{
|
||||
exit($this->fetch('public/404'));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
304
app/admin/controller/agent/AgentManage.php
Normal file
304
app/admin/controller/agent/AgentManage.php
Normal file
@ -0,0 +1,304 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\agent;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use app\admin\model\order\StoreOrder;
|
||||
use app\admin\model\system\SystemAttachment;
|
||||
use app\admin\model\user\User;
|
||||
use app\admin\model\wechat\WechatUser as UserModel;
|
||||
use app\models\routine\RoutineQrcode;
|
||||
use app\models\user\UserBill;
|
||||
use crmeb\services\JsonService;
|
||||
use crmeb\services\UploadService;
|
||||
use crmeb\services\UtilService as Util;
|
||||
|
||||
/**
|
||||
* 分销商管理控制器
|
||||
* Class AgentManage
|
||||
* @package app\admin\controller\agent
|
||||
*/
|
||||
class AgentManage extends AuthController
|
||||
{
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->assign( 'year',getMonth());
|
||||
$this->assign('store_brokerage_statu',\crmeb\services\SystemConfigService::get('store_brokerage_statu'));
|
||||
return $this->fetch();
|
||||
}
|
||||
public function get_spread_list()
|
||||
{
|
||||
$where=Util::getMore([
|
||||
['nickname',''],
|
||||
['start_time',''],
|
||||
['end_time',''],
|
||||
['sex',''],
|
||||
['excel',''],
|
||||
['subscribe',''],
|
||||
['order',''],
|
||||
['page',1],
|
||||
['limit',20],
|
||||
['user_type',''],
|
||||
]);
|
||||
return JsonService::successlayui(UserModel::agentSystemPage($where));
|
||||
}
|
||||
|
||||
public function get_badge()
|
||||
{
|
||||
$where = Util::postMore([
|
||||
['data',''],
|
||||
['nickname',''],
|
||||
['excel',''],
|
||||
]);
|
||||
return JsonService::successful(UserModel::getSpreadBadge($where));
|
||||
}
|
||||
|
||||
/**
|
||||
* 一级推荐人页面
|
||||
* @return mixed
|
||||
*/
|
||||
public function stair($uid = ''){
|
||||
if($uid == '') return $this->failed('参数错误');
|
||||
$this->assign('uid',$uid ? : 0);
|
||||
$this->assign( 'year',getMonth());
|
||||
return $this->fetch();
|
||||
}
|
||||
/*
|
||||
* 统计推广订单
|
||||
* @param int $uid
|
||||
* */
|
||||
public function stair_order($uid = 0)
|
||||
{
|
||||
if($uid == '') return $this->failed('参数错误');
|
||||
$this->assign('uid',$uid ? : 0);
|
||||
$this->assign( 'year',getMonth());
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function get_stair_order_list(){
|
||||
$where = Util::getMore([
|
||||
['uid',$this->request->param('uid',0)],
|
||||
['data',''],
|
||||
['order_id',''],
|
||||
['type',''],
|
||||
['page',1],
|
||||
['limit',20],
|
||||
]);
|
||||
return JsonService::successlayui(UserModel::getStairOrderList($where));
|
||||
}
|
||||
|
||||
public function get_stair_order_badge()
|
||||
{
|
||||
$where = Util::getMore([
|
||||
['uid',''],
|
||||
['data',''],
|
||||
['order_id',''],
|
||||
['type',''],
|
||||
]);
|
||||
return JsonService::successful(UserModel::getStairOrderBadge($where));
|
||||
}
|
||||
|
||||
public function get_stair_list()
|
||||
{
|
||||
$where = Util::getMore([
|
||||
['uid',$this->request->param('uid',0)],
|
||||
['data',''],
|
||||
['nickname',''],
|
||||
['type',''],
|
||||
['page',1],
|
||||
['limit',20],
|
||||
]);
|
||||
return JsonService::successlayui(UserModel::getStairList($where));
|
||||
}
|
||||
|
||||
public function get_stair_badge()
|
||||
{
|
||||
$where = Util::getMore([
|
||||
['uid',''],
|
||||
['data',''],
|
||||
['nickname',''],
|
||||
['type',''],
|
||||
]);
|
||||
return JsonService::successful(UserModel::getSairBadge($where));
|
||||
}
|
||||
|
||||
/**
|
||||
* 二级推荐人页面
|
||||
* @return mixed
|
||||
*/
|
||||
public function stair_two($uid = '')
|
||||
{
|
||||
if($uid == '') return $this->failed('参数错误');
|
||||
$spread_uid=User::where('spread_uid',$uid)->column('uid','uid');
|
||||
if(count($spread_uid))
|
||||
$spread_uid_two=User::where('spread_uid','in',$spread_uid)->column('uid','uid');
|
||||
else
|
||||
$spread_uid_two=[0];
|
||||
$list = User::alias('u')
|
||||
->where('u.uid','in',$spread_uid_two)
|
||||
->field('u.avatar,u.nickname,u.now_money,u.spread_time,u.uid')
|
||||
->where('u.status',1)
|
||||
->order('u.add_time DESC')
|
||||
->select()
|
||||
->toArray();
|
||||
foreach ($list as $key=>$value) $list[$key]['orderCount'] = StoreOrder::getOrderCount($value['uid'])?:0;
|
||||
$this->assign('list',$list);
|
||||
return $this->fetch('stair');
|
||||
}
|
||||
|
||||
/*
|
||||
* 批量清除推广权限
|
||||
* */
|
||||
public function delete_promoter()
|
||||
{
|
||||
list($uids)=Util::postMore([
|
||||
['uids',[]]
|
||||
],$this->request,true);
|
||||
if(!count($uids)) return JsonService::fail('请选择需要解除推广权限的用户!');
|
||||
User::beginTrans();
|
||||
try{
|
||||
if(User::where('uid','in',$uids)->update(['is_promoter'=>0])){
|
||||
User::commitTrans();
|
||||
return JsonService::successful('解除成功');
|
||||
}else{
|
||||
User::rollbackTrans();
|
||||
return JsonService::fail('解除失败');
|
||||
}
|
||||
}catch (\PDOException $e){
|
||||
User::rollbackTrans();
|
||||
return JsonService::fail('数据库操作错误',['line'=>$e->getLine(),'message'=>$e->getMessage()]);
|
||||
}catch (\Exception $e){
|
||||
User::rollbackTrans();
|
||||
return JsonService::fail('系统错误',['line'=>$e->getLine(),'message'=>$e->getMessage()]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* 查看公众号推广二维码
|
||||
* @param int $uid
|
||||
* @return json
|
||||
* */
|
||||
public function look_code($uid='',$action='')
|
||||
{
|
||||
if(!$uid || !$action) return JsonService::fail('缺少参数');
|
||||
try{
|
||||
if(method_exists($this,$action)){
|
||||
$res = $this->$action($uid);
|
||||
if($res)
|
||||
return JsonService::successful($res);
|
||||
else
|
||||
return JsonService::fail(isset($res['msg']) ? $res['msg'] : '获取失败,请稍后再试!' );
|
||||
}else
|
||||
return JsonService::fail('暂无此方法');
|
||||
}catch (\Exception $e){
|
||||
return JsonService::fail('获取推广二维码失败,请检查您的微信配置',['line'=>$e->getLine(),'messag'=>$e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取小程序二维码
|
||||
* */
|
||||
public function routine_code($uid)
|
||||
{
|
||||
$userInfo = User::getUserInfos($uid);
|
||||
$name = $userInfo['uid'].'_'.$userInfo['is_promoter'].'_user.jpg';
|
||||
$imageInfo = SystemAttachment::getInfo($name,'name');
|
||||
if(!$imageInfo){
|
||||
$res = \app\models\routine\RoutineCode::getShareCode($uid, 'spread', '', '');
|
||||
if(!$res) throw new \think\Exception('二维码生成失败');
|
||||
$imageInfo = UploadService::imageStream($name,$res['res'],'routine/spread/code');
|
||||
if(!is_array($imageInfo)) return $imageInfo;
|
||||
SystemAttachment::attachmentAdd($imageInfo['name'],$imageInfo['size'],$imageInfo['type'],$imageInfo['dir'],$imageInfo['thumb_path'],1,$imageInfo['image_type'],$imageInfo['time']);
|
||||
RoutineQrcode::setRoutineQrcodeFind($res['id'],['status'=>1,'time'=>time(),'qrcode_url'=>$imageInfo['dir']]);
|
||||
$urlCode = $imageInfo['dir'];
|
||||
}else $urlCode = $imageInfo['att_dir'];
|
||||
return ['code_src'=>$urlCode];
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* */
|
||||
public function wechant_code($uid)
|
||||
{
|
||||
$qr_code = \crmeb\services\QrcodeService::getTemporaryQrcode('spread',$uid);
|
||||
if(isset($qr_code['url']))
|
||||
return ['code_src'=>$qr_code['url']];
|
||||
else
|
||||
throw new \think\Exception('获取失败,请稍后再试!');
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 查看小程序推广二维码
|
||||
* @param string $uid
|
||||
*/
|
||||
public function look_xcx_code($uid = '')
|
||||
{
|
||||
if(!strlen(trim($uid))) return JsonService::fail('缺少参数');
|
||||
try{
|
||||
$userInfo = User::getUserInfos($uid);
|
||||
$name = $userInfo['uid'].'_'.$userInfo['is_promoter'].'_user.jpg';
|
||||
$imageInfo = SystemAttachment::getInfo($name,'name');
|
||||
if(!$imageInfo){
|
||||
$res = \app\models\routine\RoutineCode::getShareCode($uid, 'spread', '', '');
|
||||
if(!$res) return JsonService::fail('二维码生成失败');
|
||||
$imageInfo = UploadService::imageStream($name,$res['res'],'routine/spread/code');
|
||||
if(!is_array($imageInfo)) return JsonService::fail($imageInfo);
|
||||
SystemAttachment::attachmentAdd($imageInfo['name'],$imageInfo['size'],$imageInfo['type'],$imageInfo['dir'],$imageInfo['thumb_path'],1,$imageInfo['image_type'],$imageInfo['time']);
|
||||
RoutineQrcode::setRoutineQrcodeFind($res['id'],['status'=>1,'time'=>time(),'qrcode_url'=>$imageInfo['dir']]);
|
||||
$urlCode = $imageInfo['dir'];
|
||||
}else $urlCode = $imageInfo['att_dir'];
|
||||
return JsonService::successful(['code_src'=>$urlCode]);
|
||||
}catch (\Exception $e){
|
||||
return JsonService::fail('查看推广二维码失败!',['line'=>$e->getLine(),'meassge'=>$e->getMessage()]);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 解除单个用户的推广权限
|
||||
* @param int $uid
|
||||
* */
|
||||
public function delete_spread($uid=0)
|
||||
{
|
||||
if(!$uid) return JsonService::fail('缺少参数');
|
||||
if(User::where('uid',$uid)->update(['is_promoter'=>0]))
|
||||
return JsonService::successful('解除成功');
|
||||
else
|
||||
return JsonService::fail('解除失败');
|
||||
}
|
||||
|
||||
/*
|
||||
* 清除推广人
|
||||
* */
|
||||
public function empty_spread($uid=0)
|
||||
{
|
||||
if(!$uid) return JsonService::fail('缺少参数');
|
||||
$res=true;
|
||||
$spread_uid = User::where('spread_uid',$uid)->column('uid','uid');
|
||||
if(count($spread_uid)) $res = $res && false !== User::where('spread_uid','in',$spread_uid)->update(['spread_uid'=>0]);
|
||||
$res = $res && false !== User::where('spread_uid',$uid)->update(['spread_uid'=>0]);
|
||||
if($res)
|
||||
return JsonService::successful('清除成功');
|
||||
else
|
||||
return JsonService::fail('清除失败');
|
||||
}
|
||||
/**
|
||||
* 个人资金详情页面
|
||||
* @return mixed
|
||||
*/
|
||||
public function now_money($uid = ''){
|
||||
if($uid == '') return $this->failed('参数错误');
|
||||
$list = UserBill::where('uid',$uid)->where('category','now_money')
|
||||
->field('mark,pm,number,add_time')
|
||||
->where('status',1)->order('add_time DESC')->select()->toArray();
|
||||
foreach ($list as &$v){
|
||||
$v['add_time'] = date('Y-m-d H:i:s',$v['add_time']);
|
||||
}
|
||||
$this->assign('list',$list);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
}
|
||||
190
app/admin/controller/article/Article.php
Normal file
190
app/admin/controller/article/Article.php
Normal file
@ -0,0 +1,190 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\article;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use crmeb\services\UtilService as Util;
|
||||
use crmeb\services\PHPTreeService as Phptree;
|
||||
use crmeb\services\JsonService as Json;
|
||||
use crmeb\services\UploadService as Upload;
|
||||
use app\admin\model\article\ArticleCategory as ArticleCategoryModel;
|
||||
use app\admin\model\article\Article as ArticleModel;
|
||||
use app\admin\model\system\SystemAttachment;
|
||||
|
||||
/**
|
||||
* 图文管理
|
||||
* Class WechatNews
|
||||
* @package app\admin\controller\wechat
|
||||
*/
|
||||
class Article extends AuthController
|
||||
{
|
||||
/**
|
||||
* TODO 显示后台管理员添加的图文
|
||||
* @return mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$where = Util::getMore([
|
||||
['title',''],
|
||||
['cid','']
|
||||
],$this->request);
|
||||
$pid = $this->request->param('pid');
|
||||
$this->assign('where',$where);
|
||||
$where['merchant'] = 0;//区分是管理员添加的图文显示 0 还是 商户添加的图文显示 1
|
||||
$cateList = ArticleCategoryModel::getArticleCategoryList();
|
||||
$tree = [];
|
||||
//获取分类列表
|
||||
if(count($cateList)){
|
||||
$tree = Phptree::makeTreeForHtml($cateList);
|
||||
if($pid){
|
||||
$pids = Util::getChildrenPid($tree,$pid);
|
||||
$where['cid'] = ltrim($pid.$pids);
|
||||
}
|
||||
}
|
||||
$this->assign(compact('tree'));
|
||||
$this->assign(ArticleModel::getAll($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 文件添加和修改
|
||||
* @return mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function create(){
|
||||
$id = $this->request->param('id');
|
||||
$cid = $this->request->param('cid');
|
||||
$news = [];
|
||||
$all = [];
|
||||
$news['id'] = '';
|
||||
$news['image_input'] = '';
|
||||
$news['title'] = '';
|
||||
$news['author'] = '';
|
||||
$news['is_banner'] = '';
|
||||
$news['is_hot'] = '';
|
||||
$news['content'] = '';
|
||||
$news['synopsis'] = '';
|
||||
$news['url'] = '';
|
||||
$news['cid'] = [];
|
||||
$select = 0;
|
||||
if($id){
|
||||
$news = ArticleModel::where('n.id',$id)->alias('n')->field('n.*,c.content')->join('ArticleContent c','c.nid=n.id','left')->find();
|
||||
if(!$news) return $this->failed('数据不存在!');
|
||||
$news['cid'] = explode(',',$news['cid']);
|
||||
}
|
||||
if($cid && in_array($cid, ArticleCategoryModel::getArticleCategoryInfo(0,'id'))){
|
||||
$all = ArticleCategoryModel::getArticleCategoryInfo($cid);
|
||||
$select = 1;
|
||||
}
|
||||
if(!$select){
|
||||
$list = ArticleCategoryModel::getTierList();
|
||||
foreach ($list as $menu){
|
||||
$all[$menu['id']] = $menu['html'].$menu['title'];
|
||||
}
|
||||
}
|
||||
$this->assign('all',$all);
|
||||
$this->assign('news',$news);
|
||||
$this->assign('cid',$cid);
|
||||
$this->assign('select',$select);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传图文图片
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function upload_image(){
|
||||
$res = Upload::Image($_POST['file'],'wechat/image/'.date('Ymd'));
|
||||
if(!is_array($res)) return Json::fail($res);
|
||||
SystemAttachment::attachmentAdd($res['name'],$res['size'],$res['type'],$res['dir'],$res['thumb_path'],5,$res['image_type'],$res['time']);
|
||||
return Json::successful('上传成功!',['url'=>$res['dir']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加和修改图文
|
||||
*/
|
||||
public function add_new(){
|
||||
$data = Util::postMore([
|
||||
['id',0],
|
||||
['cid',[]],
|
||||
'title',
|
||||
'author',
|
||||
'image_input',
|
||||
'content',
|
||||
'synopsis',
|
||||
'share_title',
|
||||
'share_synopsis',
|
||||
['visit',0],
|
||||
['sort',0],
|
||||
'url',
|
||||
['is_banner',0],
|
||||
['is_hot',0],
|
||||
['status',1],]);
|
||||
$data['cid'] = implode(',',$data['cid']);
|
||||
$content = $data['content'];
|
||||
unset($data['content']);
|
||||
if($data['id']){
|
||||
$id = $data['id'];
|
||||
unset($data['id']);
|
||||
$res = false;
|
||||
ArticleModel::beginTrans();
|
||||
$res1 = ArticleModel::edit($data,$id,'id');
|
||||
$res2 = ArticleModel::setContent($id,$content);
|
||||
if($res1 && $res2){
|
||||
$res = true;
|
||||
}
|
||||
ArticleModel::checkTrans($res);
|
||||
if($res)
|
||||
return Json::successful('修改图文成功!',$id);
|
||||
else
|
||||
return Json::fail('修改图文失败,您并没有修改什么!',$id);
|
||||
}else{
|
||||
$data['add_time'] = time();
|
||||
$data['admin_id'] = $this->adminId;
|
||||
$res = false;
|
||||
ArticleModel::beginTrans();
|
||||
$res1 = ArticleModel::create($data);
|
||||
$res2 = false;
|
||||
if($res1)
|
||||
$res2 = ArticleModel::setContent($res1->id,$content);
|
||||
if($res1 && $res2){
|
||||
$res = true;
|
||||
}
|
||||
ArticleModel::checkTrans($res);
|
||||
if($res)
|
||||
return Json::successful('添加图文成功!',$res1->id);
|
||||
else
|
||||
return Json::successful('添加图文失败!',$res1->id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除图文
|
||||
* @param $id
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
$res = ArticleModel::del($id);
|
||||
if(!$res)
|
||||
return Json::fail('删除失败,请稍候再试!');
|
||||
else
|
||||
return Json::successful('删除成功!');
|
||||
}
|
||||
|
||||
public function merchantIndex(){
|
||||
$where = Util::getMore([
|
||||
['title','']
|
||||
],$this->request);
|
||||
$this->assign('where',$where);
|
||||
$where['cid'] = input('cid');
|
||||
$where['merchant'] = 1;//区分是管理员添加的图文显示 0 还是 商户添加的图文显示 1
|
||||
$this->assign(ArticleModel::getAll($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
183
app/admin/controller/article/ArticleCategory.php
Normal file
183
app/admin/controller/article/ArticleCategory.php
Normal file
@ -0,0 +1,183 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\article;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use app\admin\model\system\SystemAttachment;
|
||||
use crmeb\services\FormBuilder as Form;
|
||||
use crmeb\services\UtilService as Util;
|
||||
use crmeb\services\JsonService as Json;
|
||||
use crmeb\services\UploadService as Upload;
|
||||
use think\facade\Route as Url;
|
||||
use app\admin\model\article\ArticleCategory as ArticleCategoryModel;
|
||||
use app\admin\model\article\Article as ArticleModel;
|
||||
|
||||
|
||||
/**
|
||||
* 文章分类管理 控制器
|
||||
* */
|
||||
class ArticleCategory extends AuthController
|
||||
|
||||
{
|
||||
|
||||
/**
|
||||
* 分类管理
|
||||
* */
|
||||
public function index(){
|
||||
$where = Util::getMore([
|
||||
['status',''],
|
||||
['title',''],
|
||||
],$this->request);
|
||||
$this->assign('where',$where);
|
||||
$this->assign(ArticleCategoryModel::systemPage($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 添加分类管理
|
||||
|
||||
* */
|
||||
|
||||
public function create(){
|
||||
$f = array();
|
||||
$f[] = Form::select('pid','父级id')->setOptions(function(){
|
||||
$list = ArticleCategoryModel::getTierList();
|
||||
$menus[] = ['value'=>0,'label'=>'顶级分类'];
|
||||
foreach ($list as $menu){
|
||||
$menus[] = ['value'=>$menu['id'],'label'=>$menu['html'].$menu['title']];
|
||||
}
|
||||
return $menus;
|
||||
})->filterable(1);
|
||||
$f[] = Form::input('title','分类名称');
|
||||
$f[] = Form::input('intr','分类简介')->type('textarea');
|
||||
// $f[] = Form::select('new_id','图文列表')->setOptions(function(){
|
||||
// $list = ArticleModel::getNews();
|
||||
// $options = [];
|
||||
// foreach ($list as $id=>$roleName){
|
||||
// $options[] = ['label'=>$roleName,'value'=>$id];
|
||||
// }
|
||||
// return $options;
|
||||
// })->multiple(1)->filterable(1);
|
||||
$f[] = Form::frameImageOne('image','分类图片',Url::buildUrl('admin/widget.images/index',array('fodder'=>'image')))->icon('image')->width('100%')->height('500px');
|
||||
$f[] = Form::number('sort','排序',0);
|
||||
$f[] = Form::radio('status','状态',1)->options([['value'=>1,'label'=>'显示'],['value'=>0,'label'=>'隐藏']]);
|
||||
$form = Form::make_post_form('添加分类',$f,Url::buildUrl('save'));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* s上传图片
|
||||
* */
|
||||
public function upload(){
|
||||
$res = Upload::image('file','article');
|
||||
if(!is_array($res)) return Json::fail($res);
|
||||
SystemAttachment::attachmentAdd($res['name'],$res['size'],$res['type'],$res['dir'],$res['thumb_path'],5,$res['image_type'],$res['time']);
|
||||
return Json::successful('图片上传成功!',['name'=>$res['name'],'url'=>Upload::pathToUrl($res['thumb_path'])]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 保存分类管理
|
||||
|
||||
* */
|
||||
|
||||
public function save(){
|
||||
$data = Util::postMore([
|
||||
'title',
|
||||
'pid',
|
||||
'intr',
|
||||
['new_id',[]],
|
||||
['image',[]],
|
||||
['sort',0],
|
||||
'status',]);
|
||||
if(!$data['title']) return Json::fail('请输入分类名称');
|
||||
if(count($data['image']) != 1) return Json::fail('请选择分类图片,并且只能上传一张');
|
||||
if($data['sort'] < 0) return Json::fail('排序不能是负数');
|
||||
$data['add_time'] = time();
|
||||
$data['image'] = $data['image'][0];
|
||||
$new_id = $data['new_id'];
|
||||
unset($data['new_id']);
|
||||
$res = ArticleCategoryModel::create($data);
|
||||
if(!ArticleModel::saveBatchCid($res['id'],implode(',',$new_id))) return Json::fail('文章列表添加失败');
|
||||
return Json::successful('添加分类成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 修改分类
|
||||
|
||||
* */
|
||||
|
||||
public function edit($id){
|
||||
if(!$id) return $this->failed('参数错误');
|
||||
$article = ArticleCategoryModel::get($id)->getData();
|
||||
if(!$article) return Json::fail('数据不存在!');
|
||||
$f = array();
|
||||
$f[] = Form::select('pid','父级id',(string)$article['pid'])->setOptions(function(){
|
||||
$list = ArticleCategoryModel::getTierList();
|
||||
$menus[] = ['value'=>0,'label'=>'顶级分类'];
|
||||
foreach ($list as $menu){
|
||||
$menus[] = ['value'=>$menu['id'],'label'=>$menu['html'].$menu['title']];
|
||||
}
|
||||
return $menus;
|
||||
})->filterable(1);
|
||||
$f[] = Form::input('title','分类名称',$article['title']);
|
||||
$f[] = Form::input('intr','分类简介',$article['intr'])->type('textarea');
|
||||
// $f[] = Form::select('new_id','图文列表',explode(',',$article->getData('new_id')))->setOptions(function(){
|
||||
// $list = ArticleModel::getNews();
|
||||
// $options = [];
|
||||
// foreach ($list as $id=>$roleName){
|
||||
// $options[] = ['label'=>$roleName,'value'=>$id];
|
||||
// }
|
||||
// return $options;
|
||||
// })->multiple(1)->filterable(1);
|
||||
$f[] = Form::frameImageOne('image','分类图片',Url::buildUrl('admin/widget.images/index',array('fodder'=>'image')),$article['image'])->icon('image')->width('100%')->height('500px');
|
||||
$f[] = Form::number('sort','排序',0);
|
||||
$f[] = Form::radio('status','状态',$article['status'])->options([['value'=>1,'label'=>'显示'],['value'=>0,'label'=>'隐藏']]);
|
||||
$form = Form::make_post_form('编辑分类',$f,Url::buildUrl('update',array('id'=>$id)));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function update($id)
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'pid',
|
||||
'title',
|
||||
'intr',
|
||||
// ['new_id',[]],
|
||||
['image',[]],
|
||||
['sort',0],
|
||||
'status',]);
|
||||
if(!$data['title']) return Json::fail('请输入分类名称');
|
||||
if(count($data['image']) != 1) return Json::fail('请选择分类图片,并且只能上传一张');
|
||||
if($data['sort'] < 0) return Json::fail('排序不能是负数');
|
||||
$data['image'] = $data['image'][0];
|
||||
if(!ArticleCategoryModel::get($id)) return Json::fail('编辑的记录不存在!');
|
||||
// if(!ArticleModel::saveBatchCid($id,implode(',',$data['new_id']))) return Json::fail('文章列表添加失败');
|
||||
// unset($data['new_id']);
|
||||
ArticleCategoryModel::edit($data,$id);
|
||||
return Json::successful('修改成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除分类
|
||||
* */
|
||||
public function delete($id)
|
||||
{
|
||||
$res = ArticleCategoryModel::delArticleCategory($id);
|
||||
if(!$res)
|
||||
return Json::fail(ArticleCategoryModel::getErrorInfo('删除失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('删除成功!');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
180
app/admin/controller/article/WechatNews.php
Normal file
180
app/admin/controller/article/WechatNews.php
Normal file
@ -0,0 +1,180 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\article;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use crmeb\services\UtilService as Util;
|
||||
use crmeb\services\JsonService as Json;
|
||||
use crmeb\services\UploadService as Upload;
|
||||
use app\admin\model\article\ArticleCategory as ArticleCategoryModel;
|
||||
use app\admin\model\article\Article as ArticleModel;
|
||||
use app\admin\model\system\SystemAttachment;
|
||||
|
||||
/**
|
||||
* 图文管理
|
||||
* Class WechatNews
|
||||
* @package app\admin\controller\wechat
|
||||
*/
|
||||
class WechatNews extends AuthController
|
||||
{
|
||||
/**
|
||||
* 显示后台管理员添加的图文
|
||||
* @return mixed
|
||||
*/
|
||||
public function index($cid = 0)
|
||||
{
|
||||
$where = Util::getMore([
|
||||
['title','']
|
||||
],$this->request);
|
||||
if($cid)
|
||||
$where['cid'] = $cid;
|
||||
else
|
||||
$where['cid'] = '';
|
||||
$this->assign('where',$where);
|
||||
$where['merchant'] = 0;//区分是管理员添加的图文显示 0 还是 商户添加的图文显示 1
|
||||
$this->assign('cid',$cid);
|
||||
$this->assign(ArticleModel::getAll($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 展示页面 添加和删除
|
||||
* @return mixed
|
||||
*/
|
||||
public function create(){
|
||||
$id = input('id');
|
||||
$cid = input('cid');
|
||||
$news = array();
|
||||
$news['id'] = '';
|
||||
$news['image_input'] = '';
|
||||
$news['title'] = '';
|
||||
$news['author'] = '';
|
||||
$news['content'] = '';
|
||||
$news['synopsis'] = '';
|
||||
$news['url'] = '';
|
||||
$news['cid'] = array();
|
||||
if($id){
|
||||
$news = \app\admin\model\wechat\WechatNews::where('n.id',$id)->alias('n')->field('n.*,c.content')->join('__WECHAT_NEWS_CONTENT__ c','c.nid=n.id')->find();
|
||||
if(!$news) return $this->failedNotice('数据不存在!');
|
||||
$news['cid'] = explode(',',$news['cid']);
|
||||
// dump($news);
|
||||
}
|
||||
$all = array();
|
||||
$select = 0;
|
||||
if(!$cid)
|
||||
$cid = '';
|
||||
else {
|
||||
if($id){
|
||||
$all = ArticleCategoryModel::where('id',$cid)->where('hidden','<>',0)->column('title','id');
|
||||
$select = 1;
|
||||
}else{
|
||||
$all = ArticleCategoryModel::where('id',$cid)->column('title','id');
|
||||
$select = 1;
|
||||
}
|
||||
|
||||
}
|
||||
if(empty($all)){
|
||||
$all = ArticleCategoryModel::getField();//新闻分类
|
||||
$select = 0;
|
||||
}
|
||||
$this->assign('all',$all);
|
||||
$this->assign('news',$news);
|
||||
$this->assign('cid',$cid);
|
||||
$this->assign('select',$select);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传图文图片
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function upload_image(){
|
||||
$res = Upload::Image($_POST['file'],'wechat/image/'.date('Ymd'));
|
||||
if(!is_array($res)) return Json::fail($res);
|
||||
SystemAttachment::attachmentAdd($res['name'],$res['size'],$res['type'],$res['dir'],$res['thumb_path'],5,$res['image_type'],$res['time']);
|
||||
return Json::successful('上传成功!',['url'=>$res['thumb_path']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加和修改图文
|
||||
*/
|
||||
public function add_new(){
|
||||
$data = Util::postMore([
|
||||
['id',0],
|
||||
['cid',[]],
|
||||
'title',
|
||||
'author',
|
||||
'image_input',
|
||||
'content',
|
||||
'synopsis',
|
||||
'share_title',
|
||||
'share_synopsis',
|
||||
['visit',0],
|
||||
['sort',0],
|
||||
'url',
|
||||
['status',1],]);
|
||||
$data['cid'] = implode(',',$data['cid']);
|
||||
$content = $data['content'];
|
||||
unset($data['content']);
|
||||
if($data['id']){
|
||||
$id = $data['id'];
|
||||
unset($data['id']);
|
||||
ArticleModel::beginTrans();
|
||||
$res1 = ArticleModel::edit($data,$id,'id');
|
||||
$res2 = ArticleModel::setContent($id,$content);
|
||||
if($res1 && $res2)
|
||||
$res = true;
|
||||
else
|
||||
$res =false;
|
||||
// dump($res);
|
||||
// exit();
|
||||
ArticleModel::checkTrans($res);
|
||||
if($res)
|
||||
return Json::successful('修改图文成功!',$id);
|
||||
else
|
||||
return Json::fail('修改图文失败!',$id);
|
||||
}else{
|
||||
$data['add_time'] = time();
|
||||
$data['admin_id'] = $this->adminId;
|
||||
ArticleModel::beginTrans();
|
||||
$res1 = ArticleModel::create($data);
|
||||
$res2 = false;
|
||||
if($res1)
|
||||
$res2 = ArticleModel::setContent($res1->id,$content);
|
||||
if($res1 && $res2)
|
||||
$res = true;
|
||||
else
|
||||
$res =false;
|
||||
ArticleModel::checkTrans($res);
|
||||
if($res)
|
||||
return Json::successful('添加图文成功!',$res1->id);
|
||||
else
|
||||
return Json::successful('添加图文失败!',$res1->id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除图文
|
||||
* @param $id
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
$res = ArticleModel::del($id);
|
||||
if(!$res)
|
||||
return Json::fail('删除失败,请稍候再试!');
|
||||
else
|
||||
return Json::successful('删除成功!');
|
||||
}
|
||||
|
||||
public function merchantIndex(){
|
||||
$where = Util::getMore([
|
||||
['title','']
|
||||
],$this->request);
|
||||
$this->assign('where',$where);
|
||||
$where['cid'] = input('cid');
|
||||
$where['merchant'] = 1;//区分是管理员添加的图文显示 0 还是 商户添加的图文显示 1
|
||||
$this->assign(ArticleModel::getAll($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
123
app/admin/controller/finance/Finance.php
Normal file
123
app/admin/controller/finance/Finance.php
Normal file
@ -0,0 +1,123 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: xurongyao <763569752@qq.com>
|
||||
* Date: 2018/6/14 下午5:25
|
||||
*/
|
||||
|
||||
namespace app\admin\controller\finance;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use app\admin\model\user\UserBill;
|
||||
use crmeb\services\JsonService as Json;
|
||||
use app\admin\model\finance\FinanceModel;
|
||||
use crmeb\services\UtilService as Util;
|
||||
use crmeb\services\FormBuilder as Form;
|
||||
use app\admin\model\user\User;
|
||||
|
||||
/**
|
||||
* 微信充值记录
|
||||
* Class UserRecharge
|
||||
* @package app\admin\controller\user
|
||||
*/
|
||||
class Finance extends AuthController
|
||||
|
||||
{
|
||||
|
||||
/**
|
||||
* 显示资金记录
|
||||
*/
|
||||
public function bill(){
|
||||
$list=UserBill::where('type','not in',['gain','system_sub','deduction','sign'])
|
||||
->where('category','not in','integral')
|
||||
->field(['title','type'])
|
||||
->group('type')
|
||||
->distinct(true)
|
||||
->select()
|
||||
->toArray();
|
||||
$this->assign('selectList',$list);
|
||||
return $this->fetch();
|
||||
}
|
||||
/**
|
||||
* 显示资金记录ajax列表
|
||||
*/
|
||||
public function billlist(){
|
||||
$where = Util::getMore([
|
||||
['start_time',''],
|
||||
['end_time',''],
|
||||
['nickname',''],
|
||||
['limit',20],
|
||||
['page',1],
|
||||
['type',''],
|
||||
]);
|
||||
return Json::successlayui(FinanceModel::getBillList($where));
|
||||
}
|
||||
/**
|
||||
*保存资金监控的excel表格
|
||||
*/
|
||||
public function save_bell_export(){
|
||||
$where = Util::getMore([
|
||||
['start_time',''],
|
||||
['end_time',''],
|
||||
['nickname',''],
|
||||
['type',''],
|
||||
]);
|
||||
FinanceModel::SaveExport($where);
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示佣金记录
|
||||
*/
|
||||
public function commission_list(){
|
||||
$this->assign('is_layui',true);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 佣金记录异步获取
|
||||
*/
|
||||
public function get_commission_list(){
|
||||
$get=Util::getMore([
|
||||
['page',1],
|
||||
['limit',20],
|
||||
['nickname',''],
|
||||
['price_max',''],
|
||||
['price_min',''],
|
||||
['order',''],
|
||||
['excel',''],
|
||||
]);
|
||||
return Json::successlayui(User::getCommissionList($get));
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示操作记录
|
||||
*/
|
||||
public function index3(){
|
||||
|
||||
}
|
||||
/**
|
||||
* 佣金详情
|
||||
*/
|
||||
public function content_info($uid=''){
|
||||
if($uid=='') return $this->failed('缺少参数');
|
||||
$this->assign('userinfo',User::getUserinfo($uid));
|
||||
$this->assign('uid',$uid);
|
||||
return $this->fetch();
|
||||
}
|
||||
/**
|
||||
* 佣金提现记录个人列表
|
||||
*/
|
||||
public function get_extract_list($uid=''){
|
||||
if($uid=='') return Json::fail('缺少参数');
|
||||
$where=Util::getMore([
|
||||
['page',1],
|
||||
['limit',20],
|
||||
['start_time',''],
|
||||
['end_time',''],
|
||||
['nickname','']
|
||||
]);
|
||||
return Json::successlayui(UserBill::getExtrctOneList($where,$uid));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
149
app/admin/controller/finance/UserExtract.php
Normal file
149
app/admin/controller/finance/UserExtract.php
Normal file
@ -0,0 +1,149 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: lianghuan
|
||||
* Date: 2018-03-03
|
||||
* Time: 16:37
|
||||
*/
|
||||
namespace app\admin\controller\finance;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use crmeb\services\FormBuilder as Form;
|
||||
use app\admin\model\user\UserExtract as UserExtractModel;
|
||||
use crmeb\services\JsonService;
|
||||
use crmeb\services\UtilService as Util;
|
||||
use think\facade\Route as Url;
|
||||
|
||||
/**
|
||||
* 用户提现管理
|
||||
* Class UserExtract
|
||||
* @package app\admin\controller\finance
|
||||
*/
|
||||
class UserExtract extends AuthController
|
||||
{
|
||||
public function index(){
|
||||
$where = Util::getMore([
|
||||
['status',''],
|
||||
['nickname',''],
|
||||
['extract_type',''],
|
||||
['nireid',''],
|
||||
['date',''],
|
||||
],$this->request);
|
||||
$limitTimeList = [
|
||||
'today'=>implode(' - ',[date('Y/m/d'),date('Y/m/d',strtotime('+1 day'))]),
|
||||
'week'=>implode(' - ',[
|
||||
date('Y/m/d', (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600)),
|
||||
date('Y-m-d', (time() + (7 - (date('w') == 0 ? 7 : date('w'))) * 24 * 3600))
|
||||
]),
|
||||
'month'=>implode(' - ',[date('Y/m').'/01',date('Y/m').'/'.date('t')]),
|
||||
'quarter'=>implode(' - ',[
|
||||
date('Y').'/'.(ceil((date('n'))/3)*3-3+1).'/01',
|
||||
date('Y').'/'.(ceil((date('n'))/3)*3).'/'.date('t',mktime(0,0,0,(ceil((date('n'))/3)*3),1,date('Y')))
|
||||
]),
|
||||
'year'=>implode(' - ',[
|
||||
date('Y').'/01/01',date('Y/m/d',strtotime(date('Y').'/01/01 + 1year -1 day'))
|
||||
])
|
||||
];
|
||||
$this->assign('where',$where);
|
||||
$this->assign('limitTimeList',$limitTimeList);
|
||||
$this->assign(UserExtractModel::extractStatistics());
|
||||
$this->assign(UserExtractModel::systemPage($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
public function edit($id){
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$UserExtract = UserExtractModel::get($id);
|
||||
if(!$UserExtract) return JsonService::fail('数据不存在!');
|
||||
$f = array();
|
||||
$f[] = Form::input('real_name','姓名',$UserExtract['real_name']);
|
||||
$f[] = Form::number('extract_price','提现金额',$UserExtract['extract_price'])->precision(2);
|
||||
if($UserExtract['extract_type']=='alipay'){
|
||||
$f[] = Form::input('alipay_code','支付宝账号',$UserExtract['alipay_code']);
|
||||
}else if($UserExtract['extract_type']=='weixin'){
|
||||
$f[] = Form::input('wechat','微信号',$UserExtract['wechat']);
|
||||
}else{
|
||||
$f[] = Form::input('bank_code','银行卡号',$UserExtract['bank_code']);
|
||||
$f[] = Form::input('bank_address','开户行',$UserExtract['bank_address']);
|
||||
}
|
||||
$f[] = Form::input('mark','备注',$UserExtract['mark'])->type('textarea');
|
||||
$form = Form::make_post_form('编辑',$f,Url::buildUrl('update',array('id'=>$id)));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
|
||||
}
|
||||
public function update($id)
|
||||
{
|
||||
$UserExtract = UserExtractModel::get($id);
|
||||
if(!$UserExtract) return JsonService::fail('数据不存在!');
|
||||
if($UserExtract['extract_type']=='alipay'){
|
||||
$data = Util::postMore([
|
||||
'real_name',
|
||||
'mark',
|
||||
'extract_price',
|
||||
'alipay_code',
|
||||
]);
|
||||
if(!$data['real_name']) return JsonService::fail('请输入姓名');
|
||||
if($data['extract_price']<=-1) return JsonService::fail('请输入提现金额');
|
||||
if(!$data['alipay_code']) return JsonService::fail('请输入支付宝账号');
|
||||
}else if($UserExtract['extract_type']=='weixin'){
|
||||
$data = Util::postMore([
|
||||
'real_name',
|
||||
'mark',
|
||||
'extract_price',
|
||||
'wechat',
|
||||
]);
|
||||
// if(!$data['real_name']) return JsonService::fail('请输入姓名');
|
||||
if($data['extract_price']<=-1) return JsonService::fail('请输入提现金额');
|
||||
if(!$data['wechat']) return JsonService::fail('请输入微信账号');
|
||||
}else{
|
||||
$data = Util::postMore([
|
||||
'real_name',
|
||||
'extract_price',
|
||||
'mark',
|
||||
'bank_code',
|
||||
'bank_address',
|
||||
]);
|
||||
if(!$data['real_name']) return JsonService::fail('请输入姓名');
|
||||
if($data['extract_price']<=-1) return JsonService::fail('请输入提现金额');
|
||||
if(!$data['bank_code']) return JsonService::fail('请输入银行卡号');
|
||||
if(!$data['bank_address']) return JsonService::fail('请输入开户行');
|
||||
}
|
||||
if(!UserExtractModel::edit($data,$id))
|
||||
return JsonService::fail(UserExtractModel::getErrorInfo('修改失败'));
|
||||
else
|
||||
return JsonService::successful('修改成功!');
|
||||
}
|
||||
public function fail($id)
|
||||
{
|
||||
if(!UserExtractModel::be(['id'=>$id,'status'=>0])) return JsonService::fail('操作记录不存在或状态错误!');
|
||||
$fail_msg =request()->post();
|
||||
$extract=UserExtractModel::get($id);
|
||||
if(!$extract) return JsonService::fail('操作记录不存在!');
|
||||
if($extract->status==1) return JsonService::fail('已经提现,错误操作');
|
||||
if($extract->status==-1) return JsonService::fail('您的提现申请已被拒绝,请勿重复操作!');
|
||||
$res = UserExtractModel::changeFail($id,$fail_msg['message']);
|
||||
if($res){
|
||||
return JsonService::successful('操作成功!');
|
||||
}else{
|
||||
return JsonService::fail('操作失败!');
|
||||
}
|
||||
}
|
||||
public function succ($id)
|
||||
{
|
||||
if(!UserExtractModel::be(['id'=>$id,'status'=>0]))
|
||||
return JsonService::fail('操作记录不存在或状态错误!');
|
||||
UserExtractModel::beginTrans();
|
||||
$extract=UserExtractModel::get($id);
|
||||
if(!$extract) return JsonService::fail('操作记录不存!');
|
||||
if($extract->status == 1) return JsonService::fail('您已提现,请勿重复提现!');
|
||||
if($extract->status == -1) return JsonService::fail('您的提现申请已被拒绝!');
|
||||
$res = UserExtractModel::changeSuccess($id);
|
||||
if($res){
|
||||
UserExtractModel::commitTrans();
|
||||
return JsonService::successful('操作成功!');
|
||||
}else{
|
||||
UserExtractModel::rollbackTrans();
|
||||
return JsonService::fail('操作失败!');
|
||||
}
|
||||
}
|
||||
}
|
||||
142
app/admin/controller/finance/UserRecharge.php
Normal file
142
app/admin/controller/finance/UserRecharge.php
Normal file
@ -0,0 +1,142 @@
|
||||
<?php
|
||||
namespace app\admin\controller\finance;
|
||||
use app\admin\controller\AuthController;
|
||||
use app\admin\model\user\User;
|
||||
use app\admin\model\user\UserRecharge as UserRechargeModel;
|
||||
use app\models\routine\RoutineTemplate;
|
||||
use app\models\user\UserBill;
|
||||
use crmeb\services\JsonService;
|
||||
use crmeb\services\MiniProgramService;
|
||||
use crmeb\services\UtilService;
|
||||
use crmeb\services\WechatService;
|
||||
use crmeb\services\UtilService as Util;
|
||||
use crmeb\services\JsonService as Json;
|
||||
use think\facade\Route as Url;
|
||||
use crmeb\services\FormBuilder as Form;
|
||||
use crmeb\services\WechatTemplateService;
|
||||
use app\models\user\WechatUser as WechatUserWap;
|
||||
/**
|
||||
* 微信充值记录
|
||||
* Class UserRecharge
|
||||
* @package app\admin\controller\user
|
||||
*/
|
||||
class UserRecharge extends AuthController
|
||||
{
|
||||
/**
|
||||
* 显示操作记录
|
||||
*/
|
||||
public function index(){
|
||||
$this->assign( 'year',getMonth());
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function get_user_recharge_list(){
|
||||
$where = UtilService::getMore([
|
||||
['data',''],
|
||||
['paid',''],
|
||||
['page',1],
|
||||
['limit',20],
|
||||
['nickname',''],
|
||||
['excel',''],
|
||||
]);
|
||||
return JsonService::successlayui(UserRechargeModel::getUserRechargeList($where));
|
||||
}
|
||||
|
||||
public function delect($id = 0){
|
||||
if(!$id) return JsonService::fail('缺少参数');
|
||||
$rechargInfo = UserRechargeModel::get($id);
|
||||
if($rechargInfo->paid) return JsonService::fail('已支付的订单记录无法删除');
|
||||
if(UserRechargeModel::del($id))
|
||||
return JsonService::successful('删除成功');
|
||||
else
|
||||
return JsonService::fail('删除失败');
|
||||
}
|
||||
|
||||
public function get_badge(){
|
||||
$where = UtilService::getMore([
|
||||
['data',''],
|
||||
['paid',''],
|
||||
['nickname',''],
|
||||
]);
|
||||
return JsonService::successful(UserRechargeModel::getDataList($where));
|
||||
}
|
||||
/**退款
|
||||
* @param $id
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function edit($id){
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$UserRecharge = UserRechargeModel::get($id);
|
||||
if(!$UserRecharge) return Json::fail('数据不存在!');
|
||||
if($UserRecharge['paid'] == 1){
|
||||
$f = array();
|
||||
$f[] = Form::input('order_id','退款单号',$UserRecharge->getData('order_id'))->disabled(1);
|
||||
$f[] = Form::number('refund_price','退款金额',$UserRecharge->getData('price'))->precision(2)->min(0)->max($UserRecharge->getData('price'));
|
||||
$jsContent = <<<SCRIPT
|
||||
parent.SuccessFun();
|
||||
parent.layer.close(parent.layer.getFrameIndex(window.name));
|
||||
SCRIPT;
|
||||
$form = Form::make_post_form('编辑',$f,Url::buildUrl('updateRefundY',array('id'=>$id)),$jsContent);
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
else return Json::fail('数据不存在!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 退款更新
|
||||
* @param $id
|
||||
*/
|
||||
public function updateRefundY($id){
|
||||
$data = Util::postMore([
|
||||
'refund_price',
|
||||
]);
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$UserRecharge = UserRechargeModel::get($id);
|
||||
if(!$UserRecharge) return Json::fail('数据不存在!');
|
||||
if($UserRecharge['price'] == $UserRecharge['refund_price']) return Json::fail('已退完支付金额!不能再退款了');
|
||||
if(!$data['refund_price']) return Json::fail('请输入退款金额');
|
||||
$refund_price = $data['refund_price'];
|
||||
$data['refund_price'] = bcadd($data['refund_price'],$UserRecharge['refund_price'],2);
|
||||
$bj = bccomp((float)$UserRecharge['price'],(float)$data['refund_price'],2);
|
||||
if($bj < 0) return Json::fail('退款金额大于支付金额,请修改退款金额');
|
||||
$refund_data['pay_price'] = $UserRecharge['price'];
|
||||
$refund_data['refund_price'] = $refund_price;
|
||||
// $refund_data['refund_account']='REFUND_SOURCE_RECHARGE_FUNDS';
|
||||
try{
|
||||
$recharge_type = UserRechargeModel::where('order_id',$UserRecharge['order_id'])->value('recharge_type');
|
||||
if($recharge_type == 'weixin'){
|
||||
WechatService::payOrderRefund($UserRecharge['order_id'],$refund_data);
|
||||
}else{
|
||||
MiniProgramService::payOrderRefund($UserRecharge['order_id'],$refund_data);
|
||||
}
|
||||
}catch(\Exception $e){
|
||||
return Json::fail($e->getMessage());
|
||||
}
|
||||
UserRechargeModel::edit($data,$id);
|
||||
User::bcDec($UserRecharge['uid'],'now_money',$refund_price,'uid');
|
||||
switch (strtolower($UserRecharge['recharge_type'])){
|
||||
case 'weixin':
|
||||
WechatTemplateService::sendTemplate(WechatUserWap::where('uid',$UserRecharge['uid'])->value('openid'),WechatTemplateService::ORDER_REFUND_STATUS, [
|
||||
'first'=>'亲,您充值的金额已退款,本次退款'.
|
||||
$data['refund_price'].'金额',
|
||||
'keyword1'=>$UserRecharge['order_id'],
|
||||
'keyword2'=>$UserRecharge['price'],
|
||||
'keyword3'=>date('Y-m-d H:i:s',$UserRecharge['add_time']),
|
||||
'remark'=>'点击查看订单详情'
|
||||
],Url::buildUrl('wap/My/balance','',true,true));
|
||||
break;
|
||||
case 'routine':
|
||||
RoutineTemplate::sendOut('ORDER_REFUND_SUCCESS',$UserRecharge['uid'],[
|
||||
'keyword1'=>$UserRecharge['order_id'],
|
||||
'keyword2'=>date('Y-m-d H:i:s',time()),
|
||||
'keyword3'=>$UserRecharge['price'],
|
||||
'keyword4'=>'余额充值退款',
|
||||
'keyword5'=>'亲,您充值的金额已退款,本次退款'. $data['refund_price'].'金额',
|
||||
]);
|
||||
break;
|
||||
}
|
||||
UserBill::expend('系统退款',$UserRecharge['uid'],'now_money','user_recharge_refund',$refund_price,$id,$UserRecharge['price'],'退款给用户'.$refund_price.'元');
|
||||
return Json::successful('退款成功!');
|
||||
}
|
||||
}
|
||||
693
app/admin/controller/order/StoreOrder.php
Normal file
693
app/admin/controller/order/StoreOrder.php
Normal file
@ -0,0 +1,693 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/11/11
|
||||
*/
|
||||
namespace app\admin\controller\order;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use app\admin\model\system\Express;
|
||||
use crmeb\repositories\OrderRepository;
|
||||
use crmeb\services\ExpressService;
|
||||
use crmeb\services\MiniProgramService;
|
||||
use crmeb\services\UtilService;
|
||||
use crmeb\services\WechatService;
|
||||
use crmeb\services\FormBuilder as Form;
|
||||
use crmeb\services\HookService;
|
||||
use crmeb\subscribes\OrderSubscribe;
|
||||
use app\admin\model\order\StoreOrderStatus;
|
||||
use app\admin\model\ump\StorePink;
|
||||
use app\admin\model\user\User;
|
||||
use app\admin\model\user\UserBill;
|
||||
use crmeb\basic\BaseModel;
|
||||
use crmeb\services\CacheService;
|
||||
use crmeb\services\JsonService;
|
||||
use crmeb\services\UtilService as Util;
|
||||
use crmeb\services\JsonService as Json;
|
||||
use think\facade\Db;
|
||||
use think\facade\Route as Url;
|
||||
use app\admin\model\order\StoreOrder as StoreOrderModel;
|
||||
/**
|
||||
* 订单管理控制器 同一个订单表放在一个控制器
|
||||
* Class StoreOrder
|
||||
* @package app\admin\controller\store
|
||||
*/
|
||||
class StoreOrder extends AuthController
|
||||
{
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->assign([
|
||||
'year'=>getMonth(),
|
||||
'real_name'=>$this->request->get('real_name',''),
|
||||
'status'=>$this->request->param('status',''),
|
||||
'orderCount'=>StoreOrderModel::orderCount(),
|
||||
'payTypeCount'=>StoreOrderModel::payTypeCount(),
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
/**
|
||||
* 获取头部订单金额等信息
|
||||
* return json
|
||||
*
|
||||
*/
|
||||
public function getBadge(){
|
||||
$where = Util::postMore([
|
||||
['status',''],
|
||||
['real_name',''],
|
||||
['is_del',0],
|
||||
['data',''],
|
||||
['type',''],
|
||||
['pay_type',''],
|
||||
['order','']
|
||||
]);
|
||||
return JsonService::successful(StoreOrderModel::getBadge($where));
|
||||
}
|
||||
/**
|
||||
* 获取订单列表
|
||||
* return json
|
||||
*/
|
||||
public function order_list(){
|
||||
$where = Util::getMore([
|
||||
['status',''],
|
||||
['real_name',$this->request->param('real_name','')],
|
||||
['is_del',0],
|
||||
['data',''],
|
||||
['type',''],
|
||||
['pay_type',''],
|
||||
['order',''],
|
||||
['page',1],
|
||||
['limit',20],
|
||||
['excel',0]
|
||||
]);
|
||||
return JsonService::successlayui(StoreOrderModel::OrderList($where));
|
||||
}
|
||||
public function orderchart(){
|
||||
$where = Util::getMore([
|
||||
['status',''],
|
||||
['real_name',''],
|
||||
['is_del',0],
|
||||
['data',''],
|
||||
['combination_id',''],
|
||||
['export',0],
|
||||
['order','id desc']
|
||||
],$this->request);
|
||||
$limitTimeList = [
|
||||
'today'=>implode(' - ',[date('Y/m/d'),date('Y/m/d',strtotime('+1 day'))]),
|
||||
'week'=>implode(' - ',[
|
||||
date('Y/m/d', (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600)),
|
||||
date('Y-m-d', (time() + (7 - (date('w') == 0 ? 7 : date('w'))) * 24 * 3600))
|
||||
]),
|
||||
'month'=>implode(' - ',[date('Y/m').'/01',date('Y/m').'/'.date('t')]),
|
||||
'quarter'=>implode(' - ',[
|
||||
date('Y').'/'.(ceil((date('n'))/3)*3-3+1).'/01',
|
||||
date('Y').'/'.(ceil((date('n'))/3)*3).'/'.date('t',mktime(0,0,0,(ceil((date('n'))/3)*3),1,date('Y')))
|
||||
]),
|
||||
'year'=>implode(' - ',[
|
||||
date('Y').'/01/01',date('Y/m/d',strtotime(date('Y').'/01/01 + 1year -1 day'))
|
||||
])
|
||||
];
|
||||
if($where['data'] == '') $where['data'] = $limitTimeList['today'];
|
||||
$orderCount = [
|
||||
urlencode('未支付')=>StoreOrderModel::getOrderWhere($where,StoreOrderModel::statusByWhere(0))->count(),
|
||||
urlencode('未发货')=>StoreOrderModel::getOrderWhere($where,StoreOrderModel::statusByWhere(1))->count(),
|
||||
urlencode('待收货')=>StoreOrderModel::getOrderWhere($where,StoreOrderModel::statusByWhere(2))->count(),
|
||||
urlencode('待评价')=>StoreOrderModel::getOrderWhere($where,StoreOrderModel::statusByWhere(3))->count(),
|
||||
urlencode('交易完成')=>StoreOrderModel::getOrderWhere($where,StoreOrderModel::statusByWhere(4))->count(),
|
||||
urlencode('退款中')=>StoreOrderModel::getOrderWhere($where,StoreOrderModel::statusByWhere(-1))->count(),
|
||||
urlencode('已退款')=>StoreOrderModel::getOrderWhere($where,StoreOrderModel::statusByWhere(-2))->count()
|
||||
];
|
||||
$model = StoreOrderModel::getOrderWhere($where,new StoreOrderModel())->field('sum(total_num) total_num,count(*) count,sum(total_price) total_price,sum(refund_price) refund_price,from_unixtime(add_time,\'%Y-%m-%d\') add_time')
|
||||
->group('from_unixtime(add_time,\'%Y-%m-%d\')');
|
||||
$orderPrice = $model->select()->toArray();
|
||||
$orderDays = [];
|
||||
$orderCategory = [
|
||||
['name'=>'商品数','type'=>'line','data'=>[]],
|
||||
['name'=>'订单数','type'=>'line','data'=>[]],
|
||||
['name'=>'订单金额','type'=>'line','data'=>[]],
|
||||
['name'=>'退款金额','type'=>'line','data'=>[]]
|
||||
];
|
||||
foreach ($orderPrice as $price){
|
||||
$orderDays[] = $price['add_time'];
|
||||
$orderCategory[0]['data'][] = $price['total_num'];
|
||||
$orderCategory[1]['data'][] = $price['count'];
|
||||
$orderCategory[2]['data'][] = $price['total_price'];
|
||||
$orderCategory[3]['data'][] = $price['refund_price'];
|
||||
}
|
||||
$this->assign(StoreOrderModel::systemPage($where,$this->adminId));
|
||||
$this->assign('price',StoreOrderModel::getOrderPrice($where));
|
||||
$this->assign(compact('limitTimeList','where','orderCount','orderPrice','orderDays','orderCategory'));
|
||||
return $this->fetch();
|
||||
}
|
||||
/**
|
||||
* 修改支付金额等
|
||||
* @param $id
|
||||
* @return mixed|\think\response\Json|void
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = StoreOrderModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
$f = array();
|
||||
$f[] = Form::input('order_id','订单编号',$product->getData('order_id'))->disabled(1);
|
||||
$f[] = Form::number('total_price','商品总价',$product->getData('total_price'))->min(0);
|
||||
$f[] = Form::number('total_postage','原始邮费',$product->getData('total_postage'))->min(0);
|
||||
$f[] = Form::number('pay_price','实际支付金额',$product->getData('pay_price'))->min(0);
|
||||
$f[] = Form::number('pay_postage','实际支付邮费',$product->getData('pay_postage'));
|
||||
$f[] = Form::number('gain_integral','赠送积分',$product->getData('gain_integral'));
|
||||
// $f[] = Form::radio('status','状态',$product->getData('status'))->options([['label'=>'开启','value'=>1],['label'=>'关闭','value'=>0]]);
|
||||
$form = Form::make_post_form('修改订单',$f,Url::buildUrl('update',array('id'=>$id)));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改订单提交更新
|
||||
* @param $id
|
||||
*/
|
||||
public function update($id)
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'order_id',
|
||||
'total_price',
|
||||
'total_postage',
|
||||
'pay_price',
|
||||
'pay_postage',
|
||||
'gain_integral',
|
||||
]);
|
||||
if($data['total_price'] <= 0) return Json::fail('请输入商品总价');
|
||||
if($data['pay_price'] <= 0) return Json::fail('请输入实际支付金额');
|
||||
$data['order_id'] = StoreOrderModel::changeOrderId($data['order_id']);
|
||||
StoreOrderModel::edit($data,$id);
|
||||
event('StoreProductOrderEditAfter',[$data,$id]);
|
||||
StoreOrderStatus::setStatus($id,'order_edit','修改商品总价为:'.$data['total_price'].' 实际支付金额'.$data['pay_price']);
|
||||
return Json::successful('修改成功!');
|
||||
}
|
||||
|
||||
/*
|
||||
* 发送货
|
||||
* @param int $id
|
||||
* @return html
|
||||
* */
|
||||
public function order_goods($id = 0)
|
||||
{
|
||||
$list = Express::where('is_show',1)->order('sort desc')->column('name','id');
|
||||
$this->assign([
|
||||
'list'=>$list,
|
||||
'id'=>$id
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
/*
|
||||
* 删除订单
|
||||
* */
|
||||
public function del_order()
|
||||
{
|
||||
$ids = UtilService::postMore(['ids'])['ids'];
|
||||
if(!count($ids)) return JsonService::fail('请选择需要删除的订单');
|
||||
if(StoreOrderModel::where('is_del',0)->where('id','in',$ids)->count()) return JsonService::fail('您选择的的订单存在用户未删除的订单,无法删除用户未删除的订单');
|
||||
$res=StoreOrderModel::where('id','in',$ids)->update(['is_system_del'=>1]);
|
||||
if($res)
|
||||
return JsonService::successful('删除成功');
|
||||
else
|
||||
return JsonService::fail('删除失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 送货信息提交
|
||||
* @param Request $request
|
||||
* @param $id
|
||||
*/
|
||||
public function update_delivery($id = 0){
|
||||
$data = Util::postMore([
|
||||
['type',1],
|
||||
['delivery_name',''],
|
||||
['delivery_id',''],
|
||||
['sh_delivery_name',''],
|
||||
['sh_delivery_id',''],
|
||||
],$this->request);
|
||||
switch ((int)$data['type']){
|
||||
case 1:
|
||||
//发货
|
||||
$data['delivery_type'] = 'express';
|
||||
if(!$data['delivery_name']) return Json::fail('请选择快递公司');
|
||||
if(!$data['delivery_id']) return Json::fail('请输入快递单号');
|
||||
$data['status'] = 1;
|
||||
StoreOrderModel::edit($data,$id);
|
||||
event('StoreProductOrderDeliveryGoodsAfter',[$data,$id]);
|
||||
StoreOrderStatus::setStatus($id,'delivery_goods','已发货 快递公司:'.$data['delivery_name'].' 快递单号:'.$data['delivery_id']);
|
||||
break;
|
||||
case 2:
|
||||
//送货
|
||||
$data['delivery_type'] = 'send';
|
||||
$data['delivery_name'] = $data['sh_delivery_name'];
|
||||
$data['delivery_id'] = $data['sh_delivery_id'];
|
||||
unset($data['sh_delivery_name'],$data['sh_delivery_id']);
|
||||
if(!$data['delivery_name']) return Json::fail('请输入送货人姓名');
|
||||
if(!(int)$data['delivery_id']) return Json::fail('请输入送货人电话号码');
|
||||
else if(!preg_match("/^1[3456789]{1}\d{9}$/",$data['delivery_id'])) return Json::fail('请输入正确的送货人电话号码');
|
||||
$data['status'] = 1;
|
||||
StoreOrderModel::edit($data,$id);
|
||||
event('StoreProductOrderDeliveryAfter',[$data,$id]);
|
||||
StoreOrderStatus::setStatus($id,'delivery','已配送 发货人:'.$data['delivery_name'].' 发货人电话:'.$data['delivery_id']);
|
||||
break;
|
||||
case 3:
|
||||
//虚拟发货
|
||||
$data['delivery_type'] = 'fictitious';
|
||||
$data['status'] = 1;
|
||||
StoreOrderModel::edit($data,$id);
|
||||
event('StoreProductOrderDeliveryAfter',[$data,$id]);
|
||||
StoreOrderStatus::setStatus($id,'delivery_fictitious','已虚拟发货');
|
||||
break;
|
||||
default:
|
||||
return Json::fail('暂时不支持其他发货类型');
|
||||
break;
|
||||
}
|
||||
return Json::successful('修改成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 填写送货信息
|
||||
* @param $id
|
||||
* @return mixed|void
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function delivery($id){
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = StoreOrderModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
if($product['paid'] == 1 && $product['status'] == 0) {
|
||||
$f = array();
|
||||
$f[] = Form::input('delivery_name','送货人姓名')->required('送货人姓名不能为空','required:true;');
|
||||
$f[] = Form::input('delivery_id','送货人电话')->required('请输入正确电话号码','telephone');
|
||||
$form = Form::make_post_form('修改订单',$f,Url::buildUrl('updateDelivery',array('id'=>$id)),7);
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
else $this->failedNotice('订单状态错误');
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 送货信息提交
|
||||
* @param $id
|
||||
*/
|
||||
public function updateDelivery($id){
|
||||
$data = Util::postMore([
|
||||
'delivery_name',
|
||||
'delivery_id',
|
||||
]);
|
||||
$data['delivery_type'] = 'send';
|
||||
if(!$data['delivery_name']) return Json::fail('请输入送货人姓名');
|
||||
if(!(int)$data['delivery_id']) return Json::fail('请输入送货人电话号码');
|
||||
else if(!preg_match("/^1[3456789]{1}\d{9}$/",$data['delivery_id'])) return Json::fail('请输入正确的送货人电话号码');
|
||||
$data['status'] = 1;
|
||||
StoreOrderModel::edit($data,$id);
|
||||
event('StoreProductOrderDeliveryAfter',[$data,$id]);
|
||||
StoreOrderStatus::setStatus($id,'delivery','已配送 发货人:'.$data['delivery_name'].' 发货人电话:'.$data['delivery_id']);
|
||||
return Json::successful('修改成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 填写发货信息
|
||||
* @param $id
|
||||
* @return mixed|void
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function deliver_goods($id){
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = StoreOrderModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
if($product['paid'] == 1 && $product['status'] == 0){
|
||||
$f = array();
|
||||
$f[] = Form::select('delivery_name','快递公司')->setOptions(function(){
|
||||
$list = Db::name('express')->where('is_show',1)->order('sort DESC')->column('name','id');
|
||||
$menus = [];
|
||||
foreach ($list as $k=>$v){
|
||||
$menus[] = ['value'=>$v,'label'=>$v];
|
||||
}
|
||||
return $menus;
|
||||
})->filterable(1);
|
||||
$f[] = Form::input('delivery_id','快递单号');
|
||||
$form = Form::make_post_form('修改订单',$f,Url::buildUrl('updateDeliveryGoods',array('id'=>$id)),7);
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
else return $this->failedNotice('订单状态错误');
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 发货信息提交
|
||||
* @param $id
|
||||
*/
|
||||
public function updateDeliveryGoods($id){
|
||||
$data = Util::postMore([
|
||||
'delivery_name',
|
||||
'delivery_id',
|
||||
]);
|
||||
$data['delivery_type'] = 'express';
|
||||
if(!$data['delivery_name']) return Json::fail('请选择快递公司');
|
||||
if(!$data['delivery_id']) return Json::fail('请输入快递单号');
|
||||
$data['status'] = 1;
|
||||
StoreOrderModel::edit($data,$id);
|
||||
event('StoreProductOrderDeliveryGoodsAfter',[$data,$id]);
|
||||
StoreOrderStatus::setStatus($id,'delivery_goods','已发货 快递公司:'.$data['delivery_name'].' 快递单号:'.$data['delivery_id']);
|
||||
return Json::successful('修改成功!');
|
||||
}
|
||||
/**
|
||||
* 修改状态为已收货
|
||||
* @param $id
|
||||
* @return \think\response\Json|void
|
||||
*/
|
||||
public function take_delivery($id){
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$order = StoreOrderModel::get($id);
|
||||
if(!$order) return Json::fail('数据不存在!');
|
||||
if($order['status'] == 2) return Json::fail('不能重复收货!');
|
||||
if($order['paid'] == 1 && $order['status'] == 1) $data['status'] = 2;
|
||||
else if($order['pay_type'] == 'offline') $data['status'] = 2;
|
||||
else return Json::fail('请先发货或者送货!');
|
||||
if(!StoreOrderModel::edit($data,$id))
|
||||
return Json::fail(StoreOrderModel::getErrorInfo('收货失败,请稍候再试!'));
|
||||
else{
|
||||
try{
|
||||
OrderRepository::storeProductOrderTakeDeliveryAdmin($order, $id);
|
||||
}catch (\Exception $e){
|
||||
return Json::fail($e->getMessage());
|
||||
}
|
||||
StoreOrderStatus::setStatus($id,'take_delivery','已收货');
|
||||
return Json::successful('收货成功!');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 修改退款状态
|
||||
* @param $id
|
||||
* @return \think\response\Json|void
|
||||
*/
|
||||
public function refund_y($id){
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = StoreOrderModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
if($product['paid'] == 1){
|
||||
$f = array();
|
||||
$f[] = Form::input('order_id','退款单号',$product->getData('order_id'))->disabled(1);
|
||||
$f[] = Form::number('refund_price','退款金额',$product->getData('pay_price'))->precision(2)->min(0.01);
|
||||
$f[] = Form::radio('type','状态',1)->options([['label'=>'直接退款','value'=>1],['label'=>'退款后,返回原状态','value'=>2]]);
|
||||
$form = Form::make_post_form('退款处理',$f,Url::buildUrl('updateRefundY',array('id'=>$id)),7);
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
else return Json::fail('数据不存在!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 退款处理
|
||||
* @param $id
|
||||
*/
|
||||
public function updateRefundY($id){
|
||||
$data = Util::postMore([
|
||||
'refund_price',
|
||||
['type',1],
|
||||
]);
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = StoreOrderModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
if($product['pay_price'] == $product['refund_price']) return Json::fail('已退完支付金额!不能再退款了');
|
||||
if(!$data['refund_price']) return Json::fail('请输入退款金额');
|
||||
$refund_price = $data['refund_price'];
|
||||
$data['refund_price'] = bcadd($data['refund_price'],$product['refund_price'],2);
|
||||
$bj = bccomp((float)$product['pay_price'],(float)$data['refund_price'],2);
|
||||
if($bj < 0) return Json::fail('退款金额大于支付金额,请修改退款金额');
|
||||
if($data['type'] == 1){
|
||||
$data['refund_status'] = 2;
|
||||
}else if($data['type'] == 2){
|
||||
$data['refund_status'] = 0;
|
||||
}
|
||||
$type = $data['type'];
|
||||
unset($data['type']);
|
||||
$refund_data['pay_price'] = $product['pay_price'];
|
||||
$refund_data['refund_price'] = $refund_price;
|
||||
if($product['pay_type'] == 'weixin'){
|
||||
if($product['is_channel']){//小程序
|
||||
try{
|
||||
MiniProgramService::payOrderRefund($product['order_id'],$refund_data);//2.5.36
|
||||
}catch(\Exception $e){
|
||||
return Json::fail($e->getMessage());
|
||||
}
|
||||
}else{//TODO 公众号
|
||||
try{
|
||||
WechatService::payOrderRefund($product['order_id'],$refund_data);
|
||||
}catch(\Exception $e){
|
||||
return Json::fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
}else if($product['pay_type'] == 'yue'){
|
||||
BaseModel::beginTrans();
|
||||
$usermoney = User::where('uid',$product['uid'])->value('now_money');
|
||||
$res1 = User::bcInc($product['uid'],'now_money',$refund_price,'uid');
|
||||
$res2 = $res2 = UserBill::income('商品退款',$product['uid'],'now_money','pay_product_refund',$refund_price,$product['id'],bcadd($usermoney,$refund_price,2),'订单退款到余额'.floatval($refund_price).'元');
|
||||
try{
|
||||
OrderRepository::storeOrderYueRefund($product, $refund_data);
|
||||
}catch (\Exception $e){
|
||||
BaseModel::rollbackTrans();
|
||||
return Json::fail($e->getMessage());
|
||||
}
|
||||
$res = $res1 && $res2;
|
||||
BaseModel::checkTrans($res);
|
||||
if(!$res) return Json::fail('余额退款失败!');
|
||||
}
|
||||
$resEdit = StoreOrderModel::edit($data,$id);
|
||||
if($resEdit){
|
||||
$data['type'] = $type;
|
||||
if($data['type'] == 1) StorePink::setRefundPink($id);
|
||||
try{
|
||||
OrderRepository::storeProductOrderRefundY($data, $id);
|
||||
}catch (\Exception $e){
|
||||
BaseModel::rollbackTrans();
|
||||
return Json::fail($e->getMessage());
|
||||
}
|
||||
StoreOrderStatus::setStatus($id,'refund_price','退款给用户'.$refund_price.'元');
|
||||
BaseModel::commitTrans();
|
||||
return Json::successful('修改成功!');
|
||||
}else{
|
||||
StoreOrderStatus::setStatus($id,'refund_price','退款给用户'.$refund_price.'元失败');
|
||||
return Json::successful('修改失败!');
|
||||
}
|
||||
}
|
||||
public function order_info($oid = '')
|
||||
{
|
||||
if(!$oid || !($orderInfo = StoreOrderModel::get($oid)))
|
||||
return $this->failed('订单不存在!');
|
||||
$userInfo = User::getUserInfos($orderInfo['uid']);
|
||||
if($userInfo['spread_uid']){
|
||||
$spread = User::where('uid',$userInfo['spread_uid'])->value('nickname');
|
||||
}else{
|
||||
$spread ='';
|
||||
}
|
||||
$this->assign(compact('orderInfo','userInfo','spread'));
|
||||
return $this->fetch();
|
||||
}
|
||||
public function express($oid = '')
|
||||
{
|
||||
if(!$oid || !($order = StoreOrderModel::get($oid)))
|
||||
return $this->failed('订单不存在!');
|
||||
if($order['delivery_type'] != 'express' || !$order['delivery_id']) return $this->failed('该订单不存在快递单号!');
|
||||
$cacheName = $order['order_id'].$order['delivery_id'];
|
||||
$result = CacheService::get($cacheName,null);
|
||||
if($result === null){
|
||||
$result = ExpressService::query($order['delivery_id']);
|
||||
if(is_array($result) &&
|
||||
isset($result['result']) &&
|
||||
isset($result['result']['deliverystatus']) &&
|
||||
$result['result']['deliverystatus'] >= 3)
|
||||
$cacheTime = 0;
|
||||
else
|
||||
$cacheTime = 1800;
|
||||
CacheService::set($cacheName,$result,$cacheTime);
|
||||
}
|
||||
$this->assign([
|
||||
'order'=>$order,
|
||||
'express'=>$result
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
/**
|
||||
* 修改配送信息
|
||||
* @param $id
|
||||
* @return mixed|\think\response\Json|void
|
||||
*/
|
||||
public function distribution($id){
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = StoreOrderModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
$f = array();
|
||||
$f[] = Form::input('order_id','退款单号',$product->getData('order_id'))->disabled(1);
|
||||
if($product['delivery_type'] == 'send'){
|
||||
$f[] = Form::input('delivery_name','送货人姓名',$product->getData('delivery_name'));
|
||||
$f[] = Form::input('delivery_id','送货人电话',$product->getData('delivery_id'));
|
||||
}else if($product['delivery_type'] == 'express'){
|
||||
$f[] = Form::select('delivery_name','快递公司',$product->getData('delivery_name'))->setOptions(function (){
|
||||
$list = Db::name('express')->where('is_show',1)->column('name','id');
|
||||
$menus = [];
|
||||
foreach ($list as $k=>$v){
|
||||
$menus[] = ['value'=>$v,'label'=>$v];
|
||||
}
|
||||
return $menus;
|
||||
});
|
||||
$f[] = Form::input('delivery_id','快递单号',$product->getData('delivery_id'));
|
||||
}
|
||||
$form = Form::make_post_form('配送信息',$f,Url::buildUrl('updateDistribution',array('id'=>$id)),7);
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改配送信息
|
||||
* @param $id
|
||||
*/
|
||||
public function updateDistribution($id){
|
||||
$data = Util::postMore([
|
||||
'delivery_name',
|
||||
'delivery_id',
|
||||
]);
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = StoreOrderModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
if($product['delivery_type'] == 'send'){
|
||||
if(!$data['delivery_name']) return Json::fail('请输入送货人姓名');
|
||||
if(!(int)$data['delivery_id']) return Json::fail('请输入送货人电话号码');
|
||||
else if(!preg_match("/^1[3456789]{1}\d{9}$/",$data['delivery_id'])) return Json::fail('请输入正确的送货人电话号码');
|
||||
}else if($product['delivery_type'] == 'express'){
|
||||
if(!$data['delivery_name']) return Json::fail('请选择快递公司');
|
||||
if(!$data['delivery_id']) return Json::fail('请输入快递单号');
|
||||
}
|
||||
StoreOrderModel::edit($data,$id);
|
||||
event('StoreProductOrderDistributionAfter',[$data,$id]);
|
||||
StoreOrderStatus::setStatus($id,'distribution','修改发货信息为'.$data['delivery_name'].'号'.$data['delivery_id']);
|
||||
return Json::successful('修改成功!');
|
||||
}
|
||||
/**
|
||||
* 修改退款状态
|
||||
* @param $id
|
||||
* @return mixed|\think\response\Json|void
|
||||
*/
|
||||
public function refund_n($id){
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = StoreOrderModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
$f[] = Form::input('order_id','退款单号',$product->getData('order_id'))->disabled(1);
|
||||
$f[] = Form::input('refund_reason','退款原因')->type('textarea');
|
||||
$form = Form::make_post_form('退款',$f,Url::buildUrl('updateRefundN',array('id'=>$id)));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/**
|
||||
* 不退款原因
|
||||
* @param $id
|
||||
*/
|
||||
public function updateRefundN($id){
|
||||
$data = Util::postMore([
|
||||
'refund_reason',
|
||||
]);
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = StoreOrderModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
if(!$data['refund_reason']) return Json::fail('请输入退款原因');
|
||||
$data['refund_status'] = 0;
|
||||
StoreOrderModel::edit($data,$id);
|
||||
event('StoreProductOrderRefundNAfter',[$data['refund_reason'],$id]);
|
||||
StoreOrderStatus::setStatus($id,'refund_n','不退款原因:'.$data['refund_reason']);
|
||||
return Json::successful('修改成功!');
|
||||
}
|
||||
/**
|
||||
* 立即支付
|
||||
* @param $id
|
||||
*/
|
||||
public function offline($id){
|
||||
$res = StoreOrderModel::updateOffline($id);
|
||||
if($res){
|
||||
event('StoreProductOrderOffline',[$id]);
|
||||
StoreOrderStatus::setStatus($id,'offline','线下付款');
|
||||
return Json::successful('修改成功!');
|
||||
}else{
|
||||
return Json::fail(StoreOrderModel::getErrorInfo('修改失败!'));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 修改积分和金额
|
||||
* @param $id
|
||||
* @return mixed|\think\response\Json|void
|
||||
*/
|
||||
public function integral_back($id){
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = StoreOrderModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
if($product['paid'] == 1){
|
||||
$f[] = Form::input('order_id','退款单号',$product->getData('order_id'))->disabled(1);
|
||||
$f[] = Form::number('use_integral','使用的积分',$product->getData('use_integral'))->min(0)->disabled(1);
|
||||
$f[] = Form::number('use_integrals','已退积分',$product->getData('back_integral'))->min(0)->disabled(1);
|
||||
$f[] = Form::number('back_integral','可退积分',bcsub($product->getData('use_integral'),$product->getData('use_integral')))->min(0);
|
||||
$form = Form::make_post_form('退积分',$f,Url::buildUrl('updateIntegralBack',array('id'=>$id)),7);
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}else{
|
||||
return Json::fail('参数错误!');
|
||||
}
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/**
|
||||
* 退积分保存
|
||||
* @param $id
|
||||
*/
|
||||
public function updateIntegralBack($id){
|
||||
$data = Util::postMore([
|
||||
'back_integral',
|
||||
]);
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = StoreOrderModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
if($data['back_integral'] <= 0) return Json::fail('请输入积分');
|
||||
if($product['use_integral'] == $product['back_integral']) return Json::fail('已退完积分!不能再积分了');
|
||||
$back_integral = $data['back_integral'];
|
||||
$data['back_integral'] = bcadd($data['back_integral'],$product['back_integral'],2);
|
||||
$bj = bccomp((float)$product['use_integral'],(float)$data['back_integral'],2);
|
||||
if($bj < 0) return Json::fail('退积分大于支付积分,请修改退积分');
|
||||
BaseModel::beginTrans();
|
||||
$integral = User::where('uid',$product['uid'])->value('integral');
|
||||
$res1 = User::bcInc($product['uid'],'integral',$back_integral,'uid');
|
||||
$res2 = UserBill::income('商品退积分',$product['uid'],'integral','pay_product_integral_back',$back_integral,$product['id'],bcadd($integral,$back_integral,2),'订单退积分'.floatval($back_integral).'积分到用户积分');
|
||||
event('StoreOrderIntegralBack',[$product,$back_integral]);
|
||||
try{
|
||||
OrderRepository::storeOrderIntegralBack($product,$back_integral);
|
||||
}catch (\Exception $e){
|
||||
BaseModel::rollbackTrans();
|
||||
return Json::fail($e->getMessage());
|
||||
}
|
||||
$res = $res1 && $res2;
|
||||
BaseModel::checkTrans($res);
|
||||
if(!$res) return Json::fail('退积分失败!');
|
||||
StoreOrderModel::edit($data,$id);
|
||||
StoreOrderStatus::setStatus($id,'integral_back','商品退积分:'.$data['back_integral']);
|
||||
return Json::successful('退积分成功!');
|
||||
}
|
||||
public function remark(){
|
||||
$data = Util::postMore(['id','remark']);
|
||||
if(!$data['id']) return Json::fail('参数错误!');
|
||||
if($data['remark'] == '') return Json::fail('请输入要备注的内容!');
|
||||
$id = $data['id'];
|
||||
unset($data['id']);
|
||||
StoreOrderModel::edit($data,$id);
|
||||
return Json::successful('备注成功!');
|
||||
}
|
||||
public function order_status($oid){
|
||||
if(!$oid) return $this->failed('数据不存在');
|
||||
$this->assign(StoreOrderStatus::systemPage($oid));
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
590
app/admin/controller/order/combinationOrder.php
Normal file
590
app/admin/controller/order/combinationOrder.php
Normal file
@ -0,0 +1,590 @@
|
||||
<?php
|
||||
namespace app\admin\controller\order;
|
||||
use crmeb\repositories\OrderRepository;
|
||||
use crmeb\services\ExpressService;
|
||||
use crmeb\services\MiniProgramService;
|
||||
use crmeb\services\WechatService;
|
||||
use crmeb\basic\BaseModel;
|
||||
use crmeb\services\CacheService;
|
||||
use crmeb\services\UtilService as Util;
|
||||
use crmeb\services\JsonService as Json;
|
||||
use think\facade\Db;
|
||||
use think\facade\Route as Url;
|
||||
use app\admin\controller\AuthController;
|
||||
use crmeb\services\FormBuilder as Form;
|
||||
use app\admin\model\order\StoreOrderStatus;
|
||||
use app\admin\model\ump\StorePink;
|
||||
use app\admin\model\user\User;
|
||||
use app\admin\model\user\UserBill;
|
||||
use app\admin\model\order\StoreOrder as StoreOrderModel;
|
||||
/**
|
||||
* 订单管理控制器
|
||||
* Class StoreOrder
|
||||
* @package app\admin\controller\store
|
||||
*/
|
||||
class CombinationOrder extends AuthController
|
||||
{
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$where = Util::getMore([
|
||||
['status',''],
|
||||
['real_name',''],
|
||||
['is_del',0],
|
||||
['data',''],
|
||||
['combination_id',''],
|
||||
['export',0],
|
||||
['order','id desc']
|
||||
],$this->request);
|
||||
$limitTimeList = [
|
||||
'yesterday'=>implode(' - ',[date('Y/m/d',strtotime('-1 day')),date('Y/m/d')]),
|
||||
'today'=>implode(' - ',[date('Y/m/d'),date('Y/m/d',strtotime('+1 day'))]),
|
||||
'week'=>implode(' - ',[
|
||||
date('Y/m/d', (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600)),
|
||||
date('Y-m-d', (time() + (7 - (date('w') == 0 ? 7 : date('w'))) * 24 * 3600))
|
||||
]),
|
||||
'month'=>implode(' - ',[date('Y/m').'/01',date('Y/m').'/'.date('t')]),
|
||||
'quarter'=>implode(' - ',[
|
||||
date('Y').'/'.(ceil((date('n'))/3)*3-3+1).'/01',
|
||||
date('Y').'/'.(ceil((date('n'))/3)*3).'/'.date('t',mktime(0,0,0,(ceil((date('n'))/3)*3),1,date('Y')))
|
||||
]),
|
||||
'year'=>implode(' - ',[
|
||||
date('Y').'/01/01',date('Y/m/d',strtotime(date('Y').'/01/01 + 1year -1 day'))
|
||||
])
|
||||
];
|
||||
$this->assign(StoreOrderModel::systemPage($where,$this->adminId));
|
||||
$this->assign('price',StoreOrderModel::getOrderPrice($where));
|
||||
$this->assign(compact('where','limitTimeList'));
|
||||
return $this->fetch();
|
||||
}
|
||||
public function orderchart(){
|
||||
$where = Util::getMore([
|
||||
['status',''],
|
||||
['real_name',''],
|
||||
['is_del',0],
|
||||
['data',''],
|
||||
['combination_id',''],
|
||||
['export',0],
|
||||
['order','id desc']
|
||||
],$this->request);
|
||||
$limitTimeList = [
|
||||
'today'=>implode(' - ',[date('Y/m/d'),date('Y/m/d',strtotime('+1 day'))]),
|
||||
'week'=>implode(' - ',[
|
||||
date('Y/m/d', (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600)),
|
||||
date('Y-m-d', (time() + (7 - (date('w') == 0 ? 7 : date('w'))) * 24 * 3600))
|
||||
]),
|
||||
'month'=>implode(' - ',[date('Y/m').'/01',date('Y/m').'/'.date('t')]),
|
||||
'quarter'=>implode(' - ',[
|
||||
date('Y').'/'.(ceil((date('n'))/3)*3-3+1).'/01',
|
||||
date('Y').'/'.(ceil((date('n'))/3)*3).'/'.date('t',mktime(0,0,0,(ceil((date('n'))/3)*3),1,date('Y')))
|
||||
]),
|
||||
'year'=>implode(' - ',[
|
||||
date('Y').'/01/01',date('Y/m/d',strtotime(date('Y').'/01/01 + 1year -1 day'))
|
||||
])
|
||||
];
|
||||
if($where['data'] == '') $where['data'] = $limitTimeList['today'];
|
||||
$orderCount = [
|
||||
urlencode('未支付')=>StoreOrderModel::getOrderWhere($where,StoreOrderModel::statusByWhere(0))->count(),
|
||||
urlencode('未发货')=>StoreOrderModel::getOrderWhere($where,StoreOrderModel::statusByWhere(1))->count(),
|
||||
urlencode('待收货')=>StoreOrderModel::getOrderWhere($where,StoreOrderModel::statusByWhere(2))->count(),
|
||||
urlencode('待评价')=>StoreOrderModel::getOrderWhere($where,StoreOrderModel::statusByWhere(3))->count(),
|
||||
urlencode('交易完成')=>StoreOrderModel::getOrderWhere($where,StoreOrderModel::statusByWhere(4))->count(),
|
||||
urlencode('退款中')=>StoreOrderModel::getOrderWhere($where,StoreOrderModel::statusByWhere(-1))->count(),
|
||||
urlencode('已退款')=>StoreOrderModel::getOrderWhere($where,StoreOrderModel::statusByWhere(-2))->count()
|
||||
];
|
||||
$model = StoreOrderModel::getOrderWhere($where,new StoreOrderModel())->field('sum(total_num) total_num,count(*) count,sum(total_price) total_price,sum(refund_price) refund_price,from_unixtime(add_time,\'%Y-%m-%d\') add_time')
|
||||
->group('from_unixtime(add_time,\'%Y-%m-%d\')');
|
||||
$orderPrice = $model->select()->toArray();
|
||||
$orderDays = [];
|
||||
$orderCategory = [
|
||||
['name'=>'商品数','type'=>'line','data'=>[]],
|
||||
['name'=>'订单数','type'=>'line','data'=>[]],
|
||||
['name'=>'订单金额','type'=>'line','data'=>[]],
|
||||
['name'=>'退款金额','type'=>'line','data'=>[]]
|
||||
];
|
||||
foreach ($orderPrice as $price){
|
||||
$orderDays[] = $price['add_time'];
|
||||
$orderCategory[0]['data'][] = $price['total_num'];
|
||||
$orderCategory[1]['data'][] = $price['count'];
|
||||
$orderCategory[2]['data'][] = $price['total_price'];
|
||||
$orderCategory[3]['data'][] = $price['refund_price'];
|
||||
}
|
||||
$this->assign(StoreOrderModel::systemPage($where,$this->adminId));
|
||||
$this->assign('price',StoreOrderModel::getOrderPrice($where));
|
||||
$this->assign(compact('limitTimeList','where','orderCount','orderPrice','orderDays','orderCategory'));
|
||||
return $this->fetch();
|
||||
}
|
||||
/**
|
||||
* 修改支付金额等
|
||||
* @param $id
|
||||
* @return mixed|\think\response\Json|void
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = StoreOrderModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
$this->assign([
|
||||
'title'=>'修改订单','rules'=>$this->read($id)->getContent(),
|
||||
'action'=>Url::buildUrl('update',array('id'=>$id))
|
||||
]);
|
||||
return $this->fetch('public/common_form');
|
||||
}
|
||||
public function read($id)
|
||||
{
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = StoreOrderModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
Form::text('order_id','订单编号',$product->getData('order_id'))->readonly();
|
||||
Form::number('total_price','商品总价',$product->getData('total_price'))->min(0);
|
||||
Form::number('total_postage','原始邮费',$product->getData('total_postage'))->min(0);
|
||||
Form::number('pay_price','实际支付金额',$product->getData('pay_price'))->min(0);
|
||||
Form::number('pay_postage','实际支付邮费',$product->getData('pay_postage'))->min(0);
|
||||
Form::number('gain_integral','赠送积分',$product->getData('gain_integral'))->min(0);
|
||||
return Form::builder();
|
||||
}
|
||||
public function update($id)
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'order_id',
|
||||
'total_price',
|
||||
'total_postage',
|
||||
'pay_price',
|
||||
'pay_postage',
|
||||
'gain_integral',
|
||||
]);
|
||||
if($data['total_price'] <= 0) return Json::fail('请输入商品总价');
|
||||
if($data['pay_price'] <= 0) return Json::fail('请输入实际支付金额');
|
||||
$data['order_id'] = StoreOrderModel::changeOrderId($data['order_id']);
|
||||
StoreOrderModel::edit($data,$id);
|
||||
event('StoreProductOrderEditAfter',[$data,$id]);
|
||||
StoreOrderStatus::setStatus($id,'order_edit','修改商品总价为:'.$data['total_price'].' 实际支付金额'.$data['pay_price']);
|
||||
return Json::successful('修改成功!');
|
||||
}
|
||||
/**
|
||||
* 送货
|
||||
* @param $id
|
||||
* send
|
||||
*/
|
||||
public function delivery($id){
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = StoreOrderModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
if($product['paid'] == 1 && $product['status'] == 0) {
|
||||
$this->assign([
|
||||
'title' => '送货信息', 'rules' => $this->readDelivery($id)->getContent(),
|
||||
'action' => Url::buildUrl('updateDelivery', array('id' => $id))
|
||||
]);
|
||||
return $this->fetch('public/common_form');
|
||||
}
|
||||
else return Json::fail('数据不存在!');
|
||||
}
|
||||
public function readDelivery($id){
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = StoreOrderModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
Form::text('delivery_name','送货人姓名');
|
||||
Form::text('delivery_id','送货人电话')->number();
|
||||
return Form::builder();
|
||||
}
|
||||
public function updateDelivery($id){
|
||||
$data = Util::postMore([
|
||||
'delivery_name',
|
||||
'delivery_id',
|
||||
]);
|
||||
$data['delivery_type'] = 'send';
|
||||
if(!$data['delivery_name']) return Json::fail('请输入送货人姓名');
|
||||
if(!(int)$data['delivery_id']) return Json::fail('请输入送货人电话号码');
|
||||
else if(!preg_match("/^1[3456789]{1}\d{9}$/",$data['delivery_id'])) return Json::fail('请输入正确的送货人电话号码');
|
||||
$data['status'] = 1;
|
||||
StoreOrderModel::edit($data,$id);
|
||||
event('storeProductOrderDeliveryAfter',[$data,$id]);
|
||||
StoreOrderStatus::setStatus($id,'delivery','已配送 发货人:'.$data['delivery_name'].' 发货人电话:'.$data['delivery_id']);
|
||||
return Json::successful('修改成功!');
|
||||
}
|
||||
/**
|
||||
* 发货
|
||||
* @param $id
|
||||
* express
|
||||
*/
|
||||
public function deliver_goods($id){
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = StoreOrderModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
if($product['paid'] == 1 && $product['status'] == 0){
|
||||
$this->assign([
|
||||
'title'=>'发货信息','rules'=>$this->readDeliveryGoods($id)->getContent(),
|
||||
'action'=>Url::buildUrl('updateDeliveryGoods',array('id'=>$id))
|
||||
]);
|
||||
return $this->fetch('public/common_form');
|
||||
}
|
||||
else return Json::fail('数据不存在!');
|
||||
}
|
||||
public function readDeliveryGoods($id){
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = StoreOrderModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
Form::select('delivery_name','快递公司',function(){
|
||||
$list = Db::name('express')->where('is_show',1)->order('sort DESC')->column('name','id');
|
||||
$menus = [];
|
||||
foreach ($list as $k=>$v){
|
||||
$menus[] = ['value'=>$v,'label'=>$v];
|
||||
}
|
||||
return $menus;
|
||||
})->filterable();
|
||||
Form::text('delivery_id','快递单号');
|
||||
return Form::builder();
|
||||
}
|
||||
public function updateDeliveryGoods($id){
|
||||
$data = Util::postMore([
|
||||
'delivery_name',
|
||||
'delivery_id',
|
||||
]);
|
||||
$data['delivery_type'] = 'express';
|
||||
if(!$data['delivery_name']) return Json::fail('请选择快递公司');
|
||||
if(!$data['delivery_id']) return Json::fail('请输入快递单号');
|
||||
$data['status'] = 1;
|
||||
StoreOrderModel::edit($data,$id);
|
||||
event('StoreProductOrderDeliveryGoodsAfter',[$data,$id]);
|
||||
StoreOrderStatus::setStatus($id,'delivery_goods','已发货 快递公司:'.$data['delivery_name'].' 快递单号:'.$data['delivery_id']);
|
||||
return Json::successful('修改成功!');
|
||||
}
|
||||
/**
|
||||
* 修改状态为已收货
|
||||
* @param $id
|
||||
* @return \think\response\Json|void
|
||||
*/
|
||||
public function take_delivery($id){
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = StoreOrderModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
if($product['status'] == 2) return Json::fail('不能重复收货!');
|
||||
if($product['paid'] == 1 && $product['status'] == 1) $data['status'] = 2;
|
||||
else if($product['pay_type'] == 'offline') $data['status'] = 2;
|
||||
else return Json::fail('请先发货或者送货!');
|
||||
if(!StoreOrderModel::edit($data,$id))
|
||||
return Json::fail(StoreOrderModel::getErrorInfo('收货失败,请稍候再试!'));
|
||||
else{
|
||||
try{
|
||||
OrderRepository::storeProductOrderTakeDeliveryAdmin($data, $id);
|
||||
}catch (\Exception $e){
|
||||
return Json::fail($e->getMessage());
|
||||
}
|
||||
StoreOrderStatus::setStatus($id,'take_delivery','已收货');
|
||||
return Json::successful('收货成功!');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 修改退款状态
|
||||
* @param $id
|
||||
* @return \think\response\Json|void
|
||||
*/
|
||||
public function refund_y($id){
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = StoreOrderModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
if($product['paid'] == 1){
|
||||
$this->assign([
|
||||
'title'=>'退款','rules'=>$this->readRefundY($id)->getContent(),
|
||||
'action'=>Url::buildUrl('updateRefundY',array('id'=>$id))
|
||||
]);
|
||||
return $this->fetch('public/common_form');
|
||||
}
|
||||
else return Json::fail('数据不存在!');
|
||||
}
|
||||
public function readRefundY($id){
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = StoreOrderModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
Form::text('order_id','退款单号',$product->getData('order_id'))->readonly();
|
||||
Form::number('refund_price','退款金额',$product->getData('pay_price'))->min(0);
|
||||
Form::radio('type','状态',[['label'=>'直接退款','value'=>1],['label'=>'退款后,返回原状态','value'=>2]],1);
|
||||
return Form::builder();
|
||||
}
|
||||
public function updateRefundY($id){
|
||||
$data = Util::postMore([
|
||||
'refund_price',
|
||||
['type',1],
|
||||
]);
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = StoreOrderModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
if($product['pay_price'] == $product['refund_price']) return Json::fail('已退完支付金额!不能再退款了');
|
||||
if(!$data['refund_price']) return Json::fail('请输入退款金额');
|
||||
$refund_price = $data['refund_price'];
|
||||
$data['refund_price'] = bcadd($data['refund_price'],$product['refund_price'],2);
|
||||
$bj = bccomp((float)$product['pay_price'],(float)$data['refund_price'],2);
|
||||
if($bj < 0) return Json::fail('退款金额大于支付金额,请修改退款金额');
|
||||
if($data['type'] == 1){
|
||||
$data['refund_status'] = 2;
|
||||
}else if($data['type'] == 2){
|
||||
$data['refund_status'] = 0;
|
||||
}
|
||||
$type = $data['type'];
|
||||
unset($data['type']);
|
||||
$refund_data['pay_price'] = $product['pay_price'];
|
||||
$refund_data['refund_price'] = $refund_price;
|
||||
if($product['pay_type'] == 'weixin'){
|
||||
if($product['is_channel']){//TODO 小程序
|
||||
try{
|
||||
MiniProgramService::payOrderRefund($product['order_id'],$refund_data);//2.5.36
|
||||
}catch(\Exception $e){
|
||||
return Json::fail($e->getMessage());
|
||||
}
|
||||
}else{ //TODO 公众号
|
||||
try{
|
||||
WechatService::payOrderRefund($product['order_id'],$refund_data);
|
||||
}catch(\Exception $e){
|
||||
return Json::fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}else if($product['pay_type'] == 'yue'){
|
||||
BaseModel::beginTrans();
|
||||
$usermoney = User::where('uid',$product['uid'])->value('now_money');
|
||||
$res1 = User::bcInc($product['uid'],'now_money',$refund_price,'uid');
|
||||
$res2 = $res2 = UserBill::income('商品退款',$product['uid'],'now_money','pay_product_refund',$refund_price,$product['id'],bcadd($usermoney,$refund_price,2),'订单退款到余额'.floatval($refund_price).'元');
|
||||
try{
|
||||
OrderRepository::storeOrderYueRefund($product, $refund_data);
|
||||
}catch (\Exception $e){
|
||||
BaseModel::rollbackTrans();
|
||||
return Json::fail($e->getMessage());
|
||||
}
|
||||
$res = $res1 && $res2;
|
||||
BaseModel::checkTrans($res);
|
||||
if(!$res) return Json::fail('余额退款失败!');
|
||||
}
|
||||
$resEdit = StoreOrderModel::edit($data,$id);
|
||||
if($resEdit){
|
||||
$data['type'] = $type;
|
||||
if($data['type'] == 1) StorePink::setRefundPink($id);
|
||||
try{
|
||||
OrderRepository::storeProductOrderRefundY($data, $id);
|
||||
}catch (\Exception $e){
|
||||
return Json::fail($e->getMessage());
|
||||
}
|
||||
StoreOrderStatus::setStatus($id,'refund_price','退款给用户'.$refund_price.'元');
|
||||
return Json::successful('修改成功!');
|
||||
}else{
|
||||
StoreOrderStatus::setStatus($id,'refund_price','退款给用户'.$refund_price.'元失败');
|
||||
return Json::fail('修改失败!');
|
||||
}
|
||||
}
|
||||
public function order_info($oid = '')
|
||||
{
|
||||
if(!$oid || !($orderInfo = StoreOrderModel::get($oid)))
|
||||
return $this->failed('订单不存在!');
|
||||
$userInfo = User::getUserInfo($orderInfo['uid']);
|
||||
if($userInfo['spread_uid']){
|
||||
$spread = User::where('uid',$userInfo['spread_uid'])->value('nickname');
|
||||
}else{
|
||||
$spread ='';
|
||||
}
|
||||
$this->assign(compact('orderInfo','userInfo','spread'));
|
||||
return $this->fetch();
|
||||
}
|
||||
public function express($oid = '')
|
||||
{
|
||||
if(!$oid || !($order = StoreOrderModel::get($oid)))
|
||||
return $this->failed('订单不存在!');
|
||||
if($order['delivery_type'] != 'express' || !$order['delivery_id']) return $this->failed('该订单不存在快递单号!');
|
||||
$cacheName = $order['order_id'].$order['delivery_id'];
|
||||
$result = CacheService::get($cacheName,null);
|
||||
if($result === null){
|
||||
$result = ExpressService::query($order['delivery_id']);
|
||||
if(is_array($result) &&
|
||||
isset($result['result']) &&
|
||||
isset($result['result']['deliverystatus']) &&
|
||||
$result['result']['deliverystatus'] >= 3)
|
||||
$cacheTime = 0;
|
||||
else
|
||||
$cacheTime = 1800;
|
||||
CacheService::set($cacheName,$result,$cacheTime);
|
||||
}
|
||||
$this->assign([
|
||||
'order'=>$order,
|
||||
'express'=>$result
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
/**
|
||||
* 修改配送信息
|
||||
* @param $id
|
||||
* @return mixed|\think\response\Json|void
|
||||
*/
|
||||
public function distribution($id){
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = StoreOrderModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
$this->assign([
|
||||
'title'=>'配送信息','rules'=>$this->readDistribution($id)->getContent(),
|
||||
'action'=>Url::buildUrl('updateDistribution',array('id'=>$id))
|
||||
]);
|
||||
return $this->fetch('public/common_form');
|
||||
}
|
||||
public function readDistribution($id){
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = StoreOrderModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
if($product['delivery_type'] == 'send'){
|
||||
Form::text('delivery_name','送货人姓名',$product->getData('delivery_name'));
|
||||
Form::text('delivery_id','送货人电话',$product->getData('delivery_id'))->number();
|
||||
}else if($product['delivery_type'] == 'express'){
|
||||
Form::select('delivery_name','快递公司',function(){
|
||||
$list = Db::name('express')->where('is_show',1)->column('name','id');
|
||||
$menus = [];
|
||||
foreach ($list as $k=>$v){
|
||||
$menus[] = ['value'=>$v,'label'=>$v];
|
||||
}
|
||||
return $menus;
|
||||
},$product->getData('delivery_name'))->filterable();
|
||||
Form::text('delivery_id','快递单号',$product->getData('delivery_id'));
|
||||
}
|
||||
return Form::builder();
|
||||
}
|
||||
public function updateDistribution($id){
|
||||
$data = Util::postMore([
|
||||
'delivery_name',
|
||||
'delivery_id',
|
||||
]);
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = StoreOrderModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
if($product['delivery_type'] == 'send'){
|
||||
if(!$data['delivery_name']) return Json::fail('请输入送货人姓名');
|
||||
if(!(int)$data['delivery_id']) return Json::fail('请输入送货人电话号码');
|
||||
else if(!preg_match("/^1[3456789]{1}\d{9}$/",$data['delivery_id'])) return Json::fail('请输入正确的送货人电话号码');
|
||||
}else if($product['delivery_type'] == 'express'){
|
||||
if(!$data['delivery_name']) return Json::fail('请选择快递公司');
|
||||
if(!$data['delivery_id']) return Json::fail('请输入快递单号');
|
||||
}
|
||||
StoreOrderModel::edit($data,$id);
|
||||
event('StoreProductOrderDistributionAfter',[$data,$id]);
|
||||
StoreOrderStatus::setStatus($id,'distribution','修改发货信息为'.$data['delivery_name'].'号'.$data['delivery_id']);
|
||||
return Json::successful('修改成功!');
|
||||
}
|
||||
/**
|
||||
* 修改退款状态
|
||||
* @param $id
|
||||
* @return mixed|\think\response\Json|void
|
||||
*/
|
||||
public function refund_n($id){
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = StoreOrderModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
$this->assign([
|
||||
'title'=>'退款','rules'=>$this->readRefundN($id)->getContent(),
|
||||
'action'=>Url::buildUrl('updateRefundN',array('id'=>$id))
|
||||
]);
|
||||
return $this->fetch('public/common_form');
|
||||
}
|
||||
public function readRefundN($id){
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = StoreOrderModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
Form::text('order_id','退款单号',$product->getData('order_id'))->readonly();
|
||||
Form::textarea('refund_reason','退款原因');
|
||||
return Form::builder();
|
||||
}
|
||||
public function updateRefundN($id){
|
||||
$data = Util::postMore([
|
||||
'refund_reason',
|
||||
]);
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = StoreOrderModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
if(!$data['refund_reason']) return Json::fail('请输入退款原因');
|
||||
$data['refund_status'] = 0;
|
||||
StoreOrderModel::edit($data,$id);
|
||||
event('StoreProductOrderRefundNAfter',[$data['refund_reason'],$id]);
|
||||
StoreOrderStatus::setStatus($id,'refund_n','不退款原因:'.$data['refund_reason']);
|
||||
return Json::successful('修改成功!');
|
||||
}
|
||||
/**
|
||||
* 立即支付
|
||||
* @param $id
|
||||
*/
|
||||
public function offline($id){
|
||||
$res = StoreOrderModel::updateOffline($id);
|
||||
if($res){
|
||||
event('StoreProductOrderOffline',[$id]);
|
||||
StoreOrderStatus::setStatus($id,'offline','线下付款');
|
||||
return Json::successful('修改成功!');
|
||||
}else{
|
||||
return Json::fail(StoreOrderModel::getErrorInfo('修改失败!'));
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 修改积分和金额
|
||||
* @param $id
|
||||
* @return mixed|\think\response\Json|void
|
||||
*/
|
||||
public function integral_back($id){
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = StoreOrderModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
if($product['paid'] == 1){
|
||||
$this->assign([
|
||||
'title'=>'退积分','rules'=>$this->readIntegralBack($id)->getContent(),
|
||||
'action'=>Url::buildUrl('updateIntegralBack',array('id'=>$id))
|
||||
]);
|
||||
}else{
|
||||
return Json::fail('参数错误!');
|
||||
}
|
||||
return $this->fetch('public/common_form');
|
||||
}
|
||||
public function readIntegralBack($id){
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = StoreOrderModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
Form::text('order_id','退积分单号',$product->getData('order_id'))->readonly();
|
||||
Form::number('back_integral','退积分')->min(0);
|
||||
return Form::builder();
|
||||
}
|
||||
public function updateIntegralBack($id){
|
||||
$data = Util::postMore([
|
||||
'back_integral',
|
||||
]);
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = StoreOrderModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
if($data['back_integral'] <= 0) return Json::fail('请输入积分');
|
||||
if($product['use_integral'] == $product['back_integral']) return Json::fail('已退完积分!不能再积分了');
|
||||
$back_integral = $data['back_integral'];
|
||||
$data['back_integral'] = bcadd($data['back_integral'],$product['back_integral'],2);
|
||||
$bj = bccomp((float)$product['use_integral'],(float)$data['back_integral'],2);
|
||||
if($bj < 0) return Json::fail('退积分大于支付积分,请修改退积分');
|
||||
BaseModel::beginTrans();
|
||||
$integral = User::where('uid',product['uid'])->value('integral');
|
||||
$res1 = User::bcInc($product['uid'],'integral',$back_integral,'uid');
|
||||
$res2 = UserBill::income('商品退积分',$product['uid'],'integral','pay_product_integral_back',$back_integral,$product['id'],bcadd($integral,$back_integral,2),'订单退积分'.floatval($back_integral).'积分到用户积分');
|
||||
try{
|
||||
OrderRepository::storeOrderIntegralBack($product,$back_integral);
|
||||
}catch (\Exception $e){
|
||||
BaseModel::rollbackTrans();
|
||||
return Json::fail($e->getMessage());
|
||||
}
|
||||
$res = $res1 && $res2;
|
||||
BaseModel::checkTrans($res);
|
||||
if(!$res) return Json::fail('退积分失败!');
|
||||
StoreOrderModel::edit($data,$id);
|
||||
StoreOrderStatus::setStatus($id,'integral_back','商品退积分:'.$data['back_integral']);
|
||||
return Json::successful('退积分成功!');
|
||||
}
|
||||
public function remark(){
|
||||
$data = Util::postMore(['id','remark']);
|
||||
if(!$data['id']) return Json::fail('参数错误!');
|
||||
if($data['remark'] == '') return Json::fail('请输入要备注的内容!');
|
||||
$id = $data['id'];
|
||||
unset($data['id']);
|
||||
StoreOrderModel::edit($data,$id);
|
||||
return Json::successful('备注成功!');
|
||||
}
|
||||
public function order_status($oid){
|
||||
if(!$oid) return $this->failed('数据不存在');
|
||||
$this->assign(StoreOrderStatus::systemPage($oid));
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
604
app/admin/controller/record/Record.php
Normal file
604
app/admin/controller/record/Record.php
Normal file
@ -0,0 +1,604 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: xurongyao <763569752@qq.com>
|
||||
* Date: 2018/6/14 下午5:25
|
||||
*/
|
||||
|
||||
namespace app\admin\controller\record;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use app\admin\model\store\StoreProduct;
|
||||
use app\admin\model\order\StoreOrder;
|
||||
use app\admin\model\ump\StoreBargain;
|
||||
use app\admin\model\ump\StoreSeckill;
|
||||
use app\admin\model\ump\StoreCombination;
|
||||
use crmeb\services\JsonService;
|
||||
use crmeb\services\UtilService as Util;
|
||||
use app\admin\model\user\User;
|
||||
use app\admin\model\user\UserBill;
|
||||
use app\admin\model\user\UserExtract;
|
||||
use app\admin\model\store\StoreCouponUser;
|
||||
/**
|
||||
* 微信充值记录
|
||||
* Class UserRecharge
|
||||
* @package app\admin\controller\user
|
||||
*/
|
||||
class Record extends AuthController
|
||||
|
||||
{
|
||||
|
||||
/**
|
||||
* 显示操作记录
|
||||
*/
|
||||
public function index(){
|
||||
|
||||
|
||||
}
|
||||
/**
|
||||
* 显示订单记录
|
||||
*/
|
||||
public function chart_order(){
|
||||
$this->assign([
|
||||
'is_layui'=>true,
|
||||
'year'=>getMonth()
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
public function get_echarts_order(){
|
||||
$where=Util::getMore([
|
||||
['type',''],
|
||||
['status',''],
|
||||
['data',''],
|
||||
]);
|
||||
return JsonService::successful(StoreOrder::getEchartsOrder($where));
|
||||
}
|
||||
/**
|
||||
* 显示产品记录
|
||||
*/
|
||||
public function chart_product(){
|
||||
$this->assign([
|
||||
'is_layui'=>true,
|
||||
'year'=>getMonth()
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
/**
|
||||
* 获取产品曲线图数据
|
||||
*/
|
||||
public function get_echarts_product($type='',$data=''){
|
||||
return JsonService::successful(StoreProduct::getChatrdata($type,$data));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取销量
|
||||
*/
|
||||
public function get_echarts_maxlist($data=''){
|
||||
return JsonService::successful(StoreProduct::getMaxList(compact('data')));
|
||||
}
|
||||
/**
|
||||
* 获取利润
|
||||
*/
|
||||
public function get_echarts_profity($data=''){
|
||||
return JsonService::successful(StoreProduct::ProfityTop10(compact('data')));
|
||||
}
|
||||
/**
|
||||
* 获取缺货列表
|
||||
*/
|
||||
public function getLackList(){
|
||||
$where=Util::getMore([
|
||||
['page',1],
|
||||
['limit',20],
|
||||
]);
|
||||
return JsonService::successlayui(StoreProduct::getLackList($where));
|
||||
}
|
||||
/**
|
||||
* 表单快速修改
|
||||
*/
|
||||
public function editField($id=''){
|
||||
$post=$this->request->post();
|
||||
StoreProduct::beginTrans();
|
||||
try{
|
||||
StoreProduct::edit($post,$id);
|
||||
StoreProduct::commitTrans();
|
||||
return JsonService::successful('修改成功');
|
||||
}catch (\Exception $e){
|
||||
StoreProduct::rollbackTrans();
|
||||
return JsonService::fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
//获取差评
|
||||
public function getnegativelist(){
|
||||
$where=Util::getMore([
|
||||
['page',1],
|
||||
['limit',10],
|
||||
]);
|
||||
return JsonService::successful(StoreProduct::getnegativelist($where));
|
||||
}
|
||||
/**
|
||||
* 获取退货
|
||||
*/
|
||||
public function getTuiPriesList(){
|
||||
return JsonService::successful(StoreProduct::TuiProductList());
|
||||
}
|
||||
//营销统计
|
||||
/**
|
||||
* 显示积分统计
|
||||
*/
|
||||
public function chart_score(){
|
||||
$this->assign([
|
||||
'is_layui'=>true,
|
||||
'year'=>getMonth()
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
/**
|
||||
* 获取积分头部信息
|
||||
*/
|
||||
public function getScoreBadgeList($data=''){
|
||||
return JsonService::successful(UserBill::getScoreBadgeList(compact('data')));
|
||||
}
|
||||
/**
|
||||
* 获取积分曲线图和柱状图
|
||||
*/
|
||||
public function getScoreCurve($data='',$limit=20){
|
||||
return JsonService::successful(UserBill::getScoreCurve(compact('data','limit')));
|
||||
}
|
||||
/**
|
||||
* 显示优惠券统计
|
||||
*/
|
||||
public function chart_coupon(){
|
||||
$this->assign([
|
||||
'is_layui'=>true,
|
||||
'year'=>getMonth()
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
/**
|
||||
* 获取优惠劵头部信息
|
||||
*/
|
||||
public function getCouponBadgeList($data=''){
|
||||
return JsonService::successful(StoreCouponUser::getCouponBadgeList(compact('data')));
|
||||
}
|
||||
/**
|
||||
* 获取优惠劵数据图表
|
||||
*/
|
||||
public function getConponCurve($data=''){
|
||||
return JsonService::successful(StoreCouponUser::getConponCurve(compact('data')));
|
||||
}
|
||||
/**
|
||||
* 显示拼团统计
|
||||
*/
|
||||
public function chart_combination(){
|
||||
$this->assign([
|
||||
'is_layui'=>true,
|
||||
'year'=>getMonth()
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
/**
|
||||
* 显示砍价统计
|
||||
*/
|
||||
public function chart_bargain(){
|
||||
$this->assign([
|
||||
'is_layui'=>true,
|
||||
'year'=>getMonth()
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
/**
|
||||
* 显示秒杀统计
|
||||
*/
|
||||
public function chart_seckill(){
|
||||
$this->assign([
|
||||
'is_layui'=>true,
|
||||
'year'=>getMonth()
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
//财务统计
|
||||
/**
|
||||
* 显示反佣统计
|
||||
*/
|
||||
public function chart_rebate(){
|
||||
$this->assign([
|
||||
'is_layui'=>true,
|
||||
'year'=>getMonth()
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
//获取用户返佣柱状图
|
||||
public function getUserBillBrokerage($data=''){
|
||||
return JsonService::successful(UserBill::getUserBillChart(compact('data')));
|
||||
}
|
||||
//获取用户返佣头部信息
|
||||
public function getRebateBadge($data=''){
|
||||
return JsonService::successful(UserBill::getRebateBadge(compact('data')));
|
||||
}
|
||||
//获得 返佣列表,带分页
|
||||
public function getFanList($page=1,$limit=20){
|
||||
return JsonService::successful(UserBill::getFanList(compact('page','limit')));
|
||||
}
|
||||
//获得 返佣总次数
|
||||
public function getFanCount(){
|
||||
return JsonService::successful(UserBill::getFanCount());
|
||||
}
|
||||
/**
|
||||
* 显示充值统计
|
||||
*/
|
||||
public function chart_recharge(){
|
||||
$this->assign([
|
||||
'is_layui'=>true,
|
||||
'year'=>getMonth()
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
/**
|
||||
* 获取用户充值柱状图和曲线图
|
||||
*/
|
||||
public function getEchartsRecharge($data=''){
|
||||
return JsonService::successful(UserBill::getEchartsRecharge(compact('data')));
|
||||
}
|
||||
/**
|
||||
* 显示提现统计
|
||||
*/
|
||||
public function chart_cash(){
|
||||
$this->assign([
|
||||
'is_layui'=>true,
|
||||
'year'=>getMonth()
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
//获取提现头部信息
|
||||
public function getExtractHead($data=''){
|
||||
return JsonService::successful(UserExtract::getExtractHead(compact('data')));
|
||||
}
|
||||
//会员统计
|
||||
/**
|
||||
* 显示用户统计
|
||||
*/
|
||||
public function user_chart(){
|
||||
$this->assign([
|
||||
'is_layui'=>true,
|
||||
'year'=>getMonth()
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
/**
|
||||
* 获取头部信息
|
||||
*
|
||||
* 人数 增长 分销人数 分销增长
|
||||
*/
|
||||
public function getBadgeList($data='',$is_promoter='',$status=''){
|
||||
return JsonService::successful(User::getBadgeList(compact('data','is_promoter','status')));
|
||||
}
|
||||
/*
|
||||
* 获取用户增长曲线图
|
||||
*
|
||||
*/
|
||||
public function getUserChartList($data='',$is_promoter='',$status=''){
|
||||
return JsonService::successful(User::getUserChartList(compact('data','is_promoter','status')));
|
||||
}
|
||||
/*
|
||||
* 获取提现分布图和提现人数金额曲线图
|
||||
*
|
||||
*/
|
||||
public function getExtractData($data=''){
|
||||
return JsonService::successful(UserExtract::getExtractList(compact('data')));
|
||||
}
|
||||
/*
|
||||
* 分销会员统计
|
||||
*
|
||||
*/
|
||||
public function user_distribution_chart(){
|
||||
$limit=10;
|
||||
$top10list=User::getUserDistributionTop10List($limit);
|
||||
$this->assign([
|
||||
'is_layui'=>true,
|
||||
'limit'=>$limit,
|
||||
'year'=>getMonth(),
|
||||
'commissionList'=>$top10list['commission'],
|
||||
'extractList'=>$top10list['extract'],
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
/*
|
||||
* 获取分销会员统计会员头部详情
|
||||
*
|
||||
*/
|
||||
public function getDistributionBadgeList($data=''){
|
||||
return JsonService::successful(User::getDistributionBadgeList(compact('data')));
|
||||
}
|
||||
/*
|
||||
* 获取分销会员统计图表数据
|
||||
*
|
||||
* $data 时间范围
|
||||
*
|
||||
*/
|
||||
public function getUserDistributionChart($data=''){
|
||||
return JsonService::successful(User::getUserDistributionChart(compact('data')));
|
||||
}
|
||||
/**
|
||||
* 会员业务
|
||||
*/
|
||||
public function user_business_chart(){
|
||||
$limit=10;
|
||||
$top10list=User::getUserTop10List($limit);
|
||||
$this->assign([
|
||||
'is_layui'=>true,
|
||||
'limit'=>$limit,
|
||||
'year'=>getMonth(),
|
||||
'integralList'=>$top10list['integral'],
|
||||
'moneyList'=>$top10list['now_money'],
|
||||
'shopcountList'=>$top10list['shopcount'],
|
||||
'orderList'=>$top10list['order'],
|
||||
'lastorderList'=>$top10list['lastorder']
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
/*
|
||||
* 获取 会员业务的
|
||||
* 购物会员统计
|
||||
* 分销商业务人数和提现人数统计
|
||||
* 分销商业务佣金和提现金额统计
|
||||
* 曲线图
|
||||
* $data 时间
|
||||
*/
|
||||
public function getUserBusinessChart($data=''){
|
||||
return JsonService::successful(User::getUserBusinessChart(compact('data')));
|
||||
}
|
||||
/*
|
||||
* 获取 会员业务
|
||||
* 会员总余额 分销商总佣金 分销商总佣金余额 分销商总提现佣金 本月分销商业务佣金 本月分销商佣金提现金额
|
||||
* 上月分销商业务佣金 上月分销商佣金提现金额
|
||||
* $where 查询条件
|
||||
*
|
||||
* return array
|
||||
*/
|
||||
public function getUserBusinesHeade($data){
|
||||
return JsonService::successful(User::getUserBusinesHeade(compact('data')));
|
||||
}
|
||||
/**
|
||||
* 显示用户属性统计
|
||||
*/
|
||||
public function user_attr(){
|
||||
$this->assign([
|
||||
'is_layui'=>true,
|
||||
'year'=>getMonth()
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
/**
|
||||
* 获取用户属性统计
|
||||
*/
|
||||
public function getEchartsData($data=''){
|
||||
return JsonService::successful(User::getEchartsData(compact('data')));
|
||||
}
|
||||
//排行榜
|
||||
/**
|
||||
* 显示产品排行榜
|
||||
*/
|
||||
public function ranking_saleslists(){
|
||||
$this->assign([
|
||||
'is_layui'=>true,
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
/*
|
||||
*获取产品排行 带分页
|
||||
*/
|
||||
public function getSaleslists($start_time='',$end_time='',$title='',$page=1,$limit=20){
|
||||
return JsonService::successlayui(StoreProduct::getSaleslists(compact('start_time','end_time','title','page','limit')));
|
||||
}
|
||||
/*
|
||||
*生成表格,并下载
|
||||
*/
|
||||
public function save_product_export($start_time='',$end_time='',$title=''){
|
||||
return JsonService::successlayui(StoreProduct::SaveProductExport(compact('start_time','end_time','title')));
|
||||
}
|
||||
/*
|
||||
*获取单个商品的详情
|
||||
*/
|
||||
public function product_info($id=''){
|
||||
if($id=='') $this->failed('缺少商品id');
|
||||
if(!StoreProduct::be(['id'=>$id])) return $this->failed('商品不存在!');
|
||||
$this->assign([
|
||||
'is_layui'=>true,
|
||||
'year'=>getMonth(),
|
||||
'id'=>$id,
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
/*
|
||||
*获取单个商品的详情头部信息
|
||||
*/
|
||||
public function getProductBadgeList($id='',$data=''){
|
||||
return JsonService::successful(StoreProduct::getProductBadgeList($id,$data));
|
||||
}
|
||||
/*
|
||||
*获取单个商品的销售曲线图
|
||||
*/
|
||||
public function getProductCurve($id='',$data='',$limit=20){
|
||||
return JsonService::successful(StoreProduct::getProductCurve(compact('id','data','limit')));
|
||||
}
|
||||
/*
|
||||
*获取单个商品的销售总条数
|
||||
*/
|
||||
public function getProductCount($id,$data=''){
|
||||
return JsonService::successful(StoreProduct::setWhere(compact('data'))
|
||||
->where('a.product_id',$id)
|
||||
->join('user c','c.uid=a.uid')
|
||||
->where('a.is_pay',1)
|
||||
->count());
|
||||
}
|
||||
/*
|
||||
*获取单个商品的销售列表
|
||||
*/
|
||||
public function getSalelList($data='',$id=0,$page=1,$limit=20){
|
||||
return JsonService::successful(StoreProduct::getSalelList(compact('data','id','page','limit')));
|
||||
}
|
||||
/**
|
||||
* 显示反佣排行榜
|
||||
*/
|
||||
public function ranking_commission(){
|
||||
$this->assign([
|
||||
'is_layui'=>true,
|
||||
'year'=>getMonth()
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
public function getcommissionlist($page=1,$limit=20){
|
||||
return JsonService::successful(UserExtract::where('status',1)
|
||||
->field(['real_name','extract_price','balance'])
|
||||
->order('extract_price desc')
|
||||
->page($page,$limit)
|
||||
->select());
|
||||
}
|
||||
public function getmonthcommissionlist($page=1,$limit=20){
|
||||
return JsonService::successful(UserExtract::where('status',1)
|
||||
->whereTime('add_time','month')
|
||||
->field(['real_name','extract_price','balance'])
|
||||
->order('extract_price desc')
|
||||
->page($page,$limit)
|
||||
->select());
|
||||
}
|
||||
//获取佣金返现总条数
|
||||
public function getCommissonCount(){
|
||||
return JsonService::successful(UserExtract::where('status',1)->count());
|
||||
}
|
||||
//获取本月佣金返现条数
|
||||
public function getMonthCommissonCount(){
|
||||
return JsonService::successful(UserExtract::where('status',1)->whereTime('add_time','month')->count());
|
||||
}
|
||||
/**
|
||||
* 显示积分排行榜
|
||||
*/
|
||||
public function ranking_point(){
|
||||
$this->assign([
|
||||
'is_layui'=>true,
|
||||
'year'=>getMonth()
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
//获取所有积分排行总人数
|
||||
public function getPountCount(){
|
||||
return JsonService::successful(User::where('status', 1)->where('integral','<>',0)->count());
|
||||
}
|
||||
//获取积分排行列表
|
||||
public function getpointList($page=1,$limit=20){
|
||||
return JsonService::successful(($list=User::where('status', 1)
|
||||
->where('integral','<>',0)
|
||||
->field('nickname,integral')
|
||||
->order('integral desc')
|
||||
->page($page,$limit)
|
||||
->select()) && count($list) ? $list->toArray():[]);
|
||||
}
|
||||
//获取本月积分排行别表
|
||||
public function getMonthpountList($page=1,$limit=20){
|
||||
return JsonService::successful(($list=User::where('status',1)
|
||||
->where('integral','<>',0)
|
||||
->whereTime('add_time','month')
|
||||
->order('integral desc')
|
||||
->field('nickname,integral')
|
||||
->page($page,$limit)
|
||||
->select()) && count($list) ? $list->toArray():[]);
|
||||
}
|
||||
public function getMonthPountCount(){
|
||||
return JsonService::successful(User::where('status',1)->where('integral','<>',0)->whereTime('add_time','month')->count());
|
||||
}
|
||||
/**
|
||||
*
|
||||
* 显示下级会员排行榜
|
||||
*/
|
||||
public function ranking_lower(){
|
||||
echo " 复购率 复购增长率 活跃度 活跃率 分销总金额 增长率 消费会员 非消费会员 消费排行榜 积分排行榜 余额排行榜 分销总金额排行榜 分销人数排行榜 分销余额排行榜 购物金额排行榜 购物次数排行榜 提现排行榜 ";
|
||||
}
|
||||
/**
|
||||
* 获取砍价产品曲线图数据
|
||||
*/
|
||||
public function get_mark_echarts_product($type='',$data='',$model = 0){
|
||||
if(!$model) return JsonService::successful(StoreBargain::getChatrdata($type,$data));
|
||||
if($model) return JsonService::successful(StoreSeckill::getChatrdata($type,$data));
|
||||
}
|
||||
/**
|
||||
* 获取拼团产品曲线图数据
|
||||
*/
|
||||
public function get_combination_echarts_product($type='',$data=''){
|
||||
return JsonService::successful(StoreCombination::getChatrdata($type,$data));
|
||||
}
|
||||
/*
|
||||
* 获取拼团销量
|
||||
*/
|
||||
public function get_combination_maxlist($data=''){
|
||||
return JsonService::successful(StoreCombination::getMaxList(compact('data')));
|
||||
}
|
||||
/*
|
||||
* 拼团盈利
|
||||
*/
|
||||
public function get_combination_profity($data=''){
|
||||
return JsonService::successful(StoreCombination::ProfityTop10(compact('data')));
|
||||
}
|
||||
/*
|
||||
* 拼团退货
|
||||
*/
|
||||
public function get_combination_refund_list(){
|
||||
$where = Util::getMore([
|
||||
['page',1],
|
||||
['limit',20],
|
||||
]);
|
||||
return JsonService::successlayui(StoreCombination::getBargainRefundList($where));
|
||||
}
|
||||
/**
|
||||
* 获取销量
|
||||
*/
|
||||
public function get_mark_echarts_maxlist($data='',$model = 0){
|
||||
if(!$model) return JsonService::successful(StoreBargain::getMaxList(compact('data')));
|
||||
if($model) return JsonService::successful(StoreSeckill::getMaxList(compact('data')));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取利润
|
||||
*/
|
||||
public function get_mark_echarts_profity($data='',$model = 0){
|
||||
if(!$model) return JsonService::successful(StoreBargain::ProfityTop10(compact('data')));
|
||||
if($model) return JsonService::successful(StoreSeckill::ProfityTop10(compact('data')));
|
||||
}
|
||||
/**
|
||||
* 获取补货的砍价产品
|
||||
*/
|
||||
public function get_mark_lack_list($model = 0){
|
||||
$where = Util::getMore([
|
||||
['page',1],
|
||||
['limit',20],
|
||||
]);
|
||||
if(!$model) return JsonService::successlayui(StoreBargain::getLackList($where));
|
||||
if($model) return JsonService::successlayui(StoreSeckill::getLackList($where));
|
||||
}
|
||||
/**
|
||||
* 获取砍价产品的评论
|
||||
*/
|
||||
public function get_mark_negative_list($model = 0){
|
||||
$where = Util::getMore([
|
||||
['page',1],
|
||||
['limit',20],
|
||||
]);
|
||||
if(!$model) return JsonService::successlayui(StoreBargain::getNegativeList($where));
|
||||
if($model) return JsonService::successlayui(StoreSeckill::getNegativeList($where));
|
||||
}
|
||||
/**
|
||||
* 获取砍价产品的退货
|
||||
*/
|
||||
public function get_mark_bargain_refund_list($model = 0){
|
||||
$where = Util::getMore([
|
||||
['page',1],
|
||||
['limit',20],
|
||||
]);
|
||||
if(!$model) return JsonService::successlayui(StoreBargain::getBargainRefundList($where));
|
||||
if($model) return JsonService::successlayui(StoreSeckill::getBargainRefundList($where));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
87
app/admin/controller/record/StoreStatistics.php
Normal file
87
app/admin/controller/record/StoreStatistics.php
Normal file
@ -0,0 +1,87 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Administrator
|
||||
* Date: 2018/4/16 0016
|
||||
* Time: 10:39
|
||||
*/
|
||||
|
||||
namespace app\admin\controller\record;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use crmeb\services\UtilService as Util;
|
||||
use app\admin\model\record\StoreStatistics as StatisticsModel;
|
||||
|
||||
/**
|
||||
* Class StoreStatistics
|
||||
* @package app\admin\controller\record
|
||||
*/
|
||||
class StoreStatistics extends AuthController
|
||||
{
|
||||
/**
|
||||
* 显示列表
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$where = Util::getMore([
|
||||
['date',''],
|
||||
['export',''],
|
||||
['data','']
|
||||
],$this->request);
|
||||
$where['date']=$this->request->param('date');
|
||||
$where['data']=$this->request->param('data');
|
||||
$where['export']=$this->request->param('export');
|
||||
$trans=StatisticsModel::trans();//最近交易
|
||||
$seckill=StatisticsModel::getSeckill($where);//秒杀商品
|
||||
$ordinary=StatisticsModel::getOrdinary($where);//普通商品
|
||||
$pink=StatisticsModel::getPink($where);//拼团商品
|
||||
$recharge=StatisticsModel::getRecharge($where);//充值
|
||||
$extension=StatisticsModel::getExtension($where);//推广金
|
||||
$orderCount = [
|
||||
urlencode('微信支付')=>StatisticsModel::getTimeWhere($where,StatisticsModel::statusByWhere('weixin'))->count(),
|
||||
urlencode('余额支付')=>StatisticsModel::getTimeWhere($where,StatisticsModel::statusByWhere('yue'))->count(),
|
||||
urlencode('线下支付')=>StatisticsModel::getTimeWhere($where,StatisticsModel::statusByWhere('offline'))->count(),
|
||||
];
|
||||
$Statistic = [
|
||||
['name'=>'营业额','type'=>'line','data'=>[]],
|
||||
['name'=>'支出','type'=>'line','data'=>[]],
|
||||
['name'=>'盈利','type'=>'line','data'=>[]],
|
||||
];
|
||||
$orderinfos=StatisticsModel::getOrderInfo($where);
|
||||
$orderinfo=$orderinfos['orderinfo'];
|
||||
$orderDays=[];
|
||||
if (empty($orderinfo)){
|
||||
$orderDays[]=date('Y-m-d',time());
|
||||
$Statistic[0]['data'][] = 0;
|
||||
$Statistic[1]['data'][] = 0;
|
||||
$Statistic[2]['data'][] = 0;
|
||||
}
|
||||
foreach($orderinfo as $info){
|
||||
$orderDays[]=$info['pay_time'];
|
||||
$Statistic[0]['data'][] = $info['total_price']+$info['pay_postage'];
|
||||
$Statistic[1]['data'][] = $info['coupon_price']+$info['deduction_price']+$info['cost'];
|
||||
$Statistic[2]['data'][] = ($info['total_price']+$info['pay_postage'])-($info['coupon_price']+$info['deduction_price']+$info['cost']);
|
||||
}
|
||||
$price=$orderinfos['price']+$orderinfos['postage'];
|
||||
$cost=$orderinfos['deduction']+$orderinfos['coupon']+$orderinfos['cost'];
|
||||
$Consumption=StatisticsModel::getConsumption($where)['number'];
|
||||
$header=[
|
||||
['name'=>'总营业额', 'class'=>'fa-line-chart', 'value'=>'¥'.$price, 'color'=>'red'],
|
||||
['name'=>'总支出', 'class'=>'fa-area-chart', 'value'=>'¥'.($cost+$extension), 'color'=>'lazur'],
|
||||
['name'=>'总盈利', 'class'=>'fa-bar-chart', 'value'=>'¥'.bcsub($price,$cost,0), 'color'=>'navy'],
|
||||
['name'=>'新增消费', 'class'=>'fa-pie-chart', 'value'=>'¥'.($Consumption==0?0:$Consumption), 'color'=>'yellow']
|
||||
];
|
||||
$data=[
|
||||
['value'=>$orderinfos['cost'], 'name'=>'商品成本'],
|
||||
['value'=>$orderinfos['coupon'], 'name'=>'优惠券抵扣'],
|
||||
['value'=>$orderinfos['deduction'], 'name'=>'积分抵扣'],
|
||||
['value'=>$extension, 'name'=>'推广人佣金']
|
||||
];
|
||||
|
||||
$this->assign(StatisticsModel::systemTable($where));
|
||||
$this->assign(compact('where','trans','orderCount','orderDays','header','Statistic','ordinary','pink','recharge','data','seckill'));
|
||||
$this->assign('price',StatisticsModel::getOrderPrice($where));
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
115
app/admin/controller/routine/RoutineTemplate.php
Normal file
115
app/admin/controller/routine/RoutineTemplate.php
Normal file
@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\routine;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use crmeb\services\FormBuilder as Form;
|
||||
use crmeb\services\UtilService as Util;
|
||||
use crmeb\services\JsonService as Json;
|
||||
use think\facade\Route as Url;
|
||||
use app\admin\model\routine\RoutineTemplate as RoutineTemplateModel;
|
||||
|
||||
/**
|
||||
* 小程序模板消息控制器
|
||||
* Class RoutineTemplate
|
||||
* @package app\admin\controller\routine
|
||||
*/
|
||||
class RoutineTemplate extends AuthController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$where = Util::getMore([
|
||||
['name',''],
|
||||
['status','']
|
||||
],$this->request);
|
||||
$this->assign('where',$where);
|
||||
$this->assign(RoutineTemplateModel::SystemPage($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加模板消息
|
||||
* @return mixed
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$f = array();
|
||||
$f[] = Form::input('tempkey','模板编号');
|
||||
$f[] = Form::input('tempid','模板ID');
|
||||
$f[] = Form::input('name','模板名');
|
||||
$f[] = Form::input('content','回复内容')->type('textarea');
|
||||
$f[] = Form::radio('status','状态',1)->options([['label'=>'开启','value'=>1],['label'=>'关闭','value'=>0]]);
|
||||
$form = Form::make_post_form('添加模板消息',$f,Url::buildUrl('save'));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
public function save()
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'tempkey',
|
||||
'tempid',
|
||||
'name',
|
||||
'content',
|
||||
['status',0]
|
||||
]);
|
||||
if($data['tempkey'] == '') return Json::fail('请输入模板编号');
|
||||
if($data['tempkey'] != '' && RoutineTemplateModel::be($data['tempkey'],'tempkey'))
|
||||
return Json::fail('请输入模板编号已存在,请重新输入');
|
||||
if($data['tempid'] == '') return Json::fail('请输入模板ID');
|
||||
if($data['name'] == '') return Json::fail('请输入模板名');
|
||||
if($data['content'] == '') return Json::fail('请输入回复内容');
|
||||
$data['add_time'] = time();
|
||||
RoutineTemplateModel::create($data);
|
||||
return Json::successful('添加模板消息成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑模板消息
|
||||
* @param $id
|
||||
* @return mixed|\think\response\Json|void
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = RoutineTemplateModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
$f = array();
|
||||
$f[] = Form::input('tempkey','模板编号',$product->getData('tempkey'))->disabled(1);
|
||||
$f[] = Form::input('name','模板名',$product->getData('name'))->disabled(1);
|
||||
$f[] = Form::input('tempid','模板ID',$product->getData('tempid'));
|
||||
$f[] = Form::radio('status','状态',$product->getData('status'))->options([['label'=>'开启','value'=>1],['label'=>'关闭','value'=>0]]);
|
||||
$form = Form::make_post_form('编辑模板消息',$f,Url::buildUrl('update',compact('id')));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
public function update($id)
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'tempid',
|
||||
['status',0]
|
||||
]);
|
||||
if($data['tempid'] == '') return Json::fail('请输入模板ID');
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = RoutineTemplateModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
RoutineTemplateModel::edit($data,$id);
|
||||
return Json::successful('修改成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除模板消息
|
||||
* @param $id
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
if(!$id) return Json::fail('数据不存在!');
|
||||
if(!RoutineTemplateModel::del($id))
|
||||
return Json::fail(RoutineTemplateModel::getErrorInfo('删除失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('删除成功!');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
216
app/admin/controller/setting/SystemAdmin.php
Normal file
216
app/admin/controller/setting/SystemAdmin.php
Normal file
@ -0,0 +1,216 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\setting;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use crmeb\services\FormBuilder as Form;
|
||||
use crmeb\services\JsonService;
|
||||
use crmeb\services\UtilService as Util;
|
||||
use crmeb\services\JsonService as Json;
|
||||
use app\admin\model\system\SystemRole;
|
||||
use think\facade\Route as Url;
|
||||
use app\admin\model\system\SystemAdmin as AdminModel;
|
||||
|
||||
/**
|
||||
* 管理员列表控制器
|
||||
* Class SystemAdmin
|
||||
* @package app\admin\controller\system
|
||||
*/
|
||||
class SystemAdmin extends AuthController
|
||||
{
|
||||
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$admin = $this->adminInfo;
|
||||
$where = Util::getMore([
|
||||
['name',''],
|
||||
['roles',''],
|
||||
['level',bcadd($admin->level,1,0)]
|
||||
]);
|
||||
$this->assign('where',$where);
|
||||
$this->assign('role',SystemRole::getRole(bcadd($admin->level,1,0)));
|
||||
$this->assign(AdminModel::systemPage($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$admin = $this->adminInfo;
|
||||
$f = array();
|
||||
$f[] = Form::input('account','管理员账号');
|
||||
$f[] = Form::input('pwd','管理员密码')->type('password');
|
||||
$f[] = Form::input('conf_pwd','确认密码')->type('password');
|
||||
$f[] = Form::input('real_name','管理员姓名');
|
||||
$f[] = Form::select('roles','管理员身份')->setOptions(function ()use($admin){
|
||||
$list = SystemRole::getRole(bcadd($admin->level,1,0));
|
||||
$options = [];
|
||||
foreach ($list as $id=>$roleName){
|
||||
$options[] = ['label'=>$roleName,'value'=>$id];
|
||||
}
|
||||
return $options;
|
||||
})->multiple(1);
|
||||
$f[] = Form::radio('status','状态',1)->options([['label'=>'开启','value'=>1],['label'=>'关闭','value'=>0]]);
|
||||
$form = Form::make_post_form('添加管理员',$f,Url::buildUrl('save'));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'account',
|
||||
'conf_pwd',
|
||||
'pwd',
|
||||
'real_name',
|
||||
['roles',[]],
|
||||
['status',0]
|
||||
]);
|
||||
if(!$data['account']) return Json::fail('请输入管理员账号');
|
||||
if(!$data['roles']) return Json::fail('请选择至少一个管理员身份');
|
||||
if(!$data['pwd']) return Json::fail('请输入管理员登陆密码');
|
||||
if($data['pwd'] != $data['conf_pwd']) return Json::fail('两次输入密码不想同');
|
||||
if(AdminModel::be($data['account'],'account')) return Json::fail('管理员账号已存在');
|
||||
$data['pwd'] = md5($data['pwd']);
|
||||
$data['add_time'] = time();
|
||||
unset($data['conf_pwd']);
|
||||
$data['level'] = $this->adminInfo['level'] + 1;
|
||||
$data['add_time'] =time();
|
||||
if(!AdminModel::create($data)) return Json::fail('添加管理员失败');
|
||||
return Json::successful('添加管理员成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
if(!$id) return $this->failed('参数错误');
|
||||
$admin = AdminModel::get($id);
|
||||
if(!$admin) return Json::fail('数据不存在!');
|
||||
$f = array();
|
||||
$f[] = Form::input('account','管理员账号',$admin->account);
|
||||
$f[] = Form::input('pwd','管理员密码')->type('password');
|
||||
$f[] = Form::input('conf_pwd','确认密码')->type('password');
|
||||
$f[] = Form::input('real_name','管理员姓名',$admin->real_name);
|
||||
$f[] = Form::select('roles','管理员身份',explode(',',$admin->roles))->setOptions(function ()use($admin){
|
||||
$list = SystemRole::getRole($admin->level);
|
||||
$options = [];
|
||||
foreach ($list as $id=>$roleName){
|
||||
$options[] = ['label'=>$roleName,'value'=>$id];
|
||||
}
|
||||
return $options;
|
||||
})->multiple(1);
|
||||
$f[] = Form::radio('status','状态',1)->options([['label'=>'开启','value'=>1],['label'=>'关闭','value'=>0]]);
|
||||
$form = Form::make_post_form('编辑管理员',$f,Url::buildUrl('update',compact('id')));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存更新的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function update($id)
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'account',
|
||||
'conf_pwd',
|
||||
'pwd',
|
||||
'real_name',
|
||||
['roles',[]],
|
||||
['status',0]
|
||||
]);
|
||||
if(!$data['account']) return Json::fail('请输入管理员账号');
|
||||
if(!$data['roles']) return Json::fail('请选择至少一个管理员身份');
|
||||
if(!$data['pwd'])
|
||||
unset($data['pwd']);
|
||||
else{
|
||||
if(isset($data['pwd']) && $data['pwd'] != $data['conf_pwd']) return Json::fail('两次输入密码不想同');
|
||||
$data['pwd'] = md5($data['pwd']);
|
||||
}
|
||||
if(AdminModel::where('account',$data['account'])->where('id','<>',$id)->count()) return Json::fail('管理员账号已存在');
|
||||
unset($data['conf_pwd']);
|
||||
if(!AdminModel::edit($data,$id)) return Json::fail('修改失败');
|
||||
return Json::successful('修改成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
if(!$id)
|
||||
return JsonService::fail('删除失败!');
|
||||
if(AdminModel::edit(['is_del'=>1,'status'=>0],$id,'id'))
|
||||
return JsonService::successful('删除成功!');
|
||||
else
|
||||
return JsonService::fail('删除失败!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 个人资料 展示
|
||||
* @return string
|
||||
*/
|
||||
public function adminInfo(){
|
||||
$adminInfo = $this->adminInfo;//获取当前登录的管理员
|
||||
$this->assign('adminInfo',$adminInfo);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存信息
|
||||
*/
|
||||
public function setAdminInfo(){
|
||||
$adminInfo = $this->adminInfo;//获取当前登录的管理员
|
||||
if($this->request->isPost()){
|
||||
$data = Util::postMore([
|
||||
['new_pwd',''],
|
||||
['new_pwd_ok',''],
|
||||
['pwd',''],
|
||||
'real_name',
|
||||
]);
|
||||
if($data['pwd'] != ''){
|
||||
$pwd = md5($data['pwd']);
|
||||
if($adminInfo['pwd'] != $pwd) return Json::fail('原始密码错误');
|
||||
}
|
||||
if($data['new_pwd'] != ''){
|
||||
if(!$data['new_pwd_ok']) return Json::fail('请输入确认新密码');
|
||||
if($data['new_pwd'] != $data['new_pwd_ok']) return Json::fail('俩次密码不一样');
|
||||
}
|
||||
if($data['pwd'] != '' && $data['new_pwd'] != ''){
|
||||
$data['pwd'] = md5($data['new_pwd']);
|
||||
}else{
|
||||
unset($data['pwd']);
|
||||
}
|
||||
unset($data['new_pwd']);
|
||||
unset($data['new_pwd_ok']);
|
||||
if(!AdminModel::edit($data,$adminInfo['id'])) return Json::fail('修改失败');
|
||||
return Json::successful('修改成功!,请重新登录');
|
||||
}
|
||||
}
|
||||
}
|
||||
426
app/admin/controller/setting/SystemConfig.php
Normal file
426
app/admin/controller/setting/SystemConfig.php
Normal file
@ -0,0 +1,426 @@
|
||||
<?php
|
||||
namespace app\admin\controller\setting;
|
||||
|
||||
use app\admin\model\system\SystemAttachment;
|
||||
use think\facade\Route as Url;
|
||||
use crmeb\services\FormBuilder as Form;
|
||||
use crmeb\services\UtilService as Util;
|
||||
use crmeb\services\JsonService as Json;
|
||||
use crmeb\services\UploadService as Upload;
|
||||
use app\admin\controller\AuthController;
|
||||
use app\admin\model\system\SystemConfig as ConfigModel;
|
||||
/**
|
||||
* 配置列表控制器
|
||||
* Class SystemConfig
|
||||
* @package app\admin\controller\system
|
||||
*/
|
||||
class SystemConfig extends AuthController
|
||||
{
|
||||
/**
|
||||
* 基础配置
|
||||
* */
|
||||
public function index(){
|
||||
$type = input('type')!=0?input('type'):0;
|
||||
$tab_id = input('tab_id');
|
||||
if(!$tab_id) $tab_id = 1;
|
||||
$this->assign('tab_id',$tab_id);
|
||||
$list = ConfigModel::getAll($tab_id);
|
||||
if($type==3){//其它分类
|
||||
$config_tab = null;
|
||||
}else{
|
||||
$config_tab = ConfigModel::getConfigTabAll($type);
|
||||
foreach ($config_tab as $kk=>$vv){
|
||||
$arr = ConfigModel::getAll($vv['value'])->toArray();
|
||||
if(empty($arr)){
|
||||
unset($config_tab[$kk]);
|
||||
}
|
||||
}
|
||||
}
|
||||
$formbuider = [];
|
||||
// var_dump($list->toArray());
|
||||
foreach ($list as $data){
|
||||
switch ($data['type']){
|
||||
case 'text'://文本框
|
||||
switch ($data['input_type']){
|
||||
case 'input':
|
||||
$data['value'] = json_decode($data['value'],true)?:'';
|
||||
$formbuider[] = Form::input($data['menu_name'],$data['info'],$data['value'])->info($data['desc'])->placeholder($data['desc'])->col(13);
|
||||
break;
|
||||
case 'number':
|
||||
$data['value'] = json_decode($data['value'],true)?:0;
|
||||
$formbuider[] = Form::number($data['menu_name'],$data['info'],$data['value'])->info($data['desc']);
|
||||
break;
|
||||
case 'dateTime':
|
||||
$formbuider[] = Form::dateTime($data['menu_name'],$data['info'],$data['value'])->info($data['desc']);
|
||||
break;
|
||||
case 'color':
|
||||
$data['value'] = json_decode($data['value'],true)?:'';
|
||||
$formbuider[] = Form::color($data['menu_name'],$data['info'],$data['value'])->info($data['desc']);
|
||||
break;
|
||||
default:
|
||||
$data['value'] = json_decode($data['value'],true)?:'';
|
||||
$formbuider[] = Form::input($data['menu_name'],$data['info'],$data['value'])->info($data['desc'])->placeholder($data['desc'])->col(13);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'textarea'://多行文本框
|
||||
$data['value'] = json_decode($data['value'],true)?:'';
|
||||
$formbuider[] = Form::textarea($data['menu_name'],$data['info'],$data['value'])->placeholder($data['desc'])->info($data['desc'])->rows(6)->col(13);
|
||||
break;
|
||||
case 'radio'://单选框
|
||||
$data['value'] = json_decode($data['value'],true)?:'0';
|
||||
$parameter = explode("\n",$data['parameter']);
|
||||
$options = [];
|
||||
if($parameter) {
|
||||
foreach ($parameter as $v) {
|
||||
$pdata = explode("=>", $v);
|
||||
$options[] = ['label' => $pdata[1], 'value' => $pdata[0]];
|
||||
}
|
||||
$formbuider[] = Form::radio($data['menu_name'],$data['info'],$data['value'])->options($options)->info($data['desc'])->col(13);
|
||||
}
|
||||
break;
|
||||
case 'upload'://文件上传
|
||||
switch ($data['upload_type']){
|
||||
case 1:
|
||||
$data['value'] = json_decode($data['value'],true)?:'';
|
||||
$formbuider[] = Form::frameImageOne($data['menu_name'],$data['info'],Url::buildUrl('admin/widget.images/index',array('fodder'=>$data['menu_name'])),$data['value'])->icon('image')->width('70%')->height('500px')->info($data['desc'])->col(13);
|
||||
break;
|
||||
case 2:
|
||||
$data['value'] = json_decode($data['value'],true)?:[];
|
||||
$formbuider[] = Form::frameImages($data['menu_name'],$data['info'],Url::buildUrl('admin/widget.images/index',array('fodder'=>$data['menu_name'])),$data['value'])->maxLength(5)->icon('image')->width('70%')->height('500px')->info($data['desc'])->col(13);
|
||||
break;
|
||||
case 3:
|
||||
$data['value'] = json_decode($data['value'],true);
|
||||
$formbuider[] = Form::uploadFileOne($data['menu_name'],$data['info'],Url::buildUrl('file_upload'),$data['value'])->name('file')->info($data['desc'])->col(13);
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
case 'checkbox'://多选框
|
||||
$data['value'] = json_decode($data['value'],true)?:[];
|
||||
$parameter = explode("\n",$data['parameter']);
|
||||
$options = [];
|
||||
if($parameter) {
|
||||
foreach ($parameter as $v) {
|
||||
$pdata = explode("=>", $v);
|
||||
$options[] = ['label' => $pdata[1], 'value' => $pdata[0]];
|
||||
}
|
||||
$formbuider[] = Form::checkbox($data['menu_name'],$data['info'],$data['value'])->options($options)->info($data['desc'])->col(13);
|
||||
}
|
||||
break;
|
||||
case 'select'://多选框
|
||||
$data['value'] = json_decode($data['value'],true)?:[];
|
||||
$parameter = explode("\n",$data['parameter']);
|
||||
$options = [];
|
||||
if($parameter) {
|
||||
foreach ($parameter as $v) {
|
||||
$pdata = explode("=>", $v);
|
||||
$options[] = ['label' => $pdata[1], 'value' => $pdata[0]];
|
||||
}
|
||||
$formbuider[] = Form::select($data['menu_name'],$data['info'],$data['value'])->options($options)->info($data['desc'])->col(13);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$form = Form::make_post_form('编辑配置',$formbuider,Url::buildUrl('save_basics'));
|
||||
$this->assign(compact('form'));
|
||||
$this->assign('config_tab',$config_tab);
|
||||
$this->assign('list',$list);
|
||||
return $this->fetch();
|
||||
}
|
||||
/**
|
||||
* 基础配置 单个
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function index_alone(){
|
||||
$tab_id = input('tab_id');
|
||||
if(!$tab_id) return $this->failed('参数错误,请重新打开');
|
||||
$this->assign('tab_id',$tab_id);
|
||||
$list = ConfigModel::getAll($tab_id);
|
||||
foreach ($list as $k=>$v){
|
||||
if(!is_null(json_decode($v['value'])))
|
||||
$list[$k]['value'] = json_decode($v['value'],true);
|
||||
if($v['type'] == 'upload' && !empty($v['value'])){
|
||||
if($v['upload_type'] == 1 || $v['upload_type'] == 3) $list[$k]['value'] = explode(',',$v['value']);
|
||||
}
|
||||
}
|
||||
$this->assign('list',$list);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加字段
|
||||
* @return string
|
||||
* @throws \FormBuilder\exception\FormBuilderException
|
||||
*/
|
||||
public function create(){
|
||||
$data = Util::getMore(['type',]);//接收参数
|
||||
$tab_id = !empty(request()->param('tab_id')) ? request()->param('tab_id') : 1;
|
||||
$formbuider = array();
|
||||
switch ($data['type']){
|
||||
case 0://文本框
|
||||
$formbuider = ConfigModel::createInputRule($tab_id);
|
||||
break;
|
||||
case 1://多行文本框
|
||||
$formbuider = ConfigModel::createTextAreaRule($tab_id);
|
||||
break;
|
||||
case 2://单选框
|
||||
$formbuider = ConfigModel::createRadioRule($tab_id);
|
||||
break;
|
||||
case 3://文件上传
|
||||
$formbuider = ConfigModel::createUploadRule($tab_id);
|
||||
break;
|
||||
case 4://多选框
|
||||
$formbuider = ConfigModel::createCheckboxRule($tab_id);
|
||||
break;
|
||||
case 5://下拉框
|
||||
$formbuider = ConfigModel::createSelectRule($tab_id);
|
||||
break;
|
||||
}
|
||||
$form = Form::make_post_form('添加字段',$formbuider,Url::buildUrl('save'));
|
||||
$this->assign(compact('form'));
|
||||
$this->assign('get',request()->param());
|
||||
return $this->fetch();
|
||||
}
|
||||
/**
|
||||
* 保存字段
|
||||
* */
|
||||
public function save(){
|
||||
$data = Util::postMore([
|
||||
'menu_name',
|
||||
'type',
|
||||
'input_type',
|
||||
'config_tab_id',
|
||||
'parameter',
|
||||
'upload_type',
|
||||
'required',
|
||||
'width',
|
||||
'high',
|
||||
'value',
|
||||
'info',
|
||||
'desc',
|
||||
'sort',
|
||||
'status',]);
|
||||
if(!$data['info']) return Json::fail('请输入配置名称');
|
||||
if(!$data['menu_name']) return Json::fail('请输入字段名称');
|
||||
if($data['menu_name']){
|
||||
$oneConfig = ConfigModel::getOneConfig('menu_name',$data['menu_name']);
|
||||
if(!empty($oneConfig)) return Json::fail('请重新输入字段名称,之前的已经使用过了');
|
||||
}
|
||||
if(!$data['desc']) return Json::fail('请输入配置简介');
|
||||
if($data['sort'] < 0){
|
||||
$data['sort'] = 0;
|
||||
}
|
||||
if($data['type'] == 'text'){
|
||||
if(!ConfigModel::valiDateTextRole($data)) return Json::fail(ConfigModel::getErrorInfo());
|
||||
}
|
||||
if($data['type'] == 'textarea'){
|
||||
if(!ConfigModel::valiDateTextareaRole($data)) return Json::fail(ConfigModel::getErrorInfo());
|
||||
}
|
||||
if($data['type'] == 'radio' || $data['type'] == 'checkbox' ){
|
||||
if(!$data['parameter']) return Json::fail('请输入配置参数');
|
||||
if(!ConfigModel::valiDateRadioAndCheckbox($data)) return Json::fail(ConfigModel::getErrorInfo());
|
||||
$data['value'] = json_encode($data['value']);
|
||||
}
|
||||
ConfigModel::create($data);
|
||||
return Json::successful('添加菜单成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
*/
|
||||
public function update_config($id)
|
||||
{
|
||||
$type = request()->post('type');
|
||||
if($type =='text' || $type =='textarea'|| $type == 'radio' || ($type == 'upload' && (request()->post('upload_type') == 1 || request()->post('upload_type') == 3))){
|
||||
$value = request()->post('value');
|
||||
}else{
|
||||
$value = request()->post('value/a');
|
||||
}
|
||||
$data = Util::postMore(['status','info','desc','sort','config_tab_id','required','parameter',['value',$value],'upload_type','input_type']);
|
||||
$data['value'] = json_encode($data['value']);
|
||||
if(!ConfigModel::get($id)) return Json::fail('编辑的记录不存在!');
|
||||
ConfigModel::edit($data,$id);
|
||||
return Json::successful('修改成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改是否显示子子段
|
||||
* @param $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function edit_cinfig($id){
|
||||
$menu = ConfigModel::get($id)->getData();
|
||||
if(!$menu) return Json::fail('数据不存在!');
|
||||
$formbuider = array();
|
||||
$formbuider[] = Form::input('menu_name','字段变量',$menu['menu_name'])->disabled(1);
|
||||
$formbuider[] = Form::hidden('type',$menu['type']);
|
||||
$formbuider[] = Form::select('config_tab_id','分类',(string)$menu['config_tab_id'])->setOptions(ConfigModel::getConfigTabAll(-1));
|
||||
$formbuider[] = Form::input('info','配置名称',$menu['info'])->autofocus(1);
|
||||
$formbuider[] = Form::input('desc','配置简介',$menu['desc']);
|
||||
switch ($menu['type']){
|
||||
case 'text':
|
||||
$menu['value'] = json_decode($menu['value'],true);
|
||||
$formbuider[] = Form::select('input_type','类型',$menu['input_type'])->setOptions(ConfigModel::texttype());
|
||||
//输入框验证规则
|
||||
$formbuider[] = Form::input('value','默认值',$menu['value']);
|
||||
if(!empty($menu['required'])){
|
||||
$formbuider[] = Form::number('width','文本框宽(%)',$menu['width']);
|
||||
$formbuider[] = Form::input('required','验证规则',$menu['required'])->placeholder('多个请用,隔开例如:required:true,url:true');
|
||||
}
|
||||
break;
|
||||
case 'textarea':
|
||||
$menu['value'] = json_decode($menu['value'],true);
|
||||
//多行文本
|
||||
if(!empty($menu['high'])){
|
||||
$formbuider[] = Form::textarea('value','默认值',$menu['value'])->rows(5);
|
||||
$formbuider[] = Form::number('width','文本框宽(%)',$menu['width']);
|
||||
$formbuider[] = Form::number('high','多行文本框高(%)',$menu['high']);
|
||||
}else{
|
||||
$formbuider[] = Form::input('value','默认值',$menu['value']);
|
||||
}
|
||||
break;
|
||||
case 'radio':
|
||||
$menu['value'] = json_decode($menu['value'],true);
|
||||
$parameter = explode("\n",$menu['parameter']);
|
||||
$options = [];
|
||||
if($parameter){
|
||||
foreach ($parameter as $v){
|
||||
$data = explode("=>",$v);
|
||||
$options[] = ['label'=>$data[1],'value'=>$data[0]];
|
||||
}
|
||||
$formbuider[] = Form::radio('value','默认值',$menu['value'])->options($options);
|
||||
}
|
||||
//单选和多选参数配置
|
||||
if(!empty($menu['parameter'])){
|
||||
$formbuider[] = Form::textarea('parameter','配置参数',$menu['parameter'])->placeholder("参数方式例如:\n1=白色\n2=红色\n3=黑色");
|
||||
}
|
||||
break;
|
||||
case 'checkbox':
|
||||
$menu['value'] = json_decode($menu['value'],true)?:[];
|
||||
$parameter = explode("\n",$menu['parameter']);
|
||||
$options = [];
|
||||
if($parameter) {
|
||||
foreach ($parameter as $v) {
|
||||
$data = explode("=>", $v);
|
||||
$options[] = ['label' => $data[1], 'value' => $data[0]];
|
||||
}
|
||||
$formbuider[] = Form::checkbox('value', '默认值', $menu['value'])->options($options);
|
||||
}
|
||||
//单选和多选参数配置
|
||||
if(!empty($menu['parameter'])){
|
||||
$formbuider[] = Form::textarea('parameter','配置参数',$menu['parameter'])->placeholder("参数方式例如:\n1=白色\n2=红色\n3=黑色");
|
||||
}
|
||||
break;
|
||||
case 'upload':
|
||||
if($menu['upload_type'] == 1 ){
|
||||
$menu['value'] = json_decode($menu['value'],true);
|
||||
$formbuider[] = Form::frameImageOne('value','图片',Url::buildUrl('admin/widget.images/index',array('fodder'=>'value')),(string)$menu['value'])->icon('image')->width('100%')->height('550px');
|
||||
}elseif ($menu['upload_type'] == 2 ){
|
||||
$menu['value'] = json_decode($menu['value'],true)?:[];
|
||||
$formbuider[] = Form::frameImages('value','多图片',Url::buildUrl('admin/widget.images/index',array('fodder'=>'value')),$menu['value'])->maxLength(5)->icon('images')->width('100%')->height('550px')->spin(0);
|
||||
}else{
|
||||
$menu['value'] = json_decode($menu['value'],true);
|
||||
$formbuider[] = Form::uploadFileOne('value','文件',Url::buildUrl('file_upload'),$menu['value'])->name('file');
|
||||
}
|
||||
//上传类型选择
|
||||
if(!empty($menu['upload_type'])){
|
||||
$formbuider[] = Form::radio('upload_type','上传类型',$menu['upload_type'])->options([['value'=>1,'label'=>'单图'],['value'=>2,'label'=>'多图'],['value'=>3,'label'=>'文件']]);
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
$formbuider[] = Form::number('sort','排序',$menu['sort']);
|
||||
$formbuider[] = Form::radio('status','状态',$menu['status'])->options([['value'=>1,'label'=>'显示'],['value'=>2,'label'=>'隐藏']]);
|
||||
|
||||
$form = Form::make_post_form('编辑字段',$formbuider,Url::buildUrl('update_config',array('id'=>$id)));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
/**
|
||||
* 删除子字段
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function delete_cinfig(){
|
||||
$id = input('id');
|
||||
if(!ConfigModel::del($id))
|
||||
return Json::fail(ConfigModel::getErrorInfo('删除失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('删除成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存数据 true
|
||||
* */
|
||||
public function save_basics(){
|
||||
$request = app('request');
|
||||
if($request->isPost()){
|
||||
$post = $request->post();
|
||||
foreach ($post as $k=>$v){
|
||||
if(is_array($v)){
|
||||
$res = ConfigModel::where('menu_name',$k)->column('upload_type','type');
|
||||
foreach ($res as $kk=>$vv){
|
||||
if($kk == 'upload'){
|
||||
if($vv == 1 || $vv == 3){
|
||||
$post[$k] = $v[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($post as $k=>$v){
|
||||
ConfigModel::edit(['value' => json_encode($v)],$k,'menu_name');
|
||||
}
|
||||
return $this->successful('修改成功');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 模板表单提交
|
||||
* */
|
||||
// public function view_upload(){
|
||||
// if($_POST['type'] == 3){
|
||||
// $res = Upload::file($_POST['file'],'config/file');
|
||||
// if(!$res->status) return Json::fail($res->error);
|
||||
// return Json::successful('上传成功!',['url'=>$res->filePath]);
|
||||
// }else{
|
||||
// $res = Upload::Image($_POST['file'],'config/image');
|
||||
// if(is_array($res)){
|
||||
// SystemAttachment::attachmentAdd($res['name'],$res['size'],$res['type'],$res['dir'],$res['thumb_path'],0,$res['image_type'],$res['time']);
|
||||
// return Json::successful('上传成功!',['url'=>$res['dir']]);
|
||||
// }else return Json::fail($res);
|
||||
// }
|
||||
// }
|
||||
/**
|
||||
* 文件上传
|
||||
* */
|
||||
public function file_upload(){
|
||||
$res = Upload::file($this->request->param('file','file'),'config/file');
|
||||
if(!$res->status) return Json::fail($res->error);
|
||||
return Json::successful('上传成功!',['filePath'=>$res->filePath]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取文件名
|
||||
* */
|
||||
// public function getImageName(){
|
||||
// $request = app('request');
|
||||
// $post = $request->post();
|
||||
// $src = $post['src'];
|
||||
// $data['name'] = basename($src);
|
||||
// exit(json_encode($data));
|
||||
// }
|
||||
/**
|
||||
* 删除原来图片
|
||||
* @param $url
|
||||
*/
|
||||
// public function rmPublicResource($url)
|
||||
// {
|
||||
// $res = Util::rmPublicResource($url);
|
||||
// if($res->status)
|
||||
// return $this->successful('删除成功!');
|
||||
// else
|
||||
// return $this->failed($res->msg);
|
||||
// }
|
||||
}
|
||||
148
app/admin/controller/setting/SystemConfigTab.php
Normal file
148
app/admin/controller/setting/SystemConfigTab.php
Normal file
@ -0,0 +1,148 @@
|
||||
<?php
|
||||
namespace app\admin\controller\setting;
|
||||
|
||||
use think\facade\Route as Url;
|
||||
use crmeb\services\FormBuilder as Form;
|
||||
use think\Request;
|
||||
use crmeb\services\UtilService as Util;
|
||||
use crmeb\services\JsonService as Json;
|
||||
use app\admin\controller\AuthController;
|
||||
use app\admin\model\system\SystemConfigTab as ConfigTabModel;
|
||||
use app\admin\model\system\SystemConfig as ConfigModel;
|
||||
/**
|
||||
* 配置分类控制器
|
||||
* Class SystemConfigTab
|
||||
* @package app\admin\controller\system
|
||||
*/
|
||||
class SystemConfigTab extends AuthController
|
||||
{
|
||||
|
||||
/** 定义配置分类,需要添加分类可以手动添加
|
||||
* @return array
|
||||
*/
|
||||
public function getConfigType(){
|
||||
return [
|
||||
['value'=>0,'label'=>'系统']
|
||||
,['value'=>1,'label'=>'应用']
|
||||
,['value'=>2,'label'=>'支付']
|
||||
,['value'=>3,'label'=>'其它']
|
||||
];
|
||||
// return [
|
||||
// ['value'=>0,'label'=>'系统']
|
||||
// ,['value'=>1,'label'=>'公众号']
|
||||
// ,['value'=>2,'label'=>'小程序']
|
||||
// ,['value'=>3,'label'=>'其它']
|
||||
// ];
|
||||
}
|
||||
/**
|
||||
* 子子段
|
||||
* @return mixed|\think\response\Json
|
||||
*/
|
||||
public function sonconfigtab(){
|
||||
$tab_id = input('tab_id');
|
||||
if(!$tab_id) return Json::fail('参数错误');
|
||||
$this->assign('tab_id',$tab_id);
|
||||
$list = ConfigModel::getAll($tab_id);
|
||||
foreach ($list as $k=>$v){
|
||||
$list[$k]['value'] = json_decode($v['value'],true)?:'';
|
||||
if($v['type'] == 'radio' || $v['type'] == 'checkbox'){
|
||||
$list[$k]['value'] = ConfigTabModel::getRadioOrCheckboxValueInfo($v['menu_name'],$v['value']);
|
||||
}
|
||||
if($v['type'] == 'upload' && !empty($v['value'])){
|
||||
if($v['upload_type'] == 1 || $v['upload_type'] == 3) $list[$k]['value'] = explode(',',$v['value']);
|
||||
}
|
||||
}
|
||||
$this->assign('list',$list);
|
||||
return $this->fetch();
|
||||
}
|
||||
/**
|
||||
* 基础配置
|
||||
* @return mixed
|
||||
*/
|
||||
public function index(){
|
||||
$where = Util::getMore([
|
||||
['status',''],
|
||||
['title',''],
|
||||
],$this->request);
|
||||
$this->assign('where',$where);
|
||||
$this->assign(ConfigTabModel::getSystemConfigTabPage($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加配置分类
|
||||
* @return mixed
|
||||
*/
|
||||
public function create(){
|
||||
$form = Form::create(Url::buildUrl('save'),[
|
||||
Form::input('title','分类昵称'),
|
||||
Form::input('eng_title','分类字段'),
|
||||
Form::frameInputOne('icon','图标',Url::buildUrl('admin/widget.widgets/icon',array('fodder'=>'icon')))->icon('ionic')->height('500px'),
|
||||
Form::radio('type','类型',0)->options(self::getConfigType()),
|
||||
Form::radio('status','状态',1)->options([['value'=>1,'label'=>'显示'],['value'=>2,'label'=>'隐藏']])
|
||||
]);
|
||||
$form->setMethod('post')->setTitle('添加分类配置');
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存分类名称
|
||||
*/
|
||||
public function save(){
|
||||
$data = Util::postMore([
|
||||
'eng_title',
|
||||
'status',
|
||||
'title',
|
||||
'icon',
|
||||
'type']);
|
||||
if(!$data['title']) return Json::fail('请输入按钮名称');
|
||||
ConfigTabModel::create($data);
|
||||
return Json::successful('添加菜单成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改分类
|
||||
* @param $id
|
||||
* @return string|void
|
||||
* @throws \FormBuilder\exception\FormBuilderException
|
||||
*/
|
||||
public function edit($id){
|
||||
$menu = ConfigTabModel::get($id)->getData();
|
||||
if(!$menu) return Json::fail('数据不存在!');
|
||||
$form = Form::create(Url::buildUrl('update',array('id'=>$id)),[
|
||||
Form::input('title','分类昵称',$menu['title']),
|
||||
Form::input('eng_title','分类字段',$menu['eng_title']),
|
||||
Form::frameInputOne('icon','图标',Url::buildUrl('admin/widget.widgets/icon',array('fodder'=>'icon')),$menu['icon'])->icon('ionic')->height('500px'),
|
||||
Form::radio('type','类型',$menu['type'])->options(self::getConfigType()),
|
||||
Form::radio('status','状态',$menu['status'])->options([['value'=>1,'label'=>'显示'],['value'=>2,'label'=>'隐藏']])
|
||||
]);
|
||||
$form->setMethod('post')->setTitle('添加分类配置');
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
*/
|
||||
public function update($id)
|
||||
{
|
||||
$data = Util::postMore(['title','status','eng_title','icon','type']);
|
||||
if(!$data['title']) return Json::fail('请输入分类昵称');
|
||||
if(!$data['eng_title']) return Json::fail('请输入分类字段');
|
||||
if(!ConfigTabModel::get($id)) return Json::fail('编辑的记录不存在!');
|
||||
ConfigTabModel::edit($data,$id);
|
||||
return Json::successful('修改成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
*/
|
||||
public function delete($id){
|
||||
if(!ConfigTabModel::del($id))
|
||||
return Json::fail(ConfigTabModel::getErrorInfo('删除失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('删除成功!');
|
||||
}
|
||||
}
|
||||
128
app/admin/controller/setting/SystemGroup.php
Normal file
128
app/admin/controller/setting/SystemGroup.php
Normal file
@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\setting;
|
||||
|
||||
use crmeb\services\UtilService as Util;
|
||||
use crmeb\services\JsonService as Json;
|
||||
use think\facade\Route as Url;
|
||||
use app\admin\model\system\SystemGroup as GroupModel;
|
||||
use app\admin\model\system\SystemGroupData as GroupDataModel;
|
||||
use app\admin\controller\AuthController;
|
||||
|
||||
/**
|
||||
* 组合数据控制器
|
||||
* Class SystemGroup
|
||||
* @package app\admin\controller\system
|
||||
*/
|
||||
class SystemGroup extends AuthController
|
||||
{
|
||||
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->assign(GroupModel::page());
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$this->assign(['title'=>'添加数据组','save'=>Url::buildUrl('save')]);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
$params = Util::postMore([
|
||||
['id',''],
|
||||
['name',''],
|
||||
['config_name',''],
|
||||
['info',''],
|
||||
['typelist',[]],
|
||||
],$this->request);
|
||||
|
||||
//数据组名称判断
|
||||
if(!$params['name'])return Json::fail('请输入数据组名称!');
|
||||
if(!$params['config_name'])return Json::fail('请输入配置名称!');
|
||||
//判断ID是否存在,存在就是编辑,不存在就是添加
|
||||
if(!$params['id']){
|
||||
if(GroupModel::be($params['config_name'],'config_name')) return Json::fail('数据关键字已存在!');
|
||||
}
|
||||
$data["name"] = $params['name'];
|
||||
$data["config_name"] = $params['config_name'];
|
||||
$data["info"] = $params['info'];
|
||||
//字段信息判断
|
||||
if(!count($params['typelist']))
|
||||
return Json::fail('字段至少存在一个!');
|
||||
else{
|
||||
$validate = ["name","type","title","description"];
|
||||
foreach ($params["typelist"] as $key => $value) {
|
||||
foreach ($value as $name => $field) {
|
||||
if(empty($field["value"]) && in_array($name,$validate))
|
||||
return Json::fail("字段".($key + 1).":".$field["placeholder"]."不能为空!");
|
||||
else
|
||||
$data["fields"][$key][$name] = $field["value"];
|
||||
}
|
||||
}
|
||||
}
|
||||
$data["fields"] = json_encode($data["fields"]);
|
||||
//判断ID是否存在,存在就是编辑,不存在就是添加
|
||||
if(!$params['id']) {
|
||||
GroupModel::create($data);
|
||||
return Json::successful('添加数据组成功!');
|
||||
}else{
|
||||
GroupModel::edit($data,$params['id']);
|
||||
return Json::successful('编辑数据组成功!');
|
||||
}
|
||||
}
|
||||
|
||||
/**编辑数组
|
||||
* @param $id
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$Groupinfo = GroupModel::get($id);
|
||||
$fields = json_decode($Groupinfo['fields'],true);
|
||||
$typelist = [];
|
||||
foreach ($fields as $key => $v){
|
||||
$typelist[$key]['name']['value'] = $v['name'];
|
||||
$typelist[$key]['title']['value'] = $v['title'];
|
||||
$typelist[$key]['type']['value'] = $v['type'];
|
||||
$typelist[$key]['param']['value'] = $v['param'];
|
||||
}
|
||||
$Groupinfo['fields'] = json_encode($typelist);
|
||||
$this->assign(compact('Groupinfo'));
|
||||
$this->assign(['title'=>'添加数据组','save'=>Url::buildUrl('save')]);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
if(!GroupModel::del($id))
|
||||
return Json::fail(GroupModel::getErrorInfo('删除失败,请稍候再试!'));
|
||||
else{
|
||||
GroupDataModel::del(["gid"=>$id]);
|
||||
return Json::successful('删除成功!');
|
||||
}
|
||||
}
|
||||
}
|
||||
258
app/admin/controller/setting/SystemGroupData.php
Normal file
258
app/admin/controller/setting/SystemGroupData.php
Normal file
@ -0,0 +1,258 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\setting;
|
||||
|
||||
use crmeb\services\FormBuilder as Form;
|
||||
use crmeb\services\JsonService as Json;
|
||||
use crmeb\services\UploadService as Upload;
|
||||
use crmeb\services\UtilService as Util;
|
||||
use think\facade\Route as Url;
|
||||
use app\admin\model\system\SystemGroup as GroupModel;
|
||||
use app\admin\model\system\SystemGroupData as GroupDataModel;
|
||||
use app\admin\controller\AuthController;
|
||||
use app\admin\model\system\SystemAttachment;
|
||||
/**
|
||||
* 数据列表控制器 在组合数据中
|
||||
* Class SystemGroupData
|
||||
* @package app\admin\controller\system
|
||||
*/
|
||||
class SystemGroupData extends AuthController
|
||||
{
|
||||
|
||||
/**
|
||||
* 显示资源列表
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index($gid = 0)
|
||||
{
|
||||
$where = Util::getMore([
|
||||
['gid',0],
|
||||
['status',''],
|
||||
],$this->request);
|
||||
if($gid) $where['gid'] = $gid;
|
||||
$this->assign('where',$where);
|
||||
$this->assign(compact("gid"));
|
||||
$this->assign(GroupModel::getField($gid));
|
||||
$this->assign(GroupDataModel::getList($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function create($gid)
|
||||
{
|
||||
$Fields = GroupModel::getField($gid);
|
||||
$f = array();
|
||||
foreach ($Fields["fields"] as $key => $value) {
|
||||
$info = [];
|
||||
if(isset($value["param"])){
|
||||
$value["param"] = str_replace("\r\n","\n",$value["param"]);//防止不兼容
|
||||
$params = explode("\n",$value["param"]);
|
||||
if(is_array($params) && !empty($params)){
|
||||
foreach ($params as $index => $v) {
|
||||
$vl = explode('=>',$v);
|
||||
if(isset($vl[0]) && isset($vl[1])){
|
||||
$info[$index]["value"] = $vl[0];
|
||||
$info[$index]["label"] = $vl[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch ($value["type"]){
|
||||
case 'input':
|
||||
$f[] = Form::input($value["title"],$value["name"]);
|
||||
break;
|
||||
case 'textarea':
|
||||
$f[] = Form::input($value["title"],$value["name"])->type('textarea')->placeholder($value['param']);
|
||||
break;
|
||||
case 'radio':
|
||||
$f[] = Form::radio($value["title"],$value["name"],$info[0]["value"] ?? '')->options($info);
|
||||
break;
|
||||
case 'checkbox':
|
||||
$f[] = Form::checkbox($value["title"],$value["name"],$info[0] ?? '')->options($info);
|
||||
break;
|
||||
case 'select':
|
||||
$f[] = Form::select($value["title"],$value["name"],$info[0] ?? '')->options($info)->multiple(false);
|
||||
break;
|
||||
case 'upload':
|
||||
$f[] = Form::frameImageOne($value["title"],$value["name"],Url::buildUrl('admin/widget.images/index',array('fodder'=>$value["title"],'big'=>1)))->icon('image')->width('100%')->height('500px');
|
||||
break;
|
||||
case 'uploads':
|
||||
$f[] = Form::frameImages($value["title"],$value["name"],Url::buildUrl('admin/widget.images/index',array('fodder'=>$value["title"],'big'=>1)))->maxLength(5)->icon('images')->width('100%')->height('500px')->spin(0);
|
||||
break;
|
||||
default:
|
||||
$f[] = Form::input($value["title"],$value["name"]);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
$f[] = Form::number('sort','排序',1);
|
||||
$f[] = Form::radio('status','状态',1)->options([['value'=>1,'label'=>'显示'],['value'=>2,'label'=>'隐藏']]);
|
||||
$form = Form::make_post_form('添加数据',$f,Url::buildUrl('save',compact('gid')),2);
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function save($gid)
|
||||
{
|
||||
$Fields = GroupModel::getField($gid);
|
||||
$params = request()->post();
|
||||
foreach ($params as $key => $param) {
|
||||
foreach ($Fields['fields'] as $index => $field) {
|
||||
if($key == $field["title"]){
|
||||
// if($param == "" || count($param) == 0)
|
||||
if($param == "")
|
||||
return Json::fail($field["name"]."不能为空!");
|
||||
else{
|
||||
$value[$key]["type"] = $field["type"];
|
||||
$value[$key]["value"] = $param;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$data = array("gid"=>$gid,"add_time"=>time(),"value"=>json_encode($value),"sort"=>$params["sort"],"status"=>$params["status"]);
|
||||
GroupDataModel::create($data);
|
||||
return Json::successful('添加数据成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示指定的资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function read($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($gid,$id)
|
||||
{
|
||||
$GroupData = GroupDataModel::get($id);
|
||||
$GroupDataValue = json_decode($GroupData["value"],true);
|
||||
$Fields = GroupModel::getField($gid);
|
||||
$f = array();
|
||||
if(!isset($Fields['fields'])) return $this->failed('数据解析失败!');
|
||||
foreach ($Fields['fields'] as $key => $value) {
|
||||
$info = [];
|
||||
if(isset($value["param"])){
|
||||
$value["param"] = str_replace("\r\n","\n",$value["param"]);//防止不兼容
|
||||
$params = explode("\n",$value["param"]);
|
||||
if(is_array($params) && !empty($params)){
|
||||
foreach ($params as $index => $v) {
|
||||
$vl = explode('=>',$v);
|
||||
if(isset($vl[0]) && isset($vl[1])){
|
||||
$info[$index]["value"] = $vl[0];
|
||||
$info[$index]["label"] = $vl[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$fvalue = isset($GroupDataValue[$value['title']]['value'])?$GroupDataValue[$value['title']]['value']:'';
|
||||
switch ($value['type']){
|
||||
case 'input':
|
||||
$f[] = Form::input($value['title'],$value['name'],$fvalue);
|
||||
break;
|
||||
case 'textarea':
|
||||
$f[] = Form::input($value['title'],$value['name'],$fvalue)->type('textarea');
|
||||
break;
|
||||
case 'radio':
|
||||
|
||||
$f[] = Form::radio($value['title'],$value['name'],$fvalue)->options($info);
|
||||
break;
|
||||
case 'checkbox':
|
||||
$f[] = Form::checkbox($value['title'],$value['name'],$fvalue)->options($info);
|
||||
break;
|
||||
case 'upload':
|
||||
if(!empty($fvalue)){
|
||||
$image = is_string($fvalue) ? $fvalue : $fvalue[0];
|
||||
}else{
|
||||
$image = '';
|
||||
}
|
||||
$f[] = Form::frameImageOne($value['title'],$value['name'],Url::buildUrl('admin/widget.images/index',array('fodder'=>$value['title'],'big'=>1)),$image)->icon('image')->width('100%')->height('500px');
|
||||
break;
|
||||
case 'uploads':
|
||||
$images = !empty($fvalue) ? $fvalue:[];
|
||||
$f[] = Form::frameImages($value['title'],$value['name'],Url::buildUrl('admin/widget.images/index', array('fodder' => $value['title'],'big'=>1)),$images)->maxLength(5)->icon('images')->width('100%')->height('500px')->spin(0);
|
||||
break;
|
||||
case 'select':
|
||||
$f[] = Form::select($value['title'],$value['name'],$fvalue)->setOptions($info);
|
||||
break;
|
||||
default:
|
||||
$f[] = Form::input($value['title'],$value['name'],$fvalue);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
$f[] = Form::input('sort','排序',$GroupData["sort"]);
|
||||
$f[] = Form::radio('status','状态',$GroupData["status"])->options([['value'=>1,'label'=>'显示'],['value'=>2,'label'=>'隐藏']]);
|
||||
$form = Form::make_post_form('添加用户通知',$f,Url::buildUrl('update',compact('id')),2);
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存更新的资源
|
||||
*
|
||||
* @param $id
|
||||
*/
|
||||
public function update($id)
|
||||
{
|
||||
$GroupData = GroupDataModel::get($id);
|
||||
$Fields = GroupModel::getField($GroupData["gid"]);
|
||||
$params = request()->post();
|
||||
foreach ($params as $key => $param) {
|
||||
foreach ($Fields['fields'] as $index => $field) {
|
||||
if($key == $field["title"]){
|
||||
if(trim($param) == '')
|
||||
return Json::fail($field["name"]."不能为空!");
|
||||
else{
|
||||
$value[$key]["type"] = $field["type"];
|
||||
$value[$key]["value"] = $param;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$data = array("value"=>json_encode($value),"sort"=>$params["sort"],"status"=>$params["status"]);
|
||||
GroupDataModel::edit($data,$id);
|
||||
return Json::successful('修改成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
if(!GroupDataModel::del($id))
|
||||
return Json::fail(GroupDataModel::getErrorInfo('删除失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('删除成功!');
|
||||
}
|
||||
|
||||
public function upload()
|
||||
{
|
||||
$res = Upload::image('file','common');
|
||||
if(!is_array($res)) return Json::fail($res);
|
||||
SystemAttachment::attachmentAdd($res['name'],$res['size'],$res['type'],$res['dir'],$res['thumb_path'],6,$res['image_type'],$res['time']);
|
||||
return Json::successful('图片上传成功!',['name'=>$res['name'],'url'=>Upload::pathToUrl($res['thumb_path'])]);
|
||||
}
|
||||
}
|
||||
215
app/admin/controller/setting/SystemMenus.php
Normal file
215
app/admin/controller/setting/SystemMenus.php
Normal file
@ -0,0 +1,215 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\setting;
|
||||
|
||||
use crmeb\services\FormBuilder as Form;
|
||||
use crmeb\traits\CurdControllerTrait;
|
||||
use crmeb\services\UtilService as Util;
|
||||
use crmeb\services\JsonService as Json;
|
||||
use think\facade\Route as Url;
|
||||
use app\admin\model\system\SystemMenus as MenusModel;
|
||||
use app\admin\controller\AuthController;
|
||||
|
||||
/**
|
||||
* 菜单管理控制器
|
||||
* Class SystemMenus
|
||||
* @package app\admin\controller\system
|
||||
*/
|
||||
class SystemMenus extends AuthController
|
||||
{
|
||||
use CurdControllerTrait;
|
||||
|
||||
public $bindModel = MenusModel::class;
|
||||
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$pid = $this->request->param('pid')?$this->request->param('pid'):0;
|
||||
$params = Util::getMore([
|
||||
['is_show',''],
|
||||
// ['access',''],
|
||||
['keyword',''],
|
||||
['pid',$pid]
|
||||
],$this->request);
|
||||
$this->assign(MenusModel::getAdminPage($params));
|
||||
$addurl = Url::buildUrl('create',['cid'=>input('pid')]);
|
||||
$this->assign(compact('params','addurl'));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function create($cid = 0)
|
||||
{
|
||||
$field = [];
|
||||
$field[] = Form::input('menu_name','按钮名称')->required('按钮名称必填');
|
||||
$field[] = Form::select('pid','父级id',$cid)->setOptions(function(){
|
||||
$list = (Util::sortListTier(MenusModel::all(function($m){
|
||||
$m->order('sort DESC,id ASC');
|
||||
})->toArray(),'顶级','pid','menu_name'));
|
||||
$menus = [['value'=>0,'label'=>'顶级按钮']];
|
||||
foreach ($list as $menu){
|
||||
$menus[] = ['value'=>$menu['id'],'label'=>$menu['html'].$menu['menu_name']];
|
||||
}
|
||||
return $menus;
|
||||
})->filterable(1);
|
||||
$field[] = Form::select('module','模块名')->options([['label'=>'总后台','value'=>'admin']]);
|
||||
if($cid)$controller = MenusModel::where('id',$cid)->value('controller')?:'';
|
||||
else $controller = '';
|
||||
$field[] = Form::input('controller','控制器名',$controller);
|
||||
if (!empty($controller))
|
||||
{
|
||||
$controller = preg_replace_callback('/([.]+([a-z]{1}))/i', function ($matches) {
|
||||
return '\\' . strtoupper($matches[2]);
|
||||
}, $controller);
|
||||
if(class_exists('\app\admin\controller\\' . $controller))
|
||||
{
|
||||
$list = get_this_class_methods('\app\admin\controller\\' . $controller);
|
||||
|
||||
$field[] = Form::select('action','方法名')->setOptions(function()use($list){
|
||||
$menus = [['value'=>0,'label'=>'默认函数']];
|
||||
foreach ($list as $menu){
|
||||
$menus[] = ['value'=>$menu,'label'=>$menu];
|
||||
}
|
||||
return $menus;
|
||||
})->filterable(1);
|
||||
}else{
|
||||
$field[] = Form::input('action','方法名');
|
||||
}
|
||||
}else{
|
||||
$field[] = Form::input('action','方法名');
|
||||
}
|
||||
$field[] = Form::input('params','参数')->placeholder('举例:a/123/b/234');
|
||||
$field[] = Form::frameInputOne('icon','图标',Url::buildUrl('admin/widget.widgets/icon',array('fodder'=>'icon')))->icon('ionic')->height('500px');
|
||||
$field[] = Form::number('sort','排序',0);
|
||||
$field[] = Form::radio('is_show','是否菜单',0)->options([['value'=>0,'label'=>'隐藏'],['value'=>1,'label'=>'显示(菜单只显示三级)']]);
|
||||
$form = Form::make_post_form('添加权限',$field,Url::buildUrl('save'),3);
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'menu_name',
|
||||
'controller',
|
||||
['module','admin'],
|
||||
'action',
|
||||
'icon',
|
||||
'params',
|
||||
['pid',0],
|
||||
['sort',0],
|
||||
['is_show',0],
|
||||
['access',1]]);
|
||||
if(!$data['menu_name']) return Json::fail('请输入按钮名称');
|
||||
MenusModel::create($data);
|
||||
return Json::successful('添加菜单成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$menu = MenusModel::get($id);
|
||||
if (!$menu) return Json::fail('数据不存在!');
|
||||
$field = array();
|
||||
$field[] = Form::input('menu_name','按钮名称',$menu['menu_name']);
|
||||
$field[] = Form::select('pid','父级id',(string)$menu->getData('pid'))->setOptions(function()use($id){
|
||||
$list = (Util::sortListTier(MenusModel::all(function($m){
|
||||
$m->order('sort DESC,id ASC');
|
||||
})->toArray(),'顶级','pid','menu_name'));
|
||||
$menus = [['value'=>0,'label'=>'顶级按钮']];
|
||||
foreach ($list as $menu){
|
||||
$menus[] = ['value'=>$menu['id'],'label'=>$menu['html'].$menu['menu_name']];
|
||||
}
|
||||
return $menus;
|
||||
})->filterable(1);
|
||||
$field[] = Form::select('module','模块名',$menu['module'])->options([['label'=>'总后台','value'=>'admin']]);
|
||||
$field[] = Form::input('controller','控制器名',$menu['controller']);
|
||||
if (!empty($menu['controller']))
|
||||
{
|
||||
$controller = preg_replace_callback('/([.]+([a-z]{1}))/i', function ($matches) {
|
||||
return '\\' . strtoupper($matches[2]);
|
||||
}, $menu['controller']);
|
||||
if(class_exists('\app\admin\controller\\' . $controller))
|
||||
{
|
||||
$list = get_this_class_methods('\app\admin\controller\\' . $controller);
|
||||
|
||||
$field[] = Form::select('action','方法名',(string)$menu->getData('action'))->setOptions(function()use($list){
|
||||
$menus = [['value'=>0,'label'=>'默认函数']];
|
||||
foreach ($list as $menu){
|
||||
$menus[] = ['value'=>$menu,'label'=>$menu];
|
||||
}
|
||||
return $menus;
|
||||
})->filterable(1);
|
||||
}else{
|
||||
$field[] = Form::input('action','方法名',$menu['action']);
|
||||
}
|
||||
}else{
|
||||
$field[] = Form::input('action','方法名');
|
||||
}
|
||||
$field[] = Form::input('params','参数',MenusModel::paramStr($menu['params']))->placeholder('举例:a/123/b/234');
|
||||
$field[] = Form::frameInputOne('icon','图标',Url::buildUrl('admin/widget.widgets/icon',array('fodder'=>'icon')),$menu['icon'])->icon('ionic')->height('500px');
|
||||
$field[] = Form::number('sort','排序',$menu['sort']);
|
||||
$field[] = Form::radio('is_show','是否菜单',$menu['is_show'])->options([['value'=>0,'label'=>'隐藏'],['value'=>1,'label'=>'显示(菜单只显示三级)']]);
|
||||
$form = Form::make_post_form('添加权限',$field,Url::buildUrl('update',array('id'=>$id)),3);
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存更新的资源
|
||||
*
|
||||
* @param $id
|
||||
*/
|
||||
public function update($id)
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'menu_name',
|
||||
'controller',
|
||||
['module','admin'],
|
||||
'action',
|
||||
'params',
|
||||
'icon',
|
||||
['sort',0],
|
||||
['pid',0],
|
||||
['is_show',0],
|
||||
['access',1]]);
|
||||
if(!$data['menu_name']) return Json::fail('请输入按钮名称');
|
||||
if(!MenusModel::get($id)) return Json::fail('编辑的记录不存在!');
|
||||
MenusModel::edit($data,$id);
|
||||
return Json::successful('修改成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
if(!$id) return $this->failed('参数错误,请重新打开');
|
||||
$res = MenusModel::delMenu($id);
|
||||
if(!$res)
|
||||
return Json::fail(MenusModel::getErrorInfo('删除失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('删除成功!');
|
||||
}
|
||||
|
||||
}
|
||||
126
app/admin/controller/setting/SystemNotice.php
Normal file
126
app/admin/controller/setting/SystemNotice.php
Normal file
@ -0,0 +1,126 @@
|
||||
<?php
|
||||
namespace app\admin\controller\setting;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use crmeb\services\FormBuilder as Form;
|
||||
use app\admin\model\system\SystemAdmin;
|
||||
use app\admin\model\system\SystemNotice as NoticeModel;
|
||||
use crmeb\services\JsonService;
|
||||
use crmeb\services\UtilService;
|
||||
use think\facade\Route as Url;
|
||||
/**
|
||||
* 管理员消息通知 控制器
|
||||
* Class SystemNotice
|
||||
* @package app\admin\controller\system
|
||||
*/
|
||||
class SystemNotice extends AuthController
|
||||
{
|
||||
public function index(){
|
||||
$this->assign(NoticeModel::page(function($notice){
|
||||
$notice->push_admin_name = !empty($notice->push_admin) ? implode(',',SystemAdmin::where('id','IN',$notice->push_admin)->column('real_name','real_name')) : '';
|
||||
}));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$f = array();
|
||||
$f[] = Form::input('title','通知标题');
|
||||
$f[] = Form::input('type','通知类型');
|
||||
$f[] = Form::frameInputOne('icon','图标',Url::buildUrl('admin/widget.widgets/icon',array('fodder'=>'icon')))->icon('ionic')->height('500px');
|
||||
$f[] = Form::input('template','通知模板');
|
||||
$f[] = Form::input('table_title','通知数据')->type('textarea')->placeholder('数据1-key1,数据2-key2');
|
||||
$f[] = Form::select('push_admin','通知管理员')->setOptions(function(){
|
||||
$list = SystemAdmin::getOrdAdmin('real_name,id')?:[];
|
||||
$options = [];
|
||||
foreach ($list as $admin){
|
||||
$options[] = ['label'=>$admin['real_name'],'value'=>$admin['id']];
|
||||
}
|
||||
return $options;
|
||||
})->multiple(1);
|
||||
$f[] = Form::radio('status','状态',1)->options([['label'=>'开启','value'=>1],['label'=>'关闭','value'=>0]]);
|
||||
$form = Form::make_post_form('添加通知模板',$f,Url::buildUrl('save'));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
public function save()
|
||||
{
|
||||
$data = UtilService::postMore([
|
||||
'title', 'type', 'icon', 'template','table_title',
|
||||
['push_admin', []], ['status', 0]
|
||||
]);
|
||||
$data['push_admin'] = array_unique(array_filter($data['push_admin']));
|
||||
if (!$data['template']) return $this->failed('请填写通知模板');
|
||||
if (!$data['title']) return $this->failed('请输入模板标题');
|
||||
if (!$data['type']) return $this->failed('请输入模板类型');
|
||||
if (NoticeModel::create($data))
|
||||
return $this->successful('添加通知成功');
|
||||
else
|
||||
return $this->failed('添加失败!');
|
||||
}
|
||||
|
||||
/**编辑通知模板
|
||||
* @param $id
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$data = NoticeModel::get($id);
|
||||
if(!$data) return JsonService::fail('数据不存在!');
|
||||
$data->tableTitle = implode(',',array_map(function($value){
|
||||
return $value['title'].'-'.$value['key'];
|
||||
},$data->table_title));
|
||||
$data->tableTitleStr = implode(',',array_map(function($value){
|
||||
return $value['title'].'-'.$value['key'];
|
||||
},$data->table_title));
|
||||
$f = array();
|
||||
$f[] = Form::input('title','通知标题',$data->title);
|
||||
$f[] = Form::input('type','通知类型',$data->type);
|
||||
$f[] = Form::frameInputOne('icon','图标',Url::buildUrl('admin/widget.widgets/icon',array('fodder'=>'icon')),$data->icon)->icon('ionic')->height('500px');
|
||||
$f[] = Form::input('template','通知模板',$data->template);
|
||||
$f[] = Form::input('table_title','通知数据',$data->tableTitleStr)->type('textarea')->placeholder('数据1-key1,数据2-key2');
|
||||
$f[] = Form::select('push_admin','通知管理员',$data->push_admin)->setOptions(function(){
|
||||
$list = SystemAdmin::getOrdAdmin('real_name,id')?:[];
|
||||
$options = [];
|
||||
foreach ($list as $admin){
|
||||
$options[] = ['label'=>$admin['real_name'],'value'=>$admin['id']];
|
||||
}
|
||||
return $options;
|
||||
})->multiple(1);
|
||||
$f[] = Form::radio('status','状态',$data->status)->options([['label'=>'开启','value'=>1],['label'=>'关闭','value'=>0]]);
|
||||
$form = Form::make_post_form('编辑通知模板',$f,Url::buildUrl('update',array('id'=>$id)));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
public function update($id)
|
||||
{
|
||||
$data = UtilService::postMore([
|
||||
'title','type','icon','template','table_title',
|
||||
['push_admin',[]],['status',0]
|
||||
]);
|
||||
$data['push_admin'] = array_unique(array_filter($data['push_admin']));
|
||||
if(!$data['template']) return $this->failed('请填写通知模板');
|
||||
if(!$data['title']) return $this->failed('请输入模板标题');
|
||||
if(!$data['type']) return $this->failed('请输入模板类型');
|
||||
NoticeModel::edit($data,$id);
|
||||
return $this->successful('修改成功!');
|
||||
}
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
$res = NoticeModel::del($id);
|
||||
if(!$res)
|
||||
return $this->failed(('删除失败,请稍候再试!'));
|
||||
else
|
||||
return $this->successful('删除成功!');
|
||||
}
|
||||
public function message($type = 'all')
|
||||
{
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
144
app/admin/controller/setting/SystemRole.php
Normal file
144
app/admin/controller/setting/SystemRole.php
Normal file
@ -0,0 +1,144 @@
|
||||
<?php
|
||||
namespace app\admin\controller\setting;
|
||||
|
||||
use app\admin\model\system\SystemMenus;
|
||||
use crmeb\services\UtilService as Util;
|
||||
use crmeb\services\JsonService as Json;
|
||||
use think\facade\Route as Url;
|
||||
use app\admin\model\system\SystemRole as RoleModel;
|
||||
use app\admin\controller\AuthController;
|
||||
|
||||
/**
|
||||
* 身份管理 控制器
|
||||
* Class SystemRole
|
||||
* @package app\admin\controller\setting
|
||||
*/
|
||||
class SystemRole extends AuthController
|
||||
{
|
||||
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$where = Util::getMore([
|
||||
['status',''],
|
||||
['role_name',''],
|
||||
],$this->request);
|
||||
$where['level'] = $this->adminInfo['level'];
|
||||
$this->assign('where',$where);
|
||||
$this->assign(RoleModel::systemPage($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
|
||||
// if(0 == 0){
|
||||
// }else{
|
||||
// dump($this->adminInfo['level']);
|
||||
// }
|
||||
$menus = $this->adminInfo['level'] == 0 ? SystemMenus::ruleList() : SystemMenus::rolesByRuleList($this->adminInfo['roles']);
|
||||
$this->assign(['menus'=>json($menus)->getContent(),'saveUrl'=>Url::buildUrl('save')]);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'role_name',
|
||||
['status',0],
|
||||
['checked_menus',[],'','rules']
|
||||
]);
|
||||
if(!$data['role_name']) return Json::fail('请输入身份名称');
|
||||
if(!is_array($data['rules']) || !count($data['rules']) )
|
||||
return Json::fail('请选择最少一个权限');
|
||||
foreach ($data['rules'] as $v){
|
||||
$pid = SystemMenus::where('id',$v)->value('pid');
|
||||
if(!in_array($pid,$data['rules'])) $data['rules'][] = $pid;
|
||||
}
|
||||
$data['rules'] = implode(',',$data['rules']);
|
||||
$data['level'] = $this->adminInfo['level']+1;
|
||||
if(!RoleModel::create($data)) return Json::fail('添加身份失败!');
|
||||
return Json::successful('添加身份成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示指定的资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function read($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
//
|
||||
$role = RoleModel::get($id);
|
||||
$menus = $this->adminInfo['level'] == 0 ? SystemMenus::ruleList() : SystemMenus::rolesByRuleList($this->adminInfo['roles']);
|
||||
$this->assign(['role'=>$role->toJson(),'menus'=>json($menus)->getContent(),'updateUrl'=>Url::buildUrl('update',array('id'=>$id))]);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存更新的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function update($id)
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'role_name',
|
||||
['status',0],
|
||||
['checked_menus',[],'','rules']
|
||||
]);
|
||||
if(!$data['role_name']) return Json::fail('请输入身份名称');
|
||||
if(!is_array($data['rules']) || !count($data['rules']) )
|
||||
return Json::fail('请选择最少一个权限');
|
||||
foreach ($data['rules'] as $v){
|
||||
$pid = SystemMenus::where('id',$v)->value('pid');
|
||||
if(!in_array($pid,$data['rules'])) $data['rules'][] = $pid;
|
||||
}
|
||||
$data['rules'] = implode(',',$data['rules']);
|
||||
if(!RoleModel::edit($data,$id)) return Json::fail('修改失败!');
|
||||
return Json::successful('修改成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
if(!RoleModel::del($id))
|
||||
return Json::fail(RoleModel::getErrorInfo('删除失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('删除成功!');
|
||||
}
|
||||
}
|
||||
64
app/admin/controller/sms/SmsAdmin.php
Normal file
64
app/admin/controller/sms/SmsAdmin.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\sms;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use app\admin\model\system\SystemConfig;
|
||||
use crmeb\services\HttpService;
|
||||
use crmeb\services\JsonService;
|
||||
use crmeb\services\SMSService;
|
||||
use crmeb\services\UtilService;
|
||||
|
||||
/**
|
||||
* 短信账号
|
||||
* Class SmsAdmin
|
||||
* @package app\admin\controller\sms
|
||||
*/
|
||||
class SmsAdmin extends AuthController
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function captcha()
|
||||
{
|
||||
if (!request()->isPost()) return JsonService::fail('发生失败');
|
||||
$phone = request()->param('phone');
|
||||
if (!trim($phone)) return JsonService::fail('请填写手机号');
|
||||
|
||||
$res = json_decode(HttpService::getRequest(SMSService::code(), compact('phone')), true);
|
||||
if (!isset($res['status']) && $res['status'] !== 200)
|
||||
return JsonService::fail(isset($res['data']['message']) ? $res['data']['message'] : $res['msg']);
|
||||
return JsonService::success(isset($res['data']['message']) ? $res['data']['message'] : $res['msg']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改/注册短信平台账号
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
list($account, $password, $phone, $code, $url, $sign) = UtilService::postMore([
|
||||
['account', ''],
|
||||
['password', ''],
|
||||
['phone', ''],
|
||||
['code', ''],
|
||||
['url', ''],
|
||||
['sign', ''],
|
||||
], null, true);
|
||||
$signLen = mb_strlen(trim($sign));
|
||||
if (!strlen(trim($account))) return JsonService::fail('请填写账号');
|
||||
if (!strlen(trim($password))) return JsonService::fail('请填写密码');
|
||||
if (!$signLen) return JsonService::fail('请填写短信签名');
|
||||
if ($signLen > 8) return JsonService::fail('短信签名最长为8位');
|
||||
if (!strlen(trim($code))) return JsonService::fail('请填写验证码');
|
||||
if (!strlen(trim($url))) return JsonService::fail('请填写域名');
|
||||
$status = SMSService::register($account, md5(trim($password)), $url, $phone, $code, $sign);
|
||||
if ($status['status'] == 400) return JsonService::fail('短信平台:' . $status['msg']);
|
||||
SystemConfig::setConfigSmsInfo($account, $password);
|
||||
return JsonService::success('短信平台:' . $status['msg']);
|
||||
}
|
||||
}
|
||||
155
app/admin/controller/sms/SmsConfig.php
Normal file
155
app/admin/controller/sms/SmsConfig.php
Normal file
@ -0,0 +1,155 @@
|
||||
<?php
|
||||
namespace app\admin\controller\sms;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use crmeb\services\FormBuilder;
|
||||
use think\facade\Route;
|
||||
use app\admin\model\system\SystemConfig as ConfigModel;
|
||||
/**
|
||||
* 短信配置
|
||||
* Class SmsConfig
|
||||
* @package app\admin\controller\sms
|
||||
*/
|
||||
class SmsConfig extends AuthController
|
||||
{
|
||||
/**
|
||||
* 展示配置
|
||||
* @return string
|
||||
* @throws \FormBuilder\exception\FormBuilderException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function index(){
|
||||
$type = input('type')!=0?input('type'):0;
|
||||
$tab_id = input('tab_id');
|
||||
if(!$tab_id) $tab_id = 1;
|
||||
$this->assign('tab_id',$tab_id);
|
||||
$list = ConfigModel::getAll($tab_id);
|
||||
if($type==3){//其它分类
|
||||
$config_tab = null;
|
||||
}else{
|
||||
$config_tab = ConfigModel::getConfigTabAll($type);
|
||||
foreach ($config_tab as $kk=>$vv){
|
||||
$arr = ConfigModel::getAll($vv['value'])->toArray();
|
||||
if(empty($arr)){
|
||||
unset($config_tab[$kk]);
|
||||
}
|
||||
}
|
||||
}
|
||||
$formBuilder = [];
|
||||
foreach ($list as $data){
|
||||
switch ($data['type']){
|
||||
case 'text'://文本框
|
||||
switch ($data['input_type']){
|
||||
case 'input':
|
||||
$data['value'] = json_decode($data['value'],true)?:'';
|
||||
$formBuilder[] = FormBuilder::input($data['menu_name'],$data['info'],$data['value'])->info($data['desc'])->placeholder($data['desc'])->col(13);
|
||||
break;
|
||||
case 'number':
|
||||
$data['value'] = json_decode($data['value'],true)?:0;
|
||||
$formBuilder[] = FormBuilder::number($data['menu_name'],$data['info'],$data['value'])->info($data['desc']);
|
||||
break;
|
||||
case 'dateTime':
|
||||
$formBuilder[] = FormBuilder::dateTime($data['menu_name'],$data['info'],$data['value'])->info($data['desc']);
|
||||
break;
|
||||
case 'color':
|
||||
$data['value'] = json_decode($data['value'],true)?:'';
|
||||
$formBuilder[] = FormBuilder::color($data['menu_name'],$data['info'],$data['value'])->info($data['desc']);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'textarea'://多行文本框
|
||||
$data['value'] = json_decode($data['value'],true)?:'';
|
||||
$formBuilder[] = FormBuilder::textarea($data['menu_name'],$data['info'],$data['value'])->placeholder($data['desc'])->info($data['desc']);
|
||||
break;
|
||||
case 'radio'://单选框
|
||||
$data['value'] = json_decode($data['value'],true)?:'0';
|
||||
$parameter = explode("\n",$data['parameter']);
|
||||
$options = [];
|
||||
if($parameter) {
|
||||
foreach ($parameter as $v) {
|
||||
$pdata = explode("=>", $v);
|
||||
$options[] = ['label' => $pdata[1], 'value' => $pdata[0]];
|
||||
}
|
||||
$formBuilder[] = FormBuilder::radio($data['menu_name'],$data['info'],$data['value'])->options($options)->info($data['desc']);
|
||||
}
|
||||
break;
|
||||
case 'upload'://文件上传
|
||||
switch ($data['upload_type']){
|
||||
case 1:
|
||||
$data['value'] = json_decode($data['value'],true)?:'';
|
||||
$formBuilder[] = FormBuilder::frameImageOne($data['menu_name'],$data['info'],Url::buildUrl('admin/widget.images/index',array('fodder'=>$data['menu_name'])),$data['value'])->icon('image')->width('100%')->height('500px')->info($data['desc']);
|
||||
break;
|
||||
case 2:
|
||||
$data['value'] = json_decode($data['value'],true)?:[];
|
||||
$formBuilder[] = FormBuilder::frameImages($data['menu_name'],$data['info'],Url::buildUrl('admin/widget.images/index',array('fodder'=>$data['menu_name'])),$data['value'])->maxLength(5)->icon('image')->width('100%')->height('500px')->info($data['desc']);
|
||||
break;
|
||||
case 3:
|
||||
$data['value'] = json_decode($data['value'],true);
|
||||
$formBuilder[] = FormBuilder::uploadFileOne($data['menu_name'],$data['info'],Url::buildUrl('file_upload'),$data['value'])->name('file')->info($data['desc']);
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
case 'checkbox'://多选框
|
||||
$data['value'] = json_decode($data['value'],true)?:[];
|
||||
$parameter = explode("\n",$data['parameter']);
|
||||
$options = [];
|
||||
if($parameter) {
|
||||
foreach ($parameter as $v) {
|
||||
$pdata = explode("=>", $v);
|
||||
$options[] = ['label' => $pdata[1], 'value' => $pdata[0]];
|
||||
}
|
||||
$formBuilder[] = FormBuilder::checkbox($data['menu_name'],$data['info'],$data['value'])->options($options)->info($data['desc']);
|
||||
}
|
||||
break;
|
||||
case 'select'://多选框
|
||||
$data['value'] = json_decode($data['value'],true)?:[];
|
||||
$parameter = explode("\n",$data['parameter']);
|
||||
$options = [];
|
||||
if($parameter) {
|
||||
foreach ($parameter as $v) {
|
||||
$pdata = explode("=>", $v);
|
||||
$options[] = ['label' => $pdata[1], 'value' => $pdata[0]];
|
||||
}
|
||||
$formBuilder[] = FormBuilder::select($data['menu_name'],$data['info'],$data['value'])->options($options)->info($data['desc']);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$form = FormBuilder::make_post_form('编辑配置',$formBuilder,Route::buildUrl('save_basics'));
|
||||
$this->assign(compact('form'));
|
||||
$this->assign('config_tab',$config_tab);
|
||||
$this->assign('list',$list);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存配置
|
||||
*/
|
||||
public function save_basics()
|
||||
{
|
||||
$request = app('request');
|
||||
if($request->isPost()){
|
||||
$post = $request->post();
|
||||
foreach ($post as $k=>$v){
|
||||
if(is_array($v)){
|
||||
$res = ConfigModel::where('menu_name',$k)->column('upload_type','type');
|
||||
foreach ($res as $kk=>$vv){
|
||||
if($kk == 'upload'){
|
||||
if($vv == 1 || $vv == 3){
|
||||
$post[$k] = $v[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($post as $k=>$v){
|
||||
ConfigModel::edit(['value' => json_encode($v)],$k,'menu_name');
|
||||
}
|
||||
return $this->successful('修改成功');
|
||||
}
|
||||
}
|
||||
}
|
||||
206
app/admin/controller/sms/SmsPay.php
Normal file
206
app/admin/controller/sms/SmsPay.php
Normal file
@ -0,0 +1,206 @@
|
||||
<?php
|
||||
namespace app\admin\controller\sms;
|
||||
|
||||
use crmeb\services\SMSService;
|
||||
use think\facade\Route;
|
||||
use app\admin\controller\AuthController;
|
||||
use crmeb\services\FormBuilder;
|
||||
use crmeb\services\JsonService;
|
||||
use crmeb\services\UtilService;
|
||||
|
||||
/**
|
||||
* 短信购买
|
||||
* Class SmsPay
|
||||
* @package app\admin\controller\sms
|
||||
*/
|
||||
class SmsPay extends AuthController
|
||||
{
|
||||
/**
|
||||
* 显示资源列表
|
||||
* @return string
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$sms = new SMSService();
|
||||
if(!$sms::$status) return $this->failed('请先填写短信配置');
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取账号信息
|
||||
*/
|
||||
public function number()
|
||||
{
|
||||
$countInfo = SMSService::count();
|
||||
if($countInfo['status'] == 400) return JsonService::fail($countInfo['msg']);
|
||||
return JsonService::success($countInfo['data']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取支付套餐
|
||||
*/
|
||||
public function price()
|
||||
{
|
||||
list($page, $limit) = UtilService::getMore([
|
||||
['page',1],
|
||||
['limit',20],
|
||||
], null, true);
|
||||
$mealInfo = SMSService::meal($page, $limit);
|
||||
if($mealInfo['status'] == 400) return JsonService::fail($mealInfo['msg']);
|
||||
return JsonService::success($mealInfo['data']['data']);
|
||||
}
|
||||
/**
|
||||
* 获取支付码
|
||||
*/
|
||||
public function pay()
|
||||
{
|
||||
list($payType, $mealId, $price)= UtilService::postMore([
|
||||
['payType', 'weixin'],
|
||||
['mealId', 0],
|
||||
['price', 0],
|
||||
], null, true);
|
||||
$payInfo = SMSService::pay($payType, $mealId, $price, $this->adminId);
|
||||
if($payInfo['status'] == 400) return JsonService::fail($payInfo['msg']);
|
||||
return JsonService::success($payInfo['data']);
|
||||
}
|
||||
|
||||
public function meal()
|
||||
{
|
||||
$this->assign('badge',SmsMeal::reckonNumber());
|
||||
return $this->fetch();
|
||||
}
|
||||
/*
|
||||
* 异步获取分类列表
|
||||
* @return json
|
||||
*/
|
||||
public function meal_list(){
|
||||
$where = UtilService::getMore([
|
||||
['is_show',''],
|
||||
['title',''],
|
||||
['page',1],
|
||||
['limit',20],
|
||||
['order','']
|
||||
]);
|
||||
return JsonService::successlayui(SmsMeal::lst($where));
|
||||
}
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
*
|
||||
* @return string
|
||||
* @throws \FormBuilder\exception\FormBuilderException
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$field = [
|
||||
FormBuilder::input('title','套餐名称'),
|
||||
FormBuilder::number('price','套餐价格',0)->min(0),
|
||||
FormBuilder::number('num','短信条数',0)->min(0),
|
||||
FormBuilder::datePicker('end_time','使用期限',0),
|
||||
FormBuilder::radio('is_show','是否可用',1)->options([['label'=>'可用','value'=>1],['label'=>'不可用','value'=>0]])
|
||||
];
|
||||
$form = FormBuilder::make_post_form('添加短信套餐',$field,Route::buildUrl('save'),2);
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
$data = UtilService::postMore([
|
||||
['title',''],
|
||||
['price',''],
|
||||
['num',''],
|
||||
['end_time',''],
|
||||
['is_show',1],
|
||||
]);
|
||||
if(!strlen(trim($data['title']))) return JsonService::fail('请输入套餐名称');
|
||||
if(!strlen(trim($data['price']))) return JsonService::fail('请输入套餐价格');
|
||||
if(!strlen(trim($data['num']))) return JsonService::fail('请输入短信条数');
|
||||
$data['end_time'] = strtotime($data['end_time']);
|
||||
$data['add_time'] = time();
|
||||
$res = SmsMeal::create($data);
|
||||
if($res)
|
||||
return JsonService::successful('添加成功');
|
||||
return JsonService::fail('添加失败');
|
||||
}
|
||||
/**
|
||||
* 设置单个产品上架|下架
|
||||
* @param string $is_show
|
||||
* @param string $id
|
||||
*/
|
||||
public function set_show($is_show='',$id=''){
|
||||
($is_show=='' || $id=='') && JsonService::fail('缺少参数');
|
||||
$res=SmsMeal::where('id', $id)->update(['is_show'=>(int)$is_show]);
|
||||
if($res){
|
||||
return JsonService::successful($is_show==1 ? '显示成功':'隐藏成功');
|
||||
}else{
|
||||
return JsonService::fail($is_show==1 ? '显示失败':'隐藏失败');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
* @param $id
|
||||
* @return string|void
|
||||
* @throws \FormBuilder\exception\FormBuilderException
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$adminInfo = SmsMeal::get($id);
|
||||
if(!$adminInfo) return $this->failed('数据不存在!');
|
||||
$field = [
|
||||
FormBuilder::input('title','账号', $adminInfo->getData('title'))->disabled(true),
|
||||
FormBuilder::number('price','短信条数', $adminInfo->getData('price'))->min(0),
|
||||
FormBuilder::number('num','短信条数', $adminInfo->getData('num'))->min(0),
|
||||
FormBuilder::datePicker('end_time','使用期限',date('Y-m-d H:i',$adminInfo->getData('end_time'))),
|
||||
FormBuilder::radio('is_show','是否可用', $adminInfo->getData('is_show'))->options([['label'=>'可用','value'=>1],['label'=>'不可用','value'=>0]])
|
||||
];
|
||||
$form = FormBuilder::make_post_form('编辑短信套餐',$field,Route::buildUrl('update',array('id'=>$id)),2);
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存更新的资源
|
||||
* @param \think\Request $request
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function update($id)
|
||||
{
|
||||
$adminInfo = SmsAdminModel::get($id);
|
||||
if(!$adminInfo) return $this->failed('数据不存在!');
|
||||
$data = Util::postMore([
|
||||
['title',''],
|
||||
['price',''],
|
||||
['num',''],
|
||||
['end_time',''],
|
||||
['is_show',1],
|
||||
]);
|
||||
if(!strlen(trim($data['title']))) return JsonService::fail('请输入套餐名称');
|
||||
if(!strlen(trim($data['price']))) return JsonService::fail('请输入套餐价格');
|
||||
if(!strlen(trim($data['num']))) return JsonService::fail('请输入短信条数');
|
||||
$data['end_time'] = strtotime($data['end_time']);
|
||||
$data['add_time'] = time();
|
||||
$res = SmsMeal::edit($data, $id);
|
||||
if($res)
|
||||
return JsonService::successful('修改成功');
|
||||
return JsonService::fail('修改失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
* @param $id
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
$smsAdmin = SmsMeal::get($id);
|
||||
if(!$smsAdmin) return JsonService::fail('数据不存在!');
|
||||
if($smsAdmin['is_del']) return JsonService::fail('已删除');
|
||||
if(SmsMeal::del($id)){
|
||||
return JsonService::successful('删除成功');
|
||||
}
|
||||
return JsonService::fail('删除失败');
|
||||
}
|
||||
|
||||
}
|
||||
56
app/admin/controller/sms/SmsPublicTemp.php
Normal file
56
app/admin/controller/sms/SmsPublicTemp.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
namespace app\admin\controller\sms;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use crmeb\services\JsonService;
|
||||
use crmeb\services\SMSService;
|
||||
use crmeb\services\UtilService;
|
||||
|
||||
/**
|
||||
* 公共短信模板
|
||||
* Class SmsPublicTemp
|
||||
* @package app\admin\controller\sms
|
||||
*/
|
||||
class SmsPublicTemp extends AuthController
|
||||
{
|
||||
|
||||
public function index()
|
||||
{
|
||||
$sms = new SMSService();
|
||||
if(!$sms::$status) return $this->failed('请先填写短信配置');
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步获取公共模板列表
|
||||
*/
|
||||
public function lst()
|
||||
{
|
||||
$where = UtilService::getMore([
|
||||
['is_have',''],
|
||||
['page',1],
|
||||
['limit',20],
|
||||
]);
|
||||
$templateList = SMSService::publictemp($where);
|
||||
if($templateList['status'] == 400) return JsonService::fail($templateList['msg']);
|
||||
return JsonService::successlayui($templateList['data']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加公共短信模板
|
||||
*/
|
||||
public function status()
|
||||
{
|
||||
list($id, $tempId) = UtilService::postMore([
|
||||
['id', 0],
|
||||
['tempId', 0]
|
||||
], null, true);
|
||||
if(!(int)$id) return JsonService::fail('参数错误');
|
||||
if(!strlen(trim($tempId))) return JsonService::fail('参数错误');
|
||||
$useStatus = SMSService::use($id, $tempId);
|
||||
if($useStatus['status'] == 400) return JsonService::fail($useStatus['msg']);
|
||||
return JsonService::success($useStatus['msg']);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
80
app/admin/controller/sms/SmsTemplateApply.php
Normal file
80
app/admin/controller/sms/SmsTemplateApply.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
namespace app\admin\controller\sms;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use crmeb\services\FormBuilder;
|
||||
use crmeb\services\JsonService;
|
||||
use crmeb\services\SMSService;
|
||||
use crmeb\services\UtilService;
|
||||
use think\facade\Route;
|
||||
|
||||
/**
|
||||
* 短信模板申请
|
||||
* Class SmsTemplateApply
|
||||
* @package app\admin\controller\sms
|
||||
*/
|
||||
class SmsTemplateApply extends AuthController
|
||||
{
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$sms = new SMSService();
|
||||
if(!$sms::$status) return $this->failed('请先填写短信配置');
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步获取模板列表
|
||||
*/
|
||||
public function lst()
|
||||
{
|
||||
$where = UtilService::getMore([
|
||||
['status',''],
|
||||
['title',''],
|
||||
['page',1],
|
||||
['limit',20],
|
||||
]);
|
||||
$templateList = SMSService::template($where);
|
||||
if($templateList['status'] == 400) return JsonService::fail($templateList['msg']);
|
||||
return JsonService::successlayui($templateList['data']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
*
|
||||
* @return string
|
||||
* @throws \FormBuilder\exception\FormBuilderException
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$field = [
|
||||
FormBuilder::input('title','模板名称'),
|
||||
FormBuilder::input('content','模板内容')->type('textarea'),
|
||||
FormBuilder::radio('type','模板类型',1)->options([['label'=>'验证码','value'=>1],['label'=>'通知','value'=>2],['label'=>'推广','value'=>3]])
|
||||
];
|
||||
$form = FormBuilder::make_post_form('申请短信模板',$field,Route::buildUrl('save'),2);
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
$data = UtilService::postMore([
|
||||
['title',''],
|
||||
['content',''],
|
||||
['type',0]
|
||||
]);
|
||||
if(!strlen(trim($data['title']))) return JsonService::fail('请输入模板名称');
|
||||
if(!strlen(trim($data['content']))) return JsonService::fail('请输入模板内容');
|
||||
$applyStatus = SMSService::apply($data['title'], $data['content'], $data['type']);
|
||||
if($applyStatus['status'] == 400) return JsonService::fail($applyStatus['msg']);
|
||||
return JsonService::success('申请成功');
|
||||
}
|
||||
}
|
||||
873
app/admin/controller/store/CopyTaobao.php
Normal file
873
app/admin/controller/store/CopyTaobao.php
Normal file
@ -0,0 +1,873 @@
|
||||
<?php
|
||||
/**
|
||||
* Project: 快速复制 淘宝、天猫、1688、京东 商品到CRMEB系统
|
||||
* Author: 有一片天 <810806442@qq.com> 微信:szktor
|
||||
* Date: 2019-04-25
|
||||
*/
|
||||
|
||||
namespace app\admin\controller\store;
|
||||
|
||||
use crmeb\services\HttpService;
|
||||
use crmeb\services\UploadService;
|
||||
use think\exception\PDOException;
|
||||
use app\admin\controller\AuthController;
|
||||
use app\admin\model\system\SystemConfig;
|
||||
use crmeb\traits\CurdControllerTrait;
|
||||
use crmeb\services\JsonService;
|
||||
use crmeb\services\UtilService;
|
||||
use app\admin\model\store\StoreCategory as CategoryModel;
|
||||
use app\admin\model\store\StoreProduct as ProductModel;
|
||||
use app\admin\model\system\SystemAttachment;
|
||||
use app\admin\model\system\SystemAttachmentCategory;
|
||||
|
||||
/**
|
||||
* 产品管理
|
||||
* Class StoreProduct
|
||||
* @package app\admin\controller\store
|
||||
*/
|
||||
class CopyTaobao extends AuthController
|
||||
{
|
||||
|
||||
use CurdControllerTrait;
|
||||
|
||||
protected $bindModel = ProductModel::class;
|
||||
//错误信息
|
||||
protected $errorInfo = true;
|
||||
//产品默认字段
|
||||
protected $productInfo = [
|
||||
'cate_id' => '',
|
||||
'store_name' => '',
|
||||
'store_info' => '',
|
||||
'unit_name' => '件',
|
||||
'price' => 0,
|
||||
'keyword' => '',
|
||||
'ficti' => 0,
|
||||
'ot_price' => 0,
|
||||
'give_integral' => 0,
|
||||
'postage' => 0,
|
||||
'cost' => 0,
|
||||
'image' => '',
|
||||
'slider_image' => '',
|
||||
'add_time' => 0,
|
||||
'stock' => 0,
|
||||
'description' => '',
|
||||
'soure_link' => ''
|
||||
];
|
||||
//抓取网站主域名
|
||||
protected $grabName = [
|
||||
'taobao',
|
||||
'1688',
|
||||
'tmall',
|
||||
'jd'
|
||||
];
|
||||
//远程下载附件图片分类名称
|
||||
protected $AttachmentCategoryName = '远程下载';
|
||||
|
||||
/**
|
||||
* 显示资源
|
||||
* @return html
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$list = CategoryModel::getTierList(null, 1);
|
||||
$menus = [];
|
||||
foreach ($list as $menu) {
|
||||
$menus[] = ['value' => $menu['id'], 'label' => $menu['html'] . $menu['cate_name'], 'disabled' => $menu['pid'] == 0];//,'disabled'=>$menu['pid']== 0];
|
||||
}
|
||||
$this->assign('menus', $menus);
|
||||
$this->assign('is_layui', 1);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/*
|
||||
* 设置错误信息
|
||||
* @param string $msg 错误信息
|
||||
* */
|
||||
public function setErrorInfo($msg = '')
|
||||
{
|
||||
$this->errorInfo = $msg;
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* 设置字符串字符集
|
||||
* @param string $str 需要设置字符集的字符串
|
||||
* @return string
|
||||
* */
|
||||
public function Utf8String($str)
|
||||
{
|
||||
$encode = mb_detect_encoding($str, array("ASCII", 'UTF-8', "GB2312", "GBK", 'BIG5'));
|
||||
if (strtoupper($encode) != 'UTF-8') $str = mb_convert_encoding($str, 'utf-8', $encode);
|
||||
return $str;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取资源,并解析出对应的商品参数
|
||||
* @return json
|
||||
*/
|
||||
public function get_request_contents()
|
||||
{
|
||||
list($link) = UtilService::postMore([
|
||||
['link', '']
|
||||
], $this->request, true);
|
||||
$url = $this->checkurl($link);
|
||||
if ($url === false) return JsonService::fail($this->errorInfo);
|
||||
$this->errorInfo = true;
|
||||
$html = $this->curl_Get($url, 60);
|
||||
if (!$html) return JsonService::fail('商品HTML信息获取失败');
|
||||
$html = $this->Utf8String($html);
|
||||
preg_match('/<title>([^<>]*)<\/title>/', $html, $title);
|
||||
//商品标题
|
||||
$this->productInfo['store_name'] = isset($title['1']) ? str_replace(['-淘宝网', '-tmall.com天猫', ' - 阿里巴巴', ' ', '-', '【图片价格品牌报价】京东', '京东', '【行情报价价格评测】'], '', trim($title['1'])) : '';
|
||||
$this->productInfo['store_info'] = $this->productInfo['store_name'];
|
||||
try {
|
||||
//获取url信息
|
||||
$pathinfo = pathinfo($url);
|
||||
if (!isset($pathinfo['dirname'])) return JsonService::fail('解析URL失败');
|
||||
//提取域名
|
||||
$parse_url = parse_url($pathinfo['dirname']);
|
||||
if (!isset($parse_url['host'])) return JsonService::fail('获取域名失败');
|
||||
//获取第一次.出现的位置
|
||||
$strLeng = strpos($parse_url['host'], '.') + 1;
|
||||
//截取域名中的真实域名不带.com后的
|
||||
$funsuffix = substr($parse_url['host'], $strLeng, strrpos($parse_url['host'], '.') - $strLeng);
|
||||
if (!in_array($funsuffix, $this->grabName)) return JsonService::fail('您输入的地址不在复制范围内!');
|
||||
//设拼接设置产品函数
|
||||
$funName = "setProductInfo" . ucfirst($funsuffix);
|
||||
//执行方法
|
||||
if (method_exists($this, $funName))
|
||||
$this->$funName($html);
|
||||
else
|
||||
return JsonService::fail('设置产品函数不存在');
|
||||
if (!$this->productInfo['slider_image']) return JsonService::fail('未能获取到商品信息,请确保商品信息有效!');
|
||||
return JsonService::successful($this->productInfo);
|
||||
} catch (\Exception $e) {
|
||||
return JsonService::fail('系统错误', ['line' => $e->getLine(), 'meass' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 淘宝设置产品
|
||||
* @param string $html 网页内容
|
||||
* */
|
||||
public function setProductInfoTaobao($html)
|
||||
{
|
||||
//获取轮播图
|
||||
$images = $this->getTaobaoImg($html);
|
||||
$images = array_merge($images);
|
||||
$this->productInfo['slider_image'] = isset($images['gaoqing']) ? $images['gaoqing'] : (array)$images;
|
||||
//获取产品详情请求链接
|
||||
$link = $this->getTaobaoDesc($html);
|
||||
//获取请求内容
|
||||
$desc_json = HttpService::getRequest($link);
|
||||
//转换字符集
|
||||
$desc_json = $this->Utf8String($desc_json);
|
||||
//截取掉多余字符
|
||||
$this->productInfo['test'] = $desc_json;
|
||||
$desc_json = str_replace('var desc=\'', '', $desc_json);
|
||||
$desc_json = str_replace(["\n", "\t", "\r"], '', $desc_json);
|
||||
$content = substr($desc_json, 0, -2);
|
||||
$this->productInfo['description'] = $content;
|
||||
//获取详情图
|
||||
$description_images = $this->decodedesc($this->productInfo['description']);
|
||||
$this->productInfo['description_images'] = is_array($description_images) ? $description_images : [];
|
||||
$this->productInfo['image'] = is_array($this->productInfo['slider_image']) && isset($this->productInfo['slider_image'][0]) ? $this->productInfo['slider_image'][0] : '';
|
||||
}
|
||||
|
||||
/*
|
||||
* 天猫设置产品
|
||||
* @param string $html 网页内容
|
||||
* */
|
||||
public function setProductInfoTmall($html)
|
||||
{
|
||||
//获取轮播图
|
||||
$images = $this->getTianMaoImg($html);
|
||||
$images = array_merge($images);
|
||||
$this->productInfo['slider_image'] = $images;
|
||||
$this->productInfo['image'] = is_array($this->productInfo['slider_image']) && isset($this->productInfo['slider_image'][0]) ? $this->productInfo['slider_image'][0] : '';
|
||||
//获取产品详情请求链接
|
||||
$link = $this->getTianMaoDesc($html);
|
||||
//获取请求内容
|
||||
$desc_json = HttpService::getRequest($link);
|
||||
//转换字符集
|
||||
$desc_json = $this->Utf8String($desc_json);
|
||||
//截取掉多余字符
|
||||
$desc_json = str_replace('var desc=\'', '', $desc_json);
|
||||
$desc_json = str_replace(["\n", "\t", "\r"], '', $desc_json);
|
||||
$content = substr($desc_json, 0, -2);
|
||||
$this->productInfo['description'] = $content;
|
||||
//获取详情图
|
||||
$description_images = $this->decodedesc($this->productInfo['description']);
|
||||
$this->productInfo['description_images'] = is_array($description_images) ? $description_images : [];
|
||||
}
|
||||
|
||||
/*
|
||||
* 1688设置产品
|
||||
* @param string $html 网页内容
|
||||
* */
|
||||
public function setProductInfo1688($html)
|
||||
{
|
||||
//获取轮播图
|
||||
$images = $this->get1688Img($html);
|
||||
if (isset($images['gaoqing'])) {
|
||||
$images['gaoqing'] = array_merge($images['gaoqing']);
|
||||
$this->productInfo['slider_image'] = $images['gaoqing'];
|
||||
} else
|
||||
$this->productInfo['slider_image'] = $images;
|
||||
$this->productInfo['image'] = is_array($this->productInfo['slider_image']) && isset($this->productInfo['slider_image'][0]) ? $this->productInfo['slider_image'][0] : '';
|
||||
//获取产品详情请求链接
|
||||
$link = $this->get1688Desc($html);
|
||||
//获取请求内容
|
||||
$desc_json = HttpService::getRequest($link);
|
||||
//转换字符集
|
||||
$desc_json = $this->Utf8String($desc_json);
|
||||
$this->productInfo['test'] = $desc_json;
|
||||
//截取掉多余字符
|
||||
$desc_json = str_replace('var offer_details=', '', $desc_json);
|
||||
$desc_json = str_replace(["\n", "\t", "\r"], '', $desc_json);
|
||||
$desc_json = substr($desc_json, 0, -1);
|
||||
$descArray = json_decode($desc_json, true);
|
||||
if (!isset($descArray['content'])) $descArray['content'] = '';
|
||||
$this->productInfo['description'] = $descArray['content'];
|
||||
//获取详情图
|
||||
$description_images = $this->decodedesc($this->productInfo['description']);
|
||||
$this->productInfo['description_images'] = is_array($description_images) ? $description_images : [];
|
||||
}
|
||||
|
||||
/*
|
||||
* JD设置产品
|
||||
* @param string $html 网页内容
|
||||
* */
|
||||
public function setProductInfoJd($html)
|
||||
{
|
||||
//获取产品详情请求链接
|
||||
$desc_url = $this->getJdDesc($html);
|
||||
//获取请求内容
|
||||
$desc_json = HttpService::getRequest($desc_url);
|
||||
//转换字符集
|
||||
$desc_json = $this->Utf8String($desc_json);
|
||||
//截取掉多余字符
|
||||
if (substr($desc_json, 0, 8) == 'showdesc') $desc_json = str_replace('showdesc', '', $desc_json);
|
||||
$desc_json = str_replace('data-lazyload=', 'src=', $desc_json);
|
||||
$descArray = json_decode($desc_json, true);
|
||||
if (!$descArray) $descArray = ['content' => ''];
|
||||
//获取轮播图
|
||||
$images = $this->getJdImg($html);
|
||||
$images = array_merge($images);
|
||||
$this->productInfo['slider_image'] = $images;
|
||||
$this->productInfo['image'] = is_array($this->productInfo['slider_image']) ? $this->productInfo['slider_image'][0] : '';
|
||||
$this->productInfo['description'] = $descArray['content'];
|
||||
//获取详情图
|
||||
$description_images = $this->decodedesc($descArray['content']);
|
||||
$this->productInfo['description_images'] = is_array($description_images) ? $description_images : [];
|
||||
}
|
||||
|
||||
/*
|
||||
* 检查淘宝,天猫,1688的商品链接
|
||||
* @return string
|
||||
*/
|
||||
public function checkurl($link)
|
||||
{
|
||||
$link = strtolower($link);
|
||||
if (!$link) return $this->setErrorInfo('请输入链接地址');
|
||||
if (substr($link, 0, 4) != 'http') return $this->setErrorInfo('链接地址必须以http开头');
|
||||
$arrLine = explode('?', $link);
|
||||
if (!count($arrLine)) return $this->setErrorInfo('链接地址有误(ERR:1001)');
|
||||
if (!isset($arrLine[1])) {
|
||||
if (strpos($link, '1688') !== false && strpos($link, 'offer') !== false) return trim($arrLine[0]);
|
||||
else if (strpos($link, 'item.jd') !== false) return trim($arrLine[0]);
|
||||
else return $this->setErrorInfo('链接地址有误(ERR:1002)');
|
||||
}
|
||||
if (strpos($link, '1688') !== false && strpos($link, 'offer') !== false) return trim($arrLine[0]);
|
||||
if (strpos($link, 'item.jd') !== false) return trim($arrLine[0]);
|
||||
$arrLineValue = explode('&', $arrLine[1]);
|
||||
if (!is_array($arrLineValue)) return $this->setErrorInfo('链接地址有误(ERR:1003)');
|
||||
if (!strpos(trim($arrLine[0]), 'item.htm')) $this->setErrorInfo('链接地址有误(ERR:1004)');
|
||||
//链接参数
|
||||
$lastStr = '';
|
||||
foreach ($arrLineValue as $k => $v) {
|
||||
if (substr(strtolower($v), 0, 3) == 'id=') {
|
||||
$lastStr = trim($v);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$lastStr) return $this->setErrorInfo('链接地址有误(ERR:1005)');
|
||||
return trim($arrLine[0]) . '?' . $lastStr;
|
||||
}
|
||||
|
||||
/*
|
||||
* 保存图片保存产品信息
|
||||
* */
|
||||
public function save_product()
|
||||
{
|
||||
$data = UtilService::postMore([
|
||||
['cate_id', ''],
|
||||
['store_name', ''],
|
||||
['store_info', ''],
|
||||
['keyword', ''],
|
||||
['unit_name', ''],
|
||||
['image', ''],
|
||||
['slider_image', []],
|
||||
['price', ''],
|
||||
['ot_price', ''],
|
||||
['give_integral', ''],
|
||||
['postage', ''],
|
||||
['sales', ''],
|
||||
['ficti', ''],
|
||||
['stock', ''],
|
||||
['cost', ''],
|
||||
['description_images', []],
|
||||
['description', ''],
|
||||
['is_show', 0],
|
||||
['soure_link', ''],
|
||||
]);
|
||||
if (!$data['cate_id']) return JsonService::fail('请选择分类!');
|
||||
if (!$data['store_name']) return JsonService::fail('请填写产品名称');
|
||||
if (!$data['unit_name']) return JsonService::fail('请填写产品单位');
|
||||
if (!$data['image']) return JsonService::fail('商品主图暂无,无法保存商品,您可选择其他链接进行复制产品');
|
||||
if ($data['price'] == '' || $data['price'] < 0) return JsonService::fail('请输入产品售价');
|
||||
if ($data['ot_price'] == '' || $data['ot_price'] < 0) return JsonService::fail('请输入产品市场价');
|
||||
if ($data['stock'] == '' || $data['stock'] < 0) return JsonService::fail('请输入库存');
|
||||
//查询附件分类
|
||||
$AttachmentCategory = SystemAttachmentCategory::where('name' , $this->AttachmentCategoryName)->find();
|
||||
//不存在则创建
|
||||
if (!$AttachmentCategory) $AttachmentCategory = SystemAttachmentCategory::create(['pid' => '0', 'name' => $this->AttachmentCategoryName, 'enname' => '']);
|
||||
//生成附件目录
|
||||
try{
|
||||
if (make_path('attach', 3) == '') return JsonService::fail('无法创建文件夹,请检查您的上传目录权限:' . app()->getRootPath() . 'public' . DS . 'uploads' . DS. 'attach' . DS);
|
||||
|
||||
}catch (\Exception $e){
|
||||
return JsonService::fail($e->getMessage().'或无法创建文件夹,请检查您的上传目录权限:' . app()->getRootPath() . 'public' . DS . 'uploads' . DS. 'attach' . DS);
|
||||
}
|
||||
ini_set("max_execution_time", 600);
|
||||
//开始图片下载处理
|
||||
ProductModel::beginTrans();
|
||||
try {
|
||||
//放入主图
|
||||
$images = [
|
||||
['w' => 305, 'h' => 305, 'line' => $data['image'], 'valuename' => 'image']
|
||||
];
|
||||
//放入轮播图
|
||||
foreach ($data['slider_image'] as $item) {
|
||||
$value = ['w' => 640, 'h' => 640, 'line' => $item, 'valuename' => 'slider_image', 'isTwoArray' => true];
|
||||
array_push($images, $value);
|
||||
}
|
||||
//执行下载
|
||||
$res = $this->uploadImage($images, false, 0, $AttachmentCategory['id']);
|
||||
if (!is_array($res)) return JsonService::fail($this->errorInfo ? $this->errorInfo : '保存图片失败');
|
||||
if (isset($res['image'])) $data['image'] = $res['image'];
|
||||
if (isset($res['slider_image'])) $data['slider_image'] = $res['slider_image'];
|
||||
$data['slider_image'] = count($data['slider_image']) ? json_encode($data['slider_image']) : '';
|
||||
//替换并下载详情里面的图片默认下载全部图片
|
||||
$data['description'] = preg_replace('#<style>.*?</style>#is', '', $data['description']);
|
||||
$data['description'] = $this->uploadImage($data['description_images'], $data['description'], 1, $AttachmentCategory['id']);
|
||||
unset($data['description_images']);
|
||||
$data['add_time'] = time();
|
||||
$cate_id = explode(',', $data['cate_id']);
|
||||
//产品存在
|
||||
if ($productInfo = ProductModel::where('soure_link', $data['soure_link'])->find()) {
|
||||
$productInfo->description = $data['description'];
|
||||
$productInfo->slider_image = $data['slider_image'];
|
||||
$productInfo->image = $data['image'];
|
||||
$productInfo->store_name = $data['store_name'];
|
||||
$productInfo->save();
|
||||
ProductModel::commitTrans();
|
||||
return JsonService::successful('商品存在,信息已被更新成功');
|
||||
} else {
|
||||
//不存在时新增
|
||||
if ($res = ProductModel::create($data)) {
|
||||
foreach ($cate_id as $cid) {
|
||||
\think\facade\Db::name('store_product_cate')->insert(['product_id' => $res['id'], 'cate_id' => $cid, 'add_time' => time()]);
|
||||
}
|
||||
ProductModel::commitTrans();
|
||||
return JsonService::successful('生成产品成功');
|
||||
} else {
|
||||
ProductModel::rollbackTrans();
|
||||
return JsonService::fail('生成产品失败');
|
||||
}
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
ProductModel::rollbackTrans();
|
||||
return JsonService::fail('插入数据库错误', ['line' => $e->getLine(), 'messag' => $e->getMessage()]);
|
||||
} catch (\Exception $e) {
|
||||
ProductModel::rollbackTrans();
|
||||
return JsonService::fail('系统错误', ['line' => $e->getLine(), 'messag' => $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 上传图片处理
|
||||
* @param array $image 图片路径
|
||||
* @param int $uploadType 上传方式 0=远程下载
|
||||
* */
|
||||
public function uploadImage(array $images = [], $html = '', $uploadType = 0, $AttachmentCategoryId = 0)
|
||||
{
|
||||
$uploadImage = [];
|
||||
$siteUrl = SystemConfig::getConfigValue('site_url');
|
||||
switch ($uploadType) {
|
||||
case 0:
|
||||
foreach ($images as $item) {
|
||||
//下载图片文件
|
||||
if ($item['w'] && $item['h'])
|
||||
$uploadValue = $this->downloadImage($item['line'], '', 0, 30, $item['w'], $item['h']);
|
||||
else
|
||||
$uploadValue = $this->downloadImage($item['line']);
|
||||
//下载成功更新数据库
|
||||
if (is_array($uploadValue)) {
|
||||
//TODO 拼接图片地址
|
||||
if ($uploadValue['image_type'] == 1) $imagePath = $siteUrl . $uploadValue['path'];
|
||||
else $imagePath = $uploadValue['path'];
|
||||
//写入数据库
|
||||
if (!$uploadValue['is_exists'] && $AttachmentCategoryId) SystemAttachment::attachmentAdd($uploadValue['name'], $uploadValue['size'], $uploadValue['mime'], $imagePath, $imagePath, $AttachmentCategoryId, $uploadValue['image_type'], time(), 1);
|
||||
//组装数组
|
||||
if (isset($item['isTwoArray']) && $item['isTwoArray'])
|
||||
$uploadImage[$item['valuename']][] = $imagePath;
|
||||
else
|
||||
$uploadImage[$item['valuename']] = $imagePath;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
preg_match_all('#<img.*?src="([^"]*)"[^>]*>#i', $html, $match);
|
||||
if (isset($match[1])) {
|
||||
foreach ($match[1] as $item) {
|
||||
if (is_int(strpos($item, 'http')))
|
||||
$arcurl = $item;
|
||||
else
|
||||
$arcurl = 'http://' . ltrim($item, '\//');
|
||||
$uploadValue = $this->downloadImage($arcurl);
|
||||
//下载成功更新数据库
|
||||
if (is_array($uploadValue)) {
|
||||
//TODO 拼接图片地址
|
||||
if ($uploadValue['image_type'] == 1) $imagePath = $siteUrl . $uploadValue['path'];
|
||||
else $imagePath = $uploadValue['path'];
|
||||
//写入数据库
|
||||
if (!$uploadValue['is_exists'] && $AttachmentCategoryId) SystemAttachment::attachmentAdd($uploadValue['name'], $uploadValue['size'], $uploadValue['mime'], $imagePath, $imagePath, $AttachmentCategoryId, $uploadValue['image_type'], time(), 1);
|
||||
//替换图片
|
||||
$html = str_replace($item, $imagePath, $html);
|
||||
} else {
|
||||
//替换掉没有下载下来的图片
|
||||
$html = preg_replace('#<img.*?src="' . $item . '"*>#i', '', $html);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $html;
|
||||
break;
|
||||
default:
|
||||
return $this->setErrorInfo('上传方式错误');
|
||||
break;
|
||||
}
|
||||
return $uploadImage;
|
||||
}
|
||||
|
||||
//提取商品描述中的所有图片
|
||||
public function decodedesc($desc = '')
|
||||
{
|
||||
$desc = trim($desc);
|
||||
if (!$desc) return '';
|
||||
preg_match_all('/<img[^>]*?src="([^"]*?)"[^>]*?>/i', $desc, $match);
|
||||
if (!isset($match[1]) || count($match[1]) <= 0) {
|
||||
preg_match_all('/:url(([^"]*?));/i', $desc, $match);
|
||||
if (!isset($match[1]) || count($match[1]) <= 0) return $desc;
|
||||
} else {
|
||||
preg_match_all('/:url(([^"]*?));/i', $desc, $newmatch);
|
||||
if (isset($newmatch[1]) && count($newmatch[1]) > 0) $match[1] = array_merge($match[1], $newmatch[1]);
|
||||
}
|
||||
$match[1] = array_unique($match[1]); //去掉重复
|
||||
foreach ($match[1] as $k => &$v) {
|
||||
$_tmp_img = str_replace([')', '(', ';'], '', $v);
|
||||
$_tmp_img = strpos($_tmp_img, 'http') ? $_tmp_img : 'http:' . $_tmp_img;
|
||||
if (strpos($v, '?')) {
|
||||
$_tarr = explode('?', $v);
|
||||
$_tmp_img = trim($_tarr[0]);
|
||||
}
|
||||
$_urls = str_replace(['\'', '"'], '', $_tmp_img);
|
||||
if ($this->_img_exists($_urls)) $v = $_urls;
|
||||
}
|
||||
return $match[1];
|
||||
}
|
||||
|
||||
//获取京东商品组图
|
||||
public function getJdImg($html = '')
|
||||
{
|
||||
//获取图片服务器网址
|
||||
preg_match('/<img(.*?)id="spec-img"(.*?)data-origin=\"(.*?)\"[^>]*>/', $html, $img);
|
||||
if (!isset($img[3])) return '';
|
||||
$info = parse_url(trim($img[3]));
|
||||
if (!$info['host']) return '';
|
||||
if (!$info['path']) return '';
|
||||
$_tmparr = explode('/', trim($info['path']));
|
||||
$url = 'http://' . $info['host'] . '/' . $_tmparr[1] . '/' . str_replace(['jfs', ' '], '', trim($_tmparr[2]));
|
||||
preg_match('/imageList:(.*?)"],/is', $html, $img);
|
||||
if (!isset($img[1])) {
|
||||
return '';
|
||||
}
|
||||
$_arr = explode(',', $img[1]);
|
||||
foreach ($_arr as $k => &$v) {
|
||||
$_str = $url . str_replace(['"', '[', ']', ' '], '', trim($v));
|
||||
if (strpos($_str, '?')) {
|
||||
$_tarr = explode('?', $_str);
|
||||
$_str = trim($_tarr[0]);
|
||||
}
|
||||
if ($this->_img_exists($_str)) {
|
||||
$v = $_str;
|
||||
} else {
|
||||
unset($_arr[$k]);
|
||||
}
|
||||
}
|
||||
return array_unique($_arr);
|
||||
}
|
||||
|
||||
//获取京东商品描述
|
||||
public function getJdDesc($html = '')
|
||||
{
|
||||
preg_match('/,(.*?)desc:([^<>]*)\',/i', $html, $descarr);
|
||||
if (!isset($descarr[1]) && !isset($descarr[2])) return '';
|
||||
$tmpArr = explode(',', $descarr[2]);
|
||||
if (count($tmpArr) > 0) {
|
||||
$descarr[2] = trim($tmpArr[0]);
|
||||
}
|
||||
$replace_arr = ['\'', '\',', ' ', ',', '/*', '*/'];
|
||||
if (isset($descarr[2])) {
|
||||
$d_url = str_replace($replace_arr, '', $descarr[2]);
|
||||
return $this->formatDescUrl(strpos($d_url, 'http') ? $d_url : 'http:' . $d_url);
|
||||
}
|
||||
$d_url = str_replace($replace_arr, '', $descarr[1]);
|
||||
$d_url = $this->formatDescUrl($d_url);
|
||||
$d_url = rtrim(rtrim($d_url, "?"), "&");
|
||||
return substr($d_url, 0, 4) == 'http' ? $d_url : 'http:' . $d_url;
|
||||
}
|
||||
|
||||
//处理下京东商品描述网址
|
||||
public function formatDescUrl($url = '')
|
||||
{
|
||||
if (!$url) return '';
|
||||
$url = substr($url, 0, 4) == 'http' ? $url : 'http:' . $url;
|
||||
if (!strpos($url, '&')) {
|
||||
$_arr = explode('?', $url);
|
||||
if (!is_array($_arr) || count($_arr) <= 0) return $url;
|
||||
return trim($_arr[0]);
|
||||
} else {
|
||||
$_arr = explode('&', $url);
|
||||
}
|
||||
if (!is_array($_arr) || count($_arr) <= 0) return $url;
|
||||
unset($_arr[count($_arr) - 1]);
|
||||
$new_url = '';
|
||||
foreach ($_arr as $k => $v) {
|
||||
$new_url .= $v . '&';
|
||||
}
|
||||
return !$new_url ? $url : $new_url;
|
||||
}
|
||||
|
||||
//获取1688商品组图
|
||||
public function get1688Img($html = '')
|
||||
{
|
||||
preg_match('/<ul class=\"nav nav-tabs fd-clr\">(.*?)<\/ul>/is', $html, $img);
|
||||
if (!isset($img[0])) {
|
||||
return '';
|
||||
}
|
||||
preg_match_all('/preview":"(.*?)\"\}\'>/is', $img[0], $arrb);
|
||||
if (!isset($arrb[1]) || count($arrb[1]) <= 0) {
|
||||
return '';
|
||||
}
|
||||
$thumb = [];
|
||||
$gaoqing = [];
|
||||
$res = ['thumb' => '', 'gaoqing' => '']; //缩略图片和高清图片
|
||||
foreach ($arrb[1] as $k => $v) {
|
||||
$_str = str_replace(['","original":"'], '*', $v);
|
||||
$_arr = explode('*', $_str);
|
||||
if (is_array($_arr) && isset($_arr[0]) && isset($_arr[1])) {
|
||||
if (strpos($_arr[0], '?')) {
|
||||
$_tarr = explode('?', $_arr[0]);
|
||||
$_arr[0] = trim($_tarr[0]);
|
||||
}
|
||||
if (strpos($_arr[1], '?')) {
|
||||
$_tarr = explode('?', $_arr[1]);
|
||||
$_arr[1] = trim($_tarr[0]);
|
||||
}
|
||||
if ($this->_img_exists($_arr[0])) $thumb[] = trim($_arr[0]);
|
||||
if ($this->_img_exists($_arr[1])) $gaoqing[] = trim($_arr[1]);
|
||||
}
|
||||
}
|
||||
$res = ['thumb' => array_unique($thumb), 'gaoqing' => array_unique($gaoqing)]; //缩略图片和高清图片
|
||||
return $res;
|
||||
}
|
||||
|
||||
//获取1688商品描述
|
||||
public function get1688Desc($html = '')
|
||||
{
|
||||
preg_match('/data-tfs-url="([^<>]*)data-enable="true"/', $html, $descarr);
|
||||
if (!isset($descarr[1])) return '';
|
||||
return str_replace(['"', ' '], '', $descarr[1]);
|
||||
}
|
||||
|
||||
//获取天猫商品组图
|
||||
public function getTianMaoImg($html = '')
|
||||
{
|
||||
$pic_size = '430';
|
||||
preg_match('/<img[^>]*id="J_ImgBooth"[^r]*rc=\"([^"]*)\"[^>]*>/', $html, $img);
|
||||
if (isset($img[1])) {
|
||||
$_arr = explode('x', $img[1]);
|
||||
$filename = $_arr[count($_arr) - 1];
|
||||
$pic_size = intval(substr($filename, 0, 3));
|
||||
}
|
||||
preg_match('|<ul id="J_UlThumb" class="tb-thumb tm-clear">(.*)</ul>|isU', $html, $match);
|
||||
preg_match_all('/<img src="(.*?)" \//', $match[1], $images);
|
||||
if (!isset($images[1])) return '';
|
||||
foreach ($images[1] as $k => &$v) {
|
||||
$tmp_v = trim($v);
|
||||
$_arr = explode('x', $tmp_v);
|
||||
$_fname = $_arr[count($_arr) - 1];
|
||||
$_size = intval(substr($_fname, 0, 3));
|
||||
if (strpos($tmp_v, '://')) {
|
||||
$_arr = explode(':', $tmp_v);
|
||||
$r_url = trim($_arr[1]);
|
||||
} else {
|
||||
$r_url = $tmp_v;
|
||||
}
|
||||
$str = str_replace($_size, $pic_size, $r_url);
|
||||
if (strpos($str, '?')) {
|
||||
$_tarr = explode('?', $str);
|
||||
$str = trim($_tarr[0]);
|
||||
}
|
||||
$_i_url = strpos($str, 'http') ? $str : 'http:' . $str;
|
||||
if ($this->_img_exists($_i_url)) {
|
||||
$v = $_i_url;
|
||||
} else {
|
||||
unset($images[1][$k]);
|
||||
}
|
||||
}
|
||||
return array_unique($images[1]);
|
||||
}
|
||||
|
||||
//获取天猫商品描述
|
||||
public function getTianMaoDesc($html = '')
|
||||
{
|
||||
preg_match('/descUrl":"([^<>]*)","httpsDescUrl":"/', $html, $descarr);
|
||||
if (!isset($descarr[1])) {
|
||||
preg_match('/httpsDescUrl":"([^<>]*)","fetchDcUrl/', $html, $descarr);
|
||||
if (!isset($descarr[1])) return '';
|
||||
}
|
||||
return strpos($descarr[1], 'http') ? $descarr[1] : 'http:' . $descarr[1];
|
||||
}
|
||||
|
||||
//获取淘宝商品组图
|
||||
public function getTaobaoImg($html = '')
|
||||
{
|
||||
preg_match('/auctionImages([^<>]*)"]/', $html, $imgarr);
|
||||
if (!isset($imgarr[1])) return '';
|
||||
$arr = explode(',', $imgarr[1]);
|
||||
foreach ($arr as $k => &$v) {
|
||||
$str = trim($v);
|
||||
$str = str_replace(['"', ' ', '', ':['], '', $str);
|
||||
if (strpos($str, '?')) {
|
||||
$_tarr = explode('?', $str);
|
||||
$str = trim($_tarr[0]);
|
||||
}
|
||||
$_i_url = strpos($str, 'http') ? $str : 'http:' . $str;
|
||||
if ($this->_img_exists($_i_url)) {
|
||||
$v = $_i_url;
|
||||
} else {
|
||||
unset($arr[$k]);
|
||||
}
|
||||
}
|
||||
return array_unique($arr);
|
||||
}
|
||||
|
||||
//获取淘宝商品描述
|
||||
public function getTaobaoDesc($html = '')
|
||||
{
|
||||
preg_match('/descUrl([^<>]*)counterApi/', $html, $descarr);
|
||||
if (!isset($descarr[1])) return '';
|
||||
$arr = explode(':', $descarr[1]);
|
||||
$url = [];
|
||||
foreach ($arr as $k => $v) {
|
||||
if (strpos($v, '//')) {
|
||||
$str = str_replace(['\'', ',', ' ', '?', ':'], '', $v);
|
||||
$url[] = trim($str);
|
||||
}
|
||||
}
|
||||
if ($url) {
|
||||
return strpos($url[0], 'http') ? $url[0] : 'http:' . $url[0];
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* GET 请求
|
||||
* @param string $url
|
||||
*/
|
||||
public function curl_Get($url = '', $time_out = 25)
|
||||
{
|
||||
if (!$url) return '';
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
|
||||
if (stripos($url, "https://") !== FALSE) {
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); // 从证书中检查SSL加密算法是否存在
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('user-agent:' . $_SERVER['HTTP_USER_AGENT']));
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, $time_out);
|
||||
$response = curl_exec($ch);
|
||||
if ($error = curl_error($ch)) {
|
||||
return false;
|
||||
}
|
||||
curl_close($ch);
|
||||
return mb_convert_encoding($response, 'utf-8', 'GB2312');
|
||||
}
|
||||
|
||||
//检测远程文件是否存在
|
||||
public function _img_exists($url = '')
|
||||
{
|
||||
ini_set("max_execution_time", 0);
|
||||
$str = @file_get_contents($url, 0, null, 0, 1);
|
||||
if (strlen($str) <= 0) return false;
|
||||
if ($str)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
//TODO 下载图片
|
||||
public function downloadImage($url = '', $name = '', $type = 0, $timeout = 30, $w = 0, $h = 0)
|
||||
{
|
||||
if (!strlen(trim($url))) return '';
|
||||
if (!strlen(trim($name))) {
|
||||
//TODO 获取要下载的文件名称
|
||||
$downloadImageInfo = $this->getImageExtname($url);
|
||||
$name = $downloadImageInfo['file_name'];
|
||||
if (!strlen(trim($name))) return '';
|
||||
}
|
||||
//TODO 获取远程文件所采用的方法
|
||||
if ($type) {
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //TODO 跳过证书检查
|
||||
if (stripos($url, "https://") !== FALSE) curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); //TODO 从证书中检查SSL加密算法是否存在
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('user-agent:' . $_SERVER['HTTP_USER_AGENT']));
|
||||
if (ini_get('open_basedir') == '' && ini_get('safe_mode' == 'Off')) curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);//TODO 是否采集301、302之后的页面
|
||||
$content = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
} else {
|
||||
try {
|
||||
ob_start();
|
||||
readfile($url);
|
||||
$content = ob_get_contents();
|
||||
ob_end_clean();
|
||||
} catch (\Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
}
|
||||
$size = strlen(trim($content));
|
||||
if (!$content || $size <= 2) return '图片流获取失败';
|
||||
$date_dir = date('Y') . DS . date('m') . DS . date('d');
|
||||
$imageInfo = UploadService::imageStream($name, $content, 'attach/' . $date_dir);
|
||||
if (!is_array($imageInfo)) return $imageInfo;
|
||||
$date['path'] = $imageInfo['dir'];
|
||||
$date['name'] = $imageInfo['name'];
|
||||
$date['size'] = $imageInfo['size'];
|
||||
$date['mime'] = $imageInfo['type'];
|
||||
$date['image_type'] = $imageInfo['image_type'];
|
||||
$date['is_exists'] = false;
|
||||
return $date;
|
||||
}
|
||||
|
||||
//获取即将要下载的图片扩展名
|
||||
public function getImageExtname($url = '', $ex = 'jpg')
|
||||
{
|
||||
$_empty = ['file_name' => '', 'ext_name' => $ex];
|
||||
if (!$url) return $_empty;
|
||||
if (strpos($url, '?')) {
|
||||
$_tarr = explode('?', $url);
|
||||
$url = trim($_tarr[0]);
|
||||
}
|
||||
$arr = explode('.', $url);
|
||||
if (!is_array($arr) || count($arr) <= 1) return $_empty;
|
||||
$ext_name = trim($arr[count($arr) - 1]);
|
||||
$ext_name = !$ext_name ? $ex : $ext_name;
|
||||
return ['file_name' => md5($url) . '.' . $ext_name, 'ext_name' => $ext_name];
|
||||
}
|
||||
|
||||
/*
|
||||
$filepath = 绝对路径,末尾有斜杠 /
|
||||
$name = 图片文件名
|
||||
$maxwidth 定义生成图片的最大宽度(单位:像素)
|
||||
$maxheight 生成图片的最大高度(单位:像素)
|
||||
$filetype 最终生成的图片类型(.jpg/.png/.gif)
|
||||
*/
|
||||
public function resizeImage($filepath = '', $name = '', $maxwidth = 0, $maxheight = 0)
|
||||
{
|
||||
$pic_file = $filepath . $name; //图片文件
|
||||
$img_info = getimagesize($pic_file); //索引 2 是图像类型的标记:1 = GIF,2 = JPG,3 = PNG,4 = SWF,5 = PSD,
|
||||
if ($img_info[2] == 1) {
|
||||
$im = imagecreatefromgif($pic_file); //打开图片
|
||||
$filetype = '.gif';
|
||||
} elseif ($img_info[2] == 2) {
|
||||
$im = imagecreatefromjpeg($pic_file); //打开图片
|
||||
$filetype = '.jpg';
|
||||
} elseif ($img_info[2] == 3) {
|
||||
$im = imagecreatefrompng($pic_file); //打开图片
|
||||
$filetype = '.png';
|
||||
} else {
|
||||
return ['path' => $filepath, 'file' => $name, 'mime' => ''];
|
||||
}
|
||||
$file_name = md5('_tmp_' . microtime() . '_' . rand(0, 10)) . $filetype;
|
||||
$pic_width = imagesx($im);
|
||||
$pic_height = imagesy($im);
|
||||
$resizewidth_tag = false;
|
||||
$resizeheight_tag = false;
|
||||
if (($maxwidth && $pic_width > $maxwidth) || ($maxheight && $pic_height > $maxheight)) {
|
||||
if ($maxwidth && $pic_width > $maxwidth) {
|
||||
$widthratio = $maxwidth / $pic_width;
|
||||
$resizewidth_tag = true;
|
||||
}
|
||||
if ($maxheight && $pic_height > $maxheight) {
|
||||
$heightratio = $maxheight / $pic_height;
|
||||
$resizeheight_tag = true;
|
||||
}
|
||||
if ($resizewidth_tag && $resizeheight_tag) {
|
||||
if ($widthratio < $heightratio)
|
||||
$ratio = $widthratio;
|
||||
else
|
||||
$ratio = $heightratio;
|
||||
}
|
||||
if ($resizewidth_tag && !$resizeheight_tag)
|
||||
$ratio = $widthratio;
|
||||
if ($resizeheight_tag && !$resizewidth_tag)
|
||||
$ratio = $heightratio;
|
||||
$newwidth = $pic_width * $ratio;
|
||||
$newheight = $pic_height * $ratio;
|
||||
if (function_exists("imagecopyresampled")) {
|
||||
$newim = imagecreatetruecolor($newwidth, $newheight);
|
||||
imagecopyresampled($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $pic_width, $pic_height);
|
||||
} else {
|
||||
$newim = imagecreate($newwidth, $newheight);
|
||||
imagecopyresized($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $pic_width, $pic_height);
|
||||
}
|
||||
if ($filetype == '.png') {
|
||||
imagepng($newim, $filepath . $file_name);
|
||||
} else if ($filetype == '.gif') {
|
||||
imagegif($newim, $filepath . $file_name);
|
||||
} else {
|
||||
imagejpeg($newim, $filepath . $file_name);
|
||||
}
|
||||
imagedestroy($newim);
|
||||
} else {
|
||||
if ($filetype == '.png') {
|
||||
imagepng($im, $filepath . $file_name);
|
||||
} else if ($filetype == '.gif') {
|
||||
imagegif($im, $filepath . $file_name);
|
||||
} else {
|
||||
imagejpeg($im, $filepath . $file_name);
|
||||
}
|
||||
imagedestroy($im);
|
||||
}
|
||||
@unlink($pic_file);
|
||||
return ['path' => $filepath, 'file' => $file_name, 'mime' => $img_info['mime']];
|
||||
}
|
||||
}
|
||||
213
app/admin/controller/store/StoreCategory.php
Normal file
213
app/admin/controller/store/StoreCategory.php
Normal file
@ -0,0 +1,213 @@
|
||||
<?php
|
||||
namespace app\admin\controller\store;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use crmeb\services\FormBuilder as Form;
|
||||
use crmeb\services\JsonService;
|
||||
use crmeb\services\UtilService as Util;
|
||||
use crmeb\services\JsonService as Json;
|
||||
use crmeb\services\UploadService as Upload;
|
||||
use think\Request;
|
||||
use app\admin\model\store\StoreCategory as CategoryModel;
|
||||
use think\facade\Route as Url;
|
||||
use app\admin\model\system\SystemAttachment;
|
||||
|
||||
/**
|
||||
* 产品分类控制器
|
||||
* Class StoreCategory
|
||||
* @package app\admin\controller\system
|
||||
*/
|
||||
class StoreCategory extends AuthController
|
||||
{
|
||||
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->assign('pid',$this->request->get('pid',0));
|
||||
$this->assign('cate',CategoryModel::getTierList(null, 0));
|
||||
return $this->fetch();
|
||||
}
|
||||
/*
|
||||
* 异步获取分类列表
|
||||
* @return json
|
||||
*/
|
||||
public function category_list(){
|
||||
$where = Util::getMore([
|
||||
['is_show',''],
|
||||
['pid',$this->request->param('pid','')],
|
||||
['cate_name',''],
|
||||
['page',1],
|
||||
['limit',20],
|
||||
['order','']
|
||||
]);
|
||||
return JsonService::successlayui(CategoryModel::CategoryList($where));
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置产品分类上架|下架
|
||||
* @param string $is_show
|
||||
* @param string $id
|
||||
*/
|
||||
public function set_show($is_show = '',$id = ''){
|
||||
($is_show=='' || $id=='') && JsonService::fail('缺少参数');
|
||||
if(CategoryModel::setCategoryShow($id, (int)$is_show)){
|
||||
return JsonService::successful($is_show == 1 ? '显示成功':'隐藏成功');
|
||||
}else{
|
||||
return JsonService::fail(CategoryModel::getErrorInfo($is_show == 1 ? '显示失败':'隐藏失败'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 快速编辑
|
||||
* @param string $field
|
||||
* @param string $id
|
||||
* @param string $value
|
||||
*/
|
||||
public function set_category($field='',$id='',$value=''){
|
||||
$field=='' || $id=='' || $value=='' && JsonService::fail('缺少参数');
|
||||
if(CategoryModel::where('id', $id)->update([$field=>$value]))
|
||||
return JsonService::successful('保存成功');
|
||||
else
|
||||
return JsonService::fail('保存失败');
|
||||
}
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$field = [
|
||||
Form::select('pid','父级')->setOptions(function(){
|
||||
$list = CategoryModel::getTierList(null, 0);
|
||||
$menus = [['value'=>0,'label'=>'顶级菜单']];
|
||||
foreach ($list as $menu){
|
||||
$menus[] = ['value'=>$menu['id'],'label'=>$menu['html'].$menu['cate_name']];
|
||||
}
|
||||
return $menus;
|
||||
})->filterable(1),
|
||||
Form::input('cate_name','分类名称'),
|
||||
Form::frameImageOne('pic','分类图标(180*180)',Url::buildUrl('admin/widget.images/index',array('fodder'=>'pic')))->icon('image')->width('100%')->height('500px'),
|
||||
Form::number('sort','排序'),
|
||||
Form::radio('is_show','状态',1)->options([['label'=>'显示','value'=>1],['label'=>'隐藏','value'=>0]])
|
||||
];
|
||||
$form = Form::make_post_form('添加分类',$field,Url::buildUrl('save'),2);
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 上传图片
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function upload()
|
||||
{
|
||||
$res = Upload::image('file','store/category'.date('Ymd'));
|
||||
if(is_array($res)){
|
||||
SystemAttachment::attachmentAdd($res['name'],$res['size'],$res['type'],$res['dir'],$res['thumb_path'],1,$res['image_type'],$res['time']);
|
||||
return Json::successful('图片上传成功!',['name'=>$res['name'],'url'=>Upload::pathToUrl($res['thumb_path'])]);
|
||||
}else
|
||||
return Json::fail($res);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function save(Request $request)
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'pid',
|
||||
'cate_name',
|
||||
['pic',[]],
|
||||
'sort',
|
||||
['is_show',0]
|
||||
],$request);
|
||||
if($data['pid'] == '') return Json::fail('请选择父类');
|
||||
if(!$data['cate_name']) return Json::fail('请输入分类名称');
|
||||
if(count($data['pic'])<1) return Json::fail('请上传分类图标');
|
||||
if($data['sort'] <0 ) $data['sort'] = 0;
|
||||
$data['pic'] = $data['pic'][0];
|
||||
$data['add_time'] = time();
|
||||
CategoryModel::create($data);
|
||||
return Json::successful('添加分类成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$c = CategoryModel::get($id);
|
||||
if(!$c) return Json::fail('数据不存在!');
|
||||
$field = [
|
||||
Form::select('pid','父级',(string)$c->getData('pid'))->setOptions(function() use($id){
|
||||
$list = CategoryModel::getTierList(CategoryModel::where('id','<>',$id), 0);
|
||||
// $list = (Util::sortListTier(CategoryModel::where('id','<>',$id)->select()->toArray(),'顶级','pid','cate_name'));
|
||||
$menus = [['value'=>0,'label'=>'顶级菜单']];
|
||||
foreach ($list as $menu){
|
||||
$menus[] = ['value'=>$menu['id'],'label'=>$menu['html'].$menu['cate_name']];
|
||||
}
|
||||
return $menus;
|
||||
})->filterable(1),
|
||||
Form::input('cate_name','分类名称',$c->getData('cate_name')),
|
||||
Form::frameImageOne('pic','分类图标',Url::buildUrl('admin/widget.images/index',array('fodder'=>'pic')),$c->getData('pic'))->icon('image')->width('100%')->height('500px'),
|
||||
Form::number('sort','排序',$c->getData('sort')),
|
||||
Form::radio('is_show','状态',$c->getData('is_show'))->options([['label'=>'显示','value'=>1],['label'=>'隐藏','value'=>0]])
|
||||
];
|
||||
$form = Form::make_post_form('编辑分类',$field,Url::buildUrl('update',array('id'=>$id)),2);
|
||||
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存更新的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'pid',
|
||||
'cate_name',
|
||||
['pic',[]],
|
||||
'sort',
|
||||
['is_show',0]
|
||||
],$request);
|
||||
if($data['pid'] == '') return Json::fail('请选择父类');
|
||||
if(!$data['cate_name']) return Json::fail('请输入分类名称');
|
||||
if(count($data['pic'])<1) return Json::fail('请上传分类图标');
|
||||
if($data['sort'] <0 ) $data['sort'] = 0;
|
||||
$data['pic'] = $data['pic'][0];
|
||||
CategoryModel::edit($data,$id);
|
||||
return Json::successful('修改成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
if(!CategoryModel::delCategory($id))
|
||||
return Json::fail(CategoryModel::getErrorInfo('删除失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('删除成功!');
|
||||
}
|
||||
}
|
||||
175
app/admin/controller/store/StoreInfoMana.php
Normal file
175
app/admin/controller/store/StoreInfoMana.php
Normal file
@ -0,0 +1,175 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\store;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use app\admin\model\system\SystemAttachment;
|
||||
use crmeb\services\FormBuilder;
|
||||
use crmeb\services\UtilService as Util;
|
||||
use crmeb\services\JsonService as Json;
|
||||
use crmeb\services\UploadService as Upload;
|
||||
use think\facade\Route as Url;
|
||||
use app\admin\model\article\ArticleCategory as ArticleCategoryModel;
|
||||
use app\admin\model\wechat\WechatNews as WechatNewsModel;
|
||||
|
||||
|
||||
/**
|
||||
* 资讯管理 控制器
|
||||
* Class StoreInfoMana
|
||||
* @package app\admin\controller\store
|
||||
*/
|
||||
class StoreInfoMana extends AuthController
|
||||
|
||||
{
|
||||
|
||||
/**
|
||||
* 新闻管理
|
||||
* */
|
||||
public function index($is_list=0){
|
||||
if(!$is_list) return $this->failed('数据不存在');
|
||||
echo $is_list;
|
||||
exit();
|
||||
$where = Util::getMore([
|
||||
['status',''],
|
||||
['title',''],
|
||||
],$this->request);
|
||||
$this->assign('where',$where);
|
||||
$this->assign(ArticleCategoryModel::systemPage($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 添加分类管理
|
||||
|
||||
* */
|
||||
|
||||
public function create(){
|
||||
FormBuilder::text('title','分类昵称');
|
||||
FormBuilder::textarea('intr','分类简介');
|
||||
FormBuilder::select('new_id','图文列表',function(){
|
||||
$list = \app\admin\model\wechat\WechatNews::getNews();
|
||||
$options = [];
|
||||
foreach ($list as $id=>$roleName){
|
||||
$options[] = ['label'=>$roleName,'value'=>$id];
|
||||
}
|
||||
return $options;
|
||||
})->multiple()->filterable();
|
||||
FormBuilder::upload('image','分类图片');
|
||||
FormBuilder::number('sort','排序',0);
|
||||
FormBuilder::radio('status','状态',[['value'=>1,'label'=>'显示'],['value'=>0,'label'=>'隐藏']],1);
|
||||
$rules = FormBuilder::builder()->getContent();
|
||||
$this->assign(['title'=>'编辑菜单','rules'=>$rules,'save'=>Url::buildUrl('save')]);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 上传图片
|
||||
* */
|
||||
public function upload()
|
||||
{
|
||||
$res = Upload::image('file','article/'.date('Ymd'));
|
||||
SystemAttachment::attachmentAdd($res['name'],$res['size'],$res['type'],$res['dir'],$res['thumb_path'],2,$res['image_type'],$res['time']);
|
||||
if(is_array($res))
|
||||
return Json::successful('图片上传成功!',['name'=>$res['name'],'url'=>Upload::pathToUrl($res['thumb_path'])]);
|
||||
else
|
||||
return Json::fail($res);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 保存分类管理
|
||||
|
||||
* */
|
||||
|
||||
public function save(){
|
||||
$data = Util::postMore([
|
||||
'title',
|
||||
'intr',
|
||||
['new_id',[]],
|
||||
['image',[]],
|
||||
['sort',0],
|
||||
'status',]);
|
||||
if(!$data['title']) return Json::fail('请输入分类名称');
|
||||
if(count($data['image']) != 1) return Json::fail('请选择分类图片,并且只能上传一张');
|
||||
if($data['sort'] < 0) return Json::fail('排序不能是负数');
|
||||
$data['add_time'] = time();
|
||||
$data['image'] = $data['image'][0];
|
||||
$new_id = $data['new_id'];
|
||||
unset($data['new_id']);
|
||||
$res = ArticleCategoryModel::create($data);
|
||||
if(!WechatNewsModel::saveBatchCid($res['id'],implode(',',$new_id))) return Json::fail('文章列表添加失败');
|
||||
return Json::successful('添加分类成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
* 修改分类
|
||||
|
||||
* */
|
||||
|
||||
public function edit($id){
|
||||
$this->assign(['title'=>'编辑菜单','read'=>Url::buildUrl('read',array('id'=>$id)),'update'=>Url::buildUrl('update',array('id'=>$id))]);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function read($id)
|
||||
{
|
||||
$article = ArticleCategoryModel::get($id)->getData();
|
||||
if(!$article) return Json::fail('数据不存在!');
|
||||
FormBuilder::text('title','分类昵称',$article['title']);
|
||||
FormBuilder::textarea('intr','分类简介',$article['intr']);
|
||||
$arr = ArticleCategoryModel::getArticle($id,'id,title,cid');//子文章
|
||||
$new_id = array();
|
||||
foreach ($arr as $k=>$v){
|
||||
$new_id[$k] = $k;
|
||||
}
|
||||
FormBuilder::select('new_id','文章列表',function(){
|
||||
$list = \app\admin\model\wechat\WechatNews::getNews();
|
||||
$options = [];
|
||||
foreach ($list as $id=>$roleName){
|
||||
$options[] = ['label'=>$roleName,'value'=>$id];
|
||||
}
|
||||
return $options;
|
||||
},$new_id)->multiple();
|
||||
FormBuilder::upload('image','分类图片')->defaultFileList($article['image']);
|
||||
FormBuilder::number('sort','排序',$article['sort']);
|
||||
FormBuilder::radio('status','状态',[['value'=>1,'label'=>'显示'],['value'=>0,'label'=>'隐藏']],$article['status']);
|
||||
return FormBuilder::builder();
|
||||
}
|
||||
|
||||
public function update($id)
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'title',
|
||||
'intr',
|
||||
['new_id',[]],
|
||||
['image',[]],
|
||||
['sort',0],
|
||||
'status',]);
|
||||
if(!$data['title']) return Json::fail('请输入分类名称');
|
||||
if(count($data['image']) != 1) return Json::fail('请选择分类图片,并且只能上传一张');
|
||||
if($data['sort'] < 0) return Json::fail('排序不能是负数');
|
||||
$data['image'] = $data['image'][0];
|
||||
// dump($data);
|
||||
// exit;
|
||||
if(!ArticleCategoryModel::get($id)) return Json::fail('编辑的记录不存在!');
|
||||
if(!WechatNewsModel::saveBatchCid($id,implode(',',$data['new_id']))) return Json::fail('文章列表添加失败');
|
||||
unset($data['new_id']);
|
||||
ArticleCategoryModel::edit($data,$id);
|
||||
return Json::successful('修改成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除分类
|
||||
* */
|
||||
public function delete($id)
|
||||
{
|
||||
$res = ArticleCategoryModel::delArticleCategory($id);
|
||||
if(!$res)
|
||||
return Json::fail(ArticleCategoryModel::getErrorInfo('删除失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('删除成功!');
|
||||
}
|
||||
}
|
||||
|
||||
508
app/admin/controller/store/StoreProduct.php
Normal file
508
app/admin/controller/store/StoreProduct.php
Normal file
@ -0,0 +1,508 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\store;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use app\admin\model\store\StoreProductAttrValue;
|
||||
use crmeb\services\FormBuilder as Form;
|
||||
use app\admin\model\store\StoreProductAttr;
|
||||
use app\admin\model\store\StoreProductAttrResult;
|
||||
use app\admin\model\store\StoreProductRelation;
|
||||
use crmeb\services\JsonService;
|
||||
use think\facade\Db;
|
||||
use crmeb\traits\CurdControllerTrait;
|
||||
use crmeb\services\UtilService as Util;
|
||||
use crmeb\services\JsonService as Json;
|
||||
use crmeb\services\UploadService as Upload;
|
||||
use app\admin\model\store\StoreCategory as CategoryModel;
|
||||
use app\admin\model\store\StoreProduct as ProductModel;
|
||||
use think\facade\Route as Url;
|
||||
|
||||
use app\admin\model\system\SystemAttachment;
|
||||
|
||||
|
||||
/**
|
||||
* 产品管理
|
||||
* Class StoreProduct
|
||||
* @package app\admin\controller\store
|
||||
*/
|
||||
class StoreProduct extends AuthController
|
||||
{
|
||||
|
||||
use CurdControllerTrait;
|
||||
|
||||
protected $bindModel = ProductModel::class;
|
||||
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$type = $this->request->param('type');
|
||||
//获取分类
|
||||
$this->assign('cate',CategoryModel::getTierList(null, 1));
|
||||
//出售中产品
|
||||
$onsale = ProductModel::where('is_del',0)->where('is_show',1)->count();
|
||||
//待上架产品
|
||||
$forsale = ProductModel::where('is_del',0)->where('is_show',0)->count();
|
||||
//仓库中产品
|
||||
$warehouse = ProductModel::where('is_del',0)->count();
|
||||
//已经售馨产品
|
||||
$outofstock = ProductModel::getModelObject()->where(ProductModel::setData(4))->count();
|
||||
//警戒库存
|
||||
$policeforce =ProductModel::getModelObject()->where(ProductModel::setData(5))->count();
|
||||
//回收站
|
||||
$recycle = ProductModel::where('is_del',1)->count();
|
||||
if($type == null) $type = 1;
|
||||
$this->assign(compact('type','onsale','forsale','warehouse','outofstock','policeforce','recycle'));
|
||||
return $this->fetch();
|
||||
}
|
||||
/**
|
||||
* 异步查找产品
|
||||
*
|
||||
* @return json
|
||||
*/
|
||||
public function product_ist(){
|
||||
$where=Util::getMore([
|
||||
['page',1],
|
||||
['limit',20],
|
||||
['store_name',''],
|
||||
['cate_id',''],
|
||||
['excel',0],
|
||||
['order',''],
|
||||
['type',$this->request->param('type')]
|
||||
]);
|
||||
return JsonService::successlayui(ProductModel::ProductList($where));
|
||||
}
|
||||
/**
|
||||
* 设置单个产品上架|下架
|
||||
*
|
||||
* @return json
|
||||
*/
|
||||
public function set_show($is_show='',$id=''){
|
||||
($is_show=='' || $id=='') && JsonService::fail('缺少参数');
|
||||
$res=ProductModel::where(['id'=>$id])->update(['is_show'=>(int)$is_show]);
|
||||
if($res){
|
||||
return JsonService::successful($is_show==1 ? '上架成功':'下架成功');
|
||||
}else{
|
||||
return JsonService::fail($is_show==1 ? '上架失败':'下架失败');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 快速编辑
|
||||
*
|
||||
* @return json
|
||||
*/
|
||||
public function set_product($field='',$id='',$value=''){
|
||||
$field=='' || $id=='' || $value=='' && JsonService::fail('缺少参数');
|
||||
if(ProductModel::where(['id'=>$id])->update([$field=>$value]))
|
||||
return JsonService::successful('保存成功');
|
||||
else
|
||||
return JsonService::fail('保存失败');
|
||||
}
|
||||
/**
|
||||
* 设置批量产品上架
|
||||
*
|
||||
* @return json
|
||||
*/
|
||||
public function product_show(){
|
||||
$post=Util::postMore([
|
||||
['ids',[]]
|
||||
]);
|
||||
if(empty($post['ids'])){
|
||||
return JsonService::fail('请选择需要上架的产品');
|
||||
}else{
|
||||
$res=ProductModel::where('id','in',$post['ids'])->update(['is_show'=>1]);
|
||||
if($res)
|
||||
return JsonService::successful('上架成功');
|
||||
else
|
||||
return JsonService::fail('上架失败');
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
// $this->assign(['title'=>'添加产品','action'=>Url::buildUrl('save'),'rules'=>$this->rules()->getContent()]);
|
||||
// return $this->fetch('public/common_form');
|
||||
$field = [
|
||||
Form::select('cate_id','产品分类')->setOptions(function(){
|
||||
$list = CategoryModel::getTierList(null, 1);
|
||||
$menus=[];
|
||||
foreach ($list as $menu){
|
||||
$menus[] = ['value'=>$menu['id'],'label'=>$menu['html'].$menu['cate_name'],'disabled'=>$menu['pid']== 0];//,'disabled'=>$menu['pid']== 0];
|
||||
}
|
||||
return $menus;
|
||||
})->filterable(1)->multiple(1),
|
||||
Form::input('store_name','产品名称')->col(Form::col(24)),
|
||||
Form::input('store_info','产品简介')->type('textarea'),
|
||||
Form::input('keyword','产品关键字')->placeholder('多个用英文状态下的逗号隔开'),
|
||||
Form::input('unit_name','产品单位','件'),
|
||||
Form::frameImageOne('image','产品主图片(305*305px)',Url::buildUrl('admin/widget.images/index',array('fodder'=>'image')))->icon('image')->width('100%')->height('500px'),
|
||||
Form::frameImages('slider_image','产品轮播图(640*640px)',Url::buildUrl('admin/widget.images/index',array('fodder'=>'slider_image')))->maxLength(5)->icon('images')->width('100%')->height('500px')->spin(0),
|
||||
Form::number('price','产品售价')->min(0)->col(8),
|
||||
Form::number('ot_price','产品市场价')->min(0)->col(8),
|
||||
Form::number('give_integral','赠送积分')->min(0)->precision(0)->col(8),
|
||||
Form::number('postage','邮费')->min(0)->col(Form::col(8)),
|
||||
Form::number('sales','销量',0)->min(0)->precision(0)->col(8)->readonly(1),
|
||||
Form::number('ficti','虚拟销量')->min(0)->precision(0)->col(8),
|
||||
Form::number('stock','库存')->min(0)->precision(0)->col(8),
|
||||
Form::number('cost','产品成本价')->min(0)->col(8),
|
||||
Form::number('sort','排序')->col(8),
|
||||
Form::radio('is_show','产品状态',0)->options([['label'=>'上架','value'=>1],['label'=>'下架','value'=>0]])->col(8),
|
||||
Form::radio('is_hot','热卖单品',0)->options([['label'=>'是','value'=>1],['label'=>'否','value'=>0]])->col(8),
|
||||
Form::radio('is_benefit','促销单品',0)->options([['label'=>'是','value'=>1],['label'=>'否','value'=>0]])->col(8),
|
||||
Form::radio('is_best','精品推荐',0)->options([['label'=>'是','value'=>1],['label'=>'否','value'=>0]])->col(8),
|
||||
Form::radio('is_new','首发新品',0)->options([['label'=>'是','value'=>1],['label'=>'否','value'=>0]])->col(8),
|
||||
Form::radio('is_postage','是否包邮',0)->options([['label'=>'是','value'=>1],['label'=>'否','value'=>0]])->col(8)
|
||||
];
|
||||
$form = Form::make_post_form('添加产品',$field,Url::buildUrl('save'),2);
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传图片
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function upload()
|
||||
{
|
||||
$res = Upload::image('file','store/product/'.date('Ymd'));
|
||||
SystemAttachment::attachmentAdd($res['name'],$res['size'],$res['type'],$res['dir'],$res['thumb_path'],1,$res['image_type'],$res['time']);
|
||||
if(is_array($res))
|
||||
return Json::successful('图片上传成功!',['name'=>$res['name'],'url'=>Upload::pathToUrl($res['thumb_path'])]);
|
||||
else
|
||||
return Json::fail($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
*
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
$data = Util::postMore([
|
||||
['cate_id',[]],
|
||||
'store_name',
|
||||
'store_info',
|
||||
'keyword',
|
||||
['unit_name','件'],
|
||||
['image',[]],
|
||||
['slider_image',[]],
|
||||
['postage',0],
|
||||
['ot_price',0],
|
||||
['price',0],
|
||||
['sort',0],
|
||||
['stock',100],
|
||||
'sales',
|
||||
['ficti',100],
|
||||
['give_integral',0],
|
||||
['is_show',0],
|
||||
['cost',0],
|
||||
['is_hot',0],
|
||||
['is_benefit',0],
|
||||
['is_best',0],
|
||||
['is_new',0],
|
||||
['mer_use',0],
|
||||
['is_postage',0],
|
||||
]);
|
||||
if(count($data['cate_id']) < 1) return Json::fail('请选择产品分类');
|
||||
$cate_id=$data['cate_id'];
|
||||
$data['cate_id'] = implode(',',$data['cate_id']);
|
||||
if(!$data['store_name']) return Json::fail('请输入产品名称');
|
||||
if(count($data['image'])<1) return Json::fail('请上传产品图片');
|
||||
if(count($data['slider_image'])<1) return Json::fail('请上传产品轮播图');
|
||||
if($data['price'] == '' || $data['price'] < 0) return Json::fail('请输入产品售价');
|
||||
if($data['ot_price'] == '' || $data['ot_price'] < 0) return Json::fail('请输入产品市场价');
|
||||
if($data['stock'] == '' || $data['stock'] < 0) return Json::fail('请输入库存');
|
||||
$data['image'] = $data['image'][0];
|
||||
$data['slider_image'] = json_encode($data['slider_image']);
|
||||
$data['add_time'] = time();
|
||||
$data['description'] = '';
|
||||
$data['code_path'] = '';
|
||||
$res = ProductModel::create($data);
|
||||
foreach ($cate_id as $cid){
|
||||
Db::name('store_product_cate')->insert(['product_id'=>$res['id'],'cate_id'=>$cid,'add_time'=>time()]);
|
||||
}
|
||||
return Json::successful('添加产品成功!');
|
||||
}
|
||||
|
||||
|
||||
public function edit_content($id){
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = ProductModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
$this->assign([
|
||||
'content'=>ProductModel::where('id',$id)->value('description'),
|
||||
'field'=>'description',
|
||||
'action'=>Url::buildUrl('change_field',['id'=>$id,'field'=>'description'])
|
||||
]);
|
||||
return $this->fetch('public/edit_content');
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = ProductModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
$field = [
|
||||
Form::select('cate_id','产品分类',explode(',',$product->getData('cate_id')))->setOptions(function(){
|
||||
$list = CategoryModel::getTierList(null, 1);
|
||||
$menus=[];
|
||||
foreach ($list as $menu){
|
||||
$menus[] = ['value'=>$menu['id'],'label'=>$menu['html'].$menu['cate_name'],'disabled'=>$menu['pid']== 0];//,'disabled'=>$menu['pid']== 0];
|
||||
}
|
||||
return $menus;
|
||||
})->filterable(1)->multiple(1),
|
||||
Form::input('store_name','产品名称',$product->getData('store_name')),
|
||||
Form::input('store_info','产品简介',$product->getData('store_info'))->type('textarea'),
|
||||
Form::input('keyword','产品关键字',$product->getData('keyword'))->placeholder('多个用英文状态下的逗号隔开'),
|
||||
Form::input('unit_name','产品单位',$product->getData('unit_name')),
|
||||
Form::frameImageOne('image','产品主图片(305*305px)',Url::buildUrl('admin/widget.images/index',array('fodder'=>'image')),$product->getData('image'))->icon('image')->width('100%')->height('500px'),
|
||||
Form::frameImages('slider_image','产品轮播图(640*640px)',Url::buildUrl('admin/widget.images/index',array('fodder'=>'slider_image')),json_decode($product->getData('slider_image'),1) ? : [])->maxLength(5)->icon('images')->width('100%')->height('500px'),
|
||||
Form::number('price','产品售价',$product->getData('price'))->min(0)->precision(2)->col(8),
|
||||
Form::number('ot_price','产品市场价',$product->getData('ot_price'))->min(0)->col(8),
|
||||
Form::number('give_integral','赠送积分',$product->getData('give_integral'))->min(0)->precision(0)->col(8),
|
||||
Form::number('postage','邮费',$product->getData('postage'))->min(0)->col(8),
|
||||
Form::number('sales','销量',$product->getData('sales'))->min(0)->precision(0)->col(8)->readonly(1),
|
||||
Form::number('ficti','虚拟销量',$product->getData('ficti'))->min(0)->precision(0)->col(8),
|
||||
Form::number('stock','库存',ProductModel::getStock($id)>0?ProductModel::getStock($id):$product->getData('stock'))->min(0)->precision(0)->col(8),
|
||||
Form::number('cost','产品成本价',$product->getData('cost'))->min(0)->col(8),
|
||||
Form::number('sort','排序',$product->getData('sort'))->col(8),
|
||||
Form::radio('is_show','产品状态',$product->getData('is_show'))->options([['label'=>'上架','value'=>1],['label'=>'下架','value'=>0]])->col(8),
|
||||
Form::radio('is_hot','热卖单品',$product->getData('is_hot'))->options([['label'=>'是','value'=>1],['label'=>'否','value'=>0]])->col(8),
|
||||
Form::radio('is_benefit','促销单品',$product->getData('is_benefit'))->options([['label'=>'是','value'=>1],['label'=>'否','value'=>0]])->col(8),
|
||||
Form::radio('is_best','精品推荐',$product->getData('is_best'))->options([['label'=>'是','value'=>1],['label'=>'否','value'=>0]])->col(8),
|
||||
Form::radio('is_new','首发新品',$product->getData('is_new'))->options([['label'=>'是','value'=>1],['label'=>'否','value'=>0]])->col(8),
|
||||
Form::radio('is_postage','是否包邮',$product->getData('is_postage'))->options([['label'=>'是','value'=>1],['label'=>'否','value'=>0]])->col(8)
|
||||
];
|
||||
$form = Form::make_post_form('编辑产品',$field,Url::buildUrl('update',array('id'=>$id)),2);
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 保存更新的资源
|
||||
*
|
||||
* @param $id
|
||||
*/
|
||||
public function update($id)
|
||||
{
|
||||
$data = Util::postMore([
|
||||
['cate_id',[]],
|
||||
'store_name',
|
||||
'store_info',
|
||||
'keyword',
|
||||
['unit_name','件'],
|
||||
['image',[]],
|
||||
['slider_image',[]],
|
||||
['postage',0],
|
||||
['ot_price',0],
|
||||
['price',0],
|
||||
['sort',0],
|
||||
['stock',0],
|
||||
['ficti',100],
|
||||
['give_integral',0],
|
||||
['is_show',0],
|
||||
['cost',0],
|
||||
['is_hot',0],
|
||||
['is_benefit',0],
|
||||
['is_best',0],
|
||||
['is_new',0],
|
||||
['mer_use',0],
|
||||
['is_postage',0],
|
||||
]);
|
||||
if(count($data['cate_id']) < 1) return Json::fail('请选择产品分类');
|
||||
$cate_id=$data['cate_id'];
|
||||
$data['cate_id'] = implode(',',$data['cate_id']);
|
||||
if(!$data['store_name']) return Json::fail('请输入产品名称');
|
||||
if(count($data['image'])<1) return Json::fail('请上传产品图片');
|
||||
if(count($data['slider_image'])<1) return Json::fail('请上传产品轮播图');
|
||||
// if(count($data['slider_image'])>8) return Json::fail('轮播图最多5张图');
|
||||
if($data['price'] == '' || $data['price'] < 0) return Json::fail('请输入产品售价');
|
||||
if($data['ot_price'] == '' || $data['ot_price'] < 0) return Json::fail('请输入产品市场价');
|
||||
if($data['stock'] == '' || $data['stock'] < 0) return Json::fail('请输入库存');
|
||||
$data['image'] = $data['image'][0];
|
||||
$data['slider_image'] = json_encode($data['slider_image']);
|
||||
ProductModel::edit($data,$id);
|
||||
Db::name('store_product_cate')->where('product_id',$id)->delete();
|
||||
foreach ($cate_id as $cid){
|
||||
Db::name('store_product_cate')->insert(['product_id'=>$id,'cate_id'=>$cid,'add_time'=>time()]);
|
||||
}
|
||||
return Json::successful('修改成功!');
|
||||
}
|
||||
|
||||
public function attr($id)
|
||||
{
|
||||
if(!$id) return $this->failed('数据不存在!');
|
||||
// $result = StoreProductAttrResult::getResult($id);
|
||||
$result = StoreProductAttrValue::getStoreProductAttrResult($id);
|
||||
$image = ProductModel::where('id',$id)->value('image');
|
||||
$this->assign(compact('id','result','image'));
|
||||
return $this->fetch();
|
||||
}
|
||||
/**
|
||||
* 生成属性
|
||||
* @param int $id
|
||||
*/
|
||||
public function is_format_attr($id = 0){
|
||||
if(!$id) return Json::fail('产品不存在');
|
||||
list($attr,$detail) = Util::postMore([
|
||||
['items',[]],
|
||||
['attrs',[]]
|
||||
],null,true);
|
||||
$product = ProductModel::get($id);
|
||||
if(!$product) return Json::fail('产品不存在');
|
||||
$attrFormat = attrFormat($attr)[1];
|
||||
if(count($detail)){
|
||||
foreach ($attrFormat as $k=>$v){
|
||||
foreach ($detail as $kk=>$vv){
|
||||
if($v['detail'] == $vv['detail']){
|
||||
$attrFormat[$k]['price'] = $vv['price'];
|
||||
$attrFormat[$k]['cost'] = isset($vv['cost']) ? $vv['cost'] : $product['cost'];
|
||||
$attrFormat[$k]['sales'] = $vv['sales'];
|
||||
$attrFormat[$k]['pic'] = $vv['pic'];
|
||||
$attrFormat[$k]['check'] = false;
|
||||
break;
|
||||
}else{
|
||||
$attrFormat[$k]['cost'] = $product['cost'];
|
||||
$attrFormat[$k]['price'] = '';
|
||||
$attrFormat[$k]['sales'] = '';
|
||||
$attrFormat[$k]['pic'] = $product['image'];
|
||||
$attrFormat[$k]['check'] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
foreach ($attrFormat as $k=>$v){
|
||||
$attrFormat[$k]['cost'] = $product['cost'];
|
||||
$attrFormat[$k]['price'] = $product['price'];
|
||||
$attrFormat[$k]['sales'] = $product['stock'];
|
||||
$attrFormat[$k]['pic'] = $product['image'];
|
||||
$attrFormat[$k]['check'] = false;
|
||||
}
|
||||
}
|
||||
return Json::successful($attrFormat);
|
||||
}
|
||||
|
||||
public function set_attr($id)
|
||||
{
|
||||
if(!$id) return $this->failed('产品不存在!');
|
||||
list($attr,$detail) = Util::postMore([
|
||||
['items',[]],
|
||||
['attrs',[]]
|
||||
],null,true);
|
||||
$res = StoreProductAttr::createProductAttr($attr,$detail,$id);
|
||||
if($res)
|
||||
return $this->successful('编辑属性成功!');
|
||||
else
|
||||
return $this->failed(StoreProductAttr::getErrorInfo());
|
||||
}
|
||||
|
||||
public function clear_attr($id)
|
||||
{
|
||||
if(!$id) return $this->failed('产品不存在!');
|
||||
if(false !== StoreProductAttr::clearProductAttr($id) && false !== StoreProductAttrResult::clearResult($id))
|
||||
return $this->successful('清空产品属性成功!');
|
||||
else
|
||||
return $this->failed(StoreProductAttr::getErrorInfo('清空产品属性失败!'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
if(!ProductModel::be(['id'=>$id])) return $this->failed('产品数据不存在');
|
||||
if(ProductModel::be(['id'=>$id,'is_del'=>1])){
|
||||
$data['is_del'] = 0;
|
||||
if(!ProductModel::edit($data,$id))
|
||||
return Json::fail(ProductModel::getErrorInfo('恢复失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('成功恢复产品!');
|
||||
}else{
|
||||
$data['is_del'] = 1;
|
||||
if(!ProductModel::edit($data,$id))
|
||||
return Json::fail(ProductModel::getErrorInfo('删除失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('成功移到回收站!');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 点赞
|
||||
* @param $id
|
||||
* @return mixed|\think\response\Json|void
|
||||
*/
|
||||
public function collect($id){
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = ProductModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
$this->assign(StoreProductRelation::getCollect($id));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 收藏
|
||||
* @param $id
|
||||
* @return mixed|\think\response\Json|void
|
||||
*/
|
||||
public function like($id){
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = ProductModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
$this->assign(StoreProductRelation::getLike($id));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改产品价格
|
||||
*/
|
||||
public function edit_product_price(){
|
||||
$data = Util::postMore([
|
||||
['id',0],
|
||||
['price',0],
|
||||
]);
|
||||
if(!$data['id']) return Json::fail('参数错误');
|
||||
$res = ProductModel::edit(['price'=>$data['price']],$data['id']);
|
||||
if($res) return Json::successful('修改成功');
|
||||
else return Json::fail('修改失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改产品库存
|
||||
*
|
||||
*/
|
||||
public function edit_product_stock(){
|
||||
$data = Util::postMore([
|
||||
['id',0],
|
||||
['stock',0],
|
||||
]);
|
||||
if(!$data['id']) return Json::fail('参数错误');
|
||||
$res = ProductModel::edit(['stock'=>$data['stock']],$data['id']);
|
||||
if($res) return Json::successful('修改成功');
|
||||
else return Json::fail('修改失败');
|
||||
}
|
||||
}
|
||||
108
app/admin/controller/store/StoreProductReply.php
Normal file
108
app/admin/controller/store/StoreProductReply.php
Normal file
@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\store;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use crmeb\services\JsonService;
|
||||
use crmeb\services\UtilService;
|
||||
use crmeb\traits\CurdControllerTrait;
|
||||
use crmeb\services\UtilService as Util;
|
||||
use crmeb\services\JsonService as Json;
|
||||
use app\admin\model\store\StoreProductReply as ProductReplyModel;
|
||||
/**
|
||||
* 评论管理 控制器
|
||||
* Class StoreProductReply
|
||||
* @package app\admin\controller\store
|
||||
*/
|
||||
class StoreProductReply extends AuthController
|
||||
{
|
||||
|
||||
use CurdControllerTrait;
|
||||
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$product_id = input('product_id');
|
||||
if(!$product_id) $product_id = 0;
|
||||
$this->assign('is_layui',true);
|
||||
$this->assign('product_id',(int)$product_id);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function get_product_imaes_list()
|
||||
{
|
||||
$where=UtilService::getMore([
|
||||
['page',1],
|
||||
['limit',10],
|
||||
['title',''],
|
||||
['is_reply',''],
|
||||
['product_name',''],
|
||||
['product_id',0],
|
||||
]);
|
||||
return JsonService::successful(ProductReplyModel::getProductImaesList($where));
|
||||
}
|
||||
|
||||
public function get_product_reply_list()
|
||||
{
|
||||
$where=UtilService::getMore([
|
||||
['limit',10],
|
||||
['title',''],
|
||||
['is_reply',''],
|
||||
['message_page',1],
|
||||
['producr_id',0],
|
||||
]);
|
||||
return JsonService::successful(ProductReplyModel::getProductReplyList($where));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return \think\response\Json|void
|
||||
*/
|
||||
public function delete($id){
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$data['is_del'] = 1;
|
||||
if(!ProductReplyModel::edit($data,$id))
|
||||
return Json::fail(ProductReplyModel::getErrorInfo('删除失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('删除成功!');
|
||||
}
|
||||
|
||||
public function set_reply(){
|
||||
$data = Util::postMore([
|
||||
'id',
|
||||
'content',
|
||||
]);
|
||||
if(!$data['id']) return Json::fail('参数错误');
|
||||
if($data['content'] == '') return Json::fail('请输入回复内容');
|
||||
$save['merchant_reply_content'] = $data['content'];
|
||||
$save['merchant_reply_time'] = time();
|
||||
$save['is_reply'] = 2;
|
||||
$res = ProductReplyModel::edit($save,$data['id']);
|
||||
if(!$res)
|
||||
return Json::fail(ProductReplyModel::getErrorInfo('回复失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('回复成功!');
|
||||
}
|
||||
|
||||
public function edit_reply(){
|
||||
$data = Util::postMore([
|
||||
'id',
|
||||
'content',
|
||||
]);
|
||||
if(!$data['id']) return Json::fail('参数错误');
|
||||
if($data['content'] == '') return Json::fail('请输入回复内容');
|
||||
$save['merchant_reply_content'] = $data['content'];
|
||||
$save['merchant_reply_time'] = time();
|
||||
$save['is_reply'] = 2;
|
||||
$res = ProductReplyModel::edit($save,$data['id']);
|
||||
if(!$res)
|
||||
return Json::fail(ProductReplyModel::getErrorInfo('回复失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('回复成功!');
|
||||
}
|
||||
|
||||
}
|
||||
86
app/admin/controller/system/Clear.php
Normal file
86
app/admin/controller/system/Clear.php
Normal file
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\system;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use crmeb\services\JsonService as Json;
|
||||
|
||||
/**
|
||||
* 首页控制器
|
||||
* Class Clear
|
||||
* @package app\admin\controller
|
||||
*
|
||||
*/
|
||||
class Clear extends AuthController
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新数据缓存
|
||||
*/
|
||||
public function refresh_cache()
|
||||
{
|
||||
$root = app()->getRootPath() . 'runtime' . DS;
|
||||
$adminRoute = $root . 'admin';
|
||||
$apiRoute = $root . 'api';
|
||||
$cacheRoute = $root . 'cache';
|
||||
$cache = [];
|
||||
|
||||
if(is_dir($adminRoute))
|
||||
$cache[$adminRoute] = scandir($adminRoute);
|
||||
if(is_dir($apiRoute))
|
||||
$cache[$apiRoute] = scandir($apiRoute);
|
||||
if(is_dir($cacheRoute))
|
||||
$cache[$cacheRoute] = scandir($cacheRoute);
|
||||
|
||||
foreach ($cache as $p => $list) {
|
||||
foreach ($list as $file) {
|
||||
if (!in_array($file, ['.', '..', 'log', 'schema', 'route.php'])) {
|
||||
$path = $p . DS . $file;
|
||||
if (is_file($path)) {
|
||||
@unlink($path);
|
||||
} else {
|
||||
$this->delDirAndFile($path . DS);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return app('json')->successful('数据缓存刷新成功!');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除日志
|
||||
*/
|
||||
public function delete_log()
|
||||
{
|
||||
$root = app()->getRootPath() . 'runtime' . DS;
|
||||
$this->delDirAndFile($root . 'admin' . DS . 'log' . DS);
|
||||
$this->delDirAndFile($root . 'api' . DS . 'log' . DS);
|
||||
$this->delDirAndFile($root . 'log' . DS);
|
||||
|
||||
return app('json')->successful('数据缓存刷新成功!');
|
||||
}
|
||||
|
||||
/** 递归删除文件
|
||||
* @param $dirName
|
||||
* @param bool $subdir
|
||||
*/
|
||||
protected function delDirAndFile($dirName)
|
||||
{
|
||||
$list = glob($dirName . '*');
|
||||
foreach ($list as $file) {
|
||||
if (is_dir($file))
|
||||
$this->delDirAndFile($file . DS);
|
||||
else
|
||||
@unlink($file);
|
||||
}
|
||||
@rmdir($dirName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
125
app/admin/controller/system/Express.php
Normal file
125
app/admin/controller/system/Express.php
Normal file
@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\system;
|
||||
|
||||
use crmeb\services\FormBuilder as Form;
|
||||
use crmeb\services\UtilService as Util;
|
||||
use crmeb\services\JsonService as Json;
|
||||
use think\facade\Route as Url;
|
||||
use app\admin\model\system\Express as ExpressModel;
|
||||
use app\admin\controller\AuthController;
|
||||
|
||||
/**
|
||||
* 物流公司管理控制器
|
||||
* Class SystemMenus
|
||||
* @package app\admin\controller\system
|
||||
*/
|
||||
class Express extends AuthController
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$params = Util::getMore([
|
||||
['keyword','']
|
||||
],$this->request);
|
||||
$this->assign(ExpressModel::systemPage($params));
|
||||
$this->assign(compact('params'));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function create($cid = 0)
|
||||
{
|
||||
$formbuider = [
|
||||
Form::input('name','公司名称')->required('公司名称名称必填'),
|
||||
Form::input('code','编码'),
|
||||
Form::number('sort','排序',0),
|
||||
Form::radio('is_show','是否启用',1)->options([['value'=>0,'label'=>'隐藏'],['value'=>1,'label'=>'启用']]),
|
||||
];
|
||||
$form = Form::make_post_form('添加物流公司',$formbuider,Url::buildUrl('save'),2);
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'name',
|
||||
'code',
|
||||
['sort',0],
|
||||
['is_show',0]]);
|
||||
if(!$data['name']) return Json::fail('请输入公司名称');
|
||||
ExpressModel::create($data);
|
||||
return Json::successful('添加公司成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$menu = ExpressModel::get($id);
|
||||
if(!$menu) return Json::fail('数据不存在!');
|
||||
$formbuider = [
|
||||
Form::input('name','公司名称',$menu['name']),
|
||||
Form::input('code','编码',$menu['code']),
|
||||
Form::number('sort','排序',$menu['sort']),
|
||||
Form::radio('is_show','是否启用',$menu['is_show'])->options([['value'=>0,'label'=>'隐藏'],['value'=>1,'label'=>'启用']])
|
||||
];
|
||||
$form = Form::make_post_form('添加物流公司',$formbuider,Url::buildUrl('update',array('id'=>$id)),2);
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存更新的资源
|
||||
*
|
||||
* @param $id
|
||||
*/
|
||||
public function update($id)
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'name',
|
||||
'code',
|
||||
['sort',0],
|
||||
['is_show',0]]);
|
||||
if(!$data['name']) return Json::fail('请输入公司名称');
|
||||
if(!ExpressModel::get($id)) return Json::fail('编辑的记录不存在!');
|
||||
ExpressModel::edit($data,$id);
|
||||
return Json::successful('修改成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
if(!$id) return $this->failed('参数错误,请重新打开');
|
||||
$res = ExpressModel::destroy($id);
|
||||
if(!$res)
|
||||
return Json::fail(ExpressModel::getErrorInfo('删除失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('删除成功!');
|
||||
}
|
||||
|
||||
}
|
||||
41
app/admin/controller/system/SystemAttachment.php
Normal file
41
app/admin/controller/system/SystemAttachment.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\system;
|
||||
|
||||
use app\admin\model\system\SystemAttachment as SystemAttachmentModel;
|
||||
use app\admin\controller\AuthController;
|
||||
use crmeb\services\SystemConfigService;
|
||||
use crmeb\services\UploadService as Upload;
|
||||
/**
|
||||
* 附件管理控制器
|
||||
* Class SystemAttachment
|
||||
* @package app\admin\controller\system
|
||||
*
|
||||
*/
|
||||
class SystemAttachment extends AuthController
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* TODO 编辑器上传图片
|
||||
*/
|
||||
public function upload()
|
||||
{
|
||||
$res = Upload::image('upfile','editor/'.date('Ymd'));
|
||||
if(is_array($res)){
|
||||
SystemAttachmentModel::attachmentAdd($res['name'],$res['size'],$res['type'],$res['dir'],$res['thumb_path'],0,$res['image_type'],$res['time']);
|
||||
$info["originalName"] = $res['name'];
|
||||
$info["name"] = $res['name'];
|
||||
$info["url"] = $res['dir'];
|
||||
$info["size"] = $res['size'];
|
||||
$info["type"] = $res['type'];
|
||||
$info["state"] = "SUCCESS";
|
||||
if($res['image_type'] == 1) $info['url'] = SystemConfigService::get('site_url').str_replace('\\','/',$res['dir']);
|
||||
}else
|
||||
$info = array(
|
||||
"msg" => $res,
|
||||
"state" => "ERROR"
|
||||
);
|
||||
echo json_encode($info);
|
||||
}
|
||||
}
|
||||
157
app/admin/controller/system/SystemCleardata.php
Normal file
157
app/admin/controller/system/SystemCleardata.php
Normal file
@ -0,0 +1,157 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: sugar1569
|
||||
* Date: 2018/5/24
|
||||
* Time: 10:58
|
||||
*/
|
||||
|
||||
namespace app\admin\controller\system;
|
||||
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use crmeb\services\JsonService as Json;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 清除默认数据理控制器
|
||||
* Class SystemclearData
|
||||
* @package app\admin\controller\system
|
||||
*/
|
||||
class SystemclearData extends AuthController
|
||||
{
|
||||
|
||||
public function index(){
|
||||
return $this->fetch();
|
||||
}
|
||||
//清除用户数据
|
||||
public function userRelevantData(){
|
||||
self::clearData('user_recharge',1);
|
||||
self::clearData('user_address',1);
|
||||
self::clearData('user_bill',1);
|
||||
self::clearData('user_enter',1);
|
||||
self::clearData('user_extract',1);
|
||||
self::clearData('user_notice',1);
|
||||
self::clearData('user_notice_see',1);
|
||||
self::clearData('wechat_qrcode',1);
|
||||
self::clearData('wechat_message',1);
|
||||
self::clearData('store_visit',1);
|
||||
self::clearData('store_coupon_user',1);
|
||||
self::clearData('store_coupon_issue_user',1);
|
||||
self::clearData('store_bargain_user',1);
|
||||
self::clearData('store_bargain_user_help',1);
|
||||
self::clearData('store_product_reply',1);
|
||||
self::clearData('routine_qrcode',1);
|
||||
self::clearData('routine_form_id',1);
|
||||
self::clearData('user_sign',1);
|
||||
self::clearData('user_task_finish',1);
|
||||
self::clearData('user_level',1);
|
||||
self::clearData('token',1);
|
||||
self::clearData('user_group',1);
|
||||
$this->delDirAndFile('./public/uploads/store/comment');
|
||||
self::clearData('store_product_relation',1);
|
||||
return Json::successful('清除数据成功!');
|
||||
}
|
||||
//清除商城数据
|
||||
public function storeData(){
|
||||
self::clearData('store_coupon',1);
|
||||
self::clearData('store_coupon_issue',1);
|
||||
self::clearData('store_bargain',1);
|
||||
self::clearData('store_combination',1);
|
||||
self::clearData('store_combination_attr',1);
|
||||
self::clearData('store_combination_attr_result',1);
|
||||
self::clearData('store_combination_attr_value',1);
|
||||
self::clearData('store_product_attr',1);
|
||||
self::clearData('store_product_attr_result',1);
|
||||
self::clearData('store_product_attr_value',1);
|
||||
self::clearData('store_seckill',1);
|
||||
self::clearData('store_seckill_attr',1);
|
||||
self::clearData('store_seckill_attr_result',1);
|
||||
self::clearData('store_seckill_attr_value',1);
|
||||
self::clearData('store_product',1);
|
||||
self::clearData('store_visit',1);
|
||||
return Json::successful('清除数据成功!');
|
||||
}
|
||||
//清除产品分类
|
||||
public function categoryData(){
|
||||
self::clearData('store_category',1);
|
||||
return Json::successful('清除数据成功!');
|
||||
}
|
||||
//清除订单数据
|
||||
public function orderData(){
|
||||
self::clearData('store_order',1);
|
||||
self::clearData('store_order_cart_info',1);
|
||||
self::clearData('store_order_status',1);
|
||||
self::clearData('store_pink',1);
|
||||
self::clearData('store_cart',1);
|
||||
self::clearData('store_order_status',1);
|
||||
return Json::successful('清除数据成功!');
|
||||
}
|
||||
//清除客服数据
|
||||
public function kefuData(){
|
||||
self::clearData('store_service',1);
|
||||
$this->delDirAndFile('./public/uploads/store/service');
|
||||
self::clearData('store_service_log',1);
|
||||
return Json::successful('清除数据成功!');
|
||||
}
|
||||
|
||||
//清除微信管理数据
|
||||
public function wechatData(){
|
||||
self::clearData('wechat_media',1);
|
||||
self::clearData('wechat_reply',1);
|
||||
self::clearData('cache',1);
|
||||
$this->delDirAndFile('./public/uploads/wechat');
|
||||
return Json::successful('清除数据成功!');
|
||||
}
|
||||
//清除所有附件
|
||||
public function uploadData(){
|
||||
self::clearData('system_attachment',1);
|
||||
self::clearData('system_attachment_category',1);
|
||||
$this->delDirAndFile('./public/uploads/');
|
||||
return Json::successful('清除上传文件成功!');
|
||||
}
|
||||
//清除微信用户
|
||||
public function wechatuserData(){
|
||||
self::clearData('wechat_user',1);
|
||||
self::clearData('user',1);
|
||||
return Json::successful('清除数据成功!');
|
||||
}
|
||||
//清除内容分类
|
||||
public function articledata(){
|
||||
self::clearData('article_category',1);
|
||||
self::clearData('article',1);
|
||||
self::clearData('article_content',1);
|
||||
return Json::successful('清除数据成功!');
|
||||
}
|
||||
//清除系统记录
|
||||
public function systemdata(){
|
||||
self::clearData('system_notice_admin',1);
|
||||
self::clearData('system_log',1);
|
||||
return Json::successful('清除数据成功!');
|
||||
}
|
||||
//清除制定表数据
|
||||
public function clearData($table_name,$status){
|
||||
$table_name = config('database.connections.' . config('database.default'))['prefix'].$table_name;
|
||||
if($status){
|
||||
@db::execute('TRUNCATE TABLE '.$table_name);
|
||||
}else{
|
||||
@db::execute('DELETE FROM'.$table_name);
|
||||
}
|
||||
|
||||
}
|
||||
//递归删除文件
|
||||
function delDirAndFile($dirName,$subdir=true){
|
||||
if ($handle = @opendir("$dirName")){
|
||||
while(false !== ($item = readdir($handle))){
|
||||
if($item != "." && $item != ".."){
|
||||
if(is_dir("$dirName/$item"))
|
||||
$this->delDirAndFile("$dirName/$item",false);
|
||||
else
|
||||
@unlink("$dirName/$item");
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
if(!$subdir) @rmdir($dirName);
|
||||
}
|
||||
}
|
||||
}
|
||||
217
app/admin/controller/system/SystemDatabackup.php
Normal file
217
app/admin/controller/system/SystemDatabackup.php
Normal file
@ -0,0 +1,217 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\system;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use crmeb\services\JsonService as Json;
|
||||
use \crmeb\services\MysqlBackupService as Backup;
|
||||
use think\facade\Session;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 文件校验控制器
|
||||
* Class SystemDatabackup
|
||||
* @package app\admin\controller\system
|
||||
*
|
||||
*/
|
||||
class SystemDatabackup extends AuthController
|
||||
{
|
||||
/**
|
||||
* @var Backup
|
||||
*/
|
||||
protected $DB;
|
||||
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$config = array(
|
||||
//数据库备份卷大小
|
||||
'compress' => 1,
|
||||
//数据库备份文件是否启用压缩 0不压缩 1 压缩
|
||||
'level' => 5,
|
||||
);
|
||||
$this->DB = new Backup($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据类表列表
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据库表
|
||||
*/
|
||||
public function tablelist()
|
||||
{
|
||||
$db = $this->DB;
|
||||
return Json::result(0, 'sucess', $db->dataList(), count($db->dataList()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看表结构
|
||||
*/
|
||||
public function seetable()
|
||||
{
|
||||
$database = config("database.database");
|
||||
$tablename = request()->param('tablename');
|
||||
$res = Db::query("select * from information_schema.columns where table_name = '" . $tablename . "' and table_schema = '" . $database . "'");
|
||||
$html = '';
|
||||
$html .= '<table border="1" cellspacing="0" cellpadding="0" align="center">';
|
||||
$html .= '<tbody><tr><th>字段名</th><th>数据类型</th><th>默认值</th><th>允许非空</th><th>自动递增</th><th>备注</th></tr>';
|
||||
$html .= '';
|
||||
foreach ($res AS $f) {
|
||||
$html .= '<td class="c1">' . $f['COLUMN_NAME'] . '</td>';
|
||||
$html .= '<td class="c2">' . $f['COLUMN_TYPE'] . '</td>';
|
||||
$html .= '<td class="c3">' . $f['COLUMN_DEFAULT'] . '</td>';
|
||||
$html .= '<td class="c4">' . $f['IS_NULLABLE'] . '</td>';
|
||||
$html .= '<td class="c5">' . ($f['EXTRA'] == 'auto_increment' ? '是' : ' ') . '</td>';
|
||||
$html .= '<td class="c6">' . $f['COLUMN_COMMENT'] . '</td>';
|
||||
$html .= '</tr>';
|
||||
}
|
||||
$html .= '</tbody></table></p>';
|
||||
$html .= '<p style="text-align:left;margin:20px auto;">总共:' . count($res) . '个字段</p>';
|
||||
$html .= '</body></html>';
|
||||
echo '<style>
|
||||
body,td,th {font-family:"宋体"; font-size:12px;}
|
||||
table,h1,p{width:960px;margin:0px auto;}
|
||||
table{border-collapse:collapse;border:1px solid #CCC;background:#efefef;}
|
||||
table caption{text-align:left; background-color:#fff; line-height:2em; font-size:14px; font-weight:bold; }
|
||||
table th{text-align:left; font-weight:bold;height:26px; line-height:26px; font-size:12px; border:1px solid #CCC;padding-left:5px;}
|
||||
table td{height:20px; font-size:12px; border:1px solid #CCC;background-color:#fff;padding-left:5px;}
|
||||
.c1{ width: 150px;}
|
||||
.c2{ width: 150px;}
|
||||
.c3{ width: 80px;}
|
||||
.c4{ width: 100px;}
|
||||
.c5{ width: 100px;}
|
||||
.c6{ width: 300px;}
|
||||
</style>';
|
||||
echo $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* 优化表
|
||||
*/
|
||||
public function optimize()
|
||||
{
|
||||
$tables = request()->post('tables/a');
|
||||
$db = $this->DB;
|
||||
$res = $db->optimize($tables);
|
||||
return Json::successful($res ? '优化成功' : '优化失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 修复表
|
||||
*/
|
||||
public function repair()
|
||||
{
|
||||
$tables = request()->post('tables/a');
|
||||
$db = $this->DB;
|
||||
$res = $db->repair($tables);
|
||||
return Json::successful($res ? '修复成功' : '修复失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 备份表
|
||||
*/
|
||||
public function backup()
|
||||
{
|
||||
$tables = request()->post('tables/a');
|
||||
$db = $this->DB;
|
||||
$data = '';
|
||||
foreach ($tables as $t) {
|
||||
$res = $db->backup($t, 0);
|
||||
if ($res == false && $res != 0) {
|
||||
$data .= $t . '|';
|
||||
}
|
||||
}
|
||||
return Json::successful($data ? '备份失败' . $data : '备份成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取备份记录表
|
||||
*/
|
||||
public function fileList()
|
||||
{
|
||||
$db = $this->DB;
|
||||
$files = $db->fileList();
|
||||
$data = [];
|
||||
foreach ($files as $key => $t) {
|
||||
$data[$key]['filename'] = $t['filename'];
|
||||
$data[$key]['part'] = $t['part'];
|
||||
$data[$key]['size'] = $t['size'] . 'B';
|
||||
$data[$key]['compress'] = $t['compress'];
|
||||
$data[$key]['backtime'] = $key;
|
||||
$data[$key]['time'] = $t['time'];
|
||||
}
|
||||
krsort($data);//根据时间降序
|
||||
return Json::result(0, 'sucess', $data, count($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除备份记录表
|
||||
*/
|
||||
public function delFile()
|
||||
{
|
||||
$feilname = intval(request()->post('feilname'));
|
||||
$files = $this->DB->delFile($feilname);
|
||||
return Json::result(0, 'sucess');
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入备份记录表
|
||||
*/
|
||||
public function import()
|
||||
{
|
||||
$part = request()->post('part') != '' ? intval(request()->post('part')) : null;
|
||||
$start = request()->post('start') != '' ? intval(request()->post('start')) : null;
|
||||
$time = intval(request()->post('time'));
|
||||
$db = $this->DB;
|
||||
if (is_numeric($time) && is_null($part) && is_null($start)) {
|
||||
$list = $db->getFile('timeverif', $time);
|
||||
if (is_array($list)) {
|
||||
session::set('backup_list', $list);
|
||||
$this->success('初始化完成!', '', array('part' => 1, 'start' => 0));
|
||||
} else {
|
||||
$this->error('备份文件可能已经损坏,请检查!');
|
||||
}
|
||||
} else if (is_numeric($part) && is_numeric($start)) {
|
||||
$list = session::get('backup_list');
|
||||
$start = $db->setFile($list)->import($start);
|
||||
if (false === $start) {
|
||||
$this->error('还原数据出错!');
|
||||
} elseif (0 === $start) {
|
||||
if (isset($list[++$part])) {
|
||||
$data = array('part' => $part, 'start' => 0);
|
||||
$this->success("正在还原...#{$part}", '', $data);
|
||||
} else {
|
||||
session::delete('backup_list');
|
||||
$this->success('还原完成!');
|
||||
}
|
||||
} else {
|
||||
$data = array('part' => $part, 'start' => $start[0]);
|
||||
if ($start[1]) {
|
||||
$rate = floor(100 * ($start[0] / $start[1]));
|
||||
$this->success("正在还原...#{$part}({$rate}%)", '', $data);
|
||||
} else {
|
||||
$data['gz'] = 1;
|
||||
$this->success("正在还原...#{$part}", '', $data);
|
||||
}
|
||||
$this->success("正在还原...#{$part}", '');
|
||||
}
|
||||
} else {
|
||||
$this->error('参数错误!');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载备份记录表
|
||||
*/
|
||||
public function downloadFile()
|
||||
{
|
||||
$time = intval(request()->param('feilname'));
|
||||
$this->DB->downloadFile($time);
|
||||
}
|
||||
}
|
||||
305
app/admin/controller/system/SystemFile.php
Normal file
305
app/admin/controller/system/SystemFile.php
Normal file
@ -0,0 +1,305 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\system;
|
||||
|
||||
use app\admin\model\system\SystemFile as SystemFileModel;
|
||||
use app\admin\controller\AuthController;
|
||||
use crmeb\services\FormBuilder as Form;
|
||||
use crmeb\services\FileService as FileClass;
|
||||
use crmeb\services\JsonService as Json;
|
||||
|
||||
/**
|
||||
* 文件校验控制器
|
||||
* Class SystemFile
|
||||
* @package app\admin\controller\system
|
||||
*
|
||||
*/
|
||||
class SystemFile extends AuthController
|
||||
{
|
||||
//打开目录
|
||||
public function opendir($filedir = '')
|
||||
{
|
||||
$fileAll = array('dir' => [], 'file' => []);
|
||||
//根目录
|
||||
$rootdir = app()->getRootPath();
|
||||
//当前目录
|
||||
$request_dir = app('request')->param('dir');
|
||||
//防止查看站点以外的目录
|
||||
if(strpos($request_dir,$rootdir) === false){
|
||||
$request_dir = $rootdir;
|
||||
}
|
||||
//判断是否是返回上级
|
||||
if (app('request')->param('superior') && !empty($request_dir)) {
|
||||
if(strpos(dirname($request_dir),$rootdir) !== false){
|
||||
$dir = dirname($request_dir);
|
||||
}else{
|
||||
$dir = $rootdir;
|
||||
}
|
||||
|
||||
} else {
|
||||
$dir = !empty($request_dir) ? $request_dir : $rootdir;
|
||||
$dir = rtrim($dir,DS) .DS. app('request')->param('filedir');
|
||||
}
|
||||
$list = scandir($dir);
|
||||
foreach ($list as $key => $v) {
|
||||
if ($v != '.' && $v != '..') {
|
||||
if (is_dir($dir . DS . $v)) {
|
||||
$fileAll['dir'][] = FileClass::list_info($dir .DS. $v);
|
||||
}
|
||||
if (is_file($dir . DS . $v)) {
|
||||
$fileAll['file'][] = FileClass::list_info($dir .DS. $v);
|
||||
}
|
||||
}
|
||||
}
|
||||
//var_dump($fileAll['dir']);
|
||||
//兼容windows
|
||||
$uname = php_uname('s');
|
||||
if (strstr($uname, 'Windows') !== false) $dir = ltrim($dir, '\\');
|
||||
$this->assign(compact('fileAll', 'dir'));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
//读取文件
|
||||
public function openfile($file = '')
|
||||
{
|
||||
$file = $this->request->param('file');
|
||||
if (empty($file)) return Json::fail('出现错误');
|
||||
$filepath = $file;
|
||||
$content = FileClass::read_file($filepath);//防止页面内嵌textarea标签
|
||||
$ext = FileClass::get_ext($filepath);
|
||||
$extarray = [
|
||||
'js' => 'text/javascript'
|
||||
, 'php' => 'text/x-php'
|
||||
, 'html' => 'text/html'
|
||||
, 'sql' => 'text/x-mysql'
|
||||
, 'css' => 'text/x-scss'];
|
||||
$mode = empty($extarray[$ext]) ? '' : $extarray[$ext];
|
||||
$this->assign(compact('content', 'mode', 'filepath'));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
//保存文件
|
||||
public function savefile()
|
||||
{
|
||||
$comment = $this->request->post('comment');
|
||||
$filepath = $this->request->post('filepath');
|
||||
if (!empty($comment) && !empty($filepath)) {
|
||||
//兼容windows
|
||||
$uname = php_uname('s');
|
||||
if (strstr($uname, 'Windows') !== false)
|
||||
$filepath = ltrim(str_replace('/', DS, $filepath), '.');
|
||||
if (FileClass::isWritable($filepath)) {
|
||||
$res = FileClass::write_file($filepath, $comment);
|
||||
if ($res) {
|
||||
return Json::successful('保存成功!');
|
||||
} else {
|
||||
return Json::fail('保存失败');
|
||||
}
|
||||
} else {
|
||||
return Json::fail('没有权限!');
|
||||
}
|
||||
|
||||
} else {
|
||||
return Json::fail('出现错误');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$app = $this->getDir('./application');
|
||||
$extend = $this->getDir('./extend');
|
||||
$public = $this->getDir('./public');
|
||||
$arr = array();
|
||||
$arr = array_merge($app, $extend);
|
||||
$arr = array_merge($arr, $public);
|
||||
$fileAll = array();//本地文件
|
||||
$cha = array();//不同的文件
|
||||
foreach ($arr as $k => $v) {
|
||||
$fp = fopen($v, 'r');
|
||||
if (filesize($v)) $ct = fread($fp, filesize($v));
|
||||
else $ct = null;
|
||||
fclose($fp);
|
||||
$cthash = md5($ct);
|
||||
$update_time = stat($v);
|
||||
$fileAll[$k]['cthash'] = $cthash;
|
||||
$fileAll[$k]['filename'] = $v;
|
||||
$fileAll[$k]['atime'] = $update_time['atime'];
|
||||
$fileAll[$k]['mtime'] = $update_time['mtime'];
|
||||
$fileAll[$k]['ctime'] = $update_time['ctime'];
|
||||
}
|
||||
$file = SystemFileModel::all(function ($query) {
|
||||
$query->order('atime', 'desc');
|
||||
})->toArray();//数据库中的文件
|
||||
if (empty($file)) {
|
||||
$data_num = array_chunk($fileAll, 10);
|
||||
SystemFileModel::beginTrans();
|
||||
$res = true;
|
||||
foreach ($data_num as $k => $v) {
|
||||
$res = $res && SystemFileModel::insertAll($v);
|
||||
}
|
||||
SystemFileModel::checkTrans($res);
|
||||
if ($res) {
|
||||
$cha = array();//不同的文件
|
||||
} else {
|
||||
$cha = $fileAll;
|
||||
}
|
||||
} else {
|
||||
$cha = array();//差异文件
|
||||
foreach ($file as $k => $v) {
|
||||
foreach ($fileAll as $ko => $vo) {
|
||||
if ($v['filename'] == $vo['filename']) {
|
||||
if ($v['cthash'] != $vo['cthash']) {
|
||||
$cha[$k]['filename'] = $v['filename'];
|
||||
$cha[$k]['cthash'] = $v['cthash'];
|
||||
$cha[$k]['atime'] = $v['atime'];
|
||||
$cha[$k]['mtime'] = $v['mtime'];
|
||||
$cha[$k]['ctime'] = $v['ctime'];
|
||||
$cha[$k]['type'] = '已修改';
|
||||
}
|
||||
unset($fileAll[$ko]);
|
||||
unset($file[$k]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
foreach ($file as $k => $v) {
|
||||
$cha[$k]['filename'] = $v['filename'];
|
||||
$cha[$k]['cthash'] = $v['cthash'];
|
||||
$cha[$k]['atime'] = $v['atime'];
|
||||
$cha[$k]['mtime'] = $v['mtime'];
|
||||
$cha[$k]['ctime'] = $v['ctime'];
|
||||
$cha[$k]['type'] = '已删除';
|
||||
}
|
||||
foreach ($fileAll as $k => $v) {
|
||||
$cha[$k]['filename'] = $v['filename'];
|
||||
$cha[$k]['cthash'] = $v['cthash'];
|
||||
$cha[$k]['atime'] = $v['atime'];
|
||||
$cha[$k]['mtime'] = $v['mtime'];
|
||||
$cha[$k]['ctime'] = $v['ctime'];
|
||||
$cha[$k]['type'] = '新增的';
|
||||
}
|
||||
|
||||
}
|
||||
// dump($file);
|
||||
// dump($fileAll);
|
||||
$this->assign('cha', $cha);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取文件夹中的文件 不包括子文件
|
||||
* @param $dir
|
||||
* @return array
|
||||
*/
|
||||
public function getNextDir()
|
||||
{
|
||||
$dir = './';
|
||||
$list = scandir($dir);
|
||||
$dirlist = array();
|
||||
$filelist = array();
|
||||
foreach ($list as $key => $v) {
|
||||
if ($v != '.' && $v != '..') {
|
||||
if (is_dir($dir . '/' . $v)) {
|
||||
$dirlist['dir'][$key] = $v;
|
||||
}
|
||||
if (is_file($dir . '/' . $v)) {
|
||||
$filelist['file'][$key] = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
$filesarr = array_merge($dirlist, $filelist);
|
||||
print_r($filesarr);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件夹中的文件 包括子文件 不能直接用 直接使用 $this->getDir()方法 P156
|
||||
* @param $path
|
||||
* @param $data
|
||||
*/
|
||||
public function searchDir($path, &$data)
|
||||
{
|
||||
if (is_dir($path) && !strpos($path, 'uploads')) {
|
||||
$dp = dir($path);
|
||||
while ($file = $dp->read()) {
|
||||
if ($file != '.' && $file != '..') {
|
||||
$this->searchDir($path . '/' . $file, $data);
|
||||
}
|
||||
}
|
||||
$dp->close();
|
||||
}
|
||||
if (is_file($path)) {
|
||||
$data[] = $path;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件夹中的文件 包括子文件
|
||||
* @param $dir
|
||||
* @return array
|
||||
*/
|
||||
public function getDir($dir)
|
||||
{
|
||||
$data = array();
|
||||
$this->searchDir($dir, $data);
|
||||
return $data;
|
||||
}
|
||||
|
||||
//测试
|
||||
public function ceshi()
|
||||
{
|
||||
//创建form
|
||||
$form = Form::create('/save.php', [
|
||||
Form::input('goods_name', '商品名称')
|
||||
, Form::input('goods_name1', 'password')->type('password')
|
||||
, Form::input('goods_name2', 'textarea')->type('textarea')
|
||||
, Form::input('goods_name3', 'email')->type('email')
|
||||
, Form::input('goods_name4', 'date')->type('date')
|
||||
, Form::city('address', 'cityArea',
|
||||
'陕西省', '西安市'
|
||||
)
|
||||
, Form::dateRange('limit_time', 'dateRange',
|
||||
strtotime('- 10 day'),
|
||||
time()
|
||||
)
|
||||
, Form::dateTime('add_time', 'dateTime')
|
||||
, Form::color('color', 'color', '#ff0000')
|
||||
, Form::checkbox('checkbox', 'checkbox', [1])->options([['value' => 1, 'label' => '白色'], ['value' => 2, 'label' => '红色'], ['value' => 31, 'label' => '黑色']])
|
||||
, Form::date('riqi', 'date', '2018-03-1')
|
||||
, Form::dateTimeRange('dateTimeRange', '区间时间段')
|
||||
, Form::year('year', 'year')
|
||||
, Form::month('month', 'month')
|
||||
, Form::frame('frame', 'frame', '/admin/system.system_attachment/index.html?fodder=frame')
|
||||
, Form::frameInputs('frameInputs', 'frameInputs', '/admin/system.system_attachment/index.html?fodder=frameInputs')
|
||||
, Form::frameFiles('month1', 'frameFiles', '/admin/system.system_attachment/index.html?fodder=month1')
|
||||
, Form::frameImages('fodder1', 'frameImages', '/admin/system.system_attachment/index.html?fodder=fodder1')->maxLength(3)->width('800px')->height('400px')
|
||||
, Form::frameImages('fodder11', 'frameImages', '/admin/system.system_attachment/index.html?fodder=fodder11')->icon('images')
|
||||
, Form::frameInputOne('month3', 'frameInputOne', '/admin/system.system_attachment/index.html?fodder=month3')->icon('ionic')
|
||||
, Form::frameFileOne('month4', 'frameFileOne', '/admin/system.system_attachment/index.html?fodder=month4')
|
||||
, Form::frameImageOne('month5', 'frameImageOne', '/admin/system.system_attachment/index.html?fodder=month5')->icon('image')
|
||||
, Form::hidden('month6', 'hidden')
|
||||
, Form::number('month7', 'number')
|
||||
// ,Form::input input输入框,其他type: text类型Form::text,password类型Form::password,textarea类型Form::textarea,url类型Form::url,email类型Form::email,date类型Form::idate
|
||||
, Form::radio('month8', 'radio')->options([['value' => 1, 'label' => '白色'], ['value' => 2, 'label' => '红色'], ['value' => 31, 'label' => '黑色']])
|
||||
, Form::rate('month9', 'rate')
|
||||
, Form::select('month10', 'select')->options([['value' => 1, 'label' => '白色'], ['value' => 2, 'label' => '红色'], ['value' => 31, 'label' => '黑色']])
|
||||
, Form::selectMultiple('month11', 'selectMultiple')
|
||||
, Form::selectOne('month12', 'selectOne')
|
||||
, Form::slider('month13', 'slider', 2)
|
||||
, Form::sliderRange('month23', 'sliderRange', 2, 13)
|
||||
, Form::switches('month14', '区间时间段')
|
||||
, Form::timePicker('month15', '区间时间段')
|
||||
, Form::time('month16', '区间时间段')
|
||||
, Form::timeRange('month17', '区间时间段')
|
||||
// ,Form::upload('month','区间时间段')
|
||||
// ,Form::uploadImages('month','区间时间段')
|
||||
// ,Form::uploadFiles('month','区间时间段')
|
||||
// ,Form::uploadImageOne('month','区间时间段')
|
||||
// ,Form::uploadFileOne('month','区间时间段')
|
||||
|
||||
]);
|
||||
$html = $form->setMethod('get')->setTitle('编辑商品')->view();
|
||||
echo $html;
|
||||
}
|
||||
}
|
||||
42
app/admin/controller/system/SystemLog.php
Normal file
42
app/admin/controller/system/SystemLog.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\system;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use app\admin\model\system\SystemAdmin;
|
||||
use app\admin\model\system\SystemLog as LogModel;
|
||||
use crmeb\services\UtilService as Util;
|
||||
|
||||
/**
|
||||
* 管理员操作记录表控制器
|
||||
* Class SystemLog
|
||||
* @package app\admin\controller\system
|
||||
*/
|
||||
class SystemLog extends AuthController
|
||||
|
||||
{
|
||||
|
||||
/**
|
||||
* 显示操作记录
|
||||
*/
|
||||
public function index(){
|
||||
LogModel::deleteLog();
|
||||
$where = Util::getMore([
|
||||
['pages',''],
|
||||
['path',''],
|
||||
['ip',''],
|
||||
['admin_id',''],
|
||||
['data',''],
|
||||
],$this->request);
|
||||
$where['level'] = $this->adminInfo['level'];
|
||||
$this->assign('where',$where);
|
||||
$this->assign('admin',SystemAdmin::getOrdAdmin('id,real_name',$this->adminInfo['level']));
|
||||
$this->assign(LogModel::systemPage($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
196
app/admin/controller/system/SystemUpgradeclient.php
Normal file
196
app/admin/controller/system/SystemUpgradeclient.php
Normal file
@ -0,0 +1,196 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\system;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use crmeb\services\JsonService as Json;
|
||||
use crmeb\services\UpgradeService as uService;
|
||||
use think\facade\Db;
|
||||
use app\admin\model\system\SystemConfig;
|
||||
/**
|
||||
* 在线升级控制器
|
||||
* Class SystemUpgradeclient
|
||||
* @package app\admin\controller\system
|
||||
*
|
||||
*/
|
||||
class SystemUpgradeclient extends AuthController
|
||||
{
|
||||
|
||||
protected $serverweb = array('version'=>'1.0','version_code'=>0);//本站点信息
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
//屏蔽所有错误避免操作文件夹发生错误提示
|
||||
ini_set('display_errors',0);
|
||||
error_reporting(0);
|
||||
self::snyweninfo();//更新站点信息
|
||||
$this->assign(['auth'=>self::isauth(),'app'=>uService::isWritable(app()->getRootPath()),'extend'=>uService::isWritable(EXTEND_PATH),'public'=>uService::isWritable(app()->getRootPath().'public')]);
|
||||
}
|
||||
//同步更新站点信息
|
||||
public function snyweninfo(){
|
||||
$this->serverweb['ip'] = $this->request->ip();
|
||||
$this->serverweb['host'] = $this->request->host();
|
||||
$this->serverweb['https'] = !empty($this->request->domain())?$this->request->domain():SystemConfig::getConfigValue('site_url');
|
||||
$this->serverweb['webname'] = SystemConfig::getConfigValue('site_name');
|
||||
$local=uService::getVersion();
|
||||
if($local['code']==200 && isset($local['msg']['version']) && isset($local['msg']['version_code'])){
|
||||
$this->serverweb['version'] = uService::replace($local['msg']['version']);
|
||||
$this->serverweb['version_code'] = (int)uService::replace($local['msg']['version_code']);
|
||||
}
|
||||
uService::snyweninfo($this->serverweb);
|
||||
}
|
||||
//是否授权
|
||||
public function isauth(){
|
||||
return uService::isauth();
|
||||
}
|
||||
public function index(){
|
||||
$server=uService::start();
|
||||
$version=$this->serverweb['version'];
|
||||
$version_code=$this->serverweb['version_code'];
|
||||
$this->assign(compact('server','version','version_code'));
|
||||
return $this->fetch();
|
||||
}
|
||||
public function get_list(){
|
||||
$list=uService::request_post(uService::$isList,['page'=>input('post.page/d'),'limit'=>input('post.limit/d')]);
|
||||
if(is_array($list) && isset($list['code']) && isset($list['data']) && $list['code']==200){
|
||||
$list=$list['data'];
|
||||
}else{
|
||||
$list=[];
|
||||
}
|
||||
Json::successful('ok',['list'=>$list,'page'=>input('post.page/d')+1]);
|
||||
}
|
||||
//删除备份文件
|
||||
public function setcopydel(){
|
||||
$post=input('post.');
|
||||
if(!isset($post['id'])) Json::fail('删除备份文件失败,缺少参数ID');
|
||||
if(!isset($post['ids'])) Json::fail('删除备份文件失败,缺少参数IDS');
|
||||
$fileservice=new uService;
|
||||
if(is_array($post['ids'])){
|
||||
foreach ($post['ids'] as $file){
|
||||
$fileservice->del_dir(app()->getRootPath().'public'.DS.'copyfile'.$file);
|
||||
}
|
||||
}
|
||||
if($post['id']){
|
||||
$copyFile=app()->getRootPath().'public'.DS.'copyfile'.$post['id'];
|
||||
$fileservice->del_dir($copyFile);
|
||||
}
|
||||
Json::successful('删除成功');
|
||||
}
|
||||
public function get_new_version_conte(){
|
||||
$post=$this->request->post();
|
||||
if(!isset($post['id'])) Json::fail('缺少参数ID');
|
||||
$versionInfo=uService::request_post(uService::$NewVersionCount,['id'=>$post['id']]);
|
||||
if(isset($versionInfo['code']) && isset($versionInfo['data']['count']) && $versionInfo['code']==200){
|
||||
return Json::successful(['count'=>$versionInfo['data']['count']]);
|
||||
}else{
|
||||
return Json::fail('服务器异常');
|
||||
}
|
||||
}
|
||||
//一键升级
|
||||
public function auto_upgrad(){
|
||||
$prefix=config('database.prefix');
|
||||
$fileservice=new uService;
|
||||
$post=$this->request->post();
|
||||
if(!isset($post['id'])) Json::fail('缺少参数ID');
|
||||
$versionInfo=$fileservice->request_post(uService::$isNowVersion,['id'=>$post['id']]);
|
||||
if($versionInfo===null) Json::fail('服务器异常,请稍后再试');
|
||||
if(isset($versionInfo['code']) && $versionInfo['code']==400) Json::fail(isset($versionInfo['msg'])?$versionInfo['msg']:'您暂时没有权限升级,请联系管理员!');
|
||||
if(is_array($versionInfo) && isset($versionInfo['data'])){
|
||||
$list=$versionInfo['data'];
|
||||
$id=[];
|
||||
foreach ($list as $key=>$val){
|
||||
$savefile=app()->getRootPath() . 'public' . DS.'upgrade_lv';
|
||||
//1,检查远程下载文件,并下载
|
||||
if(($save_path=$fileservice->check_remote_file_exists($val['zip_name'],$savefile))===false) Json::fail('远程升级包不存在');
|
||||
//2,首先解压文件
|
||||
$savename=app()->getRootPath().'public'.DS.'upgrade_lv'.DS.time();
|
||||
$fileservice->zipopen($save_path,$savename);
|
||||
//3,执行SQL文件
|
||||
Db::startTrans();
|
||||
try{
|
||||
//参数3不介意大小写的
|
||||
$sqlfile=$fileservice->list_dir_info($savename.DS,true,'sql');
|
||||
if(is_array($sqlfile) && !empty($sqlfile)){
|
||||
foreach($sqlfile as $file){
|
||||
if(file_exists($file)){
|
||||
//为一键安装做工作记得表前缀要改为[#DB_PREFIX#]哦
|
||||
$execute_sql=explode(";\r",str_replace(['[#DB_PREFIX#]', "\n"], [$prefix, "\r"], file_get_contents($file)));
|
||||
foreach($execute_sql as $_sql){
|
||||
if ($query_string = trim(str_replace(array(
|
||||
"\r",
|
||||
"\n",
|
||||
"\t"
|
||||
), '', $_sql))) Db::execute($query_string);
|
||||
}
|
||||
//执行完sql记得删掉哦
|
||||
$fileservice->unlink_file($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
Db::commit();
|
||||
}catch(\Exception $e){
|
||||
Db::rollback();
|
||||
//删除解压下的文件
|
||||
$fileservice->del_dir(app()->getRootPath().'public'.DS.'upgrade_lv');
|
||||
//删除压缩包
|
||||
$fileservice->unlink_file($save_path);
|
||||
//升级失败发送错误信息
|
||||
$fileservice->request_post(uService::$isInsertLog,[
|
||||
'content'=>'升级失败,错误信息为:'.$e->getMessage(),
|
||||
'add_time'=>time(),
|
||||
'ip'=>$this->request->ip(),
|
||||
'http'=>$this->request->domain(),
|
||||
'type'=>'error',
|
||||
'version'=>$val['version']
|
||||
]);
|
||||
return Json::fail('升级失败SQL文件执行有误');
|
||||
}
|
||||
//4,备份文件
|
||||
$copyFile=app()->getRootPath().'public'.DS.'copyfile'.$val['id'];
|
||||
$copyList=$fileservice->get_dirs($savename.DS);
|
||||
if(isset($copyList['dir'])){
|
||||
if($copyList['dir'][0]=='.' && $copyList['dir'][1]=='..'){
|
||||
array_shift($copyList['dir']);
|
||||
array_shift($copyList['dir']);
|
||||
}
|
||||
foreach($copyList['dir'] as $dir){
|
||||
if(file_exists(app()->getRootPath().$dir,$copyFile.DS.$dir)){
|
||||
$fileservice->copy_dir(app()->getRootPath().$dir,$copyFile.DS.$dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
//5,覆盖文件
|
||||
$fileservice->handle_dir($savename,app()->getRootPath());
|
||||
//6,删除升级生成的目录
|
||||
$fileservice->del_dir(app()->getRootPath().'public'.DS.'upgrade_lv');
|
||||
//7,删除压缩包
|
||||
$fileservice->unlink_file($save_path);
|
||||
//8,改写本地升级文件
|
||||
$handle=fopen(app()->getRootPath().'.version','w+');
|
||||
if($handle===false) Json::fail(app()->getRootPath().'.version'.'无法写入打开');
|
||||
$content=<<<EOT
|
||||
version={$val['version']}
|
||||
version_code={$val['id']}
|
||||
EOT;
|
||||
if(fwrite($handle,$content)===false) Json::fail('升级包写入失败');
|
||||
fclose($handle);
|
||||
//9,向服务端发送升级日志
|
||||
$posts=[
|
||||
'ip'=>$this->request->ip(),
|
||||
'https'=>$this->request->domain(),
|
||||
'update_time'=>time(),
|
||||
'content'=>'一键升级成功,升级版本号为:'.$val['version'].'。版本code为:'.$val['id'],
|
||||
'type'=>'log',
|
||||
'versionbefor'=>$this->serverweb['version'],
|
||||
'versionend'=>$val['version']
|
||||
];
|
||||
$inset=$fileservice->request_post(uService::$isInsertLog,$posts);
|
||||
$id[]=$val['id'];
|
||||
}
|
||||
//10,升级完成
|
||||
Json::successful('升级成功',['code'=>end($id),'version'=>$val['version']]);
|
||||
}else{
|
||||
Json::fail('服务器异常,请稍后再试');
|
||||
}
|
||||
}
|
||||
}
|
||||
274
app/admin/controller/ump/StoreCoupon.php
Normal file
274
app/admin/controller/ump/StoreCoupon.php
Normal file
@ -0,0 +1,274 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\ump;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use app\admin\model\ump\StoreCouponIssue;
|
||||
use app\admin\model\wechat\WechatUser as UserModel;
|
||||
use crmeb\services\FormBuilder as Form;
|
||||
use crmeb\services\JsonService;
|
||||
use crmeb\services\UtilService as Util;
|
||||
use crmeb\services\JsonService as Json;
|
||||
use crmeb\services\UtilService;
|
||||
use app\admin\model\ump\StoreCoupon as CouponModel;
|
||||
use think\facade\Route as Url;
|
||||
|
||||
/**
|
||||
* 优惠券控制器
|
||||
* Class StoreCategory
|
||||
* @package app\admin\controller\system
|
||||
*/
|
||||
class StoreCoupon extends AuthController
|
||||
{
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$where = Util::getMore([
|
||||
['status',''],
|
||||
['title',''],
|
||||
],$this->request);
|
||||
$this->assign('where',$where);
|
||||
$this->assign(CouponModel::systemPage($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$f = array();
|
||||
$f[] = Form::input('title','优惠券名称');
|
||||
$f[] = Form::number('coupon_price','优惠券面值',0)->min(0);
|
||||
$f[] = Form::number('use_min_price','优惠券最低消费')->min(0);
|
||||
$f[] = Form::number('coupon_time','优惠券有效期限')->min(0);
|
||||
$f[] = Form::number('sort','排序');
|
||||
$f[] = Form::radio('status','状态',0)->options([['label'=>'开启','value'=>1],['label'=>'关闭','value'=>0]]);
|
||||
|
||||
$form = Form::make_post_form('添加优惠券',$f,Url::buildUrl('save'));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'title',
|
||||
'coupon_price',
|
||||
'use_min_price',
|
||||
'coupon_time',
|
||||
'sort',
|
||||
['status',0]
|
||||
]);
|
||||
if(!$data['title']) return Json::fail('请输入优惠券名称');
|
||||
if(!$data['coupon_price']) return Json::fail('请输入优惠券面值');
|
||||
if(!$data['coupon_time']) return Json::fail('请输入优惠券有效期限');
|
||||
$data['add_time'] = time();
|
||||
CouponModel::create($data);
|
||||
return Json::successful('添加优惠券成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
* @param $id
|
||||
* @return string|void
|
||||
* @throws \FormBuilder\exception\FormBuilderException
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$coupon = CouponModel::get($id);
|
||||
if(!$coupon) return Json::fail('数据不存在!');
|
||||
$f = array();
|
||||
$f[] = Form::input('title','优惠券名称',$coupon->getData('title'));
|
||||
$f[] = Form::number('coupon_price','优惠券面值',$coupon->getData('coupon_price'))->min(0);
|
||||
$f[] = Form::number('use_min_price','优惠券最低消费',$coupon->getData('use_min_price'))->min(0);
|
||||
$f[] = Form::number('coupon_time','优惠券有效期限',$coupon->getData('coupon_time'))->min(0);
|
||||
$f[] = Form::number('sort','排序',$coupon->getData('sort'));
|
||||
$f[] = Form::radio('status','状态',$coupon->getData('status'))->options([['label'=>'开启','value'=>1],['label'=>'关闭','value'=>0]]);
|
||||
|
||||
$form = Form::make_post_form('添加优惠券',$f,Url::buildUrl('update',array('id'=>$id)));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 保存更新的资源
|
||||
*
|
||||
* @param $id
|
||||
*/
|
||||
public function update($id)
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'title',
|
||||
'coupon_price',
|
||||
'use_min_price',
|
||||
'coupon_time',
|
||||
'sort',
|
||||
['status',0]
|
||||
]);
|
||||
if(!$data['title']) return Json::fail('请输入优惠券名称');
|
||||
if(!$data['coupon_price']) return Json::fail('请输入优惠券面值');
|
||||
if(!$data['coupon_time']) return Json::fail('请输入优惠券有效期限');
|
||||
CouponModel::edit($data,$id);
|
||||
return Json::successful('修改成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
if(!$id) return Json::fail('数据不存在!');
|
||||
$data['is_del'] = 1;
|
||||
if(!CouponModel::edit($data,$id))
|
||||
return Json::fail(CouponModel::getErrorInfo('删除失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('删除成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改优惠券状态
|
||||
* @param $id
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function status($id)
|
||||
{
|
||||
if(!$id) return Json::fail('数据不存在!');
|
||||
if(!CouponModel::editIsDel($id))
|
||||
return Json::fail(CouponModel::getErrorInfo('修改失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('修改成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function grant_subscribe(){
|
||||
$where = Util::getMore([
|
||||
['status',''],
|
||||
['title',''],
|
||||
['is_del',0],
|
||||
],$this->request);
|
||||
$this->assign('where',$where);
|
||||
$this->assign(CouponModel::systemPageCoupon($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function grant_all(){
|
||||
$where = Util::getMore([
|
||||
['status',''],
|
||||
['title',''],
|
||||
['is_del',0],
|
||||
],$this->request);
|
||||
$this->assign('where',$where);
|
||||
$this->assign(CouponModel::systemPageCoupon($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
*/
|
||||
public function grant($id){
|
||||
$where = Util::getMore([
|
||||
['status',''],
|
||||
['title',''],
|
||||
['is_del',0],
|
||||
],$this->request);
|
||||
$nickname = UserModel::where('uid','IN',$id)->column('nickname','uid');
|
||||
$this->assign('where',$where);
|
||||
$this->assign('uid',$id);
|
||||
$this->assign('nickname',implode(',',$nickname));
|
||||
$this->assign(CouponModel::systemPageCoupon($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function issue($id)
|
||||
{
|
||||
if(!CouponModel::be(['id'=>$id,'status'=>1,'is_del'=>0]))
|
||||
return $this->failed('发布的优惠劵已失效或不存在!');
|
||||
$f = array();
|
||||
$f[] = Form::input('id','优惠劵ID',$id)->disabled(1);
|
||||
$f[] = Form::dateTimeRange('range_date','领取时间')->placeholder('不填为永久有效');
|
||||
$f[] = Form::number('count','发布数量',0)->min(0)->placeholder('不填或填0,为不限量');
|
||||
$f[] = Form::radio('is_permanent','是否不限量',0)->options([['label'=>'限量','value'=>0],['label'=>'不限量','value'=>1]]);
|
||||
$f[] = Form::radio('status','状态',1)->options([['label'=>'开启','value'=>1],['label'=>'关闭','value'=>0]]);
|
||||
|
||||
$form = Form::make_post_form('添加优惠券',$f,Url::buildUrl('update_issue',array('id'=>$id)));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
|
||||
// FormBuilder::text('id','优惠劵ID',$id)->disabled();
|
||||
// FormBuilder::dateTimeRange('range_date','领取时间')->placeholder('不填为永久有效');
|
||||
// FormBuilder::text('count','发布数量')->placeholder('不填或填0,为不限量');
|
||||
// FormBuilder::radio('status','是否开启',[
|
||||
// ['value'=>1,'label'=>'开启'],
|
||||
// ['value'=>0,'label'=>'关闭']
|
||||
// ],1);
|
||||
// $this->assign(['title'=>'发布优惠券','rules'=>FormBuilder::builder()->getContent(),'action'=>Url::buildUrl('update_issue',array('id'=>$id))]);
|
||||
// return $this->fetch('public/common_form');
|
||||
}
|
||||
|
||||
public function update_issue($id)
|
||||
{
|
||||
list($_id,$rangeTime,$count,$status,$is_permanent) = UtilService::postMore([
|
||||
'id',['range_date',['','']],['count',0],['status',0],['is_permanent',0]
|
||||
],null,true);
|
||||
if($_id != $id) return JsonService::fail('操作失败,信息不对称');
|
||||
if(!$count) $count = 0;
|
||||
if(!CouponModel::be(['id'=>$id,'status'=>1,'is_del'=>0])) return JsonService::fail('发布的优惠劵已失效或不存在!');
|
||||
if(count($rangeTime)!=2) return JsonService::fail('请选择正确的时间区间');
|
||||
|
||||
list($startTime,$endTime) = $rangeTime;
|
||||
// echo $startTime;echo $endTime;var_dump($rangeTime);die;
|
||||
if(!$startTime) $startTime = 0;
|
||||
if(!$endTime) $endTime = 0;
|
||||
if(!$startTime && $endTime) return JsonService::fail('请选择正确的开始时间');
|
||||
if($startTime && !$endTime) return JsonService::fail('请选择正确的结束时间');
|
||||
if(StoreCouponIssue::setIssue($id,$count,strtotime($startTime),strtotime($endTime),$count,$status,$is_permanent))
|
||||
return JsonService::successful('发布优惠劵成功!');
|
||||
else
|
||||
return JsonService::fail('发布优惠劵失败!');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 给分组用户发放优惠券
|
||||
*/
|
||||
public function grant_group(){
|
||||
$where = Util::getMore([
|
||||
['status',''],
|
||||
['title',''],
|
||||
['is_del',0],
|
||||
],$this->request);
|
||||
$group = UserModel::getUserGroup();
|
||||
$this->assign('where',$where);
|
||||
$this->assign('group',json_encode($group));
|
||||
$this->assign(CouponModel::systemPageCoupon($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
/**
|
||||
* 给标签用户发放优惠券
|
||||
*/
|
||||
public function grant_tag(){
|
||||
$where = Util::getMore([
|
||||
['status',''],
|
||||
['title',''],
|
||||
['is_del',0],
|
||||
],$this->request);
|
||||
$tag = UserModel::getUserTag();;//获取所有标签
|
||||
$this->assign('where',$where);
|
||||
$this->assign('tag',json_encode($tag));
|
||||
$this->assign(CouponModel::systemPageCoupon($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
63
app/admin/controller/ump/StoreCouponIssue.php
Normal file
63
app/admin/controller/ump/StoreCouponIssue.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2018/01/17
|
||||
*/
|
||||
|
||||
namespace app\admin\controller\ump;
|
||||
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use crmeb\services\FormBuilder as Form;
|
||||
use app\admin\model\ump\StoreCouponIssue as CouponIssueModel;
|
||||
use app\admin\model\ump\StoreCouponIssueUser;
|
||||
use crmeb\services\JsonService;
|
||||
use think\facade\Route as Url;
|
||||
use crmeb\traits\CurdControllerTrait;
|
||||
use crmeb\services\UtilService as Util;
|
||||
|
||||
class StoreCouponIssue extends AuthController
|
||||
{
|
||||
use CurdControllerTrait;
|
||||
|
||||
protected $bindModel = CouponIssueModel::class;
|
||||
|
||||
public function index()
|
||||
{
|
||||
$where=Util::getMore([
|
||||
['status',''],
|
||||
['coupon_title','']
|
||||
]);
|
||||
$this->assign(CouponIssueModel::stsypage($where));
|
||||
$this->assign('where',$where);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function delete($id = '')
|
||||
{
|
||||
if(!$id) return JsonService::fail('参数有误!');
|
||||
if(CouponIssueModel::edit(['is_del'=>1],$id,'id'))
|
||||
return JsonService::successful('删除成功!');
|
||||
else
|
||||
return JsonService::fail('删除失败!');
|
||||
}
|
||||
|
||||
public function edit($id = '')
|
||||
{
|
||||
if(!$id) return JsonService::fail('参数有误!');
|
||||
$issueInfo = CouponIssueModel::get($id);
|
||||
if(-1 == $issueInfo['status'] || 1 == $issueInfo['is_del']) return $this->failed('状态错误,无法修改');
|
||||
$f = [Form::radio('status','是否开启',$issueInfo['status'])->options([['label'=>'开启','value'=>1],['label'=>'关闭','value'=>0]])];
|
||||
$form = Form::make_post_form('状态修改',$f,Url::buildUrl('change_field',array('id'=>$id,'field'=>'status')));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
public function issue_log($id = '')
|
||||
{
|
||||
if(!$id) return JsonService::fail('参数有误!');
|
||||
$this->assign(StoreCouponIssueUser::systemCouponIssuePage($id));
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
113
app/admin/controller/ump/StoreCouponUser.php
Normal file
113
app/admin/controller/ump/StoreCouponUser.php
Normal file
@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\ump;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use app\admin\model\wechat\WechatUser;
|
||||
use crmeb\services\UtilService as Util;
|
||||
use crmeb\services\JsonService as Json;
|
||||
use app\admin\model\ump\StoreCoupon as CouponModel;
|
||||
use app\admin\model\ump\StoreCouponUser as CouponUserModel;
|
||||
use app\admin\model\wechat\WechatUser as UserModel;
|
||||
|
||||
/**
|
||||
* 优惠券发放记录控制器
|
||||
* Class StoreCategory
|
||||
* @package app\admin\controller\system
|
||||
*/
|
||||
class StoreCouponUser extends AuthController
|
||||
{
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$where = Util::getMore([
|
||||
['status',''],
|
||||
['is_fail',''],
|
||||
['coupon_title',''],
|
||||
['nickname',''],
|
||||
],$this->request);
|
||||
$this->assign('where',$where);
|
||||
$this->assign(CouponUserModel::systemPage($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 给已关注的用户发放优惠券
|
||||
* @param $id
|
||||
*/
|
||||
public function grant_subscribe($id){
|
||||
if(!$id) return Json::fail('数据不存在!');
|
||||
$coupon = CouponModel::get($id)->toArray();
|
||||
if(!$coupon) return Json::fail('数据不存在!');
|
||||
$user = UserModel::getSubscribe('uid');
|
||||
if(!CouponUserModel::setCoupon($coupon,$user))
|
||||
return Json::fail(CouponUserModel::getErrorInfo('发放失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('发放成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 给所有人发放优惠券
|
||||
* @param $id
|
||||
*/
|
||||
public function grant_all($id){
|
||||
if(!$id) return Json::fail('数据不存在!');
|
||||
$coupon = CouponModel::get($id)->toArray();
|
||||
if(!$coupon) return Json::fail('数据不存在!');
|
||||
$user = UserModel::getUserAll('uid');
|
||||
if(!CouponUserModel::setCoupon($coupon,$user))
|
||||
return Json::fail(CouponUserModel::getErrorInfo('发放失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('发放成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 发放优惠券到指定个人
|
||||
* @param $id
|
||||
* @param $uid
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function grant($id,$uid){
|
||||
if(!$id) return Json::fail('数据不存在!');
|
||||
$coupon = CouponModel::get($id)->toArray();
|
||||
if(!$coupon) return Json::fail('数据不存在!');
|
||||
$user = explode(',',$uid);
|
||||
if(!CouponUserModel::setCoupon($coupon,$user))
|
||||
return Json::fail(CouponUserModel::getErrorInfo('发放失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('发放成功!');
|
||||
|
||||
}
|
||||
|
||||
public function grant_group($id){
|
||||
$data = Util::postMore([
|
||||
['group',0]
|
||||
]);
|
||||
if(!$id) return Json::fail('数据不存在!');
|
||||
$coupon = CouponModel::get($id)->toArray();
|
||||
if(!$coupon) return Json::fail('数据不存在!');
|
||||
$user = WechatUser::where('groupid',$data['group'])->column('uid','uid');
|
||||
if(!CouponUserModel::setCoupon($coupon,$user))
|
||||
return Json::fail(CouponUserModel::getErrorInfo('发放失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('发放成功!');
|
||||
}
|
||||
|
||||
public function grant_tag($id){
|
||||
$data = Util::postMore([
|
||||
['tag',0]
|
||||
]);
|
||||
if(!$id) return Json::fail('数据不存在!');
|
||||
$coupon = CouponModel::get($id)->toArray();
|
||||
if(!$coupon) return Json::fail('数据不存在!');
|
||||
$user = WechatUser::where("tagid_list","LIKE","%$data[tag]%")->column('uid','uid');
|
||||
if(!CouponUserModel::setCoupon($coupon,$user))
|
||||
return Json::fail(CouponUserModel::getErrorInfo('发放失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('发放成功!');
|
||||
}
|
||||
|
||||
}
|
||||
377
app/admin/controller/ump/StoreSeckill.php
Normal file
377
app/admin/controller/ump/StoreSeckill.php
Normal file
@ -0,0 +1,377 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\ump;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use crmeb\services\FormBuilder as Form;
|
||||
use crmeb\traits\CurdControllerTrait;
|
||||
use crmeb\services\UtilService as Util;
|
||||
use crmeb\services\JsonService as Json;
|
||||
use crmeb\services\UploadService as Upload;
|
||||
use app\admin\model\store\StoreProduct as ProductModel;
|
||||
use think\facade\Route as Url;
|
||||
use app\admin\model\ump\StoreSeckillAttr;
|
||||
use app\admin\model\ump\StoreSeckillAttrResult;
|
||||
use app\admin\model\ump\StoreSeckill as StoreSeckillModel;
|
||||
use app\admin\model\system\SystemAttachment;
|
||||
|
||||
/**
|
||||
* 限时秒杀 控制器
|
||||
* Class StoreSeckill
|
||||
* @package app\admin\controller\store
|
||||
*/
|
||||
class StoreSeckill extends AuthController
|
||||
{
|
||||
|
||||
use CurdControllerTrait;
|
||||
|
||||
protected $bindModel = StoreSeckillModel::class;
|
||||
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->assign('countSeckill',StoreSeckillModel::getSeckillCount());
|
||||
$this->assign('seckillId',StoreSeckillModel::getSeckillIdAll());
|
||||
return $this->fetch();
|
||||
}
|
||||
public function save_excel(){
|
||||
$where=Util::getMore([
|
||||
['status',''],
|
||||
['store_name','']
|
||||
]);
|
||||
StoreSeckillModel::SaveExcel($where);
|
||||
}
|
||||
/**
|
||||
* 异步获取砍价数据
|
||||
*/
|
||||
public function get_seckill_list(){
|
||||
$where=Util::getMore([
|
||||
['page',1],
|
||||
['limit',20],
|
||||
['status',''],
|
||||
['store_name','']
|
||||
]);
|
||||
$seckillList = StoreSeckillModel::systemPage($where);
|
||||
if(is_object($seckillList['list'])) $seckillList['list'] = $seckillList['list']->toArray();
|
||||
$data = $seckillList['list']['data'];
|
||||
foreach ($data as $k=>$v){
|
||||
$data[$k]['_stop_time'] =$v['stop_time'] ? date('Y/m/d H:i:s',$v['stop_time']) : '';
|
||||
}
|
||||
return Json::successlayui(['count'=>$seckillList['list']['total'],'data'=>$data]);
|
||||
}
|
||||
|
||||
public function get_seckill_id(){
|
||||
return Json::successlayui(StoreSeckillModel::getSeckillIdAll());
|
||||
}
|
||||
/**
|
||||
* 添加秒杀产品
|
||||
* @return form-builder
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$f = array();
|
||||
$f[] = Form::input('title','产品标题');
|
||||
$f[] = Form::input('info','秒杀活动简介')->type('textarea');
|
||||
$f[] = Form::input('unit_name','单位')->placeholder('个、位');
|
||||
$f[] = Form::dateTimeRange('section_time','活动时间');
|
||||
$f[] = Form::frameImageOne('image','产品主图片(305*305px)',Url::buildUrl('admin/widget.images/index',array('fodder'=>'image')))->icon('image')->width('100%')->height('500px');
|
||||
$f[] = Form::frameImages('images','产品轮播图(640*640px)',Url::buildUrl('admin/widget.images/index',array('fodder'=>'images')))->maxLength(5)->icon('images')->width('100%')->height('500px');
|
||||
$f[] = Form::number('price','秒杀价')->min(0)->col(12);
|
||||
$f[] = Form::number('ot_price','原价')->min(0)->col(12);
|
||||
$f[] = Form::number('cost','成本价')->min(0)->col(12);
|
||||
$f[] = Form::number('stock','库存')->min(0)->precision(0)->col(12);
|
||||
$f[] = Form::number('sales','销量')->min(0)->precision(0)->col(12);
|
||||
$f[] = Form::number('sort','排序')->col(12);
|
||||
$f[] = Form::number('num','单次购买产品个数')->precision(0)->col(12);
|
||||
$f[] = Form::number('give_integral','赠送积分')->min(0)->precision(0)->col(12);
|
||||
$f[] = Form::number('postage','邮费')->min(0)->col(12);
|
||||
$f[] = Form::radio('is_postage','是否包邮',1)->options([['label'=>'是','value'=>1],['label'=>'否','value'=>0]])->col(12);
|
||||
$f[] = Form::radio('is_hot','热门推荐',1)->options([['label'=>'开启','value'=>1],['label'=>'关闭','value'=>0]])->col(12);
|
||||
$f[] = Form::radio('status','活动状态',1)->options([['label'=>'开启','value'=>1],['label'=>'关闭','value'=>0]])->col(12);
|
||||
$form = Form::make_post_form('添加用户通知',$f,Url::buildUrl('save'));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存秒杀产品
|
||||
* @param int $id
|
||||
*/
|
||||
public function save($id = 0)
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'title',
|
||||
'product_id',
|
||||
'info',
|
||||
'unit_name',
|
||||
['image',''],
|
||||
['images',[]],
|
||||
'price',
|
||||
'ot_price',
|
||||
'cost',
|
||||
'sales',
|
||||
'stock',
|
||||
'sort',
|
||||
'give_integral',
|
||||
'postage',
|
||||
['section_time',[]],
|
||||
['is_postage',0],
|
||||
['cost',0],
|
||||
['is_hot',0],
|
||||
['status',0],
|
||||
['num',0]
|
||||
]);
|
||||
if(!$data['title']) return Json::fail('请输入产品标题');
|
||||
if(!$data['unit_name']) return Json::fail('请输入产品单位');
|
||||
if(!$data['product_id']) return Json::fail('产品ID不能为空');
|
||||
if(count($data['section_time'])<1) return Json::fail('请选择活动时间');
|
||||
$data['start_time'] = strtotime($data['section_time'][0]);
|
||||
$data['stop_time'] = strtotime($data['section_time'][1]);
|
||||
unset($data['section_time']);
|
||||
if(!$data['image']) return Json::fail('请选择推荐图');
|
||||
if(count($data['images'])<1) return Json::fail('请选择轮播图');
|
||||
$data['images'] = json_encode($data['images']);
|
||||
if($data['price'] == '' || $data['price'] < 0) return Json::fail('请输入产品秒杀售价');
|
||||
if($data['ot_price'] == '' || $data['ot_price'] < 0) return Json::fail('请输入产品原售价');
|
||||
if($data['cost'] == '' || $data['cost'] < 0) return Json::fail('请输入产品成本价');
|
||||
if($data['stock'] == '' || $data['stock'] < 0) return Json::fail('请输入库存');
|
||||
if($data['num']<1) return Json::fail('请输入单次秒杀个数');
|
||||
if($id){
|
||||
$product = StoreSeckillModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
StoreSeckillModel::edit($data,$id);
|
||||
return Json::successful('编辑成功!');
|
||||
}else{
|
||||
$data['add_time'] = time();
|
||||
StoreSeckillModel::create($data);
|
||||
return Json::successful('添加成功!');
|
||||
}
|
||||
|
||||
}
|
||||
/** 开启秒杀
|
||||
* @param $id
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function seckill($id){
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = ProductModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
$f = array();
|
||||
$f[] = Form::input('title','产品标题',$product->getData('store_name'));
|
||||
$f[] = Form::hidden('product_id',$id);
|
||||
$f[] = Form::input('info','秒杀活动简介',$product->getData('store_info'))->type('textarea');
|
||||
$f[] = Form::input('unit_name','单位',$product->getData('unit_name'))->placeholder('个、位');
|
||||
$f[] = Form::dateTimeRange('section_time','活动时间');
|
||||
$f[] = Form::frameImageOne('image','产品主图片(305*305px)',Url::buildUrl('admin/widget.images/index',array('fodder'=>'image')),$product->getData('image'))->icon('image')->width('100%')->height('500px');
|
||||
$f[] = Form::frameImages('images','产品轮播图(640*640px)',Url::buildUrl('admin/widget.images/index',array('fodder'=>'images')),json_decode($product->getData('slider_image')))->maxLength(5)->icon('images')->width('100%')->height('500px');
|
||||
$f[] = Form::number('price','秒杀价')->min(0)->col(12);
|
||||
$f[] = Form::number('ot_price','原价',$product->getData('price'))->min(0)->col(12);
|
||||
$f[] = Form::number('cost','成本价',$product->getData('cost'))->min(0)->col(12);
|
||||
$f[] = Form::number('stock','库存',$product->getData('stock'))->min(0)->precision(0)->col(12);
|
||||
$f[] = Form::number('sales','销量',$product->getData('sales'))->min(0)->precision(0)->col(12);
|
||||
$f[] = Form::number('sort','排序',$product->getData('sort'))->col(12);
|
||||
$f[] = Form::number('num','单次购买产品个数',1)->precision(0)->col(12);
|
||||
$f[] = Form::number('give_integral','赠送积分',$product->getData('give_integral'))->min(0)->precision(0)->col(12);
|
||||
$f[] = Form::number('postage','邮费',$product->getData('postage'))->min(0)->col(12);
|
||||
$f[] = Form::radio('is_postage','是否包邮',$product->getData('is_postage'))->options([['label'=>'是','value'=>1],['label'=>'否','value'=>0]])->col(12);
|
||||
$f[] = Form::radio('is_hot','热门推荐',1)->options([['label'=>'开启','value'=>1],['label'=>'关闭','value'=>0]])->col(12);
|
||||
$f[] = Form::radio('status','活动状态',1)->options([['label'=>'开启','value'=>1],['label'=>'关闭','value'=>0]])->col(12);
|
||||
$form = Form::make_post_form('添加用户通知',$f,Url::buildUrl('save'));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传图片
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function upload()
|
||||
{
|
||||
$res = Upload::image('file','store/product/'.date('Ymd'));
|
||||
if(is_array($res)){
|
||||
SystemAttachment::attachmentAdd($res['name'],$res['size'],$res['type'],$res['dir'],$res['thumb_path'],4,$res['image_type'],$res['time']);
|
||||
return Json::successful('图片上传成功!',['name'=>$res['name'],'url'=>Upload::pathToUrl($res['thumb_path'])]);
|
||||
}else
|
||||
return Json::fail($res);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = StoreSeckillModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
$f = array();
|
||||
$f[] = Form::hidden('product_id',$product->getData('product_id'));
|
||||
$f[] = Form::input('title','产品标题',$product->getData('title'));
|
||||
$f[] = Form::input('info','秒杀活动简介',$product->getData('info'))->type('textarea');
|
||||
$f[] = Form::input('unit_name','单位',$product->getData('unit_name'))->placeholder('个、位');
|
||||
$f[] = Form::dateTimeRange('section_time','活动时间',date('Y-m-d H:i:s', (int)$product->getData('start_time')),date('Y-m-d H:i:s', (int)$product->getData('stop_time')));
|
||||
$f[] = Form::frameImageOne('image','产品主图片(305*305px)',Url::buildUrl('admin/widget.images/index',array('fodder'=>'image')),$product->getData('image'))->icon('image')->width('100%')->height('500px');
|
||||
$f[] = Form::frameImages('images','产品轮播图(640*640px)',Url::buildUrl('admin/widget.images/index',array('fodder'=>'images')),json_decode($product->getData('images')))->maxLength(5)->icon('images')->width('100%')->height('500px');
|
||||
$f[] = Form::number('price','秒杀价',$product->getData('price'))->min(0)->col(12);
|
||||
$f[] = Form::number('ot_price','原价',$product->getData('ot_price'))->min(0)->col(12);
|
||||
$f[] = Form::number('cost','成本价',$product->getData('cost'))->min(0)->col(12);
|
||||
$f[] = Form::number('stock','库存',$product->getData('stock'))->min(0)->precision(0)->col(12);
|
||||
$f[] = Form::number('sales','销量',$product->getData('sales'))->min(0)->precision(0)->col(12);
|
||||
$f[] = Form::number('sort','排序',$product->getData('sort'))->col(12);
|
||||
$f[] = Form::number('num','单次购买产品个数',$product->getData('num'))->precision(0)->col(12);
|
||||
$f[] = Form::number('give_integral','赠送积分',$product->getData('give_integral'))->min(0)->precision(0)->col(12);
|
||||
$f[] = Form::number('postage','邮费',$product->getData('postage'))->min(0)->col(12);
|
||||
$f[] = Form::radio('is_postage','是否包邮',$product->getData('is_postage'))->options([['label'=>'是','value'=>1],['label'=>'否','value'=>0]])->col(12);
|
||||
$f[] = Form::radio('is_hot','热门推荐',$product->getData('is_hot'))->options([['label'=>'开启','value'=>1],['label'=>'关闭','value'=>0]])->col(12);
|
||||
$f[] = Form::radio('status','活动状态',$product->getData('status'))->options([['label'=>'开启','value'=>1],['label'=>'关闭','value'=>0]])->col(12);
|
||||
$form = Form::make_post_form('添加用户通知',$f,Url::buildUrl('save',compact('id')));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = StoreSeckillModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
if($product['is_del']) return Json::fail('已删除!');
|
||||
$data['is_del'] = 1;
|
||||
if(!StoreSeckillModel::edit($data,$id))
|
||||
return Json::fail(StoreSeckillModel::getErrorInfo('删除失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('删除成功!');
|
||||
}
|
||||
|
||||
public function edit_content($id){
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$seckill = StoreSeckillModel::get($id);
|
||||
if(!$seckill) return Json::fail('数据不存在!');
|
||||
$this->assign([
|
||||
'content'=>StoreSeckillModel::where('id',$id)->value('description'),
|
||||
'field'=>'description',
|
||||
'action'=>Url::buildUrl('change_field',['id'=>$id,'field'=>'description'])
|
||||
]);
|
||||
return $this->fetch('public/edit_content');
|
||||
}
|
||||
|
||||
public function change_field($id){
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$seckill = StoreSeckillModel::get($id);
|
||||
if(!$seckill) return Json::fail('数据不存在!');
|
||||
$data['description'] = request()->post('description');
|
||||
$res = StoreSeckillModel::edit($data,$id);
|
||||
if($res)
|
||||
return Json::successful('添加成功');
|
||||
else
|
||||
return Json::fail('添加失败');
|
||||
}
|
||||
/**
|
||||
* 属性页面
|
||||
* @param $id
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function attr($id)
|
||||
{
|
||||
if(!$id) return $this->failed('数据不存在!');
|
||||
$result = StoreSeckillAttrResult::getResult($id);
|
||||
$image = StoreSeckillModel::where('id',$id)->value('image');
|
||||
$this->assign(compact('id','result','product','image'));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成属性
|
||||
* @param int $id
|
||||
*/
|
||||
public function is_format_attr($id = 0){
|
||||
if(!$id) return Json::fail('产品不存在');
|
||||
list($attr,$detail) = Util::postMore([
|
||||
['items',[]],
|
||||
['attrs',[]]
|
||||
],$this->request,true);
|
||||
$product = StoreSeckillModel::get($id);
|
||||
if(!$product) return Json::fail('产品不存在');
|
||||
$attrFormat = attrFormat($attr)[1];
|
||||
if(count($detail)){
|
||||
foreach ($attrFormat as $k=>$v){
|
||||
foreach ($detail as $kk=>$vv){
|
||||
if($v['detail'] == $vv['detail']){
|
||||
$attrFormat[$k]['price'] = $vv['price'];
|
||||
$attrFormat[$k]['sales'] = $vv['sales'];
|
||||
$attrFormat[$k]['pic'] = $vv['pic'];
|
||||
$attrFormat[$k]['check'] = false;
|
||||
break;
|
||||
}else{
|
||||
$attrFormat[$k]['price'] = '';
|
||||
$attrFormat[$k]['sales'] = '';
|
||||
$attrFormat[$k]['pic'] = $product['image'];
|
||||
$attrFormat[$k]['check'] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
foreach ($attrFormat as $k=>$v){
|
||||
$attrFormat[$k]['price'] = $product['price'];
|
||||
$attrFormat[$k]['sales'] = $product['stock'];
|
||||
$attrFormat[$k]['pic'] = $product['image'];
|
||||
$attrFormat[$k]['check'] = false;
|
||||
}
|
||||
}
|
||||
return Json::successful($attrFormat);
|
||||
}
|
||||
/**
|
||||
* 添加 修改属性
|
||||
* @param $id
|
||||
*/
|
||||
public function set_attr($id)
|
||||
{
|
||||
if(!$id) return $this->failed('产品不存在!');
|
||||
list($attr,$detail) = Util::postMore([
|
||||
['items',[]],
|
||||
['attrs',[]]
|
||||
],$this->request,true);
|
||||
$res = StoreSeckillAttr::createProductAttr($attr,$detail,$id);
|
||||
if($res)
|
||||
return $this->successful('编辑属性成功!');
|
||||
else
|
||||
return $this->failed(StoreSeckillAttr::getErrorInfo());
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除属性
|
||||
* @param $id
|
||||
*/
|
||||
public function clear_attr($id)
|
||||
{
|
||||
if(!$id) return $this->failed('产品不存在!');
|
||||
if(false !== StoreSeckillAttr::clearProductAttr($id) && false !== StoreSeckillAttrResult::clearResult($id))
|
||||
return $this->successful('清空产品属性成功!');
|
||||
else
|
||||
return $this->failed(StoreSeckillAttr::getErrorInfo('清空产品属性失败!'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改秒杀产品状态
|
||||
* @param $status
|
||||
* @param int $id
|
||||
*/
|
||||
public function set_seckill_status($status,$id = 0){
|
||||
if(!$id) return Json::fail('参数错误');
|
||||
$res = StoreSeckillModel::edit(['status'=>$status],$id);
|
||||
if($res) return Json::successful('修改成功');
|
||||
else return Json::fail('修改失败');
|
||||
}
|
||||
}
|
||||
71
app/admin/controller/ump/UserPoint.php
Normal file
71
app/admin/controller/ump/UserPoint.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
namespace app\admin\controller\ump;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use crmeb\services\UtilService as Util;
|
||||
use app\admin\model\user\UserPoint AS UserPointModel;
|
||||
use think\facade\Route as Url;
|
||||
use crmeb\services\JsonService;
|
||||
|
||||
/**
|
||||
* 优惠券控制器
|
||||
* Class StoreCategory
|
||||
* @package app\admin\controller\system
|
||||
*/
|
||||
class UserPoint extends AuthController
|
||||
{
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->assign([
|
||||
// 'sum_point'=>UserBill::where(['category'=>'integral','type'=>'system_add'])->sum('number'),
|
||||
// 'count'=>UserBill::where(['category'=>'integral','type'=>'sign'])->group('uid')->count(),
|
||||
// 'song_point'=>UserBill::where(['category'=>'integral','type'=>'sign'])->group('uid')->sum('number'),
|
||||
'is_layui'=>true,
|
||||
'year'=>getMonth(),
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$this->assign(['title'=>'添加优惠券','action'=>Url::buildUrl('save'),'rules'=>$this->rules()->getContent()]);
|
||||
return $this->fetch('public/common_form');
|
||||
}
|
||||
//异步获取积分列表
|
||||
public function getponitlist(){
|
||||
$where = Util::getMore([
|
||||
['start_time',''],
|
||||
['end_time',''],
|
||||
['nickname',''],
|
||||
['page',1],
|
||||
['limit',10],
|
||||
]);
|
||||
return JsonService::successlayui(UserPointModel::getpointlist($where));
|
||||
}
|
||||
//导出Excel表格
|
||||
public function export(){
|
||||
$where = Util::getMore([
|
||||
['start_time',''],
|
||||
['end_time',''],
|
||||
['nickname',''],
|
||||
]);
|
||||
UserPointModel::SaveExport($where);
|
||||
}
|
||||
//获取积分日志头部信息
|
||||
public function getuserpointbadgelist(){
|
||||
$where = Util::getMore([
|
||||
['start_time',''],
|
||||
['end_time',''],
|
||||
['nickname',''],
|
||||
]);
|
||||
return JsonService::successful(UserPointModel::getUserpointBadgelist($where));
|
||||
}
|
||||
|
||||
}
|
||||
719
app/admin/controller/user/User.php
Normal file
719
app/admin/controller/user/User.php
Normal file
@ -0,0 +1,719 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/11/11
|
||||
*/
|
||||
namespace app\admin\controller\user;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use app\admin\model\system\SystemUserLevel;
|
||||
use crmeb\repositories\UserRepository;
|
||||
use crmeb\services\FormBuilder as Form;
|
||||
use crmeb\services\JsonService;
|
||||
use think\facade\Db;
|
||||
use crmeb\traits\CurdControllerTrait;
|
||||
use crmeb\services\UtilService as Util;
|
||||
use crmeb\services\JsonService as Json;
|
||||
use think\facade\Route as Url;
|
||||
use app\admin\model\user\User as UserModel;
|
||||
use app\admin\model\user\UserBill AS UserBillAdmin;
|
||||
use crmeb\basic\BaseModel;
|
||||
use app\admin\model\user\UserLevel;
|
||||
use app\admin\model\store\StoreVisit;
|
||||
use app\admin\model\wechat\WechatMessage;
|
||||
use app\admin\model\order\StoreOrder;
|
||||
use app\admin\model\store\StoreCouponUser;
|
||||
|
||||
/**
|
||||
* 用户管理控制器
|
||||
* Class User
|
||||
* @package app\admin\controller\user
|
||||
*/
|
||||
class User extends AuthController
|
||||
{
|
||||
use CurdControllerTrait;
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index(){
|
||||
$this->assign('count_user',UserModel::getcount());
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/*
|
||||
* 赠送会员等级
|
||||
* @paran int $uid
|
||||
* */
|
||||
public function give_level($uid=0)
|
||||
{
|
||||
if(!$uid) return $this->failed('缺少参数');
|
||||
$level=\app\models\user\UserLevel::getUserLevel($uid);
|
||||
//获取当前会员等级
|
||||
if($level===false)
|
||||
$grade=0;
|
||||
else
|
||||
$grade=\app\models\user\UserLevel::getUserLevelInfo($level,'grade');
|
||||
//查询高于当前会员的所有会员等级
|
||||
$systemLevelList=SystemUserLevel::where('grade','>',$grade)->where(['is_show'=>1,'is_del'=>0])->field(['name','id'])->select();
|
||||
$field[]=Form::select('level_id','会员等级')->setOptions(function() use($systemLevelList) {
|
||||
$menus=[];
|
||||
foreach ($systemLevelList as $menu){
|
||||
$menus[] = ['value'=>$menu['id'],'label'=>$menu['name']];
|
||||
}
|
||||
return $menus;
|
||||
})->filterable(1);
|
||||
$form = Form::make_post_form('赠送会员',$field,Url::buildUrl('save_give_level',['uid'=>$uid]),2);
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
public function edit_other($uid)
|
||||
{
|
||||
if(!$uid) return $this->failed('数据不存在');
|
||||
$user = UserModel::get($uid);
|
||||
if(!$user) return Json::fail('数据不存在!');
|
||||
$f = array();
|
||||
$f[] = Form::radio('money_status','修改余额',1)->options([['value'=>1,'label'=>'增加'],['value'=>2,'label'=>'减少']]);
|
||||
$f[] = Form::number('money','余额')->min(0);
|
||||
$f[] = Form::radio('integration_status','修改积分',1)->options([['value'=>1,'label'=>'增加'],['value'=>2,'label'=>'减少']]);
|
||||
$f[] = Form::number('integration','积分')->min(0);
|
||||
$form = Form::make_post_form('修改其他',$f,Url::buildUrl('update_other',array('uid'=>$uid)));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
public function update_other($uid=0)
|
||||
{
|
||||
$data = Util::postMore([
|
||||
['money_status',0],
|
||||
['money',0],
|
||||
['integration_status',0],
|
||||
['integration',0],
|
||||
],$this->request);
|
||||
if(!$uid) return $this->failed('数据不存在');
|
||||
$user = UserModel::get($uid);
|
||||
if(!$user) return Json::fail('数据不存在!');
|
||||
BaseModel::beginTrans();
|
||||
$res1 = false;
|
||||
$res2 = false;
|
||||
$edit = array();
|
||||
if($data['money_status'] && $data['money']){//余额增加或者减少
|
||||
if($data['money_status'] == 1){//增加
|
||||
$edit['now_money'] = bcadd($user['now_money'],$data['money'],2);
|
||||
$res1 = UserBillAdmin::income('系统增加余额',$user['uid'],'now_money','system_add',$data['money'],$this->adminId,$edit['now_money'],'系统增加了'.floatval($data['money']).'余额');
|
||||
try{
|
||||
UserRepository::adminAddMoney($user,$data['money']);
|
||||
}catch (\Exception $e){
|
||||
BaseModel::rollbackTrans();
|
||||
return Json::fail($e->getMessage());
|
||||
}
|
||||
}else if($data['money_status'] == 2){//减少
|
||||
$edit['now_money'] = bcsub($user['now_money'],$data['money'],2);
|
||||
$res1 = UserBillAdmin::expend('系统减少余额',$user['uid'],'now_money','system_sub',$data['money'],$this->adminId,$edit['now_money'],'系统扣除了'.floatval($data['money']).'余额');
|
||||
try{
|
||||
UserRepository::adminSubMoney($user,$data['money']);
|
||||
}catch (\Exception $e){
|
||||
BaseModel::rollbackTrans();
|
||||
return Json::fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$res1 = true;
|
||||
}
|
||||
if($data['integration_status'] && $data['integration']){//积分增加或者减少
|
||||
if($data['integration_status'] == 1){//增加
|
||||
$edit['integral'] = bcadd($user['integral'],$data['integration'],2);
|
||||
$res2 = UserBillAdmin::income('系统增加积分',$user['uid'],'integral','system_add',$data['integration'],$this->adminId,$edit['integral'],'系统增加了'.floatval($data['integration']).'积分');
|
||||
try{
|
||||
UserRepository::adminAddIntegral($user,$data['integration']);
|
||||
}catch (\Exception $e){
|
||||
BaseModel::rollbackTrans();
|
||||
return Json::fail($e->getMessage());
|
||||
}
|
||||
}else if($data['integration_status'] == 2){//减少
|
||||
$edit['integral'] = bcsub($user['integral'],$data['integration'],2);
|
||||
$res2 = UserBillAdmin::expend('系统减少积分',$user['uid'],'integral','system_sub',$data['integration'],$this->adminId,$edit['integral'],'系统扣除了'.floatval($data['integration']).'积分');
|
||||
try{
|
||||
UserRepository::adminSubIntegral($user,$data['integration']);
|
||||
}catch (\Exception $e){
|
||||
BaseModel::rollbackTrans();
|
||||
return Json::fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$res2 = true;
|
||||
}
|
||||
if($edit) $res3 = UserModel::edit($edit,$uid);
|
||||
else $res3 = true;
|
||||
if($res1 && $res2 && $res3) $res =true;
|
||||
else $res = false;
|
||||
BaseModel::checkTrans($res);
|
||||
if($res) return Json::successful('修改成功!');
|
||||
else return Json::fail('修改失败');
|
||||
}
|
||||
|
||||
/*
|
||||
* 赠送会员等级
|
||||
* @paran int $uid
|
||||
* @return json
|
||||
* */
|
||||
public function save_give_level($uid=0)
|
||||
{
|
||||
if(!$uid) return JsonService::fail('缺少参数');
|
||||
list($level_id)=Util::postMore([
|
||||
['level_id',0],
|
||||
],$this->request,true);
|
||||
//查询当前选择的会员等级
|
||||
$systemLevel=SystemUserLevel::where(['is_show'=>1,'is_del'=>0,'id'=>$level_id])->find();
|
||||
if(!$systemLevel) return JsonService::fail('您选择赠送的会员等级不存在!');
|
||||
//检查是否拥有此会员等级
|
||||
$level=UserLevel::where(['uid'=>$uid,'level_id'=>$level_id,'is_del'=>0])->field('valid_time,is_forever')->find();
|
||||
if($level) if(!$level['is_forever'] && time() < $level['valid_time']) return JsonService::fail('此用户已有该会员等级,无法再次赠送');
|
||||
//设置会员过期时间
|
||||
$add_valid_time=(int)$systemLevel->valid_date*86400;
|
||||
UserModel::commitTrans();
|
||||
try{
|
||||
//保存会员信息
|
||||
$res=UserLevel::create([
|
||||
'is_forever'=>$systemLevel->is_forever,
|
||||
'status'=>1,
|
||||
'is_del'=>0,
|
||||
'grade'=>$systemLevel->grade,
|
||||
'uid'=>$uid,
|
||||
'add_time'=>time(),
|
||||
'level_id'=>$level_id,
|
||||
'discount'=>$systemLevel->discount,
|
||||
'valid_time'=>$systemLevel->discount ? $add_valid_time + time() : 0,
|
||||
'mark'=>'尊敬的用户【'.UserModel::where('uid',$uid)->value('nickname').'】在'.date('Y-m-d H:i:s',time()).'赠送会员等级成为'.$systemLevel['name'].'会员',
|
||||
]);
|
||||
//提取等级任务并记录完成情况
|
||||
$levelIds=[$level_id];
|
||||
$lowGradeLevelIds=SystemUserLevel::where('grade','<',$systemLevel->grade)->where(['is_show'=>1,'is_del'=>0])->column('id','id');
|
||||
if(count($lowGradeLevelIds)) $levelIds=array_merge($levelIds,$lowGradeLevelIds);
|
||||
$taskIds=Db::name('system_user_task')->where('level_id','in',$levelIds)->column('id','id');
|
||||
$inserValue=[];
|
||||
foreach ($taskIds as $id){
|
||||
$inserValue[]=['uid'=>$uid,'task_id'=>$id,'status'=>1,'add_time'=>time()];
|
||||
}
|
||||
$res=$res && Db::name('user_task_finish')->insertAll($inserValue) && UserModel::where('uid',$uid)->update(['level'=>$level_id]);
|
||||
if($res){
|
||||
UserModel::commitTrans();
|
||||
return JsonService::successful('赠送成功');
|
||||
}else{
|
||||
UserModel::rollbackTrans();
|
||||
return JsonService::successful('赠送失败');
|
||||
}
|
||||
}catch (\Exception $e){
|
||||
UserModel::rollbackTrans();
|
||||
return JsonService::fail('赠送失败');
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 清除会员等级
|
||||
* @param int $uid
|
||||
* @return json
|
||||
* */
|
||||
public function del_level($uid=0)
|
||||
{
|
||||
if(!$uid) return JsonService::fail('缺少参数');
|
||||
if(UserLevel::cleanUpLevel($uid))
|
||||
return JsonService::successful('清除成功');
|
||||
else
|
||||
return JsonService::fail('清除失败');
|
||||
}
|
||||
/**
|
||||
* 修改user表状态
|
||||
*
|
||||
* @return json
|
||||
*/
|
||||
public function set_status($status='',$uid=0,$is_echo=0){
|
||||
if($is_echo==0) {
|
||||
if ($status == '' || $uid == 0) return Json::fail('参数错误');
|
||||
UserModel::where(['uid' => $uid])->update(['status' => $status]);
|
||||
}else{
|
||||
$uids=Util::postMore([
|
||||
['uids',[]]
|
||||
]);
|
||||
UserModel::destrSyatus($uids['uids'],$status);
|
||||
}
|
||||
return Json::successful($status==0 ? '禁用成功':'解禁成功');
|
||||
}
|
||||
/**
|
||||
* 获取user表
|
||||
*
|
||||
* @return json
|
||||
*/
|
||||
public function get_user_list(){
|
||||
$where=Util::getMore([
|
||||
['page',1],
|
||||
['limit',20],
|
||||
['nickname',''],
|
||||
['status',''],
|
||||
['pay_count',''],
|
||||
['is_promoter',''],
|
||||
['order',''],
|
||||
['data',''],
|
||||
['user_type',''],
|
||||
['country',''],
|
||||
['province',''],
|
||||
['city',''],
|
||||
['user_time_type',''],
|
||||
['user_time',''],
|
||||
['sex',''],
|
||||
]);
|
||||
return Json::successlayui(UserModel::getUserList($where));
|
||||
}
|
||||
/**
|
||||
* 编辑模板消息
|
||||
* @param $id
|
||||
* @return mixed|\think\response\Json|void
|
||||
*/
|
||||
public function edit($uid)
|
||||
{
|
||||
if(!$uid) return $this->failed('数据不存在');
|
||||
$user = UserModel::get($uid);
|
||||
if(!$user) return Json::fail('数据不存在!');
|
||||
$f = array();
|
||||
$f[] = Form::input('uid','用户编号',$user->getData('uid'))->disabled(1);
|
||||
$f[] = Form::input('real_name','真实姓名',$user->getData('real_name'));
|
||||
$f[] = Form::date('birthday','生日',$user->getData('birthday') ? date('Y-m-d',$user->getData('birthday')) : 0);
|
||||
$f[] = Form::input('card_id','身份证号',$user->getData('card_id'));
|
||||
$f[] = Form::textarea('mark','用户备注',$user->getData('mark'));
|
||||
$f[] = Form::radio('is_promoter','推广员',$user->getData('is_promoter'))->options([['value'=>1,'label'=>'开启'],['value'=>0,'label'=>'关闭']]);
|
||||
$f[] = Form::radio('status','状态',$user->getData('status'))->options([['value'=>1,'label'=>'开启'],['value'=>0,'label'=>'锁定']]);
|
||||
$form = Form::make_post_form('添加用户通知',$f,Url::buildUrl('update',array('uid'=>$uid)),5);
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
public function update($uid)
|
||||
{
|
||||
$data = Util::postMore([
|
||||
['money_status',0],
|
||||
['is_promoter',1],
|
||||
['real_name',''],
|
||||
['card_id',''],
|
||||
['birthday',''],
|
||||
['mark',''],
|
||||
['money',0],
|
||||
['integration_status',0],
|
||||
['integration',0],
|
||||
['status',0],
|
||||
]);
|
||||
if(!$uid) return $this->failed('数据不存在');
|
||||
$user = UserModel::get($uid);
|
||||
if(!$user) return Json::fail('数据不存在!');
|
||||
BaseModel::beginTrans();
|
||||
$res1 = false;
|
||||
$res2 = false;
|
||||
$edit = array();
|
||||
if($data['money_status'] && $data['money']){//余额增加或者减少
|
||||
if($data['money_status'] == 1){//增加
|
||||
$edit['now_money'] = bcadd($user['now_money'],$data['money'],2);
|
||||
$res1 = UserBillAdmin::income('系统增加余额',$user['uid'],'now_money','system_add',$data['money'],$this->adminId,$edit['now_money'],'系统增加了'.floatval($data['money']).'余额');
|
||||
try{
|
||||
UserRepository::adminAddMoney($user,$data['money']);
|
||||
}catch (\Exception $e){
|
||||
BaseModel::rollbackTrans();
|
||||
return Json::fail($e->getMessage());
|
||||
}
|
||||
}else if($data['money_status'] == 2){//减少
|
||||
$edit['now_money'] = bcsub($user['now_money'],$data['money'],2);
|
||||
$res1 = UserBillAdmin::expend('系统减少余额',$user['uid'],'now_money','system_sub',$data['money'],$this->adminId,$edit['now_money'],'系统扣除了'.floatval($data['money']).'余额');
|
||||
try{
|
||||
UserRepository::adminSubMoney($user,$data['money']);
|
||||
}catch (\Exception $e){
|
||||
BaseModel::rollbackTrans();
|
||||
return Json::fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$res1 = true;
|
||||
}
|
||||
if($data['integration_status'] && $data['integration']){//积分增加或者减少
|
||||
if($data['integration_status'] == 1){//增加
|
||||
$edit['integral'] = bcadd($user['integral'],$data['integration'],2);
|
||||
$res2 = UserBillAdmin::income('系统增加积分',$user['uid'],'integral','system_add',$data['integration'],$this->adminId,$edit['integral'],'系统增加了'.floatval($data['integration']).'积分');
|
||||
try{
|
||||
UserRepository::adminAddIntegral($user,$data['integration']);
|
||||
}catch (\Exception $e){
|
||||
BaseModel::rollbackTrans();
|
||||
return Json::fail($e->getMessage());
|
||||
}
|
||||
}else if($data['integration_status'] == 2){//减少
|
||||
$edit['integral'] = bcsub($user['integral'],$data['integration'],2);
|
||||
$res2 = UserBillAdmin::expend('系统减少积分',$user['uid'],'integral','system_sub',$data['integration'],$this->adminId,$edit['integral'],'系统扣除了'.floatval($data['integration']).'积分');
|
||||
try{
|
||||
UserRepository::adminSubIntegral($user,$data['integration']);
|
||||
}catch (\Exception $e){
|
||||
BaseModel::rollbackTrans();
|
||||
return Json::fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$res2 = true;
|
||||
}
|
||||
$edit['status'] = $data['status'];
|
||||
$edit['real_name'] = $data['real_name'];
|
||||
$edit['card_id'] = $data['card_id'];
|
||||
$edit['birthday'] = $data['birthday'];
|
||||
$edit['mark'] = $data['mark'];
|
||||
$edit['is_promoter'] = $data['is_promoter'];
|
||||
if($edit) $res3 = UserModel::edit($edit,$uid);
|
||||
else $res3 = true;
|
||||
if($res1 && $res2 && $res3) $res =true;
|
||||
else $res = false;
|
||||
BaseModel::checkTrans($res);
|
||||
if($res) return Json::successful('修改成功!');
|
||||
else return Json::fail('修改失败');
|
||||
}
|
||||
/**
|
||||
* 用户图表
|
||||
* @return mixed
|
||||
*/
|
||||
public function user_analysis(){
|
||||
$where = Util::getMore([
|
||||
['nickname',''],
|
||||
['status',''],
|
||||
['is_promoter',''],
|
||||
['date',''],
|
||||
['user_type',''],
|
||||
['export',0]
|
||||
],$this->request);
|
||||
$user_count=UserModel::consume($where,'',true);
|
||||
//头部信息
|
||||
$header=[
|
||||
[
|
||||
'name'=>'新增用户',
|
||||
'class'=>'fa-line-chart',
|
||||
'value'=>$user_count,
|
||||
'color'=>'red'
|
||||
],
|
||||
[
|
||||
'name'=>'用户留存',
|
||||
'class'=>'fa-area-chart',
|
||||
'value'=>$this->gethreaderValue(UserModel::consume($where,'',true),$where).'%',
|
||||
'color'=>'lazur'
|
||||
],
|
||||
[
|
||||
'name'=>'新增用户总消费',
|
||||
'class'=>'fa-bar-chart',
|
||||
'value'=>'¥'.UserModel::consume($where),
|
||||
'color'=>'navy'
|
||||
],
|
||||
[
|
||||
'name'=>'用户活跃度',
|
||||
'class'=>'fa-pie-chart',
|
||||
'value'=>$this->gethreaderValue(UserModel::consume($where,'',true)).'%',
|
||||
'color'=>'yellow'
|
||||
],
|
||||
];
|
||||
$name=['新增用户','用户消费'];
|
||||
$dates=$this->get_user_index($where,$name);
|
||||
$user_index=['name'=>json_encode($name), 'date'=>json_encode($dates['time']), 'series'=>json_encode($dates['series'])];
|
||||
//用户浏览分析
|
||||
$view=StoreVisit::getVisit($where['date'],['','warning','info','danger']);
|
||||
$view_v1=WechatMessage::getViweList($where['date'],['','warning','info','danger']);
|
||||
$view=array_merge($view,$view_v1);
|
||||
$view_v2=[];
|
||||
foreach ($view as $val){
|
||||
$view_v2['color'][]='#'.rand(100000,339899);
|
||||
$view_v2['name'][]=$val['name'];
|
||||
$view_v2['value'][]=$val['value'];
|
||||
}
|
||||
$view=$view_v2;
|
||||
//消费会员排行用户分析
|
||||
$user_null=UserModel::getUserSpend($where['date']);
|
||||
//消费数据
|
||||
$now_number=UserModel::getUserSpend($where['date'],true);
|
||||
list($paren_number,$title)=UserModel::getPostNumber($where['date']);
|
||||
if($paren_number==0) {
|
||||
$rightTitle=[
|
||||
'number'=>$now_number>0?$now_number:0,
|
||||
'icon'=>'fa-level-up',
|
||||
'title'=>$title
|
||||
];
|
||||
}else{
|
||||
$number=(float)bcsub($now_number,$paren_number,4);
|
||||
if($now_number==0){
|
||||
$icon='fa-level-down';
|
||||
}else{
|
||||
$icon=$now_number>$paren_number?'fa-level-up':'fa-level-down';
|
||||
}
|
||||
$rightTitle=['number'=>$number, 'icon'=>$icon, 'title'=>$title];
|
||||
}
|
||||
unset($title,$paren_number,$now_number);
|
||||
list($paren_user_count,$title)=UserModel::getPostNumber($where['date'],true,'add_time','');
|
||||
if($paren_user_count==0){
|
||||
$count=$user_count==0?0:$user_count;
|
||||
$icon=$user_count==0?'fa-level-down':'fa-level-up';
|
||||
}else{
|
||||
$count=(float)bcsub($user_count,$paren_user_count,4);
|
||||
$icon=$user_count<$paren_user_count?'fa-level-down':'fa-level-up';
|
||||
}
|
||||
$leftTitle=[
|
||||
'count'=>$count,
|
||||
'icon'=>$icon,
|
||||
'title'=>$title
|
||||
];
|
||||
unset($count,$icon,$title);
|
||||
$consume=[
|
||||
'title'=>'消费金额为¥'.UserModel::consume($where),
|
||||
'series'=>UserModel::consume($where,'xiaofei'),
|
||||
'rightTitle'=>$rightTitle,
|
||||
'leftTitle'=>$leftTitle,
|
||||
];
|
||||
$form=UserModel::consume($where,'form');
|
||||
$grouping=UserModel::consume($where,'grouping');
|
||||
$this->assign(compact('header','user_index','view','user_null','consume','form','grouping','where'));
|
||||
return $this->fetch();
|
||||
}
|
||||
public function gethreaderValue($chart,$where=[]){
|
||||
if($where){
|
||||
switch($where['date']){
|
||||
case null:case 'today':case 'week':case 'year':
|
||||
if($where['date']==null){
|
||||
$where['date']='month';
|
||||
}
|
||||
$sum_user=UserModel::whereTime('add_time',$where['date'])->count();
|
||||
if($sum_user==0) return 0;
|
||||
$counts=bcdiv($chart,$sum_user,4)*100;
|
||||
return $counts;
|
||||
break;
|
||||
case 'quarter':
|
||||
$quarter=UserModel::getMonth('n');
|
||||
$quarter[0]=strtotime($quarter[0]);
|
||||
$quarter[1]=strtotime($quarter[1]);
|
||||
$sum_user=UserModel::where('add_time','between',$quarter)->count();
|
||||
if($sum_user==0) return 0;
|
||||
$counts=bcdiv($chart,$sum_user,4)*100;
|
||||
return $counts;
|
||||
default:
|
||||
//自定义时间
|
||||
$quarter=explode('-',$where['date']);
|
||||
$quarter[0]=strtotime($quarter[0]);
|
||||
$quarter[1]=strtotime($quarter[1]);
|
||||
$sum_user=UserModel::where('add_time','between',$quarter)->count();
|
||||
if($sum_user==0) return 0;
|
||||
$counts=bcdiv($chart,$sum_user,4)*100;
|
||||
return $counts;
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
$num=UserModel::count();
|
||||
$chart=$num!=0?bcdiv($chart,$num,5)*100:0;
|
||||
return $chart;
|
||||
}
|
||||
}
|
||||
public function get_user_index($where,$name){
|
||||
switch ($where['date']){
|
||||
case null:
|
||||
$days = date("t",strtotime(date('Y-m',time())));
|
||||
$dates=[];
|
||||
$series=[];
|
||||
$times_list=[];
|
||||
foreach ($name as $key=>$val){
|
||||
for($i=1;$i<=$days;$i++){
|
||||
if(!in_array($i.'号',$times_list)){
|
||||
array_push($times_list,$i.'号');
|
||||
}
|
||||
$time=$this->gettime(date("Y-m",time()).'-'.$i);
|
||||
if($key==0){
|
||||
$dates['data'][]=UserModel::where('add_time','between',$time)->count();
|
||||
}else if($key==1){
|
||||
$dates['data'][]=UserModel::consume(true,$time);
|
||||
}
|
||||
}
|
||||
$dates['name']=$val;
|
||||
$dates['type']='line';
|
||||
$series[]=$dates;
|
||||
unset($dates);
|
||||
}
|
||||
return ['time'=>$times_list,'series'=>$series];
|
||||
case 'today':
|
||||
$dates=[];
|
||||
$series=[];
|
||||
$times_list=[];
|
||||
foreach ($name as $key=>$val){
|
||||
for($i=0;$i<=24;$i++){
|
||||
$strtitle=$i.'点';
|
||||
if(!in_array($strtitle,$times_list)){
|
||||
array_push($times_list,$strtitle);
|
||||
}
|
||||
$time=$this->gettime(date("Y-m-d ",time()).$i);
|
||||
if($key==0){
|
||||
$dates['data'][]=UserModel::where('add_time','between',$time)->count();
|
||||
}else if($key==1){
|
||||
$dates['data'][]=UserModel::consume(true,$time);
|
||||
}
|
||||
}
|
||||
$dates['name']=$val;
|
||||
$dates['type']='line';
|
||||
$series[]=$dates;
|
||||
unset($dates);
|
||||
}
|
||||
return ['time'=>$times_list,'series'=>$series];
|
||||
case "week":
|
||||
$dates=[];
|
||||
$series=[];
|
||||
$times_list=[];
|
||||
foreach ($name as $key=>$val){
|
||||
for($i=0;$i<=6;$i++){
|
||||
if(!in_array('星期'.($i+1),$times_list)){
|
||||
array_push($times_list,'星期'.($i+1));
|
||||
}
|
||||
$time=UserModel::getMonth('h',$i);
|
||||
if($key==0){
|
||||
$dates['data'][]=UserModel::where('add_time','between',[strtotime($time[0]),strtotime($time[1])])->count();
|
||||
}else if($key==1){
|
||||
$dates['data'][]=UserModel::consume(true,[strtotime($time[0]),strtotime($time[1])]);
|
||||
}
|
||||
}
|
||||
$dates['name']=$val;
|
||||
$dates['type']='line';
|
||||
$series[]=$dates;
|
||||
unset($dates);
|
||||
}
|
||||
return ['time'=>$times_list,'series'=>$series];
|
||||
case 'year':
|
||||
$dates=[];
|
||||
$series=[];
|
||||
$times_list=[];
|
||||
$year=date('Y');
|
||||
foreach ($name as $key=>$val){
|
||||
for($i=1;$i<=12;$i++){
|
||||
if(!in_array($i.'月',$times_list)){
|
||||
array_push($times_list,$i.'月');
|
||||
}
|
||||
$t = strtotime($year.'-'.$i.'-01');
|
||||
$arr= explode('/',date('Y-m-01',$t).'/'.date('Y-m-',$t).date('t',$t));
|
||||
if($key==0){
|
||||
$dates['data'][]=UserModel::where('add_time','between',[strtotime($arr[0]),strtotime($arr[1])])->count();
|
||||
}else if($key==1){
|
||||
$dates['data'][]=UserModel::consume(true,[strtotime($arr[0]),strtotime($arr[1])]);
|
||||
}
|
||||
}
|
||||
$dates['name']=$val;
|
||||
$dates['type']='line';
|
||||
$series[]=$dates;
|
||||
unset($dates);
|
||||
}
|
||||
return ['time'=>$times_list,'series'=>$series];
|
||||
case 'quarter':
|
||||
$dates=[];
|
||||
$series=[];
|
||||
$times_list=[];
|
||||
foreach ($name as $key=>$val){
|
||||
for($i=1;$i<=4;$i++){
|
||||
$arr=$this->gettime('quarter',$i);
|
||||
if(!in_array(implode('--',$arr).'季度',$times_list)){
|
||||
array_push($times_list,implode('--',$arr).'季度');
|
||||
}
|
||||
if($key==0){
|
||||
$dates['data'][]=UserModel::where('add_time','between',[strtotime($arr[0]),strtotime($arr[1])])->count();
|
||||
}else if($key==1){
|
||||
$dates['data'][]=UserModel::consume(true,[strtotime($arr[0]),strtotime($arr[1])]);
|
||||
}
|
||||
}
|
||||
$dates['name']=$val;
|
||||
$dates['type']='line';
|
||||
$series[]=$dates;
|
||||
unset($dates);
|
||||
}
|
||||
return ['time'=>$times_list,'series'=>$series];
|
||||
default:
|
||||
$list=UserModel::consume($where,'default');
|
||||
$dates=[];
|
||||
$series=[];
|
||||
$times_list=[];
|
||||
foreach ($name as $k=>$v){
|
||||
foreach ($list as $val){
|
||||
$date=$val['add_time'];
|
||||
if(!in_array($date,$times_list)){
|
||||
array_push($times_list,$date);
|
||||
}
|
||||
if($k==0){
|
||||
$dates['data'][]=$val['num'];
|
||||
}else if($k==1){
|
||||
$dates['data'][]=UserBillAdmin::where(['uid'=>$val['uid'],'type'=>'pay_product'])->sum('number');
|
||||
}
|
||||
}
|
||||
$dates['name']=$v;
|
||||
$dates['type']='line';
|
||||
$series[]=$dates;
|
||||
unset($dates);
|
||||
}
|
||||
return ['time'=>$times_list,'series'=>$series];
|
||||
}
|
||||
}
|
||||
public function gettime($time='',$season=''){
|
||||
if(!empty($time) && empty($season)){
|
||||
$timestamp0 = strtotime($time);
|
||||
$timestamp24 =strtotime($time)+86400;
|
||||
return [$timestamp0,$timestamp24];
|
||||
}else if(!empty($time) && !empty($season)){
|
||||
$firstday=date('Y-m-01',mktime(0,0,0,($season - 1) *3 +1,1,date('Y')));
|
||||
$lastday=date('Y-m-t',mktime(0,0,0,$season * 3,1,date('Y')));
|
||||
return [$firstday,$lastday];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 会员等级首页
|
||||
*/
|
||||
public function group(){
|
||||
return $this->fetch();
|
||||
}
|
||||
/**
|
||||
* 会员详情
|
||||
*/
|
||||
public function see($uid=''){
|
||||
$this->assign([
|
||||
'uid'=>$uid,
|
||||
'userinfo'=>UserModel::getUserDetailed($uid),
|
||||
'is_layui'=>true,
|
||||
'headerList'=>UserModel::getHeaderList($uid),
|
||||
'count'=>UserModel::getCountInfo($uid),
|
||||
]);
|
||||
return $this->fetch();
|
||||
}
|
||||
/*
|
||||
* 获取某个用户的推广下线
|
||||
* */
|
||||
public function getSpreadList($uid,$page=1,$limit=20){
|
||||
return Json::successful(UserModel::getSpreadList($uid,(int)$page,(int)$limit));
|
||||
}
|
||||
/**
|
||||
* 获取某用户的订单列表
|
||||
*/
|
||||
public function getOneorderList($uid,$page=1,$limit=20){
|
||||
return Json::successful(StoreOrder::getOneorderList(compact('uid','page','limit')));
|
||||
}
|
||||
/**
|
||||
* 获取某用户的积分列表
|
||||
*/
|
||||
public function getOneIntegralList($uid,$page=1,$limit=20){
|
||||
return Json::successful(UserBillAdmin::getOneIntegralList(compact('uid','page','limit')));
|
||||
}
|
||||
/**
|
||||
* 获取某用户的积分列表
|
||||
*/
|
||||
public function getOneSignList($uid,$page=1,$limit=20){
|
||||
return Json::successful(UserBillAdmin::getOneSignList(compact('uid','page','limit')));
|
||||
}
|
||||
/**
|
||||
* 获取某用户的持有优惠劵
|
||||
*/
|
||||
public function getOneCouponsList($uid,$page=1,$limit=20){
|
||||
return Json::successful(StoreCouponUser::getOneCouponsList(compact('uid','page','limit')));
|
||||
}
|
||||
/**
|
||||
* 获取某用户的余额变动记录
|
||||
*/
|
||||
public function getOneBalanceChangList($uid,$page=1,$limit=20){
|
||||
return Json::successful(UserBillAdmin::getOneBalanceChangList(compact('uid','page','limit')));
|
||||
}
|
||||
}
|
||||
337
app/admin/controller/user/UserLevel.php
Normal file
337
app/admin/controller/user/UserLevel.php
Normal file
@ -0,0 +1,337 @@
|
||||
<?php
|
||||
namespace app\admin\controller\user;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use app\admin\model\system\SystemUserLevel;
|
||||
use app\admin\model\system\SystemUserTask;
|
||||
use crmeb\services\FormBuilder as Form;
|
||||
use crmeb\services\JsonService;
|
||||
use crmeb\services\UtilService;
|
||||
use think\facade\Route as Url;
|
||||
use crmeb\traits\CurdControllerTrait;
|
||||
use app\admin\model\user\UserLevel as UserLevelModel;
|
||||
|
||||
/**
|
||||
* 会员设置
|
||||
* Class UserLevel
|
||||
* @package app\admin\controller\user
|
||||
*/
|
||||
class UserLevel extends AuthController
|
||||
{
|
||||
use CurdControllerTrait;
|
||||
|
||||
/*
|
||||
* 等级展示
|
||||
* */
|
||||
public function index()
|
||||
{
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/*
|
||||
* 创建form表单
|
||||
* */
|
||||
public function create($id=0)
|
||||
{
|
||||
if($id) $vipinfo=SystemUserLevel::get($id);
|
||||
$field[]= Form::input('name','等级名称',isset($vipinfo) ? $vipinfo->name : '')->col(Form::col(24));
|
||||
$field[]= Form::radio('is_forever','是否为永久',isset($vipinfo) ? $vipinfo->is_forever : 0)->options([['label'=>'永久','value'=>1],['label'=>'非永久','value'=>0]])->col(24);
|
||||
$field[]= Form::number('money','等级价格',isset($vipinfo) ? $vipinfo->money : 0)->min(0)->col(24);
|
||||
$field[]= Form::radio('is_pay','是否需要购买',isset($vipinfo) ? $vipinfo->is_pay : 0)->options([['label'=>'需要','value'=>1],['label'=>'免费','value'=>0]])->col(24);
|
||||
$field[]= Form::number('valid_date','有效时间(天)',isset($vipinfo) ? $vipinfo->valid_date : 0)->min(0)->col(8);
|
||||
$field[]= Form::number('grade','等级',isset($vipinfo) ? $vipinfo->grade : 0)->min(0)->col(8);
|
||||
$field[]= Form::number('discount','享受折扣',isset($vipinfo) ? $vipinfo->discount : 0)->min(0)->col(8);
|
||||
$field[]= Form::frameImageOne('icon','图标',Url::buildUrl('admin/widget.images/index',array('fodder'=>'icon')),isset($vipinfo) ? $vipinfo->icon : '')->icon('image')->width('100%')->height('500px');
|
||||
$field[]= Form::frameImageOne('image','会员背景',Url::buildUrl('admin/widget.images/index',array('fodder'=>'image')),isset($vipinfo) ? $vipinfo->image : '')->icon('image')->width('100%')->height('500px');
|
||||
$field[]= Form::radio('is_show','是否显示',isset($vipinfo) ? $vipinfo->is_show : 0)->options([['label'=>'显示','value'=>1],['label'=>'隐藏','value'=>0]])->col(8);
|
||||
$field[]= Form::textarea('explain','等级说明',isset($vipinfo) ? $vipinfo->explain : '');
|
||||
$form = Form::make_post_form('添加等级设置',$field,Url::buildUrl('save',['id'=>$id]),2);
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/*
|
||||
* 会员等级添加或者修改
|
||||
* @param $id 修改的等级id
|
||||
* @return json
|
||||
* */
|
||||
public function save($id=0)
|
||||
{
|
||||
$data=UtilService::postMore([
|
||||
['name',''],
|
||||
['is_forever',0],
|
||||
['money',0],
|
||||
['is_pay',0],
|
||||
['valid_date',0],
|
||||
['grade',0],
|
||||
['discount',0],
|
||||
['icon',''],
|
||||
['image',''],
|
||||
['is_show',''],
|
||||
['explain',''],
|
||||
]);
|
||||
if(!$data['name']) return JsonService::fail('请输入等级名称');
|
||||
if(!$data['grade']) return JsonService::fail('请输入等级');
|
||||
if(!$data['explain']) return JsonService::fail('请输入等级说明');
|
||||
if($data['is_forever']==0 && !$data['valid_date']) return JsonService::fail('请输入有效时间(天)');
|
||||
if($data['is_pay']) return JsonService::fail('会员等级购买功能正在开发中,暂时关闭可购买功能!');
|
||||
if($data['is_pay'] && !$data['money']) return JsonService::fail('请输入购买金额');
|
||||
if(!$data['icon']) return JsonService::fail('请上传等级图标');
|
||||
if(!$data['image']) return JsonService::fail('请上传等级背景图标');
|
||||
if(!$id && SystemUserLevel::be(['is_del'=>0,'grade'=>$data['grade']])) return JsonService::fail('已检测到您设置过的会员等级,此等级不可重复');
|
||||
SystemUserLevel::beginTrans();
|
||||
try{
|
||||
//修改
|
||||
if($id){
|
||||
if(SystemUserLevel::edit($data,$id)){
|
||||
SystemUserLevel::commitTrans();
|
||||
return JsonService::successful('修改成功');
|
||||
}else{
|
||||
SystemUserLevel::rollbackTrans();
|
||||
return JsonService::fail('修改失败');
|
||||
}
|
||||
}else{
|
||||
//新增
|
||||
$data['add_time']=time();
|
||||
if(SystemUserLevel::create($data)){
|
||||
SystemUserLevel::commitTrans();
|
||||
return JsonService::successful('添加成功');
|
||||
}else{
|
||||
SystemUserLevel::rollbackTrans();
|
||||
return JsonService::fail('添加失败');
|
||||
}
|
||||
}
|
||||
}catch (\Exception $e){
|
||||
SystemUserLevel::rollbackTrans();
|
||||
return JsonService::fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 获取系统设置的vip列表
|
||||
* @param int page
|
||||
* @param int limit
|
||||
* */
|
||||
public function get_system_vip_list()
|
||||
{
|
||||
$where=UtilService::getMore([
|
||||
['page',0],
|
||||
['limit',10],
|
||||
['title',''],
|
||||
['is_show',''],
|
||||
]);
|
||||
return JsonService::successlayui(SystemUserLevel::getSytemList($where));
|
||||
}
|
||||
|
||||
/*
|
||||
* 删除会员等级
|
||||
* @param int $id
|
||||
* */
|
||||
public function delete($id=0)
|
||||
{
|
||||
if(SystemUserLevel::edit(['is_del'=>1],$id))
|
||||
return JsonService::successful('删除成功');
|
||||
else
|
||||
return JsonService::fail('删除失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置单个产品上架|下架
|
||||
*
|
||||
* @return json
|
||||
*/
|
||||
public function set_show($is_show='',$id=''){
|
||||
($is_show=='' || $id=='') && Json::fail('缺少参数');
|
||||
$res=SystemUserLevel::where(['id'=>$id])->update(['is_show'=>(int)$is_show]);
|
||||
if($res){
|
||||
return JsonService::successful($is_show==1 ? '显示成功':'隐藏成功');
|
||||
}else{
|
||||
return JsonService::fail($is_show==1 ? '显示失败':'隐藏失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 快速编辑
|
||||
*
|
||||
* @return json
|
||||
*/
|
||||
public function set_value($field='',$id='',$value=''){
|
||||
$field=='' || $id=='' || $value=='' && Json::fail('缺少参数');
|
||||
if(SystemUserLevel::where(['id'=>$id])->update([$field=>$value]))
|
||||
return JsonService::successful('保存成功');
|
||||
else
|
||||
return JsonService::fail('保存失败');
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 等级任务列表
|
||||
* @param int $vip_id 等级id
|
||||
* @return json
|
||||
* */
|
||||
public function tash($level_id=0)
|
||||
{
|
||||
$this->assign('level_id',$level_id);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 快速编辑
|
||||
*
|
||||
* @return json
|
||||
*/
|
||||
public function set_tash_value($field='',$id='',$value=''){
|
||||
$field=='' || $id=='' || $value=='' && Json::fail('缺少参数');
|
||||
if(SystemUserTask::where(['id'=>$id])->update([$field=>$value]))
|
||||
return JsonService::successful('保存成功');
|
||||
else
|
||||
return JsonService::fail('保存失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置单个产品上架|下架
|
||||
*
|
||||
* @return json
|
||||
*/
|
||||
public function set_tash_show($is_show='',$id=''){
|
||||
($is_show=='' || $id=='') && Json::fail('缺少参数');
|
||||
$res=SystemUserTask::where(['id'=>$id])->update(['is_show'=>(int)$is_show]);
|
||||
if($res){
|
||||
return JsonService::successful($is_show==1 ? '显示成功':'隐藏成功');
|
||||
}else{
|
||||
return JsonService::fail($is_show==1 ? '显示失败':'隐藏失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置单个产品上架|下架
|
||||
*
|
||||
* @return json
|
||||
*/
|
||||
public function set_tash_must($is_must='',$id=''){
|
||||
($is_must=='' || $id=='') && Json::fail('缺少参数');
|
||||
$res=SystemUserTask::where(['id'=>$id])->update(['is_must'=>(int)$is_must]);
|
||||
if($res){
|
||||
return JsonService::successful('设置成功');
|
||||
}else{
|
||||
return JsonService::fail('设置失败');
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 生成任务表单
|
||||
* @param int $id 任务id
|
||||
* @param int $vip_id 会员id
|
||||
* @return html
|
||||
* */
|
||||
public function create_tash($id=0,$level_id=0)
|
||||
{
|
||||
if($id) $tash=SystemUserTask::get($id);
|
||||
$field[]= Form::select('task_type','任务类型',isset($tash) ? $tash->task_type : '')->setOptions(function(){
|
||||
$list = SystemUserTask::getTaskTypeAll();
|
||||
$menus=[];
|
||||
foreach ($list as $menu){
|
||||
$menus[] = ['value'=>$menu['type'],'label'=>$menu['name'].'----单位['.$menu['unit'].']'];
|
||||
}
|
||||
return $menus;
|
||||
})->filterable(1);
|
||||
$field[]= Form::number('number','限定数量',isset($tash) ? $tash->number : 0)->min(0)->col(24);
|
||||
$field[]= Form::number('sort','排序',isset($tash) ? $tash->sort : 0)->min(0)->col(24);
|
||||
$field[]= Form::radio('is_show','是否显示',isset($tash) ? $tash->is_show : 1)->options([['label'=>'显示','value'=>1],['label'=>'隐藏','value'=>0]])->col(24);
|
||||
$field[]= Form::radio('is_must','是否务必达成',isset($tash) ? $tash->is_must : 1)->options([['label'=>'务必达成','value'=>1],['label'=>'完成其一','value'=>0]])->col(24);
|
||||
$field[]= Form::textarea('illustrate','任务说明',isset($tash) ? $tash->illustrate : '');
|
||||
$form = Form::make_post_form('添加任务',$field,Url::buildUrl('save_tash',['id'=>$id,'level_id'=>$level_id]),2);
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* 保存或者修改任务
|
||||
* @param int $id 任务id
|
||||
* @param int $vip_id 会员id
|
||||
* */
|
||||
public function save_tash($id=0,$level_id=0)
|
||||
{
|
||||
if(!$level_id) return JsonService::fail('缺少参数');
|
||||
$data=UtilService::postMore([
|
||||
['task_type',''],
|
||||
['number',0],
|
||||
['is_show',0],
|
||||
['sort',0],
|
||||
['is_must',0],
|
||||
['illustrate',''],
|
||||
]);
|
||||
if(!$data['task_type']) return JsonService::fail('请选择任务类型');
|
||||
if($data['number'] < 0) return JsonService::fail('请输入限定数量');
|
||||
$tash=SystemUserTask::getTaskType($data['task_type']);
|
||||
if($tash['max_number']!=0 && $data['number'] > $tash['max_number']) return JsonService::fail('您设置的限定数量超出最大限制,最大限制为:'.$tash['max_number']);
|
||||
$data['name']=SystemUserTask::setTaskName($data['task_type'],$data['number']);
|
||||
try{
|
||||
if($id){
|
||||
SystemUserTask::edit($data,$id);
|
||||
return JsonService::successful('修改成功');
|
||||
}else{
|
||||
$data['level_id']=$level_id;
|
||||
$data['add_time']=time();
|
||||
$data['real_name']=$tash['real_name'];
|
||||
if(SystemUserTask::create($data))
|
||||
return JsonService::successful('添加成功');
|
||||
else
|
||||
return JsonService::fail('添加失败');
|
||||
}
|
||||
}catch (\Exception $e){
|
||||
return JsonService::fail($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 异步获取等级任务列表
|
||||
* @param int $vip_id 会员id
|
||||
* @param int $page 分页
|
||||
* @param int $limit 显示条数
|
||||
* @return json
|
||||
* */
|
||||
public function get_tash_list($level_id=0)
|
||||
{
|
||||
list($page,$limit)=UtilService::getMore([
|
||||
['page',1],
|
||||
['limit',10],
|
||||
],$this->request,true);
|
||||
return JsonService::successlayui(SystemUserTask::getTashList($level_id,(int)$page,(int)$limit));
|
||||
}
|
||||
|
||||
/*
|
||||
* 删除任务
|
||||
* @param int 任务id
|
||||
* */
|
||||
public function delete_tash($id=0)
|
||||
{
|
||||
if(!$id) return JsonService::fail('缺少差参数');
|
||||
if(SystemUserTask::del($id))
|
||||
return JsonService::successful('删除成功');
|
||||
else
|
||||
return JsonService::fail('删除失败');
|
||||
}
|
||||
|
||||
/*
|
||||
* 会员等级展示
|
||||
*
|
||||
* */
|
||||
public function user_level_list()
|
||||
{
|
||||
$this->assign('level',SystemUserLevel::where('is_del',0)->where('is_show',1)->order('grade asc')->field(['id','name'])->select());
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function get_user_vip_list()
|
||||
{
|
||||
$where=UtilService::getMore([
|
||||
['page',1],
|
||||
['limit',10],
|
||||
['nickname',''],
|
||||
['level_id',''],
|
||||
]);
|
||||
return JsonService::successlayui(UserLevelModel::getUserVipList($where));
|
||||
}
|
||||
|
||||
}
|
||||
296
app/admin/controller/user/UserNotice.php
Normal file
296
app/admin/controller/user/UserNotice.php
Normal file
@ -0,0 +1,296 @@
|
||||
<?php
|
||||
namespace app\admin\controller\user;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use crmeb\services\FormBuilder as Form;
|
||||
use crmeb\services\JsonService;
|
||||
use crmeb\services\UtilService as Util;
|
||||
use crmeb\services\JsonService as Json;
|
||||
use think\facade\Route as Url;
|
||||
use app\admin\model\user\UserNotice as UserNoticeModel;
|
||||
use app\admin\model\user\UserNoticeSee as UserNoticeSeeModel;
|
||||
use app\admin\model\wechat\WechatUser as UserModel;
|
||||
/**
|
||||
* 用户通知
|
||||
* Class UserNotice
|
||||
* @package app\admin\controller\user
|
||||
*/
|
||||
class UserNotice extends AuthController
|
||||
{
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
if($this->request->isAjax()){
|
||||
$where=Util::getMore([
|
||||
['page',1],
|
||||
['limit',20]
|
||||
]);
|
||||
return Json::successlayui(UserNoticeModel::getList($where));
|
||||
}else{
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function create(){
|
||||
$f = array();
|
||||
$f[] = Form::input('user','发送人','系统管理员');
|
||||
$f[] = Form::input('title','通知标题');
|
||||
$f[] = Form::input('content','通知内容')->type('textarea');
|
||||
$f[] = Form::radio('type','消息类型',1)->options([['label'=>'系统消息','value'=>1],['label'=>'用户通知','value'=>2]]);
|
||||
$form = Form::make_post_form('添加用户通知',$f,Url::buildUrl('save'));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*/
|
||||
public function save(){
|
||||
$params = request()->post();
|
||||
if(!$params["user"])return Json::fail('请输入发送人!');
|
||||
if(!$params["title"])return Json::fail('请输入通知标题!');
|
||||
if(!$params["content"])return Json::fail('请输入通知内容!');
|
||||
if($params["type"] == 2){
|
||||
$uids = UserModel::order('uid desc')->column("uid",'uid');
|
||||
$params["uid"] = count($uids) > 0 ? ",".implode(",",$uids)."," : "";
|
||||
}
|
||||
$params["add_time"] = time();
|
||||
$params["send_time"] = 0;
|
||||
UserNoticeModel::create($params);
|
||||
return Json::successful('添加成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$notice = UserNoticeModel::get($id);
|
||||
if(!$notice) return Json::fail('数据不存在!');
|
||||
$f = array();
|
||||
$f[] = Form::input('user','发送人',$notice["user"]);
|
||||
$f[] = Form::input('title','通知标题',$notice["title"]);
|
||||
$f[] = Form::input('content','通知内容',$notice["content"])->type('textarea');
|
||||
$f[] = Form::radio('type','消息类型',$notice["type"])->options([['label'=>'系统消息','value'=>1],['label'=>'用户通知','value'=>2]]);
|
||||
$form = Form::make_post_form('编辑通知',$f,Url::buildUrl('update',["id"=>$id]),2);
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
* @param $id
|
||||
*/
|
||||
public function update($id)
|
||||
{
|
||||
$params = request()->post();
|
||||
if(!$params["user"])return Json::fail('请输入发送人!');
|
||||
if(!$params["title"])return Json::fail('请输入通知标题!');
|
||||
if(!$params["content"])return Json::fail('请输入通知内容!');
|
||||
UserNoticeModel::edit($params,$id);
|
||||
return Json::successful('修改成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function send($id)
|
||||
{
|
||||
UserNoticeModel::edit(array("is_send"=>1,"send_time"=>time()),$id);
|
||||
return Json::successful('发送成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
if(!UserNoticeModel::del($id))
|
||||
return Json::fail(UserNoticeModel::getErrorInfo('删除失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('删除成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询发送信息的用户资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function user($id){
|
||||
$notice = UserNoticeModel::get($id)->toArray();
|
||||
$model = new UserModel;
|
||||
$model = $model::alias('A');
|
||||
$model = $model->field('A.*');
|
||||
if($notice["type"] == 2){
|
||||
if($notice["uid"] != ""){
|
||||
$uids = explode(",",$notice["uid"]);
|
||||
array_splice($uids,0,1);
|
||||
array_splice($uids,count($uids)-1,1);
|
||||
$model = $model->where("A.uid","in",$uids);
|
||||
}else{
|
||||
$model = $model->where("A.uid",$notice['uid']);
|
||||
}
|
||||
$model->order('A.uid desc');
|
||||
}else{
|
||||
$model = $model->join('UserNoticeSee B','A.uid = B.uid','RIGHT');
|
||||
$model = $model->where("B.nid",$notice['id']);
|
||||
$model->order('B.add_time desc');
|
||||
}
|
||||
$this->assign(UserModel::page($model,function($item,$key) use ($notice){
|
||||
$item["is_see"] = UserNoticeSeeModel::where("uid",$item["uid"])->where("nid",$notice["id"])->count() > 0 ? 1 : 0;
|
||||
}));
|
||||
$this->assign(compact('notice'));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加发送信息的用户
|
||||
*
|
||||
* @param $id
|
||||
* @return string
|
||||
*/
|
||||
public function user_create($id){
|
||||
$where = Util::getMore([
|
||||
['nickname',''],
|
||||
['data',''],
|
||||
],$this->request);
|
||||
$this->assign('where',$where);
|
||||
$this->assign(UserModel::systemPage($where));
|
||||
$this->assign(['title'=>'添加发送用户','save'=>Url::buildUrl('user_save',array('id'=>$id))]);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
* @param $id
|
||||
*/
|
||||
public function user_save($id){
|
||||
$notice = UserNoticeModel::get($id)->toArray();
|
||||
if(!$notice) return Json::fail('通知信息不存在!');
|
||||
if($notice["type"] == 1) return Json::fail('系统通知不能管理用户!');
|
||||
|
||||
//查找当前选中的uid
|
||||
$params = request()->post();
|
||||
if(isset($params["search"])){
|
||||
$model = new UserModel;
|
||||
if($params['search']['nickname'] !== '') $model = $model->where('nickname','LIKE',"%".$params['search']['nickname']."%");
|
||||
if($params['search']['data'] !== ''){
|
||||
list($startTime,$endTime) = explode(' - ',$params['search']['data']);
|
||||
$model = $model->where('add_time','>',strtotime($startTime));
|
||||
$model = $model->where('add_time','<',strtotime($endTime));
|
||||
}
|
||||
$model = $model->order('uid desc');
|
||||
$uids = $model->column("uid",'uid');
|
||||
}else{
|
||||
$uids = $params["checked_menus"];
|
||||
}
|
||||
if(count($uids) <= 0)return Json::fail('请选择要添加的用户!');
|
||||
|
||||
//合并原来和现在的uid
|
||||
if($notice["uid"] != ""){
|
||||
$now_uids = explode(",",$notice["uid"]);
|
||||
array_splice($now_uids,0,1);
|
||||
array_splice($now_uids,count($now_uids)-1,1);
|
||||
$now_uids = array_merge($now_uids,$uids);
|
||||
}else{
|
||||
$now_uids = $uids;
|
||||
}
|
||||
|
||||
//编辑合并之后的uid
|
||||
$res_uids = UserModel::where("uid","in",$now_uids)->order('uid desc')->column("uid",'uid');
|
||||
UserNoticeModel::edit(array("uid"=>",".implode(",",$res_uids).","),$notice["id"]);
|
||||
return Json::successful('添加成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function user_delete($id,$uid)
|
||||
{
|
||||
$notice = UserNoticeModel::get($id)->toArray();
|
||||
if(!$notice) return Json::fail('通知信息不存在!');
|
||||
if($notice["type"] == 1) return Json::fail('系统通知不能管理用户!');
|
||||
if($notice["uid"] != ""){
|
||||
$res_uids = explode(",",$notice["uid"]);
|
||||
array_splice($res_uids,0,1);
|
||||
array_splice($res_uids,count($res_uids)-1,1);
|
||||
}
|
||||
array_splice($res_uids,array_search($uid,$res_uids),1);
|
||||
$value = count($res_uids) > 0 ? ",".implode(",",$res_uids)."," : "";
|
||||
UserNoticeModel::edit(array("uid"=>$value),$notice["id"]);
|
||||
return Json::successful('删除成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定的资源
|
||||
* @param $id
|
||||
*/
|
||||
public function user_select_delete($id){
|
||||
$params = request()->post();
|
||||
if(count($params["checked_menus"]) <= 0)return Json::fail('删除数据不能为空!');
|
||||
$notice = UserNoticeModel::get($id)->toArray();
|
||||
if(!$notice) return Json::fail('通知信息不存在!');
|
||||
|
||||
$res_uids = explode(",",$notice["uid"]);
|
||||
array_splice($res_uids,0,1);
|
||||
array_splice($res_uids,count($res_uids)-1,1);
|
||||
foreach ($params["checked_menus"] as $key => $value) {
|
||||
array_splice($res_uids,array_search($value,$res_uids),1);
|
||||
}
|
||||
$value = count($res_uids) > 0 ? ",".implode(",",$res_uids)."," : "";
|
||||
UserNoticeModel::edit(array("uid"=>$value),$notice["id"]);
|
||||
return Json::successful('删除成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function notice($id){
|
||||
$where = Util::getMore([
|
||||
['title',''],
|
||||
],$this->request);
|
||||
$nickname = UserModel::where('uid','IN',$id)->column('nickname','uid');
|
||||
$this->assign('where',$where);
|
||||
$this->assign('uid',$id);
|
||||
$this->assign('nickname',implode(',',$nickname));
|
||||
$this->assign(UserNoticeModel::getUserList($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 给指定用户发送站内信息
|
||||
* @param $id
|
||||
*/
|
||||
public function send_user($id = 0,$uid = '')
|
||||
{
|
||||
if(!$id || $uid == '') return JsonService::fail('参数错误');
|
||||
$uids = UserNoticeModel::where(['id'=>$id])->value('uid');
|
||||
$uid = rtrim($uids,',').",".$uid.",";
|
||||
UserNoticeModel::edit(array("send_time"=>time(),'uid'=>$uid),$id);
|
||||
return Json::successful('发送成功!');
|
||||
}
|
||||
}
|
||||
42
app/admin/controller/wechat/Menus.php
Normal file
42
app/admin/controller/wechat/Menus.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
namespace app\admin\controller\wechat;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use crmeb\services\WechatService;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 微信菜单 控制器
|
||||
* Class Menus
|
||||
* @package app\admin\controller\wechat
|
||||
*/
|
||||
class Menus extends AuthController
|
||||
{
|
||||
|
||||
public function index()
|
||||
{
|
||||
$menus = Db::name('cache')->where('key','wechat_menus')->value('result');
|
||||
$menus = $menus ? : '[]';
|
||||
$this->assign('menus',$menus);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$buttons = request()->post('button/a',[]);
|
||||
if(!count($buttons)) return $this->failed('请添加至少一个按钮');
|
||||
try{
|
||||
WechatService::menuService()->add($buttons);
|
||||
$count = Db::name('cache')->where('key', 'wechat_menus')->count();
|
||||
if($count){
|
||||
$count = Db::name('cache')->where('key', 'wechat_menus')->where('result', json_encode($buttons))->count();
|
||||
if(!$count)
|
||||
Db::name('cache')->where('key', 'wechat_menus')->update(['result'=>json_encode($buttons),'add_time'=>time()]);
|
||||
}else
|
||||
Db::name('cache')->insert(['key'=>'wechat_menus','result'=>json_encode($buttons),'add_time'=>time()],true);
|
||||
return $this->successful('修改成功!');
|
||||
}catch (\Exception $e){
|
||||
return $this->failed($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
176
app/admin/controller/wechat/Reply.php
Normal file
176
app/admin/controller/wechat/Reply.php
Normal file
@ -0,0 +1,176 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\wechat;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use app\admin\model\system\SystemAttachment;
|
||||
use app\admin\model\wechat\WechatReply;
|
||||
use crmeb\services\UtilService as Util;
|
||||
use crmeb\services\JsonService as Json;
|
||||
use crmeb\services\UploadService as Upload;
|
||||
|
||||
/**
|
||||
* 关键字管理 控制器
|
||||
* Class Reply
|
||||
* @package app\admin\controller\wechat
|
||||
*/
|
||||
class Reply extends AuthController
|
||||
{
|
||||
/**关注回复
|
||||
* @return mixed|void
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
if(empty(input('key'))) return $this->failed('请输入参数key');
|
||||
if(empty(input('title'))) return $this->failed('请输入参数title');
|
||||
$key = input('key');
|
||||
switch($key){
|
||||
case 'subscribe':
|
||||
$title = '编辑关注回复';
|
||||
break;
|
||||
case 'default':
|
||||
$title = '编辑关键字默认回复';
|
||||
break;
|
||||
default:
|
||||
$title = '编辑关键字回复';
|
||||
break;
|
||||
}
|
||||
$this->assign('replay_arr',WechatReply::getDataByKey($key));
|
||||
$this->assign('key',$key);
|
||||
$this->assign('title',$title);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function one_reply(){
|
||||
$where = Util::postMore([
|
||||
['key'],
|
||||
['add',0],
|
||||
],$this->request);
|
||||
if(!empty($where['key'])) $replay_arr = WechatReply::getDataByKey($where['key']);
|
||||
$replay_arr['code'] = 200;
|
||||
if(empty($replay_arr)) {
|
||||
$replay_arr['code'] = 0;
|
||||
}
|
||||
if($where['add'] && empty($where['key'])){
|
||||
$replay_arr['code'] = 0;
|
||||
}
|
||||
exit(json_encode($replay_arr));
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'type',
|
||||
'key',
|
||||
['status',0],
|
||||
['data',[]],
|
||||
]);
|
||||
if(!isset($data['type']) && empty($data['type']))
|
||||
return Json::fail('请选择回复类型');
|
||||
if(!in_array($data['type'],WechatReply::$reply_type))
|
||||
return Json::fail('回复类型有误!');
|
||||
if(!isset($data['data']) || !is_array($data['data']))
|
||||
return Json::fail('回复消息参数有误!');
|
||||
$res = WechatReply::redact($data['data'],$data['key'],$data['type'],$data['status']);
|
||||
if(!$res)
|
||||
return Json::fail(WechatReply::getErrorInfo());
|
||||
else
|
||||
return Json::successful('保存成功!',$data);
|
||||
}
|
||||
|
||||
public function upload_img()
|
||||
{
|
||||
$name = $this->request->post('file');
|
||||
if(!$name) return Json::fail('请上传图片');
|
||||
$res = Upload::image($name,'wechat/image',true,true,null,'uniqid',1);
|
||||
if(!is_array($res)) return Json::fail($res);
|
||||
SystemAttachment::attachmentAdd($res['name'],$res['size'],$res['type'],$res['dir'],$res['thumb_path'],0,$res['image_type'],$res['time']);
|
||||
return Json::successful('上传成功',$res['dir']);
|
||||
}
|
||||
|
||||
public function upload_file()
|
||||
{
|
||||
$name = $this->request->post('file');
|
||||
if(!$name) return Json::fail('请上传声音');
|
||||
$autoValidate['size'] = 2097152;
|
||||
$res = Upload::file($name,'wechat/voice',true,$autoValidate);
|
||||
return $res->status === true ? Json::successful('上传成功',$res->filePath) : Json::fail($res->error);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关键字回复
|
||||
* */
|
||||
public function keyword(){
|
||||
$where = Util::getMore([
|
||||
['key',''],
|
||||
['type',''],
|
||||
]);
|
||||
$this->assign('where',$where);
|
||||
$this->assign(WechatReply::getKeyAll($where));
|
||||
return $this->fetch();
|
||||
|
||||
}
|
||||
/**
|
||||
* 添加关键字
|
||||
* */
|
||||
public function add_keyword(){
|
||||
$key = input('key');
|
||||
if(empty($key)) $key = '';
|
||||
$this->assign('key',$key);
|
||||
$this->assign('dis',1);
|
||||
$this->assign('replay_arr',[]);
|
||||
return $this->fetch();
|
||||
}
|
||||
/**
|
||||
* 修改关键字
|
||||
* */
|
||||
public function info_keyword(){
|
||||
$key = input('key');
|
||||
if(empty($key)) return $this->failed('参数错误,请重新修改');
|
||||
$this->assign('replay_arr',WechatReply::getDataByKey($key));
|
||||
$this->assign('key',$key);
|
||||
$this->assign('dis',2);
|
||||
return $this->fetch('add_keyword');
|
||||
}
|
||||
/**
|
||||
* 保存关键字
|
||||
* */
|
||||
public function save_keyword()
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'key',
|
||||
'type',
|
||||
['status',0],
|
||||
['data',[]],
|
||||
]);
|
||||
if(!isset($data['key']) && empty($data['key']))
|
||||
return Json::fail('请输入关键字');
|
||||
if(isset($data['key']) && !empty($data['key'])){
|
||||
if(trim($data['key']) == 'subscribe') return Json::fail('请重新输入关键字');
|
||||
if(trim($data['key']) == 'default') return Json::fail('请重新输入关键字');
|
||||
}
|
||||
if(!isset($data['type']) && empty($data['type']))
|
||||
return Json::fail('请选择回复类型');
|
||||
if(!in_array($data['type'],WechatReply::$reply_type))
|
||||
return Json::fail('回复类型有误!');
|
||||
if(!isset($data['data']) || !is_array($data['data']))
|
||||
return Json::fail('回复消息参数有误!');
|
||||
$res = WechatReply::redact($data['data'],$data['key'],$data['type'],$data['status']);
|
||||
if(!$res)
|
||||
return Json::fail(WechatReply::getErrorInfo());
|
||||
else
|
||||
return Json::successful('保存成功!',$data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除关键字
|
||||
* */
|
||||
public function delete($id){
|
||||
if(!WechatReply::del($id))
|
||||
return Json::fail(WechatReply::getErrorInfo('删除失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('删除成功!');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
176
app/admin/controller/wechat/StoreService.php
Normal file
176
app/admin/controller/wechat/StoreService.php
Normal file
@ -0,0 +1,176 @@
|
||||
<?php
|
||||
namespace app\admin\controller\wechat;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use app\admin\model\system\SystemAttachment;
|
||||
use crmeb\services\CacheService;
|
||||
use crmeb\services\FormBuilder as Form;
|
||||
use crmeb\services\UtilService as Util;
|
||||
use crmeb\services\JsonService as Json;
|
||||
use crmeb\services\UploadService as Upload;
|
||||
use think\facade\Route as Url;
|
||||
use app\admin\model\wechat\StoreService as ServiceModel;
|
||||
use app\admin\model\wechat\StoreServiceLog as StoreServiceLog;
|
||||
use app\admin\model\wechat\WechatUser as UserModel;
|
||||
|
||||
/**
|
||||
* 客服管理
|
||||
* Class StoreService
|
||||
* @package app\admin\controller\store
|
||||
*/
|
||||
class StoreService extends AuthController
|
||||
{
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->assign(ServiceModel::getList(0));
|
||||
return $this->fetch();
|
||||
}
|
||||
/**
|
||||
* 显示创建资源表单页.
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function create(){
|
||||
$where = Util::getMore([
|
||||
['nickname',''],
|
||||
['data',''],
|
||||
['tagid_list',''],
|
||||
['groupid','-1'],
|
||||
['sex',''],
|
||||
['export',''],
|
||||
['stair',''],
|
||||
['second',''],
|
||||
['order_stair',''],
|
||||
['order_second',''],
|
||||
['subscribe',''],
|
||||
['now_money',''],
|
||||
['is_promoter',''],
|
||||
],$this->request);
|
||||
$this->assign('where',$where);
|
||||
$this->assign(UserModel::systemPage($where));
|
||||
$this->assign(['title'=>'添加客服','save'=>Url::buildUrl('save')]);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*/
|
||||
public function save(){
|
||||
$params = request()->post();
|
||||
if(count($params["checked_menus"]) <= 0)return Json::fail('请选择要添加的用户!');
|
||||
if(ServiceModel::where('mer_id',0)->where(array("uid"=>array("in",implode(',',$params["checked_menus"]))))->count())return Json::fail('添加用户中存在已有的客服!');
|
||||
foreach ($params["checked_menus"] as $key => $value) {
|
||||
$now_user = UserModel::get($value);
|
||||
$data[$key]["mer_id"] = 0;
|
||||
$data[$key]["uid"] = $now_user["uid"];
|
||||
$data[$key]["avatar"] = $now_user["headimgurl"];
|
||||
$data[$key]["nickname"] = $now_user["nickname"];
|
||||
$data[$key]["add_time"] = time();
|
||||
}
|
||||
ServiceModel::setAll($data);
|
||||
return Json::successful('添加成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示编辑资源表单页.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$service = ServiceModel::get($id);
|
||||
if(!$service) return Json::fail('数据不存在!');
|
||||
$f = array();
|
||||
$f[] = Form::frameImageOne('avatar','客服头像',Url::buildUrl('admin/widget.images/index',array('fodder'=>'avatar')),$service['avatar'])->icon('image')->width('100%')->height('500px');
|
||||
$f[] = Form::input('nickname','客服名称',$service["nickname"]);
|
||||
$f[] = Form::radio('customer','统计管理',$service['customer'])->options([['value'=>1,'label'=>'开启'],['value'=>0,'label'=>'关闭']]);
|
||||
$f[] = Form::radio('notify','订单通知',$service['notify'])->options([['value'=>1,'label'=>'开启'],['value'=>0,'label'=>'关闭']]);
|
||||
$f[] = Form::radio('status','客服状态',$service['status'])->options([['value'=>1,'label'=>'显示'],['value'=>0,'label'=>'隐藏']]);
|
||||
$form = Form::make_post_form('修改数据',$f,Url::buildUrl('update',compact('id')));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
/**
|
||||
* 保存新建的资源
|
||||
*
|
||||
* @param \think\Request $request
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function update($id)
|
||||
{
|
||||
$params = request()->post();
|
||||
if(empty($params["nickname"]))return Json::fail("客服名称不能为空!");
|
||||
$data = array("avatar"=>$params["avatar"]
|
||||
,"nickname"=>$params["nickname"]
|
||||
,'status'=>$params['status']
|
||||
,'notify'=>$params['notify']
|
||||
,'customer'=>$params['customer']
|
||||
);
|
||||
ServiceModel::edit($data,$id);
|
||||
return Json::successful('修改成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定资源
|
||||
*
|
||||
* @param int $id
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
if(!ServiceModel::del($id))
|
||||
return Json::fail(ServiceModel::getErrorInfo('删除失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('删除成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传图片
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function upload()
|
||||
{
|
||||
$res = Upload::image('file','store/product/'.date('Ymd'));
|
||||
if(is_array($res)){
|
||||
SystemAttachment::attachmentAdd($res['name'],$res['size'],$res['type'],$res['dir'],$res['thumb_path'],2,$res['image_type'],$res['time']);
|
||||
return Json::successful('图片上传成功!',['name'=>$res['name'],'url'=>Upload::pathToUrl($res['thumb_path'])]);
|
||||
}else
|
||||
return Json::fail($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return \think\Response
|
||||
*/
|
||||
public function chat_user($id)
|
||||
{
|
||||
$now_service = ServiceModel::get($id);
|
||||
if(!$now_service) return Json::fail('数据不存在!');
|
||||
$list = ServiceModel::getChatUser($now_service->toArray(),0);
|
||||
$this->assign(compact('list','now_service'));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $uid
|
||||
* @param int $to_uid
|
||||
* @return string
|
||||
*/
|
||||
public function chat_list()
|
||||
{
|
||||
$where = Util::getMore([['uid',0], ['to_uid', 0], ['id', 0]]);
|
||||
if($where['uid'])
|
||||
CacheService::set('admin_chat_list'.$this->adminId, $where);
|
||||
$where = CacheService::get('admin_chat_list'.$this->adminId);
|
||||
$this->assign(StoreServiceLog::getChatList($where, 0));
|
||||
$this->assign('where',$where);
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
35
app/admin/controller/wechat/WechatMessage.php
Normal file
35
app/admin/controller/wechat/WechatMessage.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\wechat;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use app\admin\model\wechat\WechatMessage as MessageModel;
|
||||
use crmeb\services\UtilService as Util;
|
||||
|
||||
/**
|
||||
* 用户扫码点击事件
|
||||
* Class SystemMessage
|
||||
* @package app\admin\controller\system
|
||||
*/
|
||||
class WechatMessage extends AuthController
|
||||
|
||||
{
|
||||
|
||||
/**
|
||||
* 显示操作记录
|
||||
*/
|
||||
public function index(){
|
||||
$where = Util::getMore([
|
||||
['nickname',''],
|
||||
['type',''],
|
||||
['data',''],
|
||||
],$this->request);
|
||||
$this->assign('where',$where);
|
||||
$this->assign('mold',MessageModel::$mold);
|
||||
$this->assign(MessageModel::systemPage($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
292
app/admin/controller/wechat/WechatNewsCategory.php
Normal file
292
app/admin/controller/wechat/WechatNewsCategory.php
Normal file
@ -0,0 +1,292 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\wechat;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use app\admin\model\article\Article;
|
||||
use crmeb\services\FormBuilder as Form;
|
||||
use crmeb\services\JsonService;
|
||||
use crmeb\services\UtilService as Util;
|
||||
use crmeb\services\JsonService as Json;
|
||||
use app\admin\model\wechat\WechatReply;
|
||||
use app\admin\model\wechat\WechatUser;
|
||||
use crmeb\services\UtilService;
|
||||
use think\facade\Db;
|
||||
use think\facade\Route as Url;
|
||||
use crmeb\services\WechatService;
|
||||
use \app\admin\model\wechat\WechatNewsCategory as WechatNewsCategoryModel;
|
||||
use app\admin\model\article\Article as ArticleModel;
|
||||
/**
|
||||
* 图文信息
|
||||
* Class WechatNewsCategory
|
||||
* @package app\admin\controller\wechat
|
||||
*
|
||||
*/
|
||||
class WechatNewsCategory extends AuthController
|
||||
{
|
||||
public function select($callback = '_selectNews$eb'){
|
||||
$where = Util::getMore([
|
||||
['cate_name','']
|
||||
],$this->request);
|
||||
$this->assign('where',$where);
|
||||
$this->assign('callback',$callback);
|
||||
$list = WechatNewsCategoryModel::getAll($where);
|
||||
$newList = $list['list']->toArray();
|
||||
$newList = $newList['data'];
|
||||
$this->assign($list);
|
||||
$this->assign('newList', $newList);
|
||||
return $this->fetch();
|
||||
}
|
||||
public function index()
|
||||
{
|
||||
$where = Util::getMore([
|
||||
['cate_name','']
|
||||
],$this->request);
|
||||
$this->assign('where',$where);
|
||||
$this->assign(WechatNewsCategoryModel::getAll($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
public function create(){
|
||||
$f = array();
|
||||
$f[] = Form::input('cate_name','分类名称')->autofocus(1);
|
||||
$f[] = Form::select('new_id','图文列表')->setOptions(function(){
|
||||
$list = ArticleModel::getNews();
|
||||
$options = [];
|
||||
foreach ($list as $id=>$roleName){
|
||||
$options[] = ['label'=>$roleName,'value'=>$id];
|
||||
}
|
||||
return $options;
|
||||
})->filterable(1)->multiple(1);
|
||||
$form = Form::make_post_form('编辑菜单',$f,Url::buildUrl('save'));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
public function save(){
|
||||
$data = Util::postMore([
|
||||
'cate_name',
|
||||
['new_id',[]],
|
||||
['sort',0],
|
||||
['add_time',time()],
|
||||
['status',1],]);
|
||||
if(!$data['cate_name']) return Json::fail('请输入图文名称');
|
||||
if(empty($data['new_id'])) return Json::fail('请选择图文列表');
|
||||
$data['new_id'] = array_unique($data['new_id']);
|
||||
if(count($data['new_id']) > 8){
|
||||
$data['new_id'] = array_slice($data['new_id'], 0, 8);
|
||||
};
|
||||
$data['new_id'] = implode(',',$data['new_id']);
|
||||
WechatNewsCategoryModel::create($data);
|
||||
return Json::successful('添加菜单成功!');
|
||||
}
|
||||
public function edit($id){
|
||||
$menu = WechatNewsCategoryModel::get($id);
|
||||
if(!$menu) return Json::fail('数据不存在!');
|
||||
$arr_new_id = array_unique(explode(',',$menu->new_id));
|
||||
foreach ($arr_new_id as $k=>$v){
|
||||
$arr_new_id[$k] = intval($v);
|
||||
}
|
||||
$f = array();
|
||||
$f[] = Form::input('cate_name','分类名称',$menu['cate_name'])->autofocus(1);
|
||||
$f[] = Form::select('new_id','图文列表',$arr_new_id)->setOptions(function(){
|
||||
$list = ArticleModel::getNews();
|
||||
$options = [];
|
||||
foreach ($list as $id=>$roleName){
|
||||
$options[] = ['label'=>$roleName,'value'=>$id];
|
||||
}
|
||||
return $options;
|
||||
})->filterable(1)->multiple(1);
|
||||
$form = Form::make_post_form('编辑图文',$f,Url::buildUrl('update',compact('id')));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
public function update($id)
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'cate_name',
|
||||
['new_id',[]],
|
||||
['sort',0],
|
||||
['status',1],]);
|
||||
if(!$data['cate_name']) return Json::fail('请输入图文名称');
|
||||
if(empty($data['new_id'])) return Json::fail('请选择图文列表');
|
||||
if(count($data['new_id']) > 8){
|
||||
$data['new_id'] = array_slice($data['new_id'], 0, 8);
|
||||
};
|
||||
$data['new_id'] = implode(',',$data['new_id']);;
|
||||
if(!WechatNewsCategoryModel::get($id)) return Json::fail('编辑的记录不存在!');
|
||||
WechatNewsCategoryModel::edit($data,$id);
|
||||
return Json::successful('修改成功!');
|
||||
}
|
||||
public function delete($id){
|
||||
if(!WechatNewsCategoryModel::del($id))
|
||||
return Json::fail(WechatNewsCategoryModel::getErrorInfo('删除失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('删除成功!');
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 发送消息
|
||||
* @param int $id
|
||||
* @param string $wechat
|
||||
* $wechat 不为空 发消息 / 空 群发消息
|
||||
*/
|
||||
public function push($id = 0,$wechat = ''){
|
||||
if(!$id) return Json::fail('参数错误');
|
||||
$list = WechatNewsCategoryModel::getWechatNewsItem($id);
|
||||
$wechatNews = [];
|
||||
if($list){
|
||||
if($list['new'] && is_array($list['new'])){
|
||||
foreach ($list['new'] as $kk=>$vv){
|
||||
$wechatNews[$kk]['title'] = $vv['title'];
|
||||
$wechatNews[$kk]['image'] = $vv['image_input'];
|
||||
$wechatNews[$kk]['date'] = date('m月d日',time());
|
||||
$wechatNews[$kk]['description'] = $vv['synopsis'];
|
||||
$wechatNews[$kk]['id'] = $vv['id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
if($wechat != ''){//客服消息
|
||||
$wechatNews = WechatReply::tidyNews($wechatNews);
|
||||
$message = WechatService::newsMessage($wechatNews);
|
||||
$errorLog = [];//发送失败的用户
|
||||
$user = WechatUser::where('uid','IN',$wechat)->column('nickname,subscribe,openid','uid');
|
||||
if($user){
|
||||
foreach ($user as $v){
|
||||
if($v['subscribe'] && $v['openid']){
|
||||
try {
|
||||
WechatService::staffService()->message($message)->to($v['openid'])->send();
|
||||
} catch (\Exception $e) {
|
||||
$errorLog[] = $v['nickname'].'发送失败';
|
||||
}
|
||||
}else{
|
||||
$errorLog[] = $v['nickname'].'没有关注发送失败(不是微信公众号用户)';
|
||||
}
|
||||
}
|
||||
}else return Json::fail('发送失败,参数不正确');
|
||||
if(!count($errorLog)) return Json::successful('全部发送成功');
|
||||
else return Json::successful(implode(',',$errorLog).',剩余的发送成功');
|
||||
}else{//群发消息
|
||||
// if($list){
|
||||
// if($list['new'] && is_array($list['new'])){
|
||||
// foreach ($list['new'] as $kk=>$vv){
|
||||
// $wechatNews[$kk]['title'] = $vv['title'];
|
||||
// $wechatNews[$kk]['thumb_media_id'] = $vv['image_input'];
|
||||
// $wechatNews[$kk]['author'] = $vv['author'];
|
||||
// $wechatNews[$kk]['digest'] = $vv['synopsis'];
|
||||
// $wechatNews[$kk]['show_cover_pic'] = 1;
|
||||
// $wechatNews[$kk]['content'] = Db::name('articleContent')->where('nid',$vv["id"])->value('content');
|
||||
// $wechatNews[$kk]['content_source_url'] = $vv['url'];
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//6sFx6PzPF2v_Lv4FGOMzz-oQunU2Z3wrOWb-7zS508E
|
||||
//6sFx6PzPF2v_Lv4FGOMzz7SUUuamgWwlqdVfhQ5ALT4
|
||||
// foreach ($wechatNews as $k=>$v){
|
||||
// $material = WechatService::materialService()->uploadImage(UtilService::urlToPath($v['thumb_media_id']));
|
||||
// dump($material);
|
||||
// $wechatNews[$k]['thumb_media_id'] = $material->media_id;
|
||||
// }
|
||||
// $mediaIdNews = WechatService::uploadNews($wechatNews);
|
||||
// $res = WechatService::sendNewsMessage($mediaIdNews->media_id);
|
||||
// if($res->errcode) return Json::fail($res->errmsg);
|
||||
// else return Json::successful('推送成功');
|
||||
// dump($mediaIdNews);
|
||||
// dump($res);
|
||||
}
|
||||
}
|
||||
|
||||
public function send_news($id = ''){
|
||||
if($id == '') return $this->failed('参数错误');
|
||||
$where = Util::getMore([
|
||||
['cate_name','']
|
||||
],$this->request);
|
||||
$this->assign('where',$where);
|
||||
$this->assign('wechat',$id);
|
||||
$this->assign(WechatNewsCategoryModel::getAll($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function append(){
|
||||
$this->assign('list',[
|
||||
[
|
||||
'id'=>0,
|
||||
'title'=>'',
|
||||
'author'=>$this->adminInfo->real_name,
|
||||
'content'=>'',
|
||||
'image_input'=>'/system/module/wechat/news/images/image.png',
|
||||
'synopsis'=>'',
|
||||
]
|
||||
]);
|
||||
$this->assign('id',0);
|
||||
$this->assign('author',$this->adminInfo->real_name);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function append_save(){
|
||||
$data = UtilService::postMore([
|
||||
['list',[]],
|
||||
['id',0]
|
||||
]);
|
||||
$id = [];
|
||||
$countList = count($data['list']);
|
||||
if(!$countList) return JsonService::fail('请添加图文');
|
||||
Article::beginTrans();
|
||||
foreach ($data['list'] as $k=>$v){
|
||||
if($v['title'] == '') return JsonService::fail('标题不能为空');
|
||||
if($v['author'] == '') return JsonService::fail('作者不能为空');
|
||||
if($v['content'] == '') return JsonService::fail('正文不能为空');
|
||||
if($v['synopsis'] == '') return JsonService::fail('摘要不能为空');
|
||||
$v['status'] = 1;
|
||||
$v['add_time'] = time();
|
||||
if($v['id']){
|
||||
$idC = $v['id'];
|
||||
unset($v['id']);
|
||||
Article::edit($v,$idC);
|
||||
Db::name('ArticleContent')->where('nid',$idC)->update(['content'=>$v['content']]);
|
||||
$data['list'][$k]['id'] = $idC;
|
||||
$id[] = $idC;
|
||||
}else{
|
||||
unset($v['id']);
|
||||
$res = Article::create($v)->toArray();
|
||||
$id[] = $res['id'];
|
||||
$data['list'][$k]['id'] = $res['id'];
|
||||
Db::name('ArticleContent')->insert(['content'=>$v['content'],'nid'=>$res['id']]);
|
||||
}
|
||||
}
|
||||
$countId = count($id);
|
||||
if($countId != $countList){
|
||||
Article::checkTrans(false);
|
||||
if($data['id']) return JsonService::fail('修改失败');
|
||||
else return JsonService::fail('添加失败');
|
||||
}else{
|
||||
Article::checkTrans(true);
|
||||
$newsCategory['cate_name'] = $data['list'][0]['title'];
|
||||
$newsCategory['new_id'] = implode(',',$id);
|
||||
$newsCategory['sort'] = 0;
|
||||
$newsCategory['add_time'] = time();
|
||||
$newsCategory['status'] = 1;
|
||||
if($data['id']) {
|
||||
WechatNewsCategoryModel::edit($newsCategory,$data['id']);
|
||||
return JsonService::successful('修改成功');
|
||||
}else{
|
||||
WechatNewsCategoryModel::create($newsCategory);
|
||||
return JsonService::successful('添加成功');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function modify($id){
|
||||
if(!strlen(trim($id)) || !$id) return $this->failed('参数错误');
|
||||
$wechatNews = WechatNewsCategoryModel::get($id);
|
||||
if(!$wechatNews) return $this->failed('参数错误');
|
||||
$wechatNews = $wechatNews->toArray();
|
||||
$list = Article::getArticleList($wechatNews['new_id']);
|
||||
$this->assign('list',$list);
|
||||
$this->assign('id',$id);
|
||||
$this->assign('author',$this->adminInfo->real_name);
|
||||
return $this->fetch('append');
|
||||
}
|
||||
|
||||
}
|
||||
133
app/admin/controller/wechat/WechatTemplate.php
Normal file
133
app/admin/controller/wechat/WechatTemplate.php
Normal file
@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\wechat;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use crmeb\services\FormBuilder as Form;
|
||||
use crmeb\services\UtilService as Util;
|
||||
use crmeb\services\JsonService as Json;
|
||||
use crmeb\services\WechatTemplateService;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Route as Url;
|
||||
use app\admin\model\wechat\WechatTemplate as WechatTemplateModel;
|
||||
|
||||
/**
|
||||
* 微信模板消息控制器
|
||||
* Class WechatTemplate
|
||||
* @package app\admin\controller\wechat
|
||||
*/
|
||||
class WechatTemplate extends AuthController
|
||||
{
|
||||
|
||||
protected $cacheTag = '_system_wechat';
|
||||
|
||||
public function index()
|
||||
{
|
||||
$where = Util::getMore([
|
||||
['name',''],
|
||||
['status','']
|
||||
],$this->request);
|
||||
$this->assign('where',$where);
|
||||
$this->assign(WechatTemplateModel::SystemPage($where));
|
||||
$industry = Cache::tag($this->cacheTag)->remember('_wechat_industry',function(){
|
||||
try{
|
||||
$cache = WechatTemplateService::getIndustry();
|
||||
if(!$cache) return [];
|
||||
Cache::tag($this->cacheTag,['_wechat_industry']);
|
||||
return $cache->toArray();
|
||||
}catch (\Exception $e){
|
||||
return $e->getMessage();
|
||||
}
|
||||
|
||||
},0)?:[];
|
||||
!is_array($industry) && $industry = [];
|
||||
$this->assign('industry',$industry);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加模板消息
|
||||
* @return mixed
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$f = array();
|
||||
$f[] = Form::input('tempkey','模板编号');
|
||||
$f[] = Form::input('tempid','模板ID');
|
||||
$f[] = Form::input('name','模板名');
|
||||
$f[] = Form::input('content','回复内容')->type('textarea');
|
||||
$f[] = Form::radio('status','状态',1)->options([['label'=>'开启','value'=>1],['label'=>'关闭','value'=>0]]);
|
||||
$form = Form::make_post_form('添加模板消息',$f,Url::buildUrl('save'));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
public function save()
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'tempkey',
|
||||
'tempid',
|
||||
'name',
|
||||
'content',
|
||||
['status',0]
|
||||
]);
|
||||
if($data['tempkey'] == '') return Json::fail('请输入模板编号');
|
||||
if($data['tempkey'] != '' && WechatTemplateModel::be($data['tempkey'],'tempkey'))
|
||||
return Json::fail('请输入模板编号已存在,请重新输入');
|
||||
if($data['tempid'] == '') return Json::fail('请输入模板ID');
|
||||
if($data['name'] == '') return Json::fail('请输入模板名');
|
||||
if($data['content'] == '') return Json::fail('请输入回复内容');
|
||||
$data['add_time'] = time();
|
||||
WechatTemplateModel::create($data);
|
||||
return Json::successful('添加模板消息成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑模板消息
|
||||
* @param $id
|
||||
* @return mixed|\think\response\Json|void
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = WechatTemplateModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
$f = array();
|
||||
$f[] = Form::input('tempkey','模板编号',$product->getData('tempkey'))->disabled(1);
|
||||
$f[] = Form::input('name','模板名',$product->getData('name'))->disabled(1);
|
||||
$f[] = Form::input('tempid','模板ID',$product->getData('tempid'));
|
||||
$f[] = Form::radio('status','状态',$product->getData('status'))->options([['label'=>'开启','value'=>1],['label'=>'关闭','value'=>0]]);
|
||||
$form = Form::make_post_form('编辑模板消息',$f,Url::buildUrl('update',compact('id')));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
public function update($id)
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'tempid',
|
||||
['status',0]
|
||||
]);
|
||||
if($data['tempid'] == '') return Json::fail('请输入模板ID');
|
||||
if(!$id) return $this->failed('数据不存在');
|
||||
$product = WechatTemplateModel::get($id);
|
||||
if(!$product) return Json::fail('数据不存在!');
|
||||
WechatTemplateModel::edit($data,$id);
|
||||
return Json::successful('修改成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除模板消息
|
||||
* @param $id
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
if(!$id) return Json::fail('数据不存在!');
|
||||
if(!WechatTemplateModel::del($id))
|
||||
return Json::fail(WechatTemplateModel::getErrorInfo('删除失败,请稍候再试!'));
|
||||
else
|
||||
return Json::successful('删除成功!');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
389
app/admin/controller/wechat/WechatUser.php
Normal file
389
app/admin/controller/wechat/WechatUser.php
Normal file
@ -0,0 +1,389 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\wechat;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
use crmeb\services\FormBuilder as Form;
|
||||
use app\admin\model\user\User;
|
||||
use app\admin\model\wechat\WechatUser as UserModel;
|
||||
use app\models\user\UserBill;
|
||||
use crmeb\services\JsonService;
|
||||
use crmeb\services\UtilService as Util;
|
||||
use crmeb\services\WechatService;
|
||||
use think\Collection;
|
||||
use think\facade\Route as Url;
|
||||
|
||||
/**
|
||||
* 管理员操作记录表控制器
|
||||
* Class WechatUser
|
||||
* @package app\admin\controller\wechat
|
||||
*/
|
||||
class WechatUser extends AuthController
|
||||
|
||||
{
|
||||
|
||||
/**
|
||||
* 显示操作记录
|
||||
*/
|
||||
public function index(){
|
||||
$where = Util::getMore([
|
||||
['nickname',''],
|
||||
['data',''],
|
||||
['tagid_list',''],
|
||||
['groupid','-1'],
|
||||
['sex',''],
|
||||
['export',''],
|
||||
['stair',''],
|
||||
['second',''],
|
||||
['order_stair',''],
|
||||
['order_second',''],
|
||||
['subscribe',''],
|
||||
['now_money',''],
|
||||
['is_promoter',''],
|
||||
],$this->request);
|
||||
$tagidList = explode(',',$where['tagid_list']);
|
||||
foreach ($tagidList as $k=>$v){
|
||||
if(!$v){
|
||||
unset($tagidList[$k]);
|
||||
}
|
||||
}
|
||||
$tagidList = array_unique($tagidList);
|
||||
$where['tagid_list'] = implode(',',$tagidList);
|
||||
try{
|
||||
$groupList=UserModel::getUserGroup();
|
||||
$tagList=UserModel::getUserTag();
|
||||
}catch (\Exception $e){
|
||||
$groupList=[];
|
||||
$tagList=[];
|
||||
}
|
||||
$this->assign([
|
||||
'where'=>$where,
|
||||
'groupList'=>$groupList,
|
||||
'tagList'=>$tagList
|
||||
]);
|
||||
$limitTimeList = [
|
||||
'today'=>implode(' - ',[date('Y/m/d'),date('Y/m/d',strtotime('+1 day'))]),
|
||||
'week'=>implode(' - ',[
|
||||
date('Y/m/d', (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600)),
|
||||
date('Y-m-d', (time() + (7 - (date('w') == 0 ? 7 : date('w'))) * 24 * 3600))
|
||||
]),
|
||||
'month'=>implode(' - ',[date('Y/m').'/01',date('Y/m').'/'.date('t')]),
|
||||
'quarter'=>implode(' - ',[
|
||||
date('Y').'/'.(ceil((date('n'))/3)*3-3+1).'/01',
|
||||
date('Y').'/'.(ceil((date('n'))/3)*3).'/'.date('t',mktime(0,0,0,(ceil((date('n'))/3)*3),1,date('Y')))
|
||||
]),
|
||||
'year'=>implode(' - ',[
|
||||
date('Y').'/01/01',date('Y/m/d',strtotime(date('Y').'/01/01 + 1year -1 day'))
|
||||
])
|
||||
];
|
||||
$uidAll = UserModel::getAll($where);
|
||||
$this->assign(compact('limitTimeList','uidAll'));
|
||||
$this->assign(UserModel::systemPage($where));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
public function edit_user_tag($openid)
|
||||
{
|
||||
if(!$openid) return JsonService::fail('参数错误!');
|
||||
$list = Collection::make(UserModel::getUserTag())->each(function($item){
|
||||
return ['value'=>$item['id'],'label'=>$item['name']];
|
||||
});
|
||||
$tagList = UserModel::where('openid',$openid)->value('tagid_list');
|
||||
|
||||
$tagList = explode(',',$tagList)?:[];
|
||||
$f = [Form::select('tag_id','用户标签',$tagList)->setOptions($list->toArray())->multiple(1)];
|
||||
$form = Form::make_post_form('标签名称',$f,Url::buildUrl('update_user_tag',compact('openid')));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
public function update_user_tag($openid)
|
||||
{
|
||||
if(!$openid) return JsonService::fail('参数错误!');
|
||||
$tagId = request()->post('tag_id/a',[]);
|
||||
if(!$tagId) return JsonService::fail('请选择用户标签!');
|
||||
$tagList = explode(',',UserModel::where('openid',$openid)->value('tagid_list'))?:[];
|
||||
UserModel::edit(['tagid_list'=>$tagId],$openid,'openid');
|
||||
if(!$tagId[0])unset($tagId[0]);
|
||||
UserModel::edit(['tagid_list'=>$tagId],$openid,'openid');
|
||||
try{
|
||||
foreach ($tagList as $tag){
|
||||
if($tag) WechatService::userTagService()->batchUntagUsers([$openid],$tag);
|
||||
}
|
||||
foreach ($tagId as $tag){
|
||||
WechatService::userTagService()->batchTagUsers([$openid],$tag);
|
||||
}
|
||||
}catch (\Exception $e){
|
||||
UserModel::rollbackTrans();
|
||||
return JsonService::fail($e->getMessage());
|
||||
}
|
||||
UserModel::commitTrans();
|
||||
return JsonService::successful('修改成功!');
|
||||
}
|
||||
|
||||
public function edit_user_group($openid)
|
||||
{
|
||||
if(!$openid) return JsonService::fail('参数错误!');
|
||||
$list = Collection::make(UserModel::getUserGroup())->each(function($item){
|
||||
return ['value'=>$item['id'],'label'=>$item['name']];
|
||||
});
|
||||
$groupId = UserModel::where('openid',$openid)->value('groupid');
|
||||
$f = [Form::select('group_id','用户分组',(string)$groupId)->setOptions($list->toArray())];
|
||||
$form = Form::make_post_form('用户分组',$f,Url::buildUrl('update_user_group',compact('openid')));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
public function update_user_group($openid)
|
||||
{
|
||||
if(!$openid) return JsonService::fail('参数错误!');
|
||||
$groupId = request()->post('group_id');
|
||||
// if(!$groupId) return JsonService::fail('请选择用户分组!');
|
||||
UserModel::beginTrans();
|
||||
UserModel::edit(['groupid'=>$groupId],$openid,'openid');
|
||||
try{
|
||||
WechatService::userGroupService()->moveUser($openid,$groupId);
|
||||
}catch (\Exception $e){
|
||||
UserModel::rollbackTrans();
|
||||
return JsonService::fail($e->getMessage());
|
||||
}
|
||||
UserModel::commitTrans();
|
||||
return JsonService::successful('修改成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户标签列表
|
||||
*/
|
||||
public function tag($refresh = 0)
|
||||
{
|
||||
$list=[];
|
||||
if($refresh == 1) {
|
||||
UserModel::clearUserTag();
|
||||
$this->redirect(Url::buildUrl('tag'));
|
||||
}
|
||||
try{
|
||||
$list = UserModel::getUserTag();
|
||||
}catch (\Exception $e){}
|
||||
$this->assign(compact('list'));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加标签
|
||||
* @return mixed
|
||||
*/
|
||||
public function create_tag()
|
||||
{
|
||||
$f = [Form::input('name','标签名称')];
|
||||
$form = Form::make_post_form('标签名称',$f,Url::buildUrl('save_tag'));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*/
|
||||
public function save_tag()
|
||||
{
|
||||
$tagName = request()->post('name');
|
||||
if(!$tagName) return JsonService::fail('请输入标签名称!');
|
||||
try{
|
||||
WechatService::userTagService()->create($tagName);
|
||||
}catch (\Exception $e){
|
||||
return JsonService::fail($e->getMessage());
|
||||
}
|
||||
UserModel::clearUserTag();
|
||||
return JsonService::successful('添加标签成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改标签
|
||||
* @param $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function edit_tag($id)
|
||||
{
|
||||
$f = [Form::input('name','标签名称')];
|
||||
$form = Form::make_post_form('标签名称',$f,Url::buildUrl('update_tag',['id'=>$id]));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改标签
|
||||
* @param $id
|
||||
*/
|
||||
public function update_tag($id)
|
||||
{
|
||||
$tagName = request()->post('name');
|
||||
if(!$tagName) return JsonService::fail('请输入标签名称!');
|
||||
try{
|
||||
WechatService::userTagService()->update($id,$tagName);
|
||||
}catch (\Exception $e){
|
||||
return JsonService::fail($e->getMessage());
|
||||
}
|
||||
UserModel::clearUserTag();
|
||||
return JsonService::successful('修改标签成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除标签
|
||||
* @param $id
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function delete_tag($id)
|
||||
{
|
||||
try{
|
||||
WechatService::userTagService()->delete($id);
|
||||
}catch (\Exception $e){
|
||||
return JsonService::fail($e->getMessage());
|
||||
}
|
||||
UserModel::clearUserTag();
|
||||
return JsonService::successful('删除标签成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户分组列表
|
||||
*/
|
||||
|
||||
public function group($refresh = 0)
|
||||
{
|
||||
$list=[];
|
||||
if($refresh == 1) {
|
||||
UserModel::clearUserGroup();
|
||||
$this->redirect(Url::buildUrl('group'));
|
||||
}
|
||||
try{
|
||||
$list = UserModel::getUserGroup();
|
||||
}catch (\Exception $e){}
|
||||
$this->assign(compact('list'));
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加分组
|
||||
* @return mixed
|
||||
*/
|
||||
public function create_group()
|
||||
{
|
||||
$f = [Form::input('name','分组名称')];
|
||||
$form = Form::make_post_form('标签名称',$f,Url::buildUrl('save_group'));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*/
|
||||
public function save_group()
|
||||
{
|
||||
$tagName = request()->post('name');
|
||||
if(!$tagName) return JsonService::fail('请输入分组名称!');
|
||||
try{
|
||||
WechatService::userGroupService()->create($tagName);
|
||||
}catch (\Exception $e){
|
||||
return JsonService::fail($e->getMessage());
|
||||
}
|
||||
UserModel::clearUserGroup();
|
||||
return JsonService::successful('添加分组成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改分组
|
||||
* @param $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function edit_group($id)
|
||||
{
|
||||
$f = [Form::input('name','分组名称')];
|
||||
$form = Form::make_post_form('标签名称',$f,Url::buildUrl('update_group',compact('id')));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改分组
|
||||
* @param $id
|
||||
*/
|
||||
public function update_group($id)
|
||||
{
|
||||
$tagName = request()->post('name');
|
||||
if(!$tagName) return JsonService::fail('请输入分组名称!');
|
||||
try{
|
||||
WechatService::userGroupService()->update($id,$tagName);
|
||||
}catch (\Exception $e){
|
||||
return JsonService::fail($e->getMessage());
|
||||
}
|
||||
UserModel::clearUserGroup();
|
||||
return JsonService::successful('修改分组成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除分组
|
||||
* @param $id
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function delete_group($id)
|
||||
{
|
||||
try{
|
||||
WechatService::userTagService()->delete($id);
|
||||
}catch (\Exception $e){
|
||||
return JsonService::fail($e->getMessage());
|
||||
}
|
||||
UserModel::clearUserGroup();
|
||||
return JsonService::successful('删除分组成功!');
|
||||
}
|
||||
|
||||
public function synchro_tag($openid){
|
||||
if(!$openid) return JsonService::fail('参数错误!');
|
||||
$data = array();
|
||||
if(UserModel::be($openid,'openid')){
|
||||
try{
|
||||
$tag = WechatService::userTagService()->userTags($openid)->toArray();
|
||||
}catch (\Exception $e) {
|
||||
return JsonService::fail($e->getMessage());
|
||||
}
|
||||
if($tag['tagid_list']) $data['tagid_list'] = implode(',',$tag['tagid_list']);
|
||||
else $data['tagid_list'] = '';
|
||||
$res = UserModel::edit($data,$openid,'openid');
|
||||
if($res) return JsonService::successful('同步成功');
|
||||
else return JsonService::fail('同步失败!');
|
||||
}else return JsonService::fail('参数错误!');
|
||||
}
|
||||
|
||||
/**
|
||||
* 一级推荐人页面
|
||||
* @return mixed
|
||||
*/
|
||||
public function stair($uid = ''){
|
||||
if($uid == '') return $this->failed('参数错误');
|
||||
$list = User::alias('u')
|
||||
->where('u.spread_uid',$uid)
|
||||
->field('u.avatar,u.nickname,u.now_money,u.add_time,u.uid')
|
||||
->where('u.status',1)
|
||||
->order('u.add_time DESC')
|
||||
->select()
|
||||
->toArray();
|
||||
foreach ($list as $key=>$value) $list[$key]['orderCount'] = StoreOrder::getOrderCount($value['uid']);
|
||||
$this->assign('list',$list);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 个人资金详情页面
|
||||
* @return mixed
|
||||
*/
|
||||
public function now_money($uid = ''){
|
||||
if($uid == '') return $this->failed('参数错误');
|
||||
$list = UserBill::where('uid',$uid)->where('category','now_money')
|
||||
->field('mark,pm,number,add_time')
|
||||
->where('status',1)->order('add_time DESC')->select()->toArray();
|
||||
foreach ($list as &$v){
|
||||
$v['add_time'] = date('Y-m-d H:i:s',$v['add_time']);
|
||||
}
|
||||
$this->assign('list',$list);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
7
app/admin/controller/wechat/index.php
Normal file
7
app/admin/controller/wechat/index.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: Administrator
|
||||
* Date: 2018/4/18 0018
|
||||
* Time: 上午 10:44
|
||||
*/
|
||||
275
app/admin/controller/widget/Images.php
Normal file
275
app/admin/controller/widget/Images.php
Normal file
@ -0,0 +1,275 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\widget;
|
||||
|
||||
use crmeb\services\storage\COS;
|
||||
use crmeb\services\storage\OSS;
|
||||
use crmeb\services\storage\Qiniu;
|
||||
use think\facade\Route as Url;
|
||||
use app\admin\model\system\SystemAttachment as SystemAttachmentModel;
|
||||
use app\admin\model\system\SystemAttachmentCategory as Category;
|
||||
use app\admin\controller\AuthController;
|
||||
use crmeb\services\UploadService as Upload;
|
||||
use crmeb\services\JsonService as Json;
|
||||
use crmeb\services\UtilService as Util;
|
||||
use crmeb\services\FormBuilder as Form;
|
||||
|
||||
/**
|
||||
* TODO 附件控制器
|
||||
* Class Images
|
||||
* @package app\admin\controller\widget
|
||||
*/
|
||||
class Images extends AuthController
|
||||
{
|
||||
/**
|
||||
* 附件列表
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$pid = request()->param('pid');
|
||||
if($pid === NULL)
|
||||
{
|
||||
$pid = session('pid') ? session('pid') : 0;
|
||||
}
|
||||
session('pid',$pid);
|
||||
$this->assign('pid',$pid);
|
||||
//// //TODO 分类标题
|
||||
// $typearray = Category::getAll();
|
||||
// $this->assign(compact('typearray'));
|
||||
// $this->assign(SystemAttachmentModel::getAll($pid));
|
||||
return $this->fetch('widget/images');
|
||||
}
|
||||
|
||||
/**获取图片列表
|
||||
*
|
||||
*/
|
||||
public function get_image_list()
|
||||
{
|
||||
$where = Util::getMore([
|
||||
['page',1],
|
||||
['limit',18],
|
||||
['pid',0]
|
||||
]);
|
||||
return Json::successful(SystemAttachmentModel::getImageList($where));
|
||||
}
|
||||
/**获取分类
|
||||
* @param string $name
|
||||
*/
|
||||
public function get_image_cate($name = '')
|
||||
{
|
||||
return Json::successful(Category::getAll($name));
|
||||
}
|
||||
|
||||
/**
|
||||
* 图片管理上传图片
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function upload()
|
||||
{
|
||||
$pid = input('pid')!= NULL ?input('pid'):session('pid');
|
||||
$upload_type = $this->request->get('upload_type',0);
|
||||
try{
|
||||
$path = make_path('attach');
|
||||
$res = Upload::image('file',$path,true,true,null,'uniqid',$upload_type);
|
||||
if(is_object($res) && $res->status === false){
|
||||
$info = array(
|
||||
'code' =>400,
|
||||
'msg' =>'上传失败:'.$res->error,
|
||||
'src' =>''
|
||||
);
|
||||
}else if(is_string($res)){
|
||||
$info = array(
|
||||
'code' =>400,
|
||||
'msg' =>'上传失败:'.$res,
|
||||
'src' =>''
|
||||
);
|
||||
}else if(is_array($res)){
|
||||
$res['dir'] = str_replace('\\','/',$res['dir']);
|
||||
$res['thumb_path'] = str_replace('\\','/',$res['thumb_path']);
|
||||
SystemAttachmentModel::attachmentAdd($res['name'],$res['size'],$res['type'],$res['dir'],$res['thumb_path'],$pid,$res['image_type'],$res['time']);
|
||||
$info = array(
|
||||
'code' =>200,
|
||||
'msg' =>'上传成功',
|
||||
'src' =>$res['dir']
|
||||
);
|
||||
}
|
||||
}catch (\Exception $e){
|
||||
$info = [
|
||||
'code' =>400,
|
||||
'msg' =>'上传失败:'.$e->getMessage(),
|
||||
'src' =>''
|
||||
];
|
||||
}
|
||||
echo json_encode($info);
|
||||
}
|
||||
|
||||
/**
|
||||
* ajax 提交删除
|
||||
*/
|
||||
public function delete(){
|
||||
$request = app('request');
|
||||
$post = $request->post();
|
||||
if(empty($post['imageid'] ))
|
||||
Json::fail('还没选择要删除的图片呢?');
|
||||
foreach ($post['imageid'] as $v){
|
||||
self::deleteimganddata($v);
|
||||
}
|
||||
Json::successful('删除成功');
|
||||
}
|
||||
|
||||
/**删除图片和数据记录
|
||||
* @param $att_id
|
||||
*/
|
||||
public function deleteimganddata($att_id){
|
||||
$attinfo = SystemAttachmentModel::get($att_id)->toArray();
|
||||
if($attinfo){
|
||||
if($attinfo['image_type'] == 1){
|
||||
@unlink(app()->getRootPath().ltrim($attinfo['att_dir'],'.'));
|
||||
@unlink(app()->getRootPath().ltrim($attinfo['satt_dir'],'.'));
|
||||
}else if($attinfo['image_type'] == 2){
|
||||
Qiniu::delete($attinfo['name']);
|
||||
}else if($attinfo['image_type'] == 3){
|
||||
OSS::delete($attinfo['name']);
|
||||
}else if($attinfo['image_type'] == 4){
|
||||
COS::delete($attinfo['name']);
|
||||
}
|
||||
SystemAttachmentModel::where('att_id', $att_id)->delete();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 移动图片分类显示
|
||||
*/
|
||||
public function moveimg($imgaes){
|
||||
|
||||
$formbuider = [];
|
||||
$formbuider[] = Form::hidden('imgaes',$imgaes);
|
||||
$formbuider[] = Form::select('pid','选择分类')->setOptions(function (){
|
||||
$list = Category::getCateList();
|
||||
$options = [['value'=>0,'label'=>'所有分类']];
|
||||
foreach ($list as $id=>$cateName){
|
||||
$options[] = ['label'=>$cateName['html'].$cateName['name'],'value'=>$cateName['id']];
|
||||
}
|
||||
return $options;
|
||||
})->filterable(1);
|
||||
$form = Form::make_post_form('编辑分类',$formbuider,Url::buildUrl('moveImgCecate'));
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/**
|
||||
* 移动图片分类操作
|
||||
*/
|
||||
public function moveImgCecate()
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'pid',
|
||||
'imgaes'
|
||||
]);
|
||||
if($data['imgaes'] == '') return Json::fail('请选择图片');
|
||||
if(!$data['pid']) return Json::fail('请选择分类');
|
||||
$res = SystemAttachmentModel::where('att_id','in',$data['imgaes'])->update(['pid'=>$data['pid']]);
|
||||
if($res)
|
||||
Json::successful('移动成功');
|
||||
else
|
||||
Json::fail('移动失败!');
|
||||
}
|
||||
/**
|
||||
* ajax 添加分类
|
||||
*/
|
||||
public function addcate($id = 0){
|
||||
$formbuider = [];
|
||||
$formbuider[] = Form::select('pid','上级分类',(string)$id)->setOptions(function (){
|
||||
$list = Category::getCateList(0);
|
||||
$options = [['value'=>0,'label'=>'所有分类']];
|
||||
foreach ($list as $id=>$cateName){
|
||||
$options[] = ['label'=>$cateName['html'].$cateName['name'],'value'=>$cateName['id']];
|
||||
}
|
||||
return $options;
|
||||
})->filterable(1);
|
||||
$formbuider[] = Form::input('name','分类名称');
|
||||
$jsContent = <<<SCRIPT
|
||||
parent.SuccessCateg();
|
||||
parent.layer.close(parent.layer.getFrameIndex(window.name));
|
||||
SCRIPT;
|
||||
$form = Form::make_post_form('添加分类',$formbuider,Url::buildUrl('saveCate'),$jsContent);
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
/**
|
||||
* 添加分类
|
||||
*/
|
||||
public function saveCate(){
|
||||
$request = app('request');
|
||||
$post = $request->post();
|
||||
$data['pid'] = $post['pid'];
|
||||
$data['name'] = $post['name'];
|
||||
if(empty($post['name'] ))
|
||||
Json::fail('分类名称不能为空!');
|
||||
$res = Category::create($data);
|
||||
if($res)
|
||||
Json::successful('添加成功');
|
||||
else
|
||||
Json::fail('添加失败!');
|
||||
|
||||
}
|
||||
/**
|
||||
* 编辑分类
|
||||
*/
|
||||
public function editcate($id){
|
||||
$Category = Category::get($id);
|
||||
if(!$Category) return Json::fail('数据不存在!');
|
||||
$formbuider = [];
|
||||
$formbuider[] = Form::hidden('id',$id);
|
||||
$formbuider[] = Form::select('pid','上级分类',(string)$Category->getData('pid'))->setOptions(function ()use($id){
|
||||
$list = Category::getCateList();
|
||||
$options = [['value'=>0,'label'=>'所有分类']];
|
||||
foreach ($list as $id=>$cateName){
|
||||
$options[] = ['label'=>$cateName['html'].$cateName['name'],'value'=>$cateName['id']];
|
||||
}
|
||||
return $options;
|
||||
})->filterable(1);
|
||||
$formbuider[] = Form::input('name','分类名称',$Category->getData('name'));
|
||||
$jsContent = <<<SCRIPT
|
||||
parent.SuccessCateg();
|
||||
parent.layer.close(parent.layer.getFrameIndex(window.name));
|
||||
SCRIPT;
|
||||
$form = Form::make_post_form('编辑分类',$formbuider,Url::buildUrl('updateCate'),$jsContent);
|
||||
$this->assign(compact('form'));
|
||||
return $this->fetch('public/form-builder');
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新分类
|
||||
* @param $id
|
||||
*/
|
||||
public function updateCate($id)
|
||||
{
|
||||
$data = Util::postMore([
|
||||
'pid',
|
||||
'name'
|
||||
]);
|
||||
if($data['pid'] == '') return Json::fail('请选择父类');
|
||||
if(!$data['name']) return Json::fail('请输入分类名称');
|
||||
Category::edit($data,$id);
|
||||
return Json::successful('分类编辑成功!');
|
||||
}
|
||||
/**
|
||||
* 删除分类
|
||||
*/
|
||||
public function deletecate($id){
|
||||
$chdcount = Category::where('pid',$id)->count();
|
||||
if($chdcount) return Json::fail('有子栏目不能删除');
|
||||
$chdcount = SystemAttachmentModel::where('pid',$id)->count();
|
||||
if($chdcount) return Json::fail('栏目内有图片不能删除');
|
||||
if(Category::del($id))
|
||||
return Json::successful('删除成功!');
|
||||
else
|
||||
return Json::fail('删除失败');
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
49
app/admin/controller/widget/Widgets.php
Normal file
49
app/admin/controller/widget/Widgets.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\widget;
|
||||
|
||||
use app\admin\controller\AuthController;
|
||||
/**
|
||||
* 文件校验控制器
|
||||
* Class SystemFile
|
||||
* @package app\admin\controller\system
|
||||
*
|
||||
*/
|
||||
class Widgets extends AuthController
|
||||
{
|
||||
|
||||
/**
|
||||
* icon
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function icon()
|
||||
{
|
||||
return $this->fetch('widget/icon');
|
||||
}
|
||||
/**
|
||||
* 会员列页面
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function userlist()
|
||||
{
|
||||
return $this->fetch('widget/icon');
|
||||
}
|
||||
/**
|
||||
* 产品列表页
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function productlist()
|
||||
{
|
||||
return $this->fetch('widget/icon');
|
||||
}
|
||||
/**
|
||||
* 图文列表页
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function newtlist()
|
||||
{
|
||||
return $this->fetch('widget/icon');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
21
app/admin/event.php
Normal file
21
app/admin/event.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
// 事件定义文件
|
||||
return [
|
||||
'listen' => [
|
||||
'AppInit' => [],
|
||||
'HttpRun' => [],
|
||||
'HttpEnd' => [],
|
||||
'LogLevel' => [],
|
||||
'LogWrite' => [],
|
||||
]
|
||||
];
|
||||
156
app/admin/model/article/Article.php
Normal file
156
app/admin/model/article/Article.php
Normal file
@ -0,0 +1,156 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
|
||||
*
|
||||
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
|
||||
* @day: 2017/11/02
|
||||
|
||||
*/
|
||||
|
||||
namespace app\admin\model\article;
|
||||
|
||||
use app\admin\model\system\SystemAdmin;
|
||||
use crmeb\traits\ModelTrait;
|
||||
use crmeb\basic\BaseModel;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 图文管理 Model
|
||||
* Class WechatNews
|
||||
* @package app\admin\model\wechat
|
||||
*/
|
||||
class Article extends BaseModel {
|
||||
|
||||
use ModelTrait;
|
||||
|
||||
protected $pk = 'id';
|
||||
|
||||
protected $name = 'article';
|
||||
|
||||
/**
|
||||
* 获取配置分类
|
||||
* @param array $where
|
||||
* @return array
|
||||
*/
|
||||
public static function getAll($where = array()){
|
||||
$model = new self;
|
||||
// if($where['status'] !== '') $model = $model->where('status',$where['status']);
|
||||
// if($where['access'] !== '') $model = $model->where('access',$where['access']);
|
||||
if($where['title'] !== '') $model = $model->where('title','LIKE',"%$where[title]%");
|
||||
if($where['cid'] !== '')
|
||||
$model = $model->where('cid','in',$where['cid']);
|
||||
else
|
||||
if($where['merchant'])
|
||||
$model = $model->where('mer_id','>',0);
|
||||
else
|
||||
$model = $model->where('mer_id',0);
|
||||
$model = $model->where('status',1)->where('hide',0);
|
||||
return self::page($model,function($item){
|
||||
if(!$item['mer_id']) $item['admin_name'] = '总后台管理员---》'.SystemAdmin::where('id',$item['admin_id'])->value('real_name');
|
||||
else $item['admin_name'] = Merchant::where('id',$item['mer_id'])->value('mer_name').'---》'.MerchantAdmin::where('id',$item['admin_id'])->value('real_name');
|
||||
$item['content'] = Db::name('ArticleContent')->where('nid',$item['id'])->value('content');
|
||||
$item['catename'] = Db::name('ArticleCategory')->where('id',$item['cid'])->value('title');
|
||||
},$where);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除图文
|
||||
* @param $id
|
||||
* @return bool
|
||||
*/
|
||||
public static function del($id){
|
||||
return self::edit(['status'=>0],$id,'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定字段的值
|
||||
* @return array
|
||||
*/
|
||||
public static function getNews()
|
||||
{
|
||||
return self::where('status',1)->where('hide',0)->order('id desc')->column('title','id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 给表中的字符串类型追加值
|
||||
* 删除所有有当前分类的id之后重新添加
|
||||
* @param $cid
|
||||
* @param $id
|
||||
* @return bool
|
||||
*/
|
||||
public static function saveBatchCid($cid,$id){
|
||||
$res_all = self::where('cid','LIKE',"%$cid%")->select();//获取所有有当前分类的图文
|
||||
foreach ($res_all as $k=>$v){
|
||||
$cid_arr = explode(',',$v['cid']);
|
||||
if(in_array($cid,$cid_arr)){
|
||||
$key = array_search($cid, $cid_arr);
|
||||
array_splice($cid_arr, $key, 1);
|
||||
}
|
||||
if(empty($cid_arr)) {
|
||||
$data['cid'] = 0;
|
||||
self::edit($data,$v['id']);
|
||||
}else{
|
||||
$data['cid'] = implode(',',$cid_arr);
|
||||
self::edit($data,$v['id']);
|
||||
}
|
||||
}
|
||||
$res = self::where('id','IN',$id)->select();
|
||||
foreach ($res as $k=>$v){
|
||||
if(!in_array($cid,explode(',',$v['cid']))){
|
||||
if(!$v['cid']){
|
||||
$data['cid'] = $cid;
|
||||
}else{
|
||||
$data['cid'] = $v['cid'].','.$cid;
|
||||
}
|
||||
self::edit($data,$v['id']);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function setContent($id,$content){
|
||||
$count = Db::name('ArticleContent')->where('nid',$id)->count();
|
||||
$data['nid'] = $id;
|
||||
$data['content'] = $content;
|
||||
if($count){
|
||||
$contentSql = Db::name('ArticleContent')->where('nid',$id)->value('content');
|
||||
if($contentSql == $content) $res = true;
|
||||
else $res = Db::name('ArticleContent')->where('nid',$id)->update(['content'=>$content]);
|
||||
if($res !== false) $res = true;
|
||||
}else{
|
||||
$res = Db::name('ArticleContent')->insert($data);
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
public static function merchantPage($where = array()){
|
||||
$model = new self;
|
||||
if($where['title'] !== '') $model = $model->where('title','LIKE',"%$where[title]%");
|
||||
if($where['cid'] !== '') $model = $model->where('cid','LIKE',"%$where[cid]%");
|
||||
$model = $model
|
||||
->where('status',1)
|
||||
->where('hide',0)
|
||||
->where('admin_id',$where['admin_id'])
|
||||
->where('mer_id',$where['mer_id']);
|
||||
return self::page($model,function($item){
|
||||
$item['content'] = Db::name('ArticleContent')->where('nid',$item['id'])->value('content');
|
||||
},$where);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定文章列表 图文管理使用
|
||||
* @param string $id
|
||||
* @param string $field
|
||||
* @return false|\PDOStatement|string|\think\Collection
|
||||
*/
|
||||
public static function getArticleList($id = '',$field = 'title,author,image_input,synopsis,id'){
|
||||
$list = self::where('id','IN',$id)->field($field)->select();
|
||||
foreach ($list as $k=>$v){
|
||||
$list[$k]['content'] = Db::name('ArticleContent')->where('nid',$v['id'])->value('content');
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
}
|
||||
116
app/admin/model/article/ArticleCategory.php
Normal file
116
app/admin/model/article/ArticleCategory.php
Normal file
@ -0,0 +1,116 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/11/02
|
||||
*/
|
||||
namespace app\admin\model\article;
|
||||
|
||||
use crmeb\traits\ModelTrait;
|
||||
use app\admin\model\article\Article as ArticleModel;
|
||||
use crmeb\basic\BaseModel;
|
||||
use crmeb\services\UtilService as Util;
|
||||
|
||||
/**
|
||||
* 文章分类model
|
||||
* Class ArticleCategory
|
||||
* @package app\admin\model\wechat
|
||||
*/
|
||||
class ArticleCategory extends BaseModel
|
||||
{
|
||||
use ModelTrait;
|
||||
|
||||
protected $pk = 'id';
|
||||
|
||||
protected $name = 'article_category';
|
||||
|
||||
/**
|
||||
* 获取系统分页数据 分类
|
||||
* @param array $where
|
||||
* @return array
|
||||
*/
|
||||
public static function systemPage($where = array()){
|
||||
$model = new self;
|
||||
if($where['title'] !== '') $model = $model->where('title','LIKE',"%$where[title]%");
|
||||
if($where['status'] !== '') $model = $model->where('status',$where['status']);
|
||||
$model = $model->where('is_del',0);
|
||||
$model = $model->where('hidden',0);
|
||||
return self::page($model);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除分类
|
||||
* @param $id
|
||||
* @return bool
|
||||
*/
|
||||
public static function delArticleCategory($id)
|
||||
{
|
||||
if(count(self::getArticle($id,'*'))>0)
|
||||
return self::setErrorInfo('请先删除改分类下的文章!');
|
||||
return self::edit(['is_del'=>1],$id,'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分类名称和id
|
||||
* @return array
|
||||
*/
|
||||
public static function getField(){
|
||||
return self::where('is_del',0)->where('status',1)->where('hidden',0)->column('title','id');
|
||||
}
|
||||
/**
|
||||
* 分级排序列表
|
||||
* @param null $model
|
||||
* @return array
|
||||
*/
|
||||
public static function getTierList($model = null)
|
||||
{
|
||||
if($model === null) $model = new self();
|
||||
return Util::sortListTier($model->where('is_del',0)->where('status',1)->select()->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分类底下的文章
|
||||
* id 分类表中的分类id
|
||||
* return array
|
||||
* */
|
||||
public static function getArticle($id,$field){
|
||||
$res = ArticleModel::where('status',1)->where('hide',0)->column($field,'id');
|
||||
$new_res = array();
|
||||
foreach ($res as $k=>$v){
|
||||
$cid_arr = explode(',',$v['cid']);
|
||||
if(in_array($id,$cid_arr)){
|
||||
$new_res[$k] = $res[$k];
|
||||
}
|
||||
}
|
||||
return $new_res;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 获取文章分类
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function getArticleCategoryList(){
|
||||
$list = self::where('is_del',0)->where('status',1)->select();
|
||||
if($list) return $list->toArray();
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 获取文章分类信息
|
||||
* @param $id
|
||||
* @param string $field
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getArticleCategoryInfo($id, $field = 'title')
|
||||
{
|
||||
$model = new self;
|
||||
if($id) $model = $model->where('id',$id);
|
||||
$model = $model->where('is_del',0);
|
||||
$model = $model->where('status',1);
|
||||
return $model->column($field,'id');
|
||||
}
|
||||
|
||||
}
|
||||
265
app/admin/model/finance/FinanceModel.php
Normal file
265
app/admin/model/finance/FinanceModel.php
Normal file
@ -0,0 +1,265 @@
|
||||
<?php
|
||||
namespace app\admin\model\finance;
|
||||
|
||||
use crmeb\traits\ModelTrait;
|
||||
use crmeb\basic\BaseModel;
|
||||
use app\models\user\UserBill;
|
||||
use app\admin\model\user\User;
|
||||
use crmeb\services\PHPExcelService;
|
||||
|
||||
/**
|
||||
* 数据统计处理
|
||||
* Class FinanceModel
|
||||
* @package app\admin\model\finance
|
||||
*/
|
||||
class FinanceModel extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* 数据表主键
|
||||
* @var string
|
||||
*/
|
||||
protected $pk = 'id';
|
||||
|
||||
/**
|
||||
* 模型名称
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'user_bill';
|
||||
|
||||
use ModelTrait;
|
||||
|
||||
/**
|
||||
* 处理金额
|
||||
* @param $where
|
||||
* @return array
|
||||
*/
|
||||
public static function systemPage($where)
|
||||
{
|
||||
$model = new self;
|
||||
//翻页
|
||||
$limit = $where['limit'];
|
||||
$offset= $where['offset'];
|
||||
$limit = $offset.','.$limit;
|
||||
//排序
|
||||
$order = '';
|
||||
if(!empty($where['sort'])&&!empty($where['sortOrder'])){
|
||||
$order = $where['sort'].' '.$where['sortOrder'];
|
||||
}
|
||||
unset($where['limit']);unset($where['offset']);
|
||||
unset($where['sort']);unset($where['sortOrder']);
|
||||
if(!empty($where['add_time'])){
|
||||
list($startTime,$endTime) = explode(' - ',$where['add_time']);
|
||||
$where['add_time'] = array('between',[strtotime($startTime),strtotime($endTime)]);
|
||||
}else{
|
||||
$where['add_time'] = array('between',[strtotime(date('Y/m').'/01'),strtotime(date('Y/m').'/'.date('t'))]);
|
||||
}
|
||||
if(empty($where['title'])){
|
||||
unset($where['title']);
|
||||
}
|
||||
|
||||
$total = $model->where($where)->count();
|
||||
$rows = $model->where($where)->order($order)->limit($limit)->select()->each(function($e){
|
||||
return $e['add_time'] = date('Y-m-d H:i:s',$e['add_time']);
|
||||
})->toArray();
|
||||
return compact('total','rows');
|
||||
}
|
||||
public static function getBillList($where){
|
||||
$data=($data=self::setWhereList($where)->page((int)$where['page'],(int)$where['limit'])->select()) && count($data) ? $data->toArray():[];
|
||||
$count=self::setWhereList($where)->count();
|
||||
return compact('data','count');
|
||||
}
|
||||
public static function SaveExport($where){
|
||||
$data=($data=self::setWhereList($where)->select()) && count($data) ? $data->toArray():[];
|
||||
$export = [];
|
||||
foreach ($data as $value){
|
||||
$export[]=[
|
||||
$value['uid'],
|
||||
$value['nickname'],
|
||||
$value['pm']==0 ? '-'.$value['number']:$value['number'],
|
||||
$value['title'],
|
||||
$value['mark'],
|
||||
$value['add_time'],
|
||||
];
|
||||
}
|
||||
PHPExcelService::setExcelHeader(['会员ID','昵称','金额/积分','类型','备注','创建时间'])
|
||||
->setExcelTile('资金监控', '资金监控',date('Y-m-d H:i:s',time()))
|
||||
->setExcelContent($export)
|
||||
->ExcelSave();
|
||||
}
|
||||
public static function setWhereList($where){
|
||||
$time['data']='';
|
||||
if($where['start_time']!='' && $where['end_time']!=''){
|
||||
$time['data']=$where['start_time'].' - '.$where['end_time'];
|
||||
}
|
||||
$model=self::getModelTime($time,self::alias('A')
|
||||
->join('user B','B.uid=A.uid')
|
||||
->where('A.category','not in','integral')
|
||||
->order('A.add_time desc'),'A.add_time');
|
||||
if(trim($where['type'])!=''){
|
||||
$model=$model->where('A.type',$where['type']);
|
||||
}else{
|
||||
$model=$model->where('A.type','not in','gain,system_sub,deduction,sign');
|
||||
}
|
||||
if($where['nickname']!=''){
|
||||
$model=$model->where('B.nickname|B.uid','like',"%$where[nickname]%");
|
||||
}
|
||||
return $model->field(['A.*','FROM_UNIXTIME(A.add_time,"%Y-%m-%d %H:%i:%s") as add_time','B.uid','B.nickname']);
|
||||
}
|
||||
/**
|
||||
* 获取营业数据
|
||||
*/
|
||||
public static function getOrderInfo($where)
|
||||
{
|
||||
$orderinfo = self::getTimeWhere($where)
|
||||
->field('sum(total_price) total_price,sum(cost) cost,sum(pay_postage) pay_postage,sum(pay_price) pay_price,sum(coupon_price) coupon_price,sum(deduction_price) deduction_price,from_unixtime(pay_time,\'%Y-%m-%d\') pay_time')->order('pay_time')->group('from_unixtime(pay_time,\'%Y-%m-%d\')')->select()->toArray();
|
||||
$price = 0;
|
||||
$postage = 0;
|
||||
$deduction = 0;
|
||||
$coupon = 0;
|
||||
$cost = 0;
|
||||
foreach ($orderinfo as $info) {
|
||||
$price = bcadd($price, $info['total_price'], 2);//应支付
|
||||
$postage = bcadd($postage, $info['pay_postage'], 2);//邮费
|
||||
$deduction = bcadd($deduction, $info['deduction_price'], 2);//抵扣
|
||||
$coupon = bcadd($coupon, $info['coupon_price'], 2);//优惠券
|
||||
$cost = bcadd($cost, $info['cost'], 2);//成本
|
||||
}
|
||||
return compact('orderinfo', 'price', 'postage', 'deduction', 'coupon', 'cost');
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理where条件
|
||||
*/
|
||||
public static function statusByWhere($status, $model = null)
|
||||
{
|
||||
if ($model == null) $model = new self;
|
||||
if ('' === $status)
|
||||
return $model;
|
||||
else if ($status == 'weixin')//微信支付
|
||||
return $model->where('pay_type', 'weixin');
|
||||
else if ($status == 'yue')//余额支付
|
||||
return $model->where('pay_type', 'yue');
|
||||
else if ($status == 'offline')//线下支付
|
||||
return $model->where('pay_type', 'offline');
|
||||
else
|
||||
return $model;
|
||||
}
|
||||
|
||||
public static function getTimeWhere($where, $model = null)
|
||||
{
|
||||
return self::getTime($where)->where('paid', 1)->where('refund_status', 0);
|
||||
}
|
||||
/**
|
||||
* 获取时间区间
|
||||
*/
|
||||
public static function getTime($where,$model=null,$prefix='add_time'){
|
||||
if ($model == null) $model = new self;
|
||||
if ($where['data'] == '') {
|
||||
switch ($where['date']){
|
||||
case 'today':case 'week':case 'month':case 'year':
|
||||
$model=$model->whereTime($prefix,$where['date']);
|
||||
break;
|
||||
case 'quarter':
|
||||
list($startTime,$endTime)=User::getMonth('n');
|
||||
$model = $model->where($prefix, '>', strtotime($startTime));
|
||||
$model = $model->where($prefix, '<', strtotime($endTime));
|
||||
break;
|
||||
}
|
||||
}else{
|
||||
list($startTime, $endTime) = explode(' - ', $where['data']);
|
||||
$model = $model->where($prefix, '>', strtotime($startTime));
|
||||
$model = $model->where($prefix, '<', strtotime($endTime));
|
||||
}
|
||||
return $model;
|
||||
}
|
||||
/**
|
||||
* 获取新增消费
|
||||
*/
|
||||
public static function getConsumption($where)
|
||||
{
|
||||
$consumption=self::getTime($where,new UserBill,'b.add_time')->alias('a')->join('user b','a.uid = b.uid')
|
||||
->field('sum(a.number) number')
|
||||
->where('a.type','pay_product')->find()->toArray();
|
||||
return $consumption;
|
||||
}
|
||||
/**
|
||||
* 获取拼团商品
|
||||
*/
|
||||
public static function getPink($where)
|
||||
{
|
||||
$pink = self::getTimeWhere($where)->where('pink_id', '<>', 0)->sum('pay_price');
|
||||
return $pink;
|
||||
}
|
||||
/**
|
||||
* 获取秒杀商品
|
||||
*/
|
||||
public static function getSeckill($where){
|
||||
$seckill=self::getTimeWhere($where)->where('seckill_id', '<>', 0)->sum('pay_price');
|
||||
return $seckill;
|
||||
}
|
||||
/**
|
||||
* 获取普通商品数
|
||||
*/
|
||||
public static function getOrdinary($where)
|
||||
{
|
||||
$ordinary = self::getTimeWhere($where)->where('pink_id', 0)->where('seckill_id',0)->sum('pay_price');
|
||||
return $ordinary;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户充值
|
||||
*/
|
||||
public static function getRecharge($where)
|
||||
{
|
||||
$Recharge = self::getTime($where,new UserBill)->where('type', 'system_add')->where('category','now_money')->sum('number');
|
||||
return $Recharge;
|
||||
}
|
||||
/**
|
||||
* 获取推广金
|
||||
*/
|
||||
public static function getExtension($where)
|
||||
{
|
||||
$extension = self::getTime($where,new UserBill)->where('type', 'brokerage')->where('category','now_money')->sum('number');
|
||||
return $extension;
|
||||
}
|
||||
|
||||
/**
|
||||
* 最近交易
|
||||
*/
|
||||
public static function trans()
|
||||
{
|
||||
$trans = self::alias('a')
|
||||
->join('user b', 'a.uid=b.uid')
|
||||
->join('__store_order_cart_info__ c', 'a.id=c.oid')
|
||||
->join('__store_product__ d', 'c.product_id=d.id')
|
||||
->field('b.nickname,a.pay_price,d.store_name')
|
||||
->order('a.add_time DESC')
|
||||
->limit('6')
|
||||
->select()->toArray();
|
||||
return $trans;
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出表格
|
||||
*/
|
||||
public static function systemTable($where){
|
||||
$orderinfos=self::getOrderInfo($where);
|
||||
if($where['export'] == 1){
|
||||
$export = [];
|
||||
$orderinfo=$orderinfos['orderinfo'];
|
||||
foreach($orderinfo as $info){
|
||||
$time=$info['pay_time'];
|
||||
$price = $info['total_price']+$info['pay_postage'];
|
||||
$zhichu = $info['coupon_price']+$info['deduction_price']+$info['cost'];
|
||||
$profit = ($info['total_price']+$info['pay_postage'])-($info['coupon_price']+$info['deduction_price']+$info['cost']);
|
||||
$deduction=$info['deduction_price'];//积分抵扣
|
||||
$coupon=$info['coupon_price'];//优惠
|
||||
$cost=$info['cost'];//成本
|
||||
$export[] = [$time,$price,$zhichu,$cost,$coupon,$deduction,$profit];
|
||||
}
|
||||
// ExportService::exportCsv($export,'统计'.time(),['时间','营业额(元)','支出(元)','成本','优惠','积分抵扣','盈利(元)']);
|
||||
PHPExcelService::setExcelHeader(['时间','营业额(元)','支出(元)','成本','优惠','积分抵扣','盈利(元)'])->setExcelTile('财务统计', '财务统计',date('Y-m-d H:i:s',time()))->setExcelContent($export)->ExcelSave();
|
||||
}
|
||||
}
|
||||
}
|
||||
1253
app/admin/model/order/StoreOrder.php
Normal file
1253
app/admin/model/order/StoreOrder.php
Normal file
File diff suppressed because it is too large
Load Diff
44
app/admin/model/order/StoreOrderCartInfo.php
Normal file
44
app/admin/model/order/StoreOrderCartInfo.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/12/26
|
||||
*/
|
||||
|
||||
namespace app\admin\model\order;
|
||||
|
||||
|
||||
use crmeb\basic\BaseModel;
|
||||
use crmeb\traits\ModelTrait;
|
||||
|
||||
class StoreOrderCartInfo extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* 模型名称
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'store_order_cart_info';
|
||||
|
||||
use ModelTrait;
|
||||
|
||||
/** 获取订单产品列表
|
||||
* @param $oid
|
||||
* @return array
|
||||
*/
|
||||
public static function getProductNameList($oid)
|
||||
{
|
||||
$cartInfo = self::where('oid',$oid)->select();
|
||||
$goodsName = [];
|
||||
foreach ($cartInfo as $cart){
|
||||
if(isset($cart['cart_info']['productInfo'])){
|
||||
$suk = isset($cart['cart_info']['productInfo']['attrInfo']) ? '('.$cart['cart_info']['productInfo']['attrInfo']['suk'].')' : '';
|
||||
$goodsName[] = $cart['cart_info']['productInfo']['store_name'].$suk;
|
||||
}else{
|
||||
$goodsName[] = '';
|
||||
}
|
||||
}
|
||||
return $goodsName;
|
||||
}
|
||||
|
||||
}
|
||||
63
app/admin/model/order/StoreOrderStatus.php
Normal file
63
app/admin/model/order/StoreOrderStatus.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/11/11
|
||||
*/
|
||||
|
||||
namespace app\admin\model\order;
|
||||
|
||||
use crmeb\traits\ModelTrait;
|
||||
use crmeb\basic\BaseModel;
|
||||
|
||||
/**
|
||||
* 订单操作纪律model
|
||||
* Class StoreOrderStatus
|
||||
* @package app\admin\model\store
|
||||
*/
|
||||
class StoreOrderStatus extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* 模型名称
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'store_order_status';
|
||||
|
||||
use ModelTrait;
|
||||
|
||||
/**
|
||||
* @param $oid
|
||||
* @param $type
|
||||
* @param $message
|
||||
*/
|
||||
public static function setStatus($oid,$type,$message){
|
||||
$data['oid'] = (int)$oid;
|
||||
$data['change_type'] = $type;
|
||||
$data['change_message'] = $message;
|
||||
$data['change_time'] = time();
|
||||
self::create($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $where
|
||||
* @return array
|
||||
*/
|
||||
public static function systemPage($oid){
|
||||
$model = new self;
|
||||
$model = $model->where('oid',$oid);
|
||||
$model = $model->order('change_time asc');
|
||||
return self::page($model);
|
||||
}
|
||||
/**
|
||||
* @param $where
|
||||
* @return array
|
||||
*/
|
||||
public static function systemPageMer($oid){
|
||||
$model = new self;
|
||||
$model = $model->where('oid',$oid);
|
||||
// $model = $model->where('change_type','LIKE','mer_%');
|
||||
$model = $model->order('change_time asc');
|
||||
return self::page($model);
|
||||
}
|
||||
}
|
||||
218
app/admin/model/record/StoreStatistics.php
Normal file
218
app/admin/model/record/StoreStatistics.php
Normal file
@ -0,0 +1,218 @@
|
||||
<?php
|
||||
namespace app\admin\model\record;
|
||||
|
||||
use crmeb\traits\ModelTrait;
|
||||
use crmeb\basic\BaseModel;
|
||||
use app\models\user\UserBill;
|
||||
use crmeb\services\PHPExcelService;
|
||||
|
||||
class StoreStatistics extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 数据表主键
|
||||
* @var string
|
||||
*/
|
||||
protected $pk = 'id';
|
||||
|
||||
/**
|
||||
* 模型名称
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'store_order';
|
||||
|
||||
use ModelTrait;
|
||||
|
||||
/**
|
||||
* 处理金额
|
||||
* @param $where
|
||||
* @return array
|
||||
*/
|
||||
public static function getOrderPrice($where)
|
||||
{
|
||||
$model = new self;
|
||||
$price = array();
|
||||
$price['pay_price_wx'] = 0;//微信支付金额
|
||||
$price['pay_price_yue'] = 0;//余额支付金额
|
||||
$price['pay_price_offline'] = 0;//线下支付金额
|
||||
$list = self::getTimeWhere($where, $model)->field('pay_price,total_price,deduction_price,coupon_price,total_postage,pay_type,pay_time')->select()->toArray();
|
||||
if (empty($list)) {
|
||||
$price['pay_price_wx'] = 0;
|
||||
$price['pay_price_yue'] = 0;
|
||||
$price['pay_price_offline'] = 0;
|
||||
}
|
||||
foreach ($list as $v) {
|
||||
if ($v['pay_type'] == 'weixin') {
|
||||
$price['pay_price_wx'] = bcadd($price['pay_price_wx'], $v['pay_price'], 2);
|
||||
} elseif ($v['pay_type'] == 'yue') {
|
||||
$price['pay_price_yue'] = bcadd($price['pay_price_yue'], $v['pay_price'], 2);
|
||||
} elseif ($v['pay_type'] == 'offline') {
|
||||
$price['pay_price_offline'] = bcadd($price['pay_price_offline'], $v['pay_price'], 2);
|
||||
}
|
||||
}
|
||||
return $price;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取营业数据
|
||||
*/
|
||||
public static function getOrderInfo($where)
|
||||
{
|
||||
$orderinfo = self::getTimeWhere($where)
|
||||
->field('sum(total_price) total_price,sum(cost) cost,sum(pay_postage) pay_postage,sum(pay_price) pay_price,sum(coupon_price) coupon_price,sum(deduction_price) deduction_price,from_unixtime(pay_time,\'%Y-%m-%d\') pay_time')->order('pay_time')->group('from_unixtime(pay_time,\'%Y-%m-%d\')')->select()->toArray();
|
||||
$price = 0;
|
||||
$postage = 0;
|
||||
$deduction = 0;
|
||||
$coupon = 0;
|
||||
$cost = 0;
|
||||
foreach ($orderinfo as $info) {
|
||||
$price = bcadd($price, $info['total_price'], 2);//应支付
|
||||
$postage = bcadd($postage, $info['pay_postage'], 2);//邮费
|
||||
$deduction = bcadd($deduction, $info['deduction_price'], 2);//抵扣
|
||||
$coupon = bcadd($coupon, $info['coupon_price'], 2);//优惠券
|
||||
$cost = bcadd($cost, $info['cost'], 2);//成本
|
||||
}
|
||||
return compact('orderinfo', 'price', 'postage', 'deduction', 'coupon', 'cost');
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理where条件
|
||||
*/
|
||||
public static function statusByWhere($status, $model = null)
|
||||
{
|
||||
if ($model == null) $model = new self;
|
||||
if ('' === $status)
|
||||
return $model;
|
||||
else if ($status == 'weixin')//微信支付
|
||||
return $model->where('pay_type', 'weixin');
|
||||
else if ($status == 'yue')//余额支付
|
||||
return $model->where('pay_type', 'yue');
|
||||
else if ($status == 'offline')//线下支付
|
||||
return $model->where('pay_type', 'offline');
|
||||
else
|
||||
return $model;
|
||||
}
|
||||
|
||||
public static function getTimeWhere($where, $model = null)
|
||||
{
|
||||
return self::getTime($where)->where('paid', 1)->where('refund_status', 0);
|
||||
}
|
||||
/**
|
||||
* 获取时间区间
|
||||
*/
|
||||
public static function getTime($where,$model=null,$prefix='add_time'){
|
||||
if ($model == null) $model = new self;
|
||||
if(!$where['date']) return $model;
|
||||
if ($where['data'] == '') {
|
||||
$limitTimeList = [
|
||||
'today'=>implode(' - ',[date('Y/m/d'),date('Y/m/d',strtotime('+1 day'))]),
|
||||
'week'=>implode(' - ',[
|
||||
date('Y/m/d', (time() - ((date('w') == 0 ? 7 : date('w')) - 1) * 24 * 3600)),
|
||||
date('Y-m-d', (time() + (7 - (date('w') == 0 ? 7 : date('w'))) * 24 * 3600))
|
||||
]),
|
||||
'month'=>implode(' - ',[date('Y/m').'/01',date('Y/m').'/'.date('t')]),
|
||||
'quarter'=>implode(' - ',[
|
||||
date('Y').'/'.(ceil((date('n'))/3)*3-3+1).'/01',
|
||||
date('Y').'/'.(ceil((date('n'))/3)*3).'/'.date('t',mktime(0,0,0,(ceil((date('n'))/3)*3),1,date('Y')))
|
||||
]),
|
||||
'year'=>implode(' - ',[
|
||||
date('Y').'/01/01',date('Y/m/d',strtotime(date('Y').'/01/01 + 1year -1 day'))
|
||||
])
|
||||
];
|
||||
$where['data'] = $limitTimeList[$where['date']];
|
||||
}
|
||||
list($startTime, $endTime) = explode(' - ', $where['data']);
|
||||
$model = $model->where($prefix, '>', strtotime($startTime));
|
||||
$model = $model->where($prefix, '<', strtotime($endTime));
|
||||
return $model;
|
||||
}
|
||||
/**
|
||||
* 获取新增消费
|
||||
*/
|
||||
public static function getConsumption($where)
|
||||
{
|
||||
$consumption=self::getTime($where,new UserBill,'b.add_time')->alias('a')->join('__user__ b','a.uid = b.uid')
|
||||
->field('sum(a.number) number')
|
||||
->where('a.type','pay_product')->find()->toArray();
|
||||
return $consumption;
|
||||
}
|
||||
/**
|
||||
* 获取拼团商品
|
||||
*/
|
||||
public static function getPink($where)
|
||||
{
|
||||
$pink = self::getTimeWhere($where)->where('pink_id', '<>', 0)->sum('pay_price');
|
||||
return $pink;
|
||||
}
|
||||
/**
|
||||
* 获取秒杀商品
|
||||
*/
|
||||
public static function getSeckill($where){
|
||||
$seckill=self::getTimeWhere($where)->where('seckill_id', '<>', 0)->sum('pay_price');
|
||||
return $seckill;
|
||||
}
|
||||
/**
|
||||
* 获取普通商品数
|
||||
*/
|
||||
public static function getOrdinary($where)
|
||||
{
|
||||
$ordinary = self::getTimeWhere($where)->where('pink_id', 0)->where('seckill_id','0')->sum('pay_price');
|
||||
return $ordinary;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户充值
|
||||
*/
|
||||
public static function getRecharge($where)
|
||||
{
|
||||
$Recharge = self::getTime($where,new UserBill)->where('type', 'system_add')->where('category','now_money')->sum('number');
|
||||
return $Recharge;
|
||||
}
|
||||
/**
|
||||
* 获取推广金
|
||||
*/
|
||||
public static function getExtension($where)
|
||||
{
|
||||
$extension = self::getTime($where,new UserBill)->where('type', 'brokerage')->where('category','now_money')->sum('number');
|
||||
return $extension;
|
||||
}
|
||||
|
||||
/**
|
||||
* 最近交易
|
||||
*/
|
||||
public static function trans()
|
||||
{
|
||||
$trans = self::alias('a')
|
||||
->join('__user__ b', 'a.uid=b.uid','left')
|
||||
->join('__store_order_cart_info__ c', 'a.id=c.oid')
|
||||
->join('__store_product__ d', 'c.product_id=d.id')
|
||||
->field('b.nickname,a.pay_price,d.store_name')
|
||||
->order('a.add_time DESC')
|
||||
->limit('6')
|
||||
->select()->toArray();
|
||||
return $trans;
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出表格
|
||||
*/
|
||||
public static function systemTable($where){
|
||||
$orderinfos=self::getOrderInfo($where);
|
||||
if($where['export'] == 1){
|
||||
$export = [];
|
||||
$orderinfo=$orderinfos['orderinfo'];
|
||||
foreach($orderinfo as $info){
|
||||
$time=$info['pay_time'];
|
||||
$price = $info['total_price']+$info['pay_postage'];
|
||||
$zhichu = $info['coupon_price']+$info['deduction_price']+$info['cost'];
|
||||
$profit = ($info['total_price']+$info['pay_postage'])-($info['coupon_price']+$info['deduction_price']+$info['cost']);
|
||||
$deduction=$info['deduction_price'];//积分抵扣
|
||||
$coupon=$info['coupon_price'];//优惠
|
||||
$cost=$info['cost'];//成本
|
||||
$export[] = [$time,$price,$zhichu,$cost,$coupon,$deduction,$profit];
|
||||
}
|
||||
// ExportService::exportCsv($export,'统计'.time(),['时间','营业额(元)','支出(元)','成本','优惠','积分抵扣','盈利(元)']);
|
||||
dump($export);
|
||||
PHPExcelService::setExcelHeader(['时间','营业额(元)','支出(元)','成本','优惠','积分抵扣','盈利(元)'])->setExcelTile('财务统计', '财务统计',date('Y-m-d H:i:s',time()))->setExcelContent($export)->ExcelSave();
|
||||
}
|
||||
}
|
||||
}
|
||||
72
app/admin/model/record/StoreVisit.php
Normal file
72
app/admin/model/record/StoreVisit.php
Normal file
@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/**
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/11/11
|
||||
*/
|
||||
namespace app\admin\model\store;
|
||||
|
||||
use crmeb\traits\ModelTrait;
|
||||
use crmeb\basic\BaseModel;
|
||||
use app\admin\model\user\User;
|
||||
|
||||
/**
|
||||
* TODO 产品浏览记录
|
||||
* Class StoreVisit
|
||||
* @package app\admin\model\store
|
||||
*/
|
||||
class StoreVisit extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 数据表主键
|
||||
* @var string
|
||||
*/
|
||||
protected $pk = 'id';
|
||||
|
||||
/**
|
||||
* 模型名称
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'store_visit';
|
||||
|
||||
use ModelTrait;
|
||||
|
||||
/**
|
||||
* @param $date
|
||||
* @param array $class
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function getVisit($date,$class=[]){
|
||||
$model=new self();
|
||||
switch ($date){
|
||||
case null:case 'today':case 'week':case 'year':
|
||||
if($date==null) $date='month';
|
||||
$model=$model->whereTime('add_time',$date);
|
||||
break;
|
||||
case 'quarter':
|
||||
list($startTime,$endTime)=User::getMonth('n');
|
||||
$model = $model->where('add_time','>',$startTime);
|
||||
$model = $model->where('add_time','<',$endTime);
|
||||
break;
|
||||
default:
|
||||
list($startTime,$endTime)=explode('-',$date);
|
||||
$model = $model->where('add_time','>',strtotime($startTime));
|
||||
$model = $model->where('add_time','<',strtotime($endTime));
|
||||
break;
|
||||
}
|
||||
$list=$model->group('type')->field('sum(count) as sum,product_id,cate_id,type,content')->order('sum desc')->limit(0,10)->select()->toArray();
|
||||
$view=[];
|
||||
foreach ($list as $key=>$val){
|
||||
$now_list['name']=$val['type']=='viwe'?'浏览量':'搜索';
|
||||
$now_list['value']=$val['sum'];
|
||||
$now_list['class']=isset($class[$key])?$class[$key]:'';
|
||||
$view[]=$now_list;
|
||||
}
|
||||
if(empty($list)){
|
||||
$view=[['name'=>'暂无数据', 'value'=>100, 'class'=>'']];
|
||||
}
|
||||
return $view;
|
||||
}
|
||||
}
|
||||
56
app/admin/model/routine/RoutineFormId.php
Normal file
56
app/admin/model/routine/RoutineFormId.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
namespace app\admin\model\routine;
|
||||
|
||||
use crmeb\basic\BaseModel;
|
||||
use crmeb\traits\ModelTrait;
|
||||
|
||||
/**
|
||||
* 表单ID表
|
||||
* Class RoutineFormId
|
||||
* @package app\admin\model\routine
|
||||
*/
|
||||
class RoutineFormId extends BaseModel {
|
||||
|
||||
/**
|
||||
* 数据表主键
|
||||
* @var string
|
||||
*/
|
||||
protected $pk = 'id';
|
||||
|
||||
/**
|
||||
* 模型名称
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'routine_form_id';
|
||||
|
||||
|
||||
use ModelTrait;
|
||||
|
||||
/**
|
||||
* 删除已失效的formID
|
||||
* @return int
|
||||
*/
|
||||
public static function delStatusInvalid(){
|
||||
return self::where('status',2)->where('stop_time','<',time())->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一个可以使用的formId
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public static function getFormIdOne($uid = 0){
|
||||
$formId = self::where('status',1)->where('stop_time','>',time())->where('uid',$uid)->order('id asc')->find();
|
||||
if($formId) return $formId['form_id'];
|
||||
else return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改一个FormID为已使用
|
||||
* @param string $formId
|
||||
* @return $this|bool
|
||||
*/
|
||||
public static function delFormIdOne($formId = ''){
|
||||
if($formId == '') return true;
|
||||
return self::where('form_id',$formId)->update(['status'=>2]);
|
||||
}
|
||||
}
|
||||
52
app/admin/model/routine/RoutineTemplate.php
Normal file
52
app/admin/model/routine/RoutineTemplate.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/**
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/11/02
|
||||
*/
|
||||
|
||||
namespace app\admin\model\routine;
|
||||
|
||||
use crmeb\traits\ModelTrait;
|
||||
use crmeb\basic\BaseModel;
|
||||
|
||||
/**
|
||||
* 小程序模板消息Model
|
||||
* Class RoutineTemplate
|
||||
* @package app\admin\model\wechat
|
||||
*/
|
||||
class RoutineTemplate extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 数据表主键
|
||||
* @var string
|
||||
*/
|
||||
protected $pk = 'id';
|
||||
|
||||
/**
|
||||
* 模型名称
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'routine_template';
|
||||
|
||||
use ModelTrait;
|
||||
|
||||
/**
|
||||
* 获取系统分页数据 分类
|
||||
* @param array $where
|
||||
* @return array
|
||||
*/
|
||||
public static function systemPage($where = array()){
|
||||
$model = new self;
|
||||
if($where['name'] !== '') $model = $model->where('name','LIKE',"%$where[name]%");
|
||||
if($where['status'] !== '') $model = $model->where('status',$where['status']);
|
||||
return self::page($model, $where);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据模版编号获取模版ID
|
||||
* @param $tempkey
|
||||
*/
|
||||
public static function getTempid($tempkey){
|
||||
return self::where('tempkey',$tempkey)->where('status',1)->cache(true,3600)->value('tempid');
|
||||
}
|
||||
}
|
||||
142
app/admin/model/store/StoreCategory.php
Normal file
142
app/admin/model/store/StoreCategory.php
Normal file
@ -0,0 +1,142 @@
|
||||
<?php
|
||||
/**
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/11/11
|
||||
*/
|
||||
|
||||
namespace app\admin\model\store;
|
||||
|
||||
use crmeb\traits\ModelTrait;
|
||||
use crmeb\basic\BaseModel;
|
||||
use crmeb\services\UtilService;
|
||||
|
||||
/**
|
||||
* Class StoreCategory
|
||||
* @package app\admin\model\store
|
||||
*/
|
||||
class StoreCategory extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* 数据表主键
|
||||
* @var string
|
||||
*/
|
||||
protected $pk = 'id';
|
||||
|
||||
/**
|
||||
* 模型名称
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'store_category';
|
||||
|
||||
use ModelTrait;
|
||||
|
||||
/*
|
||||
* 异步获取分类列表
|
||||
* @param $where
|
||||
* @return array
|
||||
*/
|
||||
public static function CategoryList($where){
|
||||
$data=($data=self::systemPage($where,true)->page((int)$where['page'],(int)$where['limit'])->select()) && count($data) ? $data->toArray() :[];
|
||||
foreach ($data as &$item){
|
||||
if($item['pid']){
|
||||
$item['pid_name'] = self::where('id',$item['pid'])->value('cate_name');
|
||||
}else{
|
||||
$item['pid_name'] = '顶级';
|
||||
}
|
||||
}
|
||||
$count=self::systemPage($where,true)->count();
|
||||
return compact('count','data');
|
||||
}
|
||||
/**
|
||||
* @param $where
|
||||
* @return array
|
||||
*/
|
||||
public static function systemPage($where,$isAjax=false){
|
||||
$model = new self;
|
||||
if($where['pid'] != '') $model = $model->where('pid',$where['pid']);
|
||||
else if($where['pid']=='' && $where['cate_name']=='') $model = $model->where('pid',0);
|
||||
if($where['is_show'] != '') $model = $model->where('is_show',$where['is_show']);
|
||||
if($where['cate_name'] != '') $model = $model->where('cate_name','LIKE',"%$where[cate_name]%");
|
||||
if($isAjax===true){
|
||||
if(isset($where['order']) && $where['order']!=''){
|
||||
$model=$model->order(self::setOrder($where['order']));
|
||||
}else{
|
||||
$model=$model->order('sort desc,id desc');
|
||||
}
|
||||
return $model;
|
||||
}
|
||||
return self::page($model,function ($item){
|
||||
if($item['pid']){
|
||||
$item['pid_name'] = self::where('id',$item['pid'])->value('cate_name');
|
||||
}else{
|
||||
$item['pid_name'] = '顶级';
|
||||
}
|
||||
},$where);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取顶级分类
|
||||
* @return array
|
||||
*/
|
||||
public static function getCategory()
|
||||
{
|
||||
return self::where('is_show',1)->column('cate_name','id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 分级排序列表
|
||||
* @param null $model
|
||||
* @param int $type
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function getTierList($model = null, $type = 0)
|
||||
{
|
||||
if($model === null) $model = new self();
|
||||
if(!$type) return UtilService::sortListTier($model->order('sort desc,id desc')->where('pid', 0)->select()->toArray());
|
||||
return UtilService::sortListTier($model->order('sort desc,id desc')->select()->toArray());
|
||||
}
|
||||
|
||||
public static function delCategory($id){
|
||||
$count = self::where('pid',$id)->count();
|
||||
if($count)
|
||||
return self::setErrorInfo('请先删除下级子分类');
|
||||
else{
|
||||
return self::del($id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 产品分类隐藏显示
|
||||
* @param $id
|
||||
* @param $show
|
||||
* @return bool
|
||||
*/
|
||||
public static function setCategoryShow($id, $show)
|
||||
{
|
||||
$count = self::where('id', $id)->count();
|
||||
if(!$count) return self::setErrorInfo('参数错误');
|
||||
$count = self::where('id', $id)->where('is_show', $show)->count();
|
||||
if($count) return true;
|
||||
$pid = self::where('id', $id)->value('pid');
|
||||
self::beginTrans();
|
||||
$res1 = true;
|
||||
$res2 = self::where('id', $id)->update(['is_show' => $show]);
|
||||
if(!$pid){//一级分类隐藏
|
||||
$count = self::where('pid', $id)->count();
|
||||
if($count){
|
||||
$count = self::where('pid', $id)->where('is_show', $show)->count();
|
||||
$countWhole = self::where('pid', $id)->count();
|
||||
if(!$count || $countWhole > $count){
|
||||
$res1 = self::where('pid', $id)->update(['is_show' => $show]);
|
||||
}
|
||||
}
|
||||
}
|
||||
$res = $res1 && $res2;
|
||||
self::checkTrans($res);
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
115
app/admin/model/store/StoreCouponUser.php
Normal file
115
app/admin/model/store/StoreCouponUser.php
Normal file
@ -0,0 +1,115 @@
|
||||
<?php
|
||||
namespace app\admin\model\store;
|
||||
|
||||
use crmeb\basic\BaseModel;
|
||||
use crmeb\traits\ModelTrait;
|
||||
use think\facade\Db;
|
||||
|
||||
class StoreCouponUser extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 数据表主键
|
||||
* @var string
|
||||
*/
|
||||
protected $pk = 'id';
|
||||
|
||||
/**
|
||||
* 模型名称
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'store_coupon_user';
|
||||
|
||||
use ModelTrait;
|
||||
|
||||
public static function tidyCouponList($couponList)
|
||||
{
|
||||
$time = time();
|
||||
foreach ($couponList as &$coupon){
|
||||
$coupon['_add_time'] = date('Y/m/d',$coupon['add_time']);
|
||||
$coupon['_end_time'] = date('Y/m/d',$coupon['end_time']);
|
||||
$coupon['use_min_price'] = floatval($coupon['use_min_price']);
|
||||
$coupon['coupon_price'] = floatval($coupon['coupon_price']);
|
||||
if($coupon['is_fail']){
|
||||
$coupon['_type'] = 0;
|
||||
$coupon['_msg'] = '已失效';
|
||||
}else if ($coupon['status'] == 1){
|
||||
$coupon['_type'] = 0;
|
||||
$coupon['_msg'] = '已使用';
|
||||
}else if ($coupon['status'] == 2){
|
||||
$coupon['_type'] = 0;
|
||||
$coupon['_msg'] = '已过期';
|
||||
}else if($coupon['add_time'] > $time || $coupon['end_time'] < $time){
|
||||
$coupon['_type'] = 0;
|
||||
$coupon['_msg'] = '已过期';
|
||||
}else{
|
||||
if($coupon['add_time']+ 3600*24 > $time){
|
||||
$coupon['_type'] = 2;
|
||||
$coupon['_msg'] = '可使用';
|
||||
}else{
|
||||
$coupon['_type'] = 1;
|
||||
$coupon['_msg'] = '可使用';
|
||||
}
|
||||
}
|
||||
$coupon['integral']= Db::name('store_coupon')->where(['id'=>$coupon['cid']])->value('integral');
|
||||
}
|
||||
return $couponList;
|
||||
}
|
||||
//获取个人优惠券列表
|
||||
public static function getOneCouponsList($where){
|
||||
$list=self::where(['uid'=>$where['uid']])->page((int)$where['page'],(int)$where['limit'])->select();
|
||||
return self::tidyCouponList($list);
|
||||
}
|
||||
//获取优惠劵头部信息
|
||||
public static function getCouponBadgeList($where){
|
||||
return [
|
||||
[
|
||||
'name'=>'总发放优惠券',
|
||||
'field'=>'张',
|
||||
'count'=>self::getModelTime($where, Db::name('store_coupon_issue'))->where('status',1)->sum('total_count'),
|
||||
'background_color'=>'layui-bg-blue',
|
||||
'col'=>6,
|
||||
],
|
||||
[
|
||||
'name'=>'总使用优惠券',
|
||||
'field'=>'张',
|
||||
'count'=>self::getModelTime($where,new self())->where('status',1)->count(),
|
||||
'background_color'=>'layui-bg-blue',
|
||||
'col'=>6,
|
||||
]
|
||||
];
|
||||
}
|
||||
//获取优惠劵图表
|
||||
public static function getConponCurve($where,$limit=20){
|
||||
//优惠劵发放记录
|
||||
$list=self::getModelTime($where, Db::name('store_coupon_issue')
|
||||
->where('status',1)
|
||||
->field(['FROM_UNIXTIME(add_time,"%Y-%m-%d") as _add_time','sum(total_count) as total_count'])->group('_add_time')->order('_add_time asc'))->select();
|
||||
$date=[];
|
||||
$seriesdata=[];
|
||||
$zoom='';
|
||||
foreach ($list as $item){
|
||||
$date[]=$item['_add_time'];
|
||||
$seriesdata[]=$item['total_count'];
|
||||
}
|
||||
unset($item);
|
||||
if(count($date)>$limit){
|
||||
$zoom=$date[$limit-5];
|
||||
}
|
||||
//优惠劵使用记录
|
||||
$componList=self::getModelTime($where,self::where('status',1)->field(['FROM_UNIXTIME(add_time,"%Y-%m-%d") as _add_time','sum(coupon_price) as coupon_price'])
|
||||
->group('_add_time')->order('_add_time asc'))->select();
|
||||
count($componList) && $componList=$componList->toArray();
|
||||
$compon_date=[];
|
||||
$compon_data=[];
|
||||
$compon_zoom='';
|
||||
foreach($componList as $item){
|
||||
$compon_date[]=$item['_add_time'];
|
||||
$compon_data[]=$item['coupon_price'];
|
||||
}
|
||||
if(count($compon_date)>$limit){
|
||||
$compon_zoom=$compon_date[$limit-5];
|
||||
}
|
||||
return compact('date','seriesdata','zoom','compon_date','compon_data','compon_zoom');
|
||||
}
|
||||
|
||||
}
|
||||
674
app/admin/model/store/StoreProduct.php
Normal file
674
app/admin/model/store/StoreProduct.php
Normal file
@ -0,0 +1,674 @@
|
||||
<?php
|
||||
/**
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/11/11
|
||||
*/
|
||||
|
||||
namespace app\admin\model\store;
|
||||
|
||||
use app\admin\model\ump\StoreBargain;
|
||||
use app\admin\model\ump\StoreCombination;
|
||||
use app\admin\model\ump\StoreSeckill;
|
||||
use crmeb\services\PHPExcelService;
|
||||
use think\facade\Db;
|
||||
use crmeb\traits\ModelTrait;
|
||||
use crmeb\basic\BaseModel;
|
||||
use app\admin\model\store\StoreCategory as CategoryModel;
|
||||
use app\admin\model\order\StoreOrder;
|
||||
use app\admin\model\system\SystemConfig;
|
||||
|
||||
/**
|
||||
* 产品管理 model
|
||||
* Class StoreProduct
|
||||
* @package app\admin\model\store
|
||||
*/
|
||||
class StoreProduct extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* 数据表主键
|
||||
* @var string
|
||||
*/
|
||||
protected $pk = 'id';
|
||||
|
||||
/**
|
||||
* 模型名称
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'store_product';
|
||||
|
||||
use ModelTrait;
|
||||
|
||||
/**删除产品
|
||||
* @param $id
|
||||
*/
|
||||
public static function proDelete($id){
|
||||
// //删除产品
|
||||
// //删除属性
|
||||
// //删除秒杀
|
||||
// //删除拼团
|
||||
// //删除砍价
|
||||
// //删除拼团
|
||||
// $model=new self();
|
||||
// self::beginTrans();
|
||||
// $res0 = $model::del($id);
|
||||
// $res1 = StoreSeckillModel::where(['product_id'=>$id])->delete();
|
||||
// $res2 = StoreCombinationModel::where(['product_id'=>$id])->delete();
|
||||
// $res3 = StoreBargainModel::where(['product_id'=>$id])->delete();
|
||||
// //。。。。
|
||||
// $res = $res0 && $res1 && $res2 && $res3;
|
||||
// self::checkTrans($res);
|
||||
// return $res;
|
||||
}
|
||||
/**
|
||||
* 获取连表查询条件
|
||||
* @param $type
|
||||
* @return array
|
||||
*/
|
||||
public static function setData($type){
|
||||
switch ((int)$type){
|
||||
case 1:
|
||||
$data = ['p.is_show'=>1,'p.is_del'=>0];
|
||||
break;
|
||||
case 2:
|
||||
$data = ['p.is_show'=>0,'p.is_del'=>0];
|
||||
break;
|
||||
case 3:
|
||||
$data = ['p.is_del'=>0];
|
||||
break;
|
||||
case 4:
|
||||
$data = ['p.is_show'=>1,'p.is_del'=>0,'pav.stock|p.stock'=>0];
|
||||
break;
|
||||
case 5:
|
||||
$min = SystemConfig::getConfigValue('store_stock');
|
||||
$min = $min ? $min : 10;
|
||||
$data = ['p.is_show'=>1,'p.is_del'=>0,'pav.stock|p.stock'=>['<=',$min]];
|
||||
break;
|
||||
case 6:
|
||||
$data = ['p.is_del'=>1];
|
||||
break;
|
||||
};
|
||||
return isset($data) ? $data: [];
|
||||
}
|
||||
/**
|
||||
* 获取连表MOdel
|
||||
* @param $model
|
||||
* @return object
|
||||
*/
|
||||
public static function getModelObject($where=[]){
|
||||
$model=new self();
|
||||
$model=$model->alias('p')->join('StoreProductAttrValue pav','p.id=pav.product_id','LEFT');
|
||||
if(!empty($where)){
|
||||
$model=$model->group('p.id');
|
||||
if(isset($where['type']) && $where['type']!='' && ($data=self::setData($where['type']))){
|
||||
$model = $model->where($data);
|
||||
}
|
||||
if(isset($where['store_name']) && $where['store_name']!=''){
|
||||
$model = $model->where('p.store_name|p.keyword|p.id','LIKE',"%$where[store_name]%");
|
||||
}
|
||||
if(isset($where['cate_id']) && trim($where['cate_id'])!=''){
|
||||
$catid1 = $where['cate_id'].',';//匹配最前面的cateid
|
||||
$catid2 = ','.$where['cate_id'].',';//匹配中间的cateid
|
||||
$catid3 = ','.$where['cate_id'];//匹配后面的cateid
|
||||
$catid4 = $where['cate_id'];//匹配全等的cateid
|
||||
// $model = $model->whereOr('p.cate_id','LIKE',["%$catid%",$catidab]);
|
||||
$sql = " LIKE '$catid1%' OR `cate_id` LIKE '%$catid2%' OR `cate_id` LIKE '%$catid3' OR `cate_id`=$catid4";
|
||||
$model->where(self::getPidSql($where['cate_id']));
|
||||
}
|
||||
if(isset($where['order']) && $where['order']!=''){
|
||||
$model = $model->order(self::setOrder($where['order']));
|
||||
}
|
||||
}
|
||||
return $model;
|
||||
}
|
||||
|
||||
/**根据cateid查询产品 拼sql语句
|
||||
* @param $cateid
|
||||
* @return string
|
||||
*/
|
||||
protected static function getCateSql($cateid){
|
||||
$lcateid = $cateid.',%';//匹配最前面的cateid
|
||||
$ccatid = '%,'.$cateid.',%';//匹配中间的cateid
|
||||
$ratidid = '%,'.$cateid;//匹配后面的cateid
|
||||
return " `cate_id` LIKE '$lcateid' OR `cate_id` LIKE '$ccatid' OR `cate_id` LIKE '$ratidid' OR `cate_id`=$cateid";
|
||||
}
|
||||
|
||||
/** 如果有子分类查询子分类获取拼接查询sql
|
||||
* @param $cateid
|
||||
* @return string
|
||||
*/
|
||||
protected static function getPidSql($cateid){
|
||||
|
||||
$sql = self::getCateSql($cateid);
|
||||
$ids = CategoryModel::where('pid', $cateid)->column('id','id');
|
||||
//查询如果有子分类获取子分类查询sql语句
|
||||
if($ids) foreach ($ids as $v) $sql .= " OR ".self::getcatesql($v);
|
||||
return $sql;
|
||||
}
|
||||
/*
|
||||
* 获取产品列表
|
||||
* @param $where array
|
||||
* @return array
|
||||
*
|
||||
*/
|
||||
public static function ProductList($where){
|
||||
$model=self::getModelObject($where)->field(['p.*','sum(pav.stock) as vstock']);
|
||||
if($where['excel']==0) $model=$model->page((int)$where['page'],(int)$where['limit']);
|
||||
$data=($data=$model->select()) && count($data) ? $data->toArray():[];
|
||||
foreach ($data as &$item){
|
||||
$cateName = CategoryModel::where('id', 'IN', $item['cate_id'])->column('cate_name', 'id');
|
||||
$item['cate_name']=is_array($cateName) ? implode(',',$cateName) : '';
|
||||
$item['collect'] = StoreProductRelation::where('product_id',$item['id'])->where('type','collect')->count();//收藏
|
||||
$item['like'] = StoreProductRelation::where('product_id',$item['id'])->where('type','like')->count();//点赞
|
||||
$item['stock'] = self::getStock($item['id'])>0?self::getStock($item['id']):$item['stock'];//库存
|
||||
$item['stock_attr'] = self::getStock($item['id'])>0 ? true : false;//库存
|
||||
$item['sales_attr'] = self::getSales($item['id']);//属性销量
|
||||
$item['visitor'] = StoreVisit::where('product_id',$item['id'])->where('product_type','product')->count();
|
||||
}
|
||||
unset($item);
|
||||
if($where['excel']==1){
|
||||
$export = [];
|
||||
foreach ($data as $index=>$item){
|
||||
$export[] = [
|
||||
$item['store_name'],
|
||||
$item['store_info'],
|
||||
$item['cate_name'],
|
||||
'¥'.$item['price'],
|
||||
$item['stock'],
|
||||
$item['sales'],
|
||||
$item['like'],
|
||||
$item['collect']
|
||||
];
|
||||
}
|
||||
PHPExcelService::setExcelHeader(['产品名称','产品简介','产品分类','价格','库存','销量','点赞人数','收藏人数'])
|
||||
->setExcelTile('产品导出','产品信息'.time(),' 生成时间:'.date('Y-m-d H:i:s',time()))
|
||||
->setExcelContent($export)
|
||||
->ExcelSave();
|
||||
}
|
||||
$count=self::getModelObject($where)->count();
|
||||
return compact('count','data');
|
||||
}
|
||||
|
||||
public static function getChatrdata($type,$data){
|
||||
$legdata=['销量','数量','点赞','收藏'];
|
||||
$model=self::setWhereType(self::order('id desc'),$type);
|
||||
$list=self::getModelTime(compact('data'),$model)
|
||||
->field('FROM_UNIXTIME(add_time,"%Y-%c-%d") as un_time,count(id) as count,sum(sales) as sales')
|
||||
->group('un_time')
|
||||
->distinct(true)
|
||||
->select()
|
||||
->each(function($item) use($data){
|
||||
$item['collect']=self::getModelTime(compact('data'),new StoreProductRelation)->where('type','collect')->count();
|
||||
$item['like']=self::getModelTime(compact('data'),new StoreProductRelation)->where('type','like')->count();
|
||||
})->toArray();
|
||||
$chatrList=[];
|
||||
$datetime=[];
|
||||
$data_item=[];
|
||||
$itemList=[0=>[],1=>[],2=>[],3=>[]];
|
||||
foreach ($list as $item){
|
||||
$itemList[0][]=$item['sales'];
|
||||
$itemList[1][]=$item['count'];
|
||||
$itemList[2][]=$item['like'];
|
||||
$itemList[3][]=$item['collect'];
|
||||
array_push($datetime,$item['un_time']);
|
||||
}
|
||||
foreach ($legdata as $key=>$leg){
|
||||
$data_item['name']=$leg;
|
||||
$data_item['type']='line';
|
||||
$data_item['data']=$itemList[$key];
|
||||
$chatrList[]=$data_item;
|
||||
unset($data_item);
|
||||
}
|
||||
unset($leg);
|
||||
$badge=self::getbadge(compact('data'),$type);
|
||||
$count=self::setWhereType(self::getModelTime(compact('data'),new self()),$type)->count();
|
||||
return compact('datetime','chatrList','legdata','badge','count');
|
||||
|
||||
}
|
||||
//获取 badge 内容
|
||||
public static function getbadge($where,$type){
|
||||
$replenishment_num = SystemConfig::getConfigValue('replenishment_num');
|
||||
$replenishment_num = $replenishment_num > 0 ? $replenishment_num : 20;
|
||||
$sum = [];
|
||||
$lack = 0;
|
||||
|
||||
//获取普通产品缺货
|
||||
$stock1 = self::getModelTime($where,new self())->where('stock','<',$replenishment_num)->column('stock','id');
|
||||
$sum_stock = self::where('stock','<',$replenishment_num)->column('stock','id');
|
||||
$stk = [];
|
||||
foreach ($stock1 as $item){
|
||||
$stk[] = $replenishment_num-$item;
|
||||
}
|
||||
$lack = bcadd($lack,array_sum($stk),0);
|
||||
foreach ($sum_stock as $val){
|
||||
$sum[] = $replenishment_num-$val;
|
||||
}
|
||||
unset($stk,$sum_stock,$stock1);
|
||||
|
||||
//获取砍价缺货产品
|
||||
$stock1 = self::getModelTime($where,new StoreBargain())->where('stock','<',$replenishment_num)->column('stock','id');
|
||||
$sum_stock = StoreBargain::where('stock','<',$replenishment_num)->column('stock','id');
|
||||
$stk = [];
|
||||
foreach ($stock1 as $item){
|
||||
$stk[] = $replenishment_num-$item;
|
||||
}
|
||||
$lack = bcadd($lack,array_sum($stk),0);
|
||||
foreach ($sum_stock as $val){
|
||||
$sum[] = $replenishment_num-$val;
|
||||
}
|
||||
unset($stk,$sum_stock,$stock1);
|
||||
|
||||
//获取拼团缺货产品
|
||||
$stock1 = self::getModelTime($where,new StoreCombination())->where('stock','<',$replenishment_num)->column('stock','id');
|
||||
$sum_stock = StoreCombination::where('stock','<',$replenishment_num)->column('stock','id');
|
||||
$stk = [];
|
||||
foreach ($stock1 as $item){
|
||||
$stk[] = $replenishment_num - $item;
|
||||
}
|
||||
$lack = bcadd($lack,array_sum($stk),0);
|
||||
foreach ($sum_stock as $val){
|
||||
$sum[] = $replenishment_num - $val;
|
||||
}
|
||||
unset($stk,$sum_stock,$stock1);
|
||||
|
||||
return [
|
||||
[
|
||||
'name'=>'商品种类',
|
||||
'field'=>'件',
|
||||
'count'=>self::setWhereType(new self(),$type)->where('add_time','<',mktime(0,0,0,date('m'),date('d'),date('Y')))->count(),
|
||||
'content'=>'商品数量总数',
|
||||
'background_color'=>'layui-bg-blue',
|
||||
'sum'=>self::count(),
|
||||
'class'=>'fa fa fa-ioxhost',
|
||||
],
|
||||
[
|
||||
'name'=>'新增商品',
|
||||
'field'=>'件',
|
||||
'count'=>self::setWhereType(self::getModelTime($where,new self),$type)->where('is_new',1)->sum('stock'),
|
||||
'content'=>'新增商品总数',
|
||||
'background_color'=>'layui-bg-cyan',
|
||||
'sum'=>self::where('is_new',1)->sum('stock'),
|
||||
'class'=>'fa fa-line-chart',
|
||||
],
|
||||
[
|
||||
'name'=>'活动商品',
|
||||
'field'=>'件',
|
||||
'count'=>self::getActivityProductSum($where),
|
||||
'content'=>'活动商品总数',
|
||||
'background_color'=>'layui-bg-green',
|
||||
'sum'=>self::getActivityProductSum(),
|
||||
'class'=>'fa fa-bar-chart',
|
||||
],
|
||||
[
|
||||
'name'=>'缺货商品',
|
||||
'field'=>'件',
|
||||
'count'=>$lack,
|
||||
'content'=>'总商品数量',
|
||||
'background_color'=>'layui-bg-orange',
|
||||
'sum'=>array_sum($sum),
|
||||
'class'=>'fa fa-cube',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取活动产品总和
|
||||
* @param array $where 查询条件
|
||||
* */
|
||||
public static function getActivityProductSum($where=false)
|
||||
{
|
||||
if($where){
|
||||
$bargain=self::getModelTime($where,new StoreBargain())->sum('stock');
|
||||
$pink=self::getModelTime($where,new StoreCombination())->sum('stock');
|
||||
$seckill=self::getModelTime($where,new StoreSeckill())->sum('stock');
|
||||
}else{
|
||||
$bargain=StoreBargain::sum('stock');
|
||||
$pink=StoreCombination::sum('stock');
|
||||
$seckill=StoreSeckill::sum('stock');
|
||||
}
|
||||
return bcadd(bcadd($bargain,$pink,0),$seckill,0);
|
||||
}
|
||||
|
||||
public static function setWhereType($model,$type){
|
||||
switch ($type){
|
||||
case 1:
|
||||
$data = ['is_show'=>1,'is_del'=>0];
|
||||
break;
|
||||
case 2:
|
||||
$data = ['is_show'=>0,'is_del'=>0];
|
||||
break;
|
||||
case 3:
|
||||
$data = ['is_del'=>0];
|
||||
break;
|
||||
case 4:
|
||||
$data = ['is_show'=>1,'is_del'=>0,'stock'=>0];
|
||||
break;
|
||||
case 5:
|
||||
$data = ['is_show'=>1,'is_del'=>0,'stock'=>['elt',1]];
|
||||
break;
|
||||
case 6:
|
||||
$data = ['is_del'=>1];
|
||||
break;
|
||||
}
|
||||
if(isset($data)) $model = $model->where($data);
|
||||
return $model;
|
||||
}
|
||||
/*
|
||||
* layui-bg-red 红 layui-bg-orange 黄 layui-bg-green 绿 layui-bg-blue 蓝 layui-bg-cyan 黑
|
||||
* 销量排行 top 10
|
||||
*/
|
||||
public static function getMaxList($where){
|
||||
$classs=['layui-bg-red','layui-bg-orange','layui-bg-green','layui-bg-blue','layui-bg-cyan'];
|
||||
$model=StoreOrder::alias('a')->join('StoreOrderCartInfo c','a.id=c.oid')->join('__store_product__ b','b.id=c.product_id');
|
||||
$list=self::getModelTime($where,$model,'a.add_time')->group('c.product_id')->order('p_count desc')->limit(10)
|
||||
->field(['count(c.product_id) as p_count','b.store_name','sum(b.price) as sum_price'])->select();
|
||||
if(count($list)) $list=$list->toArray();
|
||||
$maxList=[];
|
||||
$sum_count=0;
|
||||
$sum_price=0;
|
||||
foreach ($list as $item){
|
||||
$sum_count+=$item['p_count'];
|
||||
$sum_price=bcadd($sum_price,$item['sum_price'],2);
|
||||
}
|
||||
unset($item);
|
||||
foreach ($list as $key=>&$item){
|
||||
$item['w']=bcdiv($item['p_count'],$sum_count,2)*100;
|
||||
$item['class']=isset($classs[$key]) ?$classs[$key]:( isset($classs[$key-count($classs)]) ? $classs[$key-count($classs)]:'');
|
||||
$item['store_name']=self::getSubstrUTf8($item['store_name']);
|
||||
}
|
||||
$maxList['sum_count']=$sum_count;
|
||||
$maxList['sum_price']=$sum_price;
|
||||
$maxList['list']=$list;
|
||||
return $maxList;
|
||||
}
|
||||
//获取利润
|
||||
public static function ProfityTop10($where){
|
||||
$classs=['layui-bg-red','layui-bg-orange','layui-bg-green','layui-bg-blue','layui-bg-cyan'];
|
||||
$model=StoreOrder::alias('a')
|
||||
->join('StoreOrderCartInfo c','a.id=c.oid')
|
||||
->join('__store_product__ b','b.id=c.product_id')
|
||||
->where('b.is_show',1)
|
||||
->where('b.is_del',0);
|
||||
$list=self::getModelTime($where,$model,'a.add_time')->group('c.product_id')->order('profity desc')->limit(10)
|
||||
->field(['count(c.product_id) as p_count','b.store_name','sum(b.price) as sum_price','(b.price-b.cost) as profity'])
|
||||
->select();
|
||||
if(count($list)) $list=$list->toArray();
|
||||
$maxList=[];
|
||||
$sum_count=0;
|
||||
$sum_price=0;
|
||||
foreach ($list as $item){
|
||||
$sum_count+=$item['p_count'];
|
||||
$sum_price=bcadd($sum_price,$item['sum_price'],2);
|
||||
}
|
||||
foreach ($list as $key=>&$item){
|
||||
$item['w']=bcdiv($item['sum_price'],$sum_price,2)*100;
|
||||
$item['class']=isset($classs[$key]) ?$classs[$key]:( isset($classs[$key-count($classs)]) ? $classs[$key-count($classs)]:'');
|
||||
$item['store_name']=self::getSubstrUTf8($item['store_name'],30);
|
||||
}
|
||||
$maxList['sum_count']=$sum_count;
|
||||
$maxList['sum_price']=$sum_price;
|
||||
$maxList['list']=$list;
|
||||
return $maxList;
|
||||
}
|
||||
//获取缺货
|
||||
public static function getLackList($where){
|
||||
$replenishment_num = SystemConfig::getConfigValue('replenishment_num');
|
||||
$replenishment_num = $replenishment_num > 0 ? $replenishment_num : 20;
|
||||
$list=self::where('stock','<',$replenishment_num)->field(['id','store_name','stock','price'])->page((int)$where['page'],(int)$where['limit'])->order('stock asc')->select();
|
||||
if(count($list)) $list=$list->toArray();
|
||||
$count=self::where('stock','<',$replenishment_num)->count();
|
||||
return ['count'=>$count,'data'=>$list];
|
||||
}
|
||||
//获取差评
|
||||
public static function getnegativelist($where){
|
||||
$list=self::alias('s')->join('StoreProductReply r','s.id=r.product_id')
|
||||
->field('s.id,s.store_name,s.price,count(r.product_id) as count')
|
||||
->page((int)$where['page'],(int)$where['limit'])
|
||||
->where('r.product_score',1)
|
||||
->order('count desc')
|
||||
->group('r.product_id')
|
||||
->select();
|
||||
if(count($list)) $list=$list->toArray();
|
||||
$count=self::alias('s')->join('StoreProductReply r','s.id=r.product_id')->group('r.product_id')->where('r.product_score',1)->count();
|
||||
return ['count'=>$count,'data'=>$list];
|
||||
}
|
||||
public static function TuiProductList(){
|
||||
$perd=StoreOrder::alias('s')->join('StoreOrderCartInfo c','s.id=c.oid')
|
||||
->field('count(c.product_id) as count,c.product_id as id')
|
||||
->group('c.product_id')
|
||||
->where('s.status',-1)
|
||||
->order('count desc')
|
||||
->limit(10)
|
||||
->select();
|
||||
if(count($perd)) $perd=$perd->toArray();
|
||||
foreach ($perd as &$item){
|
||||
$item['store_name']=self::where(['id'=>$item['id']])->value('store_name');
|
||||
$item['price']=self::where(['id'=>$item['id']])->value('price');
|
||||
}
|
||||
return $perd;
|
||||
}
|
||||
//编辑库存
|
||||
public static function changeStock($stock,$productId)
|
||||
{
|
||||
return self::edit(compact('stock'),$productId);
|
||||
}
|
||||
//获取库存数量
|
||||
public static function getStock($productId)
|
||||
{
|
||||
return StoreProductAttrValue::where(['product_id'=>$productId])->sum('stock');
|
||||
}
|
||||
//获取总销量
|
||||
public static function getSales($productId)
|
||||
{
|
||||
return StoreProductAttrValue::where(['product_id'=>$productId])->sum('sales');
|
||||
}
|
||||
|
||||
public static function getTierList($model = null)
|
||||
{
|
||||
if($model === null) $model = new self();
|
||||
return $model->field('id,store_name')->where('is_del',0)->select()->toArray();
|
||||
}
|
||||
/**
|
||||
* 设置查询条件
|
||||
* @param array $where
|
||||
* @return array
|
||||
*/
|
||||
public static function setWhere($where){
|
||||
$time['data']='';
|
||||
if(isset($where['start_time']) && $where['start_time']!='' && isset($where['end_time']) && $where['end_time']!=''){
|
||||
$time['data']=$where['start_time'].' - '.$where['end_time'];
|
||||
}else{
|
||||
$time['data']=isset($where['data'])? $where['data']:'';
|
||||
}
|
||||
$model=self::getModelTime($time, Db::name('store_cart')->alias('a')->join('__store_product__ b','a.product_id=b.id'),'a.add_time');
|
||||
if(isset($where['title']) && $where['title']!=''){
|
||||
$model=$model->where('b.store_name|b.id','like',"%$where[title]%");
|
||||
}
|
||||
return $model;
|
||||
}
|
||||
/**
|
||||
* 获取真实销量排行
|
||||
* @param array $where
|
||||
* @return array
|
||||
*/
|
||||
public static function getSaleslists($where){
|
||||
$data=self::setWhere($where)->where('a.is_pay',1)
|
||||
->group('a.product_id')
|
||||
->field(['sum(a.cart_num) as num_product','b.store_name','b.image','b.price','b.id'])
|
||||
->order('num_product desc')
|
||||
->page((int)$where['page'],(int)$where['limit'])
|
||||
->select();
|
||||
$count=self::setWhere($where)->where('a.is_pay',1)->group('a.product_id')->count();
|
||||
foreach ($data as &$item){
|
||||
$item['sum_price']=bcmul($item['num_product'],$item['price'],2);
|
||||
}
|
||||
return compact('data','count');
|
||||
}
|
||||
public static function SaveProductExport($where){
|
||||
$list=self::setWhere($where)
|
||||
->where('a.is_pay',1)
|
||||
->field(['sum(a.cart_num) as num_product','b.store_name','b.image','b.price','b.id'])
|
||||
->order('num_product desc')
|
||||
->group('a.product_id')
|
||||
->select();
|
||||
$export=[];
|
||||
foreach ($list as $item){
|
||||
$export[]=[
|
||||
$item['id'],
|
||||
$item['store_name'],
|
||||
$item['price'],
|
||||
bcmul($item['num_product'],$item['price'],2),
|
||||
$item['num_product'],
|
||||
];
|
||||
}
|
||||
PHPExcelService::setExcelHeader(['商品编号','商品名称','商品售价','销售额','销量'])
|
||||
->setExcelTile('产品销量排行','产品销量排行',' 生成时间:'.date('Y-m-d H:i:s',time()))
|
||||
->setExcelContent($export)
|
||||
->ExcelSave();
|
||||
}
|
||||
/*
|
||||
* 单个商品详情的头部查询
|
||||
* $id 商品id
|
||||
* $where 条件
|
||||
*/
|
||||
public static function getProductBadgeList($id,$where){
|
||||
$data['data']=$where;
|
||||
$list=self::setWhere($data)
|
||||
->field(['sum(a.cart_num) as num_product','b.id','b.price'])
|
||||
->where('a.is_pay',1)
|
||||
->group('a.product_id')
|
||||
->order('num_product desc')
|
||||
->select();
|
||||
//排名
|
||||
$ranking=0;
|
||||
//销量
|
||||
$xiaoliang=0;
|
||||
//销售额 数组
|
||||
$list_price=[];
|
||||
foreach ($list as $key=>$item){
|
||||
if($item['id']==$id){
|
||||
$ranking=$key+1;
|
||||
$xiaoliang=$item['num_product'];
|
||||
}
|
||||
$value['sum_price']=$item['price']*$item['num_product'];
|
||||
$value['id']=$item['id'];
|
||||
$list_price[]=$value;
|
||||
}
|
||||
//排序
|
||||
$list_price=self::my_sort($list_price,'sum_price',SORT_DESC);
|
||||
//销售额排名
|
||||
$rank_price=0;
|
||||
//当前销售额
|
||||
$num_price=0;
|
||||
if($list_price!==false && is_array($list_price)){
|
||||
foreach ($list_price as $key=>$item){
|
||||
if($item['id']==$id){
|
||||
$num_price=$item['sum_price'];
|
||||
$rank_price=$key+1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
return [
|
||||
[
|
||||
'name'=>'销售额排名',
|
||||
'field'=>'名',
|
||||
'count'=>$rank_price,
|
||||
'background_color'=>'layui-bg-blue',
|
||||
],
|
||||
[
|
||||
'name'=>'销量排名',
|
||||
'field'=>'名',
|
||||
'count'=>$ranking,
|
||||
'background_color'=>'layui-bg-blue',
|
||||
],
|
||||
[
|
||||
'name'=>'商品销量',
|
||||
'field'=>'名',
|
||||
'count'=>$xiaoliang,
|
||||
'background_color'=>'layui-bg-blue',
|
||||
],
|
||||
[
|
||||
'name'=>'点赞次数',
|
||||
'field'=>'个',
|
||||
'count'=>Db::name('store_product_relation')->where('product_id',$id)->where('type','like')->count(),
|
||||
'background_color'=>'layui-bg-blue',
|
||||
],
|
||||
[
|
||||
'name'=>'销售总额',
|
||||
'field'=>'元',
|
||||
'count'=>$num_price,
|
||||
'background_color'=>'layui-bg-blue',
|
||||
'col'=>12,
|
||||
],
|
||||
];
|
||||
}
|
||||
/*
|
||||
* 处理二维数组排序
|
||||
* $arrays 需要处理的数组
|
||||
* $sort_key 需要处理的key名
|
||||
* $sort_order 排序方式
|
||||
* $sort_type 类型 可不填写
|
||||
*/
|
||||
public static function my_sort($arrays,$sort_key,$sort_order=SORT_ASC,$sort_type=SORT_NUMERIC ){
|
||||
if(is_array($arrays)){
|
||||
foreach ($arrays as $array){
|
||||
if(is_array($array)){
|
||||
$key_arrays[] = $array[$sort_key];
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(isset($key_arrays)){
|
||||
array_multisort($key_arrays,$sort_order,$sort_type,$arrays);
|
||||
return $arrays;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/*
|
||||
* 查询单个商品的销量曲线图
|
||||
*
|
||||
*/
|
||||
public static function getProductCurve($where){
|
||||
$list=self::setWhere($where)
|
||||
->where('a.product_id',$where['id'])
|
||||
->where('a.is_pay',1)
|
||||
->field(['FROM_UNIXTIME(a.add_time,"%Y-%m-%d") as _add_time','sum(a.cart_num) as num'])
|
||||
->group('_add_time')
|
||||
->order('_add_time asc')
|
||||
->select();
|
||||
$seriesdata=[];
|
||||
$date=[];
|
||||
$zoom='';
|
||||
foreach ($list as $item){
|
||||
$date[]=$item['_add_time'];
|
||||
$seriesdata[]=$item['num'];
|
||||
}
|
||||
if(count($date)>$where['limit']) $zoom=$date[$where['limit']-5];
|
||||
return compact('seriesdata','date','zoom');
|
||||
}
|
||||
/*
|
||||
* 查询单个商品的销售列表
|
||||
*
|
||||
*/
|
||||
public static function getSalelList($where){
|
||||
return self::setWhere($where)
|
||||
->where('a.product_id', $where['id'])
|
||||
->where('a.is_pay', 1)
|
||||
->join('user c','c.uid=a.uid')
|
||||
->field(['FROM_UNIXTIME(a.add_time,"%Y-%m-%d") as _add_time','c.nickname','b.price','a.id','a.cart_num as num'])
|
||||
->page((int)$where['page'],(int)$where['limit'])
|
||||
->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 获取某个字段值
|
||||
* @param $id
|
||||
* @param string $field
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getProductField($id,$field = 'store_name'){
|
||||
return self::where('id',$id)->value($field);
|
||||
}
|
||||
}
|
||||
139
app/admin/model/store/StoreProductAttr.php
Normal file
139
app/admin/model/store/StoreProductAttr.php
Normal file
@ -0,0 +1,139 @@
|
||||
<?php
|
||||
/**
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/12/08
|
||||
*/
|
||||
|
||||
namespace app\admin\model\store;
|
||||
|
||||
use crmeb\basic\BaseModel;
|
||||
use crmeb\traits\ModelTrait;
|
||||
|
||||
class StoreProductAttr extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* 模型名称
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'store_product_attr';
|
||||
|
||||
use ModelTrait;
|
||||
|
||||
protected function setAttrValuesAttr($value)
|
||||
{
|
||||
return is_array($value) ? implode(',',$value) : $value;
|
||||
}
|
||||
|
||||
protected function getAttrValuesAttr($value)
|
||||
{
|
||||
return explode(',',$value);
|
||||
}
|
||||
|
||||
|
||||
public static function createProductAttr($attrList,$valueList,$productId)
|
||||
{
|
||||
$result = ['attr'=>$attrList,'value'=>$valueList];
|
||||
$attrValueList = [];
|
||||
$attrNameList = [];
|
||||
foreach ($attrList as $index=>$attr){
|
||||
if(!isset($attr['value'])) return self::setErrorInfo('请输入规则名称!');
|
||||
$attr['value'] = trim($attr['value']);
|
||||
if(!isset($attr['value'])) return self::setErrorInfo('请输入规则名称!!');
|
||||
if(!isset($attr['detail']) || !count($attr['detail'])) return self::setErrorInfo('请输入属性名称!');
|
||||
foreach ($attr['detail'] as $k=>$attrValue){
|
||||
$attrValue = trim($attrValue);
|
||||
if(empty($attrValue)) return self::setErrorInfo('请输入正确的属性');
|
||||
$attr['detail'][$k] = $attrValue;
|
||||
$attrValueList[] = $attrValue;
|
||||
$attr['detail'][$k] = $attrValue;
|
||||
}
|
||||
$attrNameList[] = $attr['value'];
|
||||
$attrList[$index] = $attr;
|
||||
}
|
||||
$attrCount = count($attrList);
|
||||
foreach ($valueList as $index=>$value){
|
||||
if(!isset($value['detail']) || count($value['detail']) != $attrCount) return self::setErrorInfo('请填写正确的商品信息');
|
||||
if(!isset($value['price']) || !is_numeric($value['price']) || floatval($value['price']) != $value['price'])
|
||||
return self::setErrorInfo('请填写正确的商品价格');
|
||||
if(!isset($value['sales']) || !is_numeric($value['sales']) || intval($value['sales']) != $value['sales'])
|
||||
return self::setErrorInfo('请填写正确的商品库存');
|
||||
if(!isset($value['cost']) || !is_numeric($value['cost']) || floatval($value['cost']) != $value['cost'])
|
||||
return self::setErrorInfo('请填写正确的商品成本价格');
|
||||
if(!isset($value['pic']) || empty($value['pic']))
|
||||
return self::setErrorInfo('请上传商品图片');
|
||||
foreach ($value['detail'] as $attrName=>$attrValue){
|
||||
$attrName = trim($attrName);
|
||||
$attrValue = trim($attrValue);
|
||||
if(!in_array($attrName,$attrNameList,true)) return self::setErrorInfo($attrName.'规则不存在');
|
||||
if(!in_array($attrValue,$attrValueList,true)) return self::setErrorInfo($attrName.'属性不存在');
|
||||
if(empty($attrName)) return self::setErrorInfo('请输入正确的属性');
|
||||
$value['detail'][$attrName] = $attrValue;
|
||||
}
|
||||
$valueList[$index] = $value;
|
||||
}
|
||||
$attrGroup = [];
|
||||
$valueGroup = [];
|
||||
foreach ($attrList as $k=>$value){
|
||||
$attrGroup[] = [
|
||||
'product_id'=>$productId,
|
||||
'attr_name'=>$value['value'],
|
||||
'attr_values'=>$value['detail']
|
||||
];
|
||||
}
|
||||
foreach ($valueList as $k=>$value){
|
||||
sort($value['detail'],SORT_STRING);
|
||||
$suk = implode(',',$value['detail']);
|
||||
$valueGroup[$suk] = [
|
||||
'product_id'=>$productId,
|
||||
'suk'=>$suk,
|
||||
'price'=>$value['price'],
|
||||
'cost'=>$value['cost'],
|
||||
'stock'=>$value['sales'],
|
||||
'unique'=> StoreProductAttrValue::uniqueId($productId.$suk.uniqid(true)),
|
||||
'image'=>$value['pic']
|
||||
];
|
||||
}
|
||||
if(!count($attrGroup) || !count($valueGroup)) return self::setErrorInfo('请设置至少一个属性!');
|
||||
$attrModel = new self;
|
||||
$attrValueModel = new StoreProductAttrValue;
|
||||
self::beginTrans();
|
||||
if(!self::clearProductAttr($productId)) return false;
|
||||
$res = false !== $attrModel->saveAll($attrGroup)
|
||||
&& false !== $attrValueModel->saveAll($valueGroup)
|
||||
&& false !== StoreProductAttrResult::setResult($result,$productId);
|
||||
self::checkTrans($res);
|
||||
if($res)
|
||||
return true;
|
||||
else
|
||||
return self::setErrorInfo('编辑商品属性失败!');
|
||||
}
|
||||
|
||||
public static function clearProductAttr($productId)
|
||||
{
|
||||
if (empty($productId) && $productId != 0) return self::setErrorInfo('商品不存在!');
|
||||
$res = false !== self::where('product_id',$productId)->delete()
|
||||
&& false !== StoreProductAttrValue::clearProductAttrValue($productId);
|
||||
if(!$res)
|
||||
return self::setErrorInfo('编辑属性失败,清除旧属性失败!');
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取产品属性
|
||||
* @param $productId
|
||||
* @return array|bool|null|\think\Model
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function getProductAttr($productId)
|
||||
{
|
||||
if (empty($productId) && $productId != 0) return self::setErrorInfo('商品不存在!');
|
||||
$count = self::where('product_id',$productId)->count();
|
||||
if(!$count) return self::setErrorInfo('商品不存在!');
|
||||
return self::where('product_id',$productId)->select()->toArray();
|
||||
}
|
||||
|
||||
}
|
||||
56
app/admin/model/store/StoreProductAttrResult.php
Normal file
56
app/admin/model/store/StoreProductAttrResult.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/12/09
|
||||
*/
|
||||
|
||||
namespace app\admin\model\store;
|
||||
|
||||
use crmeb\basic\BaseModel;
|
||||
use crmeb\traits\ModelTrait;
|
||||
|
||||
class StoreProductAttrResult extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* 模型名称
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'store_product_attr_result';
|
||||
|
||||
use ModelTrait;
|
||||
|
||||
protected $insert = ['change_time'];
|
||||
|
||||
protected static function setChangeTimeAttr($value)
|
||||
{
|
||||
return time();
|
||||
}
|
||||
|
||||
protected static function setResultAttr($value)
|
||||
{
|
||||
return is_array($value) ? json_encode($value) : $value;
|
||||
}
|
||||
|
||||
public static function setResult($result,$product_id)
|
||||
{
|
||||
$result = self::setResultAttr($result);
|
||||
$change_time = self::setChangeTimeAttr(0);
|
||||
$count = self::where('product_id',$product_id)->count();
|
||||
$res = true;
|
||||
if($count) $res = self::where('product_id',$product_id)->delete();
|
||||
if($res) return self::insert(compact('product_id','result','change_time'),true);
|
||||
return $res;
|
||||
}
|
||||
|
||||
public static function getResult($productId)
|
||||
{
|
||||
return json_decode(self::where('product_id',$productId)->value('result'),true) ?: [];
|
||||
}
|
||||
|
||||
public static function clearResult($productId)
|
||||
{
|
||||
return self::where('product_id', $productId)->delete();
|
||||
}
|
||||
|
||||
}
|
||||
120
app/admin/model/store/StoreProductAttrValue.php
Normal file
120
app/admin/model/store/StoreProductAttrValue.php
Normal file
@ -0,0 +1,120 @@
|
||||
<?php
|
||||
/**
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/12/08
|
||||
*/
|
||||
|
||||
namespace app\admin\model\store;
|
||||
|
||||
use crmeb\basic\BaseModel;
|
||||
use crmeb\services\SystemConfigService;
|
||||
use crmeb\services\workerman\ChannelService;
|
||||
use crmeb\traits\ModelTrait;
|
||||
|
||||
class StoreProductAttrValue extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* 模型名称
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'store_product_attr_value';
|
||||
|
||||
use ModelTrait;
|
||||
|
||||
protected $insert = ['unique'];
|
||||
|
||||
protected function setSukAttr($value)
|
||||
{
|
||||
return is_array($value) ? implode(',',$value) : $value;
|
||||
}
|
||||
|
||||
protected function setUniqueAttr($value,$data)
|
||||
{
|
||||
|
||||
if(is_array($data['suk'])) $data['suk'] = $this->setSukAttr($data['suk']);
|
||||
return self::uniqueId($data['product_id'].$data['suk'].uniqid(true));
|
||||
}
|
||||
|
||||
/*
|
||||
* 减少销量增加库存
|
||||
* */
|
||||
public static function incProductAttrStock($productId,$unique,$num)
|
||||
{
|
||||
$productAttr=self::where('unique',$unique)->where('product_id',$productId)->field('stock,sales')->find();
|
||||
if(!$productAttr) return true;
|
||||
if($productAttr->sales > 0) $productAttr->sales=bcsub($productAttr->sales,$num,0);
|
||||
if($productAttr->sales < 0) $productAttr->sales=0;
|
||||
$productAttr->stock = bcadd($productAttr->stock, $num,0);
|
||||
return $productAttr->save();
|
||||
}
|
||||
|
||||
public static function decProductAttrStock($productId,$unique,$num)
|
||||
{
|
||||
$res = self::where('product_id',$productId)->where('unique',$unique)
|
||||
->dec('stock',$num)->inc('sales',$num)->update();
|
||||
if($res){
|
||||
$stock = self::where('product_id',$productId)->where('unique',$unique)->value('stock');
|
||||
$replenishment_num = SystemConfigService::get('store_stock') ?? 0;//库存预警界限
|
||||
if($replenishment_num >= $stock){
|
||||
ChannelService::instance()->send('STORE_STOCK', ['id'=>$productId]);
|
||||
}
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取属性参数
|
||||
* @param $productId
|
||||
* @return array|string
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function getStoreProductAttrResult($productId)
|
||||
{
|
||||
$productAttr = StoreProductAttr::getProductAttr($productId);
|
||||
if(!$productAttr) return [];
|
||||
$attr = [];
|
||||
foreach ($productAttr as $key=>$value){
|
||||
$attr[$key]['value'] = $value['attr_name'];
|
||||
$attr[$key]['detailValue'] = '';
|
||||
$attr[$key]['attrHidden'] = true;
|
||||
$attr[$key]['detail'] = $value['attr_values'];
|
||||
}
|
||||
$value = attrFormat($attr)[1];
|
||||
$valueNew = [];
|
||||
$count = 0;
|
||||
foreach ($value as $key=>$item){
|
||||
$detail = $item['detail'];
|
||||
sort($item['detail'],SORT_STRING);
|
||||
$suk = implode(',', $item['detail']);
|
||||
$sukValue = self::where('product_id', $productId)->where('suk', $suk)->column('cost,price,stock as sales,image as pic','suk');
|
||||
if(!count($sukValue)){
|
||||
unset($value[$key]);
|
||||
}else{
|
||||
$valueNew[$count]['detail'] = $detail;
|
||||
$valueNew[$count]['cost'] = $sukValue[$suk]['cost'];
|
||||
$valueNew[$count]['price'] = $sukValue[$suk]['price'];
|
||||
$valueNew[$count]['sales'] = $sukValue[$suk]['sales'];
|
||||
$valueNew[$count]['pic'] = $sukValue[$suk]['pic'];
|
||||
$valueNew[$count]['check'] = false;
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
return ['attr'=>$attr, 'value'=>$valueNew];
|
||||
}
|
||||
|
||||
|
||||
public static function uniqueId($key)
|
||||
{
|
||||
return substr(md5($key),12,8);
|
||||
}
|
||||
|
||||
public static function clearProductAttrValue($productId)
|
||||
{
|
||||
return self::where('product_id',$productId)->delete();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
43
app/admin/model/store/StoreProductRelation.php
Normal file
43
app/admin/model/store/StoreProductRelation.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/**
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/11/11
|
||||
*/
|
||||
|
||||
namespace app\admin\model\store;
|
||||
|
||||
use crmeb\traits\ModelTrait;
|
||||
use crmeb\basic\BaseModel;
|
||||
|
||||
/**
|
||||
* 点赞and收藏 model
|
||||
* Class StoreProductRelation
|
||||
* @package app\admin\model\store
|
||||
*/
|
||||
class StoreProductRelation extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* 模型名称
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'store_product_relation';
|
||||
|
||||
use ModelTrait;
|
||||
|
||||
public static function getCollect($pid){
|
||||
$model = new self();
|
||||
$model = $model->where('r.product_id',$pid)->where('r.type','collect');
|
||||
$model = $model->alias('r')->join('__WECHAT_USER__ u','u.uid=r.uid');
|
||||
$model = $model->field('r.*,u.nickname');
|
||||
return self::page($model);
|
||||
}
|
||||
public static function getLike($pid){
|
||||
$model = new self();
|
||||
$model = $model->where('r.product_id',$pid)->where('r.type','like');
|
||||
$model = $model->alias('r')->join('__WECHAT_USER__ u','u.uid=r.uid');
|
||||
$model = $model->field('r.*,u.nickname');
|
||||
return self::page($model);
|
||||
}
|
||||
|
||||
}
|
||||
109
app/admin/model/store/StoreProductReply.php
Normal file
109
app/admin/model/store/StoreProductReply.php
Normal file
@ -0,0 +1,109 @@
|
||||
<?php
|
||||
/**
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/11/11
|
||||
*/
|
||||
|
||||
namespace app\admin\model\store;
|
||||
|
||||
use crmeb\traits\ModelTrait;
|
||||
use crmeb\basic\BaseModel;
|
||||
|
||||
/**
|
||||
* 评论管理 model
|
||||
* Class StoreProductReply
|
||||
* @package app\admin\model\store
|
||||
*/
|
||||
class StoreProductReply extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 数据表主键
|
||||
* @var string
|
||||
*/
|
||||
protected $pk = 'id';
|
||||
|
||||
/**
|
||||
* 模型名称
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'store_product_reply';
|
||||
|
||||
use ModelTrait;
|
||||
|
||||
protected function getPicsAttr($value)
|
||||
{
|
||||
return json_decode($value,true);
|
||||
}
|
||||
/*
|
||||
* 设置where条件
|
||||
* @param array $where
|
||||
* @param string $alias
|
||||
* @param object $model
|
||||
* */
|
||||
public static function valiWhere($where,$alias='',$joinAlias='',$model=null)
|
||||
{
|
||||
$model=is_null($model) ? new self() : $model;
|
||||
if($alias){
|
||||
$model=$model->alias($alias);
|
||||
$alias.='.';
|
||||
}
|
||||
$joinAlias=$joinAlias ? $joinAlias.'.' : '';
|
||||
if(isset($where['title']) && $where['title']!='') $model=$model->where("{$alias}comment",'LIKE',"%$where[title]%");
|
||||
if(isset($where['is_reply']) && $where['is_reply']!='') $model= $where['is_reply'] >= 0 ? $model->where("{$alias}is_reply",$where['is_reply']) : $model->where("{$alias}is_reply",'>',0);
|
||||
if(isset($where['producr_id']) && $where['producr_id']!=0) $model=$model->where($alias.'product_id',$where['producr_id']);
|
||||
if(isset($where['product_name']) && $where['product_name']) $model=$model->where("{$joinAlias}store_name",'LIKE',"%$where[product_name]%");
|
||||
return $model->where("{$alias}is_del",0);
|
||||
}
|
||||
|
||||
public static function getProductImaesList($where)
|
||||
{
|
||||
$list=self::valiWhere($where,'a','p')->group('p.id')->join('__wechat_user__ u','u.uid=a.uid')->join("__store_product__ p",'a.product_id=p.id')->field(['p.id','p.image','p.store_name','p.price'])->page($where['page'],$where['limit'])->select();
|
||||
$list=count($list) ? $list->toArray() : [];
|
||||
foreach ($list as &$item){
|
||||
$item['store_name']=self::getSubstrUTf8($item['store_name'],10,'UTF-8','');
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
public static function getProductReplyList($where)
|
||||
{
|
||||
$data=self::valiWhere($where,'a','p')->join("__store_product__ p",'a.product_id=p.id')
|
||||
->join('__wechat_user__ u','u.uid=a.uid')
|
||||
->order('a.add_time desc,a.is_reply asc')
|
||||
->field('a.*,u.nickname,u.headimgurl as avatar')
|
||||
->page((int)$where['message_page'],(int)$where['limit'])
|
||||
->select();
|
||||
$data=count($data) ? $data->toArray() : [];
|
||||
foreach ($data as &$item){
|
||||
$item['time']=\crmeb\services\UtilService::timeTran($item['add_time']);
|
||||
}
|
||||
$count=self::valiWhere($where,'a','p')->join('__wechat_user__ u','u.uid=a.uid')->join("__store_product__ p",'a.product_id=p.id')->count();
|
||||
return ['list'=>$data,'count'=>$count];
|
||||
}
|
||||
/**
|
||||
* @param $where
|
||||
* @return array
|
||||
*/
|
||||
public static function systemPage($where){
|
||||
$model = new self;
|
||||
if($where['comment'] != '') $model = $model->where('r.comment','LIKE',"%$where[comment]%");
|
||||
if($where['is_reply'] != ''){
|
||||
if($where['is_reply'] >= 0){
|
||||
$model = $model->where('r.is_reply',$where['is_reply']);
|
||||
}else{
|
||||
$model = $model->where('r.is_reply','>',0);
|
||||
}
|
||||
}
|
||||
if($where['product_id']) $model = $model->where('r.product_id',$where['product_id']);
|
||||
$model = $model->alias('r')->join('__wechat_user__ u','u.uid=r.uid');
|
||||
$model = $model->join('__store_product__ p','p.id=r.product_id');
|
||||
$model = $model->where('r.is_del',0);
|
||||
$model = $model->field('r.*,u.nickname,u.headimgurl,p.store_name');
|
||||
$model = $model->order('r.add_time desc,r.is_reply asc');
|
||||
return self::page($model,function($itme){
|
||||
|
||||
},$where);
|
||||
}
|
||||
|
||||
}
|
||||
73
app/admin/model/store/StoreVisit.php
Normal file
73
app/admin/model/store/StoreVisit.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
/**
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/11/11
|
||||
*/
|
||||
|
||||
namespace app\admin\model\store;
|
||||
|
||||
use crmeb\traits\ModelTrait;
|
||||
use crmeb\basic\BaseModel;
|
||||
use app\admin\model\user\User;
|
||||
|
||||
/**
|
||||
* 商品浏览分析
|
||||
* Class StoreVisit
|
||||
* @package app\admin\model\store
|
||||
*/
|
||||
class StoreVisit extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 数据表主键
|
||||
* @var string
|
||||
*/
|
||||
protected $pk = 'id';
|
||||
|
||||
/**
|
||||
* 模型名称
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'store_visit';
|
||||
|
||||
use ModelTrait;
|
||||
|
||||
/**
|
||||
* @param $date
|
||||
* @param array $class
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function getVisit($date,$class=[]){
|
||||
$model=new self();
|
||||
switch ($date){
|
||||
case null:case 'today':case 'week':case 'year':
|
||||
if($date==null) $date='month';
|
||||
$model=$model->whereTime('add_time',$date);
|
||||
break;
|
||||
case 'quarter':
|
||||
list($startTime,$endTime)=User::getMonth('n');
|
||||
$model = $model->where('add_time','>',$startTime);
|
||||
$model = $model->where('add_time','<',$endTime);
|
||||
break;
|
||||
default:
|
||||
list($startTime,$endTime)=explode('-',$date);
|
||||
$model = $model->where('add_time','>',strtotime($startTime));
|
||||
$model = $model->where('add_time','<',strtotime($endTime));
|
||||
break;
|
||||
}
|
||||
$list=$model->group('type')->field('sum(count) as sum,product_id,cate_id,type,content')->order('sum desc')->limit(0,10)->select()->toArray();
|
||||
$view=[];
|
||||
foreach ($list as $key=>$val){
|
||||
$now_list['name']=$val['type']=='viwe'?'浏览量':'搜索';
|
||||
$now_list['value']=$val['sum'];
|
||||
$now_list['class']=isset($class[$key])?$class[$key]:'';
|
||||
$view[]=$now_list;
|
||||
}
|
||||
if(empty($list)){
|
||||
$view=[['name'=>'暂无数据', 'value'=>100, 'class'=>'']];
|
||||
}
|
||||
return $view;
|
||||
}
|
||||
}
|
||||
40
app/admin/model/system/Express.php
Normal file
40
app/admin/model/system/Express.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/11/11
|
||||
*/
|
||||
|
||||
namespace app\admin\model\system;
|
||||
|
||||
use crmeb\traits\ModelTrait;
|
||||
use crmeb\basic\BaseModel;
|
||||
|
||||
/**
|
||||
* Class Express
|
||||
* @package app\admin\model\system
|
||||
*/
|
||||
class Express extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* 数据表主键
|
||||
* @var string
|
||||
*/
|
||||
protected $pk = 'id';
|
||||
|
||||
/**
|
||||
* 模型名称
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'express';
|
||||
|
||||
use ModelTrait;
|
||||
|
||||
public static function systemPage($params)
|
||||
{
|
||||
$model = new self;
|
||||
if($params['keyword'] !== '') $model = $model->where('name|code','LIKE',"%$params[keyword]%");
|
||||
$model = $model->order('sort DESC,id DESC');
|
||||
return self::page($model,$params);
|
||||
}
|
||||
}
|
||||
171
app/admin/model/system/SystemAdmin.php
Normal file
171
app/admin/model/system/SystemAdmin.php
Normal file
@ -0,0 +1,171 @@
|
||||
<?php
|
||||
/**
|
||||
* @author: xaboy<365615158@qq.com>
|
||||
* @day: 2017/11/11
|
||||
*/
|
||||
|
||||
namespace app\admin\model\system;
|
||||
|
||||
use crmeb\traits\ModelTrait;
|
||||
use crmeb\basic\BaseModel;
|
||||
use think\facade\Session;
|
||||
|
||||
/**
|
||||
* Class SystemAdmin
|
||||
* @package app\admin\model\system
|
||||
*/
|
||||
class SystemAdmin extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 数据表主键
|
||||
* @var string
|
||||
*/
|
||||
protected $pk = 'id';
|
||||
|
||||
/**
|
||||
* 模型名称
|
||||
* @var string
|
||||
*/
|
||||
protected $name = 'system_admin';
|
||||
|
||||
use ModelTrait;
|
||||
|
||||
protected $insert = ['add_time'];
|
||||
|
||||
public static function setAddTimeAttr($value)
|
||||
{
|
||||
return time();
|
||||
}
|
||||
|
||||
public static function setRolesAttr($value)
|
||||
{
|
||||
return is_array($value) ? implode(',', $value) : $value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 用户登陆
|
||||
* @param $account
|
||||
* @param $pwd
|
||||
* @return bool
|
||||
*/
|
||||
public static function login($account,$pwd)
|
||||
{
|
||||
$adminInfo = self::get(compact('account'));
|
||||
if(!$adminInfo) return self::setErrorInfo('登陆的账号不存在!');
|
||||
if($adminInfo['pwd'] != md5($pwd)) return self::setErrorInfo('账号或密码错误,请重新输入');
|
||||
if(!$adminInfo['status']) return self::setErrorInfo('该账号已被关闭!');
|
||||
self::setLoginInfo($adminInfo);
|
||||
event('SystemAdminLoginAfter',[$adminInfo]);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存当前登陆用户信息
|
||||
*/
|
||||
public static function setLoginInfo($adminInfo)
|
||||
{
|
||||
Session::set('adminId',$adminInfo['id']);
|
||||
Session::set('adminInfo',$adminInfo->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空当前登陆用户信息
|
||||
*/
|
||||
public static function clearLoginInfo()
|
||||
{
|
||||
Session::delete('adminInfo');
|
||||
Session::delete('adminId');
|
||||
Session::clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查用户登陆状态
|
||||
* @return bool
|
||||
*/
|
||||
public static function hasActiveAdmin()
|
||||
{
|
||||
return Session::has('adminId') && Session::has('adminInfo');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得登陆用户信息
|
||||
* @return mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function activeAdminInfoOrFail()
|
||||
{
|
||||
$adminInfo = Session::get('adminInfo');
|
||||
if(!$adminInfo) exception('请登陆');
|
||||
if(!$adminInfo['status']) exception('该账号已被关闭!');
|
||||
return $adminInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得登陆用户Id 如果没有直接抛出错误
|
||||
* @return mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function activeAdminIdOrFail()
|
||||
{
|
||||
$adminId = Session::get('adminId');
|
||||
if(!$adminId) exception('访问用户为登陆登陆!');
|
||||
return $adminId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|null
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function activeAdminAuthOrFail()
|
||||
{
|
||||
$adminInfo = self::activeAdminInfoOrFail();
|
||||
if(is_object($adminInfo)) $adminInfo = $adminInfo->toArray();
|
||||
return $adminInfo['level'] === 0 ? SystemRole::getAllAuth() : SystemRole::rolesByAuth($adminInfo['roles']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得有效管理员信息
|
||||
* @param $id
|
||||
* @return mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getValidAdminInfoOrFail($id)
|
||||
{
|
||||
$adminInfo = self::get($id);
|
||||
if(!$adminInfo) exception('用户不能存在!');
|
||||
if(!$adminInfo['status']) exception('该账号已被关闭!');
|
||||
return $adminInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @param int $level
|
||||
* @return \think\Collection
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public static function getOrdAdmin($field = 'real_name,id',$level = 0){
|
||||
return self::where('level','>=',$level)->field($field)->select();
|
||||
}
|
||||
|
||||
public static function getTopAdmin($field = 'real_name,id')
|
||||
{
|
||||
return self::where('level',0)->field($field)->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $where
|
||||
* @return array
|
||||
*/
|
||||
public static function systemPage($where){
|
||||
$model = new self;
|
||||
if($where['name'] != '') $model = $model->where('account|real_name','LIKE',"%$where[name]%");
|
||||
if($where['roles'] != '') $model = $model->where("CONCAT(',',roles,',') LIKE '%,$where[roles],%'");
|
||||
$model = $model->where('level',$where['level'])->where('is_del',0);
|
||||
return self::page($model,function($admin){
|
||||
$admin->roles = SystemRole::where('id','IN',$admin->roles)->column('role_name','id');
|
||||
},$where);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user