chore(src): 所有代码上传

This commit is contained in:
2025-12-02 15:36:42 +08:00
parent ce8e59902c
commit eb79ad260c
669 changed files with 86838 additions and 87639 deletions

View File

@@ -1,38 +1,30 @@
<?php
/**
*/
return [
// 自定义模板页面类型,格式:[ 'title' => '页面类型名称', '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' => []
<?php
return [
// 自定义模板页面类型,格式:[ 'title' => '页面类型名称', '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' => []
];

View File

@@ -1,21 +1,12 @@
<?php
/**
*/
return [
'name' => 'alioss',
'title' => '阿里云OSS',
'description' => '阿里云OSS',
'type' => 'system', //插件类型 system :系统插件(自动安装), business:业务插件 promotion:营销插件 tool:工具插件
'status' => 1,
'author' => '',
'version' => '5.3.1',
'version_no' => '525231212001',
'content' => '',
<?php
return [
'name' => 'alioss',
'title' => '阿里云OSS',
'description' => '阿里云OSS',
'type' => 'system', //插件类型 system :系统插件(自动安装), business:业务插件 promotion:营销插件 tool:工具插件
'status' => 1,
'author' => '',
'version' => '5.3.1',
'version_no' => '525231212001',
'content' => '',
];

View File

@@ -1,39 +1,31 @@
<?php
/**
*/
namespace addon\alioss\event;
use addon\alioss\model\Alioss;
use addon\alioss\model\Config;
/**
* 删除阿里云图片
*/
class ClearAlbumPic
{
public function handle($params)
{
$config_model = new Config();
$alioss_model = new Alioss();
$config = $config_model->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;
}
}
}
<?php
namespace addon\alioss\event;
use addon\alioss\model\Alioss;
use addon\alioss\model\Config;
/**
* 删除阿里云图片
*/
class ClearAlbumPic
{
public function handle($params)
{
$config_model = new Config();
$alioss_model = new Alioss();
$config = $config_model->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;
}
}
}
}

View File

@@ -1,27 +1,19 @@
<?php
/**
*/
namespace addon\alioss\event;
use addon\alioss\model\Config;
/**
* 关闭云上传
*/
class CloseOss
{
public function handle()
{
$config_model = new Config();
$result = $config_model->modifyConfigIsUse(0);
return $result;
}
<?php
namespace addon\alioss\event;
use addon\alioss\model\Config;
/**
* 关闭云上传
*/
class CloseOss
{
public function handle()
{
$config_model = new Config();
$result = $config_model->modifyConfigIsUse(0);
return $result;
}
}

View File

@@ -1,26 +1,18 @@
<?php
/**
*/
namespace addon\alioss\event;
/**
* 应用安装
*/
class Install
{
/**
* 执行安装
*/
public function handle()
{
return success();
}
<?php
namespace addon\alioss\event;
/**
* 应用安装
*/
class Install
{
/**
* 执行安装
*/
public function handle()
{
return success();
}
}

View File

@@ -1,33 +1,25 @@
<?php
/**
*/
namespace addon\alioss\event;
/**
* 云上传方式
*/
class OssType
{
/**
* 短信发送方式方式及配置
*/
public function handle()
{
$info = array(
"sms_type" => "alioss",
"sms_type_name" => "阿里云上传",
"edit_url" => "alioss://shop/config/config",
"shop_url" => "alioss://shop/config/config",
"desc" => "阿里云上传"
);
return $info;
}
<?php
namespace addon\alioss\event;
/**
* 云上传方式
*/
class OssType
{
/**
* 短信发送方式方式及配置
*/
public function handle()
{
$info = array(
"sms_type" => "alioss",
"sms_type_name" => "阿里云上传",
"edit_url" => "alioss://shop/config/config",
"shop_url" => "alioss://shop/config/config",
"desc" => "阿里云上传"
);
return $info;
}
}

View File

@@ -1,31 +1,23 @@
<?php
/**
*/
namespace addon\alioss\event;
use addon\alioss\model\Alioss;
/**
* 云上传方式
*/
class Put
{
/**
* @param $param
* @return array
*/
public function handle($param)
{
$qiniu_model = new Alioss();
$result = $qiniu_model->putFile($param);
return $result;
}
<?php
namespace addon\alioss\event;
use addon\alioss\model\Alioss;
/**
* 云上传方式
*/
class Put
{
/**
* @param $param
* @return array
*/
public function handle($param)
{
$qiniu_model = new Alioss();
$result = $qiniu_model->putFile($param);
return $result;
}
}

View File

@@ -1,27 +1,18 @@
<?php
/**
*/
namespace addon\alioss\event;
/**
* 应用卸载
*/
class UnInstall
{
/**
* 执行卸载
*/
public function handle()
{
return success();
}
<?php
namespace addon\alioss\event;
/**
* 应用卸载
*/
class UnInstall
{
/**
* 执行卸载
*/
public function handle()
{
return success();
}
}

View File

@@ -1,146 +1,138 @@
<?php
/**
*/
namespace addon\alioss\model;
use app\model\BaseModel;
use OSS\Core\OssException;
use OSS\OssClient;
use think\facade\Log;
/**
* 阿里云OSS上传
*/
class Alioss extends BaseModel
{
/**
* 字节组上传
* @param $data
* @param $key
* @return array
*/
public function put($param)
{
$data = $param['data'];
$key = $param['key'];
$config_model = new Config();
$config_result = $config_model->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());
}
}
}
<?php
namespace addon\alioss\model;
use app\model\BaseModel;
use OSS\Core\OssException;
use OSS\OssClient;
use think\facade\Log;
/**
* 阿里云OSS上传
*/
class Alioss extends BaseModel
{
/**
* 字节组上传
* @param $data
* @param $key
* @return array
*/
public function put($param)
{
$data = $param['data'];
$key = $param['key'];
$config_model = new Config();
$config_result = $config_model->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());
}
}
}
}

View File

