lqmac 1 year ago
parent 6bc01d382d
commit d883d148b7
  1. 23
      application/api/controller/User.php
  2. 27
      application/common/service/OrderService.php

@ -664,13 +664,18 @@ class User extends Api
$user = $this->auth->getUserinfo(); $user = $this->auth->getUserinfo();
$id = $this->request->post("id", 1); $id = $this->request->post("id", 1);
$pay_voucher = $this->request->post("pay_voucher", 10); $pay_voucher = $this->request->post("pay_voucher", 10);
if (!$pay_voucher) {
$this->error("没有上传支付凭证");
}
$info = Db::name('income_expend')->where("id", $id)->find(); $info = Db::name('income_expend')->where("id", $id)->find();
if (!$info) { if (!$info) {
$this->error("记录不存在"); $this->error("记录不存在");
} }
Db::name('income_expend')->where("id", $id)->update(["pay_voucher" => $pay_voucher, "updatetime" => time(),'status' => 2]); Db::name('income_expend')->where("id", $id)->update(["pay_voucher" => $pay_voucher, "updatetime" => time(),'status' => 2]);
//是否都提交了了支付凭证,更新我的买单为支付待确认 //是否都提交了了支付凭证,更新我的买单为支付待确认,卖单为已完成
$is_all = Db::name('income_expend')->whereTime('createtime', 'today')->where("payer_id", $user['id'])->where('pay_voucher', '')->find(); $is_all = Db::name('income_expend')->whereTime('createtime', 'today')->where("payer_id", $user['id'])->where('pay_voucher', '')->find();
// var_dump($is_all);
// exit();
if (!$is_all) { if (!$is_all) {
Db::name('order') Db::name('order')
->whereTime('createtime', 'today') ->whereTime('createtime', 'today')
@ -678,6 +683,13 @@ class User extends Api
->where('user_id', $user['id']) ->where('user_id', $user['id'])
->where('order_type', 0) ->where('order_type', 0)
->update(['status' => 1,"updatetime" => time()]); ->update(['status' => 1,"updatetime" => time()]);
Db::name('order')
->whereTime('createtime', 'today')
->where('warehouse_id', $info['warehouse_id'])
->where('user_id', $user['id'])
->where('order_type', 1)
->update(['status' => 6,"updatetime" => time()]);
} }
$this->success("succ"); $this->success("succ");
} }
@ -697,9 +709,16 @@ class User extends Api
$this->error("付款人还没支付,不能确认收款"); $this->error("付款人还没支付,不能确认收款");
} }
Db::name('income_expend')->where("id", $id)->update(['status' => 3, "updatetime" => time()]); Db::name('income_expend')->where("id", $id)->update(['status' => 3, "updatetime" => time()]);
//把今天自己的订单都改为已完成 //把今天自己的卖单订单都改为已完成,买单更新为已支付
$is_all = Db::name('income_expend')->whereTime('createtime', 'today')->where("payee_id", $user['id'])->where('status','<>', 3)->find(); $is_all = Db::name('income_expend')->whereTime('createtime', 'today')->where("payee_id", $user['id'])->where('status','<>', 3)->find();
if (!$is_all) { if (!$is_all) {
Db::name('order')
->whereTime('createtime', 'today')
->where('warehouse_id', $info['warehouse_id'])
->where('user_id', $user['id'])
->where('order_type', 0)
->update(['status' => 1,"updatetime" => time()]);
Db::name('order') Db::name('order')
->whereTime('createtime', 'today') ->whereTime('createtime', 'today')
->where('warehouse_id', $info['warehouse_id']) ->where('warehouse_id', $info['warehouse_id'])

@ -44,14 +44,23 @@ class OrderService
$buyer_order[] = $value; $buyer_order[] = $value;
} }
} }
// echo "<pre>";
// print_r($buyer_order);
// print_r($seller_order);
//exit();
$pay_record = []; $pay_record = [];
foreach ($seller_order as $seller) { foreach ($seller_order as $seq => &$seller) {
if ($seller['pay_amount'] <= 0) { if ($seller['pay_amount'] <= 0) {
continue; unset($seller_order[$seq]);
continue;
} }
foreach ($buyer_order as $key => $buyer) { foreach ($buyer_order as $key => &$buyer) {
if ($buyer['pay_amount'] == 0) {
unset($buyer_order[$key]);
continue;
}
if ($seller['pay_amount'] >= abs($buyer['pay_amount'])) { if ($seller['pay_amount'] >= abs($buyer['pay_amount'])) {
$pay_record[] = [ $pay_record[] = [
'payer_id' => $buyer['user_id'], 'payer_id' => $buyer['user_id'],
'payee_id' => $seller['user_id'], 'payee_id' => $seller['user_id'],
'amount' => abs($buyer['pay_amount']), 'amount' => abs($buyer['pay_amount']),
@ -62,7 +71,7 @@ class OrderService
$seller['pay_amount'] = $seller['pay_amount'] + $buyer['pay_amount']; $seller['pay_amount'] = $seller['pay_amount'] + $buyer['pay_amount'];
unset($buyer_order[$key]); unset($buyer_order[$key]);
} else { } else {
$pay_record[] = [ $pay_record[] = [
'payer_id' => $buyer['user_id'], 'payer_id' => $buyer['user_id'],
'payee_id' => $seller['user_id'], 'payee_id' => $seller['user_id'],
'amount' => $seller['pay_amount'], 'amount' => $seller['pay_amount'],
@ -73,8 +82,14 @@ class OrderService
$buyer['pay_amount'] = $buyer['pay_amount'] + $seller['pay_amount']; $buyer['pay_amount'] = $buyer['pay_amount'] + $seller['pay_amount'];
$seller['pay_amount'] = 0; $seller['pay_amount'] = 0;
} }
// echo "<pre>";
// print_r($buyer);
} }
}
foreach ($pay_record as $key => $value) {
if ($value['amount'] == 0) {
unset($pay_record[$key]);
}
} }
// echo "<pre>"; // echo "<pre>";
// print_r($pay_record); // print_r($pay_record);

Loading…
Cancel
Save