Browse Source

'初始化'

master
tanghuijun 4 years ago
parent
commit
59b1a49cde
  1. 25
      .env
  2. 24
      .env.official
  3. 24
      .gitignore
  4. 42
      .travis.yml
  5. 32
      LICENSE.txt
  6. 1
      app/.htaccess
  7. 22
      app/AppService.php
  8. 94
      app/BaseController.php
  9. 32
      app/BaseModel.php
  10. 58
      app/ExceptionHandle.php
  11. 8
      app/Request.php
  12. 105
      app/api/controller/Base.php
  13. 104
      app/api/controller/Goods.php
  14. 97
      app/api/validate/Goods.php
  15. 107
      app/common.php
  16. 80
      app/entrust/controller/Base.php
  17. 17
      app/entrust/controller/Index.php
  18. 17
      app/event.php
  19. 11
      app/middleware.php
  20. 10
      app/model/Cert.php
  21. 129
      app/model/Goods.php
  22. 14
      app/model/GoodsDetail.php
  23. 11
      app/model/GoodsSource.php
  24. 9
      app/provider.php
  25. 9
      app/service.php
  26. 212
      app/service/BaseService.php
  27. 174
      app/service/Goods/ClassifyService.php
  28. 845
      app/service/Goods/GoodsService.php
  29. 192
      app/service/IndexService.php
  30. 25
      app/service/LogService.php
  31. 59
      app/service/SignService.php
  32. 92
      app/service/UploadService.php
  33. 30
      app/service/clearing/ClearingService.php
  34. 29
      app/service/culture/ClassifyService.php
  35. 301
      app/service/order/AccountCloseService.php
  36. 1748
      app/service/order/OrderService.php
  37. 80
      app/service/pay/ApiHelperoneService.php
  38. 110
      app/service/pay/InvoiceManagementService.php
  39. 676
      app/service/pay/PayService.php
  40. 175
      app/service/pay/SeparateAccountService.php
  41. 200
      app/service/pay/security.php
  42. 666
      app/service/task/GoodsService.php
  43. 353
      app/service/task/OrderService.php
  44. 78
      app/service/user/LoginService.php
  45. 374
      app/service/user/UserService.php
  46. 18
      app/task/controller/Base.php
  47. 186
      app/task/controller/Goods.php
  48. 166
      app/task/controller/Order.php
  49. 2
      clean_sh/ignore.sh
  50. 2
      clean_sh/no_ignore.sh
  51. 51
      composer.json
  52. 1238
      composer.lock
  53. 32
      config/app.php
  54. 81
      config/cache.php
  55. 9
      config/console.php
  56. 20
      config/cookie.php
  57. 63
      config/database.php
  58. 16
      config/festivals.php
  59. 24
      config/filesystem.php
  60. 15
      config/jwt.php
  61. 27
      config/lang.php
  62. 45
      config/log.php
  63. 8
      config/middleware.php
  64. 45
      config/route.php
  65. 19
      config/session.php
  66. 10
      config/trace.php
  67. 50
      config/upload.php
  68. 18
      config/userauth.php
  69. 25
      config/view.php
  70. 2
      extend/.gitignore
  71. 0
      public/.htaccess
  72. 52
      public/cert/distribute/private_key.pem
  73. 14
      public/cert/distribute/public_key.pem
  74. 52
      public/cert/entrust/private_key.pem
  75. 14
      public/cert/entrust/public_key.pem
  76. 16
      public/cert/user_real/private_key.pem
  77. 6
      public/cert/user_real/public_key.pem
  78. BIN
      public/favicon.ico
  79. 24
      public/index.php
  80. 0
      public/nginx.htaccess
  81. 2
      public/robots.txt
  82. 19
      public/router.php
  83. 2136
      ranking.sql
  84. 17
      route/app.php
  85. 2
      runtime/.gitignore
  86. 19
      sql/22-03-30/update.sql
  87. 33
      sql/22-03-31/update.sql
  88. 2136
      sql/22-06-15/ranking.sql
  89. 1043
      sql/jiao_api_alpha_x.sql
  90. 5520
      sql/jiao_api_alpha_x_full.sql
  91. 10
      think
  92. 1
      view/README.md

25
.env

@ -0,0 +1,25 @@
APP_DEBUG = true
[APP]
DEFAULT_TIMEZONE = Asia/Shanghai
ENTRUST_URL = http://10.14.1.173:9528
#TIANLANG_ENTRUST_URL = http://58.30.231.137:51317
TIANLANG_ENTRUST_URL = http://10.14.1.248:11030
REAL_URL = http://58.30.231.137:51317
HOST = http://58.30.231.138:8899
[ISLI]
CHANNEL_ISLI = 999998-000000000126-6
[DATABASE]
TYPE = mysql
HOSTNAME = 127.0.0.1
DATABASE = ranking
USERNAME = ranking
PASSWORD = rankingroot
HOSTPORT = 3306
CHARSET = utf8
DEBUG = true
[LANG]
default_lang = zh-cn

24
.env.official

@ -0,0 +1,24 @@
APP_DEBUG = false
[APP]
DEFAULT_TIMEZONE = Asia/Shanghai
ENTRUST_URL = http://10.24.4.14:51317
TIANLANG_ENTRUST_URL = http://10.24.4.90:11030
REAL_URL = http://10.24.4.14:51317
HOST = http://10.24.4.56
[ISLI]
CHANNEL_ISLI = 999998-000000000126-6
[DATABASE]
TYPE = mysql
HOSTNAME = 10.24.4.162
DATABASE = jiao_api_alpha_x
USERNAME = jiao_api_alpha_x
PASSWORD = YcpfGJyJpy6KfYR3
HOSTPORT = 3306
CHARSET = utf8
DEBUG = true
[LANG]
default_lang = zh-cn

24
.gitignore

@ -1,20 +1,4 @@
# ---> Actionscript
# Build and Release Folders
bin-debug/
bin-release/
[Oo]bj/
[Bb]in/
# Other files and folders
.settings/
# Executables
*.swf
*.air
*.ipa
*.apk
# Project files, i.e. `.project`, `.actionScriptProperties` and `.flexProperties`
# should NOT be excluded as they contain compiler settings and other important
# information for Eclipse / Flash Builder.
/.idea
/.vscode
/vendor
*.log

42
.travis.yml

@ -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

32
LICENSE.txt

@ -0,0 +1,32 @@
ThinkPHP遵循Apache2开源协议发布,并提供免费使用。
版权所有Copyright © 2006-2016 by ThinkPHP (http://thinkphp.cn)
All rights reserved。
ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。
Apache Licence是著名的非盈利开源组织Apache采用的协议。
该协议和BSD类似,鼓励代码共享和尊重原作者的著作权,
允许代码修改,再作为开源或商业软件发布。需要满足
的条件:
1. 需要给代码的用户一份Apache Licence ;
2. 如果你修改了代码,需要在被修改的文件中说明;
3. 在延伸的代码中(修改和有源代码衍生的代码中)需要
带有原来代码中的协议,商标,专利声明和其他原来作者规
定需要包含的说明;
4. 如果再发布的产品中包含一个Notice文件,则在Notice文
件中需要带有本协议内容。你可以在Notice中增加自己的
许可,但不可以表现为对Apache Licence构成更改。
具体的协议参考:http://www.apache.org/licenses/LICENSE-2.0
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

1
app/.htaccess

@ -0,0 +1 @@
deny from all

22
app/AppService.php

@ -0,0 +1,22 @@
<?php
declare (strict_types = 1);
namespace app;
use think\Service;
/**
* 应用服务类
*/
class AppService extends Service
{
public function register()
{
// 服务注册
}
public function boot()
{
// 服务启动
}
}

94
app/BaseController.php

@ -0,0 +1,94 @@
<?php
declare (strict_types = 1);
namespace app;
use think\App;
use think\exception\ValidateException;
use think\Validate;
/**
* 控制器基础类
*/
abstract class BaseController
{
/**
* Request实例
* @var \think\Request
*/
protected $request;
/**
* 应用实例
* @var \think\App
*/
protected $app;
/**
* 是否批量验证
* @var bool
*/
protected $batchValidate = false;
/**
* 控制器中间件
* @var array
*/
protected $middleware = [];
/**
* 构造方法
* @access public
* @param App $app 应用对象
*/
public function __construct()
{
$this->app = App();
$this->request = $this->app->request;
// 控制器初始化
$this->initialize();
}
// 初始化
protected function initialize()
{}
/**
* 验证数据
* @access protected
* @param array $data 数据
* @param string|array $validate 验证器名或者验证规则数组
* @param array $message 提示信息
* @param bool $batch 是否批量验证
* @return array|string|true
* @throws ValidateException
*/
protected function validate(array $data, $validate, array $message = [], bool $batch = false)
{
if (is_array($validate)) {
$v = new Validate();
$v->rule($validate);
} else {
if (strpos($validate, '.')) {
// 支持场景
[$validate, $scene] = explode('.', $validate);
}
$class = false !== strpos($validate, '\\') ? $validate : $this->app->parseClass('validate', $validate);
$v = new $class();
if (!empty($scene)) {
$v->scene($scene);
}
}
$v->message($message);
// 是否批量验证
if ($batch || $this->batchValidate) {
$v->batch(true);
}
return $v->failException(true)->check($data);
}
}

32
app/BaseModel.php

@ -0,0 +1,32 @@
<?php
namespace app;
use think\Model;
class BaseModel extends Model
{
public $withJoin = false;
/**
* 转换获取with,根据参数with替换为withData中自定义with数据
* @param array $with
* @param array $withData
* @return array|null
*/
public function buildWith(array $with, array $withData) {
if ($with['withJoin'] ?? false){
$this->withJoin = $with['withJoin'];
unset($with['withJoin']);
}
foreach ($withData as $k => $v){
if (in_array($k, $with)){
$with_key = array_search($k, $with);
unset($with[$with_key]);
$with[$k] = $v;
}
}
return $with; //添加 withDiff 中数据
}
}

58
app/ExceptionHandle.php

@ -0,0 +1,58 @@
<?php
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);
}
}

8
app/Request.php

@ -0,0 +1,8 @@
<?php
namespace app;
// 应用请求对象类
class Request extends \think\Request
{
}

105
app/api/controller/Base.php

@ -0,0 +1,105 @@
<?php
namespace app\api\controller;
use app\BaseController;
use app\service\BaseService;
use app\service\SignService;
use app\service\user\UserService;
use log\LogOpe;
use think\exception\HttpResponseException;
use think\facade\Log;
use think\facade\Request;
class Base extends BaseController
{
/**
* 无需检测的方法.
*
* @var array
*/
protected $noNeedCheck = ['apiDoc'];
protected $log = null;
protected $apilog = null;
protected $token = null;
public function __construct()
{
parent::__construct();
$this->log = new LogOpe('api/'.get_class($this) . 'Controller');
$this->apilog = new LogOpe("request/".date("YmdH") . "Request");
if(!$this->match($this->noNeedCheck)){
// $this->checkSign();
}
$this->checkUser();
}
/**
* 检测当前控制器和方法是否匹配传递的数组.
*
* @param array $arr 需要验证权限的数组
* @return bool
*/
public function match($arr = [])
{
$request = Request::instance();
$arr = is_array($arr) ? $arr : explode(',', $arr);
if (! $arr) {
return false;
}
$arr = array_map('strtolower', $arr);
// 是否存在
if (in_array(strtolower($request->action()), $arr) || in_array('*', $arr)) {
return true;
}
// 没找到匹配
return false;
}
/**
* 请求校验(抛异常)
* @param $class
* @param string $scene
* @param string|null $method 指定参数类型
* @param bool $limit 限制请求类型
* @throws \Exception
*/
protected function checkVaild($class, $scene = '', $method = null, $limit = false) {
(new BaseService())->checkVaild($class, $scene, $method, $limit);
}
/**
* 校验签名.
*
* @return bool
*/
public function checkSign()
{
$signService = new SignService();
// 获取请求数据
$post = $this->request->post(['appkey', 'timestamp']);
// 获取签名以及key
$sign = isset($_SERVER['HTTP_SIGN']) ? $_SERVER['HTTP_SIGN'] : '';
if (!$sign){
throw new HttpResponseException(_error('缺少sign', 400));
}
$signService->checkSign($post, $sign);
}
public function checkUser(){
$user_isli = $this->request->post('user_isli', '');
$userService = new UserService();
if(!empty($user_isli)){
// $userService->checkUser($user_isli);
}
}
}

104
app/api/controller/Goods.php

@ -0,0 +1,104 @@
<?php
namespace app\api\controller;
use app\Request;
use app\service\Goods\GoodsService;
use think\cache\driver\Redis;
class Goods extends Base
{
protected $noNeedCheck = ['getApiGoods'];
public function __construct()
{
parent::__construct();
$this->valid = \app\api\validate\Goods::class;
}
/**
* @title 获取购物车
* @url /api/Goods/getShoppingCar
* @method POST
* @param string user_isli 用户isli标识码
* @return string msg 返回信息
* @return int code 状态码 200:成功;>=400:失败
*/
public function getShoppingCar(){
try {
// todo 被请求获取购物车 接口
$this->checkVaild($this->valid, 'getShoppingCar', 'post');
$user_isli = $this->request->post('user_isli');
$goodsService = new GoodsService();
$this->apilog->info("获取购物车", Request()->param());
$result = $goodsService->getShoppingCar($user_isli);
return _success('成功', $result);
}catch(\Exception $e){
return _error($e->getMessage(), $e->getCode() ?: 400, $e);
}
}
/**
* @title 根据类型获取委托信息
* @url /api/Goods/getTypeGoods
* @method POST
* @param string type 类型;1:点击;2:销售;3:推荐
* @param string hot 热门展示
* @param string hotsale 热卖展示
* @return string msg 返回信息
* @return int code 状态码 200:成功;>=400:失败
*/
public function getTypeGoods(){
try {
// todo 被请求首页排行榜 接口
// $this->checkVaild($this->valid, 'getTypeGoods', 'post');
// $goods_type = $this->request->post('goods_type');
// $type = $this->request->post('type');
$createtime = $this->request->post('createtime');
$goodsService = new GoodsService();
$result = $goodsService->getTypeGoods('1', $createtime);
return _success('成功', $result);
}catch(\Exception $e){
return _error($e->getMessage(), $e->getCode() ?: 400, $e);
}
}
/**
* @title 查询委托信息
* @url /api/Goods/searchGoods
* @method POST
* @param string entrust_time 委托时间(时间戳)
* @param string record_type 数据类型
* @param string entrust_user_name 委托方名称
* @param string authorization 授权方式
* @param string pay_type 付费类型
* @param string entrust_name 委托数据名称
* @param string entrust_islicode 委托数据isli标识码
* @param string goods_islicode 商品isli标识码
* @return string msg 返回信息
* @return int code 状态码 200:成功;>=400:失败
*/
public function searchGoods(){
try {
// todo 被请求委托查询 接口
$this->checkVaild($this->valid, 'searchGoods', 'post');
$post = $this->request->post(['entrust_time', 'record_type', 'entrust_user_name', 'authorization', 'pay_type',
'entrust_name', 'entrust_islicode', 'goods_islicode', 'source_type', 'order_type', 'order', 'goods_status', 'page', 'limit']);
$goodsService = new GoodsService();
$this->apilog->info("查询委托信息接口", $post);
$result = $goodsService->searchGoods($post);
return _success('成功', $result);
}catch(\Exception $e){
return _error($e->getMessage(), $e->getCode() ?: 400, $e);
}
}
public function test(){
$goodsService = new GoodsService();
$goodsService->test();
}
}

97
app/api/validate/Goods.php

@ -0,0 +1,97 @@
<?php
namespace app\api\validate;
use think\Validate;
class Goods extends Validate
{
/**
* 验证规则.
*/
protected $rule = [
'page|页数' => 'number',
'limit|条数' => 'number',
'goods_name|商品名称' => 'max:20',
'user_isli|用户ISLI标识码' => 'require',
'goods_isli|商品ISLI标识码' => 'require',
'goods_num|商品数量' => 'require|number|>:0',
'use_years|使用年限' => 'require|number|>:0',
// 'platform' => '、require|number|in:1,2',
// 'hot' => 'require|number|in:1,2',
// 'hotsale' => 'require|number|in:1,2',
'source_type' => 'max:20',
'entrust_time' => 'checkDateTime',
'record_type' => 'number|in:1,2',
'entrust_user_name' => 'max:30',
'authorization' => 'number|in:1,2',
'pay_type' => 'number|in:1,2',
'entrust_name' => 'max:300',
'type' => 'require|in:1,2,3',
'goods_status' => 'checkStatusStr',
'createtime' => 'checkDateTime',
];
/**
* 提示消息.
*/
protected $message = [
];
/**
* 字段描述.
*/
protected $field = [
];
/**
* 验证场景.
*/
protected $scene = [
'list' => ['page', 'limit', 'goods_name'],
'addShoppingCar' => ['user_isli', 'goods_isli', 'use_years'],
'delShoppingCar' => ['user_isli', 'goods_isli'],
'addCarGoodsCount' => ['user_isli', 'goods_isli'],
'decCarGoodsCount' => ['user_isli', 'goods_isli'],
'getShoppingCar' => ['user_isli'],
'getTypeGoods' => ['type'],
'searchGoods' => ['entrust_time', 'record_type', 'entrust_user_name', 'authorization', 'pay_type', 'entrust_name', 'source_type', 'goods_status', 'page', 'limit'],
];
function checkDateTime($value){
if(!is_array($value)){
return "时间格式为数组";
}
if(count($value) != 2){
return "时间数组错误";
}
if(!isset($value[0]) || !isset($value[1]) || empty($value[0]) || empty($value[1])){
return "时间数组错误";
}
if(strtotime($value[0]) == false || strtotime($value[1]) == false){
return "格式错误";
}
return true;
}
function checkStatusStr($value){
if(empty($value)){
return true;
}
if(!is_string($value)){
return "格式错误";
}
$arr = explode(',', $value);
if(count($arr) <= 0){
return "数据错误";
}
foreach($arr as $val){
if(!preg_match("/^\d*$/" , $val)){
return "需为数字";
}
}
return true;
}
}

107
app/common.php

@ -0,0 +1,107 @@
<?php
// 应用公共文件
if (!function_exists('_error'))
{
function _error($msg, int $code = 400, $data = null, $return_array = false){
$result = [
'code' => $code,
'msg' => $msg
];
if($data instanceof \Exception && (config('app.app_debug') || request()->param('xdebug') == 'xdebug')){
$result['data'] = $data->getTrace();
}elseif ($data !== null){
$result['data'] = $data;
}
if ($return_array){
return $result;
}else{
return json($result);
}
}
}
if (! function_exists('_success'))
{
function _success($msg, $data = null, $return_array = false){
$result = [
'code' => 200,
'msg' => $msg
];
if ($data !== null){
$result['data'] = $data;
}
if ($return_array){
return $result;
}else{
return json($result);
}
}
}
if (! function_exists('upload_file'))
{
/**
* 上传文件.
*
* @param string $file 上传的文件
* @param string $name 上传的位置
* @param string $path 上传的文件夹
* @param string $validate 规则验证
*
* @return string|bool
* @author niu
*/
function upload_file($file = null, $name = 'local', $path = '', $validate = '')
{
//文件
if (! $file) {
return false;
}
//上传配置
$config_name = 'filesystem.disks.'.$name;
$filesystem = config($config_name);
if (! $filesystem) {
return false;
}
//上传文件
if ($validate) {
validate(['file' => $validate])->check(['file' => $file]);
}
$savename = \think\facade\Filesystem::disk($name)->putFile($path, $file, function ($file) {
//重命名
return date('Ymd').'/'.md5((string) microtime(true));
});
if (isset($filesystem['url'])) {
$savename = $filesystem['url'].$savename;
}
return $savename;
}
}
if (! function_exists('getSourceFileSize')) {
function getSourceFileSize($size)
{
$file_size = $size - 1;
if ($file_size >= 1099511627776) $show_filesize = number_format(($file_size / 1099511627776), 2) . " TB";
elseif ($file_size >= 1073741824) $show_filesize = number_format(($file_size / 1073741824), 2) . " GB";
elseif ($file_size >= 1048576) $show_filesize = number_format(($file_size / 1048576), 2) . " MB";
elseif ($file_size >= 1024) $show_filesize = number_format(($file_size / 1024), 2) . " KB";
elseif ($file_size > 0) $show_filesize = $file_size . " b";
elseif ($file_size == 0 || $file_size == -1) $show_filesize = "0 b";
return $show_filesize;
}
}

80
app/entrust/controller/Base.php

@ -0,0 +1,80 @@
<?php
namespace app\entrust\controller;
use app\BaseController;
use app\service\SignService;
use think\exception\HttpResponseException;
use think\facade\Log;
use think\facade\Request;
use think\Validate;
class Base extends BaseController
{
/**
* 无需检测的方法.
*
* @var array
*/
protected $noNeedCheck = ['apiDoc'];
protected $log = null;
protected $token = null;
public function __construct()
{
parent::__construct();
$this->log = new Log();
if(!$this->match($this->noNeedCheck)){
$this->checkSign();
}
}
/**
* 检测当前控制器和方法是否匹配传递的数组.
*
* @param array $arr 需要验证权限的数组
* @return bool
*/
public function match($arr = [])
{
$request = Request::instance();
$arr = is_array($arr) ? $arr : explode(',', $arr);
if (! $arr) {
return false;
}
$arr = array_map('strtolower', $arr);
// 是否存在
if (in_array(strtolower($request->action()), $arr) || in_array('*', $arr)) {
return true;
}
// 没找到匹配
return false;
}
/**
* 校验签名.
*
* @return bool
*/
public function checkSign()
{
$signService = new SignService();
// 获取请求数据
$post = $this->request->post();
// 获取签名以及key
$sign = isset($_SERVER['HTTP_SIGN']) ? $_SERVER['HTTP_SIGN'] : '';
if (!$sign){
throw new HttpResponseException(_error('缺少sign', 400));
}
$signService->checkSign($post, $sign);
}
}

17
app/entrust/controller/Index.php

@ -0,0 +1,17 @@
<?php
namespace app\entrust\controller;
class Index extends Base
{
public function __construct()
{
parent::__construct();
}
public function test(){
echo 'index';
}
}

17
app/event.php

@ -0,0 +1,17 @@
<?php
// 事件定义文件
return [
'bind' => [
],
'listen' => [
'AppInit' => [],
'HttpRun' => [],
'HttpEnd' => [],
'LogLevel' => [],
'LogWrite' => [],
],
'subscribe' => [
],
];

11
app/middleware.php

@ -0,0 +1,11 @@
<?php
// 全局中间件定义文件
return [
// 全局请求缓存
// \think\middleware\CheckRequestCache::class,
// 多语言加载
// \think\middleware\LoadLangPack::class,
// Session初始化
// \think\middleware\SessionInit::class
\think\middleware\AllowCrossDomain::class,
];

10
app/model/Cert.php

@ -0,0 +1,10 @@
<?php
namespace app\model;
use app\BaseModel;
class Cert extends BaseModel
{
}

129
app/model/Goods.php

@ -0,0 +1,129 @@
<?php
namespace app\model;
use app\BaseModel;
class Goods extends BaseModel
{
public function goodsDetail(){
return $this->hasOne(GoodsDetail::class, 'id', 'goods_detail_id')
->bind(['goods_name', 'goods_image', 'total_inventory', 'surplus_inventory', 'goods_ownership', 'goods_ownership_str', 'goods_type', 'charges_type',
'goods_entrust', 'goods_exceptions', 'entrust_month', 'earnest_money', 'canceltime', 'stock',
'contractual_period', 'contract', 'transaction_class', 'otherIdentifiers', 'classification', 'price']);
}
// public function goodsData(){
// return $this->hasMany(GoodsSource::class, "goods_detail_id", 'goods_id');
// }
public function User(){
return $this->hasOne(User::class, 'user_isli', 'user_islicode')
->bind(['username', 'agency_type', 'attest_status', 'registertime', 'attesttime']);
}
public function searchGoodsNameAttr($query, $value){
if($value){
$query->whereLike('goodsDetail.goods_name', '%'.$value.'%');
}
}
public function searchUserNameAttr($query, $value){
if($value){
$query->whereLike('goods.username', '%'.$value.'%');
}
}
public function searchGoodsIsLiCodeAttr($query, $value){
if($value){
$query->whereIn('goods.goods_islicode', $value);
}
}
public function searchOrderAttr($query, $value){
if ($value){
$query->orderRaw($value);
}else{
$query->order('goods.id','desc');
}
}
public function searchCreatetimeAttr($query, $value){
if (isset($value[1]) && preg_match("/^\d{4}-\d{2}-\d{2}$/", $value[1])){
$value[1] = $value[1] . ' 23:59:59';
}
if (isset($value[0]) && isset($value[1]) && $value[0] && $value[1]){
$query->whereBetweenTime('goods.createtime', $value[0], $value[1]);
}elseif (isset($value[0]) && $value[0]){
$query->whereTime('goods.createtime', '>=', $value[0]);
}elseif (isset($value[1]) && $value[1]){
$query->whereTime('goods.createtime', '<=', $value[1]);
}
}
public function searchGoodsStatusAttr($query, $value){
if($value){
$query->whereIn('goods.goods_status', $value);
}
}
public function searchSearchUserAttr($query, $value){
if($value){
$query->where(function($query) use($value){
$query->whereLike("goods.username", "%{$value}%", "or")->whereLike("goods.user_islicode", "%{$value}%", "or");
});
}
}
public function searchGoodsAttr($query, $value){
if($value){
$query->where(function($query) use($value){
$query->whereLike("goodsDetail.goods_name", "%{$value}%", "or")->whereLike("goods.goods_islicode", "%{$value}%", "or");
});
}
}
public function searchGoodsFieldAttr($query, $value){
if($value){
$query->whereLike("goodsDetail.join_field", "%{$value}%");
}
}
public function list(array $search = [], array $where = [], $type = null, array $with = [], $limit = null){
$this->fields = ['id', 'user_id', 'goods_detail_id', 'goods_islicode', 'username', 'createtime', 'updatetime', 'goods_status', 'is_deleted', 'user_islicode', 'sale_count', 'click_count', 'recommend_sort', 'is_recommend', 'entrust_status', "username"];
$result = $this->field($this->fields)->order('goods.recommend_sort', 'desc')->alias('goods');
$withData = [];
if($search){
$result = $result->withSearch($search[0], $search[1]);
}
if ($with){ // 自定义with数据
$with = $this->buildWith($with, $withData);
if ($this->withJoin){
$result = $result->withJoin($with, $this->withJoin === true ? 'INNER' : $this->withJoin);
}else{
$result = $result->with($with);
}
}
if($where){
$result = $result->where($where);
}
// 执行查询
if ($type == 'fetchSql' || $type == 'sql'){
$result = $result->fetchSql(true)->select();
}elseif (in_array($type, ['select', 'find', 'count'])){
if(!empty($limit)){
$result = $result->limit($limit)->$type();
}else{
$result = $result->$type();
}
}else{
$result = $result->paginate($type ?: 20);
}
return $result;
}
}

14
app/model/GoodsDetail.php

@ -0,0 +1,14 @@
<?php
namespace app\model;
use app\BaseModel;
class GoodsDetail extends BaseModel
{
public function Order(){
return $this->belongsTo(Order::class, 'id', 'goods_detail_id');
}
}

11
app/model/GoodsSource.php

@ -0,0 +1,11 @@
<?php
namespace app\model;
use app\BaseModel;
class GoodsSource extends BaseModel
{
}

9
app/provider.php

@ -0,0 +1,9 @@
<?php
use app\ExceptionHandle;
use app\Request;
// 容器Provider定义文件
return [
'think\Request' => Request::class,
'think\exception\Handle' => ExceptionHandle::class,
];

9
app/service.php

@ -0,0 +1,9 @@
<?php
use app\AppService;
// 系统服务定义文件
// 服务在完成全局初始化之后执行
return [
AppService::class,
];

212
app/service/BaseService.php