@@ -1,56 +1,48 @@
<?php
/**
*/
namespace addon\alioss\model;
use app\model\system\Config as ConfigModel;
use app\model\BaseModel;
/**
* 阿里云配置
*/
class Config extends BaseModel
{
/**
* 设置阿里云OSS上传配置
* array $data
*/
public function setAliossConfig($data, $status, $site_id = 1, $app_module = 'shop')
{
if ($status == 1) {
event('CloseOss', []);//同步关闭所有云上传
}
$config = new ConfigModel();
$res = $config->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;
}
<?php
namespace addon\alioss\model;
use app\model\system\Config as ConfigModel;
use app\model\BaseModel;
/**
* 阿里云配置
*/
class Config extends BaseModel
{
/**
* 设置阿里云OSS上传配置
* array $data
*/
public function setAliossConfig($data, $status, $site_id = 1, $app_module = 'shop')
{
if ($status == 1) {
event('CloseOss', []);//同步关闭所有云上传
}
$config = new ConfigModel();
$res = $config->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;
}
}

View File

@@ -1,56 +1,48 @@
<?php
/**
*/
namespace addon\alioss\shop\controller;
use addon\alioss\model\Config as ConfigModel;
use app\shop\controller\BaseShop;
/**
* 七牛云上传管理
*/
class Config extends BaseShop
{
/**
* 云上传配置
* @return mixed
*/
public function config()
{
$config_model = new ConfigModel();
if (request()->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');
}
}
<?php
namespace addon\alioss\shop\controller;
use addon\alioss\model\Config as ConfigModel;
use app\shop\controller\BaseShop;
/**
* 七牛云上传管理
*/
class Config extends BaseShop
{
/**
* 云上传配置
* @return mixed
*/
public function config()
{
$config_model = new ConfigModel();
if (request()->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');
}
}
}

View File

@@ -1,38 +1,30 @@
<?php
/**
*/
return [
// 自定义模板页面类型,格式:[ 'title' => '页面类型名称', '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' => []
<?php
return [
// 自定义模板页面类型,格式:[ 'title' => '页面类型名称', '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' => []
];

View File

@@ -1,50 +1,42 @@
<?php
/**
*/
return [
'bind' => [
],
'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' => [
],
];
<?php
return [
'bind' => [
],
'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' => [
],
];

View File

@@ -1,21 +1,12 @@
<?php
/**
*/
return [
'name' => 'alipay',
'title' => '支付宝支付',
'description' => '支付宝支付功能',
'type' => 'system', //插件类型 system :系统插件(自动安装), promotion:营销插件 tool:工具插件
'status' => 1,
'author' => '',
'version' => '5.3.1',
'version_no' => '525231212001',
'content' => '',
<?php
return [
'name' => 'alipay',
'title' => '支付宝支付',
'description' => '支付宝支付功能',
'type' => 'system', //插件类型 system :系统插件(自动安装), promotion:营销插件 tool:工具插件
'status' => 1,
'author' => '',
'version' => '5.3.1',
'version_no' => '525231212001',
'content' => '',
];

View File

@@ -1,23 +1,15 @@
<?php
/**
*/
return [
[
'name' => '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,
],
];
<?php
return [
[
'name' => '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,
],
];

View File

@@ -1,27 +1,18 @@
<?php
/**
*/
namespace addon\alipay\event;
/**
* 应用安装
*/
class Install
{
/**
* 执行安装
*/
public function handle()
{
return success();
}
<?php
namespace addon\alipay\event;
/**
* 应用安装
*/
class Install
{
/**
* 执行安装
*/
public function handle()
{
return success();
}
}

View File

@@ -1,33 +1,25 @@
<?php
/**
*/
namespace addon\alipay\event;
use addon\alipay\model\Pay as PayModel;
/**
* 生成支付
*/
class Pay
{
/**
* 支付方式及配置
*/
public function handle($param)
{
if ($param[ "pay_type" ] == "alipay") {
if (in_array($param[ "app_type" ], [ "h5", "app", "pc", "aliapp", 'wechat' ])) {
$pay_model = new PayModel($param[ 'site_id' ], $param[ "app_type" ] == 'aliapp');
$res = $pay_model->pay($param);
return $res;
}
}
}
<?php
namespace addon\alipay\event;
use addon\alipay\model\Pay as PayModel;
/**
* 生成支付
*/
class Pay
{
/**
* 支付方式及配置
*/
public function handle($param)
{
if ($param[ "pay_type" ] == "alipay") {
if (in_array($param[ "app_type" ], [ "h5", "app", "pc", "aliapp", 'wechat' ])) {
$pay_model = new PayModel($param[ 'site_id' ], $param[ "app_type" ] == 'aliapp');
$res = $pay_model->pay($param);
return $res;
}
}
}
}

View File

@@ -1,39 +1,31 @@
<?php
/**
*/
namespace addon\alipay\event;
use addon\alipay\model\Pay as PayModel;
/**
* 关闭支付
*/
class PayClose
{
/**
* 关闭支付
* @param $params
* @return \addon\alipay\model\multitype|array
*/
public function handle($params)
{
// if ($params["pay_type"] == "alipay") {
try {
$pay_model = new PayModel($params[ 'site_id' ]);
$result = $pay_model->close($params);
return $result;
} catch (\Exception $e) {
return error(-1, $e->getMessage());
} catch (\Throwable $e) {
return error(-1, $e->getMessage());
}
// }
}
<?php
namespace addon\alipay\event;
use addon\alipay\model\Pay as PayModel;
/**
* 关闭支付
*/
class PayClose
{
/**
* 关闭支付
* @param $params
* @return \addon\alipay\model\multitype|array
*/
public function handle($params)
{
// if ($params["pay_type"] == "alipay") {
try {
$pay_model = new PayModel($params[ 'site_id' ]);
$result = $pay_model->close($params);
return $result;
} catch (\Exception $e) {
return error(-1, $e->getMessage());
} catch (\Throwable $e) {
return error(-1, $e->getMessage());
}
// }
}
}

View File

@@ -1,41 +1,33 @@
<?php
/**
*/
namespace addon\alipay\event;
use addon\alipay\model\Pay as PayModel;
use app\model\system\Pay as PayCommon;
/**
* 支付回调
*/
class PayNotify
{
/**
* 支付方式及配置
*/
public function handle()
{
if (isset($_POST[ 'out_trade_no' ])) {
$out_trade_no = $_POST[ 'out_trade_no' ];
$pay = new PayCommon();
$pay_info = $pay->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();
}
}
<?php
namespace addon\alipay\event;
use addon\alipay\model\Pay as PayModel;
use app\model\system\Pay as PayCommon;
/**
* 支付回调
*/
class PayNotify
{
/**
* 支付方式及配置
*/
public function handle()
{
if (isset($_POST[ 'out_trade_no' ])) {
$out_trade_no = $_POST[ 'out_trade_no' ];
$pay = new PayCommon();
$pay_info = $pay->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();
}
}
}

View File

@@ -1,34 +1,26 @@
<?php
/**
*/
namespace addon\alipay\event;
use addon\alipay\model\Config as ConfigModel;
use addon\alipay\model\Pay as PayModel;
use app\model\system\Pay;
/**
* 查询支付结果
*/
class PayOrderQuery
{
public function handle(array $params)
{
$pay_info = ( new Pay() )->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);
}
}
}
}
<?php
namespace addon\alipay\event;
use addon\alipay\model\Config as ConfigModel;
use addon\alipay\model\Pay as PayModel;
use app\model\system\Pay;
/**
* 查询支付结果
*/
class PayOrderQuery
{
public function handle(array $params)
{
$pay_info = ( new Pay() )->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);
}
}
}
}

View File

@@ -1,33 +1,25 @@
<?php
/**
*/
namespace addon\alipay\event;
use addon\alipay\model\Pay as PayModel;
/**
* 原路退款
*/
class PayRefund
{
/**
* 关闭支付
*/
public function handle($params)
{
if ($params[ "pay_info" ][ "pay_type" ] == "alipay") {
$mch_info = empty($params[ 'pay_info' ][ 'mch_info' ]) ? [] : json_decode($params[ 'pay_info' ][ 'mch_info' ], true);
$pay_model = new PayModel($params[ 'site_id' ], $mch_info[ 'is_aliapp' ] ?? 0);
$result = $pay_model->refund($params);
return $result;
}
}
<?php
namespace addon\alipay\event;
use addon\alipay\model\Pay as PayModel;
/**
* 原路退款
*/
class PayRefund
{
/**
* 关闭支付
*/
public function handle($params)
{
if ($params[ "pay_info" ][ "pay_type" ] == "alipay") {
$mch_info = empty($params[ 'pay_info' ][ 'mch_info' ]) ? [] : json_decode($params[ 'pay_info' ][ 'mch_info' ], true);
$pay_model = new PayModel($params[ 'site_id' ], $mch_info[ 'is_aliapp' ] ?? 0);
$result = $pay_model->refund($params);
return $result;
}
}
}

View File

@@ -1,42 +1,34 @@
<?php
/**
*/
namespace addon\alipay\event;
use addon\alipay\model\Pay;
use addon\alipay\model\Config;
class PayTransfer
{
public function handle(array $params)
{
if ($params[ 'transfer_type' ] == 'alipay') {
$pay = new Pay($params[ 'site_id' ]);
$config_model = new Config();
$config_result = $config_model->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;
}
}
}
<?php
namespace addon\alipay\event;
use addon\alipay\model\Pay;
use addon\alipay\model\Config;
class PayTransfer
{
public function handle(array $params)
{
if ($params[ 'transfer_type' ] == 'alipay') {
$pay = new Pay($params[ 'site_id' ]);
$config_model = new Config();
$config_result = $config_model->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;
}
}
}
}

View File

@@ -1,51 +1,43 @@
<?php
/**
*/
namespace addon\alipay\event;
use addon\alipay\model\Config;
/**
* 支付方式 (后台调用)
*/
class PayType
{
/**
* 支付方式及配置
*/
public function handle($param)
{
$app_type = $param['app_type'] ?? '';
if (!empty($app_type)) {
if (!in_array($app_type, [ "h5", "app", "pc", "aliapp", 'wechat' ])) {
return '';
}
if ($app_type != 'aliapp') {
$config_model = new Config();
$config_result = $config_model->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;
}
<?php
namespace addon\alipay\event;
use addon\alipay\model\Config;
/**
* 支付方式 (后台调用)
*/
class PayType
{
/**
* 支付方式及配置
*/
public function handle($param)
{
$app_type = $param['app_type'] ?? '';
if (!empty($app_type)) {
if (!in_array($app_type, [ "h5", "app", "pc", "aliapp", 'wechat' ])) {
return '';
}
if ($app_type != 'aliapp') {
$config_model = new Config();
$config_result = $config_model->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;
}
}

View File

@@ -1,39 +1,31 @@
<?php
/**
*/
namespace addon\alipay\event;
use addon\alipay\model\Config;
class TransferType
{
public function handle(array $param)
{
$app_type = $param['app_type'] ?? '';
if (!empty($app_type)) {
if (!in_array($app_type, [ "h5", "app", "pc", "aliapp" ])) {
return '';
}
$config_model = new Config();
$config_result = $config_model->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;
}
<?php
namespace addon\alipay\event;
use addon\alipay\model\Config;
class TransferType
{
public function handle(array $param)
{
$app_type = $param['app_type'] ?? '';
if (!empty($app_type)) {
if (!in_array($app_type, [ "h5", "app", "pc", "aliapp" ])) {
return '';
}
$config_model = new Config();
$config_result = $config_model->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;
}
}

View File

@@ -1,26 +1,17 @@
<?php
/**
*/
namespace addon\alipay\event;
/**
* 应用卸载
*/
class UnInstall
{
/**
* 执行卸载
*/
public function handle()
{
return error(-1, "系统插件不得删除");
}
<?php
namespace addon\alipay\event;
/**
* 应用卸载
*/
class UnInstall
{
/**
* 执行卸载
*/
public function handle()
{
return error(-1, "系统插件不得删除");
}
}

View File

@@ -1,96 +1,88 @@
<?php
/**
*/
namespace addon\alipay\model;
use app\model\system\Config as ConfigModel;
use app\model\BaseModel;
/**
* 支付宝支付配置
*/
class Config extends BaseModel
{
private $encrypt = '******';
/**
* 设置支付配置
* @param $data
* @param int $site_id
* @param string $app_module
* @return array
*/
public function setPayConfig($data, $site_id = 0, $app_module = 'shop')
{
$config = new ConfigModel();
// 未加密前的数据
$original_config = $this->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;
}
<?php
namespace addon\alipay\model;
use app\model\system\Config as ConfigModel;
use app\model\BaseModel;
/**
* 支付宝支付配置
*/
class Config extends BaseModel
{
private $encrypt = '******';
/**
* 设置支付配置
* @param $data
* @param int $site_id
* @param string $app_module
* @return array
*/
public function setPayConfig($data, $site_id = 0, $app_module = 'shop')
{
$config = new ConfigModel();
// 未加密前的数据
$original_config = $this->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;
}
}

View File

@@ -1,486 +1,478 @@
<?php
/**
*/
namespace addon\alipay\model;
use addon\alipay\data\sdk\AopClient;
use addon\alipay\data\sdk\request\AlipayFundTransToaccountTransferRequest;
use addon\alipay\data\sdk\request\AlipayTradeAppPayRequest;
use addon\alipay\data\sdk\request\AlipayTradeCloseRequest;
use addon\alipay\data\sdk\request\AlipayTradeCreateRequest;
use addon\alipay\data\sdk\request\AlipayTradePagePayRequest;
use addon\alipay\data\sdk\request\AlipayTradeRefundRequest;
use addon\alipay\data\sdk\request\AlipayTradeWapPayRequest;
use addon\alipay\data\sdk\request\AlipayTradePrecreateRequest;
use addon\alipay\data\sdk\request\AlipayTradePayRequest;
use addon\alipay\data\sdk\request\AlipayTradeQueryRequest;
use app\model\BaseModel;
use app\model\system\Cron;
use app\model\system\Pay as PayCommon;
use addon\alipay\data\sdk\request\AlipayFundTransUniTransferRequest;
use addon\alipay\data\sdk\AopCertClient;
use app\model\system\Pay as PayModel;
use addon\aliapp\model\Config as AliappConfig;
use think\facade\Log;
/**
* 支付宝支付配置
*/
class Pay extends BaseModel
{
public $aop;
private $is_aliapp = 0;
/**
*
* @param $site_id
* @param int $is_aliapp 是否是小程序
*/
function __construct($site_id, $is_aliapp = 0)
{
$this->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);
}
}
<?php
namespace addon\alipay\model;
use addon\alipay\data\sdk\AopClient;
use addon\alipay\data\sdk\request\AlipayFundTransToaccountTransferRequest;
use addon\alipay\data\sdk\request\AlipayTradeAppPayRequest;
use addon\alipay\data\sdk\request\AlipayTradeCloseRequest;
use addon\alipay\data\sdk\request\AlipayTradeCreateRequest;
use addon\alipay\data\sdk\request\AlipayTradePagePayRequest;
use addon\alipay\data\sdk\request\AlipayTradeRefundRequest;
use addon\alipay\data\sdk\request\AlipayTradeWapPayRequest;
use addon\alipay\data\sdk\request\AlipayTradePrecreateRequest;
use addon\alipay\data\sdk\request\AlipayTradePayRequest;
use addon\alipay\data\sdk\request\AlipayTradeQueryRequest;
use app\model\BaseModel;
use app\model\system\Cron;
use app\model\system\Pay as PayCommon;
use addon\alipay\data\sdk\request\AlipayFundTransUniTransferRequest;
use addon\alipay\data\sdk\AopCertClient;
use app\model\system\Pay as PayModel;
use addon\aliapp\model\Config as AliappConfig;
use think\facade\Log;
/**
* 支付宝支付配置
*/
class Pay extends BaseModel
{
public $aop;
private $is_aliapp = 0;
/**
*
* @param $site_id
* @param int $is_aliapp 是否是小程序
*/
function __construct($site_id, $is_aliapp = 0)
{
$this->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);
}
}
}

View File

@@ -1,94 +1,86 @@
<?php
/**
*/
namespace addon\alipay\shop\controller;
use addon\alipay\model\Config as ConfigModel;
use app\shop\controller\BaseShop;
use think\facade\Config;
use app\model\upload\Upload;
/**
* 支付宝 控制器
*/
class Pay extends BaseShop
{
public function config()
{
$config_model = new ConfigModel();
if (request()->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;
}
<?php
namespace addon\alipay\shop\controller;
use addon\alipay\model\Config as ConfigModel;
use app\shop\controller\BaseShop;
use think\facade\Config;
use app\model\upload\Upload;
/**
* 支付宝 控制器
*/
class Pay extends BaseShop
{
public function config()
{
$config_model = new ConfigModel();
if (request()->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;
}
}

View File

@@ -1,48 +1,40 @@
<?php
/**
*/
return [
// 自定义模板页面类型,格式:[ 'title' => '页面类型名称', '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' => []
<?php
return [
// 自定义模板页面类型,格式:[ 'title' => '页面类型名称', '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' => []
];

View File

@@ -1,21 +1,12 @@
<?php
/**
*/
return [
'name' => 'cases',
'title' => '案例展示',
'description' => '展示案例信息',
'type' => 'tool', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
'status' => 1,
'author' => '',
'version' => '1.0.0',
'version_no' => '2025051923121',
'content' => '',
<?php
return [
'name' => 'cases',
'title' => '案例展示',
'description' => '展示案例信息',
'type' => 'tool', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
'status' => 1,
'author' => '',
'version' => '1.0.0',
'version_no' => '2025051923121',
'content' => '',
];

View File

@@ -1,25 +1,17 @@
<?php
/**
*/
namespace addon\cases\event;
/**
* 应用安装
*/
class Install
{
/**
* 执行安装
*/
public function handle()
{
return success();
}
<?php
namespace addon\cases\event;
/**
* 应用安装
*/
class Install
{
/**
* 执行安装
*/
public function handle()
{
return success();
}
}

View File

@@ -1,30 +1,21 @@
<?php
/**
*/
namespace addon\cases\event;
/**
* 应用卸载
*/
class UnInstall
{
/**
* 执行卸载
*/
public function handle()
{
try {
return error('', "系统插件不允许删除");
} catch (\Exception $e) {
return error('', $e->getMessage());
}
}
<?php
namespace addon\cases\event;
/**
* 应用卸载
*/
class UnInstall
{
/**
* 执行卸载
*/
public function handle()
{
try {
return error('', "系统插件不允许删除");
} catch (\Exception $e) {
return error('', $e->getMessage());
}
}
}

View File

@@ -1,351 +1,343 @@
<?php
/**
*/
namespace addon\coupon\api\controller;
use app\api\controller\BaseApi;
use addon\coupon\model\Coupon as CouponModel;
use addon\coupon\model\CouponType as CouponTypeModel;
use addon\coupon\model\MemberCoupon;
use think\facade\Db;
/**
* 优惠券
*/
class Coupon extends BaseApi
{
/**
* 优惠券类型信息
*/
public function typeinfo()
{
$coupon_type_id = $this->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);
}
<?php
namespace addon\coupon\api\controller;
use app\api\controller\BaseApi;
use addon\coupon\model\Coupon as CouponModel;
use addon\coupon\model\CouponType as CouponTypeModel;
use addon\coupon\model\MemberCoupon;
use think\facade\Db;
/**
* 优惠券
*/
class Coupon extends BaseApi
{
/**
* 优惠券类型信息
*/
public function typeinfo()
{
$coupon_type_id = $this->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);
}
}

View File

@@ -1,67 +1,59 @@
<?php
/**
*/
return [
// 自定义模板页面类型,格式:[ 'title' => '页面类型名称', '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' => []
<?php
return [
// 自定义模板页面类型,格式:[ 'title' => '页面类型名称', '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' => []
];

View File

@@ -1,21 +1,12 @@
<?php
/**
*/
return [
'name' => 'coupon',
'title' => '优惠券',
'description' => '会员优惠券功能',
'type' => 'system', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
'status' => 1,
'author' => '',
'version' => '5.3.1',
'version_no' => '525231212001',
'content' => '',
<?php
return [
'name' => 'coupon',
'title' => '优惠券',
'description' => '会员优惠券功能',
'type' => 'system', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
'status' => 1,
'author' => '',
'version' => '5.3.1',
'version_no' => '525231212001',
'content' => '',
];

View File

@@ -1,55 +1,46 @@
<?php
/**
*/
namespace addon\coupon\dict;
/**
* 订单公共属性
*/
class CouponDict
{
const normal = 1;
const used = 2;
const expire = 3;
const close = 4;
/**
* 优惠券状态
* @param $status
* @return string|string[]
*/
public static function getStatus($status = ''){
$list = [
self::normal => '待使用',
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;
}
}
<?php
namespace addon\coupon\dict;
/**
* 订单公共属性
*/
class CouponDict
{
const normal = 1;
const used = 2;
const expire = 3;
const close = 4;
/**
* 优惠券状态
* @param $status
* @return string|string[]
*/
public static function getStatus($status = ''){
$list = [
self::normal => '待使用',
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;
}
}

View File

@@ -1,27 +1,19 @@
<?php
/**
*/
namespace addon\coupon\event;
use addon\coupon\model\Coupon;
/**
* 启动活动
*/
class CronCouponEnd
{
public function handle($params = [])
{
$coupon = new Coupon();
$res = $coupon->cronCouponEnd();
return $res;
}
<?php
namespace addon\coupon\event;
use addon\coupon\model\Coupon;
/**
* 启动活动
*/
class CronCouponEnd
{
public function handle($params = [])
{
$coupon = new Coupon();
$res = $coupon->cronCouponEnd();
return $res;
}
}

View File

@@ -1,27 +1,19 @@
<?php
/**
*/
namespace addon\coupon\event;
use addon\coupon\model\CouponType;
/**
* 优惠券定时结束
*/
class CronCouponTypeEnd
{
public function handle($params = [])
{
$coupon = new CouponType();
$res = $coupon->couponCronEnd($params[ 'relate_id' ]);
return $res;
}
<?php
namespace addon\coupon\event;
use addon\coupon\model\CouponType;
/**
* 优惠券定时结束
*/
class CronCouponTypeEnd
{
public function handle($params = [])
{
$coupon = new CouponType();
$res = $coupon->couponCronEnd($params[ 'relate_id' ]);
return $res;
}
}

View File

@@ -1,38 +1,29 @@
<?php
/**
*/
namespace addon\coupon\event;
use app\model\system\Cron;
/**
* 应用安装
*/
class Install
{
/**
* 执行安装
*/
public function handle()
{
try {
execute_sql('addon/coupon/data/install.sql');
$cron = new Cron();
$cron->deleteCron([ ['event', '=', 'CronCouponEnd'] ]);
$cron->addCron(2, 1, '优惠券过期自动关闭', 'CronCouponEnd', time(), 0);
return success();
} catch (\Exception $e) {
return error('', $e->getMessage());
}
}
<?php
namespace addon\coupon\event;
use app\model\system\Cron;
/**
* 应用安装
*/
class Install
{
/**
* 执行安装
*/
public function handle()
{
try {
execute_sql('addon/coupon/data/install.sql');
$cron = new Cron();
$cron->deleteCron([ ['event', '=', 'CronCouponEnd'] ]);
$cron->addCron(2, 1, '优惠券过期自动关闭', 'CronCouponEnd', time(), 0);
return success();
} catch (\Exception $e) {
return error('', $e->getMessage());
}
}
}

View File

@@ -1,46 +1,38 @@
<?php
/**
*/
namespace addon\coupon\event;
/**
* 店铺活动
*/
class ShowPromotion
{
/**
* 活动展示
* @return array
*/
public function handle()
{
$data = [
'shop' => [
[
//插件名称
'name' => 'coupon',
//展示分类根据平台端设置admin平台营销shop店铺营销member:会员营销, tool:应用工具)
'show_type' => 'shop',
//展示主题
'title' => '优惠券',
//展示介绍
'description' => '设置商家优惠券',
//展示图标
'icon' => 'addon/coupon/icon.png',
//跳转链接
'url' => 'coupon://shop/coupon/lists',
]
]
];
return $data;
}
<?php
namespace addon\coupon\event;
/**
* 店铺活动
*/
class ShowPromotion
{
/**
* 活动展示
* @return array
*/
public function handle()
{
$data = [
'shop' => [
[
//插件名称
'name' => 'coupon',
//展示分类根据平台端设置admin平台营销shop店铺营销member:会员营销, tool:应用工具)
'show_type' => 'shop',
//展示主题
'title' => '优惠券',
//展示介绍
'description' => '设置商家优惠券',
//展示图标
'icon' => 'addon/coupon/icon.png',
//跳转链接
'url' => 'coupon://shop/coupon/lists',
]
]
];
return $data;
}
}

View File

@@ -1,32 +1,23 @@
<?php
/**
*/
namespace addon\coupon\event;
/**
* 应用卸载
*/
class UnInstall
{
/**
* 执行卸载
*/
public function handle()
{
try {
return error('', "系统插件不允许删除");
//execute_sql('addon/coupon/data/uninstall.sql');
//return success();
} catch (\Exception $e) {
return error('', $e->getMessage());
}
}
<?php
namespace addon\coupon\event;
/**
* 应用卸载
*/
class UnInstall
{
/**
* 执行卸载
*/
public function handle()
{
try {
return error('', "系统插件不允许删除");
//execute_sql('addon/coupon/data/uninstall.sql');
//return success();
} catch (\Exception $e) {
return error('', $e->getMessage());
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,64 +1,56 @@
<?php
/**
*/
namespace addon\coupon\model;
use app\model\BaseModel;
use app\model\system\Stat;
/**
* 优惠券统计
*/
class CouponStat extends BaseModel
{
/**
* 领取优惠券统计
* @param $params
* @return array
*/
public function addReceiveCouponStat($params)
{
$coupon_id = $params[ 'coupon_id' ];
$site_id = $params[ 'site_id' ] ?? 0;
$order_condition = array (
[ 'coupon_id', '=', $coupon_id ],
[ 'site_id', '=', $site_id ]
);
$info = model('promotion_coupon')->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;
}
<?php
namespace addon\coupon\model;
use app\model\BaseModel;
use app\model\system\Stat;
/**
* 优惠券统计
*/
class CouponStat extends BaseModel
{
/**
* 领取优惠券统计
* @param $params
* @return array
*/
public function addReceiveCouponStat($params)
{
$coupon_id = $params[ 'coupon_id' ];
$site_id = $params[ 'site_id' ] ?? 0;
$order_condition = array (
[ 'coupon_id', '=', $coupon_id ],
[ 'site_id', '=', $site_id ]
);
$info = model('promotion_coupon')->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;
}
}

View File

@@ -1,336 +1,328 @@
<?php
/**
*/
namespace addon\coupon\model;
use app\model\BaseModel;
use app\model\system\Config as ConfigModel;
use app\model\system\Cron;
use app\model\upload\Upload;
/**
* 优惠券活动
*/
class CouponType extends BaseModel
{
//优惠券类型状态
private $coupon_type_status = [
1 => '进行中',
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);
}
<?php
namespace addon\coupon\model;
use app\model\BaseModel;
use app\model\system\Config as ConfigModel;
use app\model\system\Cron;
use app\model\upload\Upload;
/**
* 优惠券活动
*/
class CouponType extends BaseModel
{
//优惠券类型状态
private $coupon_type_status = [
1 => '进行中',
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);
}
}

View File

@@ -1,243 +1,235 @@
<?php
/**
*/
namespace addon\coupon\model;
use addon\coupon\dict\CouponDict;
use app\model\BaseModel;
/**
* 优惠券
*/
class MemberCoupon extends BaseModel
{
/**
* 获取会员已领取优惠券
* @param $member_id
* @param $state
* @param int $site_id
* @param string $order
* @return array
*/
public function getMemberCouponList($member_id, $state, $site_id = 0, $order = "fetch_time desc")
{
$condition = array (
[ "member_id", "=", $member_id ],
[ "state", "=", $state ],
);
if ($site_id > 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();
}
<?php
namespace addon\coupon\model;
use addon\coupon\dict\CouponDict;
use app\model\BaseModel;
/**
* 优惠券
*/
class MemberCoupon extends BaseModel
{
/**
* 获取会员已领取优惠券
* @param $member_id
* @param $state
* @param int $site_id
* @param string $order
* @return array
*/
public function getMemberCouponList($member_id, $state, $site_id = 0, $order = "fetch_time desc")
{
$condition = array (
[ "member_id", "=", $member_id ],
[ "state", "=", $state ],
);
if ($site_id > 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();
}
}

View File

@@ -1,103 +1,94 @@
<?php
/**
*/
namespace addon\coupon\model\share;
use app\model\share\WchatShareBase as BaseModel;
use app\model\system\Config as ConfigModel;
use app\model\system\Site as SiteModel;
/**
* 分享
*/
class WchatShare extends BaseModel
{
protected $config = [
[
'title' => '领券中心',
'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,
];
}
}
<?php
namespace addon\coupon\model\share;
use app\model\share\WchatShareBase as BaseModel;
use app\model\system\Config as ConfigModel;
use app\model\system\Site as SiteModel;
/**
* 分享
*/
class WchatShare extends BaseModel
{
protected $config = [
[
'title' => '领券中心',
'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,
];
}
}

View File

@@ -1,91 +1,82 @@
<?php
/**
*/
namespace addon\coupon\model\share;
use app\model\share\WeappShareBase;
use app\model\system\Config as ConfigModel;
/**
* 分享
*/
class WeappShare extends WeappShareBase
{
protected $config = [
[
'title' => '领券中心',
'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,
];
}
}
<?php
namespace addon\coupon\model\share;
use app\model\share\WeappShareBase;
use app\model\system\Config as ConfigModel;
/**
* 分享
*/
class WeappShare extends WeappShareBase
{
protected $config = [
[
'title' => '领券中心',
'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,
];
}
}

View File

@@ -1,110 +1,102 @@
<?php
/**
*/
namespace addon\coupon\shopapi\controller;
use addon\coupon\model\Coupon as CouponModel;
use addon\coupon\model\CouponType as CouponTypeModel;
use addon\coupon\model\MemberCoupon;
use app\shopapi\controller\BaseApi;
/**
* 优惠券
*/
class Coupon extends BaseApi
{
public function __construct()
{
//执行父类构造函数
parent::__construct();
$token = $this->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);
}
<?php
namespace addon\coupon\shopapi\controller;
use addon\coupon\model\Coupon as CouponModel;
use addon\coupon\model\CouponType as CouponTypeModel;
use addon\coupon\model\MemberCoupon;
use app\shopapi\controller\BaseApi;
/**
* 优惠券
*/
class Coupon extends BaseApi
{
public function __construct()
{
//执行父类构造函数
parent::__construct();
$token = $this->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);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,21 +1,12 @@
<?php
/**
*/
return [
'name' => 'diy_default1',
'title' => '官方模板一',
'description' => '官方默认模板(一)',
'type' => 'system', //插件类型 system :系统插件(自动安装), business:业务插件 promotion:营销插件 tool:工具插件
'status' => 1,
'author' => '',
'version' => '5.3.1',
'version_no' => '525231212001',
'content' => '',
<?php
return [
'name' => 'diy_default1',
'title' => '官方模板一',
'description' => '官方默认模板(一)',
'type' => 'system', //插件类型 system :系统插件(自动安装), business:业务插件 promotion:营销插件 tool:工具插件
'status' => 1,
'author' => '',
'version' => '5.3.1',
'version_no' => '525231212001',
'content' => '',
];

View File

@@ -1,27 +1,18 @@
<?php
/**
*/
namespace addon\diy_default1\event;
/**
* 应用安装
*/
class Install
{
/**
* 执行安装
*/
public function handle()
{
return success();
}
<?php
namespace addon\diy_default1\event;
/**
* 应用安装
*/
class Install
{
/**
* 执行安装
*/
public function handle()
{
return success();
}
}

View File

@@ -1,26 +1,18 @@
<?php
/**
*/
namespace addon\diy_default1\event;
/**
* 应用卸载
*/
class UnInstall
{
/**
* 执行卸载
*/
public function handle()
{
return success();
}
<?php
namespace addon\diy_default1\event;
/**
* 应用卸载
*/
class UnInstall
{
/**
* 执行卸载
*/
public function handle()
{
return success();
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,21 +1,12 @@
<?php
/**
*/
return [
'name' => 'diy_default2',
'title' => '官方模板二',
'description' => '官方默认模板(二)',
'type' => 'system', //插件类型 system :系统插件(自动安装), business:业务插件 promotion:营销插件 tool:工具插件
'status' => 1,
'author' => '',
'version' => '5.3.1',
'version_no' => '525231212001',
'content' => '',
<?php
return [
'name' => 'diy_default2',
'title' => '官方模板二',
'description' => '官方默认模板(二)',
'type' => 'system', //插件类型 system :系统插件(自动安装), business:业务插件 promotion:营销插件 tool:工具插件
'status' => 1,
'author' => '',
'version' => '5.3.1',
'version_no' => '525231212001',
'content' => '',
];

View File

@@ -1,27 +1,18 @@
<?php
/**
*/
namespace addon\diy_default2\event;
/**
* 应用安装
*/
class Install
{
/**
* 执行安装
*/
public function handle()
{
return success();
}
<?php
namespace addon\diy_default2\event;
/**
* 应用安装
*/
class Install
{
/**
* 执行安装
*/
public function handle()
{
return success();
}
}

View File

@@ -1,26 +1,18 @@
<?php
/**
*/
namespace addon\diy_default2\event;
/**
* 应用卸载
*/
class UnInstall
{
/**
* 执行卸载
*/
public function handle()
{
return success();
}
<?php
namespace addon\diy_default2\event;
/**
* 应用卸载
*/
class UnInstall
{
/**
* 执行卸载
*/
public function handle()
{
return success();
}
}

View File

@@ -1,38 +1,30 @@
<?php
/**
*/
return [
// 自定义模板页面类型,格式:[ 'title' => '页面类型名称', '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' => []
<?php
return [
// 自定义模板页面类型,格式:[ 'title' => '页面类型名称', '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' => []
];

View File

@@ -1,20 +1,12 @@
<?php
/**
*/
return [
'name' => 'electronicsheet',
'title' => '电子面单',
'description' => '电子面单',
'type' => 'tool', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
'status' => 1,
'author' => '',
'version' => '5.3.1',
'version_no' => '525231212001',
'content' => '',
<?php
return [
'name' => 'electronicsheet',
'title' => '电子面单',
'description' => '电子面单',
'type' => 'tool', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
'status' => 1,
'author' => '',
'version' => '5.3.1',
'version_no' => '525231212001',
'content' => '',
];

View File

@@ -1,25 +1,17 @@
<?php
/**
*/
namespace addon\electronicsheet\event;
/**
* 应用安装
*/
class Install
{
/**
* 执行安装
*/
public function handle()
{
return success();
}
<?php
namespace addon\electronicsheet\event;
/**
* 应用安装
*/
class Install
{
/**
* 执行安装
*/
public function handle()
{
return success();
}
}

View File

@@ -1,27 +1,19 @@
<?php
/**
*/
namespace addon\electronicsheet\event;
/**
* 活动类型
*/
class PromotionType
{
/**
* 活动类型
* @return array
*/
public function handle()
{
return [ "name" => "电子面单", "type" => "electronicsheet" ];
}
<?php
namespace addon\electronicsheet\event;
/**
* 活动类型
*/
class PromotionType
{
/**
* 活动类型
* @return array
*/
public function handle()
{
return [ "name" => "电子面单", "type" => "electronicsheet" ];
}
}

View File

@@ -1,46 +1,38 @@
<?php
/**
*/
namespace addon\electronicsheet\event;
/**
* 活动展示
*/
class ShowPromotion
{
/**
* 活动展示
* @return array
*/
public function handle()
{
$data = [
'shop' => [
[
//插件名称
'name' => 'electronicsheet',
//店铺端展示分类 shop:营销活动 member:互动营销
'show_type' => 'tool',
//展示主题
'title' => '电子面单',
//展示介绍
'description' => '商家发货主动打印快递面单',
//展示图标
'icon' => 'addon/electronicsheet/icon.png',
//跳转链接
'url' => 'electronicsheet://shop/electronicsheet/lists',
]
]
];
return $data;
}
<?php
namespace addon\electronicsheet\event;
/**
* 活动展示
*/
class ShowPromotion
{
/**
* 活动展示
* @return array
*/
public function handle()
{
$data = [
'shop' => [
[
//插件名称
'name' => 'electronicsheet',
//店铺端展示分类 shop:营销活动 member:互动营销
'show_type' => 'tool',
//展示主题
'title' => '电子面单',
//展示介绍
'description' => '商家发货主动打印快递面单',
//展示图标
'icon' => 'addon/electronicsheet/icon.png',
//跳转链接
'url' => 'electronicsheet://shop/electronicsheet/lists',
]
]
];
return $data;
}
}

View File

@@ -1,25 +1,17 @@
<?php
/**
*/
namespace addon\electronicsheet\event;
/**
* 应用卸载
*/
class UnInstall
{
/**
* 执行卸载
*/
public function handle()
{
return success();
}
<?php
namespace addon\electronicsheet\event;
/**
* 应用卸载
*/
class UnInstall
{
/**
* 执行卸载
*/
public function handle()
{
return success();
}
}

View File

@@ -1,172 +1,164 @@
<?php
/**
*/
namespace addon\electronicsheet\model;
use app\model\BaseModel;
use app\model\shop\Shop;
use extend\Kdniao;
use app\model\system\Address;
/**
* 电子面单物流配送
*/
class ElectronicsheetDelivery extends BaseModel
{
/**
* 电子面单发货
* @param $param
* @param $is_delivery
* @return array
*/
public function delivery($param)
{
//获取电子面单设置
$electronicsheet_model = new ExpressElectronicsheet();
$config_info = $electronicsheet_model->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' ]);
}
<?php
namespace addon\electronicsheet\model;
use app\model\BaseModel;
use app\model\shop\Shop;
use extend\Kdniao;
use app\model\system\Address;
/**
* 电子面单物流配送
*/
class ElectronicsheetDelivery extends BaseModel
{
/**
* 电子面单发货
* @param $param
* @param $is_delivery
* @return array
*/
public function delivery($param)
{
//获取电子面单设置
$electronicsheet_model = new ExpressElectronicsheet();
$config_info = $electronicsheet_model->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' ]);
}
}

View File

@@ -1,213 +1,205 @@
<?php
/**
*/
namespace addon\electronicsheet\model;
use app\model\express\ExpressCompanyTemplate;
use app\model\system\Config;
use app\model\BaseModel;
class ExpressElectronicsheet extends BaseModel
{
/************************************ 电子面单设置 start **********************************************************/
/**
* 电子面单设置
* @param $data
* @return array
*/
public function setElectronicsheetConfig($data)
{
$config = new Config();
$res = $config->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);
}
<?php
namespace addon\electronicsheet\model;
use app\model\express\ExpressCompanyTemplate;
use app\model\system\Config;
use app\model\BaseModel;
class ExpressElectronicsheet extends BaseModel
{
/************************************ 电子面单设置 start **********************************************************/
/**
* 电子面单设置
* @param $data
* @return array
*/
public function setElectronicsheetConfig($data)
{
$config = new Config();
$res = $config->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);
}
}

View File

@@ -1,47 +1,39 @@
<?php
/**
*/
namespace addon\electronicsheet\shop\controller;
use app\shop\controller\BaseShop;
use addon\electronicsheet\model\ExpressElectronicsheet as ExpressElectronicsheetModel;
class Config extends BaseShop
{
/*
* 电子面单设置
*/
public function config()
{
$config = new ExpressElectronicsheetModel();
if (request()->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');
}
}
<?php
namespace addon\electronicsheet\shop\controller;
use app\shop\controller\BaseShop;
use addon\electronicsheet\model\ExpressElectronicsheet as ExpressElectronicsheetModel;
class Config extends BaseShop
{
/*
* 电子面单设置
*/
public function config()
{
$config = new ExpressElectronicsheetModel();
if (request()->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');
}
}
}

View File

@@ -1,146 +1,138 @@
<?php
/**
*/
namespace addon\electronicsheet\shop\controller;
use app\model\express\ExpressCompanyTemplate;
use app\shop\controller\BaseShop;
use addon\electronicsheet\model\ExpressElectronicsheet as ExpressElectronicsheetModel;
class Electronicsheet extends BaseShop
{
/*
* 电子面单列表
*/
public function lists()
{
$model = new ExpressElectronicsheetModel();
$condition[] = [ 'site_id', '=', $this->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);
}
<?php
namespace addon\electronicsheet\shop\controller;
use app\model\express\ExpressCompanyTemplate;
use app\shop\controller\BaseShop;
use addon\electronicsheet\model\ExpressElectronicsheet as ExpressElectronicsheetModel;
class Electronicsheet extends BaseShop
{
/*
* 电子面单列表
*/
public function lists()
{
$model = new ExpressElectronicsheetModel();
$condition[] = [ 'site_id', '=', $this->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);
}
}

View File

@@ -1,50 +1,42 @@
<?php
/**
*/
namespace addon\fenxiao\api\controller;
use addon\fenxiao\model\FenxiaoAccount;
use addon\fenxiao\model\Fenxiao as FenxiaoModel;
use app\api\controller\BaseApi;
/**
* 分销商流水
*/
class Account extends BaseApi
{
/**
* 分销商流水分页
* @return false|string
*/
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;
$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'));
}
<?php
namespace addon\fenxiao\api\controller;
use addon\fenxiao\model\FenxiaoAccount;
use addon\fenxiao\model\Fenxiao as FenxiaoModel;
use app\api\controller\BaseApi;
/**
* 分销商流水
*/
class Account extends BaseApi
{
/**
* 分销商流水分页
* @return false|string
*/
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;
$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'));
}
}

View File

@@ -1,99 +1,91 @@
<?php
/**
*/
namespace addon\fenxiao\api\controller;
use addon\fenxiao\model\Config;
use addon\fenxiao\model\FenxiaoApply;
use addon\fenxiao\model\Fenxiao;
use app\api\controller\BaseApi;
/**
* 申请分销商
*/
class Apply extends BaseApi
{
/**
* 判断分销商名称是否存在
*/
public function existFenxiaoName()
{
$token = $this->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);
}
<?php
namespace addon\fenxiao\api\controller;
use addon\fenxiao\model\Config;
use addon\fenxiao\model\FenxiaoApply;
use addon\fenxiao\model\Fenxiao;
use app\api\controller\BaseApi;
/**
* 申请分销商
*/
class Apply extends BaseApi
{
/**
* 判断分销商名称是否存在
*/
public function existFenxiaoName()
{
$token = $this->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);
}
}

View File

@@ -1,127 +1,119 @@
<?php
/**
*/
namespace addon\fenxiao\api\controller;
use app\api\controller\BaseApi;
use addon\fenxiao\model\Config as ConfigModel;
use app\model\goods\Goods;
use app\model\system\Document;
/**
* 分销相关配置
*/
class Config extends BaseApi
{
/**
* 提现配置
*/
public function withdraw()
{
$config = new ConfigModel();
$res = $config->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);
}
<?php
namespace addon\fenxiao\api\controller;
use app\api\controller\BaseApi;
use addon\fenxiao\model\Config as ConfigModel;
use app\model\goods\Goods;
use app\model\system\Document;
/**
* 分销相关配置
*/
class Config extends BaseApi
{
/**
* 提现配置
*/
public function withdraw()
{
$config = new ConfigModel();
$res = $config->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);
}
}

View File

@@ -1,407 +1,399 @@
<?php
/**
*/
namespace addon\fenxiao\api\controller;
use addon\fenxiao\model\Config;
use addon\fenxiao\model\Fenxiao as FenxiaoModel;
use addon\fenxiao\model\FenxiaoLevel;
use addon\fenxiao\model\FenxiaoOrder as FenxiaoOrderModel;
use addon\fenxiao\model\Poster;
use addon\fenxiao\model\PosterTemplate as PosterTemplateModel;
use app\api\controller\BaseApi;
use app\model\member\Member;
use Carbon\Carbon;
use think\facade\Db;
/**
* 分销相关信息
*/
class Fenxiao extends BaseApi
{
/**
* 获取分销商信息
*/
public function detail()
{
$token = $this->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);
}
<?php
namespace addon\fenxiao\api\controller;
use addon\fenxiao\model\Config;
use addon\fenxiao\model\Fenxiao as FenxiaoModel;
use addon\fenxiao\model\FenxiaoLevel;
use addon\fenxiao\model\FenxiaoOrder as FenxiaoOrderModel;
use addon\fenxiao\model\Poster;
use addon\fenxiao\model\PosterTemplate as PosterTemplateModel;
use app\api\controller\BaseApi;
use app\model\member\Member;
use Carbon\Carbon;
use think\facade\Db;
/**
* 分销相关信息
*/
class Fenxiao extends BaseApi
{
/**
* 获取分销商信息
*/
public function detail()
{
$token = $this->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);
}
}

View File

@@ -1,170 +1,162 @@
<?php
/**
*/
namespace addon\fenxiao\api\controller;
use addon\fenxiao\model\Config as ConfigModel;
use addon\fenxiao\model\Fenxiao as FenxiaoModel;
use addon\fenxiao\model\FenxiaoGoodsCollect as FenxiaoGoodsCollectModel;
use addon\fenxiao\model\FenxiaoGoodsSku as FenxiaoGoodsSkuModel;
use addon\fenxiao\model\FenxiaoLevel;
use app\api\controller\BaseApi;
/**
* 分销商品
*/
class Goods extends BaseApi
{
/**
* 分销商品详情
* @param int $id
* @return false|string
*/
public function detail($id = 0)
{
$token = $this->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);
}
<?php
namespace addon\fenxiao\api\controller;
use addon\fenxiao\model\Config as ConfigModel;
use addon\fenxiao\model\Fenxiao as FenxiaoModel;
use addon\fenxiao\model\FenxiaoGoodsCollect as FenxiaoGoodsCollectModel;
use addon\fenxiao\model\FenxiaoGoodsSku as FenxiaoGoodsSkuModel;
use addon\fenxiao\model\FenxiaoLevel;
use app\api\controller\BaseApi;
/**
* 分销商品
*/
class Goods extends BaseApi
{
/**
* 分销商品详情
* @param int $id
* @return false|string
*/
public function detail($id = 0)
{
$token = $this->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);
}
}

View File

@@ -1,138 +1,130 @@
<?php
/**
*/
namespace addon\fenxiao\api\controller;
use addon\fenxiao\model\FenxiaoGoodsSku;
use addon\fenxiao\model\FenxiaoLevel;
use app\api\controller\BaseApi;
use addon\fenxiao\model\Fenxiao as FenxiaoModel;
use addon\fenxiao\model\FenxiaoGoodsCollect as FenxiaoGoodsCollectModel;
/**
* 分销商关注商品
*/
class Goodscollect extends BaseApi
{
/**
* 添加分销商关注商品
* @return false|string
*/
public function add()
{
$token = $this->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);
}
<?php
namespace addon\fenxiao\api\controller;
use addon\fenxiao\model\FenxiaoGoodsSku;
use addon\fenxiao\model\FenxiaoLevel;
use app\api\controller\BaseApi;
use addon\fenxiao\model\Fenxiao as FenxiaoModel;
use addon\fenxiao\model\FenxiaoGoodsCollect as FenxiaoGoodsCollectModel;
/**
* 分销商关注商品
*/
class Goodscollect extends BaseApi
{
/**
* 添加分销商关注商品
* @return false|string
*/
public function add()
{
$token = $this->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);
}
}

View File

@@ -1,42 +1,34 @@
<?php
/**
*/
namespace addon\fenxiao\api\controller;
use addon\fenxiao\model\FenxiaoLevel;
use app\api\controller\BaseApi;
/**
* 分销等级
*/
class Level extends BaseApi
{
/**
* 分销商等级列表
*/
public function lists()
{
$token = $this->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);
}
<?php
namespace addon\fenxiao\api\controller;
use addon\fenxiao\model\FenxiaoLevel;
use app\api\controller\BaseApi;
/**
* 分销等级
*/
class Level extends BaseApi
{
/**
* 分销商等级列表
*/
public function lists()
{
$token = $this->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);
}
}

View File

@@ -1,114 +1,106 @@
<?php
/**
*/
namespace addon\fenxiao\api\controller;
use app\api\controller\BaseApi;
use addon\fenxiao\model\FenxiaoOrder as FenxiaoOrderModel;
use addon\fenxiao\model\Fenxiao;
/**
* 分销订单
*/
class Order extends BaseApi
{
/**
* 信息
* @return false|string
*/
public function info()
{
$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'));
$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);
}
<?php
namespace addon\fenxiao\api\controller;
use app\api\controller\BaseApi;
use addon\fenxiao\model\FenxiaoOrder as FenxiaoOrderModel;
use addon\fenxiao\model\Fenxiao;
/**
* 分销订单
*/
class Order extends BaseApi
{
/**
* 信息
* @return false|string
*/
public function info()
{
$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'));
$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);
}
}

View File

@@ -1,122 +1,114 @@
<?php
/**
*/
namespace addon\fenxiao\api\controller;
use addon\fenxiao\model\FenxiaoWithdraw;
use app\api\controller\BaseApi;
use app\model\member\Member;
/**
* 分销提现
*/
class Withdraw extends BaseApi
{
/**
* 提现记录分页
* @return false|string
*/
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;
$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);
}
<?php
namespace addon\fenxiao\api\controller;
use addon\fenxiao\model\FenxiaoWithdraw;
use app\api\controller\BaseApi;
use app\model\member\Member;
/**
* 分销提现
*/
class Withdraw extends BaseApi
{
/**
* 提现记录分页
* @return false|string
*/
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;
$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);
}
}

View File

@@ -1,124 +1,116 @@
<?php
/**
*/
return [
// 自定义模板页面类型,格式:[ 'title' => '页面类型名称', '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' => []
<?php
return [
// 自定义模板页面类型,格式:[ 'title' => '页面类型名称', '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' => []
];

View File

@@ -1,23 +1,15 @@
<?php
/**
*/
namespace addon\fenxiao\event;
/**
* 增加默认自定义数据:分销市场
*/
class AddSiteDiyView
{
public function handle($param)
{
}
<?php
namespace addon\fenxiao\event;
/**
* 增加默认自定义数据:分销市场
*/
class AddSiteDiyView
{
public function handle($param)
{
}
}

View File

@@ -1,56 +1,48 @@
<?php
/**
*/
namespace addon\fenxiao\event;
use addon\fenxiao\model\FenxiaoLevel as FenxiaoLevelModel;
/**
* 增加默认分销商等级
*/
class AddSiteFenxiaoLevel
{
public function handle($param)
{
if (!empty($param[ 'site_id' ])) {
$model = new FenxiaoLevelModel();
$default_level = $model->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;
}
}
}
<?php
namespace addon\fenxiao\event;
use addon\fenxiao\model\FenxiaoLevel as FenxiaoLevelModel;
/**
* 增加默认分销商等级
*/
class AddSiteFenxiaoLevel
{
public function handle($param)
{
if (!empty($param[ 'site_id' ])) {
$model = new FenxiaoLevelModel();
$default_level = $model->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;
}
}
}
}

View File

@@ -1,34 +1,26 @@
<?php
/**
*/
namespace addon\fenxiao\event;
use addon\fenxiao\model\Fenxiao as FenxiaoModel;
/**
* 活动展示
*/
class AlterShareRelation
{
/**
* 用户分销上下级关系
* @param $param
* @return array|void
*/
public function handle($param)
{
$fenxiao_model = new FenxiaoModel();
return $fenxiao_model->bindRelation([
'site_id' => $param[ 'site_id' ],
'member_id' => $param[ 'member_id' ],
'action' => 'alter_share_relation',
]);
}
<?php
namespace addon\fenxiao\event;
use addon\fenxiao\model\Fenxiao as FenxiaoModel;
/**
* 活动展示
*/
class AlterShareRelation
{
/**
* 用户分销上下级关系
* @param $param
* @return array|void
*/
public function handle($param)
{
$fenxiao_model = new FenxiaoModel();
return $fenxiao_model->bindRelation([
'site_id' => $param[ 'site_id' ],
'member_id' => $param[ 'member_id' ],
'action' => 'alter_share_relation',
]);
}
}

View File

@@ -1,31 +1,23 @@
<?php
/**
*/
namespace addon\fenxiao\event;
use addon\fenxiao\model\Fenxiao;
/**
* 分销商升级
*/
class FenxiaoUpgrade
{
/**
* 分销商升级
* @param $fenxiao_id
*/
public function handle($fenxiao_id)
{
if (!empty($fenxiao_id)) {
$fenxiao = new Fenxiao();
$fenxiao->fenxiaoUpgrade($fenxiao_id);
}
}
<?php
namespace addon\fenxiao\event;
use addon\fenxiao\model\Fenxiao;
/**
* 分销商升级
*/
class FenxiaoUpgrade
{
/**
* 分销商升级
* @param $fenxiao_id
*/
public function handle($fenxiao_id)
{
if (!empty($fenxiao_id)) {
$fenxiao = new Fenxiao();
$fenxiao->fenxiaoUpgrade($fenxiao_id);
}
}
}

View File

@@ -1,41 +1,33 @@
<?php
/**
*/
namespace addon\fenxiao\event;
use app\model\goods\Goods as GoodsModel;
/**
* 商品分类
*/
class GoodsListCategoryIds
{
/**
* 商品营销活动信息
* @param $param
* @return array
*/
public function handle($param)
{
if (empty($param[ 'promotion' ]) || $param[ 'promotion' ] != 'fenxiao') return [];
$condition = [
[ 'is_delete', '=', 0 ],
[ 'site_id', '=', $param[ 'site_id' ] ],
[ 'is_fenxiao', '=', 1 ],
[ 'goods_state', '=', 1 ]
];
$model = new GoodsModel();
$res = $model->getGoodsCategoryIds($condition);
return $res;
}
<?php
namespace addon\fenxiao\event;
use app\model\goods\Goods as GoodsModel;
/**
* 商品分类
*/
class GoodsListCategoryIds
{
/**
* 商品营销活动信息
* @param $param
* @return array
*/
public function handle($param)
{
if (empty($param[ 'promotion' ]) || $param[ 'promotion' ] != 'fenxiao') return [];
$condition = [
[ 'is_delete', '=', 0 ],
[ 'site_id', '=', $param[ 'site_id' ] ],
[ 'is_fenxiao', '=', 1 ],
[ 'goods_state', '=', 1 ]
];
$model = new GoodsModel();
$res = $model->getGoodsCategoryIds($condition);
return $res;
}
}

View File

@@ -1,61 +1,53 @@
<?php
/**
*/
namespace addon\fenxiao\event;
use app\model\goods\Goods as GoodsModel;
/**
* 商品营销活动信息
*/
class GoodsListPromotion
{
/**
* 商品营销活动信息
* @param $param
* @return array
*/
public function handle($param)
{
if (empty($param[ 'promotion' ]) || $param[ 'promotion' ] != 'fenxiao') return [];
$alias = 'g';
$join = [];
$condition = [
[ 'g.is_delete', '=', 0 ],
[ 'g.site_id', '=', $param[ 'site_id' ] ],
[ 'g.is_fenxiao', '=', 1 ],
[ 'g.goods_state', '=', 1 ]
];
if (!empty($param[ 'goods_name' ])) {
$condition[] = [ 'g.goods_name', 'like', '%' . $param[ 'goods_name' ] . '%' ];
}
if (!empty($param[ 'select_type' ]) && $param[ 'select_type' ] == 'selected' && isset($param[ 'goods_ids' ])) {
$condition[] = [ 'g.goods_id', 'in', $param[ 'goods_ids' ] ];
}
if (!empty($param[ 'category_id' ])) {
$condition[] = [ 'g.category_id', 'like', '%,' . $param[ 'category_id' ] . ',%' ];
}
if (!empty($param[ 'label_id' ])) {
$condition[] = [ 'g.label_id', '=', $param[ 'label_id' ] ];
}
if (!empty($param[ 'goods_class' ])) {
$condition[] = [ 'g.goods_class', '=', $param[ 'goods_class' ] ];
}
$model = new GoodsModel();
$field = 'g.goods_id,g.goods_name,g.goods_class_name,g.goods_image,g.price,g.goods_stock,g.create_time,g.is_virtual,g.sku_id';
$list = $model->getGoodsPageList($condition, $param[ 'page' ], $param[ 'page_size' ], 'g.create_time desc', $field, $alias, $join);
return $list;
}
<?php
namespace addon\fenxiao\event;
use app\model\goods\Goods as GoodsModel;
/**
* 商品营销活动信息
*/
class GoodsListPromotion
{
/**
* 商品营销活动信息
* @param $param
* @return array
*/
public function handle($param)
{
if (empty($param[ 'promotion' ]) || $param[ 'promotion' ] != 'fenxiao') return [];
$alias = 'g';
$join = [];
$condition = [
[ 'g.is_delete', '=', 0 ],
[ 'g.site_id', '=', $param[ 'site_id' ] ],
[ 'g.is_fenxiao', '=', 1 ],
[ 'g.goods_state', '=', 1 ]
];
if (!empty($param[ 'goods_name' ])) {
$condition[] = [ 'g.goods_name', 'like', '%' . $param[ 'goods_name' ] . '%' ];
}
if (!empty($param[ 'select_type' ]) && $param[ 'select_type' ] == 'selected' && isset($param[ 'goods_ids' ])) {
$condition[] = [ 'g.goods_id', 'in', $param[ 'goods_ids' ] ];
}
if (!empty($param[ 'category_id' ])) {
$condition[] = [ 'g.category_id', 'like', '%,' . $param[ 'category_id' ] . ',%' ];
}
if (!empty($param[ 'label_id' ])) {
$condition[] = [ 'g.label_id', '=', $param[ 'label_id' ] ];
}
if (!empty($param[ 'goods_class' ])) {
$condition[] = [ 'g.goods_class', '=', $param[ 'goods_class' ] ];
}
$model = new GoodsModel();
$field = 'g.goods_id,g.goods_name,g.goods_class_name,g.goods_image,g.price,g.goods_stock,g.create_time,g.is_virtual,g.sku_id';
$list = $model->getGoodsPageList($condition, $param[ 'page' ], $param[ 'page_size' ], 'g.create_time desc', $field, $alias, $join);
return $list;
}
}

View File

@@ -1,57 +1,49 @@
<?php
/**
*/
namespace addon\fenxiao\event;
use addon\fenxiao\model\FenxiaoLevel as FenxiaoLevelModel;
/**
* 应用安装
*/
class Install
{
/**
* 执行安装
*/
public function handle()
{
$site_id = request()->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();
}
<?php
namespace addon\fenxiao\event;
use addon\fenxiao\model\FenxiaoLevel as FenxiaoLevelModel;
/**
* 应用安装
*/
class Install
{
/**
* 执行安装
*/
public function handle()
{
$site_id = request()->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();
}
}

View File

@@ -1,35 +1,27 @@
<?php
/**
*/
namespace addon\fenxiao\event;
/**
* 会员账户变化来源类型
*/
class MemberAccountFromType
{
public function handle($data)
{
$from_type = [
'balance_money' => [
'fenxiao' => [
'type_name' => '分销佣金',
'type_url' => '',
],
],
];
if ($data == '') {
return $from_type;
} else {
return $from_type[$data] ?? [];
}
}
<?php
namespace addon\fenxiao\event;
/**
* 会员账户变化来源类型
*/
class MemberAccountFromType
{
public function handle($data)
{
$from_type = [
'balance_money' => [
'fenxiao' => [
'type_name' => '分销佣金',
'type_url' => '',
],
],
];
if ($data == '') {
return $from_type;
} else {
return $from_type[$data] ?? [];
}
}
}

View File

@@ -1,31 +1,23 @@
<?php
/**
*/
namespace addon\fenxiao\event;
use addon\fenxiao\model\Fenxiao;
/**
* 会员注销
*/
class MemberCancel
{
/**
* @param $param
* @return array
*/
public function handle($param)
{
$fenxiao_model = new Fenxiao();
$res = $fenxiao_model->CronMemberCancel($param[ 'member_id' ], $param[ 'site_id' ]);
return $res;
}
<?php
namespace addon\fenxiao\event;
use addon\fenxiao\model\Fenxiao;
/**
* 会员注销
*/
class MemberCancel
{
/**
* @param $param
* @return array
*/
public function handle($param)
{
$fenxiao_model = new Fenxiao();
$res = $fenxiao_model->CronMemberCancel($param[ 'member_id' ], $param[ 'site_id' ]);
return $res;
}
}

View File

@@ -1,32 +1,23 @@
<?php
/**
*/
namespace addon\fenxiao\event;
use addon\fenxiao\model\Fenxiao;
/**
* 活动展示
*/
class MemberRegister
{
/**
* 会员注册
* @param $param
*/
public function handle($param)
{
if (isset($param['member_id']) && !empty($param['member_id'])) {
$fenxiao = new Fenxiao();
$fenxiao->memberRegister($param['member_id'], $param['site_id']);
}
}
<?php
namespace addon\fenxiao\event;
use addon\fenxiao\model\Fenxiao;
/**
* 活动展示
*/
class MemberRegister
{
/**
* 会员注册
* @param $param
*/
public function handle($param)
{
if (isset($param['member_id']) && !empty($param['member_id'])) {
$fenxiao = new Fenxiao();
$fenxiao->memberRegister($param['member_id'], $param['site_id']);
}
}
}

View File

@@ -1,35 +1,27 @@
<?php
/**
*/
namespace addon\fenxiao\event;
use addon\fenxiao\model\Fenxiao as FenxiaoModel;
use app\model\order\OrderCommon;
/**
* 订单完成事件
*/
class OrderComplete
{
/**
* 订单创建后绑定上下线关系
* @param $param
*/
public function handle($param)
{
$order_id = $param[ 'order_id' ];
$order_model = new OrderCommon();
$order_info = $order_model->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' ]);
}
}
<?php
namespace addon\fenxiao\event;
use addon\fenxiao\model\Fenxiao as FenxiaoModel;
use app\model\order\OrderCommon;
/**
* 订单完成事件
*/
class OrderComplete
{
/**
* 订单创建后绑定上下线关系
* @param $param
*/
public function handle($param)
{
$order_id = $param[ 'order_id' ];
$order_model = new OrderCommon();
$order_info = $order_model->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' ]);
}
}
}

View File

@@ -1,38 +1,30 @@
<?php
/**
*/
namespace addon\fenxiao\event;
use addon\fenxiao\model\Fenxiao as FenxiaoModel;
use app\model\order\OrderCommon;
/**
* 订单创建事件
*/
class OrderCreateAfter
{
/**
* 订单创建后绑定上下线关系
* @param $param
* @return array|void
*/
public function handle($param)
{
$order_info = $param['create_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',
]);
}
}
<?php
namespace addon\fenxiao\event;
use addon\fenxiao\model\Fenxiao as FenxiaoModel;
use app\model\order\OrderCommon;
/**
* 订单创建事件
*/
class OrderCreateAfter
{
/**
* 订单创建后绑定上下线关系
* @param $param
* @return array|void
*/
public function handle($param)
{
$order_info = $param['create_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',
]);
}
}
}

View File

@@ -1,32 +1,24 @@
<?php
/**
*/
namespace addon\fenxiao\event;
use addon\fenxiao\model\FenxiaoOrder;
/**
* 活动类型
*/
class OrderGoodsRefund
{
/**
* 活动类型
* @param $data
* @return array
*/
public function handle($data)
{
$order_model = new FenxiaoOrder();
$res = $order_model->refund($data);
return $res;
}
<?php
namespace addon\fenxiao\event;
use addon\fenxiao\model\FenxiaoOrder;
/**
* 活动类型
*/
class OrderGoodsRefund
{
/**
* 活动类型
* @param $data
* @return array
*/
public function handle($data)
{
$order_model = new FenxiaoOrder();
$res = $order_model->refund($data);
return $res;
}
}

View File

@@ -1,43 +1,34 @@
<?php
/**
*/
namespace addon\fenxiao\event;
use addon\fenxiao\model\FenxiaoOrder;
use addon\fenxiao\model\Fenxiao as FenxiaoModel;
use think\facade\Log;
/**
* 活动展示
*/
class OrderPayAfter
{
/**
* 订单结算
*/
public function handle($order)
{
//先检测是否需要绑定上下线
$fenxiao_model = new FenxiaoModel();
$fenxiao_model->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);
}
<?php
namespace addon\fenxiao\event;
use addon\fenxiao\model\FenxiaoOrder;
use addon\fenxiao\model\Fenxiao as FenxiaoModel;
use think\facade\Log;
/**
* 活动展示
*/
class OrderPayAfter
{
/**
* 订单结算
*/
public function handle($order)
{
//先检测是否需要绑定上下线
$fenxiao_model = new FenxiaoModel();
$fenxiao_model->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);
}
}

View File

@@ -1,34 +1,25 @@
<?php
/**
*/
namespace addon\fenxiao\event;
use addon\fenxiao\model\FenxiaoOrder;
/**
* 活动类型
*/
class OrderSettlement
{
/**
* 活动类型
* @param $data
* @return array
*/
public function handle($data)
{
$fenxiao_order_model = new FenxiaoOrder();
$fenxiao_order_model->settlement($data['order_id']);
$res = $fenxiao_order_model->calculateOrder($data['order_id']);
return $res;
}
<?php
namespace addon\fenxiao\event;
use addon\fenxiao\model\FenxiaoOrder;
/**
* 活动类型
*/
class OrderSettlement
{
/**
* 活动类型
* @param $data
* @return array
*/
public function handle($data)
{
$fenxiao_order_model = new FenxiaoOrder();
$fenxiao_order_model->settlement($data['order_id']);
$res = $fenxiao_order_model->calculateOrder($data['order_id']);
return $res;
}
}

View File

@@ -1,40 +1,32 @@
<?php
/**
*/
namespace addon\fenxiao\event;
use addon\fenxiao\model\Fenxiao as FenxiaoModel;
use addon\presale\model\PresaleOrder;
/**
* 预售订单创建
*/
class PresaleOrderCreate
{
/**
* 订单创建后绑定上下线关系
* @param $param
* @return array|void
*/
public function handle($param)
{
$id = $param[ 'id' ];
$order_model = new PresaleOrder();
$order_info = $order_model->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',
]);
}
}
<?php
namespace addon\fenxiao\event;
use addon\fenxiao\model\Fenxiao as FenxiaoModel;
use addon\presale\model\PresaleOrder;
/**
* 预售订单创建
*/
class PresaleOrderCreate
{
/**
* 订单创建后绑定上下线关系
* @param $param
* @return array|void
*/
public function handle($param)
{
$id = $param[ 'id' ];
$order_model = new PresaleOrder();
$order_info = $order_model->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',
]);
}
}
}

View File

@@ -1,26 +1,18 @@
<?php
/**
*/
namespace addon\fenxiao\event;
/**
* 活动类型
*/
class PromotionType
{
/**
* 活动类型
* @return array
*/
public function handle()
{
return [ "name" => "分销", "type" => "fenxiao" ];
}
<?php
namespace addon\fenxiao\event;
/**
* 活动类型
*/
class PromotionType
{
/**
* 活动类型
* @return array
*/
public function handle()
{
return [ "name" => "分销", "type" => "fenxiao" ];
}
}

View File

@@ -1,46 +1,38 @@
<?php
/**
*/
namespace addon\fenxiao\event;
/**
* 活动展示
*/
class ShowPromotion
{
/**
* 活动展示
* @return array
*/
public function handle()
{
$data = [
'shop' => [
[
//插件名称
'name' => 'fenxiao',
//店铺端展示分类 shop:营销活动 member:互动营销
'show_type' => 'member',
//展示主题
'title' => '分销',
//展示介绍
'description' => '让客户为您推广销售',
//展示图标
'icon' => 'addon/fenxiao/icon.png',
//跳转链接
'url' => 'fenxiao://shop/fenxiao/index',
]
]
];
return $data;
}
<?php
namespace addon\fenxiao\event;
/**
* 活动展示
*/
class ShowPromotion
{
/**
* 活动展示
* @return array
*/
public function handle()
{
$data = [
'shop' => [
[
//插件名称
'name' => 'fenxiao',
//店铺端展示分类 shop:营销活动 member:互动营销
'show_type' => 'member',
//展示主题
'title' => '分销',
//展示介绍
'description' => '让客户为您推广销售',
//展示图标
'icon' => 'addon/fenxiao/icon.png',
//跳转链接
'url' => 'fenxiao://shop/fenxiao/index',
]
]
];
return $data;
}
}

View File

@@ -1,25 +1,17 @@
<?php
/**
*/
namespace addon\fenxiao\event;
/**
* 应用卸载
*/
class UnInstall
{
/**
* 执行卸载
*/
public function handle()
{
return success();
}
<?php
namespace addon\fenxiao\event;
/**
* 应用卸载
*/
class UnInstall
{
/**
* 执行卸载
*/
public function handle()
{
return success();
}
}

View File

@@ -1,27 +1,19 @@
<?php
/**
*/
namespace addon\fenxiao\event;
use addon\fenxiao\model\share\WchatShare as ShareModel;
/**
* 获取分享配置
*/
class WchatShareConfig
{
public function handle($param)
{
$share_model = new ShareModel();
return $share_model->getShareConfig($param);
}
<?php
namespace addon\fenxiao\event;
use addon\fenxiao\model\share\WchatShare as ShareModel;
/**
* 获取分享配置
*/
class WchatShareConfig
{
public function handle($param)
{
$share_model = new ShareModel();
return $share_model->getShareConfig($param);
}
}

View File

@@ -1,28 +1,19 @@
<?php
/**
*/
namespace addon\fenxiao\event;
use addon\fenxiao\model\share\WchatShare as ShareModel;
/**
* 获取分享数据
*/
class WchatShareData
{
public function handle($param)
{
$share_model = new ShareModel();
return $share_model->getShareData($param);
}
<?php
namespace addon\fenxiao\event;
use addon\fenxiao\model\share\WchatShare as ShareModel;
/**
* 获取分享数据
*/
class WchatShareData
{
public function handle($param)
{
$share_model = new ShareModel();
return $share_model->getShareData($param);
}
}

View File

@@ -1,28 +1,19 @@
<?php
/**
*/
namespace addon\fenxiao\event;
use addon\fenxiao\model\share\WeappShare as ShareModel;
/**
* 获取分享配置
*/
class WeappShareConfig
{
public function handle($param)
{
$share_model = new ShareModel();
return $share_model->getShareConfig($param);
}
<?php
namespace addon\fenxiao\event;
use addon\fenxiao\model\share\WeappShare as ShareModel;
/**
* 获取分享配置
*/
class WeappShareConfig
{
public function handle($param)
{
$share_model = new ShareModel();
return $share_model->getShareConfig($param);
}
}

View File

@@ -1,28 +1,19 @@
<?php
/**
*/
namespace addon\fenxiao\event;
use addon\fenxiao\model\share\WeappShare as ShareModel;
/**
* 获取分享数据
*/
class WeappShareData
{
public function handle($param)
{
$share_model = new ShareModel();
return $share_model->getShareData($param);
}
<?php
namespace addon\fenxiao\event;
use addon\fenxiao\model\share\WeappShare as ShareModel;
/**
* 获取分享数据
*/
class WeappShareData
{
public function handle($param)
{
$share_model = new ShareModel();
return $share_model->getShareData($param);
}
}

View File

@@ -1,337 +1,329 @@
<?php
/**
*/
namespace addon\fenxiao\model;
use app\model\system\Config as ConfigModel;
use app\model\BaseModel;
use app\model\system\Document;
/**
* 微信小程序配置
*/
class Config extends BaseModel
{
/******************************************************************** 分销基本配置 start ****************************************************************************/
/**
* 设置分销基本配置
* @param $data
* @param $is_use
* @param $site_id
* @return array
*/
public function setFenxiaoBasicsConfig($data, $is_use, $site_id)
{
$config = new ConfigModel();
//分销基本设置
$basics_data = [
'level' => $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 ****************************************************************************/
<?php
namespace addon\fenxiao\model;
use app\model\system\Config as ConfigModel;
use app\model\BaseModel;
use app\model\system\Document;
/**
* 微信小程序配置
*/
class Config extends BaseModel
{
/******************************************************************** 分销基本配置 start ****************************************************************************/
/**
* 设置分销基本配置
* @param $data
* @param $is_use
* @param $site_id
* @return array
*/
public function setFenxiaoBasicsConfig($data, $is_use, $site_id)
{
$config = new ConfigModel();
//分销基本设置
$basics_data = [
'level' => $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 ****************************************************************************/
}

Some files were not shown because too many files have changed in this diff Show More