232 lines
9.5 KiB
PHP
232 lines
9.5 KiB
PHP
<?php
|
|
defined('WXAPP_ITEMS') OR exit('No direct script access allowed');
|
|
ini_set('display_errors', 'On');
|
|
error_reporting(E_ERROR);
|
|
|
|
require_once APPPATH . 'controllers/wxapp/Wxapp.php';
|
|
|
|
/**
|
|
* Notes:分销首页
|
|
* Created on: 2020/6/29 15:16
|
|
* Created by: dengbw
|
|
*/
|
|
class Home extends Wxapp
|
|
{
|
|
private $uid;
|
|
|
|
function __construct($inputs, $app_key)
|
|
{
|
|
parent::__construct($inputs, $app_key);
|
|
$this->login_white = '';//
|
|
$this->check_status = array();//用户状态校验
|
|
$this->check_mobile = array();//需要手机号
|
|
$this->check_headimg = array();//授权微信信息
|
|
$this->majia_white = array('get');//超级管理员披上马甲可操作权限
|
|
|
|
$this->uid = $this->session['uid'];
|
|
$this->load->model('app/User_account_model', 'mdUserAccount');
|
|
}
|
|
|
|
/**
|
|
* Notes:分销首页
|
|
* Created on: 2020/6/30 11:47
|
|
* Created by: dengbw
|
|
* @return array
|
|
* @throws Exception
|
|
*/
|
|
protected function get()
|
|
{
|
|
$money_total = $money_left = $money_freeze = '0.00';
|
|
$re = $this->mdUserAccount->get(array('app_id' => $this->app_id, 'app_uid' => $this->uid, 'status' => 1));
|
|
if ($re) {
|
|
$money_total = $re['money_total'];
|
|
$money_left = $re['money_left'];
|
|
}
|
|
$img_url = $this->mdUserAccount->config()[$this->app_id]['deal']['img_url'];
|
|
$bg_color = $this->mdUserAccount->config()[$this->app_id]['deal']['bg_color'];
|
|
$reU = $this->app_user_model->get(array('id' => $this->uid));
|
|
|
|
$shareTitle = $shareImg = $team_title = $team_url = $team_invite = '';
|
|
if ($reU['up_uid'] == 0) {
|
|
$shareTitle = '邀请您一起参与' . $this->cf_title . '分销';
|
|
$shareImg = $img_url . '/distribute/share-tip.jpg';
|
|
$team_title = '我的团队';
|
|
$team_url = '/pages/distribute/team/index?type=1';
|
|
$team_invite = '邀请团员';
|
|
} else {
|
|
if ($this->app_config('lock_fans') == 1) {//锁粉才有粉丝
|
|
$team_title = '我的粉丝';
|
|
$team_url = '/pages/distribute/fans/index';
|
|
}
|
|
}
|
|
if($this->session['dealer']){
|
|
//$menulist[] = ['title' => '推广素材', 'url' => '/pages/distribute/material/index', 'img' => $img_url . '/distribute/icon-sucai.png'];
|
|
$menulist[] = ['title' => '推广数据', 'url' => '/pages/distribute/statistics/index', 'img' => $img_url . '/distribute/icon-shuju.png'];
|
|
$menulist[] = ['title' => '佣金明细', 'url' => '/pages/distribute/reward/index', 'img' => $img_url . '/distribute/icon-yongjin.png'];
|
|
!$this->session['up_uid'] && $this->session['dealer'] && $menulist[] = ['title' => '我的团队', 'url' => '/pages/distribute/team/index', 'img' => $img_url . '/distribute/icon-tuandui.png'];
|
|
}
|
|
$this->session['manage'] && $menulist[] = ['title' => '分销管理', 'url' => '/pages/distribute/apply/index', 'img' => $img_url . '/distribute/icon-shenqing.png'];
|
|
//$menulist[] = ['title' => '报备线索', 'url' => '/pages/distribute/clue/index', 'img' => $img_url . '/distribute/icon-sucai.png'];
|
|
$menulist[] = ['title' => '联系小狸', 'url' => '', 'img' => $img_url . '/distribute/icon-kefu.png'];
|
|
$data = array(
|
|
"title" => '分销',
|
|
"bg" => array('color' => $bg_color, 'img' => $img_url . '/distribute/index-banner.png'),
|
|
"income" => array('title' => '总收入', 'value' => $money_total),
|
|
"cashout" => array('title' => '可提现金额', 'value' => $money_left, 'url' => '/pages/distribute/cashout/index'),
|
|
"rule" => array('title' => '佣金规则', 'value' => $this->mdUserAccount->config()[$this->app_id]['deal']['rule']),
|
|
"btn" => array('title' => $team_invite, 'shareTitle' => $shareTitle, 'shareImg' => $shareImg),
|
|
"menulist" => $menulist
|
|
);
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* Notes:帐户信息
|
|
* Created on: 2020/7/3 17:11
|
|
* Created by: dengbw
|
|
* @return array
|
|
*/
|
|
protected function get_info()
|
|
{
|
|
$dealer = $up_uid = 0;
|
|
$money_total = $money_left = $money_freeze = 0.00;
|
|
$team_nums = 0;
|
|
$reU = $this->app_user_model->get(array('id' => $this->uid));
|
|
if ($reU['dealer'] == 1) {
|
|
$dealer = $reU['dealer'];
|
|
$up_uid = $reU['up_uid'];
|
|
$reUa = $this->mdUserAccount->get(array('app_id' => $this->app_id, 'app_uid' => $this->uid)
|
|
, 'id,money_total,money_freeze,money_left');
|
|
if ($reUa['id']) {
|
|
$money_total = $reUa['money_total'];
|
|
$money_freeze = $reUa['money_freeze'];
|
|
$money_left = $reUa['money_left'];
|
|
if ($up_uid == 0) {
|
|
$team_nums = $this->app_user_model->count(array('dealer' => 1, 'up_uid' => $up_uid));
|
|
}
|
|
} else {
|
|
//添加资金账户
|
|
$addData = array('app_id' => $this->app_id, 'app_uid' => $this->uid, 'status' => 1, 'c_time' => time());
|
|
$this->mdUserAccount->add($addData);
|
|
}
|
|
}
|
|
$data = array(
|
|
"dealer" => $dealer,
|
|
"up_uid" => $up_uid,
|
|
"team_nums" => $team_nums,
|
|
"money_total" => $money_total,
|
|
"money_freeze" => $money_freeze,
|
|
"money_left" => $money_left,
|
|
);
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* Notes:收到团队邀请
|
|
* Created on: 2020/7/2 15:27
|
|
* Created by: dengbw
|
|
* @return array
|
|
* @throws Hd_exception
|
|
*/
|
|
protected function get_invite()
|
|
{
|
|
$up_uid = $this->input_param('up_uid');
|
|
if (!$up_uid) {
|
|
throw new Hd_exception('请求超时', API_CODE_INVILD_PARAM);
|
|
}
|
|
if ($up_uid == $this->uid) {
|
|
return array("show" => 0);
|
|
}
|
|
$re = $this->app_user_model->get(array('id' => $this->uid), 'nickname,dealer,up_uid');
|
|
if ($re['dealer'] == 1) {
|
|
return array("show" => 0);
|
|
}
|
|
$re_up = $this->app_user_model->get(array('id' => $up_uid), 'nickname,dealer,up_uid');
|
|
if (!$re_up) {
|
|
throw new Hd_exception('无此分销用户', API_CODE_FAIL);
|
|
}
|
|
if ($re_up['dealer'] != 1) {
|
|
throw new Hd_exception('无邀请权限', API_CODE_FAIL);
|
|
}
|
|
|
|
$invite_name = $re_up['nickname'];
|
|
if ($re_up['up_uid'] == 0) { //一级分销邀请的团员
|
|
$title = '一起来赚钱吧~';
|
|
} else {//团员邀请的粉丝
|
|
$title = $re['up_uid'] ? '更换为' . $re_up['nickname'] . '的粉丝' : '加入' . $re_up['nickname'] . '的粉丝';
|
|
}
|
|
$data = array(
|
|
"show" => 1,
|
|
'title' => $title,
|
|
'content' => $invite_name . '邀请您一起参与' . $this->cf_title . '分销'
|
|
);
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* Notes:加入分销团队
|
|
* Created on: 2020/6/30 9:25
|
|
* Created by: dengbw
|
|
* @return array
|
|
* @throws Hd_exception
|
|
*/
|
|
protected function put_invite()
|
|
{
|
|
$up_uid = $this->input_param('up_uid');
|
|
if (!$up_uid) {
|
|
throw new Hd_exception('请求超时', API_CODE_INVILD_PARAM);
|
|
}
|
|
if ($up_uid == $this->uid) {
|
|
throw new Hd_exception('不能自己邀请自己', API_CODE_FAIL);
|
|
}
|
|
$re = $this->app_user_model->get(array('id' => $this->uid), 'nickname,dealer');
|
|
if ($re['dealer'] == 1) {
|
|
throw new Hd_exception('您已是分销人员', API_CODE_FAIL);
|
|
}
|
|
$re_up = $this->app_user_model->get(array('id' => $up_uid), 'nickname,dealer,up_uid');
|
|
if (!$re_up) {
|
|
throw new Hd_exception('无此分销用户', API_CODE_INVILD_PARAM);
|
|
}
|
|
if ($re_up['dealer'] != 1) {
|
|
throw new Hd_exception('无邀请权限', API_CODE_FAIL);
|
|
}
|
|
$reUa = $this->mdUserAccount->get(array('app_id' => $this->app_id, 'app_uid' => $this->uid), 'id');
|
|
if (!$reUa['id']) {//添加资金账户
|
|
$addData = array('app_id' => $this->app_id, 'app_uid' => $this->uid, 'status' => 1, 'c_time' => time());
|
|
$this->mdUserAccount->add($addData);
|
|
}
|
|
//更新上级uid
|
|
if ($re_up['dealer'] == 1 && $re_up['up_uid'] == 0) {//一级分销邀请的团员
|
|
$upd = array('up_uid' => $up_uid, 'dealer' => 1);
|
|
$this->app_user_model->update($upd, array('id' => $this->uid));
|
|
} else {//团员邀请的粉丝
|
|
$this->app_user_model->update(array('up_uid' => $up_uid), array('id' => $this->uid));
|
|
}
|
|
throw new Hd_exception('加入成功', API_CODE_SUCCESS);
|
|
}
|
|
|
|
/**
|
|
* Notes:加入粉丝
|
|
* Created on: 2020/7/7 15:18
|
|
* Created by: dengbw
|
|
*/
|
|
protected function put_fans()
|
|
{
|
|
if (!$this->app_config('lock_fans')) {
|
|
throw new Hd_exception('未开启锁粉', API_CODE_SUCCESS);
|
|
}
|
|
$up_uid = $this->input_param('up_uid');
|
|
$re = $this->app_user_model->get(array('id' => $this->uid), 'dealer,up_uid');
|
|
if ($re['dealer'] == 1 || $re['up_uid']) {
|
|
throw new Hd_exception('已是粉丝', API_CODE_SUCCESS);
|
|
}
|
|
$re_up = $this->app_user_model->get(array('id' => $up_uid), 'dealer,up_uid');
|
|
if (!$re_up || $re_up['dealer'] != 1) {
|
|
throw new Hd_exception('无邀请权限', API_CODE_SUCCESS);
|
|
}
|
|
$this->app_user_model->update(array('up_uid' => $up_uid), array('id' => $this->uid));
|
|
throw new Hd_exception('加入成功', API_CODE_SUCCESS);
|
|
}
|
|
|
|
}
|