1 Star 0 Fork 5

doo/lmshop_kj

forked from YHGJ/lmshop_kj 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
agent_bonus.php 7.76 KB
一键复制 编辑 原始数据 按行查看 历史
Administrator 提交于 2017-12-05 10:41 . test
<?php
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
require(ROOT_PATH . 'includes/lib_license.php');
require_once('includes/cls_json.php');
define('RETURN_TYPE', empty($_POST['return_data']) ? 1 : ($_POST['return_data'] == 'json' ? 2 : 1));
/* 接收传递参数并初步检验 */
/* if (empty($_POST) || empty($_POST['ac']))
{
// api_err('0x003', 'no parameter'); //输出系统级错误:数据异常
}
*/
function random($length, $numeric = FALSE) {
$seed = base_convert(md5(microtime() . $_SERVER['DOCUMENT_ROOT']), 16, $numeric ? 10 : 35);
$seed = $numeric ? (str_replace('0', '', $seed) . '012340567890') : ($seed . 'zZ' . strtoupper($seed));
if ($numeric) {
$hash = '';
} else {
$hash = chr(rand(1, 26) + rand(0, 1) * 32 + 64);
$length--;
}
$max = strlen($seed) - 1;
for ($i = 0; $i < $length; $i++) {
$hash .= $seed{mt_rand(0, $max)};
}
return $hash;
}
switch ($_GET['act'])
{
case 'index': index(); break;
//default: api_err('0x008', 'no this type api'); //输出系统级错误:数据异常
}
/* 执行代理商结算流程 */
function index(){
$settlement_cycle = 3;//1表示按年,2表示按月,3表示按周
$order_days = 0;//订单完成多少天才进入返佣结算,为0表示收货即进行结算
$a_sql = 'SELECT * FROM ' . $GLOBALS['ecs']->table('users') . ' WHERE is_agent=1';
$agent_list = $GLOBALS['db']->getAll($a_sql);
//计算结算起止时间
if($settlement_cycle == 3){
$beginLastweek=mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y')) - date('Z') - $order_days*86400;
$endLastweek=mktime(23,59,59,date('m'),date('d')-date('w')+7-7,date('Y')) - date('Z') - $order_days*86400;
//$where = " AND o.complete_time >=".$beginLastweek." AND o.complete_time <=".$endLastweek;
$sql = 'SELECT a.*,o.order_status,o.complete_time FROM ' . $GLOBALS['ecs']->table('agent_delivery_goods') . ' a' . ' LEFT JOIN' . $GLOBALS['ecs']->table('order_info') . ' o ON a.order_id = o.order_id';
$sql .= ' WHERE o.shipping_status = 2 AND a.ab_id = 0' . $where . ' ORDER BY agent_id DESC';
$list = $GLOBALS['db']->getAll($sql);
//获取所有退款信息
$r_where = " AND ot.refound_time >=".$beginLastweek." AND ot.refound_time <=".$endLastweek;
$r_sql = 'SELECT r.*, o.shipping_status,ot.refound_status,o.complete_time,ot.order_id FROM ' . $GLOBALS['ecs']->table('return_goods') . ' r' . ' LEFT JOIN ' . $GLOBALS['ecs']->table('order_return') . ' ot ON r.ret_id = ot.ret_id'
. ' LEFT JOIN ' . $GLOBALS['ecs']->table('order_info') . ' o ON ot.order_id = o.order_id';
$r_sql .= ' WHERE o.shipping_status = 2 AND r.ab_id = 0 AND ot.refound_status=1 AND o.complete_time > 0' . $r_where . ' ORDER BY rg_id DESC';
$r_list = $GLOBALS['db']->getAll($r_sql);
$return_amount = array();
if(!empty($r_list)){
foreach ($r_list as $r){
if($r){
$ad_sql = "SELECT * FROM ".$GLOBALS['ecs']->table('agent_delivery_goods')." WHERE og_id=".$r['rec_id'];
$ad_info = $GLOBALS['db']->getRow($ad_sql);
if(!empty($ad_info)){
$return_amount[$ad_info['agent_id']]['return_amount'] = $ad_info['agent_price']*$r['return_number'];
$return_amount[$ad_info['agent_id']]['return_goods_id'][] = $r['rg_id'];
}
}
}
}
//计算每个代理商结算价格
$id_arr = array();
if(!empty($list)){
$bonus_amount = array();
foreach ($list as $a){
//$a_amount = ($a['goods_sale'] - $a['agent_price'])*$a['goods_num'];
$a_amount = $a['agent_price']*$a['goods_num'];
$bonus_amount[$a['agent_id']]['amount'] += $a_amount;
$bonus_amount[$a['agent_id']]['goodscount'] += $a['goods_num'];
$bonus_amount[$a['agent_id']]['goods_sale'] += $a['goods_sale']*$a['goods_num'];
$bonus_amount[$a['agent_id']]['id_arr'][] = $a['rec_id'];
}
$data['starttime'] = $beginLastweek;
$data['endtime'] = $endLastweek;
$data['createtime'] = gmtime();
$data['status'] = 0;
$test = local_date($format);
$data['year'] =date('Y',mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y')));
$data['month'] = date('m',mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y')));
$data['week'] = ceil(date('d',mktime(0,0,0,date('m'),date('d')-date('w')+1-7,date('Y')))/7);
foreach ($agent_list as $al){
if(!empty($bonus_amount[$al['user_id']] || !empty($return_amount[$al['user_id']]))){
$billno = "AB".date('YmdHis') . random(6, true);
while (1)
{
$sql2 = 'select count(*) from ' . $GLOBALS['ecs']->table('agent_abonus_bill') . ' where billno = '.'"$billno"';
$count = $GLOBALS['db']->getOne($sql2);
if ($count <= 0)
{
break;
}
$billno = "AB".date('YmdHis') . random(6, true);;
}
$sql3 = 'select count(*) from ' . $GLOBALS['ecs']->table('agent_abonus_bill') . ' where agent_id = '.$al['user_id'] . ' and starttime = '.$data['starttime'] . ' and endtime= '.$data['endtime'];
$count = $GLOBALS['db']->getOne($sql3);
if($count <= 0){
$ids = implode(',',$bonus_amount[$al['user_id']]['id_arr']);
$data['bonusmoney_send'] = gmtime();
$data['billno'] = $billno;
$data['goodscount'] = $bonus_amount[$al['user_id']]['goodscount'];
$data['goodsmoney'] = $bonus_amount[$al['user_id']]['goods_sale'];
$data['bonusmoney'] = $bonus_amount[$al['user_id']]['amount'] - $return_amount[$al['user_id']]['return_amount'];
$data['agent_id']= $al['user_id'];
$GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('agent_abonus_bill'), $data, "INSERT");
if($GLOBALS['db']->insert_id()){
$u_data['ab_id'] = $GLOBALS['db']->insert_id();
$GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('agent_delivery_goods'), $u_data, "UPDATE",'rec_id in (' . $ids . ')');
if(!empty($return_amount[$al['user_id']])){
$r_ids = implode(',',$return_amount[$al['user_id']]['return_goods_id']);
$GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('return_goods'), $u_data, "UPDATE",'rg_id in (' . $r_ids . ')');
}
}
}
}
}
/* foreach ($bonus_amount as $key=>$b){
$billno = "AB".date('YmdHis') . random(6, true);
while (1)
{
$sql2 = 'select count(*) from ' . $GLOBALS['ecs']->table('agent_abonus_bill') . ' where billno = '.'"$billno"';
$count = $GLOBALS['db']->getOne($sql2);
if ($count <= 0)
{
break;
}
$billno = "AB".date('YmdHis') . random(6, true);;
}
$sql3 = 'select count(*) from ' . $GLOBALS['ecs']->table('agent_abonus_bill') . ' where agent_id = '.$key . ' and starttime = '.$data['starttime'] . ' and endtime= '.$data['endtime'];
$count = $GLOBALS['db']->getOne($sql3);
if($count <= 0){
$ids = implode(',',$b['id_arr']);
$data['bonusmoney_send'] = gmtime();
$data['billno'] = $billno;
$data['goodscount'] = $b['goodscount'];
$data['goodsmoney'] = $b['goods_sale'];
$data['bonusmoney'] = $b['amount'];
$data['agent_id']= $key;
$GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('agent_abonus_bill'), $data, "INSERT");
if($GLOBALS['db']->insert_id()){
$u_data['ab_id'] = $GLOBALS['db']->insert_id();
$GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('agent_delivery_goods'), $u_data, "UPDATE",'rec_id in (' . $ids . ')');
}
}
//$sql3 = 'INSERT INTO ' . $GLOBALS['ecs']->table('agent_abonus_bill') . ' (bonusmoney_send, billno,goodscount,goodsmoney,bonusmoney,agent_id,starttime,endtime,createtime,status,year,month,week) '
// . 'VALUES (\'' . $data['bonusmoney_send'] . '\', \'' . $data['billno'] . '\', \'' .$data['goodscount']. '\', \'' .$data['goodsmoney']. '\', \'' .$data['bonusmoney']. '\', \'' .$data['agent_id'])';
//$GLOBALS['db']->query($sql);
} */
echo "sucess";
}else{
echo "无更多更新";
}
//计算每个代理商结算周期内的,退货价
}
}
?>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/dzh19951015/lmshop_kj.git
git@gitee.com:dzh19951015/lmshop_kj.git
dzh19951015
lmshop_kj
lmshop_kj
master

搜索帮助