初始上传
This commit is contained in:
337
addon/fenxiao/model/Config.php
Executable file
337
addon/fenxiao/model/Config.php
Executable file
@@ -0,0 +1,337 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\fenxiao\model;
|
||||
|
||||
use app\model\system\Config as ConfigModel;
|
||||
use app\model\BaseModel;
|
||||
use app\model\system\Document;
|
||||
|
||||
|
||||
/**
|
||||
* 微信小程序配置
|
||||
*/
|
||||
class Config extends BaseModel
|
||||
{
|
||||
/******************************************************************** 分销基本配置 start ****************************************************************************/
|
||||
/**
|
||||
* 设置分销基本配置
|
||||
* @param $data
|
||||
* @param $is_use
|
||||
* @param $site_id
|
||||
* @return array
|
||||
*/
|
||||
public function setFenxiaoBasicsConfig($data, $is_use, $site_id)
|
||||
{
|
||||
$config = new ConfigModel();
|
||||
|
||||
//分销基本设置
|
||||
$basics_data = [
|
||||
'level' => $data[ 'level' ],//分销层级
|
||||
'internal_buy' => $data[ 'internal_buy' ],//分销内购
|
||||
'is_examine' => $data[ 'is_examine' ],//是否需要审核
|
||||
'self_purchase_rebate' => $data[ 'self_purchase_rebate' ],//是否开启分销商自购返佣
|
||||
'is_apply' => $data[ 'is_apply' ],//是否开启分销申请
|
||||
'is_commission_money' => $data[ 'is_commission_money' ],//是否开启商品详情一级佣金
|
||||
];
|
||||
$config->setConfig($basics_data, '分销基本配置', $is_use, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_BASICS_CONFIG' ] ]);
|
||||
//分销商设置
|
||||
$fenxiao_data = [
|
||||
'fenxiao_condition' => $data[ 'fenxiao_condition' ],//成为分销商条件(0无条件 1申请 2消费次数 3消费金额 4购买商品)
|
||||
'consume_count' => $data[ 'consume_count' ],//消费次数
|
||||
'consume_money' => $data[ 'consume_money' ],//消费金额
|
||||
'goods_ids' => $data[ 'goods_ids' ],//指定商品id
|
||||
'consume_condition' => $data[ 'consume_condition' ],//消费条件(1付款后 2订单完成)
|
||||
'perfect_info' => $data[ 'perfect_info' ],//完善资料
|
||||
];
|
||||
$config->setConfig($fenxiao_data, '分销商配置', $is_use, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_CONFIG' ] ]);
|
||||
// 分销默认等级佣金比率
|
||||
( new FenxiaoLevel() )->editLevel([
|
||||
'one_rate' => $data[ 'one_rate' ],
|
||||
'two_rate' => $data[ 'two_rate' ],
|
||||
'three_rate' => $data[ 'three_rate' ]
|
||||
], [ [ 'site_id', '=', $site_id ], [ 'is_default', '=', 1 ] ]);
|
||||
//上下级关系
|
||||
$relation_data = [
|
||||
'child_condition' => $data[ 'child_condition' ],//成为下线条件
|
||||
];
|
||||
$res = $config->setConfig($relation_data, '分销上下级关系配置', $is_use, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_RELATION_CONFIG' ] ]);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分销基本设置
|
||||
* @param $site_id
|
||||
* @return array
|
||||
*/
|
||||
public function getFenxiaoBasicsConfig($site_id)
|
||||
{
|
||||
$config = new ConfigModel();
|
||||
$res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_BASICS_CONFIG' ] ]);
|
||||
|
||||
if (empty($res[ 'data' ][ 'value' ])) {
|
||||
$res[ 'data' ][ 'value' ] = [
|
||||
'level' => 2,//分销层级
|
||||
'internal_buy' => 0,//分销内购
|
||||
'is_examine' => 0,//是否需要审核
|
||||
'is_apply' => 0,//分销商申请方式
|
||||
'is_commission_money' => 1,//是否开启商品详情一级佣金
|
||||
];
|
||||
}
|
||||
$res[ 'data' ][ 'value' ][ 'is_commission_money' ] = $res[ 'data' ][ 'value' ][ 'is_commission_money' ] ?? 1;
|
||||
$res[ 'data' ][ 'value' ][ 'self_purchase_rebate' ] = $res[ 'data' ][ 'value' ][ 'self_purchase_rebate' ] ?? 1;
|
||||
$res[ 'data' ][ 'value' ][ 'is_apply' ] = $res[ 'data' ][ 'value' ][ 'is_apply' ] ?? 1;
|
||||
$res[ 'data' ][ 'value' ][ 'level' ] = $res[ 'data' ][ 'value' ][ 'level' ] == 3 ? 2 : $res[ 'data' ][ 'value' ][ 'level' ];
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分销商设置
|
||||
* @param $site_id
|
||||
* @return array
|
||||
*/
|
||||
public function getFenxiaoConfig($site_id)
|
||||
{
|
||||
$config = new ConfigModel();
|
||||
$res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_CONFIG' ] ]);
|
||||
if (empty($res[ 'data' ][ 'value' ])) {
|
||||
$res[ 'data' ][ 'value' ] = [
|
||||
'fenxiao_condition' => 0,//成为分销商条件(0无条件 2消费次数 3消费金额 4购买商品)
|
||||
'is_agreement' => 0,//显示申请协议
|
||||
'agreement_title' => '',//协议标题
|
||||
'agreement_content' => '',//协议内容
|
||||
'consume_count' => 0,//消费次数
|
||||
'consume_money' => 0,//消费次数
|
||||
'consume_condition' => 1,//消费条件(1付款后 2订单完成)
|
||||
'img' => '',//申请页面顶部图片
|
||||
'perfect_info' => '',//完善资料
|
||||
];
|
||||
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取上下级关系
|
||||
* @param $site_id
|
||||
* @return array
|
||||
*/
|
||||
public function getFenxiaoRelationConfig($site_id)
|
||||
{
|
||||
$config = new ConfigModel();
|
||||
$res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_RELATION_CONFIG' ] ]);
|
||||
if (empty($res[ 'data' ][ 'value' ])) {
|
||||
$res[ 'data' ][ 'value' ] = [
|
||||
'child_condition' => 1,//成为下线条件 1:首次点击分享链接 2:首次下单 3:首次付款
|
||||
];
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
/******************************************************************** 分销基本配置 end ****************************************************************************/
|
||||
|
||||
/******************************************************************** 分销协议配置 start ****************************************************************************/
|
||||
|
||||
/**
|
||||
* 设置分销协议配置
|
||||
* @param $data
|
||||
* @param $is_use
|
||||
* @param $site_id
|
||||
* @return array
|
||||
*/
|
||||
public function setFenxiaoAgreementConfig($data, $is_use, $site_id)
|
||||
{
|
||||
$config = new ConfigModel();
|
||||
|
||||
$agreement_config = [
|
||||
'is_agreement' => $data[ 'is_agreement' ],//是否显示申请协议
|
||||
'img' => $data[ 'img' ],//申请页面顶部图片
|
||||
];
|
||||
$res = $config->setConfig($agreement_config, '分销协议配置', $is_use, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_AGREEMENT_CONFIG' ] ]);
|
||||
|
||||
$document = new Document();
|
||||
$document->setDocument($data[ 'agreement_title' ], $data[ 'agreement_content' ], [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'document_key', '=', "FENXIAO_AGREEMENT" ] ]);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分销协议配置
|
||||
* @param $site_id
|
||||
* @return array
|
||||
*/
|
||||
public function getFenxiaoAgreementConfig($site_id)
|
||||
{
|
||||
$config = new ConfigModel();
|
||||
$res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_AGREEMENT_CONFIG' ] ]);
|
||||
if (empty($res[ 'data' ][ 'value' ])) {
|
||||
$res[ 'data' ][ 'value' ] = [
|
||||
'is_agreement' => 0,//显示申请协议
|
||||
'img' => 'public/static/img/fenxiao/apply_top_gg.png',//申请页面顶部图片
|
||||
];
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
/******************************************************************** 分销协议配置 end ****************************************************************************/
|
||||
|
||||
|
||||
/******************************************************************** 分销结算配置 start ****************************************************************************/
|
||||
|
||||
/**
|
||||
* 设置分销结算配置
|
||||
* @param $data
|
||||
* @param $is_use
|
||||
* @param $site_id
|
||||
* @return array
|
||||
*/
|
||||
public function setFenxiaoSettlementConfig($data, $is_use, $site_id)
|
||||
{
|
||||
|
||||
$config = new ConfigModel();
|
||||
//分销商结算配置
|
||||
$settlement_data = [
|
||||
'account_type' => $data[ 'account_type' ],//佣金计算方式
|
||||
];
|
||||
|
||||
$config->setConfig($settlement_data, '分销结算配置', $is_use, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_SETTLEMENT_CONFIG' ] ]);
|
||||
//分销商提现配置
|
||||
$withdraw_data = [
|
||||
'withdraw' => $data[ 'withdraw' ],//最低提现额度
|
||||
'withdraw_rate' => $data[ 'withdraw_rate' ],//佣金提现手续费
|
||||
// 'min_no_fee' => $data['min_no_fee'],//最低免手续费区间
|
||||
// 'max_no_fee' => $data['max_no_fee'],//最高免手续费区间
|
||||
'withdraw_status' => $data[ 'withdraw_status' ],//提现审核
|
||||
'settlement_day' => $data[ 'settlement_day' ],//天数
|
||||
'withdraw_type' => $data[ 'withdraw_type' ],//账户类型 alipay 支付宝 bank 银行卡
|
||||
|
||||
'transfer_type' => $data[ 'transfer_type' ],//提现方式
|
||||
'max' => $data[ 'max' ],//提现方式
|
||||
'is_auto_transfer' => $data[ 'is_auto_transfer' ], // 是否自动转账 1 手动转账 2 自动转账
|
||||
];
|
||||
|
||||
$res = $config->setConfig($withdraw_data, '分销提现配置', $is_use, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_WITHDRAW_CONFIG' ] ]);
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分销商结算配置
|
||||
* @param $site_id
|
||||
* @return array
|
||||
*/
|
||||
public function getFenxiaoSettlementConfig($site_id)
|
||||
{
|
||||
$config = new ConfigModel();
|
||||
$res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_SETTLEMENT_CONFIG' ] ]);
|
||||
if (empty($res[ 'data' ][ 'value' ])) {
|
||||
$res[ 'data' ][ 'value' ] = [
|
||||
'account_type' => 0
|
||||
];
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分销商提现配置
|
||||
* @param $site_id
|
||||
* @return array
|
||||
*/
|
||||
public function getFenxiaoWithdrawConfig($site_id)
|
||||
{
|
||||
$config = new ConfigModel();
|
||||
$res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_WITHDRAW_CONFIG' ] ]);
|
||||
if (empty($res[ 'data' ][ 'value' ])) {
|
||||
$res[ 'data' ][ 'value' ] = [
|
||||
'withdraw' => 0,//最低提现额度
|
||||
'withdraw_rate' => 0,//佣金提现手续费
|
||||
'min_no_fee' => 0,//最低免手续费区间
|
||||
'max_no_fee' => 0,//最高免手续费区间
|
||||
'withdraw_status' => 1,//提现审核
|
||||
'withdraw_type' => 0,//提现方式
|
||||
'is_auto_transfer' => 0,
|
||||
'transfer_type' => '',
|
||||
'max' => 0
|
||||
];
|
||||
}
|
||||
$value = $res[ 'data' ][ 'value' ];
|
||||
if (!isset($value[ 'transfer_type' ])) {
|
||||
$value[ 'transfer_type' ] = 'balance';
|
||||
}
|
||||
if (!isset($value[ 'max' ])) {
|
||||
$value[ 'max' ] = 0;
|
||||
}
|
||||
if (!isset($value[ 'is_auto_transfer' ])) {
|
||||
$value[ 'is_auto_transfer' ] = 0;
|
||||
}
|
||||
$res[ 'data' ][ 'value' ] = $value;
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转账方式
|
||||
* @param int $site_id
|
||||
* @return array
|
||||
*/
|
||||
public function getTransferType($site_id = 0)
|
||||
{
|
||||
$fenxiao_withdraw_model = new FenxiaoWithdraw();
|
||||
$transfer_type_list = $fenxiao_withdraw_model->getTransferType($site_id);
|
||||
$config = $this->getFenxiaoWithdrawConfig($site_id)[ "data" ][ 'value' ] ?? [];
|
||||
$data = [];
|
||||
$support_type = explode(",", $config[ "transfer_type" ]);
|
||||
foreach ($transfer_type_list as $k => $v) {
|
||||
if (in_array($k, $support_type)) {
|
||||
$data[ $k ] = $v;
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
/******************************************************************** 分销结算配置 end ****************************************************************************/
|
||||
|
||||
/******************************************************************** 分销文字配置 start ****************************************************************************/
|
||||
|
||||
/**
|
||||
* 设置分销文字配置
|
||||
* @param $data
|
||||
* @param $is_use
|
||||
* @param $site_id
|
||||
* @return array
|
||||
*/
|
||||
public function setFenxiaoWordsConfig($data, $is_use, $site_id)
|
||||
{
|
||||
$config = new ConfigModel();
|
||||
$res = $config->setConfig($data, '分销文字配置', $is_use, [ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_WORDS_CONFIG' ] ]);
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分销文字配置
|
||||
* @param $site_id
|
||||
* @return array
|
||||
*/
|
||||
public function getFenxiaoWordsConfig($site_id)
|
||||
{
|
||||
$config = new ConfigModel();
|
||||
$res = $config->getConfig([ [ 'site_id', '=', $site_id ], [ 'app_module', '=', 'shop' ], [ 'config_key', '=', 'FENXIAO_WORDS_CONFIG' ] ]);
|
||||
if (empty($res[ 'data' ][ 'value' ])) {
|
||||
$res[ 'data' ][ 'value' ] = [
|
||||
'concept' => '分销',// 分销概念
|
||||
'fenxiao_name' => '分销商',// 分销商名称
|
||||
'withdraw' => '提现',// 提现名称
|
||||
'account' => '佣金',// 佣金
|
||||
'my_team' => '团队',// 我的团队
|
||||
'child' => '下线',// 下线
|
||||
];
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
/******************************************************************** 分销文字配置 end ****************************************************************************/
|
||||
|
||||
}
|
||||
826
addon/fenxiao/model/Fenxiao.php
Executable file
826
addon/fenxiao/model/Fenxiao.php
Executable file
@@ -0,0 +1,826 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\fenxiao\model;
|
||||
|
||||
use addon\fenxiao\model\Config as ConfigModel;
|
||||
use app\model\BaseModel;
|
||||
use app\model\member\Member;
|
||||
use app\model\order\OrderCommon;
|
||||
use app\model\system\Stat;
|
||||
|
||||
/**
|
||||
* 分销
|
||||
*/
|
||||
class Fenxiao extends BaseModel
|
||||
{
|
||||
|
||||
public $fenxiao_status_zh = [
|
||||
1 => '正常',
|
||||
-1 => '冻结',
|
||||
];
|
||||
|
||||
/**
|
||||
* 添加分销商
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function addFenxiao($data)
|
||||
{
|
||||
$fenxiao_info = model('fenxiao')->getInfo(
|
||||
[ [ 'member_id', '=', $data[ 'member_id' ] ], [ 'is_delete', '=', 0 ] ],
|
||||
'fenxiao_id'
|
||||
);
|
||||
if (!empty($fenxiao_info)) return $this->error('', '已经是分销商了');
|
||||
|
||||
$data[ 'fenxiao_no' ] = date('YmdHi') . rand(1000, 9999);
|
||||
$data[ 'create_time' ] = time();
|
||||
$data[ 'audit_time' ] = time();
|
||||
|
||||
model('fenxiao')->startTrans();
|
||||
try {
|
||||
|
||||
if (!empty($data[ 'parent' ])) {
|
||||
//添加上级分销商一级下线人数
|
||||
model('fenxiao')->setInc([ [ 'fenxiao_id', '=', $data[ 'parent' ] ], [ 'is_delete', '=', 0 ] ], 'one_child_fenxiao_num');
|
||||
//获取上上级分销商id
|
||||
$grand_parent_id = model('fenxiao')->getInfo([ [ 'fenxiao_id', '=', $data[ 'parent' ] ], [ 'is_delete', '=', 0 ] ], 'parent');
|
||||
|
||||
if (!empty($grand_parent_id) && $grand_parent_id[ 'parent' ] != 0) {
|
||||
//添加上上级分销商二级下线人数
|
||||
model('fenxiao')->setInc([ [ 'fenxiao_id', '=', $grand_parent_id[ 'parent' ] ] ], 'two_child_fenxiao_num');
|
||||
|
||||
$data[ 'grand_parent' ] = $grand_parent_id[ 'parent' ];
|
||||
}
|
||||
|
||||
// 分销商检测升级
|
||||
event('FenxiaoUpgrade', $data[ 'parent' ]);
|
||||
}
|
||||
|
||||
$res = model('fenxiao')->add($data);
|
||||
//修改会员信息
|
||||
model('member')->update([ 'fenxiao_id' => $res, 'is_fenxiao' => 1 ], [ [ 'member_id', '=', $data[ 'member_id' ] ] ]);
|
||||
|
||||
$stat_model = new Stat();
|
||||
$stat_model->switchStat([ 'type' => 'add_fenxiao_member', 'data' => [ 'site_id' => $data[ 'site_id' ] ] ]);
|
||||
|
||||
model('fenxiao')->commit();
|
||||
return $this->success($res);
|
||||
} catch (\Exception $e) {
|
||||
model('fenxiao')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 冻结
|
||||
* @param $fenxiao_id
|
||||
* @return array
|
||||
*/
|
||||
public function frozen($fenxiao_id)
|
||||
{
|
||||
$data = [
|
||||
'status' => -1,
|
||||
'lock_time' => time()
|
||||
];
|
||||
|
||||
$res = model('fenxiao')->update($data, [ [ 'fenxiao_id', '=', $fenxiao_id ] ]);
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 解冻
|
||||
* @param $fenxiao_id
|
||||
* @return array
|
||||
*/
|
||||
public function unfrozen($fenxiao_id)
|
||||
{
|
||||
$data = [
|
||||
'status' => 1,
|
||||
'lock_time' => time()
|
||||
];
|
||||
|
||||
$res = model('fenxiao')->update($data, [ [ 'fenxiao_id', '=', $fenxiao_id ] ]);
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分销商详细信息
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public function getFenxiaoInfo($condition = [], $field = '*')
|
||||
{
|
||||
$condition[] = [ 'is_delete', '=', 0 ];
|
||||
$res = model('fenxiao')->getInfo($condition, $field);
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分销商详细信息
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public function getFenxiaoDetailInfo($condition = [])
|
||||
{
|
||||
$condition[] = [ 'f.is_delete', '=', 0 ];
|
||||
|
||||
$field = 'f.*,pf.fenxiao_name as parent_name,nm.username,nm.nickname,nm.headimg,nm.order_num,nm.order_money,fl.level_num';
|
||||
$alias = 'f';
|
||||
$join = [
|
||||
[
|
||||
'fenxiao pf',
|
||||
'pf.fenxiao_id = f.parent',
|
||||
'left'
|
||||
],
|
||||
[
|
||||
'member nm',
|
||||
'nm.member_id = f.member_id',
|
||||
'left'
|
||||
],
|
||||
[
|
||||
'fenxiao_level fl',
|
||||
'f.level_id = fl.level_id',
|
||||
'left'
|
||||
]
|
||||
];
|
||||
$res = model('fenxiao')->getInfo($condition, $field, $alias, $join);
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取分销列表
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
* @param string $order
|
||||
* @param null $limit
|
||||
* @return array
|
||||
*/
|
||||
public function getFenxiaoList($condition = [], $field = '*', $order = '', $limit = null)
|
||||
{
|
||||
$condition[] = [ 'is_delete', '=', 0 ];
|
||||
$list = model('fenxiao')->getList($condition, $field, $order, '', '', '', $limit);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分销分页列表
|
||||
* @param array $condition
|
||||
* @param int $page
|
||||
* @param int $page_size
|
||||
* @param string $order
|
||||
* @return array
|
||||
*/
|
||||
public function getFenxiaoPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $site_id = 0)
|
||||
{
|
||||
$condition[] = [ 'f.is_delete', '=', 0 ];
|
||||
$field = 'f.*,pf.fenxiao_name as parent_name,m.username,m.nickname,m.mobile as member_mobile,m.headimg';
|
||||
$alias = 'f';
|
||||
$join = [
|
||||
[
|
||||
'fenxiao pf',
|
||||
'pf.fenxiao_id = f.parent',
|
||||
'left'
|
||||
],
|
||||
[
|
||||
'member m',
|
||||
'm.member_id = f.member_id',
|
||||
'left'
|
||||
]
|
||||
];
|
||||
$list = model('fenxiao')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
|
||||
$id_array = [];
|
||||
foreach ($list[ 'list' ] as $k => $v) {
|
||||
$id_array[] = $v['fenxiao_id'];
|
||||
}
|
||||
|
||||
// 查询分销基础配置
|
||||
$config_model = new Config();
|
||||
$fenxiao_basic_config = $config_model->getFenxiaoBasicsConfig($site_id)[ 'data' ][ 'value' ];
|
||||
$level = $fenxiao_basic_config[ 'level' ];
|
||||
|
||||
switch ( $level ) {
|
||||
case 1:
|
||||
$member_array = [];
|
||||
$member_count_array = model('member')->getList([['fenxiao_id', 'in', $id_array]], 'count(*) as count, fenxiao_id', '', '', '', 'fenxiao_id');
|
||||
if (!empty($member_count_array)){
|
||||
$member_key = array_column($member_count_array, 'fenxiao_id');
|
||||
$member_array = array_combine($member_key, $member_count_array);
|
||||
}
|
||||
|
||||
foreach ($list[ 'list' ] as $k => $v) {
|
||||
$count = 0;
|
||||
if(isset($member_array[ $v['fenxiao_id'] ])) $count = $member_array[ $v['fenxiao_id'] ][ 'count' ];
|
||||
$list[ 'list' ][ $k ][ 'team_num' ] = $count;
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
|
||||
$team_array = [];
|
||||
$team_list_array = model('fenxiao')->getList([[ 'parent', 'in', $id_array]], 'fenxiao_id, parent');
|
||||
|
||||
if(!empty($team_list_array)){
|
||||
$team_id_array = [];
|
||||
foreach ($team_list_array as $team_k => $team_v) {
|
||||
$team_id_array[] = $team_v['fenxiao_id'];
|
||||
$team_array[$team_v['parent']][] = $team_v;
|
||||
}
|
||||
$id_array = array_merge($id_array, $team_id_array);
|
||||
}
|
||||
|
||||
$member_array = [];
|
||||
$member_count_array = model('member')->getList([['fenxiao_id', 'in', $id_array]], 'count(*) as count, fenxiao_id', '', '', '', 'fenxiao_id');
|
||||
if (!empty($member_count_array)){
|
||||
$member_key = array_column($member_count_array, 'fenxiao_id');
|
||||
$member_array = array_combine($member_key, $member_count_array);
|
||||
}
|
||||
|
||||
foreach ($list[ 'list' ] as $k => $v) {
|
||||
$count = 0;
|
||||
$num = 0;
|
||||
if(isset($member_array[ $v['fenxiao_id'] ])) $count = $member_array[ $v['fenxiao_id'] ][ 'count' ];
|
||||
|
||||
if(isset($team_array[$v['fenxiao_id']])){
|
||||
foreach ($team_array[$v['fenxiao_id']] as $key => $val){
|
||||
if(isset($member_array[ $val['fenxiao_id'] ])) $num += $member_array[ $val['fenxiao_id'] ][ 'count' ];
|
||||
}
|
||||
}
|
||||
$list[ 'list' ][ $k ][ 'team_num' ] = $count + $num;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分销分页列表2
|
||||
* @param array $condition
|
||||
* @param int $page
|
||||
* @param int $page_size
|
||||
* @param string $order
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public function getFenxiaoPageLists($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*', $alias = 'a', $join = null)
|
||||
{
|
||||
$list = model('fenxiao')->pageList($condition, $field, $order, $page, $page_size, $alias, $join, '');
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分销商团队
|
||||
* @param $level
|
||||
* @param $fenxiao_id
|
||||
* @param int $page
|
||||
* @param int $page_size
|
||||
* @param int $is_pay
|
||||
* @return array
|
||||
*/
|
||||
public function getFenxiaoTeam($level, $fenxiao_id, $page = 1, $page_size = PAGE_LIST_ROWS, $is_pay = 0)
|
||||
{
|
||||
$condition = '';
|
||||
|
||||
// 下级分销商id集合
|
||||
$one_level_fenxiao = model('fenxiao')->getColumn([ [ 'parent', '=', $fenxiao_id ] ], 'fenxiao_id');
|
||||
|
||||
switch ( $level ) {
|
||||
// 一级分销
|
||||
case 1:
|
||||
// 直属会员 + 直属下级分销商
|
||||
$or = " OR (f.parent = {$fenxiao_id}) ";
|
||||
$condition = "( (m.fenxiao_id = {$fenxiao_id} AND m.is_fenxiao = 0) " . $or . ') AND m.is_delete = 0';
|
||||
break;
|
||||
// 二级分销
|
||||
case 2:
|
||||
// 直属下级分销商的下级分销商 + 直属下级分销商的会员
|
||||
if (!empty($one_level_fenxiao)) {
|
||||
$or = ' OR (f.parent in (' . implode(',',$one_level_fenxiao) . ') ) ';
|
||||
$condition = '( (m.is_fenxiao = 0 AND m.fenxiao_id in (' . implode(',', $one_level_fenxiao) . ') )' . $or . ') AND m.is_delete = 0';
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (empty($condition)) return $this->success([
|
||||
'page_count' => 1,
|
||||
'count' => 0,
|
||||
'list' => []
|
||||
]);
|
||||
|
||||
if ($is_pay) $condition .= ' AND m.order_num > 0';
|
||||
$condition .= '';
|
||||
|
||||
$field = 'm.member_id,m.nickname,m.headimg,m.is_fenxiao,m.reg_time,m.order_money,m.order_complete_money,m.order_num,m.order_complete_num,m.bind_fenxiao_time,f.fenxiao_id,f.fenxiao_no,f.fenxiao_name,f.audit_time,f.level_name,f.one_child_num,f.one_child_fenxiao_num';
|
||||
$alias = 'm';
|
||||
$join = [
|
||||
[ 'fenxiao f', 'm.member_id = f.member_id', 'left' ]
|
||||
];
|
||||
|
||||
$list = model('member')->pageList($condition, $field, 'm.bind_fenxiao_time desc', $page, $page_size, $alias, $join);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询我的团队的数量
|
||||
* @param $fenxiao_id
|
||||
* @param $site_id
|
||||
* @return array
|
||||
*/
|
||||
public function getFenxiaoTeamNum($fenxiao_id, $site_id)
|
||||
{
|
||||
// 查询分销基础配置
|
||||
$config_model = new Config();
|
||||
$fenxiao_basic_config = $config_model->getFenxiaoBasicsConfig($site_id)[ 'data' ][ 'value' ];
|
||||
$level = $fenxiao_basic_config[ 'level' ];
|
||||
|
||||
$return = [
|
||||
'num' => 0, // 总人数
|
||||
'member_num' => 0, // 会员人数
|
||||
'fenxiao_num' => 0 // 分销商人数
|
||||
];
|
||||
|
||||
//递归查询
|
||||
$calc_level = 1;
|
||||
$parent_fenxiao_ids = [$fenxiao_id];
|
||||
while($calc_level <= $level){
|
||||
if(!empty($parent_fenxiao_ids)){
|
||||
$member_num = model('member')->getCount([ [ 'fenxiao_id', 'in', $parent_fenxiao_ids ], [ 'is_fenxiao', '=', 0 ], [ 'is_delete', '=', 0 ] ]);
|
||||
$fenxiao_list = model('fenxiao')->getList([ [ 'parent', 'in', $parent_fenxiao_ids ], [ 'is_delete', '=', 0 ] ], 'fenxiao_id');
|
||||
$fenxiao_ids = array_column($fenxiao_list, 'fenxiao_id');
|
||||
$fenxiao_num = count($fenxiao_ids);
|
||||
|
||||
//会员数量
|
||||
$return['member_num'] += $member_num;
|
||||
$return['member_num_'.$calc_level] = $member_num;
|
||||
//分销商数量
|
||||
$return['fenxiao_num'] += $fenxiao_num;
|
||||
$return['fenxiao_num_'.$calc_level] = $fenxiao_num;
|
||||
//总数量
|
||||
$return['num_'.$calc_level] = $member_num + $fenxiao_num;
|
||||
$return['num'] += $member_num + $fenxiao_num;
|
||||
|
||||
$parent_fenxiao_ids = $fenxiao_ids;
|
||||
}else{
|
||||
$return['member_num_'.$calc_level] = 0;
|
||||
$return['fenxiao_num_'.$calc_level] = 0;
|
||||
$return['num_'.$calc_level] = 0;
|
||||
}
|
||||
|
||||
$calc_level ++;
|
||||
}
|
||||
$return['level'] = $level;
|
||||
|
||||
return $this->success($return);
|
||||
}
|
||||
|
||||
/**
|
||||
* 会员注册之后
|
||||
* @param $member_id
|
||||
* @param $site_id
|
||||
*/
|
||||
public function memberRegister($member_id, $site_id)
|
||||
{
|
||||
//如果有推荐人则要修改分享关系
|
||||
$member_model = new Member();
|
||||
$member_info = $member_model->getMemberInfo([ [ 'member_id', '=', $member_id ] ], 'source_member')[ 'data' ];
|
||||
if (!empty($member_info[ 'source_member' ])) {
|
||||
$member_model->alterShareRelation($member_id, $member_info[ 'source_member' ], $site_id);
|
||||
}
|
||||
$this->autoBecomeFenxiao($member_id, $site_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 自动成为分销商
|
||||
* @param $member_id
|
||||
* @param $site_id
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function autoBecomeFenxiao($member_id, $site_id)
|
||||
{
|
||||
$member_info = model('member')->getInfo([ [ 'member_id', '=', $member_id ], [ 'site_id', '=', $site_id ], [ 'is_delete', '=', 0 ] ], 'order_num,order_complete_num,order_money,order_complete_money,is_fenxiao');
|
||||
if (empty($member_info)) return $this->error('', '未查询到会员信息');
|
||||
|
||||
$fenxiao_info = $this->getFenxiaoDetailInfo([ [ 'f.member_id', '=', $member_id ] ])[ 'data' ];
|
||||
if (!empty($fenxiao_info) && $member_info[ 'is_fenxiao' ]) return $this->error('', '已经是分销商');
|
||||
|
||||
try {
|
||||
$config = new Config();
|
||||
|
||||
// 分销商基础设置
|
||||
$basics_config = $config->getFenxiaoBasicsConfig($site_id)[ 'data' ][ 'value' ];
|
||||
if (!$basics_config[ 'level' ]) return $this->error('', '未开启分销');
|
||||
if ($basics_config[ 'is_apply' ] != 0) return $this->error('', '成为分销商需进行申请');
|
||||
|
||||
// 成为分销商的资格
|
||||
$fenxiao_config = $config->getFenxiaoConfig($site_id)[ 'data' ][ 'value' ];
|
||||
|
||||
switch ( $fenxiao_config[ 'fenxiao_condition' ] ) {
|
||||
case 2:
|
||||
// 消费次数
|
||||
if ($fenxiao_config[ 'consume_condition' ] == 1 && $member_info[ 'order_num' ] < $fenxiao_config[ 'consume_count' ]) return $this->error('', '未满足成为分销商的条件');
|
||||
if ($fenxiao_config[ 'consume_condition' ] == 2 && $member_info[ 'order_complete_num' ] < $fenxiao_config[ 'consume_count' ]) return $this->error('', '未满足成为分销商的条件');
|
||||
break;
|
||||
case 3:
|
||||
// 消费金额
|
||||
if ($fenxiao_config[ 'consume_condition' ] == 1 && bccomp($member_info[ 'order_money' ], $fenxiao_config[ 'consume_money' ], 2) == -1) return $this->error('', '未满足成为分销商的条件');
|
||||
if ($fenxiao_config[ 'consume_condition' ] == 2 && bccomp($member_info[ 'order_complete_money' ], $fenxiao_config[ 'consume_money' ], 2) == -1) return $this->error('', '未满足成为分销商的条件');
|
||||
break;
|
||||
case 4:
|
||||
// 购买指定商品
|
||||
$condition = [
|
||||
[ 'og.goods_id', 'in', $fenxiao_config[ 'goods_ids' ] ],
|
||||
[ 'og.member_id', '=', $member_id ]
|
||||
];
|
||||
if ($fenxiao_config[ 'consume_condition' ] == 1) $condition[] = [ 'pay_status', '=', 1 ];
|
||||
if ($fenxiao_config[ 'consume_condition' ] == 2) $condition[] = [ 'order_status', '=', OrderCommon::ORDER_COMPLETE ];
|
||||
$count = model('order_goods')->getCount($condition, 'order_goods_id', 'og', [ [ 'order o', 'o.order_id = og.order_id', 'inner' ] ]);
|
||||
if (!$count) return $this->error('', '未满足成为分销商的条件');
|
||||
break;
|
||||
}
|
||||
return $this->directlyBecomeFenxiao($member_id);
|
||||
} catch (\Exception $e) {
|
||||
return $this->error('', 'File:' . $e->getFile() . ',Line:' . $e->getLine() . ',Message:' . $e->getMessage() . ',Code:' . $e->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 会员直接成为分销商
|
||||
* @param $member_id
|
||||
* @return mixed
|
||||
*/
|
||||
private function directlyBecomeFenxiao($member_id)
|
||||
{
|
||||
//获取用户信息
|
||||
$member_field = 'member_id,site_id,source_member,fenxiao_id,nickname,headimg,mobile,reg_time,order_money,order_complete_money,order_num,order_complete_num';
|
||||
$member_info = model('member')->getInfo([ [ 'member_id', '=', $member_id ] ], $member_field);
|
||||
|
||||
if (!empty($member_info)) {
|
||||
$parent = 0;
|
||||
if (!empty($member_info[ 'fenxiao_id' ])) {
|
||||
$fenxiao_info = model('fenxiao')->getInfo([ [ 'fenxiao_id', '=', $member_info[ 'fenxiao_id' ] ], [ 'is_delete', '=', 0 ] ], 'fenxiao_id');
|
||||
if (!empty($fenxiao_info)) $parent = $fenxiao_info[ 'fenxiao_id' ];
|
||||
}
|
||||
|
||||
//获取分销等级信息
|
||||
$level_model = new FenxiaoLevel();
|
||||
$level_info = $level_model->getLevelInfo([ [ 'site_id', '=', $member_info[ 'site_id' ] ], [ 'is_default', '=', 1 ] ], 'level_id,level_name');
|
||||
|
||||
$data = [
|
||||
'site_id' => $member_info[ 'site_id' ],
|
||||
'fenxiao_name' => $member_info[ 'nickname' ],
|
||||
'mobile' => $member_info[ 'mobile' ],
|
||||
'member_id' => $member_info[ 'member_id' ],
|
||||
'parent' => $parent,
|
||||
'level_id' => $level_info[ 'data' ][ 'level_id' ],
|
||||
'level_name' => $level_info[ 'data' ][ 'level_name' ]
|
||||
];
|
||||
$res = $this->addFenxiao($data);
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定上下线关系
|
||||
* TODO 订单创建对返回结果进行检测 不可返回失败
|
||||
* @param $param
|
||||
* @return array|void
|
||||
*/
|
||||
public function bindRelation($param)
|
||||
{
|
||||
$site_id = $param[ 'site_id' ] ?? 0;
|
||||
$member_id = $param[ 'member_id' ] ?? 0;
|
||||
$action = $param[ 'action' ] ?? '';
|
||||
|
||||
$config = [
|
||||
'alter_share_relation' => 1,//对应 首次点击链接后绑定
|
||||
'order_create' => 2,//对应 首次下单后绑定
|
||||
'order_pay' => 3,//对应 首次付款后绑定
|
||||
];
|
||||
if (!isset($config[ $action ])) return;
|
||||
|
||||
//检测触发场景和设置是否匹配
|
||||
$config_model = new ConfigModel();
|
||||
$child_condition = $config_model->getFenxiaoRelationConfig($site_id)[ 'data' ][ 'value' ][ 'child_condition' ];
|
||||
if ($child_condition != $config[ $action ]) return;
|
||||
|
||||
//检测用户
|
||||
$member_info = model('member')->getInfo([
|
||||
[ 'member_id', '=', $member_id ],
|
||||
], 'share_member,fenxiao_id');
|
||||
if (empty($member_info)) return;
|
||||
//如果已经是分销商 不可以再修改关系
|
||||
if (!empty($member_info[ 'fenxiao_id' ])) return;
|
||||
|
||||
// 查询推荐人是否是分销商
|
||||
$fenxiao_info = model('fenxiao')->getInfo([
|
||||
[ 'member_id', '=', $member_info[ 'share_member' ] ],
|
||||
[ 'is_delete', '=', 0 ],
|
||||
], 'fenxiao_id');
|
||||
if (empty($fenxiao_info)) return;
|
||||
|
||||
model('member')->startTrans();
|
||||
try {
|
||||
$member_data = [
|
||||
'fenxiao_id' => $fenxiao_info[ 'fenxiao_id' ],
|
||||
'bind_fenxiao_time' => time()
|
||||
];
|
||||
model('member')->update($member_data, [ [ 'member_id', '=', $member_id ] ]);
|
||||
model('fenxiao')->setInc([ [ 'fenxiao_id', '=', $fenxiao_info[ 'fenxiao_id' ] ] ], 'one_child_num');
|
||||
|
||||
// 分销商检测升级
|
||||
event('FenxiaoUpgrade', $fenxiao_info[ 'fenxiao_id' ]);
|
||||
|
||||
model('member')->commit();
|
||||
return $this->success();
|
||||
} catch (\Exception $e) {
|
||||
model('member')->rollback();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 分销商检测升级
|
||||
* @param $fenxiao_id
|
||||
*/
|
||||
public function fenxiaoUpgrade($fenxiao_id)
|
||||
{
|
||||
$join = [
|
||||
[ 'member m', 'f.member_id = m.member_id', 'inner' ],
|
||||
[ 'fenxiao_level fl', 'f.level_id = fl.level_id', 'inner' ]
|
||||
];
|
||||
$fenxiao_info = model('fenxiao')->getInfo([ [ 'f.fenxiao_id', '=', $fenxiao_id ], [ 'f.status', '=', 1 ], [ 'f.is_delete', '=', 0 ] ], 'f.level_id,m.order_num,m.order_money,f.one_fenxiao_order_num,f.one_fenxiao_order_money,f.one_fenxiao_total_order,f.one_child_num,f.one_child_fenxiao_num,fl.one_rate,fl.level_num,f.site_id', 'f', $join);
|
||||
if (!empty($fenxiao_info)) {
|
||||
$level_list = model('fenxiao_level')->getList([ [ 'site_id', '=', $fenxiao_info[ 'site_id' ] ], [ 'level_num', '>', $fenxiao_info[ 'level_num' ] ] ], '*', 'level_num asc,one_rate asc');
|
||||
if (!empty($level_list)) {
|
||||
$upgrade_level = null;
|
||||
foreach ($level_list as $item) {
|
||||
if ($item[ 'upgrade_type' ] == 2) {
|
||||
if ($fenxiao_info[ 'order_num' ] >= $item[ 'order_num' ] && $fenxiao_info[ 'order_money' ] >= $item[ 'order_money' ] && $fenxiao_info[ 'one_fenxiao_order_num' ] >= $item[ 'one_fenxiao_order_num' ] && $fenxiao_info[ 'one_fenxiao_total_order' ] >= $item[ 'one_fenxiao_total_order' ] && $fenxiao_info[ 'one_fenxiao_order_money' ] >= $item[ 'one_fenxiao_order_money' ] && $fenxiao_info[ 'one_child_num' ] >= $item[ 'one_child_num' ] && $fenxiao_info[ 'one_child_fenxiao_num' ] >= $item[ 'one_child_fenxiao_num' ]) {
|
||||
$upgrade_level = $item;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (( $fenxiao_info[ 'order_num' ] >= $item[ 'order_num' ] && $item[ 'order_num' ] > 0 ) || ( $fenxiao_info[ 'order_money' ] >= $item[ 'order_money' ] && $item[ 'order_money' ] > 0 ) || ( $fenxiao_info[ 'one_fenxiao_order_num' ] >= $item[ 'one_fenxiao_order_num' ] && $item[ 'one_fenxiao_order_num' ] > 0 ) || ( $fenxiao_info[ 'one_fenxiao_order_money' ] >= $item[ 'one_fenxiao_order_money' ] && $item[ 'one_fenxiao_order_money' ] > 0 ) || ( $fenxiao_info[ 'one_fenxiao_total_order' ] >= $item[ 'one_fenxiao_total_order' ] && $item[ 'one_fenxiao_total_order' ] > 0 ) || ( $fenxiao_info[ 'one_child_num' ] >= $item[ 'one_child_num' ] && $item[ 'one_child_num' ] > 0 ) || ( $fenxiao_info[ 'one_child_fenxiao_num' ] >= $item[ 'one_child_fenxiao_num' ] && $item[ 'one_child_fenxiao_num' ] > 0 )) {
|
||||
$upgrade_level = $item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($upgrade_level) {
|
||||
model('fenxiao')->update([ 'level_id' => $upgrade_level[ 'level_id' ], 'level_name' => $upgrade_level[ 'level_name' ] ], [ [ 'fenxiao_id', '=', $fenxiao_id ] ]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取下一个可升级的分销商等级 及当前分销商已达成的条件
|
||||
* @param $member_id
|
||||
* @param $site_id
|
||||
* @return array
|
||||
*/
|
||||
public function geFenxiaoNextLevel($member_id, $site_id)
|
||||
{
|
||||
$array = [];
|
||||
$join = [
|
||||
[ 'member m', 'f.member_id = m.member_id', 'inner' ],
|
||||
[ 'fenxiao_level fl', 'f.level_id = fl.level_id', 'inner' ]
|
||||
];
|
||||
$fenxiao_info = model('fenxiao')->getInfo(
|
||||
[ [ 'f.member_id', '=', $member_id ], [ 'f.site_id', '=', $site_id ], [ 'f.status', '=', 1 ], [ 'f.is_delete', '=', 0 ] ],
|
||||
'f.level_id,m.order_num,m.order_money,f.one_fenxiao_order_num,f.one_fenxiao_order_money,f.one_child_num,f.one_child_fenxiao_num,fl.one_rate,fl.level_num', 'f', $join
|
||||
);
|
||||
$array[ 'fenxiao' ] = $fenxiao_info;
|
||||
$last_level = [];
|
||||
if (!empty($fenxiao_info)) {
|
||||
$last_level = model('fenxiao_level')->getFirstData([ [ 'site_id', '=', $site_id ], [ 'level_num', '>=', $fenxiao_info[ 'level_num' ] ], [ 'level_id', '<>', $fenxiao_info[ 'level_id' ] ] ], '*', 'level_num asc,one_rate asc');
|
||||
}
|
||||
$array[ 'last_level' ] = $last_level;
|
||||
return $this->success($array);
|
||||
}
|
||||
|
||||
/**
|
||||
* 变更上下级关系
|
||||
* @param $member_id
|
||||
* @param $parent
|
||||
* @return array
|
||||
*/
|
||||
public function changeParentFenxiao($member_id, $parent)
|
||||
{
|
||||
if ($member_id == '' || $member_id == 0) {
|
||||
return $this->error('', '参数member_id不能为空');
|
||||
}
|
||||
if ($parent == '' || $parent == 0) {
|
||||
return $this->error('', '上级分销商不能为空');
|
||||
}
|
||||
|
||||
//获取上级分销商id
|
||||
$parent_info = model('fenxiao')->getInfo([ [ 'fenxiao_id', '=', $parent ], [ 'is_delete', '=', 0 ] ]);
|
||||
if (empty($parent_info)) {
|
||||
return $this->error('', '上级分销商不存在');
|
||||
}
|
||||
|
||||
//用户信息
|
||||
$member_info = model('member')->getInfo([ [ 'member_id', '=', $member_id ] ], 'fenxiao_id,is_fenxiao');
|
||||
if (empty($member_info)) {
|
||||
return $this->error('', '用户不存在');
|
||||
}
|
||||
|
||||
model('fenxiao')->startTrans();
|
||||
try {
|
||||
|
||||
if ($member_info[ 'is_fenxiao' ] == 1) {//是分销商
|
||||
|
||||
$fenxiao_info = model('fenxiao')->getInfo([ [ 'fenxiao_id', '=', $member_info[ 'fenxiao_id' ] ], [ 'is_delete', '=', 0 ] ], 'parent');
|
||||
//修改原有上级分销商团队人数
|
||||
if ($fenxiao_info[ 'parent' ] > 0) {
|
||||
//获取原有上级分销商信息
|
||||
model('fenxiao')->setDec([ [ 'fenxiao_id', '=', $fenxiao_info[ 'parent' ] ] ], 'one_child_fenxiao_num');
|
||||
}
|
||||
|
||||
//修改变更后的上级分销商团队人数
|
||||
model('fenxiao')->setInc([ [ 'fenxiao_id', '=', $parent ] ], 'one_child_fenxiao_num');
|
||||
//修改上级分销商
|
||||
model('fenxiao')->update([ 'parent' => $parent, 'grand_parent' => $parent_info[ 'parent' ] ], [ [ 'fenxiao_id', '=', $member_info[ 'fenxiao_id' ] ] ]);
|
||||
} else {
|
||||
//不是分销商
|
||||
|
||||
//修改上级分销商
|
||||
model('member')->update([ 'fenxiao_id' => $parent ], [ [ 'member_id', '=', $member_id ] ]);
|
||||
//修改变更后的上级分销商团队人数
|
||||
model('fenxiao')->update([ 'one_child_num' => $parent_info[ 'one_child_num' ] + 1 ], [ [ 'fenxiao_id', '=', $parent ] ]);
|
||||
|
||||
}
|
||||
|
||||
model('fenxiao')->commit();
|
||||
return $this->success();
|
||||
} catch (\Exception $e) {
|
||||
model('fenxiao')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消上级分销商
|
||||
* @param $member_id
|
||||
* @return array
|
||||
*/
|
||||
public function cancelParentFenxiao($member_id)
|
||||
{
|
||||
if ($member_id == '' || $member_id == 0) {
|
||||
return $this->error('', '参数member_id不能为空');
|
||||
}
|
||||
|
||||
//用户信息
|
||||
$member_info = model('member')->getInfo([ [ 'member_id', '=', $member_id ] ], 'fenxiao_id,is_fenxiao');
|
||||
if (empty($member_info)) {
|
||||
return $this->error('', '用户不存在');
|
||||
}
|
||||
|
||||
model('fenxiao')->startTrans();
|
||||
try {
|
||||
|
||||
if ($member_info[ 'is_fenxiao' ] == 1) {//是分销商
|
||||
|
||||
$fenxiao_info = model('fenxiao')->getInfo(
|
||||
[ [ 'fenxiao_id', '=', $member_info[ 'fenxiao_id' ] ], [ 'is_delete', '=', 0 ] ],
|
||||
'parent'
|
||||
);
|
||||
//修改原有上级分销商团队人数
|
||||
if ($fenxiao_info[ 'parent' ] > 0) {
|
||||
//获取原有上级分销商信息
|
||||
model('fenxiao')->setDec([ [ 'fenxiao_id', '=', $fenxiao_info[ 'parent' ] ] ], 'one_child_fenxiao_num');
|
||||
}
|
||||
//修改上级分销商
|
||||
model('fenxiao')->update([ 'parent' => '0' ], [ [ 'fenxiao_id', '=', $member_info[ 'fenxiao_id' ] ] ]);
|
||||
}
|
||||
model('fenxiao')->commit();
|
||||
return $this->success();
|
||||
} catch (\Exception $e) {
|
||||
|
||||
model('fenxiao')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取上级分销商名称
|
||||
* @param $fenxiao_id
|
||||
* @param int $type 1-上级
|
||||
* @return mixed|string
|
||||
*/
|
||||
public function getParentFenxiaoName($fenxiao_id, $type = 1)
|
||||
{
|
||||
if ($fenxiao_id == 0) {
|
||||
return '';
|
||||
}
|
||||
if ($type == 1) {
|
||||
$fenxiao_name = model('fenxiao')->getValue([ [ 'fenxiao_id', '=', $fenxiao_id ] ], 'fenxiao_name');
|
||||
return $fenxiao_name;
|
||||
} else {
|
||||
|
||||
$parent = model('fenxiao')->getValue([ [ 'fenxiao_id', '=', $fenxiao_id ] ], 'parent');
|
||||
if ($parent == 0) {
|
||||
return '';
|
||||
} else {
|
||||
$fenxiao_name = model('fenxiao')->getValue([ [ 'fenxiao_id', '=', $parent ] ], 'fenxiao_name');
|
||||
return $fenxiao_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询上级分销商名称列表(用于会员列表查询)
|
||||
* @param $fenxiao_id
|
||||
*/
|
||||
public function getParentFenxiaoNameList($fenxiao_ids)
|
||||
{
|
||||
$fenxiao_name_list = model('fenxiao')->getList([ [ 'fenxiao_id', 'in', $fenxiao_ids ] ], 'fenxiao_id, fenxiao_name');
|
||||
return $fenxiao_name_list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 会员注销删除分销商
|
||||
* @param $member_id
|
||||
* @param $site_id
|
||||
* @return array
|
||||
*/
|
||||
public function CronMemberCancel($member_id, $site_id)
|
||||
{
|
||||
$info = model('fenxiao')->getInfo([ [ 'member_id', '=', $member_id ], [ 'site_id', '=', $site_id ] ]);
|
||||
if (empty($info)) {
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
//冻结账户并删除
|
||||
$data = [
|
||||
'status' => -1,
|
||||
'lock_time' => time(),
|
||||
'is_delete' => 1
|
||||
];
|
||||
|
||||
$res = model('fenxiao')->update($data, [ [ 'fenxiao_id', '=', $info[ 'fenxiao_id' ] ] ]);
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 变更分销商等级
|
||||
* @param $data
|
||||
* @param $condition
|
||||
* @return array
|
||||
*/
|
||||
public function changeFenxiaoLevel($data, $condition)
|
||||
{
|
||||
$result = model('fenxiao')->update($data, $condition);
|
||||
return $this->success($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分销等级分销商数量
|
||||
* @param $condition
|
||||
* @return int|mixed
|
||||
*/
|
||||
public function getFenxiaoMemberCount($condition)
|
||||
{
|
||||
$condition[] = [ 'is_delete', '=', 0 ];
|
||||
$count = model('fenxiao')->getCount($condition);
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分销商排名
|
||||
* @param $site_id
|
||||
* @param $fenxiao_id
|
||||
* @param $order
|
||||
* @return array
|
||||
*/
|
||||
public function getFenxiaoRanking($site_id, $fenxiao_id, $order)
|
||||
{
|
||||
$prefix = config('database.connections.mysql.prefix');
|
||||
$version = model('fenxiao')->query('SELECT VERSION() as version')[ 0 ][ 'version' ];
|
||||
|
||||
if (substr($version, 0, 1) == 8) {
|
||||
$query = "SELECT * FROM (select *,row_number() OVER(order by {$order} DESC) as rownum from {$prefix}fenxiao nf) AS f WHERE f.fenxiao_id = {$fenxiao_id}";
|
||||
} else {
|
||||
$query = "SELECT b.rownum FROM (SELECT t.*, @rownum := @rownum + 1 AS rownum FROM (SELECT @rownum := 0) r,(SELECT * FROM {$prefix}fenxiao WHERE site_id = {$site_id} ORDER BY {$order} DESC,fenxiao_id ASC) AS t) AS b WHERE b.fenxiao_id = {$fenxiao_id};";
|
||||
}
|
||||
$data = model('fenxiao')->query($query);
|
||||
$data = empty($data) ? 0 : $data[ 0 ][ 'rownum' ];
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
// todo 删除分销商
|
||||
|
||||
}
|
||||
108
addon/fenxiao/model/FenxiaoAccount.php
Executable file
108
addon/fenxiao/model/FenxiaoAccount.php
Executable file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\fenxiao\model;
|
||||
|
||||
use app\model\BaseModel;
|
||||
|
||||
|
||||
/**
|
||||
* 分销
|
||||
*/
|
||||
class FenxiaoAccount extends BaseModel
|
||||
{
|
||||
public $type = [
|
||||
'withdraw' => '提现',
|
||||
'order' => '订单结算',
|
||||
];
|
||||
|
||||
/**
|
||||
* 添加账户流水
|
||||
* @param $fenxiao_id
|
||||
* @param $fenxiao_name
|
||||
* @param $type
|
||||
* @param $money
|
||||
* @param $relate_id
|
||||
* @return array
|
||||
*/
|
||||
public function addAccount($fenxiao_id, $fenxiao_name, $type, $money, $relate_id)
|
||||
{
|
||||
$account_no = date('YmdHi') . rand(1000, 9999);
|
||||
$data = array (
|
||||
'fenxiao_id' => $fenxiao_id,
|
||||
'fenxiao_name' => $fenxiao_name,
|
||||
'account_no' => $account_no,
|
||||
'money' => $money,
|
||||
'type' => $type,
|
||||
'type_name' => $this->type[ $type ],
|
||||
'relate_id' => $relate_id,
|
||||
'create_time' => time(),
|
||||
);
|
||||
|
||||
$res = model('fenxiao_account')->add($data);
|
||||
model('fenxiao')->setInc([ [ 'fenxiao_id', '=', $fenxiao_id ] ], 'account', $money);
|
||||
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分销商账户流水信息
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public function getFenxiaoAccountInfo($condition = [], $field = '*')
|
||||
{
|
||||
$list = model('fenxiao_account')->getInfo($condition, $field);
|
||||
return $this->success($list);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分销商账户流水分页列表
|
||||
* @param array $condition
|
||||
* @param int $page
|
||||
* @param int $page_size
|
||||
* @param string $order
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public function getFenxiaoAccountPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'create_time desc', $field = '*')
|
||||
{
|
||||
$list = model('fenxiao_account')->pageList($condition, $field, $order, $page, $page_size);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加分销商账户流水(不扣账户)
|
||||
* @param $fenxiao_id
|
||||
* @param $fenxiao_name
|
||||
* @param string $type
|
||||
* @param $money
|
||||
* @param $relate_id
|
||||
* @return array
|
||||
*/
|
||||
public function addAccountLog($fenxiao_id, $fenxiao_name, $type, $money, $relate_id)
|
||||
{
|
||||
$account_no = date('YmdHi') . rand(1000, 9999);
|
||||
$data = array (
|
||||
'fenxiao_id' => $fenxiao_id,
|
||||
'fenxiao_name' => $fenxiao_name,
|
||||
'account_no' => $account_no,
|
||||
'money' => $money,
|
||||
'type' => $type,
|
||||
'type_name' => $this->type[ $type ],
|
||||
'relate_id' => $relate_id,
|
||||
'create_time' => time(),
|
||||
);
|
||||
$res = model('fenxiao_account')->add($data);
|
||||
return $this->success($res);
|
||||
}
|
||||
}
|
||||
310
addon/fenxiao/model/FenxiaoApply.php
Executable file
310
addon/fenxiao/model/FenxiaoApply.php
Executable file
@@ -0,0 +1,310 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\fenxiao\model;
|
||||
|
||||
use app\model\BaseModel;
|
||||
use app\model\member\Member;
|
||||
|
||||
|
||||
/**
|
||||
* 分销
|
||||
*/
|
||||
class FenxiaoApply extends BaseModel
|
||||
{
|
||||
|
||||
public $fenxiao_status_zh = [
|
||||
1 => '待审核',
|
||||
2 => '已审核',
|
||||
-1 => '拒绝',
|
||||
];
|
||||
|
||||
/**
|
||||
* 判断分销商名称是否存在
|
||||
* @param $fenxiao_name
|
||||
* @param $site_id
|
||||
* @return array
|
||||
*/
|
||||
public function existFenxiaoName($fenxiao_name, $site_id)
|
||||
{
|
||||
$res = model('fenxiao_apply')->getCount([ [ 'fenxiao_name', '=', $fenxiao_name ], [ 'site_id', '=', $site_id ] ]);
|
||||
if ($res > 0) {
|
||||
return $this->error('', '该分销商名称已存在');
|
||||
}
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 申请成为分销商
|
||||
* @param $member_id
|
||||
* @param $site_id
|
||||
* @param string $fenxiao_name
|
||||
* @param string $mobile
|
||||
* @return array|int|mixed|string
|
||||
*/
|
||||
public function applyFenxiao($member_id, $site_id, $fenxiao_name = '', $mobile = '')
|
||||
{
|
||||
//判断该用户是否已经申请
|
||||
$apply_info = model('fenxiao_apply')->getInfo([ [ 'member_id', '=', $member_id ] ], 'apply_id,status');
|
||||
if (!empty($apply_info) && $apply_info[ 'status' ] != -1) {
|
||||
return $this->error('', '已经申请过,请不要重复申请');
|
||||
}
|
||||
|
||||
// 分销商基础设置
|
||||
$config = new Config();
|
||||
$basics_config = $config->getFenxiaoBasicsConfig($site_id)[ 'data' ][ 'value' ];
|
||||
|
||||
if (!$basics_config[ 'level' ]) return $this->error('', '未开启分销');
|
||||
|
||||
//获取分销配置信息
|
||||
$fenxiao_config = $config->getFenxiaoConfig($site_id)[ 'data' ][ 'value' ];
|
||||
|
||||
//获取用户信息
|
||||
$member_model = new Member();
|
||||
$member_field = 'source_member,fenxiao_id,nickname,headimg,reg_time,order_money,order_complete_money,order_num,order_complete_num';
|
||||
$member_info = $member_model->getMemberInfo([ [ 'member_id', '=', $member_id ] ], $member_field);
|
||||
|
||||
// 判断用户是否可以成为申请分销商
|
||||
if ($fenxiao_config[ 'fenxiao_condition' ] == 2) {
|
||||
if ($fenxiao_config[ 'consume_condition' ] == 1 && $fenxiao_config[ 'consume_count' ] > $member_info[ 'data' ][ 'order_num' ]) {
|
||||
return $this->error('', '您的消费次数未满足申请条件');
|
||||
} elseif ($fenxiao_config[ 'consume_condition' ] == 2 && $fenxiao_config[ 'consume_count' ] > $member_info[ 'data' ][ 'order_complete_num' ]) {
|
||||
return $this->error('', '您的消费次数未满足申请条件');
|
||||
}
|
||||
} elseif ($fenxiao_config[ 'fenxiao_condition' ] == 3) {
|
||||
if ($fenxiao_config[ 'consume_condition' ] == 1 && $fenxiao_config[ 'consume_money' ] > $member_info[ 'data' ][ 'order_money' ]) {
|
||||
return $this->error('', '您的消费金额未满足申请条件');
|
||||
} elseif ($fenxiao_config[ 'consume_condition' ] == 2 && $fenxiao_config[ 'consume_money' ] > $member_info[ 'data' ][ 'order_complete_money' ]) {
|
||||
return $this->error('', '您的消费金额未满足申请条件');
|
||||
}
|
||||
} elseif ($fenxiao_config[ 'fenxiao_condition' ] == 4) { //购买指定商品
|
||||
//获取用户购买商品是否在成为分销商指定商品区域
|
||||
$alias = 'og';
|
||||
$condition[] = [ 'og.member_id', '=', $member_id ];
|
||||
$condition[] = [ 'og.site_id', '=', $site_id ];
|
||||
$condition[] = [ 'og.goods_id', 'in', $fenxiao_config[ 'goods_ids' ] ];
|
||||
$field = 'o.order_status,og.goods_id';
|
||||
$join = [
|
||||
[
|
||||
'order o',
|
||||
'o.order_id = og.order_id',
|
||||
'inner'
|
||||
]
|
||||
];
|
||||
if ($fenxiao_config[ 'consume_condition' ] == 1) {
|
||||
$condition[] = [ 'o.pay_status', '=', 1 ];
|
||||
$order_data = model('order_goods')->getList($condition, $field, '', $alias, $join);
|
||||
if (empty($order_data)) {
|
||||
return $this->error('', '您还未满足申请条件');
|
||||
}
|
||||
} elseif ($fenxiao_config[ 'consume_condition' ] == 2) {
|
||||
$condition[] = [ 'o.order_status', '=', '10' ];
|
||||
$order_data = model('order_goods')->getList($condition, $field, '', $alias, $join);
|
||||
if (empty($order_data)) {
|
||||
return $this->error('', '您还未满足申请条件');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (empty($fenxiao_name)) $fenxiao_name = $member_info[ 'data' ][ 'nickname' ];
|
||||
|
||||
//获取分销等级信息
|
||||
$level_model = new FenxiaoLevel();
|
||||
$level_info = $level_model->getLevelInfo([ [ 'site_id', '=', $site_id ], [ 'is_default', '=', 1 ] ], 'level_id,level_name');
|
||||
|
||||
// 成为分销商是否需要审核
|
||||
if ($basics_config[ 'is_examine' ]) {
|
||||
$apply_data = [
|
||||
'site_id' => $site_id,
|
||||
'fenxiao_name' => $fenxiao_name,
|
||||
'parent' => $member_info[ 'data' ][ 'fenxiao_id' ],
|
||||
'member_id' => $member_id,
|
||||
'mobile' => $mobile,
|
||||
'nickname' => $member_info[ 'data' ][ 'nickname' ],
|
||||
'headimg' => $member_info[ 'data' ][ 'headimg' ],
|
||||
'level_id' => $level_info[ 'data' ][ 'level_id' ],
|
||||
'level_name' => $level_info[ 'data' ][ 'level_name' ],
|
||||
'order_complete_money' => $member_info[ 'data' ][ 'order_complete_money' ],
|
||||
'order_complete_num' => $member_info[ 'data' ][ 'order_complete_num' ],
|
||||
'reg_time' => $member_info[ 'data' ][ 'reg_time' ],
|
||||
'create_time' => time(),
|
||||
'status' => 1
|
||||
];
|
||||
if (!empty($apply_info)) {
|
||||
$res = model('fenxiao_apply')->update($apply_data, [ [ 'member_id', '=', $member_id ] ]);
|
||||
} else {
|
||||
$res = model('fenxiao_apply')->add($apply_data);
|
||||
}
|
||||
return $this->success($res);
|
||||
} else {
|
||||
$fenxiao_data = [
|
||||
'site_id' => $site_id,
|
||||
'fenxiao_name' => $fenxiao_name,
|
||||
'mobile' => $mobile,
|
||||
'member_id' => $member_id,
|
||||
'parent' => $member_info[ 'data' ][ 'fenxiao_id' ],
|
||||
'level_id' => $level_info[ 'data' ][ 'level_id' ],
|
||||
'level_name' => $level_info[ 'data' ][ 'level_name' ]
|
||||
];
|
||||
$fenxiao_model = new Fenxiao();
|
||||
$res = $fenxiao_model->addFenxiao($fenxiao_data);
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理员添加分销商
|
||||
*/
|
||||
public function addFenxiao($fenxiao_data)
|
||||
{
|
||||
if (empty($fenxiao_data[ 'fenxiao_name' ])) {
|
||||
return $this->error('', '分销商名称不能为空');
|
||||
}
|
||||
if (empty($fenxiao_data[ 'level_id' ])) {
|
||||
return $this->error('', '请选择分销商等级');
|
||||
}
|
||||
if (empty($fenxiao_data[ 'member_id' ])) {
|
||||
return $this->error('', '请选择关联会员');
|
||||
}
|
||||
|
||||
//判断该用户是否已经申请
|
||||
$apply_info = model('fenxiao_apply')->getInfo([ [ 'member_id', '=', $fenxiao_data[ 'member_id' ] ] ], 'apply_id,status');
|
||||
if (!empty($apply_info) && $apply_info[ 'status' ] != -1) {
|
||||
return $this->error('', '已经申请过,请不要重复申请');
|
||||
}
|
||||
|
||||
// 分销商基础设置
|
||||
$config = new Config();
|
||||
//获取分销配置信息
|
||||
$fenxiao_config = $config->getFenxiaoConfig($fenxiao_data[ 'site_id' ])[ 'data' ][ 'value' ];
|
||||
|
||||
//获取用户信息
|
||||
$member_model = new Member();
|
||||
$member_field = 'source_member,fenxiao_id,nickname,headimg,reg_time,order_money,order_complete_money,order_num,order_complete_num';
|
||||
$member_info = $member_model->getMemberInfo([ [ 'member_id', '=', $fenxiao_data[ 'member_id' ] ] ], $member_field);
|
||||
if (empty($member_info)) return $this->error('', '未获取到会员信息');
|
||||
|
||||
//获取分销等级信息
|
||||
$level_model = new FenxiaoLevel();
|
||||
$level_info = $level_model->getLevelInfo([ [ 'site_id', '=', $fenxiao_data[ 'site_id' ] ], [ 'level_id', '=', $fenxiao_data[ 'level_id' ] ] ], 'level_name');
|
||||
$fenxiao_data[ 'level_name' ] = $level_info[ 'data' ][ 'level_name' ];
|
||||
|
||||
$fenxiao_model = new Fenxiao();
|
||||
return $fenxiao_model->addFenxiao($fenxiao_data);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 审核通过
|
||||
* @param $apply_id
|
||||
* @param $site_id
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function pass($apply_id, $site_id)
|
||||
{
|
||||
$info = model('fenxiao_apply')->getInfo([ [ 'apply_id', '=', $apply_id ], [ 'site_id', '=', $site_id ] ]);
|
||||
if ($info[ 'status' ] == 2) {
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
model('fenxiao_apply')->startTrans();
|
||||
try {
|
||||
$data = [
|
||||
'status' => 2,
|
||||
'update_time' => time(),
|
||||
];
|
||||
$res = model('fenxiao_apply')->update($data, [ [ 'apply_id', '=', $apply_id ], [ 'site_id', '=', $site_id ] ]);
|
||||
|
||||
$fenxiao_data = [
|
||||
'site_id' => $info[ 'site_id' ],
|
||||
'fenxiao_name' => $info[ 'fenxiao_name' ],
|
||||
'mobile' => $info[ 'mobile' ],
|
||||
'member_id' => $info[ 'member_id' ],
|
||||
'parent' => $info[ 'parent' ],
|
||||
'level_id' => $info[ 'level_id' ],
|
||||
'level_name' => $info[ 'level_name' ]
|
||||
];
|
||||
|
||||
$fenxiao_model = new Fenxiao();
|
||||
$result = $fenxiao_model->addFenxiao($fenxiao_data);
|
||||
if ($result[ 'code' ] != 0) {
|
||||
model('fenxiao_apply')->rollback();
|
||||
return $result;
|
||||
}
|
||||
|
||||
model('fenxiao_apply')->commit();
|
||||
|
||||
return $this->success($res);
|
||||
} catch (\Exception $e) {
|
||||
model('fenxiao_apply')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 审核不通过
|
||||
* @param $apply_id
|
||||
* @return array
|
||||
*/
|
||||
public function refuse($apply_id)
|
||||
{
|
||||
$data = [
|
||||
'status' => -1,
|
||||
'update_time' => time()
|
||||
];
|
||||
|
||||
$res = model('fenxiao_apply')->update($data, [ [ 'apply_id', '=', $apply_id ] ]);
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分销商申请信息
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public function getFenxiaoApplyInfo($condition = [], $field = '*')
|
||||
{
|
||||
$res = model('fenxiao_apply')->getInfo($condition, $field);
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分销商申请分页列表
|
||||
* @param array $condition
|
||||
* @param int $page
|
||||
* @param int $page_size
|
||||
* @param string $order
|
||||
* @param string $field
|
||||
* @param string $alias
|
||||
* @param array $join
|
||||
* @return array
|
||||
*/
|
||||
public function getFenxiaoApplyPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*', $alias = 'a', $join = [])
|
||||
{
|
||||
$list = model('fenxiao_apply')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分销商申请数量
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public function getFenxiaoApplyCount($condition = [], $field = 'id')
|
||||
{
|
||||
$count = model('fenxiao_apply')->getCount($condition, $field);
|
||||
return $this->success($count);
|
||||
}
|
||||
|
||||
}
|
||||
82
addon/fenxiao/model/FenxiaoData.php
Executable file
82
addon/fenxiao/model/FenxiaoData.php
Executable file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\fenxiao\model;
|
||||
|
||||
use app\model\BaseModel;
|
||||
|
||||
|
||||
/**
|
||||
* 分销数据
|
||||
*/
|
||||
class FenxiaoData extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* 分销商账户统计
|
||||
* @param $site_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function getFenxiaoAccountData($site_id)
|
||||
{
|
||||
$field = 'sum(account) as account,sum(account_withdraw) as account_withdraw,sum(account_withdraw_apply) as account_withdraw_apply';
|
||||
$res = model('fenxiao')->getInfo([ [ 'status', 'in', '1,-1' ], [ 'site_id', '=', $site_id ], [ 'is_delete', '=', 0 ] ], $field);
|
||||
|
||||
if (empty($res) || $res[ 'account' ] == null) {
|
||||
$res[ 'account' ] = '0.00';
|
||||
}
|
||||
|
||||
if (empty($res) || $res[ 'account_withdraw' ] == null) {
|
||||
$res[ 'account_withdraw' ] = '0.00';
|
||||
}
|
||||
if (empty($res) || $res[ 'account_withdraw_apply' ] == null) {
|
||||
$res[ 'account_withdraw_apply' ] = '0.00';
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分销商申请人数
|
||||
* @param $site_id
|
||||
* @return int|mixed
|
||||
*/
|
||||
public function getFenxiaoApplyCount($site_id)
|
||||
{
|
||||
$count = model('fenxiao_apply')->getCount([ [ 'status', '=', 1 ], [ 'site_id', '=', $site_id ] ]);
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分销商人数
|
||||
* @param $site_id
|
||||
* @return int|mixed
|
||||
*/
|
||||
public function getFenxiaoCount($site_id)
|
||||
{
|
||||
$count = model('fenxiao')->getCount([ [ 'site_id', '=', $site_id ], [ 'is_delete', '=', 0 ] ]);
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计分销订单总金额
|
||||
* @param $site_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function getFenxiaoOrderSum($site_id)
|
||||
{
|
||||
$field = 'sum(real_goods_money) as real_goods_money';
|
||||
$res = model('fenxiao_order')->getInfo([ [ 'site_id', '=', $site_id ] ], $field);
|
||||
if ($res[ 'real_goods_money' ] == null) {
|
||||
$res[ 'real_goods_money' ] = '0.00';
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
219
addon/fenxiao/model/FenxiaoGoods.php
Executable file
219
addon/fenxiao/model/FenxiaoGoods.php
Executable file
@@ -0,0 +1,219 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\fenxiao\model;
|
||||
|
||||
use addon\fenxiao\model\Fenxiao as FenxiaoModel;
|
||||
use app\model\BaseModel;
|
||||
use app\model\goods\Goods as GoodsModel;
|
||||
|
||||
/**
|
||||
* 分销商品 addon\fenxiao\model\FenxiaoGoods
|
||||
*/
|
||||
class FenxiaoGoods extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* 修改分销商品
|
||||
* @param $data
|
||||
* @param $condition
|
||||
* @return array
|
||||
*/
|
||||
public function editGoodsFenxiao($data, $condition)
|
||||
{
|
||||
$re = model('goods')->update($data, $condition);
|
||||
return $this->success($re);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改分销状态
|
||||
* @param $goods_id
|
||||
* @param $is_fenxiao
|
||||
* @param $site_id
|
||||
* @return array
|
||||
*/
|
||||
public function modifyGoodsFenxiaoStatus($goods_id, $is_fenxiao, $site_id)
|
||||
{
|
||||
$fenxiao_goods_skus = model('fenxiao_goods_sku')->getList([['goods_id', '=', $goods_id]]);
|
||||
model('goods')->startTrans();
|
||||
try {
|
||||
if (empty($fenxiao_goods_skus)) {
|
||||
$level_list = model('fenxiao_level')->getList([['site_id', '=', $site_id], ['status', '=', 1]]);
|
||||
$goods_model = new GoodsModel();
|
||||
$goods_info = $goods_model->getGoodsDetail($goods_id);
|
||||
$fenxiao_goods_sku_data = [];
|
||||
foreach ($level_list as $level) {
|
||||
foreach ($goods_info['data']['sku_data'] as $sku) {
|
||||
$fenxiao_sku = [
|
||||
'goods_id' => $goods_id,
|
||||
'level_id' => $level['level_id'],
|
||||
'sku_id' => $sku['sku_id'],
|
||||
'one_rate' => $level['one_rate'],
|
||||
'one_money' => 0,
|
||||
'two_rate' => $level['two_rate'],
|
||||
'two_money' => 0,
|
||||
'three_rate' => $level['three_rate'],
|
||||
'three_money' => 0,
|
||||
];
|
||||
$fenxiao_goods_sku_data[] = $fenxiao_sku;
|
||||
}
|
||||
}
|
||||
model('fenxiao_goods_sku')->addList($fenxiao_goods_sku_data);
|
||||
}
|
||||
|
||||
model('goods')->update(['is_fenxiao' => $is_fenxiao], [['goods_id', '=', $goods_id], ['site_id', '=', $site_id]]);
|
||||
model('goods')->commit();
|
||||
return $this->success(1);
|
||||
} catch (\Exception $e) {
|
||||
model('goods')->rollback();
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 取消参与分销
|
||||
* @param $goods_ids
|
||||
* @param $site_id
|
||||
* @return array
|
||||
*/
|
||||
public function modifyGoodsIsFenxiao($goods_ids, $is_fenxiao, $site_id)
|
||||
{
|
||||
$res = model('goods')->update(['is_fenxiao' => $is_fenxiao], [['goods_id', 'in', $goods_ids], ['site_id', '=', $site_id]]);
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询商品分销详情
|
||||
* @param $goods_sku_detail_array
|
||||
*/
|
||||
public function getGoodsFenxiaoDetailInApi($goods_sku_detail_array, $member_id, $site_id, $discount_price = 0)
|
||||
{
|
||||
$config = new Config();
|
||||
$words_config = $config->getFenxiaoWordsConfig($site_id)['data']['value'];
|
||||
$basic_config = $config->getFenxiaoBasicsConfig($site_id)['data']['value'];
|
||||
$data = [
|
||||
'words_account' => $words_config['account'],
|
||||
'commission_money' => 0.00,
|
||||
'is_commission_money' => $basic_config['is_commission_money'],
|
||||
];
|
||||
$goods_sku_detail_array['goods_sku_detail']['fenxiao_detail'] = $data;
|
||||
//检测当前用户是否是分销商以及分销商等级
|
||||
$member_info = $goods_sku_detail_array['member_info'];
|
||||
$goods_sku_detail = $goods_sku_detail_array['goods_sku_detail'];
|
||||
if ($member_info['is_fenxiao'] == 0 || $goods_sku_detail['is_fenxiao'] == 0) {
|
||||
|
||||
return $goods_sku_detail_array;
|
||||
}
|
||||
//查询分销商等级
|
||||
$fenxiao_model = new FenxiaoModel();
|
||||
$fenxiao_info = $fenxiao_model->getFenxiaoInfo([['member_id', '=', $member_id]], 'fenxiao_id,level_id')['data'];
|
||||
if (empty($fenxiao_info)) return $goods_sku_detail_array;
|
||||
// $discount_price = $goods_sku_detail['fenxiao_price'] > 0 ? $goods_sku_detail['fenxiao_price'] : $goods_sku_detail['discount_price'];
|
||||
if ($goods_sku_detail['fenxiao_price'] > 0) {
|
||||
$discount_price = $goods_sku_detail['fenxiao_price'];
|
||||
} else {
|
||||
if ($discount_price == 0) {
|
||||
if (!empty($goods_sku_detail['member_price'])) {
|
||||
$discount_price = min($goods_sku_detail['member_price'], $goods_sku_detail['discount_price']);
|
||||
} else {
|
||||
$discount_price = $goods_sku_detail['discount_price'];
|
||||
}
|
||||
} else {
|
||||
$discount_price = $discount_price; // 特殊营销活动直接指定计算价格
|
||||
}
|
||||
}
|
||||
if ($goods_sku_detail['fenxiao_type'] == 1) {
|
||||
$fenxiao_level = new FenxiaoLevel();
|
||||
$level_info = $fenxiao_level->getLevelInfo([['level_id', '=', $fenxiao_info['level_id']]], 'one_rate')['data'];
|
||||
if (!empty($level_info)) {
|
||||
$data['commission_money'] = number_format($discount_price * $level_info['one_rate'] / 100, 2, '.', '');
|
||||
}
|
||||
} else {
|
||||
$fenxiao_sku_info = model('fenxiao_goods_sku')->getInfo([['level_id', '=', $fenxiao_info['level_id']], ['sku_id', '=', $goods_sku_detail['sku_id']]], 'one_money, one_rate');
|
||||
if (!empty($fenxiao_sku_info)) {
|
||||
$data['commission_money'] = $fenxiao_sku_info['one_money'];
|
||||
if ($fenxiao_sku_info['one_rate'] > 0) {
|
||||
$data['commission_money'] = number_format($discount_price * $fenxiao_sku_info['one_rate'] / 100, 2, '.', '');
|
||||
}
|
||||
}
|
||||
}
|
||||
$goods_sku_detail_array['goods_sku_detail']['fenxiao_detail'] = $data;
|
||||
return $goods_sku_detail_array;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询商品规格列表分销信息
|
||||
* @param $goods_sku_list
|
||||
* @param $member_id
|
||||
* @param $site_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function getGoodsSkuListFenxiaoInApi($goods_sku_list, $member_id, $site_id)
|
||||
{
|
||||
$config = new Config();
|
||||
$words_config = $config->getFenxiaoWordsConfig($site_id)['data']['value'];
|
||||
$basic_config = $config->getFenxiaoBasicsConfig($site_id)['data']['value'];
|
||||
$data = [
|
||||
'words_account' => $words_config['account'],
|
||||
'commission_money' => 0.00,
|
||||
'is_commission_money' => $basic_config['is_commission_money'],
|
||||
];
|
||||
//组装数据
|
||||
foreach ($goods_sku_list as $k => $v) {
|
||||
$goods_sku_list[$k]['fenxiao_detail'] = $data;
|
||||
}
|
||||
//检测当前用户是否是分销商以及分销商等级
|
||||
$goods_sku_info = $goods_sku_list[0];
|
||||
$member_info = $goods_sku_list[0]['member_info'];
|
||||
if ($member_info['is_fenxiao'] == 0 || $goods_sku_info['is_fenxiao'] == 0) {
|
||||
return $goods_sku_list;
|
||||
}
|
||||
//查询分销商等级
|
||||
$fenxiao_model = new FenxiaoModel();
|
||||
$fenxiao_info = $fenxiao_model->getFenxiaoInfo([['member_id', '=', $member_id]], 'fenxiao_id,level_id')['data'];
|
||||
if (empty($fenxiao_info)) return $goods_sku_list;
|
||||
|
||||
if ($goods_sku_info['fenxiao_type'] == 1) {
|
||||
$fenxiao_level = new FenxiaoLevel();
|
||||
$level_info = $fenxiao_level->getLevelInfo([['level_id', '=', $fenxiao_info['level_id']]], 'one_rate')['data'];
|
||||
if (!empty($level_info)) {
|
||||
foreach ($goods_sku_list as $k => $v) {
|
||||
|
||||
if ($v['fenxiao_price'] > 0) {
|
||||
$discount_price = $v['fenxiao_price'];
|
||||
} else {
|
||||
if (!empty($v['member_price'])) {
|
||||
$discount_price = min($v['member_price'], $v['discount_price']);
|
||||
} else {
|
||||
$discount_price = $v['discount_price'];
|
||||
}
|
||||
}
|
||||
// $discount_price = $v['fenxiao_price'] > 0 ? $v['fenxiao_price'] : $v['discount_price'];
|
||||
$goods_sku_list[$k]['fenxiao_detail']['commission_money'] = number_format($discount_price * $level_info['one_rate'] / 100, 2, '.', '');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$fenxiao_sku_list = model('fenxiao_goods_sku')->getList([['level_id', '=', $fenxiao_info['level_id']], ['goods_id', '=', $goods_sku_info['goods_id']]], 'sku_id, one_money, one_rate');
|
||||
$fenxiao_sku_list = array_column($fenxiao_sku_list, null, 'sku_id');
|
||||
foreach ($goods_sku_list as $k => $v) {
|
||||
$fenxiao_sku_info = $fenxiao_sku_list[$v['sku_id']] ?? [];
|
||||
if (!empty($fenxiao_sku_info)) {
|
||||
$discount_price = $v['fenxiao_price'] > 0 ? $v['fenxiao_price'] : $v['discount_price'];
|
||||
$goods_sku_list[$k]['fenxiao_detail']['commission_money'] = $fenxiao_sku_info['one_money'];
|
||||
if ($fenxiao_sku_info['one_rate'] > 0) {
|
||||
$goods_sku_list[$k]['fenxiao_detail']['commission_money'] = number_format($discount_price * $fenxiao_sku_info['one_rate'] / 100, 2, '.', '');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return $goods_sku_list;
|
||||
}
|
||||
}
|
||||
83
addon/fenxiao/model/FenxiaoGoodsCollect.php
Executable file
83
addon/fenxiao/model/FenxiaoGoodsCollect.php
Executable file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\fenxiao\model;
|
||||
|
||||
use app\model\BaseModel;
|
||||
|
||||
|
||||
/**
|
||||
* 分销商关注商品
|
||||
*/
|
||||
class FenxiaoGoodsCollect extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 添加分销商关注商品
|
||||
* @param $data
|
||||
* @return array
|
||||
*/
|
||||
public function addCollect($data)
|
||||
{
|
||||
$res = model('fenxiao_goods_collect')->getCount([ [ 'member_id', '=', $data[ 'member_id' ] ], [ 'goods_id', '=', $data[ 'goods_id' ] ] ]);
|
||||
if (empty($res)) {
|
||||
$data[ 'create_time' ] = time();
|
||||
$collect_id = model('fenxiao_goods_collect')->add($data);
|
||||
return $this->success($collect_id);
|
||||
} else {
|
||||
return $this->error('', 'GOODS_COLLECT_IS_EXIST');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除分销商关注商品
|
||||
* @param array $condition
|
||||
* @return array
|
||||
*/
|
||||
public function deleteCollect($condition = [])
|
||||
{
|
||||
$res = model('fenxiao_goods_collect')->delete($condition);
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分销商关注商品数信息
|
||||
* @param $condition
|
||||
* @param $field
|
||||
* @return array
|
||||
*/
|
||||
public function getCollectInfo($condition, $field = '*')
|
||||
{
|
||||
$res = model('fenxiao_goods_collect')->getInfo($condition, $field);
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分销商关注商品分页列表
|
||||
* @param array $condition
|
||||
* @param int $page
|
||||
* @param int $page_size
|
||||
* @param string $order
|
||||
* @param string $field
|
||||
* @param string $order
|
||||
* @return array
|
||||
*/
|
||||
public function getCollectPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'fgc.create_time desc', $field = 'fgc.collect_id,fgc.member_id,fgc.fenxiao_id,fgc.create_time,gs.sku_id,gs.sku_name,gs.discount_price,gs.stock,gs.sale_num,gs.sku_image,gs.site_id,gs.fenxiao_price,g.goods_image,g.fenxiao_type')
|
||||
{
|
||||
$alias = 'fgc';
|
||||
$join = [
|
||||
[ 'goods_sku gs', 'fgc.sku_id = gs.sku_id', 'inner' ],
|
||||
[ 'goods g', 'fgc.goods_id = g.goods_id', 'inner' ]
|
||||
];
|
||||
|
||||
$list = model('fenxiao_goods_collect')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
}
|
||||
188
addon/fenxiao/model/FenxiaoGoodsSku.php
Executable file
188
addon/fenxiao/model/FenxiaoGoodsSku.php
Executable file
@@ -0,0 +1,188 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\fenxiao\model;
|
||||
|
||||
use app\model\BaseModel;
|
||||
|
||||
|
||||
/**
|
||||
* 分销
|
||||
*/
|
||||
class FenxiaoGoodsSku extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 添加分销商品
|
||||
* @param $data
|
||||
* @return array
|
||||
*/
|
||||
public function addSku($data)
|
||||
{
|
||||
$res = model('fenxiao_goods_sku')->add($data);
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑分销商品
|
||||
* @param $data
|
||||
* @param array $condition
|
||||
* @return array
|
||||
*/
|
||||
public function editSku($data, $condition = [])
|
||||
{
|
||||
$data[ 'update_time' ] = time();
|
||||
$res = model('fenxiao_goods_sku')->update($data, $condition);
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除分销商品
|
||||
* @param array $condition
|
||||
* @return array
|
||||
*/
|
||||
public function deleteSku($condition = [])
|
||||
{
|
||||
$res = model('fenxiao_goods_sku')->delete($condition);
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分销商品详情
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public function getFenxiaoGoodsSkuDetail($condition = [], $field = 'fgs.goods_sku_id,fgs.goods_id,fgs.sku_id,fgs.level_id,fgs.one_rate,fgs.one_money,fgs.two_rate,fgs.two_money,fgs.three_rate,fgs.three_money,gs.discount_price,gs.fenxiao_price')
|
||||
{
|
||||
$alias = 'fgs';
|
||||
$join = [
|
||||
[ 'goods_sku gs', 'fgs.sku_id = gs.sku_id', 'inner' ],
|
||||
[ 'goods g', 'g.goods_id = gs.goods_id', 'inner' ]
|
||||
];
|
||||
$list = model('fenxiao_goods_sku')->getInfo($condition, $field, $alias, $join);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分销sku列表
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
* @param string $order
|
||||
* @param null $limit
|
||||
* @return array
|
||||
*/
|
||||
public function getSkuList($condition = [], $field = '*', $order = '', $limit = null)
|
||||
{
|
||||
$list = model('fenxiao_goods_sku')->getList($condition, $field, $order, '', '', '', $limit);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分销商品分页列表
|
||||
* @param array $condition
|
||||
* @param int $page
|
||||
* @param int $page_size
|
||||
* @param string $order
|
||||
* @param string $field
|
||||
* @param string $order
|
||||
* @return array
|
||||
*/
|
||||
public function getFenxiaoGoodsSkuPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'g.create_time desc', $field = 'g.goods_id,g.label_name,g.goods_name,g.goods_image,g.sku_id,gs.sku_name,gs.discount_price,gs.price,gs.stock,gs.sale_num,gs.sku_image,gs.fenxiao_price,g.fenxiao_type,(g.sale_num + g.virtual_sale) as sale_sort')
|
||||
{
|
||||
$alias = 'g';
|
||||
$join = [
|
||||
[ 'goods_sku gs', 'g.sku_id = gs.sku_id', 'inner' ],
|
||||
];
|
||||
$res = model('goods')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
|
||||
foreach ($res[ 'list' ] as $k => $v) {
|
||||
if (isset($v[ 'goods_stock' ])) {
|
||||
$res[ 'list' ][ $k ][ 'goods_stock' ] = numberFormat($res[ 'list' ][ $k ][ 'goods_stock' ]);
|
||||
}
|
||||
if (isset($v[ 'sale_num' ])) {
|
||||
$res[ 'list' ][ $k ][ 'sale_num' ] = numberFormat($res[ 'list' ][ $k ][ 'sale_num' ]);
|
||||
}
|
||||
if (isset($v[ 'virtual_sale' ])) {
|
||||
$res[ 'list' ][ $k ][ 'virtual_sale' ] = numberFormat($res[ 'list' ][ $k ][ 'virtual_sale' ]);
|
||||
}
|
||||
if (isset($v[ 'real_stock' ])) {
|
||||
$res[ 'list' ][ $k ][ 'real_stock' ] = numberFormat($res[ 'list' ][ $k ][ 'real_stock' ]);
|
||||
}
|
||||
if (isset($v[ 'stock' ])) {
|
||||
$res[ 'list' ][ $k ][ 'stock' ] = numberFormat($res[ 'list' ][ $k ][ 'stock' ]);
|
||||
}
|
||||
if (isset($v[ 'sale_sort' ])) {
|
||||
$res[ 'list' ][ $k ][ 'sale_sort' ] = numberFormat($res[ 'list' ][ $k ][ 'sale_sort' ]);
|
||||
}
|
||||
}
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量添加分销商品
|
||||
* @param $data
|
||||
* @return array
|
||||
*/
|
||||
public function addSkuList($data)
|
||||
{
|
||||
$re = model('fenxiao_goods_sku')->addList($data);
|
||||
return $this->success($re);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分销商品信息
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public function getFenxiaoGoodsSkuInfo($condition = [], $field = '*')
|
||||
{
|
||||
$res = model('fenxiao_goods_sku')->getInfo($condition, $field);
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取商品一级分销佣金
|
||||
* @param $sku_id
|
||||
* @param $level_id
|
||||
* @return array
|
||||
*/
|
||||
public function getSkuFenxiaoCommission($sku_id, $level_id)
|
||||
{
|
||||
$commission = 0.00;
|
||||
|
||||
$condition = [ [ 'gs.sku_id', '=', $sku_id ], [ 'g.is_fenxiao', '=', 1 ] ];
|
||||
$join = [
|
||||
[ 'goods g', 'g.goods_id = gs.goods_id', 'inner' ]
|
||||
];
|
||||
$sku_info = model('goods_sku')->getInfo($condition, 'g.fenxiao_type,gs.fenxiao_price,gs.discount_price', 'gs', $join);
|
||||
|
||||
if (!empty($sku_info)) {
|
||||
$discount_price = $sku_info[ 'fenxiao_price' ] > 0 ? $sku_info[ 'fenxiao_price' ] : $sku_info[ 'discount_price' ];
|
||||
// 默认规则
|
||||
if ($sku_info[ 'fenxiao_type' ] == 1) {
|
||||
$fenxiao_level = new FenxiaoLevel();
|
||||
$level_info = $fenxiao_level->getLevelInfo([ [ 'level_id', '=', $level_id ] ], 'one_rate')[ 'data' ];
|
||||
if (!empty($level_info)) {
|
||||
$commission = number_format($discount_price * $level_info[ 'one_rate' ] / 100, 2, '.', '');
|
||||
}
|
||||
} else {
|
||||
$fenxiao_sku_info = $this->getFenxiaoGoodsSkuInfo([ [ 'level_id', '=', $level_id ], [ 'sku_id', '=', $sku_id ] ])[ 'data' ];
|
||||
if (!empty($fenxiao_sku_info)) {
|
||||
$commission = $fenxiao_sku_info[ 'one_money' ];
|
||||
if ($fenxiao_sku_info[ 'one_rate' ] > 0) {
|
||||
$commission = number_format($discount_price * $fenxiao_sku_info[ 'one_rate' ] / 100, 2, '.', '');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->success($commission);
|
||||
}
|
||||
}
|
||||
182
addon/fenxiao/model/FenxiaoLevel.php
Executable file
182
addon/fenxiao/model/FenxiaoLevel.php
Executable file
@@ -0,0 +1,182 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\fenxiao\model;
|
||||
|
||||
use app\model\BaseModel;
|
||||
|
||||
|
||||
/**
|
||||
* 分销
|
||||
*/
|
||||
class FenxiaoLevel extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* 添加分销等级
|
||||
* @param $data
|
||||
* @return array
|
||||
*/
|
||||
public function addLevel($data)
|
||||
{
|
||||
$data[ 'create_time' ] = time();
|
||||
$data[ 'status' ] = 1;
|
||||
|
||||
$res = model('fenxiao_level')->add($data);
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑分销等级
|
||||
* @param $data
|
||||
* @param array $condition
|
||||
* @return array
|
||||
*/
|
||||
public function editLevel($data, $condition = [])
|
||||
{
|
||||
$data[ 'update_time' ] = time();
|
||||
|
||||
$res = model('fenxiao_level')->update($data, $condition);
|
||||
if ($res) {
|
||||
if (isset($data[ 'level_name' ]) && $data[ 'level_name' ] != '') {
|
||||
model('fenxiao')->update([ 'level_name' => $data[ 'level_name' ] ], $condition);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除分销等级
|
||||
* @param $level_id
|
||||
* @param $site_id
|
||||
* @return array
|
||||
*/
|
||||
public function deleteLevel($level_id, $site_id)
|
||||
{
|
||||
$fenxiao_model = new Fenxiao();
|
||||
$fenxiao_list = $fenxiao_model->getFenxiaoList([ [ 'level_id', '=', $level_id ] ], 'fenxiao_id');
|
||||
if (empty($fenxiao_list[ 'data' ])) {
|
||||
$res = model('fenxiao_level')->delete([ [ 'level_id', '=', $level_id ], [ 'site_id', '=', $site_id ] ]);
|
||||
return $this->success($res);
|
||||
} else {
|
||||
return $this->error('', '该分销等级存在其他分销商,无法删除');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分销等级信息
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public function getLevelInfo($condition = [], $field = '*')
|
||||
{
|
||||
$res = model('fenxiao_level')->getInfo($condition, $field);
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public function getLevelColumn($condition = [], $field = 'level_id')
|
||||
{
|
||||
$list = model('fenxiao_level')->getColumn($condition, $field);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分销商等级列表
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
* @param string $order
|
||||
* @param null $limit
|
||||
* @return array
|
||||
*/
|
||||
public function getLevelList($condition = [], $field = '*', $order = '', $limit = null)
|
||||
{
|
||||
$list = model('fenxiao_level')->getList($condition, $field, $order, '', '', '', $limit);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分销商等级分页列表
|
||||
* @param array $condition
|
||||
* @param int $page
|
||||
* @param int $page_size
|
||||
* @param string $order
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public function getLevelPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
|
||||
{
|
||||
$list = model('fenxiao_level')->pageList($condition, $field, $order, $page, $page_size);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取最低的分销商等级
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public function getMinLevel($condition = [], $field = '*')
|
||||
{
|
||||
$info = model('fenxiao_level')->getFirstData($condition, $field, 'level_num asc,one_rate asc');
|
||||
return $this->success($info);
|
||||
}
|
||||
|
||||
/**
|
||||
* 某项排序的第一个
|
||||
* @param $condition
|
||||
* @param $field
|
||||
* @param $order
|
||||
* @return array
|
||||
*/
|
||||
public function getLevelFirst($condition, $field, $order)
|
||||
{
|
||||
$first = model('fenxiao_level')->getFirstData($condition, $field, $order);
|
||||
return $this->success($first);
|
||||
}
|
||||
|
||||
/**
|
||||
* 平台端获取分销商列表
|
||||
* @param array $condition
|
||||
* @param int $page
|
||||
* @param int $page_size
|
||||
* @param string $order
|
||||
* @param string $field
|
||||
*/
|
||||
public function getLevelPageListInAdmin($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*')
|
||||
{
|
||||
$list = $this->getLevelPageList($condition, $page, $page_size, $order, $field);
|
||||
if (!empty($list[ 'data' ][ 'list' ])) {
|
||||
$level_id_arr = [];
|
||||
foreach ($list[ 'data' ][ 'list' ] as $key => $val) {
|
||||
$level_id_arr[] = $val['level_id'];
|
||||
}
|
||||
$level_ids = implode(',', $level_id_arr);
|
||||
|
||||
$fenxiao_list = model('fenxiao')->getList([['level_id', 'in', $level_ids]], 'level_id, count(*) as count', '', '', '', 'level_id');
|
||||
|
||||
if(!empty($fenxiao_list)) {
|
||||
$key = array_column($fenxiao_list, 'level_id');
|
||||
$fenxiao_list = array_combine($key, $fenxiao_list);
|
||||
}
|
||||
foreach ($list[ 'data' ][ 'list' ] as $key => $val) {
|
||||
$list[ 'data' ][ 'list' ][ $key ][ 'fenxiao_num' ] = $fenxiao_list['level_id'] ?? 0;
|
||||
}
|
||||
}
|
||||
return $list;
|
||||
}
|
||||
|
||||
}
|
||||
580
addon/fenxiao/model/FenxiaoOrder.php
Executable file
580
addon/fenxiao/model/FenxiaoOrder.php
Executable file
@@ -0,0 +1,580 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\fenxiao\model;
|
||||
|
||||
use app\dict\order_refund\OrderRefundDict;
|
||||
use app\model\BaseModel;
|
||||
use app\model\message\Message;
|
||||
use app\model\system\Stat;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* 分销商品
|
||||
*/
|
||||
class FenxiaoOrder extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* 分销订单计算
|
||||
* @param $order
|
||||
* @return array
|
||||
*/
|
||||
public function calculate($order)
|
||||
{
|
||||
//获取分销基础配置
|
||||
$config_model = new Config();
|
||||
$fenxiao_basic_config = $config_model->getFenxiaoBasicsConfig($order[ 'site_id' ])['data'] ?? [];
|
||||
$level_config = $fenxiao_basic_config[ 'value' ][ 'level' ];
|
||||
if (empty($level_config)) {
|
||||
return $this->success();
|
||||
}
|
||||
//检测分销商上级关系
|
||||
$member_info = model('member')->getInfo([ [ 'member_id', '=', $order[ 'member_id' ] ] ], 'fenxiao_id,is_fenxiao');
|
||||
//如果没有分销商直接返回不计算,没有考虑首次付款上下级绑定
|
||||
if (empty($member_info)) {
|
||||
return $this->success();
|
||||
}
|
||||
if ($member_info[ 'fenxiao_id' ] == 0) {
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
$fenxiao_id = $member_info[ 'fenxiao_id' ];
|
||||
$fenxiao_info = model('fenxiao')->getInfo([ [ 'fenxiao_id', '=', $fenxiao_id ], [ 'is_delete', '=', 0 ] ]);
|
||||
if (empty($fenxiao_info)) {
|
||||
return $this->success();
|
||||
}
|
||||
// 如果购买人是分销商 并且未开启分销商自购
|
||||
if ($member_info[ 'is_fenxiao' ] && $fenxiao_basic_config[ 'value' ][ 'self_purchase_rebate' ] == 0) {
|
||||
if (empty($fenxiao_info[ 'parent' ])) return $this->success();
|
||||
$fenxiao_info = model('fenxiao')->getInfo([ [ 'fenxiao_id', '=', $fenxiao_info[ 'parent' ] ], [ 'is_delete', '=', 0 ] ]);
|
||||
if (empty($fenxiao_info)) return $this->success();
|
||||
}
|
||||
|
||||
//判断几级分销
|
||||
$parent_fenxiao_info = $level_config >= 2 ? model('fenxiao')->getInfo([ [ 'fenxiao_id', '=', $fenxiao_info[ 'parent' ] ], [ 'is_delete', '=', 0 ] ], 'fenxiao_id, fenxiao_name, status, parent') : [];
|
||||
$grand_parent_fenxiao_info = $level_config >= 3 && !empty($parent_fenxiao_info[ 'parent' ]) ? model('fenxiao')->getInfo([ [ 'fenxiao_id', '=', $parent_fenxiao_info[ 'parent' ] ], [ 'is_delete', '=', 0 ] ], 'fenxiao_id, fenxiao_name, status') : [];
|
||||
$order_goods = model('order_goods')->getList([ [ 'order_id', '=', $order[ 'order_id' ] ], [ 'is_fenxiao', '=', 1 ] ], 'order_goods_id, goods_id, sku_id, sku_name, sku_image, sku_no, is_virtual, price, cost_price, num, goods_money, cost_money, delivery_no, delivery_status, real_goods_money');
|
||||
if (empty($order_goods)) return $this->success();
|
||||
|
||||
model('fenxiao_order')->delete([ [ 'order_id', '=', $order[ 'order_id' ] ] ]);
|
||||
//获取分销等级
|
||||
foreach ($order_goods as $k => $v) {
|
||||
$v[ 'num' ] = numberFormat($v[ 'num' ]);
|
||||
|
||||
//商品信息管理
|
||||
$goods_info = model('goods')->getInfo([ [ 'goods_id', '=', $v[ 'goods_id' ] ] ], 'is_fenxiao, fenxiao_type');
|
||||
if ($goods_info[ 'is_fenxiao' ] != 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$sku_info = model('goods_sku')->getInfo([ [ 'sku_id', '=', $v[ 'sku_id' ] ] ], 'fenxiao_price');
|
||||
if (!empty($sku_info) && $sku_info[ 'fenxiao_price' ] > 0) $v[ 'real_goods_money' ] = $sku_info[ 'fenxiao_price' ] * $v[ 'num' ];
|
||||
|
||||
$commission = 0;
|
||||
$commission_rate = 0;
|
||||
$order_fenxiao_data = [
|
||||
'one_rate' => 0,
|
||||
'one_commission' => 0,
|
||||
'two_rate' => 0,
|
||||
'two_commission' => 0,
|
||||
'three_rate' => 0,
|
||||
];
|
||||
|
||||
if ($goods_info[ 'fenxiao_type' ] == 2) {
|
||||
// 自定义分销规则
|
||||
$fenxiao_level = model('fenxiao_goods_sku')->getInfo([ [ 'goods_id', '=', $v[ 'goods_id' ] ], [ 'sku_id', '=', $v[ 'sku_id' ] ], [ 'level_id', '=', $fenxiao_info[ 'level_id' ] ] ]);
|
||||
if (empty($fenxiao_level)) continue;
|
||||
|
||||
if ($fenxiao_info[ 'status' ] == 1) {
|
||||
if ($fenxiao_level[ 'one_rate' ] > 0) {
|
||||
$commission_rate += $order_fenxiao_data[ 'one_rate' ] = $fenxiao_level[ 'one_rate' ];
|
||||
$commission += $order_fenxiao_data[ 'one_commission' ] = $fenxiao_level[ 'one_rate' ] * $v[ 'real_goods_money' ] / 100;
|
||||
} else {
|
||||
$commission_rate += $order_fenxiao_data[ 'one_rate' ] = round($fenxiao_level[ 'one_money' ] * $v[ 'num' ] / $v[ 'real_goods_money' ], 2);
|
||||
$commission += $order_fenxiao_data[ 'one_commission' ] = $fenxiao_level[ 'one_money' ] * $v[ 'num' ];
|
||||
}
|
||||
}
|
||||
if (!empty($parent_fenxiao_info) && $parent_fenxiao_info[ 'status' ] == 1) {
|
||||
if ($fenxiao_level[ 'two_rate' ] > 0) {
|
||||
$commission_rate += $order_fenxiao_data[ 'two_rate' ] = $fenxiao_level[ 'two_rate' ];
|
||||
$commission += $order_fenxiao_data[ 'two_commission' ] = $fenxiao_level[ 'two_rate' ] * $v[ 'real_goods_money' ] / 100;
|
||||
} else {
|
||||
$commission_rate += $order_fenxiao_data[ 'two_rate' ] = round($fenxiao_level[ 'two_money' ] * $v[ 'num' ] / $v[ 'real_goods_money' ], 2);
|
||||
$commission += $order_fenxiao_data[ 'two_commission' ] = $fenxiao_level[ 'two_money' ] * $v[ 'num' ];
|
||||
}
|
||||
}
|
||||
if (!empty($grand_parent_fenxiao_info) && $grand_parent_fenxiao_info[ 'status' ] == 1) {
|
||||
if ($fenxiao_level[ 'three_rate' ] > 0) {
|
||||
$commission_rate += $order_fenxiao_data[ 'three_rate' ] = $fenxiao_level[ 'three_rate' ];
|
||||
$commission += $order_fenxiao_data[ 'three_commission' ] = $fenxiao_level[ 'three_rate' ] * $v[ 'real_goods_money' ] / 100;
|
||||
} else {
|
||||
$commission_rate += $order_fenxiao_data[ 'three_rate' ] = round($fenxiao_level[ 'three_money' ] * $v[ 'num' ] / $v[ 'real_goods_money' ], 2);
|
||||
$commission += $order_fenxiao_data[ 'three_commission' ] = $fenxiao_level[ 'three_money' ] * $v[ 'num' ];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 默认规则
|
||||
$fenxiao_level = model('fenxiao_level')->getInfo([ [ 'level_id', '=', $fenxiao_info[ 'level_id' ] ] ]);
|
||||
if ($fenxiao_info[ 'status' ] == 1) {
|
||||
if ($fenxiao_level[ 'one_rate' ] > 0) {
|
||||
$commission_rate += $order_fenxiao_data[ 'one_rate' ] = $fenxiao_level[ 'one_rate' ];
|
||||
$commission += $order_fenxiao_data[ 'one_commission' ] = $fenxiao_level[ 'one_rate' ] * $v[ 'real_goods_money' ] / 100;
|
||||
} else {
|
||||
$order_fenxiao_data[ 'one_rate' ] = 0;
|
||||
$order_fenxiao_data[ 'one_commission' ] = 0;
|
||||
}
|
||||
}
|
||||
if (!empty($parent_fenxiao_info) && $parent_fenxiao_info[ 'status' ] == 1) {
|
||||
if ($fenxiao_level[ 'two_rate' ] > 0) {
|
||||
$commission_rate += $order_fenxiao_data[ 'two_rate' ] = $fenxiao_level[ 'two_rate' ];
|
||||
$commission += $order_fenxiao_data[ 'two_commission' ] = $fenxiao_level[ 'two_rate' ] * $v[ 'real_goods_money' ] / 100;
|
||||
} else {
|
||||
$order_fenxiao_data[ 'two_rate' ] = 0;
|
||||
$order_fenxiao_data[ 'two_commission' ] = 0;
|
||||
}
|
||||
}
|
||||
if (!empty($grand_parent_fenxiao_info) && $grand_parent_fenxiao_info[ 'status' ] == 1) {
|
||||
if ($fenxiao_level[ 'three_rate' ] > 0) {
|
||||
$commission_rate += $order_fenxiao_data[ 'three_rate' ] = $fenxiao_level[ 'three_rate' ];
|
||||
$commission += $order_fenxiao_data[ 'three_commission' ] = $fenxiao_level[ 'three_rate' ] * $v[ 'real_goods_money' ] / 100;
|
||||
} else {
|
||||
$order_fenxiao_data[ 'three_rate' ] = 0;
|
||||
$order_fenxiao_data[ 'three_commission' ] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
//启动分销
|
||||
$data = [
|
||||
'order_id' => $order[ 'order_id' ],
|
||||
'order_no' => $order[ 'order_no' ],
|
||||
'order_goods_id' => $v[ 'order_goods_id' ],
|
||||
'site_id' => $order[ 'site_id' ],
|
||||
'site_name' => $order[ 'site_name' ],
|
||||
'goods_id' => $v[ 'goods_id' ],
|
||||
'sku_id' => $v[ 'sku_id' ],
|
||||
'sku_name' => $v[ 'sku_name' ],
|
||||
'sku_image' => $v[ 'sku_image' ],
|
||||
'price' => $v[ 'price' ],
|
||||
'num' => $v[ 'num' ],
|
||||
'real_goods_money' => $v[ 'real_goods_money' ],
|
||||
'member_id' => $order[ 'member_id' ],
|
||||
'member_name' => $order[ 'name' ] ?? '',
|
||||
'member_mobile' => $order[ 'mobile' ] ?? '',
|
||||
'full_address' => $order[ 'full_address' ] ?? '' . $order[ 'address' ] ?? '',
|
||||
'commission' => $commission,
|
||||
'commission_rate' => $commission_rate,
|
||||
'one_fenxiao_id' => $fenxiao_info[ 'fenxiao_id' ],
|
||||
'one_rate' => empty($order_fenxiao_data[ 'one_rate' ]) ? 0 : $order_fenxiao_data[ 'one_rate' ],
|
||||
'one_commission' => empty($order_fenxiao_data[ 'one_commission' ]) ? 0 : $order_fenxiao_data[ 'one_commission' ],
|
||||
'one_fenxiao_name' => $fenxiao_info[ 'fenxiao_name' ],
|
||||
'two_fenxiao_id' => empty($parent_fenxiao_info) ? 0 : $parent_fenxiao_info[ 'fenxiao_id' ],
|
||||
'two_rate' => empty($order_fenxiao_data[ 'two_rate' ]) ? 0 : $order_fenxiao_data[ 'two_rate' ],
|
||||
'two_commission' => empty($order_fenxiao_data[ 'two_commission' ]) ? 0 : $order_fenxiao_data[ 'two_commission' ],
|
||||
'two_fenxiao_name' => empty($parent_fenxiao_info) ? '' : $parent_fenxiao_info[ 'fenxiao_name' ],
|
||||
'three_fenxiao_id' => empty($grand_parent_fenxiao_info) ? '' : $grand_parent_fenxiao_info[ 'fenxiao_id' ],
|
||||
'three_rate' => empty($order_fenxiao_data[ 'three_rate' ]) ? 0 : $order_fenxiao_data[ 'three_rate' ],
|
||||
'three_commission' => empty($order_fenxiao_data[ 'three_commission' ]) ? 0 : $order_fenxiao_data[ 'three_commission' ],
|
||||
'three_fenxiao_name' => empty($grand_parent_fenxiao_info) ? '' : $grand_parent_fenxiao_info[ 'fenxiao_name' ],
|
||||
'create_time' => time()
|
||||
];
|
||||
model('fenxiao_order')->add($data);
|
||||
}
|
||||
// 分销商检测升级
|
||||
event('FenxiaoUpgrade', $member_info[ 'fenxiao_id' ]);
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单退款
|
||||
* @param $order_goods_id
|
||||
* @return array
|
||||
*/
|
||||
public function refund($data)
|
||||
{
|
||||
$order_goods_info = $data['order_goods_info'];
|
||||
if ($order_goods_info[ 'refund_mode' ] == OrderRefundDict::refund) {
|
||||
$res = model('fenxiao_order')->update([ 'is_refund' => 1 ], [ [ 'order_goods_id', '=', $order_goods_info['order_goods_id'] ] ]);
|
||||
return $this->success($res);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单结算
|
||||
* @param $order_id
|
||||
* @return array
|
||||
*/
|
||||
public function settlement($order_id)
|
||||
{
|
||||
//获取未退款的和未结算的分销订单
|
||||
$fenxiao_orders = model('fenxiao_order')->getList([ [ 'order_id', '=', $order_id ], [ 'is_settlement', '=', 0 ], [ 'is_refund', '=', 0 ] ], '*');
|
||||
//同时修改分销订单状态为已结算
|
||||
model('fenxiao_order')->startTrans();
|
||||
try {
|
||||
model('fenxiao_order')->update([ 'is_settlement' => 1 ], [ [ 'order_id', '=', $order_id ] ]);
|
||||
$commission = 0;
|
||||
$fenxiao_account = new FenxiaoAccount();
|
||||
$site_id = 0;
|
||||
foreach ($fenxiao_orders as $fenxiao_order) {
|
||||
$site_id = $fenxiao_order[ 'site_id' ];
|
||||
$commission += $fenxiao_order[ 'one_commission' ];
|
||||
$fenxiao_account->addAccount($fenxiao_order[ 'one_fenxiao_id' ], $fenxiao_order[ 'one_fenxiao_name' ], 'order', $fenxiao_order[ 'one_commission' ], $fenxiao_order[ 'fenxiao_order_id' ]);
|
||||
|
||||
// 分销佣金发放通知
|
||||
( new Message() )->sendMessage([
|
||||
'keywords' => 'COMMISSION_GRANT',
|
||||
'order_id' => $fenxiao_order[ 'fenxiao_order_id' ],
|
||||
'site_id' => $fenxiao_order[ 'site_id' ],
|
||||
'level' => 'one',
|
||||
]);
|
||||
|
||||
model('fenxiao')->setInc([ [ 'fenxiao_id', '=', $fenxiao_order[ 'one_fenxiao_id' ] ] ], 'total_commission', $fenxiao_order[ 'one_commission' ]);
|
||||
|
||||
if ($fenxiao_order[ 'two_commission' ] > 0) {
|
||||
$commission += $fenxiao_order[ 'two_commission' ];
|
||||
$fenxiao_account->addAccount($fenxiao_order[ 'two_fenxiao_id' ], $fenxiao_order[ 'two_fenxiao_name' ], 'order', $fenxiao_order[ 'two_commission' ], $fenxiao_order[ 'fenxiao_order_id' ]);
|
||||
|
||||
// 分销佣金发放通知
|
||||
( new Message() )->sendMessage([
|
||||
'keywords' => 'COMMISSION_GRANT',
|
||||
'order_id' => $fenxiao_order[ 'fenxiao_order_id' ],
|
||||
'site_id' => $fenxiao_order[ 'site_id' ],
|
||||
'level' => 'two',
|
||||
]);
|
||||
|
||||
model('fenxiao')->setInc([ [ 'fenxiao_id', '=', $fenxiao_order[ 'two_fenxiao_id' ] ] ], 'total_commission', $fenxiao_order[ 'two_commission' ]);
|
||||
}
|
||||
if ($fenxiao_order[ 'three_commission' ] > 0) {
|
||||
$commission += $fenxiao_order[ 'three_commission' ];
|
||||
$fenxiao_account->addAccount($fenxiao_order[ 'three_fenxiao_id' ], $fenxiao_order[ 'three_fenxiao_name' ], 'order', $fenxiao_order[ 'three_commission' ], $fenxiao_order[ 'fenxiao_order_id' ]);
|
||||
|
||||
// 分销佣金发放通知
|
||||
( new Message() )->sendMessage([
|
||||
'keywords' => 'COMMISSION_GRANT',
|
||||
'order_id' => $fenxiao_order[ 'fenxiao_order_id' ],
|
||||
'site_id' => $fenxiao_order[ 'site_id' ],
|
||||
'level' => 'three',
|
||||
]);
|
||||
|
||||
model('fenxiao')->setInc([ [ 'fenxiao_id', '=', $fenxiao_order[ 'three_fenxiao_id' ] ] ], 'total_commission', $fenxiao_order[ 'three_commission' ]);
|
||||
}
|
||||
|
||||
}
|
||||
$stat_model = new Stat();
|
||||
$stat_model->switchStat([ 'type' => 'fenxiao_order', 'data' => [ 'order_id' => $order_id, 'site_id' => $site_id ] ]);
|
||||
//增加订单佣金结算
|
||||
model('order')->setInc([ [ 'order_id', '=', $order_id ] ], 'commission', $commission);
|
||||
model('fenxiao_order')->commit();
|
||||
return $this->success();
|
||||
} catch ( Exception $e) {
|
||||
model('fenxiao_order')->rollback();
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算对应分销商的第一次订单数量&&金额
|
||||
* @param $order_id
|
||||
* @return array
|
||||
*/
|
||||
public function calculateOrder($order_id)
|
||||
{
|
||||
$fenxiao_order_info = model('fenxiao_order')->getFirstData([ [ 'order_id', '=', $order_id ] ], 'one_fenxiao_id');
|
||||
if (!empty($fenxiao_order_info)) {
|
||||
$one_commission_sum = model('fenxiao_order')->getSum([ [ 'order_id', '=', $order_id ] ], 'one_commission');
|
||||
$one_fenxiao_total_order = model('fenxiao_order')->getSum([ [ 'order_id', '=', $order_id ] ], 'real_goods_money');
|
||||
model('fenxiao')->setInc([ [ 'fenxiao_id', '=', $fenxiao_order_info[ 'one_fenxiao_id' ] ] ], 'one_fenxiao_order_num');
|
||||
model('fenxiao')->setInc([ [ 'fenxiao_id', '=', $fenxiao_order_info[ 'one_fenxiao_id' ] ] ], 'one_fenxiao_order_money', $one_commission_sum);
|
||||
model('fenxiao')->setInc([ [ 'fenxiao_id', '=', $fenxiao_order_info[ 'one_fenxiao_id' ] ] ], 'one_fenxiao_total_order', $one_fenxiao_total_order);
|
||||
// 分销商检测升级
|
||||
event('FenxiaoUpgrade', $fenxiao_order_info[ 'one_fenxiao_id' ]);
|
||||
}
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分销订单列表
|
||||
* @param array $condition
|
||||
* @param int $page
|
||||
* @param int $page_size
|
||||
* @param string $order
|
||||
* @return array
|
||||
*/
|
||||
public function getFenxiaoOrderPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'fo.order_id DESC')
|
||||
{
|
||||
$field = '
|
||||
fo.fenxiao_order_id,fo.order_no,fo.site_id,fo.site_name,fo.sku_id,fo.sku_name,fo.sku_image,fo.price,fo.num,fo.real_goods_money,fo.member_name,
|
||||
fo.member_mobile,fo.one_fenxiao_name,fo.is_settlement,fo.commission,fo.is_refund,
|
||||
o.order_status_name,o.create_time,fo.one_fenxiao_id,fo.two_fenxiao_id,fo.three_fenxiao_id,fo.one_commission,fo.two_commission,fo.three_commission';
|
||||
|
||||
$alias = 'fo';
|
||||
$join = [
|
||||
[
|
||||
'order o',
|
||||
'fo.order_id = o.order_id',
|
||||
'inner'
|
||||
]
|
||||
];
|
||||
$list = model('fenxiao_order')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询订单信息
|
||||
* @param $condition
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public function getFenxiaoOrderInfo($condition, $field = '*')
|
||||
{
|
||||
$fenxiao_order_info = model('fenxiao_order')->getInfo($condition, $field);
|
||||
return $this->success($fenxiao_order_info);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询订单信息
|
||||
* @param $condition
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public function getFenxiaoOrderInfoNew($condition, $field = '*')
|
||||
{
|
||||
$alias = 'fo';
|
||||
$join = [
|
||||
[
|
||||
'order o',
|
||||
'o.order_id = fo.order_id',
|
||||
'left'
|
||||
]
|
||||
];
|
||||
$fenxiao_order_info = model('fenxiao_order')->getInfo($condition, $field, $alias, $join);
|
||||
return $this->success($fenxiao_order_info);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询分销订单列表(管理端调用)
|
||||
* @param array $condition
|
||||
* @param int $page
|
||||
* @param int $page_size
|
||||
* @param string $order
|
||||
* @return array
|
||||
*/
|
||||
public function getFenxiaoOrderPage($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = 'order_id DESC')
|
||||
{
|
||||
$field = 'order_id,order_no,site_name,member_name,create_time,is_settlement,fenxiao_order_id';
|
||||
$list = model('fenxiao_order')->pageList($condition, $field, $order, $page, $page_size, 'fo', [], 'order_id');
|
||||
if (!empty($list[ 'list' ])) {
|
||||
$order_id_arr = [];
|
||||
foreach ($list['list'] as $k => $v)
|
||||
{
|
||||
$order_id_arr[] = $v['order_id'];
|
||||
}
|
||||
$order_ids = implode(',', $order_id_arr);
|
||||
$order_list = model('order')->getList([ [ 'order_id', 'in', $order_ids ] ], 'order_id,name,full_address,mobile,order_status_name');
|
||||
$order_goods_list = model('fenxiao_order')->getList([ [ 'order_id', 'in', $order_ids ] ]);
|
||||
foreach ($list[ 'list' ] as $k => $item) {
|
||||
foreach ($order_list as $k_order => $v_order)
|
||||
{
|
||||
if($item['order_id'] == $v_order['order_id'])
|
||||
{
|
||||
$list[ 'list' ][ $k ] = array_merge($list[ 'list' ][ $k ], $v_order);
|
||||
}
|
||||
}
|
||||
$list[ 'list' ][ $k ][ 'order_goods' ] = [];
|
||||
foreach ($order_goods_list as $k_order_goods => $v_order_goods)
|
||||
{
|
||||
if($item['order_id'] == $v_order_goods['order_id'])
|
||||
{
|
||||
$list[ 'list' ][ $k ][ 'order_goods' ][] = $v_order_goods;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分销订单详情
|
||||
* @param $condition
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public function getFenxiaoOrderDetail($condition, $field = '*')
|
||||
{
|
||||
$order_info = model('order')->getInfo($condition, $field);
|
||||
if (!empty($order_info)) {
|
||||
$order_goods = model('fenxiao_order')->getList([ [ 'order_id', '=', $order_info[ 'order_id' ] ] ]);
|
||||
$member_info = model('member')->getInfo([ 'member_id' => $order_info[ 'member_id' ] ], 'nickname');
|
||||
$order_info[ 'order_goods' ] = $order_goods;
|
||||
$order_info[ 'nickname' ] = $member_info[ 'nickname' ];
|
||||
}
|
||||
return $this->success($order_info);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分销订单数量
|
||||
* @param $condition
|
||||
* @return array
|
||||
*/
|
||||
public function getFenxiaoOrderCount($condition)
|
||||
{
|
||||
$count = model('fenxiao_order')->getCount($condition);
|
||||
return $this->success($count);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分销订单总和
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
* @param string $alias
|
||||
* @param null $join
|
||||
* @return array
|
||||
*/
|
||||
public function getFenxiaoOrderSum(array $condition, $field = '', $alias = 'a', $join = null)
|
||||
{
|
||||
$data = model('fenxiao_order')->getSum($condition, $field, $alias, $join);
|
||||
return $this->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询订单数据并导出
|
||||
* @param $condition
|
||||
* @param int $site_id
|
||||
*/
|
||||
public function orderExport($condition, $site_id = 0)
|
||||
{
|
||||
$field = [
|
||||
'order_no' => '订单编号',
|
||||
'site_name' => '站点名称',
|
||||
'sku_name' => '商品名称',
|
||||
'member_name' => '购买人',
|
||||
'member_mobile' => '购买人电话',
|
||||
'commission' => '总佣金',
|
||||
'one_rate' => '一级分销比例',
|
||||
'one_commission' => '一级分销佣金',
|
||||
'one_fenxiao_name' => '一级分销商名',
|
||||
'two_rate' => '二级分销比例',
|
||||
'two_commission' => '二级分销佣金',
|
||||
'two_fenxiao_name' => '二级分销商名',
|
||||
'three_rate' => '三级分销比例',
|
||||
'three_commission' => '三级分销佣金',
|
||||
'three_fenxiao_name' => '三级分销商名',
|
||||
'is_settlement' => '是否结算',
|
||||
'is_refund' => '是否退款',
|
||||
'province_name' => '省',
|
||||
'city_name' => '市',
|
||||
'district_name' => '县',
|
||||
'full_address' => '详细地址',
|
||||
'order_status_name' => '订单状态'
|
||||
];
|
||||
|
||||
$fields = 'fo.*,o.address,o.full_address,o.order_status_name';
|
||||
$alias = 'fo';
|
||||
$join = [
|
||||
[
|
||||
'order o',
|
||||
'o.order_id = fo.order_id',
|
||||
'left'
|
||||
]
|
||||
];
|
||||
|
||||
$list = model('fenxiao_order')->getList($condition, $fields, '', $alias, $join);
|
||||
$head_html = [];
|
||||
$line_html = [];
|
||||
foreach ($field as $k => $v) {
|
||||
$head_html[] = $v;
|
||||
$line_html[] = $k;
|
||||
}
|
||||
|
||||
$temp_line = implode(',', $head_html) . "\n";
|
||||
$html = str_replace("\n", '', $temp_line) . "\n";
|
||||
$line = implode(',', $line_html);
|
||||
$html .= str_replace("\n", '', $line) . "\n";
|
||||
|
||||
$temp = [];
|
||||
foreach ($line_html as $temp_line_k => $temp_line_v) {
|
||||
$temp[] = "{\$$temp_line_v}";
|
||||
}
|
||||
|
||||
$tempLine = implode(',', $temp) . "\n";
|
||||
|
||||
foreach ($list as $item) {
|
||||
$new_line_value = $tempLine;
|
||||
$address_arr = explode('-', $item[ 'full_address' ]);
|
||||
$item[ 'province_name' ] = !empty($address_arr[ 0 ]) ? $address_arr[ 0 ] : '';
|
||||
$item[ 'city_name' ] = !empty($address_arr[ 1 ]) ? $address_arr[ 1 ] : '';
|
||||
$item[ 'district_name' ] = !empty($address_arr[ 2 ]) ? $address_arr[ 2 ] : '';
|
||||
$item[ 'is_settlement' ] = $item[ 'is_settlement' ] == 0 ? '否' : '是';
|
||||
$item[ 'is_refund' ] = $item[ 'is_refund' ] == 0 ? '否' : '是';
|
||||
|
||||
foreach ($item as $key => $val) {
|
||||
if ($key == 'full_address') {
|
||||
$address = $item[ 'address' ] ?? '';
|
||||
$val = $val . $address;
|
||||
}
|
||||
|
||||
//CSV比较简单,记得转义 逗号就好
|
||||
$values = str_replace(',', '\\', $val . "\t");
|
||||
$values = str_replace("\n", '', $values);
|
||||
$new_line_value = str_replace("{\$$key}", $values, $new_line_value);
|
||||
|
||||
}
|
||||
|
||||
$html .= $new_line_value;
|
||||
}
|
||||
|
||||
$filename = date('YmdHis') . '.csv'; //设置文件名
|
||||
header('Content-type:text/csv');
|
||||
header('Content-Disposition:attachment;filename=' . $filename);
|
||||
header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
|
||||
header('Expires:0');
|
||||
header('Pragma:public');
|
||||
exit(mb_convert_encoding($html, 'GBK', 'UTF-8'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 给csv写入新的数据
|
||||
* @param $item_list
|
||||
* @param $field_key
|
||||
* @param $temp_line
|
||||
* @param $fp
|
||||
*/
|
||||
public function itemExport($item_list, $field_key, $temp_line, $fp)
|
||||
{
|
||||
$item_list = $item_list->toArray();
|
||||
foreach ($item_list as $k => $item_v) {
|
||||
$new_line_value = $temp_line;
|
||||
//省市县
|
||||
$address_arr = explode('-', $item_v[ 'full_address' ]);
|
||||
|
||||
$item_v[ 'province_name' ] = $address_arr[ 0 ] ?: '';
|
||||
$item_v[ 'city_name' ] = $address_arr[ 1 ] ?: '';
|
||||
$item_v[ 'district_name' ] = $address_arr[ 2 ] ?: '';
|
||||
|
||||
foreach ($item_v as $key => $value) {
|
||||
|
||||
if ($key == 'full_address') {
|
||||
$address = $item_v[ 'address' ] ?? '';
|
||||
$value = $value . $address;
|
||||
}
|
||||
//CSV比较简单,记得转义 逗号就好
|
||||
$values = str_replace(',', '\\', $value . "\t");
|
||||
$values = str_replace("\n", '', $values);
|
||||
$new_line_value = str_replace("{\$$key}", $values, $new_line_value);
|
||||
}
|
||||
//写入第一行表头
|
||||
fwrite($fp, $new_line_value);
|
||||
dump($new_line_value);
|
||||
exit;
|
||||
//销毁变量, 防止内存溢出
|
||||
unset($new_line_value);
|
||||
}
|
||||
}
|
||||
}
|
||||
96
addon/fenxiao/model/FenxiaoStat.php
Executable file
96
addon/fenxiao/model/FenxiaoStat.php
Executable file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\fenxiao\model;
|
||||
|
||||
use app\model\BaseModel;
|
||||
use app\model\system\Stat;
|
||||
|
||||
/**
|
||||
* 分销订单统计
|
||||
*/
|
||||
class FenxiaoStat extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* 写入新增分销商统计数据
|
||||
* @param $params
|
||||
* @return array
|
||||
*/
|
||||
public function addFenxiaoMemberStat($params)
|
||||
{
|
||||
$site_id = $params[ 'site_id' ] ?? 0;
|
||||
$stat_data = array (
|
||||
'site_id' => $site_id,
|
||||
'add_fenxiao_member_count' => 1
|
||||
);
|
||||
|
||||
$stat_model = new Stat();
|
||||
|
||||
$result = $stat_model->addShopStat($stat_data);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分销订单总额统计
|
||||
* @param $params
|
||||
* @return array
|
||||
*/
|
||||
public function addFenxiaoOrderStat($params)
|
||||
{
|
||||
$order_id = $params[ 'order_id' ];
|
||||
$site_id = $params[ 'site_id' ] ?? 0;
|
||||
$order_condition = array (
|
||||
[ 'order_id', '=', $order_id ],
|
||||
[ 'site_id', '=', $site_id ]
|
||||
);
|
||||
$order_info = model('order')->getInfo($order_condition);
|
||||
if (empty($order_info))
|
||||
return $this->error();
|
||||
|
||||
$order_money = $order_info[ 'order_money' ];
|
||||
$refund_money = $order_info[ 'refund_money' ];
|
||||
$stat_data = array (
|
||||
'site_id' => $site_id,
|
||||
'fenxiao_order_count' => 1,
|
||||
'fenxiao_order_total_money' => $order_money - $refund_money,
|
||||
);
|
||||
$stat_model = new Stat();
|
||||
|
||||
$result = $stat_model->addShopStat($stat_data);
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 分销佣金账户
|
||||
* @param int $site_id
|
||||
* @return array
|
||||
*/
|
||||
public function getFenxiaoAccountSum($site_id = 0)
|
||||
{
|
||||
$field = '
|
||||
sum(account) as account,
|
||||
sum(account_withdraw_apply) as account_withdraw_apply,
|
||||
sum(account_withdraw) as account_withdraw
|
||||
';
|
||||
$info = model('fenxiao')->getInfo([ [ 'site_id', '=', $site_id ] ], $field);
|
||||
if ($info[ 'account' ] == null) {
|
||||
$info[ 'account' ] = '0.00';
|
||||
}
|
||||
if ($info[ 'account_withdraw_apply' ] == null) {
|
||||
$info[ 'account_withdraw_apply' ] = '0.00';
|
||||
}
|
||||
if ($info[ 'account_withdraw' ] == null) {
|
||||
$info[ 'account_withdraw' ] = '0.00';
|
||||
}
|
||||
return $this->success($info);
|
||||
}
|
||||
}
|
||||
960
addon/fenxiao/model/FenxiaoWithdraw.php
Executable file
960
addon/fenxiao/model/FenxiaoWithdraw.php
Executable file
@@ -0,0 +1,960 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\fenxiao\model;
|
||||
|
||||
use app\model\BaseModel;
|
||||
use app\model\member\Member;
|
||||
use app\model\member\MemberAccount;
|
||||
use app\model\message\Message;
|
||||
use app\model\message\Sms;
|
||||
use app\model\shop\ShopAcceptMessage;
|
||||
use addon\wechat\model\Message as WechatMessage;
|
||||
use app\model\member\Member as MemberModel;
|
||||
use addon\weapp\model\Message as WeappMessage;
|
||||
use app\model\system\Pay;
|
||||
use app\model\system\PayTransfer;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 分销商提现
|
||||
*/
|
||||
class FenxiaoWithdraw extends BaseModel
|
||||
{
|
||||
//提现类型
|
||||
public $withdraw_type = [
|
||||
'balance' => '余额',
|
||||
'weixin' => '微信',
|
||||
'alipay' => '支付宝',
|
||||
'bank' => '银行卡',
|
||||
];
|
||||
|
||||
const STATUS_WAIT_AUDIT = 1;//待审核
|
||||
const STATUS_WAIT_TRANSFER = 2;//待转账
|
||||
const STATUS_SUCCESS = 3;//转账成功
|
||||
const STATUS_IN_PROCESS = 4;//转账中
|
||||
const STATUS_REFUSE = -1;//审核拒绝
|
||||
const STATUS_FAIL = -2;//转账失败
|
||||
|
||||
public $status = array (
|
||||
self::STATUS_WAIT_AUDIT => '待审核',
|
||||
self::STATUS_WAIT_TRANSFER => '待转账',
|
||||
self::STATUS_SUCCESS => '已转账',
|
||||
self::STATUS_IN_PROCESS => '转账中',
|
||||
self::STATUS_REFUSE => '已拒绝',
|
||||
self::STATUS_FAIL => '转账失败',
|
||||
);
|
||||
|
||||
public function getTransferType($site_id)
|
||||
{
|
||||
$pay_model = new Pay();
|
||||
$transfer_type_list = $pay_model->getTransferType($site_id);
|
||||
$transfer_type_list[ 'balance' ] = '余额';
|
||||
return $transfer_type_list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分销商申请提现
|
||||
* @param $data
|
||||
* @return array
|
||||
*/
|
||||
public function addFenxiaoWithdraw($data)
|
||||
{
|
||||
//获取分销商信息
|
||||
$fenxiao_model = new Fenxiao();
|
||||
$fenxiao_info = $fenxiao_model->getFenxiaoInfo([ [ 'member_id', '=', $data[ 'member_id' ] ] ], 'fenxiao_id,fenxiao_name,account');
|
||||
if (empty($fenxiao_info[ 'data' ])) {
|
||||
return $this->error('该分销商不存在');
|
||||
}
|
||||
|
||||
if ($fenxiao_info[ 'data' ][ 'account' ] < $data[ 'money' ]) {
|
||||
return $this->error('', '提现金额大于可提现金额');
|
||||
}
|
||||
//获取提现配置信息
|
||||
$config_model = new Config();
|
||||
$config_info = $config_model->getFenxiaoWithdrawConfig($data[ 'site_id' ])[ 'data' ][ 'value' ];
|
||||
if ($config_info[ 'withdraw' ] > $data[ 'money' ]) {
|
||||
return $this->error('', '提现金额小于最低提现金额');
|
||||
}
|
||||
if ($data[ 'money' ] >= $config_info[ 'min_no_fee' ] && $data[ 'money' ] <= $config_info[ 'max_no_fee' ]) {
|
||||
$data[ 'withdraw_rate' ] = 0;
|
||||
$data[ 'withdraw_rate_money' ] = 0;
|
||||
$data[ 'real_money' ] = $data[ 'money' ];
|
||||
} else {
|
||||
$data[ 'withdraw_rate' ] = $config_info[ 'withdraw_rate' ];
|
||||
if ($config_info[ 'withdraw_rate' ] == 0) {
|
||||
$data[ 'withdraw_rate' ] = 0;
|
||||
$data[ 'withdraw_rate_money' ] = 0;
|
||||
$data[ 'real_money' ] = $data[ 'money' ];
|
||||
} else {
|
||||
$data[ 'withdraw_rate' ] = $config_info[ 'withdraw_rate' ];
|
||||
$data[ 'withdraw_rate_money' ] = round($data[ 'money' ] * $config_info[ 'withdraw_rate' ] / 100, 2);
|
||||
$data[ 'real_money' ] = $data[ 'money' ] - $data[ 'withdraw_rate_money' ];
|
||||
}
|
||||
}
|
||||
|
||||
$data[ 'withdraw_no' ] = date('YmdHis') . rand(1000, 9999);
|
||||
$data[ 'create_time' ] = time();
|
||||
|
||||
model('fenxiao_withdraw')->startTrans();
|
||||
try {
|
||||
|
||||
$data[ 'fenxiao_id' ] = $fenxiao_info[ 'data' ][ 'fenxiao_id' ];
|
||||
$data[ 'fenxiao_name' ] = $fenxiao_info[ 'data' ][ 'fenxiao_name' ];
|
||||
|
||||
$res = model('fenxiao_withdraw')->add($data);
|
||||
|
||||
//修改分销商提现中金额
|
||||
model('fenxiao')->setInc([ [ 'member_id', '=', $data[ 'member_id' ] ] ], 'account_withdraw_apply', $data[ 'money' ]);
|
||||
//修改分销商可提现金额
|
||||
model('fenxiao')->setDec([ [ 'member_id', '=', $data[ 'member_id' ] ] ], 'account', $data[ 'money' ]);
|
||||
|
||||
//判断是否需要审核
|
||||
if ($config_info[ 'withdraw_status' ] == 2) {//不需要
|
||||
$result = $this->withdrawPass($res, $data[ 'site_id' ]);
|
||||
if ($result[ 'code' ] < 0) {
|
||||
model('fenxiao_withdraw')->rollback();
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
model('fenxiao_withdraw')->commit();
|
||||
|
||||
//申请提现发送消息
|
||||
$data[ 'keywords' ] = 'FENXIAO_WITHDRAWAL_APPLY';
|
||||
$message_model = new Message();
|
||||
$message_model->sendMessage($data);
|
||||
|
||||
return $this->success($res);
|
||||
} catch (\Exception $e) {
|
||||
model('fenxiao_withdraw')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 提现审核通过
|
||||
* @param $ids
|
||||
* @param $site_id
|
||||
* @return array
|
||||
*/
|
||||
public function withdrawPass($ids, $site_id)
|
||||
{
|
||||
model('fenxiao_withdraw')->startTrans();
|
||||
try {
|
||||
|
||||
$withdraw_list = $this->getFenxiaoWithdrawList([ [ 'id', 'in', $ids ] ], '*');
|
||||
foreach ($withdraw_list[ 'data' ] as $k => $v) {
|
||||
if ($v[ 'status' ] == self::STATUS_WAIT_AUDIT) {
|
||||
$this->agree([ 'id' => $v[ 'id' ], 'site_id' => $site_id ]);
|
||||
}
|
||||
}
|
||||
model('fenxiao_withdraw')->commit();
|
||||
return $this->success();
|
||||
} catch (\Exception $e) {
|
||||
model('fenxiao_withdraw')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取提现详情
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public function getFenxiaoWithdrawInfo($condition = [], $field = '*')
|
||||
{
|
||||
$res = model('fenxiao_withdraw')->getInfo($condition, $field);
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提现详情
|
||||
* @param $params
|
||||
* @return array
|
||||
*/
|
||||
public function getFenxiaoWithdrawDetail($params)
|
||||
{
|
||||
$id = $params[ 'id' ];
|
||||
$site_id = $params[ 'site_id' ] ?? 0;
|
||||
$member_id = $params[ 'member_id' ] ?? 0;
|
||||
$condition = array (
|
||||
[ 'id', '=', $id ]
|
||||
);
|
||||
if ($site_id > 0) {
|
||||
$condition[] = [ 'site_id', '=', $site_id ];
|
||||
}
|
||||
if ($member_id > 0) {
|
||||
$condition[] = [ 'member_id', '=', $member_id ];
|
||||
}
|
||||
$info = model('fenxiao_withdraw')->getInfo($condition, '*');
|
||||
if (!empty($info)) {
|
||||
$info = $this->tran($info);
|
||||
}
|
||||
return $this->success($info);
|
||||
}
|
||||
|
||||
public function tran($data)
|
||||
{
|
||||
$status = $data[ 'status' ] ?? 0;
|
||||
if ($status != 0) {
|
||||
$data[ 'status_name' ] = $this->status[ $status ] ?? '';
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分销列表
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
* @param string $order
|
||||
* @param null $limit
|
||||
* @return array
|
||||
*/
|
||||
public function getFenxiaoWithdrawList($condition = [], $field = '*', $order = '', $limit = null)
|
||||
{
|
||||
$list = model('fenxiao_withdraw')->getList($condition, $field, $order, '', '', '', $limit);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分销提现分页列表
|
||||
* @param array $condition
|
||||
* @param int $page
|
||||
* @param int $page_size
|
||||
* @param string $order
|
||||
* @param string $field
|
||||
* @param string $alias
|
||||
* @param array $join
|
||||
* @return array
|
||||
*/
|
||||
public function getFenxiaoWithdrawPageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $order = '', $field = '*', $alias = '', $join = [])
|
||||
{
|
||||
$list = model('fenxiao_withdraw')->pageList($condition, $field, $order, $page, $page_size, $alias, $join);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分销佣金发放通知
|
||||
* @param $data
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
*/
|
||||
public function messageOrderCommissionGrant($data)
|
||||
{
|
||||
//发送短信
|
||||
$sms_model = new Sms();
|
||||
|
||||
// 分销订单
|
||||
$fenxiao_order_model = new FenxiaoOrder();
|
||||
$fenxiao_order_info = $fenxiao_order_model->getFenxiaoOrderInfo([ [ 'fenxiao_order_id', '=', $data[ 'order_id' ] ] ])[ 'data' ];
|
||||
$commission = $fenxiao_order_info[ $data[ 'level' ] . '_commission' ];
|
||||
|
||||
$fenxiao_id = $fenxiao_order_info[ $data[ 'level' ] . '_fenxiao_id' ];
|
||||
$fenxiao_model = new Fenxiao();
|
||||
$fenxiao_info = $fenxiao_model->getFenxiaoInfo([ [ 'fenxiao_id', '=', $fenxiao_id ] ], 'fenxiao_id, member_id')[ 'data' ];
|
||||
|
||||
$member_model = new MemberModel();
|
||||
$member_info_result = $member_model->getMemberInfo([ [ 'member_id', '=', $fenxiao_info[ 'member_id' ] ?? 0 ] ]);
|
||||
$member_info = $member_info_result[ 'data' ];
|
||||
|
||||
//绑定微信公众号才发送
|
||||
if (!empty($member_info) && !empty($member_info[ 'wx_openid' ])) {
|
||||
$wechat_model = new WechatMessage();
|
||||
$data[ 'openid' ] = $member_info[ 'wx_openid' ];
|
||||
$data[ 'template_data' ] = [
|
||||
'amount1' => $commission, // 提现金额
|
||||
'time3' => time_to_date($fenxiao_order_info[ 'create_time' ]), // 提现日期
|
||||
];
|
||||
$data[ 'page' ] = '';
|
||||
$wechat_model->sendMessage($data);
|
||||
}
|
||||
|
||||
//发送订阅消息
|
||||
if (!empty($member_info) && !empty($member_info[ 'weapp_openid' ])) {
|
||||
$weapp_model = new WeappMessage();
|
||||
$data[ 'openid' ] = $member_info[ 'weapp_openid' ];
|
||||
$data[ 'template_data' ] = [
|
||||
'amount1' => [
|
||||
'value' => $fenxiao_order_info[ 'real_goods_money' ]
|
||||
],
|
||||
'amount2' => [
|
||||
'value' => $commission
|
||||
],
|
||||
'thing3' => [
|
||||
'value' => $fenxiao_order_info[ 'sku_name' ]
|
||||
],
|
||||
'time4' => [
|
||||
'value' => time_to_date($fenxiao_order_info[ 'create_time' ]),
|
||||
],
|
||||
];
|
||||
$data[ 'page' ] = '';
|
||||
$weapp_model->sendMessage($data);
|
||||
}
|
||||
|
||||
$buyer_member = $member_model->getMemberInfo([ [ 'member_id', '=', $fenxiao_order_info[ 'member_id' ] ?? 0 ] ]);
|
||||
$buyer_member_info = $buyer_member[ 'data' ];
|
||||
|
||||
$var_parse = [
|
||||
'sitename' => replaceSpecialChar($data[ 'site_info' ][ 'site_name' ]),
|
||||
'level' => $data[ 'level' ],
|
||||
'username' => empty(replaceSpecialChar($buyer_member_info[ 'nickname' ])) ? $buyer_member_info[ 'mobile' ] : replaceSpecialChar($buyer_member_info[ 'nickname' ]),
|
||||
];
|
||||
$data[ 'sms_account' ] = $member_info[ 'mobile' ];
|
||||
$data[ 'var_parse' ] = $var_parse;
|
||||
$sms_model->sendMessage($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分销提现成功通知
|
||||
* @param $data
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
*/
|
||||
public function messageFenxiaoWithdrawalSuccess($data)
|
||||
{
|
||||
//发送短信
|
||||
$sms_model = new Sms();
|
||||
|
||||
$var_parse = array (
|
||||
'username' => $data[ 'fenxiao_name' ],//会员名
|
||||
'money' => $data[ 'money' ]
|
||||
);
|
||||
|
||||
$data[ 'sms_account' ] = $data[ 'mobile' ];//手机号
|
||||
$data[ 'var_parse' ] = $var_parse;
|
||||
$sms_model->sendMessage($data);
|
||||
|
||||
$member_model = new MemberModel();
|
||||
$member_info_result = $member_model->getMemberInfo([ [ 'member_id', '=', $data[ 'member_id' ] ] ]);
|
||||
$member_info = $member_info_result[ 'data' ];
|
||||
|
||||
//绑定微信公众号才发送
|
||||
if (!empty($member_info) && !empty($member_info[ 'wx_openid' ])) {
|
||||
$wechat_model = new WechatMessage();
|
||||
$data[ 'openid' ] = $member_info[ 'wx_openid' ];
|
||||
$data[ 'template_data' ] = [
|
||||
'amount1' => $data[ 'money' ], // 提现金额
|
||||
'time3' => time_to_date($data[ 'payment_time' ]), // 提现日期
|
||||
];
|
||||
$data[ 'page' ] = '';
|
||||
$wechat_model->sendMessage($data);
|
||||
}
|
||||
|
||||
//发送订阅消息
|
||||
if (!empty($member_info) && !empty($member_info[ 'weapp_openid' ])) {
|
||||
$weapp_model = new WeappMessage();
|
||||
$data[ 'openid' ] = $member_info[ 'weapp_openid' ];
|
||||
$data[ 'template_data' ] = [
|
||||
'amount1' => [
|
||||
'value' => $data[ 'money' ]
|
||||
],
|
||||
'time2' => [
|
||||
'value' => time_to_date(time())
|
||||
],
|
||||
'thing3' => [
|
||||
'value' => '提现成功'
|
||||
]
|
||||
];
|
||||
$data[ 'page' ] = '';
|
||||
$weapp_model->sendMessage($data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 分销提现失败通知
|
||||
* @param $data
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
*/
|
||||
public function messageFenxiaoWithdrawalError($data)
|
||||
{
|
||||
//发送短信
|
||||
$sms_model = new Sms();
|
||||
|
||||
$member_model = new MemberModel();
|
||||
$member_info_result = $member_model->getMemberInfo([ [ 'member_id', '=', $data[ 'member_id' ] ] ]);
|
||||
$member_info = $member_info_result[ 'data' ];
|
||||
|
||||
$var_parse = array (
|
||||
'fenxiaoname' => str_replace(' ', '', $data[ 'fenxiao_name' ]),//会员名
|
||||
'money' => $data[ 'money' ]
|
||||
);
|
||||
|
||||
$data[ 'sms_account' ] = $member_info[ 'mobile' ];//手机号
|
||||
$data[ 'var_parse' ] = $var_parse;
|
||||
$sms_model->sendMessage($data);
|
||||
|
||||
// 【弃用,暂无模板信息,无法使用,等待后续微信支持后开发】绑定微信公众号才发送
|
||||
// if (!empty($member_info) && !empty($member_info[ 'wx_openid' ])) {
|
||||
// $wechat_model = new WechatMessage();
|
||||
// $data[ 'openid' ] = $member_info[ 'wx_openid' ];
|
||||
// $data[ 'template_data' ] = [
|
||||
// 'keyword1' => time_to_date($data[ 'create_time' ]),
|
||||
// 'keyword2' => '审核失败',
|
||||
// 'keyword3' => '会员申请提现',
|
||||
// 'keyword4' => $data[ 'money' ],
|
||||
// ];
|
||||
// $data[ 'page' ] = '';
|
||||
// $wechat_model->sendMessage($data);
|
||||
// }
|
||||
|
||||
//发送订阅消息
|
||||
if (!empty($member_info) && !empty($member_info[ 'weapp_openid' ])) {
|
||||
$weapp_model = new WeappMessage();
|
||||
$data[ 'openid' ] = $member_info[ 'weapp_openid' ];
|
||||
$data[ 'template_data' ] = [
|
||||
'amount2' => [
|
||||
'value' => $data[ 'money' ]
|
||||
],
|
||||
'thing4' => [
|
||||
'value' => '提现审核失败'
|
||||
]
|
||||
];
|
||||
$data[ 'page' ] = '';
|
||||
$weapp_model->sendMessage($data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 分销申请提现通知,卖家通知
|
||||
* @param $data
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
*/
|
||||
public function messageFenxiaoWithdrawalApply($data)
|
||||
{
|
||||
//发送短信
|
||||
$sms_model = new Sms();
|
||||
|
||||
$var_parse = array (
|
||||
'fenxiaoname' => replaceSpecialChar($data[ 'fenxiao_name' ]),//会员名
|
||||
'money' => $data[ 'money' ],//退款申请金额
|
||||
);
|
||||
// $site_id = $data['site_id'];
|
||||
// $shop_info = model('shop')->getInfo([['site_id', '=', $site_id]], 'mobile,email');
|
||||
// $message_data['sms_account'] = $shop_info['mobile'];//手机号
|
||||
$data[ 'var_parse' ] = $var_parse;
|
||||
|
||||
$shop_accept_message_model = new ShopAcceptMessage();
|
||||
$result = $shop_accept_message_model->getShopAcceptMessageList();
|
||||
$list = $result[ 'data' ];
|
||||
if (!empty($list)) {
|
||||
foreach ($list as $v) {
|
||||
$message_data = $data;
|
||||
$message_data[ 'sms_account' ] = $v[ 'mobile' ];//手机号
|
||||
$sms_model->sendMessage($message_data);
|
||||
|
||||
if ($v[ 'wx_openid' ] != '') {
|
||||
$wechat_model = new WechatMessage();
|
||||
$data[ 'openid' ] = $v[ 'wx_openid' ];
|
||||
$data[ 'template_data' ] = [
|
||||
'thing3' => replaceSpecialChar($data[ 'fenxiao_name' ]), // 客户名称
|
||||
'amount6' => $data[ 'money' ], // 提现金额
|
||||
'time8' => time_to_date($data[ 'create_time' ]) // 提现时间
|
||||
];
|
||||
$data[ 'page' ] = '';
|
||||
$wechat_model->sendMessage($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取提现数量
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public function getFenxiaoWithdrawCount($condition = [], $field = '*')
|
||||
{
|
||||
$res = model('fenxiao_withdraw')->getCount($condition, $field);
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
public function apply($data, $site_id = 0)
|
||||
{
|
||||
$config_model = new Config();
|
||||
$config = $config_model->getFenxiaoWithdrawConfig($site_id)[ 'data' ][ 'value' ] ?? [];
|
||||
|
||||
$withdraw_no = $this->createWithdrawNo();
|
||||
$apply_money = round($data[ 'apply_money' ], 2);
|
||||
|
||||
$withdraw_min_money = $config[ 'withdraw' ];
|
||||
$withdraw_max_money = $config[ 'max' ];
|
||||
if ($apply_money < $withdraw_min_money) return $this->error([], '申请提现金额不能小于最低提现额度' . $withdraw_min_money);
|
||||
if ($withdraw_max_money > 0 && $apply_money > $withdraw_max_money) return $this->error([], '申请提现金额不能大于最高提现额度' . $withdraw_max_money);
|
||||
|
||||
$member_id = $data[ 'member_id' ];
|
||||
$member_model = new Member();
|
||||
$member_condition = array (
|
||||
[ 'member_id', '=', $member_id ]
|
||||
);
|
||||
$member_info = $member_model->getMemberInfo($member_condition, 'balance_money,headimg,wx_openid,username,mobile,weapp_openid,nickname')[ 'data' ] ?? [];
|
||||
if (empty($member_info))
|
||||
return $this->error([], 'MEMBER_NOT_EXIST');
|
||||
|
||||
$fenxiao_model = new Fenxiao();
|
||||
$fenxiao_info = $fenxiao_model->getFenxiaoInfo($member_condition, 'fenxiao_id,fenxiao_name,account')[ 'data' ] ?? [];
|
||||
if (empty($fenxiao_info)) {
|
||||
return $this->error('该分销商不存在');
|
||||
}
|
||||
$fenxiao_account = $fenxiao_info[ 'account' ];//会员的分销佣金
|
||||
if ($fenxiao_account < $apply_money) {
|
||||
return $this->error('', '提现金额大于可提现金额');
|
||||
}
|
||||
|
||||
$transfer_type = $data[ 'transfer_type' ];
|
||||
$transfer_type_list = $this->getTransferType($site_id);
|
||||
$transfer_type_name = $transfer_type_list[ $transfer_type ] ?? '';
|
||||
if (empty($transfer_type_name))
|
||||
return $this->error([], '不支持的提现方式');
|
||||
|
||||
model('fenxiao_withdraw')->startTrans();
|
||||
try {
|
||||
$withdraw_rate = $config[ 'withdraw_rate' ];
|
||||
$bank_name = '';
|
||||
$account_number = '';
|
||||
$applet_type = 0;
|
||||
switch ( $transfer_type ) {
|
||||
case 'bank':
|
||||
$bank_name = $data[ 'bank_name' ];
|
||||
$account_number = $data[ 'account_number' ];
|
||||
break;
|
||||
case 'alipay':
|
||||
$bank_name = '';
|
||||
$account_number = $data[ 'account_number' ];
|
||||
break;
|
||||
case 'wechatpay':
|
||||
$bank_name = '';
|
||||
if (empty($member_info[ 'wx_openid' ]) && empty($member_info[ 'weapp_openid' ])) {
|
||||
return $this->error('', '请绑定微信或更换提现账户');
|
||||
}
|
||||
if ($data['app_type'] != 'weapp') {
|
||||
$account_number = $member_info[ 'wx_openid' ];
|
||||
$applet_type = 0; // 公众号
|
||||
} else {
|
||||
$account_number = $member_info[ 'weapp_openid' ];
|
||||
$applet_type = 1; // 小程序
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
if ($transfer_type == 'balance') {
|
||||
$withdraw_rate = 0;
|
||||
}
|
||||
$service_money = round($apply_money * $withdraw_rate / 100, 2);//手续费
|
||||
$real_money = $apply_money - $service_money;
|
||||
$data = array (
|
||||
'site_id' => $site_id,
|
||||
'withdraw_no' => $withdraw_no,
|
||||
'member_id' => $member_id,
|
||||
'fenxiao_id' => $fenxiao_info[ 'fenxiao_id' ],
|
||||
'fenxiao_name' => $fenxiao_info[ 'fenxiao_name' ],
|
||||
'transfer_type' => $transfer_type,
|
||||
'transfer_name' => $transfer_type_name,
|
||||
'money' => $apply_money,
|
||||
'withdraw_rate_money' => $service_money,
|
||||
'withdraw_rate' => $withdraw_rate,
|
||||
'real_money' => $real_money,
|
||||
'create_time' => time(),
|
||||
'status' => self::STATUS_WAIT_AUDIT,
|
||||
'status_name' => $this->status[self::STATUS_WAIT_AUDIT],
|
||||
|
||||
'member_headimg' => $member_info[ 'headimg' ],
|
||||
'realname' => $data[ 'realname' ],
|
||||
'bank_name' => $bank_name,
|
||||
'account_number' => $account_number,
|
||||
'mobile' => $data[ 'mobile' ],
|
||||
'applet_type' => $applet_type
|
||||
);
|
||||
|
||||
$result = model('fenxiao_withdraw')->add($data);
|
||||
|
||||
//添加转账记录
|
||||
$pay_transfer_model = new PayTransfer();
|
||||
$info = model('fenxiao_withdraw')->getInfo([['id', '=', $result]]);
|
||||
$pay_transfer_model->add([
|
||||
'real_name' => $info[ 'realname' ],
|
||||
'amount' => $info[ 'real_money' ],
|
||||
'desc' => '会员提现',
|
||||
'transfer_type' => $transfer_type,
|
||||
'account_number' => $info[ 'account_number' ],
|
||||
'site_id' => $info[ 'site_id' ],
|
||||
'is_weapp' => $info[ 'applet_type' ],
|
||||
'member_id' => $info[ 'member_id' ],
|
||||
'from_type' => 'fenxiao_withdraw',
|
||||
'relate_tag' => $info['id'],
|
||||
]);
|
||||
|
||||
//修改分销商提现中金额
|
||||
model('fenxiao')->setInc($member_condition, 'account_withdraw_apply', $apply_money);
|
||||
|
||||
//修改分销商可提现金额
|
||||
model('fenxiao')->setDec($member_condition, 'account', $apply_money);
|
||||
|
||||
//申请提现发送消息
|
||||
$data[ 'keywords' ] = 'FENXIAO_WITHDRAWAL_APPLY';
|
||||
$message_model = new Message();
|
||||
$message_model->sendMessage($data);
|
||||
|
||||
//判断是否需要审核
|
||||
if ($config[ 'withdraw_status' ] == 2) {//不需要
|
||||
$result = $this->agree([ 'id' => $result, 'site_id' => $site_id ]);
|
||||
if ($result[ 'code' ] < 0) {
|
||||
model('fenxiao_withdraw')->rollback();
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
model('fenxiao_withdraw')->commit();
|
||||
return $this->success();
|
||||
} catch (\Exception $e) {
|
||||
model('fenxiao_withdraw')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 提现流水号
|
||||
*/
|
||||
private function createWithdrawNo()
|
||||
{
|
||||
$cache = Cache::get('member_withdraw_no' . time());
|
||||
if (empty($cache)) {
|
||||
Cache::set('niutk' . time(), 1000);
|
||||
$cache = Cache::get('member_withdraw_no' . time());
|
||||
} else {
|
||||
$cache = $cache + 1;
|
||||
Cache::set('member_withdraw_no' . time(), $cache);
|
||||
}
|
||||
$no = date('Ymdhis', time()) . rand(1000, 9999) . $cache;
|
||||
return $no;
|
||||
}
|
||||
|
||||
public function agree($params)
|
||||
{
|
||||
$id = $params[ 'id' ];
|
||||
$site_id = $params[ 'site_id' ];
|
||||
if (empty($site_id)) {
|
||||
return $this->error(-1, '参数错误');
|
||||
}
|
||||
$condition = array (
|
||||
[ 'id', '=', $id ],
|
||||
[ 'site_id', '=', $site_id ],
|
||||
);
|
||||
$info = model('fenxiao_withdraw')->getInfo($condition);
|
||||
|
||||
if (empty($info))
|
||||
return $this->error();
|
||||
|
||||
$config_model = new Config();
|
||||
$config = $config_model->getFenxiaoWithdrawConfig($site_id)[ 'data' ][ 'value' ] ?? [];
|
||||
|
||||
model('fenxiao_withdraw')->startTrans();
|
||||
try {
|
||||
$data = array (
|
||||
'status' => self::STATUS_WAIT_TRANSFER,
|
||||
'status_name' => $this->status[self::STATUS_WAIT_TRANSFER],//已审核待转账
|
||||
'audit_time' => time(),
|
||||
);
|
||||
$result = model('fenxiao_withdraw')->update($data, $condition);
|
||||
//是否启用自动转账(必须是微信或支付宝)
|
||||
if ($config[ 'is_auto_transfer' ] == 1) {
|
||||
$this->transfer([ 'id' => $id ]);
|
||||
}
|
||||
model('fenxiao_withdraw')->commit();
|
||||
return $this->success();
|
||||
} catch (\Exception $e) {
|
||||
model('fenxiao_withdraw')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转账
|
||||
* @param $params
|
||||
* @return array|mixed|void
|
||||
*/
|
||||
public function transfer($params)
|
||||
{
|
||||
$id = $params[ 'id' ];
|
||||
$site_id = $params[ 'site_id' ] ?? 0;
|
||||
$condition = array (
|
||||
[ 'id', '=', $id ],
|
||||
);
|
||||
if ($site_id > 0) {
|
||||
$condition[] = [ 'site_id', '=', $site_id ];
|
||||
}
|
||||
$info = model('fenxiao_withdraw')->getInfo($condition);
|
||||
if (empty($info))
|
||||
return $this->error();
|
||||
$site_id = $info[ 'site_id' ];
|
||||
$transfer_type = $info[ 'transfer_type' ];
|
||||
$member_id = $info[ 'member_id' ];
|
||||
$real_money = $info[ 'real_money' ];
|
||||
if ($transfer_type == 'balance') {
|
||||
//添加会员账户流水
|
||||
$member_account = new MemberAccount();
|
||||
$member_result = $member_account->addMemberAccount($site_id, $member_id, 'balance_money', $real_money, 'fenxiao', '佣金提现', '分销佣金提现');
|
||||
if ($member_result[ 'code' ] < 0) {
|
||||
return $member_result;
|
||||
}
|
||||
return $this->transferFinish(['id' => $id, 'site_id' => $site_id]);
|
||||
} else {
|
||||
if (!in_array($transfer_type, [ 'wechatpay', 'alipay' ]))
|
||||
return $this->error('', '当前提现方式不支持在线转账');
|
||||
|
||||
$pay_transfer_model = new PayTransfer();
|
||||
$res = $pay_transfer_model->transfer('fenxiao_withdraw', $info['id']);
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转账结果通知
|
||||
* @param $param
|
||||
* @return array
|
||||
* @throws \think\db\exception\DbException
|
||||
*/
|
||||
public function transferNotify($param)
|
||||
{
|
||||
$id = $param['relate_tag'];
|
||||
$site_id = $param['site_id'];
|
||||
$withdraw_info = model('fenxiao_withdraw')->getInfo([
|
||||
['id', '=', $id],
|
||||
['site_id', '=', $site_id],
|
||||
]);
|
||||
if(empty($withdraw_info)){
|
||||
return $this->error(null, '提现信息有误');
|
||||
}
|
||||
|
||||
//成功的处理
|
||||
switch($param['status']){
|
||||
case PayTransfer::STATUS_IN_PROCESS:
|
||||
model('fenxiao_withdraw')->update([
|
||||
'status' => self::STATUS_IN_PROCESS,
|
||||
'status_name' => $this->status[self::STATUS_IN_PROCESS],
|
||||
'modify_time' => time(),
|
||||
], [['id', '=', $withdraw_info['id']]]);
|
||||
return $this->success();
|
||||
break;
|
||||
case PayTransfer::STATUS_SUCCESS:
|
||||
//添加账户流水
|
||||
$account_model = new FenxiaoAccount();
|
||||
$account_model->addAccountLog($withdraw_info['fenxiao_id'], $withdraw_info[ 'fenxiao_name' ], 'withdraw', '-' . $withdraw_info['money'], $withdraw_info['id']);
|
||||
|
||||
return $this->transferFinish([ 'id' => $withdraw_info['id'], 'site_id' => $withdraw_info[ 'site_id' ] ]);
|
||||
break;
|
||||
case PayTransfer::STATUS_FAIL:
|
||||
$resp_data = json_decode($param['resp_data'], true);
|
||||
$fail_reason = $resp_data['fail_reason'] ?? '';
|
||||
model('fenxiao_withdraw')->update([
|
||||
'status' => self::STATUS_FAIL,
|
||||
'status_name' => $this->status[self::STATUS_FAIL],
|
||||
'fail_reason' => $fail_reason,
|
||||
'modify_time' => time(),
|
||||
], [['id', '=', $withdraw_info['id']]]);
|
||||
|
||||
//账户金额回退
|
||||
$member_condition = [['fenxiao_id', '=', $withdraw_info['fenxiao_id']]];
|
||||
$apply_money = $withdraw_info['money'];
|
||||
model('fenxiao')->setDec($member_condition, 'account_withdraw_apply', $apply_money);
|
||||
model('fenxiao')->setInc($member_condition, 'account', $apply_money);
|
||||
|
||||
return $this->success();
|
||||
break;
|
||||
default:
|
||||
return $this->error(null, '转账结果状态有误');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 提现转账完成
|
||||
* @param array $param
|
||||
* @return array
|
||||
*/
|
||||
public function transferFinish($param = [])
|
||||
{
|
||||
$condition = [
|
||||
[ 'id', '=', $param[ 'id' ] ],
|
||||
[ 'site_id', '=', $param[ 'site_id' ] ],
|
||||
[ 'status', 'in', [self::STATUS_WAIT_TRANSFER, self::STATUS_IN_PROCESS] ]
|
||||
];
|
||||
$info = model('fenxiao_withdraw')->getInfo($condition);
|
||||
if (empty($info)) return $this->error(null, '提现信息有误');
|
||||
|
||||
$fenxiao_id = $info[ 'fenxiao_id' ];
|
||||
$money = $info[ 'money' ];
|
||||
$payment_time = time();
|
||||
model('fenxiao_withdraw')->startTrans();
|
||||
try {
|
||||
$data = [
|
||||
'status' => self::STATUS_SUCCESS,
|
||||
'status_name' => $this->status[self::STATUS_SUCCESS],
|
||||
'payment_time' => $payment_time,
|
||||
'document' => $param[ 'certificate' ] ?? '',
|
||||
'transfer_remark' => $param[ 'certificate_remark' ] ?? ''
|
||||
];
|
||||
model('fenxiao_withdraw')->update($data, $condition);
|
||||
|
||||
$fenxiao_condition = array (
|
||||
[ 'fenxiao_id', '=', $fenxiao_id ]
|
||||
);
|
||||
//修改分销商提现中金额
|
||||
model('fenxiao')->setDec($fenxiao_condition, 'account_withdraw_apply', $money);
|
||||
//修改分销商已提现金额
|
||||
model('fenxiao')->setInc($fenxiao_condition, 'account_withdraw', $money);
|
||||
|
||||
model('fenxiao_withdraw')->commit();
|
||||
|
||||
$message_model = new Message();
|
||||
$info[ 'keywords' ] = 'FENXIAO_WITHDRAWAL_SUCCESS';
|
||||
$message_model->sendMessage($info);
|
||||
return $this->success();
|
||||
} catch (\Exception $e) {
|
||||
model('fenxiao_withdraw')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 拒绝提现申请
|
||||
* @param $params
|
||||
* @return array
|
||||
*/
|
||||
public function refuse($params)
|
||||
{
|
||||
$id = $params[ 'id' ];
|
||||
$site_id = $params[ 'site_id' ];
|
||||
$condition = array (
|
||||
[ 'id', '=', $id ],
|
||||
[ 'site_id', '=', $site_id ]
|
||||
);
|
||||
$info = model('fenxiao_withdraw')->getInfo($condition, '*');
|
||||
if (empty($info)) return $this->error(null, '提现信息有误');
|
||||
if(!in_array($info['status'], [self::STATUS_WAIT_AUDIT, self::STATUS_WAIT_TRANSFER])){
|
||||
return $this->error(null, '提现状态有误');
|
||||
}
|
||||
|
||||
model('fenxiao_withdraw')->startTrans();
|
||||
try {
|
||||
$money = $info[ 'money' ];
|
||||
$fenxiao_id = $info[ 'fenxiao_id' ];
|
||||
$data = [
|
||||
'status' => self::STATUS_REFUSE,
|
||||
'status_name' => $this->status[self::STATUS_REFUSE],
|
||||
'refuse_reason' => $params['refuse_reason'],
|
||||
'audit_time' => time(),
|
||||
];
|
||||
model('fenxiao_withdraw')->update($data, $condition);
|
||||
$fenxiao_condition = array (
|
||||
[ 'fenxiao_id', '=', $fenxiao_id ]
|
||||
);
|
||||
//修改分销商提现中金额
|
||||
model('fenxiao')->setDec($fenxiao_condition, 'account_withdraw_apply', $money);
|
||||
|
||||
//修改分销商可提现金额
|
||||
model('fenxiao')->setInc($fenxiao_condition, 'account', $money);
|
||||
|
||||
//提现失败发送消息
|
||||
$message_model = new Message();
|
||||
$info[ 'keywords' ] = 'FENXIAO_WITHDRAWAL_ERROR';
|
||||
$message_model->sendMessage($info);
|
||||
model('fenxiao_withdraw')->commit();
|
||||
return $this->success();
|
||||
} catch (\Exception $e) {
|
||||
model('fenxiao_withdraw')->rollback();
|
||||
return $this->error('', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function exportFenxiaoWithdraw($condition, $order, $site_id)
|
||||
{
|
||||
try {
|
||||
$file_name = date('Y年m月d日-分销提现', time()) . '.csv';
|
||||
// $file_name = date('YmdHis').'.csv';//csv文件名
|
||||
//通过分批次执行数据导出(防止内存超出配置设置的)
|
||||
set_time_limit(0);
|
||||
ini_set('memory_limit', '256M');
|
||||
//设置header头
|
||||
header('Content-Description: File Transfer');
|
||||
header('Content-Type: application/vnd.ms-excel');
|
||||
header('Content-Disposition: attachment; filename="' . $file_name . '"');
|
||||
header('Expires: 0');
|
||||
header('Cache-Control: must-revalidate');
|
||||
header('Pragma: public');
|
||||
//打开php数据输入缓冲区
|
||||
$fp = fopen('php://output', 'a');
|
||||
// fwrite($fp, chr(0xEF).chr(0xBB).chr(0xBF)); // 添加 BOM
|
||||
$heade = [ '分销商', '提现方式', '申请提现金额', '提现手续费', '实际转账金额', '提现状态', '申请时间', '收款账号', '真实姓名', '手机号', '银行名称', '银行账号' ];
|
||||
//将数据编码转换成GBK格式
|
||||
mb_convert_variables('GBK', 'UTF-8', $heade);
|
||||
//将数据格式化为CSV格式并写入到output流中
|
||||
fputcsv($fp, $heade);
|
||||
$transfer_type_list = $this->getTransferType($site_id);
|
||||
$status_name = [ 1 => '待审核', 2 => '待转账', 3 => '已转账', -1 => '已拒绝', -2 => '转账失败'];
|
||||
//写入第一行表头
|
||||
Db::name('fenxiao_withdraw')->where($condition)->order($order)->chunk(500, function($item_list) use ($fp, $transfer_type_list, $status_name) {
|
||||
//写入导出信息
|
||||
foreach ($item_list as $k => $item_v) {
|
||||
$temp_data = [
|
||||
$item_v[ 'fenxiao_name' ] . "\t",
|
||||
$transfer_type_list[ $item_v[ 'transfer_type' ] ] . "\t",
|
||||
(float) $item_v[ 'money' ] . "\t",
|
||||
(float) $item_v[ 'withdraw_rate_money' ] . "\t",
|
||||
(float) $item_v[ 'real_money' ] . "\t",
|
||||
$status_name[ $item_v[ 'status' ] ] . "\t",
|
||||
time_to_date($item_v[ 'create_time' ]) . "\t",
|
||||
$item_v[ 'account_number' ] . "\t",
|
||||
$item_v[ 'realname' ] . "\t",
|
||||
$item_v[ 'mobile' ] . "\t",
|
||||
$item_v[ 'bank_name' ] . "\t",
|
||||
$item_v[ 'transfer_account_no' ] . "\t",
|
||||
];
|
||||
mb_convert_variables('GBK', 'UTF-8', $temp_data);
|
||||
fputcsv($fp, $temp_data);
|
||||
//将已经存储到csv中的变量数据销毁,释放内存
|
||||
unset($item_v);
|
||||
}
|
||||
unset($item_list);
|
||||
});
|
||||
|
||||
//关闭句柄
|
||||
fclose($fp);
|
||||
die;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return $this->error([], $e->getMessage() . $e->getFile() . $e->getLine());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 转账检测
|
||||
* @param $id
|
||||
*/
|
||||
public function transferCheck($id)
|
||||
{
|
||||
$info_result = $this->getFenxiaoWithdrawInfo([ [ "id", "=", $id ] ], "withdraw_no,account_number,realname,money,transfer_type,status");
|
||||
if (empty($info_result["data"]))
|
||||
return $this->error(null, '提现信息缺失');
|
||||
|
||||
$info = $info_result["data"];
|
||||
if(!in_array($info["transfer_type"], ["wechatpay","alipay"]))
|
||||
return $this->error('', "当前提现方式不支持在线转账");
|
||||
if($info['status'] != self::STATUS_WAIT_TRANSFER){
|
||||
return $this->error('', "当前提现单非待转账状态");
|
||||
}
|
||||
return $this->success();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
290
addon/fenxiao/model/Poster.php
Executable file
290
addon/fenxiao/model/Poster.php
Executable file
@@ -0,0 +1,290 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\fenxiao\model;
|
||||
|
||||
use app\model\BaseModel;
|
||||
use extend\Poster as PosterExtend;
|
||||
use app\model\upload\Upload;
|
||||
|
||||
/**
|
||||
* 海报生成类
|
||||
*/
|
||||
class Poster extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 获取分销海报
|
||||
* @param $param
|
||||
* @return array|\extend\multitype|PosterExtend|mixed|string|void
|
||||
*/
|
||||
public function getFenxiaoPoster($param)
|
||||
{
|
||||
$app_type = $param['app_type'] ?? 'h5';
|
||||
$qrcode_param = $param['qrcode_param'] ?? [];
|
||||
$site_id = $param['site_id'] ?? 0;
|
||||
$page = $param['page'] ?? '';
|
||||
$template_id = $param['template_id'] ?? 'default';
|
||||
|
||||
//海报信息
|
||||
if ($template_id == 'default') {
|
||||
$template_info = PosterTemplate::DEFAULT_CREATE_TEMPLATE;
|
||||
} else {
|
||||
$template_info = model('poster_template')->getInfo([
|
||||
['site_id', '=', $site_id],
|
||||
['template_type', '=', 'fenxiao'],
|
||||
['template_status', '=', 1],
|
||||
['template_id', '=', $template_id],
|
||||
]);
|
||||
if (empty($template_info)) return $this->error(null, '模板信息有误');
|
||||
$template_info['template_json'] = json_decode($template_info['template_json'], true);
|
||||
}
|
||||
//二维码信息
|
||||
$qrcode_info = $this->getQrcode($app_type, $page, $qrcode_param, $site_id);
|
||||
if ($qrcode_info['code'] < 0) return $qrcode_info;
|
||||
//会员信息
|
||||
$member_info = $this->getMemberInfo($qrcode_param['source_member']);
|
||||
if (empty($member_info)) return $this->error('未获取到会员信息');
|
||||
|
||||
$res = $this->createPoster([
|
||||
'qrcode_path' => $qrcode_info['data']['path'],
|
||||
'member_info' => $member_info,
|
||||
'template_info' => $template_info,
|
||||
'site_id' => $site_id,
|
||||
]);
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成海报
|
||||
*/
|
||||
public function createPoster($param)
|
||||
{
|
||||
$qrcode_path = $param['qrcode_path'];
|
||||
$template_info = $param['template_info'];
|
||||
$member_info = $param['member_info'];
|
||||
$site_id = $param['site_id'];
|
||||
|
||||
//如果有对应的数据则直接返回
|
||||
$param_md5 = $this->getPosterParamMd5($param);
|
||||
$poster_condition = [
|
||||
['site_id', '=', $site_id],
|
||||
['template_id', '=', $template_info['template_id'] ?? 0],
|
||||
['type', '=', 'fenxiao'],
|
||||
['param_md5', '=', $param_md5],
|
||||
];
|
||||
$poster_info = model('poster')->getInfo($poster_condition, 'file_path');
|
||||
if(!empty($poster_info)){
|
||||
$upload_model = new \app\model\upload\Upload();
|
||||
if($upload_model->isImageLinkValid($poster_info['file_path'])){
|
||||
return $this->success([
|
||||
'path' => $poster_info['file_path'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$params = $template_info;
|
||||
$params['background_width'] = $params['background_width'] ?? 740;
|
||||
$params['background_height'] = $params['background_height'] ?? 1250;
|
||||
$poster = new PosterExtend($params['background_width'], $params['background_height']);
|
||||
$fontRate = 0.725;
|
||||
$nickname_color = is_array($params['template_json']['nickname_color']) ? $params['template_json']['nickname_color'] : hex2rgb($params['template_json']['nickname_color']);
|
||||
//外网图片无法制作海报 本地化处理
|
||||
if (strpos($params['background'], "http") !== false) {
|
||||
$params['background'] = $this->createTempImage($params['background']);
|
||||
$temp_background = $params['background'];
|
||||
}
|
||||
if (strpos($member_info['headimg'], "http") !== false) {
|
||||
$member_info['headimg'] = $this->createTempImage($member_info['headimg']);
|
||||
$temp_headimg = $member_info['headimg'];
|
||||
}
|
||||
$option = [
|
||||
[
|
||||
'action' => 'imageCopy', // 写入背景图
|
||||
'data' => [
|
||||
img($params['background']),
|
||||
0,
|
||||
0,
|
||||
$params['background_width'],
|
||||
$params['background_height'],
|
||||
'square',
|
||||
0,
|
||||
1
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageCopy', // 写入二维码
|
||||
'data' => [
|
||||
$qrcode_path,
|
||||
(int)$params['qrcode_left'] * 2,
|
||||
(int)$params['qrcode_top'] * 2,
|
||||
(int)$params['qrcode_width'] * 2,
|
||||
(int)$params['qrcode_height'] * 2,
|
||||
'square',
|
||||
0,
|
||||
1
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageText', // 写入分享语
|
||||
'data' => [
|
||||
$params['template_json']['share_content'],
|
||||
$params['template_json']['share_content_font_size'] * $fontRate * 2,
|
||||
is_array($params['template_json']['share_content_color']) ? $params['template_json']['share_content_color'] : hex2rgb($params['template_json']['share_content_color']),
|
||||
$params['template_json']['share_content_left'] * 2,
|
||||
($params['template_json']['share_content_top'] + $params['template_json']['share_content_font_size']) * 2,
|
||||
$params['template_json']['share_content_width'] * 2,
|
||||
1
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageCopy', // 写入用户头像
|
||||
'data' => [
|
||||
!empty($member_info['headimg']) ? img($member_info['headimg']) : img('public/static/img/default_img/head.png'),
|
||||
$params['template_json']['headimg_left'] * 2,
|
||||
$params['template_json']['headimg_top'] * 2,
|
||||
$params['template_json']['headimg_width'] * 2,
|
||||
$params['template_json']['headimg_height'] * 2,
|
||||
!empty($params['template_json']['headimg_shape']) ? $params['template_json']['headimg_shape'] : 'square',
|
||||
0,
|
||||
$params['template_json']['headimg_is_show']
|
||||
]
|
||||
],
|
||||
[
|
||||
'action' => 'imageText', // 写入分享人昵称
|
||||
'data' => [
|
||||
$member_info['nickname'],
|
||||
$params['template_json']['nickname_font_size'] * $fontRate * 2,
|
||||
$nickname_color,
|
||||
$params['template_json']['nickname_left'] * 2,
|
||||
($params['template_json']['nickname_top'] + $params['template_json']['nickname_font_size']) * 2,
|
||||
$params['template_json']['nickname_width'] * 2,
|
||||
1,
|
||||
true,
|
||||
$params['template_json']['nickname_is_show']
|
||||
]
|
||||
],
|
||||
];
|
||||
$option_res = $poster->create($option);
|
||||
if (is_array($option_res)) return $option_res;
|
||||
|
||||
$poster_dir = 'upload/poster/distribution';
|
||||
$res = $option_res->jpeg($poster_dir, $param_md5);
|
||||
|
||||
//删除本地临时生成文件。
|
||||
if (isset($temp_background)) unlink($temp_background);
|
||||
if (isset($temp_headimg)) unlink($temp_headimg);
|
||||
|
||||
$file_path = $res['data']['path'];
|
||||
if ($res['code'] == 0) {
|
||||
$upload = new Upload($site_id);
|
||||
$cloud_res = $upload->fileCloud($file_path);
|
||||
if ($cloud_res['code'] >= 0) {
|
||||
$file_path = $cloud_res['data'];
|
||||
}
|
||||
}
|
||||
|
||||
//添加或更新记录
|
||||
if(empty($poster_info)){
|
||||
model('poster')->add([
|
||||
'site_id' => $site_id,
|
||||
'template_id' => $template_info['template_id'] ?? 0,
|
||||
'type' => 'fenxiao',
|
||||
'file_path' => $file_path,
|
||||
'param_md5' => $param_md5,
|
||||
]);
|
||||
}else{
|
||||
model('poster')->update([
|
||||
'file_path' => $file_path,
|
||||
], $poster_condition);
|
||||
}
|
||||
|
||||
return $this->success(["path" => $file_path]);
|
||||
} catch (\Exception $e) {
|
||||
return $this->error($e->getMessage() . $e->getFile() . $e->getLine());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成临时图片
|
||||
* @param $file_path
|
||||
* @return string
|
||||
*/
|
||||
public function createTempImage($file_path)
|
||||
{
|
||||
$temp_dir = "upload/fenxiao_poster/temp/";
|
||||
if (!is_dir($temp_dir)) mkdir($temp_dir, 0777, true);
|
||||
$upload_model = new \app\model\upload\Upload();
|
||||
$image_content = $upload_model->curlGetFile($file_path);
|
||||
$image_ext = $upload_model->getFileExt($file_path, 'png');
|
||||
$temp_file = $temp_dir . uniqid() . ".".$image_ext;
|
||||
file_put_contents($temp_file, $image_content);
|
||||
return $temp_file;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取海报名称
|
||||
* @param $param
|
||||
* @return string
|
||||
*/
|
||||
public function getPosterParamMd5($param)
|
||||
{
|
||||
$qrcode_path = $param['qrcode_path'];
|
||||
$template_info = $param['template_info'];
|
||||
$member_info = $param['member_info'];
|
||||
|
||||
$params = $template_info;
|
||||
$data = [
|
||||
$qrcode_path,
|
||||
$params['background'],
|
||||
$params['qrcode_left'],
|
||||
$params['qrcode_left'],
|
||||
$params['qrcode_top'],
|
||||
$params['qrcode_width'],
|
||||
$params['qrcode_height'],
|
||||
$params['template_json'],
|
||||
$member_info['headimg'],
|
||||
$member_info['nickname'],
|
||||
];
|
||||
return md5(json_encode($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
* @param $member_id
|
||||
* @return mixed
|
||||
*/
|
||||
private function getMemberInfo($member_id)
|
||||
{
|
||||
$info = model('member')->getInfo(['member_id' => $member_id], 'nickname,headimg');
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取二维码
|
||||
* @param unknown $app_type 请求类型
|
||||
* @param unknown $page uniapp页面路径
|
||||
* @param unknown $qrcode_param 二维码携带参数
|
||||
* @param string $promotion_type 活动类型 null为无活动
|
||||
*/
|
||||
private function getQrcode($app_type, $page, $qrcode_param, $site_id)
|
||||
{
|
||||
$res = event('Qrcode', [
|
||||
'site_id' => $site_id,
|
||||
'app_type' => $app_type,
|
||||
'type' => 'get',
|
||||
'data' => $qrcode_param,
|
||||
'page' => $page,
|
||||
'qrcode_path' => 'upload/qrcode/distribution',
|
||||
'qrcode_name' => 'distribution' . '_' . $qrcode_param['source_member'] . '_' . $site_id,
|
||||
], true);
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
218
addon/fenxiao/model/PosterTemplate.php
Executable file
218
addon/fenxiao/model/PosterTemplate.php
Executable file
@@ -0,0 +1,218 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
|
||||
* 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\fenxiao\model;
|
||||
|
||||
use app\model\BaseModel;
|
||||
|
||||
/**
|
||||
* 海报模板
|
||||
*/
|
||||
class PosterTemplate extends BaseModel
|
||||
{
|
||||
//默认模板数据
|
||||
const DEFAULT_TEMPLATE = [
|
||||
'template_id' => 0,
|
||||
'template_type' => 'fenxiao',
|
||||
'poster_name' => '',
|
||||
'background' => '',
|
||||
//二维码
|
||||
'qrcode_type' => '',
|
||||
'qrcode_width' => 80,
|
||||
'qrcode_height' => 80,
|
||||
'qrcode_top' => 540,
|
||||
'qrcode_left' => 260,
|
||||
//json数据
|
||||
'template_json' => [
|
||||
//头像
|
||||
'headimg_is_show' => 1,
|
||||
'headimg_shape' => 'circle',
|
||||
'headimg_width' => 56,
|
||||
'headimg_height' => 56,
|
||||
'headimg_top' => 426,
|
||||
'headimg_left' => 41,
|
||||
//昵称
|
||||
'nickname_is_show' => 1,
|
||||
'nickname_font_size' => 22,
|
||||
'nickname_color' => '#faa87a',
|
||||
'nickname_width' => 150,
|
||||
'nickname_height' => 30,
|
||||
'nickname_top' => 515,
|
||||
'nickname_left' => 20,
|
||||
//分享语
|
||||
'share_content' => '邀您一起分享赚佣金',
|
||||
'share_content_is_show' => 1,
|
||||
'share_content_font_size' => 14,
|
||||
'share_content_color' => '#8D8D8D',
|
||||
'share_content_width' => 130,
|
||||
'share_content_height' => 30,
|
||||
'share_content_top' => 550,
|
||||
'share_content_left' => 20,
|
||||
]
|
||||
];
|
||||
|
||||
//默认模板数据
|
||||
const DEFAULT_CREATE_TEMPLATE = [
|
||||
'template_id' => 0,
|
||||
'template_type' => 'fenxiao',
|
||||
'poster_name' => '',
|
||||
'background' => 'upload/poster/bg/fenxiao_2.png',
|
||||
'background_width' => 720,
|
||||
'background_height' => 1280,
|
||||
//二维码
|
||||
'qrcode_type' => '',
|
||||
'qrcode_width' => 75,
|
||||
'qrcode_height' => 75,
|
||||
'qrcode_top' => 517.5,
|
||||
'qrcode_left' => 246,
|
||||
//json数据
|
||||
'template_json' => [
|
||||
//头像
|
||||
'headimg_is_show' => 1,
|
||||
'headimg_shape' => 'circle',
|
||||
'headimg_width' => 50,
|
||||
'headimg_height' => 50,
|
||||
'headimg_top' => 510,
|
||||
'headimg_left' => 32.5,
|
||||
//昵称
|
||||
'nickname_is_show' => 1,
|
||||
'nickname_font_size' => 11 / 0.725,
|
||||
'nickname_color' => [255, 129, 61],
|
||||
'nickname_width' => 150,
|
||||
'nickname_height' => 30,
|
||||
'nickname_top' => 530 - 11 / 0.725,
|
||||
'nickname_left' => 90,
|
||||
//分享语
|
||||
'share_content' => '',
|
||||
'share_content_is_show' => 1,
|
||||
'share_content_font_size' => 14,
|
||||
'share_content_color' => '#8D8D8D',
|
||||
'share_content_width' => 130,
|
||||
'share_content_height' => 30,
|
||||
'share_content_top' => 550,
|
||||
'share_content_left' => 20,
|
||||
]
|
||||
];
|
||||
|
||||
/**
|
||||
* 添加海报模板
|
||||
* @param $data
|
||||
* @return array
|
||||
*/
|
||||
public function addPosterTemplate($data)
|
||||
{
|
||||
$res = model('poster_template')->add($data);
|
||||
if ($res === false) {
|
||||
return $this->error('', 'RESULT_ERROR');
|
||||
}
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑海报模板
|
||||
* @param $data
|
||||
* @param $condition
|
||||
* @return array
|
||||
*/
|
||||
public function editPosterTemplate($data, $condition)
|
||||
{
|
||||
$res = model('poster_template')->update($data, $condition);
|
||||
if ($res === false) {
|
||||
return $this->error('', 'SAVE_FAIL');
|
||||
}
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除海报模板
|
||||
* @param $condition
|
||||
* @return array
|
||||
*/
|
||||
public function deletePosterTemplate($condition)
|
||||
{
|
||||
$res = model('poster_template')->delete($condition);
|
||||
if ($res === false) {
|
||||
return $this->error('', 'RESULT_ERROR');
|
||||
}
|
||||
return $this->success($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取海报模板信息
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
* @return array
|
||||
*/
|
||||
public function getPosterTemplateInfo($condition = [], $field = '*')
|
||||
{
|
||||
$info = model('poster_template')->getInfo($condition, $field);
|
||||
return $this->success($info);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取海报模板列表
|
||||
* @param array $condition
|
||||
* @param string $field
|
||||
* @param string $order
|
||||
* @param null $limit
|
||||
* @return array
|
||||
*/
|
||||
public function getPosterTemplateList($condition = [], $field = '*', $order = 'create_time desc')
|
||||
{
|
||||
$list = model('poster_template')->getList($condition, $field, $order);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取海报模板分页列表
|
||||
* @param array $condition
|
||||
* @param int $page
|
||||
* @param int $page_size
|
||||
* @param string $field
|
||||
* @param string $order
|
||||
* @return array
|
||||
*/
|
||||
public function getPosterTemplatePageList($condition = [], $page = 1, $page_size = PAGE_LIST_ROWS, $field = '*', $order = 'create_time desc')
|
||||
{
|
||||
$list = model('poster_template')->pageList($condition, $field, $order, $page, $page_size);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对之前的数据做兼容处理
|
||||
* @param $template_json
|
||||
* @return array
|
||||
*/
|
||||
public function correctTemplateJsonData($template_json)
|
||||
{
|
||||
//兼容处理
|
||||
if (!isset($template_json[ 'share_content_is_show' ])) $template_json[ 'share_content_is_show' ] = 1;
|
||||
if (!isset($template_json[ 'share_content_font_size' ])) $template_json[ 'share_content_font_size' ] = 14;
|
||||
if (!isset($template_json[ 'share_content_color' ])) $template_json[ 'share_content_color' ] = '#8D8D8D';
|
||||
return $this->success($template_json);
|
||||
}
|
||||
|
||||
/*************************** 模板默认数据 ********************************/
|
||||
|
||||
public function getMubanInfo($condition = [], $field = '*', $alias = 'a', $join = [])
|
||||
{
|
||||
$list = model('poster_muban')->getInfo($condition, $field, $alias, $join);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
public function getMubanList($condition = [], $field = '*')
|
||||
{
|
||||
$list = model('poster_muban')->getList($condition, $field);
|
||||
return $this->success($list);
|
||||
}
|
||||
|
||||
}
|
||||
114
addon/fenxiao/model/share/WchatShare.php
Executable file
114
addon/fenxiao/model/share/WchatShare.php
Executable file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\fenxiao\model\share;
|
||||
|
||||
use app\model\share\WchatShareBase as BaseModel;
|
||||
use app\model\member\Member as MemberModel;
|
||||
use app\model\system\Site as SiteModel;
|
||||
use app\model\system\Config as ConfigModel;
|
||||
|
||||
/**
|
||||
* 分享
|
||||
*/
|
||||
class WchatShare extends BaseModel
|
||||
{
|
||||
protected $config = [
|
||||
[
|
||||
'title' => '分销推广',
|
||||
'config_key' => 'WCHAT_SHARE_CONFIG_FENXIAO_PROMOTE',
|
||||
'path' => [ '/pages_promotion/fenxiao/promote_code' ],
|
||||
'method_prefix' => 'promote',
|
||||
],
|
||||
];
|
||||
|
||||
protected $sort = 3;
|
||||
|
||||
/**
|
||||
* 推广分享数据
|
||||
* @param $param
|
||||
* @return array
|
||||
*/
|
||||
protected function promoteShareData($param)
|
||||
{
|
||||
$site_id = $param[ 'site_id' ] ?? 0;
|
||||
$member_id = $param[ 'member_id' ] ?? 0;
|
||||
$param[ 'url' ] = str_replace("/pages_promotion/fenxiao/promote_code", "/pages/index/index", $param[ 'url' ]);
|
||||
if (strpos($param[ 'url' ], '?')) $param[ 'url' ] = explode('?', $param[ 'url' ])[ 0 ];
|
||||
|
||||
//站点设置
|
||||
$site_model = new SiteModel();
|
||||
$site_info = $site_model->getSiteInfo([ [ 'site_id', '=', $site_id ] ])[ 'data' ];
|
||||
|
||||
//跳转路径
|
||||
$link = $this->getShareLink($param);
|
||||
|
||||
//会员信息
|
||||
$member_model = new MemberModel();
|
||||
$member_info = $member_model->getMemberInfo([ [ 'member_id', '=', $member_id ] ], 'nickname, headimg')[ 'data' ];
|
||||
|
||||
//获取和替换配置数据
|
||||
$config_data = $this->promoteShareConfig($param);
|
||||
$title = str_replace('{nickname}', $member_info[ 'nickname' ], $config_data[ 'value' ][ 'title' ]);
|
||||
$desc = str_replace('{nickname}', $member_info[ 'nickname' ], $config_data[ 'value' ][ 'desc' ]);
|
||||
$image_url = $config_data[ 'value' ][ 'imgUrl' ] ?: $site_info[ 'logo_square' ];
|
||||
|
||||
$data = [
|
||||
'title' => $title,
|
||||
'desc' => $desc,
|
||||
'link' => $link,
|
||||
'imgUrl' => $image_url,
|
||||
];
|
||||
return [
|
||||
'permission' => [
|
||||
'hideOptionMenu' => false,
|
||||
'hideMenuItems' => [],
|
||||
],
|
||||
'data' => $data,//分享内容
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 推广分享配置
|
||||
* @param $param
|
||||
* @return array
|
||||
*/
|
||||
protected function promoteShareConfig($param)
|
||||
{
|
||||
$site_id = $param[ 'site_id' ];
|
||||
$config = $param[ 'config' ];
|
||||
|
||||
$config_model = new ConfigModel();
|
||||
$data = $config_model->getConfig([
|
||||
[ 'site_id', '=', $site_id ],
|
||||
[ 'app_module', '=', 'shop' ],
|
||||
[ 'config_key', '=', $config[ 'config_key' ] ],
|
||||
])[ 'data' ];
|
||||
if (empty($data[ 'value' ])) {
|
||||
$data[ 'value' ] = [
|
||||
'title' => "快来加入{nickname}的团队吧,一起赚佣金哦",
|
||||
'desc' => "好物精选\n向您推荐",
|
||||
'imgUrl' => '',
|
||||
];
|
||||
}
|
||||
if (empty($data[ 'value' ][ 'imgUrl' ])) {
|
||||
$data[ 'value' ][ 'imgUrl' ] = img('addon/fenxiao/icon.png');
|
||||
}
|
||||
$variable = [
|
||||
[ 'title' => '用户昵称', 'name' => '{nickname}' ],
|
||||
];
|
||||
|
||||
return [
|
||||
'value' => $data[ 'value' ],
|
||||
'variable' => $variable,
|
||||
];
|
||||
}
|
||||
}
|
||||
100
addon/fenxiao/model/share/WeappShare.php
Executable file
100
addon/fenxiao/model/share/WeappShare.php
Executable file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\fenxiao\model\share;
|
||||
|
||||
use app\model\member\Member as MemberModel;
|
||||
use app\model\share\WeappShareBase as BaseModel;
|
||||
use app\model\system\Config as ConfigModel;
|
||||
|
||||
/**
|
||||
* 分享
|
||||
*/
|
||||
class WeappShare extends BaseModel
|
||||
{
|
||||
protected $config = [
|
||||
[
|
||||
'title' => '分销推广',
|
||||
'config_key' => 'WEAPP_SHARE_CONFIG_FENXIAO_PROMOTE',
|
||||
'path' => [ '/pages_promotion/fenxiao/promote_code' ],
|
||||
'method_prefix' => 'promote',
|
||||
],
|
||||
];
|
||||
|
||||
protected $sort = 2;
|
||||
|
||||
/**
|
||||
* 首页分享数据
|
||||
* @param $param
|
||||
* @return array
|
||||
*/
|
||||
protected function promoteShareData($param)
|
||||
{
|
||||
$member_id = $param[ 'member_id' ] ?? 0;
|
||||
$param[ 'path' ] = str_replace("/pages_promotion/fenxiao/promote_code", "/pages/index/index", $param[ 'path' ]);
|
||||
if (strpos($param[ 'path' ], '?')) $param[ 'path' ] = explode('?', $param[ 'path' ])[ 0 ];
|
||||
|
||||
//会员信息
|
||||
$member_model = new MemberModel();
|
||||
$member_info = $member_model->getMemberInfo([ [ 'member_id', '=', $member_id ] ], 'nickname, headimg')[ 'data' ];
|
||||
|
||||
//获取和替换配置数据
|
||||
$config_data = $this->promoteShareConfig($param);
|
||||
$title = str_replace('{nickname}', $member_info[ 'nickname' ], $config_data[ 'value' ][ 'title' ]);
|
||||
$image_url = $config_data[ 'value' ][ 'imageUrl' ] ? img($config_data[ 'value' ][ 'imageUrl' ]) : '';
|
||||
$path = $this->getSharePath($param);
|
||||
|
||||
$data = [
|
||||
'title' => $title,
|
||||
'path' => $path,
|
||||
'imageUrl' => $image_url,
|
||||
];
|
||||
return [
|
||||
'permission' => [
|
||||
'onShareAppMessage' => true,
|
||||
'onShareTimeline' => true,
|
||||
],
|
||||
'data' => $data,//分享内容
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 首页分享配置
|
||||
* @param $param
|
||||
* @return array
|
||||
*/
|
||||
protected function promoteShareConfig($param)
|
||||
{
|
||||
$site_id = $param[ 'site_id' ];
|
||||
$config = $param[ 'config' ];
|
||||
|
||||
$config_model = new ConfigModel();
|
||||
$data = $config_model->getConfig([
|
||||
[ 'site_id', '=', $site_id ],
|
||||
[ 'app_module', '=', 'shop' ],
|
||||
[ 'config_key', '=', $config[ 'config_key' ] ],
|
||||
])[ 'data' ];
|
||||
if (empty($data[ 'value' ])) {
|
||||
$data[ 'value' ] = [
|
||||
'title' => '快来加入{nickname}的团队吧,一起赚有佣金哦',
|
||||
'imageUrl' => '',
|
||||
];
|
||||
}
|
||||
$variable = [
|
||||
[ 'title' => '用户昵称', 'name' => '{nickname}' ],
|
||||
];
|
||||
|
||||
return [
|
||||
'value' => $data[ 'value' ],
|
||||
'variable' => $variable,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user