@ -0,0 +1,212 @@
<?php
namespace app\service;
use app\model\Admin;
use app\model\Cert;
use Firebase\JWT\JWT;
use Firebase\JWT\Key;
use log\LogOpe;
use think\exception\HttpResponseException;
use think\facade\Log;
use think\facade\Request;
class BaseService
{
protected $admin = null;
protected $admin_id = null;
protected $token = null;
protected $log = null;
protected $orderlog = null;
protected $goodslog = null;
protected $account_id;
protected $account_name;
public function __construct(){
$this->log = new LogOpe(get_class($this));
$this->orderlog = new LogOpe("order/".date("YmdH") . "Order");
$this->goodslog = new LogOpe("goods/".date("YmdH") . "Goods");
// 获取token
if(isset($_SERVER['HTTP_TOKEN'])){
$this->token = $_SERVER['HTTP_TOKEN'];
$this->checkToken();
}
}
/**
* 请求校验(抛异常)
* @param $class
* @param string $scene
* @param string|array|null $method 指定参数类型
* @param bool $limit 限制请求类型
* @throws \Exception
*/
public function checkVaild($class, string $scene = '', string $method = null) {
$method = strtolower($method);
switch ($method){
case "get":
if (!Request::isGet()){
throw new \think\Exception('请求类型错误');
}
$data = Request::get();
break;
case "post":
if (!Request::isPost()){
throw new \think\Exception('请求类型错误');
}
$data = Request::post();
break;
case 'put':
if (!Request::isPut()){
throw new \think\Exception('请求类型错误');
}
$data = Request::put();
break;
case 'patch':
if (!Request::isPatch()){
throw new \think\Exception('请求类型错误');
}
$data = Request::patch();
break;
case 'delete':
if (!Request::isDelete()){
throw new \think\Exception('请求类型错误');
}
$data = Request::delete();
break;
default:
if (is_array($method)){
$data = $method;
}else{
$data = Request::param();
}
}
if ($scene) {
$result = validate($class)->scene($scene)->check($data);
} else {
$result = validate($class)->check($data);
}
return $result;
}
/**
* 构造列表搜索 withSearch 转换函数
* @param $param array 需要搜索的字段
* @param $where array where条件,匹配中存在search中字段则排除原数组字段,使用whthSearch搜索
* @param string $wherePrefix
* @return array[] withSearch条件参数[0] [1]
*/
public function buildSearch(array $param,array &$where, string $wherePrefix = '') {
$search = [0 => [], 1 => []];
foreach ($param as $v){
if ($v == ''){
continue;
}
$search[0][] = $v;
if (isset($where[$v])){
if ($where[$v] != ''){
$search[1][$v] = $where[$v];
}
unset($where[$v]);
}
}
$where = $this->buildWhere($where, true, $wherePrefix);
return $search;
}
/**
* 重组where数据,同时兼容2种查询方法插入
*
* @param $where
* @param bool $filter
* @param string $prefix
* @return array
*/
public function buildWhere($where, $filter = true, $prefix = ''){
//为 where 拼接前缀
if ($prefix != ''){
foreach ($where as $k => $v){
if (is_numeric($k)){
if (strpos($where[$k][0],'.') === false) {
$where[$k][0] = $prefix . $where[$k][0];
}
} elseif (strpos($k,'.') === false) {
$where[$prefix . $k] = $v;
unset($where[$k]);
}
}
}
// 删除where内容为空的数据
if ($filter == true){
$where = array_filter($where,
function($val) {//等于0不能过滤
if ($val === 0 || $val === '0' || $val != false) {
return true;
} else {
return false;
}
});
}
// 拼接重置where为多维数组,支持2种方式组合where
foreach ($where as $k => $v) {
if (is_numeric($k)) {
continue;
} else if (is_array($v)) {
array_unshift($where[$k], $k);
} else {
$where[$k] = [$k, '=', $v];
}
}
return $where = array_values($where);
}
/**
* TOKEN校验
*/
protected function checkToken() {
$cert = Cert::where('status', 0)->where('type', "entrust")->find();
if(!$cert){
throw new \think\Exception('缺少证书', 400);
}
$key = $cert->token;
$jwt = new JWT();
$data = $jwt::decode($this->token, new Key($key, 'HS512'));
if(!empty($data)){
$data = json_decode( json_encode($data), true);
$this->admin_id = Admin::where('account_id', $data['accountId'])->value('id');
$this->account_id = $data['accountId'];
$this->account_name = $data['accountName'];
}
}
public function createSign($type){
$cert = Cert::where('status', 0)->where('type', $type)->find();
if(!$cert){
throw new \think\Exception('缺少证书', 400);
}
$priv_key = file_get_contents($cert->private_key);
$exp = 5 * 60 * 1000;
$payload = [
'iss' => $cert->token,
'exp' => time() + $exp,
'iat' => time(),
];
if($type == "user_real"){
$payload['aud'] = "BD84DD42A7234B05B0C5D11616132AC4";
}
$sign = JWT::encode($payload, $priv_key, 'RS256');
return $sign;
}
}

174
app/service/Goods/ClassifyService.php

@ -0,0 +1,174 @@
<?php
namespace app\service\Goods;
use app\model\Classify;
use app\model\OperationLog;
use app\service\BaseService;
class ClassifyService extends BaseService
{
public function __construct()
{
parent::__construct();
}
public function list($top_class, $son_class, $user_id, $usestatus, $createtime, $page, $limit){
$where = [];
$where['classify.is_deleted'] = 0;
if(!empty($top_class)){
$where['classify.top_class'] = $top_class;
}
if(!empty($son_class)){
$where['classify.son_class'] = $son_class;
}
if(!empty($user_id)){
$where['classify.user_id'] = $user_id;
}
if(!empty($usestatus) || $usestatus >= 0){
$where['classify.status'] = $usestatus;
}
if(!empty($createtime)){
$where['createtime'] = $createtime;
}
$search = $this->buildSearch(['createtime', 'order'], $where);
$list = (new Classify())->list($search, $where, $limit, ['admin']);
$list->hidden(['admin']);
$list = $list->toArray();
$start = ($page - 1) * $limit + 1;
$end = $page * $limit;
if($list['total'] < $end){
$end = $list['total'];
}
if($list['total'] < $start){
$start = $end = $list['total'];
}
$list['start'] = $start;
$list['end'] = $end;
return $list;
}
public function getTop(){
$where = [];
$where['classify.is_deleted'] = 0;
$result = [];
Classify::where($where)->field('top_class')->select()->each(function($item) use(&$result){
if(count($result) >= 1){
$result[count($result)+1] = $item['top_class'];
}else{
$result[1] = $item['top_class'];
}
});
$result = array_unique($result);
return $result;
}
public function getSon($top_class){
$where = [];
$where['is_deleted'] = 0;
$where['top_class'] = $top_class;
$result = Classify::where($where)->field('son_class')->select()->toArray();
$result = array_column($result, "son_class");
return $result;
}
public function addClass($pull_top_class, $top_class, $son_class){
if(!empty($pull_top_class)){
$addclass = [
'top_class' => $pull_top_class,
'son_class' => $son_class,
'user_id' => $this->admin_id,
];
$id = (new Classify())->insertGetId($addclass);
// 插入操作日志
$log = [
'type' => 'class',
'log_id' => $id,
'message' => date('Y-m-d H:i:s') . "由{$this->account_name}创建",
];
(new OperationLog())->insert($log);
return;
}
$where = [];
$where['is_deleted'] = 0;
$where['top_class'] = $top_class;
$result = Classify::where($where)->find();
if($result){
$addclass = [
'top_class' => $top_class,
'son_class' => $son_class,
'user_id' => $this->admin_id,
];
$id = (new Classify())->insertGetId($addclass);
// 插入操作日志
$log = [
'type' => 'class',
'log_id' => $id,
'message' => date('Y-m-d H:i:s') . "由{$this->account_name}创建",
];
(new OperationLog())->insert($log);
}else{
$addclass = [
'top_class' => $top_class,
'son_class' => $son_class,
'user_id' => $this->admin_id,
];
$id = (new Classify())->insertGetId($addclass);
// 插入操作日志
$log = [
'type' => 'class',
'log_id' => $id,
'message' => date('Y-m-d H:i:s') . "由{$this->account_name}创建",
];
(new OperationLog())->insert($log);
}
}
public function updateStatus($id){
$where = [];
$where['is_deleted'] = 0;
$where['id'] = $id;
$result = Classify::where($where)->find();
if(!$result){
throw new \think\Exception('该分类不存在', 400);
}
if($result->status == 0){
$result->status = 1;
$result->save();
// 插入操作日志
$log = [
'type' => 'class',
'log_id' => $id,
'message' => date('Y-m-d H:i:s') . "由{$this->account_name}停用",
];
(new OperationLog())->insert($log);
}else{
$result->status = 0;
$result->save();
// 插入操作日志
$log = [
'type' => 'class',
'log_id' => $id,
'message' => date('Y-m-d H:i:s') . "由{$this->account_name}启用",
];
(new OperationLog())->insert($log);
}
}
}

845
app/service/Goods/GoodsService.php

