diff --git a/README.md b/README.md
index 23db9ef71..5df0f8efe 100644
--- a/README.md
+++ b/README.md
@@ -23,10 +23,12 @@ cp .env.example .env.development
```bash
# 本地部署时,需要将 APP_ENV 设置为 local, 并指定 docker-compose.local.yml 文件
-docker-compose --project-name shop_local --env-file .env.local -f docker-compose.local.yml up -d
+docker-compose --env-file .env.local -f docker-compose.local.yml up -d
+# docker-compose --project-name shop_local --env-file .env.local -f docker-compose.local.yml up -d
# docker-compose down 命令,用来停止并删除容器
-docker-compose --project-name shop_local down -v
+docker-compose -f docker-compose.local.yml down -v
+# docker-compose --project-name shop_local down -v
```
diff --git a/src/addon/alioss/config/diy_view.php b/src/addon/alioss/config/diy_view.php
index c3c657905..e36ca9b7d 100644
--- a/src/addon/alioss/config/diy_view.php
+++ b/src/addon/alioss/config/diy_view.php
@@ -1,38 +1,30 @@
- '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
- 'template' => [],
-
- // 后台自定义组件——装修
- 'util' => [],
-
- // 自定义页面路径
- 'link' => [],
-
- // 自定义图标库
- 'icon_library' => [],
-
- // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
- 'component' => [],
-
- // uni-app 页面,多个逗号隔开
- 'pages' => [],
-
- // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
- 'info' => [],
-
- // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
- 'theme' => [],
-
- // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
- 'data' => []
+ '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
+ 'template' => [],
+
+ // 后台自定义组件——装修
+ 'util' => [],
+
+ // 自定义页面路径
+ 'link' => [],
+
+ // 自定义图标库
+ 'icon_library' => [],
+
+ // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
+ 'component' => [],
+
+ // uni-app 页面,多个逗号隔开
+ 'pages' => [],
+
+ // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
+ 'info' => [],
+
+ // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
+ 'theme' => [],
+
+ // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
+ 'data' => []
];
\ No newline at end of file
diff --git a/src/addon/alioss/config/info.php b/src/addon/alioss/config/info.php
index e1ce32c76..b17546736 100644
--- a/src/addon/alioss/config/info.php
+++ b/src/addon/alioss/config/info.php
@@ -1,21 +1,12 @@
- 'alioss',
- 'title' => '阿里云OSS',
- 'description' => '阿里云OSS',
- 'type' => 'system', //插件类型 system :系统插件(自动安装), business:业务插件 promotion:营销插件 tool:工具插件
- 'status' => 1,
- 'author' => '',
- 'version' => '5.3.1',
- 'version_no' => '525231212001',
- 'content' => '',
+ 'alioss',
+ 'title' => '阿里云OSS',
+ 'description' => '阿里云OSS',
+ 'type' => 'system', //插件类型 system :系统插件(自动安装), business:业务插件 promotion:营销插件 tool:工具插件
+ 'status' => 1,
+ 'author' => '',
+ 'version' => '5.3.1',
+ 'version_no' => '525231212001',
+ 'content' => '',
];
\ No newline at end of file
diff --git a/src/addon/alioss/event/ClearAlbumPic.php b/src/addon/alioss/event/ClearAlbumPic.php
index f676c2751..04a9093fd 100644
--- a/src/addon/alioss/event/ClearAlbumPic.php
+++ b/src/addon/alioss/event/ClearAlbumPic.php
@@ -1,39 +1,31 @@
-getAliossConfig($params[ 'site_id' ]);
- if (!empty($config[ 'data' ])) {
- if (!empty($config[ 'data' ][ 'value' ][ 'endpoint' ]) && strpos($params[ 'pic_path' ], $config[ 'data' ][ 'value' ][ 'endpoint' ]) === 0) {
- $result = $alioss_model->deleteAlbumPic($params[ 'pic_path' ], $config[ 'data' ][ 'value' ][ 'endpoint' ]);
- return $result;
- }
- if (!empty($config[ 'data' ][ 'value' ][ 'domain' ]) && strpos($params[ 'pic_path' ], $config[ 'data' ][ 'value' ][ 'domain' ]) === 0) {
- $result = $alioss_model->deleteAlbumPic($params[ 'pic_path' ], $config[ 'data' ][ 'value' ][ 'domain' ]);
- return $result;
- }
- }
- }
+getAliossConfig($params[ 'site_id' ]);
+ if (!empty($config[ 'data' ])) {
+ if (!empty($config[ 'data' ][ 'value' ][ 'endpoint' ]) && strpos($params[ 'pic_path' ], $config[ 'data' ][ 'value' ][ 'endpoint' ]) === 0) {
+ $result = $alioss_model->deleteAlbumPic($params[ 'pic_path' ], $config[ 'data' ][ 'value' ][ 'endpoint' ]);
+ return $result;
+ }
+ if (!empty($config[ 'data' ][ 'value' ][ 'domain' ]) && strpos($params[ 'pic_path' ], $config[ 'data' ][ 'value' ][ 'domain' ]) === 0) {
+ $result = $alioss_model->deleteAlbumPic($params[ 'pic_path' ], $config[ 'data' ][ 'value' ][ 'domain' ]);
+ return $result;
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/alioss/event/CloseOss.php b/src/addon/alioss/event/CloseOss.php
index 930653350..d3006be6d 100644
--- a/src/addon/alioss/event/CloseOss.php
+++ b/src/addon/alioss/event/CloseOss.php
@@ -1,27 +1,19 @@
-modifyConfigIsUse(0);
- return $result;
- }
+modifyConfigIsUse(0);
+ return $result;
+ }
}
\ No newline at end of file
diff --git a/src/addon/alioss/event/Install.php b/src/addon/alioss/event/Install.php
index 9c9340b5f..aac0648f6 100644
--- a/src/addon/alioss/event/Install.php
+++ b/src/addon/alioss/event/Install.php
@@ -1,26 +1,18 @@
- "alioss",
- "sms_type_name" => "阿里云上传",
- "edit_url" => "alioss://shop/config/config",
- "shop_url" => "alioss://shop/config/config",
- "desc" => "阿里云上传"
- );
- return $info;
- }
+ "alioss",
+ "sms_type_name" => "阿里云上传",
+ "edit_url" => "alioss://shop/config/config",
+ "shop_url" => "alioss://shop/config/config",
+ "desc" => "阿里云上传"
+ );
+ return $info;
+ }
}
\ No newline at end of file
diff --git a/src/addon/alioss/event/Put.php b/src/addon/alioss/event/Put.php
index adb2aaf2f..f09f748f7 100644
--- a/src/addon/alioss/event/Put.php
+++ b/src/addon/alioss/event/Put.php
@@ -1,31 +1,23 @@
-putFile($param);
- return $result;
- }
+putFile($param);
+ return $result;
+ }
}
\ No newline at end of file
diff --git a/src/addon/alioss/event/UnInstall.php b/src/addon/alioss/event/UnInstall.php
index 39d7524ea..003cb89d6 100644
--- a/src/addon/alioss/event/UnInstall.php
+++ b/src/addon/alioss/event/UnInstall.php
@@ -1,27 +1,18 @@
-getAliossConfig();
- $config = $config_result['data'];
-
- if ($config['is_use'] == 1) {
- $config = $config['value'];
- $access_key_id = $config['access_key_id'];
- $access_key_secret = $config['access_key_secret'];
- $bucket = $config['bucket'];
- $endpoint = $config['endpoint'];
- try {
- $ossClient = new OssClient($access_key_id, $access_key_secret, $endpoint);
-
- $result = $ossClient->putObject($bucket, $key, $data);
- $is_domain = $config[ 'is_domain' ] ?? 0;
- $path = $is_domain > 0 ? $config[ 'domain' ] . '/' . $key : $result['info']['url'];
- $data = array (
- 'path' => $path,
-// "path" => $result["info"]["url"],
- 'domain' => $endpoint,
- 'bucket' => $bucket
- );
- return $this->success($data);
- } catch (OssException $e) {
- return $this->error('', $e->getErrorMessage());
- }
-
- }
- }
-
- /**
- * 设置阿里云OSS参数配置
- * @param unknown $filePath 上传图片路径
- * @param unknown $key 上传到阿里云后保存的文件名
- */
- public function putFile($param)
- {
- $file_path = $param['file_path'];
- $key = $param['key'];
- $config_model = new Config();
- $config = $config_model->getAliossConfig()['data'];
- if ($config['is_use'] == 1) {
- $config = $config['value'];
- $access_key_id = $config['access_key_id'];
- $access_key_secret = $config['access_key_secret'];
- $bucket = $config['bucket'];
- //要上传的空间
- $endpoint = $config['endpoint'];
- try {
- $ossClient = new OssClient($access_key_id, $access_key_secret, $endpoint);
- $result = $ossClient->uploadFile($bucket, $key, $file_path);
- $is_domain = $config[ 'is_domain' ] ?? 0;
- $path = $is_domain > 0 ? $config[ 'domain' ] . '/' . $key : $result['info']['url'];
- $path = str_replace('http://', 'https://', $path);
- //返回图片的完整URL
- $data = array (
-// "path" => $this->subEndpoint($endpoint, $bucket)."/". $key,
- 'path' => $path,
- 'domain' => $endpoint,
- 'bucket' => $bucket
- );
- return $this->success($data);
- } catch (\Exception $e) {
- return $this->error('', $e->getMessage());
- }
- }
- }
-
- public function subEndpoint($endpoint, $bucket)
- {
- if (strpos($endpoint, 'http://') === 0) {
- $temp = 'http://';
- } else {
- $temp = 'https://';
- }
- $temp_array = explode($temp, $endpoint);
- return $temp . $bucket . '.' . $temp_array[ 1 ];
- }
-
- /**
- * @param $file_path
- * @return array
- * 删除阿里云图片
- */
- public function deleteAlbumPic($file_path, $prefix)
- {
- $config_model = new Config();
- $config_result = $config_model->getAliossConfig();
- $config = $config_result['data'];
-
- if (!empty($config)) {
- $config = $config['value'];
- $access_key_id = $config['access_key_id'];
- $access_key_secret = $config['access_key_secret'];
- $bucket = $config['bucket'];
- //要上传的空间
- $endpoint = $config['endpoint'];
- try {
- $ossClient = new OssClient($access_key_id, $access_key_secret, $endpoint);
- $ossClient->deleteObject($bucket, str_replace($prefix . '/', '', $file_path));
- $ossClient->deleteObject($bucket, str_replace($prefix . '/', '', img($file_path, 'big')));
- $ossClient->deleteObject($bucket, str_replace($prefix . '/', '', img($file_path, 'mid')));
- $ossClient->deleteObject($bucket, str_replace($prefix . '/', '', img($file_path, 'small')));
-
- return $this->success();
- } catch (OssException $e) {
- return $this->error('', $e->getErrorMessage());
- }
- }
-
- }
-
+getAliossConfig();
+ $config = $config_result['data'];
+
+ if ($config['is_use'] == 1) {
+ $config = $config['value'];
+ $access_key_id = $config['access_key_id'];
+ $access_key_secret = $config['access_key_secret'];
+ $bucket = $config['bucket'];
+ $endpoint = $config['endpoint'];
+ try {
+ $ossClient = new OssClient($access_key_id, $access_key_secret, $endpoint);
+
+ $result = $ossClient->putObject($bucket, $key, $data);
+ $is_domain = $config[ 'is_domain' ] ?? 0;
+ $path = $is_domain > 0 ? $config[ 'domain' ] . '/' . $key : $result['info']['url'];
+ $data = array (
+ 'path' => $path,
+// "path" => $result["info"]["url"],
+ 'domain' => $endpoint,
+ 'bucket' => $bucket
+ );
+ return $this->success($data);
+ } catch (OssException $e) {
+ return $this->error('', $e->getErrorMessage());
+ }
+
+ }
+ }
+
+ /**
+ * 设置阿里云OSS参数配置
+ * @param unknown $filePath 上传图片路径
+ * @param unknown $key 上传到阿里云后保存的文件名
+ */
+ public function putFile($param)
+ {
+ $file_path = $param['file_path'];
+ $key = $param['key'];
+ $config_model = new Config();
+ $config = $config_model->getAliossConfig()['data'];
+ if ($config['is_use'] == 1) {
+ $config = $config['value'];
+ $access_key_id = $config['access_key_id'];
+ $access_key_secret = $config['access_key_secret'];
+ $bucket = $config['bucket'];
+ //要上传的空间
+ $endpoint = $config['endpoint'];
+ try {
+ $ossClient = new OssClient($access_key_id, $access_key_secret, $endpoint);
+ $result = $ossClient->uploadFile($bucket, $key, $file_path);
+ $is_domain = $config[ 'is_domain' ] ?? 0;
+ $path = $is_domain > 0 ? $config[ 'domain' ] . '/' . $key : $result['info']['url'];
+ $path = str_replace('http://', 'https://', $path);
+ //返回图片的完整URL
+ $data = array (
+// "path" => $this->subEndpoint($endpoint, $bucket)."/". $key,
+ 'path' => $path,
+ 'domain' => $endpoint,
+ 'bucket' => $bucket
+ );
+ return $this->success($data);
+ } catch (\Exception $e) {
+ return $this->error('', $e->getMessage());
+ }
+ }
+ }
+
+ public function subEndpoint($endpoint, $bucket)
+ {
+ if (strpos($endpoint, 'http://') === 0) {
+ $temp = 'http://';
+ } else {
+ $temp = 'https://';
+ }
+ $temp_array = explode($temp, $endpoint);
+ return $temp . $bucket . '.' . $temp_array[ 1 ];
+ }
+
+ /**
+ * @param $file_path
+ * @return array
+ * 删除阿里云图片
+ */
+ public function deleteAlbumPic($file_path, $prefix)
+ {
+ $config_model = new Config();
+ $config_result = $config_model->getAliossConfig();
+ $config = $config_result['data'];
+
+ if (!empty($config)) {
+ $config = $config['value'];
+ $access_key_id = $config['access_key_id'];
+ $access_key_secret = $config['access_key_secret'];
+ $bucket = $config['bucket'];
+ //要上传的空间
+ $endpoint = $config['endpoint'];
+ try {
+ $ossClient = new OssClient($access_key_id, $access_key_secret, $endpoint);
+ $ossClient->deleteObject($bucket, str_replace($prefix . '/', '', $file_path));
+ $ossClient->deleteObject($bucket, str_replace($prefix . '/', '', img($file_path, 'big')));
+ $ossClient->deleteObject($bucket, str_replace($prefix . '/', '', img($file_path, 'mid')));
+ $ossClient->deleteObject($bucket, str_replace($prefix . '/', '', img($file_path, 'small')));
+
+ return $this->success();
+ } catch (OssException $e) {
+ return $this->error('', $e->getErrorMessage());
+ }
+ }
+
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/alioss/model/Config.php b/src/addon/alioss/model/Config.php
index 505ae391b..f25fb5d77 100644
--- a/src/addon/alioss/model/Config.php
+++ b/src/addon/alioss/model/Config.php
@@ -1,56 +1,48 @@
-setConfig($data, '阿里云OSS上传配置', $status, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'ALIOSS_CONFIG' ] ]);
- return $res;
- }
-
- /**
- * 获取阿里云上传配置
- */
- public function getAliossConfig($site_id = 1, $app_module = 'shop')
- {
- $config = new ConfigModel();
- $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'ALIOSS_CONFIG' ] ]);
- return $res;
- }
-
- /**
- * 配置阿里云开关状态
- * @param $status
- */
- public function modifyConfigIsUse($status, $site_id = 1, $app_module = 'shop')
- {
- $config = new ConfigModel();
- $res = $config->modifyConfigIsUse($status, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'ALIOSS_CONFIG' ] ]);
- return $res;
- }
+setConfig($data, '阿里云OSS上传配置', $status, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'ALIOSS_CONFIG' ] ]);
+ return $res;
+ }
+
+ /**
+ * 获取阿里云上传配置
+ */
+ public function getAliossConfig($site_id = 1, $app_module = 'shop')
+ {
+ $config = new ConfigModel();
+ $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'ALIOSS_CONFIG' ] ]);
+ return $res;
+ }
+
+ /**
+ * 配置阿里云开关状态
+ * @param $status
+ */
+ public function modifyConfigIsUse($status, $site_id = 1, $app_module = 'shop')
+ {
+ $config = new ConfigModel();
+ $res = $config->modifyConfigIsUse($status, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'ALIOSS_CONFIG' ] ]);
+ return $res;
+ }
}
\ No newline at end of file
diff --git a/src/addon/alioss/shop/controller/Config.php b/src/addon/alioss/shop/controller/Config.php
index a95b01b0e..da75b8fb1 100644
--- a/src/addon/alioss/shop/controller/Config.php
+++ b/src/addon/alioss/shop/controller/Config.php
@@ -1,56 +1,48 @@
-isJson()) {
- $bucket = input('bucket', '');
- $access_key_id = input('access_key_id', '');
- $access_key_secret = input('access_key_secret', '');
- $endpoint = input('endpoint', '');
- $status = input('status', 0);
- $domain = input('domain', '');
- $is_domain = input('is_domain', 0);
-
- $data = array (
- 'bucket' => $bucket,
- 'access_key_id' => $access_key_id,
- 'access_key_secret' => $access_key_secret,
- 'endpoint' => $endpoint,
- 'domain' => $domain,
- 'is_domain' => $is_domain
- );
-
- $result = $config_model->setAliossConfig($data, $status, $this->site_id, $this->app_module);
- return $result;
- } else {
- $info_result = $config_model->getAliossConfig($this->site_id, $this->app_module);
- $info = $info_result['data'];
- $this->assign('info', $info);
- return $this->fetch('config/config');
- }
- }
+isJson()) {
+ $bucket = input('bucket', '');
+ $access_key_id = input('access_key_id', '');
+ $access_key_secret = input('access_key_secret', '');
+ $endpoint = input('endpoint', '');
+ $status = input('status', 0);
+ $domain = input('domain', '');
+ $is_domain = input('is_domain', 0);
+
+ $data = array (
+ 'bucket' => $bucket,
+ 'access_key_id' => $access_key_id,
+ 'access_key_secret' => $access_key_secret,
+ 'endpoint' => $endpoint,
+ 'domain' => $domain,
+ 'is_domain' => $is_domain
+ );
+
+ $result = $config_model->setAliossConfig($data, $status, $this->site_id, $this->app_module);
+ return $result;
+ } else {
+ $info_result = $config_model->getAliossConfig($this->site_id, $this->app_module);
+ $info = $info_result['data'];
+ $this->assign('info', $info);
+ return $this->fetch('config/config');
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/alipay/config/diy_view.php b/src/addon/alipay/config/diy_view.php
index c3c657905..e36ca9b7d 100644
--- a/src/addon/alipay/config/diy_view.php
+++ b/src/addon/alipay/config/diy_view.php
@@ -1,38 +1,30 @@
- '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
- 'template' => [],
-
- // 后台自定义组件——装修
- 'util' => [],
-
- // 自定义页面路径
- 'link' => [],
-
- // 自定义图标库
- 'icon_library' => [],
-
- // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
- 'component' => [],
-
- // uni-app 页面,多个逗号隔开
- 'pages' => [],
-
- // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
- 'info' => [],
-
- // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
- 'theme' => [],
-
- // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
- 'data' => []
+ '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
+ 'template' => [],
+
+ // 后台自定义组件——装修
+ 'util' => [],
+
+ // 自定义页面路径
+ 'link' => [],
+
+ // 自定义图标库
+ 'icon_library' => [],
+
+ // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
+ 'component' => [],
+
+ // uni-app 页面,多个逗号隔开
+ 'pages' => [],
+
+ // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
+ 'info' => [],
+
+ // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
+ 'theme' => [],
+
+ // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
+ 'data' => []
];
\ No newline at end of file
diff --git a/src/addon/alipay/config/event.php b/src/addon/alipay/config/event.php
index 0bc30b9f4..7d660dc1f 100644
--- a/src/addon/alipay/config/event.php
+++ b/src/addon/alipay/config/event.php
@@ -1,50 +1,42 @@
- [
-
- ],
-
- 'listen' => [
- //支付异步回调
- 'PayNotify' => [
- 'addon\alipay\event\PayNotify'
- ],
- //支付方式,后台查询
- 'PayType' => [
- 'addon\alipay\event\PayType'
- ],
- //支付,前台应用
- 'Pay' => [
- 'addon\alipay\event\Pay'
- ],
- 'PayClose' => [
- 'addon\alipay\event\PayClose'
- ],
- 'PayRefund' => [
- 'addon\alipay\event\PayRefund'
- ],
- 'PayTransfer' => [
- 'addon\alipay\event\PayTransfer'
- ],
- 'TransferType' => [
- 'addon\alipay\event\TransferType'
- ],
- 'AuthcodePay' => [
- 'addon\alipay\event\AuthcodePay'
- ],
- 'PayOrderQuery' => [
- 'addon\alipay\event\PayOrderQuery'
- ],
- ],
-
- 'subscribe' => [
- ],
-];
+ [
+
+ ],
+
+ 'listen' => [
+ //支付异步回调
+ 'PayNotify' => [
+ 'addon\alipay\event\PayNotify'
+ ],
+ //支付方式,后台查询
+ 'PayType' => [
+ 'addon\alipay\event\PayType'
+ ],
+ //支付,前台应用
+ 'Pay' => [
+ 'addon\alipay\event\Pay'
+ ],
+ 'PayClose' => [
+ 'addon\alipay\event\PayClose'
+ ],
+ 'PayRefund' => [
+ 'addon\alipay\event\PayRefund'
+ ],
+ 'PayTransfer' => [
+ 'addon\alipay\event\PayTransfer'
+ ],
+ 'TransferType' => [
+ 'addon\alipay\event\TransferType'
+ ],
+ 'AuthcodePay' => [
+ 'addon\alipay\event\AuthcodePay'
+ ],
+ 'PayOrderQuery' => [
+ 'addon\alipay\event\PayOrderQuery'
+ ],
+ ],
+
+ 'subscribe' => [
+ ],
+];
diff --git a/src/addon/alipay/config/info.php b/src/addon/alipay/config/info.php
index e7ce28878..bd5228f97 100644
--- a/src/addon/alipay/config/info.php
+++ b/src/addon/alipay/config/info.php
@@ -1,21 +1,12 @@
- 'alipay',
- 'title' => '支付宝支付',
- 'description' => '支付宝支付功能',
- 'type' => 'system', //插件类型 system :系统插件(自动安装), promotion:营销插件 tool:工具插件
- 'status' => 1,
- 'author' => '',
- 'version' => '5.3.1',
- 'version_no' => '525231212001',
- 'content' => '',
+ 'alipay',
+ 'title' => '支付宝支付',
+ 'description' => '支付宝支付功能',
+ 'type' => 'system', //插件类型 system :系统插件(自动安装), promotion:营销插件 tool:工具插件
+ 'status' => 1,
+ 'author' => '',
+ 'version' => '5.3.1',
+ 'version_no' => '525231212001',
+ 'content' => '',
];
\ No newline at end of file
diff --git a/src/addon/alipay/config/menu_shop.php b/src/addon/alipay/config/menu_shop.php
index 862ee7d2d..e37ca0195 100644
--- a/src/addon/alipay/config/menu_shop.php
+++ b/src/addon/alipay/config/menu_shop.php
@@ -1,23 +1,15 @@
- 'ALI_PAY_CONFIG',
- 'title' => '支付宝支付编辑',
- 'url' => 'alipay://shop/pay/config',
- 'parent' => 'CONFIG_PAY',
- 'is_show' => 0,
- 'is_control' => 1,
- 'is_icon' => 0,
- 'picture' => '',
- 'picture_select' => '',
- 'sort' => 1,
- ],
-];
+ 'ALI_PAY_CONFIG',
+ 'title' => '支付宝支付编辑',
+ 'url' => 'alipay://shop/pay/config',
+ 'parent' => 'CONFIG_PAY',
+ 'is_show' => 0,
+ 'is_control' => 1,
+ 'is_icon' => 0,
+ 'picture' => '',
+ 'picture_select' => '',
+ 'sort' => 1,
+ ],
+];
diff --git a/src/addon/alipay/event/Install.php b/src/addon/alipay/event/Install.php
index f7fd8e178..acf616ad7 100644
--- a/src/addon/alipay/event/Install.php
+++ b/src/addon/alipay/event/Install.php
@@ -1,27 +1,18 @@
-pay($param);
- return $res;
- }
- }
- }
+pay($param);
+ return $res;
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/alipay/event/PayClose.php b/src/addon/alipay/event/PayClose.php
index 0222cf812..2735871aa 100644
--- a/src/addon/alipay/event/PayClose.php
+++ b/src/addon/alipay/event/PayClose.php
@@ -1,39 +1,31 @@
-close($params);
- return $result;
- } catch (\Exception $e) {
- return error(-1, $e->getMessage());
- } catch (\Throwable $e) {
- return error(-1, $e->getMessage());
- }
-// }
- }
+close($params);
+ return $result;
+ } catch (\Exception $e) {
+ return error(-1, $e->getMessage());
+ } catch (\Throwable $e) {
+ return error(-1, $e->getMessage());
+ }
+// }
+ }
}
\ No newline at end of file
diff --git a/src/addon/alipay/event/PayNotify.php b/src/addon/alipay/event/PayNotify.php
index 0a7c34d59..43022db6b 100644
--- a/src/addon/alipay/event/PayNotify.php
+++ b/src/addon/alipay/event/PayNotify.php
@@ -1,41 +1,33 @@
-getPayInfo($out_trade_no)[ 'data' ];
- if (empty($pay_info)) return false;
-
- if ($_POST[ 'total_amount' ] != $pay_info[ 'pay_money' ]) {
- return false;
- }
- $mch_info = empty($pay_info[ 'mch_info' ]) ? [] : json_decode($pay_info[ 'mch_info' ], true);
-
- $pay_model = new PayModel($pay_info[ 'site_id' ], $mch_info[ 'is_aliapp' ] ?? 0);
- $pay_model->payNotify();
- }
- }
+getPayInfo($out_trade_no)[ 'data' ];
+ if (empty($pay_info)) return false;
+
+ if ($_POST[ 'total_amount' ] != $pay_info[ 'pay_money' ]) {
+ return false;
+ }
+ $mch_info = empty($pay_info[ 'mch_info' ]) ? [] : json_decode($pay_info[ 'mch_info' ], true);
+
+ $pay_model = new PayModel($pay_info[ 'site_id' ], $mch_info[ 'is_aliapp' ] ?? 0);
+ $pay_model->payNotify();
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/alipay/event/PayOrderQuery.php b/src/addon/alipay/event/PayOrderQuery.php
index 0ecd52ed6..295275441 100644
--- a/src/addon/alipay/event/PayOrderQuery.php
+++ b/src/addon/alipay/event/PayOrderQuery.php
@@ -1,34 +1,26 @@
-getInfo([ [ 'id', '=', $params[ 'relate_id' ] ] ])[ 'data' ];
- if (!empty($pay_info)) {
- $config_model = new ConfigModel();
- $pay_config = $config_model->getPayConfig($pay_info[ 'site_id' ])[ 'data' ][ 'value' ];
- if (!empty($pay_config) && $pay_config[ 'pay_status' ] != 2) {
- $pay_common = new PayModel($pay_info[ 'site_id' ]);
- $pay_common->orderQuery($pay_info);
- }
- }
- }
-}
+getInfo([ [ 'id', '=', $params[ 'relate_id' ] ] ])[ 'data' ];
+ if (!empty($pay_info)) {
+ $config_model = new ConfigModel();
+ $pay_config = $config_model->getPayConfig($pay_info[ 'site_id' ])[ 'data' ][ 'value' ];
+ if (!empty($pay_config) && $pay_config[ 'pay_status' ] != 2) {
+ $pay_common = new PayModel($pay_info[ 'site_id' ]);
+ $pay_common->orderQuery($pay_info);
+ }
+ }
+ }
+}
diff --git a/src/addon/alipay/event/PayRefund.php b/src/addon/alipay/event/PayRefund.php
index 26a246b72..edf98f145 100644
--- a/src/addon/alipay/event/PayRefund.php
+++ b/src/addon/alipay/event/PayRefund.php
@@ -1,33 +1,25 @@
-refund($params);
- return $result;
- }
- }
+refund($params);
+ return $result;
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/alipay/event/PayTransfer.php b/src/addon/alipay/event/PayTransfer.php
index a979c3651..b4cc5f592 100644
--- a/src/addon/alipay/event/PayTransfer.php
+++ b/src/addon/alipay/event/PayTransfer.php
@@ -1,42 +1,34 @@
-getPayConfig($params[ 'site_id' ]);
- $config = $config_result[ "data" ];
- if (!empty($config[ 'value' ])) {
- $config_info = $config[ "value" ];
- $countersign_type = $config_info['countersign_type'] ?? 0;
- if ($countersign_type == 0) {
- $res = $pay->payTransfer($params);
- return $res;
- } else {
- $res = $pay->payNewTransfer($params);
- return $res;
- }
- } else {
- $res = $pay->payTransfer($params);
- return $res;
- }
- }
- }
+getPayConfig($params[ 'site_id' ]);
+ $config = $config_result[ "data" ];
+ if (!empty($config[ 'value' ])) {
+ $config_info = $config[ "value" ];
+ $countersign_type = $config_info['countersign_type'] ?? 0;
+ if ($countersign_type == 0) {
+ $res = $pay->payTransfer($params);
+ return $res;
+ } else {
+ $res = $pay->payNewTransfer($params);
+ return $res;
+ }
+ } else {
+ $res = $pay->payTransfer($params);
+ return $res;
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/alipay/event/PayType.php b/src/addon/alipay/event/PayType.php
index d7c10853e..5d7631337 100644
--- a/src/addon/alipay/event/PayType.php
+++ b/src/addon/alipay/event/PayType.php
@@ -1,51 +1,43 @@
-getPayConfig($param[ 'site_id' ]);
- $config = $config_result[ "data" ][ "value" ] ?? [];
- $pay_status = $config[ "pay_status" ] ?? 0;
- if ($pay_status == 0) {
- return '';
- }
- }
- }
- $info = array (
- "pay_type" => "alipay",
- "pay_type_name" => "支付宝支付",
- "edit_url" => "alipay://shop/pay/config",
- "shop_url" => "alipay://shop/pay/config",
- "logo" => "addon/alipay/icon.png",
- "desc" => "支付宝网站(www.alipay.com) 是国内先进的网上支付平台。"
- );
- return $info;
- }
+getPayConfig($param[ 'site_id' ]);
+ $config = $config_result[ "data" ][ "value" ] ?? [];
+ $pay_status = $config[ "pay_status" ] ?? 0;
+ if ($pay_status == 0) {
+ return '';
+ }
+ }
+ }
+ $info = array (
+ "pay_type" => "alipay",
+ "pay_type_name" => "支付宝支付",
+ "edit_url" => "alipay://shop/pay/config",
+ "shop_url" => "alipay://shop/pay/config",
+ "logo" => "addon/alipay/icon.png",
+ "desc" => "支付宝网站(www.alipay.com) 是国内先进的网上支付平台。"
+ );
+ return $info;
+ }
}
\ No newline at end of file
diff --git a/src/addon/alipay/event/TransferType.php b/src/addon/alipay/event/TransferType.php
index 4bffaf48a..981292a4a 100644
--- a/src/addon/alipay/event/TransferType.php
+++ b/src/addon/alipay/event/TransferType.php
@@ -1,39 +1,31 @@
-getPayConfig($param[ 'site_id' ]);
- $config = $config_result[ "data" ][ "value" ] ?? [];
- $transfer_status = $config[ "transfer_status" ] ?? 0;
- if ($transfer_status == 0) {
- return '';
- }
- }
- $info = array (
- "type" => "alipay",
- "type_name" => "支付宝",
- );
- return $info;
- }
+getPayConfig($param[ 'site_id' ]);
+ $config = $config_result[ "data" ][ "value" ] ?? [];
+ $transfer_status = $config[ "transfer_status" ] ?? 0;
+ if ($transfer_status == 0) {
+ return '';
+ }
+ }
+ $info = array (
+ "type" => "alipay",
+ "type_name" => "支付宝",
+ );
+ return $info;
+ }
}
\ No newline at end of file
diff --git a/src/addon/alipay/event/UnInstall.php b/src/addon/alipay/event/UnInstall.php
index 0ee043cf5..fdc8d926c 100644
--- a/src/addon/alipay/event/UnInstall.php
+++ b/src/addon/alipay/event/UnInstall.php
@@ -1,26 +1,17 @@
-getPayConfig($site_id)[ 'data' ][ 'value' ];
-
- // 检测数据是否发生变化,如果没有变化,则保持未加密前的数据
- if (!empty($data[ 'private_key' ]) && $data[ 'private_key' ] == $this->encrypt) {
- $data[ 'private_key' ] = $original_config[ 'private_key' ]; // 应用私钥
- }
- if (!empty($data[ 'public_key' ]) && $data[ 'public_key' ] == $this->encrypt) {
- $data[ 'public_key' ] = $original_config[ 'public_key' ]; // 应用公钥
- }
- if (!empty($data[ 'alipay_public_key' ]) && $data[ 'alipay_public_key' ] == $this->encrypt) {
- $data[ 'alipay_public_key' ] = $original_config[ 'alipay_public_key' ]; // 支付宝公钥
- }
- if (!empty($data[ 'public_key_crt' ]) && $data[ 'public_key_crt' ] == $this->encrypt) {
- $data[ 'public_key_crt' ] = $original_config[ 'public_key_crt' ]; // 应用公钥证书
- }
- if (!empty($data[ 'alipay_public_key_crt' ]) && $data[ 'alipay_public_key_crt' ] == $this->encrypt) {
- $data[ 'alipay_public_key_crt' ] = $original_config[ 'alipay_public_key_crt' ]; // 支付宝公钥证书
- }
- if (!empty($data[ 'alipay_with_crt' ]) && $data[ 'alipay_with_crt' ] == $this->encrypt) {
- $data[ 'alipay_with_crt' ] = $original_config[ 'alipay_with_crt' ]; // 支付宝根证书
- }
-
- $res = $config->setConfig($data, '支付宝支付配置', 1, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'ALI_PAY_CONFIG' ] ]);
- return $res;
- }
-
- /**
- * 获取支付配置
- * @param int $site_id
- * @param string $app_module
- * @param bool $need_encrypt 是否需要加密数据,true:加密、false:不加密
- * @return array
- */
- public function getPayConfig($site_id = 0, $app_module = 'shop', $need_encrypt = false)
- {
- $config = new ConfigModel();
- $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'ALI_PAY_CONFIG' ] ]);
- if ($need_encrypt) {
- // 加密敏感信息
- if (!empty($res[ 'data' ][ 'value' ][ 'private_key' ])) {
- $res[ 'data' ][ 'value' ][ 'private_key' ] = $this->encrypt; // 应用私钥
- }
- if (!empty($res[ 'data' ][ 'value' ][ 'public_key' ])) {
- $res[ 'data' ][ 'value' ][ 'public_key' ] = $this->encrypt; // 应用公钥
- }
- if (!empty($res[ 'data' ][ 'value' ][ 'alipay_public_key' ])) {
- $res[ 'data' ][ 'value' ][ 'alipay_public_key' ] = $this->encrypt; // 支付宝公钥
- }
- if (!empty($res[ 'data' ][ 'value' ][ 'public_key_crt' ])) {
- $res[ 'data' ][ 'value' ][ 'public_key_crt' ] = $this->encrypt; // 应用公钥证书
- }
- if (!empty($res[ 'data' ][ 'value' ][ 'alipay_public_key_crt' ])) {
- $res[ 'data' ][ 'value' ][ 'alipay_public_key_crt' ] = $this->encrypt; // 支付宝公钥证书
- }
- if (!empty($res[ 'data' ][ 'value' ][ 'alipay_with_crt' ])) {
- $res[ 'data' ][ 'value' ][ 'alipay_with_crt' ] = $this->encrypt; // 支付宝根证书
- }
- }
- return $res;
- }
+getPayConfig($site_id)[ 'data' ][ 'value' ];
+
+ // 检测数据是否发生变化,如果没有变化,则保持未加密前的数据
+ if (!empty($data[ 'private_key' ]) && $data[ 'private_key' ] == $this->encrypt) {
+ $data[ 'private_key' ] = $original_config[ 'private_key' ]; // 应用私钥
+ }
+ if (!empty($data[ 'public_key' ]) && $data[ 'public_key' ] == $this->encrypt) {
+ $data[ 'public_key' ] = $original_config[ 'public_key' ]; // 应用公钥
+ }
+ if (!empty($data[ 'alipay_public_key' ]) && $data[ 'alipay_public_key' ] == $this->encrypt) {
+ $data[ 'alipay_public_key' ] = $original_config[ 'alipay_public_key' ]; // 支付宝公钥
+ }
+ if (!empty($data[ 'public_key_crt' ]) && $data[ 'public_key_crt' ] == $this->encrypt) {
+ $data[ 'public_key_crt' ] = $original_config[ 'public_key_crt' ]; // 应用公钥证书
+ }
+ if (!empty($data[ 'alipay_public_key_crt' ]) && $data[ 'alipay_public_key_crt' ] == $this->encrypt) {
+ $data[ 'alipay_public_key_crt' ] = $original_config[ 'alipay_public_key_crt' ]; // 支付宝公钥证书
+ }
+ if (!empty($data[ 'alipay_with_crt' ]) && $data[ 'alipay_with_crt' ] == $this->encrypt) {
+ $data[ 'alipay_with_crt' ] = $original_config[ 'alipay_with_crt' ]; // 支付宝根证书
+ }
+
+ $res = $config->setConfig($data, '支付宝支付配置', 1, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'ALI_PAY_CONFIG' ] ]);
+ return $res;
+ }
+
+ /**
+ * 获取支付配置
+ * @param int $site_id
+ * @param string $app_module
+ * @param bool $need_encrypt 是否需要加密数据,true:加密、false:不加密
+ * @return array
+ */
+ public function getPayConfig($site_id = 0, $app_module = 'shop', $need_encrypt = false)
+ {
+ $config = new ConfigModel();
+ $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'ALI_PAY_CONFIG' ] ]);
+ if ($need_encrypt) {
+ // 加密敏感信息
+ if (!empty($res[ 'data' ][ 'value' ][ 'private_key' ])) {
+ $res[ 'data' ][ 'value' ][ 'private_key' ] = $this->encrypt; // 应用私钥
+ }
+ if (!empty($res[ 'data' ][ 'value' ][ 'public_key' ])) {
+ $res[ 'data' ][ 'value' ][ 'public_key' ] = $this->encrypt; // 应用公钥
+ }
+ if (!empty($res[ 'data' ][ 'value' ][ 'alipay_public_key' ])) {
+ $res[ 'data' ][ 'value' ][ 'alipay_public_key' ] = $this->encrypt; // 支付宝公钥
+ }
+ if (!empty($res[ 'data' ][ 'value' ][ 'public_key_crt' ])) {
+ $res[ 'data' ][ 'value' ][ 'public_key_crt' ] = $this->encrypt; // 应用公钥证书
+ }
+ if (!empty($res[ 'data' ][ 'value' ][ 'alipay_public_key_crt' ])) {
+ $res[ 'data' ][ 'value' ][ 'alipay_public_key_crt' ] = $this->encrypt; // 支付宝公钥证书
+ }
+ if (!empty($res[ 'data' ][ 'value' ][ 'alipay_with_crt' ])) {
+ $res[ 'data' ][ 'value' ][ 'alipay_with_crt' ] = $this->encrypt; // 支付宝根证书
+ }
+ }
+ return $res;
+ }
}
\ No newline at end of file
diff --git a/src/addon/alipay/model/Pay.php b/src/addon/alipay/model/Pay.php
index e51bf19c4..12c9cb371 100644
--- a/src/addon/alipay/model/Pay.php
+++ b/src/addon/alipay/model/Pay.php
@@ -1,486 +1,478 @@
-is_aliapp = $is_aliapp;
-
- try {
- // 获取支付宝支付参数(统一支付到平台账户)
- if ($is_aliapp) {
- $config_info = ( new AliappConfig() )->getAliappConfig($site_id)[ 'data' ][ 'value' ];
- } else {
- $config_info = ( new Config() )->getPayConfig($site_id)[ 'data' ][ 'value' ];
- }
-
- if (!empty($config_info)) {
- $countersign_type = $config_info[ 'countersign_type' ] ?? 0;
-
- if ($countersign_type == 1) {
- $appCertPath = $config_info[ "public_key_crt" ] ?? "";
- $alipayCertPath = $config_info[ "alipay_public_key_crt" ] ?? "";
- $rootCertPath = $config_info[ "alipay_with_crt" ] ?? "";
-
- $this->aop = new AopCertClient();
- //调用getPublicKey从支付宝公钥证书中提取公钥
- $this->aop->alipayrsaPublicKey = $this->aop->getPublicKey($alipayCertPath);
- //是否校验自动下载的支付宝公钥证书,如果开启校验要保证支付宝根证书在有效期内
- $this->aop->isCheckAlipayPublicCert = false;
- //调用getCertSN获取证书序列号
- $this->aop->appCertSN = $this->aop->getCertSN($appCertPath);
- //调用getRootCertSN获取支付宝根证书序列号
- $this->aop->alipayRootCertSN = $this->aop->getRootCertSN($rootCertPath);
-
- } else {
- // 获取支付宝支付参数(统一支付到平台账户)
- $this->aop = new AopClient();
- $this->aop->alipayrsaPublicKey = $config_info[ 'public_key' ] ?? "";
- $this->aop->alipayPublicKey = $config_info[ 'alipay_public_key' ] ?? "";
- }
- $this->aop->appId = $config_info[ "app_id" ] ?? "";
- $this->aop->rsaPrivateKey = $config_info[ 'private_key' ] ?? "";
- $this->aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
- $this->aop->apiVersion = '1.0';
- $this->aop->signType = 'RSA2';
- $this->aop->postCharset = 'UTF-8';
- $this->aop->format = 'json';
-
- }
-// else{
-// return $this->error('', '支付宝支付未配置');
-// }
-
- } catch (\Exception $e) {
- return $this->error('', '支付宝配置错误');
- }
- }
-
- /**
- * 生成支付
- * @param $param
- * @return array
- */
- public function pay($param)
- {
- //构造要请求的参数数组,无需改动
- $parameter = array (
- "out_trade_no" => $param[ "out_trade_no" ],
- "subject" => str_sub($param[ "pay_body" ], 15),
- "total_amount" => (float) $param[ "pay_money" ],
- "body" => str_sub($param[ "pay_body" ], 60),
- "product_code" => 'FAST_INSTANT_TRADE_PAY',
- );
-
- switch ( $param[ "app_type" ] ) {
- case "h5":
- $request = new AlipayTradeWapPayRequest();
- break;
- case "pc":
- $request = new AlipayTradePagePayRequest();
- break;
- case "app":
- $request = new AlipayTradeAppPayRequest();
- break;
- case 'wechat':
- $request = new AlipayTradeWapPayRequest();
- break;
- case 'cashier':
- $request = new AlipayTradePrecreateRequest();
- break;
- case 'aliapp':
- $parameter[ 'product_code' ] = 'FACE_TO_FACE_PAYMENT';
-
- $member_info = model('member')->getInfo([ [ "member_id", "=", $param[ "member_id" ] ] ], 'ali_openid');
- if (empty($member_info)) return $this->error(-1, '未获取到会员信息');
-
- $parameter[ 'buyer_id' ] = $member_info[ 'ali_openid' ];
- $request = new AlipayTradeCreateRequest();
- break;
- }
-
- $parameter = json_encode($parameter);
- $request->setBizContent($parameter);
- $request->SetReturnUrl($param[ "return_url" ]);
- $request->SetNotifyUrl($param[ "notify_url" ]);
-
- ///绑定商户数据
- $pay_model = new PayModel();
- $pay_model->bindMchPay($param[ "out_trade_no" ], [ "is_aliapp" => $this->is_aliapp ]);
-
- try {
- if ($param[ "app_type" ] == 'h5' || $param[ "app_type" ] == 'wechat' || $param[ "app_type" ] == 'pc') {
- $result = $this->aop->pageExecute($request, 'get');
- return $this->success([
- 'type' => 'url',
- 'data' => $result
- ]);
- } elseif ($param[ "app_type" ] == 'app') {
- $result = $this->aop->sdkExecute($request);
- if (strpos(get_class($this->aop), 'AopClient') !== false) {
- return $this->success([
- 'type' => 'url',
- 'data' => $result
- ]);
- }
- } else {
- $result = $this->aop->execute($request);
- }
- if ($result === false) return $this->error('', '支付宝发起支付失败');
- } catch (\Exception $e) {
- return $this->error('', $e->getMessage());
- }
-
- $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
- $resultCode = $result->$responseNode->code;
- if (!empty($resultCode) && $resultCode == 10000) {
- switch ( $param[ "app_type" ] ) {
- case 'cashier':
- return $this->success([
- 'type' => 'qrcode',
- 'data' => [
- 'qrcode' => $result->$responseNode->qr_code
- ]
- ]);
- break;
- case 'aliapp':
- return $this->success([
- 'type' => 'data',
- 'data' => [
- 'orderInfo' => $result->$responseNode->trade_no
- ]
- ]);
- break;
- default:
- return $this->success();
- }
- } else {
- return $this->error("", $result->$responseNode->sub_msg);
- }
- }
-
- /**
- * 支付关闭
- * @param $param
- * @return array
- * @throws \think\Exception
- */
- public function close($param)
- {
- $parameter = array (
- "out_trade_no" => $param[ "out_trade_no" ]
- );
- // 建立请求
- $request = new AlipayTradeCloseRequest();
- $request->setBizContent(json_encode($parameter));
- $result = $this->aop->execute($request);
- $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
- $resultCode = $result->$responseNode->code;
- if (!empty($resultCode) && $resultCode == 10000) {
- return $this->success();
- } else {
- $sub_code = $result->$responseNode->sub_code;
- $data = [];
- if(in_array($sub_code, ['ACQ.TRADE_STATUS_ERROR', 'ACQ.REASON_TRADE_STATUS_INVALID', 'ACQ.REASON_ILLEGAL_STATUS'])){
- $pay_order_result = $this->get($param[ "out_trade_no" ]);
- if(!empty($pay_order_result) && $pay_order_result['code'] >= 0){
- if($pay_order_result['data']['trade_status'] == 'TRADE_SUCCESS' || $pay_order_result['data']['trade_status'] == 'TRADE_FINISHED'){
- $data['is_paid'] = 1;
- }
- }
- }
-
-
- return $this->error($data, $result->$responseNode->sub_msg);
- }
- }
-
- /**
- * 支付宝支付原路返回
- * @param array $param 支付参数
- * @return array
- * @throws \think\Exception
- */
- public function refund($param)
- {
- $pay_info = $param[ "pay_info" ];
- $refund_no = $param[ "refund_no" ];
- $out_trade_no = $pay_info[ "trade_no" ] ?? '';
- $refund_fee = $param[ "refund_fee" ];
- $parameter = array (
- 'trade_no' => $out_trade_no,
- 'refund_amount' => sprintf("%.2f", $refund_fee),
- 'out_request_no' => $refund_no
- );
- // 建立请求
- $request = new AlipayTradeRefundRequest ();
- $request->setBizContent(json_encode($parameter));
- $result = $this->aop->execute($request);
- $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
- $resultCode = $result->$responseNode->code;
- if (!empty($resultCode) && $resultCode == 10000) {
- return $this->success();
- } else {
- return $this->error("", $result->$responseNode->sub_msg);
- }
- }
-
- /**
- * 支付宝转账
- * @param $param
- * @return array
- */
- public function payTransfer($param)
- {
- try {
- $config_model = new Config();
- $config_result = $config_model->getPayConfig($param[ 'site_id' ]);
- if ($config_result[ 'code' ] < 0) return $config_result;
- $config = $config_result[ 'data' ][ 'value' ];
- if (empty($config)) return $this->error([], '未配置支付宝支付');
- if (!$config[ 'transfer_status' ]) return $this->error([], '未启用支付宝转账');
-
- $parameter = [
- 'out_biz_no' => $param[ 'out_trade_no' ],
- 'payee_type' => 'ALIPAY_LOGONID',
- 'payee_account' => $param[ "account_number" ],
- 'amount' => sprintf("%.2f", $param[ 'amount' ]),
- 'payee_real_name' => $param[ "real_name" ],
- 'remark' => $param[ "desc" ]
- ];
- // 建立请求
- $request = new AlipayFundTransToaccountTransferRequest();
- $request->setBizContent(json_encode($parameter));
- $result = $this->aop->execute($request);
- $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
- $resultCode = $result->$responseNode->code;
- if (!empty($resultCode) && $resultCode == 10000) {
- return $this->success([
- 'out_trade_no' => $result->$responseNode->out_biz_no, // 商户交易号
- 'payment_no' => $result->$responseNode->order_id, // 微信付款单号
- 'payment_time' => date_to_time($result->$responseNode->pay_date) // 付款成功时间
- ]);
- } else {
- return $this->error([], $result->$responseNode->sub_msg);
- }
- } catch (\Exception $e) {
- return $this->error([], $e->getMessage());
- }
- }
-
- /**
- * 异步完成支付
- * @param $param
- */
- public function payNotify()
- {
-
-// Log::write('pay_notifiy_log:alipay:'.json_encode(input()), 'notice');
- try {
- $res = $this->aop->rsaCheckV1($_POST, $this->aop->alipayrsaPublicKey, $this->aop->signType);
- if ($res) { // 验证成功
- $out_trade_no = $_POST[ 'out_trade_no' ];
- // 支付宝交易号
- $trade_no = $_POST[ 'trade_no' ];
- // 交易状态
- $trade_status = $_POST[ 'trade_status' ];
- $pay_common = new PayCommon();
- if ($trade_status == "TRADE_SUCCESS") {
- $retval = $pay_common->onlinePay($out_trade_no, "alipay", $trade_no, "alipay");
- }
- echo "success";
- } else {
- // 验证失败
- echo "fail";
- }
- } catch (\Exception $e) {
- echo "fail";
- }
- }
-
- public function payNewTransfer($param)
- {
- try {
- $config_model = new Config();
- $config_result = $config_model->getPayConfig($param[ 'site_id' ]);
- if ($config_result[ 'code' ] < 0) return $config_result;
- $config = $config_result[ 'data' ][ 'value' ];
- if (empty($config)) return $this->error([], '未配置支付宝支付');
- if (!$config[ 'transfer_status' ]) return $this->error([], '未启用支付宝转账');
-
- $parameter = [
- 'out_biz_no' => $param[ 'out_trade_no' ],
- 'trans_amount' => sprintf("%.2f", $param[ 'amount' ]),
- 'product_code' => 'TRANS_ACCOUNT_NO_PWD',
- 'biz_scene' => 'DIRECT_TRANSFER',
- 'order_title' => '支付宝转账',
- 'remark' => $param[ "desc" ],
- 'payee_info' => [
- 'identity' => $param[ "account_number" ],
- 'identity_type' => "ALIPAY_LOGON_ID",
- 'name' => $param[ "real_name" ]
- ]
- ];
-
- // 建立请求
- $request = new AlipayFundTransUniTransferRequest();
- $request->setBizContent(json_encode($parameter));
- $result = $this->aop->execute($request);
- $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
- $resultCode = $result->$responseNode->code;
- if (!empty($resultCode) && $resultCode == 10000) {
- return $this->success([
- 'out_trade_no' => $result->$responseNode->out_biz_no, // 商户交易号
- 'payment_no' => $result->$responseNode->order_id, // 微信付款单号
- 'payment_time' => date_to_time($result->$responseNode->trans_date) // 付款成功时间
- ]);
- } else {
- return $this->error([], $result->$responseNode->sub_msg);
- }
- } catch (\Exception $e) {
- return $this->error([], $e->getMessage());
- }
- }
-
- /**
- * 付款码支付
- * @param $param
- * @return array|mixed|void
- */
- public function micropay($param)
- {
- try {
- //构造要请求的参数数组,无需改动
- $parameter = array (
- "out_trade_no" => $param[ "out_trade_no" ],
- "subject" => str_sub($param[ "pay_body" ], 15),
- "total_amount" => (float) $param[ "pay_money" ],
- "scene" => "bar_code",
- "auth_code" => $param[ 'auth_code' ],
- );
- $parameter = json_encode($parameter);
- $request = new AlipayTradePayRequest();
- $request->setBizContent($parameter);
- $result = $this->aop->execute($request);
- $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
- $resultCode = $result->$responseNode->code;
- Log::write('支付宝—付款码支付,result:' . json_encode($result));
- Log::write('支付宝—付款码支付,resultCode:' . json_encode($resultCode));
- if (!empty($resultCode)) {
- if ($resultCode == 10000) {
- $pay_common = new PayModel();
- return $res = $pay_common->onlinePay($param[ 'out_trade_no' ], 'alipay', $result->$responseNode->trade_no, 'alipay');
- } else if ($resultCode == 10003) {
- // 等待用户付款
- ( new Cron() )->addCron(1, 0, "查询付款码支付结果", "PayOrderQuery", time() + 3, $param[ 'id' ]);
- }
- } else {
- return $this->error([], $result->$responseNode->sub_msg);
- }
- } catch (\Exception $e) {
- return $this->error([], $e->getMessage());
- }
- }
-
- // todo 查询交易信息【AlipayTradeQueryRequest】 https://opendocs.alipay.com/open/194/106039?pathHash=5b8cf9e6
- public function orderQuery($param)
- {
- try {
- //构造要请求的参数数组,无需改动
- $parameter = array (
- "out_trade_no" => $param[ "out_trade_no" ],
- );
- $parameter = json_encode($parameter);
- $request = new AlipayTradeQueryRequest();
- $request->setBizContent($parameter);
- $result = $this->aop->execute($request);
- $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
- $resultCode = $result->$responseNode->code;
- Log::write('alipay_orderQuery' . json_encode($result));
- Log::write('alipay_orderQuery_$resultCode' . json_encode($resultCode));
- if (!empty($resultCode) && $resultCode == 10000) {
- if ($result->$responseNode->trade_status == 'TRADE_SUCCESS') {
- $pay_common = new PayModel();
- return $res = $pay_common->onlinePay($param[ 'out_trade_no' ], 'alipay', $result->$responseNode->trade_no, 'alipay');
- } else {
- ( new Cron() )->addCron(1, 0, "查询付款码支付结果", "PayOrderQuery", time() + 3, $param[ 'id' ]);
- }
-
- } else {
- return $this->error([], $result->$responseNode->sub_msg);
- }
- } catch (\Exception $e) {
- return $this->error([], $e->getMessage());
- }
- }
-
-
- /**
- * 查询订单信息
- * @param $out_trade_no
- * @return array
- * @throws \think\Exception
- */
- public function get($out_trade_no)
- {
- $parameter = array (
- "out_trade_no" => $out_trade_no
- );
- // 建立请求
- $request = new AlipayTradeQueryRequest();
- $request->setBizContent(json_encode($parameter));
- $result = $this->aop->execute($request);
- $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
- $resultCode = $result->$responseNode->code;
-
-
- if (!empty($resultCode) && $resultCode == 10000) {
- return $this->success(json_decode(json_encode($result->$responseNode), true));
- } else {
- return $this->error([], $result->$responseNode->sub_msg);
- }
- }
+is_aliapp = $is_aliapp;
+
+ try {
+ // 获取支付宝支付参数(统一支付到平台账户)
+ if ($is_aliapp) {
+ $config_info = ( new AliappConfig() )->getAliappConfig($site_id)[ 'data' ][ 'value' ];
+ } else {
+ $config_info = ( new Config() )->getPayConfig($site_id)[ 'data' ][ 'value' ];
+ }
+
+ if (!empty($config_info)) {
+ $countersign_type = $config_info[ 'countersign_type' ] ?? 0;
+
+ if ($countersign_type == 1) {
+ $appCertPath = $config_info[ "public_key_crt" ] ?? "";
+ $alipayCertPath = $config_info[ "alipay_public_key_crt" ] ?? "";
+ $rootCertPath = $config_info[ "alipay_with_crt" ] ?? "";
+
+ $this->aop = new AopCertClient();
+ //调用getPublicKey从支付宝公钥证书中提取公钥
+ $this->aop->alipayrsaPublicKey = $this->aop->getPublicKey($alipayCertPath);
+ //是否校验自动下载的支付宝公钥证书,如果开启校验要保证支付宝根证书在有效期内
+ $this->aop->isCheckAlipayPublicCert = false;
+ //调用getCertSN获取证书序列号
+ $this->aop->appCertSN = $this->aop->getCertSN($appCertPath);
+ //调用getRootCertSN获取支付宝根证书序列号
+ $this->aop->alipayRootCertSN = $this->aop->getRootCertSN($rootCertPath);
+
+ } else {
+ // 获取支付宝支付参数(统一支付到平台账户)
+ $this->aop = new AopClient();
+ $this->aop->alipayrsaPublicKey = $config_info[ 'public_key' ] ?? "";
+ $this->aop->alipayPublicKey = $config_info[ 'alipay_public_key' ] ?? "";
+ }
+ $this->aop->appId = $config_info[ "app_id" ] ?? "";
+ $this->aop->rsaPrivateKey = $config_info[ 'private_key' ] ?? "";
+ $this->aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
+ $this->aop->apiVersion = '1.0';
+ $this->aop->signType = 'RSA2';
+ $this->aop->postCharset = 'UTF-8';
+ $this->aop->format = 'json';
+
+ }
+// else{
+// return $this->error('', '支付宝支付未配置');
+// }
+
+ } catch (\Exception $e) {
+ return $this->error('', '支付宝配置错误');
+ }
+ }
+
+ /**
+ * 生成支付
+ * @param $param
+ * @return array
+ */
+ public function pay($param)
+ {
+ //构造要请求的参数数组,无需改动
+ $parameter = array (
+ "out_trade_no" => $param[ "out_trade_no" ],
+ "subject" => str_sub($param[ "pay_body" ], 15),
+ "total_amount" => (float) $param[ "pay_money" ],
+ "body" => str_sub($param[ "pay_body" ], 60),
+ "product_code" => 'FAST_INSTANT_TRADE_PAY',
+ );
+
+ switch ( $param[ "app_type" ] ) {
+ case "h5":
+ $request = new AlipayTradeWapPayRequest();
+ break;
+ case "pc":
+ $request = new AlipayTradePagePayRequest();
+ break;
+ case "app":
+ $request = new AlipayTradeAppPayRequest();
+ break;
+ case 'wechat':
+ $request = new AlipayTradeWapPayRequest();
+ break;
+ case 'cashier':
+ $request = new AlipayTradePrecreateRequest();
+ break;
+ case 'aliapp':
+ $parameter[ 'product_code' ] = 'FACE_TO_FACE_PAYMENT';
+
+ $member_info = model('member')->getInfo([ [ "member_id", "=", $param[ "member_id" ] ] ], 'ali_openid');
+ if (empty($member_info)) return $this->error(-1, '未获取到会员信息');
+
+ $parameter[ 'buyer_id' ] = $member_info[ 'ali_openid' ];
+ $request = new AlipayTradeCreateRequest();
+ break;
+ }
+
+ $parameter = json_encode($parameter);
+ $request->setBizContent($parameter);
+ $request->SetReturnUrl($param[ "return_url" ]);
+ $request->SetNotifyUrl($param[ "notify_url" ]);
+
+ ///绑定商户数据
+ $pay_model = new PayModel();
+ $pay_model->bindMchPay($param[ "out_trade_no" ], [ "is_aliapp" => $this->is_aliapp ]);
+
+ try {
+ if ($param[ "app_type" ] == 'h5' || $param[ "app_type" ] == 'wechat' || $param[ "app_type" ] == 'pc') {
+ $result = $this->aop->pageExecute($request, 'get');
+ return $this->success([
+ 'type' => 'url',
+ 'data' => $result
+ ]);
+ } elseif ($param[ "app_type" ] == 'app') {
+ $result = $this->aop->sdkExecute($request);
+ if (strpos(get_class($this->aop), 'AopClient') !== false) {
+ return $this->success([
+ 'type' => 'url',
+ 'data' => $result
+ ]);
+ }
+ } else {
+ $result = $this->aop->execute($request);
+ }
+ if ($result === false) return $this->error('', '支付宝发起支付失败');
+ } catch (\Exception $e) {
+ return $this->error('', $e->getMessage());
+ }
+
+ $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
+ $resultCode = $result->$responseNode->code;
+ if (!empty($resultCode) && $resultCode == 10000) {
+ switch ( $param[ "app_type" ] ) {
+ case 'cashier':
+ return $this->success([
+ 'type' => 'qrcode',
+ 'data' => [
+ 'qrcode' => $result->$responseNode->qr_code
+ ]
+ ]);
+ break;
+ case 'aliapp':
+ return $this->success([
+ 'type' => 'data',
+ 'data' => [
+ 'orderInfo' => $result->$responseNode->trade_no
+ ]
+ ]);
+ break;
+ default:
+ return $this->success();
+ }
+ } else {
+ return $this->error("", $result->$responseNode->sub_msg);
+ }
+ }
+
+ /**
+ * 支付关闭
+ * @param $param
+ * @return array
+ * @throws \think\Exception
+ */
+ public function close($param)
+ {
+ $parameter = array (
+ "out_trade_no" => $param[ "out_trade_no" ]
+ );
+ // 建立请求
+ $request = new AlipayTradeCloseRequest();
+ $request->setBizContent(json_encode($parameter));
+ $result = $this->aop->execute($request);
+ $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
+ $resultCode = $result->$responseNode->code;
+ if (!empty($resultCode) && $resultCode == 10000) {
+ return $this->success();
+ } else {
+ $sub_code = $result->$responseNode->sub_code;
+ $data = [];
+ if(in_array($sub_code, ['ACQ.TRADE_STATUS_ERROR', 'ACQ.REASON_TRADE_STATUS_INVALID', 'ACQ.REASON_ILLEGAL_STATUS'])){
+ $pay_order_result = $this->get($param[ "out_trade_no" ]);
+ if(!empty($pay_order_result) && $pay_order_result['code'] >= 0){
+ if($pay_order_result['data']['trade_status'] == 'TRADE_SUCCESS' || $pay_order_result['data']['trade_status'] == 'TRADE_FINISHED'){
+ $data['is_paid'] = 1;
+ }
+ }
+ }
+
+
+ return $this->error($data, $result->$responseNode->sub_msg);
+ }
+ }
+
+ /**
+ * 支付宝支付原路返回
+ * @param array $param 支付参数
+ * @return array
+ * @throws \think\Exception
+ */
+ public function refund($param)
+ {
+ $pay_info = $param[ "pay_info" ];
+ $refund_no = $param[ "refund_no" ];
+ $out_trade_no = $pay_info[ "trade_no" ] ?? '';
+ $refund_fee = $param[ "refund_fee" ];
+ $parameter = array (
+ 'trade_no' => $out_trade_no,
+ 'refund_amount' => sprintf("%.2f", $refund_fee),
+ 'out_request_no' => $refund_no
+ );
+ // 建立请求
+ $request = new AlipayTradeRefundRequest ();
+ $request->setBizContent(json_encode($parameter));
+ $result = $this->aop->execute($request);
+ $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
+ $resultCode = $result->$responseNode->code;
+ if (!empty($resultCode) && $resultCode == 10000) {
+ return $this->success();
+ } else {
+ return $this->error("", $result->$responseNode->sub_msg);
+ }
+ }
+
+ /**
+ * 支付宝转账
+ * @param $param
+ * @return array
+ */
+ public function payTransfer($param)
+ {
+ try {
+ $config_model = new Config();
+ $config_result = $config_model->getPayConfig($param[ 'site_id' ]);
+ if ($config_result[ 'code' ] < 0) return $config_result;
+ $config = $config_result[ 'data' ][ 'value' ];
+ if (empty($config)) return $this->error([], '未配置支付宝支付');
+ if (!$config[ 'transfer_status' ]) return $this->error([], '未启用支付宝转账');
+
+ $parameter = [
+ 'out_biz_no' => $param[ 'out_trade_no' ],
+ 'payee_type' => 'ALIPAY_LOGONID',
+ 'payee_account' => $param[ "account_number" ],
+ 'amount' => sprintf("%.2f", $param[ 'amount' ]),
+ 'payee_real_name' => $param[ "real_name" ],
+ 'remark' => $param[ "desc" ]
+ ];
+ // 建立请求
+ $request = new AlipayFundTransToaccountTransferRequest();
+ $request->setBizContent(json_encode($parameter));
+ $result = $this->aop->execute($request);
+ $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
+ $resultCode = $result->$responseNode->code;
+ if (!empty($resultCode) && $resultCode == 10000) {
+ return $this->success([
+ 'out_trade_no' => $result->$responseNode->out_biz_no, // 商户交易号
+ 'payment_no' => $result->$responseNode->order_id, // 微信付款单号
+ 'payment_time' => date_to_time($result->$responseNode->pay_date) // 付款成功时间
+ ]);
+ } else {
+ return $this->error([], $result->$responseNode->sub_msg);
+ }
+ } catch (\Exception $e) {
+ return $this->error([], $e->getMessage());
+ }
+ }
+
+ /**
+ * 异步完成支付
+ * @param $param
+ */
+ public function payNotify()
+ {
+
+// Log::write('pay_notifiy_log:alipay:'.json_encode(input()), 'notice');
+ try {
+ $res = $this->aop->rsaCheckV1($_POST, $this->aop->alipayrsaPublicKey, $this->aop->signType);
+ if ($res) { // 验证成功
+ $out_trade_no = $_POST[ 'out_trade_no' ];
+ // 支付宝交易号
+ $trade_no = $_POST[ 'trade_no' ];
+ // 交易状态
+ $trade_status = $_POST[ 'trade_status' ];
+ $pay_common = new PayCommon();
+ if ($trade_status == "TRADE_SUCCESS") {
+ $retval = $pay_common->onlinePay($out_trade_no, "alipay", $trade_no, "alipay");
+ }
+ echo "success";
+ } else {
+ // 验证失败
+ echo "fail";
+ }
+ } catch (\Exception $e) {
+ echo "fail";
+ }
+ }
+
+ public function payNewTransfer($param)
+ {
+ try {
+ $config_model = new Config();
+ $config_result = $config_model->getPayConfig($param[ 'site_id' ]);
+ if ($config_result[ 'code' ] < 0) return $config_result;
+ $config = $config_result[ 'data' ][ 'value' ];
+ if (empty($config)) return $this->error([], '未配置支付宝支付');
+ if (!$config[ 'transfer_status' ]) return $this->error([], '未启用支付宝转账');
+
+ $parameter = [
+ 'out_biz_no' => $param[ 'out_trade_no' ],
+ 'trans_amount' => sprintf("%.2f", $param[ 'amount' ]),
+ 'product_code' => 'TRANS_ACCOUNT_NO_PWD',
+ 'biz_scene' => 'DIRECT_TRANSFER',
+ 'order_title' => '支付宝转账',
+ 'remark' => $param[ "desc" ],
+ 'payee_info' => [
+ 'identity' => $param[ "account_number" ],
+ 'identity_type' => "ALIPAY_LOGON_ID",
+ 'name' => $param[ "real_name" ]
+ ]
+ ];
+
+ // 建立请求
+ $request = new AlipayFundTransUniTransferRequest();
+ $request->setBizContent(json_encode($parameter));
+ $result = $this->aop->execute($request);
+ $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
+ $resultCode = $result->$responseNode->code;
+ if (!empty($resultCode) && $resultCode == 10000) {
+ return $this->success([
+ 'out_trade_no' => $result->$responseNode->out_biz_no, // 商户交易号
+ 'payment_no' => $result->$responseNode->order_id, // 微信付款单号
+ 'payment_time' => date_to_time($result->$responseNode->trans_date) // 付款成功时间
+ ]);
+ } else {
+ return $this->error([], $result->$responseNode->sub_msg);
+ }
+ } catch (\Exception $e) {
+ return $this->error([], $e->getMessage());
+ }
+ }
+
+ /**
+ * 付款码支付
+ * @param $param
+ * @return array|mixed|void
+ */
+ public function micropay($param)
+ {
+ try {
+ //构造要请求的参数数组,无需改动
+ $parameter = array (
+ "out_trade_no" => $param[ "out_trade_no" ],
+ "subject" => str_sub($param[ "pay_body" ], 15),
+ "total_amount" => (float) $param[ "pay_money" ],
+ "scene" => "bar_code",
+ "auth_code" => $param[ 'auth_code' ],
+ );
+ $parameter = json_encode($parameter);
+ $request = new AlipayTradePayRequest();
+ $request->setBizContent($parameter);
+ $result = $this->aop->execute($request);
+ $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
+ $resultCode = $result->$responseNode->code;
+ Log::write('支付宝—付款码支付,result:' . json_encode($result));
+ Log::write('支付宝—付款码支付,resultCode:' . json_encode($resultCode));
+ if (!empty($resultCode)) {
+ if ($resultCode == 10000) {
+ $pay_common = new PayModel();
+ return $res = $pay_common->onlinePay($param[ 'out_trade_no' ], 'alipay', $result->$responseNode->trade_no, 'alipay');
+ } else if ($resultCode == 10003) {
+ // 等待用户付款
+ ( new Cron() )->addCron(1, 0, "查询付款码支付结果", "PayOrderQuery", time() + 3, $param[ 'id' ]);
+ }
+ } else {
+ return $this->error([], $result->$responseNode->sub_msg);
+ }
+ } catch (\Exception $e) {
+ return $this->error([], $e->getMessage());
+ }
+ }
+
+ // todo 查询交易信息【AlipayTradeQueryRequest】 https://opendocs.alipay.com/open/194/106039?pathHash=5b8cf9e6
+ public function orderQuery($param)
+ {
+ try {
+ //构造要请求的参数数组,无需改动
+ $parameter = array (
+ "out_trade_no" => $param[ "out_trade_no" ],
+ );
+ $parameter = json_encode($parameter);
+ $request = new AlipayTradeQueryRequest();
+ $request->setBizContent($parameter);
+ $result = $this->aop->execute($request);
+ $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
+ $resultCode = $result->$responseNode->code;
+ Log::write('alipay_orderQuery' . json_encode($result));
+ Log::write('alipay_orderQuery_$resultCode' . json_encode($resultCode));
+ if (!empty($resultCode) && $resultCode == 10000) {
+ if ($result->$responseNode->trade_status == 'TRADE_SUCCESS') {
+ $pay_common = new PayModel();
+ return $res = $pay_common->onlinePay($param[ 'out_trade_no' ], 'alipay', $result->$responseNode->trade_no, 'alipay');
+ } else {
+ ( new Cron() )->addCron(1, 0, "查询付款码支付结果", "PayOrderQuery", time() + 3, $param[ 'id' ]);
+ }
+
+ } else {
+ return $this->error([], $result->$responseNode->sub_msg);
+ }
+ } catch (\Exception $e) {
+ return $this->error([], $e->getMessage());
+ }
+ }
+
+
+ /**
+ * 查询订单信息
+ * @param $out_trade_no
+ * @return array
+ * @throws \think\Exception
+ */
+ public function get($out_trade_no)
+ {
+ $parameter = array (
+ "out_trade_no" => $out_trade_no
+ );
+ // 建立请求
+ $request = new AlipayTradeQueryRequest();
+ $request->setBizContent(json_encode($parameter));
+ $result = $this->aop->execute($request);
+ $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
+ $resultCode = $result->$responseNode->code;
+
+
+ if (!empty($resultCode) && $resultCode == 10000) {
+ return $this->success(json_decode(json_encode($result->$responseNode), true));
+ } else {
+ return $this->error([], $result->$responseNode->sub_msg);
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/alipay/shop/controller/Pay.php b/src/addon/alipay/shop/controller/Pay.php
index b410f5db9..08f022e1f 100644
--- a/src/addon/alipay/shop/controller/Pay.php
+++ b/src/addon/alipay/shop/controller/Pay.php
@@ -1,94 +1,86 @@
-isJson()) {
- $app_id = input("app_id", "");//支付宝应用ID (支付宝分配给开发者的应用ID)
- $private_key = input("private_key", "");//应用私钥
- $public_key = input("public_key", "");//应用公钥
- $alipay_public_key = input("alipay_public_key", "");//支付宝公钥
- $app_type = input("app_type", "");//支持端口 如web app
- $pay_status = input("pay_status", 0);//支付启用状态
- $refund_status = input("refund_status", 0);//退款启用状态
- $transfer_status = input("transfer_status", 0);//转账启用状态
- $public_key_crt = input("public_key_crt", "");
- $alipay_public_key_crt = input("alipay_public_key_crt", "");
- $alipay_with_crt = input("alipay_with_crt", "");
- $countersign_type = input("countersign_type", 0);//加签模式
-
- $data = array (
- "app_id" => $app_id,
- "private_key" => $private_key,
- "public_key" => $public_key,
- "alipay_public_key" => $alipay_public_key,
- "refund_status" => $refund_status,
- "pay_status" => $pay_status,
- "transfer_status" => $transfer_status,
- "app_type" => $app_type,
- "public_key_crt" => $public_key_crt,
- "alipay_public_key_crt" => $alipay_public_key_crt,
- "alipay_with_crt" => $alipay_with_crt,
- "countersign_type" => $countersign_type
- );
- $result = $config_model->setPayConfig($data, $this->site_id, $this->app_module);
- return $result;
- } else {
- $info = $config_model->getPayConfig($this->site_id, $this->app_module, true)[ 'data' ][ 'value' ];
-
- if (!empty($info)) {
- $app_type_arr = [];
- if (!empty($info[ 'app_type' ])) {
- $app_type_arr = explode(',', $info[ 'app_type' ]);
- }
- $info[ 'app_type_arr' ] = $app_type_arr;
- if (empty($info[ 'countersign_type' ])) {
- $info[ 'countersign_type' ] = 0;
- }
- }
- $this->assign("info", $info);
- $this->assign("app_type", Config::get("app_type"));
-
- return $this->fetch("pay/config");
- }
- }
-
- /**
- * 上传微信支付证书
- */
- public function uploadAlipayCrt()
- {
- $upload_model = new Upload();
- $site_id = request()->siteid();
- $name = input("name", "");
- $extend_type = [ 'crt' ];
- $param = array (
- "name" => "file",
- "extend_type" => $extend_type
- );
-
- $site_id = max($site_id, 0);
- $result = $upload_model->setPath("common/alipay/crt/" . $site_id . "/")->file($param);
- return $result;
- }
+isJson()) {
+ $app_id = input("app_id", "");//支付宝应用ID (支付宝分配给开发者的应用ID)
+ $private_key = input("private_key", "");//应用私钥
+ $public_key = input("public_key", "");//应用公钥
+ $alipay_public_key = input("alipay_public_key", "");//支付宝公钥
+ $app_type = input("app_type", "");//支持端口 如web app
+ $pay_status = input("pay_status", 0);//支付启用状态
+ $refund_status = input("refund_status", 0);//退款启用状态
+ $transfer_status = input("transfer_status", 0);//转账启用状态
+ $public_key_crt = input("public_key_crt", "");
+ $alipay_public_key_crt = input("alipay_public_key_crt", "");
+ $alipay_with_crt = input("alipay_with_crt", "");
+ $countersign_type = input("countersign_type", 0);//加签模式
+
+ $data = array (
+ "app_id" => $app_id,
+ "private_key" => $private_key,
+ "public_key" => $public_key,
+ "alipay_public_key" => $alipay_public_key,
+ "refund_status" => $refund_status,
+ "pay_status" => $pay_status,
+ "transfer_status" => $transfer_status,
+ "app_type" => $app_type,
+ "public_key_crt" => $public_key_crt,
+ "alipay_public_key_crt" => $alipay_public_key_crt,
+ "alipay_with_crt" => $alipay_with_crt,
+ "countersign_type" => $countersign_type
+ );
+ $result = $config_model->setPayConfig($data, $this->site_id, $this->app_module);
+ return $result;
+ } else {
+ $info = $config_model->getPayConfig($this->site_id, $this->app_module, true)[ 'data' ][ 'value' ];
+
+ if (!empty($info)) {
+ $app_type_arr = [];
+ if (!empty($info[ 'app_type' ])) {
+ $app_type_arr = explode(',', $info[ 'app_type' ]);
+ }
+ $info[ 'app_type_arr' ] = $app_type_arr;
+ if (empty($info[ 'countersign_type' ])) {
+ $info[ 'countersign_type' ] = 0;
+ }
+ }
+ $this->assign("info", $info);
+ $this->assign("app_type", Config::get("app_type"));
+
+ return $this->fetch("pay/config");
+ }
+ }
+
+ /**
+ * 上传微信支付证书
+ */
+ public function uploadAlipayCrt()
+ {
+ $upload_model = new Upload();
+ $site_id = request()->siteid();
+ $name = input("name", "");
+ $extend_type = [ 'crt' ];
+ $param = array (
+ "name" => "file",
+ "extend_type" => $extend_type
+ );
+
+ $site_id = max($site_id, 0);
+ $result = $upload_model->setPath("common/alipay/crt/" . $site_id . "/")->file($param);
+ return $result;
+ }
}
\ No newline at end of file
diff --git a/src/addon/cases/config/diy_view.php b/src/addon/cases/config/diy_view.php
index 65acacc12..cf82988ef 100644
--- a/src/addon/cases/config/diy_view.php
+++ b/src/addon/cases/config/diy_view.php
@@ -1,48 +1,40 @@
- '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
- 'template' => [],
-
- // 后台自定义组件——装修
- 'util' => [],
-
- // 自定义页面路径
- 'link' => [
- [
- 'name' => 'CASES_INFO',
- 'title' => '案例展示',
- 'parent' => 'BASICS_LINK',
- 'wap_url' => '/pages_tool/cases/index',
- 'web_url' => '',
- 'sort' => 0
- ]
- ],
-
- // 自定义图标库
- 'icon_library' => [],
-
- // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
- 'component' => [],
-
- // uni-app 页面,多个逗号隔开
- 'pages' => [],
-
- // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
- 'info' => [],
-
- // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
- 'theme' => [],
-
- // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
- 'data' => []
+ '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
+ 'template' => [],
+
+ // 后台自定义组件——装修
+ 'util' => [],
+
+ // 自定义页面路径
+ 'link' => [
+ [
+ 'name' => 'CASES_INFO',
+ 'title' => '案例展示',
+ 'parent' => 'BASICS_LINK',
+ 'wap_url' => '/pages_tool/cases/index',
+ 'web_url' => '',
+ 'sort' => 0
+ ]
+ ],
+
+ // 自定义图标库
+ 'icon_library' => [],
+
+ // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
+ 'component' => [],
+
+ // uni-app 页面,多个逗号隔开
+ 'pages' => [],
+
+ // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
+ 'info' => [],
+
+ // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
+ 'theme' => [],
+
+ // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
+ 'data' => []
];
\ No newline at end of file
diff --git a/src/addon/cases/config/info.php b/src/addon/cases/config/info.php
index 85d37bb95..6812ec8f3 100644
--- a/src/addon/cases/config/info.php
+++ b/src/addon/cases/config/info.php
@@ -1,21 +1,12 @@
- 'cases',
- 'title' => '案例展示',
- 'description' => '展示案例信息',
- 'type' => 'tool', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
- 'status' => 1,
- 'author' => '',
- 'version' => '1.0.0',
- 'version_no' => '2025051923121',
- 'content' => '',
+ 'cases',
+ 'title' => '案例展示',
+ 'description' => '展示案例信息',
+ 'type' => 'tool', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
+ 'status' => 1,
+ 'author' => '',
+ 'version' => '1.0.0',
+ 'version_no' => '2025051923121',
+ 'content' => '',
];
\ No newline at end of file
diff --git a/src/addon/cases/event/Install.php b/src/addon/cases/event/Install.php
index 3b17ea916..9acf97a90 100644
--- a/src/addon/cases/event/Install.php
+++ b/src/addon/cases/event/Install.php
@@ -1,25 +1,17 @@
-getMessage());
- }
- }
+getMessage());
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/coupon/api/controller/Coupon.php b/src/addon/coupon/api/controller/Coupon.php
index 7e84fce29..c3335fa3a 100644
--- a/src/addon/coupon/api/controller/Coupon.php
+++ b/src/addon/coupon/api/controller/Coupon.php
@@ -1,351 +1,343 @@
-params['coupon_type_id'] ?? 0;
- if (empty($coupon_type_id)) {
- return $this->response($this->error('', 'REQUEST_COUPON_TYPE_ID'));
- }
-
- $app_type = $this->params['app_type'] ?? 'h5';
-
- $coupon_model = new CouponModel();
- $condition = [
- [ 'coupon_type_id', '=', $coupon_type_id ],
- [ 'is_show', '=', 1 ],
- [ 'site_id', '=', $this->site_id ]
- ];
-
- $coupon_type_model = new CouponTypeModel();
- $qrcode = $coupon_type_model->qrcode($coupon_type_id, $app_type, $this->site_id)[ 'data' ];
-
- $info = $coupon_model->getCouponTypeInfo($condition);
- if (!empty($info[ 'data' ]) && !empty($qrcode)) {
- $info[ 'data' ][ 'qrcode' ] = $qrcode[ 'path' ];
- }
- return $this->response($info);
- }
-
- /**
- * 列表信息
- */
- public function memberpage()
- {
- $token = $this->checkToken();
- if ($token[ 'code' ] < 0) return $this->response($token);
-
- $page = $this->params['page'] ?? 1;
- $page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
- $state = $this->params['state'] ?? 1;//优惠券状态 1已领用(未使用) 2已使用 3已过期
-
- $coupon_model = new CouponModel();
- $condition = [
- [ 'npc.member_id', '=', $token[ 'data' ][ 'member_id' ] ],
- [ 'npc.state', '=', $state ]
- ];
-
- //按类型筛选
- $type = $this->params['type'] ?? '';
- $related_id = $this->params['related_id'] ?? 0;
- switch ( $type ) {
- case 'reward'://满减
- $condition[] = ['npc.type', '=', 'reward'];
- break;
- case 'discount'://折扣
- $condition[] = ['npc.type', '=', 'discount'];
- break;
- case 'no_threshold'://无门槛
- $condition[] = ['npc.at_least', '=', 0 ];
- break;
- }
- if (!empty($related_id)) {
- $condition[] = [ 'related_id', '=', $related_id ];
- }
-
- $list = $coupon_model->getMemberCouponPageList($condition, $page, $page_size);
-
- return $this->response($list);
- }
-
- /**
- * 优惠券类型列表
- */
- public function typelists()
- {
- $num = $this->params['num'] ?? 0;
- $coupon_type_id_arr = $this->params['coupon_type_id_arr'] ?? '';//coupon_type_id数组
- $can_receive = $this->params['can_receive'] ?? 0;// 是否只查询可领取的
-
- $token = $this->checkToken();
-
- $coupon_model = new CouponModel();
- $condition = [
- [ 'status', '=', 1 ],
- [ 'is_show', '=', 1 ],
- [ 'site_id', '=', $this->site_id ]
- ];
-
- //按类型查询
- $type = $this->params['type'] ?? '';
- switch ( $type ) {
- case 'reward'://满减
- $condition[] = ['type', '=', 'reward'];
- break;
- case 'discount'://折扣
- $condition[] = ['type', '=', 'discount'];
- break;
- case 'no_threshold'://无门槛
- $condition[] = ['at_least', '=', 0 ];
- break;
- }
-
- if (!empty($coupon_type_id_arr)) {
- $condition[] = [ 'coupon_type_id', 'in', $coupon_type_id_arr ];
- }
- $field = 'coupon_type_id,type,site_id,coupon_name,money,discount,max_fetch,at_least,end_time,image,validity_type,fixed_term,status,is_show,goods_type,discount_limit,count,lead_count,IF(count < 0 or count - lead_count > 0, 1, 0) as is_remain';
- if ($can_receive == 1) {
- $condition[] = [ [ 'count', '<>', Db::raw('lead_count') ] ];
- }
-
- $order = Db::raw('IF(count < 0 or count - lead_count > 0, 1, 0) DESC,sort ASC');
-
- $list = $coupon_model->getCouponTypeList($condition, $field, $order, $num);
- if (!empty($list[ 'data' ]) && $this->member_id) {
- foreach ($list[ 'data' ] as $k => $v) {
- $list[ 'data' ][ $k ][ 'member_coupon_num' ] = $coupon_model->getCouponCount([
- [ 'get_type', '=', 2 ],
- [ 'member_id', '=', $this->member_id ],
- [ 'coupon_type_id', '=', $v[ 'coupon_type_id' ] ]
- ])[ 'data' ];
- }
- }
-
- return $this->response($list);
- }
-
- /**
- * 优惠券类型分页列表
- */
- public function typepagelists()
- {
- $page = $this->params['page'] ?? 1;
- $page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
- $coupon_type_id_arr = $this->params['coupon_type_id_arr'] ?? '';//coupon_type_id数组
- $can_receive = $this->params['can_receive'] ?? 0;// 是否只查询可领取的
-
- $token = $this->checkToken();
-
- $coupon_model = new CouponModel();
- $condition = [
- [ 'status', '=', 1 ],
- [ 'is_show', '=', 1 ],
- [ 'site_id', '=', $this->site_id ]
- ];
-
- //按类型查询
- $type = $this->params['type'] ?? '';
- switch ( $type ) {
- case 'reward'://满减
- $condition[] = ['type', '=', 'reward'];
- break;
- case 'discount'://折扣
- $condition[] = ['type', '=', 'discount'];
- break;
- case 'no_threshold'://无门槛
- $condition[] = ['at_least', '=', 0 ];
- break;
- }
-
- if (!empty($coupon_type_id_arr)) {
- $condition[] = [ 'coupon_type_id', 'in', $coupon_type_id_arr ];
- }
- $field = 'coupon_type_id,type,site_id,coupon_name,money,discount,max_fetch,at_least,end_time,image,validity_type,fixed_term,status,is_show,goods_type,discount_limit,count,lead_count,IF(count < 0 or count - lead_count > 0, 1, 0) as is_remain';
- if ($can_receive == 1) {
- $condition[] = [ [ 'count', '<>', Db::raw('lead_count') ] ];
- }
-
- if ($this->member_id) {
- $prefix = config('database.connections.mysql.prefix');
- $field .= ', (select count(coupon_id) from ' . $prefix . 'promotion_coupon pc where pc.coupon_type_id = ct.coupon_type_id and pc.get_type=2 and pc.member_id=' . $this->member_id . ') as member_coupon_num';
- }
-
- $order = Db::raw('IF(count < 0 or count - lead_count > 0, 1, 0) DESC,sort ASC');
-
- $list = $coupon_model->getCouponTypePageList($condition, $page, $page_size, $order, $field, 'ct');
-
- return $this->response($list);
- }
-
- /**
- * 获取优惠券
- */
- public function receive()
- {
- $token = $this->checkToken();
- if ($token[ 'code' ] < 0) return $this->response($token);
-
- $site_id = $this->site_id;
- $coupon_type_id = $this->params['coupon_type_id'] ?? 0;
- $get_type = $this->params['get_type'] ?? 2;//获取方式:1订单2.直接领取3.活动领取
-
- if (empty($coupon_type_id)) {
- return $this->response($this->error('', 'REQUEST_COUPON_TYPE_ID'));
- }
-
- $coupon_model = new CouponModel();
- $res = $coupon_model->receiveCoupon($coupon_type_id, $site_id, $token[ 'data' ][ 'member_id' ], $get_type);
- $res[ 'data' ] = [];
-
- //判断一下用户是否拥有当前优惠券
- $coupon = $coupon_model->getCouponInfo([ [ 'coupon_type_id', '=', $coupon_type_id ], [ 'site_id', '=', $site_id ], [ 'member_id', '=', $token[ 'data' ][ 'member_id' ] ] ], 'coupon_id')[ 'data' ];
- $res[ 'data' ][ 'is_exist' ] = empty($coupon) ? 0 : 1;
- return $this->response($res);
- }
-
- /**
- * 会员优惠券数量
- * @return string
- */
- public function num()
- {
- $token = $this->checkToken();
- if ($token[ 'code' ] < 0) return $this->response($token);
-
- $state = $this->params[ 'state' ] ?? 1;
- $coupon_model = new MemberCoupon();
-
- $count = $coupon_model->getMemberCouponNum($token[ 'data' ][ 'member_id' ], $state);
- return $this->response($count);
- }
-
- /**
- * 是否可以领取
- */
- public function receivedNum()
- {
- $token = $this->checkToken();
- if ($token[ 'code' ] < 0) return $this->response($token);
-
- $coupon_type_id = $this->params['coupon_type_id'] ?? 0;
-
- $coupon_model = new MemberCoupon();
- $res = $coupon_model->receivedNum($coupon_type_id, $this->member_id);
- return $this->response($res);
- }
-
- /**
- * 查询商品可用的优惠券
- * @param int $id
- * @return false|string
- */
- public function goodsCoupon($id = 0)
- {
- $this->checkToken();
- $coupon_model = new CouponModel();
- $goods_id = $this->params[ 'goods_id' ] ?? 0;
- if (!empty($id)) {
- $goods_id = $id;
- }
-
- // 查询全部商品参与
- $condition = [
- [ 'site_id', '=', $this->site_id ],
- [ 'status', '=', 1 ],
- [ 'is_show', '=', 1 ],
- [ 'goods_type', '=', 1 ]
- ];
-
- $field = 'count,lead_count,coupon_type_id,coupon_type_id as type_id,type,site_id,coupon_name,money,discount,max_fetch,at_least,end_time,validity_type,fixed_term,goods_type,discount_limit';
-
- if ($this->member_id) {
- $prefix = config('database.connections.mysql.prefix');
- $field .= ',(select count(coupon_id) from ' . $prefix . 'promotion_coupon pc where pc.coupon_type_id = type_id and pc.get_type=2 and pc.member_id=' . $this->member_id . ') as member_coupon_num';
- }
-
- $list = $coupon_model->getCouponTypeList($condition, $field, 'money desc', null, 'ct');
-
- // 查询指定商品参与
- $goods_condition = [
- [ 'site_id', '=', $this->site_id ],
- [ 'status', '=', 1 ],
- [ 'is_show', '=', 1 ],
- [ 'goods_type', '=', 2 ],
- [ 'goods_ids', 'like', "%,$goods_id,%" ]
- ];
-
- $goods_coupon = $coupon_model->getCouponTypeList($goods_condition, $field, 'money desc', null, 'ct');
-
- if (!empty($goods_coupon[ 'data' ])) {
- $list[ 'data' ] = array_merge($list[ 'data' ], $goods_coupon[ 'data' ]);
- }
-
- // 查询指定商品不参与
- $not_goods_condition = [
- [ 'site_id', '=', $this->site_id ],
- [ 'status', '=', 1 ],
- [ 'is_show', '=', 1 ],
- [ 'goods_type', '=', 3 ],
- [ 'goods_ids', 'not like', "%,$goods_id,%" ]
- ];
-
- $not_goods_coupon = $coupon_model->getCouponTypeList($not_goods_condition, $field, 'money desc', null, 'ct');
- if (!empty($not_goods_coupon[ 'data' ])) {
- $list[ 'data' ] = array_merge($list[ 'data' ], $not_goods_coupon[ 'data' ]);
- }
-
- if ($list[ 'data' ] && $this->member_id) {
- foreach ($list[ 'data' ] as $k => $v) {
- // 已抢光
- if ($v[ 'count' ] == $v[ 'lead_count' ]) {
- unset($list[ 'data' ][ $k ]);
- } elseif ($v[ 'max_fetch' ] != 0 && $v[ 'member_coupon_num' ] > 0 && $v[ 'member_coupon_num' ] >= $v[ 'max_fetch' ]) {
- // 已领取
- unset($list[ 'data' ][ $k ]);
- }
- }
- $list[ 'data' ] = array_values($list[ 'data' ]);
- }
- return $this->response($list);
- }
-
- /**
- * 查询优惠券通过优惠券类型id
- */
- public function couponById()
- {
- $id = $this->params[ 'id' ] ?? 0;
- $coupon_model = new CouponModel();
- $condition = [
- [ 'site_id', '=', $this->site_id ],
- [ 'status', '=', 1 ],
- [ 'coupon_type_id', 'in', $id ]
- ];
- $list = $coupon_model->getCouponTypeList($condition, 'coupon_type_id,type,site_id,coupon_name,money,discount,max_fetch,at_least,end_time,validity_type,fixed_term,goods_type,discount_limit', 'money desc', '');
- return $this->response($list);
- }
+params['coupon_type_id'] ?? 0;
+ if (empty($coupon_type_id)) {
+ return $this->response($this->error('', 'REQUEST_COUPON_TYPE_ID'));
+ }
+
+ $app_type = $this->params['app_type'] ?? 'h5';
+
+ $coupon_model = new CouponModel();
+ $condition = [
+ [ 'coupon_type_id', '=', $coupon_type_id ],
+ [ 'is_show', '=', 1 ],
+ [ 'site_id', '=', $this->site_id ]
+ ];
+
+ $coupon_type_model = new CouponTypeModel();
+ $qrcode = $coupon_type_model->qrcode($coupon_type_id, $app_type, $this->site_id)[ 'data' ];
+
+ $info = $coupon_model->getCouponTypeInfo($condition);
+ if (!empty($info[ 'data' ]) && !empty($qrcode)) {
+ $info[ 'data' ][ 'qrcode' ] = $qrcode[ 'path' ];
+ }
+ return $this->response($info);
+ }
+
+ /**
+ * 列表信息
+ */
+ public function memberpage()
+ {
+ $token = $this->checkToken();
+ if ($token[ 'code' ] < 0) return $this->response($token);
+
+ $page = $this->params['page'] ?? 1;
+ $page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
+ $state = $this->params['state'] ?? 1;//优惠券状态 1已领用(未使用) 2已使用 3已过期
+
+ $coupon_model = new CouponModel();
+ $condition = [
+ [ 'npc.member_id', '=', $token[ 'data' ][ 'member_id' ] ],
+ [ 'npc.state', '=', $state ]
+ ];
+
+ //按类型筛选
+ $type = $this->params['type'] ?? '';
+ $related_id = $this->params['related_id'] ?? 0;
+ switch ( $type ) {
+ case 'reward'://满减
+ $condition[] = ['npc.type', '=', 'reward'];
+ break;
+ case 'discount'://折扣
+ $condition[] = ['npc.type', '=', 'discount'];
+ break;
+ case 'no_threshold'://无门槛
+ $condition[] = ['npc.at_least', '=', 0 ];
+ break;
+ }
+ if (!empty($related_id)) {
+ $condition[] = [ 'related_id', '=', $related_id ];
+ }
+
+ $list = $coupon_model->getMemberCouponPageList($condition, $page, $page_size);
+
+ return $this->response($list);
+ }
+
+ /**
+ * 优惠券类型列表
+ */
+ public function typelists()
+ {
+ $num = $this->params['num'] ?? 0;
+ $coupon_type_id_arr = $this->params['coupon_type_id_arr'] ?? '';//coupon_type_id数组
+ $can_receive = $this->params['can_receive'] ?? 0;// 是否只查询可领取的
+
+ $token = $this->checkToken();
+
+ $coupon_model = new CouponModel();
+ $condition = [
+ [ 'status', '=', 1 ],
+ [ 'is_show', '=', 1 ],
+ [ 'site_id', '=', $this->site_id ]
+ ];
+
+ //按类型查询
+ $type = $this->params['type'] ?? '';
+ switch ( $type ) {
+ case 'reward'://满减
+ $condition[] = ['type', '=', 'reward'];
+ break;
+ case 'discount'://折扣
+ $condition[] = ['type', '=', 'discount'];
+ break;
+ case 'no_threshold'://无门槛
+ $condition[] = ['at_least', '=', 0 ];
+ break;
+ }
+
+ if (!empty($coupon_type_id_arr)) {
+ $condition[] = [ 'coupon_type_id', 'in', $coupon_type_id_arr ];
+ }
+ $field = 'coupon_type_id,type,site_id,coupon_name,money,discount,max_fetch,at_least,end_time,image,validity_type,fixed_term,status,is_show,goods_type,discount_limit,count,lead_count,IF(count < 0 or count - lead_count > 0, 1, 0) as is_remain';
+ if ($can_receive == 1) {
+ $condition[] = [ [ 'count', '<>', Db::raw('lead_count') ] ];
+ }
+
+ $order = Db::raw('IF(count < 0 or count - lead_count > 0, 1, 0) DESC,sort ASC');
+
+ $list = $coupon_model->getCouponTypeList($condition, $field, $order, $num);
+ if (!empty($list[ 'data' ]) && $this->member_id) {
+ foreach ($list[ 'data' ] as $k => $v) {
+ $list[ 'data' ][ $k ][ 'member_coupon_num' ] = $coupon_model->getCouponCount([
+ [ 'get_type', '=', 2 ],
+ [ 'member_id', '=', $this->member_id ],
+ [ 'coupon_type_id', '=', $v[ 'coupon_type_id' ] ]
+ ])[ 'data' ];
+ }
+ }
+
+ return $this->response($list);
+ }
+
+ /**
+ * 优惠券类型分页列表
+ */
+ public function typepagelists()
+ {
+ $page = $this->params['page'] ?? 1;
+ $page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
+ $coupon_type_id_arr = $this->params['coupon_type_id_arr'] ?? '';//coupon_type_id数组
+ $can_receive = $this->params['can_receive'] ?? 0;// 是否只查询可领取的
+
+ $token = $this->checkToken();
+
+ $coupon_model = new CouponModel();
+ $condition = [
+ [ 'status', '=', 1 ],
+ [ 'is_show', '=', 1 ],
+ [ 'site_id', '=', $this->site_id ]
+ ];
+
+ //按类型查询
+ $type = $this->params['type'] ?? '';
+ switch ( $type ) {
+ case 'reward'://满减
+ $condition[] = ['type', '=', 'reward'];
+ break;
+ case 'discount'://折扣
+ $condition[] = ['type', '=', 'discount'];
+ break;
+ case 'no_threshold'://无门槛
+ $condition[] = ['at_least', '=', 0 ];
+ break;
+ }
+
+ if (!empty($coupon_type_id_arr)) {
+ $condition[] = [ 'coupon_type_id', 'in', $coupon_type_id_arr ];
+ }
+ $field = 'coupon_type_id,type,site_id,coupon_name,money,discount,max_fetch,at_least,end_time,image,validity_type,fixed_term,status,is_show,goods_type,discount_limit,count,lead_count,IF(count < 0 or count - lead_count > 0, 1, 0) as is_remain';
+ if ($can_receive == 1) {
+ $condition[] = [ [ 'count', '<>', Db::raw('lead_count') ] ];
+ }
+
+ if ($this->member_id) {
+ $prefix = config('database.connections.mysql.prefix');
+ $field .= ', (select count(coupon_id) from ' . $prefix . 'promotion_coupon pc where pc.coupon_type_id = ct.coupon_type_id and pc.get_type=2 and pc.member_id=' . $this->member_id . ') as member_coupon_num';
+ }
+
+ $order = Db::raw('IF(count < 0 or count - lead_count > 0, 1, 0) DESC,sort ASC');
+
+ $list = $coupon_model->getCouponTypePageList($condition, $page, $page_size, $order, $field, 'ct');
+
+ return $this->response($list);
+ }
+
+ /**
+ * 获取优惠券
+ */
+ public function receive()
+ {
+ $token = $this->checkToken();
+ if ($token[ 'code' ] < 0) return $this->response($token);
+
+ $site_id = $this->site_id;
+ $coupon_type_id = $this->params['coupon_type_id'] ?? 0;
+ $get_type = $this->params['get_type'] ?? 2;//获取方式:1订单2.直接领取3.活动领取
+
+ if (empty($coupon_type_id)) {
+ return $this->response($this->error('', 'REQUEST_COUPON_TYPE_ID'));
+ }
+
+ $coupon_model = new CouponModel();
+ $res = $coupon_model->receiveCoupon($coupon_type_id, $site_id, $token[ 'data' ][ 'member_id' ], $get_type);
+ $res[ 'data' ] = [];
+
+ //判断一下用户是否拥有当前优惠券
+ $coupon = $coupon_model->getCouponInfo([ [ 'coupon_type_id', '=', $coupon_type_id ], [ 'site_id', '=', $site_id ], [ 'member_id', '=', $token[ 'data' ][ 'member_id' ] ] ], 'coupon_id')[ 'data' ];
+ $res[ 'data' ][ 'is_exist' ] = empty($coupon) ? 0 : 1;
+ return $this->response($res);
+ }
+
+ /**
+ * 会员优惠券数量
+ * @return string
+ */
+ public function num()
+ {
+ $token = $this->checkToken();
+ if ($token[ 'code' ] < 0) return $this->response($token);
+
+ $state = $this->params[ 'state' ] ?? 1;
+ $coupon_model = new MemberCoupon();
+
+ $count = $coupon_model->getMemberCouponNum($token[ 'data' ][ 'member_id' ], $state);
+ return $this->response($count);
+ }
+
+ /**
+ * 是否可以领取
+ */
+ public function receivedNum()
+ {
+ $token = $this->checkToken();
+ if ($token[ 'code' ] < 0) return $this->response($token);
+
+ $coupon_type_id = $this->params['coupon_type_id'] ?? 0;
+
+ $coupon_model = new MemberCoupon();
+ $res = $coupon_model->receivedNum($coupon_type_id, $this->member_id);
+ return $this->response($res);
+ }
+
+ /**
+ * 查询商品可用的优惠券
+ * @param int $id
+ * @return false|string
+ */
+ public function goodsCoupon($id = 0)
+ {
+ $this->checkToken();
+ $coupon_model = new CouponModel();
+ $goods_id = $this->params[ 'goods_id' ] ?? 0;
+ if (!empty($id)) {
+ $goods_id = $id;
+ }
+
+ // 查询全部商品参与
+ $condition = [
+ [ 'site_id', '=', $this->site_id ],
+ [ 'status', '=', 1 ],
+ [ 'is_show', '=', 1 ],
+ [ 'goods_type', '=', 1 ]
+ ];
+
+ $field = 'count,lead_count,coupon_type_id,coupon_type_id as type_id,type,site_id,coupon_name,money,discount,max_fetch,at_least,end_time,validity_type,fixed_term,goods_type,discount_limit';
+
+ if ($this->member_id) {
+ $prefix = config('database.connections.mysql.prefix');
+ $field .= ',(select count(coupon_id) from ' . $prefix . 'promotion_coupon pc where pc.coupon_type_id = type_id and pc.get_type=2 and pc.member_id=' . $this->member_id . ') as member_coupon_num';
+ }
+
+ $list = $coupon_model->getCouponTypeList($condition, $field, 'money desc', null, 'ct');
+
+ // 查询指定商品参与
+ $goods_condition = [
+ [ 'site_id', '=', $this->site_id ],
+ [ 'status', '=', 1 ],
+ [ 'is_show', '=', 1 ],
+ [ 'goods_type', '=', 2 ],
+ [ 'goods_ids', 'like', "%,$goods_id,%" ]
+ ];
+
+ $goods_coupon = $coupon_model->getCouponTypeList($goods_condition, $field, 'money desc', null, 'ct');
+
+ if (!empty($goods_coupon[ 'data' ])) {
+ $list[ 'data' ] = array_merge($list[ 'data' ], $goods_coupon[ 'data' ]);
+ }
+
+ // 查询指定商品不参与
+ $not_goods_condition = [
+ [ 'site_id', '=', $this->site_id ],
+ [ 'status', '=', 1 ],
+ [ 'is_show', '=', 1 ],
+ [ 'goods_type', '=', 3 ],
+ [ 'goods_ids', 'not like', "%,$goods_id,%" ]
+ ];
+
+ $not_goods_coupon = $coupon_model->getCouponTypeList($not_goods_condition, $field, 'money desc', null, 'ct');
+ if (!empty($not_goods_coupon[ 'data' ])) {
+ $list[ 'data' ] = array_merge($list[ 'data' ], $not_goods_coupon[ 'data' ]);
+ }
+
+ if ($list[ 'data' ] && $this->member_id) {
+ foreach ($list[ 'data' ] as $k => $v) {
+ // 已抢光
+ if ($v[ 'count' ] == $v[ 'lead_count' ]) {
+ unset($list[ 'data' ][ $k ]);
+ } elseif ($v[ 'max_fetch' ] != 0 && $v[ 'member_coupon_num' ] > 0 && $v[ 'member_coupon_num' ] >= $v[ 'max_fetch' ]) {
+ // 已领取
+ unset($list[ 'data' ][ $k ]);
+ }
+ }
+ $list[ 'data' ] = array_values($list[ 'data' ]);
+ }
+ return $this->response($list);
+ }
+
+ /**
+ * 查询优惠券通过优惠券类型id
+ */
+ public function couponById()
+ {
+ $id = $this->params[ 'id' ] ?? 0;
+ $coupon_model = new CouponModel();
+ $condition = [
+ [ 'site_id', '=', $this->site_id ],
+ [ 'status', '=', 1 ],
+ [ 'coupon_type_id', 'in', $id ]
+ ];
+ $list = $coupon_model->getCouponTypeList($condition, 'coupon_type_id,type,site_id,coupon_name,money,discount,max_fetch,at_least,end_time,validity_type,fixed_term,goods_type,discount_limit', 'money desc', '');
+ return $this->response($list);
+ }
}
\ No newline at end of file
diff --git a/src/addon/coupon/config/diy_view.php b/src/addon/coupon/config/diy_view.php
index 2e312f81e..586432484 100644
--- a/src/addon/coupon/config/diy_view.php
+++ b/src/addon/coupon/config/diy_view.php
@@ -1,67 +1,59 @@
- '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
- 'template' => [],
-
- // 后台自定义组件——装修
- 'util' => [
- [
- 'name' => 'Coupon',
- 'title' => '优惠券',
- 'type' => 'PROMOTION',
- 'value' => '{"style":1,"sources":"initial","styleName":"风格一","couponIds":[],"count":6,"previewList":[],"nameColor":"","moneyColor":"#FFFFFF","limitColor":"#FFFFFF","btnStyle":{"maxLen": 4,"textColor":"#FFFFFF","bgColor":"","text":"立即领取","aroundRadius":0,"isBgColor":false,"isAroundRadius":false},"isName":false,"couponBgColor":"","couponBgUrl":"","couponType":"img","ifNeedBg":true}',
- 'sort' => '30000',
- 'support_diy_view' => '',
- 'max_count' => 0,
- 'icon' => 'iconfont iconyouhuiquan',
- ],
- ],
-
- // 自定义页面路径
- 'link' => [
- [
- 'name' => 'COUPON_LIST',
- 'title' => '优惠券',
- 'parent' => 'MARKETING_LINK',
- 'wap_url' => '',
- 'web_url' => '',
- 'sort' => 0,
- 'child_list' => [
- [
- 'name' => 'COUPON_PREFECTURE',
- 'title' => '优惠券专区',
- 'wap_url' => '/pages_tool/goods/coupon',
- 'web_url' => '',
- 'sort' => 0
- ]
- ]
- ],
- ],
-
- // 自定义图标库
- 'icon_library' => [],
-
- // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
- 'component' => [],
-
- // uni-app 页面,多个逗号隔开
- 'pages' => [],
-
- // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
- 'info' => [],
-
- // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
- 'theme' => [],
-
- // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
- 'data' => []
+ '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
+ 'template' => [],
+
+ // 后台自定义组件——装修
+ 'util' => [
+ [
+ 'name' => 'Coupon',
+ 'title' => '优惠券',
+ 'type' => 'PROMOTION',
+ 'value' => '{"style":1,"sources":"initial","styleName":"风格一","couponIds":[],"count":6,"previewList":[],"nameColor":"","moneyColor":"#FFFFFF","limitColor":"#FFFFFF","btnStyle":{"maxLen": 4,"textColor":"#FFFFFF","bgColor":"","text":"立即领取","aroundRadius":0,"isBgColor":false,"isAroundRadius":false},"isName":false,"couponBgColor":"","couponBgUrl":"","couponType":"img","ifNeedBg":true}',
+ 'sort' => '30000',
+ 'support_diy_view' => '',
+ 'max_count' => 0,
+ 'icon' => 'iconfont iconyouhuiquan',
+ ],
+ ],
+
+ // 自定义页面路径
+ 'link' => [
+ [
+ 'name' => 'COUPON_LIST',
+ 'title' => '优惠券',
+ 'parent' => 'MARKETING_LINK',
+ 'wap_url' => '',
+ 'web_url' => '',
+ 'sort' => 0,
+ 'child_list' => [
+ [
+ 'name' => 'COUPON_PREFECTURE',
+ 'title' => '优惠券专区',
+ 'wap_url' => '/pages_tool/goods/coupon',
+ 'web_url' => '',
+ 'sort' => 0
+ ]
+ ]
+ ],
+ ],
+
+ // 自定义图标库
+ 'icon_library' => [],
+
+ // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
+ 'component' => [],
+
+ // uni-app 页面,多个逗号隔开
+ 'pages' => [],
+
+ // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
+ 'info' => [],
+
+ // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
+ 'theme' => [],
+
+ // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
+ 'data' => []
];
\ No newline at end of file
diff --git a/src/addon/coupon/config/info.php b/src/addon/coupon/config/info.php
index a57819fca..5fcaf5bf7 100644
--- a/src/addon/coupon/config/info.php
+++ b/src/addon/coupon/config/info.php
@@ -1,21 +1,12 @@
- 'coupon',
- 'title' => '优惠券',
- 'description' => '会员优惠券功能',
- 'type' => 'system', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
- 'status' => 1,
- 'author' => '',
- 'version' => '5.3.1',
- 'version_no' => '525231212001',
- 'content' => '',
+ 'coupon',
+ 'title' => '优惠券',
+ 'description' => '会员优惠券功能',
+ 'type' => 'system', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
+ 'status' => 1,
+ 'author' => '',
+ 'version' => '5.3.1',
+ 'version_no' => '525231212001',
+ 'content' => '',
];
\ No newline at end of file
diff --git a/src/addon/coupon/dict/CouponDict.php b/src/addon/coupon/dict/CouponDict.php
index 32f53405c..4356dbe4f 100644
--- a/src/addon/coupon/dict/CouponDict.php
+++ b/src/addon/coupon/dict/CouponDict.php
@@ -1,55 +1,46 @@
- '待使用',
- self::used => '已使用',
- self::expire => '已过期',
- self::close => '已关闭',
- ];
-
- if($status) return $list[$status] ?? '';
- return $list;
- }
-
- const all = 1;
- const selected = 2;
- const selected_out = 3;
- public static function getGoodsType($type = ''){
- $list = [
- self::all => '全部商品参与',
- self::selected => '指定商品参与',
- self::selected_out => '指定不参与商品'
- ];
-
- if($type) return $list[$type] ?? '';
- return $list;
- }
-}
+ '待使用',
+ self::used => '已使用',
+ self::expire => '已过期',
+ self::close => '已关闭',
+ ];
+
+ if($status) return $list[$status] ?? '';
+ return $list;
+ }
+
+ const all = 1;
+ const selected = 2;
+ const selected_out = 3;
+ public static function getGoodsType($type = ''){
+ $list = [
+ self::all => '全部商品参与',
+ self::selected => '指定商品参与',
+ self::selected_out => '指定不参与商品'
+ ];
+
+ if($type) return $list[$type] ?? '';
+ return $list;
+ }
+}
diff --git a/src/addon/coupon/event/CronCouponEnd.php b/src/addon/coupon/event/CronCouponEnd.php
index e4421fca7..df8f8cf81 100644
--- a/src/addon/coupon/event/CronCouponEnd.php
+++ b/src/addon/coupon/event/CronCouponEnd.php
@@ -1,27 +1,19 @@
-cronCouponEnd();
- return $res;
- }
+cronCouponEnd();
+ return $res;
+ }
}
\ No newline at end of file
diff --git a/src/addon/coupon/event/CronCouponTypeEnd.php b/src/addon/coupon/event/CronCouponTypeEnd.php
index ca91366c1..064d731ba 100644
--- a/src/addon/coupon/event/CronCouponTypeEnd.php
+++ b/src/addon/coupon/event/CronCouponTypeEnd.php
@@ -1,27 +1,19 @@
-couponCronEnd($params[ 'relate_id' ]);
- return $res;
- }
+couponCronEnd($params[ 'relate_id' ]);
+ return $res;
+ }
}
\ No newline at end of file
diff --git a/src/addon/coupon/event/Install.php b/src/addon/coupon/event/Install.php
index d2ea56273..df186f6a7 100644
--- a/src/addon/coupon/event/Install.php
+++ b/src/addon/coupon/event/Install.php
@@ -1,38 +1,29 @@
-deleteCron([ ['event', '=', 'CronCouponEnd'] ]);
- $cron->addCron(2, 1, '优惠券过期自动关闭', 'CronCouponEnd', time(), 0);
-
- return success();
- } catch (\Exception $e) {
- return error('', $e->getMessage());
- }
- }
+deleteCron([ ['event', '=', 'CronCouponEnd'] ]);
+ $cron->addCron(2, 1, '优惠券过期自动关闭', 'CronCouponEnd', time(), 0);
+
+ return success();
+ } catch (\Exception $e) {
+ return error('', $e->getMessage());
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/coupon/event/ShowPromotion.php b/src/addon/coupon/event/ShowPromotion.php
index 532d02828..558531b12 100644
--- a/src/addon/coupon/event/ShowPromotion.php
+++ b/src/addon/coupon/event/ShowPromotion.php
@@ -1,46 +1,38 @@
- [
- [
- //插件名称
- 'name' => 'coupon',
- //展示分类(根据平台端设置,admin(平台营销),shop:店铺营销,member:会员营销, tool:应用工具)
- 'show_type' => 'shop',
- //展示主题
- 'title' => '优惠券',
- //展示介绍
- 'description' => '设置商家优惠券',
- //展示图标
- 'icon' => 'addon/coupon/icon.png',
- //跳转链接
- 'url' => 'coupon://shop/coupon/lists',
- ]
- ]
-
- ];
- return $data;
- }
+ [
+ [
+ //插件名称
+ 'name' => 'coupon',
+ //展示分类(根据平台端设置,admin(平台营销),shop:店铺营销,member:会员营销, tool:应用工具)
+ 'show_type' => 'shop',
+ //展示主题
+ 'title' => '优惠券',
+ //展示介绍
+ 'description' => '设置商家优惠券',
+ //展示图标
+ 'icon' => 'addon/coupon/icon.png',
+ //跳转链接
+ 'url' => 'coupon://shop/coupon/lists',
+ ]
+ ]
+
+ ];
+ return $data;
+ }
}
\ No newline at end of file
diff --git a/src/addon/coupon/event/UnInstall.php b/src/addon/coupon/event/UnInstall.php
index 5546a8f61..d95f45a44 100644
--- a/src/addon/coupon/event/UnInstall.php
+++ b/src/addon/coupon/event/UnInstall.php
@@ -1,32 +1,23 @@
-getMessage());
- }
- }
+getMessage());
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/coupon/model/Coupon.php b/src/addon/coupon/model/Coupon.php
index bec396e35..b69646d5b 100644
--- a/src/addon/coupon/model/Coupon.php
+++ b/src/addon/coupon/model/Coupon.php
@@ -1,645 +1,637 @@
- '消费奖励',
- 2 => '直接领取',
- 3 => '会员升级奖励',
- 4 => '商家发放',
- 6 => '活动奖励'
- ];
- $event = event('CouponGetType');
- if (!empty($event)) {
- foreach ($event as $k => $v) {
- $get_type[ array_keys($v)[ 0 ] ] = array_values($v)[ 0 ];
- }
- }
- if ($type) return $get_type[ $type ] ?? '';
- else return $get_type;
- }
-
- /**
- * 获取编码
- */
- public function getCode()
- {
- return random_keys(8);
- }
-
- /**
- * 领取优惠券
- * @param $coupon_type_id
- * @param $site_id
- * @param $member_id
- * @param $get_type
- * @param int $is_stock
- * @param int $is_limit
- * @return array
- */
- public function receiveCoupon($coupon_type_id, $site_id, $member_id, $get_type, $is_stock = 0, $is_limit = 1)
- {
- // 用户已领取数量
- if (empty($member_id)) {
- return $this->error('', '请先进行登录');
- }
- $coupon_type_info = model('promotion_coupon_type')->getInfo([ 'coupon_type_id' => $coupon_type_id, 'site_id' => $site_id ]);
- if (!empty($coupon_type_info)) {
- if ($coupon_type_info[ 'count' ] != -1 || $is_stock == 0) {
- if ($coupon_type_info[ 'count' ] == $coupon_type_info[ 'lead_count' ]) {
- return $this->error('', '来迟了该优惠券已被领取完了');
- }
- }
- if ($coupon_type_info[ 'max_fetch' ] != 0 && $get_type == 2) {
- //限制领取
- $member_receive_num = model('promotion_coupon')->getCount([
- 'coupon_type_id' => $coupon_type_id,
- 'member_id' => $member_id,
- 'get_type' => 2
- ]);
- if ($member_receive_num >= $coupon_type_info[ 'max_fetch' ] && $is_limit == 1) {
- return $this->error('', '该优惠券领取已达到上限');
- }
- }
-
- //只有正在进行中的优惠券可以添加或者发送领取)
- if ($coupon_type_info[ 'status' ] != 1) {
- return $this->error('', '该优惠券已过期');
- }
-
- $data = [
- 'coupon_type_id' => $coupon_type_id,
- 'site_id' => $site_id,
- 'coupon_code' => $this->getCode(),
- 'member_id' => $member_id,
- 'money' => $coupon_type_info[ 'money' ],
- 'state' => CouponDict::normal,
- 'get_type' => $get_type,
- 'goods_type' => $coupon_type_info[ 'goods_type' ],
- 'fetch_time' => time(),
- 'coupon_name' => $coupon_type_info[ 'coupon_name' ],
- 'at_least' => $coupon_type_info[ 'at_least' ],
- 'type' => $coupon_type_info[ 'type' ],
- 'discount' => $coupon_type_info[ 'discount' ],
- 'discount_limit' => $coupon_type_info[ 'discount_limit' ],
- 'goods_ids' => $coupon_type_info[ 'goods_ids' ],
- ];
-
- if ($coupon_type_info[ 'validity_type' ] == 0) {
- $data[ 'end_time' ] = $coupon_type_info[ 'end_time' ];
- } elseif ($coupon_type_info[ 'validity_type' ] == 1) {
- $data[ 'end_time' ] = ( time() + $coupon_type_info[ 'fixed_term' ] * 86400 );
- }
- $res = model('promotion_coupon')->add($data);
- if ($is_stock == 0) {
- model('promotion_coupon_type')->setInc([ [ 'coupon_type_id', '=', $coupon_type_id ] ], 'lead_count');
- }
- $stat_model = new Stat();
- $stat_model->switchStat([ 'type' => 'receive_coupon', 'data' => [
- 'site_id' => $site_id,
- 'coupon_id' => $res
- ] ]);
- return $this->success($res);
- } else {
- return $this->error('', '未查找到该优惠券');
- }
- }
-
- /**
- * 批量奖励优惠券(不会统计领券会员数)(不会限制数量)
- * @param $member_data //会员相关数据,防止重复查询
- * @param $coupon_type_list //奖励优惠券活动列表(每种只发送一张)
- */
- public function batchReceiveCoupon($member_data, $coupon_type_list, $get_type)
- {
- $coupon_list = [];
- $lead_count_ids = [];
- foreach ($coupon_type_list as $k => $v) {
- //可发放状态
- if ($v[ 'status' ] == 1) {
- $data = [
- 'coupon_type_id' => $v[ 'coupon_type_id' ],
- 'site_id' => $v[ 'site_id' ],
- 'coupon_code' => $this->getCode(),
- 'member_id' => $member_data[ 'member_id' ],
- 'money' => $v[ 'money' ],
- 'state' => CouponDict::normal,
- 'get_type' => $get_type,
- 'goods_type' => $v[ 'goods_type' ],
- 'fetch_time' => time(),
- 'coupon_name' => $v[ 'coupon_name' ],
- 'at_least' => $v[ 'at_least' ],
- 'type' => $v[ 'type' ],
- 'discount' => $v[ 'discount' ],
- 'discount_limit' => $v[ 'discount_limit' ],
- 'goods_ids' => $v[ 'goods_ids' ],
- ];
- if ($v[ 'validity_type' ] == 0) {
- $data[ 'end_time' ] = $v[ 'end_time' ];
- } elseif ($v[ 'validity_type' ] == 1) {
- $data[ 'end_time' ] = ( time() + $v[ 'fixed_term' ] * 86400 );
- }
- $coupon_list[] = $data;
- $lead_count_ids[] = $v[ 'coupon_type_id' ];
- }
-
- }
- if (!empty($coupon_list)) {
- model('promotion_coupon')->addList($coupon_list);
- $lead_count_ids = implode(',', $lead_count_ids);
- model('promotion_coupon_type')->setInc([ [ 'coupon_type_id', 'in', $lead_count_ids ] ], 'lead_count');
- }
-
- }
-
- /**
- * 发放优惠券
- * @param array $coupon_data [ ['coupon_type_id' => xx, 'num' => xx ] ]
- * @param int $site_id
- * @param int $member_id
- * @param int $get_type
- * @param int $related_id
- * @return array
- */
- public function giveCoupon(array $coupon_data, int $site_id, int $member_id, $get_type = 4, $related_id = 0, $is_limit = 1, $is_stock = 1)
- {
- if (empty($member_id)) return $this->error('', '请先选择会员');
-
- try {
- $coupon_list = [];
- $coupon_count = count($coupon_data);
- foreach ($coupon_data as $item) {
- $coupon_type_info = model('promotion_coupon_type')->getInfo([
- [ 'coupon_type_id', '=', $item[ 'coupon_type_id' ] ],
- [ 'site_id', '=', $site_id ],
- [ 'status', '=', 1 ]
- ]);
- if (empty($coupon_type_info)) {
- continue;
- }
-
- if ($coupon_type_info[ 'count' ] != -1 && $coupon_type_info[ 'is_show' ] == 1) {
- if ($is_stock && $coupon_type_info[ 'count' ] == $coupon_type_info[ 'lead_count' ]) {
- if ($coupon_count == 1) {
- return $this->error('', '来迟了该优惠券已被领取完了');
- } else {
- continue;
- }
- }
- }
-
- if ($coupon_type_info[ 'max_fetch' ] != 0 && $get_type == 2) {
- //限制领取
- if ($is_limit) {
- $member_receive_num = model('promotion_coupon')->getCount([
- 'coupon_type_id' => $item[ 'coupon_type_id' ],
- 'member_id' => $member_id,
- 'get_type' => 2
- ]);
- if ($member_receive_num >= $coupon_type_info[ 'max_fetch' ]) {
- if ($coupon_count == 1) {
- return $this->error('', '[' . $coupon_type_info[ 'coupon_name' ] . '] 优惠券领取已达到上限');
- } else {
- continue;
- }
- }
- }
- }
-
- $data = [
- 'coupon_type_id' => $item[ 'coupon_type_id' ],
- 'site_id' => $site_id,
- 'coupon_code' => $this->getCode(),
- 'member_id' => $member_id,
- 'money' => $coupon_type_info[ 'money' ],
- 'state' => CouponDict::normal,
- 'get_type' => $get_type,
- 'goods_type' => $coupon_type_info[ 'goods_type' ],
- 'fetch_time' => time(),
- 'coupon_name' => $coupon_type_info[ 'coupon_name' ],
- 'at_least' => $coupon_type_info[ 'at_least' ],
- 'type' => $coupon_type_info[ 'type' ],
- 'discount' => $coupon_type_info[ 'discount' ],
- 'discount_limit' => $coupon_type_info[ 'discount_limit' ],
- 'goods_ids' => $coupon_type_info[ 'goods_ids' ],
- 'related_id' => $related_id,
- 'end_time' => 0
- ];
- if ($coupon_type_info[ 'validity_type' ] == 0) {
- $data[ 'end_time' ] = $coupon_type_info[ 'end_time' ];
- } elseif ($coupon_type_info[ 'validity_type' ] == 1) {
- $data[ 'end_time' ] = ( time() + $coupon_type_info[ 'fixed_term' ] * 86400 );
- }
- for ($i = 0; $i < $item[ 'num' ]; $i++) {
- $data[ 'coupon_code' ] = $this->getCode();
- $coupon_list[] = $data;
- }
- model('promotion_coupon_type')->setInc([ [ 'coupon_type_id', '=', $item[ 'coupon_type_id' ] ] ], 'lead_count', $item[ 'num' ]);
- }
-
- if (empty($coupon_list)) return $this->error('', '没有可发放的优惠券');
-
- $res = model('promotion_coupon')->addList($coupon_list);
- return $this->success($res);
- } catch (\Exception $e) {
- return $this->error('', '发放失败');
- }
- }
-
- /**
- * 使用优惠券
- * @param $coupon_id
- * @param $member_id
- * @param $use_order_id
- * @return array
- */
- public function useCoupon($coupon_id, $member_id, $use_order_id)
- {
- $data = [ 'use_order_id' => $use_order_id, 'use_time' => time(), 'state' => CouponDict::used ];
- $condition = [
- [ 'coupon_id', '=', $coupon_id ],
- [ 'member_id', '=', $member_id ],
- [ 'state', '=', CouponDict::normal ]
- ];
- $result = model('promotion_coupon')->update($data, $condition);
- return $this->success($result);
- }
-
- /**
- * 退还优惠券
- * @param $coupon_id
- * @param $member_id
- * @return array
- */
- public function refundCoupon($coupon_id, $member_id)
- {
- //获取优惠券信息
- $condition = [
- [ 'pc.coupon_id', '=', $coupon_id ],
- [ 'pc.member_id', '=', $member_id ],
- [ 'pc.state', '=', CouponDict::used ]
- ];
-
- $field = 'pct.validity_type,pc.end_time';
- $alias = 'pc';
- $join = [
- [ 'promotion_coupon_type pct', 'pc.coupon_type_id = pct.coupon_type_id', 'left' ]
- ];
- $info = model('promotion_coupon')->getInfo($condition, $field, $alias, $join);
- if (empty($info)) {
- return $this->success();
- }
-
- $data = [ 'use_time' => 0, 'state' => CouponDict::normal ];
-
- // 判断优惠券是否过期,有效期类型:0:固定时间,1:领取之日起x天有效,2:长期有效
- if ($info[ 'validity_type' ] == 0) {
- // 固定时间
- if ($info[ 'end_time' ] <= time()) {
- $data[ 'state' ] = CouponDict::expire;
- }
- }
-
- $result = model('promotion_coupon')->update($data, [ [ 'coupon_id', '=', $coupon_id ], [ 'member_id', '=', $member_id ], [ 'state', '=', CouponDict::used ] ]);
- return $this->success($result);
- }
-
- /**
- * 获取优惠券信息
- * @param $condition $coupon_code 优惠券编码
- * @param $field
- * @return array
- */
- public function getCouponInfo($condition, $field)
- {
- $info = model('promotion_coupon')->getInfo($condition, $field);
- return $this->success($info);
- }
-
- /**
- * 获取优惠券数量
- * @param $condition $coupon_code 优惠券编码
- * @return array
- */
- public function getCouponCount($condition)
- {
- $info = model('promotion_coupon')->getCount($condition);
- return $this->success($info);
- }
-
- /**
- * 获取优惠券列表
- * @param array $condition
- * @param bool $field
- * @param string $order
- * @param null $limit
- * @return array
- */
- public function getCouponList($condition = [], $field = true, $order = '', $limit = null)
- {
- $list = model('promotion_coupon')->getList($condition, $field, $order, '', '', '', $limit);
- return $this->success($list);
- }
-
- /**
- * 获取优惠券列表
- * @param array $condition
- * @param int $page
- * @param int $page_size
- * @param string $order
- * @param string $field
- * @param string $alias
- * @param array $join
- * @return array
- */
- public function getCouponPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'fetch_time desc', $field = 'coupon_id,type,discount,coupon_type_id,coupon_name,site_id,coupon_code,member_id,use_order_id,at_least,money,state,get_type,fetch_time,use_time,end_time', $alias = 'a', $join = [])
- {
- $list = model('promotion_coupon')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
- return $this->success($list);
- }
-
- /**
- * 获取会员优惠券列表
- * @param $condition
- * @param int $page
- * @param int $page_size
- * @return array
- */
- public function getMemberCouponPageList($condition, $page = 1, $page_size = PAGE_LIST_ROWS)
- {
- $field = 'npc.coupon_name,npc.type,npc.use_order_id,npc.coupon_id,npc.coupon_type_id,npc.site_id,npc.coupon_code,npc.member_id,npc.discount_limit,
- npc.at_least,npc.money,npc.discount,npc.state,npc.get_type,npc.fetch_time,npc.use_time,npc.end_time,mem.nickname,on.order_no,npc.end_time,mem.nickname,mem.headimg,mem.mobile';
- $alias = 'npc';
- $join = [
- [
- 'member mem',
- 'npc.member_id = mem.member_id',
- 'inner'
- ],
- [
- 'order on',
- 'npc.use_order_id = on.order_id',
- 'left'
- ]
- ];
- $list = model('promotion_coupon')->pageList($condition, $field, 'fetch_time desc', $page, $page_size, $alias, $join);
- return $this->success($list);
- }
-
- /**
- * 获取优惠券信息
- * @param $condition
- * @param string $field
- * @return array
- */
- public function getCouponTypeInfo($condition, $field = 'coupon_type_id,site_id,coupon_name,money,count,lead_count,max_fetch,at_least,end_time,image,validity_type,fixed_term,status,type,discount')
- {
- $info = model('promotion_coupon_type')->getInfo($condition, $field);
- return $this->success($info);
- }
-
- /**
- * 获取优惠券列表
- * @param array $condition
- * @param bool $field
- * @param string $order
- * @param null $limit
- * @return array
- */
- public function getCouponTypeList($condition = [], $field = true, $order = '', $limit = null, $alias = '', $join = [])
- {
- $list = model('promotion_coupon_type')->getList($condition, $field, $order, $alias, $join, '', $limit);
- return $this->success($list);
- }
-
- /**
- * 获取优惠券分页列表
- * @param $condition
- * @param int $page
- * @param int $page_size
- * @param string $order
- * @param string $field
- * @return array
- */
- public function getCouponTypePageList($condition, $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'coupon_type_id desc', $field = '*', $alias = '', $join = [])
- {
- $list = model('promotion_coupon_type')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
- return $this->success($list);
- }
-
- /**
- * 获取会员已领取优惠券
- * @param $member_id
- * @param $state
- * @param int $site_id
- * @param int $money
- * @param string $order
- * @return array
- */
- public function getMemberCouponList($member_id, $state, $site_id = 0, $money = 0, $order = 'fetch_time desc')
- {
- $condition = array (
- [ 'member_id', '=', $member_id ],
- [ 'state', '=', $state ],
-// [ "end_time", ">", time()]
- );
- if ($site_id > 0) {
- $condition[] = [ 'site_id', '=', $site_id ];
- }
- if ($money > 0) {
-// $condition[] = [ "at_least", "=", 0 ];
- $condition[] = [ 'at_least', '<=', $money ];
- }
- $list = model('promotion_coupon')->getList($condition, '*', $order, '', '', '', 0);
- return $this->success($list);
- }
-
- public function getMemberCouponCount($condition)
- {
- $list = model('promotion_coupon')->getCount($condition);
- return $this->success($list);
- }
-
- /**
- * 增加库存
- * @param $param
- * @return array
- */
- public function incStock($param)
- {
- $condition = array (
- [ 'coupon_type_id', '=', $param[ 'coupon_type_id' ] ]
- );
- $num = $param[ 'num' ];
- $coupon_info = model('promotion_coupon_type')->getInfo($condition, 'count,lead_count');
- if (empty($coupon_info))
- return $this->error(-1, '');
-
- //更新优惠券库存
- $result = model('promotion_coupon_type')->setDec($condition, 'lead_count', $num);
- return $this->success($result);
- }
-
- /**
- * 减少库存
- * @param $param
- * @return array
- */
- public function decStock($param)
- {
- $condition = array (
- [ 'coupon_type_id', '=', $param[ 'coupon_type_id' ] ]
- );
- $num = $param[ 'num' ];
- $coupon_info = model('promotion_coupon_type')->getInfo($condition, 'count,lead_count');
- if (empty($coupon_info))
- return $this->error(-1, '找不到优惠券!');
-
- //编辑sku库存
- if ($coupon_info[ 'count' ] != -1) {
- if (( $coupon_info[ 'count' ] - $coupon_info[ 'lead_count' ] ) < $num)
- return $this->error(-1, '优惠券库存不足!');
- }
-
- $result = model('promotion_coupon_type')->setInc($condition, 'lead_count', $num);
- if ($result === false)
- return $this->error();
-
- return $this->success($result);
- }
-
- /**
- * 定时关闭
- * @return mixed
- */
- public function cronCouponEnd()
- {
- $res = model('promotion_coupon')->update([ 'state' => CouponDict::expire ], [ [ 'state', '=', CouponDict::normal ], [ 'end_time', '>', 0 ], [ 'end_time', '<=', time() ] ]);
- return $res;
- }
-
- /**
- * 核验会员是否还可以领用某一张优惠券
- * @param $params
- * @return array
- */
- public function checkMemberReceiveCoupon($params)
- {
- $member_id = $params[ 'member_id' ];//会员id
- $coupon_type_info = $params[ 'coupon_type_info' ];
- $site_id = $params[ 'site_id' ];
- $coupon_type_id = $params[ 'coupon_type_id' ] ?? 0;
- if ($coupon_type_id > 0) {
- $coupon_type_info = model('promotion_coupon_type')->getInfo([ 'coupon_type_id' => $coupon_type_id, 'site_id' => $site_id ]);
- }
- if (!empty($coupon_type_info)) {
- $coupon_type_id = $coupon_type_info[ 'coupon_type_id' ] ?? 0;
- if ($coupon_type_info[ 'count' ] != -1 && $coupon_type_info[ 'is_show' ] == 1) {
- if ($coupon_type_info[ 'count' ] == $coupon_type_info[ 'lead_count' ]) {
- return $this->error('', '来迟了该优惠券已被领取完了!');
- }
- }
- if ($coupon_type_info[ 'max_fetch' ] != 0) {
- //限制领取
- $member_receive_num = model('promotion_coupon')->getCount([
- 'coupon_type_id' => $coupon_type_id,
- 'member_id' => $member_id,
- 'get_type' => 2
- ]);
- if ($member_receive_num >= $coupon_type_info[ 'max_fetch' ]) {
- return $this->error('', '该优惠券领取已达到上限!');
- }
- }
- //只有正在进行中的优惠券可以添加或者发送领取)
- if ($coupon_type_info[ 'status' ] != 1) {
- return $this->error('', '该优惠券已过期!');
- }
- }
- return $this->success();
- }
-
- /**
- * 获取商品可领用优惠券
- * @param $goods_sku_detail_array
- * @param $member_id
- * @param $site_id
- */
- public function getGoodsCanReceiveCouponInApi($goods_sku_detail_array, $member_id, $site_id)
- {
- $goods_sku_detail = $goods_sku_detail_array[ 'goods_sku_detail' ];
- $condition = [
- [ 'site_id', '=', $site_id ],
- [ 'status', '=', 1 ],
- [ 'is_show', '=', 1 ],
- ];
- //查询正在进行的优惠券活动
- $field = 'count,lead_count,coupon_type_id,coupon_type_id as type_id,type,site_id,coupon_name,money,discount,max_fetch,at_least,end_time,validity_type,fixed_term,goods_type,discount_limit,goods_ids';
- $coupon_type_list = model('promotion_coupon_type')->getList($condition, $field);
- //查询会员领用的优惠券数量
- if ($member_id != 0) {
- $member_coupon_num = model('promotion_coupon')->getList([ [ 'member_id', '=', $member_id ] ], 'coupon_type_id,count(coupon_type_id) as member_coupon_num', 'money desc', 'a', [], 'coupon_type_id');
- if (!empty($member_coupon_num)) {
- $key = array_column($member_coupon_num, 'coupon_type_id');
- $member_coupon_num = array_combine($key, $member_coupon_num);
- } else {
- $member_coupon_num = [];
- }
-
- }
-
- foreach ($coupon_type_list as $k => $v) {
- if ($v[ 'goods_type' ] == 2) {
- //部分商品可用
- $goods_id_array = explode(',', $v[ 'goods_ids' ]);
- if (!in_array($goods_sku_detail[ 'goods_id' ], $goods_id_array)) {
- unset($coupon_type_list[ $k ]);
- continue;
- }
- }
- if ($v[ 'goods_type' ] == 3) {
- //部分商品不可用
- $goods_id_array = explode(',', $v[ 'goods_ids' ]);
- if (in_array($goods_sku_detail[ 'goods_id' ], $goods_id_array)) {
- unset($coupon_type_list[ $k ]);
- continue;
- }
- }
- if ($member_id != 0) {
- $coupon_rec_num = $member_coupon_num[ 'coupon_type_id' ][ 'member_coupon_num' ] ?? 0;
- //控制领用数量
- if ($v[ 'count' ] == $v[ 'lead_count' ]) {
- unset($coupon_type_list[ $k ]);
- } elseif ($v[ 'max_fetch' ] != 0 && $coupon_rec_num >= $v[ 'max_fetch' ]) {
- // 已领取
- unset($coupon_type_list[ $k ]);
- }
- }
- }
- $goods_sku_detail_array[ 'goods_sku_detail' ][ 'coupon_list' ] = $coupon_type_list;
- return $goods_sku_detail_array;
- }
+ '消费奖励',
+ 2 => '直接领取',
+ 3 => '会员升级奖励',
+ 4 => '商家发放',
+ 6 => '活动奖励'
+ ];
+ $event = event('CouponGetType');
+ if (!empty($event)) {
+ foreach ($event as $k => $v) {
+ $get_type[ array_keys($v)[ 0 ] ] = array_values($v)[ 0 ];
+ }
+ }
+ if ($type) return $get_type[ $type ] ?? '';
+ else return $get_type;
+ }
+
+ /**
+ * 获取编码
+ */
+ public function getCode()
+ {
+ return random_keys(8);
+ }
+
+ /**
+ * 领取优惠券
+ * @param $coupon_type_id
+ * @param $site_id
+ * @param $member_id
+ * @param $get_type
+ * @param int $is_stock
+ * @param int $is_limit
+ * @return array
+ */
+ public function receiveCoupon($coupon_type_id, $site_id, $member_id, $get_type, $is_stock = 0, $is_limit = 1)
+ {
+ // 用户已领取数量
+ if (empty($member_id)) {
+ return $this->error('', '请先进行登录');
+ }
+ $coupon_type_info = model('promotion_coupon_type')->getInfo([ 'coupon_type_id' => $coupon_type_id, 'site_id' => $site_id ]);
+ if (!empty($coupon_type_info)) {
+ if ($coupon_type_info[ 'count' ] != -1 || $is_stock == 0) {
+ if ($coupon_type_info[ 'count' ] == $coupon_type_info[ 'lead_count' ]) {
+ return $this->error('', '来迟了该优惠券已被领取完了');
+ }
+ }
+ if ($coupon_type_info[ 'max_fetch' ] != 0 && $get_type == 2) {
+ //限制领取
+ $member_receive_num = model('promotion_coupon')->getCount([
+ 'coupon_type_id' => $coupon_type_id,
+ 'member_id' => $member_id,
+ 'get_type' => 2
+ ]);
+ if ($member_receive_num >= $coupon_type_info[ 'max_fetch' ] && $is_limit == 1) {
+ return $this->error('', '该优惠券领取已达到上限');
+ }
+ }
+
+ //只有正在进行中的优惠券可以添加或者发送领取)
+ if ($coupon_type_info[ 'status' ] != 1) {
+ return $this->error('', '该优惠券已过期');
+ }
+
+ $data = [
+ 'coupon_type_id' => $coupon_type_id,
+ 'site_id' => $site_id,
+ 'coupon_code' => $this->getCode(),
+ 'member_id' => $member_id,
+ 'money' => $coupon_type_info[ 'money' ],
+ 'state' => CouponDict::normal,
+ 'get_type' => $get_type,
+ 'goods_type' => $coupon_type_info[ 'goods_type' ],
+ 'fetch_time' => time(),
+ 'coupon_name' => $coupon_type_info[ 'coupon_name' ],
+ 'at_least' => $coupon_type_info[ 'at_least' ],
+ 'type' => $coupon_type_info[ 'type' ],
+ 'discount' => $coupon_type_info[ 'discount' ],
+ 'discount_limit' => $coupon_type_info[ 'discount_limit' ],
+ 'goods_ids' => $coupon_type_info[ 'goods_ids' ],
+ ];
+
+ if ($coupon_type_info[ 'validity_type' ] == 0) {
+ $data[ 'end_time' ] = $coupon_type_info[ 'end_time' ];
+ } elseif ($coupon_type_info[ 'validity_type' ] == 1) {
+ $data[ 'end_time' ] = ( time() + $coupon_type_info[ 'fixed_term' ] * 86400 );
+ }
+ $res = model('promotion_coupon')->add($data);
+ if ($is_stock == 0) {
+ model('promotion_coupon_type')->setInc([ [ 'coupon_type_id', '=', $coupon_type_id ] ], 'lead_count');
+ }
+ $stat_model = new Stat();
+ $stat_model->switchStat([ 'type' => 'receive_coupon', 'data' => [
+ 'site_id' => $site_id,
+ 'coupon_id' => $res
+ ] ]);
+ return $this->success($res);
+ } else {
+ return $this->error('', '未查找到该优惠券');
+ }
+ }
+
+ /**
+ * 批量奖励优惠券(不会统计领券会员数)(不会限制数量)
+ * @param $member_data //会员相关数据,防止重复查询
+ * @param $coupon_type_list //奖励优惠券活动列表(每种只发送一张)
+ */
+ public function batchReceiveCoupon($member_data, $coupon_type_list, $get_type)
+ {
+ $coupon_list = [];
+ $lead_count_ids = [];
+ foreach ($coupon_type_list as $k => $v) {
+ //可发放状态
+ if ($v[ 'status' ] == 1) {
+ $data = [
+ 'coupon_type_id' => $v[ 'coupon_type_id' ],
+ 'site_id' => $v[ 'site_id' ],
+ 'coupon_code' => $this->getCode(),
+ 'member_id' => $member_data[ 'member_id' ],
+ 'money' => $v[ 'money' ],
+ 'state' => CouponDict::normal,
+ 'get_type' => $get_type,
+ 'goods_type' => $v[ 'goods_type' ],
+ 'fetch_time' => time(),
+ 'coupon_name' => $v[ 'coupon_name' ],
+ 'at_least' => $v[ 'at_least' ],
+ 'type' => $v[ 'type' ],
+ 'discount' => $v[ 'discount' ],
+ 'discount_limit' => $v[ 'discount_limit' ],
+ 'goods_ids' => $v[ 'goods_ids' ],
+ ];
+ if ($v[ 'validity_type' ] == 0) {
+ $data[ 'end_time' ] = $v[ 'end_time' ];
+ } elseif ($v[ 'validity_type' ] == 1) {
+ $data[ 'end_time' ] = ( time() + $v[ 'fixed_term' ] * 86400 );
+ }
+ $coupon_list[] = $data;
+ $lead_count_ids[] = $v[ 'coupon_type_id' ];
+ }
+
+ }
+ if (!empty($coupon_list)) {
+ model('promotion_coupon')->addList($coupon_list);
+ $lead_count_ids = implode(',', $lead_count_ids);
+ model('promotion_coupon_type')->setInc([ [ 'coupon_type_id', 'in', $lead_count_ids ] ], 'lead_count');
+ }
+
+ }
+
+ /**
+ * 发放优惠券
+ * @param array $coupon_data [ ['coupon_type_id' => xx, 'num' => xx ] ]
+ * @param int $site_id
+ * @param int $member_id
+ * @param int $get_type
+ * @param int $related_id
+ * @return array
+ */
+ public function giveCoupon(array $coupon_data, int $site_id, int $member_id, $get_type = 4, $related_id = 0, $is_limit = 1, $is_stock = 1)
+ {
+ if (empty($member_id)) return $this->error('', '请先选择会员');
+
+ try {
+ $coupon_list = [];
+ $coupon_count = count($coupon_data);
+ foreach ($coupon_data as $item) {
+ $coupon_type_info = model('promotion_coupon_type')->getInfo([
+ [ 'coupon_type_id', '=', $item[ 'coupon_type_id' ] ],
+ [ 'site_id', '=', $site_id ],
+ [ 'status', '=', 1 ]
+ ]);
+ if (empty($coupon_type_info)) {
+ continue;
+ }
+
+ if ($coupon_type_info[ 'count' ] != -1 && $coupon_type_info[ 'is_show' ] == 1) {
+ if ($is_stock && $coupon_type_info[ 'count' ] == $coupon_type_info[ 'lead_count' ]) {
+ if ($coupon_count == 1) {
+ return $this->error('', '来迟了该优惠券已被领取完了');
+ } else {
+ continue;
+ }
+ }
+ }
+
+ if ($coupon_type_info[ 'max_fetch' ] != 0 && $get_type == 2) {
+ //限制领取
+ if ($is_limit) {
+ $member_receive_num = model('promotion_coupon')->getCount([
+ 'coupon_type_id' => $item[ 'coupon_type_id' ],
+ 'member_id' => $member_id,
+ 'get_type' => 2
+ ]);
+ if ($member_receive_num >= $coupon_type_info[ 'max_fetch' ]) {
+ if ($coupon_count == 1) {
+ return $this->error('', '[' . $coupon_type_info[ 'coupon_name' ] . '] 优惠券领取已达到上限');
+ } else {
+ continue;
+ }
+ }
+ }
+ }
+
+ $data = [
+ 'coupon_type_id' => $item[ 'coupon_type_id' ],
+ 'site_id' => $site_id,
+ 'coupon_code' => $this->getCode(),
+ 'member_id' => $member_id,
+ 'money' => $coupon_type_info[ 'money' ],
+ 'state' => CouponDict::normal,
+ 'get_type' => $get_type,
+ 'goods_type' => $coupon_type_info[ 'goods_type' ],
+ 'fetch_time' => time(),
+ 'coupon_name' => $coupon_type_info[ 'coupon_name' ],
+ 'at_least' => $coupon_type_info[ 'at_least' ],
+ 'type' => $coupon_type_info[ 'type' ],
+ 'discount' => $coupon_type_info[ 'discount' ],
+ 'discount_limit' => $coupon_type_info[ 'discount_limit' ],
+ 'goods_ids' => $coupon_type_info[ 'goods_ids' ],
+ 'related_id' => $related_id,
+ 'end_time' => 0
+ ];
+ if ($coupon_type_info[ 'validity_type' ] == 0) {
+ $data[ 'end_time' ] = $coupon_type_info[ 'end_time' ];
+ } elseif ($coupon_type_info[ 'validity_type' ] == 1) {
+ $data[ 'end_time' ] = ( time() + $coupon_type_info[ 'fixed_term' ] * 86400 );
+ }
+ for ($i = 0; $i < $item[ 'num' ]; $i++) {
+ $data[ 'coupon_code' ] = $this->getCode();
+ $coupon_list[] = $data;
+ }
+ model('promotion_coupon_type')->setInc([ [ 'coupon_type_id', '=', $item[ 'coupon_type_id' ] ] ], 'lead_count', $item[ 'num' ]);
+ }
+
+ if (empty($coupon_list)) return $this->error('', '没有可发放的优惠券');
+
+ $res = model('promotion_coupon')->addList($coupon_list);
+ return $this->success($res);
+ } catch (\Exception $e) {
+ return $this->error('', '发放失败');
+ }
+ }
+
+ /**
+ * 使用优惠券
+ * @param $coupon_id
+ * @param $member_id
+ * @param $use_order_id
+ * @return array
+ */
+ public function useCoupon($coupon_id, $member_id, $use_order_id)
+ {
+ $data = [ 'use_order_id' => $use_order_id, 'use_time' => time(), 'state' => CouponDict::used ];
+ $condition = [
+ [ 'coupon_id', '=', $coupon_id ],
+ [ 'member_id', '=', $member_id ],
+ [ 'state', '=', CouponDict::normal ]
+ ];
+ $result = model('promotion_coupon')->update($data, $condition);
+ return $this->success($result);
+ }
+
+ /**
+ * 退还优惠券
+ * @param $coupon_id
+ * @param $member_id
+ * @return array
+ */
+ public function refundCoupon($coupon_id, $member_id)
+ {
+ //获取优惠券信息
+ $condition = [
+ [ 'pc.coupon_id', '=', $coupon_id ],
+ [ 'pc.member_id', '=', $member_id ],
+ [ 'pc.state', '=', CouponDict::used ]
+ ];
+
+ $field = 'pct.validity_type,pc.end_time';
+ $alias = 'pc';
+ $join = [
+ [ 'promotion_coupon_type pct', 'pc.coupon_type_id = pct.coupon_type_id', 'left' ]
+ ];
+ $info = model('promotion_coupon')->getInfo($condition, $field, $alias, $join);
+ if (empty($info)) {
+ return $this->success();
+ }
+
+ $data = [ 'use_time' => 0, 'state' => CouponDict::normal ];
+
+ // 判断优惠券是否过期,有效期类型:0:固定时间,1:领取之日起x天有效,2:长期有效
+ if ($info[ 'validity_type' ] == 0) {
+ // 固定时间
+ if ($info[ 'end_time' ] <= time()) {
+ $data[ 'state' ] = CouponDict::expire;
+ }
+ }
+
+ $result = model('promotion_coupon')->update($data, [ [ 'coupon_id', '=', $coupon_id ], [ 'member_id', '=', $member_id ], [ 'state', '=', CouponDict::used ] ]);
+ return $this->success($result);
+ }
+
+ /**
+ * 获取优惠券信息
+ * @param $condition $coupon_code 优惠券编码
+ * @param $field
+ * @return array
+ */
+ public function getCouponInfo($condition, $field)
+ {
+ $info = model('promotion_coupon')->getInfo($condition, $field);
+ return $this->success($info);
+ }
+
+ /**
+ * 获取优惠券数量
+ * @param $condition $coupon_code 优惠券编码
+ * @return array
+ */
+ public function getCouponCount($condition)
+ {
+ $info = model('promotion_coupon')->getCount($condition);
+ return $this->success($info);
+ }
+
+ /**
+ * 获取优惠券列表
+ * @param array $condition
+ * @param bool $field
+ * @param string $order
+ * @param null $limit
+ * @return array
+ */
+ public function getCouponList($condition = [], $field = true, $order = '', $limit = null)
+ {
+ $list = model('promotion_coupon')->getList($condition, $field, $order, '', '', '', $limit);
+ return $this->success($list);
+ }
+
+ /**
+ * 获取优惠券列表
+ * @param array $condition
+ * @param int $page
+ * @param int $page_size
+ * @param string $order
+ * @param string $field
+ * @param string $alias
+ * @param array $join
+ * @return array
+ */
+ public function getCouponPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'fetch_time desc', $field = 'coupon_id,type,discount,coupon_type_id,coupon_name,site_id,coupon_code,member_id,use_order_id,at_least,money,state,get_type,fetch_time,use_time,end_time', $alias = 'a', $join = [])
+ {
+ $list = model('promotion_coupon')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
+ return $this->success($list);
+ }
+
+ /**
+ * 获取会员优惠券列表
+ * @param $condition
+ * @param int $page
+ * @param int $page_size
+ * @return array
+ */
+ public function getMemberCouponPageList($condition, $page = 1, $page_size = PAGE_LIST_ROWS)
+ {
+ $field = 'npc.coupon_name,npc.type,npc.use_order_id,npc.coupon_id,npc.coupon_type_id,npc.site_id,npc.coupon_code,npc.member_id,npc.discount_limit,
+ npc.at_least,npc.money,npc.discount,npc.state,npc.get_type,npc.fetch_time,npc.use_time,npc.end_time,mem.nickname,on.order_no,npc.end_time,mem.nickname,mem.headimg,mem.mobile';
+ $alias = 'npc';
+ $join = [
+ [
+ 'member mem',
+ 'npc.member_id = mem.member_id',
+ 'inner'
+ ],
+ [
+ 'order on',
+ 'npc.use_order_id = on.order_id',
+ 'left'
+ ]
+ ];
+ $list = model('promotion_coupon')->pageList($condition, $field, 'fetch_time desc', $page, $page_size, $alias, $join);
+ return $this->success($list);
+ }
+
+ /**
+ * 获取优惠券信息
+ * @param $condition
+ * @param string $field
+ * @return array
+ */
+ public function getCouponTypeInfo($condition, $field = 'coupon_type_id,site_id,coupon_name,money,count,lead_count,max_fetch,at_least,end_time,image,validity_type,fixed_term,status,type,discount')
+ {
+ $info = model('promotion_coupon_type')->getInfo($condition, $field);
+ return $this->success($info);
+ }
+
+ /**
+ * 获取优惠券列表
+ * @param array $condition
+ * @param bool $field
+ * @param string $order
+ * @param null $limit
+ * @return array
+ */
+ public function getCouponTypeList($condition = [], $field = true, $order = '', $limit = null, $alias = '', $join = [])
+ {
+ $list = model('promotion_coupon_type')->getList($condition, $field, $order, $alias, $join, '', $limit);
+ return $this->success($list);
+ }
+
+ /**
+ * 获取优惠券分页列表
+ * @param $condition
+ * @param int $page
+ * @param int $page_size
+ * @param string $order
+ * @param string $field
+ * @return array
+ */
+ public function getCouponTypePageList($condition, $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'coupon_type_id desc', $field = '*', $alias = '', $join = [])
+ {
+ $list = model('promotion_coupon_type')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
+ return $this->success($list);
+ }
+
+ /**
+ * 获取会员已领取优惠券
+ * @param $member_id
+ * @param $state
+ * @param int $site_id
+ * @param int $money
+ * @param string $order
+ * @return array
+ */
+ public function getMemberCouponList($member_id, $state, $site_id = 0, $money = 0, $order = 'fetch_time desc')
+ {
+ $condition = array (
+ [ 'member_id', '=', $member_id ],
+ [ 'state', '=', $state ],
+// [ "end_time", ">", time()]
+ );
+ if ($site_id > 0) {
+ $condition[] = [ 'site_id', '=', $site_id ];
+ }
+ if ($money > 0) {
+// $condition[] = [ "at_least", "=", 0 ];
+ $condition[] = [ 'at_least', '<=', $money ];
+ }
+ $list = model('promotion_coupon')->getList($condition, '*', $order, '', '', '', 0);
+ return $this->success($list);
+ }
+
+ public function getMemberCouponCount($condition)
+ {
+ $list = model('promotion_coupon')->getCount($condition);
+ return $this->success($list);
+ }
+
+ /**
+ * 增加库存
+ * @param $param
+ * @return array
+ */
+ public function incStock($param)
+ {
+ $condition = array (
+ [ 'coupon_type_id', '=', $param[ 'coupon_type_id' ] ]
+ );
+ $num = $param[ 'num' ];
+ $coupon_info = model('promotion_coupon_type')->getInfo($condition, 'count,lead_count');
+ if (empty($coupon_info))
+ return $this->error(-1, '');
+
+ //更新优惠券库存
+ $result = model('promotion_coupon_type')->setDec($condition, 'lead_count', $num);
+ return $this->success($result);
+ }
+
+ /**
+ * 减少库存
+ * @param $param
+ * @return array
+ */
+ public function decStock($param)
+ {
+ $condition = array (
+ [ 'coupon_type_id', '=', $param[ 'coupon_type_id' ] ]
+ );
+ $num = $param[ 'num' ];
+ $coupon_info = model('promotion_coupon_type')->getInfo($condition, 'count,lead_count');
+ if (empty($coupon_info))
+ return $this->error(-1, '找不到优惠券!');
+
+ //编辑sku库存
+ if ($coupon_info[ 'count' ] != -1) {
+ if (( $coupon_info[ 'count' ] - $coupon_info[ 'lead_count' ] ) < $num)
+ return $this->error(-1, '优惠券库存不足!');
+ }
+
+ $result = model('promotion_coupon_type')->setInc($condition, 'lead_count', $num);
+ if ($result === false)
+ return $this->error();
+
+ return $this->success($result);
+ }
+
+ /**
+ * 定时关闭
+ * @return mixed
+ */
+ public function cronCouponEnd()
+ {
+ $res = model('promotion_coupon')->update([ 'state' => CouponDict::expire ], [ [ 'state', '=', CouponDict::normal ], [ 'end_time', '>', 0 ], [ 'end_time', '<=', time() ] ]);
+ return $res;
+ }
+
+ /**
+ * 核验会员是否还可以领用某一张优惠券
+ * @param $params
+ * @return array
+ */
+ public function checkMemberReceiveCoupon($params)
+ {
+ $member_id = $params[ 'member_id' ];//会员id
+ $coupon_type_info = $params[ 'coupon_type_info' ];
+ $site_id = $params[ 'site_id' ];
+ $coupon_type_id = $params[ 'coupon_type_id' ] ?? 0;
+ if ($coupon_type_id > 0) {
+ $coupon_type_info = model('promotion_coupon_type')->getInfo([ 'coupon_type_id' => $coupon_type_id, 'site_id' => $site_id ]);
+ }
+ if (!empty($coupon_type_info)) {
+ $coupon_type_id = $coupon_type_info[ 'coupon_type_id' ] ?? 0;
+ if ($coupon_type_info[ 'count' ] != -1 && $coupon_type_info[ 'is_show' ] == 1) {
+ if ($coupon_type_info[ 'count' ] == $coupon_type_info[ 'lead_count' ]) {
+ return $this->error('', '来迟了该优惠券已被领取完了!');
+ }
+ }
+ if ($coupon_type_info[ 'max_fetch' ] != 0) {
+ //限制领取
+ $member_receive_num = model('promotion_coupon')->getCount([
+ 'coupon_type_id' => $coupon_type_id,
+ 'member_id' => $member_id,
+ 'get_type' => 2
+ ]);
+ if ($member_receive_num >= $coupon_type_info[ 'max_fetch' ]) {
+ return $this->error('', '该优惠券领取已达到上限!');
+ }
+ }
+ //只有正在进行中的优惠券可以添加或者发送领取)
+ if ($coupon_type_info[ 'status' ] != 1) {
+ return $this->error('', '该优惠券已过期!');
+ }
+ }
+ return $this->success();
+ }
+
+ /**
+ * 获取商品可领用优惠券
+ * @param $goods_sku_detail_array
+ * @param $member_id
+ * @param $site_id
+ */
+ public function getGoodsCanReceiveCouponInApi($goods_sku_detail_array, $member_id, $site_id)
+ {
+ $goods_sku_detail = $goods_sku_detail_array[ 'goods_sku_detail' ];
+ $condition = [
+ [ 'site_id', '=', $site_id ],
+ [ 'status', '=', 1 ],
+ [ 'is_show', '=', 1 ],
+ ];
+ //查询正在进行的优惠券活动
+ $field = 'count,lead_count,coupon_type_id,coupon_type_id as type_id,type,site_id,coupon_name,money,discount,max_fetch,at_least,end_time,validity_type,fixed_term,goods_type,discount_limit,goods_ids';
+ $coupon_type_list = model('promotion_coupon_type')->getList($condition, $field);
+ //查询会员领用的优惠券数量
+ if ($member_id != 0) {
+ $member_coupon_num = model('promotion_coupon')->getList([ [ 'member_id', '=', $member_id ] ], 'coupon_type_id,count(coupon_type_id) as member_coupon_num', 'money desc', 'a', [], 'coupon_type_id');
+ if (!empty($member_coupon_num)) {
+ $key = array_column($member_coupon_num, 'coupon_type_id');
+ $member_coupon_num = array_combine($key, $member_coupon_num);
+ } else {
+ $member_coupon_num = [];
+ }
+
+ }
+
+ foreach ($coupon_type_list as $k => $v) {
+ if ($v[ 'goods_type' ] == 2) {
+ //部分商品可用
+ $goods_id_array = explode(',', $v[ 'goods_ids' ]);
+ if (!in_array($goods_sku_detail[ 'goods_id' ], $goods_id_array)) {
+ unset($coupon_type_list[ $k ]);
+ continue;
+ }
+ }
+ if ($v[ 'goods_type' ] == 3) {
+ //部分商品不可用
+ $goods_id_array = explode(',', $v[ 'goods_ids' ]);
+ if (in_array($goods_sku_detail[ 'goods_id' ], $goods_id_array)) {
+ unset($coupon_type_list[ $k ]);
+ continue;
+ }
+ }
+ if ($member_id != 0) {
+ $coupon_rec_num = $member_coupon_num[ 'coupon_type_id' ][ 'member_coupon_num' ] ?? 0;
+ //控制领用数量
+ if ($v[ 'count' ] == $v[ 'lead_count' ]) {
+ unset($coupon_type_list[ $k ]);
+ } elseif ($v[ 'max_fetch' ] != 0 && $coupon_rec_num >= $v[ 'max_fetch' ]) {
+ // 已领取
+ unset($coupon_type_list[ $k ]);
+ }
+ }
+ }
+ $goods_sku_detail_array[ 'goods_sku_detail' ][ 'coupon_list' ] = $coupon_type_list;
+ return $goods_sku_detail_array;
+ }
}
\ No newline at end of file
diff --git a/src/addon/coupon/model/CouponStat.php b/src/addon/coupon/model/CouponStat.php
index 18f600714..e88004878 100644
--- a/src/addon/coupon/model/CouponStat.php
+++ b/src/addon/coupon/model/CouponStat.php
@@ -1,64 +1,56 @@
-getInfo($order_condition);
- if (empty($info))
- return $this->error();
-
- $stat_data = array (
- 'site_id' => $site_id,
- 'coupon_count' => 1
- );
- $member_id = $info[ 'member_id' ];
- //如果是第一笔订单才能累加下单会员数
-
- $time_region = getDayStartAndEndTime();
- $today_start_time = $time_region[ 'start_time' ];
- $today_end_time = $time_region[ 'end_time' ];
- $today_order_condition = array (
- [ 'member_id', '=', $member_id ],
- [ 'fetch_time', 'between', [ $today_start_time, $today_end_time ] ],
- [ 'coupon_id', '<>', $coupon_id ]
- );
- $count = model('promotion_coupon')->getCount($today_order_condition);
- if ($count == 0) {
- $stat_data[ 'coupon_member_count' ] = 1;
- }
-
- //发布统计
- $stat_model = new Stat();
- $result = $stat_model->addShopStat($stat_data);
- return $result;
- }
+getInfo($order_condition);
+ if (empty($info))
+ return $this->error();
+
+ $stat_data = array (
+ 'site_id' => $site_id,
+ 'coupon_count' => 1
+ );
+ $member_id = $info[ 'member_id' ];
+ //如果是第一笔订单才能累加下单会员数
+
+ $time_region = getDayStartAndEndTime();
+ $today_start_time = $time_region[ 'start_time' ];
+ $today_end_time = $time_region[ 'end_time' ];
+ $today_order_condition = array (
+ [ 'member_id', '=', $member_id ],
+ [ 'fetch_time', 'between', [ $today_start_time, $today_end_time ] ],
+ [ 'coupon_id', '<>', $coupon_id ]
+ );
+ $count = model('promotion_coupon')->getCount($today_order_condition);
+ if ($count == 0) {
+ $stat_data[ 'coupon_member_count' ] = 1;
+ }
+
+ //发布统计
+ $stat_model = new Stat();
+ $result = $stat_model->addShopStat($stat_data);
+ return $result;
+ }
}
\ No newline at end of file
diff --git a/src/addon/coupon/model/CouponType.php b/src/addon/coupon/model/CouponType.php
index 3fabc0538..32326e545 100644
--- a/src/addon/coupon/model/CouponType.php
+++ b/src/addon/coupon/model/CouponType.php
@@ -1,336 +1,328 @@
- '进行中',
- 2 => '已结束',
- -1 => '已关闭',
- ];
-
- public function getCouponTypeStatus()
- {
- return $this->coupon_type_status;
- }
-
- /**
- * 添加优惠券活动
- * @param $data
- * @return array
- */
- public function addCouponType($data)
- {
- //只要创建了就是进行中
- $data[ 'status' ] = 1;
- $data[ 'create_time' ] = time();
- //获取商品id
- if ($data[ 'goods_type' ] == 1) {//全部商品参与
- $data[ 'goods_ids' ] = '';
- }
-
- $data[ 'goods_ids' ] = ',' . $data[ 'goods_ids' ] . ',';
- $res = model('promotion_coupon_type')->add($data);
- if ($data[ 'validity_type' ] == 0) {
- $cron = new Cron();
- $cron->addCron(1, 1, '优惠券活动定时结束', 'CronCouponTypeEnd', $data[ 'end_time' ], $res);
- }
-
- $this->qrcode($res, 'all', $data[ 'site_id' ]);
- return $this->success($res);
- }
-
- /**
- * 编辑优惠券活动
- * @param $data
- * @param $coupon_type_id
- * @return array
- */
- public function editCouponType($data, $coupon_type_id)
- {
- $data[ 'update_time' ] = time();
-
- //获取商品id
- if ($data[ 'goods_type' ] == 1) {//全部商品参与
- $data[ 'goods_ids' ] = '';
- }
-
- $coupon_info = model('promotion_coupon_type')->getInfo([ [ 'coupon_type_id', '=', $coupon_type_id ] ]);
- if (!empty($coupon_info[ 'image' ]) && !empty($data[ 'image' ]) && $coupon_info[ 'image' ] != $data[ 'image' ]) {
- $upload_model = new Upload();
- $upload_model->deletePic($coupon_info[ 'image' ], $coupon_info[ 'site_id' ]);
- }
-
- $data[ 'goods_ids' ] = ',' . $data[ 'goods_ids' ] . ',';
- $res = model('promotion_coupon_type')->update($data, [ [ 'coupon_type_id', '=', $coupon_type_id ] ]);
- model('promotion_coupon')->update([ 'goods_ids' => $data[ 'goods_ids' ], 'goods_type' => $data[ 'goods_type' ] ], [ [ 'coupon_type_id', '=', $coupon_type_id ], [ 'state', '=', 1 ] ]);
- $cron = new Cron();
- $cron->deleteCron([ [ 'event', '=', 'CronCouponTypeEnd' ], [ 'relate_id', '=', $coupon_type_id ] ]);
- if ($data[ 'validity_type' ] == 0) {
- $cron->addCron(1, 1, '优惠券活动定时结束', 'CronCouponTypeEnd', $data[ 'end_time' ], $coupon_type_id);
- }
- return $this->success($res);
- }
-
- /**
- * 关闭优惠券
- * @param $coupon_type_id
- * @param $site_id
- * @return array
- */
- public function closeCouponType($coupon_type_id, $site_id)
- {
- $res = model('promotion_coupon_type')->update([ 'status' => -1 ], [ [ 'coupon_type_id', '=', $coupon_type_id ], [ 'site_id', '=', $site_id ] ]);
-// if ($res) {
-// model("promotion_coupon")->update(['state' => 3], [['coupon_type_id', '=', $coupon_type_id], ['site_id', '=', $site_id]]);
-// }
- $cron = new Cron();
- $cron->deleteCron([ [ 'event', '=', 'CronCouponTypeEnd' ], [ 'relate_id', '=', $coupon_type_id ] ]);
- return $this->success($res);
- }
-
- /**
- * 删除优惠券活动
- * @param $coupon_type_id
- * @param $site_id
- * @return array
- */
- public function deleteCouponType($coupon_type_id, $site_id)
- {
- $coupon_info = model('promotion_coupon_type')->getInfo([ [ 'coupon_type_id', '=', $coupon_type_id ] ]);
-
- if ($coupon_info['status'] == 1) return $this->error('', '进行中的优惠卷无法删除,请先关闭');
-
- if (!empty($coupon_info[ 'image' ])) {
- $upload_model = new Upload();
- $upload_model->deletePic($coupon_info[ 'image' ], $coupon_info[ 'site_id' ]);
- }
-
- $res = model('promotion_coupon_type')->delete([ [ 'coupon_type_id', '=', $coupon_type_id ], [ 'site_id', '=', $site_id ] ]);
- if ($res) {
- model('promotion_coupon')->delete([ [ 'coupon_type_id', '=', $coupon_type_id ] ]);
- }
- $cron = new Cron();
- $cron->deleteCron([ [ 'event', '=', 'CronCouponTypeEnd' ], [ 'relate_id', '=', $coupon_type_id ] ]);
-
- return $this->success($res);
- }
-
- /**
- * 获取优惠券活动详情
- * @param $coupon_type_id
- * @param $site_id
- * @return array
- */
- public function getCouponTypeInfo($coupon_type_id, $site_id)
- {
- $res = model('promotion_coupon_type')->getList([ [ 'coupon_type_id', 'in', $coupon_type_id ], [ 'site_id', '=', $site_id ] ]);
- if (!empty($res)) {
- foreach ($res as $k => $v) {
- if ($v[ 'goods_type' ] == 2 || $v[ 'goods_type' ] == 3) {
- $field[ $k ] = 'goods_id,goods_name,FLOOR(goods_stock) as goods_stock,goods_image,price,sort';
- $goods_ids[ $k ] = substr($v[ 'goods_ids' ], '1', '-1');
- $goods_list[ $k ] = model('goods')->getList([ [ 'goods_id', 'in', $goods_ids[ $k ] ] ], $field[ $k ]);
- }
- $res[ $k ][ 'goods_list' ] = $goods_list[$k] ?? [];
- $res[ $k ][ 'goods_list_count' ] = count($res[ $k ][ 'goods_list' ]);
- }
- }
- return $this->success($res);
- }
-
- /**
- * 获取优惠券活动信息
- * @param array $where
- * @param bool $field
- * @param string $alias
- * @param null $join
- * @param null $data
- * @return array
- */
- public function getInfo($where = [], $field = true, $alias = 'a', $join = null, $data = null)
- {
- $res = model('promotion_coupon_type')->getInfo($where, $field, $alias, $join, $data);
- return $this->success($res);
- }
-
- /**
- * 获取优惠券类型列表
- * @param array $condition
- * @param string $field
- * @param string $order
- * @param null $limit
- * @return array
- */
- public function getCouponTypeList($condition = [], $field = '*', $order = 'create_time desc', $limit = null)
- {
- $res = model('promotion_coupon_type')->getList($condition, $field, $order, '', '', '', $limit);
- return $this->success($res);
- }
-
- /**
- * 获取优惠券活动分页列表
- * @param array $condition
- * @param int $page
- * @param int $page_size
- * @param string $order
- * @param string $field
- * @return array
- */
- public function getCouponTypePageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
- {
- $condition[] = [ 'promotion_type', '=', 0 ];
- $list = model('promotion_coupon_type')->pageList($condition, $field, $order, $page, $page_size);
- return $this->success($list);
- }
-
- /**
- * 排序
- * @param $coupon_type_id
- * @param $sort
- * @return array
- */
- public function couponSort($coupon_type_id, $sort)
- {
- $res = model('promotion_coupon_type')->update([ 'sort' => $sort ], [ [ 'coupon_type_id', '=', $coupon_type_id ] ]);
- return $this->success($res);
- }
-
- /**
- * 生成优惠券二维码
- * @param $coupon_type_id
- * @param string $app_type all为全部
- * @param string $type 类型 create创建 get获取
- * @return mixed|array
- */
- public function qrcode($coupon_type_id, $app_type, $site_id, $type = 'create')
- {
- $res = event('Qrcode', [
- 'site_id' => $site_id,
- 'app_type' => $app_type,
- 'type' => $type,
- 'data' => [
- 'coupon_type_id' => $coupon_type_id
- ],
- 'page' => '/pages_tool/goods/coupon_receive',
- 'qrcode_path' => 'upload/qrcode/coupon',
- 'qrcode_name' => 'coupon_type_code_' . $coupon_type_id . '_' . $site_id,
- ], true);
- return $res;
- }
-
- /**
- * 优惠券定时结束
- * @param $coupon_type_id
- * @return array
- */
- public function couponCronEnd($coupon_type_id)
- {
- $res = model('promotion_coupon_type')->update([ 'status' => 2 ], [ [ 'coupon_type_id', '=', $coupon_type_id ] ]);
- return $this->success($res);
- }
-
- public function spread($coupon_type_id, $name, $site_id, $type = 'create')
- {
- $data = [
- 'site_id' => $site_id,
- 'app_type' => 'all', // all为全部
- 'type' => $type, // 类型 create创建 get获取
- 'data' => [
- 'coupon_type_id' => $coupon_type_id
- ],
- 'page' => '/pages_tool/goods/coupon_receive',
- 'qrcode_path' => 'upload/qrcode/coupon',
- 'qrcode_name' => 'coupon_type_code_' . $coupon_type_id . '_' . $site_id,
- ];
- event('Qrcode', $data, true);
- $app_type_list = config('app_type');
- $path = [];
- foreach ($app_type_list as $k => $v) {
- switch ( $k ) {
- case 'h5':
- $wap_domain = getH5Domain();
- $path[ $k ][ 'status' ] = 1;
- $path[ $k ][ 'url' ] = $wap_domain . $data[ 'page' ] . '?coupon_type_id=' . $coupon_type_id;
- $path[ $k ][ 'img' ] = 'upload/qrcode/coupon/coupon_type_code_' . $coupon_type_id . '_' . $site_id . '_' . $k . '.png';
- break;
- case 'weapp' :
- $config = new ConfigModel();
- $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'WEAPP_CONFIG' ] ]);
- if (!empty($res[ 'data' ])) {
- if (empty($res[ 'data' ][ 'value' ][ 'qrcode' ])) {
- $path[ $k ][ 'status' ] = 2;
- $path[ $k ][ 'message' ] = '未配置微信小程序';
- } else {
- $path[ $k ][ 'status' ] = 1;
- $path[ $k ][ 'img' ] = $res[ 'data' ][ 'value' ][ 'qrcode' ];
- }
- } else {
- $path[ $k ][ 'status' ] = 2;
- $path[ $k ][ 'message' ] = '未配置微信小程序';
- }
- break;
-
- case 'wechat' :
- $config = new ConfigModel();
- $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'WECHAT_CONFIG' ] ]);
- if (!empty($res[ 'data' ])) {
- if (empty($res[ 'data' ][ 'value' ][ 'qrcode' ])) {
- $path[ $k ][ 'status' ] = 2;
- $path[ $k ][ 'message' ] = '未配置微信公众号';
- } else {
- $path[ $k ][ 'status' ] = 1;
- $path[ $k ][ 'img' ] = $res[ 'data' ][ 'value' ][ 'qrcode' ];
- }
- } else {
- $path[ $k ][ 'status' ] = 2;
- $path[ $k ][ 'message' ] = '未配置微信公众号';
- }
- break;
- }
-
- }
-
- $return = [
- 'path' => $path,
- 'name' => $name,
- ];
-
- return $this->success($return);
- }
-
- public function urlQrcode($page, $qrcode_param, $promotion_type, $app_type, $site_id)
- {
- $params = [
- 'site_id' => $site_id,
- 'data' => $qrcode_param,
- 'page' => $page,
- 'promotion_type' => $promotion_type,
- 'app_type' => $app_type,
- 'h5_path' => $page . '?coupon_type_id=' . $qrcode_param[ 'coupon_type_id' ],
- 'qrcode_path' => 'upload/qrcode/coupon',
- 'qrcode_name' => 'coupon_type_code_' . $promotion_type . '_' . $qrcode_param[ 'coupon_type_id' ] . '_' . $site_id,
- ];
-
- $solitaire = event('PromotionQrcode', $params, true);
- return $this->success($solitaire);
- }
+ '进行中',
+ 2 => '已结束',
+ -1 => '已关闭',
+ ];
+
+ public function getCouponTypeStatus()
+ {
+ return $this->coupon_type_status;
+ }
+
+ /**
+ * 添加优惠券活动
+ * @param $data
+ * @return array
+ */
+ public function addCouponType($data)
+ {
+ //只要创建了就是进行中
+ $data[ 'status' ] = 1;
+ $data[ 'create_time' ] = time();
+ //获取商品id
+ if ($data[ 'goods_type' ] == 1) {//全部商品参与
+ $data[ 'goods_ids' ] = '';
+ }
+
+ $data[ 'goods_ids' ] = ',' . $data[ 'goods_ids' ] . ',';
+ $res = model('promotion_coupon_type')->add($data);
+ if ($data[ 'validity_type' ] == 0) {
+ $cron = new Cron();
+ $cron->addCron(1, 1, '优惠券活动定时结束', 'CronCouponTypeEnd', $data[ 'end_time' ], $res);
+ }
+
+ $this->qrcode($res, 'all', $data[ 'site_id' ]);
+ return $this->success($res);
+ }
+
+ /**
+ * 编辑优惠券活动
+ * @param $data
+ * @param $coupon_type_id
+ * @return array
+ */
+ public function editCouponType($data, $coupon_type_id)
+ {
+ $data[ 'update_time' ] = time();
+
+ //获取商品id
+ if ($data[ 'goods_type' ] == 1) {//全部商品参与
+ $data[ 'goods_ids' ] = '';
+ }
+
+ $coupon_info = model('promotion_coupon_type')->getInfo([ [ 'coupon_type_id', '=', $coupon_type_id ] ]);
+ if (!empty($coupon_info[ 'image' ]) && !empty($data[ 'image' ]) && $coupon_info[ 'image' ] != $data[ 'image' ]) {
+ $upload_model = new Upload();
+ $upload_model->deletePic($coupon_info[ 'image' ], $coupon_info[ 'site_id' ]);
+ }
+
+ $data[ 'goods_ids' ] = ',' . $data[ 'goods_ids' ] . ',';
+ $res = model('promotion_coupon_type')->update($data, [ [ 'coupon_type_id', '=', $coupon_type_id ] ]);
+ model('promotion_coupon')->update([ 'goods_ids' => $data[ 'goods_ids' ], 'goods_type' => $data[ 'goods_type' ] ], [ [ 'coupon_type_id', '=', $coupon_type_id ], [ 'state', '=', 1 ] ]);
+ $cron = new Cron();
+ $cron->deleteCron([ [ 'event', '=', 'CronCouponTypeEnd' ], [ 'relate_id', '=', $coupon_type_id ] ]);
+ if ($data[ 'validity_type' ] == 0) {
+ $cron->addCron(1, 1, '优惠券活动定时结束', 'CronCouponTypeEnd', $data[ 'end_time' ], $coupon_type_id);
+ }
+ return $this->success($res);
+ }
+
+ /**
+ * 关闭优惠券
+ * @param $coupon_type_id
+ * @param $site_id
+ * @return array
+ */
+ public function closeCouponType($coupon_type_id, $site_id)
+ {
+ $res = model('promotion_coupon_type')->update([ 'status' => -1 ], [ [ 'coupon_type_id', '=', $coupon_type_id ], [ 'site_id', '=', $site_id ] ]);
+// if ($res) {
+// model("promotion_coupon")->update(['state' => 3], [['coupon_type_id', '=', $coupon_type_id], ['site_id', '=', $site_id]]);
+// }
+ $cron = new Cron();
+ $cron->deleteCron([ [ 'event', '=', 'CronCouponTypeEnd' ], [ 'relate_id', '=', $coupon_type_id ] ]);
+ return $this->success($res);
+ }
+
+ /**
+ * 删除优惠券活动
+ * @param $coupon_type_id
+ * @param $site_id
+ * @return array
+ */
+ public function deleteCouponType($coupon_type_id, $site_id)
+ {
+ $coupon_info = model('promotion_coupon_type')->getInfo([ [ 'coupon_type_id', '=', $coupon_type_id ] ]);
+
+ if ($coupon_info['status'] == 1) return $this->error('', '进行中的优惠卷无法删除,请先关闭');
+
+ if (!empty($coupon_info[ 'image' ])) {
+ $upload_model = new Upload();
+ $upload_model->deletePic($coupon_info[ 'image' ], $coupon_info[ 'site_id' ]);
+ }
+
+ $res = model('promotion_coupon_type')->delete([ [ 'coupon_type_id', '=', $coupon_type_id ], [ 'site_id', '=', $site_id ] ]);
+ if ($res) {
+ model('promotion_coupon')->delete([ [ 'coupon_type_id', '=', $coupon_type_id ] ]);
+ }
+ $cron = new Cron();
+ $cron->deleteCron([ [ 'event', '=', 'CronCouponTypeEnd' ], [ 'relate_id', '=', $coupon_type_id ] ]);
+
+ return $this->success($res);
+ }
+
+ /**
+ * 获取优惠券活动详情
+ * @param $coupon_type_id
+ * @param $site_id
+ * @return array
+ */
+ public function getCouponTypeInfo($coupon_type_id, $site_id)
+ {
+ $res = model('promotion_coupon_type')->getList([ [ 'coupon_type_id', 'in', $coupon_type_id ], [ 'site_id', '=', $site_id ] ]);
+ if (!empty($res)) {
+ foreach ($res as $k => $v) {
+ if ($v[ 'goods_type' ] == 2 || $v[ 'goods_type' ] == 3) {
+ $field[ $k ] = 'goods_id,goods_name,FLOOR(goods_stock) as goods_stock,goods_image,price,sort';
+ $goods_ids[ $k ] = substr($v[ 'goods_ids' ], '1', '-1');
+ $goods_list[ $k ] = model('goods')->getList([ [ 'goods_id', 'in', $goods_ids[ $k ] ] ], $field[ $k ]);
+ }
+ $res[ $k ][ 'goods_list' ] = $goods_list[$k] ?? [];
+ $res[ $k ][ 'goods_list_count' ] = count($res[ $k ][ 'goods_list' ]);
+ }
+ }
+ return $this->success($res);
+ }
+
+ /**
+ * 获取优惠券活动信息
+ * @param array $where
+ * @param bool $field
+ * @param string $alias
+ * @param null $join
+ * @param null $data
+ * @return array
+ */
+ public function getInfo($where = [], $field = true, $alias = 'a', $join = null, $data = null)
+ {
+ $res = model('promotion_coupon_type')->getInfo($where, $field, $alias, $join, $data);
+ return $this->success($res);
+ }
+
+ /**
+ * 获取优惠券类型列表
+ * @param array $condition
+ * @param string $field
+ * @param string $order
+ * @param null $limit
+ * @return array
+ */
+ public function getCouponTypeList($condition = [], $field = '*', $order = 'create_time desc', $limit = null)
+ {
+ $res = model('promotion_coupon_type')->getList($condition, $field, $order, '', '', '', $limit);
+ return $this->success($res);
+ }
+
+ /**
+ * 获取优惠券活动分页列表
+ * @param array $condition
+ * @param int $page
+ * @param int $page_size
+ * @param string $order
+ * @param string $field
+ * @return array
+ */
+ public function getCouponTypePageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
+ {
+ $condition[] = [ 'promotion_type', '=', 0 ];
+ $list = model('promotion_coupon_type')->pageList($condition, $field, $order, $page, $page_size);
+ return $this->success($list);
+ }
+
+ /**
+ * 排序
+ * @param $coupon_type_id
+ * @param $sort
+ * @return array
+ */
+ public function couponSort($coupon_type_id, $sort)
+ {
+ $res = model('promotion_coupon_type')->update([ 'sort' => $sort ], [ [ 'coupon_type_id', '=', $coupon_type_id ] ]);
+ return $this->success($res);
+ }
+
+ /**
+ * 生成优惠券二维码
+ * @param $coupon_type_id
+ * @param string $app_type all为全部
+ * @param string $type 类型 create创建 get获取
+ * @return mixed|array
+ */
+ public function qrcode($coupon_type_id, $app_type, $site_id, $type = 'create')
+ {
+ $res = event('Qrcode', [
+ 'site_id' => $site_id,
+ 'app_type' => $app_type,
+ 'type' => $type,
+ 'data' => [
+ 'coupon_type_id' => $coupon_type_id
+ ],
+ 'page' => '/pages_tool/goods/coupon_receive',
+ 'qrcode_path' => 'upload/qrcode/coupon',
+ 'qrcode_name' => 'coupon_type_code_' . $coupon_type_id . '_' . $site_id,
+ ], true);
+ return $res;
+ }
+
+ /**
+ * 优惠券定时结束
+ * @param $coupon_type_id
+ * @return array
+ */
+ public function couponCronEnd($coupon_type_id)
+ {
+ $res = model('promotion_coupon_type')->update([ 'status' => 2 ], [ [ 'coupon_type_id', '=', $coupon_type_id ] ]);
+ return $this->success($res);
+ }
+
+ public function spread($coupon_type_id, $name, $site_id, $type = 'create')
+ {
+ $data = [
+ 'site_id' => $site_id,
+ 'app_type' => 'all', // all为全部
+ 'type' => $type, // 类型 create创建 get获取
+ 'data' => [
+ 'coupon_type_id' => $coupon_type_id
+ ],
+ 'page' => '/pages_tool/goods/coupon_receive',
+ 'qrcode_path' => 'upload/qrcode/coupon',
+ 'qrcode_name' => 'coupon_type_code_' . $coupon_type_id . '_' . $site_id,
+ ];
+ event('Qrcode', $data, true);
+ $app_type_list = config('app_type');
+ $path = [];
+ foreach ($app_type_list as $k => $v) {
+ switch ( $k ) {
+ case 'h5':
+ $wap_domain = getH5Domain();
+ $path[ $k ][ 'status' ] = 1;
+ $path[ $k ][ 'url' ] = $wap_domain . $data[ 'page' ] . '?coupon_type_id=' . $coupon_type_id;
+ $path[ $k ][ 'img' ] = 'upload/qrcode/coupon/coupon_type_code_' . $coupon_type_id . '_' . $site_id . '_' . $k . '.png';
+ break;
+ case 'weapp' :
+ $config = new ConfigModel();
+ $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'WEAPP_CONFIG' ] ]);
+ if (!empty($res[ 'data' ])) {
+ if (empty($res[ 'data' ][ 'value' ][ 'qrcode' ])) {
+ $path[ $k ][ 'status' ] = 2;
+ $path[ $k ][ 'message' ] = '未配置微信小程序';
+ } else {
+ $path[ $k ][ 'status' ] = 1;
+ $path[ $k ][ 'img' ] = $res[ 'data' ][ 'value' ][ 'qrcode' ];
+ }
+ } else {
+ $path[ $k ][ 'status' ] = 2;
+ $path[ $k ][ 'message' ] = '未配置微信小程序';
+ }
+ break;
+
+ case 'wechat' :
+ $config = new ConfigModel();
+ $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'WECHAT_CONFIG' ] ]);
+ if (!empty($res[ 'data' ])) {
+ if (empty($res[ 'data' ][ 'value' ][ 'qrcode' ])) {
+ $path[ $k ][ 'status' ] = 2;
+ $path[ $k ][ 'message' ] = '未配置微信公众号';
+ } else {
+ $path[ $k ][ 'status' ] = 1;
+ $path[ $k ][ 'img' ] = $res[ 'data' ][ 'value' ][ 'qrcode' ];
+ }
+ } else {
+ $path[ $k ][ 'status' ] = 2;
+ $path[ $k ][ 'message' ] = '未配置微信公众号';
+ }
+ break;
+ }
+
+ }
+
+ $return = [
+ 'path' => $path,
+ 'name' => $name,
+ ];
+
+ return $this->success($return);
+ }
+
+ public function urlQrcode($page, $qrcode_param, $promotion_type, $app_type, $site_id)
+ {
+ $params = [
+ 'site_id' => $site_id,
+ 'data' => $qrcode_param,
+ 'page' => $page,
+ 'promotion_type' => $promotion_type,
+ 'app_type' => $app_type,
+ 'h5_path' => $page . '?coupon_type_id=' . $qrcode_param[ 'coupon_type_id' ],
+ 'qrcode_path' => 'upload/qrcode/coupon',
+ 'qrcode_name' => 'coupon_type_code_' . $promotion_type . '_' . $qrcode_param[ 'coupon_type_id' ] . '_' . $site_id,
+ ];
+
+ $solitaire = event('PromotionQrcode', $params, true);
+ return $this->success($solitaire);
+ }
}
\ No newline at end of file
diff --git a/src/addon/coupon/model/MemberCoupon.php b/src/addon/coupon/model/MemberCoupon.php
index c28e992ed..ae2537d72 100644
--- a/src/addon/coupon/model/MemberCoupon.php
+++ b/src/addon/coupon/model/MemberCoupon.php
@@ -1,243 +1,235 @@
- 0) {
- $condition[] = [ "site_id", "=", $site_id ];
- }
- $list = model("promotion_coupon")->getList($condition, "*", $order, '', '', '', 0);
- return $this->success($list);
- }
-
- /**
- * 使用优惠券
- * @param $coupon_id
- * @param $member_id
- * @param int $order_id
- * @return array
- */
- public function useMemberCoupon($coupon_id, $member_id, $order_id = 0)
- {
- //优惠券处理方案
- $result = model('promotion_coupon')->update([ 'use_order_id' => $order_id, 'state' => 2, 'use_time' => time() ], [ [ 'coupon_id', '=', $coupon_id ], [ "member_id", "=", $member_id ], [ 'state', '=', 1 ] ]);
- if ($result === false) {
- return $this->error();
- }
- return $this->success();
- }
-
- /**
- * 获取会员已领取优惠券数量
- * @param $member_id
- * @param $state
- * @param int $site_id
- * @return array
- */
- public function getMemberCouponNum($member_id, $state, $site_id = 0)
- {
- $condition = array (
- [ "member_id", "=", $member_id ],
- [ "state", "=", $state ],
- );
- if ($site_id > 0) {
- $condition[] = [ "site_id", "=", $site_id ];
- }
- $num = model("promotion_coupon")->getCount($condition);
- return $this->success($num);
- }
-
- /**
- * 会员是否可领取该优惠券
- * @param $coupon_type_id
- * @param $member_id
- * @return array
- */
- public function receivedNum($coupon_type_id, $member_id)
- {
- $received_num = model('promotion_coupon')->getCount([ [ 'coupon_type_id', '=', $coupon_type_id ], [ 'member_id', '=', $member_id ] ]);
- return $this->success($received_num);
- }
-
- /**
- * 获取编码
- */
- public function getCode()
- {
- return random_keys(8);
- }
-
- /**
- * 会员批量发放优惠券
- * @param $coupon_type_ids
- * @param $site_id
- * @param $member_id
- * @param int $get_type
- * @param int $is_stock
- * @param int $related_id
- * @return array
- */
- public function sendCoupon($coupon_type_ids, $site_id, $member_id, $get_type = 4, $is_stock = 0, $related_id = 0)
- {
- //已选优惠券提交数组
- if (!empty($coupon_type_ids)) {
- $res = 0;
- foreach ($coupon_type_ids as $coupon_type_id) {
- $coupon_type_info = model('promotion_coupon_type')->getInfo([ 'coupon_type_id' => $coupon_type_id, 'site_id' => $site_id, 'status' => 1 ]);
- if (!empty($coupon_type_info)) {
-
- if ($coupon_type_info[ 'count' ] != -1 || $is_stock == 0) {
- if ($coupon_type_info[ 'count' ] == $coupon_type_info[ 'lead_count' ]) {
- return $this->error('', '来迟了该优惠券已被领取完了');
- }
- }
- if ($coupon_type_info[ 'max_fetch' ] != 0 && $get_type == 2) {
- //限制领取
- $member_receive_num = model('promotion_coupon')->getCount([
- 'coupon_type_id' => $coupon_type_id,
- 'member_id' => $member_id,
- 'get_type' => 2
- ]);
- if ($member_receive_num >= $coupon_type_info[ 'max_fetch' ] ) {
- return $this->error('', '该优惠券领取已达到上限');
- }
- }
-
- $data = [
- 'coupon_type_id' => $coupon_type_id,
- 'site_id' => $site_id,
- 'coupon_code' => $this->getCode(),
- 'member_id' => $member_id,
- 'money' => $coupon_type_info[ 'money' ],
- 'state' => 1,
- 'get_type' => $get_type,
- 'goods_type' => $coupon_type_info[ 'goods_type' ],
- 'fetch_time' => time(),
- 'coupon_name' => $coupon_type_info[ 'coupon_name' ],
- 'at_least' => $coupon_type_info[ 'at_least' ],
- 'type' => $coupon_type_info[ 'type' ],
- 'discount' => $coupon_type_info[ 'discount' ],
- 'discount_limit' => $coupon_type_info[ 'discount_limit' ],
- 'goods_ids' => $coupon_type_info[ 'goods_ids' ],
- 'related_id' => $related_id
- ];
-
- if ($coupon_type_info[ 'validity_type' ] == 0) {
- $data[ 'end_time' ] = $coupon_type_info[ 'end_time' ];
- } elseif ($coupon_type_info[ 'validity_type' ] == 1) {
- $data[ 'end_time' ] = ( time() + $coupon_type_info[ 'fixed_term' ] * 86400 );
- }
-
- $res = model('promotion_coupon')->add($data);
- if ($is_stock == 0) {
- model('promotion_coupon_type')->setInc([ [ 'coupon_type_id', '=', $coupon_type_id ] ], 'lead_count');
- }
- }
- }
- if ($res) {
- return $this->success($res);
- } else {
- return $this->error();
- }
- } else {
- return $this->error();
- }
- }
-
- /**
- * 回收优惠券
- * @param array $coupon_list
- * @param $site_id
- * @return array
- */
- public function recoveryCoupon(array $coupon_list, $site_id)
- {
- $coupon = [];
- foreach ($coupon_list as $coupon_item) {
- if (isset($coupon[ $coupon_item[ 'coupon_type_id' ] ])) {
- $coupon[$coupon_item['coupon_type_id']][] = $coupon_item['coupon_id'];
- } else {
- $coupon[ $coupon_item[ 'coupon_type_id' ] ] = [ $coupon_item[ 'coupon_id' ] ];
- }
- }
- if (!count($coupon)) return $this->error();
-
- model('promotion_coupon')->startTrans();
- try {
- foreach ($coupon as $coupon_type_id => $coupon_ids) {
- $num = model('promotion_coupon')->delete([ [ 'coupon_id', 'in', $coupon_ids ], [ 'site_id', '=', $site_id ], [ 'state', '=', 1 ] ]);
- if ($num) model('promotion_coupon_type')->setDec([ [ 'coupon_type_id', '=', $coupon_type_id ] ], 'lead_count', $num);
- }
- model('promotion_coupon')->commit();
- return $this->success();
- } catch (\Exception $e) {
- model('promotion_coupon')->rollback();
- return $this->error('', '回收失败');
- }
- }
-
- /**
- * 专用于撤回活动赠送的优惠券
- * @return void
- */
- public function cancelByPromotion($data){
- $member_id = $data['member_id'];
- $coupon_data = $data['coupon_data'];//优惠券id相关项
- $coupon_ids = array_column($coupon_data, 'coupon_type_id');
- $member_coupon_list = model('promotion_coupon')->getList([
- ['member_id', '=', $member_id],
- ['coupon_type_id', 'in', $coupon_ids],
- ['state', '=', CouponDict::normal]
- ], '*');
- $member_coupon_type_group_list = [];
- foreach($member_coupon_list as $v){
- $member_coupon_type_group_list[$v['coupon_type_id']][] = $v['coupon_id'];
- }
- $cancel_ids = [];
- foreach ($coupon_data as $item) {
- $coupon_type_id = $item['coupon_type_id'];
- $num = $item['num'];
- $item_coupon_type_group = $member_coupon_type_group_list[$coupon_type_id] ?? [];
- if($item_coupon_type_group){
- if(count($item_coupon_type_group) > $num){
- $cancel_ids = array_merge($cancel_ids, array_slice($item_coupon_type_group, 0, $num));
- }else{
- $cancel_ids = array_merge($cancel_ids, $item_coupon_type_group);
- }
- }
- }
- model('promotion_coupon')->update(['state' => CouponDict::close], [['coupon_id', 'in', $cancel_ids]]);
- return $this->success();
-
- }
+ 0) {
+ $condition[] = [ "site_id", "=", $site_id ];
+ }
+ $list = model("promotion_coupon")->getList($condition, "*", $order, '', '', '', 0);
+ return $this->success($list);
+ }
+
+ /**
+ * 使用优惠券
+ * @param $coupon_id
+ * @param $member_id
+ * @param int $order_id
+ * @return array
+ */
+ public function useMemberCoupon($coupon_id, $member_id, $order_id = 0)
+ {
+ //优惠券处理方案
+ $result = model('promotion_coupon')->update([ 'use_order_id' => $order_id, 'state' => 2, 'use_time' => time() ], [ [ 'coupon_id', '=', $coupon_id ], [ "member_id", "=", $member_id ], [ 'state', '=', 1 ] ]);
+ if ($result === false) {
+ return $this->error();
+ }
+ return $this->success();
+ }
+
+ /**
+ * 获取会员已领取优惠券数量
+ * @param $member_id
+ * @param $state
+ * @param int $site_id
+ * @return array
+ */
+ public function getMemberCouponNum($member_id, $state, $site_id = 0)
+ {
+ $condition = array (
+ [ "member_id", "=", $member_id ],
+ [ "state", "=", $state ],
+ );
+ if ($site_id > 0) {
+ $condition[] = [ "site_id", "=", $site_id ];
+ }
+ $num = model("promotion_coupon")->getCount($condition);
+ return $this->success($num);
+ }
+
+ /**
+ * 会员是否可领取该优惠券
+ * @param $coupon_type_id
+ * @param $member_id
+ * @return array
+ */
+ public function receivedNum($coupon_type_id, $member_id)
+ {
+ $received_num = model('promotion_coupon')->getCount([ [ 'coupon_type_id', '=', $coupon_type_id ], [ 'member_id', '=', $member_id ] ]);
+ return $this->success($received_num);
+ }
+
+ /**
+ * 获取编码
+ */
+ public function getCode()
+ {
+ return random_keys(8);
+ }
+
+ /**
+ * 会员批量发放优惠券
+ * @param $coupon_type_ids
+ * @param $site_id
+ * @param $member_id
+ * @param int $get_type
+ * @param int $is_stock
+ * @param int $related_id
+ * @return array
+ */
+ public function sendCoupon($coupon_type_ids, $site_id, $member_id, $get_type = 4, $is_stock = 0, $related_id = 0)
+ {
+ //已选优惠券提交数组
+ if (!empty($coupon_type_ids)) {
+ $res = 0;
+ foreach ($coupon_type_ids as $coupon_type_id) {
+ $coupon_type_info = model('promotion_coupon_type')->getInfo([ 'coupon_type_id' => $coupon_type_id, 'site_id' => $site_id, 'status' => 1 ]);
+ if (!empty($coupon_type_info)) {
+
+ if ($coupon_type_info[ 'count' ] != -1 || $is_stock == 0) {
+ if ($coupon_type_info[ 'count' ] == $coupon_type_info[ 'lead_count' ]) {
+ return $this->error('', '来迟了该优惠券已被领取完了');
+ }
+ }
+ if ($coupon_type_info[ 'max_fetch' ] != 0 && $get_type == 2) {
+ //限制领取
+ $member_receive_num = model('promotion_coupon')->getCount([
+ 'coupon_type_id' => $coupon_type_id,
+ 'member_id' => $member_id,
+ 'get_type' => 2
+ ]);
+ if ($member_receive_num >= $coupon_type_info[ 'max_fetch' ] ) {
+ return $this->error('', '该优惠券领取已达到上限');
+ }
+ }
+
+ $data = [
+ 'coupon_type_id' => $coupon_type_id,
+ 'site_id' => $site_id,
+ 'coupon_code' => $this->getCode(),
+ 'member_id' => $member_id,
+ 'money' => $coupon_type_info[ 'money' ],
+ 'state' => 1,
+ 'get_type' => $get_type,
+ 'goods_type' => $coupon_type_info[ 'goods_type' ],
+ 'fetch_time' => time(),
+ 'coupon_name' => $coupon_type_info[ 'coupon_name' ],
+ 'at_least' => $coupon_type_info[ 'at_least' ],
+ 'type' => $coupon_type_info[ 'type' ],
+ 'discount' => $coupon_type_info[ 'discount' ],
+ 'discount_limit' => $coupon_type_info[ 'discount_limit' ],
+ 'goods_ids' => $coupon_type_info[ 'goods_ids' ],
+ 'related_id' => $related_id
+ ];
+
+ if ($coupon_type_info[ 'validity_type' ] == 0) {
+ $data[ 'end_time' ] = $coupon_type_info[ 'end_time' ];
+ } elseif ($coupon_type_info[ 'validity_type' ] == 1) {
+ $data[ 'end_time' ] = ( time() + $coupon_type_info[ 'fixed_term' ] * 86400 );
+ }
+
+ $res = model('promotion_coupon')->add($data);
+ if ($is_stock == 0) {
+ model('promotion_coupon_type')->setInc([ [ 'coupon_type_id', '=', $coupon_type_id ] ], 'lead_count');
+ }
+ }
+ }
+ if ($res) {
+ return $this->success($res);
+ } else {
+ return $this->error();
+ }
+ } else {
+ return $this->error();
+ }
+ }
+
+ /**
+ * 回收优惠券
+ * @param array $coupon_list
+ * @param $site_id
+ * @return array
+ */
+ public function recoveryCoupon(array $coupon_list, $site_id)
+ {
+ $coupon = [];
+ foreach ($coupon_list as $coupon_item) {
+ if (isset($coupon[ $coupon_item[ 'coupon_type_id' ] ])) {
+ $coupon[$coupon_item['coupon_type_id']][] = $coupon_item['coupon_id'];
+ } else {
+ $coupon[ $coupon_item[ 'coupon_type_id' ] ] = [ $coupon_item[ 'coupon_id' ] ];
+ }
+ }
+ if (!count($coupon)) return $this->error();
+
+ model('promotion_coupon')->startTrans();
+ try {
+ foreach ($coupon as $coupon_type_id => $coupon_ids) {
+ $num = model('promotion_coupon')->delete([ [ 'coupon_id', 'in', $coupon_ids ], [ 'site_id', '=', $site_id ], [ 'state', '=', 1 ] ]);
+ if ($num) model('promotion_coupon_type')->setDec([ [ 'coupon_type_id', '=', $coupon_type_id ] ], 'lead_count', $num);
+ }
+ model('promotion_coupon')->commit();
+ return $this->success();
+ } catch (\Exception $e) {
+ model('promotion_coupon')->rollback();
+ return $this->error('', '回收失败');
+ }
+ }
+
+ /**
+ * 专用于撤回活动赠送的优惠券
+ * @return void
+ */
+ public function cancelByPromotion($data){
+ $member_id = $data['member_id'];
+ $coupon_data = $data['coupon_data'];//优惠券id相关项
+ $coupon_ids = array_column($coupon_data, 'coupon_type_id');
+ $member_coupon_list = model('promotion_coupon')->getList([
+ ['member_id', '=', $member_id],
+ ['coupon_type_id', 'in', $coupon_ids],
+ ['state', '=', CouponDict::normal]
+ ], '*');
+ $member_coupon_type_group_list = [];
+ foreach($member_coupon_list as $v){
+ $member_coupon_type_group_list[$v['coupon_type_id']][] = $v['coupon_id'];
+ }
+ $cancel_ids = [];
+ foreach ($coupon_data as $item) {
+ $coupon_type_id = $item['coupon_type_id'];
+ $num = $item['num'];
+ $item_coupon_type_group = $member_coupon_type_group_list[$coupon_type_id] ?? [];
+ if($item_coupon_type_group){
+ if(count($item_coupon_type_group) > $num){
+ $cancel_ids = array_merge($cancel_ids, array_slice($item_coupon_type_group, 0, $num));
+ }else{
+ $cancel_ids = array_merge($cancel_ids, $item_coupon_type_group);
+ }
+ }
+ }
+ model('promotion_coupon')->update(['state' => CouponDict::close], [['coupon_id', 'in', $cancel_ids]]);
+ return $this->success();
+
+ }
}
\ No newline at end of file
diff --git a/src/addon/coupon/model/share/WchatShare.php b/src/addon/coupon/model/share/WchatShare.php
index 744436592..899ba8d0f 100644
--- a/src/addon/coupon/model/share/WchatShare.php
+++ b/src/addon/coupon/model/share/WchatShare.php
@@ -1,103 +1,94 @@
- '领券中心',
- 'config_key' => 'WCHAT_SHARE_CONFIG_COUPON_LIST',
- 'path' => [ '/pages_tool/goods/coupon' ],
- 'method_prefix' => 'couponList',
- ],
- ];
-
- /**
- * 商品列表分享数据
- * @param $param
- * @return array
- */
- protected function couponListShareData($param)
- {
- $site_id = $param[ 'site_id' ] ?? 0;
-
- //站点设置
- $site_model = new SiteModel();
- $site_info = $site_model->getSiteInfo([ [ 'site_id', '=', $site_id ] ])[ 'data' ];
-
- //跳转路径
- $link = $this->getShareLink($param);
-
- //获取和替换配置数据
- $config_method = preg_replace('/Data$/', 'Config', __FUNCTION__);
- $config_data = $this->$config_method($param);
- $title = $config_data[ 'value' ][ 'title' ];
- $desc = $config_data[ 'value' ][ 'desc' ];
- $image_url = $config_data[ 'value' ][ 'imgUrl' ] ?: $site_info[ 'logo_square' ];
-
- $data = [
- 'title' => $title,
- 'desc' => $desc,
- 'link' => $link,
- 'imgUrl' => $image_url,
- ];
- return [
- 'permission' => [
- 'hideOptionMenu' => false,
- 'hideMenuItems' => [],
- ],
- 'data' => $data,//分享内容
- ];
- }
-
- /**
- * 商品列表分享配置
- * @param $param
- * @return array
- */
- protected function couponListShareConfig($param)
- {
- $site_id = $param[ 'site_id' ];
- $config = $param[ 'config' ];
-
- $config_model = new ConfigModel();
- $data = $config_model->getConfig([
- [ 'site_id', '=', $site_id ],
- [ 'app_module', '=', 'shop' ],
- [ 'config_key', '=', $config[ 'config_key' ] ],
- ])[ 'data' ];
- if (empty($data[ 'value' ])) {
- $data[ 'value' ] = [
- 'title' => '送你一张优惠券',
- 'desc' => "优惠多多\n好物多多",
- 'imgUrl' => '',
- ];
- }
- if (empty($data[ 'value' ][ 'imgUrl' ])) {
- $data[ 'value' ][ 'imgUrl' ] = img('addon/coupon/icon.png');
- }
- $variable = [];
-
- return [
- 'value' => $data[ 'value' ],
- 'variable' => $variable,
- ];
- }
-}
+ '领券中心',
+ 'config_key' => 'WCHAT_SHARE_CONFIG_COUPON_LIST',
+ 'path' => [ '/pages_tool/goods/coupon' ],
+ 'method_prefix' => 'couponList',
+ ],
+ ];
+
+ /**
+ * 商品列表分享数据
+ * @param $param
+ * @return array
+ */
+ protected function couponListShareData($param)
+ {
+ $site_id = $param[ 'site_id' ] ?? 0;
+
+ //站点设置
+ $site_model = new SiteModel();
+ $site_info = $site_model->getSiteInfo([ [ 'site_id', '=', $site_id ] ])[ 'data' ];
+
+ //跳转路径
+ $link = $this->getShareLink($param);
+
+ //获取和替换配置数据
+ $config_method = preg_replace('/Data$/', 'Config', __FUNCTION__);
+ $config_data = $this->$config_method($param);
+ $title = $config_data[ 'value' ][ 'title' ];
+ $desc = $config_data[ 'value' ][ 'desc' ];
+ $image_url = $config_data[ 'value' ][ 'imgUrl' ] ?: $site_info[ 'logo_square' ];
+
+ $data = [
+ 'title' => $title,
+ 'desc' => $desc,
+ 'link' => $link,
+ 'imgUrl' => $image_url,
+ ];
+ return [
+ 'permission' => [
+ 'hideOptionMenu' => false,
+ 'hideMenuItems' => [],
+ ],
+ 'data' => $data,//分享内容
+ ];
+ }
+
+ /**
+ * 商品列表分享配置
+ * @param $param
+ * @return array
+ */
+ protected function couponListShareConfig($param)
+ {
+ $site_id = $param[ 'site_id' ];
+ $config = $param[ 'config' ];
+
+ $config_model = new ConfigModel();
+ $data = $config_model->getConfig([
+ [ 'site_id', '=', $site_id ],
+ [ 'app_module', '=', 'shop' ],
+ [ 'config_key', '=', $config[ 'config_key' ] ],
+ ])[ 'data' ];
+ if (empty($data[ 'value' ])) {
+ $data[ 'value' ] = [
+ 'title' => '送你一张优惠券',
+ 'desc' => "优惠多多\n好物多多",
+ 'imgUrl' => '',
+ ];
+ }
+ if (empty($data[ 'value' ][ 'imgUrl' ])) {
+ $data[ 'value' ][ 'imgUrl' ] = img('addon/coupon/icon.png');
+ }
+ $variable = [];
+
+ return [
+ 'value' => $data[ 'value' ],
+ 'variable' => $variable,
+ ];
+ }
+}
diff --git a/src/addon/coupon/model/share/WeappShare.php b/src/addon/coupon/model/share/WeappShare.php
index d6e0dc714..34f60e4be 100644
--- a/src/addon/coupon/model/share/WeappShare.php
+++ b/src/addon/coupon/model/share/WeappShare.php
@@ -1,91 +1,82 @@
- '领券中心',
- 'config_key' => 'WEAPP_SHARE_CONFIG_COUPON_LIST',
- 'path' => [ '/pages_tool/goods/coupon' ],
- 'method_prefix' => 'couponList',
- ],
- ];
-
- protected $sort = 2;
-
- /***************************** 领券中心 ***************************/
-
- /**
- * 首页分享数据
- * @param $param
- * @return array
- */
- protected function couponListShareData($param)
- {
- //获取和替换配置数据
- $config_data = $this->couponListShareConfig($param);
- $title = $config_data[ 'value' ][ 'title' ];
- $image_url = $config_data[ 'value' ][ 'imageUrl' ] ? img($config_data[ 'value' ][ 'imageUrl' ]) : '';
- $path = $this->getSharePath($param);
-
- $data = [
- 'title' => $title,
- 'path' => $path,
- 'imageUrl' => $image_url,
- ];
- return [
- 'permission' => [
- 'onShareAppMessage' => true,
- 'onShareTimeline' => true,
- ],
- 'data' => $data,//分享内容
- ];
- }
-
- /**
- * 首页分享配置
- * @param $param
- * @return array
- */
- protected function couponListShareConfig($param)
- {
- $site_id = $param[ 'site_id' ];
- $config = $param[ 'config' ];
-
- $config_model = new ConfigModel();
- $data = $config_model->getConfig([
- [ 'site_id', '=', $site_id ],
- [ 'app_module', '=', 'shop' ],
- [ 'config_key', '=', $config[ 'config_key' ] ],
- ])[ 'data' ];
- if (empty($data[ 'value' ])) {
- $data[ 'value' ] = [
- 'title' => '送你一张优惠券,快来领取吧',
- 'imageUrl' => '',
- ];
- }
- $variable = [];
-
- return [
- 'value' => $data[ 'value' ],
- 'variable' => $variable,
- ];
- }
-}
+ '领券中心',
+ 'config_key' => 'WEAPP_SHARE_CONFIG_COUPON_LIST',
+ 'path' => [ '/pages_tool/goods/coupon' ],
+ 'method_prefix' => 'couponList',
+ ],
+ ];
+
+ protected $sort = 2;
+
+ /***************************** 领券中心 ***************************/
+
+ /**
+ * 首页分享数据
+ * @param $param
+ * @return array
+ */
+ protected function couponListShareData($param)
+ {
+ //获取和替换配置数据
+ $config_data = $this->couponListShareConfig($param);
+ $title = $config_data[ 'value' ][ 'title' ];
+ $image_url = $config_data[ 'value' ][ 'imageUrl' ] ? img($config_data[ 'value' ][ 'imageUrl' ]) : '';
+ $path = $this->getSharePath($param);
+
+ $data = [
+ 'title' => $title,
+ 'path' => $path,
+ 'imageUrl' => $image_url,
+ ];
+ return [
+ 'permission' => [
+ 'onShareAppMessage' => true,
+ 'onShareTimeline' => true,
+ ],
+ 'data' => $data,//分享内容
+ ];
+ }
+
+ /**
+ * 首页分享配置
+ * @param $param
+ * @return array
+ */
+ protected function couponListShareConfig($param)
+ {
+ $site_id = $param[ 'site_id' ];
+ $config = $param[ 'config' ];
+
+ $config_model = new ConfigModel();
+ $data = $config_model->getConfig([
+ [ 'site_id', '=', $site_id ],
+ [ 'app_module', '=', 'shop' ],
+ [ 'config_key', '=', $config[ 'config_key' ] ],
+ ])[ 'data' ];
+ if (empty($data[ 'value' ])) {
+ $data[ 'value' ] = [
+ 'title' => '送你一张优惠券,快来领取吧',
+ 'imageUrl' => '',
+ ];
+ }
+ $variable = [];
+
+ return [
+ 'value' => $data[ 'value' ],
+ 'variable' => $variable,
+ ];
+ }
+}
diff --git a/src/addon/coupon/shopapi/controller/Coupon.php b/src/addon/coupon/shopapi/controller/Coupon.php
index e5926fbf6..112e99db7 100644
--- a/src/addon/coupon/shopapi/controller/Coupon.php
+++ b/src/addon/coupon/shopapi/controller/Coupon.php
@@ -1,110 +1,102 @@
-checkToken();
- if ($token[ 'code' ] < 0) {
- echo $this->response($token);
- exit;
- }
- }
-
- /**
- * 活动列表
- */
- public function lists()
- {
- $coupon_type_model = new CouponTypeModel();
-
- $page = $this->params['page'] ?? 1;
- $page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
- $coupon_name = $this->params['coupon_name'] ?? '';
- $status = $this->params['status'] ?? '';
-
- $condition = [];
- if ($status !== '') {
- $condition[] = [ 'status', '=', $status ];
- }
- $type = $this->params['type'] ?? '';
- if ($type) {
- $condition[] = [ 'type', '=', $type ];
- }
- //类型
- $validity_type = $this->params['validity_type'] ?? '';
- if ($validity_type) {
- $start_time = $this->params['start_time'] ?? '';
- $end_time = $this->params['end_time'] ?? '';
- switch ( $validity_type ) {
- case 1: //固定
- $condition[] = [ 'end_time', 'between', [ $start_time, $end_time ] ];
- break;
- case 2:
- $condition[] = [ 'fixed_term', 'between', [ $start_time, $end_time ] ];
- break;
- }
- }
-
- $condition[] = [ 'site_id', '=', $this->site_id ];
- $condition[] = [ 'coupon_name', 'like', '%' . $coupon_name . '%' ];
- $order = 'create_time desc';
- $field = '*';
-
- $res = $coupon_type_model->getCouponTypePageList($condition, $page, $page_size, $order, $field);
- //获取优惠券状态
- $coupon_type_status_arr = $coupon_type_model->getCouponTypeStatus();
- foreach ($res[ 'data' ][ 'list' ] as $key => $val) {
- $res[ 'data' ][ 'list' ][ $key ][ 'status_name' ] = $coupon_type_status_arr[ $val[ 'status' ] ];
- }
-
- return $this->response($res);
- }
-
- /**
- * 发放优惠券
- */
- public function send()
- {
- $member_id = $this->params['member_id'] ?? 0;
- $coupon_type_ids = $this->params['parent'] ?? '';
- $get_type = $this->params['get_type'] ?? 4;
- $site_id = $this->site_id;
- $parent = $coupon_type_ids;
- if (empty($parent)) {
- return $this->error('', 'REQUEST_COUPON_TYPE_ID');
- }
- $parent = explode(',', $parent);
- if (count($parent) == 1) {
- $coupon_model = new CouponModel();
- $res = $coupon_model->receiveCoupon($parent[ 0 ], $site_id, $member_id, $get_type);
- } else {
- $member_coupon_model = new MemberCoupon();
- $res = $member_coupon_model->sendCoupon(explode(',', $coupon_type_ids), $site_id, $member_id, $get_type);
- }
- return $this->response($res);
- }
-
+checkToken();
+ if ($token[ 'code' ] < 0) {
+ echo $this->response($token);
+ exit;
+ }
+ }
+
+ /**
+ * 活动列表
+ */
+ public function lists()
+ {
+ $coupon_type_model = new CouponTypeModel();
+
+ $page = $this->params['page'] ?? 1;
+ $page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
+ $coupon_name = $this->params['coupon_name'] ?? '';
+ $status = $this->params['status'] ?? '';
+
+ $condition = [];
+ if ($status !== '') {
+ $condition[] = [ 'status', '=', $status ];
+ }
+ $type = $this->params['type'] ?? '';
+ if ($type) {
+ $condition[] = [ 'type', '=', $type ];
+ }
+ //类型
+ $validity_type = $this->params['validity_type'] ?? '';
+ if ($validity_type) {
+ $start_time = $this->params['start_time'] ?? '';
+ $end_time = $this->params['end_time'] ?? '';
+ switch ( $validity_type ) {
+ case 1: //固定
+ $condition[] = [ 'end_time', 'between', [ $start_time, $end_time ] ];
+ break;
+ case 2:
+ $condition[] = [ 'fixed_term', 'between', [ $start_time, $end_time ] ];
+ break;
+ }
+ }
+
+ $condition[] = [ 'site_id', '=', $this->site_id ];
+ $condition[] = [ 'coupon_name', 'like', '%' . $coupon_name . '%' ];
+ $order = 'create_time desc';
+ $field = '*';
+
+ $res = $coupon_type_model->getCouponTypePageList($condition, $page, $page_size, $order, $field);
+ //获取优惠券状态
+ $coupon_type_status_arr = $coupon_type_model->getCouponTypeStatus();
+ foreach ($res[ 'data' ][ 'list' ] as $key => $val) {
+ $res[ 'data' ][ 'list' ][ $key ][ 'status_name' ] = $coupon_type_status_arr[ $val[ 'status' ] ];
+ }
+
+ return $this->response($res);
+ }
+
+ /**
+ * 发放优惠券
+ */
+ public function send()
+ {
+ $member_id = $this->params['member_id'] ?? 0;
+ $coupon_type_ids = $this->params['parent'] ?? '';
+ $get_type = $this->params['get_type'] ?? 4;
+ $site_id = $this->site_id;
+ $parent = $coupon_type_ids;
+ if (empty($parent)) {
+ return $this->error('', 'REQUEST_COUPON_TYPE_ID');
+ }
+ $parent = explode(',', $parent);
+ if (count($parent) == 1) {
+ $coupon_model = new CouponModel();
+ $res = $coupon_model->receiveCoupon($parent[ 0 ], $site_id, $member_id, $get_type);
+ } else {
+ $member_coupon_model = new MemberCoupon();
+ $res = $member_coupon_model->sendCoupon(explode(',', $coupon_type_ids), $site_id, $member_id, $get_type);
+ }
+ return $this->response($res);
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/diy_default1/config/diy_view.php b/src/addon/diy_default1/config/diy_view.php
index 269d932e9..d04f5ca65 100644
--- a/src/addon/diy_default1/config/diy_view.php
+++ b/src/addon/diy_default1/config/diy_view.php
@@ -1,2072 +1,2064 @@
- '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
- 'template' => [],
-
- // 后台自定义组件——装修
- 'util' => [
-// [
-// 'name' => 'TextExtend', // 组件控制器名称
-// 'title' => '扩展标题',
-// 'type' => 'EXTEND', // 组件类型,SYSTEM:基础组件,PROMOTION:营销组件,EXTEND:扩展组件
-// 'value' => '{}',
-// 'sort' => '50000',
-// 'support_diy_view' => '', // 支持的自定义页面(为空表示公共组件都支持)
-// 'max_count' => 0, // 限制添加次数,0表示可以无限添加该组件
-// 'is_delete' => 0, // 组件是否可以删除,0 允许,1 禁用
-// 'icon' => 'icon-comp-diy-default icon-wenben', // 组件字体图标
-// ],
- ],
-
- // 自定义页面路径
- 'link' => [],
-
- // 自定义图标库
- 'icon_library' => [
-
- // 组件图标【用于后台组件装修】
- 'component' => [
-// 'name' => 'icon-comp-diy-default', // 字体名称
-// 'path' => 'addon/diy_default1/shop/view/public/css/comp_iconfont.css' // 文件路径
- ],
-
- // 自定义图标库
- 'icon' => [
-// 'name' => 'icondiy-my-template', // 字体名称
-// 'path' => 'addon/diy_default1/shop/view/public/css/diy_iconfont.css' // 文件路径
- ],
-
- // 图标类型
- 'type' => [
-// 'icon-building' => '建筑',
-// 'icon-furniture' => '家具',
-// 'icon-animal' => '动物',
- ]
- ],
-
- // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
- 'component' => [
-// [
-// 'name' => 'TextExtend', // 组件名称
-// 'path' => 'components/diy-components/diy-text-extend.vue' // 路径
-// ],
-// [
-// 'name' => 'my-music', // 文件夹名称
-// 'path' => 'components/my-music' // 目录路径
-// ],
- ],
-
- // uni-app 页面,多个逗号隔开
- 'pages' => [
-// [
-// 'path' => 'pages/goods/my_cart',
-// 'style' => [
-// 'navigationBarTitleText' => '新购物车'
-// ]
-// ],
-// [
-// 'path' => 'pages_promotion/index/index',
-// 'style' => [
-// 'navigationBarTitleText' => '营销活动中心'
-// ]
-// ],
- ],
-
- // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
- 'info' => [
- 'title' => '官方模板一', // 模板名称
- 'name' => 'official_default_round', // 模板标识
- 'cover' => 'addon/diy_default1/shop/view/public/img/cover.png', // 模板封面图
- 'preview' => 'addon/diy_default1/shop/view/public/img/preview.png', // 模板预览图
- 'desc' => '商城简约而不失时尚,适合大部分商城运营。', // 模板描述
- ],
-
- // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
- 'theme' => [
-// [
-// 'title' => '中国红',
-// 'name' => 'colorful',
-// 'preview' => [
-// 'public/static/img/diy_view/style/decorate-default-1.jpg',
-// 'public/static/img/diy_view/style/decorate-default-2.jpg',
-// 'public/static/img/diy_view/style/decorate-default-3.jpg',
-// ],
-// 'color_img' => 'public/static/img/diy_view/style/default.png', // 配色图
-// 'main_color' => '#F4391c',
-// 'aux_color' => '#F7B500',
-// 'bg_color' => '#FF4646',//主题背景
-// 'bg_color_shallow' => '#FF4646',//主题背景渐变浅色
-// 'promotion_color' => '#FF4646',//活动背景
-// 'promotion_aux_color' => '#F7B500',//活动背景辅色
-// 'main_color_shallow' => '#FFF4F4',//淡背景
-// 'price_color' => 'rgb(252,82,39)',//价格颜色
-// 'btn_text_color' => '#FFFFFF',//按钮文字颜色
-// 'goods_detail' => [
-// 'goods_price' => 'rgb(252,82,39,1)',//价格
-// 'promotion_tag' => '#FF4646',
-// 'goods_card_bg' => '#201A18',//会员卡背景
-// 'goods_card_bg_shallow' => '#7C7878',//会员卡背景浅色
-// 'goods_card_color' => '#FFD792',
-// 'goods_coupon' => '#FC5227',
-// 'goods_cart_num_corner' => '#FC5227',//购物车数量角标
-// 'goods_btn_color' => '#FF4646',//按钮颜色
-// 'goods_btn_color_shallow' => '#F7B500',//副按钮颜色
-// ],
-// 'super_member' => [
-// 'super_member_start_bg' => '#7c7878',
-// 'super_member_end_bg' => '#201a18',
-// 'super_member_start_text_color' => '#FFDBA6',
-// 'super_member_end_text_color' => '#FFEBCA',
-// ],
-// 'giftcard' => [
-// 'giftcard_promotion_color' => '#FF3369',//活动背景
-// 'giftcard_promotion_aux_color' => '#F7B500',//活动辅色
-// ],
-// ],
- ],
-
- // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
- 'data' => [
- [
- 'title' => '官方模板一',
- 'name' => "DIY_VIEW_INDEX",
- 'value' => [
- "global" => [
- "title" => "官方模板一",
- "pageBgColor" => "#F6F9FF",
- "topNavColor" => "#FFFFFF",
- "topNavBg" => false,
- "navBarSwitch" => true,
- "textNavColor" => "#333333",
- "topNavImg" => "",
- "moreLink" => [
- "name" => ""
- ],
- "openBottomNav" => true,
- "navStyle" => 1,
- "textImgPosLink" => "center",
- "mpCollect" => false,
- "popWindow" => [
- "imageUrl" => "",
- "count" => -1,
- "show" => 0,
- "link" => [
- "name" => ""
- ],
- "imgWidth" => "",
- "imgHeight" => ""
- ],
- "bgUrl" => 'addon/diy_default1/shop/view/public/img/bg.png',
- "imgWidth" => "2250",
- "imgHeight" => "1110",
- "template" => [
- "pageBgColor" => "",
- "textColor" => "#303133",
- "componentBgColor" => "",
- "componentAngle" => "round",
- "topAroundRadius" => 0,
- "bottomAroundRadius" => 0,
- "elementBgColor" => "",
- "elementAngle" => "round",
- "topElementAroundRadius" => 0,
- "bottomElementAroundRadius" => 0,
- "margin" => [
- "top" => 0,
- "bottom" => 0,
- "both" => 12
- ]
- ],
- ],
- "value" => [
- [
- "id" => "5wtw72w1wj80",
- 'addonName' => '',
- "componentName" => "Search",
- "componentTitle" => "搜索框",
- "isDelete" => 0,
- "topAroundRadius" => 0,
- "bottomAroundRadius" => 0,
- "topElementAroundRadius" => 0,
- "bottomElementAroundRadius" => 0,
- "margin" => [
- "top" => 10,
- "bottom" => 10,
- "both" => 12
- ],
- "title" => "请输入搜索关键词",
- "textAlign" => "left",
- "borderType" => 2,
- "searchImg" => "",
- "searchStyle" => 1,
- "searchLink" => [
- "name" => ""
- ],
- "pageBgColor" => "#FFFFFF",
- "textColor" => "#303133",
- "componentBgColor" => "",
- "elementBgColor" => "#F6F9FF",
- "iconType" => "img",
- "icon" => "",
- "style" => [
- "fontSize" => "60",
- "iconBgColor" => [],
- "iconBgColorDeg" => 0,
- "iconBgImg" => "",
- "bgRadius" => 0,
- "iconColor" => [
- "#000000"
- ],
- "iconColorDeg" => 0
- ],
- "imageUrl" => "",
- "positionWay" => "static"
- ],
- [
- "id" => "2o7za2qmi900",
- "list" => [
- [
- "link" => [
- "name" => ""
- ],
- "imageUrl" => 'addon/diy_default1/shop/view/public/img/banner.png',
- "imgWidth" => "750",
- "imgHeight" => "320",
- "id" => "1iy3xvq2ngf40"
- ]
- ],
- "indicatorIsShow" => true,
- "indicatorColor" => "#ffffff",
- "carouselStyle" => "circle",
- "indicatorLocation" => "center",
- 'addonName' => '',
- "componentName" => "ImageAds",
- "componentTitle" => "图片广告",
- "isDelete" => 0,
- "pageBgColor" => "",
- "componentBgColor" => "",
- "componentAngle" => "round",
- "topAroundRadius" => 10,
- "bottomAroundRadius" => 10,
- "topElementAroundRadius" => 0,
- "bottomElementAroundRadius" => 0,
- "margin" => [
- "top" => 12,
- "bottom" => 12,
- "both" => 12
- ]
- ],
- [
- "id" => "113ohzka4n40",
- "mode" => "graphic",
- "type" => "img",
- "showStyle" => "fixed",
- "ornament" => [
- "type" => "default",
- "color" => "#EDEDED"
- ],
- "rowCount" => 5,
- "pageCount" => 2,
- "carousel" => [
- "type" => "circle",
- "color" => "#FFFFFF"
- ],
- "imageSize" => 40,
- "aroundRadius" => 25,
- "font" => [
- "size" => 14,
- "weight" => 'normal',
- "color" => "#303133"
- ],
- "list" => [
- [
- "title" => "团购",
- "icon" => "icondiy icon-system-groupbuy-nav",
- "imageUrl" => "",
- "iconType" => "icon",
- "style" => [
- "fontSize" => 50,
- "iconBgColor" => [
- "#FF9F3E",
- "#FF4116"
- ],
- "iconBgColorDeg" => 90,
- "iconBgImg" => "public/static/ext/diyview/img/icon_bg/bg_06.png",
- "bgRadius" => 50,
- "iconColor" => [
- "#FFFFFF"
- ],
- "iconColorDeg" => 0
- ],
- "link" => [
- "name" => "GROUPBUY_PREFECTURE",
- "title" => "团购专区",
- "wap_url" => "/pages_promotion/groupbuy/list",
- "parent" => "MARKETING_LINK"
- ],
- "label" => [
- "control" => false,
- "text" => "热门",
- "textColor" => "#FFFFFF",
- "bgColorStart" => "#F83287",
- "bgColorEnd" => "#FE3423"
- ],
- "id" => "ycafod7gfgg0"
- ],
- [
- "title" => "拼团",
- "icon" => "icondiy icon-system-pintuan-nav",
- "imageUrl" => "",
- "iconType" => "icon",
- "style" => [
- "fontSize" => 50,
- "iconBgColor" => [
- "#58BCFF",
- "#1379FF"
- ],
- "iconBgColorDeg" => 90,
- "iconBgImg" => "public/static/ext/diyview/img/icon_bg/bg_06.png",
- "bgRadius" => 50,
- "iconColor" => [
- "#FFFFFF"
- ],
- "iconColorDeg" => 0
- ],
- "link" => [
- "name" => "PINTUAN_PREFECTURE",
- "title" => "拼团专区",
- "wap_url" => "/pages_promotion/pintuan/list",
- "parent" => "MARKETING_LINK"
- ],
- "label" => [
- "control" => false,
- "text" => "热门",
- "textColor" => "#FFFFFF",
- "bgColorStart" => "#F83287",
- "bgColorEnd" => "#FE3423"
- ],
- "id" => "wnlf5ak6u8g0"
- ],
- [
- "title" => "秒杀",
- "icon" => "icondiy icon-system-seckill-time",
- "imageUrl" => "",
- "iconType" => "icon",
- "style" => [
- "fontSize" => 50,
- "iconBgColor" => [
- "#FFCC26",
- "#FF9F29"
- ],
- "iconBgColorDeg" => 90,
- "iconBgImg" => "public/static/ext/diyview/img/icon_bg/bg_06.png",
- "bgRadius" => 50,
- "iconColor" => [
- "#FFFFFF"
- ],
- "iconColorDeg" => 0
- ],
- "link" => [
- "name" => "SECKILL_PREFECTURE",
- "title" => "秒杀专区",
- "wap_url" => "/pages_promotion/seckill/list",
- "parent" => "MARKETING_LINK"
- ],
- "label" => [
- "control" => true,
- "text" => "热门",
- "textColor" => "#FFFFFF",
- "bgColorStart" => "#F83288",
- "bgColorEnd" => "#FE3523"
- ],
- "id" => "lpg2grtvmxo0"
- ],
- [
- "title" => " 积分",
- "icon" => "icondiy icon-system-point-nav",
- "imageUrl" => "",
- "iconType" => "icon",
- "style" => [
- "fontSize" => 50,
- "iconBgColor" => [
- "#02CC96",
- "#43EEC9"
- ],
- "iconBgColorDeg" => 90,
- "iconBgImg" => "public/static/ext/diyview/img/icon_bg/bg_06.png",
- "bgRadius" => 50,
- "iconColor" => [
- "#FFFFFF"
- ],
- "iconColorDeg" => 0
- ],
- "link" => [
- "name" => "INTEGRAL_STORE",
- "title" => "积分商城",
- "wap_url" => "/pages_promotion/point/list",
- "parent" => "MARKETING_LINK"
- ],
- "label" => [
- "control" => false,
- "text" => "热门",
- "textColor" => "#FFFFFF",
- "bgColorStart" => "#F83287",
- "bgColorEnd" => "#FE3423"
- ],
- "id" => "1jfs721gome8"
- ],
- [
- "title" => "专题活动",
- "icon" => "icondiy icon-system-topic-nav",
- "imageUrl" => "",
- "iconType" => "icon",
- "style" => [
- "fontSize" => 50,
- "iconBgColor" => [
- "#BE79FF",
- "#7B00FF"
- ],
- "iconBgColorDeg" => 0,
- "iconBgImg" => "public/static/ext/diyview/img/icon_bg/bg_06.png",
- "bgRadius" => 50,
- "iconColor" => [
- "#FFFFFF"
- ],
- "iconColorDeg" => 0
- ],
- "link" => [
- "name" => "THEMATIC_ACTIVITIES_LIST",
- "title" => "专题活动列表",
- "wap_url" => "/pages_promotion/topics/list",
- "parent" => "MARKETING_LINK"
- ],
- "label" => [
- "control" => false,
- "text" => "热门",
- "textColor" => "#FFFFFF",
- "bgColorStart" => "#F83287",
- "bgColorEnd" => "#FE3423"
- ],
- "id" => "1grejh3c8fwg0"
- ],
- [
- "title" => "砍价",
- "icon" => "icondiy icon-system-bargain-nav",
- "imageUrl" => "",
- "iconType" => "icon",
- "style" => [
- "fontSize" => 50,
- "iconBgColor" => [
- "#5BBDFF",
- "#2E87FD"
- ],
- "iconBgColorDeg" => 90,
- "iconBgImg" => "public/static/ext/diyview/img/icon_bg/bg_06.png",
- "bgRadius" => 50,
- "iconColor" => [
- "#FFFFFF"
- ],
- "iconColorDeg" => 0
- ],
- "link" => [
- "name" => "BARGAIN_PREFECTURE",
- "title" => "砍价专区",
- "wap_url" => "/pages_promotion/bargain/list",
- "parent" => "MARKETING_LINK"
- ],
- "label" => [
- "control" => false,
- "text" => "热门",
- "textColor" => "#FFFFFF",
- "bgColorStart" => "#F83287",
- "bgColorEnd" => "#FE3423"
- ],
- "id" => "ycpsnfbaf800"
- ],
- [
- "title" => "领券",
- "icon" => "icondiy icon-system-get-coupon",
- "imageUrl" => "",
- "iconType" => "icon",
- "style" => [
- "fontSize" => 50,
- "iconBgColor" => [
- "#BE79FF",
- "#7B00FF"
- ],
- "iconBgColorDeg" => 90,
- "iconBgImg" => "public/static/ext/diyview/img/icon_bg/bg_06.png",
- "bgRadius" => 50,
- "iconColor" => [
- "#FFFFFF"
- ],
- "iconColorDeg" => 0
- ],
- "link" => [
- "name" => "COUPON_PREFECTURE",
- "title" => "优惠券专区",
- "wap_url" => "/pages_tool/goods/coupon",
- "parent" => "MARKETING_LINK"
- ],
- "label" => [
- "control" => false,
- "text" => "热门",
- "textColor" => "#FFFFFF",
- "bgColorStart" => "#F83287",
- "bgColorEnd" => "#FE3423"
- ],
- "id" => "17dcs7xstz400"
- ],
- [
- "title" => "文章",
- "icon" => "icondiy icon-system-article-nav",
- "imageUrl" => "",
- "iconType" => "icon",
- "style" => [
- "fontSize" => 50,
- "iconBgColor" => [
- "#FF8052",
- "#FF4830"
- ],
- "iconBgColorDeg" => 0,
- "iconBgImg" => "public/static/ext/diyview/img/icon_bg/bg_06.png",
- "bgRadius" => 50,
- "iconColor" => [
- "#FFFFFF"
- ],
- "iconColorDeg" => 0
- ],
- "link" => [
- "name" => "SHOPPING_ARTICLE",
- "title" => "文章",
- "wap_url" => "/pages_tool/article/list",
- "parent" => "MALL_LINK"
- ],
- "label" => [
- "control" => false,
- "text" => "热门",
- "textColor" => "#FFFFFF",
- "bgColorStart" => "#F83287",
- "bgColorEnd" => "#FE3423"
- ],
- "id" => "hg8450mb0hc0"
- ],
- [
- "title" => "公告",
- "icon" => "icondiy icon-system-notice-nav",
- "imageUrl" => "",
- "iconType" => "icon",
- "style" => [
- "fontSize" => 50,
- "iconBgColor" => [
- "#FFCC26",
- "#FF9F29"
- ],
- "iconBgColorDeg" => 90,
- "iconBgImg" => "public/static/ext/diyview/img/icon_bg/bg_06.png",
- "bgRadius" => 50,
- "iconColor" => [
- "#FFFFFF"
- ],
- "iconColorDeg" => 0
- ],
- "link" => [
- "name" => "SHOPPING_NOTICE",
- "title" => "公告",
- "wap_url" => "/pages_tool/notice/list",
- "parent" => "MALL_LINK"
- ],
- "label" => [
- "control" => false,
- "text" => "热门",
- "textColor" => "#FFFFFF",
- "bgColorStart" => "#F83287",
- "bgColorEnd" => "#FE3423"
- ],
- "id" => "1cg964qu9f9c0"
- ],
- [
- "title" => "帮助",
- "icon" => "icondiy icon-system-help",
- "imageUrl" => "",
- "iconType" => "icon",
- "style" => [
- "fontSize" => 50,
- "iconBgColor" => [
- "#02CC96",
- "#43EEC9"
- ],
- "iconBgColorDeg" => 90,
- "iconBgImg" => "public/static/ext/diyview/img/icon_bg/bg_06.png",
- "bgRadius" => 50,
- "iconColor" => [
- "#FFFFFF"
- ],
- "iconColorDeg" => 0
- ],
- "link" => [
- "name" => "SHOPPING_HELP",
- "title" => "帮助",
- "wap_url" => "/pages_tool/help/list",
- "parent" => "MALL_LINK"
- ],
- "label" => [
- "control" => false,
- "text" => "热门",
- "textColor" => "#FFFFFF",
- "bgColorStart" => "#F83287",
- "bgColorEnd" => "#FE3423"
- ],
- "id" => "1v4budp7jav40"
- ]
- ],
- 'addonName' => '',
- "componentName" => "GraphicNav",
- "componentTitle" => "图文导航",
- "isDelete" => 0,
- "pageBgColor" => "",
- "componentBgColor" => "#FFFFFF",
- "componentAngle" => "round",
- "topAroundRadius" => 10,
- "bottomAroundRadius" => 10,
- "topElementAroundRadius" => 0,
- "bottomElementAroundRadius" => 0,
- "margin" => [
- "top" => 0,
- "bottom" => 12,
- "both" => 12
- ]
- ],
- [
- "id" => "3tegcfvyijk0",
- "list" => [
- [
- "link" => [
- "name" => ""
- ],
- "imageUrl" => 'addon/diy_default1/shop/view/public/img/mf_left.png',
- "imgWidth" => "338",
- "imgHeight" => "450",
- "previewWidth" => 187.5,
- "previewHeight" => "249.63px"
- ],
- [
- "imageUrl" => 'addon/diy_default1/shop/view/public/img/mf_right1.png',
- "link" => [
- "name" => ""
- ],
- "imgWidth" => "354",
- "imgHeight" => "220",
- "previewWidth" => 187.5,
- "previewHeight" => "124.82px",
- ],
- [
- "imageUrl" => 'addon/diy_default1/shop/view/public/img/mf_right2.png',
- "imgWidth" => "354",
- "imgHeight" => "220",
- "previewWidth" => 187.5,
- "previewHeight" => "124.82px",
- "link" => [
- "name" => ""
- ]
- ]
- ],
- "mode" => "row1-lt-of2-rt",
- "imageGap" => 10,
- 'addonName' => '',
- "componentName" => "RubikCube",
- "componentTitle" => "魔方",
- "isDelete" => 0,
- "pageBgColor" => "",
- "componentBgColor" => "",
- "componentAngle" => "round",
- "topAroundRadius" => 10,
- "bottomAroundRadius" => 10,
- "elementAngle" => "round",
- "topElementAroundRadius" => 0,
- "bottomElementAroundRadius" => 0,
- "margin" => [
- "top" => 0,
- "bottom" => 12,
- "both" => 12
- ]
- ],
- [
- "id" => "3acr0xjm1c80",
- "style" => "style-16",
- "subTitle" => [
- "fontSize" => 14,
- "text" => "超级优惠",
- "isElementShow" => true,
- "color" => "#FFFFFF",
- "bgColor" => "#FF9F29",
- "icon" => "icondiy icon-system-coupon",
- "fontWeight" => 'bold'
- ],
- "link" => [
- "name" => "COUPON_PREFECTURE",
- "title" => "优惠券专区",
- "wap_url" => "/pages_tool/goods/coupon",
- "parent" => "MARKETING_LINK"
- ],
- "fontSize" => 16,
- "styleName" => "风格16",
- "fontWeight" => 'bold',
- "more" => [
- "text" => "",
- "link" => [
- "name" => "COUPON_PREFECTURE",
- "title" => "优惠券专区",
- "wap_url" => "/pages_tool/goods/coupon",
- "parent" => "MARKETING_LINK"
- ],
- "isShow" => true,
- "isElementShow" => true,
- "color" => "#999999"
- ],
- "text" => "优惠专区",
- 'addonName' => '',
- "componentName" => "Text",
- "componentTitle" => "标题",
- "isDelete" => 0,
- "pageBgColor" => "",
- "textColor" => "#303133",
- "componentBgColor" => "#FFFFFF",
- "componentAngle" => "round",
- "topAroundRadius" => 10,
- "bottomAroundRadius" => 0,
- "topElementAroundRadius" => 0,
- "bottomElementAroundRadius" => 0,
- "margin" => [
- "top" => 0,
- "bottom" => 0,
- "both" => 12
- ]
- ],
- [
- "id" => "2parw5r2qq00",
- "style" => "6",
- "sources" => "initial",
- "styleName" => "风格六",
- "couponIds" => [],
- "count" => 6,
- "previewList" => [],
- "nameColor" => "#303133",
- "moneyColor" => "#FF0000",
- "limitColor" => "#303133",
- "btnStyle" => [
- "textColor" => "#FFFFFF",
- "bgColor" => "#303133",
- "text" => "领取",
- "aroundRadius" => 20,
- "isBgColor" => true,
- "isAroundRadius" => true
- ],
- "bgColor" => "",
- "isName" => true,
- "couponBgColor" => "#FFFFFF",
- "couponBgUrl" => "",
- "couponType" => "color",
- "ifNeedBg" => true,
- 'addonName' => 'coupon',
- "componentName" => "Coupon",
- "componentTitle" => "优惠券",
- "isDelete" => 0,
- "pageBgColor" => "",
- "topAroundRadius" => 0,
- "bottomAroundRadius" => 0,
- "elementBgColor" => "",
- "topElementAroundRadius" => 0,
- "bottomElementAroundRadius" => 0,
- "margin" => [
- "top" => 0,
- "bottom" => 0,
- "both" => 12
- ]
- ],
- [
- "id" => "68p4o1plca80",
- "height" => 10,
- 'addonName' => '',
- "componentName" => "HorzBlank",
- "componentTitle" => "辅助空白",
- "isDelete" => 0,
- "pageBgColor" => "",
- "componentBgColor" => "#FFFFFF",
- "componentAngle" => "round",
- "topAroundRadius" => 0,
- "bottomAroundRadius" => 0,
- "topElementAroundRadius" => 0,
- "bottomElementAroundRadius" => 0,
- "margin" => [
- "top" => 0,
- "bottom" => 10,
- "both" => 12
- ]
- ],
- [
- "id" => "3moj09pl5c20",
- "style" => "style-1",
- "sources" => "initial",
- "count" => 6,
- "goodsId" => [],
- "ornament" => [
- "type" => "default",
- "color" => "#EDEDED"
- ],
- "nameLineMode" => "single",
- "template" => "row1-of1",
- "goodsMarginType" => "default",
- "goodsMarginNum" => 10,
- "btnStyle" => [
- "text" => "去秒杀",
- "textColor" => "#FFFFFF",
- "theme" => "default",
- "aroundRadius" => 25,
- "control" => true,
- "support" => true,
- "bgColorStart" => "#FF7B1D",
- "bgColorEnd" => "#FF1544"
- ],
- "imgAroundRadius" => 10,
- "saleStyle" => [
- "color" => "#999CA7",
- "control" => true,
- "support" => true
- ],
- "progressStyle" => [
- "control" => true,
- "support" => true,
- "currColor" => "#FDBE6C",
- "bgColor" => "#FCECD7"
- ],
- "titleStyle" => [
- "backgroundImage" => "addon/seckill/component/view/seckill/img/style_title_3_bg.png",
- "isShow" => true,
- "leftStyle" => "img",
- "leftImg" => "addon/seckill/component/view/seckill/img/style_title_3_name.png",
- "style" => "style-3",
- "styleName" => "风格3",
- "leftText" => "限时秒杀",
- "fontSize" => 16,
- "fontWeight" => true,
- "textColor" => "#FFFFFF",
- "bgColorStart" => "#FA6400",
- "bgColorEnd" => "#FF287A",
- "more" => "更多",
- "moreColor" => "#FFFFFF",
- "moreFontSize" => 12,
- "moreSupport" => true,
- "timeBgColor" => "",
- "timeImageUrl" => "",
- "colonColor" => "#FFFFFF",
- "numBgColorStart" => "#FFFFFF",
- "numBgColorEnd" => "#FFFFFF",
- "numTextColor" => "#FD3B54"
- ],
- "slideMode" => "scroll",
- "theme" => "default",
- "priceStyle" => [
- "mainColor" => "#FF1745",
- "mainControl" => true,
- "lineColor" => "#999CA7",
- "lineControl" => true,
- "lineSupport" => true
- ],
- "goodsNameStyle" => [
- "color" => "#303133",
- "control" => true,
- "fontWeight" => false
- ],
- 'addonName' => 'seckill',
- "componentName" => "Seckill",
- "componentTitle" => "秒杀",
- "isDelete" => 0,
- "pageBgColor" => "",
- "componentBgColor" => "",
- "componentAngle" => "round",
- "topAroundRadius" => 10,
- "bottomAroundRadius" => 10,
- "elementBgColor" => "#FFFFFF",
- "elementAngle" => "round",
- "topElementAroundRadius" => 0,
- "bottomElementAroundRadius" => 0,
- "margin" => [
- "top" => 0,
- "bottom" => 12,
- "both" => 12
- ]
- ],
- [
- "id" => "z9bdab3tm34",
- "style" => "style-1",
- "sources" => "initial",
- "count" => 6,
- "goodsId" => [],
- "ornament" => [
- "type" => "default",
- "color" => "#EDEDED"
- ],
- "nameLineMode" => "single",
- "template" => "horizontal-slide",
- "goodsMarginType" => "default",
- "goodsMarginNum" => 10,
- "btnStyle" => [
- "text" => "去拼团",
- "textColor" => "#FFFFFF",
- "theme" => "default",
- "aroundRadius" => 25,
- "control" => false,
- "support" => false,
- "bgColorStart" => "#FF1544",
- "bgColorEnd" => "#FF1544"
- ],
- "imgAroundRadius" => 10,
- "saleStyle" => [
- "color" => "#FF1544",
- "control" => false,
- "support" => false
- ],
- "groupStyle" => [
- "color" => "#FFFFFF",
- "control" => true,
- "support" => true,
- "bgColorStart" => "#FA2379",
- "bgColorEnd" => "#FF4F61"
- ],
- "priceStyle" => [
- "mainColor" => "#FF1544",
- "mainControl" => true,
- "lineColor" => "#999CA7",
- "lineControl" => true,
- "lineSupport" => true
- ],
- "slideMode" => "scroll",
- "theme" => "default",
- "goodsNameStyle" => [
- "color" => "#303133",
- "control" => true,
- "fontWeight" => false
- ],
- "titleStyle" => [
- "bgColorStart" => "#6236FF",
- "bgColorEnd" => "#0091FF",
- "isShow" => true,
- "leftStyle" => "img",
- "leftImg" => "addon/pintuan/component/view/pintuan/img/horizontal_slide_name.png",
- "style" => "style-1",
- "styleName" => "风格1",
- "leftText" => "超值拼团",
- "fontSize" => 16,
- "fontWeight" => true,
- "textColor" => "#FFFFFF",
- "more" => "查看更多",
- "moreColor" => "#FFFFFF",
- "moreFontSize" => 12,
- "backgroundImage" => "addon/pintuan/component/view/pintuan/img/horizontal_slide_bg.png"
- ],
- 'addonName' => 'pintuan',
- "componentName" => "Pintuan",
- "componentTitle" => "拼团",
- "isDelete" => 0,
- "pageBgColor" => "",
- "componentBgColor" => "#FFFFFF",
- "componentAngle" => "round",
- "topAroundRadius" => 0,
- "bottomAroundRadius" => 10,
- "elementBgColor" => "",
- "elementAngle" => "round",
- "topElementAroundRadius" => 0,
- "bottomElementAroundRadius" => 0,
- "margin" => [
- "top" => 0,
- "bottom" => 12,
- "both" => 12
- ]
- ],
- [
- "id" => "xwdnfttfj7k",
- "style" => "style-1",
- "sources" => "initial",
- "count" => 6,
- "goodsId" => [],
- "ornament" => [
- "type" => "default",
- "color" => "#EDEDED"
- ],
- "nameLineMode" => "single",
- "template" => "horizontal-slide",
- "goodsMarginType" => "default",
- "goodsMarginNum" => 10,
- "btnStyle" => [
- "text" => "立即抢购",
- "textColor" => "#FFFFFF",
- "theme" => "default",
- "aroundRadius" => 25,
- "control" => false,
- "support" => false,
- "bgColorStart" => "#FF7B1D",
- "bgColorEnd" => "#FF1544"
- ],
- "imgAroundRadius" => 5,
- "saleStyle" => [
- "color" => "#FFFFFF",
- "control" => true,
- "support" => true
- ],
- "slideMode" => "scroll",
- "theme" => "default",
- "goodsNameStyle" => [
- "color" => "#303133",
- "control" => true,
- "fontWeight" => false
- ],
- "priceStyle" => [
- "mainColor" => "#FF1745",
- "mainControl" => true,
- "lineColor" => "#999CA7",
- "lineControl" => true,
- "lineSupport" => true
- ],
- "titleStyle" => [
- "bgColorStart" => "#FF209D",
- "bgColorEnd" => "#B620E0",
- "isShow" => true,
- "leftStyle" => "img",
- "leftImg" => "",
- "style" => "style-1",
- "styleName" => "风格1",
- "leftText" => "疯狂砍价",
- "fontSize" => 16,
- "fontWeight" => true,
- "textColor" => "#FFFFFF",
- "more" => "更多",
- "moreColor" => "#FFFFFF",
- "moreFontSize" => 12,
- "backgroundImage" => ""
- ],
- 'addonName' => 'bargain',
- "componentName" => "Bargain",
- "componentTitle" => "砍价",
- "isDelete" => 0,
- "pageBgColor" => "",
- "componentBgColor" => "#FFFFFF",
- "componentAngle" => "round",
- "topAroundRadius" => 0,
- "bottomAroundRadius" => 10,
- "elementBgColor" => "",
- "elementAngle" => "round",
- "topElementAroundRadius" => 0,
- "bottomElementAroundRadius" => 0,
- "margin" => [
- "top" => 0,
- "bottom" => 12,
- "both" => 12
- ]
- ],
- [
- "id" => "29fhippqsrgg",
- "list" => [
- [
- "link" => [
- "name" => ""
- ],
- "imageUrl" => 'addon/diy_default1/shop/view/public/img/gg.png',
- "imgWidth" => "702",
- "imgHeight" => "252",
- "id" => "1z94aaav9klc0"
- ]
- ],
- "indicatorIsShow" => true,
- "indicatorColor" => "#ffffff",
- "carouselStyle" => "circle",
- "indicatorLocation" => "center",
- 'addonName' => '',
- "componentName" => "ImageAds",
- "componentTitle" => "图片广告",
- "isDelete" => 0,
- "pageBgColor" => "",
- "componentBgColor" => "",
- "componentAngle" => "round",
- "topAroundRadius" => 10,
- "bottomAroundRadius" => 10,
- "topElementAroundRadius" => 0,
- "bottomElementAroundRadius" => 0,
- "margin" => [
- "top" => 0,
- "bottom" => 12,
- "both" => 12
- ]
- ],
- [
- "id" => "i4xirbfy0m8",
- "style" => "style-3",
- "sources" => "initial",
- "count" => 6,
- "goodsId" => [],
- "ornament" => [
- "type" => "default",
- "color" => "#EDEDED"
- ],
- "nameLineMode" => "multiple",
- "template" => "row1-of2",
- "goodsMarginType" => "default",
- "goodsMarginNum" => 6,
- "btnStyle" => [
- "fontWeight" => false,
- "padding" => 0,
- "cartEvent" => "detail",
- "text" => "购买",
- "textColor" => "#FFFFFF",
- "theme" => "default",
- "aroundRadius" => 25,
- "control" => false,
- "support" => false,
- "bgColor" => "#FF6A00",
- "style" => "button",
- "iconDiy" => [
- "iconType" => "icon",
- "icon" => "",
- "style" => [
- "fontSize" => "60",
- "iconBgColor" => [],
- "iconBgColorDeg" => 0,
- "iconBgImg" => "",
- "bgRadius" => 0,
- "iconColor" => [
- "#000000"
- ],
- "iconColorDeg" => 0
- ]
- ]
- ],
- "categoryId" => 0,
- "categoryName" => "请选择",
- "sortWay" => "default",
- "tag" => [
- "text" => "隐藏",
- "value" => "hidden"
- ],
- "imgAroundRadius" => 0,
- "slideMode" => "scroll",
- "goodsNameStyle" => [
- "color" => "#303133",
- "control" => true,
- "fontWeight" => false
- ],
- "saleStyle" => [
- "color" => "#999CA7",
- "control" => true,
- "support" => true
- ],
- "theme" => "default",
- "priceStyle" => [
- "mainColor" => "#FF6A00",
- "mainControl" => true,
- "lineColor" => "#999CA7",
- "lineControl" => false,
- "lineSupport" => false
- ],
- 'addonName' => '',
- "componentName" => "GoodsList",
- "componentTitle" => "商品列表",
- "isDelete" => 0,
- "pageBgColor" => "",
- "componentBgColor" => "",
- "componentAngle" => "round",
- "topAroundRadius" => 0,
- "bottomAroundRadius" => 0,
- "elementBgColor" => "#FFFFFF",
- "elementAngle" => "round",
- "topElementAroundRadius" => 10,
- "bottomElementAroundRadius" => 0,
- "margin" => [
- "top" => 0,
- "bottom" => 10,
- "both" => 12
- ]
- ]
- ]
- ]
- ],
- [
- 'title' => '商品分类',
- 'name' => "DIY_VIEW_GOODS_CATEGORY",
- 'value' => [
- "global" => [
- "title" => "商品分类",
- "pageBgColor" => "#FFFFFF",
- "topNavColor" => "#FFFFFF",
- "topNavBg" => false,
- "navBarSwitch" => true,
- "textNavColor" => "#333333",
- "topNavImg" => "",
- "moreLink" => [
- "name" => ""
- ],
- "openBottomNav" => true,
- "navStyle" => 1,
- "textImgPosLink" => "left",
- "mpCollect" => false,
- "popWindow" => [
- "imageUrl" => "",
- "count" => -1,
- "show" => 0,
- "link" => [
- "name" => ""
- ],
- "imgWidth" => "",
- "imgHeight" => ""
- ],
- "bgUrl" => "",
- "imgWidth" => "",
- "imgHeight" => "",
- "template" => [
- "pageBgColor" => "",
- "textColor" => "#303133",
- "componentBgColor" => "",
- "componentAngle" => "round",
- "topAroundRadius" => 0,
- "bottomAroundRadius" => 0,
- "elementBgColor" => "",
- "elementAngle" => "round",
- "topElementAroundRadius" => 0,
- "bottomElementAroundRadius" => 0,
- "margin" => [
- "top" => 0,
- "bottom" => 0,
- "both" => 0
- ]
- ]
- ],
- "value" => [
- [
- "level" => "2",
- "template" => "2",
- "quickBuy" => 1,
- "search" => 1,
- 'addonName' => '',
- "componentName" => "GoodsCategory",
- "componentTitle" => "商品分类",
- "isDelete" => 1,
- "topAroundRadius" => 0,
- "bottomAroundRadius" => 0,
- "topElementAroundRadius" => 0,
- "bottomElementAroundRadius" => 0,
- "margin" => [],
- "goodsLevel" => 1,
- "loadType" => "part"
- ]
- ]
- ]
- ],
- [
- 'title' => '会员中心',
- 'name' => "DIY_VIEW_MEMBER_INDEX",
- 'value' => [
- "global" => [
- "title" => "会员中心",
- "pageBgColor" => "#F8F8F8",
- "topNavColor" => "#FFFFFF",
- "topNavBg" => true,
- "navBarSwitch" => true,
- "textNavColor" => "#333333",
- "topNavImg" => "",
- "moreLink" => [
- "name" => ""
- ],
- "openBottomNav" => true,
- "navStyle" => 1,
- "textImgPosLink" => "center",
- "mpCollect" => false,
- "popWindow" => [
- "imageUrl" => "",
- "count" => -1,
- "show" => 0,
- "link" => [
- "name" => ""
- ],
- "imgWidth" => "",
- "imgHeight" => ""
- ],
- "bgUrl" => "",
- "imgWidth" => "",
- "imgHeight" => "",
- "template" => [
- "pageBgColor" => "",
- "textColor" => "#303133",
- "componentBgColor" => "",
- "componentAngle" => "round",
- "topAroundRadius" => 0,
- "bottomAroundRadius" => 0,
- "elementBgColor" => "",
- "elementAngle" => "round",
- "topElementAroundRadius" => 0,
- "bottomElementAroundRadius" => 0,
- "margin" => [
- "top" => 0,
- "bottom" => 0,
- "both" => 0
- ]
- ]
- ],
- "value" => [
- [
- "style" => 4,
- "theme" => "default",
- "bgColorStart" => "#FF7230",
- "bgColorEnd" => "#FF1544",
- "gradientAngle" => "129",
- "infoMargin" => 15,
- "id" => "1tkaoxbhavj4",
- 'addonName' => '',
- "componentName" => "MemberInfo",
- "componentTitle" => "会员信息",
- "isDelete" => 0,
- "pageBgColor" => "",
- "textColor" => "#303133",
- "componentBgColor" => "",
- "componentAngle" => "round",
- "topAroundRadius" => 0,
- "bottomAroundRadius" => 0,
- "elementBgColor" => "",
- "elementAngle" => "round",
- "topElementAroundRadius" => 0,
- "bottomElementAroundRadius" => 0,
- "margin" => [
- "top" => 0,
- "bottom" => 0,
- "both" => 0
- ]
- ],
- [
- "style" => "style-12",
- "styleName" => "风格12",
- "text" => "我的订单",
- "link" => [
- "name" => ""
- ],
- "fontSize" => 17,
- "fontWeight" => 'bold',
- "subTitle" => [
- "fontSize" => 14,
- "text" => "",
- "isElementShow" => true,
- "color" => "#999999",
- "bgColor" => "#303133"
- ],
- "more" => [
- "text" => "全部订单",
- "link" => [
- "name" => "ALL_ORDER",
- "title" => "全部订单",
- "wap_url" => "/pages/order/list",
- "parent" => "MALL_LINK"
- ],
- "isShow" => true,
- "isElementShow" => true,
- "color" => "#999999"
- ],
- "id" => "2txcvx3d5u6",
- 'addonName' => '',
- "componentName" => "Text",
- "componentTitle" => "标题",
- "isDelete" => 0,
- "pageBgColor" => "",
- "textColor" => "#303133",
- "componentBgColor" => "#FFFFFF",
- "componentAngle" => "round",
- "topAroundRadius" => 9,
- "bottomAroundRadius" => 0,
- "topElementAroundRadius" => 0,
- "bottomElementAroundRadius" => 0,
- "margin" => [
- "top" => 15,
- "bottom" => 0,
- "both" => 15
- ]
- ],
- [
- "color" => "#EEEEEE",
- "borderStyle" => "solid",
- "id" => "3hsh2st470e0",
- 'addonName' => '',
- "componentName" => "HorzLine",
- "componentTitle" => "辅助线",
- "isDelete" => 0,
- "pageBgColor" => "",
- "topAroundRadius" => 0,
- "bottomAroundRadius" => 0,
- "topElementAroundRadius" => 0,
- "bottomElementAroundRadius" => 0,
- "margin" => [
- "top" => 0,
- "bottom" => 0,
- "both" => 20
- ]
- ],
- [
- "icon" => [
- "waitPay" => [
- "title" => "待付款",
- "icon" => "icondiy icon-system-daifukuan2",
- "style" => [
- "bgRadius" => 0,
- "fontSize" => 65,
- "iconBgColor" => [],
- "iconBgColorDeg" => 0,
- "iconBgImg" => "",
- "iconColor" => [
- "#ffa3a3",
- "#FF4646"
- ],
- "iconColorDeg" => 0
- ]
- ],
- "waitSend" => [
- "title" => "待发货",
- "icon" => "icondiy icon-system-daifahuo2",
- "style" => [
- "bgRadius" => 0,
- "fontSize" => 65,
- "iconBgColor" => [],
- "iconBgColorDeg" => 0,
- "iconBgImg" => "",
- "iconColor" => [
- "#ffa3a3",
- "#FF4646"
- ],
- "iconColorDeg" => 0
- ]
- ],
- "waitConfirm" => [
- "title" => "待收货",
- "icon" => "icondiy icon-system-daishouhuo2",
- "style" => [
- "bgRadius" => 0,
- "fontSize" => 65,
- "iconBgColor" => [],
- "iconBgColorDeg" => 0,
- "iconBgImg" => "",
- "iconColor" => [
- "#ffa3a3",
- "#FF4646"
- ],
- "iconColorDeg" => 0
- ]
- ],
- "waitUse" => [
- "title" => "待使用",
- "icon" => "icondiy icon-system-daishiyong2",
- "style" => [
- "bgRadius" => 0,
- "fontSize" => 65,
- "iconBgColor" => [],
- "iconBgColorDeg" => 0,
- "iconBgImg" => "",
- "iconColor" => [
- "#ffa3a3",
- "#FF4646"
- ],
- "iconColorDeg" => 0
- ]
- ],
- "refunding" => [
- "title" => "售后",
- "icon" => "icondiy icon-system-shuhou2",
- "style" => [
- "bgRadius" => 0,
- "fontSize" => 65,
- "iconBgColor" => [],
- "iconBgColorDeg" => 0,
- "iconBgImg" => "",
- "iconColor" => [
- "#ffa3a3",
- "#FF4646"
- ],
- "iconColorDeg" => 0
- ]
- ]
- ],
- "style" => 1,
- "id" => "51h05xpcanw0",
- 'addonName' => '',
- "componentName" => "MemberMyOrder",
- "componentTitle" => "我的订单",
- "isDelete" => 0,
- "pageBgColor" => "",
- "textColor" => "#303133",
- "componentBgColor" => "#FFFFFF",
- "componentAngle" => "round",
- "topAroundRadius" => 0,
- "bottomAroundRadius" => 9,
- "elementBgColor" => "",
- "elementAngle" => "round",
- "topElementAroundRadius" => 0,
- "bottomElementAroundRadius" => 0,
- "margin" => [
- "top" => 0,
- "bottom" => 0,
- "both" => 15
- ]
- ],
- [
- "style" => "style-12",
- "styleName" => "风格12",
- "text" => "常用工具",
- "link" => [
- "name" => ""
- ],
- "fontSize" => 17,
- "fontWeight" => 'bold',
- "subTitle" => [
- "fontSize" => 14,
- "text" => "",
- "isElementShow" => true,
- "color" => "#999999",
- "bgColor" => "#303133"
- ],
- "more" => [
- "text" => "",
- "link" => [
- "name" => ""
- ],
- "isShow" => 0,
- "isElementShow" => true,
- "color" => "#999999"
- ],
- "id" => "405rb6vv3rq0",
- 'addonName' => '',
- "componentName" => "Text",
- "componentTitle" => "标题",
- "isDelete" => 0,
- "pageBgColor" => "",
- "textColor" => "#303133",
- "componentBgColor" => "#FFFFFF",
- "componentAngle" => "round",
- "topAroundRadius" => 9,
- "bottomAroundRadius" => 0,
- "topElementAroundRadius" => 0,
- "bottomElementAroundRadius" => 0,
- "margin" => [
- "top" => 15,
- "bottom" => 0,
- "both" => 15
- ]
- ],
- [
- "mode" => "graphic",
- "type" => "img",
- "showStyle" => "fixed",
- "ornament" => [
- "type" => "default",
- "color" => "#EDEDED"
- ],
- "rowCount" => 4,
- "pageCount" => 2,
- "carousel" => [
- "type" => "circle",
- "color" => "#FFFFFF"
- ],
- "imageSize" => 30,
- "aroundRadius" => 0,
- "font" => [
- "size" => 13,
- "weight" => 'normal',
- "color" => "#303133"
- ],
- "list" => [
- [
- "title" => "个人资料",
- "imageUrl" => "public/uniapp/member/index/menu/default_person.png",
- "iconType" => "img",
- "style" => [
- "fontSize" => "60",
- "iconBgColor" => [],
- "iconBgColorDeg" => 0,
- "iconBgImg" => "",
- "bgRadius" => 0,
- "iconColor" => [
- "#000000"
- ],
- "iconColorDeg" => 0
- ],
- "link" => [
- "name" => "MEMBER_INFO",
- "title" => "个人资料",
- "wap_url" => "/pages_tool/member/info",
- "parent" => "MALL_LINK"
- ],
- "label" => [
- "control" => false,
- "text" => "热门",
- "textColor" => "#FFFFFF",
- "bgColorStart" => "#F83287",
- "bgColorEnd" => "#FE3423"
- ],
- "icon" => "",
- "id" => "10rhv0x6phhc0"
- ],
- [
- "title" => "收货地址",
- "imageUrl" => "public/uniapp/member/index/menu/default_address.png",
- "iconType" => "img",
- "style" => [
- "fontSize" => "60",
- "iconBgColor" => [],
- "iconBgColorDeg" => 0,
- "iconBgImg" => "",
- "bgRadius" => 0,
- "iconColor" => [
- "#000000"
- ],
- "iconColorDeg" => 0
- ],
- "link" => [
- "name" => "SHIPPING_ADDRESS",
- "title" => "收货地址",
- "wap_url" => "/pages_tool/member/address",
- "parent" => "MALL_LINK"
- ],
- "label" => [
- "control" => false,
- "text" => "热门",
- "textColor" => "#FFFFFF",
- "bgColorStart" => "#F83287",
- "bgColorEnd" => "#FE3423"
- ],
- "icon" => "",
- "id" => "1n8gycn6xqe80"
- ],
- [
- "title" => "我的关注",
- "imageUrl" => "public/uniapp/member/index/menu/default_like.png",
- "iconType" => "img",
- "style" => [
- "fontSize" => "60",
- "iconBgColor" => [],
- "iconBgColorDeg" => 0,
- "iconBgImg" => "",
- "bgRadius" => 0,
- "iconColor" => [
- "#000000"
- ],
- "iconColorDeg" => 0
- ],
- "link" => [
- "name" => "ATTENTION",
- "title" => "我的关注",
- "wap_url" => "/pages_tool/member/collection",
- "parent" => "MALL_LINK"
- ],
- "label" => [
- "control" => false,
- "text" => "热门",
- "textColor" => "#FFFFFF",
- "bgColorStart" => "#F83287",
- "bgColorEnd" => "#FE3423"
- ],
- "icon" => "",
- "id" => "cnamoch6cvk0"
- ],
- [
- "title" => "我的足迹",
- "imageUrl" => "public/uniapp/member/index/menu/default_toot.png",
- "iconType" => "img",
- "style" => [
- "fontSize" => "60",
- "iconBgColor" => [],
- "iconBgColorDeg" => 0,
- "iconBgImg" => "",
- "bgRadius" => 0,
- "iconColor" => [
- "#000000"
- ],
- "iconColorDeg" => 0
- ],
- "link" => [
- "name" => "FOOTPRINT",
- "title" => "我的足迹",
- "wap_url" => "/pages_tool/member/footprint",
- "parent" => "MALL_LINK"
- ],
- "label" => [
- "control" => false,
- "text" => "热门",
- "textColor" => "#FFFFFF",
- "bgColorStart" => "#F83287",
- "bgColorEnd" => "#FE3423"
- ],
- "icon" => "",
- "id" => "drf3hi3slo00"
- ],
- [
- "title" => "账户列表",
- "imageUrl" => "public/uniapp/member/index/menu/default_cash.png",
- "iconType" => "img",
- "style" => "",
- "link" => [
- "name" => "ACCOUNT",
- "title" => "账户列表",
- "wap_url" => "/pages_tool/member/account",
- "parent" => "MALL_LINK"
- ],
- "label" => [
- "control" => false,
- "text" => "热门",
- "textColor" => "#FFFFFF",
- "bgColorStart" => "#F83287",
- "bgColorEnd" => "#FE3423"
- ],
- "iconfont" => [
- "value" => "",
- "color" => ""
- ],
- "id" => "1l4axfhbayqo0"
- ],
- [
- "title" => "优惠券",
- "imageUrl" => "public/uniapp/member/index/menu/default_discount.png",
- "iconType" => "img",
- "style" => "",
- "link" => [
- "name" => "COUPON",
- "title" => "优惠券",
- "wap_url" => "/pages_tool/member/coupon",
- "parent" => "MALL_LINK"
- ],
- "label" => [
- "control" => false,
- "text" => "热门",
- "textColor" => "#FFFFFF",
- "bgColorStart" => "#F83287",
- "bgColorEnd" => "#FE3423"
- ],
- "iconfont" => [
- "value" => "",
- "color" => ""
- ],
- "id" => "1tnu0vihrnq80"
- ],
- [
- "title" => "签到",
- "imageUrl" => "public/uniapp/member/index/menu/default_sign.png",
- "iconType" => "img",
- "style" => "",
- "link" => [
- "name" => "SIGN_IN",
- "title" => "签到",
- "wap_url" => "/pages_tool/member/signin",
- "parent" => "MARKETING_LINK"
- ],
- "label" => [
- "control" => false,
- "text" => "热门",
- "textColor" => "#FFFFFF",
- "bgColorStart" => "#F83287",
- "bgColorEnd" => "#FE3423"
- ],
- "iconfont" => [
- "value" => "",
- "color" => ""
- ],
- "id" => "hodjcxowf8g0"
- ],
- [
- "title" => "我的拼单",
- "imageUrl" => "public/uniapp/member/index/menu/default_store.png",
- "iconType" => "img",
- "style" => "",
- "link" => [
- "name" => "MY_PINTUAN",
- "title" => "我的拼团",
- "wap_url" => "/pages_promotion/pintuan/my_spell",
- "parent" => "MARKETING_LINK"
- ],
- "label" => [
- "control" => false,
- "text" => "热门",
- "textColor" => "#FFFFFF",
- "bgColorStart" => "#F83287",
- "bgColorEnd" => "#FE3423"
- ],
- "iconfont" => [
- "value" => "",
- "color" => ""
- ],
- "id" => "uoarcfsleio0"
- ],
- [
- "title" => "积分兑换",
- "imageUrl" => "public/uniapp/member/index/menu/default_point_recond.png",
- "iconType" => "img",
- "style" => "",
- "link" => [
- "name" => "INTEGRAL_CONVERSION",
- "title" => "积分兑换",
- "wap_url" => "/pages_promotion/point/order_list",
- "parent" => "MARKETING_LINK"
- ],
- "label" => [
- "control" => false,
- "text" => "热门",
- "textColor" => "#FFFFFF",
- "bgColorStart" => "#F83287",
- "bgColorEnd" => "#FE3423"
- ],
- "iconfont" => [
- "value" => "",
- "color" => ""
- ],
- "id" => "rnyw8xo5rdc0"
- ],
- [
- "title" => "分销中心",
- "imageUrl" => "public/uniapp/member/index/menu/default_fenxiao.png",
- "iconType" => "img",
- "style" => "",
- "link" => [
- "name" => "DISTRIBUTION_CENTRE",
- "title" => "分销中心",
- "wap_url" => "/pages_promotion/fenxiao/index",
- "parent" => "MARKETING_LINK"
- ],
- "label" => [
- "control" => false,
- "text" => "热门",
- "textColor" => "#FFFFFF",
- "bgColorStart" => "#F83287",
- "bgColorEnd" => "#FE3423"
- ],
- "iconfont" => [
- "value" => "",
- "color" => ""
- ],
- "id" => "yevac1grnlc0"
- ],
- [
- "title" => "我的砍价",
- "imageUrl" => "public/uniapp/member/index/menu/default_bargain.png",
- "iconType" => "img",
- "style" => "",
- "link" => [
- "name" => "MY_BARGAIN",
- "title" => "我的砍价",
- "wap_url" => "/pages_promotion/bargain/my_bargain",
- "parent" => "MARKETING_LINK"
- ],
- "label" => [
- "control" => false,
- "text" => "热门",
- "textColor" => "#FFFFFF",
- "bgColorStart" => "#F83287",
- "bgColorEnd" => "#FE3423"
- ],
- "iconfont" => [
- "value" => "",
- "color" => ""
- ],
- "id" => "13uz22sbag000"
- ],
- [
- "title" => "邀请有礼",
- "imageUrl" => "public/uniapp/member/index/menu/default_memberrecommend.png",
- "iconType" => "img",
- "style" => "",
- "link" => [
- "name" => "MEMBER_RECOMMEND",
- "title" => "邀请有礼",
- "wap_url" => "/pages_tool/member/invite_friends",
- "parent" => "MARKETING_LINK"
- ],
- "label" => [
- "control" => false,
- "text" => "热门",
- "textColor" => "#FFFFFF",
- "bgColorStart" => "#F83287",
- "bgColorEnd" => "#FE3423"
- ],
- "iconfont" => [
- "value" => "",
- "color" => ""
- ],
- "id" => "1h34nmfisge80"
- ],
- [
- "title" => "我的预售",
- "imageUrl" => "public/uniapp/member/index/menu/my_presale.png",
- "iconType" => "img",
- "style" => "",
- "link" => [
- "name" => "PRESALE",
- "title" => "我的预售",
- "wap_url" => "/pages_promotion/presale/order_list",
- "parent" => "MARKETING_LINK"
- ],
- "label" => [
- "control" => false,
- "text" => "热门",
- "textColor" => "#FFFFFF",
- "bgColorStart" => "#F83287",
- "bgColorEnd" => "#FE3423"
- ],
- "iconfont" => [
- "value" => "",
- "color" => ""
- ],
- "id" => "1a3cqyziwqdc0"
- ],
- [
- "title" => "我的礼品卡",
- "imageUrl" => "public/uniapp/member/index/menu/my_giftcard.png",
- "iconType" => "img",
- "style" => "",
- "link" => [
- "name" => "GIFTCARD",
- "title" => "我的礼品卡",
- "wap_url" => "/pages_promotion/giftcard/member",
- "parent" => "MARKETING_LINK"
- ],
- "label" => [
- "control" => false,
- "text" => "热门",
- "textColor" => "#FFFFFF",
- "bgColorStart" => "#F83287",
- "bgColorEnd" => "#FE3423"
- ],
- "iconfont" => [
- "value" => "",
- "color" => ""
- ],
- "id" => "1es42rgg2mhs0"
- ],
- [
- "title" => "好友瓜分券",
- "imageUrl" => "public/uniapp/member/index/menu/my_divideticket.png",
- "iconType" => "img",
- "style" => "",
- "link" => [
- "name" => "DIVIDETICKET",
- "title" => "我的好友瓜分券",
- "wap_url" => "/pages_promotion/divideticket/my_guafen",
- "parent" => "MARKETING_LINK"
- ],
- "label" => [
- "control" => false,
- "text" => "热门",
- "textColor" => "#FFFFFF",
- "bgColorStart" => "#F83287",
- "bgColorEnd" => "#FE3423"
- ],
- "iconfont" => [
- "value" => "",
- "color" => ""
- ],
- "id" => "14rxg7u5yu2k0"
- ],
- [
- "title" => "拼团返利",
- "imageUrl" => "public/uniapp/member/index/menu/my_pinfan.png",
- "iconType" => "img",
- "style" => "",
- "link" => [
- "name" => "PINFAN",
- "title" => "我的拼团返利",
- "wap_url" => "/pages_promotion/pinfan/my_rebate",
- "parent" => "MARKETING_LINK"
- ],
- "label" => [
- "control" => false,
- "text" => "热门",
- "textColor" => "#FFFFFF",
- "bgColorStart" => "#F83287",
- "bgColorEnd" => "#FE3423"
- ],
- "iconfont" => [
- "value" => "",
- "color" => ""
- ],
- "id" => "20eeayo377xc0"
- ],
- [
- "title" => "裂变红包",
- "imageUrl" => "public/uniapp/member/index/menu/my_hongbao.png",
- "iconType" => "img",
- "style" => "",
- "link" => [
- "name" => "HONGBAO",
- "title" => "我的裂变红包",
- "wap_url" => "/pages_tool/hongbao/my_hongbao",
- "parent" => "MARKETING_LINK"
- ],
- "label" => [
- "control" => false,
- "text" => "热门",
- "textColor" => "#FFFFFF",
- "bgColorStart" => "#F83287",
- "bgColorEnd" => "#FE3423"
- ],
- "iconfont" => [
- "value" => "",
- "color" => ""
- ],
- "id" => "nbthjkdt5c00"
- ],
- [
- "title" => "盲盒",
- "imageUrl" => "public/uniapp/member/index/menu/my_box.png",
- "iconType" => "img",
- "style" => "",
- "link" => [
- "name" => "BLINDBOX",
- "title" => "我的盲盒",
- "wap_url" => "/pages_promotion/blindbox/my_box",
- "parent" => "MARKETING_LINK"
- ],
- "label" => [
- "control" => false,
- "text" => "热门",
- "textColor" => "#FFFFFF",
- "bgColorStart" => "#F83287",
- "bgColorEnd" => "#FE3423"
- ],
- "iconfont" => [
- "value" => "",
- "color" => ""
- ],
- "id" => "1i61b1fdeasg0"
- ]
- ],
- "id" => "5ywbzsnigpw0",
- 'addonName' => '',
- "componentName" => "GraphicNav",
- "componentTitle" => "图文导航",
- "isDelete" => 0,
- "pageBgColor" => "",
- "componentBgColor" => "#FFFFFF",
- "componentAngle" => "round",
- "topAroundRadius" => 0,
- "bottomAroundRadius" => 9,
- "topElementAroundRadius" => 0,
- "bottomElementAroundRadius" => 0,
- "margin" => [
- "top" => 0,
- "bottom" => 0,
- "both" => 15
- ]
- ]
- ]
- ]
- ]
- ]
-
+ '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
+ 'template' => [],
+
+ // 后台自定义组件——装修
+ 'util' => [
+// [
+// 'name' => 'TextExtend', // 组件控制器名称
+// 'title' => '扩展标题',
+// 'type' => 'EXTEND', // 组件类型,SYSTEM:基础组件,PROMOTION:营销组件,EXTEND:扩展组件
+// 'value' => '{}',
+// 'sort' => '50000',
+// 'support_diy_view' => '', // 支持的自定义页面(为空表示公共组件都支持)
+// 'max_count' => 0, // 限制添加次数,0表示可以无限添加该组件
+// 'is_delete' => 0, // 组件是否可以删除,0 允许,1 禁用
+// 'icon' => 'icon-comp-diy-default icon-wenben', // 组件字体图标
+// ],
+ ],
+
+ // 自定义页面路径
+ 'link' => [],
+
+ // 自定义图标库
+ 'icon_library' => [
+
+ // 组件图标【用于后台组件装修】
+ 'component' => [
+// 'name' => 'icon-comp-diy-default', // 字体名称
+// 'path' => 'addon/diy_default1/shop/view/public/css/comp_iconfont.css' // 文件路径
+ ],
+
+ // 自定义图标库
+ 'icon' => [
+// 'name' => 'icondiy-my-template', // 字体名称
+// 'path' => 'addon/diy_default1/shop/view/public/css/diy_iconfont.css' // 文件路径
+ ],
+
+ // 图标类型
+ 'type' => [
+// 'icon-building' => '建筑',
+// 'icon-furniture' => '家具',
+// 'icon-animal' => '动物',
+ ]
+ ],
+
+ // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
+ 'component' => [
+// [
+// 'name' => 'TextExtend', // 组件名称
+// 'path' => 'components/diy-components/diy-text-extend.vue' // 路径
+// ],
+// [
+// 'name' => 'my-music', // 文件夹名称
+// 'path' => 'components/my-music' // 目录路径
+// ],
+ ],
+
+ // uni-app 页面,多个逗号隔开
+ 'pages' => [
+// [
+// 'path' => 'pages/goods/my_cart',
+// 'style' => [
+// 'navigationBarTitleText' => '新购物车'
+// ]
+// ],
+// [
+// 'path' => 'pages_promotion/index/index',
+// 'style' => [
+// 'navigationBarTitleText' => '营销活动中心'
+// ]
+// ],
+ ],
+
+ // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
+ 'info' => [
+ 'title' => '官方模板一', // 模板名称
+ 'name' => 'official_default_round', // 模板标识
+ 'cover' => 'addon/diy_default1/shop/view/public/img/cover.png', // 模板封面图
+ 'preview' => 'addon/diy_default1/shop/view/public/img/preview.png', // 模板预览图
+ 'desc' => '商城简约而不失时尚,适合大部分商城运营。', // 模板描述
+ ],
+
+ // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
+ 'theme' => [
+// [
+// 'title' => '中国红',
+// 'name' => 'colorful',
+// 'preview' => [
+// 'public/static/img/diy_view/style/decorate-default-1.jpg',
+// 'public/static/img/diy_view/style/decorate-default-2.jpg',
+// 'public/static/img/diy_view/style/decorate-default-3.jpg',
+// ],
+// 'color_img' => 'public/static/img/diy_view/style/default.png', // 配色图
+// 'main_color' => '#F4391c',
+// 'aux_color' => '#F7B500',
+// 'bg_color' => '#FF4646',//主题背景
+// 'bg_color_shallow' => '#FF4646',//主题背景渐变浅色
+// 'promotion_color' => '#FF4646',//活动背景
+// 'promotion_aux_color' => '#F7B500',//活动背景辅色
+// 'main_color_shallow' => '#FFF4F4',//淡背景
+// 'price_color' => 'rgb(252,82,39)',//价格颜色
+// 'btn_text_color' => '#FFFFFF',//按钮文字颜色
+// 'goods_detail' => [
+// 'goods_price' => 'rgb(252,82,39,1)',//价格
+// 'promotion_tag' => '#FF4646',
+// 'goods_card_bg' => '#201A18',//会员卡背景
+// 'goods_card_bg_shallow' => '#7C7878',//会员卡背景浅色
+// 'goods_card_color' => '#FFD792',
+// 'goods_coupon' => '#FC5227',
+// 'goods_cart_num_corner' => '#FC5227',//购物车数量角标
+// 'goods_btn_color' => '#FF4646',//按钮颜色
+// 'goods_btn_color_shallow' => '#F7B500',//副按钮颜色
+// ],
+// 'super_member' => [
+// 'super_member_start_bg' => '#7c7878',
+// 'super_member_end_bg' => '#201a18',
+// 'super_member_start_text_color' => '#FFDBA6',
+// 'super_member_end_text_color' => '#FFEBCA',
+// ],
+// 'giftcard' => [
+// 'giftcard_promotion_color' => '#FF3369',//活动背景
+// 'giftcard_promotion_aux_color' => '#F7B500',//活动辅色
+// ],
+// ],
+ ],
+
+ // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
+ 'data' => [
+ [
+ 'title' => '官方模板一',
+ 'name' => "DIY_VIEW_INDEX",
+ 'value' => [
+ "global" => [
+ "title" => "官方模板一",
+ "pageBgColor" => "#F6F9FF",
+ "topNavColor" => "#FFFFFF",
+ "topNavBg" => false,
+ "navBarSwitch" => true,
+ "textNavColor" => "#333333",
+ "topNavImg" => "",
+ "moreLink" => [
+ "name" => ""
+ ],
+ "openBottomNav" => true,
+ "navStyle" => 1,
+ "textImgPosLink" => "center",
+ "mpCollect" => false,
+ "popWindow" => [
+ "imageUrl" => "",
+ "count" => -1,
+ "show" => 0,
+ "link" => [
+ "name" => ""
+ ],
+ "imgWidth" => "",
+ "imgHeight" => ""
+ ],
+ "bgUrl" => 'addon/diy_default1/shop/view/public/img/bg.png',
+ "imgWidth" => "2250",
+ "imgHeight" => "1110",
+ "template" => [
+ "pageBgColor" => "",
+ "textColor" => "#303133",
+ "componentBgColor" => "",
+ "componentAngle" => "round",
+ "topAroundRadius" => 0,
+ "bottomAroundRadius" => 0,
+ "elementBgColor" => "",
+ "elementAngle" => "round",
+ "topElementAroundRadius" => 0,
+ "bottomElementAroundRadius" => 0,
+ "margin" => [
+ "top" => 0,
+ "bottom" => 0,
+ "both" => 12
+ ]
+ ],
+ ],
+ "value" => [
+ [
+ "id" => "5wtw72w1wj80",
+ 'addonName' => '',
+ "componentName" => "Search",
+ "componentTitle" => "搜索框",
+ "isDelete" => 0,
+ "topAroundRadius" => 0,
+ "bottomAroundRadius" => 0,
+ "topElementAroundRadius" => 0,
+ "bottomElementAroundRadius" => 0,
+ "margin" => [
+ "top" => 10,
+ "bottom" => 10,
+ "both" => 12
+ ],
+ "title" => "请输入搜索关键词",
+ "textAlign" => "left",
+ "borderType" => 2,
+ "searchImg" => "",
+ "searchStyle" => 1,
+ "searchLink" => [
+ "name" => ""
+ ],
+ "pageBgColor" => "#FFFFFF",
+ "textColor" => "#303133",
+ "componentBgColor" => "",
+ "elementBgColor" => "#F6F9FF",
+ "iconType" => "img",
+ "icon" => "",
+ "style" => [
+ "fontSize" => "60",
+ "iconBgColor" => [],
+ "iconBgColorDeg" => 0,
+ "iconBgImg" => "",
+ "bgRadius" => 0,
+ "iconColor" => [
+ "#000000"
+ ],
+ "iconColorDeg" => 0
+ ],
+ "imageUrl" => "",
+ "positionWay" => "static"
+ ],
+ [
+ "id" => "2o7za2qmi900",
+ "list" => [
+ [
+ "link" => [
+ "name" => ""
+ ],
+ "imageUrl" => 'addon/diy_default1/shop/view/public/img/banner.png',
+ "imgWidth" => "750",
+ "imgHeight" => "320",
+ "id" => "1iy3xvq2ngf40"
+ ]
+ ],
+ "indicatorIsShow" => true,
+ "indicatorColor" => "#ffffff",
+ "carouselStyle" => "circle",
+ "indicatorLocation" => "center",
+ 'addonName' => '',
+ "componentName" => "ImageAds",
+ "componentTitle" => "图片广告",
+ "isDelete" => 0,
+ "pageBgColor" => "",
+ "componentBgColor" => "",
+ "componentAngle" => "round",
+ "topAroundRadius" => 10,
+ "bottomAroundRadius" => 10,
+ "topElementAroundRadius" => 0,
+ "bottomElementAroundRadius" => 0,
+ "margin" => [
+ "top" => 12,
+ "bottom" => 12,
+ "both" => 12
+ ]
+ ],
+ [
+ "id" => "113ohzka4n40",
+ "mode" => "graphic",
+ "type" => "img",
+ "showStyle" => "fixed",
+ "ornament" => [
+ "type" => "default",
+ "color" => "#EDEDED"
+ ],
+ "rowCount" => 5,
+ "pageCount" => 2,
+ "carousel" => [
+ "type" => "circle",
+ "color" => "#FFFFFF"
+ ],
+ "imageSize" => 40,
+ "aroundRadius" => 25,
+ "font" => [
+ "size" => 14,
+ "weight" => 'normal',
+ "color" => "#303133"
+ ],
+ "list" => [
+ [
+ "title" => "团购",
+ "icon" => "icondiy icon-system-groupbuy-nav",
+ "imageUrl" => "",
+ "iconType" => "icon",
+ "style" => [
+ "fontSize" => 50,
+ "iconBgColor" => [
+ "#FF9F3E",
+ "#FF4116"
+ ],
+ "iconBgColorDeg" => 90,
+ "iconBgImg" => "public/static/ext/diyview/img/icon_bg/bg_06.png",
+ "bgRadius" => 50,
+ "iconColor" => [
+ "#FFFFFF"
+ ],
+ "iconColorDeg" => 0
+ ],
+ "link" => [
+ "name" => "GROUPBUY_PREFECTURE",
+ "title" => "团购专区",
+ "wap_url" => "/pages_promotion/groupbuy/list",
+ "parent" => "MARKETING_LINK"
+ ],
+ "label" => [
+ "control" => false,
+ "text" => "热门",
+ "textColor" => "#FFFFFF",
+ "bgColorStart" => "#F83287",
+ "bgColorEnd" => "#FE3423"
+ ],
+ "id" => "ycafod7gfgg0"
+ ],
+ [
+ "title" => "拼团",
+ "icon" => "icondiy icon-system-pintuan-nav",
+ "imageUrl" => "",
+ "iconType" => "icon",
+ "style" => [
+ "fontSize" => 50,
+ "iconBgColor" => [
+ "#58BCFF",
+ "#1379FF"
+ ],
+ "iconBgColorDeg" => 90,
+ "iconBgImg" => "public/static/ext/diyview/img/icon_bg/bg_06.png",
+ "bgRadius" => 50,
+ "iconColor" => [
+ "#FFFFFF"
+ ],
+ "iconColorDeg" => 0
+ ],
+ "link" => [
+ "name" => "PINTUAN_PREFECTURE",
+ "title" => "拼团专区",
+ "wap_url" => "/pages_promotion/pintuan/list",
+ "parent" => "MARKETING_LINK"
+ ],
+ "label" => [
+ "control" => false,
+ "text" => "热门",
+ "textColor" => "#FFFFFF",
+ "bgColorStart" => "#F83287",
+ "bgColorEnd" => "#FE3423"
+ ],
+ "id" => "wnlf5ak6u8g0"
+ ],
+ [
+ "title" => "秒杀",
+ "icon" => "icondiy icon-system-seckill-time",
+ "imageUrl" => "",
+ "iconType" => "icon",
+ "style" => [
+ "fontSize" => 50,
+ "iconBgColor" => [
+ "#FFCC26",
+ "#FF9F29"
+ ],
+ "iconBgColorDeg" => 90,
+ "iconBgImg" => "public/static/ext/diyview/img/icon_bg/bg_06.png",
+ "bgRadius" => 50,
+ "iconColor" => [
+ "#FFFFFF"
+ ],
+ "iconColorDeg" => 0
+ ],
+ "link" => [
+ "name" => "SECKILL_PREFECTURE",
+ "title" => "秒杀专区",
+ "wap_url" => "/pages_promotion/seckill/list",
+ "parent" => "MARKETING_LINK"
+ ],
+ "label" => [
+ "control" => true,
+ "text" => "热门",
+ "textColor" => "#FFFFFF",
+ "bgColorStart" => "#F83288",
+ "bgColorEnd" => "#FE3523"
+ ],
+ "id" => "lpg2grtvmxo0"
+ ],
+ [
+ "title" => " 积分",
+ "icon" => "icondiy icon-system-point-nav",
+ "imageUrl" => "",
+ "iconType" => "icon",
+ "style" => [
+ "fontSize" => 50,
+ "iconBgColor" => [
+ "#02CC96",
+ "#43EEC9"
+ ],
+ "iconBgColorDeg" => 90,
+ "iconBgImg" => "public/static/ext/diyview/img/icon_bg/bg_06.png",
+ "bgRadius" => 50,
+ "iconColor" => [
+ "#FFFFFF"
+ ],
+ "iconColorDeg" => 0
+ ],
+ "link" => [
+ "name" => "INTEGRAL_STORE",
+ "title" => "积分商城",
+ "wap_url" => "/pages_promotion/point/list",
+ "parent" => "MARKETING_LINK"
+ ],
+ "label" => [
+ "control" => false,
+ "text" => "热门",
+ "textColor" => "#FFFFFF",
+ "bgColorStart" => "#F83287",
+ "bgColorEnd" => "#FE3423"
+ ],
+ "id" => "1jfs721gome8"
+ ],
+ [
+ "title" => "专题活动",
+ "icon" => "icondiy icon-system-topic-nav",
+ "imageUrl" => "",
+ "iconType" => "icon",
+ "style" => [
+ "fontSize" => 50,
+ "iconBgColor" => [
+ "#BE79FF",
+ "#7B00FF"
+ ],
+ "iconBgColorDeg" => 0,
+ "iconBgImg" => "public/static/ext/diyview/img/icon_bg/bg_06.png",
+ "bgRadius" => 50,
+ "iconColor" => [
+ "#FFFFFF"
+ ],
+ "iconColorDeg" => 0
+ ],
+ "link" => [
+ "name" => "THEMATIC_ACTIVITIES_LIST",
+ "title" => "专题活动列表",
+ "wap_url" => "/pages_promotion/topics/list",
+ "parent" => "MARKETING_LINK"
+ ],
+ "label" => [
+ "control" => false,
+ "text" => "热门",
+ "textColor" => "#FFFFFF",
+ "bgColorStart" => "#F83287",
+ "bgColorEnd" => "#FE3423"
+ ],
+ "id" => "1grejh3c8fwg0"
+ ],
+ [
+ "title" => "砍价",
+ "icon" => "icondiy icon-system-bargain-nav",
+ "imageUrl" => "",
+ "iconType" => "icon",
+ "style" => [
+ "fontSize" => 50,
+ "iconBgColor" => [
+ "#5BBDFF",
+ "#2E87FD"
+ ],
+ "iconBgColorDeg" => 90,
+ "iconBgImg" => "public/static/ext/diyview/img/icon_bg/bg_06.png",
+ "bgRadius" => 50,
+ "iconColor" => [
+ "#FFFFFF"
+ ],
+ "iconColorDeg" => 0
+ ],
+ "link" => [
+ "name" => "BARGAIN_PREFECTURE",
+ "title" => "砍价专区",
+ "wap_url" => "/pages_promotion/bargain/list",
+ "parent" => "MARKETING_LINK"
+ ],
+ "label" => [
+ "control" => false,
+ "text" => "热门",
+ "textColor" => "#FFFFFF",
+ "bgColorStart" => "#F83287",
+ "bgColorEnd" => "#FE3423"
+ ],
+ "id" => "ycpsnfbaf800"
+ ],
+ [
+ "title" => "领券",
+ "icon" => "icondiy icon-system-get-coupon",
+ "imageUrl" => "",
+ "iconType" => "icon",
+ "style" => [
+ "fontSize" => 50,
+ "iconBgColor" => [
+ "#BE79FF",
+ "#7B00FF"
+ ],
+ "iconBgColorDeg" => 90,
+ "iconBgImg" => "public/static/ext/diyview/img/icon_bg/bg_06.png",
+ "bgRadius" => 50,
+ "iconColor" => [
+ "#FFFFFF"
+ ],
+ "iconColorDeg" => 0
+ ],
+ "link" => [
+ "name" => "COUPON_PREFECTURE",
+ "title" => "优惠券专区",
+ "wap_url" => "/pages_tool/goods/coupon",
+ "parent" => "MARKETING_LINK"
+ ],
+ "label" => [
+ "control" => false,
+ "text" => "热门",
+ "textColor" => "#FFFFFF",
+ "bgColorStart" => "#F83287",
+ "bgColorEnd" => "#FE3423"
+ ],
+ "id" => "17dcs7xstz400"
+ ],
+ [
+ "title" => "文章",
+ "icon" => "icondiy icon-system-article-nav",
+ "imageUrl" => "",
+ "iconType" => "icon",
+ "style" => [
+ "fontSize" => 50,
+ "iconBgColor" => [
+ "#FF8052",
+ "#FF4830"
+ ],
+ "iconBgColorDeg" => 0,
+ "iconBgImg" => "public/static/ext/diyview/img/icon_bg/bg_06.png",
+ "bgRadius" => 50,
+ "iconColor" => [
+ "#FFFFFF"
+ ],
+ "iconColorDeg" => 0
+ ],
+ "link" => [
+ "name" => "SHOPPING_ARTICLE",
+ "title" => "文章",
+ "wap_url" => "/pages_tool/article/list",
+ "parent" => "MALL_LINK"
+ ],
+ "label" => [
+ "control" => false,
+ "text" => "热门",
+ "textColor" => "#FFFFFF",
+ "bgColorStart" => "#F83287",
+ "bgColorEnd" => "#FE3423"
+ ],
+ "id" => "hg8450mb0hc0"
+ ],
+ [
+ "title" => "公告",
+ "icon" => "icondiy icon-system-notice-nav",
+ "imageUrl" => "",
+ "iconType" => "icon",
+ "style" => [
+ "fontSize" => 50,
+ "iconBgColor" => [
+ "#FFCC26",
+ "#FF9F29"
+ ],
+ "iconBgColorDeg" => 90,
+ "iconBgImg" => "public/static/ext/diyview/img/icon_bg/bg_06.png",
+ "bgRadius" => 50,
+ "iconColor" => [
+ "#FFFFFF"
+ ],
+ "iconColorDeg" => 0
+ ],
+ "link" => [
+ "name" => "SHOPPING_NOTICE",
+ "title" => "公告",
+ "wap_url" => "/pages_tool/notice/list",
+ "parent" => "MALL_LINK"
+ ],
+ "label" => [
+ "control" => false,
+ "text" => "热门",
+ "textColor" => "#FFFFFF",
+ "bgColorStart" => "#F83287",
+ "bgColorEnd" => "#FE3423"
+ ],
+ "id" => "1cg964qu9f9c0"
+ ],
+ [
+ "title" => "帮助",
+ "icon" => "icondiy icon-system-help",
+ "imageUrl" => "",
+ "iconType" => "icon",
+ "style" => [
+ "fontSize" => 50,
+ "iconBgColor" => [
+ "#02CC96",
+ "#43EEC9"
+ ],
+ "iconBgColorDeg" => 90,
+ "iconBgImg" => "public/static/ext/diyview/img/icon_bg/bg_06.png",
+ "bgRadius" => 50,
+ "iconColor" => [
+ "#FFFFFF"
+ ],
+ "iconColorDeg" => 0
+ ],
+ "link" => [
+ "name" => "SHOPPING_HELP",
+ "title" => "帮助",
+ "wap_url" => "/pages_tool/help/list",
+ "parent" => "MALL_LINK"
+ ],
+ "label" => [
+ "control" => false,
+ "text" => "热门",
+ "textColor" => "#FFFFFF",
+ "bgColorStart" => "#F83287",
+ "bgColorEnd" => "#FE3423"
+ ],
+ "id" => "1v4budp7jav40"
+ ]
+ ],
+ 'addonName' => '',
+ "componentName" => "GraphicNav",
+ "componentTitle" => "图文导航",
+ "isDelete" => 0,
+ "pageBgColor" => "",
+ "componentBgColor" => "#FFFFFF",
+ "componentAngle" => "round",
+ "topAroundRadius" => 10,
+ "bottomAroundRadius" => 10,
+ "topElementAroundRadius" => 0,
+ "bottomElementAroundRadius" => 0,
+ "margin" => [
+ "top" => 0,
+ "bottom" => 12,
+ "both" => 12
+ ]
+ ],
+ [
+ "id" => "3tegcfvyijk0",
+ "list" => [
+ [
+ "link" => [
+ "name" => ""
+ ],
+ "imageUrl" => 'addon/diy_default1/shop/view/public/img/mf_left.png',
+ "imgWidth" => "338",
+ "imgHeight" => "450",
+ "previewWidth" => 187.5,
+ "previewHeight" => "249.63px"
+ ],
+ [
+ "imageUrl" => 'addon/diy_default1/shop/view/public/img/mf_right1.png',
+ "link" => [
+ "name" => ""
+ ],
+ "imgWidth" => "354",
+ "imgHeight" => "220",
+ "previewWidth" => 187.5,
+ "previewHeight" => "124.82px",
+ ],
+ [
+ "imageUrl" => 'addon/diy_default1/shop/view/public/img/mf_right2.png',
+ "imgWidth" => "354",
+ "imgHeight" => "220",
+ "previewWidth" => 187.5,
+ "previewHeight" => "124.82px",
+ "link" => [
+ "name" => ""
+ ]
+ ]
+ ],
+ "mode" => "row1-lt-of2-rt",
+ "imageGap" => 10,
+ 'addonName' => '',
+ "componentName" => "RubikCube",
+ "componentTitle" => "魔方",
+ "isDelete" => 0,
+ "pageBgColor" => "",
+ "componentBgColor" => "",
+ "componentAngle" => "round",
+ "topAroundRadius" => 10,
+ "bottomAroundRadius" => 10,
+ "elementAngle" => "round",
+ "topElementAroundRadius" => 0,
+ "bottomElementAroundRadius" => 0,
+ "margin" => [
+ "top" => 0,
+ "bottom" => 12,
+ "both" => 12
+ ]
+ ],
+ [
+ "id" => "3acr0xjm1c80",
+ "style" => "style-16",
+ "subTitle" => [
+ "fontSize" => 14,
+ "text" => "超级优惠",
+ "isElementShow" => true,
+ "color" => "#FFFFFF",
+ "bgColor" => "#FF9F29",
+ "icon" => "icondiy icon-system-coupon",
+ "fontWeight" => 'bold'
+ ],
+ "link" => [
+ "name" => "COUPON_PREFECTURE",
+ "title" => "优惠券专区",
+ "wap_url" => "/pages_tool/goods/coupon",
+ "parent" => "MARKETING_LINK"
+ ],
+ "fontSize" => 16,
+ "styleName" => "风格16",
+ "fontWeight" => 'bold',
+ "more" => [
+ "text" => "",
+ "link" => [
+ "name" => "COUPON_PREFECTURE",
+ "title" => "优惠券专区",
+ "wap_url" => "/pages_tool/goods/coupon",
+ "parent" => "MARKETING_LINK"
+ ],
+ "isShow" => true,
+ "isElementShow" => true,
+ "color" => "#999999"
+ ],
+ "text" => "优惠专区",
+ 'addonName' => '',
+ "componentName" => "Text",
+ "componentTitle" => "标题",
+ "isDelete" => 0,
+ "pageBgColor" => "",
+ "textColor" => "#303133",
+ "componentBgColor" => "#FFFFFF",
+ "componentAngle" => "round",
+ "topAroundRadius" => 10,
+ "bottomAroundRadius" => 0,
+ "topElementAroundRadius" => 0,
+ "bottomElementAroundRadius" => 0,
+ "margin" => [
+ "top" => 0,
+ "bottom" => 0,
+ "both" => 12
+ ]
+ ],
+ [
+ "id" => "2parw5r2qq00",
+ "style" => "6",
+ "sources" => "initial",
+ "styleName" => "风格六",
+ "couponIds" => [],
+ "count" => 6,
+ "previewList" => [],
+ "nameColor" => "#303133",
+ "moneyColor" => "#FF0000",
+ "limitColor" => "#303133",
+ "btnStyle" => [
+ "textColor" => "#FFFFFF",
+ "bgColor" => "#303133",
+ "text" => "领取",
+ "aroundRadius" => 20,
+ "isBgColor" => true,
+ "isAroundRadius" => true
+ ],
+ "bgColor" => "",
+ "isName" => true,
+ "couponBgColor" => "#FFFFFF",
+ "couponBgUrl" => "",
+ "couponType" => "color",
+ "ifNeedBg" => true,
+ 'addonName' => 'coupon',
+ "componentName" => "Coupon",
+ "componentTitle" => "优惠券",
+ "isDelete" => 0,
+ "pageBgColor" => "",
+ "topAroundRadius" => 0,
+ "bottomAroundRadius" => 0,
+ "elementBgColor" => "",
+ "topElementAroundRadius" => 0,
+ "bottomElementAroundRadius" => 0,
+ "margin" => [
+ "top" => 0,
+ "bottom" => 0,
+ "both" => 12
+ ]
+ ],
+ [
+ "id" => "68p4o1plca80",
+ "height" => 10,
+ 'addonName' => '',
+ "componentName" => "HorzBlank",
+ "componentTitle" => "辅助空白",
+ "isDelete" => 0,
+ "pageBgColor" => "",
+ "componentBgColor" => "#FFFFFF",
+ "componentAngle" => "round",
+ "topAroundRadius" => 0,
+ "bottomAroundRadius" => 0,
+ "topElementAroundRadius" => 0,
+ "bottomElementAroundRadius" => 0,
+ "margin" => [
+ "top" => 0,
+ "bottom" => 10,
+ "both" => 12
+ ]
+ ],
+ [
+ "id" => "3moj09pl5c20",
+ "style" => "style-1",
+ "sources" => "initial",
+ "count" => 6,
+ "goodsId" => [],
+ "ornament" => [
+ "type" => "default",
+ "color" => "#EDEDED"
+ ],
+ "nameLineMode" => "single",
+ "template" => "row1-of1",
+ "goodsMarginType" => "default",
+ "goodsMarginNum" => 10,
+ "btnStyle" => [
+ "text" => "去秒杀",
+ "textColor" => "#FFFFFF",
+ "theme" => "default",
+ "aroundRadius" => 25,
+ "control" => true,
+ "support" => true,
+ "bgColorStart" => "#FF7B1D",
+ "bgColorEnd" => "#FF1544"
+ ],
+ "imgAroundRadius" => 10,
+ "saleStyle" => [
+ "color" => "#999CA7",
+ "control" => true,
+ "support" => true
+ ],
+ "progressStyle" => [
+ "control" => true,
+ "support" => true,
+ "currColor" => "#FDBE6C",
+ "bgColor" => "#FCECD7"
+ ],
+ "titleStyle" => [
+ "backgroundImage" => "addon/seckill/component/view/seckill/img/style_title_3_bg.png",
+ "isShow" => true,
+ "leftStyle" => "img",
+ "leftImg" => "addon/seckill/component/view/seckill/img/style_title_3_name.png",
+ "style" => "style-3",
+ "styleName" => "风格3",
+ "leftText" => "限时秒杀",
+ "fontSize" => 16,
+ "fontWeight" => true,
+ "textColor" => "#FFFFFF",
+ "bgColorStart" => "#FA6400",
+ "bgColorEnd" => "#FF287A",
+ "more" => "更多",
+ "moreColor" => "#FFFFFF",
+ "moreFontSize" => 12,
+ "moreSupport" => true,
+ "timeBgColor" => "",
+ "timeImageUrl" => "",
+ "colonColor" => "#FFFFFF",
+ "numBgColorStart" => "#FFFFFF",
+ "numBgColorEnd" => "#FFFFFF",
+ "numTextColor" => "#FD3B54"
+ ],
+ "slideMode" => "scroll",
+ "theme" => "default",
+ "priceStyle" => [
+ "mainColor" => "#FF1745",
+ "mainControl" => true,
+ "lineColor" => "#999CA7",
+ "lineControl" => true,
+ "lineSupport" => true
+ ],
+ "goodsNameStyle" => [
+ "color" => "#303133",
+ "control" => true,
+ "fontWeight" => false
+ ],
+ 'addonName' => 'seckill',
+ "componentName" => "Seckill",
+ "componentTitle" => "秒杀",
+ "isDelete" => 0,
+ "pageBgColor" => "",
+ "componentBgColor" => "",
+ "componentAngle" => "round",
+ "topAroundRadius" => 10,
+ "bottomAroundRadius" => 10,
+ "elementBgColor" => "#FFFFFF",
+ "elementAngle" => "round",
+ "topElementAroundRadius" => 0,
+ "bottomElementAroundRadius" => 0,
+ "margin" => [
+ "top" => 0,
+ "bottom" => 12,
+ "both" => 12
+ ]
+ ],
+ [
+ "id" => "z9bdab3tm34",
+ "style" => "style-1",
+ "sources" => "initial",
+ "count" => 6,
+ "goodsId" => [],
+ "ornament" => [
+ "type" => "default",
+ "color" => "#EDEDED"
+ ],
+ "nameLineMode" => "single",
+ "template" => "horizontal-slide",
+ "goodsMarginType" => "default",
+ "goodsMarginNum" => 10,
+ "btnStyle" => [
+ "text" => "去拼团",
+ "textColor" => "#FFFFFF",
+ "theme" => "default",
+ "aroundRadius" => 25,
+ "control" => false,
+ "support" => false,
+ "bgColorStart" => "#FF1544",
+ "bgColorEnd" => "#FF1544"
+ ],
+ "imgAroundRadius" => 10,
+ "saleStyle" => [
+ "color" => "#FF1544",
+ "control" => false,
+ "support" => false
+ ],
+ "groupStyle" => [
+ "color" => "#FFFFFF",
+ "control" => true,
+ "support" => true,
+ "bgColorStart" => "#FA2379",
+ "bgColorEnd" => "#FF4F61"
+ ],
+ "priceStyle" => [
+ "mainColor" => "#FF1544",
+ "mainControl" => true,
+ "lineColor" => "#999CA7",
+ "lineControl" => true,
+ "lineSupport" => true
+ ],
+ "slideMode" => "scroll",
+ "theme" => "default",
+ "goodsNameStyle" => [
+ "color" => "#303133",
+ "control" => true,
+ "fontWeight" => false
+ ],
+ "titleStyle" => [
+ "bgColorStart" => "#6236FF",
+ "bgColorEnd" => "#0091FF",
+ "isShow" => true,
+ "leftStyle" => "img",
+ "leftImg" => "addon/pintuan/component/view/pintuan/img/horizontal_slide_name.png",
+ "style" => "style-1",
+ "styleName" => "风格1",
+ "leftText" => "超值拼团",
+ "fontSize" => 16,
+ "fontWeight" => true,
+ "textColor" => "#FFFFFF",
+ "more" => "查看更多",
+ "moreColor" => "#FFFFFF",
+ "moreFontSize" => 12,
+ "backgroundImage" => "addon/pintuan/component/view/pintuan/img/horizontal_slide_bg.png"
+ ],
+ 'addonName' => 'pintuan',
+ "componentName" => "Pintuan",
+ "componentTitle" => "拼团",
+ "isDelete" => 0,
+ "pageBgColor" => "",
+ "componentBgColor" => "#FFFFFF",
+ "componentAngle" => "round",
+ "topAroundRadius" => 0,
+ "bottomAroundRadius" => 10,
+ "elementBgColor" => "",
+ "elementAngle" => "round",
+ "topElementAroundRadius" => 0,
+ "bottomElementAroundRadius" => 0,
+ "margin" => [
+ "top" => 0,
+ "bottom" => 12,
+ "both" => 12
+ ]
+ ],
+ [
+ "id" => "xwdnfttfj7k",
+ "style" => "style-1",
+ "sources" => "initial",
+ "count" => 6,
+ "goodsId" => [],
+ "ornament" => [
+ "type" => "default",
+ "color" => "#EDEDED"
+ ],
+ "nameLineMode" => "single",
+ "template" => "horizontal-slide",
+ "goodsMarginType" => "default",
+ "goodsMarginNum" => 10,
+ "btnStyle" => [
+ "text" => "立即抢购",
+ "textColor" => "#FFFFFF",
+ "theme" => "default",
+ "aroundRadius" => 25,
+ "control" => false,
+ "support" => false,
+ "bgColorStart" => "#FF7B1D",
+ "bgColorEnd" => "#FF1544"
+ ],
+ "imgAroundRadius" => 5,
+ "saleStyle" => [
+ "color" => "#FFFFFF",
+ "control" => true,
+ "support" => true
+ ],
+ "slideMode" => "scroll",
+ "theme" => "default",
+ "goodsNameStyle" => [
+ "color" => "#303133",
+ "control" => true,
+ "fontWeight" => false
+ ],
+ "priceStyle" => [
+ "mainColor" => "#FF1745",
+ "mainControl" => true,
+ "lineColor" => "#999CA7",
+ "lineControl" => true,
+ "lineSupport" => true
+ ],
+ "titleStyle" => [
+ "bgColorStart" => "#FF209D",
+ "bgColorEnd" => "#B620E0",
+ "isShow" => true,
+ "leftStyle" => "img",
+ "leftImg" => "",
+ "style" => "style-1",
+ "styleName" => "风格1",
+ "leftText" => "疯狂砍价",
+ "fontSize" => 16,
+ "fontWeight" => true,
+ "textColor" => "#FFFFFF",
+ "more" => "更多",
+ "moreColor" => "#FFFFFF",
+ "moreFontSize" => 12,
+ "backgroundImage" => ""
+ ],
+ 'addonName' => 'bargain',
+ "componentName" => "Bargain",
+ "componentTitle" => "砍价",
+ "isDelete" => 0,
+ "pageBgColor" => "",
+ "componentBgColor" => "#FFFFFF",
+ "componentAngle" => "round",
+ "topAroundRadius" => 0,
+ "bottomAroundRadius" => 10,
+ "elementBgColor" => "",
+ "elementAngle" => "round",
+ "topElementAroundRadius" => 0,
+ "bottomElementAroundRadius" => 0,
+ "margin" => [
+ "top" => 0,
+ "bottom" => 12,
+ "both" => 12
+ ]
+ ],
+ [
+ "id" => "29fhippqsrgg",
+ "list" => [
+ [
+ "link" => [
+ "name" => ""
+ ],
+ "imageUrl" => 'addon/diy_default1/shop/view/public/img/gg.png',
+ "imgWidth" => "702",
+ "imgHeight" => "252",
+ "id" => "1z94aaav9klc0"
+ ]
+ ],
+ "indicatorIsShow" => true,
+ "indicatorColor" => "#ffffff",
+ "carouselStyle" => "circle",
+ "indicatorLocation" => "center",
+ 'addonName' => '',
+ "componentName" => "ImageAds",
+ "componentTitle" => "图片广告",
+ "isDelete" => 0,
+ "pageBgColor" => "",
+ "componentBgColor" => "",
+ "componentAngle" => "round",
+ "topAroundRadius" => 10,
+ "bottomAroundRadius" => 10,
+ "topElementAroundRadius" => 0,
+ "bottomElementAroundRadius" => 0,
+ "margin" => [
+ "top" => 0,
+ "bottom" => 12,
+ "both" => 12
+ ]
+ ],
+ [
+ "id" => "i4xirbfy0m8",
+ "style" => "style-3",
+ "sources" => "initial",
+ "count" => 6,
+ "goodsId" => [],
+ "ornament" => [
+ "type" => "default",
+ "color" => "#EDEDED"
+ ],
+ "nameLineMode" => "multiple",
+ "template" => "row1-of2",
+ "goodsMarginType" => "default",
+ "goodsMarginNum" => 6,
+ "btnStyle" => [
+ "fontWeight" => false,
+ "padding" => 0,
+ "cartEvent" => "detail",
+ "text" => "购买",
+ "textColor" => "#FFFFFF",
+ "theme" => "default",
+ "aroundRadius" => 25,
+ "control" => false,
+ "support" => false,
+ "bgColor" => "#FF6A00",
+ "style" => "button",
+ "iconDiy" => [
+ "iconType" => "icon",
+ "icon" => "",
+ "style" => [
+ "fontSize" => "60",
+ "iconBgColor" => [],
+ "iconBgColorDeg" => 0,
+ "iconBgImg" => "",
+ "bgRadius" => 0,
+ "iconColor" => [
+ "#000000"
+ ],
+ "iconColorDeg" => 0
+ ]
+ ]
+ ],
+ "categoryId" => 0,
+ "categoryName" => "请选择",
+ "sortWay" => "default",
+ "tag" => [
+ "text" => "隐藏",
+ "value" => "hidden"
+ ],
+ "imgAroundRadius" => 0,
+ "slideMode" => "scroll",
+ "goodsNameStyle" => [
+ "color" => "#303133",
+ "control" => true,
+ "fontWeight" => false
+ ],
+ "saleStyle" => [
+ "color" => "#999CA7",
+ "control" => true,
+ "support" => true
+ ],
+ "theme" => "default",
+ "priceStyle" => [
+ "mainColor" => "#FF6A00",
+ "mainControl" => true,
+ "lineColor" => "#999CA7",
+ "lineControl" => false,
+ "lineSupport" => false
+ ],
+ 'addonName' => '',
+ "componentName" => "GoodsList",
+ "componentTitle" => "商品列表",
+ "isDelete" => 0,
+ "pageBgColor" => "",
+ "componentBgColor" => "",
+ "componentAngle" => "round",
+ "topAroundRadius" => 0,
+ "bottomAroundRadius" => 0,
+ "elementBgColor" => "#FFFFFF",
+ "elementAngle" => "round",
+ "topElementAroundRadius" => 10,
+ "bottomElementAroundRadius" => 0,
+ "margin" => [
+ "top" => 0,
+ "bottom" => 10,
+ "both" => 12
+ ]
+ ]
+ ]
+ ]
+ ],
+ [
+ 'title' => '商品分类',
+ 'name' => "DIY_VIEW_GOODS_CATEGORY",
+ 'value' => [
+ "global" => [
+ "title" => "商品分类",
+ "pageBgColor" => "#FFFFFF",
+ "topNavColor" => "#FFFFFF",
+ "topNavBg" => false,
+ "navBarSwitch" => true,
+ "textNavColor" => "#333333",
+ "topNavImg" => "",
+ "moreLink" => [
+ "name" => ""
+ ],
+ "openBottomNav" => true,
+ "navStyle" => 1,
+ "textImgPosLink" => "left",
+ "mpCollect" => false,
+ "popWindow" => [
+ "imageUrl" => "",
+ "count" => -1,
+ "show" => 0,
+ "link" => [
+ "name" => ""
+ ],
+ "imgWidth" => "",
+ "imgHeight" => ""
+ ],
+ "bgUrl" => "",
+ "imgWidth" => "",
+ "imgHeight" => "",
+ "template" => [
+ "pageBgColor" => "",
+ "textColor" => "#303133",
+ "componentBgColor" => "",
+ "componentAngle" => "round",
+ "topAroundRadius" => 0,
+ "bottomAroundRadius" => 0,
+ "elementBgColor" => "",
+ "elementAngle" => "round",
+ "topElementAroundRadius" => 0,
+ "bottomElementAroundRadius" => 0,
+ "margin" => [
+ "top" => 0,
+ "bottom" => 0,
+ "both" => 0
+ ]
+ ]
+ ],
+ "value" => [
+ [
+ "level" => "2",
+ "template" => "2",
+ "quickBuy" => 1,
+ "search" => 1,
+ 'addonName' => '',
+ "componentName" => "GoodsCategory",
+ "componentTitle" => "商品分类",
+ "isDelete" => 1,
+ "topAroundRadius" => 0,
+ "bottomAroundRadius" => 0,
+ "topElementAroundRadius" => 0,
+ "bottomElementAroundRadius" => 0,
+ "margin" => [],
+ "goodsLevel" => 1,
+ "loadType" => "part"
+ ]
+ ]
+ ]
+ ],
+ [
+ 'title' => '会员中心',
+ 'name' => "DIY_VIEW_MEMBER_INDEX",
+ 'value' => [
+ "global" => [
+ "title" => "会员中心",
+ "pageBgColor" => "#F8F8F8",
+ "topNavColor" => "#FFFFFF",
+ "topNavBg" => true,
+ "navBarSwitch" => true,
+ "textNavColor" => "#333333",
+ "topNavImg" => "",
+ "moreLink" => [
+ "name" => ""
+ ],
+ "openBottomNav" => true,
+ "navStyle" => 1,
+ "textImgPosLink" => "center",
+ "mpCollect" => false,
+ "popWindow" => [
+ "imageUrl" => "",
+ "count" => -1,
+ "show" => 0,
+ "link" => [
+ "name" => ""
+ ],
+ "imgWidth" => "",
+ "imgHeight" => ""
+ ],
+ "bgUrl" => "",
+ "imgWidth" => "",
+ "imgHeight" => "",
+ "template" => [
+ "pageBgColor" => "",
+ "textColor" => "#303133",
+ "componentBgColor" => "",
+ "componentAngle" => "round",
+ "topAroundRadius" => 0,
+ "bottomAroundRadius" => 0,
+ "elementBgColor" => "",
+ "elementAngle" => "round",
+ "topElementAroundRadius" => 0,
+ "bottomElementAroundRadius" => 0,
+ "margin" => [
+ "top" => 0,
+ "bottom" => 0,
+ "both" => 0
+ ]
+ ]
+ ],
+ "value" => [
+ [
+ "style" => 4,
+ "theme" => "default",
+ "bgColorStart" => "#FF7230",
+ "bgColorEnd" => "#FF1544",
+ "gradientAngle" => "129",
+ "infoMargin" => 15,
+ "id" => "1tkaoxbhavj4",
+ 'addonName' => '',
+ "componentName" => "MemberInfo",
+ "componentTitle" => "会员信息",
+ "isDelete" => 0,
+ "pageBgColor" => "",
+ "textColor" => "#303133",
+ "componentBgColor" => "",
+ "componentAngle" => "round",
+ "topAroundRadius" => 0,
+ "bottomAroundRadius" => 0,
+ "elementBgColor" => "",
+ "elementAngle" => "round",
+ "topElementAroundRadius" => 0,
+ "bottomElementAroundRadius" => 0,
+ "margin" => [
+ "top" => 0,
+ "bottom" => 0,
+ "both" => 0
+ ]
+ ],
+ [
+ "style" => "style-12",
+ "styleName" => "风格12",
+ "text" => "我的订单",
+ "link" => [
+ "name" => ""
+ ],
+ "fontSize" => 17,
+ "fontWeight" => 'bold',
+ "subTitle" => [
+ "fontSize" => 14,
+ "text" => "",
+ "isElementShow" => true,
+ "color" => "#999999",
+ "bgColor" => "#303133"
+ ],
+ "more" => [
+ "text" => "全部订单",
+ "link" => [
+ "name" => "ALL_ORDER",
+ "title" => "全部订单",
+ "wap_url" => "/pages/order/list",
+ "parent" => "MALL_LINK"
+ ],
+ "isShow" => true,
+ "isElementShow" => true,
+ "color" => "#999999"
+ ],
+ "id" => "2txcvx3d5u6",
+ 'addonName' => '',
+ "componentName" => "Text",
+ "componentTitle" => "标题",
+ "isDelete" => 0,
+ "pageBgColor" => "",
+ "textColor" => "#303133",
+ "componentBgColor" => "#FFFFFF",
+ "componentAngle" => "round",
+ "topAroundRadius" => 9,
+ "bottomAroundRadius" => 0,
+ "topElementAroundRadius" => 0,
+ "bottomElementAroundRadius" => 0,
+ "margin" => [
+ "top" => 15,
+ "bottom" => 0,
+ "both" => 15
+ ]
+ ],
+ [
+ "color" => "#EEEEEE",
+ "borderStyle" => "solid",
+ "id" => "3hsh2st470e0",
+ 'addonName' => '',
+ "componentName" => "HorzLine",
+ "componentTitle" => "辅助线",
+ "isDelete" => 0,
+ "pageBgColor" => "",
+ "topAroundRadius" => 0,
+ "bottomAroundRadius" => 0,
+ "topElementAroundRadius" => 0,
+ "bottomElementAroundRadius" => 0,
+ "margin" => [
+ "top" => 0,
+ "bottom" => 0,
+ "both" => 20
+ ]
+ ],
+ [
+ "icon" => [
+ "waitPay" => [
+ "title" => "待付款",
+ "icon" => "icondiy icon-system-daifukuan2",
+ "style" => [
+ "bgRadius" => 0,
+ "fontSize" => 65,
+ "iconBgColor" => [],
+ "iconBgColorDeg" => 0,
+ "iconBgImg" => "",
+ "iconColor" => [
+ "#ffa3a3",
+ "#FF4646"
+ ],
+ "iconColorDeg" => 0
+ ]
+ ],
+ "waitSend" => [
+ "title" => "待发货",
+ "icon" => "icondiy icon-system-daifahuo2",
+ "style" => [
+ "bgRadius" => 0,
+ "fontSize" => 65,
+ "iconBgColor" => [],
+ "iconBgColorDeg" => 0,
+ "iconBgImg" => "",
+ "iconColor" => [
+ "#ffa3a3",
+ "#FF4646"
+ ],
+ "iconColorDeg" => 0
+ ]
+ ],
+ "waitConfirm" => [
+ "title" => "待收货",
+ "icon" => "icondiy icon-system-daishouhuo2",
+ "style" => [
+ "bgRadius" => 0,
+ "fontSize" => 65,
+ "iconBgColor" => [],
+ "iconBgColorDeg" => 0,
+ "iconBgImg" => "",
+ "iconColor" => [
+ "#ffa3a3",
+ "#FF4646"
+ ],
+ "iconColorDeg" => 0
+ ]
+ ],
+ "waitUse" => [
+ "title" => "待使用",
+ "icon" => "icondiy icon-system-daishiyong2",
+ "style" => [
+ "bgRadius" => 0,
+ "fontSize" => 65,
+ "iconBgColor" => [],
+ "iconBgColorDeg" => 0,
+ "iconBgImg" => "",
+ "iconColor" => [
+ "#ffa3a3",
+ "#FF4646"
+ ],
+ "iconColorDeg" => 0
+ ]
+ ],
+ "refunding" => [
+ "title" => "售后",
+ "icon" => "icondiy icon-system-shuhou2",
+ "style" => [
+ "bgRadius" => 0,
+ "fontSize" => 65,
+ "iconBgColor" => [],
+ "iconBgColorDeg" => 0,
+ "iconBgImg" => "",
+ "iconColor" => [
+ "#ffa3a3",
+ "#FF4646"
+ ],
+ "iconColorDeg" => 0
+ ]
+ ]
+ ],
+ "style" => 1,
+ "id" => "51h05xpcanw0",
+ 'addonName' => '',
+ "componentName" => "MemberMyOrder",
+ "componentTitle" => "我的订单",
+ "isDelete" => 0,
+ "pageBgColor" => "",
+ "textColor" => "#303133",
+ "componentBgColor" => "#FFFFFF",
+ "componentAngle" => "round",
+ "topAroundRadius" => 0,
+ "bottomAroundRadius" => 9,
+ "elementBgColor" => "",
+ "elementAngle" => "round",
+ "topElementAroundRadius" => 0,
+ "bottomElementAroundRadius" => 0,
+ "margin" => [
+ "top" => 0,
+ "bottom" => 0,
+ "both" => 15
+ ]
+ ],
+ [
+ "style" => "style-12",
+ "styleName" => "风格12",
+ "text" => "常用工具",
+ "link" => [
+ "name" => ""
+ ],
+ "fontSize" => 17,
+ "fontWeight" => 'bold',
+ "subTitle" => [
+ "fontSize" => 14,
+ "text" => "",
+ "isElementShow" => true,
+ "color" => "#999999",
+ "bgColor" => "#303133"
+ ],
+ "more" => [
+ "text" => "",
+ "link" => [
+ "name" => ""
+ ],
+ "isShow" => 0,
+ "isElementShow" => true,
+ "color" => "#999999"
+ ],
+ "id" => "405rb6vv3rq0",
+ 'addonName' => '',
+ "componentName" => "Text",
+ "componentTitle" => "标题",
+ "isDelete" => 0,
+ "pageBgColor" => "",
+ "textColor" => "#303133",
+ "componentBgColor" => "#FFFFFF",
+ "componentAngle" => "round",
+ "topAroundRadius" => 9,
+ "bottomAroundRadius" => 0,
+ "topElementAroundRadius" => 0,
+ "bottomElementAroundRadius" => 0,
+ "margin" => [
+ "top" => 15,
+ "bottom" => 0,
+ "both" => 15
+ ]
+ ],
+ [
+ "mode" => "graphic",
+ "type" => "img",
+ "showStyle" => "fixed",
+ "ornament" => [
+ "type" => "default",
+ "color" => "#EDEDED"
+ ],
+ "rowCount" => 4,
+ "pageCount" => 2,
+ "carousel" => [
+ "type" => "circle",
+ "color" => "#FFFFFF"
+ ],
+ "imageSize" => 30,
+ "aroundRadius" => 0,
+ "font" => [
+ "size" => 13,
+ "weight" => 'normal',
+ "color" => "#303133"
+ ],
+ "list" => [
+ [
+ "title" => "个人资料",
+ "imageUrl" => "public/uniapp/member/index/menu/default_person.png",
+ "iconType" => "img",
+ "style" => [
+ "fontSize" => "60",
+ "iconBgColor" => [],
+ "iconBgColorDeg" => 0,
+ "iconBgImg" => "",
+ "bgRadius" => 0,
+ "iconColor" => [
+ "#000000"
+ ],
+ "iconColorDeg" => 0
+ ],
+ "link" => [
+ "name" => "MEMBER_INFO",
+ "title" => "个人资料",
+ "wap_url" => "/pages_tool/member/info",
+ "parent" => "MALL_LINK"
+ ],
+ "label" => [
+ "control" => false,
+ "text" => "热门",
+ "textColor" => "#FFFFFF",
+ "bgColorStart" => "#F83287",
+ "bgColorEnd" => "#FE3423"
+ ],
+ "icon" => "",
+ "id" => "10rhv0x6phhc0"
+ ],
+ [
+ "title" => "收货地址",
+ "imageUrl" => "public/uniapp/member/index/menu/default_address.png",
+ "iconType" => "img",
+ "style" => [
+ "fontSize" => "60",
+ "iconBgColor" => [],
+ "iconBgColorDeg" => 0,
+ "iconBgImg" => "",
+ "bgRadius" => 0,
+ "iconColor" => [
+ "#000000"
+ ],
+ "iconColorDeg" => 0
+ ],
+ "link" => [
+ "name" => "SHIPPING_ADDRESS",
+ "title" => "收货地址",
+ "wap_url" => "/pages_tool/member/address",
+ "parent" => "MALL_LINK"
+ ],
+ "label" => [
+ "control" => false,
+ "text" => "热门",
+ "textColor" => "#FFFFFF",
+ "bgColorStart" => "#F83287",
+ "bgColorEnd" => "#FE3423"
+ ],
+ "icon" => "",
+ "id" => "1n8gycn6xqe80"
+ ],
+ [
+ "title" => "我的关注",
+ "imageUrl" => "public/uniapp/member/index/menu/default_like.png",
+ "iconType" => "img",
+ "style" => [
+ "fontSize" => "60",
+ "iconBgColor" => [],
+ "iconBgColorDeg" => 0,
+ "iconBgImg" => "",
+ "bgRadius" => 0,
+ "iconColor" => [
+ "#000000"
+ ],
+ "iconColorDeg" => 0
+ ],
+ "link" => [
+ "name" => "ATTENTION",
+ "title" => "我的关注",
+ "wap_url" => "/pages_tool/member/collection",
+ "parent" => "MALL_LINK"
+ ],
+ "label" => [
+ "control" => false,
+ "text" => "热门",
+ "textColor" => "#FFFFFF",
+ "bgColorStart" => "#F83287",
+ "bgColorEnd" => "#FE3423"
+ ],
+ "icon" => "",
+ "id" => "cnamoch6cvk0"
+ ],
+ [
+ "title" => "我的足迹",
+ "imageUrl" => "public/uniapp/member/index/menu/default_toot.png",
+ "iconType" => "img",
+ "style" => [
+ "fontSize" => "60",
+ "iconBgColor" => [],
+ "iconBgColorDeg" => 0,
+ "iconBgImg" => "",
+ "bgRadius" => 0,
+ "iconColor" => [
+ "#000000"
+ ],
+ "iconColorDeg" => 0
+ ],
+ "link" => [
+ "name" => "FOOTPRINT",
+ "title" => "我的足迹",
+ "wap_url" => "/pages_tool/member/footprint",
+ "parent" => "MALL_LINK"
+ ],
+ "label" => [
+ "control" => false,
+ "text" => "热门",
+ "textColor" => "#FFFFFF",
+ "bgColorStart" => "#F83287",
+ "bgColorEnd" => "#FE3423"
+ ],
+ "icon" => "",
+ "id" => "drf3hi3slo00"
+ ],
+ [
+ "title" => "账户列表",
+ "imageUrl" => "public/uniapp/member/index/menu/default_cash.png",
+ "iconType" => "img",
+ "style" => "",
+ "link" => [
+ "name" => "ACCOUNT",
+ "title" => "账户列表",
+ "wap_url" => "/pages_tool/member/account",
+ "parent" => "MALL_LINK"
+ ],
+ "label" => [
+ "control" => false,
+ "text" => "热门",
+ "textColor" => "#FFFFFF",
+ "bgColorStart" => "#F83287",
+ "bgColorEnd" => "#FE3423"
+ ],
+ "iconfont" => [
+ "value" => "",
+ "color" => ""
+ ],
+ "id" => "1l4axfhbayqo0"
+ ],
+ [
+ "title" => "优惠券",
+ "imageUrl" => "public/uniapp/member/index/menu/default_discount.png",
+ "iconType" => "img",
+ "style" => "",
+ "link" => [
+ "name" => "COUPON",
+ "title" => "优惠券",
+ "wap_url" => "/pages_tool/member/coupon",
+ "parent" => "MALL_LINK"
+ ],
+ "label" => [
+ "control" => false,
+ "text" => "热门",
+ "textColor" => "#FFFFFF",
+ "bgColorStart" => "#F83287",
+ "bgColorEnd" => "#FE3423"
+ ],
+ "iconfont" => [
+ "value" => "",
+ "color" => ""
+ ],
+ "id" => "1tnu0vihrnq80"
+ ],
+ [
+ "title" => "签到",
+ "imageUrl" => "public/uniapp/member/index/menu/default_sign.png",
+ "iconType" => "img",
+ "style" => "",
+ "link" => [
+ "name" => "SIGN_IN",
+ "title" => "签到",
+ "wap_url" => "/pages_tool/member/signin",
+ "parent" => "MARKETING_LINK"
+ ],
+ "label" => [
+ "control" => false,
+ "text" => "热门",
+ "textColor" => "#FFFFFF",
+ "bgColorStart" => "#F83287",
+ "bgColorEnd" => "#FE3423"
+ ],
+ "iconfont" => [
+ "value" => "",
+ "color" => ""
+ ],
+ "id" => "hodjcxowf8g0"
+ ],
+ [
+ "title" => "我的拼单",
+ "imageUrl" => "public/uniapp/member/index/menu/default_store.png",
+ "iconType" => "img",
+ "style" => "",
+ "link" => [
+ "name" => "MY_PINTUAN",
+ "title" => "我的拼团",
+ "wap_url" => "/pages_promotion/pintuan/my_spell",
+ "parent" => "MARKETING_LINK"
+ ],
+ "label" => [
+ "control" => false,
+ "text" => "热门",
+ "textColor" => "#FFFFFF",
+ "bgColorStart" => "#F83287",
+ "bgColorEnd" => "#FE3423"
+ ],
+ "iconfont" => [
+ "value" => "",
+ "color" => ""
+ ],
+ "id" => "uoarcfsleio0"
+ ],
+ [
+ "title" => "积分兑换",
+ "imageUrl" => "public/uniapp/member/index/menu/default_point_recond.png",
+ "iconType" => "img",
+ "style" => "",
+ "link" => [
+ "name" => "INTEGRAL_CONVERSION",
+ "title" => "积分兑换",
+ "wap_url" => "/pages_promotion/point/order_list",
+ "parent" => "MARKETING_LINK"
+ ],
+ "label" => [
+ "control" => false,
+ "text" => "热门",
+ "textColor" => "#FFFFFF",
+ "bgColorStart" => "#F83287",
+ "bgColorEnd" => "#FE3423"
+ ],
+ "iconfont" => [
+ "value" => "",
+ "color" => ""
+ ],
+ "id" => "rnyw8xo5rdc0"
+ ],
+ [
+ "title" => "分销中心",
+ "imageUrl" => "public/uniapp/member/index/menu/default_fenxiao.png",
+ "iconType" => "img",
+ "style" => "",
+ "link" => [
+ "name" => "DISTRIBUTION_CENTRE",
+ "title" => "分销中心",
+ "wap_url" => "/pages_promotion/fenxiao/index",
+ "parent" => "MARKETING_LINK"
+ ],
+ "label" => [
+ "control" => false,
+ "text" => "热门",
+ "textColor" => "#FFFFFF",
+ "bgColorStart" => "#F83287",
+ "bgColorEnd" => "#FE3423"
+ ],
+ "iconfont" => [
+ "value" => "",
+ "color" => ""
+ ],
+ "id" => "yevac1grnlc0"
+ ],
+ [
+ "title" => "我的砍价",
+ "imageUrl" => "public/uniapp/member/index/menu/default_bargain.png",
+ "iconType" => "img",
+ "style" => "",
+ "link" => [
+ "name" => "MY_BARGAIN",
+ "title" => "我的砍价",
+ "wap_url" => "/pages_promotion/bargain/my_bargain",
+ "parent" => "MARKETING_LINK"
+ ],
+ "label" => [
+ "control" => false,
+ "text" => "热门",
+ "textColor" => "#FFFFFF",
+ "bgColorStart" => "#F83287",
+ "bgColorEnd" => "#FE3423"
+ ],
+ "iconfont" => [
+ "value" => "",
+ "color" => ""
+ ],
+ "id" => "13uz22sbag000"
+ ],
+ [
+ "title" => "邀请有礼",
+ "imageUrl" => "public/uniapp/member/index/menu/default_memberrecommend.png",
+ "iconType" => "img",
+ "style" => "",
+ "link" => [
+ "name" => "MEMBER_RECOMMEND",
+ "title" => "邀请有礼",
+ "wap_url" => "/pages_tool/member/invite_friends",
+ "parent" => "MARKETING_LINK"
+ ],
+ "label" => [
+ "control" => false,
+ "text" => "热门",
+ "textColor" => "#FFFFFF",
+ "bgColorStart" => "#F83287",
+ "bgColorEnd" => "#FE3423"
+ ],
+ "iconfont" => [
+ "value" => "",
+ "color" => ""
+ ],
+ "id" => "1h34nmfisge80"
+ ],
+ [
+ "title" => "我的预售",
+ "imageUrl" => "public/uniapp/member/index/menu/my_presale.png",
+ "iconType" => "img",
+ "style" => "",
+ "link" => [
+ "name" => "PRESALE",
+ "title" => "我的预售",
+ "wap_url" => "/pages_promotion/presale/order_list",
+ "parent" => "MARKETING_LINK"
+ ],
+ "label" => [
+ "control" => false,
+ "text" => "热门",
+ "textColor" => "#FFFFFF",
+ "bgColorStart" => "#F83287",
+ "bgColorEnd" => "#FE3423"
+ ],
+ "iconfont" => [
+ "value" => "",
+ "color" => ""
+ ],
+ "id" => "1a3cqyziwqdc0"
+ ],
+ [
+ "title" => "我的礼品卡",
+ "imageUrl" => "public/uniapp/member/index/menu/my_giftcard.png",
+ "iconType" => "img",
+ "style" => "",
+ "link" => [
+ "name" => "GIFTCARD",
+ "title" => "我的礼品卡",
+ "wap_url" => "/pages_promotion/giftcard/member",
+ "parent" => "MARKETING_LINK"
+ ],
+ "label" => [
+ "control" => false,
+ "text" => "热门",
+ "textColor" => "#FFFFFF",
+ "bgColorStart" => "#F83287",
+ "bgColorEnd" => "#FE3423"
+ ],
+ "iconfont" => [
+ "value" => "",
+ "color" => ""
+ ],
+ "id" => "1es42rgg2mhs0"
+ ],
+ [
+ "title" => "好友瓜分券",
+ "imageUrl" => "public/uniapp/member/index/menu/my_divideticket.png",
+ "iconType" => "img",
+ "style" => "",
+ "link" => [
+ "name" => "DIVIDETICKET",
+ "title" => "我的好友瓜分券",
+ "wap_url" => "/pages_promotion/divideticket/my_guafen",
+ "parent" => "MARKETING_LINK"
+ ],
+ "label" => [
+ "control" => false,
+ "text" => "热门",
+ "textColor" => "#FFFFFF",
+ "bgColorStart" => "#F83287",
+ "bgColorEnd" => "#FE3423"
+ ],
+ "iconfont" => [
+ "value" => "",
+ "color" => ""
+ ],
+ "id" => "14rxg7u5yu2k0"
+ ],
+ [
+ "title" => "拼团返利",
+ "imageUrl" => "public/uniapp/member/index/menu/my_pinfan.png",
+ "iconType" => "img",
+ "style" => "",
+ "link" => [
+ "name" => "PINFAN",
+ "title" => "我的拼团返利",
+ "wap_url" => "/pages_promotion/pinfan/my_rebate",
+ "parent" => "MARKETING_LINK"
+ ],
+ "label" => [
+ "control" => false,
+ "text" => "热门",
+ "textColor" => "#FFFFFF",
+ "bgColorStart" => "#F83287",
+ "bgColorEnd" => "#FE3423"
+ ],
+ "iconfont" => [
+ "value" => "",
+ "color" => ""
+ ],
+ "id" => "20eeayo377xc0"
+ ],
+ [
+ "title" => "裂变红包",
+ "imageUrl" => "public/uniapp/member/index/menu/my_hongbao.png",
+ "iconType" => "img",
+ "style" => "",
+ "link" => [
+ "name" => "HONGBAO",
+ "title" => "我的裂变红包",
+ "wap_url" => "/pages_tool/hongbao/my_hongbao",
+ "parent" => "MARKETING_LINK"
+ ],
+ "label" => [
+ "control" => false,
+ "text" => "热门",
+ "textColor" => "#FFFFFF",
+ "bgColorStart" => "#F83287",
+ "bgColorEnd" => "#FE3423"
+ ],
+ "iconfont" => [
+ "value" => "",
+ "color" => ""
+ ],
+ "id" => "nbthjkdt5c00"
+ ],
+ [
+ "title" => "盲盒",
+ "imageUrl" => "public/uniapp/member/index/menu/my_box.png",
+ "iconType" => "img",
+ "style" => "",
+ "link" => [
+ "name" => "BLINDBOX",
+ "title" => "我的盲盒",
+ "wap_url" => "/pages_promotion/blindbox/my_box",
+ "parent" => "MARKETING_LINK"
+ ],
+ "label" => [
+ "control" => false,
+ "text" => "热门",
+ "textColor" => "#FFFFFF",
+ "bgColorStart" => "#F83287",
+ "bgColorEnd" => "#FE3423"
+ ],
+ "iconfont" => [
+ "value" => "",
+ "color" => ""
+ ],
+ "id" => "1i61b1fdeasg0"
+ ]
+ ],
+ "id" => "5ywbzsnigpw0",
+ 'addonName' => '',
+ "componentName" => "GraphicNav",
+ "componentTitle" => "图文导航",
+ "isDelete" => 0,
+ "pageBgColor" => "",
+ "componentBgColor" => "#FFFFFF",
+ "componentAngle" => "round",
+ "topAroundRadius" => 0,
+ "bottomAroundRadius" => 9,
+ "topElementAroundRadius" => 0,
+ "bottomElementAroundRadius" => 0,
+ "margin" => [
+ "top" => 0,
+ "bottom" => 0,
+ "both" => 15
+ ]
+ ]
+ ]
+ ]
+ ]
+ ]
+
];
\ No newline at end of file
diff --git a/src/addon/diy_default1/config/info.php b/src/addon/diy_default1/config/info.php
index d30ffcde2..3b341b78b 100644
--- a/src/addon/diy_default1/config/info.php
+++ b/src/addon/diy_default1/config/info.php
@@ -1,21 +1,12 @@
- 'diy_default1',
- 'title' => '官方模板一',
- 'description' => '官方默认模板(一)',
- 'type' => 'system', //插件类型 system :系统插件(自动安装), business:业务插件 promotion:营销插件 tool:工具插件
- 'status' => 1,
- 'author' => '',
- 'version' => '5.3.1',
- 'version_no' => '525231212001',
- 'content' => '',
+ 'diy_default1',
+ 'title' => '官方模板一',
+ 'description' => '官方默认模板(一)',
+ 'type' => 'system', //插件类型 system :系统插件(自动安装), business:业务插件 promotion:营销插件 tool:工具插件
+ 'status' => 1,
+ 'author' => '',
+ 'version' => '5.3.1',
+ 'version_no' => '525231212001',
+ 'content' => '',
];
\ No newline at end of file
diff --git a/src/addon/diy_default1/event/Install.php b/src/addon/diy_default1/event/Install.php
index 91bf44562..a6867209e 100644
--- a/src/addon/diy_default1/event/Install.php
+++ b/src/addon/diy_default1/event/Install.php
@@ -1,27 +1,18 @@
- '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
- 'template' => [],
-
- // 后台自定义组件——装修
- 'util' => [],
-
- // 自定义页面路径
- 'link' => [],
-
- // 自定义图标库
- 'icon_library' => [],
-
- // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
- 'component' => [],
-
- // uni-app 页面,多个逗号隔开
- 'pages' => [],
-
- // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
- 'info' => [
- 'title' => '官方模板二', // 模板名称
- 'name' => 'official_default_plane', // 模板标识
- 'cover' => 'addon/diy_default2/shop/view/public/img/cover.png', // 模板封面图
- 'preview' => 'addon/diy_default2/shop/view/public/img/preview.png', // 模板预览图
- 'desc' => '商城简约而不失时尚,适合大部分商城运营。', // 模板描述
- ],
-
- // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
- 'theme' => [],
-
- // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
- 'data' => [
- [
- 'title' => '官方模板二',
- 'name' => "DIY_VIEW_INDEX",
- 'value' => [
- "global" => [
- "title" => "官方模板二",
- "pageBgColor" => "#F3F3F3",
- "topNavColor" => "#FFFFFF",
- "topNavBg" => false,
- "navBarSwitch" => true,
- "textNavColor" => "#333333",
- "topNavImg" => "",
- "moreLink" => [
- "name" => ""
- ],
- "openBottomNav" => true,
- "navStyle" => 1,
- "textImgPosLink" => "center",
- "mpCollect" => false,
- "popWindow" => [
- "imageUrl" => "",
- "count" => -1,
- "show" => 0,
- "link" => [
- "name" => ""
- ],
- "imgWidth" => "",
- "imgHeight" => ""
- ],
- "bgUrl" => "",
- "imgWidth" => "",
- "imgHeight" => "",
- "template" => [
- "pageBgColor" => "",
- "textColor" => "#303133",
- "componentBgColor" => "",
- "componentAngle" => "round",
- "topAroundRadius" => 0,
- "bottomAroundRadius" => 0,
- "elementBgColor" => "",
- "elementAngle" => "round",
- "topElementAroundRadius" => 0,
- "bottomElementAroundRadius" => 0,
- "margin" => [
- "top" => 0,
- "bottom" => 0,
- "both" => 0
- ]
- ]
- ],
- "value" => [
- [
- "id" => "5wtw72w1wj80",
- 'addonName' => '',
- "componentName" => "Search",
- "componentTitle" => "搜索框",
- "isDelete" => 0,
- "topAroundRadius" => 0,
- "bottomAroundRadius" => 0,
- "topElementAroundRadius" => 0,
- "bottomElementAroundRadius" => 0,
- "margin" => [
- "top" => 10,
- "bottom" => 10,
- "both" => 12
- ],
- "title" => "请输入搜索关键词",
- "textAlign" => "left",
- "borderType" => 2,
- "searchImg" => "",
- "searchStyle" => 1,
- "searchLink" => [
- "name" => ""
- ],
- "pageBgColor" => "#FFFFFF",
- "textColor" => "#303133",
- "componentBgColor" => "",
- "elementBgColor" => "#F6F9FF",
- "iconType" => "img",
- "icon" => "",
- "style" => [
- "fontSize" => "60",
- "iconBgColor" => [],
- "iconBgColorDeg" => 0,
- "iconBgImg" => "",
- "bgRadius" => 0,
- "iconColor" => [
- "#000000"
- ],
- "iconColorDeg" => 0
- ],
- "imageUrl" => "",
- "positionWay" => "static"
- ],
- [
- "id" => "2o7za2qmi900",
- "list" => [
- [
- "link" => [
- "name" => ""
- ],
- "imageUrl" => 'addon/diy_default2/shop/view/public/img/banner.png',
- "imgWidth" => "750",
- "imgHeight" => "320",
- "id" => "17vtbffhsvsw0"
- ]
- ],
- "indicatorIsShow" => true,
- "indicatorColor" => "#ffffff",
- "carouselStyle" => "circle",
- "indicatorLocation" => "center",
- 'addonName' => '',
- "componentName" => "ImageAds",
- "componentTitle" => "图片广告",
- "isDelete" => 0,
- "pageBgColor" => "",
- "componentBgColor" => "",
- "componentAngle" => "round",
- "topAroundRadius" => 0,
- "bottomAroundRadius" => 0,
- "topElementAroundRadius" => 0,
- "bottomElementAroundRadius" => 0,
- "margin" => [
- "top" => 0,
- "bottom" => 0,
- "both" => 0
- ]
- ],
- [
- "id" => "113ohzka4n40",
- "mode" => "graphic",
- "type" => "img",
- "showStyle" => "fixed",
- "ornament" => [
- "type" => "default",
- "color" => "#EDEDED"
- ],
- "rowCount" => 5,
- "pageCount" => 2,
- "carousel" => [
- "type" => "circle",
- "color" => "#FFFFFF"
- ],
- "imageSize" => 40,
- "aroundRadius" => 25,
- "font" => [
- "size" => 14,
- "weight" => 500,
- "color" => "#303133"
- ],
- "list" => [
- [
- "title" => "团购",
- "icon" => "icondiy icon-system-groupbuy-nav",
- "imageUrl" => "",
- "iconType" => "icon",
- "style" => [
- "fontSize" => 50,
- "iconBgColor" => [
- "#FF5715",
- "#FF4116"
- ],
- "iconBgColorDeg" => 90,
- "iconBgImg" => "public/static/ext/diyview/img/icon_bg/bg_04.png",
- "bgRadius" => 19,
- "iconColor" => [
- "#FFFFFF"
- ],
- "iconColorDeg" => 0
- ],
- "link" => [
- "name" => "GROUPBUY_PREFECTURE",
- "title" => "团购专区",
- "wap_url" => "/pages_promotion/groupbuy/list",
- "parent" => "MARKETING_LINK"
- ],
- "label" => [
- "control" => false,
- "text" => "热门",
- "textColor" => "#FFFFFF",
- "bgColorStart" => "#F83287",
- "bgColorEnd" => "#FE3423"
- ],
- "id" => "1e67vek25rhc0"
- ],
- [
- "title" => "拼团",
- "icon" => "icondiy icon-system-pintuan-nav",
- "imageUrl" => "",
- "iconType" => "icon",
- "style" => [
- "fontSize" => 50,
- "iconBgColor" => [
- "#58BCFF",
- "#1379FF"
- ],
- "iconBgColorDeg" => 90,
- "iconBgImg" => "public/static/ext/diyview/img/icon_bg/bg_04.png",
- "bgRadius" => 19,
- "iconColor" => [
- "#FFFFFF"
- ],
- "iconColorDeg" => 0
- ],
- "link" => [
- "name" => "PINTUAN_PREFECTURE",
- "title" => "拼团专区",
- "wap_url" => "/pages_promotion/pintuan/list",
- "parent" => "MARKETING_LINK"
- ],
- "label" => [
- "control" => false,
- "text" => "热门",
- "textColor" => "#FFFFFF",
- "bgColorStart" => "#F83287",
- "bgColorEnd" => "#FE3423"
- ],
- "id" => "b1kn8ktvs440"
- ],
- [
- "title" => "秒杀",
- "icon" => "icondiy icon-system-seckill-time",
- "imageUrl" => "",
- "iconType" => "icon",
- "style" => [
- "fontSize" => 50,
- "iconBgColor" => [
- "#FF9100"
- ],
- "iconBgColorDeg" => 0,
- "iconBgImg" => "public/static/ext/diyview/img/icon_bg/bg_04.png",
- "bgRadius" => 19,
- "iconColor" => [
- "#FFFFFF"
- ],
- "iconColorDeg" => 0
- ],
- "link" => [
- "name" => "SECKILL_PREFECTURE",
- "title" => "秒杀专区",
- "wap_url" => "/pages_promotion/seckill/list",
- "parent" => "MARKETING_LINK"
- ],
- "label" => [
- "control" => true,
- "text" => "热门",
- "textColor" => "#FFFFFF",
- "bgColorStart" => "#F83288",
- "bgColorEnd" => "#FE3523"
- ],
- "id" => "1cgq3tjxkc800"
- ],
- [
- "title" => " 积分",
- "icon" => "icondiy icon-system-point-nav",
- "imageUrl" => "",
- "iconType" => "icon",
- "style" => [
- "fontSize" => 50,
- "iconBgColor" => [
- "#02CC96",
- "#43EEC9"
- ],
- "iconBgColorDeg" => 90,
- "iconBgImg" => "public/static/ext/diyview/img/icon_bg/bg_04.png",
- "bgRadius" => 19,
- "iconColor" => [
- "#FFFFFF"
- ],
- "iconColorDeg" => 0
- ],
- "link" => [
- "name" => "INTEGRAL_STORE",
- "title" => "积分商城",
- "wap_url" => "/pages_promotion/point/list",
- "parent" => "MARKETING_LINK"
- ],
- "label" => [
- "control" => false,
- "text" => "热门",
- "textColor" => "#FFFFFF",
- "bgColorStart" => "#F83287",
- "bgColorEnd" => "#FE3423"
- ],
- "id" => "1v6a5arxdyqo0"
- ],
- [
- "title" => "专题活动",
- "icon" => "icondiy icon-system-topic-nav",
- "imageUrl" => "",
- "iconType" => "icon",
- "style" => [
- "fontSize" => 50,
- "iconBgColor" => [
- "#BE79FF",
- "#7B00FF"
- ],
- "iconBgColorDeg" => 90,
- "iconBgImg" => "public/static/ext/diyview/img/icon_bg/bg_04.png",
- "bgRadius" => 19,
- "iconColor" => [
- "#FFFFFF"
- ],
- "iconColorDeg" => 0
- ],
- "link" => [
- "name" => "THEMATIC_ACTIVITIES_LIST",
- "title" => "专题活动列表",
- "wap_url" => "/pages_promotion/topics/list",
- "parent" => "MARKETING_LINK"
- ],
- "label" => [
- "control" => false,
- "text" => "热门",
- "textColor" => "#FFFFFF",
- "bgColorStart" => "#F83287",
- "bgColorEnd" => "#FE3423"
- ],
- "id" => "x7bqn51r8hs0"
- ],
- [
- "title" => "砍价",
- "icon" => "icondiy icon-system-bargain-nav",
- "imageUrl" => "",
- "iconType" => "icon",
- "style" => [
- "fontSize" => 50,
- "iconBgColor" => [
- "#5BBDFF",
- "#2E87FD"
- ],
- "iconBgColorDeg" => 90,
- "iconBgImg" => "public/static/ext/diyview/img/icon_bg/bg_04.png",
- "bgRadius" => 19,
- "iconColor" => [
- "#FFFFFF"
- ],
- "iconColorDeg" => 0
- ],
- "link" => [
- "name" => "BARGAIN_PREFECTURE",
- "title" => "砍价专区",
- "wap_url" => "/pages_promotion/bargain/list",
- "parent" => "MARKETING_LINK"
- ],
- "label" => [
- "control" => false,
- "text" => "热门",
- "textColor" => "#FFFFFF",
- "bgColorStart" => "#F83287",
- "bgColorEnd" => "#FE3423"
- ],
- "id" => "140zkvoseuw00"
- ],
- [
- "title" => "领券",
- "icon" => "icondiy icon-system-get-coupon",
- "imageUrl" => "",
- "iconType" => "icon",
- "style" => [
- "fontSize" => 50,
- "iconBgColor" => [
- "#BE79FF",
- "#7B00FF"
- ],
- "iconBgColorDeg" => 90,
- "iconBgImg" => "public/static/ext/diyview/img/icon_bg/bg_04.png",
- "bgRadius" => 19,
- "iconColor" => [
- "#FFFFFF"
- ],
- "iconColorDeg" => 0
- ],
- "link" => [
- "name" => "COUPON_PREFECTURE",
- "title" => "优惠券专区",
- "wap_url" => "/pages_tool/goods/coupon",
- "parent" => "MARKETING_LINK"
- ],
- "label" => [
- "control" => false,
- "text" => "热门",
- "textColor" => "#FFFFFF",
- "bgColorStart" => "#F83287",
- "bgColorEnd" => "#FE3423"
- ],
- "id" => "5sjwa1q2t5k0"
- ],
- [
- "title" => "文章",
- "icon" => "icondiy icon-system-article-nav",
- "imageUrl" => "",
- "iconType" => "icon",
- "style" => [
- "fontSize" => 50,
- "iconBgColor" => [
- "#FF8052",
- "#FF4830"
- ],
- "iconBgColorDeg" => 90,
- "iconBgImg" => "public/static/ext/diyview/img/icon_bg/bg_04.png",
- "bgRadius" => 19,
- "iconColor" => [
- "#FFFFFF"
- ],
- "iconColorDeg" => 0
- ],
- "link" => [
- "name" => "SHOPPING_ARTICLE",
- "title" => "文章",
- "wap_url" => "/pages_tool/article/list",
- "parent" => "MALL_LINK"
- ],
- "label" => [
- "control" => false,
- "text" => "热门",
- "textColor" => "#FFFFFF",
- "bgColorStart" => "#F83287",
- "bgColorEnd" => "#FE3423"
- ],
- "id" => "4aforgjwmdw0"
- ],
- [
- "title" => "公告",
- "icon" => "icondiy icon-system-notice-nav",
- "imageUrl" => "",
- "iconType" => "icon",
- "style" => [
- "fontSize" => 50,
- "iconBgColor" => [
- "#FFCC26",
- "#FF9F29"
- ],
- "iconBgColorDeg" => 90,
- "iconBgImg" => "public/static/ext/diyview/img/icon_bg/bg_04.png",
- "bgRadius" => 19,
- "iconColor" => [
- "#FFFFFF"
- ],
- "iconColorDeg" => 0
- ],
- "link" => [
- "name" => "SHOPPING_NOTICE",
- "title" => "公告",
- "wap_url" => "/pages_tool/notice/list",
- "parent" => "MALL_LINK"
- ],
- "label" => [
- "control" => false,
- "text" => "热门",
- "textColor" => "#FFFFFF",
- "bgColorStart" => "#F83287",
- "bgColorEnd" => "#FE3423"
- ],
- "id" => "myo9oz46yj40"
- ],
- [
- "title" => "帮助",
- "icon" => "icondiy icon-system-help",
- "imageUrl" => "",
- "iconType" => "icon",
- "style" => [
- "fontSize" => 50,
- "iconBgColor" => [
- "#02CC96",
- "#43EEC9"
- ],
- "iconBgColorDeg" => 90,
- "iconBgImg" => "public/static/ext/diyview/img/icon_bg/bg_04.png",
- "bgRadius" => 19,
- "iconColor" => [
- "#FFFFFF"
- ],
- "iconColorDeg" => 0
- ],
- "link" => [
- "name" => "SHOPPING_HELP",
- "title" => "帮助",
- "wap_url" => "/pages_tool/help/list",
- "parent" => "MALL_LINK"
- ],
- "label" => [
- "control" => false,
- "text" => "热门",
- "textColor" => "#FFFFFF",
- "bgColorStart" => "#F83287",
- "bgColorEnd" => "#FE3423"
- ],
- "id" => "h4nt4orc9i80"
- ]
- ],
- 'addonName' => '',
- "componentName" => "GraphicNav",
- "componentTitle" => "图文导航",
- "isDelete" => 0,
- "pageBgColor" => "#FFFFFF",
- "componentBgColor" => "",
- "componentAngle" => "round",
- "topAroundRadius" => 0,
- "bottomAroundRadius" => 0,
- "topElementAroundRadius" => 0,
- "bottomElementAroundRadius" => 0,
- "margin" => [
- "top" => 0,
- "bottom" => 0,
- "both" => 12
- ]
- ],
- [
- "id" => "3tegcfvyijk0",
- "style" => "5",
- "sources" => "initial",
- "styleName" => "风格五",
- "couponIds" => [],
- "count" => 6,
- "previewList" => [],
- "nameColor" => "#303133",
- "moneyColor" => "#FF0000",
- "limitColor" => "#999999",
- "btnStyle" => [
- "textColor" => "#FFFFFF",
- "bgColor" => "#303133",
- "text" => "立即领取",
- "aroundRadius" => 5,
- "isBgColor" => true,
- "isAroundRadius" => true
- ],
- "bgColor" => "",
- "isName" => true,
- "couponBgColor" => "",
- "couponBgUrl" => "",
- "couponType" => "img",
- "ifNeedBg" => true,
- 'addonName' => 'coupon',
- "componentName" => "Coupon",
- "componentTitle" => "优惠券",
- "isDelete" => 0,
- "pageBgColor" => "",
- "topAroundRadius" => 0,
- "bottomAroundRadius" => 0,
- "elementBgColor" => "",
- "topElementAroundRadius" => 0,
- "bottomElementAroundRadius" => 0,
- "margin" => [
- "top" => 10,
- "bottom" => 10,
- "both" => 12
- ]
- ],
- [
- "id" => "3acr0xjm1c80",
- 'addonName' => '',
- "componentName" => "RubikCube",
- "componentTitle" => "魔方",
- "isDelete" => 0,
- "pageBgColor" => "",
- "componentBgColor" => "",
- "componentAngle" => "round",
- "topAroundRadius" => 10,
- "bottomAroundRadius" => 10,
- "topElementAroundRadius" => 0,
- "bottomElementAroundRadius" => 0,
- "margin" => [
- "top" => 0,
- "bottom" => 10,
- "both" => 12
- ],
- "list" => [
- [
- "imageUrl" => 'addon/diy_default2/shop/view/public/img/mf_left.png',
- "imgWidth" => "338",
- "imgHeight" => "450",
- "previewWidth" => 187.5,
- "previewHeight" => "249.63px",
- "link" => [
- "name" => ""
- ]
- ],
- [
- "imageUrl" => 'addon/diy_default2/shop/view/public/img/mf_right1.png',
- "imgWidth" => "354",
- "imgHeight" => "220",
- "previewWidth" => 187.5,
- "previewHeight" => "124.82px",
- "link" => [
- "name" => ""
- ]
- ],
- [
- "imageUrl" => 'addon/diy_default2/shop/view/public/img/mf_right2.png',
- "imgWidth" => "354",
- "imgHeight" => "22",
- "previewWidth" => 187.5,
- "previewHeight" => "124.82px",
- "link" => [
- "name" => ""
- ]
- ]
- ],
- "mode" => "row1-lt-of2-rt",
- "imageGap" => 10,
- "elementAngle" => "round"
- ],
- [
- "id" => "68p4o1plca80",
- "style" => "style-1",
- "sources" => "initial",
- "styleName" => "风格1",
- "count" => 6,
- 'addonName' => '',
- "componentName" => "GoodsRecommend",
- "componentTitle" => "商品推荐",
- "isDelete" => 0,
- "topAroundRadius" => 0,
- "bottomAroundRadius" => 0,
- "topElementAroundRadius" => 10,
- "bottomElementAroundRadius" => 10,
- "margin" => [
- "top" => 0,
- "bottom" => 10,
- "both" => 12
- ],
- "nameLineMode" => "single",
- "sortWay" => "default",
- "ornament" => [
- "type" => "default",
- "color" => "#EDEDED"
- ],
- "imgAroundRadius" => 0,
- "goodsNameStyle" => [
- "color" => "#303133",
- "control" => true,
- "fontWeight" => false,
- "support" => true
- ],
- "saleStyle" => [
- "color" => "#999CA7",
- "control" => true,
- "support" => true
- ],
- "theme" => "default",
- "priceStyle" => [
- "mainColor" => "#FF1544",
- "mainControl" => true,
- "lineColor" => "#999CA7",
- "lineControl" => false,
- "lineSupport" => false
- ],
- "goodsId" => [],
- "categoryId" => 0,
- "categoryName" => "请选择",
- "topStyle" => [
- "title" => "今日推荐",
- "subTitle" => "大家都在买",
- "icon" => [
- "value" => "icondiy icon-system-tuijian",
- "color" => "#FF3D3D",
- "bgColor" => ""
- ],
- "color" => "#303133",
- "subColor" => "#999CA7",
- "support" => true
- ],
- "bgUrl" => "",
- "pageBgColor" => "",
- "componentBgColor" => "",
- "componentAngle" => "round",
- "elementBgColor" => "#FFFFFF",
- "elementAngle" => "round",
- "labelStyle" => [
- "support" => false,
- "bgColor" => "#FF504D",
- "title" => "新人专享",
- "color" => "#FFFFFF"
- ]
- ],
- [
- "id" => "3moj09pl5c20",
- "style" => "style-1",
- "sources" => "initial",
- "count" => 6,
- "goodsId" => [],
- "ornament" => [
- "type" => "default",
- "color" => "#EDEDED"
- ],
- "nameLineMode" => "single",
- "template" => "row1-of1",
- "goodsMarginType" => "default",
- "goodsMarginNum" => 10,
- "btnStyle" => [
- "text" => "去秒杀",
- "textColor" => "#FFFFFF",
- "theme" => "default",
- "aroundRadius" => 25,
- "control" => true,
- "support" => true,
- "bgColorStart" => "#FF7B1D",
- "bgColorEnd" => "#FF1544"
- ],
- "imgAroundRadius" => 10,
- "saleStyle" => [
- "color" => "#999CA7",
- "control" => true,
- "support" => true
- ],
- "progressStyle" => [
- "control" => true,
- "support" => true,
- "currColor" => "#FDBE6C",
- "bgColor" => "#FCECD7"
- ],
- "titleStyle" => [
- "backgroundImage" => "addon/seckill/component/view/seckill/img/style_title_3_bg.png",
- "isShow" => true,
- "leftStyle" => "img",
- "leftImg" => "addon/seckill/component/view/seckill/img/style_title_3_name.png",
- "style" => "style-3",
- "styleName" => "风格3",
- "leftText" => "限时秒杀",
- "fontSize" => 16,
- "fontWeight" => true,
- "textColor" => "#FFFFFF",
- "bgColorStart" => "#FA6400",
- "bgColorEnd" => "#FF287A",
- "more" => "更多",
- "moreColor" => "#FFFFFF",
- "moreFontSize" => 12,
- "moreSupport" => true,
- "timeBgColor" => "",
- "timeImageUrl" => "",
- "colonColor" => "#FFFFFF",
- "numBgColorStart" => "#FFFFFF",
- "numBgColorEnd" => "#FFFFFF",
- "numTextColor" => "#FD3B54"
- ],
- "slideMode" => "scroll",
- "theme" => "default",
- "priceStyle" => [
- "mainColor" => "#FF1745",
- "mainControl" => true,
- "lineColor" => "#999CA7",
- "lineControl" => true,
- "lineSupport" => true
- ],
- "goodsNameStyle" => [
- "color" => "#303133",
- "control" => true,
- "fontWeight" => false
- ],
- 'addonName' => 'seckill',
- "componentName" => "Seckill",
- "componentTitle" => "秒杀",
- "isDelete" => 0,
- "pageBgColor" => "",
- "componentBgColor" => "",
- "componentAngle" => "round",
- "topAroundRadius" => 0,
- "bottomAroundRadius" => 0,
- "elementBgColor" => "#FFFFFF",
- "elementAngle" => "round",
- "topElementAroundRadius" => 0,
- "bottomElementAroundRadius" => 0,
- "margin" => [
- "top" => 0,
- "bottom" => 10,
- "both" => 12
- ]
- ],
- [
- "id" => "z9bdab3tm34",
- "style" => "style-1",
- "sources" => "initial",
- "count" => 6,
- "goodsId" => [],
- "ornament" => [
- "type" => "default",
- "color" => "#EDEDED"
- ],
- "nameLineMode" => "single",
- "template" => "horizontal-slide",
- "goodsMarginType" => "default",
- "goodsMarginNum" => 10,
- "btnStyle" => [
- "text" => "去拼团",
- "textColor" => "#FFFFFF",
- "theme" => "default",
- "aroundRadius" => 25,
- "control" => false,
- "support" => false,
- "bgColorStart" => "#FF1544",
- "bgColorEnd" => "#FF1544"
- ],
- "imgAroundRadius" => 10,
- "saleStyle" => [
- "color" => "#FF1544",
- "control" => false,
- "support" => false
- ],
- "groupStyle" => [
- "color" => "#FFFFFF",
- "control" => true,
- "support" => true,
- "bgColorStart" => "#FA2379",
- "bgColorEnd" => "#FF4F61"
- ],
- "priceStyle" => [
- "mainColor" => "#FF1544",
- "mainControl" => true,
- "lineColor" => "#999CA7",
- "lineControl" => true,
- "lineSupport" => true
- ],
- "slideMode" => "scroll",
- "theme" => "default",
- "goodsNameStyle" => [
- "color" => "#303133",
- "control" => true,
- "fontWeight" => false
- ],
- "titleStyle" => [
- "bgColorStart" => "#6236FF",
- "bgColorEnd" => "#0091FF",
- "isShow" => true,
- "leftStyle" => "img",
- "leftImg" => "addon/pintuan/component/view/pintuan/img/horizontal_slide_name.png",
- "style" => "style-1",
- "styleName" => "风格1",
- "leftText" => "超值拼团",
- "fontSize" => 16,
- "fontWeight" => true,
- "textColor" => "#FFFFFF",
- "more" => "查看更多",
- "moreColor" => "#FFFFFF",
- "moreFontSize" => 12,
- "backgroundImage" => "addon/pintuan/component/view/pintuan/img/horizontal_slide_bg.png"
- ],
- 'addonName' => 'pintuan',
- "componentName" => "Pintuan",
- "componentTitle" => "拼团",
- "isDelete" => 0,
- "pageBgColor" => "",
- "componentBgColor" => "#FFFFFF",
- "componentAngle" => "round",
- "topAroundRadius" => 0,
- "bottomAroundRadius" => 10,
- "elementBgColor" => "",
- "elementAngle" => "round",
- "topElementAroundRadius" => 0,
- "bottomElementAroundRadius" => 0,
- "margin" => [
- "top" => 0,
- "bottom" => 10,
- "both" => 12
- ]
- ],
- [
- "id" => "xwdnfttfj7k",
- "style" => "style-1",
- "sources" => "initial",
- "count" => 6,
- "goodsId" => [],
- "ornament" => [
- "type" => "default",
- "color" => "#EDEDED"
- ],
- "nameLineMode" => "single",
- "template" => "horizontal-slide",
- "goodsMarginType" => "default",
- "goodsMarginNum" => 10,
- "btnStyle" => [
- "text" => "立即抢购",
- "textColor" => "#FFFFFF",
- "theme" => "default",
- "aroundRadius" => 25,
- "control" => false,
- "support" => false,
- "bgColorStart" => "#FF7B1D",
- "bgColorEnd" => "#FF1544"
- ],
- "imgAroundRadius" => 5,
- "saleStyle" => [
- "color" => "#FFFFFF",
- "control" => true,
- "support" => true
- ],
- "slideMode" => "scroll",
- "theme" => "default",
- "goodsNameStyle" => [
- "color" => "#303133",
- "control" => true,
- "fontWeight" => false
- ],
- "priceStyle" => [
- "mainColor" => "#FF1745",
- "mainControl" => true,
- "lineColor" => "#999CA7",
- "lineControl" => true,
- "lineSupport" => true
- ],
- "titleStyle" => [
- "bgColorStart" => "#FF209D",
- "bgColorEnd" => "#B620E0",
- "isShow" => true,
- "leftStyle" => "img",
- "leftImg" => "",
- "style" => "style-1",
- "styleName" => "风格1",
- "leftText" => "疯狂砍价",
- "fontSize" => 16,
- "fontWeight" => true,
- "textColor" => "#FFFFFF",
- "more" => "更多",
- "moreColor" => "#FFFFFF",
- "moreFontSize" => 12,
- "backgroundImage" => ""
- ],
- 'addonName' => 'bargain',
- "componentName" => "Bargain",
- "componentTitle" => "砍价",
- "isDelete" => 0,
- "pageBgColor" => "",
- "componentBgColor" => "#FFFFFF",
- "componentAngle" => "round",
- "topAroundRadius" => 0,
- "bottomAroundRadius" => 10,
- "elementBgColor" => "",
- "elementAngle" => "round",
- "topElementAroundRadius" => 0,
- "bottomElementAroundRadius" => 0,
- "margin" => [
- "top" => 0,
- "bottom" => 10,
- "both" => 12
- ]
- ],
- [
- "id" => "5zj6d48bxks0",
- 'addonName' => '',
- "componentName" => "ImageAds",
- "componentTitle" => "图片广告",
- "isDelete" => 0,
- "pageBgColor" => "",
- "componentBgColor" => "",
- "componentAngle" => "round",
- "topAroundRadius" => 5,
- "bottomAroundRadius" => 5,
- "topElementAroundRadius" => 0,
- "bottomElementAroundRadius" => 0,
- "margin" => [
- "top" => 0,
- "bottom" => 10,
- "both" => 12
- ],
- "list" => [
- [
- "link" => [
- "name" => ""
- ],
- "imageUrl" => 'addon/diy_default2/shop/view/public/img/gg.png',
- "imgWidth" => "702",
- "imgHeight" => "252",
- "id" => "ccnb530uc5k0"
- ]
- ],
- "indicatorIsShow" => true,
- "indicatorColor" => "#ffffff",
- "carouselStyle" => "circle",
- "indicatorLocation" => "center"
- ],
- [
- "id" => "xwdnfttfj6k",
- "style" => "style-3",
- "sources" => "initial",
- "count" => 6,
- "goodsId" => [],
- "ornament" => [
- "type" => "default",
- "color" => "#EDEDED"
- ],
- "nameLineMode" => "multiple",
- "template" => "row1-of2",
- "goodsMarginType" => "default",
- "goodsMarginNum" => 6,
- "btnStyle" => [
- "fontWeight" => false,
- "padding" => 0,
- "cartEvent" => "detail",
- "text" => "购买",
- "textColor" => "#FFFFFF",
- "theme" => "default",
- "aroundRadius" => 25,
- "control" => false,
- "support" => false,
- "bgColor" => "#FF6A00",
- "style" => "button",
- "iconDiy" => [
- "iconType" => "icon",
- "icon" => "",
- "style" => [
- "fontSize" => "60",
- "iconBgColor" => [],
- "iconBgColorDeg" => 0,
- "iconBgImg" => "",
- "bgRadius" => 0,
- "iconColor" => [
- "#000000"
- ],
- "iconColorDeg" => 0
- ]
- ]
- ],
- "imgAroundRadius" => 0,
- "saleStyle" => [
- "color" => "#999CA7",
- "control" => true,
- "support" => true
- ],
- "slideMode" => "slide",
- "theme" => "default",
- "goodsNameStyle" => [
- "color" => "#303133",
- "control" => true,
- "fontWeight" => false
- ],
- "priceStyle" => [
- "mainColor" => "#FF6A00",
- "mainControl" => true,
- "lineColor" => "#999CA7",
- "lineControl" => false,
- "lineSupport" => false
- ],
- 'addonName' => '',
- "componentName" => "GoodsList",
- "componentTitle" => "商品列表",
- "isDelete" => 0,
- "pageBgColor" => "",
- "componentBgColor" => "",
- "componentAngle" => "round",
- "topAroundRadius" => 10,
- "bottomAroundRadius" => 10,
- "elementBgColor" => "#FFFFFF",
- "elementAngle" => "round",
- "topElementAroundRadius" => 10,
- "bottomElementAroundRadius" => 10,
- "margin" => [
- "top" => 0,
- "bottom" => 0,
- "both" => 12
- ],
- "categoryId" => 0,
- "categoryName" => "请选择",
- "sortWay" => "default",
- "tag" => [
- "text" => "隐藏",
- "value" => "hidden"
- ]
- ]
- ]
- ]
- ]
- ]
+ '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
+ 'template' => [],
+
+ // 后台自定义组件——装修
+ 'util' => [],
+
+ // 自定义页面路径
+ 'link' => [],
+
+ // 自定义图标库
+ 'icon_library' => [],
+
+ // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
+ 'component' => [],
+
+ // uni-app 页面,多个逗号隔开
+ 'pages' => [],
+
+ // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
+ 'info' => [
+ 'title' => '官方模板二', // 模板名称
+ 'name' => 'official_default_plane', // 模板标识
+ 'cover' => 'addon/diy_default2/shop/view/public/img/cover.png', // 模板封面图
+ 'preview' => 'addon/diy_default2/shop/view/public/img/preview.png', // 模板预览图
+ 'desc' => '商城简约而不失时尚,适合大部分商城运营。', // 模板描述
+ ],
+
+ // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
+ 'theme' => [],
+
+ // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
+ 'data' => [
+ [
+ 'title' => '官方模板二',
+ 'name' => "DIY_VIEW_INDEX",
+ 'value' => [
+ "global" => [
+ "title" => "官方模板二",
+ "pageBgColor" => "#F3F3F3",
+ "topNavColor" => "#FFFFFF",
+ "topNavBg" => false,
+ "navBarSwitch" => true,
+ "textNavColor" => "#333333",
+ "topNavImg" => "",
+ "moreLink" => [
+ "name" => ""
+ ],
+ "openBottomNav" => true,
+ "navStyle" => 1,
+ "textImgPosLink" => "center",
+ "mpCollect" => false,
+ "popWindow" => [
+ "imageUrl" => "",
+ "count" => -1,
+ "show" => 0,
+ "link" => [
+ "name" => ""
+ ],
+ "imgWidth" => "",
+ "imgHeight" => ""
+ ],
+ "bgUrl" => "",
+ "imgWidth" => "",
+ "imgHeight" => "",
+ "template" => [
+ "pageBgColor" => "",
+ "textColor" => "#303133",
+ "componentBgColor" => "",
+ "componentAngle" => "round",
+ "topAroundRadius" => 0,
+ "bottomAroundRadius" => 0,
+ "elementBgColor" => "",
+ "elementAngle" => "round",
+ "topElementAroundRadius" => 0,
+ "bottomElementAroundRadius" => 0,
+ "margin" => [
+ "top" => 0,
+ "bottom" => 0,
+ "both" => 0
+ ]
+ ]
+ ],
+ "value" => [
+ [
+ "id" => "5wtw72w1wj80",
+ 'addonName' => '',
+ "componentName" => "Search",
+ "componentTitle" => "搜索框",
+ "isDelete" => 0,
+ "topAroundRadius" => 0,
+ "bottomAroundRadius" => 0,
+ "topElementAroundRadius" => 0,
+ "bottomElementAroundRadius" => 0,
+ "margin" => [
+ "top" => 10,
+ "bottom" => 10,
+ "both" => 12
+ ],
+ "title" => "请输入搜索关键词",
+ "textAlign" => "left",
+ "borderType" => 2,
+ "searchImg" => "",
+ "searchStyle" => 1,
+ "searchLink" => [
+ "name" => ""
+ ],
+ "pageBgColor" => "#FFFFFF",
+ "textColor" => "#303133",
+ "componentBgColor" => "",
+ "elementBgColor" => "#F6F9FF",
+ "iconType" => "img",
+ "icon" => "",
+ "style" => [
+ "fontSize" => "60",
+ "iconBgColor" => [],
+ "iconBgColorDeg" => 0,
+ "iconBgImg" => "",
+ "bgRadius" => 0,
+ "iconColor" => [
+ "#000000"
+ ],
+ "iconColorDeg" => 0
+ ],
+ "imageUrl" => "",
+ "positionWay" => "static"
+ ],
+ [
+ "id" => "2o7za2qmi900",
+ "list" => [
+ [
+ "link" => [
+ "name" => ""
+ ],
+ "imageUrl" => 'addon/diy_default2/shop/view/public/img/banner.png',
+ "imgWidth" => "750",
+ "imgHeight" => "320",
+ "id" => "17vtbffhsvsw0"
+ ]
+ ],
+ "indicatorIsShow" => true,
+ "indicatorColor" => "#ffffff",
+ "carouselStyle" => "circle",
+ "indicatorLocation" => "center",
+ 'addonName' => '',
+ "componentName" => "ImageAds",
+ "componentTitle" => "图片广告",
+ "isDelete" => 0,
+ "pageBgColor" => "",
+ "componentBgColor" => "",
+ "componentAngle" => "round",
+ "topAroundRadius" => 0,
+ "bottomAroundRadius" => 0,
+ "topElementAroundRadius" => 0,
+ "bottomElementAroundRadius" => 0,
+ "margin" => [
+ "top" => 0,
+ "bottom" => 0,
+ "both" => 0
+ ]
+ ],
+ [
+ "id" => "113ohzka4n40",
+ "mode" => "graphic",
+ "type" => "img",
+ "showStyle" => "fixed",
+ "ornament" => [
+ "type" => "default",
+ "color" => "#EDEDED"
+ ],
+ "rowCount" => 5,
+ "pageCount" => 2,
+ "carousel" => [
+ "type" => "circle",
+ "color" => "#FFFFFF"
+ ],
+ "imageSize" => 40,
+ "aroundRadius" => 25,
+ "font" => [
+ "size" => 14,
+ "weight" => 500,
+ "color" => "#303133"
+ ],
+ "list" => [
+ [
+ "title" => "团购",
+ "icon" => "icondiy icon-system-groupbuy-nav",
+ "imageUrl" => "",
+ "iconType" => "icon",
+ "style" => [
+ "fontSize" => 50,
+ "iconBgColor" => [
+ "#FF5715",
+ "#FF4116"
+ ],
+ "iconBgColorDeg" => 90,
+ "iconBgImg" => "public/static/ext/diyview/img/icon_bg/bg_04.png",
+ "bgRadius" => 19,
+ "iconColor" => [
+ "#FFFFFF"
+ ],
+ "iconColorDeg" => 0
+ ],
+ "link" => [
+ "name" => "GROUPBUY_PREFECTURE",
+ "title" => "团购专区",
+ "wap_url" => "/pages_promotion/groupbuy/list",
+ "parent" => "MARKETING_LINK"
+ ],
+ "label" => [
+ "control" => false,
+ "text" => "热门",
+ "textColor" => "#FFFFFF",
+ "bgColorStart" => "#F83287",
+ "bgColorEnd" => "#FE3423"
+ ],
+ "id" => "1e67vek25rhc0"
+ ],
+ [
+ "title" => "拼团",
+ "icon" => "icondiy icon-system-pintuan-nav",
+ "imageUrl" => "",
+ "iconType" => "icon",
+ "style" => [
+ "fontSize" => 50,
+ "iconBgColor" => [
+ "#58BCFF",
+ "#1379FF"
+ ],
+ "iconBgColorDeg" => 90,
+ "iconBgImg" => "public/static/ext/diyview/img/icon_bg/bg_04.png",
+ "bgRadius" => 19,
+ "iconColor" => [
+ "#FFFFFF"
+ ],
+ "iconColorDeg" => 0
+ ],
+ "link" => [
+ "name" => "PINTUAN_PREFECTURE",
+ "title" => "拼团专区",
+ "wap_url" => "/pages_promotion/pintuan/list",
+ "parent" => "MARKETING_LINK"
+ ],
+ "label" => [
+ "control" => false,
+ "text" => "热门",
+ "textColor" => "#FFFFFF",
+ "bgColorStart" => "#F83287",
+ "bgColorEnd" => "#FE3423"
+ ],
+ "id" => "b1kn8ktvs440"
+ ],
+ [
+ "title" => "秒杀",
+ "icon" => "icondiy icon-system-seckill-time",
+ "imageUrl" => "",
+ "iconType" => "icon",
+ "style" => [
+ "fontSize" => 50,
+ "iconBgColor" => [
+ "#FF9100"
+ ],
+ "iconBgColorDeg" => 0,
+ "iconBgImg" => "public/static/ext/diyview/img/icon_bg/bg_04.png",
+ "bgRadius" => 19,
+ "iconColor" => [
+ "#FFFFFF"
+ ],
+ "iconColorDeg" => 0
+ ],
+ "link" => [
+ "name" => "SECKILL_PREFECTURE",
+ "title" => "秒杀专区",
+ "wap_url" => "/pages_promotion/seckill/list",
+ "parent" => "MARKETING_LINK"
+ ],
+ "label" => [
+ "control" => true,
+ "text" => "热门",
+ "textColor" => "#FFFFFF",
+ "bgColorStart" => "#F83288",
+ "bgColorEnd" => "#FE3523"
+ ],
+ "id" => "1cgq3tjxkc800"
+ ],
+ [
+ "title" => " 积分",
+ "icon" => "icondiy icon-system-point-nav",
+ "imageUrl" => "",
+ "iconType" => "icon",
+ "style" => [
+ "fontSize" => 50,
+ "iconBgColor" => [
+ "#02CC96",
+ "#43EEC9"
+ ],
+ "iconBgColorDeg" => 90,
+ "iconBgImg" => "public/static/ext/diyview/img/icon_bg/bg_04.png",
+ "bgRadius" => 19,
+ "iconColor" => [
+ "#FFFFFF"
+ ],
+ "iconColorDeg" => 0
+ ],
+ "link" => [
+ "name" => "INTEGRAL_STORE",
+ "title" => "积分商城",
+ "wap_url" => "/pages_promotion/point/list",
+ "parent" => "MARKETING_LINK"
+ ],
+ "label" => [
+ "control" => false,
+ "text" => "热门",
+ "textColor" => "#FFFFFF",
+ "bgColorStart" => "#F83287",
+ "bgColorEnd" => "#FE3423"
+ ],
+ "id" => "1v6a5arxdyqo0"
+ ],
+ [
+ "title" => "专题活动",
+ "icon" => "icondiy icon-system-topic-nav",
+ "imageUrl" => "",
+ "iconType" => "icon",
+ "style" => [
+ "fontSize" => 50,
+ "iconBgColor" => [
+ "#BE79FF",
+ "#7B00FF"
+ ],
+ "iconBgColorDeg" => 90,
+ "iconBgImg" => "public/static/ext/diyview/img/icon_bg/bg_04.png",
+ "bgRadius" => 19,
+ "iconColor" => [
+ "#FFFFFF"
+ ],
+ "iconColorDeg" => 0
+ ],
+ "link" => [
+ "name" => "THEMATIC_ACTIVITIES_LIST",
+ "title" => "专题活动列表",
+ "wap_url" => "/pages_promotion/topics/list",
+ "parent" => "MARKETING_LINK"
+ ],
+ "label" => [
+ "control" => false,
+ "text" => "热门",
+ "textColor" => "#FFFFFF",
+ "bgColorStart" => "#F83287",
+ "bgColorEnd" => "#FE3423"
+ ],
+ "id" => "x7bqn51r8hs0"
+ ],
+ [
+ "title" => "砍价",
+ "icon" => "icondiy icon-system-bargain-nav",
+ "imageUrl" => "",
+ "iconType" => "icon",
+ "style" => [
+ "fontSize" => 50,
+ "iconBgColor" => [
+ "#5BBDFF",
+ "#2E87FD"
+ ],
+ "iconBgColorDeg" => 90,
+ "iconBgImg" => "public/static/ext/diyview/img/icon_bg/bg_04.png",
+ "bgRadius" => 19,
+ "iconColor" => [
+ "#FFFFFF"
+ ],
+ "iconColorDeg" => 0
+ ],
+ "link" => [
+ "name" => "BARGAIN_PREFECTURE",
+ "title" => "砍价专区",
+ "wap_url" => "/pages_promotion/bargain/list",
+ "parent" => "MARKETING_LINK"
+ ],
+ "label" => [
+ "control" => false,
+ "text" => "热门",
+ "textColor" => "#FFFFFF",
+ "bgColorStart" => "#F83287",
+ "bgColorEnd" => "#FE3423"
+ ],
+ "id" => "140zkvoseuw00"
+ ],
+ [
+ "title" => "领券",
+ "icon" => "icondiy icon-system-get-coupon",
+ "imageUrl" => "",
+ "iconType" => "icon",
+ "style" => [
+ "fontSize" => 50,
+ "iconBgColor" => [
+ "#BE79FF",
+ "#7B00FF"
+ ],
+ "iconBgColorDeg" => 90,
+ "iconBgImg" => "public/static/ext/diyview/img/icon_bg/bg_04.png",
+ "bgRadius" => 19,
+ "iconColor" => [
+ "#FFFFFF"
+ ],
+ "iconColorDeg" => 0
+ ],
+ "link" => [
+ "name" => "COUPON_PREFECTURE",
+ "title" => "优惠券专区",
+ "wap_url" => "/pages_tool/goods/coupon",
+ "parent" => "MARKETING_LINK"
+ ],
+ "label" => [
+ "control" => false,
+ "text" => "热门",
+ "textColor" => "#FFFFFF",
+ "bgColorStart" => "#F83287",
+ "bgColorEnd" => "#FE3423"
+ ],
+ "id" => "5sjwa1q2t5k0"
+ ],
+ [
+ "title" => "文章",
+ "icon" => "icondiy icon-system-article-nav",
+ "imageUrl" => "",
+ "iconType" => "icon",
+ "style" => [
+ "fontSize" => 50,
+ "iconBgColor" => [
+ "#FF8052",
+ "#FF4830"
+ ],
+ "iconBgColorDeg" => 90,
+ "iconBgImg" => "public/static/ext/diyview/img/icon_bg/bg_04.png",
+ "bgRadius" => 19,
+ "iconColor" => [
+ "#FFFFFF"
+ ],
+ "iconColorDeg" => 0
+ ],
+ "link" => [
+ "name" => "SHOPPING_ARTICLE",
+ "title" => "文章",
+ "wap_url" => "/pages_tool/article/list",
+ "parent" => "MALL_LINK"
+ ],
+ "label" => [
+ "control" => false,
+ "text" => "热门",
+ "textColor" => "#FFFFFF",
+ "bgColorStart" => "#F83287",
+ "bgColorEnd" => "#FE3423"
+ ],
+ "id" => "4aforgjwmdw0"
+ ],
+ [
+ "title" => "公告",
+ "icon" => "icondiy icon-system-notice-nav",
+ "imageUrl" => "",
+ "iconType" => "icon",
+ "style" => [
+ "fontSize" => 50,
+ "iconBgColor" => [
+ "#FFCC26",
+ "#FF9F29"
+ ],
+ "iconBgColorDeg" => 90,
+ "iconBgImg" => "public/static/ext/diyview/img/icon_bg/bg_04.png",
+ "bgRadius" => 19,
+ "iconColor" => [
+ "#FFFFFF"
+ ],
+ "iconColorDeg" => 0
+ ],
+ "link" => [
+ "name" => "SHOPPING_NOTICE",
+ "title" => "公告",
+ "wap_url" => "/pages_tool/notice/list",
+ "parent" => "MALL_LINK"
+ ],
+ "label" => [
+ "control" => false,
+ "text" => "热门",
+ "textColor" => "#FFFFFF",
+ "bgColorStart" => "#F83287",
+ "bgColorEnd" => "#FE3423"
+ ],
+ "id" => "myo9oz46yj40"
+ ],
+ [
+ "title" => "帮助",
+ "icon" => "icondiy icon-system-help",
+ "imageUrl" => "",
+ "iconType" => "icon",
+ "style" => [
+ "fontSize" => 50,
+ "iconBgColor" => [
+ "#02CC96",
+ "#43EEC9"
+ ],
+ "iconBgColorDeg" => 90,
+ "iconBgImg" => "public/static/ext/diyview/img/icon_bg/bg_04.png",
+ "bgRadius" => 19,
+ "iconColor" => [
+ "#FFFFFF"
+ ],
+ "iconColorDeg" => 0
+ ],
+ "link" => [
+ "name" => "SHOPPING_HELP",
+ "title" => "帮助",
+ "wap_url" => "/pages_tool/help/list",
+ "parent" => "MALL_LINK"
+ ],
+ "label" => [
+ "control" => false,
+ "text" => "热门",
+ "textColor" => "#FFFFFF",
+ "bgColorStart" => "#F83287",
+ "bgColorEnd" => "#FE3423"
+ ],
+ "id" => "h4nt4orc9i80"
+ ]
+ ],
+ 'addonName' => '',
+ "componentName" => "GraphicNav",
+ "componentTitle" => "图文导航",
+ "isDelete" => 0,
+ "pageBgColor" => "#FFFFFF",
+ "componentBgColor" => "",
+ "componentAngle" => "round",
+ "topAroundRadius" => 0,
+ "bottomAroundRadius" => 0,
+ "topElementAroundRadius" => 0,
+ "bottomElementAroundRadius" => 0,
+ "margin" => [
+ "top" => 0,
+ "bottom" => 0,
+ "both" => 12
+ ]
+ ],
+ [
+ "id" => "3tegcfvyijk0",
+ "style" => "5",
+ "sources" => "initial",
+ "styleName" => "风格五",
+ "couponIds" => [],
+ "count" => 6,
+ "previewList" => [],
+ "nameColor" => "#303133",
+ "moneyColor" => "#FF0000",
+ "limitColor" => "#999999",
+ "btnStyle" => [
+ "textColor" => "#FFFFFF",
+ "bgColor" => "#303133",
+ "text" => "立即领取",
+ "aroundRadius" => 5,
+ "isBgColor" => true,
+ "isAroundRadius" => true
+ ],
+ "bgColor" => "",
+ "isName" => true,
+ "couponBgColor" => "",
+ "couponBgUrl" => "",
+ "couponType" => "img",
+ "ifNeedBg" => true,
+ 'addonName' => 'coupon',
+ "componentName" => "Coupon",
+ "componentTitle" => "优惠券",
+ "isDelete" => 0,
+ "pageBgColor" => "",
+ "topAroundRadius" => 0,
+ "bottomAroundRadius" => 0,
+ "elementBgColor" => "",
+ "topElementAroundRadius" => 0,
+ "bottomElementAroundRadius" => 0,
+ "margin" => [
+ "top" => 10,
+ "bottom" => 10,
+ "both" => 12
+ ]
+ ],
+ [
+ "id" => "3acr0xjm1c80",
+ 'addonName' => '',
+ "componentName" => "RubikCube",
+ "componentTitle" => "魔方",
+ "isDelete" => 0,
+ "pageBgColor" => "",
+ "componentBgColor" => "",
+ "componentAngle" => "round",
+ "topAroundRadius" => 10,
+ "bottomAroundRadius" => 10,
+ "topElementAroundRadius" => 0,
+ "bottomElementAroundRadius" => 0,
+ "margin" => [
+ "top" => 0,
+ "bottom" => 10,
+ "both" => 12
+ ],
+ "list" => [
+ [
+ "imageUrl" => 'addon/diy_default2/shop/view/public/img/mf_left.png',
+ "imgWidth" => "338",
+ "imgHeight" => "450",
+ "previewWidth" => 187.5,
+ "previewHeight" => "249.63px",
+ "link" => [
+ "name" => ""
+ ]
+ ],
+ [
+ "imageUrl" => 'addon/diy_default2/shop/view/public/img/mf_right1.png',
+ "imgWidth" => "354",
+ "imgHeight" => "220",
+ "previewWidth" => 187.5,
+ "previewHeight" => "124.82px",
+ "link" => [
+ "name" => ""
+ ]
+ ],
+ [
+ "imageUrl" => 'addon/diy_default2/shop/view/public/img/mf_right2.png',
+ "imgWidth" => "354",
+ "imgHeight" => "22",
+ "previewWidth" => 187.5,
+ "previewHeight" => "124.82px",
+ "link" => [
+ "name" => ""
+ ]
+ ]
+ ],
+ "mode" => "row1-lt-of2-rt",
+ "imageGap" => 10,
+ "elementAngle" => "round"
+ ],
+ [
+ "id" => "68p4o1plca80",
+ "style" => "style-1",
+ "sources" => "initial",
+ "styleName" => "风格1",
+ "count" => 6,
+ 'addonName' => '',
+ "componentName" => "GoodsRecommend",
+ "componentTitle" => "商品推荐",
+ "isDelete" => 0,
+ "topAroundRadius" => 0,
+ "bottomAroundRadius" => 0,
+ "topElementAroundRadius" => 10,
+ "bottomElementAroundRadius" => 10,
+ "margin" => [
+ "top" => 0,
+ "bottom" => 10,
+ "both" => 12
+ ],
+ "nameLineMode" => "single",
+ "sortWay" => "default",
+ "ornament" => [
+ "type" => "default",
+ "color" => "#EDEDED"
+ ],
+ "imgAroundRadius" => 0,
+ "goodsNameStyle" => [
+ "color" => "#303133",
+ "control" => true,
+ "fontWeight" => false,
+ "support" => true
+ ],
+ "saleStyle" => [
+ "color" => "#999CA7",
+ "control" => true,
+ "support" => true
+ ],
+ "theme" => "default",
+ "priceStyle" => [
+ "mainColor" => "#FF1544",
+ "mainControl" => true,
+ "lineColor" => "#999CA7",
+ "lineControl" => false,
+ "lineSupport" => false
+ ],
+ "goodsId" => [],
+ "categoryId" => 0,
+ "categoryName" => "请选择",
+ "topStyle" => [
+ "title" => "今日推荐",
+ "subTitle" => "大家都在买",
+ "icon" => [
+ "value" => "icondiy icon-system-tuijian",
+ "color" => "#FF3D3D",
+ "bgColor" => ""
+ ],
+ "color" => "#303133",
+ "subColor" => "#999CA7",
+ "support" => true
+ ],
+ "bgUrl" => "",
+ "pageBgColor" => "",
+ "componentBgColor" => "",
+ "componentAngle" => "round",
+ "elementBgColor" => "#FFFFFF",
+ "elementAngle" => "round",
+ "labelStyle" => [
+ "support" => false,
+ "bgColor" => "#FF504D",
+ "title" => "新人专享",
+ "color" => "#FFFFFF"
+ ]
+ ],
+ [
+ "id" => "3moj09pl5c20",
+ "style" => "style-1",
+ "sources" => "initial",
+ "count" => 6,
+ "goodsId" => [],
+ "ornament" => [
+ "type" => "default",
+ "color" => "#EDEDED"
+ ],
+ "nameLineMode" => "single",
+ "template" => "row1-of1",
+ "goodsMarginType" => "default",
+ "goodsMarginNum" => 10,
+ "btnStyle" => [
+ "text" => "去秒杀",
+ "textColor" => "#FFFFFF",
+ "theme" => "default",
+ "aroundRadius" => 25,
+ "control" => true,
+ "support" => true,
+ "bgColorStart" => "#FF7B1D",
+ "bgColorEnd" => "#FF1544"
+ ],
+ "imgAroundRadius" => 10,
+ "saleStyle" => [
+ "color" => "#999CA7",
+ "control" => true,
+ "support" => true
+ ],
+ "progressStyle" => [
+ "control" => true,
+ "support" => true,
+ "currColor" => "#FDBE6C",
+ "bgColor" => "#FCECD7"
+ ],
+ "titleStyle" => [
+ "backgroundImage" => "addon/seckill/component/view/seckill/img/style_title_3_bg.png",
+ "isShow" => true,
+ "leftStyle" => "img",
+ "leftImg" => "addon/seckill/component/view/seckill/img/style_title_3_name.png",
+ "style" => "style-3",
+ "styleName" => "风格3",
+ "leftText" => "限时秒杀",
+ "fontSize" => 16,
+ "fontWeight" => true,
+ "textColor" => "#FFFFFF",
+ "bgColorStart" => "#FA6400",
+ "bgColorEnd" => "#FF287A",
+ "more" => "更多",
+ "moreColor" => "#FFFFFF",
+ "moreFontSize" => 12,
+ "moreSupport" => true,
+ "timeBgColor" => "",
+ "timeImageUrl" => "",
+ "colonColor" => "#FFFFFF",
+ "numBgColorStart" => "#FFFFFF",
+ "numBgColorEnd" => "#FFFFFF",
+ "numTextColor" => "#FD3B54"
+ ],
+ "slideMode" => "scroll",
+ "theme" => "default",
+ "priceStyle" => [
+ "mainColor" => "#FF1745",
+ "mainControl" => true,
+ "lineColor" => "#999CA7",
+ "lineControl" => true,
+ "lineSupport" => true
+ ],
+ "goodsNameStyle" => [
+ "color" => "#303133",
+ "control" => true,
+ "fontWeight" => false
+ ],
+ 'addonName' => 'seckill',
+ "componentName" => "Seckill",
+ "componentTitle" => "秒杀",
+ "isDelete" => 0,
+ "pageBgColor" => "",
+ "componentBgColor" => "",
+ "componentAngle" => "round",
+ "topAroundRadius" => 0,
+ "bottomAroundRadius" => 0,
+ "elementBgColor" => "#FFFFFF",
+ "elementAngle" => "round",
+ "topElementAroundRadius" => 0,
+ "bottomElementAroundRadius" => 0,
+ "margin" => [
+ "top" => 0,
+ "bottom" => 10,
+ "both" => 12
+ ]
+ ],
+ [
+ "id" => "z9bdab3tm34",
+ "style" => "style-1",
+ "sources" => "initial",
+ "count" => 6,
+ "goodsId" => [],
+ "ornament" => [
+ "type" => "default",
+ "color" => "#EDEDED"
+ ],
+ "nameLineMode" => "single",
+ "template" => "horizontal-slide",
+ "goodsMarginType" => "default",
+ "goodsMarginNum" => 10,
+ "btnStyle" => [
+ "text" => "去拼团",
+ "textColor" => "#FFFFFF",
+ "theme" => "default",
+ "aroundRadius" => 25,
+ "control" => false,
+ "support" => false,
+ "bgColorStart" => "#FF1544",
+ "bgColorEnd" => "#FF1544"
+ ],
+ "imgAroundRadius" => 10,
+ "saleStyle" => [
+ "color" => "#FF1544",
+ "control" => false,
+ "support" => false
+ ],
+ "groupStyle" => [
+ "color" => "#FFFFFF",
+ "control" => true,
+ "support" => true,
+ "bgColorStart" => "#FA2379",
+ "bgColorEnd" => "#FF4F61"
+ ],
+ "priceStyle" => [
+ "mainColor" => "#FF1544",
+ "mainControl" => true,
+ "lineColor" => "#999CA7",
+ "lineControl" => true,
+ "lineSupport" => true
+ ],
+ "slideMode" => "scroll",
+ "theme" => "default",
+ "goodsNameStyle" => [
+ "color" => "#303133",
+ "control" => true,
+ "fontWeight" => false
+ ],
+ "titleStyle" => [
+ "bgColorStart" => "#6236FF",
+ "bgColorEnd" => "#0091FF",
+ "isShow" => true,
+ "leftStyle" => "img",
+ "leftImg" => "addon/pintuan/component/view/pintuan/img/horizontal_slide_name.png",
+ "style" => "style-1",
+ "styleName" => "风格1",
+ "leftText" => "超值拼团",
+ "fontSize" => 16,
+ "fontWeight" => true,
+ "textColor" => "#FFFFFF",
+ "more" => "查看更多",
+ "moreColor" => "#FFFFFF",
+ "moreFontSize" => 12,
+ "backgroundImage" => "addon/pintuan/component/view/pintuan/img/horizontal_slide_bg.png"
+ ],
+ 'addonName' => 'pintuan',
+ "componentName" => "Pintuan",
+ "componentTitle" => "拼团",
+ "isDelete" => 0,
+ "pageBgColor" => "",
+ "componentBgColor" => "#FFFFFF",
+ "componentAngle" => "round",
+ "topAroundRadius" => 0,
+ "bottomAroundRadius" => 10,
+ "elementBgColor" => "",
+ "elementAngle" => "round",
+ "topElementAroundRadius" => 0,
+ "bottomElementAroundRadius" => 0,
+ "margin" => [
+ "top" => 0,
+ "bottom" => 10,
+ "both" => 12
+ ]
+ ],
+ [
+ "id" => "xwdnfttfj7k",
+ "style" => "style-1",
+ "sources" => "initial",
+ "count" => 6,
+ "goodsId" => [],
+ "ornament" => [
+ "type" => "default",
+ "color" => "#EDEDED"
+ ],
+ "nameLineMode" => "single",
+ "template" => "horizontal-slide",
+ "goodsMarginType" => "default",
+ "goodsMarginNum" => 10,
+ "btnStyle" => [
+ "text" => "立即抢购",
+ "textColor" => "#FFFFFF",
+ "theme" => "default",
+ "aroundRadius" => 25,
+ "control" => false,
+ "support" => false,
+ "bgColorStart" => "#FF7B1D",
+ "bgColorEnd" => "#FF1544"
+ ],
+ "imgAroundRadius" => 5,
+ "saleStyle" => [
+ "color" => "#FFFFFF",
+ "control" => true,
+ "support" => true
+ ],
+ "slideMode" => "scroll",
+ "theme" => "default",
+ "goodsNameStyle" => [
+ "color" => "#303133",
+ "control" => true,
+ "fontWeight" => false
+ ],
+ "priceStyle" => [
+ "mainColor" => "#FF1745",
+ "mainControl" => true,
+ "lineColor" => "#999CA7",
+ "lineControl" => true,
+ "lineSupport" => true
+ ],
+ "titleStyle" => [
+ "bgColorStart" => "#FF209D",
+ "bgColorEnd" => "#B620E0",
+ "isShow" => true,
+ "leftStyle" => "img",
+ "leftImg" => "",
+ "style" => "style-1",
+ "styleName" => "风格1",
+ "leftText" => "疯狂砍价",
+ "fontSize" => 16,
+ "fontWeight" => true,
+ "textColor" => "#FFFFFF",
+ "more" => "更多",
+ "moreColor" => "#FFFFFF",
+ "moreFontSize" => 12,
+ "backgroundImage" => ""
+ ],
+ 'addonName' => 'bargain',
+ "componentName" => "Bargain",
+ "componentTitle" => "砍价",
+ "isDelete" => 0,
+ "pageBgColor" => "",
+ "componentBgColor" => "#FFFFFF",
+ "componentAngle" => "round",
+ "topAroundRadius" => 0,
+ "bottomAroundRadius" => 10,
+ "elementBgColor" => "",
+ "elementAngle" => "round",
+ "topElementAroundRadius" => 0,
+ "bottomElementAroundRadius" => 0,
+ "margin" => [
+ "top" => 0,
+ "bottom" => 10,
+ "both" => 12
+ ]
+ ],
+ [
+ "id" => "5zj6d48bxks0",
+ 'addonName' => '',
+ "componentName" => "ImageAds",
+ "componentTitle" => "图片广告",
+ "isDelete" => 0,
+ "pageBgColor" => "",
+ "componentBgColor" => "",
+ "componentAngle" => "round",
+ "topAroundRadius" => 5,
+ "bottomAroundRadius" => 5,
+ "topElementAroundRadius" => 0,
+ "bottomElementAroundRadius" => 0,
+ "margin" => [
+ "top" => 0,
+ "bottom" => 10,
+ "both" => 12
+ ],
+ "list" => [
+ [
+ "link" => [
+ "name" => ""
+ ],
+ "imageUrl" => 'addon/diy_default2/shop/view/public/img/gg.png',
+ "imgWidth" => "702",
+ "imgHeight" => "252",
+ "id" => "ccnb530uc5k0"
+ ]
+ ],
+ "indicatorIsShow" => true,
+ "indicatorColor" => "#ffffff",
+ "carouselStyle" => "circle",
+ "indicatorLocation" => "center"
+ ],
+ [
+ "id" => "xwdnfttfj6k",
+ "style" => "style-3",
+ "sources" => "initial",
+ "count" => 6,
+ "goodsId" => [],
+ "ornament" => [
+ "type" => "default",
+ "color" => "#EDEDED"
+ ],
+ "nameLineMode" => "multiple",
+ "template" => "row1-of2",
+ "goodsMarginType" => "default",
+ "goodsMarginNum" => 6,
+ "btnStyle" => [
+ "fontWeight" => false,
+ "padding" => 0,
+ "cartEvent" => "detail",
+ "text" => "购买",
+ "textColor" => "#FFFFFF",
+ "theme" => "default",
+ "aroundRadius" => 25,
+ "control" => false,
+ "support" => false,
+ "bgColor" => "#FF6A00",
+ "style" => "button",
+ "iconDiy" => [
+ "iconType" => "icon",
+ "icon" => "",
+ "style" => [
+ "fontSize" => "60",
+ "iconBgColor" => [],
+ "iconBgColorDeg" => 0,
+ "iconBgImg" => "",
+ "bgRadius" => 0,
+ "iconColor" => [
+ "#000000"
+ ],
+ "iconColorDeg" => 0
+ ]
+ ]
+ ],
+ "imgAroundRadius" => 0,
+ "saleStyle" => [
+ "color" => "#999CA7",
+ "control" => true,
+ "support" => true
+ ],
+ "slideMode" => "slide",
+ "theme" => "default",
+ "goodsNameStyle" => [
+ "color" => "#303133",
+ "control" => true,
+ "fontWeight" => false
+ ],
+ "priceStyle" => [
+ "mainColor" => "#FF6A00",
+ "mainControl" => true,
+ "lineColor" => "#999CA7",
+ "lineControl" => false,
+ "lineSupport" => false
+ ],
+ 'addonName' => '',
+ "componentName" => "GoodsList",
+ "componentTitle" => "商品列表",
+ "isDelete" => 0,
+ "pageBgColor" => "",
+ "componentBgColor" => "",
+ "componentAngle" => "round",
+ "topAroundRadius" => 10,
+ "bottomAroundRadius" => 10,
+ "elementBgColor" => "#FFFFFF",
+ "elementAngle" => "round",
+ "topElementAroundRadius" => 10,
+ "bottomElementAroundRadius" => 10,
+ "margin" => [
+ "top" => 0,
+ "bottom" => 0,
+ "both" => 12
+ ],
+ "categoryId" => 0,
+ "categoryName" => "请选择",
+ "sortWay" => "default",
+ "tag" => [
+ "text" => "隐藏",
+ "value" => "hidden"
+ ]
+ ]
+ ]
+ ]
+ ]
+ ]
];
\ No newline at end of file
diff --git a/src/addon/diy_default2/config/info.php b/src/addon/diy_default2/config/info.php
index f1b408d5c..2d8aa2733 100644
--- a/src/addon/diy_default2/config/info.php
+++ b/src/addon/diy_default2/config/info.php
@@ -1,21 +1,12 @@
- 'diy_default2',
- 'title' => '官方模板二',
- 'description' => '官方默认模板(二)',
- 'type' => 'system', //插件类型 system :系统插件(自动安装), business:业务插件 promotion:营销插件 tool:工具插件
- 'status' => 1,
- 'author' => '',
- 'version' => '5.3.1',
- 'version_no' => '525231212001',
- 'content' => '',
+ 'diy_default2',
+ 'title' => '官方模板二',
+ 'description' => '官方默认模板(二)',
+ 'type' => 'system', //插件类型 system :系统插件(自动安装), business:业务插件 promotion:营销插件 tool:工具插件
+ 'status' => 1,
+ 'author' => '',
+ 'version' => '5.3.1',
+ 'version_no' => '525231212001',
+ 'content' => '',
];
\ No newline at end of file
diff --git a/src/addon/diy_default2/event/Install.php b/src/addon/diy_default2/event/Install.php
index 88edac4b9..7998b6064 100644
--- a/src/addon/diy_default2/event/Install.php
+++ b/src/addon/diy_default2/event/Install.php
@@ -1,27 +1,18 @@
- '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
- 'template' => [],
-
- // 后台自定义组件——装修
- 'util' => [],
-
- // 自定义页面路径
- 'link' => [],
-
- // 自定义图标库
- 'icon_library' => [],
-
- // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
- 'component' => [],
-
- // uni-app 页面,多个逗号隔开
- 'pages' => [],
-
- // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
- 'info' => [],
-
- // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
- 'theme' => [],
-
- // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
- 'data' => []
+ '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
+ 'template' => [],
+
+ // 后台自定义组件——装修
+ 'util' => [],
+
+ // 自定义页面路径
+ 'link' => [],
+
+ // 自定义图标库
+ 'icon_library' => [],
+
+ // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
+ 'component' => [],
+
+ // uni-app 页面,多个逗号隔开
+ 'pages' => [],
+
+ // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
+ 'info' => [],
+
+ // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
+ 'theme' => [],
+
+ // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
+ 'data' => []
];
\ No newline at end of file
diff --git a/src/addon/electronicsheet/config/info.php b/src/addon/electronicsheet/config/info.php
index 0965d2058..b25953d9c 100644
--- a/src/addon/electronicsheet/config/info.php
+++ b/src/addon/electronicsheet/config/info.php
@@ -1,20 +1,12 @@
- 'electronicsheet',
- 'title' => '电子面单',
- 'description' => '电子面单',
- 'type' => 'tool', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
- 'status' => 1,
- 'author' => '',
- 'version' => '5.3.1',
- 'version_no' => '525231212001',
- 'content' => '',
+ 'electronicsheet',
+ 'title' => '电子面单',
+ 'description' => '电子面单',
+ 'type' => 'tool', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
+ 'status' => 1,
+ 'author' => '',
+ 'version' => '5.3.1',
+ 'version_no' => '525231212001',
+ 'content' => '',
];
\ No newline at end of file
diff --git a/src/addon/electronicsheet/event/Install.php b/src/addon/electronicsheet/event/Install.php
index 10dab9ad0..326018eaa 100644
--- a/src/addon/electronicsheet/event/Install.php
+++ b/src/addon/electronicsheet/event/Install.php
@@ -1,25 +1,17 @@
- "电子面单", "type" => "electronicsheet" ];
- }
+ "电子面单", "type" => "electronicsheet" ];
+ }
}
\ No newline at end of file
diff --git a/src/addon/electronicsheet/event/ShowPromotion.php b/src/addon/electronicsheet/event/ShowPromotion.php
index ead6854f9..add612ee6 100644
--- a/src/addon/electronicsheet/event/ShowPromotion.php
+++ b/src/addon/electronicsheet/event/ShowPromotion.php
@@ -1,46 +1,38 @@
- [
- [
- //插件名称
- 'name' => 'electronicsheet',
- //店铺端展示分类 shop:营销活动 member:互动营销
- 'show_type' => 'tool',
- //展示主题
- 'title' => '电子面单',
- //展示介绍
- 'description' => '商家发货主动打印快递面单',
- //展示图标
- 'icon' => 'addon/electronicsheet/icon.png',
- //跳转链接
- 'url' => 'electronicsheet://shop/electronicsheet/lists',
- ]
- ]
-
- ];
- return $data;
- }
+ [
+ [
+ //插件名称
+ 'name' => 'electronicsheet',
+ //店铺端展示分类 shop:营销活动 member:互动营销
+ 'show_type' => 'tool',
+ //展示主题
+ 'title' => '电子面单',
+ //展示介绍
+ 'description' => '商家发货主动打印快递面单',
+ //展示图标
+ 'icon' => 'addon/electronicsheet/icon.png',
+ //跳转链接
+ 'url' => 'electronicsheet://shop/electronicsheet/lists',
+ ]
+ ]
+
+ ];
+ return $data;
+ }
}
\ No newline at end of file
diff --git a/src/addon/electronicsheet/event/UnInstall.php b/src/addon/electronicsheet/event/UnInstall.php
index 2919198df..1b3f9b11c 100644
--- a/src/addon/electronicsheet/event/UnInstall.php
+++ b/src/addon/electronicsheet/event/UnInstall.php
@@ -1,25 +1,17 @@
-getElectronicsheetConfig($param[ 'site_id' ])[ 'data' ][ 'value' ];
- if (empty($config_info)) {
- return $this->error('', '请先配置电子面单');
- }
-
- if (empty($param[ 'template_id' ])) {
- return $this->error('', '请先配置电子面单模板');
- }
- //获取电子模板信息
- $template = $electronicsheet_model->getExpressElectronicsheetInfo([ [ 'id', '=', $param[ 'template_id' ] ] ])[ 'data' ];
- if (empty($template)) {
- return $this->error('', '电子面单模板不存在');
- }
-
- //获取店铺信息
- $shop_model = new Shop();
- $shop_info = $shop_model->getShopInfo([ [ 'site_id', '=', $param[ 'site_id' ] ] ])[ 'data' ];
-
- if (empty($shop_info[ 'name' ])) {
- return $this->error('', '店铺联系地址中联系人姓名未设置');
- }
- if (empty($shop_info[ 'province_name' ]) || empty($shop_info[ 'city_name' ]) || empty($shop_info[ 'district_name' ]) || empty($shop_info[ 'address' ])) {
- return $this->error('', '店铺联系地址中联系地址未设置');
- }
- if (empty($shop_info[ 'telephone' ]) && empty($shop_info[ 'mobile' ])) {
- return $this->error('', '店铺联系地址中联系方式未设置');
- }
-
- $result = $this->electronicsheetDelivery($param, $config_info, $template, $shop_info);
- if (isset($result[ 'code' ]) && $result[ 'code' ] < 0) {
- return $result;
- } else {
- return $this->success($result);
- }
- }
-
- /**
- * 电子面单发货
- * @param $delivery_id //包裹id
- * @param $config_info //快递鸟配置信息
- * @param $template //电子面单模板
- * @param $shop_info //发货人信息
- * @param $goods_array //商品信息
- * @return array
- */
- public function electronicsheetDelivery($param, $config_info, $template, $shop_info)
- {
- //获取订单信息
- $order_info = model('order')->getInfo([ [ 'order_id', '=', $param[ 'order_id' ] ] ]);
- //获取快递公司编码
- $express_company = model('express_company_template')->getInfo([ [ 'company_id', '=', $template[ 'company_id' ] ] ], 'express_no,print_style');
- $print_style = json_decode($express_company[ 'print_style' ], true);
-
- $goods_commodity = [];
- //获取商品信息
- if (empty($param[ 'order_goods_id_array' ])) {
- $goods_array = model('order_goods')->getList(
- [
- [ 'order_id', '=', $param[ 'order_id' ] ]
- ], 'sku_name as GoodsName,num as GoodsQuantity'
- );
- } else {
- $goods_array = model('order_goods')->getList(
- [
- [ 'order_goods_id', 'in', $param[ 'order_goods_id_array' ] ],
- [ 'order_id', '=', $param[ 'order_id' ] ]
- ], 'sku_name as GoodsName,num as GoodsQuantity'
- );
- }
- //替换商品名称中的特殊字符 ' " # & + < > % \
- $search = array ( "'", '"', '&', '+', '<', '>', '%', "\\", '#', "and" );
- foreach ($goods_array as $key => $val){
- $goods_commodity[] = [
- 'GoodsName' => str_replace($search, '', $val[ 'GoodsName' ]),
- 'GoodsQuantity' => $val['GoodsQuantity']
- ];
- }
-
- //实例化快递鸟
- $config = [
- 'EBusinessID' => $config_info[ 'kdniao_user_id' ],
- 'AppKey' => $config_info[ 'kdniao_api_key' ]
- ];
- $kdniao = new Kdniao($config);
- //构造电子面单提交信息
- $eorder = [];
- $eorder[ 'CustomerName' ] = $template[ 'customer_name' ];
- $eorder[ 'CustomerPwd' ] = $template[ 'customer_pwd' ];
- $eorder[ 'SendSite' ] = $template[ 'send_site' ];
- $eorder[ 'SendStaff' ] = $template[ 'send_staff' ];
- $eorder[ 'MonthCode' ] = $template[ 'month_code' ];
- $eorder[ 'ShipperCode' ] = $express_company[ 'express_no' ];//快递公司编码
- $eorder[ 'OrderCode' ] = $order_info[ 'order_no' ];//订单号
- $eorder[ 'PayType' ] = $template[ 'postage_payment_method' ]; //邮费支付方式
- $eorder[ 'ExpType' ] = 1; //快递类型
- $eorder[ 'TemplateSize' ] = $print_style[ $template[ 'print_style' ] ][ 'template_size' ]; //模板规格
- //发货人信息
- $sender = [];
- $sender[ 'Name' ] = $shop_info[ 'name' ];
- $sender[ 'Mobile' ] = $shop_info[ 'mobile' ];
- $sender[ 'Tel' ] = $shop_info[ 'telephone' ];
- $sender[ 'ProvinceName' ] = $shop_info[ 'province_name' ];
- $sender[ 'CityName' ] = $shop_info[ 'city_name' ];
- $sender[ 'ExpAreaName' ] = $shop_info[ 'district_name' ];
- $sender[ 'Address' ] = $shop_info[ 'address' ];
- $sender[ 'PostCode' ] = '000000';
- //获取收货人信息
- $area_model = new Address();
- $province_name = $area_model->getAreasInfo([ [ 'id', '=', $order_info[ 'province_id' ] ] ], 'name');
- $city_name = $area_model->getAreasInfo([ [ 'id', '=', $order_info[ 'city_id' ] ] ], 'name');
- $district_name = $area_model->getAreasInfo([ [ 'id', '=', $order_info[ 'district_id' ] ] ], 'name');
- $receiver = [];
- $receiver[ 'Name' ] = $order_info[ 'name' ];
- $receiver[ 'Mobile' ] = $order_info[ 'mobile' ];
- $receiver[ 'ProvinceName' ] = $province_name[ 'data' ][ 'name' ];
- $receiver[ 'CityName' ] = $city_name[ 'data' ][ 'name' ];
- $receiver[ 'ExpAreaName' ] = empty($district_name[ 'data' ][ 'name' ]) ? '' : $district_name[ 'data' ][ 'name' ];
- $receiver[ 'Address' ] = $order_info[ 'address' ];
- $receiver[ 'PostCode' ] = '000000';
-
-// $commodity[] = $goods_array;
- $eorder[ 'Sender' ] = $sender;
- $eorder[ 'Receiver' ] = $receiver;
- $eorder[ 'Commodity' ] = $goods_commodity; //商品信息
-
- $eorder[ 'IsReturnPrintTemplate' ] = 1; //是否返回电子模板
-
- $jsonResult = $kdniao->submitEOrder($eorder);
-
- $result = json_decode($jsonResult, true);
- if (isset($result[ 'ResultCode' ])) {
- if ($result[ 'ResultCode' ] == '100' || $result[ 'ResultCode' ] == '106') {
- return $result;
- }
- }
- return $this->error('', $result[ 'Reason' ]);
- }
-
+getElectronicsheetConfig($param[ 'site_id' ])[ 'data' ][ 'value' ];
+ if (empty($config_info)) {
+ return $this->error('', '请先配置电子面单');
+ }
+
+ if (empty($param[ 'template_id' ])) {
+ return $this->error('', '请先配置电子面单模板');
+ }
+ //获取电子模板信息
+ $template = $electronicsheet_model->getExpressElectronicsheetInfo([ [ 'id', '=', $param[ 'template_id' ] ] ])[ 'data' ];
+ if (empty($template)) {
+ return $this->error('', '电子面单模板不存在');
+ }
+
+ //获取店铺信息
+ $shop_model = new Shop();
+ $shop_info = $shop_model->getShopInfo([ [ 'site_id', '=', $param[ 'site_id' ] ] ])[ 'data' ];
+
+ if (empty($shop_info[ 'name' ])) {
+ return $this->error('', '店铺联系地址中联系人姓名未设置');
+ }
+ if (empty($shop_info[ 'province_name' ]) || empty($shop_info[ 'city_name' ]) || empty($shop_info[ 'district_name' ]) || empty($shop_info[ 'address' ])) {
+ return $this->error('', '店铺联系地址中联系地址未设置');
+ }
+ if (empty($shop_info[ 'telephone' ]) && empty($shop_info[ 'mobile' ])) {
+ return $this->error('', '店铺联系地址中联系方式未设置');
+ }
+
+ $result = $this->electronicsheetDelivery($param, $config_info, $template, $shop_info);
+ if (isset($result[ 'code' ]) && $result[ 'code' ] < 0) {
+ return $result;
+ } else {
+ return $this->success($result);
+ }
+ }
+
+ /**
+ * 电子面单发货
+ * @param $delivery_id //包裹id
+ * @param $config_info //快递鸟配置信息
+ * @param $template //电子面单模板
+ * @param $shop_info //发货人信息
+ * @param $goods_array //商品信息
+ * @return array
+ */
+ public function electronicsheetDelivery($param, $config_info, $template, $shop_info)
+ {
+ //获取订单信息
+ $order_info = model('order')->getInfo([ [ 'order_id', '=', $param[ 'order_id' ] ] ]);
+ //获取快递公司编码
+ $express_company = model('express_company_template')->getInfo([ [ 'company_id', '=', $template[ 'company_id' ] ] ], 'express_no,print_style');
+ $print_style = json_decode($express_company[ 'print_style' ], true);
+
+ $goods_commodity = [];
+ //获取商品信息
+ if (empty($param[ 'order_goods_id_array' ])) {
+ $goods_array = model('order_goods')->getList(
+ [
+ [ 'order_id', '=', $param[ 'order_id' ] ]
+ ], 'sku_name as GoodsName,num as GoodsQuantity'
+ );
+ } else {
+ $goods_array = model('order_goods')->getList(
+ [
+ [ 'order_goods_id', 'in', $param[ 'order_goods_id_array' ] ],
+ [ 'order_id', '=', $param[ 'order_id' ] ]
+ ], 'sku_name as GoodsName,num as GoodsQuantity'
+ );
+ }
+ //替换商品名称中的特殊字符 ' " # & + < > % \
+ $search = array ( "'", '"', '&', '+', '<', '>', '%', "\\", '#', "and" );
+ foreach ($goods_array as $key => $val){
+ $goods_commodity[] = [
+ 'GoodsName' => str_replace($search, '', $val[ 'GoodsName' ]),
+ 'GoodsQuantity' => $val['GoodsQuantity']
+ ];
+ }
+
+ //实例化快递鸟
+ $config = [
+ 'EBusinessID' => $config_info[ 'kdniao_user_id' ],
+ 'AppKey' => $config_info[ 'kdniao_api_key' ]
+ ];
+ $kdniao = new Kdniao($config);
+ //构造电子面单提交信息
+ $eorder = [];
+ $eorder[ 'CustomerName' ] = $template[ 'customer_name' ];
+ $eorder[ 'CustomerPwd' ] = $template[ 'customer_pwd' ];
+ $eorder[ 'SendSite' ] = $template[ 'send_site' ];
+ $eorder[ 'SendStaff' ] = $template[ 'send_staff' ];
+ $eorder[ 'MonthCode' ] = $template[ 'month_code' ];
+ $eorder[ 'ShipperCode' ] = $express_company[ 'express_no' ];//快递公司编码
+ $eorder[ 'OrderCode' ] = $order_info[ 'order_no' ];//订单号
+ $eorder[ 'PayType' ] = $template[ 'postage_payment_method' ]; //邮费支付方式
+ $eorder[ 'ExpType' ] = 1; //快递类型
+ $eorder[ 'TemplateSize' ] = $print_style[ $template[ 'print_style' ] ][ 'template_size' ]; //模板规格
+ //发货人信息
+ $sender = [];
+ $sender[ 'Name' ] = $shop_info[ 'name' ];
+ $sender[ 'Mobile' ] = $shop_info[ 'mobile' ];
+ $sender[ 'Tel' ] = $shop_info[ 'telephone' ];
+ $sender[ 'ProvinceName' ] = $shop_info[ 'province_name' ];
+ $sender[ 'CityName' ] = $shop_info[ 'city_name' ];
+ $sender[ 'ExpAreaName' ] = $shop_info[ 'district_name' ];
+ $sender[ 'Address' ] = $shop_info[ 'address' ];
+ $sender[ 'PostCode' ] = '000000';
+ //获取收货人信息
+ $area_model = new Address();
+ $province_name = $area_model->getAreasInfo([ [ 'id', '=', $order_info[ 'province_id' ] ] ], 'name');
+ $city_name = $area_model->getAreasInfo([ [ 'id', '=', $order_info[ 'city_id' ] ] ], 'name');
+ $district_name = $area_model->getAreasInfo([ [ 'id', '=', $order_info[ 'district_id' ] ] ], 'name');
+ $receiver = [];
+ $receiver[ 'Name' ] = $order_info[ 'name' ];
+ $receiver[ 'Mobile' ] = $order_info[ 'mobile' ];
+ $receiver[ 'ProvinceName' ] = $province_name[ 'data' ][ 'name' ];
+ $receiver[ 'CityName' ] = $city_name[ 'data' ][ 'name' ];
+ $receiver[ 'ExpAreaName' ] = empty($district_name[ 'data' ][ 'name' ]) ? '' : $district_name[ 'data' ][ 'name' ];
+ $receiver[ 'Address' ] = $order_info[ 'address' ];
+ $receiver[ 'PostCode' ] = '000000';
+
+// $commodity[] = $goods_array;
+ $eorder[ 'Sender' ] = $sender;
+ $eorder[ 'Receiver' ] = $receiver;
+ $eorder[ 'Commodity' ] = $goods_commodity; //商品信息
+
+ $eorder[ 'IsReturnPrintTemplate' ] = 1; //是否返回电子模板
+
+ $jsonResult = $kdniao->submitEOrder($eorder);
+
+ $result = json_decode($jsonResult, true);
+ if (isset($result[ 'ResultCode' ])) {
+ if ($result[ 'ResultCode' ] == '100' || $result[ 'ResultCode' ] == '106') {
+ return $result;
+ }
+ }
+ return $this->error('', $result[ 'Reason' ]);
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/electronicsheet/model/ExpressElectronicsheet.php b/src/addon/electronicsheet/model/ExpressElectronicsheet.php
index f19ea82d3..6be245134 100644
--- a/src/addon/electronicsheet/model/ExpressElectronicsheet.php
+++ b/src/addon/electronicsheet/model/ExpressElectronicsheet.php
@@ -1,213 +1,205 @@
-setConfig($data, '电子面单设置', 1, [ [ 'site_id', '=', $data[ 'site_id' ] ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'ELECTRONICSHEET_CONFIG' ] ]);
- return $this->success($res);
- }
-
- /**
- * 获取电子面单设置
- * @return array
- */
- public function getElectronicsheetConfig($site_id)
- {
- $config = new Config();
- $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'ELECTRONICSHEET_CONFIG' ] ]);
- if (empty($res[ 'data' ][ 'value' ])) {
- $res[ 'data' ][ 'value' ] = [
- 'type' => 'kdniao',
-
- 'kdniao_user_id' => '',
- 'kdniao_api_key' => '',
- 'kdniao_port' => '',
-
- 'cainiao_token' => '',
- 'cainiao_ip' => ''
- ];
- }
- return $res;
- }
-
- /************************************ 电子面单设置 end **********************************************************/
-
- /**
- * 添加电子面单
- * @param $data
- * @return array
- */
- public function addExpressElectronicsheet($data)
- {
- //判断模板名称是否重复
- $count = model('express_electronicsheet')->getCount(
- [
- [ 'site_id', '=', $data[ 'site_id' ] ],
- [ 'template_name', '=', $data[ 'template_name' ] ]
- ]);
-
- if ($count > 0) {
- return $this->error('', '该电子面单名称已存在');
- }
- $express_company_model = new ExpressCompanyTemplate();
- $express_company_info = $express_company_model->getExpressCompanyTemplateInfo([ [ 'company_id', '=', $data[ 'company_id' ] ] ], 'company_id,company_name,express_no');
- if (empty($express_company_info)) {
- return $this->error('', '快递公司不存在');
- }
- if (empty($express_company_info[ 'data' ][ 'express_no' ]) || empty($express_company_info[ 'data' ][ 'company_name' ])) {
- return $this->error('', '快递公司名称或者快递鸟编码为空');
- }
-
- $data[ 'express_no' ] = $express_company_info[ 'data' ][ 'express_no' ];
- $data[ 'company_name' ] = $express_company_info[ 'data' ][ 'company_name' ];
- $data[ 'create_time' ] = time();
-
- model('express_electronicsheet')->startTrans();
- try {
-
- if ($data[ 'is_default' ] == 1) {
- $this->setExpressElectronicsheetDefault([ [ 'site_id', '=', $data[ 'site_id' ] ], [ 'is_default', '=', 1 ] ], 0);
- }
- model('express_electronicsheet')->add($data);
-
- model('express_electronicsheet')->commit();
- return $this->success();
- } catch (\Exception $e) {
- model('express_electronicsheet')->rollback();
- return $this->error('', $e->getMessage());
- }
- }
-
- /**
- * 编辑电子面单
- * @param $data
- * @return array
- */
- public function editExpressElectronicsheet($data)
- {
- //判断模板名称是否重复
- $count = model('express_electronicsheet')->getCount(
- [
- [ 'site_id', '=', $data[ 'site_id' ] ],
- [ 'id', '<>', $data[ 'id' ] ],
- [ 'template_name', '=', $data[ 'template_name' ] ]
- ]);
- if ($count > 0) {
- return $this->error('', '该电子面单名称已存在');
- }
-
- $express_company_model = new ExpressCompanyTemplate();
- $express_company_info = $express_company_model->getExpressCompanyTemplateInfo([ [ 'company_id', '=', $data[ 'company_id' ] ] ], 'company_id,company_name,express_no');
- if (empty($express_company_info)) {
- return $this->error('', '快递公司不存在');
- }
- if (empty($express_company_info[ 'data' ][ 'express_no' ]) || empty($express_company_info[ 'data' ][ 'company_name' ])) {
- return $this->error('', '快递公司名称或者快递鸟编码为空');
- }
- $data[ 'express_no' ] = $express_company_info[ 'data' ][ 'express_no' ];
- $data[ 'company_name' ] = $express_company_info[ 'data' ][ 'company_name' ];
- $data[ 'update_time' ] = time();
-
- model('express_electronicsheet')->startTrans();
- try {
-
- if ($data[ 'is_default' ] == 1) {
- $this->setExpressElectronicsheetDefault([ [ 'site_id', '=', $data[ 'site_id' ] ], [ 'id', '<>', $data[ 'id' ] ], [ 'is_default', '=', 1 ] ], 0);
- }
- model('express_electronicsheet')->update($data, [ [ 'id', '=', $data[ 'id' ] ], [ 'site_id', '=', $data[ 'site_id' ] ] ]);
-
- model('express_electronicsheet')->commit();
- return $this->success();
- } catch (\Exception $e) {
-
- model('express_electronicsheet')->rollback();
- return $this->error('', $e->getMessage());
- }
- }
-
- /**
- * 设置默认状态
- * @param $condition
- * @param $is_default
- * @return array
- */
- public function setExpressElectronicsheetDefault($condition, $is_default)
- {
- $res = model('express_electronicsheet')->update([ 'is_default' => $is_default ], $condition);
- return $this->success($res);
- }
-
- /**
- * 删除
- * @param $condition
- * @return array
- */
- public function deleteExpressElectronicsheet($condition)
- {
- $res = model('express_electronicsheet')->delete($condition);
- return $this->success($res);
- }
-
- /**
- * 获取电子面单信息
- * @param array $condition
- * @param string $field
- * @return array
- */
- public function getExpressElectronicsheetInfo($condition = [], $field = '*')
- {
- $res = model('express_electronicsheet')->getInfo($condition, $field);
- return $this->success($res);
- }
-
- /**
- * 获取电子面单列表
- * @param array $condition
- * @param string $field
- * @param string $order
- * @param string $limit
- */
- public function getExpressElectronicsheetList($condition = [], $field = '*', $order = '', $limit = null)
- {
- $list = model('express_electronicsheet')->getList($condition, $field, $order, '', '', '', $limit);
- return $this->success($list);
- }
-
- /**
- * 获取电子面单分页列表
- * @param array $condition
- * @param number $page
- * @param string $page_size
- * @param string $order
- * @param string $field
- */
- public function getExpressElectronicsheetPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
- {
- $list = model('express_electronicsheet')->pageList($condition, $field, $order, $page, $page_size);
- return $this->success($list);
- }
-
+setConfig($data, '电子面单设置', 1, [ [ 'site_id', '=', $data[ 'site_id' ] ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'ELECTRONICSHEET_CONFIG' ] ]);
+ return $this->success($res);
+ }
+
+ /**
+ * 获取电子面单设置
+ * @return array
+ */
+ public function getElectronicsheetConfig($site_id)
+ {
+ $config = new Config();
+ $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'ELECTRONICSHEET_CONFIG' ] ]);
+ if (empty($res[ 'data' ][ 'value' ])) {
+ $res[ 'data' ][ 'value' ] = [
+ 'type' => 'kdniao',
+
+ 'kdniao_user_id' => '',
+ 'kdniao_api_key' => '',
+ 'kdniao_port' => '',
+
+ 'cainiao_token' => '',
+ 'cainiao_ip' => ''
+ ];
+ }
+ return $res;
+ }
+
+ /************************************ 电子面单设置 end **********************************************************/
+
+ /**
+ * 添加电子面单
+ * @param $data
+ * @return array
+ */
+ public function addExpressElectronicsheet($data)
+ {
+ //判断模板名称是否重复
+ $count = model('express_electronicsheet')->getCount(
+ [
+ [ 'site_id', '=', $data[ 'site_id' ] ],
+ [ 'template_name', '=', $data[ 'template_name' ] ]
+ ]);
+
+ if ($count > 0) {
+ return $this->error('', '该电子面单名称已存在');
+ }
+ $express_company_model = new ExpressCompanyTemplate();
+ $express_company_info = $express_company_model->getExpressCompanyTemplateInfo([ [ 'company_id', '=', $data[ 'company_id' ] ] ], 'company_id,company_name,express_no');
+ if (empty($express_company_info)) {
+ return $this->error('', '快递公司不存在');
+ }
+ if (empty($express_company_info[ 'data' ][ 'express_no' ]) || empty($express_company_info[ 'data' ][ 'company_name' ])) {
+ return $this->error('', '快递公司名称或者快递鸟编码为空');
+ }
+
+ $data[ 'express_no' ] = $express_company_info[ 'data' ][ 'express_no' ];
+ $data[ 'company_name' ] = $express_company_info[ 'data' ][ 'company_name' ];
+ $data[ 'create_time' ] = time();
+
+ model('express_electronicsheet')->startTrans();
+ try {
+
+ if ($data[ 'is_default' ] == 1) {
+ $this->setExpressElectronicsheetDefault([ [ 'site_id', '=', $data[ 'site_id' ] ], [ 'is_default', '=', 1 ] ], 0);
+ }
+ model('express_electronicsheet')->add($data);
+
+ model('express_electronicsheet')->commit();
+ return $this->success();
+ } catch (\Exception $e) {
+ model('express_electronicsheet')->rollback();
+ return $this->error('', $e->getMessage());
+ }
+ }
+
+ /**
+ * 编辑电子面单
+ * @param $data
+ * @return array
+ */
+ public function editExpressElectronicsheet($data)
+ {
+ //判断模板名称是否重复
+ $count = model('express_electronicsheet')->getCount(
+ [
+ [ 'site_id', '=', $data[ 'site_id' ] ],
+ [ 'id', '<>', $data[ 'id' ] ],
+ [ 'template_name', '=', $data[ 'template_name' ] ]
+ ]);
+ if ($count > 0) {
+ return $this->error('', '该电子面单名称已存在');
+ }
+
+ $express_company_model = new ExpressCompanyTemplate();
+ $express_company_info = $express_company_model->getExpressCompanyTemplateInfo([ [ 'company_id', '=', $data[ 'company_id' ] ] ], 'company_id,company_name,express_no');
+ if (empty($express_company_info)) {
+ return $this->error('', '快递公司不存在');
+ }
+ if (empty($express_company_info[ 'data' ][ 'express_no' ]) || empty($express_company_info[ 'data' ][ 'company_name' ])) {
+ return $this->error('', '快递公司名称或者快递鸟编码为空');
+ }
+ $data[ 'express_no' ] = $express_company_info[ 'data' ][ 'express_no' ];
+ $data[ 'company_name' ] = $express_company_info[ 'data' ][ 'company_name' ];
+ $data[ 'update_time' ] = time();
+
+ model('express_electronicsheet')->startTrans();
+ try {
+
+ if ($data[ 'is_default' ] == 1) {
+ $this->setExpressElectronicsheetDefault([ [ 'site_id', '=', $data[ 'site_id' ] ], [ 'id', '<>', $data[ 'id' ] ], [ 'is_default', '=', 1 ] ], 0);
+ }
+ model('express_electronicsheet')->update($data, [ [ 'id', '=', $data[ 'id' ] ], [ 'site_id', '=', $data[ 'site_id' ] ] ]);
+
+ model('express_electronicsheet')->commit();
+ return $this->success();
+ } catch (\Exception $e) {
+
+ model('express_electronicsheet')->rollback();
+ return $this->error('', $e->getMessage());
+ }
+ }
+
+ /**
+ * 设置默认状态
+ * @param $condition
+ * @param $is_default
+ * @return array
+ */
+ public function setExpressElectronicsheetDefault($condition, $is_default)
+ {
+ $res = model('express_electronicsheet')->update([ 'is_default' => $is_default ], $condition);
+ return $this->success($res);
+ }
+
+ /**
+ * 删除
+ * @param $condition
+ * @return array
+ */
+ public function deleteExpressElectronicsheet($condition)
+ {
+ $res = model('express_electronicsheet')->delete($condition);
+ return $this->success($res);
+ }
+
+ /**
+ * 获取电子面单信息
+ * @param array $condition
+ * @param string $field
+ * @return array
+ */
+ public function getExpressElectronicsheetInfo($condition = [], $field = '*')
+ {
+ $res = model('express_electronicsheet')->getInfo($condition, $field);
+ return $this->success($res);
+ }
+
+ /**
+ * 获取电子面单列表
+ * @param array $condition
+ * @param string $field
+ * @param string $order
+ * @param string $limit
+ */
+ public function getExpressElectronicsheetList($condition = [], $field = '*', $order = '', $limit = null)
+ {
+ $list = model('express_electronicsheet')->getList($condition, $field, $order, '', '', '', $limit);
+ return $this->success($list);
+ }
+
+ /**
+ * 获取电子面单分页列表
+ * @param array $condition
+ * @param number $page
+ * @param string $page_size
+ * @param string $order
+ * @param string $field
+ */
+ public function getExpressElectronicsheetPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
+ {
+ $list = model('express_electronicsheet')->pageList($condition, $field, $order, $page, $page_size);
+ return $this->success($list);
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/electronicsheet/shop/controller/Config.php b/src/addon/electronicsheet/shop/controller/Config.php
index 997843eba..480bf30d9 100644
--- a/src/addon/electronicsheet/shop/controller/Config.php
+++ b/src/addon/electronicsheet/shop/controller/Config.php
@@ -1,47 +1,39 @@
-isJson()) {
-
- $data = [
- 'site_id' => $this->site_id,
- 'type' => input('type', 'kdniao'),
- 'kdniao_user_id' => input('kdniao_user_id', ''),
- 'kdniao_api_key' => input('kdniao_api_key', ''),
- 'kdniao_port' => input('kdniao_port', ''),
- 'cainiao_token' => input('cainiao_token', ''),
- 'cainiao_ip' => input('cainiao_ip', ''),
- ];
-
- return $config->setElectronicsheetConfig($data);
- } else {
-
- $res = $config->getElectronicsheetConfig($this->site_id);
- $this->assign('config_info', $res[ 'data' ][ 'value' ]);
- return $this->fetch('config/config');
- }
- }
-
+isJson()) {
+
+ $data = [
+ 'site_id' => $this->site_id,
+ 'type' => input('type', 'kdniao'),
+ 'kdniao_user_id' => input('kdniao_user_id', ''),
+ 'kdniao_api_key' => input('kdniao_api_key', ''),
+ 'kdniao_port' => input('kdniao_port', ''),
+ 'cainiao_token' => input('cainiao_token', ''),
+ 'cainiao_ip' => input('cainiao_ip', ''),
+ ];
+
+ return $config->setElectronicsheetConfig($data);
+ } else {
+
+ $res = $config->getElectronicsheetConfig($this->site_id);
+ $this->assign('config_info', $res[ 'data' ][ 'value' ]);
+ return $this->fetch('config/config');
+ }
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/electronicsheet/shop/controller/Electronicsheet.php b/src/addon/electronicsheet/shop/controller/Electronicsheet.php
index 601ca1949..d211f3822 100644
--- a/src/addon/electronicsheet/shop/controller/Electronicsheet.php
+++ b/src/addon/electronicsheet/shop/controller/Electronicsheet.php
@@ -1,146 +1,138 @@
-site_id ];
- //获取续签信息
- if (request()->isJson()) {
- $status = input('status', '');//模板状态
- if ($status) {
- $condition[] = [ 'status', '=', $status ];
- }
- $template_name = input('template_name', '');
- if ($template_name) {
- $condition[] = [ 'template_name', 'like', '%' . $template_name . '%' ];
- }
-
- $page = input('page', 1);
- $page_size = input('page_size', PAGE_LIST_ROWS);
- $list = $model->getExpressElectronicsheetPageList($condition, $page, $page_size, 'is_default desc');
- return $list;
- }
- return $this->fetch('electronicsheet/lists');
- }
-
- /**
- * 添加电子面单
- */
- public function add()
- {
- if (request()->isJson()) {
- $data = [
- 'site_id' => $this->site_id,
- 'template_name' => input('template_name', ''),
- 'company_id' => input('company_id', ''),
- 'customer_name' => input('customer_name', ''),
- 'customer_pwd' => input('customer_pwd', ''),
- 'send_site' => input('send_site', ''),
- 'send_staff' => input('send_staff', ''),
- 'month_code' => input('month_code', ''),
- 'postage_payment_method' => input('postage_payment_method', ''),
- 'is_notice' => input('is_notice', ''),
- 'is_default' => input('is_default', 0),
- 'print_style' => input('print_style', 0),
- ];
- $model = new ExpressElectronicsheetModel();
- return $model->addExpressElectronicsheet($data);
-
- } else {
- //快递公司
- $express_company_model = new ExpressCompanyTemplate();
- $condition = [
- [ 'is_electronicsheet', '=', 1 ],
- ];
- $company_list = $express_company_model->getExpressCompanyTemplateList($condition, 'company_id,company_name,print_style', 'sort asc');
- $this->assign('company_list', $company_list[ 'data' ]);
- return $this->fetch('electronicsheet/add');
- }
- }
-
- /**
- * 编辑电子面单
- */
- public function edit()
- {
- $model = new ExpressElectronicsheetModel();
- $id = input('id', 0);
- if (request()->isJson()) {
- $data = [
- 'id' => $id,
- 'site_id' => $this->site_id,
- 'template_name' => input('template_name', ''),
- 'company_id' => input('company_id', ''),
- 'customer_name' => input('customer_name', ''),
- 'customer_pwd' => input('customer_pwd', ''),
- 'send_site' => input('send_site', ''),
- 'send_staff' => input('send_staff', ''),
- 'month_code' => input('month_code', ''),
- 'postage_payment_method' => input('postage_payment_method', ''),
- 'is_notice' => input('is_notice', ''),
- 'is_default' => input('is_default', 0),
- 'print_style' => input('print_style', 0),
- ];
- return $model->editExpressElectronicsheet($data);
-
- } else {
-
- $info = $model->getExpressElectronicsheetInfo([ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ]);
- $this->assign('electronicsheet_info', $info[ 'data' ]);
- //快递公司
- $express_company_model = new ExpressCompanyTemplate();
- $condition = [
- [ 'is_electronicsheet', '=', 1 ],
-
- ];
- $company_list = $express_company_model->getExpressCompanyTemplateList($condition, 'company_id,company_name,print_style', 'sort asc');
- $this->assign('company_list', $company_list[ 'data' ]);
- return $this->fetch('electronicsheet/edit');
- }
- }
-
- /*
- * 删除
- */
- public function delete()
- {
- $id = input('id', '');
-
- $groupbuy_model = new ExpressElectronicsheetModel();
- return $groupbuy_model->deleteExpressElectronicsheet([ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ]);
- }
-
- /*
- * 修改默认状态
- */
- public function setDefaultStatus()
- {
- $id = input('id', '');
-
- $groupbuy_model = new ExpressElectronicsheetModel();
- $groupbuy_model->setExpressElectronicsheetDefault([ [ 'site_id', '=', $this->site_id ] ], 0);
- return $groupbuy_model->setExpressElectronicsheetDefault([ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ], 1);
- }
-
+site_id ];
+ //获取续签信息
+ if (request()->isJson()) {
+ $status = input('status', '');//模板状态
+ if ($status) {
+ $condition[] = [ 'status', '=', $status ];
+ }
+ $template_name = input('template_name', '');
+ if ($template_name) {
+ $condition[] = [ 'template_name', 'like', '%' . $template_name . '%' ];
+ }
+
+ $page = input('page', 1);
+ $page_size = input('page_size', PAGE_LIST_ROWS);
+ $list = $model->getExpressElectronicsheetPageList($condition, $page, $page_size, 'is_default desc');
+ return $list;
+ }
+ return $this->fetch('electronicsheet/lists');
+ }
+
+ /**
+ * 添加电子面单
+ */
+ public function add()
+ {
+ if (request()->isJson()) {
+ $data = [
+ 'site_id' => $this->site_id,
+ 'template_name' => input('template_name', ''),
+ 'company_id' => input('company_id', ''),
+ 'customer_name' => input('customer_name', ''),
+ 'customer_pwd' => input('customer_pwd', ''),
+ 'send_site' => input('send_site', ''),
+ 'send_staff' => input('send_staff', ''),
+ 'month_code' => input('month_code', ''),
+ 'postage_payment_method' => input('postage_payment_method', ''),
+ 'is_notice' => input('is_notice', ''),
+ 'is_default' => input('is_default', 0),
+ 'print_style' => input('print_style', 0),
+ ];
+ $model = new ExpressElectronicsheetModel();
+ return $model->addExpressElectronicsheet($data);
+
+ } else {
+ //快递公司
+ $express_company_model = new ExpressCompanyTemplate();
+ $condition = [
+ [ 'is_electronicsheet', '=', 1 ],
+ ];
+ $company_list = $express_company_model->getExpressCompanyTemplateList($condition, 'company_id,company_name,print_style', 'sort asc');
+ $this->assign('company_list', $company_list[ 'data' ]);
+ return $this->fetch('electronicsheet/add');
+ }
+ }
+
+ /**
+ * 编辑电子面单
+ */
+ public function edit()
+ {
+ $model = new ExpressElectronicsheetModel();
+ $id = input('id', 0);
+ if (request()->isJson()) {
+ $data = [
+ 'id' => $id,
+ 'site_id' => $this->site_id,
+ 'template_name' => input('template_name', ''),
+ 'company_id' => input('company_id', ''),
+ 'customer_name' => input('customer_name', ''),
+ 'customer_pwd' => input('customer_pwd', ''),
+ 'send_site' => input('send_site', ''),
+ 'send_staff' => input('send_staff', ''),
+ 'month_code' => input('month_code', ''),
+ 'postage_payment_method' => input('postage_payment_method', ''),
+ 'is_notice' => input('is_notice', ''),
+ 'is_default' => input('is_default', 0),
+ 'print_style' => input('print_style', 0),
+ ];
+ return $model->editExpressElectronicsheet($data);
+
+ } else {
+
+ $info = $model->getExpressElectronicsheetInfo([ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ]);
+ $this->assign('electronicsheet_info', $info[ 'data' ]);
+ //快递公司
+ $express_company_model = new ExpressCompanyTemplate();
+ $condition = [
+ [ 'is_electronicsheet', '=', 1 ],
+
+ ];
+ $company_list = $express_company_model->getExpressCompanyTemplateList($condition, 'company_id,company_name,print_style', 'sort asc');
+ $this->assign('company_list', $company_list[ 'data' ]);
+ return $this->fetch('electronicsheet/edit');
+ }
+ }
+
+ /*
+ * 删除
+ */
+ public function delete()
+ {
+ $id = input('id', '');
+
+ $groupbuy_model = new ExpressElectronicsheetModel();
+ return $groupbuy_model->deleteExpressElectronicsheet([ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ]);
+ }
+
+ /*
+ * 修改默认状态
+ */
+ public function setDefaultStatus()
+ {
+ $id = input('id', '');
+
+ $groupbuy_model = new ExpressElectronicsheetModel();
+ $groupbuy_model->setExpressElectronicsheetDefault([ [ 'site_id', '=', $this->site_id ] ], 0);
+ return $groupbuy_model->setExpressElectronicsheetDefault([ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ], 1);
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/api/controller/Account.php b/src/addon/fenxiao/api/controller/Account.php
index 8827bc0e9..da3a1aaed 100644
--- a/src/addon/fenxiao/api/controller/Account.php
+++ b/src/addon/fenxiao/api/controller/Account.php
@@ -1,50 +1,42 @@
-checkToken();
- if ($token[ 'code' ] < 0) return $this->response($token);
-
- $page = $this->params['page'] ?? 1;
- $page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
-
- $model = new FenxiaoModel();
- $fenxiao_info = $model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id')[ 'data' ];
- if (!empty($fenxiao_info[ 'fenxiao_id' ])) {
- $condition = [
- [ 'fenxiao_id', '=', $fenxiao_info[ 'fenxiao_id' ] ]
- ];
-
- $account_model = new FenxiaoAccount();
- $list = $account_model->getFenxiaoAccountPageList($condition, $page, $page_size);
- return $this->response($list);
- }
- return $this->response($this->error('', 'FENXIAO_NOT_EXIST'));
- }
-
+checkToken();
+ if ($token[ 'code' ] < 0) return $this->response($token);
+
+ $page = $this->params['page'] ?? 1;
+ $page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
+
+ $model = new FenxiaoModel();
+ $fenxiao_info = $model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id')[ 'data' ];
+ if (!empty($fenxiao_info[ 'fenxiao_id' ])) {
+ $condition = [
+ [ 'fenxiao_id', '=', $fenxiao_info[ 'fenxiao_id' ] ]
+ ];
+
+ $account_model = new FenxiaoAccount();
+ $list = $account_model->getFenxiaoAccountPageList($condition, $page, $page_size);
+ return $this->response($list);
+ }
+ return $this->response($this->error('', 'FENXIAO_NOT_EXIST'));
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/api/controller/Apply.php b/src/addon/fenxiao/api/controller/Apply.php
index dd98e7ffe..27a0f355f 100644
--- a/src/addon/fenxiao/api/controller/Apply.php
+++ b/src/addon/fenxiao/api/controller/Apply.php
@@ -1,99 +1,91 @@
-checkToken();
- if ($token[ 'code' ] < 0) return $this->response($token);
-
- $fenxiao_name = $this->params['fenxiao_name'] ?? '';//分销商名称
- if (empty($fenxiao_name)) {
- return $this->response($this->error('', 'REQUEST_FENXIAO_NAME'));
- }
-
- $apply_model = new FenxiaoApply();
- $res = $apply_model->existFenxiaoName($fenxiao_name, $this->site_id);
-
- return $this->response($res);
- }
-
- /**
- * 申请成为分销商
- */
- public function applyFenxiao()
- {
- $token = $this->checkToken();
- if ($token[ 'code' ] < 0) return $this->response($token);
-
- $fenxiao_name = $this->params['fenxiao_name'] ?? '';//分销商名称
- $mobile = $this->params['mobile'] ?? '';//联系电话
-
- $config = new Config();
- $basics_config = $config->getFenxiaoBasicsConfig($this->site_id)[ 'data' ][ 'value' ];
- if (!$basics_config[ 'level' ]) return $this->response($this->error('', '未开启分销功能'));
-
- if ($basics_config[ 'is_apply' ] == 1) {
- if (empty($fenxiao_name)) {
- return $this->response($this->error('', 'REQUEST_FENXIAO_NAME'));
- }
- if (empty($mobile)) {
- return $this->response($this->error('', 'REQUEST_MOBILE'));
- }
- $apply_model = new FenxiaoApply();
- $res = $apply_model->applyFenxiao($this->member_id, $this->site_id, $fenxiao_name, $mobile);
- } else if ($basics_config[ 'is_apply' ] == 0) {
- $apply_model = new Fenxiao();
- $res = $apply_model->autoBecomeFenxiao($this->member_id, $this->site_id);
- } else {
- return $this->response($this->error('', '未开启分销商申请'));
- }
-
- return $this->response($res);
- }
-
- public function info()
- {
- $token = $this->checkToken();
- if ($token[ 'code' ] < 0) return $this->response($token);
-
- $apply_model = new Fenxiao();
- $apply_model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'apply_id,fenxiao_name,parent,member_id,mobile,nickname,headimg,level_id,level_name,status');
- }
-
- /**
- * 获取申请分销商状态
- * @return false|string
- */
- public function status()
- {
- $token = $this->checkToken();
- if ($token[ 'code' ] < 0) return $this->response($token);
-
- $apply_model = new FenxiaoApply();
- $res = $apply_model->getFenxiaoApplyInfo([ [ 'member_id', '=', $this->member_id ] ], 'status');
- return $this->response($res);
- }
-
+checkToken();
+ if ($token[ 'code' ] < 0) return $this->response($token);
+
+ $fenxiao_name = $this->params['fenxiao_name'] ?? '';//分销商名称
+ if (empty($fenxiao_name)) {
+ return $this->response($this->error('', 'REQUEST_FENXIAO_NAME'));
+ }
+
+ $apply_model = new FenxiaoApply();
+ $res = $apply_model->existFenxiaoName($fenxiao_name, $this->site_id);
+
+ return $this->response($res);
+ }
+
+ /**
+ * 申请成为分销商
+ */
+ public function applyFenxiao()
+ {
+ $token = $this->checkToken();
+ if ($token[ 'code' ] < 0) return $this->response($token);
+
+ $fenxiao_name = $this->params['fenxiao_name'] ?? '';//分销商名称
+ $mobile = $this->params['mobile'] ?? '';//联系电话
+
+ $config = new Config();
+ $basics_config = $config->getFenxiaoBasicsConfig($this->site_id)[ 'data' ][ 'value' ];
+ if (!$basics_config[ 'level' ]) return $this->response($this->error('', '未开启分销功能'));
+
+ if ($basics_config[ 'is_apply' ] == 1) {
+ if (empty($fenxiao_name)) {
+ return $this->response($this->error('', 'REQUEST_FENXIAO_NAME'));
+ }
+ if (empty($mobile)) {
+ return $this->response($this->error('', 'REQUEST_MOBILE'));
+ }
+ $apply_model = new FenxiaoApply();
+ $res = $apply_model->applyFenxiao($this->member_id, $this->site_id, $fenxiao_name, $mobile);
+ } else if ($basics_config[ 'is_apply' ] == 0) {
+ $apply_model = new Fenxiao();
+ $res = $apply_model->autoBecomeFenxiao($this->member_id, $this->site_id);
+ } else {
+ return $this->response($this->error('', '未开启分销商申请'));
+ }
+
+ return $this->response($res);
+ }
+
+ public function info()
+ {
+ $token = $this->checkToken();
+ if ($token[ 'code' ] < 0) return $this->response($token);
+
+ $apply_model = new Fenxiao();
+ $apply_model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'apply_id,fenxiao_name,parent,member_id,mobile,nickname,headimg,level_id,level_name,status');
+ }
+
+ /**
+ * 获取申请分销商状态
+ * @return false|string
+ */
+ public function status()
+ {
+ $token = $this->checkToken();
+ if ($token[ 'code' ] < 0) return $this->response($token);
+
+ $apply_model = new FenxiaoApply();
+ $res = $apply_model->getFenxiaoApplyInfo([ [ 'member_id', '=', $this->member_id ] ], 'status');
+ return $this->response($res);
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/api/controller/Config.php b/src/addon/fenxiao/api/controller/Config.php
index 50c25a122..48a105850 100644
--- a/src/addon/fenxiao/api/controller/Config.php
+++ b/src/addon/fenxiao/api/controller/Config.php
@@ -1,127 +1,119 @@
-getFenxiaoWithdrawConfig($this->site_id);
- return $this->response($this->success($res[ 'data' ][ 'value' ]));
- }
-
- /**
- * 文字设置
- * @return false|string
- */
- public function words()
- {
- $config = new ConfigModel();
- $res = $config->getFenxiaoWordsConfig($this->site_id);
- return $this->response($this->success($res[ 'data' ][ 'value' ]));
- }
-
- /**
- * 申请协议
- * @return false|string
- */
- public function agreement()
- {
- $config = new ConfigModel();
- $agreement = $config->getFenxiaoAgreementConfig($this->site_id);
- $res = [];
- $res[ 'agreement' ] = $agreement[ 'data' ][ 'value' ];
- if ($agreement[ 'data' ][ 'value' ][ 'is_agreement' ] == 1) {
- $document_model = new Document();
- $document = $document_model->getDocument([ [ 'site_id', '=', $this->site_id ], [ 'app_module', '=', 'shop' ], [ 'document_key', '=', 'FENXIAO_AGREEMENT'] ]);
- $res[ 'document' ] = $document[ 'data' ];
- }
-
- return $this->response($this->success($res));
- }
-
- /**
- * 分销基本设置
- * @return false|string
- */
- public function basics()
- {
- $config = new ConfigModel();
- $res = $config->getFenxiaoBasicsConfig($this->site_id);
- return $this->response($this->success($res[ 'data' ][ 'value' ]));
- }
-
- /**
- * 分销商资格设置
- * @return false|string
- */
- public function fenxiao()
- {
- $config = new ConfigModel();
- $res = $config->getFenxiaoConfig($this->site_id);
- $res[ 'data' ][ 'value' ][ 'goods_list' ] = [];
- // 购买指定商品
- if ($res[ 'data' ][ 'value' ][ 'fenxiao_condition' ] == 4) {
- $page = $this->params[ 'page' ] ?? 1;
- $page_size = $this->params[ 'page_size' ] ?? 10;
- $condition[] = [ 'gs.goods_state', '=', 1 ];
- $condition[] = [ 'gs.is_delete', '=', 0 ];
- $condition[] = [ 'gs.site_id', '=', $this->site_id ];
- $condition[] = [ 'gs.goods_id', 'in', $res[ 'data' ][ 'value' ][ 'goods_ids' ] ];
-
- $field = 'gs.goods_id,gs.sku_id,gs.sku_name,gs.price,gs.market_price,gs.discount_price,gs.stock,(g.sale_num + g.virtual_sale) as sale_num,gs.sku_image,gs.goods_name,gs.site_id,gs.is_free_shipping,gs.introduction,gs.promotion_type,g.goods_image,gs.unit';
- $alias = 'gs';
- $join = [
- [ 'goods g', 'gs.sku_id = g.sku_id', 'inner' ]
- ];
- $goods = new Goods();
- $list = $goods->getGoodsSkuPageList($condition, $page, $page_size, '', $field, $alias, $join);
- $res[ 'data' ][ 'value' ][ 'goods_list' ] = $list[ 'data' ][ 'list' ];
- }
-
- return $this->response($this->success($res[ 'data' ][ 'value' ]));
- }
-
- /**
- * 获取上下级关系设置
- * @return false|string
- */
- public function relation()
- {
- $config = new ConfigModel();
- $res = $config->getFenxiaoRelationConfig($this->site_id);
- return $this->response($this->success($res[ 'data' ][ 'value' ]));
- }
-
- /**
- * 推广规则
- * @return false|string
- */
- public function promoteRule()
- {
- $document_model = new Document();
- $document = $document_model->getDocument([ [ 'site_id', '=', $this->site_id ], [ 'app_module', '=', 'shop' ], [ 'document_key', '=', 'FENXIAO_PROMOTE_RULE'] ]);
- return $this->response($document);
- }
+getFenxiaoWithdrawConfig($this->site_id);
+ return $this->response($this->success($res[ 'data' ][ 'value' ]));
+ }
+
+ /**
+ * 文字设置
+ * @return false|string
+ */
+ public function words()
+ {
+ $config = new ConfigModel();
+ $res = $config->getFenxiaoWordsConfig($this->site_id);
+ return $this->response($this->success($res[ 'data' ][ 'value' ]));
+ }
+
+ /**
+ * 申请协议
+ * @return false|string
+ */
+ public function agreement()
+ {
+ $config = new ConfigModel();
+ $agreement = $config->getFenxiaoAgreementConfig($this->site_id);
+ $res = [];
+ $res[ 'agreement' ] = $agreement[ 'data' ][ 'value' ];
+ if ($agreement[ 'data' ][ 'value' ][ 'is_agreement' ] == 1) {
+ $document_model = new Document();
+ $document = $document_model->getDocument([ [ 'site_id', '=', $this->site_id ], [ 'app_module', '=', 'shop' ], [ 'document_key', '=', 'FENXIAO_AGREEMENT'] ]);
+ $res[ 'document' ] = $document[ 'data' ];
+ }
+
+ return $this->response($this->success($res));
+ }
+
+ /**
+ * 分销基本设置
+ * @return false|string
+ */
+ public function basics()
+ {
+ $config = new ConfigModel();
+ $res = $config->getFenxiaoBasicsConfig($this->site_id);
+ return $this->response($this->success($res[ 'data' ][ 'value' ]));
+ }
+
+ /**
+ * 分销商资格设置
+ * @return false|string
+ */
+ public function fenxiao()
+ {
+ $config = new ConfigModel();
+ $res = $config->getFenxiaoConfig($this->site_id);
+ $res[ 'data' ][ 'value' ][ 'goods_list' ] = [];
+ // 购买指定商品
+ if ($res[ 'data' ][ 'value' ][ 'fenxiao_condition' ] == 4) {
+ $page = $this->params[ 'page' ] ?? 1;
+ $page_size = $this->params[ 'page_size' ] ?? 10;
+ $condition[] = [ 'gs.goods_state', '=', 1 ];
+ $condition[] = [ 'gs.is_delete', '=', 0 ];
+ $condition[] = [ 'gs.site_id', '=', $this->site_id ];
+ $condition[] = [ 'gs.goods_id', 'in', $res[ 'data' ][ 'value' ][ 'goods_ids' ] ];
+
+ $field = 'gs.goods_id,gs.sku_id,gs.sku_name,gs.price,gs.market_price,gs.discount_price,gs.stock,(g.sale_num + g.virtual_sale) as sale_num,gs.sku_image,gs.goods_name,gs.site_id,gs.is_free_shipping,gs.introduction,gs.promotion_type,g.goods_image,gs.unit';
+ $alias = 'gs';
+ $join = [
+ [ 'goods g', 'gs.sku_id = g.sku_id', 'inner' ]
+ ];
+ $goods = new Goods();
+ $list = $goods->getGoodsSkuPageList($condition, $page, $page_size, '', $field, $alias, $join);
+ $res[ 'data' ][ 'value' ][ 'goods_list' ] = $list[ 'data' ][ 'list' ];
+ }
+
+ return $this->response($this->success($res[ 'data' ][ 'value' ]));
+ }
+
+ /**
+ * 获取上下级关系设置
+ * @return false|string
+ */
+ public function relation()
+ {
+ $config = new ConfigModel();
+ $res = $config->getFenxiaoRelationConfig($this->site_id);
+ return $this->response($this->success($res[ 'data' ][ 'value' ]));
+ }
+
+ /**
+ * 推广规则
+ * @return false|string
+ */
+ public function promoteRule()
+ {
+ $document_model = new Document();
+ $document = $document_model->getDocument([ [ 'site_id', '=', $this->site_id ], [ 'app_module', '=', 'shop' ], [ 'document_key', '=', 'FENXIAO_PROMOTE_RULE'] ]);
+ return $this->response($document);
+ }
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/api/controller/Fenxiao.php b/src/addon/fenxiao/api/controller/Fenxiao.php
index 83c2eaac7..82a873551 100644
--- a/src/addon/fenxiao/api/controller/Fenxiao.php
+++ b/src/addon/fenxiao/api/controller/Fenxiao.php
@@ -1,407 +1,399 @@
-checkToken();
- if ($token[ 'code' ] < 0) return $this->response($token);
-
- $condition = [
- [ 'f.member_id', '=', $this->member_id ]
- ];
-
- $model = new FenxiaoModel();
- $info = $model->getFenxiaoDetailInfo($condition);
- if (empty($info[ 'data' ])) {
- $res = $model->autoBecomeFenxiao($this->member_id, $this->site_id);
- if (isset($res[ 'code' ]) && $res[ 'code' ] >= 0) {
- $info = $model->getFenxiaoDetailInfo($condition);
- }
- } else {
- $member = new Member();
- //$info[ 'data' ][ 'one_child_num' ] = $member->getMemberCount([ [ 'fenxiao_id', '=', $info[ 'data' ][ 'fenxiao_id' ] ], [ 'is_fenxiao', '=', 0 ] ])[ 'data' ];
-
- $condition_result = $model->geFenxiaoNextLevel($this->member_id, $this->site_id);
- $info[ 'data' ][ 'condition' ] = $condition_result[ 'data' ];
- }
-
- if (!empty($info[ 'data' ])) {
- $fenxiao_order_model = new FenxiaoOrderModel();
-
- // 今日收入
- $compare_today = Carbon::today()->timestamp;
- $compare_tomorrow = Carbon::tomorrow()->timestamp;
-
- $commission = 0;
- $one_commission = $fenxiao_order_model->getFenxiaoOrderInfo([ [ 'one_fenxiao_id', '=', $info[ 'data' ][ 'fenxiao_id' ] ], [ 'create_time', 'between', [ $compare_today, $compare_tomorrow ] ], [ 'is_settlement', '=', 1 ] ], 'sum(one_commission) as commission');
- $two_commission = $fenxiao_order_model->getFenxiaoOrderInfo([ [ 'two_fenxiao_id', '=', $info[ 'data' ][ 'fenxiao_id' ] ], [ 'create_time', 'between', [ $compare_today, $compare_tomorrow ] ], [ 'is_settlement', '=', 1 ] ], 'sum(two_commission) as commission');
- $three_commission = $fenxiao_order_model->getFenxiaoOrderInfo([ [ 'three_fenxiao_id', '=', $info[ 'data' ][ 'fenxiao_id' ] ], [ 'create_time', 'between', [ $compare_today, $compare_tomorrow ] ], [ 'is_settlement', '=', 1 ] ], 'sum(three_commission) as commission');
-
- if (!empty($one_commission[ 'data' ][ 'commission' ])) $commission += $one_commission[ 'data' ][ 'commission' ];
- if (!empty($two_commission[ 'data' ][ 'commission' ])) $commission += $two_commission[ 'data' ][ 'commission' ];
- if (!empty($three_commission[ 'data' ][ 'commission' ])) $commission += $three_commission[ 'data' ][ 'commission' ];
-
- $info[ 'data' ][ 'today_commission' ] = $commission;
-
- // 总销售额
- $fenxiao_order_info = $fenxiao_order_model->getFenxiaoOrderInfoNew([ [ 'fo.one_fenxiao_id|fo.two_fenxiao_id|fo.three_fenxiao_id', '=', $info[ 'data' ][ 'fenxiao_id' ] ], ['', 'exp', Db::raw('fo.is_refund=0 or (o.order_status=10 and fo.is_refund=1) ') ] ], 'sum(fo.real_goods_money) as real_goods_money');
-
- $fenxiao_order_info = $fenxiao_order_info[ 'data' ];
- if (empty($fenxiao_order_info[ 'real_goods_money' ])) {
- $fenxiao_order_info[ 'real_goods_money' ] = 0;
- }
- $info[ 'data' ][ 'today_order_money' ] = $fenxiao_order_info[ 'real_goods_money' ];
-
- $info[ 'data' ][ 'in_progress_money' ] = 0;
- $one_in_progress_commission = $fenxiao_order_model->getFenxiaoOrderInfo([ [ 'one_fenxiao_id', '=', $info[ 'data' ][ 'fenxiao_id' ] ], [ 'is_settlement', '=', 0 ], [ 'is_refund', '=', 0 ] ], 'sum(one_commission) as commission');
- $two_in_progress_commission = $fenxiao_order_model->getFenxiaoOrderInfo([ [ 'two_fenxiao_id', '=', $info[ 'data' ][ 'fenxiao_id' ] ], [ 'is_settlement', '=', 0 ], [ 'is_refund', '=', 0 ] ], 'sum(two_commission) as commission');
- $three_in_progress_commission = $fenxiao_order_model->getFenxiaoOrderInfo([ [ 'three_fenxiao_id', '=', $info[ 'data' ][ 'fenxiao_id' ] ], [ 'is_settlement', '=', 0 ], [ 'is_refund', '=', 0 ] ], 'sum(three_commission) as commission');
-
- if (!empty($one_in_progress_commission[ 'data' ][ 'commission' ])) $info[ 'data' ][ 'in_progress_money' ] += $one_in_progress_commission[ 'data' ][ 'commission' ];
- if (!empty($two_in_progress_commission[ 'data' ][ 'commission' ])) $info[ 'data' ][ 'in_progress_money' ] += $two_in_progress_commission[ 'data' ][ 'commission' ];
- if (!empty($three_in_progress_commission[ 'data' ][ 'commission' ])) $info[ 'data' ][ 'in_progress_money' ] += $three_in_progress_commission[ 'data' ][ 'commission' ];
- }
- return $this->response($info);
- }
-
- /**
- * 获取推荐人分销商信息
- */
- public function sourceInfo()
- {
- $token = $this->checkToken();
- if ($token[ 'code' ] < 0) return $this->response($token);
-
- $member = new Member();
- $member_info = $member->getMemberInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id');
- $fenxiao_id = $member_info[ 'data' ][ 'fenxiao_id' ] ?? 0;
-
- if (empty($fenxiao_id)) {
- return $this->response($this->error('', 'REQUEST_SOURCE_MEMBER'));
- }
- $condition = [
- [ 'fenxiao_id', '=', $fenxiao_id ]
- ];
-
- $model = new FenxiaoModel();
- $info = $model->getFenxiaoInfo($condition, 'fenxiao_name');
-
- return $this->response($info);
- }
-
- /**
- * 获取模板id
- * @return false|string
- */
- public function posterTemplateIds()
- {
- $token = $this->checkToken();
- if ($token[ 'code' ] < 0) return $this->response($token);
-
- $condition = [
- [ 'site_id', '=', $this->site_id ],
- [ 'template_type', '=', 'fenxiao' ],
- [ 'template_status', '=', 1 ],
- ];
- $condition[] = [ 'template_type', '=', 'fenxiao' ];
- $poster_template_model = new PosterTemplateModel();
- $list = $poster_template_model->getPosterTemplateList($condition, 'template_id', 'template_id asc')[ 'data' ];
- $id_arr = array_column($list, 'template_id');
- if (empty($id_arr)) $id_arr = [ 'default' ];
-
- return $this->response($this->success($id_arr));
- }
-
- /**
- * 分销海报
- * @return \app\api\controller\false|string
- */
- public function poster()
- {
- $token = $this->checkToken();
- if ($token[ 'code' ] < 0) return $this->response($token);
-
- $qrcode_param = $this->params['qrcode_param'] ?? '';//二维码
-
- if (empty($qrcode_param)) {
- return $this->response($this->error('', 'REQUEST_QRCODE_PARAM'));
- }
-
- $qrcode_param = json_decode($qrcode_param, true);
- $qrcode_param[ 'source_member' ] = $this->member_id;
-
- $poster = new Poster();
- $param = $this->params;
- $param[ 'qrcode_param' ] = $qrcode_param;
- $res = $poster->getFenxiaoPoster($param);
-
- return $this->response($res);
- }
-
- /**
- * 分销海报
- * @return \app\api\controller\false|string
- */
- public function posterList()
- {
- $token = $this->checkToken();
- if ($token[ 'code' ] < 0) return $this->response($token);
-
- $condition = [
- [ 'site_id', '=', $this->site_id ],
- [ 'template_type', '=', 'fenxiao' ],
- [ 'template_status', '=', 1 ],
- ];
- $condition[] = [ 'template_type', '=', 'fenxiao' ];
- $poster_template_model = new PosterTemplateModel();
- $list = $poster_template_model->getPosterTemplateList($condition, 'template_id', 'template_id asc')[ 'data' ];
- $id_arr = array_column($list, 'template_id');
- $id_arr = $id_arr ?: ['default'];
- $qrcode_param = $this->params['qrcode_param'] ?? '';//二维码
- $qrcode_param = [json_decode($qrcode_param, true)];
- $qrcode_param[ 'source_member' ] = $this->member_id;
- $poster = new Poster();
- $param = $this->params;
- $param[ 'qrcode_param' ] = $qrcode_param;
- $path = [];
- foreach ($id_arr as $k => $v){
- $param['template_id'] = $v;
- $res = $poster->getFenxiaoPoster($param)['data']['path'] ?? '';
- if($res) $path[] = $res;
- }
- return $this->response($this->success($path));
- }
-
- /**
- * 分销商等级信息
- */
- public function level()
- {
- $token = $this->checkToken();
- if ($token[ 'code' ] < 0) return $this->response($token);
-
- $level = $this->params[ 'level' ] ?? 0;
-
- $condition = [
- [ 'level_id', '=', $level ]
- ];
- $model = new FenxiaoLevel();
- $info = $model->getLevelInfo($condition);
-
- return $this->response($info);
- }
-
- /**
- * 分销商我的团队
- */
- public function team()
- {
- $token = $this->checkToken();
- if ($token[ 'code' ] < 0) return $this->response($token);
-
- $page = $this->params[ 'page' ] ?? 1;
- $page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
- $level = $this->params[ 'level' ] ?? 1;
- $is_pay = $this->params[ 'is_pay' ] ?? 0;
-
- $model = new FenxiaoModel();
- $fenxiao_info = $model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id');
- if (empty($fenxiao_info[ 'data' ])) return $this->response($this->error('', 'MEMBER_NOT_IS_FENXIAO'));
-
- $list = $model->getFenxiaoTeam($level, $fenxiao_info[ 'data' ][ 'fenxiao_id' ], $page, $page_size, $is_pay);
-
- return $this->response($list);
- }
-
- /**
- * 查询我的团队的数量
- */
- public function teamNum()
- {
- $token = $this->checkToken();
- if ($token[ 'code' ] < 0) return $this->response($token);
-
- $model = new FenxiaoModel();
- $fenxiao_info = $model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id');
- if (empty($fenxiao_info[ 'data' ])) return $this->response($this->error('', 'MEMBER_NOT_IS_FENXIAO'));
-
- $data = $model->getFenxiaoTeamNum($fenxiao_info[ 'data' ][ 'fenxiao_id' ], $this->site_id);
- return $this->response($data);
- }
-
- /**
- * 获取下级分销商订单
- * @return false|string
- */
- public function getOrder()
- {
- $token = $this->checkToken();
- if ($token[ 'code' ] < 0) return $this->response($token);
-
- $model = new FenxiaoModel();
- $fenxiao_info = $model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id');
- if (empty($fenxiao_info[ 'data' ])) return $this->response($this->error('', 'MEMBER_NOT_IS_FENXIAO'));
- $fenxiao_info = $fenxiao_info[ 'data' ];
-
- $page = $this->params[ 'page' ] ?? 1;
- $page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
- $fenxiao_id = $this->params[ 'fenxiao_id' ] ?? 0;
- $sub_member_id = $this->params[ 'sub_member_id' ] ?? 0;
- $condition = [];
-
- if (!empty($fenxiao_id)) {
- $sub_fenxiao_info = $model->getFenxiaoInfo([ [ 'fenxiao_id', '=', $fenxiao_id ] ], 'fenxiao_id,member_id')[ 'data' ];
- if (empty($sub_fenxiao_info)) return $this->response($this->error('', 'MEMBER_NOT_IS_FENXIAO'));
-
- $condition = [
- [ '', 'exp', Db::raw("( (fo.one_fenxiao_id = {$fenxiao_info['fenxiao_id']} AND fo.two_fenxiao_id = {$fenxiao_id}) OR (fo.two_fenxiao_id = {$fenxiao_info['fenxiao_id']} AND fo.three_fenxiao_id = {$fenxiao_id})) OR fo.member_id = {$sub_fenxiao_info['member_id']}") ]
- ];
- } elseif (!empty($sub_member_id)) {
- $is_sub_member = model('member')->getCount([ [ 'member_id', '=', $sub_member_id ], [ 'fenxiao_id', '=', $fenxiao_info[ 'fenxiao_id' ] ] ]);
- if (!$is_sub_member) return $this->response($this->error('', 'NOT_EXIST_FENXIAO_RELATION'));
-
- $condition = [
- [ 'fo.one_fenxiao_id', '=', $fenxiao_info[ 'fenxiao_id' ] ],
- [ 'fo.member_id', '=', $sub_member_id ]
- ];
- }
-
- $order_model = new FenxiaoOrderModel();
- $list = $order_model->getFenxiaoOrderPageList($condition, $page, $page_size, 'fo.fenxiao_order_id desc');
- if (!empty($list[ 'data' ][ 'list' ])) {
- foreach ($list[ 'data' ][ 'list' ] as $k => $item) {
- if ($item[ 'one_fenxiao_id' ] == $fenxiao_info[ 'fenxiao_id' ]) {
- $list[ 'data' ][ 'list' ][ $k ][ 'commission' ] = $item[ 'one_commission' ];
- $list[ 'data' ][ 'list' ][ $k ][ 'commission_level' ] = 1;
- } elseif ($item[ 'two_fenxiao_id' ] == $fenxiao_info[ 'fenxiao_id' ]) {
- $list[ 'data' ][ 'list' ][ $k ][ 'commission' ] = $item[ 'two_commission' ];
- $list[ 'data' ][ 'list' ][ $k ][ 'commission_level' ] = 2;
- } elseif ($item[ 'three_fenxiao_id' ] == $fenxiao_info[ 'fenxiao_id' ]) {
- $list[ 'data' ][ 'list' ][ $k ][ 'commission' ] = $item[ 'three_commission' ];
- $list[ 'data' ][ 'list' ][ $k ][ 'commission_level' ] = 3;
- }
- $list[ 'data' ][ 'list' ][ $k ] = array_diff_key($list[ 'data' ][ 'list' ][ $k ], [ 'one_fenxiao_id' => '', 'one_rate' => '', 'one_commission' => '', 'one_fenxiao_name' => '', 'two_fenxiao_id' => '', 'two_rate' => '', 'two_commission' => '', 'two_fenxiao_name' => '', 'three_fenxiao_id' => '', 'three_rate' => '', 'three_commission' => '', 'three_fenxiao_name' => '' ]);
- }
- }
- return $this->response($list);
- }
-
- /**
- * 排行榜
- */
- public function rankingList()
- {
- $token = $this->checkToken();
- if ($token[ 'code' ] < 0) return $this->response($token);
-
- $type = $this->params[ 'type' ] ?? 'profit'; // 排行榜 profit:按受益 invited_num:按邀请人数
- $page = $this->params[ 'page' ] ?? 1;
- $page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
-
- $model = new FenxiaoModel();
-
- $condition = [
- [ 'f.site_id', '=', $this->site_id ],
- [ 'f.is_delete', '=', 0 ]
- ];
-
- $order = $type == 'profit' ? 'f.total_commission desc' : Db::raw('(f.one_child_num) desc');
- $field = 'f.total_commission, (f.one_child_num) as child_num, m.nickname,m.headimg';
-
- $data = $model->getFenxiaoPageLists($condition, $page, $page_size, $order, $field, 'f', [ [ 'member m', 'm.member_id = f.member_id', 'inner' ] ]);
-
- return $this->response($data);
- }
-
- /**
- * 获取排名
- * @return false|string
- */
- public function ranking()
- {
- $token = $this->checkToken();
- if ($token[ 'code' ] < 0) return $this->response($token);
-
- $type = $this->params[ 'type' ] ?? 'invited_num'; // 排行榜 profit:按受益 invited_num:按邀请人数
-
- $model = new FenxiaoModel();
- $fenxiao_info = $model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id')[ 'data' ];
- if (empty($fenxiao_info)) return $this->response($this->error('', 'MEMBER_NOT_IS_FENXIAO'));
-
- $order = $type == 'profit' ? 'total_commission' : '(one_child_num + one_child_fenxiao_num)';
-
- $data = $model->getFenxiaoRanking($this->site_id, $fenxiao_info[ 'fenxiao_id' ], $order);
- return $this->response($data);
- }
-
- /**
- * 子级分销商
- */
- public function childFenxiao()
- {
- $token = $this->checkToken();
- if ($token[ 'code' ] < 0) return $this->response($token);
-
- $page = $this->params[ 'page' ] ?? 1;
- $page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
-
- $model = new FenxiaoModel();
- $fenxiao_info = $model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id')[ 'data' ];
- if (empty($fenxiao_info)) return $this->response($this->error('', 'MEMBER_NOT_IS_FENXIAO'));
-
- $parent_fenxiao_id = [ $fenxiao_info[ 'fenxiao_id' ] ]; // 上级分销商id集合
-
- // 查询分销基础配置
- $config_model = new Config();
- $fenxiao_basic_config = $config_model->getFenxiaoBasicsConfig($this->site_id)[ 'data' ][ 'value' ];
- $level = $fenxiao_basic_config[ 'level' ];
-
- if ($level == 2) {
-
- // 二级分销商id集合
- $one_level_fenxiao = model('fenxiao')->getColumn([ [ 'parent', '=', $fenxiao_info[ 'fenxiao_id' ] ] ], 'fenxiao_id');
- if (!empty($one_level_fenxiao)) {
- $parent_fenxiao_id = array_merge($parent_fenxiao_id, $one_level_fenxiao);
- }
- }
-
- $condition = [
- [ 'f.site_id', '=', $this->site_id ],
- [ 'f.parent', 'in', $parent_fenxiao_id ],
- [ 'm.is_delete', '=', 0 ]
- ];
- $field = 'm.nickname,m.headimg,m.member_id,m.order_num,m.order_money,f.fenxiao_id,f.audit_time,f.level_name,m.is_fenxiao,m.bind_fenxiao_time,f.one_child_num,f.one_child_fenxiao_num';
- $join = [ [ 'member m', 'm.member_id = f.member_id', 'inner' ] ];
-
- $res = $model->getFenxiaoPageLists($condition, $page, $page_size, 'f.audit_time desc', $field, 'f', $join);
- return $this->response($res);
- }
+checkToken();
+ if ($token[ 'code' ] < 0) return $this->response($token);
+
+ $condition = [
+ [ 'f.member_id', '=', $this->member_id ]
+ ];
+
+ $model = new FenxiaoModel();
+ $info = $model->getFenxiaoDetailInfo($condition);
+ if (empty($info[ 'data' ])) {
+ $res = $model->autoBecomeFenxiao($this->member_id, $this->site_id);
+ if (isset($res[ 'code' ]) && $res[ 'code' ] >= 0) {
+ $info = $model->getFenxiaoDetailInfo($condition);
+ }
+ } else {
+ $member = new Member();
+ //$info[ 'data' ][ 'one_child_num' ] = $member->getMemberCount([ [ 'fenxiao_id', '=', $info[ 'data' ][ 'fenxiao_id' ] ], [ 'is_fenxiao', '=', 0 ] ])[ 'data' ];
+
+ $condition_result = $model->geFenxiaoNextLevel($this->member_id, $this->site_id);
+ $info[ 'data' ][ 'condition' ] = $condition_result[ 'data' ];
+ }
+
+ if (!empty($info[ 'data' ])) {
+ $fenxiao_order_model = new FenxiaoOrderModel();
+
+ // 今日收入
+ $compare_today = Carbon::today()->timestamp;
+ $compare_tomorrow = Carbon::tomorrow()->timestamp;
+
+ $commission = 0;
+ $one_commission = $fenxiao_order_model->getFenxiaoOrderInfo([ [ 'one_fenxiao_id', '=', $info[ 'data' ][ 'fenxiao_id' ] ], [ 'create_time', 'between', [ $compare_today, $compare_tomorrow ] ], [ 'is_settlement', '=', 1 ] ], 'sum(one_commission) as commission');
+ $two_commission = $fenxiao_order_model->getFenxiaoOrderInfo([ [ 'two_fenxiao_id', '=', $info[ 'data' ][ 'fenxiao_id' ] ], [ 'create_time', 'between', [ $compare_today, $compare_tomorrow ] ], [ 'is_settlement', '=', 1 ] ], 'sum(two_commission) as commission');
+ $three_commission = $fenxiao_order_model->getFenxiaoOrderInfo([ [ 'three_fenxiao_id', '=', $info[ 'data' ][ 'fenxiao_id' ] ], [ 'create_time', 'between', [ $compare_today, $compare_tomorrow ] ], [ 'is_settlement', '=', 1 ] ], 'sum(three_commission) as commission');
+
+ if (!empty($one_commission[ 'data' ][ 'commission' ])) $commission += $one_commission[ 'data' ][ 'commission' ];
+ if (!empty($two_commission[ 'data' ][ 'commission' ])) $commission += $two_commission[ 'data' ][ 'commission' ];
+ if (!empty($three_commission[ 'data' ][ 'commission' ])) $commission += $three_commission[ 'data' ][ 'commission' ];
+
+ $info[ 'data' ][ 'today_commission' ] = $commission;
+
+ // 总销售额
+ $fenxiao_order_info = $fenxiao_order_model->getFenxiaoOrderInfoNew([ [ 'fo.one_fenxiao_id|fo.two_fenxiao_id|fo.three_fenxiao_id', '=', $info[ 'data' ][ 'fenxiao_id' ] ], ['', 'exp', Db::raw('fo.is_refund=0 or (o.order_status=10 and fo.is_refund=1) ') ] ], 'sum(fo.real_goods_money) as real_goods_money');
+
+ $fenxiao_order_info = $fenxiao_order_info[ 'data' ];
+ if (empty($fenxiao_order_info[ 'real_goods_money' ])) {
+ $fenxiao_order_info[ 'real_goods_money' ] = 0;
+ }
+ $info[ 'data' ][ 'today_order_money' ] = $fenxiao_order_info[ 'real_goods_money' ];
+
+ $info[ 'data' ][ 'in_progress_money' ] = 0;
+ $one_in_progress_commission = $fenxiao_order_model->getFenxiaoOrderInfo([ [ 'one_fenxiao_id', '=', $info[ 'data' ][ 'fenxiao_id' ] ], [ 'is_settlement', '=', 0 ], [ 'is_refund', '=', 0 ] ], 'sum(one_commission) as commission');
+ $two_in_progress_commission = $fenxiao_order_model->getFenxiaoOrderInfo([ [ 'two_fenxiao_id', '=', $info[ 'data' ][ 'fenxiao_id' ] ], [ 'is_settlement', '=', 0 ], [ 'is_refund', '=', 0 ] ], 'sum(two_commission) as commission');
+ $three_in_progress_commission = $fenxiao_order_model->getFenxiaoOrderInfo([ [ 'three_fenxiao_id', '=', $info[ 'data' ][ 'fenxiao_id' ] ], [ 'is_settlement', '=', 0 ], [ 'is_refund', '=', 0 ] ], 'sum(three_commission) as commission');
+
+ if (!empty($one_in_progress_commission[ 'data' ][ 'commission' ])) $info[ 'data' ][ 'in_progress_money' ] += $one_in_progress_commission[ 'data' ][ 'commission' ];
+ if (!empty($two_in_progress_commission[ 'data' ][ 'commission' ])) $info[ 'data' ][ 'in_progress_money' ] += $two_in_progress_commission[ 'data' ][ 'commission' ];
+ if (!empty($three_in_progress_commission[ 'data' ][ 'commission' ])) $info[ 'data' ][ 'in_progress_money' ] += $three_in_progress_commission[ 'data' ][ 'commission' ];
+ }
+ return $this->response($info);
+ }
+
+ /**
+ * 获取推荐人分销商信息
+ */
+ public function sourceInfo()
+ {
+ $token = $this->checkToken();
+ if ($token[ 'code' ] < 0) return $this->response($token);
+
+ $member = new Member();
+ $member_info = $member->getMemberInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id');
+ $fenxiao_id = $member_info[ 'data' ][ 'fenxiao_id' ] ?? 0;
+
+ if (empty($fenxiao_id)) {
+ return $this->response($this->error('', 'REQUEST_SOURCE_MEMBER'));
+ }
+ $condition = [
+ [ 'fenxiao_id', '=', $fenxiao_id ]
+ ];
+
+ $model = new FenxiaoModel();
+ $info = $model->getFenxiaoInfo($condition, 'fenxiao_name');
+
+ return $this->response($info);
+ }
+
+ /**
+ * 获取模板id
+ * @return false|string
+ */
+ public function posterTemplateIds()
+ {
+ $token = $this->checkToken();
+ if ($token[ 'code' ] < 0) return $this->response($token);
+
+ $condition = [
+ [ 'site_id', '=', $this->site_id ],
+ [ 'template_type', '=', 'fenxiao' ],
+ [ 'template_status', '=', 1 ],
+ ];
+ $condition[] = [ 'template_type', '=', 'fenxiao' ];
+ $poster_template_model = new PosterTemplateModel();
+ $list = $poster_template_model->getPosterTemplateList($condition, 'template_id', 'template_id asc')[ 'data' ];
+ $id_arr = array_column($list, 'template_id');
+ if (empty($id_arr)) $id_arr = [ 'default' ];
+
+ return $this->response($this->success($id_arr));
+ }
+
+ /**
+ * 分销海报
+ * @return \app\api\controller\false|string
+ */
+ public function poster()
+ {
+ $token = $this->checkToken();
+ if ($token[ 'code' ] < 0) return $this->response($token);
+
+ $qrcode_param = $this->params['qrcode_param'] ?? '';//二维码
+
+ if (empty($qrcode_param)) {
+ return $this->response($this->error('', 'REQUEST_QRCODE_PARAM'));
+ }
+
+ $qrcode_param = json_decode($qrcode_param, true);
+ $qrcode_param[ 'source_member' ] = $this->member_id;
+
+ $poster = new Poster();
+ $param = $this->params;
+ $param[ 'qrcode_param' ] = $qrcode_param;
+ $res = $poster->getFenxiaoPoster($param);
+
+ return $this->response($res);
+ }
+
+ /**
+ * 分销海报
+ * @return \app\api\controller\false|string
+ */
+ public function posterList()
+ {
+ $token = $this->checkToken();
+ if ($token[ 'code' ] < 0) return $this->response($token);
+
+ $condition = [
+ [ 'site_id', '=', $this->site_id ],
+ [ 'template_type', '=', 'fenxiao' ],
+ [ 'template_status', '=', 1 ],
+ ];
+ $condition[] = [ 'template_type', '=', 'fenxiao' ];
+ $poster_template_model = new PosterTemplateModel();
+ $list = $poster_template_model->getPosterTemplateList($condition, 'template_id', 'template_id asc')[ 'data' ];
+ $id_arr = array_column($list, 'template_id');
+ $id_arr = $id_arr ?: ['default'];
+ $qrcode_param = $this->params['qrcode_param'] ?? '';//二维码
+ $qrcode_param = [json_decode($qrcode_param, true)];
+ $qrcode_param[ 'source_member' ] = $this->member_id;
+ $poster = new Poster();
+ $param = $this->params;
+ $param[ 'qrcode_param' ] = $qrcode_param;
+ $path = [];
+ foreach ($id_arr as $k => $v){
+ $param['template_id'] = $v;
+ $res = $poster->getFenxiaoPoster($param)['data']['path'] ?? '';
+ if($res) $path[] = $res;
+ }
+ return $this->response($this->success($path));
+ }
+
+ /**
+ * 分销商等级信息
+ */
+ public function level()
+ {
+ $token = $this->checkToken();
+ if ($token[ 'code' ] < 0) return $this->response($token);
+
+ $level = $this->params[ 'level' ] ?? 0;
+
+ $condition = [
+ [ 'level_id', '=', $level ]
+ ];
+ $model = new FenxiaoLevel();
+ $info = $model->getLevelInfo($condition);
+
+ return $this->response($info);
+ }
+
+ /**
+ * 分销商我的团队
+ */
+ public function team()
+ {
+ $token = $this->checkToken();
+ if ($token[ 'code' ] < 0) return $this->response($token);
+
+ $page = $this->params[ 'page' ] ?? 1;
+ $page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
+ $level = $this->params[ 'level' ] ?? 1;
+ $is_pay = $this->params[ 'is_pay' ] ?? 0;
+
+ $model = new FenxiaoModel();
+ $fenxiao_info = $model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id');
+ if (empty($fenxiao_info[ 'data' ])) return $this->response($this->error('', 'MEMBER_NOT_IS_FENXIAO'));
+
+ $list = $model->getFenxiaoTeam($level, $fenxiao_info[ 'data' ][ 'fenxiao_id' ], $page, $page_size, $is_pay);
+
+ return $this->response($list);
+ }
+
+ /**
+ * 查询我的团队的数量
+ */
+ public function teamNum()
+ {
+ $token = $this->checkToken();
+ if ($token[ 'code' ] < 0) return $this->response($token);
+
+ $model = new FenxiaoModel();
+ $fenxiao_info = $model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id');
+ if (empty($fenxiao_info[ 'data' ])) return $this->response($this->error('', 'MEMBER_NOT_IS_FENXIAO'));
+
+ $data = $model->getFenxiaoTeamNum($fenxiao_info[ 'data' ][ 'fenxiao_id' ], $this->site_id);
+ return $this->response($data);
+ }
+
+ /**
+ * 获取下级分销商订单
+ * @return false|string
+ */
+ public function getOrder()
+ {
+ $token = $this->checkToken();
+ if ($token[ 'code' ] < 0) return $this->response($token);
+
+ $model = new FenxiaoModel();
+ $fenxiao_info = $model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id');
+ if (empty($fenxiao_info[ 'data' ])) return $this->response($this->error('', 'MEMBER_NOT_IS_FENXIAO'));
+ $fenxiao_info = $fenxiao_info[ 'data' ];
+
+ $page = $this->params[ 'page' ] ?? 1;
+ $page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
+ $fenxiao_id = $this->params[ 'fenxiao_id' ] ?? 0;
+ $sub_member_id = $this->params[ 'sub_member_id' ] ?? 0;
+ $condition = [];
+
+ if (!empty($fenxiao_id)) {
+ $sub_fenxiao_info = $model->getFenxiaoInfo([ [ 'fenxiao_id', '=', $fenxiao_id ] ], 'fenxiao_id,member_id')[ 'data' ];
+ if (empty($sub_fenxiao_info)) return $this->response($this->error('', 'MEMBER_NOT_IS_FENXIAO'));
+
+ $condition = [
+ [ '', 'exp', Db::raw("( (fo.one_fenxiao_id = {$fenxiao_info['fenxiao_id']} AND fo.two_fenxiao_id = {$fenxiao_id}) OR (fo.two_fenxiao_id = {$fenxiao_info['fenxiao_id']} AND fo.three_fenxiao_id = {$fenxiao_id})) OR fo.member_id = {$sub_fenxiao_info['member_id']}") ]
+ ];
+ } elseif (!empty($sub_member_id)) {
+ $is_sub_member = model('member')->getCount([ [ 'member_id', '=', $sub_member_id ], [ 'fenxiao_id', '=', $fenxiao_info[ 'fenxiao_id' ] ] ]);
+ if (!$is_sub_member) return $this->response($this->error('', 'NOT_EXIST_FENXIAO_RELATION'));
+
+ $condition = [
+ [ 'fo.one_fenxiao_id', '=', $fenxiao_info[ 'fenxiao_id' ] ],
+ [ 'fo.member_id', '=', $sub_member_id ]
+ ];
+ }
+
+ $order_model = new FenxiaoOrderModel();
+ $list = $order_model->getFenxiaoOrderPageList($condition, $page, $page_size, 'fo.fenxiao_order_id desc');
+ if (!empty($list[ 'data' ][ 'list' ])) {
+ foreach ($list[ 'data' ][ 'list' ] as $k => $item) {
+ if ($item[ 'one_fenxiao_id' ] == $fenxiao_info[ 'fenxiao_id' ]) {
+ $list[ 'data' ][ 'list' ][ $k ][ 'commission' ] = $item[ 'one_commission' ];
+ $list[ 'data' ][ 'list' ][ $k ][ 'commission_level' ] = 1;
+ } elseif ($item[ 'two_fenxiao_id' ] == $fenxiao_info[ 'fenxiao_id' ]) {
+ $list[ 'data' ][ 'list' ][ $k ][ 'commission' ] = $item[ 'two_commission' ];
+ $list[ 'data' ][ 'list' ][ $k ][ 'commission_level' ] = 2;
+ } elseif ($item[ 'three_fenxiao_id' ] == $fenxiao_info[ 'fenxiao_id' ]) {
+ $list[ 'data' ][ 'list' ][ $k ][ 'commission' ] = $item[ 'three_commission' ];
+ $list[ 'data' ][ 'list' ][ $k ][ 'commission_level' ] = 3;
+ }
+ $list[ 'data' ][ 'list' ][ $k ] = array_diff_key($list[ 'data' ][ 'list' ][ $k ], [ 'one_fenxiao_id' => '', 'one_rate' => '', 'one_commission' => '', 'one_fenxiao_name' => '', 'two_fenxiao_id' => '', 'two_rate' => '', 'two_commission' => '', 'two_fenxiao_name' => '', 'three_fenxiao_id' => '', 'three_rate' => '', 'three_commission' => '', 'three_fenxiao_name' => '' ]);
+ }
+ }
+ return $this->response($list);
+ }
+
+ /**
+ * 排行榜
+ */
+ public function rankingList()
+ {
+ $token = $this->checkToken();
+ if ($token[ 'code' ] < 0) return $this->response($token);
+
+ $type = $this->params[ 'type' ] ?? 'profit'; // 排行榜 profit:按受益 invited_num:按邀请人数
+ $page = $this->params[ 'page' ] ?? 1;
+ $page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
+
+ $model = new FenxiaoModel();
+
+ $condition = [
+ [ 'f.site_id', '=', $this->site_id ],
+ [ 'f.is_delete', '=', 0 ]
+ ];
+
+ $order = $type == 'profit' ? 'f.total_commission desc' : Db::raw('(f.one_child_num) desc');
+ $field = 'f.total_commission, (f.one_child_num) as child_num, m.nickname,m.headimg';
+
+ $data = $model->getFenxiaoPageLists($condition, $page, $page_size, $order, $field, 'f', [ [ 'member m', 'm.member_id = f.member_id', 'inner' ] ]);
+
+ return $this->response($data);
+ }
+
+ /**
+ * 获取排名
+ * @return false|string
+ */
+ public function ranking()
+ {
+ $token = $this->checkToken();
+ if ($token[ 'code' ] < 0) return $this->response($token);
+
+ $type = $this->params[ 'type' ] ?? 'invited_num'; // 排行榜 profit:按受益 invited_num:按邀请人数
+
+ $model = new FenxiaoModel();
+ $fenxiao_info = $model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id')[ 'data' ];
+ if (empty($fenxiao_info)) return $this->response($this->error('', 'MEMBER_NOT_IS_FENXIAO'));
+
+ $order = $type == 'profit' ? 'total_commission' : '(one_child_num + one_child_fenxiao_num)';
+
+ $data = $model->getFenxiaoRanking($this->site_id, $fenxiao_info[ 'fenxiao_id' ], $order);
+ return $this->response($data);
+ }
+
+ /**
+ * 子级分销商
+ */
+ public function childFenxiao()
+ {
+ $token = $this->checkToken();
+ if ($token[ 'code' ] < 0) return $this->response($token);
+
+ $page = $this->params[ 'page' ] ?? 1;
+ $page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
+
+ $model = new FenxiaoModel();
+ $fenxiao_info = $model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id')[ 'data' ];
+ if (empty($fenxiao_info)) return $this->response($this->error('', 'MEMBER_NOT_IS_FENXIAO'));
+
+ $parent_fenxiao_id = [ $fenxiao_info[ 'fenxiao_id' ] ]; // 上级分销商id集合
+
+ // 查询分销基础配置
+ $config_model = new Config();
+ $fenxiao_basic_config = $config_model->getFenxiaoBasicsConfig($this->site_id)[ 'data' ][ 'value' ];
+ $level = $fenxiao_basic_config[ 'level' ];
+
+ if ($level == 2) {
+
+ // 二级分销商id集合
+ $one_level_fenxiao = model('fenxiao')->getColumn([ [ 'parent', '=', $fenxiao_info[ 'fenxiao_id' ] ] ], 'fenxiao_id');
+ if (!empty($one_level_fenxiao)) {
+ $parent_fenxiao_id = array_merge($parent_fenxiao_id, $one_level_fenxiao);
+ }
+ }
+
+ $condition = [
+ [ 'f.site_id', '=', $this->site_id ],
+ [ 'f.parent', 'in', $parent_fenxiao_id ],
+ [ 'm.is_delete', '=', 0 ]
+ ];
+ $field = 'm.nickname,m.headimg,m.member_id,m.order_num,m.order_money,f.fenxiao_id,f.audit_time,f.level_name,m.is_fenxiao,m.bind_fenxiao_time,f.one_child_num,f.one_child_fenxiao_num';
+ $join = [ [ 'member m', 'm.member_id = f.member_id', 'inner' ] ];
+
+ $res = $model->getFenxiaoPageLists($condition, $page, $page_size, 'f.audit_time desc', $field, 'f', $join);
+ return $this->response($res);
+ }
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/api/controller/Goods.php b/src/addon/fenxiao/api/controller/Goods.php
index cc19e429e..da8f96e77 100644
--- a/src/addon/fenxiao/api/controller/Goods.php
+++ b/src/addon/fenxiao/api/controller/Goods.php
@@ -1,170 +1,162 @@
-checkToken();
- if ($token[ 'code' ] < 0) return $this->response($token);
-
- $sku_id = $this->params['sku_id'] ?? 0;
- if (!empty($id)) {
- $sku_id = $id;
- }
- if (empty($sku_id)) {
- return $this->response($this->error('', 'REQUEST_SKU_ID'));
- }
-
- $config = new ConfigModel();
-
- $words_config = $config->getFenxiaoWordsConfig($this->site_id)[ 'data' ][ 'value' ];
-
- $data = [
- 'words_account' => $words_config[ 'account' ],
- 'commission_money' => 0.00
- ];
-
- $fenxiao_model = new FenxiaoModel();
- $fenxiao_info = $fenxiao_model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id,level_id')[ 'data' ];
- if (empty($fenxiao_info)) return $this->response($this->error());
-
- $fenxiao_goods_sku_model = new FenxiaoGoodsSkuModel();
- $data[ 'commission_money' ] = $fenxiao_goods_sku_model->getSkuFenxiaoCommission($sku_id, $fenxiao_info[ 'level_id' ])[ 'data' ];
-
- $basics = $config->getFenxiaoBasicsConfig($this->site_id);
- $data[ 'is_commission_money' ] = $basics[ 'data' ][ 'value' ][ 'is_commission_money' ];
- return $this->response($this->success($data));
- }
-
- /**
- * 分销商品分页列表
- */
- public function page()
- {
- $token = $this->checkToken();
- if ($token[ 'code' ] < 0) return $this->response($token);
-
- $page = $this->params['page'] ?? 1;
- $page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
- $keyword = $this->params['keyword'] ?? '';//关键词
- $category_id = $this->params['category_id'] ?? 0;//分类
- $min_price = $this->params['min_price'] ?? 0;//价格区间,小
- $max_price = $this->params['max_price'] ?? 0;//价格区间,大
- $is_free_shipping = $this->params['is_free_shipping'] ?? 0;//是否免邮
- $order = $this->params['order'] ?? 'create_time';//排序(综合、销量、价格)
- $sort = $this->params['sort'] ?? 'desc';//升序、降序
- $goods_id_arr = $this->params['goods_id_arr'] ?? '';//goods_id数组
-
- $condition = [
- [ 'g.is_fenxiao', '=', 1 ],
- [ 'g.goods_state', '=', 1 ],
- [ 'g.is_delete', '=', 0 ],
- [ 'g.site_id', '=', $this->site_id ]
- ];
-
- if (!empty($keyword)) {
- $condition[] = [ 'g.goods_name|g.keywords', 'like', '%' . $keyword . '%' ];
- }
-
- if (!empty($category_id)) {
- $condition[] = [ 'g.category_id', 'like', '%,' . $category_id . ',%' ];
- }
-
- if (!empty($goods_id_arr)) {
- $condition[] = [ 'g.goods_id', 'in', $goods_id_arr ];
- }
-
- if ($min_price != '' && $max_price != '') {
- $condition[] = [ 'g.discount_price', 'between', [ $min_price, $max_price ] ];
- } elseif ($min_price != '') {
- $condition[] = [ 'g.discount_price', '>=', $min_price ];
- } elseif ($max_price != '') {
- $condition[] = [ 'g.discount_price', '<=', $max_price ];
- }
-
- if (!empty($is_free_shipping)) {
- $condition[] = [ 'g.is_free_shipping', '=', $is_free_shipping ];
- }
-
- // 非法参数进行过滤
- if ($sort != 'desc' && $sort != 'asc') {
- $sort = '';
- }
-
- // 非法参数进行过滤
- if ($order != '') {
- if ($order != 'sale_num' && $order != 'discount_price') {
- $order = 'gs.create_time';
- } elseif ($order != 'sale_num') {
- $order = 'gs.' . $order;
- } else {
- $order = 'sale_sort';
- }
- $order_by = $order . ' ' . $sort;
- } else {
- $order_by = 'g.sort desc,g.create_time desc';
- }
-
- $fenxiao_model = new FenxiaoModel();
- $fenxiao_info = $fenxiao_model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id,level_id')[ 'data' ];
-
-// $fenxiao_level = new FenxiaoLevel();
-// $level_info = $fenxiao_level->getLevelInfo([ [ 'level_id', '=', $fenxiao_info[ 'level_id' ] ] ], 'one_rate')[ 'data' ];
-
- $fenxiao_goods_sku_model = new FenxiaoGoodsSkuModel();
- $list = $fenxiao_goods_sku_model->getFenxiaoGoodsSkuPageList($condition, $page, $page_size, $order_by);
-
- $fenxiao_goods_collect_model = new FenxiaoGoodsCollectModel();
-
- // 计算佣金
- foreach ($list[ 'data' ][ 'list' ] as $k => $v) {
- $collection_info = $fenxiao_goods_collect_model->getCollectInfo([
- [ 'member_id', '=', $this->member_id ],
- [ 'goods_id', '=', $v[ 'goods_id' ] ],
- [ 'fenxiao_id', '=', $fenxiao_info[ 'fenxiao_id' ] ],
- ], 'collect_id');
-
- // 查询是否关注该分销商品
- $collection_info = $collection_info[ 'data' ];
- if (!empty($collection_info)) {
- $list[ 'data' ][ 'list' ][ $k ][ 'is_collect' ] = 1;
- $list[ 'data' ][ 'list' ][ $k ][ 'collect_id' ] = $collection_info[ 'collect_id' ];
- } else {
- $list[ 'data' ][ 'list' ][ $k ][ 'is_collect' ] = 0;
- }
-
- $sku_commission_info = $fenxiao_goods_sku_model->getSkuFenxiaoCommission($v[ 'sku_id' ], $fenxiao_info[ 'level_id' ]);
- $list[ 'data' ][ 'list' ][ $k ][ 'commission_money' ] = $sku_commission_info[ 'data' ];
- }
-
- return $this->response($list);
-
- }
-
+checkToken();
+ if ($token[ 'code' ] < 0) return $this->response($token);
+
+ $sku_id = $this->params['sku_id'] ?? 0;
+ if (!empty($id)) {
+ $sku_id = $id;
+ }
+ if (empty($sku_id)) {
+ return $this->response($this->error('', 'REQUEST_SKU_ID'));
+ }
+
+ $config = new ConfigModel();
+
+ $words_config = $config->getFenxiaoWordsConfig($this->site_id)[ 'data' ][ 'value' ];
+
+ $data = [
+ 'words_account' => $words_config[ 'account' ],
+ 'commission_money' => 0.00
+ ];
+
+ $fenxiao_model = new FenxiaoModel();
+ $fenxiao_info = $fenxiao_model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id,level_id')[ 'data' ];
+ if (empty($fenxiao_info)) return $this->response($this->error());
+
+ $fenxiao_goods_sku_model = new FenxiaoGoodsSkuModel();
+ $data[ 'commission_money' ] = $fenxiao_goods_sku_model->getSkuFenxiaoCommission($sku_id, $fenxiao_info[ 'level_id' ])[ 'data' ];
+
+ $basics = $config->getFenxiaoBasicsConfig($this->site_id);
+ $data[ 'is_commission_money' ] = $basics[ 'data' ][ 'value' ][ 'is_commission_money' ];
+ return $this->response($this->success($data));
+ }
+
+ /**
+ * 分销商品分页列表
+ */
+ public function page()
+ {
+ $token = $this->checkToken();
+ if ($token[ 'code' ] < 0) return $this->response($token);
+
+ $page = $this->params['page'] ?? 1;
+ $page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
+ $keyword = $this->params['keyword'] ?? '';//关键词
+ $category_id = $this->params['category_id'] ?? 0;//分类
+ $min_price = $this->params['min_price'] ?? 0;//价格区间,小
+ $max_price = $this->params['max_price'] ?? 0;//价格区间,大
+ $is_free_shipping = $this->params['is_free_shipping'] ?? 0;//是否免邮
+ $order = $this->params['order'] ?? 'create_time';//排序(综合、销量、价格)
+ $sort = $this->params['sort'] ?? 'desc';//升序、降序
+ $goods_id_arr = $this->params['goods_id_arr'] ?? '';//goods_id数组
+
+ $condition = [
+ [ 'g.is_fenxiao', '=', 1 ],
+ [ 'g.goods_state', '=', 1 ],
+ [ 'g.is_delete', '=', 0 ],
+ [ 'g.site_id', '=', $this->site_id ]
+ ];
+
+ if (!empty($keyword)) {
+ $condition[] = [ 'g.goods_name|g.keywords', 'like', '%' . $keyword . '%' ];
+ }
+
+ if (!empty($category_id)) {
+ $condition[] = [ 'g.category_id', 'like', '%,' . $category_id . ',%' ];
+ }
+
+ if (!empty($goods_id_arr)) {
+ $condition[] = [ 'g.goods_id', 'in', $goods_id_arr ];
+ }
+
+ if ($min_price != '' && $max_price != '') {
+ $condition[] = [ 'g.discount_price', 'between', [ $min_price, $max_price ] ];
+ } elseif ($min_price != '') {
+ $condition[] = [ 'g.discount_price', '>=', $min_price ];
+ } elseif ($max_price != '') {
+ $condition[] = [ 'g.discount_price', '<=', $max_price ];
+ }
+
+ if (!empty($is_free_shipping)) {
+ $condition[] = [ 'g.is_free_shipping', '=', $is_free_shipping ];
+ }
+
+ // 非法参数进行过滤
+ if ($sort != 'desc' && $sort != 'asc') {
+ $sort = '';
+ }
+
+ // 非法参数进行过滤
+ if ($order != '') {
+ if ($order != 'sale_num' && $order != 'discount_price') {
+ $order = 'gs.create_time';
+ } elseif ($order != 'sale_num') {
+ $order = 'gs.' . $order;
+ } else {
+ $order = 'sale_sort';
+ }
+ $order_by = $order . ' ' . $sort;
+ } else {
+ $order_by = 'g.sort desc,g.create_time desc';
+ }
+
+ $fenxiao_model = new FenxiaoModel();
+ $fenxiao_info = $fenxiao_model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id,level_id')[ 'data' ];
+
+// $fenxiao_level = new FenxiaoLevel();
+// $level_info = $fenxiao_level->getLevelInfo([ [ 'level_id', '=', $fenxiao_info[ 'level_id' ] ] ], 'one_rate')[ 'data' ];
+
+ $fenxiao_goods_sku_model = new FenxiaoGoodsSkuModel();
+ $list = $fenxiao_goods_sku_model->getFenxiaoGoodsSkuPageList($condition, $page, $page_size, $order_by);
+
+ $fenxiao_goods_collect_model = new FenxiaoGoodsCollectModel();
+
+ // 计算佣金
+ foreach ($list[ 'data' ][ 'list' ] as $k => $v) {
+ $collection_info = $fenxiao_goods_collect_model->getCollectInfo([
+ [ 'member_id', '=', $this->member_id ],
+ [ 'goods_id', '=', $v[ 'goods_id' ] ],
+ [ 'fenxiao_id', '=', $fenxiao_info[ 'fenxiao_id' ] ],
+ ], 'collect_id');
+
+ // 查询是否关注该分销商品
+ $collection_info = $collection_info[ 'data' ];
+ if (!empty($collection_info)) {
+ $list[ 'data' ][ 'list' ][ $k ][ 'is_collect' ] = 1;
+ $list[ 'data' ][ 'list' ][ $k ][ 'collect_id' ] = $collection_info[ 'collect_id' ];
+ } else {
+ $list[ 'data' ][ 'list' ][ $k ][ 'is_collect' ] = 0;
+ }
+
+ $sku_commission_info = $fenxiao_goods_sku_model->getSkuFenxiaoCommission($v[ 'sku_id' ], $fenxiao_info[ 'level_id' ]);
+ $list[ 'data' ][ 'list' ][ $k ][ 'commission_money' ] = $sku_commission_info[ 'data' ];
+ }
+
+ return $this->response($list);
+
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/api/controller/Goodscollect.php b/src/addon/fenxiao/api/controller/Goodscollect.php
index 12d10bf51..32bb1b371 100644
--- a/src/addon/fenxiao/api/controller/Goodscollect.php
+++ b/src/addon/fenxiao/api/controller/Goodscollect.php
@@ -1,138 +1,130 @@
-checkToken();
- if ($token[ 'code' ] < 0) return $this->response($token);
-
- $goods_id = $this->params['goods_id'] ?? 0;
- $sku_id = $this->params['sku_id'] ?? 0;
-
- if (empty($goods_id)) {
- return $this->response($this->error('', 'REQUEST_GOODS_ID'));
- }
-
- $fenxiao_model = new FenxiaoModel();
- $fenxiao_info = $fenxiao_model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id')[ 'data' ];
-
- $data = [
- 'member_id' => $this->member_id,
- 'fenxiao_id' => $fenxiao_info[ 'fenxiao_id' ],
- 'goods_id' => $goods_id,
- 'sku_id' => $sku_id,
- 'site_id' => $this->site_id
- ];
- $fenxiao_goods_sku_model = new FenxiaoGoodsCollectModel();
- $res = $fenxiao_goods_sku_model->addCollect($data);
- return $this->response($res);
- }
-
- /**
- * 删除分销商关注商品
- * @return false|string
- */
- public function delete()
- {
- $token = $this->checkToken();
- if ($token[ 'code' ] < 0) return $this->response($token);
-
- $collect_id = $this->params['collect_id'] ?? 0;
-
- if (empty($collect_id)) {
- return $this->response($this->error('', 'REQUEST_COLLECT_ID'));
- }
-
- $fenxiao_model = new FenxiaoModel();
- $fenxiao_info = $fenxiao_model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id')[ 'data' ];
- $condition = [
- [ 'fenxiao_id', '=', $fenxiao_info[ 'fenxiao_id' ] ],
- [ 'collect_id', '=', $collect_id ]
- ];
- $fenxiao_goods_sku_model = new FenxiaoGoodsCollectModel();
- $res = $fenxiao_goods_sku_model->deleteCollect($condition);
- return $this->response($res);
- }
-
- /**
- * 分销商关注商品分页列表
- */
- public function page()
- {
- $token = $this->checkToken();
- if ($token[ 'code' ] < 0) return $this->response($token);
-
- $page = $this->params['page'] ?? 1;
- $page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
-
- // 获取当前用户的分销等级
- $fenxiao_model = new FenxiaoModel();
- $fenxiao_info = $fenxiao_model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id,level_id')[ 'data' ];
-
- $fenxiao_level = new FenxiaoLevel();
- $level_info = $fenxiao_level->getLevelInfo([ [ 'level_id', '=', $fenxiao_info[ 'level_id' ] ] ], 'one_rate')[ 'data' ];
-
- $condition = [
- [ 'g.is_fenxiao', '=', 1 ],
- [ 'g.site_id', '=', $this->site_id ],
- [ 'gs.goods_state', '=', 1 ],
- [ 'gs.is_delete', '=', 0 ],
- [ 'fgc.member_id', '=', $this->member_id ]
- ];
-
- $fenxiao_goods_collect_model = new FenxiaoGoodsCollectModel();
- $list = $fenxiao_goods_collect_model->getCollectPageList($condition, $page, $page_size);
- $fenxiao_goods_sku_model = new FenxiaoGoodsSku();
-
- // 计算佣金比率
- foreach ($list[ 'data' ][ 'list' ] as $k => $v) {
- $discount_price = $v[ 'fenxiao_price' ] > 0 ? $v[ 'fenxiao_price' ] : $v[ 'discount_price' ];
-
- $money = 0;
- if ($v[ 'fenxiao_type' ] == 1) {
- // 默认规则
- $money = number_format($discount_price * $level_info[ 'one_rate' ] / 100, 2, '.', '');
- } else {
- // 自定义规则
- $fenxiao_goods_sku_info = $fenxiao_goods_sku_model->getFenxiaoGoodsSkuInfo([ [ 'sku_id', '=', $v[ 'sku_id' ] ], [ 'level_id', '=', $fenxiao_info[ 'level_id' ] ] ], 'one_money,one_rate');
- if (!empty($fenxiao_goods_sku_info[ 'data' ])) {
- $fenxiao_goods_sku_info = $fenxiao_goods_sku_info[ 'data' ];
- $money = $fenxiao_goods_sku_info[ 'one_money' ];
- if ($fenxiao_goods_sku_info[ 'one_rate' ] > 0) {
- $money = number_format($discount_price * $fenxiao_goods_sku_info[ 'one_rate' ] / 100, 2, '.', '');
- }
- }
- }
- $list[ 'data' ][ 'list' ][ $k ][ 'commission_money' ] = $money;
- }
-
- return $this->response($list);
-
- }
-
+checkToken();
+ if ($token[ 'code' ] < 0) return $this->response($token);
+
+ $goods_id = $this->params['goods_id'] ?? 0;
+ $sku_id = $this->params['sku_id'] ?? 0;
+
+ if (empty($goods_id)) {
+ return $this->response($this->error('', 'REQUEST_GOODS_ID'));
+ }
+
+ $fenxiao_model = new FenxiaoModel();
+ $fenxiao_info = $fenxiao_model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id')[ 'data' ];
+
+ $data = [
+ 'member_id' => $this->member_id,
+ 'fenxiao_id' => $fenxiao_info[ 'fenxiao_id' ],
+ 'goods_id' => $goods_id,
+ 'sku_id' => $sku_id,
+ 'site_id' => $this->site_id
+ ];
+ $fenxiao_goods_sku_model = new FenxiaoGoodsCollectModel();
+ $res = $fenxiao_goods_sku_model->addCollect($data);
+ return $this->response($res);
+ }
+
+ /**
+ * 删除分销商关注商品
+ * @return false|string
+ */
+ public function delete()
+ {
+ $token = $this->checkToken();
+ if ($token[ 'code' ] < 0) return $this->response($token);
+
+ $collect_id = $this->params['collect_id'] ?? 0;
+
+ if (empty($collect_id)) {
+ return $this->response($this->error('', 'REQUEST_COLLECT_ID'));
+ }
+
+ $fenxiao_model = new FenxiaoModel();
+ $fenxiao_info = $fenxiao_model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id')[ 'data' ];
+ $condition = [
+ [ 'fenxiao_id', '=', $fenxiao_info[ 'fenxiao_id' ] ],
+ [ 'collect_id', '=', $collect_id ]
+ ];
+ $fenxiao_goods_sku_model = new FenxiaoGoodsCollectModel();
+ $res = $fenxiao_goods_sku_model->deleteCollect($condition);
+ return $this->response($res);
+ }
+
+ /**
+ * 分销商关注商品分页列表
+ */
+ public function page()
+ {
+ $token = $this->checkToken();
+ if ($token[ 'code' ] < 0) return $this->response($token);
+
+ $page = $this->params['page'] ?? 1;
+ $page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
+
+ // 获取当前用户的分销等级
+ $fenxiao_model = new FenxiaoModel();
+ $fenxiao_info = $fenxiao_model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id,level_id')[ 'data' ];
+
+ $fenxiao_level = new FenxiaoLevel();
+ $level_info = $fenxiao_level->getLevelInfo([ [ 'level_id', '=', $fenxiao_info[ 'level_id' ] ] ], 'one_rate')[ 'data' ];
+
+ $condition = [
+ [ 'g.is_fenxiao', '=', 1 ],
+ [ 'g.site_id', '=', $this->site_id ],
+ [ 'gs.goods_state', '=', 1 ],
+ [ 'gs.is_delete', '=', 0 ],
+ [ 'fgc.member_id', '=', $this->member_id ]
+ ];
+
+ $fenxiao_goods_collect_model = new FenxiaoGoodsCollectModel();
+ $list = $fenxiao_goods_collect_model->getCollectPageList($condition, $page, $page_size);
+ $fenxiao_goods_sku_model = new FenxiaoGoodsSku();
+
+ // 计算佣金比率
+ foreach ($list[ 'data' ][ 'list' ] as $k => $v) {
+ $discount_price = $v[ 'fenxiao_price' ] > 0 ? $v[ 'fenxiao_price' ] : $v[ 'discount_price' ];
+
+ $money = 0;
+ if ($v[ 'fenxiao_type' ] == 1) {
+ // 默认规则
+ $money = number_format($discount_price * $level_info[ 'one_rate' ] / 100, 2, '.', '');
+ } else {
+ // 自定义规则
+ $fenxiao_goods_sku_info = $fenxiao_goods_sku_model->getFenxiaoGoodsSkuInfo([ [ 'sku_id', '=', $v[ 'sku_id' ] ], [ 'level_id', '=', $fenxiao_info[ 'level_id' ] ] ], 'one_money,one_rate');
+ if (!empty($fenxiao_goods_sku_info[ 'data' ])) {
+ $fenxiao_goods_sku_info = $fenxiao_goods_sku_info[ 'data' ];
+ $money = $fenxiao_goods_sku_info[ 'one_money' ];
+ if ($fenxiao_goods_sku_info[ 'one_rate' ] > 0) {
+ $money = number_format($discount_price * $fenxiao_goods_sku_info[ 'one_rate' ] / 100, 2, '.', '');
+ }
+ }
+ }
+ $list[ 'data' ][ 'list' ][ $k ][ 'commission_money' ] = $money;
+ }
+
+ return $this->response($list);
+
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/api/controller/Level.php b/src/addon/fenxiao/api/controller/Level.php
index 51344369e..cae5f71e1 100644
--- a/src/addon/fenxiao/api/controller/Level.php
+++ b/src/addon/fenxiao/api/controller/Level.php
@@ -1,42 +1,34 @@
-checkToken();
- if ($token[ 'code' ] < 0) return $this->response($token);
-
- $condition = [
- [ 'status', '=', 1 ],
- [ 'site_id', '=', $this->site_id ],
- [ 'is_default', '=', 0 ]
- ];
- $model = new FenxiaoLevel();
- $info = $model->getLevelList($condition, 'level_id,level_num,level_name,one_rate,two_rate,three_rate,upgrade_type,fenxiao_order_num,fenxiao_order_meney,one_fenxiao_order_num,one_fenxiao_order_money,order_num,order_money,child_num,child_fenxiao_num,one_child_num,one_child_fenxiao_num,one_fenxiao_total_order', 'level_num asc,one_rate asc');
-
- return $this->response($info);
- }
-
+checkToken();
+ if ($token[ 'code' ] < 0) return $this->response($token);
+
+ $condition = [
+ [ 'status', '=', 1 ],
+ [ 'site_id', '=', $this->site_id ],
+ [ 'is_default', '=', 0 ]
+ ];
+ $model = new FenxiaoLevel();
+ $info = $model->getLevelList($condition, 'level_id,level_num,level_name,one_rate,two_rate,three_rate,upgrade_type,fenxiao_order_num,fenxiao_order_meney,one_fenxiao_order_num,one_fenxiao_order_money,order_num,order_money,child_num,child_fenxiao_num,one_child_num,one_child_fenxiao_num,one_fenxiao_total_order', 'level_num asc,one_rate asc');
+
+ return $this->response($info);
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/api/controller/Order.php b/src/addon/fenxiao/api/controller/Order.php
index de7c8cc46..80046e270 100644
--- a/src/addon/fenxiao/api/controller/Order.php
+++ b/src/addon/fenxiao/api/controller/Order.php
@@ -1,114 +1,106 @@
-checkToken();
- if ($token[ 'code' ] < 0) return $this->response($token);
-
- $model = new Fenxiao();
- $fenxiao_info = $model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id');
- if (empty($fenxiao_info[ 'data' ])) return $this->response($this->error('', 'MEMBER_NOT_IS_FENXIAO'));
-
- $fenxiao_order_id = $this->params['fenxiao_order_id'] ?? 0;
- if (empty($fenxiao_order_id)) {
- return $this->response($this->error('', 'REQUEST_FENXIAO_ORDER_ID'));
- }
- $order_model = new FenxiaoOrderModel();
- $condition = [
- [ 'one_fenxiao_id|two_fenxiao_id|three_fenxiao_id', '=', $fenxiao_info[ 'data' ][ 'fenxiao_id' ] ],
- [ 'fenxiao_order_id', '=', $fenxiao_order_id ]
- ];
- $res = $order_model->getFenxiaoOrderInfo($condition);
- if (!empty($res[ 'data' ])) {
- if ($res[ 'data' ][ 'one_fenxiao_id' ] == $fenxiao_info[ 'data' ][ 'fenxiao_id' ]) {
- $res[ 'data' ][ 'commission' ] = $res[ 'data' ][ 'one_commission' ];
- $res[ 'data' ][ 'commission_rate' ] = $res[ 'data' ][ 'one_rate' ];
- $res[ 'data' ][ 'commission_level' ] = 1;
- } elseif ($res[ 'data' ][ 'two_fenxiao_id' ] == $fenxiao_info[ 'data' ][ 'fenxiao_id' ]) {
- $res[ 'data' ][ 'commission' ] = $res[ 'data' ][ 'two_commission' ];
- $res[ 'data' ][ 'commission_rate' ] = $res[ 'data' ][ 'two_rate' ];
- $res[ 'data' ][ 'commission_level' ] = 2;
- } elseif ($res[ 'data' ][ 'three_fenxiao_id' ] == $fenxiao_info[ 'data' ][ 'fenxiao_id' ]) {
- $res[ 'data' ][ 'commission' ] = $res[ 'data' ][ 'three_commission' ];
- $res[ 'data' ][ 'commission_rate' ] = $res[ 'data' ][ 'three_rate' ];
- $res[ 'data' ][ 'commission_level' ] = 3;
- }
- $res[ 'data' ] = array_diff_key($res[ 'data' ], [ 'member_id' => '', 'member_name' => '', 'member_mobile' => '', 'full_address' => '', 'one_fenxiao_id' => '', 'one_rate' => '', 'one_commission' => '', 'one_fenxiao_name' => '', 'two_fenxiao_id' => '', 'two_rate' => '', 'two_commission' => '', 'two_fenxiao_name' => '', 'three_fenxiao_id' => '', 'three_rate' => '', 'three_commission' => '', 'three_fenxiao_name' => '' ]);
- }
- return $this->response($res);
- }
-
- /**
- * 列表
- */
- public function page()
- {
- $token = $this->checkToken();
- if ($token[ 'code' ] < 0) return $this->response($token);
-
- $model = new Fenxiao();
- $fenxiao_info = $model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id');
- if (empty($fenxiao_info[ 'data' ])) return $this->response($this->error('', 'MEMBER_NOT_IS_FENXIAO'));
-
- $page = $this->params['page'] ?? 1;
- $page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
- $is_settlement = $this->params['is_settlement'] ?? 0;// 结算状态 0 全部 1 待结算 2 已结算 3 已退款
-
- $condition = [
- [ 'fo.one_fenxiao_id|fo.two_fenxiao_id|fo.three_fenxiao_id', '=', $fenxiao_info[ 'data' ][ 'fenxiao_id' ] ]
- ];
- if (!empty($is_settlement)) {
- if ($is_settlement == 3) {
- $condition[] = [ 'fo.is_refund', '=', 1 ];
- }
- if (in_array($is_settlement, [ 1, 2 ])) {
- $condition[] = [ 'fo.is_settlement', '=', $is_settlement - 1 ];
- $condition[] = [ 'fo.is_refund', '=', 0 ];
- }
- }
-
- $order_model = new FenxiaoOrderModel();
- $list = $order_model->getFenxiaoOrderPageList($condition, $page, $page_size, 'fo.fenxiao_order_id desc');
- if (!empty($list[ 'data' ][ 'list' ])) {
- foreach ($list[ 'data' ][ 'list' ] as $k => $item) {
- if ($item[ 'one_fenxiao_id' ] == $fenxiao_info[ 'data' ][ 'fenxiao_id' ]) {
- $list[ 'data' ][ 'list' ][ $k ][ 'commission' ] = $item[ 'one_commission' ];
- $list[ 'data' ][ 'list' ][ $k ][ 'commission_level' ] = 1;
- } elseif ($item[ 'two_fenxiao_id' ] == $fenxiao_info[ 'data' ][ 'fenxiao_id' ]) {
- $list[ 'data' ][ 'list' ][ $k ][ 'commission' ] = $item[ 'two_commission' ];
- $list[ 'data' ][ 'list' ][ $k ][ 'commission_level' ] = 2;
- } elseif ($item[ 'three_fenxiao_id' ] == $fenxiao_info[ 'data' ][ 'fenxiao_id' ]) {
- $list[ 'data' ][ 'list' ][ $k ][ 'commission' ] = $item[ 'three_commission' ];
- $list[ 'data' ][ 'list' ][ $k ][ 'commission_level' ] = 3;
- }
- $list[ 'data' ][ 'list' ][ $k ] = array_diff_key($list[ 'data' ][ 'list' ][ $k ], [ 'one_fenxiao_id' => '', 'one_rate' => '', 'one_commission' => '', 'one_fenxiao_name' => '', 'two_fenxiao_id' => '', 'two_rate' => '', 'two_commission' => '', 'two_fenxiao_name' => '', 'three_fenxiao_id' => '', 'three_rate' => '', 'three_commission' => '', 'three_fenxiao_name' => '' ]);
- }
- }
- return $this->response($list);
- }
-
+checkToken();
+ if ($token[ 'code' ] < 0) return $this->response($token);
+
+ $model = new Fenxiao();
+ $fenxiao_info = $model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id');
+ if (empty($fenxiao_info[ 'data' ])) return $this->response($this->error('', 'MEMBER_NOT_IS_FENXIAO'));
+
+ $fenxiao_order_id = $this->params['fenxiao_order_id'] ?? 0;
+ if (empty($fenxiao_order_id)) {
+ return $this->response($this->error('', 'REQUEST_FENXIAO_ORDER_ID'));
+ }
+ $order_model = new FenxiaoOrderModel();
+ $condition = [
+ [ 'one_fenxiao_id|two_fenxiao_id|three_fenxiao_id', '=', $fenxiao_info[ 'data' ][ 'fenxiao_id' ] ],
+ [ 'fenxiao_order_id', '=', $fenxiao_order_id ]
+ ];
+ $res = $order_model->getFenxiaoOrderInfo($condition);
+ if (!empty($res[ 'data' ])) {
+ if ($res[ 'data' ][ 'one_fenxiao_id' ] == $fenxiao_info[ 'data' ][ 'fenxiao_id' ]) {
+ $res[ 'data' ][ 'commission' ] = $res[ 'data' ][ 'one_commission' ];
+ $res[ 'data' ][ 'commission_rate' ] = $res[ 'data' ][ 'one_rate' ];
+ $res[ 'data' ][ 'commission_level' ] = 1;
+ } elseif ($res[ 'data' ][ 'two_fenxiao_id' ] == $fenxiao_info[ 'data' ][ 'fenxiao_id' ]) {
+ $res[ 'data' ][ 'commission' ] = $res[ 'data' ][ 'two_commission' ];
+ $res[ 'data' ][ 'commission_rate' ] = $res[ 'data' ][ 'two_rate' ];
+ $res[ 'data' ][ 'commission_level' ] = 2;
+ } elseif ($res[ 'data' ][ 'three_fenxiao_id' ] == $fenxiao_info[ 'data' ][ 'fenxiao_id' ]) {
+ $res[ 'data' ][ 'commission' ] = $res[ 'data' ][ 'three_commission' ];
+ $res[ 'data' ][ 'commission_rate' ] = $res[ 'data' ][ 'three_rate' ];
+ $res[ 'data' ][ 'commission_level' ] = 3;
+ }
+ $res[ 'data' ] = array_diff_key($res[ 'data' ], [ 'member_id' => '', 'member_name' => '', 'member_mobile' => '', 'full_address' => '', 'one_fenxiao_id' => '', 'one_rate' => '', 'one_commission' => '', 'one_fenxiao_name' => '', 'two_fenxiao_id' => '', 'two_rate' => '', 'two_commission' => '', 'two_fenxiao_name' => '', 'three_fenxiao_id' => '', 'three_rate' => '', 'three_commission' => '', 'three_fenxiao_name' => '' ]);
+ }
+ return $this->response($res);
+ }
+
+ /**
+ * 列表
+ */
+ public function page()
+ {
+ $token = $this->checkToken();
+ if ($token[ 'code' ] < 0) return $this->response($token);
+
+ $model = new Fenxiao();
+ $fenxiao_info = $model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id');
+ if (empty($fenxiao_info[ 'data' ])) return $this->response($this->error('', 'MEMBER_NOT_IS_FENXIAO'));
+
+ $page = $this->params['page'] ?? 1;
+ $page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
+ $is_settlement = $this->params['is_settlement'] ?? 0;// 结算状态 0 全部 1 待结算 2 已结算 3 已退款
+
+ $condition = [
+ [ 'fo.one_fenxiao_id|fo.two_fenxiao_id|fo.three_fenxiao_id', '=', $fenxiao_info[ 'data' ][ 'fenxiao_id' ] ]
+ ];
+ if (!empty($is_settlement)) {
+ if ($is_settlement == 3) {
+ $condition[] = [ 'fo.is_refund', '=', 1 ];
+ }
+ if (in_array($is_settlement, [ 1, 2 ])) {
+ $condition[] = [ 'fo.is_settlement', '=', $is_settlement - 1 ];
+ $condition[] = [ 'fo.is_refund', '=', 0 ];
+ }
+ }
+
+ $order_model = new FenxiaoOrderModel();
+ $list = $order_model->getFenxiaoOrderPageList($condition, $page, $page_size, 'fo.fenxiao_order_id desc');
+ if (!empty($list[ 'data' ][ 'list' ])) {
+ foreach ($list[ 'data' ][ 'list' ] as $k => $item) {
+ if ($item[ 'one_fenxiao_id' ] == $fenxiao_info[ 'data' ][ 'fenxiao_id' ]) {
+ $list[ 'data' ][ 'list' ][ $k ][ 'commission' ] = $item[ 'one_commission' ];
+ $list[ 'data' ][ 'list' ][ $k ][ 'commission_level' ] = 1;
+ } elseif ($item[ 'two_fenxiao_id' ] == $fenxiao_info[ 'data' ][ 'fenxiao_id' ]) {
+ $list[ 'data' ][ 'list' ][ $k ][ 'commission' ] = $item[ 'two_commission' ];
+ $list[ 'data' ][ 'list' ][ $k ][ 'commission_level' ] = 2;
+ } elseif ($item[ 'three_fenxiao_id' ] == $fenxiao_info[ 'data' ][ 'fenxiao_id' ]) {
+ $list[ 'data' ][ 'list' ][ $k ][ 'commission' ] = $item[ 'three_commission' ];
+ $list[ 'data' ][ 'list' ][ $k ][ 'commission_level' ] = 3;
+ }
+ $list[ 'data' ][ 'list' ][ $k ] = array_diff_key($list[ 'data' ][ 'list' ][ $k ], [ 'one_fenxiao_id' => '', 'one_rate' => '', 'one_commission' => '', 'one_fenxiao_name' => '', 'two_fenxiao_id' => '', 'two_rate' => '', 'two_commission' => '', 'two_fenxiao_name' => '', 'three_fenxiao_id' => '', 'three_rate' => '', 'three_commission' => '', 'three_fenxiao_name' => '' ]);
+ }
+ }
+ return $this->response($list);
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/api/controller/Withdraw.php b/src/addon/fenxiao/api/controller/Withdraw.php
index d661c3490..40cf17267 100644
--- a/src/addon/fenxiao/api/controller/Withdraw.php
+++ b/src/addon/fenxiao/api/controller/Withdraw.php
@@ -1,122 +1,114 @@
-checkToken();
- if ($token[ 'code' ] < 0) return $this->response($token);
-
- $page = $this->params['page'] ?? 1;
- $page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
- $status = $this->params['status'] ?? 0;// 当前状态 1待审核 2待转账 3已转账 -1 已拒绝
-
- $condition = [
- [ 'member_id', '=', $this->member_id ]
- ];
- if (!empty($status)) {
- $condition[] = [ 'status', '=', $status ];
- }
-
- $order = 'id desc';
- $withdraw_model = new FenxiaoWithdraw();
- $list = $withdraw_model->getFenxiaoWithdrawPageList($condition, $page, $page_size, $order);
- foreach ($list[ 'data' ][ 'list' ] as $k => $v) {
- $list[ 'data' ][ 'list' ][ $k ] = $withdraw_model->tran($v);
- }
- return $this->response($list);
- }
-
- /**
- * 获取转账方式
- * @return false|string
- */
- public function transferType()
- {
- $token = $this->checkToken();
- if ($token[ 'code' ] < 0) return $this->response($token);
-
- $member_model = new Member();
- $member_info = $member_model->getMemberInfo([ [ 'member_id', '=', $token[ 'data' ][ 'member_id' ] ] ], 'site_id,wx_openid,weapp_openid');
- $withdraw_config_model = new \addon\fenxiao\model\Config();
- $transfer_type_list = $withdraw_config_model->getTransferType($member_info[ 'data' ][ 'site_id' ]);
- if (empty($member_info[ 'data' ][ 'wx_openid' ]) && empty($member_info[ 'data' ][ 'weapp_openid' ])) {
- unset($transfer_type_list[ 'wechatpay' ]);
- }
- return $this->response($this->success($transfer_type_list));
- }
-
- /**
- * 申请提现
- * @return mixed
- */
- public function apply()
- {
- $token = $this->checkToken();
- if ($token[ 'code' ] < 0) return $this->response($token);
-
- $apply_money = $this->params[ 'apply_money' ] ?? 0;
- $transfer_type = $this->params[ 'transfer_type' ] ?? '';//提现方式
- $realname = $this->params[ 'realname' ] ?? '';//真实姓名
- $bank_name = $this->params[ 'bank_name' ] ?? '';//银行名称
- $account_number = $this->params[ 'account_number' ] ?? '';//账号名称
- $mobile = $this->params[ 'mobile' ] ?? '';//手机号
- $app_type = $this->params[ 'app_type' ];
- $fenxiao_withdraw_model = new FenxiaoWithdraw();
- $data = array (
- 'member_id' => $this->member_id,
- 'transfer_type' => $transfer_type,
- 'realname' => $realname,
- 'bank_name' => $bank_name,
- 'account_number' => $account_number,
- 'apply_money' => $apply_money,
- 'mobile' => $mobile,
- 'app_type' => $app_type
- );
- $result = $fenxiao_withdraw_model->apply($data, $this->site_id);
- return $this->response($result);
- }
-
- /**
- * 提现详情
- * @return mixed
- */
- public function detail()
- {
- $token = $this->checkToken();
- if ($token[ 'code' ] < 0) return $this->response($token);
-
- $id = $this->params[ 'id' ] ?? 0;
- $fenxiao_withdraw_model = new FenxiaoWithdraw();
- $params = array (
- 'id' => $id,
- 'site_id' => $this->site_id
- );
- $result = $fenxiao_withdraw_model->getFenxiaoWithdrawDetail($params);
- return $this->response($result);
- }
-
+checkToken();
+ if ($token[ 'code' ] < 0) return $this->response($token);
+
+ $page = $this->params['page'] ?? 1;
+ $page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
+ $status = $this->params['status'] ?? 0;// 当前状态 1待审核 2待转账 3已转账 -1 已拒绝
+
+ $condition = [
+ [ 'member_id', '=', $this->member_id ]
+ ];
+ if (!empty($status)) {
+ $condition[] = [ 'status', '=', $status ];
+ }
+
+ $order = 'id desc';
+ $withdraw_model = new FenxiaoWithdraw();
+ $list = $withdraw_model->getFenxiaoWithdrawPageList($condition, $page, $page_size, $order);
+ foreach ($list[ 'data' ][ 'list' ] as $k => $v) {
+ $list[ 'data' ][ 'list' ][ $k ] = $withdraw_model->tran($v);
+ }
+ return $this->response($list);
+ }
+
+ /**
+ * 获取转账方式
+ * @return false|string
+ */
+ public function transferType()
+ {
+ $token = $this->checkToken();
+ if ($token[ 'code' ] < 0) return $this->response($token);
+
+ $member_model = new Member();
+ $member_info = $member_model->getMemberInfo([ [ 'member_id', '=', $token[ 'data' ][ 'member_id' ] ] ], 'site_id,wx_openid,weapp_openid');
+ $withdraw_config_model = new \addon\fenxiao\model\Config();
+ $transfer_type_list = $withdraw_config_model->getTransferType($member_info[ 'data' ][ 'site_id' ]);
+ if (empty($member_info[ 'data' ][ 'wx_openid' ]) && empty($member_info[ 'data' ][ 'weapp_openid' ])) {
+ unset($transfer_type_list[ 'wechatpay' ]);
+ }
+ return $this->response($this->success($transfer_type_list));
+ }
+
+ /**
+ * 申请提现
+ * @return mixed
+ */
+ public function apply()
+ {
+ $token = $this->checkToken();
+ if ($token[ 'code' ] < 0) return $this->response($token);
+
+ $apply_money = $this->params[ 'apply_money' ] ?? 0;
+ $transfer_type = $this->params[ 'transfer_type' ] ?? '';//提现方式
+ $realname = $this->params[ 'realname' ] ?? '';//真实姓名
+ $bank_name = $this->params[ 'bank_name' ] ?? '';//银行名称
+ $account_number = $this->params[ 'account_number' ] ?? '';//账号名称
+ $mobile = $this->params[ 'mobile' ] ?? '';//手机号
+ $app_type = $this->params[ 'app_type' ];
+ $fenxiao_withdraw_model = new FenxiaoWithdraw();
+ $data = array (
+ 'member_id' => $this->member_id,
+ 'transfer_type' => $transfer_type,
+ 'realname' => $realname,
+ 'bank_name' => $bank_name,
+ 'account_number' => $account_number,
+ 'apply_money' => $apply_money,
+ 'mobile' => $mobile,
+ 'app_type' => $app_type
+ );
+ $result = $fenxiao_withdraw_model->apply($data, $this->site_id);
+ return $this->response($result);
+ }
+
+ /**
+ * 提现详情
+ * @return mixed
+ */
+ public function detail()
+ {
+ $token = $this->checkToken();
+ if ($token[ 'code' ] < 0) return $this->response($token);
+
+ $id = $this->params[ 'id' ] ?? 0;
+ $fenxiao_withdraw_model = new FenxiaoWithdraw();
+ $params = array (
+ 'id' => $id,
+ 'site_id' => $this->site_id
+ );
+ $result = $fenxiao_withdraw_model->getFenxiaoWithdrawDetail($params);
+ return $this->response($result);
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/config/diy_view.php b/src/addon/fenxiao/config/diy_view.php
index 007a13cb9..0218339e0 100644
--- a/src/addon/fenxiao/config/diy_view.php
+++ b/src/addon/fenxiao/config/diy_view.php
@@ -1,124 +1,116 @@
- '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
- 'template' => [
-// [
-// 'title' => '分销市场',
-// 'name' => 'DIY_FENXIAO_MARKET',
-// 'path' => '/pages_tool/index/diy?name=DIY_FENXIAO_MARKET',
-// 'value' => '',
-// ]
- ],
-
- // 后台自定义组件——装修
- 'util' => [
-// [
-// 'name' => 'FenxiaoGoodsList',
-// 'title' => '分销商品',
-// 'type' => 'PROMOTION',
-// 'value' => '{"style":"style-1","sources":"initial","count":6,"goodsId":[],"nameLineMode":"single","template":"row1-of2","categoryId":0,"categoryName":"请选择","goodsNameStyle":{"color":"#303133","control":true,"fontWeight":false},"imgAroundRadius":0,"btnStyle":{"text":"关注","textColor":"#FFFFFF","theme":"default","aroundRadius":25,"control":true,"support":true,"bgColorStart":"#FC6731","bgColorEnd":"#FF4444"},"priceStyle":{"mainColor":"#FF4444","mainControl":true,"lineColor":"#999CA7","lineControl":true,"lineSupport":true},"ornament":{"type":"default","color":"#EDEDED"},"theme":"default"}',
-// 'sort' => '30008',
-// 'support_diy_view' => 'DIY_FENXIAO_MARKET',
-// 'max_count' => 0,
-// 'icon' => 'iconfont iconfenxiaoshangpin'
-// ]
- ],
-
- // 自定义页面路径
- 'link' => [
- [
- 'name' => 'DISTRIBUTION',
- 'title' => '分销',
- 'parent' => 'MARKETING_LINK',
- 'wap_url' => '',
- 'web_url' => '',
- 'sort' => 2,
- 'child_list' => [
- [
- 'name' => 'DISTRIBUTION_CENTRE',
- 'title' => '分销中心',
- 'wap_url' => '/pages_promotion/fenxiao/index',
- 'web_url' => '',
- 'sort' => 0
- ],
- [
- 'name' => 'WITHDRAWAL_SUBSIDIARY',
- 'title' => '提现明细',
- 'wap_url' => '/pages_promotion/fenxiao/withdraw_list',
- 'web_url' => '',
- 'sort' => 0
- ],
- [
- 'name' => 'DISTRIBUTION_ORDER',
- 'title' => '分销订单',
- 'wap_url' => '/pages_promotion/fenxiao/order',
- 'web_url' => '',
- 'sort' => 0
- ],
-// [
-// 'name' => 'DISTRIBUTION_MARKET',
-// 'title' => '分销市场',
-// 'wap_url' => '/pages_tool/index/diy?name=DIY_FENXIAO_MARKET',
-// 'web_url' => '',
-// 'sort' => 0
-// ],
- // [
- // 'name' => 'DISTRIBUTION_GOODS',
- // 'title' => '分销商品',
- // 'wap_url' => '/pages_promotion/fenxiao/goods_list',
- // 'web_url' => '',
- // 'sort' => 0
- // ],
- [
- 'name' => 'DISTRIBUTION_TEAM',
- 'title' => '分销团队',
- 'wap_url' => '/pages_promotion/fenxiao/team',
- 'web_url' => '',
- 'sort' => 0
- ],
- [
- 'name' => 'PROMOTION_POSTER',
- 'title' => '推广海报',
- 'wap_url' => '/pages_promotion/fenxiao/promote_code',
- 'web_url' => '',
- 'sort' => 0
- ],
- ]
- ],
- // [
- // 'name' => 'DISTRIBUTION_GOODS',
- // 'title' => '分销商品',
- // 'parent' => 'COMMODITY',
- // 'wap_url' => '',
- // 'web_url' => '',
- // 'child_list' => []
- // ],
- ],
-
- // 自定义图标库
- 'icon_library' => [],
-
- // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
- 'component' => [],
-
- // uni-app 页面,多个逗号隔开
- 'pages' => [],
-
- // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
- 'info' => [],
-
- // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
- 'theme' => [],
-
- // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
- 'data' => []
+ '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
+ 'template' => [
+// [
+// 'title' => '分销市场',
+// 'name' => 'DIY_FENXIAO_MARKET',
+// 'path' => '/pages_tool/index/diy?name=DIY_FENXIAO_MARKET',
+// 'value' => '',
+// ]
+ ],
+
+ // 后台自定义组件——装修
+ 'util' => [
+// [
+// 'name' => 'FenxiaoGoodsList',
+// 'title' => '分销商品',
+// 'type' => 'PROMOTION',
+// 'value' => '{"style":"style-1","sources":"initial","count":6,"goodsId":[],"nameLineMode":"single","template":"row1-of2","categoryId":0,"categoryName":"请选择","goodsNameStyle":{"color":"#303133","control":true,"fontWeight":false},"imgAroundRadius":0,"btnStyle":{"text":"关注","textColor":"#FFFFFF","theme":"default","aroundRadius":25,"control":true,"support":true,"bgColorStart":"#FC6731","bgColorEnd":"#FF4444"},"priceStyle":{"mainColor":"#FF4444","mainControl":true,"lineColor":"#999CA7","lineControl":true,"lineSupport":true},"ornament":{"type":"default","color":"#EDEDED"},"theme":"default"}',
+// 'sort' => '30008',
+// 'support_diy_view' => 'DIY_FENXIAO_MARKET',
+// 'max_count' => 0,
+// 'icon' => 'iconfont iconfenxiaoshangpin'
+// ]
+ ],
+
+ // 自定义页面路径
+ 'link' => [
+ [
+ 'name' => 'DISTRIBUTION',
+ 'title' => '分销',
+ 'parent' => 'MARKETING_LINK',
+ 'wap_url' => '',
+ 'web_url' => '',
+ 'sort' => 2,
+ 'child_list' => [
+ [
+ 'name' => 'DISTRIBUTION_CENTRE',
+ 'title' => '分销中心',
+ 'wap_url' => '/pages_promotion/fenxiao/index',
+ 'web_url' => '',
+ 'sort' => 0
+ ],
+ [
+ 'name' => 'WITHDRAWAL_SUBSIDIARY',
+ 'title' => '提现明细',
+ 'wap_url' => '/pages_promotion/fenxiao/withdraw_list',
+ 'web_url' => '',
+ 'sort' => 0
+ ],
+ [
+ 'name' => 'DISTRIBUTION_ORDER',
+ 'title' => '分销订单',
+ 'wap_url' => '/pages_promotion/fenxiao/order',
+ 'web_url' => '',
+ 'sort' => 0
+ ],
+// [
+// 'name' => 'DISTRIBUTION_MARKET',
+// 'title' => '分销市场',
+// 'wap_url' => '/pages_tool/index/diy?name=DIY_FENXIAO_MARKET',
+// 'web_url' => '',
+// 'sort' => 0
+// ],
+ // [
+ // 'name' => 'DISTRIBUTION_GOODS',
+ // 'title' => '分销商品',
+ // 'wap_url' => '/pages_promotion/fenxiao/goods_list',
+ // 'web_url' => '',
+ // 'sort' => 0
+ // ],
+ [
+ 'name' => 'DISTRIBUTION_TEAM',
+ 'title' => '分销团队',
+ 'wap_url' => '/pages_promotion/fenxiao/team',
+ 'web_url' => '',
+ 'sort' => 0
+ ],
+ [
+ 'name' => 'PROMOTION_POSTER',
+ 'title' => '推广海报',
+ 'wap_url' => '/pages_promotion/fenxiao/promote_code',
+ 'web_url' => '',
+ 'sort' => 0
+ ],
+ ]
+ ],
+ // [
+ // 'name' => 'DISTRIBUTION_GOODS',
+ // 'title' => '分销商品',
+ // 'parent' => 'COMMODITY',
+ // 'wap_url' => '',
+ // 'web_url' => '',
+ // 'child_list' => []
+ // ],
+ ],
+
+ // 自定义图标库
+ 'icon_library' => [],
+
+ // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
+ 'component' => [],
+
+ // uni-app 页面,多个逗号隔开
+ 'pages' => [],
+
+ // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
+ 'info' => [],
+
+ // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
+ 'theme' => [],
+
+ // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
+ 'data' => []
];
\ No newline at end of file
diff --git a/src/addon/fenxiao/event/AddSiteDiyView.php b/src/addon/fenxiao/event/AddSiteDiyView.php
index 7a83dfeb5..b15639625 100644
--- a/src/addon/fenxiao/event/AddSiteDiyView.php
+++ b/src/addon/fenxiao/event/AddSiteDiyView.php
@@ -1,23 +1,15 @@
-getLevelInfo([ [ 'site_id', '=', $param[ 'site_id' ] ], [ 'is_default', '=', 1 ] ], 'level_id');
-
- if (empty($default_level[ 'data' ])) {
- $data = [
- 'site_id' => $param[ 'site_id' ],
- 'level_name' => '默认等级',
- 'level_num' => 0,
- 'one_rate' => 10.00,
- 'two_rate' => 5.00,
- 'three_rate' => '',
- 'upgrade_type' => '2',
- 'fenxiao_order_num' => '',
- 'fenxiao_order_meney' => '',
- 'one_fenxiao_order_num' => '',
- 'one_fenxiao_order_money' => '',
- 'one_fenxiao_total_order' => '',
- 'order_num' => '',
- 'order_money' => '',
- 'child_num' => '',
- 'child_fenxiao_num' => '',
- 'one_child_num' => '',
- 'one_child_fenxiao_num' => '',
- 'is_default' => 1
- ];
- $res = $model->addLevel($data);
- return $res;
- }
- }
- }
-
+getLevelInfo([ [ 'site_id', '=', $param[ 'site_id' ] ], [ 'is_default', '=', 1 ] ], 'level_id');
+
+ if (empty($default_level[ 'data' ])) {
+ $data = [
+ 'site_id' => $param[ 'site_id' ],
+ 'level_name' => '默认等级',
+ 'level_num' => 0,
+ 'one_rate' => 10.00,
+ 'two_rate' => 5.00,
+ 'three_rate' => '',
+ 'upgrade_type' => '2',
+ 'fenxiao_order_num' => '',
+ 'fenxiao_order_meney' => '',
+ 'one_fenxiao_order_num' => '',
+ 'one_fenxiao_order_money' => '',
+ 'one_fenxiao_total_order' => '',
+ 'order_num' => '',
+ 'order_money' => '',
+ 'child_num' => '',
+ 'child_fenxiao_num' => '',
+ 'one_child_num' => '',
+ 'one_child_fenxiao_num' => '',
+ 'is_default' => 1
+ ];
+ $res = $model->addLevel($data);
+ return $res;
+ }
+ }
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/event/AlterShareRelation.php b/src/addon/fenxiao/event/AlterShareRelation.php
index 0bbe14262..cb60de722 100644
--- a/src/addon/fenxiao/event/AlterShareRelation.php
+++ b/src/addon/fenxiao/event/AlterShareRelation.php
@@ -1,34 +1,26 @@
-bindRelation([
- 'site_id' => $param[ 'site_id' ],
- 'member_id' => $param[ 'member_id' ],
- 'action' => 'alter_share_relation',
- ]);
- }
+bindRelation([
+ 'site_id' => $param[ 'site_id' ],
+ 'member_id' => $param[ 'member_id' ],
+ 'action' => 'alter_share_relation',
+ ]);
+ }
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/event/FenxiaoUpgrade.php b/src/addon/fenxiao/event/FenxiaoUpgrade.php
index 76631213a..7a8a014d4 100644
--- a/src/addon/fenxiao/event/FenxiaoUpgrade.php
+++ b/src/addon/fenxiao/event/FenxiaoUpgrade.php
@@ -1,31 +1,23 @@
-fenxiaoUpgrade($fenxiao_id);
- }
- }
+fenxiaoUpgrade($fenxiao_id);
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/event/GoodsListCategoryIds.php b/src/addon/fenxiao/event/GoodsListCategoryIds.php
index b152225ae..0ca65c6bd 100644
--- a/src/addon/fenxiao/event/GoodsListCategoryIds.php
+++ b/src/addon/fenxiao/event/GoodsListCategoryIds.php
@@ -1,41 +1,33 @@
-getGoodsCategoryIds($condition);
- return $res;
- }
+getGoodsCategoryIds($condition);
+ return $res;
+ }
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/event/GoodsListPromotion.php b/src/addon/fenxiao/event/GoodsListPromotion.php
index 1694e4fb9..bbffc5bb2 100644
--- a/src/addon/fenxiao/event/GoodsListPromotion.php
+++ b/src/addon/fenxiao/event/GoodsListPromotion.php
@@ -1,61 +1,53 @@
-getGoodsPageList($condition, $param[ 'page' ], $param[ 'page_size' ], 'g.create_time desc', $field, $alias, $join);
- return $list;
- }
+getGoodsPageList($condition, $param[ 'page' ], $param[ 'page_size' ], 'g.create_time desc', $field, $alias, $join);
+ return $list;
+ }
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/event/Install.php b/src/addon/fenxiao/event/Install.php
index 0d74b89e0..103e99a73 100644
--- a/src/addon/fenxiao/event/Install.php
+++ b/src/addon/fenxiao/event/Install.php
@@ -1,57 +1,49 @@
-siteid();
- $model = new FenxiaoLevelModel();
- $default_level = $model->getLevelInfo([ [ 'site_id', '=', $site_id ], [ 'is_default', '=', 1 ] ], 'level_id');
-
- if (empty($default_level[ 'data' ])) {
- $data = [
- 'site_id' => $site_id,
- 'level_name' => '默认等级',
- 'level_num' => 0,
- 'one_rate' => '',
- 'two_rate' => '',
- 'three_rate' => '',
- 'upgrade_type' => '2',
- 'fenxiao_order_num' => '',
- 'fenxiao_order_meney' => '',
- 'one_fenxiao_order_num' => '',
- 'one_fenxiao_order_money' => '',
- 'one_fenxiao_total_order' => '',
- 'order_num' => '',
- 'order_money' => '',
- 'child_num' => '',
- 'child_fenxiao_num' => '',
- 'one_child_num' => '',
- 'one_child_fenxiao_num' => '',
- 'is_default' => 1
- ];
- $res = $model->addLevel($data);
- return $res;
- }
-
- return success();
- }
+siteid();
+ $model = new FenxiaoLevelModel();
+ $default_level = $model->getLevelInfo([ [ 'site_id', '=', $site_id ], [ 'is_default', '=', 1 ] ], 'level_id');
+
+ if (empty($default_level[ 'data' ])) {
+ $data = [
+ 'site_id' => $site_id,
+ 'level_name' => '默认等级',
+ 'level_num' => 0,
+ 'one_rate' => '',
+ 'two_rate' => '',
+ 'three_rate' => '',
+ 'upgrade_type' => '2',
+ 'fenxiao_order_num' => '',
+ 'fenxiao_order_meney' => '',
+ 'one_fenxiao_order_num' => '',
+ 'one_fenxiao_order_money' => '',
+ 'one_fenxiao_total_order' => '',
+ 'order_num' => '',
+ 'order_money' => '',
+ 'child_num' => '',
+ 'child_fenxiao_num' => '',
+ 'one_child_num' => '',
+ 'one_child_fenxiao_num' => '',
+ 'is_default' => 1
+ ];
+ $res = $model->addLevel($data);
+ return $res;
+ }
+
+ return success();
+ }
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/event/MemberAccountFromType.php b/src/addon/fenxiao/event/MemberAccountFromType.php
index 57db06ee5..a753b8bd9 100644
--- a/src/addon/fenxiao/event/MemberAccountFromType.php
+++ b/src/addon/fenxiao/event/MemberAccountFromType.php
@@ -1,35 +1,27 @@
- [
- 'fenxiao' => [
- 'type_name' => '分销佣金',
- 'type_url' => '',
- ],
- ],
- ];
- if ($data == '') {
- return $from_type;
- } else {
- return $from_type[$data] ?? [];
- }
- }
+ [
+ 'fenxiao' => [
+ 'type_name' => '分销佣金',
+ 'type_url' => '',
+ ],
+ ],
+ ];
+ if ($data == '') {
+ return $from_type;
+ } else {
+ return $from_type[$data] ?? [];
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/event/MemberCancel.php b/src/addon/fenxiao/event/MemberCancel.php
index ba3303200..70e3949ca 100644
--- a/src/addon/fenxiao/event/MemberCancel.php
+++ b/src/addon/fenxiao/event/MemberCancel.php
@@ -1,31 +1,23 @@
-CronMemberCancel($param[ 'member_id' ], $param[ 'site_id' ]);
- return $res;
- }
+CronMemberCancel($param[ 'member_id' ], $param[ 'site_id' ]);
+ return $res;
+ }
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/event/MemberRegister.php b/src/addon/fenxiao/event/MemberRegister.php
index 8c90b0919..976e44c90 100644
--- a/src/addon/fenxiao/event/MemberRegister.php
+++ b/src/addon/fenxiao/event/MemberRegister.php
@@ -1,32 +1,23 @@
-memberRegister($param['member_id'], $param['site_id']);
- }
- }
+memberRegister($param['member_id'], $param['site_id']);
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/event/OrderComplete.php b/src/addon/fenxiao/event/OrderComplete.php
index a928c522f..b0d7ddb0e 100644
--- a/src/addon/fenxiao/event/OrderComplete.php
+++ b/src/addon/fenxiao/event/OrderComplete.php
@@ -1,35 +1,27 @@
-getOrderInfo([ [ 'order_id', '=', $order_id ] ])[ 'data' ];
- if (!empty($order_info)) {
- $fenxiao_model = new FenxiaoModel();
- $fenxiao_model->autoBecomeFenxiao($order_info[ 'member_id' ], $order_info[ 'site_id' ]);
- }
- }
+getOrderInfo([ [ 'order_id', '=', $order_id ] ])[ 'data' ];
+ if (!empty($order_info)) {
+ $fenxiao_model = new FenxiaoModel();
+ $fenxiao_model->autoBecomeFenxiao($order_info[ 'member_id' ], $order_info[ 'site_id' ]);
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/event/OrderCreateAfter.php b/src/addon/fenxiao/event/OrderCreateAfter.php
index bc46f747f..1425a2b33 100644
--- a/src/addon/fenxiao/event/OrderCreateAfter.php
+++ b/src/addon/fenxiao/event/OrderCreateAfter.php
@@ -1,38 +1,30 @@
-bindRelation([
- 'site_id' => $order_info[ 'site_id' ],
- 'member_id' => $order_info[ 'member_id' ],
- 'action' => 'order_create',
- ]);
- }
- }
+bindRelation([
+ 'site_id' => $order_info[ 'site_id' ],
+ 'member_id' => $order_info[ 'member_id' ],
+ 'action' => 'order_create',
+ ]);
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/event/OrderGoodsRefund.php b/src/addon/fenxiao/event/OrderGoodsRefund.php
index f18665984..a0773812a 100644
--- a/src/addon/fenxiao/event/OrderGoodsRefund.php
+++ b/src/addon/fenxiao/event/OrderGoodsRefund.php
@@ -1,32 +1,24 @@
-refund($data);
- return $res;
- }
+refund($data);
+ return $res;
+ }
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/event/OrderPayAfter.php b/src/addon/fenxiao/event/OrderPayAfter.php
index 4d8c582a8..eb386c86c 100644
--- a/src/addon/fenxiao/event/OrderPayAfter.php
+++ b/src/addon/fenxiao/event/OrderPayAfter.php
@@ -1,43 +1,34 @@
-bindRelation([
- 'site_id' => $order['site_id'],
- 'member_id' => $order['member_id'],
- 'action' => 'order_pay',
- ]);
-
- // 自动成为分销商
- $fenxiao_model->autoBecomeFenxiao($order['member_id'], $order['site_id']);
-
- $fenxiao_order = new FenxiaoOrder();
- return $fenxiao_order->calculate($order);
- }
+bindRelation([
+ 'site_id' => $order['site_id'],
+ 'member_id' => $order['member_id'],
+ 'action' => 'order_pay',
+ ]);
+
+ // 自动成为分销商
+ $fenxiao_model->autoBecomeFenxiao($order['member_id'], $order['site_id']);
+
+ $fenxiao_order = new FenxiaoOrder();
+ return $fenxiao_order->calculate($order);
+ }
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/event/OrderSettlement.php b/src/addon/fenxiao/event/OrderSettlement.php
index 075e1fd53..92a40dbe6 100644
--- a/src/addon/fenxiao/event/OrderSettlement.php
+++ b/src/addon/fenxiao/event/OrderSettlement.php
@@ -1,34 +1,25 @@
-settlement($data['order_id']);
- $res = $fenxiao_order_model->calculateOrder($data['order_id']);
- return $res;
- }
+settlement($data['order_id']);
+ $res = $fenxiao_order_model->calculateOrder($data['order_id']);
+ return $res;
+ }
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/event/PresaleOrderCreate.php b/src/addon/fenxiao/event/PresaleOrderCreate.php
index 19239958d..fd3c5b363 100644
--- a/src/addon/fenxiao/event/PresaleOrderCreate.php
+++ b/src/addon/fenxiao/event/PresaleOrderCreate.php
@@ -1,40 +1,32 @@
-getPresaleOrderInfo([ [ 'id', '=', $id ] ])[ 'data' ];
- if (!empty($order_info)) {
- $fenxiao_model = new FenxiaoModel();
- return $fenxiao_model->bindRelation([
- 'site_id' => $order_info[ 'site_id' ],
- 'member_id' => $order_info[ 'member_id' ],
- 'action' => 'order_create',
- ]);
- }
- }
+getPresaleOrderInfo([ [ 'id', '=', $id ] ])[ 'data' ];
+ if (!empty($order_info)) {
+ $fenxiao_model = new FenxiaoModel();
+ return $fenxiao_model->bindRelation([
+ 'site_id' => $order_info[ 'site_id' ],
+ 'member_id' => $order_info[ 'member_id' ],
+ 'action' => 'order_create',
+ ]);
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/event/PromotionType.php b/src/addon/fenxiao/event/PromotionType.php
index 63ba09ccd..7841e8eb8 100644
--- a/src/addon/fenxiao/event/PromotionType.php
+++ b/src/addon/fenxiao/event/PromotionType.php
@@ -1,26 +1,18 @@
- "分销", "type" => "fenxiao" ];
- }
+ "分销", "type" => "fenxiao" ];
+ }
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/event/ShowPromotion.php b/src/addon/fenxiao/event/ShowPromotion.php
index 4112bdd67..8f54505ab 100644
--- a/src/addon/fenxiao/event/ShowPromotion.php
+++ b/src/addon/fenxiao/event/ShowPromotion.php
@@ -1,46 +1,38 @@
- [
- [
- //插件名称
- 'name' => 'fenxiao',
- //店铺端展示分类 shop:营销活动 member:互动营销
- 'show_type' => 'member',
- //展示主题
- 'title' => '分销',
- //展示介绍
- 'description' => '让客户为您推广销售',
- //展示图标
- 'icon' => 'addon/fenxiao/icon.png',
- //跳转链接
- 'url' => 'fenxiao://shop/fenxiao/index',
- ]
- ]
-
- ];
- return $data;
- }
+ [
+ [
+ //插件名称
+ 'name' => 'fenxiao',
+ //店铺端展示分类 shop:营销活动 member:互动营销
+ 'show_type' => 'member',
+ //展示主题
+ 'title' => '分销',
+ //展示介绍
+ 'description' => '让客户为您推广销售',
+ //展示图标
+ 'icon' => 'addon/fenxiao/icon.png',
+ //跳转链接
+ 'url' => 'fenxiao://shop/fenxiao/index',
+ ]
+ ]
+
+ ];
+ return $data;
+ }
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/event/UnInstall.php b/src/addon/fenxiao/event/UnInstall.php
index 23d8fe0bf..b5c811ce9 100644
--- a/src/addon/fenxiao/event/UnInstall.php
+++ b/src/addon/fenxiao/event/UnInstall.php
@@ -1,25 +1,17 @@
-getShareConfig($param);
- }
-
+getShareConfig($param);
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/event/WchatShareData.php b/src/addon/fenxiao/event/WchatShareData.php
index aef0a3d49..91b8324be 100644
--- a/src/addon/fenxiao/event/WchatShareData.php
+++ b/src/addon/fenxiao/event/WchatShareData.php
@@ -1,28 +1,19 @@
-getShareData($param);
- }
-
+getShareData($param);
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/event/WeappShareConfig.php b/src/addon/fenxiao/event/WeappShareConfig.php
index 97f757f21..6c81c4c06 100644
--- a/src/addon/fenxiao/event/WeappShareConfig.php
+++ b/src/addon/fenxiao/event/WeappShareConfig.php
@@ -1,28 +1,19 @@
-getShareConfig($param);
- }
-
+getShareConfig($param);
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/event/WeappShareData.php b/src/addon/fenxiao/event/WeappShareData.php
index d561d754e..8ac30c9c8 100644
--- a/src/addon/fenxiao/event/WeappShareData.php
+++ b/src/addon/fenxiao/event/WeappShareData.php
@@ -1,28 +1,19 @@
-getShareData($param);
- }
-
+getShareData($param);
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/model/Config.php b/src/addon/fenxiao/model/Config.php
index 51179e178..f043e4f0f 100644
--- a/src/addon/fenxiao/model/Config.php
+++ b/src/addon/fenxiao/model/Config.php
@@ -1,337 +1,329 @@
- $data[ 'level' ],//分销层级
- 'internal_buy' => $data[ 'internal_buy' ],//分销内购
- 'is_examine' => $data[ 'is_examine' ],//是否需要审核
- 'self_purchase_rebate' => $data[ 'self_purchase_rebate' ],//是否开启分销商自购返佣
- 'is_apply' => $data[ 'is_apply' ],//是否开启分销申请
- 'is_commission_money' => $data[ 'is_commission_money' ],//是否开启商品详情一级佣金
- ];
- $config->setConfig($basics_data, '分销基本配置', $is_use, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_BASICS_CONFIG' ] ]);
- //分销商设置
- $fenxiao_data = [
- 'fenxiao_condition' => $data[ 'fenxiao_condition' ],//成为分销商条件(0无条件 1申请 2消费次数 3消费金额 4购买商品)
- 'consume_count' => $data[ 'consume_count' ],//消费次数
- 'consume_money' => $data[ 'consume_money' ],//消费金额
- 'goods_ids' => $data[ 'goods_ids' ],//指定商品id
- 'consume_condition' => $data[ 'consume_condition' ],//消费条件(1付款后 2订单完成)
- 'perfect_info' => $data[ 'perfect_info' ],//完善资料
- ];
- $config->setConfig($fenxiao_data, '分销商配置', $is_use, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_CONFIG' ] ]);
- // 分销默认等级佣金比率
- ( new FenxiaoLevel() )->editLevel([
- 'one_rate' => $data[ 'one_rate' ],
- 'two_rate' => $data[ 'two_rate' ],
- 'three_rate' => $data[ 'three_rate' ]
- ], [ [ 'site_id', '=', $site_id ], [ 'is_default', '=', 1 ] ]);
- //上下级关系
- $relation_data = [
- 'child_condition' => $data[ 'child_condition' ],//成为下线条件
- ];
- $res = $config->setConfig($relation_data, '分销上下级关系配置', $is_use, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_RELATION_CONFIG' ] ]);
-
- return $res;
- }
-
- /**
- * 获取分销基本设置
- * @param $site_id
- * @return array
- */
- public function getFenxiaoBasicsConfig($site_id)
- {
- $config = new ConfigModel();
- $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_BASICS_CONFIG' ] ]);
-
- if (empty($res[ 'data' ][ 'value' ])) {
- $res[ 'data' ][ 'value' ] = [
- 'level' => 2,//分销层级
- 'internal_buy' => 0,//分销内购
- 'is_examine' => 0,//是否需要审核
- 'is_apply' => 0,//分销商申请方式
- 'is_commission_money' => 1,//是否开启商品详情一级佣金
- ];
- }
- $res[ 'data' ][ 'value' ][ 'is_commission_money' ] = $res[ 'data' ][ 'value' ][ 'is_commission_money' ] ?? 1;
- $res[ 'data' ][ 'value' ][ 'self_purchase_rebate' ] = $res[ 'data' ][ 'value' ][ 'self_purchase_rebate' ] ?? 1;
- $res[ 'data' ][ 'value' ][ 'is_apply' ] = $res[ 'data' ][ 'value' ][ 'is_apply' ] ?? 1;
- $res[ 'data' ][ 'value' ][ 'level' ] = $res[ 'data' ][ 'value' ][ 'level' ] == 3 ? 2 : $res[ 'data' ][ 'value' ][ 'level' ];
- return $res;
- }
-
- /**
- * 获取分销商设置
- * @param $site_id
- * @return array
- */
- public function getFenxiaoConfig($site_id)
- {
- $config = new ConfigModel();
- $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_CONFIG' ] ]);
- if (empty($res[ 'data' ][ 'value' ])) {
- $res[ 'data' ][ 'value' ] = [
- 'fenxiao_condition' => 0,//成为分销商条件(0无条件 2消费次数 3消费金额 4购买商品)
- 'is_agreement' => 0,//显示申请协议
- 'agreement_title' => '',//协议标题
- 'agreement_content' => '',//协议内容
- 'consume_count' => 0,//消费次数
- 'consume_money' => 0,//消费次数
- 'consume_condition' => 1,//消费条件(1付款后 2订单完成)
- 'img' => '',//申请页面顶部图片
- 'perfect_info' => '',//完善资料
- ];
-
- }
- return $res;
- }
-
- /**
- * 获取上下级关系
- * @param $site_id
- * @return array
- */
- public function getFenxiaoRelationConfig($site_id)
- {
- $config = new ConfigModel();
- $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_RELATION_CONFIG' ] ]);
- if (empty($res[ 'data' ][ 'value' ])) {
- $res[ 'data' ][ 'value' ] = [
- 'child_condition' => 1,//成为下线条件 1:首次点击分享链接 2:首次下单 3:首次付款
- ];
- }
- return $res;
- }
- /******************************************************************** 分销基本配置 end ****************************************************************************/
-
- /******************************************************************** 分销协议配置 start ****************************************************************************/
-
- /**
- * 设置分销协议配置
- * @param $data
- * @param $is_use
- * @param $site_id
- * @return array
- */
- public function setFenxiaoAgreementConfig($data, $is_use, $site_id)
- {
- $config = new ConfigModel();
-
- $agreement_config = [
- 'is_agreement' => $data[ 'is_agreement' ],//是否显示申请协议
- 'img' => $data[ 'img' ],//申请页面顶部图片
- ];
- $res = $config->setConfig($agreement_config, '分销协议配置', $is_use, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_AGREEMENT_CONFIG' ] ]);
-
- $document = new Document();
- $document->setDocument($data[ 'agreement_title' ], $data[ 'agreement_content' ], [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'document_key', '=', "FENXIAO_AGREEMENT" ] ]);
-
- return $res;
- }
-
- /**
- * 获取分销协议配置
- * @param $site_id
- * @return array
- */
- public function getFenxiaoAgreementConfig($site_id)
- {
- $config = new ConfigModel();
- $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_AGREEMENT_CONFIG' ] ]);
- if (empty($res[ 'data' ][ 'value' ])) {
- $res[ 'data' ][ 'value' ] = [
- 'is_agreement' => 0,//显示申请协议
- 'img' => 'public/static/img/fenxiao/apply_top_gg.png',//申请页面顶部图片
- ];
- }
- return $res;
- }
-
- /******************************************************************** 分销协议配置 end ****************************************************************************/
-
-
- /******************************************************************** 分销结算配置 start ****************************************************************************/
-
- /**
- * 设置分销结算配置
- * @param $data
- * @param $is_use
- * @param $site_id
- * @return array
- */
- public function setFenxiaoSettlementConfig($data, $is_use, $site_id)
- {
-
- $config = new ConfigModel();
- //分销商结算配置
- $settlement_data = [
- 'account_type' => $data[ 'account_type' ],//佣金计算方式
- ];
-
- $config->setConfig($settlement_data, '分销结算配置', $is_use, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_SETTLEMENT_CONFIG' ] ]);
- //分销商提现配置
- $withdraw_data = [
- 'withdraw' => $data[ 'withdraw' ],//最低提现额度
- 'withdraw_rate' => $data[ 'withdraw_rate' ],//佣金提现手续费
-// 'min_no_fee' => $data['min_no_fee'],//最低免手续费区间
-// 'max_no_fee' => $data['max_no_fee'],//最高免手续费区间
- 'withdraw_status' => $data[ 'withdraw_status' ],//提现审核
- 'settlement_day' => $data[ 'settlement_day' ],//天数
- 'withdraw_type' => $data[ 'withdraw_type' ],//账户类型 alipay 支付宝 bank 银行卡
-
- 'transfer_type' => $data[ 'transfer_type' ],//提现方式
- 'max' => $data[ 'max' ],//提现方式
- 'is_auto_transfer' => $data[ 'is_auto_transfer' ], // 是否自动转账 1 手动转账 2 自动转账
- ];
-
- $res = $config->setConfig($withdraw_data, '分销提现配置', $is_use, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_WITHDRAW_CONFIG' ] ]);
- return $res;
- }
-
- /**
- * 分销商结算配置
- * @param $site_id
- * @return array
- */
- public function getFenxiaoSettlementConfig($site_id)
- {
- $config = new ConfigModel();
- $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_SETTLEMENT_CONFIG' ] ]);
- if (empty($res[ 'data' ][ 'value' ])) {
- $res[ 'data' ][ 'value' ] = [
- 'account_type' => 0
- ];
- }
- return $res;
- }
-
- /**
- * 分销商提现配置
- * @param $site_id
- * @return array
- */
- public function getFenxiaoWithdrawConfig($site_id)
- {
- $config = new ConfigModel();
- $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_WITHDRAW_CONFIG' ] ]);
- if (empty($res[ 'data' ][ 'value' ])) {
- $res[ 'data' ][ 'value' ] = [
- 'withdraw' => 0,//最低提现额度
- 'withdraw_rate' => 0,//佣金提现手续费
- 'min_no_fee' => 0,//最低免手续费区间
- 'max_no_fee' => 0,//最高免手续费区间
- 'withdraw_status' => 1,//提现审核
- 'withdraw_type' => 0,//提现方式
- 'is_auto_transfer' => 0,
- 'transfer_type' => '',
- 'max' => 0
- ];
- }
- $value = $res[ 'data' ][ 'value' ];
- if (!isset($value[ 'transfer_type' ])) {
- $value[ 'transfer_type' ] = 'balance';
- }
- if (!isset($value[ 'max' ])) {
- $value[ 'max' ] = 0;
- }
- if (!isset($value[ 'is_auto_transfer' ])) {
- $value[ 'is_auto_transfer' ] = 0;
- }
- $res[ 'data' ][ 'value' ] = $value;
- return $res;
- }
-
- /**
- * 转账方式
- * @param int $site_id
- * @return array
- */
- public function getTransferType($site_id = 0)
- {
- $fenxiao_withdraw_model = new FenxiaoWithdraw();
- $transfer_type_list = $fenxiao_withdraw_model->getTransferType($site_id);
- $config = $this->getFenxiaoWithdrawConfig($site_id)[ "data" ][ 'value' ] ?? [];
- $data = [];
- $support_type = explode(",", $config[ "transfer_type" ]);
- foreach ($transfer_type_list as $k => $v) {
- if (in_array($k, $support_type)) {
- $data[ $k ] = $v;
- }
- }
- return $data;
- }
- /******************************************************************** 分销结算配置 end ****************************************************************************/
-
- /******************************************************************** 分销文字配置 start ****************************************************************************/
-
- /**
- * 设置分销文字配置
- * @param $data
- * @param $is_use
- * @param $site_id
- * @return array
- */
- public function setFenxiaoWordsConfig($data, $is_use, $site_id)
- {
- $config = new ConfigModel();
- $res = $config->setConfig($data, '分销文字配置', $is_use, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_WORDS_CONFIG' ] ]);
- return $res;
- }
-
- /**
- * 获取分销文字配置
- * @param $site_id
- * @return array
- */
- public function getFenxiaoWordsConfig($site_id)
- {
- $config = new ConfigModel();
- $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_WORDS_CONFIG' ] ]);
- if (empty($res[ 'data' ][ 'value' ])) {
- $res[ 'data' ][ 'value' ] = [
- 'concept' => '分销',// 分销概念
- 'fenxiao_name' => '分销商',// 分销商名称
- 'withdraw' => '提现',// 提现名称
- 'account' => '佣金',// 佣金
- 'my_team' => '团队',// 我的团队
- 'child' => '下线',// 下线
- ];
- }
- return $res;
- }
- /******************************************************************** 分销文字配置 end ****************************************************************************/
-
+ $data[ 'level' ],//分销层级
+ 'internal_buy' => $data[ 'internal_buy' ],//分销内购
+ 'is_examine' => $data[ 'is_examine' ],//是否需要审核
+ 'self_purchase_rebate' => $data[ 'self_purchase_rebate' ],//是否开启分销商自购返佣
+ 'is_apply' => $data[ 'is_apply' ],//是否开启分销申请
+ 'is_commission_money' => $data[ 'is_commission_money' ],//是否开启商品详情一级佣金
+ ];
+ $config->setConfig($basics_data, '分销基本配置', $is_use, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_BASICS_CONFIG' ] ]);
+ //分销商设置
+ $fenxiao_data = [
+ 'fenxiao_condition' => $data[ 'fenxiao_condition' ],//成为分销商条件(0无条件 1申请 2消费次数 3消费金额 4购买商品)
+ 'consume_count' => $data[ 'consume_count' ],//消费次数
+ 'consume_money' => $data[ 'consume_money' ],//消费金额
+ 'goods_ids' => $data[ 'goods_ids' ],//指定商品id
+ 'consume_condition' => $data[ 'consume_condition' ],//消费条件(1付款后 2订单完成)
+ 'perfect_info' => $data[ 'perfect_info' ],//完善资料
+ ];
+ $config->setConfig($fenxiao_data, '分销商配置', $is_use, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_CONFIG' ] ]);
+ // 分销默认等级佣金比率
+ ( new FenxiaoLevel() )->editLevel([
+ 'one_rate' => $data[ 'one_rate' ],
+ 'two_rate' => $data[ 'two_rate' ],
+ 'three_rate' => $data[ 'three_rate' ]
+ ], [ [ 'site_id', '=', $site_id ], [ 'is_default', '=', 1 ] ]);
+ //上下级关系
+ $relation_data = [
+ 'child_condition' => $data[ 'child_condition' ],//成为下线条件
+ ];
+ $res = $config->setConfig($relation_data, '分销上下级关系配置', $is_use, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_RELATION_CONFIG' ] ]);
+
+ return $res;
+ }
+
+ /**
+ * 获取分销基本设置
+ * @param $site_id
+ * @return array
+ */
+ public function getFenxiaoBasicsConfig($site_id)
+ {
+ $config = new ConfigModel();
+ $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_BASICS_CONFIG' ] ]);
+
+ if (empty($res[ 'data' ][ 'value' ])) {
+ $res[ 'data' ][ 'value' ] = [
+ 'level' => 2,//分销层级
+ 'internal_buy' => 0,//分销内购
+ 'is_examine' => 0,//是否需要审核
+ 'is_apply' => 0,//分销商申请方式
+ 'is_commission_money' => 1,//是否开启商品详情一级佣金
+ ];
+ }
+ $res[ 'data' ][ 'value' ][ 'is_commission_money' ] = $res[ 'data' ][ 'value' ][ 'is_commission_money' ] ?? 1;
+ $res[ 'data' ][ 'value' ][ 'self_purchase_rebate' ] = $res[ 'data' ][ 'value' ][ 'self_purchase_rebate' ] ?? 1;
+ $res[ 'data' ][ 'value' ][ 'is_apply' ] = $res[ 'data' ][ 'value' ][ 'is_apply' ] ?? 1;
+ $res[ 'data' ][ 'value' ][ 'level' ] = $res[ 'data' ][ 'value' ][ 'level' ] == 3 ? 2 : $res[ 'data' ][ 'value' ][ 'level' ];
+ return $res;
+ }
+
+ /**
+ * 获取分销商设置
+ * @param $site_id
+ * @return array
+ */
+ public function getFenxiaoConfig($site_id)
+ {
+ $config = new ConfigModel();
+ $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_CONFIG' ] ]);
+ if (empty($res[ 'data' ][ 'value' ])) {
+ $res[ 'data' ][ 'value' ] = [
+ 'fenxiao_condition' => 0,//成为分销商条件(0无条件 2消费次数 3消费金额 4购买商品)
+ 'is_agreement' => 0,//显示申请协议
+ 'agreement_title' => '',//协议标题
+ 'agreement_content' => '',//协议内容
+ 'consume_count' => 0,//消费次数
+ 'consume_money' => 0,//消费次数
+ 'consume_condition' => 1,//消费条件(1付款后 2订单完成)
+ 'img' => '',//申请页面顶部图片
+ 'perfect_info' => '',//完善资料
+ ];
+
+ }
+ return $res;
+ }
+
+ /**
+ * 获取上下级关系
+ * @param $site_id
+ * @return array
+ */
+ public function getFenxiaoRelationConfig($site_id)
+ {
+ $config = new ConfigModel();
+ $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_RELATION_CONFIG' ] ]);
+ if (empty($res[ 'data' ][ 'value' ])) {
+ $res[ 'data' ][ 'value' ] = [
+ 'child_condition' => 1,//成为下线条件 1:首次点击分享链接 2:首次下单 3:首次付款
+ ];
+ }
+ return $res;
+ }
+ /******************************************************************** 分销基本配置 end ****************************************************************************/
+
+ /******************************************************************** 分销协议配置 start ****************************************************************************/
+
+ /**
+ * 设置分销协议配置
+ * @param $data
+ * @param $is_use
+ * @param $site_id
+ * @return array
+ */
+ public function setFenxiaoAgreementConfig($data, $is_use, $site_id)
+ {
+ $config = new ConfigModel();
+
+ $agreement_config = [
+ 'is_agreement' => $data[ 'is_agreement' ],//是否显示申请协议
+ 'img' => $data[ 'img' ],//申请页面顶部图片
+ ];
+ $res = $config->setConfig($agreement_config, '分销协议配置', $is_use, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_AGREEMENT_CONFIG' ] ]);
+
+ $document = new Document();
+ $document->setDocument($data[ 'agreement_title' ], $data[ 'agreement_content' ], [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'document_key', '=', "FENXIAO_AGREEMENT" ] ]);
+
+ return $res;
+ }
+
+ /**
+ * 获取分销协议配置
+ * @param $site_id
+ * @return array
+ */
+ public function getFenxiaoAgreementConfig($site_id)
+ {
+ $config = new ConfigModel();
+ $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_AGREEMENT_CONFIG' ] ]);
+ if (empty($res[ 'data' ][ 'value' ])) {
+ $res[ 'data' ][ 'value' ] = [
+ 'is_agreement' => 0,//显示申请协议
+ 'img' => 'public/static/img/fenxiao/apply_top_gg.png',//申请页面顶部图片
+ ];
+ }
+ return $res;
+ }
+
+ /******************************************************************** 分销协议配置 end ****************************************************************************/
+
+
+ /******************************************************************** 分销结算配置 start ****************************************************************************/
+
+ /**
+ * 设置分销结算配置
+ * @param $data
+ * @param $is_use
+ * @param $site_id
+ * @return array
+ */
+ public function setFenxiaoSettlementConfig($data, $is_use, $site_id)
+ {
+
+ $config = new ConfigModel();
+ //分销商结算配置
+ $settlement_data = [
+ 'account_type' => $data[ 'account_type' ],//佣金计算方式
+ ];
+
+ $config->setConfig($settlement_data, '分销结算配置', $is_use, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_SETTLEMENT_CONFIG' ] ]);
+ //分销商提现配置
+ $withdraw_data = [
+ 'withdraw' => $data[ 'withdraw' ],//最低提现额度
+ 'withdraw_rate' => $data[ 'withdraw_rate' ],//佣金提现手续费
+// 'min_no_fee' => $data['min_no_fee'],//最低免手续费区间
+// 'max_no_fee' => $data['max_no_fee'],//最高免手续费区间
+ 'withdraw_status' => $data[ 'withdraw_status' ],//提现审核
+ 'settlement_day' => $data[ 'settlement_day' ],//天数
+ 'withdraw_type' => $data[ 'withdraw_type' ],//账户类型 alipay 支付宝 bank 银行卡
+
+ 'transfer_type' => $data[ 'transfer_type' ],//提现方式
+ 'max' => $data[ 'max' ],//提现方式
+ 'is_auto_transfer' => $data[ 'is_auto_transfer' ], // 是否自动转账 1 手动转账 2 自动转账
+ ];
+
+ $res = $config->setConfig($withdraw_data, '分销提现配置', $is_use, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_WITHDRAW_CONFIG' ] ]);
+ return $res;
+ }
+
+ /**
+ * 分销商结算配置
+ * @param $site_id
+ * @return array
+ */
+ public function getFenxiaoSettlementConfig($site_id)
+ {
+ $config = new ConfigModel();
+ $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_SETTLEMENT_CONFIG' ] ]);
+ if (empty($res[ 'data' ][ 'value' ])) {
+ $res[ 'data' ][ 'value' ] = [
+ 'account_type' => 0
+ ];
+ }
+ return $res;
+ }
+
+ /**
+ * 分销商提现配置
+ * @param $site_id
+ * @return array
+ */
+ public function getFenxiaoWithdrawConfig($site_id)
+ {
+ $config = new ConfigModel();
+ $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_WITHDRAW_CONFIG' ] ]);
+ if (empty($res[ 'data' ][ 'value' ])) {
+ $res[ 'data' ][ 'value' ] = [
+ 'withdraw' => 0,//最低提现额度
+ 'withdraw_rate' => 0,//佣金提现手续费
+ 'min_no_fee' => 0,//最低免手续费区间
+ 'max_no_fee' => 0,//最高免手续费区间
+ 'withdraw_status' => 1,//提现审核
+ 'withdraw_type' => 0,//提现方式
+ 'is_auto_transfer' => 0,
+ 'transfer_type' => '',
+ 'max' => 0
+ ];
+ }
+ $value = $res[ 'data' ][ 'value' ];
+ if (!isset($value[ 'transfer_type' ])) {
+ $value[ 'transfer_type' ] = 'balance';
+ }
+ if (!isset($value[ 'max' ])) {
+ $value[ 'max' ] = 0;
+ }
+ if (!isset($value[ 'is_auto_transfer' ])) {
+ $value[ 'is_auto_transfer' ] = 0;
+ }
+ $res[ 'data' ][ 'value' ] = $value;
+ return $res;
+ }
+
+ /**
+ * 转账方式
+ * @param int $site_id
+ * @return array
+ */
+ public function getTransferType($site_id = 0)
+ {
+ $fenxiao_withdraw_model = new FenxiaoWithdraw();
+ $transfer_type_list = $fenxiao_withdraw_model->getTransferType($site_id);
+ $config = $this->getFenxiaoWithdrawConfig($site_id)[ "data" ][ 'value' ] ?? [];
+ $data = [];
+ $support_type = explode(",", $config[ "transfer_type" ]);
+ foreach ($transfer_type_list as $k => $v) {
+ if (in_array($k, $support_type)) {
+ $data[ $k ] = $v;
+ }
+ }
+ return $data;
+ }
+ /******************************************************************** 分销结算配置 end ****************************************************************************/
+
+ /******************************************************************** 分销文字配置 start ****************************************************************************/
+
+ /**
+ * 设置分销文字配置
+ * @param $data
+ * @param $is_use
+ * @param $site_id
+ * @return array
+ */
+ public function setFenxiaoWordsConfig($data, $is_use, $site_id)
+ {
+ $config = new ConfigModel();
+ $res = $config->setConfig($data, '分销文字配置', $is_use, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_WORDS_CONFIG' ] ]);
+ return $res;
+ }
+
+ /**
+ * 获取分销文字配置
+ * @param $site_id
+ * @return array
+ */
+ public function getFenxiaoWordsConfig($site_id)
+ {
+ $config = new ConfigModel();
+ $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_WORDS_CONFIG' ] ]);
+ if (empty($res[ 'data' ][ 'value' ])) {
+ $res[ 'data' ][ 'value' ] = [
+ 'concept' => '分销',// 分销概念
+ 'fenxiao_name' => '分销商',// 分销商名称
+ 'withdraw' => '提现',// 提现名称
+ 'account' => '佣金',// 佣金
+ 'my_team' => '团队',// 我的团队
+ 'child' => '下线',// 下线
+ ];
+ }
+ return $res;
+ }
+ /******************************************************************** 分销文字配置 end ****************************************************************************/
+
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/model/Fenxiao.php b/src/addon/fenxiao/model/Fenxiao.php
index 8eb54d1cd..30b9624e4 100644
--- a/src/addon/fenxiao/model/Fenxiao.php
+++ b/src/addon/fenxiao/model/Fenxiao.php
@@ -1,837 +1,829 @@
- '正常',
- -1 => '冻结',
- ];
-
- /**
- * 添加分销商
- * @param $data
- * @return mixed
- */
- public function addFenxiao($data)
- {
- $fenxiao_info = model('fenxiao')->getInfo(
- [ [ 'member_id', '=', $data[ 'member_id' ] ], [ 'is_delete', '=', 0 ] ],
- 'fenxiao_id'
- );
- if (!empty($fenxiao_info)) return $this->error('', '已经是分销商了');
-
- $data[ 'fenxiao_no' ] = date('YmdHi') . rand(1000, 9999);
- $data[ 'create_time' ] = time();
- $data[ 'audit_time' ] = time();
-
- model('fenxiao')->startTrans();
- try {
-
- if (!empty($data[ 'parent' ])) {
- //添加上级分销商一级下线人数
- model('fenxiao')->setInc([ [ 'fenxiao_id', '=', $data[ 'parent' ] ], [ 'is_delete', '=', 0 ] ], 'one_child_fenxiao_num');
- //获取上上级分销商id
- $grand_parent_id = model('fenxiao')->getInfo([ [ 'fenxiao_id', '=', $data[ 'parent' ] ], [ 'is_delete', '=', 0 ] ], 'parent');
-
- if (!empty($grand_parent_id) && $grand_parent_id[ 'parent' ] != 0) {
- //添加上上级分销商二级下线人数
- model('fenxiao')->setInc([ [ 'fenxiao_id', '=', $grand_parent_id[ 'parent' ] ] ], 'two_child_fenxiao_num');
-
- $data[ 'grand_parent' ] = $grand_parent_id[ 'parent' ];
- }
-
- // 分销商检测升级
- event('FenxiaoUpgrade', $data[ 'parent' ]);
- }
-
- $res = model('fenxiao')->add($data);
- //修改会员信息
- model('member')->update([ 'fenxiao_id' => $res, 'is_fenxiao' => 1 ], [ [ 'member_id', '=', $data[ 'member_id' ] ] ]);
-
- $stat_model = new Stat();
- $stat_model->switchStat([ 'type' => 'add_fenxiao_member', 'data' => [ 'site_id' => $data[ 'site_id' ] ] ]);
-
- model('fenxiao')->commit();
- return $this->success($res);
- } catch (\Exception $e) {
- model('fenxiao')->rollback();
- return $this->error('', $e->getMessage());
- }
-
- }
-
- /**
- * 冻结
- * @param $fenxiao_id
- * @return array
- */
- public function frozen($fenxiao_id)
- {
- $data = [
- 'status' => -1,
- 'lock_time' => time()
- ];
-
- $res = model('fenxiao')->update($data, [ [ 'fenxiao_id', '=', $fenxiao_id ] ]);
- return $this->success($res);
- }
-
- /**
- * 删除
- * @param $fenxiao_id
- * @return array
- */
- public function delete($fenxiao_id)
- {
- $fenxiao = model('fenxiao')->getInfo(['fenxiao_id'=>$fenxiao_id]);
- $res = model('fenxiao')->delete([ [ 'fenxiao_id', '=', $fenxiao_id ] ]);
- model('member')->update(['is_fenxiao'=>0,'fenxiao_id'=>0], [ [ 'member_id', '=', $fenxiao['member_id'] ] ]);
- return $this->success($res);
- }
-
- /**
- * 解冻
- * @param $fenxiao_id
- * @return array
- */
- public function unfrozen($fenxiao_id)
- {
- $data = [
- 'status' => 1,
- 'lock_time' => time()
- ];
-
- $res = model('fenxiao')->update($data, [ [ 'fenxiao_id', '=', $fenxiao_id ] ]);
- return $this->success($res);
- }
-
- /**
- * 获取分销商详细信息
- * @param array $condition
- * @param string $field
- * @return array
- */
- public function getFenxiaoInfo($condition = [], $field = '*')
- {
- $condition[] = [ 'is_delete', '=', 0 ];
- $res = model('fenxiao')->getInfo($condition, $field);
- return $this->success($res);
- }
-
- /**
- * 获取分销商详细信息
- * @param array $condition
- * @param string $field
- * @return array
- */
- public function getFenxiaoDetailInfo($condition = [])
- {
- $condition[] = [ 'f.is_delete', '=', 0 ];
-
- $field = 'f.*,pf.fenxiao_name as parent_name,nm.username,nm.nickname,nm.headimg,nm.order_num,nm.order_money,fl.level_num';
- $alias = 'f';
- $join = [
- [
- 'fenxiao pf',
- 'pf.fenxiao_id = f.parent',
- 'left'
- ],
- [
- 'member nm',
- 'nm.member_id = f.member_id',
- 'left'
- ],
- [
- 'fenxiao_level fl',
- 'f.level_id = fl.level_id',
- 'left'
- ]
- ];
- $res = model('fenxiao')->getInfo($condition, $field, $alias, $join);
- return $this->success($res);
- }
-
-
- /**
- * 获取分销列表
- * @param array $condition
- * @param string $field
- * @param string $order
- * @param null $limit
- * @return array
- */
- public function getFenxiaoList($condition = [], $field = '*', $order = '', $limit = null)
- {
- $condition[] = [ 'is_delete', '=', 0 ];
- $list = model('fenxiao')->getList($condition, $field, $order, '', '', '', $limit);
- return $this->success($list);
- }
-
- /**
- * 获取分销分页列表
- * @param array $condition
- * @param int $page
- * @param int $page_size
- * @param string $order
- * @return array
- */
- public function getFenxiaoPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $site_id = 0)
- {
- $condition[] = [ 'f.is_delete', '=', 0 ];
- $field = 'f.*,pf.fenxiao_name as parent_name,m.username,m.nickname,m.mobile as member_mobile,m.headimg';
- $alias = 'f';
- $join = [
- [
- 'fenxiao pf',
- 'pf.fenxiao_id = f.parent',
- 'left'
- ],
- [
- 'member m',
- 'm.member_id = f.member_id',
- 'left'
- ]
- ];
- $list = model('fenxiao')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
- $id_array = [];
- foreach ($list[ 'list' ] as $k => $v) {
- $id_array[] = $v['fenxiao_id'];
- }
-
- // 查询分销基础配置
- $config_model = new Config();
- $fenxiao_basic_config = $config_model->getFenxiaoBasicsConfig($site_id)[ 'data' ][ 'value' ];
- $level = $fenxiao_basic_config[ 'level' ];
-
- switch ( $level ) {
- case 1:
- $member_array = [];
- $member_count_array = model('member')->getList([['fenxiao_id', 'in', $id_array]], 'count(*) as count, fenxiao_id', '', '', '', 'fenxiao_id');
- if (!empty($member_count_array)){
- $member_key = array_column($member_count_array, 'fenxiao_id');
- $member_array = array_combine($member_key, $member_count_array);
- }
-
- foreach ($list[ 'list' ] as $k => $v) {
- $count = 0;
- if(isset($member_array[ $v['fenxiao_id'] ])) $count = $member_array[ $v['fenxiao_id'] ][ 'count' ];
- $list[ 'list' ][ $k ][ 'team_num' ] = $count;
- }
- break;
-
- case 2:
-
- $team_array = [];
- $team_list_array = model('fenxiao')->getList([[ 'parent', 'in', $id_array]], 'fenxiao_id, parent');
-
- if(!empty($team_list_array)){
- $team_id_array = [];
- foreach ($team_list_array as $team_k => $team_v) {
- $team_id_array[] = $team_v['fenxiao_id'];
- $team_array[$team_v['parent']][] = $team_v;
- }
- $id_array = array_merge($id_array, $team_id_array);
- }
-
- $member_array = [];
- $member_count_array = model('member')->getList([['fenxiao_id', 'in', $id_array]], 'count(*) as count, fenxiao_id', '', '', '', 'fenxiao_id');
- if (!empty($member_count_array)){
- $member_key = array_column($member_count_array, 'fenxiao_id');
- $member_array = array_combine($member_key, $member_count_array);
- }
-
- foreach ($list[ 'list' ] as $k => $v) {
- $count = 0;
- $num = 0;
- if(isset($member_array[ $v['fenxiao_id'] ])) $count = $member_array[ $v['fenxiao_id'] ][ 'count' ];
-
- if(isset($team_array[$v['fenxiao_id']])){
- foreach ($team_array[$v['fenxiao_id']] as $key => $val){
- if(isset($member_array[ $val['fenxiao_id'] ])) $num += $member_array[ $val['fenxiao_id'] ][ 'count' ];
- }
- }
- $list[ 'list' ][ $k ][ 'team_num' ] = $count + $num;
- }
-
- break;
- }
-
- return $this->success($list);
- }
-
- /**
- * 获取分销分页列表2
- * @param array $condition
- * @param int $page
- * @param int $page_size
- * @param string $order
- * @param string $field
- * @return array
- */
- public function getFenxiaoPageLists($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*', $alias = 'a', $join = null)
- {
- $list = model('fenxiao')->pageList($condition, $field, $order, $page, $page_size, $alias, $join, '');
- return $this->success($list);
- }
-
- /**
- * 获取分销商团队
- * @param $level
- * @param $fenxiao_id
- * @param int $page
- * @param int $page_size
- * @param int $is_pay
- * @return array
- */
- public function getFenxiaoTeam($level, $fenxiao_id, $page = 1, $page_size = PAGE_LIST_ROWS, $is_pay = 0)
- {
- $condition = '';
-
- // 下级分销商id集合
- $one_level_fenxiao = model('fenxiao')->getColumn([ [ 'parent', '=', $fenxiao_id ] ], 'fenxiao_id');
-
- switch ( $level ) {
- // 一级分销
- case 1:
- // 直属会员 + 直属下级分销商
- $or = " OR (f.parent = {$fenxiao_id}) ";
- $condition = "( (m.fenxiao_id = {$fenxiao_id} AND m.is_fenxiao = 0) " . $or . ') AND m.is_delete = 0';
- break;
- // 二级分销
- case 2:
- // 直属下级分销商的下级分销商 + 直属下级分销商的会员
- if (!empty($one_level_fenxiao)) {
- $or = ' OR (f.parent in (' . implode(',',$one_level_fenxiao) . ') ) ';
- $condition = '( (m.is_fenxiao = 0 AND m.fenxiao_id in (' . implode(',', $one_level_fenxiao) . ') )' . $or . ') AND m.is_delete = 0';
- }
- break;
- }
- if (empty($condition)) return $this->success([
- 'page_count' => 1,
- 'count' => 0,
- 'list' => []
- ]);
-
- if ($is_pay) $condition .= ' AND m.order_num > 0';
- $condition .= '';
-
- $field = 'm.member_id,m.nickname,m.headimg,m.is_fenxiao,m.reg_time,m.order_money,m.order_complete_money,m.order_num,m.order_complete_num,m.bind_fenxiao_time,f.fenxiao_id,f.fenxiao_no,f.fenxiao_name,f.audit_time,f.level_name,f.one_child_num,f.one_child_fenxiao_num';
- $alias = 'm';
- $join = [
- [ 'fenxiao f', 'm.member_id = f.member_id', 'left' ]
- ];
-
- $list = model('member')->pageList($condition, $field, 'm.bind_fenxiao_time desc', $page, $page_size, $alias, $join);
- return $this->success($list);
- }
-
- /**
- * 查询我的团队的数量
- * @param $fenxiao_id
- * @param $site_id
- * @return array
- */
- public function getFenxiaoTeamNum($fenxiao_id, $site_id)
- {
- // 查询分销基础配置
- $config_model = new Config();
- $fenxiao_basic_config = $config_model->getFenxiaoBasicsConfig($site_id)[ 'data' ][ 'value' ];
- $level = $fenxiao_basic_config[ 'level' ];
-
- $num = model('member')->getCount([ [ 'fenxiao_id', '=', $fenxiao_id ], [ 'is_fenxiao', '=', 0 ], [ 'is_delete', '=', 0 ] ]);
-
- // 下级分销商id集合
- $one_level_fenxiao = model('fenxiao')->getColumn([ [ 'parent', '=', $fenxiao_id ], [ 'is_delete', '=', 0 ] ], 'fenxiao_id');
-
- $return = [
- 'num' => $num, // 总人数
- 'member_num' => $num, // 会员人数
- 'fenxiao_num' => 0 // 分销商人数
- ];
-
- switch ( $level ) {
- case 1:
- $return[ 'num' ] += count($one_level_fenxiao);
- $return[ 'fenxiao_num' ] += count($one_level_fenxiao);
- break;
- case 2:
- if (!empty($one_level_fenxiao)) {
- $return[ 'num' ] += count($one_level_fenxiao);
- $return[ 'fenxiao_num' ] += count($one_level_fenxiao);
-
- $num = model('member')->getCount([ [ 'fenxiao_id', 'in', $one_level_fenxiao ], [ 'is_fenxiao', '=', 0 ], [ 'is_delete', '=', 0 ] ]);
- $return[ 'num' ] += $num;
- $return[ 'member_num' ] += $num;
-
- $num = model('fenxiao')->getCount([ [ 'parent', 'in', $one_level_fenxiao ], [ 'is_delete', '=', 0 ] ], 'fenxiao_id');
- $return[ 'num' ] += $num;
- $return[ 'fenxiao_num' ] += $num;
- }
- break;
- }
- return $this->success($return);
- }
-
- /**
- * 会员注册之后
- * @param $member_id
- * @param $site_id
- */
- public function memberRegister($member_id, $site_id)
- {
- //如果有推荐人则要修改分享关系
- $member_model = new Member();
- $member_info = $member_model->getMemberInfo([ [ 'member_id', '=', $member_id ] ], 'source_member')[ 'data' ];
- if (!empty($member_info[ 'source_member' ])) {
- $member_model->alterShareRelation($member_id, $member_info[ 'source_member' ], $site_id);
- }
- $this->autoBecomeFenxiao($member_id, $site_id);
- }
-
- /**
- * 自动成为分销商
- * @param $member_id
- * @param $site_id
- * @return array|mixed
- */
- public function autoBecomeFenxiao($member_id, $site_id)
- {
- $member_info = model('member')->getInfo([ [ 'member_id', '=', $member_id ], [ 'site_id', '=', $site_id ], [ 'is_delete', '=', 0 ] ], 'order_num,order_complete_num,order_money,order_complete_money,is_fenxiao');
- if (empty($member_info)) return $this->error('', '未查询到会员信息');
-
- $fenxiao_info = $this->getFenxiaoDetailInfo([ [ 'f.member_id', '=', $member_id ] ])[ 'data' ];
- if (!empty($fenxiao_info) && $member_info[ 'is_fenxiao' ]) return $this->error('', '已经是分销商');
-
- try {
- $config = new Config();
-
- // 分销商基础设置
- $basics_config = $config->getFenxiaoBasicsConfig($site_id)[ 'data' ][ 'value' ];
- if (!$basics_config[ 'level' ]) return $this->error('', '未开启分销');
- if ($basics_config[ 'is_apply' ] != 0) return $this->error('', '成为分销商需进行申请');
-
- // 成为分销商的资格
- $fenxiao_config = $config->getFenxiaoConfig($site_id)[ 'data' ][ 'value' ];
-
- switch ( $fenxiao_config[ 'fenxiao_condition' ] ) {
- case 2:
- // 消费次数
- if ($fenxiao_config[ 'consume_condition' ] == 1 && $member_info[ 'order_num' ] < $fenxiao_config[ 'consume_count' ]) return $this->error('', '未满足成为分销商的条件');
- if ($fenxiao_config[ 'consume_condition' ] == 2 && $member_info[ 'order_complete_num' ] < $fenxiao_config[ 'consume_count' ]) return $this->error('', '未满足成为分销商的条件');
- break;
- case 3:
- // 消费金额
- if ($fenxiao_config[ 'consume_condition' ] == 1 && bccomp($member_info[ 'order_money' ], $fenxiao_config[ 'consume_money' ], 2) == -1) return $this->error('', '未满足成为分销商的条件');
- if ($fenxiao_config[ 'consume_condition' ] == 2 && bccomp($member_info[ 'order_complete_money' ], $fenxiao_config[ 'consume_money' ], 2) == -1) return $this->error('', '未满足成为分销商的条件');
- break;
- case 4:
- // 购买指定商品
- $condition = [
- [ 'og.goods_id', 'in', $fenxiao_config[ 'goods_ids' ] ],
- [ 'og.member_id', '=', $member_id ]
- ];
- if ($fenxiao_config[ 'consume_condition' ] == 1) $condition[] = [ 'pay_status', '=', 1 ];
- if ($fenxiao_config[ 'consume_condition' ] == 2) $condition[] = [ 'order_status', '=', OrderCommon::ORDER_COMPLETE ];
- $count = model('order_goods')->getCount($condition, 'order_goods_id', 'og', [ [ 'order o', 'o.order_id = og.order_id', 'inner' ] ]);
- if (!$count) return $this->error('', '未满足成为分销商的条件');
- break;
- }
- return $this->directlyBecomeFenxiao($member_id);
- } catch (\Exception $e) {
- return $this->error('', 'File:' . $e->getFile() . ',Line:' . $e->getLine() . ',Message:' . $e->getMessage() . ',Code:' . $e->getCode());
- }
- }
-
- /**
- * 会员直接成为分销商
- * @param $member_id
- * @return mixed
- */
- private function directlyBecomeFenxiao($member_id)
- {
- //获取用户信息
- $member_field = 'member_id,site_id,source_member,fenxiao_id,nickname,headimg,mobile,reg_time,order_money,order_complete_money,order_num,order_complete_num';
- $member_info = model('member')->getInfo([ [ 'member_id', '=', $member_id ] ], $member_field);
-
- if (!empty($member_info)) {
- $parent = 0;
- if (!empty($member_info[ 'source_member' ])) {
- $fenxiao_info = model('fenxiao')->getInfo([ [ 'member_id', '=', $member_info[ 'source_member' ] ], [ 'is_delete', '=', 0 ] ], 'fenxiao_id');
- if (!empty($fenxiao_info)) $parent = $fenxiao_info[ 'fenxiao_id' ];
- }
- if (!empty($member_info[ 'fenxiao_id' ])) {
- $fenxiao_info = model('fenxiao')->getInfo([ [ 'member_id', '=', $member_info[ 'source_member' ] ], [ 'is_delete', '=', 0 ] ], 'fenxiao_id');
- if (!empty($fenxiao_info)) $parent = $fenxiao_info[ 'fenxiao_id' ];
- }
-
- //获取分销等级信息
- $level_model = new FenxiaoLevel();
- $level_info = $level_model->getLevelInfo([ [ 'site_id', '=', $member_info[ 'site_id' ] ], [ 'is_default', '=', 1 ] ], 'level_id,level_name');
-
- $data = [
- 'site_id' => $member_info[ 'site_id' ],
- 'fenxiao_name' => $member_info[ 'nickname' ],
- 'mobile' => $member_info[ 'mobile' ],
- 'member_id' => $member_info[ 'member_id' ],
- 'parent' => $parent,
- 'level_id' => $level_info[ 'data' ][ 'level_id' ],
- 'level_name' => $level_info[ 'data' ][ 'level_name' ]
- ];
- $res = $this->addFenxiao($data);
- return $res;
- }
- }
-
- /**
- * 绑定上下线关系
- * TODO 订单创建对返回结果进行检测 不可返回失败
- * @param $param
- * @return array|void
- */
- public function bindRelation($param)
- {
- $site_id = $param[ 'site_id' ] ?? 0;
- $member_id = $param[ 'member_id' ] ?? 0;
- $action = $param[ 'action' ] ?? '';
-
- $config = [
- 'alter_share_relation' => 1,//对应 首次点击链接后绑定
- 'order_create' => 2,//对应 首次下单后绑定
- 'order_pay' => 3,//对应 首次付款后绑定
- ];
- if (!isset($config[ $action ])) return;
-
- //检测触发场景和设置是否匹配
- $config_model = new ConfigModel();
- $child_condition = $config_model->getFenxiaoRelationConfig($site_id)[ 'data' ][ 'value' ][ 'child_condition' ];
- if ($child_condition != $config[ $action ]) return;
-
- //检测用户
- $member_info = model('member')->getInfo([
- [ 'member_id', '=', $member_id ],
- ], 'share_member,fenxiao_id');
- if (empty($member_info)) return;
- //如果已经是分销商 不可以再修改关系
- if (!empty($member_info[ 'fenxiao_id' ])) return;
-
- // 查询推荐人是否是分销商
- $fenxiao_info = model('fenxiao')->getInfo([
- [ 'member_id', '=', $member_info[ 'share_member' ] ],
- [ 'is_delete', '=', 0 ],
- ], 'fenxiao_id');
- if (empty($fenxiao_info)) return;
-
- model('member')->startTrans();
- try {
- $member_data = [
- 'fenxiao_id' => $fenxiao_info[ 'fenxiao_id' ],
- 'bind_fenxiao_time' => time()
- ];
- model('member')->update($member_data, [ [ 'member_id', '=', $member_id ] ]);
- model('fenxiao')->setInc([ [ 'fenxiao_id', '=', $fenxiao_info[ 'fenxiao_id' ] ] ], 'one_child_num');
-
- // 分销商检测升级
- event('FenxiaoUpgrade', $fenxiao_info[ 'fenxiao_id' ]);
-
- model('member')->commit();
- return $this->success();
- } catch (\Exception $e) {
- model('member')->rollback();
- return;
- }
- }
-
- /**
- * 分销商检测升级
- * @param $fenxiao_id
- */
- public function fenxiaoUpgrade($fenxiao_id)
- {
- $join = [
- [ 'member m', 'f.member_id = m.member_id', 'inner' ],
- [ 'fenxiao_level fl', 'f.level_id = fl.level_id', 'inner' ]
- ];
- $fenxiao_info = model('fenxiao')->getInfo([ [ 'f.fenxiao_id', '=', $fenxiao_id ], [ 'f.status', '=', 1 ], [ 'f.is_delete', '=', 0 ] ], 'f.level_id,m.order_num,m.order_money,f.one_fenxiao_order_num,f.one_fenxiao_order_money,f.one_fenxiao_total_order,f.one_child_num,f.one_child_fenxiao_num,fl.one_rate,fl.level_num,f.site_id', 'f', $join);
- if (!empty($fenxiao_info)) {
- $level_list = model('fenxiao_level')->getList([ [ 'site_id', '=', $fenxiao_info[ 'site_id' ] ], [ 'level_num', '>', $fenxiao_info[ 'level_num' ] ] ], '*', 'level_num asc,one_rate asc');
- if (!empty($level_list)) {
- $upgrade_level = null;
- foreach ($level_list as $item) {
- if ($item[ 'upgrade_type' ] == 2) {
- if ($fenxiao_info[ 'order_num' ] >= $item[ 'order_num' ] && $fenxiao_info[ 'order_money' ] >= $item[ 'order_money' ] && $fenxiao_info[ 'one_fenxiao_order_num' ] >= $item[ 'one_fenxiao_order_num' ] && $fenxiao_info[ 'one_fenxiao_total_order' ] >= $item[ 'one_fenxiao_total_order' ] && $fenxiao_info[ 'one_fenxiao_order_money' ] >= $item[ 'one_fenxiao_order_money' ] && $fenxiao_info[ 'one_child_num' ] >= $item[ 'one_child_num' ] && $fenxiao_info[ 'one_child_fenxiao_num' ] >= $item[ 'one_child_fenxiao_num' ]) {
- $upgrade_level = $item;
- break;
- }
- } else {
- if (( $fenxiao_info[ 'order_num' ] >= $item[ 'order_num' ] && $item[ 'order_num' ] > 0 ) || ( $fenxiao_info[ 'order_money' ] >= $item[ 'order_money' ] && $item[ 'order_money' ] > 0 ) || ( $fenxiao_info[ 'one_fenxiao_order_num' ] >= $item[ 'one_fenxiao_order_num' ] && $item[ 'one_fenxiao_order_num' ] > 0 ) || ( $fenxiao_info[ 'one_fenxiao_order_money' ] >= $item[ 'one_fenxiao_order_money' ] && $item[ 'one_fenxiao_order_money' ] > 0 ) || ( $fenxiao_info[ 'one_fenxiao_total_order' ] >= $item[ 'one_fenxiao_total_order' ] && $item[ 'one_fenxiao_total_order' ] > 0 ) || ( $fenxiao_info[ 'one_child_num' ] >= $item[ 'one_child_num' ] && $item[ 'one_child_num' ] > 0 ) || ( $fenxiao_info[ 'one_child_fenxiao_num' ] >= $item[ 'one_child_fenxiao_num' ] && $item[ 'one_child_fenxiao_num' ] > 0 )) {
- $upgrade_level = $item;
- break;
- }
- }
- }
- if ($upgrade_level) {
- model('fenxiao')->update([ 'level_id' => $upgrade_level[ 'level_id' ], 'level_name' => $upgrade_level[ 'level_name' ] ], [ [ 'fenxiao_id', '=', $fenxiao_id ] ]);
- }
- }
- }
- }
-
- /**
- * 获取下一个可升级的分销商等级 及当前分销商已达成的条件
- * @param $member_id
- * @param $site_id
- * @return array
- */
- public function geFenxiaoNextLevel($member_id, $site_id)
- {
- $array = [];
- $join = [
- [ 'member m', 'f.member_id = m.member_id', 'inner' ],
- [ 'fenxiao_level fl', 'f.level_id = fl.level_id', 'inner' ]
- ];
- $fenxiao_info = model('fenxiao')->getInfo(
- [ [ 'f.member_id', '=', $member_id ], [ 'f.site_id', '=', $site_id ], [ 'f.status', '=', 1 ], [ 'f.is_delete', '=', 0 ] ],
- 'f.level_id,m.order_num,m.order_money,f.one_fenxiao_order_num,f.one_fenxiao_order_money,f.one_child_num,f.one_child_fenxiao_num,fl.one_rate,fl.level_num', 'f', $join
- );
- $array[ 'fenxiao' ] = $fenxiao_info;
- $last_level = [];
- if (!empty($fenxiao_info)) {
- $last_level = model('fenxiao_level')->getFirstData([ [ 'site_id', '=', $site_id ], [ 'level_num', '>=', $fenxiao_info[ 'level_num' ] ], [ 'level_id', '<>', $fenxiao_info[ 'level_id' ] ] ], '*', 'level_num asc,one_rate asc');
- }
- $array[ 'last_level' ] = $last_level;
- return $this->success($array);
- }
-
- /**
- * 变更上下级关系
- * @param $member_id
- * @param $parent
- * @return array
- */
- public function changeParentFenxiao($member_id, $parent)
- {
- if ($member_id == '' || $member_id == 0) {
- return $this->error('', '参数member_id不能为空');
- }
- if ($parent == '' || $parent == 0) {
- return $this->error('', '上级分销商不能为空');
- }
-
- //获取上级分销商id
- $parent_info = model('fenxiao')->getInfo([ [ 'fenxiao_id', '=', $parent ], [ 'is_delete', '=', 0 ] ]);
- if (empty($parent_info)) {
- return $this->error('', '上级分销商不存在');
- }
-
- //用户信息
- $member_info = model('member')->getInfo([ [ 'member_id', '=', $member_id ] ], 'fenxiao_id,is_fenxiao');
- if (empty($member_info)) {
- return $this->error('', '用户不存在');
- }
-
- model('fenxiao')->startTrans();
- try {
-
- if ($member_info[ 'is_fenxiao' ] == 1) {//是分销商
-
- $fenxiao_info = model('fenxiao')->getInfo([ [ 'fenxiao_id', '=', $member_info[ 'fenxiao_id' ] ], [ 'is_delete', '=', 0 ] ], 'parent');
- //修改原有上级分销商团队人数
- if ($fenxiao_info[ 'parent' ] > 0) {
- //获取原有上级分销商信息
- model('fenxiao')->setDec([ [ 'fenxiao_id', '=', $fenxiao_info[ 'parent' ] ] ], 'one_child_fenxiao_num');
- }
-
- //修改变更后的上级分销商团队人数
- model('fenxiao')->setInc([ [ 'fenxiao_id', '=', $parent ] ], 'one_child_fenxiao_num');
- //修改上级分销商
- model('fenxiao')->update([ 'parent' => $parent, 'grand_parent' => $parent_info[ 'parent' ] ], [ [ 'fenxiao_id', '=', $member_info[ 'fenxiao_id' ] ] ]);
- } else {
- //不是分销商
-
- //修改上级分销商
- model('member')->update([ 'fenxiao_id' => $parent ], [ [ 'member_id', '=', $member_id ] ]);
- //修改变更后的上级分销商团队人数
- model('fenxiao')->update([ 'one_child_num' => $parent_info[ 'one_child_num' ] + 1 ], [ [ 'fenxiao_id', '=', $parent ] ]);
-
- }
-
- model('fenxiao')->commit();
- return $this->success();
- } catch (\Exception $e) {
- model('fenxiao')->rollback();
- return $this->error('', $e->getMessage());
- }
- }
-
- /**
- * 取消上级分销商
- * @param $member_id
- * @return array
- */
- public function cancelParentFenxiao($member_id)
- {
- if ($member_id == '' || $member_id == 0) {
- return $this->error('', '参数member_id不能为空');
- }
-
- //用户信息
- $member_info = model('member')->getInfo([ [ 'member_id', '=', $member_id ] ], 'fenxiao_id,is_fenxiao');
- if (empty($member_info)) {
- return $this->error('', '用户不存在');
- }
-
- model('fenxiao')->startTrans();
- try {
-
- if ($member_info[ 'is_fenxiao' ] == 1) {//是分销商
-
- $fenxiao_info = model('fenxiao')->getInfo(
- [ [ 'fenxiao_id', '=', $member_info[ 'fenxiao_id' ] ], [ 'is_delete', '=', 0 ] ],
- 'parent'
- );
- //修改原有上级分销商团队人数
- if ($fenxiao_info[ 'parent' ] > 0) {
- //获取原有上级分销商信息
- model('fenxiao')->setDec([ [ 'fenxiao_id', '=', $fenxiao_info[ 'parent' ] ] ], 'one_child_fenxiao_num');
- }
- //修改上级分销商
- model('fenxiao')->update([ 'parent' => '0' ], [ [ 'fenxiao_id', '=', $member_info[ 'fenxiao_id' ] ] ]);
- }
- model('fenxiao')->commit();
- return $this->success();
- } catch (\Exception $e) {
-
- model('fenxiao')->rollback();
- return $this->error('', $e->getMessage());
- }
- }
-
- /**
- * 获取上级分销商名称
- * @param $fenxiao_id
- * @param int $type 1-上级
- * @return mixed|string
- */
- public function getParentFenxiaoName($fenxiao_id, $type = 1)
- {
- if ($fenxiao_id == 0) {
- return '';
- }
- if ($type == 1) {
- $fenxiao_name = model('fenxiao')->getValue([ [ 'fenxiao_id', '=', $fenxiao_id ] ], 'fenxiao_name');
- return $fenxiao_name;
- } else {
-
- $parent = model('fenxiao')->getValue([ [ 'fenxiao_id', '=', $fenxiao_id ] ], 'parent');
- if ($parent == 0) {
- return '';
- } else {
- $fenxiao_name = model('fenxiao')->getValue([ [ 'fenxiao_id', '=', $parent ] ], 'fenxiao_name');
- return $fenxiao_name;
- }
- }
- }
-
- /**
- * 查询上级分销商名称列表(用于会员列表查询)
- * @param $fenxiao_id
- */
- public function getParentFenxiaoNameList($fenxiao_ids)
- {
- $fenxiao_name_list = model('fenxiao')->getList([ [ 'fenxiao_id', 'in', $fenxiao_ids ] ], 'fenxiao_id, fenxiao_name');
- return $fenxiao_name_list;
- }
-
- /**
- * 会员注销删除分销商
- * @param $member_id
- * @param $site_id
- * @return array
- */
- public function CronMemberCancel($member_id, $site_id)
- {
- $info = model('fenxiao')->getInfo([ [ 'member_id', '=', $member_id ], [ 'site_id', '=', $site_id ] ]);
- if (empty($info)) {
- return $this->success();
- }
-
- //冻结账户并删除
- $data = [
- 'status' => -1,
- 'lock_time' => time(),
- 'is_delete' => 1
- ];
-
- $res = model('fenxiao')->update($data, [ [ 'fenxiao_id', '=', $info[ 'fenxiao_id' ] ] ]);
- return $this->success($res);
- }
-
- /**
- * 变更分销商等级
- * @param $data
- * @param $condition
- * @return array
- */
- public function changeFenxiaoLevel($data, $condition)
- {
- $result = model('fenxiao')->update($data, $condition);
- return $this->success($result);
- }
-
- /**
- * 获取分销等级分销商数量
- * @param $condition
- * @return int|mixed
- */
- public function getFenxiaoMemberCount($condition)
- {
- $condition[] = [ 'is_delete', '=', 0 ];
- $count = model('fenxiao')->getCount($condition);
- return $count;
- }
-
- /**
- * 获取分销商排名
- * @param $site_id
- * @param $fenxiao_id
- * @param $order
- * @return array
- */
- public function getFenxiaoRanking($site_id, $fenxiao_id, $order)
- {
- $prefix = config('database.connections.mysql.prefix');
- $version = model('fenxiao')->query('SELECT VERSION() as version')[ 0 ][ 'version' ];
-
- if (substr($version, 0, 1) == 8) {
- $query = "SELECT * FROM (select *,row_number() OVER(order by {$order} DESC) as rownum from {$prefix}fenxiao nf) AS f WHERE f.fenxiao_id = {$fenxiao_id}";
- } else {
- $query = "SELECT b.rownum FROM (SELECT t.*, @rownum := @rownum + 1 AS rownum FROM (SELECT @rownum := 0) r,(SELECT * FROM {$prefix}fenxiao WHERE site_id = {$site_id} ORDER BY {$order} DESC,fenxiao_id ASC) AS t) AS b WHERE b.fenxiao_id = {$fenxiao_id};";
- }
- $data = model('fenxiao')->query($query);
- $data = empty($data) ? 0 : $data[ 0 ][ 'rownum' ];
- return $this->success($data);
- }
-
- // todo 删除分销商
-
-}
+ '正常',
+ -1 => '冻结',
+ ];
+
+ /**
+ * 添加分销商
+ * @param $data
+ * @return mixed
+ */
+ public function addFenxiao($data)
+ {
+ $fenxiao_info = model('fenxiao')->getInfo(
+ [ [ 'member_id', '=', $data[ 'member_id' ] ], [ 'is_delete', '=', 0 ] ],
+ 'fenxiao_id'
+ );
+ if (!empty($fenxiao_info)) return $this->error('', '已经是分销商了');
+
+ $data[ 'fenxiao_no' ] = date('YmdHi') . rand(1000, 9999);
+ $data[ 'create_time' ] = time();
+ $data[ 'audit_time' ] = time();
+
+ model('fenxiao')->startTrans();
+ try {
+
+ if (!empty($data[ 'parent' ])) {
+ //添加上级分销商一级下线人数
+ model('fenxiao')->setInc([ [ 'fenxiao_id', '=', $data[ 'parent' ] ], [ 'is_delete', '=', 0 ] ], 'one_child_fenxiao_num');
+ //获取上上级分销商id
+ $grand_parent_id = model('fenxiao')->getInfo([ [ 'fenxiao_id', '=', $data[ 'parent' ] ], [ 'is_delete', '=', 0 ] ], 'parent');
+
+ if (!empty($grand_parent_id) && $grand_parent_id[ 'parent' ] != 0) {
+ //添加上上级分销商二级下线人数
+ model('fenxiao')->setInc([ [ 'fenxiao_id', '=', $grand_parent_id[ 'parent' ] ] ], 'two_child_fenxiao_num');
+
+ $data[ 'grand_parent' ] = $grand_parent_id[ 'parent' ];
+ }
+
+ // 分销商检测升级
+ event('FenxiaoUpgrade', $data[ 'parent' ]);
+ }
+
+ $res = model('fenxiao')->add($data);
+ //修改会员信息
+ model('member')->update([ 'fenxiao_id' => $res, 'is_fenxiao' => 1 ], [ [ 'member_id', '=', $data[ 'member_id' ] ] ]);
+
+ $stat_model = new Stat();
+ $stat_model->switchStat([ 'type' => 'add_fenxiao_member', 'data' => [ 'site_id' => $data[ 'site_id' ] ] ]);
+
+ model('fenxiao')->commit();
+ return $this->success($res);
+ } catch (\Exception $e) {
+ model('fenxiao')->rollback();
+ return $this->error('', $e->getMessage());
+ }
+
+ }
+
+ /**
+ * 冻结
+ * @param $fenxiao_id
+ * @return array
+ */
+ public function frozen($fenxiao_id)
+ {
+ $data = [
+ 'status' => -1,
+ 'lock_time' => time()
+ ];
+
+ $res = model('fenxiao')->update($data, [ [ 'fenxiao_id', '=', $fenxiao_id ] ]);
+ return $this->success($res);
+ }
+
+ /**
+ * 删除
+ * @param $fenxiao_id
+ * @return array
+ */
+ public function delete($fenxiao_id)
+ {
+ $fenxiao = model('fenxiao')->getInfo(['fenxiao_id'=>$fenxiao_id]);
+ $res = model('fenxiao')->delete([ [ 'fenxiao_id', '=', $fenxiao_id ] ]);
+ model('member')->update(['is_fenxiao'=>0,'fenxiao_id'=>0], [ [ 'member_id', '=', $fenxiao['member_id'] ] ]);
+ return $this->success($res);
+ }
+
+ /**
+ * 解冻
+ * @param $fenxiao_id
+ * @return array
+ */
+ public function unfrozen($fenxiao_id)
+ {
+ $data = [
+ 'status' => 1,
+ 'lock_time' => time()
+ ];
+
+ $res = model('fenxiao')->update($data, [ [ 'fenxiao_id', '=', $fenxiao_id ] ]);
+ return $this->success($res);
+ }
+
+ /**
+ * 获取分销商详细信息
+ * @param array $condition
+ * @param string $field
+ * @return array
+ */
+ public function getFenxiaoInfo($condition = [], $field = '*')
+ {
+ $condition[] = [ 'is_delete', '=', 0 ];
+ $res = model('fenxiao')->getInfo($condition, $field);
+ return $this->success($res);
+ }
+
+ /**
+ * 获取分销商详细信息
+ * @param array $condition
+ * @param string $field
+ * @return array
+ */
+ public function getFenxiaoDetailInfo($condition = [])
+ {
+ $condition[] = [ 'f.is_delete', '=', 0 ];
+
+ $field = 'f.*,pf.fenxiao_name as parent_name,nm.username,nm.nickname,nm.headimg,nm.order_num,nm.order_money,fl.level_num';
+ $alias = 'f';
+ $join = [
+ [
+ 'fenxiao pf',
+ 'pf.fenxiao_id = f.parent',
+ 'left'
+ ],
+ [
+ 'member nm',
+ 'nm.member_id = f.member_id',
+ 'left'
+ ],
+ [
+ 'fenxiao_level fl',
+ 'f.level_id = fl.level_id',
+ 'left'
+ ]
+ ];
+ $res = model('fenxiao')->getInfo($condition, $field, $alias, $join);
+ return $this->success($res);
+ }
+
+
+ /**
+ * 获取分销列表
+ * @param array $condition
+ * @param string $field
+ * @param string $order
+ * @param null $limit
+ * @return array
+ */
+ public function getFenxiaoList($condition = [], $field = '*', $order = '', $limit = null)
+ {
+ $condition[] = [ 'is_delete', '=', 0 ];
+ $list = model('fenxiao')->getList($condition, $field, $order, '', '', '', $limit);
+ return $this->success($list);
+ }
+
+ /**
+ * 获取分销分页列表
+ * @param array $condition
+ * @param int $page
+ * @param int $page_size
+ * @param string $order
+ * @return array
+ */
+ public function getFenxiaoPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $site_id = 0)
+ {
+ $condition[] = [ 'f.is_delete', '=', 0 ];
+ $field = 'f.*,pf.fenxiao_name as parent_name,m.username,m.nickname,m.mobile as member_mobile,m.headimg';
+ $alias = 'f';
+ $join = [
+ [
+ 'fenxiao pf',
+ 'pf.fenxiao_id = f.parent',
+ 'left'
+ ],
+ [
+ 'member m',
+ 'm.member_id = f.member_id',
+ 'left'
+ ]
+ ];
+ $list = model('fenxiao')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
+ $id_array = [];
+ foreach ($list[ 'list' ] as $k => $v) {
+ $id_array[] = $v['fenxiao_id'];
+ }
+
+ // 查询分销基础配置
+ $config_model = new Config();
+ $fenxiao_basic_config = $config_model->getFenxiaoBasicsConfig($site_id)[ 'data' ][ 'value' ];
+ $level = $fenxiao_basic_config[ 'level' ];
+
+ switch ( $level ) {
+ case 1:
+ $member_array = [];
+ $member_count_array = model('member')->getList([['fenxiao_id', 'in', $id_array]], 'count(*) as count, fenxiao_id', '', '', '', 'fenxiao_id');
+ if (!empty($member_count_array)){
+ $member_key = array_column($member_count_array, 'fenxiao_id');
+ $member_array = array_combine($member_key, $member_count_array);
+ }
+
+ foreach ($list[ 'list' ] as $k => $v) {
+ $count = 0;
+ if(isset($member_array[ $v['fenxiao_id'] ])) $count = $member_array[ $v['fenxiao_id'] ][ 'count' ];
+ $list[ 'list' ][ $k ][ 'team_num' ] = $count;
+ }
+ break;
+
+ case 2:
+
+ $team_array = [];
+ $team_list_array = model('fenxiao')->getList([[ 'parent', 'in', $id_array]], 'fenxiao_id, parent');
+
+ if(!empty($team_list_array)){
+ $team_id_array = [];
+ foreach ($team_list_array as $team_k => $team_v) {
+ $team_id_array[] = $team_v['fenxiao_id'];
+ $team_array[$team_v['parent']][] = $team_v;
+ }
+ $id_array = array_merge($id_array, $team_id_array);
+ }
+
+ $member_array = [];
+ $member_count_array = model('member')->getList([['fenxiao_id', 'in', $id_array]], 'count(*) as count, fenxiao_id', '', '', '', 'fenxiao_id');
+ if (!empty($member_count_array)){
+ $member_key = array_column($member_count_array, 'fenxiao_id');
+ $member_array = array_combine($member_key, $member_count_array);
+ }
+
+ foreach ($list[ 'list' ] as $k => $v) {
+ $count = 0;
+ $num = 0;
+ if(isset($member_array[ $v['fenxiao_id'] ])) $count = $member_array[ $v['fenxiao_id'] ][ 'count' ];
+
+ if(isset($team_array[$v['fenxiao_id']])){
+ foreach ($team_array[$v['fenxiao_id']] as $key => $val){
+ if(isset($member_array[ $val['fenxiao_id'] ])) $num += $member_array[ $val['fenxiao_id'] ][ 'count' ];
+ }
+ }
+ $list[ 'list' ][ $k ][ 'team_num' ] = $count + $num;
+ }
+
+ break;
+ }
+
+ return $this->success($list);
+ }
+
+ /**
+ * 获取分销分页列表2
+ * @param array $condition
+ * @param int $page
+ * @param int $page_size
+ * @param string $order
+ * @param string $field
+ * @return array
+ */
+ public function getFenxiaoPageLists($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*', $alias = 'a', $join = null)
+ {
+ $list = model('fenxiao')->pageList($condition, $field, $order, $page, $page_size, $alias, $join, '');
+ return $this->success($list);
+ }
+
+ /**
+ * 获取分销商团队
+ * @param $level
+ * @param $fenxiao_id
+ * @param int $page
+ * @param int $page_size
+ * @param int $is_pay
+ * @return array
+ */
+ public function getFenxiaoTeam($level, $fenxiao_id, $page = 1, $page_size = PAGE_LIST_ROWS, $is_pay = 0)
+ {
+ $condition = '';
+
+ // 下级分销商id集合
+ $one_level_fenxiao = model('fenxiao')->getColumn([ [ 'parent', '=', $fenxiao_id ] ], 'fenxiao_id');
+
+ switch ( $level ) {
+ // 一级分销
+ case 1:
+ // 直属会员 + 直属下级分销商
+ $or = " OR (f.parent = {$fenxiao_id}) ";
+ $condition = "( (m.fenxiao_id = {$fenxiao_id} AND m.is_fenxiao = 0) " . $or . ') AND m.is_delete = 0';
+ break;
+ // 二级分销
+ case 2:
+ // 直属下级分销商的下级分销商 + 直属下级分销商的会员
+ if (!empty($one_level_fenxiao)) {
+ $or = ' OR (f.parent in (' . implode(',',$one_level_fenxiao) . ') ) ';
+ $condition = '( (m.is_fenxiao = 0 AND m.fenxiao_id in (' . implode(',', $one_level_fenxiao) . ') )' . $or . ') AND m.is_delete = 0';
+ }
+ break;
+ }
+ if (empty($condition)) return $this->success([
+ 'page_count' => 1,
+ 'count' => 0,
+ 'list' => []
+ ]);
+
+ if ($is_pay) $condition .= ' AND m.order_num > 0';
+ $condition .= '';
+
+ $field = 'm.member_id,m.nickname,m.headimg,m.is_fenxiao,m.reg_time,m.order_money,m.order_complete_money,m.order_num,m.order_complete_num,m.bind_fenxiao_time,f.fenxiao_id,f.fenxiao_no,f.fenxiao_name,f.audit_time,f.level_name,f.one_child_num,f.one_child_fenxiao_num';
+ $alias = 'm';
+ $join = [
+ [ 'fenxiao f', 'm.member_id = f.member_id', 'left' ]
+ ];
+
+ $list = model('member')->pageList($condition, $field, 'm.bind_fenxiao_time desc', $page, $page_size, $alias, $join);
+ return $this->success($list);
+ }
+
+ /**
+ * 查询我的团队的数量
+ * @param $fenxiao_id
+ * @param $site_id
+ * @return array
+ */
+ public function getFenxiaoTeamNum($fenxiao_id, $site_id)
+ {
+ // 查询分销基础配置
+ $config_model = new Config();
+ $fenxiao_basic_config = $config_model->getFenxiaoBasicsConfig($site_id)[ 'data' ][ 'value' ];
+ $level = $fenxiao_basic_config[ 'level' ];
+
+ $num = model('member')->getCount([ [ 'fenxiao_id', '=', $fenxiao_id ], [ 'is_fenxiao', '=', 0 ], [ 'is_delete', '=', 0 ] ]);
+
+ // 下级分销商id集合
+ $one_level_fenxiao = model('fenxiao')->getColumn([ [ 'parent', '=', $fenxiao_id ], [ 'is_delete', '=', 0 ] ], 'fenxiao_id');
+
+ $return = [
+ 'num' => $num, // 总人数
+ 'member_num' => $num, // 会员人数
+ 'fenxiao_num' => 0 // 分销商人数
+ ];
+
+ switch ( $level ) {
+ case 1:
+ $return[ 'num' ] += count($one_level_fenxiao);
+ $return[ 'fenxiao_num' ] += count($one_level_fenxiao);
+ break;
+ case 2:
+ if (!empty($one_level_fenxiao)) {
+ $return[ 'num' ] += count($one_level_fenxiao);
+ $return[ 'fenxiao_num' ] += count($one_level_fenxiao);
+
+ $num = model('member')->getCount([ [ 'fenxiao_id', 'in', $one_level_fenxiao ], [ 'is_fenxiao', '=', 0 ], [ 'is_delete', '=', 0 ] ]);
+ $return[ 'num' ] += $num;
+ $return[ 'member_num' ] += $num;
+
+ $num = model('fenxiao')->getCount([ [ 'parent', 'in', $one_level_fenxiao ], [ 'is_delete', '=', 0 ] ], 'fenxiao_id');
+ $return[ 'num' ] += $num;
+ $return[ 'fenxiao_num' ] += $num;
+ }
+ break;
+ }
+ return $this->success($return);
+ }
+
+ /**
+ * 会员注册之后
+ * @param $member_id
+ * @param $site_id
+ */
+ public function memberRegister($member_id, $site_id)
+ {
+ //如果有推荐人则要修改分享关系
+ $member_model = new Member();
+ $member_info = $member_model->getMemberInfo([ [ 'member_id', '=', $member_id ] ], 'source_member')[ 'data' ];
+ if (!empty($member_info[ 'source_member' ])) {
+ $member_model->alterShareRelation($member_id, $member_info[ 'source_member' ], $site_id);
+ }
+ $this->autoBecomeFenxiao($member_id, $site_id);
+ }
+
+ /**
+ * 自动成为分销商
+ * @param $member_id
+ * @param $site_id
+ * @return array|mixed
+ */
+ public function autoBecomeFenxiao($member_id, $site_id)
+ {
+ $member_info = model('member')->getInfo([ [ 'member_id', '=', $member_id ], [ 'site_id', '=', $site_id ], [ 'is_delete', '=', 0 ] ], 'order_num,order_complete_num,order_money,order_complete_money,is_fenxiao');
+ if (empty($member_info)) return $this->error('', '未查询到会员信息');
+
+ $fenxiao_info = $this->getFenxiaoDetailInfo([ [ 'f.member_id', '=', $member_id ] ])[ 'data' ];
+ if (!empty($fenxiao_info) && $member_info[ 'is_fenxiao' ]) return $this->error('', '已经是分销商');
+
+ try {
+ $config = new Config();
+
+ // 分销商基础设置
+ $basics_config = $config->getFenxiaoBasicsConfig($site_id)[ 'data' ][ 'value' ];
+ if (!$basics_config[ 'level' ]) return $this->error('', '未开启分销');
+ if ($basics_config[ 'is_apply' ] != 0) return $this->error('', '成为分销商需进行申请');
+
+ // 成为分销商的资格
+ $fenxiao_config = $config->getFenxiaoConfig($site_id)[ 'data' ][ 'value' ];
+
+ switch ( $fenxiao_config[ 'fenxiao_condition' ] ) {
+ case 2:
+ // 消费次数
+ if ($fenxiao_config[ 'consume_condition' ] == 1 && $member_info[ 'order_num' ] < $fenxiao_config[ 'consume_count' ]) return $this->error('', '未满足成为分销商的条件');
+ if ($fenxiao_config[ 'consume_condition' ] == 2 && $member_info[ 'order_complete_num' ] < $fenxiao_config[ 'consume_count' ]) return $this->error('', '未满足成为分销商的条件');
+ break;
+ case 3:
+ // 消费金额
+ if ($fenxiao_config[ 'consume_condition' ] == 1 && bccomp($member_info[ 'order_money' ], $fenxiao_config[ 'consume_money' ], 2) == -1) return $this->error('', '未满足成为分销商的条件');
+ if ($fenxiao_config[ 'consume_condition' ] == 2 && bccomp($member_info[ 'order_complete_money' ], $fenxiao_config[ 'consume_money' ], 2) == -1) return $this->error('', '未满足成为分销商的条件');
+ break;
+ case 4:
+ // 购买指定商品
+ $condition = [
+ [ 'og.goods_id', 'in', $fenxiao_config[ 'goods_ids' ] ],
+ [ 'og.member_id', '=', $member_id ]
+ ];
+ if ($fenxiao_config[ 'consume_condition' ] == 1) $condition[] = [ 'pay_status', '=', 1 ];
+ if ($fenxiao_config[ 'consume_condition' ] == 2) $condition[] = [ 'order_status', '=', OrderCommon::ORDER_COMPLETE ];
+ $count = model('order_goods')->getCount($condition, 'order_goods_id', 'og', [ [ 'order o', 'o.order_id = og.order_id', 'inner' ] ]);
+ if (!$count) return $this->error('', '未满足成为分销商的条件');
+ break;
+ }
+ return $this->directlyBecomeFenxiao($member_id);
+ } catch (\Exception $e) {
+ return $this->error('', 'File:' . $e->getFile() . ',Line:' . $e->getLine() . ',Message:' . $e->getMessage() . ',Code:' . $e->getCode());
+ }
+ }
+
+ /**
+ * 会员直接成为分销商
+ * @param $member_id
+ * @return mixed
+ */
+ private function directlyBecomeFenxiao($member_id)
+ {
+ //获取用户信息
+ $member_field = 'member_id,site_id,source_member,fenxiao_id,nickname,headimg,mobile,reg_time,order_money,order_complete_money,order_num,order_complete_num';
+ $member_info = model('member')->getInfo([ [ 'member_id', '=', $member_id ] ], $member_field);
+
+ if (!empty($member_info)) {
+ $parent = 0;
+ if (!empty($member_info[ 'source_member' ])) {
+ $fenxiao_info = model('fenxiao')->getInfo([ [ 'member_id', '=', $member_info[ 'source_member' ] ], [ 'is_delete', '=', 0 ] ], 'fenxiao_id');
+ if (!empty($fenxiao_info)) $parent = $fenxiao_info[ 'fenxiao_id' ];
+ }
+ if (!empty($member_info[ 'fenxiao_id' ])) {
+ $fenxiao_info = model('fenxiao')->getInfo([ [ 'member_id', '=', $member_info[ 'source_member' ] ], [ 'is_delete', '=', 0 ] ], 'fenxiao_id');
+ if (!empty($fenxiao_info)) $parent = $fenxiao_info[ 'fenxiao_id' ];
+ }
+
+ //获取分销等级信息
+ $level_model = new FenxiaoLevel();
+ $level_info = $level_model->getLevelInfo([ [ 'site_id', '=', $member_info[ 'site_id' ] ], [ 'is_default', '=', 1 ] ], 'level_id,level_name');
+
+ $data = [
+ 'site_id' => $member_info[ 'site_id' ],
+ 'fenxiao_name' => $member_info[ 'nickname' ],
+ 'mobile' => $member_info[ 'mobile' ],
+ 'member_id' => $member_info[ 'member_id' ],
+ 'parent' => $parent,
+ 'level_id' => $level_info[ 'data' ][ 'level_id' ],
+ 'level_name' => $level_info[ 'data' ][ 'level_name' ]
+ ];
+ $res = $this->addFenxiao($data);
+ return $res;
+ }
+ }
+
+ /**
+ * 绑定上下线关系
+ * TODO 订单创建对返回结果进行检测 不可返回失败
+ * @param $param
+ * @return array|void
+ */
+ public function bindRelation($param)
+ {
+ $site_id = $param[ 'site_id' ] ?? 0;
+ $member_id = $param[ 'member_id' ] ?? 0;
+ $action = $param[ 'action' ] ?? '';
+
+ $config = [
+ 'alter_share_relation' => 1,//对应 首次点击链接后绑定
+ 'order_create' => 2,//对应 首次下单后绑定
+ 'order_pay' => 3,//对应 首次付款后绑定
+ ];
+ if (!isset($config[ $action ])) return;
+
+ //检测触发场景和设置是否匹配
+ $config_model = new ConfigModel();
+ $child_condition = $config_model->getFenxiaoRelationConfig($site_id)[ 'data' ][ 'value' ][ 'child_condition' ];
+ if ($child_condition != $config[ $action ]) return;
+
+ //检测用户
+ $member_info = model('member')->getInfo([
+ [ 'member_id', '=', $member_id ],
+ ], 'share_member,fenxiao_id');
+ if (empty($member_info)) return;
+ //如果已经是分销商 不可以再修改关系
+ if (!empty($member_info[ 'fenxiao_id' ])) return;
+
+ // 查询推荐人是否是分销商
+ $fenxiao_info = model('fenxiao')->getInfo([
+ [ 'member_id', '=', $member_info[ 'share_member' ] ],
+ [ 'is_delete', '=', 0 ],
+ ], 'fenxiao_id');
+ if (empty($fenxiao_info)) return;
+
+ model('member')->startTrans();
+ try {
+ $member_data = [
+ 'fenxiao_id' => $fenxiao_info[ 'fenxiao_id' ],
+ 'bind_fenxiao_time' => time()
+ ];
+ model('member')->update($member_data, [ [ 'member_id', '=', $member_id ] ]);
+ model('fenxiao')->setInc([ [ 'fenxiao_id', '=', $fenxiao_info[ 'fenxiao_id' ] ] ], 'one_child_num');
+
+ // 分销商检测升级
+ event('FenxiaoUpgrade', $fenxiao_info[ 'fenxiao_id' ]);
+
+ model('member')->commit();
+ return $this->success();
+ } catch (\Exception $e) {
+ model('member')->rollback();
+ return;
+ }
+ }
+
+ /**
+ * 分销商检测升级
+ * @param $fenxiao_id
+ */
+ public function fenxiaoUpgrade($fenxiao_id)
+ {
+ $join = [
+ [ 'member m', 'f.member_id = m.member_id', 'inner' ],
+ [ 'fenxiao_level fl', 'f.level_id = fl.level_id', 'inner' ]
+ ];
+ $fenxiao_info = model('fenxiao')->getInfo([ [ 'f.fenxiao_id', '=', $fenxiao_id ], [ 'f.status', '=', 1 ], [ 'f.is_delete', '=', 0 ] ], 'f.level_id,m.order_num,m.order_money,f.one_fenxiao_order_num,f.one_fenxiao_order_money,f.one_fenxiao_total_order,f.one_child_num,f.one_child_fenxiao_num,fl.one_rate,fl.level_num,f.site_id', 'f', $join);
+ if (!empty($fenxiao_info)) {
+ $level_list = model('fenxiao_level')->getList([ [ 'site_id', '=', $fenxiao_info[ 'site_id' ] ], [ 'level_num', '>', $fenxiao_info[ 'level_num' ] ] ], '*', 'level_num asc,one_rate asc');
+ if (!empty($level_list)) {
+ $upgrade_level = null;
+ foreach ($level_list as $item) {
+ if ($item[ 'upgrade_type' ] == 2) {
+ if ($fenxiao_info[ 'order_num' ] >= $item[ 'order_num' ] && $fenxiao_info[ 'order_money' ] >= $item[ 'order_money' ] && $fenxiao_info[ 'one_fenxiao_order_num' ] >= $item[ 'one_fenxiao_order_num' ] && $fenxiao_info[ 'one_fenxiao_total_order' ] >= $item[ 'one_fenxiao_total_order' ] && $fenxiao_info[ 'one_fenxiao_order_money' ] >= $item[ 'one_fenxiao_order_money' ] && $fenxiao_info[ 'one_child_num' ] >= $item[ 'one_child_num' ] && $fenxiao_info[ 'one_child_fenxiao_num' ] >= $item[ 'one_child_fenxiao_num' ]) {
+ $upgrade_level = $item;
+ break;
+ }
+ } else {
+ if (( $fenxiao_info[ 'order_num' ] >= $item[ 'order_num' ] && $item[ 'order_num' ] > 0 ) || ( $fenxiao_info[ 'order_money' ] >= $item[ 'order_money' ] && $item[ 'order_money' ] > 0 ) || ( $fenxiao_info[ 'one_fenxiao_order_num' ] >= $item[ 'one_fenxiao_order_num' ] && $item[ 'one_fenxiao_order_num' ] > 0 ) || ( $fenxiao_info[ 'one_fenxiao_order_money' ] >= $item[ 'one_fenxiao_order_money' ] && $item[ 'one_fenxiao_order_money' ] > 0 ) || ( $fenxiao_info[ 'one_fenxiao_total_order' ] >= $item[ 'one_fenxiao_total_order' ] && $item[ 'one_fenxiao_total_order' ] > 0 ) || ( $fenxiao_info[ 'one_child_num' ] >= $item[ 'one_child_num' ] && $item[ 'one_child_num' ] > 0 ) || ( $fenxiao_info[ 'one_child_fenxiao_num' ] >= $item[ 'one_child_fenxiao_num' ] && $item[ 'one_child_fenxiao_num' ] > 0 )) {
+ $upgrade_level = $item;
+ break;
+ }
+ }
+ }
+ if ($upgrade_level) {
+ model('fenxiao')->update([ 'level_id' => $upgrade_level[ 'level_id' ], 'level_name' => $upgrade_level[ 'level_name' ] ], [ [ 'fenxiao_id', '=', $fenxiao_id ] ]);
+ }
+ }
+ }
+ }
+
+ /**
+ * 获取下一个可升级的分销商等级 及当前分销商已达成的条件
+ * @param $member_id
+ * @param $site_id
+ * @return array
+ */
+ public function geFenxiaoNextLevel($member_id, $site_id)
+ {
+ $array = [];
+ $join = [
+ [ 'member m', 'f.member_id = m.member_id', 'inner' ],
+ [ 'fenxiao_level fl', 'f.level_id = fl.level_id', 'inner' ]
+ ];
+ $fenxiao_info = model('fenxiao')->getInfo(
+ [ [ 'f.member_id', '=', $member_id ], [ 'f.site_id', '=', $site_id ], [ 'f.status', '=', 1 ], [ 'f.is_delete', '=', 0 ] ],
+ 'f.level_id,m.order_num,m.order_money,f.one_fenxiao_order_num,f.one_fenxiao_order_money,f.one_child_num,f.one_child_fenxiao_num,fl.one_rate,fl.level_num', 'f', $join
+ );
+ $array[ 'fenxiao' ] = $fenxiao_info;
+ $last_level = [];
+ if (!empty($fenxiao_info)) {
+ $last_level = model('fenxiao_level')->getFirstData([ [ 'site_id', '=', $site_id ], [ 'level_num', '>=', $fenxiao_info[ 'level_num' ] ], [ 'level_id', '<>', $fenxiao_info[ 'level_id' ] ] ], '*', 'level_num asc,one_rate asc');
+ }
+ $array[ 'last_level' ] = $last_level;
+ return $this->success($array);
+ }
+
+ /**
+ * 变更上下级关系
+ * @param $member_id
+ * @param $parent
+ * @return array
+ */
+ public function changeParentFenxiao($member_id, $parent)
+ {
+ if ($member_id == '' || $member_id == 0) {
+ return $this->error('', '参数member_id不能为空');
+ }
+ if ($parent == '' || $parent == 0) {
+ return $this->error('', '上级分销商不能为空');
+ }
+
+ //获取上级分销商id
+ $parent_info = model('fenxiao')->getInfo([ [ 'fenxiao_id', '=', $parent ], [ 'is_delete', '=', 0 ] ]);
+ if (empty($parent_info)) {
+ return $this->error('', '上级分销商不存在');
+ }
+
+ //用户信息
+ $member_info = model('member')->getInfo([ [ 'member_id', '=', $member_id ] ], 'fenxiao_id,is_fenxiao');
+ if (empty($member_info)) {
+ return $this->error('', '用户不存在');
+ }
+
+ model('fenxiao')->startTrans();
+ try {
+
+ if ($member_info[ 'is_fenxiao' ] == 1) {//是分销商
+
+ $fenxiao_info = model('fenxiao')->getInfo([ [ 'fenxiao_id', '=', $member_info[ 'fenxiao_id' ] ], [ 'is_delete', '=', 0 ] ], 'parent');
+ //修改原有上级分销商团队人数
+ if ($fenxiao_info[ 'parent' ] > 0) {
+ //获取原有上级分销商信息
+ model('fenxiao')->setDec([ [ 'fenxiao_id', '=', $fenxiao_info[ 'parent' ] ] ], 'one_child_fenxiao_num');
+ }
+
+ //修改变更后的上级分销商团队人数
+ model('fenxiao')->setInc([ [ 'fenxiao_id', '=', $parent ] ], 'one_child_fenxiao_num');
+ //修改上级分销商
+ model('fenxiao')->update([ 'parent' => $parent, 'grand_parent' => $parent_info[ 'parent' ] ], [ [ 'fenxiao_id', '=', $member_info[ 'fenxiao_id' ] ] ]);
+ } else {
+ //不是分销商
+
+ //修改上级分销商
+ model('member')->update([ 'fenxiao_id' => $parent ], [ [ 'member_id', '=', $member_id ] ]);
+ //修改变更后的上级分销商团队人数
+ model('fenxiao')->update([ 'one_child_num' => $parent_info[ 'one_child_num' ] + 1 ], [ [ 'fenxiao_id', '=', $parent ] ]);
+
+ }
+
+ model('fenxiao')->commit();
+ return $this->success();
+ } catch (\Exception $e) {
+ model('fenxiao')->rollback();
+ return $this->error('', $e->getMessage());
+ }
+ }
+
+ /**
+ * 取消上级分销商
+ * @param $member_id
+ * @return array
+ */
+ public function cancelParentFenxiao($member_id)
+ {
+ if ($member_id == '' || $member_id == 0) {
+ return $this->error('', '参数member_id不能为空');
+ }
+
+ //用户信息
+ $member_info = model('member')->getInfo([ [ 'member_id', '=', $member_id ] ], 'fenxiao_id,is_fenxiao');
+ if (empty($member_info)) {
+ return $this->error('', '用户不存在');
+ }
+
+ model('fenxiao')->startTrans();
+ try {
+
+ if ($member_info[ 'is_fenxiao' ] == 1) {//是分销商
+
+ $fenxiao_info = model('fenxiao')->getInfo(
+ [ [ 'fenxiao_id', '=', $member_info[ 'fenxiao_id' ] ], [ 'is_delete', '=', 0 ] ],
+ 'parent'
+ );
+ //修改原有上级分销商团队人数
+ if ($fenxiao_info[ 'parent' ] > 0) {
+ //获取原有上级分销商信息
+ model('fenxiao')->setDec([ [ 'fenxiao_id', '=', $fenxiao_info[ 'parent' ] ] ], 'one_child_fenxiao_num');
+ }
+ //修改上级分销商
+ model('fenxiao')->update([ 'parent' => '0' ], [ [ 'fenxiao_id', '=', $member_info[ 'fenxiao_id' ] ] ]);
+ }
+ model('fenxiao')->commit();
+ return $this->success();
+ } catch (\Exception $e) {
+
+ model('fenxiao')->rollback();
+ return $this->error('', $e->getMessage());
+ }
+ }
+
+ /**
+ * 获取上级分销商名称
+ * @param $fenxiao_id
+ * @param int $type 1-上级
+ * @return mixed|string
+ */
+ public function getParentFenxiaoName($fenxiao_id, $type = 1)
+ {
+ if ($fenxiao_id == 0) {
+ return '';
+ }
+ if ($type == 1) {
+ $fenxiao_name = model('fenxiao')->getValue([ [ 'fenxiao_id', '=', $fenxiao_id ] ], 'fenxiao_name');
+ return $fenxiao_name;
+ } else {
+
+ $parent = model('fenxiao')->getValue([ [ 'fenxiao_id', '=', $fenxiao_id ] ], 'parent');
+ if ($parent == 0) {
+ return '';
+ } else {
+ $fenxiao_name = model('fenxiao')->getValue([ [ 'fenxiao_id', '=', $parent ] ], 'fenxiao_name');
+ return $fenxiao_name;
+ }
+ }
+ }
+
+ /**
+ * 查询上级分销商名称列表(用于会员列表查询)
+ * @param $fenxiao_id
+ */
+ public function getParentFenxiaoNameList($fenxiao_ids)
+ {
+ $fenxiao_name_list = model('fenxiao')->getList([ [ 'fenxiao_id', 'in', $fenxiao_ids ] ], 'fenxiao_id, fenxiao_name');
+ return $fenxiao_name_list;
+ }
+
+ /**
+ * 会员注销删除分销商
+ * @param $member_id
+ * @param $site_id
+ * @return array
+ */
+ public function CronMemberCancel($member_id, $site_id)
+ {
+ $info = model('fenxiao')->getInfo([ [ 'member_id', '=', $member_id ], [ 'site_id', '=', $site_id ] ]);
+ if (empty($info)) {
+ return $this->success();
+ }
+
+ //冻结账户并删除
+ $data = [
+ 'status' => -1,
+ 'lock_time' => time(),
+ 'is_delete' => 1
+ ];
+
+ $res = model('fenxiao')->update($data, [ [ 'fenxiao_id', '=', $info[ 'fenxiao_id' ] ] ]);
+ return $this->success($res);
+ }
+
+ /**
+ * 变更分销商等级
+ * @param $data
+ * @param $condition
+ * @return array
+ */
+ public function changeFenxiaoLevel($data, $condition)
+ {
+ $result = model('fenxiao')->update($data, $condition);
+ return $this->success($result);
+ }
+
+ /**
+ * 获取分销等级分销商数量
+ * @param $condition
+ * @return int|mixed
+ */
+ public function getFenxiaoMemberCount($condition)
+ {
+ $condition[] = [ 'is_delete', '=', 0 ];
+ $count = model('fenxiao')->getCount($condition);
+ return $count;
+ }
+
+ /**
+ * 获取分销商排名
+ * @param $site_id
+ * @param $fenxiao_id
+ * @param $order
+ * @return array
+ */
+ public function getFenxiaoRanking($site_id, $fenxiao_id, $order)
+ {
+ $prefix = config('database.connections.mysql.prefix');
+ $version = model('fenxiao')->query('SELECT VERSION() as version')[ 0 ][ 'version' ];
+
+ if (substr($version, 0, 1) == 8) {
+ $query = "SELECT * FROM (select *,row_number() OVER(order by {$order} DESC) as rownum from {$prefix}fenxiao nf) AS f WHERE f.fenxiao_id = {$fenxiao_id}";
+ } else {
+ $query = "SELECT b.rownum FROM (SELECT t.*, @rownum := @rownum + 1 AS rownum FROM (SELECT @rownum := 0) r,(SELECT * FROM {$prefix}fenxiao WHERE site_id = {$site_id} ORDER BY {$order} DESC,fenxiao_id ASC) AS t) AS b WHERE b.fenxiao_id = {$fenxiao_id};";
+ }
+ $data = model('fenxiao')->query($query);
+ $data = empty($data) ? 0 : $data[ 0 ][ 'rownum' ];
+ return $this->success($data);
+ }
+
+ // todo 删除分销商
+
+}
diff --git a/src/addon/fenxiao/model/FenxiaoAccount.php b/src/addon/fenxiao/model/FenxiaoAccount.php
index 7850cf587..51142c4fa 100644
--- a/src/addon/fenxiao/model/FenxiaoAccount.php
+++ b/src/addon/fenxiao/model/FenxiaoAccount.php
@@ -1,108 +1,100 @@
- '提现',
- 'order' => '订单结算',
- ];
-
- /**
- * 添加账户流水
- * @param $fenxiao_id
- * @param $fenxiao_name
- * @param $type
- * @param $money
- * @param $relate_id
- * @return array
- */
- public function addAccount($fenxiao_id, $fenxiao_name, $type, $money, $relate_id)
- {
- $account_no = date('YmdHi') . rand(1000, 9999);
- $data = array (
- 'fenxiao_id' => $fenxiao_id,
- 'fenxiao_name' => $fenxiao_name,
- 'account_no' => $account_no,
- 'money' => $money,
- 'type' => $type,
- 'type_name' => $this->type[ $type ],
- 'relate_id' => $relate_id,
- 'create_time' => time(),
- );
-
- $res = model('fenxiao_account')->add($data);
- model('fenxiao')->setInc([ [ 'fenxiao_id', '=', $fenxiao_id ] ], 'account', $money);
-
- return $this->success($res);
- }
-
- /**
- * 获取分销商账户流水信息
- * @param array $condition
- * @param string $field
- * @return array
- */
- public function getFenxiaoAccountInfo($condition = [], $field = '*')
- {
- $list = model('fenxiao_account')->getInfo($condition, $field);
- return $this->success($list);
-
- }
-
- /**
- * 获取分销商账户流水分页列表
- * @param array $condition
- * @param int $page
- * @param int $page_size
- * @param string $order
- * @param string $field
- * @return array
- */
- public function getFenxiaoAccountPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'create_time desc', $field = '*')
- {
- $list = model('fenxiao_account')->pageList($condition, $field, $order, $page, $page_size);
- return $this->success($list);
- }
-
- /**
- * 添加分销商账户流水(不扣账户)
- * @param $fenxiao_id
- * @param $fenxiao_name
- * @param string $type
- * @param $money
- * @param $relate_id
- * @return array
- */
- public function addAccountLog($fenxiao_id, $fenxiao_name, $type, $money, $relate_id)
- {
- $account_no = date('YmdHi') . rand(1000, 9999);
- $data = array (
- 'fenxiao_id' => $fenxiao_id,
- 'fenxiao_name' => $fenxiao_name,
- 'account_no' => $account_no,
- 'money' => $money,
- 'type' => $type,
- 'type_name' => $this->type[ $type ],
- 'relate_id' => $relate_id,
- 'create_time' => time(),
- );
- $res = model('fenxiao_account')->add($data);
- return $this->success($res);
- }
+ '提现',
+ 'order' => '订单结算',
+ ];
+
+ /**
+ * 添加账户流水
+ * @param $fenxiao_id
+ * @param $fenxiao_name
+ * @param $type
+ * @param $money
+ * @param $relate_id
+ * @return array
+ */
+ public function addAccount($fenxiao_id, $fenxiao_name, $type, $money, $relate_id)
+ {
+ $account_no = date('YmdHi') . rand(1000, 9999);
+ $data = array (
+ 'fenxiao_id' => $fenxiao_id,
+ 'fenxiao_name' => $fenxiao_name,
+ 'account_no' => $account_no,
+ 'money' => $money,
+ 'type' => $type,
+ 'type_name' => $this->type[ $type ],
+ 'relate_id' => $relate_id,
+ 'create_time' => time(),
+ );
+
+ $res = model('fenxiao_account')->add($data);
+ model('fenxiao')->setInc([ [ 'fenxiao_id', '=', $fenxiao_id ] ], 'account', $money);
+
+ return $this->success($res);
+ }
+
+ /**
+ * 获取分销商账户流水信息
+ * @param array $condition
+ * @param string $field
+ * @return array
+ */
+ public function getFenxiaoAccountInfo($condition = [], $field = '*')
+ {
+ $list = model('fenxiao_account')->getInfo($condition, $field);
+ return $this->success($list);
+
+ }
+
+ /**
+ * 获取分销商账户流水分页列表
+ * @param array $condition
+ * @param int $page
+ * @param int $page_size
+ * @param string $order
+ * @param string $field
+ * @return array
+ */
+ public function getFenxiaoAccountPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'create_time desc', $field = '*')
+ {
+ $list = model('fenxiao_account')->pageList($condition, $field, $order, $page, $page_size);
+ return $this->success($list);
+ }
+
+ /**
+ * 添加分销商账户流水(不扣账户)
+ * @param $fenxiao_id
+ * @param $fenxiao_name
+ * @param string $type
+ * @param $money
+ * @param $relate_id
+ * @return array
+ */
+ public function addAccountLog($fenxiao_id, $fenxiao_name, $type, $money, $relate_id)
+ {
+ $account_no = date('YmdHi') . rand(1000, 9999);
+ $data = array (
+ 'fenxiao_id' => $fenxiao_id,
+ 'fenxiao_name' => $fenxiao_name,
+ 'account_no' => $account_no,
+ 'money' => $money,
+ 'type' => $type,
+ 'type_name' => $this->type[ $type ],
+ 'relate_id' => $relate_id,
+ 'create_time' => time(),
+ );
+ $res = model('fenxiao_account')->add($data);
+ return $this->success($res);
+ }
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/model/FenxiaoApply.php b/src/addon/fenxiao/model/FenxiaoApply.php
index 538e169aa..f74accc76 100644
--- a/src/addon/fenxiao/model/FenxiaoApply.php
+++ b/src/addon/fenxiao/model/FenxiaoApply.php
@@ -1,311 +1,303 @@
- '待审核',
- 2 => '已审核',
- -1 => '拒绝',
- ];
-
- /**
- * 判断分销商名称是否存在
- * @param $fenxiao_name
- * @param $site_id
- * @return array
- */
- public function existFenxiaoName($fenxiao_name, $site_id)
- {
- $res = model('fenxiao_apply')->getCount([ [ 'fenxiao_name', '=', $fenxiao_name ], [ 'site_id', '=', $site_id ] ]);
- if ($res > 0) {
- return $this->error('', '该分销商名称已存在');
- }
- return $this->success();
- }
-
- /**
- * 申请成为分销商
- * @param $member_id
- * @param $site_id
- * @param string $fenxiao_name
- * @param string $mobile
- * @return array|int|mixed|string
- */
- public function applyFenxiao($member_id, $site_id, $fenxiao_name = '', $mobile = '')
- {
- //判断该用户是否已经申请
- $apply_info = model('fenxiao_apply')->getInfo([ [ 'member_id', '=', $member_id ] ], 'apply_id,status');
- if (!empty($apply_info) && $apply_info[ 'status' ] != -1) {
- return $this->error('', '已经申请过,请不要重复申请');
- }
-
- // 分销商基础设置
- $config = new Config();
- $basics_config = $config->getFenxiaoBasicsConfig($site_id)[ 'data' ][ 'value' ];
-
- if (!$basics_config[ 'level' ]) return $this->error('', '未开启分销');
-
- //获取分销配置信息
- $fenxiao_config = $config->getFenxiaoConfig($site_id)[ 'data' ][ 'value' ];
-
- //获取用户信息
- $member_model = new Member();
- $member_field = 'source_member,fenxiao_id,nickname,headimg,reg_time,order_money,order_complete_money,order_num,order_complete_num';
- $member_info = $member_model->getMemberInfo([ [ 'member_id', '=', $member_id ] ], $member_field);
-
- // 判断用户是否可以成为申请分销商
- if ($fenxiao_config[ 'fenxiao_condition' ] == 2) {
- if ($fenxiao_config[ 'consume_condition' ] == 1 && $fenxiao_config[ 'consume_count' ] > $member_info[ 'data' ][ 'order_num' ]) {
- return $this->error('', '您的消费次数未满足申请条件');
- } elseif ($fenxiao_config[ 'consume_condition' ] == 2 && $fenxiao_config[ 'consume_count' ] > $member_info[ 'data' ][ 'order_complete_num' ]) {
- return $this->error('', '您的消费次数未满足申请条件');
- }
- } elseif ($fenxiao_config[ 'fenxiao_condition' ] == 3) {
- if ($fenxiao_config[ 'consume_condition' ] == 1 && $fenxiao_config[ 'consume_money' ] > $member_info[ 'data' ][ 'order_money' ]) {
- return $this->error('', '您的消费金额未满足申请条件');
- } elseif ($fenxiao_config[ 'consume_condition' ] == 2 && $fenxiao_config[ 'consume_money' ] > $member_info[ 'data' ][ 'order_complete_money' ]) {
- return $this->error('', '您的消费金额未满足申请条件');
- }
- } elseif ($fenxiao_config[ 'fenxiao_condition' ] == 4) { //购买指定商品
- //获取用户购买商品是否在成为分销商指定商品区域
- $alias = 'og';
- $condition[] = [ 'og.member_id', '=', $member_id ];
- $condition[] = [ 'og.site_id', '=', $site_id ];
- $condition[] = [ 'og.goods_id', 'in', $fenxiao_config[ 'goods_ids' ] ];
- $field = 'o.order_status,og.goods_id';
- $join = [
- [
- 'order o',
- 'o.order_id = og.order_id',
- 'inner'
- ],
-
- ];
- if ($fenxiao_config[ 'consume_condition' ] == 1) {
- $condition[] = [ 'o.pay_status', '=', 1 ];
- $order_data = model('order_goods')->getList($condition, $field, '', $alias, $join);
- if (empty($order_data)) {
- return $this->error('', '您还未满足申请条件');
- }
- } elseif ($fenxiao_config[ 'consume_condition' ] == 2) {
- $condition[] = [ 'o.order_status', '=', '10' ];
- $order_data = model('order_goods')->getList($condition, $field, '', $alias, $join);
- if (empty($order_data)) {
- return $this->error('', '您还未满足申请条件');
- }
- }
-
- }
-
- if (empty($fenxiao_name)) $fenxiao_name = $member_info[ 'data' ][ 'nickname' ];
-
- //获取分销等级信息
- $level_model = new FenxiaoLevel();
- $level_info = $level_model->getLevelInfo([ [ 'site_id', '=', $site_id ], [ 'is_default', '=', 1 ] ], 'level_id,level_name');
-
- // 成为分销商是否需要审核
- if ($basics_config[ 'is_examine' ]) {
- $apply_data = [
- 'site_id' => $site_id,
- 'fenxiao_name' => $fenxiao_name,
- 'parent' => $member_info[ 'data' ][ 'fenxiao_id' ],
- 'member_id' => $member_id,
- 'mobile' => $mobile,
- 'nickname' => $member_info[ 'data' ][ 'nickname' ],
- 'headimg' => $member_info[ 'data' ][ 'headimg' ],
- 'level_id' => $level_info[ 'data' ][ 'level_id' ],
- 'level_name' => $level_info[ 'data' ][ 'level_name' ],
- 'order_complete_money' => $member_info[ 'data' ][ 'order_complete_money' ],
- 'order_complete_num' => $member_info[ 'data' ][ 'order_complete_num' ],
- 'reg_time' => $member_info[ 'data' ][ 'reg_time' ],
- 'create_time' => time(),
- 'status' => 1
- ];
- if (!empty($apply_info)) {
- $res = model('fenxiao_apply')->update($apply_data, [ [ 'member_id', '=', $member_id ] ]);
- } else {
- $res = model('fenxiao_apply')->add($apply_data);
- }
- return $this->success($res);
- } else {
- $fenxiao_data = [
- 'site_id' => $site_id,
- 'fenxiao_name' => $fenxiao_name,
- 'mobile' => $mobile,
- 'member_id' => $member_id,
- 'parent' => $member_info[ 'data' ][ 'fenxiao_id' ],
- 'level_id' => $level_info[ 'data' ][ 'level_id' ],
- 'level_name' => $level_info[ 'data' ][ 'level_name' ]
- ];
- $fenxiao_model = new Fenxiao();
- $res = $fenxiao_model->addFenxiao($fenxiao_data);
- return $res;
- }
- }
-
- /**
- * 管理员添加分销商
- */
- public function addFenxiao($fenxiao_data)
- {
- if (empty($fenxiao_data[ 'fenxiao_name' ])) {
- return $this->error('', '分销商名称不能为空');
- }
- if (empty($fenxiao_data[ 'level_id' ])) {
- return $this->error('', '请选择分销商等级');
- }
- if (empty($fenxiao_data[ 'member_id' ])) {
- return $this->error('', '请选择关联会员');
- }
-
- //判断该用户是否已经申请
- $apply_info = model('fenxiao_apply')->getInfo([ [ 'member_id', '=', $fenxiao_data[ 'member_id' ] ] ], 'apply_id,status');
- if (!empty($apply_info) && $apply_info[ 'status' ] != -1) {
- return $this->error('', '已经申请过,请不要重复申请');
- }
-
- // 分销商基础设置
- $config = new Config();
- //获取分销配置信息
- $fenxiao_config = $config->getFenxiaoConfig($fenxiao_data[ 'site_id' ])[ 'data' ][ 'value' ];
-
- //获取用户信息
- $member_model = new Member();
- $member_field = 'source_member,fenxiao_id,nickname,headimg,reg_time,order_money,order_complete_money,order_num,order_complete_num';
- $member_info = $member_model->getMemberInfo([ [ 'member_id', '=', $fenxiao_data[ 'member_id' ] ] ], $member_field);
- if (empty($member_info)) return $this->error('', '未获取到会员信息');
-
- //获取分销等级信息
- $level_model = new FenxiaoLevel();
- $level_info = $level_model->getLevelInfo([ [ 'site_id', '=', $fenxiao_data[ 'site_id' ] ], [ 'level_id', '=', $fenxiao_data[ 'level_id' ] ] ], 'level_name');
- $fenxiao_data[ 'level_name' ] = $level_info[ 'data' ][ 'level_name' ];
-
- $fenxiao_model = new Fenxiao();
- return $fenxiao_model->addFenxiao($fenxiao_data);
-
- }
-
- /**
- * 审核通过
- * @param $apply_id
- * @param $site_id
- * @return array|mixed
- */
- public function pass($apply_id, $site_id)
- {
- $info = model('fenxiao_apply')->getInfo([ [ 'apply_id', '=', $apply_id ], [ 'site_id', '=', $site_id ] ]);
- if ($info[ 'status' ] == 2) {
- return $this->success();
- }
-
- model('fenxiao_apply')->startTrans();
- try {
- $data = [
- 'status' => 2,
- 'update_time' => time(),
- ];
- $res = model('fenxiao_apply')->update($data, [ [ 'apply_id', '=', $apply_id ], [ 'site_id', '=', $site_id ] ]);
-
- $fenxiao_data = [
- 'site_id' => $info[ 'site_id' ],
- 'fenxiao_name' => $info[ 'fenxiao_name' ],
- 'mobile' => $info[ 'mobile' ],
- 'member_id' => $info[ 'member_id' ],
- 'parent' => $info[ 'parent' ],
- 'level_id' => $info[ 'level_id' ],
- 'level_name' => $info[ 'level_name' ]
- ];
-
- $fenxiao_model = new Fenxiao();
- $result = $fenxiao_model->addFenxiao($fenxiao_data);
- if ($result[ 'code' ] != 0) {
- model('fenxiao_apply')->rollback();
- return $result;
- }
-
- model('fenxiao_apply')->commit();
-
- return $this->success($res);
- } catch (\Exception $e) {
- model('fenxiao_apply')->rollback();
- return $this->error('', $e->getMessage());
- }
-
- }
-
- /**
- * 审核不通过
- * @param $apply_id
- * @return array
- */
- public function refuse($apply_id)
- {
- $data = [
- 'status' => -1,
- 'update_time' => time()
- ];
-
- $res = model('fenxiao_apply')->update($data, [ [ 'apply_id', '=', $apply_id ] ]);
- return $this->success($res);
- }
-
- /**
- * 获取分销商申请信息
- * @param array $condition
- * @param string $field
- * @return array
- */
- public function getFenxiaoApplyInfo($condition = [], $field = '*')
- {
- $res = model('fenxiao_apply')->getInfo($condition, $field);
- return $this->success($res);
- }
-
- /**
- * 获取分销商申请分页列表
- * @param array $condition
- * @param int $page
- * @param int $page_size
- * @param string $order
- * @param string $field
- * @param string $alias
- * @param array $join
- * @return array
- */
- public function getFenxiaoApplyPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*', $alias = 'a', $join = [])
- {
- $list = model('fenxiao_apply')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
- return $this->success($list);
- }
-
- /**
- * 获取分销商申请数量
- * @param array $condition
- * @param string $field
- * @return array
- */
- public function getFenxiaoApplyCount($condition = [], $field = 'id')
- {
- $count = model('fenxiao_apply')->getCount($condition, $field);
- return $this->success($count);
- }
-
+ '待审核',
+ 2 => '已审核',
+ -1 => '拒绝',
+ ];
+
+ /**
+ * 判断分销商名称是否存在
+ * @param $fenxiao_name
+ * @param $site_id
+ * @return array
+ */
+ public function existFenxiaoName($fenxiao_name, $site_id)
+ {
+ $res = model('fenxiao_apply')->getCount([ [ 'fenxiao_name', '=', $fenxiao_name ], [ 'site_id', '=', $site_id ] ]);
+ if ($res > 0) {
+ return $this->error('', '该分销商名称已存在');
+ }
+ return $this->success();
+ }
+
+ /**
+ * 申请成为分销商
+ * @param $member_id
+ * @param $site_id
+ * @param string $fenxiao_name
+ * @param string $mobile
+ * @return array|int|mixed|string
+ */
+ public function applyFenxiao($member_id, $site_id, $fenxiao_name = '', $mobile = '')
+ {
+ //判断该用户是否已经申请
+ $apply_info = model('fenxiao_apply')->getInfo([ [ 'member_id', '=', $member_id ] ], 'apply_id,status');
+ if (!empty($apply_info) && $apply_info[ 'status' ] != -1) {
+ return $this->error('', '已经申请过,请不要重复申请');
+ }
+
+ // 分销商基础设置
+ $config = new Config();
+ $basics_config = $config->getFenxiaoBasicsConfig($site_id)[ 'data' ][ 'value' ];
+
+ if (!$basics_config[ 'level' ]) return $this->error('', '未开启分销');
+
+ //获取分销配置信息
+ $fenxiao_config = $config->getFenxiaoConfig($site_id)[ 'data' ][ 'value' ];
+
+ //获取用户信息
+ $member_model = new Member();
+ $member_field = 'source_member,fenxiao_id,nickname,headimg,reg_time,order_money,order_complete_money,order_num,order_complete_num';
+ $member_info = $member_model->getMemberInfo([ [ 'member_id', '=', $member_id ] ], $member_field);
+
+ // 判断用户是否可以成为申请分销商
+ if ($fenxiao_config[ 'fenxiao_condition' ] == 2) {
+ if ($fenxiao_config[ 'consume_condition' ] == 1 && $fenxiao_config[ 'consume_count' ] > $member_info[ 'data' ][ 'order_num' ]) {
+ return $this->error('', '您的消费次数未满足申请条件');
+ } elseif ($fenxiao_config[ 'consume_condition' ] == 2 && $fenxiao_config[ 'consume_count' ] > $member_info[ 'data' ][ 'order_complete_num' ]) {
+ return $this->error('', '您的消费次数未满足申请条件');
+ }
+ } elseif ($fenxiao_config[ 'fenxiao_condition' ] == 3) {
+ if ($fenxiao_config[ 'consume_condition' ] == 1 && $fenxiao_config[ 'consume_money' ] > $member_info[ 'data' ][ 'order_money' ]) {
+ return $this->error('', '您的消费金额未满足申请条件');
+ } elseif ($fenxiao_config[ 'consume_condition' ] == 2 && $fenxiao_config[ 'consume_money' ] > $member_info[ 'data' ][ 'order_complete_money' ]) {
+ return $this->error('', '您的消费金额未满足申请条件');
+ }
+ } elseif ($fenxiao_config[ 'fenxiao_condition' ] == 4) { //购买指定商品
+ //获取用户购买商品是否在成为分销商指定商品区域
+ $alias = 'og';
+ $condition[] = [ 'og.member_id', '=', $member_id ];
+ $condition[] = [ 'og.site_id', '=', $site_id ];
+ $condition[] = [ 'og.goods_id', 'in', $fenxiao_config[ 'goods_ids' ] ];
+ $field = 'o.order_status,og.goods_id';
+ $join = [
+ [
+ 'order o',
+ 'o.order_id = og.order_id',
+ 'inner'
+ ],
+
+ ];
+ if ($fenxiao_config[ 'consume_condition' ] == 1) {
+ $condition[] = [ 'o.pay_status', '=', 1 ];
+ $order_data = model('order_goods')->getList($condition, $field, '', $alias, $join);
+ if (empty($order_data)) {
+ return $this->error('', '您还未满足申请条件');
+ }
+ } elseif ($fenxiao_config[ 'consume_condition' ] == 2) {
+ $condition[] = [ 'o.order_status', '=', '10' ];
+ $order_data = model('order_goods')->getList($condition, $field, '', $alias, $join);
+ if (empty($order_data)) {
+ return $this->error('', '您还未满足申请条件');
+ }
+ }
+
+ }
+
+ if (empty($fenxiao_name)) $fenxiao_name = $member_info[ 'data' ][ 'nickname' ];
+
+ //获取分销等级信息
+ $level_model = new FenxiaoLevel();
+ $level_info = $level_model->getLevelInfo([ [ 'site_id', '=', $site_id ], [ 'is_default', '=', 1 ] ], 'level_id,level_name');
+
+ // 成为分销商是否需要审核
+ if ($basics_config[ 'is_examine' ]) {
+ $apply_data = [
+ 'site_id' => $site_id,
+ 'fenxiao_name' => $fenxiao_name,
+ 'parent' => $member_info[ 'data' ][ 'fenxiao_id' ],
+ 'member_id' => $member_id,
+ 'mobile' => $mobile,
+ 'nickname' => $member_info[ 'data' ][ 'nickname' ],
+ 'headimg' => $member_info[ 'data' ][ 'headimg' ],
+ 'level_id' => $level_info[ 'data' ][ 'level_id' ],
+ 'level_name' => $level_info[ 'data' ][ 'level_name' ],
+ 'order_complete_money' => $member_info[ 'data' ][ 'order_complete_money' ],
+ 'order_complete_num' => $member_info[ 'data' ][ 'order_complete_num' ],
+ 'reg_time' => $member_info[ 'data' ][ 'reg_time' ],
+ 'create_time' => time(),
+ 'status' => 1
+ ];
+ if (!empty($apply_info)) {
+ $res = model('fenxiao_apply')->update($apply_data, [ [ 'member_id', '=', $member_id ] ]);
+ } else {
+ $res = model('fenxiao_apply')->add($apply_data);
+ }
+ return $this->success($res);
+ } else {
+ $fenxiao_data = [
+ 'site_id' => $site_id,
+ 'fenxiao_name' => $fenxiao_name,
+ 'mobile' => $mobile,
+ 'member_id' => $member_id,
+ 'parent' => $member_info[ 'data' ][ 'fenxiao_id' ],
+ 'level_id' => $level_info[ 'data' ][ 'level_id' ],
+ 'level_name' => $level_info[ 'data' ][ 'level_name' ]
+ ];
+ $fenxiao_model = new Fenxiao();
+ $res = $fenxiao_model->addFenxiao($fenxiao_data);
+ return $res;
+ }
+ }
+
+ /**
+ * 管理员添加分销商
+ */
+ public function addFenxiao($fenxiao_data)
+ {
+ if (empty($fenxiao_data[ 'fenxiao_name' ])) {
+ return $this->error('', '分销商名称不能为空');
+ }
+ if (empty($fenxiao_data[ 'level_id' ])) {
+ return $this->error('', '请选择分销商等级');
+ }
+ if (empty($fenxiao_data[ 'member_id' ])) {
+ return $this->error('', '请选择关联会员');
+ }
+
+ //判断该用户是否已经申请
+ $apply_info = model('fenxiao_apply')->getInfo([ [ 'member_id', '=', $fenxiao_data[ 'member_id' ] ] ], 'apply_id,status');
+ if (!empty($apply_info) && $apply_info[ 'status' ] != -1) {
+ return $this->error('', '已经申请过,请不要重复申请');
+ }
+
+ // 分销商基础设置
+ $config = new Config();
+ //获取分销配置信息
+ $fenxiao_config = $config->getFenxiaoConfig($fenxiao_data[ 'site_id' ])[ 'data' ][ 'value' ];
+
+ //获取用户信息
+ $member_model = new Member();
+ $member_field = 'source_member,fenxiao_id,nickname,headimg,reg_time,order_money,order_complete_money,order_num,order_complete_num';
+ $member_info = $member_model->getMemberInfo([ [ 'member_id', '=', $fenxiao_data[ 'member_id' ] ] ], $member_field);
+ if (empty($member_info)) return $this->error('', '未获取到会员信息');
+
+ //获取分销等级信息
+ $level_model = new FenxiaoLevel();
+ $level_info = $level_model->getLevelInfo([ [ 'site_id', '=', $fenxiao_data[ 'site_id' ] ], [ 'level_id', '=', $fenxiao_data[ 'level_id' ] ] ], 'level_name');
+ $fenxiao_data[ 'level_name' ] = $level_info[ 'data' ][ 'level_name' ];
+
+ $fenxiao_model = new Fenxiao();
+ return $fenxiao_model->addFenxiao($fenxiao_data);
+
+ }
+
+ /**
+ * 审核通过
+ * @param $apply_id
+ * @param $site_id
+ * @return array|mixed
+ */
+ public function pass($apply_id, $site_id)
+ {
+ $info = model('fenxiao_apply')->getInfo([ [ 'apply_id', '=', $apply_id ], [ 'site_id', '=', $site_id ] ]);
+ if ($info[ 'status' ] == 2) {
+ return $this->success();
+ }
+
+ model('fenxiao_apply')->startTrans();
+ try {
+ $data = [
+ 'status' => 2,
+ 'update_time' => time(),
+ ];
+ $res = model('fenxiao_apply')->update($data, [ [ 'apply_id', '=', $apply_id ], [ 'site_id', '=', $site_id ] ]);
+
+ $fenxiao_data = [
+ 'site_id' => $info[ 'site_id' ],
+ 'fenxiao_name' => $info[ 'fenxiao_name' ],
+ 'mobile' => $info[ 'mobile' ],
+ 'member_id' => $info[ 'member_id' ],
+ 'parent' => $info[ 'parent' ],
+ 'level_id' => $info[ 'level_id' ],
+ 'level_name' => $info[ 'level_name' ]
+ ];
+
+ $fenxiao_model = new Fenxiao();
+ $result = $fenxiao_model->addFenxiao($fenxiao_data);
+ if ($result[ 'code' ] != 0) {
+ model('fenxiao_apply')->rollback();
+ return $result;
+ }
+
+ model('fenxiao_apply')->commit();
+
+ return $this->success($res);
+ } catch (\Exception $e) {
+ model('fenxiao_apply')->rollback();
+ return $this->error('', $e->getMessage());
+ }
+
+ }
+
+ /**
+ * 审核不通过
+ * @param $apply_id
+ * @return array
+ */
+ public function refuse($apply_id)
+ {
+ $data = [
+ 'status' => -1,
+ 'update_time' => time()
+ ];
+
+ $res = model('fenxiao_apply')->update($data, [ [ 'apply_id', '=', $apply_id ] ]);
+ return $this->success($res);
+ }
+
+ /**
+ * 获取分销商申请信息
+ * @param array $condition
+ * @param string $field
+ * @return array
+ */
+ public function getFenxiaoApplyInfo($condition = [], $field = '*')
+ {
+ $res = model('fenxiao_apply')->getInfo($condition, $field);
+ return $this->success($res);
+ }
+
+ /**
+ * 获取分销商申请分页列表
+ * @param array $condition
+ * @param int $page
+ * @param int $page_size
+ * @param string $order
+ * @param string $field
+ * @param string $alias
+ * @param array $join
+ * @return array
+ */
+ public function getFenxiaoApplyPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*', $alias = 'a', $join = [])
+ {
+ $list = model('fenxiao_apply')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
+ return $this->success($list);
+ }
+
+ /**
+ * 获取分销商申请数量
+ * @param array $condition
+ * @param string $field
+ * @return array
+ */
+ public function getFenxiaoApplyCount($condition = [], $field = 'id')
+ {
+ $count = model('fenxiao_apply')->getCount($condition, $field);
+ return $this->success($count);
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/model/FenxiaoData.php b/src/addon/fenxiao/model/FenxiaoData.php
index abda0b95f..c3aea81e0 100644
--- a/src/addon/fenxiao/model/FenxiaoData.php
+++ b/src/addon/fenxiao/model/FenxiaoData.php
@@ -1,82 +1,74 @@
-getInfo([ [ 'status', 'in', '1,-1' ], [ 'site_id', '=', $site_id ], [ 'is_delete', '=', 0 ] ], $field);
-
- if (empty($res) || $res[ 'account' ] == null) {
- $res[ 'account' ] = '0.00';
- }
-
- if (empty($res) || $res[ 'account_withdraw' ] == null) {
- $res[ 'account_withdraw' ] = '0.00';
- }
- if (empty($res) || $res[ 'account_withdraw_apply' ] == null) {
- $res[ 'account_withdraw_apply' ] = '0.00';
- }
-
- return $res;
- }
-
- /**
- * 获取分销商申请人数
- * @param $site_id
- * @return int|mixed
- */
- public function getFenxiaoApplyCount($site_id)
- {
- $count = model('fenxiao_apply')->getCount([ [ 'status', '=', 1 ], [ 'site_id', '=', $site_id ] ]);
- return $count;
- }
-
- /**
- * 获取分销商人数
- * @param $site_id
- * @return int|mixed
- */
- public function getFenxiaoCount($site_id)
- {
- $count = model('fenxiao')->getCount([ [ 'site_id', '=', $site_id ], [ 'is_delete', '=', 0 ] ]);
- return $count;
- }
-
- /**
- * 统计分销订单总金额
- * @param $site_id
- * @return mixed
- */
- public function getFenxiaoOrderSum($site_id)
- {
- $field = 'sum(real_goods_money) as real_goods_money';
- $res = model('fenxiao_order')->getInfo([ [ 'site_id', '=', $site_id ] ], $field);
- if ($res[ 'real_goods_money' ] == null) {
- $res[ 'real_goods_money' ] = '0.00';
- }
- return $res;
- }
+getInfo([ [ 'status', 'in', '1,-1' ], [ 'site_id', '=', $site_id ], [ 'is_delete', '=', 0 ] ], $field);
+
+ if (empty($res) || $res[ 'account' ] == null) {
+ $res[ 'account' ] = '0.00';
+ }
+
+ if (empty($res) || $res[ 'account_withdraw' ] == null) {
+ $res[ 'account_withdraw' ] = '0.00';
+ }
+ if (empty($res) || $res[ 'account_withdraw_apply' ] == null) {
+ $res[ 'account_withdraw_apply' ] = '0.00';
+ }
+
+ return $res;
+ }
+
+ /**
+ * 获取分销商申请人数
+ * @param $site_id
+ * @return int|mixed
+ */
+ public function getFenxiaoApplyCount($site_id)
+ {
+ $count = model('fenxiao_apply')->getCount([ [ 'status', '=', 1 ], [ 'site_id', '=', $site_id ] ]);
+ return $count;
+ }
+
+ /**
+ * 获取分销商人数
+ * @param $site_id
+ * @return int|mixed
+ */
+ public function getFenxiaoCount($site_id)
+ {
+ $count = model('fenxiao')->getCount([ [ 'site_id', '=', $site_id ], [ 'is_delete', '=', 0 ] ]);
+ return $count;
+ }
+
+ /**
+ * 统计分销订单总金额
+ * @param $site_id
+ * @return mixed
+ */
+ public function getFenxiaoOrderSum($site_id)
+ {
+ $field = 'sum(real_goods_money) as real_goods_money';
+ $res = model('fenxiao_order')->getInfo([ [ 'site_id', '=', $site_id ] ], $field);
+ if ($res[ 'real_goods_money' ] == null) {
+ $res[ 'real_goods_money' ] = '0.00';
+ }
+ return $res;
+ }
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/model/FenxiaoGoods.php b/src/addon/fenxiao/model/FenxiaoGoods.php
index 4eb221192..2881c3a52 100644
--- a/src/addon/fenxiao/model/FenxiaoGoods.php
+++ b/src/addon/fenxiao/model/FenxiaoGoods.php
@@ -1,195 +1,187 @@
-update($data, $condition);
- return $this->success($re);
- }
-
- /**
- * 修改分销状态
- * @param $goods_id
- * @param $is_fenxiao
- * @param $site_id
- * @return array
- */
- public function modifyGoodsFenxiaoStatus($goods_id, $is_fenxiao, $site_id)
- {
- $fenxiao_goods_skus = model('fenxiao_goods_sku')->getList([ [ 'goods_id', '=', $goods_id ] ]);
- model('goods')->startTrans();
- try {
- if (empty($fenxiao_goods_skus)) {
- $level_list = model('fenxiao_level')->getList([ [ 'site_id', '=', $site_id ], [ 'status', '=', 1 ] ]);
- $goods_model = new GoodsModel();
- $goods_info = $goods_model->getGoodsDetail($goods_id);
- $fenxiao_goods_sku_data = [];
- foreach ($level_list as $level) {
- foreach ($goods_info[ 'data' ][ 'sku_data' ] as $sku) {
- $fenxiao_sku = [
- 'goods_id' => $goods_id,
- 'level_id' => $level[ 'level_id' ],
- 'sku_id' => $sku[ 'sku_id' ],
- 'one_rate' => $level[ 'one_rate' ],
- 'one_money' => 0,
- 'two_rate' => $level[ 'two_rate' ],
- 'two_money' => 0,
- 'three_rate' => $level[ 'three_rate' ],
- 'three_money' => 0,
- ];
- $fenxiao_goods_sku_data[] = $fenxiao_sku;
- }
- }
- model('fenxiao_goods_sku')->addList($fenxiao_goods_sku_data);
- }
-
- model('goods')->update([ 'is_fenxiao' => $is_fenxiao ], [ [ 'goods_id', '=', $goods_id ], [ 'site_id', '=', $site_id ] ]);
- model('goods')->commit();
- return $this->success(1);
- } catch (\Exception $e) {
- model('goods')->rollback();
- return $this->error($e->getMessage());
- }
- }
-
- /**
- * 取消参与分销
- * @param $goods_ids
- * @param $site_id
- * @return array
- */
- public function modifyGoodsIsFenxiao($goods_ids, $is_fenxiao, $site_id)
- {
- $res = model('goods')->update([ 'is_fenxiao' => $is_fenxiao ], [ [ 'goods_id', 'in', $goods_ids ], [ 'site_id', '=', $site_id ] ]);
- return $this->success($res);
- }
-
- /**
- * 查询商品分销详情
- * @param $goods_sku_detail_array
- */
- public function getGoodsFenxiaoDetailInApi($goods_sku_detail_array, $member_id, $site_id)
- {
- $config = new Config();
- $words_config = $config->getFenxiaoWordsConfig($site_id)[ 'data' ][ 'value' ];
- $basic_config = $config->getFenxiaoBasicsConfig($site_id)[ 'data' ][ 'value' ];
- $data = [
- 'words_account' => $words_config[ 'account' ],
- 'commission_money' => 0.00,
- 'is_commission_money' => $basic_config[ 'is_commission_money' ],
- ];
-
- $goods_sku_detail_array[ 'goods_sku_detail' ][ 'fenxiao_detail' ] = $data;
- //检测当前用户是否是分销商以及分销商等级
- $member_info = $goods_sku_detail_array[ 'member_info' ];
- $goods_sku_detail = $goods_sku_detail_array[ 'goods_sku_detail' ];
- if ($member_info[ 'is_fenxiao' ] == 0 || $goods_sku_detail[ 'is_fenxiao' ] == 0) {
-
- return $goods_sku_detail_array;
- }
- //查询分销商等级
- $fenxiao_model = new FenxiaoModel();
- $fenxiao_info = $fenxiao_model->getFenxiaoInfo([ [ 'member_id', '=', $member_id ] ], 'fenxiao_id,level_id')[ 'data' ];
- if (empty($fenxiao_info)) return $goods_sku_detail_array;
- $discount_price = $goods_sku_detail[ 'fenxiao_price' ] > 0 ? $goods_sku_detail[ 'fenxiao_price' ] : $goods_sku_detail[ 'discount_price' ];
- if ($goods_sku_detail[ 'fenxiao_type' ] == 1) {
- $fenxiao_level = new FenxiaoLevel();
- $level_info = $fenxiao_level->getLevelInfo([ [ 'level_id', '=', $fenxiao_info[ 'level_id' ] ] ], 'one_rate')[ 'data' ];
- if (!empty($level_info)) {
- $data[ 'commission_money' ] = number_format($discount_price * $level_info[ 'one_rate' ] / 100, 2, '.', '');
- }
- } else {
- $fenxiao_sku_info = model('fenxiao_goods_sku')->getInfo([ [ 'level_id', '=', $fenxiao_info[ 'level_id' ] ], [ 'sku_id', '=', $goods_sku_detail[ 'sku_id' ] ] ], 'one_money, one_rate');
- if (!empty($fenxiao_sku_info)) {
- $data[ 'commission_money' ] = $fenxiao_sku_info[ 'one_money' ];
- if ($fenxiao_sku_info[ 'one_rate' ] > 0) {
- $data[ 'commission_money' ] = number_format($discount_price * $fenxiao_sku_info[ 'one_rate' ] / 100, 2, '.', '');
- }
- }
- }
- $goods_sku_detail_array[ 'goods_sku_detail' ][ 'fenxiao_detail' ] = $data;
- return $goods_sku_detail_array;
- }
-
- /**
- * 查询商品规格列表分销信息
- * @param $goods_sku_list
- * @param $member_id
- * @param $site_id
- * @return mixed
- */
- public function getGoodsSkuListFenxiaoInApi($goods_sku_list, $member_id, $site_id)
- {
- $config = new Config();
- $words_config = $config->getFenxiaoWordsConfig($site_id)[ 'data' ][ 'value' ];
- $data = [
- 'words_account' => $words_config[ 'account' ],
- 'commission_money' => 0.00
- ];
- //组装数据
- foreach ($goods_sku_list as $k => $v) {
- $goods_sku_list[ $k ][ 'fenxiao_detail' ] = $data;
- }
- //检测当前用户是否是分销商以及分销商等级
- $goods_sku_info = $goods_sku_list[ 0 ];
- $member_info = $goods_sku_list[ 0 ][ 'member_info' ];
- if ($member_info[ 'is_fenxiao' ] == 0 || $goods_sku_info[ 'is_fenxiao' ] == 0) {
- return $goods_sku_list;
- }
- //查询分销商等级
- $fenxiao_model = new FenxiaoModel();
- $fenxiao_info = $fenxiao_model->getFenxiaoInfo([ [ 'member_id', '=', $member_id ] ], 'fenxiao_id,level_id')[ 'data' ];
- if (empty($fenxiao_info)) return $goods_sku_list;
-
- if ($goods_sku_info[ 'fenxiao_type' ] == 1) {
- $fenxiao_level = new FenxiaoLevel();
- $level_info = $fenxiao_level->getLevelInfo([ [ 'level_id', '=', $fenxiao_info[ 'level_id' ] ] ], 'one_rate')[ 'data' ];
- if (!empty($level_info)) {
- foreach ($goods_sku_list as $k => $v) {
- $discount_price = $v[ 'fenxiao_price' ] > 0 ? $v[ 'fenxiao_price' ] : $v[ 'discount_price' ];
- $goods_sku_list[ $k ][ 'fenxiao_detail' ][ 'commission_money' ] = number_format($discount_price * $level_info[ 'one_rate' ] / 100, 2, '.', '');
- }
- }
- } else {
- $fenxiao_sku_list = model('fenxiao_goods_sku')->getList([ [ 'level_id', '=', $fenxiao_info[ 'level_id' ] ], [ 'goods_id', '=', $goods_sku_info[ 'goods_id' ] ] ], 'sku_id, one_money, one_rate');
- $fenxiao_sku_list = array_column($fenxiao_sku_list, null, 'sku_id');
- foreach ($goods_sku_list as $k => $v) {
- $fenxiao_sku_info = $fenxiao_sku_list[ $v[ 'sku_id' ] ] ?? [];
- if (!empty($fenxiao_sku_info)) {
- $discount_price = $v[ 'fenxiao_price' ] > 0 ? $v[ 'fenxiao_price' ] : $v[ 'discount_price' ];
- $goods_sku_list[ $k ][ 'fenxiao_detail' ][ 'commission_money' ] = $fenxiao_sku_info[ 'one_money' ];
- if ($fenxiao_sku_info[ 'one_rate' ] > 0) {
- $goods_sku_list[ $k ][ 'fenxiao_detail' ][ 'commission_money' ] = number_format($discount_price * $fenxiao_sku_info[ 'one_rate' ] / 100, 2, '.', '');
- }
- }
- }
-
- }
- return $goods_sku_list;
- }
+update($data, $condition);
+ return $this->success($re);
+ }
+
+ /**
+ * 修改分销状态
+ * @param $goods_id
+ * @param $is_fenxiao
+ * @param $site_id
+ * @return array
+ */
+ public function modifyGoodsFenxiaoStatus($goods_id, $is_fenxiao, $site_id)
+ {
+ $fenxiao_goods_skus = model('fenxiao_goods_sku')->getList([ [ 'goods_id', '=', $goods_id ] ]);
+ model('goods')->startTrans();
+ try {
+ if (empty($fenxiao_goods_skus)) {
+ $level_list = model('fenxiao_level')->getList([ [ 'site_id', '=', $site_id ], [ 'status', '=', 1 ] ]);
+ $goods_model = new GoodsModel();
+ $goods_info = $goods_model->getGoodsDetail($goods_id);
+ $fenxiao_goods_sku_data = [];
+ foreach ($level_list as $level) {
+ foreach ($goods_info[ 'data' ][ 'sku_data' ] as $sku) {
+ $fenxiao_sku = [
+ 'goods_id' => $goods_id,
+ 'level_id' => $level[ 'level_id' ],
+ 'sku_id' => $sku[ 'sku_id' ],
+ 'one_rate' => $level[ 'one_rate' ],
+ 'one_money' => 0,
+ 'two_rate' => $level[ 'two_rate' ],
+ 'two_money' => 0,
+ 'three_rate' => $level[ 'three_rate' ],
+ 'three_money' => 0,
+ ];
+ $fenxiao_goods_sku_data[] = $fenxiao_sku;
+ }
+ }
+ model('fenxiao_goods_sku')->addList($fenxiao_goods_sku_data);
+ }
+
+ model('goods')->update([ 'is_fenxiao' => $is_fenxiao ], [ [ 'goods_id', '=', $goods_id ], [ 'site_id', '=', $site_id ] ]);
+ model('goods')->commit();
+ return $this->success(1);
+ } catch (\Exception $e) {
+ model('goods')->rollback();
+ return $this->error($e->getMessage());
+ }
+ }
+
+ /**
+ * 取消参与分销
+ * @param $goods_ids
+ * @param $site_id
+ * @return array
+ */
+ public function modifyGoodsIsFenxiao($goods_ids, $is_fenxiao, $site_id)
+ {
+ $res = model('goods')->update([ 'is_fenxiao' => $is_fenxiao ], [ [ 'goods_id', 'in', $goods_ids ], [ 'site_id', '=', $site_id ] ]);
+ return $this->success($res);
+ }
+
+ /**
+ * 查询商品分销详情
+ * @param $goods_sku_detail_array
+ */
+ public function getGoodsFenxiaoDetailInApi($goods_sku_detail_array, $member_id, $site_id)
+ {
+ $config = new Config();
+ $words_config = $config->getFenxiaoWordsConfig($site_id)[ 'data' ][ 'value' ];
+ $basic_config = $config->getFenxiaoBasicsConfig($site_id)[ 'data' ][ 'value' ];
+ $data = [
+ 'words_account' => $words_config[ 'account' ],
+ 'commission_money' => 0.00,
+ 'is_commission_money' => $basic_config[ 'is_commission_money' ],
+ ];
+
+ $goods_sku_detail_array[ 'goods_sku_detail' ][ 'fenxiao_detail' ] = $data;
+ //检测当前用户是否是分销商以及分销商等级
+ $member_info = $goods_sku_detail_array[ 'member_info' ];
+ $goods_sku_detail = $goods_sku_detail_array[ 'goods_sku_detail' ];
+ if ($member_info[ 'is_fenxiao' ] == 0 || $goods_sku_detail[ 'is_fenxiao' ] == 0) {
+
+ return $goods_sku_detail_array;
+ }
+ //查询分销商等级
+ $fenxiao_model = new FenxiaoModel();
+ $fenxiao_info = $fenxiao_model->getFenxiaoInfo([ [ 'member_id', '=', $member_id ] ], 'fenxiao_id,level_id')[ 'data' ];
+ if (empty($fenxiao_info)) return $goods_sku_detail_array;
+ $discount_price = $goods_sku_detail[ 'fenxiao_price' ] > 0 ? $goods_sku_detail[ 'fenxiao_price' ] : $goods_sku_detail[ 'discount_price' ];
+ if ($goods_sku_detail[ 'fenxiao_type' ] == 1) {
+ $fenxiao_level = new FenxiaoLevel();
+ $level_info = $fenxiao_level->getLevelInfo([ [ 'level_id', '=', $fenxiao_info[ 'level_id' ] ] ], 'one_rate')[ 'data' ];
+ if (!empty($level_info)) {
+ $data[ 'commission_money' ] = number_format($discount_price * $level_info[ 'one_rate' ] / 100, 2, '.', '');
+ }
+ } else {
+ $fenxiao_sku_info = model('fenxiao_goods_sku')->getInfo([ [ 'level_id', '=', $fenxiao_info[ 'level_id' ] ], [ 'sku_id', '=', $goods_sku_detail[ 'sku_id' ] ] ], 'one_money, one_rate');
+ if (!empty($fenxiao_sku_info)) {
+ $data[ 'commission_money' ] = $fenxiao_sku_info[ 'one_money' ];
+ if ($fenxiao_sku_info[ 'one_rate' ] > 0) {
+ $data[ 'commission_money' ] = number_format($discount_price * $fenxiao_sku_info[ 'one_rate' ] / 100, 2, '.', '');
+ }
+ }
+ }
+ $goods_sku_detail_array[ 'goods_sku_detail' ][ 'fenxiao_detail' ] = $data;
+ return $goods_sku_detail_array;
+ }
+
+ /**
+ * 查询商品规格列表分销信息
+ * @param $goods_sku_list
+ * @param $member_id
+ * @param $site_id
+ * @return mixed
+ */
+ public function getGoodsSkuListFenxiaoInApi($goods_sku_list, $member_id, $site_id)
+ {
+ $config = new Config();
+ $words_config = $config->getFenxiaoWordsConfig($site_id)[ 'data' ][ 'value' ];
+ $data = [
+ 'words_account' => $words_config[ 'account' ],
+ 'commission_money' => 0.00
+ ];
+ //组装数据
+ foreach ($goods_sku_list as $k => $v) {
+ $goods_sku_list[ $k ][ 'fenxiao_detail' ] = $data;
+ }
+ //检测当前用户是否是分销商以及分销商等级
+ $goods_sku_info = $goods_sku_list[ 0 ];
+ $member_info = $goods_sku_list[ 0 ][ 'member_info' ];
+ if ($member_info[ 'is_fenxiao' ] == 0 || $goods_sku_info[ 'is_fenxiao' ] == 0) {
+ return $goods_sku_list;
+ }
+ //查询分销商等级
+ $fenxiao_model = new FenxiaoModel();
+ $fenxiao_info = $fenxiao_model->getFenxiaoInfo([ [ 'member_id', '=', $member_id ] ], 'fenxiao_id,level_id')[ 'data' ];
+ if (empty($fenxiao_info)) return $goods_sku_list;
+
+ if ($goods_sku_info[ 'fenxiao_type' ] == 1) {
+ $fenxiao_level = new FenxiaoLevel();
+ $level_info = $fenxiao_level->getLevelInfo([ [ 'level_id', '=', $fenxiao_info[ 'level_id' ] ] ], 'one_rate')[ 'data' ];
+ if (!empty($level_info)) {
+ foreach ($goods_sku_list as $k => $v) {
+ $discount_price = $v[ 'fenxiao_price' ] > 0 ? $v[ 'fenxiao_price' ] : $v[ 'discount_price' ];
+ $goods_sku_list[ $k ][ 'fenxiao_detail' ][ 'commission_money' ] = number_format($discount_price * $level_info[ 'one_rate' ] / 100, 2, '.', '');
+ }
+ }
+ } else {
+ $fenxiao_sku_list = model('fenxiao_goods_sku')->getList([ [ 'level_id', '=', $fenxiao_info[ 'level_id' ] ], [ 'goods_id', '=', $goods_sku_info[ 'goods_id' ] ] ], 'sku_id, one_money, one_rate');
+ $fenxiao_sku_list = array_column($fenxiao_sku_list, null, 'sku_id');
+ foreach ($goods_sku_list as $k => $v) {
+ $fenxiao_sku_info = $fenxiao_sku_list[ $v[ 'sku_id' ] ] ?? [];
+ if (!empty($fenxiao_sku_info)) {
+ $discount_price = $v[ 'fenxiao_price' ] > 0 ? $v[ 'fenxiao_price' ] : $v[ 'discount_price' ];
+ $goods_sku_list[ $k ][ 'fenxiao_detail' ][ 'commission_money' ] = $fenxiao_sku_info[ 'one_money' ];
+ if ($fenxiao_sku_info[ 'one_rate' ] > 0) {
+ $goods_sku_list[ $k ][ 'fenxiao_detail' ][ 'commission_money' ] = number_format($discount_price * $fenxiao_sku_info[ 'one_rate' ] / 100, 2, '.', '');
+ }
+ }
+ }
+
+ }
+ return $goods_sku_list;
+ }
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/model/FenxiaoGoodsCollect.php b/src/addon/fenxiao/model/FenxiaoGoodsCollect.php
index b48827148..f4ad8183f 100644
--- a/src/addon/fenxiao/model/FenxiaoGoodsCollect.php
+++ b/src/addon/fenxiao/model/FenxiaoGoodsCollect.php
@@ -1,83 +1,75 @@
-getCount([ [ 'member_id', '=', $data[ 'member_id' ] ], [ 'goods_id', '=', $data[ 'goods_id' ] ] ]);
- if (empty($res)) {
- $data[ 'create_time' ] = time();
- $collect_id = model('fenxiao_goods_collect')->add($data);
- return $this->success($collect_id);
- } else {
- return $this->error('', 'GOODS_COLLECT_IS_EXIST');
- }
- }
-
- /**
- * 删除分销商关注商品
- * @param array $condition
- * @return array
- */
- public function deleteCollect($condition = [])
- {
- $res = model('fenxiao_goods_collect')->delete($condition);
- return $this->success($res);
- }
-
- /**
- * 获取分销商关注商品数信息
- * @param $condition
- * @param $field
- * @return array
- */
- public function getCollectInfo($condition, $field = '*')
- {
- $res = model('fenxiao_goods_collect')->getInfo($condition, $field);
- return $this->success($res);
- }
-
- /**
- * 获取分销商关注商品分页列表
- * @param array $condition
- * @param int $page
- * @param int $page_size
- * @param string $order
- * @param string $field
- * @param string $order
- * @return array
- */
- public function getCollectPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'fgc.create_time desc', $field = 'fgc.collect_id,fgc.member_id,fgc.fenxiao_id,fgc.create_time,gs.sku_id,gs.sku_name,gs.discount_price,gs.stock,gs.sale_num,gs.sku_image,gs.site_id,gs.fenxiao_price,g.goods_image,g.fenxiao_type')
- {
- $alias = 'fgc';
- $join = [
- [ 'goods_sku gs', 'fgc.sku_id = gs.sku_id', 'inner' ],
- [ 'goods g', 'fgc.goods_id = g.goods_id', 'inner' ]
- ];
-
- $list = model('fenxiao_goods_collect')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
- return $this->success($list);
- }
-
+getCount([ [ 'member_id', '=', $data[ 'member_id' ] ], [ 'goods_id', '=', $data[ 'goods_id' ] ] ]);
+ if (empty($res)) {
+ $data[ 'create_time' ] = time();
+ $collect_id = model('fenxiao_goods_collect')->add($data);
+ return $this->success($collect_id);
+ } else {
+ return $this->error('', 'GOODS_COLLECT_IS_EXIST');
+ }
+ }
+
+ /**
+ * 删除分销商关注商品
+ * @param array $condition
+ * @return array
+ */
+ public function deleteCollect($condition = [])
+ {
+ $res = model('fenxiao_goods_collect')->delete($condition);
+ return $this->success($res);
+ }
+
+ /**
+ * 获取分销商关注商品数信息
+ * @param $condition
+ * @param $field
+ * @return array
+ */
+ public function getCollectInfo($condition, $field = '*')
+ {
+ $res = model('fenxiao_goods_collect')->getInfo($condition, $field);
+ return $this->success($res);
+ }
+
+ /**
+ * 获取分销商关注商品分页列表
+ * @param array $condition
+ * @param int $page
+ * @param int $page_size
+ * @param string $order
+ * @param string $field
+ * @param string $order
+ * @return array
+ */
+ public function getCollectPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'fgc.create_time desc', $field = 'fgc.collect_id,fgc.member_id,fgc.fenxiao_id,fgc.create_time,gs.sku_id,gs.sku_name,gs.discount_price,gs.stock,gs.sale_num,gs.sku_image,gs.site_id,gs.fenxiao_price,g.goods_image,g.fenxiao_type')
+ {
+ $alias = 'fgc';
+ $join = [
+ [ 'goods_sku gs', 'fgc.sku_id = gs.sku_id', 'inner' ],
+ [ 'goods g', 'fgc.goods_id = g.goods_id', 'inner' ]
+ ];
+
+ $list = model('fenxiao_goods_collect')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
+ return $this->success($list);
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/model/FenxiaoGoodsSku.php b/src/addon/fenxiao/model/FenxiaoGoodsSku.php
index 65547968c..92327f262 100644
--- a/src/addon/fenxiao/model/FenxiaoGoodsSku.php
+++ b/src/addon/fenxiao/model/FenxiaoGoodsSku.php
@@ -1,189 +1,181 @@
-add($data);
- return $this->success($res);
- }
-
- /**
- * 编辑分销商品
- * @param $data
- * @param array $condition
- * @return array
- */
- public function editSku($data, $condition = [])
- {
- $data[ 'update_time' ] = time();
- $res = model('fenxiao_goods_sku')->update($data, $condition);
- return $this->success($res);
- }
-
-
- /**
- * 删除分销商品
- * @param array $condition
- * @return array
- */
- public function deleteSku($condition = [])
- {
- $res = model('fenxiao_goods_sku')->delete($condition);
- return $this->success($res);
- }
-
- /**
- * 获取分销商品详情
- * @param array $condition
- * @param string $field
- * @return array
- */
- public function getFenxiaoGoodsSkuDetail($condition = [], $field = 'fgs.goods_sku_id,fgs.goods_id,fgs.sku_id,fgs.level_id,fgs.one_rate,fgs.one_money,fgs.two_rate,fgs.two_money,fgs.three_rate,fgs.three_money,gs.discount_price,gs.fenxiao_price')
- {
- $alias = 'fgs';
- $join = [
- [ 'goods_sku gs', 'fgs.sku_id = gs.sku_id', 'inner' ],
- [ 'goods g', 'g.goods_id = gs.goods_id', 'inner' ]
- ];
- $list = model('fenxiao_goods_sku')->getInfo($condition, $field, $alias, $join);
- return $this->success($list);
- }
-
- /**
- * 获取分销sku列表
- * @param array $condition
- * @param string $field
- * @param string $order
- * @param null $limit
- * @return array
- */
- public function getSkuList($condition = [], $field = '*', $order = '', $limit = null)
- {
- $list = model('fenxiao_goods_sku')->getList($condition, $field, $order, '', '', '', $limit);
- return $this->success($list);
- }
-
- /**
- * 获取分销商品分页列表
- * @param array $condition
- * @param int $page
- * @param int $page_size
- * @param string $order
- * @param string $field
- * @param string $order
- * @return array
- */
- public function getFenxiaoGoodsSkuPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'g.create_time desc', $field = 'g.goods_id,g.label_name,g.goods_name,g.goods_image,g.sku_id,gs.sku_name,gs.discount_price,gs.price,gs.stock,gs.sale_num,gs.sku_image,gs.fenxiao_price,g.fenxiao_type,(g.sale_num + g.virtual_sale) as sale_sort')
- {
- $alias = 'g';
- $join = [
- [ 'goods_sku gs', 'g.sku_id = gs.sku_id', 'inner' ],
- ];
- $res = model('goods')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
- foreach ($res[ 'list' ] as $k => $v) {
- if (isset($v[ 'goods_stock' ])) {
- $res[ 'list' ][ $k ][ 'goods_stock' ] = numberFormat($res[ 'list' ][ $k ][ 'goods_stock' ]);
- }
- if (isset($v[ 'sale_num' ])) {
- $res[ 'list' ][ $k ][ 'sale_num' ] = numberFormat($res[ 'list' ][ $k ][ 'sale_num' ]);
- }
- if (isset($v[ 'virtual_sale' ])) {
- $res[ 'list' ][ $k ][ 'virtual_sale' ] = numberFormat($res[ 'list' ][ $k ][ 'virtual_sale' ]);
- }
- if (isset($v[ 'real_stock' ])) {
- $res[ 'list' ][ $k ][ 'real_stock' ] = numberFormat($res[ 'list' ][ $k ][ 'real_stock' ]);
- }
- if (isset($v[ 'stock' ])) {
- $res[ 'list' ][ $k ][ 'stock' ] = numberFormat($res[ 'list' ][ $k ][ 'stock' ]);
- }
- if (isset($v[ 'sale_sort' ])) {
- $res[ 'list' ][ $k ][ 'sale_sort' ] = numberFormat($res[ 'list' ][ $k ][ 'sale_sort' ]);
- }
- }
- return $this->success($res);
- }
-
- /**
- * 批量添加分销商品
- * @param $data
- * @return array
- */
- public function addSkuList($data)
- {
- $re = model('fenxiao_goods_sku')->addList($data);
- return $this->success($re);
- }
-
- /**
- * 获取分销商品信息
- * @param array $condition
- * @param string $field
- * @return array
- */
- public function getFenxiaoGoodsSkuInfo($condition = [], $field = '*')
- {
- $res = model('fenxiao_goods_sku')->getInfo($condition, $field);
- return $this->success($res);
- }
-
- /**
- * 获取商品一级分销佣金
- * @param $sku_id
- * @param $level_id
- * @return array
- */
- public function getSkuFenxiaoCommission($sku_id, $level_id)
- {
- $commission = 0.00;
-
- $condition = [ [ 'gs.sku_id', '=', $sku_id ], [ 'g.is_fenxiao', '=', 1 ] ];
- $join = [
- [ 'goods g', 'g.goods_id = gs.goods_id', 'inner' ]
- ];
- $sku_info = model('goods_sku')->getInfo($condition, 'g.fenxiao_type,gs.fenxiao_price,gs.discount_price', 'gs', $join);
-
- if (!empty($sku_info)) {
- $discount_price = $sku_info[ 'fenxiao_price' ] > 0 ? $sku_info[ 'fenxiao_price' ] : $sku_info[ 'discount_price' ];
- // 默认规则
- if ($sku_info[ 'fenxiao_type' ] == 1) {
- $fenxiao_level = new FenxiaoLevel();
- $level_info = $fenxiao_level->getLevelInfo([ [ 'level_id', '=', $level_id ] ], 'one_rate')[ 'data' ];
- if (!empty($level_info)) {
- $commission = number_format($discount_price * $level_info[ 'one_rate' ] / 100, 2, '.', '');
- }
- } else {
- $fenxiao_sku_info = $this->getFenxiaoGoodsSkuInfo([ [ 'level_id', '=', $level_id ], [ 'sku_id', '=', $sku_id ] ])[ 'data' ];
- if (!empty($fenxiao_sku_info)) {
- $commission = $fenxiao_sku_info[ 'one_money' ];
- if ($fenxiao_sku_info[ 'one_rate' ] > 0) {
- $commission = number_format($discount_price * $fenxiao_sku_info[ 'one_rate' ] / 100, 2, '.', '');
- }
- }
- }
- }
-
- return $this->success($commission);
- }
+add($data);
+ return $this->success($res);
+ }
+
+ /**
+ * 编辑分销商品
+ * @param $data
+ * @param array $condition
+ * @return array
+ */
+ public function editSku($data, $condition = [])
+ {
+ $data[ 'update_time' ] = time();
+ $res = model('fenxiao_goods_sku')->update($data, $condition);
+ return $this->success($res);
+ }
+
+
+ /**
+ * 删除分销商品
+ * @param array $condition
+ * @return array
+ */
+ public function deleteSku($condition = [])
+ {
+ $res = model('fenxiao_goods_sku')->delete($condition);
+ return $this->success($res);
+ }
+
+ /**
+ * 获取分销商品详情
+ * @param array $condition
+ * @param string $field
+ * @return array
+ */
+ public function getFenxiaoGoodsSkuDetail($condition = [], $field = 'fgs.goods_sku_id,fgs.goods_id,fgs.sku_id,fgs.level_id,fgs.one_rate,fgs.one_money,fgs.two_rate,fgs.two_money,fgs.three_rate,fgs.three_money,gs.discount_price,gs.fenxiao_price')
+ {
+ $alias = 'fgs';
+ $join = [
+ [ 'goods_sku gs', 'fgs.sku_id = gs.sku_id', 'inner' ],
+ [ 'goods g', 'g.goods_id = gs.goods_id', 'inner' ]
+ ];
+ $list = model('fenxiao_goods_sku')->getInfo($condition, $field, $alias, $join);
+ return $this->success($list);
+ }
+
+ /**
+ * 获取分销sku列表
+ * @param array $condition
+ * @param string $field
+ * @param string $order
+ * @param null $limit
+ * @return array
+ */
+ public function getSkuList($condition = [], $field = '*', $order = '', $limit = null)
+ {
+ $list = model('fenxiao_goods_sku')->getList($condition, $field, $order, '', '', '', $limit);
+ return $this->success($list);
+ }
+
+ /**
+ * 获取分销商品分页列表
+ * @param array $condition
+ * @param int $page
+ * @param int $page_size
+ * @param string $order
+ * @param string $field
+ * @param string $order
+ * @return array
+ */
+ public function getFenxiaoGoodsSkuPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'g.create_time desc', $field = 'g.goods_id,g.label_name,g.goods_name,g.goods_image,g.sku_id,gs.sku_name,gs.discount_price,gs.price,gs.stock,gs.sale_num,gs.sku_image,gs.fenxiao_price,g.fenxiao_type,(g.sale_num + g.virtual_sale) as sale_sort')
+ {
+ $alias = 'g';
+ $join = [
+ [ 'goods_sku gs', 'g.sku_id = gs.sku_id', 'inner' ],
+ ];
+ $res = model('goods')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
+ foreach ($res[ 'list' ] as $k => $v) {
+ if (isset($v[ 'goods_stock' ])) {
+ $res[ 'list' ][ $k ][ 'goods_stock' ] = numberFormat($res[ 'list' ][ $k ][ 'goods_stock' ]);
+ }
+ if (isset($v[ 'sale_num' ])) {
+ $res[ 'list' ][ $k ][ 'sale_num' ] = numberFormat($res[ 'list' ][ $k ][ 'sale_num' ]);
+ }
+ if (isset($v[ 'virtual_sale' ])) {
+ $res[ 'list' ][ $k ][ 'virtual_sale' ] = numberFormat($res[ 'list' ][ $k ][ 'virtual_sale' ]);
+ }
+ if (isset($v[ 'real_stock' ])) {
+ $res[ 'list' ][ $k ][ 'real_stock' ] = numberFormat($res[ 'list' ][ $k ][ 'real_stock' ]);
+ }
+ if (isset($v[ 'stock' ])) {
+ $res[ 'list' ][ $k ][ 'stock' ] = numberFormat($res[ 'list' ][ $k ][ 'stock' ]);
+ }
+ if (isset($v[ 'sale_sort' ])) {
+ $res[ 'list' ][ $k ][ 'sale_sort' ] = numberFormat($res[ 'list' ][ $k ][ 'sale_sort' ]);
+ }
+ }
+ return $this->success($res);
+ }
+
+ /**
+ * 批量添加分销商品
+ * @param $data
+ * @return array
+ */
+ public function addSkuList($data)
+ {
+ $re = model('fenxiao_goods_sku')->addList($data);
+ return $this->success($re);
+ }
+
+ /**
+ * 获取分销商品信息
+ * @param array $condition
+ * @param string $field
+ * @return array
+ */
+ public function getFenxiaoGoodsSkuInfo($condition = [], $field = '*')
+ {
+ $res = model('fenxiao_goods_sku')->getInfo($condition, $field);
+ return $this->success($res);
+ }
+
+ /**
+ * 获取商品一级分销佣金
+ * @param $sku_id
+ * @param $level_id
+ * @return array
+ */
+ public function getSkuFenxiaoCommission($sku_id, $level_id)
+ {
+ $commission = 0.00;
+
+ $condition = [ [ 'gs.sku_id', '=', $sku_id ], [ 'g.is_fenxiao', '=', 1 ] ];
+ $join = [
+ [ 'goods g', 'g.goods_id = gs.goods_id', 'inner' ]
+ ];
+ $sku_info = model('goods_sku')->getInfo($condition, 'g.fenxiao_type,gs.fenxiao_price,gs.discount_price', 'gs', $join);
+
+ if (!empty($sku_info)) {
+ $discount_price = $sku_info[ 'fenxiao_price' ] > 0 ? $sku_info[ 'fenxiao_price' ] : $sku_info[ 'discount_price' ];
+ // 默认规则
+ if ($sku_info[ 'fenxiao_type' ] == 1) {
+ $fenxiao_level = new FenxiaoLevel();
+ $level_info = $fenxiao_level->getLevelInfo([ [ 'level_id', '=', $level_id ] ], 'one_rate')[ 'data' ];
+ if (!empty($level_info)) {
+ $commission = number_format($discount_price * $level_info[ 'one_rate' ] / 100, 2, '.', '');
+ }
+ } else {
+ $fenxiao_sku_info = $this->getFenxiaoGoodsSkuInfo([ [ 'level_id', '=', $level_id ], [ 'sku_id', '=', $sku_id ] ])[ 'data' ];
+ if (!empty($fenxiao_sku_info)) {
+ $commission = $fenxiao_sku_info[ 'one_money' ];
+ if ($fenxiao_sku_info[ 'one_rate' ] > 0) {
+ $commission = number_format($discount_price * $fenxiao_sku_info[ 'one_rate' ] / 100, 2, '.', '');
+ }
+ }
+ }
+ }
+
+ return $this->success($commission);
+ }
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/model/FenxiaoLevel.php b/src/addon/fenxiao/model/FenxiaoLevel.php
index 3376a4313..73e8f72d4 100644
--- a/src/addon/fenxiao/model/FenxiaoLevel.php
+++ b/src/addon/fenxiao/model/FenxiaoLevel.php
@@ -1,182 +1,174 @@
-add($data);
- return $this->success($res);
- }
-
- /**
- * 编辑分销等级
- * @param $data
- * @param array $condition
- * @return array
- */
- public function editLevel($data, $condition = [])
- {
- $data[ 'update_time' ] = time();
-
- $res = model('fenxiao_level')->update($data, $condition);
- if ($res) {
- if (isset($data[ 'level_name' ]) && $data[ 'level_name' ] != '') {
- model('fenxiao')->update([ 'level_name' => $data[ 'level_name' ] ], $condition);
- }
- }
-
- return $this->success($res);
- }
-
- /**
- * 删除分销等级
- * @param $level_id
- * @param $site_id
- * @return array
- */
- public function deleteLevel($level_id, $site_id)
- {
- $fenxiao_model = new Fenxiao();
- $fenxiao_list = $fenxiao_model->getFenxiaoList([ [ 'level_id', '=', $level_id ] ], 'fenxiao_id');
- if (empty($fenxiao_list[ 'data' ])) {
- $res = model('fenxiao_level')->delete([ [ 'level_id', '=', $level_id ], [ 'site_id', '=', $site_id ] ]);
- return $this->success($res);
- } else {
- return $this->error('', '该分销等级存在其他分销商,无法删除');
- }
- }
-
- /**
- * 获取分销等级信息
- * @param array $condition
- * @param string $field
- * @return array
- */
- public function getLevelInfo($condition = [], $field = '*')
- {
- $res = model('fenxiao_level')->getInfo($condition, $field);
- return $this->success($res);
- }
-
- /**
- * @param array $condition
- * @param string $field
- * @return array
- */
- public function getLevelColumn($condition = [], $field = 'level_id')
- {
- $list = model('fenxiao_level')->getColumn($condition, $field);
- return $this->success($list);
- }
-
- /**
- * 获取分销商等级列表
- * @param array $condition
- * @param string $field
- * @param string $order
- * @param null $limit
- * @return array
- */
- public function getLevelList($condition = [], $field = '*', $order = '', $limit = null)
- {
- $list = model('fenxiao_level')->getList($condition, $field, $order, '', '', '', $limit);
- return $this->success($list);
- }
-
- /**
- * 获取分销商等级分页列表
- * @param array $condition
- * @param int $page
- * @param int $page_size
- * @param string $order
- * @param string $field
- * @return array
- */
- public function getLevelPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
- {
- $list = model('fenxiao_level')->pageList($condition, $field, $order, $page, $page_size);
- return $this->success($list);
- }
-
- /**
- * 获取最低的分销商等级
- * @param array $condition
- * @param string $field
- * @return array
- */
- public function getMinLevel($condition = [], $field = '*')
- {
- $info = model('fenxiao_level')->getFirstData($condition, $field, 'level_num asc,one_rate asc');
- return $this->success($info);
- }
-
- /**
- * 某项排序的第一个
- * @param $condition
- * @param $field
- * @param $order
- * @return array
- */
- public function getLevelFirst($condition, $field, $order)
- {
- $first = model('fenxiao_level')->getFirstData($condition, $field, $order);
- return $this->success($first);
- }
-
- /**
- * 平台端获取分销商列表
- * @param array $condition
- * @param int $page
- * @param int $page_size
- * @param string $order
- * @param string $field
- */
- public function getLevelPageListInAdmin($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
- {
- $list = $this->getLevelPageList($condition, $page, $page_size, $order, $field);
- if (!empty($list[ 'data' ][ 'list' ])) {
- $level_id_arr = [];
- foreach ($list[ 'data' ][ 'list' ] as $key => $val) {
- $level_id_arr[] = $val['level_id'];
- }
- $level_ids = implode(',', $level_id_arr);
-
- $fenxiao_list = model('fenxiao')->getList([['level_id', 'in', $level_ids]], 'level_id, count(*) as count', '', '', '', 'level_id');
-
- if(!empty($fenxiao_list)) {
- $key = array_column($fenxiao_list, 'level_id');
- $fenxiao_list = array_combine($key, $fenxiao_list);
- }
- foreach ($list[ 'data' ][ 'list' ] as $key => $val) {
- $list[ 'data' ][ 'list' ][ $key ][ 'fenxiao_num' ] = $fenxiao_list['level_id'] ?? 0;
- }
- }
- return $list;
- }
-
+add($data);
+ return $this->success($res);
+ }
+
+ /**
+ * 编辑分销等级
+ * @param $data
+ * @param array $condition
+ * @return array
+ */
+ public function editLevel($data, $condition = [])
+ {
+ $data[ 'update_time' ] = time();
+
+ $res = model('fenxiao_level')->update($data, $condition);
+ if ($res) {
+ if (isset($data[ 'level_name' ]) && $data[ 'level_name' ] != '') {
+ model('fenxiao')->update([ 'level_name' => $data[ 'level_name' ] ], $condition);
+ }
+ }
+
+ return $this->success($res);
+ }
+
+ /**
+ * 删除分销等级
+ * @param $level_id
+ * @param $site_id
+ * @return array
+ */
+ public function deleteLevel($level_id, $site_id)
+ {
+ $fenxiao_model = new Fenxiao();
+ $fenxiao_list = $fenxiao_model->getFenxiaoList([ [ 'level_id', '=', $level_id ] ], 'fenxiao_id');
+ if (empty($fenxiao_list[ 'data' ])) {
+ $res = model('fenxiao_level')->delete([ [ 'level_id', '=', $level_id ], [ 'site_id', '=', $site_id ] ]);
+ return $this->success($res);
+ } else {
+ return $this->error('', '该分销等级存在其他分销商,无法删除');
+ }
+ }
+
+ /**
+ * 获取分销等级信息
+ * @param array $condition
+ * @param string $field
+ * @return array
+ */
+ public function getLevelInfo($condition = [], $field = '*')
+ {
+ $res = model('fenxiao_level')->getInfo($condition, $field);
+ return $this->success($res);
+ }
+
+ /**
+ * @param array $condition
+ * @param string $field
+ * @return array
+ */
+ public function getLevelColumn($condition = [], $field = 'level_id')
+ {
+ $list = model('fenxiao_level')->getColumn($condition, $field);
+ return $this->success($list);
+ }
+
+ /**
+ * 获取分销商等级列表
+ * @param array $condition
+ * @param string $field
+ * @param string $order
+ * @param null $limit
+ * @return array
+ */
+ public function getLevelList($condition = [], $field = '*', $order = '', $limit = null)
+ {
+ $list = model('fenxiao_level')->getList($condition, $field, $order, '', '', '', $limit);
+ return $this->success($list);
+ }
+
+ /**
+ * 获取分销商等级分页列表
+ * @param array $condition
+ * @param int $page
+ * @param int $page_size
+ * @param string $order
+ * @param string $field
+ * @return array
+ */
+ public function getLevelPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
+ {
+ $list = model('fenxiao_level')->pageList($condition, $field, $order, $page, $page_size);
+ return $this->success($list);
+ }
+
+ /**
+ * 获取最低的分销商等级
+ * @param array $condition
+ * @param string $field
+ * @return array
+ */
+ public function getMinLevel($condition = [], $field = '*')
+ {
+ $info = model('fenxiao_level')->getFirstData($condition, $field, 'level_num asc,one_rate asc');
+ return $this->success($info);
+ }
+
+ /**
+ * 某项排序的第一个
+ * @param $condition
+ * @param $field
+ * @param $order
+ * @return array
+ */
+ public function getLevelFirst($condition, $field, $order)
+ {
+ $first = model('fenxiao_level')->getFirstData($condition, $field, $order);
+ return $this->success($first);
+ }
+
+ /**
+ * 平台端获取分销商列表
+ * @param array $condition
+ * @param int $page
+ * @param int $page_size
+ * @param string $order
+ * @param string $field
+ */
+ public function getLevelPageListInAdmin($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
+ {
+ $list = $this->getLevelPageList($condition, $page, $page_size, $order, $field);
+ if (!empty($list[ 'data' ][ 'list' ])) {
+ $level_id_arr = [];
+ foreach ($list[ 'data' ][ 'list' ] as $key => $val) {
+ $level_id_arr[] = $val['level_id'];
+ }
+ $level_ids = implode(',', $level_id_arr);
+
+ $fenxiao_list = model('fenxiao')->getList([['level_id', 'in', $level_ids]], 'level_id, count(*) as count', '', '', '', 'level_id');
+
+ if(!empty($fenxiao_list)) {
+ $key = array_column($fenxiao_list, 'level_id');
+ $fenxiao_list = array_combine($key, $fenxiao_list);
+ }
+ foreach ($list[ 'data' ][ 'list' ] as $key => $val) {
+ $list[ 'data' ][ 'list' ][ $key ][ 'fenxiao_num' ] = $fenxiao_list['level_id'] ?? 0;
+ }
+ }
+ return $list;
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/model/FenxiaoOrder.php b/src/addon/fenxiao/model/FenxiaoOrder.php
index 96aaf766e..90a8cfeff 100644
--- a/src/addon/fenxiao/model/FenxiaoOrder.php
+++ b/src/addon/fenxiao/model/FenxiaoOrder.php
@@ -1,601 +1,593 @@
-getFenxiaoBasicsConfig($order[ 'site_id' ])['data'] ?? [];
- $level_config = $fenxiao_basic_config[ 'value' ][ 'level' ];
- if (empty($level_config)) {
- return $this->success();
- }
-
- //检测分销商上级关系
- $member_info = model('member')->getInfo([ [ 'member_id', '=', $order[ 'member_id' ] ] ], 'fenxiao_id,is_fenxiao');
- //如果没有分销商直接返回不计算,没有考虑首次付款上下级绑定
- if (empty($member_info)) {
- return $this->success();
- }
- if ($member_info[ 'fenxiao_id' ] == 0) {
- return $this->success();
- }
-
- $fenxiao_id = $member_info[ 'fenxiao_id' ];
- //上一级分销商信息
- $fenxiao_info = model('fenxiao')->getInfo([ [ 'fenxiao_id', '=', $fenxiao_id ], [ 'is_delete', '=', 0 ] ]);
- if (empty($fenxiao_info)) {
- return $this->success();
- }
- // 如果购买人是分销商 并且未开启分销商自购
- if ($member_info[ 'is_fenxiao' ] && $fenxiao_basic_config[ 'value' ][ 'self_purchase_rebate' ] == 0) {
- if (empty($fenxiao_info[ 'parent' ])) return $this->success();
- $fenxiao_info = model('fenxiao')->getInfo([ [ 'fenxiao_id', '=', $fenxiao_info[ 'parent' ] ], [ 'is_delete', '=', 0 ] ]);
- if (empty($fenxiao_info)) return $this->success();
- }
-
- //判断几级分销
- //上二级分销商信息
- $parent_fenxiao_info = $level_config >= 2 ? model('fenxiao')->getInfo([ [ 'fenxiao_id', '=', $fenxiao_info[ 'parent' ] ], [ 'is_delete', '=', 0 ] ], 'fenxiao_id, fenxiao_name, status, parent,level_id') : [];
- $grand_parent_fenxiao_info = $level_config >= 3 && !empty($parent_fenxiao_info[ 'parent' ]) ? model('fenxiao')->getInfo([ [ 'fenxiao_id', '=', $parent_fenxiao_info[ 'parent' ] ], [ 'is_delete', '=', 0 ] ], 'fenxiao_id, fenxiao_name, status') : [];
- $order_goods = model('order_goods')->getList([ [ 'order_id', '=', $order[ 'order_id' ] ], [ 'is_fenxiao', '=', 1 ] ], 'order_goods_id, goods_id, sku_id, sku_name, sku_image, sku_no, is_virtual, price, cost_price, num, goods_money, cost_money, delivery_no, delivery_status, real_goods_money');
- if (empty($order_goods)) return $this->success();
-
- model('fenxiao_order')->delete([ [ 'order_id', '=', $order[ 'order_id' ] ] ]);
- //获取分销等级
- foreach ($order_goods as $k => $v) {
- $v[ 'num' ] = numberFormat($v[ 'num' ]);
-
- //商品信息管理
- $goods_info = model('goods')->getInfo([ [ 'goods_id', '=', $v[ 'goods_id' ] ] ], 'is_fenxiao, fenxiao_type');
- if ($goods_info[ 'is_fenxiao' ] != 1) {
- continue;
- }
-
- $sku_info = model('goods_sku')->getInfo([ [ 'sku_id', '=', $v[ 'sku_id' ] ] ], 'fenxiao_price');
- if (!empty($sku_info) && $sku_info[ 'fenxiao_price' ] > 0) $v[ 'real_goods_money' ] = $sku_info[ 'fenxiao_price' ] * $v[ 'num' ];
-
- $commission = 0;
- $commission_rate = 0;
- $order_fenxiao_data = [
- 'one_rate' => 0,//一级比例
- 'one_commission' => 0,//一级佣金
- 'two_rate' => 0,//二级比例
- 'two_commission' => 0,//二级佣金
- 'three_rate' => 0,
- ];
-
- if ($goods_info[ 'fenxiao_type' ] == 2) {
- // 自定义分销规则
- $fenxiao_level = model('fenxiao_goods_sku')->getInfo([ [ 'goods_id', '=', $v[ 'goods_id' ] ], [ 'sku_id', '=', $v[ 'sku_id' ] ], [ 'level_id', '=', $fenxiao_info[ 'level_id' ] ] ]);
- if (empty($fenxiao_level)) continue;
-
- if ($fenxiao_info[ 'status' ] == 1) {
- if ($fenxiao_level[ 'one_rate' ] > 0) {
- $commission_rate += $order_fenxiao_data[ 'one_rate' ] = $fenxiao_level[ 'one_rate' ];
- $commission += $order_fenxiao_data[ 'one_commission' ] = $fenxiao_level[ 'one_rate' ] * $v[ 'real_goods_money' ] / 100;
- } else {
- $commission_rate += $order_fenxiao_data[ 'one_rate' ] = round($fenxiao_level[ 'one_money' ] * $v[ 'num' ] / $v[ 'real_goods_money' ], 2);
- $commission += $order_fenxiao_data[ 'one_commission' ] = $fenxiao_level[ 'one_money' ] * $v[ 'num' ];
- }
- }
- if (!empty($parent_fenxiao_info) && $parent_fenxiao_info[ 'status' ] == 1) {
- if ($fenxiao_level[ 'two_rate' ] > 0) {
- $commission_rate += $order_fenxiao_data[ 'two_rate' ] = $fenxiao_level[ 'two_rate' ];
- $commission += $order_fenxiao_data[ 'two_commission' ] = $fenxiao_level[ 'two_rate' ] * $v[ 'real_goods_money' ] / 100;
- } else {
- $commission_rate += $order_fenxiao_data[ 'two_rate' ] = round($fenxiao_level[ 'two_money' ] * $v[ 'num' ] / $v[ 'real_goods_money' ], 2);
- $commission += $order_fenxiao_data[ 'two_commission' ] = $fenxiao_level[ 'two_money' ] * $v[ 'num' ];
- }
- }
- if (!empty($grand_parent_fenxiao_info) && $grand_parent_fenxiao_info[ 'status' ] == 1) {
- if ($fenxiao_level[ 'three_rate' ] > 0) {
- $commission_rate += $order_fenxiao_data[ 'three_rate' ] = $fenxiao_level[ 'three_rate' ];
- $commission += $order_fenxiao_data[ 'three_commission' ] = $fenxiao_level[ 'three_rate' ] * $v[ 'real_goods_money' ] / 100;
- } else {
- $commission_rate += $order_fenxiao_data[ 'three_rate' ] = round($fenxiao_level[ 'three_money' ] * $v[ 'num' ] / $v[ 'real_goods_money' ], 2);
- $commission += $order_fenxiao_data[ 'three_commission' ] = $fenxiao_level[ 'three_money' ] * $v[ 'num' ];
- }
- }
- } else {
- // 默认规则
- //一级分销商等级信息
- $fenxiao_level = model('fenxiao_level')->getInfo([ [ 'level_id', '=', $fenxiao_info[ 'level_id' ] ] ]);
- //二级分销商等级信息
- if($parent_fenxiao_info){
- $fenxiao_level2 = model('fenxiao_level')->getInfo([ [ 'level_id', '=', $parent_fenxiao_info[ 'level_id' ] ] ]);
- //add lucky赋值按二级用户获取对应用户等级佣金比例
- $fenxiao_level['two_rate'] = $fenxiao_level2['two_rate'];
- }
- if ($fenxiao_info[ 'status' ] == 1) {
- if ($fenxiao_level[ 'one_rate' ] > 0) {
- $commission_rate += $order_fenxiao_data[ 'one_rate' ] = $fenxiao_level[ 'one_rate' ];
- $commission += $order_fenxiao_data[ 'one_commission' ] = $fenxiao_level[ 'one_rate' ] * $v[ 'real_goods_money' ] / 100;
- } else {
- $order_fenxiao_data[ 'one_rate' ] = 0;
- $order_fenxiao_data[ 'one_commission' ] = 0;
- }
- }
- if (!empty($parent_fenxiao_info) && $parent_fenxiao_info[ 'status' ] == 1) {
- if ($fenxiao_level[ 'two_rate' ] > 0) {
- $commission_rate += $order_fenxiao_data[ 'two_rate' ] = $fenxiao_level[ 'two_rate' ];
- $commission += $order_fenxiao_data[ 'two_commission' ] = $fenxiao_level[ 'two_rate' ] * $v[ 'real_goods_money' ] / 100;
- } else {
- $order_fenxiao_data[ 'two_rate' ] = 0;
- $order_fenxiao_data[ 'two_commission' ] = 0;
- }
- }
- if (!empty($grand_parent_fenxiao_info) && $grand_parent_fenxiao_info[ 'status' ] == 1) {
- if ($fenxiao_level[ 'three_rate' ] > 0) {
- $commission_rate += $order_fenxiao_data[ 'three_rate' ] = $fenxiao_level[ 'three_rate' ];
- $commission += $order_fenxiao_data[ 'three_commission' ] = $fenxiao_level[ 'three_rate' ] * $v[ 'real_goods_money' ] / 100;
- } else {
- $order_fenxiao_data[ 'three_rate' ] = 0;
- $order_fenxiao_data[ 'three_commission' ] = 0;
- }
- }
- }
- //启动分销
- $data = [
- 'order_id' => $order[ 'order_id' ],
- 'order_no' => $order[ 'order_no' ],
- 'order_goods_id' => $v[ 'order_goods_id' ],
- 'site_id' => $order[ 'site_id' ],
- 'site_name' => $order[ 'site_name' ],
- 'goods_id' => $v[ 'goods_id' ],
- 'sku_id' => $v[ 'sku_id' ],
- 'sku_name' => $v[ 'sku_name' ],
- 'sku_image' => $v[ 'sku_image' ],
- 'price' => $v[ 'price' ],
- 'num' => $v[ 'num' ],
- 'real_goods_money' => $v[ 'real_goods_money' ],
- 'member_id' => $order[ 'member_id' ],
- 'member_name' => $order[ 'name' ] ?? '',
- 'member_mobile' => $order[ 'mobile' ] ?? '',
- 'full_address' => $order[ 'full_address' ] ?? '' . $order[ 'address' ] ?? '',
- 'commission' => $commission,
- 'commission_rate' => $commission_rate,
- 'one_fenxiao_id' => $fenxiao_info[ 'fenxiao_id' ],
- 'one_rate' => empty($order_fenxiao_data[ 'one_rate' ]) ? 0 : $order_fenxiao_data[ 'one_rate' ],
- 'one_commission' => empty($order_fenxiao_data[ 'one_commission' ]) ? 0 : $order_fenxiao_data[ 'one_commission' ],
- 'one_fenxiao_name' => $fenxiao_info[ 'fenxiao_name' ],
- 'two_fenxiao_id' => empty($parent_fenxiao_info) ? 0 : $parent_fenxiao_info[ 'fenxiao_id' ],
- 'two_rate' => empty($order_fenxiao_data[ 'two_rate' ]) ? 0 : $order_fenxiao_data[ 'two_rate' ],
- 'two_commission' => empty($order_fenxiao_data[ 'two_commission' ]) ? 0 : $order_fenxiao_data[ 'two_commission' ],
- 'two_fenxiao_name' => empty($parent_fenxiao_info) ? '' : $parent_fenxiao_info[ 'fenxiao_name' ],
- 'three_fenxiao_id' => empty($grand_parent_fenxiao_info) ? '' : $grand_parent_fenxiao_info[ 'fenxiao_id' ],
- 'three_rate' => empty($order_fenxiao_data[ 'three_rate' ]) ? 0 : $order_fenxiao_data[ 'three_rate' ],
- 'three_commission' => empty($order_fenxiao_data[ 'three_commission' ]) ? 0 : $order_fenxiao_data[ 'three_commission' ],
- 'three_fenxiao_name' => empty($grand_parent_fenxiao_info) ? '' : $grand_parent_fenxiao_info[ 'fenxiao_name' ],
- 'create_time' => time()
- ];
- model('fenxiao_order')->add($data);
- }
- // 分销商检测升级
- event('FenxiaoUpgrade', $member_info[ 'fenxiao_id' ]);
- return $this->success();
- }
-
- /**
- * 订单退款
- * @param $order_goods_id
- * @return array
- */
- public function refund($data)
- {
- $order_goods_info = $data['order_goods_info'];
- if ($order_goods_info[ 'refund_mode' ] == OrderRefundDict::refund) {
- $res = model('fenxiao_order')->update([ 'is_refund' => 1 ], [ [ 'order_goods_id', '=', $order_goods_info['order_goods_id'] ] ]);
- return $this->success($res);
- }
- }
-
- /**
- * 订单结算
- * @param $order_id
- * @return array
- */
- public function settlement($order_id)
- {
- //获取未退款的和未结算的分销订单
- $fenxiao_orders = model('fenxiao_order')->getList([ [ 'order_id', '=', $order_id ], [ 'is_settlement', '=', 0 ], [ 'is_refund', '=', 0 ] ], '*');
- //同时修改分销订单状态为已结算
- model('fenxiao_order')->startTrans();
- try {
- model('fenxiao_order')->update([ 'is_settlement' => 1 ], [ [ 'order_id', '=', $order_id ] ]);
- $commission = 0;
- $fenxiao_account = new FenxiaoAccount();
- $site_id = 0;
- foreach ($fenxiao_orders as $fenxiao_order) {
- $site_id = $fenxiao_order[ 'site_id' ];
- $commission += $fenxiao_order[ 'one_commission' ];
- $fenxiao_account->addAccount($fenxiao_order[ 'one_fenxiao_id' ], $fenxiao_order[ 'one_fenxiao_name' ], 'order', $fenxiao_order[ 'one_commission' ], $fenxiao_order[ 'fenxiao_order_id' ]);
-
- // 分销佣金发放通知
- ( new Message() )->sendMessage([
- 'keywords' => 'COMMISSION_GRANT',
- 'order_id' => $fenxiao_order[ 'fenxiao_order_id' ],
- 'site_id' => $fenxiao_order[ 'site_id' ],
- 'level' => 'one',
- ]);
-
- model('fenxiao')->setInc([ [ 'fenxiao_id', '=', $fenxiao_order[ 'one_fenxiao_id' ] ] ], 'total_commission', $fenxiao_order[ 'one_commission' ]);
-
- if ($fenxiao_order[ 'two_commission' ] > 0) {
- $commission += $fenxiao_order[ 'two_commission' ];
- $fenxiao_account->addAccount($fenxiao_order[ 'two_fenxiao_id' ], $fenxiao_order[ 'two_fenxiao_name' ], 'order', $fenxiao_order[ 'two_commission' ], $fenxiao_order[ 'fenxiao_order_id' ]);
-
- // 分销佣金发放通知
- ( new Message() )->sendMessage([
- 'keywords' => 'COMMISSION_GRANT',
- 'order_id' => $fenxiao_order[ 'fenxiao_order_id' ],
- 'site_id' => $fenxiao_order[ 'site_id' ],
- 'level' => 'two',
- ]);
-
- model('fenxiao')->setInc([ [ 'fenxiao_id', '=', $fenxiao_order[ 'two_fenxiao_id' ] ] ], 'total_commission', $fenxiao_order[ 'two_commission' ]);
- }
- if ($fenxiao_order[ 'three_commission' ] > 0) {
- $commission += $fenxiao_order[ 'three_commission' ];
- $fenxiao_account->addAccount($fenxiao_order[ 'three_fenxiao_id' ], $fenxiao_order[ 'three_fenxiao_name' ], 'order', $fenxiao_order[ 'three_commission' ], $fenxiao_order[ 'fenxiao_order_id' ]);
-
- // 分销佣金发放通知
- ( new Message() )->sendMessage([
- 'keywords' => 'COMMISSION_GRANT',
- 'order_id' => $fenxiao_order[ 'fenxiao_order_id' ],
- 'site_id' => $fenxiao_order[ 'site_id' ],
- 'level' => 'three',
- ]);
-
- model('fenxiao')->setInc([ [ 'fenxiao_id', '=', $fenxiao_order[ 'three_fenxiao_id' ] ] ], 'total_commission', $fenxiao_order[ 'three_commission' ]);
- }
-
- }
- $stat_model = new Stat();
- $stat_model->switchStat([ 'type' => 'fenxiao_order', 'data' => [ 'order_id' => $order_id, 'site_id' => $site_id ] ]);
- //增加订单佣金结算
- model('order')->setInc([ [ 'order_id', '=', $order_id ] ], 'commission', $commission);
- model('fenxiao_order')->commit();
- return $this->success();
- } catch ( Exception $e) {
- model('fenxiao_order')->rollback();
- return $this->error($e->getMessage());
- }
- }
-
- /**
- * 计算对应分销商的第一次订单数量&&金额
- * @param $order_id
- * @return array
- */
- public function calculateOrder($order_id)
- {
- $fenxiao_order_info = model('fenxiao_order')->getFirstData([ [ 'order_id', '=', $order_id ] ], 'one_fenxiao_id');
- if (!empty($fenxiao_order_info)) {
- $one_commission_sum = model('fenxiao_order')->getSum([ [ 'order_id', '=', $order_id ] ], 'one_commission');
- $one_fenxiao_total_order = model('fenxiao_order')->getSum([ [ 'order_id', '=', $order_id ] ], 'real_goods_money');
- model('fenxiao')->setInc([ [ 'fenxiao_id', '=', $fenxiao_order_info[ 'one_fenxiao_id' ] ] ], 'one_fenxiao_order_num');
- model('fenxiao')->setInc([ [ 'fenxiao_id', '=', $fenxiao_order_info[ 'one_fenxiao_id' ] ] ], 'one_fenxiao_order_money', $one_commission_sum);
- model('fenxiao')->setInc([ [ 'fenxiao_id', '=', $fenxiao_order_info[ 'one_fenxiao_id' ] ] ], 'one_fenxiao_total_order', $one_fenxiao_total_order);
- // 分销商检测升级
- event('FenxiaoUpgrade', $fenxiao_order_info[ 'one_fenxiao_id' ]);
- }
- return $this->success();
- }
-
- /**
- * 获取分销订单列表
- * @param array $condition
- * @param int $page
- * @param int $page_size
- * @param string $order
- * @return array
- */
- public function getFenxiaoOrderPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'fo.order_id DESC')
- {
- $field = '
- fo.fenxiao_order_id,fo.order_no,fo.site_id,fo.site_name,fo.sku_id,fo.sku_name,fo.sku_image,fo.price,fo.num,fo.real_goods_money,fo.member_name,
- fo.member_mobile,fo.one_fenxiao_name,fo.is_settlement,fo.commission,fo.is_refund,
- o.order_status_name,o.create_time,fo.one_fenxiao_id,fo.two_fenxiao_id,fo.three_fenxiao_id,fo.one_commission,fo.two_commission,fo.three_commission
- ';
-
- $alias = 'fo';
- $join = [
- [
- 'order o',
- 'fo.order_id = o.order_id',
- 'inner'
- ]
- ];
- $list = model('fenxiao_order')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
- return $this->success($list);
- }
-
- /**
- * 查询订单信息
- * @param $condition
- * @param string $field
- * @return array
- */
- public function getFenxiaoOrderInfo($condition, $field = '*')
- {
- $fenxiao_order_info = model('fenxiao_order')->getInfo($condition, $field);
- return $this->success($fenxiao_order_info);
- }
-
- /**
- * 查询订单信息
- * @param $condition
- * @param string $field
- * @return array
- */
- public function getFenxiaoOrderInfoNew($condition, $field = '*')
- {
- $alias = 'fo';
- $join = [
- [
- 'order o',
- 'o.order_id = fo.order_id',
- 'left'
- ]
- ];
- $fenxiao_order_info = model('fenxiao_order')->getInfo($condition, $field, $alias, $join);
- return $this->success($fenxiao_order_info);
- }
-
- /**
- * 查询分销订单列表(管理端调用)
- * @param array $condition
- * @param int $page
- * @param int $page_size
- * @param string $order
- * @return array
- */
- public function getFenxiaoOrderPage($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'order_id DESC')
- {
- // 解决GROUP BY问题:只查询主键ID,避免ONLY_FULL_GROUP_BY错误
- $field = 'DISTINCT fo.order_id';
- $list = model('fenxiao_order')->pageList($condition, $field, $order, $page, $page_size, 'fo', [], 'fo.order_id');
- if (!empty($list[ 'list' ])) {
- $order_id_arr = [];
- foreach ($list['list'] as $k => $v)
- {
- $order_id_arr[] = $v['order_id'];
- }
- if (!empty($order_id_arr)) {
- $order_ids = implode(',', $order_id_arr);
-
- // 重新查询完整的分销订单数据
- $fenxiao_orders = model('fenxiao_order')->getList([ [ 'fo.order_id', 'in', $order_ids ] ],
- 'fo.order_id, fo.order_no, fo.site_name, fo.member_name, fo.create_time, fo.is_settlement, fo.fenxiao_order_id',
- '', 'fo');
-
- // 重新组织数据
- $new_list = [];
- foreach ($fenxiao_orders as $fenxiao_order) {
- $order_list = model('order')->getInfo([ [ 'order_id', '=', $fenxiao_order['order_id'] ] ],
- 'name,full_address,mobile,order_status_name');
- $order_goods_list = model('fenxiao_order')->getList([ [ 'order_id', '=', $fenxiao_order['order_id'] ] ]);
-
- // 合并数据
- $new_item = array_merge($fenxiao_order, [
- 'address' => $order_list['full_address'] ?? '',
- 'mobile' => $order_list['mobile'] ?? '',
- 'order_status_name' => $order_list['order_status_name'] ?? '',
- 'order_goods' => $order_goods_list
- ]);
- $new_list[] = $new_item;
- }
- $list['list'] = $new_list;
- }
- }
- return $this->success($list);
- }
-
- /**
- * 获取分销订单详情
- * @param $condition
- * @param string $field
- * @return array
- */
- public function getFenxiaoOrderDetail($condition, $field = '*')
- {
- $order_info = model('order')->getInfo($condition, $field);
- if (!empty($order_info)) {
- $order_goods = model('fenxiao_order')->getList([ [ 'order_id', '=', $order_info[ 'order_id' ] ] ]);
- $member_info = model('member')->getInfo([ 'member_id' => $order_info[ 'member_id' ] ], 'nickname');
- $order_info[ 'order_goods' ] = $order_goods;
- $order_info[ 'nickname' ] = $member_info[ 'nickname' ];
- }
- return $this->success($order_info);
- }
-
- /**
- * 获取分销订单数量
- * @param $condition
- * @return array
- */
- public function getFenxiaoOrderCount($condition)
- {
- $count = model('fenxiao_order')->getCount($condition);
- return $this->success($count);
- }
-
- /**
- * 获取分销订单总和
- * @param array $condition
- * @param string $field
- * @param string $alias
- * @param null $join
- * @return array
- */
- public function getFenxiaoOrderSum(array $condition, $field = '', $alias = 'a', $join = null)
- {
- $data = model('fenxiao_order')->getSum($condition, $field, $alias, $join);
- return $this->success($data);
- }
-
- /**
- * 查询订单数据并导出
- * @param $condition
- * @param int $site_id
- */
- public function orderExport($condition, $site_id = 0)
- {
- $field = [
- 'order_no' => '订单编号',
- 'site_name' => '站点名称',
- 'sku_name' => '商品名称',
- 'member_name' => '购买人',
- 'member_mobile' => '购买人电话',
- 'commission' => '总佣金',
- 'one_rate' => '一级分销比例',
- 'one_commission' => '一级分销佣金',
- 'one_fenxiao_name' => '一级分销商名',
- 'two_rate' => '二级分销比例',
- 'two_commission' => '二级分销佣金',
- 'two_fenxiao_name' => '二级分销商名',
- 'three_rate' => '三级分销比例',
- 'three_commission' => '三级分销佣金',
- 'three_fenxiao_name' => '三级分销商名',
- 'is_settlement' => '是否结算',
- 'is_refund' => '是否退款',
- 'province_name' => '省',
- 'city_name' => '市',
- 'district_name' => '县',
- 'full_address' => '详细地址',
- 'order_status_name' => '订单状态'
- ];
-
- $fields = 'fo.*,o.address,o.full_address,o.order_status_name';
- $alias = 'fo';
- $join = [
- [
- 'order o',
- 'o.order_id = fo.order_id',
- 'left'
- ]
- ];
-
- $list = model('fenxiao_order')->getList($condition, $fields, '', $alias, $join);
- $head_html = [];
- $line_html = [];
- foreach ($field as $k => $v) {
- $head_html[] = $v;
- $line_html[] = $k;
- }
-
- $temp_line = implode(',', $head_html) . "\n";
- $html = str_replace("\n", '', $temp_line) . "\n";
- $line = implode(',', $line_html);
- $html .= str_replace("\n", '', $line) . "\n";
-
- $temp = [];
- foreach ($line_html as $temp_line_k => $temp_line_v) {
- $temp[] = "{\$$temp_line_v}";
- }
-
- $tempLine = implode(',', $temp) . "\n";
-
- foreach ($list as $item) {
- $new_line_value = $tempLine;
- $address_arr = explode('-', $item[ 'full_address' ]);
- $item[ 'province_name' ] = !empty($address_arr[ 0 ]) ? $address_arr[ 0 ] : '';
- $item[ 'city_name' ] = !empty($address_arr[ 1 ]) ? $address_arr[ 1 ] : '';
- $item[ 'district_name' ] = !empty($address_arr[ 2 ]) ? $address_arr[ 2 ] : '';
- $item[ 'is_settlement' ] = $item[ 'is_settlement' ] == 0 ? '否' : '是';
- $item[ 'is_refund' ] = $item[ 'is_refund' ] == 0 ? '否' : '是';
-
- foreach ($item as $key => $val) {
- if ($key == 'full_address') {
- $address = $item[ 'address' ] ?? '';
- $val = $val . $address;
- }
-
- //CSV比较简单,记得转义 逗号就好
- $values = str_replace(',', '\\', $val . "\t");
- $values = str_replace("\n", '', $values);
- $new_line_value = str_replace("{\$$key}", $values, $new_line_value);
-
- }
-
- $html .= $new_line_value;
- }
-
- $filename = date('YmdHis') . '.csv'; //设置文件名
- header('Content-type:text/csv');
- header('Content-Disposition:attachment;filename=' . $filename);
- header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
- header('Expires:0');
- header('Pragma:public');
- exit(mb_convert_encoding($html, 'GBK', 'UTF-8'));
-
- }
-
- /**
- * 给csv写入新的数据
- * @param $item_list
- * @param $field_key
- * @param $temp_line
- * @param $fp
- */
- public function itemExport($item_list, $field_key, $temp_line, $fp)
- {
- $item_list = $item_list->toArray();
- foreach ($item_list as $k => $item_v) {
- $new_line_value = $temp_line;
- //省市县
- $address_arr = explode('-', $item_v[ 'full_address' ]);
-
- $item_v[ 'province_name' ] = $address_arr[ 0 ] ?: '';
- $item_v[ 'city_name' ] = $address_arr[ 1 ] ?: '';
- $item_v[ 'district_name' ] = $address_arr[ 2 ] ?: '';
-
- foreach ($item_v as $key => $value) {
-
- if ($key == 'full_address') {
- $address = $item_v[ 'address' ] ?? '';
- $value = $value . $address;
- }
- //CSV比较简单,记得转义 逗号就好
- $values = str_replace(',', '\\', $value . "\t");
- $values = str_replace("\n", '', $values);
- $new_line_value = str_replace("{\$$key}", $values, $new_line_value);
- }
- //写入第一行表头
- fwrite($fp, $new_line_value);
- dump($new_line_value);
- exit;
- //销毁变量, 防止内存溢出
- unset($new_line_value);
- }
- }
+getFenxiaoBasicsConfig($order[ 'site_id' ])['data'] ?? [];
+ $level_config = $fenxiao_basic_config[ 'value' ][ 'level' ];
+ if (empty($level_config)) {
+ return $this->success();
+ }
+
+ //检测分销商上级关系
+ $member_info = model('member')->getInfo([ [ 'member_id', '=', $order[ 'member_id' ] ] ], 'fenxiao_id,is_fenxiao');
+ //如果没有分销商直接返回不计算,没有考虑首次付款上下级绑定
+ if (empty($member_info)) {
+ return $this->success();
+ }
+ if ($member_info[ 'fenxiao_id' ] == 0) {
+ return $this->success();
+ }
+
+ $fenxiao_id = $member_info[ 'fenxiao_id' ];
+ //上一级分销商信息
+ $fenxiao_info = model('fenxiao')->getInfo([ [ 'fenxiao_id', '=', $fenxiao_id ], [ 'is_delete', '=', 0 ] ]);
+ if (empty($fenxiao_info)) {
+ return $this->success();
+ }
+ // 如果购买人是分销商 并且未开启分销商自购
+ if ($member_info[ 'is_fenxiao' ] && $fenxiao_basic_config[ 'value' ][ 'self_purchase_rebate' ] == 0) {
+ if (empty($fenxiao_info[ 'parent' ])) return $this->success();
+ $fenxiao_info = model('fenxiao')->getInfo([ [ 'fenxiao_id', '=', $fenxiao_info[ 'parent' ] ], [ 'is_delete', '=', 0 ] ]);
+ if (empty($fenxiao_info)) return $this->success();
+ }
+
+ //判断几级分销
+ //上二级分销商信息
+ $parent_fenxiao_info = $level_config >= 2 ? model('fenxiao')->getInfo([ [ 'fenxiao_id', '=', $fenxiao_info[ 'parent' ] ], [ 'is_delete', '=', 0 ] ], 'fenxiao_id, fenxiao_name, status, parent,level_id') : [];
+ $grand_parent_fenxiao_info = $level_config >= 3 && !empty($parent_fenxiao_info[ 'parent' ]) ? model('fenxiao')->getInfo([ [ 'fenxiao_id', '=', $parent_fenxiao_info[ 'parent' ] ], [ 'is_delete', '=', 0 ] ], 'fenxiao_id, fenxiao_name, status') : [];
+ $order_goods = model('order_goods')->getList([ [ 'order_id', '=', $order[ 'order_id' ] ], [ 'is_fenxiao', '=', 1 ] ], 'order_goods_id, goods_id, sku_id, sku_name, sku_image, sku_no, is_virtual, price, cost_price, num, goods_money, cost_money, delivery_no, delivery_status, real_goods_money');
+ if (empty($order_goods)) return $this->success();
+
+ model('fenxiao_order')->delete([ [ 'order_id', '=', $order[ 'order_id' ] ] ]);
+ //获取分销等级
+ foreach ($order_goods as $k => $v) {
+ $v[ 'num' ] = numberFormat($v[ 'num' ]);
+
+ //商品信息管理
+ $goods_info = model('goods')->getInfo([ [ 'goods_id', '=', $v[ 'goods_id' ] ] ], 'is_fenxiao, fenxiao_type');
+ if ($goods_info[ 'is_fenxiao' ] != 1) {
+ continue;
+ }
+
+ $sku_info = model('goods_sku')->getInfo([ [ 'sku_id', '=', $v[ 'sku_id' ] ] ], 'fenxiao_price');
+ if (!empty($sku_info) && $sku_info[ 'fenxiao_price' ] > 0) $v[ 'real_goods_money' ] = $sku_info[ 'fenxiao_price' ] * $v[ 'num' ];
+
+ $commission = 0;
+ $commission_rate = 0;
+ $order_fenxiao_data = [
+ 'one_rate' => 0,//一级比例
+ 'one_commission' => 0,//一级佣金
+ 'two_rate' => 0,//二级比例
+ 'two_commission' => 0,//二级佣金
+ 'three_rate' => 0,
+ ];
+
+ if ($goods_info[ 'fenxiao_type' ] == 2) {
+ // 自定义分销规则
+ $fenxiao_level = model('fenxiao_goods_sku')->getInfo([ [ 'goods_id', '=', $v[ 'goods_id' ] ], [ 'sku_id', '=', $v[ 'sku_id' ] ], [ 'level_id', '=', $fenxiao_info[ 'level_id' ] ] ]);
+ if (empty($fenxiao_level)) continue;
+
+ if ($fenxiao_info[ 'status' ] == 1) {
+ if ($fenxiao_level[ 'one_rate' ] > 0) {
+ $commission_rate += $order_fenxiao_data[ 'one_rate' ] = $fenxiao_level[ 'one_rate' ];
+ $commission += $order_fenxiao_data[ 'one_commission' ] = $fenxiao_level[ 'one_rate' ] * $v[ 'real_goods_money' ] / 100;
+ } else {
+ $commission_rate += $order_fenxiao_data[ 'one_rate' ] = round($fenxiao_level[ 'one_money' ] * $v[ 'num' ] / $v[ 'real_goods_money' ], 2);
+ $commission += $order_fenxiao_data[ 'one_commission' ] = $fenxiao_level[ 'one_money' ] * $v[ 'num' ];
+ }
+ }
+ if (!empty($parent_fenxiao_info) && $parent_fenxiao_info[ 'status' ] == 1) {
+ if ($fenxiao_level[ 'two_rate' ] > 0) {
+ $commission_rate += $order_fenxiao_data[ 'two_rate' ] = $fenxiao_level[ 'two_rate' ];
+ $commission += $order_fenxiao_data[ 'two_commission' ] = $fenxiao_level[ 'two_rate' ] * $v[ 'real_goods_money' ] / 100;
+ } else {
+ $commission_rate += $order_fenxiao_data[ 'two_rate' ] = round($fenxiao_level[ 'two_money' ] * $v[ 'num' ] / $v[ 'real_goods_money' ], 2);
+ $commission += $order_fenxiao_data[ 'two_commission' ] = $fenxiao_level[ 'two_money' ] * $v[ 'num' ];
+ }
+ }
+ if (!empty($grand_parent_fenxiao_info) && $grand_parent_fenxiao_info[ 'status' ] == 1) {
+ if ($fenxiao_level[ 'three_rate' ] > 0) {
+ $commission_rate += $order_fenxiao_data[ 'three_rate' ] = $fenxiao_level[ 'three_rate' ];
+ $commission += $order_fenxiao_data[ 'three_commission' ] = $fenxiao_level[ 'three_rate' ] * $v[ 'real_goods_money' ] / 100;
+ } else {
+ $commission_rate += $order_fenxiao_data[ 'three_rate' ] = round($fenxiao_level[ 'three_money' ] * $v[ 'num' ] / $v[ 'real_goods_money' ], 2);
+ $commission += $order_fenxiao_data[ 'three_commission' ] = $fenxiao_level[ 'three_money' ] * $v[ 'num' ];
+ }
+ }
+ } else {
+ // 默认规则
+ //一级分销商等级信息
+ $fenxiao_level = model('fenxiao_level')->getInfo([ [ 'level_id', '=', $fenxiao_info[ 'level_id' ] ] ]);
+ //二级分销商等级信息
+ if($parent_fenxiao_info){
+ $fenxiao_level2 = model('fenxiao_level')->getInfo([ [ 'level_id', '=', $parent_fenxiao_info[ 'level_id' ] ] ]);
+ //add lucky赋值按二级用户获取对应用户等级佣金比例
+ $fenxiao_level['two_rate'] = $fenxiao_level2['two_rate'];
+ }
+ if ($fenxiao_info[ 'status' ] == 1) {
+ if ($fenxiao_level[ 'one_rate' ] > 0) {
+ $commission_rate += $order_fenxiao_data[ 'one_rate' ] = $fenxiao_level[ 'one_rate' ];
+ $commission += $order_fenxiao_data[ 'one_commission' ] = $fenxiao_level[ 'one_rate' ] * $v[ 'real_goods_money' ] / 100;
+ } else {
+ $order_fenxiao_data[ 'one_rate' ] = 0;
+ $order_fenxiao_data[ 'one_commission' ] = 0;
+ }
+ }
+ if (!empty($parent_fenxiao_info) && $parent_fenxiao_info[ 'status' ] == 1) {
+ if ($fenxiao_level[ 'two_rate' ] > 0) {
+ $commission_rate += $order_fenxiao_data[ 'two_rate' ] = $fenxiao_level[ 'two_rate' ];
+ $commission += $order_fenxiao_data[ 'two_commission' ] = $fenxiao_level[ 'two_rate' ] * $v[ 'real_goods_money' ] / 100;
+ } else {
+ $order_fenxiao_data[ 'two_rate' ] = 0;
+ $order_fenxiao_data[ 'two_commission' ] = 0;
+ }
+ }
+ if (!empty($grand_parent_fenxiao_info) && $grand_parent_fenxiao_info[ 'status' ] == 1) {
+ if ($fenxiao_level[ 'three_rate' ] > 0) {
+ $commission_rate += $order_fenxiao_data[ 'three_rate' ] = $fenxiao_level[ 'three_rate' ];
+ $commission += $order_fenxiao_data[ 'three_commission' ] = $fenxiao_level[ 'three_rate' ] * $v[ 'real_goods_money' ] / 100;
+ } else {
+ $order_fenxiao_data[ 'three_rate' ] = 0;
+ $order_fenxiao_data[ 'three_commission' ] = 0;
+ }
+ }
+ }
+ //启动分销
+ $data = [
+ 'order_id' => $order[ 'order_id' ],
+ 'order_no' => $order[ 'order_no' ],
+ 'order_goods_id' => $v[ 'order_goods_id' ],
+ 'site_id' => $order[ 'site_id' ],
+ 'site_name' => $order[ 'site_name' ],
+ 'goods_id' => $v[ 'goods_id' ],
+ 'sku_id' => $v[ 'sku_id' ],
+ 'sku_name' => $v[ 'sku_name' ],
+ 'sku_image' => $v[ 'sku_image' ],
+ 'price' => $v[ 'price' ],
+ 'num' => $v[ 'num' ],
+ 'real_goods_money' => $v[ 'real_goods_money' ],
+ 'member_id' => $order[ 'member_id' ],
+ 'member_name' => $order[ 'name' ] ?? '',
+ 'member_mobile' => $order[ 'mobile' ] ?? '',
+ 'full_address' => $order[ 'full_address' ] ?? '' . $order[ 'address' ] ?? '',
+ 'commission' => $commission,
+ 'commission_rate' => $commission_rate,
+ 'one_fenxiao_id' => $fenxiao_info[ 'fenxiao_id' ],
+ 'one_rate' => empty($order_fenxiao_data[ 'one_rate' ]) ? 0 : $order_fenxiao_data[ 'one_rate' ],
+ 'one_commission' => empty($order_fenxiao_data[ 'one_commission' ]) ? 0 : $order_fenxiao_data[ 'one_commission' ],
+ 'one_fenxiao_name' => $fenxiao_info[ 'fenxiao_name' ],
+ 'two_fenxiao_id' => empty($parent_fenxiao_info) ? 0 : $parent_fenxiao_info[ 'fenxiao_id' ],
+ 'two_rate' => empty($order_fenxiao_data[ 'two_rate' ]) ? 0 : $order_fenxiao_data[ 'two_rate' ],
+ 'two_commission' => empty($order_fenxiao_data[ 'two_commission' ]) ? 0 : $order_fenxiao_data[ 'two_commission' ],
+ 'two_fenxiao_name' => empty($parent_fenxiao_info) ? '' : $parent_fenxiao_info[ 'fenxiao_name' ],
+ 'three_fenxiao_id' => empty($grand_parent_fenxiao_info) ? '' : $grand_parent_fenxiao_info[ 'fenxiao_id' ],
+ 'three_rate' => empty($order_fenxiao_data[ 'three_rate' ]) ? 0 : $order_fenxiao_data[ 'three_rate' ],
+ 'three_commission' => empty($order_fenxiao_data[ 'three_commission' ]) ? 0 : $order_fenxiao_data[ 'three_commission' ],
+ 'three_fenxiao_name' => empty($grand_parent_fenxiao_info) ? '' : $grand_parent_fenxiao_info[ 'fenxiao_name' ],
+ 'create_time' => time()
+ ];
+ model('fenxiao_order')->add($data);
+ }
+ // 分销商检测升级
+ event('FenxiaoUpgrade', $member_info[ 'fenxiao_id' ]);
+ return $this->success();
+ }
+
+ /**
+ * 订单退款
+ * @param $order_goods_id
+ * @return array
+ */
+ public function refund($data)
+ {
+ $order_goods_info = $data['order_goods_info'];
+ if ($order_goods_info[ 'refund_mode' ] == OrderRefundDict::refund) {
+ $res = model('fenxiao_order')->update([ 'is_refund' => 1 ], [ [ 'order_goods_id', '=', $order_goods_info['order_goods_id'] ] ]);
+ return $this->success($res);
+ }
+ }
+
+ /**
+ * 订单结算
+ * @param $order_id
+ * @return array
+ */
+ public function settlement($order_id)
+ {
+ //获取未退款的和未结算的分销订单
+ $fenxiao_orders = model('fenxiao_order')->getList([ [ 'order_id', '=', $order_id ], [ 'is_settlement', '=', 0 ], [ 'is_refund', '=', 0 ] ], '*');
+ //同时修改分销订单状态为已结算
+ model('fenxiao_order')->startTrans();
+ try {
+ model('fenxiao_order')->update([ 'is_settlement' => 1 ], [ [ 'order_id', '=', $order_id ] ]);
+ $commission = 0;
+ $fenxiao_account = new FenxiaoAccount();
+ $site_id = 0;
+ foreach ($fenxiao_orders as $fenxiao_order) {
+ $site_id = $fenxiao_order[ 'site_id' ];
+ $commission += $fenxiao_order[ 'one_commission' ];
+ $fenxiao_account->addAccount($fenxiao_order[ 'one_fenxiao_id' ], $fenxiao_order[ 'one_fenxiao_name' ], 'order', $fenxiao_order[ 'one_commission' ], $fenxiao_order[ 'fenxiao_order_id' ]);
+
+ // 分销佣金发放通知
+ ( new Message() )->sendMessage([
+ 'keywords' => 'COMMISSION_GRANT',
+ 'order_id' => $fenxiao_order[ 'fenxiao_order_id' ],
+ 'site_id' => $fenxiao_order[ 'site_id' ],
+ 'level' => 'one',
+ ]);
+
+ model('fenxiao')->setInc([ [ 'fenxiao_id', '=', $fenxiao_order[ 'one_fenxiao_id' ] ] ], 'total_commission', $fenxiao_order[ 'one_commission' ]);
+
+ if ($fenxiao_order[ 'two_commission' ] > 0) {
+ $commission += $fenxiao_order[ 'two_commission' ];
+ $fenxiao_account->addAccount($fenxiao_order[ 'two_fenxiao_id' ], $fenxiao_order[ 'two_fenxiao_name' ], 'order', $fenxiao_order[ 'two_commission' ], $fenxiao_order[ 'fenxiao_order_id' ]);
+
+ // 分销佣金发放通知
+ ( new Message() )->sendMessage([
+ 'keywords' => 'COMMISSION_GRANT',
+ 'order_id' => $fenxiao_order[ 'fenxiao_order_id' ],
+ 'site_id' => $fenxiao_order[ 'site_id' ],
+ 'level' => 'two',
+ ]);
+
+ model('fenxiao')->setInc([ [ 'fenxiao_id', '=', $fenxiao_order[ 'two_fenxiao_id' ] ] ], 'total_commission', $fenxiao_order[ 'two_commission' ]);
+ }
+ if ($fenxiao_order[ 'three_commission' ] > 0) {
+ $commission += $fenxiao_order[ 'three_commission' ];
+ $fenxiao_account->addAccount($fenxiao_order[ 'three_fenxiao_id' ], $fenxiao_order[ 'three_fenxiao_name' ], 'order', $fenxiao_order[ 'three_commission' ], $fenxiao_order[ 'fenxiao_order_id' ]);
+
+ // 分销佣金发放通知
+ ( new Message() )->sendMessage([
+ 'keywords' => 'COMMISSION_GRANT',
+ 'order_id' => $fenxiao_order[ 'fenxiao_order_id' ],
+ 'site_id' => $fenxiao_order[ 'site_id' ],
+ 'level' => 'three',
+ ]);
+
+ model('fenxiao')->setInc([ [ 'fenxiao_id', '=', $fenxiao_order[ 'three_fenxiao_id' ] ] ], 'total_commission', $fenxiao_order[ 'three_commission' ]);
+ }
+
+ }
+ $stat_model = new Stat();
+ $stat_model->switchStat([ 'type' => 'fenxiao_order', 'data' => [ 'order_id' => $order_id, 'site_id' => $site_id ] ]);
+ //增加订单佣金结算
+ model('order')->setInc([ [ 'order_id', '=', $order_id ] ], 'commission', $commission);
+ model('fenxiao_order')->commit();
+ return $this->success();
+ } catch ( Exception $e) {
+ model('fenxiao_order')->rollback();
+ return $this->error($e->getMessage());
+ }
+ }
+
+ /**
+ * 计算对应分销商的第一次订单数量&&金额
+ * @param $order_id
+ * @return array
+ */
+ public function calculateOrder($order_id)
+ {
+ $fenxiao_order_info = model('fenxiao_order')->getFirstData([ [ 'order_id', '=', $order_id ] ], 'one_fenxiao_id');
+ if (!empty($fenxiao_order_info)) {
+ $one_commission_sum = model('fenxiao_order')->getSum([ [ 'order_id', '=', $order_id ] ], 'one_commission');
+ $one_fenxiao_total_order = model('fenxiao_order')->getSum([ [ 'order_id', '=', $order_id ] ], 'real_goods_money');
+ model('fenxiao')->setInc([ [ 'fenxiao_id', '=', $fenxiao_order_info[ 'one_fenxiao_id' ] ] ], 'one_fenxiao_order_num');
+ model('fenxiao')->setInc([ [ 'fenxiao_id', '=', $fenxiao_order_info[ 'one_fenxiao_id' ] ] ], 'one_fenxiao_order_money', $one_commission_sum);
+ model('fenxiao')->setInc([ [ 'fenxiao_id', '=', $fenxiao_order_info[ 'one_fenxiao_id' ] ] ], 'one_fenxiao_total_order', $one_fenxiao_total_order);
+ // 分销商检测升级
+ event('FenxiaoUpgrade', $fenxiao_order_info[ 'one_fenxiao_id' ]);
+ }
+ return $this->success();
+ }
+
+ /**
+ * 获取分销订单列表
+ * @param array $condition
+ * @param int $page
+ * @param int $page_size
+ * @param string $order
+ * @return array
+ */
+ public function getFenxiaoOrderPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'fo.order_id DESC')
+ {
+ $field = '
+ fo.fenxiao_order_id,fo.order_no,fo.site_id,fo.site_name,fo.sku_id,fo.sku_name,fo.sku_image,fo.price,fo.num,fo.real_goods_money,fo.member_name,
+ fo.member_mobile,fo.one_fenxiao_name,fo.is_settlement,fo.commission,fo.is_refund,
+ o.order_status_name,o.create_time,fo.one_fenxiao_id,fo.two_fenxiao_id,fo.three_fenxiao_id,fo.one_commission,fo.two_commission,fo.three_commission
+ ';
+
+ $alias = 'fo';
+ $join = [
+ [
+ 'order o',
+ 'fo.order_id = o.order_id',
+ 'inner'
+ ]
+ ];
+ $list = model('fenxiao_order')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
+ return $this->success($list);
+ }
+
+ /**
+ * 查询订单信息
+ * @param $condition
+ * @param string $field
+ * @return array
+ */
+ public function getFenxiaoOrderInfo($condition, $field = '*')
+ {
+ $fenxiao_order_info = model('fenxiao_order')->getInfo($condition, $field);
+ return $this->success($fenxiao_order_info);
+ }
+
+ /**
+ * 查询订单信息
+ * @param $condition
+ * @param string $field
+ * @return array
+ */
+ public function getFenxiaoOrderInfoNew($condition, $field = '*')
+ {
+ $alias = 'fo';
+ $join = [
+ [
+ 'order o',
+ 'o.order_id = fo.order_id',
+ 'left'
+ ]
+ ];
+ $fenxiao_order_info = model('fenxiao_order')->getInfo($condition, $field, $alias, $join);
+ return $this->success($fenxiao_order_info);
+ }
+
+ /**
+ * 查询分销订单列表(管理端调用)
+ * @param array $condition
+ * @param int $page
+ * @param int $page_size
+ * @param string $order
+ * @return array
+ */
+ public function getFenxiaoOrderPage($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'order_id DESC')
+ {
+ // 解决GROUP BY问题:只查询主键ID,避免ONLY_FULL_GROUP_BY错误
+ $field = 'DISTINCT fo.order_id';
+ $list = model('fenxiao_order')->pageList($condition, $field, $order, $page, $page_size, 'fo', [], 'fo.order_id');
+ if (!empty($list[ 'list' ])) {
+ $order_id_arr = [];
+ foreach ($list['list'] as $k => $v)
+ {
+ $order_id_arr[] = $v['order_id'];
+ }
+ if (!empty($order_id_arr)) {
+ $order_ids = implode(',', $order_id_arr);
+
+ // 重新查询完整的分销订单数据
+ $fenxiao_orders = model('fenxiao_order')->getList([ [ 'fo.order_id', 'in', $order_ids ] ],
+ 'fo.order_id, fo.order_no, fo.site_name, fo.member_name, fo.create_time, fo.is_settlement, fo.fenxiao_order_id',
+ '', 'fo');
+
+ // 重新组织数据
+ $new_list = [];
+ foreach ($fenxiao_orders as $fenxiao_order) {
+ $order_list = model('order')->getInfo([ [ 'order_id', '=', $fenxiao_order['order_id'] ] ],
+ 'name,full_address,mobile,order_status_name');
+ $order_goods_list = model('fenxiao_order')->getList([ [ 'order_id', '=', $fenxiao_order['order_id'] ] ]);
+
+ // 合并数据
+ $new_item = array_merge($fenxiao_order, [
+ 'address' => $order_list['full_address'] ?? '',
+ 'mobile' => $order_list['mobile'] ?? '',
+ 'order_status_name' => $order_list['order_status_name'] ?? '',
+ 'order_goods' => $order_goods_list
+ ]);
+ $new_list[] = $new_item;
+ }
+ $list['list'] = $new_list;
+ }
+ }
+ return $this->success($list);
+ }
+
+ /**
+ * 获取分销订单详情
+ * @param $condition
+ * @param string $field
+ * @return array
+ */
+ public function getFenxiaoOrderDetail($condition, $field = '*')
+ {
+ $order_info = model('order')->getInfo($condition, $field);
+ if (!empty($order_info)) {
+ $order_goods = model('fenxiao_order')->getList([ [ 'order_id', '=', $order_info[ 'order_id' ] ] ]);
+ $member_info = model('member')->getInfo([ 'member_id' => $order_info[ 'member_id' ] ], 'nickname');
+ $order_info[ 'order_goods' ] = $order_goods;
+ $order_info[ 'nickname' ] = $member_info[ 'nickname' ];
+ }
+ return $this->success($order_info);
+ }
+
+ /**
+ * 获取分销订单数量
+ * @param $condition
+ * @return array
+ */
+ public function getFenxiaoOrderCount($condition)
+ {
+ $count = model('fenxiao_order')->getCount($condition);
+ return $this->success($count);
+ }
+
+ /**
+ * 获取分销订单总和
+ * @param array $condition
+ * @param string $field
+ * @param string $alias
+ * @param null $join
+ * @return array
+ */
+ public function getFenxiaoOrderSum(array $condition, $field = '', $alias = 'a', $join = null)
+ {
+ $data = model('fenxiao_order')->getSum($condition, $field, $alias, $join);
+ return $this->success($data);
+ }
+
+ /**
+ * 查询订单数据并导出
+ * @param $condition
+ * @param int $site_id
+ */
+ public function orderExport($condition, $site_id = 0)
+ {
+ $field = [
+ 'order_no' => '订单编号',
+ 'site_name' => '站点名称',
+ 'sku_name' => '商品名称',
+ 'member_name' => '购买人',
+ 'member_mobile' => '购买人电话',
+ 'commission' => '总佣金',
+ 'one_rate' => '一级分销比例',
+ 'one_commission' => '一级分销佣金',
+ 'one_fenxiao_name' => '一级分销商名',
+ 'two_rate' => '二级分销比例',
+ 'two_commission' => '二级分销佣金',
+ 'two_fenxiao_name' => '二级分销商名',
+ 'three_rate' => '三级分销比例',
+ 'three_commission' => '三级分销佣金',
+ 'three_fenxiao_name' => '三级分销商名',
+ 'is_settlement' => '是否结算',
+ 'is_refund' => '是否退款',
+ 'province_name' => '省',
+ 'city_name' => '市',
+ 'district_name' => '县',
+ 'full_address' => '详细地址',
+ 'order_status_name' => '订单状态'
+ ];
+
+ $fields = 'fo.*,o.address,o.full_address,o.order_status_name';
+ $alias = 'fo';
+ $join = [
+ [
+ 'order o',
+ 'o.order_id = fo.order_id',
+ 'left'
+ ]
+ ];
+
+ $list = model('fenxiao_order')->getList($condition, $fields, '', $alias, $join);
+ $head_html = [];
+ $line_html = [];
+ foreach ($field as $k => $v) {
+ $head_html[] = $v;
+ $line_html[] = $k;
+ }
+
+ $temp_line = implode(',', $head_html) . "\n";
+ $html = str_replace("\n", '', $temp_line) . "\n";
+ $line = implode(',', $line_html);
+ $html .= str_replace("\n", '', $line) . "\n";
+
+ $temp = [];
+ foreach ($line_html as $temp_line_k => $temp_line_v) {
+ $temp[] = "{\$$temp_line_v}";
+ }
+
+ $tempLine = implode(',', $temp) . "\n";
+
+ foreach ($list as $item) {
+ $new_line_value = $tempLine;
+ $address_arr = explode('-', $item[ 'full_address' ]);
+ $item[ 'province_name' ] = !empty($address_arr[ 0 ]) ? $address_arr[ 0 ] : '';
+ $item[ 'city_name' ] = !empty($address_arr[ 1 ]) ? $address_arr[ 1 ] : '';
+ $item[ 'district_name' ] = !empty($address_arr[ 2 ]) ? $address_arr[ 2 ] : '';
+ $item[ 'is_settlement' ] = $item[ 'is_settlement' ] == 0 ? '否' : '是';
+ $item[ 'is_refund' ] = $item[ 'is_refund' ] == 0 ? '否' : '是';
+
+ foreach ($item as $key => $val) {
+ if ($key == 'full_address') {
+ $address = $item[ 'address' ] ?? '';
+ $val = $val . $address;
+ }
+
+ //CSV比较简单,记得转义 逗号就好
+ $values = str_replace(',', '\\', $val . "\t");
+ $values = str_replace("\n", '', $values);
+ $new_line_value = str_replace("{\$$key}", $values, $new_line_value);
+
+ }
+
+ $html .= $new_line_value;
+ }
+
+ $filename = date('YmdHis') . '.csv'; //设置文件名
+ header('Content-type:text/csv');
+ header('Content-Disposition:attachment;filename=' . $filename);
+ header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
+ header('Expires:0');
+ header('Pragma:public');
+ exit(mb_convert_encoding($html, 'GBK', 'UTF-8'));
+
+ }
+
+ /**
+ * 给csv写入新的数据
+ * @param $item_list
+ * @param $field_key
+ * @param $temp_line
+ * @param $fp
+ */
+ public function itemExport($item_list, $field_key, $temp_line, $fp)
+ {
+ $item_list = $item_list->toArray();
+ foreach ($item_list as $k => $item_v) {
+ $new_line_value = $temp_line;
+ //省市县
+ $address_arr = explode('-', $item_v[ 'full_address' ]);
+
+ $item_v[ 'province_name' ] = $address_arr[ 0 ] ?: '';
+ $item_v[ 'city_name' ] = $address_arr[ 1 ] ?: '';
+ $item_v[ 'district_name' ] = $address_arr[ 2 ] ?: '';
+
+ foreach ($item_v as $key => $value) {
+
+ if ($key == 'full_address') {
+ $address = $item_v[ 'address' ] ?? '';
+ $value = $value . $address;
+ }
+ //CSV比较简单,记得转义 逗号就好
+ $values = str_replace(',', '\\', $value . "\t");
+ $values = str_replace("\n", '', $values);
+ $new_line_value = str_replace("{\$$key}", $values, $new_line_value);
+ }
+ //写入第一行表头
+ fwrite($fp, $new_line_value);
+ dump($new_line_value);
+ exit;
+ //销毁变量, 防止内存溢出
+ unset($new_line_value);
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/model/FenxiaoStat.php b/src/addon/fenxiao/model/FenxiaoStat.php
index 870d6116b..6fe63817e 100644
--- a/src/addon/fenxiao/model/FenxiaoStat.php
+++ b/src/addon/fenxiao/model/FenxiaoStat.php
@@ -1,96 +1,88 @@
- $site_id,
- 'add_fenxiao_member_count' => 1
- );
-
- $stat_model = new Stat();
-
- $result = $stat_model->addShopStat($stat_data);
- return $result;
- }
-
- /**
- * 分销订单总额统计
- * @param $params
- * @return array
- */
- public function addFenxiaoOrderStat($params)
- {
- $order_id = $params[ 'order_id' ];
- $site_id = $params[ 'site_id' ] ?? 0;
- $order_condition = array (
- [ 'order_id', '=', $order_id ],
- [ 'site_id', '=', $site_id ]
- );
- $order_info = model('order')->getInfo($order_condition);
- if (empty($order_info))
- return $this->error();
-
- $order_money = $order_info[ 'order_money' ];
- $refund_money = $order_info[ 'refund_money' ];
- $stat_data = array (
- 'site_id' => $site_id,
- 'fenxiao_order_count' => 1,
- 'fenxiao_order_total_money' => $order_money - $refund_money,
- );
- $stat_model = new Stat();
-
- $result = $stat_model->addShopStat($stat_data);
- return $result;
- }
-
-
- /**
- * 分销佣金账户
- * @param int $site_id
- * @return array
- */
- public function getFenxiaoAccountSum($site_id = 0)
- {
- $field = '
- sum(account) as account,
- sum(account_withdraw_apply) as account_withdraw_apply,
- sum(account_withdraw) as account_withdraw
- ';
- $info = model('fenxiao')->getInfo([ [ 'site_id', '=', $site_id ] ], $field);
- if ($info[ 'account' ] == null) {
- $info[ 'account' ] = '0.00';
- }
- if ($info[ 'account_withdraw_apply' ] == null) {
- $info[ 'account_withdraw_apply' ] = '0.00';
- }
- if ($info[ 'account_withdraw' ] == null) {
- $info[ 'account_withdraw' ] = '0.00';
- }
- return $this->success($info);
- }
+ $site_id,
+ 'add_fenxiao_member_count' => 1
+ );
+
+ $stat_model = new Stat();
+
+ $result = $stat_model->addShopStat($stat_data);
+ return $result;
+ }
+
+ /**
+ * 分销订单总额统计
+ * @param $params
+ * @return array
+ */
+ public function addFenxiaoOrderStat($params)
+ {
+ $order_id = $params[ 'order_id' ];
+ $site_id = $params[ 'site_id' ] ?? 0;
+ $order_condition = array (
+ [ 'order_id', '=', $order_id ],
+ [ 'site_id', '=', $site_id ]
+ );
+ $order_info = model('order')->getInfo($order_condition);
+ if (empty($order_info))
+ return $this->error();
+
+ $order_money = $order_info[ 'order_money' ];
+ $refund_money = $order_info[ 'refund_money' ];
+ $stat_data = array (
+ 'site_id' => $site_id,
+ 'fenxiao_order_count' => 1,
+ 'fenxiao_order_total_money' => $order_money - $refund_money,
+ );
+ $stat_model = new Stat();
+
+ $result = $stat_model->addShopStat($stat_data);
+ return $result;
+ }
+
+
+ /**
+ * 分销佣金账户
+ * @param int $site_id
+ * @return array
+ */
+ public function getFenxiaoAccountSum($site_id = 0)
+ {
+ $field = '
+ sum(account) as account,
+ sum(account_withdraw_apply) as account_withdraw_apply,
+ sum(account_withdraw) as account_withdraw
+ ';
+ $info = model('fenxiao')->getInfo([ [ 'site_id', '=', $site_id ] ], $field);
+ if ($info[ 'account' ] == null) {
+ $info[ 'account' ] = '0.00';
+ }
+ if ($info[ 'account_withdraw_apply' ] == null) {
+ $info[ 'account_withdraw_apply' ] = '0.00';
+ }
+ if ($info[ 'account_withdraw' ] == null) {
+ $info[ 'account_withdraw' ] = '0.00';
+ }
+ return $this->success($info);
+ }
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/model/FenxiaoWithdraw.php b/src/addon/fenxiao/model/FenxiaoWithdraw.php
index 626ce794c..73d3b6253 100644
--- a/src/addon/fenxiao/model/FenxiaoWithdraw.php
+++ b/src/addon/fenxiao/model/FenxiaoWithdraw.php
@@ -1,884 +1,876 @@
- '余额',
- 'weixin' => '微信',
- 'alipay' => '支付宝',
- 'bank' => '银行卡',
- ];
-
- public $status = array (
- 1 => '待审核',
- 2 => '待转账',
- 3 => '已转账',
- -1 => '已拒绝'
- );
-
- public function getTransferType($site_id)
- {
- $pay_model = new Pay();
- $transfer_type_list = $pay_model->getTransferType($site_id);
- $transfer_type_list[ 'balance' ] = '余额';
- return $transfer_type_list;
- }
-
- /**
- * 分销商申请提现
- * @param $data
- * @return array
- */
- public function addFenxiaoWithdraw($data)
- {
- //获取分销商信息
- $fenxiao_model = new Fenxiao();
- $fenxiao_info = $fenxiao_model->getFenxiaoInfo([ [ 'member_id', '=', $data[ 'member_id' ] ] ], 'fenxiao_id,fenxiao_name,account');
- if (empty($fenxiao_info[ 'data' ])) {
- return $this->error('该分销商不存在');
- }
-
- if ($fenxiao_info[ 'data' ][ 'account' ] < $data[ 'money' ]) {
- return $this->error('', '提现金额大于可提现金额');
- }
- //获取提现配置信息
- $config_model = new Config();
- $config_info = $config_model->getFenxiaoWithdrawConfig($data[ 'site_id' ])[ 'data' ][ 'value' ];
- if ($config_info[ 'withdraw' ] > $data[ 'money' ]) {
- return $this->error('', '提现金额小于最低提现金额');
- }
- if ($data[ 'money' ] >= $config_info[ 'min_no_fee' ] && $data[ 'money' ] <= $config_info[ 'max_no_fee' ]) {
- $data[ 'withdraw_rate' ] = 0;
- $data[ 'withdraw_rate_money' ] = 0;
- $data[ 'real_money' ] = $data[ 'money' ];
- } else {
- $data[ 'withdraw_rate' ] = $config_info[ 'withdraw_rate' ];
- if ($config_info[ 'withdraw_rate' ] == 0) {
- $data[ 'withdraw_rate' ] = 0;
- $data[ 'withdraw_rate_money' ] = 0;
- $data[ 'real_money' ] = $data[ 'money' ];
- } else {
- $data[ 'withdraw_rate' ] = $config_info[ 'withdraw_rate' ];
- $data[ 'withdraw_rate_money' ] = round($data[ 'money' ] * $config_info[ 'withdraw_rate' ] / 100, 2);
- $data[ 'real_money' ] = $data[ 'money' ] - $data[ 'withdraw_rate_money' ];
- }
- }
-
- $data[ 'withdraw_no' ] = date('YmdHis') . rand(1000, 9999);
- $data[ 'create_time' ] = time();
-
- model('fenxiao_withdraw')->startTrans();
- try {
-
- $data[ 'fenxiao_id' ] = $fenxiao_info[ 'data' ][ 'fenxiao_id' ];
- $data[ 'fenxiao_name' ] = $fenxiao_info[ 'data' ][ 'fenxiao_name' ];
-
- $res = model('fenxiao_withdraw')->add($data);
-
- //修改分销商提现中金额
- model('fenxiao')->setInc([ [ 'member_id', '=', $data[ 'member_id' ] ] ], 'account_withdraw_apply', $data[ 'money' ]);
- //修改分销商可提现金额
- model('fenxiao')->setDec([ [ 'member_id', '=', $data[ 'member_id' ] ] ], 'account', $data[ 'money' ]);
-
- //判断是否需要审核
- if ($config_info[ 'withdraw_status' ] == 2) {//不需要
- $result = $this->withdrawPass($res, $data[ 'site_id' ]);
- if ($result[ 'code' ] < 0) {
- model('fenxiao_withdraw')->rollback();
- return $result;
- }
- }
-
- model('fenxiao_withdraw')->commit();
-
- //申请提现发送消息
- $data[ 'keywords' ] = 'FENXIAO_WITHDRAWAL_APPLY';
- $message_model = new Message();
- $message_model->sendMessage($data);
-
- return $this->success($res);
- } catch (\Exception $e) {
- model('fenxiao_withdraw')->rollback();
- return $this->error('', $e->getMessage());
- }
-
- }
-
- /**
- * 提现审核通过
- * @param $ids
- * @param $site_id
- * @return array
- */
- public function withdrawPass($ids, $site_id)
- {
- model('fenxiao_withdraw')->startTrans();
- try {
-
- $withdraw_list = $this->getFenxiaoWithdrawList([ [ 'id', 'in', $ids ] ], '*');
- foreach ($withdraw_list[ 'data' ] as $k => $v) {
- if ($v[ 'status' ] == 1) {
- $this->agree([ 'id' => $v[ 'id' ], 'site_id' => $site_id ]);
- }
- }
- model('fenxiao_withdraw')->commit();
- return $this->success();
- } catch (\Exception $e) {
- model('fenxiao_withdraw')->rollback();
- return $this->error('', $e->getMessage());
- }
- }
-
- /**
- * 获取提现详情
- * @param array $condition
- * @param string $field
- * @return array
- */
- public function getFenxiaoWithdrawInfo($condition = [], $field = '*')
- {
- $res = model('fenxiao_withdraw')->getInfo($condition, $field);
- return $this->success($res);
- }
-
- /**
- * 提现详情
- * @param $params
- * @return array
- */
- public function getFenxiaoWithdrawDetail($params)
- {
- $id = $params[ 'id' ];
- $site_id = $params[ 'site_id' ] ?? 0;
- $member_id = $params[ 'member_id' ] ?? 0;
- $condition = array (
- [ 'id', '=', $id ]
- );
- if ($site_id > 0) {
- $condition[] = [ 'site_id', '=', $site_id ];
- }
- if ($member_id > 0) {
- $condition[] = [ 'member_id', '=', $member_id ];
- }
- $info = model('fenxiao_withdraw')->getInfo($condition, '*');
- if (!empty($info)) {
- $info = $this->tran($info);
- }
- return $this->success($info);
- }
-
- public function tran($data)
- {
- $status = $data[ 'status' ] ?? 0;
- if ($status != 0) {
- $data[ 'status_name' ] = $this->status[ $status ] ?? '';
- }
- return $data;
- }
-
- /**
- * 获取分销列表
- * @param array $condition
- * @param string $field
- * @param string $order
- * @param null $limit
- * @return array
- */
- public function getFenxiaoWithdrawList($condition = [], $field = '*', $order = '', $limit = null)
- {
- $list = model('fenxiao_withdraw')->getList($condition, $field, $order, '', '', '', $limit);
- return $this->success($list);
- }
-
- /**
- * 获取分销提现分页列表
- * @param array $condition
- * @param int $page
- * @param int $page_size
- * @param string $order
- * @param string $field
- * @param string $alias
- * @param array $join
- * @return array
- */
- public function getFenxiaoWithdrawPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*', $alias = '', $join = [])
- {
- $list = model('fenxiao_withdraw')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
- return $this->success($list);
- }
-
- /**
- * 分销佣金发放通知
- * @param $data
- * @throws \GuzzleHttp\Exception\GuzzleException
- */
- public function messageOrderCommissionGrant($data)
- {
- //发送短信
- $sms_model = new Sms();
-
- // 分销订单
- $fenxiao_order_model = new FenxiaoOrder();
- $fenxiao_order_info = $fenxiao_order_model->getFenxiaoOrderInfo([ [ 'fenxiao_order_id', '=', $data[ 'order_id' ] ] ])[ 'data' ];
- $commission = $fenxiao_order_info[ $data[ 'level' ] . '_commission' ];
-
- $fenxiao_id = $fenxiao_order_info[ $data[ 'level' ] . '_fenxiao_id' ];
- $fenxiao_model = new Fenxiao();
- $fenxiao_info = $fenxiao_model->getFenxiaoInfo([ [ 'fenxiao_id', '=', $fenxiao_id ] ], 'fenxiao_id, member_id')[ 'data' ];
-
- $member_model = new MemberModel();
- $member_info_result = $member_model->getMemberInfo([ [ 'member_id', '=', $fenxiao_info[ 'member_id' ] ?? 0 ] ]);
- $member_info = $member_info_result[ 'data' ];
-
- //绑定微信公众号才发送
- if (!empty($member_info) && !empty($member_info[ 'wx_openid' ])) {
- $wechat_model = new WechatMessage();
- $data[ 'openid' ] = $member_info[ 'wx_openid' ];
- $data[ 'template_data' ] = [
- 'amount1' => $commission, // 提现金额
- 'time3' => time_to_date($fenxiao_order_info[ 'create_time' ]), // 提现日期
- ];
- $data[ 'page' ] = '';
- $wechat_model->sendMessage($data);
- }
-
- //发送订阅消息
- if (!empty($member_info) && !empty($member_info[ 'weapp_openid' ])) {
- $weapp_model = new WeappMessage();
- $data[ 'openid' ] = $member_info[ 'weapp_openid' ];
- $data[ 'template_data' ] = [
- 'amount1' => [
- 'value' => $fenxiao_order_info[ 'real_goods_money' ]
- ],
- 'amount2' => [
- 'value' => $commission
- ],
- 'thing3' => [
- 'value' => $fenxiao_order_info[ 'sku_name' ]
- ],
- 'time4' => [
- 'value' => time_to_date($fenxiao_order_info[ 'create_time' ]),
- ],
- ];
- $data[ 'page' ] = '';
- $weapp_model->sendMessage($data);
- }
-
- $buyer_member = $member_model->getMemberInfo([ [ 'member_id', '=', $fenxiao_order_info[ 'member_id' ] ?? 0 ] ]);
- $buyer_member_info = $buyer_member[ 'data' ];
-
- $var_parse = [
- 'sitename' => replaceSpecialChar($data[ 'site_info' ][ 'site_name' ]),
- 'level' => $data[ 'level' ],
- 'username' => empty(replaceSpecialChar($buyer_member_info[ 'nickname' ])) ? $buyer_member_info[ 'mobile' ] : replaceSpecialChar($buyer_member_info[ 'nickname' ]),
- ];
- $data[ 'sms_account' ] = $member_info[ 'mobile' ];
- $data[ 'var_parse' ] = $var_parse;
- $sms_model->sendMessage($data);
- }
-
- /**
- * 分销提现成功通知
- * @param $data
- * @throws \GuzzleHttp\Exception\GuzzleException
- */
- public function messageFenxiaoWithdrawalSuccess($data)
- {
- //发送短信
- $sms_model = new Sms();
-
- $var_parse = array (
- 'username' => $data[ 'fenxiao_name' ],//会员名
- 'money' => $data[ 'money' ]
- );
-
- $data[ 'sms_account' ] = $data[ 'mobile' ];//手机号
- $data[ 'var_parse' ] = $var_parse;
- $sms_model->sendMessage($data);
-
- $member_model = new MemberModel();
- $member_info_result = $member_model->getMemberInfo([ [ 'member_id', '=', $data[ 'member_id' ] ] ]);
- $member_info = $member_info_result[ 'data' ];
-
- //绑定微信公众号才发送
- if (!empty($member_info) && !empty($member_info[ 'wx_openid' ])) {
- $wechat_model = new WechatMessage();
- $data[ 'openid' ] = $member_info[ 'wx_openid' ];
- $data[ 'template_data' ] = [
- 'amount1' => $data[ 'money' ], // 提现金额
- 'time3' => time_to_date($data[ 'payment_time' ]), // 提现日期
- ];
- $data[ 'page' ] = '';
- $wechat_model->sendMessage($data);
- }
-
- //发送订阅消息
- if (!empty($member_info) && !empty($member_info[ 'weapp_openid' ])) {
- $weapp_model = new WeappMessage();
- $data[ 'openid' ] = $member_info[ 'weapp_openid' ];
- $data[ 'template_data' ] = [
- 'amount1' => [
- 'value' => $data[ 'money' ]
- ],
- 'time2' => [
- 'value' => time_to_date(time())
- ],
- 'thing3' => [
- 'value' => '提现成功'
- ]
- ];
- $data[ 'page' ] = '';
- $weapp_model->sendMessage($data);
- }
-
- }
-
- /**
- * 分销提现失败通知
- * @param $data
- * @throws \GuzzleHttp\Exception\GuzzleException
- */
- public function messageFenxiaoWithdrawalError($data)
- {
- //发送短信
- $sms_model = new Sms();
-
- $member_model = new MemberModel();
- $member_info_result = $member_model->getMemberInfo([ [ 'member_id', '=', $data[ 'member_id' ] ] ]);
- $member_info = $member_info_result[ 'data' ];
-
- $var_parse = array (
- 'fenxiaoname' => str_replace(' ', '', $data[ 'fenxiao_name' ]),//会员名
- 'money' => $data[ 'money' ]
- );
-
- $data[ 'sms_account' ] = $member_info[ 'mobile' ];//手机号
- $data[ 'var_parse' ] = $var_parse;
- $sms_model->sendMessage($data);
-
- // 【弃用,暂无模板信息,无法使用,等待后续微信支持后开发】绑定微信公众号才发送
-// if (!empty($member_info) && !empty($member_info[ 'wx_openid' ])) {
-// $wechat_model = new WechatMessage();
-// $data[ 'openid' ] = $member_info[ 'wx_openid' ];
-// $data[ 'template_data' ] = [
-// 'keyword1' => time_to_date($data[ 'create_time' ]),
-// 'keyword2' => '审核失败',
-// 'keyword3' => '会员申请提现',
-// 'keyword4' => $data[ 'money' ],
-// ];
-// $data[ 'page' ] = '';
-// $wechat_model->sendMessage($data);
-// }
-
- //发送订阅消息
- if (!empty($member_info) && !empty($member_info[ 'weapp_openid' ])) {
- $weapp_model = new WeappMessage();
- $data[ 'openid' ] = $member_info[ 'weapp_openid' ];
- $data[ 'template_data' ] = [
- 'amount2' => [
- 'value' => $data[ 'money' ]
- ],
- 'thing4' => [
- 'value' => '提现审核失败'
- ]
- ];
- $data[ 'page' ] = '';
- $weapp_model->sendMessage($data);
- }
-
- }
-
- /**
- * 分销申请提现通知,卖家通知
- * @param $data
- * @throws \GuzzleHttp\Exception\GuzzleException
- */
- public function messageFenxiaoWithdrawalApply($data)
- {
- //发送短信
- $sms_model = new Sms();
-
- $var_parse = array (
- 'fenxiaoname' => replaceSpecialChar($data[ 'fenxiao_name' ]),//会员名
- 'money' => $data[ 'money' ],//退款申请金额
- );
-// $site_id = $data['site_id'];
-// $shop_info = model('shop')->getInfo([['site_id', '=', $site_id]], 'mobile,email');
-// $message_data['sms_account'] = $shop_info['mobile'];//手机号
- $data[ 'var_parse' ] = $var_parse;
-
- $shop_accept_message_model = new ShopAcceptMessage();
- $result = $shop_accept_message_model->getShopAcceptMessageList();
- $list = $result[ 'data' ];
- if (!empty($list)) {
- foreach ($list as $v) {
- $message_data = $data;
- $message_data[ 'sms_account' ] = $v[ 'mobile' ];//手机号
- $sms_model->sendMessage($message_data);
-
- if ($v[ 'wx_openid' ] != '') {
- $wechat_model = new WechatMessage();
- $data[ 'openid' ] = $v[ 'wx_openid' ];
- $data[ 'template_data' ] = [
- 'thing3' => replaceSpecialChar($data[ 'fenxiao_name' ]), // 客户名称
- 'amount6' => $data[ 'money' ], // 提现金额
- 'time8' => time_to_date($data[ 'create_time' ]) // 提现时间
- ];
- $data[ 'page' ] = '';
- $wechat_model->sendMessage($data);
- }
- }
- }
- }
-
- /**
- * 获取提现数量
- * @param array $condition
- * @param string $field
- * @return array
- */
- public function getFenxiaoWithdrawCount($condition = [], $field = '*')
- {
- $res = model('fenxiao_withdraw')->getCount($condition, $field);
- return $this->success($res);
- }
-
- public function apply($data, $site_id = 0)
- {
- $config_model = new Config();
- $config = $config_model->getFenxiaoWithdrawConfig($site_id)[ 'data' ][ 'value' ] ?? [];
-
- $withdraw_no = $this->createWithdrawNo();
- $apply_money = round($data[ 'apply_money' ], 2);
-
- $withdraw_min_money = $config[ 'withdraw' ];
- $withdraw_max_money = $config[ 'max' ];
- if ($apply_money < $withdraw_min_money) return $this->error([], '申请提现金额不能小于最低提现额度' . $withdraw_min_money);
- if ($apply_money > $withdraw_max_money) return $this->error([], '申请提现金额不能大于最高提现额度' . $withdraw_max_money);
-
- $member_id = $data[ 'member_id' ];
- $member_model = new Member();
- $member_condition = array (
- [ 'member_id', '=', $member_id ]
- );
- $member_info = $member_model->getMemberInfo($member_condition, 'balance_money,headimg,wx_openid,username,mobile,weapp_openid,nickname')[ 'data' ] ?? [];
- if (empty($member_info))
- return $this->error([], 'MEMBER_NOT_EXIST');
-
- $fenxiao_model = new Fenxiao();
- $fenxiao_info = $fenxiao_model->getFenxiaoInfo($member_condition, 'fenxiao_id,fenxiao_name,account')[ 'data' ] ?? [];
- if (empty($fenxiao_info)) {
- return $this->error('该分销商不存在');
- }
- $fenxiao_account = $fenxiao_info[ 'account' ];//会员的分销佣金
- if ($fenxiao_account < $apply_money) {
- return $this->error('', '提现金额大于可提现金额');
- }
-
- $transfer_type = $data[ 'transfer_type' ];
- $transfer_type_list = $this->getTransferType($site_id);
- $transfer_type_name = $transfer_type_list[ $transfer_type ] ?? '';
- if (empty($transfer_type_name))
- return $this->error([], '不支持的提现方式');
-
- model('fenxiao_withdraw')->startTrans();
- try {
- $withdraw_rate = $config[ 'withdraw_rate' ];
- $bank_name = '';
- $account_number = '';
- $applet_type = 0;
- switch ( $transfer_type ) {
- case 'bank':
- $bank_name = $data[ 'bank_name' ];
- $account_number = $data[ 'account_number' ];
- break;
- case 'alipay':
- $bank_name = '';
- $account_number = $data[ 'account_number' ];
- break;
- case 'wechatpay':
- $bank_name = '';
- if (empty($member_info[ 'wx_openid' ]) && empty($member_info[ 'weapp_openid' ])) {
- return $this->error('', '请绑定微信或更换提现账户');
- }
- if (!empty($member_info[ 'wx_openid' ])) {
- $account_number = $member_info[ 'wx_openid' ];
- $applet_type = 0; // 公众号
- } else {
- $account_number = $member_info[ 'weapp_openid' ];
- $applet_type = 1; // 小程序
- }
- break;
-
- }
- if ($transfer_type == 'balance') {
- $withdraw_rate = 0;
- }
- $service_money = round($apply_money * $withdraw_rate / 100, 2);//手续费
- $real_money = $apply_money - $service_money;
- $data = array (
- 'site_id' => $site_id,
- 'withdraw_no' => $withdraw_no,
- 'member_id' => $member_id,
- 'fenxiao_id' => $fenxiao_info[ 'fenxiao_id' ],
- 'fenxiao_name' => $fenxiao_info[ 'fenxiao_name' ],
- 'transfer_type' => $transfer_type,
- 'transfer_name' => $transfer_type_name,
- 'money' => $apply_money,
- 'withdraw_rate_money' => $service_money,
- 'withdraw_rate' => $withdraw_rate,
- 'real_money' => $real_money,
- 'create_time' => time(),
- 'status' => 1,
-
- 'member_headimg' => $member_info[ 'headimg' ],
- 'realname' => $data[ 'realname' ],
- 'bank_name' => $bank_name,
- 'account_number' => $account_number,
- 'mobile' => $data[ 'mobile' ],
- 'applet_type' => $applet_type
- );
-
- $result = model('fenxiao_withdraw')->add($data);
-
- //修改分销商提现中金额
- model('fenxiao')->setInc($member_condition, 'account_withdraw_apply', $apply_money);
-
- //修改分销商可提现金额
- model('fenxiao')->setDec($member_condition, 'account', $apply_money);
-
- //申请提现发送消息
- $data[ 'keywords' ] = 'FENXIAO_WITHDRAWAL_APPLY';
- $message_model = new Message();
- $message_model->sendMessage($data);
-
- //判断是否需要审核
- if ($config[ 'withdraw_status' ] == 2) {//不需要
- $result = $this->agree([ 'id' => $result, 'site_id' => $site_id ]);
- if ($result[ 'code' ] < 0) {
- model('fenxiao_withdraw')->rollback();
- return $result;
- }
- }
- model('fenxiao_withdraw')->commit();
- return $this->success();
- } catch (\Exception $e) {
- model('fenxiao_withdraw')->rollback();
- return $this->error('', $e->getMessage());
- }
- }
-
- /**
- * 提现流水号
- */
- private function createWithdrawNo()
- {
- $cache = Cache::get('member_withdraw_no' . time());
- if (empty($cache)) {
- Cache::set('niutk' . time(), 1000);
- $cache = Cache::get('member_withdraw_no' . time());
- } else {
- $cache = $cache + 1;
- Cache::set('member_withdraw_no' . time(), $cache);
- }
- $no = date('Ymdhis', time()) . rand(1000, 9999) . $cache;
- return $no;
- }
-
- public function agree($params)
- {
- $id = $params[ 'id' ];
- $site_id = $params[ 'site_id' ];
- if (empty($site_id)) {
- return $this->error(-1, '参数错误');
- }
- $condition = array (
- [ 'id', '=', $id ],
- [ 'site_id', '=', $site_id ],
- );
- $info = model('fenxiao_withdraw')->getInfo($condition);
-
- if (empty($info))
- return $this->error();
-
- $config_model = new Config();
- $config = $config_model->getFenxiaoWithdrawConfig($site_id)[ 'data' ][ 'value' ] ?? [];
-
- model('fenxiao_withdraw')->startTrans();
- try {
- $data = array (
- 'status' => 2,
-// 'status_name' => '待转账',//已审核待转账
- 'audit_time' => time(),
- );
- $result = model('fenxiao_withdraw')->update($data, $condition);
- //是否启用自动转账(必须是微信或支付宝)
- if ($config[ 'is_auto_transfer' ] == 1) {
- $this->transfer([ 'id' => $id ]);
- }
- model('fenxiao_withdraw')->commit();
- return $this->success();
- } catch (\Exception $e) {
- model('fenxiao_withdraw')->rollback();
- return $this->error('', $e->getMessage() . $e->getLine());
- }
- }
-
- /**
- * 转账
- * @param $params
- * @return array|mixed|void
- */
- public function transfer($params)
- {
- $id = $params[ 'id' ];
- $site_id = $params[ 'site_id' ] ?? 0;
- $condition = array (
- [ 'id', '=', $id ],
- );
- if ($site_id > 0) {
- $condition[] = [ 'site_id', '=', $site_id ];
- }
- $info = model('fenxiao_withdraw')->getInfo($condition);
- if (empty($info))
- return $this->error();
- $site_id = $info[ 'site_id' ];
- $transfer_type = $info[ 'transfer_type' ];
- $member_id = $info[ 'member_id' ];
- $money = $info[ 'money' ];
- $fenxiao_id = $info[ 'fenxiao_id' ];
- $fenxiao_name = $info[ 'fenxiao_name' ];
- $real_money = $info[ 'real_money' ];
- if ($transfer_type == 'balance') {
- //添加会员账户流水
- $member_account = new MemberAccount();
- $member_result = $member_account->addMemberAccount($site_id, $member_id, 'balance_money', $real_money, 'fenxiao', '佣金提现', '分销佣金提现');
- if ($member_result[ 'code' ] < 0) {
- return $member_result;
- }
-
- } else {
- if (!in_array($transfer_type, [ 'wechatpay', 'alipay' ]))
- return $this->error('', '当前提现方式不支持在线转账');
-
- $pay_data = array (
- 'id' => $id,
- 'out_trade_no' => $info[ 'withdraw_no' ],
- 'real_name' => $info[ 'realname' ],
- 'amount' => $info[ 'real_money' ],
- 'desc' => '会员提现',
- 'transfer_type' => $transfer_type,
- 'account_number' => $info[ 'account_number' ],
- 'site_id' => $info[ 'site_id' ],
- 'is_weapp' => $info[ 'applet_type' ],
- 'member_id' => $info[ 'member_id' ]
- );
- //调用在线转账借口
- $pay_result = event('PayTransfer', $pay_data, true);
- if (empty($pay_result)) {
- $pay_result = $this->error();
- }
- if ($pay_result[ 'code' ] < 0) {
- return $pay_result;
- }
- }
- $account_model = new FenxiaoAccount();
- $account_result = $account_model->addAccountLog($fenxiao_id, $fenxiao_name, 'withdraw', '-' . $money, $id);
- if ($account_result[ 'code' ] != 0) {
- return $account_result;
- }
- //调用完成转账
- $result = $this->transferFinish([ 'id' => $id, 'site_id' => $info[ 'site_id' ] , 'certificate' => $params['certificate'] ?? '', 'certificate_remark' => $params['certificate_remark'] ?? '']);
- return $result;
- }
-
- /**
- * 提现转账完成
- * @param array $param
- * @return array
- */
- public function transferFinish($param = [])
- {
- $condition = [
- [ 'id', '=', $param[ 'id' ] ],
- [ 'site_id', '=', $param[ 'site_id' ] ],
- [ 'status', '=', 2 ]
- ];
- $info = model('fenxiao_withdraw')->getInfo($condition);
- if (empty($info)) return $this->error();
- $site_id = $info[ 'site_id' ];
- $member_id = $info[ 'member_id' ];
- $fenxiao_id = $info[ 'fenxiao_id' ];
- $money = $info[ 'money' ];
- $payment_time = time();
- model('fenxiao_withdraw')->startTrans();
- try {
- $data = [
- 'status' => 3,
- 'status_name' => '已转账',
- 'payment_time' => $payment_time,
- 'document' => $param[ 'certificate' ] ?? '',
- 'transfer_remark' => $param[ 'certificate_remark' ] ?? ''
- ];
- $result = model('fenxiao_withdraw')->update($data, $condition);
-
- $fenxiao_condition = array (
- [ 'fenxiao_id', '=', $fenxiao_id ]
- );
- //修改分销商提现中金额
- model('fenxiao')->setDec($fenxiao_condition, 'account_withdraw_apply', $money);
- //修改分销商已提现金额
- model('fenxiao')->setInc($fenxiao_condition, 'account_withdraw', $money);
-
- model('fenxiao_withdraw')->commit();
-
-// $member_info = model('member')->getInfo([ [ 'member_id', '=', $member_id ] ], 'nickname');
-
-// $stat_model = new Stat();
-// $stat_model->switchStat(['type' => 'member_withdraw', 'data' => ['site_id' => $info['site_id'], 'id' => $info['id']]]);
-
- $message_model = new Message();
- $info[ 'keywords' ] = 'FENXIAO_WITHDRAWAL_SUCCESS';
- $message_model->sendMessage($info);
- return $this->success();
- } catch (\Exception $e) {
- model('fenxiao_withdraw')->rollback();
- return $this->error('', $e->getMessage());
- }
- }
-
- /**
- * 拒绝提现申请
- * @param $params
- * @return array
- */
- public function refuse($params)
- {
- $id = $params[ 'id' ];
- $site_id = $params[ 'site_id' ];
- $data = [
- 'status' => -1,
- 'refuse_reason' => $params['refuse_reason'],
- 'audit_time' => time(),
- ];
- $condition = array (
- [ 'id', '=', $id ],
- [ 'site_id', '=', $site_id ]
- );
- $info = model('fenxiao_withdraw')->getInfo($condition, '*');
- if (empty($info)) return $this->error();
- model('fenxiao_withdraw')->startTrans();
- try {
- $money = $info[ 'money' ];
- $fenxiao_id = $info[ 'fenxiao_id' ];
- if ($info[ 'status' ] == 1) {
- model('fenxiao_withdraw')->update($data, $condition);
- $fenxiao_condition = array (
- [ 'fenxiao_id', '=', $fenxiao_id ]
- );
- //修改分销商提现中金额
- model('fenxiao')->setDec($fenxiao_condition, 'account_withdraw_apply', $money);
-
- //修改分销商可提现金额
- model('fenxiao')->setInc($fenxiao_condition, 'account', $money);
-
- //提现失败发送消息
- $message_model = new Message();
- $info[ 'keywords' ] = 'FENXIAO_WITHDRAWAL_ERROR';
- $message_model->sendMessage($info);
- }
- model('fenxiao_withdraw')->commit();
- return $this->success();
- } catch (\Exception $e) {
- model('fenxiao_withdraw')->rollback();
- return $this->error('', $e->getMessage());
- }
- }
-
- public function exportFenxiaoWithdraw($condition, $order, $site_id)
- {
- try {
- $file_name = date('Y年m月d日-分销提现', time()) . '.csv';
-// $file_name = date('YmdHis').'.csv';//csv文件名
- //通过分批次执行数据导出(防止内存超出配置设置的)
- set_time_limit(0);
- ini_set('memory_limit', '256M');
- //设置header头
- header('Content-Description: File Transfer');
- header('Content-Type: application/vnd.ms-excel');
- header('Content-Disposition: attachment; filename="' . $file_name . '"');
- header('Expires: 0');
- header('Cache-Control: must-revalidate');
- header('Pragma: public');
- //打开php数据输入缓冲区
- $fp = fopen('php://output', 'a');
-// fwrite($fp, chr(0xEF).chr(0xBB).chr(0xBF)); // 添加 BOM
- $heade = [ '分销商', '提现方式', '申请提现金额', '提现手续费', '实际转账金额', '提现状态', '申请时间', '收款账号', '真实姓名', '手机号', '银行名称', '银行账号' ];
- //将数据编码转换成GBK格式
- mb_convert_variables('GBK', 'UTF-8', $heade);
- //将数据格式化为CSV格式并写入到output流中
- fputcsv($fp, $heade);
- $transfer_type_list = $this->getTransferType($site_id);
- $status_name = [ 1 => '待审核', 2 => '待转账', 3 => '已转账', -1 => '已拒绝', -2 => '转账失败'];
- //写入第一行表头
- Db::name('fenxiao_withdraw')->where($condition)->order($order)->chunk(500, function($item_list) use ($fp, $transfer_type_list, $status_name) {
- //写入导出信息
- foreach ($item_list as $k => $item_v) {
- $temp_data = [
- $item_v[ 'fenxiao_name' ] . "\t",
- $transfer_type_list[ $item_v[ 'transfer_type' ] ] . "\t",
- (float) $item_v[ 'money' ] . "\t",
- (float) $item_v[ 'withdraw_rate_money' ] . "\t",
- (float) $item_v[ 'real_money' ] . "\t",
- $status_name[ $item_v[ 'status' ] ] . "\t",
- time_to_date($item_v[ 'create_time' ]) . "\t",
- $item_v[ 'account_number' ] . "\t",
- $item_v[ 'realname' ] . "\t",
- $item_v[ 'mobile' ] . "\t",
- $item_v[ 'bank_name' ] . "\t",
- $item_v[ 'transfer_account_no' ] . "\t",
- ];
- mb_convert_variables('GBK', 'UTF-8', $temp_data);
- fputcsv($fp, $temp_data);
- //将已经存储到csv中的变量数据销毁,释放内存
- unset($item_v);
- }
- unset($item_list);
- });
-
- //关闭句柄
- fclose($fp);
- die;
-
- } catch (\Exception $e) {
- return $this->error([], $e->getMessage() . $e->getFile() . $e->getLine());
- }
- }
+ '余额',
+ 'weixin' => '微信',
+ 'alipay' => '支付宝',
+ 'bank' => '银行卡',
+ ];
+
+ public $status = array (
+ 1 => '待审核',
+ 2 => '待转账',
+ 3 => '已转账',
+ -1 => '已拒绝'
+ );
+
+ public function getTransferType($site_id)
+ {
+ $pay_model = new Pay();
+ $transfer_type_list = $pay_model->getTransferType($site_id);
+ $transfer_type_list[ 'balance' ] = '余额';
+ return $transfer_type_list;
+ }
+
+ /**
+ * 分销商申请提现
+ * @param $data
+ * @return array
+ */
+ public function addFenxiaoWithdraw($data)
+ {
+ //获取分销商信息
+ $fenxiao_model = new Fenxiao();
+ $fenxiao_info = $fenxiao_model->getFenxiaoInfo([ [ 'member_id', '=', $data[ 'member_id' ] ] ], 'fenxiao_id,fenxiao_name,account');
+ if (empty($fenxiao_info[ 'data' ])) {
+ return $this->error('该分销商不存在');
+ }
+
+ if ($fenxiao_info[ 'data' ][ 'account' ] < $data[ 'money' ]) {
+ return $this->error('', '提现金额大于可提现金额');
+ }
+ //获取提现配置信息
+ $config_model = new Config();
+ $config_info = $config_model->getFenxiaoWithdrawConfig($data[ 'site_id' ])[ 'data' ][ 'value' ];
+ if ($config_info[ 'withdraw' ] > $data[ 'money' ]) {
+ return $this->error('', '提现金额小于最低提现金额');
+ }
+ if ($data[ 'money' ] >= $config_info[ 'min_no_fee' ] && $data[ 'money' ] <= $config_info[ 'max_no_fee' ]) {
+ $data[ 'withdraw_rate' ] = 0;
+ $data[ 'withdraw_rate_money' ] = 0;
+ $data[ 'real_money' ] = $data[ 'money' ];
+ } else {
+ $data[ 'withdraw_rate' ] = $config_info[ 'withdraw_rate' ];
+ if ($config_info[ 'withdraw_rate' ] == 0) {
+ $data[ 'withdraw_rate' ] = 0;
+ $data[ 'withdraw_rate_money' ] = 0;
+ $data[ 'real_money' ] = $data[ 'money' ];
+ } else {
+ $data[ 'withdraw_rate' ] = $config_info[ 'withdraw_rate' ];
+ $data[ 'withdraw_rate_money' ] = round($data[ 'money' ] * $config_info[ 'withdraw_rate' ] / 100, 2);
+ $data[ 'real_money' ] = $data[ 'money' ] - $data[ 'withdraw_rate_money' ];
+ }
+ }
+
+ $data[ 'withdraw_no' ] = date('YmdHis') . rand(1000, 9999);
+ $data[ 'create_time' ] = time();
+
+ model('fenxiao_withdraw')->startTrans();
+ try {
+
+ $data[ 'fenxiao_id' ] = $fenxiao_info[ 'data' ][ 'fenxiao_id' ];
+ $data[ 'fenxiao_name' ] = $fenxiao_info[ 'data' ][ 'fenxiao_name' ];
+
+ $res = model('fenxiao_withdraw')->add($data);
+
+ //修改分销商提现中金额
+ model('fenxiao')->setInc([ [ 'member_id', '=', $data[ 'member_id' ] ] ], 'account_withdraw_apply', $data[ 'money' ]);
+ //修改分销商可提现金额
+ model('fenxiao')->setDec([ [ 'member_id', '=', $data[ 'member_id' ] ] ], 'account', $data[ 'money' ]);
+
+ //判断是否需要审核
+ if ($config_info[ 'withdraw_status' ] == 2) {//不需要
+ $result = $this->withdrawPass($res, $data[ 'site_id' ]);
+ if ($result[ 'code' ] < 0) {
+ model('fenxiao_withdraw')->rollback();
+ return $result;
+ }
+ }
+
+ model('fenxiao_withdraw')->commit();
+
+ //申请提现发送消息
+ $data[ 'keywords' ] = 'FENXIAO_WITHDRAWAL_APPLY';
+ $message_model = new Message();
+ $message_model->sendMessage($data);
+
+ return $this->success($res);
+ } catch (\Exception $e) {
+ model('fenxiao_withdraw')->rollback();
+ return $this->error('', $e->getMessage());
+ }
+
+ }
+
+ /**
+ * 提现审核通过
+ * @param $ids
+ * @param $site_id
+ * @return array
+ */
+ public function withdrawPass($ids, $site_id)
+ {
+ model('fenxiao_withdraw')->startTrans();
+ try {
+
+ $withdraw_list = $this->getFenxiaoWithdrawList([ [ 'id', 'in', $ids ] ], '*');
+ foreach ($withdraw_list[ 'data' ] as $k => $v) {
+ if ($v[ 'status' ] == 1) {
+ $this->agree([ 'id' => $v[ 'id' ], 'site_id' => $site_id ]);
+ }
+ }
+ model('fenxiao_withdraw')->commit();
+ return $this->success();
+ } catch (\Exception $e) {
+ model('fenxiao_withdraw')->rollback();
+ return $this->error('', $e->getMessage());
+ }
+ }
+
+ /**
+ * 获取提现详情
+ * @param array $condition
+ * @param string $field
+ * @return array
+ */
+ public function getFenxiaoWithdrawInfo($condition = [], $field = '*')
+ {
+ $res = model('fenxiao_withdraw')->getInfo($condition, $field);
+ return $this->success($res);
+ }
+
+ /**
+ * 提现详情
+ * @param $params
+ * @return array
+ */
+ public function getFenxiaoWithdrawDetail($params)
+ {
+ $id = $params[ 'id' ];
+ $site_id = $params[ 'site_id' ] ?? 0;
+ $member_id = $params[ 'member_id' ] ?? 0;
+ $condition = array (
+ [ 'id', '=', $id ]
+ );
+ if ($site_id > 0) {
+ $condition[] = [ 'site_id', '=', $site_id ];
+ }
+ if ($member_id > 0) {
+ $condition[] = [ 'member_id', '=', $member_id ];
+ }
+ $info = model('fenxiao_withdraw')->getInfo($condition, '*');
+ if (!empty($info)) {
+ $info = $this->tran($info);
+ }
+ return $this->success($info);
+ }
+
+ public function tran($data)
+ {
+ $status = $data[ 'status' ] ?? 0;
+ if ($status != 0) {
+ $data[ 'status_name' ] = $this->status[ $status ] ?? '';
+ }
+ return $data;
+ }
+
+ /**
+ * 获取分销列表
+ * @param array $condition
+ * @param string $field
+ * @param string $order
+ * @param null $limit
+ * @return array
+ */
+ public function getFenxiaoWithdrawList($condition = [], $field = '*', $order = '', $limit = null)
+ {
+ $list = model('fenxiao_withdraw')->getList($condition, $field, $order, '', '', '', $limit);
+ return $this->success($list);
+ }
+
+ /**
+ * 获取分销提现分页列表
+ * @param array $condition
+ * @param int $page
+ * @param int $page_size
+ * @param string $order
+ * @param string $field
+ * @param string $alias
+ * @param array $join
+ * @return array
+ */
+ public function getFenxiaoWithdrawPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*', $alias = '', $join = [])
+ {
+ $list = model('fenxiao_withdraw')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
+ return $this->success($list);
+ }
+
+ /**
+ * 分销佣金发放通知
+ * @param $data
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function messageOrderCommissionGrant($data)
+ {
+ //发送短信
+ $sms_model = new Sms();
+
+ // 分销订单
+ $fenxiao_order_model = new FenxiaoOrder();
+ $fenxiao_order_info = $fenxiao_order_model->getFenxiaoOrderInfo([ [ 'fenxiao_order_id', '=', $data[ 'order_id' ] ] ])[ 'data' ];
+ $commission = $fenxiao_order_info[ $data[ 'level' ] . '_commission' ];
+
+ $fenxiao_id = $fenxiao_order_info[ $data[ 'level' ] . '_fenxiao_id' ];
+ $fenxiao_model = new Fenxiao();
+ $fenxiao_info = $fenxiao_model->getFenxiaoInfo([ [ 'fenxiao_id', '=', $fenxiao_id ] ], 'fenxiao_id, member_id')[ 'data' ];
+
+ $member_model = new MemberModel();
+ $member_info_result = $member_model->getMemberInfo([ [ 'member_id', '=', $fenxiao_info[ 'member_id' ] ?? 0 ] ]);
+ $member_info = $member_info_result[ 'data' ];
+
+ //绑定微信公众号才发送
+ if (!empty($member_info) && !empty($member_info[ 'wx_openid' ])) {
+ $wechat_model = new WechatMessage();
+ $data[ 'openid' ] = $member_info[ 'wx_openid' ];
+ $data[ 'template_data' ] = [
+ 'amount1' => $commission, // 提现金额
+ 'time3' => time_to_date($fenxiao_order_info[ 'create_time' ]), // 提现日期
+ ];
+ $data[ 'page' ] = '';
+ $wechat_model->sendMessage($data);
+ }
+
+ //发送订阅消息
+ if (!empty($member_info) && !empty($member_info[ 'weapp_openid' ])) {
+ $weapp_model = new WeappMessage();
+ $data[ 'openid' ] = $member_info[ 'weapp_openid' ];
+ $data[ 'template_data' ] = [
+ 'amount1' => [
+ 'value' => $fenxiao_order_info[ 'real_goods_money' ]
+ ],
+ 'amount2' => [
+ 'value' => $commission
+ ],
+ 'thing3' => [
+ 'value' => $fenxiao_order_info[ 'sku_name' ]
+ ],
+ 'time4' => [
+ 'value' => time_to_date($fenxiao_order_info[ 'create_time' ]),
+ ],
+ ];
+ $data[ 'page' ] = '';
+ $weapp_model->sendMessage($data);
+ }
+
+ $buyer_member = $member_model->getMemberInfo([ [ 'member_id', '=', $fenxiao_order_info[ 'member_id' ] ?? 0 ] ]);
+ $buyer_member_info = $buyer_member[ 'data' ];
+
+ $var_parse = [
+ 'sitename' => replaceSpecialChar($data[ 'site_info' ][ 'site_name' ]),
+ 'level' => $data[ 'level' ],
+ 'username' => empty(replaceSpecialChar($buyer_member_info[ 'nickname' ])) ? $buyer_member_info[ 'mobile' ] : replaceSpecialChar($buyer_member_info[ 'nickname' ]),
+ ];
+ $data[ 'sms_account' ] = $member_info[ 'mobile' ];
+ $data[ 'var_parse' ] = $var_parse;
+ $sms_model->sendMessage($data);
+ }
+
+ /**
+ * 分销提现成功通知
+ * @param $data
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function messageFenxiaoWithdrawalSuccess($data)
+ {
+ //发送短信
+ $sms_model = new Sms();
+
+ $var_parse = array (
+ 'username' => $data[ 'fenxiao_name' ],//会员名
+ 'money' => $data[ 'money' ]
+ );
+
+ $data[ 'sms_account' ] = $data[ 'mobile' ];//手机号
+ $data[ 'var_parse' ] = $var_parse;
+ $sms_model->sendMessage($data);
+
+ $member_model = new MemberModel();
+ $member_info_result = $member_model->getMemberInfo([ [ 'member_id', '=', $data[ 'member_id' ] ] ]);
+ $member_info = $member_info_result[ 'data' ];
+
+ //绑定微信公众号才发送
+ if (!empty($member_info) && !empty($member_info[ 'wx_openid' ])) {
+ $wechat_model = new WechatMessage();
+ $data[ 'openid' ] = $member_info[ 'wx_openid' ];
+ $data[ 'template_data' ] = [
+ 'amount1' => $data[ 'money' ], // 提现金额
+ 'time3' => time_to_date($data[ 'payment_time' ]), // 提现日期
+ ];
+ $data[ 'page' ] = '';
+ $wechat_model->sendMessage($data);
+ }
+
+ //发送订阅消息
+ if (!empty($member_info) && !empty($member_info[ 'weapp_openid' ])) {
+ $weapp_model = new WeappMessage();
+ $data[ 'openid' ] = $member_info[ 'weapp_openid' ];
+ $data[ 'template_data' ] = [
+ 'amount1' => [
+ 'value' => $data[ 'money' ]
+ ],
+ 'time2' => [
+ 'value' => time_to_date(time())
+ ],
+ 'thing3' => [
+ 'value' => '提现成功'
+ ]
+ ];
+ $data[ 'page' ] = '';
+ $weapp_model->sendMessage($data);
+ }
+
+ }
+
+ /**
+ * 分销提现失败通知
+ * @param $data
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function messageFenxiaoWithdrawalError($data)
+ {
+ //发送短信
+ $sms_model = new Sms();
+
+ $member_model = new MemberModel();
+ $member_info_result = $member_model->getMemberInfo([ [ 'member_id', '=', $data[ 'member_id' ] ] ]);
+ $member_info = $member_info_result[ 'data' ];
+
+ $var_parse = array (
+ 'fenxiaoname' => str_replace(' ', '', $data[ 'fenxiao_name' ]),//会员名
+ 'money' => $data[ 'money' ]
+ );
+
+ $data[ 'sms_account' ] = $member_info[ 'mobile' ];//手机号
+ $data[ 'var_parse' ] = $var_parse;
+ $sms_model->sendMessage($data);
+
+ // 【弃用,暂无模板信息,无法使用,等待后续微信支持后开发】绑定微信公众号才发送
+// if (!empty($member_info) && !empty($member_info[ 'wx_openid' ])) {
+// $wechat_model = new WechatMessage();
+// $data[ 'openid' ] = $member_info[ 'wx_openid' ];
+// $data[ 'template_data' ] = [
+// 'keyword1' => time_to_date($data[ 'create_time' ]),
+// 'keyword2' => '审核失败',
+// 'keyword3' => '会员申请提现',
+// 'keyword4' => $data[ 'money' ],
+// ];
+// $data[ 'page' ] = '';
+// $wechat_model->sendMessage($data);
+// }
+
+ //发送订阅消息
+ if (!empty($member_info) && !empty($member_info[ 'weapp_openid' ])) {
+ $weapp_model = new WeappMessage();
+ $data[ 'openid' ] = $member_info[ 'weapp_openid' ];
+ $data[ 'template_data' ] = [
+ 'amount2' => [
+ 'value' => $data[ 'money' ]
+ ],
+ 'thing4' => [
+ 'value' => '提现审核失败'
+ ]
+ ];
+ $data[ 'page' ] = '';
+ $weapp_model->sendMessage($data);
+ }
+
+ }
+
+ /**
+ * 分销申请提现通知,卖家通知
+ * @param $data
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function messageFenxiaoWithdrawalApply($data)
+ {
+ //发送短信
+ $sms_model = new Sms();
+
+ $var_parse = array (
+ 'fenxiaoname' => replaceSpecialChar($data[ 'fenxiao_name' ]),//会员名
+ 'money' => $data[ 'money' ],//退款申请金额
+ );
+// $site_id = $data['site_id'];
+// $shop_info = model('shop')->getInfo([['site_id', '=', $site_id]], 'mobile,email');
+// $message_data['sms_account'] = $shop_info['mobile'];//手机号
+ $data[ 'var_parse' ] = $var_parse;
+
+ $shop_accept_message_model = new ShopAcceptMessage();
+ $result = $shop_accept_message_model->getShopAcceptMessageList();
+ $list = $result[ 'data' ];
+ if (!empty($list)) {
+ foreach ($list as $v) {
+ $message_data = $data;
+ $message_data[ 'sms_account' ] = $v[ 'mobile' ];//手机号
+ $sms_model->sendMessage($message_data);
+
+ if ($v[ 'wx_openid' ] != '') {
+ $wechat_model = new WechatMessage();
+ $data[ 'openid' ] = $v[ 'wx_openid' ];
+ $data[ 'template_data' ] = [
+ 'thing3' => replaceSpecialChar($data[ 'fenxiao_name' ]), // 客户名称
+ 'amount6' => $data[ 'money' ], // 提现金额
+ 'time8' => time_to_date($data[ 'create_time' ]) // 提现时间
+ ];
+ $data[ 'page' ] = '';
+ $wechat_model->sendMessage($data);
+ }
+ }
+ }
+ }
+
+ /**
+ * 获取提现数量
+ * @param array $condition
+ * @param string $field
+ * @return array
+ */
+ public function getFenxiaoWithdrawCount($condition = [], $field = '*')
+ {
+ $res = model('fenxiao_withdraw')->getCount($condition, $field);
+ return $this->success($res);
+ }
+
+ public function apply($data, $site_id = 0)
+ {
+ $config_model = new Config();
+ $config = $config_model->getFenxiaoWithdrawConfig($site_id)[ 'data' ][ 'value' ] ?? [];
+
+ $withdraw_no = $this->createWithdrawNo();
+ $apply_money = round($data[ 'apply_money' ], 2);
+
+ $withdraw_min_money = $config[ 'withdraw' ];
+ $withdraw_max_money = $config[ 'max' ];
+ if ($apply_money < $withdraw_min_money) return $this->error([], '申请提现金额不能小于最低提现额度' . $withdraw_min_money);
+ if ($apply_money > $withdraw_max_money) return $this->error([], '申请提现金额不能大于最高提现额度' . $withdraw_max_money);
+
+ $member_id = $data[ 'member_id' ];
+ $member_model = new Member();
+ $member_condition = array (
+ [ 'member_id', '=', $member_id ]
+ );
+ $member_info = $member_model->getMemberInfo($member_condition, 'balance_money,headimg,wx_openid,username,mobile,weapp_openid,nickname')[ 'data' ] ?? [];
+ if (empty($member_info))
+ return $this->error([], 'MEMBER_NOT_EXIST');
+
+ $fenxiao_model = new Fenxiao();
+ $fenxiao_info = $fenxiao_model->getFenxiaoInfo($member_condition, 'fenxiao_id,fenxiao_name,account')[ 'data' ] ?? [];
+ if (empty($fenxiao_info)) {
+ return $this->error('该分销商不存在');
+ }
+ $fenxiao_account = $fenxiao_info[ 'account' ];//会员的分销佣金
+ if ($fenxiao_account < $apply_money) {
+ return $this->error('', '提现金额大于可提现金额');
+ }
+
+ $transfer_type = $data[ 'transfer_type' ];
+ $transfer_type_list = $this->getTransferType($site_id);
+ $transfer_type_name = $transfer_type_list[ $transfer_type ] ?? '';
+ if (empty($transfer_type_name))
+ return $this->error([], '不支持的提现方式');
+
+ model('fenxiao_withdraw')->startTrans();
+ try {
+ $withdraw_rate = $config[ 'withdraw_rate' ];
+ $bank_name = '';
+ $account_number = '';
+ $applet_type = 0;
+ switch ( $transfer_type ) {
+ case 'bank':
+ $bank_name = $data[ 'bank_name' ];
+ $account_number = $data[ 'account_number' ];
+ break;
+ case 'alipay':
+ $bank_name = '';
+ $account_number = $data[ 'account_number' ];
+ break;
+ case 'wechatpay':
+ $bank_name = '';
+ if (empty($member_info[ 'wx_openid' ]) && empty($member_info[ 'weapp_openid' ])) {
+ return $this->error('', '请绑定微信或更换提现账户');
+ }
+ if (!empty($member_info[ 'wx_openid' ])) {
+ $account_number = $member_info[ 'wx_openid' ];
+ $applet_type = 0; // 公众号
+ } else {
+ $account_number = $member_info[ 'weapp_openid' ];
+ $applet_type = 1; // 小程序
+ }
+ break;
+
+ }
+ if ($transfer_type == 'balance') {
+ $withdraw_rate = 0;
+ }
+ $service_money = round($apply_money * $withdraw_rate / 100, 2);//手续费
+ $real_money = $apply_money - $service_money;
+ $data = array (
+ 'site_id' => $site_id,
+ 'withdraw_no' => $withdraw_no,
+ 'member_id' => $member_id,
+ 'fenxiao_id' => $fenxiao_info[ 'fenxiao_id' ],
+ 'fenxiao_name' => $fenxiao_info[ 'fenxiao_name' ],
+ 'transfer_type' => $transfer_type,
+ 'transfer_name' => $transfer_type_name,
+ 'money' => $apply_money,
+ 'withdraw_rate_money' => $service_money,
+ 'withdraw_rate' => $withdraw_rate,
+ 'real_money' => $real_money,
+ 'create_time' => time(),
+ 'status' => 1,
+
+ 'member_headimg' => $member_info[ 'headimg' ],
+ 'realname' => $data[ 'realname' ],
+ 'bank_name' => $bank_name,
+ 'account_number' => $account_number,
+ 'mobile' => $data[ 'mobile' ],
+ 'applet_type' => $applet_type
+ );
+
+ $result = model('fenxiao_withdraw')->add($data);
+
+ //修改分销商提现中金额
+ model('fenxiao')->setInc($member_condition, 'account_withdraw_apply', $apply_money);
+
+ //修改分销商可提现金额
+ model('fenxiao')->setDec($member_condition, 'account', $apply_money);
+
+ //申请提现发送消息
+ $data[ 'keywords' ] = 'FENXIAO_WITHDRAWAL_APPLY';
+ $message_model = new Message();
+ $message_model->sendMessage($data);
+
+ //判断是否需要审核
+ if ($config[ 'withdraw_status' ] == 2) {//不需要
+ $result = $this->agree([ 'id' => $result, 'site_id' => $site_id ]);
+ if ($result[ 'code' ] < 0) {
+ model('fenxiao_withdraw')->rollback();
+ return $result;
+ }
+ }
+ model('fenxiao_withdraw')->commit();
+ return $this->success();
+ } catch (\Exception $e) {
+ model('fenxiao_withdraw')->rollback();
+ return $this->error('', $e->getMessage());
+ }
+ }
+
+ /**
+ * 提现流水号
+ */
+ private function createWithdrawNo()
+ {
+ $cache = Cache::get('member_withdraw_no' . time());
+ if (empty($cache)) {
+ Cache::set('niutk' . time(), 1000);
+ $cache = Cache::get('member_withdraw_no' . time());
+ } else {
+ $cache = $cache + 1;
+ Cache::set('member_withdraw_no' . time(), $cache);
+ }
+ $no = date('Ymdhis', time()) . rand(1000, 9999) . $cache;
+ return $no;
+ }
+
+ public function agree($params)
+ {
+ $id = $params[ 'id' ];
+ $site_id = $params[ 'site_id' ];
+ if (empty($site_id)) {
+ return $this->error(-1, '参数错误');
+ }
+ $condition = array (
+ [ 'id', '=', $id ],
+ [ 'site_id', '=', $site_id ],
+ );
+ $info = model('fenxiao_withdraw')->getInfo($condition);
+
+ if (empty($info))
+ return $this->error();
+
+ $config_model = new Config();
+ $config = $config_model->getFenxiaoWithdrawConfig($site_id)[ 'data' ][ 'value' ] ?? [];
+
+ model('fenxiao_withdraw')->startTrans();
+ try {
+ $data = array (
+ 'status' => 2,
+// 'status_name' => '待转账',//已审核待转账
+ 'audit_time' => time(),
+ );
+ $result = model('fenxiao_withdraw')->update($data, $condition);
+ //是否启用自动转账(必须是微信或支付宝)
+ if ($config[ 'is_auto_transfer' ] == 1) {
+ $this->transfer([ 'id' => $id ]);
+ }
+ model('fenxiao_withdraw')->commit();
+ return $this->success();
+ } catch (\Exception $e) {
+ model('fenxiao_withdraw')->rollback();
+ return $this->error('', $e->getMessage() . $e->getLine());
+ }
+ }
+
+ /**
+ * 转账
+ * @param $params
+ * @return array|mixed|void
+ */
+ public function transfer($params)
+ {
+ $id = $params[ 'id' ];
+ $site_id = $params[ 'site_id' ] ?? 0;
+ $condition = array (
+ [ 'id', '=', $id ],
+ );
+ if ($site_id > 0) {
+ $condition[] = [ 'site_id', '=', $site_id ];
+ }
+ $info = model('fenxiao_withdraw')->getInfo($condition);
+ if (empty($info))
+ return $this->error();
+ $site_id = $info[ 'site_id' ];
+ $transfer_type = $info[ 'transfer_type' ];
+ $member_id = $info[ 'member_id' ];
+ $money = $info[ 'money' ];
+ $fenxiao_id = $info[ 'fenxiao_id' ];
+ $fenxiao_name = $info[ 'fenxiao_name' ];
+ $real_money = $info[ 'real_money' ];
+ if ($transfer_type == 'balance') {
+ //添加会员账户流水
+ $member_account = new MemberAccount();
+ $member_result = $member_account->addMemberAccount($site_id, $member_id, 'balance_money', $real_money, 'fenxiao', '佣金提现', '分销佣金提现');
+ if ($member_result[ 'code' ] < 0) {
+ return $member_result;
+ }
+
+ } else {
+ if (!in_array($transfer_type, [ 'wechatpay', 'alipay' ]))
+ return $this->error('', '当前提现方式不支持在线转账');
+
+ $pay_data = array (
+ 'id' => $id,
+ 'out_trade_no' => $info[ 'withdraw_no' ],
+ 'real_name' => $info[ 'realname' ],
+ 'amount' => $info[ 'real_money' ],
+ 'desc' => '会员提现',
+ 'transfer_type' => $transfer_type,
+ 'account_number' => $info[ 'account_number' ],
+ 'site_id' => $info[ 'site_id' ],
+ 'is_weapp' => $info[ 'applet_type' ],
+ 'member_id' => $info[ 'member_id' ]
+ );
+ //调用在线转账借口
+ $pay_result = event('PayTransfer', $pay_data, true);
+ if (empty($pay_result)) {
+ $pay_result = $this->error();
+ }
+ if ($pay_result[ 'code' ] < 0) {
+ return $pay_result;
+ }
+ }
+ $account_model = new FenxiaoAccount();
+ $account_result = $account_model->addAccountLog($fenxiao_id, $fenxiao_name, 'withdraw', '-' . $money, $id);
+ if ($account_result[ 'code' ] != 0) {
+ return $account_result;
+ }
+ //调用完成转账
+ $result = $this->transferFinish([ 'id' => $id, 'site_id' => $info[ 'site_id' ] , 'certificate' => $params['certificate'] ?? '', 'certificate_remark' => $params['certificate_remark'] ?? '']);
+ return $result;
+ }
+
+ /**
+ * 提现转账完成
+ * @param array $param
+ * @return array
+ */
+ public function transferFinish($param = [])
+ {
+ $condition = [
+ [ 'id', '=', $param[ 'id' ] ],
+ [ 'site_id', '=', $param[ 'site_id' ] ],
+ [ 'status', '=', 2 ]
+ ];
+ $info = model('fenxiao_withdraw')->getInfo($condition);
+ if (empty($info)) return $this->error();
+ $site_id = $info[ 'site_id' ];
+ $member_id = $info[ 'member_id' ];
+ $fenxiao_id = $info[ 'fenxiao_id' ];
+ $money = $info[ 'money' ];
+ $payment_time = time();
+ model('fenxiao_withdraw')->startTrans();
+ try {
+ $data = [
+ 'status' => 3,
+ 'status_name' => '已转账',
+ 'payment_time' => $payment_time,
+ 'document' => $param[ 'certificate' ] ?? '',
+ 'transfer_remark' => $param[ 'certificate_remark' ] ?? ''
+ ];
+ $result = model('fenxiao_withdraw')->update($data, $condition);
+
+ $fenxiao_condition = array (
+ [ 'fenxiao_id', '=', $fenxiao_id ]
+ );
+ //修改分销商提现中金额
+ model('fenxiao')->setDec($fenxiao_condition, 'account_withdraw_apply', $money);
+ //修改分销商已提现金额
+ model('fenxiao')->setInc($fenxiao_condition, 'account_withdraw', $money);
+
+ model('fenxiao_withdraw')->commit();
+
+// $member_info = model('member')->getInfo([ [ 'member_id', '=', $member_id ] ], 'nickname');
+
+// $stat_model = new Stat();
+// $stat_model->switchStat(['type' => 'member_withdraw', 'data' => ['site_id' => $info['site_id'], 'id' => $info['id']]]);
+
+ $message_model = new Message();
+ $info[ 'keywords' ] = 'FENXIAO_WITHDRAWAL_SUCCESS';
+ $message_model->sendMessage($info);
+ return $this->success();
+ } catch (\Exception $e) {
+ model('fenxiao_withdraw')->rollback();
+ return $this->error('', $e->getMessage());
+ }
+ }
+
+ /**
+ * 拒绝提现申请
+ * @param $params
+ * @return array
+ */
+ public function refuse($params)
+ {
+ $id = $params[ 'id' ];
+ $site_id = $params[ 'site_id' ];
+ $data = [
+ 'status' => -1,
+ 'refuse_reason' => $params['refuse_reason'],
+ 'audit_time' => time(),
+ ];
+ $condition = array (
+ [ 'id', '=', $id ],
+ [ 'site_id', '=', $site_id ]
+ );
+ $info = model('fenxiao_withdraw')->getInfo($condition, '*');
+ if (empty($info)) return $this->error();
+ model('fenxiao_withdraw')->startTrans();
+ try {
+ $money = $info[ 'money' ];
+ $fenxiao_id = $info[ 'fenxiao_id' ];
+ if ($info[ 'status' ] == 1) {
+ model('fenxiao_withdraw')->update($data, $condition);
+ $fenxiao_condition = array (
+ [ 'fenxiao_id', '=', $fenxiao_id ]
+ );
+ //修改分销商提现中金额
+ model('fenxiao')->setDec($fenxiao_condition, 'account_withdraw_apply', $money);
+
+ //修改分销商可提现金额
+ model('fenxiao')->setInc($fenxiao_condition, 'account', $money);
+
+ //提现失败发送消息
+ $message_model = new Message();
+ $info[ 'keywords' ] = 'FENXIAO_WITHDRAWAL_ERROR';
+ $message_model->sendMessage($info);
+ }
+ model('fenxiao_withdraw')->commit();
+ return $this->success();
+ } catch (\Exception $e) {
+ model('fenxiao_withdraw')->rollback();
+ return $this->error('', $e->getMessage());
+ }
+ }
+
+ public function exportFenxiaoWithdraw($condition, $order, $site_id)
+ {
+ try {
+ $file_name = date('Y年m月d日-分销提现', time()) . '.csv';
+// $file_name = date('YmdHis').'.csv';//csv文件名
+ //通过分批次执行数据导出(防止内存超出配置设置的)
+ set_time_limit(0);
+ ini_set('memory_limit', '256M');
+ //设置header头
+ header('Content-Description: File Transfer');
+ header('Content-Type: application/vnd.ms-excel');
+ header('Content-Disposition: attachment; filename="' . $file_name . '"');
+ header('Expires: 0');
+ header('Cache-Control: must-revalidate');
+ header('Pragma: public');
+ //打开php数据输入缓冲区
+ $fp = fopen('php://output', 'a');
+// fwrite($fp, chr(0xEF).chr(0xBB).chr(0xBF)); // 添加 BOM
+ $heade = [ '分销商', '提现方式', '申请提现金额', '提现手续费', '实际转账金额', '提现状态', '申请时间', '收款账号', '真实姓名', '手机号', '银行名称', '银行账号' ];
+ //将数据编码转换成GBK格式
+ mb_convert_variables('GBK', 'UTF-8', $heade);
+ //将数据格式化为CSV格式并写入到output流中
+ fputcsv($fp, $heade);
+ $transfer_type_list = $this->getTransferType($site_id);
+ $status_name = [ 1 => '待审核', 2 => '待转账', 3 => '已转账', -1 => '已拒绝', -2 => '转账失败'];
+ //写入第一行表头
+ Db::name('fenxiao_withdraw')->where($condition)->order($order)->chunk(500, function($item_list) use ($fp, $transfer_type_list, $status_name) {
+ //写入导出信息
+ foreach ($item_list as $k => $item_v) {
+ $temp_data = [
+ $item_v[ 'fenxiao_name' ] . "\t",
+ $transfer_type_list[ $item_v[ 'transfer_type' ] ] . "\t",
+ (float) $item_v[ 'money' ] . "\t",
+ (float) $item_v[ 'withdraw_rate_money' ] . "\t",
+ (float) $item_v[ 'real_money' ] . "\t",
+ $status_name[ $item_v[ 'status' ] ] . "\t",
+ time_to_date($item_v[ 'create_time' ]) . "\t",
+ $item_v[ 'account_number' ] . "\t",
+ $item_v[ 'realname' ] . "\t",
+ $item_v[ 'mobile' ] . "\t",
+ $item_v[ 'bank_name' ] . "\t",
+ $item_v[ 'transfer_account_no' ] . "\t",
+ ];
+ mb_convert_variables('GBK', 'UTF-8', $temp_data);
+ fputcsv($fp, $temp_data);
+ //将已经存储到csv中的变量数据销毁,释放内存
+ unset($item_v);
+ }
+ unset($item_list);
+ });
+
+ //关闭句柄
+ fclose($fp);
+ die;
+
+ } catch (\Exception $e) {
+ return $this->error([], $e->getMessage() . $e->getFile() . $e->getLine());
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/model/Poster.php b/src/addon/fenxiao/model/Poster.php
index 5728d3df7..c785b16e1 100644
--- a/src/addon/fenxiao/model/Poster.php
+++ b/src/addon/fenxiao/model/Poster.php
@@ -1,260 +1,252 @@
-getQrcode($app_type, $page, $qrcode_param, $site_id);
- if ($qrcode_info[ 'code' ] < 0) return $qrcode_info;
-
- $member_info = $this->getMemberInfo($qrcode_param[ 'source_member' ]);
- if (empty($member_info)) return $this->error('未获取到会员信息');
-
- $poster = new PosterExtend(720, 1280);
- if (empty($template_info)) {
-
- $option = [
- [
- 'action' => 'imageCopy', // 背景图
- 'data' => [
- 'upload/poster/bg/fenxiao_2.png',
- 0,
- 0,
- 720,
- 1280,
- 'square',
- 0,
- 1
- ]
- ],
- [
- 'action' => 'imageCopy', // 写入二维码
- 'data' => [
- $qrcode_info[ 'data' ][ 'path' ],
- 492,
- 1035,
- 150,
- 150,
- 'square',
- 0,
- 1
- ]
- ],
- [
- 'action' => 'imageCircularCopy', // 写入用户头像
- 'data' => [
- !empty($member_info[ 'headimg' ]) ? $member_info[ 'headimg' ] : 'public/static/img/default_img/head.png',
- 65,
- 1020,
- 100,
- 100
- ]
- ],
- [
- 'action' => 'imageText', // 写入分享人昵称
- 'data' => [
- $member_info[ 'nickname' ],
- 22,
- [ 255, 129, 61 ],
- 180,
- 1060,
- 440,
- 1,
- true,
- 1
- ]
- ]
- ];
- } else {
- $params = $template_info;
- $poster = new PosterExtend(740, 1250);
- $fontRate = 0.725;
- $nickname_color = is_array($params[ 'template_json' ][ 'nickname_color' ]) ? $params[ 'template_json' ][ 'nickname_color' ] : hex2rgb($params[ 'template_json' ][ 'nickname_color' ]);
-
- $option = [
- [
- 'action' => 'imageCopy', // 写入背景图
- 'data' => [
- img($params[ 'background' ]),
- 0,
- 0,
- 740,
- 1250,
- 'square',
- 0,
- 1
- ]
- ],
- [
- 'action' => 'imageCopy', // 写入二维码
- 'data' => [
- $qrcode_info[ 'data' ][ 'path' ],
- (int) $params[ 'qrcode_left' ] * 2,
- (int) $params[ 'qrcode_top' ] * 2,
- (int) $params[ 'qrcode_width' ] * 2,
- (int) $params[ 'qrcode_height' ] * 2,
- 'square',
- 0,
- 1
- ]
- ],
- [
- 'action' => 'imageText', // 写入分享语
- 'data' => [
- $params[ 'template_json' ][ 'share_content' ],
- $params[ 'template_json' ][ 'share_content_font_size' ] * $fontRate * 2,
- is_array($params[ 'template_json' ][ 'share_content_color' ]) ? $params[ 'template_json' ][ 'share_content_color' ] : hex2rgb($params[ 'template_json' ][ 'share_content_color' ]),
- $params[ 'template_json' ][ 'share_content_left' ] * 2,
- ( $params[ 'template_json' ][ 'share_content_top' ] + $params[ 'template_json' ][ 'share_content_font_size' ] ) * 2,
- $params[ 'template_json' ][ 'share_content_width' ] * 2,
- 1
- ]
- ],
- [
- 'action' => 'imageCopy', // 写入用户头像
- 'data' => [
- !empty($member_info[ 'headimg' ]) ? img($member_info[ 'headimg' ]) : img('public/static/img/default_img/head.png'),
- $params[ 'template_json' ][ 'headimg_left' ] * 2,
- $params[ 'template_json' ][ 'headimg_top' ] * 2,
- $params[ 'template_json' ][ 'headimg_width' ] * 2,
- $params[ 'template_json' ][ 'headimg_height' ] * 2,
- !empty($params[ 'template_json' ][ 'headimg_shape' ]) ? $params[ 'template_json' ][ 'headimg_shape' ] : 'square',
- 0,
- $params[ 'template_json' ][ 'headimg_is_show' ]
- ]
- ],
- [
- 'action' => 'imageText', // 写入分享人昵称
- 'data' => [
- $member_info[ 'nickname' ],
- $params[ 'template_json' ][ 'nickname_font_size' ] * $fontRate * 2,
- $nickname_color,
- $params[ 'template_json' ][ 'nickname_left' ] * 2,
- ( $params[ 'template_json' ][ 'nickname_top' ] + $params[ 'template_json' ][ 'nickname_font_size' ] ) * 2,
- $params[ 'template_json' ][ 'nickname_width' ] * 2,
- 1,
- true,
- $params[ 'template_json' ][ 'nickname_is_show' ]
- ]
- ],
- ];
-
- }
- $option_res = $poster->create($option);
-
- if (is_array($option_res)) return $option_res;
- $pic_name = "";
- if (!empty($params)) {
- $pic_name = md5(json_encode([
- 'id' => $params[ 'template_id' ],
- 'poster_name' => $params[ 'poster_name' ]
- ]));
- $pic_name = "_" . $pic_name;
- }
-
- $res = $option_res->jpeg('upload/poster/distribution', 'distribution_' . $qrcode_param[ 'source_member' ] . $pic_name . '_' . $app_type);
- if ($res[ 'code' ] == 0) {
- $upload = new Upload($site_id);
- $cloud_res = $upload->fileCloud($res[ 'data' ][ 'path' ]);
- if ($cloud_res[ 'code' ] >= 0) {
- return $this->success([ "path" => $cloud_res[ 'data' ] ]);
- } else {
- return $this->error();
- }
- }
- return $res;
- } catch (\Exception $e) {
- return $this->error($e->getMessage() . $e->getFile() . $e->getLine());
- }
- }
-
- /**
- * 获取用户信息
- * @param $member_id
- * @return mixed
- */
- private function getMemberInfo($member_id)
- {
- $info = model('member')->getInfo([ 'member_id' => $member_id ], 'nickname,headimg');
- return $info;
- }
-
- /**
- * 获取二维码
- * @param unknown $app_type 请求类型
- * @param unknown $page uniapp页面路径
- * @param unknown $qrcode_param 二维码携带参数
- * @param string $promotion_type 活动类型 null为无活动
- */
- private function getQrcode($app_type, $page, $qrcode_param, $site_id)
- {
- $res = event('Qrcode', [
- 'site_id' => $site_id,
- 'app_type' => $app_type,
- 'type' => 'get',
- 'data' => $qrcode_param,
- 'page' => $page,
- 'qrcode_path' => 'upload/qrcode/distribution',
- 'qrcode_name' => 'distribution' . '_' . $qrcode_param[ 'source_member' ] . '_' . $site_id,
- ], true);
- return $res;
- }
-
- /**
- * 获取分销海报
- * @param $param
- * @return array|\extend\multitype|PosterExtend|mixed|string|void
- */
- public function getFenxiaoPoster($param)
- {
- $app_type = $param[ 'app_type' ] ?? 'h5';
- $qrcode_param = $param[ 'qrcode_param' ] ?? [];
- $site_id = $param[ 'site_id' ] ?? 0;
- $page = $param[ 'page' ] ?? '';
- $template_id = $param[ 'template_id' ] ?? 'default';
-
- if ($template_id == 'default') {
- //默认海报
- $template_info = null;
- } else {
- //设置的海报
- $template_info = model('poster_template')->getInfo([
- [ 'site_id', '=', $site_id ],
- [ 'template_type', '=', 'fenxiao' ],
- [ 'template_status', '=', 1 ],
- [ 'template_id', '=', $template_id ],
- ]);
- if (empty($template_info)) return $this->error(null, '模板信息有误');
- $template_info[ 'template_json' ] = json_decode($template_info[ 'template_json' ], true);
- }
- $res = $this->distribution($app_type, $page, $qrcode_param, $site_id, $template_info);
- return $res;
- }
+getQrcode($app_type, $page, $qrcode_param, $site_id);
+ if ($qrcode_info[ 'code' ] < 0) return $qrcode_info;
+
+ $member_info = $this->getMemberInfo($qrcode_param[ 'source_member' ]);
+ if (empty($member_info)) return $this->error('未获取到会员信息');
+
+ $poster = new PosterExtend(720, 1280);
+ if (empty($template_info)) {
+
+ $option = [
+ [
+ 'action' => 'imageCopy', // 背景图
+ 'data' => [
+ 'upload/poster/bg/fenxiao_2.png',
+ 0,
+ 0,
+ 720,
+ 1280,
+ 'square',
+ 0,
+ 1
+ ]
+ ],
+ [
+ 'action' => 'imageCopy', // 写入二维码
+ 'data' => [
+ $qrcode_info[ 'data' ][ 'path' ],
+ 492,
+ 1035,
+ 150,
+ 150,
+ 'square',
+ 0,
+ 1
+ ]
+ ],
+ [
+ 'action' => 'imageCircularCopy', // 写入用户头像
+ 'data' => [
+ !empty($member_info[ 'headimg' ]) ? $member_info[ 'headimg' ] : 'public/static/img/default_img/head.png',
+ 65,
+ 1020,
+ 100,
+ 100
+ ]
+ ],
+ [
+ 'action' => 'imageText', // 写入分享人昵称
+ 'data' => [
+ $member_info[ 'nickname' ],
+ 22,
+ [ 255, 129, 61 ],
+ 180,
+ 1060,
+ 440,
+ 1,
+ true,
+ 1
+ ]
+ ]
+ ];
+ } else {
+ $params = $template_info;
+ $poster = new PosterExtend(740, 1250);
+ $fontRate = 0.725;
+ $nickname_color = is_array($params[ 'template_json' ][ 'nickname_color' ]) ? $params[ 'template_json' ][ 'nickname_color' ] : hex2rgb($params[ 'template_json' ][ 'nickname_color' ]);
+
+ $option = [
+ [
+ 'action' => 'imageCopy', // 写入背景图
+ 'data' => [
+ img($params[ 'background' ]),
+ 0,
+ 0,
+ 740,
+ 1250,
+ 'square',
+ 0,
+ 1
+ ]
+ ],
+ [
+ 'action' => 'imageCopy', // 写入二维码
+ 'data' => [
+ $qrcode_info[ 'data' ][ 'path' ],
+ (int) $params[ 'qrcode_left' ] * 2,
+ (int) $params[ 'qrcode_top' ] * 2,
+ (int) $params[ 'qrcode_width' ] * 2,
+ (int) $params[ 'qrcode_height' ] * 2,
+ 'square',
+ 0,
+ 1
+ ]
+ ],
+ [
+ 'action' => 'imageText', // 写入分享语
+ 'data' => [
+ $params[ 'template_json' ][ 'share_content' ],
+ $params[ 'template_json' ][ 'share_content_font_size' ] * $fontRate * 2,
+ is_array($params[ 'template_json' ][ 'share_content_color' ]) ? $params[ 'template_json' ][ 'share_content_color' ] : hex2rgb($params[ 'template_json' ][ 'share_content_color' ]),
+ $params[ 'template_json' ][ 'share_content_left' ] * 2,
+ ( $params[ 'template_json' ][ 'share_content_top' ] + $params[ 'template_json' ][ 'share_content_font_size' ] ) * 2,
+ $params[ 'template_json' ][ 'share_content_width' ] * 2,
+ 1
+ ]
+ ],
+ [
+ 'action' => 'imageCopy', // 写入用户头像
+ 'data' => [
+ !empty($member_info[ 'headimg' ]) ? img($member_info[ 'headimg' ]) : img('public/static/img/default_img/head.png'),
+ $params[ 'template_json' ][ 'headimg_left' ] * 2,
+ $params[ 'template_json' ][ 'headimg_top' ] * 2,
+ $params[ 'template_json' ][ 'headimg_width' ] * 2,
+ $params[ 'template_json' ][ 'headimg_height' ] * 2,
+ !empty($params[ 'template_json' ][ 'headimg_shape' ]) ? $params[ 'template_json' ][ 'headimg_shape' ] : 'square',
+ 0,
+ $params[ 'template_json' ][ 'headimg_is_show' ]
+ ]
+ ],
+ [
+ 'action' => 'imageText', // 写入分享人昵称
+ 'data' => [
+ $member_info[ 'nickname' ],
+ $params[ 'template_json' ][ 'nickname_font_size' ] * $fontRate * 2,
+ $nickname_color,
+ $params[ 'template_json' ][ 'nickname_left' ] * 2,
+ ( $params[ 'template_json' ][ 'nickname_top' ] + $params[ 'template_json' ][ 'nickname_font_size' ] ) * 2,
+ $params[ 'template_json' ][ 'nickname_width' ] * 2,
+ 1,
+ true,
+ $params[ 'template_json' ][ 'nickname_is_show' ]
+ ]
+ ],
+ ];
+
+ }
+ $option_res = $poster->create($option);
+
+ if (is_array($option_res)) return $option_res;
+ $pic_name = "";
+ if (!empty($params)) {
+ $pic_name = md5(json_encode([
+ 'id' => $params[ 'template_id' ],
+ 'poster_name' => $params[ 'poster_name' ]
+ ]));
+ $pic_name = "_" . $pic_name;
+ }
+
+ $res = $option_res->jpeg('upload/poster/distribution', 'distribution_' . $qrcode_param[ 'source_member' ] . $pic_name . '_' . $app_type);
+ if ($res[ 'code' ] == 0) {
+ $upload = new Upload($site_id);
+ $cloud_res = $upload->fileCloud($res[ 'data' ][ 'path' ]);
+ if ($cloud_res[ 'code' ] >= 0) {
+ return $this->success([ "path" => $cloud_res[ 'data' ] ]);
+ } else {
+ return $this->error();
+ }
+ }
+ return $res;
+ } catch (\Exception $e) {
+ return $this->error($e->getMessage() . $e->getFile() . $e->getLine());
+ }
+ }
+
+ /**
+ * 获取用户信息
+ * @param $member_id
+ * @return mixed
+ */
+ private function getMemberInfo($member_id)
+ {
+ $info = model('member')->getInfo([ 'member_id' => $member_id ], 'nickname,headimg');
+ return $info;
+ }
+
+ /**
+ * 获取二维码
+ * @param unknown $app_type 请求类型
+ * @param unknown $page uniapp页面路径
+ * @param unknown $qrcode_param 二维码携带参数
+ * @param string $promotion_type 活动类型 null为无活动
+ */
+ private function getQrcode($app_type, $page, $qrcode_param, $site_id)
+ {
+ $res = event('Qrcode', [
+ 'site_id' => $site_id,
+ 'app_type' => $app_type,
+ 'type' => 'get',
+ 'data' => $qrcode_param,
+ 'page' => $page,
+ 'qrcode_path' => 'upload/qrcode/distribution',
+ 'qrcode_name' => 'distribution' . '_' . $qrcode_param[ 'source_member' ] . '_' . $site_id,
+ ], true);
+ return $res;
+ }
+
+ /**
+ * 获取分销海报
+ * @param $param
+ * @return array|\extend\multitype|PosterExtend|mixed|string|void
+ */
+ public function getFenxiaoPoster($param)
+ {
+ $app_type = $param[ 'app_type' ] ?? 'h5';
+ $qrcode_param = $param[ 'qrcode_param' ] ?? [];
+ $site_id = $param[ 'site_id' ] ?? 0;
+ $page = $param[ 'page' ] ?? '';
+ $template_id = $param[ 'template_id' ] ?? 'default';
+
+ if ($template_id == 'default') {
+ //默认海报
+ $template_info = null;
+ } else {
+ //设置的海报
+ $template_info = model('poster_template')->getInfo([
+ [ 'site_id', '=', $site_id ],
+ [ 'template_type', '=', 'fenxiao' ],
+ [ 'template_status', '=', 1 ],
+ [ 'template_id', '=', $template_id ],
+ ]);
+ if (empty($template_info)) return $this->error(null, '模板信息有误');
+ $template_info[ 'template_json' ] = json_decode($template_info[ 'template_json' ], true);
+ }
+ $res = $this->distribution($app_type, $page, $qrcode_param, $site_id, $template_info);
+ return $res;
+ }
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/model/share/WchatShare.php b/src/addon/fenxiao/model/share/WchatShare.php
index 838eff864..6fbd43145 100644
--- a/src/addon/fenxiao/model/share/WchatShare.php
+++ b/src/addon/fenxiao/model/share/WchatShare.php
@@ -1,114 +1,105 @@
- '分销推广',
- 'config_key' => 'WCHAT_SHARE_CONFIG_FENXIAO_PROMOTE',
- 'path' => [ '/pages_promotion/fenxiao/promote_code' ],
- 'method_prefix' => 'promote',
- ],
- ];
-
- protected $sort = 3;
-
- /**
- * 推广分享数据
- * @param $param
- * @return array
- */
- protected function promoteShareData($param)
- {
- $site_id = $param[ 'site_id' ] ?? 0;
- $member_id = $param[ 'member_id' ] ?? 0;
- $param[ 'url' ] = str_replace("/pages_promotion/fenxiao/promote_code", "/pages/index/index", $param[ 'url' ]);
- if (strpos($param[ 'url' ], '?')) $param[ 'url' ] = explode('?', $param[ 'url' ])[ 0 ];
-
- //站点设置
- $site_model = new SiteModel();
- $site_info = $site_model->getSiteInfo([ [ 'site_id', '=', $site_id ] ])[ 'data' ];
-
- //跳转路径
- $link = $this->getShareLink($param);
-
- //会员信息
- $member_model = new MemberModel();
- $member_info = $member_model->getMemberInfo([ [ 'member_id', '=', $member_id ] ], 'nickname, headimg')[ 'data' ];
-
- //获取和替换配置数据
- $config_data = $this->promoteShareConfig($param);
- $title = str_replace('{nickname}', $member_info[ 'nickname' ], $config_data[ 'value' ][ 'title' ]);
- $desc = str_replace('{nickname}', $member_info[ 'nickname' ], $config_data[ 'value' ][ 'desc' ]);
- $image_url = $config_data[ 'value' ][ 'imgUrl' ] ?: $site_info[ 'logo_square' ];
-
- $data = [
- 'title' => $title,
- 'desc' => $desc,
- 'link' => $link,
- 'imgUrl' => $image_url,
- ];
- return [
- 'permission' => [
- 'hideOptionMenu' => false,
- 'hideMenuItems' => [],
- ],
- 'data' => $data,//分享内容
- ];
- }
-
- /**
- * 推广分享配置
- * @param $param
- * @return array
- */
- protected function promoteShareConfig($param)
- {
- $site_id = $param[ 'site_id' ];
- $config = $param[ 'config' ];
-
- $config_model = new ConfigModel();
- $data = $config_model->getConfig([
- [ 'site_id', '=', $site_id ],
- [ 'app_module', '=', 'shop' ],
- [ 'config_key', '=', $config[ 'config_key' ] ],
- ])[ 'data' ];
- if (empty($data[ 'value' ])) {
- $data[ 'value' ] = [
- 'title' => "快来加入{nickname}的团队吧,一起赚佣金哦",
- 'desc' => "好物精选\n向您推荐",
- 'imgUrl' => '',
- ];
- }
- if (empty($data[ 'value' ][ 'imgUrl' ])) {
- $data[ 'value' ][ 'imgUrl' ] = img('addon/fenxiao/icon.png');
- }
- $variable = [
- [ 'title' => '用户昵称', 'name' => '{nickname}' ],
- ];
-
- return [
- 'value' => $data[ 'value' ],
- 'variable' => $variable,
- ];
- }
-}
+ '分销推广',
+ 'config_key' => 'WCHAT_SHARE_CONFIG_FENXIAO_PROMOTE',
+ 'path' => [ '/pages_promotion/fenxiao/promote_code' ],
+ 'method_prefix' => 'promote',
+ ],
+ ];
+
+ protected $sort = 3;
+
+ /**
+ * 推广分享数据
+ * @param $param
+ * @return array
+ */
+ protected function promoteShareData($param)
+ {
+ $site_id = $param[ 'site_id' ] ?? 0;
+ $member_id = $param[ 'member_id' ] ?? 0;
+ $param[ 'url' ] = str_replace("/pages_promotion/fenxiao/promote_code", "/pages/index/index", $param[ 'url' ]);
+ if (strpos($param[ 'url' ], '?')) $param[ 'url' ] = explode('?', $param[ 'url' ])[ 0 ];
+
+ //站点设置
+ $site_model = new SiteModel();
+ $site_info = $site_model->getSiteInfo([ [ 'site_id', '=', $site_id ] ])[ 'data' ];
+
+ //跳转路径
+ $link = $this->getShareLink($param);
+
+ //会员信息
+ $member_model = new MemberModel();
+ $member_info = $member_model->getMemberInfo([ [ 'member_id', '=', $member_id ] ], 'nickname, headimg')[ 'data' ];
+
+ //获取和替换配置数据
+ $config_data = $this->promoteShareConfig($param);
+ $title = str_replace('{nickname}', $member_info[ 'nickname' ], $config_data[ 'value' ][ 'title' ]);
+ $desc = str_replace('{nickname}', $member_info[ 'nickname' ], $config_data[ 'value' ][ 'desc' ]);
+ $image_url = $config_data[ 'value' ][ 'imgUrl' ] ?: $site_info[ 'logo_square' ];
+
+ $data = [
+ 'title' => $title,
+ 'desc' => $desc,
+ 'link' => $link,
+ 'imgUrl' => $image_url,
+ ];
+ return [
+ 'permission' => [
+ 'hideOptionMenu' => false,
+ 'hideMenuItems' => [],
+ ],
+ 'data' => $data,//分享内容
+ ];
+ }
+
+ /**
+ * 推广分享配置
+ * @param $param
+ * @return array
+ */
+ protected function promoteShareConfig($param)
+ {
+ $site_id = $param[ 'site_id' ];
+ $config = $param[ 'config' ];
+
+ $config_model = new ConfigModel();
+ $data = $config_model->getConfig([
+ [ 'site_id', '=', $site_id ],
+ [ 'app_module', '=', 'shop' ],
+ [ 'config_key', '=', $config[ 'config_key' ] ],
+ ])[ 'data' ];
+ if (empty($data[ 'value' ])) {
+ $data[ 'value' ] = [
+ 'title' => "快来加入{nickname}的团队吧,一起赚佣金哦",
+ 'desc' => "好物精选\n向您推荐",
+ 'imgUrl' => '',
+ ];
+ }
+ if (empty($data[ 'value' ][ 'imgUrl' ])) {
+ $data[ 'value' ][ 'imgUrl' ] = img('addon/fenxiao/icon.png');
+ }
+ $variable = [
+ [ 'title' => '用户昵称', 'name' => '{nickname}' ],
+ ];
+
+ return [
+ 'value' => $data[ 'value' ],
+ 'variable' => $variable,
+ ];
+ }
+}
diff --git a/src/addon/fenxiao/model/share/WeappShare.php b/src/addon/fenxiao/model/share/WeappShare.php
index a59735bf3..dcedd4d30 100644
--- a/src/addon/fenxiao/model/share/WeappShare.php
+++ b/src/addon/fenxiao/model/share/WeappShare.php
@@ -1,100 +1,91 @@
- '分销推广',
- 'config_key' => 'WEAPP_SHARE_CONFIG_FENXIAO_PROMOTE',
- 'path' => [ '/pages_promotion/fenxiao/promote_code' ],
- 'method_prefix' => 'promote',
- ],
- ];
-
- protected $sort = 2;
-
- /**
- * 首页分享数据
- * @param $param
- * @return array
- */
- protected function promoteShareData($param)
- {
- $member_id = $param[ 'member_id' ] ?? 0;
- $param[ 'path' ] = str_replace("/pages_promotion/fenxiao/promote_code", "/pages/index/index", $param[ 'path' ]);
- if (strpos($param[ 'path' ], '?')) $param[ 'path' ] = explode('?', $param[ 'path' ])[ 0 ];
-
- //会员信息
- $member_model = new MemberModel();
- $member_info = $member_model->getMemberInfo([ [ 'member_id', '=', $member_id ] ], 'nickname, headimg')[ 'data' ];
-
- //获取和替换配置数据
- $config_data = $this->promoteShareConfig($param);
- $title = str_replace('{nickname}', $member_info[ 'nickname' ], $config_data[ 'value' ][ 'title' ]);
- $image_url = $config_data[ 'value' ][ 'imageUrl' ] ? img($config_data[ 'value' ][ 'imageUrl' ]) : '';
- $path = $this->getSharePath($param);
-
- $data = [
- 'title' => $title,
- 'path' => $path,
- 'imageUrl' => $image_url,
- ];
- return [
- 'permission' => [
- 'onShareAppMessage' => true,
- 'onShareTimeline' => true,
- ],
- 'data' => $data,//分享内容
- ];
- }
-
- /**
- * 首页分享配置
- * @param $param
- * @return array
- */
- protected function promoteShareConfig($param)
- {
- $site_id = $param[ 'site_id' ];
- $config = $param[ 'config' ];
-
- $config_model = new ConfigModel();
- $data = $config_model->getConfig([
- [ 'site_id', '=', $site_id ],
- [ 'app_module', '=', 'shop' ],
- [ 'config_key', '=', $config[ 'config_key' ] ],
- ])[ 'data' ];
- if (empty($data[ 'value' ])) {
- $data[ 'value' ] = [
- 'title' => '快来加入{nickname}的团队吧,一起赚有佣金哦',
- 'imageUrl' => '',
- ];
- }
- $variable = [
- [ 'title' => '用户昵称', 'name' => '{nickname}' ],
- ];
-
- return [
- 'value' => $data[ 'value' ],
- 'variable' => $variable,
- ];
- }
-}
+ '分销推广',
+ 'config_key' => 'WEAPP_SHARE_CONFIG_FENXIAO_PROMOTE',
+ 'path' => [ '/pages_promotion/fenxiao/promote_code' ],
+ 'method_prefix' => 'promote',
+ ],
+ ];
+
+ protected $sort = 2;
+
+ /**
+ * 首页分享数据
+ * @param $param
+ * @return array
+ */
+ protected function promoteShareData($param)
+ {
+ $member_id = $param[ 'member_id' ] ?? 0;
+ $param[ 'path' ] = str_replace("/pages_promotion/fenxiao/promote_code", "/pages/index/index", $param[ 'path' ]);
+ if (strpos($param[ 'path' ], '?')) $param[ 'path' ] = explode('?', $param[ 'path' ])[ 0 ];
+
+ //会员信息
+ $member_model = new MemberModel();
+ $member_info = $member_model->getMemberInfo([ [ 'member_id', '=', $member_id ] ], 'nickname, headimg')[ 'data' ];
+
+ //获取和替换配置数据
+ $config_data = $this->promoteShareConfig($param);
+ $title = str_replace('{nickname}', $member_info[ 'nickname' ], $config_data[ 'value' ][ 'title' ]);
+ $image_url = $config_data[ 'value' ][ 'imageUrl' ] ? img($config_data[ 'value' ][ 'imageUrl' ]) : '';
+ $path = $this->getSharePath($param);
+
+ $data = [
+ 'title' => $title,
+ 'path' => $path,
+ 'imageUrl' => $image_url,
+ ];
+ return [
+ 'permission' => [
+ 'onShareAppMessage' => true,
+ 'onShareTimeline' => true,
+ ],
+ 'data' => $data,//分享内容
+ ];
+ }
+
+ /**
+ * 首页分享配置
+ * @param $param
+ * @return array
+ */
+ protected function promoteShareConfig($param)
+ {
+ $site_id = $param[ 'site_id' ];
+ $config = $param[ 'config' ];
+
+ $config_model = new ConfigModel();
+ $data = $config_model->getConfig([
+ [ 'site_id', '=', $site_id ],
+ [ 'app_module', '=', 'shop' ],
+ [ 'config_key', '=', $config[ 'config_key' ] ],
+ ])[ 'data' ];
+ if (empty($data[ 'value' ])) {
+ $data[ 'value' ] = [
+ 'title' => '快来加入{nickname}的团队吧,一起赚有佣金哦',
+ 'imageUrl' => '',
+ ];
+ }
+ $variable = [
+ [ 'title' => '用户昵称', 'name' => '{nickname}' ],
+ ];
+
+ return [
+ 'value' => $data[ 'value' ],
+ 'variable' => $variable,
+ ];
+ }
+}
diff --git a/src/addon/fenxiao/shop/controller/Config.php b/src/addon/fenxiao/shop/controller/Config.php
index 5bb3c58a1..7b64452a6 100644
--- a/src/addon/fenxiao/shop/controller/Config.php
+++ b/src/addon/fenxiao/shop/controller/Config.php
@@ -1,201 +1,193 @@
-isJson()) {
- $data = [
- 'level' => input('level', ''),//分销层级
- 'internal_buy' => input('internal_buy', ''),//分销内购
- 'is_examine' => input('is_examine', ''),//是否需要审核(0关闭 1开启)
- 'self_purchase_rebate' => input('self_purchase_rebate', ''),//是否开启分销商自购返佣(0关闭 1开启)
- 'fenxiao_condition' => input('fenxiao_condition', ''),//成为分销商条件(0无条件 1申请 2消费次数 3消费金额 4购买指定商品)
- 'consume_count' => input('consume_count', ''),//消费次数
- 'consume_money' => input('consume_money', ''), //消费金额
- 'goods_ids' => input('goods_ids', ''), //指定商品id
- 'consume_condition' => input('consume_condition', ''),//消费条件(1付款后 2订单完成)
- 'perfect_info' => input('perfect_info', ''),//完善资料
- 'child_condition' => input('child_condition', ''),//成为下线条件
- 'is_apply' => input('is_apply', ''),//是否开启分销申请(0关闭 1开启)
- 'is_commission_money' => input('is_commission_money', ''),//是否开启商品详情一级佣金(0关闭 1开启)
- 'one_rate' => input('one_rate', 0.00),
- 'two_rate' => input('two_rate', 0.00),
- 'three_rate' => input('three_rate', 0.00),
- ];
-
- $res = $model->setFenxiaoBasicsConfig($data, 1, $this->site_id);
- return $res;
- } else {
- $basics = $model->getFenxiaoBasicsConfig($this->site_id);
- $this->assign('basics_info', $basics[ 'data' ][ 'value' ]);
-
- $fenxiao = $model->getFenxiaoConfig($this->site_id)[ 'data' ][ 'value' ];
-
- $fenxiao[ 'goods_list' ] = '';
- if ($fenxiao[ 'fenxiao_condition' ] == 4) { // 购买指定商品
- $goods_model = new GoodsModel();
- $condition[] = [ 'goods_id', 'in', $fenxiao[ 'goods_ids' ] ];
- $condition[] = [ 'site_id', '=', $this->site_id ];
- $fenxiao[ 'goods_list' ] = $goods_model->getGoodsList($condition, 'goods_id,goods_name,goods_image,price,goods_stock')[ 'data' ];
- }
- $this->assign('fenxiao_info', $fenxiao);
-
- $relation = $model->getFenxiaoRelationConfig($this->site_id);
- $this->assign('relation_info', $relation[ 'data' ][ 'value' ]);
-
- $level_model = new FenxiaoLevelModel();
- $level_info = $level_model->getLevelInfo([ [ 'site_id', '=', $this->site_id ], [ 'is_default', '=', 1 ] ], 'one_rate,two_rate,three_rate')[ 'data' ];
- $this->assign('level', $level_info);
-
-
- return $this->fetch('config/basics');
- }
-
- }
-
- /**
- * 分销协议设置
- */
- public function agreement()
- {
- $model = new ConfigModel();
-
- if (request()->isJson()) {
- $data = [
- 'is_agreement' => input('is_agreement', ''),//是否显示申请协议
- 'agreement_title' => input('agreement_title', ''),//协议标题
- 'agreement_content' => input('agreement_content', ''),//协议内容
- 'img' => input('img', ''),//申请页面顶部图片
- ];
- $res = $model->setFenxiaoAgreementConfig($data, 1, $this->site_id);
- return $res;
- } else {
- $agreement = $model->getFenxiaoAgreementConfig($this->site_id);
- $this->assign('agreement_info', $agreement[ 'data' ][ 'value' ]);
-
- $document_model = new Document();
- $document = $document_model->getDocument([ [ 'site_id', '=', $this->site_id ], [ 'app_module', '=', 'shop' ], [ 'document_key', '=', 'FENXIAO_AGREEMENT'] ]);
- $this->assign('document', $document[ 'data' ]);
-
-
- return $this->fetch('config/agreement');
- }
- }
-
- /**
- * 分销结算设置
- */
- public function settlement()
- {
- $model = new ConfigModel();
- if (request()->isJson()) {
- $transfer_type = '';
- if (!empty(input('transfer_type'))) {
- $transfer_type = implode(',', input('transfer_type'));
- }
- $data = [
- 'account_type' => input('account_type', ''),//佣金计算方式
- 'settlement_day' => input('settlement_day', ''),//天数
- 'withdraw' => input('withdraw', ''),//最低提现额度
- 'withdraw_rate' => input('withdraw_rate', ''),//佣金提现手续费
-// 'min_no_fee' => input('min_no_fee', ''),//最低免手续费区间
-// 'max_no_fee' => input('max_no_fee', ''),//最高免手续费区间
- 'withdraw_status' => input('withdraw_status', ''),//提现审核
- 'withdraw_type' => input('withdraw_type', ''),//提现方式,
-
- 'transfer_type' => $transfer_type,//转账方式,
- 'is_auto_transfer' => input('is_auto_transfer', 0),//是否自动转账 1 手动转账 2 自动转账
-// 'min' => input('min', 0),//提现最低额度
- 'max' => input('max', 0),//提现最高额度
- ];
- $res = $model->setFenxiaoSettlementConfig($data, 1, $this->site_id);
- return $res;
- } else {
-// $settlement = $model->getFenxiaoSettlementConfig($this->site_id);
-// $this->assign('settlement_info', $settlement[ 'data' ][ 'value' ]);
- $withdraw_config = $model->getFenxiaoWithdrawConfig($this->site_id)[ 'data' ][ 'value' ] ?? [];
- $this->assign('withdraw_info', $withdraw_config);
-
- $fenxiao_withdraw_model = new FenxiaoWithdraw();
- $transfer_type_list = $fenxiao_withdraw_model->getTransferType($this->site_id);
- $transfer_type_list[ 'balance' ] = '余额';
- $this->assign('transfer_type_list', $transfer_type_list);
-
- return $this->fetch('config/settlement');
- }
-
- }
-
- /**
- * 分销文字设置
- */
- public function words()
- {
- $model = new ConfigModel();
- if (request()->isJson()) {
- $data = [
- 'concept' => input('concept', ''),//分销概念
- 'fenxiao_name' => input('fenxiao_name', ''),//分销商名称
- 'withdraw' => input('withdraw', ''),//提现名称
- 'account' => input('account', ''),//佣金
- 'my_team' => input('my_team', ''),//我的团队
- 'child' => input('child', ''),//下线
- ];
-
- $res = $model->setFenxiaoWordsConfig($data, 1, $this->site_id);
- return $res;
- } else {
- $config_info = $model->getFenxiaoWordsConfig($this->site_id)[ 'data' ][ 'value' ];
- $this->assign('config_info', $config_info);
-
-
- return $this->fetch('config/words');
- }
-
- }
-
- /**
- * 活动规则
- */
- public function promoteRule()
- {
- $document_model = new Document();
- if (request()->isJson()) {
- $content = input('content', '');
- $res = $document_model->setDocument('分销推广规则', $content, [ [ 'site_id', '=', $this->site_id ], [ 'app_module', '=', 'shop' ], [ 'document_key', '=', 'FENXIAO_PROMOTE_RULE'] ]);
- return $res;
- } else {
- $document = $document_model->getDocument([ [ 'site_id', '=', $this->site_id ], [ 'app_module', '=', 'shop' ], [ 'document_key', '=', 'FENXIAO_PROMOTE_RULE'] ]);
- $this->assign('document', $document[ 'data' ]);
-
- return $this->fetch('config/promote_rule');
- }
- }
+isJson()) {
+ $data = [
+ 'level' => input('level', ''),//分销层级
+ 'internal_buy' => input('internal_buy', ''),//分销内购
+ 'is_examine' => input('is_examine', ''),//是否需要审核(0关闭 1开启)
+ 'self_purchase_rebate' => input('self_purchase_rebate', ''),//是否开启分销商自购返佣(0关闭 1开启)
+ 'fenxiao_condition' => input('fenxiao_condition', ''),//成为分销商条件(0无条件 1申请 2消费次数 3消费金额 4购买指定商品)
+ 'consume_count' => input('consume_count', ''),//消费次数
+ 'consume_money' => input('consume_money', ''), //消费金额
+ 'goods_ids' => input('goods_ids', ''), //指定商品id
+ 'consume_condition' => input('consume_condition', ''),//消费条件(1付款后 2订单完成)
+ 'perfect_info' => input('perfect_info', ''),//完善资料
+ 'child_condition' => input('child_condition', ''),//成为下线条件
+ 'is_apply' => input('is_apply', ''),//是否开启分销申请(0关闭 1开启)
+ 'is_commission_money' => input('is_commission_money', ''),//是否开启商品详情一级佣金(0关闭 1开启)
+ 'one_rate' => input('one_rate', 0.00),
+ 'two_rate' => input('two_rate', 0.00),
+ 'three_rate' => input('three_rate', 0.00),
+ ];
+
+ $res = $model->setFenxiaoBasicsConfig($data, 1, $this->site_id);
+ return $res;
+ } else {
+ $basics = $model->getFenxiaoBasicsConfig($this->site_id);
+ $this->assign('basics_info', $basics[ 'data' ][ 'value' ]);
+
+ $fenxiao = $model->getFenxiaoConfig($this->site_id)[ 'data' ][ 'value' ];
+
+ $fenxiao[ 'goods_list' ] = '';
+ if ($fenxiao[ 'fenxiao_condition' ] == 4) { // 购买指定商品
+ $goods_model = new GoodsModel();
+ $condition[] = [ 'goods_id', 'in', $fenxiao[ 'goods_ids' ] ];
+ $condition[] = [ 'site_id', '=', $this->site_id ];
+ $fenxiao[ 'goods_list' ] = $goods_model->getGoodsList($condition, 'goods_id,goods_name,goods_image,price,goods_stock')[ 'data' ];
+ }
+ $this->assign('fenxiao_info', $fenxiao);
+
+ $relation = $model->getFenxiaoRelationConfig($this->site_id);
+ $this->assign('relation_info', $relation[ 'data' ][ 'value' ]);
+
+ $level_model = new FenxiaoLevelModel();
+ $level_info = $level_model->getLevelInfo([ [ 'site_id', '=', $this->site_id ], [ 'is_default', '=', 1 ] ], 'one_rate,two_rate,three_rate')[ 'data' ];
+ $this->assign('level', $level_info);
+
+
+ return $this->fetch('config/basics');
+ }
+
+ }
+
+ /**
+ * 分销协议设置
+ */
+ public function agreement()
+ {
+ $model = new ConfigModel();
+
+ if (request()->isJson()) {
+ $data = [
+ 'is_agreement' => input('is_agreement', ''),//是否显示申请协议
+ 'agreement_title' => input('agreement_title', ''),//协议标题
+ 'agreement_content' => input('agreement_content', ''),//协议内容
+ 'img' => input('img', ''),//申请页面顶部图片
+ ];
+ $res = $model->setFenxiaoAgreementConfig($data, 1, $this->site_id);
+ return $res;
+ } else {
+ $agreement = $model->getFenxiaoAgreementConfig($this->site_id);
+ $this->assign('agreement_info', $agreement[ 'data' ][ 'value' ]);
+
+ $document_model = new Document();
+ $document = $document_model->getDocument([ [ 'site_id', '=', $this->site_id ], [ 'app_module', '=', 'shop' ], [ 'document_key', '=', 'FENXIAO_AGREEMENT'] ]);
+ $this->assign('document', $document[ 'data' ]);
+
+
+ return $this->fetch('config/agreement');
+ }
+ }
+
+ /**
+ * 分销结算设置
+ */
+ public function settlement()
+ {
+ $model = new ConfigModel();
+ if (request()->isJson()) {
+ $transfer_type = '';
+ if (!empty(input('transfer_type'))) {
+ $transfer_type = implode(',', input('transfer_type'));
+ }
+ $data = [
+ 'account_type' => input('account_type', ''),//佣金计算方式
+ 'settlement_day' => input('settlement_day', ''),//天数
+ 'withdraw' => input('withdraw', ''),//最低提现额度
+ 'withdraw_rate' => input('withdraw_rate', ''),//佣金提现手续费
+// 'min_no_fee' => input('min_no_fee', ''),//最低免手续费区间
+// 'max_no_fee' => input('max_no_fee', ''),//最高免手续费区间
+ 'withdraw_status' => input('withdraw_status', ''),//提现审核
+ 'withdraw_type' => input('withdraw_type', ''),//提现方式,
+
+ 'transfer_type' => $transfer_type,//转账方式,
+ 'is_auto_transfer' => input('is_auto_transfer', 0),//是否自动转账 1 手动转账 2 自动转账
+// 'min' => input('min', 0),//提现最低额度
+ 'max' => input('max', 0),//提现最高额度
+ ];
+ $res = $model->setFenxiaoSettlementConfig($data, 1, $this->site_id);
+ return $res;
+ } else {
+// $settlement = $model->getFenxiaoSettlementConfig($this->site_id);
+// $this->assign('settlement_info', $settlement[ 'data' ][ 'value' ]);
+ $withdraw_config = $model->getFenxiaoWithdrawConfig($this->site_id)[ 'data' ][ 'value' ] ?? [];
+ $this->assign('withdraw_info', $withdraw_config);
+
+ $fenxiao_withdraw_model = new FenxiaoWithdraw();
+ $transfer_type_list = $fenxiao_withdraw_model->getTransferType($this->site_id);
+ $transfer_type_list[ 'balance' ] = '余额';
+ $this->assign('transfer_type_list', $transfer_type_list);
+
+ return $this->fetch('config/settlement');
+ }
+
+ }
+
+ /**
+ * 分销文字设置
+ */
+ public function words()
+ {
+ $model = new ConfigModel();
+ if (request()->isJson()) {
+ $data = [
+ 'concept' => input('concept', ''),//分销概念
+ 'fenxiao_name' => input('fenxiao_name', ''),//分销商名称
+ 'withdraw' => input('withdraw', ''),//提现名称
+ 'account' => input('account', ''),//佣金
+ 'my_team' => input('my_team', ''),//我的团队
+ 'child' => input('child', ''),//下线
+ ];
+
+ $res = $model->setFenxiaoWordsConfig($data, 1, $this->site_id);
+ return $res;
+ } else {
+ $config_info = $model->getFenxiaoWordsConfig($this->site_id)[ 'data' ][ 'value' ];
+ $this->assign('config_info', $config_info);
+
+
+ return $this->fetch('config/words');
+ }
+
+ }
+
+ /**
+ * 活动规则
+ */
+ public function promoteRule()
+ {
+ $document_model = new Document();
+ if (request()->isJson()) {
+ $content = input('content', '');
+ $res = $document_model->setDocument('分销推广规则', $content, [ [ 'site_id', '=', $this->site_id ], [ 'app_module', '=', 'shop' ], [ 'document_key', '=', 'FENXIAO_PROMOTE_RULE'] ]);
+ return $res;
+ } else {
+ $document = $document_model->getDocument([ [ 'site_id', '=', $this->site_id ], [ 'app_module', '=', 'shop' ], [ 'document_key', '=', 'FENXIAO_PROMOTE_RULE'] ]);
+ $this->assign('document', $document[ 'data' ]);
+
+ return $this->fetch('config/promote_rule');
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/shop/controller/Fenxiao.php b/src/addon/fenxiao/shop/controller/Fenxiao.php
index 936d36458..e90ff278a 100644
--- a/src/addon/fenxiao/shop/controller/Fenxiao.php
+++ b/src/addon/fenxiao/shop/controller/Fenxiao.php
@@ -1,694 +1,686 @@
-replace = [
- 'FENXIAO_JS' => __ROOT__ . '/addon/fenxiao/shop/view/public/js',
- 'FENXIAO_CSS' => __ROOT__ . '/addon/fenxiao/shop/view/public/css'
- ];
- parent::__construct($app);
- }
-
- /**
- * 分销概况
- */
- public function index()
- {
- return $this->fetch('fenxiao/index');
- }
-
- public function stat()
- {
- $data = [
- 'account_data' => [],
- 'fenxiao_account' => 0.00,
- 'shop_commission' => [],
- 'shop_commission_end' => [],
- 'commission_money' => 0.00,
- 'fenxiao_apply_num' => 0,
- 'fenxiao_num' => 0,
- 'fenxiao_goods_num' => 0
- ];
-
- $fenxiao_data_model = new FenxiaoData();
- $account_data = $fenxiao_data_model->getFenxiaoAccountData($this->site_id);
- $data['account_data'] = $account_data;
-
- //累计佣金
- $fenxiao_account = number_format($account_data[ 'account' ], 2, '.', '');
- $data['fenxiao_account'] = $fenxiao_account;
-
- //获取分销的总金额
- $order_model = new FenxiaoOrderModel();
- $commission = $order_model->getFenxiaoOrderInfo([ [ 'site_id', '=', $this->site_id ] ], 'sum(real_goods_money) as real_goods_money,sum(commission) as commission')[ 'data' ];
- if ($commission[ 'real_goods_money' ] == null) {
- $commission[ 'real_goods_money' ] = '0.00';
- }
- if ($commission[ 'commission' ] == null) {
- $commission[ 'commission' ] = '0.00';
- }
- $data['shop_commission'] = $commission;
-
- //获取已结算分销的总金额
- $commission_end = $order_model->getFenxiaoOrderInfo([ [ 'site_id', '=', $this->site_id ], [ 'is_settlement', '=', 1 ], [ 'is_refund', '=', 0 ] ], 'sum(real_goods_money) as real_goods_money,sum(commission) as commission')[ 'data' ];
- if ($commission_end[ 'real_goods_money' ] == null) {
- $commission_end[ 'real_goods_money' ] = '0.00';
- }
- if ($commission_end[ 'commission' ] == null) {
- $commission_end[ 'commission' ] = '0.00';
- }
- $data['shop_commission_end'] = $commission_end;
-
- //获取已退款的佣金
- $commission_refund = $order_model->getFenxiaoOrderInfo([ [ 'site_id', '=', $this->site_id ], [ 'is_refund', '=', 1 ] ], 'sum(real_goods_money) as real_goods_money,sum(commission) as commission')[ 'data' ];
- if ($commission_refund[ 'real_goods_money' ] == null) {
- $commission_refund[ 'real_goods_money' ] = '0.00';
- }
- if ($commission_refund[ 'commission' ] == null) {
- $commission_refund[ 'commission' ] = '0.00';
- }
- $commission_money = round($commission[ 'commission' ], 2) - round($commission_end[ 'commission' ], 2) - round($commission_refund[ 'commission' ], 2);
- $commission_money = number_format($commission_money, 2);
- $data['commission_money'] = $commission_money;
-
- $fenxiao_apply_num = $fenxiao_data_model->getFenxiaoApplyCount($this->site_id);
- $data['fenxiao_apply_num'] = $fenxiao_apply_num;
-
- //分销商人数
- $fenxiao_num = $fenxiao_data_model->getFenxiaoCount($this->site_id);
- $data['fenxiao_num'] = $fenxiao_num;
-
- $goods_model = new GoodsModel();
- $fenxiao_goods_num = $goods_model->getGoodsInfo([ [ 'site_id', '=', $this->site_id ], [ 'is_fenxiao', '=', 1 ], [ 'is_delete', '=', 0 ] ], 'count(goods_id) as fenxiao_goods_num')[ 'data' ];
- $data['fenxiao_goods_num'] = $fenxiao_goods_num[ 'fenxiao_goods_num' ];
-
- return $data;
- }
-
-
- /**
- * 分销商列表
- */
- public function lists()
- {
- $model = new FenxiaoModel();
- if (request()->isJson()) {
-
- $condition[] = [ 'f.site_id', '=', $this->site_id ];
- $fenxiao_name = input('fenxiao_name', '');
- $nickname = input('nickname', '');
- $mobile = input('mobile', '');
- $parent_name = input('parent_name', '');
- $level_id = input('level_id', '');
- $start_time = input('start_time', '');
- $end_time = input('end_time', '');
- $status = input('status', '');
-
- if ($fenxiao_name) {
- $condition[] = [ 'f.fenxiao_name', 'like', '%' . $fenxiao_name . '%' ];
- }
- if ($nickname) {
- $condition[] = [ 'm.nickname', 'like', '%' . $nickname . '%' ];
- }
- if ($mobile) {
- $condition[] = [ 'm.mobile', 'like', '%' . $mobile . '%' ];
- }
-
- if ($parent_name) {
- $condition[] = [ 'pf.fenxiao_name', 'like', '%' . $parent_name . '%' ];
- }
-
- if ($level_id) {
- $condition[] = [ 'f.level_id', '=', $level_id ];
- }
- if ($start_time && $end_time) {
- $condition[] = [ 'f.create_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
- } elseif (!$start_time && $end_time) {
- $condition[] = [ 'f.create_time', '<=', date_to_time($end_time) ];
-
- } elseif ($start_time && !$end_time) {
- $condition[] = [ 'f.create_time', '>=', date_to_time($start_time) ];
- }
-
- if (!empty($status)) {
- $condition[] = [ 'f.status', '=', $status ];
- }
- $page = input('page', 1);
- $page_size = input('page_size', PAGE_LIST_ROWS);
- $list = $model->getFenxiaoPageList($condition, $page, $page_size, 'f.create_time desc', $this->site_id);
- return $list;
-
- } else {
- $level_model = new FenxiaoLevelModel();
- $level_list = $level_model->getLevelList([ [ 'status', '=', 1 ], [ 'site_id', '=', $this->site_id ] ], 'level_id,level_name')[ 'data' ];
- $this->assign('level_list', $level_list);
-
- $config_model = new ConfigModel();
- $basics = $config_model->getFenxiaoBasicsConfig($this->site_id)[ 'data' ][ 'value' ];
- $this->assign('basics_info', $basics);
-
-
- return $this->fetch('fenxiao/lists');
- }
- }
-
- /**
- * 添加分销商
- */
- public function add()
- {
- if (request()->isJson()) {
-
- $fenxiao_data = [
- 'site_id' => $this->site_id,
- 'fenxiao_name' => input('fenxiao_name', ''),//分销商名称
- 'level_id' => input('level_id', 0),//分销商等级
- 'parent' => input('fenxiao_id', 0),//上级分销商ID
- 'member_id' => input('member_id', 0),//关联会员ID
- ];
- $apply_model = new FenxiaoApply();
- return $apply_model->addFenxiao($fenxiao_data);
-
- } else {
-
- //获取分销商等级
- $level_model = new FenxiaoLevelModel();
- $level_list = $level_model->getLevelList([ [ 'status', '=', 1 ], [ 'site_id', '=', $this->site_id ] ], 'level_id,level_name')[ 'data' ];
- $this->assign('level_list', $level_list);
-
- //获取分销商列表
- $fenxiao_model = new FenxiaoModel();
- $condition[] = [ 'status', '=', '1' ];
- $fenxiao_list = $fenxiao_model->getFenxiaoList($condition, 'fenxiao_id,fenxiao_name')[ 'data' ];
- $this->assign('fenxiao_list', $fenxiao_list);
-
- //获取会员列表
- $member_model = new MemberModel();
- $where[] = [ 'is_fenxiao', '=', '0' ];
- $member_list = $member_model->getMemberList($where, 'member_id,nickname')[ 'data' ];
- $this->assign('member_list', $member_list);
-
- return $this->fetch('fenxiao/add');
- }
-
- }
-
- /**
- * 获取分销商列表
- */
- public function getFenxiaoList()
- {
- $page_index = input('page', 1);
- $page_size = input('page_size', PAGE_LIST_ROWS);
- $fenxiao_search = input('fenxiao_search', '');
- $condition = [];
- $condition[] = [ 'mobile|fenxiao_name', 'like', '%' . $fenxiao_search . '%' ];
- $condition[] = [ 'status', '=', 1 ];
- $condition[] = [ 'site_id', '=', $this->site_id ];
- $fenxiao_model = new FenxiaoModel();
- $list = $fenxiao_model->getFenxiaoPageLists($condition, $page_index, $page_size, '', 'fenxiao_id,fenxiao_name,account');
- return $list;
- }
-
- /**
- * 获取会员列表
- */
- public function getMemberList()
- {
- $page_index = input('page', 1);
- $page_size = input('page_size', PAGE_LIST_ROWS);
- $member_search = input('member_search', '');
- $condition = [];
- $condition[] = [ 'mobile|email|username', 'like', '%' . $member_search . '%' ];
- $condition[] = [ 'site_id', '=', $this->site_id ];
- $condition[] = [ 'is_fenxiao', '=', '0' ];
- $member_model = new MemberModel();
- $list = $member_model->getMemberPageList($condition, $page_index, $page_size, '', 'member_id,headimg,nickname,point,balance');
- return $list;
- }
-
- /**
- * 详情
- */
- public function detail()
- {
- $fenxiao_id = input('fenxiao_id', '');
-
- $model = new FenxiaoModel();
- $fenxiao_leve_model = new FenxiaoLevelModel();
-
- $condition[] = [ 'f.fenxiao_id', '=', $fenxiao_id ];
- $info = $model->getFenxiaoDetailInfo($condition);
-
- if (empty($info[ 'data' ])) $this->error('未获取到分销商数据', href_url('fenxiao://shop/fenxiao/lists'));
-
- $fenxiao_level = $fenxiao_leve_model->getLevelInfo([ [ 'level_id', '=', $info[ 'data' ][ 'level_id' ] ] ]);
-
- $this->assign('status', $model->fenxiao_status_zh);
- $this->assign('level', $fenxiao_level[ 'data' ]);
- $this->assign('info', $info[ 'data' ]);
-
- $this->assign('fenxiao_id', $fenxiao_id);
-
- $config_model = new ConfigModel();
- $basics_config = $config_model->getFenxiaoBasicsConfig($this->site_id);
- $this->assign('fenxiao_level_num', $basics_config[ 'data' ][ 'value' ][ 'level' ]);
-
- return $this->fetch('fenxiao/fenxiao_detail');
- }
-
- /**
- * 分销账户信息
- */
- public function account()
- {
- $model = new FenxiaoModel();
- $fenxiao_id = input('fenxiao_id', '');
-
- $condition[] = [ 'f.fenxiao_id', '=', $fenxiao_id ];
- $info = $model->getFenxiaoDetailInfo($condition);
- if (empty($info[ 'data' ])) $this->error('未获取到分销商数据', href_url('fenxiao://shop/fenxiao/lists'));
- $account = $info[ 'data' ][ 'account' ] - $info[ 'data' ][ 'account_withdraw_apply' ];
- $info[ 'data' ][ 'account' ] = number_format($account, 2, '.', '');
- $this->assign('fenxiao_info', $info[ 'data' ]);
-
- if (request()->isJson()) {
-
- $account_model = new FenxiaoAccount();
- $page = input('page', 1);
- $status = input('status', '');
-
- $fenxiao_id = input('fenxiao_id', '');
- $list_condition[] = [ 'fenxiao_id', '=', $fenxiao_id ];
- if ($status) {
- if ($status == 1) {
- $list_condition[] = [ 'money', '>', 0 ];
- } else {
- $list_condition[] = [ 'money', '<', 0 ];
- }
- }
-
- $start_time = input('start_time', '');
- $end_time = input('end_time', '');
- if ($start_time && $end_time) {
- $list_condition[] = [ 'create_time', 'between', [ $start_time, $end_time ] ];
- } elseif (!$start_time && $end_time) {
- $list_condition[] = [ 'create_time', '<=', $end_time ];
-
- } elseif ($start_time && !$end_time) {
- $list_condition[] = [ 'create_time', '>=', $start_time ];
- }
-
- $page_size = input('page_size', PAGE_LIST_ROWS);
- $list = $account_model->getFenxiaoAccountPageList($list_condition, $page, $page_size);
- return $list;
- }
- }
-
- /**
- * 分销商团队
- */
- public function team()
- {
- $fenxiao_id = input('fenxiao_id', 0);
- $fenxiao_model = new FenxiaoModel();
- if (request()->isJson()) {
- $level = input('level', 1);
- $page = input('page', 1);
- $page_size = input('page_size', PAGE_LIST_ROWS);
- $list = $fenxiao_model->getFenxiaoTeam($level, $fenxiao_id, $page, $page_size);
- return $list;
- }
- }
-
- /**
- * 订单管理
- */
- public function order()
- {
- $model = new FenxiaoOrderModel();
- if (request()->isJson()) {
-
- $page_index = input('page', 1);
- $page_size = input('page_size', PAGE_LIST_ROWS);
- $fenxiao_id = input('fenxiao_id', '');
- $status = input('status', 0);
-
- $condition[] = [ 'one_fenxiao_id|two_fenxiao_id|three_fenxiao_id', '=', $fenxiao_id ];
-
- $search_text_type = input('search_text_type', 'goods_name');//订单编号/商品名称
- $search_text = input('search_text', '');
- if (!empty($search_text)) {
- $condition[] = [ 'fo.' . $search_text_type, 'like', '%' . $search_text . '%' ];
- }
- if (in_array($status, [ 1, 2 ])) {
- $condition[] = [ 'fo.is_settlement', '=', $status - 1 ];
- }
-
- //下单时间
- $start_time = input('start_time', '');
- $end_time = input('end_time', '');
- if (!empty($start_time) && empty($end_time)) {
- $condition[] = [ 'fo.create_time', '>=', date_to_time($start_time) ];
- } elseif (empty($start_time) && !empty($end_time)) {
- $condition[] = [ 'fo.create_time', '<=', date_to_time($end_time) ];
- } elseif (!empty($start_time) && !empty(date_to_time($end_time))) {
- $condition[] = [ 'fo.create_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
- }
-
- $list = $model->getFenxiaoOrderPage($condition, $page_index, $page_size);
- return $list;
-
- }
- }
-
- /**
- * 订单详情
- */
- public function orderDetail()
- {
- $fenxiao_order_model = new FenxiaoOrderModel();
- $fenxiao_order_id = input('fenxiao_order_id', '');
- $order_info = $fenxiao_order_model->getFenxiaoOrderDetail([ [ 'fenxiao_order_id', '=', $fenxiao_order_id ] ]);
- $this->assign('order_info', $order_info[ 'data' ]);
- return $this->fetch('fenxiao/order_detail');
- }
-
- /**
- * 冻结
- */
- public function frozen()
- {
- $fenxiao_id = input('fenxiao_id', '');
- $model = new FenxiaoModel();
- return $model->frozen($fenxiao_id);
- }
-
- /**
- * 删除
- */
- public function delete()
- {
- $fenxiao_id = input('fenxiao_id', '');
- $model = new FenxiaoModel();
- return $model->delete($fenxiao_id);
- }
-
-
- /**
- * 恢复正常
- */
- public function unfrozen()
- {
- $fenxiao_id = input('fenxiao_id', '');
- $model = new FenxiaoModel();
- return $model->unfrozen($fenxiao_id);
- }
-
- /**
- * 分销商申请列表
- */
- public function apply()
- {
- $model = new FenxiaoApply();
- if (request()->isJson()) {
-
- $condition[] = [ 'fa.site_id', '=', $this->site_id ];
- $condition[] = [ 'fa.status', '=', 1 ];
- $condition[] = [ 'm.is_delete', '=', 0 ];
-
- $fenxiao_name = input('fenxiao_name', '');
- if ($fenxiao_name) {
- $condition[] = [ 'fenxiao_name', 'like', '%' . $fenxiao_name . '%' ];
- }
- $nickname = input('nickname', '');
- if ($nickname) {
- $condition[] = [ 'm.nickname', 'like', '%' . $nickname . '%' ];
- }
- $mobile = input('mobile', '');
- if ($mobile) {
- $condition[] = [ 'm.mobile', 'like', '%' . $mobile . '%' ];
- }
- $level_id = input('level_id', '');
- if ($level_id) {
- $condition[] = [ 'fa.level_id', '=', $level_id ];
- }
- $create_start_time = input('create_start_time', '');
- $create_end_time = input('create_end_time', '');
- if ($create_start_time && $create_end_time) {
- $condition[] = [ 'fa.create_time', 'between', [ strtotime($create_start_time), strtotime($create_end_time) ] ];
- } elseif (!$create_start_time && $create_end_time) {
- $condition[] = [ 'fa.create_time', '<=', strtotime($create_end_time) ];
-
- } elseif ($create_start_time && !$create_end_time) {
- $condition[] = [ 'fa.create_time', '>=', strtotime($create_start_time) ];
- }
-
- $rg_start_time = input('rg_start_time', '');
- $rg_end_time = input('rg_end_time', '');
- if ($rg_start_time && $rg_end_time) {
- $condition[] = [ 'fa.reg_time', 'between', [ strtotime($rg_start_time), strtotime($rg_end_time) ] ];
- } elseif (!$rg_start_time && $rg_end_time) {
- $condition[] = [ 'fa.reg_time', '<=', strtotime($rg_end_time) ];
-
- } elseif ($rg_start_time && !$rg_end_time) {
- $condition[] = [ 'fa.reg_time', '>=', strtotime($rg_start_time) ];
- }
-
- $join = [
- [ 'member m', 'fa.member_id = m.member_id', 'inner' ]
- ];
- $field = 'fa.apply_id,fa.fenxiao_name,fa.parent,fa.member_id,fa.level_id,fa.level_name,fa.order_complete_money,fa.order_complete_num,fa.reg_time,fa.create_time,fa.status,m.mobile,m.nickname,m.headimg';
-
- $page = input('page', 1);
- $page_size = input('page_size', PAGE_LIST_ROWS);
- $list = $model->getFenxiaoApplyPageList($condition, $page, $page_size, 'fa.create_time desc', $field, 'fa', $join);
- return $list;
- } else {
-
- $level_model = new FenxiaoLevelModel();
- $level_list = $level_model->getLevelList([ [ 'status', '=', 1 ] ], 'level_id,level_name');
- $this->assign('level_list', $level_list[ 'data' ]);
-
-
- return $this->fetch('fenxiao/apply');
- }
- }
-
- /**
- * 分销商申请通过
- */
- public function applyPass()
- {
- $apply_id = input('apply_id');
-
- $model = new FenxiaoApply();
- $res = $model->pass($apply_id, $this->site_id);
- return $res;
- }
-
- /**
- * 分销商申请通过
- */
- public function applyRefuse()
- {
- $apply_id = input('apply_id');
- $model = new FenxiaoApply();
- $res = $model->refuse($apply_id);
- return $res;
- }
-
- /**
- * 变更上下级
- */
- public function change()
- {
- $member_id = input('member_id');
-
- $model = new FenxiaoModel();
- $member_model = new MemberModel();
- $member_info = $member_model->getMemberInfo([ [ 'member_id', '=', $member_id ] ], 'fenxiao_id,is_fenxiao')[ 'data' ];
- if (request()->isJson()) {
- if ($member_info[ 'is_fenxiao' ] == 1) {
- $condition[] = [ 'f.fenxiao_id', '<>', $member_info[ 'fenxiao_id' ] ];
- $condition[] = [ 'f.parent', '<>', $member_info[ 'fenxiao_id' ] ];
- }
-
- $condition[] = [ 'f.site_id', '=', $this->site_id ];
- $status = input('status', 1);
- if ($status) {
- $condition[] = [ 'f.status', '=', $status ];
- }
-
- $fenxiao_name = input('fenxiao_name', '');
- if ($fenxiao_name) {
- $condition[] = [ 'f.fenxiao_name', 'like', '%' . $fenxiao_name . '%' ];
- }
-
- $parent_name = input('parent_name', '');
- if ($parent_name) {
- $condition[] = [ 'pf.fenxiao_name', 'like', '%' . $parent_name . '%' ];
- }
-
- $level_id = input('level_id', '');
- if ($level_id) {
- $condition[] = [ 'f.level_id', '=', $level_id ];
- }
- $start_time = input('start_time', '');
- $end_time = input('end_time', '');
- if ($start_time && $end_time) {
- $condition[] = [ 'f.create_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
- } elseif (!$start_time && $end_time) {
- $condition[] = [ 'f.create_time', '<=', date_to_time($end_time) ];
-
- } elseif ($start_time && !$end_time) {
- $condition[] = [ 'f.create_time', '>=', date_to_time($start_time) ];
- }
-
- $page = input('page', 1);
- $page_size = input('page_size', PAGE_LIST_ROWS);
- $list = $model->getFenxiaoPageList($condition, $page, $page_size, 'f.create_time desc');
- return $list;
-
- } else {
- $level_model = new FenxiaoLevelModel();
- $level_list = $level_model->getLevelList([ [ 'status', '=', 1 ], [ 'site_id', '=', $this->site_id ] ], 'level_id,level_name');
- $this->assign('level_list', $level_list[ 'data' ]);
-
- $config_model = new ConfigModel();
- $basics = $config_model->getFenxiaoBasicsConfig($this->site_id);
- $this->assign('basics_info', $basics[ 'data' ][ 'value' ]);
- //获取分销信息
- $fenxiao_info = $model->getFenxiaoInfo([ [ 'fenxiao_id', '=', $member_info[ 'fenxiao_id' ] ] ], 'parent');
-
- //获取上级分销商信息
- $parent_info = [];
- if (!empty($fenxiao_info[ 'data' ])) {
- $parent_info = $model->getFenxiaoInfo([ [ 'fenxiao_id', '=', $fenxiao_info[ 'data' ][ 'parent' ] ] ], 'fenxiao_id,fenxiao_name')['data'];
- }
-
- $this->assign('member_id', $member_id);
- $this->assign('parent_info', $parent_info);
- return $this->fetch('fenxiao/change');
- }
- }
-
- /**
- * 确认变更
- */
- public function confirmChange()
- {
- if (request()->isJson()) {
-
- $member_id = input('member_id', '');
- $parent = input('parent', '');
- $type = input('type', '');
- $model = new FenxiaoModel();
- if ($type == 1) {
- $res = $model->changeParentFenxiao($member_id, $parent);
- } else {
- $res = $model->cancelParentFenxiao($member_id);
- }
-
- return $res;
- }
- }
-
- /**
- * 会员详情
- */
- public function memberInfo()
- {
- if (request()->isJson()) {
-
- $member_id = input('member_id', '');
- $condition[] = [ 'site_id', '=', $this->site_id ];
- $condition[] = [ 'member_id', '=', $member_id ];
- $member_model = new MemberModel();
- $member_info_result = $member_model->getMemberInfo($condition);
- $member_info = $member_info_result['data'];
- if (empty($member_info)) return $member_model->error([], '账号不存在!');
- return $member_info_result;
- }
- }
-
- /**
- * 修改分销商等级
- */
- public function change_level()
- {
- $member_id = input('member_id', '');
- $fenxiao_id = input('fenxiao_id', '');
- if (request()->isJson()) {
- $level_model = new FenxiaoLevelModel();
- $fenxiao_model = new FenxiaoModel();
- $fenxiao_info = $fenxiao_model->getFenxiaoInfo([ [ 'fenxiao_id', '=', $fenxiao_id ] ], 'member_id,level_id,level_name')[ 'data' ];
- $condition[] = [ 'site_id', '=', $this->site_id ];
- if (!empty($fenxiao_info)) {
- $condition[] = [ 'level_id', '<>', $fenxiao_info[ 'level_id' ] ];
- }
-
- $lists = $level_model->getLevelPageList($condition, '1', PAGE_LIST_ROWS, 'level_num asc');
- return $lists;
- } else {
- $config_model = new ConfigModel();
- $basics = $config_model->getFenxiaoBasicsConfig($this->site_id);
- $this->assign('basics_info', $basics[ 'data' ][ 'value' ]);
-
- $this->assign('member_id', $member_id);
-
- $this->assign('fenxiao_id', $fenxiao_id);
- return $this->fetch('fenxiao/change_level');
- }
-
- }
-
- /**
- * 确认变更
- */
- public function confirmChangeLevel()
- {
- if (request()->isJson()) {
-
- $member_id = input('member_id', '');
- $level_id = input('level_id', '');
-
- $level_model = new FenxiaoLevelModel();
- $level_data = $level_model->getLevelInfo([ [ 'level_id', '=', $level_id ] ], 'level_id,level_name')[ 'data' ];
- $fenxiao_model = new FenxiaoModel();
- $data = [
- 'level_id' => $level_data[ 'level_id' ],
- 'level_name' => $level_data[ 'level_name' ]
- ];
- $res = $fenxiao_model->changeFenxiaoLevel($data, [ [ 'member_id', '=', $member_id ] ]);
- return $res;
- }
- }
+replace = [
+ 'FENXIAO_JS' => __ROOT__ . '/addon/fenxiao/shop/view/public/js',
+ 'FENXIAO_CSS' => __ROOT__ . '/addon/fenxiao/shop/view/public/css'
+ ];
+ parent::__construct($app);
+ }
+
+ /**
+ * 分销概况
+ */
+ public function index()
+ {
+ return $this->fetch('fenxiao/index');
+ }
+
+ public function stat()
+ {
+ $data = [
+ 'account_data' => [],
+ 'fenxiao_account' => 0.00,
+ 'shop_commission' => [],
+ 'shop_commission_end' => [],
+ 'commission_money' => 0.00,
+ 'fenxiao_apply_num' => 0,
+ 'fenxiao_num' => 0,
+ 'fenxiao_goods_num' => 0
+ ];
+
+ $fenxiao_data_model = new FenxiaoData();
+ $account_data = $fenxiao_data_model->getFenxiaoAccountData($this->site_id);
+ $data['account_data'] = $account_data;
+
+ //累计佣金
+ $fenxiao_account = number_format($account_data[ 'account' ], 2, '.', '');
+ $data['fenxiao_account'] = $fenxiao_account;
+
+ //获取分销的总金额
+ $order_model = new FenxiaoOrderModel();
+ $commission = $order_model->getFenxiaoOrderInfo([ [ 'site_id', '=', $this->site_id ] ], 'sum(real_goods_money) as real_goods_money,sum(commission) as commission')[ 'data' ];
+ if ($commission[ 'real_goods_money' ] == null) {
+ $commission[ 'real_goods_money' ] = '0.00';
+ }
+ if ($commission[ 'commission' ] == null) {
+ $commission[ 'commission' ] = '0.00';
+ }
+ $data['shop_commission'] = $commission;
+
+ //获取已结算分销的总金额
+ $commission_end = $order_model->getFenxiaoOrderInfo([ [ 'site_id', '=', $this->site_id ], [ 'is_settlement', '=', 1 ], [ 'is_refund', '=', 0 ] ], 'sum(real_goods_money) as real_goods_money,sum(commission) as commission')[ 'data' ];
+ if ($commission_end[ 'real_goods_money' ] == null) {
+ $commission_end[ 'real_goods_money' ] = '0.00';
+ }
+ if ($commission_end[ 'commission' ] == null) {
+ $commission_end[ 'commission' ] = '0.00';
+ }
+ $data['shop_commission_end'] = $commission_end;
+
+ //获取已退款的佣金
+ $commission_refund = $order_model->getFenxiaoOrderInfo([ [ 'site_id', '=', $this->site_id ], [ 'is_refund', '=', 1 ] ], 'sum(real_goods_money) as real_goods_money,sum(commission) as commission')[ 'data' ];
+ if ($commission_refund[ 'real_goods_money' ] == null) {
+ $commission_refund[ 'real_goods_money' ] = '0.00';
+ }
+ if ($commission_refund[ 'commission' ] == null) {
+ $commission_refund[ 'commission' ] = '0.00';
+ }
+ $commission_money = round($commission[ 'commission' ], 2) - round($commission_end[ 'commission' ], 2) - round($commission_refund[ 'commission' ], 2);
+ $commission_money = number_format($commission_money, 2);
+ $data['commission_money'] = $commission_money;
+
+ $fenxiao_apply_num = $fenxiao_data_model->getFenxiaoApplyCount($this->site_id);
+ $data['fenxiao_apply_num'] = $fenxiao_apply_num;
+
+ //分销商人数
+ $fenxiao_num = $fenxiao_data_model->getFenxiaoCount($this->site_id);
+ $data['fenxiao_num'] = $fenxiao_num;
+
+ $goods_model = new GoodsModel();
+ $fenxiao_goods_num = $goods_model->getGoodsInfo([ [ 'site_id', '=', $this->site_id ], [ 'is_fenxiao', '=', 1 ], [ 'is_delete', '=', 0 ] ], 'count(goods_id) as fenxiao_goods_num')[ 'data' ];
+ $data['fenxiao_goods_num'] = $fenxiao_goods_num[ 'fenxiao_goods_num' ];
+
+ return $data;
+ }
+
+
+ /**
+ * 分销商列表
+ */
+ public function lists()
+ {
+ $model = new FenxiaoModel();
+ if (request()->isJson()) {
+
+ $condition[] = [ 'f.site_id', '=', $this->site_id ];
+ $fenxiao_name = input('fenxiao_name', '');
+ $nickname = input('nickname', '');
+ $mobile = input('mobile', '');
+ $parent_name = input('parent_name', '');
+ $level_id = input('level_id', '');
+ $start_time = input('start_time', '');
+ $end_time = input('end_time', '');
+ $status = input('status', '');
+
+ if ($fenxiao_name) {
+ $condition[] = [ 'f.fenxiao_name', 'like', '%' . $fenxiao_name . '%' ];
+ }
+ if ($nickname) {
+ $condition[] = [ 'm.nickname', 'like', '%' . $nickname . '%' ];
+ }
+ if ($mobile) {
+ $condition[] = [ 'm.mobile', 'like', '%' . $mobile . '%' ];
+ }
+
+ if ($parent_name) {
+ $condition[] = [ 'pf.fenxiao_name', 'like', '%' . $parent_name . '%' ];
+ }
+
+ if ($level_id) {
+ $condition[] = [ 'f.level_id', '=', $level_id ];
+ }
+ if ($start_time && $end_time) {
+ $condition[] = [ 'f.create_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
+ } elseif (!$start_time && $end_time) {
+ $condition[] = [ 'f.create_time', '<=', date_to_time($end_time) ];
+
+ } elseif ($start_time && !$end_time) {
+ $condition[] = [ 'f.create_time', '>=', date_to_time($start_time) ];
+ }
+
+ if (!empty($status)) {
+ $condition[] = [ 'f.status', '=', $status ];
+ }
+ $page = input('page', 1);
+ $page_size = input('page_size', PAGE_LIST_ROWS);
+ $list = $model->getFenxiaoPageList($condition, $page, $page_size, 'f.create_time desc', $this->site_id);
+ return $list;
+
+ } else {
+ $level_model = new FenxiaoLevelModel();
+ $level_list = $level_model->getLevelList([ [ 'status', '=', 1 ], [ 'site_id', '=', $this->site_id ] ], 'level_id,level_name')[ 'data' ];
+ $this->assign('level_list', $level_list);
+
+ $config_model = new ConfigModel();
+ $basics = $config_model->getFenxiaoBasicsConfig($this->site_id)[ 'data' ][ 'value' ];
+ $this->assign('basics_info', $basics);
+
+
+ return $this->fetch('fenxiao/lists');
+ }
+ }
+
+ /**
+ * 添加分销商
+ */
+ public function add()
+ {
+ if (request()->isJson()) {
+
+ $fenxiao_data = [
+ 'site_id' => $this->site_id,
+ 'fenxiao_name' => input('fenxiao_name', ''),//分销商名称
+ 'level_id' => input('level_id', 0),//分销商等级
+ 'parent' => input('fenxiao_id', 0),//上级分销商ID
+ 'member_id' => input('member_id', 0),//关联会员ID
+ ];
+ $apply_model = new FenxiaoApply();
+ return $apply_model->addFenxiao($fenxiao_data);
+
+ } else {
+
+ //获取分销商等级
+ $level_model = new FenxiaoLevelModel();
+ $level_list = $level_model->getLevelList([ [ 'status', '=', 1 ], [ 'site_id', '=', $this->site_id ] ], 'level_id,level_name')[ 'data' ];
+ $this->assign('level_list', $level_list);
+
+ //获取分销商列表
+ $fenxiao_model = new FenxiaoModel();
+ $condition[] = [ 'status', '=', '1' ];
+ $fenxiao_list = $fenxiao_model->getFenxiaoList($condition, 'fenxiao_id,fenxiao_name')[ 'data' ];
+ $this->assign('fenxiao_list', $fenxiao_list);
+
+ //获取会员列表
+ $member_model = new MemberModel();
+ $where[] = [ 'is_fenxiao', '=', '0' ];
+ $member_list = $member_model->getMemberList($where, 'member_id,nickname')[ 'data' ];
+ $this->assign('member_list', $member_list);
+
+ return $this->fetch('fenxiao/add');
+ }
+
+ }
+
+ /**
+ * 获取分销商列表
+ */
+ public function getFenxiaoList()
+ {
+ $page_index = input('page', 1);
+ $page_size = input('page_size', PAGE_LIST_ROWS);
+ $fenxiao_search = input('fenxiao_search', '');
+ $condition = [];
+ $condition[] = [ 'mobile|fenxiao_name', 'like', '%' . $fenxiao_search . '%' ];
+ $condition[] = [ 'status', '=', 1 ];
+ $condition[] = [ 'site_id', '=', $this->site_id ];
+ $fenxiao_model = new FenxiaoModel();
+ $list = $fenxiao_model->getFenxiaoPageLists($condition, $page_index, $page_size, '', 'fenxiao_id,fenxiao_name,account');
+ return $list;
+ }
+
+ /**
+ * 获取会员列表
+ */
+ public function getMemberList()
+ {
+ $page_index = input('page', 1);
+ $page_size = input('page_size', PAGE_LIST_ROWS);
+ $member_search = input('member_search', '');
+ $condition = [];
+ $condition[] = [ 'mobile|email|username', 'like', '%' . $member_search . '%' ];
+ $condition[] = [ 'site_id', '=', $this->site_id ];
+ $condition[] = [ 'is_fenxiao', '=', '0' ];
+ $member_model = new MemberModel();
+ $list = $member_model->getMemberPageList($condition, $page_index, $page_size, '', 'member_id,headimg,nickname,point,balance');
+ return $list;
+ }
+
+ /**
+ * 详情
+ */
+ public function detail()
+ {
+ $fenxiao_id = input('fenxiao_id', '');
+
+ $model = new FenxiaoModel();
+ $fenxiao_leve_model = new FenxiaoLevelModel();
+
+ $condition[] = [ 'f.fenxiao_id', '=', $fenxiao_id ];
+ $info = $model->getFenxiaoDetailInfo($condition);
+
+ if (empty($info[ 'data' ])) $this->error('未获取到分销商数据', href_url('fenxiao://shop/fenxiao/lists'));
+
+ $fenxiao_level = $fenxiao_leve_model->getLevelInfo([ [ 'level_id', '=', $info[ 'data' ][ 'level_id' ] ] ]);
+
+ $this->assign('status', $model->fenxiao_status_zh);
+ $this->assign('level', $fenxiao_level[ 'data' ]);
+ $this->assign('info', $info[ 'data' ]);
+
+ $this->assign('fenxiao_id', $fenxiao_id);
+
+ $config_model = new ConfigModel();
+ $basics_config = $config_model->getFenxiaoBasicsConfig($this->site_id);
+ $this->assign('fenxiao_level_num', $basics_config[ 'data' ][ 'value' ][ 'level' ]);
+
+ return $this->fetch('fenxiao/fenxiao_detail');
+ }
+
+ /**
+ * 分销账户信息
+ */
+ public function account()
+ {
+ $model = new FenxiaoModel();
+ $fenxiao_id = input('fenxiao_id', '');
+
+ $condition[] = [ 'f.fenxiao_id', '=', $fenxiao_id ];
+ $info = $model->getFenxiaoDetailInfo($condition);
+ if (empty($info[ 'data' ])) $this->error('未获取到分销商数据', href_url('fenxiao://shop/fenxiao/lists'));
+ $account = $info[ 'data' ][ 'account' ] - $info[ 'data' ][ 'account_withdraw_apply' ];
+ $info[ 'data' ][ 'account' ] = number_format($account, 2, '.', '');
+ $this->assign('fenxiao_info', $info[ 'data' ]);
+
+ if (request()->isJson()) {
+
+ $account_model = new FenxiaoAccount();
+ $page = input('page', 1);
+ $status = input('status', '');
+
+ $fenxiao_id = input('fenxiao_id', '');
+ $list_condition[] = [ 'fenxiao_id', '=', $fenxiao_id ];
+ if ($status) {
+ if ($status == 1) {
+ $list_condition[] = [ 'money', '>', 0 ];
+ } else {
+ $list_condition[] = [ 'money', '<', 0 ];
+ }
+ }
+
+ $start_time = input('start_time', '');
+ $end_time = input('end_time', '');
+ if ($start_time && $end_time) {
+ $list_condition[] = [ 'create_time', 'between', [ $start_time, $end_time ] ];
+ } elseif (!$start_time && $end_time) {
+ $list_condition[] = [ 'create_time', '<=', $end_time ];
+
+ } elseif ($start_time && !$end_time) {
+ $list_condition[] = [ 'create_time', '>=', $start_time ];
+ }
+
+ $page_size = input('page_size', PAGE_LIST_ROWS);
+ $list = $account_model->getFenxiaoAccountPageList($list_condition, $page, $page_size);
+ return $list;
+ }
+ }
+
+ /**
+ * 分销商团队
+ */
+ public function team()
+ {
+ $fenxiao_id = input('fenxiao_id', 0);
+ $fenxiao_model = new FenxiaoModel();
+ if (request()->isJson()) {
+ $level = input('level', 1);
+ $page = input('page', 1);
+ $page_size = input('page_size', PAGE_LIST_ROWS);
+ $list = $fenxiao_model->getFenxiaoTeam($level, $fenxiao_id, $page, $page_size);
+ return $list;
+ }
+ }
+
+ /**
+ * 订单管理
+ */
+ public function order()
+ {
+ $model = new FenxiaoOrderModel();
+ if (request()->isJson()) {
+
+ $page_index = input('page', 1);
+ $page_size = input('page_size', PAGE_LIST_ROWS);
+ $fenxiao_id = input('fenxiao_id', '');
+ $status = input('status', 0);
+
+ $condition[] = [ 'one_fenxiao_id|two_fenxiao_id|three_fenxiao_id', '=', $fenxiao_id ];
+
+ $search_text_type = input('search_text_type', 'goods_name');//订单编号/商品名称
+ $search_text = input('search_text', '');
+ if (!empty($search_text)) {
+ $condition[] = [ 'fo.' . $search_text_type, 'like', '%' . $search_text . '%' ];
+ }
+ if (in_array($status, [ 1, 2 ])) {
+ $condition[] = [ 'fo.is_settlement', '=', $status - 1 ];
+ }
+
+ //下单时间
+ $start_time = input('start_time', '');
+ $end_time = input('end_time', '');
+ if (!empty($start_time) && empty($end_time)) {
+ $condition[] = [ 'fo.create_time', '>=', date_to_time($start_time) ];
+ } elseif (empty($start_time) && !empty($end_time)) {
+ $condition[] = [ 'fo.create_time', '<=', date_to_time($end_time) ];
+ } elseif (!empty($start_time) && !empty(date_to_time($end_time))) {
+ $condition[] = [ 'fo.create_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
+ }
+
+ $list = $model->getFenxiaoOrderPage($condition, $page_index, $page_size);
+ return $list;
+
+ }
+ }
+
+ /**
+ * 订单详情
+ */
+ public function orderDetail()
+ {
+ $fenxiao_order_model = new FenxiaoOrderModel();
+ $fenxiao_order_id = input('fenxiao_order_id', '');
+ $order_info = $fenxiao_order_model->getFenxiaoOrderDetail([ [ 'fenxiao_order_id', '=', $fenxiao_order_id ] ]);
+ $this->assign('order_info', $order_info[ 'data' ]);
+ return $this->fetch('fenxiao/order_detail');
+ }
+
+ /**
+ * 冻结
+ */
+ public function frozen()
+ {
+ $fenxiao_id = input('fenxiao_id', '');
+ $model = new FenxiaoModel();
+ return $model->frozen($fenxiao_id);
+ }
+
+ /**
+ * 删除
+ */
+ public function delete()
+ {
+ $fenxiao_id = input('fenxiao_id', '');
+ $model = new FenxiaoModel();
+ return $model->delete($fenxiao_id);
+ }
+
+
+ /**
+ * 恢复正常
+ */
+ public function unfrozen()
+ {
+ $fenxiao_id = input('fenxiao_id', '');
+ $model = new FenxiaoModel();
+ return $model->unfrozen($fenxiao_id);
+ }
+
+ /**
+ * 分销商申请列表
+ */
+ public function apply()
+ {
+ $model = new FenxiaoApply();
+ if (request()->isJson()) {
+
+ $condition[] = [ 'fa.site_id', '=', $this->site_id ];
+ $condition[] = [ 'fa.status', '=', 1 ];
+ $condition[] = [ 'm.is_delete', '=', 0 ];
+
+ $fenxiao_name = input('fenxiao_name', '');
+ if ($fenxiao_name) {
+ $condition[] = [ 'fenxiao_name', 'like', '%' . $fenxiao_name . '%' ];
+ }
+ $nickname = input('nickname', '');
+ if ($nickname) {
+ $condition[] = [ 'm.nickname', 'like', '%' . $nickname . '%' ];
+ }
+ $mobile = input('mobile', '');
+ if ($mobile) {
+ $condition[] = [ 'm.mobile', 'like', '%' . $mobile . '%' ];
+ }
+ $level_id = input('level_id', '');
+ if ($level_id) {
+ $condition[] = [ 'fa.level_id', '=', $level_id ];
+ }
+ $create_start_time = input('create_start_time', '');
+ $create_end_time = input('create_end_time', '');
+ if ($create_start_time && $create_end_time) {
+ $condition[] = [ 'fa.create_time', 'between', [ strtotime($create_start_time), strtotime($create_end_time) ] ];
+ } elseif (!$create_start_time && $create_end_time) {
+ $condition[] = [ 'fa.create_time', '<=', strtotime($create_end_time) ];
+
+ } elseif ($create_start_time && !$create_end_time) {
+ $condition[] = [ 'fa.create_time', '>=', strtotime($create_start_time) ];
+ }
+
+ $rg_start_time = input('rg_start_time', '');
+ $rg_end_time = input('rg_end_time', '');
+ if ($rg_start_time && $rg_end_time) {
+ $condition[] = [ 'fa.reg_time', 'between', [ strtotime($rg_start_time), strtotime($rg_end_time) ] ];
+ } elseif (!$rg_start_time && $rg_end_time) {
+ $condition[] = [ 'fa.reg_time', '<=', strtotime($rg_end_time) ];
+
+ } elseif ($rg_start_time && !$rg_end_time) {
+ $condition[] = [ 'fa.reg_time', '>=', strtotime($rg_start_time) ];
+ }
+
+ $join = [
+ [ 'member m', 'fa.member_id = m.member_id', 'inner' ]
+ ];
+ $field = 'fa.apply_id,fa.fenxiao_name,fa.parent,fa.member_id,fa.level_id,fa.level_name,fa.order_complete_money,fa.order_complete_num,fa.reg_time,fa.create_time,fa.status,m.mobile,m.nickname,m.headimg';
+
+ $page = input('page', 1);
+ $page_size = input('page_size', PAGE_LIST_ROWS);
+ $list = $model->getFenxiaoApplyPageList($condition, $page, $page_size, 'fa.create_time desc', $field, 'fa', $join);
+ return $list;
+ } else {
+
+ $level_model = new FenxiaoLevelModel();
+ $level_list = $level_model->getLevelList([ [ 'status', '=', 1 ] ], 'level_id,level_name');
+ $this->assign('level_list', $level_list[ 'data' ]);
+
+
+ return $this->fetch('fenxiao/apply');
+ }
+ }
+
+ /**
+ * 分销商申请通过
+ */
+ public function applyPass()
+ {
+ $apply_id = input('apply_id');
+
+ $model = new FenxiaoApply();
+ $res = $model->pass($apply_id, $this->site_id);
+ return $res;
+ }
+
+ /**
+ * 分销商申请通过
+ */
+ public function applyRefuse()
+ {
+ $apply_id = input('apply_id');
+ $model = new FenxiaoApply();
+ $res = $model->refuse($apply_id);
+ return $res;
+ }
+
+ /**
+ * 变更上下级
+ */
+ public function change()
+ {
+ $member_id = input('member_id');
+
+ $model = new FenxiaoModel();
+ $member_model = new MemberModel();
+ $member_info = $member_model->getMemberInfo([ [ 'member_id', '=', $member_id ] ], 'fenxiao_id,is_fenxiao')[ 'data' ];
+ if (request()->isJson()) {
+ if ($member_info[ 'is_fenxiao' ] == 1) {
+ $condition[] = [ 'f.fenxiao_id', '<>', $member_info[ 'fenxiao_id' ] ];
+ $condition[] = [ 'f.parent', '<>', $member_info[ 'fenxiao_id' ] ];
+ }
+
+ $condition[] = [ 'f.site_id', '=', $this->site_id ];
+ $status = input('status', 1);
+ if ($status) {
+ $condition[] = [ 'f.status', '=', $status ];
+ }
+
+ $fenxiao_name = input('fenxiao_name', '');
+ if ($fenxiao_name) {
+ $condition[] = [ 'f.fenxiao_name', 'like', '%' . $fenxiao_name . '%' ];
+ }
+
+ $parent_name = input('parent_name', '');
+ if ($parent_name) {
+ $condition[] = [ 'pf.fenxiao_name', 'like', '%' . $parent_name . '%' ];
+ }
+
+ $level_id = input('level_id', '');
+ if ($level_id) {
+ $condition[] = [ 'f.level_id', '=', $level_id ];
+ }
+ $start_time = input('start_time', '');
+ $end_time = input('end_time', '');
+ if ($start_time && $end_time) {
+ $condition[] = [ 'f.create_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
+ } elseif (!$start_time && $end_time) {
+ $condition[] = [ 'f.create_time', '<=', date_to_time($end_time) ];
+
+ } elseif ($start_time && !$end_time) {
+ $condition[] = [ 'f.create_time', '>=', date_to_time($start_time) ];
+ }
+
+ $page = input('page', 1);
+ $page_size = input('page_size', PAGE_LIST_ROWS);
+ $list = $model->getFenxiaoPageList($condition, $page, $page_size, 'f.create_time desc');
+ return $list;
+
+ } else {
+ $level_model = new FenxiaoLevelModel();
+ $level_list = $level_model->getLevelList([ [ 'status', '=', 1 ], [ 'site_id', '=', $this->site_id ] ], 'level_id,level_name');
+ $this->assign('level_list', $level_list[ 'data' ]);
+
+ $config_model = new ConfigModel();
+ $basics = $config_model->getFenxiaoBasicsConfig($this->site_id);
+ $this->assign('basics_info', $basics[ 'data' ][ 'value' ]);
+ //获取分销信息
+ $fenxiao_info = $model->getFenxiaoInfo([ [ 'fenxiao_id', '=', $member_info[ 'fenxiao_id' ] ] ], 'parent');
+
+ //获取上级分销商信息
+ $parent_info = [];
+ if (!empty($fenxiao_info[ 'data' ])) {
+ $parent_info = $model->getFenxiaoInfo([ [ 'fenxiao_id', '=', $fenxiao_info[ 'data' ][ 'parent' ] ] ], 'fenxiao_id,fenxiao_name')['data'];
+ }
+
+ $this->assign('member_id', $member_id);
+ $this->assign('parent_info', $parent_info);
+ return $this->fetch('fenxiao/change');
+ }
+ }
+
+ /**
+ * 确认变更
+ */
+ public function confirmChange()
+ {
+ if (request()->isJson()) {
+
+ $member_id = input('member_id', '');
+ $parent = input('parent', '');
+ $type = input('type', '');
+ $model = new FenxiaoModel();
+ if ($type == 1) {
+ $res = $model->changeParentFenxiao($member_id, $parent);
+ } else {
+ $res = $model->cancelParentFenxiao($member_id);
+ }
+
+ return $res;
+ }
+ }
+
+ /**
+ * 会员详情
+ */
+ public function memberInfo()
+ {
+ if (request()->isJson()) {
+
+ $member_id = input('member_id', '');
+ $condition[] = [ 'site_id', '=', $this->site_id ];
+ $condition[] = [ 'member_id', '=', $member_id ];
+ $member_model = new MemberModel();
+ $member_info_result = $member_model->getMemberInfo($condition);
+ $member_info = $member_info_result['data'];
+ if (empty($member_info)) return $member_model->error([], '账号不存在!');
+ return $member_info_result;
+ }
+ }
+
+ /**
+ * 修改分销商等级
+ */
+ public function change_level()
+ {
+ $member_id = input('member_id', '');
+ $fenxiao_id = input('fenxiao_id', '');
+ if (request()->isJson()) {
+ $level_model = new FenxiaoLevelModel();
+ $fenxiao_model = new FenxiaoModel();
+ $fenxiao_info = $fenxiao_model->getFenxiaoInfo([ [ 'fenxiao_id', '=', $fenxiao_id ] ], 'member_id,level_id,level_name')[ 'data' ];
+ $condition[] = [ 'site_id', '=', $this->site_id ];
+ if (!empty($fenxiao_info)) {
+ $condition[] = [ 'level_id', '<>', $fenxiao_info[ 'level_id' ] ];
+ }
+
+ $lists = $level_model->getLevelPageList($condition, '1', PAGE_LIST_ROWS, 'level_num asc');
+ return $lists;
+ } else {
+ $config_model = new ConfigModel();
+ $basics = $config_model->getFenxiaoBasicsConfig($this->site_id);
+ $this->assign('basics_info', $basics[ 'data' ][ 'value' ]);
+
+ $this->assign('member_id', $member_id);
+
+ $this->assign('fenxiao_id', $fenxiao_id);
+ return $this->fetch('fenxiao/change_level');
+ }
+
+ }
+
+ /**
+ * 确认变更
+ */
+ public function confirmChangeLevel()
+ {
+ if (request()->isJson()) {
+
+ $member_id = input('member_id', '');
+ $level_id = input('level_id', '');
+
+ $level_model = new FenxiaoLevelModel();
+ $level_data = $level_model->getLevelInfo([ [ 'level_id', '=', $level_id ] ], 'level_id,level_name')[ 'data' ];
+ $fenxiao_model = new FenxiaoModel();
+ $data = [
+ 'level_id' => $level_data[ 'level_id' ],
+ 'level_name' => $level_data[ 'level_name' ]
+ ];
+ $res = $fenxiao_model->changeFenxiaoLevel($data, [ [ 'member_id', '=', $member_id ] ]);
+ return $res;
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/shop/controller/Goods.php b/src/addon/fenxiao/shop/controller/Goods.php
index 3dba42c1b..a3e6c1290 100644
--- a/src/addon/fenxiao/shop/controller/Goods.php
+++ b/src/addon/fenxiao/shop/controller/Goods.php
@@ -1,271 +1,263 @@
-isJson()) {
-
- $page_index = input('page', 1);
- $page_size = input('page_size', PAGE_LIST_ROWS);
- $condition = [
- [ 'is_delete', '=', 0 ],
- [ 'site_id', '=', $this->site_id ]
- ];
- $search_text_type = input('search_text_type', 'goods_name');//店铺名称或者商品名称
- $search_text = input('search_text', '');
- $goods_class = input('goods_class', '');//商品种类
- $goods_state = input('goods_state', '');//商品状态
- $category_id = input('category_id', '');//分类ID
- $is_fenxiao = input('is_fenxiao', '');
- $start_sale = input('start_sale', 0);
- $end_sale = input('end_sale', 0);
- if (!empty($search_text)) {
- $condition[] = [ $search_text_type, 'like', '%' . $search_text . '%' ];
- }
-
- if ($is_fenxiao !== '') {
- $condition[] = [ 'is_fenxiao', '=', $is_fenxiao ];
- }
- if (!empty($start_sale)) $condition[] = [ 'sale_num', '>=', $start_sale ];
- if (!empty($end_sale)) $condition[] = [ 'sale_num', '<=', $end_sale ];
-
- if ($goods_class !== '') {
- $condition[] = [ 'goods_class', '=', $goods_class ];
- }
-
- if ($goods_state !== '') {
- $condition[] = [ 'goods_state', '=', $goods_state ];
- }
-
- if (!empty($category_id)) {
- $condition[] = [ 'category_id', 'like', '%,' . $category_id . ',%' ];
- }
- $list = $model->getGoodsPageList($condition, $page_index, $page_size);
- return $list;
- } else {
-
- return $this->fetch('goods/lists');
- }
- }
-
- public function detail()
- {
- $goods_id = input('goods_id');
- $goods_model = new GoodsModel();
- $fenxiao_sku_model = new FenxiaoGoodsSkuModel();
- $fenxiao_leve_model = new FenxiaoLevelModel();
- $goods_info = $goods_model->getGoodsDetail($goods_id);
- if (empty($goods_info[ 'data' ]) || $goods_info[ 'data' ][ 'site_id' ] != $this->site_id) $this->error('商品信息不存在');
- $fenxiao_skus = $fenxiao_sku_model->getSkuList([ 'goods_id' => $goods_id ]);
- $skus = [];
- foreach ($fenxiao_skus[ 'data' ] as $fenxiao_sku) {
- $skus[ $fenxiao_sku[ 'level_id' ] . '_' . $fenxiao_sku[ 'sku_id' ] ] = $fenxiao_sku;
- }
- $goods_info[ 'data' ][ 'fenxiao_skus' ] = $skus;
- $goods_info[ 'data' ][ 'goods_image' ] = explode(',', $goods_info[ 'data' ][ 'goods_image' ]);
- $fenxiao_level = $fenxiao_leve_model->getLevelList([ [ 'site_id', '=', $this->site_id ] ]);
- $this->assign('fenxiao_level', $fenxiao_level[ 'data' ]);
- $this->assign('goods_info', $goods_info[ 'data' ]);
-
- $fenxiao_config_model = new FenxiaoConfigModel();
- $fenxiao_config = $fenxiao_config_model->getFenxiaoBasicsConfig($this->site_id)[ 'data' ] ?? [];
- $this->assign('fenxiao_config', $fenxiao_config[ 'value' ] ?? []);
- return $this->fetch('goods/detail');
- }
-
- /**
- * 添加活动
- */
- public function config()
- {
- $goods_id = input('goods_id');
- $goods_model = new GoodsModel();
- $fenxiao_sku_model = new FenxiaoGoodsSkuModel();
- $fenxiao_leve_model = new FenxiaoLevelModel();
- $fenxiao_level = $fenxiao_leve_model->getLevelList([ [ 'site_id', '=', $this->site_id ], [ 'status', '=', 1 ] ], '*', 'level_num asc,one_rate asc');
- $goods_info = $goods_model->getGoodsDetail($goods_id);
- if (empty($goods_info[ 'data' ]) || $goods_info[ 'data' ][ 'site_id' ] != $this->site_id) $this->error('商品信息不存在');
- $fenxiao_config_model = new FenxiaoConfigModel();
- $fenxiao_config = $fenxiao_config_model->getFenxiaoBasicsConfig($this->site_id)[ 'data' ] ?? [];
- $fenxiao_config = $fenxiao_config[ 'value' ] ?? [];
- if (request()->isJson()) {
- Db::startTrans();
- try {
- $fenxiao_type = input('fenxiao_type', 1);
- $fenxiao_skus = input('fenxiao', []);
- $is_fenxiao = input('is_fenxiao', 0);
- $fenxiao_price = input('fenxiao_price', []);
-
- $goods_data = [ 'is_fenxiao' => $is_fenxiao, 'fenxiao_type' => $fenxiao_type ];
- if ($fenxiao_type == 2) {
- $fenxiao_goods_sku_data = [];
- foreach ($fenxiao_skus as $level_id => $level_data) {
- foreach ($level_data[ 'sku_id' ] as $key => $sku_id) {
- $fenxiao_total = 0;
- $fenxiao_level = [ 'one', 'two', 'three' ];
- foreach ($fenxiao_level as $level) {
- $item_rate_array = $level_data[ $level . '_rate' ] ?? [];
- $item_rate = $item_rate_array[ $key ] ?? 0;
- $item_money_array = $level_data[ $level . '_money' ] ?? [];
- $item_money = $item_money_array[ $key ] ?? 0;
- $var_rate_name = $level . '_rate';
- $$var_rate_name = $item_rate;
- $var_money_name = $level . '_money';
- $$var_money_name = $item_money;
- if ($item_rate > 0) {
- $fenxiao_total += $level_data[ 'sku_price' ][ $key ] * $item_rate / 100;
- } elseif ($item_money > 0) {
- $fenxiao_total += $item_money;
- }
- }
- if (empty($fenxiao_total)) {
- return error(-1, '分销金额不可以为零');
- }
- if ($level_data[ 'sku_price' ][ $key ] < $fenxiao_total) {
- return error(-1, '分销总金额不能大于商品sku价格的100%!');
- }
-
- if ($fenxiao_config[ 'level' ] < 3) {
- $three_rate = 0;
- $three_money = 0;
- //通过分销设置的等级配置
- if ($fenxiao_config[ 'level' ] < 2) {
- $two_rate = 0;
- $two_money = 0;
- }
- }
- $fenxiao_sku = [
- 'goods_id' => $goods_id,
- 'level_id' => $level_id,
- 'sku_id' => $sku_id,
- 'one_rate' => $one_rate ?? 0,
- 'one_money' => $one_money ?? 0,
- 'two_rate' => $two_rate ?? 0,
- 'two_money' => $two_money ?? 0,
- 'three_rate' => $three_rate ?? 0,
- 'three_money' => $three_money ?? 0,
- ];
- $fenxiao_goods_sku_data[] = $fenxiao_sku;
- }
- }
- $fenxiao_sku_model->deleteSku([ 'goods_id' => $goods_id ]);
- $fenxiao_sku_model->addSkuList($fenxiao_goods_sku_data);
- }
- if ($fenxiao_type == 1) {
- $fenxiao_goods_sku_data = [];
- foreach ($fenxiao_level[ 'data' ] as $level) {
- foreach ($goods_info[ 'data' ][ 'sku_data' ] as $sku) {
- $item_one_rate = $level[ 'one_rate' ] ?? 0;
- $item_two_rate = $level[ 'two_rate' ] ?? 0;
- $item_three_rate = $level[ 'three_rate' ] ?? 0;
- //通过分销设置的等级配置
- if ($fenxiao_config[ 'level' ] < 3) {
- $item_three_rate = 0;
- if ($fenxiao_config[ 'level' ] < 2) {
- $item_two_rate = 0;
- }
- }
- $fenxiao_sku = [
- 'goods_id' => $goods_id,
- 'level_id' => $level[ 'level_id' ],
- 'sku_id' => $sku[ 'sku_id' ],
- 'one_rate' => $item_one_rate,
- 'one_money' => 0,
- 'two_rate' => $item_two_rate,
- 'two_money' => 0,
- 'three_rate' => $item_three_rate,
- 'three_money' => 0,
- ];
- $fenxiao_goods_sku_data[] = $fenxiao_sku;
- }
- }
- $fenxiao_sku_model->deleteSku([ 'goods_id' => $goods_id ]);
- $fenxiao_sku_model->addSkuList($fenxiao_goods_sku_data);
- }
-
- $fenxiao_goods_model = new FenxiaoGoodsModel();
- $re = $fenxiao_goods_model->editGoodsFenxiao($goods_data, [ [ 'goods_id', '=', $goods_id ], [ 'site_id', '=', $this->site_id ] ]);
-
- if ($is_fenxiao) {
- foreach ($fenxiao_price as $sku_id => $item) {
- if (empty($item) || $item < 0) $item = 0;
- $res = model('goods_sku')->update([ 'fenxiao_price' => $item ], [ [ 'sku_id', '=', $sku_id ], [ 'site_id', '=', $this->site_id ] ]);
- }
- }
- Db::commit();
- return $re;
- } catch (\Exception $e) {
- Db::rollback();
- return error(-1, $e->getMessage());
- }
- }
- $fenxiao_skus = $fenxiao_sku_model->getSkuList([ 'goods_id' => $goods_id ]);
- $skus = [];
- foreach ($fenxiao_skus[ 'data' ] as $fenxiao_sku) {
- $skus[ $fenxiao_sku[ 'level_id' ] . '_' . $fenxiao_sku[ 'sku_id' ] ] = $fenxiao_sku;
- }
- $goods_info[ 'data' ][ 'fenxiao_skus' ] = $skus;
- $goods_info[ 'data' ][ 'goods_image' ] = explode(',', $goods_info[ 'data' ][ 'goods_image' ]);
-
- $this->assign('fenxiao_level', $fenxiao_level[ 'data' ]);
- $this->assign('goods_info', $goods_info[ 'data' ]);
-
- $this->assign('fenxiao_config', $fenxiao_config);
- return $this->fetch('goods/config');
- }
-
- /**
- * 修改分销状态
- */
- public function modify()
- {
- if (request()->isJson()) {
- $fenxiao_goods_model = new FenxiaoGoodsModel();
- $goods_id = input('goods_id');
- $is_fenxiao = input('is_fenxiao', 0);
- return $fenxiao_goods_model->modifyGoodsFenxiaoStatus($goods_id, $is_fenxiao ? 0 : 1, $this->site_id);
- }
- }
-
- /**
- * 批量设置是否参与分销
- * @return array
- */
- public function setGoodsIsFenxiao()
- {
- if (request()->isJson()) {
- $fenxiao_goods_model = new FenxiaoGoodsModel();
- $goods_ids = input('goods_ids', '');
- $is_fenxiao = input('is_fenxiao', 0);
- return $fenxiao_goods_model->modifyGoodsIsFenxiao($goods_ids, $is_fenxiao, $this->site_id);
- }
- }
+isJson()) {
+
+ $page_index = input('page', 1);
+ $page_size = input('page_size', PAGE_LIST_ROWS);
+ $condition = [
+ [ 'is_delete', '=', 0 ],
+ [ 'site_id', '=', $this->site_id ]
+ ];
+ $search_text_type = input('search_text_type', 'goods_name');//店铺名称或者商品名称
+ $search_text = input('search_text', '');
+ $goods_class = input('goods_class', '');//商品种类
+ $goods_state = input('goods_state', '');//商品状态
+ $category_id = input('category_id', '');//分类ID
+ $is_fenxiao = input('is_fenxiao', '');
+ $start_sale = input('start_sale', 0);
+ $end_sale = input('end_sale', 0);
+ if (!empty($search_text)) {
+ $condition[] = [ $search_text_type, 'like', '%' . $search_text . '%' ];
+ }
+
+ if ($is_fenxiao !== '') {
+ $condition[] = [ 'is_fenxiao', '=', $is_fenxiao ];
+ }
+ if (!empty($start_sale)) $condition[] = [ 'sale_num', '>=', $start_sale ];
+ if (!empty($end_sale)) $condition[] = [ 'sale_num', '<=', $end_sale ];
+
+ if ($goods_class !== '') {
+ $condition[] = [ 'goods_class', '=', $goods_class ];
+ }
+
+ if ($goods_state !== '') {
+ $condition[] = [ 'goods_state', '=', $goods_state ];
+ }
+
+ if (!empty($category_id)) {
+ $condition[] = [ 'category_id', 'like', '%,' . $category_id . ',%' ];
+ }
+ $list = $model->getGoodsPageList($condition, $page_index, $page_size);
+ return $list;
+ } else {
+
+ return $this->fetch('goods/lists');
+ }
+ }
+
+ public function detail()
+ {
+ $goods_id = input('goods_id');
+ $goods_model = new GoodsModel();
+ $fenxiao_sku_model = new FenxiaoGoodsSkuModel();
+ $fenxiao_leve_model = new FenxiaoLevelModel();
+ $goods_info = $goods_model->getGoodsDetail($goods_id);
+ if (empty($goods_info[ 'data' ]) || $goods_info[ 'data' ][ 'site_id' ] != $this->site_id) $this->error('商品信息不存在');
+ $fenxiao_skus = $fenxiao_sku_model->getSkuList([ 'goods_id' => $goods_id ]);
+ $skus = [];
+ foreach ($fenxiao_skus[ 'data' ] as $fenxiao_sku) {
+ $skus[ $fenxiao_sku[ 'level_id' ] . '_' . $fenxiao_sku[ 'sku_id' ] ] = $fenxiao_sku;
+ }
+ $goods_info[ 'data' ][ 'fenxiao_skus' ] = $skus;
+ $goods_info[ 'data' ][ 'goods_image' ] = explode(',', $goods_info[ 'data' ][ 'goods_image' ]);
+ $fenxiao_level = $fenxiao_leve_model->getLevelList([ [ 'site_id', '=', $this->site_id ] ]);
+ $this->assign('fenxiao_level', $fenxiao_level[ 'data' ]);
+ $this->assign('goods_info', $goods_info[ 'data' ]);
+
+ $fenxiao_config_model = new FenxiaoConfigModel();
+ $fenxiao_config = $fenxiao_config_model->getFenxiaoBasicsConfig($this->site_id)[ 'data' ] ?? [];
+ $this->assign('fenxiao_config', $fenxiao_config[ 'value' ] ?? []);
+ return $this->fetch('goods/detail');
+ }
+
+ /**
+ * 添加活动
+ */
+ public function config()
+ {
+ $goods_id = input('goods_id');
+ $goods_model = new GoodsModel();
+ $fenxiao_sku_model = new FenxiaoGoodsSkuModel();
+ $fenxiao_leve_model = new FenxiaoLevelModel();
+ $fenxiao_level = $fenxiao_leve_model->getLevelList([ [ 'site_id', '=', $this->site_id ], [ 'status', '=', 1 ] ], '*', 'level_num asc,one_rate asc');
+ $goods_info = $goods_model->getGoodsDetail($goods_id);
+ if (empty($goods_info[ 'data' ]) || $goods_info[ 'data' ][ 'site_id' ] != $this->site_id) $this->error('商品信息不存在');
+ $fenxiao_config_model = new FenxiaoConfigModel();
+ $fenxiao_config = $fenxiao_config_model->getFenxiaoBasicsConfig($this->site_id)[ 'data' ] ?? [];
+ $fenxiao_config = $fenxiao_config[ 'value' ] ?? [];
+ if (request()->isJson()) {
+ Db::startTrans();
+ try {
+ $fenxiao_type = input('fenxiao_type', 1);
+ $fenxiao_skus = input('fenxiao', []);
+ $is_fenxiao = input('is_fenxiao', 0);
+ $fenxiao_price = input('fenxiao_price', []);
+
+ $goods_data = [ 'is_fenxiao' => $is_fenxiao, 'fenxiao_type' => $fenxiao_type ];
+ if ($fenxiao_type == 2) {
+ $fenxiao_goods_sku_data = [];
+ foreach ($fenxiao_skus as $level_id => $level_data) {
+ foreach ($level_data[ 'sku_id' ] as $key => $sku_id) {
+ $fenxiao_total = 0;
+ $fenxiao_level = [ 'one', 'two', 'three' ];
+ foreach ($fenxiao_level as $level) {
+ $item_rate_array = $level_data[ $level . '_rate' ] ?? [];
+ $item_rate = $item_rate_array[ $key ] ?? 0;
+ $item_money_array = $level_data[ $level . '_money' ] ?? [];
+ $item_money = $item_money_array[ $key ] ?? 0;
+ $var_rate_name = $level . '_rate';
+ $$var_rate_name = $item_rate;
+ $var_money_name = $level . '_money';
+ $$var_money_name = $item_money;
+ if ($item_rate > 0) {
+ $fenxiao_total += $level_data[ 'sku_price' ][ $key ] * $item_rate / 100;
+ } elseif ($item_money > 0) {
+ $fenxiao_total += $item_money;
+ }
+ }
+ if (empty($fenxiao_total)) {
+ return error(-1, '分销金额不可以为零');
+ }
+ if ($level_data[ 'sku_price' ][ $key ] < $fenxiao_total) {
+ return error(-1, '分销总金额不能大于商品sku价格的100%!');
+ }
+
+ if ($fenxiao_config[ 'level' ] < 3) {
+ $three_rate = 0;
+ $three_money = 0;
+ //通过分销设置的等级配置
+ if ($fenxiao_config[ 'level' ] < 2) {
+ $two_rate = 0;
+ $two_money = 0;
+ }
+ }
+ $fenxiao_sku = [
+ 'goods_id' => $goods_id,
+ 'level_id' => $level_id,
+ 'sku_id' => $sku_id,
+ 'one_rate' => $one_rate ?? 0,
+ 'one_money' => $one_money ?? 0,
+ 'two_rate' => $two_rate ?? 0,
+ 'two_money' => $two_money ?? 0,
+ 'three_rate' => $three_rate ?? 0,
+ 'three_money' => $three_money ?? 0,
+ ];
+ $fenxiao_goods_sku_data[] = $fenxiao_sku;
+ }
+ }
+ $fenxiao_sku_model->deleteSku([ 'goods_id' => $goods_id ]);
+ $fenxiao_sku_model->addSkuList($fenxiao_goods_sku_data);
+ }
+ if ($fenxiao_type == 1) {
+ $fenxiao_goods_sku_data = [];
+ foreach ($fenxiao_level[ 'data' ] as $level) {
+ foreach ($goods_info[ 'data' ][ 'sku_data' ] as $sku) {
+ $item_one_rate = $level[ 'one_rate' ] ?? 0;
+ $item_two_rate = $level[ 'two_rate' ] ?? 0;
+ $item_three_rate = $level[ 'three_rate' ] ?? 0;
+ //通过分销设置的等级配置
+ if ($fenxiao_config[ 'level' ] < 3) {
+ $item_three_rate = 0;
+ if ($fenxiao_config[ 'level' ] < 2) {
+ $item_two_rate = 0;
+ }
+ }
+ $fenxiao_sku = [
+ 'goods_id' => $goods_id,
+ 'level_id' => $level[ 'level_id' ],
+ 'sku_id' => $sku[ 'sku_id' ],
+ 'one_rate' => $item_one_rate,
+ 'one_money' => 0,
+ 'two_rate' => $item_two_rate,
+ 'two_money' => 0,
+ 'three_rate' => $item_three_rate,
+ 'three_money' => 0,
+ ];
+ $fenxiao_goods_sku_data[] = $fenxiao_sku;
+ }
+ }
+ $fenxiao_sku_model->deleteSku([ 'goods_id' => $goods_id ]);
+ $fenxiao_sku_model->addSkuList($fenxiao_goods_sku_data);
+ }
+
+ $fenxiao_goods_model = new FenxiaoGoodsModel();
+ $re = $fenxiao_goods_model->editGoodsFenxiao($goods_data, [ [ 'goods_id', '=', $goods_id ], [ 'site_id', '=', $this->site_id ] ]);
+
+ if ($is_fenxiao) {
+ foreach ($fenxiao_price as $sku_id => $item) {
+ if (empty($item) || $item < 0) $item = 0;
+ $res = model('goods_sku')->update([ 'fenxiao_price' => $item ], [ [ 'sku_id', '=', $sku_id ], [ 'site_id', '=', $this->site_id ] ]);
+ }
+ }
+ Db::commit();
+ return $re;
+ } catch (\Exception $e) {
+ Db::rollback();
+ return error(-1, $e->getMessage());
+ }
+ }
+ $fenxiao_skus = $fenxiao_sku_model->getSkuList([ 'goods_id' => $goods_id ]);
+ $skus = [];
+ foreach ($fenxiao_skus[ 'data' ] as $fenxiao_sku) {
+ $skus[ $fenxiao_sku[ 'level_id' ] . '_' . $fenxiao_sku[ 'sku_id' ] ] = $fenxiao_sku;
+ }
+ $goods_info[ 'data' ][ 'fenxiao_skus' ] = $skus;
+ $goods_info[ 'data' ][ 'goods_image' ] = explode(',', $goods_info[ 'data' ][ 'goods_image' ]);
+
+ $this->assign('fenxiao_level', $fenxiao_level[ 'data' ]);
+ $this->assign('goods_info', $goods_info[ 'data' ]);
+
+ $this->assign('fenxiao_config', $fenxiao_config);
+ return $this->fetch('goods/config');
+ }
+
+ /**
+ * 修改分销状态
+ */
+ public function modify()
+ {
+ if (request()->isJson()) {
+ $fenxiao_goods_model = new FenxiaoGoodsModel();
+ $goods_id = input('goods_id');
+ $is_fenxiao = input('is_fenxiao', 0);
+ return $fenxiao_goods_model->modifyGoodsFenxiaoStatus($goods_id, $is_fenxiao ? 0 : 1, $this->site_id);
+ }
+ }
+
+ /**
+ * 批量设置是否参与分销
+ * @return array
+ */
+ public function setGoodsIsFenxiao()
+ {
+ if (request()->isJson()) {
+ $fenxiao_goods_model = new FenxiaoGoodsModel();
+ $goods_ids = input('goods_ids', '');
+ $is_fenxiao = input('is_fenxiao', 0);
+ return $fenxiao_goods_model->modifyGoodsIsFenxiao($goods_ids, $is_fenxiao, $this->site_id);
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/shop/controller/Level.php b/src/addon/fenxiao/shop/controller/Level.php
index 4e6571a68..aa3daca77 100644
--- a/src/addon/fenxiao/shop/controller/Level.php
+++ b/src/addon/fenxiao/shop/controller/Level.php
@@ -1,159 +1,151 @@
-isJson()) {
-
- $page = input('page', 1);
- $page_size = input('page_size', PAGE_LIST_ROWS);
- $list = $model->getLevelPageListInAdmin([ [ 'site_id', '=', $this->site_id ], ['is_default', '=', 0] ], $page, $page_size, 'level_num asc,one_rate asc', $field);
- return $list;
-
- } else {
-
- //获取系统配置
- $config_model = new ConfigModel();
- $basics = $config_model->getFenxiaoBasicsConfig($this->site_id);
- $this->assign("basics_info", $basics[ 'data' ][ 'value' ]);
- return $this->fetch('level/lists');
-
- }
-
- }
-
- /**
- * 添加分销等级
- */
- public function add()
- {
- $model = new FenxiaoLevelModel();
-
- if (request()->isJson()) {
-
- $data = [
- 'site_id' => $this->site_id,
- 'level_name' => input('level_name', ''),
- 'one_rate' => input('one_rate', ''),
- 'two_rate' => input('two_rate', ''),
- 'three_rate' => input('three_rate', ''),
- 'upgrade_type' => input('upgrade_type', ''),
- 'level_num' => input('level_num', 1),
- 'fenxiao_order_num' => input('fenxiao_order_num', ''),
- 'fenxiao_order_meney' => input('fenxiao_order_meney', ''),
- 'one_fenxiao_order_num' => input('one_fenxiao_order_num', ''),
- 'one_fenxiao_order_money' => input('one_fenxiao_order_money', ''),
- 'one_fenxiao_total_order' => input('one_fenxiao_total_order', ''),
- 'order_num' => input('order_num', ''),
- 'order_money' => input('order_money', ''),
- 'child_num' => input('child_num', ''),
- 'child_fenxiao_num' => input('child_fenxiao_num', ''),
- 'one_child_num' => input('one_child_num', ''),
- 'one_child_fenxiao_num' => input('one_child_fenxiao_num', ''),
- ];
- $res = $model->addLevel($data);
- return $res;
- } else {
- //获取系统配置
- $config_model = new ConfigModel();
- $basics = $config_model->getFenxiaoBasicsConfig($this->site_id);
- $this->assign("basics_info", $basics[ 'data' ][ 'value' ]);
-
- $level_weight = $model->getLevelList([ [ 'level_num', '<>', '' ], [ 'site_id', '=', $this->site_id ] ], 'level_num');
- $level_weight = $level_weight[ 'data' ];
- if (!empty($level_weight)) $level_weight = array_column($level_weight, 'level_num');
- $this->assign('level_weight', $level_weight);
-
- return $this->fetch('level/add');
- }
-
- }
-
- /**
- * 编辑分销等级
- */
- public function edit()
- {
- $model = new FenxiaoLevelModel();
-
- if (request()->isJson()) {
-
- $data = [
- 'level_name' => input('level_name', ''),
- 'one_rate' => input('one_rate', ''),
- 'two_rate' => input('two_rate', ''),
- 'three_rate' => input('three_rate', ''),
- 'upgrade_type' => input('upgrade_type', ''),
- 'level_num' => input('level_num', 0),
- 'fenxiao_order_num' => input('fenxiao_order_num', ''),
- 'fenxiao_order_meney' => input('fenxiao_order_meney', ''),
- 'one_fenxiao_order_num' => input('one_fenxiao_order_num', ''),
- 'one_fenxiao_order_money' => input('one_fenxiao_order_money', ''),
- 'one_fenxiao_total_order' => input('one_fenxiao_total_order', ''),
- 'order_num' => input('order_num', ''),
- 'order_money' => input('order_money', ''),
- 'child_num' => input('child_num', ''),
- 'child_fenxiao_num' => input('child_fenxiao_num', ''),
- 'one_child_num' => input('one_child_num', ''),
- 'one_child_fenxiao_num' => input('one_child_fenxiao_num', ''),
- ];
- $level_id = input('level_id', '');
-
- $res = $model->editLevel($data, [ [ 'level_id', '=', $level_id ], [ 'site_id', '=', $this->site_id ] ]);
- return $res;
- } else {
- $level_id = input('level_id', '');
- $info = $model->getLevelInfo([ [ 'level_id', '=', $level_id ], [ 'site_id', '=', $this->site_id ] ]);
- if (empty($info[ 'data' ])) $this->error('未获取到等级数据', href_url('fenxiao://shop/level/lists'));
- $this->assign('info', $info[ 'data' ]);
- //获取系统配置
- $config_model = new ConfigModel();
- $basics = $config_model->getFenxiaoBasicsConfig($this->site_id);
- $this->assign("basics_info", $basics[ 'data' ][ 'value' ]);
-
- $level_weight = $model->getLevelList([ [ 'level_num', '<>', '' ], [ 'level_id', '<>', $level_id ], [ 'site_id', '=', $this->site_id ] ], 'level_num');
- $level_weight = $level_weight[ 'data' ];
- if (!empty($level_weight)) $level_weight = array_column($level_weight, 'level_num');
- $this->assign('level_weight', $level_weight);
- }
-
- return $this->fetch('level/edit');
- }
-
- /**
- * 删除分销等级
- */
- public function delete()
- {
- $model = new FenxiaoLevelModel();
-
- $level_id = input('level_id', '');
- $res = $model->deleteLevel($level_id, $this->site_id);
- return $res;
- }
+isJson()) {
+
+ $page = input('page', 1);
+ $page_size = input('page_size', PAGE_LIST_ROWS);
+ $list = $model->getLevelPageListInAdmin([ [ 'site_id', '=', $this->site_id ], ['is_default', '=', 0] ], $page, $page_size, 'level_num asc,one_rate asc', $field);
+ return $list;
+
+ } else {
+
+ //获取系统配置
+ $config_model = new ConfigModel();
+ $basics = $config_model->getFenxiaoBasicsConfig($this->site_id);
+ $this->assign("basics_info", $basics[ 'data' ][ 'value' ]);
+ return $this->fetch('level/lists');
+
+ }
+
+ }
+
+ /**
+ * 添加分销等级
+ */
+ public function add()
+ {
+ $model = new FenxiaoLevelModel();
+
+ if (request()->isJson()) {
+
+ $data = [
+ 'site_id' => $this->site_id,
+ 'level_name' => input('level_name', ''),
+ 'one_rate' => input('one_rate', ''),
+ 'two_rate' => input('two_rate', ''),
+ 'three_rate' => input('three_rate', ''),
+ 'upgrade_type' => input('upgrade_type', ''),
+ 'level_num' => input('level_num', 1),
+ 'fenxiao_order_num' => input('fenxiao_order_num', ''),
+ 'fenxiao_order_meney' => input('fenxiao_order_meney', ''),
+ 'one_fenxiao_order_num' => input('one_fenxiao_order_num', ''),
+ 'one_fenxiao_order_money' => input('one_fenxiao_order_money', ''),
+ 'one_fenxiao_total_order' => input('one_fenxiao_total_order', ''),
+ 'order_num' => input('order_num', ''),
+ 'order_money' => input('order_money', ''),
+ 'child_num' => input('child_num', ''),
+ 'child_fenxiao_num' => input('child_fenxiao_num', ''),
+ 'one_child_num' => input('one_child_num', ''),
+ 'one_child_fenxiao_num' => input('one_child_fenxiao_num', ''),
+ ];
+ $res = $model->addLevel($data);
+ return $res;
+ } else {
+ //获取系统配置
+ $config_model = new ConfigModel();
+ $basics = $config_model->getFenxiaoBasicsConfig($this->site_id);
+ $this->assign("basics_info", $basics[ 'data' ][ 'value' ]);
+
+ $level_weight = $model->getLevelList([ [ 'level_num', '<>', '' ], [ 'site_id', '=', $this->site_id ] ], 'level_num');
+ $level_weight = $level_weight[ 'data' ];
+ if (!empty($level_weight)) $level_weight = array_column($level_weight, 'level_num');
+ $this->assign('level_weight', $level_weight);
+
+ return $this->fetch('level/add');
+ }
+
+ }
+
+ /**
+ * 编辑分销等级
+ */
+ public function edit()
+ {
+ $model = new FenxiaoLevelModel();
+
+ if (request()->isJson()) {
+
+ $data = [
+ 'level_name' => input('level_name', ''),
+ 'one_rate' => input('one_rate', ''),
+ 'two_rate' => input('two_rate', ''),
+ 'three_rate' => input('three_rate', ''),
+ 'upgrade_type' => input('upgrade_type', ''),
+ 'level_num' => input('level_num', 0),
+ 'fenxiao_order_num' => input('fenxiao_order_num', ''),
+ 'fenxiao_order_meney' => input('fenxiao_order_meney', ''),
+ 'one_fenxiao_order_num' => input('one_fenxiao_order_num', ''),
+ 'one_fenxiao_order_money' => input('one_fenxiao_order_money', ''),
+ 'one_fenxiao_total_order' => input('one_fenxiao_total_order', ''),
+ 'order_num' => input('order_num', ''),
+ 'order_money' => input('order_money', ''),
+ 'child_num' => input('child_num', ''),
+ 'child_fenxiao_num' => input('child_fenxiao_num', ''),
+ 'one_child_num' => input('one_child_num', ''),
+ 'one_child_fenxiao_num' => input('one_child_fenxiao_num', ''),
+ ];
+ $level_id = input('level_id', '');
+
+ $res = $model->editLevel($data, [ [ 'level_id', '=', $level_id ], [ 'site_id', '=', $this->site_id ] ]);
+ return $res;
+ } else {
+ $level_id = input('level_id', '');
+ $info = $model->getLevelInfo([ [ 'level_id', '=', $level_id ], [ 'site_id', '=', $this->site_id ] ]);
+ if (empty($info[ 'data' ])) $this->error('未获取到等级数据', href_url('fenxiao://shop/level/lists'));
+ $this->assign('info', $info[ 'data' ]);
+ //获取系统配置
+ $config_model = new ConfigModel();
+ $basics = $config_model->getFenxiaoBasicsConfig($this->site_id);
+ $this->assign("basics_info", $basics[ 'data' ][ 'value' ]);
+
+ $level_weight = $model->getLevelList([ [ 'level_num', '<>', '' ], [ 'level_id', '<>', $level_id ], [ 'site_id', '=', $this->site_id ] ], 'level_num');
+ $level_weight = $level_weight[ 'data' ];
+ if (!empty($level_weight)) $level_weight = array_column($level_weight, 'level_num');
+ $this->assign('level_weight', $level_weight);
+ }
+
+ return $this->fetch('level/edit');
+ }
+
+ /**
+ * 删除分销等级
+ */
+ public function delete()
+ {
+ $model = new FenxiaoLevelModel();
+
+ $level_id = input('level_id', '');
+ $res = $model->deleteLevel($level_id, $this->site_id);
+ return $res;
+ }
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/shop/controller/Market.php b/src/addon/fenxiao/shop/controller/Market.php
index ff410ee0b..f52659083 100644
--- a/src/addon/fenxiao/shop/controller/Market.php
+++ b/src/addon/fenxiao/shop/controller/Market.php
@@ -1,36 +1,28 @@
- $this->site_id,
- 'name' => 'DIY_FENXIAO_MARKET',
- 'support_diy_view' => [ '', 'DIY_FENXIAO_MARKET' ],
- ];
- $edit_view = event('DiyViewEdit', $data, true);
-
- return $edit_view;
- }
-
+ $this->site_id,
+ 'name' => 'DIY_FENXIAO_MARKET',
+ 'support_diy_view' => [ '', 'DIY_FENXIAO_MARKET' ],
+ ];
+ $edit_view = event('DiyViewEdit', $data, true);
+
+ return $edit_view;
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/shop/controller/Order.php b/src/addon/fenxiao/shop/controller/Order.php
index 97f9860f1..7489b3ab3 100644
--- a/src/addon/fenxiao/shop/controller/Order.php
+++ b/src/addon/fenxiao/shop/controller/Order.php
@@ -1,122 +1,114 @@
-replace = [
- 'FENXIAO_JS' => __ROOT__ . '/addon/fenxiao/shop/view/public/js',
- 'FENXIAO_CSS' => __ROOT__ . '/addon/fenxiao/shop/view/public/css'
- ];
- parent::__construct($app);
- }
-
- /**
- * 分销订单列表
- */
- public function lists()
- {
- if (request()->isJson()) {
- $model = new FenxiaoOrder();
- $page_index = input('page', 1);
- $page_size = input('page_size', PAGE_LIST_ROWS);
- $status = input('status', 0);
- $condition = [ [ 'fo.site_id', '=', $this->site_id ] ];
- if ($status == 3) {
- $condition[] = [ 'fo.is_refund', '=', 1 ];
- }
- if (in_array($status, [ 1, 2 ])) {
- $condition[] = [ 'fo.is_settlement', '=', $status - 1 ];
- }
- $search_text_type = input('search_text_type', "sku_name");//商品名称/订单编号
- $search_text = input('search_text', "");
- if (!empty($search_text)) {
- $condition[] = [ 'fo.' . $search_text_type, 'like', '%' . $search_text . '%' ];
- }
- //下单时间
- $start_time = input('start_time', '');
- $end_time = input('end_time', '');
- if (!empty($start_time) && empty($end_time)) {
- $condition[] = [ 'fo.create_time', '>=', date_to_time($start_time) ];
- } elseif (empty($start_time) && !empty($end_time)) {
- $condition[] = [ 'fo.create_time', '<=', date_to_time($end_time) ];
- } elseif (!empty($start_time) && !empty(date_to_time($end_time))) {
- $condition[] = [ 'fo.create_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
- }
-
- $list = $model->getFenxiaoOrderPage($condition, $page_index, $page_size);
-
- return $list;
- } else {
-
- //订单状态
- return $this->fetch('order/lists');
- }
- }
-
- public function detail()
- {
- $fenxiao_order_model = new FenxiaoOrder();
- $order_id = input('order_id', '');
- $order_info = $fenxiao_order_model->getFenxiaoOrderDetail([ [ 'order_id', '=', $order_id ] ]);
- if (empty($order_info[ 'data' ])) $this->error('未获取到订单数据', href_url('fenxiao://shop/order/lists'));
- $this->assign('order_detail', $order_info[ 'data' ]);
- return $this->fetch('order/detail');
- }
-
- /**
- * 订单导出
- */
- public function exportorder()
- {
- $model = new FenxiaoOrder();
- $status = input('status', 0);
- $fenxiao_order_id = input('order_ids', "");
-
- $condition = [ [ 'fo.site_id', '=', $this->site_id ] ];
- if ($status == 3) {
- $condition[] = [ 'fo.is_refund', '=', 1 ];
- }
- if (in_array($status, [ 1, 2 ])) {
- $condition[] = [ 'fo.is_settlement', '=', $status - 1 ];
- }
- $search_text_type = input('search_text_type', "goods_name");//商品名称/订单编号
- $search_text = input('search_text', "");
- if (!empty($search_text)) {
- $condition[] = [ 'fo.' . $search_text_type, 'like', '%' . $search_text . '%' ];
- }
- //下单时间
- $start_time = input('start_time', '');
- $end_time = input('end_time', '');
- if (!empty($start_time) && empty($end_time)) {
- $condition[] = [ 'fo.create_time', '>=', date_to_time($start_time) ];
- } elseif (empty($start_time) && !empty($end_time)) {
- $condition[] = [ 'fo.create_time', '<=', date_to_time($end_time) ];
- } elseif (!empty($start_time) && !empty(date_to_time($end_time))) {
- $condition[] = [ 'fo.create_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
- }
- if ($fenxiao_order_id) {
- $condition = [];
- $condition[] = [ "fo.fenxiao_order_id", "in", $fenxiao_order_id ];
- }
- $model->orderExport($condition);
- return;
- }
+replace = [
+ 'FENXIAO_JS' => __ROOT__ . '/addon/fenxiao/shop/view/public/js',
+ 'FENXIAO_CSS' => __ROOT__ . '/addon/fenxiao/shop/view/public/css'
+ ];
+ parent::__construct($app);
+ }
+
+ /**
+ * 分销订单列表
+ */
+ public function lists()
+ {
+ if (request()->isJson()) {
+ $model = new FenxiaoOrder();
+ $page_index = input('page', 1);
+ $page_size = input('page_size', PAGE_LIST_ROWS);
+ $status = input('status', 0);
+ $condition = [ [ 'fo.site_id', '=', $this->site_id ] ];
+ if ($status == 3) {
+ $condition[] = [ 'fo.is_refund', '=', 1 ];
+ }
+ if (in_array($status, [ 1, 2 ])) {
+ $condition[] = [ 'fo.is_settlement', '=', $status - 1 ];
+ }
+ $search_text_type = input('search_text_type', "sku_name");//商品名称/订单编号
+ $search_text = input('search_text', "");
+ if (!empty($search_text)) {
+ $condition[] = [ 'fo.' . $search_text_type, 'like', '%' . $search_text . '%' ];
+ }
+ //下单时间
+ $start_time = input('start_time', '');
+ $end_time = input('end_time', '');
+ if (!empty($start_time) && empty($end_time)) {
+ $condition[] = [ 'fo.create_time', '>=', date_to_time($start_time) ];
+ } elseif (empty($start_time) && !empty($end_time)) {
+ $condition[] = [ 'fo.create_time', '<=', date_to_time($end_time) ];
+ } elseif (!empty($start_time) && !empty(date_to_time($end_time))) {
+ $condition[] = [ 'fo.create_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
+ }
+
+ $list = $model->getFenxiaoOrderPage($condition, $page_index, $page_size);
+
+ return $list;
+ } else {
+
+ //订单状态
+ return $this->fetch('order/lists');
+ }
+ }
+
+ public function detail()
+ {
+ $fenxiao_order_model = new FenxiaoOrder();
+ $order_id = input('order_id', '');
+ $order_info = $fenxiao_order_model->getFenxiaoOrderDetail([ [ 'order_id', '=', $order_id ] ]);
+ if (empty($order_info[ 'data' ])) $this->error('未获取到订单数据', href_url('fenxiao://shop/order/lists'));
+ $this->assign('order_detail', $order_info[ 'data' ]);
+ return $this->fetch('order/detail');
+ }
+
+ /**
+ * 订单导出
+ */
+ public function exportorder()
+ {
+ $model = new FenxiaoOrder();
+ $status = input('status', 0);
+ $fenxiao_order_id = input('order_ids', "");
+
+ $condition = [ [ 'fo.site_id', '=', $this->site_id ] ];
+ if ($status == 3) {
+ $condition[] = [ 'fo.is_refund', '=', 1 ];
+ }
+ if (in_array($status, [ 1, 2 ])) {
+ $condition[] = [ 'fo.is_settlement', '=', $status - 1 ];
+ }
+ $search_text_type = input('search_text_type', "goods_name");//商品名称/订单编号
+ $search_text = input('search_text', "");
+ if (!empty($search_text)) {
+ $condition[] = [ 'fo.' . $search_text_type, 'like', '%' . $search_text . '%' ];
+ }
+ //下单时间
+ $start_time = input('start_time', '');
+ $end_time = input('end_time', '');
+ if (!empty($start_time) && empty($end_time)) {
+ $condition[] = [ 'fo.create_time', '>=', date_to_time($start_time) ];
+ } elseif (empty($start_time) && !empty($end_time)) {
+ $condition[] = [ 'fo.create_time', '<=', date_to_time($end_time) ];
+ } elseif (!empty($start_time) && !empty(date_to_time($end_time))) {
+ $condition[] = [ 'fo.create_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
+ }
+ if ($fenxiao_order_id) {
+ $condition = [];
+ $condition[] = [ "fo.fenxiao_order_id", "in", $fenxiao_order_id ];
+ }
+ $model->orderExport($condition);
+ return;
+ }
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/shop/controller/Postertemplate.php b/src/addon/fenxiao/shop/controller/Postertemplate.php
index 1d819864b..aed7fa9c2 100644
--- a/src/addon/fenxiao/shop/controller/Postertemplate.php
+++ b/src/addon/fenxiao/shop/controller/Postertemplate.php
@@ -1,313 +1,305 @@
-isJson()) {
- $page_index = input('page', 1);
- $page_size = input('page_size', PAGE_LIST_ROWS);
- $search_text = input('search_text', '');
- $condition = [ [ 'site_id', '=', $this->site_id ] ];
- $condition[] = [ 'template_type', '=', 'fenxiao' ];
- if (!empty($search_text)) {
- $condition[] = [ 'poster_name', 'like', '%' . $search_text . '%' ];
- }
- $poster_template_model = new PosterTemplateModel();
- $res = $poster_template_model->getPosterTemplatePageList($condition, $page_index, $page_size);
- return $res;
- } else {
-
-
- return $this->fetch('poster_template/lists');
- }
- }
-
- /**
- * 添加海报模板
- * @return mixed
- */
- public function addPosterTemplate()
- {
- $poster_template_model = new PosterTemplateModel();
- if (request()->isJson()) {
- $default_template = PosterTemplateModel::DEFAULT_TEMPLATE;
- $add_data = [];
- $template_json = [];
- foreach ($default_template as $field => $field_value) {
- if ($field == 'template_json') {
- foreach ($default_template[ 'template_json' ] as $json_field => $json_field_value) {
- $template_json[ $json_field ] = input($json_field, $json_field_value);
- }
- } else {
- $add_data[ $field ] = input($field, $field_value);
- }
- }
- unset($add_data[ 'template_id' ]);
- $add_data[ 'site_id' ] = $this->site_id;
- $add_data[ 'template_json' ] = json_encode($template_json, true);
-
- return $poster_template_model->addPosterTemplate($add_data);
- } else {
- //模板信息
- $muban_id = input('muban_id', 0);
- $muban_info = $poster_template_model->getMubanInfo([ [ 'muban_id', '=', $muban_id ] ])[ 'data' ];
- if (!empty($muban_info)) {
- $template_info = $muban_info;
- $template_info[ 'template_json' ] = json_decode($template_info[ 'template_json' ], true);
- $template_info[ 'template_id' ] = 0;
- } else {
- $template_info = PosterTemplateModel::DEFAULT_TEMPLATE;
- }
- $template_info[ 'template_json' ] = $poster_template_model->correctTemplateJsonData($template_info[ 'template_json' ])[ 'data' ];
- $template_info = array_merge($template_info, $template_info[ 'template_json' ]);
- unset($template_info[ 'template_json' ]);
- $this->assign('template_info', $template_info);
-
- //站点信息
- $site_model = new Site();
- $site_info = $site_model->getSiteInfo([ [ "site_id", "=", $this->site_id ] ], 'site_name,logo,logo_square')[ 'data' ];
- $this->assign('site_data', $site_info);
-
- return $this->fetch('poster_template/add');
- }
- }
-
- /**
- * 添加海报模板
- * @return mixed
- */
- public function editPosterTemplate()
- {
- $template_id = input('template_id', '');
- $poster_template_model = new PosterTemplateModel();
- if (request()->isJson()) {
- $default_template = PosterTemplateModel::DEFAULT_TEMPLATE;
- $edit_data = [];
- $template_json = [];
- foreach ($default_template as $field => $field_value) {
- if ($field == 'template_json') {
- foreach ($default_template[ 'template_json' ] as $json_field => $json_field_value) {
- $template_json[ $json_field ] = input($json_field, $json_field_value);
- }
- } else {
- $edit_data[ $field ] = input($field, $field_value);
- }
- }
- unset($edit_data[ 'template_id' ]);
- $edit_data[ 'site_id' ] = $this->site_id;
- $edit_data[ 'template_json' ] = json_encode($template_json, true);
- return $poster_data = $poster_template_model->editPosterTemplate($edit_data, [
- [ 'template_id', '=', $template_id ],
- [ 'site_id', '=', $this->site_id ]
- ]);
- } else {
- //模板信息
- $template_info = $poster_template_model->getPosterTemplateInfo([
- [ 'site_id', '=', $this->site_id ],
- [ 'template_id', '=', $template_id ],
- ], '*')[ 'data' ];
- if (empty($template_info)) $this->error('模板信息有误');
- $template_info[ 'template_json' ] = json_decode($template_info[ 'template_json' ], true);
- $template_info[ 'template_json' ] = $poster_template_model->correctTemplateJsonData($template_info[ 'template_json' ])[ 'data' ];
- $template_info = array_merge($template_info, $template_info[ 'template_json' ]);
- unset($template_info[ 'template_json' ]);
- $this->assign('template_info', $template_info);
-
- //站点信息
- $site_model = new Site();
- $site_info = $site_model->getSiteInfo([ [ "site_id", "=", $this->site_id ] ], 'site_name,logo,logo_square');
- $this->assign('site_data', $site_info[ 'data' ]);
- return $this->fetch('poster_template/add');
- }
- }
-
- /**
- * 获取海报模板预览
- * @return mixed
- */
- public function posterTemplateDetail()
- {
- $template_id = input('template_id', '');
- $condition = [
- [ 'template_id', '=', $template_id ],
- [ 'site_id', '=', $this->site_id ]
- ];
- $poster_template_model = new PosterTemplateModel();
- $poster_data = $poster_template_model->getPosterTemplateInfo($condition);
- if (empty($poster_data[ 'data' ])) {
- return $poster_template_model->error(null, '海报数据有误');
- }
-
- $poster_data[ 'data' ][ 'template_json' ] = json_decode($poster_data[ 'data' ][ 'template_json' ], true);
- $poster_data[ 'data' ][ 'template_json' ] = $poster_template_model->correctTemplateJsonData($poster_data[ 'data' ][ 'template_json' ])[ 'data' ];
- $site_model = new Site();
- $where = array (
- [ "site_id", "=", $this->site_id ]
- );
- $site_info = $site_model->getSiteInfo($where);
- $poster_width = 720;
- $poster_height = 1280;
- $poster = new PosterExtend($poster_width, $poster_height);
- $ground = [
- [
- 'action' => 'setBackground', // 设背景色
- 'data' => [ 255, 255, 255 ]
- ],
- ];
-
- $fontRate = 0.725; // 20px 等于 14.5磅,换算比率 1px = 0.725磅
- $option = [
- [
- 'action' => 'imageCopy', // 写入二维码
- 'data' => [
- getUrl() . '/public/static/img/caner_erweima.png',
- $poster_data[ 'data' ][ 'qrcode_left' ] * 2,
- $poster_data[ 'data' ][ 'qrcode_top' ] * 2,
- $poster_data[ 'data' ][ 'qrcode_width' ] * 2,
- $poster_data[ 'data' ][ 'qrcode_height' ] * 2,
- 'square',
- 0,
- 1
- ]
- ],
- [
- 'action' => 'imageText', // 写入分享语
- 'data' => [
- $poster_data[ 'data' ][ 'template_json' ][ 'share_content' ],
- $poster_data[ 'data' ][ 'template_json' ][ 'share_content_font_size' ] * $fontRate * 2,
- is_array($poster_data[ 'data' ][ 'template_json' ][ 'share_content_color' ]) ? $poster_data[ 'data' ][ 'template_json' ][ 'share_content_color' ] : hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'share_content_color' ]),
- $poster_data[ 'data' ][ 'template_json' ][ 'share_content_left' ] * 2,
- ( $poster_data[ 'data' ][ 'template_json' ][ 'share_content_top' ] ) * 2,
- $poster_data[ 'data' ][ 'template_json' ][ 'share_content_width' ] * 2,
- 1
- ]
- ]
- ];
-
- $nickname_color = is_array($poster_data[ 'data' ][ 'template_json' ][ 'nickname_color' ]) ? $poster_data[ 'data' ][ 'template_json' ][ 'nickname_color' ] : hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'nickname_color' ]);
-
- $member_option = [
- [
- 'action' => 'imageCopy', // 写入用户头像
- 'data' => [
- getUrl() . '/public/static/img/default_img/head.png',
- $poster_data[ 'data' ][ 'template_json' ][ 'headimg_left' ] * 2,
- $poster_data[ 'data' ][ 'template_json' ][ 'headimg_top' ] * 2,
- $poster_data[ 'data' ][ 'template_json' ][ 'headimg_width' ] * 2,
- $poster_data[ 'data' ][ 'template_json' ][ 'headimg_height' ] * 2,
- !empty($poster_data[ 'data' ][ 'template_json' ][ 'headimg_shape' ]) ? $poster_data[ 'data' ][ 'template_json' ][ 'headimg_shape' ] : 'square',
- 0,
- $poster_data[ 'data' ][ 'template_json' ][ 'headimg_is_show' ]
- ]
- ],
- [
- 'action' => 'imageText', // 写入分享人昵称
- 'data' => [
- '用户昵称',
- $poster_data[ 'data' ][ 'template_json' ][ 'nickname_font_size' ] * $fontRate * 2,
- $nickname_color,
- $poster_data[ 'data' ][ 'template_json' ][ 'nickname_left' ] * 2,
- ( $poster_data[ 'data' ][ 'template_json' ][ 'nickname_top' ] ) * 2,
- $poster_data[ 'data' ][ 'template_json' ][ 'nickname_width' ] * 2,
- $poster_data[ 'data' ][ 'template_json' ][ 'nickname_height' ] * 2,
- 0,
- $poster_data[ 'data' ][ 'template_json' ][ 'nickname_is_show' ]
- ]
- ],
- ];
-
- list($width, $height, $type, $attr) = getimagesize(img($poster_data[ 'data' ][ 'background' ]));
- $height = 720 * $height / $width;
- $back_ground = [
- [
- 'action' => 'imageCopy', // 写入背景图
- 'data' => [
- img($poster_data[ 'data' ][ 'background' ]),
- 0,
- 0,
- 720,
- $height,
- 'square',
- 0,
- 1
- ]
- ],
- ];
- $option = array_merge($ground, $back_ground, $option, $member_option);
- $option_res = $poster->create($option);
-
- if (is_array($option_res)) return $option_res;
- $pic_name = rand(10000, 99999);
- $res = $option_res->jpeg('upload/poster/goods', 'fenxiao' . $pic_name);
- if ($res[ 'code' ] < 0) {
- return $res;
- }
-
- $upload = new Upload($this->site_id);
- $cloud_res = $upload->fileCloud($res[ 'data' ][ 'path' ]);
- return $cloud_res;
- }
-
- /**
- * 删除海报模板
- * @return mixed
- */
- public function delPosterTemplate()
- {
- if (request()->isJson()) {
- $template_ids = input('template_ids', '');
- $condition = [
- [ 'template_id', 'in', $template_ids ],
- [ 'site_id', '=', $this->site_id ],
- ];
- $poster_template_model = new PosterTemplateModel();
- $res = $poster_template_model->deletePosterTemplate($condition);
- return $res;
- }
- }
-
- /**
- * 编辑模板状态啊
- * @return array
- */
- public function editstatus()
- {
- if (request()->isJson()) {
- $template_id = input('template_id', 0);
- $template_status = input('template_status', 0);
- $condition = [
- [ 'template_id', 'in', $template_id ],
- [ 'site_id', '=', $this->site_id ]
- ];
- $data = [ 'template_status' => $template_status ];
- $poster_template_model = new PosterTemplateModel();
- $res = $poster_template_model->editPosterTemplate($data, $condition);
- return $res;
- }
- }
-
+isJson()) {
+ $page_index = input('page', 1);
+ $page_size = input('page_size', PAGE_LIST_ROWS);
+ $search_text = input('search_text', '');
+ $condition = [ [ 'site_id', '=', $this->site_id ] ];
+ $condition[] = [ 'template_type', '=', 'fenxiao' ];
+ if (!empty($search_text)) {
+ $condition[] = [ 'poster_name', 'like', '%' . $search_text . '%' ];
+ }
+ $poster_template_model = new PosterTemplateModel();
+ $res = $poster_template_model->getPosterTemplatePageList($condition, $page_index, $page_size);
+ return $res;
+ } else {
+
+
+ return $this->fetch('poster_template/lists');
+ }
+ }
+
+ /**
+ * 添加海报模板
+ * @return mixed
+ */
+ public function addPosterTemplate()
+ {
+ $poster_template_model = new PosterTemplateModel();
+ if (request()->isJson()) {
+ $default_template = PosterTemplateModel::DEFAULT_TEMPLATE;
+ $add_data = [];
+ $template_json = [];
+ foreach ($default_template as $field => $field_value) {
+ if ($field == 'template_json') {
+ foreach ($default_template[ 'template_json' ] as $json_field => $json_field_value) {
+ $template_json[ $json_field ] = input($json_field, $json_field_value);
+ }
+ } else {
+ $add_data[ $field ] = input($field, $field_value);
+ }
+ }
+ unset($add_data[ 'template_id' ]);
+ $add_data[ 'site_id' ] = $this->site_id;
+ $add_data[ 'template_json' ] = json_encode($template_json, true);
+
+ return $poster_template_model->addPosterTemplate($add_data);
+ } else {
+ //模板信息
+ $muban_id = input('muban_id', 0);
+ $muban_info = $poster_template_model->getMubanInfo([ [ 'muban_id', '=', $muban_id ] ])[ 'data' ];
+ if (!empty($muban_info)) {
+ $template_info = $muban_info;
+ $template_info[ 'template_json' ] = json_decode($template_info[ 'template_json' ], true);
+ $template_info[ 'template_id' ] = 0;
+ } else {
+ $template_info = PosterTemplateModel::DEFAULT_TEMPLATE;
+ }
+ $template_info[ 'template_json' ] = $poster_template_model->correctTemplateJsonData($template_info[ 'template_json' ])[ 'data' ];
+ $template_info = array_merge($template_info, $template_info[ 'template_json' ]);
+ unset($template_info[ 'template_json' ]);
+ $this->assign('template_info', $template_info);
+
+ //站点信息
+ $site_model = new Site();
+ $site_info = $site_model->getSiteInfo([ [ "site_id", "=", $this->site_id ] ], 'site_name,logo,logo_square')[ 'data' ];
+ $this->assign('site_data', $site_info);
+
+ return $this->fetch('poster_template/add');
+ }
+ }
+
+ /**
+ * 添加海报模板
+ * @return mixed
+ */
+ public function editPosterTemplate()
+ {
+ $template_id = input('template_id', '');
+ $poster_template_model = new PosterTemplateModel();
+ if (request()->isJson()) {
+ $default_template = PosterTemplateModel::DEFAULT_TEMPLATE;
+ $edit_data = [];
+ $template_json = [];
+ foreach ($default_template as $field => $field_value) {
+ if ($field == 'template_json') {
+ foreach ($default_template[ 'template_json' ] as $json_field => $json_field_value) {
+ $template_json[ $json_field ] = input($json_field, $json_field_value);
+ }
+ } else {
+ $edit_data[ $field ] = input($field, $field_value);
+ }
+ }
+ unset($edit_data[ 'template_id' ]);
+ $edit_data[ 'site_id' ] = $this->site_id;
+ $edit_data[ 'template_json' ] = json_encode($template_json, true);
+ return $poster_data = $poster_template_model->editPosterTemplate($edit_data, [
+ [ 'template_id', '=', $template_id ],
+ [ 'site_id', '=', $this->site_id ]
+ ]);
+ } else {
+ //模板信息
+ $template_info = $poster_template_model->getPosterTemplateInfo([
+ [ 'site_id', '=', $this->site_id ],
+ [ 'template_id', '=', $template_id ],
+ ], '*')[ 'data' ];
+ if (empty($template_info)) $this->error('模板信息有误');
+ $template_info[ 'template_json' ] = json_decode($template_info[ 'template_json' ], true);
+ $template_info[ 'template_json' ] = $poster_template_model->correctTemplateJsonData($template_info[ 'template_json' ])[ 'data' ];
+ $template_info = array_merge($template_info, $template_info[ 'template_json' ]);
+ unset($template_info[ 'template_json' ]);
+ $this->assign('template_info', $template_info);
+
+ //站点信息
+ $site_model = new Site();
+ $site_info = $site_model->getSiteInfo([ [ "site_id", "=", $this->site_id ] ], 'site_name,logo,logo_square');
+ $this->assign('site_data', $site_info[ 'data' ]);
+ return $this->fetch('poster_template/add');
+ }
+ }
+
+ /**
+ * 获取海报模板预览
+ * @return mixed
+ */
+ public function posterTemplateDetail()
+ {
+ $template_id = input('template_id', '');
+ $condition = [
+ [ 'template_id', '=', $template_id ],
+ [ 'site_id', '=', $this->site_id ]
+ ];
+ $poster_template_model = new PosterTemplateModel();
+ $poster_data = $poster_template_model->getPosterTemplateInfo($condition);
+ if (empty($poster_data[ 'data' ])) {
+ return $poster_template_model->error(null, '海报数据有误');
+ }
+
+ $poster_data[ 'data' ][ 'template_json' ] = json_decode($poster_data[ 'data' ][ 'template_json' ], true);
+ $poster_data[ 'data' ][ 'template_json' ] = $poster_template_model->correctTemplateJsonData($poster_data[ 'data' ][ 'template_json' ])[ 'data' ];
+ $site_model = new Site();
+ $where = array (
+ [ "site_id", "=", $this->site_id ]
+ );
+ $site_info = $site_model->getSiteInfo($where);
+ $poster_width = 720;
+ $poster_height = 1280;
+ $poster = new PosterExtend($poster_width, $poster_height);
+ $ground = [
+ [
+ 'action' => 'setBackground', // 设背景色
+ 'data' => [ 255, 255, 255 ]
+ ],
+ ];
+
+ $fontRate = 0.725; // 20px 等于 14.5磅,换算比率 1px = 0.725磅
+ $option = [
+ [
+ 'action' => 'imageCopy', // 写入二维码
+ 'data' => [
+ getUrl() . '/public/static/img/caner_erweima.png',
+ $poster_data[ 'data' ][ 'qrcode_left' ] * 2,
+ $poster_data[ 'data' ][ 'qrcode_top' ] * 2,
+ $poster_data[ 'data' ][ 'qrcode_width' ] * 2,
+ $poster_data[ 'data' ][ 'qrcode_height' ] * 2,
+ 'square',
+ 0,
+ 1
+ ]
+ ],
+ [
+ 'action' => 'imageText', // 写入分享语
+ 'data' => [
+ $poster_data[ 'data' ][ 'template_json' ][ 'share_content' ],
+ $poster_data[ 'data' ][ 'template_json' ][ 'share_content_font_size' ] * $fontRate * 2,
+ is_array($poster_data[ 'data' ][ 'template_json' ][ 'share_content_color' ]) ? $poster_data[ 'data' ][ 'template_json' ][ 'share_content_color' ] : hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'share_content_color' ]),
+ $poster_data[ 'data' ][ 'template_json' ][ 'share_content_left' ] * 2,
+ ( $poster_data[ 'data' ][ 'template_json' ][ 'share_content_top' ] ) * 2,
+ $poster_data[ 'data' ][ 'template_json' ][ 'share_content_width' ] * 2,
+ 1
+ ]
+ ]
+ ];
+
+ $nickname_color = is_array($poster_data[ 'data' ][ 'template_json' ][ 'nickname_color' ]) ? $poster_data[ 'data' ][ 'template_json' ][ 'nickname_color' ] : hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'nickname_color' ]);
+
+ $member_option = [
+ [
+ 'action' => 'imageCopy', // 写入用户头像
+ 'data' => [
+ getUrl() . '/public/static/img/default_img/head.png',
+ $poster_data[ 'data' ][ 'template_json' ][ 'headimg_left' ] * 2,
+ $poster_data[ 'data' ][ 'template_json' ][ 'headimg_top' ] * 2,
+ $poster_data[ 'data' ][ 'template_json' ][ 'headimg_width' ] * 2,
+ $poster_data[ 'data' ][ 'template_json' ][ 'headimg_height' ] * 2,
+ !empty($poster_data[ 'data' ][ 'template_json' ][ 'headimg_shape' ]) ? $poster_data[ 'data' ][ 'template_json' ][ 'headimg_shape' ] : 'square',
+ 0,
+ $poster_data[ 'data' ][ 'template_json' ][ 'headimg_is_show' ]
+ ]
+ ],
+ [
+ 'action' => 'imageText', // 写入分享人昵称
+ 'data' => [
+ '用户昵称',
+ $poster_data[ 'data' ][ 'template_json' ][ 'nickname_font_size' ] * $fontRate * 2,
+ $nickname_color,
+ $poster_data[ 'data' ][ 'template_json' ][ 'nickname_left' ] * 2,
+ ( $poster_data[ 'data' ][ 'template_json' ][ 'nickname_top' ] ) * 2,
+ $poster_data[ 'data' ][ 'template_json' ][ 'nickname_width' ] * 2,
+ $poster_data[ 'data' ][ 'template_json' ][ 'nickname_height' ] * 2,
+ 0,
+ $poster_data[ 'data' ][ 'template_json' ][ 'nickname_is_show' ]
+ ]
+ ],
+ ];
+
+ list($width, $height, $type, $attr) = getimagesize(img($poster_data[ 'data' ][ 'background' ]));
+ $height = 720 * $height / $width;
+ $back_ground = [
+ [
+ 'action' => 'imageCopy', // 写入背景图
+ 'data' => [
+ img($poster_data[ 'data' ][ 'background' ]),
+ 0,
+ 0,
+ 720,
+ $height,
+ 'square',
+ 0,
+ 1
+ ]
+ ],
+ ];
+ $option = array_merge($ground, $back_ground, $option, $member_option);
+ $option_res = $poster->create($option);
+
+ if (is_array($option_res)) return $option_res;
+ $pic_name = rand(10000, 99999);
+ $res = $option_res->jpeg('upload/poster/goods', 'fenxiao' . $pic_name);
+ if ($res[ 'code' ] < 0) {
+ return $res;
+ }
+
+ $upload = new Upload($this->site_id);
+ $cloud_res = $upload->fileCloud($res[ 'data' ][ 'path' ]);
+ return $cloud_res;
+ }
+
+ /**
+ * 删除海报模板
+ * @return mixed
+ */
+ public function delPosterTemplate()
+ {
+ if (request()->isJson()) {
+ $template_ids = input('template_ids', '');
+ $condition = [
+ [ 'template_id', 'in', $template_ids ],
+ [ 'site_id', '=', $this->site_id ],
+ ];
+ $poster_template_model = new PosterTemplateModel();
+ $res = $poster_template_model->deletePosterTemplate($condition);
+ return $res;
+ }
+ }
+
+ /**
+ * 编辑模板状态啊
+ * @return array
+ */
+ public function editstatus()
+ {
+ if (request()->isJson()) {
+ $template_id = input('template_id', 0);
+ $template_status = input('template_status', 0);
+ $condition = [
+ [ 'template_id', 'in', $template_id ],
+ [ 'site_id', '=', $this->site_id ]
+ ];
+ $data = [ 'template_status' => $template_status ];
+ $poster_template_model = new PosterTemplateModel();
+ $res = $poster_template_model->editPosterTemplate($data, $condition);
+ return $res;
+ }
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/fenxiao/shop/controller/Withdraw.php b/src/addon/fenxiao/shop/controller/Withdraw.php
index 6a9348f10..9568c4ecc 100644
--- a/src/addon/fenxiao/shop/controller/Withdraw.php
+++ b/src/addon/fenxiao/shop/controller/Withdraw.php
@@ -1,248 +1,240 @@
-getTransferType($this->site_id);
- if (request()->isJson()) {
- $page = input('page', 1);
- $page_size = input('page_size', PAGE_LIST_ROWS);
- $withdraw_no = input('withdraw_no', '');
- $start_date = input('start_date', '');
- $end_date = input('end_date', '');
- $status = input('status', 'all');//提现状态
- $transfer_type = input('transfer_type', '');//提现转账方式
- $fenxiao_name = input('fenxiao_name', '');//提现转账方式
-
- $payment_start_date = input('payment_start_date', '');
- $payment_end_date = input('payment_end_date', '');
-
- $condition = [ [ 'fw.site_id', '=', $this->site_id ] ];
- if (!empty($withdraw_no)) {
- $condition[] = [ 'fw.withdraw_no', 'like', '%' . $withdraw_no . '%' ];
- }
- if (!empty($transfer_type)) {
- $condition[] = [ 'fw.transfer_type', '=', $transfer_type ];
- }
- if ($status != "all") {
- $condition[] = [ 'fw.status', '=', $status ];
- }
- if (!empty($fenxiao_name)) {
- $condition[] = [ 'm.nickname|fw.fenxiao_name', '=', $fenxiao_name ];
- }
- if ($start_date != '' && $end_date != '') {
- $condition[] = [ 'fw.create_time', 'between', [ strtotime($start_date), strtotime($end_date) ] ];
- } else if ($start_date != '' && $end_date == '') {
- $condition[] = [ 'fw.create_time', '>=', strtotime($start_date) ];
- } else if ($start_date == '' && $end_date != '') {
- $condition[] = [ 'fw.create_time', '<=', strtotime($end_date) ];
- }
-
- if ($payment_start_date != '' && $payment_end_date != '') {
- $condition[] = [ 'fw.payment_time', 'between', [ strtotime($payment_start_date), strtotime($payment_end_date) ] ];
- } else if ($payment_start_date != '' && $payment_end_date == '') {
- $condition[] = [ 'fw.payment_time', '>=', strtotime($payment_start_date) ];
- } else if ($payment_start_date == '' && $payment_end_date != '') {
- $condition[] = [ 'fw.payment_time', '<=', strtotime($payment_end_date) ];
- }
-
- $order = 'fw.create_time desc';
- $field = 'fw.id,fw.site_id,fw.withdraw_no,fw.member_id,fw.fenxiao_id,fw.fenxiao_name,fw.withdraw_type,fw.bank_name,fw.account_number,fw.realname,fw.mobile,fw.money,fw.withdraw_rate,
- fw.withdraw_rate_money,fw.real_money,fw.`status`,fw.remark,fw.create_time,fw.payment_time,fw.modify_time,fw.transfer_type,fw.transfer_name,fw.transfer_remark,fw.transfer_no,
- fw.transfer_account_no,fw.document,fw.audit_time,fw.refuse_reason,fw.applet_type, m.headimg,m.nickname,m.mobile as member_mobile,m.headimg';
- $join = [
- [ 'member m', 'fw.member_id = m.member_id', 'left' ]
- ];
- $list = $model->getFenxiaoWithdrawPageList($condition, $page, $page_size, $order, $field, 'fw', $join);
-
- foreach ($list[ 'data' ][ 'list' ] as $k => $v) {
- $list[ 'data' ][ 'list' ][ $k ][ 'transfer_type_name' ] = $transfer_type_list[ $v[ 'transfer_type' ] ];
- }
- return $list;
- } else {
- $this->assign('transfer_type_list', $transfer_type_list);
-
- $fenxiao_stat_model = new FenxiaoStat();
- $fenxiao_balance_sum = $fenxiao_stat_model->getFenxiaoAccountSum($this->site_id)[ 'data' ] ?? [];
- $this->assign('fenxiao_balance_sum', $fenxiao_balance_sum);
- return $this->fetch("withdraw/lists");
- }
- }
-
- /**
- * 提现记录详情
- * @return mixed
- */
- public function detail()
- {
- $fenxiao_withdraw_model = new FenxiaoWithdrawModel();
- $params = array (
- 'id' => input('id', 0),
- 'site_id' => $this->site_id
- );
- $detail = $fenxiao_withdraw_model->getFenxiaoWithdrawDetail($params)[ 'data' ] ?? [];
- if (empty($detail))
- $this->error('找不到提现账户记录');
-
- $this->assign('info', $detail);
- return $this->fetch('withdraw/detail');
- }
-
- /**
- * 同意
- * @return array
- */
- public function agree()
- {
- if (request()->isJson()) {
- $id = input('id', 0);
- $fenxiao_withdraw_model = new FenxiaoWithdrawModel();
- $params = array (
- 'site_id' => $this->site_id,
- "id" => $id,
- );
- $result = $fenxiao_withdraw_model->agree($params);
- return $result;
- }
- }
-
- /**
- * 拒绝
- * @return array
- */
- public function refuse()
- {
- if (request()->isJson()) {
- $id = input('id', 0);
- $refuse_reason = input('refuse_reason', '');
- $fenxiao_withdraw_model = new FenxiaoWithdrawModel();
- $data = array (
- "refuse_reason" => $refuse_reason,
- 'site_id' => $this->site_id,
- 'id' => $id
- );
- $result = $fenxiao_withdraw_model->refuse($data);
- return $result;
- }
- }
-
- /**
- * 转账
- */
- public function transferFinish()
- {
- if (request()->isJson()) {
- $id = input('id', 0);
- $certificate = input('certificate', '');
- $certificate_remark = input('certificate_remark', '');
- $fenxiao_withdraw_model = new FenxiaoWithdrawModel();
- $data = array (
- "id" => $id,
- "site_id" => $this->site_id,
- "certificate" => $certificate,
- "certificate_remark" => $certificate_remark,
- );
- $result = $fenxiao_withdraw_model->transferFinish($data);
- return $result;
- }
- }
-
- /**
- * 转账
- */
- public function transfer()
- {
- if (request()->isJson()) {
- $id = input('id', 0);
- $fenxiao_withdraw_model = new FenxiaoWithdrawModel();
- $result = $fenxiao_withdraw_model->transfer([ 'id' => $id, 'site_id' => $this->site_id ]);
- return $result;
- }
- }
-
- public function export()
- {
- $fenxiao_withdraw_model = new FenxiaoWithdrawModel();
-
- $withdraw_no = input('withdraw_no', '');
- $start_date = input('start_date', '');
- $end_date = input('end_date', '');
- $status = input('status', 'all');//提现状态
- $transfer_type = input('transfer_type', '');//提现转账方式
- $fenxiao_name = input('fenxiao_name', '');//提现转账方式
-
- $payment_start_date = input('payment_start_date', '');
- $payment_end_date = input('payment_end_date', '');
-
- $condition = [ [ 'site_id', '=', $this->site_id ] ];
- if (!empty($withdraw_no)) {
- $condition[] = [ 'withdraw_no', 'like', '%' . $withdraw_no . '%' ];
- }
- if (!empty($transfer_type)) {
- $condition[] = [ 'transfer_type', '=', $transfer_type ];
- }
- if ($status != "all") {
- $condition[] = [ 'status', '=', $status ];
- }
- if (!empty($fenxiao_name)) {
- $condition[] = [ 'fenxiao_name', '=', $fenxiao_name ];
- }
- if ($start_date != '' && $end_date != '') {
- $condition[] = [ 'create_time', 'between', [ strtotime($start_date), strtotime($end_date) ] ];
- } else if ($start_date != '' && $end_date == '') {
- $condition[] = [ 'create_time', '>=', strtotime($start_date) ];
- } else if ($start_date == '' && $end_date != '') {
- $condition[] = [ 'create_time', '<=', strtotime($end_date) ];
- }
-
- if ($payment_start_date != '' && $payment_end_date != '') {
- $condition[] = [ 'payment_time', 'between', [ strtotime($payment_start_date), strtotime($payment_end_date) ] ];
- } else if ($payment_start_date != '' && $payment_end_date == '') {
- $condition[] = [ 'payment_time', '>=', strtotime($payment_start_date) ];
- } else if ($payment_start_date == '' && $payment_end_date != '') {
- $condition[] = [ 'payment_time', '<=', strtotime($payment_end_date) ];
- }
- $order = 'create_time desc';
- $fenxiao_withdraw_model->exportFenxiaoWithdraw($condition, $order, $this->site_id);
- }
-//
-// public function test(){
-// $model = new FenxiaoWithdrawModel();
-// $data = array (
-// 'member_id' => 417,
-// 'transfer_type' => 'alipay',
-// 'realname' => $realname ?? 'zxczx',
-// 'bank_name' => $bank_name ?? '45yuik',
-// 'account_number' => $account_number ?? '43453',
-// 'apply_money' => $apply_money ?? '1',
-// 'mobile' => $mobile ?? '18541256985',
-// 'app_type' => $app_type ?? ''
-// );
-// $result = $model->apply($data, $this->site_id);
-// dd($result);
-// }
+getTransferType($this->site_id);
+ if (request()->isJson()) {
+ $page = input('page', 1);
+ $page_size = input('page_size', PAGE_LIST_ROWS);
+ $withdraw_no = input('withdraw_no', '');
+ $start_date = input('start_date', '');
+ $end_date = input('end_date', '');
+ $status = input('status', 'all');//提现状态
+ $transfer_type = input('transfer_type', '');//提现转账方式
+ $fenxiao_name = input('fenxiao_name', '');//提现转账方式
+
+ $payment_start_date = input('payment_start_date', '');
+ $payment_end_date = input('payment_end_date', '');
+
+ $condition = [ [ 'fw.site_id', '=', $this->site_id ] ];
+ if (!empty($withdraw_no)) {
+ $condition[] = [ 'fw.withdraw_no', 'like', '%' . $withdraw_no . '%' ];
+ }
+ if (!empty($transfer_type)) {
+ $condition[] = [ 'fw.transfer_type', '=', $transfer_type ];
+ }
+ if ($status != "all") {
+ $condition[] = [ 'fw.status', '=', $status ];
+ }
+ if (!empty($fenxiao_name)) {
+ $condition[] = [ 'm.nickname|fw.fenxiao_name', '=', $fenxiao_name ];
+ }
+ if ($start_date != '' && $end_date != '') {
+ $condition[] = [ 'fw.create_time', 'between', [ strtotime($start_date), strtotime($end_date) ] ];
+ } else if ($start_date != '' && $end_date == '') {
+ $condition[] = [ 'fw.create_time', '>=', strtotime($start_date) ];
+ } else if ($start_date == '' && $end_date != '') {
+ $condition[] = [ 'fw.create_time', '<=', strtotime($end_date) ];
+ }
+
+ if ($payment_start_date != '' && $payment_end_date != '') {
+ $condition[] = [ 'fw.payment_time', 'between', [ strtotime($payment_start_date), strtotime($payment_end_date) ] ];
+ } else if ($payment_start_date != '' && $payment_end_date == '') {
+ $condition[] = [ 'fw.payment_time', '>=', strtotime($payment_start_date) ];
+ } else if ($payment_start_date == '' && $payment_end_date != '') {
+ $condition[] = [ 'fw.payment_time', '<=', strtotime($payment_end_date) ];
+ }
+
+ $order = 'fw.create_time desc';
+ $field = 'fw.id,fw.site_id,fw.withdraw_no,fw.member_id,fw.fenxiao_id,fw.fenxiao_name,fw.withdraw_type,fw.bank_name,fw.account_number,fw.realname,fw.mobile,fw.money,fw.withdraw_rate,
+ fw.withdraw_rate_money,fw.real_money,fw.`status`,fw.remark,fw.create_time,fw.payment_time,fw.modify_time,fw.transfer_type,fw.transfer_name,fw.transfer_remark,fw.transfer_no,
+ fw.transfer_account_no,fw.document,fw.audit_time,fw.refuse_reason,fw.applet_type, m.headimg,m.nickname,m.mobile as member_mobile,m.headimg';
+ $join = [
+ [ 'member m', 'fw.member_id = m.member_id', 'left' ]
+ ];
+ $list = $model->getFenxiaoWithdrawPageList($condition, $page, $page_size, $order, $field, 'fw', $join);
+
+ foreach ($list[ 'data' ][ 'list' ] as $k => $v) {
+ $list[ 'data' ][ 'list' ][ $k ][ 'transfer_type_name' ] = $transfer_type_list[ $v[ 'transfer_type' ] ];
+ }
+ return $list;
+ } else {
+ $this->assign('transfer_type_list', $transfer_type_list);
+
+ $fenxiao_stat_model = new FenxiaoStat();
+ $fenxiao_balance_sum = $fenxiao_stat_model->getFenxiaoAccountSum($this->site_id)[ 'data' ] ?? [];
+ $this->assign('fenxiao_balance_sum', $fenxiao_balance_sum);
+ return $this->fetch("withdraw/lists");
+ }
+ }
+
+ /**
+ * 提现记录详情
+ * @return mixed
+ */
+ public function detail()
+ {
+ $fenxiao_withdraw_model = new FenxiaoWithdrawModel();
+ $params = array (
+ 'id' => input('id', 0),
+ 'site_id' => $this->site_id
+ );
+ $detail = $fenxiao_withdraw_model->getFenxiaoWithdrawDetail($params)[ 'data' ] ?? [];
+ if (empty($detail))
+ $this->error('找不到提现账户记录');
+
+ $this->assign('info', $detail);
+ return $this->fetch('withdraw/detail');
+ }
+
+ /**
+ * 同意
+ * @return array
+ */
+ public function agree()
+ {
+ if (request()->isJson()) {
+ $id = input('id', 0);
+ $fenxiao_withdraw_model = new FenxiaoWithdrawModel();
+ $params = array (
+ 'site_id' => $this->site_id,
+ "id" => $id,
+ );
+ $result = $fenxiao_withdraw_model->agree($params);
+ return $result;
+ }
+ }
+
+ /**
+ * 拒绝
+ * @return array
+ */
+ public function refuse()
+ {
+ if (request()->isJson()) {
+ $id = input('id', 0);
+ $refuse_reason = input('refuse_reason', '');
+ $fenxiao_withdraw_model = new FenxiaoWithdrawModel();
+ $data = array (
+ "refuse_reason" => $refuse_reason,
+ 'site_id' => $this->site_id,
+ 'id' => $id
+ );
+ $result = $fenxiao_withdraw_model->refuse($data);
+ return $result;
+ }
+ }
+
+ /**
+ * 转账
+ */
+ public function transferFinish()
+ {
+ if (request()->isJson()) {
+ $id = input('id', 0);
+ $certificate = input('certificate', '');
+ $certificate_remark = input('certificate_remark', '');
+ $fenxiao_withdraw_model = new FenxiaoWithdrawModel();
+ $data = array (
+ "id" => $id,
+ "site_id" => $this->site_id,
+ "certificate" => $certificate,
+ "certificate_remark" => $certificate_remark,
+ );
+ $result = $fenxiao_withdraw_model->transferFinish($data);
+ return $result;
+ }
+ }
+
+ /**
+ * 转账
+ */
+ public function transfer()
+ {
+ if (request()->isJson()) {
+ $id = input('id', 0);
+ $fenxiao_withdraw_model = new FenxiaoWithdrawModel();
+ $result = $fenxiao_withdraw_model->transfer([ 'id' => $id, 'site_id' => $this->site_id ]);
+ return $result;
+ }
+ }
+
+ public function export()
+ {
+ $fenxiao_withdraw_model = new FenxiaoWithdrawModel();
+
+ $withdraw_no = input('withdraw_no', '');
+ $start_date = input('start_date', '');
+ $end_date = input('end_date', '');
+ $status = input('status', 'all');//提现状态
+ $transfer_type = input('transfer_type', '');//提现转账方式
+ $fenxiao_name = input('fenxiao_name', '');//提现转账方式
+
+ $payment_start_date = input('payment_start_date', '');
+ $payment_end_date = input('payment_end_date', '');
+
+ $condition = [ [ 'site_id', '=', $this->site_id ] ];
+ if (!empty($withdraw_no)) {
+ $condition[] = [ 'withdraw_no', 'like', '%' . $withdraw_no . '%' ];
+ }
+ if (!empty($transfer_type)) {
+ $condition[] = [ 'transfer_type', '=', $transfer_type ];
+ }
+ if ($status != "all") {
+ $condition[] = [ 'status', '=', $status ];
+ }
+ if (!empty($fenxiao_name)) {
+ $condition[] = [ 'fenxiao_name', '=', $fenxiao_name ];
+ }
+ if ($start_date != '' && $end_date != '') {
+ $condition[] = [ 'create_time', 'between', [ strtotime($start_date), strtotime($end_date) ] ];
+ } else if ($start_date != '' && $end_date == '') {
+ $condition[] = [ 'create_time', '>=', strtotime($start_date) ];
+ } else if ($start_date == '' && $end_date != '') {
+ $condition[] = [ 'create_time', '<=', strtotime($end_date) ];
+ }
+
+ if ($payment_start_date != '' && $payment_end_date != '') {
+ $condition[] = [ 'payment_time', 'between', [ strtotime($payment_start_date), strtotime($payment_end_date) ] ];
+ } else if ($payment_start_date != '' && $payment_end_date == '') {
+ $condition[] = [ 'payment_time', '>=', strtotime($payment_start_date) ];
+ } else if ($payment_start_date == '' && $payment_end_date != '') {
+ $condition[] = [ 'payment_time', '<=', strtotime($payment_end_date) ];
+ }
+ $order = 'create_time desc';
+ $fenxiao_withdraw_model->exportFenxiaoWithdraw($condition, $order, $this->site_id);
+ }
+//
+// public function test(){
+// $model = new FenxiaoWithdrawModel();
+// $data = array (
+// 'member_id' => 417,
+// 'transfer_type' => 'alipay',
+// 'realname' => $realname ?? 'zxczx',
+// 'bank_name' => $bank_name ?? '45yuik',
+// 'account_number' => $account_number ?? '43453',
+// 'apply_money' => $apply_money ?? '1',
+// 'mobile' => $mobile ?? '18541256985',
+// 'app_type' => $app_type ?? ''
+// );
+// $result = $model->apply($data, $this->site_id);
+// dd($result);
+// }
}
\ No newline at end of file
diff --git a/src/addon/form/api/controller/Form.php b/src/addon/form/api/controller/Form.php
index e476333b2..23ff61d69 100644
--- a/src/addon/form/api/controller/Form.php
+++ b/src/addon/form/api/controller/Form.php
@@ -1,88 +1,79 @@
-site_id)) return $this->response( $this->success([]) );
-
- $goods_id = $this->params['goods_id'] ?? 0;
-
- $condition = [
- ['g.site_id', '=', $this->site_id ],
- ['g.goods_id', '=', $goods_id ],
- ['g.form_id', '>', 0 ],
- ['f.is_use', '=', 1 ]
- ];
- $data = (new Goods())->getGoodsInfo($condition, 'f.json_data', 'g', [ ['form f', 'g.form_id = f.id', 'left'] ])['data'];
- if (!empty($data)) {
- return $this->response( $this->success( json_decode($data['json_data'], true) ) );
- }
- return $this->response( $this->success($data) );
- }
-
- /**
- * 获取表单信息
- * @return false|string
- */
- public function info(){
- $form_id = $this->params['form_id'] ?? 0;
- $uniacid = $this->params['uniacid'] ?? 0;
- $condition = [
- ['site_id', '=', $uniacid ],
- ['id', '=', $form_id ],
- ['is_use', '=', 1 ],
- ['form_type', '=', 'custom' ]
- ];
- $data = (new FormModel())->getFormInfo($condition, 'json_data,form_name');
- // file_put_contents(__DIR__ . '/debug.txt', var_export($data,true));
- if (!empty($data['data'])) {
- $data['data']['json_data'] = json_decode($data['data']['json_data'], true);
- // $data['data']['title'] = model('form')->getValue(['id'=>$form_id]);
- }
- return $this->response($data);
- }
-
- /**
- * 添加表单数据
- * @return false|string
- */
- public function create(){
- // $token = $this->checkToken();
- // if ($token['code'] < 0) return $this->response($token);
-
- $form_id = $this->params['form_id'] ?? 0;
- $form_data = $this->params[ 'form_data' ] ?? '[]';
- $uniacid = $this->params['uniacid'] ?? 0;
- $data = [
- 'site_id' => $uniacid,
- 'form_id' => $form_id,
- // 'member_id' => $this->member_id,
- 'relation_id' => 0,
- 'form_data' => json_decode($form_data, true),
- 'scene' => 'custom'
- ];
-
- $res = (new FormModel())->addFormData($data);
- return $this->response($res);
- }
+site_id)) return $this->response( $this->success([]) );
+
+ $goods_id = $this->params['goods_id'] ?? 0;
+
+ $condition = [
+ ['g.site_id', '=', $this->site_id ],
+ ['g.goods_id', '=', $goods_id ],
+ ['g.form_id', '>', 0 ],
+ ['f.is_use', '=', 1 ]
+ ];
+ $data = (new Goods())->getGoodsInfo($condition, 'f.json_data', 'g', [ ['form f', 'g.form_id = f.id', 'left'] ])['data'];
+ if (!empty($data)) {
+ return $this->response( $this->success( json_decode($data['json_data'], true) ) );
+ }
+ return $this->response( $this->success($data) );
+ }
+
+ /**
+ * 获取表单信息
+ * @return false|string
+ */
+ public function info(){
+ $form_id = $this->params['form_id'] ?? 0;
+ $uniacid = $this->params['uniacid'] ?? 0;
+ $condition = [
+ ['site_id', '=', $uniacid ],
+ ['id', '=', $form_id ],
+ ['is_use', '=', 1 ],
+ ['form_type', '=', 'custom' ]
+ ];
+ $data = (new FormModel())->getFormInfo($condition, 'json_data,form_name');
+ // file_put_contents(__DIR__ . '/debug.txt', var_export($data,true));
+ if (!empty($data['data'])) {
+ $data['data']['json_data'] = json_decode($data['data']['json_data'], true);
+ // $data['data']['title'] = model('form')->getValue(['id'=>$form_id]);
+ }
+ return $this->response($data);
+ }
+
+ /**
+ * 添加表单数据
+ * @return false|string
+ */
+ public function create(){
+ // $token = $this->checkToken();
+ // if ($token['code'] < 0) return $this->response($token);
+
+ $form_id = $this->params['form_id'] ?? 0;
+ $form_data = $this->params[ 'form_data' ] ?? '[]';
+ $uniacid = $this->params['uniacid'] ?? 0;
+ $data = [
+ 'site_id' => $uniacid,
+ 'form_id' => $form_id,
+ // 'member_id' => $this->member_id,
+ 'relation_id' => 0,
+ 'form_data' => json_decode($form_data, true),
+ 'scene' => 'custom'
+ ];
+
+ $res = (new FormModel())->addFormData($data);
+ return $this->response($res);
+ }
}
\ No newline at end of file
diff --git a/src/addon/form/config/diy_view.php b/src/addon/form/config/diy_view.php
index fa9a281c6..4648affe2 100644
--- a/src/addon/form/config/diy_view.php
+++ b/src/addon/form/config/diy_view.php
@@ -1,47 +1,39 @@
- '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
- 'template' => [],
-
- // 后台自定义组件——装修
- 'util' => [],
-
- // 自定义页面路径
- 'link' => [
- [
- 'name' => 'DIY_FORM',
- 'title' => '自定义表单',
- 'parent' => 'INTERACTION_PROMOTION',
- 'wap_url' => '',
- 'web_url' => '',
- 'sort' => 4
- ]
- ],
-
- // 自定义图标库
- 'icon_library' => [],
-
- // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
- 'component' => [],
-
- // uni-app 页面,多个逗号隔开
- 'pages' => [],
-
- // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
- 'info' => [],
-
- // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
- 'theme' => [],
-
- // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
- 'data' => []
+ '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
+ 'template' => [],
+
+ // 后台自定义组件——装修
+ 'util' => [],
+
+ // 自定义页面路径
+ 'link' => [
+ [
+ 'name' => 'DIY_FORM',
+ 'title' => '自定义表单',
+ 'parent' => 'INTERACTION_PROMOTION',
+ 'wap_url' => '',
+ 'web_url' => '',
+ 'sort' => 4
+ ]
+ ],
+
+ // 自定义图标库
+ 'icon_library' => [],
+
+ // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
+ 'component' => [],
+
+ // uni-app 页面,多个逗号隔开
+ 'pages' => [],
+
+ // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
+ 'info' => [],
+
+ // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
+ 'theme' => [],
+
+ // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
+ 'data' => []
];
\ No newline at end of file
diff --git a/src/addon/form/config/info.php b/src/addon/form/config/info.php
index 71426c629..60727ad68 100644
--- a/src/addon/form/config/info.php
+++ b/src/addon/form/config/info.php
@@ -1,21 +1,12 @@
- 'form',
- 'title' => '系统表单',
- 'description' => '表单自定义信息收集',
- 'type' => 'system', //插件类型 system :系统插件(自动安装), business:业务插件 promotion:营销插件 tool:工具插件
- 'status' => 1,
- 'author' => '',
- 'version' => '5.3.1',
- 'version_no' => '525231212001',
- 'content' => '',
+ 'form',
+ 'title' => '系统表单',
+ 'description' => '表单自定义信息收集',
+ 'type' => 'system', //插件类型 system :系统插件(自动安装), business:业务插件 promotion:营销插件 tool:工具插件
+ 'status' => 1,
+ 'author' => '',
+ 'version' => '5.3.1',
+ 'version_no' => '525231212001',
+ 'content' => '',
];
\ No newline at end of file
diff --git a/src/addon/form/event/Install.php b/src/addon/form/event/Install.php
index a27492fe0..f2d3736e1 100644
--- a/src/addon/form/event/Install.php
+++ b/src/addon/form/event/Install.php
@@ -1,27 +1,18 @@
-param['form_data'] ?? [];
- if ($form_data) {
- $site_id = $order_object->site_id;
- $order_id = $order_object->order_id;
- $member_id = $order_object->member_id;
- // 添加订单表单
- $form = new Form();
- if (isset($form_data[ 'form_data' ])) {
- $res = $form->addFormData([
- 'site_id' => $site_id,
- 'form_id' => $form_data[ 'form_id' ],
- 'member_id' => $member_id,
- 'relation_id' => $order_id,
- 'form_data' => $form_data[ 'form_data' ],
- 'scene' => 'order'
- ]);
- if ($res[ 'code' ] != 0) return $res;
- }
- // 添加商品表单
- $goods_form = $form_data[ 'goods_form' ] ?? [];
- if ($goods_form) {
- //查询订单项
-// $goods_list = array_column($order_object->goods_list, null, 'sku_id');
- $order_goods_list = array_column($order_object->getOrderGoodsList(), null, 'sku_id');
- foreach ($goods_form as $sku_id => $form_item) {
-// $goods_item = $goods_list[ $sku_id ] ?? [];
- $order_goods_item = $order_goods_list[$sku_id] ?? [];
- $res = $form->addFormData([
- 'site_id' => $site_id,
- 'form_id' => $form_item[ 'form_id' ],
- 'member_id' => $member_id,
- 'relation_id' => $order_goods_item[ 'order_goods_id' ] ?? 0,
- 'form_data' => $form_item[ 'form_data' ],
- 'scene' => 'goods'
- ]);
- if ($res[ 'code' ] != 0) return $res;
- }
- }
- }
- return success();
- }
+param['form_data'] ?? [];
+ if ($form_data) {
+ $site_id = $order_object->site_id;
+ $order_id = $order_object->order_id;
+ $member_id = $order_object->member_id;
+ // 添加订单表单
+ $form = new Form();
+ if (isset($form_data[ 'form_data' ])) {
+ $res = $form->addFormData([
+ 'site_id' => $site_id,
+ 'form_id' => $form_data[ 'form_id' ],
+ 'member_id' => $member_id,
+ 'relation_id' => $order_id,
+ 'form_data' => $form_data[ 'form_data' ],
+ 'scene' => 'order'
+ ]);
+ if ($res[ 'code' ] != 0) return $res;
+ }
+ // 添加商品表单
+ $goods_form = $form_data[ 'goods_form' ] ?? [];
+ if ($goods_form) {
+ //查询订单项
+// $goods_list = array_column($order_object->goods_list, null, 'sku_id');
+ $order_goods_list = array_column($order_object->getOrderGoodsList(), null, 'sku_id');
+ foreach ($goods_form as $sku_id => $form_item) {
+// $goods_item = $goods_list[ $sku_id ] ?? [];
+ $order_goods_item = $order_goods_list[$sku_id] ?? [];
+ $res = $form->addFormData([
+ 'site_id' => $site_id,
+ 'form_id' => $form_item[ 'form_id' ],
+ 'member_id' => $member_id,
+ 'relation_id' => $order_goods_item[ 'order_goods_id' ] ?? 0,
+ 'form_data' => $form_item[ 'form_data' ],
+ 'scene' => 'goods'
+ ]);
+ if ($res[ 'code' ] != 0) return $res;
+ }
+ }
+ }
+ return success();
+ }
}
\ No newline at end of file
diff --git a/src/addon/form/event/OrderPayment.php b/src/addon/form/event/OrderPayment.php
index 86de9a460..10b8c6fe5 100644
--- a/src/addon/form/event/OrderPayment.php
+++ b/src/addon/form/event/OrderPayment.php
@@ -1,52 +1,44 @@
-site_id;
- $form_model = new Form();
- $info = $form_model->getFormInfo([ [ 'site_id', '=', $site_id], [ 'is_use', '=', 1 ], [ 'form_type', '=', 'order' ] ], 'id,json_data,form_name')[ 'data' ] ?? [];
- if (!empty($info)) {
- $info[ 'json_data' ] = json_decode($info[ 'json_data' ], true);
- //todo 查询用法
- $order_object->system_form = $info;
- }
- $form_ids = array_filter(array_unique(array_column($order_object->goods_list, 'form_id')));
- if($form_ids){
- $form_list = $form_model->getFormList([ [ 'site_id', '=', $site_id], [ 'is_use', '=', 1 ] , ['id', 'in', $form_ids]], '', 'id, json_data')['data'] ?? [];
- $form_array = array_column($form_list, null, 'id');
- foreach($order_object->goods_list as &$goods_item){
- $item_form = $form_array[$goods_item['form_id'] ?? 0] ?? [];
- if($item_form){
- $item_form['json_data'] = json_decode($item_form[ 'json_data' ], true);
- $goods_item[ 'goods_form' ] = $item_form;
- }
- }
- }
-
- return true;
- }
+site_id;
+ $form_model = new Form();
+ $info = $form_model->getFormInfo([ [ 'site_id', '=', $site_id], [ 'is_use', '=', 1 ], [ 'form_type', '=', 'order' ] ], 'id,json_data,form_name')[ 'data' ] ?? [];
+ if (!empty($info)) {
+ $info[ 'json_data' ] = json_decode($info[ 'json_data' ], true);
+ //todo 查询用法
+ $order_object->system_form = $info;
+ }
+ $form_ids = array_filter(array_unique(array_column($order_object->goods_list, 'form_id')));
+ if($form_ids){
+ $form_list = $form_model->getFormList([ [ 'site_id', '=', $site_id], [ 'is_use', '=', 1 ] , ['id', 'in', $form_ids]], '', 'id, json_data')['data'] ?? [];
+ $form_array = array_column($form_list, null, 'id');
+ foreach($order_object->goods_list as &$goods_item){
+ $item_form = $form_array[$goods_item['form_id'] ?? 0] ?? [];
+ if($item_form){
+ $item_form['json_data'] = json_decode($item_form[ 'json_data' ], true);
+ $goods_item[ 'goods_form' ] = $item_form;
+ }
+ }
+ }
+
+ return true;
+ }
}
\ No newline at end of file
diff --git a/src/addon/form/event/ShowPromotion.php b/src/addon/form/event/ShowPromotion.php
index 5cd9028c1..15d6813f5 100644
--- a/src/addon/form/event/ShowPromotion.php
+++ b/src/addon/form/event/ShowPromotion.php
@@ -1,46 +1,38 @@
- [
- [
- //插件名称
- 'name' => 'form',
- //店铺端展示分类 shop:营销活动 member:互动营销
- 'show_type' => 'tool',
- //展示主题
- 'title' => '系统表单',
- //展示介绍
- 'description' => '帮助商家快速收集客户信息',
- //展示图标
- 'icon' => 'addon/form/icon.png',
- //跳转链接
- 'url' => 'form://shop/form/lists',
- ]
- ]
-
- ];
- return $data;
- }
+ [
+ [
+ //插件名称
+ 'name' => 'form',
+ //店铺端展示分类 shop:营销活动 member:互动营销
+ 'show_type' => 'tool',
+ //展示主题
+ 'title' => '系统表单',
+ //展示介绍
+ 'description' => '帮助商家快速收集客户信息',
+ //展示图标
+ 'icon' => 'addon/form/icon.png',
+ //跳转链接
+ 'url' => 'form://shop/form/lists',
+ ]
+ ]
+
+ ];
+ return $data;
+ }
}
\ No newline at end of file
diff --git a/src/addon/form/event/UnInstall.php b/src/addon/form/event/UnInstall.php
index b3dcdc0f2..6c16996ba 100644
--- a/src/addon/form/event/UnInstall.php
+++ b/src/addon/form/event/UnInstall.php
@@ -1,27 +1,18 @@
- [
- 'type' => 'order',
- 'name' => '统一下单',
- 'preview_img' => 'addon/form/shop/view/public/img/preview/order.png',
- 'head_img' => 'addon/form/shop/view/public/img/head/order.png'
- ],
- 'goods' => [
- 'type' => 'goods',
- 'name' => '商品表单',
- 'preview_img' => 'addon/form/shop/view/public/img/preview/goods.png',
- 'head_img' => 'addon/form/shop/view/public/img/head/goods.png'
- ],
- 'custom' => [
- 'type' => 'custom',
- 'name' => '自定义表单',
- 'preview_img' => 'addon/form/shop/view/public/img/preview/custom.png',
- 'head_img' => 'addon/form/shop/view/public/img/head/custom.png'
- ]
- ];
-
- /**
- * 表单组件
- */
- const FORM_COMPONENT = [
- 'ONE_LINE_TEXT' => [
- 'name' => 'ONE_LINE_TEXT',
- 'title' => '单行文本',
- 'type' => 'SYSTEM',
- 'controller' => 'Text',
- 'value' => [
- 'title' => '单行文本框',
- 'placeholder' => '请输入提示语',
- 'default' => '',
- 'required' => true
- ],
- 'sort' => '10000',
- 'support_diy_view' => '',
- 'max_count' => 0,
- 'is_delete' => 0,
- 'icon' => 'addon/form/shop/view/public/img/icon/on_line_text.png',
- 'icon_selected' => 'addon/form/shop/view/public/img/icon/on_line_text_selected.png'
- ],
- 'MANY_LINE_TEXT' => [
- 'name' => 'MANY_LINE_TEXT',
- 'title' => '多行文本',
- 'type' => 'SYSTEM',
- 'controller' => 'Textarea',
- 'value' => [
- 'title' => '多行文本',
- 'placeholder' => '请输入提示语',
- 'default' => '',
- 'required' => true
- ],
- 'sort' => '10000',
- 'support_diy_view' => '',
- 'max_count' => 0,
- 'is_delete' => 0,
- 'icon' => 'addon/form/shop/view/public/img/icon/many_line_text.png',
- 'icon_selected' => 'addon/form/shop/view/public/img/icon/many_line_text_selected.png'
- ],
- 'ID_CARD' => [
- 'name' => 'ID_CARD',
- 'title' => '身份证号码',
- 'type' => 'SYSTEM',
- 'controller' => 'Text',
- 'value' => [
- 'title' => '身份证号码',
- 'placeholder' => '请输入身份证号码',
- 'required' => true
- ],
- 'sort' => '10000',
- 'support_diy_view' => '',
- 'max_count' => 0,
- 'is_delete' => 0,
- 'icon' => 'addon/form/shop/view/public/img/icon/id_card.png',
- 'icon_selected' => 'addon/form/shop/view/public/img/icon/id_card_selected.png'
- ],
- 'SELECT' => [
- 'name' => 'SELECT',
- 'title' => '下拉框',
- 'type' => 'SYSTEM',
- 'controller' => 'Select',
- 'value' => [
- 'title' => '下拉框',
- 'options' => [
- '选项一',
- '选项二'
- ],
- 'required' => true
- ],
- 'sort' => '10000',
- 'support_diy_view' => '',
- 'max_count' => 0,
- 'is_delete' => 0,
- 'icon' => 'addon/form/shop/view/public/img/icon/select.png',
- 'icon_selected' => 'addon/form/shop/view/public/img/icon/select_selected.png'
- ],
- 'CHECKBOX' => [
- 'name' => 'CHECKBOX',
- 'title' => '多选框',
- 'type' => 'SYSTEM',
- 'controller' => 'Checkbox',
- 'value' => [
- 'title' => '多选框',
- 'options' => [
- '选项一',
- '选项二'
- ],
- 'required' => true
- ],
- 'sort' => '10000',
- 'support_diy_view' => '',
- 'max_count' => 0,
- 'is_delete' => 0,
- 'icon' => 'addon/form/shop/view/public/img/icon/checkbox.png',
- 'icon_selected' => 'addon/form/shop/view/public/img/icon/checkbox_selected.png'
- ],
- 'RADIO' => [
- 'name' => 'RADIO',
- 'title' => '单选框',
- 'type' => 'SYSTEM',
- 'controller' => 'Radio',
- 'value' => [
- 'title' => '单选框',
- 'options' => [
- '选项一',
- '选项二'
- ],
- 'required' => true
- ],
- 'sort' => '10000',
- 'support_diy_view' => '',
- 'max_count' => 0,
- 'is_delete' => 0,
- 'icon' => 'addon/form/shop/view/public/img/icon/radio.png',
- 'icon_selected' => 'addon/form/shop/view/public/img/icon/radio_selected.png'
- ],
- 'IMG' => [
- 'name' => 'IMG',
- 'title' => '图片',
- 'type' => 'SYSTEM',
- 'controller' => 'Img',
- 'value' => [
- 'title' => '图片',
- 'max_count' => 3,
- 'required' => true
- ],
- 'sort' => '10000',
- 'support_diy_view' => '',
- 'max_count' => 0,
- 'is_delete' => 0,
- 'icon' => 'addon/form/shop/view/public/img/icon/img.png',
- 'icon_selected' => 'addon/form/shop/view/public/img/icon/img_selected.png'
- ],
- 'DATE' => [
- 'name' => 'DATE',
- 'title' => '日期',
- 'type' => 'SYSTEM',
- 'controller' => 'Date',
- 'value' => [
- 'title' => '日期',
- 'placeholder' => '请输入提示语',
- 'is_show_default' => true,
- 'is_current' => true,
- 'default' => '',
- 'required' => true
- ],
- 'sort' => '10000',
- 'support_diy_view' => '',
- 'max_count' => 0,
- 'is_delete' => 0,
- 'icon' => 'addon/form/shop/view/public/img/icon/date.png',
- 'icon_selected' => 'addon/form/shop/view/public/img/icon/date_selected.png'
- ],
- 'DATE_LIMIT' => [
- 'name' => 'DATE_LIMIT',
- 'title' => '日期范围',
- 'type' => 'SYSTEM',
- 'controller' => 'Datelimit',
- 'value' => [
- 'title' => '日期范围',
- 'placeholder_start' => '请输入起始日期提示语',
- 'placeholder_end' => '请输入结束日期提示语',
- 'is_show_default_start' => true,
- 'is_show_default_end' => true,
- 'is_current_start' => true,
- 'is_current_end' => true,
- 'default_start' => '',
- 'default_end' => '',
- 'required' => true
- ],
- 'sort' => '10000',
- 'support_diy_view' => '',
- 'max_count' => 0,
- 'is_delete' => 0,
- 'icon' => 'addon/form/shop/view/public/img/icon/date_limit.png',
- 'icon_selected' => 'addon/form/shop/view/public/img/icon/date_limit_selected.png'
- ],
- 'TIME' => [
- 'name' => 'TIME',
- 'title' => '时间',
- 'type' => 'SYSTEM',
- 'controller' => 'Time',
- 'value' => [
- 'title' => '时间',
- 'placeholder' => '请输入提示语',
- 'is_show_default' => true,
- 'is_current' => true,
- 'default' => '',
- 'required' => true
- ],
- 'sort' => '10000',
- 'support_diy_view' => '',
- 'max_count' => 0,
- 'is_delete' => 0,
- 'icon' => 'addon/form/shop/view/public/img/icon/time.png',
- 'icon_selected' => 'addon/form/shop/view/public/img/icon/time_selected.png'
- ],
- 'TIME_LIMIT' => [
- 'name' => 'TIME_LIMIT',
- 'title' => '时间范围',
- 'type' => 'SYSTEM',
- 'controller' => 'Timelimit',
- 'value' => [
- 'title' => '时间范围',
- 'placeholder_start' => '请输入起始时间提示语',
- 'placeholder_end' => '请输入结束时间提示语',
- 'is_show_default_start' => true,
- 'is_show_default_end' => true,
- 'is_current_start' => true,
- 'is_current_end' => true,
- 'default_start' => '',
- 'default_end' => '',
- 'required' => true
- ],
- 'sort' => '10000',
- 'support_diy_view' => '',
- 'max_count' => 0,
- 'is_delete' => 0,
- 'icon' => 'addon/form/shop/view/public/img/icon/time_limit.png',
- 'icon_selected' => 'addon/form/shop/view/public/img/icon/time_limit_selected.png'
- ],
- 'CITY' => [
- 'name' => 'CITY',
- 'title' => '城市',
- 'type' => 'SYSTEM',
- 'controller' => 'City',
- 'value' => [
- 'title' => '城市',
- 'placeholder' => '请输入提示语',
- 'default_type' => 1,
- 'required' => true
- ],
- 'sort' => '10000',
- 'support_diy_view' => '',
- 'max_count' => 0,
- 'is_delete' => 0,
- 'icon' => 'addon/form/shop/view/public/img/icon/city.png',
- 'icon_selected' => 'addon/form/shop/view/public/img/icon/city_selected.png'
- ],
- 'MOBILE' => [
- 'name' => 'MOBILE',
- 'title' => '手机号码',
- 'type' => 'SYSTEM',
- 'controller' => 'Text',
- 'value' => [
- 'title' => '手机号码',
- 'placeholder' => '请输入手机号码',
- 'required' => true
- ],
- 'sort' => '10000',
- 'support_diy_view' => '',
- 'max_count' => 0,
- 'is_delete' => 0,
- 'icon' => 'addon/form/shop/view/public/img/icon/mobile.png',
- 'icon_selected' => 'addon/form/shop/view/public/img/icon/mobile_selected.png'
- ],
- ];
-
- /**
- * 添加自定义模板
- * @param $data
- * @return array
- */
- public function addForm($data)
- {
- $res = model('form')->add($data);
- if ($res) {
- Cache::tag('form')->clear();
- return $this->success($res);
- } else {
- return $this->error($res);
- }
- }
-
-
- /**
- * 修改自定义模板
- * @param array $data
- * @param array $condition
- * @return array
- */
- public function editForm($data, $condition)
- {
- $res = model('form')->update($data, $condition);
- if ($res) {
- Cache::tag('form')->clear();
- return $this->success($res);
- } else {
- return $this->error($res);
- }
- }
-
- /**
- * 获取自定义模板信息
- * @param array $condition
- * @param string $field
- * @return array
- */
- public function getFormInfo($condition = [], $field = '*', $alias = 'a', $join = [])
- {
-
- $info = model('form')->getInfo($condition, $field, $alias, $join);
- return $this->success($info);
- }
-
- /**
- * 删除表单
- * @param array $condition
- * @return array
- */
- public function deleteForm($id, $site_id)
- {
- model('form')->startTrans();
-
- $res = model('form')->delete([ [ 'id', '=', $id ], [ 'site_id', '=', $site_id ] ]);
- if ($res) {
- model('form_data')->delete([ [ 'form_id', '=', $id ], [ 'site_id', '=', $site_id ] ]);
- model('form')->commit();
- Cache::tag('form')->clear();
- return $this->success($res);
- } else {
- model('form')->rollback();
- return $this->error($res);
- }
- }
-
- /**
- * 获取表单分页列表
- * @param array $condition
- * @param int $page
- * @param int $page_size
- * @param string $order
- * @param string $field
- * @return array
- */
- public function getFormPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'id desc', $field = '*')
- {
- $list = model('form')->pageList($condition, $field, $order, $page, $page_size);
- return $this->success($list);
- }
-
- /**
- * 获取表单列表
- * @param array $condition
- * @param string $order
- * @param string $field
- * @return array
- */
- public function getFormList($condition = [], $order = 'id desc', $field = '*')
- {
- $data = json_encode([ $condition, $field, $order]);
- $cache = Cache::get('form_getFormList_' . $data);
- if (!empty($cache)) {
- return $this->success($cache);
- }
- $list = model('form')->getList($condition, $field, $order);
- Cache::tag('form')->set('form_getFormList_' . $data, $list);
- return $this->success($list);
- }
-
- /**
- * 查询订单数据并导出
- * @param $condition
- */
- public function export($param)
- {
- $form_info = model('form')->getInfo([ [ 'id', '=', $param[ 'id' ] ], [ 'site_id', '=', $param[ 'site_id' ] ] ], 'form_name,id,json_data');
- if (empty($form_info)) return $this->error('', '未获取到表单信息');
- $form_info[ 'json_data' ] = json_decode($form_info[ 'json_data' ], true);
-
- $form_data_list = model('form_data')->getList([ [ 'fd.form_id', '=', $form_info[ 'id' ] ] ], 'fd.form_data,fd.create_time,m.nickname', 'id desc', 'fd', [ [ 'member m', 'm.member_id = fd.member_id', 'left' ] ]);
- if (empty($form_data_list)) return $this->error('', '表单没有可导出的数据');
-
- $phpExcel = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
- $phpExcel->getProperties()->setTitle('表单数据');
- $phpExcel->getProperties()->setSubject('表单数据');
- $sheet = $phpExcel->getActiveSheet();
-
- // 创建表头
- foreach ($form_info[ 'json_data' ] as $k => $form_item) {
- $sheet->getCellByColumnAndRow(( $k + 1 ), 1)->setValue($form_item[ 'value' ][ 'title' ]);
- }
- $sheet->getCellByColumnAndRow(( count($form_info[ 'json_data' ]) + 1 ), 1)->setValue('会员');
- $sheet->getCellByColumnAndRow(( count($form_info[ 'json_data' ]) + 2 ), 1)->setValue('填写时间');
-
- // 填充数据
- foreach ($form_data_list as $data_k => $data_item) {
- foreach ($form_info[ 'json_data' ] as $k => $form_item) {
- $form_data = array_column(json_decode($data_item[ 'form_data' ], true), null, 'id');
- if (!empty($form_data[ $form_item[ 'id' ] ])) {
- $sheet->getCellByColumnAndRow(( $k + 1 ), ( $data_k + 2 ))->setValue($form_data[ $form_item[ 'id' ] ][ 'val' ] ?? '');
- }
- }
- $sheet->getCellByColumnAndRow(( count($form_info[ 'json_data' ]) + 1 ), ( $data_k + 2 ))->setValue($data_item[ 'nickname' ] ?: '');
- $sheet->getCellByColumnAndRow(( count($form_info[ 'json_data' ]) + 2 ), ( $data_k + 2 ))->setValue(time_to_date($data_item[ 'create_time' ]));
- }
-
- $objWriter = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($phpExcel, 'Xlsx');
- $file = date('Y年m月d日-' . $form_info[ 'form_name' ] . '数据导出', time()) . '.xlsx';
- $objWriter->save($file);
-
- header('Content-type:application/octet-stream');
-
- $filename = basename($file);
- header('Content-Disposition:attachment;filename = ' . $filename);
- header('Accept-ranges:bytes');
- header('Accept-length:' . filesize($file));
- readfile($file);
- unlink($file);
- exit;
- }
-
- /**
- * 添加表单数据
- * @param $param
- */
- public function addFormData($param)
- {
- $info = model('form')->getInfo([ [ 'id', '=', $param[ 'form_id' ] ], [ 'site_id', '=', $param[ 'site_id' ] ] ]);
- if (empty($info)) return $this->error('', '该表单不存在');
- if (!$info[ 'is_use' ]) return $this->error('', '该表单未启用');
- $id = model('form_data')->add([
- 'site_id' => $param[ 'site_id' ],
- 'form_id' => $param[ 'form_id' ],
- 'member_id' => 0,
- 'relation_id' => $param[ 'relation_id' ],
- 'create_time' => time(),
- 'form_data' => json_encode($param[ 'form_data' ]),
- 'scene' => $param[ 'scene' ]
- ]);
- return $this->success($id);
- }
-
- public function urlQrcode($page, $qrcode_param, $app_type, $site_id)
- {
- $params = [
- 'site_id' => $site_id,
- 'data' => $qrcode_param,
- 'page' => $page,
- 'promotion_type' => '',
- 'app_type' => $app_type,
- 'h5_path' => $page . '?id=' . $qrcode_param[ 'id' ],
- 'qrcode_path' => 'upload/qrcode/form',
- 'qrcode_name' => 'form_qrcode_' . $qrcode_param[ 'id' ] . '_' . $site_id
- ];
-
- $solitaire = event('PromotionQrcode', $params, true);
- return $this->success($solitaire);
- }
+ [
+ 'type' => 'order',
+ 'name' => '统一下单',
+ 'preview_img' => 'addon/form/shop/view/public/img/preview/order.png',
+ 'head_img' => 'addon/form/shop/view/public/img/head/order.png'
+ ],
+ 'goods' => [
+ 'type' => 'goods',
+ 'name' => '商品表单',
+ 'preview_img' => 'addon/form/shop/view/public/img/preview/goods.png',
+ 'head_img' => 'addon/form/shop/view/public/img/head/goods.png'
+ ],
+ 'custom' => [
+ 'type' => 'custom',
+ 'name' => '自定义表单',
+ 'preview_img' => 'addon/form/shop/view/public/img/preview/custom.png',
+ 'head_img' => 'addon/form/shop/view/public/img/head/custom.png'
+ ]
+ ];
+
+ /**
+ * 表单组件
+ */
+ const FORM_COMPONENT = [
+ 'ONE_LINE_TEXT' => [
+ 'name' => 'ONE_LINE_TEXT',
+ 'title' => '单行文本',
+ 'type' => 'SYSTEM',
+ 'controller' => 'Text',
+ 'value' => [
+ 'title' => '单行文本框',
+ 'placeholder' => '请输入提示语',
+ 'default' => '',
+ 'required' => true
+ ],
+ 'sort' => '10000',
+ 'support_diy_view' => '',
+ 'max_count' => 0,
+ 'is_delete' => 0,
+ 'icon' => 'addon/form/shop/view/public/img/icon/on_line_text.png',
+ 'icon_selected' => 'addon/form/shop/view/public/img/icon/on_line_text_selected.png'
+ ],
+ 'MANY_LINE_TEXT' => [
+ 'name' => 'MANY_LINE_TEXT',
+ 'title' => '多行文本',
+ 'type' => 'SYSTEM',
+ 'controller' => 'Textarea',
+ 'value' => [
+ 'title' => '多行文本',
+ 'placeholder' => '请输入提示语',
+ 'default' => '',
+ 'required' => true
+ ],
+ 'sort' => '10000',
+ 'support_diy_view' => '',
+ 'max_count' => 0,
+ 'is_delete' => 0,
+ 'icon' => 'addon/form/shop/view/public/img/icon/many_line_text.png',
+ 'icon_selected' => 'addon/form/shop/view/public/img/icon/many_line_text_selected.png'
+ ],
+ 'ID_CARD' => [
+ 'name' => 'ID_CARD',
+ 'title' => '身份证号码',
+ 'type' => 'SYSTEM',
+ 'controller' => 'Text',
+ 'value' => [
+ 'title' => '身份证号码',
+ 'placeholder' => '请输入身份证号码',
+ 'required' => true
+ ],
+ 'sort' => '10000',
+ 'support_diy_view' => '',
+ 'max_count' => 0,
+ 'is_delete' => 0,
+ 'icon' => 'addon/form/shop/view/public/img/icon/id_card.png',
+ 'icon_selected' => 'addon/form/shop/view/public/img/icon/id_card_selected.png'
+ ],
+ 'SELECT' => [
+ 'name' => 'SELECT',
+ 'title' => '下拉框',
+ 'type' => 'SYSTEM',
+ 'controller' => 'Select',
+ 'value' => [
+ 'title' => '下拉框',
+ 'options' => [
+ '选项一',
+ '选项二'
+ ],
+ 'required' => true
+ ],
+ 'sort' => '10000',
+ 'support_diy_view' => '',
+ 'max_count' => 0,
+ 'is_delete' => 0,
+ 'icon' => 'addon/form/shop/view/public/img/icon/select.png',
+ 'icon_selected' => 'addon/form/shop/view/public/img/icon/select_selected.png'
+ ],
+ 'CHECKBOX' => [
+ 'name' => 'CHECKBOX',
+ 'title' => '多选框',
+ 'type' => 'SYSTEM',
+ 'controller' => 'Checkbox',
+ 'value' => [
+ 'title' => '多选框',
+ 'options' => [
+ '选项一',
+ '选项二'
+ ],
+ 'required' => true
+ ],
+ 'sort' => '10000',
+ 'support_diy_view' => '',
+ 'max_count' => 0,
+ 'is_delete' => 0,
+ 'icon' => 'addon/form/shop/view/public/img/icon/checkbox.png',
+ 'icon_selected' => 'addon/form/shop/view/public/img/icon/checkbox_selected.png'
+ ],
+ 'RADIO' => [
+ 'name' => 'RADIO',
+ 'title' => '单选框',
+ 'type' => 'SYSTEM',
+ 'controller' => 'Radio',
+ 'value' => [
+ 'title' => '单选框',
+ 'options' => [
+ '选项一',
+ '选项二'
+ ],
+ 'required' => true
+ ],
+ 'sort' => '10000',
+ 'support_diy_view' => '',
+ 'max_count' => 0,
+ 'is_delete' => 0,
+ 'icon' => 'addon/form/shop/view/public/img/icon/radio.png',
+ 'icon_selected' => 'addon/form/shop/view/public/img/icon/radio_selected.png'
+ ],
+ 'IMG' => [
+ 'name' => 'IMG',
+ 'title' => '图片',
+ 'type' => 'SYSTEM',
+ 'controller' => 'Img',
+ 'value' => [
+ 'title' => '图片',
+ 'max_count' => 3,
+ 'required' => true
+ ],
+ 'sort' => '10000',
+ 'support_diy_view' => '',
+ 'max_count' => 0,
+ 'is_delete' => 0,
+ 'icon' => 'addon/form/shop/view/public/img/icon/img.png',
+ 'icon_selected' => 'addon/form/shop/view/public/img/icon/img_selected.png'
+ ],
+ 'DATE' => [
+ 'name' => 'DATE',
+ 'title' => '日期',
+ 'type' => 'SYSTEM',
+ 'controller' => 'Date',
+ 'value' => [
+ 'title' => '日期',
+ 'placeholder' => '请输入提示语',
+ 'is_show_default' => true,
+ 'is_current' => true,
+ 'default' => '',
+ 'required' => true
+ ],
+ 'sort' => '10000',
+ 'support_diy_view' => '',
+ 'max_count' => 0,
+ 'is_delete' => 0,
+ 'icon' => 'addon/form/shop/view/public/img/icon/date.png',
+ 'icon_selected' => 'addon/form/shop/view/public/img/icon/date_selected.png'
+ ],
+ 'DATE_LIMIT' => [
+ 'name' => 'DATE_LIMIT',
+ 'title' => '日期范围',
+ 'type' => 'SYSTEM',
+ 'controller' => 'Datelimit',
+ 'value' => [
+ 'title' => '日期范围',
+ 'placeholder_start' => '请输入起始日期提示语',
+ 'placeholder_end' => '请输入结束日期提示语',
+ 'is_show_default_start' => true,
+ 'is_show_default_end' => true,
+ 'is_current_start' => true,
+ 'is_current_end' => true,
+ 'default_start' => '',
+ 'default_end' => '',
+ 'required' => true
+ ],
+ 'sort' => '10000',
+ 'support_diy_view' => '',
+ 'max_count' => 0,
+ 'is_delete' => 0,
+ 'icon' => 'addon/form/shop/view/public/img/icon/date_limit.png',
+ 'icon_selected' => 'addon/form/shop/view/public/img/icon/date_limit_selected.png'
+ ],
+ 'TIME' => [
+ 'name' => 'TIME',
+ 'title' => '时间',
+ 'type' => 'SYSTEM',
+ 'controller' => 'Time',
+ 'value' => [
+ 'title' => '时间',
+ 'placeholder' => '请输入提示语',
+ 'is_show_default' => true,
+ 'is_current' => true,
+ 'default' => '',
+ 'required' => true
+ ],
+ 'sort' => '10000',
+ 'support_diy_view' => '',
+ 'max_count' => 0,
+ 'is_delete' => 0,
+ 'icon' => 'addon/form/shop/view/public/img/icon/time.png',
+ 'icon_selected' => 'addon/form/shop/view/public/img/icon/time_selected.png'
+ ],
+ 'TIME_LIMIT' => [
+ 'name' => 'TIME_LIMIT',
+ 'title' => '时间范围',
+ 'type' => 'SYSTEM',
+ 'controller' => 'Timelimit',
+ 'value' => [
+ 'title' => '时间范围',
+ 'placeholder_start' => '请输入起始时间提示语',
+ 'placeholder_end' => '请输入结束时间提示语',
+ 'is_show_default_start' => true,
+ 'is_show_default_end' => true,
+ 'is_current_start' => true,
+ 'is_current_end' => true,
+ 'default_start' => '',
+ 'default_end' => '',
+ 'required' => true
+ ],
+ 'sort' => '10000',
+ 'support_diy_view' => '',
+ 'max_count' => 0,
+ 'is_delete' => 0,
+ 'icon' => 'addon/form/shop/view/public/img/icon/time_limit.png',
+ 'icon_selected' => 'addon/form/shop/view/public/img/icon/time_limit_selected.png'
+ ],
+ 'CITY' => [
+ 'name' => 'CITY',
+ 'title' => '城市',
+ 'type' => 'SYSTEM',
+ 'controller' => 'City',
+ 'value' => [
+ 'title' => '城市',
+ 'placeholder' => '请输入提示语',
+ 'default_type' => 1,
+ 'required' => true
+ ],
+ 'sort' => '10000',
+ 'support_diy_view' => '',
+ 'max_count' => 0,
+ 'is_delete' => 0,
+ 'icon' => 'addon/form/shop/view/public/img/icon/city.png',
+ 'icon_selected' => 'addon/form/shop/view/public/img/icon/city_selected.png'
+ ],
+ 'MOBILE' => [
+ 'name' => 'MOBILE',
+ 'title' => '手机号码',
+ 'type' => 'SYSTEM',
+ 'controller' => 'Text',
+ 'value' => [
+ 'title' => '手机号码',
+ 'placeholder' => '请输入手机号码',
+ 'required' => true
+ ],
+ 'sort' => '10000',
+ 'support_diy_view' => '',
+ 'max_count' => 0,
+ 'is_delete' => 0,
+ 'icon' => 'addon/form/shop/view/public/img/icon/mobile.png',
+ 'icon_selected' => 'addon/form/shop/view/public/img/icon/mobile_selected.png'
+ ],
+ ];
+
+ /**
+ * 添加自定义模板
+ * @param $data
+ * @return array
+ */
+ public function addForm($data)
+ {
+ $res = model('form')->add($data);
+ if ($res) {
+ Cache::tag('form')->clear();
+ return $this->success($res);
+ } else {
+ return $this->error($res);
+ }
+ }
+
+
+ /**
+ * 修改自定义模板
+ * @param array $data
+ * @param array $condition
+ * @return array
+ */
+ public function editForm($data, $condition)
+ {
+ $res = model('form')->update($data, $condition);
+ if ($res) {
+ Cache::tag('form')->clear();
+ return $this->success($res);
+ } else {
+ return $this->error($res);
+ }
+ }
+
+ /**
+ * 获取自定义模板信息
+ * @param array $condition
+ * @param string $field
+ * @return array
+ */
+ public function getFormInfo($condition = [], $field = '*', $alias = 'a', $join = [])
+ {
+
+ $info = model('form')->getInfo($condition, $field, $alias, $join);
+ return $this->success($info);
+ }
+
+ /**
+ * 删除表单
+ * @param array $condition
+ * @return array
+ */
+ public function deleteForm($id, $site_id)
+ {
+ model('form')->startTrans();
+
+ $res = model('form')->delete([ [ 'id', '=', $id ], [ 'site_id', '=', $site_id ] ]);
+ if ($res) {
+ model('form_data')->delete([ [ 'form_id', '=', $id ], [ 'site_id', '=', $site_id ] ]);
+ model('form')->commit();
+ Cache::tag('form')->clear();
+ return $this->success($res);
+ } else {
+ model('form')->rollback();
+ return $this->error($res);
+ }
+ }
+
+ /**
+ * 获取表单分页列表
+ * @param array $condition
+ * @param int $page
+ * @param int $page_size
+ * @param string $order
+ * @param string $field
+ * @return array
+ */
+ public function getFormPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'id desc', $field = '*')
+ {
+ $list = model('form')->pageList($condition, $field, $order, $page, $page_size);
+ return $this->success($list);
+ }
+
+ /**
+ * 获取表单列表
+ * @param array $condition
+ * @param string $order
+ * @param string $field
+ * @return array
+ */
+ public function getFormList($condition = [], $order = 'id desc', $field = '*')
+ {
+ $data = json_encode([ $condition, $field, $order]);
+ $cache = Cache::get('form_getFormList_' . $data);
+ if (!empty($cache)) {
+ return $this->success($cache);
+ }
+ $list = model('form')->getList($condition, $field, $order);
+ Cache::tag('form')->set('form_getFormList_' . $data, $list);
+ return $this->success($list);
+ }
+
+ /**
+ * 查询订单数据并导出
+ * @param $condition
+ */
+ public function export($param)
+ {
+ $form_info = model('form')->getInfo([ [ 'id', '=', $param[ 'id' ] ], [ 'site_id', '=', $param[ 'site_id' ] ] ], 'form_name,id,json_data');
+ if (empty($form_info)) return $this->error('', '未获取到表单信息');
+ $form_info[ 'json_data' ] = json_decode($form_info[ 'json_data' ], true);
+
+ $form_data_list = model('form_data')->getList([ [ 'fd.form_id', '=', $form_info[ 'id' ] ] ], 'fd.form_data,fd.create_time,m.nickname', 'id desc', 'fd', [ [ 'member m', 'm.member_id = fd.member_id', 'left' ] ]);
+ if (empty($form_data_list)) return $this->error('', '表单没有可导出的数据');
+
+ $phpExcel = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
+ $phpExcel->getProperties()->setTitle('表单数据');
+ $phpExcel->getProperties()->setSubject('表单数据');
+ $sheet = $phpExcel->getActiveSheet();
+
+ // 创建表头
+ foreach ($form_info[ 'json_data' ] as $k => $form_item) {
+ $sheet->getCellByColumnAndRow(( $k + 1 ), 1)->setValue($form_item[ 'value' ][ 'title' ]);
+ }
+ $sheet->getCellByColumnAndRow(( count($form_info[ 'json_data' ]) + 1 ), 1)->setValue('会员');
+ $sheet->getCellByColumnAndRow(( count($form_info[ 'json_data' ]) + 2 ), 1)->setValue('填写时间');
+
+ // 填充数据
+ foreach ($form_data_list as $data_k => $data_item) {
+ foreach ($form_info[ 'json_data' ] as $k => $form_item) {
+ $form_data = array_column(json_decode($data_item[ 'form_data' ], true), null, 'id');
+ if (!empty($form_data[ $form_item[ 'id' ] ])) {
+ $sheet->getCellByColumnAndRow(( $k + 1 ), ( $data_k + 2 ))->setValue($form_data[ $form_item[ 'id' ] ][ 'val' ] ?? '');
+ }
+ }
+ $sheet->getCellByColumnAndRow(( count($form_info[ 'json_data' ]) + 1 ), ( $data_k + 2 ))->setValue($data_item[ 'nickname' ] ?: '');
+ $sheet->getCellByColumnAndRow(( count($form_info[ 'json_data' ]) + 2 ), ( $data_k + 2 ))->setValue(time_to_date($data_item[ 'create_time' ]));
+ }
+
+ $objWriter = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($phpExcel, 'Xlsx');
+ $file = date('Y年m月d日-' . $form_info[ 'form_name' ] . '数据导出', time()) . '.xlsx';
+ $objWriter->save($file);
+
+ header('Content-type:application/octet-stream');
+
+ $filename = basename($file);
+ header('Content-Disposition:attachment;filename = ' . $filename);
+ header('Accept-ranges:bytes');
+ header('Accept-length:' . filesize($file));
+ readfile($file);
+ unlink($file);
+ exit;
+ }
+
+ /**
+ * 添加表单数据
+ * @param $param
+ */
+ public function addFormData($param)
+ {
+ $info = model('form')->getInfo([ [ 'id', '=', $param[ 'form_id' ] ], [ 'site_id', '=', $param[ 'site_id' ] ] ]);
+ if (empty($info)) return $this->error('', '该表单不存在');
+ if (!$info[ 'is_use' ]) return $this->error('', '该表单未启用');
+ $id = model('form_data')->add([
+ 'site_id' => $param[ 'site_id' ],
+ 'form_id' => $param[ 'form_id' ],
+ 'member_id' => 0,
+ 'relation_id' => $param[ 'relation_id' ],
+ 'create_time' => time(),
+ 'form_data' => json_encode($param[ 'form_data' ]),
+ 'scene' => $param[ 'scene' ]
+ ]);
+ return $this->success($id);
+ }
+
+ public function urlQrcode($page, $qrcode_param, $app_type, $site_id)
+ {
+ $params = [
+ 'site_id' => $site_id,
+ 'data' => $qrcode_param,
+ 'page' => $page,
+ 'promotion_type' => '',
+ 'app_type' => $app_type,
+ 'h5_path' => $page . '?id=' . $qrcode_param[ 'id' ],
+ 'qrcode_path' => 'upload/qrcode/form',
+ 'qrcode_name' => 'form_qrcode_' . $qrcode_param[ 'id' ] . '_' . $site_id
+ ];
+
+ $solitaire = event('PromotionQrcode', $params, true);
+ return $this->success($solitaire);
+ }
}
\ No newline at end of file
diff --git a/src/addon/form/model/FormData.php b/src/addon/form/model/FormData.php
index 033d6448d..2f61c7f22 100644
--- a/src/addon/form/model/FormData.php
+++ b/src/addon/form/model/FormData.php
@@ -1,67 +1,59 @@
-pageList($condition, $field, $order, $page, $limit, $alias, $join);
- return $this->success($list);
- }
-
- /**
- * 查询表单数据
- * @param array $where
- * @param bool $field
- * @param string $alias
- * @param null $join
- * @return array
- */
- public function getFormDataInfo($where = [], $field = true, $alias = 'a', $join = null)
- {
- $info = model('form_data')->getInfo($where, $field, $alias, $join);
- return $this->success($info);
- }
-
- /**
- * 删除表单数据
- * @param array $condition
- * @return array
- */
- public function deleteFormData($condition = [])
- {
- $res = model('form_data')->delete($condition);
- if ($res) {
- return $this->success($res);
- } else {
- return $this->error($res);
- }
- }
+pageList($condition, $field, $order, $page, $limit, $alias, $join);
+ return $this->success($list);
+ }
+
+ /**
+ * 查询表单数据
+ * @param array $where
+ * @param bool $field
+ * @param string $alias
+ * @param null $join
+ * @return array
+ */
+ public function getFormDataInfo($where = [], $field = true, $alias = 'a', $join = null)
+ {
+ $info = model('form_data')->getInfo($where, $field, $alias, $join);
+ return $this->success($info);
+ }
+
+ /**
+ * 删除表单数据
+ * @param array $condition
+ * @return array
+ */
+ public function deleteFormData($condition = [])
+ {
+ $res = model('form_data')->delete($condition);
+ if ($res) {
+ return $this->success($res);
+ } else {
+ return $this->error($res);
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/form/shop/controller/Form.php b/src/addon/form/shop/controller/Form.php
index 329162e4e..0c8689e62 100644
--- a/src/addon/form/shop/controller/Form.php
+++ b/src/addon/form/shop/controller/Form.php
@@ -1,332 +1,324 @@
-replace = [
- 'FORM_JS' => __ROOT__ . '/addon/form/shop/view/public/js',
- 'FORM_CSS' => __ROOT__ . '/addon/form/shop/view/public/css',
- 'FORM_IMG' => __ROOT__ . '/addon/form/shop/view/public/img'
- ];
- parent::__construct($app);
- }
-
- /**
- * 编辑添加系统表单
- * @param $game_data
- * @param $award_json
- * @return array
- */
- public function editForm()
- {
- $from_model = new FormModel();
- if (request()->isJson()) {
- $id = input('id', '');
- $form_name = input('form_name', '');
- $json_data = input('json_data', '');
- $data = [
- 'form_name' => $form_name,
- 'json_data' => $json_data,
- 'modify_time' => time()
- ];
- $res = $from_model->editForm($data, [ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ]);
- return $res;
- }
- $id = input('id', '');
- $info = $from_model->getFormInfo([ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ]);
- if (empty($info[ 'data' ])) $this->error('未获取到表单数据');
-
- $this->assign('component', FormModel::FORM_COMPONENT);
- $this->assign('info', $info[ 'data' ]);
- $this->assign('form_type', ( new FormModel() )->form_type[ $info[ 'data' ][ 'form_type' ] ]);
-
- return $this->fetch('form/edit');
- }
-
- /**
- * 添加表单
- * @return array|mixed
- */
- public function addForm()
- {
- if (request()->isJson()) {
- $form_name = input('form_name', '');
- $json_data = input('json_data', '');
- $form_type = input('form_type', 'order');
- $data = [
- 'form_name' => $form_name,
- 'json_data' => $json_data,
- 'form_type' => $form_type,
- 'site_id' => $this->site_id,
- 'create_time' => time(),
- 'is_use' => $form_type != 'order' ? 1 : 0
- ];
- $from_model = new FormModel();
- $res = $from_model->addForm($data);
- return $res;
- }
- $form_type = input('form_type', 'order');
- $this->assign('component', FormModel::FORM_COMPONENT);
- $this->assign('form_type', ( new FormModel() )->form_type[ $form_type ]);
- return $this->fetch('form/edit');
- }
-
- /**
- * 是否开启
- * @param $game_data
- * @param $award_json
- * @return array
- */
- public function editIsUse()
- {
- $from_model = new FormModel();
- $is_use = input('is_use', '');
- $id = input('id', '');
- $form_type = input('form_type', '');
- if (empty($is_use) && empty($id)) {
- $this->error('id和is_use不可为空');
- }
- //启用之前先把该类型的全都不启用
- if ($form_type == 'order') {
- $from_model->editForm([ 'is_use' => 0 ], [ [ 'form_type', '=', 'order' ], [ 'site_id', '=', $this->site_id ] ]);
- }
-
- $data = [
- 'is_use' => $is_use
- ];
-
- $res = $from_model->editForm($data, [ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ]);
- return $res;
- }
-
- /**
- * 删除数据
- * @param $game_data
- * @param $award_json
- * @return array
- */
- public function deleteForm()
- {
- $id = input('id', '');
- if (empty($id)) {
- $this->error('id不可为空');
- }
- $from_model = new FormModel();
- $res = $from_model->deleteForm($id, $this->site_id);
- return $res;
- }
-
- /**
- * 表单列表
- * @param $game_data
- * @param $award_json
- * @return array
- */
- public function lists()
- {
- if (request()->isJson()) {
- $form_type = input('form_type', '');
- $form_name = input('form_name', '');
- $page = input('page', 1);
- $page_size = input('page_size', PAGE_LIST_ROWS);
- $is_use = input('is_use', '');
- $condition = [];
- $condition[] = [ 'site_id', '=', $this->site_id ];
- if (!empty($form_type)) {
- $condition[] = [ 'form_type', '=', $form_type ];
- }
- if (!empty($form_name)) {
- $condition[] = [ 'form_name', 'like', '%' . $form_name . '%' ];
- }
- if (!empty($is_use)) {
- $condition[] = [ 'is_use', '=', $is_use ];
- }
- $from_model = new FormModel();
- $res = $from_model->getFormPageList($condition, $page, $page_size);
-
- return $res;
- }
- $this->assign('form_type', ( new FormModel() )->form_type);
- return $this->fetch('form/lists');
- }
-
-
- /**
- * 导出表单列表
- * @param $game_data
- * @param $award_json
- * @return array
- */
- public function exportForm()
- {
- $id = input('id', '');
- if (empty($id)) {
- $this->error('id不可为空');
- }
- $from_model = new FormModel();
- $res = $from_model->export([ 'id' => $id, 'site_id' => $this->site_id ]);
- if (isset($res[ 'code' ]) && $res[ 'code' ] != 0) $this->error($res[ 'message' ]);
- }
-
-
- /**
- * 获取详情
- * @param $game_data
- * @param $award_json
- * @return array
- */
- public function formInfo()
- {
- $id = input('id', '');
- $condition[] = [ 'site_id', '=', $this->site_id ];
- if (empty($id)) {
- $this->error('id不可为空');
- }
- $condition[] = [ 'id', '=', $id ];
- $from_model = new FormModel();
- $res = $from_model->getFormInfo($condition);
- return $res;
- }
-
- /**
- * 查看表单数据
- * @param $game_data
- * @param $award_json
- * @return array
- */
- public function formData()
- {
- $form_id = input('form_id', '');
- if (request()->isJson()) {
- if (empty($form_id)) {
- return error(-1, 'id不可为空');
- }
- $page = input('page', 1);
- $page_size = input('page_size', PAGE_LIST_ROWS);
- $nickname = input('nickname', '');
- $start_time = input('start_time', '');
- $end_time = input('end_time', '');
-
- $condition[] = [ 'fd.form_id', '=', $form_id ];
- $condition[] = [ 'fd.site_id', '=', $this->site_id ];
-
- if ($start_time && !$end_time) {
- $condition[] = [ 'fd.create_time', '>=', date_to_time($start_time) ];
- } elseif (!$start_time && $end_time) {
- $condition[] = [ 'fd.create_time', '<=', date_to_time($end_time) ];
- } elseif ($start_time && $end_time) {
- $condition[] = [ 'fd.create_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
- }
- if (!empty($nickname)) $condition[] = [ 'm.nickname', 'like', "%{$nickname}%" ];
-
- $alias = 'fd';
- $join = [
- /* [
- 'member m',
- 'fd.member_id = m.member_id',
- 'inner'
- ],*/
-
- ];
- //,m.headimg,m.nickname,m.status,m.member_level_type
- $field = 'fd.*';
-
- $from_model = new FormDataModel();
- $res = $from_model->getFormDataPageList($condition, $field, 'fd.id desc', $page, $page_size, $alias, $join);
- if (!empty($res[ 'data' ][ 'list' ])) {
- $order_model = new OrderModel();
- foreach ($res[ 'data' ][ 'list' ] as $k => &$item_v) {
- $item_v[ 'form_data' ] = json_decode($item_v[ 'form_data' ], true);
- if ($item_v[ 'scene' ] == 'order') {
- $item_v[ 'order_info' ] = $order_model->getOrderInfo([ [ 'order_id', '=', $item_v[ 'relation_id' ] ] ], 'order_id,order_no')[ 'data' ];
- } elseif ($item_v[ 'scene' ] == 'goods') {
- $item_v[ 'order_goods_info' ] = $order_model->getOrderGoodsInfo([ [ 'order_goods_id', '=', $item_v[ 'relation_id' ] ] ], 'order_goods_id,order_id,order_no')[ 'data' ];
- }
- if($item_v['member_id'] > 0){
- $member = model('member')->getInfo(['member_id'=>$item_v['member_id']]);
- $res[ 'data' ][ 'list' ][$k]['headimg'] = $member['headimg'];
- $res[ 'data' ][ 'list' ][$k]['nickname'] = $member['nickname'];
- $res[ 'data' ][ 'list' ][$k]['status'] = $member['status'];
- $res[ 'data' ][ 'list' ][$k]['member_level_type'] = $member['member_level_type'];
- }
- }
- }
- return $res;
- } else {
- $this->assign('form_id', $form_id);
- $item = model('form')->getInfo(['id'=>$form_id]);
- $this->assign('item', $item);
- return $this->fetch('form/formdata');
- }
- }
-
- /**
- * 查询表单列表
- * @return array
- */
- public function getFormList()
- {
- if (request()->isJson()) {
- $form_type = input('form_type', 'goods');
- $is_use = input('is_use', 1);
-
- $condition = [
- [ 'site_id', '=', $this->site_id ],
- [ 'form_type', '=', $form_type ],
- [ 'is_use', '=', $is_use ]
- ];
- return ( new FormModel() )->getFormList($condition, 'id desc', 'id,form_name');
- }
- }
-
- /**
- * 推广
- * @return array
- */
- public function promote()
- {
- if (request()->isJson()) {
- $form_id = input('form_id', '');
- $app_type = input('app_type', 'all');
- $from_model = new FormModel();
- $res = $from_model->urlQrcode('/pages_tool/form/formdata', [ 'id' => $form_id,'uniacid'=>$this->site_id ], $app_type, $this->site_id);
- return $res;
- }
- }
-
- /**
- * 删除表单数据
- * @return array|string|string[]
- */
- public function deleteFormData()
- {
- if (request()->isJson()) {
- $id = input('id', '');
- if (empty($id)) return error(-1, 'id不可为空');
-
- $from_model = new FormDataModel();
- $res = $from_model->deleteFormData([ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ]);
- return $res;
- }
- }
+replace = [
+ 'FORM_JS' => __ROOT__ . '/addon/form/shop/view/public/js',
+ 'FORM_CSS' => __ROOT__ . '/addon/form/shop/view/public/css',
+ 'FORM_IMG' => __ROOT__ . '/addon/form/shop/view/public/img'
+ ];
+ parent::__construct($app);
+ }
+
+ /**
+ * 编辑添加系统表单
+ * @param $game_data
+ * @param $award_json
+ * @return array
+ */
+ public function editForm()
+ {
+ $from_model = new FormModel();
+ if (request()->isJson()) {
+ $id = input('id', '');
+ $form_name = input('form_name', '');
+ $json_data = input('json_data', '');
+ $data = [
+ 'form_name' => $form_name,
+ 'json_data' => $json_data,
+ 'modify_time' => time()
+ ];
+ $res = $from_model->editForm($data, [ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ]);
+ return $res;
+ }
+ $id = input('id', '');
+ $info = $from_model->getFormInfo([ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ]);
+ if (empty($info[ 'data' ])) $this->error('未获取到表单数据');
+
+ $this->assign('component', FormModel::FORM_COMPONENT);
+ $this->assign('info', $info[ 'data' ]);
+ $this->assign('form_type', ( new FormModel() )->form_type[ $info[ 'data' ][ 'form_type' ] ]);
+
+ return $this->fetch('form/edit');
+ }
+
+ /**
+ * 添加表单
+ * @return array|mixed
+ */
+ public function addForm()
+ {
+ if (request()->isJson()) {
+ $form_name = input('form_name', '');
+ $json_data = input('json_data', '');
+ $form_type = input('form_type', 'order');
+ $data = [
+ 'form_name' => $form_name,
+ 'json_data' => $json_data,
+ 'form_type' => $form_type,
+ 'site_id' => $this->site_id,
+ 'create_time' => time(),
+ 'is_use' => $form_type != 'order' ? 1 : 0
+ ];
+ $from_model = new FormModel();
+ $res = $from_model->addForm($data);
+ return $res;
+ }
+ $form_type = input('form_type', 'order');
+ $this->assign('component', FormModel::FORM_COMPONENT);
+ $this->assign('form_type', ( new FormModel() )->form_type[ $form_type ]);
+ return $this->fetch('form/edit');
+ }
+
+ /**
+ * 是否开启
+ * @param $game_data
+ * @param $award_json
+ * @return array
+ */
+ public function editIsUse()
+ {
+ $from_model = new FormModel();
+ $is_use = input('is_use', '');
+ $id = input('id', '');
+ $form_type = input('form_type', '');
+ if (empty($is_use) && empty($id)) {
+ $this->error('id和is_use不可为空');
+ }
+ //启用之前先把该类型的全都不启用
+ if ($form_type == 'order') {
+ $from_model->editForm([ 'is_use' => 0 ], [ [ 'form_type', '=', 'order' ], [ 'site_id', '=', $this->site_id ] ]);
+ }
+
+ $data = [
+ 'is_use' => $is_use
+ ];
+
+ $res = $from_model->editForm($data, [ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ]);
+ return $res;
+ }
+
+ /**
+ * 删除数据
+ * @param $game_data
+ * @param $award_json
+ * @return array
+ */
+ public function deleteForm()
+ {
+ $id = input('id', '');
+ if (empty($id)) {
+ $this->error('id不可为空');
+ }
+ $from_model = new FormModel();
+ $res = $from_model->deleteForm($id, $this->site_id);
+ return $res;
+ }
+
+ /**
+ * 表单列表
+ * @param $game_data
+ * @param $award_json
+ * @return array
+ */
+ public function lists()
+ {
+ if (request()->isJson()) {
+ $form_type = input('form_type', '');
+ $form_name = input('form_name', '');
+ $page = input('page', 1);
+ $page_size = input('page_size', PAGE_LIST_ROWS);
+ $is_use = input('is_use', '');
+ $condition = [];
+ $condition[] = [ 'site_id', '=', $this->site_id ];
+ if (!empty($form_type)) {
+ $condition[] = [ 'form_type', '=', $form_type ];
+ }
+ if (!empty($form_name)) {
+ $condition[] = [ 'form_name', 'like', '%' . $form_name . '%' ];
+ }
+ if (!empty($is_use)) {
+ $condition[] = [ 'is_use', '=', $is_use ];
+ }
+ $from_model = new FormModel();
+ $res = $from_model->getFormPageList($condition, $page, $page_size);
+
+ return $res;
+ }
+ $this->assign('form_type', ( new FormModel() )->form_type);
+ return $this->fetch('form/lists');
+ }
+
+
+ /**
+ * 导出表单列表
+ * @param $game_data
+ * @param $award_json
+ * @return array
+ */
+ public function exportForm()
+ {
+ $id = input('id', '');
+ if (empty($id)) {
+ $this->error('id不可为空');
+ }
+ $from_model = new FormModel();
+ $res = $from_model->export([ 'id' => $id, 'site_id' => $this->site_id ]);
+ if (isset($res[ 'code' ]) && $res[ 'code' ] != 0) $this->error($res[ 'message' ]);
+ }
+
+
+ /**
+ * 获取详情
+ * @param $game_data
+ * @param $award_json
+ * @return array
+ */
+ public function formInfo()
+ {
+ $id = input('id', '');
+ $condition[] = [ 'site_id', '=', $this->site_id ];
+ if (empty($id)) {
+ $this->error('id不可为空');
+ }
+ $condition[] = [ 'id', '=', $id ];
+ $from_model = new FormModel();
+ $res = $from_model->getFormInfo($condition);
+ return $res;
+ }
+
+ /**
+ * 查看表单数据
+ * @param $game_data
+ * @param $award_json
+ * @return array
+ */
+ public function formData()
+ {
+ $form_id = input('form_id', '');
+ if (request()->isJson()) {
+ if (empty($form_id)) {
+ return error(-1, 'id不可为空');
+ }
+ $page = input('page', 1);
+ $page_size = input('page_size', PAGE_LIST_ROWS);
+ $nickname = input('nickname', '');
+ $start_time = input('start_time', '');
+ $end_time = input('end_time', '');
+
+ $condition[] = [ 'fd.form_id', '=', $form_id ];
+ $condition[] = [ 'fd.site_id', '=', $this->site_id ];
+
+ if ($start_time && !$end_time) {
+ $condition[] = [ 'fd.create_time', '>=', date_to_time($start_time) ];
+ } elseif (!$start_time && $end_time) {
+ $condition[] = [ 'fd.create_time', '<=', date_to_time($end_time) ];
+ } elseif ($start_time && $end_time) {
+ $condition[] = [ 'fd.create_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
+ }
+ if (!empty($nickname)) $condition[] = [ 'm.nickname', 'like', "%{$nickname}%" ];
+
+ $alias = 'fd';
+ $join = [
+ /* [
+ 'member m',
+ 'fd.member_id = m.member_id',
+ 'inner'
+ ],*/
+
+ ];
+ //,m.headimg,m.nickname,m.status,m.member_level_type
+ $field = 'fd.*';
+
+ $from_model = new FormDataModel();
+ $res = $from_model->getFormDataPageList($condition, $field, 'fd.id desc', $page, $page_size, $alias, $join);
+ if (!empty($res[ 'data' ][ 'list' ])) {
+ $order_model = new OrderModel();
+ foreach ($res[ 'data' ][ 'list' ] as $k => &$item_v) {
+ $item_v[ 'form_data' ] = json_decode($item_v[ 'form_data' ], true);
+ if ($item_v[ 'scene' ] == 'order') {
+ $item_v[ 'order_info' ] = $order_model->getOrderInfo([ [ 'order_id', '=', $item_v[ 'relation_id' ] ] ], 'order_id,order_no')[ 'data' ];
+ } elseif ($item_v[ 'scene' ] == 'goods') {
+ $item_v[ 'order_goods_info' ] = $order_model->getOrderGoodsInfo([ [ 'order_goods_id', '=', $item_v[ 'relation_id' ] ] ], 'order_goods_id,order_id,order_no')[ 'data' ];
+ }
+ if($item_v['member_id'] > 0){
+ $member = model('member')->getInfo(['member_id'=>$item_v['member_id']]);
+ $res[ 'data' ][ 'list' ][$k]['headimg'] = $member['headimg'];
+ $res[ 'data' ][ 'list' ][$k]['nickname'] = $member['nickname'];
+ $res[ 'data' ][ 'list' ][$k]['status'] = $member['status'];
+ $res[ 'data' ][ 'list' ][$k]['member_level_type'] = $member['member_level_type'];
+ }
+ }
+ }
+ return $res;
+ } else {
+ $this->assign('form_id', $form_id);
+ $item = model('form')->getInfo(['id'=>$form_id]);
+ $this->assign('item', $item);
+ return $this->fetch('form/formdata');
+ }
+ }
+
+ /**
+ * 查询表单列表
+ * @return array
+ */
+ public function getFormList()
+ {
+ if (request()->isJson()) {
+ $form_type = input('form_type', 'goods');
+ $is_use = input('is_use', 1);
+
+ $condition = [
+ [ 'site_id', '=', $this->site_id ],
+ [ 'form_type', '=', $form_type ],
+ [ 'is_use', '=', $is_use ]
+ ];
+ return ( new FormModel() )->getFormList($condition, 'id desc', 'id,form_name');
+ }
+ }
+
+ /**
+ * 推广
+ * @return array
+ */
+ public function promote()
+ {
+ if (request()->isJson()) {
+ $form_id = input('form_id', '');
+ $app_type = input('app_type', 'all');
+ $from_model = new FormModel();
+ $res = $from_model->urlQrcode('/pages_tool/form/formdata', [ 'id' => $form_id,'uniacid'=>$this->site_id ], $app_type, $this->site_id);
+ return $res;
+ }
+ }
+
+ /**
+ * 删除表单数据
+ * @return array|string|string[]
+ */
+ public function deleteFormData()
+ {
+ if (request()->isJson()) {
+ $id = input('id', '');
+ if (empty($id)) return error(-1, 'id不可为空');
+
+ $from_model = new FormDataModel();
+ $res = $from_model->deleteFormData([ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ]);
+ return $res;
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/form/shopapi/controller/Form.php b/src/addon/form/shopapi/controller/Form.php
index a79337138..0dcabde76 100644
--- a/src/addon/form/shopapi/controller/Form.php
+++ b/src/addon/form/shopapi/controller/Form.php
@@ -1,32 +1,24 @@
-params[ 'form_type' ] ?? 'goods';
- $res = ( new FormModel() )->getFormList([ [ 'site_id', '=', $this->site_id ], [ 'form_type', '=', $form_type ], [ 'is_use', '=', 1 ] ], 'id desc', 'id, form_name');
- return $this->response($res);
- }
+params[ 'form_type' ] ?? 'goods';
+ $res = ( new FormModel() )->getFormList([ [ 'site_id', '=', $this->site_id ], [ 'form_type', '=', $form_type ], [ 'is_use', '=', 1 ] ], 'id desc', 'id, form_name');
+ return $this->response($res);
+ }
}
\ No newline at end of file
diff --git a/src/addon/freeshipping/config/diy_view.php b/src/addon/freeshipping/config/diy_view.php
index c3c657905..e36ca9b7d 100644
--- a/src/addon/freeshipping/config/diy_view.php
+++ b/src/addon/freeshipping/config/diy_view.php
@@ -1,38 +1,30 @@
- '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
- 'template' => [],
-
- // 后台自定义组件——装修
- 'util' => [],
-
- // 自定义页面路径
- 'link' => [],
-
- // 自定义图标库
- 'icon_library' => [],
-
- // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
- 'component' => [],
-
- // uni-app 页面,多个逗号隔开
- 'pages' => [],
-
- // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
- 'info' => [],
-
- // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
- 'theme' => [],
-
- // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
- 'data' => []
+ '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
+ 'template' => [],
+
+ // 后台自定义组件——装修
+ 'util' => [],
+
+ // 自定义页面路径
+ 'link' => [],
+
+ // 自定义图标库
+ 'icon_library' => [],
+
+ // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
+ 'component' => [],
+
+ // uni-app 页面,多个逗号隔开
+ 'pages' => [],
+
+ // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
+ 'info' => [],
+
+ // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
+ 'theme' => [],
+
+ // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
+ 'data' => []
];
\ No newline at end of file
diff --git a/src/addon/freeshipping/config/info.php b/src/addon/freeshipping/config/info.php
index 048afea0d..3c9b39fbf 100644
--- a/src/addon/freeshipping/config/info.php
+++ b/src/addon/freeshipping/config/info.php
@@ -1,20 +1,12 @@
- 'freeshipping',
- 'title' => '满额包邮',
- 'description' => '满额包邮',
- 'type' => 'system', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
- 'status' => 1,
- 'author' => '',
- 'version' => '5.3.1',
- 'version_no' => '525231212001',
- 'content' => '',
+ 'freeshipping',
+ 'title' => '满额包邮',
+ 'description' => '满额包邮',
+ 'type' => 'system', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
+ 'status' => 1,
+ 'author' => '',
+ 'version' => '5.3.1',
+ 'version_no' => '525231212001',
+ 'content' => '',
];
\ No newline at end of file
diff --git a/src/addon/freeshipping/event/Install.php b/src/addon/freeshipping/event/Install.php
index b2f3d0243..552b0e858 100644
--- a/src/addon/freeshipping/event/Install.php
+++ b/src/addon/freeshipping/event/Install.php
@@ -1,25 +1,17 @@
- "满额包邮", "type" => "freeshipping"];
- }
+ "满额包邮", "type" => "freeshipping"];
+ }
}
\ No newline at end of file
diff --git a/src/addon/freeshipping/event/ShowPromotion.php b/src/addon/freeshipping/event/ShowPromotion.php
index c65c55aa0..0240acfe8 100644
--- a/src/addon/freeshipping/event/ShowPromotion.php
+++ b/src/addon/freeshipping/event/ShowPromotion.php
@@ -1,45 +1,37 @@
- [
- [
- //插件名称
- 'name' => 'freeshipping',
- //店铺端展示分类 shop:营销活动 member:互动营销
- 'show_type' => 'shop',
- //展示主题
- 'title' => '满额包邮',
- //展示介绍
- 'description' => '购满指定金额订单包邮',
- //展示图标
- 'icon' => 'addon/freeshipping/icon.png',
- //跳转链接
- 'url' => 'freeshipping://shop/freeshipping/lists',
- ]
- ]
-
- ];
- return $data;
- }
+ [
+ [
+ //插件名称
+ 'name' => 'freeshipping',
+ //店铺端展示分类 shop:营销活动 member:互动营销
+ 'show_type' => 'shop',
+ //展示主题
+ 'title' => '满额包邮',
+ //展示介绍
+ 'description' => '购满指定金额订单包邮',
+ //展示图标
+ 'icon' => 'addon/freeshipping/icon.png',
+ //跳转链接
+ 'url' => 'freeshipping://shop/freeshipping/lists',
+ ]
+ ]
+
+ ];
+ return $data;
+ }
}
\ No newline at end of file
diff --git a/src/addon/freeshipping/event/UnInstall.php b/src/addon/freeshipping/event/UnInstall.php
index 9460abcb2..783bf04c5 100644
--- a/src/addon/freeshipping/event/UnInstall.php
+++ b/src/addon/freeshipping/event/UnInstall.php
@@ -1,26 +1,18 @@
- $v) {
- foreach ($v as $area_id) {
-
- $condition = [
- [ 'site_id', '=', $data[ 'site_id' ] ],
- [ 'merch_id', '=', $data[ 'merch_id' ] ],
- [ 'area_ids', 'like', '%' . $area_id . '%' ],
- ];
- if($data[ 'merch_id' ]){
- $condition[] = [ 'merch_id', '=', $data[ 'merch_id' ] ];
- }
- //判断该城市是否已存在
- $count = model('promotion_freeshipping')->getCount($condition);
- if ($count > 0) {
- return $this->error('', '指定地区城市不能重复');
- }
- }
-
- }
- }
-
- $res = model('promotion_freeshipping')->add($data);
- return $this->success($res);
- }
-
- /**
- * 编辑满额包邮
- * @param $groupbuy_id
- * @param $site_id
- * @param $groupbuy_data
- * @return array|\multitype
- */
- public function editFreeshipping($data)
- {
- $freeshipping_id = $data[ 'freeshipping_id' ];
- unset($data[ 'freeshipping_id' ]);
- $data[ 'update_time' ] = time();
- $area_ids = json_decode($data[ 'area_ids' ], true);
- if (!empty($area_ids)) {
- foreach ($area_ids[ '3' ] as $k => $v) {
- foreach ($v as $area_id) {
- $condition = [
- [ 'site_id', '=', $data[ 'site_id' ] ],
- [ 'merch_id', '=', $data[ 'merch_id' ] ],
- [ 'area_ids', 'like', '%' . $area_id . '%' ],
- [ 'freeshipping_id', '<>', $freeshipping_id ]
- ];
- if($data[ 'merch_id' ]){
- $condition[] = [ 'merch_id', '=', $data[ 'merch_id' ] ];
- }
- //判断该城市是否已存在
- $count = model('promotion_freeshipping')->getCount($condition);
- if ($count > 0) {
- return $this->error('', '指定地区城市不能重复');
- }
- }
-
- }
- }
-
- $res = model('promotion_freeshipping')->update($data,
- [ [ 'site_id', '=', $data[ 'site_id' ] ], [ 'freeshipping_id', '=', $freeshipping_id ] ]
- );
- return $this->success($res);
- }
-
- /**
- * 删除满额包邮活动
- * @param $groupbuy_id
- * @param $site_id
- * @return array|\multitype
- */
- public function deleteFreeshipping($freeshipping_id, $site_id)
- {
- $list = model('promotion_freeshipping')->delete([ [ 'freeshipping_id', '=', $freeshipping_id ], [ 'site_id', '=', $site_id ] ]);
- return $this->success($list);
- }
-
- /**
- * 获取信息
- * @param array $condition
- * @param string $field
- * @return array
- */
- public function getFreeshippingInfo($condition = [], $field = '*')
- {
- $res = model('promotion_freeshipping')->getInfo($condition, $field);
- return $this->success($res);
- }
-
- /**
- * 获取满额包邮分页列表
- * @param array $condition
- * @param number $page
- * @param string $page_size
- * @param string $order
- * @param string $field
- */
- public function getFreeshippingPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
- {
- $list = model('promotion_freeshipping')->pageList($condition, $field, $order, $page, $page_size);
- return $this->success($list);
- }
-
- /********************************************************************* 订单核验是否符合地区 start*****************************************************************************/
-
- /**
- * 是否符合满额包邮
- * @param $money
- * @param $district_id
- * @param $site_id
- * @return array
- */
- public function calculate($money, $district_id, $site_id)
- {
- $condition = array (
- [ 'price', '<=', $money ],
- [ 'site_id', '=', $site_id ],
- [ 'area_ids', 'like', '%"' . $district_id . '"%' ]
- );
-
- $info = model('promotion_freeshipping')->getInfo($condition, '*');
- if (!empty($info)) {
- return $this->success($info);
- } else {
- return $this->error();
- }
- }
- /********************************************************************* 订单核验是否符合地区 end*****************************************************************************/
-
+ $v) {
+ foreach ($v as $area_id) {
+
+ $condition = [
+ [ 'site_id', '=', $data[ 'site_id' ] ],
+ [ 'merch_id', '=', $data[ 'merch_id' ] ],
+ [ 'area_ids', 'like', '%' . $area_id . '%' ],
+ ];
+ if($data[ 'merch_id' ]){
+ $condition[] = [ 'merch_id', '=', $data[ 'merch_id' ] ];
+ }
+ //判断该城市是否已存在
+ $count = model('promotion_freeshipping')->getCount($condition);
+ if ($count > 0) {
+ return $this->error('', '指定地区城市不能重复');
+ }
+ }
+
+ }
+ }
+
+ $res = model('promotion_freeshipping')->add($data);
+ return $this->success($res);
+ }
+
+ /**
+ * 编辑满额包邮
+ * @param $groupbuy_id
+ * @param $site_id
+ * @param $groupbuy_data
+ * @return array|\multitype
+ */
+ public function editFreeshipping($data)
+ {
+ $freeshipping_id = $data[ 'freeshipping_id' ];
+ unset($data[ 'freeshipping_id' ]);
+ $data[ 'update_time' ] = time();
+ $area_ids = json_decode($data[ 'area_ids' ], true);
+ if (!empty($area_ids)) {
+ foreach ($area_ids[ '3' ] as $k => $v) {
+ foreach ($v as $area_id) {
+ $condition = [
+ [ 'site_id', '=', $data[ 'site_id' ] ],
+ [ 'merch_id', '=', $data[ 'merch_id' ] ],
+ [ 'area_ids', 'like', '%' . $area_id . '%' ],
+ [ 'freeshipping_id', '<>', $freeshipping_id ]
+ ];
+ if($data[ 'merch_id' ]){
+ $condition[] = [ 'merch_id', '=', $data[ 'merch_id' ] ];
+ }
+ //判断该城市是否已存在
+ $count = model('promotion_freeshipping')->getCount($condition);
+ if ($count > 0) {
+ return $this->error('', '指定地区城市不能重复');
+ }
+ }
+
+ }
+ }
+
+ $res = model('promotion_freeshipping')->update($data,
+ [ [ 'site_id', '=', $data[ 'site_id' ] ], [ 'freeshipping_id', '=', $freeshipping_id ] ]
+ );
+ return $this->success($res);
+ }
+
+ /**
+ * 删除满额包邮活动
+ * @param $groupbuy_id
+ * @param $site_id
+ * @return array|\multitype
+ */
+ public function deleteFreeshipping($freeshipping_id, $site_id)
+ {
+ $list = model('promotion_freeshipping')->delete([ [ 'freeshipping_id', '=', $freeshipping_id ], [ 'site_id', '=', $site_id ] ]);
+ return $this->success($list);
+ }
+
+ /**
+ * 获取信息
+ * @param array $condition
+ * @param string $field
+ * @return array
+ */
+ public function getFreeshippingInfo($condition = [], $field = '*')
+ {
+ $res = model('promotion_freeshipping')->getInfo($condition, $field);
+ return $this->success($res);
+ }
+
+ /**
+ * 获取满额包邮分页列表
+ * @param array $condition
+ * @param number $page
+ * @param string $page_size
+ * @param string $order
+ * @param string $field
+ */
+ public function getFreeshippingPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
+ {
+ $list = model('promotion_freeshipping')->pageList($condition, $field, $order, $page, $page_size);
+ return $this->success($list);
+ }
+
+ /********************************************************************* 订单核验是否符合地区 start*****************************************************************************/
+
+ /**
+ * 是否符合满额包邮
+ * @param $money
+ * @param $district_id
+ * @param $site_id
+ * @return array
+ */
+ public function calculate($money, $district_id, $site_id)
+ {
+ $condition = array (
+ [ 'price', '<=', $money ],
+ [ 'site_id', '=', $site_id ],
+ [ 'area_ids', 'like', '%"' . $district_id . '"%' ]
+ );
+
+ $info = model('promotion_freeshipping')->getInfo($condition, '*');
+ if (!empty($info)) {
+ return $this->success($info);
+ } else {
+ return $this->error();
+ }
+ }
+ /********************************************************************* 订单核验是否符合地区 end*****************************************************************************/
+
}
\ No newline at end of file
diff --git a/src/addon/freeshipping/shop/controller/Freeshipping.php b/src/addon/freeshipping/shop/controller/Freeshipping.php
index bc1b2d7b1..be370fd4d 100644
--- a/src/addon/freeshipping/shop/controller/Freeshipping.php
+++ b/src/addon/freeshipping/shop/controller/Freeshipping.php
@@ -1,111 +1,103 @@
-site_id ];
- if (request()->isJson()) {
- $page = input('page', 1);
- $page_size = input('page_size', PAGE_LIST_ROWS);
- $list = $model->getFreeshippingPageList($condition, $page, $page_size, 'price asc');
- return $list;
- } else {
- return $this->fetch('freeshipping/lists');
- }
-
- }
-
- /**
- * 添加活动
- */
- public function add()
- {
- if (request()->isJson()) {
-
- $price = input('price', '');
- $json = input('json', '');
- $surplus_area_ids = input('surplus_area_ids', '');
-
- $json_data = json_decode($json, true);
- $data = $json_data[ '1' ];
- $data[ 'price' ] = $price;
- $data[ 'site_id' ] = $this->site_id;
- $data[ 'surplus_area_ids' ] = $surplus_area_ids;
- $model = new FreeshippingModel();
- $result = $model->addFreeshipping($data);
- return $result;
-
- } else {
-
- // 地区等级设置 将来从配置中查询数据
- $area_level = 3;
- $this->assign('area_level', $area_level);//地址级别
- return $this->fetch('freeshipping/add');
- }
- }
-
- /**
- * 编辑活动
- */
- public function edit()
- {
- $model = new FreeshippingModel();
- $freeshipping_id = input('freeshipping_id', 0);
- if (request()->isJson()) {
-
- $price = input('price', '');
- $json = input('json', '');
- $surplus_area_ids = input('surplus_area_ids', '');
-
- $json_data = json_decode($json, true);
- $data = $json_data[ '1' ];
- $data[ 'price' ] = $price;
- $data[ 'site_id' ] = $this->site_id;
- $data[ 'surplus_area_ids' ] = $surplus_area_ids;
- $data[ 'freeshipping_id' ] = $freeshipping_id;
-
- $result = $model->editFreeshipping($data);
- return $result;
-
- } else {
- $this->assign('freeshipping_id', $freeshipping_id);
- // 地区等级设置 将来从配置中查询数据
- $area_level = 3;
- $this->assign('area_level', $area_level);//地址级别
-
- $info = $model->getFreeshippingInfo([ [ 'freeshipping_id', '=', $freeshipping_id ], [ 'site_id', '=', $this->site_id ] ])[ 'data' ];
- $this->assign('info', $info);
- return $this->fetch('freeshipping/edit');
- }
- }
-
- /*
- * 删除
- */
- public function delete()
- {
- $freeshipping_id = input('freeshipping_id', '');
- $site_id = $this->site_id;
-
- $model = new FreeshippingModel();
- return $model->deleteFreeshipping($freeshipping_id, $site_id);
- }
-
+site_id ];
+ if (request()->isJson()) {
+ $page = input('page', 1);
+ $page_size = input('page_size', PAGE_LIST_ROWS);
+ $list = $model->getFreeshippingPageList($condition, $page, $page_size, 'price asc');
+ return $list;
+ } else {
+ return $this->fetch('freeshipping/lists');
+ }
+
+ }
+
+ /**
+ * 添加活动
+ */
+ public function add()
+ {
+ if (request()->isJson()) {
+
+ $price = input('price', '');
+ $json = input('json', '');
+ $surplus_area_ids = input('surplus_area_ids', '');
+
+ $json_data = json_decode($json, true);
+ $data = $json_data[ '1' ];
+ $data[ 'price' ] = $price;
+ $data[ 'site_id' ] = $this->site_id;
+ $data[ 'surplus_area_ids' ] = $surplus_area_ids;
+ $model = new FreeshippingModel();
+ $result = $model->addFreeshipping($data);
+ return $result;
+
+ } else {
+
+ // 地区等级设置 将来从配置中查询数据
+ $area_level = 3;
+ $this->assign('area_level', $area_level);//地址级别
+ return $this->fetch('freeshipping/add');
+ }
+ }
+
+ /**
+ * 编辑活动
+ */
+ public function edit()
+ {
+ $model = new FreeshippingModel();
+ $freeshipping_id = input('freeshipping_id', 0);
+ if (request()->isJson()) {
+
+ $price = input('price', '');
+ $json = input('json', '');
+ $surplus_area_ids = input('surplus_area_ids', '');
+
+ $json_data = json_decode($json, true);
+ $data = $json_data[ '1' ];
+ $data[ 'price' ] = $price;
+ $data[ 'site_id' ] = $this->site_id;
+ $data[ 'surplus_area_ids' ] = $surplus_area_ids;
+ $data[ 'freeshipping_id' ] = $freeshipping_id;
+
+ $result = $model->editFreeshipping($data);
+ return $result;
+
+ } else {
+ $this->assign('freeshipping_id', $freeshipping_id);
+ // 地区等级设置 将来从配置中查询数据
+ $area_level = 3;
+ $this->assign('area_level', $area_level);//地址级别
+
+ $info = $model->getFreeshippingInfo([ [ 'freeshipping_id', '=', $freeshipping_id ], [ 'site_id', '=', $this->site_id ] ])[ 'data' ];
+ $this->assign('info', $info);
+ return $this->fetch('freeshipping/edit');
+ }
+ }
+
+ /*
+ * 删除
+ */
+ public function delete()
+ {
+ $freeshipping_id = input('freeshipping_id', '');
+ $site_id = $this->site_id;
+
+ $model = new FreeshippingModel();
+ return $model->deleteFreeshipping($freeshipping_id, $site_id);
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/huaweipay/data/sdk/HuaweiPayClient.php b/src/addon/huaweipay/data/sdk/HuaweiPayClient.php
index 34c4be610..071edd32d 100644
--- a/src/addon/huaweipay/data/sdk/HuaweiPayClient.php
+++ b/src/addon/huaweipay/data/sdk/HuaweiPayClient.php
@@ -21,13 +21,13 @@ class HuaweiPayClient
private $signType = 'RSA2';
// 商户应用私有证书实例
- private $private_key_certificate_instance = '';
+ private $private_key_certificate_instance;
// 华为平台支付证书实例
- private $huawei_public_key_certificate_instance = '';
+ private $huawei_public_key_certificate_instance;
// 华为平台支付服务加密证书实例
- private $huawei_public_key_certificate_instance_encrypt = '';
+ private $huawei_public_key_certificate_instance_encrypt;
// 是否加载了华为平台支付服务加密证书
private $has_huawei_public_key_certificate_instance_encrypt = false;
@@ -40,52 +40,96 @@ class HuaweiPayClient
{
$this->config = $config;
+ // 验证必要配置项
+ if (empty($this->config['app_id'])) {
+ throw new \Exception('缺少必要配置:app_id');
+ }
+ if (empty($this->config['merc_no'])) {
+ throw new \Exception('缺少必要配置:merc_no');
+ }
+
// 证书基础路径
$cert_base_path = app()->getRootPath();
- // 加载商户应用私有证书
- $private_key_path = realpath($cert_base_path . $this->config['private_key']);
- if (!$private_key_path) {
- throw new \Exception('商户应用私有证书文件不存在: ' . $this->config['private_key']);
- }
- $private_key_content = file_get_contents($private_key_path);
- $this->private_key_certificate_instance = openssl_pkey_get_private($private_key_content);
- if (!$this->private_key_certificate_instance) {
- throw new \Exception('加载商户应用私有证书失败');
- }
-
- // 加载华为平台支付证书
- $huawei_public_key_path = realpath($cert_base_path . $this->config['huawei_public_key']);
- if (!$huawei_public_key_path) {
- throw new \Exception('华为平台支付证书文件不存在: ' . $this->config['huawei_public_key']);
- }
- $huawei_public_key_content = file_get_contents($huawei_public_key_path);
- $this->huawei_public_key_certificate_instance = openssl_pkey_get_public($huawei_public_key_content);
- if (!$this->huawei_public_key_certificate_instance) {
- throw new \Exception('加载华为平台支付证书失败');
- }
-
- // 加载华为平台支付服务加密证书
- if (!empty($this->config['huawei_public_key_for_sessionkey'])) {
- $huawei_public_key_encrypt_path = realpath($cert_base_path . $this->config['huawei_public_key_for_sessionkey']);
- if (!$huawei_public_key_encrypt_path) {
- throw new \Exception('华为平台支付服务加密证书文件不存在: ' . $this->config['huawei_public_key_for_sessionkey']);
+ try {
+ // 加载商户应用私有证书
+ if (!empty($this->config['private_key'])) {
+ $private_key_path = realpath($cert_base_path . $this->config['private_key']);
+ if (!$private_key_path) {
+ throw new \Exception('商户应用私有证书文件不存在: ' . $this->config['private_key']);
+ }
+ $private_key_content = file_get_contents($private_key_path);
+ $this->private_key_certificate_instance = openssl_pkey_get_private($private_key_content);
+ if (!$this->private_key_certificate_instance) {
+ throw new \Exception('加载商户应用私有证书失败,请检查证书格式是否正确');
+ }
+ } else {
+ throw new \Exception('缺少必要配置:private_key');
}
- $huawei_public_key_encrypt_content = file_get_contents($huawei_public_key_encrypt_path);
- $this->huawei_public_key_certificate_instance_encrypt = openssl_pkey_get_public($huawei_public_key_encrypt_content);
- if (!$this->huawei_public_key_certificate_instance_encrypt) {
- throw new \Exception('加载华为平台支付服务加密证书失败');
+
+ // 加载华为平台支付证书
+ if (!empty($this->config['huawei_public_key'])) {
+ $huawei_public_key_path = realpath($cert_base_path . $this->config['huawei_public_key']);
+ if (!$huawei_public_key_path) {
+ throw new \Exception('华为平台支付证书文件不存在: ' . $this->config['huawei_public_key']);
+ }
+ $huawei_public_key_content = file_get_contents($huawei_public_key_path);
+ $this->huawei_public_key_certificate_instance = openssl_pkey_get_public($huawei_public_key_content);
+ if (!$this->huawei_public_key_certificate_instance) {
+ throw new \Exception('加载华为平台支付证书失败,请检查证书格式是否正确');
+ }
+ } else {
+ throw new \Exception('缺少必要配置:huawei_public_key');
}
- $this->has_huawei_public_key_certificate_instance_encrypt = true;
+
+ // 加载华为平台支付服务加密证书(可选)
+ if (!empty($this->config['huawei_public_key_for_sessionkey'])) {
+ $huawei_public_key_encrypt_path = realpath($cert_base_path . $this->config['huawei_public_key_for_sessionkey']);
+ if (!$huawei_public_key_encrypt_path) {
+ throw new \Exception('华为平台支付服务加密证书文件不存在: ' . $this->config['huawei_public_key_for_sessionkey']);
+ }
+ $huawei_public_key_encrypt_content = file_get_contents($huawei_public_key_encrypt_path);
+ $this->huawei_public_key_certificate_instance_encrypt = openssl_pkey_get_public($huawei_public_key_encrypt_content);
+ if (!$this->huawei_public_key_certificate_instance_encrypt) {
+ throw new \Exception('加载华为平台支付服务加密证书失败');
+ }
+ $this->has_huawei_public_key_certificate_instance_encrypt = true;
+ }
+ } catch (\Exception $e) {
+ // 释放已加载的证书资源
+ $this->__destruct();
+ throw $e;
}
-
// 根据配置设置网关地址
if (isset($config['sandbox']) && $config['sandbox']) {
$this->gatewayUrl = 'https://pay-drcn.cloud.huawei.com/gateway/api/pay';
}
}
+ /**
+ * 析构函数,释放证书资源
+ */
+ public function __destruct()
+ {
+ // 释放证书资源
+ if ($this->private_key_certificate_instance) {
+ if (is_resource($this->private_key_certificate_instance)) {
+ openssl_free_key($this->private_key_certificate_instance);
+ }
+ }
+ if ($this->huawei_public_key_certificate_instance) {
+ if (is_resource($this->huawei_public_key_certificate_instance)) {
+ openssl_free_key($this->huawei_public_key_certificate_instance);
+ }
+ }
+ if ($this->huawei_public_key_certificate_instance_encrypt) {
+ if (is_resource($this->huawei_public_key_certificate_instance_encrypt)) {
+ openssl_free_key($this->huawei_public_key_certificate_instance_encrypt);
+ }
+ }
+ }
+
/**
* 生成签名
* @param array $params 请求参数
@@ -93,43 +137,53 @@ class HuaweiPayClient
*/
private function generateSign($params)
{
+ // 深拷贝参数,避免修改原参数
+ $signParams = $params;
+
// 移除空值和签名参数
- $params = array_filter($params, function($value) {
+ $signParams = array_filter($signParams, function($value) {
return $value !== null && $value !== '';
});
- unset($params['sign']);
- unset($params['sign_type']);
+ unset($signParams['sign']);
+ unset($signParams['sign_type']);
+ unset($signParams['headerSign']); // 移除headerSign参数
// 按键名排序
- ksort($params);
+ ksort($signParams);
- // 拼接参数
+ // 拼接参数,华为支付文档要求的格式
$stringToSign = '';
- foreach ($params as $key => $value) {
+ foreach ($signParams as $key => $value) {
+ // 确保值为字符串类型
+ $value = (string)$value;
$stringToSign .= $key . '=' . $value . '&';
}
$stringToSign = rtrim($stringToSign, '&');
// 签名结果
$sign = '';
+ $signatureAlgo = '';
// 根据签名类型生成签名
switch ($this->signType) {
case 'RSA2':
- if (!openssl_sign($stringToSign, $sign, $this->private_key_certificate_instance, OPENSSL_ALGO_SHA256)) {
- throw new \Exception('RSA2签名生成失败');
- }
+ $signatureAlgo = OPENSSL_ALGO_SHA256;
break;
case 'RSA':
- if (!openssl_sign($stringToSign, $sign, $this->private_key_certificate_instance, OPENSSL_ALGO_SHA1)) {
- throw new \Exception('RSA签名生成失败');
- }
+ $signatureAlgo = OPENSSL_ALGO_SHA1;
break;
default:
- throw new \Exception('不支持的签名类型');
+ throw new \Exception('不支持的签名类型: ' . $this->signType);
}
- return base64_encode($sign);
+ // 生成签名
+ if (!is_resource($this->private_key_certificate_instance) || !openssl_sign($stringToSign, $sign, $this->private_key_certificate_instance, $signatureAlgo)) {
+ $error = openssl_error_string();
+ throw new \Exception('签名生成失败: ' . $error);
+ }
+
+ // Base64编码并URL编码
+ return urlencode(base64_encode($sign));
}
/**
@@ -145,20 +199,23 @@ class HuaweiPayClient
return false;
}
- unset($params['sign']);
- unset($params['sign_type']);
+ // 深拷贝参数,避免修改原参数
+ $verifyParams = $params;
+
+ unset($verifyParams['sign']);
+ unset($verifyParams['sign_type']);
// 移除空值
- $params = array_filter($params, function($value) {
+ $verifyParams = array_filter($verifyParams, function($value) {
return $value !== null && $value !== '';
});
// 按键名排序
- ksort($params);
+ ksort($verifyParams);
// 拼接参数
$stringToSign = '';
- foreach ($params as $key => $value) {
+ foreach ($verifyParams as $key => $value) {
$stringToSign .= $key . '=' . $value . '&';
}
$stringToSign = rtrim($stringToSign, '&');
@@ -191,22 +248,41 @@ class HuaweiPayClient
{
$ch = curl_init();
- // 生成签名
- // --- 必须参数 ---
- $params['appId'] = $this->config['app_id'];
- $params['mercNo'] = $this->config['merc_no'];
+ // 根据华为支付文档,添加必要的公共参数
+ $params['app_id'] = $this->config['app_id'];
+ $params['merc_no'] = $this->config['merc_no'];
- // --- 验证以下参数必须存在 ---
- $requiredParams = ['appId', 'mercNo', 'mercOrderNo', 'tradeSummary', 'totalAmount', 'callbackUrl'];
+ // 根据方法类型验证必要参数
+ $method = $params['method'] ?? '';
+ $requiredParams = [];
+
+ // 根据不同的API方法设置不同的必填参数
+ switch ($method) {
+ case 'h5pay.createPayment':
+ case 'apppay.createPayment':
+ $requiredParams = ['out_trade_no', 'subject', 'total_amount', 'notify_url'];
+ break;
+ case 'unifiedorder.query':
+ // 查询订单只需要out_trade_no或trade_no中的一个
+ break;
+ case 'unifiedorder.close':
+ case 'refund.apply':
+ $requiredParams = ['out_trade_no'];
+ break;
+ }
+
+ // 验证必填参数
foreach ($requiredParams as $param) {
if (!isset($params[$param]) || empty($params[$param])) {
throw new \Exception('缺少必要参数: ' . $param);
}
}
+ // 生成签名
$params['sign_type'] = $this->signType;
$params['sign'] = $this->generateSign($params);
+ // 设置请求方式
if ($method === 'POST') {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
@@ -214,30 +290,40 @@ class HuaweiPayClient
$url .= '?' . http_build_query($params);
}
- // 参考:https://developer.huawei.com/consumer/cn/doc/HMSCore-References/api-data-model-0000001538219104#section11744172016145
- $pay_merc_auth_part = [
- 'callerId' => $this->config['merc_no'], // 商户号
- 'traceId' => $params['traceId'] ?? uniqid(), // 交易ID或跟踪ID
- 'time' => date('YmdHis'), // 时间戳
- 'authId' => $this->config['auth_id'], // 商户证书编号
- 'bodySign' => $this->generateSign($params), // 对请求Body参数签名
- ];
+ // 参考华为支付文档,设置PayMercAuth头
+ // 注意:华为支付SDK v2.0及以上版本需要此头部
+ if (isset($this->config['auth_id']) && !empty($this->config['auth_id'])) {
+ $traceId = isset($params['traceId']) ? $params['traceId'] : uniqid();
+
+ $pay_merc_auth_part = [
+ 'callerId' => $this->config['merc_no'],
+ 'traceId' => $traceId,
+ 'time' => date('YmdHis'),
+ 'authId' => $this->config['auth_id'],
+ 'bodySign' => $params['sign'] // 直接使用已生成的签名
+ ];
- $pay_merc_auth = [
- 'headerSign' => $this->generateSign($pay_merc_auth_part), // 对PayMercAuthPart参数签名
- // 其他参数直接使用PayMercAuthPart中的值,不进行修改,能用解构赋值
- ...$pay_merc_auth_part,
- ];
-
- // 设置请求头
- $headers = [
- 'Content-Type: application/x-www-form-urlencoded; charset=utf-8',
- 'PayMercAuth: ' . json_encode($pay_merc_auth),
- ];
+ // 对PayMercAuthPart进行签名
+ $pay_merc_auth_part['headerSign'] = $this->generateSign($pay_merc_auth_part);
+
+ // 设置请求头
+ $headers = [
+ 'Content-Type: application/x-www-form-urlencoded; charset=utf-8',
+ 'PayMercAuth: ' . json_encode($pay_merc_auth_part),
+ ];
+ } else {
+ // 不使用PayMercAuth头的情况
+ $headers = [
+ 'Content-Type: application/x-www-form-urlencoded; charset=utf-8',
+ ];
+ }
+ // 设置curl选项
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+
+ // 在生产环境中应该启用SSL验证
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
@@ -271,14 +357,28 @@ class HuaweiPayClient
*/
public function h5Pay($params, $returnUrl, $notifyUrl)
{
+ // 检查必要参数
+ if (empty($params['out_trade_no'])) {
+ throw new \Exception('缺少必要参数:out_trade_no');
+ }
+ if (empty($params['subject'])) {
+ throw new \Exception('缺少必要参数:subject');
+ }
+ if (!isset($params['total_amount']) || $params['total_amount'] <= 0) {
+ throw new \Exception('缺少或无效的参数:total_amount');
+ }
+ if (empty($notifyUrl)) {
+ throw new \Exception('缺少必要参数:notify_url');
+ }
+
$requestParams = [
'method' => 'h5pay.createPayment',
'version' => '1.0',
'timestamp' => date('Y-m-d H:i:s'),
'out_trade_no' => $params['out_trade_no'],
- 'subject' => $params['subject'],
- 'body' => $params['body'],
- 'total_amount' => $params['total_amount'],
+ 'subject' => mb_substr($params['subject'], 0, 128, 'UTF-8'), // 限制长度
+ 'body' => isset($params['body']) ? mb_substr($params['body'], 0, 512, 'UTF-8') : mb_substr($params['subject'], 0, 512, 'UTF-8'),
+ 'total_amount' => number_format($params['total_amount'], 2, '.', ''), // 确保格式正确
'scene' => 'h5',
'return_url' => $returnUrl,
'notify_url' => $notifyUrl,
@@ -295,7 +395,7 @@ class HuaweiPayClient
$requestParams['timeout_express'] = $params['timeout_express'];
}
if (isset($params['attach'])) {
- $requestParams['attach'] = $params['attach'];
+ $requestParams['attach'] = mb_substr($params['attach'], 0, 128, 'UTF-8');
}
return $this->httpRequest($this->gatewayUrl, $requestParams);
@@ -384,17 +484,34 @@ class HuaweiPayClient
*/
public function refund($params)
{
+ // 检查必要参数
+ if (!isset($params['out_trade_no']) && !isset($params['trade_no'])) {
+ throw new \Exception('退款请求必须提供out_trade_no或trade_no');
+ }
+ if (!isset($params['out_request_no'])) {
+ throw new \Exception('退款请求必须提供out_request_no');
+ }
+ if (!isset($params['refund_amount']) || $params['refund_amount'] <= 0) {
+ throw new \Exception('退款金额必须大于0');
+ }
+
$requestParams = [
'method' => 'refund.apply',
'version' => '1.0',
'timestamp' => date('Y-m-d H:i:s'),
- 'out_trade_no' => $params['out_trade_no'],
- 'trade_no' => $params['trade_no'],
'refund_amount' => $params['refund_amount'],
'out_request_no' => $params['out_request_no'],
'refund_reason' => $params['refund_reason'] ?? '',
];
+ // 添加订单标识(二选一)
+ if (isset($params['out_trade_no'])) {
+ $requestParams['out_trade_no'] = $params['out_trade_no'];
+ }
+ if (isset($params['trade_no'])) {
+ $requestParams['trade_no'] = $params['trade_no'];
+ }
+
return $this->httpRequest($this->gatewayUrl, $requestParams);
}
diff --git a/src/addon/huaweipay/event/TransferType.php b/src/addon/huaweipay/event/TransferType.php
index 8b2439b17..a8da4c456 100644
--- a/src/addon/huaweipay/event/TransferType.php
+++ b/src/addon/huaweipay/event/TransferType.php
@@ -19,7 +19,7 @@ class TransferType
$app_type = $params['app_type'] ?? '';
if (!empty($app_type)) {
$config_model = new Config();
- $app_type_array = $config_model->app_type;
+ $app_type_array = $config_model->getSupportAppTypesKeys();
if (!in_array($app_type, $app_type_array)) {
return '';
}
diff --git a/src/addon/huaweipay/model/Config.php b/src/addon/huaweipay/model/Config.php
index ed6757df6..3371fedf6 100644
--- a/src/addon/huaweipay/model/Config.php
+++ b/src/addon/huaweipay/model/Config.php
@@ -12,6 +12,8 @@ namespace addon\huaweipay\model;
use app\model\system\Config as ConfigModel;
use app\model\BaseModel;
+use think\facade\Config as ConfigFacade;
+
/**
* 华为支付配置
*/
@@ -30,6 +32,35 @@ class Config extends BaseModel
'huawei_public_key_for_sessionkey'
];
+ /**
+ * 获取支持的应用类型
+ * 从配置文件中获取支持的应用类型,参看 src/config/app_type.php
+ * @return array
+ * 示例:
+ * [
+ * 'weapp' => ['name' => '微信小程序', 'logo' => 'public/static/img/channel/weapp.png', 'icon' => 'iconfont iconxiaochengxu'],
+ * 'h5' => ['name' => '华为快应用', 'logo' => 'public/static/img/channel/h5.png', 'icon' => 'iconfont iconxiaochengxu1']
+ * ];
+ */
+ public function getSupportAppTypes()
+ {
+ return ConfigFacade::get("app_type") ?? [];
+ }
+
+ /**
+ * 获取支持的应用类型键值
+ * @return array
+ * 示例:
+ * [
+ * 'weapp',
+ * 'h5'
+ * ];
+ */
+ public function getSupportAppTypesKeys()
+ {
+ return array_keys($this->getSupportAppTypes());
+ }
+
/**
* 设置支付配置
* @param $data
diff --git a/src/addon/huaweipay/model/Pay.php b/src/addon/huaweipay/model/Pay.php
index d7f44b7f3..36f8f2829 100644
--- a/src/addon/huaweipay/model/Pay.php
+++ b/src/addon/huaweipay/model/Pay.php
@@ -57,55 +57,128 @@ class Pay extends BaseModel
/**
* 生成支付
* @param $param 支付参数
+ * @param $param["out_trade_no"] 订单号
+ * @param $param["pay_body"] 支付描述
+ * @param $param["pay_money"] 支付金额
+ * @param $param["notify_url"] 支付回调地址
+ * @param $param["client_ip"] 客户端IP
+ * @param $param["attach"] 附加数据
+ * @param $param["app_type"] 应用类型
* @return array
*/
public function pay($param)
{
try {
+ // 验证必要参数
+ if (empty($param["out_trade_no"])) {
+ throw new \Exception('缺少必要参数:out_trade_no');
+ }
+ if (empty($param["pay_body"])) {
+ throw new \Exception('缺少必要参数:pay_body');
+ }
+ if (!isset($param["pay_money"]) || $param["pay_money"] <= 0) {
+ throw new \Exception('缺少或无效的参数:pay_money');
+ }
+ if (empty($param["notify_url"])) {
+ throw new \Exception('缺少必要参数:notify_url');
+ }
+
// 构造华为支付请求参数
$parameter = array(
"out_trade_no" => $param["out_trade_no"],
- "subject" => substr($param["pay_body"], 0, 15),
- "total_amount" => (float)$param["pay_money"],
- "body" => substr($param["pay_body"], 0, 60),
+ "subject" => mb_substr($param["pay_body"], 0, 128, 'UTF-8'), // 限制长度,支持中文
+ "total_amount" => number_format((float)$param["pay_money"], 2, '.', ''), // 确保金额格式正确
+ "body" => mb_substr($param["pay_body"], 0, 512, 'UTF-8'), // 限制长度,支持中文
);
+ // 添加客户端IP(如果有)
+ if (!empty($param["client_ip"])) {
+ $parameter["client_ip"] = $param["client_ip"];
+ }
+
+ // 添加附加数据(如果有)
+ if (!empty($param["attach"])) {
+ $parameter["attach"] = mb_substr($param["attach"], 0, 128, 'UTF-8');
+ }
+
// 绑定商户数据
$pay_model = new PayModel();
- $pay_model->bindMchPay($param["out_trade_no"], []);
+ $pay_model->bindMchPay($param["out_trade_no"], ["pay_type" => "huaweipay"]);
+
+ // 记录请求日志
+ Log::info('华为支付请求参数: ' . json_encode($parameter));
// 根据不同的应用类型调用不同的华为支付API
switch ($param["app_type"]) {
- case "h5":
- // H5支付
- $result = $this->hwpay_client->h5Pay($parameter, $param["return_url"], $param["notify_url"]);
- if ($result['code'] == '0') {
- return $this->success([
- 'type' => 'url',
- 'data' => $result['pay_url']
- ]);
- } else {
- return $this->error('', $result['msg'] ?? '华为支付请求失败');
- }
- break;
- case "app":
- // APP支付
- $result = $this->hwpay_client->appPay($parameter, $param["notify_url"]);
- if ($result['code'] == '0') {
+ case "weapp":
+ // 微信小程序支付
+ $result = $this->hwpay_client->weappPay($parameter, $param["notify_url"]);
+
+ // 记录响应日志
+ Log::info('华为微信小程序支付响应: ' . json_encode($result));
+
+ if (isset($result['code']) && $result['code'] == '0') {
return $this->success([
'type' => 'params',
'data' => $result
]);
} else {
- return $this->error('', $result['msg'] ?? '华为支付请求失败');
+ $errorMsg = $result['msg'] ?? ($result['message'] ?? '华为微信小程序支付请求失败');
+ Log::error('华为微信小程序支付失败: ' . $errorMsg);
+ return $this->error('', $errorMsg);
+ }
+ break;
+ case "h5":
+ // H5支付
+ if (empty($param["return_url"])) {
+ throw new \Exception('H5支付缺少必要参数:return_url');
+ }
+
+ $result = $this->hwpay_client->h5Pay($parameter, $param["return_url"], $param["notify_url"]);
+
+ // 记录响应日志
+ Log::info('华为H5支付响应: ' . json_encode($result));
+
+ if (isset($result['code']) && $result['code'] == '0') {
+ // 检查是否有pay_url
+ if (isset($result['pay_url'])) {
+ return $this->success([
+ 'type' => 'url',
+ 'data' => $result['pay_url']
+ ]);
+ } else {
+ throw new \Exception('华为支付响应缺少pay_url');
+ }
+ } else {
+ $errorMsg = $result['msg'] ?? ($result['message'] ?? '华为支付请求失败');
+ Log::error('华为H5支付失败: ' . $errorMsg);
+ return $this->error('', $errorMsg);
+ }
+ break;
+ case "app":
+ // APP支付
+ $result = $this->hwpay_client->appPay($parameter, $param["notify_url"]);
+
+ // 记录响应日志
+ Log::info('华为APP支付响应: ' . json_encode($result));
+
+ if (isset($result['code']) && $result['code'] == '0') {
+ return $this->success([
+ 'type' => 'params',
+ 'data' => $result
+ ]);
+ } else {
+ $errorMsg = $result['msg'] ?? ($result['message'] ?? '华为支付请求失败');
+ Log::error('华为APP支付失败: ' . $errorMsg);
+ return $this->error('', $errorMsg);
}
break;
default:
// 默认返回错误
- return $this->error('', '不支持的支付类型');
+ return $this->error('', '不支持的支付类型: ' . $param["app_type"]);
}
} catch (\Exception $e) {
- Log::error('华为支付生成支付失败: ' . $e->getMessage());
+ Log::error('华为支付生成支付失败: ' . $e->getMessage() . ',错误堆栈: ' . $e->getTraceAsString());
return $this->error('', $e->getMessage());
}
}
@@ -144,30 +217,59 @@ class Pay extends BaseModel
public function refund($param)
{
try {
+ // 验证必要参数
+ if (empty($param["pay_info"])) {
+ throw new \Exception('缺少必要参数:pay_info');
+ }
+ if (empty($param["refund_no"])) {
+ throw new \Exception('缺少必要参数:refund_no');
+ }
+ if (!isset($param["refund_fee"]) || $param["refund_fee"] <= 0) {
+ throw new \Exception('缺少或无效的参数:refund_fee');
+ }
+
$pay_info = $param["pay_info"];
$refund_no = $param["refund_no"];
$out_trade_no = $pay_info["out_trade_no"] ?? '';
$trade_no = $pay_info["trade_no"] ?? '';
$refund_fee = $param["refund_fee"];
+ // 至少需要out_trade_no或trade_no中的一个
+ if (empty($out_trade_no) && empty($trade_no)) {
+ throw new \Exception('退款请求必须提供out_trade_no或trade_no');
+ }
+
$parameter = array(
- 'out_trade_no' => $out_trade_no,
- 'trade_no' => $trade_no,
- 'refund_amount' => sprintf("%.2f", $refund_fee),
+ 'refund_amount' => number_format($refund_fee, 2, '.', ''), // 确保金额格式正确
'out_request_no' => $refund_no,
- 'refund_reason' => $param["refund_desc"] ?? ''
+ 'refund_reason' => isset($param["refund_desc"]) ? mb_substr($param["refund_desc"], 0, 512, 'UTF-8') : '用户退款',
);
+ // 添加订单标识(二选一)
+ if (!empty($out_trade_no)) {
+ $parameter['out_trade_no'] = $out_trade_no;
+ } else {
+ $parameter['trade_no'] = $trade_no;
+ }
+
+ // 记录退款请求日志
+ Log::info('华为支付退款请求参数: ' . json_encode($parameter));
+
// 调用华为支付退款API
$result = $this->hwpay_client->refund($parameter);
- if ($result['code'] == '0') {
- return $this->success();
+ // 记录退款响应日志
+ Log::info('华为支付退款响应: ' . json_encode($result));
+
+ if (isset($result['code']) && $result['code'] == '0') {
+ return $this->success($result);
} else {
- return $this->error('', $result['msg'] ?? '退款失败');
+ $errorMsg = $result['msg'] ?? ($result['message'] ?? '退款失败');
+ Log::error('华为支付退款失败: ' . $errorMsg);
+ return $this->error('', $errorMsg);
}
} catch (\Exception $e) {
- Log::error('华为支付退款失败: ' . $e->getMessage());
+ Log::error('华为支付退款异常: ' . $e->getMessage() . ',错误堆栈: ' . $e->getTraceAsString());
return $this->error('', $e->getMessage());
}
}
@@ -192,24 +294,47 @@ class Pay extends BaseModel
/**
* 异步完成支付
* @param $param 回调参数
+ * @return string 响应给华为服务器的结果
*/
public function notify($param)
{
try {
+ // 记录原始回调参数
+ Log::info('华为支付回调参数: ' . json_encode($param));
+
// 验证华为支付回调签名
$is_valid = $this->hwpay_client->verifyNotify($param);
if ($is_valid) { // 验证成功
- $out_trade_no = $param['out_trade_no'];
- // 华为支付交易号
- $trade_no = $param['trade_no'];
- // 交易状态
- $trade_status = $param['trade_status'];
- $pay_common = new PayCommon();
+ // 获取订单号和交易状态
+ $out_trade_no = $param['out_trade_no'] ?? '';
+ $trade_no = $param['trade_no'] ?? '';
+ $trade_status = $param['trade_status'] ?? '';
- if ($trade_status == "TRADE_SUCCESS") {
- $retval = $pay_common->onlinePay($out_trade_no, "huaweipay", $trade_no, "huaweipay");
+ // 验证必要参数
+ if (empty($out_trade_no)) {
+ Log::error('华为支付回调缺少out_trade_no');
+ echo "fail";
+ return;
}
+
+ // 根据华为支付文档,成功状态可能是'SUCCESS'或'TRADE_SUCCESS'
+ if ($trade_status == "SUCCESS" || $trade_status == "TRADE_SUCCESS") {
+ $pay_common = new PayCommon();
+ $retval = $pay_common->onlinePay($out_trade_no, "huaweipay", $trade_no, "huaweipay");
+
+ // 记录支付结果
+ if ($retval['code'] >= 0) {
+ Log::info('华为支付回调处理成功,订单号: ' . $out_trade_no);
+ } else {
+ Log::error('华为支付回调处理失败,订单号: ' . $out_trade_no . ',错误信息: ' . ($retval['message'] ?? '未知错误'));
+ }
+ } else {
+ Log::info('华为支付回调状态非成功: ' . $trade_status . ',订单号: ' . $out_trade_no);
+ }
+
+ // 无论支付是否成功,只要签名验证通过就返回success
+ // 避免华为服务器重复推送
echo "success";
} else {
// 验证失败
@@ -217,7 +342,7 @@ class Pay extends BaseModel
echo "fail";
}
} catch (\Exception $e) {
- Log::error('华为支付回调处理失败: ' . $e->getMessage());
+ Log::error('华为支付回调处理异常: ' . $e->getMessage() . ',错误堆栈: ' . $e->getTraceAsString());
echo "fail";
}
}
diff --git a/src/addon/huaweipay/shop/controller/Pay.php b/src/addon/huaweipay/shop/controller/Pay.php
index 8a121ef40..bfcf8d9fb 100644
--- a/src/addon/huaweipay/shop/controller/Pay.php
+++ b/src/addon/huaweipay/shop/controller/Pay.php
@@ -7,7 +7,6 @@ namespace addon\huaweipay\shop\controller;
use addon\huaweipay\model\Config as ConfigModel;
use app\shop\controller\BaseShop;
-use think\facade\Config;
use app\model\upload\Upload;
/**
@@ -57,7 +56,7 @@ class Pay extends BaseShop
$info[ 'enable_app_type_arr' ] = $enable_app_type_arr; // 当前支持的支付端口
}
$this->assign("info", $info);
- $this->assign("support_app_types", Config::get("app_type")); // 获取所有支持的支付端口
+ $this->assign("support_app_types", $config_model->getSupportAppTypes()); // 获取所有支持的支付端口
return $this->fetch("pay/config");
}
diff --git a/src/addon/huaweipay/tests/HuaweiPayClientTest.php b/src/addon/huaweipay/tests/HuaweiPayClientTest.php
new file mode 100644
index 000000000..58de17f00
--- /dev/null
+++ b/src/addon/huaweipay/tests/HuaweiPayClientTest.php
@@ -0,0 +1,295 @@
+ 'test_app_id',
+ 'merc_no' => 'test_merc_no',
+ 'private_key' => 'tests/mock/cert/merchant_private_key.pem',
+ 'huawei_public_key' => 'tests/mock/cert/huawei_public_key.pem',
+ 'sandbox' => true
+ ];
+
+ /**
+ * 运行所有测试
+ */
+ public function runTests()
+ {
+ echo "开始测试华为支付客户端...\n";
+
+ try {
+ $this->testConstructSuccess();
+ $this->testConstructMissingConfig();
+ $this->testGenerateSign();
+ $this->testH5Pay();
+ $this->testOrderQuery();
+ $this->testRefund();
+ $this->testVerifySign();
+
+ echo "\n✅ 所有测试通过!\n";
+ return true;
+ } catch (\Exception $e) {
+ echo "\n❌ 测试失败:" . $e->getMessage() . "\n";
+ echo "错误位置:" . $e->getFile() . " 第" . $e->getLine() . "行\n";
+ return false;
+ }
+ }
+
+ /**
+ * 测试构造函数 - 成功场景
+ */
+ public function testConstructSuccess()
+ {
+ echo "测试构造函数成功场景...";
+
+ // 模拟证书文件
+ $this->createMockCertFiles();
+
+ try {
+ $client = new HuaweiPayClient($this->testConfig);
+ echo " ✅ 通过\n";
+ } catch (\Exception $e) {
+ throw new \Exception("构造函数测试失败: " . $e->getMessage());
+ }
+ }
+
+ /**
+ * 测试构造函数 - 缺少必要配置
+ */
+ public function testConstructMissingConfig()
+ {
+ echo "测试构造函数缺少配置...";
+
+ // 测试缺少app_id
+ try {
+ $config = $this->testConfig;
+ unset($config['app_id']);
+ new HuaweiPayClient($config);
+ throw new \Exception("应该抛出缺少app_id的异常");
+ } catch (\Exception $e) {
+ if (strpos($e->getMessage(), '缺少必要配置:app_id') === false) {
+ throw new \Exception("异常信息不正确: " . $e->getMessage());
+ }
+ }
+
+ echo " ✅ 通过\n";
+ }
+
+ /**
+ * 测试生成签名
+ */
+ public function testGenerateSign()
+ {
+ echo "测试生成签名...";
+
+ $this->createMockCertFiles();
+ $client = new HuaweiPayClient($this->testConfig);
+
+ // 使用反射调用私有方法
+ $reflection = new \ReflectionClass($client);
+ $method = $reflection->getMethod('generateSign');
+ $method->setAccessible(true);
+
+ $params = [
+ 'app_id' => 'test_app_id',
+ 'merc_no' => 'test_merc_no',
+ 'order_id' => 'test_order_001',
+ 'amount' => 100,
+ 'sign' => 'ignored'
+ ];
+
+ // 测试签名不应该失败
+ try {
+ $sign = $method->invoke($client, $params);
+ $this->assertEquals(true, is_string($sign), "签名应该是字符串");
+ echo " ✅ 通过\n";
+ } catch (\Exception $e) {
+ throw new \Exception("签名生成测试失败: " . $e->getMessage());
+ }
+ }
+
+ /**
+ * 测试H5支付
+ */
+ public function testH5Pay()
+ {
+ echo "测试H5支付...";
+
+ $this->createMockCertFiles();
+
+ // 模拟HTTP请求
+ $this->mockHttpRequest();
+
+ $client = new HuaweiPayClient($this->testConfig);
+
+ $params = [
+ 'order_id' => 'test_order_001',
+ 'amount' => 100,
+ 'subject' => '测试商品',
+ 'notify_url' => 'https://example.com/notify',
+ 'return_url' => 'https://example.com/return'
+ ];
+
+ // 由于无法真正发送HTTP请求,这里只测试参数验证
+ try {
+ // 尝试调用,实际环境可能需要模拟curl
+ $result = $client->h5Pay($params);
+ echo " ⚠️ 跳过实际HTTP请求测试\n";
+ } catch (\Exception $e) {
+ // 预期可能会有curl错误,这里只检查是否因为参数问题
+ if (strpos($e->getMessage(), '缺少必要参数') !== false) {
+ throw new \Exception("H5支付参数测试失败: " . $e->getMessage());
+ }
+ echo " ⚠️ 跳过实际HTTP请求测试\n";
+ }
+ }
+
+ /**
+ * 测试订单查询
+ */
+ public function testOrderQuery()
+ {
+ echo "测试订单查询...";
+
+ $this->createMockCertFiles();
+
+ $client = new HuaweiPayClient($this->testConfig);
+
+ $params = [
+ 'order_id' => 'test_order_001'
+ ];
+
+ try {
+ // 尝试调用,实际环境可能需要模拟curl
+ $result = $client->orderQuery($params);
+ echo " ⚠️ 跳过实际HTTP请求测试\n";
+ } catch (\Exception $e) {
+ if (strpos($e->getMessage(), '缺少必要参数') !== false) {
+ throw new \Exception("订单查询参数测试失败: " . $e->getMessage());
+ }
+ echo " ⚠️ 跳过实际HTTP请求测试\n";
+ }
+ }
+
+ /**
+ * 测试退款
+ */
+ public function testRefund()
+ {
+ echo "测试退款...";
+
+ $this->createMockCertFiles();
+
+ $client = new HuaweiPayClient($this->testConfig);
+
+ $params = [
+ 'order_id' => 'test_order_001',
+ 'refund_order_id' => 'refund_001',
+ 'refund_amount' => 100
+ ];
+
+ try {
+ // 尝试调用,实际环境可能需要模拟curl
+ $result = $client->refund($params);
+ echo " ⚠️ 跳过实际HTTP请求测试\n";
+ } catch (\Exception $e) {
+ if (strpos($e->getMessage(), '缺少必要参数') !== false) {
+ throw new \Exception("退款参数测试失败: " . $e->getMessage());
+ }
+ echo " ⚠️ 跳过实际HTTP请求测试\n";
+ }
+ }
+
+ /**
+ * 测试签名验证
+ */
+ public function testVerifySign()
+ {
+ echo "测试签名验证...";
+
+ $this->createMockCertFiles();
+ $client = new HuaweiPayClient($this->testConfig);
+
+ // 使用反射调用私有方法
+ $reflection = new \ReflectionClass($client);
+ $method = $reflection->getMethod('verifySign');
+ $method->setAccessible(true);
+
+ $params = [
+ 'app_id' => 'test_app_id',
+ 'merc_no' => 'test_merc_no',
+ 'order_id' => 'test_order_001',
+ 'amount' => 100
+ ];
+
+ // 由于无法真正验证签名,这里只测试方法是否存在
+ try {
+ // 传入空签名,预期会失败
+ $verified = $method->invoke($client, $params, '');
+ echo " ⚠️ 跳过实际签名验证测试\n";
+ } catch (\Exception $e) {
+ echo " ⚠️ 跳过实际签名验证测试\n";
+ }
+ }
+
+ /**
+ * 创建模拟证书文件
+ */
+ private function createMockCertFiles()
+ {
+ // 确保mock证书目录存在
+ $certDir = __DIR__ . '/mock/cert/';
+ if (!is_dir($certDir)) {
+ mkdir($certDir, 0755, true);
+ }
+
+ // 创建模拟证书文件
+ $privateKeyPath = $certDir . 'merchant_private_key.pem';
+ $publicKeyPath = $certDir . 'huawei_public_key.pem';
+
+ if (!file_exists($privateKeyPath)) {
+ file_put_contents($privateKeyPath, '-----BEGIN PRIVATE KEY-----\nMOCK_PRIVATE_KEY_CONTENT\n-----END PRIVATE KEY-----');
+ }
+
+ if (!file_exists($publicKeyPath)) {
+ file_put_contents($publicKeyPath, '-----BEGIN PUBLIC KEY-----\nMOCK_PUBLIC_KEY_CONTENT\n-----END PUBLIC KEY-----');
+ }
+ }
+
+ /**
+ * 模拟HTTP请求
+ */
+ private function mockHttpRequest()
+ {
+ // 在实际测试中,可以使用更高级的模拟技术
+ // 这里仅提供基础框架
+ }
+
+ /**
+ * 断言相等
+ */
+ private function assertEquals($expected, $actual, $message = '')
+ {
+ if ($expected !== $actual) {
+ throw new \Exception($message ?: "断言失败: 期望 {$expected},实际得到 {$actual}");
+ }
+ }
+}
+
+// 如果直接运行此文件,则执行测试
+if (basename(__FILE__) == basename($_SERVER['PHP_SELF'])) {
+ $test = new HuaweiPayClientTest();
+ $test->runTests();
+}
\ No newline at end of file
diff --git a/src/addon/huaweipay/tests/PayModelTest.php b/src/addon/huaweipay/tests/PayModelTest.php
new file mode 100644
index 000000000..970354b22
--- /dev/null
+++ b/src/addon/huaweipay/tests/PayModelTest.php
@@ -0,0 +1,178 @@
+testPayMethod();
+ $this->testNotifyMethod();
+ $this->testCloseOrderMethod();
+ $this->testRefundMethod();
+ $this->testQueryOrderMethod();
+
+ echo "\n✅ 所有测试通过!\n";
+ return true;
+ } catch (\Exception $e) {
+ echo "\n❌ 测试失败:" . $e->getMessage() . "\n";
+ echo "错误位置:" . $e->getFile() . " 第" . $e->getLine() . "行\n";
+ return false;
+ }
+ }
+
+ /**
+ * 测试支付方法
+ */
+ public function testPayMethod()
+ {
+ echo "测试支付方法...";
+
+ try {
+ // 模拟配置
+ $this->mockConfig();
+
+ // 创建测试订单数据
+ $orderInfo = [
+ 'out_trade_no' => 'test_order_' . time(),
+ 'total_amount' => 100,
+ 'subject' => '测试商品',
+ 'notify_url' => 'https://example.com/notify',
+ 'return_url' => 'https://example.com/return',
+ 'buyer_id' => '1',
+ 'type' => 'h5'
+ ];
+
+ // 尝试创建Pay实例
+ $payModel = new Pay($this->siteId);
+
+ // 由于需要实际的支付客户端,这里只测试模型初始化
+ echo " ⚠️ 跳过实际支付测试,仅测试模型初始化\n";
+ } catch (\Exception $e) {
+ echo " ⚠️ 模型初始化测试跳过: " . $e->getMessage() . "\n";
+ }
+ }
+
+ /**
+ * 测试通知方法
+ */
+ public function testNotifyMethod()
+ {
+ echo "测试通知方法...";
+
+ try {
+ // 模拟配置
+ $this->mockConfig();
+
+ // 创建模拟通知数据
+ $notifyData = [
+ 'app_id' => 'test_app_id',
+ 'merc_no' => 'test_merc_no',
+ 'order_id' => 'test_order_001',
+ 'trade_status' => 'SUCCESS',
+ 'sign' => 'mock_signature'
+ ];
+
+ // 尝试创建Pay实例
+ $payModel = new Pay($this->siteId);
+
+ echo " ⚠️ 跳过实际通知处理测试\n";
+ } catch (\Exception $e) {
+ echo " ⚠️ 通知测试跳过: " . $e->getMessage() . "\n";
+ }
+ }
+
+ /**
+ * 测试关闭订单方法
+ */
+ public function testCloseOrderMethod()
+ {
+ echo "测试关闭订单方法...";
+
+ try {
+ // 模拟配置
+ $this->mockConfig();
+
+ // 尝试创建Pay实例
+ $payModel = new Pay($this->siteId);
+
+ echo " ⚠️ 跳过实际关闭订单测试\n";
+ } catch (\Exception $e) {
+ echo " ⚠️ 关闭订单测试跳过: " . $e->getMessage() . "\n";
+ }
+ }
+
+ /**
+ * 测试退款方法
+ */
+ public function testRefundMethod()
+ {
+ echo "测试退款方法...";
+
+ try {
+ // 模拟配置
+ $this->mockConfig();
+
+ // 尝试创建Pay实例
+ $payModel = new Pay($this->siteId);
+
+ echo " ⚠️ 跳过实际退款测试\n";
+ } catch (\Exception $e) {
+ echo " ⚠️ 退款测试跳过: " . $e->getMessage() . "\n";
+ }
+ }
+
+ /**
+ * 测试查询订单方法
+ */
+ public function testQueryOrderMethod()
+ {
+ echo "测试查询订单方法...";
+
+ try {
+ // 模拟配置
+ $this->mockConfig();
+
+ // 尝试创建Pay实例
+ $payModel = new Pay($this->siteId);
+
+ echo " ⚠️ 跳过实际查询订单测试\n";
+ } catch (\Exception $e) {
+ echo " ⚠️ 查询订单测试跳过: " . $e->getMessage() . "\n";
+ }
+ }
+
+ /**
+ * 模拟配置
+ */
+ private function mockConfig()
+ {
+ // 在实际测试中,可以使用更高级的模拟技术
+ // 这里仅提供基础框架
+ }
+}
+
+// 如果直接运行此文件,则执行测试
+if (basename(__FILE__) == basename($_SERVER['PHP_SELF'])) {
+ $test = new PayModelTest();
+ $test->runTests();
+}
\ No newline at end of file
diff --git a/src/addon/huaweipay/tests/README.md b/src/addon/huaweipay/tests/README.md
new file mode 100644
index 000000000..51faf6898
--- /dev/null
+++ b/src/addon/huaweipay/tests/README.md
@@ -0,0 +1,10 @@
+# 测试
+
+由于不引入PHPUnit,所以测试用例只能手动执行。
+
+
+```bash
+cd src/
+php addon/huaweipay/tests/HuaweiPayClientTest.php
+php addon/huaweipay/tests/PayModelTest.php
+```
\ No newline at end of file
diff --git a/src/addon/manjian/api/controller/Manjian.php b/src/addon/manjian/api/controller/Manjian.php
index 9fb223122..5c3d2bc70 100644
--- a/src/addon/manjian/api/controller/Manjian.php
+++ b/src/addon/manjian/api/controller/Manjian.php
@@ -1,41 +1,33 @@
-params['goods_id'] ?? 0;
- if (!empty($id)) {
- $goods_id = $id;
- }
- if (empty($goods_id)) {
- return $this->response($this->error('', 'REQUEST_GOODS_ID'));
- }
- $manjian_model = new ManjianModel();
- $res = $manjian_model->getGoodsManjianInfo($goods_id, $this->site_id);
- return $this->response($res);
- }
-
+params['goods_id'] ?? 0;
+ if (!empty($id)) {
+ $goods_id = $id;
+ }
+ if (empty($goods_id)) {
+ return $this->response($this->error('', 'REQUEST_GOODS_ID'));
+ }
+ $manjian_model = new ManjianModel();
+ $res = $manjian_model->getGoodsManjianInfo($goods_id, $this->site_id);
+ return $this->response($res);
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/manjian/config/diy_view.php b/src/addon/manjian/config/diy_view.php
index c3c657905..e36ca9b7d 100644
--- a/src/addon/manjian/config/diy_view.php
+++ b/src/addon/manjian/config/diy_view.php
@@ -1,38 +1,30 @@
- '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
- 'template' => [],
-
- // 后台自定义组件——装修
- 'util' => [],
-
- // 自定义页面路径
- 'link' => [],
-
- // 自定义图标库
- 'icon_library' => [],
-
- // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
- 'component' => [],
-
- // uni-app 页面,多个逗号隔开
- 'pages' => [],
-
- // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
- 'info' => [],
-
- // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
- 'theme' => [],
-
- // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
- 'data' => []
+ '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
+ 'template' => [],
+
+ // 后台自定义组件——装修
+ 'util' => [],
+
+ // 自定义页面路径
+ 'link' => [],
+
+ // 自定义图标库
+ 'icon_library' => [],
+
+ // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
+ 'component' => [],
+
+ // uni-app 页面,多个逗号隔开
+ 'pages' => [],
+
+ // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
+ 'info' => [],
+
+ // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
+ 'theme' => [],
+
+ // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
+ 'data' => []
];
\ No newline at end of file
diff --git a/src/addon/manjian/config/info.php b/src/addon/manjian/config/info.php
index 6caa29b96..7016f5588 100644
--- a/src/addon/manjian/config/info.php
+++ b/src/addon/manjian/config/info.php
@@ -1,21 +1,12 @@
- 'manjian',
- 'title' => '满额立减',
- 'description' => '满额立减',
- 'type' => 'promotion', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
- 'status' => 1,
- 'author' => '',
- 'version' => '5.3.1',
- 'version_no' => '525231212001',
- 'content' => '',
+ 'manjian',
+ 'title' => '满额立减',
+ 'description' => '满额立减',
+ 'type' => 'promotion', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
+ 'status' => 1,
+ 'author' => '',
+ 'version' => '5.3.1',
+ 'version_no' => '525231212001',
+ 'content' => '',
];
\ No newline at end of file
diff --git a/src/addon/manjian/event/CloseManjian.php b/src/addon/manjian/event/CloseManjian.php
index 141ea9226..a5642516a 100644
--- a/src/addon/manjian/event/CloseManjian.php
+++ b/src/addon/manjian/event/CloseManjian.php
@@ -1,28 +1,19 @@
-cronCloseManjian($params['relate_id']);
- return $res;
- }
+cronCloseManjian($params['relate_id']);
+ return $res;
+ }
}
\ No newline at end of file
diff --git a/src/addon/manjian/event/Install.php b/src/addon/manjian/event/Install.php
index 81b63b7ac..73d2a0c9c 100644
--- a/src/addon/manjian/event/Install.php
+++ b/src/addon/manjian/event/Install.php
@@ -1,31 +1,22 @@
-getMessage());
- }
- }
+getMessage());
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/manjian/event/MemberAccountFromType.php b/src/addon/manjian/event/MemberAccountFromType.php
index edf20fb5c..4edae2ebd 100644
--- a/src/addon/manjian/event/MemberAccountFromType.php
+++ b/src/addon/manjian/event/MemberAccountFromType.php
@@ -1,37 +1,28 @@
- [
- 'manjian' => [
- 'type_name' => '满减送',
- 'type_url' => '',
- ],
- ]
- ];
- if ($data == '') {
- return $from_type;
- } else {
- return $from_type[$data] ?? [];
- }
-
- }
+ [
+ 'manjian' => [
+ 'type_name' => '满减送',
+ 'type_url' => '',
+ ],
+ ]
+ ];
+ if ($data == '') {
+ return $from_type;
+ } else {
+ return $from_type[$data] ?? [];
+ }
+
+ }
}
\ No newline at end of file
diff --git a/src/addon/manjian/event/OpenManjian.php b/src/addon/manjian/event/OpenManjian.php
index c0f7617a3..8578479e6 100644
--- a/src/addon/manjian/event/OpenManjian.php
+++ b/src/addon/manjian/event/OpenManjian.php
@@ -1,28 +1,19 @@
-cronOpenManjian($params['relate_id']);
- return $res;
- }
+cronOpenManjian($params['relate_id']);
+ return $res;
+ }
}
\ No newline at end of file
diff --git a/src/addon/manjian/event/OrderPayAfter.php b/src/addon/manjian/event/OrderPayAfter.php
index 021a9445f..3aadd0de6 100644
--- a/src/addon/manjian/event/OrderPayAfter.php
+++ b/src/addon/manjian/event/OrderPayAfter.php
@@ -1,28 +1,19 @@
-orderPay($params);
- }
+orderPay($params);
+ }
}
\ No newline at end of file
diff --git a/src/addon/manjian/event/OrderRefundAllFinish.php b/src/addon/manjian/event/OrderRefundAllFinish.php
index 09274518a..f050fa03a 100644
--- a/src/addon/manjian/event/OrderRefundAllFinish.php
+++ b/src/addon/manjian/event/OrderRefundAllFinish.php
@@ -1,70 +1,62 @@
- 0) {
- $order_id = $order_info['order_id'];
- $list = model('promotion_mansong_record')->getList([['order_id', '=', $order_id], ['status', '=', 1]]);
- if (!empty($list)) {
- $member_coupon_model = new MemberCoupon();
- foreach ($list as $item) {
- try {
- // 发放积分
- $point = $item[ 'point' ] ?? 0;
- if ($point > 0) {
- $member_account = new Memberaccount();
- $member_account->addMemberAccount($site_id, $member_id, AccountDict::point, -$point, 'point_cancel', $item[ 'manjian_id' ], '活动奖励取消');
- }
- // 发放优惠券
- $coupon = $item['coupon'] ?? '';
- $coupon_num = $item['coupon_num'] ?? '';
- if ($coupon && $coupon_num) {
- $coupon_list = explode(',', $coupon);
- $coupon_num = explode(',', $coupon_num);
- $coupon_data = [];
- foreach ($coupon_list as $k => $coupon_item) {
- $coupon_data[] = [
- 'coupon_type_id' => $coupon_item,
- 'num' => $coupon_num[ $k ] ?? 1
- ];
- }
- $member_coupon_model->cancelByPromotion([
- 'coupon_data' => $coupon_data,
- 'member_id' => $member_id,
- ]);
- }
- // 定义为收回奖励
- model('promotion_mansong_record')->update([ 'status' => 2 ], [ [ 'id', '=', $item[ 'id' ] ] ]);
- model('promotion_mansong_record')->commit();
- } catch (\Exception $e) {
- model('promotion_mansong_record')->rollback();
- }
- }
- }
- }
- }
+ 0) {
+ $order_id = $order_info['order_id'];
+ $list = model('promotion_mansong_record')->getList([['order_id', '=', $order_id], ['status', '=', 1]]);
+ if (!empty($list)) {
+ $member_coupon_model = new MemberCoupon();
+ foreach ($list as $item) {
+ try {
+ // 发放积分
+ $point = $item[ 'point' ] ?? 0;
+ if ($point > 0) {
+ $member_account = new Memberaccount();
+ $member_account->addMemberAccount($site_id, $member_id, AccountDict::point, -$point, 'point_cancel', $item[ 'manjian_id' ], '活动奖励取消');
+ }
+ // 发放优惠券
+ $coupon = $item['coupon'] ?? '';
+ $coupon_num = $item['coupon_num'] ?? '';
+ if ($coupon && $coupon_num) {
+ $coupon_list = explode(',', $coupon);
+ $coupon_num = explode(',', $coupon_num);
+ $coupon_data = [];
+ foreach ($coupon_list as $k => $coupon_item) {
+ $coupon_data[] = [
+ 'coupon_type_id' => $coupon_item,
+ 'num' => $coupon_num[ $k ] ?? 1
+ ];
+ }
+ $member_coupon_model->cancelByPromotion([
+ 'coupon_data' => $coupon_data,
+ 'member_id' => $member_id,
+ ]);
+ }
+ // 定义为收回奖励
+ model('promotion_mansong_record')->update([ 'status' => 2 ], [ [ 'id', '=', $item[ 'id' ] ] ]);
+ model('promotion_mansong_record')->commit();
+ } catch (\Exception $e) {
+ model('promotion_mansong_record')->rollback();
+ }
+ }
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/manjian/event/ShowPromotion.php b/src/addon/manjian/event/ShowPromotion.php
index d83ac04d9..dfa442010 100644
--- a/src/addon/manjian/event/ShowPromotion.php
+++ b/src/addon/manjian/event/ShowPromotion.php
@@ -1,90 +1,82 @@
- [
- [
- //插件名称
- 'name' => 'manjian',
- //店铺端展示分类 shop:营销活动 member:互动营销
- 'show_type' => 'shop',
- //展示主题
- 'title' => '满减活动',
- //展示介绍
- 'description' => '购满指定金额享受优惠',
- //展示图标
- 'icon' => 'addon/manjian/icon.png',
- //跳转链接
- 'url' => 'manjian://shop/manjian/lists',
- 'summary' => $this->summary($params)
- ]
- ]
-
- ];
- return $data;
- }
-
- /**
- * 营销活动概况
- * @param $params
- * @return array
- */
- private function summary($params)
- {
- if (empty($params)) {
- return [];
- }
-
- if(isset($params['promotion_type']) && $params['promotion_type'] != $this->promotion_type){
- return [];
- }
-
- //获取活动数量
- if (isset($params[ 'count' ])) {
- $count = model("promotion_manjian")->getCount([ [ 'site_id', '=', $params[ 'site_id' ] ] ]);
- return [
- 'count' => $count
- ];
- }
- //获取活动概况,需要获取开始时间与结束时间
- if (isset($params[ 'summary' ])) {
- $list = model("promotion_manjian")->getList([
- [ '', 'exp', Db::raw('not ( (`start_time` >= ' . $params[ 'end_time' ] . ') or (`end_time` <= ' . $params[ 'start_time' ] . '))') ],
- [ 'site_id', '=', $params[ 'site_id' ] ],
- [ 'status', '<>', -1 ]
- ], 'manjian_name as promotion_name,manjian_id as promotion_id,start_time,end_time');
- return !empty($list) ? [
- 'time_limit' => [
- 'count' => count($list),
- 'detail' => $list,
- 'color' => '#FFA666'
- ]
- ] : [];
- }
- }
+ [
+ [
+ //插件名称
+ 'name' => 'manjian',
+ //店铺端展示分类 shop:营销活动 member:互动营销
+ 'show_type' => 'shop',
+ //展示主题
+ 'title' => '满减活动',
+ //展示介绍
+ 'description' => '购满指定金额享受优惠',
+ //展示图标
+ 'icon' => 'addon/manjian/icon.png',
+ //跳转链接
+ 'url' => 'manjian://shop/manjian/lists',
+ 'summary' => $this->summary($params)
+ ]
+ ]
+
+ ];
+ return $data;
+ }
+
+ /**
+ * 营销活动概况
+ * @param $params
+ * @return array
+ */
+ private function summary($params)
+ {
+ if (empty($params)) {
+ return [];
+ }
+
+ if(isset($params['promotion_type']) && $params['promotion_type'] != $this->promotion_type){
+ return [];
+ }
+
+ //获取活动数量
+ if (isset($params[ 'count' ])) {
+ $count = model("promotion_manjian")->getCount([ [ 'site_id', '=', $params[ 'site_id' ] ] ]);
+ return [
+ 'count' => $count
+ ];
+ }
+ //获取活动概况,需要获取开始时间与结束时间
+ if (isset($params[ 'summary' ])) {
+ $list = model("promotion_manjian")->getList([
+ [ '', 'exp', Db::raw('not ( (`start_time` >= ' . $params[ 'end_time' ] . ') or (`end_time` <= ' . $params[ 'start_time' ] . '))') ],
+ [ 'site_id', '=', $params[ 'site_id' ] ],
+ [ 'status', '<>', -1 ]
+ ], 'manjian_name as promotion_name,manjian_id as promotion_id,start_time,end_time');
+ return !empty($list) ? [
+ 'time_limit' => [
+ 'count' => count($list),
+ 'detail' => $list,
+ 'color' => '#FFA666'
+ ]
+ ] : [];
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/manjian/event/UnInstall.php b/src/addon/manjian/event/UnInstall.php
index 07758f17b..659852122 100644
--- a/src/addon/manjian/event/UnInstall.php
+++ b/src/addon/manjian/event/UnInstall.php
@@ -1,31 +1,23 @@
-getMessage());
- }
- }
+getMessage());
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/manjian/model/Manjian.php b/src/addon/manjian/model/Manjian.php
index 82758e695..f767b04bc 100644
--- a/src/addon/manjian/model/Manjian.php
+++ b/src/addon/manjian/model/Manjian.php
@@ -1,509 +1,501 @@
- '未开始',
- 1 => '进行中',
- 2 => '已结束',
- -1 => '已关闭',
- ];
-
- public function getManjianStatus()
- {
- return $this->manjian_status;
- }
-
- /**
- * 添加满减
- * @param unknown $data
- */
- public function addManjian($data)
- {
- //时间检测
- if ($data[ 'end_time' ] < time()) {
- return $this->error('', '结束时间不能早于当前时间');
- }
- $condition = [
- [ 'status', 'in', "0,1" ],
- [ 'site_id', '=', $data[ 'site_id' ] ],
- [ 'manjian_type', '=', 1 ],
- [ '', 'exp', Db::raw('not ( (`start_time` > ' . $data[ 'end_time' ] . ' and `start_time` > ' . $data[ 'start_time' ] . ' ) or (`end_time` < ' . $data[ 'start_time' ] . ' and `end_time` < ' . $data[ 'end_time' ] . '))') ]
- ];
- $data['merch_id'] = $data['merch_id']??0;
- if($data['merch_id']){
- $condition[] = [ 'merch_id', '=', $data[ 'merch_id' ] ];
- }
- $manjian_activity_info = model('promotion_manjian')->getInfo($condition, 'manjian_name,start_time,end_time');
- if (!empty($manjian_activity_info)) {
- $key = 'manjian' . random_keys(8) . $data[ 'site_id' ];
- Cache::set($key, [ 'list' => [ $manjian_activity_info ], 'type' => 'activity', 'promotion' => '满减送', 'start_time' => $data[ 'start_time' ], 'end_time' => $data[ 'end_time' ] ], 3600);
- return $this->error([ 'key' => $key ], 'GOODS_EXIST_MANJIAN');
- }
-
- if ($data[ 'manjian_type' ] == 2) {
- $join = [
- [ 'promotion_manjian pm', 'pm.manjian_id = pmg.manjian_id', 'left' ],
- [ 'goods g', 'g.goods_id = pmg.goods_id', 'left' ]
- ];
-
- // 查询存在交集的满减活动商品
- $condition_bing = [
- [ 'pmg.status', 'in', "0,1" ],
- [ 'pmg.site_id', '=', $data[ 'site_id' ] ],
- [ 'pmg.goods_id', 'in', $data[ 'goods_ids' ] ],
- [ '', 'exp', Db::raw('not ( (pmg.start_time > ' . $data[ 'end_time' ] . ' and pmg.start_time > ' . $data[ 'start_time' ] . ' ) or (pmg.end_time < ' . $data[ 'start_time' ] . ' and pmg.end_time < ' . $data[ 'end_time' ] . '))') ]
- ];
- if($data['merch_id']){
- $condition_bing[] = [ 'pmg.merch_id', '=', $data[ 'merch_id' ] ];
- }
- $manjian_count = model('promotion_manjian_goods')->getList($condition_bing, 'pmg.start_time,pmg.end_time,pm.manjian_name,g.goods_name', '', 'pmg', $join);
- if (!empty($manjian_count)) {
- $key = 'manjian' . random_keys(8) . $data[ 'site_id' ];
- Cache::set($key, [ 'list' => $manjian_count, 'type' => 'goods', 'promotion' => '满减送', 'start_time' => $data[ 'start_time' ], 'end_time' => $data[ 'end_time' ] ], 3600);
- return $this->error([ 'key' => $key ], 'GOODS_EXIST_MANJIAN');
- }
- }
-
- $data[ 'create_time' ] = time();
- if ($data[ 'start_time' ] <= time()) {
- $data[ 'status' ] = 1;//直接启动
- } else {
- $data[ 'status' ] = 0;
- }
- $goods_ids_arr = $data[ 'goods_ids' ];
- $data[ 'goods_ids' ] = "," . $data[ 'goods_ids' ] . ",";
-
- model('promotion_manjian')->startTrans();
- try {
- $manjian_id = model('promotion_manjian')->add($data);
- if ($data[ 'manjian_type' ] != 1) {
- $goods_ids = explode(',', $goods_ids_arr);
- $goods_data = [];
- foreach ($goods_ids as $v) {
- $goods_data[] = [
- 'manjian_id' => $manjian_id,
- 'site_id' => $data['site_id'],
- 'goods_id' => $v,
- 'manjian_type' => $data['manjian_type'],
- 'status' => $data['status'],
- 'rule_json' => $data['rule_json'],
- 'start_time' => $data['start_time'],
- 'end_time' => $data['end_time']
- ];
- }
- model('promotion_manjian_goods')->addList($goods_data);
- }
-
- $cron = new Cron();
- if ($data[ 'start_time' ] <= time()) {
- $cron->addCron(1, 0, "满减关闭", "CloseManjian", $data[ 'end_time' ], $manjian_id);
- } else {
- $cron->addCron(1, 0, "满减开启", "OpenManjian", $data[ 'start_time' ], $manjian_id);
- $cron->addCron(1, 0, "满减关闭", "CloseManjian", $data[ 'end_time' ], $manjian_id);
- }
-
- model('promotion_manjian')->commit();
- return $this->success();
- } catch (\Exception $e) {
- model('promotion_manjian')->rollback();
- return $this->error('', $e->getMessage());
- }
-
- }
-
- /**
- * 修改满减
- * @param unknown $data
- * @return multitype:string
- */
- public function editManjian($data)
- {
- $manjian_id = $data[ 'manjian_id' ];
- unset($data[ 'manjian_id' ]);
-
- $condition = [
- [ [ 'site_id', '=', $data[ 'site_id' ] ], [ 'manjian_id', '=', $manjian_id ] ]
- ];
- if($data['merch_id']){
- $condition[] = [ 'merch_id', '=', $data[ 'merch_id' ] ];
- }
- $manjian_status = model('promotion_manjian')->getInfo($condition, 'status');
- if ($manjian_status[ 'status' ] != 0 && $manjian_status[ 'status' ] != 1) {
- return $this->error('', '只有未开始和进行中的满减活动才能进行修改');
- }
-
- //时间检测
- if ($data[ 'end_time' ] < time()) {
- return $this->error('', '结束时间不能早于当前时间');
- }
- $condition_activity_info = [
- [ 'status', 'in', "0,1" ],
- [ 'site_id', '=', $data[ 'site_id' ] ],
- [ 'manjian_type', '=', 1 ],
- [ 'manjian_id', '<>', $manjian_id ],
- [ '', 'exp', Db::raw('not ( (`start_time` > ' . $data[ 'end_time' ] . ' and `start_time` > ' . $data[ 'start_time' ] . ' ) or (`end_time` < ' . $data[ 'start_time' ] . ' and `end_time` < ' . $data[ 'end_time' ] . '))') ]
- ];
- if($data['merch_id']){
- $condition_activity_info[] = [ 'merch_id', '=', $data[ 'merch_id' ] ];
- }
- $manjian_activity_info = model('promotion_manjian')->getInfo($condition_activity_info,'manjian_name,start_time,end_time');
- if (!empty($manjian_activity_info)) {
- $key = 'manjian' . random_keys(8) . $data[ 'site_id' ];
- Cache::set($key, [ 'list' => [ $manjian_activity_info ], 'type' => 'activity', 'promotion' => '满减送', 'start_time' => $data[ 'start_time' ], 'end_time' => $data[ 'end_time' ] ], 3600);
- return $this->error([ 'key' => $key ], 'GOODS_EXIST_MANJIAN');
- }
-
- if ($data[ 'manjian_type' ] == 2) {
- $join = [
- [ 'promotion_manjian pm', 'pm.manjian_id = pmg.manjian_id', 'left' ],
- [ 'goods g', 'g.goods_id = pmg.goods_id', 'left' ]
- ];
- // 查询存在交集的满减活动商品
- $condition_jiao = [
- [ 'pmg.status', 'in', "0,1" ],
- [ 'pmg.site_id', '=', $data[ 'site_id' ] ],
- [ 'pmg.manjian_id', '<>', $manjian_id ],
- [ 'pmg.goods_id', 'in', $data[ 'goods_ids' ] ],
- [ '', 'exp', Db::raw('not ( (pmg.start_time > ' . $data[ 'end_time' ] . ' and pmg.start_time > ' . $data[ 'start_time' ] . ' ) or (pmg.end_time < ' . $data[ 'start_time' ] . ' and pmg.end_time < ' . $data[ 'end_time' ] . '))') ]
- ];
- if($data['merch_id']){
- $condition_bing[] = [ 'pmg.merch_id', '=', $data[ 'merch_id' ] ];
- }
- $manjian_goods_count = model('promotion_manjian_goods')->getList($condition_jiao, 'pmg.start_time,pmg.end_time,pm.manjian_name,g.goods_name', '', 'pmg', $join);
- if (!empty($manjian_goods_count)) {
- $key = 'manjian' . random_keys(8) . $data[ 'site_id' ];
- Cache::set($key, [ 'list' => $manjian_goods_count, 'type' => 'goods', 'promotion' => '满减送', 'start_time' => $data[ 'start_time' ], 'end_time' => $data[ 'end_time' ] ], 3600);
- return $this->error([ 'key' => $key ], 'GOODS_EXIST_MANJIAN');
- }
- }
-
- if ($data[ 'start_time' ] <= time()) {
- $data[ 'status' ] = 1;//直接启动
- } else {
- $data[ 'status' ] = 0;
- }
-
- model('promotion_manjian')->startTrans();
- try {
-
- $goods_ids_arr = $data[ 'goods_ids' ];
- $data[ 'goods_ids' ] = "," . $data[ 'goods_ids' ] . ",";
-
- model('promotion_manjian')->update($data, [ [ 'site_id', '=', $data[ 'site_id' ] ], [ 'manjian_id', '=', $manjian_id ] ]);
- model('promotion_manjian_goods')->delete([
- [ 'site_id', '=', $data[ 'site_id' ] ],
- [ 'manjian_id', '=', $manjian_id ]
- ]);
-
- if ($data[ 'manjian_type' ] != 1) {
- //获取商品id
- $goods_ids = explode(',', $goods_ids_arr);
- $goods_data = [];
- foreach ($goods_ids as $v) {
- $goods_data[] = [
- 'manjian_id' => $manjian_id,
- 'site_id' => $data['site_id'],
- 'goods_id' => $v,
- 'manjian_type' => $data['manjian_type'],
- 'status' => $data['status'],
- 'rule_json' => $data['rule_json'],
- 'start_time' => $data['start_time'],
- 'end_time' => $data['end_time']
- ];
- }
- model('promotion_manjian_goods')->addList($goods_data);
- }
-
- $cron = new Cron();
- $cron->deleteCron([ [ 'event', '=', 'CloseManjian' ], [ 'relate_id', '=', $manjian_id ] ]);
- $cron->deleteCron([ [ 'event', '=', 'OpenManjian' ], [ 'relate_id', '=', $manjian_id ] ]);
- if ($data[ 'start_time' ] <= time()) {
- $cron->addCron(1, 0, "满减关闭", "CloseManjian", $data[ 'end_time' ], $manjian_id);
- } else {
- $cron->addCron(1, 0, "满减开启", "OpenManjian", $data[ 'start_time' ], $manjian_id);
- $cron->addCron(1, 0, "满减关闭", "CloseManjian", $data[ 'end_time' ], $manjian_id);
- }
- model('promotion_manjian')->commit();
- return $this->success();
- } catch (\Exception $e) {
- model('promotion_manjian')->rollback();
- return $this->error('', $e->getMessage());
- }
- }
-
- /**
- * 删除满减
- * @param unknown $manjian_id
- */
- public function deleteManjian($manjian_id, $site_id)
- {
- $condition = [
- [ 'manjian_id', '=', $manjian_id ],
- [ 'site_id', '=', $site_id ]
- ];
- $res = model('promotion_manjian')->delete($condition);
- if ($res) {
- model('promotion_manjian_goods')->delete($condition);
- $cron = new Cron();
- $cron->deleteCron([ [ 'event', '=', 'OpenManjian' ], [ 'relate_id', '=', $manjian_id ] ]);
- $cron->deleteCron([ [ 'event', '=', 'CloseManjian' ], [ 'relate_id', '=', $manjian_id ] ]);
- return $this->success($res);
- } else {
- return $this->error();
- }
- }
-
- /**
- * 获取满减信息
- * @param array $condition
- * @param string $field
- */
- public function getManjianInfo($condition, $field = '*')
- {
- $res = model('promotion_manjian')->getInfo($condition, $field);
- return $this->success($res);
- }
-
- /**
- * 满减详情
- * @param $manjian_id
- * @param $site_id
- * @param string $field
- * @return array
- */
- public function getManjianDetail($manjian_id, $site_id, $field = '*')
- {
- $res = model('promotion_manjian')->getInfo([ [ 'manjian_id', '=', $manjian_id ], [ 'site_id', '=', $site_id ] ], $field);
- if (!empty($res)) {
- //获取商品信息
- if ($res[ 'manjian_type' ] == 2) {//指定商品
- $field = 'g.goods_id,g.goods_name,g.goods_stock,g.price,g.goods_image';
- $alias = 'mg';
- $join = [
- [
- 'goods g',
- 'g.goods_id = mg.goods_id',
- 'inner'
- ]
- ];
-
- $goods_list = model('promotion_manjian_goods')->getList([ [ 'mg.manjian_id', '=', $manjian_id ], [ 'mg.site_id', '=', $site_id ] ], $field, '', $alias, $join);
- }
-
- if (isset($res[ 'rule_json' ])) {
- $rule = json_decode($res[ 'rule_json' ], true);
- foreach ($rule as $key => $item) {
- if (isset($item[ 'coupon' ]) && !empty($item[ 'coupon' ])) {
- $coupon = model('promotion_coupon_type')->getList([ [ 'coupon_type_id', 'in', $item[ 'coupon' ] ] ], 'coupon_type_id,coupon_name,type,at_least,money,discount');
- $rule[ $key ][ 'coupon_data' ] = $coupon;
- $rule[ $key ][ 'coupon_num' ] = explode(',', $item[ 'coupon_num' ]);
- }
- }
- $res[ 'rule' ] = $rule;
- }
- $res[ 'goods_list' ] = $goods_list ?? [];
- $res[ 'goods_list_count' ] = count($res[ 'goods_list' ]);
- }
- return $this->success($res);
- }
-
- /**
- * 获取满减列表
- * @param array $condition
- * @param string $field
- * @param string $order
- * @param string $limit
- */
- public function getManjianList($condition = [], $field = '*', $order = 'manjian_id desc', $limit = null)
- {
- $list = model('promotion_manjian')->getList($condition, $field, $order, '', '', '', $limit);
- return $this->success($list);
- }
-
- /**
- * 获取满减列表
- * @param array $condition
- * @param string $field
- * @param string $order
- * @param string $limit
- */
- public function getManjianGoodsList($condition = [], $field = '', $order = 'id desc', $limit = null)
- {
- $list = model('promotion_manjian_goods')->getList($condition, $field, $order, '', '', '', $limit);
- return $this->success($list);
- }
-
- /**
- * 获取最新一条商品满减活动
- * @param int $goods_id
- * @param int $site_id
- */
- public function getGoodsManjianInfo($goods_id, $site_id)
- {
- $condition = [
- [ 'site_id', '=', $site_id ],
- [ 'status', '=', 1 ],
- [ 'end_time', '>', time() ],
- [ 'manjian_type', '=', 1 ]
- ];
- $first_info = model('promotion_manjian')->getFirstData($condition, 'manjian_id,site_id,manjian_name,manjian_type,type,goods_ids,status,start_time,end_time,rule_json', 'create_time desc');
- if (empty($first_info)) {
- $condition = [
- [ 'site_id', '=', $site_id ],
- [ 'status', '=', 1 ],
- [ 'end_time', '>', time() ],
- [ 'manjian_type', '=', 2 ],
- [ 'goods_ids', 'like', [ '%,' . $goods_id . ',%', '' ], 'or' ]
- ];
- $first_info = model('promotion_manjian')->getFirstData($condition, 'manjian_id,site_id,manjian_name,manjian_type,type,goods_ids,status,start_time,end_time,rule_json', 'create_time desc');
- }
- if (!empty($first_info)) {
- $rule = json_decode($first_info[ 'rule_json' ], true);
- foreach ($rule as $key => $item) {
- if (isset($item[ 'coupon' ]) && !empty($item[ 'coupon' ])) {
- $coupon = model('promotion_coupon_type')->getList([ [ 'coupon_type_id', 'in', $item[ 'coupon' ] ] ], 'coupon_name,type,at_least,money,discount');
- $rule[ $key ][ 'coupon_num' ] = empty($item[ 'coupon_num' ]) ? [ 1 ] : explode(',', $item[ 'coupon_num' ]);
- $rule[ $key ][ 'coupon_data' ] = $coupon;
- }
- }
- $first_info[ 'rule_json' ] = $rule;
- }
-
- return $this->success($first_info);
- }
-
- /**
- * 获取满减分页列表
- * @param array $condition
- * @param number $page
- * @param string $page_size
- * @param string $order
- * @param string $field
- */
- public function getManjianPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
- {
- $list = model('promotion_manjian')->pageList($condition, $field, $order, $page, $page_size);
- return $this->success($list);
- }
-
- /**
- * 启动满减
- * @param unknown $manjian_id
- */
- public function cronOpenManjian($manjian_id)
- {
- $manjian_info = model('promotion_manjian')->getInfo([ [ 'manjian_id', '=', $manjian_id ] ], 'start_time,status');
- if (!empty($manjian_info)) {
- if ($manjian_info[ 'start_time' ] <= time() && $manjian_info[ 'status' ] == 0) {
- model('promotion_manjian')->startTrans();
- try {
- model('promotion_manjian')->update([ 'status' => 1 ], [ [ 'manjian_id', '=', $manjian_id ] ]);
- model('promotion_manjian_goods')->update([ 'status' => 1 ], [ [ 'manjian_id', '=', $manjian_id ] ]);
- model('promotion_manjian')->commit();
- return $this->success();
- } catch (\Exception $e) {
- model('promotion_manjian')->rollback();
- return $this->error('', $e->getMessage());
- }
- } else {
- return $this->error("", "满减活动已开启或者关闭");
- }
- } else {
- return $this->error("", "满减活动不存在");
- }
- }
-
- /**
- * 结束满减 自动事件
- * @param unknown $manjian_id
- */
- public function cronCloseManjian($manjian_id)
- {
- $manjian_info = model('promotion_manjian')->getInfo([ [ 'manjian_id', '=', $manjian_id ] ], 'end_time,status');
- if (!empty($manjian_info)) {
- if ($manjian_info[ 'end_time' ] <= time() && $manjian_info[ 'status' ] == 1) {
- model('promotion_manjian')->startTrans();
- try {
-
- model('promotion_manjian')->update([ 'status' => 2 ], [ [ 'manjian_id', '=', $manjian_id ] ]);
- model('promotion_manjian_goods')->update([ 'status' => 2 ], [ [ 'manjian_id', '=', $manjian_id ] ]);
-
- model('promotion_manjian')->commit();
- return $this->success();
- } catch (\Exception $e) {
-
- model('promotion_manjian')->rollback();
- return $this->error('', $e->getMessage());
- }
-
- } else {
- return $this->error("", "满减活动已关闭");
- }
- } else {
- return $this->error("", "满减活动不存在");
- }
- }
-
- /**
- * 关闭满减 手动关闭
- * @param unknown $manjian_id
- */
- public function closeManjian($manjian_id, $site_id)
- {
- $condition = array (
- [ 'manjian_id', '=', $manjian_id ],
- [ 'site_id', "=", $site_id ]
- );
- $manjian_info = model('promotion_manjian')->getInfo($condition, 'start_time,end_time,status');
- if (!empty($manjian_info)) {
- if ($manjian_info[ 'status' ] == 1) {
-
- if ($manjian_info[ 'status' ] == 1) {
-
- model('promotion_manjian')->startTrans();
- try {
-
- model('promotion_manjian')->update([ 'status' => -1 ], [ [ 'manjian_id', '=', $manjian_id ], [ 'site_id', "=", $site_id ] ]);
- model('promotion_manjian_goods')->update([ 'status' => -1 ], [ [ 'manjian_id', '=', $manjian_id ], [ 'site_id', "=", $site_id ] ]);
-
- model('promotion_manjian')->commit();
- return $this->success();
- } catch (\Exception $e) {
-
- model('promotion_manjian')->rollback();
- return $this->error('', $e->getMessage());
- }
-
- } else {
- return $this->error("", "满减活动已关闭");
- }
-
- } else {
- return $this->error("", "满减活动已关闭");
- }
- } else {
- return $this->error("", "满减活动不存在");
- }
- }
-
+ '未开始',
+ 1 => '进行中',
+ 2 => '已结束',
+ -1 => '已关闭',
+ ];
+
+ public function getManjianStatus()
+ {
+ return $this->manjian_status;
+ }
+
+ /**
+ * 添加满减
+ * @param unknown $data
+ */
+ public function addManjian($data)
+ {
+ //时间检测
+ if ($data[ 'end_time' ] < time()) {
+ return $this->error('', '结束时间不能早于当前时间');
+ }
+ $condition = [
+ [ 'status', 'in', "0,1" ],
+ [ 'site_id', '=', $data[ 'site_id' ] ],
+ [ 'manjian_type', '=', 1 ],
+ [ '', 'exp', Db::raw('not ( (`start_time` > ' . $data[ 'end_time' ] . ' and `start_time` > ' . $data[ 'start_time' ] . ' ) or (`end_time` < ' . $data[ 'start_time' ] . ' and `end_time` < ' . $data[ 'end_time' ] . '))') ]
+ ];
+ $data['merch_id'] = $data['merch_id']??0;
+ if($data['merch_id']){
+ $condition[] = [ 'merch_id', '=', $data[ 'merch_id' ] ];
+ }
+ $manjian_activity_info = model('promotion_manjian')->getInfo($condition, 'manjian_name,start_time,end_time');
+ if (!empty($manjian_activity_info)) {
+ $key = 'manjian' . random_keys(8) . $data[ 'site_id' ];
+ Cache::set($key, [ 'list' => [ $manjian_activity_info ], 'type' => 'activity', 'promotion' => '满减送', 'start_time' => $data[ 'start_time' ], 'end_time' => $data[ 'end_time' ] ], 3600);
+ return $this->error([ 'key' => $key ], 'GOODS_EXIST_MANJIAN');
+ }
+
+ if ($data[ 'manjian_type' ] == 2) {
+ $join = [
+ [ 'promotion_manjian pm', 'pm.manjian_id = pmg.manjian_id', 'left' ],
+ [ 'goods g', 'g.goods_id = pmg.goods_id', 'left' ]
+ ];
+
+ // 查询存在交集的满减活动商品
+ $condition_bing = [
+ [ 'pmg.status', 'in', "0,1" ],
+ [ 'pmg.site_id', '=', $data[ 'site_id' ] ],
+ [ 'pmg.goods_id', 'in', $data[ 'goods_ids' ] ],
+ [ '', 'exp', Db::raw('not ( (pmg.start_time > ' . $data[ 'end_time' ] . ' and pmg.start_time > ' . $data[ 'start_time' ] . ' ) or (pmg.end_time < ' . $data[ 'start_time' ] . ' and pmg.end_time < ' . $data[ 'end_time' ] . '))') ]
+ ];
+ if($data['merch_id']){
+ $condition_bing[] = [ 'pmg.merch_id', '=', $data[ 'merch_id' ] ];
+ }
+ $manjian_count = model('promotion_manjian_goods')->getList($condition_bing, 'pmg.start_time,pmg.end_time,pm.manjian_name,g.goods_name', '', 'pmg', $join);
+ if (!empty($manjian_count)) {
+ $key = 'manjian' . random_keys(8) . $data[ 'site_id' ];
+ Cache::set($key, [ 'list' => $manjian_count, 'type' => 'goods', 'promotion' => '满减送', 'start_time' => $data[ 'start_time' ], 'end_time' => $data[ 'end_time' ] ], 3600);
+ return $this->error([ 'key' => $key ], 'GOODS_EXIST_MANJIAN');
+ }
+ }
+
+ $data[ 'create_time' ] = time();
+ if ($data[ 'start_time' ] <= time()) {
+ $data[ 'status' ] = 1;//直接启动
+ } else {
+ $data[ 'status' ] = 0;
+ }
+ $goods_ids_arr = $data[ 'goods_ids' ];
+ $data[ 'goods_ids' ] = "," . $data[ 'goods_ids' ] . ",";
+
+ model('promotion_manjian')->startTrans();
+ try {
+ $manjian_id = model('promotion_manjian')->add($data);
+ if ($data[ 'manjian_type' ] != 1) {
+ $goods_ids = explode(',', $goods_ids_arr);
+ $goods_data = [];
+ foreach ($goods_ids as $v) {
+ $goods_data[] = [
+ 'manjian_id' => $manjian_id,
+ 'site_id' => $data['site_id'],
+ 'goods_id' => $v,
+ 'manjian_type' => $data['manjian_type'],
+ 'status' => $data['status'],
+ 'rule_json' => $data['rule_json'],
+ 'start_time' => $data['start_time'],
+ 'end_time' => $data['end_time']
+ ];
+ }
+ model('promotion_manjian_goods')->addList($goods_data);
+ }
+
+ $cron = new Cron();
+ if ($data[ 'start_time' ] <= time()) {
+ $cron->addCron(1, 0, "满减关闭", "CloseManjian", $data[ 'end_time' ], $manjian_id);
+ } else {
+ $cron->addCron(1, 0, "满减开启", "OpenManjian", $data[ 'start_time' ], $manjian_id);
+ $cron->addCron(1, 0, "满减关闭", "CloseManjian", $data[ 'end_time' ], $manjian_id);
+ }
+
+ model('promotion_manjian')->commit();
+ return $this->success();
+ } catch (\Exception $e) {
+ model('promotion_manjian')->rollback();
+ return $this->error('', $e->getMessage());
+ }
+
+ }
+
+ /**
+ * 修改满减
+ * @param unknown $data
+ * @return multitype:string
+ */
+ public function editManjian($data)
+ {
+ $manjian_id = $data[ 'manjian_id' ];
+ unset($data[ 'manjian_id' ]);
+
+ $condition = [
+ [ [ 'site_id', '=', $data[ 'site_id' ] ], [ 'manjian_id', '=', $manjian_id ] ]
+ ];
+ if($data['merch_id']){
+ $condition[] = [ 'merch_id', '=', $data[ 'merch_id' ] ];
+ }
+ $manjian_status = model('promotion_manjian')->getInfo($condition, 'status');
+ if ($manjian_status[ 'status' ] != 0 && $manjian_status[ 'status' ] != 1) {
+ return $this->error('', '只有未开始和进行中的满减活动才能进行修改');
+ }
+
+ //时间检测
+ if ($data[ 'end_time' ] < time()) {
+ return $this->error('', '结束时间不能早于当前时间');
+ }
+ $condition_activity_info = [
+ [ 'status', 'in', "0,1" ],
+ [ 'site_id', '=', $data[ 'site_id' ] ],
+ [ 'manjian_type', '=', 1 ],
+ [ 'manjian_id', '<>', $manjian_id ],
+ [ '', 'exp', Db::raw('not ( (`start_time` > ' . $data[ 'end_time' ] . ' and `start_time` > ' . $data[ 'start_time' ] . ' ) or (`end_time` < ' . $data[ 'start_time' ] . ' and `end_time` < ' . $data[ 'end_time' ] . '))') ]
+ ];
+ if($data['merch_id']){
+ $condition_activity_info[] = [ 'merch_id', '=', $data[ 'merch_id' ] ];
+ }
+ $manjian_activity_info = model('promotion_manjian')->getInfo($condition_activity_info,'manjian_name,start_time,end_time');
+ if (!empty($manjian_activity_info)) {
+ $key = 'manjian' . random_keys(8) . $data[ 'site_id' ];
+ Cache::set($key, [ 'list' => [ $manjian_activity_info ], 'type' => 'activity', 'promotion' => '满减送', 'start_time' => $data[ 'start_time' ], 'end_time' => $data[ 'end_time' ] ], 3600);
+ return $this->error([ 'key' => $key ], 'GOODS_EXIST_MANJIAN');
+ }
+
+ if ($data[ 'manjian_type' ] == 2) {
+ $join = [
+ [ 'promotion_manjian pm', 'pm.manjian_id = pmg.manjian_id', 'left' ],
+ [ 'goods g', 'g.goods_id = pmg.goods_id', 'left' ]
+ ];
+ // 查询存在交集的满减活动商品
+ $condition_jiao = [
+ [ 'pmg.status', 'in', "0,1" ],
+ [ 'pmg.site_id', '=', $data[ 'site_id' ] ],
+ [ 'pmg.manjian_id', '<>', $manjian_id ],
+ [ 'pmg.goods_id', 'in', $data[ 'goods_ids' ] ],
+ [ '', 'exp', Db::raw('not ( (pmg.start_time > ' . $data[ 'end_time' ] . ' and pmg.start_time > ' . $data[ 'start_time' ] . ' ) or (pmg.end_time < ' . $data[ 'start_time' ] . ' and pmg.end_time < ' . $data[ 'end_time' ] . '))') ]
+ ];
+ if($data['merch_id']){
+ $condition_bing[] = [ 'pmg.merch_id', '=', $data[ 'merch_id' ] ];
+ }
+ $manjian_goods_count = model('promotion_manjian_goods')->getList($condition_jiao, 'pmg.start_time,pmg.end_time,pm.manjian_name,g.goods_name', '', 'pmg', $join);
+ if (!empty($manjian_goods_count)) {
+ $key = 'manjian' . random_keys(8) . $data[ 'site_id' ];
+ Cache::set($key, [ 'list' => $manjian_goods_count, 'type' => 'goods', 'promotion' => '满减送', 'start_time' => $data[ 'start_time' ], 'end_time' => $data[ 'end_time' ] ], 3600);
+ return $this->error([ 'key' => $key ], 'GOODS_EXIST_MANJIAN');
+ }
+ }
+
+ if ($data[ 'start_time' ] <= time()) {
+ $data[ 'status' ] = 1;//直接启动
+ } else {
+ $data[ 'status' ] = 0;
+ }
+
+ model('promotion_manjian')->startTrans();
+ try {
+
+ $goods_ids_arr = $data[ 'goods_ids' ];
+ $data[ 'goods_ids' ] = "," . $data[ 'goods_ids' ] . ",";
+
+ model('promotion_manjian')->update($data, [ [ 'site_id', '=', $data[ 'site_id' ] ], [ 'manjian_id', '=', $manjian_id ] ]);
+ model('promotion_manjian_goods')->delete([
+ [ 'site_id', '=', $data[ 'site_id' ] ],
+ [ 'manjian_id', '=', $manjian_id ]
+ ]);
+
+ if ($data[ 'manjian_type' ] != 1) {
+ //获取商品id
+ $goods_ids = explode(',', $goods_ids_arr);
+ $goods_data = [];
+ foreach ($goods_ids as $v) {
+ $goods_data[] = [
+ 'manjian_id' => $manjian_id,
+ 'site_id' => $data['site_id'],
+ 'goods_id' => $v,
+ 'manjian_type' => $data['manjian_type'],
+ 'status' => $data['status'],
+ 'rule_json' => $data['rule_json'],
+ 'start_time' => $data['start_time'],
+ 'end_time' => $data['end_time']
+ ];
+ }
+ model('promotion_manjian_goods')->addList($goods_data);
+ }
+
+ $cron = new Cron();
+ $cron->deleteCron([ [ 'event', '=', 'CloseManjian' ], [ 'relate_id', '=', $manjian_id ] ]);
+ $cron->deleteCron([ [ 'event', '=', 'OpenManjian' ], [ 'relate_id', '=', $manjian_id ] ]);
+ if ($data[ 'start_time' ] <= time()) {
+ $cron->addCron(1, 0, "满减关闭", "CloseManjian", $data[ 'end_time' ], $manjian_id);
+ } else {
+ $cron->addCron(1, 0, "满减开启", "OpenManjian", $data[ 'start_time' ], $manjian_id);
+ $cron->addCron(1, 0, "满减关闭", "CloseManjian", $data[ 'end_time' ], $manjian_id);
+ }
+ model('promotion_manjian')->commit();
+ return $this->success();
+ } catch (\Exception $e) {
+ model('promotion_manjian')->rollback();
+ return $this->error('', $e->getMessage());
+ }
+ }
+
+ /**
+ * 删除满减
+ * @param unknown $manjian_id
+ */
+ public function deleteManjian($manjian_id, $site_id)
+ {
+ $condition = [
+ [ 'manjian_id', '=', $manjian_id ],
+ [ 'site_id', '=', $site_id ]
+ ];
+ $res = model('promotion_manjian')->delete($condition);
+ if ($res) {
+ model('promotion_manjian_goods')->delete($condition);
+ $cron = new Cron();
+ $cron->deleteCron([ [ 'event', '=', 'OpenManjian' ], [ 'relate_id', '=', $manjian_id ] ]);
+ $cron->deleteCron([ [ 'event', '=', 'CloseManjian' ], [ 'relate_id', '=', $manjian_id ] ]);
+ return $this->success($res);
+ } else {
+ return $this->error();
+ }
+ }
+
+ /**
+ * 获取满减信息
+ * @param array $condition
+ * @param string $field
+ */
+ public function getManjianInfo($condition, $field = '*')
+ {
+ $res = model('promotion_manjian')->getInfo($condition, $field);
+ return $this->success($res);
+ }
+
+ /**
+ * 满减详情
+ * @param $manjian_id
+ * @param $site_id
+ * @param string $field
+ * @return array
+ */
+ public function getManjianDetail($manjian_id, $site_id, $field = '*')
+ {
+ $res = model('promotion_manjian')->getInfo([ [ 'manjian_id', '=', $manjian_id ], [ 'site_id', '=', $site_id ] ], $field);
+ if (!empty($res)) {
+ //获取商品信息
+ if ($res[ 'manjian_type' ] == 2) {//指定商品
+ $field = 'g.goods_id,g.goods_name,g.goods_stock,g.price,g.goods_image';
+ $alias = 'mg';
+ $join = [
+ [
+ 'goods g',
+ 'g.goods_id = mg.goods_id',
+ 'inner'
+ ]
+ ];
+
+ $goods_list = model('promotion_manjian_goods')->getList([ [ 'mg.manjian_id', '=', $manjian_id ], [ 'mg.site_id', '=', $site_id ] ], $field, '', $alias, $join);
+ }
+
+ if (isset($res[ 'rule_json' ])) {
+ $rule = json_decode($res[ 'rule_json' ], true);
+ foreach ($rule as $key => $item) {
+ if (isset($item[ 'coupon' ]) && !empty($item[ 'coupon' ])) {
+ $coupon = model('promotion_coupon_type')->getList([ [ 'coupon_type_id', 'in', $item[ 'coupon' ] ] ], 'coupon_type_id,coupon_name,type,at_least,money,discount');
+ $rule[ $key ][ 'coupon_data' ] = $coupon;
+ $rule[ $key ][ 'coupon_num' ] = explode(',', $item[ 'coupon_num' ]);
+ }
+ }
+ $res[ 'rule' ] = $rule;
+ }
+ $res[ 'goods_list' ] = $goods_list ?? [];
+ $res[ 'goods_list_count' ] = count($res[ 'goods_list' ]);
+ }
+ return $this->success($res);
+ }
+
+ /**
+ * 获取满减列表
+ * @param array $condition
+ * @param string $field
+ * @param string $order
+ * @param string $limit
+ */
+ public function getManjianList($condition = [], $field = '*', $order = 'manjian_id desc', $limit = null)
+ {
+ $list = model('promotion_manjian')->getList($condition, $field, $order, '', '', '', $limit);
+ return $this->success($list);
+ }
+
+ /**
+ * 获取满减列表
+ * @param array $condition
+ * @param string $field
+ * @param string $order
+ * @param string $limit
+ */
+ public function getManjianGoodsList($condition = [], $field = '', $order = 'id desc', $limit = null)
+ {
+ $list = model('promotion_manjian_goods')->getList($condition, $field, $order, '', '', '', $limit);
+ return $this->success($list);
+ }
+
+ /**
+ * 获取最新一条商品满减活动
+ * @param int $goods_id
+ * @param int $site_id
+ */
+ public function getGoodsManjianInfo($goods_id, $site_id)
+ {
+ $condition = [
+ [ 'site_id', '=', $site_id ],
+ [ 'status', '=', 1 ],
+ [ 'end_time', '>', time() ],
+ [ 'manjian_type', '=', 1 ]
+ ];
+ $first_info = model('promotion_manjian')->getFirstData($condition, 'manjian_id,site_id,manjian_name,manjian_type,type,goods_ids,status,start_time,end_time,rule_json', 'create_time desc');
+ if (empty($first_info)) {
+ $condition = [
+ [ 'site_id', '=', $site_id ],
+ [ 'status', '=', 1 ],
+ [ 'end_time', '>', time() ],
+ [ 'manjian_type', '=', 2 ],
+ [ 'goods_ids', 'like', [ '%,' . $goods_id . ',%', '' ], 'or' ]
+ ];
+ $first_info = model('promotion_manjian')->getFirstData($condition, 'manjian_id,site_id,manjian_name,manjian_type,type,goods_ids,status,start_time,end_time,rule_json', 'create_time desc');
+ }
+ if (!empty($first_info)) {
+ $rule = json_decode($first_info[ 'rule_json' ], true);
+ foreach ($rule as $key => $item) {
+ if (isset($item[ 'coupon' ]) && !empty($item[ 'coupon' ])) {
+ $coupon = model('promotion_coupon_type')->getList([ [ 'coupon_type_id', 'in', $item[ 'coupon' ] ] ], 'coupon_name,type,at_least,money,discount');
+ $rule[ $key ][ 'coupon_num' ] = empty($item[ 'coupon_num' ]) ? [ 1 ] : explode(',', $item[ 'coupon_num' ]);
+ $rule[ $key ][ 'coupon_data' ] = $coupon;
+ }
+ }
+ $first_info[ 'rule_json' ] = $rule;
+ }
+
+ return $this->success($first_info);
+ }
+
+ /**
+ * 获取满减分页列表
+ * @param array $condition
+ * @param number $page
+ * @param string $page_size
+ * @param string $order
+ * @param string $field
+ */
+ public function getManjianPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
+ {
+ $list = model('promotion_manjian')->pageList($condition, $field, $order, $page, $page_size);
+ return $this->success($list);
+ }
+
+ /**
+ * 启动满减
+ * @param unknown $manjian_id
+ */
+ public function cronOpenManjian($manjian_id)
+ {
+ $manjian_info = model('promotion_manjian')->getInfo([ [ 'manjian_id', '=', $manjian_id ] ], 'start_time,status');
+ if (!empty($manjian_info)) {
+ if ($manjian_info[ 'start_time' ] <= time() && $manjian_info[ 'status' ] == 0) {
+ model('promotion_manjian')->startTrans();
+ try {
+ model('promotion_manjian')->update([ 'status' => 1 ], [ [ 'manjian_id', '=', $manjian_id ] ]);
+ model('promotion_manjian_goods')->update([ 'status' => 1 ], [ [ 'manjian_id', '=', $manjian_id ] ]);
+ model('promotion_manjian')->commit();
+ return $this->success();
+ } catch (\Exception $e) {
+ model('promotion_manjian')->rollback();
+ return $this->error('', $e->getMessage());
+ }
+ } else {
+ return $this->error("", "满减活动已开启或者关闭");
+ }
+ } else {
+ return $this->error("", "满减活动不存在");
+ }
+ }
+
+ /**
+ * 结束满减 自动事件
+ * @param unknown $manjian_id
+ */
+ public function cronCloseManjian($manjian_id)
+ {
+ $manjian_info = model('promotion_manjian')->getInfo([ [ 'manjian_id', '=', $manjian_id ] ], 'end_time,status');
+ if (!empty($manjian_info)) {
+ if ($manjian_info[ 'end_time' ] <= time() && $manjian_info[ 'status' ] == 1) {
+ model('promotion_manjian')->startTrans();
+ try {
+
+ model('promotion_manjian')->update([ 'status' => 2 ], [ [ 'manjian_id', '=', $manjian_id ] ]);
+ model('promotion_manjian_goods')->update([ 'status' => 2 ], [ [ 'manjian_id', '=', $manjian_id ] ]);
+
+ model('promotion_manjian')->commit();
+ return $this->success();
+ } catch (\Exception $e) {
+
+ model('promotion_manjian')->rollback();
+ return $this->error('', $e->getMessage());
+ }
+
+ } else {
+ return $this->error("", "满减活动已关闭");
+ }
+ } else {
+ return $this->error("", "满减活动不存在");
+ }
+ }
+
+ /**
+ * 关闭满减 手动关闭
+ * @param unknown $manjian_id
+ */
+ public function closeManjian($manjian_id, $site_id)
+ {
+ $condition = array (
+ [ 'manjian_id', '=', $manjian_id ],
+ [ 'site_id', "=", $site_id ]
+ );
+ $manjian_info = model('promotion_manjian')->getInfo($condition, 'start_time,end_time,status');
+ if (!empty($manjian_info)) {
+ if ($manjian_info[ 'status' ] == 1) {
+
+ if ($manjian_info[ 'status' ] == 1) {
+
+ model('promotion_manjian')->startTrans();
+ try {
+
+ model('promotion_manjian')->update([ 'status' => -1 ], [ [ 'manjian_id', '=', $manjian_id ], [ 'site_id', "=", $site_id ] ]);
+ model('promotion_manjian_goods')->update([ 'status' => -1 ], [ [ 'manjian_id', '=', $manjian_id ], [ 'site_id', "=", $site_id ] ]);
+
+ model('promotion_manjian')->commit();
+ return $this->success();
+ } catch (\Exception $e) {
+
+ model('promotion_manjian')->rollback();
+ return $this->error('', $e->getMessage());
+ }
+
+ } else {
+ return $this->error("", "满减活动已关闭");
+ }
+
+ } else {
+ return $this->error("", "满减活动已关闭");
+ }
+ } else {
+ return $this->error("", "满减活动不存在");
+ }
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/manjian/model/Order.php b/src/addon/manjian/model/Order.php
index 532227973..bce8d3390 100644
--- a/src/addon/manjian/model/Order.php
+++ b/src/addon/manjian/model/Order.php
@@ -1,69 +1,61 @@
- 0) {
- $mansong_record = model('promotion_mansong_record')->getList([ [ 'order_id', '=', $order_id ], [ 'status', '=', 0 ] ]);
- if (!empty($mansong_record)) {
- model('promotion_mansong_record')->startTrans();
- foreach ($mansong_record as $item) {
- try {
- // 发放积分
- if (!empty($item[ 'point' ])) {
- $member_account = new Memberaccount();
- $member_account->addMemberAccount($item[ 'site_id' ], $item[ 'member_id' ], 'point', $item[ 'point' ], 'manjian', $item[ 'manjian_id' ], "活动奖励发放");
- }
- // 发放优惠券
- if (!empty($item[ 'coupon' ])) {
- $coupon = new Coupon();
- $coupon_list = explode(',', $item[ 'coupon' ]);
- $coupon_num = explode(',', $item[ 'coupon_num' ]);
- $coupon_data = [];
- foreach ($coupon_list as $k => $coupon_item) {
- $coupon_data[] = [
- 'coupon_type_id' => $coupon_item,
- 'num' => $coupon_num[ $k ] ?? 1
- ];
- }
- $coupon->giveCoupon($coupon_data, $item[ 'site_id' ], $item[ 'member_id' ], 6, $item['id'], 0, 0);
- }
- // 变更发放状态
- model('promotion_mansong_record')->update([ 'status' => 1 ], [ [ 'id', '=', $item[ 'id' ] ] ]);
- model('promotion_mansong_record')->commit();
- } catch (\Exception $e) {
- model('promotion_mansong_record')->rollback();
- }
- }
- }
- }
- }
- }
+ 0) {
+ $mansong_record = model('promotion_mansong_record')->getList([ [ 'order_id', '=', $order_id ], [ 'status', '=', 0 ] ]);
+ if (!empty($mansong_record)) {
+ model('promotion_mansong_record')->startTrans();
+ foreach ($mansong_record as $item) {
+ try {
+ // 发放积分
+ if (!empty($item[ 'point' ])) {
+ $member_account = new Memberaccount();
+ $member_account->addMemberAccount($item[ 'site_id' ], $item[ 'member_id' ], 'point', $item[ 'point' ], 'manjian', $item[ 'manjian_id' ], "活动奖励发放");
+ }
+ // 发放优惠券
+ if (!empty($item[ 'coupon' ])) {
+ $coupon = new Coupon();
+ $coupon_list = explode(',', $item[ 'coupon' ]);
+ $coupon_num = explode(',', $item[ 'coupon_num' ]);
+ $coupon_data = [];
+ foreach ($coupon_list as $k => $coupon_item) {
+ $coupon_data[] = [
+ 'coupon_type_id' => $coupon_item,
+ 'num' => $coupon_num[ $k ] ?? 1
+ ];
+ }
+ $coupon->giveCoupon($coupon_data, $item[ 'site_id' ], $item[ 'member_id' ], 6, $item['id'], 0, 0);
+ }
+ // 变更发放状态
+ model('promotion_mansong_record')->update([ 'status' => 1 ], [ [ 'id', '=', $item[ 'id' ] ] ]);
+ model('promotion_mansong_record')->commit();
+ } catch (\Exception $e) {
+ model('promotion_mansong_record')->rollback();
+ }
+ }
+ }
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/manjian/shop/controller/Manjian.php b/src/addon/manjian/shop/controller/Manjian.php
index ede5f2025..2613404c0 100644
--- a/src/addon/manjian/shop/controller/Manjian.php
+++ b/src/addon/manjian/shop/controller/Manjian.php
@@ -1,221 +1,213 @@
-replace = [
- 'MANJIAN_IMG' => __ROOT__ . '/addon/manjian/shop/view/public/img',
- 'MANJIAN_JS' => __ROOT__ . '/addon/manjian/shop/view/public/js',
- 'MANJIAN_CSS' => __ROOT__ . '/addon/manjian/shop/view/public/css',
- ];
- parent::__construct($app);
- }
-
- /**
- * 满减列表
- */
- public function lists()
- {
- if (request()->isJson()) {
- $page = input('page', 1);
- $page_size = input('page_size', PAGE_LIST_ROWS);
- $manjian_name = input('manjian_name', '');
- $status = input('status', '');
- $condition = [];
- $condition[] = [ 'site_id', '=', $this->site_id ];
- $condition[] = [ 'manjian_name', 'like', '%' . $manjian_name . '%' ];
- if ($status != null) {
- $condition[] = [ 'status', '=', $status ];
- }
-
- $start_time = input('start_time', '');
- $end_time = input('end_time', '');
-
- if ($start_time && !$end_time) {
- $condition[] = [ 'end_time', '>=', date_to_time($start_time) ];
- } elseif (!$start_time && $end_time) {
- $condition[] = [ 'start_time', '<=', date_to_time($end_time) ];
- } elseif ($start_time && $end_time) {
- $start_timestamp = date_to_time($start_time);
- $end_timestamp = date_to_time($end_time);
- $sql = "start_time between {$start_timestamp} and {$end_timestamp}";
- $sql .= " or end_time between {$start_timestamp} and {$end_timestamp}";
- $sql .= " or (start_time <= {$start_timestamp} and end_time >= {$end_timestamp})";
- $condition[] = [ '', 'exp', \think\facade\Db::raw($sql) ];
- }
-
- $order = 'create_time desc';
- $field = 'manjian_id,manjian_name,start_time,end_time,create_time,status';
-
- $manjian_model = new ManjianModel();
- $res = $manjian_model->getManjianPageList($condition, $page, $page_size, $order, $field);
-
- //获取状态名称
- $manjian_status_arr = $manjian_model->getManjianStatus();
- foreach ($res[ 'data' ][ 'list' ] as $key => $val) {
- $res[ 'data' ][ 'list' ][ $key ][ 'status_name' ] = $manjian_status_arr[ $val[ 'status' ] ];
- }
- return $res;
-
- } else {
- //满减状态
- $manjian_model = new ManjianModel();
- $manjian_status_arr = $manjian_model->getManjianStatus();
- $this->assign('manjian_status_arr', $manjian_status_arr);
-
- return $this->fetch("manjian/lists");
- }
- }
-
- /**
- * 满减添加
- */
- public function add()
- {
- $member_level_model = new MemberLevel();
- if (request()->isJson()) {
- $data = [
- 'site_id' => $this->site_id,
- 'manjian_name' => input('manjian_name', ''),
- 'manjian_type' => input('manjian_type', ''),
- 'type' => input('type', 0),
- 'number' => input('number', 0),
- 'goods_ids' => input('goods_ids', ''),
- 'start_time' => strtotime(input('start_time', '')),
- 'end_time' => strtotime(input('end_time', '')),
- 'rule_json' => input('rule_json', ''),
- 'remark' => input('remark', '')
- ];
-
- $manjian_model = new ManjianModel();
- return $manjian_model->addManjian($data);
- } else {
- //获取优惠券列表
- $coupon_model = new CouponType();
- $condition = [
- [ 'status', '=', 1 ],
- [ 'site_id', '=', $this->site_id ],
- ];
- //优惠券字段
- $coupon_field = 'coupon_type_id,type,coupon_name,image,money,discount,validity_type,fixed_term,status,is_limit,at_least,count,lead_count,end_time,goods_type,max_fetch';
- $coupon_list = $coupon_model->getCouponTypeList($condition, $coupon_field);
- $this->assign('coupon_list', $coupon_list);
- $this->assign('level_time', $member_level_model->level_time);
- return $this->fetch("manjian/add");
- }
- }
-
- /**
- * 满减编辑
- */
- public function edit()
- {
- $member_level_model = new MemberLevel();
- $manjian_model = new ManjianModel();
- if (request()->isJson()) {
- $data = [
- 'manjian_id' => input('manjian_id', 0),
- 'site_id' => $this->site_id,
- 'manjian_name' => input('manjian_name', ''),
- 'manjian_type' => input('manjian_type', ''),
- 'type' => input('type', 0),
- 'goods_ids' => input('goods_ids', ''),
- 'start_time' => strtotime(input('start_time', '')),
- 'end_time' => strtotime(input('end_time', '')),
- 'rule_json' => input('rule_json', ''),
- 'remark' => input('remark', '')
- ];
- return $manjian_model->editManjian($data);
- } else {
-
- $manjian_id = input('manjian_id', 0);
- $this->assign('manjian_id', $manjian_id);
-
- $manjian_info = $manjian_model->getManjianDetail($manjian_id, $this->site_id);
- if (empty($manjian_info[ 'data' ])) $this->error('未获取到活动数据', href_url('manjian://shop/manjian/lists'));
- $this->assign('manjian_info', $manjian_info[ 'data' ]);
- //获取优惠券列表
- $coupon_model = new CouponType();
- $condition = [
- [ 'status', '=', 1 ],
- [ 'site_id', '=', $this->site_id ],
- ];
- //优惠券字段
- $coupon_field = 'coupon_type_id,type,coupon_name,image,money,discount,validity_type,fixed_term,status,is_limit,at_least,count,lead_count,end_time,goods_type,max_fetch';
- $coupon_list = $coupon_model->getCouponTypeList($condition, $coupon_field);
- $this->assign('coupon_list', $coupon_list);
- $this->assign('level_time', $member_level_model->level_time);
- return $this->fetch("manjian/edit");
- }
- }
-
- /**
- * 满减详情
- */
- public function detail()
- {
- $manjian_id = input('manjian_id', 0);
- $manjian_model = new ManjianModel();
- $manjian_info = $manjian_model->getManjianDetail($manjian_id, $this->site_id);
- if (empty($manjian_info[ 'data' ])) $this->error('未获取到活动数据', href_url('manjian://shop/manjian/lists'));
- $this->assign('manjian_info', $manjian_info[ 'data' ]);
- return $this->fetch('manjian/detail');
-
- }
-
- /**
- * 满减关闭
- */
- public function close()
- {
- if (request()->isJson()) {
- $manjian_id = input('manjian_id', 0);
- $manjian_model = new ManjianModel();
- return $manjian_model->closeManjian($manjian_id, $this->site_id);
- }
- }
-
- /**
- * 满减删除
- */
- public function delete()
- {
- if (request()->isJson()) {
- $manjian_id = input('manjian_id', 0);
- $manjian_model = new ManjianModel();
- return $manjian_model->deleteManjian($manjian_id, $this->site_id);
- }
- }
-
- /**
- * 活动冲突商品
- */
- public function conflict()
- {
- $key = input('key', '');
- $conflict_data = Cache::get($key);
- $this->assign('conflict_data', $conflict_data);
- return $this->fetch('manjian/conflict');
- }
+replace = [
+ 'MANJIAN_IMG' => __ROOT__ . '/addon/manjian/shop/view/public/img',
+ 'MANJIAN_JS' => __ROOT__ . '/addon/manjian/shop/view/public/js',
+ 'MANJIAN_CSS' => __ROOT__ . '/addon/manjian/shop/view/public/css',
+ ];
+ parent::__construct($app);
+ }
+
+ /**
+ * 满减列表
+ */
+ public function lists()
+ {
+ if (request()->isJson()) {
+ $page = input('page', 1);
+ $page_size = input('page_size', PAGE_LIST_ROWS);
+ $manjian_name = input('manjian_name', '');
+ $status = input('status', '');
+ $condition = [];
+ $condition[] = [ 'site_id', '=', $this->site_id ];
+ $condition[] = [ 'manjian_name', 'like', '%' . $manjian_name . '%' ];
+ if ($status != null) {
+ $condition[] = [ 'status', '=', $status ];
+ }
+
+ $start_time = input('start_time', '');
+ $end_time = input('end_time', '');
+
+ if ($start_time && !$end_time) {
+ $condition[] = [ 'end_time', '>=', date_to_time($start_time) ];
+ } elseif (!$start_time && $end_time) {
+ $condition[] = [ 'start_time', '<=', date_to_time($end_time) ];
+ } elseif ($start_time && $end_time) {
+ $start_timestamp = date_to_time($start_time);
+ $end_timestamp = date_to_time($end_time);
+ $sql = "start_time between {$start_timestamp} and {$end_timestamp}";
+ $sql .= " or end_time between {$start_timestamp} and {$end_timestamp}";
+ $sql .= " or (start_time <= {$start_timestamp} and end_time >= {$end_timestamp})";
+ $condition[] = [ '', 'exp', \think\facade\Db::raw($sql) ];
+ }
+
+ $order = 'create_time desc';
+ $field = 'manjian_id,manjian_name,start_time,end_time,create_time,status';
+
+ $manjian_model = new ManjianModel();
+ $res = $manjian_model->getManjianPageList($condition, $page, $page_size, $order, $field);
+
+ //获取状态名称
+ $manjian_status_arr = $manjian_model->getManjianStatus();
+ foreach ($res[ 'data' ][ 'list' ] as $key => $val) {
+ $res[ 'data' ][ 'list' ][ $key ][ 'status_name' ] = $manjian_status_arr[ $val[ 'status' ] ];
+ }
+ return $res;
+
+ } else {
+ //满减状态
+ $manjian_model = new ManjianModel();
+ $manjian_status_arr = $manjian_model->getManjianStatus();
+ $this->assign('manjian_status_arr', $manjian_status_arr);
+
+ return $this->fetch("manjian/lists");
+ }
+ }
+
+ /**
+ * 满减添加
+ */
+ public function add()
+ {
+ $member_level_model = new MemberLevel();
+ if (request()->isJson()) {
+ $data = [
+ 'site_id' => $this->site_id,
+ 'manjian_name' => input('manjian_name', ''),
+ 'manjian_type' => input('manjian_type', ''),
+ 'type' => input('type', 0),
+ 'number' => input('number', 0),
+ 'goods_ids' => input('goods_ids', ''),
+ 'start_time' => strtotime(input('start_time', '')),
+ 'end_time' => strtotime(input('end_time', '')),
+ 'rule_json' => input('rule_json', ''),
+ 'remark' => input('remark', '')
+ ];
+
+ $manjian_model = new ManjianModel();
+ return $manjian_model->addManjian($data);
+ } else {
+ //获取优惠券列表
+ $coupon_model = new CouponType();
+ $condition = [
+ [ 'status', '=', 1 ],
+ [ 'site_id', '=', $this->site_id ],
+ ];
+ //优惠券字段
+ $coupon_field = 'coupon_type_id,type,coupon_name,image,money,discount,validity_type,fixed_term,status,is_limit,at_least,count,lead_count,end_time,goods_type,max_fetch';
+ $coupon_list = $coupon_model->getCouponTypeList($condition, $coupon_field);
+ $this->assign('coupon_list', $coupon_list);
+ $this->assign('level_time', $member_level_model->level_time);
+ return $this->fetch("manjian/add");
+ }
+ }
+
+ /**
+ * 满减编辑
+ */
+ public function edit()
+ {
+ $member_level_model = new MemberLevel();
+ $manjian_model = new ManjianModel();
+ if (request()->isJson()) {
+ $data = [
+ 'manjian_id' => input('manjian_id', 0),
+ 'site_id' => $this->site_id,
+ 'manjian_name' => input('manjian_name', ''),
+ 'manjian_type' => input('manjian_type', ''),
+ 'type' => input('type', 0),
+ 'goods_ids' => input('goods_ids', ''),
+ 'start_time' => strtotime(input('start_time', '')),
+ 'end_time' => strtotime(input('end_time', '')),
+ 'rule_json' => input('rule_json', ''),
+ 'remark' => input('remark', '')
+ ];
+ return $manjian_model->editManjian($data);
+ } else {
+
+ $manjian_id = input('manjian_id', 0);
+ $this->assign('manjian_id', $manjian_id);
+
+ $manjian_info = $manjian_model->getManjianDetail($manjian_id, $this->site_id);
+ if (empty($manjian_info[ 'data' ])) $this->error('未获取到活动数据', href_url('manjian://shop/manjian/lists'));
+ $this->assign('manjian_info', $manjian_info[ 'data' ]);
+ //获取优惠券列表
+ $coupon_model = new CouponType();
+ $condition = [
+ [ 'status', '=', 1 ],
+ [ 'site_id', '=', $this->site_id ],
+ ];
+ //优惠券字段
+ $coupon_field = 'coupon_type_id,type,coupon_name,image,money,discount,validity_type,fixed_term,status,is_limit,at_least,count,lead_count,end_time,goods_type,max_fetch';
+ $coupon_list = $coupon_model->getCouponTypeList($condition, $coupon_field);
+ $this->assign('coupon_list', $coupon_list);
+ $this->assign('level_time', $member_level_model->level_time);
+ return $this->fetch("manjian/edit");
+ }
+ }
+
+ /**
+ * 满减详情
+ */
+ public function detail()
+ {
+ $manjian_id = input('manjian_id', 0);
+ $manjian_model = new ManjianModel();
+ $manjian_info = $manjian_model->getManjianDetail($manjian_id, $this->site_id);
+ if (empty($manjian_info[ 'data' ])) $this->error('未获取到活动数据', href_url('manjian://shop/manjian/lists'));
+ $this->assign('manjian_info', $manjian_info[ 'data' ]);
+ return $this->fetch('manjian/detail');
+
+ }
+
+ /**
+ * 满减关闭
+ */
+ public function close()
+ {
+ if (request()->isJson()) {
+ $manjian_id = input('manjian_id', 0);
+ $manjian_model = new ManjianModel();
+ return $manjian_model->closeManjian($manjian_id, $this->site_id);
+ }
+ }
+
+ /**
+ * 满减删除
+ */
+ public function delete()
+ {
+ if (request()->isJson()) {
+ $manjian_id = input('manjian_id', 0);
+ $manjian_model = new ManjianModel();
+ return $manjian_model->deleteManjian($manjian_id, $this->site_id);
+ }
+ }
+
+ /**
+ * 活动冲突商品
+ */
+ public function conflict()
+ {
+ $key = input('key', '');
+ $conflict_data = Cache::get($key);
+ $this->assign('conflict_data', $conflict_data);
+ return $this->fetch('manjian/conflict');
+ }
}
\ No newline at end of file
diff --git a/src/addon/membercancel/config/diy_view.php b/src/addon/membercancel/config/diy_view.php
index c3c657905..e36ca9b7d 100644
--- a/src/addon/membercancel/config/diy_view.php
+++ b/src/addon/membercancel/config/diy_view.php
@@ -1,38 +1,30 @@
- '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
- 'template' => [],
-
- // 后台自定义组件——装修
- 'util' => [],
-
- // 自定义页面路径
- 'link' => [],
-
- // 自定义图标库
- 'icon_library' => [],
-
- // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
- 'component' => [],
-
- // uni-app 页面,多个逗号隔开
- 'pages' => [],
-
- // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
- 'info' => [],
-
- // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
- 'theme' => [],
-
- // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
- 'data' => []
+ '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
+ 'template' => [],
+
+ // 后台自定义组件——装修
+ 'util' => [],
+
+ // 自定义页面路径
+ 'link' => [],
+
+ // 自定义图标库
+ 'icon_library' => [],
+
+ // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
+ 'component' => [],
+
+ // uni-app 页面,多个逗号隔开
+ 'pages' => [],
+
+ // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
+ 'info' => [],
+
+ // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
+ 'theme' => [],
+
+ // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
+ 'data' => []
];
\ No newline at end of file
diff --git a/src/addon/membercancel/config/info.php b/src/addon/membercancel/config/info.php
index d64123bc5..553b5074a 100644
--- a/src/addon/membercancel/config/info.php
+++ b/src/addon/membercancel/config/info.php
@@ -1,21 +1,12 @@
- 'membercancel',
- 'title' => '会员注销',
- 'description' => '会员注销',
- 'type' => 'tool', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
- 'status' => 1,
- 'author' => '',
- 'version' => '5.3.1',
- 'version_no' => '525231212001',
- 'content' => '',
+ 'membercancel',
+ 'title' => '会员注销',
+ 'description' => '会员注销',
+ 'type' => 'tool', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
+ 'status' => 1,
+ 'author' => '',
+ 'version' => '5.3.1',
+ 'version_no' => '525231212001',
+ 'content' => '',
];
\ No newline at end of file
diff --git a/src/addon/membercancel/event/Install.php b/src/addon/membercancel/event/Install.php
index b6982ee26..c534953a5 100644
--- a/src/addon/membercancel/event/Install.php
+++ b/src/addon/membercancel/event/Install.php
@@ -1,27 +1,18 @@
- "会员注销", "type" => "membercancel" ];
- }
+ "会员注销", "type" => "membercancel" ];
+ }
}
\ No newline at end of file
diff --git a/src/addon/membercancel/event/ShowPromotion.php b/src/addon/membercancel/event/ShowPromotion.php
index 5b1d1a258..b33019260 100644
--- a/src/addon/membercancel/event/ShowPromotion.php
+++ b/src/addon/membercancel/event/ShowPromotion.php
@@ -1,46 +1,38 @@
- [
- [
- //插件名称
- 'name' => 'membercancel',
- //展示分类(根据平台端设置,admin(平台营销),shop:店铺营销,member:会员营销, tool:应用工具)
- 'show_type' => 'tool',
- //展示主题
- 'title' => '会员注销',
- //展示介绍
- 'description' => '客户在线申请注销账号',
- //展示图标
- 'icon' => 'addon/membercancel/icon.png',
- //跳转链接
- 'url' => 'membercancel://shop/membercancel/lists',
- ]
- ]
-
- ];
- return $data;
- }
+ [
+ [
+ //插件名称
+ 'name' => 'membercancel',
+ //展示分类(根据平台端设置,admin(平台营销),shop:店铺营销,member:会员营销, tool:应用工具)
+ 'show_type' => 'tool',
+ //展示主题
+ 'title' => '会员注销',
+ //展示介绍
+ 'description' => '客户在线申请注销账号',
+ //展示图标
+ 'icon' => 'addon/membercancel/icon.png',
+ //跳转链接
+ 'url' => 'membercancel://shop/membercancel/lists',
+ ]
+ ]
+
+ ];
+ return $data;
+ }
}
\ No newline at end of file
diff --git a/src/addon/membercancel/event/UnInstall.php b/src/addon/membercancel/event/UnInstall.php
index 31a888abf..6d1bce120 100644
--- a/src/addon/membercancel/event/UnInstall.php
+++ b/src/addon/membercancel/event/UnInstall.php
@@ -1,26 +1,17 @@
-getCancelConfig($param[ 'site_id' ], 'shop');
- $value = $config_info[ 'data' ][ 'value' ];
- $value[ 'is_enable' ] = 1;//默认打开注销
- $value[ 'is_audit' ] = 0;//默认打开注销
- if ($value[ 'is_enable' ] == 0) {
- return $this->error('', '未开放注1销');
- }
- //获取用户信息
- $member_info = model('member')->getInfo(
- [
- [ 'site_id', '=', $param[ 'site_id' ] ],
- [ 'member_id', '=', $param[ 'member_id' ] ],
- [ 'is_delete', '=', 0 ]
- ]
- );
- if (empty($member_info)) {
- return $this->error('', '会员不存在');
- }
- if ($member_info[ 'balance_withdraw_apply' ] > 0) {
- return $this->error('', '有余额正在提现中,请提现成功后在申请注销');
- }
- $member_json = json_encode($member_info);
-
- //判断是否申请过
- $member_cancel_info = model('member_cancel')->getInfo([ [ 'site_id', '=', $param[ 'site_id' ] ], [ 'member_id', '=', $param[ 'member_id' ] ] ]);
- if (!empty($member_cancel_info)) {
- if ($member_cancel_info[ 'status' ] != -1) {
- return $this->error('', '请勿重复申请注销');
- }
- }
-
- //判断是否有未完成的订单
- $order_condition = [
- [ 'site_id', '=', $param[ 'site_id' ] ],
- [ 'member_id', '=', $param[ 'member_id' ] ],
- [ 'order_status', 'in', [ 1, 3, 4 ] ]
- ];
- $order_count = model('order')->getCount($order_condition);
- if ($order_count > 0) {
- return $this->error('', '还有订单未完成,请等订单完成后在申请注销');
- }
-
- //分销
- $fenxiao_json = '';
- if (addon_is_exit('fenxiao', $param[ 'site_id' ]) == 1) {
- //获取分销商信息
- $fenxiao_info = model('fenxiao')->getInfo([ [ 'site_id', '=', $param[ 'site_id' ] ], [ 'member_id', '=', $param[ 'member_id' ] ] ]);
- if (!empty($fenxiao_info)) {
- if ($fenxiao_info[ 'account_withdraw_apply' ] > 0) {
- return $this->error('', '有分销佣金正在提现中,请提现成功后在申请注销');
- }
-
- //判断是否存在未结算的分销订单
- $fenxiao_condition = [
- [ 'site_id', '=', $param[ 'site_id' ] ],
- [ 'one_fenxiao_id|two_fenxiao_id|three_fenxiao_id', '=', $fenxiao_info[ 'fenxiao_id' ] ],
- [ 'is_settlement', '=', 0 ]
- ];
- $fenxiao_order_count = model('fenxiao_order')->getCount($fenxiao_condition);
- if ($fenxiao_order_count > 0) {
- return $this->error('', '还有分销订单未结算,请等订单结算后在申请注销');
- }
-
- $fenxiao_json = json_encode($fenxiao_info);
- }
- }
-
- model('member_cancel')->startTrans();
- try {
- if (!empty($member_cancel_info)) {
- $id = $member_cancel_info[ 'id' ];
- $data = [
- 'status' => 0,
- 'audit_uid' => '',
- 'audit_username' => '',
- 'reason' => '',
- 'audit_time' => ''
- ];
- model('member_cancel')->update($data, [ [ 'id', '=', $id ] ]);
-
- } else {
- $data = [
- 'member_id' => $member_info[ 'member_id' ],
- 'site_id' => $param[ 'site_id' ],
- 'username' => $member_info[ 'username' ],
- 'mobile' => $member_info[ 'mobile' ],
- 'nickname' => $member_info[ 'nickname' ],
- 'create_time' => time(),
- 'member_json' => $member_json,
- 'fenxiao_json' => $fenxiao_json
- ];
- $id = model('member_cancel')->add($data);
- }
-
- //审核开关关闭
- if ($value[ 'is_audit' ] == 0) {
- //todo 调用审核成功接口
- $param[ 'id' ] = $id;
- $param[ 'audit_uid' ] = '';
- $param[ 'audit_username' ] = '';
- $res = $this->memberCancelAuditPass($param);
- if ($res[ 'code' ] < 0) {
- model('member_cancel')->rollback();
- return $res;
- }
- }
- model('member_cancel')->commit();
-
- //会员申请注销消息
- $message_model = new Message();
- $message_model->sendMessage([ 'keywords' => "USER_CANCEL_APPLY", 'member_id' => $member_info[ 'member_id' ], 'site_id' => $param[ 'site_id' ] ]);
- $res[ 'is_audit' ] = $value[ 'is_audit' ];
- return $this->success($res);
- } catch (\Exception $e) {
- model('member_cancel')->rollback();
- return $this->error('', $e->getMessage());
- }
- }
-
- /**
- * 撤销申请注销
- * @param $member_id
- * @param $site_id
- * @return array
- */
- public function cancelApplyMemberCancel($member_id, $site_id)
- {
- $member_cancel_info = model('member_cancel')->getInfo(
- [
- [ 'member_id', '=', $member_id ],
- [ 'site_id', '=', $site_id ]
- ]
- );
- if (empty($member_cancel_info)) {
- return $this->error('', '数据不合法');
- }
- if ($member_cancel_info[ 'status' ] == 1) {
- return $this->error('', '数据不合法');
- }
-
- $res = model('member_cancel')->delete([ [ 'member_id', '=', $member_id ], [ 'site_id', '=', $site_id ] ]);
- return $this->success($res);
- }
-
- /**
- * 审核通过
- * @param $param
- * @return array
- */
- public function memberCancelAuditPass($param)
- {
- $info = model('member_cancel')->getInfo([ [ 'id', '=', $param[ 'id' ] ], [ 'site_id', '=', $param[ 'site_id' ] ] ], 'member_id,status');
- if (empty($info)) {
- return $this->error('', '请核实数据后重试');
- }
- if ($info[ 'status' ] != 0) {
- return $this->error('', '该数据已审核,请勿重复审核');
- }
-
- model('member_cancel')->startTrans();
- try {
-
- //修改注销状态
- $data = [
- 'status' => 1,
- 'audit_uid' => $param[ 'audit_uid' ],
- 'audit_username' => $param[ 'audit_username' ],
- 'audit_time' => time()
- ];
- model('member_cancel')->update($data, [ [ 'id', '=', $param[ 'id' ] ], [ 'site_id', '=', $param[ 'site_id' ] ] ]);
-
- //删除会员信息
- model('member')->update([ 'is_delete' => 1, 'status' => 0 ], [ [ 'member_id', '=', $info[ 'member_id' ] ], [ 'site_id', '=', $param[ 'site_id' ] ] ]);
- Cache::set('member_blacklist_' . $param[ 'site_id' ], null);
-
- event('MemberCancel', [ 'member_id' => $info[ 'member_id' ], 'site_id' => $param[ 'site_id' ] ]);
-
- model('member_cancel')->commit();
-
- //会员注销成功消息
- $message_model = new Message();
- $message_model->sendMessage([ 'keywords' => "USER_CANCEL_SUCCESS", 'member_id' => $info[ 'member_id' ], 'site_id' => $param[ 'site_id' ] ]);
-
- return $this->success();
- } catch (\Exception $e) {
- model('member_cancel')->rollback();
- return $this->error('', $e->getMessage());
- }
- }
-
- /**
- * 审核拒绝
- * @param $param
- * @return array
- */
- public function memberCancelAuditRefuse($param)
- {
- $info = model('member_cancel')->getInfo([ [ 'id', '=', $param[ 'id' ] ], [ 'site_id', '=', $param[ 'site_id' ] ] ], 'status,member_id');
-
- if (empty($info)) {
- return $this->error('', '请核实数据后重试');
- }
- if ($info[ 'status' ] != 0) {
- return $this->error('', '该数据已审核,请勿重复审核');
- }
-
- $data = [
- 'status' => -1,
- 'audit_uid' => $param[ 'audit_uid' ],
- 'audit_username' => $param[ 'audit_username' ],
- 'reason' => $param[ 'reason' ],
- 'audit_time' => time()
- ];
- $res = model('member_cancel')->update($data, [ [ 'id', '=', $param[ 'id' ] ], [ 'site_id', '=', $param[ 'site_id' ] ] ]);
-
- //会员注销失败消息
- $message_model = new Message();
- $message_model->sendMessage([ 'keywords' => "USER_CANCEL_FAIL", 'member_id' => $info[ 'member_id' ], 'site_id' => $param[ 'site_id' ] ]);
-
- return $this->success($res);
- }
-
- /**
- * 获取会员注销信息
- * @param array $condition
- * @param string $field
- * @return array
- */
- public function getMemberCancelInfo($condition = [], $field = '*')
- {
- $info = model('member_cancel')->getInfo($condition, $field);
- return $this->success($info);
- }
-
- /**
- * 获取会员注销分页列表
- * @param array $condition
- * @param int $page
- * @param int $page_size
- * @param string $order
- * @param string $field
- * @return array
- */
- public function getMemberCancelPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'id desc', $field = '*')
- {
- $list = model('member_cancel')->pageList($condition, $field, $order, $page, $page_size);
- return $this->success($list);
- }
-
- /**
- * 获取用户账户信息
- * @param $member_id
- * @param $site_id
- * @return array
- */
- public function getMemberAccountInfo($member_id, $site_id)
- {
- $data = [];
- //会员信息
- $member_info = model('member')->getInfo(
- [
- [ 'member_id', '=', $member_id ],
- [ 'site_id', '=', $site_id ],
- [ 'is_delete', '=', 0 ]
- ],
- 'is_fenxiao,point,balance,balance_money,balance_withdraw_apply'
- );
- $data[ 'member_info' ] = $member_info;
- //优惠券数量
- $data[ 'member_coupon_count' ] = model('promotion_coupon')->getCount(
- [
- [ 'member_id', '=', $member_id ],
- [ 'site_id', '=', $site_id ],
- [ 'state', '=', 1 ]
- ]
- );
-
- //订单待发货
- $data[ 'order_pay_count' ] = model('order')->getCount(
- [
- [ 'member_id', '=', $member_id ],
- [ 'site_id', '=', $site_id ],
- [ 'order_status', '=', OrderCommon::ORDER_PAY ]
- ]
- );
- //订单待收货
- $data[ 'order_delivery_count' ] = model('order')->getCount(
- [
- [ 'member_id', '=', $member_id ],
- [ 'site_id', '=', $site_id ],
- [ 'order_status', '=', OrderCommon::ORDER_DELIVERY ]
- ]
- );
- //订单待完成
- $data[ 'order_take_delivery_count' ] = model('order')->getCount(
- [
- [ 'member_id', '=', $member_id ],
- [ 'site_id', '=', $site_id ],
- [ 'order_status', '=', OrderCommon::ORDER_TAKE_DELIVERY ]
- ]
- );
- //退款订单
- $data[ 'order_refund_count' ] = model('order')->getCount(
- [
- [ 'member_id', '=', $member_id ],
- [ 'site_id', '=', $site_id ],
- [ 'refund_status', 'not in', [ OrderRefundDict::REFUND_NOT_APPLY, OrderRefundDict::REFUND_COMPLETE ] ]
- ]
- );
-
- //判断用户是否是分销商
- if ($member_info[ 'is_fenxiao' ] == 1 && addon_is_exit('fenxiao', $site_id)) {
-
- //分销商信息
- $fenxiao_model = new Fenxiao();
- $fenxiao_info = $fenxiao_model->getFenxiaoInfo(
- [
- [ 'member_id', '=', $member_id ],
- [ 'site_id', '=', $site_id ]
- ],
- 'account,account_withdraw,account_withdraw_apply,total_commission'
- );
- $data[ 'fenxiao_info' ] = $fenxiao_info[ 'data' ];
-
- //分销待结算订单
- $fenxiao_order_model = new FenxiaoOrder();
- $fenxiao_order_count = $fenxiao_order_model->getFenxiaoOrderCount(
- [
- [ 'member_id', '=', $member_id ],
- [ 'site_id', '=', $site_id ],
- [ 'is_settlement', '=', 0 ]
- ]
- );
- $data[ 'fenxiao_order_count' ] = $fenxiao_order_count[ 'data' ];
- }
-
- return $this->success($data);
- }
-
- /****************************************** 会员注销通知 start **********************************************/
-
- /**
- * 会员注销成功
- * @param $data
- * @return array
- */
- public function memberCancelSuccess($data)
- {
- $member_cancel = model('member_cancel')->getInfo(
- [
- [ 'member_id', '=', $data[ 'member_id' ] ],
- [ 'site_id', '=', $data[ 'site_id' ] ]
- ]
- );
- if (empty($member_cancel)) {
- return $this->success();
- }
- $member_info = model('member')->getInfo([ [ 'member_id', '=', $data[ 'member_id' ] ] ], 'username,mobile,nickname');
-
- //发送短信
- $sms_model = new Sms();
-
- $name = $member_info[ "nickname" ] == '' ? $member_info[ "mobile" ] : $member_info[ "nickname" ];
- $var_parse = array (
- "username" => $name,
- );
-
- $data[ "sms_account" ] = $member_info[ "mobile" ] ?? '';//手机号
- $data[ "var_parse" ] = $var_parse;
- $sms_result = $sms_model->sendMessage($data);
-
- return $this->success();
- }
-
- /**
- * 会员注销失败
- * @param $data
- * @return array
- */
- public function memberCancelFail($data)
- {
- $member_cancel = model('member_cancel')->getInfo(
- [
- [ 'member_id', '=', $data[ 'member_id' ] ],
- [ 'site_id', '=', $data[ 'site_id' ] ]
- ]
- );
- if (empty($member_cancel)) {
- return $this->success();
- }
- $member_info = model('member')->getInfo([ [ 'member_id', '=', $data[ 'member_id' ] ] ], 'username,mobile,nickname');
-
- //发送短信
- $sms_model = new Sms();
-
- $name = $member_info[ "nickname" ] == '' ? $member_info[ "mobile" ] : $member_info[ "nickname" ];
- $var_parse = array (
- "username" => $name,
- );
-
- $data[ "sms_account" ] = $member_info[ "mobile" ] ?? '';//手机号
- $data[ "var_parse" ] = $var_parse;
- $sms_result = $sms_model->sendMessage($data);
-
- return $this->success();
- }
-
- /**
- * 会员注销申请通知(店铺)
- * @param $data
- * @return array
- * @throws \GuzzleHttp\Exception\GuzzleException
- */
- public function memberCancelApply($data)
- {
- $member_cancel = model('member_cancel')->getInfo(
- [
- [ 'member_id', '=', $data[ 'member_id' ] ],
- [ 'site_id', '=', $data[ 'site_id' ] ]
- ]
- );
- if (empty($member_cancel)) {
- return $this->success();
- }
- $member_info = model('member')->getInfo([ [ 'member_id', '=', $data[ 'member_id' ] ] ], 'username,mobile,nickname');
- $name = $member_info[ "nickname" ] == '' ? $member_info[ "mobile" ] : $member_info[ "nickname" ];
- //发送短信
- $sms_model = new Sms();
-
- $var_parse = array (
- "username" => $name,
- );
-// $site_id = $data['site_id'];
-// $shop_info = model("shop")->getInfo([["site_id", "=", $site_id]], "mobile,email");
-// $message_data["sms_account"] = $shop_info["mobile"];//手机号
- $data[ "var_parse" ] = $var_parse;
-
- $shop_accept_message_model = new ShopAcceptMessage();
- $result = $shop_accept_message_model->getShopAcceptMessageList();
- $list = $result[ 'data' ];
- if (!empty($list)) {
- foreach ($list as $v) {
- $message_data = $data;
- $message_data[ "sms_account" ] = $v[ "mobile" ];//手机号
- $sms_model->sendMessage($message_data);
-
- if ($v[ 'wx_openid' ] != '') {
- $wechat_model = new WechatMessage();
- $data[ "openid" ] = $v[ 'wx_openid' ];
- $data[ "template_data" ] = [
- 'thing2' => replaceSpecialChar($name), // 申请人
- 'time4' => time_to_date(time()) // 注销时间
- ];
-
- $data[ "page" ] = "";
- $wechat_model->sendMessage($data);
- }
- }
- }
- }
-
- /****************************************** 会员注销通知 end ************************************************/
+getCancelConfig($param[ 'site_id' ], 'shop');
+ $value = $config_info[ 'data' ][ 'value' ];
+ $value[ 'is_enable' ] = 1;//默认打开注销
+ $value[ 'is_audit' ] = 0;//默认打开注销
+ if ($value[ 'is_enable' ] == 0) {
+ return $this->error('', '未开放注1销');
+ }
+ //获取用户信息
+ $member_info = model('member')->getInfo(
+ [
+ [ 'site_id', '=', $param[ 'site_id' ] ],
+ [ 'member_id', '=', $param[ 'member_id' ] ],
+ [ 'is_delete', '=', 0 ]
+ ]
+ );
+ if (empty($member_info)) {
+ return $this->error('', '会员不存在');
+ }
+ if ($member_info[ 'balance_withdraw_apply' ] > 0) {
+ return $this->error('', '有余额正在提现中,请提现成功后在申请注销');
+ }
+ $member_json = json_encode($member_info);
+
+ //判断是否申请过
+ $member_cancel_info = model('member_cancel')->getInfo([ [ 'site_id', '=', $param[ 'site_id' ] ], [ 'member_id', '=', $param[ 'member_id' ] ] ]);
+ if (!empty($member_cancel_info)) {
+ if ($member_cancel_info[ 'status' ] != -1) {
+ return $this->error('', '请勿重复申请注销');
+ }
+ }
+
+ //判断是否有未完成的订单
+ $order_condition = [
+ [ 'site_id', '=', $param[ 'site_id' ] ],
+ [ 'member_id', '=', $param[ 'member_id' ] ],
+ [ 'order_status', 'in', [ 1, 3, 4 ] ]
+ ];
+ $order_count = model('order')->getCount($order_condition);
+ if ($order_count > 0) {
+ return $this->error('', '还有订单未完成,请等订单完成后在申请注销');
+ }
+
+ //分销
+ $fenxiao_json = '';
+ if (addon_is_exit('fenxiao', $param[ 'site_id' ]) == 1) {
+ //获取分销商信息
+ $fenxiao_info = model('fenxiao')->getInfo([ [ 'site_id', '=', $param[ 'site_id' ] ], [ 'member_id', '=', $param[ 'member_id' ] ] ]);
+ if (!empty($fenxiao_info)) {
+ if ($fenxiao_info[ 'account_withdraw_apply' ] > 0) {
+ return $this->error('', '有分销佣金正在提现中,请提现成功后在申请注销');
+ }
+
+ //判断是否存在未结算的分销订单
+ $fenxiao_condition = [
+ [ 'site_id', '=', $param[ 'site_id' ] ],
+ [ 'one_fenxiao_id|two_fenxiao_id|three_fenxiao_id', '=', $fenxiao_info[ 'fenxiao_id' ] ],
+ [ 'is_settlement', '=', 0 ]
+ ];
+ $fenxiao_order_count = model('fenxiao_order')->getCount($fenxiao_condition);
+ if ($fenxiao_order_count > 0) {
+ return $this->error('', '还有分销订单未结算,请等订单结算后在申请注销');
+ }
+
+ $fenxiao_json = json_encode($fenxiao_info);
+ }
+ }
+
+ model('member_cancel')->startTrans();
+ try {
+ if (!empty($member_cancel_info)) {
+ $id = $member_cancel_info[ 'id' ];
+ $data = [
+ 'status' => 0,
+ 'audit_uid' => '',
+ 'audit_username' => '',
+ 'reason' => '',
+ 'audit_time' => ''
+ ];
+ model('member_cancel')->update($data, [ [ 'id', '=', $id ] ]);
+
+ } else {
+ $data = [
+ 'member_id' => $member_info[ 'member_id' ],
+ 'site_id' => $param[ 'site_id' ],
+ 'username' => $member_info[ 'username' ],
+ 'mobile' => $member_info[ 'mobile' ],
+ 'nickname' => $member_info[ 'nickname' ],
+ 'create_time' => time(),
+ 'member_json' => $member_json,
+ 'fenxiao_json' => $fenxiao_json
+ ];
+ $id = model('member_cancel')->add($data);
+ }
+
+ //审核开关关闭
+ if ($value[ 'is_audit' ] == 0) {
+ //todo 调用审核成功接口
+ $param[ 'id' ] = $id;
+ $param[ 'audit_uid' ] = '';
+ $param[ 'audit_username' ] = '';
+ $res = $this->memberCancelAuditPass($param);
+ if ($res[ 'code' ] < 0) {
+ model('member_cancel')->rollback();
+ return $res;
+ }
+ }
+ model('member_cancel')->commit();
+
+ //会员申请注销消息
+ $message_model = new Message();
+ $message_model->sendMessage([ 'keywords' => "USER_CANCEL_APPLY", 'member_id' => $member_info[ 'member_id' ], 'site_id' => $param[ 'site_id' ] ]);
+ $res[ 'is_audit' ] = $value[ 'is_audit' ];
+ return $this->success($res);
+ } catch (\Exception $e) {
+ model('member_cancel')->rollback();
+ return $this->error('', $e->getMessage());
+ }
+ }
+
+ /**
+ * 撤销申请注销
+ * @param $member_id
+ * @param $site_id
+ * @return array
+ */
+ public function cancelApplyMemberCancel($member_id, $site_id)
+ {
+ $member_cancel_info = model('member_cancel')->getInfo(
+ [
+ [ 'member_id', '=', $member_id ],
+ [ 'site_id', '=', $site_id ]
+ ]
+ );
+ if (empty($member_cancel_info)) {
+ return $this->error('', '数据不合法');
+ }
+ if ($member_cancel_info[ 'status' ] == 1) {
+ return $this->error('', '数据不合法');
+ }
+
+ $res = model('member_cancel')->delete([ [ 'member_id', '=', $member_id ], [ 'site_id', '=', $site_id ] ]);
+ return $this->success($res);
+ }
+
+ /**
+ * 审核通过
+ * @param $param
+ * @return array
+ */
+ public function memberCancelAuditPass($param)
+ {
+ $info = model('member_cancel')->getInfo([ [ 'id', '=', $param[ 'id' ] ], [ 'site_id', '=', $param[ 'site_id' ] ] ], 'member_id,status');
+ if (empty($info)) {
+ return $this->error('', '请核实数据后重试');
+ }
+ if ($info[ 'status' ] != 0) {
+ return $this->error('', '该数据已审核,请勿重复审核');
+ }
+
+ model('member_cancel')->startTrans();
+ try {
+
+ //修改注销状态
+ $data = [
+ 'status' => 1,
+ 'audit_uid' => $param[ 'audit_uid' ],
+ 'audit_username' => $param[ 'audit_username' ],
+ 'audit_time' => time()
+ ];
+ model('member_cancel')->update($data, [ [ 'id', '=', $param[ 'id' ] ], [ 'site_id', '=', $param[ 'site_id' ] ] ]);
+
+ //删除会员信息
+ model('member')->update([ 'is_delete' => 1, 'status' => 0 ], [ [ 'member_id', '=', $info[ 'member_id' ] ], [ 'site_id', '=', $param[ 'site_id' ] ] ]);
+ Cache::set('member_blacklist_' . $param[ 'site_id' ], null);
+
+ event('MemberCancel', [ 'member_id' => $info[ 'member_id' ], 'site_id' => $param[ 'site_id' ] ]);
+
+ model('member_cancel')->commit();
+
+ //会员注销成功消息
+ $message_model = new Message();
+ $message_model->sendMessage([ 'keywords' => "USER_CANCEL_SUCCESS", 'member_id' => $info[ 'member_id' ], 'site_id' => $param[ 'site_id' ] ]);
+
+ return $this->success();
+ } catch (\Exception $e) {
+ model('member_cancel')->rollback();
+ return $this->error('', $e->getMessage());
+ }
+ }
+
+ /**
+ * 审核拒绝
+ * @param $param
+ * @return array
+ */
+ public function memberCancelAuditRefuse($param)
+ {
+ $info = model('member_cancel')->getInfo([ [ 'id', '=', $param[ 'id' ] ], [ 'site_id', '=', $param[ 'site_id' ] ] ], 'status,member_id');
+
+ if (empty($info)) {
+ return $this->error('', '请核实数据后重试');
+ }
+ if ($info[ 'status' ] != 0) {
+ return $this->error('', '该数据已审核,请勿重复审核');
+ }
+
+ $data = [
+ 'status' => -1,
+ 'audit_uid' => $param[ 'audit_uid' ],
+ 'audit_username' => $param[ 'audit_username' ],
+ 'reason' => $param[ 'reason' ],
+ 'audit_time' => time()
+ ];
+ $res = model('member_cancel')->update($data, [ [ 'id', '=', $param[ 'id' ] ], [ 'site_id', '=', $param[ 'site_id' ] ] ]);
+
+ //会员注销失败消息
+ $message_model = new Message();
+ $message_model->sendMessage([ 'keywords' => "USER_CANCEL_FAIL", 'member_id' => $info[ 'member_id' ], 'site_id' => $param[ 'site_id' ] ]);
+
+ return $this->success($res);
+ }
+
+ /**
+ * 获取会员注销信息
+ * @param array $condition
+ * @param string $field
+ * @return array
+ */
+ public function getMemberCancelInfo($condition = [], $field = '*')
+ {
+ $info = model('member_cancel')->getInfo($condition, $field);
+ return $this->success($info);
+ }
+
+ /**
+ * 获取会员注销分页列表
+ * @param array $condition
+ * @param int $page
+ * @param int $page_size
+ * @param string $order
+ * @param string $field
+ * @return array
+ */
+ public function getMemberCancelPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'id desc', $field = '*')
+ {
+ $list = model('member_cancel')->pageList($condition, $field, $order, $page, $page_size);
+ return $this->success($list);
+ }
+
+ /**
+ * 获取用户账户信息
+ * @param $member_id
+ * @param $site_id
+ * @return array
+ */
+ public function getMemberAccountInfo($member_id, $site_id)
+ {
+ $data = [];
+ //会员信息
+ $member_info = model('member')->getInfo(
+ [
+ [ 'member_id', '=', $member_id ],
+ [ 'site_id', '=', $site_id ],
+ [ 'is_delete', '=', 0 ]
+ ],
+ 'is_fenxiao,point,balance,balance_money,balance_withdraw_apply'
+ );
+ $data[ 'member_info' ] = $member_info;
+ //优惠券数量
+ $data[ 'member_coupon_count' ] = model('promotion_coupon')->getCount(
+ [
+ [ 'member_id', '=', $member_id ],
+ [ 'site_id', '=', $site_id ],
+ [ 'state', '=', 1 ]
+ ]
+ );
+
+ //订单待发货
+ $data[ 'order_pay_count' ] = model('order')->getCount(
+ [
+ [ 'member_id', '=', $member_id ],
+ [ 'site_id', '=', $site_id ],
+ [ 'order_status', '=', OrderCommon::ORDER_PAY ]
+ ]
+ );
+ //订单待收货
+ $data[ 'order_delivery_count' ] = model('order')->getCount(
+ [
+ [ 'member_id', '=', $member_id ],
+ [ 'site_id', '=', $site_id ],
+ [ 'order_status', '=', OrderCommon::ORDER_DELIVERY ]
+ ]
+ );
+ //订单待完成
+ $data[ 'order_take_delivery_count' ] = model('order')->getCount(
+ [
+ [ 'member_id', '=', $member_id ],
+ [ 'site_id', '=', $site_id ],
+ [ 'order_status', '=', OrderCommon::ORDER_TAKE_DELIVERY ]
+ ]
+ );
+ //退款订单
+ $data[ 'order_refund_count' ] = model('order')->getCount(
+ [
+ [ 'member_id', '=', $member_id ],
+ [ 'site_id', '=', $site_id ],
+ [ 'refund_status', 'not in', [ OrderRefundDict::REFUND_NOT_APPLY, OrderRefundDict::REFUND_COMPLETE ] ]
+ ]
+ );
+
+ //判断用户是否是分销商
+ if ($member_info[ 'is_fenxiao' ] == 1 && addon_is_exit('fenxiao', $site_id)) {
+
+ //分销商信息
+ $fenxiao_model = new Fenxiao();
+ $fenxiao_info = $fenxiao_model->getFenxiaoInfo(
+ [
+ [ 'member_id', '=', $member_id ],
+ [ 'site_id', '=', $site_id ]
+ ],
+ 'account,account_withdraw,account_withdraw_apply,total_commission'
+ );
+ $data[ 'fenxiao_info' ] = $fenxiao_info[ 'data' ];
+
+ //分销待结算订单
+ $fenxiao_order_model = new FenxiaoOrder();
+ $fenxiao_order_count = $fenxiao_order_model->getFenxiaoOrderCount(
+ [
+ [ 'member_id', '=', $member_id ],
+ [ 'site_id', '=', $site_id ],
+ [ 'is_settlement', '=', 0 ]
+ ]
+ );
+ $data[ 'fenxiao_order_count' ] = $fenxiao_order_count[ 'data' ];
+ }
+
+ return $this->success($data);
+ }
+
+ /****************************************** 会员注销通知 start **********************************************/
+
+ /**
+ * 会员注销成功
+ * @param $data
+ * @return array
+ */
+ public function memberCancelSuccess($data)
+ {
+ $member_cancel = model('member_cancel')->getInfo(
+ [
+ [ 'member_id', '=', $data[ 'member_id' ] ],
+ [ 'site_id', '=', $data[ 'site_id' ] ]
+ ]
+ );
+ if (empty($member_cancel)) {
+ return $this->success();
+ }
+ $member_info = model('member')->getInfo([ [ 'member_id', '=', $data[ 'member_id' ] ] ], 'username,mobile,nickname');
+
+ //发送短信
+ $sms_model = new Sms();
+
+ $name = $member_info[ "nickname" ] == '' ? $member_info[ "mobile" ] : $member_info[ "nickname" ];
+ $var_parse = array (
+ "username" => $name,
+ );
+
+ $data[ "sms_account" ] = $member_info[ "mobile" ] ?? '';//手机号
+ $data[ "var_parse" ] = $var_parse;
+ $sms_result = $sms_model->sendMessage($data);
+
+ return $this->success();
+ }
+
+ /**
+ * 会员注销失败
+ * @param $data
+ * @return array
+ */
+ public function memberCancelFail($data)
+ {
+ $member_cancel = model('member_cancel')->getInfo(
+ [
+ [ 'member_id', '=', $data[ 'member_id' ] ],
+ [ 'site_id', '=', $data[ 'site_id' ] ]
+ ]
+ );
+ if (empty($member_cancel)) {
+ return $this->success();
+ }
+ $member_info = model('member')->getInfo([ [ 'member_id', '=', $data[ 'member_id' ] ] ], 'username,mobile,nickname');
+
+ //发送短信
+ $sms_model = new Sms();
+
+ $name = $member_info[ "nickname" ] == '' ? $member_info[ "mobile" ] : $member_info[ "nickname" ];
+ $var_parse = array (
+ "username" => $name,
+ );
+
+ $data[ "sms_account" ] = $member_info[ "mobile" ] ?? '';//手机号
+ $data[ "var_parse" ] = $var_parse;
+ $sms_result = $sms_model->sendMessage($data);
+
+ return $this->success();
+ }
+
+ /**
+ * 会员注销申请通知(店铺)
+ * @param $data
+ * @return array
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function memberCancelApply($data)
+ {
+ $member_cancel = model('member_cancel')->getInfo(
+ [
+ [ 'member_id', '=', $data[ 'member_id' ] ],
+ [ 'site_id', '=', $data[ 'site_id' ] ]
+ ]
+ );
+ if (empty($member_cancel)) {
+ return $this->success();
+ }
+ $member_info = model('member')->getInfo([ [ 'member_id', '=', $data[ 'member_id' ] ] ], 'username,mobile,nickname');
+ $name = $member_info[ "nickname" ] == '' ? $member_info[ "mobile" ] : $member_info[ "nickname" ];
+ //发送短信
+ $sms_model = new Sms();
+
+ $var_parse = array (
+ "username" => $name,
+ );
+// $site_id = $data['site_id'];
+// $shop_info = model("shop")->getInfo([["site_id", "=", $site_id]], "mobile,email");
+// $message_data["sms_account"] = $shop_info["mobile"];//手机号
+ $data[ "var_parse" ] = $var_parse;
+
+ $shop_accept_message_model = new ShopAcceptMessage();
+ $result = $shop_accept_message_model->getShopAcceptMessageList();
+ $list = $result[ 'data' ];
+ if (!empty($list)) {
+ foreach ($list as $v) {
+ $message_data = $data;
+ $message_data[ "sms_account" ] = $v[ "mobile" ];//手机号
+ $sms_model->sendMessage($message_data);
+
+ if ($v[ 'wx_openid' ] != '') {
+ $wechat_model = new WechatMessage();
+ $data[ "openid" ] = $v[ 'wx_openid' ];
+ $data[ "template_data" ] = [
+ 'thing2' => replaceSpecialChar($name), // 申请人
+ 'time4' => time_to_date(time()) // 注销时间
+ ];
+
+ $data[ "page" ] = "";
+ $wechat_model->sendMessage($data);
+ }
+ }
+ }
+ }
+
+ /****************************************** 会员注销通知 end ************************************************/
}
\ No newline at end of file
diff --git a/src/addon/membercancel/shop/controller/Membercancel.php b/src/addon/membercancel/shop/controller/Membercancel.php
index 95ab355b7..526517c05 100644
--- a/src/addon/membercancel/shop/controller/Membercancel.php
+++ b/src/addon/membercancel/shop/controller/Membercancel.php
@@ -1,166 +1,158 @@
-isJson()) {
-
- $page = input('page', 1);
- $page_size = input('page_size', PAGE_LIST_ROWS);
-
- $condition = [ [ 'site_id', '=', $this->site_id ] ];
-
- $search_text = input('search_text', '');
- $search_type = input('search_type', '');
- if (!empty($search_text)) {
- $condition[] = [
- $search_type, 'like', '%' . $search_text . '%'
- ];
- }
- //状态
- $status = input('status', '');
- if ($status !== '') {
- $condition[] = [ 'status', '=', $status ];
- }
- //注销时间
- $start_time = input('start_time', '');
- $end_time = input('end_time', '');
- if ($start_time && $end_time) {
- $condition[] = [ 'create_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
- } elseif (!$start_time && $end_time) {
- $condition[] = [ 'create_time', '<=', date_to_time($end_time) ];
-
- } elseif ($start_time && !$end_time) {
- $condition[] = [ 'create_time', '>=', date_to_time($start_time) ];
- }
-
- $member_cancel_model = new MemberCancelModel();
- $list = $member_cancel_model->getMemberCancelPageList($condition, $page, $page_size);
- return $list;
- } else {
-
- //筛选条件
- $search_type = [
- 'username' => '会员账号',
- 'mobile' => '手机号',
- 'nickname' => '昵称'
- ];
- $this->assign('search_type', $search_type);
-
- return $this->fetch('membercancel/lists');
- }
- }
-
- /**
- * 审核通过
- */
- public function auditPass()
- {
- if (request()->isJson()) {
-
- $id = input('id', '');
-
- $data = [
- 'id' => $id,
- 'site_id' => $this->site_id,
- 'audit_uid' => $this->user_info[ 'uid' ],
- 'audit_username' => $this->user_info[ 'username' ]
- ];
-
- $member_cancel_model = new MemberCancelModel();
- $res = $member_cancel_model->memberCancelAuditPass($data);
- return $res;
- }
- }
-
- /**
- * 审核失败
- */
- public function auditRefuse()
- {
- if (request()->isJson()) {
-
- $id = input('id', '');
- $reason = input('reason', '');
- $data = [
- 'id' => $id,
- 'site_id' => $this->site_id,
- 'audit_uid' => $this->user_info[ 'uid' ],
- 'audit_username' => $this->user_info[ 'username' ],
- 'reason' => $reason
- ];
-
- $member_cancel_model = new MemberCancelModel();
- $res = $member_cancel_model->memberCancelAuditRefuse($data);
- return $res;
- }
- }
-
- /**
- * 注销协议
- */
- public function cancelAgreement()
- {
- if (request()->isJson()) {
- //设置注销协议
- $title = input('title', '');
- $content = input('content', '');
- $config_model = new ConfigModel();
- return $config_model->setCancelDocument($title, $content, $this->site_id, 'shop');
- } else {
- //获取注销协议
- $config_model = new ConfigModel();
- $document_info = $config_model->getCancelDocument($this->site_id, 'shop');
- $this->assign('document_info', $document_info);
-
- return $this->fetch('membercancel/cancel_agreement');
- }
- }
-
- /**
- * 注销设置
- */
- public function cancelConfig()
- {
- $config_model = new ConfigModel();
- if (request()->isJson()) {
- //设置注册设置
- $data = array (
- 'is_enable' => input('is_enable', 0),
- 'is_audit' => input('is_audit', 1),
- );
- return $config_model->setCancelConfig($data, $this->site_id, 'shop');
- } else {
- //获取注册设置
- $config_info = $config_model->getCancelConfig($this->site_id, 'shop');
- $value = $config_info[ 'data' ][ 'value' ];
-
- $this->assign('value', $value);
-
- return $this->fetch('membercancel/cancel_config');
- }
- }
-
+isJson()) {
+
+ $page = input('page', 1);
+ $page_size = input('page_size', PAGE_LIST_ROWS);
+
+ $condition = [ [ 'site_id', '=', $this->site_id ] ];
+
+ $search_text = input('search_text', '');
+ $search_type = input('search_type', '');
+ if (!empty($search_text)) {
+ $condition[] = [
+ $search_type, 'like', '%' . $search_text . '%'
+ ];
+ }
+ //状态
+ $status = input('status', '');
+ if ($status !== '') {
+ $condition[] = [ 'status', '=', $status ];
+ }
+ //注销时间
+ $start_time = input('start_time', '');
+ $end_time = input('end_time', '');
+ if ($start_time && $end_time) {
+ $condition[] = [ 'create_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
+ } elseif (!$start_time && $end_time) {
+ $condition[] = [ 'create_time', '<=', date_to_time($end_time) ];
+
+ } elseif ($start_time && !$end_time) {
+ $condition[] = [ 'create_time', '>=', date_to_time($start_time) ];
+ }
+
+ $member_cancel_model = new MemberCancelModel();
+ $list = $member_cancel_model->getMemberCancelPageList($condition, $page, $page_size);
+ return $list;
+ } else {
+
+ //筛选条件
+ $search_type = [
+ 'username' => '会员账号',
+ 'mobile' => '手机号',
+ 'nickname' => '昵称'
+ ];
+ $this->assign('search_type', $search_type);
+
+ return $this->fetch('membercancel/lists');
+ }
+ }
+
+ /**
+ * 审核通过
+ */
+ public function auditPass()
+ {
+ if (request()->isJson()) {
+
+ $id = input('id', '');
+
+ $data = [
+ 'id' => $id,
+ 'site_id' => $this->site_id,
+ 'audit_uid' => $this->user_info[ 'uid' ],
+ 'audit_username' => $this->user_info[ 'username' ]
+ ];
+
+ $member_cancel_model = new MemberCancelModel();
+ $res = $member_cancel_model->memberCancelAuditPass($data);
+ return $res;
+ }
+ }
+
+ /**
+ * 审核失败
+ */
+ public function auditRefuse()
+ {
+ if (request()->isJson()) {
+
+ $id = input('id', '');
+ $reason = input('reason', '');
+ $data = [
+ 'id' => $id,
+ 'site_id' => $this->site_id,
+ 'audit_uid' => $this->user_info[ 'uid' ],
+ 'audit_username' => $this->user_info[ 'username' ],
+ 'reason' => $reason
+ ];
+
+ $member_cancel_model = new MemberCancelModel();
+ $res = $member_cancel_model->memberCancelAuditRefuse($data);
+ return $res;
+ }
+ }
+
+ /**
+ * 注销协议
+ */
+ public function cancelAgreement()
+ {
+ if (request()->isJson()) {
+ //设置注销协议
+ $title = input('title', '');
+ $content = input('content', '');
+ $config_model = new ConfigModel();
+ return $config_model->setCancelDocument($title, $content, $this->site_id, 'shop');
+ } else {
+ //获取注销协议
+ $config_model = new ConfigModel();
+ $document_info = $config_model->getCancelDocument($this->site_id, 'shop');
+ $this->assign('document_info', $document_info);
+
+ return $this->fetch('membercancel/cancel_agreement');
+ }
+ }
+
+ /**
+ * 注销设置
+ */
+ public function cancelConfig()
+ {
+ $config_model = new ConfigModel();
+ if (request()->isJson()) {
+ //设置注册设置
+ $data = array (
+ 'is_enable' => input('is_enable', 0),
+ 'is_audit' => input('is_audit', 1),
+ );
+ return $config_model->setCancelConfig($data, $this->site_id, 'shop');
+ } else {
+ //获取注册设置
+ $config_info = $config_model->getCancelConfig($this->site_id, 'shop');
+ $value = $config_info[ 'data' ][ 'value' ];
+
+ $this->assign('value', $value);
+
+ return $this->fetch('membercancel/cancel_config');
+ }
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/memberprice/config/diy_view.php b/src/addon/memberprice/config/diy_view.php
index c3c657905..e36ca9b7d 100644
--- a/src/addon/memberprice/config/diy_view.php
+++ b/src/addon/memberprice/config/diy_view.php
@@ -1,38 +1,30 @@
- '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
- 'template' => [],
-
- // 后台自定义组件——装修
- 'util' => [],
-
- // 自定义页面路径
- 'link' => [],
-
- // 自定义图标库
- 'icon_library' => [],
-
- // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
- 'component' => [],
-
- // uni-app 页面,多个逗号隔开
- 'pages' => [],
-
- // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
- 'info' => [],
-
- // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
- 'theme' => [],
-
- // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
- 'data' => []
+ '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
+ 'template' => [],
+
+ // 后台自定义组件——装修
+ 'util' => [],
+
+ // 自定义页面路径
+ 'link' => [],
+
+ // 自定义图标库
+ 'icon_library' => [],
+
+ // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
+ 'component' => [],
+
+ // uni-app 页面,多个逗号隔开
+ 'pages' => [],
+
+ // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
+ 'info' => [],
+
+ // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
+ 'theme' => [],
+
+ // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
+ 'data' => []
];
\ No newline at end of file
diff --git a/src/addon/memberprice/config/info.php b/src/addon/memberprice/config/info.php
index aa27c8365..bb53d666e 100644
--- a/src/addon/memberprice/config/info.php
+++ b/src/addon/memberprice/config/info.php
@@ -1,20 +1,12 @@
- 'memberprice',
- 'title' => '会员价',
- 'description' => '会员价',
- 'type' => 'tool', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
- 'status' => 1,
- 'author' => '',
- 'version' => '5.3.1',
- 'version_no' => '525231212001',
- 'content' => '',
+ 'memberprice',
+ 'title' => '会员价',
+ 'description' => '会员价',
+ 'type' => 'tool', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
+ 'status' => 1,
+ 'author' => '',
+ 'version' => '5.3.1',
+ 'version_no' => '525231212001',
+ 'content' => '',
];
\ No newline at end of file
diff --git a/src/addon/memberprice/event/Install.php b/src/addon/memberprice/event/Install.php
index 32999fd27..832e48c36 100644
--- a/src/addon/memberprice/event/Install.php
+++ b/src/addon/memberprice/event/Install.php
@@ -1,25 +1,17 @@
- "会员价", "type" => "memberprice" ];
- }
+ "会员价", "type" => "memberprice" ];
+ }
}
\ No newline at end of file
diff --git a/src/addon/memberprice/event/UnInstall.php b/src/addon/memberprice/event/UnInstall.php
index 1cbd1e208..ae2c54a02 100644
--- a/src/addon/memberprice/event/UnInstall.php
+++ b/src/addon/memberprice/event/UnInstall.php
@@ -1,25 +1,17 @@
-startTrans();
- try {
-
- model('goods')->update($data, $condition);
- if ($data[ 'discount_config' ] == 1) {
- foreach ($member_price as $k => $v) {
- $sku_condition = $condition;
- $data[ 'member_price' ] = json_encode($v);
- $sku_condition[] = [ 'sku_id', '=', $k ];
- model('goods_sku')->update($data, $sku_condition);
- }
-
- } else {
- $data[ 'member_price' ] = '';
- model('goods_sku')->update($data, $condition);
- }
- model('goods')->commit();
- return $this->success();
- } catch (\Exception $e) {
- model('goods')->rollback();
- return $this->error('', $e->getMessage());
- }
-
- }
-
+startTrans();
+ try {
+
+ model('goods')->update($data, $condition);
+ if ($data[ 'discount_config' ] == 1) {
+ foreach ($member_price as $k => $v) {
+ $sku_condition = $condition;
+ $data[ 'member_price' ] = json_encode($v);
+ $sku_condition[] = [ 'sku_id', '=', $k ];
+ model('goods_sku')->update($data, $sku_condition);
+ }
+
+ } else {
+ $data[ 'member_price' ] = '';
+ model('goods_sku')->update($data, $condition);
+ }
+ model('goods')->commit();
+ return $this->success();
+ } catch (\Exception $e) {
+ model('goods')->rollback();
+ return $this->error('', $e->getMessage());
+ }
+
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/memberprice/shop/controller/Goods.php b/src/addon/memberprice/shop/controller/Goods.php
index 8d07407b1..c203b486a 100644
--- a/src/addon/memberprice/shop/controller/Goods.php
+++ b/src/addon/memberprice/shop/controller/Goods.php
@@ -1,62 +1,54 @@
-getGoodsDetail($goods_id);
- $this->assign('goods_info', $goods_info[ 'data' ]);
-
- //会员等级
- $member_level_model = new MemberLevel();
- $condition = [ [ 'site_id', '=', $this->site_id ] ];
- $order = 'level_type asc,growth asc';
- $field = '*';
- $level_list = $member_level_model->getMemberLevelList($condition, $field, $order);
- $this->assign('level_list', $level_list[ 'data' ]);
-
- if (request()->isJson()) {
-
- $goods_sku_model = new MemberPrice();
- $data = [
- 'is_consume_discount' => input('is_consume_discount', 0),
- 'discount_config' => input('discount_config', 0),
- 'discount_method' => input('discount_method', ''),
- ];
- $member_price = input('member_price', '');
- $goods_id = input('goods_id');
- $condition[] = [ 'goods_id', '=', $goods_id ];
- $condition[] = [ 'site_id', '=', $this->site_id ];
-
- return $goods_sku_model->editGoodsMemberPrice($condition, $data, $member_price);
- }
-
- return $this->fetch('goods/config');
- }
-
+getGoodsDetail($goods_id);
+ $this->assign('goods_info', $goods_info[ 'data' ]);
+
+ //会员等级
+ $member_level_model = new MemberLevel();
+ $condition = [ [ 'site_id', '=', $this->site_id ] ];
+ $order = 'level_type asc,growth asc';
+ $field = '*';
+ $level_list = $member_level_model->getMemberLevelList($condition, $field, $order);
+ $this->assign('level_list', $level_list[ 'data' ]);
+
+ if (request()->isJson()) {
+
+ $goods_sku_model = new MemberPrice();
+ $data = [
+ 'is_consume_discount' => input('is_consume_discount', 0),
+ 'discount_config' => input('discount_config', 0),
+ 'discount_method' => input('discount_method', ''),
+ ];
+ $member_price = input('member_price', '');
+ $goods_id = input('goods_id');
+ $condition[] = [ 'goods_id', '=', $goods_id ];
+ $condition[] = [ 'site_id', '=', $this->site_id ];
+
+ return $goods_sku_model->editGoodsMemberPrice($condition, $data, $member_price);
+ }
+
+ return $this->fetch('goods/config');
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/memberrecharge/api/controller/Memberrecharge.php b/src/addon/memberrecharge/api/controller/Memberrecharge.php
index ec28f2633..b49e678bd 100644
--- a/src/addon/memberrecharge/api/controller/Memberrecharge.php
+++ b/src/addon/memberrecharge/api/controller/Memberrecharge.php
@@ -1,59 +1,51 @@
-params['recharge_id'] ?? 0;
- if (empty($recharge_id)) {
- return $this->response($this->error('', 'REQUEST_RECHARGE_ID'));
- }
- $field = 'recharge_id,recharge_name,cover_img,face_value,buy_price,point,growth,coupon_id,sale_num,status';
- $member_recharge_model = new MemberRechargeModel();
- $info = $member_recharge_model->getMemberRechargeInfo([ [ 'recharge_id', '=', $recharge_id ], [ 'site_id', '=', $this->site_id ] ], $field);
- return $this->response($info);
- }
-
- /**
- * 会员充值配置
- */
- public function config()
- {
- $member_recharge_model = new MemberRechargeModel();
- $res = $member_recharge_model->getConfig($this->site_id);
- return $this->response($res);
- }
-
- /**
- * 计算信息
- */
- public function page()
- {
- $page = $this->params['page'] ?? 1;
- $page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
- $field = 'recharge_id,recharge_name,cover_img,face_value,buy_price,point,growth,coupon_id,sale_num';
- $member_recharge_model = new MemberRechargeModel();
- $list = $member_recharge_model->getMemberRechargePageList([ [ 'status', '=', 1 ], [ 'site_id', '=', $this->site_id ] ], $page, $page_size, 'create_time desc', $field);
- return $this->response($list);
- }
+params['recharge_id'] ?? 0;
+ if (empty($recharge_id)) {
+ return $this->response($this->error('', 'REQUEST_RECHARGE_ID'));
+ }
+ $field = 'recharge_id,recharge_name,cover_img,face_value,buy_price,point,growth,coupon_id,sale_num,status';
+ $member_recharge_model = new MemberRechargeModel();
+ $info = $member_recharge_model->getMemberRechargeInfo([ [ 'recharge_id', '=', $recharge_id ], [ 'site_id', '=', $this->site_id ] ], $field);
+ return $this->response($info);
+ }
+
+ /**
+ * 会员充值配置
+ */
+ public function config()
+ {
+ $member_recharge_model = new MemberRechargeModel();
+ $res = $member_recharge_model->getConfig($this->site_id);
+ return $this->response($res);
+ }
+
+ /**
+ * 计算信息
+ */
+ public function page()
+ {
+ $page = $this->params['page'] ?? 1;
+ $page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
+ $field = 'recharge_id,recharge_name,cover_img,face_value,buy_price,point,growth,coupon_id,sale_num';
+ $member_recharge_model = new MemberRechargeModel();
+ $list = $member_recharge_model->getMemberRechargePageList([ [ 'status', '=', 1 ], [ 'site_id', '=', $this->site_id ] ], $page, $page_size, 'create_time desc', $field);
+ return $this->response($list);
+ }
}
\ No newline at end of file
diff --git a/src/addon/memberrecharge/api/controller/Order.php b/src/addon/memberrecharge/api/controller/Order.php
index b12c7d46d..05dcec3ff 100644
--- a/src/addon/memberrecharge/api/controller/Order.php
+++ b/src/addon/memberrecharge/api/controller/Order.php
@@ -1,41 +1,33 @@
-checkToken();
- if ($token[ 'code' ] < 0) return $this->response($token);
- $page = $this->params['page'] ?? 1;
- $page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
- $field = 'order_id,recharge_id,recharge_name,order_no,cover_img,buy_price,create_time,out_trade_no,face_value,point,growth,coupon_id';
- $member_recharge_order_model = new MemberRechargeOrderModel();
- $condition = array (
- [ 'status', '=', 2 ],
- [ 'member_id', '=', $this->member_id ],
- [ 'site_id', '=', $this->site_id ]
- );
- $list = $member_recharge_order_model->getMemberRechargeOrderPageList($condition, $page, $page_size, 'create_time desc', $field);
- return $this->response($list);
- }
+checkToken();
+ if ($token[ 'code' ] < 0) return $this->response($token);
+ $page = $this->params['page'] ?? 1;
+ $page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
+ $field = 'order_id,recharge_id,recharge_name,order_no,cover_img,buy_price,create_time,out_trade_no,face_value,point,growth,coupon_id';
+ $member_recharge_order_model = new MemberRechargeOrderModel();
+ $condition = array (
+ [ 'status', '=', 2 ],
+ [ 'member_id', '=', $this->member_id ],
+ [ 'site_id', '=', $this->site_id ]
+ );
+ $list = $member_recharge_order_model->getMemberRechargeOrderPageList($condition, $page, $page_size, 'create_time desc', $field);
+ return $this->response($list);
+ }
}
\ No newline at end of file
diff --git a/src/addon/memberrecharge/config/diy_view.php b/src/addon/memberrecharge/config/diy_view.php
index c3c657905..e36ca9b7d 100644
--- a/src/addon/memberrecharge/config/diy_view.php
+++ b/src/addon/memberrecharge/config/diy_view.php
@@ -1,38 +1,30 @@
- '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
- 'template' => [],
-
- // 后台自定义组件——装修
- 'util' => [],
-
- // 自定义页面路径
- 'link' => [],
-
- // 自定义图标库
- 'icon_library' => [],
-
- // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
- 'component' => [],
-
- // uni-app 页面,多个逗号隔开
- 'pages' => [],
-
- // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
- 'info' => [],
-
- // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
- 'theme' => [],
-
- // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
- 'data' => []
+ '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
+ 'template' => [],
+
+ // 后台自定义组件——装修
+ 'util' => [],
+
+ // 自定义页面路径
+ 'link' => [],
+
+ // 自定义图标库
+ 'icon_library' => [],
+
+ // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
+ 'component' => [],
+
+ // uni-app 页面,多个逗号隔开
+ 'pages' => [],
+
+ // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
+ 'info' => [],
+
+ // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
+ 'theme' => [],
+
+ // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
+ 'data' => []
];
\ No newline at end of file
diff --git a/src/addon/memberrecharge/config/info.php b/src/addon/memberrecharge/config/info.php
index 1cb5254e4..559215f50 100644
--- a/src/addon/memberrecharge/config/info.php
+++ b/src/addon/memberrecharge/config/info.php
@@ -1,21 +1,12 @@
- 'memberrecharge',
- 'title' => '充值礼包',
- 'description' => '会员充值设置',
- 'type' => 'tool', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
- 'status' => 1,
- 'author' => '',
- 'version' => '5.3.1',
- 'version_no' => '525231212001',
- 'content' => '',
+ 'memberrecharge',
+ 'title' => '充值礼包',
+ 'description' => '会员充值设置',
+ 'type' => 'tool', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
+ 'status' => 1,
+ 'author' => '',
+ 'version' => '5.3.1',
+ 'version_no' => '525231212001',
+ 'content' => '',
];
\ No newline at end of file
diff --git a/src/addon/memberrecharge/event/IncomeStatistics.php b/src/addon/memberrecharge/event/IncomeStatistics.php
index 2d0e52a46..e5140f695 100644
--- a/src/addon/memberrecharge/event/IncomeStatistics.php
+++ b/src/addon/memberrecharge/event/IncomeStatistics.php
@@ -1,33 +1,24 @@
-getOrderSum([ ['site_id', '=', $param['site_id'] ], ['pay_time', 'between', [$param['start_time'], $param['end_time']] ] ], 'buy_price')['data'];
- return [
- [
- 'title' => '会员充值',
- 'value' => $money,
- 'desc' => '统计时间内,所有会员充值金额之和',
- 'url' => 'memberrecharge://shop/memberrecharge/orderlists'
- ]
- ];
- }
+getOrderSum([ ['site_id', '=', $param['site_id'] ], ['pay_time', 'between', [$param['start_time'], $param['end_time']] ] ], 'buy_price')['data'];
+ return [
+ [
+ 'title' => '会员充值',
+ 'value' => $money,
+ 'desc' => '统计时间内,所有会员充值金额之和',
+ 'url' => 'memberrecharge://shop/memberrecharge/orderlists'
+ ]
+ ];
+ }
}
\ No newline at end of file
diff --git a/src/addon/memberrecharge/event/Install.php b/src/addon/memberrecharge/event/Install.php
index 7151d0b2d..1f9ff60b0 100644
--- a/src/addon/memberrecharge/event/Install.php
+++ b/src/addon/memberrecharge/event/Install.php
@@ -1,26 +1,17 @@
- [
- 'memberrecharge' => [
- 'type_name' => '会员充值',
- 'admin_url' => 'admin/order/detail',
- 'tag_name' => 'order_id'
- ],
- ],
- 'point' => [
- 'memberrecharge' => [
- 'type_name' => '会员充值',
- 'type_url' => '',
- ],
-
- ],
- 'growth' => [
- 'memberrecharge' => [
- 'type_name' => '会员充值',
- 'type_url' => '',
- ],
- ],
- ];
- if ($data == '') {
- return $from_type;
- } else {
- return $from_type[$data] ?? [];
- }
-
- }
+ [
+ 'memberrecharge' => [
+ 'type_name' => '会员充值',
+ 'admin_url' => 'admin/order/detail',
+ 'tag_name' => 'order_id'
+ ],
+ ],
+ 'point' => [
+ 'memberrecharge' => [
+ 'type_name' => '会员充值',
+ 'type_url' => '',
+ ],
+
+ ],
+ 'growth' => [
+ 'memberrecharge' => [
+ 'type_name' => '会员充值',
+ 'type_url' => '',
+ ],
+ ],
+ ];
+ if ($data == '') {
+ return $from_type;
+ } else {
+ return $from_type[$data] ?? [];
+ }
+
+ }
}
\ No newline at end of file
diff --git a/src/addon/memberrecharge/event/MemberrechargeOrderClose.php b/src/addon/memberrecharge/event/MemberrechargeOrderClose.php
index 07765a4b7..65f4fdd9d 100644
--- a/src/addon/memberrecharge/event/MemberrechargeOrderClose.php
+++ b/src/addon/memberrecharge/event/MemberrechargeOrderClose.php
@@ -1,28 +1,19 @@
-cronMemberRechargeOrderClose($params['relate_id']);
- return $res;
- }
+cronMemberRechargeOrderClose($params['relate_id']);
+ return $res;
+ }
}
\ No newline at end of file
diff --git a/src/addon/memberrecharge/event/MemberrechargeOrderPayNotify.php b/src/addon/memberrecharge/event/MemberrechargeOrderPayNotify.php
index dbf151719..6974b3014 100644
--- a/src/addon/memberrecharge/event/MemberrechargeOrderPayNotify.php
+++ b/src/addon/memberrecharge/event/MemberrechargeOrderPayNotify.php
@@ -1,28 +1,20 @@
-orderPay($data);
- return $res;
- }
-
+orderPay($data);
+ return $res;
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/memberrecharge/event/PrinterContent.php b/src/addon/memberrecharge/event/PrinterContent.php
index df34bef60..30fc26084 100644
--- a/src/addon/memberrecharge/event/PrinterContent.php
+++ b/src/addon/memberrecharge/event/PrinterContent.php
@@ -1,125 +1,117 @@
-getMemberRechargeOrderInfo([ [ 'order_id', '=', $order_id ] ])[ 'data' ];
- $params[ 'site_id' ] = $order_info[ 'site_id' ] ?? 0;
-
- $member = new Member();
- $member_info = $member->getMemberInfo([ [ 'member_id', '=', $order_info[ 'member_id' ] ] ], 'balance, balance_money')[ 'data' ] ?? [];
- $account = number_format($member_info[ 'balance' ] + $member_info[ 'balance_money' ], 2, '.', '');
-
- //获取店铺信息
- $shop_model = new Shop();
- $shop_info = $shop_model->getShopInfo([ [ 'site_id', '=', $params[ 'site_id' ] ] ])[ 'data' ];
-
- $site_name = ( new Site() )->getSiteInfo([ [ 'site_id', '=', $params[ 'site_id' ] ] ], 'site_name')[ 'data' ][ 'site_name' ] ?? '';
-
- //获取打印机列表
- $print_model = new Printer();
- $printer_data = $print_model->getPrinterList([ [ 'site_id', '=', $params[ 'site_id' ] ], [ 'store_id', '=', $order_info[ 'store_id' ] ], [ 'recharge_open', '=', 1 ] ])[ 'data' ] ?? [];
-
- $res_data = [];
-
- foreach ($printer_data as $k => $v) {
- //此处应该根据打印机不同分别设置返回不同的数据。当前为易联云
- $array = [];
- $array[ 'printer_info' ] = $v;
- $print_template_model = new PrinterTemplate();
-
- $template_id = $v[ 'recharge_template_id' ];
-
- $print_template = $print_template_model->getPrinterTemplateInfo([ [ 'template_id', '=', $template_id ] ])[ 'data' ];
-
- $array[ 'printer_code' ] = $v[ 'printer_code' ]; //商户授权机器码
- $array[ 'origin_id' ] = $order_info[ 'order_no' ]; //内部订单号(32位以内)
- /**文本接口开始**/
- $content = "" . $v[ 'recharge_print_num' ] . "";
- //小票名称
- if ($print_template[ 'title' ] != '') {
- $content .= "
" . $print_template[ 'title' ] . "";
- $content .= str_repeat('.', 32);
- }
- //商城名称
- if ($print_template[ 'head' ] == 1) {
- $content .= "" . $site_name . "";
- $content .= str_repeat('.', 32);
- }
- $content .= "订单时间:" . date("Y-m-d H:i", $order_info[ 'pay_time' ]) . "\n";
- $content .= "订单编号:" . $order_info[ 'order_no' ] . "\n";
- $content .= "支付方式:" . $order_info[ 'pay_type_name' ] . "\n";
- $content .= str_repeat('.', 32);
-
- $content .= "充值金额:¥" . $order_info[ "face_value" ] . "\n";
- $content .= "实付金额:¥" . $order_info[ "price" ] . "\n";
- $content .= "会员余额:¥" . $account . "\n";
-
- /******************** 买家信息 **************************/
- //买家姓名
- if ($print_template[ 'buy_name' ] == 1) {
- $content .= "会员:" . $order_info[ "nickname" ] . "\n";
- $content .= str_repeat('.', 32);
- }
-
- /******************** 商城信息 **************************/
- //联系方式
- if ($print_template[ 'shop_mobile' ] == 1) {
- $content .= "" . $shop_info[ "mobile" ] . "\n";
- }
- //地址
- if ($print_template[ 'shop_address' ] == 1) {
- $content .= "" . $shop_info[ 'province_name' ] . $shop_info[ 'city_name' ] . $shop_info[ 'district_name' ] . $shop_info[ 'address' ] . "\n";
- }
-
- if ($print_template[ 'shop_mobile' ] == 1 || $print_template[ 'shop_address' ] == 1) {
- $content .= str_repeat('.', 32);
- }
- //二维码
- if ($print_template[ 'shop_qrcode' ] == 1) {
- $content .= "" . $print_template[ 'qrcode_url' ] . "";
- $content .= str_repeat('.', 32);
- }
-
- //底部内容
- if (!empty($print_template[ 'bottom' ])) {
-
- $content .= "" . $print_template[ 'bottom' ] . "";
- }
- $array[ 'content' ] = $content;
-
- $res_data[] = $array;
- }
-
- return $res_data;
-
- }
- }
+getMemberRechargeOrderInfo([ [ 'order_id', '=', $order_id ] ])[ 'data' ];
+ $params[ 'site_id' ] = $order_info[ 'site_id' ] ?? 0;
+
+ $member = new Member();
+ $member_info = $member->getMemberInfo([ [ 'member_id', '=', $order_info[ 'member_id' ] ] ], 'balance, balance_money')[ 'data' ] ?? [];
+ $account = number_format($member_info[ 'balance' ] + $member_info[ 'balance_money' ], 2, '.', '');
+
+ //获取店铺信息
+ $shop_model = new Shop();
+ $shop_info = $shop_model->getShopInfo([ [ 'site_id', '=', $params[ 'site_id' ] ] ])[ 'data' ];
+
+ $site_name = ( new Site() )->getSiteInfo([ [ 'site_id', '=', $params[ 'site_id' ] ] ], 'site_name')[ 'data' ][ 'site_name' ] ?? '';
+
+ //获取打印机列表
+ $print_model = new Printer();
+ $printer_data = $print_model->getPrinterList([ [ 'site_id', '=', $params[ 'site_id' ] ], [ 'store_id', '=', $order_info[ 'store_id' ] ], [ 'recharge_open', '=', 1 ] ])[ 'data' ] ?? [];
+
+ $res_data = [];
+
+ foreach ($printer_data as $k => $v) {
+ //此处应该根据打印机不同分别设置返回不同的数据。当前为易联云
+ $array = [];
+ $array[ 'printer_info' ] = $v;
+ $print_template_model = new PrinterTemplate();
+
+ $template_id = $v[ 'recharge_template_id' ];
+
+ $print_template = $print_template_model->getPrinterTemplateInfo([ [ 'template_id', '=', $template_id ] ])[ 'data' ];
+
+ $array[ 'printer_code' ] = $v[ 'printer_code' ]; //商户授权机器码
+ $array[ 'origin_id' ] = $order_info[ 'order_no' ]; //内部订单号(32位以内)
+ /**文本接口开始**/
+ $content = "" . $v[ 'recharge_print_num' ] . "";
+ //小票名称
+ if ($print_template[ 'title' ] != '') {
+ $content .= "" . $print_template[ 'title' ] . "";
+ $content .= str_repeat('.', 32);
+ }
+ //商城名称
+ if ($print_template[ 'head' ] == 1) {
+ $content .= "" . $site_name . "";
+ $content .= str_repeat('.', 32);
+ }
+ $content .= "订单时间:" . date("Y-m-d H:i", $order_info[ 'pay_time' ]) . "\n";
+ $content .= "订单编号:" . $order_info[ 'order_no' ] . "\n";
+ $content .= "支付方式:" . $order_info[ 'pay_type_name' ] . "\n";
+ $content .= str_repeat('.', 32);
+
+ $content .= "充值金额:¥" . $order_info[ "face_value" ] . "\n";
+ $content .= "实付金额:¥" . $order_info[ "price" ] . "\n";
+ $content .= "会员余额:¥" . $account . "\n";
+
+ /******************** 买家信息 **************************/
+ //买家姓名
+ if ($print_template[ 'buy_name' ] == 1) {
+ $content .= "会员:" . $order_info[ "nickname" ] . "\n";
+ $content .= str_repeat('.', 32);
+ }
+
+ /******************** 商城信息 **************************/
+ //联系方式
+ if ($print_template[ 'shop_mobile' ] == 1) {
+ $content .= "" . $shop_info[ "mobile" ] . "\n";
+ }
+ //地址
+ if ($print_template[ 'shop_address' ] == 1) {
+ $content .= "" . $shop_info[ 'province_name' ] . $shop_info[ 'city_name' ] . $shop_info[ 'district_name' ] . $shop_info[ 'address' ] . "\n";
+ }
+
+ if ($print_template[ 'shop_mobile' ] == 1 || $print_template[ 'shop_address' ] == 1) {
+ $content .= str_repeat('.', 32);
+ }
+ //二维码
+ if ($print_template[ 'shop_qrcode' ] == 1) {
+ $content .= "" . $print_template[ 'qrcode_url' ] . "";
+ $content .= str_repeat('.', 32);
+ }
+
+ //底部内容
+ if (!empty($print_template[ 'bottom' ])) {
+
+ $content .= "" . $print_template[ 'bottom' ] . "";
+ }
+ $array[ 'content' ] = $content;
+
+ $res_data[] = $array;
+ }
+
+ return $res_data;
+
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/memberrecharge/event/PrinterHtml.php b/src/addon/memberrecharge/event/PrinterHtml.php
index 592ef93c0..b299e98e0 100644
--- a/src/addon/memberrecharge/event/PrinterHtml.php
+++ b/src/addon/memberrecharge/event/PrinterHtml.php
@@ -1,26 +1,17 @@
-fetch('addon/memberrecharge/shop/view/template/printer_template.html');
- }
+fetch('addon/memberrecharge/shop/view/template/printer_template.html');
+ }
}
\ No newline at end of file
diff --git a/src/addon/memberrecharge/event/PrinterTemplateType.php b/src/addon/memberrecharge/event/PrinterTemplateType.php
index 09460c225..915be37a3 100644
--- a/src/addon/memberrecharge/event/PrinterTemplateType.php
+++ b/src/addon/memberrecharge/event/PrinterTemplateType.php
@@ -1,31 +1,22 @@
- 'recharge',
- 'type_name' => '会员充值',
- 'edit' => 'addon/memberrecharge/shop/view/template/recharge_template.html',
- 'add' => 'addon/memberrecharge/shop/view/template/recharge_template.html',
- ]
- ];
- }
+ 'recharge',
+ 'type_name' => '会员充值',
+ 'edit' => 'addon/memberrecharge/shop/view/template/recharge_template.html',
+ 'add' => 'addon/memberrecharge/shop/view/template/recharge_template.html',
+ ]
+ ];
+ }
}
\ No newline at end of file
diff --git a/src/addon/memberrecharge/event/PromotionType.php b/src/addon/memberrecharge/event/PromotionType.php
index 183225128..5d48cf576 100644
--- a/src/addon/memberrecharge/event/PromotionType.php
+++ b/src/addon/memberrecharge/event/PromotionType.php
@@ -1,27 +1,19 @@
- "充值礼包", "type" => "memberrecharge" ];
- }
+ "充值礼包", "type" => "memberrecharge" ];
+ }
}
\ No newline at end of file
diff --git a/src/addon/memberrecharge/event/ShowPromotion.php b/src/addon/memberrecharge/event/ShowPromotion.php
index 408f610e1..a661307ea 100644
--- a/src/addon/memberrecharge/event/ShowPromotion.php
+++ b/src/addon/memberrecharge/event/ShowPromotion.php
@@ -1,84 +1,76 @@
- [
- [
- //插件名称
- 'name' => 'memberrecharge',
- //展示分类(根据平台端设置,admin(平台营销),shop:店铺营销,member:会员营销, tool:应用工具)
- 'show_type' => 'member',
- //展示主题
- 'title' => '充值礼包',
- //展示介绍
- 'description' => '提高客户充值金额',
- //展示图标
- 'icon' => 'addon/memberrecharge/icon.png',
- //跳转链接
- 'url' => 'memberrecharge://shop/memberrecharge/lists',
- 'summary' => $this->summary($params)
- ]
- ]
-
- ];
- return $data;
- }
-
- private function summary($params)
- {
- if (empty($params)) {
- return [];
- }
-
- if(isset($params['promotion_type']) && $params['promotion_type'] != $this->promotion_type){
- return [];
- }
-
- if (isset($params[ 'count' ]) || isset($params[ 'summary' ])) $config = ( new Memberrecharge() )->getConfig($params[ 'site_id' ])[ 'data' ];
- //获取活动数量
- if (isset($params[ 'count' ])) {
- $count = model("member_recharge")->getCount([ [ 'site_id', '=', $params[ 'site_id' ] ] ]);
- return [
- 'count' => $count
- ];
- }
- //获取活动概况,需要获取开始时间与结束时间
- if (isset($params[ 'summary' ])) {
- $count = model("member_recharge")->getCount([ [ 'site_id', '=', $params[ 'site_id' ] ], [ 'status', '=', 1 ] ]);
-
- return [
- 'unlimited_time' => [
- 'status' => $config[ 'is_use' ],
- 'detail' => $count ? '已配置' . $count . '个充值套餐' : '未配置充值套餐',
- 'switch_type' => 'switch',
- 'config_key' => 'MEMBER_RECHARGE_CONFIG'
- ]
- ];
- }
- }
+ [
+ [
+ //插件名称
+ 'name' => 'memberrecharge',
+ //展示分类(根据平台端设置,admin(平台营销),shop:店铺营销,member:会员营销, tool:应用工具)
+ 'show_type' => 'member',
+ //展示主题
+ 'title' => '充值礼包',
+ //展示介绍
+ 'description' => '提高客户充值金额',
+ //展示图标
+ 'icon' => 'addon/memberrecharge/icon.png',
+ //跳转链接
+ 'url' => 'memberrecharge://shop/memberrecharge/lists',
+ 'summary' => $this->summary($params)
+ ]
+ ]
+
+ ];
+ return $data;
+ }
+
+ private function summary($params)
+ {
+ if (empty($params)) {
+ return [];
+ }
+
+ if(isset($params['promotion_type']) && $params['promotion_type'] != $this->promotion_type){
+ return [];
+ }
+
+ if (isset($params[ 'count' ]) || isset($params[ 'summary' ])) $config = ( new Memberrecharge() )->getConfig($params[ 'site_id' ])[ 'data' ];
+ //获取活动数量
+ if (isset($params[ 'count' ])) {
+ $count = model("member_recharge")->getCount([ [ 'site_id', '=', $params[ 'site_id' ] ] ]);
+ return [
+ 'count' => $count
+ ];
+ }
+ //获取活动概况,需要获取开始时间与结束时间
+ if (isset($params[ 'summary' ])) {
+ $count = model("member_recharge")->getCount([ [ 'site_id', '=', $params[ 'site_id' ] ], [ 'status', '=', 1 ] ]);
+
+ return [
+ 'unlimited_time' => [
+ 'status' => $config[ 'is_use' ],
+ 'detail' => $count ? '已配置' . $count . '个充值套餐' : '未配置充值套餐',
+ 'switch_type' => 'switch',
+ 'config_key' => 'MEMBER_RECHARGE_CONFIG'
+ ]
+ ];
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/memberrecharge/event/UnInstall.php b/src/addon/memberrecharge/event/UnInstall.php
index 3f63fceb9..c26d794c7 100644
--- a/src/addon/memberrecharge/event/UnInstall.php
+++ b/src/addon/memberrecharge/event/UnInstall.php
@@ -1,26 +1,17 @@
-getSiteInfo([ [ 'site_id', '=', $data[ 'site_id' ] ] ]);
- $card_account = substr(md5(date('YmdHis') . mt_rand(100, 999)), 8, 16);
- $card_data = [
- 'recharge_id' => $data[ 'recharge_id' ],
- 'site_id' => $data[ 'site_id' ],
- 'site_name' => $site_info[ 'data' ][ 'site_name' ],
- 'recharge_name' => $data[ 'recharge_name' ],
- 'card_account' => $card_account,
- 'cover_img' => $data[ 'cover_img' ],
- 'face_value' => $data[ 'face_value' ],
- 'point' => $data[ 'point' ],
- 'growth' => $data[ 'growth' ],
- 'coupon_id' => $data[ 'coupon_id' ],
- 'buy_price' => $data[ 'buy_price' ],
- 'member_id' => $data[ 'member_id' ],
- 'member_img' => $data[ 'member_img' ],
- 'nickname' => $data[ 'nickname' ],
- 'order_id' => $data[ 'order_id' ],
- 'order_no' => $data[ 'order_no' ],
- 'use_status' => $data[ 'use_status' ],
- 'create_time' => time(),
- 'use_time' => $data[ 'use_time' ]
- ];
- $res = model('member_recharge_card')->add($card_data);
- Cache::tag("member_recharge_card")->clear();
- return $this->success($res);
- }
-
- /**
- * 开卡发放礼包
- * @param $order_info
- */
- public function addMemberAccount($order_info)
- {
- $member_account = new MemberAccount();
- //修改用户的余额
- $member_account->addMemberAccount($order_info[ 'site_id' ], $order_info[ 'member_id' ], AccountDict::balance, $order_info[ 'face_value' ], 'memberrecharge', '0', '会员充值');
-
- //积分
- if ($order_info[ 'point' ] > 0) {
- $member_account->addMemberAccount($order_info[ 'site_id' ], $order_info[ 'member_id' ], 'point', $order_info[ 'point' ], 'memberrecharge', '0', '会员充值奖励');
- }
-
- //成长值
- if ($order_info[ 'growth' ] > 0) {
- $member_account->addMemberAccount($order_info[ 'site_id' ], $order_info[ 'member_id' ], 'growth', $order_info[ 'growth' ], 'memberrecharge', '0', '会员充值奖励');
- }
- //添加优惠券
- if (!empty($order_info[ 'coupon_id' ])) {
- $coupon_model = new Coupon();
- $coupon_id = explode(',', $order_info[ 'coupon_id' ]);
- $coupon_list = array_map(function($value) {
- return [ 'coupon_type_id' => $value, 'num' => 1 ];
- }, $coupon_id);
- $coupon_model->giveCoupon($coupon_list, $order_info[ 'site_id' ], $order_info[ 'member_id' ], 6);
- }
- }
-
- /**
- * 套餐详情
- * @param array $condition
- * @param string $field
- * @return array
- */
- public function getMemberRechargeCardInfo($condition = [], $field = '*')
- {
- $info = model('member_recharge_card')->getInfo($condition, $field);
- if ($info) {
- //获取优惠券信息
- if ($info[ 'coupon_id' ]) {
- //优惠券字段
- $coupon_field = '*';
- $model = new CouponType();
- $coupon_list = $model->getCouponTypeList([ [ 'coupon_type_id', 'in', $info[ 'coupon_id' ] ] ], $coupon_field);
- $info[ 'coupon_list' ] = $coupon_list[ 'data' ];
- }
- }
- Cache::tag("member_recharge_card")->clear();
- return $this->success($info);
- }
-
- /**
- * 开卡列表
- * @param array $condition
- * @param int $page
- * @param int $page_size
- * @param string $order
- * @param string $field
- * @return array
- */
- public function getMemberRechargeCardPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
- {
- $list = model('member_recharge_card')->pageList($condition, $field, $order, $page, $page_size);
-
- Cache::tag("member_recharge_card")->clear();
- return $this->success($list);
- }
-
+getSiteInfo([ [ 'site_id', '=', $data[ 'site_id' ] ] ]);
+ $card_account = substr(md5(date('YmdHis') . mt_rand(100, 999)), 8, 16);
+ $card_data = [
+ 'recharge_id' => $data[ 'recharge_id' ],
+ 'site_id' => $data[ 'site_id' ],
+ 'site_name' => $site_info[ 'data' ][ 'site_name' ],
+ 'recharge_name' => $data[ 'recharge_name' ],
+ 'card_account' => $card_account,
+ 'cover_img' => $data[ 'cover_img' ],
+ 'face_value' => $data[ 'face_value' ],
+ 'point' => $data[ 'point' ],
+ 'growth' => $data[ 'growth' ],
+ 'coupon_id' => $data[ 'coupon_id' ],
+ 'buy_price' => $data[ 'buy_price' ],
+ 'member_id' => $data[ 'member_id' ],
+ 'member_img' => $data[ 'member_img' ],
+ 'nickname' => $data[ 'nickname' ],
+ 'order_id' => $data[ 'order_id' ],
+ 'order_no' => $data[ 'order_no' ],
+ 'use_status' => $data[ 'use_status' ],
+ 'create_time' => time(),
+ 'use_time' => $data[ 'use_time' ]
+ ];
+ $res = model('member_recharge_card')->add($card_data);
+ Cache::tag("member_recharge_card")->clear();
+ return $this->success($res);
+ }
+
+ /**
+ * 开卡发放礼包
+ * @param $order_info
+ */
+ public function addMemberAccount($order_info)
+ {
+ $member_account = new MemberAccount();
+ //修改用户的余额
+ $member_account->addMemberAccount($order_info[ 'site_id' ], $order_info[ 'member_id' ], AccountDict::balance, $order_info[ 'face_value' ], 'memberrecharge', '0', '会员充值');
+
+ //积分
+ if ($order_info[ 'point' ] > 0) {
+ $member_account->addMemberAccount($order_info[ 'site_id' ], $order_info[ 'member_id' ], 'point', $order_info[ 'point' ], 'memberrecharge', '0', '会员充值奖励');
+ }
+
+ //成长值
+ if ($order_info[ 'growth' ] > 0) {
+ $member_account->addMemberAccount($order_info[ 'site_id' ], $order_info[ 'member_id' ], 'growth', $order_info[ 'growth' ], 'memberrecharge', '0', '会员充值奖励');
+ }
+ //添加优惠券
+ if (!empty($order_info[ 'coupon_id' ])) {
+ $coupon_model = new Coupon();
+ $coupon_id = explode(',', $order_info[ 'coupon_id' ]);
+ $coupon_list = array_map(function($value) {
+ return [ 'coupon_type_id' => $value, 'num' => 1 ];
+ }, $coupon_id);
+ $coupon_model->giveCoupon($coupon_list, $order_info[ 'site_id' ], $order_info[ 'member_id' ], 6);
+ }
+ }
+
+ /**
+ * 套餐详情
+ * @param array $condition
+ * @param string $field
+ * @return array
+ */
+ public function getMemberRechargeCardInfo($condition = [], $field = '*')
+ {
+ $info = model('member_recharge_card')->getInfo($condition, $field);
+ if ($info) {
+ //获取优惠券信息
+ if ($info[ 'coupon_id' ]) {
+ //优惠券字段
+ $coupon_field = '*';
+ $model = new CouponType();
+ $coupon_list = $model->getCouponTypeList([ [ 'coupon_type_id', 'in', $info[ 'coupon_id' ] ] ], $coupon_field);
+ $info[ 'coupon_list' ] = $coupon_list[ 'data' ];
+ }
+ }
+ Cache::tag("member_recharge_card")->clear();
+ return $this->success($info);
+ }
+
+ /**
+ * 开卡列表
+ * @param array $condition
+ * @param int $page
+ * @param int $page_size
+ * @param string $order
+ * @param string $field
+ * @return array
+ */
+ public function getMemberRechargeCardPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
+ {
+ $list = model('member_recharge_card')->pageList($condition, $field, $order, $page, $page_size);
+
+ Cache::tag("member_recharge_card")->clear();
+ return $this->success($list);
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/memberrecharge/model/Memberrecharge.php b/src/addon/memberrecharge/model/Memberrecharge.php
index 7db04fe28..25267a6f8 100644
--- a/src/addon/memberrecharge/model/Memberrecharge.php
+++ b/src/addon/memberrecharge/model/Memberrecharge.php
@@ -1,157 +1,149 @@
-add($data);
- Cache::tag("member_recharge")->clear();
- return $this->success($res);
- }
-
- /**
- * 编辑套餐
- * @param array $condition
- * @param $data
- * @return array
- */
- public function editMemberRecharge($condition, $data)
- {
- $data[ 'update_time' ] = time();
- $recharge_info = model('member_recharge')->getInfo($condition);
- if (!empty($recharge_info[ 'cover_img' ]) && !empty($data[ 'cover_img' ]) && $recharge_info[ 'cover_img' ] != $data[ 'cover_img' ]) {
- $upload_model = new Upload();
- $upload_model->deletePic($recharge_info[ 'cover_img' ], $recharge_info[ 'site_id' ]);
- }
-
- $res = model('member_recharge')->update($data, $condition);
- Cache::tag("member_recharge")->clear();
- return $this->success($res);
- }
-
- /**
- * 删除套餐详情
- * @param array $condition
- * @return mixed
- */
- public function deleteMemberRecharge($condition = [])
- {
- $recharge_info = model('member_recharge')->getInfo($condition);
- if (!empty($recharge_info[ 'cover_img' ])) {
- $upload_model = new Upload();
- $upload_model->deletePic($recharge_info[ 'cover_img' ], $recharge_info[ 'site_id' ]);
- }
- $res = model('member_recharge')->delete($condition);
- Cache::tag("member_recharge")->clear();
- return $this->success($res);
- }
-
- /**
- * 套餐详情
- * @param array $condition
- * @param string $field
- * @return array
- */
- public function getMemberRechargeInfo($condition = [], $field = '*')
- {
- $recharge = model('member_recharge')->getInfo($condition, $field);
- if ($recharge) {
- //获取优惠券信息
- if ($recharge[ 'coupon_id' ]) {
- //优惠券字段
- $coupon_field = 'coupon_type_id,coupon_name,money,count,lead_count,max_fetch,at_least,end_time,image,validity_type,fixed_term,type,discount';
-
- $model = new CouponType();
- $coupon = $model->getCouponTypeList([ [ 'coupon_type_id', 'in', $recharge[ 'coupon_id' ] ] ], $coupon_field);
- $recharge[ 'coupon_list' ] = $coupon[ 'data' ];
- }
- }
- Cache::tag("member_recharge")->clear();
- return $this->success($recharge);
- }
-
- /**
- * 套餐分页列表
- * @param array $condition
- * @param int $page
- * @param int $page_size
- * @param string $order
- * @param string $field
- * @return array
- */
- public function getMemberRechargePageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
- {
- $list = model('member_recharge')->pageList($condition, $field, $order, $page, $page_size);
-
- Cache::tag("member_recharge")->clear();
- return $this->success($list);
- }
-
- /**
- * 套餐列表
- * @param array $condition
- * @param string $order
- * @param string $field
- * @return array
- */
- public function getMemberRechargeList($condition = [], $order = '', $field = '*')
- {
- $list = model('member_recharge')->getList($condition, $field, $order);
- return $this->success($list);
- }
-
- /**
- * 设置会员充值配置
- * @param $data
- * @param $is_use
- * @param $site_id
- * @return array
- */
- public function setConfig($data, $is_use, $site_id)
- {
- $config = new ConfigModel();
- $res = $config->setConfig($data, '会员充值配置', $is_use, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'MEMBER_RECHARGE_CONFIG' ] ]);
- return $res;
- }
-
- /**
- * 获取会员充值配置
- * @param $site_id
- * @return array
- */
- public function getConfig($site_id)
- {
- $config = new ConfigModel();
- $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'MEMBER_RECHARGE_CONFIG' ] ]);
- return $res;
- }
-
+add($data);
+ Cache::tag("member_recharge")->clear();
+ return $this->success($res);
+ }
+
+ /**
+ * 编辑套餐
+ * @param array $condition
+ * @param $data
+ * @return array
+ */
+ public function editMemberRecharge($condition, $data)
+ {
+ $data[ 'update_time' ] = time();
+ $recharge_info = model('member_recharge')->getInfo($condition);
+ if (!empty($recharge_info[ 'cover_img' ]) && !empty($data[ 'cover_img' ]) && $recharge_info[ 'cover_img' ] != $data[ 'cover_img' ]) {
+ $upload_model = new Upload();
+ $upload_model->deletePic($recharge_info[ 'cover_img' ], $recharge_info[ 'site_id' ]);
+ }
+
+ $res = model('member_recharge')->update($data, $condition);
+ Cache::tag("member_recharge")->clear();
+ return $this->success($res);
+ }
+
+ /**
+ * 删除套餐详情
+ * @param array $condition
+ * @return mixed
+ */
+ public function deleteMemberRecharge($condition = [])
+ {
+ $recharge_info = model('member_recharge')->getInfo($condition);
+ if (!empty($recharge_info[ 'cover_img' ])) {
+ $upload_model = new Upload();
+ $upload_model->deletePic($recharge_info[ 'cover_img' ], $recharge_info[ 'site_id' ]);
+ }
+ $res = model('member_recharge')->delete($condition);
+ Cache::tag("member_recharge")->clear();
+ return $this->success($res);
+ }
+
+ /**
+ * 套餐详情
+ * @param array $condition
+ * @param string $field
+ * @return array
+ */
+ public function getMemberRechargeInfo($condition = [], $field = '*')
+ {
+ $recharge = model('member_recharge')->getInfo($condition, $field);
+ if ($recharge) {
+ //获取优惠券信息
+ if ($recharge[ 'coupon_id' ]) {
+ //优惠券字段
+ $coupon_field = 'coupon_type_id,coupon_name,money,count,lead_count,max_fetch,at_least,end_time,image,validity_type,fixed_term,type,discount';
+
+ $model = new CouponType();
+ $coupon = $model->getCouponTypeList([ [ 'coupon_type_id', 'in', $recharge[ 'coupon_id' ] ] ], $coupon_field);
+ $recharge[ 'coupon_list' ] = $coupon[ 'data' ];
+ }
+ }
+ Cache::tag("member_recharge")->clear();
+ return $this->success($recharge);
+ }
+
+ /**
+ * 套餐分页列表
+ * @param array $condition
+ * @param int $page
+ * @param int $page_size
+ * @param string $order
+ * @param string $field
+ * @return array
+ */
+ public function getMemberRechargePageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
+ {
+ $list = model('member_recharge')->pageList($condition, $field, $order, $page, $page_size);
+
+ Cache::tag("member_recharge")->clear();
+ return $this->success($list);
+ }
+
+ /**
+ * 套餐列表
+ * @param array $condition
+ * @param string $order
+ * @param string $field
+ * @return array
+ */
+ public function getMemberRechargeList($condition = [], $order = '', $field = '*')
+ {
+ $list = model('member_recharge')->getList($condition, $field, $order);
+ return $this->success($list);
+ }
+
+ /**
+ * 设置会员充值配置
+ * @param $data
+ * @param $is_use
+ * @param $site_id
+ * @return array
+ */
+ public function setConfig($data, $is_use, $site_id)
+ {
+ $config = new ConfigModel();
+ $res = $config->setConfig($data, '会员充值配置', $is_use, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'MEMBER_RECHARGE_CONFIG' ] ]);
+ return $res;
+ }
+
+ /**
+ * 获取会员充值配置
+ * @param $site_id
+ * @return array
+ */
+ public function getConfig($site_id)
+ {
+ $config = new ConfigModel();
+ $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'MEMBER_RECHARGE_CONFIG' ] ]);
+ return $res;
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/memberrecharge/model/MemberrechargeOrder.php b/src/addon/memberrecharge/model/MemberrechargeOrder.php
index b922b46db..7c79386fb 100644
--- a/src/addon/memberrecharge/model/MemberrechargeOrder.php
+++ b/src/addon/memberrecharge/model/MemberrechargeOrder.php
@@ -1,307 +1,299 @@
-pay_type;
- //获取当前所有在线支付方式
- $onlinepay = event('PayType');
- if (!empty($onlinepay)) {
- foreach ($onlinepay as $k => $v) {
- $pay_type[ $v[ 'pay_type' ] ] = $v[ 'pay_type_name' ];
- }
- }
- $trade_pay_type_list = event('TradePayType', []);
- if (!empty($trade_pay_type_list)) {
- foreach ($trade_pay_type_list as $k => $v) {
- if (!empty($v)) {
- $pay_type = array_merge($pay_type, $v);
- }
- }
- }
- return $pay_type;
- }
-
- /**
- * 订单详情
- * @param array $condition
- * @param string $field
- * @param string $alias
- * @param array $join
- * @return array
- */
- public function getMemberRechargeOrderInfo($condition = [], $field = '*', $alias = 'a', $join = [])
- {
- $order = model('member_recharge_order')->getInfo($condition, $field, $alias, $join);
- if ($order) {
- //获取优惠券信息
- $coupon_id = $order[ 'coupon_id' ] ?? 0;
- if ($coupon_id > 0) {
- //优惠券字段
- $coupon_field = 'coupon_type_id,coupon_name,money,count,lead_count,max_fetch,at_least,end_time,image,validity_type,fixed_term,type';
-
- $model = new CouponType();
- $coupon = $model->getCouponTypeList([ [ 'coupon_type_id', 'in', $order[ 'coupon_id' ] ] ], $coupon_field);
- $order[ 'coupon_list' ] = $coupon;
- }
-
- }
-
- return $this->success($order);
- }
-
- /**
- * 订单列表
- * @param array $condition
- * @param int $page
- * @param int $page_size
- * @param string $order
- * @param string $field
- * @param string $alias
- * @param array $join
- * @return array
- */
- public function getMemberRechargeOrderPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*', $alias = 'a', $join = [])
- {
- $list = model('member_recharge_order')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
- if (!empty($list[ 'list' ])) {
- $coupon_ids = '';
- foreach ($list[ 'list' ] as $k => $v) {
- if (!empty($v[ 'coupon_id' ])) {
- $coupon_ids = empty($coupon_ids) ? $v[ 'coupon_id' ] : $coupon_ids . ',' . $v[ 'coupon_id' ];
- }
- }
- $coupon_list = [];
- if (!empty($coupon_ids)) {
- $coupon_list = model('promotion_coupon_type')->getList([ [ 'coupon_type_id', 'in', $coupon_ids ] ], 'coupon_type_id,coupon_name');
-
- }
- if (!empty($coupon_list)) {
- $key = array_column($coupon_list, 'coupon_type_id');
- $coupon_list = array_combine($key, $coupon_list);
- }
-
- foreach ($list[ 'list' ] as $k => $v) {
- $list[ 'list' ][ $k ][ 'coupon_name' ] = '';
- $coupon_name = '';
- if (!empty($v[ 'coupon_id' ])) {
- $coupon_array = explode(',', $v[ 'coupon_id' ]);
- foreach ($coupon_array as $value) {
- $coupon_name_value = $coupon_list[ $value ][ 'name' ] ?? '';
- $coupon_name .= ',' . $coupon_name_value;
- }
- $coupon_name = ltrim($coupon_name, ',');
- }
- $list[ 'list' ][ $k ][ 'coupon_name' ] = $coupon_name;
- }
- }
- return $this->success($list);
- }
-
- /**
- * 支付回调
- * @param $data
- * @return array|\multitype
- */
- public function orderPay($data)
- {
- $order_field = 'order_id,recharge_id,recharge_name,order_no,cover_img,face_value,buy_price,point,growth,coupon_id,price,pay_type,status,create_time,pay_time,member_id,member_img,nickname,site_id,out_trade_no,order_from';
- $order_info = $this->getMemberRechargeOrderInfo([ [ 'out_trade_no', '=', $data[ 'out_trade_no' ] ] ], $order_field)[ 'data' ];
- if ($order_info[ 'status' ] == 1) {
- model('member_recharge_order')->startTrans();
- try {
-
- $pay_list = $this->getPayType();
- $pay_type_name = '';
- if (!empty($data[ 'pay_type' ])) {
- $pay_type_name = $pay_list[ $data[ 'pay_type' ] ];
- }
-
- //修改订单状态
- $order_data = [
- 'pay_type' => $data[ 'pay_type' ],
- 'pay_type_name' => $pay_type_name,
- 'pay_time' => time(),
- 'price' => $order_info[ 'buy_price' ],
- 'status' => 2
- ];
- $res = model('member_recharge_order')->update($order_data, [ [ 'out_trade_no', '=', $data[ 'out_trade_no' ] ] ]);
-
- //添加开卡记录
- $card_model = new MemberRechargeCard();
- $order_info[ 'use_status' ] = 2;
- $order_info[ 'use_time' ] = time();
- $card_model->addMemberRechargeCard($order_info);
-
- //发放礼包
- $card_model->addMemberAccount($order_info);
-
- //获取套餐信息
- $recharge_model = new Memberrecharge();
- $recharge_info = $recharge_model->getMemberRechargeInfo([ [ 'recharge_id', '=', $order_info[ 'recharge_id' ] ] ], 'sale_num,coupon_id');
- //增加发放数
- if (!empty($recharge_info[ 'data' ])) {
- $sale_num = $recharge_info[ 'data' ][ 'sale_num' ] + 1;
- $recharge_model->editMemberRecharge([ [ 'recharge_id', '=', $order_info[ 'recharge_id' ] ] ], [ 'sale_num' => $sale_num ]);
- }
- $is_stat = $data[ 'is_stat' ] ?? true;
- if ($is_stat) {
- event('MemberRechargeOrderPay', [ 'order_id' => $order_info[ 'order_id' ], 'order_from' => $order_info[ 'order_from' ] ]);
- $stat_model = new Stat();
- $stat_res = $stat_model->switchStat([
- 'type' => 'recharge',
- 'data' => [
- 'order_id' => $order_info[ 'order_id' ],
- 'site_id' => $order_info[ 'site_id' ]
- ]
- ]);
- }
-
- // 小程序录入发货信息
- $member_service = new Member();
- $order_info[ 'member_info' ] = $member_service->getMemberInfo([
- [ 'site_id', '=', $order_info[ 'site_id' ] ],
- [ 'member_id', '=', $order_info[ 'member_id' ] ]
- ], 'weapp_openid')[ 'data' ];
-
- $this->uploadShippingInfo($order_info);
-
- model('member_recharge_order')->commit();
- return $this->success($res);
- } catch (\Exception $e) {
- model('member_recharge_order')->rollback();
- Log::write('memberrechargeerr' . json_encode($e->getMessage() . $e->getFile() . $e->getLine()));
- return $this->error('', $e->getMessage());
- }
- } else {
- return $this->success(true);
- }
-
- }
-
- /**
- * 定时关闭订单
- * @param $order_id
- * @return array
- */
- public function cronMemberRechargeOrderClose($order_id)
- {
- //获取订单信息
- $order_info = $this->getMemberRechargeOrderInfo([ [ 'order_id', '=', $order_id ] ], 'status')[ 'data' ];
- if (empty($order_info)) {
- $res = true;
- } else {
- if ($order_info[ 'status' ] == 1) {
- //删除订单
- $res = model('member_recharge_order')->delete([ [ 'order_id', '=', $order_id ] ]);
- Cache::tag("member_recharge_order")->clear();
- } else {
- $res = true;
- }
- }
- return $this->success($res);
- }
-
- /**
- * 获取总数
- * @param array $where
- * @param string $field
- * @param string $alias
- * @param null $join
- * @param null $group
- * @return array
- */
- public function getOrderCount($where = [], $field = '*', $alias = 'a', $join = null, $group = null)
- {
- $res = model('member_recharge_order')->getCount($where, $field, $alias, $join, $group);
- return $this->success($res);
- }
-
- /**
- * 获取总和
- * @param array $where
- * @param string $field
- * @param string $alias
- * @param null $join
- * @return array
- */
- public function getOrderSum($where = [], $field = '*', $alias = 'a', $join = null)
- {
- $res = model('member_recharge_order')->getSum($where, $field, $alias, $join);
- return $this->success($res);
- }
-
- /**
- * 小程序录入发货信息
- * @param $order_info
- * @return array
- * @throws \GuzzleHttp\Exception\GuzzleException
- */
- public function uploadShippingInfo($order_info)
- {
- $shipping_list = [
- [
- 'tracking_no' => '', // 物流单号,物流快递发货时必填,示例值: 323244567777 字符字节限制: [1, 128]
- 'express_company' => '', // 物流公司编码,快递公司ID,参见「查询物流公司编码列表」,物流快递发货时必填, 示例值: DHL 字符字节限制: [1, 128]
- 'item_desc' => str_sub($order_info[ 'recharge_name' ], 100), // 商品信息,例如:微信红包抱枕*1个,限120个字以内
- 'contact' => [
- 'consignor_contact' => '',
- 'receiver_contact' => ''
- ]
- ]
- ];
-
- $data = [
- 'site_id' => $order_info[ 'site_id' ],
- 'out_trade_no' => $order_info[ 'out_trade_no' ],
- 'logistics_type' => 3, // 3、虚拟商品,虚拟商品,例如话费充值,点卡等,无实体配送形式
- 'delivery_mode' => 1, // 发货模式,发货模式枚举值:1、UNIFIED_DELIVERY(统一发货)
- 'shipping_list' => $shipping_list,
- 'weapp_openid' => $order_info[ 'member_info' ][ 'weapp_openid' ], // 用户标识,用户在小程序appid下的唯一标识。 下单前需获取到用户的Openid 示例值: oUpF8uMuAJO_M2pxb1Q9zNjWeS6o 字符字节限制: [1, 128]
- 'is_all_delivered' => false
- ];
-
- $weapp_model = new Weapp($order_info[ 'site_id' ]);
- $res = $weapp_model->orderShippingUploadShippingInfoByData($data);
- return $res;
-
- }
-
+pay_type;
+ //获取当前所有在线支付方式
+ $onlinepay = event('PayType');
+ if (!empty($onlinepay)) {
+ foreach ($onlinepay as $k => $v) {
+ $pay_type[ $v[ 'pay_type' ] ] = $v[ 'pay_type_name' ];
+ }
+ }
+ $trade_pay_type_list = event('TradePayType', []);
+ if (!empty($trade_pay_type_list)) {
+ foreach ($trade_pay_type_list as $k => $v) {
+ if (!empty($v)) {
+ $pay_type = array_merge($pay_type, $v);
+ }
+ }
+ }
+ return $pay_type;
+ }
+
+ /**
+ * 订单详情
+ * @param array $condition
+ * @param string $field
+ * @param string $alias
+ * @param array $join
+ * @return array
+ */
+ public function getMemberRechargeOrderInfo($condition = [], $field = '*', $alias = 'a', $join = [])
+ {
+ $order = model('member_recharge_order')->getInfo($condition, $field, $alias, $join);
+ if ($order) {
+ //获取优惠券信息
+ $coupon_id = $order[ 'coupon_id' ] ?? 0;
+ if ($coupon_id > 0) {
+ //优惠券字段
+ $coupon_field = 'coupon_type_id,coupon_name,money,count,lead_count,max_fetch,at_least,end_time,image,validity_type,fixed_term,type';
+
+ $model = new CouponType();
+ $coupon = $model->getCouponTypeList([ [ 'coupon_type_id', 'in', $order[ 'coupon_id' ] ] ], $coupon_field);
+ $order[ 'coupon_list' ] = $coupon;
+ }
+
+ }
+
+ return $this->success($order);
+ }
+
+ /**
+ * 订单列表
+ * @param array $condition
+ * @param int $page
+ * @param int $page_size
+ * @param string $order
+ * @param string $field
+ * @param string $alias
+ * @param array $join
+ * @return array
+ */
+ public function getMemberRechargeOrderPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*', $alias = 'a', $join = [])
+ {
+ $list = model('member_recharge_order')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
+ if (!empty($list[ 'list' ])) {
+ $coupon_ids = '';
+ foreach ($list[ 'list' ] as $k => $v) {
+ if (!empty($v[ 'coupon_id' ])) {
+ $coupon_ids = empty($coupon_ids) ? $v[ 'coupon_id' ] : $coupon_ids . ',' . $v[ 'coupon_id' ];
+ }
+ }
+ $coupon_list = [];
+ if (!empty($coupon_ids)) {
+ $coupon_list = model('promotion_coupon_type')->getList([ [ 'coupon_type_id', 'in', $coupon_ids ] ], 'coupon_type_id,coupon_name');
+
+ }
+ if (!empty($coupon_list)) {
+ $key = array_column($coupon_list, 'coupon_type_id');
+ $coupon_list = array_combine($key, $coupon_list);
+ }
+
+ foreach ($list[ 'list' ] as $k => $v) {
+ $list[ 'list' ][ $k ][ 'coupon_name' ] = '';
+ $coupon_name = '';
+ if (!empty($v[ 'coupon_id' ])) {
+ $coupon_array = explode(',', $v[ 'coupon_id' ]);
+ foreach ($coupon_array as $value) {
+ $coupon_name_value = $coupon_list[ $value ][ 'name' ] ?? '';
+ $coupon_name .= ',' . $coupon_name_value;
+ }
+ $coupon_name = ltrim($coupon_name, ',');
+ }
+ $list[ 'list' ][ $k ][ 'coupon_name' ] = $coupon_name;
+ }
+ }
+ return $this->success($list);
+ }
+
+ /**
+ * 支付回调
+ * @param $data
+ * @return array|\multitype
+ */
+ public function orderPay($data)
+ {
+ $order_field = 'order_id,recharge_id,recharge_name,order_no,cover_img,face_value,buy_price,point,growth,coupon_id,price,pay_type,status,create_time,pay_time,member_id,member_img,nickname,site_id,out_trade_no,order_from';
+ $order_info = $this->getMemberRechargeOrderInfo([ [ 'out_trade_no', '=', $data[ 'out_trade_no' ] ] ], $order_field)[ 'data' ];
+ if ($order_info[ 'status' ] == 1) {
+ model('member_recharge_order')->startTrans();
+ try {
+
+ $pay_list = $this->getPayType();
+ $pay_type_name = '';
+ if (!empty($data[ 'pay_type' ])) {
+ $pay_type_name = $pay_list[ $data[ 'pay_type' ] ];
+ }
+
+ //修改订单状态
+ $order_data = [
+ 'pay_type' => $data[ 'pay_type' ],
+ 'pay_type_name' => $pay_type_name,
+ 'pay_time' => time(),
+ 'price' => $order_info[ 'buy_price' ],
+ 'status' => 2
+ ];
+ $res = model('member_recharge_order')->update($order_data, [ [ 'out_trade_no', '=', $data[ 'out_trade_no' ] ] ]);
+
+ //添加开卡记录
+ $card_model = new MemberRechargeCard();
+ $order_info[ 'use_status' ] = 2;
+ $order_info[ 'use_time' ] = time();
+ $card_model->addMemberRechargeCard($order_info);
+
+ //发放礼包
+ $card_model->addMemberAccount($order_info);
+
+ //获取套餐信息
+ $recharge_model = new Memberrecharge();
+ $recharge_info = $recharge_model->getMemberRechargeInfo([ [ 'recharge_id', '=', $order_info[ 'recharge_id' ] ] ], 'sale_num,coupon_id');
+ //增加发放数
+ if (!empty($recharge_info[ 'data' ])) {
+ $sale_num = $recharge_info[ 'data' ][ 'sale_num' ] + 1;
+ $recharge_model->editMemberRecharge([ [ 'recharge_id', '=', $order_info[ 'recharge_id' ] ] ], [ 'sale_num' => $sale_num ]);
+ }
+ $is_stat = $data[ 'is_stat' ] ?? true;
+ if ($is_stat) {
+ event('MemberRechargeOrderPay', [ 'order_id' => $order_info[ 'order_id' ], 'order_from' => $order_info[ 'order_from' ] ]);
+ $stat_model = new Stat();
+ $stat_res = $stat_model->switchStat([
+ 'type' => 'recharge',
+ 'data' => [
+ 'order_id' => $order_info[ 'order_id' ],
+ 'site_id' => $order_info[ 'site_id' ]
+ ]
+ ]);
+ }
+
+ // 小程序录入发货信息
+ $member_service = new Member();
+ $order_info[ 'member_info' ] = $member_service->getMemberInfo([
+ [ 'site_id', '=', $order_info[ 'site_id' ] ],
+ [ 'member_id', '=', $order_info[ 'member_id' ] ]
+ ], 'weapp_openid')[ 'data' ];
+
+ $this->uploadShippingInfo($order_info);
+
+ model('member_recharge_order')->commit();
+ return $this->success($res);
+ } catch (\Exception $e) {
+ model('member_recharge_order')->rollback();
+ Log::write('memberrechargeerr' . json_encode($e->getMessage() . $e->getFile() . $e->getLine()));
+ return $this->error('', $e->getMessage());
+ }
+ } else {
+ return $this->success(true);
+ }
+
+ }
+
+ /**
+ * 定时关闭订单
+ * @param $order_id
+ * @return array
+ */
+ public function cronMemberRechargeOrderClose($order_id)
+ {
+ //获取订单信息
+ $order_info = $this->getMemberRechargeOrderInfo([ [ 'order_id', '=', $order_id ] ], 'status')[ 'data' ];
+ if (empty($order_info)) {
+ $res = true;
+ } else {
+ if ($order_info[ 'status' ] == 1) {
+ //删除订单
+ $res = model('member_recharge_order')->delete([ [ 'order_id', '=', $order_id ] ]);
+ Cache::tag("member_recharge_order")->clear();
+ } else {
+ $res = true;
+ }
+ }
+ return $this->success($res);
+ }
+
+ /**
+ * 获取总数
+ * @param array $where
+ * @param string $field
+ * @param string $alias
+ * @param null $join
+ * @param null $group
+ * @return array
+ */
+ public function getOrderCount($where = [], $field = '*', $alias = 'a', $join = null, $group = null)
+ {
+ $res = model('member_recharge_order')->getCount($where, $field, $alias, $join, $group);
+ return $this->success($res);
+ }
+
+ /**
+ * 获取总和
+ * @param array $where
+ * @param string $field
+ * @param string $alias
+ * @param null $join
+ * @return array
+ */
+ public function getOrderSum($where = [], $field = '*', $alias = 'a', $join = null)
+ {
+ $res = model('member_recharge_order')->getSum($where, $field, $alias, $join);
+ return $this->success($res);
+ }
+
+ /**
+ * 小程序录入发货信息
+ * @param $order_info
+ * @return array
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function uploadShippingInfo($order_info)
+ {
+ $shipping_list = [
+ [
+ 'tracking_no' => '', // 物流单号,物流快递发货时必填,示例值: 323244567777 字符字节限制: [1, 128]
+ 'express_company' => '', // 物流公司编码,快递公司ID,参见「查询物流公司编码列表」,物流快递发货时必填, 示例值: DHL 字符字节限制: [1, 128]
+ 'item_desc' => str_sub($order_info[ 'recharge_name' ], 100), // 商品信息,例如:微信红包抱枕*1个,限120个字以内
+ 'contact' => [
+ 'consignor_contact' => '',
+ 'receiver_contact' => ''
+ ]
+ ]
+ ];
+
+ $data = [
+ 'site_id' => $order_info[ 'site_id' ],
+ 'out_trade_no' => $order_info[ 'out_trade_no' ],
+ 'logistics_type' => 3, // 3、虚拟商品,虚拟商品,例如话费充值,点卡等,无实体配送形式
+ 'delivery_mode' => 1, // 发货模式,发货模式枚举值:1、UNIFIED_DELIVERY(统一发货)
+ 'shipping_list' => $shipping_list,
+ 'weapp_openid' => $order_info[ 'member_info' ][ 'weapp_openid' ], // 用户标识,用户在小程序appid下的唯一标识。 下单前需获取到用户的Openid 示例值: oUpF8uMuAJO_M2pxb1Q9zNjWeS6o 字符字节限制: [1, 128]
+ 'is_all_delivered' => false
+ ];
+
+ $weapp_model = new Weapp($order_info[ 'site_id' ]);
+ $res = $weapp_model->orderShippingUploadShippingInfoByData($data);
+ return $res;
+
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/memberrecharge/model/MemberrechargeOrderCreate.php b/src/addon/memberrecharge/model/MemberrechargeOrderCreate.php
index ac36e2150..76d5cfcf6 100644
--- a/src/addon/memberrecharge/model/MemberrechargeOrderCreate.php
+++ b/src/addon/memberrecharge/model/MemberrechargeOrderCreate.php
@@ -1,125 +1,117 @@
-getMemberInfo([ [ 'member_id', '=', $data[ 'member_id' ] ] ], 'headimg,nickname');
- $member_info = $member[ 'data' ];
- //获取套餐信息
- $recharge_model = new Memberrecharge();
-
- if ($data[ 'recharge_id' ] > 0) {
- //套餐字段
- $field = 'recharge_id,recharge_name,cover_img,face_value,buy_price,point,growth,coupon_id';
- $recharge_info = $recharge_model->getMemberRechargeInfo([ [ 'recharge_id', '=', $data[ 'recharge_id' ] ] ], $field)['data'];
- if (empty($recharge_info)) {
- return $this->error('', '无效的充值套餐');
- }
- } else {
- $recharge_info = array (
- "recharge_id" => 0,
- "recharge_name" => '自定义面额充值',
- "cover_img" => '',
- "face_value" => $data[ 'face_value' ],
- "buy_price" => $data[ 'face_value' ],
- "point" => 0,
- "growth" => 0,
- "coupon_id" => 0,
- );
- }
-
- //创建或加入
- $pay = new Pay();
- $out_trade_no = $pay->createOutTradeNo($data[ 'member_id' ]);
- $order_no = (new OrderCreate())->createOrderNo();
-
- $order_data = [
- 'recharge_id' => $data[ 'recharge_id' ],
- 'order_no' => $order_no,
- 'out_trade_no' => $out_trade_no,
- 'recharge_name' => $recharge_info[ 'recharge_name' ],
- 'cover_img' => $recharge_info[ 'cover_img' ],
- 'face_value' => $recharge_info[ 'face_value' ],
- 'buy_price' => $recharge_info[ 'buy_price' ],
- 'pay_money' => $recharge_info[ 'buy_price' ],
- 'point' => $recharge_info[ 'point' ],
- 'growth' => $recharge_info[ 'growth' ],
- 'coupon_id' => $recharge_info[ 'coupon_id' ],
- 'status' => 1,
- 'create_time' => time(),
- 'member_id' => $data[ 'member_id' ],
- 'member_img' => $member_info[ 'headimg' ],
- 'nickname' => $member_info[ 'nickname' ],
- 'order_from' => $data[ 'order_from' ],
- 'order_from_name' => $data[ 'order_from_name' ],
- 'site_id' => $data[ 'site_id' ],
- 'store_id' => $data[ 'store_id' ] ?? 0,
- 'remark' => $data[ 'remark' ] ?? '',
- 'relate_id' => $data[ 'relate_id' ] ?? 0,
- 'relate_type' => $data[ 'relate_type' ] ?? '',
- ];
-
- model("member_recharge_order")->startTrans();
- //循环生成多个订单
- try {
-
- $order_id = model("member_recharge_order")->add($order_data);
- //生成整体支付单据
- $pay->addPay($data[ 'site_id' ], $out_trade_no, "", "会员充值套餐,面额:" . $recharge_info[ 'face_value' ], "会员充值套餐,面额:" . $recharge_info[ 'face_value' ], $recharge_info[ 'buy_price' ], '', 'MemberrechargeOrderPayNotify', '');
-
- //计算订单自动关闭时间
- $config_model = new Config();
- $order_config = $config_model->getOrderEventTimeConfig($data[ 'site_id' ])[ "data" ];
- $now_time = time();
- if (!empty($order_config)) {
- $execute_time = $now_time + $order_config[ "value" ][ "auto_close" ] * 60;//自动关闭时间
- } else {
- $execute_time = $now_time + 3600;//尚未配置 默认一天
- }
- $cron_model = new Cron();
- $cron_model->addCron(1, 0, "订单自动关闭", "MemberrechargeOrderClose", $execute_time, $order_id);
-
- event("MemberRechargeOrderCreate", [ 'order_id' => $order_id ]);
- model("member_recharge_order")->commit();
- return $this->success($out_trade_no);
-
- } catch (\Exception $e) {
- model("member_recharge_order")->rollback();
- return $this->error('', $e->getMessage());
- }
-
- }
-
+getMemberInfo([ [ 'member_id', '=', $data[ 'member_id' ] ] ], 'headimg,nickname');
+ $member_info = $member[ 'data' ];
+ //获取套餐信息
+ $recharge_model = new Memberrecharge();
+
+ if ($data[ 'recharge_id' ] > 0) {
+ //套餐字段
+ $field = 'recharge_id,recharge_name,cover_img,face_value,buy_price,point,growth,coupon_id';
+ $recharge_info = $recharge_model->getMemberRechargeInfo([ [ 'recharge_id', '=', $data[ 'recharge_id' ] ] ], $field)['data'];
+ if (empty($recharge_info)) {
+ return $this->error('', '无效的充值套餐');
+ }
+ } else {
+ $recharge_info = array (
+ "recharge_id" => 0,
+ "recharge_name" => '自定义面额充值',
+ "cover_img" => '',
+ "face_value" => $data[ 'face_value' ],
+ "buy_price" => $data[ 'face_value' ],
+ "point" => 0,
+ "growth" => 0,
+ "coupon_id" => 0,
+ );
+ }
+
+ //创建或加入
+ $pay = new Pay();
+ $out_trade_no = $pay->createOutTradeNo($data[ 'member_id' ]);
+ $order_no = (new OrderCreate())->createOrderNo();
+
+ $order_data = [
+ 'recharge_id' => $data[ 'recharge_id' ],
+ 'order_no' => $order_no,
+ 'out_trade_no' => $out_trade_no,
+ 'recharge_name' => $recharge_info[ 'recharge_name' ],
+ 'cover_img' => $recharge_info[ 'cover_img' ],
+ 'face_value' => $recharge_info[ 'face_value' ],
+ 'buy_price' => $recharge_info[ 'buy_price' ],
+ 'pay_money' => $recharge_info[ 'buy_price' ],
+ 'point' => $recharge_info[ 'point' ],
+ 'growth' => $recharge_info[ 'growth' ],
+ 'coupon_id' => $recharge_info[ 'coupon_id' ],
+ 'status' => 1,
+ 'create_time' => time(),
+ 'member_id' => $data[ 'member_id' ],
+ 'member_img' => $member_info[ 'headimg' ],
+ 'nickname' => $member_info[ 'nickname' ],
+ 'order_from' => $data[ 'order_from' ],
+ 'order_from_name' => $data[ 'order_from_name' ],
+ 'site_id' => $data[ 'site_id' ],
+ 'store_id' => $data[ 'store_id' ] ?? 0,
+ 'remark' => $data[ 'remark' ] ?? '',
+ 'relate_id' => $data[ 'relate_id' ] ?? 0,
+ 'relate_type' => $data[ 'relate_type' ] ?? '',
+ ];
+
+ model("member_recharge_order")->startTrans();
+ //循环生成多个订单
+ try {
+
+ $order_id = model("member_recharge_order")->add($order_data);
+ //生成整体支付单据
+ $pay->addPay($data[ 'site_id' ], $out_trade_no, "", "会员充值套餐,面额:" . $recharge_info[ 'face_value' ], "会员充值套餐,面额:" . $recharge_info[ 'face_value' ], $recharge_info[ 'buy_price' ], '', 'MemberrechargeOrderPayNotify', '');
+
+ //计算订单自动关闭时间
+ $config_model = new Config();
+ $order_config = $config_model->getOrderEventTimeConfig($data[ 'site_id' ])[ "data" ];
+ $now_time = time();
+ if (!empty($order_config)) {
+ $execute_time = $now_time + $order_config[ "value" ][ "auto_close" ] * 60;//自动关闭时间
+ } else {
+ $execute_time = $now_time + 3600;//尚未配置 默认一天
+ }
+ $cron_model = new Cron();
+ $cron_model->addCron(1, 0, "订单自动关闭", "MemberrechargeOrderClose", $execute_time, $order_id);
+
+ event("MemberRechargeOrderCreate", [ 'order_id' => $order_id ]);
+ model("member_recharge_order")->commit();
+ return $this->success($out_trade_no);
+
+ } catch (\Exception $e) {
+ model("member_recharge_order")->rollback();
+ return $this->error('', $e->getMessage());
+ }
+
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/memberrecharge/shop/controller/Memberrecharge.php b/src/addon/memberrecharge/shop/controller/Memberrecharge.php
index 82ffd31a1..23397271a 100644
--- a/src/addon/memberrecharge/shop/controller/Memberrecharge.php
+++ b/src/addon/memberrecharge/shop/controller/Memberrecharge.php
@@ -1,497 +1,489 @@
-replace = [
- 'MEMBERRECHARGE_CSS' => __ROOT__ . '/addon/memberrecharge/shop/view/public/css',
- 'MEMBERRECHARGE_JS' => __ROOT__ . '/addon/memberrecharge/shop/view/public/js',
- 'MEMBERRECHARGE_IMG' => __ROOT__ . '/addon/memberrecharge/shop/view/public/img',
- ];
- parent::__construct($app);
- }
-
- //套餐字段
- protected $field = 'recharge_id,recharge_name,cover_img,face_value,buy_price,point,growth,coupon_id,sale_num,create_time,status';
-
- //开卡字段
- protected $card_field = 'card_id,recharge_id,card_account,cover_img,face_value,point,growth,coupon_id,buy_price,member_img,nickname,order_id,order_no,from_type,use_status,create_time,use_time';
-
- //订单字段
- protected $order_field = 'a.order_id,a.recharge_name,a.recharge_id,a.order_no,a.out_trade_no,a.member_id,a.cover_img,a.face_value,a.buy_price,a.point,a.growth,a.coupon_id,a.price,a.pay_type,a.pay_type_name,a.status,a.create_time,a.pay_time,a.member_img,a.nickname,a.order_from_name,a.order_from,IFNULL(s.store_name,"") as store_name';
-
- //优惠券字段
- protected $coupon_field = 'coupon_type_id,coupon_name,money,count,lead_count,max_fetch,at_least,end_time,image,validity_type,fixed_term';
-
- /**
- * 充值会员套餐列表
- * @return array|mixed
- */
- public function lists()
- {
- $model = new MemberRechargeModel();
- //获取续签信息
- if (request()->isJson()) {
- $status = input('status', '');//套餐状态
- $condition = [];
- if ($status) {
- $condition[] = [ 'status', '=', $status ];
- }
- $condition[] = [ 'site_id', '=', $this->site_id ];
- $page = input('page', 1);
- $page_size = input('page_size', PAGE_LIST_ROWS);
- $list = $model->getMemberRechargePageList($condition, $page, $page_size, 'recharge_id desc', $this->field);
- return $list;
- } else {
- $config = $model->getConfig($this->site_id);
- $config = $config[ 'data' ];
- $this->assign("config", $config);
- return $this->fetch('memberrecharge/lists');
- }
-
- }
-
- /**
- * 添加充值套餐
- * @return array|mixed
- */
- public function add()
- {
- if (request()->isJson()) {
-
- $data = [
- 'site_id' => $this->site_id,
- 'recharge_name' => input('recharge_name', ''),//套餐名称
- 'cover_img' => input('cover_img', ''),//封面
- 'face_value' => input('face_value', ''),//面值
- 'buy_price' => input('buy_price', ''),//价格
- 'point' => input('point', ''),//赠送积分
- 'growth' => input('growth', ''),//赠送成长值
- 'coupon_id' => input('coupon_id', '')//优惠券id
- ];
-
- $model = new MemberRechargeModel();
- return $model->addMemberRecharge($data);
-
- } else {
- return $this->fetch('memberrecharge/add');
- }
- }
-
- /**
- * 编辑充值套餐
- * @return array|mixed
- */
- public function edit()
- {
- $rechargeModel = new MemberRechargeModel();
-
- $recharge_id = input('recharge_id', '');
- if (request()->isJson()) {
-
- $data = [
- 'recharge_name' => input('recharge_name', ''),//套餐名称
- 'cover_img' => input('cover_img', ''),//封面
- 'face_value' => input('face_value', ''),//面值
- 'buy_price' => input('buy_price', ''),//价格
- 'point' => input('point', ''),//赠送积分
- 'growth' => input('growth', ''),//赠送成长值
- 'coupon_id' => input('coupon_id', '')//优惠券id
- ];
-
- return $rechargeModel->editMemberRecharge(
- [
- [ 'recharge_id', '=', $recharge_id ],
- [ 'site_id', '=', $this->site_id ]
- ], $data);
-
- } else {
- //获取套餐详情
- $recharge = $rechargeModel->getMemberRechargeInfo(
- [
- [ 'recharge_id', '=', $recharge_id ],
- [ 'site_id', '=', $this->site_id ]
- ],
- $this->field
- );
- if (empty($recharge[ 'data' ])) $this->error('未获取到套餐数据', href_url('memberrecharge://shop/memberrecharge/lists'));
- $this->assign('recharge', $recharge);
- return $this->fetch('memberrecharge/edit');
- }
-
- }
-
- /**
- * 充值套餐详情
- * @return mixed
- */
- public function detail()
- {
- $recharge_model = new MemberRechargeModel();
-
- $recharge_id = input('recharge_id', '');
-
- //获取套餐详情
- $info = $recharge_model->getMemberRechargeInfo(
- [
- [ 'recharge_id', '=', $recharge_id ],
- [ 'site_id', '=', $this->site_id ]
- ],
- $this->field
- )[ 'data' ] ?? [];
- if (empty($info)) $this->error('未获取到套餐数据', href_url('memberrecharge://shop/memberrecharge/lists'));
- $this->assign('info', $info);
-
- return $this->fetch('memberrecharge/detail');
- }
-
- /**
- * 停用充值套餐
- * @return array
- */
- public function invalid()
- {
- $model = new MemberRechargeModel();
-
- $recharge_id = input('recharge_id', '');
-
- $data = [ 'status' => 2 ];
- $condition = [ [ 'recharge_id', '=', $recharge_id ] ];
-
- $res = $model->editMemberRecharge($condition, $data);
- return $res;
- }
-
- /**
- * 开启充值套餐
- * @return array
- */
- public function open()
- {
- $model = new MemberRechargeModel();
-
- $recharge_id = input('recharge_id', '');
-
- $data = [ 'status' => 1 ];
- $condition = [ [ 'recharge_id', '=', $recharge_id ] ];
-
- $res = $model->editMemberRecharge($condition, $data);
- return $res;
- }
-
- /**
- * 删除充值套餐
- * @return mixed
- */
- public function delete()
- {
- $model = new MemberRechargeModel();
-
- $recharge_id = input('recharge_id', '');
-
- return $model->deleteMemberRecharge([ [ 'recharge_id', '=', $recharge_id ] ]);
- }
-
- /**
- * 开卡列表
- * @return array|mixed
- */
- public function cardLists()
- {
- $recharge_id = input('recharge_id', '');
- $page_size = input('page_size', PAGE_LIST_ROWS);
-
- $model = new MemberRechargeCardModel();
- $condition[] = [ 'site_id', '=', $this->site_id ];
- $condition[] = [ 'recharge_id', '=', $recharge_id ];
- //获取续签信息
- if (request()->isJson()) {
- $status = input('use_status', '');//使用状态
- if ($status) {
- $condition[] = [ 'use_status', '=', $status ];
- }
-
- $page = input('page', 1);
- $list = $model->getMemberRechargeCardPageList($condition, $page, $page_size, 'card_id desc', $this->card_field);
- return $list;
- } else {
-
- $page_size = input('page_size', PAGE_LIST_ROWS);
-
- $list = $model->getMemberRechargeCardPageList($condition, 1, $page_size, 'card_id desc', $this->card_field);
- $this->assign('list', $list);
-
- $this->assign('recharge_id', $recharge_id);
- return $this->fetch('memberrecharge/card_lists');
- }
-
- }
-
- /**
- * 开卡详情
- * @return mixed
- */
- public function cardDetail()
- {
- $model = new MemberRechargeCardModel();
-
- $card_id = input('card_id', '');
-
- //获取详情
- $info = $model->getMemberRechargeCardInfo(
- [ [ 'card_id', '=', $card_id ] ],
- $this->card_field
- )[ 'data' ] ?? [];
- $this->assign('info', $info);
-
- return $this->fetch('memberrecharge/card_detail');
- }
-
- /**
- * 订单列表
- * @return array|mixed
- */
- public function orderLists()
- {
- $recharge_id = input('recharge_id', 0);
- $model = new MemberRechargeOrderModel();
- //获取续签信息
- if (request()->isJson()) {
- $page = input('page', 1);
- $page_size = input('page_size', PAGE_LIST_ROWS);
- $nickname = input('nickname', '');
- $start_time = input('start_time', '');
- $end_time = input('end_time', '');
- $order_no = input('order_no', '');
- $store_id = input('store_id', '');
-
- $condition = [
- // [ 'a.status', '=', 2 ],
- [ 'a.site_id', '=', $this->site_id ]
- ];
-
- if ($recharge_id > 0) {
- $condition[] = [ 'recharge_id', '=', $recharge_id ];
- }
-
- if ($nickname) {
- $condition[] = [ 'a.nickname', 'like', '%' . $nickname . '%' ];
- }
- if ($order_no) {
- $condition[] = [ 'a.order_no', '=', $order_no ];
- }
- if ($store_id != '') {
- $condition[] = [ 'a.store_id', '=', $store_id ];
- }
- //支付时间
- if (!empty($start_time) && empty($end_time)) {
- $condition[] = [ "a.pay_time", ">=", date_to_time($start_time) ];
- } elseif (empty($start_time) && !empty($end_time)) {
- $condition[] = [ "a.pay_time", "<=", date_to_time($end_time) ];
- } elseif (!empty($start_time) && !empty($end_time)) {
- $condition[] = [ 'a.pay_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
- }
- $alias = 'a';
- $join[] = [
- 'store s',
- 's.store_id = a.store_id',
- 'left'
- ];
- $order = 'a.create_time desc';
- $list = $model->getMemberRechargeOrderPageList($condition, $page, $page_size, $order, $this->order_field, $alias, $join);
- return $list;
- } else {
- $this->assign('recharge_id', $recharge_id);
-
- $order_num = $model->getOrderCount([ [ 'site_id', '=', $this->site_id ], [ 'status', '=', 2 ] ], 'order_id')[ 'data' ];
- $this->assign('order_num', $order_num);
-
- $order_money = $model->getOrderSum([ [ 'site_id', '=', $this->site_id ], [ 'status', '=', 2 ] ], 'price')[ 'data' ];
- $this->assign('order_money', $order_money);
-
- if (addon_is_exit('store') == 1) {
- $store_model = new StoreModel();
- $store_list = $store_model->getStoreList([
- [ 'site_id', '=', $this->site_id ]
- ], 'store_id,store_name')[ 'data' ];
- $this->assign('store_list', $store_list);
- }
-
- $this->assign('printer_addon_is_exit',addon_is_exit('printer'));
-
- return $this->fetch('memberrecharge/order_lists');
- }
- }
-
- /**
- * 订单详情
- * @return mixed
- */
- public function orderDetail()
- {
- $order_id = input('order_id', '');
-
- $condition = [
- [ 'a.order_id', '=', $order_id ],
- [ 'a.site_id', '=', $this->site_id ]
- ];
-
- $alias = 'a';
- $join[] = [
- 'store s',
- 's.store_id = a.store_id',
- 'left'
- ];
-
- $model = new MemberRechargeOrderModel();
- $info = $model->getMemberRechargeOrderInfo($condition, $this->order_field, $alias, $join)[ 'data' ] ?? [];
- if (empty($info)) $this->error('未获取到订单数据', href_url('memberrecharge://shop/memberrecharge/order_lists'));
- $this->assign('info', $info);
-
- return $this->fetch('memberrecharge/order_detail');
- }
-
- /**
- * 是否开启充值
- * @return mixed
- */
- public function setConfig()
- {
- $model = new MemberRechargeModel();
- $is_use = input('is_use', 0);
- $data = [];
- return $model->setConfig($data, $is_use, $this->site_id);
- }
-
- public function exportRecharge()
- {
- $recharge_id = input("recharge_id", "");//订单状态
-
- $condition[] = [ "recharge_id", "=", $recharge_id ];
- $model = new MemberRechargeCardModel();
-
- $list = $model->getMemberRechargeCardPageList($condition, 1, 0, 'card_id desc', "*");
- if (empty($list[ 'data' ][ 'list' ])) {
- return $this->error("未查询到数据");
- }
-
- // 实例化excel
- $phpExcel = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
-
- $phpExcel->getProperties()->setTitle("充值记录");
- $phpExcel->getProperties()->setSubject("充值记录");
- // 对单元格设置居中效果
- $phpExcel->getActiveSheet()->getStyle('A')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $phpExcel->getActiveSheet()->getStyle('B')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $phpExcel->getActiveSheet()->getStyle('C')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $phpExcel->getActiveSheet()->getStyle('D')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $phpExcel->getActiveSheet()->getStyle('E')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $phpExcel->getActiveSheet()->getStyle('F')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $phpExcel->getActiveSheet()->getStyle('G')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $phpExcel->getActiveSheet()->getStyle('H')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $phpExcel->getActiveSheet()->getStyle('I')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $phpExcel->getActiveSheet()->getStyle('J')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $phpExcel->getActiveSheet()->getStyle('K')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $phpExcel->getActiveSheet()->getStyle('L')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- //单独添加列名称
- $phpExcel->setActiveSheetIndex(0);
- $phpExcel->getActiveSheet()->setCellValue('A1', '店铺名称');//可以指定位置
- $phpExcel->getActiveSheet()->setCellValue('B1', '充值卡号');
- $phpExcel->getActiveSheet()->setCellValue('C1', '套餐名称');
- $phpExcel->getActiveSheet()->setCellValue('D1', '面值');
- $phpExcel->getActiveSheet()->setCellValue('E1', '积分');
- $phpExcel->getActiveSheet()->setCellValue('F1', '成长值');
- $phpExcel->getActiveSheet()->setCellValue('G1', '购买金额');
- $phpExcel->getActiveSheet()->setCellValue('H1', '会员昵称');
- $phpExcel->getActiveSheet()->setCellValue('I1', '订单编号');
- $phpExcel->getActiveSheet()->setCellValue('J1', '使用状态');
- $phpExcel->getActiveSheet()->setCellValue('K1', '创建时间');
- $phpExcel->getActiveSheet()->setCellValue('L1', '使用时间');
- //循环添加数据(根据自己的逻辑)
- foreach ($list[ 'data' ][ 'list' ] as $k => $v) {
- $i = $k + 2;
- if ($v[ 'use_status' ] == 1) {
- $status_name = "未使用";
- } else {
- $status_name = "已使用";
- }
-
- $phpExcel->getActiveSheet()->setCellValue('A' . $i, $v[ 'site_name' ]);
- $phpExcel->getActiveSheet()->setCellValue('B' . $i, $v[ 'card_account' ]);
- $phpExcel->getActiveSheet()->setCellValue('C' . $i, $v[ 'recharge_name' ]);
- $phpExcel->getActiveSheet()->setCellValue('D' . $i, $v[ 'face_value' ]);
- $phpExcel->getActiveSheet()->setCellValue('E' . $i, $v[ 'point' ]);
- $phpExcel->getActiveSheet()->setCellValue('F' . $i, $v[ 'growth' ]);
- $phpExcel->getActiveSheet()->setCellValue('G' . $i, $v[ 'buy_price' ]);
- $phpExcel->getActiveSheet()->setCellValue('H' . $i, $v[ 'nickname' ]);
- $phpExcel->getActiveSheet()->setCellValue('I' . $i, ' ' . (string) $v[ 'order_no' ]);
- $phpExcel->getActiveSheet()->setCellValue('J' . $i, $status_name);
- $phpExcel->getActiveSheet()->setCellValue('K' . $i, date('Y-m-d', $v[ 'create_time' ]));
- $phpExcel->getActiveSheet()->setCellValue('L' . $i, date('Y-m-d', $v[ 'use_time' ]));
- }
-
- // 重命名工作sheet
- $phpExcel->getActiveSheet()->setTitle('充值记录');
- // 设置第一个sheet为工作的sheet
- $phpExcel->setActiveSheetIndex(0);
- // 保存Excel 2007格式文件,保存路径为当前路径,名字为export.xlsx
- $objWriter = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($phpExcel, 'Xlsx');
- $file = date('Y年m月d日-充值记录表', time()) . '.xlsx';
- $objWriter->save($file);
-
- header("Content-type:application/octet-stream");
-
- $filename = basename($file);
- header("Content-Disposition:attachment;filename = " . $filename);
- header("Accept-ranges:bytes");
- header("Accept-length:" . filesize($file));
- readfile($file);
- unlink($file);
- exit;
- }
-
- /**
- * 打印订单小票
- * @return array|mixed|void
- */
- public function printTicket()
- {
- if (addon_is_exit('printer') == 0) return error('', '未安装打印小票插件');
-
- if (request()->isJson()) {
- $order_id = input('order_id', 0);
- $printer_order_model = new PrinterOrder();
- $recharge_order = ( new MemberrechargeOrder() )->getMemberRechargeOrderInfo([ [ 'relate_type', '=', 'order' ], [ 'order_id', '=', $order_id ] ], 'order_id')[ 'data' ];
- if (empty($recharge_order)) return error('', '未获取到充值订单信息');
- $res = $printer_order_model->printer([
- 'order_id' => $recharge_order[ 'order_id' ],
- 'type' => 'recharge',
- ]);
- return $res;
- }
- }
-
+replace = [
+ 'MEMBERRECHARGE_CSS' => __ROOT__ . '/addon/memberrecharge/shop/view/public/css',
+ 'MEMBERRECHARGE_JS' => __ROOT__ . '/addon/memberrecharge/shop/view/public/js',
+ 'MEMBERRECHARGE_IMG' => __ROOT__ . '/addon/memberrecharge/shop/view/public/img',
+ ];
+ parent::__construct($app);
+ }
+
+ //套餐字段
+ protected $field = 'recharge_id,recharge_name,cover_img,face_value,buy_price,point,growth,coupon_id,sale_num,create_time,status';
+
+ //开卡字段
+ protected $card_field = 'card_id,recharge_id,card_account,cover_img,face_value,point,growth,coupon_id,buy_price,member_img,nickname,order_id,order_no,from_type,use_status,create_time,use_time';
+
+ //订单字段
+ protected $order_field = 'a.order_id,a.recharge_name,a.recharge_id,a.order_no,a.out_trade_no,a.member_id,a.cover_img,a.face_value,a.buy_price,a.point,a.growth,a.coupon_id,a.price,a.pay_type,a.pay_type_name,a.status,a.create_time,a.pay_time,a.member_img,a.nickname,a.order_from_name,a.order_from,IFNULL(s.store_name,"") as store_name';
+
+ //优惠券字段
+ protected $coupon_field = 'coupon_type_id,coupon_name,money,count,lead_count,max_fetch,at_least,end_time,image,validity_type,fixed_term';
+
+ /**
+ * 充值会员套餐列表
+ * @return array|mixed
+ */
+ public function lists()
+ {
+ $model = new MemberRechargeModel();
+ //获取续签信息
+ if (request()->isJson()) {
+ $status = input('status', '');//套餐状态
+ $condition = [];
+ if ($status) {
+ $condition[] = [ 'status', '=', $status ];
+ }
+ $condition[] = [ 'site_id', '=', $this->site_id ];
+ $page = input('page', 1);
+ $page_size = input('page_size', PAGE_LIST_ROWS);
+ $list = $model->getMemberRechargePageList($condition, $page, $page_size, 'recharge_id desc', $this->field);
+ return $list;
+ } else {
+ $config = $model->getConfig($this->site_id);
+ $config = $config[ 'data' ];
+ $this->assign("config", $config);
+ return $this->fetch('memberrecharge/lists');
+ }
+
+ }
+
+ /**
+ * 添加充值套餐
+ * @return array|mixed
+ */
+ public function add()
+ {
+ if (request()->isJson()) {
+
+ $data = [
+ 'site_id' => $this->site_id,
+ 'recharge_name' => input('recharge_name', ''),//套餐名称
+ 'cover_img' => input('cover_img', ''),//封面
+ 'face_value' => input('face_value', ''),//面值
+ 'buy_price' => input('buy_price', ''),//价格
+ 'point' => input('point', ''),//赠送积分
+ 'growth' => input('growth', ''),//赠送成长值
+ 'coupon_id' => input('coupon_id', '')//优惠券id
+ ];
+
+ $model = new MemberRechargeModel();
+ return $model->addMemberRecharge($data);
+
+ } else {
+ return $this->fetch('memberrecharge/add');
+ }
+ }
+
+ /**
+ * 编辑充值套餐
+ * @return array|mixed
+ */
+ public function edit()
+ {
+ $rechargeModel = new MemberRechargeModel();
+
+ $recharge_id = input('recharge_id', '');
+ if (request()->isJson()) {
+
+ $data = [
+ 'recharge_name' => input('recharge_name', ''),//套餐名称
+ 'cover_img' => input('cover_img', ''),//封面
+ 'face_value' => input('face_value', ''),//面值
+ 'buy_price' => input('buy_price', ''),//价格
+ 'point' => input('point', ''),//赠送积分
+ 'growth' => input('growth', ''),//赠送成长值
+ 'coupon_id' => input('coupon_id', '')//优惠券id
+ ];
+
+ return $rechargeModel->editMemberRecharge(
+ [
+ [ 'recharge_id', '=', $recharge_id ],
+ [ 'site_id', '=', $this->site_id ]
+ ], $data);
+
+ } else {
+ //获取套餐详情
+ $recharge = $rechargeModel->getMemberRechargeInfo(
+ [
+ [ 'recharge_id', '=', $recharge_id ],
+ [ 'site_id', '=', $this->site_id ]
+ ],
+ $this->field
+ );
+ if (empty($recharge[ 'data' ])) $this->error('未获取到套餐数据', href_url('memberrecharge://shop/memberrecharge/lists'));
+ $this->assign('recharge', $recharge);
+ return $this->fetch('memberrecharge/edit');
+ }
+
+ }
+
+ /**
+ * 充值套餐详情
+ * @return mixed
+ */
+ public function detail()
+ {
+ $recharge_model = new MemberRechargeModel();
+
+ $recharge_id = input('recharge_id', '');
+
+ //获取套餐详情
+ $info = $recharge_model->getMemberRechargeInfo(
+ [
+ [ 'recharge_id', '=', $recharge_id ],
+ [ 'site_id', '=', $this->site_id ]
+ ],
+ $this->field
+ )[ 'data' ] ?? [];
+ if (empty($info)) $this->error('未获取到套餐数据', href_url('memberrecharge://shop/memberrecharge/lists'));
+ $this->assign('info', $info);
+
+ return $this->fetch('memberrecharge/detail');
+ }
+
+ /**
+ * 停用充值套餐
+ * @return array
+ */
+ public function invalid()
+ {
+ $model = new MemberRechargeModel();
+
+ $recharge_id = input('recharge_id', '');
+
+ $data = [ 'status' => 2 ];
+ $condition = [ [ 'recharge_id', '=', $recharge_id ] ];
+
+ $res = $model->editMemberRecharge($condition, $data);
+ return $res;
+ }
+
+ /**
+ * 开启充值套餐
+ * @return array
+ */
+ public function open()
+ {
+ $model = new MemberRechargeModel();
+
+ $recharge_id = input('recharge_id', '');
+
+ $data = [ 'status' => 1 ];
+ $condition = [ [ 'recharge_id', '=', $recharge_id ] ];
+
+ $res = $model->editMemberRecharge($condition, $data);
+ return $res;
+ }
+
+ /**
+ * 删除充值套餐
+ * @return mixed
+ */
+ public function delete()
+ {
+ $model = new MemberRechargeModel();
+
+ $recharge_id = input('recharge_id', '');
+
+ return $model->deleteMemberRecharge([ [ 'recharge_id', '=', $recharge_id ] ]);
+ }
+
+ /**
+ * 开卡列表
+ * @return array|mixed
+ */
+ public function cardLists()
+ {
+ $recharge_id = input('recharge_id', '');
+ $page_size = input('page_size', PAGE_LIST_ROWS);
+
+ $model = new MemberRechargeCardModel();
+ $condition[] = [ 'site_id', '=', $this->site_id ];
+ $condition[] = [ 'recharge_id', '=', $recharge_id ];
+ //获取续签信息
+ if (request()->isJson()) {
+ $status = input('use_status', '');//使用状态
+ if ($status) {
+ $condition[] = [ 'use_status', '=', $status ];
+ }
+
+ $page = input('page', 1);
+ $list = $model->getMemberRechargeCardPageList($condition, $page, $page_size, 'card_id desc', $this->card_field);
+ return $list;
+ } else {
+
+ $page_size = input('page_size', PAGE_LIST_ROWS);
+
+ $list = $model->getMemberRechargeCardPageList($condition, 1, $page_size, 'card_id desc', $this->card_field);
+ $this->assign('list', $list);
+
+ $this->assign('recharge_id', $recharge_id);
+ return $this->fetch('memberrecharge/card_lists');
+ }
+
+ }
+
+ /**
+ * 开卡详情
+ * @return mixed
+ */
+ public function cardDetail()
+ {
+ $model = new MemberRechargeCardModel();
+
+ $card_id = input('card_id', '');
+
+ //获取详情
+ $info = $model->getMemberRechargeCardInfo(
+ [ [ 'card_id', '=', $card_id ] ],
+ $this->card_field
+ )[ 'data' ] ?? [];
+ $this->assign('info', $info);
+
+ return $this->fetch('memberrecharge/card_detail');
+ }
+
+ /**
+ * 订单列表
+ * @return array|mixed
+ */
+ public function orderLists()
+ {
+ $recharge_id = input('recharge_id', 0);
+ $model = new MemberRechargeOrderModel();
+ //获取续签信息
+ if (request()->isJson()) {
+ $page = input('page', 1);
+ $page_size = input('page_size', PAGE_LIST_ROWS);
+ $nickname = input('nickname', '');
+ $start_time = input('start_time', '');
+ $end_time = input('end_time', '');
+ $order_no = input('order_no', '');
+ $store_id = input('store_id', '');
+
+ $condition = [
+ // [ 'a.status', '=', 2 ],
+ [ 'a.site_id', '=', $this->site_id ]
+ ];
+
+ if ($recharge_id > 0) {
+ $condition[] = [ 'recharge_id', '=', $recharge_id ];
+ }
+
+ if ($nickname) {
+ $condition[] = [ 'a.nickname', 'like', '%' . $nickname . '%' ];
+ }
+ if ($order_no) {
+ $condition[] = [ 'a.order_no', '=', $order_no ];
+ }
+ if ($store_id != '') {
+ $condition[] = [ 'a.store_id', '=', $store_id ];
+ }
+ //支付时间
+ if (!empty($start_time) && empty($end_time)) {
+ $condition[] = [ "a.pay_time", ">=", date_to_time($start_time) ];
+ } elseif (empty($start_time) && !empty($end_time)) {
+ $condition[] = [ "a.pay_time", "<=", date_to_time($end_time) ];
+ } elseif (!empty($start_time) && !empty($end_time)) {
+ $condition[] = [ 'a.pay_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
+ }
+ $alias = 'a';
+ $join[] = [
+ 'store s',
+ 's.store_id = a.store_id',
+ 'left'
+ ];
+ $order = 'a.create_time desc';
+ $list = $model->getMemberRechargeOrderPageList($condition, $page, $page_size, $order, $this->order_field, $alias, $join);
+ return $list;
+ } else {
+ $this->assign('recharge_id', $recharge_id);
+
+ $order_num = $model->getOrderCount([ [ 'site_id', '=', $this->site_id ], [ 'status', '=', 2 ] ], 'order_id')[ 'data' ];
+ $this->assign('order_num', $order_num);
+
+ $order_money = $model->getOrderSum([ [ 'site_id', '=', $this->site_id ], [ 'status', '=', 2 ] ], 'price')[ 'data' ];
+ $this->assign('order_money', $order_money);
+
+ if (addon_is_exit('store') == 1) {
+ $store_model = new StoreModel();
+ $store_list = $store_model->getStoreList([
+ [ 'site_id', '=', $this->site_id ]
+ ], 'store_id,store_name')[ 'data' ];
+ $this->assign('store_list', $store_list);
+ }
+
+ $this->assign('printer_addon_is_exit',addon_is_exit('printer'));
+
+ return $this->fetch('memberrecharge/order_lists');
+ }
+ }
+
+ /**
+ * 订单详情
+ * @return mixed
+ */
+ public function orderDetail()
+ {
+ $order_id = input('order_id', '');
+
+ $condition = [
+ [ 'a.order_id', '=', $order_id ],
+ [ 'a.site_id', '=', $this->site_id ]
+ ];
+
+ $alias = 'a';
+ $join[] = [
+ 'store s',
+ 's.store_id = a.store_id',
+ 'left'
+ ];
+
+ $model = new MemberRechargeOrderModel();
+ $info = $model->getMemberRechargeOrderInfo($condition, $this->order_field, $alias, $join)[ 'data' ] ?? [];
+ if (empty($info)) $this->error('未获取到订单数据', href_url('memberrecharge://shop/memberrecharge/order_lists'));
+ $this->assign('info', $info);
+
+ return $this->fetch('memberrecharge/order_detail');
+ }
+
+ /**
+ * 是否开启充值
+ * @return mixed
+ */
+ public function setConfig()
+ {
+ $model = new MemberRechargeModel();
+ $is_use = input('is_use', 0);
+ $data = [];
+ return $model->setConfig($data, $is_use, $this->site_id);
+ }
+
+ public function exportRecharge()
+ {
+ $recharge_id = input("recharge_id", "");//订单状态
+
+ $condition[] = [ "recharge_id", "=", $recharge_id ];
+ $model = new MemberRechargeCardModel();
+
+ $list = $model->getMemberRechargeCardPageList($condition, 1, 0, 'card_id desc', "*");
+ if (empty($list[ 'data' ][ 'list' ])) {
+ return $this->error("未查询到数据");
+ }
+
+ // 实例化excel
+ $phpExcel = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
+
+ $phpExcel->getProperties()->setTitle("充值记录");
+ $phpExcel->getProperties()->setSubject("充值记录");
+ // 对单元格设置居中效果
+ $phpExcel->getActiveSheet()->getStyle('A')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+ $phpExcel->getActiveSheet()->getStyle('B')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+ $phpExcel->getActiveSheet()->getStyle('C')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+ $phpExcel->getActiveSheet()->getStyle('D')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+ $phpExcel->getActiveSheet()->getStyle('E')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+ $phpExcel->getActiveSheet()->getStyle('F')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+ $phpExcel->getActiveSheet()->getStyle('G')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+ $phpExcel->getActiveSheet()->getStyle('H')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+ $phpExcel->getActiveSheet()->getStyle('I')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+ $phpExcel->getActiveSheet()->getStyle('J')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+ $phpExcel->getActiveSheet()->getStyle('K')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+ $phpExcel->getActiveSheet()->getStyle('L')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+ //单独添加列名称
+ $phpExcel->setActiveSheetIndex(0);
+ $phpExcel->getActiveSheet()->setCellValue('A1', '店铺名称');//可以指定位置
+ $phpExcel->getActiveSheet()->setCellValue('B1', '充值卡号');
+ $phpExcel->getActiveSheet()->setCellValue('C1', '套餐名称');
+ $phpExcel->getActiveSheet()->setCellValue('D1', '面值');
+ $phpExcel->getActiveSheet()->setCellValue('E1', '积分');
+ $phpExcel->getActiveSheet()->setCellValue('F1', '成长值');
+ $phpExcel->getActiveSheet()->setCellValue('G1', '购买金额');
+ $phpExcel->getActiveSheet()->setCellValue('H1', '会员昵称');
+ $phpExcel->getActiveSheet()->setCellValue('I1', '订单编号');
+ $phpExcel->getActiveSheet()->setCellValue('J1', '使用状态');
+ $phpExcel->getActiveSheet()->setCellValue('K1', '创建时间');
+ $phpExcel->getActiveSheet()->setCellValue('L1', '使用时间');
+ //循环添加数据(根据自己的逻辑)
+ foreach ($list[ 'data' ][ 'list' ] as $k => $v) {
+ $i = $k + 2;
+ if ($v[ 'use_status' ] == 1) {
+ $status_name = "未使用";
+ } else {
+ $status_name = "已使用";
+ }
+
+ $phpExcel->getActiveSheet()->setCellValue('A' . $i, $v[ 'site_name' ]);
+ $phpExcel->getActiveSheet()->setCellValue('B' . $i, $v[ 'card_account' ]);
+ $phpExcel->getActiveSheet()->setCellValue('C' . $i, $v[ 'recharge_name' ]);
+ $phpExcel->getActiveSheet()->setCellValue('D' . $i, $v[ 'face_value' ]);
+ $phpExcel->getActiveSheet()->setCellValue('E' . $i, $v[ 'point' ]);
+ $phpExcel->getActiveSheet()->setCellValue('F' . $i, $v[ 'growth' ]);
+ $phpExcel->getActiveSheet()->setCellValue('G' . $i, $v[ 'buy_price' ]);
+ $phpExcel->getActiveSheet()->setCellValue('H' . $i, $v[ 'nickname' ]);
+ $phpExcel->getActiveSheet()->setCellValue('I' . $i, ' ' . (string) $v[ 'order_no' ]);
+ $phpExcel->getActiveSheet()->setCellValue('J' . $i, $status_name);
+ $phpExcel->getActiveSheet()->setCellValue('K' . $i, date('Y-m-d', $v[ 'create_time' ]));
+ $phpExcel->getActiveSheet()->setCellValue('L' . $i, date('Y-m-d', $v[ 'use_time' ]));
+ }
+
+ // 重命名工作sheet
+ $phpExcel->getActiveSheet()->setTitle('充值记录');
+ // 设置第一个sheet为工作的sheet
+ $phpExcel->setActiveSheetIndex(0);
+ // 保存Excel 2007格式文件,保存路径为当前路径,名字为export.xlsx
+ $objWriter = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($phpExcel, 'Xlsx');
+ $file = date('Y年m月d日-充值记录表', time()) . '.xlsx';
+ $objWriter->save($file);
+
+ header("Content-type:application/octet-stream");
+
+ $filename = basename($file);
+ header("Content-Disposition:attachment;filename = " . $filename);
+ header("Accept-ranges:bytes");
+ header("Accept-length:" . filesize($file));
+ readfile($file);
+ unlink($file);
+ exit;
+ }
+
+ /**
+ * 打印订单小票
+ * @return array|mixed|void
+ */
+ public function printTicket()
+ {
+ if (addon_is_exit('printer') == 0) return error('', '未安装打印小票插件');
+
+ if (request()->isJson()) {
+ $order_id = input('order_id', 0);
+ $printer_order_model = new PrinterOrder();
+ $recharge_order = ( new MemberrechargeOrder() )->getMemberRechargeOrderInfo([ [ 'relate_type', '=', 'order' ], [ 'order_id', '=', $order_id ] ], 'order_id')[ 'data' ];
+ if (empty($recharge_order)) return error('', '未获取到充值订单信息');
+ $res = $printer_order_model->printer([
+ 'order_id' => $recharge_order[ 'order_id' ],
+ 'type' => 'recharge',
+ ]);
+ return $res;
+ }
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/memberwithdraw/config/diy_view.php b/src/addon/memberwithdraw/config/diy_view.php
index c3c657905..e36ca9b7d 100644
--- a/src/addon/memberwithdraw/config/diy_view.php
+++ b/src/addon/memberwithdraw/config/diy_view.php
@@ -1,38 +1,30 @@
- '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
- 'template' => [],
-
- // 后台自定义组件——装修
- 'util' => [],
-
- // 自定义页面路径
- 'link' => [],
-
- // 自定义图标库
- 'icon_library' => [],
-
- // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
- 'component' => [],
-
- // uni-app 页面,多个逗号隔开
- 'pages' => [],
-
- // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
- 'info' => [],
-
- // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
- 'theme' => [],
-
- // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
- 'data' => []
+ '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
+ 'template' => [],
+
+ // 后台自定义组件——装修
+ 'util' => [],
+
+ // 自定义页面路径
+ 'link' => [],
+
+ // 自定义图标库
+ 'icon_library' => [],
+
+ // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
+ 'component' => [],
+
+ // uni-app 页面,多个逗号隔开
+ 'pages' => [],
+
+ // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
+ 'info' => [],
+
+ // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
+ 'theme' => [],
+
+ // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
+ 'data' => []
];
\ No newline at end of file
diff --git a/src/addon/memberwithdraw/config/info.php b/src/addon/memberwithdraw/config/info.php
index bfbb67934..a6fe3ad7d 100644
--- a/src/addon/memberwithdraw/config/info.php
+++ b/src/addon/memberwithdraw/config/info.php
@@ -1,21 +1,12 @@
- 'memberwithdraw',
- 'title' => '会员提现',
- 'description' => '会员提现',
- 'type' => 'tool', //插件类型 system :系统插件(自动安装),promotion:扩展营销插件 tool:工具插件
- 'status' => 1,
- 'author' => '',
- 'version' => '5.3.1',
- 'version_no' => '525231212001',
- 'content' => '',
+ 'memberwithdraw',
+ 'title' => '会员提现',
+ 'description' => '会员提现',
+ 'type' => 'tool', //插件类型 system :系统插件(自动安装),promotion:扩展营销插件 tool:工具插件
+ 'status' => 1,
+ 'author' => '',
+ 'version' => '5.3.1',
+ 'version_no' => '525231212001',
+ 'content' => '',
];
\ No newline at end of file
diff --git a/src/addon/memberwithdraw/event/Install.php b/src/addon/memberwithdraw/event/Install.php
index 75dfc002d..c7c85adb7 100644
--- a/src/addon/memberwithdraw/event/Install.php
+++ b/src/addon/memberwithdraw/event/Install.php
@@ -1,26 +1,17 @@
-getMemberWithdrawInfo([ [ "id", "=", $id ] ], "withdraw_no,account_number,realname,money,memo,transfer_type,site_id,applet_type,member_id");
- if (empty($info_result[ "data" ]))
- return $this->error();
-
- $info = $info_result[ "data" ];
- if (!in_array($info[ "transfer_type" ], [ "wechatpay", "alipay" ]))
- return $this->error('', "当前提现方式不支持在线转账");
-
- $pay_data = array (
- "id" => $id,
- "out_trade_no" => $info[ "withdraw_no" ],
- "real_name" => $info[ "realname" ],
- "amount" => $info[ "money" ],
- "desc" => "会员提现" . $info[ "memo" ],
- "transfer_type" => $info[ "transfer_type" ],
- "account_number" => $info[ "account_number" ],
- "site_id" => $info[ "site_id" ],
- "is_weapp" => $info[ "applet_type" ],
- "member_id" => $info[ 'member_id' ]
- );
- //调用在线转账借口
- $pay_result = event("PayTransfer", $pay_data, true);
- if (empty($pay_result)) {
- $pay_result = $this->error();
- }
- if ($pay_result[ "code" ] < 0) {
- return $pay_result;
- }
- //调用完成转账
- $result = $withdraw_model->transferFinish([ "id" => $id, "site_id" => $info[ "site_id" ] ]);
- return $result;
- }
+getMemberWithdrawInfo([ [ "id", "=", $id ] ], "withdraw_no,account_number,realname,money,memo,transfer_type,site_id,applet_type,member_id");
+ if (empty($info_result[ "data" ]))
+ return $this->error();
+
+ $info = $info_result[ "data" ];
+ if (!in_array($info[ "transfer_type" ], [ "wechatpay", "alipay" ]))
+ return $this->error('', "当前提现方式不支持在线转账");
+
+ $pay_data = array (
+ "id" => $id,
+ "out_trade_no" => $info[ "withdraw_no" ],
+ "real_name" => $info[ "realname" ],
+ "amount" => $info[ "money" ],
+ "desc" => "会员提现" . $info[ "memo" ],
+ "transfer_type" => $info[ "transfer_type" ],
+ "account_number" => $info[ "account_number" ],
+ "site_id" => $info[ "site_id" ],
+ "is_weapp" => $info[ "applet_type" ],
+ "member_id" => $info[ 'member_id' ]
+ );
+ //调用在线转账借口
+ $pay_result = event("PayTransfer", $pay_data, true);
+ if (empty($pay_result)) {
+ $pay_result = $this->error();
+ }
+ if ($pay_result[ "code" ] < 0) {
+ return $pay_result;
+ }
+ //调用完成转账
+ $result = $withdraw_model->transferFinish([ "id" => $id, "site_id" => $info[ "site_id" ] ]);
+ return $result;
+ }
}
\ No newline at end of file
diff --git a/src/addon/memberwithdraw/shop/controller/Withdraw.php b/src/addon/memberwithdraw/shop/controller/Withdraw.php
index 02c22c846..60200338d 100644
--- a/src/addon/memberwithdraw/shop/controller/Withdraw.php
+++ b/src/addon/memberwithdraw/shop/controller/Withdraw.php
@@ -1,35 +1,27 @@
-isJson()) {
- $id = input('id', 0);
- $withdraw_model = new WithdrawModel();
- $result = $withdraw_model->transfer($id);
- return $result;
- }
- }
-
+isJson()) {
+ $id = input('id', 0);
+ $withdraw_model = new WithdrawModel();
+ $result = $withdraw_model->transfer($id);
+ return $result;
+ }
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/merch/config/diy_view.php b/src/addon/merch/config/diy_view.php
index 0e685b414..0f63c58ae 100644
--- a/src/addon/merch/config/diy_view.php
+++ b/src/addon/merch/config/diy_view.php
@@ -1,48 +1,40 @@
- '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
- 'template' => [],
-
- // 后台自定义组件——装修
- 'util' => [],
-
- // 自定义页面路径
- 'link' => [
- /* [
- 'name' => 'MERCH_INFO',
- 'title' => '多商户',
- 'parent' => 'BASICS_LINK',
- 'wap_url' => '',
- 'web_url' => '',
- 'sort' => 0
- ]*/
- ],
-
- // 自定义图标库
- 'icon_library' => [],
-
- // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
- 'component' => [],
-
- // uni-app 页面,多个逗号隔开
- 'pages' => [],
-
- // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
- 'info' => [],
-
- // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
- 'theme' => [],
-
- // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
- 'data' => []
+ '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
+ 'template' => [],
+
+ // 后台自定义组件——装修
+ 'util' => [],
+
+ // 自定义页面路径
+ 'link' => [
+ /* [
+ 'name' => 'MERCH_INFO',
+ 'title' => '多商户',
+ 'parent' => 'BASICS_LINK',
+ 'wap_url' => '',
+ 'web_url' => '',
+ 'sort' => 0
+ ]*/
+ ],
+
+ // 自定义图标库
+ 'icon_library' => [],
+
+ // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
+ 'component' => [],
+
+ // uni-app 页面,多个逗号隔开
+ 'pages' => [],
+
+ // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
+ 'info' => [],
+
+ // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
+ 'theme' => [],
+
+ // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
+ 'data' => []
];
\ No newline at end of file
diff --git a/src/addon/merch/event/Install.php b/src/addon/merch/event/Install.php
index 70d49c08d..27360fd8a 100644
--- a/src/addon/merch/event/Install.php
+++ b/src/addon/merch/event/Install.php
@@ -1,25 +1,17 @@
-getMessage());
- }
- }
+getMessage());
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/personnel/config/diy_view.php b/src/addon/personnel/config/diy_view.php
index 1872e00c4..0fe9cf839 100644
--- a/src/addon/personnel/config/diy_view.php
+++ b/src/addon/personnel/config/diy_view.php
@@ -1,48 +1,40 @@
- '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
- 'template' => [],
-
- // 后台自定义组件——装修
- 'util' => [],
-
- // 自定义页面路径
- 'link' => [
- [
- 'name' => 'MINGPIAN_INFO',
- 'title' => '电子名片',
- 'parent' => 'BASICS_LINK',
- 'wap_url' => '/pages/contact/contact',
- 'web_url' => '',
- 'sort' => 0
- ]
- ],
-
- // 自定义图标库
- 'icon_library' => [],
-
- // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
- 'component' => [],
-
- // uni-app 页面,多个逗号隔开
- 'pages' => [],
-
- // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
- 'info' => [],
-
- // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
- 'theme' => [],
-
- // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
- 'data' => []
+ '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
+ 'template' => [],
+
+ // 后台自定义组件——装修
+ 'util' => [],
+
+ // 自定义页面路径
+ 'link' => [
+ [
+ 'name' => 'MINGPIAN_INFO',
+ 'title' => '电子名片',
+ 'parent' => 'BASICS_LINK',
+ 'wap_url' => '/pages/contact/contact',
+ 'web_url' => '',
+ 'sort' => 0
+ ]
+ ],
+
+ // 自定义图标库
+ 'icon_library' => [],
+
+ // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
+ 'component' => [],
+
+ // uni-app 页面,多个逗号隔开
+ 'pages' => [],
+
+ // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
+ 'info' => [],
+
+ // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
+ 'theme' => [],
+
+ // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
+ 'data' => []
];
\ No newline at end of file
diff --git a/src/addon/personnel/config/info.php b/src/addon/personnel/config/info.php
index 73bae96f3..b15cf8082 100644
--- a/src/addon/personnel/config/info.php
+++ b/src/addon/personnel/config/info.php
@@ -1,21 +1,12 @@
- 'personnel',
- 'title' => '电子名片',
- 'description' => '展示公司人员名片信息',
- 'type' => 'tool', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
- 'status' => 1,
- 'author' => '',
- 'version' => '5.3.1',
- 'version_no' => '525231212001',
- 'content' => '',
+ 'personnel',
+ 'title' => '电子名片',
+ 'description' => '展示公司人员名片信息',
+ 'type' => 'tool', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
+ 'status' => 1,
+ 'author' => '',
+ 'version' => '5.3.1',
+ 'version_no' => '525231212001',
+ 'content' => '',
];
\ No newline at end of file
diff --git a/src/addon/personnel/event/Install.php b/src/addon/personnel/event/Install.php
index 3a95457d9..1c9bfebe5 100644
--- a/src/addon/personnel/event/Install.php
+++ b/src/addon/personnel/event/Install.php
@@ -1,25 +1,17 @@
-getMessage());
- }
- }
+getMessage());
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/pointcash/config/diy_view.php b/src/addon/pointcash/config/diy_view.php
index c3c657905..e36ca9b7d 100644
--- a/src/addon/pointcash/config/diy_view.php
+++ b/src/addon/pointcash/config/diy_view.php
@@ -1,38 +1,30 @@
- '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
- 'template' => [],
-
- // 后台自定义组件——装修
- 'util' => [],
-
- // 自定义页面路径
- 'link' => [],
-
- // 自定义图标库
- 'icon_library' => [],
-
- // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
- 'component' => [],
-
- // uni-app 页面,多个逗号隔开
- 'pages' => [],
-
- // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
- 'info' => [],
-
- // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
- 'theme' => [],
-
- // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
- 'data' => []
+ '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
+ 'template' => [],
+
+ // 后台自定义组件——装修
+ 'util' => [],
+
+ // 自定义页面路径
+ 'link' => [],
+
+ // 自定义图标库
+ 'icon_library' => [],
+
+ // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
+ 'component' => [],
+
+ // uni-app 页面,多个逗号隔开
+ 'pages' => [],
+
+ // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
+ 'info' => [],
+
+ // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
+ 'theme' => [],
+
+ // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
+ 'data' => []
];
\ No newline at end of file
diff --git a/src/addon/pointcash/config/info.php b/src/addon/pointcash/config/info.php
index 838e1a083..e1b488f87 100644
--- a/src/addon/pointcash/config/info.php
+++ b/src/addon/pointcash/config/info.php
@@ -1,20 +1,12 @@
- 'pointcash',
- 'title' => '积分抵现',
- 'description' => '下单时积分可抵部分现金',
- 'type' => 'tool', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
- 'status' => 1,
- 'author' => '',
- 'version' => '5.3.1',
- 'version_no' => '525231212001',
- 'content' => '',
+ 'pointcash',
+ 'title' => '积分抵现',
+ 'description' => '下单时积分可抵部分现金',
+ 'type' => 'tool', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
+ 'status' => 1,
+ 'author' => '',
+ 'version' => '5.3.1',
+ 'version_no' => '525231212001',
+ 'content' => '',
];
\ No newline at end of file
diff --git a/src/addon/pointcash/event/Install.php b/src/addon/pointcash/event/Install.php
index c09b8d9d2..25dcf2d59 100644
--- a/src/addon/pointcash/event/Install.php
+++ b/src/addon/pointcash/event/Install.php
@@ -1,25 +1,17 @@
- [
- 'pointcash' => [
- 'type_name' => '积分抵现',
- 'type_url' => '',
- ],
- ]
- ];
- if ($data == '') {
- return $from_type;
- } else {
- return $from_type[$data] ?? [];
- }
-
- }
+ [
+ 'pointcash' => [
+ 'type_name' => '积分抵现',
+ 'type_url' => '',
+ ],
+ ]
+ ];
+ if ($data == '') {
+ return $from_type;
+ } else {
+ return $from_type[$data] ?? [];
+ }
+
+ }
}
\ No newline at end of file
diff --git a/src/addon/pointcash/event/PointRule.php b/src/addon/pointcash/event/PointRule.php
index 0f34aa2dc..7b7e5f585 100644
--- a/src/addon/pointcash/event/PointRule.php
+++ b/src/addon/pointcash/event/PointRule.php
@@ -1,34 +1,25 @@
-getPointCashConfig($data['site_id'])['data'];
-
- $data = [
- 'title' => '积分抵现',
- 'content' => !$info['is_use'] || !$info['value']['cash_rate'] ? '-' : $info['value']['cash_rate'] . "积分可抵1元",
- 'url' => 'pointcash://shop/config/index',
- 'update_time' => $info['modify_time']
- ];
- return $data;
- }
+getPointCashConfig($data['site_id'])['data'];
+
+ $data = [
+ 'title' => '积分抵现',
+ 'content' => !$info['is_use'] || !$info['value']['cash_rate'] ? '-' : $info['value']['cash_rate'] . "积分可抵1元",
+ 'url' => 'pointcash://shop/config/index',
+ 'update_time' => $info['modify_time']
+ ];
+ return $data;
+ }
}
\ No newline at end of file
diff --git a/src/addon/pointcash/event/ShowPromotion.php b/src/addon/pointcash/event/ShowPromotion.php
index f260abd57..a1785ee9b 100644
--- a/src/addon/pointcash/event/ShowPromotion.php
+++ b/src/addon/pointcash/event/ShowPromotion.php
@@ -1,95 +1,87 @@
- [
-
- ],
- 'shop' => [
- [
- //插件名称
- 'name' => 'pointcash',
- //展示分类(根据平台端设置,admin(平台营销),shop:店铺营销,member:会员营销, tool:应用工具)
- 'show_type' => 'shop',
- //展示主题
- 'title' => '积分抵现',
- //展示介绍
- 'description' => '下单时积分抵扣现金',
- //展示图标
- 'icon' => 'addon/pointcash/icon.png',
- //跳转链接
- 'url' => 'pointcash://shop/config/index',
- 'summary' => $this->summary($params)
- ],
-
- ],
-
- ];
- return $data;
- }
-
- /**
- * 营销活动概况
- * @param $params
- * @return array
- */
- private function summary($params)
- {
- if (empty($params)) {
- return [];
- }
-
- if(isset($params['promotion_type']) && $params['promotion_type'] != $this->promotion_type){
- return [];
- }
-
- if (isset($params[ 'count' ]) || isset($params[ 'summary' ])) $config = ( new Config() )->getPointCashConfig($params[ 'site_id' ])[ 'data' ];
- //获取活动数量
- if (isset($params[ 'count' ])) {
- return [
- 'count' => $config[ 'is_use' ]
- ];
- }
-
- //获取活动概况,需要获取开始时间与结束时间
-
- if (isset($params[ 'summary' ])) {
- $value = $config[ 'value' ];
- return [
- 'unlimited_time' => [
- 'status' => $config[ 'is_use' ],
- 'detail' => empty($value[ 'cash_rate' ]) ? '未配置活动' : $value[ 'cash_rate' ] . '积分可抵1元',
- 'switch_type' => empty($value[ 'cash_rate' ]) ? 'jump' : 'switch',
- 'config_key' => 'POINTCASH_CONFIG'
- ]
- ];
- }
- }
-
+ [
+
+ ],
+ 'shop' => [
+ [
+ //插件名称
+ 'name' => 'pointcash',
+ //展示分类(根据平台端设置,admin(平台营销),shop:店铺营销,member:会员营销, tool:应用工具)
+ 'show_type' => 'shop',
+ //展示主题
+ 'title' => '积分抵现',
+ //展示介绍
+ 'description' => '下单时积分抵扣现金',
+ //展示图标
+ 'icon' => 'addon/pointcash/icon.png',
+ //跳转链接
+ 'url' => 'pointcash://shop/config/index',
+ 'summary' => $this->summary($params)
+ ],
+
+ ],
+
+ ];
+ return $data;
+ }
+
+ /**
+ * 营销活动概况
+ * @param $params
+ * @return array
+ */
+ private function summary($params)
+ {
+ if (empty($params)) {
+ return [];
+ }
+
+ if(isset($params['promotion_type']) && $params['promotion_type'] != $this->promotion_type){
+ return [];
+ }
+
+ if (isset($params[ 'count' ]) || isset($params[ 'summary' ])) $config = ( new Config() )->getPointCashConfig($params[ 'site_id' ])[ 'data' ];
+ //获取活动数量
+ if (isset($params[ 'count' ])) {
+ return [
+ 'count' => $config[ 'is_use' ]
+ ];
+ }
+
+ //获取活动概况,需要获取开始时间与结束时间
+
+ if (isset($params[ 'summary' ])) {
+ $value = $config[ 'value' ];
+ return [
+ 'unlimited_time' => [
+ 'status' => $config[ 'is_use' ],
+ 'detail' => empty($value[ 'cash_rate' ]) ? '未配置活动' : $value[ 'cash_rate' ] . '积分可抵1元',
+ 'switch_type' => empty($value[ 'cash_rate' ]) ? 'jump' : 'switch',
+ 'config_key' => 'POINTCASH_CONFIG'
+ ]
+ ];
+ }
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/pointcash/event/UnInstall.php b/src/addon/pointcash/event/UnInstall.php
index e6a0736f6..85b76aaa9 100644
--- a/src/addon/pointcash/event/UnInstall.php
+++ b/src/addon/pointcash/event/UnInstall.php
@@ -1,25 +1,17 @@
-setConfig($data, '积分抵现', 1, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'POINTCASH_CONFIG' ] ]);
- return $res;
- }
-
- /**
- * 获取积分抵现配置
- * @param $site_id
- * @param string $app_module
- * @return array
- */
- public function getPointCashConfig($site_id, $app_module = 'shop')
- {
- $config = new ConfigModel();
- $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'POINTCASH_CONFIG' ] ]);
- if (empty($res[ 'data' ][ 'value' ])) {
- //默认值设置
- $res[ 'data' ][ 'value' ] = [
- 'is_enable' => 0, // 是否开启
- 'cash_rate' => 0, // 抵现比率
- 'is_limit' => 0, // 是否限制订单金额门槛
- 'limit' => 0.00, // 订单金额门槛
- 'is_limit_use' => 0, // 是否限制使用上限
- 'type' => 0, // 限制类型 0:固定金额 1:订单百分比
- 'max_use' => 0 // 最大可用
- ];
- }
- return $res;
- }
+setConfig($data, '积分抵现', 1, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'POINTCASH_CONFIG' ] ]);
+ return $res;
+ }
+
+ /**
+ * 获取积分抵现配置
+ * @param $site_id
+ * @param string $app_module
+ * @return array
+ */
+ public function getPointCashConfig($site_id, $app_module = 'shop')
+ {
+ $config = new ConfigModel();
+ $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'POINTCASH_CONFIG' ] ]);
+ if (empty($res[ 'data' ][ 'value' ])) {
+ //默认值设置
+ $res[ 'data' ][ 'value' ] = [
+ 'is_enable' => 0, // 是否开启
+ 'cash_rate' => 0, // 抵现比率
+ 'is_limit' => 0, // 是否限制订单金额门槛
+ 'limit' => 0.00, // 订单金额门槛
+ 'is_limit_use' => 0, // 是否限制使用上限
+ 'type' => 0, // 限制类型 0:固定金额 1:订单百分比
+ 'max_use' => 0 // 最大可用
+ ];
+ }
+ return $res;
+ }
}
\ No newline at end of file
diff --git a/src/addon/pointcash/shop/controller/Config.php b/src/addon/pointcash/shop/controller/Config.php
index a13db289f..f82a10d34 100644
--- a/src/addon/pointcash/shop/controller/Config.php
+++ b/src/addon/pointcash/shop/controller/Config.php
@@ -1,44 +1,36 @@
-isJson()) {
- $data = [
- 'is_enable' => input('is_enable', 0), // 是否开启
- 'cash_rate' => input('cash_rate', 0), // 抵现比率
- 'is_limit' => input('is_limit', 0), // 是否限制订单金额门槛
- 'limit' => input('limit', 0.00), // 订单金额门槛
- 'is_limit_use' => input('is_limit_use', 0), // 是否限制使用上限
- 'type' => input('type', 0), // 限制类型 0:固定金额 1:订单百分比
- 'max_use' => input('max_use', 0) // 最大可用
- ];
- $res = $config->setPointCashConfig($data, $this->site_id);
- return $res;
- } else {
- $info = $config->getPointCashConfig($this->site_id);
- $this->assign('config', $info[ 'data' ][ 'value' ]);
- return $this->fetch('config/index');
- }
- }
+isJson()) {
+ $data = [
+ 'is_enable' => input('is_enable', 0), // 是否开启
+ 'cash_rate' => input('cash_rate', 0), // 抵现比率
+ 'is_limit' => input('is_limit', 0), // 是否限制订单金额门槛
+ 'limit' => input('limit', 0.00), // 订单金额门槛
+ 'is_limit_use' => input('is_limit_use', 0), // 是否限制使用上限
+ 'type' => input('type', 0), // 限制类型 0:固定金额 1:订单百分比
+ 'max_use' => input('max_use', 0) // 最大可用
+ ];
+ $res = $config->setPointCashConfig($data, $this->site_id);
+ return $res;
+ } else {
+ $info = $config->getPointCashConfig($this->site_id);
+ $this->assign('config', $info[ 'data' ][ 'value' ]);
+ return $this->fetch('config/index');
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/pointexchange/api/controller/Goods.php b/src/addon/pointexchange/api/controller/Goods.php
index 7d4ffbaad..c6cad13e7 100644
--- a/src/addon/pointexchange/api/controller/Goods.php
+++ b/src/addon/pointexchange/api/controller/Goods.php
@@ -1,209 +1,201 @@
-params['id'] ?? 0;
- if (empty($id)) {
- return $this->response($this->error('', 'REQUEST_ID'));
- }
- $exchange_model = new ExchangeModel();
-
- $exchange_info = $exchange_model->getExchangeInfo($id, 'type, type_id')[ 'data' ];
- $condition = [
- [ 'peg.id', '=', $id ],
- [ 'peg.site_id', '=', $this->site_id ],
- [ 'peg.state', '=', 1 ],
- ];
-
- if (empty($exchange_info)) return $this->response($this->error('', '商品未找到'));
- $info = $exchange_model->getExchangeDetail($condition, $exchange_info[ 'type' ])[ 'data' ];
-
- if (empty($info)) return $this->response($this->error($info));
-
- if ($exchange_info[ 'type' ] == 1) {
-
- //判断商品规格项
- $goods_spec_format = $exchange_model->getGoodsSpecFormat($info[ 'exchange_id' ], $this->site_id, $info[ 'goods_spec_format' ]);
- $info[ 'goods_spec_format' ] = json_encode($goods_spec_format);
-
- $goods_service = new GoodsService();
- $info[ 'goods_service' ] = $goods_service->getServiceList([ [ 'site_id', '=', $this->site_id ], [ 'id', 'in', $info[ 'goods_service_ids' ] ] ], 'service_name,desc,icon')[ 'data' ];
- }
-
- return $this->response($this->success($info));
- }
-
- /**
- * 查询商品SKU集合
- * @return false|string
- */
- public function goodsSku()
- {
- $goods_id = $this->params['goods_id'] ?? 0;
- $exchange_id = $this->params['exchange_id'] ?? 0;
- $type = $this->params['type'] ?? 0;
- if (empty($goods_id)) {
- return $this->response($this->error('', 'REQUEST_ID'));
- }
- if (empty($exchange_id)) {
- return $this->response($this->error('', 'REQUEST_ID'));
- }
- $exchange_model = new ExchangeModel();
- $condition = [
- [ 'peg.id', '=', $exchange_id ],
- [ 'peg.site_id', '=', $this->site_id ],
- [ 'peg.state', '=', 1 ],
- ];
- $list = $exchange_model->getExchangeSkuList($condition, $type);
- if (!empty($list[ 'data' ])) {
- foreach ($list[ 'data' ] as $k => $v) {
- if (!empty($v[ 'goods_spec_format' ])) {
- $goods_spec_format = $exchange_model->getGoodsSpecFormat($v[ 'exchange_id' ], $this->site_id, $v[ 'goods_spec_format' ]);
- $list[ 'data' ][ $k ][ 'goods_spec_format' ] = json_encode($goods_spec_format);
- }
- }
- }
-
- return $this->response($list);
- }
-
- public function page()
- {
- $page = $this->params['page'] ?? 1;
- $page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
- $type = $this->params['type'] ?? 1;//兑换类型,1:商品,2:优惠券,3:红包
-
- //商品类型条件查询
- $keyword = $this->params['keyword'] ?? ''; //关键词
- $order = $this->params['order'] ?? '';//排序(综合、上新时间、价格)
- $sort = $this->params['sort'] ?? '';//升序、降序
- $min_point = $this->params['min_point'] ?? 0;//积分区间,小
- $max_point = $this->params['max_point'] ?? 0;//积分区间,大
- $category_id = $this->params['category_id'] ?? 0;//分类
- $condition = [
- [ 'peg.state', '=', 1 ],
- [ 'peg.type', '=', $type ],
- [ 'peg.site_id', '=', $this->site_id ]
- ];
-
- if (!empty($keyword)) {
- $condition[] = [ 'g.goods_name|peg.name', 'like', '%' . $keyword . '%' ];
- }
-
- // 非法参数进行过滤
- if ($sort != 'desc' && $sort != 'asc') {
- $sort = '';
- }
- // 非法参数进行过滤
- if ($order != '') {
- if ($order != 'create_time' && $order != 'point') {
- $order = 'peg.sort';
- } elseif ($order == 'create_time') {
- $order = 'peg.create_time';
- } else {
- $order = 'peg.' . $order;
- }
- $order_by = $order . ' ' . $sort;
- } else {
- $config_model = new ConfigModel();
- $sort_config = $config_model->getGoodsSort($this->site_id)[ 'data' ][ 'value' ];
- $order_by = 'peg.sort ' . $sort_config[ 'type' ] . ',peg.create_time desc';
- }
-
- if ($min_point != '' && $max_point != '') {
- $condition[] = [ 'peg.point', 'between', [ $min_point, $max_point ] ];
- } elseif ($min_point != '') {
- $condition[] = [ 'peg.point', '>=', $min_point ];
- } elseif ($max_point != '') {
- $condition[] = [ 'peg.point', '<=', $max_point ];
- }
-
- if (!empty($category_id)) {
- $goods_category_model = new GoodsCategoryModel();
-
- // 查询当前
- $category_list = $goods_category_model->getCategoryList([ [ 'category_id', '=', $category_id ], [ 'site_id', '=', $this->site_id ] ], 'category_id,pid,level')[ 'data' ];
-
- // 查询子级
- $category_child_list = $goods_category_model->getCategoryList([ [ 'pid', '=', $category_id ], [ 'site_id', '=', $this->site_id ] ], 'category_id,pid,level')[ 'data' ];
-
- $temp_category_list = [];
- if (!empty($category_list)) {
- $temp_category_list = $category_list;
- } elseif (!empty($category_child_list)) {
- $temp_category_list = $category_child_list;
- }
-
- if (!empty($temp_category_list)) {
- $category_id_arr = [];
- foreach ($temp_category_list as $k => $v) {
- // 三级分类,并且都能查询到
- if ($v[ 'level' ] == 3 && !empty($category_list) && !empty($category_child_list)) {
- $category_id_arr[] = $v['pid'];
- } else {
- $category_id_arr[] = $v['category_id'];
- }
- }
- $category_id_arr = array_unique($category_id_arr);
- $temp_condition = [];
- foreach ($category_id_arr as $ck => $cv) {
- $temp_condition[] = '%,' . $cv . ',%';
- }
- $category_condition = $temp_condition;
- $condition[] = [ 'g.category_id', 'like', $category_condition, 'or' ];
- }
- }
-
- $field = 'peg.*';
-
- $alias = 'peg';
- $join = [];
- if ($type == 1) {
- $condition[] = [ 'g.is_delete', '=', 0 ];
- $condition[] = [ 'g.goods_state', '=', 1 ];
-
- $join = [
- [ 'goods g', 'peg.type_id = g.goods_id', 'inner' ]
- ];
- $field .= ',g.goods_name as name,g.goods_image as image, g.goods_stock as stock, g.stock_show,g.sale_show,(g.sale_num + g.virtual_sale) as sale_num';
-
- } elseif ($type == 2) {
- $field .= ',pct.type as coupon_type,pct.goods_type,pct.at_least,pct.money,pct.discount';
- $join = [
- [ 'promotion_coupon_type pct', 'peg.type_id = pct.coupon_type_id', 'inner' ]
- ];
- }
- $exchange_model = new ExchangeModel();
-
- $list = $exchange_model->getExchangeGoodsPageList($condition, $page, $page_size, $order_by, $field, $alias, $join);
-
- return $this->response($list);
- }
-
+params['id'] ?? 0;
+ if (empty($id)) {
+ return $this->response($this->error('', 'REQUEST_ID'));
+ }
+ $exchange_model = new ExchangeModel();
+
+ $exchange_info = $exchange_model->getExchangeInfo($id, 'type, type_id')[ 'data' ];
+ $condition = [
+ [ 'peg.id', '=', $id ],
+ [ 'peg.site_id', '=', $this->site_id ],
+ [ 'peg.state', '=', 1 ],
+ ];
+
+ if (empty($exchange_info)) return $this->response($this->error('', '商品未找到'));
+ $info = $exchange_model->getExchangeDetail($condition, $exchange_info[ 'type' ])[ 'data' ];
+
+ if (empty($info)) return $this->response($this->error($info));
+
+ if ($exchange_info[ 'type' ] == 1) {
+
+ //判断商品规格项
+ $goods_spec_format = $exchange_model->getGoodsSpecFormat($info[ 'exchange_id' ], $this->site_id, $info[ 'goods_spec_format' ]);
+ $info[ 'goods_spec_format' ] = json_encode($goods_spec_format);
+
+ $goods_service = new GoodsService();
+ $info[ 'goods_service' ] = $goods_service->getServiceList([ [ 'site_id', '=', $this->site_id ], [ 'id', 'in', $info[ 'goods_service_ids' ] ] ], 'service_name,desc,icon')[ 'data' ];
+ }
+
+ return $this->response($this->success($info));
+ }
+
+ /**
+ * 查询商品SKU集合
+ * @return false|string
+ */
+ public function goodsSku()
+ {
+ $goods_id = $this->params['goods_id'] ?? 0;
+ $exchange_id = $this->params['exchange_id'] ?? 0;
+ $type = $this->params['type'] ?? 0;
+ if (empty($goods_id)) {
+ return $this->response($this->error('', 'REQUEST_ID'));
+ }
+ if (empty($exchange_id)) {
+ return $this->response($this->error('', 'REQUEST_ID'));
+ }
+ $exchange_model = new ExchangeModel();
+ $condition = [
+ [ 'peg.id', '=', $exchange_id ],
+ [ 'peg.site_id', '=', $this->site_id ],
+ [ 'peg.state', '=', 1 ],
+ ];
+ $list = $exchange_model->getExchangeSkuList($condition, $type);
+ if (!empty($list[ 'data' ])) {
+ foreach ($list[ 'data' ] as $k => $v) {
+ if (!empty($v[ 'goods_spec_format' ])) {
+ $goods_spec_format = $exchange_model->getGoodsSpecFormat($v[ 'exchange_id' ], $this->site_id, $v[ 'goods_spec_format' ]);
+ $list[ 'data' ][ $k ][ 'goods_spec_format' ] = json_encode($goods_spec_format);
+ }
+ }
+ }
+
+ return $this->response($list);
+ }
+
+ public function page()
+ {
+ $page = $this->params['page'] ?? 1;
+ $page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
+ $type = $this->params['type'] ?? 1;//兑换类型,1:商品,2:优惠券,3:红包
+
+ //商品类型条件查询
+ $keyword = $this->params['keyword'] ?? ''; //关键词
+ $order = $this->params['order'] ?? '';//排序(综合、上新时间、价格)
+ $sort = $this->params['sort'] ?? '';//升序、降序
+ $min_point = $this->params['min_point'] ?? 0;//积分区间,小
+ $max_point = $this->params['max_point'] ?? 0;//积分区间,大
+ $category_id = $this->params['category_id'] ?? 0;//分类
+ $condition = [
+ [ 'peg.state', '=', 1 ],
+ [ 'peg.type', '=', $type ],
+ [ 'peg.site_id', '=', $this->site_id ]
+ ];
+
+ if (!empty($keyword)) {
+ $condition[] = [ 'g.goods_name|peg.name', 'like', '%' . $keyword . '%' ];
+ }
+
+ // 非法参数进行过滤
+ if ($sort != 'desc' && $sort != 'asc') {
+ $sort = '';
+ }
+ // 非法参数进行过滤
+ if ($order != '') {
+ if ($order != 'create_time' && $order != 'point') {
+ $order = 'peg.sort';
+ } elseif ($order == 'create_time') {
+ $order = 'peg.create_time';
+ } else {
+ $order = 'peg.' . $order;
+ }
+ $order_by = $order . ' ' . $sort;
+ } else {
+ $config_model = new ConfigModel();
+ $sort_config = $config_model->getGoodsSort($this->site_id)[ 'data' ][ 'value' ];
+ $order_by = 'peg.sort ' . $sort_config[ 'type' ] . ',peg.create_time desc';
+ }
+
+ if ($min_point != '' && $max_point != '') {
+ $condition[] = [ 'peg.point', 'between', [ $min_point, $max_point ] ];
+ } elseif ($min_point != '') {
+ $condition[] = [ 'peg.point', '>=', $min_point ];
+ } elseif ($max_point != '') {
+ $condition[] = [ 'peg.point', '<=', $max_point ];
+ }
+
+ if (!empty($category_id)) {
+ $goods_category_model = new GoodsCategoryModel();
+
+ // 查询当前
+ $category_list = $goods_category_model->getCategoryList([ [ 'category_id', '=', $category_id ], [ 'site_id', '=', $this->site_id ] ], 'category_id,pid,level')[ 'data' ];
+
+ // 查询子级
+ $category_child_list = $goods_category_model->getCategoryList([ [ 'pid', '=', $category_id ], [ 'site_id', '=', $this->site_id ] ], 'category_id,pid,level')[ 'data' ];
+
+ $temp_category_list = [];
+ if (!empty($category_list)) {
+ $temp_category_list = $category_list;
+ } elseif (!empty($category_child_list)) {
+ $temp_category_list = $category_child_list;
+ }
+
+ if (!empty($temp_category_list)) {
+ $category_id_arr = [];
+ foreach ($temp_category_list as $k => $v) {
+ // 三级分类,并且都能查询到
+ if ($v[ 'level' ] == 3 && !empty($category_list) && !empty($category_child_list)) {
+ $category_id_arr[] = $v['pid'];
+ } else {
+ $category_id_arr[] = $v['category_id'];
+ }
+ }
+ $category_id_arr = array_unique($category_id_arr);
+ $temp_condition = [];
+ foreach ($category_id_arr as $ck => $cv) {
+ $temp_condition[] = '%,' . $cv . ',%';
+ }
+ $category_condition = $temp_condition;
+ $condition[] = [ 'g.category_id', 'like', $category_condition, 'or' ];
+ }
+ }
+
+ $field = 'peg.*';
+
+ $alias = 'peg';
+ $join = [];
+ if ($type == 1) {
+ $condition[] = [ 'g.is_delete', '=', 0 ];
+ $condition[] = [ 'g.goods_state', '=', 1 ];
+
+ $join = [
+ [ 'goods g', 'peg.type_id = g.goods_id', 'inner' ]
+ ];
+ $field .= ',g.goods_name as name,g.goods_image as image, g.goods_stock as stock, g.stock_show,g.sale_show,(g.sale_num + g.virtual_sale) as sale_num';
+
+ } elseif ($type == 2) {
+ $field .= ',pct.type as coupon_type,pct.goods_type,pct.at_least,pct.money,pct.discount';
+ $join = [
+ [ 'promotion_coupon_type pct', 'peg.type_id = pct.coupon_type_id', 'inner' ]
+ ];
+ }
+ $exchange_model = new ExchangeModel();
+
+ $list = $exchange_model->getExchangeGoodsPageList($condition, $page, $page_size, $order_by, $field, $alias, $join);
+
+ return $this->response($list);
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/pointexchange/api/controller/Order.php b/src/addon/pointexchange/api/controller/Order.php
index 6cc4fedd1..6584fbcf7 100644
--- a/src/addon/pointexchange/api/controller/Order.php
+++ b/src/addon/pointexchange/api/controller/Order.php
@@ -1,83 +1,74 @@
-checkToken();
- if ($token['code'] < 0) return $this->response($token);
-
- $order_id = $this->params['order_id'] ?? 0;
- if (empty($order_id)) {
- return $this->response($this->error('', 'REQUEST_ORDER_ID'));
- }
-
- $condition = [
- [ 'order_id', '=', $order_id ],
- [ 'member_id', '=', $this->member_id ],
- [ 'site_id', '=', $this->site_id ],
- ];
- $field = '*';
- $exchange_model = new OrderModel();
-
- $info = $exchange_model->getOrderInfo($condition, $field);
- return $this->response($info);
- }
-
- public function page()
- {
- $token = $this->checkToken();
- if ($token['code'] < 0) return $this->response($token);
-
- $page = $this->params['page'] ?? 1;
- $page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
- $order_status = $this->params['order_status'] ?? 'all';
- $condition = [
- [ 'member_id', '=', $this->member_id ],
- [ 'site_id', '=', $this->site_id ],
- ];
- if ($order_status != 'all') $condition[] = ['order_status', '=', $order_status];
- $order = 'create_time desc';
- $field = '*';
-
- $exchange_model = new OrderModel();
- $list = $exchange_model->getExchangePageList($condition, $page, $page_size, $order, $field);
- return $this->response($list);
- }
-
- /**
- * 关闭订单
- * @return false|string
- */
- public function close(){
- $token = $this->checkToken();
- if ($token['code'] < 0) return $this->response($token);
-
- $order_id = $this->params['order_id'] ?? 0;
-
- $exchange_model = new OrderModel();
- $result = $exchange_model->closeOrder($order_id);
- return $this->response($result);
- }
-
+checkToken();
+ if ($token['code'] < 0) return $this->response($token);
+
+ $order_id = $this->params['order_id'] ?? 0;
+ if (empty($order_id)) {
+ return $this->response($this->error('', 'REQUEST_ORDER_ID'));
+ }
+
+ $condition = [
+ [ 'order_id', '=', $order_id ],
+ [ 'member_id', '=', $this->member_id ],
+ [ 'site_id', '=', $this->site_id ],
+ ];
+ $field = '*';
+ $exchange_model = new OrderModel();
+
+ $info = $exchange_model->getOrderInfo($condition, $field);
+ return $this->response($info);
+ }
+
+ public function page()
+ {
+ $token = $this->checkToken();
+ if ($token['code'] < 0) return $this->response($token);
+
+ $page = $this->params['page'] ?? 1;
+ $page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
+ $order_status = $this->params['order_status'] ?? 'all';
+ $condition = [
+ [ 'member_id', '=', $this->member_id ],
+ [ 'site_id', '=', $this->site_id ],
+ ];
+ if ($order_status != 'all') $condition[] = ['order_status', '=', $order_status];
+ $order = 'create_time desc';
+ $field = '*';
+
+ $exchange_model = new OrderModel();
+ $list = $exchange_model->getExchangePageList($condition, $page, $page_size, $order, $field);
+ return $this->response($list);
+ }
+
+ /**
+ * 关闭订单
+ * @return false|string
+ */
+ public function close(){
+ $token = $this->checkToken();
+ if ($token['code'] < 0) return $this->response($token);
+
+ $order_id = $this->params['order_id'] ?? 0;
+
+ $exchange_model = new OrderModel();
+ $result = $exchange_model->closeOrder($order_id);
+ return $this->response($result);
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/pointexchange/config/info.php b/src/addon/pointexchange/config/info.php
index 0f4944b02..e5e01967c 100644
--- a/src/addon/pointexchange/config/info.php
+++ b/src/addon/pointexchange/config/info.php
@@ -1,20 +1,12 @@
- 'pointexchange',
- 'title' => '积分商城',
- 'description' => '积分购买商品,形成积分营销闭环',
- 'type' => 'tool', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
- 'status' => 1,
- 'author' => '',
- 'version' => '1.0',
- 'version_no' => '100000',
- 'content' => '',
+ 'pointexchange',
+ 'title' => '积分商城',
+ 'description' => '积分购买商品,形成积分营销闭环',
+ 'type' => 'tool', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
+ 'status' => 1,
+ 'author' => '',
+ 'version' => '1.0',
+ 'version_no' => '100000',
+ 'content' => '',
];
\ No newline at end of file
diff --git a/src/addon/pointexchange/event/CouponGetType.php b/src/addon/pointexchange/event/CouponGetType.php
index 48ca6d9d7..1bf585ff1 100644
--- a/src/addon/pointexchange/event/CouponGetType.php
+++ b/src/addon/pointexchange/event/CouponGetType.php
@@ -1,26 +1,17 @@
- '积分兑换'];
- }
+ '积分兑换'];
+ }
}
\ No newline at end of file
diff --git a/src/addon/pointexchange/event/CronExchangeOrderClose.php b/src/addon/pointexchange/event/CronExchangeOrderClose.php
index 5a7e017fb..0037e8f4a 100644
--- a/src/addon/pointexchange/event/CronExchangeOrderClose.php
+++ b/src/addon/pointexchange/event/CronExchangeOrderClose.php
@@ -1,28 +1,20 @@
-closeOrder($data['relate_id']);
- }
-
+closeOrder($data['relate_id']);
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/pointexchange/event/Install.php b/src/addon/pointexchange/event/Install.php
index 3f2254826..657892b4a 100644
--- a/src/addon/pointexchange/event/Install.php
+++ b/src/addon/pointexchange/event/Install.php
@@ -1,26 +1,18 @@
- [
- 'pointexchange' => [
- 'type_name' => '积分兑换',
- 'type_url' => ''
- ]
- ],
-// 'point' => [
-// 'pointexchangerefund' => [
-// 'type_name' => '积分兑换退还',
-// 'type_url' => ''
-// ],
-//
-// ]
- ];
- if($data == ''){
- return $from_type;
- }else{
- return $from_type[$data] ?? [];
- }
-
- }
+ [
+ 'pointexchange' => [
+ 'type_name' => '积分兑换',
+ 'type_url' => ''
+ ]
+ ],
+// 'point' => [
+// 'pointexchangerefund' => [
+// 'type_name' => '积分兑换退还',
+// 'type_url' => ''
+// ],
+//
+// ]
+ ];
+ if($data == ''){
+ return $from_type;
+ }else{
+ return $from_type[$data] ?? [];
+ }
+
+ }
}
\ No newline at end of file
diff --git a/src/addon/pointexchange/event/OrderClose.php b/src/addon/pointexchange/event/OrderClose.php
index afe6c56e4..3899287be 100644
--- a/src/addon/pointexchange/event/OrderClose.php
+++ b/src/addon/pointexchange/event/OrderClose.php
@@ -1,41 +1,33 @@
-getOrderInfo([ [ 'relate_order_id', '=', $param[ 'order_id' ] ] ]);
-
- if ($order_info_result[ 'code' ] < 0 || empty($order_info_result[ 'data' ])) {
- return $order_info_result;
- }
- if (empty($order_info_result[ 'data' ])) {
- $order_info_result[ 'data' ][ 'order_id' ] = $param[ 'order_id' ];
- }
- $res = $order_model->closeOrder($order_info_result[ 'data' ][ 'order_id' ]);
- return $res;
- }
+getOrderInfo([ [ 'relate_order_id', '=', $param[ 'order_id' ] ] ]);
+
+ if ($order_info_result[ 'code' ] < 0 || empty($order_info_result[ 'data' ])) {
+ return $order_info_result;
+ }
+ if (empty($order_info_result[ 'data' ])) {
+ $order_info_result[ 'data' ][ 'order_id' ] = $param[ 'order_id' ];
+ }
+ $res = $order_model->closeOrder($order_info_result[ 'data' ][ 'order_id' ]);
+ return $res;
+ }
}
\ No newline at end of file
diff --git a/src/addon/pointexchange/event/OrderPromotionType.php b/src/addon/pointexchange/event/OrderPromotionType.php
index 7461e09c1..992885d3a 100644
--- a/src/addon/pointexchange/event/OrderPromotionType.php
+++ b/src/addon/pointexchange/event/OrderPromotionType.php
@@ -1,29 +1,20 @@
- "积分兑换", "type" => "pointexchange"];
- }
+ "积分兑换", "type" => "pointexchange"];
+ }
}
\ No newline at end of file
diff --git a/src/addon/pointexchange/event/PointexchangeOrderPayNotify.php b/src/addon/pointexchange/event/PointexchangeOrderPayNotify.php
index 772f068a3..7169c7e50 100644
--- a/src/addon/pointexchange/event/PointexchangeOrderPayNotify.php
+++ b/src/addon/pointexchange/event/PointexchangeOrderPayNotify.php
@@ -1,29 +1,20 @@
-orderPay($data);
- }
-
+orderPay($data);
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/pointexchange/event/ShowPromotion.php b/src/addon/pointexchange/event/ShowPromotion.php
index 6089a6463..b930bd157 100644
--- a/src/addon/pointexchange/event/ShowPromotion.php
+++ b/src/addon/pointexchange/event/ShowPromotion.php
@@ -1,52 +1,44 @@
- [
-
- ],
- 'shop' => [
- [
- //插件名称
- 'name' => 'pointexchange',
- //展示分类(根据平台端设置,admin(平台营销),shop:店铺营销,member:会员营销, tool:应用工具)
- 'show_type' => 'shop',
- //展示主题
- 'title' => '积分商城',
- //展示介绍
- 'description' => '客户积分兑换更多好物',
- //展示图标
- 'icon' => 'addon/pointexchange/icon.png',
- //跳转链接
- 'url' => 'pointexchange://shop/exchange/lists',
- ],
-
- ],
-
- ];
- return $data;
- }
+ [
+
+ ],
+ 'shop' => [
+ [
+ //插件名称
+ 'name' => 'pointexchange',
+ //展示分类(根据平台端设置,admin(平台营销),shop:店铺营销,member:会员营销, tool:应用工具)
+ 'show_type' => 'shop',
+ //展示主题
+ 'title' => '积分商城',
+ //展示介绍
+ 'description' => '客户积分兑换更多好物',
+ //展示图标
+ 'icon' => 'addon/pointexchange/icon.png',
+ //跳转链接
+ 'url' => 'pointexchange://shop/exchange/lists',
+ ],
+
+ ],
+
+ ];
+ return $data;
+ }
}
\ No newline at end of file
diff --git a/src/addon/pointexchange/event/UnInstall.php b/src/addon/pointexchange/event/UnInstall.php
index e23c13679..a45dcc20c 100644
--- a/src/addon/pointexchange/event/UnInstall.php
+++ b/src/addon/pointexchange/event/UnInstall.php
@@ -1,26 +1,18 @@
- [
- 'name' => 'goods',
- 'title' => '兑换商品',
- ],
- 2 => [
- 'name' => 'coupon',
- 'title' => '兑换优惠券',
- ],
- 3 => [
- 'name' => 'balance',
- 'title' => '兑换红包',
- ],
- ];
-
- /**
- * 添加积分兑换
- * @param array $data
- */
- public function addExchange($data)
- {
-
- model('promotion_exchange')->startTrans();
- try {
- $exchange_goods_data = [
- 'site_id' => $data[ 'site_id' ],
- 'type' => $data[ 'type' ],
- 'type_name' => $data[ 'type_name' ],
- 'state' => $data[ 'state' ],
- 'create_time' => time(),
- ];
- if ($data[ 'type' ] == 1) {
- $exchange_goods = $data[ 'goods_data' ];
-
- foreach ($exchange_goods as $k => $v) {
- $exist = model('promotion_exchange_goods')->getInfo([ [ 'type', '=', 1 ], [ 'type_id', '=', $v[ 'goods_id' ] ] ], 'id');
- if (!empty($exist)) {
- return $this->error('', '商品已存在,请不要重复添加');
- }
- $sku_model = new Goods();
- $sku_info = $sku_model->getGoodsSkuInfo([ [ 'sku_id', '=', $v[ 'sku_list' ][ 0 ][ 'sku_id' ] ] ], 'sku_name,sku_image,price,stock,goods_content')[ 'data' ];
- $exchange_goods_data[ 'type_id' ] = $v[ 'goods_id' ];
- $exchange_goods_data[ 'name' ] = $sku_info[ 'sku_name' ];
- $exchange_goods_data[ 'image' ] = $sku_info[ 'sku_image' ];
- $exchange_goods_data[ 'point' ] = $v[ 'sku_list' ][ 0 ][ 'point' ];
- $exchange_goods_data[ 'price' ] = $v[ 'sku_list' ][ 0 ][ 'exchange_price' ];
- $exchange_goods_data[ 'content' ] = $sku_info[ 'goods_content' ];
- $exchange_goods_data[ 'rule' ] = $data[ 'rule' ];
- $exchange_goods_data[ 'pay_type' ] = $v[ 'sku_list' ][ 0 ][ 'exchange_price' ] ? 1 : 0;
- $exchange_goods_id = model('promotion_exchange_goods')->add($exchange_goods_data);
-
- foreach ($v[ 'sku_list' ] as $index => $item) {
- $sku_info = $sku_model->getGoodsSkuInfo([ [ 'sku_id', '=', $item[ 'sku_id' ] ] ], 'sku_name,sku_image,price,stock,goods_content')[ 'data' ];
- $exchange_data = [
- 'site_id' => $data[ 'site_id' ],
- 'exchange_goods_id' => $exchange_goods_id,
- 'type' => $data[ 'type' ],
- 'type_name' => $data[ 'type_name' ],
- 'type_id' => $item[ 'sku_id' ],
- 'state' => $data[ 'state' ],
- 'rule' => $data[ 'rule' ],
- 'name' => $sku_info[ 'sku_name' ],
- 'image' => $sku_info[ 'sku_image' ],
- 'stock' => $sku_info[ 'stock' ],
- 'pay_type' => empty($item[ 'exchange_price' ]) ? 0 : 1,
- 'point' => $item[ 'point' ],
- 'market_price' => $sku_info[ 'price' ],
- 'price' => $item[ 'exchange_price' ],
- 'limit_num' => $item[ 'limit_num' ],
- 'create_time' => time(),
- 'content' => $sku_info[ 'goods_content' ],
-
- 'is_free_shipping' => $data[ 'is_free_shipping' ], //是否免邮(0不免邮 1免邮)
- 'delivery_type' => $data[ 'delivery_type' ] ?? 1, //运费类型( 0 固定运费 1运费模板 2按照商品)
- 'shipping_template' => $data[ 'shipping_template' ], //运费模板
- 'delivery_price' => $data[ 'delivery_price' ] ?? 0 //运费
- ];
- model('promotion_exchange')->add($exchange_data);
-
- }
- }
- } elseif ($data[ 'type' ] == 2) {
- $exist = model('promotion_exchange_goods')->getInfo([ [ 'type', '=', 2 ], [ 'type_id', '=', $data[ 'coupon_type_id' ] ] ], 'id');
- if (!empty($exist)) {
- return $this->error('', '该优惠券已存在,请不要重复添加');
- }
-
- $coupon = new Coupon();
- $coupon_type_info = $coupon->getCouponTypeInfo([ [ 'coupon_type_id', '=', $data[ 'coupon_type_id' ] ] ], 'coupon_type_id,coupon_name,money,count,image,status,type,discount')[ 'data' ];
-
- $exchange_goods_data[ 'type_id' ] = $data[ 'coupon_type_id' ];
- $exchange_goods_data[ 'name' ] = $coupon_type_info[ 'coupon_name' ];
- $exchange_goods_data[ 'image' ] = $coupon_type_info[ 'image' ];
- $exchange_goods_data[ 'point' ] = $data[ 'point' ];
- $exchange_goods_data[ 'content' ] = $data[ 'content' ];
-
- $exchange_goods_id = model('promotion_exchange_goods')->add($exchange_goods_data);
-
- $exchange_data = [
- 'site_id' => $data[ 'site_id' ],
- 'exchange_goods_id' => $exchange_goods_id,
- 'type' => $data[ 'type' ],
- 'type_name' => $data[ 'type_name' ],
- 'state' => $data[ 'state' ],
- 'type_id' => $data[ 'coupon_type_id' ],
- 'name' => $coupon_type_info[ 'coupon_name' ],
- 'image' => $coupon_type_info[ 'image' ],
- 'stock' => $data[ 'stock' ],
- 'pay_type' => 0,
- 'point' => $data[ 'point' ],
- 'create_time' => time(),
- 'content' => $data[ 'content' ],
- ];
- if ($coupon_type_info[ 'type' ] == 'reward') {
- $exchange_data[ 'market_price' ] = $coupon_type_info[ 'money' ];
- } elseif ($coupon_type_info[ 'type' ] == 'discount') {
- $exchange_data[ 'market_price' ] = $coupon_type_info[ 'discount' ];
- }
-
- model('promotion_exchange')->add($exchange_data);
-
- } elseif ($data[ 'type' ] == 3) {
-
- $exchange_goods_data[ 'name' ] = $data[ 'name' ];
- $exchange_goods_data[ 'image' ] = $data[ 'image' ];
- $exchange_goods_data[ 'point' ] = $data[ 'point' ];
- $exchange_goods_data[ 'balance' ] = $data[ 'balance' ];
- $exchange_goods_data[ 'content' ] = $data[ 'content' ];
-
- $exchange_goods_id = model('promotion_exchange_goods')->add($exchange_goods_data);
-
- $exchange_data = [
- 'site_id' => $data[ 'site_id' ],
- 'exchange_goods_id' => $exchange_goods_id,
- 'type' => $data[ 'type' ],
- 'type_name' => $data[ 'type_name' ],
- 'state' => $data[ 'state' ],
- 'name' => $data[ 'name' ],
- 'image' => $data[ 'image' ],
- 'stock' => $data[ 'stock' ],
- 'pay_type' => 0,
- 'point' => $data[ 'point' ],
- 'balance' => $data[ 'balance' ],
- 'create_time' => time(),
- 'content' => $data[ 'content' ],
- ];
-
- model('promotion_exchange')->add($exchange_data);
- }
-
- model('promotion_exchange')->commit();
- return $this->success();
- } catch (\Exception $e) {
- model('promotion_exchange')->rollback();
- return $this->error('', $e->getMessage());
- }
-
- }
-
- /**
- * 编辑积分兑换
- * @param array $data
- */
- public function editExchange($data)
- {
- model('promotion_exchange')->startTrans();
- try {
- $exchange_goods_id = $data[ 'id' ];
- if ($data[ 'type' ] == 1) {
- $goods_data = $data[ 'goods_data' ];
-
- $sku_model = new Goods();
- $sku_info = $sku_model->getGoodsSkuInfo([ [ 'sku_id', '=', $goods_data[ 0 ][ 'sku_id' ] ] ], 'sku_name,sku_image,price,stock,goods_content')[ 'data' ];
- $exchange_goods_data = [
- 'modify_time' => time(),
- 'pay_type' => $goods_data[ 0 ][ 'exchange_price' ] ? 1 : 0,
- ];
- $exchange_goods_data[ 'name' ] = $sku_info[ 'sku_name' ];
- $exchange_goods_data[ 'image' ] = $sku_info[ 'sku_image' ];
- $exchange_goods_data[ 'point' ] = $goods_data[ 0 ][ 'point' ];
- $exchange_goods_data[ 'price' ] = $goods_data[ 0 ][ 'exchange_price' ];
- $exchange_goods_data[ 'content' ] = $sku_info[ 'goods_content' ];
- $exchange_goods_data[ 'rule' ] = $data[ 'rule' ];
- $exchange_goods_data[ 'state' ] = $data[ 'state' ];
- model('promotion_exchange_goods')->update($exchange_goods_data, [ [ 'id', '=', $exchange_goods_id ] ]);
-
- model('promotion_exchange')->delete([ [ 'exchange_goods_id', '=', $exchange_goods_id ] ]);
-
- foreach ($goods_data as $index => $item) {
- $sku_info = $sku_model->getGoodsSkuInfo([ [ 'sku_id', '=', $item[ 'sku_id' ] ] ], 'sku_name,sku_image,price,stock,goods_content')[ 'data' ];
- $exchange_data = [
- 'site_id' => $data[ 'site_id' ],
- 'exchange_goods_id' => $exchange_goods_id,
- 'type' => $data[ 'type' ],
- 'type_name' => $data[ 'type_name' ],
- 'type_id' => $item[ 'sku_id' ],
- 'state' => $data[ 'state' ],
- 'rule' => $data[ 'rule' ],
- 'name' => $sku_info[ 'sku_name' ],
- 'image' => $sku_info[ 'sku_image' ],
- 'stock' => $sku_info[ 'stock' ],
- 'pay_type' => empty($item[ 'exchange_price' ]) ? 0 : 1,
- 'point' => $item[ 'point' ],
- 'market_price' => $sku_info[ 'price' ],
- 'price' => $item[ 'exchange_price' ],
- 'limit_num' => $item[ 'limit_num' ],
- 'create_time' => time(),
- 'content' => $sku_info[ 'goods_content' ],
-
- 'is_free_shipping' => $data[ 'is_free_shipping' ], //是否免邮(0不免邮 1免邮)
- 'delivery_type' => $data[ 'delivery_type' ] ?? 1, //运费类型( 0 固定运费 1运费模板 2按照商品)
- 'shipping_template' => $data[ 'shipping_template' ], //运费模板
- 'delivery_price' => $data[ 'delivery_price' ] ?? 0 //运费
-
- ];
- model('promotion_exchange')->add($exchange_data);
- }
-
- } else if ($data[ 'type' ] == 2) {
- $coupon = new Coupon();
- $coupon_type_info = $coupon->getCouponTypeInfo([ [ 'coupon_type_id', '=', $data[ 'coupon_type_id' ] ] ], 'coupon_type_id,coupon_name,money,count,image,status,type,discount')[ 'data' ];
- $exchange_goods_data = [];
- $exchange_goods_data[ 'type_id' ] = $data[ 'coupon_type_id' ];
- $exchange_goods_data[ 'name' ] = $coupon_type_info[ 'coupon_name' ];
- $exchange_goods_data[ 'image' ] = $coupon_type_info[ 'image' ];
- $exchange_goods_data[ 'point' ] = $data[ 'point' ];
- $exchange_goods_data[ 'content' ] = $data[ 'content' ];
- $exchange_goods_data[ 'state' ] = $data[ 'state' ];
-
- model('promotion_exchange_goods')->update($exchange_goods_data, [ [ 'id', '=', $exchange_goods_id ] ]);
- $exchange_data = [
- 'site_id' => $data[ 'site_id' ],
- 'exchange_goods_id' => $exchange_goods_id,
- 'type' => $data[ 'type' ],
- 'type_name' => $data[ 'type_name' ],
- 'state' => $data[ 'state' ],
- 'type_id' => $data[ 'coupon_type_id' ],
- 'name' => $coupon_type_info[ 'coupon_name' ],
- 'image' => $coupon_type_info[ 'image' ],
- 'stock' => $data[ 'stock' ],
- 'pay_type' => 0,
- 'point' => $data[ 'point' ],
- 'create_time' => time(),
- 'content' => $data[ 'content' ],
- ];
- if ($coupon_type_info[ 'type' ] == 'reward') {
- $exchange_data[ 'market_price' ] = $coupon_type_info[ 'money' ];
- } elseif ($coupon_type_info[ 'type' ] == 'discount') {
- $exchange_data[ 'market_price' ] = $coupon_type_info[ 'discount' ];
- }
- model('promotion_exchange')->delete([ [ 'exchange_goods_id', '=', $exchange_goods_id ] ]);
- model('promotion_exchange')->add($exchange_data);
-
- } else if ($data[ 'type' ] == 3) {
- $exchange_goods_data = [];
- $exchange_goods_data[ 'name' ] = $data[ 'name' ];
- $exchange_goods_data[ 'image' ] = $data[ 'image' ];
- $exchange_goods_data[ 'point' ] = $data[ 'point' ];
- $exchange_goods_data[ 'balance' ] = $data[ 'balance' ];
- $exchange_goods_data[ 'content' ] = $data[ 'content' ];
- $exchange_goods_data[ 'state' ] = $data[ 'state' ];
-
- $exchange_goods_info = model('promotion_exchange_goods')->getInfo([ [ 'id', '=', $exchange_goods_id ] ]);
- if (!empty($exchange_goods_info[ 'image' ]) && !empty($data[ 'image' ]) && $exchange_goods_info[ 'image' ] != $data[ 'image' ]) {
- $upload_model = new Upload();
- $upload_model->deletePic($exchange_goods_info[ 'image' ], $data[ 'site_id' ]);
- }
-
- model('promotion_exchange_goods')->update($exchange_goods_data, [ [ 'id', '=', $exchange_goods_id ] ]);
-
- $exchange_data = [
- 'site_id' => $data[ 'site_id' ],
- 'exchange_goods_id' => $exchange_goods_id,
- 'type' => $data[ 'type' ],
- 'type_name' => $data[ 'type_name' ],
- 'state' => $data[ 'state' ],
- 'name' => $data[ 'name' ],
- 'image' => $data[ 'image' ],
- 'stock' => $data[ 'stock' ],
- 'pay_type' => 0,
- 'point' => $data[ 'point' ],
- 'balance' => $data[ 'balance' ],
- 'create_time' => time(),
- 'content' => $data[ 'content' ],
- ];
- model('promotion_exchange')->delete([ [ 'exchange_goods_id', '=', $exchange_goods_id ] ]);
- model('promotion_exchange')->add($exchange_data);
-
- }
-
- model('promotion_exchange')->commit();
- return $this->success();
- } catch (\Exception $e) {
- model('promotion_exchange')->rollback();
- return $this->error('', $e->getMessage());
- }
-
- }
-
- /**
- * 删除积分兑换
- * @param string $ids
- */
- public function deleteExchange($ids)
- {
- $list = model("promotion_exchange")->getList([ [ 'exchange_goods_id', 'in', $ids ] ]);
- if ($list) {
- foreach ($list as $k => $v) {
- if (!empty($v[ 'image' ])) {
- $upload_model = new Upload();
- $upload_model->deletePic($v[ 'image' ], $v[ 'site_id' ]);
- }
- }
- }
-
- model("promotion_exchange")->delete([ [ 'exchange_goods_id', 'in', $ids ] ]);
- model("promotion_exchange_goods")->delete([ [ 'id', 'in', $ids ] ]);
- return $this->success();
- }
-
- /**
- * 获取积分兑换信息
- * @param int $id
- */
- public function getExchangeInfo($id, $field = '*', $sku_id = 0)
- {
-
- $condition = [
- [ 'exchange_goods_id', '=', $id ]
- ];
- if ($sku_id) $condition[] = [ 'type_id', '=', $sku_id ];
-
- $info = model("promotion_exchange")->getInfo($condition, $field);
- if (!empty($info) && !empty($info[ 'type' ])) {
- switch ( $info[ 'type' ] ) {
- case 1:
- //商品
- $goods = new Goods();
- $goods_sku_info = $goods->getGoodsSkuInfo([ [ 'sku_id', '=', $info[ 'type_id' ], [ 'goods_state', '=', 1 ], [ 'is_delete', '=', 0 ] ] ], 'sku_id,sku_name,stock')[ 'data' ];
- if (!empty($goods_sku_info)) {
- $goods_sku_info[ 'stock' ] = numberFormat($goods_sku_info[ 'stock' ]);
- $info = array_merge($info, $goods_sku_info);
- } else {
- $info = [];
- }
- break;
- case 2:
- //优惠券
- $coupon = new Coupon();
- $coupon_type_info = $coupon->getCouponTypeInfo([ [ 'coupon_type_id', '=', $info[ 'type_id' ] ] ], 'type as coupon_type,discount_limit,count,lead_count')[ 'data' ];
-
- if (!empty($coupon_type_info)) {
- $info = array_merge($info, $coupon_type_info);
- } else {
- $info = [];
- }
- break;
- case 3:
- //余额红包
- break;
- }
- }
- return $this->success($info);
- }
-
- /**
- * 获取积分兑换商品详情
- * @param $id
- * @param $site_id
- * @return array
- */
- public function getExchangeGoodsDetail($id, $site_id)
- {
- $info = model("promotion_exchange_goods")->getInfo([ [ 'id', '=', $id ], [ 'site_id', '=', $site_id ] ], 'id,type,type_name,type_id,name,image,pay_type,point,price,delivery_price,balance,state,content,rule');
- // 兑换类型,1:商品,2:优惠券,3:红包
- switch ( $info[ 'type' ] ) {
- case 1:
- //商品
- $goods_sku = model('goods_sku')->getList([ [ 'goods_id', '=', $info[ 'type_id' ] ], [ 'is_delete', '=', 0 ], [ 'goods_state', '=', 1 ] ], 'stock, price,sku_id,sku_name,discount_price,stock as goods_stock,sku_image,sku_images,goods_id,site_id,goods_content');
- $exchange_list = model("promotion_exchange")->getList([ [ 'exchange_goods_id', '=', $id ], [ 'site_id', '=', $site_id ] ], 'limit_num, id,type,type_name,type_id,name,image,pay_type,point,price,delivery_price,balance,state,content,delivery_type,is_free_shipping,shipping_template,rule');
-
- foreach ($goods_sku as $k => $v) {
- $goods_sku[ $k ][ 'is_select' ] = 0;
- $goods_sku[ $k ][ 'exchange_price' ] = 0;
- $goods_sku[ $k ][ 'point' ] = 0;
- $goods_sku[ $k ][ 'limit_num' ] = 0;
- $goods_sku[ $k ][ 'stock' ] = numberFormat($goods_sku[ $k ][ 'stock' ]);
- $goods_sku[ $k ][ 'goods_stock' ] = numberFormat($goods_sku[ $k ][ 'goods_stock' ]);
- foreach ($exchange_list as $key => $val) {
- if ($val[ 'type_id' ] == $v[ 'sku_id' ]) {
- $goods_sku[ $k ][ 'is_select' ] = 1;
- $goods_sku[ $k ][ 'exchange_price' ] = $val[ 'price' ];
- $goods_sku[ $k ][ 'limit_num' ] = $val[ 'limit_num' ];
- $goods_sku[ $k ][ 'point' ] = $val[ 'point' ];
- }
- }
- }
-
- $info[ 'goods_sku' ] = $goods_sku;
- $info[ 'exchange_goods' ] = $exchange_list;
-
- break;
- case 2:
- //优惠券
- $coupon = new Coupon();
- $coupon_type_info = $coupon->getCouponTypeInfo([ [ 'coupon_type_id', '=', $info[ 'type_id' ] ] ], 'coupon_type_id,coupon_name,money,count as stock,status,lead_count,max_fetch,at_least,end_time,validity_type,fixed_term,goods_type,is_limit,type as coupon_type,discount_limit,discount')[ 'data' ];
- $exchange_info = model("promotion_exchange")->getInfo([ [ 'exchange_goods_id', '=', $id ], [ 'site_id', '=', $site_id ] ], 'market_price,stock');
- if (!empty($coupon_type_info)) {
- $info = array_merge($info, $coupon_type_info);
- } else {
- $info = [];
- }
- $info = array_merge($info, $exchange_info);
-
- break;
- case 3:
- //余额红包
- $exchange_info = model("promotion_exchange")->getInfo([ [ 'exchange_goods_id', '=', $id ], [ 'site_id', '=', $site_id ] ], 'stock');
- if (!empty($exchange_info)) {
- $info = array_merge($info, $exchange_info);
- } else {
- $info = [];
- }
- break;
- }
- if (!empty($info)) {
- return $this->success($info);
- } else {
- return $this->error('', '该兑换物品已失效');
- }
- }
-
- /**
- * 获取积分兑换列表
- * @param array $condition
- * @param string $field
- * @param string $order
- * @param null $limit
- * @param string $alias
- * @param array $join
- * @return array
- */
- public function getExchangeList($condition = [], $field = '*', $order = '', $limit = null, $alias = '', $join = [])
- {
- $list = model('promotion_exchange')->getList($condition, $field, $order, $alias, $join, '', $limit);
- return $this->success($list);
- }
-
- /**
- * 获取积分兑换列表
- * @param array $condition
- * @param int $page
- * @param int $page_size
- * @param string $order
- * @param string $field
- * @param string $alias
- * @param array $join
- * @return array
- */
- public function getExchangePageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'create_time desc', $field = '*', $alias = '', $join = [])
- {
- $list = model('promotion_exchange')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
- return $this->success($list);
- }
-
- /**
- * 获取积分兑换列表
- * @param array $condition
- * @param string $field
- * @param string $order
- * @param null $limit
- * @return array
- */
- public function getExchangeGoodsList($condition = [], $field = '*', $order = '', $limit = null)
- {
- $list = model('promotion_exchange_goods')->getList($condition, $field, $order, '', '', '', $limit);
- return $this->success($list);
- }
-
- /**
- * 获取积分兑换列表
- * @param array $condition
- * @param int $page
- * @param int $page_size
- * @param string $order
- * @param string $field
- * @param string $alias
- * @param array $join
- * @return array
- */
- public function getExchangeGoodsPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'create_time desc', $field = '*', $alias = '', $join = [])
- {
- $list = model('promotion_exchange_goods')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
- if(!empty($list['list']))
- {
- $goods_id_array = [];
- foreach ($list['list'] as $k => $v)
- {
- if($v['type'] == 1)
- {
- $goods_id_array[] = $v['type_id'];
- }
- }
- if(!empty($goods_id_array))
- {
- $goods_array = [];
- $goods_ids = implode(",", $goods_id_array);
- $goods_list = model('goods')->getList([ [ 'goods_id', 'in', $goods_ids ], ['is_delete', '=', 0] ], "goods_id, goods_name, is_delete");
- if(!empty($goods_list))
- {
- $key = array_column($goods_list, 'goods_id');
- $goods_array = array_combine($key, $goods_list);
- }
-
- }
- foreach ($list[ 'list' ] as $k => $v) {
- if ($v[ 'type' ] == 1) {
- $goods_info = $goods_array[$v['type_id']] ?? [];
- if (empty($goods_info)) {
- unset($list[ 'list' ][ $k ]);
- } else {
- if ($goods_info[ 'is_delete' ] == 1) {
- unset($list[ 'list' ][ $k ]);
- } else {
- $list[ 'list' ][ $k ][ 'g_name' ] = $goods_info[ 'goods_name' ];
- }
- }
-
- }
- }
- }
-
- return $this->success($list);
- }
-
- /**
- * 增加库存
- * @param $param
- */
- public function incStock($param)
- {
- $condition = array (
- [ "id", "=", $param[ "id" ] ]
- );
- $num = $param[ "num" ];
- $info = model("promotion_exchange")->getInfo($condition, "stock, name");
- if (empty($info))
- return $this->error(-1, "");
-
- //编辑sku库存
- $result = model("promotion_exchange")->setInc($condition, "stock", $num);
-
- return $this->success($result);
- }
-
- /**
- * 减少库存
- * @param $param
- */
- public function decStock($param)
- {
- $condition = array (
- [ "id", "=", $param[ "id" ] ]
- );
- $num = $param[ "num" ];
-
- $info = model("promotion_exchange")->getInfo($condition, "stock, name, type");
- if (empty($info))
- return $this->error();
-
- if ($info[ 'type' ] == 2 && $info[ 'stock' ] == -1) {
- return $this->success();
- }
-
- if ($info[ "stock" ] < 0) {
- return $this->error('', $info[ "name" ] . "库存不足!");
- }
-
- //编辑sku库存
- $result = model("promotion_exchange")->setDec($condition, "stock", $num);
- if ($result === false)
- return $this->error();
-
- return $this->success($result);
- }
-
- /**
- * 修改标签排序
- * @param $sort
- * @param $id
- * @return array
- */
- public function modifyExchangeSort($sort, $id)
- {
- $res = model('promotion_exchange_goods')->update([ 'sort' => $sort ], [ [ 'id', '=', $id ] ]);
- return $this->success($res);
- }
-
- /**
- * 兑换商品详情
- * @param array $condition
- * @param int $type
- * @return array
- */
- public function getExchangeDetail($condition = [], $type = 1)
- {
- $alias = 'pe';
- $field = 'peg.type,peg.id as exchange_id, pe.id,pe.type_id as sku_id,peg.type_id as goods_id,pe.pay_type,pe.point, pe.price as exchange_price, pe.limit_num,
- pe.delivery_price,pe.balance,pe.state,pe.content,pe.exchange_goods_id,pe.rule';
- $join = [
- [ 'promotion_exchange_goods peg', 'pe.exchange_goods_id = peg.id', 'inner' ]
- ];
- if ($type == 1) {
- $condition[] = [ 'g.goods_state', '=', 1 ];
- $condition[] = [ 'g.is_delete', '=', 0 ];
-
- $field .= ',sku.site_id,sku.sku_name,sku.sku_spec_format,sku.price,sku.promotion_type,sku.stock,sku.click_num,
- (sku.sale_num + sku.virtual_sale) as sale_num,sku.collect_num,sku.sku_image,
- sku.sku_images,sku.site_id,sku.goods_content,sku.goods_state,sku.is_virtual,
- sku.is_free_shipping,sku.goods_spec_format,sku.goods_attr_format,sku.introduction,
- sku.unit,sku.video_url,sku.evaluate,sku.goods_service_ids,g.goods_image,g.goods_stock,g.goods_name,sku.qr_id,g.stock_show,g.sale_show';
-
- $join[] = [ 'goods_sku sku', 'pe.type_id = sku.sku_id', 'inner' ];
- $join[] = [ 'goods g', 'g.goods_id = sku.goods_id', 'inner' ];
- } else if ($type == 2) {
- $join[] = [ 'promotion_coupon_type pct', 'pct.coupon_type_id = peg.type_id', 'inner' ];
- $field .= ',pe.stock,pct.type as coupon_type,pct.discount_limit,pct.image,pct.coupon_name as name,pct.count, pct.lead_count
- ,pct.money, pct.discount, pct.at_least, pct.validity_type,pct.fixed_term,pct.end_time, pct.image';
-// $condition[] = [ 'pct.is_show', '=', 1 ];
-// $condition[] = [ 'pct.is_forbidden', '=', 0 ];
-
- } else if ($type == 3) {
- $field .= ',pe.stock,pe.name,pe.image,pe.balance';
- }
- $info = model('promotion_exchange')->getInfo($condition, $field, $alias, $join);
- if (!empty($info)) {
- if (isset($info[ 'stock' ])) {
- $info[ 'stock' ] = numberFormat($info[ 'stock' ]);
- }
- if (isset($info[ 'sale_num' ])) {
- $info[ 'sale_num' ] = numberFormat($info[ 'sale_num' ]);
- }
- }
- return $this->success($info);
- }
-
- /**
- * 兑换商品详情
- * @param array $condition
- * @param string $field
- * @return array
- */
- public function getExchangeSkuList($condition = [], $type = 1)
- {
- $alias = 'pe';
- $field = 'peg.type,peg.id as exchange_id, pe.id,pe.type_id as sku_id,peg.type_id as goods_id,pe.pay_type,pe.point, pe.price as exchange_price, pe.limit_num,
- pe.delivery_price,pe.balance,pe.state,pe.exchange_goods_id,pe.rule';
- $join = [
- [ 'promotion_exchange_goods peg', 'pe.exchange_goods_id = peg.id', 'inner' ]
- ];
- if ($type == 1) {
- $condition[] = [ 'g.goods_state', '=', 1 ];
- $condition[] = [ 'g.is_delete', '=', 0 ];
-
- $field .= ',sku.sku_name,sku.sku_spec_format,sku.price,sku.stock,sku.sku_image,sku.sku_images,sku.goods_spec_format,g.goods_image';
-
- $join[] = [ 'goods_sku sku', 'pe.type_id = sku.sku_id', 'inner' ];
- $join[] = [ 'goods g', 'g.goods_id = sku.goods_id', 'inner' ];
- } else if ($type == 2) {
- $join[] = [ 'promotion_coupon_type pct', 'pct.coupon_type_id = peg.type_id', 'inner' ];
- $field .= ',pe.stock,pct.type as coupon_type,pct.discount_limit,pct.image,pct.coupon_name as name,pct.count, pct.lead_count
- ,pct.money, pct.discount, pct.at_least, pct.validity_type,pct.fixed_term,pct.end_time, pct.image';
-
- } else if ($type == 3) {
- $field .= ',pe.stock,pe.name,pe.image,pe.balance';
- }
- $list = model('promotion_exchange')->getList($condition, $field, '', $alias, $join);
- foreach ($list as $k => $v) {
- if (isset($v[ 'stock' ])) {
- $list[ $k ][ 'stock' ] = numberFormat($list[ $k ][ 'stock' ]);
- }
- }
- return $this->success($list);
- }
-
- /**
- * 判断规格值是否禁用
- * @param $id
- * @param $site_id
- * @param string $goods_spec_format
- * @return int|mixed
- */
- public function getGoodsSpecFormat($id, $site_id, $goods_spec_format = '')
- {
- //获取活动参与的商品sku_ids
- $sku_ids = model('promotion_exchange')->getColumn([ [ 'exchange_goods_id', '=', $id ], [ 'site_id', '=', $site_id ] ], 'type_id');
- $goods_model = new Goods();
- $res = $goods_model->getGoodsSpecFormat($sku_ids, $goods_spec_format);
- return $res;
- }
-
+ [
+ 'name' => 'goods',
+ 'title' => '兑换商品',
+ ],
+ 2 => [
+ 'name' => 'coupon',
+ 'title' => '兑换优惠券',
+ ],
+ 3 => [
+ 'name' => 'balance',
+ 'title' => '兑换红包',
+ ],
+ ];
+
+ /**
+ * 添加积分兑换
+ * @param array $data
+ */
+ public function addExchange($data)
+ {
+
+ model('promotion_exchange')->startTrans();
+ try {
+ $exchange_goods_data = [
+ 'site_id' => $data[ 'site_id' ],
+ 'type' => $data[ 'type' ],
+ 'type_name' => $data[ 'type_name' ],
+ 'state' => $data[ 'state' ],
+ 'create_time' => time(),
+ ];
+ if ($data[ 'type' ] == 1) {
+ $exchange_goods = $data[ 'goods_data' ];
+
+ foreach ($exchange_goods as $k => $v) {
+ $exist = model('promotion_exchange_goods')->getInfo([ [ 'type', '=', 1 ], [ 'type_id', '=', $v[ 'goods_id' ] ] ], 'id');
+ if (!empty($exist)) {
+ return $this->error('', '商品已存在,请不要重复添加');
+ }
+ $sku_model = new Goods();
+ $sku_info = $sku_model->getGoodsSkuInfo([ [ 'sku_id', '=', $v[ 'sku_list' ][ 0 ][ 'sku_id' ] ] ], 'sku_name,sku_image,price,stock,goods_content')[ 'data' ];
+ $exchange_goods_data[ 'type_id' ] = $v[ 'goods_id' ];
+ $exchange_goods_data[ 'name' ] = $sku_info[ 'sku_name' ];
+ $exchange_goods_data[ 'image' ] = $sku_info[ 'sku_image' ];
+ $exchange_goods_data[ 'point' ] = $v[ 'sku_list' ][ 0 ][ 'point' ];
+ $exchange_goods_data[ 'price' ] = $v[ 'sku_list' ][ 0 ][ 'exchange_price' ];
+ $exchange_goods_data[ 'content' ] = $sku_info[ 'goods_content' ];
+ $exchange_goods_data[ 'rule' ] = $data[ 'rule' ];
+ $exchange_goods_data[ 'pay_type' ] = $v[ 'sku_list' ][ 0 ][ 'exchange_price' ] ? 1 : 0;
+ $exchange_goods_id = model('promotion_exchange_goods')->add($exchange_goods_data);
+
+ foreach ($v[ 'sku_list' ] as $index => $item) {
+ $sku_info = $sku_model->getGoodsSkuInfo([ [ 'sku_id', '=', $item[ 'sku_id' ] ] ], 'sku_name,sku_image,price,stock,goods_content')[ 'data' ];
+ $exchange_data = [
+ 'site_id' => $data[ 'site_id' ],
+ 'exchange_goods_id' => $exchange_goods_id,
+ 'type' => $data[ 'type' ],
+ 'type_name' => $data[ 'type_name' ],
+ 'type_id' => $item[ 'sku_id' ],
+ 'state' => $data[ 'state' ],
+ 'rule' => $data[ 'rule' ],
+ 'name' => $sku_info[ 'sku_name' ],
+ 'image' => $sku_info[ 'sku_image' ],
+ 'stock' => $sku_info[ 'stock' ],
+ 'pay_type' => empty($item[ 'exchange_price' ]) ? 0 : 1,
+ 'point' => $item[ 'point' ],
+ 'market_price' => $sku_info[ 'price' ],
+ 'price' => $item[ 'exchange_price' ],
+ 'limit_num' => $item[ 'limit_num' ],
+ 'create_time' => time(),
+ 'content' => $sku_info[ 'goods_content' ],
+
+ 'is_free_shipping' => $data[ 'is_free_shipping' ], //是否免邮(0不免邮 1免邮)
+ 'delivery_type' => $data[ 'delivery_type' ] ?? 1, //运费类型( 0 固定运费 1运费模板 2按照商品)
+ 'shipping_template' => $data[ 'shipping_template' ], //运费模板
+ 'delivery_price' => $data[ 'delivery_price' ] ?? 0 //运费
+ ];
+ model('promotion_exchange')->add($exchange_data);
+
+ }
+ }
+ } elseif ($data[ 'type' ] == 2) {
+ $exist = model('promotion_exchange_goods')->getInfo([ [ 'type', '=', 2 ], [ 'type_id', '=', $data[ 'coupon_type_id' ] ] ], 'id');
+ if (!empty($exist)) {
+ return $this->error('', '该优惠券已存在,请不要重复添加');
+ }
+
+ $coupon = new Coupon();
+ $coupon_type_info = $coupon->getCouponTypeInfo([ [ 'coupon_type_id', '=', $data[ 'coupon_type_id' ] ] ], 'coupon_type_id,coupon_name,money,count,image,status,type,discount')[ 'data' ];
+
+ $exchange_goods_data[ 'type_id' ] = $data[ 'coupon_type_id' ];
+ $exchange_goods_data[ 'name' ] = $coupon_type_info[ 'coupon_name' ];
+ $exchange_goods_data[ 'image' ] = $coupon_type_info[ 'image' ];
+ $exchange_goods_data[ 'point' ] = $data[ 'point' ];
+ $exchange_goods_data[ 'content' ] = $data[ 'content' ];
+
+ $exchange_goods_id = model('promotion_exchange_goods')->add($exchange_goods_data);
+
+ $exchange_data = [
+ 'site_id' => $data[ 'site_id' ],
+ 'exchange_goods_id' => $exchange_goods_id,
+ 'type' => $data[ 'type' ],
+ 'type_name' => $data[ 'type_name' ],
+ 'state' => $data[ 'state' ],
+ 'type_id' => $data[ 'coupon_type_id' ],
+ 'name' => $coupon_type_info[ 'coupon_name' ],
+ 'image' => $coupon_type_info[ 'image' ],
+ 'stock' => $data[ 'stock' ],
+ 'pay_type' => 0,
+ 'point' => $data[ 'point' ],
+ 'create_time' => time(),
+ 'content' => $data[ 'content' ],
+ ];
+ if ($coupon_type_info[ 'type' ] == 'reward') {
+ $exchange_data[ 'market_price' ] = $coupon_type_info[ 'money' ];
+ } elseif ($coupon_type_info[ 'type' ] == 'discount') {
+ $exchange_data[ 'market_price' ] = $coupon_type_info[ 'discount' ];
+ }
+
+ model('promotion_exchange')->add($exchange_data);
+
+ } elseif ($data[ 'type' ] == 3) {
+
+ $exchange_goods_data[ 'name' ] = $data[ 'name' ];
+ $exchange_goods_data[ 'image' ] = $data[ 'image' ];
+ $exchange_goods_data[ 'point' ] = $data[ 'point' ];
+ $exchange_goods_data[ 'balance' ] = $data[ 'balance' ];
+ $exchange_goods_data[ 'content' ] = $data[ 'content' ];
+
+ $exchange_goods_id = model('promotion_exchange_goods')->add($exchange_goods_data);
+
+ $exchange_data = [
+ 'site_id' => $data[ 'site_id' ],
+ 'exchange_goods_id' => $exchange_goods_id,
+ 'type' => $data[ 'type' ],
+ 'type_name' => $data[ 'type_name' ],
+ 'state' => $data[ 'state' ],
+ 'name' => $data[ 'name' ],
+ 'image' => $data[ 'image' ],
+ 'stock' => $data[ 'stock' ],
+ 'pay_type' => 0,
+ 'point' => $data[ 'point' ],
+ 'balance' => $data[ 'balance' ],
+ 'create_time' => time(),
+ 'content' => $data[ 'content' ],
+ ];
+
+ model('promotion_exchange')->add($exchange_data);
+ }
+
+ model('promotion_exchange')->commit();
+ return $this->success();
+ } catch (\Exception $e) {
+ model('promotion_exchange')->rollback();
+ return $this->error('', $e->getMessage());
+ }
+
+ }
+
+ /**
+ * 编辑积分兑换
+ * @param array $data
+ */
+ public function editExchange($data)
+ {
+ model('promotion_exchange')->startTrans();
+ try {
+ $exchange_goods_id = $data[ 'id' ];
+ if ($data[ 'type' ] == 1) {
+ $goods_data = $data[ 'goods_data' ];
+
+ $sku_model = new Goods();
+ $sku_info = $sku_model->getGoodsSkuInfo([ [ 'sku_id', '=', $goods_data[ 0 ][ 'sku_id' ] ] ], 'sku_name,sku_image,price,stock,goods_content')[ 'data' ];
+ $exchange_goods_data = [
+ 'modify_time' => time(),
+ 'pay_type' => $goods_data[ 0 ][ 'exchange_price' ] ? 1 : 0,
+ ];
+ $exchange_goods_data[ 'name' ] = $sku_info[ 'sku_name' ];
+ $exchange_goods_data[ 'image' ] = $sku_info[ 'sku_image' ];
+ $exchange_goods_data[ 'point' ] = $goods_data[ 0 ][ 'point' ];
+ $exchange_goods_data[ 'price' ] = $goods_data[ 0 ][ 'exchange_price' ];
+ $exchange_goods_data[ 'content' ] = $sku_info[ 'goods_content' ];
+ $exchange_goods_data[ 'rule' ] = $data[ 'rule' ];
+ $exchange_goods_data[ 'state' ] = $data[ 'state' ];
+ model('promotion_exchange_goods')->update($exchange_goods_data, [ [ 'id', '=', $exchange_goods_id ] ]);
+
+ model('promotion_exchange')->delete([ [ 'exchange_goods_id', '=', $exchange_goods_id ] ]);
+
+ foreach ($goods_data as $index => $item) {
+ $sku_info = $sku_model->getGoodsSkuInfo([ [ 'sku_id', '=', $item[ 'sku_id' ] ] ], 'sku_name,sku_image,price,stock,goods_content')[ 'data' ];
+ $exchange_data = [
+ 'site_id' => $data[ 'site_id' ],
+ 'exchange_goods_id' => $exchange_goods_id,
+ 'type' => $data[ 'type' ],
+ 'type_name' => $data[ 'type_name' ],
+ 'type_id' => $item[ 'sku_id' ],
+ 'state' => $data[ 'state' ],
+ 'rule' => $data[ 'rule' ],
+ 'name' => $sku_info[ 'sku_name' ],
+ 'image' => $sku_info[ 'sku_image' ],
+ 'stock' => $sku_info[ 'stock' ],
+ 'pay_type' => empty($item[ 'exchange_price' ]) ? 0 : 1,
+ 'point' => $item[ 'point' ],
+ 'market_price' => $sku_info[ 'price' ],
+ 'price' => $item[ 'exchange_price' ],
+ 'limit_num' => $item[ 'limit_num' ],
+ 'create_time' => time(),
+ 'content' => $sku_info[ 'goods_content' ],
+
+ 'is_free_shipping' => $data[ 'is_free_shipping' ], //是否免邮(0不免邮 1免邮)
+ 'delivery_type' => $data[ 'delivery_type' ] ?? 1, //运费类型( 0 固定运费 1运费模板 2按照商品)
+ 'shipping_template' => $data[ 'shipping_template' ], //运费模板
+ 'delivery_price' => $data[ 'delivery_price' ] ?? 0 //运费
+
+ ];
+ model('promotion_exchange')->add($exchange_data);
+ }
+
+ } else if ($data[ 'type' ] == 2) {
+ $coupon = new Coupon();
+ $coupon_type_info = $coupon->getCouponTypeInfo([ [ 'coupon_type_id', '=', $data[ 'coupon_type_id' ] ] ], 'coupon_type_id,coupon_name,money,count,image,status,type,discount')[ 'data' ];
+ $exchange_goods_data = [];
+ $exchange_goods_data[ 'type_id' ] = $data[ 'coupon_type_id' ];
+ $exchange_goods_data[ 'name' ] = $coupon_type_info[ 'coupon_name' ];
+ $exchange_goods_data[ 'image' ] = $coupon_type_info[ 'image' ];
+ $exchange_goods_data[ 'point' ] = $data[ 'point' ];
+ $exchange_goods_data[ 'content' ] = $data[ 'content' ];
+ $exchange_goods_data[ 'state' ] = $data[ 'state' ];
+
+ model('promotion_exchange_goods')->update($exchange_goods_data, [ [ 'id', '=', $exchange_goods_id ] ]);
+ $exchange_data = [
+ 'site_id' => $data[ 'site_id' ],
+ 'exchange_goods_id' => $exchange_goods_id,
+ 'type' => $data[ 'type' ],
+ 'type_name' => $data[ 'type_name' ],
+ 'state' => $data[ 'state' ],
+ 'type_id' => $data[ 'coupon_type_id' ],
+ 'name' => $coupon_type_info[ 'coupon_name' ],
+ 'image' => $coupon_type_info[ 'image' ],
+ 'stock' => $data[ 'stock' ],
+ 'pay_type' => 0,
+ 'point' => $data[ 'point' ],
+ 'create_time' => time(),
+ 'content' => $data[ 'content' ],
+ ];
+ if ($coupon_type_info[ 'type' ] == 'reward') {
+ $exchange_data[ 'market_price' ] = $coupon_type_info[ 'money' ];
+ } elseif ($coupon_type_info[ 'type' ] == 'discount') {
+ $exchange_data[ 'market_price' ] = $coupon_type_info[ 'discount' ];
+ }
+ model('promotion_exchange')->delete([ [ 'exchange_goods_id', '=', $exchange_goods_id ] ]);
+ model('promotion_exchange')->add($exchange_data);
+
+ } else if ($data[ 'type' ] == 3) {
+ $exchange_goods_data = [];
+ $exchange_goods_data[ 'name' ] = $data[ 'name' ];
+ $exchange_goods_data[ 'image' ] = $data[ 'image' ];
+ $exchange_goods_data[ 'point' ] = $data[ 'point' ];
+ $exchange_goods_data[ 'balance' ] = $data[ 'balance' ];
+ $exchange_goods_data[ 'content' ] = $data[ 'content' ];
+ $exchange_goods_data[ 'state' ] = $data[ 'state' ];
+
+ $exchange_goods_info = model('promotion_exchange_goods')->getInfo([ [ 'id', '=', $exchange_goods_id ] ]);
+ if (!empty($exchange_goods_info[ 'image' ]) && !empty($data[ 'image' ]) && $exchange_goods_info[ 'image' ] != $data[ 'image' ]) {
+ $upload_model = new Upload();
+ $upload_model->deletePic($exchange_goods_info[ 'image' ], $data[ 'site_id' ]);
+ }
+
+ model('promotion_exchange_goods')->update($exchange_goods_data, [ [ 'id', '=', $exchange_goods_id ] ]);
+
+ $exchange_data = [
+ 'site_id' => $data[ 'site_id' ],
+ 'exchange_goods_id' => $exchange_goods_id,
+ 'type' => $data[ 'type' ],
+ 'type_name' => $data[ 'type_name' ],
+ 'state' => $data[ 'state' ],
+ 'name' => $data[ 'name' ],
+ 'image' => $data[ 'image' ],
+ 'stock' => $data[ 'stock' ],
+ 'pay_type' => 0,
+ 'point' => $data[ 'point' ],
+ 'balance' => $data[ 'balance' ],
+ 'create_time' => time(),
+ 'content' => $data[ 'content' ],
+ ];
+ model('promotion_exchange')->delete([ [ 'exchange_goods_id', '=', $exchange_goods_id ] ]);
+ model('promotion_exchange')->add($exchange_data);
+
+ }
+
+ model('promotion_exchange')->commit();
+ return $this->success();
+ } catch (\Exception $e) {
+ model('promotion_exchange')->rollback();
+ return $this->error('', $e->getMessage());
+ }
+
+ }
+
+ /**
+ * 删除积分兑换
+ * @param string $ids
+ */
+ public function deleteExchange($ids)
+ {
+ $list = model("promotion_exchange")->getList([ [ 'exchange_goods_id', 'in', $ids ] ]);
+ if ($list) {
+ foreach ($list as $k => $v) {
+ if (!empty($v[ 'image' ])) {
+ $upload_model = new Upload();
+ $upload_model->deletePic($v[ 'image' ], $v[ 'site_id' ]);
+ }
+ }
+ }
+
+ model("promotion_exchange")->delete([ [ 'exchange_goods_id', 'in', $ids ] ]);
+ model("promotion_exchange_goods")->delete([ [ 'id', 'in', $ids ] ]);
+ return $this->success();
+ }
+
+ /**
+ * 获取积分兑换信息
+ * @param int $id
+ */
+ public function getExchangeInfo($id, $field = '*', $sku_id = 0)
+ {
+
+ $condition = [
+ [ 'exchange_goods_id', '=', $id ]
+ ];
+ if ($sku_id) $condition[] = [ 'type_id', '=', $sku_id ];
+
+ $info = model("promotion_exchange")->getInfo($condition, $field);
+ if (!empty($info) && !empty($info[ 'type' ])) {
+ switch ( $info[ 'type' ] ) {
+ case 1:
+ //商品
+ $goods = new Goods();
+ $goods_sku_info = $goods->getGoodsSkuInfo([ [ 'sku_id', '=', $info[ 'type_id' ], [ 'goods_state', '=', 1 ], [ 'is_delete', '=', 0 ] ] ], 'sku_id,sku_name,stock')[ 'data' ];
+ if (!empty($goods_sku_info)) {
+ $goods_sku_info[ 'stock' ] = numberFormat($goods_sku_info[ 'stock' ]);
+ $info = array_merge($info, $goods_sku_info);
+ } else {
+ $info = [];
+ }
+ break;
+ case 2:
+ //优惠券
+ $coupon = new Coupon();
+ $coupon_type_info = $coupon->getCouponTypeInfo([ [ 'coupon_type_id', '=', $info[ 'type_id' ] ] ], 'type as coupon_type,discount_limit,count,lead_count')[ 'data' ];
+
+ if (!empty($coupon_type_info)) {
+ $info = array_merge($info, $coupon_type_info);
+ } else {
+ $info = [];
+ }
+ break;
+ case 3:
+ //余额红包
+ break;
+ }
+ }
+ return $this->success($info);
+ }
+
+ /**
+ * 获取积分兑换商品详情
+ * @param $id
+ * @param $site_id
+ * @return array
+ */
+ public function getExchangeGoodsDetail($id, $site_id)
+ {
+ $info = model("promotion_exchange_goods")->getInfo([ [ 'id', '=', $id ], [ 'site_id', '=', $site_id ] ], 'id,type,type_name,type_id,name,image,pay_type,point,price,delivery_price,balance,state,content,rule');
+ // 兑换类型,1:商品,2:优惠券,3:红包
+ switch ( $info[ 'type' ] ) {
+ case 1:
+ //商品
+ $goods_sku = model('goods_sku')->getList([ [ 'goods_id', '=', $info[ 'type_id' ] ], [ 'is_delete', '=', 0 ], [ 'goods_state', '=', 1 ] ], 'stock, price,sku_id,sku_name,discount_price,stock as goods_stock,sku_image,sku_images,goods_id,site_id,goods_content');
+ $exchange_list = model("promotion_exchange")->getList([ [ 'exchange_goods_id', '=', $id ], [ 'site_id', '=', $site_id ] ], 'limit_num, id,type,type_name,type_id,name,image,pay_type,point,price,delivery_price,balance,state,content,delivery_type,is_free_shipping,shipping_template,rule');
+
+ foreach ($goods_sku as $k => $v) {
+ $goods_sku[ $k ][ 'is_select' ] = 0;
+ $goods_sku[ $k ][ 'exchange_price' ] = 0;
+ $goods_sku[ $k ][ 'point' ] = 0;
+ $goods_sku[ $k ][ 'limit_num' ] = 0;
+ $goods_sku[ $k ][ 'stock' ] = numberFormat($goods_sku[ $k ][ 'stock' ]);
+ $goods_sku[ $k ][ 'goods_stock' ] = numberFormat($goods_sku[ $k ][ 'goods_stock' ]);
+ foreach ($exchange_list as $key => $val) {
+ if ($val[ 'type_id' ] == $v[ 'sku_id' ]) {
+ $goods_sku[ $k ][ 'is_select' ] = 1;
+ $goods_sku[ $k ][ 'exchange_price' ] = $val[ 'price' ];
+ $goods_sku[ $k ][ 'limit_num' ] = $val[ 'limit_num' ];
+ $goods_sku[ $k ][ 'point' ] = $val[ 'point' ];
+ }
+ }
+ }
+
+ $info[ 'goods_sku' ] = $goods_sku;
+ $info[ 'exchange_goods' ] = $exchange_list;
+
+ break;
+ case 2:
+ //优惠券
+ $coupon = new Coupon();
+ $coupon_type_info = $coupon->getCouponTypeInfo([ [ 'coupon_type_id', '=', $info[ 'type_id' ] ] ], 'coupon_type_id,coupon_name,money,count as stock,status,lead_count,max_fetch,at_least,end_time,validity_type,fixed_term,goods_type,is_limit,type as coupon_type,discount_limit,discount')[ 'data' ];
+ $exchange_info = model("promotion_exchange")->getInfo([ [ 'exchange_goods_id', '=', $id ], [ 'site_id', '=', $site_id ] ], 'market_price,stock');
+ if (!empty($coupon_type_info)) {
+ $info = array_merge($info, $coupon_type_info);
+ } else {
+ $info = [];
+ }
+ $info = array_merge($info, $exchange_info);
+
+ break;
+ case 3:
+ //余额红包
+ $exchange_info = model("promotion_exchange")->getInfo([ [ 'exchange_goods_id', '=', $id ], [ 'site_id', '=', $site_id ] ], 'stock');
+ if (!empty($exchange_info)) {
+ $info = array_merge($info, $exchange_info);
+ } else {
+ $info = [];
+ }
+ break;
+ }
+ if (!empty($info)) {
+ return $this->success($info);
+ } else {
+ return $this->error('', '该兑换物品已失效');
+ }
+ }
+
+ /**
+ * 获取积分兑换列表
+ * @param array $condition
+ * @param string $field
+ * @param string $order
+ * @param null $limit
+ * @param string $alias
+ * @param array $join
+ * @return array
+ */
+ public function getExchangeList($condition = [], $field = '*', $order = '', $limit = null, $alias = '', $join = [])
+ {
+ $list = model('promotion_exchange')->getList($condition, $field, $order, $alias, $join, '', $limit);
+ return $this->success($list);
+ }
+
+ /**
+ * 获取积分兑换列表
+ * @param array $condition
+ * @param int $page
+ * @param int $page_size
+ * @param string $order
+ * @param string $field
+ * @param string $alias
+ * @param array $join
+ * @return array
+ */
+ public function getExchangePageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'create_time desc', $field = '*', $alias = '', $join = [])
+ {
+ $list = model('promotion_exchange')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
+ return $this->success($list);
+ }
+
+ /**
+ * 获取积分兑换列表
+ * @param array $condition
+ * @param string $field
+ * @param string $order
+ * @param null $limit
+ * @return array
+ */
+ public function getExchangeGoodsList($condition = [], $field = '*', $order = '', $limit = null)
+ {
+ $list = model('promotion_exchange_goods')->getList($condition, $field, $order, '', '', '', $limit);
+ return $this->success($list);
+ }
+
+ /**
+ * 获取积分兑换列表
+ * @param array $condition
+ * @param int $page
+ * @param int $page_size
+ * @param string $order
+ * @param string $field
+ * @param string $alias
+ * @param array $join
+ * @return array
+ */
+ public function getExchangeGoodsPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'create_time desc', $field = '*', $alias = '', $join = [])
+ {
+ $list = model('promotion_exchange_goods')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
+ if(!empty($list['list']))
+ {
+ $goods_id_array = [];
+ foreach ($list['list'] as $k => $v)
+ {
+ if($v['type'] == 1)
+ {
+ $goods_id_array[] = $v['type_id'];
+ }
+ }
+ if(!empty($goods_id_array))
+ {
+ $goods_array = [];
+ $goods_ids = implode(",", $goods_id_array);
+ $goods_list = model('goods')->getList([ [ 'goods_id', 'in', $goods_ids ], ['is_delete', '=', 0] ], "goods_id, goods_name, is_delete");
+ if(!empty($goods_list))
+ {
+ $key = array_column($goods_list, 'goods_id');
+ $goods_array = array_combine($key, $goods_list);
+ }
+
+ }
+ foreach ($list[ 'list' ] as $k => $v) {
+ if ($v[ 'type' ] == 1) {
+ $goods_info = $goods_array[$v['type_id']] ?? [];
+ if (empty($goods_info)) {
+ unset($list[ 'list' ][ $k ]);
+ } else {
+ if ($goods_info[ 'is_delete' ] == 1) {
+ unset($list[ 'list' ][ $k ]);
+ } else {
+ $list[ 'list' ][ $k ][ 'g_name' ] = $goods_info[ 'goods_name' ];
+ }
+ }
+
+ }
+ }
+ }
+
+ return $this->success($list);
+ }
+
+ /**
+ * 增加库存
+ * @param $param
+ */
+ public function incStock($param)
+ {
+ $condition = array (
+ [ "id", "=", $param[ "id" ] ]
+ );
+ $num = $param[ "num" ];
+ $info = model("promotion_exchange")->getInfo($condition, "stock, name");
+ if (empty($info))
+ return $this->error(-1, "");
+
+ //编辑sku库存
+ $result = model("promotion_exchange")->setInc($condition, "stock", $num);
+
+ return $this->success($result);
+ }
+
+ /**
+ * 减少库存
+ * @param $param
+ */
+ public function decStock($param)
+ {
+ $condition = array (
+ [ "id", "=", $param[ "id" ] ]
+ );
+ $num = $param[ "num" ];
+
+ $info = model("promotion_exchange")->getInfo($condition, "stock, name, type");
+ if (empty($info))
+ return $this->error();
+
+ if ($info[ 'type' ] == 2 && $info[ 'stock' ] == -1) {
+ return $this->success();
+ }
+
+ if ($info[ "stock" ] < 0) {
+ return $this->error('', $info[ "name" ] . "库存不足!");
+ }
+
+ //编辑sku库存
+ $result = model("promotion_exchange")->setDec($condition, "stock", $num);
+ if ($result === false)
+ return $this->error();
+
+ return $this->success($result);
+ }
+
+ /**
+ * 修改标签排序
+ * @param $sort
+ * @param $id
+ * @return array
+ */
+ public function modifyExchangeSort($sort, $id)
+ {
+ $res = model('promotion_exchange_goods')->update([ 'sort' => $sort ], [ [ 'id', '=', $id ] ]);
+ return $this->success($res);
+ }
+
+ /**
+ * 兑换商品详情
+ * @param array $condition
+ * @param int $type
+ * @return array
+ */
+ public function getExchangeDetail($condition = [], $type = 1)
+ {
+ $alias = 'pe';
+ $field = 'peg.type,peg.id as exchange_id, pe.id,pe.type_id as sku_id,peg.type_id as goods_id,pe.pay_type,pe.point, pe.price as exchange_price, pe.limit_num,
+ pe.delivery_price,pe.balance,pe.state,pe.content,pe.exchange_goods_id,pe.rule';
+ $join = [
+ [ 'promotion_exchange_goods peg', 'pe.exchange_goods_id = peg.id', 'inner' ]
+ ];
+ if ($type == 1) {
+ $condition[] = [ 'g.goods_state', '=', 1 ];
+ $condition[] = [ 'g.is_delete', '=', 0 ];
+
+ $field .= ',sku.site_id,sku.sku_name,sku.sku_spec_format,sku.price,sku.promotion_type,sku.stock,sku.click_num,
+ (sku.sale_num + sku.virtual_sale) as sale_num,sku.collect_num,sku.sku_image,
+ sku.sku_images,sku.site_id,sku.goods_content,sku.goods_state,sku.is_virtual,
+ sku.is_free_shipping,sku.goods_spec_format,sku.goods_attr_format,sku.introduction,
+ sku.unit,sku.video_url,sku.evaluate,sku.goods_service_ids,g.goods_image,g.goods_stock,g.goods_name,sku.qr_id,g.stock_show,g.sale_show';
+
+ $join[] = [ 'goods_sku sku', 'pe.type_id = sku.sku_id', 'inner' ];
+ $join[] = [ 'goods g', 'g.goods_id = sku.goods_id', 'inner' ];
+ } else if ($type == 2) {
+ $join[] = [ 'promotion_coupon_type pct', 'pct.coupon_type_id = peg.type_id', 'inner' ];
+ $field .= ',pe.stock,pct.type as coupon_type,pct.discount_limit,pct.image,pct.coupon_name as name,pct.count, pct.lead_count
+ ,pct.money, pct.discount, pct.at_least, pct.validity_type,pct.fixed_term,pct.end_time, pct.image';
+// $condition[] = [ 'pct.is_show', '=', 1 ];
+// $condition[] = [ 'pct.is_forbidden', '=', 0 ];
+
+ } else if ($type == 3) {
+ $field .= ',pe.stock,pe.name,pe.image,pe.balance';
+ }
+ $info = model('promotion_exchange')->getInfo($condition, $field, $alias, $join);
+ if (!empty($info)) {
+ if (isset($info[ 'stock' ])) {
+ $info[ 'stock' ] = numberFormat($info[ 'stock' ]);
+ }
+ if (isset($info[ 'sale_num' ])) {
+ $info[ 'sale_num' ] = numberFormat($info[ 'sale_num' ]);
+ }
+ }
+ return $this->success($info);
+ }
+
+ /**
+ * 兑换商品详情
+ * @param array $condition
+ * @param string $field
+ * @return array
+ */
+ public function getExchangeSkuList($condition = [], $type = 1)
+ {
+ $alias = 'pe';
+ $field = 'peg.type,peg.id as exchange_id, pe.id,pe.type_id as sku_id,peg.type_id as goods_id,pe.pay_type,pe.point, pe.price as exchange_price, pe.limit_num,
+ pe.delivery_price,pe.balance,pe.state,pe.exchange_goods_id,pe.rule';
+ $join = [
+ [ 'promotion_exchange_goods peg', 'pe.exchange_goods_id = peg.id', 'inner' ]
+ ];
+ if ($type == 1) {
+ $condition[] = [ 'g.goods_state', '=', 1 ];
+ $condition[] = [ 'g.is_delete', '=', 0 ];
+
+ $field .= ',sku.sku_name,sku.sku_spec_format,sku.price,sku.stock,sku.sku_image,sku.sku_images,sku.goods_spec_format,g.goods_image';
+
+ $join[] = [ 'goods_sku sku', 'pe.type_id = sku.sku_id', 'inner' ];
+ $join[] = [ 'goods g', 'g.goods_id = sku.goods_id', 'inner' ];
+ } else if ($type == 2) {
+ $join[] = [ 'promotion_coupon_type pct', 'pct.coupon_type_id = peg.type_id', 'inner' ];
+ $field .= ',pe.stock,pct.type as coupon_type,pct.discount_limit,pct.image,pct.coupon_name as name,pct.count, pct.lead_count
+ ,pct.money, pct.discount, pct.at_least, pct.validity_type,pct.fixed_term,pct.end_time, pct.image';
+
+ } else if ($type == 3) {
+ $field .= ',pe.stock,pe.name,pe.image,pe.balance';
+ }
+ $list = model('promotion_exchange')->getList($condition, $field, '', $alias, $join);
+ foreach ($list as $k => $v) {
+ if (isset($v[ 'stock' ])) {
+ $list[ $k ][ 'stock' ] = numberFormat($list[ $k ][ 'stock' ]);
+ }
+ }
+ return $this->success($list);
+ }
+
+ /**
+ * 判断规格值是否禁用
+ * @param $id
+ * @param $site_id
+ * @param string $goods_spec_format
+ * @return int|mixed
+ */
+ public function getGoodsSpecFormat($id, $site_id, $goods_spec_format = '')
+ {
+ //获取活动参与的商品sku_ids
+ $sku_ids = model('promotion_exchange')->getColumn([ [ 'exchange_goods_id', '=', $id ], [ 'site_id', '=', $site_id ] ], 'type_id');
+ $goods_model = new Goods();
+ $res = $goods_model->getGoodsSpecFormat($sku_ids, $goods_spec_format);
+ return $res;
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/pointexchange/model/share/WchatShare.php b/src/addon/pointexchange/model/share/WchatShare.php
index 12e6c8cb9..512831ae4 100644
--- a/src/addon/pointexchange/model/share/WchatShare.php
+++ b/src/addon/pointexchange/model/share/WchatShare.php
@@ -1,155 +1,146 @@
- '积分商城',
- 'config_key' => 'WCHAT_SHARE_CONFIG_POINTEXCHANGE_LIST',
- 'path' => [ '/pages_promotion/point/list' ],
- 'method_prefix' => 'goodsList',
- ],
- [
- 'title' => '积分商品',
- 'config_key' => 'WCHAT_SHARE_CONFIG_POINTEXCHANGE_DETAIL',
- 'path' => [ '/pages_promotion/point/detail' ],
- 'method_prefix' => 'goodsDetail',
- ],
- ];
-
- protected $sort = 6;
-
- /**
- * 积分商城列表
- * @param $param
- * @return array
- */
- protected function goodsListShareData($param)
- {
- //跳转路径
- $link = $this->getShareLink($param);
- $config_data = $this->goodsListShareConfig($param)[ 'value' ];
-
- $data = [
- 'link' => $link,
- 'desc' => $config_data[ 'desc' ],
- 'imgUrl' => $config_data[ 'imgUrl' ],
- 'title' => $config_data[ 'title' ]
- ];
- return [
- 'permission' => [
- 'hideOptionMenu' => false,
- 'hideMenuItems' => [],
- ],
- 'data' => $data,//分享内容
- ];
- }
-
- /**
- * 积分商城列表分享配置
- * @param $param
- * @return array
- */
- public function goodsListShareConfig($param)
- {
- $site_id = $param[ 'site_id' ];
- $config = $param[ 'config' ];
-
- $config_model = new ConfigModel();
- $data = $config_model->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', $config[ 'config_key' ] ] ])[ 'data' ];
- if (empty($data[ 'value' ])) {
- $data[ 'value' ] = [
- 'title' => "积分商城",
- 'desc' => "积分兑换更优惠哦",
- 'imgUrl' => ''
- ];
- }
- if (empty($data[ 'value' ][ 'imgUrl' ])) {
- $data[ 'value' ][ 'imgUrl' ] = img('addon/pointexchange/icon.png');
- }
- return [
- 'value' => $data[ 'value' ],
- ];
- }
-
- /**
- * 积分商城详情
- * @param $param
- * @return array
- */
- protected function goodsDetailShareData($param)
- {
- $site_id = $param[ 'site_id' ] ?? 0;
- parse_str(parse_url($param[ 'url' ])[ 'query' ] ?? '', $query);
-
- if (isset($query[ 'id' ])) {
- $id = $query[ 'id' ];
- $exchange_model = new ExchangeModel();
- $exchange_info = $exchange_model->getExchangeInfo($id, 'type, type_id');
- $exchange_info = $exchange_info[ 'data' ];
- $condition = [
- [ 'peg.id', '=', $id ],
- [ 'peg.site_id', '=', $site_id ],
- [ 'peg.state', '=', 1 ],
- ];
- $exchange_detail = $exchange_model->getExchangeDetail($condition, $exchange_info[ 'type' ])[ 'data' ];
- if (!empty($exchange_detail)) {
- $image_url = '';
- $title = '';
- switch ( $exchange_detail[ 'type' ] ) {
- case 1://商品
- $title = $exchange_detail[ 'sku_name' ];
- $image_url = $exchange_detail[ 'sku_image' ];
- break;
- case 2://优惠券
- case 3://红包
- $title = $exchange_detail[ 'name' ];
- $image_url = $exchange_detail[ 'image' ];
- break;
- }
- if ($image_url) {
- $image_url = img($image_url);
- } else {
- $image_url = $this->getDefaultShareIcon();
- }
- $exchange_condition = [];
- if ($exchange_detail[ 'point' ] > 0) $exchange_condition[] = "{$exchange_detail['point']}积分";
- if ($exchange_detail[ 'exchange_price' ] > 0) $exchange_condition[] = "¥{$exchange_detail['exchange_price']}";
- $desc = "仅需" . join("+", $exchange_condition) . "即可兑换";
- $link = $this->getShareLink($param);
-
- $data = [
- 'title' => $title,
- 'desc' => $desc,
- 'link' => $link,
- 'imgUrl' => $image_url,
- ];
- return [
- 'permission' => [
- 'hideOptionMenu' => false,
- 'hideMenuItems' => [],
- ],
- 'data' => $data,//分享内容
- ];
- }
- }
- }
-}
+ '积分商城',
+ 'config_key' => 'WCHAT_SHARE_CONFIG_POINTEXCHANGE_LIST',
+ 'path' => [ '/pages_promotion/point/list' ],
+ 'method_prefix' => 'goodsList',
+ ],
+ [
+ 'title' => '积分商品',
+ 'config_key' => 'WCHAT_SHARE_CONFIG_POINTEXCHANGE_DETAIL',
+ 'path' => [ '/pages_promotion/point/detail' ],
+ 'method_prefix' => 'goodsDetail',
+ ],
+ ];
+
+ protected $sort = 6;
+
+ /**
+ * 积分商城列表
+ * @param $param
+ * @return array
+ */
+ protected function goodsListShareData($param)
+ {
+ //跳转路径
+ $link = $this->getShareLink($param);
+ $config_data = $this->goodsListShareConfig($param)[ 'value' ];
+
+ $data = [
+ 'link' => $link,
+ 'desc' => $config_data[ 'desc' ],
+ 'imgUrl' => $config_data[ 'imgUrl' ],
+ 'title' => $config_data[ 'title' ]
+ ];
+ return [
+ 'permission' => [
+ 'hideOptionMenu' => false,
+ 'hideMenuItems' => [],
+ ],
+ 'data' => $data,//分享内容
+ ];
+ }
+
+ /**
+ * 积分商城列表分享配置
+ * @param $param
+ * @return array
+ */
+ public function goodsListShareConfig($param)
+ {
+ $site_id = $param[ 'site_id' ];
+ $config = $param[ 'config' ];
+
+ $config_model = new ConfigModel();
+ $data = $config_model->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', $config[ 'config_key' ] ] ])[ 'data' ];
+ if (empty($data[ 'value' ])) {
+ $data[ 'value' ] = [
+ 'title' => "积分商城",
+ 'desc' => "积分兑换更优惠哦",
+ 'imgUrl' => ''
+ ];
+ }
+ if (empty($data[ 'value' ][ 'imgUrl' ])) {
+ $data[ 'value' ][ 'imgUrl' ] = img('addon/pointexchange/icon.png');
+ }
+ return [
+ 'value' => $data[ 'value' ],
+ ];
+ }
+
+ /**
+ * 积分商城详情
+ * @param $param
+ * @return array
+ */
+ protected function goodsDetailShareData($param)
+ {
+ $site_id = $param[ 'site_id' ] ?? 0;
+ parse_str(parse_url($param[ 'url' ])[ 'query' ] ?? '', $query);
+
+ if (isset($query[ 'id' ])) {
+ $id = $query[ 'id' ];
+ $exchange_model = new ExchangeModel();
+ $exchange_info = $exchange_model->getExchangeInfo($id, 'type, type_id');
+ $exchange_info = $exchange_info[ 'data' ];
+ $condition = [
+ [ 'peg.id', '=', $id ],
+ [ 'peg.site_id', '=', $site_id ],
+ [ 'peg.state', '=', 1 ],
+ ];
+ $exchange_detail = $exchange_model->getExchangeDetail($condition, $exchange_info[ 'type' ])[ 'data' ];
+ if (!empty($exchange_detail)) {
+ $image_url = '';
+ $title = '';
+ switch ( $exchange_detail[ 'type' ] ) {
+ case 1://商品
+ $title = $exchange_detail[ 'sku_name' ];
+ $image_url = $exchange_detail[ 'sku_image' ];
+ break;
+ case 2://优惠券
+ case 3://红包
+ $title = $exchange_detail[ 'name' ];
+ $image_url = $exchange_detail[ 'image' ];
+ break;
+ }
+ if ($image_url) {
+ $image_url = img($image_url);
+ } else {
+ $image_url = $this->getDefaultShareIcon();
+ }
+ $exchange_condition = [];
+ if ($exchange_detail[ 'point' ] > 0) $exchange_condition[] = "{$exchange_detail['point']}积分";
+ if ($exchange_detail[ 'exchange_price' ] > 0) $exchange_condition[] = "¥{$exchange_detail['exchange_price']}";
+ $desc = "仅需" . join("+", $exchange_condition) . "即可兑换";
+ $link = $this->getShareLink($param);
+
+ $data = [
+ 'title' => $title,
+ 'desc' => $desc,
+ 'link' => $link,
+ 'imgUrl' => $image_url,
+ ];
+ return [
+ 'permission' => [
+ 'hideOptionMenu' => false,
+ 'hideMenuItems' => [],
+ ],
+ 'data' => $data,//分享内容
+ ];
+ }
+ }
+ }
+}
diff --git a/src/addon/pointexchange/shop/controller/Exchange.php b/src/addon/pointexchange/shop/controller/Exchange.php
index 1b19a1d58..ddad2d55f 100644
--- a/src/addon/pointexchange/shop/controller/Exchange.php
+++ b/src/addon/pointexchange/shop/controller/Exchange.php
@@ -1,302 +1,294 @@
-isJson()) {
- $page = input('page', 1);
- $page_size = input('page_size', PAGE_LIST_ROWS);
- $search_text = input('search_text', '');
- $type = input('type', '');
- $state = input('state', '');
- $sort = input('sort', 'asc');
- $condition[] = [ 'peg.site_id', '=', $this->site_id ];
- if ($search_text) {
- $condition[] = [ 'peg.name', 'like', '%' . $search_text . '%' ];
- }
- if ($type) {
- $condition[] = [ 'peg.type', '=', $type ];
- }
- if ($state != '') {
- $condition[] = [ 'peg.state', '=', $state ];
- }
-
- $field = 'peg.*';
- $alias = 'peg';
- $join = [];
-
- //排序
- $order = input('order', 'create_time');
- $sort = input('sort', 'desc');
- if ($order == 'sort') {
- $order_by = 'peg.' . $order . ' ' . $sort;
- } else {
- $order_by = 'peg.' . $order . ' ' . $sort . ',peg.sort desc';
- }
-
- $exchange_model = new ExchangeModel();
- //兑换名称 兑换图片 兑换库存 兑换价格
- $lists = $exchange_model->getExchangeGoodsPageList($condition, $page, $page_size, $order_by, $field, $alias, $join);
- return $lists;
- }
-
- return $this->fetch("exchange/lists");
- }
-
- /**
- * 添加积分兑换
- */
- public function add()
- {
- if (request()->isJson()) {
- $type = input('type', '1');//兑换类型 1 商品 2 优惠券 3 红包
-
- $data = [
- 'site_id' => $this->site_id,
- 'type' => $type,//兑换类型 1 商品 2 优惠券 3 红包
- 'point' => input('point', ''),//积分
- 'state' => input('state', ''),
- 'is_free_shipping' => input('is_free_shipping', ''),
- 'delivery_type' => input('delivery_type', ''),
- 'delivery_price' => input('delivery_price', ''),
- 'shipping_template' => input('shipping_template', ''),
- ];
- if ($type == 1) {
- $data[ 'goods_data' ] = input('goods_data', '');
- $data[ 'rule' ] = input('content', '');
- $data[ 'type_name' ] = '商品';
- } elseif ($type == 2) {
- $data[ 'coupon_type_id' ] = input('coupon_type_id', '0');//优惠券id
- $data[ 'content' ] = input('content', '');
- $data[ 'type_name' ] = '优惠券';
- $data[ 'stock' ] = input('stock', '');
- } elseif ($type == 3) {
- $data[ 'name' ] = input('name', '');
- $data[ 'image' ] = input('image', '');
- $data[ 'stock' ] = input('stock', '');
- $data[ 'balance' ] = input('balance', '0');
- $data[ 'content' ] = input('content', '');
- $data[ 'type_name' ] = '红包';
- } else {
- return error(-1, '');
- }
- $exchange_model = new ExchangeModel();
- $res = $exchange_model->addExchange($data);
- return $res;
- } else {
- //获取运费模板
- $express_template_model = new ExpressTemplateModel();
- $express_template_list = $express_template_model->getExpressTemplateList([ [ 'site_id', "=", $this->site_id ] ], 'template_id,template_name', 'is_default desc');
- $express_template_list = $express_template_list[ 'data' ];
- $this->assign("express_template_list", $express_template_list);
-
- return $this->fetch("exchange/add");
- }
- }
-
- /**
- * 编辑积分兑换
- */
- public function edit()
- {
- $id = input("id", 0);
- $exchange_model = new ExchangeModel();
- if (request()->isJson()) {
- $type = input('type', '1');//兑换类型 1 商品 2 优惠券 3 红包
- $data = [
- 'site_id' => $this->site_id,
- 'type' => $type,//兑换类型 1 商品 2 优惠券 3 红包
- 'point' => input('point', ''),//积分
- 'state' => input('state', ''),
- 'id' => $id,
- 'is_free_shipping' => input('is_free_shipping', ''),
- 'delivery_type' => input('delivery_type', ''),
- 'delivery_price' => input('delivery_price', ''),
- 'shipping_template' => input('shipping_template', ''),
- ];
- if ($type == 1) {
- $data[ 'goods_data' ] = input('goods_data', '');
- $data[ 'rule' ] = input('content', '');
- $data[ 'type_name' ] = '商品';
-
- } elseif ($type == 2) {
- $data[ 'coupon_type_id' ] = input('coupon_type_id', '0');//优惠券id
- $data[ 'content' ] = input('content', '');
- $data[ 'type_name' ] = '优惠券';
- $data[ 'stock' ] = input('stock', '');
- } elseif ($type == 3) {
- $data[ 'name' ] = input('name', '');
- $data[ 'image' ] = input('image', '');
- $data[ 'stock' ] = input('stock', '');
- $data[ 'balance' ] = input('balance', '0');
- $data[ 'content' ] = input('content', '');
- $data[ 'type_name' ] = '红包';
- } else {
- return error(-1, '');
- }
-
- $res = $exchange_model->editExchange($data);
- return $res;
- } else {
- $exchange_info = $exchange_model->getExchangeGoodsDetail($id, $this->site_id);
- if (empty($exchange_info[ 'data' ][ 'id' ])) {
- $this->error('对应的积分兑换活动商品/优惠券已经不存在了!');
- }
- $this->assign("exchange_info", $exchange_info[ 'data' ]);
-
- //获取运费模板
- $express_template_model = new ExpressTemplateModel();
- $express_template_list = $express_template_model->getExpressTemplateList([ [ 'site_id', "=", $this->site_id ] ], 'template_id,template_name', 'is_default desc');
- $express_template_list = $express_template_list[ 'data' ];
- $this->assign("express_template_list", $express_template_list);
-
- return $this->fetch("exchange/edit");
- }
- }
-
- /**
- *关闭积分兑换
- */
- public function delete()
- {
- $id = input("id", 0);
- $exchange_model = new ExchangeModel();
- $res = $exchange_model->deleteExchange($id);
- return $res;
-
- }
-
- /**
- * 修改排序
- */
- public function modifySort()
- {
- $sort = input('sort', 0);
- $id = input('id', 0);
- $exchange_model = new ExchangeModel();
- return $exchange_model->modifyExchangeSort($sort, $id);
- }
-
-
- /**
- * 获取商品列表
- * @return array
- */
- public function getSkuList()
- {
- if (request()->isJson()) {
- $exchange_model = new ExchangeModel();
-
- $exchange_id = input('exchange_id', '');
-
- $field = 'pe.*,sku.sku_name,sku.price as market_price,sku.sku_image,sku.stock';
- $alias = 'pe';
- $join = [
- [
- 'promotion_exchange_goods peg',
- 'peg.id = pe.exchange_goods_id',
- 'inner'
- ],
- [
- 'goods_sku sku',
- 'sku.sku_id = pe.type_id',
- 'inner'
- ]
- ];
- $condition = [
- [ 'peg.id', '=', $exchange_id ],
- [ 'sku.is_delete', '=', 0 ],
- [ 'sku.goods_state', '=', 1 ],
- [ 'peg.state', '=', 1 ],
- ];
-
- $goods_list = $exchange_model->getExchangeList($condition, $field, '', null, $alias, $join);
- foreach ($goods_list[ 'data' ] as $k => $v) {
- $goods_list[ 'data' ][ $k ][ 'stock' ] = numberFormat($goods_list[ 'data' ][ $k ][ 'stock' ]);
- }
- return $goods_list;
- }
- }
-
- /**
- * 获取优惠券列表
- */
- public function getCouponList()
- {
- $coupon_type_model = new CouponTypeModel();
- if (request()->isJson()) {
- $page = input('page', 1);
- $page_size = input('page_size', PAGE_LIST_ROWS);
- $status = input('status', '');
-
- $condition = [];
- if ($status !== "") {
- $condition[] = [ 'status', '=', $status ];
- }
-
- $condition[] = [ 'site_id', '=', $this->site_id ];
- $order = 'sort asc';
- $field = '*';
-
- $res = $coupon_type_model->getCouponTypePageList($condition, $page, $page_size, $order, $field);
- $exchange_model = new ExchangeModel();
- //兑换名称 兑换图片 兑换库存 兑换价格
- $exchange_list = $exchange_model->getExchangeList([ [ 'type', '=', 2 ] ], 'type_id')[ 'data' ] ?? [];
- if ($exchange_list) {
- $exchange_list = array_column($exchange_list, 'type_id');
- }
-
- if ($res[ 'data' ][ 'list' ]) {
- foreach ($res[ 'data' ][ 'list' ] as $key => $val) {
- if (in_array($val[ 'coupon_type_id' ], $exchange_list)) {
- $res[ 'data' ][ 'list' ][ $key ][ 'is_exit' ] = 1;
- } else {
- $res[ 'data' ][ 'list' ][ $key ][ 'is_exit' ] = 0;
- }
- }
- }
- return $res;
-
- }
- }
-
- /**
- *关闭积分兑换
- */
- public function deleteAll()
- {
- if (request()->isJson()) {
- $id = input("exchange_id", '');
- $exchange_model = new ExchangeModel();
- foreach ($id as $k => $v){
- $res = $exchange_model->deleteExchange($v);
- }
- return $res;
- }
- }
+isJson()) {
+ $page = input('page', 1);
+ $page_size = input('page_size', PAGE_LIST_ROWS);
+ $search_text = input('search_text', '');
+ $type = input('type', '');
+ $state = input('state', '');
+ $sort = input('sort', 'asc');
+ $condition[] = [ 'peg.site_id', '=', $this->site_id ];
+ if ($search_text) {
+ $condition[] = [ 'peg.name', 'like', '%' . $search_text . '%' ];
+ }
+ if ($type) {
+ $condition[] = [ 'peg.type', '=', $type ];
+ }
+ if ($state != '') {
+ $condition[] = [ 'peg.state', '=', $state ];
+ }
+
+ $field = 'peg.*';
+ $alias = 'peg';
+ $join = [];
+
+ //排序
+ $order = input('order', 'create_time');
+ $sort = input('sort', 'desc');
+ if ($order == 'sort') {
+ $order_by = 'peg.' . $order . ' ' . $sort;
+ } else {
+ $order_by = 'peg.' . $order . ' ' . $sort . ',peg.sort desc';
+ }
+
+ $exchange_model = new ExchangeModel();
+ //兑换名称 兑换图片 兑换库存 兑换价格
+ $lists = $exchange_model->getExchangeGoodsPageList($condition, $page, $page_size, $order_by, $field, $alias, $join);
+ return $lists;
+ }
+
+ return $this->fetch("exchange/lists");
+ }
+
+ /**
+ * 添加积分兑换
+ */
+ public function add()
+ {
+ if (request()->isJson()) {
+ $type = input('type', '1');//兑换类型 1 商品 2 优惠券 3 红包
+
+ $data = [
+ 'site_id' => $this->site_id,
+ 'type' => $type,//兑换类型 1 商品 2 优惠券 3 红包
+ 'point' => input('point', ''),//积分
+ 'state' => input('state', ''),
+ 'is_free_shipping' => input('is_free_shipping', ''),
+ 'delivery_type' => input('delivery_type', ''),
+ 'delivery_price' => input('delivery_price', ''),
+ 'shipping_template' => input('shipping_template', ''),
+ ];
+ if ($type == 1) {
+ $data[ 'goods_data' ] = input('goods_data', '');
+ $data[ 'rule' ] = input('content', '');
+ $data[ 'type_name' ] = '商品';
+ } elseif ($type == 2) {
+ $data[ 'coupon_type_id' ] = input('coupon_type_id', '0');//优惠券id
+ $data[ 'content' ] = input('content', '');
+ $data[ 'type_name' ] = '优惠券';
+ $data[ 'stock' ] = input('stock', '');
+ } elseif ($type == 3) {
+ $data[ 'name' ] = input('name', '');
+ $data[ 'image' ] = input('image', '');
+ $data[ 'stock' ] = input('stock', '');
+ $data[ 'balance' ] = input('balance', '0');
+ $data[ 'content' ] = input('content', '');
+ $data[ 'type_name' ] = '红包';
+ } else {
+ return error(-1, '');
+ }
+ $exchange_model = new ExchangeModel();
+ $res = $exchange_model->addExchange($data);
+ return $res;
+ } else {
+ //获取运费模板
+ $express_template_model = new ExpressTemplateModel();
+ $express_template_list = $express_template_model->getExpressTemplateList([ [ 'site_id', "=", $this->site_id ] ], 'template_id,template_name', 'is_default desc');
+ $express_template_list = $express_template_list[ 'data' ];
+ $this->assign("express_template_list", $express_template_list);
+
+ return $this->fetch("exchange/add");
+ }
+ }
+
+ /**
+ * 编辑积分兑换
+ */
+ public function edit()
+ {
+ $id = input("id", 0);
+ $exchange_model = new ExchangeModel();
+ if (request()->isJson()) {
+ $type = input('type', '1');//兑换类型 1 商品 2 优惠券 3 红包
+ $data = [
+ 'site_id' => $this->site_id,
+ 'type' => $type,//兑换类型 1 商品 2 优惠券 3 红包
+ 'point' => input('point', ''),//积分
+ 'state' => input('state', ''),
+ 'id' => $id,
+ 'is_free_shipping' => input('is_free_shipping', ''),
+ 'delivery_type' => input('delivery_type', ''),
+ 'delivery_price' => input('delivery_price', ''),
+ 'shipping_template' => input('shipping_template', ''),
+ ];
+ if ($type == 1) {
+ $data[ 'goods_data' ] = input('goods_data', '');
+ $data[ 'rule' ] = input('content', '');
+ $data[ 'type_name' ] = '商品';
+
+ } elseif ($type == 2) {
+ $data[ 'coupon_type_id' ] = input('coupon_type_id', '0');//优惠券id
+ $data[ 'content' ] = input('content', '');
+ $data[ 'type_name' ] = '优惠券';
+ $data[ 'stock' ] = input('stock', '');
+ } elseif ($type == 3) {
+ $data[ 'name' ] = input('name', '');
+ $data[ 'image' ] = input('image', '');
+ $data[ 'stock' ] = input('stock', '');
+ $data[ 'balance' ] = input('balance', '0');
+ $data[ 'content' ] = input('content', '');
+ $data[ 'type_name' ] = '红包';
+ } else {
+ return error(-1, '');
+ }
+
+ $res = $exchange_model->editExchange($data);
+ return $res;
+ } else {
+ $exchange_info = $exchange_model->getExchangeGoodsDetail($id, $this->site_id);
+ if (empty($exchange_info[ 'data' ][ 'id' ])) {
+ $this->error('对应的积分兑换活动商品/优惠券已经不存在了!');
+ }
+ $this->assign("exchange_info", $exchange_info[ 'data' ]);
+
+ //获取运费模板
+ $express_template_model = new ExpressTemplateModel();
+ $express_template_list = $express_template_model->getExpressTemplateList([ [ 'site_id', "=", $this->site_id ] ], 'template_id,template_name', 'is_default desc');
+ $express_template_list = $express_template_list[ 'data' ];
+ $this->assign("express_template_list", $express_template_list);
+
+ return $this->fetch("exchange/edit");
+ }
+ }
+
+ /**
+ *关闭积分兑换
+ */
+ public function delete()
+ {
+ $id = input("id", 0);
+ $exchange_model = new ExchangeModel();
+ $res = $exchange_model->deleteExchange($id);
+ return $res;
+
+ }
+
+ /**
+ * 修改排序
+ */
+ public function modifySort()
+ {
+ $sort = input('sort', 0);
+ $id = input('id', 0);
+ $exchange_model = new ExchangeModel();
+ return $exchange_model->modifyExchangeSort($sort, $id);
+ }
+
+
+ /**
+ * 获取商品列表
+ * @return array
+ */
+ public function getSkuList()
+ {
+ if (request()->isJson()) {
+ $exchange_model = new ExchangeModel();
+
+ $exchange_id = input('exchange_id', '');
+
+ $field = 'pe.*,sku.sku_name,sku.price as market_price,sku.sku_image,sku.stock';
+ $alias = 'pe';
+ $join = [
+ [
+ 'promotion_exchange_goods peg',
+ 'peg.id = pe.exchange_goods_id',
+ 'inner'
+ ],
+ [
+ 'goods_sku sku',
+ 'sku.sku_id = pe.type_id',
+ 'inner'
+ ]
+ ];
+ $condition = [
+ [ 'peg.id', '=', $exchange_id ],
+ [ 'sku.is_delete', '=', 0 ],
+ [ 'sku.goods_state', '=', 1 ],
+ [ 'peg.state', '=', 1 ],
+ ];
+
+ $goods_list = $exchange_model->getExchangeList($condition, $field, '', null, $alias, $join);
+ foreach ($goods_list[ 'data' ] as $k => $v) {
+ $goods_list[ 'data' ][ $k ][ 'stock' ] = numberFormat($goods_list[ 'data' ][ $k ][ 'stock' ]);
+ }
+ return $goods_list;
+ }
+ }
+
+ /**
+ * 获取优惠券列表
+ */
+ public function getCouponList()
+ {
+ $coupon_type_model = new CouponTypeModel();
+ if (request()->isJson()) {
+ $page = input('page', 1);
+ $page_size = input('page_size', PAGE_LIST_ROWS);
+ $status = input('status', '');
+
+ $condition = [];
+ if ($status !== "") {
+ $condition[] = [ 'status', '=', $status ];
+ }
+
+ $condition[] = [ 'site_id', '=', $this->site_id ];
+ $order = 'sort asc';
+ $field = '*';
+
+ $res = $coupon_type_model->getCouponTypePageList($condition, $page, $page_size, $order, $field);
+ $exchange_model = new ExchangeModel();
+ //兑换名称 兑换图片 兑换库存 兑换价格
+ $exchange_list = $exchange_model->getExchangeList([ [ 'type', '=', 2 ] ], 'type_id')[ 'data' ] ?? [];
+ if ($exchange_list) {
+ $exchange_list = array_column($exchange_list, 'type_id');
+ }
+
+ if ($res[ 'data' ][ 'list' ]) {
+ foreach ($res[ 'data' ][ 'list' ] as $key => $val) {
+ if (in_array($val[ 'coupon_type_id' ], $exchange_list)) {
+ $res[ 'data' ][ 'list' ][ $key ][ 'is_exit' ] = 1;
+ } else {
+ $res[ 'data' ][ 'list' ][ $key ][ 'is_exit' ] = 0;
+ }
+ }
+ }
+ return $res;
+
+ }
+ }
+
+ /**
+ *关闭积分兑换
+ */
+ public function deleteAll()
+ {
+ if (request()->isJson()) {
+ $id = input("exchange_id", '');
+ $exchange_model = new ExchangeModel();
+ foreach ($id as $k => $v){
+ $res = $exchange_model->deleteExchange($v);
+ }
+ return $res;
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/pointexchange/shop/controller/Pointexchange.php b/src/addon/pointexchange/shop/controller/Pointexchange.php
index eccbed204..520bd614d 100644
--- a/src/addon/pointexchange/shop/controller/Pointexchange.php
+++ b/src/addon/pointexchange/shop/controller/Pointexchange.php
@@ -1,113 +1,105 @@
-replace = [
- 'POINTEXCHANGE_CSS' => __ROOT__ . '/addon/pointexchange/shop/view/public/css',
- 'POINTEXCHANGE_JS' => __ROOT__ . '/addon/pointexchange/shop/view/public/js',
- 'POINTEXCHANGE_IMG' => __ROOT__ . '/addon/pointexchange/shop/view/public/img',
- ];
- parent::__construct($app);
-
- }
-
- /**
- * 兑换订单列表
- * @return mixed
- */
- public function lists()
- {
-
- $exchange_id = input('exchange_id', '');
- if (request()->isJson()) {
- $page = input('page', 1);
- $page_size = input('page_size', PAGE_LIST_ROWS);
- $search_text = input('search_text', '');
- $condition = [
- ['eo.site_id','=',$this->site_id]
- ];
- if ($search_text) {
- $condition[] = [ 'eo.exchange_name', 'like', '%' . $search_text . '%' ];
- }
-
- $name = input('name', '');
- if (!empty($name)) {
- $condition[] = [ 'm.nickname', 'like', '%' . $name . '%' ];
- }
-
- $mobile = input('mobile', '');
- if (!empty($mobile)) {
- $condition[] = [ 'eo.mobile', 'like', '%' . $mobile . '%' ];
- }
-
- $type = input('type', '');
- if ($type) {
- $condition[] = [ 'eo.type', '=', $type ];
- }
-
- if ($exchange_id) {
- $condition[] = [ 'eo.exchange_goods_id', '=', $exchange_id ];
- }
-
- $start_time = input('start_time', '');
- $end_time = input('end_time', '');
-
- if ($start_time && !$end_time) {
- $condition[] = [ 'eo.pay_time', '>=', date_to_time($start_time) ];
- } elseif (!$start_time && $end_time) {
- $condition[] = [ 'eo.pay_time', '<=', date_to_time($end_time) ];
- } elseif ($start_time && $end_time) {
- $condition[] = [ 'eo.pay_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
- }
-
- $order = 'eo.create_time desc';
- $field = 'eo.*,m.nickname';
-
- $exchange_order_model = new ExchangeOrderModel();
- $list = $exchange_order_model->getExchangePageList($condition, $page, $page_size, $order, $field, 'eo', [
- [ 'member m', 'm.member_id=eo.member_id', 'left' ]
- ]);
- // file_put_contents(__DIR__ . '/debug.txt', var_export($condition,true));
- return $list;
-
- } else {
- $this->assign('exchange_id', $exchange_id);
- return $this->fetch("exchange_order/lists");
- }
-
- }
-
- /**订单详情
- * @return mixed
- */
- public function detail()
- {
- $order_id = input('order_id', 0);
- $order_model = new ExchangeOrderModel();
- $order_info = $order_model->getOrderInfo([ [ 'site_id', '=', $this->site_id ], [ 'order_id', '=', $order_id ] ]);
- $order_info = $order_info[ "data" ];
- if (empty($order_info)) $this->error('未获取到订单数据', href_url('pointexchange://shop/pointexchange/lists'));
- $this->assign("order_info", $order_info);
- return $this->fetch('exchange_order/detail');
- }
-
+replace = [
+ 'POINTEXCHANGE_CSS' => __ROOT__ . '/addon/pointexchange/shop/view/public/css',
+ 'POINTEXCHANGE_JS' => __ROOT__ . '/addon/pointexchange/shop/view/public/js',
+ 'POINTEXCHANGE_IMG' => __ROOT__ . '/addon/pointexchange/shop/view/public/img',
+ ];
+ parent::__construct($app);
+
+ }
+
+ /**
+ * 兑换订单列表
+ * @return mixed
+ */
+ public function lists()
+ {
+
+ $exchange_id = input('exchange_id', '');
+ if (request()->isJson()) {
+ $page = input('page', 1);
+ $page_size = input('page_size', PAGE_LIST_ROWS);
+ $search_text = input('search_text', '');
+ $condition = [
+ ['eo.site_id','=',$this->site_id]
+ ];
+ if ($search_text) {
+ $condition[] = [ 'eo.exchange_name', 'like', '%' . $search_text . '%' ];
+ }
+
+ $name = input('name', '');
+ if (!empty($name)) {
+ $condition[] = [ 'm.nickname', 'like', '%' . $name . '%' ];
+ }
+
+ $mobile = input('mobile', '');
+ if (!empty($mobile)) {
+ $condition[] = [ 'eo.mobile', 'like', '%' . $mobile . '%' ];
+ }
+
+ $type = input('type', '');
+ if ($type) {
+ $condition[] = [ 'eo.type', '=', $type ];
+ }
+
+ if ($exchange_id) {
+ $condition[] = [ 'eo.exchange_goods_id', '=', $exchange_id ];
+ }
+
+ $start_time = input('start_time', '');
+ $end_time = input('end_time', '');
+
+ if ($start_time && !$end_time) {
+ $condition[] = [ 'eo.pay_time', '>=', date_to_time($start_time) ];
+ } elseif (!$start_time && $end_time) {
+ $condition[] = [ 'eo.pay_time', '<=', date_to_time($end_time) ];
+ } elseif ($start_time && $end_time) {
+ $condition[] = [ 'eo.pay_time', 'between', [ date_to_time($start_time), date_to_time($end_time) ] ];
+ }
+
+ $order = 'eo.create_time desc';
+ $field = 'eo.*,m.nickname';
+
+ $exchange_order_model = new ExchangeOrderModel();
+ $list = $exchange_order_model->getExchangePageList($condition, $page, $page_size, $order, $field, 'eo', [
+ [ 'member m', 'm.member_id=eo.member_id', 'left' ]
+ ]);
+ // file_put_contents(__DIR__ . '/debug.txt', var_export($condition,true));
+ return $list;
+
+ } else {
+ $this->assign('exchange_id', $exchange_id);
+ return $this->fetch("exchange_order/lists");
+ }
+
+ }
+
+ /**订单详情
+ * @return mixed
+ */
+ public function detail()
+ {
+ $order_id = input('order_id', 0);
+ $order_model = new ExchangeOrderModel();
+ $order_info = $order_model->getOrderInfo([ [ 'site_id', '=', $this->site_id ], [ 'order_id', '=', $order_id ] ]);
+ $order_info = $order_info[ "data" ];
+ if (empty($order_info)) $this->error('未获取到订单数据', href_url('pointexchange://shop/pointexchange/lists'));
+ $this->assign("order_info", $order_info);
+ return $this->fetch('exchange_order/detail');
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/printer/config/diy_view.php b/src/addon/printer/config/diy_view.php
index c3c657905..e36ca9b7d 100644
--- a/src/addon/printer/config/diy_view.php
+++ b/src/addon/printer/config/diy_view.php
@@ -1,38 +1,30 @@
- '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
- 'template' => [],
-
- // 后台自定义组件——装修
- 'util' => [],
-
- // 自定义页面路径
- 'link' => [],
-
- // 自定义图标库
- 'icon_library' => [],
-
- // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
- 'component' => [],
-
- // uni-app 页面,多个逗号隔开
- 'pages' => [],
-
- // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
- 'info' => [],
-
- // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
- 'theme' => [],
-
- // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
- 'data' => []
+ '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
+ 'template' => [],
+
+ // 后台自定义组件——装修
+ 'util' => [],
+
+ // 自定义页面路径
+ 'link' => [],
+
+ // 自定义图标库
+ 'icon_library' => [],
+
+ // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
+ 'component' => [],
+
+ // uni-app 页面,多个逗号隔开
+ 'pages' => [],
+
+ // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
+ 'info' => [],
+
+ // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
+ 'theme' => [],
+
+ // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
+ 'data' => []
];
\ No newline at end of file
diff --git a/src/addon/printer/config/info.php b/src/addon/printer/config/info.php
index c0be5f4b4..225ff13f1 100644
--- a/src/addon/printer/config/info.php
+++ b/src/addon/printer/config/info.php
@@ -1,20 +1,12 @@
- 'printer',
- 'title' => '小票打印',
- 'description' => '小票打印',
- 'type' => 'tool', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
- 'status' => 1,
- 'author' => '',
- 'version' => '5.3.1',
- 'version_no' => '525231212001',
- 'content' => '',
+ 'printer',
+ 'title' => '小票打印',
+ 'description' => '小票打印',
+ 'type' => 'tool', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
+ 'status' => 1,
+ 'author' => '',
+ 'version' => '5.3.1',
+ 'version_no' => '525231212001',
+ 'content' => '',
];
\ No newline at end of file
diff --git a/src/addon/printer/event/Install.php b/src/addon/printer/event/Install.php
index 390616650..d65ded2e5 100644
--- a/src/addon/printer/event/Install.php
+++ b/src/addon/printer/event/Install.php
@@ -1,25 +1,17 @@
-addCron(1, 0, "充值小票打印", "MemberRechargeOrderPayPrinter", time(), $param[ 'order_id' ]);
- }
+addCron(1, 0, "充值小票打印", "MemberRechargeOrderPayPrinter", time(), $param[ 'order_id' ]);
+ }
}
\ No newline at end of file
diff --git a/src/addon/printer/event/MemberRechargeOrderPayPrinter.php b/src/addon/printer/event/MemberRechargeOrderPayPrinter.php
index e678d0d11..28a02ba0e 100644
--- a/src/addon/printer/event/MemberRechargeOrderPayPrinter.php
+++ b/src/addon/printer/event/MemberRechargeOrderPayPrinter.php
@@ -1,29 +1,20 @@
-printer([
- 'order_id' => $param['relate_id'],
- 'type' => 'recharge',
- ]);
- }
+printer([
+ 'order_id' => $param['relate_id'],
+ 'type' => 'recharge',
+ ]);
+ }
}
\ No newline at end of file
diff --git a/src/addon/printer/event/OrderPay.php b/src/addon/printer/event/OrderPay.php
index db7eb690c..b7eb047a1 100644
--- a/src/addon/printer/event/OrderPay.php
+++ b/src/addon/printer/event/OrderPay.php
@@ -1,28 +1,20 @@
-addCron(1, 0, "订单小票打印", "OrderPayPrinter", time(), $param[ 'order_id' ]);
- }
+addCron(1, 0, "订单小票打印", "OrderPayPrinter", time(), $param[ 'order_id' ]);
+ }
}
\ No newline at end of file
diff --git a/src/addon/printer/event/OrderPayPrinter.php b/src/addon/printer/event/OrderPayPrinter.php
index d075205a1..735c028f3 100644
--- a/src/addon/printer/event/OrderPayPrinter.php
+++ b/src/addon/printer/event/OrderPayPrinter.php
@@ -1,30 +1,22 @@
-printer([
- 'order_id' => $param[ 'relate_id' ],
- 'type' => 'goodsorder',
- 'printer_type' => 'order_pay',
- ]);
- }
+printer([
+ 'order_id' => $param[ 'relate_id' ],
+ 'type' => 'goodsorder',
+ 'printer_type' => 'order_pay',
+ ]);
+ }
}
\ No newline at end of file
diff --git a/src/addon/printer/event/OrderTakeDeliveryAfter.php b/src/addon/printer/event/OrderTakeDeliveryAfter.php
index dd9834695..17b498db0 100644
--- a/src/addon/printer/event/OrderTakeDeliveryAfter.php
+++ b/src/addon/printer/event/OrderTakeDeliveryAfter.php
@@ -1,28 +1,20 @@
-addCron(1, 0, "订单收货小票打印", "OrderTakeDeliveryPrinter", time(), $param[ 'order_id' ]);
- }
+addCron(1, 0, "订单收货小票打印", "OrderTakeDeliveryPrinter", time(), $param[ 'order_id' ]);
+ }
}
\ No newline at end of file
diff --git a/src/addon/printer/event/OrderTakeDeliveryPrinter.php b/src/addon/printer/event/OrderTakeDeliveryPrinter.php
index 28511e008..54cb47c84 100644
--- a/src/addon/printer/event/OrderTakeDeliveryPrinter.php
+++ b/src/addon/printer/event/OrderTakeDeliveryPrinter.php
@@ -1,32 +1,24 @@
-printer([
- 'order_id' => $param[ 'relate_id' ],
- 'type' => 'goodsorder',
- 'printer_type' => 'take_delivery',
- ]);
- }
+printer([
+ 'order_id' => $param[ 'relate_id' ],
+ 'type' => 'goodsorder',
+ 'printer_type' => 'take_delivery',
+ ]);
+ }
}
\ No newline at end of file
diff --git a/src/addon/printer/event/PrintOrder.php b/src/addon/printer/event/PrintOrder.php
index e90d75f91..5dfe98be3 100644
--- a/src/addon/printer/event/PrintOrder.php
+++ b/src/addon/printer/event/PrintOrder.php
@@ -1,26 +1,18 @@
-printer($params);
- }
+printer($params);
+ }
}
\ No newline at end of file
diff --git a/src/addon/printer/event/PrinterContent.php b/src/addon/printer/event/PrinterContent.php
index 8c567a0de..288dc5db7 100644
--- a/src/addon/printer/event/PrinterContent.php
+++ b/src/addon/printer/event/PrinterContent.php
@@ -1,320 +1,312 @@
-getOrderDetail($order_id)[ 'data' ];
- $site_id = $order_info[ 'site_id' ];
- $store_id = $order_info[ 'store_id' ];
-
- //获取店铺信息
- $shop_model = new Shop();
- $shop_info = $shop_model->getShopInfo([ [ 'site_id', '=', $site_id ] ])[ 'data' ];
-
- $site_name = ( new Site() )->getSiteInfo([ [ 'site_id', '=', $site_id ] ], 'site_name')[ 'data' ][ 'site_name' ] ?? '';
-
- //获取打印机列表
- $print_model = new Printer();
- $printer_condition = [
- [ 'site_id', '=', $site_id ]
- ];
- if (addon_is_exit('store', $site_id)) $printer_condition[] = [ 'store_id', '=', $store_id ];
-
- switch ( $stage ) {
- case 'order_pay':
- $printer_condition[] = [ 'order_pay_open', '=', 1 ];
- $printer_condition[] = [ 'order_pay_order_type', 'like', '%,' . $order_info[ 'order_type' ] . ',%' ];
- break;
- case 'take_delivery':
- $printer_condition[] = [ 'take_delivery_open', '=', 1 ];
- $printer_condition[] = [ 'take_delivery_order_type', 'like', '%,' . $order_info[ 'order_type' ] . ',%' ];
- break;
- case 'manual':
- $printer_condition[] = [ 'manual_open', '=', 1 ];
- break;
- }
-
- $printer_data = $print_model->getPrinterList($printer_condition)[ 'data' ] ?? [];
- $res_data = [];
-
- foreach ($printer_data as $k => $v) {
- //此处应该根据打印机不同分别设置返回不同的数据。当前为易联云
- $array = [];
- $array[ 'printer_info' ] = $v;
- $print_template_model = new PrinterTemplate();
-
- $template_id = 0;
- $print_num = 1;
- switch ( $stage ) {
- case 'order_pay':
- //支付
- $template_id = $v[ 'order_pay_template_id' ];
- $print_num = $v[ 'order_pay_print_num' ];
- break;
- case 'take_delivery':
- //收货
- $template_id = $v[ 'take_delivery_template_id' ];
- $print_num = $v[ 'take_delivery_print_num' ];
- break;
- case 'manual':
- //手动打印
- $template_id = $v[ 'template_id' ];
- $print_num = $v[ 'print_num' ];
- break;
- }
-
- $print_template = $print_template_model->getPrinterTemplateInfo([ [ 'template_id', '=', $template_id ] ])[ 'data' ];
-
- $array[ 'printer_code' ] = $v[ 'printer_code' ]; //商户授权机器码
- $array[ 'origin_id' ] = $order_info[ 'order_no' ]; //内部订单号(32位以内)
- /**文本接口开始**/
- $content = "" . $print_num . "";
- //小票名称
- if ($print_template[ 'title' ] != '') {
- $content .= "" . $print_template[ 'title' ] . "";
- $content .= str_repeat('.', 32);
- }
- //商城名称
- if ($print_template[ 'head' ] == 1) {
- $content .= "" . $site_name . "";
- $content .= str_repeat('.', 32);
- }
-
- if (!empty($order_info[ 'pay_time' ])) {
- $content .= "订单时间:" . date("Y-m-d H:i", $order_info[ 'pay_time' ]) . "\n";
- } else {
- $content .= "订单时间:" . date("Y-m-d H:i", time()) . "\n";
- }
- $content .= "订单编号:" . $order_info[ 'order_no' ] . "\n";
- $content .= "支付方式:" . $order_info[ 'pay_type_name' ] . "\n";
-
- switch ( $order_info[ 'order_type' ] ) {
- case 1 :
- // 物流订单
- break;
- case 2 :
- // 自提订单
- if ($order_info[ 'buyer_ask_delivery_time' ] == 0) {
- $buyer_ask_delivery_time_str = '立即自提';
- } elseif (strpos($order_info[ 'buyer_ask_delivery_time' ], '-') !== false) {
- $buyer_ask_delivery_time_str = $order_info[ 'buyer_ask_delivery_time' ];
- } else {
- $buyer_ask_delivery_time_str = date("H:i:s", $order_info[ 'buyer_ask_delivery_time' ]);
- }
- $content .= "要求自提时间:" . $buyer_ask_delivery_time_str . "\n";
- break;
- case 3 :
- // 外卖订单
- if ($order_info[ 'buyer_ask_delivery_time' ] == 0) {
- $buyer_ask_delivery_time_str = '立即送达';
- } elseif (strpos($order_info[ 'buyer_ask_delivery_time' ], '-') !== false) {
- $buyer_ask_delivery_time_str = $order_info[ 'buyer_ask_delivery_time' ];
- } else {
- $buyer_ask_delivery_time_str = date("H:i:s", $order_info[ 'buyer_ask_delivery_time' ]);
- }
- $content .= "要求送达时间:" . $buyer_ask_delivery_time_str . "\n";
- break;
- case 4 :
- // 虚拟订单
- break;
- case 5 :
- // 收银订单
- break;
- }
-
- $content .= str_repeat('.', 32);
- $content .= "";
- $content .= "";
- if ($print_template[ 'goods_price_show' ]) {
- $content .= "| 商品名称 | | 数量 | 金额 | ";
- } else {
- $content .= "商品名称 | | | 数量 | ";
- }
- $content .= "
";
- $content .= "
";
- $content .= str_repeat('.', 32);
- $content .= "";
- foreach ($order_info[ 'order_goods' ] as $goods) {
- //显示售价或卖价
- $price = $print_template[ 'goods_price_type' ] == 'price' ? $goods[ 'price' ] : $goods[ 'real_goods_money' ];
- if ($print_template[ 'goods_price_show' ]) {
- $content .= "| " . $goods[ 'sku_name' ] . " | | x" . $goods[ 'num' ] . " | ¥" . $price . " |
";
- } else {
- $content .= "| " . $goods[ 'sku_name' ] . " | | | x" . $goods[ 'num' ] . " |
";
- }
-
- //商品编码
- if ($print_template[ 'goods_code_show' ] && !empty($goods[ 'sku_no' ])) {
- $content .= "| [" . $goods[ 'sku_no' ] . "] | | | |
";
- }
-
- }
- $content .= "
";
- $content .= str_repeat('.', 32);
- if ($order_info[ "goods_money" ] > 0) {
- $content .= "商品总额:¥" . $order_info[ "goods_money" ] . "\n";
- }
- if ($order_info[ "coupon_money" ] > 0) {
- $content .= "店铺优惠券:¥" . $order_info[ "coupon_money" ] . "\n";
- }
- if ($order_info[ "promotion_money" ] > 0) {
- $content .= "店铺优惠:¥" . $order_info[ "promotion_money" ] . "\n";
- }
- if ($order_info[ "point_money" ] > 0) {
- $content .= "积分抵扣:¥" . $order_info[ "point_money" ] . "\n";
- }
- if ($order_info[ "adjust_money" ] > 0) {
- $content .= "订单调价:¥" . $order_info[ "adjust_money" ] . "\n";
- }
- if ($order_info[ 'reduction' ] > 0) {
- $content .= "订单减免:¥" . $order_info[ "reduction" ] . "\n";
- }
- if ($order_info[ "balance_money" ] > 0) {
- $content .= "余额抵扣:¥" . $order_info[ "balance_money" ] . "\n";
- }
- if ($order_info[ "delivery_money" ] > 0) {
- $content .= "配送费用:¥" . $order_info[ "delivery_money" ] . "\n";
- }
- if ($order_info[ "invoice_money" ] > 0) {
- $content .= "发票费用:¥" . $order_info[ "invoice_money" ] . "\n";
- }
- if ($order_info[ "invoice_delivery_money" ] > 0) {
- $content .= "发票邮寄费用:¥" . $order_info[ "invoice_delivery_money" ] . "\n";
- }
- if ($order_info[ "goods_num" ] > 0) {
- $content .= "订单共" . $order_info[ 'goods_num' ] . "件商品,总计: ¥" . $order_info[ 'order_money' ] . " \n";
- }
- $content .= str_repeat('.', 32);
-
- /******************** 备注信息 **************************/
- //买家留言
- if ($print_template[ 'buy_notes' ] == 1) {
- $order_info[ "buyer_message" ] = $order_info[ "buyer_message" ] ? $order_info[ "buyer_message" ] : '无';
- $content .= "买家留言:" . $order_info[ "buyer_message" ] . "\n";
- $content .= str_repeat('.', 32);
- }
- //卖家留言
- if ($print_template[ 'seller_notes' ] == 1) {
- $order_info[ "remark" ] = $order_info[ "remark" ] ? $order_info[ "remark" ] : '无';
- $content .= "卖家留言:" . $order_info[ "remark" ] . "\n";
- $content .= str_repeat('.', 32);
- }
-
- //表单
- if ($print_template[ 'form_show' ] == 1 && addon_is_exit('form')) {
- $form_info = model('form_data')->getInfo([ [ 'site_id', '=', $site_id ], [ 'scene', '=', 'order' ], [ 'relation_id', '=', $order_id ] ]);
- if (!empty($form_info) && !empty($form_info[ 'form_data' ])) {
- $form_data = json_decode($form_info[ 'form_data' ], true);
- foreach ($form_data as $item) {
- $content .= "" . $item[ 'title' ] . ":" . $item[ "val" ] . "\n";
- $content .= str_repeat('.', 32);
- }
- }
- }
-
- /******************** 买家信息 **************************/
- if ($order_info[ 'member_id' ]) {
- $member_info = model('member')->getInfo([['member_id', '=', $order_info[ 'member_id' ]]]);
- //买家姓名
- if ($print_template[ 'buy_name' ] == 1) {
- if($order_info[ 'order_type' ] == 2){
- $content .= "" . $member_info[ "nickname" ] . "\n";
- }else{
- $content .= "" . $order_info[ "name" ] . "\n";
- }
-
- }
- //联系方式
- if ($print_template[ 'buy_mobile' ] == 1) {
- if($order_info[ 'order_type' ] == 2){
- $content .= "" . $member_info[ "mobile" ] . "\n";
- }else{
- $content .= "" . $order_info[ "mobile" ] . "\n";
- }
-
- }
- //地址
- if ($print_template[ 'buy_address' ] == 1) {
- if($order_info[ 'order_type' ] == 2){
- $content .= "自提门店:" . $order_info[ 'delivery_store_name' ] . "\n";
- }else{
- $content .= "" . $order_info[ 'full_address' ] . "-" . $order_info[ 'address' ] . "\n";
- }
-
- }
- if ($print_template[ 'buy_name' ] == 1 || $print_template[ 'buy_mobile' ] == 1 || $print_template[ 'buy_address' ] == 1) {
- $content .= str_repeat('.', 32);
- }
- }
- /******************** 商城信息 **************************/
- //联系方式
- if ($print_template[ 'shop_mobile' ] == 1) {
- $content .= "" . $shop_info[ "mobile" ] . "\n";
- }
-
- //地址
- if ($print_template[ 'shop_address' ] == 1) {
- $content .= "" . $shop_info[ 'province_name' ] . $shop_info[ 'city_name' ] . $shop_info[ 'district_name' ] . $shop_info[ 'address' ] . "\n";
- }
-
- if ($print_template[ 'shop_mobile' ] == 1 || $print_template[ 'shop_address' ] == 1) {
- $content .= str_repeat('.', 32);
- }
-
- //二维码
- if ($print_template[ 'shop_qrcode' ] == 1) {
- $content .= "" . $print_template[ 'qrcode_url' ] . "";
- $content .= str_repeat('.', 32);
- }
-
- /******************** 门店信息 **************************/
- if ($order_info[ 'store_id' ] > 0) {
- $store_info = ( new Store() )->getStoreInfo([ [ 'store_id', '=', $order_info[ 'store_id' ] ] ], 'store_name,telphone,full_address')[ 'data' ];
- $content .= "" . $order_info[ "store_name" ] . "\n";//门店名称
- $content .= "" . $store_info[ "telphone" ] . "\n";//门店电话
- $content .= "" . $store_info[ "full_address" ] . "\n";//门店地址
- $content .= str_repeat('.', 32);
- }
-
- //底部内容
- if (!empty($print_template[ 'bottom' ])) {
- $content .= "" . $print_template[ 'bottom' ] . "";
- }
- $array[ 'content' ] = $content;
-
- $res_data[] = $array;
- }
- return $res_data;
-
- }
- }
+getOrderDetail($order_id)[ 'data' ];
+ $site_id = $order_info[ 'site_id' ];
+ $store_id = $order_info[ 'store_id' ];
+
+ //获取店铺信息
+ $shop_model = new Shop();
+ $shop_info = $shop_model->getShopInfo([ [ 'site_id', '=', $site_id ] ])[ 'data' ];
+
+ $site_name = ( new Site() )->getSiteInfo([ [ 'site_id', '=', $site_id ] ], 'site_name')[ 'data' ][ 'site_name' ] ?? '';
+
+ //获取打印机列表
+ $print_model = new Printer();
+ $printer_condition = [
+ [ 'site_id', '=', $site_id ]
+ ];
+ if (addon_is_exit('store', $site_id)) $printer_condition[] = [ 'store_id', '=', $store_id ];
+
+ switch ( $stage ) {
+ case 'order_pay':
+ $printer_condition[] = [ 'order_pay_open', '=', 1 ];
+ $printer_condition[] = [ 'order_pay_order_type', 'like', '%,' . $order_info[ 'order_type' ] . ',%' ];
+ break;
+ case 'take_delivery':
+ $printer_condition[] = [ 'take_delivery_open', '=', 1 ];
+ $printer_condition[] = [ 'take_delivery_order_type', 'like', '%,' . $order_info[ 'order_type' ] . ',%' ];
+ break;
+ case 'manual':
+ $printer_condition[] = [ 'manual_open', '=', 1 ];
+ break;
+ }
+
+ $printer_data = $print_model->getPrinterList($printer_condition)[ 'data' ] ?? [];
+ $res_data = [];
+
+ foreach ($printer_data as $k => $v) {
+ //此处应该根据打印机不同分别设置返回不同的数据。当前为易联云
+ $array = [];
+ $array[ 'printer_info' ] = $v;
+ $print_template_model = new PrinterTemplate();
+
+ $template_id = 0;
+ $print_num = 1;
+ switch ( $stage ) {
+ case 'order_pay':
+ //支付
+ $template_id = $v[ 'order_pay_template_id' ];
+ $print_num = $v[ 'order_pay_print_num' ];
+ break;
+ case 'take_delivery':
+ //收货
+ $template_id = $v[ 'take_delivery_template_id' ];
+ $print_num = $v[ 'take_delivery_print_num' ];
+ break;
+ case 'manual':
+ //手动打印
+ $template_id = $v[ 'template_id' ];
+ $print_num = $v[ 'print_num' ];
+ break;
+ }
+
+ $print_template = $print_template_model->getPrinterTemplateInfo([ [ 'template_id', '=', $template_id ] ])[ 'data' ];
+
+ $array[ 'printer_code' ] = $v[ 'printer_code' ]; //商户授权机器码
+ $array[ 'origin_id' ] = $order_info[ 'order_no' ]; //内部订单号(32位以内)
+ /**文本接口开始**/
+ $content = "" . $print_num . "";
+ //小票名称
+ if ($print_template[ 'title' ] != '') {
+ $content .= "" . $print_template[ 'title' ] . "";
+ $content .= str_repeat('.', 32);
+ }
+ //商城名称
+ if ($print_template[ 'head' ] == 1) {
+ $content .= "" . $site_name . "";
+ $content .= str_repeat('.', 32);
+ }
+
+ if (!empty($order_info[ 'pay_time' ])) {
+ $content .= "订单时间:" . date("Y-m-d H:i", $order_info[ 'pay_time' ]) . "\n";
+ } else {
+ $content .= "订单时间:" . date("Y-m-d H:i", time()) . "\n";
+ }
+ $content .= "订单编号:" . $order_info[ 'order_no' ] . "\n";
+ $content .= "支付方式:" . $order_info[ 'pay_type_name' ] . "\n";
+
+ switch ( $order_info[ 'order_type' ] ) {
+ case 1 :
+ // 物流订单
+ break;
+ case 2 :
+ // 自提订单
+ if ($order_info[ 'buyer_ask_delivery_time' ] == 0) {
+ $buyer_ask_delivery_time_str = '立即自提';
+ } elseif (strpos($order_info[ 'buyer_ask_delivery_time' ], '-') !== false) {
+ $buyer_ask_delivery_time_str = $order_info[ 'buyer_ask_delivery_time' ];
+ } else {
+ $buyer_ask_delivery_time_str = date("H:i:s", $order_info[ 'buyer_ask_delivery_time' ]);
+ }
+ $content .= "要求自提时间:" . $buyer_ask_delivery_time_str . "\n";
+ break;
+ case 3 :
+ // 外卖订单
+ if ($order_info[ 'buyer_ask_delivery_time' ] == 0) {
+ $buyer_ask_delivery_time_str = '立即送达';
+ } elseif (strpos($order_info[ 'buyer_ask_delivery_time' ], '-') !== false) {
+ $buyer_ask_delivery_time_str = $order_info[ 'buyer_ask_delivery_time' ];
+ } else {
+ $buyer_ask_delivery_time_str = date("H:i:s", $order_info[ 'buyer_ask_delivery_time' ]);
+ }
+ $content .= "要求送达时间:" . $buyer_ask_delivery_time_str . "\n";
+ break;
+ case 4 :
+ // 虚拟订单
+ break;
+ case 5 :
+ // 收银订单
+ break;
+ }
+
+ $content .= str_repeat('.', 32);
+ $content .= "";
+ $content .= "";
+ if ($print_template[ 'goods_price_show' ]) {
+ $content .= "| 商品名称 | | 数量 | 金额 | ";
+ } else {
+ $content .= "商品名称 | | | 数量 | ";
+ }
+ $content .= "
";
+ $content .= "
";
+ $content .= str_repeat('.', 32);
+ $content .= "";
+ foreach ($order_info[ 'order_goods' ] as $goods) {
+ //显示售价或卖价
+ $price = $print_template[ 'goods_price_type' ] == 'price' ? $goods[ 'price' ] : $goods[ 'real_goods_money' ];
+ if ($print_template[ 'goods_price_show' ]) {
+ $content .= "| " . $goods[ 'sku_name' ] . " | | x" . $goods[ 'num' ] . " | ¥" . $price . " |
";
+ } else {
+ $content .= "| " . $goods[ 'sku_name' ] . " | | | x" . $goods[ 'num' ] . " |
";
+ }
+
+ //商品编码
+ if ($print_template[ 'goods_code_show' ] && !empty($goods[ 'sku_no' ])) {
+ $content .= "| [" . $goods[ 'sku_no' ] . "] | | | |
";
+ }
+
+ }
+ $content .= "
";
+ $content .= str_repeat('.', 32);
+ if ($order_info[ "goods_money" ] > 0) {
+ $content .= "商品总额:¥" . $order_info[ "goods_money" ] . "\n";
+ }
+ if ($order_info[ "coupon_money" ] > 0) {
+ $content .= "店铺优惠券:¥" . $order_info[ "coupon_money" ] . "\n";
+ }
+ if ($order_info[ "promotion_money" ] > 0) {
+ $content .= "店铺优惠:¥" . $order_info[ "promotion_money" ] . "\n";
+ }
+ if ($order_info[ "point_money" ] > 0) {
+ $content .= "积分抵扣:¥" . $order_info[ "point_money" ] . "\n";
+ }
+ if ($order_info[ "adjust_money" ] > 0) {
+ $content .= "订单调价:¥" . $order_info[ "adjust_money" ] . "\n";
+ }
+ if ($order_info[ 'reduction' ] > 0) {
+ $content .= "订单减免:¥" . $order_info[ "reduction" ] . "\n";
+ }
+ if ($order_info[ "balance_money" ] > 0) {
+ $content .= "余额抵扣:¥" . $order_info[ "balance_money" ] . "\n";
+ }
+ if ($order_info[ "delivery_money" ] > 0) {
+ $content .= "配送费用:¥" . $order_info[ "delivery_money" ] . "\n";
+ }
+ if ($order_info[ "invoice_money" ] > 0) {
+ $content .= "发票费用:¥" . $order_info[ "invoice_money" ] . "\n";
+ }
+ if ($order_info[ "invoice_delivery_money" ] > 0) {
+ $content .= "发票邮寄费用:¥" . $order_info[ "invoice_delivery_money" ] . "\n";
+ }
+ if ($order_info[ "goods_num" ] > 0) {
+ $content .= "订单共" . $order_info[ 'goods_num' ] . "件商品,总计: ¥" . $order_info[ 'order_money' ] . " \n";
+ }
+ $content .= str_repeat('.', 32);
+
+ /******************** 备注信息 **************************/
+ //买家留言
+ if ($print_template[ 'buy_notes' ] == 1) {
+ $order_info[ "buyer_message" ] = $order_info[ "buyer_message" ] ? $order_info[ "buyer_message" ] : '无';
+ $content .= "买家留言:" . $order_info[ "buyer_message" ] . "\n";
+ $content .= str_repeat('.', 32);
+ }
+ //卖家留言
+ if ($print_template[ 'seller_notes' ] == 1) {
+ $order_info[ "remark" ] = $order_info[ "remark" ] ? $order_info[ "remark" ] : '无';
+ $content .= "卖家留言:" . $order_info[ "remark" ] . "\n";
+ $content .= str_repeat('.', 32);
+ }
+
+ //表单
+ if ($print_template[ 'form_show' ] == 1 && addon_is_exit('form')) {
+ $form_info = model('form_data')->getInfo([ [ 'site_id', '=', $site_id ], [ 'scene', '=', 'order' ], [ 'relation_id', '=', $order_id ] ]);
+ if (!empty($form_info) && !empty($form_info[ 'form_data' ])) {
+ $form_data = json_decode($form_info[ 'form_data' ], true);
+ foreach ($form_data as $item) {
+ $content .= "" . $item[ 'title' ] . ":" . $item[ "val" ] . "\n";
+ $content .= str_repeat('.', 32);
+ }
+ }
+ }
+
+ /******************** 买家信息 **************************/
+ if ($order_info[ 'member_id' ]) {
+ $member_info = model('member')->getInfo([['member_id', '=', $order_info[ 'member_id' ]]]);
+ //买家姓名
+ if ($print_template[ 'buy_name' ] == 1) {
+ if($order_info[ 'order_type' ] == 2){
+ $content .= "" . $member_info[ "nickname" ] . "\n";
+ }else{
+ $content .= "" . $order_info[ "name" ] . "\n";
+ }
+
+ }
+ //联系方式
+ if ($print_template[ 'buy_mobile' ] == 1) {
+ if($order_info[ 'order_type' ] == 2){
+ $content .= "" . $member_info[ "mobile" ] . "\n";
+ }else{
+ $content .= "" . $order_info[ "mobile" ] . "\n";
+ }
+
+ }
+ //地址
+ if ($print_template[ 'buy_address' ] == 1) {
+ if($order_info[ 'order_type' ] == 2){
+ $content .= "自提门店:" . $order_info[ 'delivery_store_name' ] . "\n";
+ }else{
+ $content .= "" . $order_info[ 'full_address' ] . "-" . $order_info[ 'address' ] . "\n";
+ }
+
+ }
+ if ($print_template[ 'buy_name' ] == 1 || $print_template[ 'buy_mobile' ] == 1 || $print_template[ 'buy_address' ] == 1) {
+ $content .= str_repeat('.', 32);
+ }
+ }
+ /******************** 商城信息 **************************/
+ //联系方式
+ if ($print_template[ 'shop_mobile' ] == 1) {
+ $content .= "" . $shop_info[ "mobile" ] . "\n";
+ }
+
+ //地址
+ if ($print_template[ 'shop_address' ] == 1) {
+ $content .= "" . $shop_info[ 'province_name' ] . $shop_info[ 'city_name' ] . $shop_info[ 'district_name' ] . $shop_info[ 'address' ] . "\n";
+ }
+
+ if ($print_template[ 'shop_mobile' ] == 1 || $print_template[ 'shop_address' ] == 1) {
+ $content .= str_repeat('.', 32);
+ }
+
+ //二维码
+ if ($print_template[ 'shop_qrcode' ] == 1) {
+ $content .= "" . $print_template[ 'qrcode_url' ] . "";
+ $content .= str_repeat('.', 32);
+ }
+
+ /******************** 门店信息 **************************/
+ if ($order_info[ 'store_id' ] > 0) {
+ $store_info = ( new Store() )->getStoreInfo([ [ 'store_id', '=', $order_info[ 'store_id' ] ] ], 'store_name,telphone,full_address')[ 'data' ];
+ $content .= "" . $order_info[ "store_name" ] . "\n";//门店名称
+ $content .= "" . $store_info[ "telphone" ] . "\n";//门店电话
+ $content .= "" . $store_info[ "full_address" ] . "\n";//门店地址
+ $content .= str_repeat('.', 32);
+ }
+
+ //底部内容
+ if (!empty($print_template[ 'bottom' ])) {
+ $content .= "" . $print_template[ 'bottom' ] . "";
+ }
+ $array[ 'content' ] = $content;
+
+ $res_data[] = $array;
+ }
+ return $res_data;
+
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/printer/event/PrinterTemplate.php b/src/addon/printer/event/PrinterTemplate.php
index 34364ced0..7e48ca82d 100644
--- a/src/addon/printer/event/PrinterTemplate.php
+++ b/src/addon/printer/event/PrinterTemplate.php
@@ -1,28 +1,20 @@
-fetch($model->getTemplateType()[ $params[ 'type' ] ][ $action_type ]);
- }
+fetch($model->getTemplateType()[ $params[ 'type' ] ][ $action_type ]);
+ }
}
\ No newline at end of file
diff --git a/src/addon/printer/event/PromotionType.php b/src/addon/printer/event/PromotionType.php
index 735e18d5e..73f2a361b 100644
--- a/src/addon/printer/event/PromotionType.php
+++ b/src/addon/printer/event/PromotionType.php
@@ -1,27 +1,19 @@
- "小票打印", "type" => "printer" ];
- }
+ "小票打印", "type" => "printer" ];
+ }
}
\ No newline at end of file
diff --git a/src/addon/printer/event/ShowPromotion.php b/src/addon/printer/event/ShowPromotion.php
index af1adb405..6bd7969c8 100644
--- a/src/addon/printer/event/ShowPromotion.php
+++ b/src/addon/printer/event/ShowPromotion.php
@@ -1,46 +1,38 @@
- [
- [
- //插件名称
- 'name' => 'printer',
- //店铺端展示分类 shop:营销活动 member:互动营销
- 'show_type' => 'tool',
- //展示主题
- 'title' => '小票打印',
- //展示介绍
- 'description' => '客户下单自动打印订单小票',
- //展示图标
- 'icon' => 'addon/printer/icon.png',
- //跳转链接
- 'url' => 'printer://shop/printer/lists',
- ]
- ]
-
- ];
- return $data;
- }
+ [
+ [
+ //插件名称
+ 'name' => 'printer',
+ //店铺端展示分类 shop:营销活动 member:互动营销
+ 'show_type' => 'tool',
+ //展示主题
+ 'title' => '小票打印',
+ //展示介绍
+ 'description' => '客户下单自动打印订单小票',
+ //展示图标
+ 'icon' => 'addon/printer/icon.png',
+ //跳转链接
+ 'url' => 'printer://shop/printer/lists',
+ ]
+ ]
+
+ ];
+ return $data;
+ }
}
\ No newline at end of file
diff --git a/src/addon/printer/event/UnInstall.php b/src/addon/printer/event/UnInstall.php
index 3b184937c..342ba138f 100644
--- a/src/addon/printer/event/UnInstall.php
+++ b/src/addon/printer/event/UnInstall.php
@@ -1,25 +1,17 @@
- '365','name' => '365'],
-// ['brand' => 'feie','name' => '飞鹅'],
- [ 'brand' => 'yilianyun', 'name' => '易联云' ],
- ];
-
- /**
- * 获取打印机品牌
- * @return array
- */
- public function getPrinterBrand()
- {
- return $this->brand;
- }
-
- /**
- * 添加小票打印
- * @param $data
- * @return array
- */
- public function addPrinter($data)
- {
-
- model('printer')->startTrans();
- try {
- $data[ 'create_time' ] = time();
- $res = model('printer')->add($data);
-
- //易联云
- if ($data[ 'printer_type' ] == 'cloud' && $data[ 'brand' ] == 'yilianyun') {
- $data[ 'printer_id' ] = $res;
- $result = $this->addPrinterYly($data);
-
- if ($result[ 'code' ] < 0) {
- model('printer')->rollback();
- return $result;
- }
- }
- model('printer')->commit();
- return $this->success($res);
- } catch (\Exception $e) {
- model('printer')->rollback();
- return $this->error('', '添加失败 ' . $e->getMessage());
- }
- }
-
- /**
- * 编辑小票打印
- * @param $data
- * @return array
- */
- public function editPrinter($data)
- {
- $data[ 'update_time' ] = time();
- $res = model('printer')->update($data, [ [ 'printer_id', '=', $data[ 'printer_id' ] ] ]);
- return $this->success($res);
- }
-
- /**
- * 删除
- * @param $condition
- * @return array
- */
- public function deletePrinter($condition)
- {
- model('printer')->startTrans();
- try {
- $printer_info = model('printer')->getInfo($condition, '*');
-
- $res = model('printer')->delete($condition);
- //易联云
- if ($printer_info[ 'printer_type' ] == 'cloud' && $printer_info[ 'brand' ] == 'yilianyun') {
-
- $result = $this->deletePrinterYly($printer_info);
- if ($result[ 'code' ] < 0) {
- model('printer')->rollback();
- return $result;
- }
- }
- model('printer')->commit();
- return $this->success($res);
- } catch (\Exception $e) {
- model('printer')->rollback();
- return $this->error('', $e->getMessage());
- }
- }
-
- /**
- * 获取小票打印信息
- * @param array $condition
- * @param string $field
- * @return array
- */
- public function getPrinterInfo($condition = [], $field = '*')
- {
- $res = model('printer')->getInfo($condition, $field);
- return $this->success($res);
- }
-
- /**
- * 获取小票打印列表
- * @param array $condition
- * @param string $field
- * @param string $order
- * @param null $limit
- * @return array
- */
- public function getPrinterList($condition = [], $field = '*', $order = '', $limit = null)
- {
- $list = model('printer')->getList($condition, $field, $order, '', '', '', $limit);
- return $this->success($list);
- }
-
- /**
- * 获取小票打印分页列表
- * @param array $condition
- * @param int $page
- * @param int $page_size
- * @param string $order
- * @param string $field
- * @return array
- */
- public function getPrinterPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
- {
- $list = model('printer')->pageList($condition, $field, $order, $page, $page_size);
- return $this->success($list);
- }
-
- /**************************************************** 打印机管理(第三方) *********************************************************/
-
- /******************** 易联云 start ************************/
-
- /**
- * 设置易联云配置
- * @param $data
- * @return array
- */
- public function setYlyTokenConfig($data)
- {
- $config = new Config();
- $res = $config->setConfig($data, '易联云小票打印token', 1, [ [ 'site_id', '=', $data[ 'site_id' ] ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'PRINTER_YLYTOKEN' ] ]);
- return $this->success($res);
- }
-
- /**
- * 获取易联云配置
- * @param $site_id
- * @return array
- */
- public function getYlyTokenConfig($site_id)
- {
- $config = new Config();
- $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'PRINTER_YLYTOKEN' ] ]);
- if (empty($res[ 'data' ][ 'value' ])) {
- $res[ 'data' ][ 'value' ] = [
- 'access_token' => '',
- 'end_time' => '0'//token有效期
- ];
- }
- return $res;
- }
-
- /**
- * 获取易联云token
- * @param $yly_config
- * @param $site_id
- * @param int $type
- * @return mixed
- */
- public function getYlyToken($yly_config, $site_id, $type = 0)
- {
- //token配置
- $config_data = $this->getYlyTokenConfig($site_id);
- $config = $config_data[ 'data' ][ 'value' ];
-
- if ($config[ 'end_time' ] == 0 || $config[ 'end_time' ] < time() || $type == 1) {
- $client = new YlyOauthClient($yly_config);
- $token = $client->getToken(); //若是开放型应用请传授权码code
- $access_token = $token->access_token; //调用API凭证AccessToken
-
- //更新token
- $expires_in = $token->expires_in;
- $end_time = time() + $expires_in;
- $token_data = [
- 'site_id' => $site_id,
- 'access_token' => $token->access_token,
- 'end_time' => $end_time
- ];
- $this->setYlyTokenConfig($token_data);
- } else {
- $access_token = $config[ 'access_token' ];
- }
- return $access_token;
- }
-
- /**
- * 添加易联云打印机授权
- * @param $param
- * @return array|mixed
- */
- public function addPrinterYly($param)
- {
- $yly_config = new YlyConfig($param[ 'open_id' ], $param[ 'apikey' ]);
-
- $access_token = $this->getYlyToken($yly_config, $param[ 'printer_id' ]);
-
- //添加打印机
- $printer = new PrinterService($access_token, $yly_config);
- $data = $printer->addPrinter($param[ 'printer_code' ], $param[ 'printer_key' ], '', '');
-
- if (isset($data->error) && $data->error == 0) {
- return $this->success();
- } else {
- return $data;
- }
- }
-
- /**
- * 删除易联云打印机授权
- * @param $param
- * @return array|mixed
- */
- public function deletePrinterYly($param)
- {
-
- $yly_config = new YlyConfig($param[ 'open_id' ], $param[ 'apikey' ]);
- $access_token = $this->getYlyToken($yly_config, $param[ 'printer_id' ]);
-
- //添加打印机
- $printer = new PrinterService($access_token, $yly_config);
- $data = $printer->deletePrinter($param[ 'printer_code' ]);
- if (isset($data->error) && $data->error == 0) {
- return $this->success();
- } else {
- return $data;
- }
- }
-
- /**
- * 重新获取易联云token
- * @param $site_id
- * @return mixed
- */
- public function refreshToken($printer_id, $site_id)
- {
- model('config')->startTrans();
- try {
- //token配置
- $printer_info = model('printer')->getInfo([ [ 'site_id', '=', $site_id ], [ 'printer_id', '=', $printer_id ] ], '*');
- $yly_config = new YlyConfig($printer_info[ 'open_id' ], $printer_info[ 'apikey' ]);
- $client = new YlyOauthClient($yly_config);
-
- $token = $client->getToken(); // 若是开放型应用请传授权码code
-
- //更新token
- $expires_in = $token->expires_in;
- $end_time = strtotime('+' . $expires_in / 86400 . 'day');
- $token_data = [
- 'site_id' => $printer_id,
- 'access_token' => $token->access_token,
- 'end_time' => $end_time
- ];
- $this->setYlyTokenConfig($token_data);
-
- model('config')->commit();
- return $this->success();
- } catch (\Exception $e) {
- model('config')->rollback();
- return $this->error('', $e->getMessage());
- }
-
- }
-
- /******************** 易联云 end ************************/
-
+ '365','name' => '365'],
+// ['brand' => 'feie','name' => '飞鹅'],
+ [ 'brand' => 'yilianyun', 'name' => '易联云' ],
+ ];
+
+ /**
+ * 获取打印机品牌
+ * @return array
+ */
+ public function getPrinterBrand()
+ {
+ return $this->brand;
+ }
+
+ /**
+ * 添加小票打印
+ * @param $data
+ * @return array
+ */
+ public function addPrinter($data)
+ {
+
+ model('printer')->startTrans();
+ try {
+ $data[ 'create_time' ] = time();
+ $res = model('printer')->add($data);
+
+ //易联云
+ if ($data[ 'printer_type' ] == 'cloud' && $data[ 'brand' ] == 'yilianyun') {
+ $data[ 'printer_id' ] = $res;
+ $result = $this->addPrinterYly($data);
+
+ if ($result[ 'code' ] < 0) {
+ model('printer')->rollback();
+ return $result;
+ }
+ }
+ model('printer')->commit();
+ return $this->success($res);
+ } catch (\Exception $e) {
+ model('printer')->rollback();
+ return $this->error('', '添加失败 ' . $e->getMessage());
+ }
+ }
+
+ /**
+ * 编辑小票打印
+ * @param $data
+ * @return array
+ */
+ public function editPrinter($data)
+ {
+ $data[ 'update_time' ] = time();
+ $res = model('printer')->update($data, [ [ 'printer_id', '=', $data[ 'printer_id' ] ] ]);
+ return $this->success($res);
+ }
+
+ /**
+ * 删除
+ * @param $condition
+ * @return array
+ */
+ public function deletePrinter($condition)
+ {
+ model('printer')->startTrans();
+ try {
+ $printer_info = model('printer')->getInfo($condition, '*');
+
+ $res = model('printer')->delete($condition);
+ //易联云
+ if ($printer_info[ 'printer_type' ] == 'cloud' && $printer_info[ 'brand' ] == 'yilianyun') {
+
+ $result = $this->deletePrinterYly($printer_info);
+ if ($result[ 'code' ] < 0) {
+ model('printer')->rollback();
+ return $result;
+ }
+ }
+ model('printer')->commit();
+ return $this->success($res);
+ } catch (\Exception $e) {
+ model('printer')->rollback();
+ return $this->error('', $e->getMessage());
+ }
+ }
+
+ /**
+ * 获取小票打印信息
+ * @param array $condition
+ * @param string $field
+ * @return array
+ */
+ public function getPrinterInfo($condition = [], $field = '*')
+ {
+ $res = model('printer')->getInfo($condition, $field);
+ return $this->success($res);
+ }
+
+ /**
+ * 获取小票打印列表
+ * @param array $condition
+ * @param string $field
+ * @param string $order
+ * @param null $limit
+ * @return array
+ */
+ public function getPrinterList($condition = [], $field = '*', $order = '', $limit = null)
+ {
+ $list = model('printer')->getList($condition, $field, $order, '', '', '', $limit);
+ return $this->success($list);
+ }
+
+ /**
+ * 获取小票打印分页列表
+ * @param array $condition
+ * @param int $page
+ * @param int $page_size
+ * @param string $order
+ * @param string $field
+ * @return array
+ */
+ public function getPrinterPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
+ {
+ $list = model('printer')->pageList($condition, $field, $order, $page, $page_size);
+ return $this->success($list);
+ }
+
+ /**************************************************** 打印机管理(第三方) *********************************************************/
+
+ /******************** 易联云 start ************************/
+
+ /**
+ * 设置易联云配置
+ * @param $data
+ * @return array
+ */
+ public function setYlyTokenConfig($data)
+ {
+ $config = new Config();
+ $res = $config->setConfig($data, '易联云小票打印token', 1, [ [ 'site_id', '=', $data[ 'site_id' ] ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'PRINTER_YLYTOKEN' ] ]);
+ return $this->success($res);
+ }
+
+ /**
+ * 获取易联云配置
+ * @param $site_id
+ * @return array
+ */
+ public function getYlyTokenConfig($site_id)
+ {
+ $config = new Config();
+ $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'PRINTER_YLYTOKEN' ] ]);
+ if (empty($res[ 'data' ][ 'value' ])) {
+ $res[ 'data' ][ 'value' ] = [
+ 'access_token' => '',
+ 'end_time' => '0'//token有效期
+ ];
+ }
+ return $res;
+ }
+
+ /**
+ * 获取易联云token
+ * @param $yly_config
+ * @param $site_id
+ * @param int $type
+ * @return mixed
+ */
+ public function getYlyToken($yly_config, $site_id, $type = 0)
+ {
+ //token配置
+ $config_data = $this->getYlyTokenConfig($site_id);
+ $config = $config_data[ 'data' ][ 'value' ];
+
+ if ($config[ 'end_time' ] == 0 || $config[ 'end_time' ] < time() || $type == 1) {
+ $client = new YlyOauthClient($yly_config);
+ $token = $client->getToken(); //若是开放型应用请传授权码code
+ $access_token = $token->access_token; //调用API凭证AccessToken
+
+ //更新token
+ $expires_in = $token->expires_in;
+ $end_time = time() + $expires_in;
+ $token_data = [
+ 'site_id' => $site_id,
+ 'access_token' => $token->access_token,
+ 'end_time' => $end_time
+ ];
+ $this->setYlyTokenConfig($token_data);
+ } else {
+ $access_token = $config[ 'access_token' ];
+ }
+ return $access_token;
+ }
+
+ /**
+ * 添加易联云打印机授权
+ * @param $param
+ * @return array|mixed
+ */
+ public function addPrinterYly($param)
+ {
+ $yly_config = new YlyConfig($param[ 'open_id' ], $param[ 'apikey' ]);
+
+ $access_token = $this->getYlyToken($yly_config, $param[ 'printer_id' ]);
+
+ //添加打印机
+ $printer = new PrinterService($access_token, $yly_config);
+ $data = $printer->addPrinter($param[ 'printer_code' ], $param[ 'printer_key' ], '', '');
+
+ if (isset($data->error) && $data->error == 0) {
+ return $this->success();
+ } else {
+ return $data;
+ }
+ }
+
+ /**
+ * 删除易联云打印机授权
+ * @param $param
+ * @return array|mixed
+ */
+ public function deletePrinterYly($param)
+ {
+
+ $yly_config = new YlyConfig($param[ 'open_id' ], $param[ 'apikey' ]);
+ $access_token = $this->getYlyToken($yly_config, $param[ 'printer_id' ]);
+
+ //添加打印机
+ $printer = new PrinterService($access_token, $yly_config);
+ $data = $printer->deletePrinter($param[ 'printer_code' ]);
+ if (isset($data->error) && $data->error == 0) {
+ return $this->success();
+ } else {
+ return $data;
+ }
+ }
+
+ /**
+ * 重新获取易联云token
+ * @param $site_id
+ * @return mixed
+ */
+ public function refreshToken($printer_id, $site_id)
+ {
+ model('config')->startTrans();
+ try {
+ //token配置
+ $printer_info = model('printer')->getInfo([ [ 'site_id', '=', $site_id ], [ 'printer_id', '=', $printer_id ] ], '*');
+ $yly_config = new YlyConfig($printer_info[ 'open_id' ], $printer_info[ 'apikey' ]);
+ $client = new YlyOauthClient($yly_config);
+
+ $token = $client->getToken(); // 若是开放型应用请传授权码code
+
+ //更新token
+ $expires_in = $token->expires_in;
+ $end_time = strtotime('+' . $expires_in / 86400 . 'day');
+ $token_data = [
+ 'site_id' => $printer_id,
+ 'access_token' => $token->access_token,
+ 'end_time' => $end_time
+ ];
+ $this->setYlyTokenConfig($token_data);
+
+ model('config')->commit();
+ return $this->success();
+ } catch (\Exception $e) {
+ model('config')->rollback();
+ return $this->error('', $e->getMessage());
+ }
+
+ }
+
+ /******************** 易联云 end ************************/
+
}
\ No newline at end of file
diff --git a/src/addon/printer/model/PrinterOrder.php b/src/addon/printer/model/PrinterOrder.php
index 658822169..c83d66d91 100644
--- a/src/addon/printer/model/PrinterOrder.php
+++ b/src/addon/printer/model/PrinterOrder.php
@@ -1,411 +1,403 @@
-error('', '没有可用的打印机');
- if (isset($items[ 'code' ]) && $items[ 'code' ] != 0) return $items;
- $printer_model = new Printer();
- foreach ($items as $k => $v) {
- $printer = $v[ 'printer_info' ] ?? [];
-
- switch ( $printer[ 'brand' ] ) {
- case '365'://365打印机
- break;
- case 'feie'://飞鹅打印机
- break;
- case 'yilianyun'://易联云打印机
- try {
- $config = new YlyConfig($printer[ 'open_id' ], $printer[ 'apikey' ]);
- $access_token = $printer_model->getYlyToken($config, $printer[ 'printer_id' ]);
- $machine_code = $v[ 'printer_code' ];//商户授权机器码
- $origin_id = $v[ 'origin_id' ]; //内部订单号(32位以内)
- $print = new PrintService($access_token, $config);
- $content = $v[ 'content' ];
- $print->index($machine_code, $content, $origin_id, $printer);
- } catch (\Exception $e) {
-// return $this->error('', $e->getMessage());
- }
- break;
- }
-
- }
-
- return $this->success($items);
- }
-
- /**
- * 订单打印
- */
- public function printOrder($data)
- {
-
-// //获取订单详情
-// $order_common_model = new OrderCommonModel();
-// $order_detail_result = $order_common_model->getOrderDetail($order_id);
-// $order_info = $order_detail_result['data'];
-//
-// if (empty($order_info)) {
-// return $this->success();
-// }
-//
-// //获取店铺信息
-// $shop_model = new Shop();
-// $shop = $shop_model->getShopInfo([['site_id', '=', $order_info['site_id']]]);
-// $shop_info = $shop['data'];
-//
-// //获取打印机列表
-// $print_model = new Printer();
-// $printer_data = $print_model->getPrinterList([['site_id', '=', $order_info['site_id']],['store_id','=',0]]);
-//
-// if($order_info['delivery_store_id'] == 0){
-// $store_printer_data['data'] = [];
-// }else{
-// $store_printer_data = $print_model->getPrinterList([['site_id', '=', $order_info['site_id']], ['order_type', 'like', '%,' . $order_info['order_type'] . ',%'],['store_id','=',$order_info['delivery_store_id']]]);
-// }
-// if (empty($printer_data['data']) && empty($store_printer_data['data'])) {
-// return $this->success();
-// }
-//
-// $printer_list = array_merge($printer_data['data'],$store_printer_data['data']);
-// foreach ($printer_list as $v) {
-//
-// switch ($v['brand']) {
-//
-// case '365'://365打印机
-//
-// break;
-// case 'feie'://飞鹅打印机
-//
-// break;
-// case 'yilianyun'://易联云打印机
-//
-// $this->Ylyprint($order_info, $v, $shop_info);
-// break;
-// }
-// }
-// return $this->success();
- }
-
- /**
- * 【测试】易联云打印
- * @param $order_info
- * @param $printer
- * @param $shop_info
- */
- public function Ylyprint($order_info, $printer, $shop_info)
- {
- //打印模板
- $print_template_model = new PrinterTemplate();
- $print_template = $print_template_model->getPrinterTemplateInfo([ [ 'template_id', '=', $printer[ 'template_id' ] ] ])['data'];
-
- $config = new YlyConfig($printer[ 'open_id' ], $printer[ 'apikey' ]);
- $printer_model = new Printer();
- $access_token = $printer_model->getYlyToken($config, $printer[ 'printer_id' ]);
- $machine_code = $printer[ 'printer_code' ]; //商户授权机器码
- $origin_id = $order_info[ 'order_no' ]; //内部订单号(32位以内)
-
- $site_name = ( new Site() )->getSiteInfo([ [ 'site_id', '=', $printer[ 'site_id' ] ] ], 'site_name')[ 'data' ][ 'site_name' ] ?? '';
-
- /**文本接口开始**/
- $print = new PrintService($access_token, $config);
- $content = "" . $printer[ 'print_num' ] . "";
- //小票名称
- if ($print_template[ 'title' ] != '') {
- $content .= "" . $print_template[ 'title' ] . "";
- $content .= str_repeat('.', 32);
- }
- //商城名称
- if ($print_template[ 'head' ] == 1) {
- $content .= "" . $site_name . "";
- $content .= str_repeat('.', 32);
- }
- if (!empty($order_info[ 'pay_time' ])) {
- $content .= "订单时间:" . date("Y-m-d H:i", $order_info[ 'pay_time' ]) . "\n";
- } else {
- $content .= "订单时间:" . date("Y-m-d H:i", time()) . "\n";
- }
- $content .= "订单编号:" . $order_info[ 'order_no' ] . "\n";
-
- $content .= str_repeat('.', 32);
- $content .= "";
- $content .= "| 商品名称 | | 数量 | 金额 |
";
- $content .= "
";
- $content .= str_repeat('.', 32);
- $content .= "";
- foreach ($order_info[ 'order_goods' ] as $goods) {
-
- $sku_name_list = $this->r_str_pad_1($goods[ 'sku_name' ], 7);
- foreach ($sku_name_list as $index => $value) {
- if ($index == 0) {
- $content .= "| " . $value . " | | x" . numberFormat($goods[ 'num' ]) . " | ¥" . $goods[ 'price' ] . " |
";
- } else {
- $content .= "| " . $value . " |
";
- }
- }
- }
- $content .= "
";
- $content .= str_repeat('.', 32);
- if ($order_info[ "goods_money" ] > 0) {
- $content .= "商品总额:¥" . $order_info[ "goods_money" ] . "\n";
- }
- if ($order_info[ "coupon_money" ] > 0) {
- $content .= "店铺优惠券:¥" . $order_info[ "coupon_money" ] . "\n";
- }
- if ($order_info[ "promotion_money" ] > 0) {
- $content .= "店铺优惠:¥" . $order_info[ "promotion_money" ] . "\n";
- }
- if ($order_info[ "point_money" ] > 0) {
- $content .= "积分抵扣:¥" . $order_info[ "point_money" ] . "\n";
- }
- if ($order_info[ "adjust_money" ] > 0) {
- $content .= "订单调价:¥" . $order_info[ "adjust_money" ] . "\n";
- }
- if ($order_info[ 'reduction' ] > 0) {
- $content .= "订单减免:¥" . $order_info[ "reduction" ] . "\n";
- }
- if ($order_info[ "balance_money" ] > 0) {
- $content .= "余额抵扣:¥" . $order_info[ "balance_money" ] . "\n";
- }
- if ($order_info[ "delivery_money" ] > 0) {
- $content .= "配送费用:¥" . $order_info[ "delivery_money" ] . "\n";
- }
- if ($order_info[ "invoice_money" ] > 0) {
- $content .= "发票费用:¥" . $order_info[ "invoice_money" ] . "\n";
- }
- if ($order_info[ "invoice_delivery_money" ] > 0) {
- $content .= "发票邮寄费用:¥" . $order_info[ "invoice_delivery_money" ] . "\n";
- }
- if ($order_info[ "goods_num" ] > 0) {
- $content .= "订单共" . numberFormat($order_info[ 'goods_num' ]) . "件商品,总计: ¥" . $order_info[ 'order_money' ] . " \n";
- }
- $content .= str_repeat('.', 32);
-
- /******************** 备注信息 **************************/
- //买家留言
- if ($print_template[ 'buy_notes' ] == 1) {
- $content .= "买家留言:" . $order_info[ "buyer_message" ] . "\n";
- $content .= str_repeat('.', 32);
- }
- //卖家留言
- if ($print_template[ 'seller_notes' ] == 1) {
- $content .= "卖家留言:" . $order_info[ "remark" ] . "\n";
- $content .= str_repeat('.', 32);
- }
-
- /******************** 买家信息 **************************/
- //买家姓名
- if ($print_template[ 'buy_name' ] == 1) {
- $content .= "" . $order_info[ "name" ] . "\n";
- }
- //联系方式
- if ($print_template[ 'buy_mobile' ] == 1) {
- $content .= "" . $order_info[ "mobile" ] . "\n";
- }
- //地址
- if ($print_template[ 'buy_address' ] == 1) {
- $content .= "" . $order_info[ 'full_address' ] . "-" . $order_info[ 'address' ] . "\n";
- }
- if ($print_template[ 'buy_name' ] == 1 || $print_template[ 'buy_mobile' ] == 1 || $print_template[ 'buy_address' ] == 1) {
- $content .= str_repeat('.', 32);
- }
- /******************** 商城信息 **************************/
- //联系方式
- if ($print_template[ 'shop_mobile' ] == 1) {
- $content .= "" . $shop_info[ "mobile" ] . "\n";
- }
- //地址
- if ($print_template[ 'shop_address' ] == 1) {
-
- $content .= "" . $shop_info[ 'province_name' ] . $shop_info[ 'city_name' ] . $shop_info[ 'district_name' ] . $shop_info[ 'address' ] . "\n";
- }
- if ($print_template[ 'shop_mobile' ] == 1 || $print_template[ 'shop_address' ] == 1) {
- $content .= str_repeat('.', 32);
- }
- //二维码
- if ($print_template[ 'shop_qrcode' ] == 1) {
- $content .= "" . $print_template[ 'qrcode_url' ] . "";
- $content .= str_repeat('.', 32);
- }
-
- /******************** 门店信息 **************************/
- if ($order_info[ 'delivery_store_id' ] > 0 && !empty($order_info[ 'delivery_store_name' ]) && !empty($order_info[ 'delivery_store_info' ])) {
- $store_info = json_decode($order_info[ 'delivery_store_info' ], true);
-
- $content .= "" . $order_info[ "delivery_store_name" ] . "\n";//门店名称
- $content .= "" . $store_info[ "telphone" ] . "\n";//门店电话
- $content .= "" . $store_info[ "full_address" ] . "\n";//门店地址
- $content .= str_repeat('.', 32);
- }
-
- //底部内容
- if (!empty($print_template[ 'bottom' ])) {
- $content .= "" . $print_template[ 'bottom' ] . "";
- }
-
- try {
- $print->index($machine_code, $content, $origin_id);
- } catch (\Exception $e) {
- echo $e->getMessage();
- }
- }
-
- /**
- * 补齐空格,每n个中文字符长度为一个数组元素
- * @param $input
- * @param int $n
- * @return array
- */
- public function r_str_pad_1($input, $n = 7)
- {
- $string = "";
- $count = 0;
- $c_count = 0;
- $arr = array ();
- for ($i = 0; $i < mb_strlen($input, 'UTF-8'); $i++) {
- $char = mb_substr($input, $i, 1, 'UTF-8');
- $string .= $char;
- if (strlen($char) == 3) {
- $count += 2;
- $c_count++;
- } else {
- $count += 1;
- }
- if ($count >= $n * 2) {
- $arr[] = $string;
- $string = '';
- $count = 0;
- $c_count = 0;
- }
- }
- if ($count < $n * 2) {
- $string = str_pad($string, $n * 2 + $c_count);
- $arr[] = $string;
- }
- return $arr;
- }
-
- /************************************************ 正式打印 end ******************************************************************/
-
-
- /************************************************ 测试打印 start ******************************************************************/
-
- /**
- * 测试打印
- * @param $printer_id
- * @param $site_id
- * @return array
- */
- public function testPrint($printer_id, $site_id)
- {
- //获取打印机列表
- $printer_info = model('printer')->getInfo([ [ 'site_id', '=', $site_id ], [ 'printer_id', '=', $printer_id ] ]);
- if (empty($printer_info)) {
- return $this->success();
- }
-
- switch ( $printer_info[ 'brand' ] ) {
- case '365':
- // 365打印机
- break;
- case 'feie':
- // 飞鹅打印机
- break;
- case 'yilianyun':
- // 易联云打印机
- $res = $this->testYlyprint($printer_info);
- break;
- }
- return $res;
- }
-
- /**
- * 测试打印
- * @param $printer
- * @return array
- */
- public function testYlyprint($printer)
- {
- $config = new YlyConfig($printer[ 'open_id' ], $printer[ 'apikey' ]);
-
- $printer_model = new Printer();
- $access_token = $printer_model->getYlyToken($config, $printer[ 'printer_id' ]);
- $machine_code = $printer[ 'printer_code' ]; //商户授权机器码
- $origin_id = date('YmdHis') . rand(1, 999); //内部订单号(32位以内)
-
- /**文本接口开始**/
- $print = new PrintService($access_token, $config);
-
- $content = "" . $printer[ 'print_num' ] . "";
-
- $content .= "小票名称";
- $content .= str_repeat('.', 32);
- $content .= "商城名称";
- $content .= str_repeat('.', 32);
-
- $content .= "订单时间:" . date("Y-m-d H:i") . "\n";
- $content .= "订单编号:" . $origin_id . "\n";
-
- $content .= str_repeat('.', 32);
- $content .= "";
- $content .= "| 商品名称 | | 数量 | 金额 |
";
- $content .= "
";
- $content .= str_repeat('.', 32);
-
- $content .= "";
- $content .= "| 烤土豆(超级辣) | | x3 | 5 |
";
- $content .= "| 烤豆干(超级辣) | | x2 | 10 |
";
- $content .= "| 烤鸡翅(超级辣) | | x3 | 15 |
";
- $content .= "
";
- $content .= str_repeat('.', 32);
-
- $content .= "商品总额:¥30 \n";
- $content .= "订单共8件商品,总计: ¥30 \n";
- $content .= str_repeat('.', 32);
-
- /******************** 备注信息 **************************/
- //买家留言
-
- $content .= "买家留言:微辣,多放孜然\n";
- $content .= str_repeat('.', 32);
-
- $content .= "谢谢惠顾,欢迎下次光临";
-
- try {
-
- $res = $print->index($machine_code, $content, $origin_id);
- if ($res->error == 0) {
- return $this->success();
- } else {
- return $this->error('', $res->error_description);
- }
- } catch (\Exception $e) {
- return $this->error('', $e->getMessage());
- }
- }
-
+error('', '没有可用的打印机');
+ if (isset($items[ 'code' ]) && $items[ 'code' ] != 0) return $items;
+ $printer_model = new Printer();
+ foreach ($items as $k => $v) {
+ $printer = $v[ 'printer_info' ] ?? [];
+
+ switch ( $printer[ 'brand' ] ) {
+ case '365'://365打印机
+ break;
+ case 'feie'://飞鹅打印机
+ break;
+ case 'yilianyun'://易联云打印机
+ try {
+ $config = new YlyConfig($printer[ 'open_id' ], $printer[ 'apikey' ]);
+ $access_token = $printer_model->getYlyToken($config, $printer[ 'printer_id' ]);
+ $machine_code = $v[ 'printer_code' ];//商户授权机器码
+ $origin_id = $v[ 'origin_id' ]; //内部订单号(32位以内)
+ $print = new PrintService($access_token, $config);
+ $content = $v[ 'content' ];
+ $print->index($machine_code, $content, $origin_id, $printer);
+ } catch (\Exception $e) {
+// return $this->error('', $e->getMessage());
+ }
+ break;
+ }
+
+ }
+
+ return $this->success($items);
+ }
+
+ /**
+ * 订单打印
+ */
+ public function printOrder($data)
+ {
+
+// //获取订单详情
+// $order_common_model = new OrderCommonModel();
+// $order_detail_result = $order_common_model->getOrderDetail($order_id);
+// $order_info = $order_detail_result['data'];
+//
+// if (empty($order_info)) {
+// return $this->success();
+// }
+//
+// //获取店铺信息
+// $shop_model = new Shop();
+// $shop = $shop_model->getShopInfo([['site_id', '=', $order_info['site_id']]]);
+// $shop_info = $shop['data'];
+//
+// //获取打印机列表
+// $print_model = new Printer();
+// $printer_data = $print_model->getPrinterList([['site_id', '=', $order_info['site_id']],['store_id','=',0]]);
+//
+// if($order_info['delivery_store_id'] == 0){
+// $store_printer_data['data'] = [];
+// }else{
+// $store_printer_data = $print_model->getPrinterList([['site_id', '=', $order_info['site_id']], ['order_type', 'like', '%,' . $order_info['order_type'] . ',%'],['store_id','=',$order_info['delivery_store_id']]]);
+// }
+// if (empty($printer_data['data']) && empty($store_printer_data['data'])) {
+// return $this->success();
+// }
+//
+// $printer_list = array_merge($printer_data['data'],$store_printer_data['data']);
+// foreach ($printer_list as $v) {
+//
+// switch ($v['brand']) {
+//
+// case '365'://365打印机
+//
+// break;
+// case 'feie'://飞鹅打印机
+//
+// break;
+// case 'yilianyun'://易联云打印机
+//
+// $this->Ylyprint($order_info, $v, $shop_info);
+// break;
+// }
+// }
+// return $this->success();
+ }
+
+ /**
+ * 【测试】易联云打印
+ * @param $order_info
+ * @param $printer
+ * @param $shop_info
+ */
+ public function Ylyprint($order_info, $printer, $shop_info)
+ {
+ //打印模板
+ $print_template_model = new PrinterTemplate();
+ $print_template = $print_template_model->getPrinterTemplateInfo([ [ 'template_id', '=', $printer[ 'template_id' ] ] ])['data'];
+
+ $config = new YlyConfig($printer[ 'open_id' ], $printer[ 'apikey' ]);
+ $printer_model = new Printer();
+ $access_token = $printer_model->getYlyToken($config, $printer[ 'printer_id' ]);
+ $machine_code = $printer[ 'printer_code' ]; //商户授权机器码
+ $origin_id = $order_info[ 'order_no' ]; //内部订单号(32位以内)
+
+ $site_name = ( new Site() )->getSiteInfo([ [ 'site_id', '=', $printer[ 'site_id' ] ] ], 'site_name')[ 'data' ][ 'site_name' ] ?? '';
+
+ /**文本接口开始**/
+ $print = new PrintService($access_token, $config);
+ $content = "" . $printer[ 'print_num' ] . "";
+ //小票名称
+ if ($print_template[ 'title' ] != '') {
+ $content .= "" . $print_template[ 'title' ] . "";
+ $content .= str_repeat('.', 32);
+ }
+ //商城名称
+ if ($print_template[ 'head' ] == 1) {
+ $content .= "" . $site_name . "";
+ $content .= str_repeat('.', 32);
+ }
+ if (!empty($order_info[ 'pay_time' ])) {
+ $content .= "订单时间:" . date("Y-m-d H:i", $order_info[ 'pay_time' ]) . "\n";
+ } else {
+ $content .= "订单时间:" . date("Y-m-d H:i", time()) . "\n";
+ }
+ $content .= "订单编号:" . $order_info[ 'order_no' ] . "\n";
+
+ $content .= str_repeat('.', 32);
+ $content .= "";
+ $content .= "| 商品名称 | | 数量 | 金额 |
";
+ $content .= "
";
+ $content .= str_repeat('.', 32);
+ $content .= "";
+ foreach ($order_info[ 'order_goods' ] as $goods) {
+
+ $sku_name_list = $this->r_str_pad_1($goods[ 'sku_name' ], 7);
+ foreach ($sku_name_list as $index => $value) {
+ if ($index == 0) {
+ $content .= "| " . $value . " | | x" . numberFormat($goods[ 'num' ]) . " | ¥" . $goods[ 'price' ] . " |
";
+ } else {
+ $content .= "| " . $value . " |
";
+ }
+ }
+ }
+ $content .= "
";
+ $content .= str_repeat('.', 32);
+ if ($order_info[ "goods_money" ] > 0) {
+ $content .= "商品总额:¥" . $order_info[ "goods_money" ] . "\n";
+ }
+ if ($order_info[ "coupon_money" ] > 0) {
+ $content .= "店铺优惠券:¥" . $order_info[ "coupon_money" ] . "\n";
+ }
+ if ($order_info[ "promotion_money" ] > 0) {
+ $content .= "店铺优惠:¥" . $order_info[ "promotion_money" ] . "\n";
+ }
+ if ($order_info[ "point_money" ] > 0) {
+ $content .= "积分抵扣:¥" . $order_info[ "point_money" ] . "\n";
+ }
+ if ($order_info[ "adjust_money" ] > 0) {
+ $content .= "订单调价:¥" . $order_info[ "adjust_money" ] . "\n";
+ }
+ if ($order_info[ 'reduction' ] > 0) {
+ $content .= "订单减免:¥" . $order_info[ "reduction" ] . "\n";
+ }
+ if ($order_info[ "balance_money" ] > 0) {
+ $content .= "余额抵扣:¥" . $order_info[ "balance_money" ] . "\n";
+ }
+ if ($order_info[ "delivery_money" ] > 0) {
+ $content .= "配送费用:¥" . $order_info[ "delivery_money" ] . "\n";
+ }
+ if ($order_info[ "invoice_money" ] > 0) {
+ $content .= "发票费用:¥" . $order_info[ "invoice_money" ] . "\n";
+ }
+ if ($order_info[ "invoice_delivery_money" ] > 0) {
+ $content .= "发票邮寄费用:¥" . $order_info[ "invoice_delivery_money" ] . "\n";
+ }
+ if ($order_info[ "goods_num" ] > 0) {
+ $content .= "订单共" . numberFormat($order_info[ 'goods_num' ]) . "件商品,总计: ¥" . $order_info[ 'order_money' ] . " \n";
+ }
+ $content .= str_repeat('.', 32);
+
+ /******************** 备注信息 **************************/
+ //买家留言
+ if ($print_template[ 'buy_notes' ] == 1) {
+ $content .= "买家留言:" . $order_info[ "buyer_message" ] . "\n";
+ $content .= str_repeat('.', 32);
+ }
+ //卖家留言
+ if ($print_template[ 'seller_notes' ] == 1) {
+ $content .= "卖家留言:" . $order_info[ "remark" ] . "\n";
+ $content .= str_repeat('.', 32);
+ }
+
+ /******************** 买家信息 **************************/
+ //买家姓名
+ if ($print_template[ 'buy_name' ] == 1) {
+ $content .= "" . $order_info[ "name" ] . "\n";
+ }
+ //联系方式
+ if ($print_template[ 'buy_mobile' ] == 1) {
+ $content .= "" . $order_info[ "mobile" ] . "\n";
+ }
+ //地址
+ if ($print_template[ 'buy_address' ] == 1) {
+ $content .= "" . $order_info[ 'full_address' ] . "-" . $order_info[ 'address' ] . "\n";
+ }
+ if ($print_template[ 'buy_name' ] == 1 || $print_template[ 'buy_mobile' ] == 1 || $print_template[ 'buy_address' ] == 1) {
+ $content .= str_repeat('.', 32);
+ }
+ /******************** 商城信息 **************************/
+ //联系方式
+ if ($print_template[ 'shop_mobile' ] == 1) {
+ $content .= "" . $shop_info[ "mobile" ] . "\n";
+ }
+ //地址
+ if ($print_template[ 'shop_address' ] == 1) {
+
+ $content .= "" . $shop_info[ 'province_name' ] . $shop_info[ 'city_name' ] . $shop_info[ 'district_name' ] . $shop_info[ 'address' ] . "\n";
+ }
+ if ($print_template[ 'shop_mobile' ] == 1 || $print_template[ 'shop_address' ] == 1) {
+ $content .= str_repeat('.', 32);
+ }
+ //二维码
+ if ($print_template[ 'shop_qrcode' ] == 1) {
+ $content .= "" . $print_template[ 'qrcode_url' ] . "";
+ $content .= str_repeat('.', 32);
+ }
+
+ /******************** 门店信息 **************************/
+ if ($order_info[ 'delivery_store_id' ] > 0 && !empty($order_info[ 'delivery_store_name' ]) && !empty($order_info[ 'delivery_store_info' ])) {
+ $store_info = json_decode($order_info[ 'delivery_store_info' ], true);
+
+ $content .= "" . $order_info[ "delivery_store_name" ] . "\n";//门店名称
+ $content .= "" . $store_info[ "telphone" ] . "\n";//门店电话
+ $content .= "" . $store_info[ "full_address" ] . "\n";//门店地址
+ $content .= str_repeat('.', 32);
+ }
+
+ //底部内容
+ if (!empty($print_template[ 'bottom' ])) {
+ $content .= "" . $print_template[ 'bottom' ] . "";
+ }
+
+ try {
+ $print->index($machine_code, $content, $origin_id);
+ } catch (\Exception $e) {
+ echo $e->getMessage();
+ }
+ }
+
+ /**
+ * 补齐空格,每n个中文字符长度为一个数组元素
+ * @param $input
+ * @param int $n
+ * @return array
+ */
+ public function r_str_pad_1($input, $n = 7)
+ {
+ $string = "";
+ $count = 0;
+ $c_count = 0;
+ $arr = array ();
+ for ($i = 0; $i < mb_strlen($input, 'UTF-8'); $i++) {
+ $char = mb_substr($input, $i, 1, 'UTF-8');
+ $string .= $char;
+ if (strlen($char) == 3) {
+ $count += 2;
+ $c_count++;
+ } else {
+ $count += 1;
+ }
+ if ($count >= $n * 2) {
+ $arr[] = $string;
+ $string = '';
+ $count = 0;
+ $c_count = 0;
+ }
+ }
+ if ($count < $n * 2) {
+ $string = str_pad($string, $n * 2 + $c_count);
+ $arr[] = $string;
+ }
+ return $arr;
+ }
+
+ /************************************************ 正式打印 end ******************************************************************/
+
+
+ /************************************************ 测试打印 start ******************************************************************/
+
+ /**
+ * 测试打印
+ * @param $printer_id
+ * @param $site_id
+ * @return array
+ */
+ public function testPrint($printer_id, $site_id)
+ {
+ //获取打印机列表
+ $printer_info = model('printer')->getInfo([ [ 'site_id', '=', $site_id ], [ 'printer_id', '=', $printer_id ] ]);
+ if (empty($printer_info)) {
+ return $this->success();
+ }
+
+ switch ( $printer_info[ 'brand' ] ) {
+ case '365':
+ // 365打印机
+ break;
+ case 'feie':
+ // 飞鹅打印机
+ break;
+ case 'yilianyun':
+ // 易联云打印机
+ $res = $this->testYlyprint($printer_info);
+ break;
+ }
+ return $res;
+ }
+
+ /**
+ * 测试打印
+ * @param $printer
+ * @return array
+ */
+ public function testYlyprint($printer)
+ {
+ $config = new YlyConfig($printer[ 'open_id' ], $printer[ 'apikey' ]);
+
+ $printer_model = new Printer();
+ $access_token = $printer_model->getYlyToken($config, $printer[ 'printer_id' ]);
+ $machine_code = $printer[ 'printer_code' ]; //商户授权机器码
+ $origin_id = date('YmdHis') . rand(1, 999); //内部订单号(32位以内)
+
+ /**文本接口开始**/
+ $print = new PrintService($access_token, $config);
+
+ $content = "" . $printer[ 'print_num' ] . "";
+
+ $content .= "小票名称";
+ $content .= str_repeat('.', 32);
+ $content .= "商城名称";
+ $content .= str_repeat('.', 32);
+
+ $content .= "订单时间:" . date("Y-m-d H:i") . "\n";
+ $content .= "订单编号:" . $origin_id . "\n";
+
+ $content .= str_repeat('.', 32);
+ $content .= "";
+ $content .= "| 商品名称 | | 数量 | 金额 |
";
+ $content .= "
";
+ $content .= str_repeat('.', 32);
+
+ $content .= "";
+ $content .= "| 烤土豆(超级辣) | | x3 | 5 |
";
+ $content .= "| 烤豆干(超级辣) | | x2 | 10 |
";
+ $content .= "| 烤鸡翅(超级辣) | | x3 | 15 |
";
+ $content .= "
";
+ $content .= str_repeat('.', 32);
+
+ $content .= "商品总额:¥30 \n";
+ $content .= "订单共8件商品,总计: ¥30 \n";
+ $content .= str_repeat('.', 32);
+
+ /******************** 备注信息 **************************/
+ //买家留言
+
+ $content .= "买家留言:微辣,多放孜然\n";
+ $content .= str_repeat('.', 32);
+
+ $content .= "谢谢惠顾,欢迎下次光临";
+
+ try {
+
+ $res = $print->index($machine_code, $content, $origin_id);
+ if ($res->error == 0) {
+ return $this->success();
+ } else {
+ return $this->error('', $res->error_description);
+ }
+ } catch (\Exception $e) {
+ return $this->error('', $e->getMessage());
+ }
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/printer/model/PrinterTemplate.php b/src/addon/printer/model/PrinterTemplate.php
index 4148259c5..11b6f7758 100644
--- a/src/addon/printer/model/PrinterTemplate.php
+++ b/src/addon/printer/model/PrinterTemplate.php
@@ -1,114 +1,106 @@
- [
- 'type' => 'goodsorder',
- 'type_name' => '商品订单',
- 'edit' => 'addon/printer/shop/view/template/goodsorder_template.html',
- 'add' => 'addon/printer/shop/view/template/goodsorder_template.html',
- ]
- ];
-
- public function getTemplateType()
- {
- $type = $this->type;
- $other_type = event('PrinterTemplateType', []);
- foreach ($other_type as $k => $v) {
- foreach ($v as $val) {
- $type[ $val[ 'type' ] ] = $val;
- }
- }
- return $type;
- }
-
- /**
- * 添加打印模板
- * @param $data
- * @return array
- */
- public function addPrinterTemplate($data)
- {
- $data[ 'create_time' ] = time();
- $res = model('printer_template')->add($data);
- return $this->success($res);
- }
-
- /**
- * 编辑打印模板
- * @param $data
- * @return array
- */
- public function editPrinterTemplate($data)
- {
- $data[ 'update_time' ] = time();
- $res = model('printer_template')->update($data, [ [ 'template_id', '=', $data[ 'template_id' ] ] ]);
- return $this->success($res);
- }
-
- /**
- * 删除
- * @param $condition
- * @return array
- */
- public function deletePrinterTemplate($condition)
- {
- $res = model('printer_template')->delete($condition);
- return $this->success($res);
- }
-
- /**
- * 获取打印模板信息
- * @param array $condition
- * @param string $field
- * @return array
- */
- public function getPrinterTemplateInfo($condition = [], $field = '*')
- {
- $res = model('printer_template')->getInfo($condition, $field);
- return $this->success($res);
- }
-
- /**
- * 获取打印模板列表
- * @param array $condition
- * @param string $field
- * @param string $order
- * @param null $limit
- * @return array
- */
- public function getPrinterTemplateList($condition = [], $field = '*', $order = '', $limit = null)
- {
- $list = model('printer_template')->getList($condition, $field, $order, '', '', '', $limit);
- return $this->success($list);
- }
-
- /**
- * 获取打印模板分页列表
- * @param array $condition
- * @param int $page
- * @param int $page_size
- * @param string $order
- * @param string $field
- * @return array
- */
- public function getPrinterTemplatePageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
- {
- $list = model('printer_template')->pageList($condition, $field, $order, $page, $page_size);
- return $this->success($list);
- }
-
+ [
+ 'type' => 'goodsorder',
+ 'type_name' => '商品订单',
+ 'edit' => 'addon/printer/shop/view/template/goodsorder_template.html',
+ 'add' => 'addon/printer/shop/view/template/goodsorder_template.html',
+ ]
+ ];
+
+ public function getTemplateType()
+ {
+ $type = $this->type;
+ $other_type = event('PrinterTemplateType', []);
+ foreach ($other_type as $k => $v) {
+ foreach ($v as $val) {
+ $type[ $val[ 'type' ] ] = $val;
+ }
+ }
+ return $type;
+ }
+
+ /**
+ * 添加打印模板
+ * @param $data
+ * @return array
+ */
+ public function addPrinterTemplate($data)
+ {
+ $data[ 'create_time' ] = time();
+ $res = model('printer_template')->add($data);
+ return $this->success($res);
+ }
+
+ /**
+ * 编辑打印模板
+ * @param $data
+ * @return array
+ */
+ public function editPrinterTemplate($data)
+ {
+ $data[ 'update_time' ] = time();
+ $res = model('printer_template')->update($data, [ [ 'template_id', '=', $data[ 'template_id' ] ] ]);
+ return $this->success($res);
+ }
+
+ /**
+ * 删除
+ * @param $condition
+ * @return array
+ */
+ public function deletePrinterTemplate($condition)
+ {
+ $res = model('printer_template')->delete($condition);
+ return $this->success($res);
+ }
+
+ /**
+ * 获取打印模板信息
+ * @param array $condition
+ * @param string $field
+ * @return array
+ */
+ public function getPrinterTemplateInfo($condition = [], $field = '*')
+ {
+ $res = model('printer_template')->getInfo($condition, $field);
+ return $this->success($res);
+ }
+
+ /**
+ * 获取打印模板列表
+ * @param array $condition
+ * @param string $field
+ * @param string $order
+ * @param null $limit
+ * @return array
+ */
+ public function getPrinterTemplateList($condition = [], $field = '*', $order = '', $limit = null)
+ {
+ $list = model('printer_template')->getList($condition, $field, $order, '', '', '', $limit);
+ return $this->success($list);
+ }
+
+ /**
+ * 获取打印模板分页列表
+ * @param array $condition
+ * @param int $page
+ * @param int $page_size
+ * @param string $order
+ * @param string $field
+ * @return array
+ */
+ public function getPrinterTemplatePageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
+ {
+ $list = model('printer_template')->pageList($condition, $field, $order, $page, $page_size);
+ return $this->success($list);
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/printer/shop/controller/BaseController.php b/src/addon/printer/shop/controller/BaseController.php
index bb44f2522..7c4ffeed5 100644
--- a/src/addon/printer/shop/controller/BaseController.php
+++ b/src/addon/printer/shop/controller/BaseController.php
@@ -1,27 +1,19 @@
- __ROOT__ . '/addon/printer/shop/view/public/css',
- 'SHOP_ADDON_IMG' => __ROOT__ . '/addon/printer/shop/view/public/img',
- 'SHOP_ADDON_JS' => __ROOT__ . '/addon/printer/shop/view/public/js',
- ]);
- return parent::fetch($template, $replace, $config);
- }
+ __ROOT__ . '/addon/printer/shop/view/public/css',
+ 'SHOP_ADDON_IMG' => __ROOT__ . '/addon/printer/shop/view/public/img',
+ 'SHOP_ADDON_JS' => __ROOT__ . '/addon/printer/shop/view/public/js',
+ ]);
+ return parent::fetch($template, $replace, $config);
+ }
}
\ No newline at end of file
diff --git a/src/addon/printer/shop/controller/Printer.php b/src/addon/printer/shop/controller/Printer.php
index 665857d5d..a371420de 100644
--- a/src/addon/printer/shop/controller/Printer.php
+++ b/src/addon/printer/shop/controller/Printer.php
@@ -1,269 +1,261 @@
-isJson()) {
- $condition[] = [ 'site_id', '=', $this->site_id ];
- $page = input('page', 1);
- $page_size = input('page_size', PAGE_LIST_ROWS);
- $list = $model->getPrinterPageList($condition, $page, $page_size, 'printer_id desc');
- return $list;
- }
- return $this->fetch("printer/lists");
- }
-
- /**
- * 添加小票打印
- */
- public function add()
- {
- $model = new PrinterModel();
- if (request()->isJson()) {
- $data = [
- 'site_id' => $this->site_id,
- 'printer_name' => input('printer_name', ''),
- 'brand' => input('brand', ''),
- 'printer_code' => input('printer_code', ''),
- 'printer_key' => input('printer_key', ''),
- 'open_id' => input('open_id', ''),
- 'apikey' => input('apikey', ''),
- 'store_id' => input('store_id', ''),
- 'printer_type' => input('printer_type', ''),
-
- //订单
- 'order_pay_open' => input('order_pay_open', 0),
- 'order_pay_template_id' => input('order_pay_template_id', 0),
- 'order_pay_print_num' => input('order_pay_print_num', 1),
- 'order_pay_order_type' => input('order_pay_order_type', ''),
-
- 'take_delivery_open' => input('take_delivery_open', 0),
- 'take_delivery_template_id' => input('take_delivery_template_id', 0),
- 'take_delivery_print_num' => input('take_delivery_print_num', 1),
- 'take_delivery_order_type' => input('take_delivery_order_type', ''),
-
- 'manual_open' => input('manual_open', 0),
- 'template_id' => input('template_id', 0),
- 'print_num' => input('print_num', 1),
-
- //充值
- 'recharge_open' => input('recharge_open', 0),
- 'recharge_template_id' => input('recharge_template_id', 0),
- 'recharge_print_num' => input('recharge_print_num', 1),
-
- 'change_shifts_open' => input('change_shifts_open', 0),
- 'change_shifts_template_id' => input('change_shifts_template_id', 0),
- 'change_shifts_print_num' => input('change_shifts_print_num', 1),
-
- 'host' => input('host', ''),
- 'ip' => input('ip', ''),
- 'port' => input('port', ''),
- 'print_width' => input('print_width', '58mm')
-
- ];
- if ($data[ 'order_pay_order_type' ]) $data[ 'order_pay_order_type' ] = ',' . $data[ 'order_pay_order_type' ] . ',';
- if ($data[ 'take_delivery_order_type' ]) $data[ 'take_delivery_order_type' ] = ',' . $data[ 'take_delivery_order_type' ] . ',';
- return $model->addPrinter($data);
-
- } else {
- //模板列表
- $template_model = new PrinterTemplate();
- $condition = [
- [ 'site_id', '=', $this->site_id ],
- ];
- $template_list = $template_model->getPrinterTemplateList($condition, 'template_id,template_name,type', 'template_id desc');
- $this->assign('template_list', $template_list[ 'data' ]);
-
- //打印机品牌
- $brand = $model->getPrinterBrand();
- $this->assign('brand', $brand);
-
- //订单类型
- $order_common_model = new OrderCommonModel();
- $order_type_list = $order_common_model->getOrderTypeStatusList();
- unset($order_type_list[ 'all' ]);
- $this->assign("order_type_list", $order_type_list);
-
- $is_exit_store = addon_is_exit('store');
- if ($is_exit_store == 1) {
- $store_model = new Store();
- $store_field = 'store_id,store_name';
- $store_list = $store_model->getStoreList([ [ 'site_id', '=', $this->site_id ] ], $store_field);
- $this->assign('store_list', $store_list[ 'data' ]);
- }
- $this->assign('is_exit_store', $is_exit_store);
- return $this->fetch("printer/add");
- }
- }
-
- /**
- * 编辑小票打印
- */
- public function edit()
- {
- $model = new PrinterModel();
- $printer_id = input('printer_id', 0);
- if (request()->isJson()) {
- $data = [
- 'printer_id' => $printer_id,
-
- 'site_id' => $this->site_id,
- 'printer_name' => input('printer_name', ''),
- 'brand' => input('brand', ''),
- 'printer_code' => input('printer_code', ''),
- 'printer_key' => input('printer_key', ''),
- 'open_id' => input('open_id', ''),
- 'apikey' => input('apikey', ''),
- 'store_id' => input('store_id', ''),
- 'printer_type' => input('printer_type', ''),
-
- //订单
- 'order_pay_open' => input('order_pay_open', 0),
- 'order_pay_template_id' => input('order_pay_template_id', 0),
- 'order_pay_print_num' => input('order_pay_print_num', 1),
- 'order_pay_order_type' => input('order_pay_order_type', ''),
-
- 'take_delivery_open' => input('take_delivery_open', 0),
- 'take_delivery_template_id' => input('take_delivery_template_id', 0),
- 'take_delivery_print_num' => input('take_delivery_print_num', 1),
- 'take_delivery_order_type' => input('take_delivery_order_type', ''),
-
- 'manual_open' => input('manual_open', 0),
- 'template_id' => input('template_id', 0),
- 'print_num' => input('print_num', 1),
-
- //充值
- 'recharge_open' => input('recharge_open', 0),
- 'recharge_template_id' => input('recharge_template_id', 0),
- 'recharge_print_num' => input('recharge_print_num', 1),
-
- 'change_shifts_open' => input('change_shifts_open', 0),
- 'change_shifts_template_id' => input('change_shifts_template_id', 0),
- 'change_shifts_print_num' => input('change_shifts_print_num', 1),
-
- 'host' => input('host', ''),
- 'ip' => input('ip', ''),
- 'port' => input('port', ''),
- 'print_width' => input('print_width', '58mm')
- ];
-
- if ($data[ 'order_pay_order_type' ]) $data[ 'order_pay_order_type' ] = ',' . $data[ 'order_pay_order_type' ] . ',';
- if ($data[ 'take_delivery_order_type' ]) $data[ 'take_delivery_order_type' ] = ',' . $data[ 'take_delivery_order_type' ] . ',';
-
- return $model->editPrinter($data);
- } else {
-
- $info = $model->getPrinterInfo([ [ 'printer_id', '=', $printer_id ], [ 'site_id', '=', $this->site_id ] ]);
- $info[ 'data' ][ 'take_delivery_order_type' ] = explode(',', $info[ 'data' ][ 'take_delivery_order_type' ]);
- $info[ 'data' ][ 'order_pay_order_type' ] = explode(',', $info[ 'data' ][ 'order_pay_order_type' ]);
- $this->assign('printer_info', $info[ 'data' ]);
-
- //模板列表
- $template_model = new PrinterTemplate();
- $condition = [
- [ 'site_id', '=', $this->site_id ],
- ];
- $template_list = $template_model->getPrinterTemplateList($condition, 'template_id,template_name,type', 'template_id desc');
- $this->assign('template_list', $template_list[ 'data' ]);
-
- //打印机品牌
- $brand = $model->getPrinterBrand();
- $this->assign('brand', $brand);
-
- //订单类型
- $order_common_model = new OrderCommonModel();
- $order_type_list = $order_common_model->getOrderTypeStatusList();
- unset($order_type_list[ 'all' ]);
- $this->assign("order_type_list", $order_type_list);
-
- //是否存在门店
- $is_exit_store = addon_is_exit('store');
- if ($is_exit_store == 1) {
- $store_model = new Store();
- $store_field = 'store_id,store_name';
- $store_list = $store_model->getStoreList([ [ 'site_id', '=', $this->site_id ] ], $store_field);
- $this->assign('store_list', $store_list[ 'data' ]);
- }
- $this->assign('is_exit_store', $is_exit_store);
- return $this->fetch("printer/edit");
- }
- }
-
- /*
- * 删除
- */
- public function delete()
- {
- $printer_id = input('printer_id', '');
-
- $printer_model = new PrinterModel();
- return $printer_model->deletePrinter([ [ 'printer_id', '=', $printer_id ], [ 'site_id', '=', $this->site_id ] ]);
- }
-
- /**
- * 测试打印
- */
- public function testPrint()
- {
- $printer_id = input('printer_id', '');
- $print_model = new PrinterOrder();
- $res = $print_model->testPrint($printer_id, $this->site_id);
- return $res;
- }
-
- /**
- * 刷新token
- */
- public function refreshToken()
- {
- $printer_id = input('printer_id', '');
- $print_model = new PrinterModel();
- $res = $print_model->refreshToken($printer_id, $this->site_id);
- return $res;
- }
-
- /**
- * 测试打印
- */
- public function test()
- {
-// $print_model = new PrinterOrder();
-// $res = $print_model->printer([
-//// 'order_id' => '5630',
-//// 'type' => 'goodsorder',
-//// 'printer_type' => 'order_pay',
-//// 'site_id' => $this->site_id
-// 'order_id' => '32',
-// 'type' => 'recharge',
-// 'site_id' => $this->site_id
-// ]);
-// return $res;
- $res = event('MemberRechargeOrderPayPrinter', [
- 'relate_id' => 66
- ]);
- }
-
+isJson()) {
+ $condition[] = [ 'site_id', '=', $this->site_id ];
+ $page = input('page', 1);
+ $page_size = input('page_size', PAGE_LIST_ROWS);
+ $list = $model->getPrinterPageList($condition, $page, $page_size, 'printer_id desc');
+ return $list;
+ }
+ return $this->fetch("printer/lists");
+ }
+
+ /**
+ * 添加小票打印
+ */
+ public function add()
+ {
+ $model = new PrinterModel();
+ if (request()->isJson()) {
+ $data = [
+ 'site_id' => $this->site_id,
+ 'printer_name' => input('printer_name', ''),
+ 'brand' => input('brand', ''),
+ 'printer_code' => input('printer_code', ''),
+ 'printer_key' => input('printer_key', ''),
+ 'open_id' => input('open_id', ''),
+ 'apikey' => input('apikey', ''),
+ 'store_id' => input('store_id', ''),
+ 'printer_type' => input('printer_type', ''),
+
+ //订单
+ 'order_pay_open' => input('order_pay_open', 0),
+ 'order_pay_template_id' => input('order_pay_template_id', 0),
+ 'order_pay_print_num' => input('order_pay_print_num', 1),
+ 'order_pay_order_type' => input('order_pay_order_type', ''),
+
+ 'take_delivery_open' => input('take_delivery_open', 0),
+ 'take_delivery_template_id' => input('take_delivery_template_id', 0),
+ 'take_delivery_print_num' => input('take_delivery_print_num', 1),
+ 'take_delivery_order_type' => input('take_delivery_order_type', ''),
+
+ 'manual_open' => input('manual_open', 0),
+ 'template_id' => input('template_id', 0),
+ 'print_num' => input('print_num', 1),
+
+ //充值
+ 'recharge_open' => input('recharge_open', 0),
+ 'recharge_template_id' => input('recharge_template_id', 0),
+ 'recharge_print_num' => input('recharge_print_num', 1),
+
+ 'change_shifts_open' => input('change_shifts_open', 0),
+ 'change_shifts_template_id' => input('change_shifts_template_id', 0),
+ 'change_shifts_print_num' => input('change_shifts_print_num', 1),
+
+ 'host' => input('host', ''),
+ 'ip' => input('ip', ''),
+ 'port' => input('port', ''),
+ 'print_width' => input('print_width', '58mm')
+
+ ];
+ if ($data[ 'order_pay_order_type' ]) $data[ 'order_pay_order_type' ] = ',' . $data[ 'order_pay_order_type' ] . ',';
+ if ($data[ 'take_delivery_order_type' ]) $data[ 'take_delivery_order_type' ] = ',' . $data[ 'take_delivery_order_type' ] . ',';
+ return $model->addPrinter($data);
+
+ } else {
+ //模板列表
+ $template_model = new PrinterTemplate();
+ $condition = [
+ [ 'site_id', '=', $this->site_id ],
+ ];
+ $template_list = $template_model->getPrinterTemplateList($condition, 'template_id,template_name,type', 'template_id desc');
+ $this->assign('template_list', $template_list[ 'data' ]);
+
+ //打印机品牌
+ $brand = $model->getPrinterBrand();
+ $this->assign('brand', $brand);
+
+ //订单类型
+ $order_common_model = new OrderCommonModel();
+ $order_type_list = $order_common_model->getOrderTypeStatusList();
+ unset($order_type_list[ 'all' ]);
+ $this->assign("order_type_list", $order_type_list);
+
+ $is_exit_store = addon_is_exit('store');
+ if ($is_exit_store == 1) {
+ $store_model = new Store();
+ $store_field = 'store_id,store_name';
+ $store_list = $store_model->getStoreList([ [ 'site_id', '=', $this->site_id ] ], $store_field);
+ $this->assign('store_list', $store_list[ 'data' ]);
+ }
+ $this->assign('is_exit_store', $is_exit_store);
+ return $this->fetch("printer/add");
+ }
+ }
+
+ /**
+ * 编辑小票打印
+ */
+ public function edit()
+ {
+ $model = new PrinterModel();
+ $printer_id = input('printer_id', 0);
+ if (request()->isJson()) {
+ $data = [
+ 'printer_id' => $printer_id,
+
+ 'site_id' => $this->site_id,
+ 'printer_name' => input('printer_name', ''),
+ 'brand' => input('brand', ''),
+ 'printer_code' => input('printer_code', ''),
+ 'printer_key' => input('printer_key', ''),
+ 'open_id' => input('open_id', ''),
+ 'apikey' => input('apikey', ''),
+ 'store_id' => input('store_id', ''),
+ 'printer_type' => input('printer_type', ''),
+
+ //订单
+ 'order_pay_open' => input('order_pay_open', 0),
+ 'order_pay_template_id' => input('order_pay_template_id', 0),
+ 'order_pay_print_num' => input('order_pay_print_num', 1),
+ 'order_pay_order_type' => input('order_pay_order_type', ''),
+
+ 'take_delivery_open' => input('take_delivery_open', 0),
+ 'take_delivery_template_id' => input('take_delivery_template_id', 0),
+ 'take_delivery_print_num' => input('take_delivery_print_num', 1),
+ 'take_delivery_order_type' => input('take_delivery_order_type', ''),
+
+ 'manual_open' => input('manual_open', 0),
+ 'template_id' => input('template_id', 0),
+ 'print_num' => input('print_num', 1),
+
+ //充值
+ 'recharge_open' => input('recharge_open', 0),
+ 'recharge_template_id' => input('recharge_template_id', 0),
+ 'recharge_print_num' => input('recharge_print_num', 1),
+
+ 'change_shifts_open' => input('change_shifts_open', 0),
+ 'change_shifts_template_id' => input('change_shifts_template_id', 0),
+ 'change_shifts_print_num' => input('change_shifts_print_num', 1),
+
+ 'host' => input('host', ''),
+ 'ip' => input('ip', ''),
+ 'port' => input('port', ''),
+ 'print_width' => input('print_width', '58mm')
+ ];
+
+ if ($data[ 'order_pay_order_type' ]) $data[ 'order_pay_order_type' ] = ',' . $data[ 'order_pay_order_type' ] . ',';
+ if ($data[ 'take_delivery_order_type' ]) $data[ 'take_delivery_order_type' ] = ',' . $data[ 'take_delivery_order_type' ] . ',';
+
+ return $model->editPrinter($data);
+ } else {
+
+ $info = $model->getPrinterInfo([ [ 'printer_id', '=', $printer_id ], [ 'site_id', '=', $this->site_id ] ]);
+ $info[ 'data' ][ 'take_delivery_order_type' ] = explode(',', $info[ 'data' ][ 'take_delivery_order_type' ]);
+ $info[ 'data' ][ 'order_pay_order_type' ] = explode(',', $info[ 'data' ][ 'order_pay_order_type' ]);
+ $this->assign('printer_info', $info[ 'data' ]);
+
+ //模板列表
+ $template_model = new PrinterTemplate();
+ $condition = [
+ [ 'site_id', '=', $this->site_id ],
+ ];
+ $template_list = $template_model->getPrinterTemplateList($condition, 'template_id,template_name,type', 'template_id desc');
+ $this->assign('template_list', $template_list[ 'data' ]);
+
+ //打印机品牌
+ $brand = $model->getPrinterBrand();
+ $this->assign('brand', $brand);
+
+ //订单类型
+ $order_common_model = new OrderCommonModel();
+ $order_type_list = $order_common_model->getOrderTypeStatusList();
+ unset($order_type_list[ 'all' ]);
+ $this->assign("order_type_list", $order_type_list);
+
+ //是否存在门店
+ $is_exit_store = addon_is_exit('store');
+ if ($is_exit_store == 1) {
+ $store_model = new Store();
+ $store_field = 'store_id,store_name';
+ $store_list = $store_model->getStoreList([ [ 'site_id', '=', $this->site_id ] ], $store_field);
+ $this->assign('store_list', $store_list[ 'data' ]);
+ }
+ $this->assign('is_exit_store', $is_exit_store);
+ return $this->fetch("printer/edit");
+ }
+ }
+
+ /*
+ * 删除
+ */
+ public function delete()
+ {
+ $printer_id = input('printer_id', '');
+
+ $printer_model = new PrinterModel();
+ return $printer_model->deletePrinter([ [ 'printer_id', '=', $printer_id ], [ 'site_id', '=', $this->site_id ] ]);
+ }
+
+ /**
+ * 测试打印
+ */
+ public function testPrint()
+ {
+ $printer_id = input('printer_id', '');
+ $print_model = new PrinterOrder();
+ $res = $print_model->testPrint($printer_id, $this->site_id);
+ return $res;
+ }
+
+ /**
+ * 刷新token
+ */
+ public function refreshToken()
+ {
+ $printer_id = input('printer_id', '');
+ $print_model = new PrinterModel();
+ $res = $print_model->refreshToken($printer_id, $this->site_id);
+ return $res;
+ }
+
+ /**
+ * 测试打印
+ */
+ public function test()
+ {
+// $print_model = new PrinterOrder();
+// $res = $print_model->printer([
+//// 'order_id' => '5630',
+//// 'type' => 'goodsorder',
+//// 'printer_type' => 'order_pay',
+//// 'site_id' => $this->site_id
+// 'order_id' => '32',
+// 'type' => 'recharge',
+// 'site_id' => $this->site_id
+// ]);
+// return $res;
+ $res = event('MemberRechargeOrderPayPrinter', [
+ 'relate_id' => 66
+ ]);
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/printer/shop/controller/Template.php b/src/addon/printer/shop/controller/Template.php
index 481752903..9eb0a5470 100644
--- a/src/addon/printer/shop/controller/Template.php
+++ b/src/addon/printer/shop/controller/Template.php
@@ -1,134 +1,126 @@
-isJson()) {
- $condition[] = [ 'site_id', '=', $this->site_id ];
- $page = input('page', 1);
- $page_size = input('page_size', PAGE_LIST_ROWS);
- $list = $model->getPrinterTemplatePageList($condition, $page, $page_size, 'template_id desc');
- return $list;
- }
- return $this->fetch("template/lists");
- }
-
- /**
- * 添加模板管理
- */
- public function add()
- {
- $model = new PrinterTemplate();
-
- $type = input('type', 'goodsorder');
- if (request()->isJson()) {
- $data = [
- 'site_id' => $this->site_id,
- 'site_name' => $this->shop_info[ 'site_name' ],
- 'template_type' => input('template_type', ''),
- 'template_name' => input('template_name', ''),
-
- 'title' => input('title', ''),
- 'head' => input('head', ''),
- 'buy_notes' => input('buy_notes', ''),
- 'seller_notes' => input('seller_notes', ''),
- 'buy_name' => input('buy_name', ''),
- 'buy_mobile' => input('buy_mobile', ''),
- 'buy_address' => input('buy_address', ''),
- 'shop_mobile' => input('shop_mobile', ''),
- 'shop_address' => input('shop_address', ''),
- 'shop_qrcode' => input('shop_qrcode', ''),
- 'qrcode_url' => input('qrcode_url', ''),
- 'bottom' => input('bottom', ''),
-
- 'type' => input('type', ''),
- 'type_name' => input('type_name', ''),
- 'goods_price_show' => input('goods_price_show', 0),
- 'goods_code_show' => input('goods_code_show', 0),
- 'form_show' => input('form_show', 0),
- 'goods_price_type' => input('goods_price_type', ''),
- ];
-
- return $model->addPrinterTemplate($data);
- } else {
- $this->assign('template_type', $model->getTemplateType());
- $this->assign('type', $type);
- return event('PrinterTemplate', [ 'type' => $type, 'action' => 'add' ], true);
- }
- }
-
- /**
- * 编辑模板管理
- */
- public function edit()
- {
- $model = new PrinterTemplate();
- $template_id = input('template_id', 0);
- if (request()->isJson()) {
- $data = [
- 'template_id' => $template_id,
- 'site_id' => $this->site_id,
- 'template_type' => input('template_type', ''),
- 'template_name' => input('template_name', ''),
-
- 'title' => input('title', ''),
- 'head' => input('head', ''),
- 'buy_notes' => input('buy_notes', ''),
- 'seller_notes' => input('seller_notes', ''),
- 'buy_name' => input('buy_name', ''),
- 'buy_mobile' => input('buy_mobile', ''),
- 'buy_address' => input('buy_address', ''),
- 'shop_mobile' => input('shop_mobile', ''),
- 'shop_address' => input('shop_address', ''),
- 'shop_qrcode' => input('shop_qrcode', ''),
- 'qrcode_url' => input('qrcode_url', ''),
- 'bottom' => input('bottom', ''),
-
- 'goods_price_show' => input('goods_price_show', 0),
- 'goods_code_show' => input('goods_code_show', 0),
- 'form_show' => input('form_show', 0),
- 'goods_price_type' => input('goods_price_type', ''),
-
- ];
- return $model->editPrinterTemplate($data);
-
- } else {
- $info = $model->getPrinterTemplateInfo([ [ 'template_id', '=', $template_id ], [ 'site_id', '=', $this->site_id ] ]);
- $this->assign('info', $info[ 'data' ]);
-
- return event('PrinterTemplate', [ 'type' => $info[ 'data' ][ 'type' ], 'action' => 'edit' ], true);
- }
- }
-
- /*
- * 删除
- */
- public function delete()
- {
- $template_id = input('template_id', '');
-
- $printer_model = new PrinterTemplate();
- return $printer_model->deletePrinterTemplate([ [ 'template_id', '=', $template_id ], [ 'site_id', '=', $this->site_id ] ]);
- }
-
+isJson()) {
+ $condition[] = [ 'site_id', '=', $this->site_id ];
+ $page = input('page', 1);
+ $page_size = input('page_size', PAGE_LIST_ROWS);
+ $list = $model->getPrinterTemplatePageList($condition, $page, $page_size, 'template_id desc');
+ return $list;
+ }
+ return $this->fetch("template/lists");
+ }
+
+ /**
+ * 添加模板管理
+ */
+ public function add()
+ {
+ $model = new PrinterTemplate();
+
+ $type = input('type', 'goodsorder');
+ if (request()->isJson()) {
+ $data = [
+ 'site_id' => $this->site_id,
+ 'site_name' => $this->shop_info[ 'site_name' ],
+ 'template_type' => input('template_type', ''),
+ 'template_name' => input('template_name', ''),
+
+ 'title' => input('title', ''),
+ 'head' => input('head', ''),
+ 'buy_notes' => input('buy_notes', ''),
+ 'seller_notes' => input('seller_notes', ''),
+ 'buy_name' => input('buy_name', ''),
+ 'buy_mobile' => input('buy_mobile', ''),
+ 'buy_address' => input('buy_address', ''),
+ 'shop_mobile' => input('shop_mobile', ''),
+ 'shop_address' => input('shop_address', ''),
+ 'shop_qrcode' => input('shop_qrcode', ''),
+ 'qrcode_url' => input('qrcode_url', ''),
+ 'bottom' => input('bottom', ''),
+
+ 'type' => input('type', ''),
+ 'type_name' => input('type_name', ''),
+ 'goods_price_show' => input('goods_price_show', 0),
+ 'goods_code_show' => input('goods_code_show', 0),
+ 'form_show' => input('form_show', 0),
+ 'goods_price_type' => input('goods_price_type', ''),
+ ];
+
+ return $model->addPrinterTemplate($data);
+ } else {
+ $this->assign('template_type', $model->getTemplateType());
+ $this->assign('type', $type);
+ return event('PrinterTemplate', [ 'type' => $type, 'action' => 'add' ], true);
+ }
+ }
+
+ /**
+ * 编辑模板管理
+ */
+ public function edit()
+ {
+ $model = new PrinterTemplate();
+ $template_id = input('template_id', 0);
+ if (request()->isJson()) {
+ $data = [
+ 'template_id' => $template_id,
+ 'site_id' => $this->site_id,
+ 'template_type' => input('template_type', ''),
+ 'template_name' => input('template_name', ''),
+
+ 'title' => input('title', ''),
+ 'head' => input('head', ''),
+ 'buy_notes' => input('buy_notes', ''),
+ 'seller_notes' => input('seller_notes', ''),
+ 'buy_name' => input('buy_name', ''),
+ 'buy_mobile' => input('buy_mobile', ''),
+ 'buy_address' => input('buy_address', ''),
+ 'shop_mobile' => input('shop_mobile', ''),
+ 'shop_address' => input('shop_address', ''),
+ 'shop_qrcode' => input('shop_qrcode', ''),
+ 'qrcode_url' => input('qrcode_url', ''),
+ 'bottom' => input('bottom', ''),
+
+ 'goods_price_show' => input('goods_price_show', 0),
+ 'goods_code_show' => input('goods_code_show', 0),
+ 'form_show' => input('form_show', 0),
+ 'goods_price_type' => input('goods_price_type', ''),
+
+ ];
+ return $model->editPrinterTemplate($data);
+
+ } else {
+ $info = $model->getPrinterTemplateInfo([ [ 'template_id', '=', $template_id ], [ 'site_id', '=', $this->site_id ] ]);
+ $this->assign('info', $info[ 'data' ]);
+
+ return event('PrinterTemplate', [ 'type' => $info[ 'data' ][ 'type' ], 'action' => 'edit' ], true);
+ }
+ }
+
+ /*
+ * 删除
+ */
+ public function delete()
+ {
+ $template_id = input('template_id', '');
+
+ $printer_model = new PrinterTemplate();
+ return $printer_model->deletePrinterTemplate([ [ 'template_id', '=', $template_id ], [ 'site_id', '=', $this->site_id ] ]);
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/printer/storeapi/controller/Printer.php b/src/addon/printer/storeapi/controller/Printer.php
index 3656728ab..4217dae3c 100644
--- a/src/addon/printer/storeapi/controller/Printer.php
+++ b/src/addon/printer/storeapi/controller/Printer.php
@@ -1,238 +1,230 @@
-params[ 'site_id' ] ?? 1;
- $store_id = $this->params[ 'store_id' ] ?? 1;
- $page = $this->params[ 'page' ] ?? 1;
- $page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
- $condition[] = [ 'site_id', '=', $site_id ];
- $condition[] = [ 'store_id', '=', $store_id ];
- $list = $model->getPrinterPageList($condition, $page, $page_size, 'printer_id desc');
- return $this->response($list);
- }
-
- /**
- * 打印机信息
- * @return false|string
- */
- public function info()
- {
- $site_id = $this->params[ 'site_id' ] ?? 1;
- $store_id = $this->params[ 'store_id' ] ?? 1;
- $printer_id = $this->params[ 'printer_id' ] ?? 1;
- $model = new PrinterModel();
- $info = $model->getPrinterInfo([ [ 'printer_id', '=', $printer_id ], [ 'site_id', '=', $site_id ], [ 'store_id', '=', $store_id ] ]);
- $info[ 'data' ][ 'take_delivery_order_type' ] = explode(',', $info[ 'data' ][ 'take_delivery_order_type' ]);
- $info[ 'data' ][ 'order_pay_order_type' ] = explode(',', $info[ 'data' ][ 'order_pay_order_type' ]);
-
- $order_common_model = new OrderCommonModel();
- $order_type_list = $order_common_model->getOrderTypeStatusList();
- unset($order_type_list[ 'all' ]);
- $info[ 'data' ][ 'order_type_list' ] = $order_type_list;
- return $this->response($info);
- }
-
- public function getOrderType()
- {
- $order_common_model = new OrderCommonModel();
- $order_type_list = $order_common_model->getOrderTypeStatusList();
- unset($order_type_list[ 'all' ]);
- return $this->response($this->success($order_type_list));
- }
-
- /**
- * 打印机品牌
- * @return false|string
- */
- public function brand()
- {
- $model = new PrinterModel();
- $brand = $model->getPrinterBrand();
- return $this->response($brand);
- }
-
- /**
- * 打印模板
- */
- public function template()
- {
- $site_id = $this->params[ 'site_id' ] ?? 1;
- $template_model = new PrinterTemplate();
- $condition = [
- [ 'site_id', '=', $site_id ],
- ];
- $template_list = $template_model->getPrinterTemplateList($condition, 'template_id,template_name,type', 'template_id desc');
- return $this->response($template_list);
- }
-
- /**
- * 添加小票打印
- */
- public function add()
- {
- $model = new PrinterModel();
- $data = [
- 'site_id' => $this->params[ 'site_id' ] ?? 1,
- 'printer_name' => $this->params[ 'printer_name' ] ?? '',
- 'brand' => $this->params[ 'brand' ] ?? '',
- 'printer_code' => $this->params[ 'printer_code' ] ?? '',
- 'printer_key' => $this->params[ 'printer_key' ] ?? '',
- 'open_id' => $this->params[ 'open_id' ] ?? '',
- 'apikey' => $this->params[ 'apikey' ] ?? '',
- 'store_id' => $this->params[ 'store_id' ] ?? 1,
- 'printer_type' => $this->params[ 'printer_type' ] ?? 'cloud',
-
- //订单
- 'order_pay_open' => $this->params[ 'order_pay_open' ] ?? 0,
- 'order_pay_template_id' => $this->params[ 'order_pay_template_id' ] ?? 0,
- 'order_pay_print_num' => $this->params[ 'order_pay_print_num' ] ?? 1,
- 'order_pay_order_type' => $this->params[ 'order_pay_order_type' ] ?? '',
-
- 'take_delivery_open' => $this->params[ 'take_delivery_open' ] ?? 0,
- 'take_delivery_template_id' => $this->params[ 'take_delivery_template_id' ] ?? 0,
- 'take_delivery_print_num' => $this->params[ 'take_delivery_print_num' ] ?? 1,
- 'take_delivery_order_type' => $this->params[ 'take_delivery_order_type' ] ?? '',
-
- 'manual_open' => $this->params[ 'manual_open' ] ?? 0,
- 'template_id' => $this->params[ 'template_id' ] ?? 0,
- 'print_num' => $this->params[ 'print_num' ] ?? 1,
-
- //充值
- 'recharge_open' => $this->params[ 'recharge_open' ] ?? 0,
- 'recharge_template_id' => $this->params[ 'recharge_template_id' ] ?? 0,
- 'recharge_print_num' => $this->params[ 'recharge_print_num' ] ?? 1,
-
- 'change_shifts_open' => $this->params[ 'change_shifts_open' ] ?? 0,
- 'change_shifts_template_id' => $this->params[ 'change_shifts_template_id' ] ?? 0,
- 'change_shifts_print_num' => $this->params[ 'change_shifts_print_num' ] ?? 1,
-
- 'host' => $this->params[ 'host' ] ?? '',
- 'ip' => $this->params[ 'ip' ] ?? '',
- 'port' => $this->params[ 'port' ] ?? '',
- 'print_width' => $this->params[ 'print_width' ] ?? '58mm'
- ];
- if ($data[ 'order_pay_order_type' ]) $data[ 'order_pay_order_type' ] = ',' . $data[ 'order_pay_order_type' ] . ',';
- if ($data[ 'take_delivery_order_type' ]) $data[ 'take_delivery_order_type' ] = ',' . $data[ 'take_delivery_order_type' ] . ',';
- return $this->response($model->addPrinter($data));
-
- }
-
- /**
- * 编辑小票打印
- */
- public function edit()
- {
- $model = new PrinterModel();
- $data = [
- 'printer_id' => $this->params[ 'printer_id' ] ?? 1,
- 'site_id' => $this->params[ 'site_id' ] ?? 1,
- 'printer_name' => $this->params[ 'printer_name' ] ?? '',
- 'brand' => $this->params[ 'brand' ] ?? '',
- 'printer_code' => $this->params[ 'printer_code' ] ?? '',
- 'printer_key' => $this->params[ 'printer_key' ] ?? '',
- 'open_id' => $this->params[ 'open_id' ] ?? '',
- 'apikey' => $this->params[ 'apikey' ] ?? '',
- 'store_id' => $this->params[ 'store_id' ] ?? 1,
- 'printer_type' => $this->params[ 'printer_type' ] ?? 'cloud',
-
- //订单
- 'order_pay_open' => $this->params[ 'order_pay_open' ] ?? 0,
- 'order_pay_template_id' => $this->params[ 'order_pay_template_id' ] ?? 0,
- 'order_pay_print_num' => $this->params[ 'order_pay_print_num' ] ?? 1,
- 'order_pay_order_type' => $this->params[ 'order_pay_order_type' ] ?? '',
-
- 'take_delivery_open' => $this->params[ 'take_delivery_open' ] ?? 0,
- 'take_delivery_template_id' => $this->params[ 'take_delivery_template_id' ] ?? 0,
- 'take_delivery_print_num' => $this->params[ 'take_delivery_print_num' ] ?? 1,
- 'take_delivery_order_type' => $this->params[ 'take_delivery_order_type' ] ?? '',
-
- 'manual_open' => $this->params[ 'manual_open' ] ?? 0,
- 'template_id' => $this->params[ 'template_id' ] ?? 0,
- 'print_num' => $this->params[ 'print_num' ] ?? 1,
-
- //充值
- 'recharge_open' => $this->params[ 'recharge_open' ] ?? 0,
- 'recharge_template_id' => $this->params[ 'recharge_template_id' ] ?? 0,
- 'recharge_print_num' => $this->params[ 'recharge_print_num' ] ?? 1,
-
- 'change_shifts_open' => $this->params[ 'change_shifts_open' ] ?? 0,
- 'change_shifts_template_id' => $this->params[ 'change_shifts_template_id' ] ?? 0,
- 'change_shifts_print_num' => $this->params[ 'change_shifts_print_num' ] ?? 1,
-
- 'host' => $this->params[ 'host' ] ?? '',
- 'ip' => $this->params[ 'ip' ] ?? '',
- 'port' => $this->params[ 'port' ] ?? '',
- 'print_width' => $this->params[ 'print_width' ] ?? '58mm'
- ];
- if ($data[ 'order_pay_order_type' ]) {
- $data[ 'order_pay_order_type' ] = ',' . $data[ 'order_pay_order_type' ] . ',';
- $data[ 'order_pay_order_type' ] = str_replace(',,', ',', $data[ 'order_pay_order_type' ]);
- }
- if ($data[ 'take_delivery_order_type' ]) {
- $data[ 'take_delivery_order_type' ] = ',' . $data[ 'take_delivery_order_type' ] . ',';
- $data[ 'take_delivery_order_type' ] = str_replace(',,', ',', $data[ 'take_delivery_order_type' ]);
- }
- return $this->response($model->editPrinter($data));
- }
-
- /*
- * 删除
- */
- public function deletePrinter()
- {
- $printer_id = $this->params[ 'printer_id' ] ?? 0;
- $store_id = $this->params[ 'store_id' ] ?? 0;
-
- $printer_model = new PrinterModel();
- $res = $printer_model->deletePrinter([ [ 'printer_id', '=', $printer_id ], [ 'store_id', '=', $store_id ] ]);
- return $this->response($res);
- }
-
- /**
- * 测试打印
- */
- public function testPrint()
- {
- $printer_id = $this->params[ 'printer_id' ] ?? 0;
- $site_id = $this->params[ 'site_id' ] ?? 1;
- $print_model = new PrinterOrder();
- $res = $print_model->testPrint($printer_id, $site_id);
- return $this->response($res);
- }
-
- /**
- * 刷新token
- */
- public function refreshToken()
- {
- $printer_id = $this->params[ 'printer_id' ] ?? 0;
- $site_id = $this->params[ 'site_id' ] ?? 1;
- $print_model = new PrinterModel();
- $res = $print_model->refreshToken($printer_id, $site_id);
- return $this->response($res);
- }
-
+params[ 'site_id' ] ?? 1;
+ $store_id = $this->params[ 'store_id' ] ?? 1;
+ $page = $this->params[ 'page' ] ?? 1;
+ $page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
+ $condition[] = [ 'site_id', '=', $site_id ];
+ $condition[] = [ 'store_id', '=', $store_id ];
+ $list = $model->getPrinterPageList($condition, $page, $page_size, 'printer_id desc');
+ return $this->response($list);
+ }
+
+ /**
+ * 打印机信息
+ * @return false|string
+ */
+ public function info()
+ {
+ $site_id = $this->params[ 'site_id' ] ?? 1;
+ $store_id = $this->params[ 'store_id' ] ?? 1;
+ $printer_id = $this->params[ 'printer_id' ] ?? 1;
+ $model = new PrinterModel();
+ $info = $model->getPrinterInfo([ [ 'printer_id', '=', $printer_id ], [ 'site_id', '=', $site_id ], [ 'store_id', '=', $store_id ] ]);
+ $info[ 'data' ][ 'take_delivery_order_type' ] = explode(',', $info[ 'data' ][ 'take_delivery_order_type' ]);
+ $info[ 'data' ][ 'order_pay_order_type' ] = explode(',', $info[ 'data' ][ 'order_pay_order_type' ]);
+
+ $order_common_model = new OrderCommonModel();
+ $order_type_list = $order_common_model->getOrderTypeStatusList();
+ unset($order_type_list[ 'all' ]);
+ $info[ 'data' ][ 'order_type_list' ] = $order_type_list;
+ return $this->response($info);
+ }
+
+ public function getOrderType()
+ {
+ $order_common_model = new OrderCommonModel();
+ $order_type_list = $order_common_model->getOrderTypeStatusList();
+ unset($order_type_list[ 'all' ]);
+ return $this->response($this->success($order_type_list));
+ }
+
+ /**
+ * 打印机品牌
+ * @return false|string
+ */
+ public function brand()
+ {
+ $model = new PrinterModel();
+ $brand = $model->getPrinterBrand();
+ return $this->response($brand);
+ }
+
+ /**
+ * 打印模板
+ */
+ public function template()
+ {
+ $site_id = $this->params[ 'site_id' ] ?? 1;
+ $template_model = new PrinterTemplate();
+ $condition = [
+ [ 'site_id', '=', $site_id ],
+ ];
+ $template_list = $template_model->getPrinterTemplateList($condition, 'template_id,template_name,type', 'template_id desc');
+ return $this->response($template_list);
+ }
+
+ /**
+ * 添加小票打印
+ */
+ public function add()
+ {
+ $model = new PrinterModel();
+ $data = [
+ 'site_id' => $this->params[ 'site_id' ] ?? 1,
+ 'printer_name' => $this->params[ 'printer_name' ] ?? '',
+ 'brand' => $this->params[ 'brand' ] ?? '',
+ 'printer_code' => $this->params[ 'printer_code' ] ?? '',
+ 'printer_key' => $this->params[ 'printer_key' ] ?? '',
+ 'open_id' => $this->params[ 'open_id' ] ?? '',
+ 'apikey' => $this->params[ 'apikey' ] ?? '',
+ 'store_id' => $this->params[ 'store_id' ] ?? 1,
+ 'printer_type' => $this->params[ 'printer_type' ] ?? 'cloud',
+
+ //订单
+ 'order_pay_open' => $this->params[ 'order_pay_open' ] ?? 0,
+ 'order_pay_template_id' => $this->params[ 'order_pay_template_id' ] ?? 0,
+ 'order_pay_print_num' => $this->params[ 'order_pay_print_num' ] ?? 1,
+ 'order_pay_order_type' => $this->params[ 'order_pay_order_type' ] ?? '',
+
+ 'take_delivery_open' => $this->params[ 'take_delivery_open' ] ?? 0,
+ 'take_delivery_template_id' => $this->params[ 'take_delivery_template_id' ] ?? 0,
+ 'take_delivery_print_num' => $this->params[ 'take_delivery_print_num' ] ?? 1,
+ 'take_delivery_order_type' => $this->params[ 'take_delivery_order_type' ] ?? '',
+
+ 'manual_open' => $this->params[ 'manual_open' ] ?? 0,
+ 'template_id' => $this->params[ 'template_id' ] ?? 0,
+ 'print_num' => $this->params[ 'print_num' ] ?? 1,
+
+ //充值
+ 'recharge_open' => $this->params[ 'recharge_open' ] ?? 0,
+ 'recharge_template_id' => $this->params[ 'recharge_template_id' ] ?? 0,
+ 'recharge_print_num' => $this->params[ 'recharge_print_num' ] ?? 1,
+
+ 'change_shifts_open' => $this->params[ 'change_shifts_open' ] ?? 0,
+ 'change_shifts_template_id' => $this->params[ 'change_shifts_template_id' ] ?? 0,
+ 'change_shifts_print_num' => $this->params[ 'change_shifts_print_num' ] ?? 1,
+
+ 'host' => $this->params[ 'host' ] ?? '',
+ 'ip' => $this->params[ 'ip' ] ?? '',
+ 'port' => $this->params[ 'port' ] ?? '',
+ 'print_width' => $this->params[ 'print_width' ] ?? '58mm'
+ ];
+ if ($data[ 'order_pay_order_type' ]) $data[ 'order_pay_order_type' ] = ',' . $data[ 'order_pay_order_type' ] . ',';
+ if ($data[ 'take_delivery_order_type' ]) $data[ 'take_delivery_order_type' ] = ',' . $data[ 'take_delivery_order_type' ] . ',';
+ return $this->response($model->addPrinter($data));
+
+ }
+
+ /**
+ * 编辑小票打印
+ */
+ public function edit()
+ {
+ $model = new PrinterModel();
+ $data = [
+ 'printer_id' => $this->params[ 'printer_id' ] ?? 1,
+ 'site_id' => $this->params[ 'site_id' ] ?? 1,
+ 'printer_name' => $this->params[ 'printer_name' ] ?? '',
+ 'brand' => $this->params[ 'brand' ] ?? '',
+ 'printer_code' => $this->params[ 'printer_code' ] ?? '',
+ 'printer_key' => $this->params[ 'printer_key' ] ?? '',
+ 'open_id' => $this->params[ 'open_id' ] ?? '',
+ 'apikey' => $this->params[ 'apikey' ] ?? '',
+ 'store_id' => $this->params[ 'store_id' ] ?? 1,
+ 'printer_type' => $this->params[ 'printer_type' ] ?? 'cloud',
+
+ //订单
+ 'order_pay_open' => $this->params[ 'order_pay_open' ] ?? 0,
+ 'order_pay_template_id' => $this->params[ 'order_pay_template_id' ] ?? 0,
+ 'order_pay_print_num' => $this->params[ 'order_pay_print_num' ] ?? 1,
+ 'order_pay_order_type' => $this->params[ 'order_pay_order_type' ] ?? '',
+
+ 'take_delivery_open' => $this->params[ 'take_delivery_open' ] ?? 0,
+ 'take_delivery_template_id' => $this->params[ 'take_delivery_template_id' ] ?? 0,
+ 'take_delivery_print_num' => $this->params[ 'take_delivery_print_num' ] ?? 1,
+ 'take_delivery_order_type' => $this->params[ 'take_delivery_order_type' ] ?? '',
+
+ 'manual_open' => $this->params[ 'manual_open' ] ?? 0,
+ 'template_id' => $this->params[ 'template_id' ] ?? 0,
+ 'print_num' => $this->params[ 'print_num' ] ?? 1,
+
+ //充值
+ 'recharge_open' => $this->params[ 'recharge_open' ] ?? 0,
+ 'recharge_template_id' => $this->params[ 'recharge_template_id' ] ?? 0,
+ 'recharge_print_num' => $this->params[ 'recharge_print_num' ] ?? 1,
+
+ 'change_shifts_open' => $this->params[ 'change_shifts_open' ] ?? 0,
+ 'change_shifts_template_id' => $this->params[ 'change_shifts_template_id' ] ?? 0,
+ 'change_shifts_print_num' => $this->params[ 'change_shifts_print_num' ] ?? 1,
+
+ 'host' => $this->params[ 'host' ] ?? '',
+ 'ip' => $this->params[ 'ip' ] ?? '',
+ 'port' => $this->params[ 'port' ] ?? '',
+ 'print_width' => $this->params[ 'print_width' ] ?? '58mm'
+ ];
+ if ($data[ 'order_pay_order_type' ]) {
+ $data[ 'order_pay_order_type' ] = ',' . $data[ 'order_pay_order_type' ] . ',';
+ $data[ 'order_pay_order_type' ] = str_replace(',,', ',', $data[ 'order_pay_order_type' ]);
+ }
+ if ($data[ 'take_delivery_order_type' ]) {
+ $data[ 'take_delivery_order_type' ] = ',' . $data[ 'take_delivery_order_type' ] . ',';
+ $data[ 'take_delivery_order_type' ] = str_replace(',,', ',', $data[ 'take_delivery_order_type' ]);
+ }
+ return $this->response($model->editPrinter($data));
+ }
+
+ /*
+ * 删除
+ */
+ public function deletePrinter()
+ {
+ $printer_id = $this->params[ 'printer_id' ] ?? 0;
+ $store_id = $this->params[ 'store_id' ] ?? 0;
+
+ $printer_model = new PrinterModel();
+ $res = $printer_model->deletePrinter([ [ 'printer_id', '=', $printer_id ], [ 'store_id', '=', $store_id ] ]);
+ return $this->response($res);
+ }
+
+ /**
+ * 测试打印
+ */
+ public function testPrint()
+ {
+ $printer_id = $this->params[ 'printer_id' ] ?? 0;
+ $site_id = $this->params[ 'site_id' ] ?? 1;
+ $print_model = new PrinterOrder();
+ $res = $print_model->testPrint($printer_id, $site_id);
+ return $this->response($res);
+ }
+
+ /**
+ * 刷新token
+ */
+ public function refreshToken()
+ {
+ $printer_id = $this->params[ 'printer_id' ] ?? 0;
+ $site_id = $this->params[ 'site_id' ] ?? 1;
+ $print_model = new PrinterModel();
+ $res = $print_model->refreshToken($printer_id, $site_id);
+ return $this->response($res);
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/qiniu/config/diy_view.php b/src/addon/qiniu/config/diy_view.php
index c3c657905..e36ca9b7d 100644
--- a/src/addon/qiniu/config/diy_view.php
+++ b/src/addon/qiniu/config/diy_view.php
@@ -1,38 +1,30 @@
- '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
- 'template' => [],
-
- // 后台自定义组件——装修
- 'util' => [],
-
- // 自定义页面路径
- 'link' => [],
-
- // 自定义图标库
- 'icon_library' => [],
-
- // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
- 'component' => [],
-
- // uni-app 页面,多个逗号隔开
- 'pages' => [],
-
- // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
- 'info' => [],
-
- // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
- 'theme' => [],
-
- // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
- 'data' => []
+ '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
+ 'template' => [],
+
+ // 后台自定义组件——装修
+ 'util' => [],
+
+ // 自定义页面路径
+ 'link' => [],
+
+ // 自定义图标库
+ 'icon_library' => [],
+
+ // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
+ 'component' => [],
+
+ // uni-app 页面,多个逗号隔开
+ 'pages' => [],
+
+ // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
+ 'info' => [],
+
+ // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
+ 'theme' => [],
+
+ // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
+ 'data' => []
];
\ No newline at end of file
diff --git a/src/addon/qiniu/config/info.php b/src/addon/qiniu/config/info.php
index d857b445c..c5ba9d1b3 100644
--- a/src/addon/qiniu/config/info.php
+++ b/src/addon/qiniu/config/info.php
@@ -1,21 +1,12 @@
- 'qiniu',
- 'title' => '七牛云上传',
- 'description' => '七牛云上传功能',
- 'type' => 'system', //插件类型 system :系统插件 promotion:营销插件 tool:工具插件
- 'status' => 1,
- 'author' => '',
- 'version' => '5.3.1',
- 'version_no' => '525231212001',
- 'content' => '',
+ 'qiniu',
+ 'title' => '七牛云上传',
+ 'description' => '七牛云上传功能',
+ 'type' => 'system', //插件类型 system :系统插件 promotion:营销插件 tool:工具插件
+ 'status' => 1,
+ 'author' => '',
+ 'version' => '5.3.1',
+ 'version_no' => '525231212001',
+ 'content' => '',
];
\ No newline at end of file
diff --git a/src/addon/qiniu/event/ClearAlbumPic.php b/src/addon/qiniu/event/ClearAlbumPic.php
index 040c3c160..5db0a5151 100644
--- a/src/addon/qiniu/event/ClearAlbumPic.php
+++ b/src/addon/qiniu/event/ClearAlbumPic.php
@@ -1,38 +1,30 @@
-getQiniuConfig($params[ 'site_id' ]);
-
- if (!empty($config[ 'data' ])) {
- if (!empty($config[ 'data' ][ 'value' ][ 'domain' ]) && strpos($params[ 'pic_path' ], $config[ 'data' ][ 'value' ][ 'domain' ]) === 0) {
- $result = $qiniu_model->deleteAlbumPic($params[ 'pic_path' ], $config[ 'data' ][ 'value' ][ 'domain' ]);
- return $result;
- }
- }
- }
-
+getQiniuConfig($params[ 'site_id' ]);
+
+ if (!empty($config[ 'data' ])) {
+ if (!empty($config[ 'data' ][ 'value' ][ 'domain' ]) && strpos($params[ 'pic_path' ], $config[ 'data' ][ 'value' ][ 'domain' ]) === 0) {
+ $result = $qiniu_model->deleteAlbumPic($params[ 'pic_path' ], $config[ 'data' ][ 'value' ][ 'domain' ]);
+ return $result;
+ }
+ }
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/qiniu/event/CloseOss.php b/src/addon/qiniu/event/CloseOss.php
index 5b9c0d26d..20726ebc8 100644
--- a/src/addon/qiniu/event/CloseOss.php
+++ b/src/addon/qiniu/event/CloseOss.php
@@ -1,27 +1,18 @@
-modifyConfigIsUse(0);
- return $result;
- }
+modifyConfigIsUse(0);
+ return $result;
+ }
}
\ No newline at end of file
diff --git a/src/addon/qiniu/event/Install.php b/src/addon/qiniu/event/Install.php
index 5438e6238..5154ab1c6 100644
--- a/src/addon/qiniu/event/Install.php
+++ b/src/addon/qiniu/event/Install.php
@@ -1,26 +1,17 @@
- "qiniu",
- "sms_type_name" => "七牛云上传",
- "edit_url" => "qiniu://shop/config/config",
- "shop_url" => "qiniu://shop/config/config",
- "desc" => "七牛云上传,七牛提供10GB免费存储空间"
- );
- return $info;
- }
+ "qiniu",
+ "sms_type_name" => "七牛云上传",
+ "edit_url" => "qiniu://shop/config/config",
+ "shop_url" => "qiniu://shop/config/config",
+ "desc" => "七牛云上传,七牛提供10GB免费存储空间"
+ );
+ return $info;
+ }
}
\ No newline at end of file
diff --git a/src/addon/qiniu/event/Put.php b/src/addon/qiniu/event/Put.php
index b72a49c37..f5b14cae5 100644
--- a/src/addon/qiniu/event/Put.php
+++ b/src/addon/qiniu/event/Put.php
@@ -1,29 +1,21 @@
-putFile($param);
- return $result;
- }
+putFile($param);
+ return $result;
+ }
}
\ No newline at end of file
diff --git a/src/addon/qiniu/event/UnInstall.php b/src/addon/qiniu/event/UnInstall.php
index 5b86ca48c..0bf9b89df 100644
--- a/src/addon/qiniu/event/UnInstall.php
+++ b/src/addon/qiniu/event/UnInstall.php
@@ -1,26 +1,17 @@
-setConfig($data, '七牛云上传配置', $status, [['site_id', '=', $site_id], ['app_module', '=', $app_module], ['config_key', '=', 'QINIU_CONFIG']]);
- return $res;
- }
-
- /**
- * 获取七牛云上传配置
- */
- public function getQiniuConfig($site_id = 1, $app_module = 'shop')
- {
- $config = new ConfigModel();
- $res = $config->getConfig([['site_id', '=', $site_id], ['app_module', '=', $app_module], ['config_key', '=', 'QINIU_CONFIG']]);
- return $res;
- }
-
- /**
- * 配置七牛云开关状态
- * @param $status
- */
- public function modifyConfigIsUse($status)
- {
- $config = new ConfigModel();
- $res = $config->modifyConfigIsUse($status, [['site_id', '=', 1], ['app_module', '=', 'shop'], ['config_key', '=', 'QINIU_CONFIG']]);
- return $res;
- }
+setConfig($data, '七牛云上传配置', $status, [['site_id', '=', $site_id], ['app_module', '=', $app_module], ['config_key', '=', 'QINIU_CONFIG']]);
+ return $res;
+ }
+
+ /**
+ * 获取七牛云上传配置
+ */
+ public function getQiniuConfig($site_id = 1, $app_module = 'shop')
+ {
+ $config = new ConfigModel();
+ $res = $config->getConfig([['site_id', '=', $site_id], ['app_module', '=', $app_module], ['config_key', '=', 'QINIU_CONFIG']]);
+ return $res;
+ }
+
+ /**
+ * 配置七牛云开关状态
+ * @param $status
+ */
+ public function modifyConfigIsUse($status)
+ {
+ $config = new ConfigModel();
+ $res = $config->modifyConfigIsUse($status, [['site_id', '=', 1], ['app_module', '=', 'shop'], ['config_key', '=', 'QINIU_CONFIG']]);
+ return $res;
+ }
}
\ No newline at end of file
diff --git a/src/addon/qiniu/model/Qiniu.php b/src/addon/qiniu/model/Qiniu.php
index 406533023..2207fd48d 100644
--- a/src/addon/qiniu/model/Qiniu.php
+++ b/src/addon/qiniu/model/Qiniu.php
@@ -1,131 +1,123 @@
-getQiniuConfig();
- $config = $config_result[ "data" ];
-
- if ($config[ "is_use" ] == 1) {
- $config = $config[ "value" ];
- $accessKey = $config[ "access_key" ];
- $secretKey = $config[ "secret_key" ];
- $bucket = $config[ "bucket" ];
- $auth = new Auth($accessKey, $secretKey);
- $token = $auth->uploadToken($bucket);
- ( new BucketManager($auth) )->delete($bucket, $key);
- $uploadMgr = new UploadManager();
- //----------------------------------------upload demo1 ----------------------------------------
- // 上传字符串到七牛
- list($ret, $err) = $uploadMgr->put($token, $key, $data);
- if ($err !== null) {
- return $this->error('', $err->getResponse()->error);
- } else {
- //返回图片的完整URL
- $domain = $config[ "domain" ];//自定义域名
- $data = array (
- "path" => $domain . "/" . $key,
- "domain" => $domain,
- "bucket" => $bucket
- );
- return $this->success($data);
- }
- }
- }
-
- /**
- * 设置七牛参数配置
- * @param unknown $filePath 上传图片路径
- * @param unknown $key 上传到七牛后保存的文件名
- */
- public function putFile($param)
- {
- $file_path = $param[ "file_path" ];
- $key = $param[ "key" ];
- $config_model = new Config();
- $config = $config_model->getQiniuConfig()[ "data" ];
- if ($config[ "is_use" ] == 1) {
- $config = $config[ "value" ];
- $accessKey = $config[ "access_key" ];
- $secretKey = $config[ "secret_key" ];
- $bucket = $config[ "bucket" ];
- $auth = new Auth($accessKey, $secretKey);
- ( new BucketManager($auth) )->delete($bucket, $key);
- //要上传的空间
- $token = $auth->uploadToken($bucket);
- // 初始化 UploadManager 对象并进行文件的上传
- $uploadMgr = new UploadManager();
- // 调用 UploadManager 的 putFile 方法进行文件的上传
- list($ret, $err) = $uploadMgr->putFile($token, $key, $file_path);
- if ($err !== null) {
- return $this->error('', $err->getResponse()->error);
- } else {
- //返回图片的完整URL
- $domain = $config[ "domain" ];//自定义域名
- $data = array (
- "path" => $domain . "/" . $key,
- "domain" => $domain,
- "bucket" => $bucket
- );
- return $this->success($data);
- }
- }
- }
-
- /**
- * @param $file_path
- * 删除七牛云图片
- */
- public function deleteAlbumPic($file_path, $prefix)
- {
- $config_model = new Config();
- $config_result = $config_model->getQiniuConfig();
- $config = $config_result[ "data" ];
- if (!empty($config)) {
- $config = $config[ "value" ];
- $accessKey = $config[ "access_key" ];
- $secretKey = $config[ "secret_key" ];
- $bucket = $config[ "bucket" ];
-
- $auth = new Auth($accessKey, $secretKey);
-// $prefix = substr($file_path,0,strripos($file_path, "/"));
-// dump(str_replace($prefix."/", "",$file_path));
- ( new BucketManager($auth) )->delete($bucket, str_replace($prefix . "/", "", $file_path));
- ( new BucketManager($auth) )->delete($bucket, str_replace($prefix . "/", "", img($file_path, 'big')));
- ( new BucketManager($auth) )->delete($bucket, str_replace($prefix . "/", "", img($file_path, 'mid')));
- ( new BucketManager($auth) )->delete($bucket, str_replace($prefix . "/", "", img($file_path, 'small')));
- }
- }
-
+getQiniuConfig();
+ $config = $config_result[ "data" ];
+
+ if ($config[ "is_use" ] == 1) {
+ $config = $config[ "value" ];
+ $accessKey = $config[ "access_key" ];
+ $secretKey = $config[ "secret_key" ];
+ $bucket = $config[ "bucket" ];
+ $auth = new Auth($accessKey, $secretKey);
+ $token = $auth->uploadToken($bucket);
+ ( new BucketManager($auth) )->delete($bucket, $key);
+ $uploadMgr = new UploadManager();
+ //----------------------------------------upload demo1 ----------------------------------------
+ // 上传字符串到七牛
+ list($ret, $err) = $uploadMgr->put($token, $key, $data);
+ if ($err !== null) {
+ return $this->error('', $err->getResponse()->error);
+ } else {
+ //返回图片的完整URL
+ $domain = $config[ "domain" ];//自定义域名
+ $data = array (
+ "path" => $domain . "/" . $key,
+ "domain" => $domain,
+ "bucket" => $bucket
+ );
+ return $this->success($data);
+ }
+ }
+ }
+
+ /**
+ * 设置七牛参数配置
+ * @param unknown $filePath 上传图片路径
+ * @param unknown $key 上传到七牛后保存的文件名
+ */
+ public function putFile($param)
+ {
+ $file_path = $param[ "file_path" ];
+ $key = $param[ "key" ];
+ $config_model = new Config();
+ $config = $config_model->getQiniuConfig()[ "data" ];
+ if ($config[ "is_use" ] == 1) {
+ $config = $config[ "value" ];
+ $accessKey = $config[ "access_key" ];
+ $secretKey = $config[ "secret_key" ];
+ $bucket = $config[ "bucket" ];
+ $auth = new Auth($accessKey, $secretKey);
+ ( new BucketManager($auth) )->delete($bucket, $key);
+ //要上传的空间
+ $token = $auth->uploadToken($bucket);
+ // 初始化 UploadManager 对象并进行文件的上传
+ $uploadMgr = new UploadManager();
+ // 调用 UploadManager 的 putFile 方法进行文件的上传
+ list($ret, $err) = $uploadMgr->putFile($token, $key, $file_path);
+ if ($err !== null) {
+ return $this->error('', $err->getResponse()->error);
+ } else {
+ //返回图片的完整URL
+ $domain = $config[ "domain" ];//自定义域名
+ $data = array (
+ "path" => $domain . "/" . $key,
+ "domain" => $domain,
+ "bucket" => $bucket
+ );
+ return $this->success($data);
+ }
+ }
+ }
+
+ /**
+ * @param $file_path
+ * 删除七牛云图片
+ */
+ public function deleteAlbumPic($file_path, $prefix)
+ {
+ $config_model = new Config();
+ $config_result = $config_model->getQiniuConfig();
+ $config = $config_result[ "data" ];
+ if (!empty($config)) {
+ $config = $config[ "value" ];
+ $accessKey = $config[ "access_key" ];
+ $secretKey = $config[ "secret_key" ];
+ $bucket = $config[ "bucket" ];
+
+ $auth = new Auth($accessKey, $secretKey);
+// $prefix = substr($file_path,0,strripos($file_path, "/"));
+// dump(str_replace($prefix."/", "",$file_path));
+ ( new BucketManager($auth) )->delete($bucket, str_replace($prefix . "/", "", $file_path));
+ ( new BucketManager($auth) )->delete($bucket, str_replace($prefix . "/", "", img($file_path, 'big')));
+ ( new BucketManager($auth) )->delete($bucket, str_replace($prefix . "/", "", img($file_path, 'mid')));
+ ( new BucketManager($auth) )->delete($bucket, str_replace($prefix . "/", "", img($file_path, 'small')));
+ }
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/qiniu/shop/controller/Config.php b/src/addon/qiniu/shop/controller/Config.php
index c69ef4ba8..4dd0b89b7 100644
--- a/src/addon/qiniu/shop/controller/Config.php
+++ b/src/addon/qiniu/shop/controller/Config.php
@@ -1,52 +1,43 @@
-isJson()) {
- $bucket = input('bucket', '');
- $access_key = input('access_key', '');
- $secret_key = input('secret_key', '');
- $domain = input('domain', '');
- $status = input('status', 0);
- $data = array(
- 'bucket' => $bucket,
- 'access_key' => $access_key,
- 'secret_key' => $secret_key,
- 'domain' => $domain,
- );
-
- $result = $config_model->setQiniuConfig($data, $status, $this->site_id, $this->app_module);
- return $result;
- } else {
- $info_result = $config_model->getQiniuConfig($this->site_id, $this->app_module);
- $info = $info_result['data'];
- $this->assign('info', $info);
- return $this->fetch('config/config');
- }
- }
+isJson()) {
+ $bucket = input('bucket', '');
+ $access_key = input('access_key', '');
+ $secret_key = input('secret_key', '');
+ $domain = input('domain', '');
+ $status = input('status', 0);
+ $data = array(
+ 'bucket' => $bucket,
+ 'access_key' => $access_key,
+ 'secret_key' => $secret_key,
+ 'domain' => $domain,
+ );
+
+ $result = $config_model->setQiniuConfig($data, $status, $this->site_id, $this->app_module);
+ return $result;
+ } else {
+ $info_result = $config_model->getQiniuConfig($this->site_id, $this->app_module);
+ $info = $info_result['data'];
+ $this->assign('info', $info);
+ return $this->fetch('config/config');
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/seckill/api/controller/Seckill.php b/src/addon/seckill/api/controller/Seckill.php
index d4850b0dd..bb0a4d547 100644
--- a/src/addon/seckill/api/controller/Seckill.php
+++ b/src/addon/seckill/api/controller/Seckill.php
@@ -1,68 +1,60 @@
-site_id ],
- [ 'seckill_end_time', '>=', $time ]
- ];
- $order = 'seckill_start_time asc';
- $field = 'id,name,seckill_start_time,seckill_end_time';
-
- $seckill_model = new SeckillModel();
- $today_list = $seckill_model->getGoodsSeckillTimeList($condition, $field, $order);
- $today_list = is_array($today_list[ 'data' ]) ? array_values($today_list[ 'data' ]) : [];
- foreach ($today_list as $key => $val) {
- $val = $seckill_model->transformSeckillTime($val);
- $today_list[ $key ][ 'seckill_start_time_show' ] = "{$val['start_hour']}:{$val['start_minute']}:{$val['start_second']}";
- $today_list[ $key ][ 'seckill_end_time_show' ] = "{$val['end_hour']}:{$val['end_minute']}:{$val['end_second']}";
- $today_list[ $key ][ 'type' ] = "today";
- }
-
- $condition = [
- [ 'site_id', '=', $this->site_id ],
- [ 'seckill_end_time', '<', $time ]
- ];
-
- $tomorrow_list = $seckill_model->getGoodsSeckillTimeList($condition, $field, $order);
- $tomorrow_list = is_array($tomorrow_list[ 'data' ]) ? array_values($tomorrow_list[ 'data' ]) : [];
- foreach ($tomorrow_list as $key => $val) {
- $val = $seckill_model->transformSeckillTime($val);
- $tomorrow_list[ $key ][ 'seckill_start_time_show' ] = "{$val['start_hour']}:{$val['start_minute']}:{$val['start_second']}";
- $tomorrow_list[ $key ][ 'seckill_end_time_show' ] = "{$val['end_hour']}:{$val['end_minute']}:{$val['end_second']}";
- $tomorrow_list[ $key ][ 'type' ] = "tomorrow";
- }
-
- $res = [
- 'list' => array_merge($today_list, $tomorrow_list)
- ];
- return $this->response($this->success($res));
- }
+site_id ],
+ [ 'seckill_end_time', '>=', $time ]
+ ];
+ $order = 'seckill_start_time asc';
+ $field = 'id,name,seckill_start_time,seckill_end_time';
+
+ $seckill_model = new SeckillModel();
+ $today_list = $seckill_model->getGoodsSeckillTimeList($condition, $field, $order);
+ $today_list = is_array($today_list[ 'data' ]) ? array_values($today_list[ 'data' ]) : [];
+ foreach ($today_list as $key => $val) {
+ $val = $seckill_model->transformSeckillTime($val);
+ $today_list[ $key ][ 'seckill_start_time_show' ] = "{$val['start_hour']}:{$val['start_minute']}:{$val['start_second']}";
+ $today_list[ $key ][ 'seckill_end_time_show' ] = "{$val['end_hour']}:{$val['end_minute']}:{$val['end_second']}";
+ $today_list[ $key ][ 'type' ] = "today";
+ }
+
+ $condition = [
+ [ 'site_id', '=', $this->site_id ],
+ [ 'seckill_end_time', '<', $time ]
+ ];
+
+ $tomorrow_list = $seckill_model->getGoodsSeckillTimeList($condition, $field, $order);
+ $tomorrow_list = is_array($tomorrow_list[ 'data' ]) ? array_values($tomorrow_list[ 'data' ]) : [];
+ foreach ($tomorrow_list as $key => $val) {
+ $val = $seckill_model->transformSeckillTime($val);
+ $tomorrow_list[ $key ][ 'seckill_start_time_show' ] = "{$val['start_hour']}:{$val['start_minute']}:{$val['start_second']}";
+ $tomorrow_list[ $key ][ 'seckill_end_time_show' ] = "{$val['end_hour']}:{$val['end_minute']}:{$val['end_second']}";
+ $tomorrow_list[ $key ][ 'type' ] = "tomorrow";
+ }
+
+ $res = [
+ 'list' => array_merge($today_list, $tomorrow_list)
+ ];
+ return $this->response($this->success($res));
+ }
}
\ No newline at end of file
diff --git a/src/addon/seckill/api/controller/Seckillgoods.php b/src/addon/seckill/api/controller/Seckillgoods.php
index c3d62b56e..7809b281e 100644
--- a/src/addon/seckill/api/controller/Seckillgoods.php
+++ b/src/addon/seckill/api/controller/Seckillgoods.php
@@ -1,222 +1,214 @@
-params[ 'seckill_id' ] ?? 0;
- $sku_id = $this->params[ 'sku_id' ] ?? 0;
- if (empty($seckill_id)) {
- return $this->response($this->error('', 'REQUEST_ID'));
- }
- if (empty($sku_id)) {
- return $this->response($this->error('', 'REQUEST_ID'));
- }
- $seckill_model = new SeckillModel();
- $order_model = new SeckillOrder();
- $condition = [
- [ 'ps.id', '=', $seckill_id ],
- [ 'psg.sku_id', '=', $sku_id ],
- [ 'psg.site_id', '=', $this->site_id ],
- [ 'psg.status', '=', 1 ],
- [ 'ps.status', '=', 1 ],
- [ 'g.goods_state', '=', 1 ],
- [ 'g.is_delete', '=', 0 ]
- ];
- $goods_sku_detail = $seckill_model->getSeckillGoodsInfo($condition, '')[ 'data' ];
-
- $res[ 'goods_sku_detail' ] = $goods_sku_detail;
- if (!empty($goods_sku_detail)) {
- $num = $order_model->getGoodsSeckillNum($seckill_id);
- $time_data = $seckill_model->getSeckillInfo($seckill_id)[ 'data' ];
- $goods_sku_detail[ 'sale_num' ] = $num;
- $goods_sku_detail[ 'seckill_start_time' ] = $time_data[ 'seckill_start_time' ];
- $goods_sku_detail[ 'seckill_end_time' ] = $time_data[ 'seckill_end_time' ];
- //判断商品规格项
- $goods_spec_format = $seckill_model->getGoodsSpecFormat($seckill_id, $this->site_id, $goods_sku_detail[ 'goods_spec_format' ]);
- $res[ 'goods_sku_detail' ][ 'goods_spec_format' ] = json_encode($goods_spec_format);
- } else {
- $sku_id = $seckill_model->getGoodsSpecFormat($seckill_id, $this->site_id, '');
- $res = [ 'type' => 'again', 'sku_id' => $sku_id ];
- }
- return $this->response($this->success($res));
- }
-
- /**
- * 详情信息
- */
- public function detail()
- {
- $this->checkToken();
- $seckill_id = $this->params[ 'seckill_id' ] ?? 0;
- if (empty($seckill_id)) {
- return $this->response($this->error('', 'REQUEST_ID'));
- }
- $seckill_model = new SeckillModel();
- $condition = [
- [ 'ps.id', '=', $seckill_id ],
- [ 'psg.site_id', '=', $this->site_id ],
- [ 'psg.status', '=', 1 ],
- [ 'ps.status', '=', 1 ],
- [ 'g.goods_state', '=', 1 ],
- [ 'g.is_delete', '=', 0 ]
- ];
- $goods_sku_detail = $seckill_model->getSeckillGoodsInfo($condition)[ 'data' ];
-
- $time_data = $seckill_model->getSeckillInfo($seckill_id)[ 'data' ];
- $goods_sku_detail[ 'seckill_start_time' ] = $time_data[ 'seckill_start_time' ];
- $goods_sku_detail[ 'seckill_end_time' ] = $time_data[ 'seckill_end_time' ];
-
- $res[ 'goods_sku_detail' ] = $goods_sku_detail;
- if (empty($goods_sku_detail)) return $this->response($this->error($res));
-
- if (!empty($goods_sku_detail[ 'goods_spec_format' ])) {
- //判断商品规格项
- $goods_spec_format = $seckill_model->getGoodsSpecFormat($seckill_id, $this->site_id, $goods_sku_detail[ 'goods_spec_format' ]);
- $res[ 'goods_sku_detail' ][ 'goods_spec_format' ] = json_encode($goods_spec_format);
- }
-
- // 处理公共数据
- $goods_sku_api = new GoodsApi();
- $goods_sku_api->handleGoodsDetailData($res[ 'goods_sku_detail' ], $this->member_id, $this->site_id);
-
- return $this->response($this->success($res));
- }
-
- /**
- * 查询商品SKU集合
- * @return false|string
- */
- public function goodsSku()
- {
- $goods_id = $this->params[ 'goods_id' ] ?? 0;
- $seckill_id = $this->params[ 'seckill_id' ] ?? 0;
- if (empty($goods_id)) {
- return $this->response($this->error('', 'REQUEST_ID'));
- }
- if (empty($seckill_id)) {
- return $this->response($this->error('', 'REQUEST_ID'));
- }
- $seckill_model = new SeckillModel();
- $condition = [
- [ 'ps.id', '=', $seckill_id ],
- [ 'psg.goods_id', '=', $goods_id ],
- [ 'psg.site_id', '=', $this->site_id ],
- [ 'psg.status', '=', 1 ],
- [ 'ps.status', '=', 1 ],
- [ 'g.goods_state', '=', 1 ],
- [ 'g.is_delete', '=', 0 ]
- ];
- $list = $seckill_model->getSeckillGoodsSkuList($condition);
- if (!empty($list[ 'data' ])) {
- foreach ($list[ 'data' ] as $k => $v) {
- if (!empty($v[ 'goods_spec_format' ])) {
- //判断商品规格项
- $goods_spec_format = $seckill_model->getGoodsSpecFormat($seckill_id, $this->site_id, $v[ 'goods_spec_format' ]);
- $list[ 'data' ][ $k ][ 'goods_spec_format' ] = json_encode($goods_spec_format);
- }
- }
- }
- return $this->response($list);
- }
-
- public function page()
- {
- $seckill_time_id = $this->params[ 'seckill_time_id' ] ?? 0;
- $page = $this->params[ 'page' ] ?? 1;
- $page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
- if (empty($seckill_time_id)) {
- return $this->response($this->error('', 'REQUEST_SECKILL_ID'));
- }
-
- $seckill_model = new SeckillModel();
- $res = $seckill_model->getSeckillGoodsPageList($seckill_time_id, $this->site_id, $page, $page_size);
- foreach ($res[ 'data' ][ 'list' ] as $key => $val) {
- if ($val[ 'price' ] != 0) {
- $discount_rate = floor($val[ 'seckill_price' ] / $val[ 'price' ] * 100);
- } else {
- $discount_rate = 100;
- }
- $res[ 'data' ][ 'list' ][ $key ][ 'discount_rate' ] = $discount_rate;
- }
- return $this->response($res);
- }
-
- public function lists()
- {
- $seckill_time_id = $this->params[ 'seckill_time_id' ] ?? 0;
- $num = $this->params[ 'num' ] ?? null;
-
- if (empty($seckill_time_id)) {
- return $this->response($this->error('', 'REQUEST_SECKILL_ID'));
- }
-
- $seckill_model = new SeckillModel();
- $res = $seckill_model->getSeckillList($seckill_time_id, $this->site_id, $num);
- $list = $res[ 'data' ];
- foreach ($list as $key => $val) {
- if ($val[ 'price' ] != 0) {
- $discount_rate = floor($val[ 'seckill_price' ] / $val[ 'price' ] * 100);
- } else {
- $discount_rate = 100;
- }
- $list[ $key ][ 'discount_rate' ] = $discount_rate;
- }
-
- return $this->response($this->success($list));
- }
-
- /**
- * 获取商品海报
- */
- public function poster()
- {
- $this->checkToken();
-
- $promotion_type = 'seckill';
- $qrcode_param = json_decode($this->params[ 'qrcode_param' ], true);
- $qrcode_param[ 'source_member' ] = $this->member_id;
- $poster = new Poster();
- $res = $poster->goods($this->params[ 'app_type' ], $this->params[ 'page' ], $qrcode_param, $promotion_type, $this->site_id);
- return $this->response($res);
- }
-
- /**
- * 分享图片
- * @return false|string
- */
- public function shareImg()
- {
- $qrcode_param = json_decode($this->params[ 'qrcode_param' ], true);
-
- $poster = new Poster();
- $res = $poster->shareImg($this->params[ 'page' ] ?? '', $qrcode_param, $this->site_id);
- return $this->response($res);
- }
+params[ 'seckill_id' ] ?? 0;
+ $sku_id = $this->params[ 'sku_id' ] ?? 0;
+ if (empty($seckill_id)) {
+ return $this->response($this->error('', 'REQUEST_ID'));
+ }
+ if (empty($sku_id)) {
+ return $this->response($this->error('', 'REQUEST_ID'));
+ }
+ $seckill_model = new SeckillModel();
+ $order_model = new SeckillOrder();
+ $condition = [
+ [ 'ps.id', '=', $seckill_id ],
+ [ 'psg.sku_id', '=', $sku_id ],
+ [ 'psg.site_id', '=', $this->site_id ],
+ [ 'psg.status', '=', 1 ],
+ [ 'ps.status', '=', 1 ],
+ [ 'g.goods_state', '=', 1 ],
+ [ 'g.is_delete', '=', 0 ]
+ ];
+ $goods_sku_detail = $seckill_model->getSeckillGoodsInfo($condition, '')[ 'data' ];
+
+ $res[ 'goods_sku_detail' ] = $goods_sku_detail;
+ if (!empty($goods_sku_detail)) {
+ $num = $order_model->getGoodsSeckillNum($seckill_id);
+ $time_data = $seckill_model->getSeckillInfo($seckill_id)[ 'data' ];
+ $goods_sku_detail[ 'sale_num' ] = $num;
+ $goods_sku_detail[ 'seckill_start_time' ] = $time_data[ 'seckill_start_time' ];
+ $goods_sku_detail[ 'seckill_end_time' ] = $time_data[ 'seckill_end_time' ];
+ //判断商品规格项
+ $goods_spec_format = $seckill_model->getGoodsSpecFormat($seckill_id, $this->site_id, $goods_sku_detail[ 'goods_spec_format' ]);
+ $res[ 'goods_sku_detail' ][ 'goods_spec_format' ] = json_encode($goods_spec_format);
+ } else {
+ $sku_id = $seckill_model->getGoodsSpecFormat($seckill_id, $this->site_id, '');
+ $res = [ 'type' => 'again', 'sku_id' => $sku_id ];
+ }
+ return $this->response($this->success($res));
+ }
+
+ /**
+ * 详情信息
+ */
+ public function detail()
+ {
+ $this->checkToken();
+ $seckill_id = $this->params[ 'seckill_id' ] ?? 0;
+ if (empty($seckill_id)) {
+ return $this->response($this->error('', 'REQUEST_ID'));
+ }
+ $seckill_model = new SeckillModel();
+ $condition = [
+ [ 'ps.id', '=', $seckill_id ],
+ [ 'psg.site_id', '=', $this->site_id ],
+ [ 'psg.status', '=', 1 ],
+ [ 'ps.status', '=', 1 ],
+ [ 'g.goods_state', '=', 1 ],
+ [ 'g.is_delete', '=', 0 ]
+ ];
+ $goods_sku_detail = $seckill_model->getSeckillGoodsInfo($condition)[ 'data' ];
+
+ $time_data = $seckill_model->getSeckillInfo($seckill_id)[ 'data' ];
+ $goods_sku_detail[ 'seckill_start_time' ] = $time_data[ 'seckill_start_time' ];
+ $goods_sku_detail[ 'seckill_end_time' ] = $time_data[ 'seckill_end_time' ];
+
+ $res[ 'goods_sku_detail' ] = $goods_sku_detail;
+ if (empty($goods_sku_detail)) return $this->response($this->error($res));
+
+ if (!empty($goods_sku_detail[ 'goods_spec_format' ])) {
+ //判断商品规格项
+ $goods_spec_format = $seckill_model->getGoodsSpecFormat($seckill_id, $this->site_id, $goods_sku_detail[ 'goods_spec_format' ]);
+ $res[ 'goods_sku_detail' ][ 'goods_spec_format' ] = json_encode($goods_spec_format);
+ }
+
+ // 处理公共数据
+ $goods_sku_api = new GoodsApi();
+ $goods_sku_api->handleGoodsDetailData($res[ 'goods_sku_detail' ], $this->member_id, $this->site_id);
+
+ return $this->response($this->success($res));
+ }
+
+ /**
+ * 查询商品SKU集合
+ * @return false|string
+ */
+ public function goodsSku()
+ {
+ $goods_id = $this->params[ 'goods_id' ] ?? 0;
+ $seckill_id = $this->params[ 'seckill_id' ] ?? 0;
+ if (empty($goods_id)) {
+ return $this->response($this->error('', 'REQUEST_ID'));
+ }
+ if (empty($seckill_id)) {
+ return $this->response($this->error('', 'REQUEST_ID'));
+ }
+ $seckill_model = new SeckillModel();
+ $condition = [
+ [ 'ps.id', '=', $seckill_id ],
+ [ 'psg.goods_id', '=', $goods_id ],
+ [ 'psg.site_id', '=', $this->site_id ],
+ [ 'psg.status', '=', 1 ],
+ [ 'ps.status', '=', 1 ],
+ [ 'g.goods_state', '=', 1 ],
+ [ 'g.is_delete', '=', 0 ]
+ ];
+ $list = $seckill_model->getSeckillGoodsSkuList($condition);
+ if (!empty($list[ 'data' ])) {
+ foreach ($list[ 'data' ] as $k => $v) {
+ if (!empty($v[ 'goods_spec_format' ])) {
+ //判断商品规格项
+ $goods_spec_format = $seckill_model->getGoodsSpecFormat($seckill_id, $this->site_id, $v[ 'goods_spec_format' ]);
+ $list[ 'data' ][ $k ][ 'goods_spec_format' ] = json_encode($goods_spec_format);
+ }
+ }
+ }
+ return $this->response($list);
+ }
+
+ public function page()
+ {
+ $seckill_time_id = $this->params[ 'seckill_time_id' ] ?? 0;
+ $page = $this->params[ 'page' ] ?? 1;
+ $page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
+ if (empty($seckill_time_id)) {
+ return $this->response($this->error('', 'REQUEST_SECKILL_ID'));
+ }
+
+ $seckill_model = new SeckillModel();
+ $res = $seckill_model->getSeckillGoodsPageList($seckill_time_id, $this->site_id, $page, $page_size);
+ foreach ($res[ 'data' ][ 'list' ] as $key => $val) {
+ if ($val[ 'price' ] != 0) {
+ $discount_rate = floor($val[ 'seckill_price' ] / $val[ 'price' ] * 100);
+ } else {
+ $discount_rate = 100;
+ }
+ $res[ 'data' ][ 'list' ][ $key ][ 'discount_rate' ] = $discount_rate;
+ }
+ return $this->response($res);
+ }
+
+ public function lists()
+ {
+ $seckill_time_id = $this->params[ 'seckill_time_id' ] ?? 0;
+ $num = $this->params[ 'num' ] ?? null;
+
+ if (empty($seckill_time_id)) {
+ return $this->response($this->error('', 'REQUEST_SECKILL_ID'));
+ }
+
+ $seckill_model = new SeckillModel();
+ $res = $seckill_model->getSeckillList($seckill_time_id, $this->site_id, $num);
+ $list = $res[ 'data' ];
+ foreach ($list as $key => $val) {
+ if ($val[ 'price' ] != 0) {
+ $discount_rate = floor($val[ 'seckill_price' ] / $val[ 'price' ] * 100);
+ } else {
+ $discount_rate = 100;
+ }
+ $list[ $key ][ 'discount_rate' ] = $discount_rate;
+ }
+
+ return $this->response($this->success($list));
+ }
+
+ /**
+ * 获取商品海报
+ */
+ public function poster()
+ {
+ $this->checkToken();
+
+ $promotion_type = 'seckill';
+ $qrcode_param = json_decode($this->params[ 'qrcode_param' ], true);
+ $qrcode_param[ 'source_member' ] = $this->member_id;
+ $poster = new Poster();
+ $res = $poster->goods($this->params[ 'app_type' ], $this->params[ 'page' ], $qrcode_param, $promotion_type, $this->site_id);
+ return $this->response($res);
+ }
+
+ /**
+ * 分享图片
+ * @return false|string
+ */
+ public function shareImg()
+ {
+ $qrcode_param = json_decode($this->params[ 'qrcode_param' ], true);
+
+ $poster = new Poster();
+ $res = $poster->shareImg($this->params[ 'page' ] ?? '', $qrcode_param, $this->site_id);
+ return $this->response($res);
+ }
}
\ No newline at end of file
diff --git a/src/addon/seckill/config/diy_view.php b/src/addon/seckill/config/diy_view.php
index 1aaa55c20..54667403e 100644
--- a/src/addon/seckill/config/diy_view.php
+++ b/src/addon/seckill/config/diy_view.php
@@ -1,68 +1,59 @@
- '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
- 'template' => [],
-
- // 后台自定义组件——装修
- 'util' => [
- [
- 'name' => 'Seckill',
- 'title' => '秒杀',
- 'type' => 'PROMOTION',
- 'value' => '{"style":"style-1","sources":"initial","count":6,"goodsId":[],"goodsMarginType":"default","goodsMarginNum":10,"ornament":{"type":"default","color":"#EDEDED"},"nameLineMode":"single","template":"row1-of1","btnStyle":{"text":"去秒杀","textColor":"#FFFFFF","theme":"default","aroundRadius":25,"control":true,"support":true,"bgColorStart":"#FF7B1D","bgColorEnd":"#FF1544"},"imgAroundRadius":5,"saleStyle":{"color":"#999CA7","control":true,"support":true},"progressStyle":{"control":true,"support":true,"currColor":"#FDBE6C","bgColor":"#FCECD7"},"titleStyle":{"backgroundImage":"","isShow":true,"leftStyle":"text","leftImg":"","style":"style-1","styleName":"风格1","leftText":"限时秒杀","fontSize":16,"fontWeight":true,"textColor":"#303133","bgColorStart":"#FFFFFF","bgColorEnd":"#FFFFFF","more":"查看更多","moreColor":"#999999","moreFontSize":12,"timeBgColor":"","timeImageUrl":"","moreSupport":true,"colonColor":"#303133","numBgColorStart":"#303133","numBgColorEnd":"#303133","numTextColor":"#FFFFFF"},"slideMode":"scroll","theme":"default","priceStyle":{"mainColor":"#FF1745","mainControl":true,"lineColor":"#999CA7","lineControl":true,"lineSupport":true},"goodsNameStyle":{"color":"#303133","control":true,"fontWeight":false}}',
- 'sort' => '30003',
- 'support_diy_view' => '',
- 'max_count' => 1,
- 'icon' => 'iconfont iconmiaosha1'
- ]
- ],
-
- // 自定义页面路径
- 'link' => [
- [
- 'name' => 'SECKILL',
- 'title' => '秒杀',
- 'parent' => 'MARKETING_LINK',
- 'wap_url' => '',
- 'web_url' => '',
- 'sort' => 0,
- 'child_list' => [
- [
- 'name' => 'SECKILL_PREFECTURE',
- 'title' => '秒杀抢购',
- 'wap_url' => '/pages_promotion/seckill/list',
- 'web_url' => '',
- 'sort' => 0
- ]
- ]
- ]
- ],
-
- // 自定义图标库
- 'icon_library' => [],
-
- // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
- 'component' => [],
-
- // uni-app 页面,多个逗号隔开
- 'pages' => [],
-
- // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
- 'info' => [],
-
- // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
- 'theme' => [],
-
- // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
- 'data' => []
+ '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
+ 'template' => [],
+
+ // 后台自定义组件——装修
+ 'util' => [
+ [
+ 'name' => 'Seckill',
+ 'title' => '秒杀',
+ 'type' => 'PROMOTION',
+ 'value' => '{"style":"style-1","sources":"initial","count":6,"goodsId":[],"goodsMarginType":"default","goodsMarginNum":10,"ornament":{"type":"default","color":"#EDEDED"},"nameLineMode":"single","template":"row1-of1","btnStyle":{"text":"去秒杀","textColor":"#FFFFFF","theme":"default","aroundRadius":25,"control":true,"support":true,"bgColorStart":"#FF7B1D","bgColorEnd":"#FF1544"},"imgAroundRadius":5,"saleStyle":{"color":"#999CA7","control":true,"support":true},"progressStyle":{"control":true,"support":true,"currColor":"#FDBE6C","bgColor":"#FCECD7"},"titleStyle":{"backgroundImage":"","isShow":true,"leftStyle":"text","leftImg":"","style":"style-1","styleName":"风格1","leftText":"限时秒杀","fontSize":16,"fontWeight":true,"textColor":"#303133","bgColorStart":"#FFFFFF","bgColorEnd":"#FFFFFF","more":"查看更多","moreColor":"#999999","moreFontSize":12,"timeBgColor":"","timeImageUrl":"","moreSupport":true,"colonColor":"#303133","numBgColorStart":"#303133","numBgColorEnd":"#303133","numTextColor":"#FFFFFF"},"slideMode":"scroll","theme":"default","priceStyle":{"mainColor":"#FF1745","mainControl":true,"lineColor":"#999CA7","lineControl":true,"lineSupport":true},"goodsNameStyle":{"color":"#303133","control":true,"fontWeight":false}}',
+ 'sort' => '30003',
+ 'support_diy_view' => '',
+ 'max_count' => 1,
+ 'icon' => 'iconfont iconmiaosha1'
+ ]
+ ],
+
+ // 自定义页面路径
+ 'link' => [
+ [
+ 'name' => 'SECKILL',
+ 'title' => '秒杀',
+ 'parent' => 'MARKETING_LINK',
+ 'wap_url' => '',
+ 'web_url' => '',
+ 'sort' => 0,
+ 'child_list' => [
+ [
+ 'name' => 'SECKILL_PREFECTURE',
+ 'title' => '秒杀抢购',
+ 'wap_url' => '/pages_promotion/seckill/list',
+ 'web_url' => '',
+ 'sort' => 0
+ ]
+ ]
+ ]
+ ],
+
+ // 自定义图标库
+ 'icon_library' => [],
+
+ // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
+ 'component' => [],
+
+ // uni-app 页面,多个逗号隔开
+ 'pages' => [],
+
+ // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
+ 'info' => [],
+
+ // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
+ 'theme' => [],
+
+ // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
+ 'data' => []
];
\ No newline at end of file
diff --git a/src/addon/seckill/config/info.php b/src/addon/seckill/config/info.php
index dfcb72c00..52b51dd42 100644
--- a/src/addon/seckill/config/info.php
+++ b/src/addon/seckill/config/info.php
@@ -1,20 +1,12 @@
- 'seckill',
- 'title' => '秒杀抢购',
- 'description' => '低价、限购,吸引更多会员',
- 'type' => 'promotion', //插件类型 system :系统插件 promotion:营销插件 tool:工具插件
- 'status' => 1,
- 'author' => '',
- 'version' => '5.3.1',
- 'version_no' => '525231212001',
- 'content' => '',
+ 'seckill',
+ 'title' => '秒杀抢购',
+ 'description' => '低价、限购,吸引更多会员',
+ 'type' => 'promotion', //插件类型 system :系统插件 promotion:营销插件 tool:工具插件
+ 'status' => 1,
+ 'author' => '',
+ 'version' => '5.3.1',
+ 'version_no' => '525231212001',
+ 'content' => '',
];
\ No newline at end of file
diff --git a/src/addon/seckill/event/CloseSeckill.php b/src/addon/seckill/event/CloseSeckill.php
index 918f7a957..66fd2e8c4 100644
--- a/src/addon/seckill/event/CloseSeckill.php
+++ b/src/addon/seckill/event/CloseSeckill.php
@@ -1,27 +1,19 @@
-cronCloseSeckill($params[ 'relate_id' ]);
- return $res;
- }
+cronCloseSeckill($params[ 'relate_id' ]);
+ return $res;
+ }
}
\ No newline at end of file
diff --git a/src/addon/seckill/event/CronOrderClose.php b/src/addon/seckill/event/CronOrderClose.php
index ac59a05ea..b68b17f54 100644
--- a/src/addon/seckill/event/CronOrderClose.php
+++ b/src/addon/seckill/event/CronOrderClose.php
@@ -1,33 +1,25 @@
-cronOrderClose($params[ 'order_id' ]);
- return $res;
- }
-
+cronOrderClose($params[ 'order_id' ]);
+ return $res;
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/seckill/event/GoodsPromotion.php b/src/addon/seckill/event/GoodsPromotion.php
index 536a355b7..fe8602cfa 100644
--- a/src/addon/seckill/event/GoodsPromotion.php
+++ b/src/addon/seckill/event/GoodsPromotion.php
@@ -1,65 +1,56 @@
- 'seckill',
- 'promotion_name' => '限时秒杀',
- 'id' => $promotion_addon['seckill']
- ];
- }
- }
-
- } else {
- if (empty($param['goods_id'])) return [];
- $goods_model = new GoodsModel();
- $goods_info = $goods_model->getGoodsInfo([['goods_id', '=', $param['goods_id']]], 'promotion_addon')['data'];
- if (!empty($goods_info['promotion_addon'])) {
- $promotion_addon = json_decode($goods_info['promotion_addon'], true);
- if (!empty($promotion_addon['seckill'])) {
- $seckill_model = new Seckill();
- $goods_detail = $seckill_model->getSeckillInfo($promotion_addon['seckill'])['data'];
- if (!empty($goods_detail)) {
- $time = time() - strtotime(date('Y-m-d'), time());
- if ($time > $goods_detail['seckill_start_time'] && $time < $goods_detail['seckill_end_time']) {
- $goods_detail['promotion_type'] = 'seckill';
- $goods_detail['promotion_name'] = '限时秒杀';
- return $goods_detail;
- }
- }
- }
- }
- return [];
- }
- }
+ 'seckill',
+ 'promotion_name' => '限时秒杀',
+ 'id' => $promotion_addon['seckill']
+ ];
+ }
+ }
+
+ } else {
+ if (empty($param['goods_id'])) return [];
+ $goods_model = new GoodsModel();
+ $goods_info = $goods_model->getGoodsInfo([['goods_id', '=', $param['goods_id']]], 'promotion_addon')['data'];
+ if (!empty($goods_info['promotion_addon'])) {
+ $promotion_addon = json_decode($goods_info['promotion_addon'], true);
+ if (!empty($promotion_addon['seckill'])) {
+ $seckill_model = new Seckill();
+ $goods_detail = $seckill_model->getSeckillInfo($promotion_addon['seckill'])['data'];
+ if (!empty($goods_detail)) {
+ $time = time() - strtotime(date('Y-m-d'), time());
+ if ($time > $goods_detail['seckill_start_time'] && $time < $goods_detail['seckill_end_time']) {
+ $goods_detail['promotion_type'] = 'seckill';
+ $goods_detail['promotion_name'] = '限时秒杀';
+ return $goods_detail;
+ }
+ }
+ }
+ }
+ return [];
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/seckill/event/GoodsPromotionType.php b/src/addon/seckill/event/GoodsPromotionType.php
index bd151c100..236f0e035 100644
--- a/src/addon/seckill/event/GoodsPromotionType.php
+++ b/src/addon/seckill/event/GoodsPromotionType.php
@@ -1,28 +1,19 @@
- '限时秒杀', 'short' => '秒', 'type' => 'seckill', 'color' => '#89689D', 'url' => 'seckill://shop/seckill/goodslist'];
- }
+ '限时秒杀', 'short' => '秒', 'type' => 'seckill', 'color' => '#89689D', 'url' => 'seckill://shop/seckill/goodslist'];
+ }
}
\ No newline at end of file
diff --git a/src/addon/seckill/event/Install.php b/src/addon/seckill/event/Install.php
index 31c4e9355..a934f3b73 100644
--- a/src/addon/seckill/event/Install.php
+++ b/src/addon/seckill/event/Install.php
@@ -1,32 +1,24 @@
-getMessage());
- } */
- return success();
- }
+getMessage());
+ } */
+ return success();
+ }
}
\ No newline at end of file
diff --git a/src/addon/seckill/event/OpenSeckill.php b/src/addon/seckill/event/OpenSeckill.php
index 80d0aba4c..4690311e7 100644
--- a/src/addon/seckill/event/OpenSeckill.php
+++ b/src/addon/seckill/event/OpenSeckill.php
@@ -1,27 +1,19 @@
-cronOpenSeckill($params[ 'relate_id' ]);
- return $res;
- }
+cronOpenSeckill($params[ 'relate_id' ]);
+ return $res;
+ }
}
\ No newline at end of file
diff --git a/src/addon/seckill/event/OrderPromotionType.php b/src/addon/seckill/event/OrderPromotionType.php
index 9974b15a9..38d4dffcd 100644
--- a/src/addon/seckill/event/OrderPromotionType.php
+++ b/src/addon/seckill/event/OrderPromotionType.php
@@ -1,27 +1,19 @@
- "秒杀", "type" => "seckill" ];
- }
+ "秒杀", "type" => "seckill" ];
+ }
}
\ No newline at end of file
diff --git a/src/addon/seckill/event/PromotionType.php b/src/addon/seckill/event/PromotionType.php
index 2c7cb54d4..c14fbc4dc 100644
--- a/src/addon/seckill/event/PromotionType.php
+++ b/src/addon/seckill/event/PromotionType.php
@@ -1,27 +1,19 @@
- "秒杀", "type" => "seckill" ];
- }
+ "秒杀", "type" => "seckill" ];
+ }
}
\ No newline at end of file
diff --git a/src/addon/seckill/event/SeckillZoneConfig.php b/src/addon/seckill/event/SeckillZoneConfig.php
index de7e80aa7..1976fc825 100644
--- a/src/addon/seckill/event/SeckillZoneConfig.php
+++ b/src/addon/seckill/event/SeckillZoneConfig.php
@@ -1,37 +1,29 @@
- 'seckill', // 标识
- 'title' => '限时秒杀', // 名称
- 'url' => 'shop/adv/lists?keyword=NS_SECKILL', // 自定义跳转链接
- 'preview' => 'addon/seckill/shop/view/public/img/zone_preview.png', // 预览图
- // 页面配置
- 'value' => [
- 'bg_color' => '#F83530'
- ],
- ];
- return $data;
- }
- }
-
+ 'seckill', // 标识
+ 'title' => '限时秒杀', // 名称
+ 'url' => 'shop/adv/lists?keyword=NS_SECKILL', // 自定义跳转链接
+ 'preview' => 'addon/seckill/shop/view/public/img/zone_preview.png', // 预览图
+ // 页面配置
+ 'value' => [
+ 'bg_color' => '#F83530'
+ ],
+ ];
+ return $data;
+ }
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/seckill/event/ShowPromotion.php b/src/addon/seckill/event/ShowPromotion.php
index d6a9c0dcc..f95847aea 100644
--- a/src/addon/seckill/event/ShowPromotion.php
+++ b/src/addon/seckill/event/ShowPromotion.php
@@ -1,91 +1,83 @@
- [
- [
- //插件名称
- 'name' => 'seckill',
- //展示分类(根据平台端设置,shop:店铺营销,member:会员营销, tool:应用工具)
- 'show_type' => 'shop',
- //展示主题
- 'title' => '限时秒杀',
- //展示介绍
- 'description' => '限时抢购引导客户快速下单',
- //展示图标
- 'icon' => 'addon/seckill/icon.png',
- //跳转链接
- 'url' => 'seckill://shop/seckill/goodslist',
- 'summary' => $this->summary($params)
- ]
- ]
-
- ];
- return $data;
- }
-
- /**
- * 营销活动概况
- * @param $params
- * @return array
- */
- private function summary($params)
- {
- if (empty($params)) {
- return [];
- }
-
- if(isset($params['promotion_type']) && $params['promotion_type'] != $this->promotion_type){
- return [];
- }
-
- //获取活动数量
- if (isset($params[ 'count' ])) {
- $count = model("promotion_seckill")->getCount([ [ 'site_id', '=', $params[ 'site_id' ] ] ]);
- return [
- 'count' => $count
- ];
- }
- //获取活动概况,需要获取开始时间与结束时间
- if (isset($params[ 'summary' ])) {
- $list = model("promotion_seckill")->getList([
- [ '', 'exp', Db::raw('not ( (`start_time` >= ' . $params[ 'end_time' ] . ') or (`end_time` <= ' . $params[ 'start_time' ] . '))') ],
- [ 'site_id', '=', $params[ 'site_id' ] ],
- [ 'status', '<>', 2 ],
- [ 'status', '<>', -1 ]
- ], 'seckill_name as promotion_name,id as promotion_id,start_time,end_time', '', 'a', null, 'seckill_name');
- return !empty($list) ? [
- 'time_limit' => [
- 'count' => count($list),
- 'detail' => $list,
- 'color' => '#6D66FF'
- ]
- ] : [];
- }
- }
+ [
+ [
+ //插件名称
+ 'name' => 'seckill',
+ //展示分类(根据平台端设置,shop:店铺营销,member:会员营销, tool:应用工具)
+ 'show_type' => 'shop',
+ //展示主题
+ 'title' => '限时秒杀',
+ //展示介绍
+ 'description' => '限时抢购引导客户快速下单',
+ //展示图标
+ 'icon' => 'addon/seckill/icon.png',
+ //跳转链接
+ 'url' => 'seckill://shop/seckill/goodslist',
+ 'summary' => $this->summary($params)
+ ]
+ ]
+
+ ];
+ return $data;
+ }
+
+ /**
+ * 营销活动概况
+ * @param $params
+ * @return array
+ */
+ private function summary($params)
+ {
+ if (empty($params)) {
+ return [];
+ }
+
+ if(isset($params['promotion_type']) && $params['promotion_type'] != $this->promotion_type){
+ return [];
+ }
+
+ //获取活动数量
+ if (isset($params[ 'count' ])) {
+ $count = model("promotion_seckill")->getCount([ [ 'site_id', '=', $params[ 'site_id' ] ] ]);
+ return [
+ 'count' => $count
+ ];
+ }
+ //获取活动概况,需要获取开始时间与结束时间
+ if (isset($params[ 'summary' ])) {
+ $list = model("promotion_seckill")->getList([
+ [ '', 'exp', Db::raw('not ( (`start_time` >= ' . $params[ 'end_time' ] . ') or (`end_time` <= ' . $params[ 'start_time' ] . '))') ],
+ [ 'site_id', '=', $params[ 'site_id' ] ],
+ [ 'status', '<>', 2 ],
+ [ 'status', '<>', -1 ]
+ ], 'seckill_name as promotion_name,id as promotion_id,start_time,end_time', '', 'a', null, 'seckill_name');
+ return !empty($list) ? [
+ 'time_limit' => [
+ 'count' => count($list),
+ 'detail' => $list,
+ 'color' => '#6D66FF'
+ ]
+ ] : [];
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/seckill/event/UnInstall.php b/src/addon/seckill/event/UnInstall.php
index 40ec89811..0d86455bd 100644
--- a/src/addon/seckill/event/UnInstall.php
+++ b/src/addon/seckill/event/UnInstall.php
@@ -1,32 +1,24 @@
-getMessage());
- } */
- return error("系统插件不能删除");
- }
+getMessage());
+ } */
+ return error("系统插件不能删除");
+ }
}
\ No newline at end of file
diff --git a/src/addon/seckill/model/Poster.php b/src/addon/seckill/model/Poster.php
index 5d7282941..1917af2fc 100644
--- a/src/addon/seckill/model/Poster.php
+++ b/src/addon/seckill/model/Poster.php
@@ -1,618 +1,610 @@
-getGoodsInfo($qrcode_param[ 'id' ]);
- if (empty($goods_info)) return $this->error('未获取到商品信息');
-
- $qrcode_param[ 'id' ] = $qrcode_param[ 'seckillId' ];
- unset($qrcode_param[ 'seckillId' ]);
-
- $qrcode_info = $this->getGoodsQrcode($app_type, $page, $qrcode_param, $promotion_type, $site_id);
- if ($qrcode_info[ 'code' ] < 0) return $qrcode_info;
- //判断海报是否存在或停用
- $template_info = $this->getTemplateInfo($goods_info[ 'template_id' ]);
- if (!empty($qrcode_param[ 'source_member' ])) {
- $member_info = $this->getMemberInfo($qrcode_param[ 'source_member' ]);
- }
-
- $upload_config_model = new Config();
- $upload_config_result = $upload_config_model->getDefaultImg($site_id);
-
- $site_model = new Site();
- $condition = array (
- [ "site_id", "=", $site_id ]
- );
- $site_info = $site_model->getSiteInfo($condition);
-
- if (empty($goods_info[ 'template_id' ]) || empty($template_info) || $template_info[ 'template_status' ] == 0) {
- $poster_width = 720;
- $poster_height = 1150;
-
- $poster = new PosterExtend($poster_width, $poster_height);
-
- $option = [
- [
- 'action' => 'setBackground', // 设背景色
- 'data' => [ 255, 255, 255 ]
- ],
- [
- 'action' => 'imageCopy', // 写入商品图
- 'data' => [
- explode(',', $goods_info[ 'sku_image' ])[ 0 ] ?? '',
- 50,
- 165,
- 620,
- 620,
- 'square',
- true,
- 1
- ]
- ],
- [
- 'action' => 'imageText', // 写入商品名称
- 'data' => [
- $goods_info[ 'sku_name' ],
- 22,
- [ 35, 35, 35 ],
- 50,
- 915,
- 360,
- 2,
- true,
- 1
- ]
- ],
- [
- 'action' => 'imageCopy', // 写入商品二维码
- 'data' => [
- $qrcode_info[ 'data' ][ 'path' ],
- 435,
- 825,
- 240,
- 240,
- 'square',
- 0,
- 1
- ]
- ],
- [
- 'action' => 'imageText', // 写入提示
- 'data' => [
- '长按识别二维码',
- 19,
- [ 102, 102, 102 ],
- 465,
- 1110,
- 490,
- 1,
- 1,
- 1
- ]
- ],
- [
- 'action' => 'imageText', // 写入商品价格单位
- 'data' => [
- '秒杀价:¥',
- 22,
- [ 255, 0, 0 ],
- 50,
- 860,
- 490,
- 2,
- true,
- 1
- ]
- ],
- [
- 'action' => 'imageText', // 写入商品价格
- 'data' => [
- $goods_info[ 'seckill_price' ],
- 30,
- [ 255, 0, 0 ],
- 188,
- 862,
- 490,
- 2,
- true,
- 1
- ]
- ],
- ];
- if (!empty($member_info)) {
- $member_option = [
- [
- 'action' => 'imageCircularCopy', // 写入用户头像
- 'data' => [
- !empty($member_info[ 'headimg' ]) ? $member_info[ 'headimg' ] : $upload_config_result[ 'data' ][ 'value' ][ 'head' ],
- 50,
- 30,
- 100,
- 100
- ]
- ],
- [
- 'action' => 'imageText', // 写入分享人昵称
- 'data' => [
- $member_info[ 'nickname' ],
- 22,
- [ 10, 10, 10 ],
- 170,
- 80,
- 580,
- 1,
- 1,
- 1
- ]
- ],
- [
- 'action' => 'imageText', // 写入分享人昵称
- 'data' => [
- '限时秒杀,抢到就是赚到',
- 18,
- [ 102, 102, 102 ],
- 170,
- 115,
- 580,
- 1,
- 1,
- 1
- ]
- ]
- ];
- $option = array_merge($option, $member_option);
- }
- } else {
- $condition = [
- [ 'template_id', '=', $goods_info[ 'template_id' ] ],
- [ 'site_id', '=', $site_id ]
- ];
- $poster_template_model = new PosterTemplateModel();
- $poster_data = $poster_template_model->getPosterTemplateInfo($condition);
- $poster_data[ 'data' ][ 'template_json' ] = json_decode($poster_data[ 'data' ][ 'template_json' ], true);
- $poster_width = 720;
- $poster_height = 1280;
- $poster = new PosterExtend($poster_width, $poster_height);
- $fontRate = 0.725; // 20px 等于 14.5磅,换算比率 1px = 0.725磅
- if (!empty($poster_data[ 'data' ][ 'background' ])) {
- list($width, $height, $type, $attr) = getimagesize(img($poster_data[ 'data' ][ 'background' ]));
- $height = 720 * $height / $width;
- $back_ground = [
- 'action' => 'imageCopy', // 写入背景图
- 'data' => [
- img($poster_data[ 'data' ][ 'background' ]),
- 0,
- 0,
- $poster_width,
- $height,
- 'square',
- true,
- 1
- ]
- ];
- } else {
- $back_ground = [
- 'action' => 'setBackground', // 设背景色
- 'data' => [ 255, 255, 255 ]
- ];
- }
- $ground = [
- [
- 'action' => 'setBackground',
- 'data' => [ 255, 255, 255 ]
- ]
- ];
- $option = [
- $back_ground,
- [
- 'action' => 'imageText', // 写入店铺名称
- 'data' => [
- $site_info[ 'data' ][ 'site_name' ],
- $poster_data[ 'data' ][ 'template_json' ][ 'store_name_font_size' ] * $fontRate * 2,
- hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'store_name_color' ]),
- $poster_data[ 'data' ][ 'template_json' ][ 'store_name_left' ] * 2,
- ( $poster_data[ 'data' ][ 'template_json' ][ 'store_name_top' ] + $poster_data[ 'data' ][ 'template_json' ][ 'store_name_font_size' ] ) * 2,
- $poster_data[ 'data' ][ 'template_json' ][ 'store_name_width' ] * 2,
- $poster_data[ 'data' ][ 'template_json' ][ 'store_name_height' ] * 2,
- true,
- $poster_data[ 'data' ][ 'template_json' ][ 'store_name_is_show' ]
- ]
- ],
- [
- 'action' => 'imageCopy', // 店铺logo
- 'data' => [
- !empty($site_info[ 'data' ][ 'logo_square' ]) ? $site_info[ 'data' ][ 'logo_square' ] : getUrl() . '/app/shop/view/public/img/shop_logo.png',
- $poster_data[ 'data' ][ 'template_json' ][ 'store_logo_left' ] * 2,
- $poster_data[ 'data' ][ 'template_json' ][ 'store_logo_top' ] * 2,
- $poster_data[ 'data' ][ 'template_json' ][ 'store_logo_width' ] * 2,
- $poster_data[ 'data' ][ 'template_json' ][ 'store_logo_height' ] * 2,
- 'square',
- true,
- $poster_data[ 'data' ][ 'template_json' ][ 'store_logo_is_show' ]
- ]
- ],
- [
- 'action' => 'imageCopy', // 写入商品图
- 'data' => [
- $goods_info[ 'sku_image' ],
- $poster_data[ 'data' ][ 'template_json' ][ 'goods_img_left' ] * 2,
- $poster_data[ 'data' ][ 'template_json' ][ 'goods_img_top' ] * 2,
- $poster_data[ 'data' ][ 'template_json' ][ 'goods_img_width' ] * 2,
- $poster_data[ 'data' ][ 'template_json' ][ 'goods_img_height' ] * 2,
- !empty($poster_data[ 'data' ][ 'template_json' ][ 'goods_img_shape' ]) ? $poster_data[ 'data' ][ 'template_json' ][ 'goods_img_shape' ] : 'square',
- 0,
- $poster_data[ 'data' ][ 'template_json' ][ 'goods_img_is_show' ]
- ]
- ],
- [
- 'action' => 'imageText', // 写入商品名称
- 'data' => [
- $goods_info[ 'sku_name' ],
- $poster_data[ 'data' ][ 'template_json' ][ 'goods_name_font_size' ] * $fontRate * 2,
- hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'goods_name_color' ]),
- $poster_data[ 'data' ][ 'template_json' ][ 'goods_name_left' ] * 2,
- ( $poster_data[ 'data' ][ 'template_json' ][ 'goods_name_top' ] + $poster_data[ 'data' ][ 'template_json' ][ 'goods_name_font_size' ] ) * 2,
- $poster_data[ 'data' ][ 'template_json' ][ 'goods_name_width' ] * 2,
- 1,//文本行数 $poster_data['data']['template_json']['goods_name_height']*2,
- true,
- $poster_data[ 'data' ][ 'template_json' ][ 'goods_name_is_show' ]
- ]
- ],
- [
- 'action' => 'imageCopy', // 写入商品二维码
- 'data' => [
- $qrcode_info[ 'data' ][ 'path' ],
- $poster_data[ 'data' ][ 'qrcode_left' ] * 2,
- $poster_data[ 'data' ][ 'qrcode_top' ] * 2,
- $poster_data[ 'data' ][ 'qrcode_width' ] * 2,
- $poster_data[ 'data' ][ 'qrcode_height' ] * 2,
- 'square',
- 0,
- 1
- ]
- ],
- [
- 'action' => 'imageText', // 写入商品价格
- 'data' => [
- '¥' . $goods_info[ 'seckill_price' ],
- $poster_data[ 'data' ][ 'template_json' ][ 'goods_price_font_size' ] * $fontRate * 2,
- hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'goods_price_color' ]),
- $poster_data[ 'data' ][ 'template_json' ][ 'goods_price_left' ] * 2,
- ( $poster_data[ 'data' ][ 'template_json' ][ 'goods_price_top' ] + $poster_data[ 'data' ][ 'template_json' ][ 'goods_price_font_size' ] ) * 2,
- $poster_data[ 'data' ][ 'template_json' ][ 'goods_price_width' ] * 2,
- $poster_data[ 'data' ][ 'template_json' ][ 'goods_price_height' ] * 2,
- true,
- $poster_data[ 'data' ][ 'template_json' ][ 'goods_price_is_show' ]
- ]
- ],
- ];
-
- if ($goods_info[ 'price' ] == 0) {
- $line = '一一一';
- } else {
- $line = '一一一一';
- }
- $market_price = [
- [
- 'action' => 'imageText', // 写入商品划线价格
- 'data' => [
- '¥' . $goods_info[ 'price' ],
- $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_font_size' ] * $fontRate * 2,
- hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_color' ]),
- $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_left' ] * 2,
- ( $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_top' ] + $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_font_size' ] ) * 2,
- $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_width' ] * 2,
- $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_height' ] * 2,
- true,
- $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_is_show' ] ?? 0
- ]
- ],
- [
- 'action' => 'imageText', // 写入线
- 'data' => [
- $line,
- $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_font_size' ] * $fontRate * 2,
- hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_color' ]),
- $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_left' ] * 2 - 5,
- ( $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_top' ] + $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_font_size' ] ) * 2,
- $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_width' ] * 2,
- $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_height' ] * 2,
- true,
- $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_is_show' ]
- ]
- ],
- ];
- $option = array_merge($option, $market_price);
-
- if (!empty($member_info)) {
- $member_option = [
- [
- 'action' => 'imageCopy', // 写入用户头像
- 'data' => [
- !empty($member_info[ 'headimg' ]) ? $member_info[ 'headimg' ] : $upload_config_result[ 'data' ][ 'value' ][ 'head' ],
- $poster_data[ 'data' ][ 'template_json' ][ 'headimg_left' ] * 2,
- $poster_data[ 'data' ][ 'template_json' ][ 'headimg_top' ] * 2,
- $poster_data[ 'data' ][ 'template_json' ][ 'headimg_width' ] * 2,
- $poster_data[ 'data' ][ 'template_json' ][ 'headimg_height' ] * 2,
- !empty($poster_data[ 'data' ][ 'template_json' ][ 'headimg_shape' ]) ? $poster_data[ 'data' ][ 'template_json' ][ 'headimg_shape' ] : 'square',
- 0,
- $poster_data[ 'data' ][ 'template_json' ][ 'headimg_is_show' ]
- ]
- ],
- [
- 'action' => 'imageText', // 写入分享人昵称
- 'data' => [
- $member_info[ 'nickname' ],
- $poster_data[ 'data' ][ 'template_json' ][ 'nickname_font_size' ] * $fontRate * 2,
- hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'nickname_color' ]),
- $poster_data[ 'data' ][ 'template_json' ][ 'nickname_left' ] * 2,
- ( $poster_data[ 'data' ][ 'template_json' ][ 'nickname_top' ] + $poster_data[ 'data' ][ 'template_json' ][ 'nickname_font_size' ] ) * 2,
- $poster_data[ 'data' ][ 'template_json' ][ 'nickname_width' ] * 2,
- $poster_data[ 'data' ][ 'template_json' ][ 'nickname_height' ] * 2,
- 0,
- $poster_data[ 'data' ][ 'template_json' ][ 'nickname_is_show' ]
- ]
- ],
- ];
- $option = array_merge($ground, $option, $member_option);
- }
-
- }
-
- $option_res = $poster->create($option);
- if (is_array($option_res)) return $option_res;
-
- $res = $option_res->jpeg('upload/poster/goods', 'goods_' . $promotion_type . '_' . $qrcode_param[ 'id' ] . '_' . $qrcode_param[ 'source_member' ] . '_' . time() . '_' . $app_type);
- if ($res[ 'code' ] == 0) {
- $upload = new Upload($site_id);
- $cloud_res = $upload->fileCloud($res[ 'data' ][ 'path' ]);
- if ($cloud_res[ 'code' ] >= 0) {
- return $this->success([ "path" => $cloud_res[ 'data' ] ]);
- } else {
- return $this->error();
- }
- }
- return $res;
- } catch (\Exception $e) {
- return $this->error($e->getMessage() . $e->getFile() . $e->getLine());
- }
- }
-
- /**
- * 获取用户信息
- * @param unknown $member_id
- */
- private function getMemberInfo($member_id)
- {
- $info = model('member')->getInfo([ 'member_id' => $member_id ], 'nickname,headimg');
- return $info;
- }
-
- /**
- * 获取商品信息
- * @param unknown $sku_id
- */
- private function getGoodsInfo($id)
- {
- $alias = 'npsg';
- $join = [
- [ 'goods_sku ngs', 'npsg.sku_id = ngs.sku_id', 'inner' ]
- ];
- $field = 'ngs.sku_name,ngs.introduction,ngs.sku_image,ngs.sku_id,npsg.seckill_price, npsg.seckill_id,ngs.template_id,ngs.price';
- $info = model('promotion_seckill_goods')->getInfo([ 'npsg.goods_id' => $id ], $field, $alias, $join);
- return $info;
- }
-
- /**
- * 获取商品二维码
- * @param unknown $app_type 请求类型
- * @param unknown $page uniapp页面路径
- * @param unknown $qrcode_param 二维码携带参数
- * @param string $promotion_type 活动类型 null为无活动
- */
- private function getGoodsQrcode($app_type, $page, $qrcode_param, $promotion_type, $site_id)
- {
- $res = event('Qrcode', [
- 'site_id' => $site_id,
- 'app_type' => $app_type,
- 'type' => 'create',
- 'data' => $qrcode_param,
- 'page' => $page,
- 'qrcode_path' => 'upload/qrcode/goods',
- 'qrcode_name' => 'goods_' . $promotion_type . '_' . $qrcode_param[ 'id' ] . '_' . $qrcode_param[ 'source_member' ] . '_' . $site_id,
- ], true);
- return $res;
- }
-
- /**
- * 获取海报信息
- * @param unknown $template_id
- */
- private function getTemplateInfo($template_id)
- {
- $info = model('poster_template')->getInfo([ 'template_id' => $template_id ], 'template_id,template_status');
- return $info;
- }
-
- /**
- * 分享图片
- * @param $page
- * @param $qrcode_param
- * @param $site_id
- * @return array|\extend\multitype|PosterExtend|string|string[]
- */
- public function shareImg($page, $qrcode_param, $site_id)
- {
- try {
- $goods_info = $this->getGoodsInfo($qrcode_param[ 'id' ]);
- if (empty($goods_info)) return $this->error('未获取到商品信息');
-
- $poster_width = 600;
- $poster_height = 480;
-
- $poster = new PosterExtend($poster_width, $poster_height);
- $option = [
- [
- 'action' => 'setBackground', // 设背景色
- 'data' => [ 255, 255, 255 ]
- ],
- [
- 'action' => 'imageCopy', // 商品图
- 'data' => [
- $goods_info[ 'sku_image' ],
- 30,
- 145,
- 200,
- 200,
- 'square',
- 50,
- 1
- ]
- ],
- [
- 'action' => 'imageText', // 写入商品名称
- 'data' => [
- $goods_info[ 'sku_name' ],
- 22,
- [ 51, 51, 51 ],
- 250,
- 190,
- 330,
- 2,
- false,
- 1
- ]
- ],
- [
- 'action' => 'imageText', // 写入商品价格
- 'data' => [
- '秒杀价:¥',
- 15,
- [ 255, 0, 0 ],
- 250,
- 300,
- 300,
- 2,
- false,
- 1
- ]
- ],
- [
- 'action' => 'imageText', // 写入商品价格
- 'data' => [
- $goods_info[ 'seckill_price' ],
- 30,
- [ 255, 0, 0 ],
- 345,
- 300,
- 300,
- 2,
- false,
- 1,
- PUBLIC_PATH . 'static/font/custom.ttf'
- ]
- ],
- [
- 'action' => 'imageText', // 写入商品原价
- 'data' => [
- '原 价:¥',
- 15,
- [ 153, 153, 153 ],
- 250,
- 340,
- 300,
- 2,
- false,
- 1
- ]
- ],
- [
- 'action' => 'imageText', // 写入商品原价
- 'data' => [
- $goods_info[ 'price' ],
- 16,
- [ 153, 153, 153 ],
- 345,
- 338,
- 300,
- 2,
- false,
- 1,
- PUBLIC_PATH . 'static/font/custom.ttf',
- ]
- ],
- // 划线(两条线)
- [
- 'action' => 'imageline',
- 'data' => [
- 325,
- 330,
- 325 + imagettfbbox(16, 0, PUBLIC_PATH . 'static/font/custom.ttf', '¥ ' . $goods_info[ 'price' ])[ 2 ],
- 330,
- [ 153, 153, 153 ],
- ]
- ],
- [
- 'action' => 'imageline',
- 'data' => [
- 325,
- 331,
- 325 + imagettfbbox(16, 0, PUBLIC_PATH . 'static/font/custom.ttf', '¥ ' . $goods_info[ 'price' ])[ 2 ],
- 331,
- [ 153, 153, 153 ],
- ]
- ],
- [
- 'action' => 'imageCopy', // 背景图
- 'data' => [
- img('upload/share_img/bg/seckill_1.png'),
- 0,
- 0,
- 600,
- 480,
- 'square',
- 0,
- 1
- ]
- ],
- ];
-
- $option_res = $poster->create($option);
- if (is_array($option_res)) {
- return $option_res;
- }
-
- $res = $option_res->jpeg('upload/share_img/seckill_' . $goods_info[ 'seckill_id' ], 'sku_' . $goods_info[ 'sku_id' ]);
- return $res;
- } catch (\Exception $e) {
- return $this->error($e->getMessage());
- }
- }
-
+getGoodsInfo($qrcode_param[ 'id' ]);
+ if (empty($goods_info)) return $this->error('未获取到商品信息');
+
+ $qrcode_param[ 'id' ] = $qrcode_param[ 'seckillId' ];
+ unset($qrcode_param[ 'seckillId' ]);
+
+ $qrcode_info = $this->getGoodsQrcode($app_type, $page, $qrcode_param, $promotion_type, $site_id);
+ if ($qrcode_info[ 'code' ] < 0) return $qrcode_info;
+ //判断海报是否存在或停用
+ $template_info = $this->getTemplateInfo($goods_info[ 'template_id' ]);
+ if (!empty($qrcode_param[ 'source_member' ])) {
+ $member_info = $this->getMemberInfo($qrcode_param[ 'source_member' ]);
+ }
+
+ $upload_config_model = new Config();
+ $upload_config_result = $upload_config_model->getDefaultImg($site_id);
+
+ $site_model = new Site();
+ $condition = array (
+ [ "site_id", "=", $site_id ]
+ );
+ $site_info = $site_model->getSiteInfo($condition);
+
+ if (empty($goods_info[ 'template_id' ]) || empty($template_info) || $template_info[ 'template_status' ] == 0) {
+ $poster_width = 720;
+ $poster_height = 1150;
+
+ $poster = new PosterExtend($poster_width, $poster_height);
+
+ $option = [
+ [
+ 'action' => 'setBackground', // 设背景色
+ 'data' => [ 255, 255, 255 ]
+ ],
+ [
+ 'action' => 'imageCopy', // 写入商品图
+ 'data' => [
+ explode(',', $goods_info[ 'sku_image' ])[ 0 ] ?? '',
+ 50,
+ 165,
+ 620,
+ 620,
+ 'square',
+ true,
+ 1
+ ]
+ ],
+ [
+ 'action' => 'imageText', // 写入商品名称
+ 'data' => [
+ $goods_info[ 'sku_name' ],
+ 22,
+ [ 35, 35, 35 ],
+ 50,
+ 915,
+ 360,
+ 2,
+ true,
+ 1
+ ]
+ ],
+ [
+ 'action' => 'imageCopy', // 写入商品二维码
+ 'data' => [
+ $qrcode_info[ 'data' ][ 'path' ],
+ 435,
+ 825,
+ 240,
+ 240,
+ 'square',
+ 0,
+ 1
+ ]
+ ],
+ [
+ 'action' => 'imageText', // 写入提示
+ 'data' => [
+ '长按识别二维码',
+ 19,
+ [ 102, 102, 102 ],
+ 465,
+ 1110,
+ 490,
+ 1,
+ 1,
+ 1
+ ]
+ ],
+ [
+ 'action' => 'imageText', // 写入商品价格单位
+ 'data' => [
+ '秒杀价:¥',
+ 22,
+ [ 255, 0, 0 ],
+ 50,
+ 860,
+ 490,
+ 2,
+ true,
+ 1
+ ]
+ ],
+ [
+ 'action' => 'imageText', // 写入商品价格
+ 'data' => [
+ $goods_info[ 'seckill_price' ],
+ 30,
+ [ 255, 0, 0 ],
+ 188,
+ 862,
+ 490,
+ 2,
+ true,
+ 1
+ ]
+ ],
+ ];
+ if (!empty($member_info)) {
+ $member_option = [
+ [
+ 'action' => 'imageCircularCopy', // 写入用户头像
+ 'data' => [
+ !empty($member_info[ 'headimg' ]) ? $member_info[ 'headimg' ] : $upload_config_result[ 'data' ][ 'value' ][ 'head' ],
+ 50,
+ 30,
+ 100,
+ 100
+ ]
+ ],
+ [
+ 'action' => 'imageText', // 写入分享人昵称
+ 'data' => [
+ $member_info[ 'nickname' ],
+ 22,
+ [ 10, 10, 10 ],
+ 170,
+ 80,
+ 580,
+ 1,
+ 1,
+ 1
+ ]
+ ],
+ [
+ 'action' => 'imageText', // 写入分享人昵称
+ 'data' => [
+ '限时秒杀,抢到就是赚到',
+ 18,
+ [ 102, 102, 102 ],
+ 170,
+ 115,
+ 580,
+ 1,
+ 1,
+ 1
+ ]
+ ]
+ ];
+ $option = array_merge($option, $member_option);
+ }
+ } else {
+ $condition = [
+ [ 'template_id', '=', $goods_info[ 'template_id' ] ],
+ [ 'site_id', '=', $site_id ]
+ ];
+ $poster_template_model = new PosterTemplateModel();
+ $poster_data = $poster_template_model->getPosterTemplateInfo($condition);
+ $poster_data[ 'data' ][ 'template_json' ] = json_decode($poster_data[ 'data' ][ 'template_json' ], true);
+ $poster_width = 720;
+ $poster_height = 1280;
+ $poster = new PosterExtend($poster_width, $poster_height);
+ $fontRate = 0.725; // 20px 等于 14.5磅,换算比率 1px = 0.725磅
+ if (!empty($poster_data[ 'data' ][ 'background' ])) {
+ list($width, $height, $type, $attr) = getimagesize(img($poster_data[ 'data' ][ 'background' ]));
+ $height = 720 * $height / $width;
+ $back_ground = [
+ 'action' => 'imageCopy', // 写入背景图
+ 'data' => [
+ img($poster_data[ 'data' ][ 'background' ]),
+ 0,
+ 0,
+ $poster_width,
+ $height,
+ 'square',
+ true,
+ 1
+ ]
+ ];
+ } else {
+ $back_ground = [
+ 'action' => 'setBackground', // 设背景色
+ 'data' => [ 255, 255, 255 ]
+ ];
+ }
+ $ground = [
+ [
+ 'action' => 'setBackground',
+ 'data' => [ 255, 255, 255 ]
+ ]
+ ];
+ $option = [
+ $back_ground,
+ [
+ 'action' => 'imageText', // 写入店铺名称
+ 'data' => [
+ $site_info[ 'data' ][ 'site_name' ],
+ $poster_data[ 'data' ][ 'template_json' ][ 'store_name_font_size' ] * $fontRate * 2,
+ hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'store_name_color' ]),
+ $poster_data[ 'data' ][ 'template_json' ][ 'store_name_left' ] * 2,
+ ( $poster_data[ 'data' ][ 'template_json' ][ 'store_name_top' ] + $poster_data[ 'data' ][ 'template_json' ][ 'store_name_font_size' ] ) * 2,
+ $poster_data[ 'data' ][ 'template_json' ][ 'store_name_width' ] * 2,
+ $poster_data[ 'data' ][ 'template_json' ][ 'store_name_height' ] * 2,
+ true,
+ $poster_data[ 'data' ][ 'template_json' ][ 'store_name_is_show' ]
+ ]
+ ],
+ [
+ 'action' => 'imageCopy', // 店铺logo
+ 'data' => [
+ !empty($site_info[ 'data' ][ 'logo_square' ]) ? $site_info[ 'data' ][ 'logo_square' ] : getUrl() . '/app/shop/view/public/img/shop_logo.png',
+ $poster_data[ 'data' ][ 'template_json' ][ 'store_logo_left' ] * 2,
+ $poster_data[ 'data' ][ 'template_json' ][ 'store_logo_top' ] * 2,
+ $poster_data[ 'data' ][ 'template_json' ][ 'store_logo_width' ] * 2,
+ $poster_data[ 'data' ][ 'template_json' ][ 'store_logo_height' ] * 2,
+ 'square',
+ true,
+ $poster_data[ 'data' ][ 'template_json' ][ 'store_logo_is_show' ]
+ ]
+ ],
+ [
+ 'action' => 'imageCopy', // 写入商品图
+ 'data' => [
+ $goods_info[ 'sku_image' ],
+ $poster_data[ 'data' ][ 'template_json' ][ 'goods_img_left' ] * 2,
+ $poster_data[ 'data' ][ 'template_json' ][ 'goods_img_top' ] * 2,
+ $poster_data[ 'data' ][ 'template_json' ][ 'goods_img_width' ] * 2,
+ $poster_data[ 'data' ][ 'template_json' ][ 'goods_img_height' ] * 2,
+ !empty($poster_data[ 'data' ][ 'template_json' ][ 'goods_img_shape' ]) ? $poster_data[ 'data' ][ 'template_json' ][ 'goods_img_shape' ] : 'square',
+ 0,
+ $poster_data[ 'data' ][ 'template_json' ][ 'goods_img_is_show' ]
+ ]
+ ],
+ [
+ 'action' => 'imageText', // 写入商品名称
+ 'data' => [
+ $goods_info[ 'sku_name' ],
+ $poster_data[ 'data' ][ 'template_json' ][ 'goods_name_font_size' ] * $fontRate * 2,
+ hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'goods_name_color' ]),
+ $poster_data[ 'data' ][ 'template_json' ][ 'goods_name_left' ] * 2,
+ ( $poster_data[ 'data' ][ 'template_json' ][ 'goods_name_top' ] + $poster_data[ 'data' ][ 'template_json' ][ 'goods_name_font_size' ] ) * 2,
+ $poster_data[ 'data' ][ 'template_json' ][ 'goods_name_width' ] * 2,
+ 1,//文本行数 $poster_data['data']['template_json']['goods_name_height']*2,
+ true,
+ $poster_data[ 'data' ][ 'template_json' ][ 'goods_name_is_show' ]
+ ]
+ ],
+ [
+ 'action' => 'imageCopy', // 写入商品二维码
+ 'data' => [
+ $qrcode_info[ 'data' ][ 'path' ],
+ $poster_data[ 'data' ][ 'qrcode_left' ] * 2,
+ $poster_data[ 'data' ][ 'qrcode_top' ] * 2,
+ $poster_data[ 'data' ][ 'qrcode_width' ] * 2,
+ $poster_data[ 'data' ][ 'qrcode_height' ] * 2,
+ 'square',
+ 0,
+ 1
+ ]
+ ],
+ [
+ 'action' => 'imageText', // 写入商品价格
+ 'data' => [
+ '¥' . $goods_info[ 'seckill_price' ],
+ $poster_data[ 'data' ][ 'template_json' ][ 'goods_price_font_size' ] * $fontRate * 2,
+ hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'goods_price_color' ]),
+ $poster_data[ 'data' ][ 'template_json' ][ 'goods_price_left' ] * 2,
+ ( $poster_data[ 'data' ][ 'template_json' ][ 'goods_price_top' ] + $poster_data[ 'data' ][ 'template_json' ][ 'goods_price_font_size' ] ) * 2,
+ $poster_data[ 'data' ][ 'template_json' ][ 'goods_price_width' ] * 2,
+ $poster_data[ 'data' ][ 'template_json' ][ 'goods_price_height' ] * 2,
+ true,
+ $poster_data[ 'data' ][ 'template_json' ][ 'goods_price_is_show' ]
+ ]
+ ],
+ ];
+
+ if ($goods_info[ 'price' ] == 0) {
+ $line = '一一一';
+ } else {
+ $line = '一一一一';
+ }
+ $market_price = [
+ [
+ 'action' => 'imageText', // 写入商品划线价格
+ 'data' => [
+ '¥' . $goods_info[ 'price' ],
+ $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_font_size' ] * $fontRate * 2,
+ hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_color' ]),
+ $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_left' ] * 2,
+ ( $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_top' ] + $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_font_size' ] ) * 2,
+ $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_width' ] * 2,
+ $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_height' ] * 2,
+ true,
+ $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_is_show' ] ?? 0
+ ]
+ ],
+ [
+ 'action' => 'imageText', // 写入线
+ 'data' => [
+ $line,
+ $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_font_size' ] * $fontRate * 2,
+ hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_color' ]),
+ $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_left' ] * 2 - 5,
+ ( $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_top' ] + $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_font_size' ] ) * 2,
+ $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_width' ] * 2,
+ $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_height' ] * 2,
+ true,
+ $poster_data[ 'data' ][ 'template_json' ][ 'goods_market_price_is_show' ]
+ ]
+ ],
+ ];
+ $option = array_merge($option, $market_price);
+
+ if (!empty($member_info)) {
+ $member_option = [
+ [
+ 'action' => 'imageCopy', // 写入用户头像
+ 'data' => [
+ !empty($member_info[ 'headimg' ]) ? $member_info[ 'headimg' ] : $upload_config_result[ 'data' ][ 'value' ][ 'head' ],
+ $poster_data[ 'data' ][ 'template_json' ][ 'headimg_left' ] * 2,
+ $poster_data[ 'data' ][ 'template_json' ][ 'headimg_top' ] * 2,
+ $poster_data[ 'data' ][ 'template_json' ][ 'headimg_width' ] * 2,
+ $poster_data[ 'data' ][ 'template_json' ][ 'headimg_height' ] * 2,
+ !empty($poster_data[ 'data' ][ 'template_json' ][ 'headimg_shape' ]) ? $poster_data[ 'data' ][ 'template_json' ][ 'headimg_shape' ] : 'square',
+ 0,
+ $poster_data[ 'data' ][ 'template_json' ][ 'headimg_is_show' ]
+ ]
+ ],
+ [
+ 'action' => 'imageText', // 写入分享人昵称
+ 'data' => [
+ $member_info[ 'nickname' ],
+ $poster_data[ 'data' ][ 'template_json' ][ 'nickname_font_size' ] * $fontRate * 2,
+ hex2rgb($poster_data[ 'data' ][ 'template_json' ][ 'nickname_color' ]),
+ $poster_data[ 'data' ][ 'template_json' ][ 'nickname_left' ] * 2,
+ ( $poster_data[ 'data' ][ 'template_json' ][ 'nickname_top' ] + $poster_data[ 'data' ][ 'template_json' ][ 'nickname_font_size' ] ) * 2,
+ $poster_data[ 'data' ][ 'template_json' ][ 'nickname_width' ] * 2,
+ $poster_data[ 'data' ][ 'template_json' ][ 'nickname_height' ] * 2,
+ 0,
+ $poster_data[ 'data' ][ 'template_json' ][ 'nickname_is_show' ]
+ ]
+ ],
+ ];
+ $option = array_merge($ground, $option, $member_option);
+ }
+
+ }
+
+ $option_res = $poster->create($option);
+ if (is_array($option_res)) return $option_res;
+
+ $res = $option_res->jpeg('upload/poster/goods', 'goods_' . $promotion_type . '_' . $qrcode_param[ 'id' ] . '_' . $qrcode_param[ 'source_member' ] . '_' . time() . '_' . $app_type);
+ if ($res[ 'code' ] == 0) {
+ $upload = new Upload($site_id);
+ $cloud_res = $upload->fileCloud($res[ 'data' ][ 'path' ]);
+ if ($cloud_res[ 'code' ] >= 0) {
+ return $this->success([ "path" => $cloud_res[ 'data' ] ]);
+ } else {
+ return $this->error();
+ }
+ }
+ return $res;
+ } catch (\Exception $e) {
+ return $this->error($e->getMessage() . $e->getFile() . $e->getLine());
+ }
+ }
+
+ /**
+ * 获取用户信息
+ * @param unknown $member_id
+ */
+ private function getMemberInfo($member_id)
+ {
+ $info = model('member')->getInfo([ 'member_id' => $member_id ], 'nickname,headimg');
+ return $info;
+ }
+
+ /**
+ * 获取商品信息
+ * @param unknown $sku_id
+ */
+ private function getGoodsInfo($id)
+ {
+ $alias = 'npsg';
+ $join = [
+ [ 'goods_sku ngs', 'npsg.sku_id = ngs.sku_id', 'inner' ]
+ ];
+ $field = 'ngs.sku_name,ngs.introduction,ngs.sku_image,ngs.sku_id,npsg.seckill_price, npsg.seckill_id,ngs.template_id,ngs.price';
+ $info = model('promotion_seckill_goods')->getInfo([ 'npsg.goods_id' => $id ], $field, $alias, $join);
+ return $info;
+ }
+
+ /**
+ * 获取商品二维码
+ * @param unknown $app_type 请求类型
+ * @param unknown $page uniapp页面路径
+ * @param unknown $qrcode_param 二维码携带参数
+ * @param string $promotion_type 活动类型 null为无活动
+ */
+ private function getGoodsQrcode($app_type, $page, $qrcode_param, $promotion_type, $site_id)
+ {
+ $res = event('Qrcode', [
+ 'site_id' => $site_id,
+ 'app_type' => $app_type,
+ 'type' => 'create',
+ 'data' => $qrcode_param,
+ 'page' => $page,
+ 'qrcode_path' => 'upload/qrcode/goods',
+ 'qrcode_name' => 'goods_' . $promotion_type . '_' . $qrcode_param[ 'id' ] . '_' . $qrcode_param[ 'source_member' ] . '_' . $site_id,
+ ], true);
+ return $res;
+ }
+
+ /**
+ * 获取海报信息
+ * @param unknown $template_id
+ */
+ private function getTemplateInfo($template_id)
+ {
+ $info = model('poster_template')->getInfo([ 'template_id' => $template_id ], 'template_id,template_status');
+ return $info;
+ }
+
+ /**
+ * 分享图片
+ * @param $page
+ * @param $qrcode_param
+ * @param $site_id
+ * @return array|\extend\multitype|PosterExtend|string|string[]
+ */
+ public function shareImg($page, $qrcode_param, $site_id)
+ {
+ try {
+ $goods_info = $this->getGoodsInfo($qrcode_param[ 'id' ]);
+ if (empty($goods_info)) return $this->error('未获取到商品信息');
+
+ $poster_width = 600;
+ $poster_height = 480;
+
+ $poster = new PosterExtend($poster_width, $poster_height);
+ $option = [
+ [
+ 'action' => 'setBackground', // 设背景色
+ 'data' => [ 255, 255, 255 ]
+ ],
+ [
+ 'action' => 'imageCopy', // 商品图
+ 'data' => [
+ $goods_info[ 'sku_image' ],
+ 30,
+ 145,
+ 200,
+ 200,
+ 'square',
+ 50,
+ 1
+ ]
+ ],
+ [
+ 'action' => 'imageText', // 写入商品名称
+ 'data' => [
+ $goods_info[ 'sku_name' ],
+ 22,
+ [ 51, 51, 51 ],
+ 250,
+ 190,
+ 330,
+ 2,
+ false,
+ 1
+ ]
+ ],
+ [
+ 'action' => 'imageText', // 写入商品价格
+ 'data' => [
+ '秒杀价:¥',
+ 15,
+ [ 255, 0, 0 ],
+ 250,
+ 300,
+ 300,
+ 2,
+ false,
+ 1
+ ]
+ ],
+ [
+ 'action' => 'imageText', // 写入商品价格
+ 'data' => [
+ $goods_info[ 'seckill_price' ],
+ 30,
+ [ 255, 0, 0 ],
+ 345,
+ 300,
+ 300,
+ 2,
+ false,
+ 1,
+ PUBLIC_PATH . 'static/font/custom.ttf'
+ ]
+ ],
+ [
+ 'action' => 'imageText', // 写入商品原价
+ 'data' => [
+ '原 价:¥',
+ 15,
+ [ 153, 153, 153 ],
+ 250,
+ 340,
+ 300,
+ 2,
+ false,
+ 1
+ ]
+ ],
+ [
+ 'action' => 'imageText', // 写入商品原价
+ 'data' => [
+ $goods_info[ 'price' ],
+ 16,
+ [ 153, 153, 153 ],
+ 345,
+ 338,
+ 300,
+ 2,
+ false,
+ 1,
+ PUBLIC_PATH . 'static/font/custom.ttf',
+ ]
+ ],
+ // 划线(两条线)
+ [
+ 'action' => 'imageline',
+ 'data' => [
+ 325,
+ 330,
+ 325 + imagettfbbox(16, 0, PUBLIC_PATH . 'static/font/custom.ttf', '¥ ' . $goods_info[ 'price' ])[ 2 ],
+ 330,
+ [ 153, 153, 153 ],
+ ]
+ ],
+ [
+ 'action' => 'imageline',
+ 'data' => [
+ 325,
+ 331,
+ 325 + imagettfbbox(16, 0, PUBLIC_PATH . 'static/font/custom.ttf', '¥ ' . $goods_info[ 'price' ])[ 2 ],
+ 331,
+ [ 153, 153, 153 ],
+ ]
+ ],
+ [
+ 'action' => 'imageCopy', // 背景图
+ 'data' => [
+ img('upload/share_img/bg/seckill_1.png'),
+ 0,
+ 0,
+ 600,
+ 480,
+ 'square',
+ 0,
+ 1
+ ]
+ ],
+ ];
+
+ $option_res = $poster->create($option);
+ if (is_array($option_res)) {
+ return $option_res;
+ }
+
+ $res = $option_res->jpeg('upload/share_img/seckill_' . $goods_info[ 'seckill_id' ], 'sku_' . $goods_info[ 'sku_id' ]);
+ return $res;
+ } catch (\Exception $e) {
+ return $this->error($e->getMessage());
+ }
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/seckill/model/Seckill.php b/src/addon/seckill/model/Seckill.php
index 374371c3f..0196b52c7 100644
--- a/src/addon/seckill/model/Seckill.php
+++ b/src/addon/seckill/model/Seckill.php
@@ -1,901 +1,893 @@
- $data[ 'seckill_end_time' ]) {
- return $this->error('', '秒杀时间段设置错误');
- }
-
- //时间段检测
- $seckill_count = model('promotion_seckill_time')->getCount([
- [ 'seckill_start_time|seckill_end_time', 'between', [ $data[ 'seckill_start_time' ], $data[ 'seckill_end_time' ] ] ],
- [ 'site_id', '=', $data[ 'site_id' ] ]
- ]);
- if ($seckill_count > 0) {
- return $this->error('', '秒杀场次设置冲突');
- }
- $seckill_count = model('promotion_seckill_time')->getCount([
- [ 'seckill_start_time', '<=', $data[ 'seckill_start_time' ] ],
- [ 'seckill_end_time', '>=', $data[ 'seckill_end_time' ] ],
- [ 'site_id', '=', $data[ 'site_id' ] ]
- ]);
- if ($seckill_count > 0) {
- return $this->error('', '秒杀场次设置冲突');
- }
- //添加数据
- $data[ 'create_time' ] = time();
- $seckill_id = model('promotion_seckill_time')->add($data);
- Cache::tag("promotion_seckill_time")->clear();
- return $this->success($seckill_id);
- }
-
- /**
- * 修改秒杀时段
- * @param $data
- * @param $site_id
- * @return array
- */
- public function editSeckillTime($data, $site_id)
- {
- if ($data[ 'seckill_start_time' ] > $data[ 'seckill_end_time' ]) {
- return $this->error('', '秒杀时间段设置错误');
- }
- //时间段检测
- $seckill_count = model('promotion_seckill_time')->getCount([
- [ 'seckill_start_time|seckill_end_time', 'between', [ $data[ 'seckill_start_time' ], $data[ 'seckill_end_time' ] ] ],
- [ 'site_id', '=', $site_id ],
- [ 'id', '<>', $data[ 'id' ] ]
- ]);
- if ($seckill_count > 0) {
- return $this->error('', '秒杀场次设置冲突');
- }
- $seckill_count = model('promotion_seckill_time')->getCount([
- [ 'seckill_start_time', '<=', $data[ 'seckill_start_time' ] ],
- [ 'seckill_end_time', '>=', $data[ 'seckill_end_time' ] ],
- [ 'site_id', '=', $site_id ],
- [ 'id', '<>', $data[ 'id' ] ]
- ]);
- if ($seckill_count > 0) {
- return $this->error('', '秒杀场次设置冲突');
- }
-
- //更新数据
- $data[ 'modify_time' ] = time();
- $res = model('promotion_seckill_time')->update($data, [ [ 'id', '=', $data[ 'id' ] ] ]);
- Cache::tag("promotion_seckill_time")->clear();
- return $this->success($res);
- }
-
- /**
- * 删除秒杀时段
- * @param $seckill_time_id
- * @return array
- */
- public function deleteSeckillTime($seckill_time_id)
- {
- $res = model('promotion_seckill_time')->delete([ [ 'id', '=', $seckill_time_id ] ]);
- if ($res) {
-
- $goods = new Goods();
-
- $condition = [
- [ 'seckill_time_id', 'like', '%,' . $seckill_time_id . ',%' ]
- ];
- $seckill_list = model('promotion_seckill')->getList($condition, 'id,seckill_time_id,goods_id');
-
- foreach ($seckill_list as $k => $v) {
-
- $time_ids = explode(',', trim($v[ 'seckill_time_id' ], ','));
- unset($time_ids[ array_search($seckill_time_id, $time_ids) ]);
-
- if (empty($time_ids)) {
- $goods->modifyPromotionAddon($v[ 'goods_id' ], [ 'seckill' => $v[ 'id' ] ], true);
- model('promotion_seckill_goods')->delete([ [ 'seckill_id', '=', $v[ 'id' ] ] ]);
- model('promotion_seckill')->delete([ [ 'id', '=', $v[ 'id' ] ] ]);
- } else {
-
- $time_id = ',' . implode(',', $time_ids) . ',';
- model('promotion_seckill')->update([ 'seckill_time_id' => $time_id ], [ [ 'id', '=', $v[ 'id' ] ] ]);
- model('promotion_seckill_goods')->update([ 'seckill_time_id' => $time_id ], [ [ 'seckill_id', '=', $v[ 'id' ] ] ]);
- }
-
- }
- }
- Cache::tag("promotion_seckill_time")->clear();
- return $this->success($res);
- }
-
- /**
- * 获取秒杀时段信息
- * @param $condition
- * @param string $field
- * @return array
- */
- public function getSeckillTimeInfo($condition, $field = '*')
- {
- $data = json_encode([ $condition, $field ]);
- $cache = Cache::get("promotion_seckill_time_getSeckillInfo_" . $data);
- if (!empty($cache)) {
- return $this->success($cache);
- }
- $res = model('promotion_seckill_time')->getInfo($condition, $field);
- Cache::tag("promotion_seckill_time")->set("promotion_seckill_time_getSeckillInfo_" . $data, $res);
- return $this->success($res);
- }
-
- /**
- * 获取秒杀时段列表
- * @param array $condition
- * @param string $field
- * @param string $order
- * @param null $limit
- * @return array
- */
- public function getSeckillTimeList($condition = [], $field = '*', $order = '', $limit = null)
- {
- $list = model('promotion_seckill_time')->getList($condition, $field, $order, '', '', '', $limit);
- return $this->success($list);
- }
-
- /**
- * 获取有商品的秒杀时段列表
- * @param $condition
- * @param $field
- * @param string $order
- * @return array
- */
- public function getGoodsSeckillTimeList($condition, $field, $order = 'seckill_start_time asc')
- {
- if (empty($field)) {
- $field = 'id, site_id, name, seckill_start_time, seckill_end_time';
- }
-
- $seckill_time = model('promotion_seckill_time')->getList($condition, $field, $order);
- foreach ($seckill_time as $k => $v) {
- $condition = [
- [ 'seckill_time_id', 'like', '%,' . $v[ 'id' ] . ',%' ],
- [ 'status', '=', 1 ],
- [ 'g.goods_state', '=', 1 ],
- [ 'g.is_delete', '=', 0 ]
- ];
- $join = [
- [ 'goods g', 'g.goods_id = psg.goods_id', 'inner' ]
- ];
- $goods = model('promotion_seckill_goods')->getInfo($condition, 'id', 'psg', $join);
- if (empty($goods)) unset($seckill_time[ $k ]);
- }
- return $this->success($seckill_time);
- }
-
- /**
- * 转换秒杀时间
- * @param $info
- * @return mixed
- */
- public function transformSeckillTime($info)
- {
- $info[ 'start_hour' ] = floor($info[ 'seckill_start_time' ] / 3600);
- $info[ 'start_minute' ] = floor(( $info[ 'seckill_start_time' ] % 3600 ) / 60);
- $info[ 'start_second' ] = $info[ 'seckill_start_time' ] % 60;
-
- $info[ 'end_hour' ] = floor($info[ 'seckill_end_time' ] / 3600);
- $info[ 'end_minute' ] = floor(( $info[ 'seckill_end_time' ] % 3600 ) / 60);
- $info[ 'end_second' ] = $info[ 'seckill_end_time' ] % 60;
-
- if ($info[ 'start_hour' ] < 10) $info[ 'start_hour' ] = '0' . $info[ 'start_hour' ];
- if ($info[ 'start_minute' ] < 10) $info[ 'start_minute' ] = '0' . $info[ 'start_minute' ];
- if ($info[ 'start_second' ] < 10) $info[ 'start_second' ] = '0' . $info[ 'start_second' ];
-
- if ($info[ 'end_hour' ] < 10) $info[ 'end_hour' ] = '0' . $info[ 'end_hour' ];
- if ($info[ 'end_minute' ] < 10) $info[ 'end_minute' ] = '0' . $info[ 'end_minute' ];
- if ($info[ 'end_second' ] < 10) $info[ 'end_second' ] = '0' . $info[ 'end_second' ];
-
- return $info;
- }
-
- /******************************************************秒杀商品*********************************************************************/
- /**
- * 添加秒杀商品
- * @param $data
- * @return array
- */
- public function addSeckillGoods($data)
- {
- $cron = new Cron();
- $goods_data = $data[ 'goods_data' ];
-
- if (empty($data[ 'seckill_time_id' ])) {
- return $this->error('', '请选择秒杀时段');
- }
- $seckill_time_id = explode(',', $data[ 'seckill_time_id' ]);
-
- //时间段检测
- foreach ($seckill_time_id as $v) {
- $seckill_count = model('promotion_seckill')->getCount([
- [ 'goods_id', 'in', $data[ 'goods_ids' ] ],
- [ 'status', 'in', '0,1' ],
- [ 'seckill_time_id', 'like', '%,' . $v . ',%' ],
- [ 'site_id', '=', $data[ 'site_id' ] ],
- [ '', 'exp', Db::raw('not ( (`start_time` > ' . $data[ 'end_time' ] . ' and `start_time` > ' . $data[ 'start_time' ] . ' ) or (`end_time` < ' . $data[ 'start_time' ] . ' and `end_time` < ' . $data[ 'end_time' ] . '))') ]//todo 修正 所有的优惠都要一样
- ]);
- if ($seckill_count > 0) {
- return $this->error('', '有商品已设置秒杀,请不要重复设置');
- }
- }
-
- model('promotion_seckill')->startTrans();
- try {
- $seckill_data = [
- 'site_id' => $data[ 'site_id' ],
- 'seckill_name' => $data[ 'seckill_name' ],
- 'remark' => $data[ 'remark' ],
- 'seckill_time_id' => ',' . $data[ 'seckill_time_id' ] . ',',
- 'start_time' => $data[ 'start_time' ],
- 'end_time' => $data[ 'end_time' ],
- 'create_time' => time(),
- 'sort' => $data[ 'sort' ],
- ];
-
- $goods = new Goods();
- $add_goods_data = [];
- foreach ($goods_data as $k => $v) {
- $seckill_data[ 'goods_id' ] = $v[ 'goods_id' ];
- $seckill_data[ 'goods_name' ] = $v[ 'sku_list' ][ 0 ][ 'sku_name' ];
- $seckill_data[ 'goods_image' ] = $v[ 'sku_list' ][ 0 ][ 'sku_image' ];
- $seckill_data[ 'seckill_price' ] = $v[ 'sku_list' ][ 0 ][ 'seckill_price' ];
-
- if ($data[ 'start_time' ] <= time()) {
- $seckill_data[ 'status' ] = 1;//直接启动
- $seckill_id = model('promotion_seckill')->add($seckill_data);
- $goods->modifyPromotionAddon($v[ 'goods_id' ], [ 'seckill' => $seckill_id ]);
- $cron->addCron(1, 0, "秒杀关闭", "CloseSeckill", $data[ 'end_time' ], $seckill_id);
- } else {
- $seckill_data[ 'status' ] = 0;
- $seckill_id = model('promotion_seckill')->add($seckill_data);
- $cron->addCron(1, 0, "秒杀开启", "OpenSeckill", $data[ 'start_time' ], $seckill_id);
- $cron->addCron(1, 0, "秒杀关闭", "CloseSeckill", $data[ 'end_time' ], $seckill_id);
- }
-
- $goods_stock = 0; // 秒杀商品总库存
-
- foreach ($v[ 'sku_list' ] as $key => $item) {
- $sku_info = model('goods_sku')->getInfo([ [ 'sku_id', '=', $item[ 'sku_id' ] ] ], 'goods_id, sku_id, sku_name,price,sku_image');
- $add_goods_data[] = [
- 'site_id' => $data[ 'site_id' ],
- 'seckill_id' => $seckill_id,
- 'seckill_time_id' => ',' . $data[ 'seckill_time_id' ] . ',',
- 'sku_id' => $item[ 'sku_id' ],
- 'goods_id' => $item[ 'goods_id' ],
- 'sku_image' => $sku_info[ 'sku_image' ],
- 'sku_name' => $sku_info[ 'sku_name' ],
- 'seckill_price' => $item[ 'seckill_price' ],
- 'price' => $sku_info[ 'price' ],
- 'stock' => $item[ 'seckill_stock' ],
- 'max_buy' => $item[ 'max_buy' ],
- 'status' => $seckill_data[ 'status' ]
- ];
- $goods_stock += $item[ 'seckill_stock' ];
- }
- model('promotion_seckill')->update([ 'goods_stock' => $goods_stock ], [ [ 'id', '=', $seckill_id ] ]);
- }
- model('promotion_seckill_goods')->addList($add_goods_data);
- foreach ($seckill_time_id as $v) {
- $count = model('promotion_seckill_goods')->getCount([ [ 'seckill_time_id', 'like', '%,' . $v . ',%' ] ], '*', 'a', '', 'goods_id');
- model('promotion_seckill_time')->update([ 'goods_num' => $count ], [ [ 'id', '=', $v ] ]);
- }
- model('promotion_seckill')->commit();
- return $this->success();
- } catch (\Exception $e) {
- model('promotion_seckill')->rollback();
- return $this->error('', $e->getMessage());
- }
-
- }
-
- /**
- * 修改秒杀商品
- * @param $data
- * @return array
- */
- public function editSeckillGoods($data)
- {
- $cron = new Cron();
-
- if (empty($data[ 'seckill_time_id' ])) {
- return $this->error('', '请选择秒杀时段');
- }
- $seckill_time_id = explode(',', $data[ 'seckill_time_id' ]);
-
- //时间段检测
- foreach ($seckill_time_id as $v) {
- $seckill_count = model('promotion_seckill')->getInfo([
- [ 'goods_id', 'in', $data[ 'goods_ids' ] ],
- [ 'status', 'in', '0,1' ],
- [ 'site_id', '=', $data[ 'site_id' ] ],
- [ 'seckill_time_id', 'like', '%,' . $v . ',%' ],
- [ 'id', '<>', $data[ 'id' ] ],
- [ '', 'exp', Db::raw('not ( (`start_time` > ' . $data[ 'end_time' ] . ' and `start_time` > ' . $data[ 'start_time' ] . ' ) or (`end_time` < ' . $data[ 'start_time' ] . ' and `end_time` < ' . $data[ 'end_time' ] . '))') ]//todo 修正 所有的优惠都要一样
- ]);
- if ($seckill_count > 0) {
- return $this->error('', '有商品已设置秒杀,请不要重复设置');
- }
- }
-
- model('promotion_seckill')->startTrans();
- try {
- $seckill_data = [
- 'site_id' => $data[ 'site_id' ],
- 'seckill_name' => $data[ 'seckill_name' ],
- 'remark' => $data[ 'remark' ],
- 'seckill_time_id' => ',' . $data[ 'seckill_time_id' ] . ',',
- 'start_time' => $data[ 'start_time' ],
- 'end_time' => $data[ 'end_time' ],
- 'modify_time' => time(),
- 'sort' => $data[ 'sort' ],
- ];
-
- $goods = new Goods();
- $add_goods_data = [];
- $seckill_data[ 'goods_id' ] = $data[ 'sku_list' ][ 0 ][ 'goods_id' ];
- $seckill_data[ 'goods_name' ] = $data[ 'sku_list' ][ 0 ][ 'sku_name' ];
- $seckill_data[ 'goods_image' ] = $data[ 'sku_list' ][ 0 ][ 'sku_image' ];
- $seckill_data[ 'seckill_price' ] = $data[ 'sku_list' ][ 0 ][ 'seckill_price' ];
-
- $seckill_id = $data[ 'id' ];
-
- if ($data[ 'start_time' ] <= time()) {
- $seckill_data[ 'status' ] = 1;//直接启动
- model('promotion_seckill')->update($seckill_data, [ [ 'id', '=', $seckill_id ] ]);
- $goods->modifyPromotionAddon($data[ 'sku_list' ][ 0 ][ 'goods_id' ], [ 'seckill' => $seckill_id ]);
- $cron->addCron(1, 0, "秒杀关闭", "CloseSeckill", $data[ 'end_time' ], $seckill_id);
- } else {
- $seckill_data[ 'status' ] = 0;
- model('promotion_seckill')->update($seckill_data, [ [ 'id', '=', $seckill_id ] ]);
- $cron->addCron(1, 0, "秒杀开启", "OpenSeckill", $data[ 'start_time' ], $seckill_id);
- $cron->addCron(1, 0, "秒杀关闭", "CloseSeckill", $data[ 'end_time' ], $seckill_id);
- }
-
- model('promotion_seckill_goods')->delete([ [ 'seckill_id', '=', $seckill_id ] ]);
-
- $goods_stock = 0; // 秒杀商品总库存
-
- foreach ($data[ 'sku_list' ] as $key => $item) {
- $sku_info = model('goods_sku')->getInfo([ [ 'sku_id', '=', $item[ 'sku_id' ] ] ], 'goods_id, sku_id, sku_name,price,sku_image');
- $add_goods_data[] = [
- 'site_id' => $data[ 'site_id' ],
- 'seckill_id' => $seckill_id,
- 'seckill_time_id' => ',' . $data[ 'seckill_time_id' ] . ',',
- 'sku_id' => $item[ 'sku_id' ],
- 'goods_id' => $item[ 'goods_id' ],
- 'sku_image' => $sku_info[ 'sku_image' ],
- 'sku_name' => $sku_info[ 'sku_name' ],
- 'seckill_price' => $item[ 'seckill_price' ],
- 'price' => $sku_info[ 'price' ],
- 'stock' => $item[ 'seckill_stock' ],
- 'max_buy' => $item[ 'max_buy' ],
- 'status' => $seckill_data[ 'status' ]
- ];
- $goods_stock += $item[ 'seckill_stock' ];
- }
- model('promotion_seckill')->update([ 'goods_stock' => $goods_stock ], [ [ 'id', '=', $seckill_id ] ]);
- model('promotion_seckill_goods')->addList($add_goods_data);
-
- foreach ($seckill_time_id as $v) {
- $count = model('promotion_seckill_goods')->getCount([ [ 'seckill_time_id', 'like', '%,' . $v . ',%' ] ], '*', 'a', '', 'goods_id');
- model('promotion_seckill_time')->update([ 'goods_num' => $count ], [ [ 'id', '=', $v ] ]);
- }
- model('promotion_seckill')->commit();
- return $this->success();
- } catch (\Exception $e) {
- model('promotion_seckill')->rollback();
- return $this->error('', $e->getMessage());
- }
- }
-
- public function seckillSort($id, $sort)
- {
- $res = model('promotion_seckill')->update([ 'sort' => $sort ], [ [ 'id', '=', $id ] ]);
- return $this->success($res);
- }
-
- /**
- * 秒杀商品详情
- * @param array $condition
- * @param string $field
- * @param string $alias
- * @param array $join
- * @return array
- */
- public function getSeckillDetail($condition = [], $field = '*', $alias = '', $join = [])
- {
- $info = model("promotion_seckill")->getInfo($condition, $field, $alias, $join);
-
- $goods_sku = model('goods_sku')->getList([ [ 'goods_id', '=', $info[ 'goods_id' ] ], [ 'is_delete', '=', 0 ], [ 'goods_state', '=', 1 ] ], 'stock as goods_stock, goods_id, sku_id, sku_name,price,sku_image,stock');
-
- $discount_goods = model("promotion_seckill_goods")->getList([ [ 'goods_id', '=', $info[ 'goods_id' ] ], [ 'seckill_id', '=', $info[ 'id' ] ] ], '*');
-
- foreach ($goods_sku as $k => $v) {
- $goods_sku[ $k ][ 'is_select' ] = 0;
- $goods_sku[ $k ][ 'seckill_price' ] = $v[ 'price' ];
- $goods_sku[ $k ][ 'seckill_stock' ] = 0;
- $goods_sku[ $k ][ 'max_buy' ] = 0;
- $goods_sku[ $k ][ 'stock' ] = numberFormat($goods_sku[ $k ][ 'stock' ]);
- $goods_sku[ $k ][ 'goods_stock' ] = numberFormat($goods_sku[ $k ][ 'goods_stock' ]);
- foreach ($discount_goods as $key => $val) {
- if ($val[ 'sku_id' ] == $v[ 'sku_id' ]) {
- $goods_sku[ $k ][ 'is_select' ] = 1;
- $goods_sku[ $k ][ 'seckill_price' ] = $val[ 'seckill_price' ];
- $goods_sku[ $k ][ 'seckill_stock' ] = $val[ 'stock' ];
- $goods_sku[ $k ][ 'max_buy' ] = $val[ 'max_buy' ];
- }
- }
- }
-
- $info[ 'goods_sku' ] = $goods_sku;
- $info[ 'seckill_goods' ] = $discount_goods;
-
- return $this->success($info);
- }
-
- /**
- * 修改秒杀商品限购数量
- * @param $seckill_id
- * @param $site_id
- * @param $sku_id
- * @param $max_buy
- * @return array
- */
- public function editSeckillGoodsNum($seckill_id, $site_id, $sku_id, $max_buy)
- {
- $data = [
- 'seckill_id' => $seckill_id,
- 'site_id' => $site_id,
- 'sku_id' => $sku_id,
- 'max_buy' => $max_buy
- ];
- model("promotion_seckill_goods")->update($data, [ [ 'seckill_id', '=', $seckill_id ], [ 'sku_id', '=', $sku_id ], [ 'site_id', '=', $site_id ] ]);
- return $this->success();
- }
-
- /**
- * 删除秒杀商品
- * @param $seckill_id
- * @param $site_id
- * @return array
- */
- public function deleteSeckillGoods($seckill_id, $site_id)
- {
- $info = model("promotion_seckill")->getInfo([ [ 'id', '=', $seckill_id ] ], 'goods_id,seckill_time_id,status');
-
- if(empty($info)) return $this->error('', '该秒杀活动不存在');
- if($info['status'] == 1) return $this->error('', '该秒杀活动正在进行');
-
- $goods = new Goods();
- $goods->modifyPromotionAddon($info[ 'goods_id' ], [ 'seckill' => $seckill_id ], true);
- model("promotion_seckill")->delete([ [ 'id', '=', $seckill_id ], [ 'site_id', '=', $site_id ] ]);
- $goods_num = model("promotion_seckill_goods")->delete([ [ 'seckill_id', '=', $seckill_id ], [ 'site_id', '=', $site_id ] ]);
- $seckill_time_id = explode(',', $info[ 'seckill_time_id' ]);
- foreach ($seckill_time_id as $v) {
- $count = model('promotion_seckill_goods')->getCount([ [ 'seckill_time_id', 'like', '%,' . $v . ',%' ] ], '*', 'a', '', 'goods_id');
- model('promotion_seckill_time')->update([ 'goods_num' => $count ], [ [ 'id', '=', $v ] ]);
- }
- return $this->success();
- }
-
- /**
- * 获取秒杀详情
- * @param $seckill_id
- * @return array
- */
- public function getSeckillInfo($seckill_id)
- {
- $seckill_info = model('promotion_seckill')->getInfo([ [ 'id', '=', $seckill_id ] ]);
- if (empty($seckill_info)) {
- return $this->success([]);
- }
- $seckill_info[ 'seckill_start_time' ] = 0;
- $seckill_info[ 'seckill_end_time' ] = 0;
- $today_time = strtotime(date("Y-m-d"), time());
- $time = time() - $today_time;//当日时间戳
-
- $seckill_time_id = trim($seckill_info[ 'seckill_time_id' ], ',');
- $condition = [
- [ 'id', 'in', $seckill_time_id ],
- [ 'seckill_start_time', '<=', $time ],
- [ 'seckill_end_time', '>', $time ],
- ];
- $time_list = model('promotion_seckill_time')->getList($condition, 'seckill_start_time, seckill_end_time', 'seckill_start_time asc', '', '', '', 1);
- if (count($time_list) > 0) {
- $seckill_info[ 'seckill_start_time' ] = $time_list[ 0 ][ 'seckill_start_time' ];
- $seckill_info[ 'seckill_end_time' ] = $time_list[ 0 ][ 'seckill_end_time' ];
- }
-
- return $this->success($seckill_info);
- }
-
- /**
- * 获取秒杀列表
- * @param array $condition
- * @param int $page
- * @param int $page_size
- * @param string $order
- * @param string $field
- * @return mixed
- */
- public function getSeckillPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '', $alias = '', $join = [])
- {
- $list = model('promotion_seckill')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
- return $this->success($list);
- }
-
- /**
- * 获取秒杀商品列表
- * @param $seckill_time_id
- * @param $site_id
- * @param int $page
- * @param int $page_size
- * @return array
- */
- public function getSeckillGoodsPageList($seckill_time_id, $site_id, $page = 1, $page_size = PAGE_LIST_ROWS)
- {
- $order = 'nps.sort asc';
- $alias = 'nps';
-// [ 'nps.goods_stock', '>', 0 ],
- $condition = [
- [ 'nps.seckill_time_id', 'like', '%,' . $seckill_time_id . ',%' ],
- [ 'nps.status', '=', 1 ],
- [ 'g.goods_state', '=', 1 ],
- [ 'g.is_delete', '=', 0 ],
- [ 'nps.site_id', '=', $site_id ]
- ];
-
- $field = 'nps.id,nps.site_id,nps.seckill_name,nps.status,nps.remark,nps.start_time,nps.end_time,
- nps.goods_id,nps.seckill_time_id,nps.seckill_price,nps.sale_num,nps.goods_stock,
- g.goods_name,g.goods_image,g.price';
-
- $join = [
- [ 'goods g', 'nps.goods_id = g.goods_id', 'inner' ]
- ];
- $res = model('promotion_seckill')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
- foreach ($res[ 'list' ] as $k => $v) {
- $res[ 'list' ][ $k ][ 'goods_stock' ] = numberFormat($res[ 'list' ][ $k ][ 'goods_stock' ]);
- }
- return $this->success($res);
- }
-
- /**
- * 获取秒杀商品列表
- * @param $seckill_time_id
- * @param $site_id
- * @param null $limit
- * @return array
- */
- public function getSeckillList($seckill_time_id, $site_id, $limit = null)
- {
- $order = 'nps.sort asc';
- $alias = 'nps';
-// [ 'nps.goods_stock', '>', 0 ],
- $condition = [
- [ 'nps.seckill_time_id', 'like', '%,' . $seckill_time_id . ',%' ],
- [ 'nps.status', '=', 1 ],
- [ 'g.goods_state', '=', 1 ],
- [ 'g.is_delete', '=', 0 ],
- [ 'nps.site_id', '=', $site_id ]
- ];
-
- $field = 'nps.id,nps.site_id,nps.seckill_name,nps.status,nps.remark,nps.start_time,nps.end_time,
- nps.goods_id,nps.seckill_time_id,nps.seckill_price,nps.sale_num,nps.goods_stock,
- g.goods_name,g.goods_image,g.price';
-
- $join = [
- [ 'goods g', 'nps.goods_id = g.goods_id', 'inner' ]
- ];
- $list = model('promotion_seckill')->getList($condition, $field, $order, $alias, $join, '', $limit);
- foreach ($list as $k => $v) {
- $list[ $k ][ 'goods_stock' ] = numberFormat($list[ $k ][ 'goods_stock' ]);
- }
- return $this->success($list);
- }
-
- /**
- * 启动秒杀事件
- * @param $seckill_id
- * @return array
- */
- public function cronOpenSeckill($seckill_id)
- {
- $seckill_info = model('promotion_seckill')->getInfo([ [ 'id', '=', $seckill_id ] ], 'start_time,status, goods_id');
- if (!empty($seckill_info)) {
- if ($seckill_info[ 'start_time' ] <= time() && $seckill_info[ 'status' ] == 0) {
- model('promotion_seckill')->update([ 'status' => 1 ], [ [ 'id', '=', $seckill_id ] ]);
- model('promotion_seckill_goods')->update([ 'status' => 1 ], [ [ 'seckill_id', '=', $seckill_id ] ]);
- $goods = new Goods();
- $goods->modifyPromotionAddon($seckill_info[ 'goods_id' ], [ 'seckill' => $seckill_id ]);
- return $this->success(1);
- } else {
- return $this->error("", "秒杀已开启或者关闭");
- }
- } else {
- return $this->error("", "秒杀不存在");
- }
- }
-
- /**
- * 结束秒杀事件
- * @param $seckill_id
- * @return array
- */
- public function cronCloseSeckill($seckill_id)
- {
- $seckill_info = model('promotion_seckill')->getInfo([ [ 'id', '=', $seckill_id ] ], 'start_time,status, goods_id');
- if (!empty($seckill_info)) {
- //针对正在进行的活动
- if ($seckill_info[ 'status' ] == 1) {
-
- model('promotion_seckill')->update([ 'status' => 2 ], [ [ 'id', '=', $seckill_id ] ]);
- model('promotion_seckill_goods')->update([ 'status' => 2 ], [ [ 'seckill_id', '=', $seckill_id ] ]);
-
- $goods = new Goods();
- $goods->modifyPromotionAddon($seckill_info[ 'goods_id' ], [ 'seckill' => $seckill_id ], true);
-
- return $this->success();
- } else {
- return $this->error("", "正在进行的秒杀才能进行关闭操作");
- }
- } else {
- return $this->error("", "活动不存在");
- }
- }
-
- /**
- * 手动结束秒杀事件
- * @param $seckill_id
- * @return array
- */
- public function closeSeckill($seckill_id)
- {
- $seckill_info = model('promotion_seckill')->getInfo([ [ 'id', '=', $seckill_id ] ], 'start_time,status, goods_id');
- if (!empty($seckill_info)) {
- //针对正在进行的活动
- if ($seckill_info[ 'status' ] == 1) {
-
- model('promotion_seckill')->update([ 'status' => -1 ], [ [ 'id', '=', $seckill_id ] ]);
- model('promotion_seckill_goods')->update([ 'status' => -1 ], [ [ 'seckill_id', '=', $seckill_id ] ]);
-
- $goods = new Goods();
- $goods->modifyPromotionAddon($seckill_info[ 'goods_id' ], [ 'seckill' => $seckill_id ], true);
-
- return $this->success();
- } else {
- return $this->error("", "正在进行的秒杀才能进行关闭操作");
- }
- } else {
- return $this->error("", "活动不存在");
- }
- }
-
- /**
- * 获取商品列表
- * @param $seckill_id
- * @return array
- */
- public function getSeckillGoodsList($seckill_id)
- {
- $field = 'psg.*,sku.sku_name,sku.price,sku.sku_image';
- $alias = 'psg';
- $join = [
- [
- 'goods g',
- 'g.goods_id = psg.goods_id',
- 'inner'
- ],
- [
- 'goods_sku sku',
- 'sku.sku_id = psg.sku_id',
- 'inner'
- ]
- ];
- $condition = [
- [ 'psg.seckill_id', '=', $seckill_id ],
- [ 'g.is_delete', '=', 0 ], [ 'g.goods_state', '=', 1 ]
- ];
- $list = model('promotion_seckill_goods')->getList($condition, $field, '', $alias, $join);
- return $this->success($list);
- }
-
- /**
- * 获取秒杀商品信息
- * @param array $condition
- * @param string $field
- * @return array
- */
- public function getSeckillGoodsInfo($condition = [], $field = '')
- {
-
- if (empty($field)) {
- $field = 'psg.id,psg.seckill_id,ps.goods_id,psg.sku_id,psg.seckill_price,psg.max_buy,psg.stock,
- ps.status,ps.start_time,ps.end_time,(ps.sale_num + g.virtual_sale) as sale_num,ps.remark,
- sku.site_id,sku.sku_name,sku.sku_spec_format,sku.price,sku.promotion_type,
- sku.click_num,sku.collect_num,sku.sku_image,sku.sku_images,
- sku.goods_content,sku.goods_state,sku.is_virtual,sku.is_free_shipping,
- sku.goods_spec_format,sku.goods_attr_format,sku.introduction,sku.unit,
- sku.video_url,g.evaluate,sku.goods_service_ids,sku.support_trade_type,g.goods_image,
- ps.goods_stock,g.goods_name,sku.qr_id,g.stock_show,g.sale_show,g.label_name,g.category_id';
- }
- $join = [
- [ 'goods_sku sku', 'psg.sku_id = sku.sku_id', 'inner' ],
- [ 'goods g', 'g.goods_id = sku.goods_id', 'inner' ],
- [ 'promotion_seckill ps', 'ps.id = psg.seckill_id', 'inner' ],
- ];
- $seckill_goods_info = model('promotion_seckill_goods')->getInfo($condition, $field, 'psg', $join);
- if (!empty($seckill_goods_info)) {
- if (isset($seckill_goods_info[ 'sale_num' ])) {
- $seckill_goods_info[ 'sale_num' ] = numberFormat($seckill_goods_info[ 'sale_num' ]);
- }
- if (isset($seckill_goods_info[ 'goods_stock' ])) {
- $seckill_goods_info[ 'goods_stock' ] = numberFormat($seckill_goods_info[ 'goods_stock' ]);
- }
- }
- return $this->success($seckill_goods_info);
- }
-
- /**
- * 获取秒杀商品信息
- * @param array $condition
- * @return array
- */
- public function getSeckillGoodsSkuList($condition = [])
- {
- $field = 'psg.id,psg.seckill_id,ps.goods_id,psg.sku_id,psg.seckill_price,psg.max_buy,psg.stock,
- ps.status,ps.start_time,ps.end_time,ps.sale_num,sku.sku_name,sku.sku_spec_format,sku.price,sku.sku_image,sku.sku_images,sku.goods_spec_format,g.goods_image,ps.goods_stock';
- $join = [
- [ 'goods_sku sku', 'psg.sku_id = sku.sku_id', 'inner' ],
- [ 'goods g', 'g.goods_id = sku.goods_id', 'inner' ],
- [ 'promotion_seckill ps', 'ps.id = psg.seckill_id', 'inner' ],
- ];
- $list = model('promotion_seckill_goods')->getList($condition, $field, 'psg.id asc', 'psg', $join);
- foreach ($list as $k => $v) {
- $list[ $k ][ 'goods_stock' ] = numberFormat($list[ $k ][ 'goods_stock' ]);
- }
- return $this->success($list);
- }
-
- /**
- * 判断规格值是否禁用
- * @param $seckill_id
- * @param $site_id
- * @param string $goods_spec_format
- * @return int|mixed
- */
- public function getGoodsSpecFormat($seckill_id, $site_id, $goods_spec_format = '')
- {
- //获取活动参与的商品sku_ids
- $sku_ids = model('promotion_seckill_goods')->getColumn([ [ 'seckill_id', '=', $seckill_id ], [ 'site_id', '=', $site_id ] ], 'sku_id');
- $goods_model = new Goods();
- $res = $goods_model->getGoodsSpecFormat($sku_ids, $goods_spec_format);
- return $res;
- }
-
- /**
- * 生成砍价二维码
- * @param $seckill_id
- * @param string $name
- * @param string $type 类型 create创建 get获取
- * @return mixed|array
- */
- public function qrcode($seckill_id, $name, $site_id, $type = 'create')
- {
- $data = [
- 'site_id' => $site_id,
- 'app_type' => "all", // all为全部
- 'type' => $type, // 类型 create创建 get获取
- 'data' => [
- "seckill_id" => $seckill_id
- ],
- 'page' => '/pages_promotion/seckill/detail',
- 'qrcode_path' => 'upload/qrcode/seckill',
- 'qrcode_name' => "seckill_qrcode_" . $seckill_id
- ];
-
- event('Qrcode', $data, true);
- $app_type_list = config('app_type');
- $path = [];
- foreach ($app_type_list as $k => $v) {
- switch ( $k ) {
- case 'h5':
- $wap_domain = getH5Domain();
- $path[ $k ][ 'status' ] = 1;
- $path[ $k ][ 'url' ] = $wap_domain . $data[ 'page' ] . '?id=' . $seckill_id;
- $path[ $k ][ 'img' ] = "upload/qrcode/seckill/seckill_qrcode_" . $seckill_id . "_" . $k . ".png";
- break;
- case 'weapp' :
- $config = new ConfigModel();
- $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'WEAPP_CONFIG' ] ]);
- if (!empty($res[ 'data' ])) {
- if (empty($res[ 'data' ][ 'value' ][ 'qrcode' ])) {
- $path[ $k ][ 'status' ] = 2;
- $path[ $k ][ 'message' ] = '未配置微信小程序';
- } else {
- $path[ $k ][ 'status' ] = 1;
- $path[ $k ][ 'img' ] = $res[ 'data' ][ 'value' ][ 'qrcode' ];
- }
-
- } else {
- $path[ $k ][ 'status' ] = 2;
- $path[ $k ][ 'message' ] = '未配置微信小程序';
- }
- break;
-
- case 'wechat' :
- $config = new ConfigModel();
- $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'WECHAT_CONFIG' ] ]);
- if (!empty($res[ 'data' ])) {
- if (empty($res[ 'data' ][ 'value' ][ 'qrcode' ])) {
- $path[ $k ][ 'status' ] = 2;
- $path[ $k ][ 'message' ] = '未配置微信公众号';
- } else {
- $path[ $k ][ 'status' ] = 1;
- $path[ $k ][ 'img' ] = $res[ 'data' ][ 'value' ][ 'qrcode' ];
- }
- } else {
- $path[ $k ][ 'status' ] = 2;
- $path[ $k ][ 'message' ] = '未配置微信公众号';
- }
- break;
- }
-
- }
-
- $return = [
- 'path' => $path,
- 'name' => $name,
- ];
-
- return $this->success($return);
- }
-
- public function urlQrcode($page, $qrcode_param, $promotion_type, $app_type, $site_id)
- {
- $params = [
- 'site_id' => $site_id,
- 'data' => $qrcode_param,
- 'page' => $page,
- 'promotion_type' => $promotion_type,
- 'app_type' => $app_type,
- 'h5_path' => $page . '?id=' . $qrcode_param[ 'id' ],
- 'qrcode_path' => 'upload/qrcode/seckill',
- 'qrcode_name' => 'seckill_qrcode_' . $promotion_type . '_' . $qrcode_param[ 'id' ] . '_' . $site_id,
- ];
- $solitaire = event('PromotionQrcode', $params, true);
- return $this->success($solitaire);
- }
-
+ $data[ 'seckill_end_time' ]) {
+ return $this->error('', '秒杀时间段设置错误');
+ }
+
+ //时间段检测
+ $seckill_count = model('promotion_seckill_time')->getCount([
+ [ 'seckill_start_time|seckill_end_time', 'between', [ $data[ 'seckill_start_time' ], $data[ 'seckill_end_time' ] ] ],
+ [ 'site_id', '=', $data[ 'site_id' ] ]
+ ]);
+ if ($seckill_count > 0) {
+ return $this->error('', '秒杀场次设置冲突');
+ }
+ $seckill_count = model('promotion_seckill_time')->getCount([
+ [ 'seckill_start_time', '<=', $data[ 'seckill_start_time' ] ],
+ [ 'seckill_end_time', '>=', $data[ 'seckill_end_time' ] ],
+ [ 'site_id', '=', $data[ 'site_id' ] ]
+ ]);
+ if ($seckill_count > 0) {
+ return $this->error('', '秒杀场次设置冲突');
+ }
+ //添加数据
+ $data[ 'create_time' ] = time();
+ $seckill_id = model('promotion_seckill_time')->add($data);
+ Cache::tag("promotion_seckill_time")->clear();
+ return $this->success($seckill_id);
+ }
+
+ /**
+ * 修改秒杀时段
+ * @param $data
+ * @param $site_id
+ * @return array
+ */
+ public function editSeckillTime($data, $site_id)
+ {
+ if ($data[ 'seckill_start_time' ] > $data[ 'seckill_end_time' ]) {
+ return $this->error('', '秒杀时间段设置错误');
+ }
+ //时间段检测
+ $seckill_count = model('promotion_seckill_time')->getCount([
+ [ 'seckill_start_time|seckill_end_time', 'between', [ $data[ 'seckill_start_time' ], $data[ 'seckill_end_time' ] ] ],
+ [ 'site_id', '=', $site_id ],
+ [ 'id', '<>', $data[ 'id' ] ]
+ ]);
+ if ($seckill_count > 0) {
+ return $this->error('', '秒杀场次设置冲突');
+ }
+ $seckill_count = model('promotion_seckill_time')->getCount([
+ [ 'seckill_start_time', '<=', $data[ 'seckill_start_time' ] ],
+ [ 'seckill_end_time', '>=', $data[ 'seckill_end_time' ] ],
+ [ 'site_id', '=', $site_id ],
+ [ 'id', '<>', $data[ 'id' ] ]
+ ]);
+ if ($seckill_count > 0) {
+ return $this->error('', '秒杀场次设置冲突');
+ }
+
+ //更新数据
+ $data[ 'modify_time' ] = time();
+ $res = model('promotion_seckill_time')->update($data, [ [ 'id', '=', $data[ 'id' ] ] ]);
+ Cache::tag("promotion_seckill_time")->clear();
+ return $this->success($res);
+ }
+
+ /**
+ * 删除秒杀时段
+ * @param $seckill_time_id
+ * @return array
+ */
+ public function deleteSeckillTime($seckill_time_id)
+ {
+ $res = model('promotion_seckill_time')->delete([ [ 'id', '=', $seckill_time_id ] ]);
+ if ($res) {
+
+ $goods = new Goods();
+
+ $condition = [
+ [ 'seckill_time_id', 'like', '%,' . $seckill_time_id . ',%' ]
+ ];
+ $seckill_list = model('promotion_seckill')->getList($condition, 'id,seckill_time_id,goods_id');
+
+ foreach ($seckill_list as $k => $v) {
+
+ $time_ids = explode(',', trim($v[ 'seckill_time_id' ], ','));
+ unset($time_ids[ array_search($seckill_time_id, $time_ids) ]);
+
+ if (empty($time_ids)) {
+ $goods->modifyPromotionAddon($v[ 'goods_id' ], [ 'seckill' => $v[ 'id' ] ], true);
+ model('promotion_seckill_goods')->delete([ [ 'seckill_id', '=', $v[ 'id' ] ] ]);
+ model('promotion_seckill')->delete([ [ 'id', '=', $v[ 'id' ] ] ]);
+ } else {
+
+ $time_id = ',' . implode(',', $time_ids) . ',';
+ model('promotion_seckill')->update([ 'seckill_time_id' => $time_id ], [ [ 'id', '=', $v[ 'id' ] ] ]);
+ model('promotion_seckill_goods')->update([ 'seckill_time_id' => $time_id ], [ [ 'seckill_id', '=', $v[ 'id' ] ] ]);
+ }
+
+ }
+ }
+ Cache::tag("promotion_seckill_time")->clear();
+ return $this->success($res);
+ }
+
+ /**
+ * 获取秒杀时段信息
+ * @param $condition
+ * @param string $field
+ * @return array
+ */
+ public function getSeckillTimeInfo($condition, $field = '*')
+ {
+ $data = json_encode([ $condition, $field ]);
+ $cache = Cache::get("promotion_seckill_time_getSeckillInfo_" . $data);
+ if (!empty($cache)) {
+ return $this->success($cache);
+ }
+ $res = model('promotion_seckill_time')->getInfo($condition, $field);
+ Cache::tag("promotion_seckill_time")->set("promotion_seckill_time_getSeckillInfo_" . $data, $res);
+ return $this->success($res);
+ }
+
+ /**
+ * 获取秒杀时段列表
+ * @param array $condition
+ * @param string $field
+ * @param string $order
+ * @param null $limit
+ * @return array
+ */
+ public function getSeckillTimeList($condition = [], $field = '*', $order = '', $limit = null)
+ {
+ $list = model('promotion_seckill_time')->getList($condition, $field, $order, '', '', '', $limit);
+ return $this->success($list);
+ }
+
+ /**
+ * 获取有商品的秒杀时段列表
+ * @param $condition
+ * @param $field
+ * @param string $order
+ * @return array
+ */
+ public function getGoodsSeckillTimeList($condition, $field, $order = 'seckill_start_time asc')
+ {
+ if (empty($field)) {
+ $field = 'id, site_id, name, seckill_start_time, seckill_end_time';
+ }
+
+ $seckill_time = model('promotion_seckill_time')->getList($condition, $field, $order);
+ foreach ($seckill_time as $k => $v) {
+ $condition = [
+ [ 'seckill_time_id', 'like', '%,' . $v[ 'id' ] . ',%' ],
+ [ 'status', '=', 1 ],
+ [ 'g.goods_state', '=', 1 ],
+ [ 'g.is_delete', '=', 0 ]
+ ];
+ $join = [
+ [ 'goods g', 'g.goods_id = psg.goods_id', 'inner' ]
+ ];
+ $goods = model('promotion_seckill_goods')->getInfo($condition, 'id', 'psg', $join);
+ if (empty($goods)) unset($seckill_time[ $k ]);
+ }
+ return $this->success($seckill_time);
+ }
+
+ /**
+ * 转换秒杀时间
+ * @param $info
+ * @return mixed
+ */
+ public function transformSeckillTime($info)
+ {
+ $info[ 'start_hour' ] = floor($info[ 'seckill_start_time' ] / 3600);
+ $info[ 'start_minute' ] = floor(( $info[ 'seckill_start_time' ] % 3600 ) / 60);
+ $info[ 'start_second' ] = $info[ 'seckill_start_time' ] % 60;
+
+ $info[ 'end_hour' ] = floor($info[ 'seckill_end_time' ] / 3600);
+ $info[ 'end_minute' ] = floor(( $info[ 'seckill_end_time' ] % 3600 ) / 60);
+ $info[ 'end_second' ] = $info[ 'seckill_end_time' ] % 60;
+
+ if ($info[ 'start_hour' ] < 10) $info[ 'start_hour' ] = '0' . $info[ 'start_hour' ];
+ if ($info[ 'start_minute' ] < 10) $info[ 'start_minute' ] = '0' . $info[ 'start_minute' ];
+ if ($info[ 'start_second' ] < 10) $info[ 'start_second' ] = '0' . $info[ 'start_second' ];
+
+ if ($info[ 'end_hour' ] < 10) $info[ 'end_hour' ] = '0' . $info[ 'end_hour' ];
+ if ($info[ 'end_minute' ] < 10) $info[ 'end_minute' ] = '0' . $info[ 'end_minute' ];
+ if ($info[ 'end_second' ] < 10) $info[ 'end_second' ] = '0' . $info[ 'end_second' ];
+
+ return $info;
+ }
+
+ /******************************************************秒杀商品*********************************************************************/
+ /**
+ * 添加秒杀商品
+ * @param $data
+ * @return array
+ */
+ public function addSeckillGoods($data)
+ {
+ $cron = new Cron();
+ $goods_data = $data[ 'goods_data' ];
+
+ if (empty($data[ 'seckill_time_id' ])) {
+ return $this->error('', '请选择秒杀时段');
+ }
+ $seckill_time_id = explode(',', $data[ 'seckill_time_id' ]);
+
+ //时间段检测
+ foreach ($seckill_time_id as $v) {
+ $seckill_count = model('promotion_seckill')->getCount([
+ [ 'goods_id', 'in', $data[ 'goods_ids' ] ],
+ [ 'status', 'in', '0,1' ],
+ [ 'seckill_time_id', 'like', '%,' . $v . ',%' ],
+ [ 'site_id', '=', $data[ 'site_id' ] ],
+ [ '', 'exp', Db::raw('not ( (`start_time` > ' . $data[ 'end_time' ] . ' and `start_time` > ' . $data[ 'start_time' ] . ' ) or (`end_time` < ' . $data[ 'start_time' ] . ' and `end_time` < ' . $data[ 'end_time' ] . '))') ]//todo 修正 所有的优惠都要一样
+ ]);
+ if ($seckill_count > 0) {
+ return $this->error('', '有商品已设置秒杀,请不要重复设置');
+ }
+ }
+
+ model('promotion_seckill')->startTrans();
+ try {
+ $seckill_data = [
+ 'site_id' => $data[ 'site_id' ],
+ 'seckill_name' => $data[ 'seckill_name' ],
+ 'remark' => $data[ 'remark' ],
+ 'seckill_time_id' => ',' . $data[ 'seckill_time_id' ] . ',',
+ 'start_time' => $data[ 'start_time' ],
+ 'end_time' => $data[ 'end_time' ],
+ 'create_time' => time(),
+ 'sort' => $data[ 'sort' ],
+ ];
+
+ $goods = new Goods();
+ $add_goods_data = [];
+ foreach ($goods_data as $k => $v) {
+ $seckill_data[ 'goods_id' ] = $v[ 'goods_id' ];
+ $seckill_data[ 'goods_name' ] = $v[ 'sku_list' ][ 0 ][ 'sku_name' ];
+ $seckill_data[ 'goods_image' ] = $v[ 'sku_list' ][ 0 ][ 'sku_image' ];
+ $seckill_data[ 'seckill_price' ] = $v[ 'sku_list' ][ 0 ][ 'seckill_price' ];
+
+ if ($data[ 'start_time' ] <= time()) {
+ $seckill_data[ 'status' ] = 1;//直接启动
+ $seckill_id = model('promotion_seckill')->add($seckill_data);
+ $goods->modifyPromotionAddon($v[ 'goods_id' ], [ 'seckill' => $seckill_id ]);
+ $cron->addCron(1, 0, "秒杀关闭", "CloseSeckill", $data[ 'end_time' ], $seckill_id);
+ } else {
+ $seckill_data[ 'status' ] = 0;
+ $seckill_id = model('promotion_seckill')->add($seckill_data);
+ $cron->addCron(1, 0, "秒杀开启", "OpenSeckill", $data[ 'start_time' ], $seckill_id);
+ $cron->addCron(1, 0, "秒杀关闭", "CloseSeckill", $data[ 'end_time' ], $seckill_id);
+ }
+
+ $goods_stock = 0; // 秒杀商品总库存
+
+ foreach ($v[ 'sku_list' ] as $key => $item) {
+ $sku_info = model('goods_sku')->getInfo([ [ 'sku_id', '=', $item[ 'sku_id' ] ] ], 'goods_id, sku_id, sku_name,price,sku_image');
+ $add_goods_data[] = [
+ 'site_id' => $data[ 'site_id' ],
+ 'seckill_id' => $seckill_id,
+ 'seckill_time_id' => ',' . $data[ 'seckill_time_id' ] . ',',
+ 'sku_id' => $item[ 'sku_id' ],
+ 'goods_id' => $item[ 'goods_id' ],
+ 'sku_image' => $sku_info[ 'sku_image' ],
+ 'sku_name' => $sku_info[ 'sku_name' ],
+ 'seckill_price' => $item[ 'seckill_price' ],
+ 'price' => $sku_info[ 'price' ],
+ 'stock' => $item[ 'seckill_stock' ],
+ 'max_buy' => $item[ 'max_buy' ],
+ 'status' => $seckill_data[ 'status' ]
+ ];
+ $goods_stock += $item[ 'seckill_stock' ];
+ }
+ model('promotion_seckill')->update([ 'goods_stock' => $goods_stock ], [ [ 'id', '=', $seckill_id ] ]);
+ }
+ model('promotion_seckill_goods')->addList($add_goods_data);
+ foreach ($seckill_time_id as $v) {
+ $count = model('promotion_seckill_goods')->getCount([ [ 'seckill_time_id', 'like', '%,' . $v . ',%' ] ], '*', 'a', '', 'goods_id');
+ model('promotion_seckill_time')->update([ 'goods_num' => $count ], [ [ 'id', '=', $v ] ]);
+ }
+ model('promotion_seckill')->commit();
+ return $this->success();
+ } catch (\Exception $e) {
+ model('promotion_seckill')->rollback();
+ return $this->error('', $e->getMessage());
+ }
+
+ }
+
+ /**
+ * 修改秒杀商品
+ * @param $data
+ * @return array
+ */
+ public function editSeckillGoods($data)
+ {
+ $cron = new Cron();
+
+ if (empty($data[ 'seckill_time_id' ])) {
+ return $this->error('', '请选择秒杀时段');
+ }
+ $seckill_time_id = explode(',', $data[ 'seckill_time_id' ]);
+
+ //时间段检测
+ foreach ($seckill_time_id as $v) {
+ $seckill_count = model('promotion_seckill')->getInfo([
+ [ 'goods_id', 'in', $data[ 'goods_ids' ] ],
+ [ 'status', 'in', '0,1' ],
+ [ 'site_id', '=', $data[ 'site_id' ] ],
+ [ 'seckill_time_id', 'like', '%,' . $v . ',%' ],
+ [ 'id', '<>', $data[ 'id' ] ],
+ [ '', 'exp', Db::raw('not ( (`start_time` > ' . $data[ 'end_time' ] . ' and `start_time` > ' . $data[ 'start_time' ] . ' ) or (`end_time` < ' . $data[ 'start_time' ] . ' and `end_time` < ' . $data[ 'end_time' ] . '))') ]//todo 修正 所有的优惠都要一样
+ ]);
+ if ($seckill_count > 0) {
+ return $this->error('', '有商品已设置秒杀,请不要重复设置');
+ }
+ }
+
+ model('promotion_seckill')->startTrans();
+ try {
+ $seckill_data = [
+ 'site_id' => $data[ 'site_id' ],
+ 'seckill_name' => $data[ 'seckill_name' ],
+ 'remark' => $data[ 'remark' ],
+ 'seckill_time_id' => ',' . $data[ 'seckill_time_id' ] . ',',
+ 'start_time' => $data[ 'start_time' ],
+ 'end_time' => $data[ 'end_time' ],
+ 'modify_time' => time(),
+ 'sort' => $data[ 'sort' ],
+ ];
+
+ $goods = new Goods();
+ $add_goods_data = [];
+ $seckill_data[ 'goods_id' ] = $data[ 'sku_list' ][ 0 ][ 'goods_id' ];
+ $seckill_data[ 'goods_name' ] = $data[ 'sku_list' ][ 0 ][ 'sku_name' ];
+ $seckill_data[ 'goods_image' ] = $data[ 'sku_list' ][ 0 ][ 'sku_image' ];
+ $seckill_data[ 'seckill_price' ] = $data[ 'sku_list' ][ 0 ][ 'seckill_price' ];
+
+ $seckill_id = $data[ 'id' ];
+
+ if ($data[ 'start_time' ] <= time()) {
+ $seckill_data[ 'status' ] = 1;//直接启动
+ model('promotion_seckill')->update($seckill_data, [ [ 'id', '=', $seckill_id ] ]);
+ $goods->modifyPromotionAddon($data[ 'sku_list' ][ 0 ][ 'goods_id' ], [ 'seckill' => $seckill_id ]);
+ $cron->addCron(1, 0, "秒杀关闭", "CloseSeckill", $data[ 'end_time' ], $seckill_id);
+ } else {
+ $seckill_data[ 'status' ] = 0;
+ model('promotion_seckill')->update($seckill_data, [ [ 'id', '=', $seckill_id ] ]);
+ $cron->addCron(1, 0, "秒杀开启", "OpenSeckill", $data[ 'start_time' ], $seckill_id);
+ $cron->addCron(1, 0, "秒杀关闭", "CloseSeckill", $data[ 'end_time' ], $seckill_id);
+ }
+
+ model('promotion_seckill_goods')->delete([ [ 'seckill_id', '=', $seckill_id ] ]);
+
+ $goods_stock = 0; // 秒杀商品总库存
+
+ foreach ($data[ 'sku_list' ] as $key => $item) {
+ $sku_info = model('goods_sku')->getInfo([ [ 'sku_id', '=', $item[ 'sku_id' ] ] ], 'goods_id, sku_id, sku_name,price,sku_image');
+ $add_goods_data[] = [
+ 'site_id' => $data[ 'site_id' ],
+ 'seckill_id' => $seckill_id,
+ 'seckill_time_id' => ',' . $data[ 'seckill_time_id' ] . ',',
+ 'sku_id' => $item[ 'sku_id' ],
+ 'goods_id' => $item[ 'goods_id' ],
+ 'sku_image' => $sku_info[ 'sku_image' ],
+ 'sku_name' => $sku_info[ 'sku_name' ],
+ 'seckill_price' => $item[ 'seckill_price' ],
+ 'price' => $sku_info[ 'price' ],
+ 'stock' => $item[ 'seckill_stock' ],
+ 'max_buy' => $item[ 'max_buy' ],
+ 'status' => $seckill_data[ 'status' ]
+ ];
+ $goods_stock += $item[ 'seckill_stock' ];
+ }
+ model('promotion_seckill')->update([ 'goods_stock' => $goods_stock ], [ [ 'id', '=', $seckill_id ] ]);
+ model('promotion_seckill_goods')->addList($add_goods_data);
+
+ foreach ($seckill_time_id as $v) {
+ $count = model('promotion_seckill_goods')->getCount([ [ 'seckill_time_id', 'like', '%,' . $v . ',%' ] ], '*', 'a', '', 'goods_id');
+ model('promotion_seckill_time')->update([ 'goods_num' => $count ], [ [ 'id', '=', $v ] ]);
+ }
+ model('promotion_seckill')->commit();
+ return $this->success();
+ } catch (\Exception $e) {
+ model('promotion_seckill')->rollback();
+ return $this->error('', $e->getMessage());
+ }
+ }
+
+ public function seckillSort($id, $sort)
+ {
+ $res = model('promotion_seckill')->update([ 'sort' => $sort ], [ [ 'id', '=', $id ] ]);
+ return $this->success($res);
+ }
+
+ /**
+ * 秒杀商品详情
+ * @param array $condition
+ * @param string $field
+ * @param string $alias
+ * @param array $join
+ * @return array
+ */
+ public function getSeckillDetail($condition = [], $field = '*', $alias = '', $join = [])
+ {
+ $info = model("promotion_seckill")->getInfo($condition, $field, $alias, $join);
+
+ $goods_sku = model('goods_sku')->getList([ [ 'goods_id', '=', $info[ 'goods_id' ] ], [ 'is_delete', '=', 0 ], [ 'goods_state', '=', 1 ] ], 'stock as goods_stock, goods_id, sku_id, sku_name,price,sku_image,stock');
+
+ $discount_goods = model("promotion_seckill_goods")->getList([ [ 'goods_id', '=', $info[ 'goods_id' ] ], [ 'seckill_id', '=', $info[ 'id' ] ] ], '*');
+
+ foreach ($goods_sku as $k => $v) {
+ $goods_sku[ $k ][ 'is_select' ] = 0;
+ $goods_sku[ $k ][ 'seckill_price' ] = $v[ 'price' ];
+ $goods_sku[ $k ][ 'seckill_stock' ] = 0;
+ $goods_sku[ $k ][ 'max_buy' ] = 0;
+ $goods_sku[ $k ][ 'stock' ] = numberFormat($goods_sku[ $k ][ 'stock' ]);
+ $goods_sku[ $k ][ 'goods_stock' ] = numberFormat($goods_sku[ $k ][ 'goods_stock' ]);
+ foreach ($discount_goods as $key => $val) {
+ if ($val[ 'sku_id' ] == $v[ 'sku_id' ]) {
+ $goods_sku[ $k ][ 'is_select' ] = 1;
+ $goods_sku[ $k ][ 'seckill_price' ] = $val[ 'seckill_price' ];
+ $goods_sku[ $k ][ 'seckill_stock' ] = $val[ 'stock' ];
+ $goods_sku[ $k ][ 'max_buy' ] = $val[ 'max_buy' ];
+ }
+ }
+ }
+
+ $info[ 'goods_sku' ] = $goods_sku;
+ $info[ 'seckill_goods' ] = $discount_goods;
+
+ return $this->success($info);
+ }
+
+ /**
+ * 修改秒杀商品限购数量
+ * @param $seckill_id
+ * @param $site_id
+ * @param $sku_id
+ * @param $max_buy
+ * @return array
+ */
+ public function editSeckillGoodsNum($seckill_id, $site_id, $sku_id, $max_buy)
+ {
+ $data = [
+ 'seckill_id' => $seckill_id,
+ 'site_id' => $site_id,
+ 'sku_id' => $sku_id,
+ 'max_buy' => $max_buy
+ ];
+ model("promotion_seckill_goods")->update($data, [ [ 'seckill_id', '=', $seckill_id ], [ 'sku_id', '=', $sku_id ], [ 'site_id', '=', $site_id ] ]);
+ return $this->success();
+ }
+
+ /**
+ * 删除秒杀商品
+ * @param $seckill_id
+ * @param $site_id
+ * @return array
+ */
+ public function deleteSeckillGoods($seckill_id, $site_id)
+ {
+ $info = model("promotion_seckill")->getInfo([ [ 'id', '=', $seckill_id ] ], 'goods_id,seckill_time_id,status');
+
+ if(empty($info)) return $this->error('', '该秒杀活动不存在');
+ if($info['status'] == 1) return $this->error('', '该秒杀活动正在进行');
+
+ $goods = new Goods();
+ $goods->modifyPromotionAddon($info[ 'goods_id' ], [ 'seckill' => $seckill_id ], true);
+ model("promotion_seckill")->delete([ [ 'id', '=', $seckill_id ], [ 'site_id', '=', $site_id ] ]);
+ $goods_num = model("promotion_seckill_goods")->delete([ [ 'seckill_id', '=', $seckill_id ], [ 'site_id', '=', $site_id ] ]);
+ $seckill_time_id = explode(',', $info[ 'seckill_time_id' ]);
+ foreach ($seckill_time_id as $v) {
+ $count = model('promotion_seckill_goods')->getCount([ [ 'seckill_time_id', 'like', '%,' . $v . ',%' ] ], '*', 'a', '', 'goods_id');
+ model('promotion_seckill_time')->update([ 'goods_num' => $count ], [ [ 'id', '=', $v ] ]);
+ }
+ return $this->success();
+ }
+
+ /**
+ * 获取秒杀详情
+ * @param $seckill_id
+ * @return array
+ */
+ public function getSeckillInfo($seckill_id)
+ {
+ $seckill_info = model('promotion_seckill')->getInfo([ [ 'id', '=', $seckill_id ] ]);
+ if (empty($seckill_info)) {
+ return $this->success([]);
+ }
+ $seckill_info[ 'seckill_start_time' ] = 0;
+ $seckill_info[ 'seckill_end_time' ] = 0;
+ $today_time = strtotime(date("Y-m-d"), time());
+ $time = time() - $today_time;//当日时间戳
+
+ $seckill_time_id = trim($seckill_info[ 'seckill_time_id' ], ',');
+ $condition = [
+ [ 'id', 'in', $seckill_time_id ],
+ [ 'seckill_start_time', '<=', $time ],
+ [ 'seckill_end_time', '>', $time ],
+ ];
+ $time_list = model('promotion_seckill_time')->getList($condition, 'seckill_start_time, seckill_end_time', 'seckill_start_time asc', '', '', '', 1);
+ if (count($time_list) > 0) {
+ $seckill_info[ 'seckill_start_time' ] = $time_list[ 0 ][ 'seckill_start_time' ];
+ $seckill_info[ 'seckill_end_time' ] = $time_list[ 0 ][ 'seckill_end_time' ];
+ }
+
+ return $this->success($seckill_info);
+ }
+
+ /**
+ * 获取秒杀列表
+ * @param array $condition
+ * @param int $page
+ * @param int $page_size
+ * @param string $order
+ * @param string $field
+ * @return mixed
+ */
+ public function getSeckillPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '', $alias = '', $join = [])
+ {
+ $list = model('promotion_seckill')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
+ return $this->success($list);
+ }
+
+ /**
+ * 获取秒杀商品列表
+ * @param $seckill_time_id
+ * @param $site_id
+ * @param int $page
+ * @param int $page_size
+ * @return array
+ */
+ public function getSeckillGoodsPageList($seckill_time_id, $site_id, $page = 1, $page_size = PAGE_LIST_ROWS)
+ {
+ $order = 'nps.sort asc';
+ $alias = 'nps';
+// [ 'nps.goods_stock', '>', 0 ],
+ $condition = [
+ [ 'nps.seckill_time_id', 'like', '%,' . $seckill_time_id . ',%' ],
+ [ 'nps.status', '=', 1 ],
+ [ 'g.goods_state', '=', 1 ],
+ [ 'g.is_delete', '=', 0 ],
+ [ 'nps.site_id', '=', $site_id ]
+ ];
+
+ $field = 'nps.id,nps.site_id,nps.seckill_name,nps.status,nps.remark,nps.start_time,nps.end_time,
+ nps.goods_id,nps.seckill_time_id,nps.seckill_price,nps.sale_num,nps.goods_stock,
+ g.goods_name,g.goods_image,g.price';
+
+ $join = [
+ [ 'goods g', 'nps.goods_id = g.goods_id', 'inner' ]
+ ];
+ $res = model('promotion_seckill')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
+ foreach ($res[ 'list' ] as $k => $v) {
+ $res[ 'list' ][ $k ][ 'goods_stock' ] = numberFormat($res[ 'list' ][ $k ][ 'goods_stock' ]);
+ }
+ return $this->success($res);
+ }
+
+ /**
+ * 获取秒杀商品列表
+ * @param $seckill_time_id
+ * @param $site_id
+ * @param null $limit
+ * @return array
+ */
+ public function getSeckillList($seckill_time_id, $site_id, $limit = null)
+ {
+ $order = 'nps.sort asc';
+ $alias = 'nps';
+// [ 'nps.goods_stock', '>', 0 ],
+ $condition = [
+ [ 'nps.seckill_time_id', 'like', '%,' . $seckill_time_id . ',%' ],
+ [ 'nps.status', '=', 1 ],
+ [ 'g.goods_state', '=', 1 ],
+ [ 'g.is_delete', '=', 0 ],
+ [ 'nps.site_id', '=', $site_id ]
+ ];
+
+ $field = 'nps.id,nps.site_id,nps.seckill_name,nps.status,nps.remark,nps.start_time,nps.end_time,
+ nps.goods_id,nps.seckill_time_id,nps.seckill_price,nps.sale_num,nps.goods_stock,
+ g.goods_name,g.goods_image,g.price';
+
+ $join = [
+ [ 'goods g', 'nps.goods_id = g.goods_id', 'inner' ]
+ ];
+ $list = model('promotion_seckill')->getList($condition, $field, $order, $alias, $join, '', $limit);
+ foreach ($list as $k => $v) {
+ $list[ $k ][ 'goods_stock' ] = numberFormat($list[ $k ][ 'goods_stock' ]);
+ }
+ return $this->success($list);
+ }
+
+ /**
+ * 启动秒杀事件
+ * @param $seckill_id
+ * @return array
+ */
+ public function cronOpenSeckill($seckill_id)
+ {
+ $seckill_info = model('promotion_seckill')->getInfo([ [ 'id', '=', $seckill_id ] ], 'start_time,status, goods_id');
+ if (!empty($seckill_info)) {
+ if ($seckill_info[ 'start_time' ] <= time() && $seckill_info[ 'status' ] == 0) {
+ model('promotion_seckill')->update([ 'status' => 1 ], [ [ 'id', '=', $seckill_id ] ]);
+ model('promotion_seckill_goods')->update([ 'status' => 1 ], [ [ 'seckill_id', '=', $seckill_id ] ]);
+ $goods = new Goods();
+ $goods->modifyPromotionAddon($seckill_info[ 'goods_id' ], [ 'seckill' => $seckill_id ]);
+ return $this->success(1);
+ } else {
+ return $this->error("", "秒杀已开启或者关闭");
+ }
+ } else {
+ return $this->error("", "秒杀不存在");
+ }
+ }
+
+ /**
+ * 结束秒杀事件
+ * @param $seckill_id
+ * @return array
+ */
+ public function cronCloseSeckill($seckill_id)
+ {
+ $seckill_info = model('promotion_seckill')->getInfo([ [ 'id', '=', $seckill_id ] ], 'start_time,status, goods_id');
+ if (!empty($seckill_info)) {
+ //针对正在进行的活动
+ if ($seckill_info[ 'status' ] == 1) {
+
+ model('promotion_seckill')->update([ 'status' => 2 ], [ [ 'id', '=', $seckill_id ] ]);
+ model('promotion_seckill_goods')->update([ 'status' => 2 ], [ [ 'seckill_id', '=', $seckill_id ] ]);
+
+ $goods = new Goods();
+ $goods->modifyPromotionAddon($seckill_info[ 'goods_id' ], [ 'seckill' => $seckill_id ], true);
+
+ return $this->success();
+ } else {
+ return $this->error("", "正在进行的秒杀才能进行关闭操作");
+ }
+ } else {
+ return $this->error("", "活动不存在");
+ }
+ }
+
+ /**
+ * 手动结束秒杀事件
+ * @param $seckill_id
+ * @return array
+ */
+ public function closeSeckill($seckill_id)
+ {
+ $seckill_info = model('promotion_seckill')->getInfo([ [ 'id', '=', $seckill_id ] ], 'start_time,status, goods_id');
+ if (!empty($seckill_info)) {
+ //针对正在进行的活动
+ if ($seckill_info[ 'status' ] == 1) {
+
+ model('promotion_seckill')->update([ 'status' => -1 ], [ [ 'id', '=', $seckill_id ] ]);
+ model('promotion_seckill_goods')->update([ 'status' => -1 ], [ [ 'seckill_id', '=', $seckill_id ] ]);
+
+ $goods = new Goods();
+ $goods->modifyPromotionAddon($seckill_info[ 'goods_id' ], [ 'seckill' => $seckill_id ], true);
+
+ return $this->success();
+ } else {
+ return $this->error("", "正在进行的秒杀才能进行关闭操作");
+ }
+ } else {
+ return $this->error("", "活动不存在");
+ }
+ }
+
+ /**
+ * 获取商品列表
+ * @param $seckill_id
+ * @return array
+ */
+ public function getSeckillGoodsList($seckill_id)
+ {
+ $field = 'psg.*,sku.sku_name,sku.price,sku.sku_image';
+ $alias = 'psg';
+ $join = [
+ [
+ 'goods g',
+ 'g.goods_id = psg.goods_id',
+ 'inner'
+ ],
+ [
+ 'goods_sku sku',
+ 'sku.sku_id = psg.sku_id',
+ 'inner'
+ ]
+ ];
+ $condition = [
+ [ 'psg.seckill_id', '=', $seckill_id ],
+ [ 'g.is_delete', '=', 0 ], [ 'g.goods_state', '=', 1 ]
+ ];
+ $list = model('promotion_seckill_goods')->getList($condition, $field, '', $alias, $join);
+ return $this->success($list);
+ }
+
+ /**
+ * 获取秒杀商品信息
+ * @param array $condition
+ * @param string $field
+ * @return array
+ */
+ public function getSeckillGoodsInfo($condition = [], $field = '')
+ {
+
+ if (empty($field)) {
+ $field = 'psg.id,psg.seckill_id,ps.goods_id,psg.sku_id,psg.seckill_price,psg.max_buy,psg.stock,
+ ps.status,ps.start_time,ps.end_time,(ps.sale_num + g.virtual_sale) as sale_num,ps.remark,
+ sku.site_id,sku.sku_name,sku.sku_spec_format,sku.price,sku.promotion_type,
+ sku.click_num,sku.collect_num,sku.sku_image,sku.sku_images,
+ sku.goods_content,sku.goods_state,sku.is_virtual,sku.is_free_shipping,
+ sku.goods_spec_format,sku.goods_attr_format,sku.introduction,sku.unit,
+ sku.video_url,g.evaluate,sku.goods_service_ids,sku.support_trade_type,g.goods_image,
+ ps.goods_stock,g.goods_name,sku.qr_id,g.stock_show,g.sale_show,g.label_name,g.category_id';
+ }
+ $join = [
+ [ 'goods_sku sku', 'psg.sku_id = sku.sku_id', 'inner' ],
+ [ 'goods g', 'g.goods_id = sku.goods_id', 'inner' ],
+ [ 'promotion_seckill ps', 'ps.id = psg.seckill_id', 'inner' ],
+ ];
+ $seckill_goods_info = model('promotion_seckill_goods')->getInfo($condition, $field, 'psg', $join);
+ if (!empty($seckill_goods_info)) {
+ if (isset($seckill_goods_info[ 'sale_num' ])) {
+ $seckill_goods_info[ 'sale_num' ] = numberFormat($seckill_goods_info[ 'sale_num' ]);
+ }
+ if (isset($seckill_goods_info[ 'goods_stock' ])) {
+ $seckill_goods_info[ 'goods_stock' ] = numberFormat($seckill_goods_info[ 'goods_stock' ]);
+ }
+ }
+ return $this->success($seckill_goods_info);
+ }
+
+ /**
+ * 获取秒杀商品信息
+ * @param array $condition
+ * @return array
+ */
+ public function getSeckillGoodsSkuList($condition = [])
+ {
+ $field = 'psg.id,psg.seckill_id,ps.goods_id,psg.sku_id,psg.seckill_price,psg.max_buy,psg.stock,
+ ps.status,ps.start_time,ps.end_time,ps.sale_num,sku.sku_name,sku.sku_spec_format,sku.price,sku.sku_image,sku.sku_images,sku.goods_spec_format,g.goods_image,ps.goods_stock';
+ $join = [
+ [ 'goods_sku sku', 'psg.sku_id = sku.sku_id', 'inner' ],
+ [ 'goods g', 'g.goods_id = sku.goods_id', 'inner' ],
+ [ 'promotion_seckill ps', 'ps.id = psg.seckill_id', 'inner' ],
+ ];
+ $list = model('promotion_seckill_goods')->getList($condition, $field, 'psg.id asc', 'psg', $join);
+ foreach ($list as $k => $v) {
+ $list[ $k ][ 'goods_stock' ] = numberFormat($list[ $k ][ 'goods_stock' ]);
+ }
+ return $this->success($list);
+ }
+
+ /**
+ * 判断规格值是否禁用
+ * @param $seckill_id
+ * @param $site_id
+ * @param string $goods_spec_format
+ * @return int|mixed
+ */
+ public function getGoodsSpecFormat($seckill_id, $site_id, $goods_spec_format = '')
+ {
+ //获取活动参与的商品sku_ids
+ $sku_ids = model('promotion_seckill_goods')->getColumn([ [ 'seckill_id', '=', $seckill_id ], [ 'site_id', '=', $site_id ] ], 'sku_id');
+ $goods_model = new Goods();
+ $res = $goods_model->getGoodsSpecFormat($sku_ids, $goods_spec_format);
+ return $res;
+ }
+
+ /**
+ * 生成砍价二维码
+ * @param $seckill_id
+ * @param string $name
+ * @param string $type 类型 create创建 get获取
+ * @return mixed|array
+ */
+ public function qrcode($seckill_id, $name, $site_id, $type = 'create')
+ {
+ $data = [
+ 'site_id' => $site_id,
+ 'app_type' => "all", // all为全部
+ 'type' => $type, // 类型 create创建 get获取
+ 'data' => [
+ "seckill_id" => $seckill_id
+ ],
+ 'page' => '/pages_promotion/seckill/detail',
+ 'qrcode_path' => 'upload/qrcode/seckill',
+ 'qrcode_name' => "seckill_qrcode_" . $seckill_id
+ ];
+
+ event('Qrcode', $data, true);
+ $app_type_list = config('app_type');
+ $path = [];
+ foreach ($app_type_list as $k => $v) {
+ switch ( $k ) {
+ case 'h5':
+ $wap_domain = getH5Domain();
+ $path[ $k ][ 'status' ] = 1;
+ $path[ $k ][ 'url' ] = $wap_domain . $data[ 'page' ] . '?id=' . $seckill_id;
+ $path[ $k ][ 'img' ] = "upload/qrcode/seckill/seckill_qrcode_" . $seckill_id . "_" . $k . ".png";
+ break;
+ case 'weapp' :
+ $config = new ConfigModel();
+ $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'WEAPP_CONFIG' ] ]);
+ if (!empty($res[ 'data' ])) {
+ if (empty($res[ 'data' ][ 'value' ][ 'qrcode' ])) {
+ $path[ $k ][ 'status' ] = 2;
+ $path[ $k ][ 'message' ] = '未配置微信小程序';
+ } else {
+ $path[ $k ][ 'status' ] = 1;
+ $path[ $k ][ 'img' ] = $res[ 'data' ][ 'value' ][ 'qrcode' ];
+ }
+
+ } else {
+ $path[ $k ][ 'status' ] = 2;
+ $path[ $k ][ 'message' ] = '未配置微信小程序';
+ }
+ break;
+
+ case 'wechat' :
+ $config = new ConfigModel();
+ $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'WECHAT_CONFIG' ] ]);
+ if (!empty($res[ 'data' ])) {
+ if (empty($res[ 'data' ][ 'value' ][ 'qrcode' ])) {
+ $path[ $k ][ 'status' ] = 2;
+ $path[ $k ][ 'message' ] = '未配置微信公众号';
+ } else {
+ $path[ $k ][ 'status' ] = 1;
+ $path[ $k ][ 'img' ] = $res[ 'data' ][ 'value' ][ 'qrcode' ];
+ }
+ } else {
+ $path[ $k ][ 'status' ] = 2;
+ $path[ $k ][ 'message' ] = '未配置微信公众号';
+ }
+ break;
+ }
+
+ }
+
+ $return = [
+ 'path' => $path,
+ 'name' => $name,
+ ];
+
+ return $this->success($return);
+ }
+
+ public function urlQrcode($page, $qrcode_param, $promotion_type, $app_type, $site_id)
+ {
+ $params = [
+ 'site_id' => $site_id,
+ 'data' => $qrcode_param,
+ 'page' => $page,
+ 'promotion_type' => $promotion_type,
+ 'app_type' => $app_type,
+ 'h5_path' => $page . '?id=' . $qrcode_param[ 'id' ],
+ 'qrcode_path' => 'upload/qrcode/seckill',
+ 'qrcode_name' => 'seckill_qrcode_' . $promotion_type . '_' . $qrcode_param[ 'id' ] . '_' . $site_id,
+ ];
+ $solitaire = event('PromotionQrcode', $params, true);
+ return $this->success($solitaire);
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/seckill/model/SeckillOrder.php b/src/addon/seckill/model/SeckillOrder.php
index 53f14acaf..56d0ba6cf 100644
--- a/src/addon/seckill/model/SeckillOrder.php
+++ b/src/addon/seckill/model/SeckillOrder.php
@@ -1,75 +1,67 @@
-getInfo([['order_id', '=', $order_id], ['promotion_type', '=', 'seckill'], ['order_status', '=', -1]], 'promotion_id');
- if (!empty($order_info)) {
- $condition = array(
- ["order_id", "=", $order_id]
- );
- $order_goods_list = model('order_goods')->getList($condition, "order_goods_id,sku_id,num,refund_status,use_point");
- foreach ($order_goods_list as $k => $v) {
- // 返还库存
- model("promotion_seckill")->setInc([['id', '=', $order_info["promotion_id"]]], "goods_stock", $v["num"]);
- model("promotion_seckill_goods")->setInc([["sku_id", '=', $v["sku_id"]], ["seckill_id", '=', $order_info["promotion_id"]]], "stock", $v["num"]);
- // 减少销量
- model("promotion_seckill")->setDec([['id', '=', $order_info["promotion_id"]]], "sale_num", $v["num"]);
- }
- }
- return $this->success();
- }
-
-
- /**
- * 获取商品已秒杀数
- * @param $goods_id
- * @param $member_id
- * @return float
- */
- public function getGoodsSeckillNum($seckill_id)
- {
- $join = [
- ['order o', 'o.order_id = og.order_id', 'left']
- ];
- $num = model('order_goods')->getSum([
- ['o.order_status', '<>', Order::ORDER_CLOSE],
- ['o.promotion_type', '=', 'seckill'],
- ['o.promotion_id', '=', $seckill_id],
- ['og.refund_status', '<>', OrderRefundDict::REFUND_COMPLETE],
- ], 'og.num', 'og', $join);
- return $num;
- }
+getInfo([['order_id', '=', $order_id], ['promotion_type', '=', 'seckill'], ['order_status', '=', -1]], 'promotion_id');
+ if (!empty($order_info)) {
+ $condition = array(
+ ["order_id", "=", $order_id]
+ );
+ $order_goods_list = model('order_goods')->getList($condition, "order_goods_id,sku_id,num,refund_status,use_point");
+ foreach ($order_goods_list as $k => $v) {
+ // 返还库存
+ model("promotion_seckill")->setInc([['id', '=', $order_info["promotion_id"]]], "goods_stock", $v["num"]);
+ model("promotion_seckill_goods")->setInc([["sku_id", '=', $v["sku_id"]], ["seckill_id", '=', $order_info["promotion_id"]]], "stock", $v["num"]);
+ // 减少销量
+ model("promotion_seckill")->setDec([['id', '=', $order_info["promotion_id"]]], "sale_num", $v["num"]);
+ }
+ }
+ return $this->success();
+ }
+
+
+ /**
+ * 获取商品已秒杀数
+ * @param $goods_id
+ * @param $member_id
+ * @return float
+ */
+ public function getGoodsSeckillNum($seckill_id)
+ {
+ $join = [
+ ['order o', 'o.order_id = og.order_id', 'left']
+ ];
+ $num = model('order_goods')->getSum([
+ ['o.order_status', '<>', Order::ORDER_CLOSE],
+ ['o.promotion_type', '=', 'seckill'],
+ ['o.promotion_id', '=', $seckill_id],
+ ['og.refund_status', '<>', OrderRefundDict::REFUND_COMPLETE],
+ ], 'og.num', 'og', $join);
+ return $num;
+ }
}
\ No newline at end of file
diff --git a/src/addon/seckill/model/SeckillOrderCreate.php b/src/addon/seckill/model/SeckillOrderCreate.php
index 9363e49e2..00c7f063b 100644
--- a/src/addon/seckill/model/SeckillOrderCreate.php
+++ b/src/addon/seckill/model/SeckillOrderCreate.php
@@ -1,310 +1,302 @@
-promotion_type = 'seckill';
- $this->promotion_type_name = '秒杀';
- }
- /**
- * 订单创建
- */
- public function create()
- {
- //计算
- $this->confirm();
- if ($this->error > 0) {
- return $this->error(['error_code' => $this->error], $this->error_msg);
- }
- //订单创建数据
- $order_insert_data = $this->getOrderInsertData(['discount'], 'invert');
- $order_insert_data['store_id'] = $this->store_id;
- $order_insert_data['create_time'] = time();
- $order_insert_data['is_enable_refund'] = 0;
- //订单类型以及状态
- $this->orderType();
- $order_insert_data['order_type'] = $this->order_type['order_type_id'];
- $order_insert_data['order_type_name'] = $this->order_type['order_type_name'];
- $order_insert_data['order_status_name'] = $this->order_type['order_status']['name'];
- $order_insert_data['order_status_action'] = json_encode($this->order_type['order_status'], JSON_UNESCAPED_UNICODE);
-
- model('order')->startTrans();
- //循环生成多个订单
- try {
- $this->order_id = model('order')->add($order_insert_data);
- $order_goods_insert_data = [];
- //订单项目表
- foreach ($this->goods_list as &$order_goods_v) {
- $order_goods_insert_data[] = $this->getOrderGoodsInsertData($order_goods_v);
-
- model("promotion_seckill_goods")->setDec([['sku_id', '=', $order_goods_v['sku_id']], ['seckill_id', '=', $this->seckill_info["id"]]], "stock", $order_goods_v['num']);
- model("promotion_seckill")->setDec([['id', '=', $this->seckill_info["id"]]], "goods_stock", $order_goods_v['num']);
- // 增加销量
- model("promotion_seckill")->setInc([['id', '=', $this->seckill_info["id"]]], "sale_num", $order_goods_v['num']);
- }
- model('order_goods')->addList($order_goods_insert_data);
-
- //扣除余额(统一扣除)
- $this->useBalance();
- //批量库存处理(卡密商品支付后在扣出库存)
- $this->batchDecOrderGoodssStock();
- model('order')->commit();
- //订单创建后事件
- $this->orderCreateAfter();
- //支付单据
- $pay = new Pay();
- $pay->addPay($this->site_id, $this->out_trade_no, $this->pay_type, $this->order_name, $this->order_name, $this->pay_money, '', 'OrderPayNotify', '');
- return $this->success($this->out_trade_no);
- } catch ( \Exception $e ) {
- model('order')->rollback();
- return $this->error('', $e->getMessage());
- }
-
- }
-
-
- /**
- * 计算后的进一步计算(不存缓存,每次都是重新计算)
- * @return array
- */
- public function confirm()
- {
- $order_key = $this->param['order_key'];
- $this->getOrderCache($order_key);
- //初始化地址
- $this->initMemberAddress();
- //初始化门店信息
- $this->initStore();
- //配送计算
- $this->calculateDelivery();
- //批量校验配送方式
- $this->batchCheckDeliveryType();
- //计算发票相关
- $this->calculateInvoice();
- //计算余额
- $this->calculateBalcnce();
- $this->pay_money = $this->order_money - $this->balance_money;
- //设置过的商品项信息
- return get_object_vars($this);
- }
-
- /**
- * 订单计算
- */
- public function calculate()
- {
- //初始化会员地址
- $this->initMemberAddress();
- $this->initMemberAccount();//初始化会员账户
- //商品列表信息
- $this->getOrderGoodsCalculate();
- //查询秒杀信息
- $seckill_model = new Seckill();
- $seckill_info = $seckill_model->getSeckillInfo($this->seckill_id)['data'] ?? [];
- if (empty($seckill_info)) throw new OrderException("找不到可用的秒杀活动");
- $this->seckill_info = $seckill_info;
- //判断秒杀时间段是否符合
- $today_time = strtotime(date("Y-m-d"), time());
- $time = time() - $today_time;//当日时间戳
- if ($time < $this->seckill_info["seckill_start_time"] || $time > $this->seckill_info["seckill_end_time"]) {
- $this->error = 1;
- $this->error_msg = "当前商品秒杀活动未开启或已过期!";
- }
-
- //秒杀库存
- if ($this->goods_list[0]) {
- $seckill_goods = $seckill_model->getSeckillGoodsInfo([['psg.seckill_id', '=', $this->seckill_id], ['psg.sku_id', '=', $this->goods_list[0]['sku_id']]], 'psg.stock')['data'] ?? [];
- $seckill_goods_stock = $seckill_goods['stock'];
- if ($this->goods_list[0]['num'] > $seckill_goods_stock) {
- $this->error = 1;
- $this->error_msg = "该商品库存不足";
- }
- }
-
- // 秒杀商品限购 按每日某时段限购
- if ($this->goods_list[0]['limit_num'] > 0) {
- $purchased_num = $this->getGoodsPurchasedNum($this->goods_list[0]['sku_id'], $this->member_id, $this->seckill_info['id']);
- if (($purchased_num + $this->goods_list[0]['num']) > $this->goods_list[0]['limit_num']) {
- $this->error = 1;
- $this->error_msg = "该商品每人限购{$this->goods_list[ 0 ]['limit_num']}件,您已购买{$purchased_num}件";
- }
- }
- $this->shopOrderCalculate();
- //获取发票相关
- $this->getInovice();
- $this->order_key = create_no();
- $this->setOrderCache(get_object_vars($this), $this->order_key);
- return true;
- }
-
- /**
- * 待付款订单
- * @param unknown $data
- */
- public function orderPayment()
- {
- //计算
- $this->calculate();
- //查询配送信息
- $this->getDeliveryData();
- //订单初始项
- event('OrderPayment', ['order_object' => $this]);
- return get_object_vars($this);
- }
-
- /**
- * 获取商品的计算信息
- * @param unknown $data
- */
- public function getOrderGoodsCalculate()
- {
- $this->getSeckillGoodsInfo();
- return true;
- }
-
- /**
- * 获取秒杀商品列表信息
- * @param $id
- * @param $num
- * @param $data
- * @return array
- */
- public function getSeckillGoodsInfo()
- {
- $id = $this->param['id'];
- $sku_id = $this->param['sku_id'];
- $num = $this->param['num'];
- //组装商品列表
- $field = 'npsg.sku_id,npsg.seckill_id,npsg.seckill_price,npsg.max_buy as limit_num,ngs.sku_name, ngs.sku_no,
- ngs.price, ngs.discount_price, ngs.cost_price, ngs.stock, ngs.weight, ngs.volume, ngs.sku_image,
- ngs.site_id, ns.site_name, ngs.goods_state, ngs.is_virtual,ngs.supplier_id,
- ngs.is_free_shipping, ngs.shipping_template, ngs.goods_class, ngs.goods_class_name,ngs.goods_id,ngs.sku_spec_format,ngs.goods_name,ngs.support_trade_type';
- $alias = 'npsg';
- $join = [
- [
- 'goods_sku ngs',
- 'npsg.sku_id = ngs.sku_id',
- 'inner'
- ],
- [
- 'site ns',
- 'ngs.site_id = ns.site_id',
- 'inner'
- ]
- ];
-
- $condition = [
- ['npsg.sku_id', '=', $sku_id],
- ['npsg.seckill_id', '=', $id],
- ['npsg.site_id', '=', $this->site_id]
- ];
- $info = model("promotion_seckill_goods")->getInfo($condition, $field, $alias, $join);
- if (empty($info)) throw new OrderException('无效的商品!');
- //判断是否是虚拟订单
- $this->seckill_id = $info['seckill_id'];
- if ($info['is_virtual']) {
- $this->is_virtual = 1;
- } else {
- $this->is_virtual = 0;
- }
- $info["num"] = $num;
- $price = $info["seckill_price"];//订单项商品单价
- $goods_money = $price * $info['num'];
- $info["price"] = $price;
- $info['goods_money'] = $goods_money;//订单项商品总价
- $info['real_goods_money'] = $goods_money;//真实商品金额
- $info['coupon_money'] = 0;//优惠券金额
- $info['promotion_money'] = 0;//优惠金额
-
- $this->site_name = $info['site_name'];
- $this->goods_money = $goods_money;
- $this->goods_list_str = $info['sku_id'] . ':' . $info['num'];
- $this->order_name = string_split("", ",", $info['sku_name']);
- $this->goods_num = $info['num'];
- $this->goods_list[] = $info;
- return true;
- }
-
- /**
- * 获取店铺订单计算
- */
- public function shopOrderCalculate()
- {
- //重新计算订单总额
- $this->getOrderMoney();
- //理论上是多余的操作
- if ($this->order_money < 0) {
- $this->order_money = 0;
- }
- //总结计算
- $this->pay_money = $this->order_money;
-
- return true;
- }
-
-
-
- /**
- * 获取会员该秒杀时段已购该商品数
- * @param $goods_id
- * @param $member_id
- * @return float
- */
- public function getGoodsPurchasedNum($sku_id, $member_id, $seckill_id)
- {
- $join = [
- ['order o', 'o.order_id = og.order_id', 'left']
- ];
- $num = model('order_goods')->getSum([
- ['og.member_id', '=', $member_id],
- ['og.sku_id', '=', $sku_id],
- ['o.order_status', '<>', Order::ORDER_CLOSE],
- ['o.promotion_type', '=', 'seckill'],
- ['o.promotion_id', '=', $seckill_id],
- ['og.refund_status', '<>', OrderRefundDict::REFUND_COMPLETE],
- ['o.create_time', 'between', [date_to_time(date('Y-m-d 00:00:00')), time()]]
- ], 'og.num', 'og', $join);
- return $num;
- }
-
-
-
+promotion_type = 'seckill';
+ $this->promotion_type_name = '秒杀';
+ }
+ /**
+ * 订单创建
+ */
+ public function create()
+ {
+ //计算
+ $this->confirm();
+ if ($this->error > 0) {
+ return $this->error(['error_code' => $this->error], $this->error_msg);
+ }
+ //订单创建数据
+ $order_insert_data = $this->getOrderInsertData(['discount'], 'invert');
+ $order_insert_data['store_id'] = $this->store_id;
+ $order_insert_data['create_time'] = time();
+ $order_insert_data['is_enable_refund'] = 0;
+ //订单类型以及状态
+ $this->orderType();
+ $order_insert_data['order_type'] = $this->order_type['order_type_id'];
+ $order_insert_data['order_type_name'] = $this->order_type['order_type_name'];
+ $order_insert_data['order_status_name'] = $this->order_type['order_status']['name'];
+ $order_insert_data['order_status_action'] = json_encode($this->order_type['order_status'], JSON_UNESCAPED_UNICODE);
+
+ model('order')->startTrans();
+ //循环生成多个订单
+ try {
+ $this->order_id = model('order')->add($order_insert_data);
+ $order_goods_insert_data = [];
+ //订单项目表
+ foreach ($this->goods_list as &$order_goods_v) {
+ $order_goods_insert_data[] = $this->getOrderGoodsInsertData($order_goods_v);
+
+ model("promotion_seckill_goods")->setDec([['sku_id', '=', $order_goods_v['sku_id']], ['seckill_id', '=', $this->seckill_info["id"]]], "stock", $order_goods_v['num']);
+ model("promotion_seckill")->setDec([['id', '=', $this->seckill_info["id"]]], "goods_stock", $order_goods_v['num']);
+ // 增加销量
+ model("promotion_seckill")->setInc([['id', '=', $this->seckill_info["id"]]], "sale_num", $order_goods_v['num']);
+ }
+ model('order_goods')->addList($order_goods_insert_data);
+
+ //扣除余额(统一扣除)
+ $this->useBalance();
+ //批量库存处理(卡密商品支付后在扣出库存)
+ $this->batchDecOrderGoodssStock();
+ model('order')->commit();
+ //订单创建后事件
+ $this->orderCreateAfter();
+ //支付单据
+ $pay = new Pay();
+ $pay->addPay($this->site_id, $this->out_trade_no, $this->pay_type, $this->order_name, $this->order_name, $this->pay_money, '', 'OrderPayNotify', '');
+ return $this->success($this->out_trade_no);
+ } catch ( \Exception $e ) {
+ model('order')->rollback();
+ return $this->error('', $e->getMessage());
+ }
+
+ }
+
+
+ /**
+ * 计算后的进一步计算(不存缓存,每次都是重新计算)
+ * @return array
+ */
+ public function confirm()
+ {
+ $order_key = $this->param['order_key'];
+ $this->getOrderCache($order_key);
+ //初始化地址
+ $this->initMemberAddress();
+ //初始化门店信息
+ $this->initStore();
+ //配送计算
+ $this->calculateDelivery();
+ //批量校验配送方式
+ $this->batchCheckDeliveryType();
+ //计算发票相关
+ $this->calculateInvoice();
+ //计算余额
+ $this->calculateBalcnce();
+ $this->pay_money = $this->order_money - $this->balance_money;
+ //设置过的商品项信息
+ return get_object_vars($this);
+ }
+
+ /**
+ * 订单计算
+ */
+ public function calculate()
+ {
+ //初始化会员地址
+ $this->initMemberAddress();
+ $this->initMemberAccount();//初始化会员账户
+ //商品列表信息
+ $this->getOrderGoodsCalculate();
+ //查询秒杀信息
+ $seckill_model = new Seckill();
+ $seckill_info = $seckill_model->getSeckillInfo($this->seckill_id)['data'] ?? [];
+ if (empty($seckill_info)) throw new OrderException("找不到可用的秒杀活动");
+ $this->seckill_info = $seckill_info;
+ //判断秒杀时间段是否符合
+ $today_time = strtotime(date("Y-m-d"), time());
+ $time = time() - $today_time;//当日时间戳
+ if ($time < $this->seckill_info["seckill_start_time"] || $time > $this->seckill_info["seckill_end_time"]) {
+ $this->error = 1;
+ $this->error_msg = "当前商品秒杀活动未开启或已过期!";
+ }
+
+ //秒杀库存
+ if ($this->goods_list[0]) {
+ $seckill_goods = $seckill_model->getSeckillGoodsInfo([['psg.seckill_id', '=', $this->seckill_id], ['psg.sku_id', '=', $this->goods_list[0]['sku_id']]], 'psg.stock')['data'] ?? [];
+ $seckill_goods_stock = $seckill_goods['stock'];
+ if ($this->goods_list[0]['num'] > $seckill_goods_stock) {
+ $this->error = 1;
+ $this->error_msg = "该商品库存不足";
+ }
+ }
+
+ // 秒杀商品限购 按每日某时段限购
+ if ($this->goods_list[0]['limit_num'] > 0) {
+ $purchased_num = $this->getGoodsPurchasedNum($this->goods_list[0]['sku_id'], $this->member_id, $this->seckill_info['id']);
+ if (($purchased_num + $this->goods_list[0]['num']) > $this->goods_list[0]['limit_num']) {
+ $this->error = 1;
+ $this->error_msg = "该商品每人限购{$this->goods_list[ 0 ]['limit_num']}件,您已购买{$purchased_num}件";
+ }
+ }
+ $this->shopOrderCalculate();
+ //获取发票相关
+ $this->getInovice();
+ $this->order_key = create_no();
+ $this->setOrderCache(get_object_vars($this), $this->order_key);
+ return true;
+ }
+
+ /**
+ * 待付款订单
+ * @param unknown $data
+ */
+ public function orderPayment()
+ {
+ //计算
+ $this->calculate();
+ //查询配送信息
+ $this->getDeliveryData();
+ //订单初始项
+ event('OrderPayment', ['order_object' => $this]);
+ return get_object_vars($this);
+ }
+
+ /**
+ * 获取商品的计算信息
+ * @param unknown $data
+ */
+ public function getOrderGoodsCalculate()
+ {
+ $this->getSeckillGoodsInfo();
+ return true;
+ }
+
+ /**
+ * 获取秒杀商品列表信息
+ * @param $id
+ * @param $num
+ * @param $data
+ * @return array
+ */
+ public function getSeckillGoodsInfo()
+ {
+ $id = $this->param['id'];
+ $sku_id = $this->param['sku_id'];
+ $num = $this->param['num'];
+ //组装商品列表
+ $field = 'npsg.sku_id,npsg.seckill_id,npsg.seckill_price,npsg.max_buy as limit_num,ngs.sku_name, ngs.sku_no,
+ ngs.price, ngs.discount_price, ngs.cost_price, ngs.stock, ngs.weight, ngs.volume, ngs.sku_image,
+ ngs.site_id, ns.site_name, ngs.goods_state, ngs.is_virtual,ngs.supplier_id,
+ ngs.is_free_shipping, ngs.shipping_template, ngs.goods_class, ngs.goods_class_name,ngs.goods_id,ngs.sku_spec_format,ngs.goods_name,ngs.support_trade_type';
+ $alias = 'npsg';
+ $join = [
+ [
+ 'goods_sku ngs',
+ 'npsg.sku_id = ngs.sku_id',
+ 'inner'
+ ],
+ [
+ 'site ns',
+ 'ngs.site_id = ns.site_id',
+ 'inner'
+ ]
+ ];
+
+ $condition = [
+ ['npsg.sku_id', '=', $sku_id],
+ ['npsg.seckill_id', '=', $id],
+ ['npsg.site_id', '=', $this->site_id]
+ ];
+ $info = model("promotion_seckill_goods")->getInfo($condition, $field, $alias, $join);
+ if (empty($info)) throw new OrderException('无效的商品!');
+ //判断是否是虚拟订单
+ $this->seckill_id = $info['seckill_id'];
+ if ($info['is_virtual']) {
+ $this->is_virtual = 1;
+ } else {
+ $this->is_virtual = 0;
+ }
+ $info["num"] = $num;
+ $price = $info["seckill_price"];//订单项商品单价
+ $goods_money = $price * $info['num'];
+ $info["price"] = $price;
+ $info['goods_money'] = $goods_money;//订单项商品总价
+ $info['real_goods_money'] = $goods_money;//真实商品金额
+ $info['coupon_money'] = 0;//优惠券金额
+ $info['promotion_money'] = 0;//优惠金额
+
+ $this->site_name = $info['site_name'];
+ $this->goods_money = $goods_money;
+ $this->goods_list_str = $info['sku_id'] . ':' . $info['num'];
+ $this->order_name = string_split("", ",", $info['sku_name']);
+ $this->goods_num = $info['num'];
+ $this->goods_list[] = $info;
+ return true;
+ }
+
+ /**
+ * 获取店铺订单计算
+ */
+ public function shopOrderCalculate()
+ {
+ //重新计算订单总额
+ $this->getOrderMoney();
+ //理论上是多余的操作
+ if ($this->order_money < 0) {
+ $this->order_money = 0;
+ }
+ //总结计算
+ $this->pay_money = $this->order_money;
+
+ return true;
+ }
+
+
+
+ /**
+ * 获取会员该秒杀时段已购该商品数
+ * @param $goods_id
+ * @param $member_id
+ * @return float
+ */
+ public function getGoodsPurchasedNum($sku_id, $member_id, $seckill_id)
+ {
+ $join = [
+ ['order o', 'o.order_id = og.order_id', 'left']
+ ];
+ $num = model('order_goods')->getSum([
+ ['og.member_id', '=', $member_id],
+ ['og.sku_id', '=', $sku_id],
+ ['o.order_status', '<>', Order::ORDER_CLOSE],
+ ['o.promotion_type', '=', 'seckill'],
+ ['o.promotion_id', '=', $seckill_id],
+ ['og.refund_status', '<>', OrderRefundDict::REFUND_COMPLETE],
+ ['o.create_time', 'between', [date_to_time(date('Y-m-d 00:00:00')), time()]]
+ ], 'og.num', 'og', $join);
+ return $num;
+ }
+
+
+
}
\ No newline at end of file
diff --git a/src/addon/seckill/model/share/WchatShare.php b/src/addon/seckill/model/share/WchatShare.php
index 441ed31f2..2940cfe0f 100644
--- a/src/addon/seckill/model/share/WchatShare.php
+++ b/src/addon/seckill/model/share/WchatShare.php
@@ -1,141 +1,132 @@
- '秒杀分享',
- 'config_key' => 'WCHAT_SHARE_CONFIG_SECKILL_PROMOTE',
- 'path' => [ '/pages_promotion/seckill/detail' ],
- 'method_prefix' => 'goodsDetail',
- ],
- [
- 'title' => '秒杀列表',
- 'config_key' => 'WCHAT_SHARE_CONFIG_SECKILL_LIST_PROMOTE',
- 'path' => [ '/pages_promotion/seckill/list' ],
- 'method_prefix' => 'goodsList',
- ],
- ];
-
- protected $sort = 8;
-
- /**
- * 秒杀列表
- * @param $param
- * @return array
- */
- protected function goodsListShareData($param)
- {
- //跳转路径
- $link = $this->getShareLink($param);
- $config_data = $this->goodsListShareConfig($param)[ 'value' ];
-
- $data = [
- 'link' => $link,
- 'desc' => $config_data[ 'desc' ],
- 'imgUrl' => $config_data[ 'imgUrl' ],
- 'title' => $config_data[ 'title' ]
- ];
- return [
- 'permission' => [
- 'hideOptionMenu' => false,
- 'hideMenuItems' => [],
- ],
- 'data' => $data,//分享内容
- ];
- }
-
- /**
- * 秒杀列表分享配置
- * @param $param
- * @return array
- */
- public function goodsListShareConfig($param)
- {
- $site_id = $param[ 'site_id' ];
- $config = $param[ 'config' ];
-
- $config_model = new ConfigModel();
- $data = $config_model->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', $config[ 'config_key' ] ] ])[ 'data' ];
- if (empty($data[ 'value' ])) {
- $data[ 'value' ] = [
- 'title' => "秒杀列表",
- 'desc' => "秒杀进行时\n快来参与吧",
- 'imgUrl' => ''
- ];
- }
- if (empty($data[ 'value' ][ 'imgUrl' ])) {
- $data[ 'value' ][ 'imgUrl' ] = img('addon/seckill/icon.png');
- }
- return [
- 'value' => $data[ 'value' ],
- ];
- }
-
- /**
- * 秒杀分享数据
- * @param $param
- * @return array
- */
- protected function goodsDetailShareData($param)
- {
- $url = $param[ 'url' ];
-
- $parse_res = parse_url($url);
- parse_str($parse_res[ 'query' ] ?? '', $query);
-
- if (isset($query[ 'seckill_id' ]) || $query[ 'id' ]) {
- $seckill_id = $query['seckill_id'] ?? $query['id'];
- $goods = new Seckill();
- $condition = [
- [ 'ps.id', '=', $seckill_id ],
- [ 'psg.site_id', '=', 1 ],
- [ 'psg.status', '=', 1 ],
- [ 'ps.status', '=', 1 ],
- [ 'g.is_delete', '=', 0 ]
- ];
- $sku_info = $goods->getSeckillGoodsInfo($condition)[ 'data' ];
- if (!empty($sku_info)) {
- $config_model = new \app\model\share\WchatShare();
- $config_data = $config_model->goodsDetailShareConfig($param);
-
- $title = str_replace('{goods_name}', $sku_info[ 'sku_name' ], $config_data[ 'value' ][ 'title' ]);
- $desc = str_replace('{price}', $sku_info[ 'seckill_price' ], $config_data[ 'value' ][ 'desc' ]);
- $link = $this->getShareLink($param);
- $image_url = $sku_info[ 'sku_image' ];
-
- $data = [
- 'title' => $title,
- 'desc' => $desc,
- 'link' => $link,
- 'imgUrl' => $image_url,
- ];
- return [
- 'permission' => [
- 'hideOptionMenu' => false,
- 'hideMenuItems' => [],
- ],
- 'data' => $data,//分享内容
- ];
- }
- }
- }
-}
+ '秒杀分享',
+ 'config_key' => 'WCHAT_SHARE_CONFIG_SECKILL_PROMOTE',
+ 'path' => [ '/pages_promotion/seckill/detail' ],
+ 'method_prefix' => 'goodsDetail',
+ ],
+ [
+ 'title' => '秒杀列表',
+ 'config_key' => 'WCHAT_SHARE_CONFIG_SECKILL_LIST_PROMOTE',
+ 'path' => [ '/pages_promotion/seckill/list' ],
+ 'method_prefix' => 'goodsList',
+ ],
+ ];
+
+ protected $sort = 8;
+
+ /**
+ * 秒杀列表
+ * @param $param
+ * @return array
+ */
+ protected function goodsListShareData($param)
+ {
+ //跳转路径
+ $link = $this->getShareLink($param);
+ $config_data = $this->goodsListShareConfig($param)[ 'value' ];
+
+ $data = [
+ 'link' => $link,
+ 'desc' => $config_data[ 'desc' ],
+ 'imgUrl' => $config_data[ 'imgUrl' ],
+ 'title' => $config_data[ 'title' ]
+ ];
+ return [
+ 'permission' => [
+ 'hideOptionMenu' => false,
+ 'hideMenuItems' => [],
+ ],
+ 'data' => $data,//分享内容
+ ];
+ }
+
+ /**
+ * 秒杀列表分享配置
+ * @param $param
+ * @return array
+ */
+ public function goodsListShareConfig($param)
+ {
+ $site_id = $param[ 'site_id' ];
+ $config = $param[ 'config' ];
+
+ $config_model = new ConfigModel();
+ $data = $config_model->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', $config[ 'config_key' ] ] ])[ 'data' ];
+ if (empty($data[ 'value' ])) {
+ $data[ 'value' ] = [
+ 'title' => "秒杀列表",
+ 'desc' => "秒杀进行时\n快来参与吧",
+ 'imgUrl' => ''
+ ];
+ }
+ if (empty($data[ 'value' ][ 'imgUrl' ])) {
+ $data[ 'value' ][ 'imgUrl' ] = img('addon/seckill/icon.png');
+ }
+ return [
+ 'value' => $data[ 'value' ],
+ ];
+ }
+
+ /**
+ * 秒杀分享数据
+ * @param $param
+ * @return array
+ */
+ protected function goodsDetailShareData($param)
+ {
+ $url = $param[ 'url' ];
+
+ $parse_res = parse_url($url);
+ parse_str($parse_res[ 'query' ] ?? '', $query);
+
+ if (isset($query[ 'seckill_id' ]) || $query[ 'id' ]) {
+ $seckill_id = $query['seckill_id'] ?? $query['id'];
+ $goods = new Seckill();
+ $condition = [
+ [ 'ps.id', '=', $seckill_id ],
+ [ 'psg.site_id', '=', 1 ],
+ [ 'psg.status', '=', 1 ],
+ [ 'ps.status', '=', 1 ],
+ [ 'g.is_delete', '=', 0 ]
+ ];
+ $sku_info = $goods->getSeckillGoodsInfo($condition)[ 'data' ];
+ if (!empty($sku_info)) {
+ $config_model = new \app\model\share\WchatShare();
+ $config_data = $config_model->goodsDetailShareConfig($param);
+
+ $title = str_replace('{goods_name}', $sku_info[ 'sku_name' ], $config_data[ 'value' ][ 'title' ]);
+ $desc = str_replace('{price}', $sku_info[ 'seckill_price' ], $config_data[ 'value' ][ 'desc' ]);
+ $link = $this->getShareLink($param);
+ $image_url = $sku_info[ 'sku_image' ];
+
+ $data = [
+ 'title' => $title,
+ 'desc' => $desc,
+ 'link' => $link,
+ 'imgUrl' => $image_url,
+ ];
+ return [
+ 'permission' => [
+ 'hideOptionMenu' => false,
+ 'hideMenuItems' => [],
+ ],
+ 'data' => $data,//分享内容
+ ];
+ }
+ }
+ }
+}
diff --git a/src/addon/seckill/shop/controller/Seckill.php b/src/addon/seckill/shop/controller/Seckill.php
index 79056adfc..8aeb39225 100644
--- a/src/addon/seckill/shop/controller/Seckill.php
+++ b/src/addon/seckill/shop/controller/Seckill.php
@@ -1,394 +1,386 @@
-replace = [
- 'SECKILL_CSS' => __ROOT__ . '/addon/seckill/shop/view/public/css',
- 'SECKILL_JS' => __ROOT__ . '/addon/seckill/shop/view/public/js',
- 'SECKILL_IMG' => __ROOT__ . '/addon/seckill/shop/view/public/img',
- ];
- parent::__construct($app);
- }
-
- /**
- * 秒杀时间段列表
- */
- public function lists()
- {
- if (request()->isJson()) {
- $condition[] = [ 'site_id', '=', $this->site_id ];
- $order = 'seckill_start_time asc';
- $field = '*';
-
- $seckill_model = new SeckillModel();
- $res = $seckill_model->getSeckillTimeList($condition, $field, $order, null);
- foreach ($res[ 'data' ] as $key => $val) {
- $val = $seckill_model->transformSeckillTime($val);
- $res[ 'data' ][ $key ][ 'seckill_start_time_show' ] = "{$val['start_hour']}:{$val['start_minute']}:{$val['start_second']}";
- $res[ 'data' ][ $key ][ 'seckill_end_time_show' ] = "{$val['end_hour']}:{$val['end_minute']}:{$val['end_second']}";
- }
- return $res;
- } else {
-
- return $this->fetch("seckill/lists");
- }
- }
-
- /**
- * 添加秒杀时间段
- */
- public function add()
- {
- if (request()->isJson()) {
- $start_hour = input('start_hour', 0);
- $start_minute = input('start_minute', 0);
- $start_second = input('start_second', 0);
-
- $end_hour = input('end_hour', 0);
- $end_minute = input('end_minute', 0);
- $end_second = input('end_second', 0);
-
- $data = [
- 'site_id' => $this->site_id,
- 'name' => input('name', ''),
- 'seckill_start_time' => $start_hour * 3600 + $start_minute * 60 + $start_second,
- 'seckill_end_time' => $end_hour * 3600 + $end_minute * 60 + $end_second,
- 'create_time' => time(),
- ];
- $seckill_model = new SeckillModel();
- return $seckill_model->addSeckillTime($data);
- } else {
- return $this->fetch("seckill/add");
- }
- }
-
- /**
- * 编辑秒杀时间段
- */
- public function edit()
- {
- $seckill_model = new SeckillModel();
- if (request()->isJson()) {
- $start_hour = input('start_hour', 0);
- $start_minute = input('start_minute', 0);
- $start_second = input('start_second', 0);
-
- $end_hour = input('end_hour', 0);
- $end_minute = input('end_minute', 0);
- $end_second = input('end_second', 0);
-
- $data = [
- 'name' => input('name', ''),
- 'seckill_start_time' => $start_hour * 3600 + $start_minute * 60 + $start_second,
- 'seckill_end_time' => $end_hour * 3600 + $end_minute * 60 + $end_second,
- 'create_time' => time(),
- 'id' => input('id', 0),
- ];
- return $seckill_model->editSeckillTime($data, $this->site_id);
- } else {
- $id = input('id', 0);
- $this->assign('id', $id);
-
- //秒杀详情
- $time_info = $seckill_model->getSeckillTimeInfo([ [ 'id', '=', $id ] ]);
- if (!empty($time_info[ 'data' ])) {
- $time_info[ 'data' ] = $seckill_model->transformSeckillTime($time_info[ 'data' ]);
- }
- $this->assign('time_info', $time_info[ 'data' ]);
-
- return $this->fetch("seckill/edit");
- }
- }
-
- /**
- * 删除秒杀时间段
- */
- public function delete()
- {
- if (request()->isJson()) {
- $seckill_time_id = input('id', 0);
- $seckill_model = new SeckillModel();
- return $seckill_model->deleteSeckillTime($seckill_time_id);
- }
- }
-
- /**
- * 添加秒杀商品
- */
- public function addGoods()
- {
- $seckill_model = new SeckillModel();
- if (request()->isJson()) {
- $data = [
- 'site_id' => $this->site_id,
- 'seckill_name' => input('seckill_name', ''),
- 'remark' => input('remark', ''),
- 'seckill_time_id' => input('seckill_time_id', ''),
- 'start_time' => strtotime(input('start_time', '')),
- 'end_time' => strtotime(input('end_time', '')),
- 'goods_data' => input('goods_data', ''),
- 'goods_ids' => input('goods_ids', ''),
- 'sort' => input('sort', '')
- ];
- $res = $seckill_model->addSeckillGoods($data);
- return $res;
- } else {
- return $this->fetch("seckill/editgoods");
- }
- }
-
- /**
- * 更新商品(秒杀价格)
- */
- public function updateGoods()
- {
- $seckill_model = new SeckillModel();
- if (request()->isJson()) {
- $data = [
- 'site_id' => $this->site_id,
- 'id' => input('id', ''),
- 'seckill_name' => input('seckill_name', ''),
- 'remark' => input('remark', ''),
- 'seckill_time_id' => input('seckill_time_id', ''),
- 'start_time' => strtotime(input('start_time', '')),
- 'end_time' => strtotime(input('end_time', '')),
- 'sku_list' => input('sku_list', ''),
- 'goods_ids' => input('goods_ids', ''),
- 'sort' => input('sort', ''),
- ];
- $res = $seckill_model->editSeckillGoods($data);
- return $res;
- } else {
- $seckill_id = input('id', '');
- if (empty($seckill_id)) {
- $this->error('缺少参数id');
- }
- $seckill_info = $seckill_model->getSeckillDetail([ [ 'id', '=', $seckill_id ] ])[ 'data' ];
-
- $seckill_time_id = trim($seckill_info[ 'seckill_time_id' ], ',');
- $time_list = $seckill_model->getSeckillTimeList([ [ 'id', 'in', $seckill_time_id ] ])[ 'data' ];
-
- $this->assign('seckill_info', $seckill_info);
- $this->assign('time_list', $time_list);
-
- return $this->fetch("seckill/editgoods");
- }
- }
-
- public function seckillSort()
- {
- $sort = input('sort', 0);
- $id = input('id', 0);
- $seckill_model = new SeckillModel();
- return $seckill_model->seckillSort($id, $sort);
- }
-
- /**
- * 删除商品
- */
- public function deleteGoods()
- {
- if (request()->isJson()) {
- $seckill_id = input('id', 0);
- $site_id = $this->site_id;
-
- $seckill_model = new SeckillModel();
- return $seckill_model->deleteSeckillGoods($seckill_id, $site_id);
- }
- }
-
- /**
- * 秒杀商品
- */
- public function goodslist()
- {
- $seckill_time_id = input('seckill_time_id', '');
- if (request()->isJson()) {
- $page = input('page', 1);
- $page_size = input('page_size', PAGE_LIST_ROWS);
- $goods_name = input('goods_name', '');
- $status = input('status', '');
- $link_sort = input('order', 'start_time');
- $sort = input('sort', 'desc');
-
- $condition = [];
- $condition[] = [ 'site_id', '=', $this->site_id ];
- $condition[] = [ 'goods_name', 'like', '%' . $goods_name . '%' ];
-
- if ($status !== '') $condition[] = [ 'status', '=', $status ];
- //排序
- if ($link_sort == 'sort') {
- $order_by = $link_sort . ' ' . $sort;
- } else {
- $order_by = $link_sort . ' ' . $sort . ',sort desc';
- }
-
- if (!empty($seckill_time_id)) {
- $condition[] = [ '', 'exp', \think\facade\Db::raw("FIND_IN_SET({$seckill_time_id},seckill_time_id)") ];
- }
-
- $start_time = input('start_time', '');
- $end_time = input('end_time', '');
-
- if ($start_time && !$end_time) {
- $condition[] = [ 'end_time', '>=', date_to_time($start_time) ];
- } elseif (!$start_time && $end_time) {
- $condition[] = [ 'start_time', '<=', date_to_time($end_time) ];
- } elseif ($start_time && $end_time) {
- $start_timestamp = date_to_time($start_time);
- $end_timestamp = date_to_time($end_time);
- $sql = "start_time between {$start_timestamp} and {$end_timestamp}";
- $sql .= " or end_time between {$start_timestamp} and {$end_timestamp}";
- $sql .= " or (start_time <= {$start_timestamp} and end_time >= {$end_timestamp})";
- $condition[] = [ '', 'exp', \think\facade\Db::raw($sql) ];
- }
-
- $seckill_model = new SeckillModel();
- $seckill_list = $seckill_model->getSeckillPageList($condition, $page, $page_size, $order_by);
-
- $seckill_condition[] = [ 'site_id', '=', $this->site_id ];
-
- $time_list = $seckill_model->getSeckillTimeList($seckill_condition);
- foreach ($seckill_list[ 'data' ][ 'list' ] as $k => $v) {
- $seckill_list[ 'data' ][ 'list' ][ $k ][ 'time_list' ] = [];
- foreach ($time_list[ 'data' ] as $index => $item) {
- if (strpos(',' . $v[ 'seckill_time_id' ] . ',', ',' . $item[ 'id' ] . ',') !== false) {
- $seckill_list[ 'data' ][ 'list' ][ $k ][ 'time_list' ][] = $item;
- }
- }
- }
-
- return $seckill_list;
- } else {
-
- $condition[] = [ 'site_id', '=', $this->site_id ];
- $order = 'seckill_start_time asc';
- $field = '*';
-
- $seckill_model = new SeckillModel();
- $res = $seckill_model->getSeckillTimeList($condition, $field, $order, null);
- $this->assign('seckill_time_id', $seckill_time_id);
- $this->assign('res', $res[ 'data' ]);
- return $this->fetch("seckill/goodslist");
- }
- }
-
- /**
- * 秒杀时段
- */
- public function seckilltimeselect()
- {
- if (request()->isJson()) {
- $condition[] = [ 'site_id', '=', $this->site_id ];
- $order = 'seckill_start_time asc';
- $field = '*';
-
- $seckill_model = new SeckillModel();
- $res = $seckill_model->getSeckillTimeList($condition, $field, $order, null);
- foreach ($res[ 'data' ] as $key => $val) {
- $val = $seckill_model->transformSeckillTime($val);
- $res[ 'data' ][ $key ][ 'seckill_start_time_show' ] = "{$val['start_hour']}:{$val['start_minute']}:{$val['start_second']}";
- $res[ 'data' ][ $key ][ 'seckill_end_time_show' ] = "{$val['end_hour']}:{$val['end_minute']}:{$val['end_second']}";
- }
- return $res;
- } else {
-
- return $this->fetch("seckill/seckilltimeselect");
- }
-
- }
-
- /**
- * 获取商品列表
- * @return array
- */
- public function getSkuList()
- {
- if (request()->isJson()) {
- $seckill_model = new SeckillModel();
- $seckill_id = input('seckill_id', '');
- $goods_list = $seckill_model->getSeckillGoodsList($seckill_id);
- return $goods_list;
- }
- }
-
- /**
- * 手动关闭秒杀
- * @return array
- */
- public function closeSeckill()
- {
- if (request()->isJson()) {
- $seckill_model = new SeckillModel();
- $seckill_id = input('seckill_id', '');
- $goods_list = $seckill_model->closeSeckill($seckill_id);
- return $goods_list;
- }
- }
-
- /**
- * 秒杀推广
- */
- public function seckillUrl()
- {
- $seckill_id = input('seckill_id', '');
- $app_type = input('app_type', 'all');
- $seckill_model = new SeckillModel();
-
- $res = $seckill_model->urlQrcode('/pages_promotion/seckill/detail', [ 'id' => $seckill_id ], 'seckill', $app_type, $this->site_id);
- return $res;
- }
-
- /**
- * 批量删除商品
- */
- public function deleteGoodsAll()
- {
- if (request()->isJson()) {
- $seckill_id = input('seckill_id', 0);
-
- $seckill_model = new SeckillModel();
- foreach ($seckill_id as $k => $v){
- $res = $seckill_model->deleteSeckillGoods($v, $this->site_id);
- }
- return $res;
- }
- }
-
- /**
- * 批量关闭秒杀
- * @return array
- */
- public function closeSeckillAll()
- {
- if (request()->isJson()) {
- $seckill_model = new SeckillModel();
- $seckill_id = input('seckill_id', '');
-
- foreach ($seckill_id as $k => $v){
- $res = $seckill_model->closeSeckill($v);
- }
- return $res;
- }
- }
-
+replace = [
+ 'SECKILL_CSS' => __ROOT__ . '/addon/seckill/shop/view/public/css',
+ 'SECKILL_JS' => __ROOT__ . '/addon/seckill/shop/view/public/js',
+ 'SECKILL_IMG' => __ROOT__ . '/addon/seckill/shop/view/public/img',
+ ];
+ parent::__construct($app);
+ }
+
+ /**
+ * 秒杀时间段列表
+ */
+ public function lists()
+ {
+ if (request()->isJson()) {
+ $condition[] = [ 'site_id', '=', $this->site_id ];
+ $order = 'seckill_start_time asc';
+ $field = '*';
+
+ $seckill_model = new SeckillModel();
+ $res = $seckill_model->getSeckillTimeList($condition, $field, $order, null);
+ foreach ($res[ 'data' ] as $key => $val) {
+ $val = $seckill_model->transformSeckillTime($val);
+ $res[ 'data' ][ $key ][ 'seckill_start_time_show' ] = "{$val['start_hour']}:{$val['start_minute']}:{$val['start_second']}";
+ $res[ 'data' ][ $key ][ 'seckill_end_time_show' ] = "{$val['end_hour']}:{$val['end_minute']}:{$val['end_second']}";
+ }
+ return $res;
+ } else {
+
+ return $this->fetch("seckill/lists");
+ }
+ }
+
+ /**
+ * 添加秒杀时间段
+ */
+ public function add()
+ {
+ if (request()->isJson()) {
+ $start_hour = input('start_hour', 0);
+ $start_minute = input('start_minute', 0);
+ $start_second = input('start_second', 0);
+
+ $end_hour = input('end_hour', 0);
+ $end_minute = input('end_minute', 0);
+ $end_second = input('end_second', 0);
+
+ $data = [
+ 'site_id' => $this->site_id,
+ 'name' => input('name', ''),
+ 'seckill_start_time' => $start_hour * 3600 + $start_minute * 60 + $start_second,
+ 'seckill_end_time' => $end_hour * 3600 + $end_minute * 60 + $end_second,
+ 'create_time' => time(),
+ ];
+ $seckill_model = new SeckillModel();
+ return $seckill_model->addSeckillTime($data);
+ } else {
+ return $this->fetch("seckill/add");
+ }
+ }
+
+ /**
+ * 编辑秒杀时间段
+ */
+ public function edit()
+ {
+ $seckill_model = new SeckillModel();
+ if (request()->isJson()) {
+ $start_hour = input('start_hour', 0);
+ $start_minute = input('start_minute', 0);
+ $start_second = input('start_second', 0);
+
+ $end_hour = input('end_hour', 0);
+ $end_minute = input('end_minute', 0);
+ $end_second = input('end_second', 0);
+
+ $data = [
+ 'name' => input('name', ''),
+ 'seckill_start_time' => $start_hour * 3600 + $start_minute * 60 + $start_second,
+ 'seckill_end_time' => $end_hour * 3600 + $end_minute * 60 + $end_second,
+ 'create_time' => time(),
+ 'id' => input('id', 0),
+ ];
+ return $seckill_model->editSeckillTime($data, $this->site_id);
+ } else {
+ $id = input('id', 0);
+ $this->assign('id', $id);
+
+ //秒杀详情
+ $time_info = $seckill_model->getSeckillTimeInfo([ [ 'id', '=', $id ] ]);
+ if (!empty($time_info[ 'data' ])) {
+ $time_info[ 'data' ] = $seckill_model->transformSeckillTime($time_info[ 'data' ]);
+ }
+ $this->assign('time_info', $time_info[ 'data' ]);
+
+ return $this->fetch("seckill/edit");
+ }
+ }
+
+ /**
+ * 删除秒杀时间段
+ */
+ public function delete()
+ {
+ if (request()->isJson()) {
+ $seckill_time_id = input('id', 0);
+ $seckill_model = new SeckillModel();
+ return $seckill_model->deleteSeckillTime($seckill_time_id);
+ }
+ }
+
+ /**
+ * 添加秒杀商品
+ */
+ public function addGoods()
+ {
+ $seckill_model = new SeckillModel();
+ if (request()->isJson()) {
+ $data = [
+ 'site_id' => $this->site_id,
+ 'seckill_name' => input('seckill_name', ''),
+ 'remark' => input('remark', ''),
+ 'seckill_time_id' => input('seckill_time_id', ''),
+ 'start_time' => strtotime(input('start_time', '')),
+ 'end_time' => strtotime(input('end_time', '')),
+ 'goods_data' => input('goods_data', ''),
+ 'goods_ids' => input('goods_ids', ''),
+ 'sort' => input('sort', '')
+ ];
+ $res = $seckill_model->addSeckillGoods($data);
+ return $res;
+ } else {
+ return $this->fetch("seckill/editgoods");
+ }
+ }
+
+ /**
+ * 更新商品(秒杀价格)
+ */
+ public function updateGoods()
+ {
+ $seckill_model = new SeckillModel();
+ if (request()->isJson()) {
+ $data = [
+ 'site_id' => $this->site_id,
+ 'id' => input('id', ''),
+ 'seckill_name' => input('seckill_name', ''),
+ 'remark' => input('remark', ''),
+ 'seckill_time_id' => input('seckill_time_id', ''),
+ 'start_time' => strtotime(input('start_time', '')),
+ 'end_time' => strtotime(input('end_time', '')),
+ 'sku_list' => input('sku_list', ''),
+ 'goods_ids' => input('goods_ids', ''),
+ 'sort' => input('sort', ''),
+ ];
+ $res = $seckill_model->editSeckillGoods($data);
+ return $res;
+ } else {
+ $seckill_id = input('id', '');
+ if (empty($seckill_id)) {
+ $this->error('缺少参数id');
+ }
+ $seckill_info = $seckill_model->getSeckillDetail([ [ 'id', '=', $seckill_id ] ])[ 'data' ];
+
+ $seckill_time_id = trim($seckill_info[ 'seckill_time_id' ], ',');
+ $time_list = $seckill_model->getSeckillTimeList([ [ 'id', 'in', $seckill_time_id ] ])[ 'data' ];
+
+ $this->assign('seckill_info', $seckill_info);
+ $this->assign('time_list', $time_list);
+
+ return $this->fetch("seckill/editgoods");
+ }
+ }
+
+ public function seckillSort()
+ {
+ $sort = input('sort', 0);
+ $id = input('id', 0);
+ $seckill_model = new SeckillModel();
+ return $seckill_model->seckillSort($id, $sort);
+ }
+
+ /**
+ * 删除商品
+ */
+ public function deleteGoods()
+ {
+ if (request()->isJson()) {
+ $seckill_id = input('id', 0);
+ $site_id = $this->site_id;
+
+ $seckill_model = new SeckillModel();
+ return $seckill_model->deleteSeckillGoods($seckill_id, $site_id);
+ }
+ }
+
+ /**
+ * 秒杀商品
+ */
+ public function goodslist()
+ {
+ $seckill_time_id = input('seckill_time_id', '');
+ if (request()->isJson()) {
+ $page = input('page', 1);
+ $page_size = input('page_size', PAGE_LIST_ROWS);
+ $goods_name = input('goods_name', '');
+ $status = input('status', '');
+ $link_sort = input('order', 'start_time');
+ $sort = input('sort', 'desc');
+
+ $condition = [];
+ $condition[] = [ 'site_id', '=', $this->site_id ];
+ $condition[] = [ 'goods_name', 'like', '%' . $goods_name . '%' ];
+
+ if ($status !== '') $condition[] = [ 'status', '=', $status ];
+ //排序
+ if ($link_sort == 'sort') {
+ $order_by = $link_sort . ' ' . $sort;
+ } else {
+ $order_by = $link_sort . ' ' . $sort . ',sort desc';
+ }
+
+ if (!empty($seckill_time_id)) {
+ $condition[] = [ '', 'exp', \think\facade\Db::raw("FIND_IN_SET({$seckill_time_id},seckill_time_id)") ];
+ }
+
+ $start_time = input('start_time', '');
+ $end_time = input('end_time', '');
+
+ if ($start_time && !$end_time) {
+ $condition[] = [ 'end_time', '>=', date_to_time($start_time) ];
+ } elseif (!$start_time && $end_time) {
+ $condition[] = [ 'start_time', '<=', date_to_time($end_time) ];
+ } elseif ($start_time && $end_time) {
+ $start_timestamp = date_to_time($start_time);
+ $end_timestamp = date_to_time($end_time);
+ $sql = "start_time between {$start_timestamp} and {$end_timestamp}";
+ $sql .= " or end_time between {$start_timestamp} and {$end_timestamp}";
+ $sql .= " or (start_time <= {$start_timestamp} and end_time >= {$end_timestamp})";
+ $condition[] = [ '', 'exp', \think\facade\Db::raw($sql) ];
+ }
+
+ $seckill_model = new SeckillModel();
+ $seckill_list = $seckill_model->getSeckillPageList($condition, $page, $page_size, $order_by);
+
+ $seckill_condition[] = [ 'site_id', '=', $this->site_id ];
+
+ $time_list = $seckill_model->getSeckillTimeList($seckill_condition);
+ foreach ($seckill_list[ 'data' ][ 'list' ] as $k => $v) {
+ $seckill_list[ 'data' ][ 'list' ][ $k ][ 'time_list' ] = [];
+ foreach ($time_list[ 'data' ] as $index => $item) {
+ if (strpos(',' . $v[ 'seckill_time_id' ] . ',', ',' . $item[ 'id' ] . ',') !== false) {
+ $seckill_list[ 'data' ][ 'list' ][ $k ][ 'time_list' ][] = $item;
+ }
+ }
+ }
+
+ return $seckill_list;
+ } else {
+
+ $condition[] = [ 'site_id', '=', $this->site_id ];
+ $order = 'seckill_start_time asc';
+ $field = '*';
+
+ $seckill_model = new SeckillModel();
+ $res = $seckill_model->getSeckillTimeList($condition, $field, $order, null);
+ $this->assign('seckill_time_id', $seckill_time_id);
+ $this->assign('res', $res[ 'data' ]);
+ return $this->fetch("seckill/goodslist");
+ }
+ }
+
+ /**
+ * 秒杀时段
+ */
+ public function seckilltimeselect()
+ {
+ if (request()->isJson()) {
+ $condition[] = [ 'site_id', '=', $this->site_id ];
+ $order = 'seckill_start_time asc';
+ $field = '*';
+
+ $seckill_model = new SeckillModel();
+ $res = $seckill_model->getSeckillTimeList($condition, $field, $order, null);
+ foreach ($res[ 'data' ] as $key => $val) {
+ $val = $seckill_model->transformSeckillTime($val);
+ $res[ 'data' ][ $key ][ 'seckill_start_time_show' ] = "{$val['start_hour']}:{$val['start_minute']}:{$val['start_second']}";
+ $res[ 'data' ][ $key ][ 'seckill_end_time_show' ] = "{$val['end_hour']}:{$val['end_minute']}:{$val['end_second']}";
+ }
+ return $res;
+ } else {
+
+ return $this->fetch("seckill/seckilltimeselect");
+ }
+
+ }
+
+ /**
+ * 获取商品列表
+ * @return array
+ */
+ public function getSkuList()
+ {
+ if (request()->isJson()) {
+ $seckill_model = new SeckillModel();
+ $seckill_id = input('seckill_id', '');
+ $goods_list = $seckill_model->getSeckillGoodsList($seckill_id);
+ return $goods_list;
+ }
+ }
+
+ /**
+ * 手动关闭秒杀
+ * @return array
+ */
+ public function closeSeckill()
+ {
+ if (request()->isJson()) {
+ $seckill_model = new SeckillModel();
+ $seckill_id = input('seckill_id', '');
+ $goods_list = $seckill_model->closeSeckill($seckill_id);
+ return $goods_list;
+ }
+ }
+
+ /**
+ * 秒杀推广
+ */
+ public function seckillUrl()
+ {
+ $seckill_id = input('seckill_id', '');
+ $app_type = input('app_type', 'all');
+ $seckill_model = new SeckillModel();
+
+ $res = $seckill_model->urlQrcode('/pages_promotion/seckill/detail', [ 'id' => $seckill_id ], 'seckill', $app_type, $this->site_id);
+ return $res;
+ }
+
+ /**
+ * 批量删除商品
+ */
+ public function deleteGoodsAll()
+ {
+ if (request()->isJson()) {
+ $seckill_id = input('seckill_id', 0);
+
+ $seckill_model = new SeckillModel();
+ foreach ($seckill_id as $k => $v){
+ $res = $seckill_model->deleteSeckillGoods($v, $this->site_id);
+ }
+ return $res;
+ }
+ }
+
+ /**
+ * 批量关闭秒杀
+ * @return array
+ */
+ public function closeSeckillAll()
+ {
+ if (request()->isJson()) {
+ $seckill_model = new SeckillModel();
+ $seckill_id = input('seckill_id', '');
+
+ foreach ($seckill_id as $k => $v){
+ $res = $seckill_model->closeSeckill($v);
+ }
+ return $res;
+ }
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/virtualcard/config/diy_view.php b/src/addon/virtualcard/config/diy_view.php
index c3c657905..e36ca9b7d 100644
--- a/src/addon/virtualcard/config/diy_view.php
+++ b/src/addon/virtualcard/config/diy_view.php
@@ -1,38 +1,30 @@
- '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
- 'template' => [],
-
- // 后台自定义组件——装修
- 'util' => [],
-
- // 自定义页面路径
- 'link' => [],
-
- // 自定义图标库
- 'icon_library' => [],
-
- // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
- 'component' => [],
-
- // uni-app 页面,多个逗号隔开
- 'pages' => [],
-
- // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
- 'info' => [],
-
- // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
- 'theme' => [],
-
- // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
- 'data' => []
+ '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
+ 'template' => [],
+
+ // 后台自定义组件——装修
+ 'util' => [],
+
+ // 自定义页面路径
+ 'link' => [],
+
+ // 自定义图标库
+ 'icon_library' => [],
+
+ // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
+ 'component' => [],
+
+ // uni-app 页面,多个逗号隔开
+ 'pages' => [],
+
+ // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
+ 'info' => [],
+
+ // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
+ 'theme' => [],
+
+ // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
+ 'data' => []
];
\ No newline at end of file
diff --git a/src/addon/virtualcard/config/info.php b/src/addon/virtualcard/config/info.php
index 3377795d5..867255f12 100644
--- a/src/addon/virtualcard/config/info.php
+++ b/src/addon/virtualcard/config/info.php
@@ -1,20 +1,12 @@
- 'virtualcard',
- 'title' => '卡密商品',
- 'description' => '创建电子卡密类型商品',
- 'type' => 'tool', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
- 'status' => 1,
- 'author' => '',
- 'version' => '5.3.1',
- 'version_no' => '525231212001',
- 'content' => '',
+ 'virtualcard',
+ 'title' => '卡密商品',
+ 'description' => '创建电子卡密类型商品',
+ 'type' => 'tool', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
+ 'status' => 1,
+ 'author' => '',
+ 'version' => '5.3.1',
+ 'version_no' => '525231212001',
+ 'content' => '',
];
\ No newline at end of file
diff --git a/src/addon/virtualcard/event/Install.php b/src/addon/virtualcard/event/Install.php
index 1e18c3d96..f61ff6f37 100644
--- a/src/addon/virtualcard/event/Install.php
+++ b/src/addon/virtualcard/event/Install.php
@@ -1,26 +1,18 @@
- 3, 'name' => '电子卡密' );
-
- private $goods_state = array (
- 1 => '销售中',
- 0 => '仓库中'
- );
-
- public function getGoodsState()
- {
- return $this->goods_state;
- }
-
- public function getGoodsClass()
- {
- return $this->goods_class;
- }
-
- /**
- * 商品添加
- * @param $data
- */
- public function addGoods($data)
- {
- model('goods')->startTrans();
-
- try {
-
- if (!empty($data[ 'goods_attr_format' ])) {
-
- $goods_attr_format = json_decode($data[ 'goods_attr_format' ], true);
- $keys = array_column($goods_attr_format, 'sort');
- if (!empty($keys)) {
- array_multisort($keys, SORT_ASC, SORT_NUMERIC, $goods_attr_format);
- $data[ 'goods_attr_format' ] = json_encode($goods_attr_format);
- }
- }
-
- $goods_image = $data[ 'goods_image' ];
- $first_image = explode(",", $goods_image)[ 0 ];
-
- //SKU商品数据
- if (!empty($data[ 'goods_sku_data' ])) {
- $data[ 'goods_sku_data' ] = json_decode($data[ 'goods_sku_data' ], true);
- }
-
- //获取标签名称
- $label_name = '';
- if ($data[ 'label_id' ]) {
- $label_info = model('goods_label')->getInfo([ [ 'id', '=', $data[ 'label_id' ] ] ], 'label_name');
- $label_name = $label_info[ 'label_name' ] ?? '';
- }
- $brand_name = '';
- if ($data[ 'brand_id' ]) {
- $brand_info = model('goods_brand')->getInfo([ [ 'brand_id', '=', $data[ 'brand_id' ] ] ], 'brand_name');
- $brand_name = $brand_info[ 'brand_name' ] ?? '';
- }
- $goods_data = array (
- 'goods_image' => $goods_image,
- 'price' => $data[ 'goods_sku_data' ][ 0 ][ 'price' ],
- 'market_price' => $data[ 'goods_sku_data' ][ 0 ][ 'market_price' ],
- 'cost_price' => $data[ 'goods_sku_data' ][ 0 ][ 'cost_price' ],
- 'goods_spec_format' => $data[ 'goods_spec_format' ],
- 'category_id' => $data[ 'category_id' ],
- 'category_json' => $data[ 'category_json' ],
- 'label_id' => $data[ 'label_id' ],
- 'label_name' => $label_name,
- 'timer_on' => $data[ 'timer_on' ],
- 'timer_off' => $data[ 'timer_off' ],
- 'sale_show' => $data[ 'sale_show' ] ?? 1,
- 'stock_show' => $data[ 'stock_show' ] ?? 1,
- 'market_price_show' => $data[ 'market_price_show' ] ?? 1,
- 'barrage_show' => $data[ 'barrage_show' ] ?? 1,
- 'is_consume_discount' => $data[ 'is_consume_discount' ],
- );
-
- $common_data = array (
- 'goods_name' => $data[ 'goods_name' ],
- 'goods_class' => $this->goods_class[ 'id' ],
- 'goods_class_name' => $this->goods_class[ 'name' ],
- 'goods_attr_class' => $data[ 'goods_attr_class' ],
- 'goods_attr_name' => $data[ 'goods_attr_name' ],
- 'is_limit' => $data[ 'is_limit' ] ?? 0,
- 'limit_type' => $data[ 'limit_type' ] ?? 1,
- 'site_id' => $data[ 'site_id' ],
- 'goods_content' => $data[ 'goods_content' ],
- 'goods_state' => $data[ 'goods_state' ],
- 'goods_stock_alarm' => $data[ 'goods_stock_alarm' ],
- 'is_virtual' => 1,
- 'virtual_indate' => 0,
- 'goods_attr_format' => $data[ 'goods_attr_format' ],
- 'introduction' => $data[ 'introduction' ],
- 'keywords' => $data[ 'keywords' ],
- 'unit' => $data[ 'unit' ],
- 'brand_id' => $data[ 'brand_id' ],//品牌id
- 'brand_name' => $brand_name,//品牌名称
- 'video_url' => $data[ 'video_url' ],
- 'sort' => $data[ 'sort' ],
- 'goods_service_ids' => $data[ 'goods_service_ids' ],
- 'create_time' => time(),
- 'virtual_sale' => $data[ 'virtual_sale' ],
- 'max_buy' => $data[ 'max_buy' ],
- 'min_buy' => $data[ 'min_buy' ],
- 'recommend_way' => $data[ 'recommend_way' ],
- 'qr_id' => $data[ 'qr_id' ] ?? 0,
- 'template_id' => $data[ 'template_id' ] ?? 0,
- 'form_id' => $data[ 'form_id' ] ?? 0,
- 'sale_channel' => $data[ 'sale_channel' ] ?? 'all',
- 'sale_store' => $data[ 'sale_store' ] ?? 'all',
- 'supplier_id' => $data[ 'supplier_id' ] ?? 0
- );
-
- $goods_id = model('goods')->add(array_merge($goods_data, $common_data));
-
- $goods_stock = 0;
-
- //添加sku商品
- foreach ($data[ 'goods_sku_data' ] as $item) {
-// $carmichael = 0;
-// if (isset($item[ 'carmichael' ])) {
-// if (is_array($item[ 'carmichael' ])) {
-// $carmichael = count($item[ 'carmichael' ]);
-// }
-// }
- $sku_data = array (
- 'sku_name' => $data[ 'goods_name' ] . ' ' . $item[ 'spec_name' ],
- 'spec_name' => $item[ 'spec_name' ],
- 'sku_no' => $item[ 'sku_no' ],
- 'sku_spec_format' => !empty($item[ 'sku_spec_format' ]) ? json_encode($item[ 'sku_spec_format' ]) : "",
- 'price' => $item[ 'price' ],
- 'market_price' => $item[ 'market_price' ],
- 'cost_price' => $item[ 'cost_price' ],
- 'discount_price' => $item[ 'price' ],//sku折扣价(默认等于单价)
-// 'stock' => $carmichael,
- 'stock_alarm' => $item[ 'stock_alarm' ],
- 'sku_image' => !empty($item[ 'sku_image' ]) ? $item[ 'sku_image' ] : $first_image,
- 'sku_images' => $item[ 'sku_images' ],
- 'goods_id' => $goods_id,
- 'is_default' => $item[ 'is_default' ] ?? 0,
- 'is_consume_discount' => $data[ 'is_consume_discount' ],
- 'site_id' => $data[ 'site_id' ]
- );
- $sku_data = array_merge($sku_data, $common_data);
- $sku_id = model('goods_sku')->add($sku_data);
-
- // 添加到虚拟商品表
- if (isset($item[ 'carmichael' ])) {
- if (is_array($item[ 'carmichael' ]) && count($item[ 'carmichael' ])) {
- $goods_stock += count($item[ 'carmichael' ]);
- $virtual_goods = [];
- foreach ($item[ 'carmichael' ] as $carmichael_item) {
- $carmichael_item = htmlspecialchars(addslashes($carmichael_item));
- $card = explode(' ', $carmichael_item);
- $card_arr = [
- 'cardno' => $card[ 0 ] ?? '',
- 'password' => $card[ 1 ] ?? ''
- ];
- $virtual_goods[] = [
- 'site_id' => $data[ 'site_id' ],
- 'sku_id' => $sku_id,
- 'sku_name' => $data[ 'goods_name' ] . ' ' . $item[ 'spec_name' ],
- 'card_info' => json_encode($card_arr),
- 'goods_id' => $goods_id
- ];
- }
- model('goods_virtual')->addList($virtual_goods);
- }
- }
- }
-
- // 赋值第一个商品sku_id
- $first_info = model('goods_sku')->getFirstData([ 'goods_id' => $goods_id ], 'sku_id', 'is_default desc,sku_id asc');
- model('goods')->update([ 'sku_id' => $first_info[ 'sku_id' ] ], [ [ 'goods_id', '=', $goods_id ] ]);
-
- if (!empty($data[ 'goods_spec_format' ])) {
- // 刷新SKU商品规格项 / 规格值JSON字符串
- $this->dealGoodsSkuSpecFormat($goods_id, $data[ 'goods_spec_format' ]);
- }
-
- $cron = new Cron();
- //定时上下架
- if ($goods_data[ 'timer_on' ] > 0) {
- $cron->addCron(1, 0, "商品定时上架", "CronGoodsTimerOn", $goods_data[ 'timer_on' ], $goods_id);
- }
- if ($goods_data[ 'timer_off' ] > 0) {
- $cron->addCron(1, 0, "商品定时下架", "CronGoodsTimerOff", $goods_data[ 'timer_off' ], $goods_id);
- }
-
- //添加统计
- $stat = new Stat();
-// $stat->addShopStat([ 'add_goods_count' => 1, 'site_id' => $data[ 'site_id' ] ]);
- $stat->switchStat([ 'type' => 'add_goods', 'data' => [ 'add_goods_count' => 1, 'site_id' => $data[ 'site_id' ] ] ]);
-
- //同步计算卡密库存数据
- $this->statisticsStock($goods_id);
- model('goods')->commit();
-
- return $this->success($goods_id);
- } catch (\Exception $e) {
- model('goods')->rollback();
- return $this->error($e->getMessage());
- }
- }
-
- /**
- * 商品编辑
- * @param $data
- */
- public function editGoods($data)
- {
-
- model('goods')->startTrans();
-
- try {
-
- if (!empty($data[ 'goods_attr_format' ])) {
-
- $goods_attr_format = json_decode($data[ 'goods_attr_format' ], true);
- $keys = array_column($goods_attr_format, 'sort');
- if (!empty($keys)) {
- array_multisort($keys, SORT_ASC, SORT_NUMERIC, $goods_attr_format);
- $data[ 'goods_attr_format' ] = json_encode($goods_attr_format);
- }
- }
-
- $goods_id = $data[ 'goods_id' ];
- $goods_image = $data[ 'goods_image' ];
- $first_image = explode(",", $goods_image)[ 0 ];
-
- //SKU商品数据
- if (!empty($data[ 'goods_sku_data' ])) {
- $data[ 'goods_sku_data' ] = json_decode($data[ 'goods_sku_data' ], true);
- }
-
- //获取标签名称
- $label_name = '';
- if ($data[ 'label_id' ]) {
- $label_info = model('goods_label')->getInfo([ [ 'id', '=', $data[ 'label_id' ] ] ], 'label_name');
- $label_name = $label_info[ 'label_name' ] ?? '';
- }
- $brand_name = '';
- if ($data[ 'brand_id' ]) {
- $brand_info = model('goods_brand')->getInfo([ [ 'brand_id', '=', $data[ 'brand_id' ] ] ], 'brand_name');
- $brand_name = $brand_info[ 'brand_name' ] ?? '';
- }
- $goods_data = array (
- 'goods_image' => $goods_image,
- 'price' => $data[ 'goods_sku_data' ][ 0 ][ 'price' ],
- 'market_price' => $data[ 'goods_sku_data' ][ 0 ][ 'market_price' ],
- 'cost_price' => $data[ 'goods_sku_data' ][ 0 ][ 'cost_price' ],
- 'goods_spec_format' => $data[ 'goods_spec_format' ],
- 'category_id' => $data[ 'category_id' ],
- 'category_json' => $data[ 'category_json' ],
- 'label_id' => $data[ 'label_id' ],
- 'label_name' => $label_name,
- 'timer_on' => $data[ 'timer_on' ],
- 'timer_off' => $data[ 'timer_off' ],
- 'sale_show' => $data[ 'sale_show' ],
- 'stock_show' => $data[ 'stock_show' ],
- 'market_price_show' => $data[ 'market_price_show' ],
- 'barrage_show' => $data[ 'barrage_show' ],
- 'is_consume_discount' => $data[ 'is_consume_discount' ],
- );
-
- $common_data = array (
- 'goods_name' => $data[ 'goods_name' ],
- 'goods_class' => $this->goods_class[ 'id' ],
- 'goods_class_name' => $this->goods_class[ 'name' ],
- 'goods_attr_class' => $data[ 'goods_attr_class' ],
- 'goods_attr_name' => $data[ 'goods_attr_name' ],
- 'is_limit' => $data[ 'is_limit' ] ?? 0,
- 'limit_type' => $data[ 'limit_type' ] ?? 1,
- 'site_id' => $data[ 'site_id' ],
- 'goods_content' => $data[ 'goods_content' ],
- 'goods_state' => $data[ 'goods_state' ],
- 'goods_stock_alarm' => $data[ 'goods_stock_alarm' ],
- 'is_virtual' => 1,
- 'virtual_indate' => 0,
- 'goods_attr_format' => $data[ 'goods_attr_format' ],
- 'introduction' => $data[ 'introduction' ],
- 'keywords' => $data[ 'keywords' ],
- 'unit' => $data[ 'unit' ],
- 'video_url' => $data[ 'video_url' ],
- 'sort' => $data[ 'sort' ],
- 'goods_service_ids' => $data[ 'goods_service_ids' ],
- 'brand_id' => $data[ 'brand_id' ],//品牌id
- 'brand_name' => $brand_name,//品牌名称
- 'modify_time' => time(),
- 'virtual_sale' => $data[ 'virtual_sale' ],
- 'max_buy' => $data[ 'max_buy' ],
- 'min_buy' => $data[ 'min_buy' ],
- 'recommend_way' => $data[ 'recommend_way' ],
- 'qr_id' => $data[ 'qr_id' ] ?? 0,
- 'template_id' => $data[ 'template_id' ] ?? 0,
- 'form_id' => $data[ 'form_id' ] ?? 0,
- 'sale_channel' => $data[ 'sale_channel' ] ?? 'all',
- 'sale_store' => $data[ 'sale_store' ] ?? 'all',
- 'supplier_id' => $data[ 'supplier_id' ] ?? 0
- );
-
- model('goods')->update(array_merge($goods_data, $common_data), [ [ 'goods_id', '=', $goods_id ], [ 'goods_class', '=', $this->goods_class[ 'id' ] ] ]);
-
- $goods_stock = 0;
-
- // 如果只编辑价格库存就是修改,如果添加规格项/值就需要重新生成
- if (!empty($data[ 'goods_sku_data' ][ 0 ][ 'sku_id' ])) {
-
- if ($data[ 'spec_type_status' ] == 1) {
- $sku_list = model('goods_sku')->getList([ [ 'goods_id', '=', $goods_id ] ], 'sku_id');
- $sku_id_arr = array_column($sku_list, 'sku_id', 'sku_id');
- //添加sku商品
- foreach ($data[ 'goods_sku_data' ] as $item) {
- $carmichael = 0;
- if (isset($item[ 'carmichael' ])) {
- if (is_array($item[ 'carmichael' ])) {
- $carmichael = count($item[ 'carmichael' ]);
- }
- }
- $sku_data = array (
- 'sku_name' => $data[ 'goods_name' ] . ' ' . $item[ 'spec_name' ],
- 'spec_name' => $item[ 'spec_name' ],
- 'sku_no' => $item[ 'sku_no' ],
- 'sku_spec_format' => !empty($item[ 'sku_spec_format' ]) ? json_encode($item[ 'sku_spec_format' ]) : "",
- 'price' => $item[ 'price' ],
- 'market_price' => $item[ 'market_price' ],
- 'cost_price' => $item[ 'cost_price' ],
- 'discount_price' => $item[ 'price' ],//sku折扣价(默认等于单价)
-// 'stock' => $carmichael,
- 'stock_alarm' => $item[ 'stock_alarm' ],
- 'sku_image' => !empty($item[ 'sku_image' ]) ? $item[ 'sku_image' ] : $first_image,
- 'sku_images' => $item[ 'sku_images' ],
- 'goods_id' => $goods_id,
- 'is_default' => $item[ 'is_default' ] ?? 0,
- 'is_consume_discount' => $data[ 'is_consume_discount' ]
- );
- $sku_data = array_merge($sku_data, $common_data);
- if (!empty($item[ 'sku_id' ]) && in_array($item[ 'sku_id' ], $sku_id_arr)) {
- $sku_id = $item[ 'sku_id' ];
- model('goods_sku')->update($sku_data, [ [ 'sku_id', '=', $sku_id ] ]);
- unset($sku_id_arr[ $sku_id ]);
- } else {
- $sku_id = model('goods_sku')->add($sku_data);
- }
-
- // 添加到虚拟商品表
- if (isset($item[ 'carmichael' ])) {
- if (is_array($item[ 'carmichael' ]) && count($item[ 'carmichael' ])) {
- $goods_stock += count($item[ 'carmichael' ]);
- $virtual_goods = [];
- foreach ($item[ 'carmichael' ] as $carmichael_item) {
- $carmichael_item = htmlspecialchars(addslashes($carmichael_item));
- $card = explode(' ', $carmichael_item);
- $card_arr = [
- 'cardno' => $card[ 0 ] ?? '',
- 'password' => $card[ 1 ] ?? ''
- ];
- $virtual_goods[] = [
- 'site_id' => $data[ 'site_id' ],
- 'sku_id' => $sku_id,
- 'sku_name' => $data[ 'goods_name' ] . ' ' . $item[ 'spec_name' ],
- 'card_info' => json_encode($card_arr),
- 'goods_id' => $goods_id
- ];
- }
- model('goods_virtual')->addList($virtual_goods);
- }
- }
- }
- //删除已经不存在的sku
- if (!empty($sku_id_arr)) {
- $check = $this->checkGoodsIsExistsOrder([ 'site_id' => $data[ 'site_id' ], 'goods_id' => $goods_id, 'sku_id' => implode(",", $sku_id_arr) ]);
- if ($check[ 'code' ] < 0) {
- model('goods')->rollback();
- return $check;
- }
- model('goods_sku')->delete([ [ 'sku_id', 'in', $sku_id_arr ] ]);
- }
- } else {
- $discount_model = new Discount();
- $sku_id_arr = [];
- foreach ($data[ 'goods_sku_data' ] as $item) {
- $discount_info = [];
- if (!empty($item[ 'sku_id' ])) {
- $discount_info_result = $discount_model->getDiscountGoodsInfo([ [ 'pdg.sku_id', '=', $item[ 'sku_id' ] ], [ 'pd.status', '=', 1 ] ], 'id');
- $discount_info = $discount_info_result[ 'data' ];
- }
-
- $carmichael = 0;
- if (isset($item[ 'carmichael' ])) {
- if (is_array($item[ 'carmichael' ])) {
- $carmichael = count($item[ 'carmichael' ]);
- }
- }
-
- $sku_data = array (
- 'sku_name' => $data[ 'goods_name' ] . ' ' . $item[ 'spec_name' ],
- 'spec_name' => $item[ 'spec_name' ],
- 'sku_no' => $item[ 'sku_no' ],
- 'sku_spec_format' => !empty($item[ 'sku_spec_format' ]) ? json_encode($item[ 'sku_spec_format' ]) : "",
- 'price' => $item[ 'price' ],
- 'market_price' => $item[ 'market_price' ],
- 'cost_price' => $item[ 'cost_price' ],
-// 'stock' => $carmichael,
- 'stock_alarm' => $item[ 'stock_alarm' ],
- 'sku_image' => !empty($item[ 'sku_image' ]) ? $item[ 'sku_image' ] : $first_image,
- 'sku_images' => $item[ 'sku_images' ],
- 'goods_id' => $goods_id,
- 'is_default' => $item[ 'is_default' ] ?? 0,
- 'is_consume_discount' => $data[ 'is_consume_discount' ]
- );
- if (empty($discount_info)) {
- $sku_data[ 'discount_price' ] = $item[ 'price' ];
- }
- if (!empty($item[ 'sku_id' ])) {
- $sku_id = $item[ 'sku_id' ];
- $sku_id_arr[] = $item[ 'sku_id' ];
- model('goods_sku')->update(array_merge($sku_data, $common_data), [ [ 'sku_id', '=', $item[ 'sku_id' ] ], [ 'goods_class', '=', $this->goods_class[ 'id' ] ] ]);
- } else {
- $sku_id = model('goods_sku')->add(array_merge($sku_data, $common_data));
- $sku_id_arr[] = $sku_id;
- }
-
- // 添加到虚拟商品表
- if (isset($item[ 'carmichael' ])) {
- if (is_array($item[ 'carmichael' ]) && count($item[ 'carmichael' ])) {
- $goods_stock += count($item[ 'carmichael' ]);
- $virtual_goods = [];
- foreach ($item[ 'carmichael' ] as $carmichael_item) {
- $carmichael_item = htmlspecialchars(addslashes($carmichael_item));
- $card = explode(' ', $carmichael_item);
- $card_arr = [
- 'cardno' => $card[ 0 ] ?? '',
- 'password' => $card[ 1 ] ?? ''
- ];
- $virtual_goods[] = [
- 'site_id' => $data[ 'site_id' ],
- 'sku_id' => $sku_id,
- 'sku_name' => $data[ 'goods_name' ] . ' ' . $item[ 'spec_name' ],
- 'card_info' => json_encode($card_arr),
- 'goods_id' => $goods_id
- ];
- }
- model('goods_virtual')->addList($virtual_goods);
- }
- }
- }
-
- // 移除不存在的商品SKU
- $sku_id_list = model('goods_sku')->getList([ [ 'goods_id', '=', $goods_id ] ], 'sku_id');
- $sku_id_list = array_column($sku_id_list, 'sku_id');
- foreach ($sku_id_list as $k => $v) {
- foreach ($sku_id_arr as $ck => $cv) {
- if ($v == $cv) {
- unset($sku_id_list[ $k ]);
- }
- }
- }
-
- $sku_id_list = array_values($sku_id_list);
- if (!empty($sku_id_list)) {
- $check = $this->checkGoodsIsExistsOrder([ 'site_id' => $data[ 'site_id' ], 'goods_id' => $goods_id, 'sku_id' => implode(",", $sku_id_list) ]);
- if ($check[ 'code' ] < 0) {
- model('goods')->rollback();
- return $check;
- }
- model('goods_sku')->delete([ [ 'sku_id', 'in', implode(",", $sku_id_list) ] ]);
- }
- }
-
- } else {
- $check = $this->checkGoodsIsExistsOrder([ 'site_id' => $data[ 'site_id' ], 'goods_id' => $goods_id ]);
- if ($check[ 'code' ] < 0) {
- model('goods')->rollback();
- return $check;
- }
-
- model('goods_sku')->delete([ [ 'goods_id', '=', $goods_id ] ]);
-
- $sku_arr = array ();
- //添加sku商品
- foreach ($data[ 'goods_sku_data' ] as $item) {
- $sku_data = array (
- 'sku_name' => $data[ 'goods_name' ] . ' ' . $item[ 'spec_name' ],
- 'spec_name' => $item[ 'spec_name' ],
- 'sku_no' => $item[ 'sku_no' ],
- 'sku_spec_format' => !empty($item[ 'sku_spec_format' ]) ? json_encode($item[ 'sku_spec_format' ]) : "",
- 'price' => $item[ 'price' ],
- 'market_price' => $item[ 'market_price' ],
- 'cost_price' => $item[ 'cost_price' ],
- 'discount_price' => $item[ 'price' ],//sku折扣价(默认等于单价)
-// 'stock' => $item[ 'stock' ],
- 'stock_alarm' => $item[ 'stock_alarm' ],
- 'sku_image' => !empty($item[ 'sku_image' ]) ? $item[ 'sku_image' ] : $first_image,
- 'sku_images' => $item[ 'sku_images' ],
- 'goods_id' => $goods_id,
- 'is_default' => $item[ 'is_default' ] ?? 0,
- 'is_consume_discount' => $data[ 'is_consume_discount' ]
- );
- $sku_data = array_merge($sku_data, $common_data);
- $sku_id = model('goods_sku')->add($sku_data);
-
- // 添加到虚拟商品表
- if (isset($item[ 'carmichael' ]) && is_array($item[ 'carmichael' ]) && count($item[ 'carmichael' ])) {
- $goods_stock += count($item[ 'carmichael' ]);
- $virtual_goods = [];
- foreach ($item[ 'carmichael' ] as $carmichael_item) {
- $carmichael_item = htmlspecialchars(addslashes($carmichael_item));
- $card = explode(' ', $carmichael_item);
- $card_arr = [
- 'cardno' => $card[ 0 ] ?? '',
- 'password' => $card[ 1 ] ?? ''
- ];
- $virtual_goods[] = [
- 'site_id' => $data[ 'site_id' ],
- 'sku_id' => $sku_id,
- 'sku_name' => $data[ 'goods_name' ] . ' ' . $item[ 'spec_name' ],
- 'card_info' => json_encode($card_arr),
- 'goods_id' => $goods_id
- ];
- }
- model('goods_virtual')->addList($virtual_goods);
- }
- }
- }
-
- // 赋值第一个商品sku_id
- $first_info = model('goods_sku')->getFirstData([ 'goods_id' => $goods_id ], 'sku_id', 'is_default desc,sku_id asc');
- model('goods')->update([ 'sku_id' => $first_info[ 'sku_id' ] ], [ [ 'goods_id', '=', $goods_id ] ]);
-
- if (!empty($data[ 'goods_spec_format' ])) {
- // 刷新SKU商品规格项 / 规格值JSON字符串
- $this->dealGoodsSkuSpecFormat($goods_id, $data[ 'goods_spec_format' ]);
- }
-
- $cron = new Cron();
- $cron->deleteCron([ [ 'event', '=', 'CronGoodsTimerOn' ], [ 'relate_id', '=', $goods_id ] ]);
- $cron->deleteCron([ [ 'event', '=', 'CronGoodsTimerOff' ], [ 'relate_id', '=', $goods_id ] ]);
- //定时上下架
- if ($goods_data[ 'timer_on' ] > 0) {
- $cron->addCron(1, 0, "商品定时上架", "CronGoodsTimerOn", $goods_data[ 'timer_on' ], $goods_id);
- }
- if ($goods_data[ 'timer_off' ] > 0) {
- $cron->addCron(1, 0, "商品定时下架", "CronGoodsTimerOff", $goods_data[ 'timer_off' ], $goods_id);
- }
-
- $this->statisticsStock($goods_id);
-
- model('goods')->commit();
- return $this->success($goods_id);
- } catch (\Exception $e) {
- model('goods')->rollback();
- return $this->error($e->getMessage() . $e->getFile() . $e->getLine());
- }
- }
-
- /**
- * 获取商品详情
- * @param $goods_id
- * @return array
- */
- public function getGoodsDetail($goods_id, $site_id)
- {
- $info = model('goods')->getInfo([ [ 'is_delete', '=', 0 ], [ 'goods_id', '=', $goods_id ], [ 'site_id', '=', $site_id ], [ 'goods_class', '=', 3 ] ], "*");
- $field = 'sku_id, sku_name,spec_name, sku_no, sku_spec_format, price, market_price, cost_price, discount_price, stock,
- weight, volume, sku_image, sku_images, sort,member_price,fenxiao_price';
- $sku_data = model('goods_sku')->getList([ [ 'goods_id', '=', $goods_id ] ], $field);
-
- if (!empty($sku_data)) {
- foreach ($sku_data as $k => $v) {
- $sku_data[ $k ][ 'member_price' ] = $v[ 'member_price' ] == '' ? '' : json_decode($v[ 'member_price' ], true);
- $sku_data[ $k ][ 'stock' ] = numberFormat($sku_data[ $k ][ 'stock' ]);
- }
- }
- if (!empty($info)) {
- if (isset($info[ 'goods_stock' ])) {
- $info[ 'goods_stock' ] = numberFormat($info[ 'goods_stock' ]);
- }
- if (isset($info[ 'sale_num' ])) {
- $info[ 'sale_num' ] = numberFormat($info[ 'sale_num' ]);
- }
- if (isset($info[ 'virtual_sale' ])) {
- $info[ 'virtual_sale' ] = numberFormat($info[ 'virtual_sale' ]);
- }
- if (isset($info[ 'real_stock' ])) {
- $info[ 'real_stock' ] = numberFormat($info[ 'real_stock' ]);
- }
- $info[ 'sku_data' ] = $sku_data;
- }
- return $this->success($info);
- }
-
- /**
- * 刷新SKU商品规格项/规格值JSON字符串
- * @param int $goods_id 商品id
- * @param string $goods_spec_format 商品完整规格项/规格值json
- */
- private function dealGoodsSkuSpecFormat($goods_id, $goods_spec_format)
- {
- if (empty($goods_spec_format)) return;
-
- $goods_spec_format = json_decode($goods_spec_format, true);
-
- //根据goods_id查询sku商品列表,查询:sku_id、sku_spec_format 列
- $sku_list = model('goods_sku')->getList([ [ 'goods_id', '=', $goods_id ], [ 'sku_spec_format', '<>', '' ] ], 'sku_id,sku_spec_format', 'sku_id asc');
- if (!empty($sku_list)) {
-
-// $temp = 0;//测试性能,勿删
-
- //循环SKU商品列表
- foreach ($sku_list as $k => $v) {
-// $temp++;
-
- $sku_format = $goods_spec_format;//最终要存储的值
- $current_format = json_decode($v[ 'sku_spec_format' ], true);//当前SKU商品规格值json
-
- $selected_data = [];//已选规格/规格值json
-
- //1、找出已选规格/规格值json
-
- //循环完整商品规格json
- foreach ($sku_format as $sku_k => $sku_v) {
-// $temp++;
-
- //循环当前SKU商品规格json
- foreach ($current_format as $current_k => $current_v) {
-// $temp++;
-
- //匹配规格项
- if ($current_v[ 'spec_id' ] == $sku_v[ 'spec_id' ]) {
-
- //循环规格值
- foreach ($sku_v[ 'value' ] as $sku_value_k => $sku_value_v) {
-// $temp++;
-
- //匹配规格值id
- if ($current_v[ 'spec_value_id' ] == $sku_value_v[ 'spec_value_id' ]) {
- $sku_format[ $sku_k ][ 'value' ][ $sku_value_k ][ 'selected' ] = true;
- $sku_format[ $sku_k ][ 'value' ][ $sku_value_k ][ 'sku_id' ] = $v[ 'sku_id' ];
- $selected_data[] = $sku_format[ $sku_k ][ 'value' ][ $sku_value_k ];
- break;
- }
- }
-
- }
-
- }
- }
-
- //2、找出未选中的规格/规格值json
- foreach ($sku_format as $sku_k => $sku_v) {
-// $temp++;
-
- foreach ($sku_v[ 'value' ] as $sku_value_k => $sku_value_v) {
-// $temp++;
-
- if (!isset($sku_value_v[ 'selected' ])) {
-
- $refer_data = [];//参考已选中的规格/规格值json
- $refer_data[] = $sku_value_v;
-
-// 根据已选中的规格值进行参考
- foreach ($selected_data as $selected_k => $selected_v) {
-// $temp++;
-// 排除自身,然后进行参考
- if ($selected_v[ 'spec_id' ] != $sku_value_v[ 'spec_id' ]) {
- $refer_data[] = $selected_v;
- }
- }
-
- foreach ($sku_list as $again_k => $again_v) {
-// $temp++;
-
- //排除当前SKU商品
- if ($again_v[ 'sku_id' ] != $v[ 'sku_id' ]) {
-
- $current_format_again = json_decode($again_v[ 'sku_spec_format' ], true);
- $count = count($current_format_again);//规格总数量
- $curr_count = 0;//当前匹配规格数量
-
- //循环当前SKU商品规格json
- foreach ($current_format_again as $current_again_k => $current_again_v) {
-// $temp++;
-
- foreach ($refer_data as $fan_k => $fan_v) {
-// $temp++;
-
- if ($current_again_v[ 'spec_value_id' ] == $fan_v[ 'spec_value_id' ]) {
- $curr_count++;
- }
- }
-
- }
-
-// 匹配数量跟规格总数一致表示匹配成功
- if ($curr_count == $count) {
- $sku_format[ $sku_k ][ 'value' ][ $sku_value_k ][ 'selected' ] = false;
- $sku_format[ $sku_k ][ 'value' ][ $sku_value_k ][ 'sku_id' ] = $again_v[ 'sku_id' ];
- break;
- }
- }
-
- }
-
- //没有匹配到规格值,则禁用
- if (!isset($sku_format[ $sku_k ][ 'value' ][ $sku_value_k ][ 'selected' ])) {
- $sku_format[ $sku_k ][ 'value' ][ $sku_value_k ][ 'disabled' ] = false;
- }
-
- }
- }
- }
-
-// var_dump($sku_format);
-// var_dump("=========");
- //修改ns_goods_sku表表中的goods_spec_format字段,将$sku_format值传入
- model('goods_sku')->update([ 'goods_spec_format' => json_encode($sku_format) ], [ [ 'sku_id', '=', $v[ 'sku_id' ] ] ]);
-
- }
-
-// var_dump("性能:" . $temp);
-
- }
-
- }
-
- /************************************************************************* 购买的虚拟产品 start *******************************************************************/
- /**
- * 生成购买的虚拟产品
- * @param $site_id
- * @param $order_id
- * @param $order_no
- * @param $sku_id
- * @param $sku_name
- * @param $code
- * @param $member_id
- * @param $sku_image
- */
- public function addGoodsVirtual($site_id, $goods_id, $sku_id, $data)
- {
- if (is_array($data) && count($data)) {
- $virtual_goods = [];
- foreach ($data as $carmichael_item) {
- $carmichael_item = htmlspecialchars(addslashes($carmichael_item));
- $card = explode(' ', $carmichael_item);
- $card_arr = [
- 'cardno' => $card[ 0 ] ?? '',
- 'password' => $card[ 1 ] ?? ''
- ];
- $virtual_goods[] = [
- 'site_id' => $site_id,
- 'sku_id' => $sku_id,
- 'card_info' => json_encode($card_arr),
- 'goods_id' => $goods_id
- ];
- }
- model("goods_virtual")->startTrans();
- try {
- $res = model("goods_virtual")->addList($virtual_goods);
-// model('goods')->setInc([ [ 'goods_id', '=', $goods_id ], [ 'site_id', '=', $site_id ] ], 'goods_stock', count($virtual_goods)); // 增加商品总库存
-// model('goods_sku')->setInc([ [ 'sku_id', '=', $sku_id ], [ 'site_id', '=', $site_id ] ], 'stock', count($virtual_goods)); // 增加sku库存
- //同步计算卡密库存数据
- $this->statisticsStock($goods_id);
- model("goods_virtual")->commit();
- return $this->success($res);
- } catch (\Exception $e) {
- model("goods_virtual")->rollback();
- return $this->error('', $e->getMessage());
- }
- } else {
- return $this->error('', '请输入要添加的卡密数据');
- }
- }
-
- /**
- * 编辑卡密数据
- * @param $data
- * @param $condition
- * @return array
- */
- public function updateGoodsVirtual($data, $condition)
- {
- $res = model("goods_virtual")->update($data, $condition);
- return $this->success();
- }
-
- /**
- * 删除
- * @param $condition
- */
- public function deleteGoodsVirtual($condition)
- {
- $res = model("goods_virtual")->delete($condition);
- if ($res === false)
- return $this->error();
-
- $check_condition = array_column($condition, 2, 0);
- $goods_id = $check_condition[ 'goods_id' ] ?? 0;
- if ($goods_id) $this->statisticsStock($goods_id);
-
- return $this->success();
- }
-
-
- /**
- * 虚拟商品详情
- * @param $condition
- */
- public function getVirtualGoodsInfo($condition, $field = "*")
- {
- $info = model('goods_virtual')->getInfo($condition, $field);
- return $this->success($info);
- }
-
- /**
- * 获取虚拟商品分页列表
- * @param array $condition
- * @param number $page
- * @param string $page_size
- * @param string $order
- * @param string $field
- */
- public function getVirtualGoodsPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'id desc', $field = '*', $alias = 'a', $join = null)
- {
- $list = model('goods_virtual')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
- return $this->success($list);
- }
-
- /**
- * 卡券数量
- * @param $condition
- */
- public function getVirtualGoodsCount($condition, $field = "*")
- {
- $count = model('goods_virtual')->getCount($condition, $field);
- return $this->success($count);
- }
- /************************************************************************* 购买的虚拟产品 end *******************************************************************/
-
- /**
- * 从excel中读取卡密数据
- * @param $path
- */
- public function importData($path)
- {
- $PHPReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx');
- //载入文件
- $PHPExcel = $PHPReader->load($path);
-
- //获取表中的第一个工作表,如果要获取第二个,把0改为1,依次类推
- $currentSheet = $PHPExcel->getSheet(0);
-
- //获取总行数
- $allRow = $currentSheet->getHighestRow();
-
- if ($allRow < 2) {
- return $this->error('', '导入了一个空文件');
- }
- $data = [];
- for ($i = 2; $i <= $allRow; $i++) {
- //卡号
- $cardno = $PHPExcel->getActiveSheet()->getCell('A' . $i)->getValue();
- //卡号
- $password = $PHPExcel->getActiveSheet()->getCell('B' . $i)->getValue();
- $data[] = $cardno . ' ' . $password;
- }
- return $this->success(implode("\n", $data));
- }
-
- /**
- * 重新统计库存
- * @param $goods_id
- */
- public function statisticsStock($goods_id)
- {
- try {
- model('goods_sku')->startTrans();
- $goods_sku_list = model('goods_sku')->getList([ [ 'goods_id', '=', $goods_id ] ], 'sku_id,goods_class,site_id');
- $goods_sku_ids = array_column($goods_sku_list, 'sku_id');
- // 先删除已不存在的sku
- model('goods_virtual')->delete([ [ 'order_id', '=', 0 ], [ 'goods_id', '=', $goods_id ], [ 'sku_id', 'not in', $goods_sku_ids ] ]);
- // 重新统计sku的库存
-
- $site_id = 0;
- $stock_sku_list = [];
- foreach ($goods_sku_list as $v) {
- $site_id = $v[ 'site_id' ];
- $sku_id = $v[ 'sku_id' ];
- $sku_stock = model('goods_virtual')->getCount([ [ 'order_id', '=', 0 ], [ 'goods_id', '=', $goods_id ], [ 'sku_id', '=', $sku_id ] ]);
-// model('goods_sku')->update([ 'stock' => $sku_stock ], [ [ 'goods_id', '=', $goods_id ], [ 'sku_id', '=', $sku_id ] ]);
- $stock_sku_list[] = [ 'sku_id' => $sku_id, 'stock' => $sku_stock, 'goods_class' => $v[ 'goods_class' ] ];
- }
- //设置库存
- $goods_stock_model = new GoodsStock();
- $result = $goods_stock_model->changeGoodsStock([
- 'site_id' => $site_id,
- 'goods_sku_list' => $stock_sku_list
- ]);
- // 重新统计spu的库存
-// $goods_stock = model('goods_sku')->getSum([ [ 'goods_id', '=', $goods_id ] ], 'stock');
-// model('goods')->update([ 'goods_stock' => $goods_stock ], [ [ 'goods_id', '=', $goods_id ] ]);
- model('goods_sku')->commit();
- } catch (\Exception $e) {
- model('goods_sku')->rollback();
- }
- }
-
- /**
- * 商品导入
- * @param $goods_data
- * @param $site_id
- * @return array
- */
- public function importGoods($goods_data, $site_id)
- {
- try {
- if (empty($goods_data[ 'goods_name' ])) return $this->error('', '商品名称不能为空');
- if (empty($goods_data[ 'goods_image' ])) return $this->error('', '商品主图不能为空');
- if (empty($goods_data[ 'category_1' ]) && empty($goods_data[ 'category_2' ]) && empty($goods_data[ 'category_3' ])) return $this->error('', '商品分类不能为空');
-
- // 处理商品分类
- $category_id = '';
- $category_json = [];
- if (!empty($goods_data[ 'category_3' ])) {
- $category_info = model('goods_category')->getInfo([ [ 'level', '=', 3 ], [ 'site_id', '=', $site_id ], [ 'category_full_name', '=', "{$goods_data['category_1']}/{$goods_data['category_2']}/{$goods_data['category_3']}" ] ], 'category_id_1,category_id_2,category_id_3');
- if (!empty($category_info)) {
- $category_id = "{$category_info['category_id_1']},{$category_info['category_id_2']},{$category_info['category_id_3']}";
- }
- }
- if (!empty($goods_data[ 'category_2' ]) && empty($category_id)) {
- $category_info = model('goods_category')->getInfo([ [ 'level', '=', 2 ], [ 'site_id', '=', $site_id ], [ 'category_full_name', '=', "{$goods_data['category_1']}/{$goods_data['category_2']}" ] ], 'category_id_1,category_id_2');
- if (!empty($category_info)) {
- $category_id = "{$category_info['category_id_1']},{$category_info['category_id_2']}";
- }
- }
- if (!empty($goods_data[ 'category_1' ]) && empty($category_id)) {
- $category_info = model('goods_category')->getInfo([ [ 'level', '=', 1 ], [ 'site_id', '=', $site_id ], [ 'category_name', '=', "{$goods_data['category_1']}" ] ], 'category_id_1');
- if (!empty($category_info)) {
- $category_id = "{$category_info['category_id_1']}";
- }
- }
- if (empty($category_id)) return $this->error('', '未找到所填商品分类');
- $category_json = [ $category_id ];
-
- $sku_data = [];
- $goods_spec_format = [];
- $tag = 0;
- // 处理sku数据
- if (isset($goods_data[ 'sku' ])) {
- foreach ($goods_data[ 'sku' ] as $sku_item) {
- if (empty($sku_item[ 'sku_data' ])) return $this->error('', '规格数据不能为空');
-
- $spec_name = '';
- $spec_data = explode(';', $sku_item[ 'sku_data' ]);
-
- $sku_spec_format = [];
- foreach ($spec_data as $item) {
- $spec_item = explode(':', $item);
- $spec_name .= ' ' . $spec_item[ 1 ];
-
- // 规格项
- $spec_index = array_search($spec_item[ 0 ], array_column($goods_spec_format, 'spec_name'));
- if (empty($goods_spec_format) || $spec_index === false) {
- $spec = [
- 'spec_id' => -( $tag + getMillisecond() ),
- 'spec_name' => $spec_item[ 0 ],
- 'value' => []
- ];
- $goods_spec_format[] = $spec;
- $tag++;
- } else {
- $spec = $goods_spec_format[ $spec_index ];
- }
- // 规格值
- $spec_index = array_search($spec_item[ 0 ], array_column($goods_spec_format, 'spec_name'));
- $spec_value_index = array_search($spec_item[ 1 ], array_column($spec[ 'value' ], 'spec_value_name'));
- if (empty($spec[ 'value' ]) || $spec_value_index === false) {
- $spec_value = [
- 'spec_id' => $spec[ 'spec_id' ],
- 'spec_name' => $spec[ 'spec_name' ],
- 'spec_value_id' => -( $tag + getMillisecond() ),
- 'spec_value_name' => $spec_item[ 1 ],
- 'image' => '',
- ];
- $goods_spec_format[ $spec_index ][ 'value' ][] = $spec_value;
- $tag++;
- } else {
- $spec_value = $spec[ 'value' ][ $spec_value_index ];
- }
-
- $sku_spec_format[] = [
- 'spec_id' => $spec[ 'spec_id' ],
- 'spec_name' => $spec[ 'spec_name' ],
- 'spec_value_id' => $spec_value[ 'spec_value_id' ],
- 'spec_value_name' => $spec_value[ 'spec_value_name' ],
- 'image' => '',
- ];
- }
-
- $sku_images_arr = explode(',', $sku_item[ 'sku_image' ]);
-
- $sku_temp = [
- 'spec_name' => trim($spec_name),
- 'sku_no' => $sku_item[ 'sku_code' ],
- 'sku_spec_format' => $sku_spec_format,
- 'price' => $sku_item[ 'price' ],
- 'market_price' => $sku_item[ 'market_price' ],
- 'cost_price' => $sku_item[ 'cost_price' ],
- 'stock_alarm' => $sku_item[ 'stock_alarm' ],
- 'sku_image' => empty($sku_item[ 'sku_image' ]) ? '' : $sku_images_arr[ 0 ],
- 'sku_images' => empty($sku_item[ 'sku_image' ]) ? '' : $sku_item[ 'sku_image' ],
- 'sku_images_arr' => empty($sku_item[ 'sku_image' ]) ? [] : $sku_images_arr,
- 'is_default' => 0,
- 'carmichael' => empty($sku_item[ 'carmichael' ]) ? [] : explode("\n", $sku_item[ 'carmichael' ])
- ];
-
- $sku_data[] = $sku_temp;
- }
- } else {
- $goods_img = explode(',', $goods_data[ 'goods_image' ]);
- $sku_data = [
- [
- 'sku_id' => 0,
- 'sku_name' => $goods_data[ 'goods_name' ],
- 'spec_name' => '',
- 'sku_spec_format' => '',
- 'price' => empty($goods_data[ 'price' ]) ? 0 : $goods_data[ 'price' ],
- 'market_price' => empty($goods_data[ 'market_price' ]) ? 0 : $goods_data[ 'market_price' ],
- 'cost_price' => empty($goods_data[ 'cost_price' ]) ? 0 : $goods_data[ 'cost_price' ],
- 'sku_no' => $goods_data[ 'goods_code' ],
- 'stock_alarm' => empty($goods_data[ 'stock_alarm' ]) ? 0 : $goods_data[ 'stock_alarm' ],
- 'sku_image' => $goods_img[ 0 ],
- 'sku_images' => $goods_data[ 'goods_image' ],
- 'carmichael' => empty($goods_data[ 'carmichael' ]) ? [] : explode("\n", $goods_data[ 'carmichael' ])
- ]
- ];
- }
-
- if (count($goods_spec_format) > 4) return $this->error('', '最多支持四种规格项');
-
- $data = [
- 'goods_name' => $goods_data[ 'goods_name' ],// 商品名称,
- 'goods_attr_class' => '',// 商品类型id,
- 'goods_attr_name' => '',// 商品类型名称,
- 'site_id' => $site_id,
- 'category_id' => ',' . $category_id . ',',
- 'category_json' => json_encode($category_json),
- 'goods_image' => $goods_data[ 'goods_image' ],// 商品主图路径
- 'goods_content' => '',// 商品详情
- 'goods_state' => 0, //$goods_data['goods_state'] == 1 || $goods_data['goods_state'] == '是' ? 1 : 0,// 商品状态(1.正常0下架)
- 'price' => empty($goods_data[ 'price' ]) ? 0 : $goods_data[ 'price' ],// 商品价格(取第一个sku)
- 'market_price' => empty($goods_data[ 'market_price' ]) ? 0 : $goods_data[ 'market_price' ],// 市场价格(取第一个sku)
- 'cost_price' => empty($goods_data[ 'cost_price' ]) ? 0 : $goods_data[ 'cost_price' ],// 成本价(取第一个sku)
- 'sku_no' => $goods_data[ 'goods_code' ],// 商品sku编码
- 'goods_stock_alarm' => empty($goods_data[ 'goods_stock_alarm' ]) ? 0 : $goods_data[ 'goods_stock_alarm' ],// 库存预警
- 'goods_spec_format' => empty($goods_spec_format) ? '' : json_encode($goods_spec_format, JSON_UNESCAPED_UNICODE),// 商品规格格式
- 'goods_attr_format' => '',// 商品参数格式
- 'introduction' => $goods_data[ 'introduction' ],// 促销语
- 'keywords' => $goods_data[ 'keywords' ],// 关键词
- 'unit' => $goods_data[ 'unit' ],// 单位
- 'sort' => '',// 排序,
- 'qr_id' => empty($goods_data[ 'qr_id' ]) ? 0 : $goods_data[ 'qr_id' ],// 社群二维码id
- 'template_id' => empty($goods_data[ 'template_id' ]) ? 0 : $goods_data[ 'template_id' ],// 海报id
- 'is_limit' => empty($goods_data[ 'is_limit' ]) ? 0 : $goods_data[ 'is_limit' ],// 是否限购
- 'limit_type' => empty($goods_data[ 'limit_type' ]) ? 0 : $goods_data[ 'limit_type' ],// 限购类型
- 'video_url' => '',// 视频
- 'goods_sku_data' => json_encode($sku_data, JSON_UNESCAPED_UNICODE),// SKU商品数据
- 'goods_service_ids' => '',// 商品服务id集合
- 'label_id' => '',// 商品分组id
- 'virtual_sale' => 0,// 虚拟销量
- 'max_buy' => 0,// 限购
- 'min_buy' => 0,// 起售
- 'recommend_way' => 0, // 推荐方式,1:新品,2:精品,3;推荐
- 'timer_on' => 0,//定时上架
- 'timer_off' => 0,//定时下架
- 'brand_id' => 0,
- 'is_consume_discount' => $goods_data[ 'is_consume_discount' ] == 1 || $goods_data[ 'is_consume_discount' ] == '是' ? 1 : 0, //是否参与会员折扣
- ];
-
- $res = $this->addGoods($data);
- return $res;
- } catch (\Exception $e) {
- return $this->error('', $e->getMessage());
- }
- }
-
- /**
- * 检测商品是否存在未完成的订单
- * @param $params
- * @return array
- */
- public function checkGoodsIsExistsOrder($params)
- {
- $condition = [
- [ 'og.site_id', '=', $params[ 'site_id' ] ],
- [ 'og.goods_id', '=', $params[ 'goods_id' ] ],
- [ 'o.order_status', 'not in', [ -1, 10 ] ] // 排除订单状态 -1:已关闭,10:已完成
- ];
-
- if (!empty($params[ 'sku_id' ])) {
- $condition[] = [ 'og.sku_id', 'in', $params[ 'sku_id' ] ];
- }
-
- $join = [
- [ 'order o', 'o.order_id = og.order_id', 'left' ]
- ];
-
- $order_model = new OrderCommon();
- $res = $order_model->getOrderGoodsCount($condition, 'order_goods_id', 'og', $join);
- if ($res[ 'data' ] > 0) {
- return $this->error('', '该商品存在未完成的订单,无法删除规格项');
- }
- return $this->success();
-
- }
-
+ 3, 'name' => '电子卡密' );
+
+ private $goods_state = array (
+ 1 => '销售中',
+ 0 => '仓库中'
+ );
+
+ public function getGoodsState()
+ {
+ return $this->goods_state;
+ }
+
+ public function getGoodsClass()
+ {
+ return $this->goods_class;
+ }
+
+ /**
+ * 商品添加
+ * @param $data
+ */
+ public function addGoods($data)
+ {
+ model('goods')->startTrans();
+
+ try {
+
+ if (!empty($data[ 'goods_attr_format' ])) {
+
+ $goods_attr_format = json_decode($data[ 'goods_attr_format' ], true);
+ $keys = array_column($goods_attr_format, 'sort');
+ if (!empty($keys)) {
+ array_multisort($keys, SORT_ASC, SORT_NUMERIC, $goods_attr_format);
+ $data[ 'goods_attr_format' ] = json_encode($goods_attr_format);
+ }
+ }
+
+ $goods_image = $data[ 'goods_image' ];
+ $first_image = explode(",", $goods_image)[ 0 ];
+
+ //SKU商品数据
+ if (!empty($data[ 'goods_sku_data' ])) {
+ $data[ 'goods_sku_data' ] = json_decode($data[ 'goods_sku_data' ], true);
+ }
+
+ //获取标签名称
+ $label_name = '';
+ if ($data[ 'label_id' ]) {
+ $label_info = model('goods_label')->getInfo([ [ 'id', '=', $data[ 'label_id' ] ] ], 'label_name');
+ $label_name = $label_info[ 'label_name' ] ?? '';
+ }
+ $brand_name = '';
+ if ($data[ 'brand_id' ]) {
+ $brand_info = model('goods_brand')->getInfo([ [ 'brand_id', '=', $data[ 'brand_id' ] ] ], 'brand_name');
+ $brand_name = $brand_info[ 'brand_name' ] ?? '';
+ }
+ $goods_data = array (
+ 'goods_image' => $goods_image,
+ 'price' => $data[ 'goods_sku_data' ][ 0 ][ 'price' ],
+ 'market_price' => $data[ 'goods_sku_data' ][ 0 ][ 'market_price' ],
+ 'cost_price' => $data[ 'goods_sku_data' ][ 0 ][ 'cost_price' ],
+ 'goods_spec_format' => $data[ 'goods_spec_format' ],
+ 'category_id' => $data[ 'category_id' ],
+ 'category_json' => $data[ 'category_json' ],
+ 'label_id' => $data[ 'label_id' ],
+ 'label_name' => $label_name,
+ 'timer_on' => $data[ 'timer_on' ],
+ 'timer_off' => $data[ 'timer_off' ],
+ 'sale_show' => $data[ 'sale_show' ] ?? 1,
+ 'stock_show' => $data[ 'stock_show' ] ?? 1,
+ 'market_price_show' => $data[ 'market_price_show' ] ?? 1,
+ 'barrage_show' => $data[ 'barrage_show' ] ?? 1,
+ 'is_consume_discount' => $data[ 'is_consume_discount' ],
+ );
+
+ $common_data = array (
+ 'goods_name' => $data[ 'goods_name' ],
+ 'goods_class' => $this->goods_class[ 'id' ],
+ 'goods_class_name' => $this->goods_class[ 'name' ],
+ 'goods_attr_class' => $data[ 'goods_attr_class' ],
+ 'goods_attr_name' => $data[ 'goods_attr_name' ],
+ 'is_limit' => $data[ 'is_limit' ] ?? 0,
+ 'limit_type' => $data[ 'limit_type' ] ?? 1,
+ 'site_id' => $data[ 'site_id' ],
+ 'goods_content' => $data[ 'goods_content' ],
+ 'goods_state' => $data[ 'goods_state' ],
+ 'goods_stock_alarm' => $data[ 'goods_stock_alarm' ],
+ 'is_virtual' => 1,
+ 'virtual_indate' => 0,
+ 'goods_attr_format' => $data[ 'goods_attr_format' ],
+ 'introduction' => $data[ 'introduction' ],
+ 'keywords' => $data[ 'keywords' ],
+ 'unit' => $data[ 'unit' ],
+ 'brand_id' => $data[ 'brand_id' ],//品牌id
+ 'brand_name' => $brand_name,//品牌名称
+ 'video_url' => $data[ 'video_url' ],
+ 'sort' => $data[ 'sort' ],
+ 'goods_service_ids' => $data[ 'goods_service_ids' ],
+ 'create_time' => time(),
+ 'virtual_sale' => $data[ 'virtual_sale' ],
+ 'max_buy' => $data[ 'max_buy' ],
+ 'min_buy' => $data[ 'min_buy' ],
+ 'recommend_way' => $data[ 'recommend_way' ],
+ 'qr_id' => $data[ 'qr_id' ] ?? 0,
+ 'template_id' => $data[ 'template_id' ] ?? 0,
+ 'form_id' => $data[ 'form_id' ] ?? 0,
+ 'sale_channel' => $data[ 'sale_channel' ] ?? 'all',
+ 'sale_store' => $data[ 'sale_store' ] ?? 'all',
+ 'supplier_id' => $data[ 'supplier_id' ] ?? 0
+ );
+
+ $goods_id = model('goods')->add(array_merge($goods_data, $common_data));
+
+ $goods_stock = 0;
+
+ //添加sku商品
+ foreach ($data[ 'goods_sku_data' ] as $item) {
+// $carmichael = 0;
+// if (isset($item[ 'carmichael' ])) {
+// if (is_array($item[ 'carmichael' ])) {
+// $carmichael = count($item[ 'carmichael' ]);
+// }
+// }
+ $sku_data = array (
+ 'sku_name' => $data[ 'goods_name' ] . ' ' . $item[ 'spec_name' ],
+ 'spec_name' => $item[ 'spec_name' ],
+ 'sku_no' => $item[ 'sku_no' ],
+ 'sku_spec_format' => !empty($item[ 'sku_spec_format' ]) ? json_encode($item[ 'sku_spec_format' ]) : "",
+ 'price' => $item[ 'price' ],
+ 'market_price' => $item[ 'market_price' ],
+ 'cost_price' => $item[ 'cost_price' ],
+ 'discount_price' => $item[ 'price' ],//sku折扣价(默认等于单价)
+// 'stock' => $carmichael,
+ 'stock_alarm' => $item[ 'stock_alarm' ],
+ 'sku_image' => !empty($item[ 'sku_image' ]) ? $item[ 'sku_image' ] : $first_image,
+ 'sku_images' => $item[ 'sku_images' ],
+ 'goods_id' => $goods_id,
+ 'is_default' => $item[ 'is_default' ] ?? 0,
+ 'is_consume_discount' => $data[ 'is_consume_discount' ],
+ 'site_id' => $data[ 'site_id' ]
+ );
+ $sku_data = array_merge($sku_data, $common_data);
+ $sku_id = model('goods_sku')->add($sku_data);
+
+ // 添加到虚拟商品表
+ if (isset($item[ 'carmichael' ])) {
+ if (is_array($item[ 'carmichael' ]) && count($item[ 'carmichael' ])) {
+ $goods_stock += count($item[ 'carmichael' ]);
+ $virtual_goods = [];
+ foreach ($item[ 'carmichael' ] as $carmichael_item) {
+ $carmichael_item = htmlspecialchars(addslashes($carmichael_item));
+ $card = explode(' ', $carmichael_item);
+ $card_arr = [
+ 'cardno' => $card[ 0 ] ?? '',
+ 'password' => $card[ 1 ] ?? ''
+ ];
+ $virtual_goods[] = [
+ 'site_id' => $data[ 'site_id' ],
+ 'sku_id' => $sku_id,
+ 'sku_name' => $data[ 'goods_name' ] . ' ' . $item[ 'spec_name' ],
+ 'card_info' => json_encode($card_arr),
+ 'goods_id' => $goods_id
+ ];
+ }
+ model('goods_virtual')->addList($virtual_goods);
+ }
+ }
+ }
+
+ // 赋值第一个商品sku_id
+ $first_info = model('goods_sku')->getFirstData([ 'goods_id' => $goods_id ], 'sku_id', 'is_default desc,sku_id asc');
+ model('goods')->update([ 'sku_id' => $first_info[ 'sku_id' ] ], [ [ 'goods_id', '=', $goods_id ] ]);
+
+ if (!empty($data[ 'goods_spec_format' ])) {
+ // 刷新SKU商品规格项 / 规格值JSON字符串
+ $this->dealGoodsSkuSpecFormat($goods_id, $data[ 'goods_spec_format' ]);
+ }
+
+ $cron = new Cron();
+ //定时上下架
+ if ($goods_data[ 'timer_on' ] > 0) {
+ $cron->addCron(1, 0, "商品定时上架", "CronGoodsTimerOn", $goods_data[ 'timer_on' ], $goods_id);
+ }
+ if ($goods_data[ 'timer_off' ] > 0) {
+ $cron->addCron(1, 0, "商品定时下架", "CronGoodsTimerOff", $goods_data[ 'timer_off' ], $goods_id);
+ }
+
+ //添加统计
+ $stat = new Stat();
+// $stat->addShopStat([ 'add_goods_count' => 1, 'site_id' => $data[ 'site_id' ] ]);
+ $stat->switchStat([ 'type' => 'add_goods', 'data' => [ 'add_goods_count' => 1, 'site_id' => $data[ 'site_id' ] ] ]);
+
+ //同步计算卡密库存数据
+ $this->statisticsStock($goods_id);
+ model('goods')->commit();
+
+ return $this->success($goods_id);
+ } catch (\Exception $e) {
+ model('goods')->rollback();
+ return $this->error($e->getMessage());
+ }
+ }
+
+ /**
+ * 商品编辑
+ * @param $data
+ */
+ public function editGoods($data)
+ {
+
+ model('goods')->startTrans();
+
+ try {
+
+ if (!empty($data[ 'goods_attr_format' ])) {
+
+ $goods_attr_format = json_decode($data[ 'goods_attr_format' ], true);
+ $keys = array_column($goods_attr_format, 'sort');
+ if (!empty($keys)) {
+ array_multisort($keys, SORT_ASC, SORT_NUMERIC, $goods_attr_format);
+ $data[ 'goods_attr_format' ] = json_encode($goods_attr_format);
+ }
+ }
+
+ $goods_id = $data[ 'goods_id' ];
+ $goods_image = $data[ 'goods_image' ];
+ $first_image = explode(",", $goods_image)[ 0 ];
+
+ //SKU商品数据
+ if (!empty($data[ 'goods_sku_data' ])) {
+ $data[ 'goods_sku_data' ] = json_decode($data[ 'goods_sku_data' ], true);
+ }
+
+ //获取标签名称
+ $label_name = '';
+ if ($data[ 'label_id' ]) {
+ $label_info = model('goods_label')->getInfo([ [ 'id', '=', $data[ 'label_id' ] ] ], 'label_name');
+ $label_name = $label_info[ 'label_name' ] ?? '';
+ }
+ $brand_name = '';
+ if ($data[ 'brand_id' ]) {
+ $brand_info = model('goods_brand')->getInfo([ [ 'brand_id', '=', $data[ 'brand_id' ] ] ], 'brand_name');
+ $brand_name = $brand_info[ 'brand_name' ] ?? '';
+ }
+ $goods_data = array (
+ 'goods_image' => $goods_image,
+ 'price' => $data[ 'goods_sku_data' ][ 0 ][ 'price' ],
+ 'market_price' => $data[ 'goods_sku_data' ][ 0 ][ 'market_price' ],
+ 'cost_price' => $data[ 'goods_sku_data' ][ 0 ][ 'cost_price' ],
+ 'goods_spec_format' => $data[ 'goods_spec_format' ],
+ 'category_id' => $data[ 'category_id' ],
+ 'category_json' => $data[ 'category_json' ],
+ 'label_id' => $data[ 'label_id' ],
+ 'label_name' => $label_name,
+ 'timer_on' => $data[ 'timer_on' ],
+ 'timer_off' => $data[ 'timer_off' ],
+ 'sale_show' => $data[ 'sale_show' ],
+ 'stock_show' => $data[ 'stock_show' ],
+ 'market_price_show' => $data[ 'market_price_show' ],
+ 'barrage_show' => $data[ 'barrage_show' ],
+ 'is_consume_discount' => $data[ 'is_consume_discount' ],
+ );
+
+ $common_data = array (
+ 'goods_name' => $data[ 'goods_name' ],
+ 'goods_class' => $this->goods_class[ 'id' ],
+ 'goods_class_name' => $this->goods_class[ 'name' ],
+ 'goods_attr_class' => $data[ 'goods_attr_class' ],
+ 'goods_attr_name' => $data[ 'goods_attr_name' ],
+ 'is_limit' => $data[ 'is_limit' ] ?? 0,
+ 'limit_type' => $data[ 'limit_type' ] ?? 1,
+ 'site_id' => $data[ 'site_id' ],
+ 'goods_content' => $data[ 'goods_content' ],
+ 'goods_state' => $data[ 'goods_state' ],
+ 'goods_stock_alarm' => $data[ 'goods_stock_alarm' ],
+ 'is_virtual' => 1,
+ 'virtual_indate' => 0,
+ 'goods_attr_format' => $data[ 'goods_attr_format' ],
+ 'introduction' => $data[ 'introduction' ],
+ 'keywords' => $data[ 'keywords' ],
+ 'unit' => $data[ 'unit' ],
+ 'video_url' => $data[ 'video_url' ],
+ 'sort' => $data[ 'sort' ],
+ 'goods_service_ids' => $data[ 'goods_service_ids' ],
+ 'brand_id' => $data[ 'brand_id' ],//品牌id
+ 'brand_name' => $brand_name,//品牌名称
+ 'modify_time' => time(),
+ 'virtual_sale' => $data[ 'virtual_sale' ],
+ 'max_buy' => $data[ 'max_buy' ],
+ 'min_buy' => $data[ 'min_buy' ],
+ 'recommend_way' => $data[ 'recommend_way' ],
+ 'qr_id' => $data[ 'qr_id' ] ?? 0,
+ 'template_id' => $data[ 'template_id' ] ?? 0,
+ 'form_id' => $data[ 'form_id' ] ?? 0,
+ 'sale_channel' => $data[ 'sale_channel' ] ?? 'all',
+ 'sale_store' => $data[ 'sale_store' ] ?? 'all',
+ 'supplier_id' => $data[ 'supplier_id' ] ?? 0
+ );
+
+ model('goods')->update(array_merge($goods_data, $common_data), [ [ 'goods_id', '=', $goods_id ], [ 'goods_class', '=', $this->goods_class[ 'id' ] ] ]);
+
+ $goods_stock = 0;
+
+ // 如果只编辑价格库存就是修改,如果添加规格项/值就需要重新生成
+ if (!empty($data[ 'goods_sku_data' ][ 0 ][ 'sku_id' ])) {
+
+ if ($data[ 'spec_type_status' ] == 1) {
+ $sku_list = model('goods_sku')->getList([ [ 'goods_id', '=', $goods_id ] ], 'sku_id');
+ $sku_id_arr = array_column($sku_list, 'sku_id', 'sku_id');
+ //添加sku商品
+ foreach ($data[ 'goods_sku_data' ] as $item) {
+ $carmichael = 0;
+ if (isset($item[ 'carmichael' ])) {
+ if (is_array($item[ 'carmichael' ])) {
+ $carmichael = count($item[ 'carmichael' ]);
+ }
+ }
+ $sku_data = array (
+ 'sku_name' => $data[ 'goods_name' ] . ' ' . $item[ 'spec_name' ],
+ 'spec_name' => $item[ 'spec_name' ],
+ 'sku_no' => $item[ 'sku_no' ],
+ 'sku_spec_format' => !empty($item[ 'sku_spec_format' ]) ? json_encode($item[ 'sku_spec_format' ]) : "",
+ 'price' => $item[ 'price' ],
+ 'market_price' => $item[ 'market_price' ],
+ 'cost_price' => $item[ 'cost_price' ],
+ 'discount_price' => $item[ 'price' ],//sku折扣价(默认等于单价)
+// 'stock' => $carmichael,
+ 'stock_alarm' => $item[ 'stock_alarm' ],
+ 'sku_image' => !empty($item[ 'sku_image' ]) ? $item[ 'sku_image' ] : $first_image,
+ 'sku_images' => $item[ 'sku_images' ],
+ 'goods_id' => $goods_id,
+ 'is_default' => $item[ 'is_default' ] ?? 0,
+ 'is_consume_discount' => $data[ 'is_consume_discount' ]
+ );
+ $sku_data = array_merge($sku_data, $common_data);
+ if (!empty($item[ 'sku_id' ]) && in_array($item[ 'sku_id' ], $sku_id_arr)) {
+ $sku_id = $item[ 'sku_id' ];
+ model('goods_sku')->update($sku_data, [ [ 'sku_id', '=', $sku_id ] ]);
+ unset($sku_id_arr[ $sku_id ]);
+ } else {
+ $sku_id = model('goods_sku')->add($sku_data);
+ }
+
+ // 添加到虚拟商品表
+ if (isset($item[ 'carmichael' ])) {
+ if (is_array($item[ 'carmichael' ]) && count($item[ 'carmichael' ])) {
+ $goods_stock += count($item[ 'carmichael' ]);
+ $virtual_goods = [];
+ foreach ($item[ 'carmichael' ] as $carmichael_item) {
+ $carmichael_item = htmlspecialchars(addslashes($carmichael_item));
+ $card = explode(' ', $carmichael_item);
+ $card_arr = [
+ 'cardno' => $card[ 0 ] ?? '',
+ 'password' => $card[ 1 ] ?? ''
+ ];
+ $virtual_goods[] = [
+ 'site_id' => $data[ 'site_id' ],
+ 'sku_id' => $sku_id,
+ 'sku_name' => $data[ 'goods_name' ] . ' ' . $item[ 'spec_name' ],
+ 'card_info' => json_encode($card_arr),
+ 'goods_id' => $goods_id
+ ];
+ }
+ model('goods_virtual')->addList($virtual_goods);
+ }
+ }
+ }
+ //删除已经不存在的sku
+ if (!empty($sku_id_arr)) {
+ $check = $this->checkGoodsIsExistsOrder([ 'site_id' => $data[ 'site_id' ], 'goods_id' => $goods_id, 'sku_id' => implode(",", $sku_id_arr) ]);
+ if ($check[ 'code' ] < 0) {
+ model('goods')->rollback();
+ return $check;
+ }
+ model('goods_sku')->delete([ [ 'sku_id', 'in', $sku_id_arr ] ]);
+ }
+ } else {
+ $discount_model = new Discount();
+ $sku_id_arr = [];
+ foreach ($data[ 'goods_sku_data' ] as $item) {
+ $discount_info = [];
+ if (!empty($item[ 'sku_id' ])) {
+ $discount_info_result = $discount_model->getDiscountGoodsInfo([ [ 'pdg.sku_id', '=', $item[ 'sku_id' ] ], [ 'pd.status', '=', 1 ] ], 'id');
+ $discount_info = $discount_info_result[ 'data' ];
+ }
+
+ $carmichael = 0;
+ if (isset($item[ 'carmichael' ])) {
+ if (is_array($item[ 'carmichael' ])) {
+ $carmichael = count($item[ 'carmichael' ]);
+ }
+ }
+
+ $sku_data = array (
+ 'sku_name' => $data[ 'goods_name' ] . ' ' . $item[ 'spec_name' ],
+ 'spec_name' => $item[ 'spec_name' ],
+ 'sku_no' => $item[ 'sku_no' ],
+ 'sku_spec_format' => !empty($item[ 'sku_spec_format' ]) ? json_encode($item[ 'sku_spec_format' ]) : "",
+ 'price' => $item[ 'price' ],
+ 'market_price' => $item[ 'market_price' ],
+ 'cost_price' => $item[ 'cost_price' ],
+// 'stock' => $carmichael,
+ 'stock_alarm' => $item[ 'stock_alarm' ],
+ 'sku_image' => !empty($item[ 'sku_image' ]) ? $item[ 'sku_image' ] : $first_image,
+ 'sku_images' => $item[ 'sku_images' ],
+ 'goods_id' => $goods_id,
+ 'is_default' => $item[ 'is_default' ] ?? 0,
+ 'is_consume_discount' => $data[ 'is_consume_discount' ]
+ );
+ if (empty($discount_info)) {
+ $sku_data[ 'discount_price' ] = $item[ 'price' ];
+ }
+ if (!empty($item[ 'sku_id' ])) {
+ $sku_id = $item[ 'sku_id' ];
+ $sku_id_arr[] = $item[ 'sku_id' ];
+ model('goods_sku')->update(array_merge($sku_data, $common_data), [ [ 'sku_id', '=', $item[ 'sku_id' ] ], [ 'goods_class', '=', $this->goods_class[ 'id' ] ] ]);
+ } else {
+ $sku_id = model('goods_sku')->add(array_merge($sku_data, $common_data));
+ $sku_id_arr[] = $sku_id;
+ }
+
+ // 添加到虚拟商品表
+ if (isset($item[ 'carmichael' ])) {
+ if (is_array($item[ 'carmichael' ]) && count($item[ 'carmichael' ])) {
+ $goods_stock += count($item[ 'carmichael' ]);
+ $virtual_goods = [];
+ foreach ($item[ 'carmichael' ] as $carmichael_item) {
+ $carmichael_item = htmlspecialchars(addslashes($carmichael_item));
+ $card = explode(' ', $carmichael_item);
+ $card_arr = [
+ 'cardno' => $card[ 0 ] ?? '',
+ 'password' => $card[ 1 ] ?? ''
+ ];
+ $virtual_goods[] = [
+ 'site_id' => $data[ 'site_id' ],
+ 'sku_id' => $sku_id,
+ 'sku_name' => $data[ 'goods_name' ] . ' ' . $item[ 'spec_name' ],
+ 'card_info' => json_encode($card_arr),
+ 'goods_id' => $goods_id
+ ];
+ }
+ model('goods_virtual')->addList($virtual_goods);
+ }
+ }
+ }
+
+ // 移除不存在的商品SKU
+ $sku_id_list = model('goods_sku')->getList([ [ 'goods_id', '=', $goods_id ] ], 'sku_id');
+ $sku_id_list = array_column($sku_id_list, 'sku_id');
+ foreach ($sku_id_list as $k => $v) {
+ foreach ($sku_id_arr as $ck => $cv) {
+ if ($v == $cv) {
+ unset($sku_id_list[ $k ]);
+ }
+ }
+ }
+
+ $sku_id_list = array_values($sku_id_list);
+ if (!empty($sku_id_list)) {
+ $check = $this->checkGoodsIsExistsOrder([ 'site_id' => $data[ 'site_id' ], 'goods_id' => $goods_id, 'sku_id' => implode(",", $sku_id_list) ]);
+ if ($check[ 'code' ] < 0) {
+ model('goods')->rollback();
+ return $check;
+ }
+ model('goods_sku')->delete([ [ 'sku_id', 'in', implode(",", $sku_id_list) ] ]);
+ }
+ }
+
+ } else {
+ $check = $this->checkGoodsIsExistsOrder([ 'site_id' => $data[ 'site_id' ], 'goods_id' => $goods_id ]);
+ if ($check[ 'code' ] < 0) {
+ model('goods')->rollback();
+ return $check;
+ }
+
+ model('goods_sku')->delete([ [ 'goods_id', '=', $goods_id ] ]);
+
+ $sku_arr = array ();
+ //添加sku商品
+ foreach ($data[ 'goods_sku_data' ] as $item) {
+ $sku_data = array (
+ 'sku_name' => $data[ 'goods_name' ] . ' ' . $item[ 'spec_name' ],
+ 'spec_name' => $item[ 'spec_name' ],
+ 'sku_no' => $item[ 'sku_no' ],
+ 'sku_spec_format' => !empty($item[ 'sku_spec_format' ]) ? json_encode($item[ 'sku_spec_format' ]) : "",
+ 'price' => $item[ 'price' ],
+ 'market_price' => $item[ 'market_price' ],
+ 'cost_price' => $item[ 'cost_price' ],
+ 'discount_price' => $item[ 'price' ],//sku折扣价(默认等于单价)
+// 'stock' => $item[ 'stock' ],
+ 'stock_alarm' => $item[ 'stock_alarm' ],
+ 'sku_image' => !empty($item[ 'sku_image' ]) ? $item[ 'sku_image' ] : $first_image,
+ 'sku_images' => $item[ 'sku_images' ],
+ 'goods_id' => $goods_id,
+ 'is_default' => $item[ 'is_default' ] ?? 0,
+ 'is_consume_discount' => $data[ 'is_consume_discount' ]
+ );
+ $sku_data = array_merge($sku_data, $common_data);
+ $sku_id = model('goods_sku')->add($sku_data);
+
+ // 添加到虚拟商品表
+ if (isset($item[ 'carmichael' ]) && is_array($item[ 'carmichael' ]) && count($item[ 'carmichael' ])) {
+ $goods_stock += count($item[ 'carmichael' ]);
+ $virtual_goods = [];
+ foreach ($item[ 'carmichael' ] as $carmichael_item) {
+ $carmichael_item = htmlspecialchars(addslashes($carmichael_item));
+ $card = explode(' ', $carmichael_item);
+ $card_arr = [
+ 'cardno' => $card[ 0 ] ?? '',
+ 'password' => $card[ 1 ] ?? ''
+ ];
+ $virtual_goods[] = [
+ 'site_id' => $data[ 'site_id' ],
+ 'sku_id' => $sku_id,
+ 'sku_name' => $data[ 'goods_name' ] . ' ' . $item[ 'spec_name' ],
+ 'card_info' => json_encode($card_arr),
+ 'goods_id' => $goods_id
+ ];
+ }
+ model('goods_virtual')->addList($virtual_goods);
+ }
+ }
+ }
+
+ // 赋值第一个商品sku_id
+ $first_info = model('goods_sku')->getFirstData([ 'goods_id' => $goods_id ], 'sku_id', 'is_default desc,sku_id asc');
+ model('goods')->update([ 'sku_id' => $first_info[ 'sku_id' ] ], [ [ 'goods_id', '=', $goods_id ] ]);
+
+ if (!empty($data[ 'goods_spec_format' ])) {
+ // 刷新SKU商品规格项 / 规格值JSON字符串
+ $this->dealGoodsSkuSpecFormat($goods_id, $data[ 'goods_spec_format' ]);
+ }
+
+ $cron = new Cron();
+ $cron->deleteCron([ [ 'event', '=', 'CronGoodsTimerOn' ], [ 'relate_id', '=', $goods_id ] ]);
+ $cron->deleteCron([ [ 'event', '=', 'CronGoodsTimerOff' ], [ 'relate_id', '=', $goods_id ] ]);
+ //定时上下架
+ if ($goods_data[ 'timer_on' ] > 0) {
+ $cron->addCron(1, 0, "商品定时上架", "CronGoodsTimerOn", $goods_data[ 'timer_on' ], $goods_id);
+ }
+ if ($goods_data[ 'timer_off' ] > 0) {
+ $cron->addCron(1, 0, "商品定时下架", "CronGoodsTimerOff", $goods_data[ 'timer_off' ], $goods_id);
+ }
+
+ $this->statisticsStock($goods_id);
+
+ model('goods')->commit();
+ return $this->success($goods_id);
+ } catch (\Exception $e) {
+ model('goods')->rollback();
+ return $this->error($e->getMessage() . $e->getFile() . $e->getLine());
+ }
+ }
+
+ /**
+ * 获取商品详情
+ * @param $goods_id
+ * @return array
+ */
+ public function getGoodsDetail($goods_id, $site_id)
+ {
+ $info = model('goods')->getInfo([ [ 'is_delete', '=', 0 ], [ 'goods_id', '=', $goods_id ], [ 'site_id', '=', $site_id ], [ 'goods_class', '=', 3 ] ], "*");
+ $field = 'sku_id, sku_name,spec_name, sku_no, sku_spec_format, price, market_price, cost_price, discount_price, stock,
+ weight, volume, sku_image, sku_images, sort,member_price,fenxiao_price';
+ $sku_data = model('goods_sku')->getList([ [ 'goods_id', '=', $goods_id ] ], $field);
+
+ if (!empty($sku_data)) {
+ foreach ($sku_data as $k => $v) {
+ $sku_data[ $k ][ 'member_price' ] = $v[ 'member_price' ] == '' ? '' : json_decode($v[ 'member_price' ], true);
+ $sku_data[ $k ][ 'stock' ] = numberFormat($sku_data[ $k ][ 'stock' ]);
+ }
+ }
+ if (!empty($info)) {
+ if (isset($info[ 'goods_stock' ])) {
+ $info[ 'goods_stock' ] = numberFormat($info[ 'goods_stock' ]);
+ }
+ if (isset($info[ 'sale_num' ])) {
+ $info[ 'sale_num' ] = numberFormat($info[ 'sale_num' ]);
+ }
+ if (isset($info[ 'virtual_sale' ])) {
+ $info[ 'virtual_sale' ] = numberFormat($info[ 'virtual_sale' ]);
+ }
+ if (isset($info[ 'real_stock' ])) {
+ $info[ 'real_stock' ] = numberFormat($info[ 'real_stock' ]);
+ }
+ $info[ 'sku_data' ] = $sku_data;
+ }
+ return $this->success($info);
+ }
+
+ /**
+ * 刷新SKU商品规格项/规格值JSON字符串
+ * @param int $goods_id 商品id
+ * @param string $goods_spec_format 商品完整规格项/规格值json
+ */
+ private function dealGoodsSkuSpecFormat($goods_id, $goods_spec_format)
+ {
+ if (empty($goods_spec_format)) return;
+
+ $goods_spec_format = json_decode($goods_spec_format, true);
+
+ //根据goods_id查询sku商品列表,查询:sku_id、sku_spec_format 列
+ $sku_list = model('goods_sku')->getList([ [ 'goods_id', '=', $goods_id ], [ 'sku_spec_format', '<>', '' ] ], 'sku_id,sku_spec_format', 'sku_id asc');
+ if (!empty($sku_list)) {
+
+// $temp = 0;//测试性能,勿删
+
+ //循环SKU商品列表
+ foreach ($sku_list as $k => $v) {
+// $temp++;
+
+ $sku_format = $goods_spec_format;//最终要存储的值
+ $current_format = json_decode($v[ 'sku_spec_format' ], true);//当前SKU商品规格值json
+
+ $selected_data = [];//已选规格/规格值json
+
+ //1、找出已选规格/规格值json
+
+ //循环完整商品规格json
+ foreach ($sku_format as $sku_k => $sku_v) {
+// $temp++;
+
+ //循环当前SKU商品规格json
+ foreach ($current_format as $current_k => $current_v) {
+// $temp++;
+
+ //匹配规格项
+ if ($current_v[ 'spec_id' ] == $sku_v[ 'spec_id' ]) {
+
+ //循环规格值
+ foreach ($sku_v[ 'value' ] as $sku_value_k => $sku_value_v) {
+// $temp++;
+
+ //匹配规格值id
+ if ($current_v[ 'spec_value_id' ] == $sku_value_v[ 'spec_value_id' ]) {
+ $sku_format[ $sku_k ][ 'value' ][ $sku_value_k ][ 'selected' ] = true;
+ $sku_format[ $sku_k ][ 'value' ][ $sku_value_k ][ 'sku_id' ] = $v[ 'sku_id' ];
+ $selected_data[] = $sku_format[ $sku_k ][ 'value' ][ $sku_value_k ];
+ break;
+ }
+ }
+
+ }
+
+ }
+ }
+
+ //2、找出未选中的规格/规格值json
+ foreach ($sku_format as $sku_k => $sku_v) {
+// $temp++;
+
+ foreach ($sku_v[ 'value' ] as $sku_value_k => $sku_value_v) {
+// $temp++;
+
+ if (!isset($sku_value_v[ 'selected' ])) {
+
+ $refer_data = [];//参考已选中的规格/规格值json
+ $refer_data[] = $sku_value_v;
+
+// 根据已选中的规格值进行参考
+ foreach ($selected_data as $selected_k => $selected_v) {
+// $temp++;
+// 排除自身,然后进行参考
+ if ($selected_v[ 'spec_id' ] != $sku_value_v[ 'spec_id' ]) {
+ $refer_data[] = $selected_v;
+ }
+ }
+
+ foreach ($sku_list as $again_k => $again_v) {
+// $temp++;
+
+ //排除当前SKU商品
+ if ($again_v[ 'sku_id' ] != $v[ 'sku_id' ]) {
+
+ $current_format_again = json_decode($again_v[ 'sku_spec_format' ], true);
+ $count = count($current_format_again);//规格总数量
+ $curr_count = 0;//当前匹配规格数量
+
+ //循环当前SKU商品规格json
+ foreach ($current_format_again as $current_again_k => $current_again_v) {
+// $temp++;
+
+ foreach ($refer_data as $fan_k => $fan_v) {
+// $temp++;
+
+ if ($current_again_v[ 'spec_value_id' ] == $fan_v[ 'spec_value_id' ]) {
+ $curr_count++;
+ }
+ }
+
+ }
+
+// 匹配数量跟规格总数一致表示匹配成功
+ if ($curr_count == $count) {
+ $sku_format[ $sku_k ][ 'value' ][ $sku_value_k ][ 'selected' ] = false;
+ $sku_format[ $sku_k ][ 'value' ][ $sku_value_k ][ 'sku_id' ] = $again_v[ 'sku_id' ];
+ break;
+ }
+ }
+
+ }
+
+ //没有匹配到规格值,则禁用
+ if (!isset($sku_format[ $sku_k ][ 'value' ][ $sku_value_k ][ 'selected' ])) {
+ $sku_format[ $sku_k ][ 'value' ][ $sku_value_k ][ 'disabled' ] = false;
+ }
+
+ }
+ }
+ }
+
+// var_dump($sku_format);
+// var_dump("=========");
+ //修改ns_goods_sku表表中的goods_spec_format字段,将$sku_format值传入
+ model('goods_sku')->update([ 'goods_spec_format' => json_encode($sku_format) ], [ [ 'sku_id', '=', $v[ 'sku_id' ] ] ]);
+
+ }
+
+// var_dump("性能:" . $temp);
+
+ }
+
+ }
+
+ /************************************************************************* 购买的虚拟产品 start *******************************************************************/
+ /**
+ * 生成购买的虚拟产品
+ * @param $site_id
+ * @param $order_id
+ * @param $order_no
+ * @param $sku_id
+ * @param $sku_name
+ * @param $code
+ * @param $member_id
+ * @param $sku_image
+ */
+ public function addGoodsVirtual($site_id, $goods_id, $sku_id, $data)
+ {
+ if (is_array($data) && count($data)) {
+ $virtual_goods = [];
+ foreach ($data as $carmichael_item) {
+ $carmichael_item = htmlspecialchars(addslashes($carmichael_item));
+ $card = explode(' ', $carmichael_item);
+ $card_arr = [
+ 'cardno' => $card[ 0 ] ?? '',
+ 'password' => $card[ 1 ] ?? ''
+ ];
+ $virtual_goods[] = [
+ 'site_id' => $site_id,
+ 'sku_id' => $sku_id,
+ 'card_info' => json_encode($card_arr),
+ 'goods_id' => $goods_id
+ ];
+ }
+ model("goods_virtual")->startTrans();
+ try {
+ $res = model("goods_virtual")->addList($virtual_goods);
+// model('goods')->setInc([ [ 'goods_id', '=', $goods_id ], [ 'site_id', '=', $site_id ] ], 'goods_stock', count($virtual_goods)); // 增加商品总库存
+// model('goods_sku')->setInc([ [ 'sku_id', '=', $sku_id ], [ 'site_id', '=', $site_id ] ], 'stock', count($virtual_goods)); // 增加sku库存
+ //同步计算卡密库存数据
+ $this->statisticsStock($goods_id);
+ model("goods_virtual")->commit();
+ return $this->success($res);
+ } catch (\Exception $e) {
+ model("goods_virtual")->rollback();
+ return $this->error('', $e->getMessage());
+ }
+ } else {
+ return $this->error('', '请输入要添加的卡密数据');
+ }
+ }
+
+ /**
+ * 编辑卡密数据
+ * @param $data
+ * @param $condition
+ * @return array
+ */
+ public function updateGoodsVirtual($data, $condition)
+ {
+ $res = model("goods_virtual")->update($data, $condition);
+ return $this->success();
+ }
+
+ /**
+ * 删除
+ * @param $condition
+ */
+ public function deleteGoodsVirtual($condition)
+ {
+ $res = model("goods_virtual")->delete($condition);
+ if ($res === false)
+ return $this->error();
+
+ $check_condition = array_column($condition, 2, 0);
+ $goods_id = $check_condition[ 'goods_id' ] ?? 0;
+ if ($goods_id) $this->statisticsStock($goods_id);
+
+ return $this->success();
+ }
+
+
+ /**
+ * 虚拟商品详情
+ * @param $condition
+ */
+ public function getVirtualGoodsInfo($condition, $field = "*")
+ {
+ $info = model('goods_virtual')->getInfo($condition, $field);
+ return $this->success($info);
+ }
+
+ /**
+ * 获取虚拟商品分页列表
+ * @param array $condition
+ * @param number $page
+ * @param string $page_size
+ * @param string $order
+ * @param string $field
+ */
+ public function getVirtualGoodsPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'id desc', $field = '*', $alias = 'a', $join = null)
+ {
+ $list = model('goods_virtual')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
+ return $this->success($list);
+ }
+
+ /**
+ * 卡券数量
+ * @param $condition
+ */
+ public function getVirtualGoodsCount($condition, $field = "*")
+ {
+ $count = model('goods_virtual')->getCount($condition, $field);
+ return $this->success($count);
+ }
+ /************************************************************************* 购买的虚拟产品 end *******************************************************************/
+
+ /**
+ * 从excel中读取卡密数据
+ * @param $path
+ */
+ public function importData($path)
+ {
+ $PHPReader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader('Xlsx');
+ //载入文件
+ $PHPExcel = $PHPReader->load($path);
+
+ //获取表中的第一个工作表,如果要获取第二个,把0改为1,依次类推
+ $currentSheet = $PHPExcel->getSheet(0);
+
+ //获取总行数
+ $allRow = $currentSheet->getHighestRow();
+
+ if ($allRow < 2) {
+ return $this->error('', '导入了一个空文件');
+ }
+ $data = [];
+ for ($i = 2; $i <= $allRow; $i++) {
+ //卡号
+ $cardno = $PHPExcel->getActiveSheet()->getCell('A' . $i)->getValue();
+ //卡号
+ $password = $PHPExcel->getActiveSheet()->getCell('B' . $i)->getValue();
+ $data[] = $cardno . ' ' . $password;
+ }
+ return $this->success(implode("\n", $data));
+ }
+
+ /**
+ * 重新统计库存
+ * @param $goods_id
+ */
+ public function statisticsStock($goods_id)
+ {
+ try {
+ model('goods_sku')->startTrans();
+ $goods_sku_list = model('goods_sku')->getList([ [ 'goods_id', '=', $goods_id ] ], 'sku_id,goods_class,site_id');
+ $goods_sku_ids = array_column($goods_sku_list, 'sku_id');
+ // 先删除已不存在的sku
+ model('goods_virtual')->delete([ [ 'order_id', '=', 0 ], [ 'goods_id', '=', $goods_id ], [ 'sku_id', 'not in', $goods_sku_ids ] ]);
+ // 重新统计sku的库存
+
+ $site_id = 0;
+ $stock_sku_list = [];
+ foreach ($goods_sku_list as $v) {
+ $site_id = $v[ 'site_id' ];
+ $sku_id = $v[ 'sku_id' ];
+ $sku_stock = model('goods_virtual')->getCount([ [ 'order_id', '=', 0 ], [ 'goods_id', '=', $goods_id ], [ 'sku_id', '=', $sku_id ] ]);
+// model('goods_sku')->update([ 'stock' => $sku_stock ], [ [ 'goods_id', '=', $goods_id ], [ 'sku_id', '=', $sku_id ] ]);
+ $stock_sku_list[] = [ 'sku_id' => $sku_id, 'stock' => $sku_stock, 'goods_class' => $v[ 'goods_class' ] ];
+ }
+ //设置库存
+ $goods_stock_model = new GoodsStock();
+ $result = $goods_stock_model->changeGoodsStock([
+ 'site_id' => $site_id,
+ 'goods_sku_list' => $stock_sku_list
+ ]);
+ // 重新统计spu的库存
+// $goods_stock = model('goods_sku')->getSum([ [ 'goods_id', '=', $goods_id ] ], 'stock');
+// model('goods')->update([ 'goods_stock' => $goods_stock ], [ [ 'goods_id', '=', $goods_id ] ]);
+ model('goods_sku')->commit();
+ } catch (\Exception $e) {
+ model('goods_sku')->rollback();
+ }
+ }
+
+ /**
+ * 商品导入
+ * @param $goods_data
+ * @param $site_id
+ * @return array
+ */
+ public function importGoods($goods_data, $site_id)
+ {
+ try {
+ if (empty($goods_data[ 'goods_name' ])) return $this->error('', '商品名称不能为空');
+ if (empty($goods_data[ 'goods_image' ])) return $this->error('', '商品主图不能为空');
+ if (empty($goods_data[ 'category_1' ]) && empty($goods_data[ 'category_2' ]) && empty($goods_data[ 'category_3' ])) return $this->error('', '商品分类不能为空');
+
+ // 处理商品分类
+ $category_id = '';
+ $category_json = [];
+ if (!empty($goods_data[ 'category_3' ])) {
+ $category_info = model('goods_category')->getInfo([ [ 'level', '=', 3 ], [ 'site_id', '=', $site_id ], [ 'category_full_name', '=', "{$goods_data['category_1']}/{$goods_data['category_2']}/{$goods_data['category_3']}" ] ], 'category_id_1,category_id_2,category_id_3');
+ if (!empty($category_info)) {
+ $category_id = "{$category_info['category_id_1']},{$category_info['category_id_2']},{$category_info['category_id_3']}";
+ }
+ }
+ if (!empty($goods_data[ 'category_2' ]) && empty($category_id)) {
+ $category_info = model('goods_category')->getInfo([ [ 'level', '=', 2 ], [ 'site_id', '=', $site_id ], [ 'category_full_name', '=', "{$goods_data['category_1']}/{$goods_data['category_2']}" ] ], 'category_id_1,category_id_2');
+ if (!empty($category_info)) {
+ $category_id = "{$category_info['category_id_1']},{$category_info['category_id_2']}";
+ }
+ }
+ if (!empty($goods_data[ 'category_1' ]) && empty($category_id)) {
+ $category_info = model('goods_category')->getInfo([ [ 'level', '=', 1 ], [ 'site_id', '=', $site_id ], [ 'category_name', '=', "{$goods_data['category_1']}" ] ], 'category_id_1');
+ if (!empty($category_info)) {
+ $category_id = "{$category_info['category_id_1']}";
+ }
+ }
+ if (empty($category_id)) return $this->error('', '未找到所填商品分类');
+ $category_json = [ $category_id ];
+
+ $sku_data = [];
+ $goods_spec_format = [];
+ $tag = 0;
+ // 处理sku数据
+ if (isset($goods_data[ 'sku' ])) {
+ foreach ($goods_data[ 'sku' ] as $sku_item) {
+ if (empty($sku_item[ 'sku_data' ])) return $this->error('', '规格数据不能为空');
+
+ $spec_name = '';
+ $spec_data = explode(';', $sku_item[ 'sku_data' ]);
+
+ $sku_spec_format = [];
+ foreach ($spec_data as $item) {
+ $spec_item = explode(':', $item);
+ $spec_name .= ' ' . $spec_item[ 1 ];
+
+ // 规格项
+ $spec_index = array_search($spec_item[ 0 ], array_column($goods_spec_format, 'spec_name'));
+ if (empty($goods_spec_format) || $spec_index === false) {
+ $spec = [
+ 'spec_id' => -( $tag + getMillisecond() ),
+ 'spec_name' => $spec_item[ 0 ],
+ 'value' => []
+ ];
+ $goods_spec_format[] = $spec;
+ $tag++;
+ } else {
+ $spec = $goods_spec_format[ $spec_index ];
+ }
+ // 规格值
+ $spec_index = array_search($spec_item[ 0 ], array_column($goods_spec_format, 'spec_name'));
+ $spec_value_index = array_search($spec_item[ 1 ], array_column($spec[ 'value' ], 'spec_value_name'));
+ if (empty($spec[ 'value' ]) || $spec_value_index === false) {
+ $spec_value = [
+ 'spec_id' => $spec[ 'spec_id' ],
+ 'spec_name' => $spec[ 'spec_name' ],
+ 'spec_value_id' => -( $tag + getMillisecond() ),
+ 'spec_value_name' => $spec_item[ 1 ],
+ 'image' => '',
+ ];
+ $goods_spec_format[ $spec_index ][ 'value' ][] = $spec_value;
+ $tag++;
+ } else {
+ $spec_value = $spec[ 'value' ][ $spec_value_index ];
+ }
+
+ $sku_spec_format[] = [
+ 'spec_id' => $spec[ 'spec_id' ],
+ 'spec_name' => $spec[ 'spec_name' ],
+ 'spec_value_id' => $spec_value[ 'spec_value_id' ],
+ 'spec_value_name' => $spec_value[ 'spec_value_name' ],
+ 'image' => '',
+ ];
+ }
+
+ $sku_images_arr = explode(',', $sku_item[ 'sku_image' ]);
+
+ $sku_temp = [
+ 'spec_name' => trim($spec_name),
+ 'sku_no' => $sku_item[ 'sku_code' ],
+ 'sku_spec_format' => $sku_spec_format,
+ 'price' => $sku_item[ 'price' ],
+ 'market_price' => $sku_item[ 'market_price' ],
+ 'cost_price' => $sku_item[ 'cost_price' ],
+ 'stock_alarm' => $sku_item[ 'stock_alarm' ],
+ 'sku_image' => empty($sku_item[ 'sku_image' ]) ? '' : $sku_images_arr[ 0 ],
+ 'sku_images' => empty($sku_item[ 'sku_image' ]) ? '' : $sku_item[ 'sku_image' ],
+ 'sku_images_arr' => empty($sku_item[ 'sku_image' ]) ? [] : $sku_images_arr,
+ 'is_default' => 0,
+ 'carmichael' => empty($sku_item[ 'carmichael' ]) ? [] : explode("\n", $sku_item[ 'carmichael' ])
+ ];
+
+ $sku_data[] = $sku_temp;
+ }
+ } else {
+ $goods_img = explode(',', $goods_data[ 'goods_image' ]);
+ $sku_data = [
+ [
+ 'sku_id' => 0,
+ 'sku_name' => $goods_data[ 'goods_name' ],
+ 'spec_name' => '',
+ 'sku_spec_format' => '',
+ 'price' => empty($goods_data[ 'price' ]) ? 0 : $goods_data[ 'price' ],
+ 'market_price' => empty($goods_data[ 'market_price' ]) ? 0 : $goods_data[ 'market_price' ],
+ 'cost_price' => empty($goods_data[ 'cost_price' ]) ? 0 : $goods_data[ 'cost_price' ],
+ 'sku_no' => $goods_data[ 'goods_code' ],
+ 'stock_alarm' => empty($goods_data[ 'stock_alarm' ]) ? 0 : $goods_data[ 'stock_alarm' ],
+ 'sku_image' => $goods_img[ 0 ],
+ 'sku_images' => $goods_data[ 'goods_image' ],
+ 'carmichael' => empty($goods_data[ 'carmichael' ]) ? [] : explode("\n", $goods_data[ 'carmichael' ])
+ ]
+ ];
+ }
+
+ if (count($goods_spec_format) > 4) return $this->error('', '最多支持四种规格项');
+
+ $data = [
+ 'goods_name' => $goods_data[ 'goods_name' ],// 商品名称,
+ 'goods_attr_class' => '',// 商品类型id,
+ 'goods_attr_name' => '',// 商品类型名称,
+ 'site_id' => $site_id,
+ 'category_id' => ',' . $category_id . ',',
+ 'category_json' => json_encode($category_json),
+ 'goods_image' => $goods_data[ 'goods_image' ],// 商品主图路径
+ 'goods_content' => '',// 商品详情
+ 'goods_state' => 0, //$goods_data['goods_state'] == 1 || $goods_data['goods_state'] == '是' ? 1 : 0,// 商品状态(1.正常0下架)
+ 'price' => empty($goods_data[ 'price' ]) ? 0 : $goods_data[ 'price' ],// 商品价格(取第一个sku)
+ 'market_price' => empty($goods_data[ 'market_price' ]) ? 0 : $goods_data[ 'market_price' ],// 市场价格(取第一个sku)
+ 'cost_price' => empty($goods_data[ 'cost_price' ]) ? 0 : $goods_data[ 'cost_price' ],// 成本价(取第一个sku)
+ 'sku_no' => $goods_data[ 'goods_code' ],// 商品sku编码
+ 'goods_stock_alarm' => empty($goods_data[ 'goods_stock_alarm' ]) ? 0 : $goods_data[ 'goods_stock_alarm' ],// 库存预警
+ 'goods_spec_format' => empty($goods_spec_format) ? '' : json_encode($goods_spec_format, JSON_UNESCAPED_UNICODE),// 商品规格格式
+ 'goods_attr_format' => '',// 商品参数格式
+ 'introduction' => $goods_data[ 'introduction' ],// 促销语
+ 'keywords' => $goods_data[ 'keywords' ],// 关键词
+ 'unit' => $goods_data[ 'unit' ],// 单位
+ 'sort' => '',// 排序,
+ 'qr_id' => empty($goods_data[ 'qr_id' ]) ? 0 : $goods_data[ 'qr_id' ],// 社群二维码id
+ 'template_id' => empty($goods_data[ 'template_id' ]) ? 0 : $goods_data[ 'template_id' ],// 海报id
+ 'is_limit' => empty($goods_data[ 'is_limit' ]) ? 0 : $goods_data[ 'is_limit' ],// 是否限购
+ 'limit_type' => empty($goods_data[ 'limit_type' ]) ? 0 : $goods_data[ 'limit_type' ],// 限购类型
+ 'video_url' => '',// 视频
+ 'goods_sku_data' => json_encode($sku_data, JSON_UNESCAPED_UNICODE),// SKU商品数据
+ 'goods_service_ids' => '',// 商品服务id集合
+ 'label_id' => '',// 商品分组id
+ 'virtual_sale' => 0,// 虚拟销量
+ 'max_buy' => 0,// 限购
+ 'min_buy' => 0,// 起售
+ 'recommend_way' => 0, // 推荐方式,1:新品,2:精品,3;推荐
+ 'timer_on' => 0,//定时上架
+ 'timer_off' => 0,//定时下架
+ 'brand_id' => 0,
+ 'is_consume_discount' => $goods_data[ 'is_consume_discount' ] == 1 || $goods_data[ 'is_consume_discount' ] == '是' ? 1 : 0, //是否参与会员折扣
+ ];
+
+ $res = $this->addGoods($data);
+ return $res;
+ } catch (\Exception $e) {
+ return $this->error('', $e->getMessage());
+ }
+ }
+
+ /**
+ * 检测商品是否存在未完成的订单
+ * @param $params
+ * @return array
+ */
+ public function checkGoodsIsExistsOrder($params)
+ {
+ $condition = [
+ [ 'og.site_id', '=', $params[ 'site_id' ] ],
+ [ 'og.goods_id', '=', $params[ 'goods_id' ] ],
+ [ 'o.order_status', 'not in', [ -1, 10 ] ] // 排除订单状态 -1:已关闭,10:已完成
+ ];
+
+ if (!empty($params[ 'sku_id' ])) {
+ $condition[] = [ 'og.sku_id', 'in', $params[ 'sku_id' ] ];
+ }
+
+ $join = [
+ [ 'order o', 'o.order_id = og.order_id', 'left' ]
+ ];
+
+ $order_model = new OrderCommon();
+ $res = $order_model->getOrderGoodsCount($condition, 'order_goods_id', 'og', $join);
+ if ($res[ 'data' ] > 0) {
+ return $this->error('', '该商品存在未完成的订单,无法删除规格项');
+ }
+ return $this->success();
+
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/virtualcard/shop/controller/Goods.php b/src/addon/virtualcard/shop/controller/Goods.php
index 260bc681f..d20af3db6 100644
--- a/src/addon/virtualcard/shop/controller/Goods.php
+++ b/src/addon/virtualcard/shop/controller/Goods.php
@@ -1,460 +1,452 @@
-replace = [
- 'ADDON_VIRTUALCARD_CSS' => __ROOT__ . '/addon/virtualcard/shop/view/public/css',
- 'ADDON_VIRTUALCARD_JS' => __ROOT__ . '/addon/virtualcard/shop/view/public/js',
- 'ADDON_VIRTUALCARD_IMG' => __ROOT__ . '/addon/virtualcard/shop/view/public/img',
- ];
- parent::__construct($app);
- }
-
- /**
- * 添加商品
- * @return mixed
- */
- public function addGoods()
- {
- if (request()->isJson()) {
-
- $category_id = input('category_id', 0);// 分类id
- $category_json = json_encode($category_id);//分类字符串
- $category_id = ',' . implode(',', $category_id) . ',';
-
- $data = [
- 'goods_name' => input('goods_name', ''),// 商品名称,
- 'goods_attr_class' => input('goods_attr_class', ''),// 商品类型id,
- 'goods_attr_name' => input('goods_attr_name', ''),// 商品类型名称,
- 'is_limit' => input('is_limit', '0'),// 商品是否开启限购,
- 'limit_type' => input('limit_type', '1'),// 限购类型,
- 'site_id' => $this->site_id,
- 'category_id' => $category_id,
- 'category_json' => $category_json,
- 'goods_image' => input('goods_image', ''),// 商品主图路径
- 'goods_content' => input('goods_content', ''),// 商品详情
- 'goods_state' => input('goods_state', ''),// 商品状态(1.正常0下架)
- 'price' => input('price', 0),// 商品价格(取第一个sku)
- 'market_price' => input('market_price', 0),// 市场价格(取第一个sku)
- 'cost_price' => input('cost_price', 0),// 成本价(取第一个sku)
- 'sku_no' => input('sku_no', ''),// 商品sku编码
- 'weight' => input('weight', ''),// 重量
- 'volume' => input('volume', ''),// 体积
- 'goods_stock' => input('goods_stock', 0),// 商品库存(总和)
- 'goods_stock_alarm' => input('goods_stock_alarm', 0),// 库存预警
- 'goods_spec_format' => input('goods_spec_format', ''),// 商品规格格式
- 'goods_attr_format' => input('goods_attr_format', ''),// 商品参数格式
- 'introduction' => input('introduction', ''),// 促销语
- 'keywords' => input('keywords', ''),// 关键词
- 'brand_id' => input('brand_id', 0),//品牌id
- 'unit' => input('unit', ''),// 单位
- 'sort' => input('sort', 0),// 排序,
- 'video_url' => input('video_url', ''),// 视频
- 'goods_sku_data' => input('goods_sku_data', ''),// SKU商品数据
- 'goods_service_ids' => input('goods_service_ids', ''),// 商品服务id集合
- 'label_id' => input('label_id', ''),// 商品分组id
- 'virtual_sale' => input('virtual_sale', 0),// 虚拟销量
- 'max_buy' => input('max_buy', 0),// 限购
- 'min_buy' => input('min_buy', 0),// 起售
- 'recommend_way' => input('recommend_way', 0), // 推荐方式,1:新品,2:精品,3;推荐
- 'timer_on' => strtotime(input('timer_on', 0)),//定时上架
- 'timer_off' => strtotime(input('timer_off', 0)),//定时下架
- 'is_consume_discount' => input('is_consume_discount', 0),//是否参与会员折扣
- 'qr_id' => input('qr_id', 0),//社群二维码id
- 'template_id' => input('template_id', 0),//商品海报id
- 'sale_show' => input('sale_show', 0),//
- 'stock_show' => input('stock_show', 0),//
- 'market_price_show' => input('market_price_show', 0),//
- 'barrage_show' => input('barrage_show', 0),//
- 'form_id' => input('form_id', 0),
- 'sale_channel' => input('sale_channel', 'all'),
- 'sale_store' => input('sale_store', 'all'),
- 'supplier_id' => input('supplier_id', 0)
- ];
-
- $virtual_goods_model = new VirtualGoodsModel();
- $res = $virtual_goods_model->addGoods($data);
- return $res;
- } else {
-
- //获取一级商品分类
- $goods_category_model = new GoodsCategoryModel();
- $condition = [
- [ 'pid', '=', 0 ],
- [ 'site_id', '=', $this->site_id ]
- ];
-
- $goods_category_list = $goods_category_model->getCategoryList($condition, 'category_id,category_name,level,commission_rate');
- $goods_category_list = $goods_category_list[ 'data' ];
- $this->assign('goods_category_list', $goods_category_list);
-
- //获取商品类型
- $goods_attr_model = new GoodsAttributeModel();
- $attr_class_list = $goods_attr_model->getAttrClassList([ [ 'site_id', '=', $this->site_id ] ], 'class_id,class_name')[ 'data' ];
- $this->assign('attr_class_list', $attr_class_list);
-
- // 商品服务
- $goods_service_model = new GoodsServiceModel();
- $service_list = $goods_service_model->getServiceList([ [ 'site_id', '=', $this->site_id ] ], 'id,service_name,icon')[ 'data' ];
- $this->assign('service_list', $service_list);
-
- // 商品标签
- $goods_label_model = new GoodsLabelModel();
- $label_list = $goods_label_model->getLabelList([ [ 'site_id', '=', $this->site_id ] ], 'id,label_name', 'sort ASC')[ 'data' ];
- $this->assign('label_list', $label_list);
- // 商品品牌
- $goods_brand_model = new GoodsBrandModel();
- $brand_list = $goods_brand_model->getBrandList([ [ 'site_id', '=', $this->site_id ] ], 'brand_id,brand_name', 'sort asc')[ 'data' ];
- $this->assign('brand_list', $brand_list);
- //商品默认排序值
- $config_model = new ConfigModel();
- $sort_config = $config_model->getGoodsSort($this->site_id)[ 'data' ][ 'value' ];
- $this->assign('sort_config', $sort_config);
-
- //获取商品海报
- $poster_list = event('PosterTemplate', [ 'site_id' => $this->site_id ], true);
- if (!empty($poster_list)) {
- $poster_list = $poster_list[ 'data' ];
- }
- $this->assign('poster_list', $poster_list);
-
- $form_is_exit = addon_is_exit('form', $this->site_id);
- if ($form_is_exit) {
- $form_list = ( new Form() )->getFormList([ [ 'site_id', '=', $this->site_id ], [ 'form_type', '=', 'goods' ], [ 'is_use', '=', 1 ] ], 'id desc', 'id, form_name')[ 'data' ];
- $this->assign('form_list', $form_list);
- }
- $this->assign('form_is_exit', $form_is_exit);
-
- $this->assign('all_goodsclass', event('GoodsClass'));
- $this->assign('goods_class', ( new VirtualGoodsModel() )->getGoodsClass());
-
- $this->assign('store_is_exit', addon_is_exit('store', $this->site_id));
-
- $is_install_supply = addon_is_exit('supply');
- if ($is_install_supply) {
- $supplier_model = new SupplierModel();
- $supplier_list = $supplier_model->getSupplyList([ [ 'supplier_site_id', '=', $this->site_id ] ], 'supplier_id,title', 'supplier_id desc')['data'];
- $this->assign('supplier_list', $supplier_list);
- }
- $this->assign('is_install_supply', $is_install_supply);
-
- return $this->fetch('goods/add_goods');
- }
- }
-
- /**
- * 编辑商品
- * @return mixed
- */
- public function editGoods()
- {
- $virtual_goods_model = new VirtualGoodsModel();
- if (request()->isJson()) {
-
- $category_id = input('category_id', 0);// 分类id
- $category_json = json_encode($category_id);//分类字符串
- $category_id = ',' . implode(',', $category_id) . ',';
-
- $data = [
- 'goods_id' => input('goods_id', 0),// 商品id
- 'goods_name' => input('goods_name', ''),// 商品名称,
- 'goods_attr_class' => input('goods_attr_class', ''),// 商品类型id,
- 'goods_attr_name' => input('goods_attr_name', ''),// 商品类型名称,
- 'is_limit' => input('is_limit', '0'),// 商品是否开启限购,
- 'limit_type' => input('limit_type', '1'),// 限购类型,
- 'site_id' => $this->site_id,
- 'category_id' => $category_id,
- 'category_json' => $category_json,
- 'goods_image' => input('goods_image', ''),// 商品主图路径
- 'goods_content' => input('goods_content', ''),// 商品详情
- 'goods_state' => input('goods_state', ''),// 商品状态(1.正常0下架)
- 'price' => input('price', 0),// 商品价格(取第一个sku)
- 'market_price' => input('market_price', 0),// 市场价格(取第一个sku)
- 'cost_price' => input('cost_price', 0),// 成本价(取第一个sku)
- 'sku_no' => input('sku_no', ''),// 商品sku编码
- 'weight' => input('weight', ''),// 重量
- 'volume' => input('volume', ''),// 体积
- 'goods_stock' => input('goods_stock', 0),// 商品库存(总和)
- 'goods_stock_alarm' => input('goods_stock_alarm', 0),// 库存预警
- 'goods_spec_format' => input('goods_spec_format', ''),// 商品规格格式
- 'goods_attr_format' => input('goods_attr_format', ''),// 商品参数格式
- 'introduction' => input('introduction', ''),// 促销语
- 'keywords' => input('keywords', ''),// 关键词
- 'unit' => input('unit', ''),// 单位
- 'sort' => input('sort', 0),// 排序,
- 'video_url' => input('video_url', ''),// 视频
- 'goods_sku_data' => input('goods_sku_data', ''),// SKU商品数据
- 'goods_service_ids' => input('goods_service_ids', ''),// 商品服务id集合
- 'label_id' => input('label_id', ''),// 商品分组id
- 'brand_id' => input('brand_id', 0),//品牌id
- 'virtual_sale' => input('virtual_sale', 0),// 虚拟销量
- 'max_buy' => input('max_buy', 0),// 限购
- 'min_buy' => input('min_buy', 0),// 起售
- 'recommend_way' => input('recommend_way', 0), // 推荐方式,1:新品,2:精品,3;推荐
- 'timer_on' => strtotime(input('timer_on', 0)),//定时上架
- 'timer_off' => strtotime(input('timer_off', 0)),//定时下架
- 'spec_type_status' => input('spec_type_status', 0),
- 'is_consume_discount' => input('is_consume_discount', 0),//是否参与会员折扣
- 'qr_id' => input('qr_id', 0),//社群二维码id
- 'template_id' => input('template_id', 0),//商品海报id
- 'sale_show' => input('sale_show', 0),//
- 'stock_show' => input('stock_show', 0),//
- 'market_price_show' => input('market_price_show', 0),//
- 'barrage_show' => input('barrage_show', 0),//
- 'form_id' => input('form_id', 0),
- 'sale_channel' => input('sale_channel', 'all'),
- 'sale_store' => input('sale_store', 'all'),
- 'supplier_id' => input('supplier_id', 0)
- ];
- $res = $virtual_goods_model->editGoods($data);
- return $res;
- } else {
- $goods_model = new GoodsModel();
- $goods_id = input('goods_id', 0);
- $goods_info = $goods_model->editGetGoodsInfo([ [ 'goods_id', '=', $goods_id ], [ 'site_id', '=', $this->site_id ] ])[ 'data' ];
- if (empty($goods_info)) $this->error('未获取到商品数据', href_url('shop/goods/lists'));
-
- $goods_sku_list = $goods_model->getGoodsSkuList([ [ 'goods_id', '=', $goods_id ], [ 'site_id', '=', $this->site_id ] ], 'sku_id,sku_name,sku_no,sku_spec_format,price,market_price,cost_price,stock,virtual_indate,sku_image,sku_images,goods_spec_format,spec_name,stock_alarm,is_default', '')[ 'data' ];
- $goods_info[ 'sku_list' ] = $goods_sku_list;
- $this->assign('goods_info', $goods_info);
-
- //获取一级商品分类
- $goods_category_model = new GoodsCategoryModel();
- $condition = [
- [ 'pid', '=', 0 ],
- [ 'site_id', '=', $this->site_id ]
- ];
- $goods_category_list = $goods_category_model->getCategoryList($condition, 'category_id,category_name,level,commission_rate')[ 'data' ];
- $this->assign('goods_category_list', $goods_category_list);
-
- //获取商品类型
- $goods_attr_model = new GoodsAttributeModel();
- $attr_class_list = $goods_attr_model->getAttrClassList([ [ 'site_id', '=', $this->site_id ] ], 'class_id,class_name')[ 'data' ];
- $this->assign('attr_class_list', $attr_class_list);
-
- // 商品服务
- $goods_service_model = new GoodsServiceModel();
- $service_list = $goods_service_model->getServiceList([ [ 'site_id', '=', $this->site_id ] ], 'id,service_name,icon')[ 'data' ];
- $this->assign('service_list', $service_list);
-
- // 商品标签
- $goods_label_model = new GoodsLabelModel();
- $label_list = $goods_label_model->getLabelList([ [ 'site_id', '=', $this->site_id ] ], 'id,label_name', 'sort ASC')[ 'data' ];
- $this->assign('label_list', $label_list);
- //获取品牌
- $goods_brand_model = new GoodsBrandModel();
- $brand_list = $goods_brand_model->getBrandList([ [ 'site_id', '=', $this->site_id ] ], 'brand_id, brand_name')[ 'data' ];
- $this->assign('brand_list', $brand_list);
-
- //获取商品海报
- $poster_list = event('PosterTemplate', [ 'site_id' => $this->site_id ], true);
- if (!empty($poster_list)) {
- $poster_list = $poster_list[ 'data' ];
- }
- $this->assign('poster_list', $poster_list);
-
- $form_is_exit = addon_is_exit('form', $this->site_id);
- if ($form_is_exit) {
- $form_list = ( new Form() )->getFormList([ [ 'site_id', '=', $this->site_id ], [ 'form_type', '=', 'goods' ], [ 'is_use', '=', 1 ] ], 'id desc', 'id, form_name')[ 'data' ];
- $this->assign('form_list', $form_list);
- }
- $this->assign('form_is_exit', $form_is_exit);
-
- $store_is_exit = addon_is_exit('store', $this->site_id);
- if ($store_is_exit && $goods_info[ 'sale_store' ] != 'all') {
- $store_list = ( new StoreModel() )->getStoreList([ [ 'site_id', '=', $this->site_id ], [ 'store_id', 'in', $goods_info[ 'sale_store' ] ] ], 'store_id,store_name,status,address,full_address,is_frozen');
- $this->assign('store_list', $store_list[ 'data' ]);
- }
- $this->assign('store_is_exit', $store_is_exit);
-
- $is_install_supply = addon_is_exit('supply');
- if ($is_install_supply) {
- $supplier_model = new SupplierModel();
- $supplier_list = $supplier_model->getSupplyList([ [ 'supplier_site_id', '=', $this->site_id ] ], 'supplier_id,title', 'supplier_id desc')['data'];
- $this->assign('supplier_list', $supplier_list);
- }
- $this->assign('is_install_supply', $is_install_supply);
-
- return $this->fetch('goods/edit_goods');
- }
- }
-
- /**
- * 卡密管理
- * @return array|mixed|void
- */
- public function carmichael()
- {
- $virtual_goods_model = new VirtualGoodsModel();
- if (request()->isJson()) {
- $page = input('page', 1);
- $page_size = input('page_size', PAGE_LIST_ROWS);
- $goods_id = input('goods_id', 0);
- $is_sold = input('is_sold', 0);
- $condition = [
- [ 'gv.goods_id', '=', $goods_id ],
- [ 'gv.site_id', '=', $this->site_id ]
- ];
- if ($is_sold) {
- $condition[] = [ 'gv.order_id', '<>', 0 ];
- } else {
- $condition[] = [ 'gv.order_id', '=', 0 ];
- }
- $join = [
- [ 'goods_sku gs', 'gs.sku_id = gv.sku_id', 'left' ],
- [ 'member m', 'm.member_id = gv.member_id', 'left' ],
- ];
- $field = 'gv.id,gv.sku_name,gv.card_info,gv.order_id,gv.sku_id,gv.sold_time,gs.spec_name,m.nickname, m.headimg';
- $res = $virtual_goods_model->getVirtualGoodsPageList($condition, $page, $page_size, 'id desc,sold_time desc', $field, 'gv', $join);
- return $res;
- }
- $goods_id = input('goods_id', 0);
- $this->assign('goods_id', $goods_id);
-
- $goods_info = $virtual_goods_model->getGoodsDetail($goods_id, $this->site_id);
- if (empty($goods_info[ 'data' ])) $this->error('未获取到商品信息');
- $this->assign('goods', $goods_info[ 'data' ]);
- $temp_condition = array (
- [ 'goods_id', '=', $goods_id ],
- [ 'site_id', '=', $this->site_id ],
- [ 'order_id', '=', 0 ]
- );
- $this->assign('stock', $virtual_goods_model->getVirtualGoodsCount($temp_condition)[ 'data' ] ?? 0);
- return $this->fetch('goods/carmichael');
- }
-
- /**
- * 下载卡密导入模板
- * @throws \PHPExcel_Exception
- * @throws \PHPExcel_Reader_Exception
- * @throws \PHPExcel_Writer_Exception
- */
- public function downloadTemplate()
- {
- // 实例化excel
- $phpExcel = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
-
- $phpExcel->getProperties()->setTitle('卡密数据导入模板');
- $phpExcel->getProperties()->setSubject('卡密数据导入模板');
- // 对单元格设置居中效果
- $phpExcel->getActiveSheet()->getStyle('A')->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER);
- $phpExcel->getActiveSheet()->getStyle('B')->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER);
-
- //单独添加列名称
- $phpExcel->setActiveSheetIndex(0);
- $phpExcel->getActiveSheet()->setCellValue('A1', '卡号');//可以指定位置
- $phpExcel->getActiveSheet()->setCellValue('B1', '密码');
-
- // 设置第一个sheet为工作的sheet
- $phpExcel->setActiveSheetIndex(0);
- // 保存Excel 2007格式文件,保存路径为当前路径,名字为export.xlsx
- $objWriter = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($phpExcel, 'Xlsx');
- $file = date('卡密数据导入模板', time()) . '.xlsx';
- $objWriter->save($file);
-
- header('Content-type:application/octet-stream');
-
- $filename = basename($file);
- header('Content-Disposition:attachment;filename = ' . $filename);
- header('Accept-ranges:bytes');
- header('Accept-length:' . filesize($file));
- readfile($file);
- unlink($file);
- exit;
- }
-
- /**
- * 添加卡密
- * @return array
- */
- public function addCarmichael()
- {
- if (request()->isJson()) {
- $virtual_goods_model = new VirtualGoodsModel();
- $goods_id = input('goods_id', 0);
- $sku_id = input('sku_id', 0);
- $data = input('data', '');
- $carmichael = explode(',', $data);
- $res = $virtual_goods_model->addGoodsVirtual($this->site_id, $goods_id, $sku_id, $carmichael);
- return $res;
- }
- }
-
- /**
- * 导入数据
- */
- public function import()
- {
- if (request()->isJson()) {
- $virtual_goods_model = new VirtualGoodsModel();
- $path = input('path', '');
- $res = $virtual_goods_model->importData($path);
- return $res;
- }
- }
-
- /**
- * 删除卡密
- */
- public function deleteGoodsVirtual()
- {
- if (request()->isJson()) {
- $ids = input('id', '');
- $goods_id = input('goods_id', '');
- $virtual_goods_model = new VirtualGoodsModel();
- $res = $virtual_goods_model->deleteGoodsVirtual([ [ 'order_id', '=', 0 ], [ 'id', 'in', $ids ], [ 'site_id', '=', $this->site_id ], [ 'goods_id', '=', $goods_id ] ]);
- return $res;
- }
- }
-
- /**
- * 编辑卡密
- * @return array
- */
- public function editGoodsVirtual()
- {
- if (request()->isJson()) {
- $virtual_goods_model = new VirtualGoodsModel();
- $id = input('id', '');
- $card_info = [
- 'cardno' => input('cardno', ''),
- 'password' => input('password', '')
- ];
- $res = $virtual_goods_model->updateGoodsVirtual([ 'card_info' => json_encode($card_info) ], [ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ], [ 'order_id', '=', 0 ] ]);
- return $res;
- }
- }
+replace = [
+ 'ADDON_VIRTUALCARD_CSS' => __ROOT__ . '/addon/virtualcard/shop/view/public/css',
+ 'ADDON_VIRTUALCARD_JS' => __ROOT__ . '/addon/virtualcard/shop/view/public/js',
+ 'ADDON_VIRTUALCARD_IMG' => __ROOT__ . '/addon/virtualcard/shop/view/public/img',
+ ];
+ parent::__construct($app);
+ }
+
+ /**
+ * 添加商品
+ * @return mixed
+ */
+ public function addGoods()
+ {
+ if (request()->isJson()) {
+
+ $category_id = input('category_id', 0);// 分类id
+ $category_json = json_encode($category_id);//分类字符串
+ $category_id = ',' . implode(',', $category_id) . ',';
+
+ $data = [
+ 'goods_name' => input('goods_name', ''),// 商品名称,
+ 'goods_attr_class' => input('goods_attr_class', ''),// 商品类型id,
+ 'goods_attr_name' => input('goods_attr_name', ''),// 商品类型名称,
+ 'is_limit' => input('is_limit', '0'),// 商品是否开启限购,
+ 'limit_type' => input('limit_type', '1'),// 限购类型,
+ 'site_id' => $this->site_id,
+ 'category_id' => $category_id,
+ 'category_json' => $category_json,
+ 'goods_image' => input('goods_image', ''),// 商品主图路径
+ 'goods_content' => input('goods_content', ''),// 商品详情
+ 'goods_state' => input('goods_state', ''),// 商品状态(1.正常0下架)
+ 'price' => input('price', 0),// 商品价格(取第一个sku)
+ 'market_price' => input('market_price', 0),// 市场价格(取第一个sku)
+ 'cost_price' => input('cost_price', 0),// 成本价(取第一个sku)
+ 'sku_no' => input('sku_no', ''),// 商品sku编码
+ 'weight' => input('weight', ''),// 重量
+ 'volume' => input('volume', ''),// 体积
+ 'goods_stock' => input('goods_stock', 0),// 商品库存(总和)
+ 'goods_stock_alarm' => input('goods_stock_alarm', 0),// 库存预警
+ 'goods_spec_format' => input('goods_spec_format', ''),// 商品规格格式
+ 'goods_attr_format' => input('goods_attr_format', ''),// 商品参数格式
+ 'introduction' => input('introduction', ''),// 促销语
+ 'keywords' => input('keywords', ''),// 关键词
+ 'brand_id' => input('brand_id', 0),//品牌id
+ 'unit' => input('unit', ''),// 单位
+ 'sort' => input('sort', 0),// 排序,
+ 'video_url' => input('video_url', ''),// 视频
+ 'goods_sku_data' => input('goods_sku_data', ''),// SKU商品数据
+ 'goods_service_ids' => input('goods_service_ids', ''),// 商品服务id集合
+ 'label_id' => input('label_id', ''),// 商品分组id
+ 'virtual_sale' => input('virtual_sale', 0),// 虚拟销量
+ 'max_buy' => input('max_buy', 0),// 限购
+ 'min_buy' => input('min_buy', 0),// 起售
+ 'recommend_way' => input('recommend_way', 0), // 推荐方式,1:新品,2:精品,3;推荐
+ 'timer_on' => strtotime(input('timer_on', 0)),//定时上架
+ 'timer_off' => strtotime(input('timer_off', 0)),//定时下架
+ 'is_consume_discount' => input('is_consume_discount', 0),//是否参与会员折扣
+ 'qr_id' => input('qr_id', 0),//社群二维码id
+ 'template_id' => input('template_id', 0),//商品海报id
+ 'sale_show' => input('sale_show', 0),//
+ 'stock_show' => input('stock_show', 0),//
+ 'market_price_show' => input('market_price_show', 0),//
+ 'barrage_show' => input('barrage_show', 0),//
+ 'form_id' => input('form_id', 0),
+ 'sale_channel' => input('sale_channel', 'all'),
+ 'sale_store' => input('sale_store', 'all'),
+ 'supplier_id' => input('supplier_id', 0)
+ ];
+
+ $virtual_goods_model = new VirtualGoodsModel();
+ $res = $virtual_goods_model->addGoods($data);
+ return $res;
+ } else {
+
+ //获取一级商品分类
+ $goods_category_model = new GoodsCategoryModel();
+ $condition = [
+ [ 'pid', '=', 0 ],
+ [ 'site_id', '=', $this->site_id ]
+ ];
+
+ $goods_category_list = $goods_category_model->getCategoryList($condition, 'category_id,category_name,level,commission_rate');
+ $goods_category_list = $goods_category_list[ 'data' ];
+ $this->assign('goods_category_list', $goods_category_list);
+
+ //获取商品类型
+ $goods_attr_model = new GoodsAttributeModel();
+ $attr_class_list = $goods_attr_model->getAttrClassList([ [ 'site_id', '=', $this->site_id ] ], 'class_id,class_name')[ 'data' ];
+ $this->assign('attr_class_list', $attr_class_list);
+
+ // 商品服务
+ $goods_service_model = new GoodsServiceModel();
+ $service_list = $goods_service_model->getServiceList([ [ 'site_id', '=', $this->site_id ] ], 'id,service_name,icon')[ 'data' ];
+ $this->assign('service_list', $service_list);
+
+ // 商品标签
+ $goods_label_model = new GoodsLabelModel();
+ $label_list = $goods_label_model->getLabelList([ [ 'site_id', '=', $this->site_id ] ], 'id,label_name', 'sort ASC')[ 'data' ];
+ $this->assign('label_list', $label_list);
+ // 商品品牌
+ $goods_brand_model = new GoodsBrandModel();
+ $brand_list = $goods_brand_model->getBrandList([ [ 'site_id', '=', $this->site_id ] ], 'brand_id,brand_name', 'sort asc')[ 'data' ];
+ $this->assign('brand_list', $brand_list);
+ //商品默认排序值
+ $config_model = new ConfigModel();
+ $sort_config = $config_model->getGoodsSort($this->site_id)[ 'data' ][ 'value' ];
+ $this->assign('sort_config', $sort_config);
+
+ //获取商品海报
+ $poster_list = event('PosterTemplate', [ 'site_id' => $this->site_id ], true);
+ if (!empty($poster_list)) {
+ $poster_list = $poster_list[ 'data' ];
+ }
+ $this->assign('poster_list', $poster_list);
+
+ $form_is_exit = addon_is_exit('form', $this->site_id);
+ if ($form_is_exit) {
+ $form_list = ( new Form() )->getFormList([ [ 'site_id', '=', $this->site_id ], [ 'form_type', '=', 'goods' ], [ 'is_use', '=', 1 ] ], 'id desc', 'id, form_name')[ 'data' ];
+ $this->assign('form_list', $form_list);
+ }
+ $this->assign('form_is_exit', $form_is_exit);
+
+ $this->assign('all_goodsclass', event('GoodsClass'));
+ $this->assign('goods_class', ( new VirtualGoodsModel() )->getGoodsClass());
+
+ $this->assign('store_is_exit', addon_is_exit('store', $this->site_id));
+
+ $is_install_supply = addon_is_exit('supply');
+ if ($is_install_supply) {
+ $supplier_model = new SupplierModel();
+ $supplier_list = $supplier_model->getSupplyList([ [ 'supplier_site_id', '=', $this->site_id ] ], 'supplier_id,title', 'supplier_id desc')['data'];
+ $this->assign('supplier_list', $supplier_list);
+ }
+ $this->assign('is_install_supply', $is_install_supply);
+
+ return $this->fetch('goods/add_goods');
+ }
+ }
+
+ /**
+ * 编辑商品
+ * @return mixed
+ */
+ public function editGoods()
+ {
+ $virtual_goods_model = new VirtualGoodsModel();
+ if (request()->isJson()) {
+
+ $category_id = input('category_id', 0);// 分类id
+ $category_json = json_encode($category_id);//分类字符串
+ $category_id = ',' . implode(',', $category_id) . ',';
+
+ $data = [
+ 'goods_id' => input('goods_id', 0),// 商品id
+ 'goods_name' => input('goods_name', ''),// 商品名称,
+ 'goods_attr_class' => input('goods_attr_class', ''),// 商品类型id,
+ 'goods_attr_name' => input('goods_attr_name', ''),// 商品类型名称,
+ 'is_limit' => input('is_limit', '0'),// 商品是否开启限购,
+ 'limit_type' => input('limit_type', '1'),// 限购类型,
+ 'site_id' => $this->site_id,
+ 'category_id' => $category_id,
+ 'category_json' => $category_json,
+ 'goods_image' => input('goods_image', ''),// 商品主图路径
+ 'goods_content' => input('goods_content', ''),// 商品详情
+ 'goods_state' => input('goods_state', ''),// 商品状态(1.正常0下架)
+ 'price' => input('price', 0),// 商品价格(取第一个sku)
+ 'market_price' => input('market_price', 0),// 市场价格(取第一个sku)
+ 'cost_price' => input('cost_price', 0),// 成本价(取第一个sku)
+ 'sku_no' => input('sku_no', ''),// 商品sku编码
+ 'weight' => input('weight', ''),// 重量
+ 'volume' => input('volume', ''),// 体积
+ 'goods_stock' => input('goods_stock', 0),// 商品库存(总和)
+ 'goods_stock_alarm' => input('goods_stock_alarm', 0),// 库存预警
+ 'goods_spec_format' => input('goods_spec_format', ''),// 商品规格格式
+ 'goods_attr_format' => input('goods_attr_format', ''),// 商品参数格式
+ 'introduction' => input('introduction', ''),// 促销语
+ 'keywords' => input('keywords', ''),// 关键词
+ 'unit' => input('unit', ''),// 单位
+ 'sort' => input('sort', 0),// 排序,
+ 'video_url' => input('video_url', ''),// 视频
+ 'goods_sku_data' => input('goods_sku_data', ''),// SKU商品数据
+ 'goods_service_ids' => input('goods_service_ids', ''),// 商品服务id集合
+ 'label_id' => input('label_id', ''),// 商品分组id
+ 'brand_id' => input('brand_id', 0),//品牌id
+ 'virtual_sale' => input('virtual_sale', 0),// 虚拟销量
+ 'max_buy' => input('max_buy', 0),// 限购
+ 'min_buy' => input('min_buy', 0),// 起售
+ 'recommend_way' => input('recommend_way', 0), // 推荐方式,1:新品,2:精品,3;推荐
+ 'timer_on' => strtotime(input('timer_on', 0)),//定时上架
+ 'timer_off' => strtotime(input('timer_off', 0)),//定时下架
+ 'spec_type_status' => input('spec_type_status', 0),
+ 'is_consume_discount' => input('is_consume_discount', 0),//是否参与会员折扣
+ 'qr_id' => input('qr_id', 0),//社群二维码id
+ 'template_id' => input('template_id', 0),//商品海报id
+ 'sale_show' => input('sale_show', 0),//
+ 'stock_show' => input('stock_show', 0),//
+ 'market_price_show' => input('market_price_show', 0),//
+ 'barrage_show' => input('barrage_show', 0),//
+ 'form_id' => input('form_id', 0),
+ 'sale_channel' => input('sale_channel', 'all'),
+ 'sale_store' => input('sale_store', 'all'),
+ 'supplier_id' => input('supplier_id', 0)
+ ];
+ $res = $virtual_goods_model->editGoods($data);
+ return $res;
+ } else {
+ $goods_model = new GoodsModel();
+ $goods_id = input('goods_id', 0);
+ $goods_info = $goods_model->editGetGoodsInfo([ [ 'goods_id', '=', $goods_id ], [ 'site_id', '=', $this->site_id ] ])[ 'data' ];
+ if (empty($goods_info)) $this->error('未获取到商品数据', href_url('shop/goods/lists'));
+
+ $goods_sku_list = $goods_model->getGoodsSkuList([ [ 'goods_id', '=', $goods_id ], [ 'site_id', '=', $this->site_id ] ], 'sku_id,sku_name,sku_no,sku_spec_format,price,market_price,cost_price,stock,virtual_indate,sku_image,sku_images,goods_spec_format,spec_name,stock_alarm,is_default', '')[ 'data' ];
+ $goods_info[ 'sku_list' ] = $goods_sku_list;
+ $this->assign('goods_info', $goods_info);
+
+ //获取一级商品分类
+ $goods_category_model = new GoodsCategoryModel();
+ $condition = [
+ [ 'pid', '=', 0 ],
+ [ 'site_id', '=', $this->site_id ]
+ ];
+ $goods_category_list = $goods_category_model->getCategoryList($condition, 'category_id,category_name,level,commission_rate')[ 'data' ];
+ $this->assign('goods_category_list', $goods_category_list);
+
+ //获取商品类型
+ $goods_attr_model = new GoodsAttributeModel();
+ $attr_class_list = $goods_attr_model->getAttrClassList([ [ 'site_id', '=', $this->site_id ] ], 'class_id,class_name')[ 'data' ];
+ $this->assign('attr_class_list', $attr_class_list);
+
+ // 商品服务
+ $goods_service_model = new GoodsServiceModel();
+ $service_list = $goods_service_model->getServiceList([ [ 'site_id', '=', $this->site_id ] ], 'id,service_name,icon')[ 'data' ];
+ $this->assign('service_list', $service_list);
+
+ // 商品标签
+ $goods_label_model = new GoodsLabelModel();
+ $label_list = $goods_label_model->getLabelList([ [ 'site_id', '=', $this->site_id ] ], 'id,label_name', 'sort ASC')[ 'data' ];
+ $this->assign('label_list', $label_list);
+ //获取品牌
+ $goods_brand_model = new GoodsBrandModel();
+ $brand_list = $goods_brand_model->getBrandList([ [ 'site_id', '=', $this->site_id ] ], 'brand_id, brand_name')[ 'data' ];
+ $this->assign('brand_list', $brand_list);
+
+ //获取商品海报
+ $poster_list = event('PosterTemplate', [ 'site_id' => $this->site_id ], true);
+ if (!empty($poster_list)) {
+ $poster_list = $poster_list[ 'data' ];
+ }
+ $this->assign('poster_list', $poster_list);
+
+ $form_is_exit = addon_is_exit('form', $this->site_id);
+ if ($form_is_exit) {
+ $form_list = ( new Form() )->getFormList([ [ 'site_id', '=', $this->site_id ], [ 'form_type', '=', 'goods' ], [ 'is_use', '=', 1 ] ], 'id desc', 'id, form_name')[ 'data' ];
+ $this->assign('form_list', $form_list);
+ }
+ $this->assign('form_is_exit', $form_is_exit);
+
+ $store_is_exit = addon_is_exit('store', $this->site_id);
+ if ($store_is_exit && $goods_info[ 'sale_store' ] != 'all') {
+ $store_list = ( new StoreModel() )->getStoreList([ [ 'site_id', '=', $this->site_id ], [ 'store_id', 'in', $goods_info[ 'sale_store' ] ] ], 'store_id,store_name,status,address,full_address,is_frozen');
+ $this->assign('store_list', $store_list[ 'data' ]);
+ }
+ $this->assign('store_is_exit', $store_is_exit);
+
+ $is_install_supply = addon_is_exit('supply');
+ if ($is_install_supply) {
+ $supplier_model = new SupplierModel();
+ $supplier_list = $supplier_model->getSupplyList([ [ 'supplier_site_id', '=', $this->site_id ] ], 'supplier_id,title', 'supplier_id desc')['data'];
+ $this->assign('supplier_list', $supplier_list);
+ }
+ $this->assign('is_install_supply', $is_install_supply);
+
+ return $this->fetch('goods/edit_goods');
+ }
+ }
+
+ /**
+ * 卡密管理
+ * @return array|mixed|void
+ */
+ public function carmichael()
+ {
+ $virtual_goods_model = new VirtualGoodsModel();
+ if (request()->isJson()) {
+ $page = input('page', 1);
+ $page_size = input('page_size', PAGE_LIST_ROWS);
+ $goods_id = input('goods_id', 0);
+ $is_sold = input('is_sold', 0);
+ $condition = [
+ [ 'gv.goods_id', '=', $goods_id ],
+ [ 'gv.site_id', '=', $this->site_id ]
+ ];
+ if ($is_sold) {
+ $condition[] = [ 'gv.order_id', '<>', 0 ];
+ } else {
+ $condition[] = [ 'gv.order_id', '=', 0 ];
+ }
+ $join = [
+ [ 'goods_sku gs', 'gs.sku_id = gv.sku_id', 'left' ],
+ [ 'member m', 'm.member_id = gv.member_id', 'left' ],
+ ];
+ $field = 'gv.id,gv.sku_name,gv.card_info,gv.order_id,gv.sku_id,gv.sold_time,gs.spec_name,m.nickname, m.headimg';
+ $res = $virtual_goods_model->getVirtualGoodsPageList($condition, $page, $page_size, 'id desc,sold_time desc', $field, 'gv', $join);
+ return $res;
+ }
+ $goods_id = input('goods_id', 0);
+ $this->assign('goods_id', $goods_id);
+
+ $goods_info = $virtual_goods_model->getGoodsDetail($goods_id, $this->site_id);
+ if (empty($goods_info[ 'data' ])) $this->error('未获取到商品信息');
+ $this->assign('goods', $goods_info[ 'data' ]);
+ $temp_condition = array (
+ [ 'goods_id', '=', $goods_id ],
+ [ 'site_id', '=', $this->site_id ],
+ [ 'order_id', '=', 0 ]
+ );
+ $this->assign('stock', $virtual_goods_model->getVirtualGoodsCount($temp_condition)[ 'data' ] ?? 0);
+ return $this->fetch('goods/carmichael');
+ }
+
+ /**
+ * 下载卡密导入模板
+ * @throws \PHPExcel_Exception
+ * @throws \PHPExcel_Reader_Exception
+ * @throws \PHPExcel_Writer_Exception
+ */
+ public function downloadTemplate()
+ {
+ // 实例化excel
+ $phpExcel = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
+
+ $phpExcel->getProperties()->setTitle('卡密数据导入模板');
+ $phpExcel->getProperties()->setSubject('卡密数据导入模板');
+ // 对单元格设置居中效果
+ $phpExcel->getActiveSheet()->getStyle('A')->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER);
+ $phpExcel->getActiveSheet()->getStyle('B')->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER);
+
+ //单独添加列名称
+ $phpExcel->setActiveSheetIndex(0);
+ $phpExcel->getActiveSheet()->setCellValue('A1', '卡号');//可以指定位置
+ $phpExcel->getActiveSheet()->setCellValue('B1', '密码');
+
+ // 设置第一个sheet为工作的sheet
+ $phpExcel->setActiveSheetIndex(0);
+ // 保存Excel 2007格式文件,保存路径为当前路径,名字为export.xlsx
+ $objWriter = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($phpExcel, 'Xlsx');
+ $file = date('卡密数据导入模板', time()) . '.xlsx';
+ $objWriter->save($file);
+
+ header('Content-type:application/octet-stream');
+
+ $filename = basename($file);
+ header('Content-Disposition:attachment;filename = ' . $filename);
+ header('Accept-ranges:bytes');
+ header('Accept-length:' . filesize($file));
+ readfile($file);
+ unlink($file);
+ exit;
+ }
+
+ /**
+ * 添加卡密
+ * @return array
+ */
+ public function addCarmichael()
+ {
+ if (request()->isJson()) {
+ $virtual_goods_model = new VirtualGoodsModel();
+ $goods_id = input('goods_id', 0);
+ $sku_id = input('sku_id', 0);
+ $data = input('data', '');
+ $carmichael = explode(',', $data);
+ $res = $virtual_goods_model->addGoodsVirtual($this->site_id, $goods_id, $sku_id, $carmichael);
+ return $res;
+ }
+ }
+
+ /**
+ * 导入数据
+ */
+ public function import()
+ {
+ if (request()->isJson()) {
+ $virtual_goods_model = new VirtualGoodsModel();
+ $path = input('path', '');
+ $res = $virtual_goods_model->importData($path);
+ return $res;
+ }
+ }
+
+ /**
+ * 删除卡密
+ */
+ public function deleteGoodsVirtual()
+ {
+ if (request()->isJson()) {
+ $ids = input('id', '');
+ $goods_id = input('goods_id', '');
+ $virtual_goods_model = new VirtualGoodsModel();
+ $res = $virtual_goods_model->deleteGoodsVirtual([ [ 'order_id', '=', 0 ], [ 'id', 'in', $ids ], [ 'site_id', '=', $this->site_id ], [ 'goods_id', '=', $goods_id ] ]);
+ return $res;
+ }
+ }
+
+ /**
+ * 编辑卡密
+ * @return array
+ */
+ public function editGoodsVirtual()
+ {
+ if (request()->isJson()) {
+ $virtual_goods_model = new VirtualGoodsModel();
+ $id = input('id', '');
+ $card_info = [
+ 'cardno' => input('cardno', ''),
+ 'password' => input('password', '')
+ ];
+ $res = $virtual_goods_model->updateGoodsVirtual([ 'card_info' => json_encode($card_info) ], [ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ], [ 'order_id', '=', 0 ] ]);
+ return $res;
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/virtualevaluation/config/diy_view.php b/src/addon/virtualevaluation/config/diy_view.php
index c3c657905..e36ca9b7d 100644
--- a/src/addon/virtualevaluation/config/diy_view.php
+++ b/src/addon/virtualevaluation/config/diy_view.php
@@ -1,38 +1,30 @@
- '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
- 'template' => [],
-
- // 后台自定义组件——装修
- 'util' => [],
-
- // 自定义页面路径
- 'link' => [],
-
- // 自定义图标库
- 'icon_library' => [],
-
- // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
- 'component' => [],
-
- // uni-app 页面,多个逗号隔开
- 'pages' => [],
-
- // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
- 'info' => [],
-
- // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
- 'theme' => [],
-
- // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
- 'data' => []
+ '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
+ 'template' => [],
+
+ // 后台自定义组件——装修
+ 'util' => [],
+
+ // 自定义页面路径
+ 'link' => [],
+
+ // 自定义图标库
+ 'icon_library' => [],
+
+ // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
+ 'component' => [],
+
+ // uni-app 页面,多个逗号隔开
+ 'pages' => [],
+
+ // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
+ 'info' => [],
+
+ // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
+ 'theme' => [],
+
+ // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
+ 'data' => []
];
\ No newline at end of file
diff --git a/src/addon/virtualevaluation/config/info.php b/src/addon/virtualevaluation/config/info.php
index 52eb46fcc..52abc6ff4 100644
--- a/src/addon/virtualevaluation/config/info.php
+++ b/src/addon/virtualevaluation/config/info.php
@@ -1,20 +1,12 @@
- 'virtualevaluation',
- 'title' => '虚拟评价',
- 'description' => '创建商品虚拟评价',
- 'type' => 'tool', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
- 'status' => 1,
- 'author' => '',
- 'version' => '5.3.1',
- 'version_no' => '525231212001',
- 'content' => '',
+ 'virtualevaluation',
+ 'title' => '虚拟评价',
+ 'description' => '创建商品虚拟评价',
+ 'type' => 'tool', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
+ 'status' => 1,
+ 'author' => '',
+ 'version' => '5.3.1',
+ 'version_no' => '525231212001',
+ 'content' => '',
];
\ No newline at end of file
diff --git a/src/addon/virtualevaluation/event/Install.php b/src/addon/virtualevaluation/event/Install.php
index 4ca6f934f..dd64c68a4 100644
--- a/src/addon/virtualevaluation/event/Install.php
+++ b/src/addon/virtualevaluation/event/Install.php
@@ -1,26 +1,18 @@
-getOrderEvaluateConfig($site_id)[ 'data' ][ 'value' ];
-
- if ($data[ 'dengji' ] == 1) {
- $evaluate_type = 3;
- } else if ($data[ 'dengji' ] == 2 || $data[ 'dengji' ] == 3) {
- $evaluate_type = 2;
- } else if ($data[ 'dengji' ] == 4 || $data[ 'dengji' ] == 5) {
- $evaluate_type = 1;
- }
- // 虚拟评价不需要审核
- $order_evaluate_config[ 'evaluate_audit' ] = 0;
-
- if (!empty($data[ 'goods_data' ])) {
- foreach ($data[ 'goods_data' ] as $k => $v) {
- $item = [
- 'order_id' => 0,
- 'order_no' => 0,
- 'member_id' => 0,
- 'member_name' => $data[ 'member_name' ],
- 'member_headimg' => $data[ 'member_headimg' ],
- 'is_anonymous' => 1,
- 'order_goods_id' => 0,
- 'goods_id' => $v[ 'goods_id' ],
- 'sku_id' => $v[ 'sku_id' ],
- 'site_id' => $site_id,
- 'sku_name' => $v[ 'goods_name' ],
- 'sku_price' => $v[ 'price' ],
- 'sku_image' => explode(',', $v[ 'goods_image' ])[ 0 ],
- 'content' => !empty($data[ 'content' ]) ? $data[ 'content' ] : '此用户没有填写评价。',
- 'images' => $data[ 'pingjia_img' ],
- 'scores' => $data[ 'dengji' ],
- 'explain_type' => $evaluate_type,
- 'is_audit' => $order_evaluate_config[ 'evaluate_audit' ] == 1 ? 0 : 1,
- 'create_time' => date_to_time($data[ 'evaluate_time' ]),
- ];
- $data_arr[] = $item;
-
- $evaluate = 0; //评价
- $evaluate_shaitu = 0; //晒图
- $evaluate_shipin = 0; //视频
- $evaluate_haoping = 0; //好评
- $evaluate_zhongping = 0; //中评
- $evaluate_chaping = 0; //差评
- $wait_evaluate_num = 0; //待审核数
- $success_evaluate_num = 1;
-
- if ($order_evaluate_config[ 'evaluate_audit' ] == 1) {
- $wait_evaluate_num = 1; //待审核数
- $success_evaluate_num = 0;
- } else {
- if ($evaluate_type == 1) {
- //好评
- $evaluate = 1; //评价
- $evaluate_haoping = 1; //好评
-
- } elseif ($evaluate_type == 2) {
- //中评
- $evaluate = 1; //评价
- $evaluate_zhongping = 1; //中评
-
- } elseif ($evaluate_type == 3) {
- //差评
- $evaluate = 1; //评价
- $evaluate_chaping = 1; //差评
- }
- if (!empty($data[ 'pingjia_img' ])) {
- $evaluate_shaitu = 1; //晒图
- }
- }
-
- Db::name('goods')->where([ [ 'goods_id', '=', $v[ 'goods_id' ] ] ])
- ->update(
- [
- "evaluate" => Db::raw('evaluate+' . $evaluate),
- "success_evaluate_num" => Db::raw('success_evaluate_num+' . $success_evaluate_num),
- "evaluate_shaitu" => Db::raw('evaluate_shaitu+' . $evaluate_shaitu),
- "evaluate_haoping" => Db::raw('evaluate_haoping+' . $evaluate_haoping),
- "evaluate_zhongping" => Db::raw('evaluate_zhongping+' . $evaluate_zhongping),
- "evaluate_chaping" => Db::raw('evaluate_chaping+' . $evaluate_chaping),
- "wait_evaluate_num" => Db::raw('wait_evaluate_num+' . $wait_evaluate_num),
- ]);
- Db::name('goods_sku')->where([ [ 'sku_id', '=', $v[ 'sku_id' ] ] ])
- ->update(
- [
- "evaluate" => Db::raw('evaluate+' . $evaluate),
- "evaluate_shaitu" => Db::raw('evaluate_shaitu+' . $evaluate_shaitu),
- "evaluate_haoping" => Db::raw('evaluate_haoping+' . $evaluate_haoping),
- "evaluate_zhongping" => Db::raw('evaluate_zhongping+' . $evaluate_zhongping),
- "evaluate_chaping" => Db::raw('evaluate_chaping+' . $evaluate_chaping),
- "wait_evaluate_num" => Db::raw('wait_evaluate_num+' . $wait_evaluate_num),
- "success_evaluate_num" => Db::raw('success_evaluate_num+' . $success_evaluate_num),
- ]);
- }
- $evaluate_id = model('goods_evaluate')->addList($data_arr);
- Cache::tag('goods_evaluate')->clear();
- return $this->success($evaluate_id);
- } else {
- return $this->error();
- }
-
- }
-
- public function batghAdd($data, $site_id)
- {
- $config_model = new ConfigModel();
- //订单评价设置
- $order_evaluate_config = $config_model->getOrderEvaluateConfig($site_id)[ 'data' ][ 'value' ];
-
- //虚拟评价不需要审核
- $order_evaluate_config[ 'evaluate_audit' ] = 0;
-
- $content_list = model('stock_content')->getList([ [ 'site_id', '=', $site_id ], [ 'stock_id', '=', $data[ 'stock_id' ] ] ], 'content');
- $pic_list = model('album_pic')->getList([ [ 'site_id', '=', $site_id ], [ 'album_id', '=', $data[ 'album_id' ] ] ], 'pic_path');
- $goods_data = model('goods')->getInfo([ [ 'goods_id', '=', $data[ 'goods_id' ] ], [ 'site_id', '=', $site_id ] ], 'sku_id,goods_id,goods_name,price,goods_image');
- if ($data[ 'number' ] > 100 || $data[ 'number' ] < 1) {
- return $this->error([], '评价数量大于1且小于100条');
- }
- if ($data[ 'number' ] >= 1) {
- for ($i = 0; $i < $data[ 'number' ]; $i++) {
- $dengji[ $i ] = $data[ 'pingfen' ][ array_rand($data[ 'pingfen' ]) ];
-
- if ($dengji[ $i ] == 1) {
- $evaluate_type[ $i ] = 3;
- } else if ($dengji[ $i ] == 2 || $dengji[ $i ] == 3) {
- $evaluate_type[ $i ] = 2;
- } else if ($dengji[ $i ] == 4 || $dengji[ $i ] == 5) {
- $evaluate_type[ $i ] = 1;
- }
-
- $item = [
- 'order_id' => 0,
- 'order_no' => 0,
- 'member_id' => 0,
- 'member_name' => $this->randNickName(),
- 'member_headimg' => $pic_list[ array_rand($pic_list) ][ 'pic_path' ],
- 'is_anonymous' => 1,
- 'order_goods_id' => 0,
- 'goods_id' => $goods_data[ 'goods_id' ],
- 'sku_id' => $goods_data[ 'sku_id' ],
- 'site_id' => $site_id,
- 'sku_name' => $goods_data[ 'goods_name' ],
- 'sku_price' => $goods_data[ 'price' ],
- 'sku_image' => explode(',', $goods_data[ 'goods_image' ])[ 0 ],
- 'content' => $content_list[ array_rand($content_list) ][ 'content' ],
- 'images' => '',
- 'scores' => $dengji[ $i ],
- 'explain_type' => $evaluate_type[ $i ],
- 'is_audit' => $order_evaluate_config[ 'evaluate_audit' ] == 1 ? 0 : 1,
- 'create_time' => mt_rand($data[ 'start_time' ], $data[ 'end_time' ]),
- ];
- $data_arr[] = $item;
-
- $evaluate = 0; //评价
- $evaluate_shaitu = 0; //晒图
- $evaluate_shipin = 0; //视频
- $evaluate_haoping = 0; //好评
- $evaluate_zhongping = 0; //中评
- $evaluate_chaping = 0; //差评
- $wait_evaluate_num = 0; //待审核数
- $success_evaluate_num = 1;
-
- if ($order_evaluate_config[ 'evaluate_audit' ] == 1) {
- $wait_evaluate_num = 1; //待审核数
- $success_evaluate_num = 0;
- } else {
- if ($evaluate_type[ $i ] == 1) {
- //好评
- $evaluate = 1; //评价
- $evaluate_haoping = 1; //好评
-
- } elseif ($evaluate_type[ $i ] == 2) {
- //中评
- $evaluate = 1; //评价
- $evaluate_zhongping = 1; //中评
-
- } elseif ($evaluate_type[ $i ] == 3) {
- //差评
- $evaluate = 1; //评价
- $evaluate_chaping = 1; //差评
- }
- if (!empty($item[ 'images' ])) {
- $evaluate_shaitu = 1; //晒图
- }
- }
-
- Db::name('goods')->where([ [ 'goods_id', '=', $goods_data[ 'goods_id' ] ] ])
- ->update(
- [
- "evaluate" => Db::raw('evaluate+' . $evaluate),
- "evaluate_shaitu" => Db::raw('evaluate_shaitu+' . $evaluate_shaitu),
- "evaluate_haoping" => Db::raw('evaluate_haoping+' . $evaluate_haoping),
- "evaluate_zhongping" => Db::raw('evaluate_zhongping+' . $evaluate_zhongping),
- "evaluate_chaping" => Db::raw('evaluate_chaping+' . $evaluate_chaping),
- "wait_evaluate_num" => Db::raw('wait_evaluate_num+' . $wait_evaluate_num),
- "success_evaluate_num" => Db::raw('success_evaluate_num+' . $success_evaluate_num),
- ]);
- Db::name('goods_sku')->where([ [ 'sku_id', '=', $goods_data[ 'sku_id' ] ] ])
- ->update(
- [
- "evaluate" => Db::raw('evaluate+' . $evaluate),
- "evaluate_shaitu" => Db::raw('evaluate_shaitu+' . $evaluate_shaitu),
- "evaluate_haoping" => Db::raw('evaluate_haoping+' . $evaluate_haoping),
- "evaluate_zhongping" => Db::raw('evaluate_zhongping+' . $evaluate_zhongping),
- "evaluate_chaping" => Db::raw('evaluate_chaping+' . $evaluate_chaping),
- "wait_evaluate_num" => Db::raw('wait_evaluate_num+' . $wait_evaluate_num),
- "success_evaluate_num" => Db::raw('success_evaluate_num+' . $success_evaluate_num),
- ]);
- }
- $evaluate_id = model('goods_evaluate')->addList($data_arr);
- Cache::tag('goods_evaluate')->clear();
- return $this->success($evaluate_id);
- } else {
- return $this->error();
- }
-
- }
-
- private function randNickName()
- {
- $nicheng_tou = array ( '快乐的', '冷静的', '醉熏的', '潇洒的', '糊涂的', '积极的', '冷酷的', '深情的', '粗暴的',
- '温柔的', '可爱的', '愉快的', '义气的', '认真的', '威武的', '帅气的', '传统的', '潇洒的', '漂亮的', '自然的',
- '专一的', '听话的', '昏睡的', '狂野的', '等待的', '搞怪的', '幽默的', '魁梧的', '活泼的', '开心的', '高兴的',
- '超帅的', '留胡子的', '坦率的', '直率的', '轻松的', '痴情的', '完美的', '精明的',
- '无聊的', '有魅力的', '丰富的', '繁荣的', '饱满的', '炙热的', '暴躁的', '碧蓝的', '俊逸的',
- '英勇的', '健忘的', '故意的', '无心的', '土豪的', '朴实的', '兴奋的', '幸福的', '淡定的', '不安的',
- '阔达的', '孤独的', '独特的', '疯狂的', '时尚的', '落后的', '风趣的', '忧伤的', '大胆的', '爱笑的', '矮小的',
- '健康的', '合适的', '玩命的', '沉默的', '斯文的', '香蕉', '苹果', '鲤鱼', '鳗鱼', '任性的', '细心的', '粗心的',
- '大意的', '甜甜的', '酷酷的', '健壮的', '英俊的', '霸气的', '阳光的', '默默的', '大力的', '孝顺的', '忧虑的', '着急的',
- '紧张的', '善良的', '凶狠的', '害怕的', '重要的', '危机的', '欢喜的', '欣慰的', '满意的', '跳跃的', '诚心的', '称心的',
- '如意的', '怡然的', '娇气的', '无奈的', '无语的', '激动的', '愤怒的', '美好的', '感动的', '激情的', '激昂的', '震动的',
- '虚拟的', '超级的', '寒冷的', '精明的', '明理的', '犹豫的', '忧郁的', '寂寞的', '奋斗的', '勤奋的', '现代的', '过时的',
- '稳重的', '热情的', '含蓄的', '开放的', '无辜的', '多情的', '纯真的', '拉长的', '热心的', '从容的', '体贴的', '风中的',
- '曾经的', '追寻的', '儒雅的', '优雅的', '开朗的', '外向的', '内向的', '清爽的', '文艺的', '长情的', '平常的', '单身的',
- '伶俐的', '高大的', '懦弱的', '柔弱的', '爱笑的', '乐观的', '耍酷的', '酷炫的', '神勇的', '年轻的', '唠叨的', '瘦瘦的',
- '无情的', '包容的', '顺心的', '畅快的', '舒适的', '靓丽的', '负责的', '背后的', '简单的', '谦让的', '彩色的', '缥缈的',
- '欢呼的', '生动的', '复杂的', '慈祥的', '仁爱的', '魔幻的', '虚幻的', '淡然的', '受伤的', '雪白的', '高高的', '糟糕的',
- '顺利的', '闪闪的', '羞涩的', '缓慢的', '迅速的', '优秀的', '聪明的', '含糊的', '俏皮的', '淡淡的', '坚强的', '平淡的',
- '欣喜的', '能干的', '灵巧的', '友好的', '机智的', '机灵的', '正直的', '谨慎的', '俭朴的', '殷勤的', '虚心的', '辛勤的',
- '自觉的', '无私的', '无限的', '踏实的', '老实的', '现实的', '可靠的', '务实的', '拼搏的', '个性的', '粗犷的', '活力的',
- '成就的', '勤劳的', '单纯的', '落寞的', '朴素的', '悲凉的', '忧心的', '洁净的', '清秀的', '自由的', '小巧的', '单薄的',
- '贪玩的', '刻苦的', '干净的', '壮观的', '和谐的', '文静的', '调皮的', '害羞的', '安详的', '自信的', '端庄的', '坚定的',
- '美满的', '舒心的', '温暖的', '专注的', '勤恳的', '美丽的', '腼腆的', '优美的', '甜美的', '甜蜜的', '整齐的', '动人的',
- '典雅的', '尊敬的', '舒服的', '妩媚的', '秀丽的', '喜悦的', '甜美的', '彪壮的', '强健的', '大方的', '俊秀的', '聪慧的',
- '迷人的', '陶醉的', '悦耳的', '动听的', '明亮的', '结实的', '魁梧的', '标致的', '清脆的', '敏感的', '光亮的', '大气的',
- '老迟到的', '知性的', '冷傲的', '呆萌的', '野性的', '隐形的', '笑点低的', '微笑的', '笨笨的', '难过的', '沉静的', '火星上的',
- '失眠的', '安静的', '纯情的', '要减肥的', '迷路的', '烂漫的', '哭泣的', '贤惠的', '苗条的', '温婉的', '发嗲的', '会撒娇的',
- '贪玩的', '执着的', '眯眯眼的', '花痴的', '想人陪的', '眼睛大的', '高贵的', '傲娇的', '心灵美的', '爱撒娇的', '细腻的', '天真的',
- '怕黑的', '感性的', '飘逸的', '怕孤独的', '忐忑的', '高挑的', '傻傻的', '冷艳的', '爱听歌的', '还单身的', '怕孤单的', '懵懂的' );
-
- $nicheng_wei = array ( '嚓茶', '凉面', '便当', '毛豆', '花生', '可乐', '灯泡', '哈密瓜', '野狼', '背包', '眼神', '缘分', '雪碧',
- '人生', '牛排', '蚂蚁', '飞鸟', '灰狼', '斑马', '汉堡', '悟空', '巨人', '绿茶', '自行车', '保温杯', '大碗', '墨镜', '魔镜',
- '煎饼', '月饼', '月亮', '星星', '芝麻', '啤酒', '玫瑰', '大叔', '小伙', '哈密瓜,数据线', '太阳', '树叶', '芹菜', '黄蜂', '蜜粉',
- '蜜蜂', '信封', '西装', '外套', '裙子', '大象', '猫咪', '母鸡', '路灯', '蓝天', '白云', '星月', '彩虹', '微笑', '摩托', '板栗', '高山',
- '大地', '大树', '电灯胆', '砖头', '楼房', '水池', '鸡翅', '蜻蜓', '红牛', '咖啡', '机器猫', '枕头', '大船', '诺言', '钢笔', '刺猬', '天空',
- '飞机', '大炮', '冬天', '洋葱', '春天', '夏天', '秋天', '冬日', '航空', '毛衣', '豌豆', '黑米', '玉米', '眼睛', '老鼠', '白羊', '帅哥', '美女',
- '季节', '鲜花', '服饰', '裙子', '白开水', '秀发', '大山', '火车', '汽车', '歌曲', '舞蹈', '老师', '导师', '方盒', '大米', '麦片', '水杯', '水壶',
- '手套', '鞋子', '自行车', '鼠标', '手机', '电脑', '书本', '奇迹', '身影', '香烟', '夕阳', '台灯', '宝贝', '未来', '皮带', '钥匙', '心锁', '故事',
- '花瓣', '滑板', '画笔', '画板', '学姐', '店员', '电源', '饼干', '宝马', '过客', '大白', '时光', '石头', '钻石', '河马', '犀牛', '西牛', '绿草',
- '抽屉', '柜子', '往事', '寒风', '路人', '橘子', '耳机', '鸵鸟', '朋友', '苗条', '铅笔', '钢笔', '硬币', '热狗', '大侠', '御姐', '萝莉', '毛巾',
- '期待', '盼望', '白昼', '黑夜', '大门', '黑裤', '钢铁侠', '哑铃', '板凳', '枫叶', '荷花', '乌龟', '仙人掌', '衬衫', '大神', '草丛', '早晨', '心情',
- '茉莉', '流沙', '蜗牛', '战斗机', '冥王星', '猎豹', '棒球', '篮球', '乐曲', '电话', '网络', '世界', '中心', '鱼', '鸡', '狗', '老虎', '鸭子', '雨',
- '羽毛', '翅膀', '外套', '火', '丝袜', '书包', '钢笔', '冷风', '八宝粥', '烤鸡', '大雁', '音响', '招牌', '胡萝卜', '冰棍', '帽子', '菠萝', '蛋挞', '香水',
- '泥猴桃', '吐司', '溪流', '黄豆', '樱桃', '小鸽子', '小蝴蝶', '爆米花', '花卷', '小鸭子', '小海豚', '日记本', '小熊猫', '小懒猪', '小懒虫', '荔枝', '镜子',
- '曲奇', '金针菇', '小松鼠', '小虾米', '酒窝', '紫菜', '金鱼', '柚子', '果汁', '百褶裙', '项链', '帆布鞋', '火龙果', '奇异果', '煎蛋', '唇彩', '小土豆', '高跟鞋',
- '戒指', '雪糕', '睫毛', '铃铛', '手链', '香氛', '红酒', '月光', '酸奶', '银耳汤', '咖啡豆', '小蜜蜂', '小蚂蚁', '蜡烛', '棉花糖', '向日葵', '水蜜桃', '小蝴蝶',
- '小刺猬', '小丸子', '指甲油', '康乃馨', '糖豆', '薯片', '口红', '超短裙', '乌冬面', '冰淇淋', '棒棒糖', '长颈鹿', '豆芽', '发箍', '发卡', '发夹', '发带', '铃铛',
- '小馒头', '小笼包', '小甜瓜', '冬瓜', '香菇', '小兔子', '含羞草', '短靴', '睫毛膏', '小蘑菇', '跳跳糖', '小白菜', '草莓', '柠檬', '月饼', '百合', '纸鹤', '小天鹅',
- '云朵', '芒果', '面包', '海燕', '小猫咪', '龙猫', '唇膏', '鞋垫', '羊', '黑猫', '白猫', '万宝路', '金毛', '山水', '音响' );
-
- $tou_num = rand(0, 331);
-
- $wei_num = rand(0, 325);
-
- $nicheng = $nicheng_tou[ $tou_num ] . $nicheng_wei[ $wei_num ];
-
- return $nicheng; //输出生成的昵称
- }
+getOrderEvaluateConfig($site_id)[ 'data' ][ 'value' ];
+
+ if ($data[ 'dengji' ] == 1) {
+ $evaluate_type = 3;
+ } else if ($data[ 'dengji' ] == 2 || $data[ 'dengji' ] == 3) {
+ $evaluate_type = 2;
+ } else if ($data[ 'dengji' ] == 4 || $data[ 'dengji' ] == 5) {
+ $evaluate_type = 1;
+ }
+ // 虚拟评价不需要审核
+ $order_evaluate_config[ 'evaluate_audit' ] = 0;
+
+ if (!empty($data[ 'goods_data' ])) {
+ foreach ($data[ 'goods_data' ] as $k => $v) {
+ $item = [
+ 'order_id' => 0,
+ 'order_no' => 0,
+ 'member_id' => 0,
+ 'member_name' => $data[ 'member_name' ],
+ 'member_headimg' => $data[ 'member_headimg' ],
+ 'is_anonymous' => 1,
+ 'order_goods_id' => 0,
+ 'goods_id' => $v[ 'goods_id' ],
+ 'sku_id' => $v[ 'sku_id' ],
+ 'site_id' => $site_id,
+ 'sku_name' => $v[ 'goods_name' ],
+ 'sku_price' => $v[ 'price' ],
+ 'sku_image' => explode(',', $v[ 'goods_image' ])[ 0 ],
+ 'content' => !empty($data[ 'content' ]) ? $data[ 'content' ] : '此用户没有填写评价。',
+ 'images' => $data[ 'pingjia_img' ],
+ 'scores' => $data[ 'dengji' ],
+ 'explain_type' => $evaluate_type,
+ 'is_audit' => $order_evaluate_config[ 'evaluate_audit' ] == 1 ? 0 : 1,
+ 'create_time' => date_to_time($data[ 'evaluate_time' ]),
+ ];
+ $data_arr[] = $item;
+
+ $evaluate = 0; //评价
+ $evaluate_shaitu = 0; //晒图
+ $evaluate_shipin = 0; //视频
+ $evaluate_haoping = 0; //好评
+ $evaluate_zhongping = 0; //中评
+ $evaluate_chaping = 0; //差评
+ $wait_evaluate_num = 0; //待审核数
+ $success_evaluate_num = 1;
+
+ if ($order_evaluate_config[ 'evaluate_audit' ] == 1) {
+ $wait_evaluate_num = 1; //待审核数
+ $success_evaluate_num = 0;
+ } else {
+ if ($evaluate_type == 1) {
+ //好评
+ $evaluate = 1; //评价
+ $evaluate_haoping = 1; //好评
+
+ } elseif ($evaluate_type == 2) {
+ //中评
+ $evaluate = 1; //评价
+ $evaluate_zhongping = 1; //中评
+
+ } elseif ($evaluate_type == 3) {
+ //差评
+ $evaluate = 1; //评价
+ $evaluate_chaping = 1; //差评
+ }
+ if (!empty($data[ 'pingjia_img' ])) {
+ $evaluate_shaitu = 1; //晒图
+ }
+ }
+
+ Db::name('goods')->where([ [ 'goods_id', '=', $v[ 'goods_id' ] ] ])
+ ->update(
+ [
+ "evaluate" => Db::raw('evaluate+' . $evaluate),
+ "success_evaluate_num" => Db::raw('success_evaluate_num+' . $success_evaluate_num),
+ "evaluate_shaitu" => Db::raw('evaluate_shaitu+' . $evaluate_shaitu),
+ "evaluate_haoping" => Db::raw('evaluate_haoping+' . $evaluate_haoping),
+ "evaluate_zhongping" => Db::raw('evaluate_zhongping+' . $evaluate_zhongping),
+ "evaluate_chaping" => Db::raw('evaluate_chaping+' . $evaluate_chaping),
+ "wait_evaluate_num" => Db::raw('wait_evaluate_num+' . $wait_evaluate_num),
+ ]);
+ Db::name('goods_sku')->where([ [ 'sku_id', '=', $v[ 'sku_id' ] ] ])
+ ->update(
+ [
+ "evaluate" => Db::raw('evaluate+' . $evaluate),
+ "evaluate_shaitu" => Db::raw('evaluate_shaitu+' . $evaluate_shaitu),
+ "evaluate_haoping" => Db::raw('evaluate_haoping+' . $evaluate_haoping),
+ "evaluate_zhongping" => Db::raw('evaluate_zhongping+' . $evaluate_zhongping),
+ "evaluate_chaping" => Db::raw('evaluate_chaping+' . $evaluate_chaping),
+ "wait_evaluate_num" => Db::raw('wait_evaluate_num+' . $wait_evaluate_num),
+ "success_evaluate_num" => Db::raw('success_evaluate_num+' . $success_evaluate_num),
+ ]);
+ }
+ $evaluate_id = model('goods_evaluate')->addList($data_arr);
+ Cache::tag('goods_evaluate')->clear();
+ return $this->success($evaluate_id);
+ } else {
+ return $this->error();
+ }
+
+ }
+
+ public function batghAdd($data, $site_id)
+ {
+ $config_model = new ConfigModel();
+ //订单评价设置
+ $order_evaluate_config = $config_model->getOrderEvaluateConfig($site_id)[ 'data' ][ 'value' ];
+
+ //虚拟评价不需要审核
+ $order_evaluate_config[ 'evaluate_audit' ] = 0;
+
+ $content_list = model('stock_content')->getList([ [ 'site_id', '=', $site_id ], [ 'stock_id', '=', $data[ 'stock_id' ] ] ], 'content');
+ $pic_list = model('album_pic')->getList([ [ 'site_id', '=', $site_id ], [ 'album_id', '=', $data[ 'album_id' ] ] ], 'pic_path');
+ $goods_data = model('goods')->getInfo([ [ 'goods_id', '=', $data[ 'goods_id' ] ], [ 'site_id', '=', $site_id ] ], 'sku_id,goods_id,goods_name,price,goods_image');
+ if ($data[ 'number' ] > 100 || $data[ 'number' ] < 1) {
+ return $this->error([], '评价数量大于1且小于100条');
+ }
+ if ($data[ 'number' ] >= 1) {
+ for ($i = 0; $i < $data[ 'number' ]; $i++) {
+ $dengji[ $i ] = $data[ 'pingfen' ][ array_rand($data[ 'pingfen' ]) ];
+
+ if ($dengji[ $i ] == 1) {
+ $evaluate_type[ $i ] = 3;
+ } else if ($dengji[ $i ] == 2 || $dengji[ $i ] == 3) {
+ $evaluate_type[ $i ] = 2;
+ } else if ($dengji[ $i ] == 4 || $dengji[ $i ] == 5) {
+ $evaluate_type[ $i ] = 1;
+ }
+
+ $item = [
+ 'order_id' => 0,
+ 'order_no' => 0,
+ 'member_id' => 0,
+ 'member_name' => $this->randNickName(),
+ 'member_headimg' => $pic_list[ array_rand($pic_list) ][ 'pic_path' ],
+ 'is_anonymous' => 1,
+ 'order_goods_id' => 0,
+ 'goods_id' => $goods_data[ 'goods_id' ],
+ 'sku_id' => $goods_data[ 'sku_id' ],
+ 'site_id' => $site_id,
+ 'sku_name' => $goods_data[ 'goods_name' ],
+ 'sku_price' => $goods_data[ 'price' ],
+ 'sku_image' => explode(',', $goods_data[ 'goods_image' ])[ 0 ],
+ 'content' => $content_list[ array_rand($content_list) ][ 'content' ],
+ 'images' => '',
+ 'scores' => $dengji[ $i ],
+ 'explain_type' => $evaluate_type[ $i ],
+ 'is_audit' => $order_evaluate_config[ 'evaluate_audit' ] == 1 ? 0 : 1,
+ 'create_time' => mt_rand($data[ 'start_time' ], $data[ 'end_time' ]),
+ ];
+ $data_arr[] = $item;
+
+ $evaluate = 0; //评价
+ $evaluate_shaitu = 0; //晒图
+ $evaluate_shipin = 0; //视频
+ $evaluate_haoping = 0; //好评
+ $evaluate_zhongping = 0; //中评
+ $evaluate_chaping = 0; //差评
+ $wait_evaluate_num = 0; //待审核数
+ $success_evaluate_num = 1;
+
+ if ($order_evaluate_config[ 'evaluate_audit' ] == 1) {
+ $wait_evaluate_num = 1; //待审核数
+ $success_evaluate_num = 0;
+ } else {
+ if ($evaluate_type[ $i ] == 1) {
+ //好评
+ $evaluate = 1; //评价
+ $evaluate_haoping = 1; //好评
+
+ } elseif ($evaluate_type[ $i ] == 2) {
+ //中评
+ $evaluate = 1; //评价
+ $evaluate_zhongping = 1; //中评
+
+ } elseif ($evaluate_type[ $i ] == 3) {
+ //差评
+ $evaluate = 1; //评价
+ $evaluate_chaping = 1; //差评
+ }
+ if (!empty($item[ 'images' ])) {
+ $evaluate_shaitu = 1; //晒图
+ }
+ }
+
+ Db::name('goods')->where([ [ 'goods_id', '=', $goods_data[ 'goods_id' ] ] ])
+ ->update(
+ [
+ "evaluate" => Db::raw('evaluate+' . $evaluate),
+ "evaluate_shaitu" => Db::raw('evaluate_shaitu+' . $evaluate_shaitu),
+ "evaluate_haoping" => Db::raw('evaluate_haoping+' . $evaluate_haoping),
+ "evaluate_zhongping" => Db::raw('evaluate_zhongping+' . $evaluate_zhongping),
+ "evaluate_chaping" => Db::raw('evaluate_chaping+' . $evaluate_chaping),
+ "wait_evaluate_num" => Db::raw('wait_evaluate_num+' . $wait_evaluate_num),
+ "success_evaluate_num" => Db::raw('success_evaluate_num+' . $success_evaluate_num),
+ ]);
+ Db::name('goods_sku')->where([ [ 'sku_id', '=', $goods_data[ 'sku_id' ] ] ])
+ ->update(
+ [
+ "evaluate" => Db::raw('evaluate+' . $evaluate),
+ "evaluate_shaitu" => Db::raw('evaluate_shaitu+' . $evaluate_shaitu),
+ "evaluate_haoping" => Db::raw('evaluate_haoping+' . $evaluate_haoping),
+ "evaluate_zhongping" => Db::raw('evaluate_zhongping+' . $evaluate_zhongping),
+ "evaluate_chaping" => Db::raw('evaluate_chaping+' . $evaluate_chaping),
+ "wait_evaluate_num" => Db::raw('wait_evaluate_num+' . $wait_evaluate_num),
+ "success_evaluate_num" => Db::raw('success_evaluate_num+' . $success_evaluate_num),
+ ]);
+ }
+ $evaluate_id = model('goods_evaluate')->addList($data_arr);
+ Cache::tag('goods_evaluate')->clear();
+ return $this->success($evaluate_id);
+ } else {
+ return $this->error();
+ }
+
+ }
+
+ private function randNickName()
+ {
+ $nicheng_tou = array ( '快乐的', '冷静的', '醉熏的', '潇洒的', '糊涂的', '积极的', '冷酷的', '深情的', '粗暴的',
+ '温柔的', '可爱的', '愉快的', '义气的', '认真的', '威武的', '帅气的', '传统的', '潇洒的', '漂亮的', '自然的',
+ '专一的', '听话的', '昏睡的', '狂野的', '等待的', '搞怪的', '幽默的', '魁梧的', '活泼的', '开心的', '高兴的',
+ '超帅的', '留胡子的', '坦率的', '直率的', '轻松的', '痴情的', '完美的', '精明的',
+ '无聊的', '有魅力的', '丰富的', '繁荣的', '饱满的', '炙热的', '暴躁的', '碧蓝的', '俊逸的',
+ '英勇的', '健忘的', '故意的', '无心的', '土豪的', '朴实的', '兴奋的', '幸福的', '淡定的', '不安的',
+ '阔达的', '孤独的', '独特的', '疯狂的', '时尚的', '落后的', '风趣的', '忧伤的', '大胆的', '爱笑的', '矮小的',
+ '健康的', '合适的', '玩命的', '沉默的', '斯文的', '香蕉', '苹果', '鲤鱼', '鳗鱼', '任性的', '细心的', '粗心的',
+ '大意的', '甜甜的', '酷酷的', '健壮的', '英俊的', '霸气的', '阳光的', '默默的', '大力的', '孝顺的', '忧虑的', '着急的',
+ '紧张的', '善良的', '凶狠的', '害怕的', '重要的', '危机的', '欢喜的', '欣慰的', '满意的', '跳跃的', '诚心的', '称心的',
+ '如意的', '怡然的', '娇气的', '无奈的', '无语的', '激动的', '愤怒的', '美好的', '感动的', '激情的', '激昂的', '震动的',
+ '虚拟的', '超级的', '寒冷的', '精明的', '明理的', '犹豫的', '忧郁的', '寂寞的', '奋斗的', '勤奋的', '现代的', '过时的',
+ '稳重的', '热情的', '含蓄的', '开放的', '无辜的', '多情的', '纯真的', '拉长的', '热心的', '从容的', '体贴的', '风中的',
+ '曾经的', '追寻的', '儒雅的', '优雅的', '开朗的', '外向的', '内向的', '清爽的', '文艺的', '长情的', '平常的', '单身的',
+ '伶俐的', '高大的', '懦弱的', '柔弱的', '爱笑的', '乐观的', '耍酷的', '酷炫的', '神勇的', '年轻的', '唠叨的', '瘦瘦的',
+ '无情的', '包容的', '顺心的', '畅快的', '舒适的', '靓丽的', '负责的', '背后的', '简单的', '谦让的', '彩色的', '缥缈的',
+ '欢呼的', '生动的', '复杂的', '慈祥的', '仁爱的', '魔幻的', '虚幻的', '淡然的', '受伤的', '雪白的', '高高的', '糟糕的',
+ '顺利的', '闪闪的', '羞涩的', '缓慢的', '迅速的', '优秀的', '聪明的', '含糊的', '俏皮的', '淡淡的', '坚强的', '平淡的',
+ '欣喜的', '能干的', '灵巧的', '友好的', '机智的', '机灵的', '正直的', '谨慎的', '俭朴的', '殷勤的', '虚心的', '辛勤的',
+ '自觉的', '无私的', '无限的', '踏实的', '老实的', '现实的', '可靠的', '务实的', '拼搏的', '个性的', '粗犷的', '活力的',
+ '成就的', '勤劳的', '单纯的', '落寞的', '朴素的', '悲凉的', '忧心的', '洁净的', '清秀的', '自由的', '小巧的', '单薄的',
+ '贪玩的', '刻苦的', '干净的', '壮观的', '和谐的', '文静的', '调皮的', '害羞的', '安详的', '自信的', '端庄的', '坚定的',
+ '美满的', '舒心的', '温暖的', '专注的', '勤恳的', '美丽的', '腼腆的', '优美的', '甜美的', '甜蜜的', '整齐的', '动人的',
+ '典雅的', '尊敬的', '舒服的', '妩媚的', '秀丽的', '喜悦的', '甜美的', '彪壮的', '强健的', '大方的', '俊秀的', '聪慧的',
+ '迷人的', '陶醉的', '悦耳的', '动听的', '明亮的', '结实的', '魁梧的', '标致的', '清脆的', '敏感的', '光亮的', '大气的',
+ '老迟到的', '知性的', '冷傲的', '呆萌的', '野性的', '隐形的', '笑点低的', '微笑的', '笨笨的', '难过的', '沉静的', '火星上的',
+ '失眠的', '安静的', '纯情的', '要减肥的', '迷路的', '烂漫的', '哭泣的', '贤惠的', '苗条的', '温婉的', '发嗲的', '会撒娇的',
+ '贪玩的', '执着的', '眯眯眼的', '花痴的', '想人陪的', '眼睛大的', '高贵的', '傲娇的', '心灵美的', '爱撒娇的', '细腻的', '天真的',
+ '怕黑的', '感性的', '飘逸的', '怕孤独的', '忐忑的', '高挑的', '傻傻的', '冷艳的', '爱听歌的', '还单身的', '怕孤单的', '懵懂的' );
+
+ $nicheng_wei = array ( '嚓茶', '凉面', '便当', '毛豆', '花生', '可乐', '灯泡', '哈密瓜', '野狼', '背包', '眼神', '缘分', '雪碧',
+ '人生', '牛排', '蚂蚁', '飞鸟', '灰狼', '斑马', '汉堡', '悟空', '巨人', '绿茶', '自行车', '保温杯', '大碗', '墨镜', '魔镜',
+ '煎饼', '月饼', '月亮', '星星', '芝麻', '啤酒', '玫瑰', '大叔', '小伙', '哈密瓜,数据线', '太阳', '树叶', '芹菜', '黄蜂', '蜜粉',
+ '蜜蜂', '信封', '西装', '外套', '裙子', '大象', '猫咪', '母鸡', '路灯', '蓝天', '白云', '星月', '彩虹', '微笑', '摩托', '板栗', '高山',
+ '大地', '大树', '电灯胆', '砖头', '楼房', '水池', '鸡翅', '蜻蜓', '红牛', '咖啡', '机器猫', '枕头', '大船', '诺言', '钢笔', '刺猬', '天空',
+ '飞机', '大炮', '冬天', '洋葱', '春天', '夏天', '秋天', '冬日', '航空', '毛衣', '豌豆', '黑米', '玉米', '眼睛', '老鼠', '白羊', '帅哥', '美女',
+ '季节', '鲜花', '服饰', '裙子', '白开水', '秀发', '大山', '火车', '汽车', '歌曲', '舞蹈', '老师', '导师', '方盒', '大米', '麦片', '水杯', '水壶',
+ '手套', '鞋子', '自行车', '鼠标', '手机', '电脑', '书本', '奇迹', '身影', '香烟', '夕阳', '台灯', '宝贝', '未来', '皮带', '钥匙', '心锁', '故事',
+ '花瓣', '滑板', '画笔', '画板', '学姐', '店员', '电源', '饼干', '宝马', '过客', '大白', '时光', '石头', '钻石', '河马', '犀牛', '西牛', '绿草',
+ '抽屉', '柜子', '往事', '寒风', '路人', '橘子', '耳机', '鸵鸟', '朋友', '苗条', '铅笔', '钢笔', '硬币', '热狗', '大侠', '御姐', '萝莉', '毛巾',
+ '期待', '盼望', '白昼', '黑夜', '大门', '黑裤', '钢铁侠', '哑铃', '板凳', '枫叶', '荷花', '乌龟', '仙人掌', '衬衫', '大神', '草丛', '早晨', '心情',
+ '茉莉', '流沙', '蜗牛', '战斗机', '冥王星', '猎豹', '棒球', '篮球', '乐曲', '电话', '网络', '世界', '中心', '鱼', '鸡', '狗', '老虎', '鸭子', '雨',
+ '羽毛', '翅膀', '外套', '火', '丝袜', '书包', '钢笔', '冷风', '八宝粥', '烤鸡', '大雁', '音响', '招牌', '胡萝卜', '冰棍', '帽子', '菠萝', '蛋挞', '香水',
+ '泥猴桃', '吐司', '溪流', '黄豆', '樱桃', '小鸽子', '小蝴蝶', '爆米花', '花卷', '小鸭子', '小海豚', '日记本', '小熊猫', '小懒猪', '小懒虫', '荔枝', '镜子',
+ '曲奇', '金针菇', '小松鼠', '小虾米', '酒窝', '紫菜', '金鱼', '柚子', '果汁', '百褶裙', '项链', '帆布鞋', '火龙果', '奇异果', '煎蛋', '唇彩', '小土豆', '高跟鞋',
+ '戒指', '雪糕', '睫毛', '铃铛', '手链', '香氛', '红酒', '月光', '酸奶', '银耳汤', '咖啡豆', '小蜜蜂', '小蚂蚁', '蜡烛', '棉花糖', '向日葵', '水蜜桃', '小蝴蝶',
+ '小刺猬', '小丸子', '指甲油', '康乃馨', '糖豆', '薯片', '口红', '超短裙', '乌冬面', '冰淇淋', '棒棒糖', '长颈鹿', '豆芽', '发箍', '发卡', '发夹', '发带', '铃铛',
+ '小馒头', '小笼包', '小甜瓜', '冬瓜', '香菇', '小兔子', '含羞草', '短靴', '睫毛膏', '小蘑菇', '跳跳糖', '小白菜', '草莓', '柠檬', '月饼', '百合', '纸鹤', '小天鹅',
+ '云朵', '芒果', '面包', '海燕', '小猫咪', '龙猫', '唇膏', '鞋垫', '羊', '黑猫', '白猫', '万宝路', '金毛', '山水', '音响' );
+
+ $tou_num = rand(0, 331);
+
+ $wei_num = rand(0, 325);
+
+ $nicheng = $nicheng_tou[ $tou_num ] . $nicheng_wei[ $wei_num ];
+
+ return $nicheng; //输出生成的昵称
+ }
}
\ No newline at end of file
diff --git a/src/addon/virtualevaluation/model/VirtualStock.php b/src/addon/virtualevaluation/model/VirtualStock.php
index 399bf9fec..334f91cbd 100644
--- a/src/addon/virtualevaluation/model/VirtualStock.php
+++ b/src/addon/virtualevaluation/model/VirtualStock.php
@@ -1,186 +1,178 @@
-pageList($condition, $field, $order, $page, $page_size);
- return $this->success($list);
- }
-
- /**
- * 添加虚拟评价库分页列表
- * @param array $condition
- * @param number $page
- * @param string $page_size
- * @param string $order
- * @param string $field
- */
- public function addStock($data)
- {
- $stock_id = model('virtual_stock')->add($data);
- return $this->success($stock_id);
- }
-
- /**
- * 删除虚拟评价库
- * @param array $condition
- * @param number $page
- * @param string $page_size
- * @param string $order
- * @param string $field
- */
- public function deleteStock($stock_id, $site_id)
- {
- $stock_id = model('virtual_stock')->delete([ [ 'stock_id', '=', $stock_id ], [ 'site_id', '=', $site_id ] ]);
-
- return $this->success($stock_id);
- }
-
- /**
- * 更新虚拟评价库
- * @param array $condition
- * @param number $page
- * @param string $page_size
- * @param string $order
- * @param string $field
- */
- public function updateStock($data, $site_id)
- {
- $stock_id = model('virtual_stock')->update($data, [ [ 'stock_id', '=', $data[ 'stock_id' ] ], [ 'site_id', '=', $site_id ] ]);
-
- return $this->success($stock_id);
- }
-
- /**
- * 获取虚拟评价库信息
- * @param array $condition
- * @param number $page
- * @param string $page_size
- * @param string $order
- * @param string $field
- */
- public function getStockInfo($stock_id, $site_id)
- {
- $stock_info = model('virtual_stock')->getInfo([ [ 'stock_id', '=', $stock_id ], [ 'site_id', '=', $site_id ] ], '*');
-
- return $this->success($stock_info);
- }
-
- /**
- * 获取虚拟评价库信息
- * @param array $condition
- * @param number $page
- * @param string $page_size
- * @param string $order
- * @param string $field
- */
- public function getContentsPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'create_time desc', $field = '*')
- {
- $list = model('stock_content')->pageList($condition, $field, $order, $page, $page_size);
- return $this->success($list);
- }
-
- /**
- * 添加虚拟评价库评论
- * @param array $condition
- * @param number $page
- * @param string $page_size
- * @param string $order
- * @param string $field
- */
- public function addContent($data)
- {
- $stock_id = model('stock_content')->add($data);
- if ($stock_id) {
- model("virtual_stock")->setInc([ [ 'stock_id', '=', $data[ 'stock_id' ] ] ], "num", 1);
- }
- return $this->success($stock_id);
- }
-
- /**
- * 删除虚拟评价库评论
- * @param array $condition
- * @param number $page
- * @param string $page_size
- * @param string $order
- * @param string $field
- */
- public function deleteContent($id, $site_id)
- {
- $stock_data = model('stock_content')->getInfo([ [ 'id', '=', $id ], [ 'site_id', '=', $site_id ] ], 'stock_id');
- model("virtual_stock")->setDec([ [ 'stock_id', '=', $stock_data[ 'stock_id' ] ] ], "num", 1);
-
- $stock_id = model('stock_content')->delete([ [ 'id', '=', $id ], [ 'site_id', '=', $site_id ] ]);
-
- return $this->success($stock_id);
- }
-
- /**
- * 获取虚拟评价库信息
- * @param array $condition
- * @param number $page
- * @param string $page_size
- * @param string $order
- * @param string $field
- */
- public function getContentInfo($id, $site_id)
- {
- $stock_info = model('stock_content')->getInfo([ [ 'id', '=', $id ], [ 'site_id', '=', $site_id ] ], '*');
-
- return $this->success($stock_info);
- }
-
- /**
- * 修改虚拟评价库信息
- * @param array $condition
- * @param number $page
- * @param string $page_size
- * @param string $order
- * @param string $field
- */
- public function editContentInfo($data, $site_id)
- {
- $content_info = model('stock_content')->update($data, [ [ 'id', '=', $data[ 'id' ] ], [ 'site_id', '=', $site_id ] ]);
-
- return $this->success($content_info);
- }
-
- /**
- * 获取评论库列表
- * @param array $condition
- * @param string $field
- * @param string $order
- * @param null $limit
- * @return array
- */
- public function getStockList($condition = [], $field = '*', $order = 'stock_id asc', $limit = null)
- {
- $list = model('virtual_stock')->getList($condition, $field, $order, '', '', '', $limit);
- return $this->success($list);
- }
-
+pageList($condition, $field, $order, $page, $page_size);
+ return $this->success($list);
+ }
+
+ /**
+ * 添加虚拟评价库分页列表
+ * @param array $condition
+ * @param number $page
+ * @param string $page_size
+ * @param string $order
+ * @param string $field
+ */
+ public function addStock($data)
+ {
+ $stock_id = model('virtual_stock')->add($data);
+ return $this->success($stock_id);
+ }
+
+ /**
+ * 删除虚拟评价库
+ * @param array $condition
+ * @param number $page
+ * @param string $page_size
+ * @param string $order
+ * @param string $field
+ */
+ public function deleteStock($stock_id, $site_id)
+ {
+ $stock_id = model('virtual_stock')->delete([ [ 'stock_id', '=', $stock_id ], [ 'site_id', '=', $site_id ] ]);
+
+ return $this->success($stock_id);
+ }
+
+ /**
+ * 更新虚拟评价库
+ * @param array $condition
+ * @param number $page
+ * @param string $page_size
+ * @param string $order
+ * @param string $field
+ */
+ public function updateStock($data, $site_id)
+ {
+ $stock_id = model('virtual_stock')->update($data, [ [ 'stock_id', '=', $data[ 'stock_id' ] ], [ 'site_id', '=', $site_id ] ]);
+
+ return $this->success($stock_id);
+ }
+
+ /**
+ * 获取虚拟评价库信息
+ * @param array $condition
+ * @param number $page
+ * @param string $page_size
+ * @param string $order
+ * @param string $field
+ */
+ public function getStockInfo($stock_id, $site_id)
+ {
+ $stock_info = model('virtual_stock')->getInfo([ [ 'stock_id', '=', $stock_id ], [ 'site_id', '=', $site_id ] ], '*');
+
+ return $this->success($stock_info);
+ }
+
+ /**
+ * 获取虚拟评价库信息
+ * @param array $condition
+ * @param number $page
+ * @param string $page_size
+ * @param string $order
+ * @param string $field
+ */
+ public function getContentsPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'create_time desc', $field = '*')
+ {
+ $list = model('stock_content')->pageList($condition, $field, $order, $page, $page_size);
+ return $this->success($list);
+ }
+
+ /**
+ * 添加虚拟评价库评论
+ * @param array $condition
+ * @param number $page
+ * @param string $page_size
+ * @param string $order
+ * @param string $field
+ */
+ public function addContent($data)
+ {
+ $stock_id = model('stock_content')->add($data);
+ if ($stock_id) {
+ model("virtual_stock")->setInc([ [ 'stock_id', '=', $data[ 'stock_id' ] ] ], "num", 1);
+ }
+ return $this->success($stock_id);
+ }
+
+ /**
+ * 删除虚拟评价库评论
+ * @param array $condition
+ * @param number $page
+ * @param string $page_size
+ * @param string $order
+ * @param string $field
+ */
+ public function deleteContent($id, $site_id)
+ {
+ $stock_data = model('stock_content')->getInfo([ [ 'id', '=', $id ], [ 'site_id', '=', $site_id ] ], 'stock_id');
+ model("virtual_stock")->setDec([ [ 'stock_id', '=', $stock_data[ 'stock_id' ] ] ], "num", 1);
+
+ $stock_id = model('stock_content')->delete([ [ 'id', '=', $id ], [ 'site_id', '=', $site_id ] ]);
+
+ return $this->success($stock_id);
+ }
+
+ /**
+ * 获取虚拟评价库信息
+ * @param array $condition
+ * @param number $page
+ * @param string $page_size
+ * @param string $order
+ * @param string $field
+ */
+ public function getContentInfo($id, $site_id)
+ {
+ $stock_info = model('stock_content')->getInfo([ [ 'id', '=', $id ], [ 'site_id', '=', $site_id ] ], '*');
+
+ return $this->success($stock_info);
+ }
+
+ /**
+ * 修改虚拟评价库信息
+ * @param array $condition
+ * @param number $page
+ * @param string $page_size
+ * @param string $order
+ * @param string $field
+ */
+ public function editContentInfo($data, $site_id)
+ {
+ $content_info = model('stock_content')->update($data, [ [ 'id', '=', $data[ 'id' ] ], [ 'site_id', '=', $site_id ] ]);
+
+ return $this->success($content_info);
+ }
+
+ /**
+ * 获取评论库列表
+ * @param array $condition
+ * @param string $field
+ * @param string $order
+ * @param null $limit
+ * @return array
+ */
+ public function getStockList($condition = [], $field = '*', $order = 'stock_id asc', $limit = null)
+ {
+ $list = model('virtual_stock')->getList($condition, $field, $order, '', '', '', $limit);
+ return $this->success($list);
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/virtualevaluation/shop/controller/Comment.php b/src/addon/virtualevaluation/shop/controller/Comment.php
index eae60a885..2559cc128 100644
--- a/src/addon/virtualevaluation/shop/controller/Comment.php
+++ b/src/addon/virtualevaluation/shop/controller/Comment.php
@@ -1,415 +1,407 @@
-isJson()) {
- $page_index = input('page', 1);
- $page_size = input('page_size', PAGE_LIST_ROWS);
- $search_text = input('search_text', "");
- $goods_state = input('goods_state', "");
- $start_sale = input('start_sale', 0);
- $end_sale = input('end_sale', 0);
- $start_price = input('start_price', 0);
- $end_price = input('end_price', 0);
- $goods_class = input('goods_class', "");
- $label_id = input('label_id', "");
- $order = input('order', '');
- $sort = input('sort', 'asc');
-
- $order_by = 'create_time desc';
- if ($order != '') {
- if ($order == 'sort') {
- $order_by = $order . ' ' . $sort . ',create_time desc';
- } else {
- $order_by = $order . ' ' . $sort;
- }
- }
- $promotion_type = input('promotion_type', "");
-
- $condition = [ [ 'is_delete', '=', 0 ], [ 'site_id', '=', $this->site_id ] ];
-
- if (!empty($search_text)) {
- $condition[] = [ 'goods_name', 'like', '%' . $search_text . '%' ];
- }
- $category_id = input('category_id', "");
- if (!empty($category_id)) {
- $condition[] = [ 'category_id', 'like', '%,' . $category_id . ',%' ];
- }
-
- if ($goods_class !== "") {
- $condition[] = [ 'goods_class', '=', $goods_class ];
- }
-
- if (!empty($label_id)) {
- $condition[] = [ 'label_id', '=', $label_id ];
- }
-
- if (!empty($promotion_type)) {
- $condition[] = [ 'promotion_addon', 'like', "%{$promotion_type}%" ];
- }
-
- // 上架状态
- if ($goods_state !== '') {
- $condition[] = [ 'goods_state', '=', $goods_state ];
- }
- if (!empty($start_sale)) $condition[] = [ 'sale_num', '>=', $start_sale ];
- if (!empty($end_sale)) $condition[] = [ 'sale_num', '<=', $end_sale ];
- if (!empty($start_price)) $condition[] = [ 'price', '>=', $start_price ];
- if (!empty($end_price)) $condition[] = [ 'price', '<=', $end_price ];
-
- // 查询库存预警的商品
- if ($stockalarm) {
- $stock_alarm = $goods_model->getGoodsStockAlarm($this->site_id);
- if (!empty($stock_alarm[ 'data' ])) {
- $condition[] = [ 'goods_id', 'in', $stock_alarm[ 'data' ] ];
- } else {
- return success(0, '', [ 'page_count' => 1, 'count' => 0, 'list' => [] ]);
- }
- }
- $field = 'goods_id,goods_name,site_id,site_name,goods_image,goods_state,price,goods_stock,goods_stock_alarm,create_time,sale_num,is_virtual,goods_class,is_fenxiao,fenxiao_type,promotion_addon,sku_id,is_consume_discount,discount_config,discount_method,sort,evaluate,evaluate_shaitu,success_evaluate_num,fail_evaluate_num,wait_evaluate_num';
- $res = $goods_model->getGoodsPageList($condition, $page_index, $page_size, $order_by, $field);
- $goods_promotion_type = event('GoodsPromotionType');
- if (!empty($res[ 'data' ][ 'list' ])) {
- foreach ($res[ 'data' ][ 'list' ] as $k => $v) {
-
- $res[ 'data' ][ 'list' ][ $k ][ 'goods_stock' ] = numberFormat($res[ 'data' ][ 'list' ][ $k ][ 'goods_stock' ]);
- $res[ 'data' ][ 'list' ][ $k ][ 'sale_num' ] = numberFormat($res[ 'data' ][ 'list' ][ $k ][ 'sale_num' ]);
-
- if (!empty($v[ 'promotion_addon' ])) {
- $v[ 'promotion_addon' ] = json_decode($v[ 'promotion_addon' ], true);
- foreach ($v[ 'promotion_addon' ] as $ck => $cv) {
- foreach ($goods_promotion_type as $gk => $gv) {
- if ($gv[ 'type' ] == $ck) {
- $res[ 'data' ][ 'list' ][ $k ][ 'promotion_addon_list' ][] = $gv;
- break;
- }
- }
- }
- }
- }
- }
- return $res;
- } else {
-
- $goods_state = input('state', '');
- $this->assign('goods_state', $goods_state);
- //获取一级商品分类
- $goods_category_model = new GoodsCategoryModel();
- $condition = [
- [ 'pid', '=', 0 ],
- [ 'site_id', '=', $this->site_id ]
- ];
-
- $goods_category_list = $goods_category_model->getCategoryList($condition, 'category_id,category_name,level,commission_rate');
- $goods_category_list = $goods_category_list[ 'data' ];
- $this->assign("goods_category_list", $goods_category_list);
-
- // 商品分组
- $goods_label_model = new GoodsLabelModel();
- $label_list = $goods_label_model->getLabelList([ [ 'site_id', '=', $this->site_id ] ], 'id,label_name', 'create_time desc')[ 'data' ];
- $this->assign("label_list", $label_list);
-
- // 商品服务
- $goods_service_model = new GoodsServiceModel();
- $service_list = $goods_service_model->getServiceList([ [ 'site_id', '=', $this->site_id ] ], 'id,service_name,icon')[ 'data' ];
- $this->assign("service_list", $service_list);
-
- //获取运费模板
- $express_template_model = new ExpressTemplateModel();
- $express_template_list = $express_template_model->getExpressTemplateList([ [ 'site_id', "=", $this->site_id ] ], 'template_id,template_name', 'is_default desc');
- $express_template_list = $express_template_list[ 'data' ];
- $this->assign("express_template_list", $express_template_list);
-
- //判断会员价插件
- $memberprice_is_exit = addon_is_exit('memberprice', $this->site_id);
- $this->assign('memberprice_is_exit', $memberprice_is_exit);
-
- // 判断采集插件
- $goodsgrab_is_exit = addon_is_exit('goodsgrab', $this->site_id);
- $this->assign('goodsgrab_is_exit', $goodsgrab_is_exit);
-
- // 营销活动
- $goods_promotion_type = event('GoodsPromotionType');
- $this->assign('promotion_type', $goods_promotion_type);
-
- $this->assign('virtualcard_exit', addon_is_exit('virtualcard', $this->site_id));
-
- $this->assign('stockalarm', $stockalarm);
-
- return $this->fetch("comment/goods_lists");
- }
- }
-
- /**
- * 创建虚拟评价
- * Class Virtualgoods
- * @package app\shop\controller
- */
- public function setting()
- {
- $goods_ids = input('goods_ids', 0);
- $goods_model = new Goods();
- $goods_data = $goods_model->getGoodsList([ [ 'goods_id', 'in', $goods_ids ], [ 'site_id', '=', $this->site_id ] ], 'sku_id,goods_id,goods_name,price,goods_image');
-
- $data = json_decode(input('field'), true);
-
- if (!empty($data[ 'member_headimg' ])) {
- $data[ 'member_headimg' ] = $data[ 'member_headimg' ][ 0 ];
- }
- $pingjia_img = '';
- if (!empty($data[ 'pingjia_img' ])) {
- foreach ($data[ 'pingjia_img' ] as $k => $val) {
- $pingjia_img = $pingjia_img . ',' . $val;
- }
- $pingjia_img = trim($pingjia_img, ',');
- }
-
- $data[ 'pingjia_img' ] = $pingjia_img;
- $data[ 'goods_data' ] = '';
- if (!empty($goods_data[ 'data' ])) {
- $data[ 'goods_data' ] = $goods_data[ 'data' ];
- }
- $VirtualEvaluation_model = new VirtualEvaluation();
- $res = $VirtualEvaluation_model->addGoodsComment($data, $this->site_id);
- return $res;
- }
-
- /**
- * 虚拟评价库
- * Class Virtualgoods
- * @package app\shop\controller
- */
- public function stock()
- {
- if (request()->isJson()) {
- $stock_model = new VirtualStock();
- $page = input('page', 1);
- $page_size = input('page_size', PAGE_LIST_ROWS);
- $condition = [
- 'site_id' => $this->site_id
- ];
- $stock_data = $stock_model->getStockPageList($condition, $page, $page_size, '', '');
- return $stock_data;
- } else {
-
- return $this->fetch("comment/stock");
- }
- }
-
- /**
- * 添加虚拟评价库
- * Class Virtualgoods
- * @package app\shop\controller
- */
- public function addStock()
- {
- $stock_model = new VirtualStock();
- $stock_name = input('stock_name', '');
- $data = [
- 'stock_name' => $stock_name,
- 'site_id' => $this->site_id,
- 'create_time' => time(),
- ];
- return $stock_model->addStock($data);
- }
-
- /**
- * 删除虚拟评价库
- * Class Virtualgoods
- * @package app\shop\controller
- */
- public function deleteStock()
- {
- $stock_model = new VirtualStock();
- $stock_id = input('stock_id', '');
-
- return $stock_model->deleteStock($stock_id, $this->site_id);
- }
-
- /**
- * 获取虚拟评价库信息
- * Class Virtualgoods
- * @package app\shop\controller
- */
- public function getStockInfo()
- {
- $stock_model = new VirtualStock();
- $stock_id = input('stock_id', '');
- return $stock_model->getStockInfo($stock_id, $this->site_id);
- }
-
- /**
- * 编辑虚拟评价库
- * Class Virtualgoods
- * @package app\shop\controller
- */
- public function editStock()
- {
- $stock_model = new VirtualStock();
- $stock_id = input('stock_id', 0);
- $stock_name = input('stock_name', '');
- $data = [
- 'stock_name' => $stock_name,
- 'modify_time' => time(),
- 'stock_id' => $stock_id
- ];
-
- return $stock_model->updateStock($data, $this->site_id);
- }
-
- /**
- * 获取虚拟评价库里的评论信息
- * Class Virtualgoods
- * @package app\shop\controller
- */
- public function getContents()
- {
- $stock_id = input('stock_id', 0);
- if (request()->isJson()) {
- $stock_model = new VirtualStock();
- $page = input('page', 1);
- $page_size = input('page_size', PAGE_LIST_ROWS);
- $condition = [
- 'site_id' => $this->site_id,
- 'stock_id' => $stock_id,
- ];
- $stock_data = $stock_model->getContentsPageList($condition, $page, $page_size, '', '');
- return $stock_data;
- } else {
- $this->assign('stock_id', $stock_id);
- return $this->fetch("comment/contents");
- }
- }
-
- /**
- * 添加虚拟评价库评论
- * Class Virtualgoods
- * @package app\shop\controller
- */
- public function addContent()
- {
- $stock_model = new VirtualStock();
- $stock_id = input('stock_id', 0);
- $content = input('content', '');
- $data = [
- 'stock_id' => $stock_id,
- 'site_id' => $this->site_id,
- 'content' => $content,
- 'create_time' => time(),
- ];
- return $stock_model->addContent($data);
- }
-
- /**
- * 删除虚拟评价库评论
- * Class Virtualgoods
- * @package app\shop\controller
- */
- public function deleteContent()
- {
- $stock_model = new VirtualStock();
- $id = input('id', 0);
-
- return $stock_model->deleteContent($id, $this->site_id);
- }
-
- /**
- * 获取虚拟评价库评论信息
- * Class Virtualgoods
- * @package app\shop\controller
- */
- public function getContentInfo()
- {
- $stock_model = new VirtualStock();
- $id = input('id', 0);
-
- return $stock_model->getContentInfo($id, $this->site_id);
- }
-
- /**
- * 修改虚拟评价库评论信息
- * Class Virtualgoods
- * @package app\shop\controller
- */
- public function editContent()
- {
- $stock_model = new VirtualStock();
- $id = input('id', 0);
- $content = input('content', '');
- $data = [
- 'content' => $content,
- 'id' => $id
- ];
- return $stock_model->editContentInfo($data, $this->site_id);
- }
-
- /**
- * 批量添加单个商品的评论
- * Class Virtualgoods
- * @package app\shop\controller
- */
- public function batchAdd()
- {
- $album_model = new Album();
- $stock_model = new VirtualStock();
- $goods_id = input('goods_id', 0);
- if (request()->isJson()) {
- $start_time = date_to_time(input('start_time'));
- $end_time = date_to_time(input('end_time'));
- if ($start_time == '' || $end_time == '' || $end_time < $start_time) return error('-1', '时间格式不正确');
- $virtual_evaluation_model = new VirtualEvaluation();
- $data = [
- 'goods_id' => input('goods_id', 0),
- 'number' => input('number', 0),
- 'pingfen' => input('pingfen', ''),
- 'start_time' => $start_time,
- 'end_time' => $end_time,
- 'album_id' => input('album_id', 0),
- 'stock_id' => input('stock_id', 0)
- ];
- $res = $virtual_evaluation_model->batghAdd($data, $this->site_id);
- return $res;
- } else {
- //获取相册
- $album_list = $album_model->getAlbumList([ [ 'site_id', '=', $this->site_id ], [ 'num', '>', 0 ] ]);
- $this->assign('album_list', $album_list[ 'data' ]);
- //获取评论库
- $stock_list = $stock_model->getStockList([ [ 'site_id', '=', $this->site_id ], [ 'num', '>', 0 ] ]);
- $this->assign('stock_list', $stock_list[ 'data' ]);
- $this->assign('goods_id', $goods_id);
- return $this->fetch("comment/batchadd");
- }
- }
-
+isJson()) {
+ $page_index = input('page', 1);
+ $page_size = input('page_size', PAGE_LIST_ROWS);
+ $search_text = input('search_text', "");
+ $goods_state = input('goods_state', "");
+ $start_sale = input('start_sale', 0);
+ $end_sale = input('end_sale', 0);
+ $start_price = input('start_price', 0);
+ $end_price = input('end_price', 0);
+ $goods_class = input('goods_class', "");
+ $label_id = input('label_id', "");
+ $order = input('order', '');
+ $sort = input('sort', 'asc');
+
+ $order_by = 'create_time desc';
+ if ($order != '') {
+ if ($order == 'sort') {
+ $order_by = $order . ' ' . $sort . ',create_time desc';
+ } else {
+ $order_by = $order . ' ' . $sort;
+ }
+ }
+ $promotion_type = input('promotion_type', "");
+
+ $condition = [ [ 'is_delete', '=', 0 ], [ 'site_id', '=', $this->site_id ] ];
+
+ if (!empty($search_text)) {
+ $condition[] = [ 'goods_name', 'like', '%' . $search_text . '%' ];
+ }
+ $category_id = input('category_id', "");
+ if (!empty($category_id)) {
+ $condition[] = [ 'category_id', 'like', '%,' . $category_id . ',%' ];
+ }
+
+ if ($goods_class !== "") {
+ $condition[] = [ 'goods_class', '=', $goods_class ];
+ }
+
+ if (!empty($label_id)) {
+ $condition[] = [ 'label_id', '=', $label_id ];
+ }
+
+ if (!empty($promotion_type)) {
+ $condition[] = [ 'promotion_addon', 'like', "%{$promotion_type}%" ];
+ }
+
+ // 上架状态
+ if ($goods_state !== '') {
+ $condition[] = [ 'goods_state', '=', $goods_state ];
+ }
+ if (!empty($start_sale)) $condition[] = [ 'sale_num', '>=', $start_sale ];
+ if (!empty($end_sale)) $condition[] = [ 'sale_num', '<=', $end_sale ];
+ if (!empty($start_price)) $condition[] = [ 'price', '>=', $start_price ];
+ if (!empty($end_price)) $condition[] = [ 'price', '<=', $end_price ];
+
+ // 查询库存预警的商品
+ if ($stockalarm) {
+ $stock_alarm = $goods_model->getGoodsStockAlarm($this->site_id);
+ if (!empty($stock_alarm[ 'data' ])) {
+ $condition[] = [ 'goods_id', 'in', $stock_alarm[ 'data' ] ];
+ } else {
+ return success(0, '', [ 'page_count' => 1, 'count' => 0, 'list' => [] ]);
+ }
+ }
+ $field = 'goods_id,goods_name,site_id,site_name,goods_image,goods_state,price,goods_stock,goods_stock_alarm,create_time,sale_num,is_virtual,goods_class,is_fenxiao,fenxiao_type,promotion_addon,sku_id,is_consume_discount,discount_config,discount_method,sort,evaluate,evaluate_shaitu,success_evaluate_num,fail_evaluate_num,wait_evaluate_num';
+ $res = $goods_model->getGoodsPageList($condition, $page_index, $page_size, $order_by, $field);
+ $goods_promotion_type = event('GoodsPromotionType');
+ if (!empty($res[ 'data' ][ 'list' ])) {
+ foreach ($res[ 'data' ][ 'list' ] as $k => $v) {
+
+ $res[ 'data' ][ 'list' ][ $k ][ 'goods_stock' ] = numberFormat($res[ 'data' ][ 'list' ][ $k ][ 'goods_stock' ]);
+ $res[ 'data' ][ 'list' ][ $k ][ 'sale_num' ] = numberFormat($res[ 'data' ][ 'list' ][ $k ][ 'sale_num' ]);
+
+ if (!empty($v[ 'promotion_addon' ])) {
+ $v[ 'promotion_addon' ] = json_decode($v[ 'promotion_addon' ], true);
+ foreach ($v[ 'promotion_addon' ] as $ck => $cv) {
+ foreach ($goods_promotion_type as $gk => $gv) {
+ if ($gv[ 'type' ] == $ck) {
+ $res[ 'data' ][ 'list' ][ $k ][ 'promotion_addon_list' ][] = $gv;
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+ return $res;
+ } else {
+
+ $goods_state = input('state', '');
+ $this->assign('goods_state', $goods_state);
+ //获取一级商品分类
+ $goods_category_model = new GoodsCategoryModel();
+ $condition = [
+ [ 'pid', '=', 0 ],
+ [ 'site_id', '=', $this->site_id ]
+ ];
+
+ $goods_category_list = $goods_category_model->getCategoryList($condition, 'category_id,category_name,level,commission_rate');
+ $goods_category_list = $goods_category_list[ 'data' ];
+ $this->assign("goods_category_list", $goods_category_list);
+
+ // 商品分组
+ $goods_label_model = new GoodsLabelModel();
+ $label_list = $goods_label_model->getLabelList([ [ 'site_id', '=', $this->site_id ] ], 'id,label_name', 'create_time desc')[ 'data' ];
+ $this->assign("label_list", $label_list);
+
+ // 商品服务
+ $goods_service_model = new GoodsServiceModel();
+ $service_list = $goods_service_model->getServiceList([ [ 'site_id', '=', $this->site_id ] ], 'id,service_name,icon')[ 'data' ];
+ $this->assign("service_list", $service_list);
+
+ //获取运费模板
+ $express_template_model = new ExpressTemplateModel();
+ $express_template_list = $express_template_model->getExpressTemplateList([ [ 'site_id', "=", $this->site_id ] ], 'template_id,template_name', 'is_default desc');
+ $express_template_list = $express_template_list[ 'data' ];
+ $this->assign("express_template_list", $express_template_list);
+
+ //判断会员价插件
+ $memberprice_is_exit = addon_is_exit('memberprice', $this->site_id);
+ $this->assign('memberprice_is_exit', $memberprice_is_exit);
+
+ // 判断采集插件
+ $goodsgrab_is_exit = addon_is_exit('goodsgrab', $this->site_id);
+ $this->assign('goodsgrab_is_exit', $goodsgrab_is_exit);
+
+ // 营销活动
+ $goods_promotion_type = event('GoodsPromotionType');
+ $this->assign('promotion_type', $goods_promotion_type);
+
+ $this->assign('virtualcard_exit', addon_is_exit('virtualcard', $this->site_id));
+
+ $this->assign('stockalarm', $stockalarm);
+
+ return $this->fetch("comment/goods_lists");
+ }
+ }
+
+ /**
+ * 创建虚拟评价
+ * Class Virtualgoods
+ * @package app\shop\controller
+ */
+ public function setting()
+ {
+ $goods_ids = input('goods_ids', 0);
+ $goods_model = new Goods();
+ $goods_data = $goods_model->getGoodsList([ [ 'goods_id', 'in', $goods_ids ], [ 'site_id', '=', $this->site_id ] ], 'sku_id,goods_id,goods_name,price,goods_image');
+
+ $data = json_decode(input('field'), true);
+
+ if (!empty($data[ 'member_headimg' ])) {
+ $data[ 'member_headimg' ] = $data[ 'member_headimg' ][ 0 ];
+ }
+ $pingjia_img = '';
+ if (!empty($data[ 'pingjia_img' ])) {
+ foreach ($data[ 'pingjia_img' ] as $k => $val) {
+ $pingjia_img = $pingjia_img . ',' . $val;
+ }
+ $pingjia_img = trim($pingjia_img, ',');
+ }
+
+ $data[ 'pingjia_img' ] = $pingjia_img;
+ $data[ 'goods_data' ] = '';
+ if (!empty($goods_data[ 'data' ])) {
+ $data[ 'goods_data' ] = $goods_data[ 'data' ];
+ }
+ $VirtualEvaluation_model = new VirtualEvaluation();
+ $res = $VirtualEvaluation_model->addGoodsComment($data, $this->site_id);
+ return $res;
+ }
+
+ /**
+ * 虚拟评价库
+ * Class Virtualgoods
+ * @package app\shop\controller
+ */
+ public function stock()
+ {
+ if (request()->isJson()) {
+ $stock_model = new VirtualStock();
+ $page = input('page', 1);
+ $page_size = input('page_size', PAGE_LIST_ROWS);
+ $condition = [
+ 'site_id' => $this->site_id
+ ];
+ $stock_data = $stock_model->getStockPageList($condition, $page, $page_size, '', '');
+ return $stock_data;
+ } else {
+
+ return $this->fetch("comment/stock");
+ }
+ }
+
+ /**
+ * 添加虚拟评价库
+ * Class Virtualgoods
+ * @package app\shop\controller
+ */
+ public function addStock()
+ {
+ $stock_model = new VirtualStock();
+ $stock_name = input('stock_name', '');
+ $data = [
+ 'stock_name' => $stock_name,
+ 'site_id' => $this->site_id,
+ 'create_time' => time(),
+ ];
+ return $stock_model->addStock($data);
+ }
+
+ /**
+ * 删除虚拟评价库
+ * Class Virtualgoods
+ * @package app\shop\controller
+ */
+ public function deleteStock()
+ {
+ $stock_model = new VirtualStock();
+ $stock_id = input('stock_id', '');
+
+ return $stock_model->deleteStock($stock_id, $this->site_id);
+ }
+
+ /**
+ * 获取虚拟评价库信息
+ * Class Virtualgoods
+ * @package app\shop\controller
+ */
+ public function getStockInfo()
+ {
+ $stock_model = new VirtualStock();
+ $stock_id = input('stock_id', '');
+ return $stock_model->getStockInfo($stock_id, $this->site_id);
+ }
+
+ /**
+ * 编辑虚拟评价库
+ * Class Virtualgoods
+ * @package app\shop\controller
+ */
+ public function editStock()
+ {
+ $stock_model = new VirtualStock();
+ $stock_id = input('stock_id', 0);
+ $stock_name = input('stock_name', '');
+ $data = [
+ 'stock_name' => $stock_name,
+ 'modify_time' => time(),
+ 'stock_id' => $stock_id
+ ];
+
+ return $stock_model->updateStock($data, $this->site_id);
+ }
+
+ /**
+ * 获取虚拟评价库里的评论信息
+ * Class Virtualgoods
+ * @package app\shop\controller
+ */
+ public function getContents()
+ {
+ $stock_id = input('stock_id', 0);
+ if (request()->isJson()) {
+ $stock_model = new VirtualStock();
+ $page = input('page', 1);
+ $page_size = input('page_size', PAGE_LIST_ROWS);
+ $condition = [
+ 'site_id' => $this->site_id,
+ 'stock_id' => $stock_id,
+ ];
+ $stock_data = $stock_model->getContentsPageList($condition, $page, $page_size, '', '');
+ return $stock_data;
+ } else {
+ $this->assign('stock_id', $stock_id);
+ return $this->fetch("comment/contents");
+ }
+ }
+
+ /**
+ * 添加虚拟评价库评论
+ * Class Virtualgoods
+ * @package app\shop\controller
+ */
+ public function addContent()
+ {
+ $stock_model = new VirtualStock();
+ $stock_id = input('stock_id', 0);
+ $content = input('content', '');
+ $data = [
+ 'stock_id' => $stock_id,
+ 'site_id' => $this->site_id,
+ 'content' => $content,
+ 'create_time' => time(),
+ ];
+ return $stock_model->addContent($data);
+ }
+
+ /**
+ * 删除虚拟评价库评论
+ * Class Virtualgoods
+ * @package app\shop\controller
+ */
+ public function deleteContent()
+ {
+ $stock_model = new VirtualStock();
+ $id = input('id', 0);
+
+ return $stock_model->deleteContent($id, $this->site_id);
+ }
+
+ /**
+ * 获取虚拟评价库评论信息
+ * Class Virtualgoods
+ * @package app\shop\controller
+ */
+ public function getContentInfo()
+ {
+ $stock_model = new VirtualStock();
+ $id = input('id', 0);
+
+ return $stock_model->getContentInfo($id, $this->site_id);
+ }
+
+ /**
+ * 修改虚拟评价库评论信息
+ * Class Virtualgoods
+ * @package app\shop\controller
+ */
+ public function editContent()
+ {
+ $stock_model = new VirtualStock();
+ $id = input('id', 0);
+ $content = input('content', '');
+ $data = [
+ 'content' => $content,
+ 'id' => $id
+ ];
+ return $stock_model->editContentInfo($data, $this->site_id);
+ }
+
+ /**
+ * 批量添加单个商品的评论
+ * Class Virtualgoods
+ * @package app\shop\controller
+ */
+ public function batchAdd()
+ {
+ $album_model = new Album();
+ $stock_model = new VirtualStock();
+ $goods_id = input('goods_id', 0);
+ if (request()->isJson()) {
+ $start_time = date_to_time(input('start_time'));
+ $end_time = date_to_time(input('end_time'));
+ if ($start_time == '' || $end_time == '' || $end_time < $start_time) return error('-1', '时间格式不正确');
+ $virtual_evaluation_model = new VirtualEvaluation();
+ $data = [
+ 'goods_id' => input('goods_id', 0),
+ 'number' => input('number', 0),
+ 'pingfen' => input('pingfen', ''),
+ 'start_time' => $start_time,
+ 'end_time' => $end_time,
+ 'album_id' => input('album_id', 0),
+ 'stock_id' => input('stock_id', 0)
+ ];
+ $res = $virtual_evaluation_model->batghAdd($data, $this->site_id);
+ return $res;
+ } else {
+ //获取相册
+ $album_list = $album_model->getAlbumList([ [ 'site_id', '=', $this->site_id ], [ 'num', '>', 0 ] ]);
+ $this->assign('album_list', $album_list[ 'data' ]);
+ //获取评论库
+ $stock_list = $stock_model->getStockList([ [ 'site_id', '=', $this->site_id ], [ 'num', '>', 0 ] ]);
+ $this->assign('stock_list', $stock_list[ 'data' ]);
+ $this->assign('goods_id', $goods_id);
+ return $this->fetch("comment/batchadd");
+ }
+ }
+
}
\ No newline at end of file
diff --git a/src/addon/weapp/api/controller/Auth.php b/src/addon/weapp/api/controller/Auth.php
index 9536e3693..efc86dfbb 100644
--- a/src/addon/weapp/api/controller/Auth.php
+++ b/src/addon/weapp/api/controller/Auth.php
@@ -1,40 +1,31 @@
-siteid();
- $this->wechat = new Weapp($site_id);
- }
-
- /**
- * 小程序消息推送
- */
- public function relateWeixin()
- {
- Log::write('微信小程序消息推送');
- $this->wechat->relateWeixin();
- }
-
-
+siteid();
+ $this->wechat = new Weapp($site_id);
+ }
+
+ /**
+ * 小程序消息推送
+ */
+ public function relateWeixin()
+ {
+ Log::write('微信小程序消息推送');
+ $this->wechat->relateWeixin();
+ }
+
+
}
\ No newline at end of file
diff --git a/src/addon/weapp/api/controller/Weapp.php b/src/addon/weapp/api/controller/Weapp.php
index 70b7b7a21..5021b3447 100644
--- a/src/addon/weapp/api/controller/Weapp.php
+++ b/src/addon/weapp/api/controller/Weapp.php
@@ -1,88 +1,80 @@
-site_id);
- $res = $weapp_model->authCodeToOpenid($this->params);
- return $this->response($res);
- }
-
- /**
- * 获取消息模板id(最多三条)
- */
- public function messageTmplIds()
- {
- $keywords = $this->params[ 'keywords' ] ?? '';
- $message = new Message();
- $res = $message->getMessageTmplIds($this->site_id, $keywords);
- return $this->response($res);
- }
-
- /*
- * 获取小程序码
- */
- public function qrcode()
- {
- $config_model = new Config();
- $config = $config_model->getWeappConfig($this->site_id);
- $qrcode = $config[ 'data' ][ 'value' ][ 'qrcode' ] ?? '';
- return $this->response($this->success($qrcode));
- }
-
- /**
- * 分享
- * @return false|string
- */
- public function share()
- {
- /*$config_model = new Config();
- $config = $config_model->getShareConfig($this->site_id, 'shop');
- $share_config = $config['data']['value'];*/
-
- $this->checkToken();
-
- //页面路径
- $path = $this->params[ 'path' ] ?? '';
-
- //分享配置
- $share_config = [];
- $share_data = event('WeappShareData', [
- 'path' => $path,
- 'site_id' => $this->site_id,
- 'member_id' => $this->member_id,
- ], true);
- if (!empty($share_data)) {
- $share_config[ 'permission' ] = $share_data[ 'permission' ];
- $share_config[ 'data' ] = $share_data[ 'data' ];
- } else {
- $share_config[ 'permission' ] = [
- 'onShareAppMessage' => false,
- 'onShareTimeline' => false,
- ];
- $share_config[ 'data' ] = null;
- }
-
- return $this->response($this->success($share_config));
- }
+site_id);
+ $res = $weapp_model->authCodeToOpenid($this->params);
+ return $this->response($res);
+ }
+
+ /**
+ * 获取消息模板id(最多三条)
+ */
+ public function messageTmplIds()
+ {
+ $keywords = $this->params[ 'keywords' ] ?? '';
+ $message = new Message();
+ $res = $message->getMessageTmplIds($this->site_id, $keywords);
+ return $this->response($res);
+ }
+
+ /*
+ * 获取小程序码
+ */
+ public function qrcode()
+ {
+ $config_model = new Config();
+ $config = $config_model->getWeappConfig($this->site_id);
+ $qrcode = $config[ 'data' ][ 'value' ][ 'qrcode' ] ?? '';
+ return $this->response($this->success($qrcode));
+ }
+
+ /**
+ * 分享
+ * @return false|string
+ */
+ public function share()
+ {
+ /*$config_model = new Config();
+ $config = $config_model->getShareConfig($this->site_id, 'shop');
+ $share_config = $config['data']['value'];*/
+
+ $this->checkToken();
+
+ //页面路径
+ $path = $this->params[ 'path' ] ?? '';
+
+ //分享配置
+ $share_config = [];
+ $share_data = event('WeappShareData', [
+ 'path' => $path,
+ 'site_id' => $this->site_id,
+ 'member_id' => $this->member_id,
+ ], true);
+ if (!empty($share_data)) {
+ $share_config[ 'permission' ] = $share_data[ 'permission' ];
+ $share_config[ 'data' ] = $share_data[ 'data' ];
+ } else {
+ $share_config[ 'permission' ] = [
+ 'onShareAppMessage' => false,
+ 'onShareTimeline' => false,
+ ];
+ $share_config[ 'data' ] = null;
+ }
+
+ return $this->response($this->success($share_config));
+ }
}
\ No newline at end of file
diff --git a/src/addon/weapp/config/diy_view.php b/src/addon/weapp/config/diy_view.php
index c3c657905..e36ca9b7d 100644
--- a/src/addon/weapp/config/diy_view.php
+++ b/src/addon/weapp/config/diy_view.php
@@ -1,38 +1,30 @@
- '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
- 'template' => [],
-
- // 后台自定义组件——装修
- 'util' => [],
-
- // 自定义页面路径
- 'link' => [],
-
- // 自定义图标库
- 'icon_library' => [],
-
- // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
- 'component' => [],
-
- // uni-app 页面,多个逗号隔开
- 'pages' => [],
-
- // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
- 'info' => [],
-
- // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
- 'theme' => [],
-
- // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
- 'data' => []
+ '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
+ 'template' => [],
+
+ // 后台自定义组件——装修
+ 'util' => [],
+
+ // 自定义页面路径
+ 'link' => [],
+
+ // 自定义图标库
+ 'icon_library' => [],
+
+ // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
+ 'component' => [],
+
+ // uni-app 页面,多个逗号隔开
+ 'pages' => [],
+
+ // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
+ 'info' => [],
+
+ // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
+ 'theme' => [],
+
+ // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
+ 'data' => []
];
\ No newline at end of file
diff --git a/src/addon/weapp/config/info.php b/src/addon/weapp/config/info.php
index eb23187b1..eac7c71c2 100644
--- a/src/addon/weapp/config/info.php
+++ b/src/addon/weapp/config/info.php
@@ -1,20 +1,12 @@
- 'weapp',
- 'title' => '微信小程序',
- 'description' => '微信小程序功能',
- 'type' => 'system', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
- 'status' => 1,
- 'author' => '',
- 'version' => '5.3.1',
- 'version_no' => '525231212001',
- 'content' => '',
+ 'weapp',
+ 'title' => '微信小程序',
+ 'description' => '微信小程序功能',
+ 'type' => 'system', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
+ 'status' => 1,
+ 'author' => '',
+ 'version' => '5.3.1',
+ 'version_no' => '525231212001',
+ 'content' => '',
];
\ No newline at end of file
diff --git a/src/addon/weapp/event/DecryptData.php b/src/addon/weapp/event/DecryptData.php
index 4de198569..f7f3ce4e7 100644
--- a/src/addon/weapp/event/DecryptData.php
+++ b/src/addon/weapp/event/DecryptData.php
@@ -1,30 +1,22 @@
-decryptData($param);
- }
- }
+decryptData($param);
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/weapp/event/Install.php b/src/addon/weapp/event/Install.php
index d72704d22..af34114df 100644
--- a/src/addon/weapp/event/Install.php
+++ b/src/addon/weapp/event/Install.php
@@ -1,25 +1,17 @@
-getInfo([ [ 'order_id', '=', $data[ 'order_id' ] ] ], 'order_from');
- if($order_info['order_from'] == 'weapp'){
- $weapp_model = new Weapp($data[ 'site_id' ]);
- $res = $weapp_model->orderShippingUploadShippingInfo([
- 'order_id' => $data[ 'order_id' ],
- ]);
- return $res;
- }
- }
+getInfo([ [ 'order_id', '=', $data[ 'order_id' ] ] ], 'order_from');
+ if($order_info['order_from'] == 'weapp'){
+ $weapp_model = new Weapp($data[ 'site_id' ]);
+ $res = $weapp_model->orderShippingUploadShippingInfo([
+ 'order_id' => $data[ 'order_id' ],
+ ]);
+ return $res;
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/weapp/event/OrderTakeDeliveryAfter.php b/src/addon/weapp/event/OrderTakeDeliveryAfter.php
index 2cc754412..66e12a9b4 100644
--- a/src/addon/weapp/event/OrderTakeDeliveryAfter.php
+++ b/src/addon/weapp/event/OrderTakeDeliveryAfter.php
@@ -1,30 +1,22 @@
-orderShippingNotifyConfirmReceive([
- 'order_id' => $data[ 'order_id' ],
- ]);
- return $res;
- }
+orderShippingNotifyConfirmReceive([
+ 'order_id' => $data[ 'order_id' ],
+ ]);
+ return $res;
+ }
}
\ No newline at end of file
diff --git a/src/addon/weapp/event/PhoneNumber.php b/src/addon/weapp/event/PhoneNumber.php
index 940efff4d..f9c935e63 100644
--- a/src/addon/weapp/event/PhoneNumber.php
+++ b/src/addon/weapp/event/PhoneNumber.php
@@ -1,29 +1,21 @@
-decryptData($param);
- if ($res[ 'code' ] != 0) return $res;
-
- return success(0, '', $res[ 'data' ][ 'purePhoneNumber' ]);
- }
- }
+decryptData($param);
+ if ($res[ 'code' ] != 0) return $res;
+
+ return success(0, '', $res[ 'data' ][ 'purePhoneNumber' ]);
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/weapp/event/Qrcode.php b/src/addon/weapp/event/Qrcode.php
index 1c6319ee6..5c05ba726 100644
--- a/src/addon/weapp/event/Qrcode.php
+++ b/src/addon/weapp/event/Qrcode.php
@@ -1,41 +1,33 @@
-createQrcode($param);
- } else {
- $filename = $param[ 'qrcode_path' ] . '/' . $param[ 'qrcode_name' ] . '_' . $param[ 'app_type' ] . '.png';
- if (file_exists($filename)) {
- $res = success(0, '', [ 'type' => 'weapp', 'path' => $filename ]);
- } else {
- $res = $weapp->createQrcode($param);
- }
- }
- return $res;
- }
- }
+createQrcode($param);
+ } else {
+ $filename = $param[ 'qrcode_path' ] . '/' . $param[ 'qrcode_name' ] . '_' . $param[ 'app_type' ] . '.png';
+ if (file_exists($filename)) {
+ $res = success(0, '', [ 'type' => 'weapp', 'path' => $filename ]);
+ } else {
+ $res = $weapp->createQrcode($param);
+ }
+ }
+ return $res;
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/weapp/event/UnInstall.php b/src/addon/weapp/event/UnInstall.php
index 8a0c1da19..f808c7b41 100644
--- a/src/addon/weapp/event/UnInstall.php
+++ b/src/addon/weapp/event/UnInstall.php
@@ -1,25 +1,17 @@
-getWeappConfig($site_id);
- if (!empty($config_info[ 'data' ][ 'value' ][ 'qrcode' ]) && !empty($data[ 'qrcode' ]) && $config_info[ 'data' ][ 'value' ][ 'qrcode' ] != $data[ 'qrcode' ]) {
- $upload_model = new Upload();
- $upload_model->deletePic($config_info[ 'data' ][ 'value' ][ 'qrcode' ], $site_id);
- }
-
- $config = new ConfigModel();
- $res = $config->setConfig($data, '微信小程序设置', $is_use, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'WEAPP_CONFIG' ] ]);
- if ($res && $data[ 'qrcode' ]) {
- copy($data[ 'qrcode' ], 'public/static/img/default_img/wxewm.png');
- }
- return $res;
- }
-
- /**
- * 获取微信小程序配置信息
- * @param int $site_id
- * @return array
- */
- public function getWeappConfig($site_id = 0)
- {
- $config = new ConfigModel();
- $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'WEAPP_CONFIG' ] ]);
- return $res;
- }
- /******************************************************************** 微信小程序配置 end ****************************************************************************/
-
- /**
- * 设置小程序版本信息
- * @param $data
- * @param $is_use
- * @param int $site_id
- * @return array
- */
- public function setWeappVersion($data, $is_use, $site_id = 0)
- {
- $config = new ConfigModel();
- $res = $config->setConfig($data, '小程序版本', $is_use, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'WEAPP_VERSION' ] ]);
- return $res;
- }
-
- /**
- * 获取小程序版本信息
- * @param int $site_id
- * @return array
- */
- public function getWeappVersion($site_id = 0)
- {
- $config = new ConfigModel();
- $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'WEAPP_VERSION' ] ]);
- return $res;
- }
-
- /**
- * 清除小程序版本信息
- */
- public function clearWeappVersion()
- {
- model('config')->update([ 'value' => '' ], [ [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'WEAPP_VERSION' ] ]);
- Cache::tag('config')->clear();
- }
-
- /**
- * 设置小程序分享
- * @param $site_id
- * @param $app_module
- * @param $key
- * @param $value
- */
- public function setShareConfig($site_id, $app_module, $key, $value)
- {
- $config = model('config')->getInfo([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'WEAPP_SHARE' ] ], 'value');
- if (!empty($config) && !empty($config[ 'value' ])) $data = json_decode($config[ 'value' ], true);
-
- if (!empty($data[ $key ][ 'path' ]) && !empty($value[ 'path' ]) && $data[ $key ][ 'path' ] != $value[ 'path' ]) {
- $upload_model = new Upload();
- $upload_model->deletePic($data[ $key ][ 'path' ], $site_id);
- }
-
- $data[ $key ] = $value;
- $model = new ConfigModel();
- $res = $model->setConfig($data, '小程序分享', 1, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'WEAPP_SHARE' ] ]);
- return $res;
- }
-
- /**
- * 获取小程序分享配置
- * @param $site_id
- * @param $app_module\
- */
- public function getShareConfig($site_id, $app_module)
- {
- $config = new ConfigModel();
- $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'WEAPP_SHARE' ] ]);
- return $res;
- }
+getWeappConfig($site_id);
+ if (!empty($config_info[ 'data' ][ 'value' ][ 'qrcode' ]) && !empty($data[ 'qrcode' ]) && $config_info[ 'data' ][ 'value' ][ 'qrcode' ] != $data[ 'qrcode' ]) {
+ $upload_model = new Upload();
+ $upload_model->deletePic($config_info[ 'data' ][ 'value' ][ 'qrcode' ], $site_id);
+ }
+
+ $config = new ConfigModel();
+ $res = $config->setConfig($data, '微信小程序设置', $is_use, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'WEAPP_CONFIG' ] ]);
+ if ($res && $data[ 'qrcode' ]) {
+ copy($data[ 'qrcode' ], 'public/static/img/default_img/wxewm.png');
+ }
+ return $res;
+ }
+
+ /**
+ * 获取微信小程序配置信息
+ * @param int $site_id
+ * @return array
+ */
+ public function getWeappConfig($site_id = 0)
+ {
+ $config = new ConfigModel();
+ $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'WEAPP_CONFIG' ] ]);
+ return $res;
+ }
+ /******************************************************************** 微信小程序配置 end ****************************************************************************/
+
+ /**
+ * 设置小程序版本信息
+ * @param $data
+ * @param $is_use
+ * @param int $site_id
+ * @return array
+ */
+ public function setWeappVersion($data, $is_use, $site_id = 0)
+ {
+ $config = new ConfigModel();
+ $res = $config->setConfig($data, '小程序版本', $is_use, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'WEAPP_VERSION' ] ]);
+ return $res;
+ }
+
+ /**
+ * 获取小程序版本信息
+ * @param int $site_id
+ * @return array
+ */
+ public function getWeappVersion($site_id = 0)
+ {
+ $config = new ConfigModel();
+ $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'WEAPP_VERSION' ] ]);
+ return $res;
+ }
+
+ /**
+ * 清除小程序版本信息
+ */
+ public function clearWeappVersion()
+ {
+ model('config')->update([ 'value' => '' ], [ [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'WEAPP_VERSION' ] ]);
+ Cache::tag('config')->clear();
+ }
+
+ /**
+ * 设置小程序分享
+ * @param $site_id
+ * @param $app_module
+ * @param $key
+ * @param $value
+ */
+ public function setShareConfig($site_id, $app_module, $key, $value)
+ {
+ $config = model('config')->getInfo([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'WEAPP_SHARE' ] ], 'value');
+ if (!empty($config) && !empty($config[ 'value' ])) $data = json_decode($config[ 'value' ], true);
+
+ if (!empty($data[ $key ][ 'path' ]) && !empty($value[ 'path' ]) && $data[ $key ][ 'path' ] != $value[ 'path' ]) {
+ $upload_model = new Upload();
+ $upload_model->deletePic($data[ $key ][ 'path' ], $site_id);
+ }
+
+ $data[ $key ] = $value;
+ $model = new ConfigModel();
+ $res = $model->setConfig($data, '小程序分享', 1, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'WEAPP_SHARE' ] ]);
+ return $res;
+ }
+
+ /**
+ * 获取小程序分享配置
+ * @param $site_id
+ * @param $app_module\
+ */
+ public function getShareConfig($site_id, $app_module)
+ {
+ $config = new ConfigModel();
+ $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'WEAPP_SHARE' ] ]);
+ return $res;
+ }
}
\ No newline at end of file
diff --git a/src/addon/weapp/model/Message.php b/src/addon/weapp/model/Message.php
index fa6bd5ebd..e8abe87a5 100644
--- a/src/addon/weapp/model/Message.php
+++ b/src/addon/weapp/model/Message.php
@@ -1,174 +1,166 @@
-pageList($condition, 'id,keywords,title,message_type,weapp_json', $order, $page, $page_size);
- if ($site_id > 0) {
- if (!empty($list[ 'list' ])) {
- foreach ($list[ 'list' ] as $k => $v) {
- $list[ 'list' ][ $k ]['message_info'] = json_decode($v['weapp_json'], true);
- $message_info = model('message')->getInfo([ [ "keywords", "=", $v[ 'keywords' ] ], [ 'site_id', '=', $site_id ] ], 'weapp_is_open,weapp_template_id');
- $list[ 'list' ][ $k ][ 'weapp_is_open' ] = $message_info == null ? 0 : $message_info[ 'weapp_is_open' ];
- $list[ 'list' ][ $k ][ 'weapp_template_id' ] = $message_info == null ? 0 : $message_info[ 'weapp_template_id' ];
- }
- }
- }
- return $this->success($list);
- }
-
-
- /**
- * 获取微信模板消息id
- * @param string $keywords
- * todo 批量获取模板消息
- */
- public function getWeappTemplateNo(string $keywords, $site_id, $weapp_is_open = 0)
- {
- $keyword = explode(',', $keywords);
- $wechat = new Weapp($site_id);
-
- if ($weapp_is_open == 1) {
- // 启用
- foreach ($keyword as $item) {
- $shop_message = model('message')->getInfo([ [ 'keywords', '=', $item ], [ "site_id", "=", $site_id ] ], 'weapp_template_id');
- $data = [
- 'weapp_is_open' => $weapp_is_open,
- 'site_id' => $site_id,
- 'keywords' => $item,
- ];
- // 开启时没有模板则进行添加
- if (!empty($shop_message)) {
- if (empty($shop_message[ 'weapp_template_id' ])) {
- $template_info = model('message_template')->getInfo([ [ 'keywords', '=', $item ], [ 'weapp_json', '<>', '' ] ], 'weapp_json');
- if (!empty($template_info)) {
- $template = json_decode($template_info[ 'weapp_json' ], true);
- $res = $wechat->getTemplateId($template);
- if (isset($res[ 'errcode' ]) && $res[ 'errcode' ] == 0) {
- $data[ 'weapp_template_id' ] = $res[ 'priTmplId' ];
- } else {
- return $this->error($res, $res[ 'errmsg' ]);
- }
- }
- }
- model('message')->update($data, [ [ 'keywords', '=', $item ], [ "site_id", "=", $site_id ] ]);
- } else {
- $template_info = model('message_template')->getInfo([ [ 'keywords', '=', $item ], [ 'weapp_json', '<>', '' ] ], 'weapp_json');
- if (!empty($template_info)) {
- $template = json_decode($template_info[ 'weapp_json' ], true);
- $res = $wechat->getTemplateId($template);
- if (isset($res[ 'errcode' ]) && $res[ 'errcode' ] == 0) {
- $data[ 'weapp_template_id' ] = $res[ 'priTmplId' ];
- } else {
- return $this->error($res, $res[ 'errmsg' ]);
- }
- }
- model('message')->add($data);
- }
- }
- } else if ($weapp_is_open == 0) {
- // 关闭
- foreach ($keyword as $item) {
- $shop_message = model('message')->getInfo([ [ 'keywords', '=', $item ], [ "site_id", "=", $site_id ] ], 'weapp_template_id');
- if (!empty($shop_message)) {
- model('message')->update([ 'weapp_is_open' => $weapp_is_open ], [ [ 'keywords', '=', $item ], [ "site_id", "=", $site_id ] ]);
- } else {
- model('message')->add([
- 'site_id' => $site_id,
- 'keywords' => $item,
- 'weapp_is_open' => $weapp_is_open
- ]);
- }
- }
- } else {
- // 获取
- $list = model('message_template')->getList([ [ 'keywords', 'in', $keyword ], [ 'weapp_json', '<>', '' ] ], 'keywords,weapp_json');
- if (!empty($list)) {
- foreach ($list as $item) {
- $template = json_decode($item[ 'weapp_json' ], true);
- $res = $wechat->getTemplateId($template);
- if (isset($res[ 'errcode' ]) && $res[ 'errcode' ] != 0) return $this->error($res, $res[ 'errmsg' ]);
-
- $shop_message = model('message')->getInfo([ [ 'keywords', '=', $item[ 'keywords' ] ], [ "site_id", "=", $site_id ] ], 'weapp_template_id');
-
- if (!empty($shop_message)) {
- model('message')->update([ 'weapp_template_id' => $res[ 'priTmplId' ] ], [ [ 'keywords', '=', $item[ 'keywords' ] ], [ "site_id", "=", $site_id ] ]);
- } else {
- model('message')->add([
- 'site_id' => $site_id,
- 'keywords' => $item[ 'keywords' ],
- 'weapp_template_id' => $res[ 'priTmplId' ]
- ]);
- }
- }
- }
- }
- return $this->success();
- }
-
- /**
- * 发送订阅消息
- * @param array $param
- */
- public function sendMessage(array $param)
- {
- try {
-
- $site_id = $param['site_id'] ?: 1;
- $support_type = $param['message_info']["support_type"] ?? [];
- if (empty($support_type) || strpos($support_type, "weapp") === false) return $this->success();
-
- if (empty($param['openid'])) return $this->success('缺少必需参数openid');
- $message_info = $param['message_info'];
- if ($message_info['weapp_is_open'] == 0) return $this->error('未启用模板消息');
- if (empty($message_info['weapp_template_id'])) return $this->error('未配置模板消息');
- $data = [
- 'openid' => $param['openid'],
- 'template_id' => $message_info['weapp_template_id'],
- 'data' => $param['template_data'],
- 'page' => $param['page'] ?? ''
- ];
- $weapp = new Weapp($site_id);
- $res = $weapp->sendTemplateMessage($data);
-
- return $res;
- } catch (\Exception $e) {
- return $this->error('', "消息发送失败");
- }
- }
-
- /**
- * 获取订阅消息模板id集合
- * @param $site_id
- * @param $keywords
- */
- public function getMessageTmplIds($site_id, $keywords){
- $data = model('message')->getColumn([ ['weapp_is_open', '=', 1], ['weapp_template_id', '<>', ''], ['site_id', '=', $site_id], ['keywords', 'in', explode(',', $keywords) ] ], 'weapp_template_id');
- return $this->success($data);
- }
+pageList($condition, 'id,keywords,title,message_type,weapp_json', $order, $page, $page_size);
+ if ($site_id > 0) {
+ if (!empty($list[ 'list' ])) {
+ foreach ($list[ 'list' ] as $k => $v) {
+ $list[ 'list' ][ $k ]['message_info'] = json_decode($v['weapp_json'], true);
+ $message_info = model('message')->getInfo([ [ "keywords", "=", $v[ 'keywords' ] ], [ 'site_id', '=', $site_id ] ], 'weapp_is_open,weapp_template_id');
+ $list[ 'list' ][ $k ][ 'weapp_is_open' ] = $message_info == null ? 0 : $message_info[ 'weapp_is_open' ];
+ $list[ 'list' ][ $k ][ 'weapp_template_id' ] = $message_info == null ? 0 : $message_info[ 'weapp_template_id' ];
+ }
+ }
+ }
+ return $this->success($list);
+ }
+
+
+ /**
+ * 获取微信模板消息id
+ * @param string $keywords
+ * todo 批量获取模板消息
+ */
+ public function getWeappTemplateNo(string $keywords, $site_id, $weapp_is_open = 0)
+ {
+ $keyword = explode(',', $keywords);
+ $wechat = new Weapp($site_id);
+
+ if ($weapp_is_open == 1) {
+ // 启用
+ foreach ($keyword as $item) {
+ $shop_message = model('message')->getInfo([ [ 'keywords', '=', $item ], [ "site_id", "=", $site_id ] ], 'weapp_template_id');
+ $data = [
+ 'weapp_is_open' => $weapp_is_open,
+ 'site_id' => $site_id,
+ 'keywords' => $item,
+ ];
+ // 开启时没有模板则进行添加
+ if (!empty($shop_message)) {
+ if (empty($shop_message[ 'weapp_template_id' ])) {
+ $template_info = model('message_template')->getInfo([ [ 'keywords', '=', $item ], [ 'weapp_json', '<>', '' ] ], 'weapp_json');
+ if (!empty($template_info)) {
+ $template = json_decode($template_info[ 'weapp_json' ], true);
+ $res = $wechat->getTemplateId($template);
+ if (isset($res[ 'errcode' ]) && $res[ 'errcode' ] == 0) {
+ $data[ 'weapp_template_id' ] = $res[ 'priTmplId' ];
+ } else {
+ return $this->error($res, $res[ 'errmsg' ]);
+ }
+ }
+ }
+ model('message')->update($data, [ [ 'keywords', '=', $item ], [ "site_id", "=", $site_id ] ]);
+ } else {
+ $template_info = model('message_template')->getInfo([ [ 'keywords', '=', $item ], [ 'weapp_json', '<>', '' ] ], 'weapp_json');
+ if (!empty($template_info)) {
+ $template = json_decode($template_info[ 'weapp_json' ], true);
+ $res = $wechat->getTemplateId($template);
+ if (isset($res[ 'errcode' ]) && $res[ 'errcode' ] == 0) {
+ $data[ 'weapp_template_id' ] = $res[ 'priTmplId' ];
+ } else {
+ return $this->error($res, $res[ 'errmsg' ]);
+ }
+ }
+ model('message')->add($data);
+ }
+ }
+ } else if ($weapp_is_open == 0) {
+ // 关闭
+ foreach ($keyword as $item) {
+ $shop_message = model('message')->getInfo([ [ 'keywords', '=', $item ], [ "site_id", "=", $site_id ] ], 'weapp_template_id');
+ if (!empty($shop_message)) {
+ model('message')->update([ 'weapp_is_open' => $weapp_is_open ], [ [ 'keywords', '=', $item ], [ "site_id", "=", $site_id ] ]);
+ } else {
+ model('message')->add([
+ 'site_id' => $site_id,
+ 'keywords' => $item,
+ 'weapp_is_open' => $weapp_is_open
+ ]);
+ }
+ }
+ } else {
+ // 获取
+ $list = model('message_template')->getList([ [ 'keywords', 'in', $keyword ], [ 'weapp_json', '<>', '' ] ], 'keywords,weapp_json');
+ if (!empty($list)) {
+ foreach ($list as $item) {
+ $template = json_decode($item[ 'weapp_json' ], true);
+ $res = $wechat->getTemplateId($template);
+ if (isset($res[ 'errcode' ]) && $res[ 'errcode' ] != 0) return $this->error($res, $res[ 'errmsg' ]);
+
+ $shop_message = model('message')->getInfo([ [ 'keywords', '=', $item[ 'keywords' ] ], [ "site_id", "=", $site_id ] ], 'weapp_template_id');
+
+ if (!empty($shop_message)) {
+ model('message')->update([ 'weapp_template_id' => $res[ 'priTmplId' ] ], [ [ 'keywords', '=', $item[ 'keywords' ] ], [ "site_id", "=", $site_id ] ]);
+ } else {
+ model('message')->add([
+ 'site_id' => $site_id,
+ 'keywords' => $item[ 'keywords' ],
+ 'weapp_template_id' => $res[ 'priTmplId' ]
+ ]);
+ }
+ }
+ }
+ }
+ return $this->success();
+ }
+
+ /**
+ * 发送订阅消息
+ * @param array $param
+ */
+ public function sendMessage(array $param)
+ {
+ try {
+
+ $site_id = $param['site_id'] ?: 1;
+ $support_type = $param['message_info']["support_type"] ?? [];
+ if (empty($support_type) || strpos($support_type, "weapp") === false) return $this->success();
+
+ if (empty($param['openid'])) return $this->success('缺少必需参数openid');
+ $message_info = $param['message_info'];
+ if ($message_info['weapp_is_open'] == 0) return $this->error('未启用模板消息');
+ if (empty($message_info['weapp_template_id'])) return $this->error('未配置模板消息');
+ $data = [
+ 'openid' => $param['openid'],
+ 'template_id' => $message_info['weapp_template_id'],
+ 'data' => $param['template_data'],
+ 'page' => $param['page'] ?? ''
+ ];
+ $weapp = new Weapp($site_id);
+ $res = $weapp->sendTemplateMessage($data);
+
+ return $res;
+ } catch (\Exception $e) {
+ return $this->error('', "消息发送失败");
+ }
+ }
+
+ /**
+ * 获取订阅消息模板id集合
+ * @param $site_id
+ * @param $keywords
+ */
+ public function getMessageTmplIds($site_id, $keywords){
+ $data = model('message')->getColumn([ ['weapp_is_open', '=', 1], ['weapp_template_id', '<>', ''], ['site_id', '=', $site_id], ['keywords', 'in', explode(',', $keywords) ] ], 'weapp_template_id');
+ return $this->success($data);
+ }
}
\ No newline at end of file
diff --git a/src/addon/weapp/model/Stat.php b/src/addon/weapp/model/Stat.php
index 04ddae5a1..8a7a1fd6d 100644
--- a/src/addon/weapp/model/Stat.php
+++ b/src/addon/weapp/model/Stat.php
@@ -1,199 +1,191 @@
-dailyVisitTrend($begin_date, $end_date);
- if ($result["code"] < 0)
- return $result;
-
- Cache::tag("weapp_visit")->set("weapp_daily_visit_trend" . "_" . $begin_date . "_" . $end_date, $result["data"]);
- return $result;
- }
-
- /**
- * 小程序 访问周趋势
- * @param $from
- * @param $to
- */
- public function weeklyVisitTrend($begin_date, $end_date)
- {
- $info = Cache::get("weapp_weekly_visit_trend" . "_" . $begin_date . "_" . $end_date);
- if (!empty($info)) {
- return success($info);
- }
- $wepp_model = new Weapp();
- $result = $wepp_model->weeklyVisitTrend($begin_date, $end_date);
- if ($result["code"] < 0)
- return $result;
-
- Cache::tag("weapp_visit")->set("weapp_weekly_visit_trend" . "_" . $begin_date . "_" . $end_date, $result["data"]);
- return $result;
- }
-
- /**
- * 小程序 访问月趋势
- * @param $from
- * @param $to
- */
- public function monthlyVisitTrend($begin_date, $end_date)
- {
- $info = Cache::get("weapp_monthly_visit_trend" . "_" . $begin_date . "_" . $end_date);
- if (!empty($info)) {
- return success($info);
- }
- $wepp_model = new Weapp();
- $result = $wepp_model->monthlyVisitTrend($begin_date, $end_date);
- if ($result["code"] < 0)
- return $result;
-
- Cache::tag("weapp_visit")->set("weapp_monthly_visit_trend" . "_" . $begin_date . "_" . $end_date, $result["data"]);
- return $result;
- }
-
- /**
- * 小程序 访问日趋势
- * @param $from
- * @param $to
- */
- public function visitPage($begin_date, $end_date)
- {
- $info = Cache::get("weapp_visit_page" . "_" . $begin_date . "_" . $end_date);
- if (!empty($info)) {
- return success($info);
- }
- $wepp_model = new Weapp();
- $result = $wepp_model->dailyVisitTrend($begin_date, $end_date);
- if ($result["code"] < 0)
- return $result;
-
- Cache::tag("weapp_visit")->set("weapp_visit_page" . "_" . $begin_date . "_" . $end_date, $result["data"]);
- return $result;
- }
-
- /**
- * 查询微信小程序访问数据
- * @param $date_type
- * @param $daterange
- */
- public function visitData($date_type)
- {
- $result = [];
-
- switch ($date_type) {
- case 'yesterday':
- $begin_date = date('Ymd', strtotime('-1 days'));
- $end_date = date('Ymd', strtotime('-1 days'));
- $result = $this->dailyVisitTrend($begin_date, $end_date);
- break;
- case 'month':
- $begin_date = date('Y-m-d', strtotime(date('Y-m-01') . ' -1 month'));
- $end_date = date('Y-m-d', strtotime(date('Y-m-01') . ' -1 day'));
- $result = $this->monthlyVisitTrend($begin_date, $end_date);
- break;
- }
-
- return $result;
- }
-
- /**
- * 获取微信小程序 数据分析统计
- */
- public function visitStatistics($daterange)
- {
- if (empty($daterange))
- return $this->success([]);
-
- $is_error = true;
- $daterange_array = explode(" 至 ", $daterange);
- $start_date = date_format(date_create($daterange_array[0]), "Ymd");
- $end_date = date_format(date_create($daterange_array[1]), "Ymd");
- $date_x = periodGroup(strtotime($start_date), strtotime($end_date));
- $session_cnt_data = [];//打开次数
- $visit_pv_data = [];//访问次数
- $visit_uv_data = [];//访问人数
- $visit_uv_new_data = [];//新用户数
- $stay_time_uv_data = [];//人均停留时长 (浮点型,单位:秒)
- $stay_time_session_data = [];//次均停留时长 (浮点型,单位:秒)
- $visit_depth_data = [];//平均访问深度 (浮点型)
- foreach ($date_x as $k => $v) {
- $session_cnt = 0;//打开次数
- $visit_pv = 0;//访问次数
- $visit_uv = 0;//访问人数
- $visit_uv_new = 0;//新用户数
- $stay_time_uv = 0;//人均停留时长 (浮点型,单位:秒)
- $stay_time_session = 0;//次均停留时长 (浮点型,单位:秒)
- $visit_depth = 0;//平均访问深度 (浮点型)
- if ($is_error) {
-// $temp_daterange = array(
-// "begin_date" => $v,
-// "end_date" => $v,
-// "site_id" => $site_id
-// );
- $result = $this->dailyVisitTrend($v, $v);
- $temp_data = $result["data"];
- if (!empty($temp_data)) {
- $session_cnt = $temp_data["session_cnt"];//打开次数
- $visit_pv = $temp_data["visit_pv"];//访问次数
- $visit_uv = $temp_data["visit_uv"];//访问人数
- $visit_uv_new = $temp_data["visit_uv_new"];//新用户数
- $stay_time_uv = $temp_data["stay_time_uv"];//人均停留时长 (浮点型,单位:秒)
- $stay_time_session = $temp_data["stay_time_session"];//次均停留时长 (浮点型,单位:秒)
- $visit_depth = $temp_data["visit_depth"];//平均访问深度 (浮点型)
- } else {
- $is_error = false;
- }
- }
-
- $session_cnt_data[] = $session_cnt;//打开次数
- $visit_pv_data[] = $visit_pv;//访问次数
- $visit_uv_data[] = $visit_uv;//访问人数
- $visit_uv_new_data[] = $visit_uv_new;//新用户数
- $stay_time_uv_data[] = $stay_time_uv;//人均停留时长 (浮点型,单位:秒)
- $stay_time_session_data[] = $stay_time_session;//次均停留时长 (浮点型,单位:秒)
- $visit_depth_data[] = $visit_depth;//平均访问深度 (浮点型)
- }
-
- $statistics_data = array(
- "date" => $date_x,
- "data" => array(
- "session_cnt_data" => $session_cnt_data,
- "visit_pv_data" => $visit_pv_data,
- "visit_uv_data" => $visit_uv_data,
- "visit_uv_new_data" => $visit_uv_new_data,
- "stay_time_uv_data" => $stay_time_uv_data,
- "stay_time_session_data" => $stay_time_session_data,
- "visit_depth_data" => $visit_depth_data,
- )
- );
- return $this->success($statistics_data);
- }
+dailyVisitTrend($begin_date, $end_date);
+ if ($result["code"] < 0)
+ return $result;
+
+ Cache::tag("weapp_visit")->set("weapp_daily_visit_trend" . "_" . $begin_date . "_" . $end_date, $result["data"]);
+ return $result;
+ }
+
+ /**
+ * 小程序 访问周趋势
+ * @param $from
+ * @param $to
+ */
+ public function weeklyVisitTrend($begin_date, $end_date)
+ {
+ $info = Cache::get("weapp_weekly_visit_trend" . "_" . $begin_date . "_" . $end_date);
+ if (!empty($info)) {
+ return success($info);
+ }
+ $wepp_model = new Weapp();
+ $result = $wepp_model->weeklyVisitTrend($begin_date, $end_date);
+ if ($result["code"] < 0)
+ return $result;
+
+ Cache::tag("weapp_visit")->set("weapp_weekly_visit_trend" . "_" . $begin_date . "_" . $end_date, $result["data"]);
+ return $result;
+ }
+
+ /**
+ * 小程序 访问月趋势
+ * @param $from
+ * @param $to
+ */
+ public function monthlyVisitTrend($begin_date, $end_date)
+ {
+ $info = Cache::get("weapp_monthly_visit_trend" . "_" . $begin_date . "_" . $end_date);
+ if (!empty($info)) {
+ return success($info);
+ }
+ $wepp_model = new Weapp();
+ $result = $wepp_model->monthlyVisitTrend($begin_date, $end_date);
+ if ($result["code"] < 0)
+ return $result;
+
+ Cache::tag("weapp_visit")->set("weapp_monthly_visit_trend" . "_" . $begin_date . "_" . $end_date, $result["data"]);
+ return $result;
+ }
+
+ /**
+ * 小程序 访问日趋势
+ * @param $from
+ * @param $to
+ */
+ public function visitPage($begin_date, $end_date)
+ {
+ $info = Cache::get("weapp_visit_page" . "_" . $begin_date . "_" . $end_date);
+ if (!empty($info)) {
+ return success($info);
+ }
+ $wepp_model = new Weapp();
+ $result = $wepp_model->dailyVisitTrend($begin_date, $end_date);
+ if ($result["code"] < 0)
+ return $result;
+
+ Cache::tag("weapp_visit")->set("weapp_visit_page" . "_" . $begin_date . "_" . $end_date, $result["data"]);
+ return $result;
+ }
+
+ /**
+ * 查询微信小程序访问数据
+ * @param $date_type
+ * @param $daterange
+ */
+ public function visitData($date_type)
+ {
+ $result = [];
+
+ switch ($date_type) {
+ case 'yesterday':
+ $begin_date = date('Ymd', strtotime('-1 days'));
+ $end_date = date('Ymd', strtotime('-1 days'));
+ $result = $this->dailyVisitTrend($begin_date, $end_date);
+ break;
+ case 'month':
+ $begin_date = date('Y-m-d', strtotime(date('Y-m-01') . ' -1 month'));
+ $end_date = date('Y-m-d', strtotime(date('Y-m-01') . ' -1 day'));
+ $result = $this->monthlyVisitTrend($begin_date, $end_date);
+ break;
+ }
+
+ return $result;
+ }
+
+ /**
+ * 获取微信小程序 数据分析统计
+ */
+ public function visitStatistics($daterange)
+ {
+ if (empty($daterange))
+ return $this->success([]);
+
+ $is_error = true;
+ $daterange_array = explode(" 至 ", $daterange);
+ $start_date = date_format(date_create($daterange_array[0]), "Ymd");
+ $end_date = date_format(date_create($daterange_array[1]), "Ymd");
+ $date_x = periodGroup(strtotime($start_date), strtotime($end_date));
+ $session_cnt_data = [];//打开次数
+ $visit_pv_data = [];//访问次数
+ $visit_uv_data = [];//访问人数
+ $visit_uv_new_data = [];//新用户数
+ $stay_time_uv_data = [];//人均停留时长 (浮点型,单位:秒)
+ $stay_time_session_data = [];//次均停留时长 (浮点型,单位:秒)
+ $visit_depth_data = [];//平均访问深度 (浮点型)
+ foreach ($date_x as $k => $v) {
+ $session_cnt = 0;//打开次数
+ $visit_pv = 0;//访问次数
+ $visit_uv = 0;//访问人数
+ $visit_uv_new = 0;//新用户数
+ $stay_time_uv = 0;//人均停留时长 (浮点型,单位:秒)
+ $stay_time_session = 0;//次均停留时长 (浮点型,单位:秒)
+ $visit_depth = 0;//平均访问深度 (浮点型)
+ if ($is_error) {
+// $temp_daterange = array(
+// "begin_date" => $v,
+// "end_date" => $v,
+// "site_id" => $site_id
+// );
+ $result = $this->dailyVisitTrend($v, $v);
+ $temp_data = $result["data"];
+ if (!empty($temp_data)) {
+ $session_cnt = $temp_data["session_cnt"];//打开次数
+ $visit_pv = $temp_data["visit_pv"];//访问次数
+ $visit_uv = $temp_data["visit_uv"];//访问人数
+ $visit_uv_new = $temp_data["visit_uv_new"];//新用户数
+ $stay_time_uv = $temp_data["stay_time_uv"];//人均停留时长 (浮点型,单位:秒)
+ $stay_time_session = $temp_data["stay_time_session"];//次均停留时长 (浮点型,单位:秒)
+ $visit_depth = $temp_data["visit_depth"];//平均访问深度 (浮点型)
+ } else {
+ $is_error = false;
+ }
+ }
+
+ $session_cnt_data[] = $session_cnt;//打开次数
+ $visit_pv_data[] = $visit_pv;//访问次数
+ $visit_uv_data[] = $visit_uv;//访问人数
+ $visit_uv_new_data[] = $visit_uv_new;//新用户数
+ $stay_time_uv_data[] = $stay_time_uv;//人均停留时长 (浮点型,单位:秒)
+ $stay_time_session_data[] = $stay_time_session;//次均停留时长 (浮点型,单位:秒)
+ $visit_depth_data[] = $visit_depth;//平均访问深度 (浮点型)
+ }
+
+ $statistics_data = array(
+ "date" => $date_x,
+ "data" => array(
+ "session_cnt_data" => $session_cnt_data,
+ "visit_pv_data" => $visit_pv_data,
+ "visit_uv_data" => $visit_uv_data,
+ "visit_uv_new_data" => $visit_uv_new_data,
+ "stay_time_uv_data" => $stay_time_uv_data,
+ "stay_time_session_data" => $stay_time_session_data,
+ "visit_depth_data" => $visit_depth_data,
+ )
+ );
+ return $this->success($statistics_data);
+ }
}
\ No newline at end of file
diff --git a/src/addon/weapp/model/Weapp.php b/src/addon/weapp/model/Weapp.php
index 903a9a0ee..230743704 100644
--- a/src/addon/weapp/model/Weapp.php
+++ b/src/addon/weapp/model/Weapp.php
@@ -1,1068 +1,1060 @@
- "小程序",
- );
-
- //小程序认证类型
- public $verify_type = array (
- -1 => "未认证",
- 0 => "微信认证",
- );
-
- //business_info 说明
- public $business_type = array (
- 'open_store' => "是否开通微信门店功能",
- 'open_scan' => "是否开通微信扫商品功能",
- 'open_pay' => "是否开通微信支付功能",
- 'open_card' => "是否开通微信卡券功能",
- 'open_shake' => "是否开通微信摇一摇功能",
- );
-
- // 站点ID
- private $site_id;
-
- public function __construct($site_id = 0)
- {
- $this->site_id = $site_id;
- //微信小程序配置
- $weapp_config_model = new WeappConfigModel();
- $weapp_config = $weapp_config_model->getWeappConfig($site_id)[ "data" ][ "value" ];
-
- if (isset($weapp_config[ 'is_authopen' ]) && addon_is_exit('wxoplatform')) {
- $plateform_config_model = new WxOplatformConfigModel();
- $plateform_config = $plateform_config_model->getOplatformConfig()[ "data" ][ "value" ];
-
- $config = [
- 'app_id' => $plateform_config[ "appid" ] ?? '',
- 'secret' => $plateform_config[ "secret" ] ?? '',
- 'token' => $plateform_config[ "token" ] ?? '',
- 'aes_key' => $plateform_config[ "aes_key" ] ?? '',
- 'log' => [
- 'level' => 'debug',
- 'permission' => 0777,
- 'file' => 'runtime/log/wechat/oplatform.logs',
- ],
- ];
- $open_platform = Factory::openPlatform($config);
- $this->app = $open_platform->miniProgram($weapp_config[ 'authorizer_appid' ], $weapp_config[ 'authorizer_refresh_token' ]);
- } else {
- $config = [
- 'app_id' => $weapp_config[ "appid" ] ?? '',
- 'secret' => $weapp_config[ "appsecret" ] ?? '',
- 'response_type' => 'array',
- 'log' => [
- 'level' => 'debug',
- 'permission' => 0777,
- 'file' => 'runtime/log/wechat/easywechat.logs',
- ],
- ];
- $this->app = Factory::miniProgram($config);
- }
- }
-
- /**
- * TODO
- * 根据 jsCode 获取用户 session 信息
- * @param $param
- * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
- */
- public function authCodeToOpenid($param)
- {
- try {
- $result = $this->app->auth->session($param[ 'code' ]);
- if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] != 0) {
- return $this->handleError($result[ 'errcode' ], $result[ 'errmsg' ]);
- } else {
- Cache::set('weapp_' . $result[ 'openid' ], $result);
- unset($result[ 'session_key' ]);
- return $this->success($result);
- }
- } catch (\Exception $e) {
- if (property_exists($e, 'formattedResponse')) {
- return $this->handleError($e->formattedResponse[ 'errcode' ], $e->formattedResponse[ 'errmsg' ]);
- }
- return $this->error('', $e->getMessage());
- }
- }
-
- /**
- * 生成二维码
- * @param unknown $param
- */
- public function createQrcode($param)
- {
- try {
- $checkpath_result = $this->checkPath($param[ 'qrcode_path' ]);
- if ($checkpath_result[ "code" ] != 0) return $checkpath_result;
-
- // scene:场景值最大32个可见字符,只支持数字,大小写英文以及部分特殊字符:!#$&'()*+,/:;=?@-._~
- $scene = '';
- if (!empty($param[ 'data' ])) {
- foreach ($param[ 'data' ] as $key => $value) {
- //防止参数过长,source_member用m代替
- if ($key == 'source_member') {
- $key = 'm';
- }
- if ($scene == '') $scene .= $key . '-' . $value;
- else $scene .= '&' . $key . '-' . $value;
- }
- }
- $response = $this->app->app_code->getUnlimit($scene, [
- 'page' => substr($param[ 'page' ], 1),
- 'width' => $param['width'] ?? 120
- ]);
- if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) {
- $filename = $param[ 'qrcode_path' ] . '/';
- $filename .= $response->saveAs($param[ 'qrcode_path' ], $param[ 'qrcode_name' ] . '_' . $param[ 'app_type' ] . '.png');
- return $this->success([ 'type' => 'weapp', 'path' => $filename ]);
- } else {
- return $this->handleError($response[ 'errcode' ], $response[ 'errmsg' ]);
- }
- } catch (\Exception $e) {
- if (property_exists($e, 'formattedResponse')) {
- return $this->handleError($e->formattedResponse[ 'errcode' ], $e->formattedResponse[ 'errmsg' ]);
- }
- return $this->error('', $e->getMessage());
- }
- }
-
- /**
- * 校验目录是否可写
- * @param unknown $path
- * @return multitype:number unknown |multitype:unknown
- */
- private function checkPath($path)
- {
- if (is_dir($path) || mkdir($path, intval('0755', 8), true)) {
- return $this->success();
- }
- return $this->error('', "directory {$path} creation failed");
- }
- /************************************************************* 数据统计与分析 start **************************************************************/
-
- /**
- * 访问日趋势
- * @param $from 格式 20170313
- * @param $to 格式 20170313
- */
- public function dailyVisitTrend($from, $to)
- {
- try {
- $result = $this->app->data_cube->dailyVisitTrend($from, $to);
- if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] != 0) {
- return $this->error([], $result[ "errmsg" ]);
- }
- return $this->success($result[ "list" ]);
- } catch (\Exception $e) {
- return $this->error([], $e->getMessage());
- }
-
- }
-
- /**
- * 访问周趋势
- * @param $from
- * @param $to
- * @return array
- */
- public function weeklyVisitTrend($from, $to)
- {
- try {
- $result = $this->app->data_cube->weeklyVisitTrend($from, $to);
- if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] != 0) {
- return $this->error([], $result[ "errmsg" ]);
- }
- return $this->success($result[ "list" ]);
- } catch (\Exception $e) {
- return $this->error([], $e->getMessage());
- }
- }
-
- /**
- * 访问月趋势
- * @param $from
- * @param $to
- * @return array
- */
- public function monthlyVisitTrend($from, $to)
- {
- try {
- $result = $this->app->data_cube->monthlyVisitTrend($from, $to);
- if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] != 0) {
- return $this->error([], $result[ "errmsg" ]);
- }
- return $this->success($result[ "list" ]);
- } catch (\Exception $e) {
- return $this->error([], $e->getMessage());
- }
- }
-
- /**
- * 访问分布
- * @param $from
- * @param $to
- * @return array
- */
- public function visitDistribution($from, $to)
- {
- try {
- $result = $this->app->data_cube->visitDistribution($from, $to);
- if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] != 0) {
- return $this->error($result, $result[ "errmsg" ]);
- }
- return $this->success($result[ "list" ]);
- } catch (\Exception $e) {
- return $this->error([], $e->getMessage());
- }
- }
-
- /**
- * 访问页面
- * @param $from
- * @param $to
- * @return array
- */
- public function visitPage($from, $to)
- {
- try {
- $result = $this->app->data_cube->visitPage($from, $to);
- if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] != 0) {
- return $this->error([], $result[ "errmsg" ]);
- }
- return $this->success($result[ "list" ]);
- } catch (\Exception $e) {
- return $this->error([], $e->getMessage());
- }
- }
- /************************************************************* 数据统计与分析 end **************************************************************/
-
- /**
- * 下载小程序代码包
- * @param $site_id
- */
- public function download($site_id)
- {
- $source_file_path = $this->createTempPackage($site_id, 'public/weapp');
- $file_arr = getFileMap($source_file_path);
-
- if (!empty($file_arr)) {
- $zipname = 'upload/weapp_' . $site_id . '_' . date('Ymd') . '.zip';
-
- $zip = new \ZipArchive();
- $res = $zip->open($zipname, \ZipArchive::CREATE);
- if ($res === TRUE) {
- foreach ($file_arr as $file_path => $file_name) {
- if (is_dir($file_path)) {
- $file_path = str_replace($source_file_path . '/', '', $file_path);
- $zip->addEmptyDir($file_path);
- } else {
- $zip_path = str_replace($source_file_path . '/', '', $file_path);
- $zip->addFile($file_path, $zip_path);
- }
- }
- $zip->close();
-
- header("Content-Type: application/zip");
- header("Content-Transfer-Encoding: Binary");
- header("Content-Length: " . filesize($zipname));
- header("Content-Disposition: attachment; filename=\"" . basename($zipname) . "\"");
- readfile($zipname);
- @unlink($zipname);
- deleteDir($source_file_path);
- }
- }
- }
-
- /**
- * 创建临时包
- * @param $site_id
- * @param $package_path
- * @param string $to_path
- * @return string
- */
- private function createTempPackage($site_id, $package_path, $to_path = '')
- {
- if (is_dir($package_path)) {
- $package = scandir($package_path);
-
- if (empty($to_path)) {
- $to_path = 'upload/temp/' . $site_id . '/';
- dir_mkdir($to_path);
- }
-
- foreach ($package as $path) {
- $temp_path = $package_path . '/' . $path;
- if (is_dir($temp_path)) {
- if ($path == '.' || $path == '..') {//判断是否为系统隐藏的文件.和.. 如果是则跳过否则就继续往下走,防止无限循环再这里。
- continue;
- }
- dir_mkdir($to_path . $path);
- $this->createTempPackage($site_id, $temp_path, $to_path . $path . '/');
- } else {
- if (file_exists($temp_path)) {
- copy($temp_path, $to_path . $path);
- if (stristr($temp_path, 'common/vendor.js')) {
- $content = file_get_contents($to_path . $path);
- $content = $this->paramReplace($site_id, $content);
- file_put_contents($to_path . $path, $content);
- }
- }
- }
- }
- return $to_path;
- }
- }
-
- /**
- * 参数替换
- * @param $site_id
- * @param $string
- * @return null|string|string[]
- */
- private function paramReplace($site_id, $string)
- {
- $api_model = new Api();
- $api_config = $api_model->getApiConfig()[ 'data' ];
-
- $web_config_model = new WebConfig();
- $web_config = $web_config_model->getMapConfig()[ 'data' ][ 'value' ];
-
- $socket_url = ( strstr(ROOT_URL, 'https://') === false ? str_replace('http', 'ws', ROOT_URL) : str_replace('https', 'wss', ROOT_URL) ) . '/wss';
-
- $patterns = [
- '/\{\{\$baseUrl\}\}/',
- '/\{\{\$imgDomain\}\}/',
- '/\{\{\$h5Domain\}\}/',
- '/\{\{\$mpKey\}\}/',
- '/\{\{\$apiSecurity\}\}/',
- '/\{\{\$publicKey\}\}/',
- '/\{\{\$webSocket\}\}/'
- ];
- $replacements = [
- ROOT_URL,
- ROOT_URL,
- ROOT_URL . '/h5',
- $web_config[ 'tencent_map_key' ] ?? '',
- $api_config[ 'is_use' ] ?? 0,
- $api_config[ 'value' ][ 'public_key' ] ?? '',
- $socket_url
- ];
- $string = preg_replace($patterns, $replacements, $string);
- return $string;
- }
-
- /**
- * 消息解密
- * @param array $param
- */
- public function decryptData($param = [])
- {
- try {
- $cache = Cache::get('weapp_' . $param[ 'weapp_openid' ]);
- $session_key = $cache[ 'session_key' ] ?? '';
- $result = $this->app->encryptor->decryptData($session_key, $param[ 'iv' ], $param[ 'encryptedData' ]);
- if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] != 0) {
- return $this->handleError($result[ 'errcode' ], $result[ 'errmsg' ]);
- }
- return $this->success($result);
- } catch (\Exception $e) {
- if (property_exists($e, 'formattedResponse')) {
- return $this->handleError($e->formattedResponse[ 'errcode' ], $e->formattedResponse[ 'errmsg' ]);
- }
- return $this->error([], $e->getMessage());
- }
- }
-
- /**
- * 获取用户手机号
- * @param $code
- * @return array
- * @throws \GuzzleHttp\Exception\GuzzleException
- */
- public function getUserPhoneNumber($code)
- {
- try {
- $result = $this->app->auth->phoneNumber($code);
- if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] != 0) {
- return $this->handleError($result[ 'errcode' ], $result[ 'errmsg' ]);
- }
- return $this->success($result[ 'phone_info' ]);
- } catch (\Exception $e) {
- if (property_exists($e, 'formattedResponse')) {
- return $this->handleError($e->formattedResponse[ 'errcode' ], $e->formattedResponse[ 'errmsg' ]);
- }
- return $this->error([], $e->getMessage());
- }
- }
-
- /**
- * 获取订阅消息template_id
- * @param array $param
- */
- public function getTemplateId(array $param)
- {
- try {
- $result = $this->app->subscribe_message->addTemplate($param[ 'tid' ], $param[ 'kidList' ], $param[ 'sceneDesc' ]);
- return $result;
- } catch (\Exception $e) {
- return [ 'errcode' => -1, 'errmsg' => $e->getMessage() ];
- }
- }
-
- /**
- * 发送订阅消息
- * @param array $param
- * @return array
- */
- public function sendTemplateMessage(array $param)
- {
- $result = $this->app->subscribe_message->send([
- 'template_id' => $param[ 'template_id' ],// 模板id
- 'touser' => $param[ 'openid' ], // openid
- 'page' => $param[ 'page' ], // 点击模板卡片后的跳转页面 支持带参数
- 'data' => $param[ 'data' ] // 模板变量
- ]);
-
- if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] != 0) {
- return $this->error($result, $result[ "errmsg" ]);
- }
- return $this->success($result);
- }
-
- /**
- * 消息推送
- */
- public function relateWeixin()
- {
- $server = $this->app->server;
- $message = $server->getMessage();
- Log::write('微信小程序消息推送:' . json_encode($message));
- // file_put_contents(__DIR__ . '/debug.txt', var_export($message,true));
- if (isset($message[ 'MsgType' ])) {
- switch ( $message[ 'MsgType' ] ) {
- case 'event':
- $this->app->server->push(function($res) {
- // file_put_contents(__DIR__ . '/debug1.txt', var_export($res,true));
- // 商品审核结果通知
- if ($res[ 'Event' ] == 'open_product_spu_audit' && addon_is_exit('shopcomponent', $this->site_id)) {
- model('shopcompoent_goods')->update([
- 'edit_status' => $res[ 'OpenProductSpuAudit' ][ 'status' ],
- 'reject_reason' => !empty($res[ 'OpenProductSpuAudit' ][ 'reject_reason' ]) ? : '',
- 'audit_time' => time()
- ], [
- [ 'out_product_id', '=', $res[ 'OpenProductSpuAudit' ][ 'out_product_id' ] ]
- ]);
- }
- // 类目审核结果通知
- if ($res[ 'Event' ] == 'open_product_category_audit' && addon_is_exit('shopcomponent', $this->site_id)) {
- model('shopcompoent_category_audit')->update([
- 'status' => $res[ 'QualificationAuditResult' ][ 'status' ],
- 'reject_reason' => !empty($res[ 'QualificationAuditResult' ][ 'reject_reason' ]) ? : '',
- 'audit_time' => time()
- ], [
- [ 'audit_id', '=', $res[ 'QualificationAuditResult' ][ 'audit_id' ] ]
- ]);
- }
-
- // 视频号支付订单回调
- if ($res[ 'Event' ] == 'open_product_order_pay' && addon_is_exit('shopcomponent', $this->site_id)) {
- event("shopcomponentNotify", $res);
- }
-
- // todo trade_manage_remind_access_api 提醒接入发货信息管理服务API
- if ($res[ 'Event' ] == 'trade_manage_remind_access_api' && addon_is_exit('weapp', $this->site_id)) {
- Log::write('提醒接入发货信息管理服务API(trade_manage_remind_access_api):' . json_encode($res));
- }
-
- // todo trade_manage_remind_shipping 提醒需要上传发货信息
- if ($res[ 'Event' ] == 'trade_manage_remind_shipping' && addon_is_exit('weapp', $this->site_id)) {
- Log::write('提醒需要上传发货信息(trade_manage_remind_shipping):' . json_encode($res));
- }
-
- // todo trade_manage_order_settlement 订单将要结算或已经结算
- if ($res[ 'Event' ] == 'trade_manage_order_settlement' && addon_is_exit('weapp', $this->site_id)) {
- Log::write('订单将要结算或已经结算(trade_manage_order_settlement):' . json_encode($res));
- }
- });
- break;
- }
- }
- $response = $this->app->server->serve();
- return $response->send();
- }
-
- /**
- * 检查场景值是否在支付校验范围内
- * @param $scene
- * @return array
- * @throws \GuzzleHttp\Exception\GuzzleException
- */
- public function sceneCheck($scene)
- {
- try {
- $result = $this->app->mini_store->checkScene($scene);
- if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] == 0) {
- return $this->success($result[ 'is_matched' ]);
- } else {
- return $this->error('', $result[ 'errmsg' ]);
- }
- } catch (\Exception $e) {
- return $this->error([], $e->getMessage());
- }
- }
-
- public function createOrder($order_info)
- {
- try {
- $result = $this->app->mini_store->addOrder($order_info);
- if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] == 0) {
- return $this->success($result[ 'is_matched' ]);
- } else {
- return $this->error('', $result[ 'errmsg' ]);
- }
- } catch (\Exception $e) {
- return $this->error([], $e->getMessage());
- }
- }
-
- /**
- * 处理错误信息
- * @param $errcode
- * @param string $message
- * @return array
- */
- public function handleError($errcode, $message = '')
- {
- $error = require 'addon/weapp/config/weapp_error.php';
- return $this->error([], $error[ $errcode ] ?? $message);
- }
-
- /**
- * 查询小程序是否已开通发货信息管理服务
- * @return array
- * @throws \GuzzleHttp\Exception\GuzzleException
- */
- public function orderShippingIsTradeManaged()
- {
- try {
- $result = $this->app->order_shipping->isTradeManaged();
- if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] != 0) {
- return $this->error(false, $result[ "errmsg" ]);
- }
- return $this->success($result[ 'is_trade_managed' ]);
- } catch (\Exception $e) {
- return $this->error(false, $e->getMessage());
- }
- }
-
- /**
- * 查询订单列表
- * @param array $data
- * @return array
- * @throws \GuzzleHttp\Exception\GuzzleException
- */
- public function orderShippingGetOrderList($data = [])
- {
- try {
- $params = [
- 'pay_time_range' => [
- 'begin_time' => $data[ 'begin_time' ] ?? 0, // 起始时间,时间戳形式,不填则视为从0开始。
- 'end_time' => $data[ 'end_time' ] ?? time() // 结束时间(含),时间戳形式,不填则视为32位无符号整型的最大值。
- ],
- 'page_size' => $data[ 'page_size' ] ?? 100 // 翻页时使用,返回列表的长度,默认为100。
- ];
-
- // 订单状态枚举:(1) 待发货;(2) 已发货;(3) 确认收货;(4) 交易完成;(5) 已退款。
- if (!empty($data[ 'order_state' ])) {
- $params[ 'order_state' ] = $data[ 'order_state' ];
- }
-
- // 翻页时使用,获取第一页时不用传入,如果查询结果中 has_more 字段为 true,则传入该次查询结果中返回的 last_index 字段可获取下一页。
- if (!empty($data[ 'last_index' ])) {
- $params[ 'last_index' ] = $data[ 'last_index' ];
- }
-
- $result = $this->app->order_shipping->getOrderList($params);
- if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] != 0) {
- return $this->error([], $result[ "errmsg" ]);
- }
-
- return $this->success($result);
- } catch (\Exception $e) {
- return $this->error([], $e->getMessage());
- }
- }
-
- /**
- * 查询订单发货状态
- * @param array $data
- * @return array
- * @throws \GuzzleHttp\Exception\GuzzleException
- */
- public function orderShippingGetOrder($data = [])
- {
- try {
- $params = [];
-
- // 原支付交易对应的微信订单号
- if (!empty($data[ 'transaction_id' ])) {
- $params[ 'transaction_id' ] = $data[ 'transaction_id' ];
- }
-
- // 支付下单商户的商户号,由微信支付生成并下发
- if (!empty($data[ 'merchant_id' ])) {
- $params[ 'merchant_id' ] = $data[ 'merchant_id' ];
- }
-
- // 商户系统内部订单号,只能是数字、大小写字母`_-*`且在同一个商户号下唯一
- if (!empty($data[ 'merchant_trade_no' ])) {
- $params[ 'merchant_trade_no' ] = $data[ 'merchant_trade_no' ];
- }
-
- // 二级商户号
- if (!empty($data[ 'sub_merchant_id' ])) {
- $params[ 'sub_merchant_id' ] = $data[ 'sub_merchant_id' ];
- }
-
- $result = $this->app->order_shipping->getOrder($params);
- if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] != 0) {
- return $this->error([], $result[ "errmsg" ]);
- }
-
- return $this->success($result[ 'order' ]);
- } catch (\Exception $e) {
- return $this->error([], $e->getMessage());
- }
- }
-
- /**
- * 消息跳转路径设置接口
- * @param $order_id
- * @param $order_type
- * @return array
- * @throws \GuzzleHttp\Exception\GuzzleException
- */
- public function orderShippingSetMsgJumpPath($order_id, $order_type)
- {
- try {
- $path = 'pages/order/detail?order_id=' . $order_id; // 物流订单
- switch ( $order_type ) {
- case 2:
- // 门店自提订单
- $path = 'pages/order/detail_pickup?order_id=' . $order_id;
- break;
- case 3:
- // 外卖订单
- $path = 'pages/order/detail_local_delivery?order_id=' . $order_id;
- break;
- case 4:
- // 虚拟订单
- $path = 'pages_tool/order/detail_virtual?order_id=' . $order_id;
- break;
- }
- $result = $this->app->order_shipping->setMsgJumpPath($path);
- if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] != 0) {
- return $this->error([], $result[ "errmsg" ]);
- }
- return $this->success($result);
- } catch (\Exception $e) {
- return $this->error([], $e->getMessage());
- }
-
- }
-
- /**
- * 订单发货信息录入接口
- * @param array $data
- * @return array
- * @throws \GuzzleHttp\Exception\GuzzleException
- */
- public function orderShippingUploadShippingInfo($data = [])
- {
-
- try {
- // 检测微信小程序是否已开通发货信息管理服务
- $is_trade_managed = $this->orderShippingIsTradeManaged();
- if (!$is_trade_managed[ 'data' ]) {
- return $this->success('', $is_trade_managed[ 'message' ]);
- }
-
- $order_model = new Order();
- $filed = 'o.order_id,o.site_id,o.order_type,o.out_trade_no,o.pay_type,o.mobile,m.weapp_openid';
- $join = [
- [ 'member m', 'o.member_id=m.member_id', 'left' ]
- ];
- $order_info = model('order')->getInfo([ [ 'order_id', '=', $data[ 'order_id' ] ] ], $filed, 'o', $join);
- if (empty($order_info)) {
- return $this->error('', '订单不存在');
- }
-
- if ($order_info[ 'pay_type' ] != 'wechatpay') {
- return $this->success('', '订单未使用微信支付');
- }
-
- $shop_model = new ShopModel();
- $shop_info = $shop_model->getShopInfo([ [ 'site_id', '=', $this->site_id ] ], '')[ 'data' ];
-
- // 设置消息跳转路径设置接口
- $this->orderShippingSetMsgJumpPath($data[ 'order_id' ], $order_info[ 'order_type' ]);
-
- $pay_config = ( new WechatPayModel() )->getPayConfig($order_info[ 'site_id' ])[ 'data' ][ 'value' ];
-
- $logistics_type = 1; // 物流模式,发货方式枚举值:1、实体物流配送采用快递公司进行实体物流配送形式 2、同城配送 3、虚拟商品,虚拟商品,例如话费充值,点卡等,无实体配送形式 4、用户自提
-
- // 订单类型 1:物流订单,2:门店自提订单,3:外卖订单,4:虚拟订单
- if ($order_info[ 'order_type' ] == 1) {
- $logistics_type = 1; // 1、实体物流配送采用快递公司进行实体物流配送形式
- } else if ($order_info[ 'order_type' ] == 2) {
- $logistics_type = 4; // 用户自提
- } else if ($order_info[ 'order_type' ] == 3) {
- $logistics_type = 2; // 同城配送
- } else if ($order_info[ 'order_type' ] == 4) {
- $logistics_type = 3; // 虚拟商品,例如话费充值,点卡等,无实体配送形式
- }
-
- $order_goods_field = 'order_goods_id,sku_name,num,delivery_no';
-
- $order_goods_list = $order_model->getOrderGoodsList([
- [ 'order_id', '=', $order_info[ 'order_id' ] ]
- ], $order_goods_field, 'order_goods_id asc')[ 'data' ];
-
- $delivery_mode = 1; // 发货模式,发货模式枚举值:1、UNIFIED_DELIVERY(统一发货)2、SPLIT_DELIVERY(分拆发货) 示例值: UNIFIED_DELIVERY
- if ($logistics_type == 1) {
- $delivery_mode = count($order_goods_list) == 1 ? 1 : 2;
- }
-
- $shipping_list = [];
- $first_shipping_info = [];
-
- // 获取物流公司
- $delivery_list = [];
- if ($logistics_type == 1) {
- $delivery_list = $this->orderShippingGetDeliveryList()[ 'data' ];
- }
-
- foreach ($order_goods_list as $k => $v) {
-
- // 一笔支付单最多分拆成 10 个包裹
- if ($k == 10) {
- break;
- }
-
- $express_company = ''; // 物流公司编码,快递公司ID,参见「查询物流公司编码列表」,物流快递发货时必填, 示例值: DHL 字符字节限制: [1, 128]
-
- if ($logistics_type == 1) {
- $info = model('express_delivery_package')->getInfo([
- [ 'order_id', '=', $order_info[ 'order_id' ] ],
- [ 'order_goods_id_array', 'like', '%' . $v[ 'order_goods_id' ] . '%' ]
- ], 'express_company_id,express_company_name');
-
- if (!empty($info) && $info[ 'express_company_id' ] && !empty($delivery_list)) {
- $index = array_search($info[ 'express_company_name' ], array_column($delivery_list, 'delivery_name'));
- if ($index !== false && isset($delivery_list[ $index ])) {
- $express_company = $delivery_list[ $index ][ 'delivery_id' ];
- }
- if (empty($express_company)) {
- return $this->error([], '物流公司不支持,请更换其他物流公司');
- }
- } else {
- $logistics_type = 2; // 无需物流的情况,无实体配送形式
- $delivery_mode = 1; // 统一发货
- }
-
- }
-
- $item = [
- 'tracking_no' => $v[ 'delivery_no' ], // 物流单号,物流快递发货时必填,示例值: 323244567777 字符字节限制: [1, 128]
- 'express_company' => $express_company, // 物流公司编码,快递公司ID,参见「查询物流公司编码列表」,物流快递发货时必填, 示例值: DHL 字符字节限制: [1, 128]
- 'item_desc' => str_sub($v[ 'sku_name' ], 90) . '*' . $v[ 'num' ], // 商品信息,例如:微信红包抱枕*1个,限120个字以内
- 'contact' => [
- 'consignor_contact' => '',
- 'receiver_contact' => ''
- ]
- ];
-
- // 寄件人联系方式,寄件人联系方式,采用掩码传输,最后4位数字不能打掩码 示例值: `189****1234, 021-****1234, ****1234, 0**2-***1234, 0**2-******23-10, ****123-8008` 值限制: 0 ≤ value ≤ 1024
- if (!empty($shop_info[ 'mobile' ])) {
- $item[ 'contact' ][ 'consignor_contact' ] = substr($shop_info[ 'mobile' ], 0, 3) . '****' . substr($shop_info[ 'mobile' ], 7);
- }
-
- // 收件人联系方式,收件人联系方式为,采用掩码传输,最后4位数字不能打掩码 示例值: `189****1234, 021-****1234, ****1234, 0**2-***1234, 0**2-******23-10, ****123-8008` 值限制: 0 ≤ value ≤ 1024
- if (!empty($order_info[ 'mobile' ])) {
- $item[ 'contact' ][ 'receiver_contact' ] = substr($order_info[ 'mobile' ], 0, 3) . '****' . substr($order_info[ 'mobile' ], 7);
- }
-
- $shipping_list[] = $item;
- if ($k == 0) {
- $first_shipping_info = $item;
- $first_shipping_inf[ 'sku_name' ] = $v[ 'sku_name' ] . '*' . $v[ 'num' ];
- }
- }
-
- // 统一发货,只能有一个物流信息,拼装商品信息
- if ($delivery_mode == 1) {
- if (count($shipping_list) > 1) {
- foreach ($shipping_list as $k => $v) {
- if ($k > 0) {
- $first_shipping_info[ 'item_desc' ] .= ',' . $v[ 'item_desc' ];
- }
- }
- }
- $first_shipping_info[ 'item_desc' ] = str_sub($first_shipping_info[ 'item_desc' ], 90);
- }
-
- // 分拆发货模式时必填,用于标识分拆发货模式下是否已全部发货完成,只有全部发货完成的情况下才会向用户推送发货完成通知。示例值: true/false
- $is_all_delivered = false;
- if ($delivery_mode == 2) {
- $is_all_delivered = true;
- }
-
- $params = [
- 'order_key' => [
- 'order_number_type' => 1, // 订单单号类型,用于确认需要上传详情的订单。枚举值1,使用下单商户号和商户侧单号;枚举值2,使用微信支付单号。
- 'mchid' => $pay_config[ 'mch_id' ], // 支付下单商户的商户号,由微信支付生成并下发。
- 'out_trade_no' => $order_info[ 'out_trade_no' ] // 商户系统内部订单号,只能是数字、大小写字母`_-*`且在同一个商户号下唯一
- ],
- 'logistics_type' => $logistics_type, // 物流模式,发货方式枚举值:1、实体物流配送采用快递公司进行实体物流配送形式 2、同城配送 3、虚拟商品,虚拟商品,例如话费充值,点卡等,无实体配送形式 4、用户自提
- 'delivery_mode' => $delivery_mode, // 发货模式,发货模式枚举值:1、UNIFIED_DELIVERY(统一发货)2、SPLIT_DELIVERY(分拆发货) 示例值: UNIFIED_DELIVERY
- // 同城配送没有物流信息,只能传一个订单
- 'shipping_list' => $delivery_mode == 1 ? [ $first_shipping_info ] : $shipping_list, // 物流信息列表,发货物流单列表,支持统一发货(单个物流单)和分拆发货(多个物流单)两种模式,多重性: [1, 10]
- 'upload_time' => date("c", time()), // 上传时间,用于标识请求的先后顺序 示例值: `2022-12-15T13:29:35.120+08:00`
- 'payer' => [
- 'openid' => $order_info[ 'weapp_openid' ] // 用户标识,用户在小程序appid下的唯一标识。 下单前需获取到用户的Openid 示例值: oUpF8uMuAJO_M2pxb1Q9zNjWeS6o 字符字节限制: [1, 128]
- ],
- 'is_all_delivered' => $is_all_delivered
- ];
-
- Log::write('发货信息录入接口(参数):' . json_encode($params));
-
- $result = $this->app->order_shipping->uploadShippingInfo($params);
-
- Log::write('发货信息录入接口(结果):' . json_encode($result));
- if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] != 0) {
- // 排除 支付单不存在,错误码:10060001
- if ($result[ 'errcode' ] != 10060001) {
- return $this->error([], $result[ "errmsg" ]);
- }
- }
-
- return $this->success($result);
- } catch (\Exception $e) {
- return $this->error([], $e->getMessage() . ",File:" . $e->getFile() . ",line:" . $e->getLine());
- }
- }
-
- /**
- * 发货信息录入接口,自备数据
- * @param array $data
- * @return array
- * @throws \GuzzleHttp\Exception\GuzzleException
- */
- public function orderShippingUploadShippingInfoByData($data = [])
- {
-
- try {
- // 检测微信小程序是否已开通发货信息管理服务
- $is_trade_managed = $this->orderShippingIsTradeManaged();
- if (!$is_trade_managed[ 'data' ]) {
- return $this->success('', $is_trade_managed[ 'message' ]);
- }
- $pay_config = ( new WechatPayModel() )->getPayConfig($data[ 'site_id' ])[ 'data' ][ 'value' ];
-
- $params = [
- 'order_key' => [
- 'order_number_type' => 1, // 订单单号类型,用于确认需要上传详情的订单。枚举值1,使用下单商户号和商户侧单号;枚举值2,使用微信支付单号。
- 'mchid' => $pay_config[ 'mch_id' ], // 支付下单商户的商户号,由微信支付生成并下发。
- 'out_trade_no' => $data[ 'out_trade_no' ] // 商户系统内部订单号,只能是数字、大小写字母`_-*`且在同一个商户号下唯一
- ],
- 'logistics_type' => $data[ 'logistics_type' ], // 物流模式,发货方式枚举值:1、实体物流配送采用快递公司进行实体物流配送形式 2、同城配送 3、虚拟商品,虚拟商品,例如话费充值,点卡等,无实体配送形式 4、用户自提
- 'delivery_mode' => $data[ 'delivery_mode' ], // 发货模式,发货模式枚举值:1、UNIFIED_DELIVERY(统一发货)2、SPLIT_DELIVERY(分拆发货) 示例值: UNIFIED_DELIVERY
- // 同城配送没有物流信息,只能传一个订单
- 'shipping_list' => $data[ 'shipping_list' ], // 物流信息列表,发货物流单列表,支持统一发货(单个物流单)和分拆发货(多个物流单)两种模式,多重性: [1, 10]
- 'upload_time' => date("c", time()), // 上传时间,用于标识请求的先后顺序 示例值: `2022-12-15T13:29:35.120+08:00`
- 'payer' => [
- 'openid' => $data[ 'weapp_openid' ] // 用户标识,用户在小程序appid下的唯一标识。 下单前需获取到用户的Openid 示例值: oUpF8uMuAJO_M2pxb1Q9zNjWeS6o 字符字节限制: [1, 128]
- ],
- 'is_all_delivered' => $data[ 'is_all_delivered' ] // 分拆发货模式时必填,用于标识分拆发货模式下是否已全部发货完成,只有全部发货完成的情况下才会向用户推送发货完成通知。示例值: true/false
- ];
-
- Log::write('发货信息录入接口,自备数据(参数):' . json_encode($params));
-
- $result = $this->app->order_shipping->uploadShippingInfo($params);
-
- Log::write('发货信息录入接口,自备数据(结果):' . json_encode($result));
- if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] != 0) {
- return $this->error([], $result[ "errmsg" ]);
- }
-
- return $this->success($result);
- } catch (\Exception $e) {
- return $this->error([], $e->getMessage() . ",File:" . $e->getFile() . ",line:" . $e->getLine());
- }
- }
-
- /**
- * todo【暂时没有用到】发货信息合单录入接口
- * @param array $data
- * @return array
- * @throws \GuzzleHttp\Exception\GuzzleException
- */
- public function orderShippingUploadCombinedShippingInfo($data = [])
- {
- try {
- $params = [
- 'order_key' => [
- 'order_number_type' => $data[ 'order_number_type' ] ?? 1, // 订单单号类型,用于确认需要上传详情的订单。枚举值1,使用下单商户号和商户侧单号;枚举值2,使用微信支付单号。
- ],
- 'logistics_type' => $data[ 'logistics_type' ], // 物流模式,发货方式枚举值:1、实体物流配送采用快递公司进行实体物流配送形式 2、同城配送 3、虚拟商品,虚拟商品,例如话费充值,点卡等,无实体配送形式 4、用户自提
- 'delivery_mode' => $data[ 'delivery_mode' ], // 发货模式,发货模式枚举值:1、UNIFIED_DELIVERY(统一发货)2、SPLIT_DELIVERY(分拆发货) 示例值: UNIFIED_DELIVERY
- 'sub_orders' => $data[ 'sub_orders' ], // 子单物流详情
- 'upload_time' => $data[ 'upload_time' ], // 上传时间,用于标识请求的先后顺序 示例值: `2022-12-15T13:29:35.120+08:00`
- 'payer' => [
- 'openid' => $data[ 'openid' ] // 用户标识,用户在小程序appid下的唯一标识。 下单前需获取到用户的Openid 示例值: oUpF8uMuAJO_M2pxb1Q9zNjWeS6o 字符字节限制: [1, 128]
- ]
- ];
-
- // 原支付交易对应的微信订单号
- if (!empty($data[ 'transaction_id' ])) {
- $params[ 'order_key' ][ 'transaction_id' ] = $data[ 'transaction_id' ];
- }
-
- // 支付下单商户的商户号,由微信支付生成并下发。
- if (!empty($data[ 'mchid' ])) {
- $params[ 'order_key' ][ 'mchid' ] = $data[ 'mchid' ];
- }
-
- // 商户系统内部订单号,只能是数字、大小写字母`_-*`且在同一个商户号下唯一
- if (!empty($data[ 'out_trade_no' ])) {
- $params[ 'order_key' ][ 'out_trade_no' ] = $data[ 'out_trade_no' ];
- }
-
- $result = $this->app->order_shipping->uploadCombinedShippingInfo($params);
- if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] != 0) {
- return $this->error([], $result[ "errmsg" ]);
- }
-
- return $this->success($result);
- } catch (\Exception $e) {
- return $this->error([], $e->getMessage());
- }
- }
-
- /**
- * 确认收货提醒接口
- * @param array $data
- * @return array
- * @throws \GuzzleHttp\Exception\GuzzleException
- */
- public function orderShippingNotifyConfirmReceive($data = [])
- {
-
- try {
- // 检测微信小程序是否已开通发货信息管理服务
- $is_trade_managed = $this->orderShippingIsTradeManaged();
- if (!$is_trade_managed[ 'data' ]) {
- return $this->success('', $is_trade_managed[ 'message' ]);
- }
-
- $filed = 'o.order_id,o.site_id,o.order_type,o.out_trade_no,o.pay_type,o.mobile,m.weapp_openid';
- $join = [
- [ 'member m', 'o.member_id=m.member_id', 'left' ]
- ];
- $order_info = model('order')->getInfo([ [ 'order_id', '=', $data[ 'order_id' ] ] ], $filed, 'o', $join);
- if (empty($order_info)) {
- return $this->error('', '订单不存在');
- }
-
- if ($order_info[ 'pay_type' ] != 'wechatpay') {
- return $this->success('', '订单未使用微信支付');
- }
-
- if ($order_info[ 'order_type' ] != 1) {
- return $this->success('', '只有物流订单才能进行提醒');
- }
-
- // 设置消息跳转路径设置接口
- $this->orderShippingSetMsgJumpPath($data[ 'order_id' ], $order_info[ 'order_type' ]);
-
- $pay_config = ( new WechatPayModel() )->getPayConfig($order_info[ 'site_id' ])[ 'data' ][ 'value' ];
-
- $params = [
- 'merchant_id' => $pay_config[ 'mch_id' ], // 支付下单商户的商户号,由微信支付生成并下发
- 'merchant_trade_no' => $order_info[ 'out_trade_no' ], // 商户系统内部订单号,只能是数字、大小写字母_-*且在同一个商户号下唯一
- 'received_time' => time() // 快递签收时间,时间戳形式
- ];
-
- Log::write('确认收货提醒接口(参数):' . json_encode($params));
-
- $result = $this->app->order_shipping->notifyConfirmReceive($params);
-
- Log::write('确认收货提醒接口(结果):' . json_encode($result));
- if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] != 0) {
- Log::write('微信小程序确认收货提醒接口报错:' . json_encode($result));
- return $this->success([], $result[ "errmsg" ]);
- }
-
- return $this->success($result);
- } catch (\Exception $e) {
- return $this->error([], $e->getMessage());
- }
- }
-
- /**
- * 获取物流公司,运力id列表get_delivery_list
- * @param array $data
- * @return array
- * @throws \GuzzleHttp\Exception\GuzzleException
- */
- public function orderShippingGetDeliveryList()
- {
- $cache = Cache::get('orderShippingGetDeliveryList');
- if ($cache) return $cache;
-
- try {
- $result = $this->app->order_shipping->getDeliveryList();
- if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] != 0) {
- return $this->error([], $result[ "errmsg" ]);
- }
-
- $data = $this->success($result[ 'delivery_list' ]);
- Cache::set('orderShippingGetDeliveryList', $data);
- return $data;
- } catch (\Exception $e) {
- return $this->error([], $e->getMessage());
- }
- }
-
-}
+ "小程序",
+ );
+
+ //小程序认证类型
+ public $verify_type = array (
+ -1 => "未认证",
+ 0 => "微信认证",
+ );
+
+ //business_info 说明
+ public $business_type = array (
+ 'open_store' => "是否开通微信门店功能",
+ 'open_scan' => "是否开通微信扫商品功能",
+ 'open_pay' => "是否开通微信支付功能",
+ 'open_card' => "是否开通微信卡券功能",
+ 'open_shake' => "是否开通微信摇一摇功能",
+ );
+
+ // 站点ID
+ private $site_id;
+
+ public function __construct($site_id = 0)
+ {
+ $this->site_id = $site_id;
+ //微信小程序配置
+ $weapp_config_model = new WeappConfigModel();
+ $weapp_config = $weapp_config_model->getWeappConfig($site_id)[ "data" ][ "value" ];
+
+ if (isset($weapp_config[ 'is_authopen' ]) && addon_is_exit('wxoplatform')) {
+ $plateform_config_model = new WxOplatformConfigModel();
+ $plateform_config = $plateform_config_model->getOplatformConfig()[ "data" ][ "value" ];
+
+ $config = [
+ 'app_id' => $plateform_config[ "appid" ] ?? '',
+ 'secret' => $plateform_config[ "secret" ] ?? '',
+ 'token' => $plateform_config[ "token" ] ?? '',
+ 'aes_key' => $plateform_config[ "aes_key" ] ?? '',
+ 'log' => [
+ 'level' => 'debug',
+ 'permission' => 0777,
+ 'file' => 'runtime/log/wechat/oplatform.logs',
+ ],
+ ];
+ $open_platform = Factory::openPlatform($config);
+ $this->app = $open_platform->miniProgram($weapp_config[ 'authorizer_appid' ], $weapp_config[ 'authorizer_refresh_token' ]);
+ } else {
+ $config = [
+ 'app_id' => $weapp_config[ "appid" ] ?? '',
+ 'secret' => $weapp_config[ "appsecret" ] ?? '',
+ 'response_type' => 'array',
+ 'log' => [
+ 'level' => 'debug',
+ 'permission' => 0777,
+ 'file' => 'runtime/log/wechat/easywechat.logs',
+ ],
+ ];
+ $this->app = Factory::miniProgram($config);
+ }
+ }
+
+ /**
+ * TODO
+ * 根据 jsCode 获取用户 session 信息
+ * @param $param
+ * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
+ */
+ public function authCodeToOpenid($param)
+ {
+ try {
+ $result = $this->app->auth->session($param[ 'code' ]);
+ if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] != 0) {
+ return $this->handleError($result[ 'errcode' ], $result[ 'errmsg' ]);
+ } else {
+ Cache::set('weapp_' . $result[ 'openid' ], $result);
+ unset($result[ 'session_key' ]);
+ return $this->success($result);
+ }
+ } catch (\Exception $e) {
+ if (property_exists($e, 'formattedResponse')) {
+ return $this->handleError($e->formattedResponse[ 'errcode' ], $e->formattedResponse[ 'errmsg' ]);
+ }
+ return $this->error('', $e->getMessage());
+ }
+ }
+
+ /**
+ * 生成二维码
+ * @param unknown $param
+ */
+ public function createQrcode($param)
+ {
+ try {
+ $checkpath_result = $this->checkPath($param[ 'qrcode_path' ]);
+ if ($checkpath_result[ "code" ] != 0) return $checkpath_result;
+
+ // scene:场景值最大32个可见字符,只支持数字,大小写英文以及部分特殊字符:!#$&'()*+,/:;=?@-._~
+ $scene = '';
+ if (!empty($param[ 'data' ])) {
+ foreach ($param[ 'data' ] as $key => $value) {
+ //防止参数过长,source_member用m代替
+ if ($key == 'source_member') {
+ $key = 'm';
+ }
+ if ($scene == '') $scene .= $key . '-' . $value;
+ else $scene .= '&' . $key . '-' . $value;
+ }
+ }
+ $response = $this->app->app_code->getUnlimit($scene, [
+ 'page' => substr($param[ 'page' ], 1),
+ 'width' => $param['width'] ?? 120
+ ]);
+ if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) {
+ $filename = $param[ 'qrcode_path' ] . '/';
+ $filename .= $response->saveAs($param[ 'qrcode_path' ], $param[ 'qrcode_name' ] . '_' . $param[ 'app_type' ] . '.png');
+ return $this->success([ 'type' => 'weapp', 'path' => $filename ]);
+ } else {
+ return $this->handleError($response[ 'errcode' ], $response[ 'errmsg' ]);
+ }
+ } catch (\Exception $e) {
+ if (property_exists($e, 'formattedResponse')) {
+ return $this->handleError($e->formattedResponse[ 'errcode' ], $e->formattedResponse[ 'errmsg' ]);
+ }
+ return $this->error('', $e->getMessage());
+ }
+ }
+
+ /**
+ * 校验目录是否可写
+ * @param unknown $path
+ * @return multitype:number unknown |multitype:unknown
+ */
+ private function checkPath($path)
+ {
+ if (is_dir($path) || mkdir($path, intval('0755', 8), true)) {
+ return $this->success();
+ }
+ return $this->error('', "directory {$path} creation failed");
+ }
+ /************************************************************* 数据统计与分析 start **************************************************************/
+
+ /**
+ * 访问日趋势
+ * @param $from 格式 20170313
+ * @param $to 格式 20170313
+ */
+ public function dailyVisitTrend($from, $to)
+ {
+ try {
+ $result = $this->app->data_cube->dailyVisitTrend($from, $to);
+ if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] != 0) {
+ return $this->error([], $result[ "errmsg" ]);
+ }
+ return $this->success($result[ "list" ]);
+ } catch (\Exception $e) {
+ return $this->error([], $e->getMessage());
+ }
+
+ }
+
+ /**
+ * 访问周趋势
+ * @param $from
+ * @param $to
+ * @return array
+ */
+ public function weeklyVisitTrend($from, $to)
+ {
+ try {
+ $result = $this->app->data_cube->weeklyVisitTrend($from, $to);
+ if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] != 0) {
+ return $this->error([], $result[ "errmsg" ]);
+ }
+ return $this->success($result[ "list" ]);
+ } catch (\Exception $e) {
+ return $this->error([], $e->getMessage());
+ }
+ }
+
+ /**
+ * 访问月趋势
+ * @param $from
+ * @param $to
+ * @return array
+ */
+ public function monthlyVisitTrend($from, $to)
+ {
+ try {
+ $result = $this->app->data_cube->monthlyVisitTrend($from, $to);
+ if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] != 0) {
+ return $this->error([], $result[ "errmsg" ]);
+ }
+ return $this->success($result[ "list" ]);
+ } catch (\Exception $e) {
+ return $this->error([], $e->getMessage());
+ }
+ }
+
+ /**
+ * 访问分布
+ * @param $from
+ * @param $to
+ * @return array
+ */
+ public function visitDistribution($from, $to)
+ {
+ try {
+ $result = $this->app->data_cube->visitDistribution($from, $to);
+ if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] != 0) {
+ return $this->error($result, $result[ "errmsg" ]);
+ }
+ return $this->success($result[ "list" ]);
+ } catch (\Exception $e) {
+ return $this->error([], $e->getMessage());
+ }
+ }
+
+ /**
+ * 访问页面
+ * @param $from
+ * @param $to
+ * @return array
+ */
+ public function visitPage($from, $to)
+ {
+ try {
+ $result = $this->app->data_cube->visitPage($from, $to);
+ if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] != 0) {
+ return $this->error([], $result[ "errmsg" ]);
+ }
+ return $this->success($result[ "list" ]);
+ } catch (\Exception $e) {
+ return $this->error([], $e->getMessage());
+ }
+ }
+ /************************************************************* 数据统计与分析 end **************************************************************/
+
+ /**
+ * 下载小程序代码包
+ * @param $site_id
+ */
+ public function download($site_id)
+ {
+ $source_file_path = $this->createTempPackage($site_id, 'public/weapp');
+ $file_arr = getFileMap($source_file_path);
+
+ if (!empty($file_arr)) {
+ $zipname = 'upload/weapp_' . $site_id . '_' . date('Ymd') . '.zip';
+
+ $zip = new \ZipArchive();
+ $res = $zip->open($zipname, \ZipArchive::CREATE);
+ if ($res === TRUE) {
+ foreach ($file_arr as $file_path => $file_name) {
+ if (is_dir($file_path)) {
+ $file_path = str_replace($source_file_path . '/', '', $file_path);
+ $zip->addEmptyDir($file_path);
+ } else {
+ $zip_path = str_replace($source_file_path . '/', '', $file_path);
+ $zip->addFile($file_path, $zip_path);
+ }
+ }
+ $zip->close();
+
+ header("Content-Type: application/zip");
+ header("Content-Transfer-Encoding: Binary");
+ header("Content-Length: " . filesize($zipname));
+ header("Content-Disposition: attachment; filename=\"" . basename($zipname) . "\"");
+ readfile($zipname);
+ @unlink($zipname);
+ deleteDir($source_file_path);
+ }
+ }
+ }
+
+ /**
+ * 创建临时包
+ * @param $site_id
+ * @param $package_path
+ * @param string $to_path
+ * @return string
+ */
+ private function createTempPackage($site_id, $package_path, $to_path = '')
+ {
+ if (is_dir($package_path)) {
+ $package = scandir($package_path);
+
+ if (empty($to_path)) {
+ $to_path = 'upload/temp/' . $site_id . '/';
+ dir_mkdir($to_path);
+ }
+
+ foreach ($package as $path) {
+ $temp_path = $package_path . '/' . $path;
+ if (is_dir($temp_path)) {
+ if ($path == '.' || $path == '..') {//判断是否为系统隐藏的文件.和.. 如果是则跳过否则就继续往下走,防止无限循环再这里。
+ continue;
+ }
+ dir_mkdir($to_path . $path);
+ $this->createTempPackage($site_id, $temp_path, $to_path . $path . '/');
+ } else {
+ if (file_exists($temp_path)) {
+ copy($temp_path, $to_path . $path);
+ if (stristr($temp_path, 'common/vendor.js')) {
+ $content = file_get_contents($to_path . $path);
+ $content = $this->paramReplace($site_id, $content);
+ file_put_contents($to_path . $path, $content);
+ }
+ }
+ }
+ }
+ return $to_path;
+ }
+ }
+
+ /**
+ * 参数替换
+ * @param $site_id
+ * @param $string
+ * @return null|string|string[]
+ */
+ private function paramReplace($site_id, $string)
+ {
+ $api_model = new Api();
+ $api_config = $api_model->getApiConfig()[ 'data' ];
+
+ $web_config_model = new WebConfig();
+ $web_config = $web_config_model->getMapConfig()[ 'data' ][ 'value' ];
+
+ $socket_url = ( strstr(ROOT_URL, 'https://') === false ? str_replace('http', 'ws', ROOT_URL) : str_replace('https', 'wss', ROOT_URL) ) . '/wss';
+
+ $patterns = [
+ '/\{\{\$baseUrl\}\}/',
+ '/\{\{\$imgDomain\}\}/',
+ '/\{\{\$h5Domain\}\}/',
+ '/\{\{\$mpKey\}\}/',
+ '/\{\{\$apiSecurity\}\}/',
+ '/\{\{\$publicKey\}\}/',
+ '/\{\{\$webSocket\}\}/'
+ ];
+ $replacements = [
+ ROOT_URL,
+ ROOT_URL,
+ ROOT_URL . '/h5',
+ $web_config[ 'tencent_map_key' ] ?? '',
+ $api_config[ 'is_use' ] ?? 0,
+ $api_config[ 'value' ][ 'public_key' ] ?? '',
+ $socket_url
+ ];
+ $string = preg_replace($patterns, $replacements, $string);
+ return $string;
+ }
+
+ /**
+ * 消息解密
+ * @param array $param
+ */
+ public function decryptData($param = [])
+ {
+ try {
+ $cache = Cache::get('weapp_' . $param[ 'weapp_openid' ]);
+ $session_key = $cache[ 'session_key' ] ?? '';
+ $result = $this->app->encryptor->decryptData($session_key, $param[ 'iv' ], $param[ 'encryptedData' ]);
+ if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] != 0) {
+ return $this->handleError($result[ 'errcode' ], $result[ 'errmsg' ]);
+ }
+ return $this->success($result);
+ } catch (\Exception $e) {
+ if (property_exists($e, 'formattedResponse')) {
+ return $this->handleError($e->formattedResponse[ 'errcode' ], $e->formattedResponse[ 'errmsg' ]);
+ }
+ return $this->error([], $e->getMessage());
+ }
+ }
+
+ /**
+ * 获取用户手机号
+ * @param $code
+ * @return array
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function getUserPhoneNumber($code)
+ {
+ try {
+ $result = $this->app->auth->phoneNumber($code);
+ if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] != 0) {
+ return $this->handleError($result[ 'errcode' ], $result[ 'errmsg' ]);
+ }
+ return $this->success($result[ 'phone_info' ]);
+ } catch (\Exception $e) {
+ if (property_exists($e, 'formattedResponse')) {
+ return $this->handleError($e->formattedResponse[ 'errcode' ], $e->formattedResponse[ 'errmsg' ]);
+ }
+ return $this->error([], $e->getMessage());
+ }
+ }
+
+ /**
+ * 获取订阅消息template_id
+ * @param array $param
+ */
+ public function getTemplateId(array $param)
+ {
+ try {
+ $result = $this->app->subscribe_message->addTemplate($param[ 'tid' ], $param[ 'kidList' ], $param[ 'sceneDesc' ]);
+ return $result;
+ } catch (\Exception $e) {
+ return [ 'errcode' => -1, 'errmsg' => $e->getMessage() ];
+ }
+ }
+
+ /**
+ * 发送订阅消息
+ * @param array $param
+ * @return array
+ */
+ public function sendTemplateMessage(array $param)
+ {
+ $result = $this->app->subscribe_message->send([
+ 'template_id' => $param[ 'template_id' ],// 模板id
+ 'touser' => $param[ 'openid' ], // openid
+ 'page' => $param[ 'page' ], // 点击模板卡片后的跳转页面 支持带参数
+ 'data' => $param[ 'data' ] // 模板变量
+ ]);
+
+ if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] != 0) {
+ return $this->error($result, $result[ "errmsg" ]);
+ }
+ return $this->success($result);
+ }
+
+ /**
+ * 消息推送
+ */
+ public function relateWeixin()
+ {
+ $server = $this->app->server;
+ $message = $server->getMessage();
+ Log::write('微信小程序消息推送:' . json_encode($message));
+ // file_put_contents(__DIR__ . '/debug.txt', var_export($message,true));
+ if (isset($message[ 'MsgType' ])) {
+ switch ( $message[ 'MsgType' ] ) {
+ case 'event':
+ $this->app->server->push(function($res) {
+ // file_put_contents(__DIR__ . '/debug1.txt', var_export($res,true));
+ // 商品审核结果通知
+ if ($res[ 'Event' ] == 'open_product_spu_audit' && addon_is_exit('shopcomponent', $this->site_id)) {
+ model('shopcompoent_goods')->update([
+ 'edit_status' => $res[ 'OpenProductSpuAudit' ][ 'status' ],
+ 'reject_reason' => !empty($res[ 'OpenProductSpuAudit' ][ 'reject_reason' ]) ? : '',
+ 'audit_time' => time()
+ ], [
+ [ 'out_product_id', '=', $res[ 'OpenProductSpuAudit' ][ 'out_product_id' ] ]
+ ]);
+ }
+ // 类目审核结果通知
+ if ($res[ 'Event' ] == 'open_product_category_audit' && addon_is_exit('shopcomponent', $this->site_id)) {
+ model('shopcompoent_category_audit')->update([
+ 'status' => $res[ 'QualificationAuditResult' ][ 'status' ],
+ 'reject_reason' => !empty($res[ 'QualificationAuditResult' ][ 'reject_reason' ]) ? : '',
+ 'audit_time' => time()
+ ], [
+ [ 'audit_id', '=', $res[ 'QualificationAuditResult' ][ 'audit_id' ] ]
+ ]);
+ }
+
+ // 视频号支付订单回调
+ if ($res[ 'Event' ] == 'open_product_order_pay' && addon_is_exit('shopcomponent', $this->site_id)) {
+ event("shopcomponentNotify", $res);
+ }
+
+ // todo trade_manage_remind_access_api 提醒接入发货信息管理服务API
+ if ($res[ 'Event' ] == 'trade_manage_remind_access_api' && addon_is_exit('weapp', $this->site_id)) {
+ Log::write('提醒接入发货信息管理服务API(trade_manage_remind_access_api):' . json_encode($res));
+ }
+
+ // todo trade_manage_remind_shipping 提醒需要上传发货信息
+ if ($res[ 'Event' ] == 'trade_manage_remind_shipping' && addon_is_exit('weapp', $this->site_id)) {
+ Log::write('提醒需要上传发货信息(trade_manage_remind_shipping):' . json_encode($res));
+ }
+
+ // todo trade_manage_order_settlement 订单将要结算或已经结算
+ if ($res[ 'Event' ] == 'trade_manage_order_settlement' && addon_is_exit('weapp', $this->site_id)) {
+ Log::write('订单将要结算或已经结算(trade_manage_order_settlement):' . json_encode($res));
+ }
+ });
+ break;
+ }
+ }
+ $response = $this->app->server->serve();
+ return $response->send();
+ }
+
+ /**
+ * 检查场景值是否在支付校验范围内
+ * @param $scene
+ * @return array
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function sceneCheck($scene)
+ {
+ try {
+ $result = $this->app->mini_store->checkScene($scene);
+ if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] == 0) {
+ return $this->success($result[ 'is_matched' ]);
+ } else {
+ return $this->error('', $result[ 'errmsg' ]);
+ }
+ } catch (\Exception $e) {
+ return $this->error([], $e->getMessage());
+ }
+ }
+
+ public function createOrder($order_info)
+ {
+ try {
+ $result = $this->app->mini_store->addOrder($order_info);
+ if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] == 0) {
+ return $this->success($result[ 'is_matched' ]);
+ } else {
+ return $this->error('', $result[ 'errmsg' ]);
+ }
+ } catch (\Exception $e) {
+ return $this->error([], $e->getMessage());
+ }
+ }
+
+ /**
+ * 处理错误信息
+ * @param $errcode
+ * @param string $message
+ * @return array
+ */
+ public function handleError($errcode, $message = '')
+ {
+ $error = require 'addon/weapp/config/weapp_error.php';
+ return $this->error([], $error[ $errcode ] ?? $message);
+ }
+
+ /**
+ * 查询小程序是否已开通发货信息管理服务
+ * @return array
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function orderShippingIsTradeManaged()
+ {
+ try {
+ $result = $this->app->order_shipping->isTradeManaged();
+ if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] != 0) {
+ return $this->error(false, $result[ "errmsg" ]);
+ }
+ return $this->success($result[ 'is_trade_managed' ]);
+ } catch (\Exception $e) {
+ return $this->error(false, $e->getMessage());
+ }
+ }
+
+ /**
+ * 查询订单列表
+ * @param array $data
+ * @return array
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function orderShippingGetOrderList($data = [])
+ {
+ try {
+ $params = [
+ 'pay_time_range' => [
+ 'begin_time' => $data[ 'begin_time' ] ?? 0, // 起始时间,时间戳形式,不填则视为从0开始。
+ 'end_time' => $data[ 'end_time' ] ?? time() // 结束时间(含),时间戳形式,不填则视为32位无符号整型的最大值。
+ ],
+ 'page_size' => $data[ 'page_size' ] ?? 100 // 翻页时使用,返回列表的长度,默认为100。
+ ];
+
+ // 订单状态枚举:(1) 待发货;(2) 已发货;(3) 确认收货;(4) 交易完成;(5) 已退款。
+ if (!empty($data[ 'order_state' ])) {
+ $params[ 'order_state' ] = $data[ 'order_state' ];
+ }
+
+ // 翻页时使用,获取第一页时不用传入,如果查询结果中 has_more 字段为 true,则传入该次查询结果中返回的 last_index 字段可获取下一页。
+ if (!empty($data[ 'last_index' ])) {
+ $params[ 'last_index' ] = $data[ 'last_index' ];
+ }
+
+ $result = $this->app->order_shipping->getOrderList($params);
+ if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] != 0) {
+ return $this->error([], $result[ "errmsg" ]);
+ }
+
+ return $this->success($result);
+ } catch (\Exception $e) {
+ return $this->error([], $e->getMessage());
+ }
+ }
+
+ /**
+ * 查询订单发货状态
+ * @param array $data
+ * @return array
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function orderShippingGetOrder($data = [])
+ {
+ try {
+ $params = [];
+
+ // 原支付交易对应的微信订单号
+ if (!empty($data[ 'transaction_id' ])) {
+ $params[ 'transaction_id' ] = $data[ 'transaction_id' ];
+ }
+
+ // 支付下单商户的商户号,由微信支付生成并下发
+ if (!empty($data[ 'merchant_id' ])) {
+ $params[ 'merchant_id' ] = $data[ 'merchant_id' ];
+ }
+
+ // 商户系统内部订单号,只能是数字、大小写字母`_-*`且在同一个商户号下唯一
+ if (!empty($data[ 'merchant_trade_no' ])) {
+ $params[ 'merchant_trade_no' ] = $data[ 'merchant_trade_no' ];
+ }
+
+ // 二级商户号
+ if (!empty($data[ 'sub_merchant_id' ])) {
+ $params[ 'sub_merchant_id' ] = $data[ 'sub_merchant_id' ];
+ }
+
+ $result = $this->app->order_shipping->getOrder($params);
+ if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] != 0) {
+ return $this->error([], $result[ "errmsg" ]);
+ }
+
+ return $this->success($result[ 'order' ]);
+ } catch (\Exception $e) {
+ return $this->error([], $e->getMessage());
+ }
+ }
+
+ /**
+ * 消息跳转路径设置接口
+ * @param $order_id
+ * @param $order_type
+ * @return array
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function orderShippingSetMsgJumpPath($order_id, $order_type)
+ {
+ try {
+ $path = 'pages/order/detail?order_id=' . $order_id; // 物流订单
+ switch ( $order_type ) {
+ case 2:
+ // 门店自提订单
+ $path = 'pages/order/detail_pickup?order_id=' . $order_id;
+ break;
+ case 3:
+ // 外卖订单
+ $path = 'pages/order/detail_local_delivery?order_id=' . $order_id;
+ break;
+ case 4:
+ // 虚拟订单
+ $path = 'pages_tool/order/detail_virtual?order_id=' . $order_id;
+ break;
+ }
+ $result = $this->app->order_shipping->setMsgJumpPath($path);
+ if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] != 0) {
+ return $this->error([], $result[ "errmsg" ]);
+ }
+ return $this->success($result);
+ } catch (\Exception $e) {
+ return $this->error([], $e->getMessage());
+ }
+
+ }
+
+ /**
+ * 订单发货信息录入接口
+ * @param array $data
+ * @return array
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function orderShippingUploadShippingInfo($data = [])
+ {
+
+ try {
+ // 检测微信小程序是否已开通发货信息管理服务
+ $is_trade_managed = $this->orderShippingIsTradeManaged();
+ if (!$is_trade_managed[ 'data' ]) {
+ return $this->success('', $is_trade_managed[ 'message' ]);
+ }
+
+ $order_model = new Order();
+ $filed = 'o.order_id,o.site_id,o.order_type,o.out_trade_no,o.pay_type,o.mobile,m.weapp_openid';
+ $join = [
+ [ 'member m', 'o.member_id=m.member_id', 'left' ]
+ ];
+ $order_info = model('order')->getInfo([ [ 'order_id', '=', $data[ 'order_id' ] ] ], $filed, 'o', $join);
+ if (empty($order_info)) {
+ return $this->error('', '订单不存在');
+ }
+
+ if ($order_info[ 'pay_type' ] != 'wechatpay') {
+ return $this->success('', '订单未使用微信支付');
+ }
+
+ $shop_model = new ShopModel();
+ $shop_info = $shop_model->getShopInfo([ [ 'site_id', '=', $this->site_id ] ], '')[ 'data' ];
+
+ // 设置消息跳转路径设置接口
+ $this->orderShippingSetMsgJumpPath($data[ 'order_id' ], $order_info[ 'order_type' ]);
+
+ $pay_config = ( new WechatPayModel() )->getPayConfig($order_info[ 'site_id' ])[ 'data' ][ 'value' ];
+
+ $logistics_type = 1; // 物流模式,发货方式枚举值:1、实体物流配送采用快递公司进行实体物流配送形式 2、同城配送 3、虚拟商品,虚拟商品,例如话费充值,点卡等,无实体配送形式 4、用户自提
+
+ // 订单类型 1:物流订单,2:门店自提订单,3:外卖订单,4:虚拟订单
+ if ($order_info[ 'order_type' ] == 1) {
+ $logistics_type = 1; // 1、实体物流配送采用快递公司进行实体物流配送形式
+ } else if ($order_info[ 'order_type' ] == 2) {
+ $logistics_type = 4; // 用户自提
+ } else if ($order_info[ 'order_type' ] == 3) {
+ $logistics_type = 2; // 同城配送
+ } else if ($order_info[ 'order_type' ] == 4) {
+ $logistics_type = 3; // 虚拟商品,例如话费充值,点卡等,无实体配送形式
+ }
+
+ $order_goods_field = 'order_goods_id,sku_name,num,delivery_no';
+
+ $order_goods_list = $order_model->getOrderGoodsList([
+ [ 'order_id', '=', $order_info[ 'order_id' ] ]
+ ], $order_goods_field, 'order_goods_id asc')[ 'data' ];
+
+ $delivery_mode = 1; // 发货模式,发货模式枚举值:1、UNIFIED_DELIVERY(统一发货)2、SPLIT_DELIVERY(分拆发货) 示例值: UNIFIED_DELIVERY
+ if ($logistics_type == 1) {
+ $delivery_mode = count($order_goods_list) == 1 ? 1 : 2;
+ }
+
+ $shipping_list = [];
+ $first_shipping_info = [];
+
+ // 获取物流公司
+ $delivery_list = [];
+ if ($logistics_type == 1) {
+ $delivery_list = $this->orderShippingGetDeliveryList()[ 'data' ];
+ }
+
+ foreach ($order_goods_list as $k => $v) {
+
+ // 一笔支付单最多分拆成 10 个包裹
+ if ($k == 10) {
+ break;
+ }
+
+ $express_company = ''; // 物流公司编码,快递公司ID,参见「查询物流公司编码列表」,物流快递发货时必填, 示例值: DHL 字符字节限制: [1, 128]
+
+ if ($logistics_type == 1) {
+ $info = model('express_delivery_package')->getInfo([
+ [ 'order_id', '=', $order_info[ 'order_id' ] ],
+ [ 'order_goods_id_array', 'like', '%' . $v[ 'order_goods_id' ] . '%' ]
+ ], 'express_company_id,express_company_name');
+
+ if (!empty($info) && $info[ 'express_company_id' ] && !empty($delivery_list)) {
+ $index = array_search($info[ 'express_company_name' ], array_column($delivery_list, 'delivery_name'));
+ if ($index !== false && isset($delivery_list[ $index ])) {
+ $express_company = $delivery_list[ $index ][ 'delivery_id' ];
+ }
+ if (empty($express_company)) {
+ return $this->error([], '物流公司不支持,请更换其他物流公司');
+ }
+ } else {
+ $logistics_type = 2; // 无需物流的情况,无实体配送形式
+ $delivery_mode = 1; // 统一发货
+ }
+
+ }
+
+ $item = [
+ 'tracking_no' => $v[ 'delivery_no' ], // 物流单号,物流快递发货时必填,示例值: 323244567777 字符字节限制: [1, 128]
+ 'express_company' => $express_company, // 物流公司编码,快递公司ID,参见「查询物流公司编码列表」,物流快递发货时必填, 示例值: DHL 字符字节限制: [1, 128]
+ 'item_desc' => str_sub($v[ 'sku_name' ], 90) . '*' . $v[ 'num' ], // 商品信息,例如:微信红包抱枕*1个,限120个字以内
+ 'contact' => [
+ 'consignor_contact' => '',
+ 'receiver_contact' => ''
+ ]
+ ];
+
+ // 寄件人联系方式,寄件人联系方式,采用掩码传输,最后4位数字不能打掩码 示例值: `189****1234, 021-****1234, ****1234, 0**2-***1234, 0**2-******23-10, ****123-8008` 值限制: 0 ≤ value ≤ 1024
+ if (!empty($shop_info[ 'mobile' ])) {
+ $item[ 'contact' ][ 'consignor_contact' ] = substr($shop_info[ 'mobile' ], 0, 3) . '****' . substr($shop_info[ 'mobile' ], 7);
+ }
+
+ // 收件人联系方式,收件人联系方式为,采用掩码传输,最后4位数字不能打掩码 示例值: `189****1234, 021-****1234, ****1234, 0**2-***1234, 0**2-******23-10, ****123-8008` 值限制: 0 ≤ value ≤ 1024
+ if (!empty($order_info[ 'mobile' ])) {
+ $item[ 'contact' ][ 'receiver_contact' ] = substr($order_info[ 'mobile' ], 0, 3) . '****' . substr($order_info[ 'mobile' ], 7);
+ }
+
+ $shipping_list[] = $item;
+ if ($k == 0) {
+ $first_shipping_info = $item;
+ $first_shipping_inf[ 'sku_name' ] = $v[ 'sku_name' ] . '*' . $v[ 'num' ];
+ }
+ }
+
+ // 统一发货,只能有一个物流信息,拼装商品信息
+ if ($delivery_mode == 1) {
+ if (count($shipping_list) > 1) {
+ foreach ($shipping_list as $k => $v) {
+ if ($k > 0) {
+ $first_shipping_info[ 'item_desc' ] .= ',' . $v[ 'item_desc' ];
+ }
+ }
+ }
+ $first_shipping_info[ 'item_desc' ] = str_sub($first_shipping_info[ 'item_desc' ], 90);
+ }
+
+ // 分拆发货模式时必填,用于标识分拆发货模式下是否已全部发货完成,只有全部发货完成的情况下才会向用户推送发货完成通知。示例值: true/false
+ $is_all_delivered = false;
+ if ($delivery_mode == 2) {
+ $is_all_delivered = true;
+ }
+
+ $params = [
+ 'order_key' => [
+ 'order_number_type' => 1, // 订单单号类型,用于确认需要上传详情的订单。枚举值1,使用下单商户号和商户侧单号;枚举值2,使用微信支付单号。
+ 'mchid' => $pay_config[ 'mch_id' ], // 支付下单商户的商户号,由微信支付生成并下发。
+ 'out_trade_no' => $order_info[ 'out_trade_no' ] // 商户系统内部订单号,只能是数字、大小写字母`_-*`且在同一个商户号下唯一
+ ],
+ 'logistics_type' => $logistics_type, // 物流模式,发货方式枚举值:1、实体物流配送采用快递公司进行实体物流配送形式 2、同城配送 3、虚拟商品,虚拟商品,例如话费充值,点卡等,无实体配送形式 4、用户自提
+ 'delivery_mode' => $delivery_mode, // 发货模式,发货模式枚举值:1、UNIFIED_DELIVERY(统一发货)2、SPLIT_DELIVERY(分拆发货) 示例值: UNIFIED_DELIVERY
+ // 同城配送没有物流信息,只能传一个订单
+ 'shipping_list' => $delivery_mode == 1 ? [ $first_shipping_info ] : $shipping_list, // 物流信息列表,发货物流单列表,支持统一发货(单个物流单)和分拆发货(多个物流单)两种模式,多重性: [1, 10]
+ 'upload_time' => date("c", time()), // 上传时间,用于标识请求的先后顺序 示例值: `2022-12-15T13:29:35.120+08:00`
+ 'payer' => [
+ 'openid' => $order_info[ 'weapp_openid' ] // 用户标识,用户在小程序appid下的唯一标识。 下单前需获取到用户的Openid 示例值: oUpF8uMuAJO_M2pxb1Q9zNjWeS6o 字符字节限制: [1, 128]
+ ],
+ 'is_all_delivered' => $is_all_delivered
+ ];
+
+ Log::write('发货信息录入接口(参数):' . json_encode($params));
+
+ $result = $this->app->order_shipping->uploadShippingInfo($params);
+
+ Log::write('发货信息录入接口(结果):' . json_encode($result));
+ if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] != 0) {
+ // 排除 支付单不存在,错误码:10060001
+ if ($result[ 'errcode' ] != 10060001) {
+ return $this->error([], $result[ "errmsg" ]);
+ }
+ }
+
+ return $this->success($result);
+ } catch (\Exception $e) {
+ return $this->error([], $e->getMessage() . ",File:" . $e->getFile() . ",line:" . $e->getLine());
+ }
+ }
+
+ /**
+ * 发货信息录入接口,自备数据
+ * @param array $data
+ * @return array
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function orderShippingUploadShippingInfoByData($data = [])
+ {
+
+ try {
+ // 检测微信小程序是否已开通发货信息管理服务
+ $is_trade_managed = $this->orderShippingIsTradeManaged();
+ if (!$is_trade_managed[ 'data' ]) {
+ return $this->success('', $is_trade_managed[ 'message' ]);
+ }
+ $pay_config = ( new WechatPayModel() )->getPayConfig($data[ 'site_id' ])[ 'data' ][ 'value' ];
+
+ $params = [
+ 'order_key' => [
+ 'order_number_type' => 1, // 订单单号类型,用于确认需要上传详情的订单。枚举值1,使用下单商户号和商户侧单号;枚举值2,使用微信支付单号。
+ 'mchid' => $pay_config[ 'mch_id' ], // 支付下单商户的商户号,由微信支付生成并下发。
+ 'out_trade_no' => $data[ 'out_trade_no' ] // 商户系统内部订单号,只能是数字、大小写字母`_-*`且在同一个商户号下唯一
+ ],
+ 'logistics_type' => $data[ 'logistics_type' ], // 物流模式,发货方式枚举值:1、实体物流配送采用快递公司进行实体物流配送形式 2、同城配送 3、虚拟商品,虚拟商品,例如话费充值,点卡等,无实体配送形式 4、用户自提
+ 'delivery_mode' => $data[ 'delivery_mode' ], // 发货模式,发货模式枚举值:1、UNIFIED_DELIVERY(统一发货)2、SPLIT_DELIVERY(分拆发货) 示例值: UNIFIED_DELIVERY
+ // 同城配送没有物流信息,只能传一个订单
+ 'shipping_list' => $data[ 'shipping_list' ], // 物流信息列表,发货物流单列表,支持统一发货(单个物流单)和分拆发货(多个物流单)两种模式,多重性: [1, 10]
+ 'upload_time' => date("c", time()), // 上传时间,用于标识请求的先后顺序 示例值: `2022-12-15T13:29:35.120+08:00`
+ 'payer' => [
+ 'openid' => $data[ 'weapp_openid' ] // 用户标识,用户在小程序appid下的唯一标识。 下单前需获取到用户的Openid 示例值: oUpF8uMuAJO_M2pxb1Q9zNjWeS6o 字符字节限制: [1, 128]
+ ],
+ 'is_all_delivered' => $data[ 'is_all_delivered' ] // 分拆发货模式时必填,用于标识分拆发货模式下是否已全部发货完成,只有全部发货完成的情况下才会向用户推送发货完成通知。示例值: true/false
+ ];
+
+ Log::write('发货信息录入接口,自备数据(参数):' . json_encode($params));
+
+ $result = $this->app->order_shipping->uploadShippingInfo($params);
+
+ Log::write('发货信息录入接口,自备数据(结果):' . json_encode($result));
+ if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] != 0) {
+ return $this->error([], $result[ "errmsg" ]);
+ }
+
+ return $this->success($result);
+ } catch (\Exception $e) {
+ return $this->error([], $e->getMessage() . ",File:" . $e->getFile() . ",line:" . $e->getLine());
+ }
+ }
+
+ /**
+ * todo【暂时没有用到】发货信息合单录入接口
+ * @param array $data
+ * @return array
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function orderShippingUploadCombinedShippingInfo($data = [])
+ {
+ try {
+ $params = [
+ 'order_key' => [
+ 'order_number_type' => $data[ 'order_number_type' ] ?? 1, // 订单单号类型,用于确认需要上传详情的订单。枚举值1,使用下单商户号和商户侧单号;枚举值2,使用微信支付单号。
+ ],
+ 'logistics_type' => $data[ 'logistics_type' ], // 物流模式,发货方式枚举值:1、实体物流配送采用快递公司进行实体物流配送形式 2、同城配送 3、虚拟商品,虚拟商品,例如话费充值,点卡等,无实体配送形式 4、用户自提
+ 'delivery_mode' => $data[ 'delivery_mode' ], // 发货模式,发货模式枚举值:1、UNIFIED_DELIVERY(统一发货)2、SPLIT_DELIVERY(分拆发货) 示例值: UNIFIED_DELIVERY
+ 'sub_orders' => $data[ 'sub_orders' ], // 子单物流详情
+ 'upload_time' => $data[ 'upload_time' ], // 上传时间,用于标识请求的先后顺序 示例值: `2022-12-15T13:29:35.120+08:00`
+ 'payer' => [
+ 'openid' => $data[ 'openid' ] // 用户标识,用户在小程序appid下的唯一标识。 下单前需获取到用户的Openid 示例值: oUpF8uMuAJO_M2pxb1Q9zNjWeS6o 字符字节限制: [1, 128]
+ ]
+ ];
+
+ // 原支付交易对应的微信订单号
+ if (!empty($data[ 'transaction_id' ])) {
+ $params[ 'order_key' ][ 'transaction_id' ] = $data[ 'transaction_id' ];
+ }
+
+ // 支付下单商户的商户号,由微信支付生成并下发。
+ if (!empty($data[ 'mchid' ])) {
+ $params[ 'order_key' ][ 'mchid' ] = $data[ 'mchid' ];
+ }
+
+ // 商户系统内部订单号,只能是数字、大小写字母`_-*`且在同一个商户号下唯一
+ if (!empty($data[ 'out_trade_no' ])) {
+ $params[ 'order_key' ][ 'out_trade_no' ] = $data[ 'out_trade_no' ];
+ }
+
+ $result = $this->app->order_shipping->uploadCombinedShippingInfo($params);
+ if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] != 0) {
+ return $this->error([], $result[ "errmsg" ]);
+ }
+
+ return $this->success($result);
+ } catch (\Exception $e) {
+ return $this->error([], $e->getMessage());
+ }
+ }
+
+ /**
+ * 确认收货提醒接口
+ * @param array $data
+ * @return array
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function orderShippingNotifyConfirmReceive($data = [])
+ {
+
+ try {
+ // 检测微信小程序是否已开通发货信息管理服务
+ $is_trade_managed = $this->orderShippingIsTradeManaged();
+ if (!$is_trade_managed[ 'data' ]) {
+ return $this->success('', $is_trade_managed[ 'message' ]);
+ }
+
+ $filed = 'o.order_id,o.site_id,o.order_type,o.out_trade_no,o.pay_type,o.mobile,m.weapp_openid';
+ $join = [
+ [ 'member m', 'o.member_id=m.member_id', 'left' ]
+ ];
+ $order_info = model('order')->getInfo([ [ 'order_id', '=', $data[ 'order_id' ] ] ], $filed, 'o', $join);
+ if (empty($order_info)) {
+ return $this->error('', '订单不存在');
+ }
+
+ if ($order_info[ 'pay_type' ] != 'wechatpay') {
+ return $this->success('', '订单未使用微信支付');
+ }
+
+ if ($order_info[ 'order_type' ] != 1) {
+ return $this->success('', '只有物流订单才能进行提醒');
+ }
+
+ // 设置消息跳转路径设置接口
+ $this->orderShippingSetMsgJumpPath($data[ 'order_id' ], $order_info[ 'order_type' ]);
+
+ $pay_config = ( new WechatPayModel() )->getPayConfig($order_info[ 'site_id' ])[ 'data' ][ 'value' ];
+
+ $params = [
+ 'merchant_id' => $pay_config[ 'mch_id' ], // 支付下单商户的商户号,由微信支付生成并下发
+ 'merchant_trade_no' => $order_info[ 'out_trade_no' ], // 商户系统内部订单号,只能是数字、大小写字母_-*且在同一个商户号下唯一
+ 'received_time' => time() // 快递签收时间,时间戳形式
+ ];
+
+ Log::write('确认收货提醒接口(参数):' . json_encode($params));
+
+ $result = $this->app->order_shipping->notifyConfirmReceive($params);
+
+ Log::write('确认收货提醒接口(结果):' . json_encode($result));
+ if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] != 0) {
+ Log::write('微信小程序确认收货提醒接口报错:' . json_encode($result));
+ return $this->success([], $result[ "errmsg" ]);
+ }
+
+ return $this->success($result);
+ } catch (\Exception $e) {
+ return $this->error([], $e->getMessage());
+ }
+ }
+
+ /**
+ * 获取物流公司,运力id列表get_delivery_list
+ * @param array $data
+ * @return array
+ * @throws \GuzzleHttp\Exception\GuzzleException
+ */
+ public function orderShippingGetDeliveryList()
+ {
+ $cache = Cache::get('orderShippingGetDeliveryList');
+ if ($cache) return $cache;
+
+ try {
+ $result = $this->app->order_shipping->getDeliveryList();
+ if (isset($result[ 'errcode' ]) && $result[ 'errcode' ] != 0) {
+ return $this->error([], $result[ "errmsg" ]);
+ }
+
+ $data = $this->success($result[ 'delivery_list' ]);
+ Cache::set('orderShippingGetDeliveryList', $data);
+ return $data;
+ } catch (\Exception $e) {
+ return $this->error([], $e->getMessage());
+ }
+ }
+
+}
diff --git a/src/addon/weapp/shop/controller/Message.php b/src/addon/weapp/shop/controller/Message.php
index eb820564e..d218e7401 100644
--- a/src/addon/weapp/shop/controller/Message.php
+++ b/src/addon/weapp/shop/controller/Message.php
@@ -1,103 +1,95 @@
-isJson()) {
- $page = input('page', 1);
- $page_size = input('page_size', PAGE_LIST_ROWS);
- $condition = array (
- [ "support_type", "like", '%weapp%' ],
- );
- $list = $message_model->getMessagePageList($condition, $this->site_id, $page, $page_size);
- return $list;
- } else {
- return $this->fetch('message/config');
- }
- }
-
- /**
- * 微信模板消息状态设置
- */
- public function setWeappStatus()
- {
- $message_model = new MessageModel();
-
- if (request()->isJson()) {
- $keywords = input("keywords", "");
- $weapp_is_open = input('weapp_is_open', 0);
- $res = $message_model->getWeappTemplateNo($keywords, $this->site_id, $weapp_is_open);
- return $res;
- }
- }
-
- /**
- * 获取模板编号
- */
- public function getWeappTemplateNo()
- {
- if (request()->isJson()) {
- $keywords = input("keywords", "");
- $message_model = new MessageModel();
- $res = $message_model->getWeappTemplateNo($keywords, $this->site_id, -1);
- return $res;
- }
- }
-
- /**
- * 编辑模板消息
- * @return array|mixed|string
- */
- public function edit()
- {
- $message_model = new MessageSyetem();
- $keywords = input("keywords", "");
- $info_result = $message_model->getMessageInfo($this->site_id, $keywords);
- $info = $info_result[ "data" ];
-
- $weapp_json_array = $info[ "weapp_json_array" ];
- if (request()->isJson()) {
- if (empty($info))
- return error("", "不存在的模板信息!");
-
- $weapp_is_open = input('weapp_is_open', 0);
-
- $res = $message_model->editMessage([ 'weapp_is_open' => $weapp_is_open, 'site_id' => $this->site_id, 'keywords' => $keywords ], [
- [ "keywords", "=", $keywords ],
- [ 'site_id', '=', $this->site_id ],
- ]);
- return $res;
- } else {
- if (empty($info)) $this->error("不存在的模板信息!");
-
-
- $this->assign("keywords", $keywords);
- $this->assign("info", $weapp_json_array);
- $this->assign('weapp_is_open', $info[ 'weapp_is_open' ]);
- return $this->fetch('message/edit');
- }
- }
+isJson()) {
+ $page = input('page', 1);
+ $page_size = input('page_size', PAGE_LIST_ROWS);
+ $condition = array (
+ [ "support_type", "like", '%weapp%' ],
+ );
+ $list = $message_model->getMessagePageList($condition, $this->site_id, $page, $page_size);
+ return $list;
+ } else {
+ return $this->fetch('message/config');
+ }
+ }
+
+ /**
+ * 微信模板消息状态设置
+ */
+ public function setWeappStatus()
+ {
+ $message_model = new MessageModel();
+
+ if (request()->isJson()) {
+ $keywords = input("keywords", "");
+ $weapp_is_open = input('weapp_is_open', 0);
+ $res = $message_model->getWeappTemplateNo($keywords, $this->site_id, $weapp_is_open);
+ return $res;
+ }
+ }
+
+ /**
+ * 获取模板编号
+ */
+ public function getWeappTemplateNo()
+ {
+ if (request()->isJson()) {
+ $keywords = input("keywords", "");
+ $message_model = new MessageModel();
+ $res = $message_model->getWeappTemplateNo($keywords, $this->site_id, -1);
+ return $res;
+ }
+ }
+
+ /**
+ * 编辑模板消息
+ * @return array|mixed|string
+ */
+ public function edit()
+ {
+ $message_model = new MessageSyetem();
+ $keywords = input("keywords", "");
+ $info_result = $message_model->getMessageInfo($this->site_id, $keywords);
+ $info = $info_result[ "data" ];
+
+ $weapp_json_array = $info[ "weapp_json_array" ];
+ if (request()->isJson()) {
+ if (empty($info))
+ return error("", "不存在的模板信息!");
+
+ $weapp_is_open = input('weapp_is_open', 0);
+
+ $res = $message_model->editMessage([ 'weapp_is_open' => $weapp_is_open, 'site_id' => $this->site_id, 'keywords' => $keywords ], [
+ [ "keywords", "=", $keywords ],
+ [ 'site_id', '=', $this->site_id ],
+ ]);
+ return $res;
+ } else {
+ if (empty($info)) $this->error("不存在的模板信息!");
+
+
+ $this->assign("keywords", $keywords);
+ $this->assign("info", $weapp_json_array);
+ $this->assign('weapp_is_open', $info[ 'weapp_is_open' ]);
+ return $this->fetch('message/edit');
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/weapp/shop/controller/Stat.php b/src/addon/weapp/shop/controller/Stat.php
index cb4b3f650..d2e845b35 100644
--- a/src/addon/weapp/shop/controller/Stat.php
+++ b/src/addon/weapp/shop/controller/Stat.php
@@ -1,104 +1,96 @@
-replace = [
- 'WEAPP_CSS' => __ROOT__ . '/addon/weapp/shop/view/public/css',
- 'WEAPP_JS' => __ROOT__ . '/addon/weapp/shop/view/public/js',
- 'WEAPP_IMG' => __ROOT__ . '/addon/weapp/shop/view/public/img',
- 'WEAPP_SVG' => __ROOT__ . '/addon/weapp/shop/view/public/svg',
- ];
- parent::__construct($app);
- }
-
- public function stat()
- {
- return $this->fetch('stat/stat');
- }
-
- /**
- * 统计昨日的数据
- */
- public function visitData()
- {
- if (request()->isJson()) {
- $date_type = input("date_type", "month");
- $stat_model = new StatModel();
- $result = $stat_model->visitData($date_type);
- return $result;
- }
- }
-
- /**
- * 获取微信小程序 数据分析统计
- */
- public function visitStatistics()
- {
-
- $stat_model = new StatModel();
- $daterange = input("daterange", "");
- $result = $stat_model->visitStatistics($daterange);
- return $result;
- }
-
- /**
- * 得到时间间隔
- * @param $date_type
- * @param string $daterange
- * @return array
- */
- public function getDaterange($date_type, $daterange = "")
- {
- $today_date = date('Ymd');//当前日日期
- $begin_date = "";
- $end_date = "";
-
- switch ($date_type) {
- case 'today':
- $begin_date = $today_date;
- $end_date = $today_date;
- break;
- case 'yesterday':
- $begin_date = date('Ymd', strtotime('-1 days'));
- $end_date = date('Ymd', strtotime('-1 days'));
- break;
- case 'week':
- $begin_date = date('Ymd', strtotime('-6 days'));
- $end_date = $today_date;
- break;
- case 'month':
- $begin_date = date('Ymd', strtotime('-29 days'));
- $end_date = $today_date;
- break;
- case 'daterange':
- if (!empty($daterange)) {
- $daterange_array = explode(" - ", $daterange);
- $begin_date = date_format(date_create($daterange_array[0]), "Ymd");
- $end_date = date_format(date_create($daterange_array[1]), "Ymd");
- }
- $begin_date = date('Ymd', strtotime($begin_date));//开始日期
- $end_date = date('Ymd', strtotime($end_date));//结束日期
- break;
- }
-
- return array("begin_date" => $begin_date, "end_date" => $end_date);
- }
+replace = [
+ 'WEAPP_CSS' => __ROOT__ . '/addon/weapp/shop/view/public/css',
+ 'WEAPP_JS' => __ROOT__ . '/addon/weapp/shop/view/public/js',
+ 'WEAPP_IMG' => __ROOT__ . '/addon/weapp/shop/view/public/img',
+ 'WEAPP_SVG' => __ROOT__ . '/addon/weapp/shop/view/public/svg',
+ ];
+ parent::__construct($app);
+ }
+
+ public function stat()
+ {
+ return $this->fetch('stat/stat');
+ }
+
+ /**
+ * 统计昨日的数据
+ */
+ public function visitData()
+ {
+ if (request()->isJson()) {
+ $date_type = input("date_type", "month");
+ $stat_model = new StatModel();
+ $result = $stat_model->visitData($date_type);
+ return $result;
+ }
+ }
+
+ /**
+ * 获取微信小程序 数据分析统计
+ */
+ public function visitStatistics()
+ {
+
+ $stat_model = new StatModel();
+ $daterange = input("daterange", "");
+ $result = $stat_model->visitStatistics($daterange);
+ return $result;
+ }
+
+ /**
+ * 得到时间间隔
+ * @param $date_type
+ * @param string $daterange
+ * @return array
+ */
+ public function getDaterange($date_type, $daterange = "")
+ {
+ $today_date = date('Ymd');//当前日日期
+ $begin_date = "";
+ $end_date = "";
+
+ switch ($date_type) {
+ case 'today':
+ $begin_date = $today_date;
+ $end_date = $today_date;
+ break;
+ case 'yesterday':
+ $begin_date = date('Ymd', strtotime('-1 days'));
+ $end_date = date('Ymd', strtotime('-1 days'));
+ break;
+ case 'week':
+ $begin_date = date('Ymd', strtotime('-6 days'));
+ $end_date = $today_date;
+ break;
+ case 'month':
+ $begin_date = date('Ymd', strtotime('-29 days'));
+ $end_date = $today_date;
+ break;
+ case 'daterange':
+ if (!empty($daterange)) {
+ $daterange_array = explode(" - ", $daterange);
+ $begin_date = date_format(date_create($daterange_array[0]), "Ymd");
+ $end_date = date_format(date_create($daterange_array[1]), "Ymd");
+ }
+ $begin_date = date('Ymd', strtotime($begin_date));//开始日期
+ $end_date = date('Ymd', strtotime($end_date));//结束日期
+ break;
+ }
+
+ return array("begin_date" => $begin_date, "end_date" => $end_date);
+ }
}
\ No newline at end of file
diff --git a/src/addon/wechatpay/api/controller/Transfer.php b/src/addon/wechatpay/api/controller/Transfer.php
new file mode 100644
index 000000000..3681bf3ef
--- /dev/null
+++ b/src/addon/wechatpay/api/controller/Transfer.php
@@ -0,0 +1,128 @@
+transferNotify();
+ }
+
+
+ /**
+ * 发起收款
+ */
+
+ public function transfer(){
+
+ $id = $this->params['id'] ?? ''; //提现单id
+ $transfer_type = $this->params['transfer_type'] ?? ''; //提现来源
+
+ $token = $this->checkToken();
+ if ($token[ 'code' ] < 0 && $transfer_type != 'store_withdraw') return $this->response($token);
+ if (empty($id)) {
+ return $this->response($this->error('', 'REQUEST_ID'));
+ }
+
+ $cache = Cache::get('transfer:' . $id);
+ if(!empty($cache)){
+ return $this->response($this->error('', '系统处理中,请务重复提交'));
+ }
+
+ try{
+ Cache::set("transfer:".$id,1,10);
+
+ //判断是公众号还是小程序
+ if($transfer_type != 'store_withdraw'){
+ $member_model = new \app\model\member\Member();
+ $member_info = $member_model->getMemberInfo([['member_id', '=', $this->member_id]], 'wx_openid,weapp_openid')['data'];
+ (new PayTransfer())->editTransfer([
+ 'is_weapp'=>$this->params['app_type'] == 'weapp' ? 1 : 0,
+ 'account_number'=>$this->params['app_type'] == 'weapp' ? $member_info['weapp_openid'] : $member_info['wx_openid'],
+ ],[['relate_tag','=',$id],['from_type','=',$transfer_type]]);
+ }
+
+ $transfer_model = new \app\model\system\PayTransfer();
+ $result = $transfer_model->transfer($transfer_type, $id, true);
+
+ Cache::delete('transfer:' . $id);
+ return $this->response($result);
+ }catch (ApiException $errorException){
+ Cache::delete('transfer:' . $id);
+ Log::write('发起收款接口异常,原因'.$errorException->getMessage());
+ return $this->response($this->error([],'系统异常,请稍后再试'));
+ }
+ }
+
+ /**
+ * 撤销转账
+ */
+
+ public function cancel(){
+ $out_trade_no = $this->params['out_trade_no'] ?? '';
+ if (empty($out_trade_no)) {
+ return $this->response($this->error('', '商户单号有误'));
+ }
+ $pay = new Pay();
+ $result = $pay->transferCancel($out_trade_no);
+ return $this->response($result);
+ }
+
+
+
+ /**
+ * 获取转账配置
+ */
+ public function getWithdrawConfig(){
+ $config_model = new Config();
+ $config = $config_model->getPayConfig($this->site_id)[ 'data' ][ 'value' ];
+ $wechat_config = (new WechatConfig())->getWechatConfig($this->site_id);
+ $weapp_config_result = (new WeaAppConfig())->getWeappConfig($this->site_id);
+ $data = [
+ 'transfer_type'=>$config['transfer_type'] == 'v3' && $config['transfer_v3_type'] == $config_model::TRANSFER_V3_TYPE_USER ? 1 : 0,
+ 'mch_id'=>$config['mch_id'] ?? '',
+ 'wechat_appid'=>$wechat_config['data']['value']['appid'] ?? '',
+ 'weapp_appid'=>$weapp_config_result['data']['value']['appid'] ?? '',
+ ];
+ return $this->response($this->success($data));
+ }
+
+ /**
+ * 更改状态为转账中
+ */
+ public function inProcess()
+ {
+ $relate_tag = $this->params['relate_tag'] ?? '';
+ $from_type = $this->params['from_type'] ?? '';
+
+ $transfer_model = new \app\model\system\PayTransfer();
+ $transfer_info = $transfer_model->getTransferInfo([['from_type', '=', $from_type], ['relate_tag', '=', $relate_tag]])['data'];
+ $res = $transfer_model->updateStatus(['status' => $transfer_model::STATUS_IN_PROCESS], $transfer_info['id'] ?? 0);
+
+ return $this->response($res);
+ }
+
+
+}
\ No newline at end of file
diff --git a/src/addon/wechatpay/config/diy_view.php b/src/addon/wechatpay/config/diy_view.php
index c3c657905..e36ca9b7d 100644
--- a/src/addon/wechatpay/config/diy_view.php
+++ b/src/addon/wechatpay/config/diy_view.php
@@ -1,38 +1,30 @@
- '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
- 'template' => [],
-
- // 后台自定义组件——装修
- 'util' => [],
-
- // 自定义页面路径
- 'link' => [],
-
- // 自定义图标库
- 'icon_library' => [],
-
- // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
- 'component' => [],
-
- // uni-app 页面,多个逗号隔开
- 'pages' => [],
-
- // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
- 'info' => [],
-
- // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
- 'theme' => [],
-
- // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
- 'data' => []
+ '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据,json格式' ]
+ 'template' => [],
+
+ // 后台自定义组件——装修
+ 'util' => [],
+
+ // 自定义页面路径
+ 'link' => [],
+
+ // 自定义图标库
+ 'icon_library' => [],
+
+ // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ],多个逗号隔开,自定义组件名称前缀必须是diy-,也可以引用第三方组件
+ 'component' => [],
+
+ // uni-app 页面,多个逗号隔开
+ 'pages' => [],
+
+ // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
+ 'info' => [],
+
+ // 主题风格配色,格式可以自由定义扩展,【在uni-app中通过:this.themeStyle... 获取定义的颜色字段,例如:this.themeStyle.main_color】
+ 'theme' => [],
+
+ // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据,json格式] ]
+ 'data' => []
];
\ No newline at end of file
diff --git a/src/addon/wechatpay/config/event.php b/src/addon/wechatpay/config/event.php
index bae09cf34..e62849f1e 100644
--- a/src/addon/wechatpay/config/event.php
+++ b/src/addon/wechatpay/config/event.php
@@ -30,8 +30,8 @@ return [
'TransferType' => [
'addon\wechatpay\event\TransferType'
],
- 'TransferResult' => [
- 'addon\wechatpay\event\TransferResult'
+ 'PayTransferResult' => [
+ 'addon\wechatpay\event\PayTransferResult'
],
//付款码支付异步回调
'AuthcodePay' => [
diff --git a/src/addon/wechatpay/config/info.php b/src/addon/wechatpay/config/info.php
index 43b869715..68780b4dc 100644
--- a/src/addon/wechatpay/config/info.php
+++ b/src/addon/wechatpay/config/info.php
@@ -1,20 +1,12 @@
- 'wechatpay',
- 'title' => '微信支付',
- 'description' => '微信支付功能',
- 'type' => 'system', //插件类型 system :系统插件(自动安装), business:业务插件 promotion:扩展营销插件 tool:工具插件
- 'status' => 1,
- 'author' => '',
- 'version' => '5.3.1',
- 'version_no' => '525231212001',
- 'content' => '',
+ 'wechatpay',
+ 'title' => '微信支付',
+ 'description' => '微信支付功能',
+ 'type' => 'system', //插件类型 system :系统插件(自动安装), business:业务插件 promotion:扩展营销插件 tool:工具插件
+ 'status' => 1,
+ 'author' => '',
+ 'version' => '5.5.2',
+ 'version_no' => '552250604001',
+ 'content' => '',
];
\ No newline at end of file
diff --git a/src/addon/wechatpay/event/AuthcodePay.php b/src/addon/wechatpay/event/AuthcodePay.php
index a26197522..082918341 100644
--- a/src/addon/wechatpay/event/AuthcodePay.php
+++ b/src/addon/wechatpay/event/AuthcodePay.php
@@ -1,4 +1,5 @@
pay($params);
- return $result;
- }
- }
+pay($params);
+ return $result;
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/wechatpay/event/PayClose.php b/src/addon/wechatpay/event/PayClose.php
index d070a633c..518af1e24 100644
--- a/src/addon/wechatpay/event/PayClose.php
+++ b/src/addon/wechatpay/event/PayClose.php
@@ -1,41 +1,34 @@
-close($params);
- return $result;
- } catch (\Exception $e) {
- return error(-1, $e->getMessage());
- } catch (\Throwable $e) {
- return error(-1, $e->getMessage());
- }
-
-// }
- }
+close($params);
+ return $result;
+ } catch (\Exception $e) {
+ return error(-1, $e->getMessage());
+ } catch (\Throwable $e) {
+ return error(-1, $e->getMessage());
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/wechatpay/event/PayNotify.php b/src/addon/wechatpay/event/PayNotify.php
index 1078eb544..72c928437 100644
--- a/src/addon/wechatpay/event/PayNotify.php
+++ b/src/addon/wechatpay/event/PayNotify.php
@@ -3,6 +3,7 @@
namespace addon\wechatpay\event;
use addon\wechatpay\model\Pay as PayModel;
+use think\facade\Log;
/**
* 支付回调
@@ -14,28 +15,9 @@ class PayNotify
*/
public function handle($param)
{
-
- try {
- $reqData = empty($GLOBALS[ 'HTTP_RAW_POST_DATA' ]) ? file_get_contents('php://input') : $GLOBALS[ 'HTTP_RAW_POST_DATA' ];
-
- if (empty($reqData)) {
- return;
- }
- $xmlstring = simplexml_load_string($reqData, 'SimpleXMLElement', LIBXML_NOCDATA);
- if (empty($xmlstring)) {
- return;
- }
- $val = json_decode(json_encode($xmlstring), true);
- // file_put_contents(__DIR__ . '/debug.txt', var_export($reqData,true).'----'.print_r($xmlstring,true).'----'.print_r($val,true).'-----'.PHP_EOL,FILE_APPEND);
- if (!empty($val[ 'trade_type' ]) && $val[ 'trade_type' ] != 'APP') {
- $pay = model('pay')->getInfo(['out_trade_no'=>$val['out_trade_no']]);
- $model = new PayModel(0,$pay['site_id']);
- return $model->payNotify();
- }
- } catch (\Exception $e) {
- //v3直接跳错误去执行
- return ( new PayModel() )->payNotify();
- }
-
+ $reqData = empty($GLOBALS[ 'HTTP_RAW_POST_DATA' ]) ? file_get_contents('php://input') : $GLOBALS[ 'HTTP_RAW_POST_DATA' ];
+ Log::write('微信支付回调数据');
+ Log::write($reqData);
+ return ( new PayModel() )->payNotify();
}
}
\ No newline at end of file
diff --git a/src/addon/wechatpay/event/PayOrderQuery.php b/src/addon/wechatpay/event/PayOrderQuery.php
index da67120b2..93dbe2356 100644
--- a/src/addon/wechatpay/event/PayOrderQuery.php
+++ b/src/addon/wechatpay/event/PayOrderQuery.php
@@ -1,35 +1,39 @@
-getInfo([ [ 'id', '=', $params[ 'relate_id' ] ], [ 'pay_type', '=', 'wechatpay' ] ])[ 'data' ];
- if (!empty($pay_info)) {
- $pay_config = ( new Config() )->getPayConfig($pay_info[ 'site_id' ])[ 'data' ][ 'value' ];
- $wechat_config = ( new WechatConfig() )->getWechatConfig($pay_info[ 'site_id' ])[ 'data' ][ 'value' ];
- $pay_config[ 'appid' ] = $wechat_config[ 'appid' ] ?? '';
- if (!empty($pay_config) && $pay_config[ 'pay_status' ] == 1) {
- ( new V2($pay_config) )->orderQuery($pay_info);
- }
- }
- }
-}
+getInfo([ [ 'id', '=', $params[ 'relate_id' ] ]])[ 'data' ];
+ if (!empty($pay_info) && $pay_info['is_delete'] == 0) {
+ $mch_info = json_decode($pay_info['mch_info'], true);
+ $pay_type = $mch_info['pay_type'] ?? 'wechatpay';
+ if($pay_type == 'wechatpay'){
+ $pay_config = ( new Config() )->getPayConfig($pay_info[ 'site_id' ])[ 'data' ][ 'value' ];
+ $wechat_config = ( new WechatConfig() )->getWechatConfig($pay_info[ 'site_id' ])[ 'data' ][ 'value' ];
+ $pay_config[ 'appid' ] = $wechat_config[ 'appid' ] ?? '';
+ if (!empty($pay_config) && $pay_config[ 'pay_status' ] == 1) {
+ $res = ( new V2($pay_config) )->orderQuery($pay_info);
+ }
+ }
+ }
+ return $res;
+ }catch (\Throwable $e) {
+ return error(-1, $e->getMessage());
+ }
+
+ }
+}
diff --git a/src/addon/wechatpay/event/PayRefund.php b/src/addon/wechatpay/event/PayRefund.php
index 81d1ce388..ad884dfd3 100644
--- a/src/addon/wechatpay/event/PayRefund.php
+++ b/src/addon/wechatpay/event/PayRefund.php
@@ -1,47 +1,39 @@
- $params[ 'out_aftersale_id' ]
- ];
- $info = $weapp_model->getAftersale($refund_params);
- if ($info[ 'code' ] == 0 && !empty($info[ 'data' ])) {
- $result = $weapp_model->orderRefund($refund_params);
- } else {
- $pay_model = new PayModel(0, $params[ 'site_id' ]);
- $result = $pay_model->refund($params);
- }
- } else {
- $pay_model = new PayModel(0, $params[ 'site_id' ]);
- $result = $pay_model->refund($params);
- }
- return $result;
- }
- }
+ $params[ 'out_aftersale_id' ]
+ ];
+ $info = $weapp_model->getAftersale($refund_params);
+ if ($info[ 'code' ] == 0 && !empty($info[ 'data' ])) {
+ $result = $weapp_model->orderRefund($refund_params);
+ } else {
+ $pay_model = new PayModel(0, $params[ 'site_id' ]);
+ $result = $pay_model->refund($params);
+ }
+ } else {
+ $pay_model = new PayModel(0, $params[ 'site_id' ]);
+ $result = $pay_model->refund($params);
+ }
+ return $result;
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/wechatpay/event/PayTransfer.php b/src/addon/wechatpay/event/PayTransfer.php
index e25566d6b..d646a783f 100644
--- a/src/addon/wechatpay/event/PayTransfer.php
+++ b/src/addon/wechatpay/event/PayTransfer.php
@@ -1,26 +1,18 @@
-transfer($params);
- return $res;
- }
- }
+transfer($params);
+ return $res;
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/wechatpay/event/PayTransferResult.php b/src/addon/wechatpay/event/PayTransferResult.php
new file mode 100644
index 000000000..62144062c
--- /dev/null
+++ b/src/addon/wechatpay/event/PayTransferResult.php
@@ -0,0 +1,20 @@
+getPayConfig($params['site_id'])['data']['value'];
+ $pay_config['site_id'] = $params['site_id'];
+ if (!empty($pay_config) && $pay_config['transfer_v3_type'] == Config::TRANSFER_V3_TYPE_SHOP) {
+ return (new V3($pay_config))->getTransferResult($params);
+ }
+ return (new V3($pay_config))->success();
+ }
+}
\ No newline at end of file
diff --git a/src/addon/wechatpay/event/PayType.php b/src/addon/wechatpay/event/PayType.php
index 6abf46521..176356cbb 100644
--- a/src/addon/wechatpay/event/PayType.php
+++ b/src/addon/wechatpay/event/PayType.php
@@ -1,50 +1,44 @@
-getPayConfig($params[ 'site_id' ]);
- $config = $config_result[ "data" ][ "value" ] ?? [];
- $pay_status = $config[ "pay_status" ] ?? 0;
- if ($pay_status == 0) {
- return '';
- }
- }
- $info = array (
- "pay_type" => "wechatpay",
- "pay_type_name" => "微信支付",
- "edit_url" => "wechatpay://shop/pay/config",
- "shop_url" => "wechatpay://shop/pay/config",
- "logo" => "addon/wechatpay/icon.png",
- "desc" => "微信支付,用户通过扫描二维码、微信内打开商品页面购买等多种方式调起微信支付模块完成支付。"
- );
- return $info;
-
- }
+getPayConfig($params[ 'site_id' ] ?? 1);
+ $config = $config_result[ "data" ][ "value" ] ?? [];
+ $pay_status = $config[ "pay_status" ] ?? 0;
+
+ $app_type = $params['app_type'] ?? '';
+ if (!empty($app_type)) {
+ $app_type_array = [ 'h5', 'wechat', 'weapp', 'pc', 'app', 'hwapp'];
+ if (!in_array($app_type, $app_type_array)) {
+ return '';
+ }
+ if ($pay_status == 0) {
+ return '';
+ }
+ }
+ $info = array (
+ "pay_type" => "wechatpay",
+ "pay_type_name" => "微信支付",
+ "edit_url" => "wechatpay://shop/pay/config",
+ "shop_url" => "wechatpay://shop/pay/config",
+ "logo" => "addon/wechatpay/icon.png",
+ "desc" => "微信支付,用户通过扫描二维码、微信内打开商品页面购买等多种方式调起微信支付模块完成支付。",
+ "pay_status" => $pay_status,
+ );
+ return $info;
+
+ }
}
\ No newline at end of file
diff --git a/src/addon/wechatpay/event/TransferType.php b/src/addon/wechatpay/event/TransferType.php
index 29fd7394f..a78504efc 100644
--- a/src/addon/wechatpay/event/TransferType.php
+++ b/src/addon/wechatpay/event/TransferType.php
@@ -1,43 +1,35 @@
-app_type;
- if (!in_array($app_type, $app_type_array)) {
- return '';
- }
- $config_result = $config_model->getPayConfig($params[ 'site_id' ]);
- $config = $config_result[ "data" ][ "value" ] ?? [];
- $transfer_status = $config[ "transfer_status" ] ?? 0;
- if ($transfer_status == 0) {
- return '';
- }
- }
- $info = array (
- "type" => "wechatpay",
- "type_name" => "微信零钱",
- );
- return $info;
-
- }
+app_type;
+ if (!in_array($app_type, $app_type_array)) {
+ return '';
+ }
+ $config_result = $config_model->getPayConfig($params[ 'site_id' ]);
+ $config = $config_result[ "data" ][ "value" ] ?? [];
+ $transfer_status = $config[ "transfer_status" ] ?? 0;
+ if ($transfer_status == 0) {
+ return '';
+ }
+ }
+ $info = array (
+ "type" => "wechatpay",
+ "type_name" => "微信零钱",
+ );
+ return $info;
+
+ }
}
\ No newline at end of file
diff --git a/src/addon/wechatpay/event/UnInstall.php b/src/addon/wechatpay/event/UnInstall.php
index ab516d34e..e2fac841d 100644
--- a/src/addon/wechatpay/event/UnInstall.php
+++ b/src/addon/wechatpay/event/UnInstall.php
@@ -1,25 +1,17 @@
-getPayConfig($site_id)[ 'data' ][ 'value' ];
-
- // 检测数据是否发生变化,如果没有变化,则保持未加密前的数据
- if (!empty($data[ 'pay_signkey' ]) && $data[ 'pay_signkey' ] == $this->encrypt) {
- $data[ 'pay_signkey' ] = $original_config[ 'pay_signkey' ]; // APIv2密钥
- }
- if (!empty($data[ 'apiclient_cert' ]) && $data[ 'apiclient_cert' ] == $this->encrypt) {
- $data[ 'apiclient_cert' ] = $original_config[ 'apiclient_cert' ]; // 支付证书cert
- }
- if (!empty($data[ 'apiclient_key' ]) && $data[ 'apiclient_key' ] == $this->encrypt) {
- $data[ 'apiclient_key' ] = $original_config[ 'apiclient_key' ]; // 支付证书key
- }
- if (!empty($data[ 'plateform_cert' ]) && $data[ 'plateform_cert' ] == $this->encrypt) {
- $data[ 'plateform_cert' ] = $original_config[ 'plateform_cert' ]; // 平台证书
- }
- if (!empty($data[ 'v3_pay_signkey' ]) && $data[ 'v3_pay_signkey' ] == $this->encrypt) {
- $data[ 'v3_pay_signkey' ] = $original_config[ 'v3_pay_signkey' ]; // APIv3密钥
- }
-
- $res = $config->setConfig($data, '微信支付配置', 1, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'WECHAT_PAY_CONFIG' ] ]);
- return $res;
- }
-
- /**
- * 获取支付配置
- * @param int $site_id
- * @param string $app_module
- * @param bool $need_encrypt 是否需要加密数据,true:加密、false:不加密
- * @return array
- */
- public function getPayConfig($site_id = 0, $app_module = 'shop', $need_encrypt = false)
- {
- $config = new ConfigModel();
- $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'WECHAT_PAY_CONFIG' ] ]);
- if (!empty($res[ 'data' ][ 'value' ])) {
- $res[ 'data' ][ 'value' ][ 'api_type' ] = $res[ 'data' ][ 'value' ][ 'api_type' ] ?? 'v2';
- $res[ 'data' ][ 'value' ][ 'transfer_type' ] = $res[ 'data' ][ 'value' ][ 'transfer_type' ] ?? 'v2';
- }
- if ($need_encrypt) {
- // 加密敏感信息
- if (!empty($res[ 'data' ][ 'value' ][ 'pay_signkey' ])) {
- $res[ 'data' ][ 'value' ][ 'pay_signkey' ] = $this->encrypt; // APIv2密钥
- }
-
- if (!empty($res[ 'data' ][ 'value' ][ 'apiclient_cert' ])) {
- $res[ 'data' ][ 'value' ][ 'apiclient_cert' ] = $this->encrypt; // 支付证书cert
- }
-
- if (!empty($res[ 'data' ][ 'value' ][ 'apiclient_key' ])) {
- $res[ 'data' ][ 'value' ][ 'apiclient_key' ] = $this->encrypt; // 支付证书key
- }
-
- if (!empty($res[ 'data' ][ 'value' ][ 'plateform_cert' ])) {
- $res[ 'data' ][ 'value' ][ 'plateform_cert' ] = $this->encrypt; // 平台证书
- }
-
- if (!empty($res[ 'data' ][ 'value' ][ 'v3_pay_signkey' ])) {
- $res[ 'data' ][ 'value' ][ 'v3_pay_signkey' ] = $this->encrypt; // APIv3密钥
- }
- }
- return $res;
- }
+getPayConfig($site_id)['data']['value'];
+
+ // 检测数据是否发生变化,如果没有变化,则保持未加密前的数据
+ if (!empty($data['pay_signkey']) && $data['pay_signkey'] == $this->encrypt) {
+ $data['pay_signkey'] = $original_config['pay_signkey']; // APIv2密钥
+ }
+ if (!empty($data['apiclient_cert']) && $data['apiclient_cert'] == $this->encrypt) {
+ $data['apiclient_cert'] = $original_config['apiclient_cert']; // 支付证书cert
+ }
+ if (!empty($data['apiclient_key']) && $data['apiclient_key'] == $this->encrypt) {
+ $data['apiclient_key'] = $original_config['apiclient_key']; // 支付证书key
+ }
+ if (!empty($data['plateform_cert']) && $data['plateform_cert'] == $this->encrypt) {
+ $data['plateform_cert'] = $original_config['plateform_cert']; // 平台证书 生成的
+ }
+ if (!empty($data['plateform_certificate']) && $data['plateform_certificate'] == $this->encrypt) {
+ $data['plateform_certificate'] = $original_config['plateform_certificate']; // 平台证书 主动上传的
+ }
+ if (!empty($data['plateform_certificate_serial']) && $data['plateform_certificate_serial'] == $this->encrypt) {
+ $data['plateform_certificate_serial'] = $original_config['plateform_certificate_serial']; // 平台证书序列号
+ }
+ if (!empty($data['v3_pay_signkey']) && $data['v3_pay_signkey'] == $this->encrypt) {
+ $data['v3_pay_signkey'] = $original_config['v3_pay_signkey']; // APIv3密钥
+ }
+
+ if(!($data['transfer_status'] == 1 && $data['transfer_type'] == 'v3' && $data['transfer_v3_type'] == self::TRANSFER_V3_TYPE_USER)){
+ $data['member_transfer_scene'] = '';
+ $data['store_transfer_scene'] = '';
+ $data['fenxiao_transfer_scene'] = '';
+ $data['member_transfer_code'] = '';
+ $data['store_transfer_code'] = '';
+ $data['fenxiao_transfer_code'] = '';
+ $data['member_transfer_info'] = [];
+ $data['fenxiao_transfer_info'] = [];
+ $data['store_transfer_info'] = [];
+ $data['member_transfer_recv'] = '';
+ $data['store_transfer_recv'] = '';
+ $data['fenxiao_transfer_recv'] = '';
+ }
+
+ $res = $config->setConfig($data, '微信支付配置', 1, [['site_id', '=', $site_id], ['app_module', '=', $app_module], ['config_key', '=', 'WECHAT_PAY_CONFIG']]);
+ return $res;
+ }
+
+ /**
+ * 获取支付配置
+ * @param int $site_id
+ * @param string $app_module
+ * @param bool $need_encrypt 是否需要加密数据,true:加密、false:不加密
+ * @return array
+ */
+ public function getPayConfig($site_id = 0, $app_module = 'shop', $need_encrypt = false)
+ {
+ $config = new ConfigModel();
+ $res = $config->getConfig([['site_id', '=', $site_id], ['app_module', '=', $app_module], ['config_key', '=', 'WECHAT_PAY_CONFIG']]);
+
+ //旧定义字段变为新定义字段
+ $res['data']['value'] = json_encode($res['data']['value']);
+ $res['data']['value'] = str_replace('member_transfer', 'member_withdraw', $res['data']['value']);
+ $res['data']['value'] = str_replace('store_transfer', 'store_withdraw', $res['data']['value']);
+ $res['data']['value'] = str_replace('fenxiao_transfer', 'fenxiao_withdraw', $res['data']['value']);
+ $res['data']['value'] = json_decode($res['data']['value'], true);
+
+ $res['data']['value'] = array_merge([
+ "appid" => '',
+ "mch_id" => '',
+ "pay_signkey" => '',
+ "apiclient_cert" => '',
+ "apiclient_key" => '',
+ "refund_status" => 0,
+ "pay_status" => 0,
+ "transfer_status" => 0,
+ 'transfer_type' => 'v2',
+ 'plateform_cert' => '',
+ 'plateform_certificate' => '',
+ 'plateform_certificate_serial' => '',
+ 'api_type' => 'v2',
+ 'v3_pay_signkey' => '',
+ 'transfer_v3_type'=>'1',//旧版1 新版2
+ 'member_withdraw_scene'=>'',
+ 'store_withdraw_scene'=>'',
+ 'fenxiao_withdraw_scene'=>'',
+ 'member_withdraw_code'=>'',
+ 'store_withdraw_code'=>'',
+ 'fenxiao_withdraw_code'=>'',
+ 'member_withdraw_info' => [],
+ 'fenxiao_withdraw_info'=> [],
+ 'store_withdraw_info' => [],
+ 'member_withdraw_recv'=>'',
+ 'store_withdraw_recv'=>'',
+ 'fenxiao_withdraw_recv'=>'',
+ ], $res['data']['value']);
+
+ // 加密敏感信息
+ if (!empty($res['data']['value']) && $need_encrypt) {
+
+ if (!empty($res['data']['value']['pay_signkey'])) {
+ $res['data']['value']['pay_signkey'] = $this->encrypt; // APIv2密钥
+ }
+ if (!empty($res['data']['value']['apiclient_cert'])) {
+ $res['data']['value']['apiclient_cert'] = $this->encrypt; // 支付证书cert
+ }
+ if (!empty($res['data']['value']['apiclient_key'])) {
+ $res['data']['value']['apiclient_key'] = $this->encrypt; // 支付证书key
+ }
+ if (!empty($res['data']['value']['plateform_cert'])) {
+ $res['data']['value']['plateform_cert'] = $this->encrypt; // 平台证书 通过接口获取和生成的
+ }
+ if (!empty($res['data']['value']['plateform_certificate'])) {
+ $res['data']['value']['plateform_certificate'] = $this->encrypt; // 平台证书,直接上传的
+ }
+ if (!empty($res['data']['value']['plateform_certificate_serial'])) {
+ $res['data']['value']['plateform_certificate_serial'] = $this->encrypt; // 平台证书ID
+ }
+ if (!empty($res['data']['value']['v3_pay_signkey'])) {
+ $res['data']['value']['v3_pay_signkey'] = $this->encrypt; // APIv3密钥
+ }
+ }
+ return $res;
+ }
+
+ CONST TRANSFER_V3_TYPE_SHOP = 1; //商户转账
+ CONST TRANSFER_V3_TYPE_USER = 2; //会员收款
+
+ public function getTransferSceneConfig()
+ {
+ $config = [
+ [
+ 'num'=>1,
+ 'title' => '现金营销',
+ 'infos' => [
+ [
+ 'info_type' => '活动名称',
+ 'info_content' => ''
+ ],
+ [
+ 'info_type' => '奖励说明',
+ 'info_content' => '',
+ ],
+ ],
+ 'user_recv'=>[
+ '活动奖励',
+ '现金奖励'
+ ]
+ ],
+ [
+ 'num'=>2,
+ 'title' => '企业赔付',
+ 'infos' => [
+ [
+ 'info_type' => '赔付原因',
+ 'info_content' => ''
+ ],
+ ],
+ 'user_recv'=>[
+ '退款',
+ '商家赔付'
+ ]
+ ],
+ [
+ 'num'=>3,
+ 'title' => '佣金报酬',
+ 'infos' => [
+ [
+ 'info_type' => '岗位类型',
+ 'info_content' => ''
+ ],
+ [
+ 'info_type' => '报酬说明',
+ 'info_content' => '',
+ ],
+ ],
+ 'user_recv'=>[
+ '劳务报酬',
+ '报销款',
+ '企业补贴',
+ '开工利是',
+ ]
+ ],
+ [
+ 'num'=>4,
+ 'title' => '采购货款',
+ 'infos' => [
+ [
+ 'info_type' => '采购商品名称',
+ 'info_content' => ''
+ ],
+ ],
+ 'user_recv'=>[
+ '货款',
+ ]
+ ],
+ [
+ 'num'=>5,
+ 'title' => '二手回收',
+ 'infos' => [
+ [
+ 'info_type' => '回收商品名称',
+ 'info_content' => ''
+ ],
+ ],
+ 'user_recv'=>[
+ '二手回收货款',
+ ]
+ ],
+ [
+ 'num'=>6,
+ 'title' => '公益补助',
+ 'infos' => [
+ [
+ 'info_type' => '公益活动名称',
+ 'info_content' => ''
+ ],
+ [
+ 'info_type' => '公益活动备案编号',
+ 'info_content' => ''
+ ],
+ ],
+ 'user_recv'=>[
+ '公益补助金',
+ ]
+ ],
+ [
+ 'num'=>7,
+ 'title' => '行政补贴',
+ 'infos' => [
+ [
+ 'info_type' => '补贴类型',
+ 'info_content' => ''
+ ],
+ ],
+ 'user_recv'=>[
+ '行政补贴',
+ '行政奖励',
+ ]
+ ],
+ [
+ 'num'=>8,
+ 'title' => '保险理赔',
+ 'infos' => [
+ [
+ 'info_type' => '保险产品备案编号',
+ 'info_content' => ''
+ ],
+ [
+ 'info_type' => '保险名称',
+ 'info_content' => ''
+ ],
+ [
+ 'info_type' => '保险操作单号',
+ 'info_content' => ''
+ ],
+ ],
+ 'user_recv'=>[
+ '保险理赔款',
+ ]
+ ]
+ ];
+
+ $data = [];
+ foreach ($config as $k=>$v){
+ $data[$v['num']] = $v;
+ }
+ return $data;
+ }
+
+
+ public function getTransferSceneInfo($param){
+
+ $data = [
+ 'member_withdraw_info'=>[],
+ 'fenxiao_withdraw_info'=>[],
+ 'store_withdraw_info'=>[]
+ ];
+ if(!isset($param['transfer_v3_type']) || $param['transfer_v3_type'] !=2){
+ return $data;
+ }
+ $config = $this->getTransferSceneConfig();
+ //会员提现场景
+ if(!empty($param['member_withdraw_scene'])){
+ foreach($config[$param['member_withdraw_scene']]['infos'] as $k=>$v){
+ $v['info_content'] = $param['member_withdraw_'.$k] ?? '';
+ $data['member_withdraw_info'][$k] = $v;
+ }
+ }
+
+ //分销提现场景
+ if(!empty($param['fenxiao_withdraw_scene'])){
+ foreach($config[$param['fenxiao_withdraw_scene']]['infos'] as $k=>$v){
+ $v['info_content'] = $param['fenxiao_withdraw_'.$k] ?? '';
+ $data['fenxiao_withdraw_info'][$k] = $v;
+ }
+ }
+
+ //店铺提现场景
+ if(!empty($param['store_withdraw_scene'])){
+ foreach($config[$param['store_withdraw_scene']]['infos'] as $k=>$v){
+ $v['info_content'] = $param['store_withdraw_'.$k] ?? '';
+ $data['store_withdraw_info'][$k] = $v;
+ }
+ }
+ return $data;
+ }
}
\ No newline at end of file
diff --git a/src/addon/wechatpay/model/Pay.php b/src/addon/wechatpay/model/Pay.php
index 4313a2f78..5c36bc0d9 100644
--- a/src/addon/wechatpay/model/Pay.php
+++ b/src/addon/wechatpay/model/Pay.php
@@ -1,327 +1,380 @@
-is_weapp = $is_weapp;
- $this->site_id = $site_id;
-
- // 支付配置
- $config_model = new Config();
- $this->config = $config_model->getPayConfig($site_id)[ 'data' ][ 'value' ];
- if (empty($this->config)) throw new ApiException(-1, "平台未配置微信支付");
-
- $this->api = $this->config[ 'api_type' ];
- $this->config[ 'site_id' ] = $site_id;
- $is_weapp = 1;//add lucky 默认测试
- if ($is_weapp == 0) {
- $wechat_config = ( new WechatConfig() )->getWechatConfig($this->site_id)[ 'data' ][ 'value' ];
- $this->config[ 'appid' ] = $wechat_config[ 'appid' ] ?? '';
- } else {
- $weapp_config = ( new WeappConfig() )->getWeappConfig($this->site_id)[ 'data' ][ 'value' ];
- $this->config[ 'appid' ] = $weapp_config[ 'appid' ] ?? '';
- }
- $this->factory();
- }
-
- /**
- * 实例化支付接口
- */
- public function factory()
- {
- $class = 'addon\\wechatpay\\model\\' . ucfirst($this->api);
- if (!class_exists($class)) throw new ApiException(-1, "Class '{$class}' not found");
-
- try {
- $this->app = new $class($this->config);
- } catch (\Exception $e) {
- Log::write('微信支付配置错误:' . $e->getMessage() . $e->getFile() . $e->getLine());
- throw new ApiException(-1, "微信支付配置错误");
- }
- }
-
- /**
- * 生成支付
- * @param $param
- */
- public function pay($param)
- {
- if (!$this->config[ 'pay_status' ]) return $this->error([], '平台未启用微信支付');
-
- ///绑定商户数据
- $pay_model = new PayModel();
- $pay_model->bindMchPay($param[ "out_trade_no" ], [ "app_id" => $this->config[ "appid" ] ]);
-
- if ($param[ 'trade_type' ] == 'JSAPI' || $param[ 'trade_type' ] == 'APPLET') {
- $member_info = model('member')->getInfo([ [ "member_id", "=", $param[ "member_id" ] ] ], 'weapp_openid,wx_openid');
- if (empty($member_info)) return $this->error(-1, '未获取到会员信息');
- $param[ 'openid' ] = $this->is_weapp ? $member_info[ 'weapp_openid' ] : $member_info[ 'wx_openid' ];
- }
-
- try {
- $result = $this->app->pay($param);
- file_put_contents(__DIR__ . '/debug.txt', var_export($result,true));
- // 对视频号订单做处理
- if ($result[ 'code' ] == 0 && in_array($param[ 'scene' ], [ 1175, 1176, 1177, 1191, 1195 ])) {
- $weapp_model = new Weapp($param[ 'site_id' ]);
- $prepay_id = str_replace('prepay_id=', '', $result[ 'data' ][ 'data' ][ 'package' ]);
- $order_info = $this->getOrderInfo($param[ "out_trade_no" ], $param[ 'openid' ], $prepay_id, $param[ 'scene' ]);
- $res = $weapp_model->createOrder($order_info);
- if ($res[ 'code' ] >= 0) {
- $order_params = [
- "order_id" => $res[ 'data' ][ 'data' ][ 'order_id' ],
- "out_order_id" => $res[ 'data' ][ 'data' ][ 'out_order_id' ],
- "openid" => $param[ "openid" ]
- ];
- $config = $weapp_model->getPaymentParams($order_params);
- $result = $this->success([
- 'type' => 'jsapi',
- 'data' => $config[ 'data' ][ 'payment_params' ]
- ]);
- }
- }
- return $result;
- } catch (\Exception $e) {
- Log::write('微信支付接口调用失败,请求参数:' . json_encode($param) . ' 错误原因:' . $e->getMessage() . $e->getFile() . $e->getLine());
- return $this->error([], '微信支付接口调用失败');
- }
- }
-
- /**
- * 支付异步通知
- * @return mixed
- */
- public function payNotify()
- {
- return $this->app->payNotify();
- }
-
- /**
- * 关闭支付
- * @param $param
- * @return array
- */
- public function close($param)
- {
- try {
- return $this->app->payClose($param);
- } catch (\Exception $e) {
- Log::write('微信订单关闭失败,请求参数:' . json_encode($param) . ' 错误原因:' . $e->getMessage() . $e->getFile() . $e->getLine());
- return $this->error([], '微信订单关闭失败');
- }
- }
-
- /**
- * 微信原路退款
- * @param $param
- * @return array
- */
- public function refund($param)
- {
- if (!$this->config[ 'refund_status' ]) return $this->error([], '平台未启用微信退款');
-
- try {
- $mch_info = empty($param[ "pay_info" ][ 'mch_info' ]) ? [] : json_decode($param[ "pay_info" ][ 'mch_info' ], true);
- $this->config[ "appid" ] = $mch_info[ "app_id" ] ?? $this->config[ "appid" ];//替换为商户自己的appid
- $this->factory();
-
- return $this->app->refund($param);
- } catch (\Exception $e) {
- Log::write('微信退款失败,请求参数:' . json_encode($param) . ' 错误原因:' . $e->getMessage() . $e->getFile() . $e->getLine());
- return $this->error([], '微信退款失败');
- }
- }
-
- /**
- * 微信转账到零钱
- * @param array $param
- * @return array
- * @throws ApiException
- */
- public function transfer(array $param)
- {
- if (!$this->config[ 'transfer_status' ]) return $this->error([], '平台未启用微信转账');
-
- if ($this->api != $this->config[ 'transfer_type' ]) {
- $this->api = $this->config[ 'transfer_type' ];
- $this->factory();
- }
-
- try {
- $result = $this->app->transfer($param);
- if ($result[ 'code' ] == 0 && $this->api == 'v3') {
- ( new Cron() )->addCron(1, 0, "查询转账结果", "TransferResult", ( time() + 10 ), $param[ 'id' ]);
- }
- return $result;
- } catch (\Exception $e) {
- Log::write('微信转账接口调用失败,错误原因:' . $e->getMessage() . $e->getFile() . $e->getLine());
- return $this->error([], '微信转账接口调用失败');
- }
- }
-
- /**
- * 获取支付所需订单信息
- * @param $out_trade_no
- * @param $openid
- * @param $prepay_id
- * @param int $scene
- * @return array
- */
- private function getOrderInfo($out_trade_no, $openid, $prepay_id, $scene = 0)
- {
- $order_info = model('order')->getInfo([ [ 'out_trade_no', '=', $out_trade_no ] ], 'site_id,create_time,order_id,order_type,member_id,order_money,delivery_money,name,full_address,mobile,delivery_store_info,delivery_store_name');
- $data = [
- 'create_time' => date("Y-m-d H:i:s", $order_info[ 'create_time' ]),
- 'out_order_id' => $order_info[ 'order_id' ],
- 'openid' => $openid,
- 'path' => ( new OrderMessage() )->handleUrl($order_info[ 'order_type' ], $order_info[ 'order_id' ]),
- 'out_user_id' => $order_info[ 'member_id' ],
- 'order_detail' => [
- 'product_infos' => [],
- 'pay_info' => [
- 'pay_method' => '微信支付',
- 'prepay_id' => $prepay_id,
- 'prepay_time' => date('Y-m-d H:i:s', time())
- ],
- 'price_info' => [
- 'order_price' => $order_info[ 'order_money' ] * 100,
- 'freight' => $order_info[ 'delivery_money' ] * 100,
- 'discounted_price' => 0,
- 'additional_price' => 0
- ]
- ],
- 'delivery_detail' => [],
- 'fund_type' => 1,
- 'expire_time' => time() + 3600
- ];
- // 配送方式
- switch ( $order_info[ 'order_type' ] ) {
- case 2:
- $delivery_store_info = json_decode($order_info[ 'delivery_store_info' ], true);
- $data[ 'delivery_detail' ][ 'delivery_type' ] = 4; //用户自提
- $data[ 'address_info' ] = [
- 'receiver_name' => $order_info[ 'delivery_store_name' ],
- 'detailed_address' => $delivery_store_info[ 'full_address' ],
- 'tel_number' => $delivery_store_info[ 'telphone' ]
- ];
- break;
- case 3:
- $data[ 'delivery_detail' ][ 'delivery_type' ] = 3; //线下配送
- break;
- case 4:
- $data[ 'delivery_detail' ][ 'delivery_type' ] = 2; //无需快递
- break;
- default:
- $data[ 'delivery_detail' ][ 'delivery_type' ] = 1; //正常快递
- $data[ 'address_info' ] = [
- 'receiver_name' => $order_info[ 'name' ],
- 'detailed_address' => $order_info[ 'full_address' ],
- 'tel_number' => $order_info[ 'mobile' ]
- ];
- break;
- }
- $order_goods = model('order_goods')->getList([ [ 'order_id', '=', $order_info[ 'order_id' ] ] ], 'goods_id,sku_id,num,price,sku_name,sku_image');
- foreach ($order_goods as $goods) {
- $data['order_detail']['product_infos'][] = [
- 'out_product_id' => $goods['goods_id'],
- 'out_sku_id' => $goods['sku_id'],
- 'product_cnt' => numberFormat($goods['num']),
- 'sale_price' => $goods['price'] * 100,
- 'path' => 'pages/goods/detail?sku_id=' . $goods['sku_id'],
- 'title' => $goods['sku_name'],
- 'head_img' => img($goods['sku_image']),
- 'sku_real_price' => $goods['price'] * 100
- ];
- }
- $video_number_scene = [ 1175, 1176, 1177, 1191, 1195 ]; // 视频号场景值
- if (in_array($scene, $video_number_scene)) model('order')->update([ 'is_video_number' => 1 ], [ [ 'order_id', '=', $order_info[ 'order_id' ] ] ]);
- return $data;
- }
-
-
- /**
- * 付款码支付
- * @param $param
- * @return array|mixed|void
- * @throws ApiException
- */
- public function micropay($param)
- {
- if (!$this->config[ 'pay_status' ]) return $this->error([], '平台未启用微信支付');
-
- if ($this->api != 'v2') {
- $this->api = 'v2';
- $this->factory();
- }
-
- try {
- $res = $this->app->micropay($param);
- if ($res[ 'code' ] != 0) return $res;
-
- $pay_model = new PayModel();
- $pay_model->bindMchPay($param[ "out_trade_no" ], [ "app_id" => $this->config[ "appid" ] ]);
-
- $res = $pay_model->onlinePay($param[ 'out_trade_no' ], 'wechatpay', $res[ 'data' ][ 'transaction_id' ], 'wechatpay');
-
- return $res;
- } catch (\Exception $e) {
- Log::write('微信付款码支付失败,请求参数:' . json_encode($param) . ' 错误原因:' . $e->getMessage() . $e->getFile() . $e->getLine());
- return $this->error([], '微信付款码支付失败');
- }
- }
+is_weapp = $is_weapp;
+ $this->site_id = $site_id;
+
+ // 支付配置
+ $config_model = new Config();
+ $this->config = $config_model->getPayConfig($site_id)[ 'data' ][ 'value' ];
+ if (empty($this->config)) throw new ApiException(-1, "平台未配置微信支付");
+
+ $this->api = $this->config[ 'api_type' ];
+ $this->config[ 'site_id' ] = $site_id;
+
+ if ($is_weapp == 0) {
+ $wechat_config = ( new WechatConfig() )->getWechatConfig($this->site_id)[ 'data' ][ 'value' ];
+ $this->config[ 'appid' ] = $wechat_config[ 'appid' ] ?? '';
+ } else {
+ $weapp_config = ( new WeappConfig() )->getWeappConfig($this->site_id)[ 'data' ][ 'value' ];
+ $this->config[ 'appid' ] = $weapp_config[ 'appid' ] ?? '';
+ }
+
+ $this->factory();
+ }
+
+ /**
+ * 实例化支付接口
+ */
+ public function factory()
+ {
+ $class = 'addon\\wechatpay\\model\\' . ucfirst($this->api);
+ if (!class_exists($class)) throw new ApiException(-1, "Class '{$class}' not found");
+
+ try {
+ $this->app = new $class($this->config);
+ } catch (\Exception $e) {
+ Log::write('微信支付配置错误:' . $e->getMessage() . $e->getFile() . $e->getLine());
+ throw new ApiException(-1, "微信支付配置错误");
+ }
+ }
+
+ /**
+ *
+ * 生成支付
+ * @param $param
+ */
+ public function pay($param)
+ {
+ if (!$this->config[ 'pay_status' ]) return $this->error([], '平台未启用微信支付');
+
+ //清除绑定支付数据
+ $pay_model = new PayModel();
+ $clear_res = $pay_model->clearMchPay($param[ "out_trade_no" ], 'wechatpay');
+ if($clear_res['code'] < 0) return $clear_res;
+
+ if ($param[ 'trade_type' ] == 'JSAPI' || $param[ 'trade_type' ] == 'APPLET') {
+ $member_info = model('member')->getInfo([ [ "member_id", "=", $param[ "member_id" ] ] ], 'weapp_openid,wx_openid');
+ if (empty($member_info)) return $this->error(-1, '未获取到会员信息');
+ $param[ 'openid' ] = $this->is_weapp ? $member_info[ 'weapp_openid' ] : $member_info[ 'wx_openid' ];
+ }
+
+ try {
+ $result = $this->app->pay($param);
+
+ //绑定支付数据
+ if($result['code'] >= 0){
+ $pay_model->bindMchPay($param[ "out_trade_no" ], [
+ "pay_type" => 'wechatpay',
+ "is_weapp" => $this->is_weapp,
+ "app_id" => $this->config[ "appid" ],
+ ]);
+ }
+
+ // 对视频号订单做处理
+ if ($result[ 'code' ] == 0 && in_array($param[ 'scene' ], [ 1175, 1176, 1177, 1191, 1195 ])) {
+ $weapp_model = new Weapp($param[ 'site_id' ]);
+ $prepay_id = str_replace('prepay_id=', '', $result[ 'data' ][ 'data' ][ 'package' ]);
+ $order_info = $this->getOrderInfo($param[ "out_trade_no" ], $param[ 'openid' ], $prepay_id, $param[ 'scene' ]);
+ $res = $weapp_model->createOrder($order_info);
+ if ($res[ 'code' ] >= 0) {
+ $order_params = [
+ "order_id" => $res[ 'data' ][ 'data' ][ 'order_id' ],
+ "out_order_id" => $res[ 'data' ][ 'data' ][ 'out_order_id' ],
+ "openid" => $param[ "openid" ]
+ ];
+ $config = $weapp_model->getPaymentParams($order_params);
+ $result = $this->success([
+ 'type' => 'jsapi',
+ 'data' => $config[ 'data' ][ 'payment_params' ]
+ ]);
+ }
+ }
+ return $result;
+ } catch (\Exception $e) {
+ Log::write('微信支付接口调用失败,请求参数:' . json_encode($param) . ' 错误原因:' . $e->getMessage() . $e->getFile() . $e->getLine());
+ return $this->error([], '微信支付接口调用失败');
+ }
+ }
+
+ /**
+ * 支付异步通知
+ * @return mixed
+ */
+ public function payNotify()
+ {
+ return $this->app->payNotify();
+ }
+
+ /**
+ * 关闭支付
+ * @param $param
+ * @return array
+ */
+ public function close($param)
+ {
+ try {
+ return $this->app->payClose($param);
+ } catch (\Exception $e) {
+ Log::write('微信订单关闭失败,请求参数:' . json_encode($param) . ' 错误原因:' . $e->getMessage() . $e->getFile() . $e->getLine());
+ return $this->error([], '微信订单关闭失败');
+ }
+ }
+
+ /**
+ * 微信原路退款
+ * @param $param
+ * @return array
+ */
+ public function refund($param)
+ {
+ if (!$this->config[ 'refund_status' ]) return $this->error([], '平台未启用微信退款');
+
+ try {
+ $mch_info = empty($param[ "pay_info" ][ 'mch_info' ]) ? [] : json_decode($param[ "pay_info" ][ 'mch_info' ], true);
+ $this->config[ "appid" ] = $mch_info[ "app_id" ] ?? $this->config[ "appid" ];//替换为商户自己的appid
+ $this->factory();
+
+ return $this->app->refund($param);
+ } catch (\Exception $e) {
+ Log::write('微信退款失败,请求参数:' . json_encode($param) . ' 错误原因:' . $e->getMessage() . $e->getFile() . $e->getLine());
+ return $this->error(['file' => $e->getFile(),'line'=>$e->getLine(),'message'=>$e->getMessage()], '微信退款失败');
+ }
+ }
+
+ /**
+ * 微信转账到零钱
+ * @param array $param
+ * @return array
+ * @throws ApiException
+ */
+ public function transfer(array $param)
+ {
+ if (!$this->config[ 'transfer_status' ]) return $this->error([], '平台未启用微信转账');
+ if ($this->api != $this->config[ 'transfer_type' ]) {
+ $this->api = $this->config[ 'transfer_type' ];
+ $this->factory();
+ }
+ try {
+ $result = $this->app->transfer($param);
+ return $result;
+ } catch (\Exception $e) {
+ Log::write('微信转账接口调用失败,错误原因:' . $e->getMessage() . $e->getFile() . $e->getLine());
+ return $this->error([], '微信转账接口调用失败');
+ }
+ }
+
+ /**
+ * 获取支付所需订单信息
+ * @param $out_trade_no
+ * @param $openid
+ * @param $prepay_id
+ * @param int $scene
+ * @return array
+ */
+ private function getOrderInfo($out_trade_no, $openid, $prepay_id, $scene = 0)
+ {
+ $order_info = model('order')->getInfo([ [ 'out_trade_no', '=', $out_trade_no ] ], 'site_id,create_time,order_id,order_type,member_id,order_money,delivery_money,name,full_address,mobile,delivery_store_info,delivery_store_name');
+ $data = [
+ 'create_time' => date("Y-m-d H:i:s", $order_info[ 'create_time' ]),
+ 'out_order_id' => $order_info[ 'order_id' ],
+ 'openid' => $openid,
+ 'path' => ( new OrderMessage() )->handleUrl($order_info[ 'order_type' ], $order_info[ 'order_id' ]),
+ 'out_user_id' => $order_info[ 'member_id' ],
+ 'order_detail' => [
+ 'product_infos' => [],
+ 'pay_info' => [
+ 'pay_method' => '微信支付',
+ 'prepay_id' => $prepay_id,
+ 'prepay_time' => date('Y-m-d H:i:s', time())
+ ],
+ 'price_info' => [
+ 'order_price' => $order_info[ 'order_money' ] * 100,
+ 'freight' => $order_info[ 'delivery_money' ] * 100,
+ 'discounted_price' => 0,
+ 'additional_price' => 0
+ ]
+ ],
+ 'delivery_detail' => [],
+ 'fund_type' => 1,
+ 'expire_time' => time() + 3600
+ ];
+ // 配送方式
+ switch ( $order_info[ 'order_type' ] ) {
+ case 2:
+ $delivery_store_info = json_decode($order_info[ 'delivery_store_info' ], true);
+ $data[ 'delivery_detail' ][ 'delivery_type' ] = 4; //用户自提
+ $data[ 'address_info' ] = [
+ 'receiver_name' => $order_info[ 'delivery_store_name' ],
+ 'detailed_address' => $delivery_store_info[ 'full_address' ],
+ 'tel_number' => $delivery_store_info[ 'telphone' ]
+ ];
+ break;
+ case 3:
+ $data[ 'delivery_detail' ][ 'delivery_type' ] = 3; //线下配送
+ break;
+ case 4:
+ $data[ 'delivery_detail' ][ 'delivery_type' ] = 2; //无需快递
+ break;
+ default:
+ $data[ 'delivery_detail' ][ 'delivery_type' ] = 1; //正常快递
+ $data[ 'address_info' ] = [
+ 'receiver_name' => $order_info[ 'name' ],
+ 'detailed_address' => $order_info[ 'full_address' ],
+ 'tel_number' => $order_info[ 'mobile' ]
+ ];
+ break;
+ }
+ $order_goods = model('order_goods')->getList([ [ 'order_id', '=', $order_info[ 'order_id' ] ] ], 'goods_id,sku_id,num,price,sku_name,sku_image');
+ foreach ($order_goods as $goods) {
+ $data['order_detail']['product_infos'][] = [
+ 'out_product_id' => $goods['goods_id'],
+ 'out_sku_id' => $goods['sku_id'],
+ 'product_cnt' => numberFormat($goods['num']),
+ 'sale_price' => $goods['price'] * 100,
+ 'path' => 'pages/goods/detail?sku_id=' . $goods['sku_id'],
+ 'title' => $goods['sku_name'],
+ 'head_img' => img($goods['sku_image']),
+ 'sku_real_price' => $goods['price'] * 100
+ ];
+ }
+ $video_number_scene = [ 1175, 1176, 1177, 1191, 1195 ]; // 视频号场景值
+ if (in_array($scene, $video_number_scene)) model('order')->update([ 'is_video_number' => 1 ], [ [ 'order_id', '=', $order_info[ 'order_id' ] ] ]);
+ return $data;
+ }
+
+
+ /**
+ * 付款码支付
+ * @param $param
+ * @return array|mixed|void
+ * @throws ApiException
+ */
+ public function micropay($param)
+ {
+ if (!$this->config[ 'pay_status' ]) return $this->error([], '平台未启用微信支付');
+
+ if ($this->api != 'v2') {
+ $this->api = 'v2';
+ $this->factory();
+ }
+
+ try {
+ $pay_model = new PayModel();
+
+ //清空绑定支付数据
+ $clear_res = $pay_model->clearMchPay($param[ "out_trade_no" ], 'wechatpay');
+ if($clear_res['code'] < 0) return $clear_res;
+ //绑定支付数据
+ $pay_model->bindMchPay($param[ "out_trade_no" ], [
+ "pay_type" => 'wechatpay',
+ "app_id" => $this->config[ "appid" ],
+ ]);
+
+ $res = $this->app->micropay($param);
+ if ($res[ 'code' ] != 0) {
+ if (isset($res['data']['err_code'])) {
+ if ($res['data']['err_code'] == 'TRADE_ERROR'){
+ (new PayModel())->edit(['pay_status' => PayModel::PAY_STATUS_CANCEL], ['out_trade_no' => $param[ "out_trade_no" ] ]);
+ }
+ }
+ return $res;
+ }
+ $res = $pay_model->onlinePay($param[ 'out_trade_no' ], 'wechatpay', $res[ 'data' ][ 'transaction_id' ], 'wechatpay');
+ return $res;
+ } catch (\Exception $e) {
+ Log::write('微信付款码支付失败,请求参数:' . json_encode($param) . ' 错误原因:' . $e->getMessage() . $e->getFile() . $e->getLine());
+ return $this->error([], '微信付款码支付失败');
+ }
+ }
+
+
+ /**
+ * 微信转账到零钱新版本回调
+ */
+ public function transferNotify()
+ {
+ if (!$this->config[ 'transfer_status' ]) return $this->error([], '平台未启用微信转账');
+ if ($this->api != $this->config[ 'transfer_type' ]) {
+ $this->api = $this->config[ 'transfer_type' ];
+ $this->factory();
+ }
+ try {
+ return $this->app->transferNotify();
+ } catch (\Exception $e) {
+ Log::write('微信转账接口回调处理失败,错误原因:' . $e->getMessage() . $e->getFile() . $e->getLine());
+ return $this->error([], '微信转账接口回调处理失败');
+ }
+ }
+
+
+ /**
+ * 撤销微信转账
+ * @param $out_bill_no 商户单号
+ * @return array
+ */
+
+ public function transferCancel($out_bill_no){
+
+ if (!$this->config[ 'transfer_status' ]) return $this->error([], '平台未启用微信转账');
+ if ($this->api != $this->config[ 'transfer_type' ]) {
+ $this->api = $this->config[ 'transfer_type' ];
+ $this->factory();
+ }
+ try {
+ return $this->app->transferCancel($out_bill_no);
+ } catch (\Exception $e) {
+ Log::write('微信转账接口回调处理失败,错误原因:' . $e->getMessage() . $e->getFile() . $e->getLine());
+ return $this->error([], '微信转账接口回调处理失败');
+ }
+ }
}
\ No newline at end of file
diff --git a/src/addon/wechatpay/model/V2.php b/src/addon/wechatpay/model/V2.php
index b8853192e..7973ee04f 100644
--- a/src/addon/wechatpay/model/V2.php
+++ b/src/addon/wechatpay/model/V2.php
@@ -146,16 +146,16 @@ class V2 extends BaseModel
*/
public function payClose(array $param)
{
- $result = $this->app->order->close($param[ "out_trade_no" ]);
-
- if ($result[ "return_code" ] == 'FAIL') {
- return $this->error([], $result[ "return_msg" ]);
+ $query_result = $this->app->order->queryByOutTradeNumber($param[ "out_trade_no" ]);
+ if($query_result['return_code'] == 'SUCCESS' && $query_result['result_code'] == 'SUCCESS' && $query_result['trade_state'] != 'CLOSED'){
+ if($query_result['trade_state'] == 'SUCCESS'){
+ return $this->error([ 'is_paid' => 1, 'pay_type' => 'wechatpay'], '微信已支付不可关闭');
+ }
+ $close_result = $this->app->order->close($param[ "out_trade_no" ]);
+ if($close_result['return_code'] != 'SUCCESS' || $close_result['result_code'] != 'SUCCESS'){
+ return $this->error($close_result, $close_result[ 'return_msg' ]);
+ }
}
- if ($result[ "result_code" ] == 'FAIL') {
- if ($result[ 'err_code' ] == 'ORDERPAID') return $this->error([ 'is_paid' => 1, 'pay_type' => 'wechatpay' ], $result[ 'err_code_des' ]);
- return $this->error([], $result[ 'err_code_des' ]);
- }
-
return $this->success();
}
@@ -193,7 +193,7 @@ class V2 extends BaseModel
'openid' => $param[ 'account_number' ],
'check_name' => 'FORCE_CHECK', // NO_CHECK:不校验真实姓名, FORCE_CHECK:强校验真实姓名
're_user_name' => $param[ 'real_name' ], // 如果 check_name 设置为FORCE_CHECK,则必填用户真实姓名
- 'amount' => $param[ 'amount' ] * 100, // 转账金额
+ 'amount' => round($param[ 'amount' ] * 100, 2), // 转账金额
'desc' => $param[ 'desc' ]
];
$res = $this->app->transfer->toBalance($data);
@@ -233,10 +233,10 @@ class V2 extends BaseModel
return $this->error([], $result[ 'return_msg' ]);
}
if ($result[ 'result_code' ] == 'FAIL') {
- if ($result[ 'err_code' ] == 'USERPAYING') {
+ if ($result[ 'err_code' ] != 'USERPAYING') {
( new Cron() )->addCron(1, 0, "查询付款码支付结果", "PayOrderQuery", time() + 3, $param[ 'id' ]);
}
- return $this->error([], $result[ 'err_code_des' ]);
+ return $this->error($result, $result[ 'err_code_des' ]);
}
return $this->success($result);
@@ -258,9 +258,13 @@ class V2 extends BaseModel
}
if ($result[ 'result_code' ] == 'SUCCESS') {
if ($result[ 'trade_state' ] == 'SUCCESS') {
- $res = ( new PayCommon() )->onlinePay($pay_info[ 'out_trade_no' ], 'wechatpay', $result[ 'transaction_id' ], 'wechatpay');
+ ( new PayCommon() )->onlinePay($pay_info[ 'out_trade_no' ], 'wechatpay', $result[ 'transaction_id' ], 'wechatpay');
} else if (in_array($result[ 'trade_state' ], [ 'NOTPAY', 'USERPAYING', 'ACCEPT' ])) {
- ( new Cron() )->addCron(1, 0, "查询付款码支付结果", "PayOrderQuery", time() + 3, $pay_info[ 'id' ]);
+ $cron_model = new Cron();
+ $cron_model->deleteCron([ [ 'event', '=', 'PayOrderQuery' ], [ 'relate_id', '=', $pay_info[ 'id' ] ] ]);
+ $cron_model->addCron(1, 0, "查询付款码支付结果", "PayOrderQuery", time() + 3, $pay_info[ 'id' ]);
+ }else if($result[ 'trade_state' ] == 'PAYERROR'){
+ (new PayCommon())->edit(['pay_status' => PayCommon::PAY_STATUS_CANCEL], ['out_trade_no' => $pay_info[ "out_trade_no" ] ]);
}
}
return $this->success($result);
diff --git a/src/addon/wechatpay/model/V3.php b/src/addon/wechatpay/model/V3.php
index 4840f7d5e..ca2210790 100644
--- a/src/addon/wechatpay/model/V3.php
+++ b/src/addon/wechatpay/model/V3.php
@@ -1,594 +1,841 @@
-config = $config;
-
- $merchant_certificate_instance = PemUtil::loadCertificate(realpath($config[ 'apiclient_cert' ]));
- // 证书序列号
- $merchant_certificate_serial = PemUtil::parseCertificateSerialNo($merchant_certificate_instance);
-
- // 检测平台证书是否存在
- if (empty($config[ 'plateform_cert' ])) {
- $create_res = $this->certificates();
- if ($create_res[ 'code' ] != 0) throw new ApiException(-1, "微信支付配置错误");
- // 保存平台证书
- $this->config[ 'plateform_cert' ] = $create_res[ 'data' ][ 'cert_path' ];
- ( new Config() )->setPayConfig($this->config, $this->config[ 'site_id' ]);
- }
-
- // 加载平台证书
- $this->plateform_certificate_instance = PemUtil::loadCertificate(realpath($this->config[ 'plateform_cert' ]));
- // 平台证书序列号
- $this->plateform_certificate_serial = PemUtil::parseCertificateSerialNo($this->plateform_certificate_instance);
-
- $this->app = Builder::factory([
- // 商户号
- 'mchid' => $config[ 'mch_id' ],
- // 商户证书序列号
- 'serial' => $merchant_certificate_serial,
- // 商户API私钥
- 'privateKey' => PemUtil::loadPrivateKey(realpath($config[ 'apiclient_key' ])),
- 'certs' => [
- $this->plateform_certificate_serial => $this->plateform_certificate_instance
- ]
- ]);
- }
-
- /**
- * 生成平台证书
- */
- private function certificates()
- {
- try {
- $merchant_certificate_instance = PemUtil::loadCertificate(realpath($this->config[ 'apiclient_cert' ]));
- // 证书序列号
- $merchant_certificate_serial = PemUtil::parseCertificateSerialNo($merchant_certificate_instance);
-
- $certs = [ 'any' => null ];
- $app = Builder::factory([
- // 商户号
- 'mchid' => $this->config[ 'mch_id' ],
- // 商户证书序列号
- 'serial' => $merchant_certificate_serial,
- // 商户API私钥
- 'privateKey' => PemUtil::loadPrivateKey(realpath($this->config[ 'apiclient_key' ])),
- 'certs' => &$certs
- ]);
-
- $stack = $app->getDriver()->select(ClientDecoratorInterface::JSON_BASED)->getConfig('handler');
- $stack->after('verifier', Middleware::mapResponse(self::certsInjector($this->config[ 'v3_pay_signkey' ], $certs)), 'injector');
- $stack->before('verifier', Middleware::mapResponse(self::certsRecorder((string) dirname($this->config[ 'apiclient_key' ]), $certs)), 'recorder');
-
- $param = [
- 'url' => '/v3/certificates',
- 'timestamp' => (string) Formatter::timestamp(),
- 'noncestr' => uniqid()
- ];
- $resp = $app->chain("v3/certificates")
- ->get([
- 'headers' => [
- 'Authorization' => Rsa::sign(
- Formatter::joinedByLineFeed(...array_values($param)),
- Rsa::from('file://' . realpath($this->config[ 'apiclient_key' ]))
- )
- ]
- ]);
- $result = json_decode($resp->getBody()->getContents(), true);
- $file_path = dirname($this->config[ 'apiclient_key' ]) . '/plateform_cert.pem';
- return $this->success([ 'cert_path' => $file_path ]);
- } catch (\Exception $e) {
- if ($e instanceof \GuzzleHttp\Exception\RequestException && $e->hasResponse()) {
- $result = json_decode($e->getResponse()->getBody()->getContents(), true);
- return $this->error($result, $result[ 'message' ]);
- } else {
- return $this->error([], $e->getMessage());
- }
- }
- }
-
- private static function certsInjector(string $apiv3Key, array &$certs) : callable
- {
- return static function(ResponseInterface $response) use ($apiv3Key, &$certs): ResponseInterface {
- $body = (string) $response->getBody();
- /** @var object{data:array