|
|
|
@ -1038,7 +1038,90 @@ public function auto_rrdae(){
|
|
|
|
|
//会长提现
|
|
|
|
|
public function promoteWithdraw()
|
|
|
|
|
{
|
|
|
|
|
$promoteMap['level'] = 1;
|
|
|
|
|
$promotes = M('promote', 'tab_')->where();
|
|
|
|
|
$map['level'] = 1;
|
|
|
|
|
$map['ver_status'] = 1;
|
|
|
|
|
$promotes = M('promote', 'tab_')->field('id, account, chain')->where($map)->select();
|
|
|
|
|
$success = 0;
|
|
|
|
|
$error_withdraw = 0;
|
|
|
|
|
$error_spend = 0;
|
|
|
|
|
$error_balance = 0;
|
|
|
|
|
|
|
|
|
|
if (!empty($promotes)) {
|
|
|
|
|
foreach ($promotes as $promote) {
|
|
|
|
|
$result = $this->promoteWithdrawByPromote($promote);
|
|
|
|
|
switch ($result) {
|
|
|
|
|
case -2:
|
|
|
|
|
$error_balance++;
|
|
|
|
|
break;
|
|
|
|
|
case -1:
|
|
|
|
|
$error_spend++;
|
|
|
|
|
break;
|
|
|
|
|
case 0:
|
|
|
|
|
$error_withdraw++;
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
$success++;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
echo "success:{$success} error_withdraw:{$error_withdraw} error_spend:{$error_spend} error_balance:{$error_balance}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function promoteWithdrawByPromote($promote)
|
|
|
|
|
{
|
|
|
|
|
$promoteMap['chain'] = ['like', "{$promote['chain']}{$promote['id']}/%"];
|
|
|
|
|
$promoteIds = M('promote', 'tab_')->where($promoteMap)->getField('id', true);
|
|
|
|
|
$promoteIds[] = $promote['id'];
|
|
|
|
|
$settlementEndTime = strtotime(date('Y-m-d')) - 1;
|
|
|
|
|
|
|
|
|
|
$spendMap['pay_status'] = 1;
|
|
|
|
|
$spendMap['selle_status'] = 0;
|
|
|
|
|
$spendMap['promote_id'] = ['in', $promoteIds];
|
|
|
|
|
$spendMap['pay_time'] = ['elt', $settlementEndTime];
|
|
|
|
|
$spendModel = M('spend', 'tab_');
|
|
|
|
|
$balance = $spendModel->field("sum(if(selle_ratio > 0, pay_amount * selle_ratio, 0)) as balance")
|
|
|
|
|
->where($spendMap)
|
|
|
|
|
->find()['balance'];
|
|
|
|
|
$balance = bcdiv($balance, 100, 2);
|
|
|
|
|
if ($balance < 100) {
|
|
|
|
|
return -2;//余额不足
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$thisTime = time();
|
|
|
|
|
$add['sum_money'] = $balance;
|
|
|
|
|
$add['promote_id'] = $promote['id'];
|
|
|
|
|
$add['promote_account'] = $promote['account'];
|
|
|
|
|
$add['create_time'] = $thisTime;
|
|
|
|
|
$add['status'] = 0;
|
|
|
|
|
$add['widthdraw_number'] = D('withdraw')->produceWithdrawNumber();
|
|
|
|
|
$add['settlement_begin_time'] = 0;
|
|
|
|
|
$add['settlement_end_time'] = $settlementEndTime;
|
|
|
|
|
$add['spend_ids'] = '';
|
|
|
|
|
$add['op_id'] = 0;
|
|
|
|
|
$add['op_type'] = 3;
|
|
|
|
|
$add['last_op_id'] = $add['op_id'];
|
|
|
|
|
$add['last_op_type'] = 3;
|
|
|
|
|
|
|
|
|
|
M()->startTrans();//开启事物
|
|
|
|
|
$withdrawId = D('withdraw')->add($add);
|
|
|
|
|
if (!$withdrawId) {
|
|
|
|
|
M()->rollback();//事物回滚
|
|
|
|
|
return 0;//提现失败
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$save['selle_status'] = 1;
|
|
|
|
|
$save['selle_time'] = $thisTime;
|
|
|
|
|
$save['withdraw_id'] = $withdrawId;
|
|
|
|
|
$res = $spendModel->where($spendMap)->save($save);
|
|
|
|
|
if ($res === false) {
|
|
|
|
|
D('withdraw')->delete($withdrawId);
|
|
|
|
|
M()->rollback();//事物回滚
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
M()->commit();//事物提交
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|