@ -0,0 +1,845 @@
<?php
namespace app\service\Goods;
use app\model\AccountRatioDetail;
use app\model\AccountRatioSetting;
use app\model\Cert;
use app\model\Goods;
use app\model\GoodsDetail;
use app\model\GoodsSource;
use app\model\OperationLog;
use app\model\Order;
use app\model\OrderGoodsDetail;
use app\model\OrderGoodsSource;
use app\model\User;
use app\service\BaseService;
use app\service\user\UserService;
use fast\Http;
use Firebase\JWT\JWT;
use Firebase\JWT\Key;
use think\cache\driver\Redis;
use think\facade\Cookie;
use think\facade\Log;
class GoodsService extends BaseService
{
public function __construct()
{
parent::__construct();
$this->redis = new \Redis();
$this->redis->connect('127.0.0.1', 6379);
}
public function addShoppingCar($user_isli, $goods_isli, $use_years){
$user = User::where('user_isli', $user_isli)->find();
if(!$user){
// throw new \think\Exception('没有该用户', 400);
}
$goods = Goods::where('goods_islicode', $goods_isli)->where('is_deleted', 0)->find();
if(!$goods){
throw new \think\Exception('没有该标的', 400);
}
if($goods->goods_status != 1){
throw new \think\Exception('该标的现不在上架中', 400);
}
if($goods->contract_status != 1){
throw new \think\Exception('标的未申请合约关联,不可购买', 400);
}
if($goods->user_islicode == $user_isli){
throw new \think\Exception('您是标的的授权方,不可添加', 400);
}
$order_exists = Order::alias('order')
->join('order_goods_detail detail', 'order.batchcode = detail.batchcode')
->where('order.buy_islicode', $user_isli)
->where('detail.goods_islicode', $goods_isli)
->where('detail.is_deleted', 0)
->where('order.status', '<>', 5)
->value('order.id');
if($order_exists){
throw new \think\Exception('该标的已有订单,添加购物车失败', 400);
}
$goods_detail = GoodsDetail::where('id', $goods->goods_detail_id)->find();
if($goods_detail->stock <= 0 && $goods_detail->goods_entrust == 1){
throw new \think\Exception('标的库存为0,不可添加', 400);
}
if($goods_detail->contractual_period == 3){
if(strtotime($goods->contractual_start_time) > time() || strtotime($goods->contractualtime_end_time) < time()){
throw new \think\Exception('标的委托已结束', 400);
}
}
// 获取购物车
$car = $this->redis->get('car_'.$user_isli);
if(!empty($car)){
$car = unserialize(stripslashes($car));
$goods_islis = array_column($car, 'goods_isli');
if(in_array($goods_isli, $goods_islis)){
throw new \think\Exception('该标的已添加到购物车', 400);
}
$car[] = [
'goods_isli' => $goods_isli,
'use_years' => $use_years,
];
$this->redis->set('car_'.$user_isli, serialize($car));
}else{
$goods = [[
'goods_isli' => $goods_isli,
'use_years' => $use_years,
]];
$this->redis->set('car_'.$user_isli, serialize($goods));
}
}
public function delShoppingCar($user_isli, $goods_isli){
// 获取购物车
$car = $this->redis->get('car_'.$user_isli);
if(!empty($car)){
$car = unserialize(stripslashes($car));
$callback = function($car)use($goods_isli){
if($car['goods_isli'] == $goods_isli){
return false;
}
return true;
};
$car = array_values(array_filter($car, $callback));
if(count($car) >= 1){
$this->redis->set('car_'.$user_isli, serialize($car));
}else{
$this->redis->del('car_'.$user_isli);
}
}
}
public function addCarGoodsCount($user_isli, $goods_isli){
$goods = Goods::where('goods_islicode', $goods_isli)->where('is_deleted', 0)->find();
if(!$goods){
throw new \think\Exception('没有该标的', 400);
}
if($goods->goods_status != 1){
throw new \think\Exception('该标的现不能购买', 400);
}
$goods_detail = GoodsDetail::where('id', $goods->goods_detail_id)->find();
// 获取购物车
$redis = new Redis();
$car = $redis->get('car_'.$user_isli);
if(!empty($car)){
$car = unserialize(stripslashes($car));
$goods_islis = array_column($car, 'goods_isli');
if(!in_array($goods_isli, $goods_islis)){
throw new \think\Exception('该标的未添加到购物车', 400);
}
foreach($car as $key => &$value){
if($value['goods_isli'] != $goods_isli){
continue;
}
$value['goods_num'] += 1;
if($value['goods_num'] > $goods_detail->surplus_inventory){
throw new \think\Exception('超出标的库存上限', 400);
}
}
$redis->set('car_'.$user_isli, serialize($car));
}
}
public function decCarGoodsCount($user_isli, $goods_isli){
$goods = Goods::where('goods_islicode', $goods_isli)->where('is_deleted', 0)->find();
if(!$goods){
throw new \think\Exception('没有该标的', 400);
}
if($goods->goods_status != 1){
throw new \think\Exception('该标的现不能购买', 400);
}
$goods_detail = GoodsDetail::where('id', $goods->goods_detail_id)->find();
// 获取购物车
$redis = new Redis();
$car = $redis->get('car_'.$user_isli);
if(!empty($car)){
$car = unserialize(stripslashes($car));
$goods_islis = array_column($car, 'goods_isli');
if(!in_array($goods_isli, $goods_islis)){
throw new \think\Exception('该标的未添加到购物车', 400);
}
foreach($car as $key => &$value){
if($value['goods_isli'] != $goods_isli){
continue;
}
$value['goods_num'] -= 1;
}
$redis->set('car_'.$user_isli, serialize($car));
}
}
public function getShoppingCar($user_isli){
// 获取购物车
$car = $this->redis->get('car_'.$user_isli);
if(empty($car)){
return [];
}
$car = unserialize(stripslashes($car));
$car = array_values($car);
$result = [];
$ratio_setting = AccountRatioSetting::where('is_deleted', 0)->where('status', 1)->find();
$ratio_detail = AccountRatioDetail::where('setting_id', $ratio_setting->id)->where('role_type', 2)->find();
for($i=count($car)-1; $i >= 0; $i--){
// 商品
$goods = Goods::where('goods_islicode', $car[$i]['goods_isli'])->find();
if(empty($goods) || $goods['goods_status'] != 1){
$goods_isli = $car[$i]['goods_isli'];
$callback = function($car)use($goods_isli){
if($car['goods_isli'] == $goods_isli){
return false;
}
return true;
};
$car = array_filter($car, $callback);
if(count($car) >= 1){
$this->redis->set('car_'.$user_isli, serialize($car));
}else{
$this->redis->del('car_'.$user_isli);
}
continue;
}
// 商品明细
$goods_detail = GoodsDetail::where('id', $goods->goods_detail_id)->find();
$goods_detail->entrust_month = $goods_detail->contractual_period;
$goods_detail->hidden(['id', 'total_inventory', 'surplus_inventory', 'goods_islicode', 'data_json', 'source_json', 'is_deleted']);
$goods['detail'] = $goods_detail->toArray();
$count = $car[$i]['use_years'];
if($goods_detail->goods_entrust == 1){
$count = 1;
}
if($goods_detail->charges_type == 2){
// 付费
if($ratio_detail->calculate == 1){
// 比例
$service_charge = $count * $goods_detail->price * ($ratio_detail->ratio / 100);
}else{
// 固定
$service_charge = $count * $goods_detail->price + $ratio_detail->amount;
}
$total_money = ($count * $goods_detail->price) + $service_charge + $goods_detail->earnest_money;
}else{
// 免费
$service_charge = 0;
$total_money = 0;
}
$goods['service_charge'] = round($service_charge, 2);
$goods['total_money'] = round($total_money, 2);
$goods['goods_price'] = round($count * $goods_detail->price, 2);
if($goods_detail->goods_entrust == 1 || ($goods_detail->charges_type == 1 && $goods_detail->goods_entrust == 2)){
$goods['transaction_count'] = "-";
}else{
$goods['transaction_count'] = $count;
}
// 商品资源
$goods_source = GoodsSource::where('goods_isli_code', $goods->goods_islicode)->where('is_deleted', 0)->select();
$goods_source->hidden(['id', 'goods_isli_code', 'is_deleted']);
$goods['source'] = $goods_source->toArray();
$goods['user'] = (new UserService())->getApiUser($user_isli);
$goods->hidden(['is_deleted', 'updatetime', 'goodsDetail', 'goods_detail_id', 'id', 'user_id']);
$goods = $goods->toArray();
$result[] = array_merge($car[$i], $goods);
}
return $result;
}
public function getTypeGoods($type, $createtime, $goods_type = ""){
$where = [];
// type 类型;1:点击;2:销售;3:推荐
if($type == 1){
$limit = 10;
$where['order'] = "goods.click_count desc";
}elseif($type == 2){
$limit = 10;
$where['order'] = "goods.sale_count desc";
}else{
$limit = 8;
$where['order'] = "goods.recommend_sort desc";
$where['is_recommend'] = 1;
$where['goods.goods_status'] = 1;
}
if(!empty($createtime)){
$where['createtime'] = $createtime;
}
if(!empty($goods_type)){
$where['goodsDetail.goods_type'] = $goods_type;
}
// $where['is_deleted'] = 0;
$goods = new Goods();
$search = $this->buildSearch(['order', 'createtime'], $where);
$res = $goods->list($search, $where, "select", ['goodsDetail', 'withJoin' => true], $limit);
$res = $res->each(function ($item){
$item['user'] = (new UserService())->getApiUser($item['user_islicode']);
$item['entrust_month'] = $item['contractual_period'];
$goods_source = GoodsSource::where('goods_isli_code', $item['goods_islicode'])->where('is_deleted', 0)->select();
$goods_source->hidden(['id', 'goods_isli_code', 'is_deleted']);
// $item['source'] = $goods_source->toArray();
return $item;
});
$res->hidden(['goodsDetail', 'id', 'user_id', 'updatetime', 'is_deleted', 'user_isli']);
$res->toArray();
return $res;
}
public function searchGoods($data){
$where = [];
$where['goods.is_deleted'] = 0;
$goods_islicode = "";
if(!empty($data['entrust_time'])){
$where['createtime'] = $data['entrust_time'];
}
if(!empty($data['record_type'])){
$where['goodsDetail.goods_type'] = $data['record_type'];
}
if(!empty($data['entrust_user_name'])){
$where['username'] = $data['entrust_user_name'];
}
if(!empty($data['authorization'])){
$where['goodsDetail.goods_entrust'] = $data['authorization'];
}
if(!empty($data['pay_type'])){
$where['goodsDetail.charges_type'] = $data['pay_type'];
}
if(!empty($data['entrust_name'])){
$where['goods_field'] = $data['entrust_name'];
}
if(!empty($data['goods_islicode'])){
$goods_islicode = $data['goods_islicode'];
$where['goods_islicode'] = $data['goods_islicode'];
}
if(!empty($data['entrust_islicode'])){
$where['goods.user_islicode'] = $data['entrust_islicode'];
}
if(!empty($data['goods_status'])){
$where['goods_status'] = $data['goods_status'];
}
if(!empty($data['source_type'])){
// 后续改with
$source_arr = GoodsSource::whereLike('source_type', "%".$data['source_type']."%")->where('is_deleted', 0)->field('goods_isli_code')->select()->toArray();
$source_ids = implode(',', array_column($source_arr, 'goods_isli_code'));
if(empty($source_ids)){
$source_ids = '-1';
}
if(isset($where['goods_islicode'])){
$where['goods_islicode'] .= ',' . $source_ids;
}else{
$where['goods_islicode'] = $source_ids;
}
}
switch ($data['order_type'] ?? null){
case 'createtime':
$where['order'] = ' goods.createtime ' . $data['order'] ?? 'desc';
break;
case 'price':
$where['order'] = ' goodsDetail.price ' . $data['order'] ?? 'desc';
break;
default:
$where['order'] = ' goods.id desc';
break;
}
$limit = 20;
if(!empty($data['limit'])){
$limit = $data['limit'];
}
$goods = new Goods();
$search = $this->buildSearch(['username', 'goods_field', 'order', 'goods_islicode', 'createtime', 'goods_status'], $where);
$list = $goods->list($search, $where, $limit, ['goodsDetail', 'withJoin' => true]);
$list = $list->each(function ($item){
$item['user'] = (new UserService())->getApiUser($item['user_islicode']);
$item['entrust_month'] = $item['contractual_period'];
$goods_source = GoodsSource::where('goods_isli_code', $item['goods_islicode'])->where('is_deleted', 0)->select();
$goods_source->hidden(['id', 'goods_isli_code', 'is_deleted']);
$item['source'] = $goods_source->toArray();
return $item;
});
$list->hidden(['goodsDetail', 'is_deleted', 'id', 'user_id', 'goods_detail_id']);
if(!empty($goods_islicode)){
Goods::whereIn('goods_islicode', $goods_islicode)->inc('click_count', 1)->update();
}
return $list->toArray();
}
public function list($goods, $islicode, $entrust_name, $goods_entrust, $goods_type, $data_type, $createtime, $transaction, $show, $order_status, $entrust_status, $page = 1, $limit = 20){
$where = [];
if(!empty($islicode)){
$where['goods.islicode'] = $islicode;
}
if(!empty($goods)){
$where['goods'] = $goods;
}
if(!empty($entrust_name)){
$where['search_user'] = $entrust_name;
}
if(!empty($goods_entrust)){
$where['goodsDetail.goods_entrust'] = $goods_entrust;
}
if(!empty($goods_type)){
$where['goodsDetail.goods_type'] = $goods_type;
}
if(!empty($data_type)){
$where['goods.goods_status'] = $data_type;
}
if(!empty($createtime)){
$where['createtime'] = $createtime;
}
if(!empty($transaction)){
//交易方式
// $where['goodsDetail.'] = $createtime;
$where['goodsDetail.goods_entrust'] = $transaction;
}
if(!empty($show)){
if($show > 1){
$where['goods.is_recommend'] = 0;
}else{
$where['goods.is_recommend'] = $show;
}
}
if(!empty($order_status)){
switch ($order_status){
case 1:
$where['order'] = "goods.sale_count desc";
break;
case 2:
$where['order'] = "goodsDetail.price desc";
break;
case 3:
$where['order'] = "goods.click_count desc";
break;
}
}
if(!empty($entrust_status)){
$where['goods.entrust_status'] = $entrust_status;
}
$search = $this->buildSearch(['goods', 'search_user', 'createtime', 'order'], $where);
$list = (new Goods())->list($search, $where, $limit, ['goodsDetail', 'withJoin' => true]);
$list->each(function ($item){
$item['key'] = $item['goods_islicode'];
return $item;
});
$list->visible(['id', 'createtime', 'goods_islicode', 'key', 'goods_name', 'username', 'user_islicode', 'goods_type', 'goods_status', 'goods_detail_id', 'is_recommend', 'entrust_status']);
$list->hidden(['user', 'goodsDetail']);
$list = $list->toArray();
$start = ($page - 1) * $limit + 1;
$end = $page * $limit;
if($list['total'] < $end){
$end = $list['total'];
}
if($list['total'] < $start){
$start = $end = $list['total'];
}
$list['start'] = $start;
$list['end'] = $end;
return $list;
}
public function goodsDetail($goods_isli){
$goods = Goods::alias('goods')->join('goods_detail detail', 'goods.goods_detail_id = detail.id')
->where('goods.is_deleted', 0)
->where('goods.goods_islicode', $goods_isli)
->field('detail.goods_image,detail.goods_name,goods.goods_islicode,detail.goods_type,detail.goods_entrust,detail.goods_ownership_str,
detail.contractual_period,detail.charges_type,detail.earnest_money,detail.price,goods.contractual_start_time,
goods.contractualtime_end_time,goods.user_islicode,goods.islicode,detail.id as goods_detail_id')
->find();
if(!$goods){
throw new \think\Exception('未查询到该标的', 400);
}
$result = [];
$user_isli = $goods->user_islicode;
$result['userinfo'] = (new UserService())->getApiUser($user_isli);
if(!empty($goods_image)){
$goods->goods_image = $this->getGoodsImageStatus($goods->goods_image, $goods->goods_detail_id);
}
$result['entrust_goods'] = $goods;
$source_gather = GoodsSource::where('goods_isli_code', $goods->goods_islicode)->where('is_deleted', 0)->select()->toArray();
$gather_arr = [];
$oneSource = [];
foreach($source_gather as $val){
$source_data = json_decode($val['source_data'], true);
if($val['datatype'] && !isset($gather_arr[ explode(' ', $val['sourceIdentify'])[1] ])){
$info = [
"name" => $val['source_name'],
"class" => $val['source_type'],
"registerDate" => $source_data['registerDate'],
"identifier" => $source_data['identifier'],
"count" => GoodsSource::where('goods_isli_code', $goods->goods_islicode)->where('datatype', 1)->where('is_deleted', 0)->whereLike('sourceIdentify', "%{$val['sourceIdentify']}%")->count(),
];
$gather_arr[explode(' ', $val['sourceIdentify'])[1]] = $info;
}elseif(!$val['datatype']){
$filesize = getSourceFileSize($source_data['metadataFileSize']);
$info = [
"name" => $val['source_name'],
"class" => $val['source_type'],
"registerDate" => $source_data['registerDate'],
"identifier" => $source_data['identifier'],
"filesize" => $filesize,
"metadataFileFormat" => $source_data['metadataFileFormat']
];
$oneSource[] = $info;
}
}
$result['gather_arr'] = array_values($gather_arr);
$result['oneSource'] = $oneSource;
return $result;
}
public function sourceDetail($identifier, $batchcode = '', $islicode = ''){
if(empty($batchcode)){
$goods_source = GoodsSource::whereLike('sourceIdentify', "%{$identifier}%")->where('goods_isli_code', $islicode)->where('datatype', 1)->select()->toArray();
if(!$goods_source){
throw new \think\Exception('未查询到该标的资源', 400);
}
}else{
$goods_source = OrderGoodsSource::whereLike('sourceIdentify', "%{$identifier}%")->where('batchcode', $batchcode)->where('datatype', 1)->select()->toArray();
if(!$goods_source){
throw new \think\Exception('未查询到该标的资源', 400);
}
}
$result = [];
$gather_arr = [];
$ind = 0;
$repetition = [];
foreach($goods_source as $val){
$source_data = json_decode($val['source_data'], true);
$target_data = json_decode($val['target_data'], true);
if($ind < 1){
$info = [
"source_name" => $val['source_name'],
"otherIdentifiers" => !empty($source_data['otherIdentifiers']) ? $source_data['otherIdentifiers'] : "-",
"identifier" => $source_data['identifier'],
"collectionType" => $source_data['collectionType'],
"serviceType" => $source_data['serviceType'],
"classification" => $source_data['classification'],
"contributors" => $source_data['contributors'],
"copyrightOwner" => $source_data['copyrightOwner'],
"carrier" => $source_data['carrier'],
"registrant" => $source_data['registrant'],
"registerDate" => $source_data['registerDate'],
"repositoryName" => $source_data['repositoryName'],
"dimensions" => !empty($source_data['dimensions']) ? $source_data['dimensions'] : "-",
"quantity" => $source_data['quantity'],
"label" => $source_data['label'],
"description" => $source_data['description'],
"md5Val" => $source_data['md5Val'],
"databaseId" => $source_data['databaseId'],
"edition" => $source_data['edition'],
"collectionCondition" => $source_data['collectionCondition'],
"cover" => $source_data['cover'],
];
$ind++;
}
if(!in_array($target_data['identifier'], $repetition)){
$filesize = getSourceFileSize($target_data['metadataFileSize']);
$gather = [
"target_name" => $val['target_name'],
"identifier" => $target_data['identifier'],
"linkCode" => $val['linkcode'],
"filesize" => $filesize,
"metadataFileFormat" => $target_data['metadataFileFormat'],
"registerDate" => $target_data['registerDate'],
];
if(!empty($batchcode) && !empty($islicode)){
$source_download = OrderGoodsDetail::where('batchcode', $batchcode)->where('goods_islicode', $islicode)->where('is_deleted', 0)->value('source_download');
$source_download = json_decode($source_download, true);
foreach($source_download as $item){
if($item['islicode'] == $val['linkcode']){
$gather['download_status'] = $item['status'];
break;
}
}
}
$gather_arr[ $target_data['serviceType'] ]['source'][] = $gather;
$gather_arr[ $target_data['serviceType'] ]['serviceType'] = $target_data['serviceType'];
$repetition[] = $target_data['identifier'];
}
}
$result['info'] = $info;
$result['gather_arr'] = array_values($gather_arr);
return $result;
}
public function exhibition($type, $limit = 20){
$where = [];
if($type == 1){
$where['goods.platform_products'] = 2;
$order = "goods.platform desc";
}elseif($type == 2){
$where['goods.hot_products'] = 2;
$order = "goods.hot desc";
}else{
$where['goods.hotsale_products'] = 2;
$order = "goods.hotsale desc";
}
$list = (new Goods())->list([], $where, $limit, ['goodsDetail', 'withJoin' => true]);
$list->order($order);
$list->hidden(['goodsDetail']);
return $list->toArray();
}
public function rankingList($type){
$where = [];
$where['goods.is_deleted'] = 0;
if($type == 1){
$limit = 10;
$where['order'] = "goods.click_count desc";
}elseif($type == 2){
$limit = 10;
$where['order'] = "goods.sale_count desc";
}else{
$limit = 8;
$where['order'] = "goods.recommend_sort desc";
$where['goods.goods_status'] = 1;
$where['goods.is_recommend'] = 1;
}
$search = $this->buildSearch(['order'], $where);
$list = (new Goods())->list($search, $where, "select", ["goodsDetail", 'withJoin' => true], $limit);
$index = 1;
$list->each(function ($item) use(&$index){
// $item['username'] = User::where('user_isli', $item['user_islicode'])->value('username');
$item['key'] = $item['goods_islicode'];
$item['id'] = $index;
$index++;
return $item;
});
$list->visible(['id', 'createtime', 'goods_islicode', 'key', 'goods_name', 'goods_type', 'username', 'goods_status', 'recommend_sort']);
$list->hidden(['goodsDetail']);
$list = $list->toArray();
return $list;
}
public function addRanking(array $goods_isli = []){
$count = Goods::where('is_deleted', 0)->where('goods_status', 1)->where('is_recommend', 1)->count();
if($count >= 8){
throw new \think\Exception('推荐数量已8个,无法继续添加', 400);
}
foreach($goods_isli as $val){
if($count >= 8){
throw new \think\Exception('推荐数量已8个,无法继续添加', 400);
}
$goods = Goods::where('goods_islicode', $val)->where('goods_status', 1)->where('is_deleted', 0)->find();
if(!$goods){
continue;
}
if($goods->is_recommend == 1){
continue;
}
$goods->is_recommend = 1;
$goods->save();
$count++;
}
}
public function delRanking(array $goods_isli = []){
foreach($goods_isli as $val){
$goods = Goods::where('goods_islicode', $val)->where('is_deleted', 0)->find();
if(!$goods){
continue;
}
if($goods->is_recommend == 0){
continue;
}
$goods->is_recommend = 0;
$goods->save();
}
}
public function rankingSort($goods_isli, $type){
$list = $this->rankingList(3);
for($i = 0; $i <= count($list) -1; $i++){
if($list[$i]['goods_islicode'] == $goods_isli){
if($type == 1){// 上移
if($i == 0){
break;
}else{
$front_sort = $list[$i-1]['recommend_sort'];
$sort = $list[$i]['recommend_sort'];
Goods::where('goods_islicode', $list[$i]['goods_islicode'])->update(['recommend_sort' => $front_sort]);
Goods::where('goods_islicode', $list[$i-1]['goods_islicode'])->update(['recommend_sort' => $sort]);
}
}else{
if($i == count($list) - 1){
break;
}else{
$behind_sort = $list[$i+1]['recommend_sort'];
$sort = $list[$i]['recommend_sort'];
Goods::where('goods_islicode', $list[$i]['goods_islicode'])->update(['recommend_sort' => $behind_sort]);
Goods::where('goods_islicode', $list[$i+1]['goods_islicode'])->update(['recommend_sort' => $sort]);
}
}
}
}
}
public function manualGetGoods(){
$goodsService = new \app\service\task\GoodsService();
$count = $goodsService->getApiGoods();
return ['count' => $count];
}
public function getGoodsImageStatus($image, $id){
// todo 被请求委托查询 接口
$image_headers = get_headers($image);
if(!strpos($image_headers[0], "200")){
$path = env("app.real_url") . "/dist/api/v2/preview?url={$image}";
$sign = parent::createSign("distribute");
$headers = array(
CURLOPT_HTTPHEADER => array(
"dist_token:{$sign}",
"Content-Type: application/json"
)
);
$res = Http::get($path, [], $headers);
if($res['code'] != 200){
throw new \think\Exception($res['msg'], 400);
}
$res = json_decode($res['data'], true);
if($res['resultCode'] != "00000000"){
throw new \think\Exception($res['resultMsg'], 400);
}
GoodsDetail::where('id', $id)->update(['goods_image' => $res['data']]);
return $res['data'];
}
return $image;
}
public function offGoods($goods_isli, $reason){
$goods = Goods::where('goods_islicode', $goods_isli)->find();
if(!$goods){
throw new \think\Exception("没有该条委托数据", 400);
}
if($goods->goods_status != 1 && $goods->goods_status != 5){
throw new \think\Exception("暂时只支持对已发布/暂停中文化数据进行撤销!", 400);
}
if($goods->apply_out == 1){
throw new \think\Exception("请勿重复提交撤销委托申请!", 400);
}
if($goods->goods_status == 5){
// throw new \think\Exception("该标的有未完成订单,请完成订单或终止订单后再申请!", 400);
}
$url = env("app.entrust_url") . "/consign/exchange/v1/exchangeRevokeEntrust";
$sign = parent::createSign("entrust");
$headers = array(
CURLOPT_HTTPHEADER => array(
"entrust_token:{$sign}"
)
);
$post = [
"revokeReason" => $reason,
"isliCode" => $goods->islicode,
"status" => 3,
];
//todo 请求交易所撤销委托接口 接口1.4
$res = Http::get($url, $post, $headers);
if($res['code'] != 200){
throw new \think\Exception($res['msg'], 400);
}
$res = json_decode($res['data'], true);
if($res['resultCode'] != "00000000"){
throw new \think\Exception($res['resultMsg'], 400);
}
Goods::where('id', $goods->id)->update(['apply_out' => 1]);
$operation_log = [
"type" => "goods",
"log_id" => $goods->id,
"message" => date('Y-m-d H:i:s') . " 由{$this->account_name}申请撤销委托,撤销原因:{$reason}"
];
(new OperationLog())->insert($operation_log);
}
public function whetherOff($goods_isli){
$goods = Goods::where('goods_islicode', $goods_isli)->find();
if(!$goods){
throw new \think\Exception("没有该条委托数据", 400);
}
if($goods->goods_status != 1 && $goods->goods_status != 5){
throw new \think\Exception("暂时只支持对已发布/暂停中文化数据进行撤销!", 400);
}
if($goods->apply_out == 1){
throw new \think\Exception("请勿重复提交撤销委托申请!", 400);
}
}
public function test(){
$detail = OrderGoodsDetail::field('goods_islicode,data_json')->select()->toArray();
foreach($detail as $val){
$json = $val['data_json'];
$json = json_decode($json, true);
$islicode = $json['isliCode'];
OrderGoodsDetail::where('goods_islicode', $val['goods_islicode'])->update(['islicode' => $islicode]);
}
}
}

192
app/service/IndexService.php

@ -0,0 +1,192 @@
<?php
namespace app\service;
use app\model\Goods;
use app\model\Order;
use app\model\OrderGoodsDetail;
use app\service\user\UserService;
class IndexService extends BaseService
{
public function __construct()
{
parent::__construct();
}
public function getSign($type){
$sign = parent::createSign($type);
return $sign;
}
public function homeInfo($leftDate, $rightDate, $sale_ranking, $saleRankingDate){
// 数量统计
$goods_count = Goods::where('is_deleted', 0)->count(); // 商品数量
$awaitpay_count = Order::where('status', 1)->count(); // 待付款数量
$awaitdelivery_count = Order::where('status', 2)->count(); // 待交付数量
$awaitclose_count = Order::where('status', 3)->count(); // 待结算数量
$complete_count = Order::where('status', 4)->count(); // 已完成数量
$close_count = Order::where('status', 5)->count(); // 关闭数量
$yesterday_start = date('Y-m-d 00:00:00', strtotime("-1 day"));
$yesterday_end = date('Y-m-d 23:59:59', strtotime("-1 day"));
// 交易总额 订单总额
$deal_money = Order::whereTime('paymenttime', 'between', [$yesterday_start, $yesterday_end])->where('pay_status', 2)->sum('total_money');
$total_service_charge = Order::whereTime('paymenttime', 'between', [$yesterday_start, $yesterday_end])->where('pay_status', 2)->sum('total_service_charge');
$order_money = $deal_money - $total_service_charge;
// 文化数据数量
$deal_goods_count = Order::alias('order')->join('order_goods_detail detail', 'order.batchcode = detail.batchcode')->where('order.status', 'in', '2,3,4')->whereTime('order.createtime', 'between', [$yesterday_start, $yesterday_end])->where('detail.is_deleted', 0)->count();
// 上架数量
$shelf_count = Goods::whereTime('createtime', 'between', [$yesterday_start, $yesterday_end])->count();
// 委托期满文化数据
$out_count = Goods::whereTime('contractualtime_end_time', 'between', [$yesterday_start, $yesterday_end])->where('goods_status', 4)->count();
//新增订单
$yester_order_count = Order::whereTime('createtime', 'between', [$yesterday_start, $yesterday_end])->where('status', 'in', '2,3,4')->count();
//已完成订单
$yester_complete_count = Order::whereTime('completetime', 'between', [$yesterday_start, $yesterday_end])->where('status', 4)->count();
$right_date = [date('Y-m-01 00:00:00'), date('Y-m-31 23:59:59')];
if($rightDate == "year"){
$right_date = [date('Y-01-01 00:00:00',strtotime('-4 year')), date('Y-12-31 23:59:59')];
}elseif($rightDate == "month"){
$right_date = [date('Y-01-01 00:00:00'), date('Y-12-31 23:59:59')];
}
// 委托方排名
$limit = 10;
// $total_ranking = Goods::where('is_deleted', 0)->whereTime('createtime', 'between', $right_date)->field('sale_count+click_count count')->limit($limit)->order('count desc')->group('user_islicode')->value('count');
// $entrust_ranking = Goods::where('is_deleted', 0)->whereTime('createtime', 'between', $right_date)->field('user_islicode,sale_count+click_count count')->limit($limit)->order('count desc')->group('user_islicode')->select();
$total_ranking = 0;
$entrust_ranking = Goods::where('is_deleted', 0)->whereTime('createtime', 'between', $right_date)->field('user_islicode,sum(sale_count+click_count) count')->limit($limit)->order('count desc')->group('user_islicode')->select();
$entrust_ranking->each(function ($item) use(&$total_ranking){
$total_ranking += $item['count'];
$userService = new UserService();
$user = $userService->getApiUser($item['user_islicode']);
if(isset($user['name'])){
$item['username'] = $user['name'];
}else{
$item['username'] = $item['user_islicode'];
}
return $item;
});
$saleRanking_date = [date('Y-m-01 00:00:00'), date('Y-m-31 23:59:59')];
if($saleRankingDate == "year"){
$saleRanking_date = [date('Y-01-01 00:00:00',strtotime('-4 year')), date('Y-12-31 23:59:59')];
}elseif($saleRankingDate == "month"){
$saleRanking_date = [date('Y-01-01 00:00:00'), date('Y-12-31 23:59:59')];
}
// 委托方排名
$limit = 10;
$total_sale_ranking = OrderGoodsDetail::alias('detail')->join('order order', 'order.batchcode = detail.batchcode')->where('order.status', 'in', '2,3,4')->where('detail.is_deleted', 0)->whereTime('detail.createtime', 'between', $saleRanking_date)->limit($limit)->order('total_money desc')->group('detail.entrust_islicode')->sum('detail.money');
$entrust_sale_ranking = OrderGoodsDetail::alias('detail')->join('order order', 'order.batchcode = detail.batchcode')->where('order.status', 'in', '2,3,4')->where('detail.is_deleted', 0)->whereTime('detail.createtime', 'between', $saleRanking_date)->field('detail.entrust_islicode,sum(detail.money) total_money')->limit($limit)->order('total_money desc')->group('detail.entrust_islicode')->select();
// $entrust_sale_ranking = OrderGoodsDetail::where('is_deleted', 0)->whereTime('createtime', 'between', $saleRanking_date)->field('entrust_islicode,sum(money) total_money')->limit($limit)->order('total_money desc')->group('entrust_islicode')->select();
$entrust_sale_ranking->each(function ($item){
$userService = new UserService();
$user = $userService->getApiUser($item['entrust_islicode']);
if(isset($user['name'])){
$item['username'] = $user['name'];
}else{
$item['username'] = $item['entrust_islicode'];
}
$item['total_money'] = $this->doFormatMoney($item['total_money']);
return $item;
});
$tree_map = [];
$lables = [];
if($leftDate == "year"){
// 近五年
for($i = 4;$i >= 0;$i--){
$year = date('Y',strtotime('-'.$i.' year'));
$money = $this->getDateMoney(date("{$year}-01-01 00:00:00"), date("{$year}-12-31 23:59:59"));
$tree_map[0]['data'][] = $money[0];
$tree_map[1]['data'][] = $money[1];
$lables[] = "{$year}年";
}
}elseif($leftDate == "month"){
// 12月
for($i = 1;$i <= 12;$i++){
$money = $this->getDateMoney(date("Y-{$i}-01 00:00:00"), date("Y-{$i}-31 23:59:59"));
$tree_map[0]['data'][] = $money[0];
$tree_map[1]['data'][] = $money[1];
$lables[] = "{$i}月";
}
}else{
// 30天
for($i = 1;$i <= date('t');$i++){
$money = $this->getDateMoney(date("Y-m-{$i} 00:00:00"), date("Y-m-{$i} 23:59:59"));
$tree_map[0]['data'][] = $money[0];
$tree_map[1]['data'][] = $money[1];
$lables[] = "{$i}";
}
}
$tree_map[0]['label'] = "订单金额总额";
$tree_map[1]['label'] = "标的价款总额";
$result = [];
$result['goods_count'] = $goods_count;
$result['awaitpay_count'] = $awaitpay_count;
$result['awaitdelivery_count'] = $awaitdelivery_count;
$result['awaitclose_count'] = $awaitclose_count;
$result['complete_count'] = $complete_count;
$result['close_count'] = $close_count;
$result['deal_money'] = $this->doFormatMoney($deal_money);
$result['order_money'] = $this->doFormatMoney($order_money);
$result['deal_goods_count'] = $deal_goods_count;
$result['shelf_count'] = $shelf_count;
$result['out_count'] = $out_count;
$result['yester_order_count'] = $yester_order_count;
$result['yester_complete_count'] = $yester_complete_count;
$result['entrust_ranking'] = $entrust_ranking->toArray();
$result['entrust_sale_ranking'] = $entrust_sale_ranking->toArray();
$result['treeMap'] = $tree_map;
$result['label'] = $lables;
$result['total_sale_ranking'] = $total_sale_ranking;
$result['total_ranking'] = $total_ranking;
return $result;
}
function doFormatMoney($money)
{
$float_money = "";
if(strpos($money, '.') !== false){
$money_arr = explode('.', $money);
$money = $money_arr[0];
$float_money = '.'.$money_arr[1];
}
$tmp_money = strrev($money);
$format_money = "";
for ($i = 3; $i < strlen($money); $i += 3) {
$format_money .= substr($tmp_money, 0, 3) . ",";
$tmp_money = substr($tmp_money, 3);
}
$format_money .= $tmp_money;
$format_money = strrev($format_money);
$format_money .= $float_money;
return $format_money;
}
public function getDateMoney($start, $end){
$deal_money = Order::whereTime('paymenttime', 'between', [$start, $end])->where('pay_status', 2)->sum('total_money');
$total_service_charge = Order::whereTime('paymenttime', 'between', [$start, $end])->where('pay_status', 2)->sum('total_service_charge');
$order_money = $deal_money - $total_service_charge;
return [
round($deal_money, 2),
round($order_money, 2)
];
}
}

25
app/service/LogService.php

@ -0,0 +1,25 @@
<?php
namespace app\service;
use app\model\OperationLog;
class LogService extends BaseService
{
public function __construct()
{
parent::__construct();
}
public function getLog($log_id, $type){
$where = [];
$where['type'] = $type;
$where['log_id'] = $log_id;
$result = (new OperationLog())->where($where)->select()->toArray();
return $result;
}
}

59
app/service/SignService.php

@ -0,0 +1,59 @@
<?php
namespace app\service;
use app\model\Channel;
use think\exception\HttpResponseException;
class SignService extends BaseService
{
public function __construct()
{
parent::__construct();
}
// 验签
public function checkSign(array $post = [], string $sign = ""){
$appkey = "";
$timestamp = 0;
if(isset($post['appkey']) && !empty($post['appkey'])){
$appkey = $post['appkey'];
}else{
throw new HttpResponseException(_error('缺少appkey', 400));
}
if(strlen($appkey) != 16){
throw new HttpResponseException(_error('错误appkey', 400));
}
if(isset($post['timestamp']) && !empty($post['timestamp'])){
if($post['timestamp'] < time()-150 || $post['timestamp'] > time()+150){
throw new HttpResponseException(_error('请求已过期', 400));
}
$timestamp = $post['timestamp'];
unset($post['timestamp']);
}else{
throw new HttpResponseException(_error('缺少timestamp', 400));
}
if (empty($sign)){
throw new HttpResponseException(_error('缺少sign', 400));
}
// 获取token
$channel = Channel::where('appkey', $appkey)->where('status', 1)->where('is_deleted', 0)->find();
if(!$channel){
throw new HttpResponseException(_error('缺少appkey', 400));
}
$str = "appkey={$appkey}&timestamp={$timestamp}&token=".$channel['token'];
if($sign != md5($str)){
throw new HttpResponseException(_error('签名错误', 400));
}
return true;
}
}

92
app/service/UploadService.php

@ -0,0 +1,92 @@
<?php
namespace app\service;
use think\facade\Config;
class UploadService extends BaseService
{
public function __construct() {
parent::__construct();
}
/**
* 上传文件
* @param mixed $filename 上传文件
* @param array|string[] $limitSuffix 限制后缀,默认允许所有后缀
* @param int $size 大小限制默认10m;单位b
* @return array
*/
public function uploadpic($filename, array $limitSuffix = ['*'], int $size = 0){
$path = "/pic";
if(is_string($filename)){
$file = request()->file($filename);
}else{
$file = $filename;
}
if(empty($file)){
throw new \think\Exception('没有上传的文件', 400);
}
$upload = config('upload');
$size = $size ?: ((int)$upload['maxsize'] * 1024 * 1024);
$fileInfo = [];
$fileInfo['name'] = $file->getOriginalName();
$fileInfo['type'] = $file->getOriginalMime();
$fileInfo['tmp_name'] = $file->getPathname();
$fileInfo['size'] = $file->getSize();
if($fileInfo['size'] > $size){
throw new \think\Exception('没有上传的文件', 400);
}
$suffix = strtolower(pathinfo($fileInfo['name'], PATHINFO_EXTENSION));
$suffix = $suffix && preg_match('/^[a-zA-Z0-9]+$/', $suffix) ? $suffix : 'file';
$mimetypeArr = explode(',', strtolower($upload['mimetype']));
$typeArr = explode('/', $fileInfo['type']);
if ($limitSuffix != ['*'] && !in_array($suffix, $limitSuffix)){
throw new \think\Exception('该文件类型不可上传', 400);
}
//禁止上传PHP和HTML文件
if (in_array($fileInfo['type'], ['text/x-php', 'text/html']) || in_array($suffix, ['php', 'html', 'htm'])) {
throw new \think\Exception('该文件类型不可上传', 400);
}
//验证文件后缀
if ($upload['mimetype'] !== '*' &&
(!in_array($suffix, $mimetypeArr) ||
(stripos($upload['mimetype'], $typeArr[1]) !== false &&
(!in_array($typeArr[1], $mimetypeArr))))) {
throw new \think\Exception('该文件类型不可上传', 400);
}
//验证是否为图片文件
$imagewidth = $imageheight = 0;
if (in_array($typeArr[1], explode('/', $fileInfo['type']))) {
$imgInfo = getimagesize($fileInfo['tmp_name']);
if (!$imgInfo || !isset($imgInfo[0]) || !isset($imgInfo[1])) {
throw new \think\Exception('不是图片文件', 400);
}
$imagewidth = isset($imgInfo[0]) ? $imgInfo[0] : $imagewidth;
$imageheight = isset($imgInfo[1]) ? $imgInfo[1] : $imageheight;
}
//上传图片
$savename = false;
try {
$savename = upload_file($file, 'public', $path); //保存用;存数据库不需要拼接Config::get('app.app_host')
$showname = trim(Config::get('app.cdnurl'), '/') . $savename; //展示用;
} catch (\Exception $e) {
$this->log->info($e->getMessage());
throw new \think\Exception('上传失败', 400);
}
return ['img' => $savename, 'show_img' => $showname];
}
}

30
app/service/clearing/ClearingService.php

@ -0,0 +1,30 @@
<?php
namespace app\service\clearing;
use app\service\BaseService;
class ClearingService extends BaseService
{
public function __construct()
{
parent::__construct();
}
public function bill(){
}
public function ratio(){
}
public function pay(){
}
}

29
app/service/culture/ClassifyService.php

@ -0,0 +1,29 @@
<?php
namespace app\service\culture;
use app\service\BaseService;
class ClassifyService extends BaseService
{
public function __construct()
{
parent::__construct();
}
public function infoList($marking){
}
public function category($createUser){
}
public function layout(){
}
}

301
app/service/order/AccountCloseService.php

@ -0,0 +1,301 @@
<?php
namespace app\service\order;
use app\model\AccountRatioDetail;
use app\model\AccountRatioSetting;
use app\model\Admin;
use app\model\Order;
use app\model\OrderGoodsDetail;
use app\model\OrderUser;
use app\model\PaySetting;
use app\model\UserAccountBill;
use app\service\BaseService;
use app\service\user\UserService;
class AccountCloseService extends BaseService
{
public function __construct()
{
parent::__construct();
}
public function getPaySetting(){
$setting = PaySetting::where('id', 1)->field('alipay,wechat_pay,ebank_pay')->find();
if(!$setting){
$setting = [
"alipay" => 0,
"wechat_pay" => 0,
"ebank_pay" => 0,
];
}
return $setting;
}
public function setPaySetting($alipay, $wechat_pay, $ebank_pay){
$setting = [
"alipay" => $alipay,
"wechat_pay" => $wechat_pay,
"ebank_pay" => $ebank_pay,
];
if(PaySetting::where('id', 1)->value('id')){
$flag = PaySetting::where('id', 1)->update($setting);
}else{
$flag = (new PaySetting())->insert($setting);
}
return $flag;
}
public function ratioList($rule_name, $user_id, $status, $createtime, $page, $limit){
$where = [];
$where['is_deleted'] = 0;
if(!empty($rule_name)){
$where['rule_name'] = $rule_name;
}
if(!empty($user_id)){
$where['user_id'] = $user_id;
}
if($status !== ""){
$where['status'] = $status;
}
if(!empty($createtime)){
$where['createtime'] = $createtime;
}
$search = $this->buildSearch(['rule_name', 'createtime', 'order'], $where);
$list = (new AccountRatioSetting())->list($search, $where, $limit, []);
$list->each(function ($item){
$item['username'] = Admin::where('id', $item['user_id'])->value('account_name');
return $item;
});
$list = $list->toArray();
$start = ($page - 1) * $limit + 1;
$end = $page * $limit;
if($list['total'] < $end){
$end = $list['total'];
}
if($list['total'] < $start){
$start = $end = $list['total'];
}
$list['start'] = $start;
$list['end'] = $end;
return $list;
}
public function ratioDetail($id){
$result = AccountRatioDetail::where('setting_id', $id)->select();
if(!$result){
throw new \think\Exception('未查询到该设置详情', 400);
}
return $result->toArray();
}
public function setRatio($ratio = [], $rule_name){
$setting = [
'user_id' => $this->admin_id,
'rule_name' => $rule_name
];
$id = (new AccountRatioSetting())->insertGetId($setting);
$sum_ration = 0;
foreach($ratio as $item){
if($item['role_type'] == 1 || $item['role_type'] == 3){
$sum_ration += $item['ratio'];
}
}
if($sum_ration != 100){
throw new \think\Exception('委托方与平台方比例之和未等于100,创建失败', 400);
}
foreach($ratio as $value){
$res = [
'role_type' => $value['role_type'],
'cost_type' => $value['cost_type'],
'calculate' => $value['calculate'],
'amount' => $value['amount'],
'ratio' => $value['ratio'],
'setting_id' => $id,
];
(new AccountRatioDetail())->insert($res);
}
}
public function ratioStatus($id){
$setting = AccountRatioSetting::where('id', $id)->where('is_deleted', 0)->find();
if(!$setting){
throw new \think\Exception('未查询到该设置', 400);
}
if($setting->status == 0){
AccountRatioSetting::where('status', 1)->where('is_deleted', 0)->update(['status' => 0]);
$setting->status = 1;
$setting->save();
}else{
throw new \think\Exception('修改状态失败,至少要设置一条分账比例!', 400);
}
}
public function closeList($user_name, $close_account, $bank_account, $status, $type, $limit, $page){
$result = (new OrderUser())->alias('user')->join('order o', 'o.batchcode = user.batchcode')->where('user.id', 'in', function ($query) {
$query->table("order_user")->field('max(id)')->group('islicode')->select();
})->where(function ($query) use($user_name, $bank_account, $status, $type){
if($type == 2){
$query->where('user.id', -1);
}
if($user_name){
$query->whereLike('user.name', "%{$user_name}%", 'or')->whereLike('user.islicode', "%{$user_name}%", 'or');
}
if($bank_account){
$query->whereLike('user.publicAccount', "%{$bank_account}%");
}
if($status){
if($status == 1){
$query->where('o.close_status', 1);
}else{
$query->whereIn('o.close_status', '2,3,4,5');
}
}
})->field('user.islicode,user.name,user.publicAccount,user.bankName,user.userType,o.close_status')->group('islicode')->order('user.id', 'desc')->paginate($limit)->toArray();
$start = ($page - 1) * $limit + 1;
$end = $page * $limit;
if($result['total'] < $end){
$end = $result['total'];
}
if($result['total'] < $start){
$start = $end = $result['total'];
}
$result['start'] = $start;
$result['end'] = $end;
return $result;
}
public function getCloseAccountInfo($user_isli){
$userinfo = (new UserService())->getUserInfo($user_isli);
return $userinfo;
}
public function getBillDetail($user_isli, $batchcode, $status, $page, $limit){
$where = [];
$where['bill.user_isli'] = $user_isli;
if(!empty($batchcode)){
$where['bill.batchcode'] = $batchcode;
}
$batchcodes = "";
if(!empty($status)){
if($status != 6){
$batchcodes = OrderGoodsDetail::where('close_status', $status)->where('entrust_islicode', $user_isli)->where('is_deleted', 0)->field('batchcode')->select()->toArray();
if($batchcodes){
$batchcodes = implode(',', array_column($batchcodes, 'batchcode'));
}else{
$batchcodes = -1;
}
}else{
$batchcodes = Order::where('buy_islicode', $user_isli)->where('status', 'in', '2,3,4')->field('batchcode')->select()->toArray();
if($batchcodes){
$batchcodes = implode(',', array_column($batchcodes, 'batchcode'));
}else{
$batchcodes = -1;
}
}
}
$income = UserAccountBill::alias('bill')->join('order order', 'bill.batchcode = order.batchcode')->where(function ($query) use($batchcodes){
if(!empty($batchcodes)){
$query->where('bill.batchcode', 'in', $batchcodes);
}
})->where(function ($query){
$query->whereOr('bill.thatday_sale_money', '>', 0)->whereOr('bill.thatday_buy_money', '>', 0);
})->where($where)->where('order.status', 'in', '2,3,4')->sum('thatday_sale_money');
$disburse = UserAccountBill::alias('bill')->join('order order', 'bill.batchcode = order.batchcode')->where(function ($query) use($batchcodes){
if(!empty($batchcodes)){
$query->where('bill.batchcode', 'in', $batchcodes);
}
})->where(function ($query){
$query->whereOr('bill.thatday_sale_money', '>', 0)->whereOr('bill.thatday_buy_money', '>', 0);
})->where($where)->where('order.status', 'in', '2,3,4')->sum('thatday_buy_money');
$list = UserAccountBill::alias('bill')->join('order order', 'bill.batchcode = order.batchcode')->where(function ($query) use($batchcodes){
if(!empty($batchcodes)){
$query->where('bill.batchcode', 'in', $batchcodes);
}
})->where(function ($query){
$query->whereOr('bill.thatday_sale_money', '>', 0)->whereOr('bill.thatday_buy_money', '>', 0);
})->where($where)->where('order.status', 'in', '2,3,4')->field('bill.*,order.createtime as order_createtime,order.completetime as order_completetime')->order('order_createtime', 'desc')->paginate($limit);
$list->each(function ($item) use(&$income, &$disburse){
if(empty($item['order_completetime'])){
$item['order_completetime'] = "-";
}
$item['callback_msg'] = OrderGoodsDetail::where('batchcode', $item['batchcode'])->where('is_deleted', 0)->where('entrust_islicode', $item['user_isli'])->value('callback_msg');
if(empty($item['callback_msg'])){
$item['callback_msg'] = '-';
}
$order_user = OrderUser::where('batchcode', $item['batchcode'])->where('islicode', $item['user_isli'])->find();
$item['order_user'] = $order_user->toArray();
if(Order::where('batchcode', $item['batchcode'])->where('buy_islicode', $item['user_isli'])->value('id')){
$item['close_status'] = 6;
$item['order_completetime'] = Order::where('batchcode', $item['batchcode'])->where('buy_islicode', $item['user_isli'])->value('paymenttime');
$item['callback_msg'] = Order::where('batchcode', $item['batchcode'])->where('buy_islicode', $item['user_isli'])->value('payid');
}else{
$item['close_status'] = OrderGoodsDetail::where('batchcode', $item['batchcode'])->where('entrust_islicode', $item['user_isli'])->where('is_deleted', 0)->value('close_status');
if($item['close_status'] == 5){
$item['callback_msg'] = OrderGoodsDetail::where('batchcode', $item['batchcode'])->where('entrust_islicode', $item['user_isli'])->where('is_deleted', 0)->value('close_serial_number');
}elseif($item['close_status'] == 2){
$item['callback_msg'] = '受理成功';
}
}
// $disburse += Order::where('buy_islicode', $item['user_isli'])->where('pay_status', 2)->sum('total_money');
// $disburse += $item['thatday_buy_money'];
// $income += $item['thatday_sale_money'];
// $money = OrderGoodsDetail::alias('detail')->join('order order', 'order.batchcode = detail.batchcode')
// ->where('detail.entrust_islicode', $item['user_isli'])
// ->where('detail.is_deleted', 0)
// ->where('order.pay_status', 2)->sum('detail.money');
// $income += $money;
return $item;
});
$list = $list->toArray();
$start = ($page - 1) * $limit + 1;
$end = $page * $limit;
if($list['total'] < $end){
$end = $list['total'];
}
if($list['total'] < $start){
$start = $end = $list['total'];
}
$list['start'] = $start;
$list['end'] = $end;
$list['income'] = round($income, 2);
$list['disburse'] = round($disburse, 2);
return $list;
}
}

1748
app/service/order/OrderService.php

File diff suppressed because it is too large

80
app/service/pay/ApiHelperoneService.php

@ -0,0 +1,80 @@
<?php
namespace app\service\pay;
use app\api\controller\Base;
require_once("security.php");
$format = "json";
$version = "2.0";
$token_session = "";
$token_secretkey = "";
$open_api_url = "";
$appid = "";
class ApiHelperoneService extends Base{
public function init($openapiurl,$appid,$session,$secretkey){
// $appid="910000198";
// $secretkey="gRAZZKiNw0UbTuF9";
$GLOBALS['appid']=$appid;
$GLOBALS['open_api_url']=$openapiurl;
$GLOBALS['token_session'] = $session;
$GLOBALS['token_secretkey'] = $secretkey;
$GLOBALS['format'] = "json";
$GLOBALS['version'] = "2.0";
//echo "".$GLOBALS['appid']."";
/**
$result = $this->getToken($openapiurl,$appid,$secretkey,$loginname,$loginpwd);
echo "".$result."<br/>";
$obj=json_decode($result);
if($obj->ret==0){
$data=$obj->data;
echo "session:".$data->session."<br/>";
echo "secretkey:".$data->secretkey."<br/>";
$GLOBALS['token_session'] = $data->session;
$GLOBALS['token_secretkey']= $data->secretkey;
}else{
return false;
}
*/
return true;
}
//获取系统调用的权限
public function getToken($openapiurl,$appid,$secretkey,$loginname,$loginpwd){
$aes=new security();
$method="qdpay.oauth.com.token.get";
$encryptdata = $aes->encrypt($secretkey,$secretkey,"{\"loginname\":\"".$loginname ."\",\"loginpwd\":\"".$loginpwd."\"}");
$time=time();
$signstr = md5($secretkey.$appid.$encryptdata.$GLOBALS['format'].$method.$time.$GLOBALS['version'].$secretkey);
$getdata = "appid=".$appid."&method=".$method."&format=".$GLOBALS['format']."&data=".$encryptdata."&v=".$GLOBALS['version']."&amp;timestamp=".$time."&sign=".$signstr;
$url =$openapiurl."?".$getdata;
//echo $url;
$httphelper=new HttpHelper();
$result=$httphelper->getSSLHttp($url);
return $result;
}
//调用其它方法
public function methodInvoke($method,$data){
$aes=new security();
$encryptdata = $aes->encrypt($GLOBALS['token_secretkey'],$GLOBALS['token_secretkey'],$data);
$time=time();
//$signstr = md5($appid.$method.$format.$encryptdata.$v.$time.$session.$appkey);
$signstr = md5($GLOBALS['token_secretkey'].$GLOBALS['appid'].$encryptdata.$GLOBALS['format'].$method.$GLOBALS['token_session'].$time.$GLOBALS['version'].$GLOBALS['token_secretkey']);
$getdata = "method=".$method."&appid=".$GLOBALS['appid']."&format=".$GLOBALS['format']."&data=".$encryptdata."&v=".$GLOBALS['version']."&timestamp=".$time."&session=".$GLOBALS['token_session']."&sign=" .$signstr;
$url = $GLOBALS['open_api_url']."?".$getdata;
// echo $url;
$httphelper=new HttpHelper();
$result=$httphelper->getSSLHttp($url);
return $result;
}
}
?>

110
app/service/pay/InvoiceManagementService.php

@ -0,0 +1,110 @@
<?php
/**
* 发票管理服务
*/
namespace app\service\pay;
use app\model\Order;
use app\model\OrderGoodsDetail;
use app\model\OrderGoodsSource;
use app\model\User;
use app\service\BaseService;
use fast\Http;
use Firebase\JWT\JWT;
use Firebase\JWT\Key;
use think\facade\Db;
use app\service\pay\ApiHelperoneService;
use app\admin\controller\Base;
use think\facade\Cache;
class InvoiceManagementService extends BaseService
{
public function __construct()
{
parent::__construct();
}
/**
* Notes: 发票申请接口
* User: torsenli
* Date: 2022/4/12
* Time: 18:04
*/
public function RespondToInvoices($data)
{
header('content-type:application/json;charset=utf8');
$openapiurl = "https://demo.szhtxx.cn:18182/apiv2/api/invoice/invoiceinfo/billing";
//请求数据
// $data = [
// 'buyerName' => '深圳亿起融网络科技有限公司', //购买方名称
// 'buyerType' => '01', //购买方类型01:企业
// 'buyerTaxNo' => '91440300326621149M', //购买方税号
// 'totalAmountTax' => '100.00', //总金额含税
// 'manualOrderDetails' => [[
// 'amount' => '100.00', //金额
// 'invoiceNature' => '0', //0:正常 1:折扣 2:被折扣
// 'itemName' => '山海经', //商品名称
// 'itemTaxCode' => '3049900000000000000', //商品税号
// 'taxIncluded' => '1', //1:含税0:不含税
// 'taxRate' => '0.06',//税率
// 'yhzcbs' => '0',//优惠政策标识
// ]],
// ];
$headers = array(
CURLOPT_HTTPHEADER => array(
'Content-Type:application/json;charset=UTF-8',
'Accept:application/json;charset=UTF-8',
'Authorization:bearer ' . $this->InvoiceRequestToken(),
'taxNo:440301999999980',
'machineNo:2',
),
);
$data = json_encode($data);
// $header = json_encode($header);
$aes = new security();
$httphelper = new HttpHelper();
// $result = $httphelper->send_post_info($openapiurl, $data, $header);
$result = Http::post($openapiurl, $data, $headers);
return json_decode($result['data'], true);
}
/**
* Notes:发票申请token
* User: torsenli
* Date: 2022/4/8
* Time: 18:05
*/
public function InvoiceRequestToken()
{
// header('content-type:application/json;charset=utf8');
header('content-type:application/json;charset=utf8');
$token = Cache::get('IRToken');
if (!$token) {
$openapiurl = "https://demo.szhtxx.cn:18182/apiv2/oauth/token";
$data = [
'client_id' => 'apiuser',
'client_secret' => 'secret',
'grant_type' => 'password',
'username' => '440301999999980',
'password' => '123456',
];
$aes = new security();
$httphelper = new HttpHelper();
$result = $httphelper->send_post($openapiurl, $data);
$val = json_decode($result, true);
Cache::set('IRToken', $val['access_token'], 3600);
return $val['access_token'];
} else {
return $token;
}
}
}

676
app/service/pay/PayService.php

@ -0,0 +1,676 @@
<?php
namespace app\service\pay;
use app\model\AccountRatioDetail;
use app\model\AccountRatioSetting;
use app\model\Goods;
use app\model\Order;
use app\model\OrderGoodsDetail;
use app\model\OrderGoodsSource;
use app\model\OrderUser;
use app\model\Ticket;
use app\model\User;
use app\service\BaseService;
use app\service\order\OrderService;
use fast\Http;
use Firebase\JWT\JWT;
use Firebase\JWT\Key;
use think\Validate;
class PayService extends BaseService
{
public function __construct()
{
parent::__construct();
if(!file_exists("./order/")){
mkdir("./order/");
}
if(!file_exists("./order/".date("Ymd"))){
mkdir("./order/".date("Ymd"));
mkdir("./order/".date("Ymd", strtotime("+1 day")));
}
}
public function payment($batchcode){
}
public function payCallback($data){
header('content-type:application/json;charset=utf8');
$json = json_decode($data, true);
if($json['Method'] == "bankwallet_batch_transfer_bank_report"){
$orderService = new OrderService();
$orderService->orderCloseCallback($data);
return;
}
$openapiurl="https://t.masget.com/openapi/rest";
$session = "iba3t9dqln8etmcaceq1xtqr7urevia1";
$appid="910000198";
$secretkey="gRAZZKiNw0UbTuF9";
$api=new ApiHelperoneService();
$api->init($openapiurl,$appid,$session,$secretkey);
$security = new security();
$decrypted = $security->decrypt($GLOBALS['token_secretkey'], $GLOBALS['token_secretkey'], $json['Data']);
$pattern = "/\\x00/";
$decrypted = preg_replace($pattern, "", $decrypted);
$result = json_decode($decrypted, true);
$batchcode = $result['ordernumber'];
$this->orderlog->info("{$batchcode}订单支付回调", $result);
$order = Order::where('batchcode', $batchcode)->find();
if(!$order){
return;
}
if($order->status != 1 || $order->pay_status == 2){
return;
}
$goodss = OrderGoodsDetail::where('batchcode', $batchcode)->where('is_deleted', 0)->field('goods_islicode')->select()->toArray();
$goodss = array_column($goodss, 'goods_islicode');
Goods::whereIn('goods_islicode', $goodss)->inc('sale_count')->update();
// $proportion = "";
// $transaction_islicode = $this->applyContractCode($order->goods_islicode,$order->buy_islicode, $order->entrust_islicode, $order->transaction_count, $order->use_years, $proportion);
// $order->transaction_islicode = $transaction_islicode;
$order->status = 2;
$order->pay_status = 2;
$order->paymenttime = date('Y-m-d H:i:s');
$order->payid = $result['payorderid'];
$order->save();
$this->payFinishOperate($batchcode);
$this->invoiceBuyOperate($batchcode);
$this->invoiceSellerOperate($batchcode);
}
public function test(){
// $this->payFinishOperate("1648890413394325");
// $this->payFinishOperate("1648539998374081");
// $this->payFinishOperate("1648631147826352");
// return $this->payFinishOperate("1650960843614890");
$this->invoiceBuyOperate("1651135887697535");
$this->invoiceSellerOperate("1651135887697535");
// $this->invoiceOperate('123');
}
public function payComplete(){
$order = Order::where('status', 2)->whereTime('paymenttime', 'between', [date('Y-m-d H:i:s', strtotime("-7 day")), date("Y-m-d H:i:s")])->field('batchcode')->select()->toArray();
foreach($order as $data){
$this->payFinishOperate($data['batchcode']);
}
}
public function payFinishOperate($batchcode){
$order = Order::where('batchcode', $batchcode)->find();
if(!$order){
// throw new \think\Exception('没有该订单', 400);
return;
}
if($order->pay_status != 2){
// throw new \think\Exception('订单还未支付成功', 400);
// return;
}
$status = $order->pay_status;
$close_status = Order::where('batchcode', $batchcode)->value('close_status');
$type = Order::where('batchcode', $batchcode)->value('type');
$buy_username = OrderUser::where('islicode', $order->buy_islicode)->where('batchcode', $batchcode)->value('name');
// 申请合约关联编码
$buy_islicode = $order->buy_islicode;
// $buy_islicode = "999998-000000000023-0";
$paytime = $order->paymenttime;
$synchInfo = [];
$contractcode_arr = [];
$order_detail = OrderGoodsDetail::where('batchcode', $batchcode)->where('is_deleted', 0)->select();
$order_detail->each(function ($item) use($buy_islicode, $paytime, $close_status, $type, $buy_username, &$synchInfo, &$contractcode_arr, $status){
$goods_islicode = $item['goods_islicode'];
if($item['goods_entrust'] == 1 || $item['charges_type'] == 1){
$date = "永久";
$transaction_count = 1;
}else{
$date = date('Y-m-d', strtotime("+".$item['transaction_count']." year", strtotime($paytime)));
$transaction_count = $item['transaction_count'];
}
if($item['money'] > 0 && $status != 2){
return $item;
}
if(empty($item['contract_code'])){
$contractcode = $this->applyContractCode($item['sourcedata_islicode'], $buy_islicode, $transaction_count, $date, $item['batchcode']);
}else{
$contractcode = $item['contract_code'];
}
$contractcode_arr[$item['id']] = $contractcode;
if(!empty($contractcode)){
OrderGoodsDetail::where('id', $item['id'])->where('is_deleted', 0)->update(['contract_code' => $contractcode]);
$synchInfo[] = [
"userId" => $buy_islicode,
"requestIsliFlag" => env('isli.channel_isli'),
"goodsIslicode" => $item['goods_islicode'],
"goodsName" => $item['goods_name'],
"orderIslicode" => $contractcode,
"batchcode" => $item['batchcode'],
"chargesType" => $item['money'],
"entrustMonth" => ($item['contractual_period'] == 1 ? "永久" : ($item['contractual_period'] == 2 ? "单次" : "周期")),
"goodsEntrust" => ($item['goods_entrust'] == 1 ? "转让" : "许可"),
"goodsOwnership" => $item['goods_ownership_str'],
"goodsType" => ($item['goods_type'] == 1 ? "文化资源数据" : "文化数字内容"),
"payStatus" => 1,
"closeStatus" => ( $close_status - 1 ),
"transactionCount" => $item['transaction_count'],
"type" => ( $type == 1 ? "委托订单" : ($type == 2 ? "认证订单" : "服务订单") ),
"buyUsername" => $buy_username,
"entrustIslicode" => $item['entrust_islicode'],
"entrustUsername" => OrderUser::where('islicode', $item['entrust_islicode'])->where('batchcode', $item['batchcode'])->value('name')
];
}
});
if(count($contractcode_arr) <= 0){
return;
}
$order_detail = $order_detail->toArray();
// $path = env("app.tianlang_entrust_url") . "/api/v1/synchInfo";
// http://45.251.21.170:51317/dist
//todo 请求交易结算平台同步订单数据到分发平台获取下载地址 接口3.1
$path = env("app.real_url") . "/dist/api/v1/synchInfo";
$sign = parent::createSign("distribute");
$headers = array(
CURLOPT_HTTPHEADER => array(
"dist_token:{$sign}",
"Content-Type: application/json"
)
);
$result = Http::post($path, json_encode($synchInfo), $headers);
$this->orderlog->info("{$batchcode}订单获取下载地址", $result);
if($result['code'] != 200){
// throw new \think\Exception($result['msg'], 400);
foreach($order_detail as $detail) {
$source_url_arr = json_decode($detail['source_download'], true);
if(empty($source_url_arr)){
$source_url_arr = [];
}
for($i=0;$i < count($source_url_arr);$i++) {
if($source_url_arr[$i]['status'] != 4){
$source_url_arr[$i]['status'] = 2;
}
}
$source_url_arr = json_encode($source_url_arr);
OrderGoodsDetail::where('id', $detail['id'])->where('is_deleted', 0)->update(['source_download' => $source_url_arr]);
}
return;
}
$result = json_decode($result['data'], true);
if($result['resultCode'] != "00000000"){
// throw new \think\Exception($result['resultMsg'], 400);
foreach($order_detail as $detail) {
$source_url_arr = json_decode($detail['source_download'], true);
if(empty($source_url_arr)){
$source_url_arr = [];
}
for($i=0;$i < count($source_url_arr);$i++) {
if($source_url_arr[$i]['status'] != 4){
$source_url_arr[$i]['status'] = 2;
}
}
$source_url_arr = json_encode($source_url_arr);
OrderGoodsDetail::where('id', $detail['id'])->where('is_deleted', 0)->update(['source_download' => $source_url_arr]);
}
return;
}
$source_url = $result['data']['source_url'];
$source_url = str_replace('{isliCode}/{contractISLICode}', '', $source_url);
// var_dump($source_url);die;
$order_goods_source = OrderGoodsSource::where('batchcode', $batchcode)->select()->toArray();
// $sign = parent::createSign("distribute");
foreach($order_detail as $detail){
$source_url_arr = json_decode($detail['source_download'], true);
// $identifiers = explode(',', $detail['identifiers']);
// foreach($order_goods_source as $value){
if(empty($source_url_arr)){
$source_url_arr = [];
}
for($i=0;$i < count($source_url_arr);$i++){
if($source_url_arr[$i]['status'] > 3){
continue;
}
if(empty($contractcode_arr[$detail['id']])){
continue;
}
//todo 请求依据同步订单信息返回的地址获取解密资源地址 接口3.2
$res = Http::get($source_url . "{$source_url_arr[$i]['islicode']}/{$contractcode_arr[$detail['id']]}", [], $headers);
$this->orderlog->info("{$batchcode}订单获取资源下载地址", $res);
if($res['code'] != 200){
// throw new \think\Exception($res['msg'], 400);
if($source_url_arr[$i]['status'] != 4){
$source_url_arr[$i]['status'] = 3;
}
continue;
}
$result = json_decode($res['data'], true);
if($result['resultCode'] != "00000000"){
// throw new \think\Exception($result['resultMsg'], 400);
if($source_url_arr[$i]['status'] != 4){
$source_url_arr[$i]['status'] = 3;
}
continue;
}
if(!empty($result['data']['url'])){
$source_url_arr[$i]['url'] = $result['data']['url'];
$source_url_arr[$i]['status'] = 4;
}else{
// $source_url_arr[$i]['url'] = $result['data']['url'];
$source_url_arr[$i]['status'] = 5;
}
}
// }
$source_url_arr = json_encode($source_url_arr);
OrderGoodsDetail::where('id', $detail['id'])->where('is_deleted', 0)->update(['source_download' => $source_url_arr]);
}
// $update_source = [];
// if(!empty($value['target_data'])){
// $value['target_data'] = json_decode($value['target_data'], true);
// $value['target_data']['source_url'] = $source_url_arr;
// $update_source['target_data'] = json_encode($value['target_data']);
// }else{
// $value['source_data'] = json_decode($value['source_data'], true);
// $value['source_data']['source_url'] = $source_url_arr;
// $update_source['source_data'] = json_encode($value['source_data']);
// }
// OrderGoodsSource::where('id', $value['id'])->update($update_source);
}
public function applyContractCode($goods_islicode, $buy_islicode, $count, $date, $batchcode){
$ratio_setting = AccountRatioSetting::where('is_deleted', 0)->where('status', 1)->find();
$entrust_ratio_detail = AccountRatioDetail::where('setting_id', $ratio_setting->id)->where('role_type', 1)->find();
$ratio = 0;
$entrust_number = 0;
if($entrust_ratio_detail['calculate'] == 1){
$entrust_number = $entrust_ratio_detail['ratio'];
}else{
$entrust_number = $entrust_ratio_detail['amount'];
}
$ratio = round(1 - ($entrust_number / 100), 4);
//todo 请求申请合约关联编码 接口1.5
$path = env("app.tianlang_entrust_url") . "/consignation/v1/applylinkcode";
$post = [
"contractISLIFlag" => $goods_islicode,
"buyerISLIFlag" => $buy_islicode,
"shareProportion" => $ratio,
"purchaseQuantity" => $count,
"authorizationDate" => $date,
];
$sign = parent::createSign("apply_code");
$headers = array(
CURLOPT_HTTPHEADER => array(
"cloudhub_token:{$sign}",
"channel_isli_flag:".env('isli.channel_isli'),
"Content-Type: application/json"
)
);
$result = Http::post($path, json_encode($post), $headers);
$this->orderlog->info("{$batchcode}订单获取合约关联编码请求参数", $post);
$this->orderlog->info("{$batchcode}订单获取合约关联编码", $result);
if($result['code'] != 200){
// throw new \think\Exception($result['msg'], 400);
return "";
}
$result = json_decode($result['data'], true);
if($result['resultCode'] != "00000000"){
return "";
// throw new \think\Exception($result['resultMsg'], 400);
}
return $result['data'][$buy_islicode];
}
public function invoiceBuyOperate($batchcode){
$pdf_path = $this->initDir();
//买家发票
$order = Order::where('batchcode', $batchcode)->find();
$buyuser_isli = $order->buy_islicode;
$userinfo = OrderUser::where('batchcode', $batchcode)->where('islicode', $buyuser_isli)->find();
$invoice_data = [
"buyerName" => $userinfo['name'], //购买方名称
"buyerType" => '01',//购买方类型01:企业
"buyerTaxNo" => $userinfo['uscc'],//购买方税号
// "totalAmountTax" => $order->total_service_charge,//总金额含税
];
$order_detail = OrderGoodsDetail::where('batchcode', $batchcode)->where('is_deleted', 0)->select()->toArray();
$invoice = new InvoiceManagementService();
$data = $this->orderMoneySplit($order_detail, $batchcode);
// foreach($order_detail as $val){
// $invoice_data['manualOrderDetails'][] = [
// 'amount' => $val['service_charge'], //金额
// 'invoiceNature' => '0', //0:正常 1:折扣 2:被折扣
// 'itemName' => $val['goods_name'], //商品名称
// 'itemTaxCode' => '3049900000000000000', //商品税号
// 'taxIncluded' => '1', //1:含税0:不含税
// 'taxRate' => '0.06',//税率
// 'yhzcbs' => '0',//优惠政策标识
// ];
// }
// if($order->total_service_charge <= 0){
// return;
// }
for($i=0;$i<count($data);$i++) {
$data[$i]['buyerName'] = $userinfo['name'];
$data[$i]['buyerType'] = '01';
$data[$i]['buyerTaxNo'] = $userinfo['uscc'];
$this->orderlog->info("{$batchcode}买家发票请求", $data[$i]);
$result = $invoice->RespondToInvoices($data[$i]);
$this->orderlog->info("{$batchcode}买家发票结果", $result);
if ($result['operateCode'] == 'S') {
// $amount = 0;
// foreach ($result['datas']['invoiceDetail'] as $value) {
// $amount += $value['amount'];
// }
$status = get_headers($result['datas']['pdfUrl']);
$ticketurl = "";
if (strpos($status[0], "200")) {
$pdf_content = file_get_contents($result['datas']['pdfUrl']);
file_put_contents('./' . $pdf_path . "{$result['datas']['serialNo']}.pdf", $pdf_content);
$ticketurl = $pdf_path . "{$result['datas']['serialNo']}.pdf";
}
$insert = [
"batchcode" => $batchcode,
"islicode" => $buyuser_isli,
"ticketid" => $result['datas']['serialNo'],
"ticketmoney" => $data[$i]['totalAmountTax'],
"ticketurl" => $ticketurl,
"pdfUrl" => $result['datas']['pdfUrl'],
"ticket_status" => 3,
"tickettime" => date('Y-m-d H:i:s'),
"ticketApiMessage" => "-",
];
// OrderUser::where('batchcode', $batchcode)->where('islicode', $buyuser_isli)->update($update);
(new Ticket())->insert($insert);
} else {
$insert = [
"batchcode" => $batchcode,
"islicode" => $buyuser_isli,
"ticketid" => "",
"ticketmoney" => $data[$i]['totalAmountTax'],
// "ticketurl" => $pdf_path . "{$result['datas']['serialNo']}.pdf",
"pdfUrl" => $result['datas']['pdfUrl'],
"ticket_status" => 4,
"tickettime" => date('Y-m-d H:i:s'),
"ticketApiMessage" => $result['message'],
];
// OrderUser::where('batchcode', $batchcode)->where('islicode', $buyuser_isli)->update($update);
(new Ticket())->insert($insert);
}
}
}
public function orderMoneySplit($data, $batchcode){
$account_ratio_id = Order::where('batchcode', $batchcode)->value('account_ratio_id');
$ratio_detail = AccountRatioDetail::where('setting_id', $account_ratio_id)->where('role_type', 2)->find();
// 金额按9999拆分
$result = [];
$index = 0;
foreach($data as $key => $val){
$money = $val['service_charge'];
if($money <= 0){
continue;
}
if($money > 9999){
while($money){
$amount = $money - 9999;
if($amount > 0){
$price = 9999;
}elseif($amount < 0){
$price = $money;
}
$index++;
$result[$index]['totalAmountTax'] = $price;
$result[$index]['manualOrderDetails'][] = [
'amount' => $price, //金额
'invoiceNature' => '0', //0:正常 1:折扣 2:被折扣
'itemName' => "*现代服务*交易佣金", //商品名称
'itemTaxCode' => '3049900000000000000', //商品税号
'taxIncluded' => '1', //1:含税0:不含税
'taxRate' => '0.06',//税率
'yhzcbs' => '0',//优惠政策标识
];
if($amount < 0){
break;
}
$money = $amount;
}
}elseif ($money == 9999){
$index++;
$result[$index]['totalAmountTax'] = $money;
$result[$index]['manualOrderDetails'][] = [
'amount' => $money, //金额
'invoiceNature' => '0', //0:正常 1:折扣 2:被折扣
'itemName' => "*现代服务*交易佣金", //商品名称
'itemTaxCode' => '3049900000000000000', //商品税号
'taxIncluded' => '1', //1:含税0:不含税
'taxRate' => '0.06',//税率
'yhzcbs' => '0',//优惠政策标识
];
}elseif($money < 9999){
if(isset($result[$index])){
$this_money = $result[$index]['totalAmountTax'];
}else{
$this_money = 0;
}
if($this_money + $money > 9999){
$this_money = 0;
$index++;
}
$result[$index]['totalAmountTax'] = $this_money + $money;
$result[$index]['manualOrderDetails'][0] = [
'amount' => $result[$index]['totalAmountTax'], //金额
'invoiceNature' => '0', //0:正常 1:折扣 2:被折扣
'itemName' => "*现代服务*交易佣金", //商品名称
'itemTaxCode' => '3049900000000000000', //商品税号
'taxIncluded' => '1', //1:含税0:不含税
'taxRate' => '0.06',//税率
'yhzcbs' => '0',//优惠政策标识
];
}
}
return array_values($result);
}
public function orderSellerMoneySplit($data, $batchcode){
$account_ratio_id = Order::where('batchcode', $batchcode)->value('account_ratio_id');
$ratio_detail = AccountRatioDetail::where('setting_id', $account_ratio_id)->where('role_type', 3)->find();
// 金额按9999拆分
$result = [];
$index = 0;
foreach($data as $key => $val){
$money = round($val['goods_price'] * ($ratio_detail->ratio / 100), 2);
if($money <= 0){
continue;
}
if($money > 9999){
while($money){
$amount = $money - 9999;
if($amount > 0){
$price = 9999;
}elseif($amount < 0){
$price = $money;
}
$index++;
$result[$index]['totalAmountTax'] = $price;
$result[$index]['manualOrderDetails'][] = [
'amount' => $price, //金额
'invoiceNature' => '0', //0:正常 1:折扣 2:被折扣
'itemName' => "*现代服务*交易佣金", //商品名称
'itemTaxCode' => '3049900000000000000', //商品税号
'taxIncluded' => '1', //1:含税0:不含税
'taxRate' => '0.06',//税率
'yhzcbs' => '0',//优惠政策标识
];
if($amount < 0){
break;
}
$money = $amount;
}
}elseif ($money == 9999){
$index++;
$result[$index]['totalAmountTax'] = $money;
$result[$index]['manualOrderDetails'][] = [
'amount' => $money, //金额
'invoiceNature' => '0', //0:正常 1:折扣 2:被折扣
'itemName' => "*现代服务*交易佣金", //商品名称
'itemTaxCode' => '3049900000000000000', //商品税号
'taxIncluded' => '1', //1:含税0:不含税
'taxRate' => '0.06',//税率
'yhzcbs' => '0',//优惠政策标识
];
}elseif($money < 9999){
if(isset($result[$index])){
$this_money = $result[$index]['totalAmountTax'];
}else{
$this_money = 0;
}
if($this_money + $money > 9999){
$this_money = 0;
$index++;
}
$result[$index]['totalAmountTax'] = $this_money + $money;
$result[$index]['manualOrderDetails'][0] = [
'amount' => $result[$index]['totalAmountTax'], //金额
'invoiceNature' => '0', //0:正常 1:折扣 2:被折扣
'itemName' => "*现代服务*交易佣金", //商品名称
'itemTaxCode' => '3049900000000000000', //商品税号
'taxIncluded' => '1', //1:含税0:不含税
'taxRate' => '0.06',//税率
'yhzcbs' => '0',//优惠政策标识
];
}
}
return array_values($result);
}
public function invoiceSellerOperate($batchcode){
$pdf_path = $this->initDir();
// 卖家发票
$invoice = new InvoiceManagementService();
$buyuser_isli = Order::where('batchcode', $batchcode)->value("buy_islicode");
$userinfo = OrderUser::where('batchcode', $batchcode)->where('islicode', '<>', $buyuser_isli)->select()->toArray();
foreach($userinfo as $val){
// $invoice_data = [
// "buyerName" => $val['name'], //购买方名称
// "buyerType" => '01',//购买方类型01:企业
// "buyerTaxNo" => $val['uscc'],//购买方税号
//// "totalAmountTax" => $order->total_service_charge,//总金额含税
// ];
// $total_service_charge = 0;
$order_detail = OrderGoodsDetail::where('batchcode', $batchcode)->where('is_deleted', 0)->where('entrust_islicode', $val['islicode'])->select()->toArray();
$data = $this->orderSellerMoneySplit($order_detail, $batchcode);
// foreach($order_detail as $value){
// $total_service_charge += $value['service_charge'];
// $invoice_data['manualOrderDetails'][] = [
// 'amount' => $value['service_charge'], //金额
// 'invoiceNature' => '0', //0:正常 1:折扣 2:被折扣
// 'itemName' => $value['goods_name'], //商品名称
// 'itemTaxCode' => '3049900000000000000', //商品税号
// 'taxIncluded' => '1', //1:含税0:不含税
// 'taxRate' => '0.06',//税率
// 'yhzcbs' => '0',//优惠政策标识
// ];
// }
// if($total_service_charge <= 0){
// return;
// }
// $invoice_data['totalAmountTax'] = $total_service_charge;
for($i=0;$i<count($data);$i++) {
$data[$i]['buyerName'] = $val['name'];
$data[$i]['buyerType'] = '01';
$data[$i]['buyerTaxNo'] = $val['uscc'];
$this->orderlog->info("{$batchcode}卖家发票请求", $data[$i]);
$result = $invoice->RespondToInvoices($data[$i]);
$this->orderlog->info("{$batchcode}卖家发票结果", $result);
if ($result['operateCode'] == 'S') {
// $amount = 0;
// foreach ($result['datas']['invoiceDetail'] as $value) {
// $amount += $value['amount'];
// }
$status = get_headers($result['datas']['pdfUrl']);
$ticketurl = "";
if (strpos($status[0], "200")) {
$pdf_content = file_get_contents($result['datas']['pdfUrl']);
file_put_contents('./' . $pdf_path . "{$result['datas']['serialNo']}.pdf", $pdf_content);
$ticketurl = $pdf_path . "{$result['datas']['serialNo']}.pdf";
}
$insert = [
"batchcode" => $batchcode,
"islicode" => $val['islicode'],
"ticketid" => $result['datas']['serialNo'],
"ticketmoney" => $data[$i]['totalAmountTax'],
"ticketurl" => $ticketurl,
"pdfUrl" => $result['datas']['pdfUrl'],
"ticket_status" => 3,
"tickettime" => date('Y-m-d H:i:s'),
"ticketApiMessage" => "-"
];
// OrderUser::where('batchcode', $batchcode)->where('islicode', $buyuser_isli)->update($update);
(new Ticket())->insert($insert);
} else {
$insert = [
"batchcode" => $batchcode,
"islicode" => $val['islicode'],
"ticketid" => "",
"ticketmoney" => $data[$i]['totalAmountTax'],
// "ticketurl" => $pdf_path . "{$result['datas']['serialNo']}.pdf",
"pdfUrl" => $result['datas']['pdfUrl'],
"ticket_status" => 4,
"tickettime" => date('Y-m-d H:i:s'),
"ticketApiMessage" => $result['message'],
];
// OrderUser::where('batchcode', $batchcode)->where('islicode', $buyuser_isli)->update($update);
(new Ticket())->insert($insert);
}
}
}
}
public function initDir(){
if(!file_exists("./uploads")){
mkdir("./uploads");
}
if(!file_exists("./uploads/pdf")){
mkdir("./uploads/pdf");
}
$date = date('Ymd');
if(!file_exists("./uploads/pdf/{$date}")){
mkdir("./uploads/pdf/{$date}");
}
return "/uploads/pdf/{$date}/";
}
}

175
app/service/pay/SeparateAccountService.php

@ -0,0 +1,175 @@
<?php
namespace app\service\pay;
use app\model\Order;
use app\model\OrderGoodsDetail;
use app\model\OrderGoodsSource;
use app\model\User;
use app\service\BaseService;
use fast\Http;
use Firebase\JWT\JWT;
use Firebase\JWT\Key;
use think\facade\Db;
use app\service\pay\ApiHelperoneService;
class SeparateAccountService extends BaseService
{
public function __construct()
{
parent::__construct();
}
/**
* Notes: 获取用户信息
* @param $Order 订单号
* @return mixed 用户数组信息
* User: torsenli
* Date: 2022/4/3
* Time: 12:51
*/
public function sell_isli_id($Order){
$sell_id = Db::table('order_goods_detail')->where('is_deleted', 0)->where('batchcode',$Order)->value('entrust_islicode');
return $sell_id;
}
/**
* Notes: 开始分账
* @param $bank_username 开会人名
* @param $bank_name 开户支行
* @param $bank_type 开户行
* @param $bank_num 银行账号
* @param $bank_userphone 预留手机
* @param $bank_add 开户行地址
* @param $amount 分账金额
* User: torsenli
* Date: 2022/4/3
* Time: 12:55
*/
public function StartSplitting($UserData, $total_money, $batchnumber){
// require_once("ApiHelperone.php");
//header("Content-type: text/html; charset=utf-8");
header('content-type:application/json;charset=utf8');
// $openapiurl="http://gw.chenoue.cn:7086/openapi/rest";
$openapiurl="https://t.masget.com/openapi/rest";
// $session = "iba3t9dqln8etmcaceq1xtqr7urevia1";
// $appid="910000198";
// $secretkey="gRAZZKiNw0UbTuF9";
$session = "pw0jhuuijprkk07iyvjmzivf55s2c1cf";
$appid = "910000202";
$secretkey = "2J8h5c0Nq9wjAEcz";
//$loginpwd="0ac8f9c2fac81091a63231ba56b868e7";
//$loginname = "mop_compaytest_0013";
$api=new ApiHelperoneService();
//$openapiurl,$appid,$session,$secretkey,
$api->init($openapiurl,$appid,$session,$secretkey);
// $method="qdpay.pay.online.paytransfer.balance.get";
// $method="masget.bankaccount.bank.wallet.get"; //结算户查询
// $method="masget.bankaccount.bank.wallet.get"; //结算户查询
$method="masget.bankaccount.bank.wallet.batch.transfer"; //1.9.1.批量代付
//批次号
// $batchnumber = time().rand(1000,9999);
//订单号
// $orderid = time().rand(10000,99999).rand(1000,9999);
//$payextraparamsArr = array(
// 'ordernumber' => '287730611608259635'
//);
//$payextraparams = json_encode($payextraparamsArr, JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT);
//结算户查询
// $arr = array(
// // "bankaccount"=>"6230580000135880099"
// "userid"=>"910000198",
// "bankid"=>"404076899",
// );
// $UserData = [[
// "ordernumber"=>$orderid,
// "accountname"=>"李通",
// "bankaccount"=>"6228480128754352879",
// "accounttype"=>"1",
// "bank"=>"农业银行民治支行",
// "txnamount"=>"100",
// ],
// [
// "ordernumber"=>$orderid,
// "accountname"=>$bank_username,
// "bankaccount"=>$bank_num,
// "accounttype"=>"1",
// "bank"=>$bank_name,
// "txnamount"=>"100",
// ]
// ];
// dd($UserData);
//分账
$arr = array(
// "bankaccount"=>"6230580000135880099"
"outuserid" => "910000198",
"bankid" => "404076899",
"batchnumber"=>$batchnumber,
"total" => count($UserData),
"totalamount" =>$total_money,
"backurl" => env('app.host') . "/api/Pay/payCallback", //回调地址
"rows"=>$UserData,
);
$data = json_encode($arr, JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT);
// echo "data=".$data."<br/>";
$result=$api->methodInvoke($method,$data);
return json_decode($result, true);
// dd(1111);
}
public function getBankCode($payee_bank, $payee_account){
// require_once("ApiHelperone.php");
//header("Content-type: text/html; charset=utf-8");
header('content-type:application/json;charset=utf8');
// $openapiurl="http://gw.chenoue.cn:7086/openapi/rest";
$openapiurl="https://t.masget.com/openapi/rest";
// $session = "iba3t9dqln8etmcaceq1xtqr7urevia1";
// $appid="910000198";
// $secretkey="gRAZZKiNw0UbTuF9";
$session = "pw0jhuuijprkk07iyvjmzivf55s2c1cf";
$appid = "910000202";
$secretkey = "2J8h5c0Nq9wjAEcz";
//$loginpwd="0ac8f9c2fac81091a63231ba56b868e7";
//$loginname = "mop_compaytest_0013";
$api=new ApiHelperoneService();
//$openapiurl,$appid,$session,$secretkey,
$api->init($openapiurl,$appid,$session,$secretkey);
// $method="qdpay.pay.online.paytransfer.balance.get";
// $method="masget.bankaccount.bank.wallet.get"; //结算户查询
// $method="masget.bankaccount.bank.wallet.get"; //结算户查询
$method="masget.base.com.bankcode.get"; //1.7.2.获取支行信息
$arr = array(
"bankaccount"=> $payee_account,
"bankkeyword" => $payee_bank,
);
$data = json_encode($arr, JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT);
// echo "data=".$data."<br/>";
$result=$api->methodInvoke($method,$data);
return json_decode($result, true);
// dd(1111);
}
}

200
app/service/pay/security.php

@ -0,0 +1,200 @@
<?php
namespace app\service\pay;
use app\admin\controller\Base;
//base64方法
class Base64Method
{
public function encode($str)
{
$base64str = base64_encode($str);
$base64str = str_replace("+", "-", $base64str);
$base64str = str_replace("/", "_", $base64str);
return $base64str;
}
public function decode($str)
{
$str = str_replace("-", "+", $str);
$str = str_replace("_", "/", $str);
$unbase64str = base64_decode($str);
return $unbase64str;
}
}
//aes 加解密
class security
{
public function encrypt($privateKey, $iv, $data)
{
//$encrypted = mcrypt_encrypt (MCRYPT_RIJNDAEL_128, $privateKey, $data, MCRYPT_MODE_CBC, $iv);
$encrypted = openssl_encrypt($data, 'aes-128-cbc', $privateKey, true, $iv);
$base64method = new Base64Method();
return $base64method->encode($encrypted);;
// return $encrypted;
// $base64method->encode($encrypted);
// dd($base64method->encode($encrypted));
}
public function decrypt($privateKey, $iv, $data)
{
$base64method = new Base64Method();
$encryptedData = $base64method->decode($data);
// echo $encryptedData;dd();
// $decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $privateKey, $encryptedData, MCRYPT_MODE_CBC, $iv);
$decrypted = openssl_decrypt($encryptedData, 'aes-128-cbc', $privateKey, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $iv);
return $decrypted;
}
}
//http get方法
class HttpHelper
{
public function getHttp($url)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($curl);
curl_close($curl);
return $data;
}
public function getSSLHttp($url)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); // https请求 不验证证书和hosts
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
$data = curl_exec($curl);
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($httpCode != 200) {
$data = "https connect timeout";
}
curl_close($curl);
return $data;
}
/**
* 发送post请求
* @param string $url 请求地址
* @param array $post_data post键值对数据
* @return string
*/
function send_post($url, $post_data, $header = null)
{
$postData = http_build_query($post_data);
$options = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type:application/x-www-form-urlencoded',
'content' => $postData,
'timeout' => 15 * 60,// 超时时间(单位:s)
),
);
if ($header) {
//数组追加
$options['http'] = array_merge($header, $options['http']);
}
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
return $result;
}
/**
* 发送post请求数据
* @param string $url 请求地址
* @param array $post_data post键值对数据
* @return string
*/
public function send_post_info($url, $data, $refererUrl = '', $method = 'GET', $contentType = 'application/json', $timeout = 30, $proxy = false)
{
$ch = null;
// $data = '{"buyerName":"\u6df1\u5733\u4ebf\u8d77\u878d\u7f51\u7edc\u79d1\u6280\u6709\u9650\u516c\u53f8","buyerType":"01","totalAmountTax":"100.00","manualOrderDetails":[{"amount":"100.00","invoiceNature":"01","itemName":"\u6d4b\u8bd5","itemTaxCode":"3049900000000000000","taxIncluded":"1","taxRate":"0.06","yhzcbs":"0"}]}';
if ('POST' === strtoupper($method)) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
if ($refererUrl) {
curl_setopt($ch, CURLOPT_REFERER, $refererUrl);
}
if ($contentType) {
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:application/json;charset=UTF-8'));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json;charset=UTF-8'));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization:' . $contentType['Authorization']));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('taxNo:' . $contentType['taxNo']));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('machineNo:' . $contentType['machineNo']));
}
if (is_string($data)) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
} else {
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
}
} else if ('GET' === strtoupper($method)) {
// if (is_string($data)) {
// $real_url = $url . (strpos($url, '?') === false ? '?' : '') . $data;
// } else {
// $real_url = $url . (strpos($url, '?') === false ? '?' : '') . http_build_query($data);
// }
//
// $ch = curl_init($real_url);
// curl_setopt($ch, CURLOPT_HEADER, 0);
// curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:' . $contentType));
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
// if ($refererUrl) {
// curl_setopt($ch, CURLOPT_REFERER, $refererUrl);
// }
} else {
$args = func_get_args();
return false;
}
if ($proxy) {
curl_setopt($ch, CURLOPT_PROXY, $proxy);
}
$ret = curl_exec($ch);
$info = curl_getinfo($ch);
$contents = array(
'httpInfo' => array(
'send' => $data,
'url' => $url,
'ret' => $ret,
'http' => $info,
),
);
curl_close($ch);
echo $ret;
dd();
return $ret;
}
}
?>

