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

@@ -23,10 +23,12 @@ cp .env.example .env.development
```bash ```bash
# 本地部署时,需要将 APP_ENV 设置为 local, 并指定 docker-compose.local.yml 文件 # 本地部署时,需要将 APP_ENV 设置为 local, 并指定 docker-compose.local.yml 文件
docker-compose --project-name shop_local --env-file .env.local -f docker-compose.local.yml up -d docker-compose --env-file .env.local -f docker-compose.local.yml up -d
# docker-compose --project-name shop_local --env-file .env.local -f docker-compose.local.yml up -d
# docker-compose down 命令,用来停止并删除容器 # docker-compose down 命令,用来停止并删除容器
docker-compose --project-name shop_local down -v docker-compose -f docker-compose.local.yml down -v
# docker-compose --project-name shop_local down -v
``` ```

View File

@@ -1,38 +1,30 @@
<?php <?php
/** return [
// 自定义模板页面类型,格式:[ 'title' => '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据json格式' ]
'template' => [],
// 后台自定义组件——装修
'util' => [],
*/
return [ // 自定义页面路径
'link' => [],
// 自定义模板页面类型,格式:[ 'title' => '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据json格式' ]
'template' => [], // 自定义图标库
'icon_library' => [],
// 后台自定义组件——装修
'util' => [], // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ]多个逗号隔开自定义组件名称前缀必须是diy-,也可以引用第三方组件
'component' => [],
// 自定义页面路径
'link' => [], // uni-app 页面,多个逗号隔开
'pages' => [],
// 自定义图标库
'icon_library' => [], // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
'info' => [],
// uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ]多个逗号隔开自定义组件名称前缀必须是diy-,也可以引用第三方组件
'component' => [], // 主题风格配色格式可以自由定义扩展【在uni-app中通过this.themeStyle... 获取定义的颜色字段例如this.themeStyle.main_color】
'theme' => [],
// uni-app 页面,多个逗号隔开
'pages' => [], // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据json格式] ]
'data' => []
// 模板信息,格式:'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 <?php
/** return [
'name' => 'alioss',
'title' => '阿里云OSS',
'description' => '阿里云OSS',
'type' => 'system', //插件类型 system :系统插件(自动安装), business:业务插件 promotion:营销插件 tool:工具插件
'status' => 1,
'author' => '',
'version' => '5.3.1',
*/ 'version_no' => '525231212001',
return [ 'content' => '',
'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 <?php
/**
namespace addon\alioss\event;
use addon\alioss\model\Alioss;
use addon\alioss\model\Config;
*/ /**
* 删除阿里云图片
*/
namespace addon\alioss\event; class ClearAlbumPic
{
use addon\alioss\model\Alioss; public function handle($params)
use addon\alioss\model\Config; {
$config_model = new Config();
/** $alioss_model = new Alioss();
* 删除阿里云图片
*/ $config = $config_model->getAliossConfig($params[ 'site_id' ]);
class ClearAlbumPic if (!empty($config[ 'data' ])) {
{ if (!empty($config[ 'data' ][ 'value' ][ 'endpoint' ]) && strpos($params[ 'pic_path' ], $config[ 'data' ][ 'value' ][ 'endpoint' ]) === 0) {
public function handle($params) $result = $alioss_model->deleteAlbumPic($params[ 'pic_path' ], $config[ 'data' ][ 'value' ][ 'endpoint' ]);
{ return $result;
$config_model = new Config(); }
$alioss_model = new Alioss(); 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' ]);
$config = $config_model->getAliossConfig($params[ 'site_id' ]); return $result;
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 <?php
/**
namespace addon\alioss\event;
use addon\alioss\model\Config;
/**
*/ * 关闭云上传
*/
class CloseOss
namespace addon\alioss\event; {
public function handle()
use addon\alioss\model\Config; {
$config_model = new Config();
/** $result = $config_model->modifyConfigIsUse(0);
* 关闭云上传 return $result;
*/ }
class CloseOss
{
public function handle()
{
$config_model = new Config();
$result = $config_model->modifyConfigIsUse(0);
return $result;
}
} }

View File

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

View File

@@ -1,33 +1,25 @@
<?php <?php
/**
namespace addon\alioss\event;
/**
* 云上传方式
*/
*/ class OssType
{
/**
namespace addon\alioss\event; * 短信发送方式方式及配置
*/
/** public function handle()
* 云上传方式 {
*/ $info = array(
class OssType "sms_type" => "alioss",
{ "sms_type_name" => "阿里云上传",
/** "edit_url" => "alioss://shop/config/config",
* 短信发送方式方式及配置 "shop_url" => "alioss://shop/config/config",
*/ "desc" => "阿里云上传"
public function handle() );
{ return $info;
$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 <?php
/**
namespace addon\alioss\event;
use addon\alioss\model\Alioss;
/**
*/ * 云上传方式
*/
class Put
namespace addon\alioss\event; {
/**
use addon\alioss\model\Alioss; * @param $param
* @return array
/** */
* 云上传方式 public function handle($param)
*/ {
class Put $qiniu_model = new Alioss();
{ $result = $qiniu_model->putFile($param);
/** return $result;
* @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 <?php
/**
namespace addon\alioss\event;
/**
* 应用卸载
*/
class UnInstall
*/ {
/**
* 执行卸载
namespace addon\alioss\event; */
public function handle()
/** {
* 应用卸载 return success();
*/ }
class UnInstall
{
/**
* 执行卸载
*/
public function handle()
{
return success();
}
} }

View File

@@ -1,146 +1,138 @@
<?php <?php
/**
namespace addon\alioss\model;
use app\model\BaseModel;
use OSS\Core\OssException;
use OSS\OssClient;
use think\facade\Log;
*/
/**
namespace addon\alioss\model; * 阿里云OSS上传
*/
use app\model\BaseModel; class Alioss extends BaseModel
use OSS\Core\OssException; {
use OSS\OssClient;
use think\facade\Log; /**
* 字节组上传
/** * @param $data
* 阿里云OSS上传 * @param $key
*/ * @return array
class Alioss extends BaseModel */
{ public function put($param)
{
/** $data = $param['data'];
* 字节组上传 $key = $param['key'];
* @param $data $config_model = new Config();
* @param $key $config_result = $config_model->getAliossConfig();
* @return array $config = $config_result['data'];
*/
public function put($param) if ($config['is_use'] == 1) {
{ $config = $config['value'];
$data = $param['data']; $access_key_id = $config['access_key_id'];
$key = $param['key']; $access_key_secret = $config['access_key_secret'];
$config_model = new Config(); $bucket = $config['bucket'];
$config_result = $config_model->getAliossConfig(); $endpoint = $config['endpoint'];
$config = $config_result['data']; try {
$ossClient = new OssClient($access_key_id, $access_key_secret, $endpoint);
if ($config['is_use'] == 1) {
$config = $config['value']; $result = $ossClient->putObject($bucket, $key, $data);
$access_key_id = $config['access_key_id']; $is_domain = $config[ 'is_domain' ] ?? 0;
$access_key_secret = $config['access_key_secret']; $path = $is_domain > 0 ? $config[ 'domain' ] . '/' . $key : $result['info']['url'];
$bucket = $config['bucket']; $data = array (
$endpoint = $config['endpoint']; 'path' => $path,
try { // "path" => $result["info"]["url"],
$ossClient = new OssClient($access_key_id, $access_key_secret, $endpoint); 'domain' => $endpoint,
'bucket' => $bucket
$result = $ossClient->putObject($bucket, $key, $data); );
$is_domain = $config[ 'is_domain' ] ?? 0; return $this->success($data);
$path = $is_domain > 0 ? $config[ 'domain' ] . '/' . $key : $result['info']['url']; } catch (OssException $e) {
$data = array ( return $this->error('', $e->getErrorMessage());
'path' => $path, }
// "path" => $result["info"]["url"],
'domain' => $endpoint, }
'bucket' => $bucket }
);
return $this->success($data); /**
} catch (OssException $e) { * 设置阿里云OSS参数配置
return $this->error('', $e->getErrorMessage()); * @param unknown $filePath 上传图片路径
} * @param unknown $key 上传到阿里云后保存的文件名
*/
} public function putFile($param)
} {
$file_path = $param['file_path'];
/** $key = $param['key'];
* 设置阿里云OSS参数配置 $config_model = new Config();
* @param unknown $filePath 上传图片路径 $config = $config_model->getAliossConfig()['data'];
* @param unknown $key 上传到阿里云后保存的文件名 if ($config['is_use'] == 1) {
*/ $config = $config['value'];
public function putFile($param) $access_key_id = $config['access_key_id'];
{ $access_key_secret = $config['access_key_secret'];
$file_path = $param['file_path']; $bucket = $config['bucket'];
$key = $param['key']; //要上传的空间
$config_model = new Config(); $endpoint = $config['endpoint'];
$config = $config_model->getAliossConfig()['data']; try {
if ($config['is_use'] == 1) { $ossClient = new OssClient($access_key_id, $access_key_secret, $endpoint);
$config = $config['value']; $result = $ossClient->uploadFile($bucket, $key, $file_path);
$access_key_id = $config['access_key_id']; $is_domain = $config[ 'is_domain' ] ?? 0;
$access_key_secret = $config['access_key_secret']; $path = $is_domain > 0 ? $config[ 'domain' ] . '/' . $key : $result['info']['url'];
$bucket = $config['bucket']; $path = str_replace('http://', 'https://', $path);
//要上传的空间 //返回图片的完整URL
$endpoint = $config['endpoint']; $data = array (
try { // "path" => $this->subEndpoint($endpoint, $bucket)."/". $key,
$ossClient = new OssClient($access_key_id, $access_key_secret, $endpoint); 'path' => $path,
$result = $ossClient->uploadFile($bucket, $key, $file_path); 'domain' => $endpoint,
$is_domain = $config[ 'is_domain' ] ?? 0; 'bucket' => $bucket
$path = $is_domain > 0 ? $config[ 'domain' ] . '/' . $key : $result['info']['url']; );
$path = str_replace('http://', 'https://', $path); return $this->success($data);
//返回图片的完整URL } catch (\Exception $e) {
$data = array ( return $this->error('', $e->getMessage());
// "path" => $this->subEndpoint($endpoint, $bucket)."/". $key, }
'path' => $path, }
'domain' => $endpoint, }
'bucket' => $bucket
); public function subEndpoint($endpoint, $bucket)
return $this->success($data); {
} catch (\Exception $e) { if (strpos($endpoint, 'http://') === 0) {
return $this->error('', $e->getMessage()); $temp = 'http://';
} } else {
} $temp = 'https://';
} }
$temp_array = explode($temp, $endpoint);
public function subEndpoint($endpoint, $bucket) return $temp . $bucket . '.' . $temp_array[ 1 ];
{ }
if (strpos($endpoint, 'http://') === 0) {
$temp = 'http://'; /**
} else { * @param $file_path
$temp = 'https://'; * @return array
} * 删除阿里云图片
$temp_array = explode($temp, $endpoint); */
return $temp . $bucket . '.' . $temp_array[ 1 ]; public function deleteAlbumPic($file_path, $prefix)
} {
$config_model = new Config();
/** $config_result = $config_model->getAliossConfig();
* @param $file_path $config = $config_result['data'];
* @return array
* 删除阿里云图片 if (!empty($config)) {
*/ $config = $config['value'];
public function deleteAlbumPic($file_path, $prefix) $access_key_id = $config['access_key_id'];
{ $access_key_secret = $config['access_key_secret'];
$config_model = new Config(); $bucket = $config['bucket'];
$config_result = $config_model->getAliossConfig(); //要上传的空间
$config = $config_result['data']; $endpoint = $config['endpoint'];
try {
if (!empty($config)) { $ossClient = new OssClient($access_key_id, $access_key_secret, $endpoint);
$config = $config['value']; $ossClient->deleteObject($bucket, str_replace($prefix . '/', '', $file_path));
$access_key_id = $config['access_key_id']; $ossClient->deleteObject($bucket, str_replace($prefix . '/', '', img($file_path, 'big')));
$access_key_secret = $config['access_key_secret']; $ossClient->deleteObject($bucket, str_replace($prefix . '/', '', img($file_path, 'mid')));
$bucket = $config['bucket']; $ossClient->deleteObject($bucket, str_replace($prefix . '/', '', img($file_path, 'small')));
//要上传的空间
$endpoint = $config['endpoint']; return $this->success();
try { } catch (OssException $e) {
$ossClient = new OssClient($access_key_id, $access_key_secret, $endpoint); return $this->error('', $e->getErrorMessage());
$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 <?php
/**
namespace addon\alioss\model;
use app\model\system\Config as ConfigModel;
use app\model\BaseModel;
/**
*/ * 阿里云配置
*/
namespace addon\alioss\model; class Config extends BaseModel
{
use app\model\system\Config as ConfigModel; /**
use app\model\BaseModel; * 设置阿里云OSS上传配置
* array $data
/** */
* 阿里云配置 public function setAliossConfig($data, $status, $site_id = 1, $app_module = 'shop')
*/ {
class Config extends BaseModel if ($status == 1) {
{ event('CloseOss', []);//同步关闭所有云上传
/** }
* 设置阿里云OSS上传配置
* array $data $config = new ConfigModel();
*/ $res = $config->setConfig($data, '阿里云OSS上传配置', $status, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'ALIOSS_CONFIG' ] ]);
public function setAliossConfig($data, $status, $site_id = 1, $app_module = 'shop') return $res;
{ }
if ($status == 1) {
event('CloseOss', []);//同步关闭所有云上传 /**
} * 获取阿里云上传配置
*/
$config = new ConfigModel(); public function getAliossConfig($site_id = 1, $app_module = 'shop')
$res = $config->setConfig($data, '阿里云OSS上传配置', $status, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'ALIOSS_CONFIG' ] ]); {
return $res; $config = new ConfigModel();
} $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'ALIOSS_CONFIG' ] ]);
return $res;
/** }
* 获取阿里云上传配置
*/ /**
public function getAliossConfig($site_id = 1, $app_module = 'shop') * 配置阿里云开关状态
{ * @param $status
$config = new ConfigModel(); */
$res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'ALIOSS_CONFIG' ] ]); public function modifyConfigIsUse($status, $site_id = 1, $app_module = 'shop')
return $res; {
} $config = new ConfigModel();
$res = $config->modifyConfigIsUse($status, [ [ '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 <?php
/**
namespace addon\alioss\shop\controller;
use addon\alioss\model\Config as ConfigModel;
use app\shop\controller\BaseShop;
/**
*/ * 七牛云上传管理
*/
namespace addon\alioss\shop\controller; class Config extends BaseShop
{
use addon\alioss\model\Config as ConfigModel;
use app\shop\controller\BaseShop; /**
* 云上传配置
/** * @return mixed
* 七牛云上传管理 */
*/ public function config()
class Config extends BaseShop {
{ $config_model = new ConfigModel();
if (request()->isJson()) {
/** $bucket = input('bucket', '');
* 云上传配置 $access_key_id = input('access_key_id', '');
* @return mixed $access_key_secret = input('access_key_secret', '');
*/ $endpoint = input('endpoint', '');
public function config() $status = input('status', 0);
{ $domain = input('domain', '');
$config_model = new ConfigModel(); $is_domain = input('is_domain', 0);
if (request()->isJson()) {
$bucket = input('bucket', ''); $data = array (
$access_key_id = input('access_key_id', ''); 'bucket' => $bucket,
$access_key_secret = input('access_key_secret', ''); 'access_key_id' => $access_key_id,
$endpoint = input('endpoint', ''); 'access_key_secret' => $access_key_secret,
$status = input('status', 0); 'endpoint' => $endpoint,
$domain = input('domain', ''); 'domain' => $domain,
$is_domain = input('is_domain', 0); 'is_domain' => $is_domain
);
$data = array (
'bucket' => $bucket, $result = $config_model->setAliossConfig($data, $status, $this->site_id, $this->app_module);
'access_key_id' => $access_key_id, return $result;
'access_key_secret' => $access_key_secret, } else {
'endpoint' => $endpoint, $info_result = $config_model->getAliossConfig($this->site_id, $this->app_module);
'domain' => $domain, $info = $info_result['data'];
'is_domain' => $is_domain $this->assign('info', $info);
); return $this->fetch('config/config');
}
$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 <?php
/** return [
// 自定义模板页面类型,格式:[ 'title' => '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据json格式' ]
'template' => [],
// 后台自定义组件——装修
'util' => [],
*/
return [ // 自定义页面路径
'link' => [],
// 自定义模板页面类型,格式:[ 'title' => '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据json格式' ]
'template' => [], // 自定义图标库
'icon_library' => [],
// 后台自定义组件——装修
'util' => [], // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ]多个逗号隔开自定义组件名称前缀必须是diy-,也可以引用第三方组件
'component' => [],
// 自定义页面路径
'link' => [], // uni-app 页面,多个逗号隔开
'pages' => [],
// 自定义图标库
'icon_library' => [], // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
'info' => [],
// uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ]多个逗号隔开自定义组件名称前缀必须是diy-,也可以引用第三方组件
'component' => [], // 主题风格配色格式可以自由定义扩展【在uni-app中通过this.themeStyle... 获取定义的颜色字段例如this.themeStyle.main_color】
'theme' => [],
// uni-app 页面,多个逗号隔开
'pages' => [], // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据json格式] ]
'data' => []
// 模板信息,格式:'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 <?php
/** return [
'bind' => [
],
'listen' => [
//支付异步回调
*/ 'PayNotify' => [
return [ 'addon\alipay\event\PayNotify'
'bind' => [ ],
//支付方式,后台查询
], 'PayType' => [
'addon\alipay\event\PayType'
'listen' => [ ],
//支付异步回调 //支付,前台应用
'PayNotify' => [ 'Pay' => [
'addon\alipay\event\PayNotify' 'addon\alipay\event\Pay'
], ],
//支付方式,后台查询 'PayClose' => [
'PayType' => [ 'addon\alipay\event\PayClose'
'addon\alipay\event\PayType' ],
], 'PayRefund' => [
//支付,前台应用 'addon\alipay\event\PayRefund'
'Pay' => [ ],
'addon\alipay\event\Pay' 'PayTransfer' => [
], 'addon\alipay\event\PayTransfer'
'PayClose' => [ ],
'addon\alipay\event\PayClose' 'TransferType' => [
], 'addon\alipay\event\TransferType'
'PayRefund' => [ ],
'addon\alipay\event\PayRefund' 'AuthcodePay' => [
], 'addon\alipay\event\AuthcodePay'
'PayTransfer' => [ ],
'addon\alipay\event\PayTransfer' 'PayOrderQuery' => [
], 'addon\alipay\event\PayOrderQuery'
'TransferType' => [ ],
'addon\alipay\event\TransferType' ],
],
'AuthcodePay' => [ 'subscribe' => [
'addon\alipay\event\AuthcodePay' ],
], ];
'PayOrderQuery' => [
'addon\alipay\event\PayOrderQuery'
],
],
'subscribe' => [
],
];

View File

@@ -1,21 +1,12 @@
<?php <?php
/** return [
'name' => 'alipay',
'title' => '支付宝支付',
'description' => '支付宝支付功能',
'type' => 'system', //插件类型 system :系统插件(自动安装), promotion:营销插件 tool:工具插件
'status' => 1,
'author' => '',
'version' => '5.3.1',
*/ 'version_no' => '525231212001',
return [ 'content' => '',
'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 <?php
/** return [
[
'name' => 'ALI_PAY_CONFIG',
'title' => '支付宝支付编辑',
'url' => 'alipay://shop/pay/config',
'parent' => 'CONFIG_PAY',
'is_show' => 0,
*/ 'is_control' => 1,
return [ 'is_icon' => 0,
[ 'picture' => '',
'name' => 'ALI_PAY_CONFIG', 'picture_select' => '',
'title' => '支付宝支付编辑', 'sort' => 1,
'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 <?php
/**
namespace addon\alipay\event;
/**
* 应用安装
*/
class Install
*/ {
/**
* 执行安装
namespace addon\alipay\event; */
public function handle()
/** {
* 应用安装 return success();
*/ }
class Install
{
/**
* 执行安装
*/
public function handle()
{
return success();
}
} }

View File

@@ -1,33 +1,25 @@
<?php <?php
/**
namespace addon\alipay\event;
use addon\alipay\model\Pay as PayModel;
/**
* 生成支付
*/ */
class Pay
namespace addon\alipay\event; {
/**
use addon\alipay\model\Pay as PayModel; * 支付方式及配置
*/
/** public function handle($param)
* 生成支付 {
*/ if ($param[ "pay_type" ] == "alipay") {
class Pay 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;
*/ }
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 <?php
/**
namespace addon\alipay\event;
use addon\alipay\model\Pay as PayModel;
/**
* 关闭支付
*/ */
class PayClose
namespace addon\alipay\event; {
/**
use addon\alipay\model\Pay as PayModel; * 关闭支付
* @param $params
/** * @return \addon\alipay\model\multitype|array
* 关闭支付 */
*/ public function handle($params)
class PayClose {
{ // if ($params["pay_type"] == "alipay") {
/** try {
* 关闭支付 $pay_model = new PayModel($params[ 'site_id' ]);
* @param $params $result = $pay_model->close($params);
* @return \addon\alipay\model\multitype|array return $result;
*/ } catch (\Exception $e) {
public function handle($params) return error(-1, $e->getMessage());
{ } catch (\Throwable $e) {
// if ($params["pay_type"] == "alipay") { return error(-1, $e->getMessage());
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 <?php
/**
namespace addon\alipay\event;
use addon\alipay\model\Pay as PayModel;
use app\model\system\Pay as PayCommon;
/**
*/ * 支付回调
*/
namespace addon\alipay\event; class PayNotify
{
use addon\alipay\model\Pay as PayModel; /**
use app\model\system\Pay as PayCommon; * 支付方式及配置
*/
/** public function handle()
* 支付回调 {
*/ if (isset($_POST[ 'out_trade_no' ])) {
class PayNotify $out_trade_no = $_POST[ 'out_trade_no' ];
{ $pay = new PayCommon();
/** $pay_info = $pay->getPayInfo($out_trade_no)[ 'data' ];
* 支付方式及配置 if (empty($pay_info)) return false;
*/
public function handle() if ($_POST[ 'total_amount' ] != $pay_info[ 'pay_money' ]) {
{ return false;
if (isset($_POST[ 'out_trade_no' ])) { }
$out_trade_no = $_POST[ 'out_trade_no' ]; $mch_info = empty($pay_info[ 'mch_info' ]) ? [] : json_decode($pay_info[ 'mch_info' ], true);
$pay = new PayCommon();
$pay_info = $pay->getPayInfo($out_trade_no)[ 'data' ]; $pay_model = new PayModel($pay_info[ 'site_id' ], $mch_info[ 'is_aliapp' ] ?? 0);
if (empty($pay_info)) return false; $pay_model->payNotify();
}
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 <?php
/**
namespace addon\alipay\event;
use addon\alipay\model\Config as ConfigModel;
use addon\alipay\model\Pay as PayModel;
use app\model\system\Pay;
*/ /**
* 查询支付结果
namespace addon\alipay\event; */
class PayOrderQuery
use addon\alipay\model\Config as ConfigModel; {
use addon\alipay\model\Pay as PayModel; public function handle(array $params)
use app\model\system\Pay; {
$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' ];
class PayOrderQuery if (!empty($pay_config) && $pay_config[ 'pay_status' ] != 2) {
{ $pay_common = new PayModel($pay_info[ 'site_id' ]);
public function handle(array $params) $pay_common->orderQuery($pay_info);
{ }
$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 <?php
/**
namespace addon\alipay\event;
use addon\alipay\model\Pay as PayModel;
/**
* 原路退款
*/ */
class PayRefund
namespace addon\alipay\event; {
/**
use addon\alipay\model\Pay as PayModel; * 关闭支付
*/
/** public function handle($params)
* 原路退款 {
*/ if ($params[ "pay_info" ][ "pay_type" ] == "alipay") {
class PayRefund $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;
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 <?php
/**
namespace addon\alipay\event;
use addon\alipay\model\Pay;
use addon\alipay\model\Config;
class PayTransfer
*/ {
public function handle(array $params)
namespace addon\alipay\event; {
if ($params[ 'transfer_type' ] == 'alipay') {
use addon\alipay\model\Pay; $pay = new Pay($params[ 'site_id' ]);
use addon\alipay\model\Config;
$config_model = new Config();
class PayTransfer $config_result = $config_model->getPayConfig($params[ 'site_id' ]);
{ $config = $config_result[ "data" ];
public function handle(array $params) if (!empty($config[ 'value' ])) {
{ $config_info = $config[ "value" ];
if ($params[ 'transfer_type' ] == 'alipay') { $countersign_type = $config_info['countersign_type'] ?? 0;
$pay = new Pay($params[ 'site_id' ]); if ($countersign_type == 0) {
$res = $pay->payTransfer($params);
$config_model = new Config(); return $res;
$config_result = $config_model->getPayConfig($params[ 'site_id' ]); } else {
$config = $config_result[ "data" ]; $res = $pay->payNewTransfer($params);
if (!empty($config[ 'value' ])) { return $res;
$config_info = $config[ "value" ]; }
$countersign_type = $config_info['countersign_type'] ?? 0; } else {
if ($countersign_type == 0) { $res = $pay->payTransfer($params);
$res = $pay->payTransfer($params); return $res;
return $res; }
} else { }
$res = $pay->payNewTransfer($params); }
return $res;
}
} else {
$res = $pay->payTransfer($params);
return $res;
}
}
}
} }

View File

@@ -1,51 +1,43 @@
<?php <?php
/**
namespace addon\alipay\event;
use addon\alipay\model\Config;
/**
* 支付方式 (后台调用)
*/ */
class PayType
namespace addon\alipay\event; {
/**
use addon\alipay\model\Config; * 支付方式及配置
*/
/** public function handle($param)
* 支付方式 (后台调用) {
*/ $app_type = $param['app_type'] ?? '';
class PayType if (!empty($app_type)) {
{ if (!in_array($app_type, [ "h5", "app", "pc", "aliapp", 'wechat' ])) {
/** return '';
* 支付方式及配置 }
*/
public function handle($param) if ($app_type != 'aliapp') {
{ $config_model = new Config();
$app_type = $param['app_type'] ?? ''; $config_result = $config_model->getPayConfig($param[ 'site_id' ]);
if (!empty($app_type)) { $config = $config_result[ "data" ][ "value" ] ?? [];
if (!in_array($app_type, [ "h5", "app", "pc", "aliapp", 'wechat' ])) { $pay_status = $config[ "pay_status" ] ?? 0;
return ''; if ($pay_status == 0) {
} return '';
}
if ($app_type != 'aliapp') { }
$config_model = new Config(); }
$config_result = $config_model->getPayConfig($param[ 'site_id' ]); $info = array (
$config = $config_result[ "data" ][ "value" ] ?? []; "pay_type" => "alipay",
$pay_status = $config[ "pay_status" ] ?? 0; "pay_type_name" => "支付宝支付",
if ($pay_status == 0) { "edit_url" => "alipay://shop/pay/config",
return ''; "shop_url" => "alipay://shop/pay/config",
} "logo" => "addon/alipay/icon.png",
} "desc" => "支付宝网站(www.alipay.com) 是国内先进的网上支付平台。"
} );
$info = array ( return $info;
"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 <?php
/**
namespace addon\alipay\event;
use addon\alipay\model\Config;
class TransferType
{
*/ public function handle(array $param)
{
namespace addon\alipay\event;
$app_type = $param['app_type'] ?? '';
use addon\alipay\model\Config; if (!empty($app_type)) {
if (!in_array($app_type, [ "h5", "app", "pc", "aliapp" ])) {
class TransferType return '';
{ }
public function handle(array $param) $config_model = new Config();
{ $config_result = $config_model->getPayConfig($param[ 'site_id' ]);
$config = $config_result[ "data" ][ "value" ] ?? [];
$app_type = $param['app_type'] ?? ''; $transfer_status = $config[ "transfer_status" ] ?? 0;
if (!empty($app_type)) { if ($transfer_status == 0) {
if (!in_array($app_type, [ "h5", "app", "pc", "aliapp" ])) { return '';
return ''; }
} }
$config_model = new Config(); $info = array (
$config_result = $config_model->getPayConfig($param[ 'site_id' ]); "type" => "alipay",
$config = $config_result[ "data" ][ "value" ] ?? []; "type_name" => "支付宝",
$transfer_status = $config[ "transfer_status" ] ?? 0; );
if ($transfer_status == 0) { return $info;
return ''; }
}
}
$info = array (
"type" => "alipay",
"type_name" => "支付宝",
);
return $info;
}
} }

View File

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

View File

@@ -1,96 +1,88 @@
<?php <?php
/**
namespace addon\alipay\model;
use app\model\system\Config as ConfigModel;
use app\model\BaseModel;
/**
*/ * 支付宝支付配置
*/
namespace addon\alipay\model; class Config extends BaseModel
{
use app\model\system\Config as ConfigModel;
use app\model\BaseModel; private $encrypt = '******';
/** /**
* 支付宝支付配置 * 设置支付配置
*/ * @param $data
class Config extends BaseModel * @param int $site_id
{ * @param string $app_module
* @return array
private $encrypt = '******'; */
public function setPayConfig($data, $site_id = 0, $app_module = 'shop')
/** {
* 设置支付配置 $config = new ConfigModel();
* @param $data
* @param int $site_id // 未加密前的数据
* @param string $app_module $original_config = $this->getPayConfig($site_id)[ 'data' ][ 'value' ];
* @return array
*/ // 检测数据是否发生变化,如果没有变化,则保持未加密前的数据
public function setPayConfig($data, $site_id = 0, $app_module = 'shop') if (!empty($data[ 'private_key' ]) && $data[ 'private_key' ] == $this->encrypt) {
{ $data[ 'private_key' ] = $original_config[ 'private_key' ]; // 应用私钥
$config = new ConfigModel(); }
if (!empty($data[ 'public_key' ]) && $data[ 'public_key' ] == $this->encrypt) {
// 未加密前的数据 $data[ 'public_key' ] = $original_config[ 'public_key' ]; // 应用公钥
$original_config = $this->getPayConfig($site_id)[ 'data' ][ 'value' ]; }
if (!empty($data[ 'alipay_public_key' ]) && $data[ 'alipay_public_key' ] == $this->encrypt) {
// 检测数据是否发生变化,如果没有变化,则保持未加密前的数据 $data[ 'alipay_public_key' ] = $original_config[ 'alipay_public_key' ]; // 支付宝公钥
if (!empty($data[ 'private_key' ]) && $data[ 'private_key' ] == $this->encrypt) { }
$data[ 'private_key' ] = $original_config[ 'private_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[ 'public_key' ]) && $data[ 'public_key' ] == $this->encrypt) { }
$data[ 'public_key' ] = $original_config[ 'public_key' ]; // 应用公钥 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_public_key' ]) && $data[ 'alipay_public_key' ] == $this->encrypt) { }
$data[ 'alipay_public_key' ] = $original_config[ 'alipay_public_key' ]; // 支付宝公钥 if (!empty($data[ 'alipay_with_crt' ]) && $data[ 'alipay_with_crt' ] == $this->encrypt) {
} $data[ 'alipay_with_crt' ] = $original_config[ 'alipay_with_crt' ]; // 支付宝根证书
if (!empty($data[ 'public_key_crt' ]) && $data[ 'public_key_crt' ] == $this->encrypt) { }
$data[ 'public_key_crt' ] = $original_config[ 'public_key_crt' ]; // 应用公钥证书
} $res = $config->setConfig($data, '支付宝支付配置', 1, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'ALI_PAY_CONFIG' ] ]);
if (!empty($data[ 'alipay_public_key_crt' ]) && $data[ 'alipay_public_key_crt' ] == $this->encrypt) { return $res;
$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' ]; // 支付宝根证书 * 获取支付配置
} * @param int $site_id
* @param string $app_module
$res = $config->setConfig($data, '支付宝支付配置', 1, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'ALI_PAY_CONFIG' ] ]); * @param bool $need_encrypt 是否需要加密数据true加密、false不加密
return $res; * @return array
} */
public function getPayConfig($site_id = 0, $app_module = 'shop', $need_encrypt = false)
/** {
* 获取支付配置 $config = new ConfigModel();
* @param int $site_id $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'ALI_PAY_CONFIG' ] ]);
* @param string $app_module if ($need_encrypt) {
* @param bool $need_encrypt 是否需要加密数据true加密、false不加密 // 加密敏感信息
* @return array if (!empty($res[ 'data' ][ 'value' ][ 'private_key' ])) {
*/ $res[ 'data' ][ 'value' ][ 'private_key' ] = $this->encrypt; // 应用私钥
public function getPayConfig($site_id = 0, $app_module = 'shop', $need_encrypt = false) }
{ if (!empty($res[ 'data' ][ 'value' ][ 'public_key' ])) {
$config = new ConfigModel(); $res[ 'data' ][ 'value' ][ 'public_key' ] = $this->encrypt; // 应用公钥
$res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', $app_module ], [ 'config_key', '=', 'ALI_PAY_CONFIG' ] ]); }
if ($need_encrypt) { if (!empty($res[ 'data' ][ 'value' ][ 'alipay_public_key' ])) {
// 加密敏感信息 $res[ 'data' ][ 'value' ][ 'alipay_public_key' ] = $this->encrypt; // 支付宝公钥
if (!empty($res[ 'data' ][ 'value' ][ 'private_key' ])) { }
$res[ 'data' ][ 'value' ][ 'private_key' ] = $this->encrypt; // 应用私钥 if (!empty($res[ 'data' ][ 'value' ][ 'public_key_crt' ])) {
} $res[ 'data' ][ 'value' ][ 'public_key_crt' ] = $this->encrypt; // 应用公钥证书
if (!empty($res[ 'data' ][ 'value' ][ 'public_key' ])) { }
$res[ 'data' ][ 'value' ][ 'public_key' ] = $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_public_key' ])) { }
$res[ 'data' ][ 'value' ][ 'alipay_public_key' ] = $this->encrypt; // 支付宝公钥 if (!empty($res[ 'data' ][ 'value' ][ 'alipay_with_crt' ])) {
} $res[ 'data' ][ 'value' ][ 'alipay_with_crt' ] = $this->encrypt; // 支付宝根证书
if (!empty($res[ 'data' ][ 'value' ][ 'public_key_crt' ])) { }
$res[ 'data' ][ 'value' ][ 'public_key_crt' ] = $this->encrypt; // 应用公钥证书 }
} return $res;
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 <?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;
namespace addon\alipay\model; use addon\alipay\data\sdk\request\AlipayTradeRefundRequest;
use addon\alipay\data\sdk\request\AlipayTradeWapPayRequest;
use addon\alipay\data\sdk\AopClient; use addon\alipay\data\sdk\request\AlipayTradePrecreateRequest;
use addon\alipay\data\sdk\request\AlipayFundTransToaccountTransferRequest; use addon\alipay\data\sdk\request\AlipayTradePayRequest;
use addon\alipay\data\sdk\request\AlipayTradeAppPayRequest; use addon\alipay\data\sdk\request\AlipayTradeQueryRequest;
use addon\alipay\data\sdk\request\AlipayTradeCloseRequest; use app\model\BaseModel;
use addon\alipay\data\sdk\request\AlipayTradeCreateRequest; use app\model\system\Cron;
use addon\alipay\data\sdk\request\AlipayTradePagePayRequest; use app\model\system\Pay as PayCommon;
use addon\alipay\data\sdk\request\AlipayTradeRefundRequest; use addon\alipay\data\sdk\request\AlipayFundTransUniTransferRequest;
use addon\alipay\data\sdk\request\AlipayTradeWapPayRequest; use addon\alipay\data\sdk\AopCertClient;
use addon\alipay\data\sdk\request\AlipayTradePrecreateRequest; use app\model\system\Pay as PayModel;
use addon\alipay\data\sdk\request\AlipayTradePayRequest; use addon\aliapp\model\Config as AliappConfig;
use addon\alipay\data\sdk\request\AlipayTradeQueryRequest; use think\facade\Log;
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; class Pay extends BaseModel
use app\model\system\Pay as PayModel; {
use addon\aliapp\model\Config as AliappConfig;
use think\facade\Log; public $aop;
/** private $is_aliapp = 0;
* 支付宝支付配置
*/ /**
class Pay extends BaseModel *
{ * @param $site_id
* @param int $is_aliapp 是否是小程序
public $aop; */
function __construct($site_id, $is_aliapp = 0)
private $is_aliapp = 0; {
$this->is_aliapp = $is_aliapp;
/**
* try {
* @param $site_id // 获取支付宝支付参数(统一支付到平台账户)
* @param int $is_aliapp 是否是小程序 if ($is_aliapp) {
*/ $config_info = ( new AliappConfig() )->getAliappConfig($site_id)[ 'data' ][ 'value' ];
function __construct($site_id, $is_aliapp = 0) } else {
{ $config_info = ( new Config() )->getPayConfig($site_id)[ 'data' ][ 'value' ];
$this->is_aliapp = $is_aliapp; }
try { if (!empty($config_info)) {
// 获取支付宝支付参数(统一支付到平台账户) $countersign_type = $config_info[ 'countersign_type' ] ?? 0;
if ($is_aliapp) {
$config_info = ( new AliappConfig() )->getAliappConfig($site_id)[ 'data' ][ 'value' ]; if ($countersign_type == 1) {
} else { $appCertPath = $config_info[ "public_key_crt" ] ?? "";
$config_info = ( new Config() )->getPayConfig($site_id)[ 'data' ][ 'value' ]; $alipayCertPath = $config_info[ "alipay_public_key_crt" ] ?? "";
} $rootCertPath = $config_info[ "alipay_with_crt" ] ?? "";
if (!empty($config_info)) { $this->aop = new AopCertClient();
$countersign_type = $config_info[ 'countersign_type' ] ?? 0; //调用getPublicKey从支付宝公钥证书中提取公钥
$this->aop->alipayrsaPublicKey = $this->aop->getPublicKey($alipayCertPath);
if ($countersign_type == 1) { //是否校验自动下载的支付宝公钥证书,如果开启校验要保证支付宝根证书在有效期内
$appCertPath = $config_info[ "public_key_crt" ] ?? ""; $this->aop->isCheckAlipayPublicCert = false;
$alipayCertPath = $config_info[ "alipay_public_key_crt" ] ?? ""; //调用getCertSN获取证书序列号
$rootCertPath = $config_info[ "alipay_with_crt" ] ?? ""; $this->aop->appCertSN = $this->aop->getCertSN($appCertPath);
//调用getRootCertSN获取支付宝根证书序列号
$this->aop = new AopCertClient(); $this->aop->alipayRootCertSN = $this->aop->getRootCertSN($rootCertPath);
//调用getPublicKey从支付宝公钥证书中提取公钥
$this->aop->alipayrsaPublicKey = $this->aop->getPublicKey($alipayCertPath); } else {
//是否校验自动下载的支付宝公钥证书,如果开启校验要保证支付宝根证书在有效期内 // 获取支付宝支付参数(统一支付到平台账户)
$this->aop->isCheckAlipayPublicCert = false; $this->aop = new AopClient();
//调用getCertSN获取证书序列号 $this->aop->alipayrsaPublicKey = $config_info[ 'public_key' ] ?? "";
$this->aop->appCertSN = $this->aop->getCertSN($appCertPath); $this->aop->alipayPublicKey = $config_info[ 'alipay_public_key' ] ?? "";
//调用getRootCertSN获取支付宝根证书序列号 }
$this->aop->alipayRootCertSN = $this->aop->getRootCertSN($rootCertPath); $this->aop->appId = $config_info[ "app_id" ] ?? "";
$this->aop->rsaPrivateKey = $config_info[ 'private_key' ] ?? "";
} else { $this->aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
// 获取支付宝支付参数(统一支付到平台账户) $this->aop->apiVersion = '1.0';
$this->aop = new AopClient(); $this->aop->signType = 'RSA2';
$this->aop->alipayrsaPublicKey = $config_info[ 'public_key' ] ?? ""; $this->aop->postCharset = 'UTF-8';
$this->aop->alipayPublicKey = $config_info[ 'alipay_public_key' ] ?? ""; $this->aop->format = 'json';
}
$this->aop->appId = $config_info[ "app_id" ] ?? ""; }
$this->aop->rsaPrivateKey = $config_info[ 'private_key' ] ?? ""; // else{
$this->aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do'; // return $this->error('', '支付宝支付未配置');
$this->aop->apiVersion = '1.0'; // }
$this->aop->signType = 'RSA2';
$this->aop->postCharset = 'UTF-8'; } catch (\Exception $e) {
$this->aop->format = 'json'; return $this->error('', '支付宝配置错误');
}
} }
// else{
// return $this->error('', '支付宝支付未配置'); /**
// } * 生成支付
* @param $param
} catch (\Exception $e) { * @return array
return $this->error('', '支付宝配置错误'); */
} public function pay($param)
} {
//构造要请求的参数数组,无需改动
/** $parameter = array (
* 生成支付 "out_trade_no" => $param[ "out_trade_no" ],
* @param $param "subject" => str_sub($param[ "pay_body" ], 15),
* @return array "total_amount" => (float) $param[ "pay_money" ],
*/ "body" => str_sub($param[ "pay_body" ], 60),
public function pay($param) "product_code" => 'FAST_INSTANT_TRADE_PAY',
{ );
//构造要请求的参数数组,无需改动
$parameter = array ( switch ( $param[ "app_type" ] ) {
"out_trade_no" => $param[ "out_trade_no" ], case "h5":
"subject" => str_sub($param[ "pay_body" ], 15), $request = new AlipayTradeWapPayRequest();
"total_amount" => (float) $param[ "pay_money" ], break;
"body" => str_sub($param[ "pay_body" ], 60), case "pc":
"product_code" => 'FAST_INSTANT_TRADE_PAY', $request = new AlipayTradePagePayRequest();
); break;
case "app":
switch ( $param[ "app_type" ] ) { $request = new AlipayTradeAppPayRequest();
case "h5": break;
$request = new AlipayTradeWapPayRequest(); case 'wechat':
break; $request = new AlipayTradeWapPayRequest();
case "pc": break;
$request = new AlipayTradePagePayRequest(); case 'cashier':
break; $request = new AlipayTradePrecreateRequest();
case "app": break;
$request = new AlipayTradeAppPayRequest(); case 'aliapp':
break; $parameter[ 'product_code' ] = 'FACE_TO_FACE_PAYMENT';
case 'wechat':
$request = new AlipayTradeWapPayRequest(); $member_info = model('member')->getInfo([ [ "member_id", "=", $param[ "member_id" ] ] ], 'ali_openid');
break; if (empty($member_info)) return $this->error(-1, '未获取到会员信息');
case 'cashier':
$request = new AlipayTradePrecreateRequest(); $parameter[ 'buyer_id' ] = $member_info[ 'ali_openid' ];
break; $request = new AlipayTradeCreateRequest();
case 'aliapp': break;
$parameter[ 'product_code' ] = 'FACE_TO_FACE_PAYMENT'; }
$member_info = model('member')->getInfo([ [ "member_id", "=", $param[ "member_id" ] ] ], 'ali_openid'); $parameter = json_encode($parameter);
if (empty($member_info)) return $this->error(-1, '未获取到会员信息'); $request->setBizContent($parameter);
$request->SetReturnUrl($param[ "return_url" ]);
$parameter[ 'buyer_id' ] = $member_info[ 'ali_openid' ]; $request->SetNotifyUrl($param[ "notify_url" ]);
$request = new AlipayTradeCreateRequest();
break; ///绑定商户数据
} $pay_model = new PayModel();
$pay_model->bindMchPay($param[ "out_trade_no" ], [ "is_aliapp" => $this->is_aliapp ]);
$parameter = json_encode($parameter);
$request->setBizContent($parameter); try {
$request->SetReturnUrl($param[ "return_url" ]); if ($param[ "app_type" ] == 'h5' || $param[ "app_type" ] == 'wechat' || $param[ "app_type" ] == 'pc') {
$request->SetNotifyUrl($param[ "notify_url" ]); $result = $this->aop->pageExecute($request, 'get');
return $this->success([
///绑定商户数据 'type' => 'url',
$pay_model = new PayModel(); 'data' => $result
$pay_model->bindMchPay($param[ "out_trade_no" ], [ "is_aliapp" => $this->is_aliapp ]); ]);
} elseif ($param[ "app_type" ] == 'app') {
try { $result = $this->aop->sdkExecute($request);
if ($param[ "app_type" ] == 'h5' || $param[ "app_type" ] == 'wechat' || $param[ "app_type" ] == 'pc') { if (strpos(get_class($this->aop), 'AopClient') !== false) {
$result = $this->aop->pageExecute($request, 'get'); return $this->success([
return $this->success([ 'type' => 'url',
'type' => 'url', 'data' => $result
'data' => $result ]);
]); }
} elseif ($param[ "app_type" ] == 'app') { } else {
$result = $this->aop->sdkExecute($request); $result = $this->aop->execute($request);
if (strpos(get_class($this->aop), 'AopClient') !== false) { }
return $this->success([ if ($result === false) return $this->error('', '支付宝发起支付失败');
'type' => 'url', } catch (\Exception $e) {
'data' => $result return $this->error('', $e->getMessage());
]); }
}
} else { $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
$result = $this->aop->execute($request); $resultCode = $result->$responseNode->code;
} if (!empty($resultCode) && $resultCode == 10000) {
if ($result === false) return $this->error('', '支付宝发起支付失败'); switch ( $param[ "app_type" ] ) {
} catch (\Exception $e) { case 'cashier':
return $this->error('', $e->getMessage()); return $this->success([
} 'type' => 'qrcode',
'data' => [
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response"; 'qrcode' => $result->$responseNode->qr_code
$resultCode = $result->$responseNode->code; ]
if (!empty($resultCode) && $resultCode == 10000) { ]);
switch ( $param[ "app_type" ] ) { break;
case 'cashier': case 'aliapp':
return $this->success([ return $this->success([
'type' => 'qrcode', 'type' => 'data',
'data' => [ 'data' => [
'qrcode' => $result->$responseNode->qr_code 'orderInfo' => $result->$responseNode->trade_no
] ]
]); ]);
break; break;
case 'aliapp': default:
return $this->success([ return $this->success();
'type' => 'data', }
'data' => [ } else {
'orderInfo' => $result->$responseNode->trade_no return $this->error("", $result->$responseNode->sub_msg);
] }
]); }
break;
default: /**
return $this->success(); * 支付关闭
} * @param $param
} else { * @return array
return $this->error("", $result->$responseNode->sub_msg); * @throws \think\Exception
} */
} public function close($param)
{
/** $parameter = array (
* 支付关闭 "out_trade_no" => $param[ "out_trade_no" ]
* @param $param );
* @return array // 建立请求
* @throws \think\Exception $request = new AlipayTradeCloseRequest();
*/ $request->setBizContent(json_encode($parameter));
public function close($param) $result = $this->aop->execute($request);
{ $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
$parameter = array ( $resultCode = $result->$responseNode->code;
"out_trade_no" => $param[ "out_trade_no" ] if (!empty($resultCode) && $resultCode == 10000) {
); return $this->success();
// 建立请求 } else {
$request = new AlipayTradeCloseRequest(); $sub_code = $result->$responseNode->sub_code;
$request->setBizContent(json_encode($parameter)); $data = [];
$result = $this->aop->execute($request); if(in_array($sub_code, ['ACQ.TRADE_STATUS_ERROR', 'ACQ.REASON_TRADE_STATUS_INVALID', 'ACQ.REASON_ILLEGAL_STATUS'])){
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response"; $pay_order_result = $this->get($param[ "out_trade_no" ]);
$resultCode = $result->$responseNode->code; if(!empty($pay_order_result) && $pay_order_result['code'] >= 0){
if (!empty($resultCode) && $resultCode == 10000) { if($pay_order_result['data']['trade_status'] == 'TRADE_SUCCESS' || $pay_order_result['data']['trade_status'] == 'TRADE_FINISHED'){
return $this->success(); $data['is_paid'] = 1;
} 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){ return $this->error($data, $result->$responseNode->sub_msg);
if($pay_order_result['data']['trade_status'] == 'TRADE_SUCCESS' || $pay_order_result['data']['trade_status'] == 'TRADE_FINISHED'){ }
$data['is_paid'] = 1; }
}
} /**
} * 支付宝支付原路返回
* @param array $param 支付参数
* @return array
return $this->error($data, $result->$responseNode->sub_msg); * @throws \think\Exception
} */
} public function refund($param)
{
/** $pay_info = $param[ "pay_info" ];
* 支付宝支付原路返回 $refund_no = $param[ "refund_no" ];
* @param array $param 支付参数 $out_trade_no = $pay_info[ "trade_no" ] ?? '';
* @return array $refund_fee = $param[ "refund_fee" ];
* @throws \think\Exception $parameter = array (
*/ 'trade_no' => $out_trade_no,
public function refund($param) 'refund_amount' => sprintf("%.2f", $refund_fee),
{ 'out_request_no' => $refund_no
$pay_info = $param[ "pay_info" ]; );
$refund_no = $param[ "refund_no" ]; // 建立请求
$out_trade_no = $pay_info[ "trade_no" ] ?? ''; $request = new AlipayTradeRefundRequest ();
$refund_fee = $param[ "refund_fee" ]; $request->setBizContent(json_encode($parameter));
$parameter = array ( $result = $this->aop->execute($request);
'trade_no' => $out_trade_no, $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
'refund_amount' => sprintf("%.2f", $refund_fee), $resultCode = $result->$responseNode->code;
'out_request_no' => $refund_no if (!empty($resultCode) && $resultCode == 10000) {
); return $this->success();
// 建立请求 } else {
$request = new AlipayTradeRefundRequest (); return $this->error("", $result->$responseNode->sub_msg);
$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(); * @param $param
} else { * @return array
return $this->error("", $result->$responseNode->sub_msg); */
} public function payTransfer($param)
} {
try {
/** $config_model = new Config();
* 支付宝转账 $config_result = $config_model->getPayConfig($param[ 'site_id' ]);
* @param $param if ($config_result[ 'code' ] < 0) return $config_result;
* @return array $config = $config_result[ 'data' ][ 'value' ];
*/ if (empty($config)) return $this->error([], '未配置支付宝支付');
public function payTransfer($param) if (!$config[ 'transfer_status' ]) return $this->error([], '未启用支付宝转账');
{
try { $parameter = [
$config_model = new Config(); 'out_biz_no' => $param[ 'out_trade_no' ],
$config_result = $config_model->getPayConfig($param[ 'site_id' ]); 'payee_type' => 'ALIPAY_LOGONID',
if ($config_result[ 'code' ] < 0) return $config_result; 'payee_account' => $param[ "account_number" ],
$config = $config_result[ 'data' ][ 'value' ]; 'amount' => sprintf("%.2f", $param[ 'amount' ]),
if (empty($config)) return $this->error([], '未配置支付宝支付'); 'payee_real_name' => $param[ "real_name" ],
if (!$config[ 'transfer_status' ]) return $this->error([], '未启用支付宝转账'); 'remark' => $param[ "desc" ]
];
$parameter = [ // 建立请求
'out_biz_no' => $param[ 'out_trade_no' ], $request = new AlipayFundTransToaccountTransferRequest();
'payee_type' => 'ALIPAY_LOGONID', $request->setBizContent(json_encode($parameter));
'payee_account' => $param[ "account_number" ], $result = $this->aop->execute($request);
'amount' => sprintf("%.2f", $param[ 'amount' ]), $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
'payee_real_name' => $param[ "real_name" ], $resultCode = $result->$responseNode->code;
'remark' => $param[ "desc" ] if (!empty($resultCode) && $resultCode == 10000) {
]; return $this->success([
// 建立请求 'out_trade_no' => $result->$responseNode->out_biz_no, // 商户交易号
$request = new AlipayFundTransToaccountTransferRequest(); 'payment_no' => $result->$responseNode->order_id, // 微信付款单号
$request->setBizContent(json_encode($parameter)); 'payment_time' => date_to_time($result->$responseNode->pay_date) // 付款成功时间
$result = $this->aop->execute($request); ]);
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response"; } else {
$resultCode = $result->$responseNode->code; return $this->error([], $result->$responseNode->sub_msg);
if (!empty($resultCode) && $resultCode == 10000) { }
return $this->success([ } catch (\Exception $e) {
'out_trade_no' => $result->$responseNode->out_biz_no, // 商户交易号 return $this->error([], $e->getMessage());
'payment_no' => $result->$responseNode->order_id, // 微信付款单号 }
'payment_time' => date_to_time($result->$responseNode->pay_date) // 付款成功时间 }
]);
} else { /**
return $this->error([], $result->$responseNode->sub_msg); * 异步完成支付
} * @param $param
} catch (\Exception $e) { */
return $this->error([], $e->getMessage()); 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);
* @param $param if ($res) { // 验证成功
*/ $out_trade_no = $_POST[ 'out_trade_no' ];
public function payNotify() // 支付宝交易号
{ $trade_no = $_POST[ 'trade_no' ];
// 交易状态
// Log::write('pay_notifiy_log:alipay:'.json_encode(input()), 'notice'); $trade_status = $_POST[ 'trade_status' ];
try { $pay_common = new PayCommon();
$res = $this->aop->rsaCheckV1($_POST, $this->aop->alipayrsaPublicKey, $this->aop->signType); if ($trade_status == "TRADE_SUCCESS") {
if ($res) { // 验证成功 $retval = $pay_common->onlinePay($out_trade_no, "alipay", $trade_no, "alipay");
$out_trade_no = $_POST[ 'out_trade_no' ]; }
// 支付宝交易号 echo "success";
$trade_no = $_POST[ 'trade_no' ]; } else {
// 交易状态 // 验证失败
$trade_status = $_POST[ 'trade_status' ]; echo "fail";
$pay_common = new PayCommon(); }
if ($trade_status == "TRADE_SUCCESS") { } catch (\Exception $e) {
$retval = $pay_common->onlinePay($out_trade_no, "alipay", $trade_no, "alipay"); echo "fail";
} }
echo "success"; }
} else {
// 验证失败 public function payNewTransfer($param)
echo "fail"; {
} try {
} catch (\Exception $e) { $config_model = new Config();
echo "fail"; $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([], '未配置支付宝支付');
public function payNewTransfer($param) if (!$config[ 'transfer_status' ]) return $this->error([], '未启用支付宝转账');
{
try { $parameter = [
$config_model = new Config(); 'out_biz_no' => $param[ 'out_trade_no' ],
$config_result = $config_model->getPayConfig($param[ 'site_id' ]); 'trans_amount' => sprintf("%.2f", $param[ 'amount' ]),
if ($config_result[ 'code' ] < 0) return $config_result; 'product_code' => 'TRANS_ACCOUNT_NO_PWD',
$config = $config_result[ 'data' ][ 'value' ]; 'biz_scene' => 'DIRECT_TRANSFER',
if (empty($config)) return $this->error([], '未配置支付宝支付'); 'order_title' => '支付宝转账',
if (!$config[ 'transfer_status' ]) return $this->error([], '未启用支付宝转账'); 'remark' => $param[ "desc" ],
'payee_info' => [
$parameter = [ 'identity' => $param[ "account_number" ],
'out_biz_no' => $param[ 'out_trade_no' ], 'identity_type' => "ALIPAY_LOGON_ID",
'trans_amount' => sprintf("%.2f", $param[ 'amount' ]), 'name' => $param[ "real_name" ]
'product_code' => 'TRANS_ACCOUNT_NO_PWD', ]
'biz_scene' => 'DIRECT_TRANSFER', ];
'order_title' => '支付宝转账',
'remark' => $param[ "desc" ], // 建立请求
'payee_info' => [ $request = new AlipayFundTransUniTransferRequest();
'identity' => $param[ "account_number" ], $request->setBizContent(json_encode($parameter));
'identity_type' => "ALIPAY_LOGON_ID", $result = $this->aop->execute($request);
'name' => $param[ "real_name" ] $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, // 商户交易号
$request = new AlipayFundTransUniTransferRequest(); 'payment_no' => $result->$responseNode->order_id, // 微信付款单号
$request->setBizContent(json_encode($parameter)); 'payment_time' => date_to_time($result->$responseNode->trans_date) // 付款成功时间
$result = $this->aop->execute($request); ]);
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response"; } else {
$resultCode = $result->$responseNode->code; return $this->error([], $result->$responseNode->sub_msg);
if (!empty($resultCode) && $resultCode == 10000) { }
return $this->success([ } catch (\Exception $e) {
'out_trade_no' => $result->$responseNode->out_biz_no, // 商户交易号 return $this->error([], $e->getMessage());
'payment_no' => $result->$responseNode->order_id, // 微信付款单号 }
'payment_time' => date_to_time($result->$responseNode->trans_date) // 付款成功时间 }
]);
} else { /**
return $this->error([], $result->$responseNode->sub_msg); * 付款码支付
} * @param $param
} catch (\Exception $e) { * @return array|mixed|void
return $this->error([], $e->getMessage()); */
} public function micropay($param)
} {
try {
/** //构造要请求的参数数组,无需改动
* 付款码支付 $parameter = array (
* @param $param "out_trade_no" => $param[ "out_trade_no" ],
* @return array|mixed|void "subject" => str_sub($param[ "pay_body" ], 15),
*/ "total_amount" => (float) $param[ "pay_money" ],
public function micropay($param) "scene" => "bar_code",
{ "auth_code" => $param[ 'auth_code' ],
try { );
//构造要请求的参数数组,无需改动 $parameter = json_encode($parameter);
$parameter = array ( $request = new AlipayTradePayRequest();
"out_trade_no" => $param[ "out_trade_no" ], $request->setBizContent($parameter);
"subject" => str_sub($param[ "pay_body" ], 15), $result = $this->aop->execute($request);
"total_amount" => (float) $param[ "pay_money" ], $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
"scene" => "bar_code", $resultCode = $result->$responseNode->code;
"auth_code" => $param[ 'auth_code' ], Log::write('支付宝—付款码支付result' . json_encode($result));
); Log::write('支付宝—付款码支付resultCode' . json_encode($resultCode));
$parameter = json_encode($parameter); if (!empty($resultCode)) {
$request = new AlipayTradePayRequest(); if ($resultCode == 10000) {
$request->setBizContent($parameter); $pay_common = new PayModel();
$result = $this->aop->execute($request); return $res = $pay_common->onlinePay($param[ 'out_trade_no' ], 'alipay', $result->$responseNode->trade_no, 'alipay');
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response"; } else if ($resultCode == 10003) {
$resultCode = $result->$responseNode->code; // 等待用户付款
Log::write('支付宝—付款码支付result' . json_encode($result)); ( new Cron() )->addCron(1, 0, "查询付款码支付结果", "PayOrderQuery", time() + 3, $param[ 'id' ]);
Log::write('支付宝—付款码支付resultCode' . json_encode($resultCode)); }
if (!empty($resultCode)) { } else {
if ($resultCode == 10000) { return $this->error([], $result->$responseNode->sub_msg);
$pay_common = new PayModel(); }
return $res = $pay_common->onlinePay($param[ 'out_trade_no' ], 'alipay', $result->$responseNode->trade_no, 'alipay'); } catch (\Exception $e) {
} else if ($resultCode == 10003) { return $this->error([], $e->getMessage());
// 等待用户付款 }
( new Cron() )->addCron(1, 0, "查询付款码支付结果", "PayOrderQuery", time() + 3, $param[ 'id' ]); }
}
} else { // todo 查询交易信息【AlipayTradeQueryRequest】 https://opendocs.alipay.com/open/194/106039?pathHash=5b8cf9e6
return $this->error([], $result->$responseNode->sub_msg); public function orderQuery($param)
} {
} catch (\Exception $e) { try {
return $this->error([], $e->getMessage()); //构造要请求的参数数组,无需改动
} $parameter = array (
} "out_trade_no" => $param[ "out_trade_no" ],
);
// todo 查询交易信息【AlipayTradeQueryRequest】 https://opendocs.alipay.com/open/194/106039?pathHash=5b8cf9e6 $parameter = json_encode($parameter);
public function orderQuery($param) $request = new AlipayTradeQueryRequest();
{ $request->setBizContent($parameter);
try { $result = $this->aop->execute($request);
//构造要请求的参数数组,无需改动 $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
$parameter = array ( $resultCode = $result->$responseNode->code;
"out_trade_no" => $param[ "out_trade_no" ], Log::write('alipay_orderQuery' . json_encode($result));
); Log::write('alipay_orderQuery_$resultCode' . json_encode($resultCode));
$parameter = json_encode($parameter); if (!empty($resultCode) && $resultCode == 10000) {
$request = new AlipayTradeQueryRequest(); if ($result->$responseNode->trade_status == 'TRADE_SUCCESS') {
$request->setBizContent($parameter); $pay_common = new PayModel();
$result = $this->aop->execute($request); return $res = $pay_common->onlinePay($param[ 'out_trade_no' ], 'alipay', $result->$responseNode->trade_no, 'alipay');
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response"; } else {
$resultCode = $result->$responseNode->code; ( new Cron() )->addCron(1, 0, "查询付款码支付结果", "PayOrderQuery", time() + 3, $param[ 'id' ]);
Log::write('alipay_orderQuery' . json_encode($result)); }
Log::write('alipay_orderQuery_$resultCode' . json_encode($resultCode));
if (!empty($resultCode) && $resultCode == 10000) { } else {
if ($result->$responseNode->trade_status == 'TRADE_SUCCESS') { return $this->error([], $result->$responseNode->sub_msg);
$pay_common = new PayModel(); }
return $res = $pay_common->onlinePay($param[ 'out_trade_no' ], 'alipay', $result->$responseNode->trade_no, 'alipay'); } catch (\Exception $e) {
} else { return $this->error([], $e->getMessage());
( new Cron() )->addCron(1, 0, "查询付款码支付结果", "PayOrderQuery", time() + 3, $param[ 'id' ]); }
} }
} else {
return $this->error([], $result->$responseNode->sub_msg); /**
} * 查询订单信息
} catch (\Exception $e) { * @param $out_trade_no
return $this->error([], $e->getMessage()); * @return array
} * @throws \think\Exception
} */
public function get($out_trade_no)
{
/** $parameter = array (
* 查询订单信息 "out_trade_no" => $out_trade_no
* @param $out_trade_no );
* @return array // 建立请求
* @throws \think\Exception $request = new AlipayTradeQueryRequest();
*/ $request->setBizContent(json_encode($parameter));
public function get($out_trade_no) $result = $this->aop->execute($request);
{ $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
$parameter = array ( $resultCode = $result->$responseNode->code;
"out_trade_no" => $out_trade_no
);
// 建立请求 if (!empty($resultCode) && $resultCode == 10000) {
$request = new AlipayTradeQueryRequest(); return $this->success(json_decode(json_encode($result->$responseNode), true));
$request->setBizContent(json_encode($parameter)); } else {
$result = $this->aop->execute($request); return $this->error([], $result->$responseNode->sub_msg);
$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 <?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;
*/
/**
namespace addon\alipay\shop\controller; * 支付宝 控制器
*/
use addon\alipay\model\Config as ConfigModel; class Pay extends BaseShop
use app\shop\controller\BaseShop; {
use think\facade\Config; public function config()
use app\model\upload\Upload; {
$config_model = new ConfigModel();
/** if (request()->isJson()) {
* 支付宝 控制器 $app_id = input("app_id", "");//支付宝应用ID (支付宝分配给开发者的应用ID)
*/ $private_key = input("private_key", "");//应用私钥
class Pay extends BaseShop $public_key = input("public_key", "");//应用公钥
{ $alipay_public_key = input("alipay_public_key", "");//支付宝公钥
public function config() $app_type = input("app_type", "");//支持端口 如web app
{ $pay_status = input("pay_status", 0);//支付启用状态
$config_model = new ConfigModel(); $refund_status = input("refund_status", 0);//退款启用状态
if (request()->isJson()) { $transfer_status = input("transfer_status", 0);//转账启用状态
$app_id = input("app_id", "");//支付宝应用ID (支付宝分配给开发者的应用ID) $public_key_crt = input("public_key_crt", "");
$private_key = input("private_key", "");//应用私钥 $alipay_public_key_crt = input("alipay_public_key_crt", "");
$public_key = input("public_key", "");//应用公钥 $alipay_with_crt = input("alipay_with_crt", "");
$alipay_public_key = input("alipay_public_key", "");//支付宝公钥 $countersign_type = input("countersign_type", 0);//加签模式
$app_type = input("app_type", "");//支持端口 如web app
$pay_status = input("pay_status", 0);//支付启用状态 $data = array (
$refund_status = input("refund_status", 0);//退款启用状态 "app_id" => $app_id,
$transfer_status = input("transfer_status", 0);//转账启用状态 "private_key" => $private_key,
$public_key_crt = input("public_key_crt", ""); "public_key" => $public_key,
$alipay_public_key_crt = input("alipay_public_key_crt", ""); "alipay_public_key" => $alipay_public_key,
$alipay_with_crt = input("alipay_with_crt", ""); "refund_status" => $refund_status,
$countersign_type = input("countersign_type", 0);//加签模式 "pay_status" => $pay_status,
"transfer_status" => $transfer_status,
$data = array ( "app_type" => $app_type,
"app_id" => $app_id, "public_key_crt" => $public_key_crt,
"private_key" => $private_key, "alipay_public_key_crt" => $alipay_public_key_crt,
"public_key" => $public_key, "alipay_with_crt" => $alipay_with_crt,
"alipay_public_key" => $alipay_public_key, "countersign_type" => $countersign_type
"refund_status" => $refund_status, );
"pay_status" => $pay_status, $result = $config_model->setPayConfig($data, $this->site_id, $this->app_module);
"transfer_status" => $transfer_status, return $result;
"app_type" => $app_type, } else {
"public_key_crt" => $public_key_crt, $info = $config_model->getPayConfig($this->site_id, $this->app_module, true)[ 'data' ][ 'value' ];
"alipay_public_key_crt" => $alipay_public_key_crt,
"alipay_with_crt" => $alipay_with_crt, if (!empty($info)) {
"countersign_type" => $countersign_type $app_type_arr = [];
); if (!empty($info[ 'app_type' ])) {
$result = $config_model->setPayConfig($data, $this->site_id, $this->app_module); $app_type_arr = explode(',', $info[ 'app_type' ]);
return $result; }
} else { $info[ 'app_type_arr' ] = $app_type_arr;
$info = $config_model->getPayConfig($this->site_id, $this->app_module, true)[ 'data' ][ 'value' ]; if (empty($info[ 'countersign_type' ])) {
$info[ 'countersign_type' ] = 0;
if (!empty($info)) { }
$app_type_arr = []; }
if (!empty($info[ 'app_type' ])) { $this->assign("info", $info);
$app_type_arr = explode(',', $info[ 'app_type' ]); $this->assign("app_type", Config::get("app_type"));
}
$info[ 'app_type_arr' ] = $app_type_arr; return $this->fetch("pay/config");
if (empty($info[ 'countersign_type' ])) { }
$info[ 'countersign_type' ] = 0; }
}
} /**
$this->assign("info", $info); * 上传微信支付证书
$this->assign("app_type", Config::get("app_type")); */
public function uploadAlipayCrt()
return $this->fetch("pay/config"); {
} $upload_model = new Upload();
} $site_id = request()->siteid();
$name = input("name", "");
/** $extend_type = [ 'crt' ];
* 上传微信支付证书 $param = array (
*/ "name" => "file",
public function uploadAlipayCrt() "extend_type" => $extend_type
{ );
$upload_model = new Upload();
$site_id = request()->siteid(); $site_id = max($site_id, 0);
$name = input("name", ""); $result = $upload_model->setPath("common/alipay/crt/" . $site_id . "/")->file($param);
$extend_type = [ 'crt' ]; return $result;
$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 <?php
/**
return [
// 自定义模板页面类型,格式:[ 'title' => '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据json格式' ]
'template' => [],
// 后台自定义组件——装修
*/ 'util' => [],
return [ // 自定义页面路径
'link' => [
// 自定义模板页面类型,格式:[ 'title' => '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据json格式' ] [
'template' => [], 'name' => 'CASES_INFO',
'title' => '案例展示',
// 后台自定义组件——装修 'parent' => 'BASICS_LINK',
'util' => [], 'wap_url' => '/pages_tool/cases/index',
'web_url' => '',
// 自定义页面路径 'sort' => 0
'link' => [ ]
[ ],
'name' => 'CASES_INFO',
'title' => '案例展示', // 自定义图标库
'parent' => 'BASICS_LINK', 'icon_library' => [],
'wap_url' => '/pages_tool/cases/index',
'web_url' => '', // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ]多个逗号隔开自定义组件名称前缀必须是diy-,也可以引用第三方组件
'sort' => 0 'component' => [],
]
], // uni-app 页面,多个逗号隔开
'pages' => [],
// 自定义图标库
'icon_library' => [], // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
'info' => [],
// uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ]多个逗号隔开自定义组件名称前缀必须是diy-,也可以引用第三方组件
'component' => [], // 主题风格配色格式可以自由定义扩展【在uni-app中通过this.themeStyle... 获取定义的颜色字段例如this.themeStyle.main_color】
'theme' => [],
// uni-app 页面,多个逗号隔开
'pages' => [], // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据json格式] ]
'data' => []
// 模板信息,格式:'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 <?php
/** return [
'name' => 'cases',
'title' => '案例展示',
'description' => '展示案例信息',
'type' => 'tool', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
'status' => 1,
'author' => '',
'version' => '1.0.0',
*/ 'version_no' => '2025051923121',
return [ 'content' => '',
'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 <?php
/**
namespace addon\cases\event;
/**
* 应用安装
*/
class Install
*/ {
/**
namespace addon\cases\event; * 执行安装
*/
/** public function handle()
* 应用安装 {
*/ return success();
class Install }
{
/**
* 执行安装
*/
public function handle()
{
return success();
}
} }

View File

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

View File

@@ -1,351 +1,343 @@
<?php <?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;
namespace addon\coupon\api\controller; /**
* 优惠券
use app\api\controller\BaseApi; */
use addon\coupon\model\Coupon as CouponModel; class Coupon extends BaseApi
use addon\coupon\model\CouponType as CouponTypeModel; {
use addon\coupon\model\MemberCoupon;
use think\facade\Db; /**
* 优惠券类型信息
/** */
* 优惠券 public function typeinfo()
*/ {
class Coupon extends BaseApi $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';
public function typeinfo()
{ $coupon_model = new CouponModel();
$coupon_type_id = $this->params['coupon_type_id'] ?? 0; $condition = [
if (empty($coupon_type_id)) { [ 'coupon_type_id', '=', $coupon_type_id ],
return $this->response($this->error('', 'REQUEST_COUPON_TYPE_ID')); [ 'is_show', '=', 1 ],
} [ 'site_id', '=', $this->site_id ]
];
$app_type = $this->params['app_type'] ?? 'h5';
$coupon_type_model = new CouponTypeModel();
$coupon_model = new CouponModel(); $qrcode = $coupon_type_model->qrcode($coupon_type_id, $app_type, $this->site_id)[ 'data' ];
$condition = [
[ 'coupon_type_id', '=', $coupon_type_id ], $info = $coupon_model->getCouponTypeInfo($condition);
[ 'is_show', '=', 1 ], if (!empty($info[ 'data' ]) && !empty($qrcode)) {
[ 'site_id', '=', $this->site_id ] $info[ 'data' ][ 'qrcode' ] = $qrcode[ 'path' ];
]; }
return $this->response($info);
$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' ]; public function memberpage()
} {
return $this->response($info); $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已过期
public function memberpage()
{ $coupon_model = new CouponModel();
$token = $this->checkToken(); $condition = [
if ($token[ 'code' ] < 0) return $this->response($token); [ 'npc.member_id', '=', $token[ 'data' ][ 'member_id' ] ],
[ 'npc.state', '=', $state ]
$page = $this->params['page'] ?? 1; ];
$page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
$state = $this->params['state'] ?? 1;//优惠券状态 1已领用未使用 2已使用 3已过期 //按类型筛选
$type = $this->params['type'] ?? '';
$coupon_model = new CouponModel(); $related_id = $this->params['related_id'] ?? 0;
$condition = [ switch ( $type ) {
[ 'npc.member_id', '=', $token[ 'data' ][ 'member_id' ] ], case 'reward'://满减
[ 'npc.state', '=', $state ] $condition[] = ['npc.type', '=', 'reward'];
]; break;
case 'discount'://折扣
//按类型筛选 $condition[] = ['npc.type', '=', 'discount'];
$type = $this->params['type'] ?? ''; break;
$related_id = $this->params['related_id'] ?? 0; case 'no_threshold'://无门槛
switch ( $type ) { $condition[] = ['npc.at_least', '=', 0 ];
case 'reward'://满减 break;
$condition[] = ['npc.type', '=', 'reward']; }
break; if (!empty($related_id)) {
case 'discount'://折扣 $condition[] = [ 'related_id', '=', $related_id ];
$condition[] = ['npc.type', '=', 'discount']; }
break;
case 'no_threshold'://无门槛 $list = $coupon_model->getMemberCouponPageList($condition, $page, $page_size);
$condition[] = ['npc.at_least', '=', 0 ];
break; return $this->response($list);
} }
if (!empty($related_id)) {
$condition[] = [ 'related_id', '=', $related_id ]; /**
} * 优惠券类型列表
*/
$list = $coupon_model->getMemberCouponPageList($condition, $page, $page_size); public function typelists()
{
return $this->response($list); $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();
*/
public function typelists() $coupon_model = new CouponModel();
{ $condition = [
$num = $this->params['num'] ?? 0; [ 'status', '=', 1 ],
$coupon_type_id_arr = $this->params['coupon_type_id_arr'] ?? '';//coupon_type_id数组 [ 'is_show', '=', 1 ],
$can_receive = $this->params['can_receive'] ?? 0;// 是否只查询可领取的 [ 'site_id', '=', $this->site_id ]
];
$token = $this->checkToken();
//按类型查询
$coupon_model = new CouponModel(); $type = $this->params['type'] ?? '';
$condition = [ switch ( $type ) {
[ 'status', '=', 1 ], case 'reward'://满减
[ 'is_show', '=', 1 ], $condition[] = ['type', '=', 'reward'];
[ 'site_id', '=', $this->site_id ] break;
]; case 'discount'://折扣
$condition[] = ['type', '=', 'discount'];
//按类型查询 break;
$type = $this->params['type'] ?? ''; case 'no_threshold'://无门槛
switch ( $type ) { $condition[] = ['at_least', '=', 0 ];
case 'reward'://满减 break;
$condition[] = ['type', '=', 'reward']; }
break;
case 'discount'://折扣 if (!empty($coupon_type_id_arr)) {
$condition[] = ['type', '=', 'discount']; $condition[] = [ 'coupon_type_id', 'in', $coupon_type_id_arr ];
break; }
case 'no_threshold'://无门槛 $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';
$condition[] = ['at_least', '=', 0 ]; if ($can_receive == 1) {
break; $condition[] = [ [ 'count', '<>', Db::raw('lead_count') ] ];
} }
if (!empty($coupon_type_id_arr)) { $order = Db::raw('IF(count < 0 or count - lead_count > 0, 1, 0) DESC,sort ASC');
$condition[] = [ 'coupon_type_id', 'in', $coupon_type_id_arr ];
} $list = $coupon_model->getCouponTypeList($condition, $field, $order, $num);
$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 (!empty($list[ 'data' ]) && $this->member_id) {
if ($can_receive == 1) { foreach ($list[ 'data' ] as $k => $v) {
$condition[] = [ [ 'count', '<>', Db::raw('lead_count') ] ]; $list[ 'data' ][ $k ][ 'member_coupon_num' ] = $coupon_model->getCouponCount([
} [ 'get_type', '=', 2 ],
[ 'member_id', '=', $this->member_id ],
$order = Db::raw('IF(count < 0 or count - lead_count > 0, 1, 0) DESC,sort ASC'); [ 'coupon_type_id', '=', $v[ 'coupon_type_id' ] ]
])[ 'data' ];
$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([ return $this->response($list);
[ 'get_type', '=', 2 ], }
[ 'member_id', '=', $this->member_id ],
[ 'coupon_type_id', '=', $v[ 'coupon_type_id' ] ] /**
])[ 'data' ]; * 优惠券类型分页列表
} */
} public function typepagelists()
{
return $this->response($list); $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();
public function typepagelists()
{ $coupon_model = new CouponModel();
$page = $this->params['page'] ?? 1; $condition = [
$page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS; [ 'status', '=', 1 ],
$coupon_type_id_arr = $this->params['coupon_type_id_arr'] ?? '';//coupon_type_id数组 [ 'is_show', '=', 1 ],
$can_receive = $this->params['can_receive'] ?? 0;// 是否只查询可领取的 [ 'site_id', '=', $this->site_id ]
];
$token = $this->checkToken();
//按类型查询
$coupon_model = new CouponModel(); $type = $this->params['type'] ?? '';
$condition = [ switch ( $type ) {
[ 'status', '=', 1 ], case 'reward'://满减
[ 'is_show', '=', 1 ], $condition[] = ['type', '=', 'reward'];
[ 'site_id', '=', $this->site_id ] break;
]; case 'discount'://折扣
$condition[] = ['type', '=', 'discount'];
//按类型查询 break;
$type = $this->params['type'] ?? ''; case 'no_threshold'://无门槛
switch ( $type ) { $condition[] = ['at_least', '=', 0 ];
case 'reward'://满减 break;
$condition[] = ['type', '=', 'reward']; }
break;
case 'discount'://折扣 if (!empty($coupon_type_id_arr)) {
$condition[] = ['type', '=', 'discount']; $condition[] = [ 'coupon_type_id', 'in', $coupon_type_id_arr ];
break; }
case 'no_threshold'://无门槛 $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';
$condition[] = ['at_least', '=', 0 ]; if ($can_receive == 1) {
break; $condition[] = [ [ 'count', '<>', Db::raw('lead_count') ] ];
} }
if (!empty($coupon_type_id_arr)) { if ($this->member_id) {
$condition[] = [ 'coupon_type_id', 'in', $coupon_type_id_arr ]; $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';
$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->getCouponTypePageList($condition, $page, $page_size, $order, $field, 'ct');
if ($this->member_id) {
$prefix = config('database.connections.mysql.prefix'); return $this->response($list);
$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'); public function receive()
{
return $this->response($list); $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.活动领取
public function receive()
{ if (empty($coupon_type_id)) {
$token = $this->checkToken(); return $this->response($this->error('', 'REQUEST_COUPON_TYPE_ID'));
if ($token[ 'code' ] < 0) return $this->response($token); }
$site_id = $this->site_id; $coupon_model = new CouponModel();
$coupon_type_id = $this->params['coupon_type_id'] ?? 0; $res = $coupon_model->receiveCoupon($coupon_type_id, $site_id, $token[ 'data' ][ 'member_id' ], $get_type);
$get_type = $this->params['get_type'] ?? 2;//获取方式:1订单2.直接领取3.活动领取 $res[ 'data' ] = [];
if (empty($coupon_type_id)) { //判断一下用户是否拥有当前优惠券
return $this->response($this->error('', 'REQUEST_COUPON_TYPE_ID')); $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);
$coupon_model = new CouponModel(); }
$res = $coupon_model->receiveCoupon($coupon_type_id, $site_id, $token[ 'data' ][ 'member_id' ], $get_type);
$res[ 'data' ] = []; /**
* 会员优惠券数量
//判断一下用户是否拥有当前优惠券 * @return string
$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; public function num()
return $this->response($res); {
} $token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
/**
* 会员优惠券数量 $state = $this->params[ 'state' ] ?? 1;
* @return string $coupon_model = new MemberCoupon();
*/
public function num() $count = $coupon_model->getMemberCouponNum($token[ 'data' ][ 'member_id' ], $state);
{ return $this->response($count);
$token = $this->checkToken(); }
if ($token[ 'code' ] < 0) return $this->response($token);
/**
$state = $this->params[ 'state' ] ?? 1; * 是否可以领取
$coupon_model = new MemberCoupon(); */
public function receivedNum()
$count = $coupon_model->getMemberCouponNum($token[ 'data' ][ 'member_id' ], $state); {
return $this->response($count); $token = $this->checkToken();
} if ($token[ 'code' ] < 0) return $this->response($token);
/** $coupon_type_id = $this->params['coupon_type_id'] ?? 0;
* 是否可以领取
*/ $coupon_model = new MemberCoupon();
public function receivedNum() $res = $coupon_model->receivedNum($coupon_type_id, $this->member_id);
{ return $this->response($res);
$token = $this->checkToken(); }
if ($token[ 'code' ] < 0) return $this->response($token);
/**
$coupon_type_id = $this->params['coupon_type_id'] ?? 0; * 查询商品可用的优惠券
* @param int $id
$coupon_model = new MemberCoupon(); * @return false|string
$res = $coupon_model->receivedNum($coupon_type_id, $this->member_id); */
return $this->response($res); public function goodsCoupon($id = 0)
} {
$this->checkToken();
/** $coupon_model = new CouponModel();
* 查询商品可用的优惠券 $goods_id = $this->params[ 'goods_id' ] ?? 0;
* @param int $id if (!empty($id)) {
* @return false|string $goods_id = $id;
*/ }
public function goodsCoupon($id = 0)
{ // 查询全部商品参与
$this->checkToken(); $condition = [
$coupon_model = new CouponModel(); [ 'site_id', '=', $this->site_id ],
$goods_id = $this->params[ 'goods_id' ] ?? 0; [ 'status', '=', 1 ],
if (!empty($id)) { [ 'is_show', '=', 1 ],
$goods_id = $id; [ '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';
$condition = [
[ 'site_id', '=', $this->site_id ], if ($this->member_id) {
[ 'status', '=', 1 ], $prefix = config('database.connections.mysql.prefix');
[ 'is_show', '=', 1 ], $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';
[ 'goods_type', '=', 1 ] }
];
$list = $coupon_model->getCouponTypeList($condition, $field, 'money desc', null, 'ct');
$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) { $goods_condition = [
$prefix = config('database.connections.mysql.prefix'); [ 'site_id', '=', $this->site_id ],
$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'; [ 'status', '=', 1 ],
} [ 'is_show', '=', 1 ],
[ 'goods_type', '=', 2 ],
$list = $coupon_model->getCouponTypeList($condition, $field, 'money desc', null, 'ct'); [ 'goods_ids', 'like', "%,$goods_id,%" ]
];
// 查询指定商品参与
$goods_condition = [ $goods_coupon = $coupon_model->getCouponTypeList($goods_condition, $field, 'money desc', null, 'ct');
[ 'site_id', '=', $this->site_id ],
[ 'status', '=', 1 ], if (!empty($goods_coupon[ 'data' ])) {
[ 'is_show', '=', 1 ], $list[ 'data' ] = array_merge($list[ 'data' ], $goods_coupon[ 'data' ]);
[ 'goods_type', '=', 2 ], }
[ 'goods_ids', 'like', "%,$goods_id,%" ]
]; // 查询指定商品不参与
$not_goods_condition = [
$goods_coupon = $coupon_model->getCouponTypeList($goods_condition, $field, 'money desc', null, 'ct'); [ 'site_id', '=', $this->site_id ],
[ 'status', '=', 1 ],
if (!empty($goods_coupon[ 'data' ])) { [ 'is_show', '=', 1 ],
$list[ 'data' ] = array_merge($list[ 'data' ], $goods_coupon[ 'data' ]); [ 'goods_type', '=', 3 ],
} [ 'goods_ids', 'not like', "%,$goods_id,%" ]
];
// 查询指定商品不参与
$not_goods_condition = [ $not_goods_coupon = $coupon_model->getCouponTypeList($not_goods_condition, $field, 'money desc', null, 'ct');
[ 'site_id', '=', $this->site_id ], if (!empty($not_goods_coupon[ 'data' ])) {
[ 'status', '=', 1 ], $list[ 'data' ] = array_merge($list[ 'data' ], $not_goods_coupon[ 'data' ]);
[ 'is_show', '=', 1 ], }
[ 'goods_type', '=', 3 ],
[ 'goods_ids', 'not like', "%,$goods_id,%" ] if ($list[ 'data' ] && $this->member_id) {
]; foreach ($list[ 'data' ] as $k => $v) {
// 已抢光
$not_goods_coupon = $coupon_model->getCouponTypeList($not_goods_condition, $field, 'money desc', null, 'ct'); if ($v[ 'count' ] == $v[ 'lead_count' ]) {
if (!empty($not_goods_coupon[ 'data' ])) { unset($list[ 'data' ][ $k ]);
$list[ 'data' ] = array_merge($list[ 'data' ], $not_goods_coupon[ 'data' ]); } elseif ($v[ 'max_fetch' ] != 0 && $v[ 'member_coupon_num' ] > 0 && $v[ 'member_coupon_num' ] >= $v[ 'max_fetch' ]) {
} // 已领取
unset($list[ 'data' ][ $k ]);
if ($list[ 'data' ] && $this->member_id) { }
foreach ($list[ 'data' ] as $k => $v) { }
// 已抢光 $list[ 'data' ] = array_values($list[ 'data' ]);
if ($v[ 'count' ] == $v[ 'lead_count' ]) { }
unset($list[ 'data' ][ $k ]); return $this->response($list);
} elseif ($v[ 'max_fetch' ] != 0 && $v[ 'member_coupon_num' ] > 0 && $v[ 'member_coupon_num' ] >= $v[ 'max_fetch' ]) { }
// 已领取
unset($list[ 'data' ][ $k ]); /**
} * 查询优惠券通过优惠券类型id
} */
$list[ 'data' ] = array_values($list[ 'data' ]); public function couponById()
} {
return $this->response($list); $id = $this->params[ 'id' ] ?? 0;
} $coupon_model = new CouponModel();
$condition = [
/** [ 'site_id', '=', $this->site_id ],
* 查询优惠券通过优惠券类型id [ 'status', '=', 1 ],
*/ [ 'coupon_type_id', 'in', $id ]
public function couponById() ];
{ $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', '');
$id = $this->params[ 'id' ] ?? 0; return $this->response($list);
$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 <?php
/** return [
// 自定义模板页面类型,格式:[ 'title' => '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据json格式' ]
'template' => [],
// 后台自定义组件——装修
'util' => [
*/ [
return [ 'name' => 'Coupon',
'title' => '优惠券',
// 自定义模板页面类型,格式:[ 'title' => '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据json格式' ] 'type' => 'PROMOTION',
'template' => [], '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' => '',
'util' => [ 'max_count' => 0,
[ 'icon' => 'iconfont iconyouhuiquan',
'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', 'link' => [
'support_diy_view' => '', [
'max_count' => 0, 'name' => 'COUPON_LIST',
'icon' => 'iconfont iconyouhuiquan', 'title' => '优惠券',
], 'parent' => 'MARKETING_LINK',
], 'wap_url' => '',
'web_url' => '',
// 自定义页面路径 'sort' => 0,
'link' => [ 'child_list' => [
[ [
'name' => 'COUPON_LIST', 'name' => 'COUPON_PREFECTURE',
'title' => '优惠券', 'title' => '优惠券专区',
'parent' => 'MARKETING_LINK', 'wap_url' => '/pages_tool/goods/coupon',
'wap_url' => '', 'web_url' => '',
'web_url' => '', 'sort' => 0
'sort' => 0, ]
'child_list' => [ ]
[ ],
'name' => 'COUPON_PREFECTURE', ],
'title' => '优惠券专区',
'wap_url' => '/pages_tool/goods/coupon', // 自定义图标库
'web_url' => '', 'icon_library' => [],
'sort' => 0
] // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ]多个逗号隔开自定义组件名称前缀必须是diy-,也可以引用第三方组件
] 'component' => [],
],
], // uni-app 页面,多个逗号隔开
'pages' => [],
// 自定义图标库
'icon_library' => [], // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
'info' => [],
// uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ]多个逗号隔开自定义组件名称前缀必须是diy-,也可以引用第三方组件
'component' => [], // 主题风格配色格式可以自由定义扩展【在uni-app中通过this.themeStyle... 获取定义的颜色字段例如this.themeStyle.main_color】
'theme' => [],
// uni-app 页面,多个逗号隔开
'pages' => [], // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据json格式] ]
'data' => []
// 模板信息,格式:'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 <?php
/** return [
'name' => 'coupon',
'title' => '优惠券',
'description' => '会员优惠券功能',
'type' => 'system', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
'status' => 1,
'author' => '',
'version' => '5.3.1',
*/ 'version_no' => '525231212001',
return [ 'content' => '',
'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 <?php
/** namespace addon\coupon\dict;
/**
* 订单公共属性
*/
class CouponDict
*/ {
const normal = 1;
namespace addon\coupon\dict; const used = 2;
const expire = 3;
const close = 4;
/**
* 订单公共属性 /**
*/ * 优惠券状态
class CouponDict * @param $status
{ * @return string|string[]
const normal = 1; */
const used = 2; public static function getStatus($status = ''){
const expire = 3; $list = [
const close = 4; self::normal => '待使用',
self::used => '已使用',
/** self::expire => '已过期',
* 优惠券状态 self::close => '已关闭',
* @param $status ];
* @return string|string[]
*/ if($status) return $list[$status] ?? '';
public static function getStatus($status = ''){ return $list;
$list = [ }
self::normal => '待使用',
self::used => '已使用', const all = 1;
self::expire => '已过期', const selected = 2;
self::close => '已关闭', const selected_out = 3;
]; public static function getGoodsType($type = ''){
$list = [
if($status) return $list[$status] ?? ''; self::all => '全部商品参与',
return $list; self::selected => '指定商品参与',
} self::selected_out => '指定不参与商品'
];
const all = 1;
const selected = 2; if($type) return $list[$type] ?? '';
const selected_out = 3; return $list;
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 <?php
/**
namespace addon\coupon\event;
use addon\coupon\model\Coupon;
/**
* 启动活动
*/ */
class CronCouponEnd
namespace addon\coupon\event; {
use addon\coupon\model\Coupon; public function handle($params = [])
{
/** $coupon = new Coupon();
* 启动活动 $res = $coupon->cronCouponEnd();
*/ return $res;
class CronCouponEnd }
{
public function handle($params = [])
{
$coupon = new Coupon();
$res = $coupon->cronCouponEnd();
return $res;
}
} }

View File

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

View File

@@ -1,38 +1,29 @@
<?php <?php
/**
namespace addon\coupon\event;
use app\model\system\Cron;
/**
* 应用安装
*/
*/ class Install
{
namespace addon\coupon\event; /**
* 执行安装
use app\model\system\Cron; */
public function handle()
/** {
* 应用安装 try {
*/ execute_sql('addon/coupon/data/install.sql');
class Install
{ $cron = new Cron();
/** $cron->deleteCron([ ['event', '=', 'CronCouponEnd'] ]);
* 执行安装 $cron->addCron(2, 1, '优惠券过期自动关闭', 'CronCouponEnd', time(), 0);
*/
public function handle() return success();
{ } catch (\Exception $e) {
try { return error('', $e->getMessage());
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 <?php
/**
namespace addon\coupon\event;
/**
* 店铺活动
*/
class ShowPromotion
*/ {
namespace addon\coupon\event; /**
* 活动展示
/** * @return array
* 店铺活动 */
*/ public function handle()
class ShowPromotion {
{ $data = [
'shop' => [
/** [
* 活动展示 //插件名称
* @return array 'name' => 'coupon',
*/ //展示分类根据平台端设置admin平台营销shop店铺营销member:会员营销, tool:应用工具)
public function handle() 'show_type' => 'shop',
{ //展示主题
$data = [ 'title' => '优惠券',
'shop' => [ //展示介绍
[ 'description' => '设置商家优惠券',
//插件名称 //展示图标
'name' => 'coupon', 'icon' => 'addon/coupon/icon.png',
//展示分类根据平台端设置admin平台营销shop店铺营销member:会员营销, tool:应用工具) //跳转链接
'show_type' => 'shop', 'url' => 'coupon://shop/coupon/lists',
//展示主题 ]
'title' => '优惠券', ]
//展示介绍
'description' => '设置商家优惠券', ];
//展示图标 return $data;
'icon' => 'addon/coupon/icon.png', }
//跳转链接
'url' => 'coupon://shop/coupon/lists',
]
]
];
return $data;
}
} }

View File

@@ -1,32 +1,23 @@
<?php <?php
/**
namespace addon\coupon\event;
/**
* 应用卸载
*/
class UnInstall
{
*/ /**
* 执行卸载
namespace addon\coupon\event; */
public function handle()
/** {
* 应用卸载 try {
*/ return error('', "系统插件不允许删除");
class UnInstall //execute_sql('addon/coupon/data/uninstall.sql');
{ //return success();
/** } catch (\Exception $e) {
* 执行卸载 return error('', $e->getMessage());
*/ }
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 <?php
/**
namespace addon\coupon\model;
use app\model\BaseModel;
use app\model\system\Stat;
/**
*/ * 优惠券统计
*/
namespace addon\coupon\model; class CouponStat extends BaseModel
{
use app\model\BaseModel;
use app\model\system\Stat; /**
* 领取优惠券统计
/** * @param $params
* 优惠券统计 * @return array
*/ */
class CouponStat extends BaseModel public function addReceiveCouponStat($params)
{ {
$coupon_id = $params[ 'coupon_id' ];
/** $site_id = $params[ 'site_id' ] ?? 0;
* 领取优惠券统计 $order_condition = array (
* @param $params [ 'coupon_id', '=', $coupon_id ],
* @return array [ 'site_id', '=', $site_id ]
*/ );
public function addReceiveCouponStat($params) $info = model('promotion_coupon')->getInfo($order_condition);
{ if (empty($info))
$coupon_id = $params[ 'coupon_id' ]; return $this->error();
$site_id = $params[ 'site_id' ] ?? 0;
$order_condition = array ( $stat_data = array (
[ 'coupon_id', '=', $coupon_id ], 'site_id' => $site_id,
[ 'site_id', '=', $site_id ] 'coupon_count' => 1
); );
$info = model('promotion_coupon')->getInfo($order_condition); $member_id = $info[ 'member_id' ];
if (empty($info)) //如果是第一笔订单才能累加下单会员数
return $this->error();
$time_region = getDayStartAndEndTime();
$stat_data = array ( $today_start_time = $time_region[ 'start_time' ];
'site_id' => $site_id, $today_end_time = $time_region[ 'end_time' ];
'coupon_count' => 1 $today_order_condition = array (
); [ 'member_id', '=', $member_id ],
$member_id = $info[ 'member_id' ]; [ 'fetch_time', 'between', [ $today_start_time, $today_end_time ] ],
//如果是第一笔订单才能累加下单会员数 [ 'coupon_id', '<>', $coupon_id ]
);
$time_region = getDayStartAndEndTime(); $count = model('promotion_coupon')->getCount($today_order_condition);
$today_start_time = $time_region[ 'start_time' ]; if ($count == 0) {
$today_end_time = $time_region[ 'end_time' ]; $stat_data[ 'coupon_member_count' ] = 1;
$today_order_condition = array ( }
[ 'member_id', '=', $member_id ],
[ 'fetch_time', 'between', [ $today_start_time, $today_end_time ] ], //发布统计
[ 'coupon_id', '<>', $coupon_id ] $stat_model = new Stat();
); $result = $stat_model->addShopStat($stat_data);
$count = model('promotion_coupon')->getCount($today_order_condition); return $result;
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 <?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;
*/
/**
namespace addon\coupon\model; * 优惠券活动
*/
use app\model\BaseModel; class CouponType extends BaseModel
use app\model\system\Config as ConfigModel; {
use app\model\system\Cron; //优惠券类型状态
use app\model\upload\Upload; private $coupon_type_status = [
1 => '进行中',
/** 2 => '已结束',
* 优惠券活动 -1 => '已关闭',
*/ ];
class CouponType extends BaseModel
{ public function getCouponTypeStatus()
//优惠券类型状态 {
private $coupon_type_status = [ return $this->coupon_type_status;
1 => '进行中', }
2 => '已结束',
-1 => '已关闭', /**
]; * 添加优惠券活动
* @param $data
public function getCouponTypeStatus() * @return array
{ */
return $this->coupon_type_status; public function addCouponType($data)
} {
//只要创建了就是进行中
/** $data[ 'status' ] = 1;
* 添加优惠券活动 $data[ 'create_time' ] = time();
* @param $data //获取商品id
* @return array if ($data[ 'goods_type' ] == 1) {//全部商品参与
*/ $data[ 'goods_ids' ] = '';
public function addCouponType($data) }
{
//只要创建了就是进行中 $data[ 'goods_ids' ] = ',' . $data[ 'goods_ids' ] . ',';
$data[ 'status' ] = 1; $res = model('promotion_coupon_type')->add($data);
$data[ 'create_time' ] = time(); if ($data[ 'validity_type' ] == 0) {
//获取商品id $cron = new Cron();
if ($data[ 'goods_type' ] == 1) {//全部商品参与 $cron->addCron(1, 1, '优惠券活动定时结束', 'CronCouponTypeEnd', $data[ 'end_time' ], $res);
$data[ 'goods_ids' ] = ''; }
}
$this->qrcode($res, 'all', $data[ 'site_id' ]);
$data[ 'goods_ids' ] = ',' . $data[ 'goods_ids' ] . ','; return $this->success($res);
$res = model('promotion_coupon_type')->add($data); }
if ($data[ 'validity_type' ] == 0) {
$cron = new Cron(); /**
$cron->addCron(1, 1, '优惠券活动定时结束', 'CronCouponTypeEnd', $data[ 'end_time' ], $res); * 编辑优惠券活动
} * @param $data
* @param $coupon_type_id
$this->qrcode($res, 'all', $data[ 'site_id' ]); * @return array
return $this->success($res); */
} public function editCouponType($data, $coupon_type_id)
{
/** $data[ 'update_time' ] = time();
* 编辑优惠券活动
* @param $data //获取商品id
* @param $coupon_type_id if ($data[ 'goods_type' ] == 1) {//全部商品参与
* @return array $data[ 'goods_ids' ] = '';
*/ }
public function editCouponType($data, $coupon_type_id)
{ $coupon_info = model('promotion_coupon_type')->getInfo([ [ 'coupon_type_id', '=', $coupon_type_id ] ]);
$data[ 'update_time' ] = time(); if (!empty($coupon_info[ 'image' ]) && !empty($data[ 'image' ]) && $coupon_info[ 'image' ] != $data[ 'image' ]) {
$upload_model = new Upload();
//获取商品id $upload_model->deletePic($coupon_info[ 'image' ], $coupon_info[ 'site_id' ]);
if ($data[ 'goods_type' ] == 1) {//全部商品参与 }
$data[ 'goods_ids' ] = '';
} $data[ 'goods_ids' ] = ',' . $data[ 'goods_ids' ] . ',';
$res = model('promotion_coupon_type')->update($data, [ [ 'coupon_type_id', '=', $coupon_type_id ] ]);
$coupon_info = model('promotion_coupon_type')->getInfo([ [ '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 ] ]);
if (!empty($coupon_info[ 'image' ]) && !empty($data[ 'image' ]) && $coupon_info[ 'image' ] != $data[ 'image' ]) { $cron = new Cron();
$upload_model = new Upload(); $cron->deleteCron([ [ 'event', '=', 'CronCouponTypeEnd' ], [ 'relate_id', '=', $coupon_type_id ] ]);
$upload_model->deletePic($coupon_info[ 'image' ], $coupon_info[ 'site_id' ]); if ($data[ 'validity_type' ] == 0) {
} $cron->addCron(1, 1, '优惠券活动定时结束', 'CronCouponTypeEnd', $data[ 'end_time' ], $coupon_type_id);
}
$data[ 'goods_ids' ] = ',' . $data[ 'goods_ids' ] . ','; return $this->success($res);
$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) { * @param $coupon_type_id
$cron->addCron(1, 1, '优惠券活动定时结束', 'CronCouponTypeEnd', $data[ 'end_time' ], $coupon_type_id); * @param $site_id
} * @return array
return $this->success($res); */
} 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) {
* @param $coupon_type_id // model("promotion_coupon")->update(['state' => 3], [['coupon_type_id', '=', $coupon_type_id], ['site_id', '=', $site_id]]);
* @param $site_id // }
* @return array $cron = new Cron();
*/ $cron->deleteCron([ [ 'event', '=', 'CronCouponTypeEnd' ], [ 'relate_id', '=', $coupon_type_id ] ]);
public function closeCouponType($coupon_type_id, $site_id) return $this->success($res);
{ }
$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]]); * 删除优惠券活动
// } * @param $coupon_type_id
$cron = new Cron(); * @param $site_id
$cron->deleteCron([ [ 'event', '=', 'CronCouponTypeEnd' ], [ 'relate_id', '=', $coupon_type_id ] ]); * @return array
return $this->success($res); */
} public function deleteCouponType($coupon_type_id, $site_id)
{
/** $coupon_info = model('promotion_coupon_type')->getInfo([ [ 'coupon_type_id', '=', $coupon_type_id ] ]);
* 删除优惠券活动
* @param $coupon_type_id if ($coupon_info['status'] == 1) return $this->error('', '进行中的优惠卷无法删除,请先关闭');
* @param $site_id
* @return array if (!empty($coupon_info[ 'image' ])) {
*/ $upload_model = new Upload();
public function deleteCouponType($coupon_type_id, $site_id) $upload_model->deletePic($coupon_info[ 'image' ], $coupon_info[ 'site_id' ]);
{ }
$coupon_info = model('promotion_coupon_type')->getInfo([ [ 'coupon_type_id', '=', $coupon_type_id ] ]);
$res = model('promotion_coupon_type')->delete([ [ 'coupon_type_id', '=', $coupon_type_id ], [ 'site_id', '=', $site_id ] ]);
if ($coupon_info['status'] == 1) return $this->error('', '进行中的优惠卷无法删除,请先关闭'); if ($res) {
model('promotion_coupon')->delete([ [ 'coupon_type_id', '=', $coupon_type_id ] ]);
if (!empty($coupon_info[ 'image' ])) { }
$upload_model = new Upload(); $cron = new Cron();
$upload_model->deletePic($coupon_info[ 'image' ], $coupon_info[ 'site_id' ]); $cron->deleteCron([ [ 'event', '=', 'CronCouponTypeEnd' ], [ 'relate_id', '=', $coupon_type_id ] ]);
}
return $this->success($res);
$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(); * @param $coupon_type_id
$cron->deleteCron([ [ 'event', '=', 'CronCouponTypeEnd' ], [ 'relate_id', '=', $coupon_type_id ] ]); * @param $site_id
* @return array
return $this->success($res); */
} 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)) {
* @param $coupon_type_id foreach ($res as $k => $v) {
* @param $site_id if ($v[ 'goods_type' ] == 2 || $v[ 'goods_type' ] == 3) {
* @return array $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');
public function getCouponTypeInfo($coupon_type_id, $site_id) $goods_list[ $k ] = model('goods')->getList([ [ 'goods_id', 'in', $goods_ids[ $k ] ] ], $field[ $k ]);
{ }
$res = model('promotion_coupon_type')->getList([ [ 'coupon_type_id', 'in', $coupon_type_id ], [ 'site_id', '=', $site_id ] ]); $res[ $k ][ 'goods_list' ] = $goods_list[$k] ?? [];
if (!empty($res)) { $res[ $k ][ 'goods_list_count' ] = count($res[ $k ][ 'goods_list' ]);
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'; return $this->success($res);
$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' ]); * @param array $where
} * @param bool $field
} * @param string $alias
return $this->success($res); * @param null $join
} * @param null $data
* @return array
/** */
* 获取优惠券活动信息 public function getInfo($where = [], $field = true, $alias = 'a', $join = null, $data = null)
* @param array $where {
* @param bool $field $res = model('promotion_coupon_type')->getInfo($where, $field, $alias, $join, $data);
* @param string $alias return $this->success($res);
* @param null $join }
* @param null $data
* @return array /**
*/ * 获取优惠券类型列表
public function getInfo($where = [], $field = true, $alias = 'a', $join = null, $data = null) * @param array $condition
{ * @param string $field
$res = model('promotion_coupon_type')->getInfo($where, $field, $alias, $join, $data); * @param string $order
return $this->success($res); * @param null $limit
} * @return array
*/
/** public function getCouponTypeList($condition = [], $field = '*', $order = 'create_time desc', $limit = null)
* 获取优惠券类型列表 {
* @param array $condition $res = model('promotion_coupon_type')->getList($condition, $field, $order, '', '', '', $limit);
* @param string $field return $this->success($res);
* @param string $order }
* @param null $limit
* @return array /**
*/ * 获取优惠券活动分页列表
public function getCouponTypeList($condition = [], $field = '*', $order = 'create_time desc', $limit = null) * @param array $condition
{ * @param int $page
$res = model('promotion_coupon_type')->getList($condition, $field, $order, '', '', '', $limit); * @param int $page_size
return $this->success($res); * @param string $order
} * @param string $field
* @return array
/** */
* 获取优惠券活动分页列表 public function getCouponTypePageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
* @param array $condition {
* @param int $page $condition[] = [ 'promotion_type', '=', 0 ];
* @param int $page_size $list = model('promotion_coupon_type')->pageList($condition, $field, $order, $page, $page_size);
* @param string $order return $this->success($list);
* @param string $field }
* @return array
*/ /**
public function getCouponTypePageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*') * 排序
{ * @param $coupon_type_id
$condition[] = [ 'promotion_type', '=', 0 ]; * @param $sort
$list = model('promotion_coupon_type')->pageList($condition, $field, $order, $page, $page_size); * @return array
return $this->success($list); */
} 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 $sort
* @return array /**
*/ * 生成优惠券二维码
public function couponSort($coupon_type_id, $sort) * @param $coupon_type_id
{ * @param string $app_type all为全部
$res = model('promotion_coupon_type')->update([ 'sort' => $sort ], [ [ 'coupon_type_id', '=', $coupon_type_id ] ]); * @param string $type 类型 create创建 get获取
return $this->success($res); * @return mixed|array
} */
public function qrcode($coupon_type_id, $app_type, $site_id, $type = 'create')
/** {
* 生成优惠券二维码 $res = event('Qrcode', [
* @param $coupon_type_id 'site_id' => $site_id,
* @param string $app_type all为全部 'app_type' => $app_type,
* @param string $type 类型 create创建 get获取 'type' => $type,
* @return mixed|array 'data' => [
*/ 'coupon_type_id' => $coupon_type_id
public function qrcode($coupon_type_id, $app_type, $site_id, $type = 'create') ],
{ 'page' => '/pages_tool/goods/coupon_receive',
$res = event('Qrcode', [ 'qrcode_path' => 'upload/qrcode/coupon',
'site_id' => $site_id, 'qrcode_name' => 'coupon_type_code_' . $coupon_type_id . '_' . $site_id,
'app_type' => $app_type, ], true);
'type' => $type, return $res;
'data' => [ }
'coupon_type_id' => $coupon_type_id
], /**
'page' => '/pages_tool/goods/coupon_receive', * 优惠券定时结束
'qrcode_path' => 'upload/qrcode/coupon', * @param $coupon_type_id
'qrcode_name' => 'coupon_type_code_' . $coupon_type_id . '_' . $site_id, * @return array
], true); */
return $res; public function couponCronEnd($coupon_type_id)
} {
$res = model('promotion_coupon_type')->update([ 'status' => 2 ], [ [ 'coupon_type_id', '=', $coupon_type_id ] ]);
/** return $this->success($res);
* 优惠券定时结束 }
* @param $coupon_type_id
* @return array public function spread($coupon_type_id, $name, $site_id, $type = 'create')
*/ {
public function couponCronEnd($coupon_type_id) $data = [
{ 'site_id' => $site_id,
$res = model('promotion_coupon_type')->update([ 'status' => 2 ], [ [ 'coupon_type_id', '=', $coupon_type_id ] ]); 'app_type' => 'all', // all为全部
return $this->success($res); 'type' => $type, // 类型 create创建 get获取
} 'data' => [
'coupon_type_id' => $coupon_type_id
public function spread($coupon_type_id, $name, $site_id, $type = 'create') ],
{ 'page' => '/pages_tool/goods/coupon_receive',
$data = [ 'qrcode_path' => 'upload/qrcode/coupon',
'site_id' => $site_id, 'qrcode_name' => 'coupon_type_code_' . $coupon_type_id . '_' . $site_id,
'app_type' => 'all', // all为全部 ];
'type' => $type, // 类型 create创建 get获取 event('Qrcode', $data, true);
'data' => [ $app_type_list = config('app_type');
'coupon_type_id' => $coupon_type_id $path = [];
], foreach ($app_type_list as $k => $v) {
'page' => '/pages_tool/goods/coupon_receive', switch ( $k ) {
'qrcode_path' => 'upload/qrcode/coupon', case 'h5':
'qrcode_name' => 'coupon_type_code_' . $coupon_type_id . '_' . $site_id, $wap_domain = getH5Domain();
]; $path[ $k ][ 'status' ] = 1;
event('Qrcode', $data, true); $path[ $k ][ 'url' ] = $wap_domain . $data[ 'page' ] . '?coupon_type_id=' . $coupon_type_id;
$app_type_list = config('app_type'); $path[ $k ][ 'img' ] = 'upload/qrcode/coupon/coupon_type_code_' . $coupon_type_id . '_' . $site_id . '_' . $k . '.png';
$path = []; break;
foreach ($app_type_list as $k => $v) { case 'weapp' :
switch ( $k ) { $config = new ConfigModel();
case 'h5': $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'WEAPP_CONFIG' ] ]);
$wap_domain = getH5Domain(); if (!empty($res[ 'data' ])) {
$path[ $k ][ 'status' ] = 1; if (empty($res[ 'data' ][ 'value' ][ 'qrcode' ])) {
$path[ $k ][ 'url' ] = $wap_domain . $data[ 'page' ] . '?coupon_type_id=' . $coupon_type_id; $path[ $k ][ 'status' ] = 2;
$path[ $k ][ 'img' ] = 'upload/qrcode/coupon/coupon_type_code_' . $coupon_type_id . '_' . $site_id . '_' . $k . '.png'; $path[ $k ][ 'message' ] = '未配置微信小程序';
break; } else {
case 'weapp' : $path[ $k ][ 'status' ] = 1;
$config = new ConfigModel(); $path[ $k ][ 'img' ] = $res[ 'data' ][ 'value' ][ 'qrcode' ];
$res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'WEAPP_CONFIG' ] ]); }
if (!empty($res[ 'data' ])) { } else {
if (empty($res[ 'data' ][ 'value' ][ 'qrcode' ])) { $path[ $k ][ 'status' ] = 2;
$path[ $k ][ 'status' ] = 2; $path[ $k ][ 'message' ] = '未配置微信小程序';
$path[ $k ][ 'message' ] = '未配置微信小程序'; }
} else { break;
$path[ $k ][ 'status' ] = 1;
$path[ $k ][ 'img' ] = $res[ 'data' ][ 'value' ][ 'qrcode' ]; case 'wechat' :
} $config = new ConfigModel();
} else { $res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'WECHAT_CONFIG' ] ]);
$path[ $k ][ 'status' ] = 2; if (!empty($res[ 'data' ])) {
$path[ $k ][ 'message' ] = '未配置微信小程序'; if (empty($res[ 'data' ][ 'value' ][ 'qrcode' ])) {
} $path[ $k ][ 'status' ] = 2;
break; $path[ $k ][ 'message' ] = '未配置微信公众号';
} else {
case 'wechat' : $path[ $k ][ 'status' ] = 1;
$config = new ConfigModel(); $path[ $k ][ 'img' ] = $res[ 'data' ][ 'value' ][ 'qrcode' ];
$res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'WECHAT_CONFIG' ] ]); }
if (!empty($res[ 'data' ])) { } else {
if (empty($res[ 'data' ][ 'value' ][ 'qrcode' ])) { $path[ $k ][ 'status' ] = 2;
$path[ $k ][ 'status' ] = 2; $path[ $k ][ 'message' ] = '未配置微信公众号';
$path[ $k ][ 'message' ] = '未配置微信公众号'; }
} else { break;
$path[ $k ][ 'status' ] = 1; }
$path[ $k ][ 'img' ] = $res[ 'data' ][ 'value' ][ 'qrcode' ];
} }
} else {
$path[ $k ][ 'status' ] = 2; $return = [
$path[ $k ][ 'message' ] = '未配置微信公众号'; 'path' => $path,
} 'name' => $name,
break; ];
}
return $this->success($return);
} }
$return = [ public function urlQrcode($page, $qrcode_param, $promotion_type, $app_type, $site_id)
'path' => $path, {
'name' => $name, $params = [
]; 'site_id' => $site_id,
'data' => $qrcode_param,
return $this->success($return); 'page' => $page,
} 'promotion_type' => $promotion_type,
'app_type' => $app_type,
public function urlQrcode($page, $qrcode_param, $promotion_type, $app_type, $site_id) 'h5_path' => $page . '?coupon_type_id=' . $qrcode_param[ 'coupon_type_id' ],
{ 'qrcode_path' => 'upload/qrcode/coupon',
$params = [ 'qrcode_name' => 'coupon_type_code_' . $promotion_type . '_' . $qrcode_param[ 'coupon_type_id' ] . '_' . $site_id,
'site_id' => $site_id, ];
'data' => $qrcode_param,
'page' => $page, $solitaire = event('PromotionQrcode', $params, true);
'promotion_type' => $promotion_type, return $this->success($solitaire);
'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 <?php
/**
namespace addon\coupon\model;
use addon\coupon\dict\CouponDict;
use app\model\BaseModel;
/**
*/ * 优惠券
*/
namespace addon\coupon\model; class MemberCoupon extends BaseModel
{
use addon\coupon\dict\CouponDict;
use app\model\BaseModel; /**
* 获取会员已领取优惠券
/** * @param $member_id
* 优惠券 * @param $state
*/ * @param int $site_id
class MemberCoupon extends BaseModel * @param string $order
{ * @return array
*/
/** public function getMemberCouponList($member_id, $state, $site_id = 0, $order = "fetch_time desc")
* 获取会员已领取优惠券 {
* @param $member_id $condition = array (
* @param $state [ "member_id", "=", $member_id ],
* @param int $site_id [ "state", "=", $state ],
* @param string $order );
* @return array if ($site_id > 0) {
*/ $condition[] = [ "site_id", "=", $site_id ];
public function getMemberCouponList($member_id, $state, $site_id = 0, $order = "fetch_time desc") }
{ $list = model("promotion_coupon")->getList($condition, "*", $order, '', '', '', 0);
$condition = array ( return $this->success($list);
[ "member_id", "=", $member_id ], }
[ "state", "=", $state ],
); /**
if ($site_id > 0) { * 使用优惠券
$condition[] = [ "site_id", "=", $site_id ]; * @param $coupon_id
} * @param $member_id
$list = model("promotion_coupon")->getList($condition, "*", $order, '', '', '', 0); * @param int $order_id
return $this->success($list); * @return array
} */
public function useMemberCoupon($coupon_id, $member_id, $order_id = 0)
/** {
* 使用优惠券 //优惠券处理方案
* @param $coupon_id $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 ] ]);
* @param $member_id if ($result === false) {
* @param int $order_id return $this->error();
* @return array }
*/ return $this->success();
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) { * @param $member_id
return $this->error(); * @param $state
} * @param int $site_id
return $this->success(); * @return array
} */
public function getMemberCouponNum($member_id, $state, $site_id = 0)
/** {
* 获取会员已领取优惠券数量 $condition = array (
* @param $member_id [ "member_id", "=", $member_id ],
* @param $state [ "state", "=", $state ],
* @param int $site_id );
* @return array if ($site_id > 0) {
*/ $condition[] = [ "site_id", "=", $site_id ];
public function getMemberCouponNum($member_id, $state, $site_id = 0) }
{ $num = model("promotion_coupon")->getCount($condition);
$condition = array ( return $this->success($num);
[ "member_id", "=", $member_id ], }
[ "state", "=", $state ],
); /**
if ($site_id > 0) { * 会员是否可领取该优惠券
$condition[] = [ "site_id", "=", $site_id ]; * @param $coupon_type_id
} * @param $member_id
$num = model("promotion_coupon")->getCount($condition); * @return array
return $this->success($num); */
} 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);
* @param $coupon_type_id }
* @param $member_id
* @return array /**
*/ * 获取编码
public function receivedNum($coupon_type_id, $member_id) */
{ public function getCode()
$received_num = model('promotion_coupon')->getCount([ [ 'coupon_type_id', '=', $coupon_type_id ], [ 'member_id', '=', $member_id ] ]); {
return $this->success($received_num); return random_keys(8);
} }
/** /**
* 获取编码 * 会员批量发放优惠券
*/ * @param $coupon_type_ids
public function getCode() * @param $site_id
{ * @param $member_id
return random_keys(8); * @param int $get_type
} * @param int $is_stock
* @param int $related_id
/** * @return array
* 会员批量发放优惠券 */
* @param $coupon_type_ids public function sendCoupon($coupon_type_ids, $site_id, $member_id, $get_type = 4, $is_stock = 0, $related_id = 0)
* @param $site_id {
* @param $member_id //已选优惠券提交数组
* @param int $get_type if (!empty($coupon_type_ids)) {
* @param int $is_stock $res = 0;
* @param int $related_id foreach ($coupon_type_ids as $coupon_type_id) {
* @return array $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)) {
public function sendCoupon($coupon_type_ids, $site_id, $member_id, $get_type = 4, $is_stock = 0, $related_id = 0)
{ if ($coupon_type_info[ 'count' ] != -1 || $is_stock == 0) {
//已选优惠券提交数组 if ($coupon_type_info[ 'count' ] == $coupon_type_info[ 'lead_count' ]) {
if (!empty($coupon_type_ids)) { return $this->error('', '来迟了该优惠券已被领取完了');
$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 ($coupon_type_info[ 'max_fetch' ] != 0 && $get_type == 2) {
if (!empty($coupon_type_info)) { //限制领取
$member_receive_num = model('promotion_coupon')->getCount([
if ($coupon_type_info[ 'count' ] != -1 || $is_stock == 0) { 'coupon_type_id' => $coupon_type_id,
if ($coupon_type_info[ 'count' ] == $coupon_type_info[ 'lead_count' ]) { 'member_id' => $member_id,
return $this->error('', '来迟了该优惠券已被领取完了'); 'get_type' => 2
} ]);
} if ($member_receive_num >= $coupon_type_info[ 'max_fetch' ] ) {
if ($coupon_type_info[ 'max_fetch' ] != 0 && $get_type == 2) { return $this->error('', '该优惠券领取已达到上限');
//限制领取 }
$member_receive_num = model('promotion_coupon')->getCount([ }
'coupon_type_id' => $coupon_type_id,
'member_id' => $member_id, $data = [
'get_type' => 2 'coupon_type_id' => $coupon_type_id,
]); 'site_id' => $site_id,
if ($member_receive_num >= $coupon_type_info[ 'max_fetch' ] ) { 'coupon_code' => $this->getCode(),
return $this->error('', '该优惠券领取已达到上限'); 'member_id' => $member_id,
} 'money' => $coupon_type_info[ 'money' ],
} 'state' => 1,
'get_type' => $get_type,
$data = [ 'goods_type' => $coupon_type_info[ 'goods_type' ],
'coupon_type_id' => $coupon_type_id, 'fetch_time' => time(),
'site_id' => $site_id, 'coupon_name' => $coupon_type_info[ 'coupon_name' ],
'coupon_code' => $this->getCode(), 'at_least' => $coupon_type_info[ 'at_least' ],
'member_id' => $member_id, 'type' => $coupon_type_info[ 'type' ],
'money' => $coupon_type_info[ 'money' ], 'discount' => $coupon_type_info[ 'discount' ],
'state' => 1, 'discount_limit' => $coupon_type_info[ 'discount_limit' ],
'get_type' => $get_type, 'goods_ids' => $coupon_type_info[ 'goods_ids' ],
'goods_type' => $coupon_type_info[ 'goods_type' ], 'related_id' => $related_id
'fetch_time' => time(), ];
'coupon_name' => $coupon_type_info[ 'coupon_name' ],
'at_least' => $coupon_type_info[ 'at_least' ], if ($coupon_type_info[ 'validity_type' ] == 0) {
'type' => $coupon_type_info[ 'type' ], $data[ 'end_time' ] = $coupon_type_info[ 'end_time' ];
'discount' => $coupon_type_info[ 'discount' ], } elseif ($coupon_type_info[ 'validity_type' ] == 1) {
'discount_limit' => $coupon_type_info[ 'discount_limit' ], $data[ 'end_time' ] = ( time() + $coupon_type_info[ 'fixed_term' ] * 86400 );
'goods_ids' => $coupon_type_info[ 'goods_ids' ], }
'related_id' => $related_id
]; $res = model('promotion_coupon')->add($data);
if ($is_stock == 0) {
if ($coupon_type_info[ 'validity_type' ] == 0) { model('promotion_coupon_type')->setInc([ [ 'coupon_type_id', '=', $coupon_type_id ] ], 'lead_count');
$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 ); }
} if ($res) {
return $this->success($res);
$res = model('promotion_coupon')->add($data); } else {
if ($is_stock == 0) { return $this->error();
model('promotion_coupon_type')->setInc([ [ 'coupon_type_id', '=', $coupon_type_id ] ], 'lead_count'); }
} } else {
} return $this->error();
} }
if ($res) { }
return $this->success($res);
} else { /**
return $this->error(); * 回收优惠券
} * @param array $coupon_list
} else { * @param $site_id
return $this->error(); * @return array
} */
} public function recoveryCoupon(array $coupon_list, $site_id)
{
/** $coupon = [];
* 回收优惠券 foreach ($coupon_list as $coupon_item) {
* @param array $coupon_list if (isset($coupon[ $coupon_item[ 'coupon_type_id' ] ])) {
* @param $site_id $coupon[$coupon_item['coupon_type_id']][] = $coupon_item['coupon_id'];
* @return array } else {
*/ $coupon[ $coupon_item[ 'coupon_type_id' ] ] = [ $coupon_item[ 'coupon_id' ] ];
public function recoveryCoupon(array $coupon_list, $site_id) }
{ }
$coupon = []; if (!count($coupon)) return $this->error();
foreach ($coupon_list as $coupon_item) {
if (isset($coupon[ $coupon_item[ 'coupon_type_id' ] ])) { model('promotion_coupon')->startTrans();
$coupon[$coupon_item['coupon_type_id']][] = $coupon_item['coupon_id']; try {
} else { foreach ($coupon as $coupon_type_id => $coupon_ids) {
$coupon[ $coupon_item[ 'coupon_type_id' ] ] = [ $coupon_item[ 'coupon_id' ] ]; $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);
} }
if (!count($coupon)) return $this->error(); model('promotion_coupon')->commit();
return $this->success();
model('promotion_coupon')->startTrans(); } catch (\Exception $e) {
try { model('promotion_coupon')->rollback();
foreach ($coupon as $coupon_type_id => $coupon_ids) { return $this->error('', '回收失败');
$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) { * @return void
model('promotion_coupon')->rollback(); */
return $this->error('', '回收失败'); 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],
* @return void ['coupon_type_id', 'in', $coupon_ids],
*/ ['state', '=', CouponDict::normal]
public function cancelByPromotion($data){ ], '*');
$member_id = $data['member_id']; $member_coupon_type_group_list = [];
$coupon_data = $data['coupon_data'];//优惠券id相关项 foreach($member_coupon_list as $v){
$coupon_ids = array_column($coupon_data, 'coupon_type_id'); $member_coupon_type_group_list[$v['coupon_type_id']][] = $v['coupon_id'];
$member_coupon_list = model('promotion_coupon')->getList([ }
['member_id', '=', $member_id], $cancel_ids = [];
['coupon_type_id', 'in', $coupon_ids], foreach ($coupon_data as $item) {
['state', '=', CouponDict::normal] $coupon_type_id = $item['coupon_type_id'];
], '*'); $num = $item['num'];
$member_coupon_type_group_list = []; $item_coupon_type_group = $member_coupon_type_group_list[$coupon_type_id] ?? [];
foreach($member_coupon_list as $v){ if($item_coupon_type_group){
$member_coupon_type_group_list[$v['coupon_type_id']][] = $v['coupon_id']; if(count($item_coupon_type_group) > $num){
} $cancel_ids = array_merge($cancel_ids, array_slice($item_coupon_type_group, 0, $num));
$cancel_ids = []; }else{
foreach ($coupon_data as $item) { $cancel_ids = array_merge($cancel_ids, $item_coupon_type_group);
$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){ model('promotion_coupon')->update(['state' => CouponDict::close], [['coupon_id', 'in', $cancel_ids]]);
if(count($item_coupon_type_group) > $num){ return $this->success();
$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 <?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;
/**
*/ * 分享
*/
namespace addon\coupon\model\share; class WchatShare extends BaseModel
{
use app\model\share\WchatShareBase as BaseModel; protected $config = [
use app\model\system\Config as ConfigModel; [
use app\model\system\Site as SiteModel; 'title' => '领券中心',
'config_key' => 'WCHAT_SHARE_CONFIG_COUPON_LIST',
/** 'path' => [ '/pages_tool/goods/coupon' ],
* 分享 'method_prefix' => 'couponList',
*/ ],
class WchatShare extends BaseModel ];
{
protected $config = [ /**
[ * 商品列表分享数据
'title' => '领券中心', * @param $param
'config_key' => 'WCHAT_SHARE_CONFIG_COUPON_LIST', * @return array
'path' => [ '/pages_tool/goods/coupon' ], */
'method_prefix' => 'couponList', protected function couponListShareData($param)
], {
]; $site_id = $param[ 'site_id' ] ?? 0;
/** //站点设置
* 商品列表分享数据 $site_model = new SiteModel();
* @param $param $site_info = $site_model->getSiteInfo([ [ 'site_id', '=', $site_id ] ])[ 'data' ];
* @return array
*/ //跳转路径
protected function couponListShareData($param) $link = $this->getShareLink($param);
{
$site_id = $param[ 'site_id' ] ?? 0; //获取和替换配置数据
$config_method = preg_replace('/Data$/', 'Config', __FUNCTION__);
//站点设置 $config_data = $this->$config_method($param);
$site_model = new SiteModel(); $title = $config_data[ 'value' ][ 'title' ];
$site_info = $site_model->getSiteInfo([ [ 'site_id', '=', $site_id ] ])[ 'data' ]; $desc = $config_data[ 'value' ][ 'desc' ];
$image_url = $config_data[ 'value' ][ 'imgUrl' ] ?: $site_info[ 'logo_square' ];
//跳转路径
$link = $this->getShareLink($param); $data = [
'title' => $title,
//获取和替换配置数据 'desc' => $desc,
$config_method = preg_replace('/Data$/', 'Config', __FUNCTION__); 'link' => $link,
$config_data = $this->$config_method($param); 'imgUrl' => $image_url,
$title = $config_data[ 'value' ][ 'title' ]; ];
$desc = $config_data[ 'value' ][ 'desc' ]; return [
$image_url = $config_data[ 'value' ][ 'imgUrl' ] ?: $site_info[ 'logo_square' ]; 'permission' => [
'hideOptionMenu' => false,
$data = [ 'hideMenuItems' => [],
'title' => $title, ],
'desc' => $desc, 'data' => $data,//分享内容
'link' => $link, ];
'imgUrl' => $image_url, }
];
return [ /**
'permission' => [ * 商品列表分享配置
'hideOptionMenu' => false, * @param $param
'hideMenuItems' => [], * @return array
], */
'data' => $data,//分享内容 protected function couponListShareConfig($param)
]; {
} $site_id = $param[ 'site_id' ];
$config = $param[ 'config' ];
/**
* 商品列表分享配置 $config_model = new ConfigModel();
* @param $param $data = $config_model->getConfig([
* @return array [ 'site_id', '=', $site_id ],
*/ [ 'app_module', '=', 'shop' ],
protected function couponListShareConfig($param) [ 'config_key', '=', $config[ 'config_key' ] ],
{ ])[ 'data' ];
$site_id = $param[ 'site_id' ]; if (empty($data[ 'value' ])) {
$config = $param[ 'config' ]; $data[ 'value' ] = [
'title' => '送你一张优惠券',
$config_model = new ConfigModel(); 'desc' => "优惠多多\n好物多多",
$data = $config_model->getConfig([ 'imgUrl' => '',
[ 'site_id', '=', $site_id ], ];
[ 'app_module', '=', 'shop' ], }
[ 'config_key', '=', $config[ 'config_key' ] ], if (empty($data[ 'value' ][ 'imgUrl' ])) {
])[ 'data' ]; $data[ 'value' ][ 'imgUrl' ] = img('addon/coupon/icon.png');
if (empty($data[ 'value' ])) { }
$data[ 'value' ] = [ $variable = [];
'title' => '送你一张优惠券',
'desc' => "优惠多多\n好物多多", return [
'imgUrl' => '', 'value' => $data[ 'value' ],
]; 'variable' => $variable,
} ];
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 <?php
/** namespace addon\coupon\model\share;
use app\model\share\WeappShareBase;
use app\model\system\Config as ConfigModel;
/**
* 分享
*/ */
class WeappShare extends WeappShareBase
namespace addon\coupon\model\share; {
protected $config = [
use app\model\share\WeappShareBase; [
use app\model\system\Config as ConfigModel; 'title' => '领券中心',
'config_key' => 'WEAPP_SHARE_CONFIG_COUPON_LIST',
/** 'path' => [ '/pages_tool/goods/coupon' ],
* 分享 'method_prefix' => 'couponList',
*/ ],
class WeappShare extends WeappShareBase ];
{
protected $config = [ protected $sort = 2;
[
'title' => '领券中心', /***************************** 领券中心 ***************************/
'config_key' => 'WEAPP_SHARE_CONFIG_COUPON_LIST',
'path' => [ '/pages_tool/goods/coupon' ], /**
'method_prefix' => 'couponList', * 首页分享数据
], * @param $param
]; * @return array
*/
protected $sort = 2; 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' ]) : '';
* @param $param $path = $this->getSharePath($param);
* @return array
*/ $data = [
protected function couponListShareData($param) 'title' => $title,
{ 'path' => $path,
//获取和替换配置数据 'imageUrl' => $image_url,
$config_data = $this->couponListShareConfig($param); ];
$title = $config_data[ 'value' ][ 'title' ]; return [
$image_url = $config_data[ 'value' ][ 'imageUrl' ] ? img($config_data[ 'value' ][ 'imageUrl' ]) : ''; 'permission' => [
$path = $this->getSharePath($param); 'onShareAppMessage' => true,
'onShareTimeline' => true,
$data = [ ],
'title' => $title, 'data' => $data,//分享内容
'path' => $path, ];
'imageUrl' => $image_url, }
];
return [ /**
'permission' => [ * 首页分享配置
'onShareAppMessage' => true, * @param $param
'onShareTimeline' => true, * @return array
], */
'data' => $data,//分享内容 protected function couponListShareConfig($param)
]; {
} $site_id = $param[ 'site_id' ];
$config = $param[ 'config' ];
/**
* 首页分享配置 $config_model = new ConfigModel();
* @param $param $data = $config_model->getConfig([
* @return array [ 'site_id', '=', $site_id ],
*/ [ 'app_module', '=', 'shop' ],
protected function couponListShareConfig($param) [ 'config_key', '=', $config[ 'config_key' ] ],
{ ])[ 'data' ];
$site_id = $param[ 'site_id' ]; if (empty($data[ 'value' ])) {
$config = $param[ 'config' ]; $data[ 'value' ] = [
'title' => '送你一张优惠券,快来领取吧',
$config_model = new ConfigModel(); 'imageUrl' => '',
$data = $config_model->getConfig([ ];
[ 'site_id', '=', $site_id ], }
[ 'app_module', '=', 'shop' ], $variable = [];
[ 'config_key', '=', $config[ 'config_key' ] ],
])[ 'data' ]; return [
if (empty($data[ 'value' ])) { 'value' => $data[ 'value' ],
$data[ 'value' ] = [ 'variable' => $variable,
'title' => '送你一张优惠券,快来领取吧', ];
'imageUrl' => '', }
]; }
}
$variable = [];
return [
'value' => $data[ 'value' ],
'variable' => $variable,
];
}
}

View File

@@ -1,110 +1,102 @@
<?php <?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;
*/
/**
namespace addon\coupon\shopapi\controller; * 优惠券
*/
use addon\coupon\model\Coupon as CouponModel; class Coupon extends BaseApi
use addon\coupon\model\CouponType as CouponTypeModel; {
use addon\coupon\model\MemberCoupon;
use app\shopapi\controller\BaseApi; public function __construct()
{
/** //执行父类构造函数
* 优惠券 parent::__construct();
*/
class Coupon extends BaseApi $token = $this->checkToken();
{ if ($token[ 'code' ] < 0) {
echo $this->response($token);
public function __construct() exit;
{ }
//执行父类构造函数 }
parent::__construct();
/**
$token = $this->checkToken(); * 活动列表
if ($token[ 'code' ] < 0) { */
echo $this->response($token); public function lists()
exit; {
} $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'] ?? '';
public function lists()
{ $condition = [];
$coupon_type_model = new CouponTypeModel(); if ($status !== '') {
$condition[] = [ 'status', '=', $status ];
$page = $this->params['page'] ?? 1; }
$page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS; $type = $this->params['type'] ?? '';
$coupon_name = $this->params['coupon_name'] ?? ''; if ($type) {
$status = $this->params['status'] ?? ''; $condition[] = [ 'type', '=', $type ];
}
$condition = []; //类型
if ($status !== '') { $validity_type = $this->params['validity_type'] ?? '';
$condition[] = [ 'status', '=', $status ]; if ($validity_type) {
} $start_time = $this->params['start_time'] ?? '';
$type = $this->params['type'] ?? ''; $end_time = $this->params['end_time'] ?? '';
if ($type) { switch ( $validity_type ) {
$condition[] = [ 'type', '=', $type ]; case 1: //固定
} $condition[] = [ 'end_time', 'between', [ $start_time, $end_time ] ];
//类型 break;
$validity_type = $this->params['validity_type'] ?? ''; case 2:
if ($validity_type) { $condition[] = [ 'fixed_term', 'between', [ $start_time, $end_time ] ];
$start_time = $this->params['start_time'] ?? ''; break;
$end_time = $this->params['end_time'] ?? ''; }
switch ( $validity_type ) { }
case 1: //固定
$condition[] = [ 'end_time', 'between', [ $start_time, $end_time ] ]; $condition[] = [ 'site_id', '=', $this->site_id ];
break; $condition[] = [ 'coupon_name', 'like', '%' . $coupon_name . '%' ];
case 2: $order = 'create_time desc';
$condition[] = [ 'fixed_term', 'between', [ $start_time, $end_time ] ]; $field = '*';
break;
} $res = $coupon_type_model->getCouponTypePageList($condition, $page, $page_size, $order, $field);
} //获取优惠券状态
$coupon_type_status_arr = $coupon_type_model->getCouponTypeStatus();
$condition[] = [ 'site_id', '=', $this->site_id ]; foreach ($res[ 'data' ][ 'list' ] as $key => $val) {
$condition[] = [ 'coupon_name', 'like', '%' . $coupon_name . '%' ]; $res[ 'data' ][ 'list' ][ $key ][ 'status_name' ] = $coupon_type_status_arr[ $val[ 'status' ] ];
$order = 'create_time desc'; }
$field = '*';
return $this->response($res);
$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' ] ]; */
} public function send()
{
return $this->response($res); $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)) {
public function send() return $this->error('', 'REQUEST_COUPON_TYPE_ID');
{ }
$member_id = $this->params['member_id'] ?? 0; $parent = explode(',', $parent);
$coupon_type_ids = $this->params['parent'] ?? ''; if (count($parent) == 1) {
$get_type = $this->params['get_type'] ?? 4; $coupon_model = new CouponModel();
$site_id = $this->site_id; $res = $coupon_model->receiveCoupon($parent[ 0 ], $site_id, $member_id, $get_type);
$parent = $coupon_type_ids; } else {
if (empty($parent)) { $member_coupon_model = new MemberCoupon();
return $this->error('', 'REQUEST_COUPON_TYPE_ID'); $res = $member_coupon_model->sendCoupon(explode(',', $coupon_type_ids), $site_id, $member_id, $get_type);
} }
$parent = explode(',', $parent); return $this->response($res);
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 <?php
/** return [
'name' => 'diy_default1',
'title' => '官方模板一',
'description' => '官方默认模板(一)',
'type' => 'system', //插件类型 system :系统插件(自动安装), business:业务插件 promotion:营销插件 tool:工具插件
'status' => 1,
'author' => '',
'version' => '5.3.1',
*/ 'version_no' => '525231212001',
return [ 'content' => '',
'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 <?php
/**
namespace addon\diy_default1\event;
/**
* 应用安装
*/
class Install
*/ {
/**
* 执行安装
namespace addon\diy_default1\event; */
public function handle()
/** {
* 应用安装 return success();
*/ }
class Install
{
/**
* 执行安装
*/
public function handle()
{
return success();
}
} }

View File

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

File diff suppressed because it is too large Load Diff

View File

@@ -1,21 +1,12 @@
<?php <?php
/** return [
'name' => 'diy_default2',
'title' => '官方模板二',
'description' => '官方默认模板(二)',
'type' => 'system', //插件类型 system :系统插件(自动安装), business:业务插件 promotion:营销插件 tool:工具插件
'status' => 1,
'author' => '',
'version' => '5.3.1',
*/ 'version_no' => '525231212001',
return [ 'content' => '',
'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 <?php
/**
namespace addon\diy_default2\event;
/**
* 应用安装
*/
class Install
*/ {
/**
* 执行安装
namespace addon\diy_default2\event; */
public function handle()
/** {
* 应用安装 return success();
*/ }
class Install
{
/**
* 执行安装
*/
public function handle()
{
return success();
}
} }

View File

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

View File

@@ -1,38 +1,30 @@
<?php <?php
/** return [
// 自定义模板页面类型,格式:[ 'title' => '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据json格式' ]
'template' => [],
// 后台自定义组件——装修
'util' => [],
*/
return [ // 自定义页面路径
'link' => [],
// 自定义模板页面类型,格式:[ 'title' => '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据json格式' ]
'template' => [], // 自定义图标库
'icon_library' => [],
// 后台自定义组件——装修
'util' => [], // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ]多个逗号隔开自定义组件名称前缀必须是diy-,也可以引用第三方组件
'component' => [],
// 自定义页面路径
'link' => [], // uni-app 页面,多个逗号隔开
'pages' => [],
// 自定义图标库
'icon_library' => [], // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
'info' => [],
// uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ]多个逗号隔开自定义组件名称前缀必须是diy-,也可以引用第三方组件
'component' => [], // 主题风格配色格式可以自由定义扩展【在uni-app中通过this.themeStyle... 获取定义的颜色字段例如this.themeStyle.main_color】
'theme' => [],
// uni-app 页面,多个逗号隔开
'pages' => [], // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据json格式] ]
'data' => []
// 模板信息,格式:'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 <?php
/** return [
'name' => 'electronicsheet',
'title' => '电子面单',
'description' => '电子面单',
'type' => 'tool', //插件类型 system :系统插件(自动安装), promotion:扩展营销插件 tool:工具插件
'status' => 1,
'author' => '',
*/ 'version' => '5.3.1',
return [ 'version_no' => '525231212001',
'name' => 'electronicsheet', 'content' => '',
'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 <?php
/**
namespace addon\electronicsheet\event;
/**
* 应用安装
*/
class Install
*/ {
/**
namespace addon\electronicsheet\event; * 执行安装
*/
/** public function handle()
* 应用安装 {
*/ return success();
class Install }
{
/**
* 执行安装
*/
public function handle()
{
return success();
}
} }

View File

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

View File

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

View File

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

View File

@@ -1,172 +1,164 @@
<?php <?php
/**
namespace addon\electronicsheet\model;
use app\model\BaseModel;
use app\model\shop\Shop;
use extend\Kdniao;
use app\model\system\Address;
*/
/**
namespace addon\electronicsheet\model; * 电子面单物流配送
*/
use app\model\BaseModel; class ElectronicsheetDelivery extends BaseModel
use app\model\shop\Shop; {
use extend\Kdniao;
use app\model\system\Address; /**
* 电子面单发货
/** * @param $param
* 电子面单物流配送 * @param $is_delivery
*/ * @return array
class ElectronicsheetDelivery extends BaseModel */
{ public function delivery($param)
{
/** //获取电子面单设置
* 电子面单发货 $electronicsheet_model = new ExpressElectronicsheet();
* @param $param $config_info = $electronicsheet_model->getElectronicsheetConfig($param[ 'site_id' ])[ 'data' ][ 'value' ];
* @param $is_delivery if (empty($config_info)) {
* @return array return $this->error('', '请先配置电子面单');
*/ }
public function delivery($param)
{ if (empty($param[ 'template_id' ])) {
//获取电子面单设置 return $this->error('', '请先配置电子面单模板');
$electronicsheet_model = new ExpressElectronicsheet(); }
$config_info = $electronicsheet_model->getElectronicsheetConfig($param[ 'site_id' ])[ 'data' ][ 'value' ]; //获取电子模板信息
if (empty($config_info)) { $template = $electronicsheet_model->getExpressElectronicsheetInfo([ [ 'id', '=', $param[ 'template_id' ] ] ])[ 'data' ];
return $this->error('', '请先配置电子面单'); if (empty($template)) {
} return $this->error('', '电子面单模板不存在');
}
if (empty($param[ 'template_id' ])) {
return $this->error('', '请先配置电子面单模板'); //获取店铺信息
} $shop_model = new Shop();
//获取电子模板信息 $shop_info = $shop_model->getShopInfo([ [ 'site_id', '=', $param[ 'site_id' ] ] ])[ 'data' ];
$template = $electronicsheet_model->getExpressElectronicsheetInfo([ [ 'id', '=', $param[ 'template_id' ] ] ])[ 'data' ];
if (empty($template)) { if (empty($shop_info[ 'name' ])) {
return $this->error('', '电子面单模板不存在'); 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('', '店铺联系地址中联系地址未设置');
$shop_model = new Shop(); }
$shop_info = $shop_model->getShopInfo([ [ 'site_id', '=', $param[ 'site_id' ] ] ])[ 'data' ]; if (empty($shop_info[ 'telephone' ]) && empty($shop_info[ 'mobile' ])) {
return $this->error('', '店铺联系地址中联系方式未设置');
if (empty($shop_info[ 'name' ])) { }
return $this->error('', '店铺联系地址中联系人姓名未设置');
} $result = $this->electronicsheetDelivery($param, $config_info, $template, $shop_info);
if (empty($shop_info[ 'province_name' ]) || empty($shop_info[ 'city_name' ]) || empty($shop_info[ 'district_name' ]) || empty($shop_info[ 'address' ])) { if (isset($result[ 'code' ]) && $result[ 'code' ] < 0) {
return $this->error('', '店铺联系地址中联系地址未设置'); return $result;
} } else {
if (empty($shop_info[ 'telephone' ]) && empty($shop_info[ 'mobile' ])) { return $this->success($result);
return $this->error('', '店铺联系地址中联系方式未设置'); }
} }
$result = $this->electronicsheetDelivery($param, $config_info, $template, $shop_info); /**
if (isset($result[ 'code' ]) && $result[ 'code' ] < 0) { * 电子面单发货
return $result; * @param $delivery_id //包裹id
} else { * @param $config_info //快递鸟配置信息
return $this->success($result); * @param $template //电子面单模板
} * @param $shop_info //发货人信息
} * @param $goods_array //商品信息
* @return array
/** */
* 电子面单发货 public function electronicsheetDelivery($param, $config_info, $template, $shop_info)
* @param $delivery_id //包裹id {
* @param $config_info //快递鸟配置信息 //获取订单信息
* @param $template //电子面单模板 $order_info = model('order')->getInfo([ [ 'order_id', '=', $param[ 'order_id' ] ] ]);
* @param $shop_info //发货人信息 //获取快递公司编码
* @param $goods_array //商品信息 $express_company = model('express_company_template')->getInfo([ [ 'company_id', '=', $template[ 'company_id' ] ] ], 'express_no,print_style');
* @return array $print_style = json_decode($express_company[ 'print_style' ], true);
*/
public function electronicsheetDelivery($param, $config_info, $template, $shop_info) $goods_commodity = [];
{ //获取商品信息
//获取订单信息 if (empty($param[ 'order_goods_id_array' ])) {
$order_info = model('order')->getInfo([ [ 'order_id', '=', $param[ 'order_id' ] ] ]); $goods_array = model('order_goods')->getList(
//获取快递公司编码 [
$express_company = model('express_company_template')->getInfo([ [ 'company_id', '=', $template[ 'company_id' ] ] ], 'express_no,print_style'); [ 'order_id', '=', $param[ 'order_id' ] ]
$print_style = json_decode($express_company[ 'print_style' ], true); ], 'sku_name as GoodsName,num as GoodsQuantity'
);
$goods_commodity = []; } else {
//获取商品信息 $goods_array = model('order_goods')->getList(
if (empty($param[ 'order_goods_id_array' ])) { [
$goods_array = model('order_goods')->getList( [ 'order_goods_id', 'in', $param[ 'order_goods_id_array' ] ],
[ [ 'order_id', '=', $param[ 'order_id' ] ]
[ 'order_id', '=', $param[ 'order_id' ] ] ], 'sku_name as GoodsName,num as GoodsQuantity'
], 'sku_name as GoodsName,num as GoodsQuantity' );
); }
} else { //替换商品名称中的特殊字符 ' " # & + < > % \
$goods_array = model('order_goods')->getList( $search = array ( "'", '"', '&', '+', '<', '>', '%', "\\", '#', "and" );
[ foreach ($goods_array as $key => $val){
[ 'order_goods_id', 'in', $param[ 'order_goods_id_array' ] ], $goods_commodity[] = [
[ 'order_id', '=', $param[ 'order_id' ] ] 'GoodsName' => str_replace($search, '', $val[ 'GoodsName' ]),
], 'sku_name as GoodsName,num as GoodsQuantity' 'GoodsQuantity' => $val['GoodsQuantity']
); ];
} }
//替换商品名称中的特殊字符 ' " # & + < > % \
$search = array ( "'", '"', '&', '+', '<', '>', '%', "\\", '#', "and" ); //实例化快递鸟
foreach ($goods_array as $key => $val){ $config = [
$goods_commodity[] = [ 'EBusinessID' => $config_info[ 'kdniao_user_id' ],
'GoodsName' => str_replace($search, '', $val[ 'GoodsName' ]), 'AppKey' => $config_info[ 'kdniao_api_key' ]
'GoodsQuantity' => $val['GoodsQuantity'] ];
]; $kdniao = new Kdniao($config);
} //构造电子面单提交信息
$eorder = [];
//实例化快递鸟 $eorder[ 'CustomerName' ] = $template[ 'customer_name' ];
$config = [ $eorder[ 'CustomerPwd' ] = $template[ 'customer_pwd' ];
'EBusinessID' => $config_info[ 'kdniao_user_id' ], $eorder[ 'SendSite' ] = $template[ 'send_site' ];
'AppKey' => $config_info[ 'kdniao_api_key' ] $eorder[ 'SendStaff' ] = $template[ 'send_staff' ];
]; $eorder[ 'MonthCode' ] = $template[ 'month_code' ];
$kdniao = new Kdniao($config); $eorder[ 'ShipperCode' ] = $express_company[ 'express_no' ];//快递公司编码
//构造电子面单提交信息 $eorder[ 'OrderCode' ] = $order_info[ 'order_no' ];//订单号
$eorder = []; $eorder[ 'PayType' ] = $template[ 'postage_payment_method' ]; //邮费支付方式
$eorder[ 'CustomerName' ] = $template[ 'customer_name' ]; $eorder[ 'ExpType' ] = 1; //快递类型
$eorder[ 'CustomerPwd' ] = $template[ 'customer_pwd' ]; $eorder[ 'TemplateSize' ] = $print_style[ $template[ 'print_style' ] ][ 'template_size' ]; //模板规格
$eorder[ 'SendSite' ] = $template[ 'send_site' ]; //发货人信息
$eorder[ 'SendStaff' ] = $template[ 'send_staff' ]; $sender = [];
$eorder[ 'MonthCode' ] = $template[ 'month_code' ]; $sender[ 'Name' ] = $shop_info[ 'name' ];
$eorder[ 'ShipperCode' ] = $express_company[ 'express_no' ];//快递公司编码 $sender[ 'Mobile' ] = $shop_info[ 'mobile' ];
$eorder[ 'OrderCode' ] = $order_info[ 'order_no' ];//订单号 $sender[ 'Tel' ] = $shop_info[ 'telephone' ];
$eorder[ 'PayType' ] = $template[ 'postage_payment_method' ]; //邮费支付方式 $sender[ 'ProvinceName' ] = $shop_info[ 'province_name' ];
$eorder[ 'ExpType' ] = 1; //快递类型 $sender[ 'CityName' ] = $shop_info[ 'city_name' ];
$eorder[ 'TemplateSize' ] = $print_style[ $template[ 'print_style' ] ][ 'template_size' ]; //模板规格 $sender[ 'ExpAreaName' ] = $shop_info[ 'district_name' ];
//发货人信息 $sender[ 'Address' ] = $shop_info[ 'address' ];
$sender = []; $sender[ 'PostCode' ] = '000000';
$sender[ 'Name' ] = $shop_info[ 'name' ]; //获取收货人信息
$sender[ 'Mobile' ] = $shop_info[ 'mobile' ]; $area_model = new Address();
$sender[ 'Tel' ] = $shop_info[ 'telephone' ]; $province_name = $area_model->getAreasInfo([ [ 'id', '=', $order_info[ 'province_id' ] ] ], 'name');
$sender[ 'ProvinceName' ] = $shop_info[ 'province_name' ]; $city_name = $area_model->getAreasInfo([ [ 'id', '=', $order_info[ 'city_id' ] ] ], 'name');
$sender[ 'CityName' ] = $shop_info[ 'city_name' ]; $district_name = $area_model->getAreasInfo([ [ 'id', '=', $order_info[ 'district_id' ] ] ], 'name');
$sender[ 'ExpAreaName' ] = $shop_info[ 'district_name' ]; $receiver = [];
$sender[ 'Address' ] = $shop_info[ 'address' ]; $receiver[ 'Name' ] = $order_info[ 'name' ];
$sender[ 'PostCode' ] = '000000'; $receiver[ 'Mobile' ] = $order_info[ 'mobile' ];
//获取收货人信息 $receiver[ 'ProvinceName' ] = $province_name[ 'data' ][ 'name' ];
$area_model = new Address(); $receiver[ 'CityName' ] = $city_name[ 'data' ][ 'name' ];
$province_name = $area_model->getAreasInfo([ [ 'id', '=', $order_info[ 'province_id' ] ] ], 'name'); $receiver[ 'ExpAreaName' ] = empty($district_name[ 'data' ][ 'name' ]) ? '' : $district_name[ 'data' ][ 'name' ];
$city_name = $area_model->getAreasInfo([ [ 'id', '=', $order_info[ 'city_id' ] ] ], 'name'); $receiver[ 'Address' ] = $order_info[ 'address' ];
$district_name = $area_model->getAreasInfo([ [ 'id', '=', $order_info[ 'district_id' ] ] ], 'name'); $receiver[ 'PostCode' ] = '000000';
$receiver = [];
$receiver[ 'Name' ] = $order_info[ 'name' ]; // $commodity[] = $goods_array;
$receiver[ 'Mobile' ] = $order_info[ 'mobile' ]; $eorder[ 'Sender' ] = $sender;
$receiver[ 'ProvinceName' ] = $province_name[ 'data' ][ 'name' ]; $eorder[ 'Receiver' ] = $receiver;
$receiver[ 'CityName' ] = $city_name[ 'data' ][ 'name' ]; $eorder[ 'Commodity' ] = $goods_commodity; //商品信息
$receiver[ 'ExpAreaName' ] = empty($district_name[ 'data' ][ 'name' ]) ? '' : $district_name[ 'data' ][ 'name' ];
$receiver[ 'Address' ] = $order_info[ 'address' ]; $eorder[ 'IsReturnPrintTemplate' ] = 1; //是否返回电子模板
$receiver[ 'PostCode' ] = '000000';
$jsonResult = $kdniao->submitEOrder($eorder);
// $commodity[] = $goods_array;
$eorder[ 'Sender' ] = $sender; $result = json_decode($jsonResult, true);
$eorder[ 'Receiver' ] = $receiver; if (isset($result[ 'ResultCode' ])) {
$eorder[ 'Commodity' ] = $goods_commodity; //商品信息 if ($result[ 'ResultCode' ] == '100' || $result[ 'ResultCode' ] == '106') {
return $result;
$eorder[ 'IsReturnPrintTemplate' ] = 1; //是否返回电子模板 }
}
$jsonResult = $kdniao->submitEOrder($eorder); return $this->error('', $result[ 'Reason' ]);
}
$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 <?php
/**
namespace addon\electronicsheet\model;
use app\model\express\ExpressCompanyTemplate;
use app\model\system\Config;
use app\model\BaseModel;
*/ class ExpressElectronicsheet extends BaseModel
{
namespace addon\electronicsheet\model;
/************************************ 电子面单设置 start **********************************************************/
use app\model\express\ExpressCompanyTemplate; /**
use app\model\system\Config; * 电子面单设置
use app\model\BaseModel; * @param $data
* @return array
class ExpressElectronicsheet extends BaseModel */
{ public function setElectronicsheetConfig($data)
{
/************************************ 电子面单设置 start **********************************************************/ $config = new Config();
/** $res = $config->setConfig($data, '电子面单设置', 1, [ [ 'site_id', '=', $data[ 'site_id' ] ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'ELECTRONICSHEET_CONFIG' ] ]);
* 电子面单设置 return $this->success($res);
* @param $data }
* @return array
*/ /**
public function setElectronicsheetConfig($data) * 获取电子面单设置
{ * @return array
$config = new Config(); */
$res = $config->setConfig($data, '电子面单设置', 1, [ [ 'site_id', '=', $data[ 'site_id' ] ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'ELECTRONICSHEET_CONFIG' ] ]); public function getElectronicsheetConfig($site_id)
return $this->success($res); {
} $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' ] = [
* @return array 'type' => 'kdniao',
*/
public function getElectronicsheetConfig($site_id) 'kdniao_user_id' => '',
{ 'kdniao_api_key' => '',
$config = new Config(); 'kdniao_port' => '',
$res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'ELECTRONICSHEET_CONFIG' ] ]);
if (empty($res[ 'data' ][ 'value' ])) { 'cainiao_token' => '',
$res[ 'data' ][ 'value' ] = [ 'cainiao_ip' => ''
'type' => 'kdniao', ];
}
'kdniao_user_id' => '', return $res;
'kdniao_api_key' => '', }
'kdniao_port' => '',
/************************************ 电子面单设置 end **********************************************************/
'cainiao_token' => '',
'cainiao_ip' => '' /**
]; * 添加电子面单
} * @param $data
return $res; * @return array
} */
public function addExpressElectronicsheet($data)
/************************************ 电子面单设置 end **********************************************************/ {
//判断模板名称是否重复
/** $count = model('express_electronicsheet')->getCount(
* 添加电子面单 [
* @param $data [ 'site_id', '=', $data[ 'site_id' ] ],
* @return array [ 'template_name', '=', $data[ 'template_name' ] ]
*/ ]);
public function addExpressElectronicsheet($data)
{ if ($count > 0) {
//判断模板名称是否重复 return $this->error('', '该电子面单名称已存在');
$count = model('express_electronicsheet')->getCount( }
[ $express_company_model = new ExpressCompanyTemplate();
[ 'site_id', '=', $data[ 'site_id' ] ], $express_company_info = $express_company_model->getExpressCompanyTemplateInfo([ [ 'company_id', '=', $data[ 'company_id' ] ] ], 'company_id,company_name,express_no');
[ 'template_name', '=', $data[ 'template_name' ] ] if (empty($express_company_info)) {
]); return $this->error('', '快递公司不存在');
}
if ($count > 0) { if (empty($express_company_info[ 'data' ][ 'express_no' ]) || empty($express_company_info[ 'data' ][ 'company_name' ])) {
return $this->error('', '该电子面单名称已存在'); 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'); $data[ 'express_no' ] = $express_company_info[ 'data' ][ 'express_no' ];
if (empty($express_company_info)) { $data[ 'company_name' ] = $express_company_info[ 'data' ][ 'company_name' ];
return $this->error('', '快递公司不存在'); $data[ 'create_time' ] = time();
}
if (empty($express_company_info[ 'data' ][ 'express_no' ]) || empty($express_company_info[ 'data' ][ 'company_name' ])) { model('express_electronicsheet')->startTrans();
return $this->error('', '快递公司名称或者快递鸟编码为空'); try {
}
if ($data[ 'is_default' ] == 1) {
$data[ 'express_no' ] = $express_company_info[ 'data' ][ 'express_no' ]; $this->setExpressElectronicsheetDefault([ [ 'site_id', '=', $data[ 'site_id' ] ], [ 'is_default', '=', 1 ] ], 0);
$data[ 'company_name' ] = $express_company_info[ 'data' ][ 'company_name' ]; }
$data[ 'create_time' ] = time(); model('express_electronicsheet')->add($data);
model('express_electronicsheet')->startTrans(); model('express_electronicsheet')->commit();
try { return $this->success();
} catch (\Exception $e) {
if ($data[ 'is_default' ] == 1) { model('express_electronicsheet')->rollback();
$this->setExpressElectronicsheetDefault([ [ 'site_id', '=', $data[ 'site_id' ] ], [ 'is_default', '=', 1 ] ], 0); return $this->error('', $e->getMessage());
} }
model('express_electronicsheet')->add($data); }
model('express_electronicsheet')->commit(); /**
return $this->success(); * 编辑电子面单
} catch (\Exception $e) { * @param $data
model('express_electronicsheet')->rollback(); * @return array
return $this->error('', $e->getMessage()); */
} public function editExpressElectronicsheet($data)
} {
//判断模板名称是否重复
/** $count = model('express_electronicsheet')->getCount(
* 编辑电子面单 [
* @param $data [ 'site_id', '=', $data[ 'site_id' ] ],
* @return array [ 'id', '<>', $data[ 'id' ] ],
*/ [ 'template_name', '=', $data[ 'template_name' ] ]
public function editExpressElectronicsheet($data) ]);
{ if ($count > 0) {
//判断模板名称是否重复 return $this->error('', '该电子面单名称已存在');
$count = model('express_electronicsheet')->getCount( }
[
[ 'site_id', '=', $data[ 'site_id' ] ], $express_company_model = new ExpressCompanyTemplate();
[ 'id', '<>', $data[ 'id' ] ], $express_company_info = $express_company_model->getExpressCompanyTemplateInfo([ [ 'company_id', '=', $data[ 'company_id' ] ] ], 'company_id,company_name,express_no');
[ 'template_name', '=', $data[ 'template_name' ] ] if (empty($express_company_info)) {
]); return $this->error('', '快递公司不存在');
if ($count > 0) { }
return $this->error('', '该电子面单名称已存在'); if (empty($express_company_info[ 'data' ][ 'express_no' ]) || empty($express_company_info[ 'data' ][ 'company_name' ])) {
} return $this->error('', '快递公司名称或者快递鸟编码为空');
}
$express_company_model = new ExpressCompanyTemplate(); $data[ 'express_no' ] = $express_company_info[ 'data' ][ 'express_no' ];
$express_company_info = $express_company_model->getExpressCompanyTemplateInfo([ [ 'company_id', '=', $data[ 'company_id' ] ] ], 'company_id,company_name,express_no'); $data[ 'company_name' ] = $express_company_info[ 'data' ][ 'company_name' ];
if (empty($express_company_info)) { $data[ 'update_time' ] = time();
return $this->error('', '快递公司不存在');
} model('express_electronicsheet')->startTrans();
if (empty($express_company_info[ 'data' ][ 'express_no' ]) || empty($express_company_info[ 'data' ][ 'company_name' ])) { try {
return $this->error('', '快递公司名称或者快递鸟编码为空');
} if ($data[ 'is_default' ] == 1) {
$data[ 'express_no' ] = $express_company_info[ 'data' ][ 'express_no' ]; $this->setExpressElectronicsheetDefault([ [ 'site_id', '=', $data[ 'site_id' ] ], [ 'id', '<>', $data[ 'id' ] ], [ 'is_default', '=', 1 ] ], 0);
$data[ 'company_name' ] = $express_company_info[ 'data' ][ 'company_name' ]; }
$data[ 'update_time' ] = time(); model('express_electronicsheet')->update($data, [ [ 'id', '=', $data[ 'id' ] ], [ 'site_id', '=', $data[ 'site_id' ] ] ]);
model('express_electronicsheet')->startTrans(); model('express_electronicsheet')->commit();
try { return $this->success();
} catch (\Exception $e) {
if ($data[ 'is_default' ] == 1) {
$this->setExpressElectronicsheetDefault([ [ 'site_id', '=', $data[ 'site_id' ] ], [ 'id', '<>', $data[ 'id' ] ], [ 'is_default', '=', 1 ] ], 0); model('express_electronicsheet')->rollback();
} return $this->error('', $e->getMessage());
model('express_electronicsheet')->update($data, [ [ 'id', '=', $data[ 'id' ] ], [ 'site_id', '=', $data[ 'site_id' ] ] ]); }
}
model('express_electronicsheet')->commit();
return $this->success(); /**
} catch (\Exception $e) { * 设置默认状态
* @param $condition
model('express_electronicsheet')->rollback(); * @param $is_default
return $this->error('', $e->getMessage()); * @return array
} */
} public function setExpressElectronicsheetDefault($condition, $is_default)
{
/** $res = model('express_electronicsheet')->update([ 'is_default' => $is_default ], $condition);
* 设置默认状态 return $this->success($res);
* @param $condition }
* @param $is_default
* @return array /**
*/ * 删除
public function setExpressElectronicsheetDefault($condition, $is_default) * @param $condition
{ * @return array
$res = model('express_electronicsheet')->update([ 'is_default' => $is_default ], $condition); */
return $this->success($res); public function deleteExpressElectronicsheet($condition)
} {
$res = model('express_electronicsheet')->delete($condition);
/** return $this->success($res);
* 删除 }
* @param $condition
* @return array /**
*/ * 获取电子面单信息
public function deleteExpressElectronicsheet($condition) * @param array $condition
{ * @param string $field
$res = model('express_electronicsheet')->delete($condition); * @return array
return $this->success($res); */
} public function getExpressElectronicsheetInfo($condition = [], $field = '*')
{
/** $res = model('express_electronicsheet')->getInfo($condition, $field);
* 获取电子面单信息 return $this->success($res);
* @param array $condition }
* @param string $field
* @return array /**
*/ * 获取电子面单列表
public function getExpressElectronicsheetInfo($condition = [], $field = '*') * @param array $condition
{ * @param string $field
$res = model('express_electronicsheet')->getInfo($condition, $field); * @param string $order
return $this->success($res); * @param string $limit
} */
public function getExpressElectronicsheetList($condition = [], $field = '*', $order = '', $limit = null)
/** {
* 获取电子面单列表 $list = model('express_electronicsheet')->getList($condition, $field, $order, '', '', '', $limit);
* @param array $condition return $this->success($list);
* @param string $field }
* @param string $order
* @param string $limit /**
*/ * 获取电子面单分页列表
public function getExpressElectronicsheetList($condition = [], $field = '*', $order = '', $limit = null) * @param array $condition
{ * @param number $page
$list = model('express_electronicsheet')->getList($condition, $field, $order, '', '', '', $limit); * @param string $page_size
return $this->success($list); * @param string $order
} * @param string $field
*/
/** public function getExpressElectronicsheetPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
* 获取电子面单分页列表 {
* @param array $condition $list = model('express_electronicsheet')->pageList($condition, $field, $order, $page, $page_size);
* @param number $page return $this->success($list);
* @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 <?php
/**
namespace addon\electronicsheet\shop\controller;
use app\shop\controller\BaseShop;
use addon\electronicsheet\model\ExpressElectronicsheet as ExpressElectronicsheetModel;
*/ class Config extends BaseShop
{
namespace addon\electronicsheet\shop\controller;
/*
use app\shop\controller\BaseShop; * 电子面单设置
use addon\electronicsheet\model\ExpressElectronicsheet as ExpressElectronicsheetModel; */
public function config()
{
class Config extends BaseShop $config = new ExpressElectronicsheetModel();
{ if (request()->isJson()) {
/* $data = [
* 电子面单设置 'site_id' => $this->site_id,
*/ 'type' => input('type', 'kdniao'),
public function config() 'kdniao_user_id' => input('kdniao_user_id', ''),
{ 'kdniao_api_key' => input('kdniao_api_key', ''),
$config = new ExpressElectronicsheetModel(); 'kdniao_port' => input('kdniao_port', ''),
if (request()->isJson()) { 'cainiao_token' => input('cainiao_token', ''),
'cainiao_ip' => input('cainiao_ip', ''),
$data = [ ];
'site_id' => $this->site_id,
'type' => input('type', 'kdniao'), return $config->setElectronicsheetConfig($data);
'kdniao_user_id' => input('kdniao_user_id', ''), } else {
'kdniao_api_key' => input('kdniao_api_key', ''),
'kdniao_port' => input('kdniao_port', ''), $res = $config->getElectronicsheetConfig($this->site_id);
'cainiao_token' => input('cainiao_token', ''), $this->assign('config_info', $res[ 'data' ][ 'value' ]);
'cainiao_ip' => input('cainiao_ip', ''), return $this->fetch('config/config');
]; }
}
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 <?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
{
namespace addon\electronicsheet\shop\controller;
/*
use app\model\express\ExpressCompanyTemplate; * 电子面单列表
use app\shop\controller\BaseShop; */
use addon\electronicsheet\model\ExpressElectronicsheet as ExpressElectronicsheetModel; public function lists()
{
class Electronicsheet extends BaseShop $model = new ExpressElectronicsheetModel();
{
$condition[] = [ 'site_id', '=', $this->site_id ];
/* //获取续签信息
* 电子面单列表 if (request()->isJson()) {
*/ $status = input('status', '');//模板状态
public function lists() if ($status) {
{ $condition[] = [ 'status', '=', $status ];
$model = new ExpressElectronicsheetModel(); }
$template_name = input('template_name', '');
$condition[] = [ 'site_id', '=', $this->site_id ]; if ($template_name) {
//获取续签信息 $condition[] = [ 'template_name', 'like', '%' . $template_name . '%' ];
if (request()->isJson()) { }
$status = input('status', '');//模板状态
if ($status) { $page = input('page', 1);
$condition[] = [ 'status', '=', $status ]; $page_size = input('page_size', PAGE_LIST_ROWS);
} $list = $model->getExpressElectronicsheetPageList($condition, $page, $page_size, 'is_default desc');
$template_name = input('template_name', ''); return $list;
if ($template_name) { }
$condition[] = [ 'template_name', 'like', '%' . $template_name . '%' ]; return $this->fetch('electronicsheet/lists');
} }
$page = input('page', 1); /**
$page_size = input('page_size', PAGE_LIST_ROWS); * 添加电子面单
$list = $model->getExpressElectronicsheetPageList($condition, $page, $page_size, 'is_default desc'); */
return $list; public function add()
} {
return $this->fetch('electronicsheet/lists'); if (request()->isJson()) {
} $data = [
'site_id' => $this->site_id,
/** 'template_name' => input('template_name', ''),
* 添加电子面单 'company_id' => input('company_id', ''),
*/ 'customer_name' => input('customer_name', ''),
public function add() 'customer_pwd' => input('customer_pwd', ''),
{ 'send_site' => input('send_site', ''),
if (request()->isJson()) { 'send_staff' => input('send_staff', ''),
$data = [ 'month_code' => input('month_code', ''),
'site_id' => $this->site_id, 'postage_payment_method' => input('postage_payment_method', ''),
'template_name' => input('template_name', ''), 'is_notice' => input('is_notice', ''),
'company_id' => input('company_id', ''), 'is_default' => input('is_default', 0),
'customer_name' => input('customer_name', ''), 'print_style' => input('print_style', 0),
'customer_pwd' => input('customer_pwd', ''), ];
'send_site' => input('send_site', ''), $model = new ExpressElectronicsheetModel();
'send_staff' => input('send_staff', ''), return $model->addExpressElectronicsheet($data);
'month_code' => input('month_code', ''),
'postage_payment_method' => input('postage_payment_method', ''), } else {
'is_notice' => input('is_notice', ''), //快递公司
'is_default' => input('is_default', 0), $express_company_model = new ExpressCompanyTemplate();
'print_style' => input('print_style', 0), $condition = [
]; [ 'is_electronicsheet', '=', 1 ],
$model = new ExpressElectronicsheetModel(); ];
return $model->addExpressElectronicsheet($data); $company_list = $express_company_model->getExpressCompanyTemplateList($condition, 'company_id,company_name,print_style', 'sort asc');
$this->assign('company_list', $company_list[ 'data' ]);
} else { return $this->fetch('electronicsheet/add');
//快递公司 }
$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' ]); public function edit()
return $this->fetch('electronicsheet/add'); {
} $model = new ExpressElectronicsheetModel();
} $id = input('id', 0);
if (request()->isJson()) {
/** $data = [
* 编辑电子面单 'id' => $id,
*/ 'site_id' => $this->site_id,
public function edit() 'template_name' => input('template_name', ''),
{ 'company_id' => input('company_id', ''),
$model = new ExpressElectronicsheetModel(); 'customer_name' => input('customer_name', ''),
$id = input('id', 0); 'customer_pwd' => input('customer_pwd', ''),
if (request()->isJson()) { 'send_site' => input('send_site', ''),
$data = [ 'send_staff' => input('send_staff', ''),
'id' => $id, 'month_code' => input('month_code', ''),
'site_id' => $this->site_id, 'postage_payment_method' => input('postage_payment_method', ''),
'template_name' => input('template_name', ''), 'is_notice' => input('is_notice', ''),
'company_id' => input('company_id', ''), 'is_default' => input('is_default', 0),
'customer_name' => input('customer_name', ''), 'print_style' => input('print_style', 0),
'customer_pwd' => input('customer_pwd', ''), ];
'send_site' => input('send_site', ''), return $model->editExpressElectronicsheet($data);
'send_staff' => input('send_staff', ''),
'month_code' => input('month_code', ''), } else {
'postage_payment_method' => input('postage_payment_method', ''),
'is_notice' => input('is_notice', ''), $info = $model->getExpressElectronicsheetInfo([ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ]);
'is_default' => input('is_default', 0), $this->assign('electronicsheet_info', $info[ 'data' ]);
'print_style' => input('print_style', 0), //快递公司
]; $express_company_model = new ExpressCompanyTemplate();
return $model->editExpressElectronicsheet($data); $condition = [
[ 'is_electronicsheet', '=', 1 ],
} else {
];
$info = $model->getExpressElectronicsheetInfo([ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ]); $company_list = $express_company_model->getExpressCompanyTemplateList($condition, 'company_id,company_name,print_style', 'sort asc');
$this->assign('electronicsheet_info', $info[ 'data' ]); $this->assign('company_list', $company_list[ 'data' ]);
//快递公司 return $this->fetch('electronicsheet/edit');
$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' ]); public function delete()
return $this->fetch('electronicsheet/edit'); {
} $id = input('id', '');
}
$groupbuy_model = new ExpressElectronicsheetModel();
/* return $groupbuy_model->deleteExpressElectronicsheet([ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ]);
* 删除 }
*/
public function delete() /*
{ * 修改默认状态
$id = input('id', ''); */
public function setDefaultStatus()
$groupbuy_model = new ExpressElectronicsheetModel(); {
return $groupbuy_model->deleteExpressElectronicsheet([ [ 'id', '=', $id ], [ 'site_id', '=', $this->site_id ] ]); $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);
*/ }
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 <?php
/**
namespace addon\fenxiao\api\controller;
use addon\fenxiao\model\FenxiaoAccount;
use addon\fenxiao\model\Fenxiao as FenxiaoModel;
use app\api\controller\BaseApi;
*/ /**
* 分销商流水
namespace addon\fenxiao\api\controller; */
class Account extends BaseApi
use addon\fenxiao\model\FenxiaoAccount; {
use addon\fenxiao\model\Fenxiao as FenxiaoModel;
use app\api\controller\BaseApi; /**
* 分销商流水分页
/** * @return false|string
* 分销商流水 */
*/ public function page()
class Account extends BaseApi {
{
$token = $this->checkToken();
/** if ($token[ 'code' ] < 0) return $this->response($token);
* 分销商流水分页
* @return false|string $page = $this->params['page'] ?? 1;
*/ $page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
public function page()
{ $model = new FenxiaoModel();
$fenxiao_info = $model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id')[ 'data' ];
$token = $this->checkToken(); if (!empty($fenxiao_info[ 'fenxiao_id' ])) {
if ($token[ 'code' ] < 0) return $this->response($token); $condition = [
[ 'fenxiao_id', '=', $fenxiao_info[ 'fenxiao_id' ] ]
$page = $this->params['page'] ?? 1; ];
$page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
$account_model = new FenxiaoAccount();
$model = new FenxiaoModel(); $list = $account_model->getFenxiaoAccountPageList($condition, $page, $page_size);
$fenxiao_info = $model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id')[ 'data' ]; return $this->response($list);
if (!empty($fenxiao_info[ 'fenxiao_id' ])) { }
$condition = [ return $this->response($this->error('', 'FENXIAO_NOT_EXIST'));
[ '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 <?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;
*/
/**
namespace addon\fenxiao\api\controller; * 申请分销商
*/
use addon\fenxiao\model\Config; class Apply extends BaseApi
use addon\fenxiao\model\FenxiaoApply; {
use addon\fenxiao\model\Fenxiao; /**
use app\api\controller\BaseApi; * 判断分销商名称是否存在
*/
/** public function existFenxiaoName()
* 申请分销商 {
*/ $token = $this->checkToken();
class Apply extends BaseApi 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'));
public function existFenxiaoName() }
{
$token = $this->checkToken(); $apply_model = new FenxiaoApply();
if ($token[ 'code' ] < 0) return $this->response($token); $res = $apply_model->existFenxiaoName($fenxiao_name, $this->site_id);
$fenxiao_name = $this->params['fenxiao_name'] ?? '';//分销商名称 return $this->response($res);
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); public function applyFenxiao()
{
return $this->response($res); $token = $this->checkToken();
} if ($token[ 'code' ] < 0) return $this->response($token);
/** $fenxiao_name = $this->params['fenxiao_name'] ?? '';//分销商名称
* 申请成为分销商 $mobile = $this->params['mobile'] ?? '';//联系电话
*/
public function applyFenxiao() $config = new Config();
{ $basics_config = $config->getFenxiaoBasicsConfig($this->site_id)[ 'data' ][ 'value' ];
$token = $this->checkToken(); if (!$basics_config[ 'level' ]) return $this->response($this->error('', '未开启分销功能'));
if ($token[ 'code' ] < 0) return $this->response($token);
if ($basics_config[ 'is_apply' ] == 1) {
$fenxiao_name = $this->params['fenxiao_name'] ?? '';//分销商名称 if (empty($fenxiao_name)) {
$mobile = $this->params['mobile'] ?? '';//联系电话 return $this->response($this->error('', 'REQUEST_FENXIAO_NAME'));
}
$config = new Config(); if (empty($mobile)) {
$basics_config = $config->getFenxiaoBasicsConfig($this->site_id)[ 'data' ][ 'value' ]; return $this->response($this->error('', 'REQUEST_MOBILE'));
if (!$basics_config[ 'level' ]) return $this->response($this->error('', '未开启分销功能')); }
$apply_model = new FenxiaoApply();
if ($basics_config[ 'is_apply' ] == 1) { $res = $apply_model->applyFenxiao($this->member_id, $this->site_id, $fenxiao_name, $mobile);
if (empty($fenxiao_name)) { } else if ($basics_config[ 'is_apply' ] == 0) {
return $this->response($this->error('', 'REQUEST_FENXIAO_NAME')); $apply_model = new Fenxiao();
} $res = $apply_model->autoBecomeFenxiao($this->member_id, $this->site_id);
if (empty($mobile)) { } else {
return $this->response($this->error('', 'REQUEST_MOBILE')); return $this->response($this->error('', '未开启分销商申请'));
} }
$apply_model = new FenxiaoApply();
$res = $apply_model->applyFenxiao($this->member_id, $this->site_id, $fenxiao_name, $mobile); return $this->response($res);
} else if ($basics_config[ 'is_apply' ] == 0) { }
$apply_model = new Fenxiao();
$res = $apply_model->autoBecomeFenxiao($this->member_id, $this->site_id); public function info()
} else { {
return $this->response($this->error('', '未开启分销商申请')); $token = $this->checkToken();
} if ($token[ 'code' ] < 0) return $this->response($token);
return $this->response($res); $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');
}
public function info()
{ /**
$token = $this->checkToken(); * 获取申请分销商状态
if ($token[ 'code' ] < 0) return $this->response($token); * @return false|string
*/
$apply_model = new Fenxiao(); public function status()
$apply_model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'apply_id,fenxiao_name,parent,member_id,mobile,nickname,headimg,level_id,level_name,status'); {
} $token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
/**
* 获取申请分销商状态 $apply_model = new FenxiaoApply();
* @return false|string $res = $apply_model->getFenxiaoApplyInfo([ [ 'member_id', '=', $this->member_id ] ], 'status');
*/ return $this->response($res);
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 <?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;
*/
/**
namespace addon\fenxiao\api\controller; * 分销相关配置
*/
use app\api\controller\BaseApi; class Config extends BaseApi
use addon\fenxiao\model\Config as ConfigModel; {
use app\model\goods\Goods;
use app\model\system\Document; /**
* 提现配置
/** */
* 分销相关配置 public function withdraw()
*/ {
class Config extends BaseApi $config = new ConfigModel();
{ $res = $config->getFenxiaoWithdrawConfig($this->site_id);
return $this->response($this->success($res[ 'data' ][ 'value' ]));
/** }
* 提现配置
*/ /**
public function withdraw() * 文字设置
{ * @return false|string
$config = new ConfigModel(); */
$res = $config->getFenxiaoWithdrawConfig($this->site_id); public function words()
return $this->response($this->success($res[ 'data' ][ 'value' ])); {
} $config = new ConfigModel();
$res = $config->getFenxiaoWordsConfig($this->site_id);
/** return $this->response($this->success($res[ 'data' ][ 'value' ]));
* 文字设置 }
* @return false|string
*/ /**
public function words() * 申请协议
{ * @return false|string
$config = new ConfigModel(); */
$res = $config->getFenxiaoWordsConfig($this->site_id); public function agreement()
return $this->response($this->success($res[ 'data' ][ 'value' ])); {
} $config = new ConfigModel();
$agreement = $config->getFenxiaoAgreementConfig($this->site_id);
/** $res = [];
* 申请协议 $res[ 'agreement' ] = $agreement[ 'data' ][ 'value' ];
* @return false|string if ($agreement[ 'data' ][ 'value' ][ 'is_agreement' ] == 1) {
*/ $document_model = new Document();
public function agreement() $document = $document_model->getDocument([ [ 'site_id', '=', $this->site_id ], [ 'app_module', '=', 'shop' ], [ 'document_key', '=', 'FENXIAO_AGREEMENT'] ]);
{ $res[ 'document' ] = $document[ 'data' ];
$config = new ConfigModel(); }
$agreement = $config->getFenxiaoAgreementConfig($this->site_id);
$res = []; return $this->response($this->success($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 false|string
} */
public function basics()
return $this->response($this->success($res)); {
} $config = new ConfigModel();
$res = $config->getFenxiaoBasicsConfig($this->site_id);
/** return $this->response($this->success($res[ 'data' ][ 'value' ]));
* 分销基本设置 }
* @return false|string
*/ /**
public function basics() * 分销商资格设置
{ * @return false|string
$config = new ConfigModel(); */
$res = $config->getFenxiaoBasicsConfig($this->site_id); public function fenxiao()
return $this->response($this->success($res[ 'data' ][ 'value' ])); {
} $config = new ConfigModel();
$res = $config->getFenxiaoConfig($this->site_id);
/** $res[ 'data' ][ 'value' ][ 'goods_list' ] = [];
* 分销商资格设置 // 购买指定商品
* @return false|string if ($res[ 'data' ][ 'value' ][ 'fenxiao_condition' ] == 4) {
*/ $page = $this->params[ 'page' ] ?? 1;
public function fenxiao() $page_size = $this->params[ 'page_size' ] ?? 10;
{ $condition[] = [ 'gs.goods_state', '=', 1 ];
$config = new ConfigModel(); $condition[] = [ 'gs.is_delete', '=', 0 ];
$res = $config->getFenxiaoConfig($this->site_id); $condition[] = [ 'gs.site_id', '=', $this->site_id ];
$res[ 'data' ][ 'value' ][ 'goods_list' ] = []; $condition[] = [ 'gs.goods_id', 'in', $res[ 'data' ][ 'value' ][ 'goods_ids' ] ];
// 购买指定商品
if ($res[ 'data' ][ 'value' ][ 'fenxiao_condition' ] == 4) { $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';
$page = $this->params[ 'page' ] ?? 1; $alias = 'gs';
$page_size = $this->params[ 'page_size' ] ?? 10; $join = [
$condition[] = [ 'gs.goods_state', '=', 1 ]; [ 'goods g', 'gs.sku_id = g.sku_id', 'inner' ]
$condition[] = [ 'gs.is_delete', '=', 0 ]; ];
$condition[] = [ 'gs.site_id', '=', $this->site_id ]; $goods = new Goods();
$condition[] = [ 'gs.goods_id', 'in', $res[ 'data' ][ 'value' ][ 'goods_ids' ] ]; $list = $goods->getGoodsSkuPageList($condition, $page, $page_size, '', $field, $alias, $join);
$res[ 'data' ][ 'value' ][ 'goods_list' ] = $list[ 'data' ][ 'list' ];
$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 = [ return $this->response($this->success($res[ 'data' ][ 'value' ]));
[ '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 false|string
} */
public function relation()
return $this->response($this->success($res[ 'data' ][ 'value' ])); {
} $config = new ConfigModel();
$res = $config->getFenxiaoRelationConfig($this->site_id);
/** return $this->response($this->success($res[ 'data' ][ 'value' ]));
* 获取上下级关系设置 }
* @return false|string
*/ /**
public function relation() * 推广规则
{ * @return false|string
$config = new ConfigModel(); */
$res = $config->getFenxiaoRelationConfig($this->site_id); public function promoteRule()
return $this->response($this->success($res[ 'data' ][ 'value' ])); {
} $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);
* 推广规则 }
* @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 <?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;
namespace addon\fenxiao\api\controller; use app\api\controller\BaseApi;
use app\model\member\Member;
use addon\fenxiao\model\Config; use Carbon\Carbon;
use addon\fenxiao\model\Fenxiao as FenxiaoModel; use think\facade\Db;
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; class Fenxiao extends BaseApi
use app\model\member\Member; {
use Carbon\Carbon; /**
use think\facade\Db; * 获取分销商信息
*/
/** public function detail()
* 分销相关信息 {
*/ $token = $this->checkToken();
class Fenxiao extends BaseApi if ($token[ 'code' ] < 0) return $this->response($token);
{
/** $condition = [
* 获取分销商信息 [ 'f.member_id', '=', $this->member_id ]
*/ ];
public function detail()
{ $model = new FenxiaoModel();
$token = $this->checkToken(); $info = $model->getFenxiaoDetailInfo($condition);
if ($token[ 'code' ] < 0) return $this->response($token); if (empty($info[ 'data' ])) {
$res = $model->autoBecomeFenxiao($this->member_id, $this->site_id);
$condition = [ if (isset($res[ 'code' ]) && $res[ 'code' ] >= 0) {
[ 'f.member_id', '=', $this->member_id ] $info = $model->getFenxiaoDetailInfo($condition);
]; }
} else {
$model = new FenxiaoModel(); $member = new Member();
$info = $model->getFenxiaoDetailInfo($condition); //$info[ 'data' ][ 'one_child_num' ] = $member->getMemberCount([ [ 'fenxiao_id', '=', $info[ 'data' ][ 'fenxiao_id' ] ], [ 'is_fenxiao', '=', 0 ] ])[ 'data' ];
if (empty($info[ 'data' ])) {
$res = $model->autoBecomeFenxiao($this->member_id, $this->site_id); $condition_result = $model->geFenxiaoNextLevel($this->member_id, $this->site_id);
if (isset($res[ 'code' ]) && $res[ 'code' ] >= 0) { $info[ 'data' ][ 'condition' ] = $condition_result[ 'data' ];
$info = $model->getFenxiaoDetailInfo($condition); }
}
} else { if (!empty($info[ 'data' ])) {
$member = new Member(); $fenxiao_order_model = new FenxiaoOrderModel();
//$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); $compare_today = Carbon::today()->timestamp;
$info[ 'data' ][ 'condition' ] = $condition_result[ 'data' ]; $compare_tomorrow = Carbon::tomorrow()->timestamp;
}
$commission = 0;
if (!empty($info[ 'data' ])) { $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');
$fenxiao_order_model = new FenxiaoOrderModel(); $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');
// 今日收入
$compare_today = Carbon::today()->timestamp; if (!empty($one_commission[ 'data' ][ 'commission' ])) $commission += $one_commission[ 'data' ][ 'commission' ];
$compare_tomorrow = Carbon::tomorrow()->timestamp; if (!empty($two_commission[ 'data' ][ 'commission' ])) $commission += $two_commission[ 'data' ][ 'commission' ];
if (!empty($three_commission[ 'data' ][ 'commission' ])) $commission += $three_commission[ 'data' ][ 'commission' ];
$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'); $info[ 'data' ][ 'today_commission' ] = $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'); // 总销售额
$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');
if (!empty($one_commission[ 'data' ][ 'commission' ])) $commission += $one_commission[ 'data' ][ 'commission' ];
if (!empty($two_commission[ 'data' ][ 'commission' ])) $commission += $two_commission[ 'data' ][ 'commission' ]; $fenxiao_order_info = $fenxiao_order_info[ 'data' ];
if (!empty($three_commission[ 'data' ][ 'commission' ])) $commission += $three_commission[ 'data' ][ 'commission' ]; if (empty($fenxiao_order_info[ 'real_goods_money' ])) {
$fenxiao_order_info[ 'real_goods_money' ] = 0;
$info[ 'data' ][ 'today_commission' ] = $commission; }
$info[ 'data' ][ 'today_order_money' ] = $fenxiao_order_info[ 'real_goods_money' ];
// 总销售额
$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'); $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');
$fenxiao_order_info = $fenxiao_order_info[ 'data' ]; $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');
if (empty($fenxiao_order_info[ 'real_goods_money' ])) { $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');
$fenxiao_order_info[ 'real_goods_money' ] = 0;
} if (!empty($one_in_progress_commission[ 'data' ][ 'commission' ])) $info[ 'data' ][ 'in_progress_money' ] += $one_in_progress_commission[ 'data' ][ 'commission' ];
$info[ 'data' ][ 'today_order_money' ] = $fenxiao_order_info[ 'real_goods_money' ]; 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' ];
$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'); return $this->response($info);
$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' ]; public function sourceInfo()
} {
return $this->response($info); $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;
public function sourceInfo()
{ if (empty($fenxiao_id)) {
$token = $this->checkToken(); return $this->response($this->error('', 'REQUEST_SOURCE_MEMBER'));
if ($token[ 'code' ] < 0) return $this->response($token); }
$condition = [
$member = new Member(); [ 'fenxiao_id', '=', $fenxiao_id ]
$member_info = $member->getMemberInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id'); ];
$fenxiao_id = $member_info[ 'data' ][ 'fenxiao_id' ] ?? 0;
$model = new FenxiaoModel();
if (empty($fenxiao_id)) { $info = $model->getFenxiaoInfo($condition, 'fenxiao_name');
return $this->response($this->error('', 'REQUEST_SOURCE_MEMBER'));
} return $this->response($info);
$condition = [ }
[ 'fenxiao_id', '=', $fenxiao_id ]
]; /**
* 获取模板id
$model = new FenxiaoModel(); * @return false|string
$info = $model->getFenxiaoInfo($condition, 'fenxiao_name'); */
public function posterTemplateIds()
return $this->response($info); {
} $token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
/**
* 获取模板id $condition = [
* @return false|string [ 'site_id', '=', $this->site_id ],
*/ [ 'template_type', '=', 'fenxiao' ],
public function posterTemplateIds() [ 'template_status', '=', 1 ],
{ ];
$token = $this->checkToken(); $condition[] = [ 'template_type', '=', 'fenxiao' ];
if ($token[ 'code' ] < 0) return $this->response($token); $poster_template_model = new PosterTemplateModel();
$list = $poster_template_model->getPosterTemplateList($condition, 'template_id', 'template_id asc')[ 'data' ];
$condition = [ $id_arr = array_column($list, 'template_id');
[ 'site_id', '=', $this->site_id ], if (empty($id_arr)) $id_arr = [ 'default' ];
[ 'template_type', '=', 'fenxiao' ],
[ 'template_status', '=', 1 ], return $this->response($this->success($id_arr));
]; }
$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'); * @return \app\api\controller\false|string
if (empty($id_arr)) $id_arr = [ 'default' ]; */
public function poster()
return $this->response($this->success($id_arr)); {
} $token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
/**
* 分销海报 $qrcode_param = $this->params['qrcode_param'] ?? '';//二维码
* @return \app\api\controller\false|string
*/ if (empty($qrcode_param)) {
public function poster() return $this->response($this->error('', 'REQUEST_QRCODE_PARAM'));
{ }
$token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token); $qrcode_param = json_decode($qrcode_param, true);
$qrcode_param[ 'source_member' ] = $this->member_id;
$qrcode_param = $this->params['qrcode_param'] ?? '';//二维码
$poster = new Poster();
if (empty($qrcode_param)) { $param = $this->params;
return $this->response($this->error('', 'REQUEST_QRCODE_PARAM')); $param[ 'qrcode_param' ] = $qrcode_param;
} $res = $poster->getFenxiaoPoster($param);
$qrcode_param = json_decode($qrcode_param, true); return $this->response($res);
$qrcode_param[ 'source_member' ] = $this->member_id; }
$poster = new Poster(); /**
$param = $this->params; * 分销海报
$param[ 'qrcode_param' ] = $qrcode_param; * @return \app\api\controller\false|string
$res = $poster->getFenxiaoPoster($param); */
public function posterList()
return $this->response($res); {
} $token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
/**
* 分销海报 $condition = [
* @return \app\api\controller\false|string [ 'site_id', '=', $this->site_id ],
*/ [ 'template_type', '=', 'fenxiao' ],
public function posterList() [ 'template_status', '=', 1 ],
{ ];
$token = $this->checkToken(); $condition[] = [ 'template_type', '=', 'fenxiao' ];
if ($token[ 'code' ] < 0) return $this->response($token); $poster_template_model = new PosterTemplateModel();
$list = $poster_template_model->getPosterTemplateList($condition, 'template_id', 'template_id asc')[ 'data' ];
$condition = [ $id_arr = array_column($list, 'template_id');
[ 'site_id', '=', $this->site_id ], $id_arr = $id_arr ?: ['default'];
[ 'template_type', '=', 'fenxiao' ], $qrcode_param = $this->params['qrcode_param'] ?? '';//二维码
[ 'template_status', '=', 1 ], $qrcode_param = [json_decode($qrcode_param, true)];
]; $qrcode_param[ 'source_member' ] = $this->member_id;
$condition[] = [ 'template_type', '=', 'fenxiao' ]; $poster = new Poster();
$poster_template_model = new PosterTemplateModel(); $param = $this->params;
$list = $poster_template_model->getPosterTemplateList($condition, 'template_id', 'template_id asc')[ 'data' ]; $param[ 'qrcode_param' ] = $qrcode_param;
$id_arr = array_column($list, 'template_id'); $path = [];
$id_arr = $id_arr ?: ['default']; foreach ($id_arr as $k => $v){
$qrcode_param = $this->params['qrcode_param'] ?? '';//二维码 $param['template_id'] = $v;
$qrcode_param = [json_decode($qrcode_param, true)]; $res = $poster->getFenxiaoPoster($param)['data']['path'] ?? '';
$qrcode_param[ 'source_member' ] = $this->member_id; if($res) $path[] = $res;
$poster = new Poster(); }
$param = $this->params; return $this->response($this->success($path));
$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; public function level()
} {
return $this->response($this->success($path)); $token = $this->checkToken();
} if ($token[ 'code' ] < 0) return $this->response($token);
/** $level = $this->params[ 'level' ] ?? 0;
* 分销商等级信息
*/ $condition = [
public function level() [ 'level_id', '=', $level ]
{ ];
$token = $this->checkToken(); $model = new FenxiaoLevel();
if ($token[ 'code' ] < 0) return $this->response($token); $info = $model->getLevelInfo($condition);
$level = $this->params[ 'level' ] ?? 0; return $this->response($info);
}
$condition = [
[ 'level_id', '=', $level ] /**
]; * 分销商我的团队
$model = new FenxiaoLevel(); */
$info = $model->getLevelInfo($condition); public function team()
{
return $this->response($info); $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;
public function team() $is_pay = $this->params[ 'is_pay' ] ?? 0;
{
$token = $this->checkToken(); $model = new FenxiaoModel();
if ($token[ 'code' ] < 0) return $this->response($token); $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; $list = $model->getFenxiaoTeam($level, $fenxiao_info[ 'data' ][ 'fenxiao_id' ], $page, $page_size, $is_pay);
$level = $this->params[ 'level' ] ?? 1;
$is_pay = $this->params[ 'is_pay' ] ?? 0; return $this->response($list);
}
$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); public function teamNum()
{
return $this->response($list); $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'));
public function teamNum()
{ $data = $model->getFenxiaoTeamNum($fenxiao_info[ 'data' ][ 'fenxiao_id' ], $this->site_id);
$token = $this->checkToken(); return $this->response($data);
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')); * @return false|string
*/
$data = $model->getFenxiaoTeamNum($fenxiao_info[ 'data' ][ 'fenxiao_id' ], $this->site_id); public function getOrder()
return $this->response($data); {
} $token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
/**
* 获取下级分销商订单 $model = new FenxiaoModel();
* @return false|string $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'));
public function getOrder() $fenxiao_info = $fenxiao_info[ 'data' ];
{
$token = $this->checkToken(); $page = $this->params[ 'page' ] ?? 1;
if ($token[ 'code' ] < 0) return $this->response($token); $page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
$fenxiao_id = $this->params[ 'fenxiao_id' ] ?? 0;
$model = new FenxiaoModel(); $sub_member_id = $this->params[ 'sub_member_id' ] ?? 0;
$fenxiao_info = $model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id'); $condition = [];
if (empty($fenxiao_info[ 'data' ])) return $this->response($this->error('', 'MEMBER_NOT_IS_FENXIAO'));
$fenxiao_info = $fenxiao_info[ 'data' ]; if (!empty($fenxiao_id)) {
$sub_fenxiao_info = $model->getFenxiaoInfo([ [ 'fenxiao_id', '=', $fenxiao_id ] ], 'fenxiao_id,member_id')[ 'data' ];
$page = $this->params[ 'page' ] ?? 1; if (empty($sub_fenxiao_info)) return $this->response($this->error('', 'MEMBER_NOT_IS_FENXIAO'));
$page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
$fenxiao_id = $this->params[ 'fenxiao_id' ] ?? 0; $condition = [
$sub_member_id = $this->params[ 'sub_member_id' ] ?? 0; [ '', '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']}") ]
$condition = []; ];
} elseif (!empty($sub_member_id)) {
if (!empty($fenxiao_id)) { $is_sub_member = model('member')->getCount([ [ 'member_id', '=', $sub_member_id ], [ 'fenxiao_id', '=', $fenxiao_info[ 'fenxiao_id' ] ] ]);
$sub_fenxiao_info = $model->getFenxiaoInfo([ [ 'fenxiao_id', '=', $fenxiao_id ] ], 'fenxiao_id,member_id')[ 'data' ]; if (!$is_sub_member) return $this->response($this->error('', 'NOT_EXIST_FENXIAO_RELATION'));
if (empty($sub_fenxiao_info)) return $this->response($this->error('', 'MEMBER_NOT_IS_FENXIAO'));
$condition = [
$condition = [ [ 'fo.one_fenxiao_id', '=', $fenxiao_info[ 'fenxiao_id' ] ],
[ '', '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']}") ] [ 'fo.member_id', '=', $sub_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')); $order_model = new FenxiaoOrderModel();
$list = $order_model->getFenxiaoOrderPageList($condition, $page, $page_size, 'fo.fenxiao_order_id desc');
$condition = [ if (!empty($list[ 'data' ][ 'list' ])) {
[ 'fo.one_fenxiao_id', '=', $fenxiao_info[ 'fenxiao_id' ] ], foreach ($list[ 'data' ][ 'list' ] as $k => $item) {
[ 'fo.member_id', '=', $sub_member_id ] 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' ]) {
$order_model = new FenxiaoOrderModel(); $list[ 'data' ][ 'list' ][ $k ][ 'commission' ] = $item[ 'two_commission' ];
$list = $order_model->getFenxiaoOrderPageList($condition, $page, $page_size, 'fo.fenxiao_order_id desc'); $list[ 'data' ][ 'list' ][ $k ][ 'commission_level' ] = 2;
if (!empty($list[ 'data' ][ 'list' ])) { } elseif ($item[ 'three_fenxiao_id' ] == $fenxiao_info[ 'fenxiao_id' ]) {
foreach ($list[ 'data' ][ 'list' ] as $k => $item) { $list[ 'data' ][ 'list' ][ $k ][ 'commission' ] = $item[ 'three_commission' ];
if ($item[ 'one_fenxiao_id' ] == $fenxiao_info[ 'fenxiao_id' ]) { $list[ 'data' ][ 'list' ][ $k ][ 'commission_level' ] = 3;
$list[ 'data' ][ 'list' ][ $k ][ 'commission' ] = $item[ 'one_commission' ]; }
$list[ 'data' ][ 'list' ][ $k ][ 'commission_level' ] = 1; $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' => '' ]);
} elseif ($item[ 'two_fenxiao_id' ] == $fenxiao_info[ 'fenxiao_id' ]) { }
$list[ 'data' ][ 'list' ][ $k ][ 'commission' ] = $item[ 'two_commission' ]; }
$list[ 'data' ][ 'list' ][ $k ][ 'commission_level' ] = 2; return $this->response($list);
} 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' => '' ]); */
} public function rankingList()
} {
return $this->response($list); $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;
public function rankingList()
{ $model = new FenxiaoModel();
$token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token); $condition = [
[ 'f.site_id', '=', $this->site_id ],
$type = $this->params[ 'type' ] ?? 'profit'; // 排行榜 profit按受益 invited_num按邀请人数 [ 'f.is_delete', '=', 0 ]
$page = $this->params[ 'page' ] ?? 1; ];
$page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
$order = $type == 'profit' ? 'f.total_commission desc' : Db::raw('(f.one_child_num) desc');
$model = new FenxiaoModel(); $field = 'f.total_commission, (f.one_child_num) as child_num, m.nickname,m.headimg';
$condition = [ $data = $model->getFenxiaoPageLists($condition, $page, $page_size, $order, $field, 'f', [ [ 'member m', 'm.member_id = f.member_id', 'inner' ] ]);
[ 'f.site_id', '=', $this->site_id ],
[ 'f.is_delete', '=', 0 ] return $this->response($data);
]; }
$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'; * 获取排名
* @return false|string
$data = $model->getFenxiaoPageLists($condition, $page, $page_size, $order, $field, 'f', [ [ 'member m', 'm.member_id = f.member_id', 'inner' ] ]); */
public function ranking()
return $this->response($data); {
} $token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
/**
* 获取排名 $type = $this->params[ 'type' ] ?? 'invited_num'; // 排行榜 profit按受益 invited_num按邀请人数
* @return false|string
*/ $model = new FenxiaoModel();
public function ranking() $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'));
$token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token); $order = $type == 'profit' ? 'total_commission' : '(one_child_num + one_child_fenxiao_num)';
$type = $this->params[ 'type' ] ?? 'invited_num'; // 排行榜 profit按受益 invited_num按邀请人数 $data = $model->getFenxiaoRanking($this->site_id, $fenxiao_info[ 'fenxiao_id' ], $order);
return $this->response($data);
$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)'; */
public function childFenxiao()
$data = $model->getFenxiaoRanking($this->site_id, $fenxiao_info[ 'fenxiao_id' ], $order); {
return $this->response($data); $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;
*/
public function childFenxiao() $model = new FenxiaoModel();
{ $fenxiao_info = $model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id')[ 'data' ];
$token = $this->checkToken(); if (empty($fenxiao_info)) return $this->response($this->error('', 'MEMBER_NOT_IS_FENXIAO'));
if ($token[ 'code' ] < 0) return $this->response($token);
$parent_fenxiao_id = [ $fenxiao_info[ 'fenxiao_id' ] ]; // 上级分销商id集合
$page = $this->params[ 'page' ] ?? 1;
$page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS; // 查询分销基础配置
$config_model = new Config();
$model = new FenxiaoModel(); $fenxiao_basic_config = $config_model->getFenxiaoBasicsConfig($this->site_id)[ 'data' ][ 'value' ];
$fenxiao_info = $model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id')[ 'data' ]; $level = $fenxiao_basic_config[ 'level' ];
if (empty($fenxiao_info)) return $this->response($this->error('', 'MEMBER_NOT_IS_FENXIAO'));
if ($level == 2) {
$parent_fenxiao_id = [ $fenxiao_info[ 'fenxiao_id' ] ]; // 上级分销商id集合
// 二级分销商id集合
// 查询分销基础配置 $one_level_fenxiao = model('fenxiao')->getColumn([ [ 'parent', '=', $fenxiao_info[ 'fenxiao_id' ] ] ], 'fenxiao_id');
$config_model = new Config(); if (!empty($one_level_fenxiao)) {
$fenxiao_basic_config = $config_model->getFenxiaoBasicsConfig($this->site_id)[ 'data' ][ 'value' ]; $parent_fenxiao_id = array_merge($parent_fenxiao_id, $one_level_fenxiao);
$level = $fenxiao_basic_config[ 'level' ]; }
}
if ($level == 2) {
$condition = [
// 二级分销商id集合 [ 'f.site_id', '=', $this->site_id ],
$one_level_fenxiao = model('fenxiao')->getColumn([ [ 'parent', '=', $fenxiao_info[ 'fenxiao_id' ] ] ], 'fenxiao_id'); [ 'f.parent', 'in', $parent_fenxiao_id ],
if (!empty($one_level_fenxiao)) { [ 'm.is_delete', '=', 0 ]
$parent_fenxiao_id = array_merge($parent_fenxiao_id, $one_level_fenxiao); ];
} $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' ] ];
$condition = [ $res = $model->getFenxiaoPageLists($condition, $page, $page_size, 'f.audit_time desc', $field, 'f', $join);
[ 'f.site_id', '=', $this->site_id ], return $this->response($res);
[ '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 <?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;
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; class Goods extends BaseApi
use addon\fenxiao\model\FenxiaoGoodsSku as FenxiaoGoodsSkuModel; {
use addon\fenxiao\model\FenxiaoLevel;
use app\api\controller\BaseApi; /**
* 分销商品详情
/** * @param int $id
* 分销商品 * @return false|string
*/ */
class Goods extends BaseApi public function detail($id = 0)
{ {
$token = $this->checkToken();
/** if ($token[ 'code' ] < 0) return $this->response($token);
* 分销商品详情
* @param int $id $sku_id = $this->params['sku_id'] ?? 0;
* @return false|string if (!empty($id)) {
*/ $sku_id = $id;
public function detail($id = 0) }
{ if (empty($sku_id)) {
$token = $this->checkToken(); return $this->response($this->error('', 'REQUEST_SKU_ID'));
if ($token[ 'code' ] < 0) return $this->response($token); }
$sku_id = $this->params['sku_id'] ?? 0; $config = new ConfigModel();
if (!empty($id)) {
$sku_id = $id; $words_config = $config->getFenxiaoWordsConfig($this->site_id)[ 'data' ][ 'value' ];
}
if (empty($sku_id)) { $data = [
return $this->response($this->error('', 'REQUEST_SKU_ID')); 'words_account' => $words_config[ 'account' ],
} 'commission_money' => 0.00
];
$config = new ConfigModel();
$fenxiao_model = new FenxiaoModel();
$words_config = $config->getFenxiaoWordsConfig($this->site_id)[ 'data' ][ 'value' ]; $fenxiao_info = $fenxiao_model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id,level_id')[ 'data' ];
if (empty($fenxiao_info)) return $this->response($this->error());
$data = [
'words_account' => $words_config[ 'account' ], $fenxiao_goods_sku_model = new FenxiaoGoodsSkuModel();
'commission_money' => 0.00 $data[ 'commission_money' ] = $fenxiao_goods_sku_model->getSkuFenxiaoCommission($sku_id, $fenxiao_info[ 'level_id' ])[ 'data' ];
];
$basics = $config->getFenxiaoBasicsConfig($this->site_id);
$fenxiao_model = new FenxiaoModel(); $data[ 'is_commission_money' ] = $basics[ 'data' ][ 'value' ][ 'is_commission_money' ];
$fenxiao_info = $fenxiao_model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id,level_id')[ 'data' ]; return $this->response($this->success($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); public function page()
$data[ 'is_commission_money' ] = $basics[ 'data' ][ 'value' ][ 'is_commission_money' ]; {
return $this->response($this->success($data)); $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'] ?? '';//关键词
public function page() $category_id = $this->params['category_id'] ?? 0;//分类
{ $min_price = $this->params['min_price'] ?? 0;//价格区间,小
$token = $this->checkToken(); $max_price = $this->params['max_price'] ?? 0;//价格区间,大
if ($token[ 'code' ] < 0) return $this->response($token); $is_free_shipping = $this->params['is_free_shipping'] ?? 0;//是否免邮
$order = $this->params['order'] ?? 'create_time';//排序(综合、销量、价格)
$page = $this->params['page'] ?? 1; $sort = $this->params['sort'] ?? 'desc';//升序、降序
$page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS; $goods_id_arr = $this->params['goods_id_arr'] ?? '';//goods_id数组
$keyword = $this->params['keyword'] ?? '';//关键词
$category_id = $this->params['category_id'] ?? 0;//分类 $condition = [
$min_price = $this->params['min_price'] ?? 0;//价格区间,小 [ 'g.is_fenxiao', '=', 1 ],
$max_price = $this->params['max_price'] ?? 0;//价格区间,大 [ 'g.goods_state', '=', 1 ],
$is_free_shipping = $this->params['is_free_shipping'] ?? 0;//是否免邮 [ 'g.is_delete', '=', 0 ],
$order = $this->params['order'] ?? 'create_time';//排序(综合、销量、价格) [ 'g.site_id', '=', $this->site_id ]
$sort = $this->params['sort'] ?? 'desc';//升序、降序 ];
$goods_id_arr = $this->params['goods_id_arr'] ?? '';//goods_id数组
if (!empty($keyword)) {
$condition = [ $condition[] = [ 'g.goods_name|g.keywords', 'like', '%' . $keyword . '%' ];
[ 'g.is_fenxiao', '=', 1 ], }
[ 'g.goods_state', '=', 1 ],
[ 'g.is_delete', '=', 0 ], if (!empty($category_id)) {
[ 'g.site_id', '=', $this->site_id ] $condition[] = [ 'g.category_id', 'like', '%,' . $category_id . ',%' ];
]; }
if (!empty($keyword)) { if (!empty($goods_id_arr)) {
$condition[] = [ 'g.goods_name|g.keywords', 'like', '%' . $keyword . '%' ]; $condition[] = [ 'g.goods_id', 'in', $goods_id_arr ];
} }
if (!empty($category_id)) { if ($min_price != '' && $max_price != '') {
$condition[] = [ 'g.category_id', 'like', '%,' . $category_id . ',%' ]; $condition[] = [ 'g.discount_price', 'between', [ $min_price, $max_price ] ];
} } elseif ($min_price != '') {
$condition[] = [ 'g.discount_price', '>=', $min_price ];
if (!empty($goods_id_arr)) { } elseif ($max_price != '') {
$condition[] = [ 'g.goods_id', 'in', $goods_id_arr ]; $condition[] = [ 'g.discount_price', '<=', $max_price ];
} }
if ($min_price != '' && $max_price != '') { if (!empty($is_free_shipping)) {
$condition[] = [ 'g.discount_price', 'between', [ $min_price, $max_price ] ]; $condition[] = [ 'g.is_free_shipping', '=', $is_free_shipping ];
} elseif ($min_price != '') { }
$condition[] = [ 'g.discount_price', '>=', $min_price ];
} elseif ($max_price != '') { // 非法参数进行过滤
$condition[] = [ 'g.discount_price', '<=', $max_price ]; if ($sort != 'desc' && $sort != 'asc') {
} $sort = '';
}
if (!empty($is_free_shipping)) {
$condition[] = [ 'g.is_free_shipping', '=', $is_free_shipping ]; // 非法参数进行过滤
} if ($order != '') {
if ($order != 'sale_num' && $order != 'discount_price') {
// 非法参数进行过滤 $order = 'gs.create_time';
if ($sort != 'desc' && $sort != 'asc') { } elseif ($order != 'sale_num') {
$sort = ''; $order = 'gs.' . $order;
} } else {
$order = 'sale_sort';
// 非法参数进行过滤 }
if ($order != '') { $order_by = $order . ' ' . $sort;
if ($order != 'sale_num' && $order != 'discount_price') { } else {
$order = 'gs.create_time'; $order_by = 'g.sort desc,g.create_time desc';
} elseif ($order != 'sale_num') { }
$order = 'gs.' . $order;
} else { $fenxiao_model = new FenxiaoModel();
$order = 'sale_sort'; $fenxiao_info = $fenxiao_model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id,level_id')[ 'data' ];
}
$order_by = $order . ' ' . $sort; // $fenxiao_level = new FenxiaoLevel();
} else { // $level_info = $fenxiao_level->getLevelInfo([ [ 'level_id', '=', $fenxiao_info[ 'level_id' ] ] ], 'one_rate')[ 'data' ];
$order_by = 'g.sort desc,g.create_time desc';
} $fenxiao_goods_sku_model = new FenxiaoGoodsSkuModel();
$list = $fenxiao_goods_sku_model->getFenxiaoGoodsSkuPageList($condition, $page, $page_size, $order_by);
$fenxiao_model = new FenxiaoModel();
$fenxiao_info = $fenxiao_model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id,level_id')[ 'data' ]; $fenxiao_goods_collect_model = new FenxiaoGoodsCollectModel();
// $fenxiao_level = new FenxiaoLevel(); // 计算佣金
// $level_info = $fenxiao_level->getLevelInfo([ [ 'level_id', '=', $fenxiao_info[ 'level_id' ] ] ], 'one_rate')[ 'data' ]; foreach ($list[ 'data' ][ 'list' ] as $k => $v) {
$collection_info = $fenxiao_goods_collect_model->getCollectInfo([
$fenxiao_goods_sku_model = new FenxiaoGoodsSkuModel(); [ 'member_id', '=', $this->member_id ],
$list = $fenxiao_goods_sku_model->getFenxiaoGoodsSkuPageList($condition, $page, $page_size, $order_by); [ 'goods_id', '=', $v[ 'goods_id' ] ],
[ 'fenxiao_id', '=', $fenxiao_info[ 'fenxiao_id' ] ],
$fenxiao_goods_collect_model = new FenxiaoGoodsCollectModel(); ], 'collect_id');
// 计算佣金 // 查询是否关注该分销商品
foreach ($list[ 'data' ][ 'list' ] as $k => $v) { $collection_info = $collection_info[ 'data' ];
$collection_info = $fenxiao_goods_collect_model->getCollectInfo([ if (!empty($collection_info)) {
[ 'member_id', '=', $this->member_id ], $list[ 'data' ][ 'list' ][ $k ][ 'is_collect' ] = 1;
[ 'goods_id', '=', $v[ 'goods_id' ] ], $list[ 'data' ][ 'list' ][ $k ][ 'collect_id' ] = $collection_info[ 'collect_id' ];
[ 'fenxiao_id', '=', $fenxiao_info[ 'fenxiao_id' ] ], } else {
], 'collect_id'); $list[ 'data' ][ 'list' ][ $k ][ 'is_collect' ] = 0;
}
// 查询是否关注该分销商品
$collection_info = $collection_info[ 'data' ]; $sku_commission_info = $fenxiao_goods_sku_model->getSkuFenxiaoCommission($v[ 'sku_id' ], $fenxiao_info[ 'level_id' ]);
if (!empty($collection_info)) { $list[ 'data' ][ 'list' ][ $k ][ 'commission_money' ] = $sku_commission_info[ 'data' ];
$list[ 'data' ][ 'list' ][ $k ][ 'is_collect' ] = 1; }
$list[ 'data' ][ 'list' ][ $k ][ 'collect_id' ] = $collection_info[ 'collect_id' ];
} else { return $this->response($list);
$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 <?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;
namespace addon\fenxiao\api\controller; /**
* 分销商关注商品
use addon\fenxiao\model\FenxiaoGoodsSku; */
use addon\fenxiao\model\FenxiaoLevel; class Goodscollect extends BaseApi
use app\api\controller\BaseApi; {
use addon\fenxiao\model\Fenxiao as FenxiaoModel;
use addon\fenxiao\model\FenxiaoGoodsCollect as FenxiaoGoodsCollectModel; /**
* 添加分销商关注商品
/** * @return false|string
* 分销商关注商品 */
*/ public function add()
class Goodscollect extends BaseApi {
{ $token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
/**
* 添加分销商关注商品 $goods_id = $this->params['goods_id'] ?? 0;
* @return false|string $sku_id = $this->params['sku_id'] ?? 0;
*/
public function add() if (empty($goods_id)) {
{ return $this->response($this->error('', 'REQUEST_GOODS_ID'));
$token = $this->checkToken(); }
if ($token[ 'code' ] < 0) return $this->response($token);
$fenxiao_model = new FenxiaoModel();
$goods_id = $this->params['goods_id'] ?? 0; $fenxiao_info = $fenxiao_model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id')[ 'data' ];
$sku_id = $this->params['sku_id'] ?? 0;
$data = [
if (empty($goods_id)) { 'member_id' => $this->member_id,
return $this->response($this->error('', 'REQUEST_GOODS_ID')); 'fenxiao_id' => $fenxiao_info[ 'fenxiao_id' ],
} 'goods_id' => $goods_id,
'sku_id' => $sku_id,
$fenxiao_model = new FenxiaoModel(); 'site_id' => $this->site_id
$fenxiao_info = $fenxiao_model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id')[ 'data' ]; ];
$fenxiao_goods_sku_model = new FenxiaoGoodsCollectModel();
$data = [ $res = $fenxiao_goods_sku_model->addCollect($data);
'member_id' => $this->member_id, return $this->response($res);
'fenxiao_id' => $fenxiao_info[ 'fenxiao_id' ], }
'goods_id' => $goods_id,
'sku_id' => $sku_id, /**
'site_id' => $this->site_id * 删除分销商关注商品
]; * @return false|string
$fenxiao_goods_sku_model = new FenxiaoGoodsCollectModel(); */
$res = $fenxiao_goods_sku_model->addCollect($data); public function delete()
return $this->response($res); {
} $token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
/**
* 删除分销商关注商品 $collect_id = $this->params['collect_id'] ?? 0;
* @return false|string
*/ if (empty($collect_id)) {
public function delete() return $this->response($this->error('', 'REQUEST_COLLECT_ID'));
{ }
$token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token); $fenxiao_model = new FenxiaoModel();
$fenxiao_info = $fenxiao_model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id')[ 'data' ];
$collect_id = $this->params['collect_id'] ?? 0; $condition = [
[ 'fenxiao_id', '=', $fenxiao_info[ 'fenxiao_id' ] ],
if (empty($collect_id)) { [ 'collect_id', '=', $collect_id ]
return $this->response($this->error('', 'REQUEST_COLLECT_ID')); ];
} $fenxiao_goods_sku_model = new FenxiaoGoodsCollectModel();
$res = $fenxiao_goods_sku_model->deleteCollect($condition);
$fenxiao_model = new FenxiaoModel(); return $this->response($res);
$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(); public function page()
$res = $fenxiao_goods_sku_model->deleteCollect($condition); {
return $this->response($res); $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;
*/
public function page() // 获取当前用户的分销等级
{ $fenxiao_model = new FenxiaoModel();
$token = $this->checkToken(); $fenxiao_info = $fenxiao_model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id,level_id')[ 'data' ];
if ($token[ 'code' ] < 0) return $this->response($token);
$fenxiao_level = new FenxiaoLevel();
$page = $this->params['page'] ?? 1; $level_info = $fenxiao_level->getLevelInfo([ [ 'level_id', '=', $fenxiao_info[ 'level_id' ] ] ], 'one_rate')[ 'data' ];
$page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
$condition = [
// 获取当前用户的分销等级 [ 'g.is_fenxiao', '=', 1 ],
$fenxiao_model = new FenxiaoModel(); [ 'g.site_id', '=', $this->site_id ],
$fenxiao_info = $fenxiao_model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id,level_id')[ 'data' ]; [ 'gs.goods_state', '=', 1 ],
[ 'gs.is_delete', '=', 0 ],
$fenxiao_level = new FenxiaoLevel(); [ 'fgc.member_id', '=', $this->member_id ]
$level_info = $fenxiao_level->getLevelInfo([ [ 'level_id', '=', $fenxiao_info[ 'level_id' ] ] ], 'one_rate')[ 'data' ]; ];
$condition = [ $fenxiao_goods_collect_model = new FenxiaoGoodsCollectModel();
[ 'g.is_fenxiao', '=', 1 ], $list = $fenxiao_goods_collect_model->getCollectPageList($condition, $page, $page_size);
[ 'g.site_id', '=', $this->site_id ], $fenxiao_goods_sku_model = new FenxiaoGoodsSku();
[ 'gs.goods_state', '=', 1 ],
[ 'gs.is_delete', '=', 0 ], // 计算佣金比率
[ 'fgc.member_id', '=', $this->member_id ] foreach ($list[ 'data' ][ 'list' ] as $k => $v) {
]; $discount_price = $v[ 'fenxiao_price' ] > 0 ? $v[ 'fenxiao_price' ] : $v[ 'discount_price' ];
$fenxiao_goods_collect_model = new FenxiaoGoodsCollectModel(); $money = 0;
$list = $fenxiao_goods_collect_model->getCollectPageList($condition, $page, $page_size); if ($v[ 'fenxiao_type' ] == 1) {
$fenxiao_goods_sku_model = new FenxiaoGoodsSku(); // 默认规则
$money = number_format($discount_price * $level_info[ 'one_rate' ] / 100, 2, '.', '');
// 计算佣金比率 } else {
foreach ($list[ 'data' ][ 'list' ] as $k => $v) { // 自定义规则
$discount_price = $v[ 'fenxiao_price' ] > 0 ? $v[ 'fenxiao_price' ] : $v[ 'discount_price' ]; $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' ])) {
$money = 0; $fenxiao_goods_sku_info = $fenxiao_goods_sku_info[ 'data' ];
if ($v[ 'fenxiao_type' ] == 1) { $money = $fenxiao_goods_sku_info[ 'one_money' ];
// 默认规则 if ($fenxiao_goods_sku_info[ 'one_rate' ] > 0) {
$money = number_format($discount_price * $level_info[ 'one_rate' ] / 100, 2, '.', ''); $money = number_format($discount_price * $fenxiao_goods_sku_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' ])) { $list[ 'data' ][ 'list' ][ $k ][ 'commission_money' ] = $money;
$fenxiao_goods_sku_info = $fenxiao_goods_sku_info[ 'data' ]; }
$money = $fenxiao_goods_sku_info[ 'one_money' ];
if ($fenxiao_goods_sku_info[ 'one_rate' ] > 0) { return $this->response($list);
$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 <?php
/**
namespace addon\fenxiao\api\controller;
use addon\fenxiao\model\FenxiaoLevel;
use app\api\controller\BaseApi;
*/ /**
* 分销等级
namespace addon\fenxiao\api\controller; */
class Level extends BaseApi
use addon\fenxiao\model\FenxiaoLevel; {
use app\api\controller\BaseApi;
/**
* 分销商等级列表
/** */
* 分销等级 public function lists()
*/ {
class Level extends BaseApi $token = $this->checkToken();
{ if ($token[ 'code' ] < 0) return $this->response($token);
/** $condition = [
* 分销商等级列表 [ 'status', '=', 1 ],
*/ [ 'site_id', '=', $this->site_id ],
public function lists() [ 'is_default', '=', 0 ]
{ ];
$token = $this->checkToken(); $model = new FenxiaoLevel();
if ($token[ 'code' ] < 0) return $this->response($token); $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');
$condition = [ return $this->response($info);
[ '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 <?php
/**
namespace addon\fenxiao\api\controller;
use app\api\controller\BaseApi;
use addon\fenxiao\model\FenxiaoOrder as FenxiaoOrderModel;
use addon\fenxiao\model\Fenxiao;
*/ /**
* 分销订单
namespace addon\fenxiao\api\controller; */
class Order extends BaseApi
use app\api\controller\BaseApi; {
use addon\fenxiao\model\FenxiaoOrder as FenxiaoOrderModel;
use addon\fenxiao\model\Fenxiao; /**
* 信息
/** * @return false|string
* 分销订单 */
*/ public function info()
class Order extends BaseApi {
{ $token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
/**
* 信息 $model = new Fenxiao();
* @return false|string $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'));
public function info()
{ $fenxiao_order_id = $this->params['fenxiao_order_id'] ?? 0;
$token = $this->checkToken(); if (empty($fenxiao_order_id)) {
if ($token[ 'code' ] < 0) return $this->response($token); return $this->response($this->error('', 'REQUEST_FENXIAO_ORDER_ID'));
}
$model = new Fenxiao(); $order_model = new FenxiaoOrderModel();
$fenxiao_info = $model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id'); $condition = [
if (empty($fenxiao_info[ 'data' ])) return $this->response($this->error('', 'MEMBER_NOT_IS_FENXIAO')); [ 'one_fenxiao_id|two_fenxiao_id|three_fenxiao_id', '=', $fenxiao_info[ 'data' ][ 'fenxiao_id' ] ],
[ 'fenxiao_order_id', '=', $fenxiao_order_id ]
$fenxiao_order_id = $this->params['fenxiao_order_id'] ?? 0; ];
if (empty($fenxiao_order_id)) { $res = $order_model->getFenxiaoOrderInfo($condition);
return $this->response($this->error('', 'REQUEST_FENXIAO_ORDER_ID')); if (!empty($res[ 'data' ])) {
} if ($res[ 'data' ][ 'one_fenxiao_id' ] == $fenxiao_info[ 'data' ][ 'fenxiao_id' ]) {
$order_model = new FenxiaoOrderModel(); $res[ 'data' ][ 'commission' ] = $res[ 'data' ][ 'one_commission' ];
$condition = [ $res[ 'data' ][ 'commission_rate' ] = $res[ 'data' ][ 'one_rate' ];
[ 'one_fenxiao_id|two_fenxiao_id|three_fenxiao_id', '=', $fenxiao_info[ 'data' ][ 'fenxiao_id' ] ], $res[ 'data' ][ 'commission_level' ] = 1;
[ 'fenxiao_order_id', '=', $fenxiao_order_id ] } elseif ($res[ 'data' ][ 'two_fenxiao_id' ] == $fenxiao_info[ 'data' ][ 'fenxiao_id' ]) {
]; $res[ 'data' ][ 'commission' ] = $res[ 'data' ][ 'two_commission' ];
$res = $order_model->getFenxiaoOrderInfo($condition); $res[ 'data' ][ 'commission_rate' ] = $res[ 'data' ][ 'two_rate' ];
if (!empty($res[ 'data' ])) { $res[ 'data' ][ 'commission_level' ] = 2;
if ($res[ 'data' ][ 'one_fenxiao_id' ] == $fenxiao_info[ 'data' ][ 'fenxiao_id' ]) { } elseif ($res[ 'data' ][ 'three_fenxiao_id' ] == $fenxiao_info[ 'data' ][ 'fenxiao_id' ]) {
$res[ 'data' ][ 'commission' ] = $res[ 'data' ][ 'one_commission' ]; $res[ 'data' ][ 'commission' ] = $res[ 'data' ][ 'three_commission' ];
$res[ 'data' ][ 'commission_rate' ] = $res[ 'data' ][ 'one_rate' ]; $res[ 'data' ][ 'commission_rate' ] = $res[ 'data' ][ 'three_rate' ];
$res[ 'data' ][ 'commission_level' ] = 1; $res[ 'data' ][ 'commission_level' ] = 3;
} elseif ($res[ 'data' ][ 'two_fenxiao_id' ] == $fenxiao_info[ 'data' ][ 'fenxiao_id' ]) { }
$res[ 'data' ][ 'commission' ] = $res[ 'data' ][ 'two_commission' ]; $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' => '' ]);
$res[ 'data' ][ 'commission_rate' ] = $res[ 'data' ][ 'two_rate' ]; }
$res[ 'data' ][ 'commission_level' ] = 2; return $this->response($res);
} 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' => '' ]); public function page()
} {
return $this->response($res); $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'));
public function page()
{ $page = $this->params['page'] ?? 1;
$token = $this->checkToken(); $page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
if ($token[ 'code' ] < 0) return $this->response($token); $is_settlement = $this->params['is_settlement'] ?? 0;// 结算状态 0 全部 1 待结算 2 已结算 3 已退款
$model = new Fenxiao(); $condition = [
$fenxiao_info = $model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id'); [ 'fo.one_fenxiao_id|fo.two_fenxiao_id|fo.three_fenxiao_id', '=', $fenxiao_info[ 'data' ][ 'fenxiao_id' ] ]
if (empty($fenxiao_info[ 'data' ])) return $this->response($this->error('', 'MEMBER_NOT_IS_FENXIAO')); ];
if (!empty($is_settlement)) {
$page = $this->params['page'] ?? 1; if ($is_settlement == 3) {
$page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS; $condition[] = [ 'fo.is_refund', '=', 1 ];
$is_settlement = $this->params['is_settlement'] ?? 0;// 结算状态 0 全部 1 待结算 2 已结算 3 已退款 }
if (in_array($is_settlement, [ 1, 2 ])) {
$condition = [ $condition[] = [ 'fo.is_settlement', '=', $is_settlement - 1 ];
[ 'fo.one_fenxiao_id|fo.two_fenxiao_id|fo.three_fenxiao_id', '=', $fenxiao_info[ 'data' ][ 'fenxiao_id' ] ] $condition[] = [ 'fo.is_refund', '=', 0 ];
]; }
if (!empty($is_settlement)) { }
if ($is_settlement == 3) {
$condition[] = [ 'fo.is_refund', '=', 1 ]; $order_model = new FenxiaoOrderModel();
} $list = $order_model->getFenxiaoOrderPageList($condition, $page, $page_size, 'fo.fenxiao_order_id desc');
if (in_array($is_settlement, [ 1, 2 ])) { if (!empty($list[ 'data' ][ 'list' ])) {
$condition[] = [ 'fo.is_settlement', '=', $is_settlement - 1 ]; foreach ($list[ 'data' ][ 'list' ] as $k => $item) {
$condition[] = [ 'fo.is_refund', '=', 0 ]; 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' ]) {
$order_model = new FenxiaoOrderModel(); $list[ 'data' ][ 'list' ][ $k ][ 'commission' ] = $item[ 'two_commission' ];
$list = $order_model->getFenxiaoOrderPageList($condition, $page, $page_size, 'fo.fenxiao_order_id desc'); $list[ 'data' ][ 'list' ][ $k ][ 'commission_level' ] = 2;
if (!empty($list[ 'data' ][ 'list' ])) { } elseif ($item[ 'three_fenxiao_id' ] == $fenxiao_info[ 'data' ][ 'fenxiao_id' ]) {
foreach ($list[ 'data' ][ 'list' ] as $k => $item) { $list[ 'data' ][ 'list' ][ $k ][ 'commission' ] = $item[ 'three_commission' ];
if ($item[ 'one_fenxiao_id' ] == $fenxiao_info[ 'data' ][ 'fenxiao_id' ]) { $list[ 'data' ][ 'list' ][ $k ][ 'commission_level' ] = 3;
$list[ 'data' ][ 'list' ][ $k ][ 'commission' ] = $item[ 'one_commission' ]; }
$list[ 'data' ][ 'list' ][ $k ][ 'commission_level' ] = 1; $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' => '' ]);
} 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; return $this->response($list);
} 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 <?php
/**
namespace addon\fenxiao\api\controller;
use addon\fenxiao\model\FenxiaoWithdraw;
use app\api\controller\BaseApi;
use app\model\member\Member;
*/ /**
* 分销提现
namespace addon\fenxiao\api\controller; */
class Withdraw extends BaseApi
use addon\fenxiao\model\FenxiaoWithdraw; {
use app\api\controller\BaseApi;
use app\model\member\Member; /**
* 提现记录分页
/** * @return false|string
* 分销提现 */
*/ public function page()
class Withdraw extends BaseApi {
{
$token = $this->checkToken();
/** if ($token[ 'code' ] < 0) return $this->response($token);
* 提现记录分页
* @return false|string $page = $this->params['page'] ?? 1;
*/ $page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
public function page() $status = $this->params['status'] ?? 0;// 当前状态 1待审核 2待转账 3已转账 -1 已拒绝
{
$condition = [
$token = $this->checkToken(); [ 'member_id', '=', $this->member_id ]
if ($token[ 'code' ] < 0) return $this->response($token); ];
if (!empty($status)) {
$page = $this->params['page'] ?? 1; $condition[] = [ 'status', '=', $status ];
$page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS; }
$status = $this->params['status'] ?? 0;// 当前状态 1待审核 2待转账 3已转账 -1 已拒绝
$order = 'id desc';
$condition = [ $withdraw_model = new FenxiaoWithdraw();
[ 'member_id', '=', $this->member_id ] $list = $withdraw_model->getFenxiaoWithdrawPageList($condition, $page, $page_size, $order);
]; foreach ($list[ 'data' ][ 'list' ] as $k => $v) {
if (!empty($status)) { $list[ 'data' ][ 'list' ][ $k ] = $withdraw_model->tran($v);
$condition[] = [ 'status', '=', $status ]; }
} return $this->response($list);
}
$order = 'id desc';
$withdraw_model = new FenxiaoWithdraw(); /**
$list = $withdraw_model->getFenxiaoWithdrawPageList($condition, $page, $page_size, $order); * 获取转账方式
foreach ($list[ 'data' ][ 'list' ] as $k => $v) { * @return false|string
$list[ 'data' ][ 'list' ][ $k ] = $withdraw_model->tran($v); */
} public function transferType()
return $this->response($list); {
} $token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
/**
* 获取转账方式 $member_model = new Member();
* @return false|string $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();
public function transferType() $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' ])) {
$token = $this->checkToken(); unset($transfer_type_list[ 'wechatpay' ]);
if ($token[ 'code' ] < 0) return $this->response($token); }
return $this->response($this->success($transfer_type_list));
$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' ])) { * @return mixed
unset($transfer_type_list[ 'wechatpay' ]); */
} public function apply()
return $this->response($this->success($transfer_type_list)); {
} $token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
/**
* 申请提现 $apply_money = $this->params[ 'apply_money' ] ?? 0;
* @return mixed $transfer_type = $this->params[ 'transfer_type' ] ?? '';//提现方式
*/ $realname = $this->params[ 'realname' ] ?? '';//真实姓名
public function apply() $bank_name = $this->params[ 'bank_name' ] ?? '';//银行名称
{ $account_number = $this->params[ 'account_number' ] ?? '';//账号名称
$token = $this->checkToken(); $mobile = $this->params[ 'mobile' ] ?? '';//手机号
if ($token[ 'code' ] < 0) return $this->response($token); $app_type = $this->params[ 'app_type' ];
$fenxiao_withdraw_model = new FenxiaoWithdraw();
$apply_money = $this->params[ 'apply_money' ] ?? 0; $data = array (
$transfer_type = $this->params[ 'transfer_type' ] ?? '';//提现方式 'member_id' => $this->member_id,
$realname = $this->params[ 'realname' ] ?? '';//真实姓名 'transfer_type' => $transfer_type,
$bank_name = $this->params[ 'bank_name' ] ?? '';//银行名称 'realname' => $realname,
$account_number = $this->params[ 'account_number' ] ?? '';//账号名称 'bank_name' => $bank_name,
$mobile = $this->params[ 'mobile' ] ?? '';//手机号 'account_number' => $account_number,
$app_type = $this->params[ 'app_type' ]; 'apply_money' => $apply_money,
$fenxiao_withdraw_model = new FenxiaoWithdraw(); 'mobile' => $mobile,
$data = array ( 'app_type' => $app_type
'member_id' => $this->member_id, );
'transfer_type' => $transfer_type, $result = $fenxiao_withdraw_model->apply($data, $this->site_id);
'realname' => $realname, return $this->response($result);
'bank_name' => $bank_name, }
'account_number' => $account_number,
'apply_money' => $apply_money, /**
'mobile' => $mobile, * 提现详情
'app_type' => $app_type * @return mixed
); */
$result = $fenxiao_withdraw_model->apply($data, $this->site_id); public function detail()
return $this->response($result); {
} $token = $this->checkToken();
if ($token[ 'code' ] < 0) return $this->response($token);
/**
* 提现详情 $id = $this->params[ 'id' ] ?? 0;
* @return mixed $fenxiao_withdraw_model = new FenxiaoWithdraw();
*/ $params = array (
public function detail() 'id' => $id,
{ 'site_id' => $this->site_id
$token = $this->checkToken(); );
if ($token[ 'code' ] < 0) return $this->response($token); $result = $fenxiao_withdraw_model->getFenxiaoWithdrawDetail($params);
return $this->response($result);
$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 <?php
/** return [
// 自定义模板页面类型,格式:[ 'title' => '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据json格式' ]
'template' => [
// [
// 'title' => '分销市场',
// 'name' => 'DIY_FENXIAO_MARKET',
*/ // 'path' => '/pages_tool/index/diy?name=DIY_FENXIAO_MARKET',
return [ // 'value' => '',
// ]
// 自定义模板页面类型,格式:[ 'title' => '页面类型名称', 'name' => '页面标识', 'path' => '页面路径', 'value' => '页面数据json格式' ] ],
'template' => [
// [ // 后台自定义组件——装修
// 'title' => '分销市场', 'util' => [
// 'name' => 'DIY_FENXIAO_MARKET', // [
// 'path' => '/pages_tool/index/diy?name=DIY_FENXIAO_MARKET', // 'name' => 'FenxiaoGoodsList',
// 'value' => '', // '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',
'util' => [ // 'max_count' => 0,
// [ // 'icon' => 'iconfont iconfenxiaoshangpin'
// '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', 'link' => [
// 'support_diy_view' => 'DIY_FENXIAO_MARKET', [
// 'max_count' => 0, 'name' => 'DISTRIBUTION',
// 'icon' => 'iconfont iconfenxiaoshangpin' 'title' => '分销',
// ] 'parent' => 'MARKETING_LINK',
], 'wap_url' => '',
'web_url' => '',
// 自定义页面路径 'sort' => 2,
'link' => [ 'child_list' => [
[ [
'name' => 'DISTRIBUTION', 'name' => 'DISTRIBUTION_CENTRE',
'title' => '分销', 'title' => '分销中心',
'parent' => 'MARKETING_LINK', 'wap_url' => '/pages_promotion/fenxiao/index',
'wap_url' => '', 'web_url' => '',
'web_url' => '', 'sort' => 0
'sort' => 2, ],
'child_list' => [ [
[ 'name' => 'WITHDRAWAL_SUBSIDIARY',
'name' => 'DISTRIBUTION_CENTRE', 'title' => '提现明细',
'title' => '分销中心', 'wap_url' => '/pages_promotion/fenxiao/withdraw_list',
'wap_url' => '/pages_promotion/fenxiao/index', 'web_url' => '',
'web_url' => '', 'sort' => 0
'sort' => 0 ],
], [
[ 'name' => 'DISTRIBUTION_ORDER',
'name' => 'WITHDRAWAL_SUBSIDIARY', 'title' => '分销订单',
'title' => '提现明细', 'wap_url' => '/pages_promotion/fenxiao/order',
'wap_url' => '/pages_promotion/fenxiao/withdraw_list', 'web_url' => '',
'web_url' => '', 'sort' => 0
'sort' => 0 ],
], // [
[ // 'name' => 'DISTRIBUTION_MARKET',
'name' => 'DISTRIBUTION_ORDER', // 'title' => '分销市场',
'title' => '分销订单', // 'wap_url' => '/pages_tool/index/diy?name=DIY_FENXIAO_MARKET',
'wap_url' => '/pages_promotion/fenxiao/order', // 'web_url' => '',
'web_url' => '', // 'sort' => 0
'sort' => 0 // ],
], // [
// [ // 'name' => 'DISTRIBUTION_GOODS',
// 'name' => 'DISTRIBUTION_MARKET', // 'title' => '分销商品',
// 'title' => '分销市场', // 'wap_url' => '/pages_promotion/fenxiao/goods_list',
// 'wap_url' => '/pages_tool/index/diy?name=DIY_FENXIAO_MARKET', // 'web_url' => '',
// 'web_url' => '', // 'sort' => 0
// 'sort' => 0 // ],
// ], [
// [ 'name' => 'DISTRIBUTION_TEAM',
// 'name' => 'DISTRIBUTION_GOODS', 'title' => '分销团队',
// 'title' => '分销商品', 'wap_url' => '/pages_promotion/fenxiao/team',
// 'wap_url' => '/pages_promotion/fenxiao/goods_list', 'web_url' => '',
// 'web_url' => '', 'sort' => 0
// 'sort' => 0 ],
// ], [
[ 'name' => 'PROMOTION_POSTER',
'name' => 'DISTRIBUTION_TEAM', 'title' => '推广海报',
'title' => '分销团队', 'wap_url' => '/pages_promotion/fenxiao/promote_code',
'wap_url' => '/pages_promotion/fenxiao/team', 'web_url' => '',
'web_url' => '', 'sort' => 0
'sort' => 0 ],
], ]
[ ],
'name' => 'PROMOTION_POSTER', // [
'title' => '推广海报', // 'name' => 'DISTRIBUTION_GOODS',
'wap_url' => '/pages_promotion/fenxiao/promote_code', // 'title' => '分销商品',
'web_url' => '', // 'parent' => 'COMMODITY',
'sort' => 0 // 'wap_url' => '',
], // 'web_url' => '',
] // 'child_list' => []
], // ],
// [ ],
// 'name' => 'DISTRIBUTION_GOODS',
// 'title' => '分销商品', // 自定义图标库
// 'parent' => 'COMMODITY', 'icon_library' => [],
// 'wap_url' => '',
// 'web_url' => '', // uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ]多个逗号隔开自定义组件名称前缀必须是diy-,也可以引用第三方组件
// 'child_list' => [] 'component' => [],
// ],
], // uni-app 页面,多个逗号隔开
'pages' => [],
// 自定义图标库
'icon_library' => [], // 模板信息,格式:'title' => '模板名称', 'name' => '模板标识', 'cover' => '模板封面图', 'preview' => '模板预览图', 'desc' => '模板描述'
'info' => [],
// uni-app 组件,格式:[ 'name' => '组件名称/文件夹名称', 'path' => '文件路径/目录路径' ]多个逗号隔开自定义组件名称前缀必须是diy-,也可以引用第三方组件
'component' => [], // 主题风格配色格式可以自由定义扩展【在uni-app中通过this.themeStyle... 获取定义的颜色字段例如this.themeStyle.main_color】
'theme' => [],
// uni-app 页面,多个逗号隔开
'pages' => [], // 自定义页面数据,格式:[ 'title' => '页面名称', 'name' => "页面标识", 'value' => [页面数据json格式] ]
'data' => []
// 模板信息,格式:'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 <?php
/**
namespace addon\fenxiao\event;
/**
* 增加默认自定义数据:分销市场
*/
*/ class AddSiteDiyView
{
namespace addon\fenxiao\event; public function handle($param)
{
/** }
* 增加默认自定义数据:分销市场
*/
class AddSiteDiyView
{
public function handle($param)
{
}
} }

View File

@@ -1,56 +1,48 @@
<?php <?php
/**
namespace addon\fenxiao\event;
use addon\fenxiao\model\FenxiaoLevel as FenxiaoLevelModel;
/**
* 增加默认分销商等级
*/ */
class AddSiteFenxiaoLevel
namespace addon\fenxiao\event; {
use addon\fenxiao\model\FenxiaoLevel as FenxiaoLevelModel; public function handle($param)
{
/** if (!empty($param[ 'site_id' ])) {
* 增加默认分销商等级
*/ $model = new FenxiaoLevelModel();
class AddSiteFenxiaoLevel $default_level = $model->getLevelInfo([ [ 'site_id', '=', $param[ 'site_id' ] ], [ 'is_default', '=', 1 ] ], 'level_id');
{
if (empty($default_level[ 'data' ])) {
public function handle($param) $data = [
{ 'site_id' => $param[ 'site_id' ],
if (!empty($param[ 'site_id' ])) { 'level_name' => '默认等级',
'level_num' => 0,
$model = new FenxiaoLevelModel(); 'one_rate' => 10.00,
$default_level = $model->getLevelInfo([ [ 'site_id', '=', $param[ 'site_id' ] ], [ 'is_default', '=', 1 ] ], 'level_id'); 'two_rate' => 5.00,
'three_rate' => '',
if (empty($default_level[ 'data' ])) { 'upgrade_type' => '2',
$data = [ 'fenxiao_order_num' => '',
'site_id' => $param[ 'site_id' ], 'fenxiao_order_meney' => '',
'level_name' => '默认等级', 'one_fenxiao_order_num' => '',
'level_num' => 0, 'one_fenxiao_order_money' => '',
'one_rate' => 10.00, 'one_fenxiao_total_order' => '',
'two_rate' => 5.00, 'order_num' => '',
'three_rate' => '', 'order_money' => '',
'upgrade_type' => '2', 'child_num' => '',
'fenxiao_order_num' => '', 'child_fenxiao_num' => '',
'fenxiao_order_meney' => '', 'one_child_num' => '',
'one_fenxiao_order_num' => '', 'one_child_fenxiao_num' => '',
'one_fenxiao_order_money' => '', 'is_default' => 1
'one_fenxiao_total_order' => '', ];
'order_num' => '', $res = $model->addLevel($data);
'order_money' => '', return $res;
'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 <?php
/**
namespace addon\fenxiao\event;
use addon\fenxiao\model\Fenxiao as FenxiaoModel;
/**
* 活动展示
*/ */
class AlterShareRelation
namespace addon\fenxiao\event; {
/**
use addon\fenxiao\model\Fenxiao as FenxiaoModel; * 用户分销上下级关系
* @param $param
/** * @return array|void
* 活动展示 */
*/ public function handle($param)
class AlterShareRelation {
{ $fenxiao_model = new FenxiaoModel();
/** return $fenxiao_model->bindRelation([
* 用户分销上下级关系 'site_id' => $param[ 'site_id' ],
* @param $param 'member_id' => $param[ 'member_id' ],
* @return array|void 'action' => 'alter_share_relation',
*/ ]);
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 <?php
/**
namespace addon\fenxiao\event;
use addon\fenxiao\model\Fenxiao;
/**
* 分销商升级
*/ */
class FenxiaoUpgrade
namespace addon\fenxiao\event; {
/**
use addon\fenxiao\model\Fenxiao; * 分销商升级
* @param $fenxiao_id
/** */
* 分销商升级 public function handle($fenxiao_id)
*/ {
class FenxiaoUpgrade if (!empty($fenxiao_id)) {
{ $fenxiao = new Fenxiao();
/** $fenxiao->fenxiaoUpgrade($fenxiao_id);
* 分销商升级 }
* @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 <?php
/**
namespace addon\fenxiao\event;
use app\model\goods\Goods as GoodsModel;
/**
* 商品分类
*/ */
class GoodsListCategoryIds
namespace addon\fenxiao\event; {
use app\model\goods\Goods as GoodsModel; /**
* 商品营销活动信息
/** * @param $param
* 商品分类 * @return array
*/ */
class GoodsListCategoryIds public function handle($param)
{ {
if (empty($param[ 'promotion' ]) || $param[ 'promotion' ] != 'fenxiao') return [];
/**
* 商品营销活动信息 $condition = [
* @param $param [ 'is_delete', '=', 0 ],
* @return array [ 'site_id', '=', $param[ 'site_id' ] ],
*/ [ 'is_fenxiao', '=', 1 ],
public function handle($param) [ 'goods_state', '=', 1 ]
{ ];
if (empty($param[ 'promotion' ]) || $param[ 'promotion' ] != 'fenxiao') return [];
$model = new GoodsModel();
$condition = [ $res = $model->getGoodsCategoryIds($condition);
[ 'is_delete', '=', 0 ], return $res;
[ '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 <?php
/**
namespace addon\fenxiao\event;
use app\model\goods\Goods as GoodsModel;
/**
* 商品营销活动信息
*/ */
class GoodsListPromotion
namespace addon\fenxiao\event; {
use app\model\goods\Goods as GoodsModel; /**
* 商品营销活动信息
/** * @param $param
* 商品营销活动信息 * @return array
*/ */
class GoodsListPromotion public function handle($param)
{ {
if (empty($param[ 'promotion' ]) || $param[ 'promotion' ] != 'fenxiao') return [];
/**
* 商品营销活动信息 $alias = 'g';
* @param $param $join = [];
* @return array
*/ $condition = [
public function handle($param) [ 'g.is_delete', '=', 0 ],
{ [ 'g.site_id', '=', $param[ 'site_id' ] ],
if (empty($param[ 'promotion' ]) || $param[ 'promotion' ] != 'fenxiao') return []; [ 'g.is_fenxiao', '=', 1 ],
[ 'g.goods_state', '=', 1 ]
$alias = 'g'; ];
$join = [];
if (!empty($param[ 'goods_name' ])) {
$condition = [ $condition[] = [ 'g.goods_name', 'like', '%' . $param[ 'goods_name' ] . '%' ];
[ 'g.is_delete', '=', 0 ], }
[ 'g.site_id', '=', $param[ 'site_id' ] ], if (!empty($param[ 'select_type' ]) && $param[ 'select_type' ] == 'selected' && isset($param[ 'goods_ids' ])) {
[ 'g.is_fenxiao', '=', 1 ], $condition[] = [ 'g.goods_id', 'in', $param[ 'goods_ids' ] ];
[ 'g.goods_state', '=', 1 ] }
]; if (!empty($param[ 'category_id' ])) {
$condition[] = [ 'g.category_id', 'like', '%,' . $param[ 'category_id' ] . ',%' ];
if (!empty($param[ 'goods_name' ])) { }
$condition[] = [ 'g.goods_name', 'like', '%' . $param[ 'goods_name' ] . '%' ]; if (!empty($param[ 'label_id' ])) {
} $condition[] = [ 'g.label_id', '=', $param[ 'label_id' ] ];
if (!empty($param[ 'select_type' ]) && $param[ 'select_type' ] == 'selected' && isset($param[ 'goods_ids' ])) { }
$condition[] = [ 'g.goods_id', 'in', $param[ 'goods_ids' ] ]; if (!empty($param[ 'goods_class' ])) {
} $condition[] = [ 'g.goods_class', '=', $param[ 'goods_class' ] ];
if (!empty($param[ 'category_id' ])) { }
$condition[] = [ 'g.category_id', 'like', '%,' . $param[ 'category_id' ] . ',%' ];
} $model = new GoodsModel();
if (!empty($param[ 'label_id' ])) { $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';
$condition[] = [ 'g.label_id', '=', $param[ 'label_id' ] ]; $list = $model->getGoodsPageList($condition, $param[ 'page' ], $param[ 'page_size' ], 'g.create_time desc', $field, $alias, $join);
} return $list;
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 <?php
/**
namespace addon\fenxiao\event;
use addon\fenxiao\model\FenxiaoLevel as FenxiaoLevelModel;
/**
* 应用安装
*/ */
class Install
namespace addon\fenxiao\event; {
/**
use addon\fenxiao\model\FenxiaoLevel as FenxiaoLevelModel; * 执行安装
*/
/** public function handle()
* 应用安装 {
*/ $site_id = request()->siteid();
class Install $model = new FenxiaoLevelModel();
{ $default_level = $model->getLevelInfo([ [ 'site_id', '=', $site_id ], [ 'is_default', '=', 1 ] ], 'level_id');
/**
* 执行安装 if (empty($default_level[ 'data' ])) {
*/ $data = [
public function handle() 'site_id' => $site_id,
{ 'level_name' => '默认等级',
$site_id = request()->siteid(); 'level_num' => 0,
$model = new FenxiaoLevelModel(); 'one_rate' => '',
$default_level = $model->getLevelInfo([ [ 'site_id', '=', $site_id ], [ 'is_default', '=', 1 ] ], 'level_id'); 'two_rate' => '',
'three_rate' => '',
if (empty($default_level[ 'data' ])) { 'upgrade_type' => '2',
$data = [ 'fenxiao_order_num' => '',
'site_id' => $site_id, 'fenxiao_order_meney' => '',
'level_name' => '默认等级', 'one_fenxiao_order_num' => '',
'level_num' => 0, 'one_fenxiao_order_money' => '',
'one_rate' => '', 'one_fenxiao_total_order' => '',
'two_rate' => '', 'order_num' => '',
'three_rate' => '', 'order_money' => '',
'upgrade_type' => '2', 'child_num' => '',
'fenxiao_order_num' => '', 'child_fenxiao_num' => '',
'fenxiao_order_meney' => '', 'one_child_num' => '',
'one_fenxiao_order_num' => '', 'one_child_fenxiao_num' => '',
'one_fenxiao_order_money' => '', 'is_default' => 1
'one_fenxiao_total_order' => '', ];
'order_num' => '', $res = $model->addLevel($data);
'order_money' => '', return $res;
'child_num' => '', }
'child_fenxiao_num' => '',
'one_child_num' => '', return success();
'one_child_fenxiao_num' => '', }
'is_default' => 1
];
$res = $model->addLevel($data);
return $res;
}
return success();
}
} }

View File

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

View File

@@ -1,31 +1,23 @@
<?php <?php
/**
namespace addon\fenxiao\event;
use addon\fenxiao\model\Fenxiao;
/**
* 会员注销
*/ */
class MemberCancel
namespace addon\fenxiao\event; {
use addon\fenxiao\model\Fenxiao; /**
* @param $param
/** * @return array
* 会员注销 */
*/ public function handle($param)
class MemberCancel {
{ $fenxiao_model = new Fenxiao();
$res = $fenxiao_model->CronMemberCancel($param[ 'member_id' ], $param[ 'site_id' ]);
/** return $res;
* @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 <?php
/**
namespace addon\fenxiao\event;
use addon\fenxiao\model\Fenxiao;
/**
* 活动展示
*/
*/ class MemberRegister
{
namespace addon\fenxiao\event; /**
* 会员注册
use addon\fenxiao\model\Fenxiao; * @param $param
*/
/** public function handle($param)
* 活动展示 {
*/ if (isset($param['member_id']) && !empty($param['member_id'])) {
class MemberRegister $fenxiao = new Fenxiao();
{ $fenxiao->memberRegister($param['member_id'], $param['site_id']);
/** }
* 会员注册 }
* @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 <?php
/**
namespace addon\fenxiao\event;
use addon\fenxiao\model\Fenxiao as FenxiaoModel;
use app\model\order\OrderCommon;
/**
*/ * 订单完成事件
*/
namespace addon\fenxiao\event; class OrderComplete
{
use addon\fenxiao\model\Fenxiao as FenxiaoModel; /**
use app\model\order\OrderCommon; * 订单创建后绑定上下线关系
* @param $param
/** */
* 订单完成事件 public function handle($param)
*/ {
class OrderComplete $order_id = $param[ 'order_id' ];
{ $order_model = new OrderCommon();
/** $order_info = $order_model->getOrderInfo([ [ 'order_id', '=', $order_id ] ])[ 'data' ];
* 订单创建后绑定上下线关系 if (!empty($order_info)) {
* @param $param $fenxiao_model = new FenxiaoModel();
*/ $fenxiao_model->autoBecomeFenxiao($order_info[ 'member_id' ], $order_info[ 'site_id' ]);
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 <?php
/**
namespace addon\fenxiao\event;
use addon\fenxiao\model\Fenxiao as FenxiaoModel;
use app\model\order\OrderCommon;
/**
*/ * 订单创建事件
*/
namespace addon\fenxiao\event; class OrderCreateAfter
{
use addon\fenxiao\model\Fenxiao as FenxiaoModel; /**
use app\model\order\OrderCommon; * 订单创建后绑定上下线关系
* @param $param
/** * @return array|void
* 订单创建事件 */
*/ public function handle($param)
class OrderCreateAfter {
{ $order_info = $param['create_data'] ?? [];
/** if (!empty($order_info)) {
* 订单创建后绑定上下线关系 $fenxiao_model = new FenxiaoModel();
* @param $param return $fenxiao_model->bindRelation([
* @return array|void 'site_id' => $order_info[ 'site_id' ],
*/ 'member_id' => $order_info[ 'member_id' ],
public function handle($param) 'action' => 'order_create',
{ ]);
$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 <?php
/**
namespace addon\fenxiao\event;
use addon\fenxiao\model\FenxiaoOrder;
/**
* 活动类型
*/ */
class OrderGoodsRefund
namespace addon\fenxiao\event; {
use addon\fenxiao\model\FenxiaoOrder; /**
* 活动类型
/** * @param $data
* 活动类型 * @return array
*/ */
class OrderGoodsRefund public function handle($data)
{ {
$order_model = new FenxiaoOrder();
/** $res = $order_model->refund($data);
* 活动类型 return $res;
* @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 <?php
/**
namespace addon\fenxiao\event;
use addon\fenxiao\model\FenxiaoOrder;
use addon\fenxiao\model\Fenxiao as FenxiaoModel;
use think\facade\Log;
/**
*/ * 活动展示
*/
namespace addon\fenxiao\event; class OrderPayAfter
{
use addon\fenxiao\model\FenxiaoOrder;
use addon\fenxiao\model\Fenxiao as FenxiaoModel; /**
use think\facade\Log; * 订单结算
*/
/** public function handle($order)
* 活动展示 {
*/ //先检测是否需要绑定上下线
class OrderPayAfter $fenxiao_model = new FenxiaoModel();
{ $fenxiao_model->bindRelation([
'site_id' => $order['site_id'],
/** 'member_id' => $order['member_id'],
* 订单结算 'action' => 'order_pay',
*/ ]);
public function handle($order)
{ // 自动成为分销商
//先检测是否需要绑定上下线 $fenxiao_model->autoBecomeFenxiao($order['member_id'], $order['site_id']);
$fenxiao_model = new FenxiaoModel();
$fenxiao_model->bindRelation([ $fenxiao_order = new FenxiaoOrder();
'site_id' => $order['site_id'], return $fenxiao_order->calculate($order);
'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 <?php
/**
namespace addon\fenxiao\event;
use addon\fenxiao\model\FenxiaoOrder;
/**
* 活动类型
*/
*/ class OrderSettlement
{
namespace addon\fenxiao\event;
/**
use addon\fenxiao\model\FenxiaoOrder; * 活动类型
* @param $data
/** * @return array
* 活动类型 */
*/ public function handle($data)
class OrderSettlement {
{ $fenxiao_order_model = new FenxiaoOrder();
$fenxiao_order_model->settlement($data['order_id']);
/** $res = $fenxiao_order_model->calculateOrder($data['order_id']);
* 活动类型 return $res;
* @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 <?php
/**
namespace addon\fenxiao\event;
use addon\fenxiao\model\Fenxiao as FenxiaoModel;
use addon\presale\model\PresaleOrder;
/**
*/ * 预售订单创建
*/
namespace addon\fenxiao\event; class PresaleOrderCreate
{
use addon\fenxiao\model\Fenxiao as FenxiaoModel; /**
use addon\presale\model\PresaleOrder; * 订单创建后绑定上下线关系
* @param $param
/** * @return array|void
* 预售订单创建 */
*/ public function handle($param)
class PresaleOrderCreate {
{ $id = $param[ 'id' ];
/** $order_model = new PresaleOrder();
* 订单创建后绑定上下线关系 $order_info = $order_model->getPresaleOrderInfo([ [ 'id', '=', $id ] ])[ 'data' ];
* @param $param if (!empty($order_info)) {
* @return array|void $fenxiao_model = new FenxiaoModel();
*/ return $fenxiao_model->bindRelation([
public function handle($param) 'site_id' => $order_info[ 'site_id' ],
{ 'member_id' => $order_info[ 'member_id' ],
$id = $param[ 'id' ]; 'action' => 'order_create',
$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 <?php
/**
namespace addon\fenxiao\event;
/**
* 活动类型
*/
class PromotionType
*/ {
/**
namespace addon\fenxiao\event; * 活动类型
* @return array
/** */
* 活动类型 public function handle()
*/ {
class PromotionType return [ "name" => "分销", "type" => "fenxiao" ];
{ }
/**
* 活动类型
* @return array
*/
public function handle()
{
return [ "name" => "分销", "type" => "fenxiao" ];
}
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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