生成汇算凭证

huazhiyu
lqmac 1 year ago
parent bb5d3eb784
commit 6bc01d382d
  1. 1
      application/admin/controller/Order.php
  2. 7
      application/api/controller/Order.php
  3. 103
      application/common/service/OrderService.php

@ -129,6 +129,7 @@ class Order extends Backend
"warehouse_id" => $params['warehouse_id'],
"order_amount" => $params['pay_amount'],
"pay_amount" => $params['pay_amount'],
"actual_amount" => $params['pay_amount'],
"coupon_price" => 0,
"coupon_id" => 0,
"status" => $params['status'],

@ -330,16 +330,13 @@ class Order extends Api
if ($ret === false) {
$this->error("下单失败");
}
//更新商品状态为下架
Goods::where('id', $goods['id'])->update(['status' => 'hidden', "updatetime" => time()]);
//分佣给买家上级
$site = Config::get("site");
$commission = bcmul($order_amount, $site['primary_distribution'] * 0.01, 2);
$obj = new UserService();
$obj->userCommission(0, $this->auth->getUserinfo(), $order_sn, $commission);
//更新商品状态为下架
Goods::where('id', $goods['id'])->update(['status' => 'hidden', "updatetime" => time()]);
$this->success("succ");
}

@ -26,64 +26,59 @@ class OrderService
*/
public function productPayRecord($warehouse_id, $time = 0){
$time = $time ? $time : time();
//卖单-待售卖
$seller_order = Db::name('order')
->field('user_id,sum(pay_amount) as pay_amount')
->whereTime('createtime', 'today')
->where('warehouse_id', $warehouse_id)
->where('order_type', 1)
->where('status', 3)
->group('user_id')
->select();
//买单-支付
$buyer_order = Db::name('order')
->field('user_id,sum(pay_amount) as pay_amount')
->whereTime('createtime', 'today')
->where('warehouse_id', $warehouse_id)
->where('order_type', 0)
->where('status', 0)
->group('user_id')
->select();
$buyer_order = array_column($buyer_order, null, "pay_amount");
$order = Db::name('order')
->field('user_id,sum(actual_amount) as pay_amount')
->whereTime('createtime', 'today')
->where('warehouse_id', $warehouse_id)
->whereIn('status', [0,3])
->group('user_id')
->select();
$buyer_order = [];
$seller_order = [];
foreach ($order as $key => $value) {
if ($value['pay_amount'] > 0) {
$seller_order[] = $value;
} elseif ($value['pay_amount'] < 0) {
$buyer_order[] = $value;
}
}
$pay_record = [];
foreach ($seller_order as $seller) {
if (isset($buyer_order[$seller['pay_amount']])) {
$pay_record[] = [
'payer_id' => $buyer_order[$seller['pay_amount']]['user_id'],
'payee_id' => $seller['user_id'],
'amount' => $seller['pay_amount'],
'createtime' => $time,
'warehouse_id' => $warehouse_id,
'date' => date("Y-m-d", $time),
];
unset($buyer_order[$seller['pay_amount']]);
if ($seller['pay_amount'] <= 0) {
continue;
}
foreach ($buyer_order as $key => $buyer) {
if ($seller['pay_amount'] >= abs($buyer['pay_amount'])) {
$pay_record[] = [
'payer_id' => $buyer['user_id'],
'payee_id' => $seller['user_id'],
'amount' => abs($buyer['pay_amount']),
'createtime' => $time,
'warehouse_id' => $warehouse_id,
'date' => date("Y-m-d", $time),
];
$seller['pay_amount'] = $seller['pay_amount'] + $buyer['pay_amount'];
unset($buyer_order[$key]);
} else {
$pay_record[] = [
'payer_id' => $buyer['user_id'],
'payee_id' => $seller['user_id'],
'amount' => $seller['pay_amount'],
'createtime' => $time,
'warehouse_id' => $warehouse_id,
'date' => date("Y-m-d", $time),
];
$buyer['pay_amount'] = $buyer['pay_amount'] + $seller['pay_amount'];
$seller['pay_amount'] = 0;
}
}
} else {
foreach ($buyer_order as $key => &$buyer) {
if ($seller['pay_amount'] > $buyer['pay_amount']) {
$pay_record[] = [
'payer_id' => $buyer['user_id'],
'payee_id' => $seller['user_id'],
'amount' => $buyer['pay_amount'],
'createtime' => $time,
'warehouse_id' => $warehouse_id,
'date' => date("Y-m-d", $time),
];
unset($seller_order[$key]);
} else {
$pay_record[] = [
'payer_id' => $buyer['user_id'],
'payee_id' => $seller['user_id'],
'amount' => $seller['pay_amount'],
'createtime' => $time,
'warehouse_id' => $warehouse_id,
'date' => date("Y-m-d", $time),
];
$buyer['pay_amount'] = $buyer['pay_amount'] - $seller['pay_amount'];
}
}
}
}
// echo "<pre>";
// print_r($pay_record);
// exit();
unset($seller);
$ret = Db::name('income_expend')->insertAll($pay_record);
return $ret;

Loading…
Cancel
Save