666
app/service/task/GoodsService.php

@ -0,0 +1,666 @@
<?php
namespace app\service\task;
use app\model\Festivals;
use app\model\Goods;
use app\model\GoodsDetail;
use app\model\GoodsSource;
use app\model\OperationLog;
use app\model\Order;
use app\model\OrderGoodsDetail;
use app\model\User;
use app\service\BaseService;
use app\service\pay\PayService;
use fast\Http;
use http\Exception;
use think\Validate;
class GoodsService extends BaseService
{
protected $sourceTypeArr = [
"图书" => 1,
"期刊" => 2,
"报纸" => 3,
"音像" => 4,
"音频" => 5,
"视频" => 6,
"其他文献" => 7,
"图片" => 8,
"文化产品" => 9,
];
public function __construct()
{
parent::__construct();
$this->http = new Http();
$this->redis = new \Redis();
$this->redis->connect('127.0.0.1', 6379);
}
public function getApiGoods(){
$count = 0;
// 通过委托系统查询委托数据信息
//todo 请求获取委托信息接口 接口1.1
$path = env("app.entrust_url") . "/consign/exchange/v1/selectEntrustSource/exchange";
$sign = parent::createSign("entrust");
$headers = array(
CURLOPT_HTTPHEADER => array(
"entrust_token:{$sign}"
)
);
$result = $this->http::get($path, [], $headers);
if($result['code'] != 200){
// throw new \think\Exception($result['msg'], 400);
return $count;
}
$result = json_decode($result['data'], true);
if($result['resultCode'] != "00000000"){
// throw new \think\Exception($result['resultMsg'], 400);
return $count;
}
$goods = $result['data'];
$this->goodslog->info("获取委托数据", $goods);
$source_path = env("app.entrust_url") . "/consign/exchange/v1/selectEntrustDetails";
foreach($goods as $k => $v){
// if($v['isliCode'] != "010007-00000000085100000001-1"){
// continue;
// }
// var_dump($v);die;
// return $v;
if(!isset($v['targetData']) || !isset($v['sourceData'])){
continue;
}
// if($v['targetData']['identifier'] == "999998-0000000001234567890-2"){
// continue;
// }
// if(!$this->checkUser($v['targetData']['identifier'])){
// continue;
// }
if(!isset($v['sourceData']['collectionType'])){
continue;
}
if(empty($v['sourceData']['identifiers'])) {
continue;
}
if(empty($v['sourceData']['identifier'])) {
continue;
}
if($v['status'] == 6 || $v['status'] == 7){
continue;
}
// $contractual_period_one = $this->getOldPeriod($v['sourceData']['contractualPeriod']);
// $contractual_period_two = $this->getNewPeriod($v['sourceData']['contractualPeriod']);
// if($contractual_period_one == 0 && $contractual_period_two == 0){
// var_dump($v);die;
// }
// continue;
// if($v['isliCode'] != "010007-00000000050100000001-5"){
// continue;
// }
// 获取委托数据资源
//todo 请求获取委托信息资源详情接口 接口1.2
$res = $this->http::get($source_path . "/{$v['sourceData']['identifiers']}", [], $headers);
$this->goodslog->info("获取{$v['sourceData']['identifiers']}委托资源详情", $goods);
if($res['code'] != 200){
// throw new \think\Exception($res['msg'], 400);
continue;
}
$res = json_decode($res['data'], true);
if($res['resultCode'] != "00000000"){
// throw new \think\Exception($res['resultMsg'], 400);
continue;
}
$res = $res['data'];
$insert = 1;
if(Goods::where('goods_islicode', $v['sourceData']['identifier'])->value('id')){
continue;
// $insert = 0;
// GoodsSource::where('goods_isli_code', $v['isliCode'])->where('is_deleted', 0)->update(['is_deleted' => 1]);
}
$this->insertGoodsSource($res, $v['sourceData']['identifier']); // 添加商品资源详情
$goods_detail_id = $this->insertGoodsDetail($v, $res); // 添加商品明细
$status = 0;
if($v['status'] == 1 || $v['status'] == 4 || $v['status'] == 5){
$status = 1;
}elseif($v['status'] == 2){
$status = 2;
}else{
$status = 4;
}
$contractual_period = $this->getOldPeriod($v['sourceData']['contractualPeriod']);
$contractualPeriodStart = $v['sourceData']['contractualPeriodStart'];
$contractualPeriodEnd = $v['sourceData']['contractualPeriodEnd'];
if(!empty($contractualPeriodStart) && preg_match("/^([0-9]{4})-([0-9]{2})-([0-9]{2})$/", $contractualPeriodStart)){
$contractualPeriodStart .= date(' H:i:s');
}
if(!empty($contractualPeriodEnd) && preg_match("/^([0-9]{4})-([0-9]{2})-([0-9]{2})$/", $contractualPeriodEnd)){
$contractualPeriodEnd .= " 23:59:59";
}
if($contractual_period){
GoodsDetail::where('id', $goods_detail_id)->update(['contractual_period' => $contractual_period]);
$status = 2;
$old_status = 1;
}else{
$contractual_period = $this->getNewPeriod($v['sourceData']['contractualPeriod']);
GoodsDetail::where('id', $goods_detail_id)->update(['contractual_period' => $contractual_period]);
if($contractual_period == 2){
$day = $v['sourceData']['contractualCycle'];
$time = $this->getEndDate($contractualPeriodStart, $day);
$contractualPeriodEnd = date("Y-m-d 23:59:59", $time);
}elseif($contractual_period == 0){
$status = 2;
}
$old_status = 0;
}
if(strtotime($contractualPeriodStart) > time() && $status == 1){
$status = 2;
}
$goods_data = [
"goods_detail_id" => $goods_detail_id,
"contract_status" => $v['sourceData']['contractStatus'],
"contractual_start_time" => $contractualPeriodStart,
"contractualtime_end_time" => $contractualPeriodEnd,
"goods_status" => $status,
"old_status" => $old_status,
"entrust_status" => $v['status']
];
if($insert){
$goods_data["user_islicode"] = $v['targetData']['identifier'];
$goods_data["username"] = $v['targetData']['titleName'];
$goods_data['islicode'] = $v['isliCode'];
$goods_data["goods_islicode"] = $v['sourceData']['identifier'];
$flag = (new Goods())->insertGetId($goods_data);
if($flag){
// $this->redis->lPush($goods_data['goods_islicode'] . "_count", 1);
Goods::where('id', $flag)->update(['recommend_sort' => $flag]);
$operation_log = [
"type" => "goods",
"log_id" => $flag,
"message" => date('Y-m-d H:i:s')." 发布标的成功",
];
(new OperationLog())->insert($operation_log);
}else{
// throw new \think\Exception("添加失败", 400);
continue;
}
}else{
$flag = (new Goods())->where('goods_islicode', $v['sourceData']['identifier'])->update($goods_data);
if($flag){
if($this->redis->lLen($v['isliCode'] . "_count") <= 0){
// $this->redis->lPush($v['isliCode'] . "_count", 1);
}
}else{
// throw new \think\Exception("添加失败", 400);
continue;
}
}
$count++;
}
return $count;
}
public function goodsPast(){
$goods = Goods::where('goods_status', '1')->select()->toArray();
foreach($goods as $val){
if(empty($val['contractualtime_end_time'])){
continue;
}
$contractual_period = GoodsDetail::where('id', $val['goods_detail_id'])->value('contractual_period');
if($contractual_period != 2 && $contractual_period != 3){
continue;
}
if(strtotime($val['contractualtime_end_time']) <= time()){
$this->log->info("委托时间到期", "{$val['goods_islicode']}委托时间{$val['contractualtime_end_time']}已到期");
Goods::where('id', $val['id'])->update(['goods_status' => 4]);
//todo 请求交易所撤销委托接口 接口1.4
$url = env("app.entrust_url") . "/consign/exchange/v1/exchangeRevokeEntrust";
$sign = parent::createSign("entrust");
$headers = array(
CURLOPT_HTTPHEADER => array(
"entrust_token:{$sign}"
)
);
$post = [
"isliCode" => $val['islicode'],
"status" => 1,
"revokeReason" => "委托周期结束"
];
$this->goodslog->info("{$val['islicode']}委托时间到期", $post);
Http::get($url, $post, $headers);
$operation_log = [
"type" => "goods",
"log_id" => $val['id'],
"message" => date('Y-m-d H:i:s')." 委托标的过期失效!",
];
(new OperationLog())->insert($operation_log);
}
}
}
public function goodsDatePutaway(){
$goods = Goods::where('old_status', 0)->whereIn('entrust_status', '1,4,5')->where('goods_status', 2)->where('apply_out', 0)->select()->toArray();
foreach($goods as $val){
if(empty($val['contractualtime_end_time']) || empty($val['contractual_start_time'])){
continue;
}
$goods_detail = GoodsDetail::where('id', $val['goods_detail_id'])->find();
if($goods_detail->goods_entrust == 1 && $goods_detail->stock == 0){
continue;
}
if(strtotime($val['contractualtime_end_time']) <= time()){
continue;
}
if(strtotime($val['contractual_start_time']) <= time()){
Goods::where('id', $val['id'])->update(['goods_status' => 1]);
}
}
}
public function checkUser($user_isli){
$user = User::where('user_isli', $user_isli)->find();
if($user){
return true;
}
//todo 请求根据账号ID查询用户信息接口 接口3.1
$path = env('app.real_url') . "/users/usermgt/v1/user-info/{$user_isli}";
$sign = parent::createSign("user_real");
$headers = array(
CURLOPT_HTTPHEADER => array(
"api_token:{$sign}",
// "Content-Type: application/json"
)
);
$result = Http::get($path, [], $headers);
if($result['code'] != 200){
throw new \think\Exception($result['msg'], 400);
}
$result = json_decode($result['data'], true);
if($result['resultCode'] != "00000000"){
throw new \think\Exception($result['resultMsg'], 400);
}
$userinfo = $result['data'];
if(!isset($userinfo['legalsCellPhone'])){
// var_dump($userinfo);die;
}
$insert = [];
if($userinfo['userType'] == "机构"){
$insert = [
"agency_type" => 2,
"attest_status" => $userinfo['state'] + 1,
"user_isli" => $userinfo['islicode'],
"username" => $userinfo['name'],
"institution_code" => $userinfo['uscc'],
"legals_name" => $userinfo['legalsName'],
"legals_type" => $userinfo['legalsType'],
"legals_idnum" => $userinfo['legalsIdnum'],
"legals_phone" => (isset($userinfo['legalsCellPhone']) ? $userinfo['legalsCellPhone'] : ''),
"bank_account" => $userinfo['publicAccount'],
"bank_card_type" => $userinfo['bankCardType'],
"bank_name" => $userinfo['bankName'],
"bank_type" => $userinfo['bankType'],
"bank_username" => $userinfo['bankAccountName'],
"bank_userid" => $userinfo['certIdnum'],
"bank_userphone" => $userinfo['bankCellPhone'],
"bank_address" => $userinfo['bankAddress'],
];
}else{
$insert = [
"agency_type" => 1,
"attest_status" => $userinfo['state'] + 1,
"user_isli" => $userinfo['islicode'],
"username" => $userinfo['Name'],
"cert_type" => $userinfo['certType'],
"idNumber" => $userinfo['idNumber'],
"cell_phone" => $userinfo['cellPhone'],
"bank_account" => $userinfo['publicAccount'],
"bank_card_type" => $userinfo['bankCardType'],
"bank_name" => $userinfo['bankName'],
"bank_username" => $userinfo['bankAccountName'],
"bank_userid" => $userinfo['certIdnum'],
"bank_userphone" => $userinfo['bankCellPhone'],
"bank_address" => $userinfo['bankAddress'],
];
}
$insert['registertime'] = date('Y-m-d H:i:s');
$insert['attesttime'] = date('Y-m-d H:i:s');
(new User())->insert($insert);
return true;
}
public function getRevocationGoods(){
//todo 请求获取撤销委托信息 接口 接口1.3
$path = env("app.entrust_url") . "/consign/exchange/v1/selectRevokeEntrust/exchange";
$this->log->info("获取撤销ISLI地址", $path);
$sign = parent::createSign("entrust");
$headers = array(
CURLOPT_HTTPHEADER => array(
"entrust_token:{$sign}"
)
);
$result = $this->http::get($path, [], $headers);
if($result['code'] != 200){
throw new \think\Exception($result['msg'], 400);
}
$result = json_decode($result['data'], true);
if($result['resultCode'] != "00000000"){
throw new \think\Exception($result['resultMsg'], 400);
}
$result = $result['data'];
$this->goodslog->info("获取撤销委托数据", $result);
foreach($result as $key => $val){
if(Goods::where('islicode', $val['isliCode'])->where('goods_status', 1)->update(['goods_status' => 2, 'apply_out' => 1])){
$this->orderRevocation($val['isliCode']);
$goods_id = Goods::where('islicode', $val['isliCode'])->where('is_deleted', 0)->value('id');
$operation_log = [
"type" => "goods",
"log_id" => $goods_id,
"message" => date('Y-m-d H:i:s')." 发布投送系统撤销委托",
];
(new OperationLog())->insert($operation_log);
}
}
}
public function getRevocationResult(){
//todo 请求查询撤销审核数据(交易所/委托)接口 接口1.5
$path = env("app.entrust_url") . "/consign/exchange/v1/selectVerifyStatus";
$sign = parent::createSign("entrust");
$headers = array(
CURLOPT_HTTPHEADER => array(
"entrust_token:{$sign}"
)
);
$result = $this->http::get($path, [], $headers);
if($result['code'] != 200){
throw new \think\Exception($result['msg'], 400);
}
$result = json_decode($result['data'], true);
if($result['resultCode'] != "00000000"){
throw new \think\Exception($result['resultMsg'], 400);
}
$result = $result['data'];
$this->goodslog->info("获取撤销委托数据结果", $result);
foreach($result as $key => $val){
if($val['revokeStatus'] != 2){
// continue;
}
if($val['verifyStatus'] == 0){
continue;
}
if($val['verifyStatus'] == 1){
if(Goods::where('islicode', $val['isliCode'])->where('apply_out', 1)->update(['goods_status' => 2])){
$this->orderRevocation($val['isliCode']);
$operation_log = [
"type" => "goods",
"log_id" => Goods::where('islicode', $val['isliCode'])->value('id'),
"message" => date('Y-m-d H:i:s') . " 申请撤销委托审核通过"
];
(new OperationLog())->insert($operation_log);
}else{
if(Goods::where('islicode', $val['isliCode'])->where('goods_status', 'in', '1,5')->update(['goods_status' => 2, 'apply_out' => 1])){
$this->orderRevocation($val['isliCode']);
$operation_log = [
"type" => "goods",
"log_id" => Goods::where('islicode', $val['isliCode'])->value('id'),
"message" => date('Y-m-d H:i:s') . " 委托系统撤销委托"
];
(new OperationLog())->insert($operation_log);
}
}
}else{
if(Goods::where('islicode', $val['isliCode'])->where('apply_out', 1)->update(['apply_out' => 0])){
$operation_log = [
"type" => "goods",
"log_id" => Goods::where('islicode', $val['isliCode'])->value('id'),
"message" => date('Y-m-d H:i:s') . " 申请撤销委托审核不通过"
];
(new OperationLog())->insert($operation_log);
}
}
}
}
public function orderRevocation($islicode){
$order_goods_detail = OrderGoodsDetail::alias('detail')
->join('order order', 'order.batchcode = detail.batchcode')
->where('detail.islicode', $islicode)
->where('order.status', 1)
->where('detail.is_deleted', 0)
->field('detail.batchcode')
->select()->toArray();
foreach($order_goods_detail as $val){
if(OrderGoodsDetail::where('batchcode', $val['batchcode'])->where('is_deleted', 0)->count() > 1){
$total_service_charge = OrderGoodsDetail::where('batchcode', $val['batchcode'])->where('islicode', '<>', $islicode)->where('is_deleted', 0)->sum('service_charge');
$total_money = OrderGoodsDetail::where('batchcode', $val['batchcode'])->where('islicode', '<>', $islicode)->where('is_deleted', 0)->sum('money');
Order::where('batchcode', $val['batchcode'])->update(['total_service_charge' => $total_service_charge, 'total_money' => $total_money]);
}else{
Order::where('batchcode', $val['batchcode'])->update(['status' => 5]);
}
OrderGoodsDetail::where('batchcode', $val['batchcode'])->where('islicode', $islicode)->update(['is_deleted' => 1]);
if(Order::where('batchcode', $val['batchcode'])->value('total_money') <= 0){
Order::where('batchcode', $val['batchcode'])->update(['status' => 2, 'pay_status' => 2, 'paymenttime' => date('Y-m-d H:i:s')]);
$pay_service = new PayService();
$pay_service->payFinishOperate($val['batchcode']);
}
}
}
public function insertGoodsSource($res, $islicode){
foreach($res as $key => $val){
// $source_type = $this->getSourceType($val['sourceType'] ?? '');
$source = [
"servicecode" => isset($val['serviceCode']) ? $val['serviceCode'] : "",
"linkcode" => isset($val['linkCode']) ? $val['linkCode'] : "",
"publisherid" => isset($val['publisherId']) ? $val['publisherId'] : "",
"registrant" => isset($val['register']) ? $val['register'] : "",
"resolution_url" => isset($val['resolutionUrl']) ? $val['resolutionUrl'] : "",
"source_type" => isset($val['sourceType']) ? $val['sourceType'] : "",
"source_name_type" => isset($val['sourceNameType']) ? $val['sourceNameType'] : "",
"source_name" => isset($val['sourceName']) ? $val['sourceName'] : "",
"sourceIdentify" => isset($val['sourceIdentify']) ? $val['sourceIdentify'] : "",
"source_fragment" => isset($val['sourceFragment']) ? $val['sourceFragment'] : "",
"target_name" => isset($val['targetName']) ? $val['targetName'] : "",
"target_name_type" => isset($val['targetNameType']) ? $val['targetNameType'] : "",
"targetIdentify" => isset($val['targetIdentify']) ? $val['targetIdentify'] : "",
"target_fragment" => isset($val['targetFragment']) ? $val['targetFragment'] : "",
"targetFormat" => isset($val['targetFormat']) ? $val['targetFormat'] : "",
"source_data" => isset($val['sourceData']) ? $val['sourceData'] : "",
"target_data" => isset($val['targetData']) ? $val['targetData'] : "",
"metadataXml" => isset($val['metadataXml']) ? $val['metadataXml'] : "",
"cancellation_reason" => isset($val['cancellationReason']) ? $val['cancellationReason'] : "",
"allocationtime" => isset($val['allocationDate']) ? $val['allocationDate'] : "",
"datatype" => $val['dataType'],
];
if(isset($val['cancellationDate'])){
$source['cancellationtime'] = $val['cancellationDate'];
}
$source['goods_isli_code'] = $islicode;
(new GoodsSource())->insert($source);
}
}
public function insertGoodsDetail($data, $source){
$price = (float)str_replace("RMB ", "", $data['sourceData']['price']);
$goods_detail = [
"goods_name" => (isset($data['sourceData']['titleName']) ? $data['sourceData']['titleName'] : ""),
"goods_image" => (isset($data['sourceData']['cover']) ? $data['sourceData']['cover'] : ""),
"price" => $price,
"goods_type" => ($data['sourceData']['collectionType'] == "文化资源数据" ? 1 : 2),
"charges_type" => ($price <= 0 ? 1 : 2),
"goods_islicode" => $data['sourceData']['identifier'],
"contractual_period" => 0,
"sourcedata_islicode" => $data['sourceData']['isliCode'],
"earnest_money" => 0,
"transaction_class" => ($data['sourceData']['transactionKind'] == "权属" ? 1 : 2),
"contract" => isset($data['sourceData']['description']) ? $data['sourceData']['description'] : "",
"otherIdentifiers" => isset($data['sourceData']['otherIdentifiers']) ? $data['sourceData']['otherIdentifiers'] : "",
"data_json" => json_encode($data),
"source_json" => json_encode($source)
];
// if($goods_detail['contractual_period'] == 3){
// // 周期
// $goods_detail['entrust_month'] = 1;
// }
if($goods_detail['transaction_class'] == 1){
// 权属
$goods_detail['identifier'] = isset($data['sourceData']['identifier']) ? $data['sourceData']['identifier'] : "";
$goods_detail['identifiers'] = isset($data['sourceData']['identifiers']) ? $data['sourceData']['identifiers'] : "";
$goods_detail["goods_ownership_str"] = isset($data['sourceData']['rights']) ? $data['sourceData']['rights'] : "";
$goods_detail["goods_entrust"] = ($data['sourceData']['transactionType'] == "授权" ? 2 : 1);
if($goods_detail["goods_entrust"] == 2){
$goods_detail['stock'] = -1;
}else{
$goods_detail['stock'] = 1;
}
}else{
// 商品
$goods_detail['identifier'] = isset($data['sourceData']['identifier']) ? $data['sourceData']['identifier'] : "";
$goods_detail["goods_entrust"] = ($data['sourceData']['transactionType'] == "租赁" ? 3 : 4);
$goods_detail['classification'] = isset($data['sourceData']['classification']) ? $data['sourceData']['classification'] : "";
$goods_detail['stock'] = 1;
// $this->redis->lPush($data['isliCode'] . "_stock", 1);
}
$goods_detail_id = (new GoodsDetail())->insertGetId($goods_detail);
return $goods_detail_id;
}
public function getOldPeriod($contractual_period){
switch ($contractual_period){
case "永久":
return 1;
case "单次":
return 2;
case "周期":
return 3;
default:
return 0;
}
return 0;
}
public function getNewPeriod($contractual_period){
switch ($contractual_period){
case "永久性委托":
return 1;
case "一次性委托":
return 2;
case "阶段性委托":
return 3;
default:
return 0;
}
return 0;
}
public function getEndDate($starttime, $day){
// 法定节假日数组
$festivals = Festivals::where('year', date('Y-m-d'))->field('date')->select()->toArray();
$festivals = array_column($festivals, 'date');
$time = strtotime("+1 day", strtotime($starttime));
while(true){
if(date('N', $time) > 5){ // 周末
$time = strtotime("+1 day", $time);
continue;
}
if(in_array( date('Y-m-d', $time), $festivals)){ // 法定节假日
$time = strtotime("+1 day", $time);
continue;
}
$day--;
if($day <= 0){
break;
}
$time = strtotime("+1 day", $time);
}
return $time;
}
public function getSourceType($str){
$source_type = 0;
foreach($this->sourceTypeArr as $key => $val){
if(strpos($str, $key) !== false){
$source_type = $val;
break;
}
}
return $source_type;
}
public function goodsJoinField(){
$goods_detail = GoodsDetail::where('is_deleted', 0)->where('is_join', 0)->field('id,data_json,source_json')->select()->toArray();
foreach($goods_detail as $value){
$goods = json_decode($value['data_json'], true);
$source = json_decode($value['source_json'], true);
$str = $this->joinField($goods, $source);
// preg_match_all("/[\x{4e00}-\x{9fa5}]+/u", $str, $res);
preg_match_all("/[\x{4e00}-\x{9fa5}a-zA-Z]+/u", $str, $res);
$res = implode('', $res[0]);
GoodsDetail::where('id', $value['id'])->update(['join_field' => $res, 'is_join' => 1]);
}
}
public function joinField(array $goods = [], array $source = []){
// todo 将委托数据字段拼接字符串
$str = "";
if(isset($goods['sourceData'])){
$source_data = $goods['sourceData'];
$str .= implode('', $source_data);
$goods['sourceData'] = null;
}
if(isset($goods['targetData'])){
$target_data = $goods['targetData'];
$str .= implode('', $target_data);
$goods['targetData'] = null;
}
$str .= implode('', $goods);
foreach($source as &$value){
if(isset($value['sourceData'])){
$str .= implode('', json_decode($value['sourceData'], true));
$value['sourceData'] = null;
}
if(isset($value['targetData'])){
$str .= implode('', json_decode($value['targetData'], true));
$value['targetData'] = null;
}
$str .= implode('', $value);
}
return $str;
}
}

