|
@@ -2,6 +2,8 @@
|
|
|
|
|
|
|
|
namespace app\models\order;
|
|
namespace app\models\order;
|
|
|
|
|
|
|
|
|
|
+use app\admin\model\system\StoreBill;
|
|
|
|
|
+use app\models\system\SystemStore;
|
|
|
use crmeb\traits\ModelTrait;
|
|
use crmeb\traits\ModelTrait;
|
|
|
use crmeb\basic\BaseModel;
|
|
use crmeb\basic\BaseModel;
|
|
|
use think\Exception;
|
|
use think\Exception;
|
|
@@ -80,19 +82,30 @@ class PaymentReceived extends BaseModel
|
|
|
if (bcsub($pay_user[$field], $amount, 2) < 0) return self::setErrorInfo($title . '不足!', true);
|
|
if (bcsub($pay_user[$field], $amount, 2) < 0) return self::setErrorInfo($title . '不足!', true);
|
|
|
$paid = 1;
|
|
$paid = 1;
|
|
|
$pay_time = time();
|
|
$pay_time = time();
|
|
|
- $transfer = bcdiv(bcmul($amount, sys_config('pay_collection_commission'), 2), 100, 2);
|
|
|
|
|
- $recommend = bcdiv(bcmul($amount, sys_config('pay_collection_recommend'), 2), 100, 2);
|
|
|
|
|
|
|
+ if ($collect_user['user_store_id'] == 0) {
|
|
|
|
|
+ $transfer = bcdiv(bcmul($amount, sys_config('pay_collection_commission'), 2), 100, 2);
|
|
|
|
|
+ $recommend = bcdiv(bcmul($amount, sys_config('pay_collection_recommend'), 2), 100, 2);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $transfer = bcdiv(bcmul($amount, sys_config('store_pay_collection_commission'), 2), 100, 2);
|
|
|
|
|
+ $recommend = bcdiv(bcmul($amount, sys_config('store_pay_collection_recommend'), 2), 100, 2);
|
|
|
|
|
+ }
|
|
|
$service_charge = $transfer;
|
|
$service_charge = $transfer;
|
|
|
$res = self::create(compact('pay_type', 'pay_uid', 'code', 'collect_uid', 'amount', 'order_id', 'add_time', 'paid', 'pay_time', 'service_charge', 'type'));
|
|
$res = self::create(compact('pay_type', 'pay_uid', 'code', 'collect_uid', 'amount', 'order_id', 'add_time', 'paid', 'pay_time', 'service_charge', 'type'));
|
|
|
if ($res) {
|
|
if ($res) {
|
|
|
$now_money = bcsub($amount, $transfer, 2);
|
|
$now_money = bcsub($amount, $transfer, 2);
|
|
|
@file_put_contents("pay.txt", 'uid:' . $pay_uid . 'collect_uid:' . $collect_uid . '--' . $amount . '--' . $transfer . '--' . $now_money);
|
|
@file_put_contents("pay.txt", 'uid:' . $pay_uid . 'collect_uid:' . $collect_uid . '--' . $amount . '--' . $transfer . '--' . $now_money);
|
|
|
- User::where('uid', $collect_uid)->inc($field, $now_money)->update();
|
|
|
|
|
User::where('uid', $pay_uid)->dec($field, $amount)->update();
|
|
User::where('uid', $pay_uid)->dec($field, $amount)->update();
|
|
|
- $str = sprintf("收到%s用户%.2f%s,到账:%.2f%s,手续费:%.2f", $pay_user['nickname'], $amount, $title, $now_money, $title, $transfer);
|
|
|
|
|
- $res1 = UserBill::income('扫码收款-' . $title, $collect_uid, 'now_money', 'qr_add_' . $field, $now_money, $res['id'], bcadd($collect_user[$field], $now_money, 2), $str);
|
|
|
|
|
$res2 = UserBill::expend("扫码付款-" . $title, $pay_uid, 'now_money', 'qr_des_' . $field, $amount, $res['id'], bcsub($pay_user[$field], $amount, 2), '支付给' . $collect_user['nickname'] . $amount . $title, 1);
|
|
$res2 = UserBill::expend("扫码付款-" . $title, $pay_uid, 'now_money', 'qr_des_' . $field, $amount, $res['id'], bcsub($pay_user[$field], $amount, 2), '支付给' . $collect_user['nickname'] . $amount . $title, 1);
|
|
|
- $spread = User::get($collect_user['m_spread_uid']);
|
|
|
|
|
|
|
+ $str = sprintf("收到%s用户%.2f%s,到账:%.2f%s,手续费:%.2f", $pay_user['nickname'], $amount, $title, $now_money, $title, $transfer);
|
|
|
|
|
+ $store = SystemStore::get($collect_user['user_store_id']);
|
|
|
|
|
+ if ($collect_user['user_store_id'] > 0 && $store && $field == 'now_money') {
|
|
|
|
|
+ $res1 = StoreBill::income('扫码收款-' . $title, $collect_user['user_store_id'], 'product_sale', $now_money, $res['id'], bcadd($store['money'], $now_money, 2), $str);
|
|
|
|
|
+ $res2 = SystemStore::bcInc($collect_user['user_store_id'], 'money', $now_money, 'id');
|
|
|
|
|
+ } else {
|
|
|
|
|
+ User::where('uid', $collect_uid)->inc($field, $now_money)->update();
|
|
|
|
|
+ $res1 = UserBill::income('扫码收款-' . $title, $collect_uid, 'now_money', 'qr_add_' . $field, $now_money, $res['id'], bcadd($collect_user[$field], $now_money, 2), $str);
|
|
|
|
|
+ }
|
|
|
|
|
+ $spread = User::get($collect_user['spread_uid']);
|
|
|
$res3 = true;
|
|
$res3 = true;
|
|
|
if ($spread && $recommend > 0) {
|
|
if ($spread && $recommend > 0) {
|
|
|
User::where('uid', $spread['uid'])->inc($field, $recommend)->update();
|
|
User::where('uid', $spread['uid'])->inc($field, $recommend)->update();
|