add-api-distribution

This commit is contained in:
lccsw
2021-08-03 19:13:06 +08:00
parent 8e1d8059f2
commit 19bcd3a433
20 changed files with 1923 additions and 9 deletions
+13 -3
View File
@@ -60,7 +60,18 @@ class Main extends HD_Controller
'value' => $value,
'btns' => array(
array('name' => '查看详情', 'url' => '/topics/topics?app_id=' . $this->app_id),
//array('name' => '查看详情', 'url' => '/sys/company?app_id=' . $this->app_id),
),
);
$conditions[] = array('icon' => 'am-icon-home', 'list' => $list);
/*小程序设置 end*/
$list = [];
$list[] = array(
'title' => '分销用户(人)',
'value' => 0,
'btns' => array(
array('name' => '查看详情', 'url' => '/appdistribution/distribution?app_id='.$this->app_id),
),
);
@@ -74,13 +85,12 @@ class Main extends HD_Controller
array('name' => '查看详情', 'url' => '/order/purchase?app_id=' . $this->app_id),
),
);
$conditions[] = array('icon' => 'am-icon-home', 'list' => $list);
/*小程序设置 end*/
/*实时数据 end*/
$this->data['conditions'] = $conditions;
$conditions[] = array('icon' => 'am-icon-home', 'list' => $list);
$this->data['_title'] = '狸车';
return $this->show_view('/app/main', true);
+2 -2
View File
@@ -110,11 +110,11 @@ class Member extends HD_Controller{
public function edit()
{
$id = $this->input->post('id');
$ifdist = $this->input->post('ifdist');
$dealer = $this->input->post('dealer');
$upd = [
'ifdist' => $ifdist,
'dealer' => $dealer,
];
$this->userM->update($upd, array('id' => $id));
+410
View File
@@ -0,0 +1,410 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require_once(dirname(__DIR__) . '/AppBase.php');
/**
* Notes:分销管理
* Created on: 2020/7/15 15:26
* Created by: dengbw
*/
class Distribution extends AppBase
{
private $statisticalAry = array();
public function __construct()
{
parent::__construct();
$this->load->model('app/User_account_model', 'mdUserAccount');
$this->load->model('app/User_accountlog_model', 'mdUserAccountLog');
$this->load->model('app/Deal_log_model', 'mdDealLog');
if ($this->app_id) {
$this->load->model($this->mdApp->appConfig()[$this->app_id]['model'], 'mdAppUser');
if ($this->app_info()['lock_fans'] == 1) {
$this->statisticalAry = array(1 => '团队', 2 => '粉丝');
} else {
$this->statisticalAry = array(1 => '团队');
}
}
}
//首页信息
public function index()
{
$this->lists();
}
//数据列表
public function lists()
{
$params = $this->input->get();
$params['page'] = $params['page'] ? intval($params['page']) : 1;
$params['size'] = $params['size'] ? intval($params['size']) : 10;
$params['statistical'] = $params['statistical'] ? intval($params['statistical']) : 1;
$res = $this->teamSelect($params);
$lists = $res['lists'];
$count = $res['count'];
$this->data['params'] = $res['params'];
$this->data['_title'] = '分销用户列表';
$this->data['pager'] = array('count' => ceil($count / $params['size']), 'curr' => $params['page'], 'totle' => $count);
$this->data['statistical_ary'] = $this->statisticalAry;
$this->data['statistical_name'] = $this->statisticalAry[$params['statistical']];
$this->data['lists'] = $lists;
return $this->show_view('appdistribution/team/lists', true);
}
/**
* Notes:分销用户
* Created on: 2020/7/15 10:45
* Created by: dengbw
* @param $params
* @return mixed
*/
private function teamSelect($params)
{
$lists = array();
$count = 0;
$where = array('dealer' => 1, 'up_uid' => 0);
if ($params['nickname']) {
$where['nickname LIKE "%' . trim($params['nickname']) . '%"'] = NULL;
}
if ($params['mobile']) {
$where['mobile LIKE "%' . trim($params['mobile']) . '%"'] = NULL;
}
$res = $this->mdAppUser->select($where, "id desc", $params['page'], $params['size'], 'id,mobile,nickname');
if ($res) {
if (!$params['export']) {
$count = $this->mdAppUser->count($where);
}
foreach ($res as $key => $value) {
$setValue = array();
$setValue['id'] = $value['id'];
$setValue['mobile'] = $value['mobile'];
$setValue['nickname'] = $value['nickname'];
if ($params['statistical'] == 1) {
$setValue['nums'] = $this->mdAppUser->count(array('dealer' => 1, 'up_uid' => $value['id'])) + 1;
$orders = $this->mdDealLog->count(array('app_id' => $this->app_id, 'app_uid' => $value['id']));
$orders_suc = $this->mdDealLog->count(array('app_id' => $this->app_id, 'app_uid' => $value['id'], 'status' => 1));
$orders_suc > $orders && $orders = $orders_suc;
$setValue['orders'] = $orders;
$setValue['orders_suc'] = $orders_suc;
$sum = $this->mdDealLog->sum('money', array('app_id' => $this->app_id, 'app_uid' => $value['id'], 'status' => 1));
$setValue['money'] = number_format_com($sum['money']);
} else if ($params['statistical'] == 2) {
$setValue['nums'] = $this->mdAppUser->count(array('dealer' => 0, 'up_uid' => $value['id']));
$orders = $this->mdDealLog->count(array('app_id' => $this->app_id, 'app_uid' => $value['id'], 'type' => 2));
$orders_suc = $this->mdDealLog->count(array('app_id' => $this->app_id, 'app_uid' => $value['id'], 'type' => 2, 'status' => 1));
$orders_suc > $orders && $orders = $orders_suc;
$setValue['orders'] = $orders;
$setValue['orders_suc'] = $orders_suc;
$sum = $this->mdDealLog->sum('money', array('app_id' => $this->app_id, 'app_uid' => $value['id'], 'type' => 2, 'status' => 1));
$setValue['money'] = number_format_com($sum['money']);
}
$lists[] = $setValue;
}
}
$data['lists'] = $lists;
$data['count'] = $count;
$data['params'] = $params;
return $data;
}
/**
* Notes:分销团队
* Created on: 2020/7/20 17:48
* Created by: dengbw
* @return bool
* @throws Hd_exception
*/
public function get_team()
{
$params = $this->input->get();
$params['page'] = $params['page'] ? intval($params['page']) : 1;
$params['size'] = $params['size'] ? intval($params['size']) : 10;
$up_uid = $params['up_uid'];
$this->app_id = $params['app_id'];
if (!$up_uid || !$this->app_id) {
return $this->show_json(SYS_CODE_FAIL, '参数错误');
}
$reU = $this->mdAppUser->get(array('id' => $up_uid));
if ($reU['dealer'] != 1 || $reU['up_uid'] != 0) {
throw new Hd_exception('不是团长', API_CODE_FAIL);
}
$this->load->model($this->mdApp->appConfig()[$this->app_id]['model'], 'mdAppUser');
$lists = $where = array();
$_title = $reU['nickname'] ? '【' . $reU['nickname'] . '】分销团队' : '分销团队';
$where_base = array('app_id' => $this->app_id, 'app_uid' => $up_uid);
if (!$params['time']) {
$params['time'] = date('Y-m-d') . ' ~ ' . date('Y-m-d');
}
if ($params['time']) {
$time = explode(' ~ ', $params['time']);
$time[0] && $where_base["c_time >="] = strtotime($time[0] . ' 00:00:00');
$time[1] && $where_base["c_time <="] = strtotime($time[1] . ' 23:59:59');
$params['time_str'] = str_replace(" ~ ", "", $params['time']);
}
if ($params['statistical'] == 1) {//团员
$where = array('dealer' => 1, 'up_uid' => $up_uid);
if ($params['page'] == 1) {
$where1 = $where2 = $where_base;
$where1['type in(0,2)'] = null;
$where2['type in(0,2)'] = null;
$where2['status'] = 1;
$myValue['id'] = $up_uid;
$myValue['type'] = 0;
$myValue['mobile'] = $reU['mobile'];
$myValue['nickname'] = $reU['nickname'] . '<span style="color: red;">(团长)</span>';
$myValue['orders'] = $this->mdDealLog->count($where1);
$myValue['orders_suc'] = $this->mdDealLog->count($where2);
$mySum = $this->mdDealLog->sum('money', $where2);
$myValue['bring_money'] = number_format_com($mySum['money']);
$lists[] = $myValue;
}
} else if ($params['statistical'] == 2) {//粉丝
$where = array('dealer' => 0, 'up_uid' => $up_uid);
}
$resU = $this->mdAppUser->select($where, 'id DESC', $params['page'], $params['size'], 'id,nickname,mobile');
$count = $this->mdAppUser->count($where);
$params['statistical'] == 1 && $count += 1;
if ($count) {
foreach ($resU as $key => $value) {
$setValue = array();
$setValue['id'] = $value['id'];
$setValue['type'] = 1;
$setValue['mobile'] = $value['mobile'];
$setValue['nickname'] = $value['nickname'] ? $value['nickname'] : '神秘用户';
if ($params['statistical'] == 1) {
$where1 = $where2 = $where_base;
$where1['t_uid'] = $value['id'];
$where1['type in(1,3)'] = null;
$where2['t_uid'] = $value['id'];
$where2['type in(1,3)'] = null;
$where2['status'] = 1;
$orders = $this->mdDealLog->count($where1);
$orders_suc = $this->mdDealLog->count($where2);
$orders_suc > $orders && $orders = $orders_suc;
$setValue['orders'] = $orders;
$setValue['orders_suc'] = $orders_suc;
$sum = $this->mdDealLog->sum('money', $where2);
$setValue['bring_money'] = number_format_com($sum['money']);
} else if ($params['statistical'] == 2) {
$where1 = $where_base;
$where1['t_uid'] = $value['id'];
$where1['type'] = 2;
$where1['status'] = 1;
$setValue['orders'] = $this->mdDealLog->count($where1);
$sum = $this->mdDealLog->sum('money', $where1);
$setValue['bring_money'] = number_format_com($sum['money']);
}
$lists[] = $setValue;
}
}
$this->data['team_orders'] = $this->mdDealLog->count($where_base);
$where3 = $where_base;
$where3['status'] = 1;
$this->data['team_orders_suc'] = $this->mdDealLog->count($where3);
$sum = $this->mdDealLog->sum('money', $where3);
$this->data['team_money'] = number_format_com($sum['money']);
$this->data['_title'] = $_title;
$this->data['lists'] = $lists;
$this->data['params'] = $params;
$this->data['pager'] = array('count' => ceil($count / $params['size']), 'curr' => $params['page'], 'totle' => $count);
return $this->show_view('appdistribution/team/get_team', true);
}
/**
* Notes:佣金明细
* Created on: 2020/7/20 17:48
* Created by: dengbw
* @return bool
*/
public function get_commission()
{
$params = $this->input->get();
$params['page'] = $params['page'] ? intval($params['page']) : 1;
$params['size'] = $params['size'] ? intval($params['size']) : 20;
$status = $params['status'];
$app_uid = $params['app_uid'];
$this->app_id = $params['app_id'];
if (!$app_uid || !$this->app_id) {
return $this->show_json(SYS_CODE_FAIL, '参数错误');
}
$this->load->model($this->mdApp->appConfig()[$this->app_id]['model'], 'mdAppUser');
//$this->load->model('apporder/order_purchase_model', 'mdOrderPurchase');
//$this->load->model('appitem/items_model', 'mdItems');
$lists = array();
$statusAry = array(0 => '进行中', 1 => '已完成', -1 => '已失效');
$reU = $this->mdAppUser->get(array('id' => $app_uid));
$_title = $reU['nickname'] ? '【' . $reU['nickname'] . '】佣金明细' : '佣金明细';
$where['app_id'] = $this->app_id;
$where['app_uid'] = $app_uid;
if (status_verify($status)) {
$where['status'] = $status;
}
if ($params['time']) {
$time = explode(' ~ ', $params['time']);
$time[0] && $where["c_time >="] = strtotime($time[0] . ' 00:00:00');
$time[1] && $where["c_time <="] = strtotime($time[1] . ' 23:59:59');
}
$count = $this->mdDealLog->count($where);
if ($count) {
$res = $this->mdDealLog->select($where, 'id DESC', $params['page'], $params['size'], 'cf_sid,type,status,money,c_time');
foreach ($res as $key => $value) {
$setValue = array();
$reOp = $this->mdOrderPurchase->get(array('sid' => $value['cf_sid']), 'item_id,item_title,item_num
,total_price,sku_id,app_uid');
$source = $item_title = '';
$item_num = 0;
$total_price = $expect_money = 0.00;
if ($reOp) {
$item_title = $reOp['item_title'];
$item_num = $reOp['item_num'];
$total_price = $reOp['total_price'];
if ($value['type'] == 0) {//自己购买
$source .= '自己购买';
} else if ($value['type'] == 1) {//团员购买
$reU = $this->mdAppUser->get(array('id' => $reOp['app_uid']), 'nickname');
$source .= '团员 ' . $reU['nickname'];
} else if ($value['type'] == 2) {//粉丝购买
$reU = $this->mdAppUser->get(array('id' => $reOp['app_uid']), 'nickname');
$source .= '粉丝 ' . $reU['nickname'];
} else if ($value['type'] == 3) {//团员粉丝购买
$reU = $this->mdAppUser->get(array('id' => $reOp['app_uid']), 'nickname,up_uid');
if ($this->app_info()['lock_fans'] == 1) {
$reU2 = $this->mdAppUser->get(array('id' => $reU['up_uid']), 'nickname');
} else {
$reU2 = $this->mdAppUser->get(array('id' => $value['t_uid']), 'nickname');
}
$nickname = $reU['nickname'] ? $reU['nickname'] : '神秘人';
$nickname2 = $reU2['nickname'] ? $reU2['nickname'] : '神秘人';
if ($reU2) {
$source .= '团粉 ' . $nickname2 . '>>' . $nickname;
} else {
$source .= '团粉 ' . $nickname;
}
}
}
$setValue['source'] = $source;
$setValue['status'] = $value['status'];
$setValue['status_name'] = $statusAry[$value['status']];
$setValue['expect_money'] = $value['money'];
$setValue['item_title'] = $item_title;
$setValue['item_num'] = $item_num;
$setValue['total_price'] = number_format_com($total_price);
$setValue['c_time'] = date('Y-m-d H:i:s', $value['c_time']);
$lists[] = $setValue;
}
}
$this->data['_title'] = $_title;
$this->data['lists'] = $lists;
$this->data['params'] = $params;
$this->data['statusAry'] = $statusAry;
$this->data['pager'] = array('count' => ceil($count / $params['size']), 'curr' => $params['page'], 'totle' => $count);
return $this->show_view('appdistribution/team/get_commission', true);
}
/**
* Notes:账户资金流水
* Created on: 2020/7/20 17:51
* Created by: dengbw
* @return bool
*/
public function get_accountlog()
{
$trade_type_ary = array(1 => '入账', 2 => '提现', 3 => '冲正');
$params = $this->input->get();
$params['page'] = $params['page'] ? intval($params['page']) : 1;
$params['size'] = $params['size'] ? intval($params['size']) : 20;
$this->app_id = $params['app_id'];
$app_uid = $params['app_uid'];
if (!$app_uid || !$this->app_id) {
return $this->show_json(SYS_CODE_FAIL, '参数错误');
}
$this->load->model($this->mdApp->appConfig()[$this->app_id]['model'], 'mdAppUser');
$reAc = $this->mdUserAccount->get(array('app_id' => $this->app_id, 'app_uid' => $app_uid));
$account_id = $reAc['id'];
if (!$account_id) {
return $this->show_json(SYS_CODE_FAIL, '无此用户');
}
$reU = $this->mdAppUser->get(array('id' => $app_uid));
$_title = $reU['nickname'] ? '【' . $reU['nickname'] . '】资金流水' : '资金流水';
$where['account_id'] = $account_id;
if ($params['trade_type']) {
$where['trade_type'] = $params['trade_type'];
}
if ($params['time']) {
$time = explode(' ~ ', $params['time']);
$time[0] && $where["c_time >="] = strtotime($time[0] . ' 00:00:00');
$time[1] && $where["c_time <="] = strtotime($time[1] . ' 23:59:59');
}
$where2 = $where3 = $where;
$where2['trade_type'] = 1;
$sum2 = $this->mdUserAccountLog->sum('money_in', $where2);
$this->data['money_in'] = number_format_com($sum2['money_in']);
$where3['trade_type'] = 2;
$sum3 = $this->mdUserAccountLog->sum('money_out', $where3);
$this->data['money_out'] = number_format_com($sum3['money_out']);
$lists = array();
$count = $this->mdUserAccountLog->count($where);
if ($count) {
$res = $this->mdUserAccountLog->select($where, 'id DESC', $params['page'], $params['size'], '');
foreach ($res as $key => $value) {
$setValue = array();
$setValue['c_time'] = date('Y-m-d H:i:s', $value['c_time']);
$setValue['sid'] = $value['sid'] ? $value['sid'] : '-';
$setValue['trade_type_name'] = $trade_type_ary[$value['trade_type']];
$setValue['money_in'] = number_format_com($value['money_in']);
$setValue['money_out'] = number_format_com($value['money_out']);
$setValue['money_left'] = number_format_com($value['money_left']);
$lists[] = $setValue;
}
}
$this->data['_title'] = $_title;
$this->data['lists'] = $lists;
$this->data['params'] = $params;
$this->data['trade_type_ary'] = $trade_type_ary;
$this->data['pager'] = array('count' => ceil($count / $params['size']), 'curr' => $params['page'], 'totle' => $count);
return $this->show_view('appdistribution/team/get_accountlog', true);
}
//设为分销/取消分销
public function edit_team_dealer()
{
$id = $this->input->post('id');
$dealer = $this->input->post('dealer');
$this->mdAppUser->update(array('dealer' => $dealer, 'up_uid' => 0), array('id' => $id));
return $this->show_json(SYS_CODE_SUCCESS, '修改成功!');
}
//展示单条数据
public function get()
{
}
//添加单条数据
public function add()
{
}
//编辑单条数据
public function edit()
{
}
//删除单条数据
public function del()
{
}
//批量操作(默认修改状态)
public function batch()
{
}
//导出数据列表
public function export()
{
}
}
+2 -2
View File
@@ -37,7 +37,7 @@
<td><?= $v['nickname'] ?></td>
<td><?= $v['mobile'] ?></td>
<td>
<input type="checkbox" class="mui-switch mui-switch-anim va-mid" true-value="1" false-value="0" <?=$v['ifdist']?'checked':''?> onchange="set_publish(this,<?=$v['id']?>)"/>
<input type="checkbox" class="mui-switch mui-switch-anim va-mid" true-value="1" false-value="0" <?=$v['dealer']?'checked':''?> onchange="set_publish(this,<?=$v['id']?>)"/>
</td>
<td><?= date('Y-m-d H:i:s',$v['c_time']) ?></td>
</tr>
@@ -66,7 +66,7 @@ function set_publish(obj,id){
}else{
value = 0;
}
var data = {'id':id,'ifdist':value};
var data = {'id':id,'dealer':value};
$.post('/app/liche/member/edit',data,function(result){
if(result.code){
layer.msg(result.msg, {time: 2000,icon:1 }, function () {
+124
View File
@@ -0,0 +1,124 @@
<div class="coms-table-wrap mt10" id="vue-app">
<form class=" form-search coms-table-hd clearfix no-border" onsubmit="return false"
action="/appdistribution/distribution/get_accountlog">
<input type="hidden" name="app_uid" value="<?= $params['app_uid'] ?>">
<input type="hidden" name="app_id" value="<?= $params['app_id'] ?>">
<div class="am-form am-form-horizontal">
<div class="am-form-group fl">
<label class="am-para-label w100">账务类型:</label>
<div class="am-para-inline w120">
<select name="trade_type">
<option value="" >全部</option>
<?php foreach ($trade_type_ary as $key => $value) { ?>
<option value="<?= $key ?>"
<?= $key == $params['trade_type'] ? 'selected' : '' ?>><?= $value ?></option>
<? } ?>
</select>
</div>
</div>
<div class="am-form-group fl ml30">
<div class="am-para-inline w300">
<input id="order-lists-time" type="text" name="time" value="<?= $params['time'] ?>"
placeholder="入账日期范围"/>
</div>
</div>
<div class="am-form-group fl mb10" style="margin-top: 5px">
<div class="am-para-inline">
<a class="mr10 order-lists-time-btn" href="javascript:void (0);" data-date="today">今天</a>
<a class="mr10 order-lists-time-btn" href="javascript:void (0);"
data-date="yesterday">昨日</a>
<a class="mr10 order-lists-time-btn" href="javascript:void (0);" data-date="7day">最近7天</a>
<a class="mr10 order-lists-time-btn" href="javascript:void (0);" data-date="30day">最近30天</a>
</div>
</div>
<div class="am-form-group fl ml30">
<div class="am-form-group fl ml10">
<button type="submit" class="am-btn am-btn-success am-btn-sm w100">搜索</button>
</div>
</div>
<div class="am-form-group" style="margin-bottom: 0px;"></div>
<div class="am-panel am-panel-default">
<div class="am-panel-bd">
<div class="am-g">
<div class="am-u-sm-2">
<ul>
<li>收入</li>
<li style="padding-top: 5px;"><?= $money_in ?></li>
</ul>
</div>
<div class="am-u-sm-2 am-u-end">
<ul>
<li>支出</li>
<li style="padding-top: 5px;"><?= $money_out ?></li>
</ul>
</div>
</div>
</div>
</div>
</div>
</form>
<div class="coms-table-bd">
<table class="am-table am-table-bordered">
<thead>
<tr>
<th width="10%"><span>入账时间</span></th>
<th width="10%"><span>订单号</span></th>
<th width="10%"><span>账务类型</span></th>
<th width="10%"><span>收入金额</span></th>
<th width="10%"><span>支出金额</span></th>
<th width="10%"><span>当前余额</span></th>
</tr>
</thead>
<tbody>
<?php if ($lists) {
foreach ($lists as $v) { ?>
<tr>
<td><?= $v['c_time'] ?></td>
<td><?= $v['sid'] ?></td>
<td><?= $v['trade_type_name'] ?></td>
<td><?= $v['money_in'] ?></td>
<td><?= $v['money_out'] ?></td>
<td><?= $v['money_left'] ?></td>
</tr>
<?php }
} ?>
</tbody>
</table>
</div>
<div class="coms-table-ft clearfix">
<div class="hander am-form">
</div>
<div class="coms-pagination fr mr20">
<?php page_view($pager) ?>
</div>
</div>
</div>
<script>
require(['laydate', 'autocomplete'], function (laydate) {
//日期范围
laydate.render({
elem: '#order-lists-time'
, range: '~'
});
$('.order-lists-time-btn').click(function () {
var type = $(this).data('date'), date = '', d_obj = new Date();
switch (type) {
case 'today':
date = d_obj.Format('yyyy-MM-dd');
date = date + ' ~ ' + date;
break;
case 'yesterday':
date = (new Date(d_obj.getTime() - 86400000)).Format('yyyy-MM-dd');
date = date + ' ~ ' + date;
break;
case '7day':
date = (new Date(d_obj.getTime() - 86400000 * 7)).Format('yyyy-MM-dd') + ' ~ ' + d_obj.Format('yyyy-MM-dd');
break;
case '30day':
date = (new Date(d_obj.getTime() - 86400000 * 30)).Format('yyyy-MM-dd') + ' ~ ' + d_obj.Format('yyyy-MM-dd');
break;
}
$('#order-lists-time').val(date);
});
});
</script>
+93
View File
@@ -0,0 +1,93 @@
<div class="coms-table-wrap mt10" id="vue-app">
<form class=" form-search coms-table-hd clearfix no-border" onsubmit="return false"
action="/appdistribution/distribution/get_commission">
<input type="hidden" name="app_uid" value="<?= $params['app_uid'] ?>">
<input type="hidden" name="app_id" value="<?= $params['app_id'] ?>">
<div class="am-form am-form-horizontal">
<div class="am-form-group fl">
<div class="am-para-inline w300">
<input id="order-lists-time" type="text" name="time" value="<?= $params['time'] ?>"
placeholder="创建日期范围"/>
</div>
</div>
<div class="am-form-group fl mb10" style="margin-top: 5px">
<div class="am-para-inline">
<a class="mr10 order-lists-time-btn" href="javascript:void (0);" data-date="today">今天</a>
<a class="mr10 order-lists-time-btn" href="javascript:void (0);"
data-date="yesterday">昨日</a>
<a class="mr10 order-lists-time-btn" href="javascript:void (0);" data-date="7day">最近7天</a>
<a class="mr10 order-lists-time-btn" href="javascript:void (0);" data-date="30day">最近30天</a>
</div>
</div>
<div class="am-form-group fl ml30">
<div class="am-form-group fl ml10">
<button type="submit" class="am-btn am-btn-success am-btn-sm w100">搜索</button>
</div>
</div>
</div>
</form>
<div class="coms-table-bd">
<table class="am-table am-table-bordered">
<thead>
<tr>
<th width="10%"><span>商品标题</span></th>
<th width="10%"><span>商品价格</span></th>
<th width="10%"><span>佣金</span></th>
<th width="10%"><span>订单来源</span></th>
<th width="10%"><span>状态</span></th>
<th width="10%"><span>创建时间</span></th>
</tr>
</thead>
<tbody>
<?php if ($lists) {
foreach ($lists as $v) { ?>
<tr>
<td><?= $v['item_title'] ?></td>
<td><?= $v['total_price'] ?></td>
<td><?= $v['expect_money'] ?></td>
<td><?= $v['source'] ?></td>
<td><?= $v['status_name'] ?></td>
<td><?= $v['c_time'] ?></td>
</tr>
<?php }
} ?>
</tbody>
</table>
</div>
<div class="coms-table-ft clearfix">
<div class="hander am-form">
</div>
<div class="coms-pagination fr mr20">
<?php page_view($pager) ?>
</div>
</div>
</div>
<script>
require(['laydate', 'autocomplete'], function (laydate) {
//日期范围
laydate.render({
elem: '#order-lists-time'
, range: '~'
});
$('.order-lists-time-btn').click(function () {
var type = $(this).data('date'), date = '', d_obj = new Date();
switch (type) {
case 'today':
date = d_obj.Format('yyyy-MM-dd');
date = date + ' ~ ' + date;
break;
case 'yesterday':
date = (new Date(d_obj.getTime() - 86400000)).Format('yyyy-MM-dd');
date = date + ' ~ ' + date;
break;
case '7day':
date = (new Date(d_obj.getTime() - 86400000 * 7)).Format('yyyy-MM-dd') + ' ~ ' + d_obj.Format('yyyy-MM-dd');
break;
case '30day':
date = (new Date(d_obj.getTime() - 86400000 * 30)).Format('yyyy-MM-dd') + ' ~ ' + d_obj.Format('yyyy-MM-dd');
break;
}
$('#order-lists-time').val(date);
});
});
</script>
+130
View File
@@ -0,0 +1,130 @@
<div class="coms-table-wrap mt10" id="vue-app">
<form class=" form-search coms-table-hd clearfix no-border" onsubmit="return false"
action="/appdistribution/distribution/get_team">
<input type="hidden" name="up_uid" value="<?= $params['up_uid'] ?>">
<input type="hidden" name="statistical" value="<?= $params['statistical'] ?>">
<div class="am-form am-form-horizontal">
<div class="am-form-group fl">
<div class="am-para-inline w300">
<input id="order-lists-time" type="text" name="time" value="<?= $params['time'] ?>"
placeholder="统计日期范围"/>
</div>
</div>
<div class="am-form-group fl mb10" style="margin-top: 5px">
<div class="am-para-inline w300">
<a class="mr10 order-lists-time-btn" href="javascript:void (0);" data-date="today">今天</a>
<a class="mr10 order-lists-time-btn" href="javascript:void (0);"
data-date="yesterday">昨日</a>
<a class="mr10 order-lists-time-btn" href="javascript:void (0);" data-date="7day">最近7天</a>
<a class="mr10 order-lists-time-btn" href="javascript:void (0);" data-date="30day">最近30天</a>
</div>
</div>
<div class="am-form-group fl ml30">
<div class="am-form-group fl ml10">
<button type="submit" class="am-btn am-btn-success am-btn-sm w100">搜索</button>
</div>
</div>
<div class="am-form-group" style="margin-bottom: 0px;"></div>
<div class="am-panel am-panel-default">
<div class="am-panel-bd">
<div class="am-g">
<div class="am-u-sm-2">
<ul>
<li style="width: 250px;">日期:<?= $params['time_str'] ?></li>
<li style="padding-top: 5px;">团队订单数:<?= $team_orders ?></li>
</ul>
</div>
<div class="am-u-sm-2">
<ul>
<li>&nbsp;&nbsp;</li>
<li style="padding-top: 5px;">团队订单成功数:<?= $team_orders_suc ?></li>
</ul>
</div>
<div class="am-u-sm-2 am-u-end">
<ul>
<li> &nbsp;&nbsp;</li>
<li style="padding-top: 5px;">团队佣金:<?= $team_money ?></li>
</ul>
</div>
</div>
</div>
</div>
</div>
</form>
<div class="coms-table-bd">
<table class="am-table am-table-bordered">
<thead>
<tr>
<th width="50"><span>ID</span></th>
<th width="10%"><span>团员名称</span></th>
<th width="10%"><span>订单数</span></th>
<th width="10%"><span>成功数</span></th>
<th width="10%"><span>带来佣金</span></th>
<th width="10%"><span>手机</span></th>
<th width="15%"><span>操作</span></th>
</tr>
</thead>
<tbody>
<?php if ($lists) {
foreach ($lists as $v) { ?>
<tr>
<td><?= $v['id'] ?></td>
<td><?= $v['nickname'] ?></td>
<td><?= $v['orders'] ?></td>
<td><?= $v['orders_suc'] ?></td>
<td><?= $v['bring_money'] ?></td>
<td><?= $v['mobile'] ?></td>
<td>
<a data-open="/appdistribution/distribution/get_commission?app_uid=<?= $v['id'] ?>&app_id=<?= $app_id ?>"
class="am-btn am-btn-primary am-btn-xs">佣金明细</a>
<a data-open="/appdistribution/distribution/get_accountlog?app_uid=<?= $v['id'] ?>&app_id=<?= $app_id ?>"
class="am-btn am-btn-primary am-btn-xs">资金流水</a>
<? if ($v['type'] == 1) { ?>
<a class="am-btn am-btn-primary am-btn-xs"
data-action="/appdistribution/distribution/edit_team_dealer" data-ajax="post"
data-params-dealer="1" data-params-app_id="<?= $app_id ?>"
data-params-id="<?= $v['id'] ?>">设为分销</a>
<? } ?>
</td>
</tr>
<?php }
} ?>
</tbody>
</table>
</div>
<div class="coms-table-ft clearfix">
<div class="hander am-form">
</div>
<div class="coms-pagination fr mr20">
<?php page_view($pager) ?>
</div>
</div>
</div>
<script>
require(['laydate', 'autocomplete'], function (laydate) {
//日期范围
laydate.render({
elem: '#order-lists-time', range: '~'
});
$('.order-lists-time-btn').click(function () {
var type = $(this).data('date'), date = '', d_obj = new Date();
switch (type) {
case 'today':
date = d_obj.Format('yyyy-MM-dd');
date = date + ' ~ ' + date;
break;
case 'yesterday':
date = (new Date(d_obj.getTime() - 86400000)).Format('yyyy-MM-dd');
date = date + ' ~ ' + date;
break;
case '7day':
date = (new Date(d_obj.getTime() - 86400000 * 7)).Format('yyyy-MM-dd') + ' ~ ' + d_obj.Format('yyyy-MM-dd');
break;
case '30day':
date = (new Date(d_obj.getTime() - 86400000 * 30)).Format('yyyy-MM-dd') + ' ~ ' + d_obj.Format('yyyy-MM-dd');
break;
}
$('#order-lists-time').val(date);
});
});
</script>
+102
View File
@@ -0,0 +1,102 @@
<div class="coms-table-wrap mt10" id="vue-app">
<form class=" form-search coms-table-hd clearfix no-border" onsubmit="return false"
action="/appdistribution/distribution">
<div class="am-form am-form-horizontal">
<div class="am-form-group fl">
<label class="am-para-label w100">团长名称:</label>
<div class="am-para-inline w200">
<input type="text" name="nickname" value="<?= $params['nickname'] ?>"/>
</div>
</div>
<div class="am-form-group fl">
<label class="am-para-label w100">电话:</label>
<div class="am-para-inline w200">
<input type="text" name="mobile" value="<?= $params['mobile'] ?>"/>
</div>
</div>
<div class="am-form-group fl">
<label class="am-para-label w100">统计:</label>
<div class="am-para-inline w120">
<select name="statistical">
<?php foreach ($statistical_ary as $key => $value) { ?>
<option value="<?= $key ?>"
<?= $key == $params['statistical'] ? 'selected' : '' ?>><?= $value ?></option>
<? } ?>
</select>
</div>
</div>
<div class="am-form-group fl ml30">
<div class="am-form-group fl ml10">
<button type="submit" class="am-btn am-btn-success am-btn-sm w100">搜索</button>
</div>
<div class="am-form-group fl ml20" style="display: none">
<button type="button" id="export" class="am-btn am-btn-success am-btn-sm w100">导出</button>
</div>
</div>
</div>
</form>
<div class="coms-table-bd">
<table class="am-table am-table-bordered">
<thead>
<tr>
<th width="50"><span>ID</span></th>
<th width="10%"><span>团长名称</span></th>
<th width="10%"><span><?= $statistical_name ?>人数</span></th>
<th width="10%"><span><?= $statistical_name ?>订单数</span></th>
<th width="10%"><span><?= $statistical_name ?>成功数</span></th>
<th width="10%"><span><?= $statistical_name ?>佣金</span></th>
<th width="10%"><span>手机</span></th>
<th width="10%"><span>操作</span></th>
</tr>
</thead>
<tbody>
<?php if ($lists) {
foreach ($lists as $v) { ?>
<tr>
<td><?= $v['id'] ?></td>
<td><?= $v['nickname'] ?></td>
<td><?= $v['nums'] ?></td>
<td><?= $v['orders'] ?></td>
<td><?= $v['orders_suc'] ?></td>
<td><?= $v['money'] ?></td>
<td><?= $v['mobile'] ?></td>
<td><a class="am-btn am-btn-danger am-btn-xs"
data-action="/appdistribution/distribution/edit_team_dealer" data-ajax="post"
data-params-dealer="0" data-params-app_id="<?= $app_id ?>"
data-params-id="<?= $v['id'] ?>">取消分销</a></td>
</tr>
<tr>
<td colspan="8" class="align-r">
<a data-open="/appdistribution/distribution/get_team?up_uid=<?= $v['id'] ?>&statistical=<?= $params['statistical'] ?>&app_id=<?= $app_id ?>"
class="am-btn am-btn-primary am-btn-xs">查看团队</a>
<a data-open="/appdistribution/distribution/get_commission?app_uid=<?= $v['id'] ?>&app_id=<?= $app_id ?>"
class="am-btn am-btn-primary am-btn-xs">佣金明细</a>
<a data-open="/appdistribution/distribution/get_accountlog?app_uid=<?= $v['id'] ?>&app_id=<?= $app_id ?>"
class="am-btn am-btn-primary am-btn-xs">资金流水</a>
</td>
</tr>
<?php }
} ?>
</tbody>
</table>
</div>
<div class="coms-table-ft clearfix">
<div class="hander am-form">
</div>
<div class="coms-pagination fr mr20">
<?php page_view($pager) ?>
</div>
</div>
</div>
<script>
$('#export').on('click', function () {
var count = <?=$pager['totle']?>;
if (count > 10000) {
layer.msg('单次导出数据不能超过10000');
return false;
}
var href = $.menu.parseUri(window.location.href);
href = href.replace("lists", "export");
window.location.href = href;
});
</script>
+57
View File
@@ -210,6 +210,63 @@ class Hd extends CI_Controller {
return $this->print_return($this->return_error($e->getCode(), $e->getMessage()));
}
}
/**
* 分销入口
*/
public function distribution(){
define('WXAPP_ITEMS', 1);
//加载输入参数
$this->input_param();
$app_id = $this->input_param('app_id');
!$app_id && $app_id = $this->input_param('vipcard_id');
$version = $this->input_param('version');
$sversion = $this->input_param('sversion');
$this->log_file = get_class($this) . "_{$app_id}.log";
//应用ID为空
if(!$app_id){
debug_log("[fail]". __FUNCTION__ . ":app_id is null; uri_string:" . $this->uri->uri_string(), $this->log_file);
return $this->print_return($this->return_error(API_CODE_INVILD_PARAM, '请求丢失'));
}
//签名不正确
if(!$this->vaild_sign()){
debug_log("[fail]". __FUNCTION__ . ":sign check fail; uri_string:" . $this->uri->uri_string() . "; param:".json_encode($this->inputs), $this->log_file);
return $this->print_return($this->return_error(API_CODE_INVILD_PARAM, '非法请求'));
}
$app = self::$apps[$app_id];
$class_name = ucfirst($this->uri->segment(3));
if($this->uri->segment(4)){
$method = $this->request . "_" . $this->uri->segment(4);
} else {
$method = $this->request;
}
//app定制ct
$file_name = APPPATH."controllers/wxapp/distribution/{$app}/{$class_name}.php";
//ct不存在
if(file_exists($file_name)) {
require_once $file_name;
} else {
//app定制ct不存在,使用公共ct
$file_name = APPPATH."controllers/wxapp/distribution/{$class_name}.php";
if(file_exists($file_name)) {
require_once $file_name;
} else{
debug_log("[fail]". __FUNCTION__ . ": file '{$file_name}' not exist; method:{$method}, app_id:".$app_id, $this->log_file);
return $this->print_return($this->return_error(API_CODE_NONE, '非法请求'));
}
}
try{
$class = new $class_name($this->inputs, $app);
$result = $class->$method($version, $sversion);
if(!$result) {
throw new Exception('', ERR_SYS_FAIL);
}
return $this->print_return($result);
} catch (Exception $e){
return $this->print_return($this->return_error($e->getCode(), $e->getMessage()));
}
}
/**
* 测试签名(开发环境)
+139
View File
@@ -0,0 +1,139 @@
<?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/7/01 15:16
* Created by: dengbw
*/
class Cash 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->log_file = 'distribution_cash.log';
$this->load->model('app/User_account_model', 'mdUserAccount');
$this->load->model('app/User_accountlog_model', 'mdUserAccountLog');
}
/**
* Notes:提现列表
* Created on: 2020/7/01 11:47
* Created by: dengbw
* @return array
*/
protected function get()
{
$page = $this->input_param('page');
$size = $this->input_param('size');
$status = $this->input_param('status');
!$page && $page = 1;
!$size && $size = 10;
$statusAry = array(1 => '已完成', -1 => '失败');
$tab[] = array("value" => '', 'title' => '全部');
foreach ($statusAry as $key => $value) {
$tab[] = array("value" => $key, 'title' => $value);
}
$lists = array();
$reUa = $this->mdUserAccount->get(array('app_id' => $this->app_id, 'app_uid' => $this->uid, 'status' => 1));
$where['account_id'] = $reUa['id'] ? $reUa['id'] : 0;
$where['trade_type'] = 2;
if (status_verify($status)) {
$where['status'] = $status;
}
$total = $this->mdUserAccountLog->count($where);
if ($total) {
$resUa = $this->mdUserAccountLog->select($where, 'id DESC', $page, $size, 'money_out,status,c_time');
foreach ($resUa as $key => $value) {
$setValue = array();
$setValue['name'] = '提现';
$setValue['status'] = $value['status'];
$setValue['status_name'] = $statusAry[$value['status']];
$setValue['money_out'] = $value['money_out'];
$setValue['c_time'] = date('Y-m-d H:i:s', $value['c_time']);
$lists[] = $setValue;
}
}
if ($page == 1) {
$img_url = $this->mdUserAccount->config()[$this->app_id]['deal']['img_url'];
$bg_color = $this->mdUserAccount->config()[$this->app_id]['deal']['bg_color'];
$data['tab'] = $tab;
$money_total = $cash_money = $cash_money_out = 0.00;
if ($reUa) {
$money_total = $reUa['money_total'];
$cash_money = $reUa['money_left'];
$cash_money_out = $reUa['money_total'] - $reUa['money_left'];
}
$data['title'] = '提现';
$data['bg'] = array('color' => $bg_color, 'img' => $img_url . '/distribute/list-theme.jpg');
$data['money_total'] = array('title' => '总收入(元)', 'value' => $money_total);
$data['cash_money'] = array('title' => '可提现金额(元)', 'value' => number_format_com($cash_money, 2, ''));
$data['cash_money_out'] = array('title' => '已提现金额(元)', 'value' => number_format_com($cash_money_out, 2, ''));
}
$data['list'] = $lists;
$data['total'] = $total;
return $data;
}
/**
* Notes:提现审请
* Created on: 2020/7/2 9:47
* Created by: dengbw
* @throws Hd_exception
*/
protected function put()
{
$reU = $this->app_user_model->get(array('id' => $this->uid));
if ($reU['dealer'] != 1) {
throw new Hd_exception('不是分销用户,不可提现', API_CODE_FAIL);
}
$reUa = $this->mdUserAccount->get(array('app_id' => $this->app_id, 'app_uid' => $this->uid, 'status' => 1));
$cash_money = $reUa['money_left'];
if ($cash_money < 1) {
throw new Hd_exception('提现金额不能少于1元', API_CODE_INVILD_PARAM);
}
$sid = create_order_no(350200, 'cash');
//企业付款到零钱
$this->load->library('Transfers', array('app_id' => $this->app_id));
$result = $this->transfers->sendMoney(array('partner_trade_no' => $sid, 'amount' => $cash_money
, 'openid' => $reU['openid'], 'desc' => '分销提现', 're_user_name' => $reU['nickname']));
//echo json_encode($result, JSON_UNESCAPED_UNICODE);
debug_log("[info] " . __FUNCTION__ . "# result:" . json_encode($result, JSON_UNESCAPED_UNICODE), $this->log_file);
if ($result['return_code'] == 'SUCCESS' && $result['result_code'] == 'SUCCESS') {//提现成功
$money_left = $reUa['money_left'] - $cash_money;
$addData = array("account_id" => $reUa['id'], "sid" => $sid, "money_out" => $cash_money, "money_left" => $money_left,
"status" => 1, "trade_type" => 2, "jsondata" => json_encode($result, JSON_UNESCAPED_UNICODE)
, 'c_time' => time());
$re1 = $this->mdUserAccountLog->add($addData);
if (!$re1) {
debug_log("[error] " . __FUNCTION__ . ":err_sql:" . $this->mdUserAccountLog->db->last_query(), $this->log_file);
}
//$money_freeze = $reUa['money_freeze'] + $cash_money;
//$updateData = array('money_freeze' => $money_freeze, 'money_left' => $money_left);
$updateData = array('money_left' => $money_left);
$this->mdUserAccount->update($updateData, array('app_id' => $this->app_id, 'app_uid' => $this->uid));
$res2 = $this->mdUserAccount->db->affected_rows();
if ($res2) {
debug_log("[success] " . __FUNCTION__ . ":操作成功", $this->log_file);
} else {
debug_log("[error] " . __FUNCTION__ . ":err_sql:" . $this->mdUserAccount->db->last_query(), $this->log_file);
}
throw new Hd_exception('提现成功', API_CODE_SUCCESS);
} else {
throw new Hd_exception('提现失败,请联系客服', API_CODE_FAIL);
}
}
}
+36
View File
@@ -0,0 +1,36 @@
<?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 Commission 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'];
}
/**
* Notes:佣金明细
* Created on: 2020/6/30 11:47
* Created by: dengbw
* @return array
*/
protected function get(){
}
}
+232
View File
@@ -0,0 +1,232 @@
<?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));
if ($reU['dealer'] != 1) {
throw new Hd_exception('不是分销用户', API_CODE_FAIL);
}
$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';
}
}
$team_title && $menulist[] = array('title' => $team_title, 'url' => $team_url, 'img' => $img_url . '/distribute/index-icon-1.png');
$menulist[] = array('title' => '佣金明细', 'url' => '/pages/distribute/reward/index', 'img' => $img_url . '/distribute/index-icon-2.png');
$menulist[] = array('title' => '立即提现', 'url' => '/pages/distribute/cashout/index', 'img' => $img_url . '/distribute/index-icon-3.png');
$menulist[] = array('title' => '分销商品库', 'url' => '/pages/distribute/goods/index', 'img' => $img_url . '/distribute/index-icon-4.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);
if(in_array($up_uid, array(2))){
//特殊用户的邀请,变成一级分销
$upd['up_uid'] = 0;
}
$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);
}
}
+186
View File
@@ -0,0 +1,186 @@
<?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 Team 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');
$this->load->model('app/User_accountlog_model', 'mdUserAccountLog');
$this->load->model('app/Deal_log_model', 'mdDealLog');
}
/**
* Notes:顶部信息
* Created on: 2020/7/20 11:34
* Created by: dengbw
* @return mixed
* @throws Hd_exception
*/
protected function get_top()
{
$reU = $this->app_user_model->get(array('id' => $this->uid), 'id,dealer,up_uid');
if ($reU['dealer'] != 1) {
throw new Hd_exception('不是分销用户', API_CODE_FAIL);
}
if ($reU['dealer'] == 1 && $reU['up_uid'] == 0) {//一级分销
$up_uid = $reU['id'];
} else {//团员
$up_uid = $reU['up_uid'];
}
$img_url = $this->mdUserAccount->config()[$this->app_id]['deal']['img_url'];
$bg_color = $this->mdUserAccount->config()[$this->app_id]['deal']['bg_color'];
$total = $this->app_user_model->count(array('dealer' => 1, 'up_uid' => $up_uid));
$data['title'] = '分销团队';
$data['bg'] = array('color' => $bg_color, 'img' => $img_url . '/distribute/zc-bg.jpg');
$where = array('app_id' => $this->app_id, 'app_uid' => $up_uid, 'status' => 1, 'type in(1,3)' => null);
$sum = $this->mdDealLog->sum('money', $where);
$data['team_money'] = array('title' => '团队佣金(元)', 'value' => number_format_com($sum['money'], 2, ''));
$data['team_nums'] = array('title' => '团队人数', 'value' => $total);
$menulist[] = array('title' => '我', 'value' => 0);
$menulist[] = array('title' => '团员', 'value' => 1);
if ($this->app_config('lock_fans') == 1) {//锁粉才有粉丝
$menulist[] = array('title' => '粉丝', 'value' => 2);
}
$data['menulist'] = $menulist;
return $data;
}
/**
* Notes:分销团队列表
* Created on: 2020/7/20 11:33
* Created by: dengbw
* @return mixed
* @throws Hd_exception
*/
protected function get()
{
$page = $this->input_param('page');
$size = $this->input_param('size');
$type = intval($this->input_param('type'));
!$page && $page = 1;
!$size && $size = 10;
$lists = $where = array();
$up_uid = 0;
$reU = $this->app_user_model->get(array('id' => $this->uid));
if ($reU['dealer'] != 1) {
throw new Hd_exception('不是分销用户', API_CODE_FAIL);
}
if ($type == 0) {
$myValue['nickname'] = $reU['nickname'] ? $reU['nickname'] : '我';
$myValue['orders'] = $this->mdDealLog->count(array('app_id' => $this->app_id, 'app_uid' => $this->uid, 'type in(0,2)' => null));
$myValue['orders_suc'] = $this->mdDealLog->count(array('app_id' => $this->app_id, 'app_uid' => $this->uid, 'type in(0,2)' => null, 'status' => 1));
$mySum = $this->mdDealLog->sum('money', array('app_id' => $this->app_id, 'app_uid' => $this->uid, 'type in(0,2)' => null, 'status' => 1));
$myValue['bring_money'] = number_format_com($mySum['money'], 2, '');
$lists[] = $myValue;
$data['field'] = array(array('title' => '姓名', 'value' => 'nickname'), array('title' => '订单数', 'value' => 'orders')
, array('title' => '成功数', 'value' => 'orders_suc'), array('title' => '带来佣金', 'value' => 'bring_money'));
$data['list'] = $lists;
$data['total'] = 1;
return $data;
} else if ($type == 1) {//团员
if ($reU['dealer'] == 1 && $reU['up_uid'] == 0) {//一级分销
$up_uid = $reU['id'];
} else {//团员
$up_uid = $reU['up_uid'];
}
$where = array('dealer' => 1, 'up_uid' => $up_uid);
$data['field'] = array(array('title' => '姓名', 'value' => 'nickname'), array('title' => '订单数', 'value' => 'orders')
, array('title' => '成功数', 'value' => 'orders_suc'), array('title' => '带来佣金', 'value' => 'bring_money'));
} else if ($type == 2) {//粉丝
$where = array('dealer' => 0, 'up_uid' => $this->uid);
$data['field'] = array(array('title' => '姓名', 'value' => 'nickname'),
array('title' => '订单数', 'value' => 'orders'), array('title' => '带来佣金', 'value' => 'bring_money'));
}
$resU = $this->app_user_model->select($where, 'id DESC', $page, $size, 'id,nickname');
$total = $this->app_user_model->count($where);
if ($total) {
foreach ($resU as $key => $value) {
$setValue = array();
$setValue['nickname'] = $value['nickname'] ? $value['nickname'] : '神秘用户';
if ($type == 1) {
$where1 = array('app_id' => $this->app_id, 'app_uid' => $up_uid, 't_uid' => $value['id'], 'type in(1,3)' => null);
$where2 = array('app_id' => $this->app_id, 'app_uid' => $up_uid, 't_uid' => $value['id'], 'type in(1,3)' => null, 'status' => 1);
$orders = $this->mdDealLog->count($where1);
$orders_suc = $this->mdDealLog->count($where2);
$orders_suc > $orders && $orders = $orders_suc;
$setValue['orders'] = $orders;
$setValue['orders_suc'] = $orders_suc;
$sum = $this->mdDealLog->sum('money', $where2);
$setValue['bring_money'] = number_format_com($sum['money'], 2, '');
} else if ($type == 2) {
$where = array('app_id' => $this->app_id, 'app_uid' => $this->uid, 't_uid' => $value['id'], 'type' => 2, 'status' => 1);
$setValue['orders'] = $this->mdDealLog->count($where);
$sum = $this->mdDealLog->sum('money', $where);
$setValue['bring_money'] = number_format_com($sum['money'], 2, '');
}
$lists[] = $setValue;
}
}
$data['list'] = $lists;
$data['total'] = $total;
return $data;
}
protected function get_fans()
{
$page = $this->input_param('page');
$size = $this->input_param('size');
!$page && $page = 1;
!$size && $size = 10;
$lists = array();
$reU = $this->app_user_model->get(array('id' => $this->uid), 'id,dealer,up_uid');
if ($reU['dealer'] != 1) {
throw new Hd_exception('不是分销用户', API_CODE_FAIL);
}
$where = array('dealer' => 0, 'up_uid' => $this->uid);
$resU = $this->app_user_model->select($where, 'id DESC', $page, $size, 'id,nickname');
$total = $this->app_user_model->count($where);
if ($total) {
foreach ($resU as $key => $value) {
$setValue = array();
$setValue['nickname'] = $value['nickname'] ? $value['nickname'] : '神秘用户';
$where = array('app_id' => $this->app_id, 'app_uid' => $this->uid, 't_uid' => $value['id'], 'type' => 2, 'status' => 1);
$setValue['orders'] = $this->mdDealLog->count($where);
$sum = $this->mdDealLog->sum('money', $where);
$setValue['bring_money'] = number_format_com($sum['money'], 2, '');
$lists[] = $setValue;
}
}
if ($page == 1) {
$img_url = $this->mdUserAccount->config()[$this->app_id]['deal']['img_url'];
$bg_color = $this->mdUserAccount->config()[$this->app_id]['deal']['bg_color'];
$data['title'] = '分销粉丝';
$data['bg'] = array('color' => $bg_color, 'img' => $img_url . '/distribute/list-theme.jpg');
$where = array('app_id' => $this->app_id, 'app_uid' => $this->uid, 'type' => 2, 'status' => 1);
$sum = $this->mdDealLog->sum('money', $where);
$data['team_money'] = array('title' => '粉丝佣金(元)', 'value' => number_format_com($sum['money'], 2, ''));
$data['team_nums'] = array('title' => '粉丝人数', 'value' => $total);
$menulist[] = array('title' => '粉丝', 'value' => 1, 'field' => array(array('title' => '姓名', 'value' => 'nickname'),
array('title' => '订单数', 'value' => 'orders'), array('title' => '带来佣金', 'value' => 'bring_money')));
$data['menulist'] = $menulist;
}
$data['list'] = $lists;
$data['total'] = $total;
return $data;
}
}
+6 -1
View File
@@ -82,6 +82,10 @@ class User extends Wxapp{
$user = $this->app_user_model->get(array('id' => $uid));
$jsondata = json_decode($user['jsondata'],true);
$istop = 0;
if($this->session['dealer'] && $this->session['up_uid']==0){
$istop = 1;
}
$data = array(
'uid' => $uid,
'mobile' => $user['mobile'],
@@ -91,6 +95,7 @@ class User extends Wxapp{
'name' => $jsondata['alipay']['name'] ? $jsondata['alipay']['name'] : '',
'account' => $jsondata['alipay']['account'] ? $jsondata['alipay']['account'] : '',
],
'istop' => $istop,
);
return $data;
@@ -336,7 +341,7 @@ class User extends Wxapp{
['title'=>'我的爱车','icon'=>'https://qs.haodian.cn/wechat_app/liche/mine/list-icon-1.png','url'=>'/pages/mine/myCar/index'],
['title'=>'联系小狸','icon'=>'https://qs.haodian.cn/wechat_app/liche/mine/list-icon-3.png'],
];
$this->session['ifdist'] && $about[] = ['title'=>'推广提现','icon'=>'https://qs.haodian.cn/wechat_app/liche/mine/list-icon-4.png','url'=>'/pages/distribute/index'];
$this->session['dealer'] && $about[] = ['title'=>'推广提现','icon'=>'https://qs.haodian.cn/wechat_app/liche/mine/list-icon-4.png','url'=>'/pages/distribute/index'];
$data = [
'progressOpt' => $progressOpt,
'progress' => $progress,
+308
View File
@@ -0,0 +1,308 @@
<?php
/**
* Notes:分销商品
* Created on: 2020/7/9 14:44
* Created by: dengbw
*/
class Deal_entity
{
private $ci;
private $app_id;
private $app_config;
private $log_file;//日志文件
private $data = array();
public function __construct($params = array())
{
$this->ci = &get_instance();
$this->init($params);
$class_name = lcfirst(get_class($this));//调用类的名称,子类或者当前类名称
$this->log_file = "libraris_{$class_name}.log";
}
public function init($params)
{
if ($params['app_id']) {
$this->app_id = $params['app_id'];
$this->load->model('app/App_model', 'mdApp');
$this->app_config = $this->ci->mdApp->appConfig()[$this->app_id];
}
}
/**
* Notes:增加分销记录
* Created on: 2020/7/8 15:21
* Created by: dengbw
* @param $params
* @return bool
*/
public function deal_log($params)
{
if (!$params['sid']) {
return array('code' => 0, 'msg' => '参数错误');
}
$this->load->model('order/order_purchase_model', 'mdOrderPurchase');
$this->load->model($this->app_config['model'], 'mdUser');
$this->load->model('app/Deal_log_model', 'mdDealLog');
$this->load->model('apporder/order_exchange_model', 'mdOrderExchange');
$order = $this->ci->mdOrderPurchase->get(array('sid' => $params['sid'], 'app_id' => $this->app_id));
if (!$order) {
return array('code' => 0, 'msg' => '订单不存在');
}
$item = $this->ci->mdItems->get(array('id' => $order['item_id'], 'app_id' => $this->app_id));
if (!$item) {
return array('code' => 0, 'msg' => '商品不存在');
}
if (!$item['is_deal']) {
return array('code' => 0, 'msg' => '不是分销商品');
}
if ($item['type'] == 1) {//实物
if ($order['status_detail'] != 25) {
return array('code' => 0, 'msg' => '不是待发货');
}
} else if ($item['type'] == 2) {//虚似商品
if ($order['status_detail'] != 21) {
return array('code' => 0, 'msg' => '不是待核销');
}
}
if ($order['sku_id']) {
$reIs = $this->ci->mdItemStock->get(array('id' => $order['sku_id']), 'brokerage_1,brokerage_2');
} else {
$reIs = $this->ci->mdItemStock->get(array('item_id' => $order['item_id'], 'sku_ids' => 0), 'brokerage_1,brokerage_2');
}
$app = $this->ci->mdApp->get(array('id' => $this->app_id));
$json = $app['jsondata'] ? json_decode($app['jsondata'], true) : array();
$lock_fans = $json['lock_fans'] ? $json['lock_fans'] : 0; //1锁粉
$app_uid = $order['app_uid'];
if ($lock_fans == 0) {//没锁粉操作
if ($order['cf_uid']) {
$app_uid = $order['cf_uid'];
} else {
$order['cf_uid'] = $app_uid;
}
}
$reU = $this->ci->mdUser->get(array('id' => $app_uid), 'dealer,up_uid');
if (!$reU) {
//debug_log("[error] " . __FUNCTION__ . ":{$order['app_uid']}_用户不存在", $this->log_file);
return array('code' => 0, 'msg' => '用户不存在');
}
if ($lock_fans == 0 && $reU['dealer'] == 0) {//没锁粉操作
return array('code' => 0, 'msg' => '不是分销用户');
}
$res = array();
$brokerage_1 = $reIs['brokerage_1'];
$brokerage_2 = $reIs['brokerage_2'];
$brokerage = $reIs['brokerage_1'] + $reIs['brokerage_2']; //直销
if ($item['type'] == 2 && $item['code_num'] == 1) {//虚似商品且一个核销码
$where = array('status' => 0, 'app_id' => $this->app_id, 'sid' => $params['sid'], 'order_type' => 'purchase');
$res = $this->ci->mdOrderExchange->select($where, 'id DESC', 0, 0, 'id');///未核销
} else {
//商品多个核销码数量或实物商品,只算订算数
for ($x = 0; $x < $order['item_num']; $x++) {
$res[] = array("id" => 0);
}
}
//type 0自己购买 1团员购买 2粉丝购买 3团员粉丝购买
if ($res) {
foreach ($res as $key => $value) {
if ($lock_fans == 1) {//1锁粉
if ($reU['dealer'] == 1) {
if ($reU['up_uid'] == 0) {//团长自己购买直销
$this->set_deal_log(array(0, $order['app_uid'], 0, $brokerage, $value['id'], $order['sid'], $order['app_id']));
} else {//团员自己购买
$this->set_deal_log(array(0, $order['app_uid'], 0, $brokerage_1, $value['id'], $order['sid'], $order['app_id']));
}
if ($reU['up_uid']) {//团员购买团长2级
$reU3 = $this->ci->mdUser->get(array('id' => $reU['up_uid']), 'dealer');//团长
if ($reU3['dealer'] == 1 && $reU3['up_uid'] == 0) {//判断是否团长
$this->set_deal_log(array(1, $reU['up_uid'], $order['app_uid'], $brokerage_2, $value['id'], $order['sid'], $order['app_id']));
}
}
} else if ($reU['dealer'] == 0 && $reU['up_uid']) {
//粉丝购买直销
$this->set_deal_log(array(2, $reU['up_uid'], $order['app_uid'], $brokerage, $value['id'], $order['sid'], $order['app_id']));
$reU2 = $this->ci->mdUser->get(array('id' => $reU['up_uid']), 'up_uid');//团员
$reU3 = $this->ci->mdUser->get(array('id' => $reU2['up_uid']), 'dealer');//团长
if ($reU3['dealer'] == 1 && $reU3['up_uid'] == 0) {//团员粉丝购买团长2级
$this->set_deal_log(array(3, $reU2['up_uid'], $reU['up_uid'], $brokerage_2, $value['id'], $order['sid'], $order['app_id']));
}
}
} else if ($lock_fans == 0) {
if ($order['cf_uid'] == $order['app_uid']) {//自己购买
if ($reU['up_uid'] == 0) {//团长自己购买直销
$this->set_deal_log(array(0, $order['app_uid'], 0, $brokerage, $value['id'], $order['sid'], $order['app_id']));
} else {//团员自己购买1级
$this->set_deal_log(array(0, $order['app_uid'], 0, $brokerage_1, $value['id'], $order['sid'], $order['app_id']));
}
if ($reU['up_uid']) {//团员购买团长2级
$reU3 = $this->ci->mdUser->get(array('id' => $reU['up_uid']), 'dealer');
if ($reU3['dealer'] == 1 && $reU3['up_uid'] == 0) {//判断是否团长
$this->set_deal_log(array(1, $reU['up_uid'], $order['app_uid'], $brokerage_2, $value['id'], $order['sid'], $order['app_id']));
}
}
} else {
if ($reU['up_uid'] == 0) {//团长自己分享出去直销
$this->set_deal_log(array(2, $order['cf_uid'], $order['app_uid'], $brokerage, $value['id'], $order['sid'], $order['app_id']));
} else {//团员分享出去
//团员1级
$this->set_deal_log(array(2, $order['cf_uid'], $order['app_uid'], $brokerage_1, $value['id'], $order['sid'], $order['app_id']));
//团长2级
$reU3 = $this->ci->mdUser->get(array('id' => $reU['up_uid']), 'dealer');
if ($reU3['dealer'] == 1 && $reU3['up_uid'] == 0) {//判断是否团长
$this->set_deal_log(array(3, $reU['up_uid'], $order['cf_uid'], $brokerage_2, $value['id'], $order['sid'], $order['app_id']));
}
}
}
}
}
}
if ($this->data) {
$res2 = $this->ci->mdDealLog->add_batch($this->data);
if (!$res2) {
debug_log("[error] " . __FUNCTION__ . ":err_sql:" . $this->ci->mdDealLog->db->last_query(), $this->log_file);
}
}
}
private function set_deal_log($params)
{
if ($params[3]) {
$this->data[] = array('type' => $params[0], 'app_uid' => $params[1], 't_uid' => $params[2], 'money' => $params[3]
, 'ex_id' => $params[4], 'cf_sid' => $params[5], 'app_id' => $params[6], 'status' => 0, 'c_time' => time());
}
}
/**
* Notes:核销成功/确认收货后加佣金
* Created on: 2020/7/9 16:30
* Created by: dengbw
* @param $params
* @return bool
*/
public function deal_log_code($params)
{
if (!$params['sid']) {
return array('code' => 0, 'msg' => '参数错误');
}
$this->load->model('appitem/items_model', 'mdItems');
$this->load->model('order/order_purchase_model', 'mdOrderPurchase');
$order = $this->ci->mdOrderPurchase->get(array('sid' => $params['sid'], 'app_id' => $this->app_id));
$item = $this->ci->mdItems->get(array('id' => $order['item_id'], 'app_id' => $this->app_id));
if (!$order) {
return array('code' => 0, 'msg' => '订单不存在');
}
if (!$item) {
return array('code' => 0, 'msg' => '商品不存在');
}
if (!$item['is_deal']) {
return array('code' => 0, 'msg' => '不是分销商品');
}
$where = array("app_id" => $this->app_id, "cf_sid" => $params['sid'], "status" => 0);
if ($item['type'] == 1) {//实物
if ($order['status_detail'] != 27) {
return array('code' => 0, 'msg' => '未收货');
}
} else if ($item['type'] == 2) {//虚似商品
if ($item['code_num'] == 1 && $params['ex_id']) {
$this->load->model('apporder/order_exchange_model', 'mdOrderExchange');
$re_exchange = $this->ci->mdOrderExchange->get(array('id' => $params['ex_id']));
if ($re_exchange['status'] != 1) {
return array('code' => 0, 'msg' => '未核销');
}
$where['ex_id'] = $params['ex_id']; //虚似商品且一个核销码,根据核销码加佣金
}
}
$this->load->model('app/User_account_model', 'mdUserAccount');
$this->load->model('app/User_accountlog_model', 'mdUserAccountLog');
$this->load->model('app/Deal_log_model', 'mdDealLog');
$res = $this->ci->mdDealLog->select($where, 'id DESC', 0, 0, 'id,app_uid,money');
if ($res) {
foreach ($res as $key => $value) {
$reUa = $this->ci->mdUserAccount->get(array('app_id' => $this->app_id, 'app_uid' => $value['app_uid']));
if ($reUa['id']) {
$aid = $reUa['id'];
$money_total = $reUa['money_total'] + $value['money'];
$money_left = $reUa['money_left'] + $value['money'];
} else {
$money_total = $value['money'];
$money_left = $value['money'];
$addData = array('app_id' => $this->app_id, 'app_uid' => $value['app_uid'], 'status' => 1, 'c_time' => time());
$aid = $this->ci->mdUserAccount->add($addData);
}
if ($aid) {
$this->ci->mdUserAccountLog->db->trans_begin();
$this->ci->mdUserAccount->db->trans_begin();
$this->ci->mdDealLog->db->trans_begin();
//增加资金流水表
$this->ci->mdUserAccountLog->add(array('account_id' => $aid, 'trade_type' => 1, 'money_in' => $value['money']
, 'money_left' => $money_left, 'status' => 1, 'c_time' => time()));
//更新账户表
$this->ci->mdUserAccount->update(array('money_total' => $money_total, 'money_left' => $money_left), array('id' => $aid));
//更新分销记录表
$this->ci->mdDealLog->update(array('status' => 1), array('id' => $value['id']));
if ($this->ci->mdUserAccountLog->db->trans_status() && $this->ci->mdUserAccount->db->trans_status()
&& $this->ci->mdDealLog->db->trans_status()) {
$this->ci->mdUserAccountLog->db->trans_commit();
$this->ci->mdUserAccount->db->trans_commit();
$this->ci->mdDealLog->db->trans_commit();
debug_log("[success] " . __FUNCTION__ . ":操作成功,account_id={$aid}", $this->log_file);
} else {
$this->ci->mdUserAccountLog->db->trans_rollback();
$this->ci->mdUserAccount->db->trans_rollback();
$this->ci->mdDealLog->db->trans_rollback();
debug_log("[finish] " . __FUNCTION__ . ":执行失败回滚,account_id={$aid}", $this->log_file);
}
}
}
}
}
/**
* Notes:更新分销记录状态 -1无效
* Created on: 2020/7/13 15:37
* Created by: dengbw
* @param $params
* @return array
*/
public function deal_log_status($params)
{
$this->load->model('appdistribution/Deal_log_model', 'mdDealLog');
$this->load->model('appitem/items_model', 'mdItems');
$this->load->model('order/order_purchase_model', 'mdOrderPurchase');
if (!$params['id']) {
return array('code' => 0, 'msg' => '参数错误');
}
$order = $this->ci->mdOrderPurchase->get(array('id' => $params['id']));
if (!$order) {
return array('code' => 0, 'msg' => '订单不存在');
}
$item = $this->ci->mdItems->get(array('id' => $order['item_id'], 'app_id' => $this->app_id));
if (!$item) {
return array('code' => 0, 'msg' => '商品不存在');
}
if (!$item['is_deal']) {
return array('code' => 0, 'msg' => '不是分销商品');
}
if (($order['status'] == 3 && $order['status_detail'] == 33) //申请退款 已退款
|| ($order['status'] == 2 && $order['status_detail'] == 23) //支付后环节 核销码过期未退款
|| ($order['status'] == 2 && $order['status_detail'] == 24) //支付后环节 核销码过期已退款
) {
//更新分销状态失效
$this->ci->mdDealLog->update(array('status' => -1), array('app_id' => $order['app_id'], 'cf_sid' => $order['sid']));
debug_log("[success] " . __FUNCTION__ . ":操作成功,sid={$order['sid']}", $this->log_file);
} else {
debug_log("[error] " . __FUNCTION__ . ":{$order['sid']}_更新分销记录状态失败", $this->log_file);
}
}
public function __get($name)
{
if ('_model' === substr($name, -6)) {
return $this->ci->$name;
} elseif ('load' == $name) {
return $this->ci->load;
}
return null;
}
}
+27
View File
@@ -16,4 +16,31 @@ class App_model extends HD_Model
parent::__construct($this->table_name, 'default');
}
/**
* Notes:app配置
* Created on: 2019/12/27 14:52
* Created by: dengbw
* @param $app_id
* @return array
*/
public function appConfig($app_id = null)
{
$map_config = array(
'1' => array(
'app_key' => 'liche',
'table' => 'hd_app_liche_users',
'model' => 'app/liche/app_liche_users_model',
'wx' => array(
'appid' => 'wx98e64c11aac45966',
'secret' => 'f8eec7be1c87a1c8e40213e144821ec3',
),
),
);
if(is_null($app_id)){
return $map_config;
}
return $map_config[$app_id];
}
}
+17
View File
@@ -0,0 +1,17 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Notes:分销-记录表
* Created on: 2020/6/30 12:45
* Created by: dengbw
*/
class Deal_log_model extends HD_Model
{
private $table_name = 'lc_app_deal_log';
public function __construct()
{
parent::__construct($this->table_name, 'default');
}
}
+15
View File
@@ -10,4 +10,19 @@ class User_account_model extends HD_Model
parent::__construct($this->table_name, 'default');
}
/**
* Notes:配置
* Created on: 2019/12/27 14:52
* Created by: dengbw
* @return array
*/
public function config()
{
return array(
1 => array(
'deal' => array('img_url' => 'https://qs.haodian.cn/wechat_app/liche', 'bg_color' => '#fb3939'),
'rule' => ''
)
);
}
}
+22
View File
@@ -97,3 +97,25 @@ create table lc_app_user_accountlog (
u_time timestamp not null default current_timestamp on update current_timestamp,
primary key (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='账户资金流水表';
-- ----------------------------
-- Title:分销-记录表
-- Author:lcc
-- Table:lc_app_deal_log
-- ---------------------------
drop table if exists lc_app_deal_log;
create table lc_app_deal_log (
id int(10) unsigned not null auto_increment comment '自增id',
app_id int(10) unsigned not null comment '小程序id',
app_uid int(10) unsigned not null comment '小程序用户id',
cf_sid varchar(32) not null comment '来源订单号',
type tinyint(1) not null default '0' comment '类型(0自己购买1团员购买2粉丝购买3团员粉丝购买)',
t_uid int(10) unsigned not null default '0' comment '根据type加id',
ex_id int(10) unsigned not null default '0' comment '核销码id',
money decimal(12,2) not null default '0.00' comment '佣金',
remark varchar(256) not null default '' comment '备注',
status tinyint(1) not null default '0' comment '状态(-1无效 0待确认 1已入账)',
c_time int(11) not null default '0' comment '创建时间',
u_time timestamp not null default current_timestamp on update current_timestamp comment '更新时间',
primary key (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='分销-记录表'
+2 -1
View File
@@ -18,7 +18,8 @@ create table lc_app_liche_users (
u_time timestamp not null default current_timestamp on update current_timestamp,
primary key (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='狸车小程序用户表';
alter table lc_app_liche_users add ifdist tinyint(1) unsigned not null default 0 comment '是否分销人员' after jsondata;
alter table lc_app_liche_users add dealer tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否分销' after jsondata;
alter table lc_app_liche_users add up_uid int(10) NOT NULL DEFAULT '0' COMMENT '上级uid' after dealer;
-- ----------------------------