353
app/service/task/OrderService.php

@ -0,0 +1,353 @@
<?php
namespace app\service\task;
use app\model\AccountRatioDetail;
use app\model\AccountRatioSetting;
use app\model\Goods;
use app\model\GoodsDetail;
use app\model\OperationLog;
use app\model\Order;
use app\model\OrderGoodsDetail;
use app\model\OrderGoodsSource;
use app\model\OrderUser;
use app\model\Ticket;
use app\service\BaseService;
use app\service\pay\PayService;
use app\service\pay\SeparateAccountService;
use fast\Http;
class OrderService extends BaseService
{
public function __construct()
{
parent::__construct();
}
public function payTimeout(){
$date = date('Y-m-d H:i:s', strtotime("-30 minute"));
$order = Order::where('status', 1)->whereTime('createtime', '<=', $date)->select()->toArray();
// $order = Order::where('batchcode', '1650098940946850')->select()->toArray();
if($order){
foreach($order as $val){
$order_detail = OrderGoodsDetail::where('batchcode', $val['batchcode'])->where('is_deleted', 0)->field("goods_islicode")->select()->toArray();
foreach($order_detail as $value){
$goods_detail_id = Goods::where('goods_islicode', $value['goods_islicode'])->value('goods_detail_id');
if(!$goods_detail_id){
continue;
}
$goods_detail = GoodsDetail::where('id', $goods_detail_id)->where('is_deleted', 0)->find();
if(!$goods_detail){
continue;
}
if($goods_detail->goods_entrust == 1 || $goods_detail->contractual_period == 2){
$goods_detail->stock = 1;
$goods_detail->save();
Goods::where('goods_islicode', $value['goods_islicode'])->update(['goods_status' => 1]);
$username = OrderUser::where('batchcode', $val['batchcode'])->where('islicode', $val['buy_islicode'])->value('name');
$operation_log = [
"type" => "goods",
"log_id" => Goods::where('goods_islicode', $value['goods_islicode'])->value('id'),
"message" => date('Y-m-d H:i:s')." {$username}未付款成功,重新发布该标的!",
];
(new OperationLog())->insert($operation_log);
}
}
Order::where('id', $val['id'])->update(['status' => 5, 'shuttime' => date('Y-m-d H:i:s')]);
}
}
}
public function SourceTimeout(){
$order = Order::where('status', '2')->whereTime('paymenttime', '<=', date('Y-m-d H:i:s', strtotime("-7 day")))->select()->toArray();
foreach($order as $v){
$buy_username = OrderUser::where('id', $v['user_id'])->value('name');
if($v['total_money'] <= 0){
$update = [
'status' => 4,
'receivetime' => date('Y-m-d H:i:s'),
'closetime' => date('Y-m-d H:i:s'),
'completetime' => date('Y-m-d H:i:s'),
];
}else{
$update = [
'status' => 3,
'receivetime' => date('Y-m-d H:i:s')
];
}
if(Order::where('batchcode', $v['batchcode'])->where('status', 2)->update($update)){
$this->orderComplete($v['batchcode']);
$goods_islicode = OrderGoodsDetail::where('batchcode', $v['batchcode'])->where('is_deleted', 0)->field('goods_islicode')->select()->toArray();
foreach($goods_islicode as $val){
$goods_id = Goods::where('goods_islicode', $val['goods_islicode'])->where('is_deleted', 0)->value('id');
if(empty($goods_id)){
continue;
}
$goods_entrust = OrderGoodsDetail::where('batchcode', $v['batchcode'])->where('is_deleted', 0)->where('goods_islicode', $val['goods_islicode'])->value('goods_entrust');
$operation_log = [
"type" => "goods",
"log_id" => $goods_id,
"message" => date('Y-m-d H:i:s')." ". ($goods_entrust == 1 ? "转让" : "授权") ."给用户{$buy_username}",
];
(new OperationLog())->insert($operation_log);
}
}
}
}
public function orderSourceDownload(){
$this->SourceTimeout();
//todo 请求获取资源下载状态 接口3.3
$order = Order::where('status', '2')->select()->toArray();
// $order = Order::where('batchcode', '1651046992561468')->select()->toArray();
$path = env("app.real_url") . "/dist/catalogs/v1/query/status";
$sign = parent::createSign("distribute");
$headers = array(
CURLOPT_HTTPHEADER => array(
"dist_token:{$sign}",
"Content-Type: application/json"
)
);
foreach($order as $value){
$buy_username = OrderUser::where('id', $value['user_id'])->value('name');
// $source = OrderGoodsSource::where('batchcode', $value['batchcode'])->select()->toArray();
$order_detail = OrderGoodsDetail::where('batchcode', $value['batchcode'])->where('is_deleted', 0)->select()->toArray();
$download = 1;
foreach($order_detail as $detail){
$source_url_arr = json_decode($detail['source_download'], true);
for($i=0;$i < count($source_url_arr);$i++){
if($source_url_arr[$i]['status'] < 4){
$download = 0;
continue;
}
if($source_url_arr[$i]['status'] == 7 || $source_url_arr[$i]['status'] == 5){
continue;
}
$url = "/{$value['batchcode']}/{$source_url_arr[$i]['islicode']}/{$value['buy_islicode']}";
// var_dump($path.$url);die;
$result = Http::get($path.$url, [], $headers);
$this->orderlog->info("{$value['batchcode']}获取资源下载状态", $result);
// var_dump($result);die;
if($result['code'] != 200){
// throw new \think\Exception($result['msg'], 400);
$download = 0;
$source_url_arr[$i]['status'] = 6;
continue;
}
$result = json_decode($result['data'], true);
if($result['resultCode'] != "00000000"){
// throw new \think\Exception($result['resultMsg'], 400);
$download = 0;
$source_url_arr[$i]['status'] = 6;
continue;
}
if(!isset($result['data']['sourceStatus'])){
$download = 0;
continue;
}
if($result['data']['sourceStatus'] == 0) {
$source_url_arr[$i]['status'] = 7;
}elseif($result['data']['sourceStatus'] == 2){
$source_url_arr[$i]['status'] = 8;
$download = 0;
}elseif($result['data']['sourceStatus'] == 1){
$download = 0;
}else{
$source_url_arr[$i]['status'] = 9;
$download = 0;
}
}
$source_url_arr = json_encode($source_url_arr);
OrderGoodsDetail::where('id', $detail['id'])->where('is_deleted', 0)->update(['source_download' => $source_url_arr]);
}
if($download == 1){
if($value['total_money'] <= 0){
$update = [
'status' => 4,
'receivetime' => date('Y-m-d H:i:s'),
'closetime' => date('Y-m-d H:i:s'),
'completetime' => date('Y-m-d H:i:s'),
];
}else{
$update = [
'status' => 3,
'receivetime' => date('Y-m-d H:i:s')
];
}
if(Order::where('batchcode', $value['batchcode'])->where('status', 2)->update($update)){
$this->orderComplete($value['batchcode']);
$goods_islicode = OrderGoodsDetail::where('batchcode', $value['batchcode'])->where('is_deleted', 0)->field('goods_islicode')->select()->toArray();
foreach($goods_islicode as $val){
$goods_id = Goods::where('goods_islicode', $val['goods_islicode'])->where('is_deleted', 0)->value('id');
if(empty($goods_id)){
continue;
}
$goods_entrust = OrderGoodsDetail::where('batchcode', $value['batchcode'])->where('is_deleted', 0)->where('goods_islicode', $val['goods_islicode'])->value('goods_entrust');
$operation_log = [
"type" => "goods",
"log_id" => $goods_id,
"message" => date('Y-m-d H:i:s')." ". ($goods_entrust == 1 ? "转让" : "授权") ."给用户{$buy_username}",
];
(new OperationLog())->insert($operation_log);
}
}
}
}
}
public function orderComplete($batchcode){
//todo 请求交易所撤销委托 接口1.4
$url = env("app.entrust_url") . "/consign/exchange/v1/exchangeRevokeEntrust";
$sign = parent::createSign("entrust");
$headers = array(
CURLOPT_HTTPHEADER => array(
"entrust_token:{$sign}"
)
);
$order_goods = OrderGoodsDetail::where('batchcode', $batchcode)->where('is_deleted', 0)->where('goods_entrust', 1)->select()->toArray();
foreach($order_goods as $val){
Goods::where('goods_islicode', $val['goods_islicode'])->where('goods_status', 5)->update(['goods_status' => 3, 'contractualtime_end_time' => date('Y-m-d H:i:s')]);
$post = [
"isliCode" => $val['islicode'],
"status" => 2,
"revokeReason" => "已转让"
];
Http::get($url, $post, $headers);
}
}
public function orderClose(){
$order = Order::where('status', '3')->select()->toArray();
// $order = Order::where('batchcode', '1652688520860660')->select()->toArray();
$ratio_setting = AccountRatioSetting::where('is_deleted', 0)->where('status', 1)->find();
$ratio_detail = AccountRatioDetail::where('setting_id', $ratio_setting->id)->where('role_type', 1)->find();
foreach($order as $item){
$account = [];
$total_money = 0;
$order_detail = OrderGoodsDetail::where('batchcode', $item['batchcode'])->where('is_deleted', 0)->where('is_close', 0)->where('close_status', '<>', 5)->select()->toArray();
foreach($order_detail as $value){
if(in_array($value['entrust_islicode'], $account)){
$user_money = $account[$value['entrust_islicode']]['txnamount'];
if($ratio_detail->calculate == 1){
if($ratio_detail->ratio <= 0){
$money = round($value['goods_price'], 2) * 100;
}else{
$money = round($value['goods_price'] * ($ratio_detail->ratio / 100), 2) * 100;
}
}else{
$money = round(($value['goods_price'] - $ratio_detail->amount), 2) * 100;
}
if($money <= 0){
OrderGoodsDetail::where('id', $value['id'])->update(['close_status' => 5, 'is_close' => 1]);
continue;
}
$total_money += $money;
$user_money = $user_money + $money;
$account[ $value['entrust_islicode'] ]['txnamount'] = $user_money;
}else{
if($ratio_detail->calculate == 1){
if($ratio_detail->ratio <= 0){
$money = round($value['goods_price'], 2) * 100;
}else{
$money = round($value['goods_price'] * ($ratio_detail->ratio / 100), 2) * 100;
}
}else{
$money = round(($value['goods_price'] - $ratio_detail->amount), 2) * 100;
}
if($money <= 0){
OrderGoodsDetail::where('id', $value['id'])->update(['close_status' => 5, 'is_close' => 1]);
continue;
}
$entrust_userinfo = OrderUser::where('id', $value['user_id'])->find();
$total_money += $money;
$order_id = md5(time() . $value['id'] . uniqid());
OrderGoodsDetail::where('batchcode', $value['batchcode'])->where('is_deleted', 0)->where('entrust_islicode', $value['entrust_islicode'])->update(['close_id' => $order_id]);
$result = (new SeparateAccountService())->getBankCode($entrust_userinfo['bankName'], $entrust_userinfo['publicAccount']);
$bankcode = "";
if($result['ret'] == 0){
if(count($result['data']['rows']) > 0){
$bankcode = $result['data']['rows']['0']['bankcode'];
}
}
$account[ $value['entrust_islicode'] ] = [
"ordernumber" => $order_id,
"accountname" => $entrust_userinfo['bankAccountName'],
"bankaccount" => $entrust_userinfo['publicAccount'],
"accounttype" => 0,
"bankcode" => $bankcode,
"bank" => $entrust_userinfo['bankName'],
"txnamount" => $money,
];
}
// $entrust_userinfo = OrderUser::where('id', $value['user_id'])->find();
// if($ratio_detail->calculate == 1){
// $money = (($value['money'] - $value['service_charge']) * ($ratio_detail->ratio / 100)) * 100;
// }else{
// $money = ($value['money'] - $value['service_charge'] - $ratio_detail->amount) * 100;
// }
// if($entrust_userinfo['userType'] == "个人"){
// $accounttype = 1;
// }else{
// $accounttype = 0;
// }
// $total_money = $money;
// $account[] = [
// "ordernumber" => $item['batchcode'],
// "accountname" => $entrust_userinfo['bankAccountName'],
// "bankaccount" => $entrust_userinfo['publicAccount'],
// "accounttype" => $accounttype,
// "bank" => $entrust_userinfo['bankName'],
// "txnamount" => $money,
// ];
}
if((!$order_detail || $total_money <= 0) && !OrderGoodsDetail::where('batchcode', $item['batchcode'])->where('is_deleted', 0)->where('close_status', '<', 5)->value('id')){
Order::where('batchcode', $item['batchcode'])->update(['closetime' => date('Y-m-d H:i:s'), "completetime" => date('Y-m-d H:i:s'), "status" => 4]);
continue;
}
if(!$order_detail || $total_money <= 0){
continue;
}
$batchnumber = md5(uniqid() . time() . rand(1000, 9999));
$account = array_values($account);
$this->orderlog->info("{$item['batchcode']}发起代付", $account);
$result = (new SeparateAccountService())->StartSplitting($account, $total_money, $batchnumber);
$this->orderlog->info("{$item['batchcode']}发起代付结果", $result);
if($result['ret'] == 0){
OrderGoodsDetail::where('batchcode', $item['batchcode'])->where('is_deleted', 0)->update(['close_status' => 2, 'is_close' => 1, 'callback_msg' => $result['message']]);
}else{
OrderGoodsDetail::where('batchcode', $item['batchcode'])->where('is_deleted', 0)->update(['close_status' => 4, 'is_close' => 1, 'callback_msg' => $result['message']]);
}
}
}
public function orderCreateBill(){
$pdf_path = (new PayService())->initDir();
Ticket::where('ticketurl', '=', '')->where('pdfUrl', '<>', '')->field('id,ticketurl,pdfUrl,ticketid')->select()
->each(function ($item) use($pdf_path){
if(empty($item['ticketurl']) && !empty($item['pdfUrl'])){
$status = get_headers($item['pdfUrl']);
$ticketurl = "";
if(strpos($status[0], "200")) {
$pdf_content = file_get_contents($item['pdfUrl']);
file_put_contents('./' . $pdf_path . "{$item['ticketid']}.pdf", $pdf_content);
$ticketurl = $pdf_path . "{$item['ticketid']}.pdf";
}
if($ticketurl){
Ticket::where('id', $item['id'])->update(['ticketurl' => $ticketurl]);
$item['pdfUrl'] = env('app.host') . $ticketurl;
}
}
});
}
}

