|
@@ -4,52 +4,34 @@ use Dever;
|
|
|
class Cash
|
|
|
{
|
|
|
# 入账:待确认
|
|
|
- public function add($order_id, $order, $info)
|
|
|
+ public function add($mid, $amount, $order_num, $source_order_num)
|
|
|
{
|
|
|
- $mid = $info['mid'];
|
|
|
$merchant = Dever::db('pay/yspay_merchant')->one(array('mid' => $mid));
|
|
|
if ($merchant) {
|
|
|
- $yspay = Dever::db('pay/yspay')->one(array('account_id' => $merchant['account_id']));
|
|
|
- if ($yspay) {
|
|
|
- $cash_per = 0;
|
|
|
- if ($merchant['type'] == 1 && $yspay['type'] == 2) {
|
|
|
- $cash_per = $merchant['cash_per'];
|
|
|
- if (!$cash_per) {
|
|
|
- if ($yspay && $yspay['cash_per']) {
|
|
|
- $cash_per = $yspay['cash_per'];
|
|
|
- }
|
|
|
- }
|
|
|
- if (!$cash_per || $cash_per <= 0) {
|
|
|
- $cash_per = 0;
|
|
|
- } else {
|
|
|
- $cash_per = $cash_per/100;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- $per = $yspay['per']/100;
|
|
|
-
|
|
|
- $data['merchant_id'] = $merchant['id'];
|
|
|
- $data['order_num'] = $info['merOrderId'];
|
|
|
- $data['source_order_num'] = $order_id;
|
|
|
- $data['ycash'] = $info['totalAmount'];
|
|
|
- $data['cash'] = round($data['ycash'] - $data['ycash'] * $per, 2);
|
|
|
- if ($yspay['cash_type'] == 1) {
|
|
|
- $fz_cash = $data['ycash'];
|
|
|
- } else {
|
|
|
- $fz_cash = $data['cash'];
|
|
|
- }
|
|
|
- $data['fz_cash'] = round($fz_cash*$cash_per, 2);
|
|
|
- $data['hf_cash'] = round($data['cash'] - $data['fz_cash'], 2);
|
|
|
- $data['status'] = 1;
|
|
|
- $id = Dever::db('pay/yspay_cash')->insert($data);
|
|
|
- return $id;
|
|
|
- }
|
|
|
+ $data = array();
|
|
|
+ $data['merchant_id'] = $merchant['id'];
|
|
|
+ $data['order_num'] = $order_num;
|
|
|
+ $data['source_order_num'] = $source_order_num;
|
|
|
+ $info = Dever::db('pay/yspay_cash')->find($data);
|
|
|
+ if ($amount && $amount > 0) {
|
|
|
+ $this->getCash($amount, $data, $merchant);
|
|
|
+ }
|
|
|
+
|
|
|
+ $data['status'] = 1;
|
|
|
+ if ($info) {
|
|
|
+ $data['where_id'] = $id = $info['id'];
|
|
|
+ Dever::db('pay/yspay_cash')->update($data);
|
|
|
+ } else {
|
|
|
+ $id = Dever::db('pay/yspay_cash')->insert($data);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $id;
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
# 修改状态
|
|
|
- public function up($id, $status = 2)
|
|
|
+ public function up($id, $status = 2, $amount = false)
|
|
|
{
|
|
|
if (is_numeric($id)) {
|
|
|
$where['id'] = $id;
|
|
@@ -59,37 +41,75 @@ class Cash
|
|
|
|
|
|
$info = Dever::db('pay/yspay_cash')->find($where);
|
|
|
if ($info) {
|
|
|
- $update = array('status' => $status, 'where_id' => $info['id']);
|
|
|
- if ($status == 3) {
|
|
|
- # 开始划付
|
|
|
- $state = $this->huafu_act($info);
|
|
|
- if ($state != 'ok') {
|
|
|
- return false;
|
|
|
- }
|
|
|
- $update['rdate'] = time();
|
|
|
- }
|
|
|
- if ($status == 4) {
|
|
|
- # 开始提现
|
|
|
- $state = $this->tixian_act($info);
|
|
|
- if ($state != 'ok') {
|
|
|
- return false;
|
|
|
- }
|
|
|
- $update['tdate'] = time();
|
|
|
- }
|
|
|
- $state = Dever::db('pay/yspay_cash')->update($update);
|
|
|
- if ($state) {
|
|
|
- if ($status == 3) {
|
|
|
- $total = Dever::db('pay/yspay_cash')->getTotal(array('status' => 3, 'merchant_id' => $info['merchant_id']));
|
|
|
- if ($total) {
|
|
|
- Dever::db('pay/yspay_merchant')->update(array('where_id' => $info['merchant_id'], 'cash' => $total['cash'], 'hf_cash' => $total['hf_cash'], 'fz_cash' => $total['fz_cash']));
|
|
|
- }
|
|
|
- }
|
|
|
- return $state;
|
|
|
+ $merchant = Dever::db('pay/yspay_merchant')->one($info['merchant_id']);
|
|
|
+ if ($merchant) {
|
|
|
+ $update = array('status' => $status, 'where_id' => $info['id']);
|
|
|
+ if ($status == 3) {
|
|
|
+ # 开始划付
|
|
|
+ $state = $this->huafu_act($info);
|
|
|
+ if ($state != 'ok') {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ $update['rdate'] = time();
|
|
|
+ } elseif ($status == 4) {
|
|
|
+ # 开始提现
|
|
|
+ $state = $this->tixian_act($info);
|
|
|
+ if ($state != 'ok') {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ $update['tdate'] = time();
|
|
|
+ } elseif ($status == 2 && $amount && $amount > 0) {
|
|
|
+ # 待入账 可以修改金额
|
|
|
+ $this->getCash($amount, $update, $merchant);
|
|
|
+ }
|
|
|
+ $state = Dever::db('pay/yspay_cash')->update($update);
|
|
|
+ if ($state) {
|
|
|
+ if ($status == 3) {
|
|
|
+ $total = Dever::db('pay/yspay_cash')->getTotal(array('status' => 3, 'merchant_id' => $info['merchant_id']));
|
|
|
+ if ($total) {
|
|
|
+ Dever::db('pay/yspay_merchant')->update(array('where_id' => $info['merchant_id'], 'cash' => $total['cash'], 'hf_cash' => $total['hf_cash'], 'fz_cash' => $total['fz_cash']));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $state;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ private function getCash($amount, $merchant, &$data)
|
|
|
+ {
|
|
|
+ $yspay = Dever::db('pay/yspay')->one(array('account_id' => $merchant['account_id']));
|
|
|
+ if ($yspay) {
|
|
|
+ $cash_per = 0;
|
|
|
+ if ($merchant['type'] == 1 && $yspay['type'] == 2) {
|
|
|
+ $cash_per = $merchant['cash_per'];
|
|
|
+ if (!$cash_per) {
|
|
|
+ if ($yspay && $yspay['cash_per']) {
|
|
|
+ $cash_per = $yspay['cash_per'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!$cash_per || $cash_per <= 0) {
|
|
|
+ $cash_per = 0;
|
|
|
+ } else {
|
|
|
+ $cash_per = $cash_per/100;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $per = $yspay['per']/100;
|
|
|
+
|
|
|
+ $data['ycash'] = $amount;
|
|
|
+ $data['cash'] = round($data['ycash'] - $data['ycash'] * $per, 2);
|
|
|
+ if ($yspay['cash_type'] == 1) {
|
|
|
+ $fz_cash = $data['ycash'];
|
|
|
+ } else {
|
|
|
+ $fz_cash = $data['cash'];
|
|
|
+ }
|
|
|
+ $data['fz_cash'] = round($fz_cash*$cash_per, 2);
|
|
|
+ $data['hf_cash'] = round($data['cash'] - $data['fz_cash'], 2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private function huafu_act($info)
|
|
|
{
|
|
|
$merchant = Dever::db('pay/yspay_merchant')->one($info['merchant_id']);
|