Files
2021-08-03 19:13:43 +08:00

140 lines
6.3 KiB
PHP
Executable File

<?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);
}
}
}