78
app/service/user/LoginService.php

@ -0,0 +1,78 @@
<?php
namespace app\service\user;
use app\model\Admin;
use app\service\BaseService;
use fast\Http;
use Firebase\JWT\JWT;
class LoginService extends BaseService
{
public function __construct()
{
parent::__construct();
}
public function checkUser($account_id, $nick){
// 权限校验
// $path = env('app.real_url') . "/adminmgt/v1/permission/getPathByNick";
$path = env('app.real_url') . "/users/adminmgt/v1/permission/getPathByNick";
$path .= "?accountId={$account_id}";
$sign = parent::createSign("user_real");
$headers = array(
CURLOPT_HTTPHEADER => array(
"api_token:{$sign}",
"nick:{$nick}",
"Content-Type: application/json"
)
);
$result = Http::get($path, [], $headers);
if($result['code'] != 200){
throw new \think\Exception($result['msg'], 400);
}
$res = json_decode($result['data'], true);
if($res['resultCode'] != '00000000'){
throw new \think\Exception($res['resultMsg'], 400);
}
return $res['data'];
}
public function adminLogin($phone, $password){
$result = Admin::where('username', $phone)->where('is_deleted', 0)->find();
if($result){
if($result->status == 1){
throw new \think\Exception('用户已失效', 400);
}
if(password_verify($password, $result->password)){
unset($result->password);
// 生成token
$encrypt = array(
'lat' => config('jwt.lat'),
'nbf' => config('jwt.nbf'),
'exp' => config('jwt.exp'),
'user_id' => $result->id,
'role_ids' => $result->role_id,
'username' => $result->username,
);
$token =JWT::encode($encrypt, config('jwt.key'), 'HS256');
$result->logintime = date('Y-m-d H:i:s');
$result->token = $token;
$result->save();
$result = $result->toArray();
return $result;
}
}
throw new \think\Exception('用户名或密码错误!', 400);
}
}

374
app/service/user/UserService.php

