初始上传
This commit is contained in:
50
addon/fenxiao/api/controller/Account.php
Executable file
50
addon/fenxiao/api/controller/Account.php
Executable file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\fenxiao\api\controller;
|
||||
|
||||
use addon\fenxiao\model\FenxiaoAccount;
|
||||
use addon\fenxiao\model\Fenxiao as FenxiaoModel;
|
||||
use app\api\controller\BaseApi;
|
||||
|
||||
/**
|
||||
* 分销商流水
|
||||
*/
|
||||
class Account extends BaseApi
|
||||
{
|
||||
|
||||
/**
|
||||
* 分销商流水分页
|
||||
* @return false|string
|
||||
*/
|
||||
public function page()
|
||||
{
|
||||
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] < 0) return $this->response($token);
|
||||
|
||||
$page = $this->params['page'] ?? 1;
|
||||
$page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
|
||||
|
||||
$model = new FenxiaoModel();
|
||||
$fenxiao_info = $model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id')[ 'data' ];
|
||||
if (!empty($fenxiao_info[ 'fenxiao_id' ])) {
|
||||
$condition = [
|
||||
[ 'fenxiao_id', '=', $fenxiao_info[ 'fenxiao_id' ] ]
|
||||
];
|
||||
|
||||
$account_model = new FenxiaoAccount();
|
||||
$list = $account_model->getFenxiaoAccountPageList($condition, $page, $page_size);
|
||||
return $this->response($list);
|
||||
}
|
||||
return $this->response($this->error('', 'FENXIAO_NOT_EXIST'));
|
||||
}
|
||||
|
||||
}
|
||||
99
addon/fenxiao/api/controller/Apply.php
Executable file
99
addon/fenxiao/api/controller/Apply.php
Executable file
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\fenxiao\api\controller;
|
||||
|
||||
use addon\fenxiao\model\Config;
|
||||
use addon\fenxiao\model\FenxiaoApply;
|
||||
use addon\fenxiao\model\Fenxiao;
|
||||
use app\api\controller\BaseApi;
|
||||
|
||||
/**
|
||||
* 申请分销商
|
||||
*/
|
||||
class Apply extends BaseApi
|
||||
{
|
||||
/**
|
||||
* 判断分销商名称是否存在
|
||||
*/
|
||||
public function existFenxiaoName()
|
||||
{
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] < 0) return $this->response($token);
|
||||
|
||||
$fenxiao_name = $this->params['fenxiao_name'] ?? '';//分销商名称
|
||||
if (empty($fenxiao_name)) {
|
||||
return $this->response($this->error('', 'REQUEST_FENXIAO_NAME'));
|
||||
}
|
||||
|
||||
$apply_model = new FenxiaoApply();
|
||||
$res = $apply_model->existFenxiaoName($fenxiao_name, $this->site_id);
|
||||
|
||||
return $this->response($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 申请成为分销商
|
||||
*/
|
||||
public function applyFenxiao()
|
||||
{
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] < 0) return $this->response($token);
|
||||
|
||||
$fenxiao_name = $this->params['fenxiao_name'] ?? '';//分销商名称
|
||||
$mobile = $this->params['mobile'] ?? '';//联系电话
|
||||
|
||||
$config = new Config();
|
||||
$basics_config = $config->getFenxiaoBasicsConfig($this->site_id)[ 'data' ][ 'value' ];
|
||||
if (!$basics_config[ 'level' ]) return $this->response($this->error('', '未开启分销功能'));
|
||||
|
||||
if ($basics_config[ 'is_apply' ] == 1) {
|
||||
if (empty($fenxiao_name)) {
|
||||
return $this->response($this->error('', 'REQUEST_FENXIAO_NAME'));
|
||||
}
|
||||
if (empty($mobile)) {
|
||||
return $this->response($this->error('', 'REQUEST_MOBILE'));
|
||||
}
|
||||
$apply_model = new FenxiaoApply();
|
||||
$res = $apply_model->applyFenxiao($this->member_id, $this->site_id, $fenxiao_name, $mobile);
|
||||
} else if ($basics_config[ 'is_apply' ] == 0) {
|
||||
$apply_model = new Fenxiao();
|
||||
$res = $apply_model->autoBecomeFenxiao($this->member_id, $this->site_id);
|
||||
} else {
|
||||
return $this->response($this->error('', '未开启分销商申请'));
|
||||
}
|
||||
|
||||
return $this->response($res);
|
||||
}
|
||||
|
||||
public function info()
|
||||
{
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] < 0) return $this->response($token);
|
||||
|
||||
$apply_model = new Fenxiao();
|
||||
$apply_model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'apply_id,fenxiao_name,parent,member_id,mobile,nickname,headimg,level_id,level_name,status');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取申请分销商状态
|
||||
* @return false|string
|
||||
*/
|
||||
public function status()
|
||||
{
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] < 0) return $this->response($token);
|
||||
|
||||
$apply_model = new FenxiaoApply();
|
||||
$res = $apply_model->getFenxiaoApplyInfo([ [ 'member_id', '=', $this->member_id ] ], 'status');
|
||||
return $this->response($res);
|
||||
}
|
||||
|
||||
}
|
||||
127
addon/fenxiao/api/controller/Config.php
Executable file
127
addon/fenxiao/api/controller/Config.php
Executable file
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\fenxiao\api\controller;
|
||||
|
||||
use app\api\controller\BaseApi;
|
||||
use addon\fenxiao\model\Config as ConfigModel;
|
||||
use app\model\goods\Goods;
|
||||
use app\model\system\Document;
|
||||
|
||||
/**
|
||||
* 分销相关配置
|
||||
*/
|
||||
class Config extends BaseApi
|
||||
{
|
||||
|
||||
/**
|
||||
* 提现配置
|
||||
*/
|
||||
public function withdraw()
|
||||
{
|
||||
$config = new ConfigModel();
|
||||
$res = $config->getFenxiaoWithdrawConfig($this->site_id);
|
||||
return $this->response($this->success($res[ 'data' ][ 'value' ]));
|
||||
}
|
||||
|
||||
/**
|
||||
* 文字设置
|
||||
* @return false|string
|
||||
*/
|
||||
public function words()
|
||||
{
|
||||
$config = new ConfigModel();
|
||||
$res = $config->getFenxiaoWordsConfig($this->site_id);
|
||||
return $this->response($this->success($res[ 'data' ][ 'value' ]));
|
||||
}
|
||||
|
||||
/**
|
||||
* 申请协议
|
||||
* @return false|string
|
||||
*/
|
||||
public function agreement()
|
||||
{
|
||||
$config = new ConfigModel();
|
||||
$agreement = $config->getFenxiaoAgreementConfig($this->site_id);
|
||||
$res = [];
|
||||
$res[ 'agreement' ] = $agreement[ 'data' ][ 'value' ];
|
||||
if ($agreement[ 'data' ][ 'value' ][ 'is_agreement' ] == 1) {
|
||||
$document_model = new Document();
|
||||
$document = $document_model->getDocument([ [ 'site_id', '=', $this->site_id ], [ 'app_module', '=', 'shop' ], [ 'document_key', '=', 'FENXIAO_AGREEMENT'] ]);
|
||||
$res[ 'document' ] = $document[ 'data' ];
|
||||
}
|
||||
|
||||
return $this->response($this->success($res));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分销基本设置
|
||||
* @return false|string
|
||||
*/
|
||||
public function basics()
|
||||
{
|
||||
$config = new ConfigModel();
|
||||
$res = $config->getFenxiaoBasicsConfig($this->site_id);
|
||||
return $this->response($this->success($res[ 'data' ][ 'value' ]));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分销商资格设置
|
||||
* @return false|string
|
||||
*/
|
||||
public function fenxiao()
|
||||
{
|
||||
$config = new ConfigModel();
|
||||
$res = $config->getFenxiaoConfig($this->site_id);
|
||||
$res[ 'data' ][ 'value' ][ 'goods_list' ] = [];
|
||||
// 购买指定商品
|
||||
if ($res[ 'data' ][ 'value' ][ 'fenxiao_condition' ] == 4) {
|
||||
$page = $this->params[ 'page' ] ?? 1;
|
||||
$page_size = $this->params[ 'page_size' ] ?? 10;
|
||||
$condition[] = [ 'gs.goods_state', '=', 1 ];
|
||||
$condition[] = [ 'gs.is_delete', '=', 0 ];
|
||||
$condition[] = [ 'gs.site_id', '=', $this->site_id ];
|
||||
$condition[] = [ 'gs.goods_id', 'in', $res[ 'data' ][ 'value' ][ 'goods_ids' ] ];
|
||||
|
||||
$field = 'gs.goods_id,gs.sku_id,gs.sku_name,gs.price,gs.market_price,gs.discount_price,gs.stock,(g.sale_num + g.virtual_sale) as sale_num,gs.sku_image,gs.goods_name,gs.site_id,gs.is_free_shipping,gs.introduction,gs.promotion_type,g.goods_image,gs.unit';
|
||||
$alias = 'gs';
|
||||
$join = [
|
||||
[ 'goods g', 'gs.sku_id = g.sku_id', 'inner' ]
|
||||
];
|
||||
$goods = new Goods();
|
||||
$list = $goods->getGoodsSkuPageList($condition, $page, $page_size, '', $field, $alias, $join);
|
||||
$res[ 'data' ][ 'value' ][ 'goods_list' ] = $list[ 'data' ][ 'list' ];
|
||||
}
|
||||
|
||||
return $this->response($this->success($res[ 'data' ][ 'value' ]));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取上下级关系设置
|
||||
* @return false|string
|
||||
*/
|
||||
public function relation()
|
||||
{
|
||||
$config = new ConfigModel();
|
||||
$res = $config->getFenxiaoRelationConfig($this->site_id);
|
||||
return $this->response($this->success($res[ 'data' ][ 'value' ]));
|
||||
}
|
||||
|
||||
/**
|
||||
* 推广规则
|
||||
* @return false|string
|
||||
*/
|
||||
public function promoteRule()
|
||||
{
|
||||
$document_model = new Document();
|
||||
$document = $document_model->getDocument([ [ 'site_id', '=', $this->site_id ], [ 'app_module', '=', 'shop' ], [ 'document_key', '=', 'FENXIAO_PROMOTE_RULE'] ]);
|
||||
return $this->response($document);
|
||||
}
|
||||
}
|
||||
407
addon/fenxiao/api/controller/Fenxiao.php
Executable file
407
addon/fenxiao/api/controller/Fenxiao.php
Executable file
@@ -0,0 +1,407 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\fenxiao\api\controller;
|
||||
|
||||
use addon\fenxiao\model\Config;
|
||||
use addon\fenxiao\model\Fenxiao as FenxiaoModel;
|
||||
use addon\fenxiao\model\FenxiaoLevel;
|
||||
use addon\fenxiao\model\FenxiaoOrder as FenxiaoOrderModel;
|
||||
use addon\fenxiao\model\Poster;
|
||||
use addon\fenxiao\model\PosterTemplate as PosterTemplateModel;
|
||||
use app\api\controller\BaseApi;
|
||||
use app\model\member\Member;
|
||||
use Carbon\Carbon;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 分销相关信息
|
||||
*/
|
||||
class Fenxiao extends BaseApi
|
||||
{
|
||||
/**
|
||||
* 获取分销商信息
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] < 0) return $this->response($token);
|
||||
|
||||
$condition = [
|
||||
[ 'f.member_id', '=', $this->member_id ]
|
||||
];
|
||||
|
||||
$model = new FenxiaoModel();
|
||||
$info = $model->getFenxiaoDetailInfo($condition);
|
||||
if (empty($info[ 'data' ])) {
|
||||
$res = $model->autoBecomeFenxiao($this->member_id, $this->site_id);
|
||||
if (isset($res[ 'code' ]) && $res[ 'code' ] >= 0) {
|
||||
$info = $model->getFenxiaoDetailInfo($condition);
|
||||
}
|
||||
} else {
|
||||
$member = new Member();
|
||||
//$info[ 'data' ][ 'one_child_num' ] = $member->getMemberCount([ [ 'fenxiao_id', '=', $info[ 'data' ][ 'fenxiao_id' ] ], [ 'is_fenxiao', '=', 0 ] ])[ 'data' ];
|
||||
|
||||
$condition_result = $model->geFenxiaoNextLevel($this->member_id, $this->site_id);
|
||||
$info[ 'data' ][ 'condition' ] = $condition_result[ 'data' ];
|
||||
}
|
||||
|
||||
if (!empty($info[ 'data' ])) {
|
||||
$fenxiao_order_model = new FenxiaoOrderModel();
|
||||
|
||||
// 今日收入
|
||||
$compare_today = Carbon::today()->timestamp;
|
||||
$compare_tomorrow = Carbon::tomorrow()->timestamp;
|
||||
|
||||
$commission = 0;
|
||||
$one_commission = $fenxiao_order_model->getFenxiaoOrderInfo([ [ 'one_fenxiao_id', '=', $info[ 'data' ][ 'fenxiao_id' ] ], [ 'create_time', 'between', [ $compare_today, $compare_tomorrow ] ], [ 'is_settlement', '=', 1 ] ], 'sum(one_commission) as commission');
|
||||
$two_commission = $fenxiao_order_model->getFenxiaoOrderInfo([ [ 'two_fenxiao_id', '=', $info[ 'data' ][ 'fenxiao_id' ] ], [ 'create_time', 'between', [ $compare_today, $compare_tomorrow ] ], [ 'is_settlement', '=', 1 ] ], 'sum(two_commission) as commission');
|
||||
$three_commission = $fenxiao_order_model->getFenxiaoOrderInfo([ [ 'three_fenxiao_id', '=', $info[ 'data' ][ 'fenxiao_id' ] ], [ 'create_time', 'between', [ $compare_today, $compare_tomorrow ] ], [ 'is_settlement', '=', 1 ] ], 'sum(three_commission) as commission');
|
||||
|
||||
if (!empty($one_commission[ 'data' ][ 'commission' ])) $commission += $one_commission[ 'data' ][ 'commission' ];
|
||||
if (!empty($two_commission[ 'data' ][ 'commission' ])) $commission += $two_commission[ 'data' ][ 'commission' ];
|
||||
if (!empty($three_commission[ 'data' ][ 'commission' ])) $commission += $three_commission[ 'data' ][ 'commission' ];
|
||||
|
||||
$info[ 'data' ][ 'today_commission' ] = $commission;
|
||||
|
||||
// 总销售额
|
||||
$fenxiao_order_info = $fenxiao_order_model->getFenxiaoOrderInfoNew([ [ 'fo.one_fenxiao_id|fo.two_fenxiao_id|fo.three_fenxiao_id', '=', $info[ 'data' ][ 'fenxiao_id' ] ], ['', 'exp', Db::raw('fo.is_refund=0 or (o.order_status=10 and fo.is_refund=1) ') ] ], 'sum(fo.real_goods_money) as real_goods_money');
|
||||
|
||||
$fenxiao_order_info = $fenxiao_order_info[ 'data' ];
|
||||
if (empty($fenxiao_order_info[ 'real_goods_money' ])) {
|
||||
$fenxiao_order_info[ 'real_goods_money' ] = 0;
|
||||
}
|
||||
$info[ 'data' ][ 'today_order_money' ] = $fenxiao_order_info[ 'real_goods_money' ];
|
||||
|
||||
$info[ 'data' ][ 'in_progress_money' ] = 0;
|
||||
$one_in_progress_commission = $fenxiao_order_model->getFenxiaoOrderInfo([ [ 'one_fenxiao_id', '=', $info[ 'data' ][ 'fenxiao_id' ] ], [ 'is_settlement', '=', 0 ], [ 'is_refund', '=', 0 ] ], 'sum(one_commission) as commission');
|
||||
$two_in_progress_commission = $fenxiao_order_model->getFenxiaoOrderInfo([ [ 'two_fenxiao_id', '=', $info[ 'data' ][ 'fenxiao_id' ] ], [ 'is_settlement', '=', 0 ], [ 'is_refund', '=', 0 ] ], 'sum(two_commission) as commission');
|
||||
$three_in_progress_commission = $fenxiao_order_model->getFenxiaoOrderInfo([ [ 'three_fenxiao_id', '=', $info[ 'data' ][ 'fenxiao_id' ] ], [ 'is_settlement', '=', 0 ], [ 'is_refund', '=', 0 ] ], 'sum(three_commission) as commission');
|
||||
|
||||
if (!empty($one_in_progress_commission[ 'data' ][ 'commission' ])) $info[ 'data' ][ 'in_progress_money' ] += $one_in_progress_commission[ 'data' ][ 'commission' ];
|
||||
if (!empty($two_in_progress_commission[ 'data' ][ 'commission' ])) $info[ 'data' ][ 'in_progress_money' ] += $two_in_progress_commission[ 'data' ][ 'commission' ];
|
||||
if (!empty($three_in_progress_commission[ 'data' ][ 'commission' ])) $info[ 'data' ][ 'in_progress_money' ] += $three_in_progress_commission[ 'data' ][ 'commission' ];
|
||||
}
|
||||
return $this->response($info);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取推荐人分销商信息
|
||||
*/
|
||||
public function sourceInfo()
|
||||
{
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] < 0) return $this->response($token);
|
||||
|
||||
$member = new Member();
|
||||
$member_info = $member->getMemberInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id');
|
||||
$fenxiao_id = $member_info[ 'data' ][ 'fenxiao_id' ] ?? 0;
|
||||
|
||||
if (empty($fenxiao_id)) {
|
||||
return $this->response($this->error('', 'REQUEST_SOURCE_MEMBER'));
|
||||
}
|
||||
$condition = [
|
||||
[ 'fenxiao_id', '=', $fenxiao_id ]
|
||||
];
|
||||
|
||||
$model = new FenxiaoModel();
|
||||
$info = $model->getFenxiaoInfo($condition, 'fenxiao_name');
|
||||
|
||||
return $this->response($info);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模板id
|
||||
* @return false|string
|
||||
*/
|
||||
public function posterTemplateIds()
|
||||
{
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] < 0) return $this->response($token);
|
||||
|
||||
$condition = [
|
||||
[ 'site_id', '=', $this->site_id ],
|
||||
[ 'template_type', '=', 'fenxiao' ],
|
||||
[ 'template_status', '=', 1 ],
|
||||
];
|
||||
$condition[] = [ 'template_type', '=', 'fenxiao' ];
|
||||
$poster_template_model = new PosterTemplateModel();
|
||||
$list = $poster_template_model->getPosterTemplateList($condition, 'template_id', 'template_id asc')[ 'data' ];
|
||||
$id_arr = array_column($list, 'template_id');
|
||||
if (empty($id_arr)) $id_arr = [ 'default' ];
|
||||
|
||||
return $this->response($this->success($id_arr));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分销海报
|
||||
* @return \app\api\controller\false|string
|
||||
*/
|
||||
public function poster()
|
||||
{
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] < 0) return $this->response($token);
|
||||
|
||||
$qrcode_param = $this->params['qrcode_param'] ?? '';//二维码
|
||||
|
||||
if (empty($qrcode_param)) {
|
||||
return $this->response($this->error('', 'REQUEST_QRCODE_PARAM'));
|
||||
}
|
||||
|
||||
$qrcode_param = json_decode($qrcode_param, true);
|
||||
$qrcode_param[ 'source_member' ] = $this->member_id;
|
||||
|
||||
$poster = new Poster();
|
||||
$param = $this->params;
|
||||
$param[ 'qrcode_param' ] = $qrcode_param;
|
||||
$res = $poster->getFenxiaoPoster($param);
|
||||
|
||||
return $this->response($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分销海报
|
||||
* @return \app\api\controller\false|string
|
||||
*/
|
||||
public function posterList()
|
||||
{
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] < 0) return $this->response($token);
|
||||
|
||||
$condition = [
|
||||
[ 'site_id', '=', $this->site_id ],
|
||||
[ 'template_type', '=', 'fenxiao' ],
|
||||
[ 'template_status', '=', 1 ],
|
||||
];
|
||||
$condition[] = [ 'template_type', '=', 'fenxiao' ];
|
||||
$poster_template_model = new PosterTemplateModel();
|
||||
$list = $poster_template_model->getPosterTemplateList($condition, 'template_id', 'template_id asc')[ 'data' ];
|
||||
$id_arr = array_column($list, 'template_id');
|
||||
$id_arr = $id_arr ?: ['default'];
|
||||
$qrcode_param = $this->params['qrcode_param'] ?? '';//二维码
|
||||
$qrcode_param = [json_decode($qrcode_param, true)];
|
||||
$qrcode_param[ 'source_member' ] = $this->member_id;
|
||||
$poster = new Poster();
|
||||
$param = $this->params;
|
||||
$param[ 'qrcode_param' ] = $qrcode_param;
|
||||
$path = [];
|
||||
foreach ($id_arr as $k => $v){
|
||||
$param['template_id'] = $v;
|
||||
$res = $poster->getFenxiaoPoster($param)['data']['path'] ?? '';
|
||||
if($res) $path[] = $res;
|
||||
}
|
||||
return $this->response($this->success($path));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分销商等级信息
|
||||
*/
|
||||
public function level()
|
||||
{
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] < 0) return $this->response($token);
|
||||
|
||||
$level = $this->params[ 'level' ] ?? 0;
|
||||
|
||||
$condition = [
|
||||
[ 'level_id', '=', $level ]
|
||||
];
|
||||
$model = new FenxiaoLevel();
|
||||
$info = $model->getLevelInfo($condition);
|
||||
|
||||
return $this->response($info);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分销商我的团队
|
||||
*/
|
||||
public function team()
|
||||
{
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] < 0) return $this->response($token);
|
||||
|
||||
$page = $this->params[ 'page' ] ?? 1;
|
||||
$page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
|
||||
$level = $this->params[ 'level' ] ?? 1;
|
||||
$is_pay = $this->params[ 'is_pay' ] ?? 0;
|
||||
|
||||
$model = new FenxiaoModel();
|
||||
$fenxiao_info = $model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id');
|
||||
if (empty($fenxiao_info[ 'data' ])) return $this->response($this->error('', 'MEMBER_NOT_IS_FENXIAO'));
|
||||
|
||||
$list = $model->getFenxiaoTeam($level, $fenxiao_info[ 'data' ][ 'fenxiao_id' ], $page, $page_size, $is_pay);
|
||||
|
||||
return $this->response($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询我的团队的数量
|
||||
*/
|
||||
public function teamNum()
|
||||
{
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] < 0) return $this->response($token);
|
||||
|
||||
$model = new FenxiaoModel();
|
||||
$fenxiao_info = $model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id');
|
||||
if (empty($fenxiao_info[ 'data' ])) return $this->response($this->error('', 'MEMBER_NOT_IS_FENXIAO'));
|
||||
|
||||
$data = $model->getFenxiaoTeamNum($fenxiao_info[ 'data' ][ 'fenxiao_id' ], $this->site_id);
|
||||
return $this->response($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取下级分销商订单
|
||||
* @return false|string
|
||||
*/
|
||||
public function getOrder()
|
||||
{
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] < 0) return $this->response($token);
|
||||
|
||||
$model = new FenxiaoModel();
|
||||
$fenxiao_info = $model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id');
|
||||
if (empty($fenxiao_info[ 'data' ])) return $this->response($this->error('', 'MEMBER_NOT_IS_FENXIAO'));
|
||||
$fenxiao_info = $fenxiao_info[ 'data' ];
|
||||
|
||||
$page = $this->params[ 'page' ] ?? 1;
|
||||
$page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
|
||||
$fenxiao_id = $this->params[ 'fenxiao_id' ] ?? 0;
|
||||
$sub_member_id = $this->params[ 'sub_member_id' ] ?? 0;
|
||||
$condition = [];
|
||||
|
||||
if (!empty($fenxiao_id)) {
|
||||
$sub_fenxiao_info = $model->getFenxiaoInfo([ [ 'fenxiao_id', '=', $fenxiao_id ] ], 'fenxiao_id,member_id')[ 'data' ];
|
||||
if (empty($sub_fenxiao_info)) return $this->response($this->error('', 'MEMBER_NOT_IS_FENXIAO'));
|
||||
|
||||
$condition = [
|
||||
[ '', 'exp', Db::raw("( (fo.one_fenxiao_id = {$fenxiao_info['fenxiao_id']} AND fo.two_fenxiao_id = {$fenxiao_id}) OR (fo.two_fenxiao_id = {$fenxiao_info['fenxiao_id']} AND fo.three_fenxiao_id = {$fenxiao_id})) OR fo.member_id = {$sub_fenxiao_info['member_id']}") ]
|
||||
];
|
||||
} elseif (!empty($sub_member_id)) {
|
||||
$is_sub_member = model('member')->getCount([ [ 'member_id', '=', $sub_member_id ], [ 'fenxiao_id', '=', $fenxiao_info[ 'fenxiao_id' ] ] ]);
|
||||
if (!$is_sub_member) return $this->response($this->error('', 'NOT_EXIST_FENXIAO_RELATION'));
|
||||
|
||||
$condition = [
|
||||
[ 'fo.one_fenxiao_id', '=', $fenxiao_info[ 'fenxiao_id' ] ],
|
||||
[ 'fo.member_id', '=', $sub_member_id ]
|
||||
];
|
||||
}
|
||||
|
||||
$order_model = new FenxiaoOrderModel();
|
||||
$list = $order_model->getFenxiaoOrderPageList($condition, $page, $page_size, 'fo.fenxiao_order_id desc');
|
||||
if (!empty($list[ 'data' ][ 'list' ])) {
|
||||
foreach ($list[ 'data' ][ 'list' ] as $k => $item) {
|
||||
if ($item[ 'one_fenxiao_id' ] == $fenxiao_info[ 'fenxiao_id' ]) {
|
||||
$list[ 'data' ][ 'list' ][ $k ][ 'commission' ] = $item[ 'one_commission' ];
|
||||
$list[ 'data' ][ 'list' ][ $k ][ 'commission_level' ] = 1;
|
||||
} elseif ($item[ 'two_fenxiao_id' ] == $fenxiao_info[ 'fenxiao_id' ]) {
|
||||
$list[ 'data' ][ 'list' ][ $k ][ 'commission' ] = $item[ 'two_commission' ];
|
||||
$list[ 'data' ][ 'list' ][ $k ][ 'commission_level' ] = 2;
|
||||
} elseif ($item[ 'three_fenxiao_id' ] == $fenxiao_info[ 'fenxiao_id' ]) {
|
||||
$list[ 'data' ][ 'list' ][ $k ][ 'commission' ] = $item[ 'three_commission' ];
|
||||
$list[ 'data' ][ 'list' ][ $k ][ 'commission_level' ] = 3;
|
||||
}
|
||||
$list[ 'data' ][ 'list' ][ $k ] = array_diff_key($list[ 'data' ][ 'list' ][ $k ], [ 'one_fenxiao_id' => '', 'one_rate' => '', 'one_commission' => '', 'one_fenxiao_name' => '', 'two_fenxiao_id' => '', 'two_rate' => '', 'two_commission' => '', 'two_fenxiao_name' => '', 'three_fenxiao_id' => '', 'three_rate' => '', 'three_commission' => '', 'three_fenxiao_name' => '' ]);
|
||||
}
|
||||
}
|
||||
return $this->response($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 排行榜
|
||||
*/
|
||||
public function rankingList()
|
||||
{
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] < 0) return $this->response($token);
|
||||
|
||||
$type = $this->params[ 'type' ] ?? 'profit'; // 排行榜 profit:按受益 invited_num:按邀请人数
|
||||
$page = $this->params[ 'page' ] ?? 1;
|
||||
$page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
|
||||
|
||||
$model = new FenxiaoModel();
|
||||
|
||||
$condition = [
|
||||
[ 'f.site_id', '=', $this->site_id ],
|
||||
[ 'f.is_delete', '=', 0 ]
|
||||
];
|
||||
|
||||
$order = $type == 'profit' ? 'f.total_commission desc' : Db::raw('(f.one_child_num) desc');
|
||||
$field = 'f.total_commission, (f.one_child_num) as child_num, m.nickname,m.headimg';
|
||||
|
||||
$data = $model->getFenxiaoPageLists($condition, $page, $page_size, $order, $field, 'f', [ [ 'member m', 'm.member_id = f.member_id', 'inner' ] ]);
|
||||
|
||||
return $this->response($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取排名
|
||||
* @return false|string
|
||||
*/
|
||||
public function ranking()
|
||||
{
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] < 0) return $this->response($token);
|
||||
|
||||
$type = $this->params[ 'type' ] ?? 'invited_num'; // 排行榜 profit:按受益 invited_num:按邀请人数
|
||||
|
||||
$model = new FenxiaoModel();
|
||||
$fenxiao_info = $model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id')[ 'data' ];
|
||||
if (empty($fenxiao_info)) return $this->response($this->error('', 'MEMBER_NOT_IS_FENXIAO'));
|
||||
|
||||
$order = $type == 'profit' ? 'total_commission' : '(one_child_num + one_child_fenxiao_num)';
|
||||
|
||||
$data = $model->getFenxiaoRanking($this->site_id, $fenxiao_info[ 'fenxiao_id' ], $order);
|
||||
return $this->response($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 子级分销商
|
||||
*/
|
||||
public function childFenxiao()
|
||||
{
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] < 0) return $this->response($token);
|
||||
|
||||
$page = $this->params[ 'page' ] ?? 1;
|
||||
$page_size = $this->params[ 'page_size' ] ?? PAGE_LIST_ROWS;
|
||||
|
||||
$model = new FenxiaoModel();
|
||||
$fenxiao_info = $model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id')[ 'data' ];
|
||||
if (empty($fenxiao_info)) return $this->response($this->error('', 'MEMBER_NOT_IS_FENXIAO'));
|
||||
|
||||
$parent_fenxiao_id = [ $fenxiao_info[ 'fenxiao_id' ] ]; // 上级分销商id集合
|
||||
|
||||
// 查询分销基础配置
|
||||
$config_model = new Config();
|
||||
$fenxiao_basic_config = $config_model->getFenxiaoBasicsConfig($this->site_id)[ 'data' ][ 'value' ];
|
||||
$level = $fenxiao_basic_config[ 'level' ];
|
||||
|
||||
if ($level == 2) {
|
||||
|
||||
// 二级分销商id集合
|
||||
$one_level_fenxiao = model('fenxiao')->getColumn([ [ 'parent', '=', $fenxiao_info[ 'fenxiao_id' ] ] ], 'fenxiao_id');
|
||||
if (!empty($one_level_fenxiao)) {
|
||||
$parent_fenxiao_id = array_merge($parent_fenxiao_id, $one_level_fenxiao);
|
||||
}
|
||||
}
|
||||
|
||||
$condition = [
|
||||
[ 'f.site_id', '=', $this->site_id ],
|
||||
[ 'f.parent', 'in', $parent_fenxiao_id ],
|
||||
[ 'm.is_delete', '=', 0 ]
|
||||
];
|
||||
$field = 'm.nickname,m.headimg,m.member_id,m.order_num,m.order_money,f.fenxiao_id,f.audit_time,f.level_name,m.is_fenxiao,m.bind_fenxiao_time,f.one_child_num,f.one_child_fenxiao_num';
|
||||
$join = [ [ 'member m', 'm.member_id = f.member_id', 'inner' ] ];
|
||||
|
||||
$res = $model->getFenxiaoPageLists($condition, $page, $page_size, 'f.audit_time desc', $field, 'f', $join);
|
||||
return $this->response($res);
|
||||
}
|
||||
}
|
||||
169
addon/fenxiao/api/controller/Goods.php
Executable file
169
addon/fenxiao/api/controller/Goods.php
Executable file
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\fenxiao\api\controller;
|
||||
|
||||
use addon\fenxiao\model\Config as ConfigModel;
|
||||
use addon\fenxiao\model\Fenxiao as FenxiaoModel;
|
||||
use addon\fenxiao\model\FenxiaoGoodsCollect as FenxiaoGoodsCollectModel;
|
||||
use addon\fenxiao\model\FenxiaoGoodsSku as FenxiaoGoodsSkuModel;
|
||||
use app\api\controller\BaseApi;
|
||||
|
||||
/**
|
||||
* 分销商品
|
||||
*/
|
||||
class Goods extends BaseApi
|
||||
{
|
||||
|
||||
/**
|
||||
* 分销商品详情
|
||||
* @param int $id
|
||||
* @return false|string
|
||||
*/
|
||||
public function detail($id = 0)
|
||||
{
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] < 0) return $this->response($token);
|
||||
|
||||
$sku_id = $this->params['sku_id'] ?? 0;
|
||||
if (!empty($id)) {
|
||||
$sku_id = $id;
|
||||
}
|
||||
if (empty($sku_id)) {
|
||||
return $this->response($this->error('', 'REQUEST_SKU_ID'));
|
||||
}
|
||||
|
||||
$config = new ConfigModel();
|
||||
|
||||
$words_config = $config->getFenxiaoWordsConfig($this->site_id)[ 'data' ][ 'value' ];
|
||||
|
||||
$data = [
|
||||
'words_account' => $words_config[ 'account' ],
|
||||
'commission_money' => 0.00
|
||||
];
|
||||
|
||||
$fenxiao_model = new FenxiaoModel();
|
||||
$fenxiao_info = $fenxiao_model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id,level_id')[ 'data' ];
|
||||
if (empty($fenxiao_info)) return $this->response($this->error());
|
||||
|
||||
$fenxiao_goods_sku_model = new FenxiaoGoodsSkuModel();
|
||||
$data[ 'commission_money' ] = $fenxiao_goods_sku_model->getSkuFenxiaoCommission($sku_id, $fenxiao_info[ 'level_id' ])[ 'data' ];
|
||||
|
||||
$basics = $config->getFenxiaoBasicsConfig($this->site_id);
|
||||
$data[ 'is_commission_money' ] = $basics[ 'data' ][ 'value' ][ 'is_commission_money' ];
|
||||
return $this->response($this->success($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分销商品分页列表
|
||||
*/
|
||||
public function page()
|
||||
{
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] < 0) return $this->response($token);
|
||||
|
||||
$page = $this->params['page'] ?? 1;
|
||||
$page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
|
||||
$keyword = $this->params['keyword'] ?? '';//关键词
|
||||
$category_id = $this->params['category_id'] ?? 0;//分类
|
||||
$min_price = $this->params['min_price'] ?? 0;//价格区间,小
|
||||
$max_price = $this->params['max_price'] ?? 0;//价格区间,大
|
||||
$is_free_shipping = $this->params['is_free_shipping'] ?? 0;//是否免邮
|
||||
$order = $this->params['order'] ?? 'create_time';//排序(综合、销量、价格)
|
||||
$sort = $this->params['sort'] ?? 'desc';//升序、降序
|
||||
$goods_id_arr = $this->params['goods_id_arr'] ?? '';//goods_id数组
|
||||
|
||||
$condition = [
|
||||
[ 'g.is_fenxiao', '=', 1 ],
|
||||
[ 'g.goods_state', '=', 1 ],
|
||||
[ 'g.is_delete', '=', 0 ],
|
||||
[ 'g.site_id', '=', $this->site_id ]
|
||||
];
|
||||
|
||||
if (!empty($keyword)) {
|
||||
$condition[] = [ 'g.goods_name|g.keywords', 'like', '%' . $keyword . '%' ];
|
||||
}
|
||||
|
||||
if (!empty($category_id)) {
|
||||
$condition[] = [ 'g.category_id', 'like', '%,' . $category_id . ',%' ];
|
||||
}
|
||||
|
||||
if (!empty($goods_id_arr)) {
|
||||
$condition[] = [ 'g.goods_id', 'in', $goods_id_arr ];
|
||||
}
|
||||
|
||||
if ($min_price != '' && $max_price != '') {
|
||||
$condition[] = [ 'g.discount_price', 'between', [ $min_price, $max_price ] ];
|
||||
} elseif ($min_price != '') {
|
||||
$condition[] = [ 'g.discount_price', '>=', $min_price ];
|
||||
} elseif ($max_price != '') {
|
||||
$condition[] = [ 'g.discount_price', '<=', $max_price ];
|
||||
}
|
||||
|
||||
if (!empty($is_free_shipping)) {
|
||||
$condition[] = [ 'g.is_free_shipping', '=', $is_free_shipping ];
|
||||
}
|
||||
|
||||
// 非法参数进行过滤
|
||||
if ($sort != 'desc' && $sort != 'asc') {
|
||||
$sort = '';
|
||||
}
|
||||
|
||||
// 非法参数进行过滤
|
||||
if ($order != '') {
|
||||
if ($order != 'sale_num' && $order != 'discount_price') {
|
||||
$order = 'gs.create_time';
|
||||
} elseif ($order != 'sale_num') {
|
||||
$order = 'gs.' . $order;
|
||||
} else {
|
||||
$order = 'sale_sort';
|
||||
}
|
||||
$order_by = $order . ' ' . $sort;
|
||||
} else {
|
||||
$order_by = 'g.sort desc,g.create_time desc';
|
||||
}
|
||||
|
||||
$fenxiao_model = new FenxiaoModel();
|
||||
$fenxiao_info = $fenxiao_model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id,level_id')[ 'data' ];
|
||||
|
||||
// $fenxiao_level = new FenxiaoLevel();
|
||||
// $level_info = $fenxiao_level->getLevelInfo([ [ 'level_id', '=', $fenxiao_info[ 'level_id' ] ] ], 'one_rate')[ 'data' ];
|
||||
|
||||
$fenxiao_goods_sku_model = new FenxiaoGoodsSkuModel();
|
||||
$list = $fenxiao_goods_sku_model->getFenxiaoGoodsSkuPageList($condition, $page, $page_size, $order_by);
|
||||
|
||||
$fenxiao_goods_collect_model = new FenxiaoGoodsCollectModel();
|
||||
|
||||
// 计算佣金
|
||||
foreach ($list[ 'data' ][ 'list' ] as $k => $v) {
|
||||
$collection_info = $fenxiao_goods_collect_model->getCollectInfo([
|
||||
[ 'member_id', '=', $this->member_id ],
|
||||
[ 'goods_id', '=', $v[ 'goods_id' ] ],
|
||||
[ 'fenxiao_id', '=', $fenxiao_info[ 'fenxiao_id' ] ],
|
||||
], 'collect_id');
|
||||
|
||||
// 查询是否关注该分销商品
|
||||
$collection_info = $collection_info[ 'data' ];
|
||||
if (!empty($collection_info)) {
|
||||
$list[ 'data' ][ 'list' ][ $k ][ 'is_collect' ] = 1;
|
||||
$list[ 'data' ][ 'list' ][ $k ][ 'collect_id' ] = $collection_info[ 'collect_id' ];
|
||||
} else {
|
||||
$list[ 'data' ][ 'list' ][ $k ][ 'is_collect' ] = 0;
|
||||
}
|
||||
|
||||
$sku_commission_info = $fenxiao_goods_sku_model->getSkuFenxiaoCommission($v[ 'sku_id' ], $fenxiao_info[ 'level_id' ]);
|
||||
$list[ 'data' ][ 'list' ][ $k ][ 'commission_money' ] = $sku_commission_info[ 'data' ];
|
||||
}
|
||||
|
||||
return $this->response($list);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
138
addon/fenxiao/api/controller/Goodscollect.php
Executable file
138
addon/fenxiao/api/controller/Goodscollect.php
Executable file
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\fenxiao\api\controller;
|
||||
|
||||
use addon\fenxiao\model\FenxiaoGoodsSku;
|
||||
use addon\fenxiao\model\FenxiaoLevel;
|
||||
use app\api\controller\BaseApi;
|
||||
use addon\fenxiao\model\Fenxiao as FenxiaoModel;
|
||||
use addon\fenxiao\model\FenxiaoGoodsCollect as FenxiaoGoodsCollectModel;
|
||||
|
||||
/**
|
||||
* 分销商关注商品
|
||||
*/
|
||||
class Goodscollect extends BaseApi
|
||||
{
|
||||
|
||||
/**
|
||||
* 添加分销商关注商品
|
||||
* @return false|string
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] < 0) return $this->response($token);
|
||||
|
||||
$goods_id = $this->params['goods_id'] ?? 0;
|
||||
$sku_id = $this->params['sku_id'] ?? 0;
|
||||
|
||||
if (empty($goods_id)) {
|
||||
return $this->response($this->error('', 'REQUEST_GOODS_ID'));
|
||||
}
|
||||
|
||||
$fenxiao_model = new FenxiaoModel();
|
||||
$fenxiao_info = $fenxiao_model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id')[ 'data' ];
|
||||
|
||||
$data = [
|
||||
'member_id' => $this->member_id,
|
||||
'fenxiao_id' => $fenxiao_info[ 'fenxiao_id' ],
|
||||
'goods_id' => $goods_id,
|
||||
'sku_id' => $sku_id,
|
||||
'site_id' => $this->site_id
|
||||
];
|
||||
$fenxiao_goods_sku_model = new FenxiaoGoodsCollectModel();
|
||||
$res = $fenxiao_goods_sku_model->addCollect($data);
|
||||
return $this->response($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除分销商关注商品
|
||||
* @return false|string
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] < 0) return $this->response($token);
|
||||
|
||||
$collect_id = $this->params['collect_id'] ?? 0;
|
||||
|
||||
if (empty($collect_id)) {
|
||||
return $this->response($this->error('', 'REQUEST_COLLECT_ID'));
|
||||
}
|
||||
|
||||
$fenxiao_model = new FenxiaoModel();
|
||||
$fenxiao_info = $fenxiao_model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id')[ 'data' ];
|
||||
$condition = [
|
||||
[ 'fenxiao_id', '=', $fenxiao_info[ 'fenxiao_id' ] ],
|
||||
[ 'collect_id', '=', $collect_id ]
|
||||
];
|
||||
$fenxiao_goods_sku_model = new FenxiaoGoodsCollectModel();
|
||||
$res = $fenxiao_goods_sku_model->deleteCollect($condition);
|
||||
return $this->response($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分销商关注商品分页列表
|
||||
*/
|
||||
public function page()
|
||||
{
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] < 0) return $this->response($token);
|
||||
|
||||
$page = $this->params['page'] ?? 1;
|
||||
$page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
|
||||
|
||||
// 获取当前用户的分销等级
|
||||
$fenxiao_model = new FenxiaoModel();
|
||||
$fenxiao_info = $fenxiao_model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id,level_id')[ 'data' ];
|
||||
|
||||
$fenxiao_level = new FenxiaoLevel();
|
||||
$level_info = $fenxiao_level->getLevelInfo([ [ 'level_id', '=', $fenxiao_info[ 'level_id' ] ] ], 'one_rate')[ 'data' ];
|
||||
|
||||
$condition = [
|
||||
[ 'g.is_fenxiao', '=', 1 ],
|
||||
[ 'g.site_id', '=', $this->site_id ],
|
||||
[ 'gs.goods_state', '=', 1 ],
|
||||
[ 'gs.is_delete', '=', 0 ],
|
||||
[ 'fgc.member_id', '=', $this->member_id ]
|
||||
];
|
||||
|
||||
$fenxiao_goods_collect_model = new FenxiaoGoodsCollectModel();
|
||||
$list = $fenxiao_goods_collect_model->getCollectPageList($condition, $page, $page_size);
|
||||
$fenxiao_goods_sku_model = new FenxiaoGoodsSku();
|
||||
|
||||
// 计算佣金比率
|
||||
foreach ($list[ 'data' ][ 'list' ] as $k => $v) {
|
||||
$discount_price = $v[ 'fenxiao_price' ] > 0 ? $v[ 'fenxiao_price' ] : $v[ 'discount_price' ];
|
||||
|
||||
$money = 0;
|
||||
if ($v[ 'fenxiao_type' ] == 1) {
|
||||
// 默认规则
|
||||
$money = number_format($discount_price * $level_info[ 'one_rate' ] / 100, 2, '.', '');
|
||||
} else {
|
||||
// 自定义规则
|
||||
$fenxiao_goods_sku_info = $fenxiao_goods_sku_model->getFenxiaoGoodsSkuInfo([ [ 'sku_id', '=', $v[ 'sku_id' ] ], [ 'level_id', '=', $fenxiao_info[ 'level_id' ] ] ], 'one_money,one_rate');
|
||||
if (!empty($fenxiao_goods_sku_info[ 'data' ])) {
|
||||
$fenxiao_goods_sku_info = $fenxiao_goods_sku_info[ 'data' ];
|
||||
$money = $fenxiao_goods_sku_info[ 'one_money' ];
|
||||
if ($fenxiao_goods_sku_info[ 'one_rate' ] > 0) {
|
||||
$money = number_format($discount_price * $fenxiao_goods_sku_info[ 'one_rate' ] / 100, 2, '.', '');
|
||||
}
|
||||
}
|
||||
}
|
||||
$list[ 'data' ][ 'list' ][ $k ][ 'commission_money' ] = $money;
|
||||
}
|
||||
|
||||
return $this->response($list);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
42
addon/fenxiao/api/controller/Level.php
Executable file
42
addon/fenxiao/api/controller/Level.php
Executable file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\fenxiao\api\controller;
|
||||
|
||||
use addon\fenxiao\model\FenxiaoLevel;
|
||||
use app\api\controller\BaseApi;
|
||||
|
||||
|
||||
/**
|
||||
* 分销等级
|
||||
*/
|
||||
class Level extends BaseApi
|
||||
{
|
||||
|
||||
/**
|
||||
* 分销商等级列表
|
||||
*/
|
||||
public function lists()
|
||||
{
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] < 0) return $this->response($token);
|
||||
|
||||
$condition = [
|
||||
[ 'status', '=', 1 ],
|
||||
[ 'site_id', '=', $this->site_id ],
|
||||
[ 'is_default', '=', 0 ]
|
||||
];
|
||||
$model = new FenxiaoLevel();
|
||||
$info = $model->getLevelList($condition, 'level_id,level_num,level_name,one_rate,two_rate,three_rate,upgrade_type,fenxiao_order_num,fenxiao_order_meney,one_fenxiao_order_num,one_fenxiao_order_money,order_num,order_money,child_num,child_fenxiao_num,one_child_num,one_child_fenxiao_num,one_fenxiao_total_order', 'level_num asc,one_rate asc');
|
||||
|
||||
return $this->response($info);
|
||||
}
|
||||
|
||||
}
|
||||
114
addon/fenxiao/api/controller/Order.php
Executable file
114
addon/fenxiao/api/controller/Order.php
Executable file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\fenxiao\api\controller;
|
||||
|
||||
use app\api\controller\BaseApi;
|
||||
use addon\fenxiao\model\FenxiaoOrder as FenxiaoOrderModel;
|
||||
use addon\fenxiao\model\Fenxiao;
|
||||
|
||||
/**
|
||||
* 分销订单
|
||||
*/
|
||||
class Order extends BaseApi
|
||||
{
|
||||
|
||||
/**
|
||||
* 信息
|
||||
* @return false|string
|
||||
*/
|
||||
public function info()
|
||||
{
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] < 0) return $this->response($token);
|
||||
|
||||
$model = new Fenxiao();
|
||||
$fenxiao_info = $model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id');
|
||||
if (empty($fenxiao_info[ 'data' ])) return $this->response($this->error('', 'MEMBER_NOT_IS_FENXIAO'));
|
||||
|
||||
$fenxiao_order_id = $this->params['fenxiao_order_id'] ?? 0;
|
||||
if (empty($fenxiao_order_id)) {
|
||||
return $this->response($this->error('', 'REQUEST_FENXIAO_ORDER_ID'));
|
||||
}
|
||||
$order_model = new FenxiaoOrderModel();
|
||||
$condition = [
|
||||
[ 'one_fenxiao_id|two_fenxiao_id|three_fenxiao_id', '=', $fenxiao_info[ 'data' ][ 'fenxiao_id' ] ],
|
||||
[ 'fenxiao_order_id', '=', $fenxiao_order_id ]
|
||||
];
|
||||
$res = $order_model->getFenxiaoOrderInfo($condition);
|
||||
if (!empty($res[ 'data' ])) {
|
||||
if ($res[ 'data' ][ 'one_fenxiao_id' ] == $fenxiao_info[ 'data' ][ 'fenxiao_id' ]) {
|
||||
$res[ 'data' ][ 'commission' ] = $res[ 'data' ][ 'one_commission' ];
|
||||
$res[ 'data' ][ 'commission_rate' ] = $res[ 'data' ][ 'one_rate' ];
|
||||
$res[ 'data' ][ 'commission_level' ] = 1;
|
||||
} elseif ($res[ 'data' ][ 'two_fenxiao_id' ] == $fenxiao_info[ 'data' ][ 'fenxiao_id' ]) {
|
||||
$res[ 'data' ][ 'commission' ] = $res[ 'data' ][ 'two_commission' ];
|
||||
$res[ 'data' ][ 'commission_rate' ] = $res[ 'data' ][ 'two_rate' ];
|
||||
$res[ 'data' ][ 'commission_level' ] = 2;
|
||||
} elseif ($res[ 'data' ][ 'three_fenxiao_id' ] == $fenxiao_info[ 'data' ][ 'fenxiao_id' ]) {
|
||||
$res[ 'data' ][ 'commission' ] = $res[ 'data' ][ 'three_commission' ];
|
||||
$res[ 'data' ][ 'commission_rate' ] = $res[ 'data' ][ 'three_rate' ];
|
||||
$res[ 'data' ][ 'commission_level' ] = 3;
|
||||
}
|
||||
$res[ 'data' ] = array_diff_key($res[ 'data' ], [ 'member_id' => '', 'member_name' => '', 'member_mobile' => '', 'full_address' => '', 'one_fenxiao_id' => '', 'one_rate' => '', 'one_commission' => '', 'one_fenxiao_name' => '', 'two_fenxiao_id' => '', 'two_rate' => '', 'two_commission' => '', 'two_fenxiao_name' => '', 'three_fenxiao_id' => '', 'three_rate' => '', 'three_commission' => '', 'three_fenxiao_name' => '' ]);
|
||||
}
|
||||
return $this->response($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
public function page()
|
||||
{
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] < 0) return $this->response($token);
|
||||
|
||||
$model = new Fenxiao();
|
||||
$fenxiao_info = $model->getFenxiaoInfo([ [ 'member_id', '=', $this->member_id ] ], 'fenxiao_id');
|
||||
if (empty($fenxiao_info[ 'data' ])) return $this->response($this->error('', 'MEMBER_NOT_IS_FENXIAO'));
|
||||
|
||||
$page = $this->params['page'] ?? 1;
|
||||
$page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
|
||||
$is_settlement = $this->params['is_settlement'] ?? 0;// 结算状态 0 全部 1 待结算 2 已结算 3 已退款
|
||||
|
||||
$condition = [
|
||||
[ 'fo.one_fenxiao_id|fo.two_fenxiao_id|fo.three_fenxiao_id', '=', $fenxiao_info[ 'data' ][ 'fenxiao_id' ] ]
|
||||
];
|
||||
if (!empty($is_settlement)) {
|
||||
if ($is_settlement == 3) {
|
||||
$condition[] = [ 'fo.is_refund', '=', 1 ];
|
||||
}
|
||||
if (in_array($is_settlement, [ 1, 2 ])) {
|
||||
$condition[] = [ 'fo.is_settlement', '=', $is_settlement - 1 ];
|
||||
$condition[] = [ 'fo.is_refund', '=', 0 ];
|
||||
}
|
||||
}
|
||||
|
||||
$order_model = new FenxiaoOrderModel();
|
||||
$list = $order_model->getFenxiaoOrderPageList($condition, $page, $page_size, 'fo.fenxiao_order_id desc');
|
||||
if (!empty($list[ 'data' ][ 'list' ])) {
|
||||
foreach ($list[ 'data' ][ 'list' ] as $k => $item) {
|
||||
if ($item[ 'one_fenxiao_id' ] == $fenxiao_info[ 'data' ][ 'fenxiao_id' ]) {
|
||||
$list[ 'data' ][ 'list' ][ $k ][ 'commission' ] = $item[ 'one_commission' ];
|
||||
$list[ 'data' ][ 'list' ][ $k ][ 'commission_level' ] = 1;
|
||||
} elseif ($item[ 'two_fenxiao_id' ] == $fenxiao_info[ 'data' ][ 'fenxiao_id' ]) {
|
||||
$list[ 'data' ][ 'list' ][ $k ][ 'commission' ] = $item[ 'two_commission' ];
|
||||
$list[ 'data' ][ 'list' ][ $k ][ 'commission_level' ] = 2;
|
||||
} elseif ($item[ 'three_fenxiao_id' ] == $fenxiao_info[ 'data' ][ 'fenxiao_id' ]) {
|
||||
$list[ 'data' ][ 'list' ][ $k ][ 'commission' ] = $item[ 'three_commission' ];
|
||||
$list[ 'data' ][ 'list' ][ $k ][ 'commission_level' ] = 3;
|
||||
}
|
||||
$list[ 'data' ][ 'list' ][ $k ] = array_diff_key($list[ 'data' ][ 'list' ][ $k ], [ 'one_fenxiao_id' => '', 'one_rate' => '', 'one_commission' => '', 'one_fenxiao_name' => '', 'two_fenxiao_id' => '', 'two_rate' => '', 'two_commission' => '', 'two_fenxiao_name' => '', 'three_fenxiao_id' => '', 'three_rate' => '', 'three_commission' => '', 'three_fenxiao_name' => '' ]);
|
||||
}
|
||||
}
|
||||
return $this->response($list);
|
||||
}
|
||||
|
||||
}
|
||||
122
addon/fenxiao/api/controller/Withdraw.php
Executable file
122
addon/fenxiao/api/controller/Withdraw.php
Executable file
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace addon\fenxiao\api\controller;
|
||||
|
||||
use addon\fenxiao\model\FenxiaoWithdraw;
|
||||
use app\api\controller\BaseApi;
|
||||
use app\model\member\Member;
|
||||
|
||||
/**
|
||||
* 分销提现
|
||||
*/
|
||||
class Withdraw extends BaseApi
|
||||
{
|
||||
|
||||
/**
|
||||
* 提现记录分页
|
||||
* @return false|string
|
||||
*/
|
||||
public function page()
|
||||
{
|
||||
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] < 0) return $this->response($token);
|
||||
|
||||
$page = $this->params['page'] ?? 1;
|
||||
$page_size = $this->params['page_size'] ?? PAGE_LIST_ROWS;
|
||||
$status = $this->params['status'] ?? 0;// 当前状态 1待审核 2待转账 3已转账 -1 已拒绝
|
||||
|
||||
$condition = [
|
||||
[ 'member_id', '=', $this->member_id ]
|
||||
];
|
||||
if (!empty($status)) {
|
||||
$condition[] = [ 'status', '=', $status ];
|
||||
}
|
||||
|
||||
$order = 'id desc';
|
||||
$withdraw_model = new FenxiaoWithdraw();
|
||||
$list = $withdraw_model->getFenxiaoWithdrawPageList($condition, $page, $page_size, $order);
|
||||
foreach ($list[ 'data' ][ 'list' ] as $k => $v) {
|
||||
$list[ 'data' ][ 'list' ][ $k ] = $withdraw_model->tran($v);
|
||||
}
|
||||
return $this->response($list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取转账方式
|
||||
* @return false|string
|
||||
*/
|
||||
public function transferType()
|
||||
{
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] < 0) return $this->response($token);
|
||||
|
||||
$member_model = new Member();
|
||||
$member_info = $member_model->getMemberInfo([ [ 'member_id', '=', $token[ 'data' ][ 'member_id' ] ] ], 'site_id,wx_openid,weapp_openid');
|
||||
$withdraw_config_model = new \addon\fenxiao\model\Config();
|
||||
$transfer_type_list = $withdraw_config_model->getTransferType($member_info[ 'data' ][ 'site_id' ]);
|
||||
if (empty($member_info[ 'data' ][ 'wx_openid' ]) && empty($member_info[ 'data' ][ 'weapp_openid' ])) {
|
||||
unset($transfer_type_list[ 'wechatpay' ]);
|
||||
}
|
||||
return $this->response($this->success($transfer_type_list));
|
||||
}
|
||||
|
||||
/**
|
||||
* 申请提现
|
||||
* @return mixed
|
||||
*/
|
||||
public function apply()
|
||||
{
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] < 0) return $this->response($token);
|
||||
|
||||
$apply_money = $this->params[ 'apply_money' ] ?? 0;
|
||||
$transfer_type = $this->params[ 'transfer_type' ] ?? '';//提现方式
|
||||
$realname = $this->params[ 'realname' ] ?? '';//真实姓名
|
||||
$bank_name = $this->params[ 'bank_name' ] ?? '';//银行名称
|
||||
$account_number = $this->params[ 'account_number' ] ?? '';//账号名称
|
||||
$mobile = $this->params[ 'mobile' ] ?? '';//手机号
|
||||
$app_type = $this->params[ 'app_type' ];
|
||||
$fenxiao_withdraw_model = new FenxiaoWithdraw();
|
||||
$data = array (
|
||||
'member_id' => $this->member_id,
|
||||
'transfer_type' => $transfer_type,
|
||||
'realname' => $realname,
|
||||
'bank_name' => $bank_name,
|
||||
'account_number' => $account_number,
|
||||
'apply_money' => $apply_money,
|
||||
'mobile' => $mobile,
|
||||
'app_type' => $app_type
|
||||
);
|
||||
$result = $fenxiao_withdraw_model->apply($data, $this->site_id);
|
||||
return $this->response($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提现详情
|
||||
* @return mixed
|
||||
*/
|
||||
public function detail()
|
||||
{
|
||||
$token = $this->checkToken();
|
||||
if ($token[ 'code' ] < 0) return $this->response($token);
|
||||
|
||||
$id = $this->params[ 'id' ] ?? 0;
|
||||
$fenxiao_withdraw_model = new FenxiaoWithdraw();
|
||||
$params = array (
|
||||
'id' => $id,
|
||||
'site_id' => $this->site_id
|
||||
);
|
||||
$result = $fenxiao_withdraw_model->getFenxiaoWithdrawDetail($params);
|
||||
return $this->response($result);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user