@ -0,0 +1,374 @@
<?php
namespace app\service\user;
use app\model\Admin;
use app\model\Cert;
use app\model\User;
use app\service\BaseService;
use fast\Http;
use Firebase\JWT\JWT;
use Firebase\JWT\Key;
use think\exception\HttpResponseException;
class UserService extends BaseService
{
protected $reset_pass = "123456";
public function __construct()
{
parent::__construct();
$this->http = new Http();
}
public function checkUser($user_isli = null){
$user = User::where('user_isli', $user_isli)->find();
if($user){
// return true;
}
$path = env('app.real_url') . "/users/usermgt/v1/user-info/{$user_isli}";
$sign = parent::createSign("user_real");
$headers = array(
CURLOPT_HTTPHEADER => array(
"api_token:{$sign}",
// "Content-Type: application/json"
)
);
//todo 请求根据账号ID查询用户信息接口 接口3.1
$result = Http::get($path, [], $headers);
if($result['code'] != 200){
// throw new \think\Exception($result['msg'], 400);
throw new HttpResponseException(_error($result['msg'], 400));
}
if(!isset($result['data'])){
// throw new \think\Exception("未获取到用户信息", 400);
throw new HttpResponseException(_error('未获取到用户信息', 400));
}
$result = json_decode($result['data'], true);
if($result['resultCode'] != "00000000"){
// throw new \think\Exception($result['resultMsg'], 400);
throw new HttpResponseException(_error($result['resultMsg'], 400));
}
if(!isset($result['data'])){
// throw new \think\Exception("未查询到该用户信息", 400);
throw new HttpResponseException(_error('未查询到该用户信息', 400));
}
$userinfo = $result['data'];
if(!isset($userinfo['legalsCellPhone'])){
// var_dump($userinfo);die;
}
$insert = [];
if($userinfo['userType'] == "机构"){
$insert = [
"agency_type" => 2,
"attest_status" => $userinfo['state'] + 1,
"user_isli" => $userinfo['islicode'],
"username" => $userinfo['name'],
"institution_code" => $userinfo['uscc'],
"legals_name" => $userinfo['legalsName'],
"legals_type" => $userinfo['legalsType'],
"legals_idnum" => $userinfo['legalsIdnum'],
"legals_phone" => (isset($userinfo['legalsCellPhone']) ? $userinfo['legalsCellPhone'] : ''),
"bank_account" => $userinfo['publicAccount'],
"bank_card_type" => $userinfo['bankCardType'],
"bank_name" => $userinfo['bankName'],
"bank_type" => $userinfo['bankType'],
"bank_username" => $userinfo['bankAccountName'],
"bank_userid" => $userinfo['certIdnum'],
"bank_userphone" => $userinfo['bankCellPhone'],
"bank_address" => $userinfo['bankAddress'],
];
}else{
$insert = [
"agency_type" => 1,
"attest_status" => $userinfo['state'] + 1,
"user_isli" => $userinfo['islicode'],
"username" => $userinfo['name'],
"cert_type" => $userinfo['certType'],
"idNumber" => $userinfo['idNumber'],
"cell_phone" => $userinfo['cellPhone'],
"bank_account" => $userinfo['publicAccount'],
"bank_card_type" => $userinfo['bankCardType'],
"bank_name" => $userinfo['bankName'],
"bank_username" => $userinfo['bankAccountName'],
"bank_userid" => $userinfo['certIdnum'],
"bank_userphone" => $userinfo['bankCellPhone'],
"bank_address" => $userinfo['bankAddress'],
];
}
$insert['registertime'] = date('Y-m-d H:i:s');
$insert['attesttime'] = date('Y-m-d H:i:s');
(new User())->insert($insert);
return true;
}
public function getApiUser($user_isli = null){
if(empty($user_isli)){
return [];
}
$path = env('app.real_url') . "/users/usermgt/v1/user-info/{$user_isli}";
$sign = parent::createSign("user_real");
$headers = array(
CURLOPT_HTTPHEADER => array(
"api_token:{$sign}",
// "Content-Type: application/json"
)
);
//todo 请求根据账号ID查询用户信息接口 接口3.1
$result = Http::get($path, [], $headers);
if($result['code'] != 200){
throw new \think\Exception($result['msg'], 400);
}
$result = json_decode($result['data'], true);
if($result['resultCode'] != "00000000"){
throw new \think\Exception($result['resultMsg'], 400);
}
if(!isset($result['data'])){
return [];
}
$userinfo = $result['data'];
if(!isset($userinfo['legalsCellPhone'])){
// var_dump($userinfo);die;
}
return $userinfo;
// $insert = [];
// if($userinfo['userType'] == "机构"){
// $res = [
// "agency_type" => 2,
// "attest_status" => $userinfo['state'] + 1,
// "user_isli" => $userinfo['islicode'],
// "username" => $userinfo['name'],
// "institution_code" => $userinfo['uscc'],
// "legals_name" => $userinfo['legalsName'],
// "legals_type" => $userinfo['legalsType'],
// "legals_idnum" => $userinfo['legalsIdnum'],
// "legals_phone" => (isset($userinfo['legalsCellPhone']) ? $userinfo['legalsCellPhone'] : ''),
// "bank_account" => $userinfo['publicAccount'],
// "bank_card_type" => $userinfo['bankCardType'],
// "bank_name" => $userinfo['bankName'],
// "bank_type" => $userinfo['bankType'],
// "bank_username" => $userinfo['bankAccountName'],
// "bank_userid" => $userinfo['certIdnum'],
// "bank_userphone" => $userinfo['bankCellPhone'],
// "bank_address" => $userinfo['bankAddress'],
// ];
// }else{
// $res = [
// "agency_type" => 1,
// "attest_status" => $userinfo['state'] + 1,
// "user_isli" => $userinfo['islicode'],
// "username" => $userinfo['Name'],
// "cert_type" => $userinfo['certType'],
// "idNumber" => $userinfo['idNumber'],
// "cell_phone" => $userinfo['cellPhone'],
// "bank_account" => $userinfo['publicAccount'],
// "bank_card_type" => $userinfo['bankCardType'],
// "bank_name" => $userinfo['bankName'],
// "bank_username" => $userinfo['bankAccountName'],
// "bank_userid" => $userinfo['certIdnum'],
// "bank_userphone" => $userinfo['bankCellPhone'],
// "bank_address" => $userinfo['bankAddress'],
// ];
// }
}
public function getUserInfo($user_isli){
$userinfo = $this->getApiUser($user_isli);
if($userinfo['userType'] == "机构"){
$res = [
"agency_type" => 2,
"attest_status" => $userinfo['state'] + 1,
"user_isli" => $userinfo['islicode'],
"username" => $userinfo['name'],
"institution_code" => $userinfo['uscc'],
"legals_name" => $userinfo['legalsName'],
"legals_type" => $userinfo['legalsType'],
"legals_idnum" => $userinfo['legalsIdnum'],
"legals_phone" => (isset($userinfo['legalsCellPhone']) ? $userinfo['legalsCellPhone'] : ''),
"bank_account" => $userinfo['publicAccount'],
"bank_card_type" => $userinfo['bankCardType'],
"bank_name" => $userinfo['bankName'],
"bank_type" => $userinfo['bankType'],
"bank_username" => $userinfo['bankAccountName'],
"bank_userid" => $userinfo['certIdnum'],
"bank_userphone" => $userinfo['bankCellPhone'],
"bank_address" => $userinfo['bankAddress'],
];
}else{
$res = [
"agency_type" => 1,
"attest_status" => $userinfo['state'] + 1,
"user_isli" => $userinfo['islicode'],
"username" => $userinfo['name'],
"cert_type" => $userinfo['certType'],
"idNumber" => $userinfo['idNumber'],
"cell_phone" => $userinfo['cellPhone'],
"bank_account" => $userinfo['publicAccount'],
"bank_card_type" => $userinfo['bankCardType'],
"bank_name" => $userinfo['bankName'],
"bank_username" => $userinfo['bankAccountName'],
"bank_userid" => $userinfo['certIdnum'],
"bank_userphone" => $userinfo['bankCellPhone'],
"bank_address" => $userinfo['bankAddress'],
];
}
return $res;
}
public function getUserFind($user_isli){
$where = [];
$where['user_isli'] = $user_isli;
$result = User::where($where)->find();
$result->toArray();
return $result;
}
public function list($user_id, $username, $page, $limit){
$where = [];
$where['is_deleted'] = 0;
if(!empty($user_id)){
$where['id'] = $user_id;
}
if(!empty($username)){
$where['username'] = $username;
}
$search = $this->buildSearch(['username'], $where);
$result = (new Admin())->list($search, $where, $limit);
return $result;
}
public function add($name, $username, $password, $status){
if(Admin::where('username', $username)->where('is_deleted', 0)->value('id')){
throw new \think\Exception('该账号已存在,请勿重复添加', 400);
}
$password_hash = password_hash($password, PASSWORD_DEFAULT);
$userinfo = [
'name' => $name,
'username' => $username,
'password' => $password_hash,
'status' => $status,
'role_id' => 0
];
$result = (new Admin())->save($userinfo);
return $result;
}
public function update($user_id, $name, $status){
$result = Admin::where('id', $user_id)->where('is_deleted', 0)->find();
if(!$result){
throw new \think\Exception('该账号不存在', 400);
}
$result->name = $name;
$result->status = $status;
return $result->save();
}
public function forbidden($user_id){
$result = Admin::where('id', $user_id)->where('is_deleted', 0)->find();
if(!$result){
throw new \think\Exception('该账号不存在', 400);
}
$status = $result->status == 0 ? 1 : 0;
$result->status = $status;
$result->save();
return $status;
}
public function resetPass($user_id){
$result = Admin::where('id', $user_id)->where('is_deleted', 0)->find();
if(!$result){
throw new \think\Exception('该账号不存在', 400);
}
if($result->status == 1){
throw new \think\Exception('该用户已禁用', 400);
}
$password_hash = password_hash($this->reset_pass, PASSWORD_DEFAULT);
$result->password = $password_hash;
return $result->save();
}
public function remove($user_id){
$result = Admin::where('id', $user_id)->where('is_deleted', 0)->find();
if(!$result){
throw new \think\Exception('该账号不存在', 400);
}
$result->is_deleted = 1;
return $result->save();
}
public function updateMyPass($password){
$result = Admin::where('id', $this->admin_id)->where('is_deleted', 0)->find();
if(!$result){
throw new \think\Exception('该账号不存在', 400);
}
if($result->status == 1){
throw new \think\Exception('该用户已禁用', 400);
}
$password_hash = password_hash($password, PASSWORD_DEFAULT);
$result->password = $password_hash;
return $result->save();
}
public function getUser(){
$result = (new Admin())->select()->toArray();
return $result;
}
public function getUserData(){
if(!isset($_SERVER['HTTP_TOKEN'])){
throw new \think\Exception('缺少TOKEN', 401);
}
if(!isset($_SERVER['HTTP_URL'])){
throw new \think\Exception('缺少模块名', 401);
}
$token = $_SERVER['HTTP_TOKEN'];
$nick = $_SERVER['HTTP_URL'];
$cert = Cert::where('status', 0)->where('type', "entrust")->find();
if(!$cert){
throw new \think\Exception('缺少证书', 400);
}
$key = $cert->token;
$jwt = new JWT();
$data = $jwt::decode($token, new Key($key, 'HS512'));
$user = json_decode( json_encode($data), true);
$loginService = new LoginService();
$auth = $loginService->checkUser($user['accountId'], $nick);
$user['auth'] = $auth;
return $user;
}
}

18
app/task/controller/Base.php

@ -0,0 +1,18 @@
<?php
namespace app\task\controller;
use app\BaseController;
use log\LogOpe;
class Base extends BaseController
{
public function __construct()
{
parent::__construct();
$this->log = new LogOpe('api/'.get_class($this) . 'Controller');
}
}

186
app/task/controller/Goods.php

@ -0,0 +1,186 @@
<?php
namespace app\task\controller;
use app\service\task\GoodsService;
use think\facade\Db;
class Goods extends Base
{
public function __construct()
{
parent::__construct();
$this->redis = new \Redis();
$this->redis->connect('127.0.0.1', 6379);
}
/**
* @title 通过委托系统查询委托数据信息
* @url /task/Goods/getApiGoods
* @method POST
* @param string page 用户名/手机号 / 是
* @param string limit 密码 / 是
* @return string msg 返回信息
* @return int code 状态码 200:成功;>=400:失败
*/
public function getApiGoods(){
try {
if($this->redis->get('getApiGoods') > 0){
return ;
}
$this->redis->set('getApiGoods', 1);
$goodsService = new GoodsService();
Db::startTrans();
$goodsService->getApiGoods();
Db::commit();
$this->redis->set('getApiGoods', 0);
return _success('成功');
}catch(\Exception $e){
Db::rollback();
$this->redis->set('getApiGoods', 0);
return _error($e->getMessage(), $e->getCode() ?: 400, $e);
}
}
/**
* @title 通过委托系统查询撤销委托数据信息
* @url /task/Goods/getRevocationGoods
* @method POST
* @param string page 用户名/手机号 / 是
* @param string limit 密码 / 是
* @return string msg 返回信息
* @return int code 状态码 200:成功;>=400:失败
*/
public function getRevocationGoods(){
try {
if($this->redis->get('getRevocationGoods') > 0){
return ;
}
$this->redis->set('getRevocationGoods', 1, 20);
$goodsService = new GoodsService();
Db::startTrans();
$goodsService->getRevocationGoods();
Db::commit();
$this->redis->set('getRevocationGoods', 0);
return _success('成功');
}catch(\Exception $e){
Db::rollback();
$this->redis->set('getRevocationGoods', 0);
return _error($e->getMessage(), $e->getCode() ?: 400, $e);
}
}
/**
* @title 查询撤销结果
* @url /task/Goods/getRevocationResult
* @method POST
* @param string page 用户名/手机号 / 是
* @param string limit 密码 / 是
* @return string msg 返回信息
* @return int code 状态码 200:成功;>=400:失败
*/
public function getRevocationResult(){
try {
if($this->redis->get('getRevocationResult') > 0){
// return ;
}
$this->redis->set('getRevocationResult', 1, 30);
$goodsService = new GoodsService();
Db::startTrans();
$goodsService->getRevocationResult();
Db::commit();
$this->redis->set('getRevocationResult', 0);
return _success('成功');
}catch(\Exception $e){
Db::rollback();
$this->redis->set('getRevocationResult', 0);
return _error($e->getMessage(), $e->getCode() ?: 400, $e);
}
}
/**
* @title 委托数据过期
* @url /task/Goods/getRevocationGoods
* @method POST
* @param string page 用户名/手机号 / 是
* @param string limit 密码 / 是
* @return string msg 返回信息
* @return int code 状态码 200:成功;>=400:失败
*/
public function goodsPast(){
try {
if($this->redis->get('goodsPast') > 0){
return ;
}
$this->redis->set('goodsPast', 1);
$goodsService = new GoodsService();
Db::startTrans();
$goodsService->goodsPast();
Db::commit();
$this->redis->set('goodsPast', 0);
return _success('成功');
}catch(\Exception $e){
Db::rollback();
$this->redis->set('goodsPast', 0);
return _error($e->getMessage(), $e->getCode() ?: 400, $e);
}
}
/**
* @title 委托数据上架时间开始上架
* @url /task/Goods/goodsDatePutaway
* @method POST
* @param string page 用户名/手机号 / 是
* @param string limit 密码 / 是
* @return string msg 返回信息
* @return int code 状态码 200:成功;>=400:失败
*/
public function goodsDatePutaway(){
try {
if($this->redis->get('goodsDatePutaway') > 0){
return ;
}
$this->redis->set('goodsDatePutaway', 1);
$goodsService = new GoodsService();
Db::startTrans();
$goodsService->goodsDatePutaway();
Db::commit();
$this->redis->set('goodsDatePutaway', 0);
return _success('成功');
}catch(\Exception $e){
Db::rollback();
$this->redis->set('goodsDatePutaway', 0);
return _error($e->getMessage(), $e->getCode() ?: 400, $e);
}
}
/**
* @title 委托数据拼接
* @url /task/Goods/goodsJoinField
* @method POST
* @return string msg 返回信息
* @return int code 状态码 200:成功;>=400:失败
*/
public function goodsJoinField(){
try {
if($this->redis->get('goodsJoinField') > 0){
// return ;
}
$this->redis->set('goodsJoinField', 1);
$goodsService = new GoodsService();
Db::startTrans();
$goodsService->goodsJoinField();
Db::commit();
$this->redis->set('goodsJoinField', 0);
return _success('成功');
}catch(\Exception $e){
Db::rollback();
$this->redis->set('goodsJoinField', 0);
return _error($e->getMessage(), $e->getCode() ?: 400, $e);
}
}
}

166
app/task/controller/Order.php

@ -0,0 +1,166 @@
<?php
namespace app\task\controller;
use app\service\pay\PayService;
use app\service\task\OrderService;
use think\facade\Db;
class Order extends Base
{
public function __construct()
{
parent::__construct();
$this->redis = new \Redis();
$this->redis->connect('127.0.0.1', 6379);
}
/**
* @title 超时订单
* @url /task/Order/payTimeout
* @method POST
* @param string page 用户名/手机号 / 是
* @param string limit 密码 / 是
* @return string msg 返回信息
* @return int code 状态码 200:成功;>=400:失败
*/
public function payTimeout(){
try {
if($this->redis->get('payTimeout') > 0){
return ;
}
$this->redis->set('payTimeout', 1, 20);
$orderService = new OrderService();
Db::startTrans();
$orderService->payTimeout();
Db::commit();
$this->redis->set('payTimeout', 0);
return _success('成功');
}catch(\Exception $e){
Db::rollback();
$this->redis->set('payTimeout', 0);
return _error($e->getMessage(), $e->getCode() ?: 400, $e);
}
}
/**
* @title 用户下载资源状态
* @url /task/Order/orderSourceDownload
* @method POST
* @return string msg 返回信息
* @return int code 状态码 200:成功;>=400:失败
*/
public function orderSourceDownload(){
try {
if($this->redis->get('orderSourceDownload') > 0){
return ;
}
$this->redis->set('orderSourceDownload', 1);
$orderService = new OrderService();
Db::startTrans();
$orderService->orderSourceDownload();
Db::commit();
$this->redis->set('orderSourceDownload', 0);
return _success('成功');
}catch(\Exception $e){
Db::rollback();
$this->redis->set('orderSourceDownload', 0);
return _error($e->getMessage(), $e->getCode() ?: 400, $e);
}
}
/**
* @title 支付完成
* @url /task/Order/payComplete
* @method POST
* @return string msg 返回信息
* @return int code 状态码 200:成功;>=400:失败
*/
public function payComplete(){
try {
if($this->redis->get('payComplete') > 0){
return ;
}
$this->redis->set('payComplete', 1, 60);
$payService = new PayService();
$result = $payService->payComplete();
$this->redis->set('payComplete', 0);
return _success('成功', $result);
}catch(\Exception $e){
$this->redis->set('payComplete', 0);
return _error($e->getMessage(), $e->getCode() ?: 400, $e);
}
}
/**
* @title 订单结算
* @url /task/Order/orderClose
* @method POST
* @return string msg 返回信息
* @return int code 状态码 200:成功;>=400:失败
*/
public function orderClose(){
try {
if($this->redis->get('orderClose') > 0){
return ;
}
$this->redis->set('orderClose', 1);
$orderService = new OrderService();
$orderService->orderClose();
$this->redis->set('orderClose', 0);
return _success('成功');
}catch(\Exception $e){
$this->redis->set('orderClose', 0);
return _error($e->getMessage(), $e->getCode() ?: 400, $e);
}
}
/**
* @title 订单生成发票
* @url /task/Order/orderCreateBill
* @method POST
* @return string msg 返回信息
* @return int code 状态码 200:成功;>=400:失败
*/
public function orderCreateBill(){
try {
if($this->redis->get('orderCreateBill') > 0){
return ;
}
$this->redis->set('orderCreateBill', 1, 30);
$orderService = new OrderService();
$orderService->orderCreateBill();
$this->redis->set('orderCreateBill', 0);
return _success('成功');
}catch(\Exception $e){
$this->redis->set('orderCreateBill', 0);
return _error($e->getMessage(), $e->getCode() ?: 400, $e);
}
}
/**
* @title 支付完成
* @url /api/Pay/payComplete
* @method POST
* @return string msg 返回信息
* @return int code 状态码 200:成功;>=400:失败
*/
public function test(){
try {
$payService = new PayService();
$result = $payService->test();
return _success('成功', $result);
}catch(\Exception $e){
return _error($e->getMessage(), $e->getCode() ?: 400, $e);
}
}
}

2
clean_sh/ignore.sh

@ -0,0 +1,2 @@
#!/usr/bin/env bash
git update-index --assume-unchanged ../.env

2
clean_sh/no_ignore.sh

@ -0,0 +1,2 @@
#!/usr/bin/env bash
git update-index --no-assume-unchanged ../.env

51
composer.json

@ -0,0 +1,51 @@
{
"name": "topthink/think",
"description": "the new thinkphp framework",
"type": "project",
"keywords": [
"framework",
"thinkphp",
"ORM"
],
"homepage": "http://thinkphp.cn/",
"license": "Apache-2.0",
"authors": [
{
"name": "liu21st",
"email": "liu21st@gmail.com"
},
{
"name": "yunwuxin",
"email": "448901948@qq.com"
}
],
"require": {
"php": ">=7.2.5",
"topthink/framework": "^6.0.0",
"topthink/think-orm": "^2.0",
"topthink/think-multi-app": "^1.0",
"firebase/php-jwt": "^6.0",
"monolog/monolog": "^2.5"
},
"require-dev": {
"symfony/var-dumper": "^4.2",
"topthink/think-trace":"^1.0"
},
"autoload": {
"psr-4": {
"app\\": "app"
},
"psr-0": {
"": "extend/"
}
},
"config": {
"preferred-install": "dist"
},
"scripts": {
"post-autoload-dump": [
"@php think service:discover",
"@php think vendor:publish"
]
}
}

1238
composer.lock

File diff suppressed because it is too large

32
config/app.php

@ -0,0 +1,32 @@
<?php
// +----------------------------------------------------------------------
// | 应用设置
// +----------------------------------------------------------------------
return [
// 应用地址
'app_host' => env('app.host', ''),
// 应用的命名空间
'app_namespace' => '',
// 是否启用路由
'with_route' => true,
// 默认应用
'default_app' => 'api',
// 默认时区
'default_timezone' => 'Asia/Shanghai',
// 应用映射(自动多应用模式有效)
'app_map' => [],
// 域名绑定(自动多应用模式有效)
'domain_bind' => [],
// 禁止URL访问的应用列表(自动多应用模式有效)
'deny_app_list' => [],
// 异常页面的模板文件
'exception_tmpl' => app()->getThinkPath() . 'tpl/think_exception.tpl',
// 错误显示信息,非调试模式有效
'error_message' => '页面错误!请稍后再试~',
// 显示错误信息
'show_error_msg' => true,
];

81
config/cache.php

@ -0,0 +1,81 @@
<?php
// +----------------------------------------------------------------------
// | 缓存设置
// +----------------------------------------------------------------------
return [
// 默认缓存驱动
'default' => env('cache.driver', 'file'),
// 缓存连接方式配置
'stores' => [
'file' => [
// 驱动方式
'type' => 'File',
// 缓存保存目录
'path' => '',
// 缓存前缀
'prefix' => '',
// 缓存有效期 0表示永久缓存
'expire' => 0,
// 缓存标签前缀
'tag_prefix' => 'tag:',
// 序列化机制 例如 ['serialize', 'unserialize']
'serialize' => [],
],
// 更多的缓存连接
'redis_write0' => [
'host' => '10.24.4.58',
'port' => 6379,
'type' => 'redis',
'password' => '123qwe**',
'timeout' => 0,
'select' => 0
],
'redis_read0' => [
'host' => '10.24.4.58',
'port' => 6380,
'type' => 'redis',
'password' => '123qwe**',
'timeout' => 0,
'select' => 0
],
'redis_write1' => [
'host' => '10.24.4.61',
'port' => 6379,
'type' => 'redis',
'password' => '123qwe**',
'timeout' => 0,
'select' => 0
],
'redis_read1' => [
'host' => '10.24.4.61',
'port' => 6380,
'type' => 'redis',
'password' => '123qwe**',
'timeout' => 0,
'select' => 0
],
'redis_write2' => [
'host' => '10.24.4.64',
'port' => 6379,
'type' => 'redis',
'password' => '123qwe**',
'timeout' => 0,
'select' => 0
],
'redis_read2' => [
'host' => '10.24.4.64',
'port' => 6380,
'type' => 'redis',
'password' => '123qwe**',
'timeout' => 0,
'select' => 0
],
],
];

9
config/console.php

@ -0,0 +1,9 @@
<?php
// +----------------------------------------------------------------------
// | 控制台配置
// +----------------------------------------------------------------------
return [
// 指令定义
'commands' => [
],
];

20
config/cookie.php

@ -0,0 +1,20 @@
<?php
// +----------------------------------------------------------------------
// | Cookie设置
// +----------------------------------------------------------------------
return [
// cookie 保存时间
'expire' => 0,
// cookie 保存路径
'path' => '/',
// cookie 有效域名
'domain' => '',
// cookie 启用安全传输
'secure' => false,
// httponly设置
'httponly' => false,
// 是否使用 setcookie
'setcookie' => true,
// samesite 设置,支持 'strict' 'lax'
'samesite' => '',
];

63
config/database.php

@ -0,0 +1,63 @@
<?php
return [
// 默认使用的数据库连接配置
'default' => env('database.driver', 'mysql'),
// 自定义时间查询规则
'time_query_rule' => [],
// 自动写入时间戳字段
// true为自动识别类型 false关闭
// 字符串则明确指定时间字段类型 支持 int timestamp datetime date
'auto_timestamp' => true,
// 时间字段取出后的默认时间格式
'datetime_format' => 'Y-m-d H:i:s',
// 时间字段配置 配置格式:create_time,update_time
'datetime_field' => '',
// 数据库连接配置信息
'connections' => [
'mysql' => [
// 数据库类型
'type' => env('database.type', 'mysql'),
// 服务器地址
'hostname' => env('database.hostname', '127.0.0.1'),
// 数据库名
'database' => env('database.database', ''),
// 用户名
'username' => env('database.username', 'root'),
// 密码
'password' => env('database.password', ''),
// 端口
'hostport' => env('database.hostport', '3306'),
// 数据库连接参数
'params' => [],
// 数据库编码默认采用utf8
'charset' => env('database.charset', 'utf8'),
// 数据库表前缀
'prefix' => env('database.prefix', ''),
// 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)
'deploy' => 0,
// 数据库读写是否分离 主从式有效
'rw_separate' => false,
// 读写分离后 主服务器数量
'master_num' => 1,
// 指定从服务器序号
'slave_no' => '',
// 是否严格检查字段是否存在
'fields_strict' => true,
// 是否需要断线重连
'break_reconnect' => false,
// 监听SQL
'trigger_sql' => false,
// 开启字段缓存
'fields_cache' => false,
],
// 更多的数据库配置信息
],
];

16
config/festivals.php

@ -0,0 +1,16 @@
<?php
return [
"2022" => [
"festivals" => [
"2022-05-01",
"2022-05-02",
"2022-05-03",
"2022-05-04",
"2022-05-05",
],
"workday" => [
"2022-04-24"
],
],
];

24
config/filesystem.php

@ -0,0 +1,24 @@
<?php
return [
// 默认磁盘
'default' => env('filesystem.driver', 'local'),
// 磁盘列表
'disks' => [
'local' => [
'type' => 'local',
'root' => app()->getRuntimePath() . 'storage',
],
'public' => [
// 磁盘类型
'type' => 'local',
// 磁盘路径
'root' => app()->getRootPath() . 'public/uploads',
// 磁盘路径对应的外部URL路径
'url' => '/uploads',
// 可见性
'visibility' => 'public',
],
// 更多的磁盘配置信息
],
];

15
config/jwt.php

@ -0,0 +1,15 @@
<?php
// +----------------------------------------------------------------------
// | jwt设置
// +----------------------------------------------------------------------
return [
// 密钥
'key' => 'wenhuayun_token_',
// 签发时间
'lat' => time(),
// 生效时间
'nbf' => time(),
// 过期时间
'exp' => time() + 3600,
];

27
config/lang.php

@ -0,0 +1,27 @@
<?php
// +----------------------------------------------------------------------
// | 多语言设置
// +----------------------------------------------------------------------
return [
// 默认语言
'default_lang' => env('lang.default_lang', 'zh-cn'),
// 允许的语言列表
'allow_lang_list' => [],
// 多语言自动侦测变量名
'detect_var' => 'lang',
// 是否使用Cookie记录
'use_cookie' => true,
// 多语言cookie变量
'cookie_var' => 'think_lang',
// 多语言header变量
'header_var' => 'think-lang',
// 扩展语言包
'extend_list' => [],
// Accept-Language转义为对应语言包名称
'accept_language' => [
'zh-hans-cn' => 'zh-cn',
],
// 是否支持语言分组
'allow_group' => false,
];

45
config/log.php

@ -0,0 +1,45 @@
<?php
// +----------------------------------------------------------------------
// | 日志设置
// +----------------------------------------------------------------------
return [
// 默认日志记录通道
'default' => env('log.channel', 'file'),
// 日志记录级别
'level' => [],
// 日志类型记录的通道 ['error'=>'email',...]
'type_channel' => [],
// 关闭全局日志写入
'close' => false,
// 全局日志处理 支持闭包
'processor' => null,
// 日志通道列表
'channels' => [
'file' => [
// 日志记录方式
'type' => 'File',
// 日志保存目录
'path' => '',
// 单文件日志写入
'single' => false,
// 独立日志级别
'apart_level' => [],
// 最大日志文件数量
'max_files' => 0,
// 使用JSON格式记录
'json' => false,
// 日志处理
'processor' => null,
// 关闭通道日志写入
'close' => false,
// 日志输出格式化
'format' => '[%s][%s] %s',
// 是否实时写入
'realtime_write' => false,
],
// 其它日志通道配置
],
];

8
config/middleware.php

@ -0,0 +1,8 @@
<?php
// 中间件配置
return [
// 别名或分组
'alias' => [],
// 优先级设置,此数组中的中间件会按照数组中的顺序优先执行
'priority' => [],
];

45
config/route.php

@ -0,0 +1,45 @@
<?php
// +----------------------------------------------------------------------
// | 路由设置
// +----------------------------------------------------------------------
return [
// pathinfo分隔符
'pathinfo_depr' => '/',
// URL伪静态后缀
'url_html_suffix' => 'html',
// URL普通方式参数 用于自动生成
'url_common_param' => true,
// 是否开启路由延迟解析
'url_lazy_route' => false,
// 是否强制使用路由
'url_route_must' => false,
// 合并路由规则
'route_rule_merge' => false,
// 路由是否完全匹配
'route_complete_match' => false,
// 访问控制器层名称
'controller_layer' => 'controller',
// 空控制器名
'empty_controller' => 'Error',
// 是否使用控制器后缀
'controller_suffix' => false,
// 默认的路由变量规则
'default_route_pattern' => '[\w\.]+',
// 是否开启请求缓存 true自动缓存 支持设置请求缓存规则
'request_cache_key' => false,
// 请求缓存有效期
'request_cache_expire' => null,
// 全局请求缓存排除规则
'request_cache_except' => [],
// 默认控制器名
'default_controller' => 'Index',
// 默认操作名
'default_action' => 'index',
// 操作方法后缀
'action_suffix' => '',
// 默认JSONP格式返回的处理方法
'default_jsonp_handler' => 'jsonpReturn',
// 默认JSONP处理方法
'var_jsonp_handler' => 'callback',
];

19
config/session.php

@ -0,0 +1,19 @@
<?php
// +----------------------------------------------------------------------
// | 会话设置
// +----------------------------------------------------------------------
return [
// session name
'name' => 'PHPSESSID',
// SESSION_ID的提交变量,解决flash上传跨域
'var_session_id' => '',
// 驱动方式 支持file cache
'type' => 'file',
// 存储连接标识 当type使用cache的时候有效
'store' => null,
// 过期时间
'expire' => 1440,
// 前缀
'prefix' => '',
];

10
config/trace.php

@ -0,0 +1,10 @@
<?php
// +----------------------------------------------------------------------
// | Trace设置 开启调试模式后有效
// +----------------------------------------------------------------------
return [
// 内置Html和Console两种方式 支持扩展
'type' => 'Html',
// 读取的日志通道名
'channel' => '',
];

50
config/upload.php

@ -0,0 +1,50 @@
<?php
// 文件上传配置
return [
/*
* 上传地址,默认是本地上传
*/
'uploadurl' => 'ajax/upload',
/*
* CDN开关
*/
'onoffcnd' => false,
/*
* CDN地址
*/
'cdnurl' => '',
/*
* OSS_KEY
*/
'oss_key' => '',
/*
* OSS_SECRET
*/
'oss_secret' => '',
/*
* OSS_BUCKET
*/
'oss_bucket' => '',
/*
* UPLOAD_IMAGE_PATH
*/
'upload_imgage_path' => strtoupper(substr(PHP_OS,0,3))==='WIN' ? 'd:/tmp/images/' : '/tmp/images/',
/*
* 文件保存格式
*/
'uploaddir' => 'uploads',
/*
* 最大可上传大小 15m
*/
'maxsize' => '15',
/*
* 可上传的文件类型
*/
'mimetype' => 'jpg,png,gif,jpeg,bmp,webp,mp3,mp4',
/*
* 是否支持批量上传
*/
'multiple' => true,
];

18
config/userauth.php

@ -0,0 +1,18 @@
<?php
return [
"NationalCulturalDataQuery" => ['goods.Goods/list', 'goods.Goods/offGoods', 'goods.Goods/goodsDetail', 'goods.Goods/sourceDetail'],
"CulturalDataCategoryManagement" => ['goods.Classify/getTop', 'admin/user.User/getUser', 'goods.Classify/list', 'goods.Classify/updateStatus', 'Log/getLog', 'goods.Classify/addClass'],
"CulturalDataAdmissionManagement" => ['goods.Goods/list', 'goods.Goods/manualGetGoods', 'goods.Goods/goodsDetail', 'goods.Goods/sourceDetail'],
"AllTradeOrders" => ['order.Order/list', 'order.Order/orderDetail', 'goods.Goods/sourceDetail', 'order.Order/orderInfo', 'order.Order/orderShut'],
"PendingPayment" => ['order.Order/list', 'order.Order/orderDetail', 'goods.Goods/sourceDetail', 'order.Order/orderInfo', 'order.Order/orderShut'],
"PendDelivery" => ['order.Order/list', 'order.Order/orderDetail', 'goods.Goods/sourceDetail', 'order.Order/orderInfo', 'order.Order/orderShut'],
"PendBalance" => ['order.Order/list', 'order.Order/orderDetail', 'goods.Goods/sourceDetail', 'order.Order/orderInfo', 'order.Order/orderShut'],
"OrderCompleted" => ['order.Order/list', 'order.Order/orderDetail', 'goods.Goods/sourceDetail', 'order.Order/orderInfo', 'order.Order/orderShut'],
"OrderClosed" => ['order.Order/list', 'order.Order/orderDetail', 'goods.Goods/sourceDetail', 'order.Order/orderInfo', 'order.Order/orderShut'],
"ServiceInvoice" => [],
"FundsSettlementStatement" => ['order.AccountClose/closeList', 'order.AccountClose/getCloseAccountInfo', 'order.AccountClose/getBillDetail'],
"AccountSharingRatioSetting" => ['order.AccountClose/ratioList', 'user.User/getUser', 'order.AccountClose/ratioStatus', 'order.AccountClose/ratioDetail', 'order.AccountClose/setRatio'],
"PaymentMethodSettings" => ['order.AccountClose/getPaySetting', 'order.AccountClose/setPaySetting'],
"DataDisplayLayoutManagement" => ['goods.Goods/rankingList', 'goods.Goods/delRanking', 'goods.Goods/list', 'goods.Goods/addRanking', 'goods.Goods/rankingSort']
];

25
config/view.php

@ -0,0 +1,25 @@
<?php
// +----------------------------------------------------------------------
// | 模板设置
// +----------------------------------------------------------------------
return [
// 模板引擎类型使用Think
'type' => 'Think',
// 默认模板渲染规则 1 解析为小写+下划线 2 全部转换小写 3 保持操作方法
'auto_rule' => 1,
// 模板目录名
'view_dir_name' => 'view',
// 模板后缀
'view_suffix' => 'html',
// 模板文件名分隔符
'view_depr' => DIRECTORY_SEPARATOR,
// 模板引擎普通标签开始标记
'tpl_begin' => '{',
// 模板引擎普通标签结束标记
'tpl_end' => '}',
// 标签库标签开始标记
'taglib_begin' => '{',
// 标签库标签结束标记
'taglib_end' => '}',
];

2
extend/.gitignore

@ -0,0 +1,2 @@
*
!.gitignore

0
public/.htaccess

52
public/cert/distribute/private_key.pem

@ -0,0 +1,52 @@
-----BEGIN PRIVATE KEY-----
MIIJQQIBADANBgkqhkiG9w0BAQEFAASCCSswggknAgEAAoICAQCn1D5uuFZMt3ug
pFdxF7eTVfkXs69rLM/tCTDGm9T1R5czS5RPY8KkzvYbKpSfVqf+tyEQsJp6QO8f
PWPiv0F0aj7sA7pY1cKDV9uskpk3clOqAvvdIVyEl6soFGTpmG9dAF8QUrj49SSW
+TdfwG3CSVMMYD/c/PRubBRw/1tp1vVYc6z6TvFHlXeQJ+stosnbVR3OZsbRIvdu
BxCyjUGBWDLccVlZ/carRVcZvxcB9UUoZ5gv+syneSF9f2o5js9IfeCTGdzOr87A
z0AK1RjjZVTPLSVkVXOoBQ6WmBdNEEZIZ1NvfomyL35rF17Uj3OnDaYCflfK4iud
3MVhE3KgdCHfUjOvgYWBvcc24yn/cAT8RjBb9I83JGAgmkNRVXnfulZXDKfsjobZ
9sWJ6PfPdVsF5qU0PFePxu/AM+uw/iISJN/RsgWDUQhCIj5khokS3Hcg25p/6/D2
nL5yXr7Vk2KB9qtDc2EbPVE2tYkshiosZ18DFZxWOx4h5zCidbhg7pLaPCzXQvT2
SYjql33EOIYeIut52ocybrH2zy7tlEO6xcDk+GqsxfpBeGna7ztkkCL8S0tt0b9K
TNoMJVzOaR9kqSStPGZPhvUP2/X49CJ1CnoSP0c5H7tjTFDKhiwMKDcN9H+570Jn
UnhbtxnOQOl91gQyhnVz0i/XQYfBVwIDAQABAoICABIGktoThHli761WWWn1MStq
/YEVNI8fVgnQheOfEyVxFgVVZc2NGnfXHsnWLfZbOVn7U1rWjRD6bnR9hH/zKNWX
H8D7uYUXGHhA9IA5kqlI50GIZoLetXAsVh7M6fXJAJUNmChJqkJbGh35EICBS4il
lXzrzZAvvxUpGJz2YFwi0WE5s2eDGRkmLZxXHUReiq27G6NymIIX7llr+tgiodmB
npzcs8sdnbwBi5RhWNhF/rKTRd5JYrfOI9G14LPj6dGQa5GBIp00dtFwsSE4uB6c
YJqL78sx/mUaffGgzkfhqprWNjjwb1urDDn2XaIY8kQMDDuSVF2fIy4mazC9BP+Y
Ul7i8vdaprQTuI9CK6ImYutiCcFBplTi7jIiGSGhdOeP1JItaIdP/3eD03xr9BtS
BLukenF49dS8VJOpHaLS2JUcONNwTQx9NzTi0j2JqKYrcFJwfI59Zgl+A3t4GmnB
IbcguV4s/n81/nlZvnKbTPjdUlZG+bualKhL/ikQJa5lxyKGMjjvavZzycOLeAdP
MVrQInsraoumQpzpaW+YCzCbkSP2IJMxLLJ8j7+Q11jVipSNwE9FNhArxfOoXnAR
XwchzRonq7mM+3P0lXyv3f7BgDle0IBP4ZGl1vwlVJxSYIqXigWY8O1RklkTCvBi
wxO/WM74i0Py75LnAR35AoIBAQDRTalkCfcB3GI8q7qzkELmizEyC38vpKRXsaCP
7p4qCynBj6uRNnrJl+1J+tJDwjLyDQAFwg0IiOhsEA3qXojV5SBYcJBjDTQGp1Vz
5LCtG+3OW/Ebb1PyXzDOW390jZR76gtmQg6bHjxOIpUiz+cI5jgQYr0mst8GfLyY
NKHevCZh7FN9V3BDxFnwX2ilLmgEsdi4CfrHIAyiJwq6nwgHZ5uksj+xfebweMT4
yebI5imuHrAB45c+wypaD62GuJst3GRETdncaQz0HH2NjYVhX9cdz4ygi1QaGZYS
eSCqYJMR/a39lQQFli8FExY3XhXR4ETkRlRFnW8tvnlBatZVAoIBAQDNRchpiAOT
6nzY/NOy9/TVz7RsJsd6jp0VFsRnK7jbsU0qogKDdHkiC6MgaIM4z6jfrfnny1VW
9v9vMU7wXULoNtYOaPB0vUpxobGUq1+yEYm4gzSq206G4SIlDeascUS+v/27IFO1
borU73ItOck57P2aZ+cuYAsR2jVQfshQ6XFN28uwS5id8YP9gUDf0FT+TnhaNpac
MkPYwMczknE5sTgWQ8wukxyxGssLtXq6rzfeSsb7p3JJU26xW8rzYJMbSkHKjd8Y
DmG3SZJXYAEI+GuJIBtiqEmIDg1m6q9WuvAWAslSb05olK4L3wK/fMAeURrjZGOt
eAXfH4HELSz7AoIBADhzhdhhh6mM00Ih3z1HD4Q2zpH839TtxxWP5wprBWW5lQ2L
vm5wDzYIMAvgBo4X9r2qG/NxnypKIsXinp4z2Rw3rD2uPoM4sGuK/lU/vRczjTQ3
QBRyNmYMnpFJxFqfRQkW2vQ9pMrZoNJCKY82G84eqchhmTqyy8xoIEW9DFuSy5dl
si8AQltEvi1Czmqe1ZdOkHEy39yNHFsvxIkJE5VLsIL/QIaSupLpP9cKPaC500wP
ItGfnM9kvCuGRvsrF0+LPc/eX4A/JStB8+sV3H+i5dY4gGlcqtZPSFa7LMBHQ+N6
VE8sveTz2MK5nyhXy/LLVklrXpdYGwBveyzVr/ECggEAch7Qq7L9YjekDzKIM2Bc
0p21zcbFceJlfDr7F+ybyi/JGeGWCiUvzvivSS4xfd0dIrXjULWfjUime9fq7gC7
WMRbvwkiXZR7Fa9yPZgFDMdpTJZNKovgHWZ+iCExVD9om6+7TVRMlXqOXpF8ZZ5R
vA2AdF49jW/B17v7lfPWQ/10i3edxzZP88c4vTAltAhrqDJSAL2Gf/IF/DQ4yvgo
UI2xA9fPZTlOYzvlFG5he/Y71i62b2QJSrDCwoGo1COlxS9EYmr7U7FzK+YQINlz
2dvaVRLvhqrOroA5fTUOI+ar4WDNMjJFYij+lgT2zyR43qHyk+bU77ThdslaaIlB
DwKCAQB/lcLJStN0hEZi6AJ+dPKXHpwjuQjjV5JEWBmBJ6GPYHApTfym2Tyd7zEt
Ix3loOIoMbDGa4kc/jSdZCoOJ+DQiQlbBtDsGXHcu16bzhlaO0EFkYC/cQmx5Iph
KWXaH+QM6H/Ch4rBjppIXA5nV4fc0KyMRRRuxXTieOEPF6LItcNGwInRo1z/hsNj
Q56Ivt6hF2o61unQmNlsfJhORejP8ssgAwJ4S7dJ8or1WoT7HSnh27QHvuWjIDx4
9MVtktPTdclR8Ht3O5V+nAy3U2MsZBOqZgEb2E8DviRUERNV1tXzdAzeFeU5fkCy
HykFkdGcDqftaxq8ztgBWA+meCLg
-----END PRIVATE KEY-----

14
public/cert/distribute/public_key.pem

@ -0,0 +1,14 @@
-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAp9Q+brhWTLd7oKRXcRe3
k1X5F7OvayzP7QkwxpvU9UeXM0uUT2PCpM72GyqUn1an/rchELCaekDvHz1j4r9B
dGo+7AO6WNXCg1fbrJKZN3JTqgL73SFchJerKBRk6ZhvXQBfEFK4+PUklvk3X8Bt
wklTDGA/3Pz0bmwUcP9badb1WHOs+k7xR5V3kCfrLaLJ21UdzmbG0SL3bgcQso1B
gVgy3HFZWf3Gq0VXGb8XAfVFKGeYL/rMp3khfX9qOY7PSH3gkxnczq/OwM9ACtUY
42VUzy0lZFVzqAUOlpgXTRBGSGdTb36Jsi9+axde1I9zpw2mAn5XyuIrndzFYRNy
oHQh31Izr4GFgb3HNuMp/3AE/EYwW/SPNyRgIJpDUVV537pWVwyn7I6G2fbFiej3
z3VbBealNDxXj8bvwDPrsP4iEiTf0bIFg1EIQiI+ZIaJEtx3INuaf+vw9py+cl6+
1ZNigfarQ3NhGz1RNrWJLIYqLGdfAxWcVjseIecwonW4YO6S2jws10L09kmI6pd9
xDiGHiLredqHMm6x9s8u7ZRDusXA5PhqrMX6QXhp2u87ZJAi/EtLbdG/SkzaDCVc
zmkfZKkkrTxmT4b1D9v1+PQidQp6Ej9HOR+7Y0xQyoYsDCg3DfR/ue9CZ1J4W7cZ
zkDpfdYEMoZ1c9Iv10GHwVcCAwEAAQ==
-----END PUBLIC KEY-----

52
public/cert/entrust/private_key.pem

@ -0,0 +1,52 @@
-----BEGIN PRIVATE KEY-----
MIIJQgIBADANBgkqhkiG9w0BAQEFAASCCSwwggkoAgEAAoICAQCcWC6YrcfF2cwC
Hn9G4aLiwsE5mELckpl1TwAHxsfRw10KaDkGcEiZ83ZWBPJzWKFQKK+k5etPj8PC
5+zpTbfdo0UlQUNwpIReFvBjOVD66FiOkN6PDA0MTWMoF/hoiHUDNBeHVDVedUfu
y6KcrEXu934WKGUPry+wScJhwllnircsR4+Y0JIT7MW+GBraB0VYt+G4ySXVbP00
kHFD/Yl5WCPPA3AsOfJ46/HtxnEqyl7wzNVriHKhsgXo/GXYUpwHwbyI5LNVWmAd
B7i9BLA7k0nHvCclniYaoffSfCpr9CiKjj+TsJRF1b7RoLg9V33vKypOyBwCZ7yN
UhP0dIxdxwm1qLTNafxpXJkAp0nzh/uj3iEc5k+bNgrusElAOOauqlqEecHAZFQq
5u33ty2FHvUolsspP80wRP5ifeY3SHDUyxY0a35ubQsuxt3BNRAaehSLqA0BE3RI
DJe9hN+ct+Ige30GjEh1662/Lcoj33clSs9Trs8q9Xp4O0e2Hxin9BjSi9CwNkWU
p+xMx7hJPSZrV0wc4GdOtbjOUsRufai9PUU7tkpIjOdWFo+Em8YYGgcDrT2F3Q14
8qnfcMD6u/GWjO5o3/AyJ1I7GxK4Yt/jQYgBq4rHRCj8Hlh98an4pnCIEhXFuFLx
9sxZ5UZNtNU2RGp2/ol6Pbcd5YE3CQIDAQABAoICADHgI8VLMv7YEy/d4MaQ9rCW
ZqPkAfhxwAjfUegpLtepFkZap055hX+vXmHkpB/N93Al+pqFSoMQHuhPqpFm3LAV
BNr0rfoCUcPeV4Of5kiU1KNubcF+m68ABRDmTLW0SnfiJ1thrsDacz8nsVF/17N7
OrsA2fSd832umhcrs+/HHdY/YfzjFKbMkuyorfA9/45k4tpbOPmUElaxeaCyAig2
yP2iYCeLuOGAi6ZJ9xIqiw0Qm0j5t3AD5cTEuAzBlcsXr/iP1PH2qdC5BOMv2rS2
sQPJ70cd45P9dZytRa84rbI93ORVoYeBv6UKO5w+DAu/XnjRd7YAt/LxazJB+AD2
8o7q0A9s1SRISX4RCgIXJp0+dB7Xdu+XmN+VugLSC8fEDbjNMFRaPd1E2C6Udm6A
qSn4PRkfNhYo2YlysPUT1jw+VOseD4ISiEPyRad/HIhkvmvaloTx82HL4W0C1G5x
fZEcU3/TWJtcrwVlQMMfGjUs2QIioqdyiXFzyfPY19KzNYBJbK0r3XgENS3TmVOr
CZzrKchhJKlreKfxkwmjNwVlCqkh9iTzmYG0kMKcgtPVmfri6OMIjsbuMjCTFgCp
v317nt2zuH/JgKwjTqaJRG+TTtHEt4yKP91U+R4EqqpOwEtBmarIq37rPwLyAlyl
GecQtkFmvdWAF+Tu7xSBAoIBAQDLvo/xa3dsk5k9Nv9Q76O6LLd1nuoD6JS/2sw5
p/tiyjboZ/UPbC9nwYCZ/LI4MjZQ0s+u16MK0EBu22Zf5B9YOLlaQewyS6cN5emf
HMezdKFSbpvnz1wHWV9WG4+voJ1v0hklyWPD9kYALUhwZa0iC13jfApTanogLcg3
ll8gLA4VQD115DX1/q5EN0vCbzrWtGNaat2YvhbXEL1zgy0FxWwuGp7PIwGKYQYq
v3j6NY77CQMICiQnhXoayzG62/iiF9DuUKS1K8WhzhVHPhiubqUxmaSOdWJ61wwM
2IuLFQIxTY6BTv/IBbRLNWQFliovlUnRncjyIOqSq2E1F5+5AoIBAQDEcXAr5J7M
VoSasJM9GnEYaBmQ3Ne6R36TX6qUld/nEBDz/3SmSF9HQ1A1JT66o0GwpAkT8hZS
xt84n+CNNaimFf4SLPotC0BTCAxk/pSgArPBL9EaMrQjpc3FcgRrFD9iKw6+fyQW
pSYMEWpn8mygoTL8IgnfYa1zigidP6PVdJioanWty5S60GjP0CmNpxrDSyehgFYB
ys+RV6/EznvJZ7YNg0MtqtLDBJzRJndktx1NG6c5Pe/zS7u6+IrMKR3G7XusJ5a1
IUTvNPQT1hIVaJM6Lsg8ZtFc1tvwp2yFEBVh8RojQsIjgXHyMYkEo4fr4Mrg0HMp
6lC7NDrfdNnRAoIBAF3qRC2TTOQ2kP8/l6a2H7FUpWhJTTNqBQ7+iv7UqLLb5T1x
let7AcsAzgetDHWM566Pzf2ZFmWIovq2lVUEMVKYKxAorPhuGN32KZ8XRBI7Y5U8
uQ68bX5RuvlVEQFytr9xh/f8Acm1foTcWrS8mXbE6I1Qgu36ebrVf6Hn5YdN51vy
VaI/BISU1b1KA9jnLqcDVXy7H9QlYx/Vbo6NW7Z6TyhdSvDOAQrJOG+B/QDQqUyb
1dLh4dJ521P4b77jYJNPCRahA5sjRyETfoltXTEifXEEkm68Ox3GfJ57Pq9oiq8x
QcvnH04TGw1D2gwdMOroFLPT2GmLtLTQ3Kj9b7kCggEAUDDCiph0HpP+46rLIDlo
C3+LWDBevAMtb3mxB6C62vcbBI+2jZ6jjlKzLk668bNtQG9l6Ud8x2O5gcL6Boru
AoadxcuogLTEGGEDtkKaZ0tTF7yuTlR+ZsLrYftuREvqp+dNyIPcNoZKJskBN9el
clj7mCNJBnA4Px8M7ywodB15p951lXGykCQ9dP/Txqh9a1WFow7hjS++VeWGsf9c
VtZIYfHAfabrDIMYhOR//pQlmPF97QcUqauzwdptxnPOXQNa5ebvRZeELWXfcS2F
Cko7N5gbU1ThiFWJSQ7/ZL4xDF9AvT4mRBo2apjABy2+cZK9HtLZADZPqGvk0I1B
0QKCAQEAvSFYQGt79lXVx2/DIvevAqX9VXk2/K0wEey0PQhQsqeKiUlaK6BToXYW
Pq1vmeMnhjvTcuswwG7MeARcuKPlh++YmLJSFcgX+nIIkXF07w883LeSAvhRpJmD
njNrxuzsBtet0y84+Y4HXib+ELYf3VzLpdOQ37fvW8WziuKcsN6f/2sNPRTdHKoJ
pHmTP22NqtePbeKNnhCZ51oRc92yCezsk1/LLtNgU7QdWLsW2kKySKAn7N2trhS7
UJsCt712PV/tcGhGjqQNb0wVIxwxv3sH7p2QDY4a9aTuFJqJDyQuaxMt3ZeiN4JX
xLbJz5Sl6gVj8/rJwUX1D1oSP0t/7A==
-----END PRIVATE KEY-----

14
public/cert/entrust/public_key.pem

@ -0,0 +1,14 @@
-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAnFgumK3HxdnMAh5/RuGi
4sLBOZhC3JKZdU8AB8bH0cNdCmg5BnBImfN2VgTyc1ihUCivpOXrT4/Dwufs6U23
3aNFJUFDcKSEXhbwYzlQ+uhYjpDejwwNDE1jKBf4aIh1AzQXh1Q1XnVH7suinKxF
7vd+FihlD68vsEnCYcJZZ4q3LEePmNCSE+zFvhga2gdFWLfhuMkl1Wz9NJBxQ/2J
eVgjzwNwLDnyeOvx7cZxKspe8MzVa4hyobIF6Pxl2FKcB8G8iOSzVVpgHQe4vQSw
O5NJx7wnJZ4mGqH30nwqa/Qoio4/k7CURdW+0aC4PVd97ysqTsgcAme8jVIT9HSM
XccJtai0zWn8aVyZAKdJ84f7o94hHOZPmzYK7rBJQDjmrqpahHnBwGRUKubt97ct
hR71KJbLKT/NMET+Yn3mN0hw1MsWNGt+bm0LLsbdwTUQGnoUi6gNARN0SAyXvYTf
nLfiIHt9BoxIdeutvy3KI993JUrPU67PKvV6eDtHth8Yp/QY0ovQsDZFlKfsTMe4
ST0ma1dMHOBnTrW4zlLEbn2ovT1FO7ZKSIznVhaPhJvGGBoHA609hd0NePKp33DA
+rvxlozuaN/wMidSOxsSuGLf40GIAauKx0Qo/B5YffGp+KZwiBIVxbhS8fbMWeVG
TbTVNkRqdv6Jej23HeWBNwkCAwEAAQ==
-----END PUBLIC KEY-----

16
public/cert/user_real/private_key.pem

@ -0,0 +1,16 @@
-----BEGIN PRIVATE KEY-----
MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAO/lIZiFw52gTaRF
KDtwxS3qMw+j1/sqePrSeZll+TC+nHigS0N0AHvROYd7irXZ19BLKR/NLNfuKc4O
BYEU5WIkvQZgchGaZukxihtTJ06S/PvVK5FAkE7NSWAhRjqEMXlr7KGnA/da12Jv
lWmtIGysjLm7wn1SWfjA2LZeAa8hAgMBAAECgYArRSwLI82F5/05LRQ1rICUaJLv
NkFl12Jc84vlZGRPK4Jzq44Hy6uuqa1zx4/cfz+THYt8Zfi5tgaqWRMbFlbNRKSb
WWn3eHfRt65D2MGT0l/mIUQicxiaA79a8I1D5LKZM/5fKrIiI1hoSPt8ZHPlXUnI
/HnlzD55e3gQDf+g8QJBAPtYKWyMHOTey+sRLWDazF0Qb1tRXxktlc7B1H50Wr9A
ijEyvZ4KDVO2OczpHbzZYjs4K9VXyLiX1PJicvY9Ck0CQQD0Vq2nnh/Lvq807lxO
kUbZ/66aVMbzJjvmRC3jOLBdQu1768iYUDJfFf32xQqwcy4xgXazT28lQ0hipQ0n
oPolAkBRy88vVCnTEe6rAVwTOSFo6ABVZ5XbS8qFDu9od9VQiGBwwmKTHBJaO+Nz
nCnhW51sSEt7kqXv7PmQKBnhqNvBAkBkx0eS5iZpK/oqE9Jg2Yzmp43FvAffDDsS
i7Z9jMk5fjxjq2muYQ2VqIV6feUdyDQaWTKzXKUUMn8tqLQXT089AkEAyHX6NXSA
eMxyAN9YfYFsoo6b9xEViHlnDEPfrQhlHoMOBUx0PhplgPernluCA50lALHby0h+
1Fjr+wGdYuodWg==
-----END PRIVATE KEY-----

6
public/cert/user_real/public_key.pem

@ -0,0 +1,6 @@
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDv5SGYhcOdoE2kRSg7cMUt6jMP
o9f7Knj60nmZZfkwvpx4oEtDdAB70TmHe4q12dfQSykfzSzX7inODgWBFOViJL0G
YHIRmmbpMYobUydOkvz71SuRQJBOzUlgIUY6hDF5a+yhpwP3Wtdib5VprSBsrIy5
u8J9Uln4wNi2XgGvIQIDAQAB
-----END PUBLIC KEY-----

BIN
public/favicon.ico

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

24
public/index.php

@ -0,0 +1,24 @@
<?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 think;
require __DIR__ . '/../vendor/autoload.php';
// 执行HTTP应用并响应
$http = (new App())->http;
$response = $http->run();
$response->send();
$http->end($response);

0
public/nginx.htaccess

2
public/robots.txt

@ -0,0 +1,2 @@
User-agent: *
Disallow:

19
public/router.php

@ -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>
// +----------------------------------------------------------------------
// $Id$
if (is_file($_SERVER["DOCUMENT_ROOT"] . $_SERVER["SCRIPT_NAME"])) {
return false;
} else {
$_SERVER["SCRIPT_FILENAME"] = __DIR__ . '/index.php';
require __DIR__ . "/index.php";
}

2136
ranking.sql

File diff suppressed because one or more lines are too long

17
route/app.php

@ -0,0 +1,17 @@
<?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>
// +----------------------------------------------------------------------
use think\facade\Route;
Route::get('think', function () {
return 'hello,ThinkPHP6!';
});
Route::get('hello/:name', 'index/hello');

2
runtime/.gitignore

@ -0,0 +1,2 @@
*
!.gitignore

19
sql/22-03-30/update.sql

@ -0,0 +1,19 @@
ALTER TABLE `order`
add `history_buy_name` varchar(200) NOT NULL DEFAULT '''' COMMENT '''' AFTER `order_islicode`;
ALTER TABLE `order`
add `history_buy_code` varchar(200) NOT NULL DEFAULT '''' COMMENT '''' AFTER `history_buy_name`;
ALTER TABLE `order_goods_detail`
add `history_entrust_name` varchar(200) NOT NULL DEFAULT '''' COMMENT '''' AFTER `contract_code`;
ALTER TABLE `order_goods_detail`
add `history_entrust_code` varchar(200) NOT NULL DEFAULT '''' COMMENT '''' AFTER `history_entrust_name`;
ALTER TABLE `order_goods_detail`
add `identifiers` text DEFAULT null COMMENT ''ISLI标志码/ISLI编码'' AFTER `identifier`;
ALTER TABLE `order_goods_detail`
add `close_serial_number` varchar(255) NOT NULL DEFAULT '''' COMMENT '''' AFTER `identifiers`;
ALTER TABLE `order`
add `ticketimage` varchar(255) NOT NULL DEFAULT '''' COMMENT ''url'' AFTER `ticketurl`;
ALTER TABLE `goods_detail`
add `identifiers` text DEFAULT null COMMENT ''ISLI标志码/ISLI编码'' AFTER `identifier`;

33
sql/22-03-31/update.sql

@ -0,0 +1,33 @@
ALTER TABLE `order`
add `source_url` varchar(255) NOT NULL DEFAULT '' COMMENT '资源下载链接' AFTER `createtime`;
ALTER TABLE `order`
add `source_status` int(1) NOT NULL DEFAULT '0' COMMENT '资源下载状态' AFTER `source_url`;
-- 修改user表
CREATE TABLE `user` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`user_isli` varchar(200) NOT NULL COMMENT '用户ISLI标识码',
`username` varchar(200) NOT NULL COMMENT '用户名称',
`institution_code` varchar(255) NOT NULL DEFAULT '' COMMENT '机构代码',
`agency_type` int(1) NOT NULL COMMENT '机构类型;1:个人;2:组织',
`cert_type` varchar(20) NOT NULL DEFAULT '身份证' COMMENT '个人-证件类型',
`idNumber` varchar(25) NOT NULL DEFAULT '' COMMENT '个人-证件号码',
`cell_phone` varchar(20) NOT NULL DEFAULT '' COMMENT '个人-手机号码',
`bank_account` varchar(50) NOT NULL DEFAULT '' COMMENT '银行账户',
`legals_name` varchar(20) NOT NULL DEFAULT '' COMMENT '机构-法人名称',
`legals_type` varchar(20) NOT NULL DEFAULT '' COMMENT '机构-法人证件类型',
`legals_idnum` varchar(50) NOT NULL DEFAULT '' COMMENT '机构-法人证件号',
`legals_phone` varchar(20) NOT NULL DEFAULT '' COMMENT '机构-法人手机号',
`bank_card_type` varchar(20) NOT NULL DEFAULT '储蓄卡' COMMENT '银行卡类型',
`bank_type` varchar(50) NOT NULL DEFAULT '' COMMENT '银行行别',
`bank_name` varchar(20) NOT NULL DEFAULT '' COMMENT '开户行名称',
`bank_username` varchar(20) NOT NULL DEFAULT '' COMMENT '开户人姓名',
`bank_userid` varchar(20) NOT NULL DEFAULT '' COMMENT '开户人身份证号码',
`bank_userphone` varchar(20) NOT NULL DEFAULT '' COMMENT '开户行预留手机号码',
`bank_address` varchar(255) DEFAULT '' COMMENT '开户行所在地',
`attest_status` int(1) NOT NULL COMMENT '认证状态;1:认证中;2:认证成功;3:认证失败',
`registertime` datetime NOT NULL COMMENT '注册时间',
`attesttime` datetime NOT NULL COMMENT '认证时间',
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;

2136
sql/22-06-15/ranking.sql

File diff suppressed because one or more lines are too long

1043
sql/jiao_api_alpha_x.sql

File diff suppressed because one or more lines are too long

5520
sql/jiao_api_alpha_x_full.sql

File diff suppressed because one or more lines are too long

10
think

@ -0,0 +1,10 @@
#!/usr/bin/env php
<?php
namespace think;
// 命令行入口文件
// 加载基础文件
require __DIR__ . '/vendor/autoload.php';
// 应用初始化
(new App())->console->run();

1
view/README.md

@ -0,0 +1 @@
如果不使用模板,可以删除该目录
Loading…
Cancel
Save