You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
281 lines
8.8 KiB
281 lines
8.8 KiB
<?php
|
|
|
|
namespace App\Service;
|
|
|
|
use App\Model\FinancialRecord;
|
|
use App\Model\Store;
|
|
use App\Model\UserBalance;
|
|
use App\Model\Users;
|
|
|
|
class FinancialRecordService implements FinancialRecordServiceInterface
|
|
{
|
|
|
|
|
|
public function ledgerAccounts($source_id, $money, $source_type, $money_type, $desc, $comment='')
|
|
{
|
|
return $this->record(
|
|
FinancialRecord::ACCOUNT_LEDGER,
|
|
[
|
|
'user_id' => FinancialRecord::ACCOUNT_LEDGER,
|
|
'user_type' => FinancialRecord::USER_TYPE_LEDGER,
|
|
'money' => $money,
|
|
'money_type' => $money_type,
|
|
'source_id' => $source_id,
|
|
'source_type' => $source_type,
|
|
'desc' => $desc,
|
|
'comment' => $comment,
|
|
'status' => FinancialRecord::STATUS_NORMAL,
|
|
],
|
|
true
|
|
);
|
|
}
|
|
|
|
public function record($user_id, $record, $isLedger=false)
|
|
{
|
|
$financialRecord = new FinancialRecord();
|
|
|
|
if (!$isLedger) {
|
|
$mod = bcmod((string)$user_id, '5', 0);
|
|
$financialRecord->suffix($mod);
|
|
}
|
|
|
|
return $financialRecord->fill(
|
|
[
|
|
'user_id' => $user_id,
|
|
'user_type' => $record['user_type'],
|
|
'money' => $record['money'],
|
|
'money_type' => $record['money_type'],
|
|
'source_id' => $record['source_id'],
|
|
'source_type' => $record['source_type'],
|
|
'desc' => $record['desc'],
|
|
'comment' => $record['comment'],
|
|
'status' => $record['status'],
|
|
]
|
|
)->save();
|
|
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function communityAwardByPlatNewUser(
|
|
$user_id,
|
|
$source_id,
|
|
$money,
|
|
$user_type=FinancialRecord::USER_TYPE_CS,
|
|
$source_type=FinancialRecord::SOURCE_TYPE_ORDER,
|
|
$money_type=FinancialRecord::MONEY_TYPE_CS_PLAT_NEW_USER,
|
|
$desc='新用户奖励',
|
|
$comment='社区服务点'
|
|
)
|
|
{
|
|
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment);
|
|
// 维护社区服务点余额
|
|
$balance = UserBalance::firstOrNew([
|
|
'user_type' => UserBalance::USER_TYPE_CS,
|
|
'source_id' => $user_id
|
|
]);
|
|
$balance->balance = bcadd($balance->balance, $money);
|
|
$balance->save();
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function communityAwardByPlatNewUserFirstOLOrder(
|
|
$user_id,
|
|
$source_id,
|
|
$money,
|
|
$user_type=FinancialRecord::USER_TYPE_CS,
|
|
$source_type=FinancialRecord::SOURCE_TYPE_ORDER,
|
|
$money_type=FinancialRecord::MONEY_TYPE_CS_FIRST_ORDER,
|
|
$desc='新用户首单奖励',
|
|
$comment='社区服务点'
|
|
)
|
|
{
|
|
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment);
|
|
// 维护社区服务点余额
|
|
$balance = UserBalance::firstOrNew([
|
|
'user_type' => UserBalance::USER_TYPE_CS,
|
|
'source_id' => $user_id
|
|
]);
|
|
$balance->balance = bcadd($balance->balance, $money);
|
|
$balance->save();
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function communitySeparateAccountsByOrderComp(
|
|
$user_id,
|
|
$source_id,
|
|
$money,
|
|
$user_type=FinancialRecord::USER_TYPE_CS,
|
|
$source_type=FinancialRecord::SOURCE_TYPE_ORDER,
|
|
$money_type=FinancialRecord::MONEY_TYPE_CS_OL_ORDER,
|
|
$desc='用户订单分成',
|
|
$comment='社区服务点'
|
|
)
|
|
{
|
|
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment);
|
|
// 维护社区服务点余额
|
|
$balance = UserBalance::firstOrNew([
|
|
'user_type' => UserBalance::USER_TYPE_CS,
|
|
'source_id' => $user_id
|
|
]);
|
|
$balance->balance = bcadd($balance->balance, $money);
|
|
$balance->save();
|
|
}
|
|
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function storeAwardByPlatNewUserOFLOrder(
|
|
$user_id,
|
|
$source_id,
|
|
$money,
|
|
$user_type=FinancialRecord::USER_TYPE_STORE,
|
|
$source_type=FinancialRecord::SOURCE_TYPE_ORDER,
|
|
$money_type=FinancialRecord::MONEY_TYPE_STORE_PLAT_NEW_USER,
|
|
$desc='新用户下单奖励',
|
|
$comment='用户当面付商户奖励'
|
|
)
|
|
{
|
|
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment);
|
|
// 同时维护钱包
|
|
$store = Store::query()->where(['user_id' => $user_id])->first();
|
|
$store->award_money = bcadd($store->award_money, $money, 2);
|
|
$store->save();
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function storeAwardByTodayFirstOFLOrder(
|
|
$user_id,
|
|
$source_id,
|
|
$money,
|
|
$user_type=FinancialRecord::USER_TYPE_STORE,
|
|
$source_type=FinancialRecord::SOURCE_TYPE_ORDER,
|
|
$money_type=FinancialRecord::MONEY_TYPE_STORE_FIRST_ORDER,
|
|
$desc='用户店铺首单奖励',
|
|
$comment='用户当面付商户奖励'
|
|
)
|
|
{
|
|
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment);
|
|
// 同时维护钱包
|
|
$store = Store::query()->where(['user_id' => $user_id])->first();
|
|
$store->award_money = bcadd($store->award_money, $money, 2);
|
|
$store->save();
|
|
}
|
|
|
|
public function recordAll($user_id, $source_id, $money, $user_type=1, $source_type=0, $money_type=0, $desc='', $comment='') {
|
|
$this->record(
|
|
$user_id,
|
|
[
|
|
'user_id' => $user_id,
|
|
'user_type' => $user_type,
|
|
'money' => $money,
|
|
'money_type' => $money_type,
|
|
'source_id' => $source_id,
|
|
'source_type' => $source_type,
|
|
'desc' => $desc,
|
|
'comment' => $comment,
|
|
'status' => FinancialRecord::STATUS_NORMAL,
|
|
]
|
|
);
|
|
|
|
$this->ledgerAccounts($source_id, $money, $source_type, $money_type, $desc, $comment);
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function userByOFLOrderPaid(
|
|
$user_id,
|
|
$source_id,
|
|
$money,
|
|
$user_type=FinancialRecord::USER_TYPE_USER,
|
|
$source_type=FinancialRecord::SOURCE_TYPE_ORDER,
|
|
$money_type=FinancialRecord::MONEY_TYPE_USER_OFL_ORDER,
|
|
$desc='用户下单(线下)',
|
|
$comment='用户下单'
|
|
)
|
|
{
|
|
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment);
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function userByOLOrderPaid(
|
|
$user_id,
|
|
$source_id,
|
|
$money,
|
|
$user_type=FinancialRecord::USER_TYPE_USER,
|
|
$source_type=FinancialRecord::SOURCE_TYPE_ORDER,
|
|
$money_type=FinancialRecord::MONEY_TYPE_USER_OL_ORDER,
|
|
$desc='用户下单(线上)',
|
|
$comment='用户下单'
|
|
)
|
|
{
|
|
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment);
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function storeByOLOrderComp(
|
|
$user_id,
|
|
$source_id,
|
|
$money,
|
|
$user_type = FinancialRecord::USER_TYPE_STORE,
|
|
$source_type = FinancialRecord::SOURCE_TYPE_ORDER,
|
|
$money_type = FinancialRecord::MONEY_TYPE_STORE_OL_ORDER_COMP,
|
|
$desc = '线上外卖订单收入',
|
|
$comment = '用户订单完成'
|
|
)
|
|
{
|
|
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment);
|
|
// 同时维护钱包
|
|
$store = Store::query()->where(['user_id' => $user_id])->first();
|
|
$store->store_wallet = bcadd($store->store_wallet, $money, 2);
|
|
$store->save();
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
*/
|
|
public function storeByOFLOrderComp(
|
|
$user_id,
|
|
$source_id,
|
|
$money,
|
|
$user_type = FinancialRecord::USER_TYPE_STORE,
|
|
$source_type = FinancialRecord::SOURCE_TYPE_ORDER,
|
|
$money_type = FinancialRecord::MONEY_TYPE_STORE_OFL_ORDER_COMP,
|
|
$desc = '线下当面付订单收入',
|
|
$comment = '用户订单完成'
|
|
)
|
|
{
|
|
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment);
|
|
}
|
|
|
|
/**
|
|
* @inheritDoc
|
|
* 订单退款(线上)
|
|
*/
|
|
public function userByOLOrderRefund(
|
|
$user_id,
|
|
$source_id,
|
|
$money,
|
|
$user_type = FinancialRecord::USER_TYPE_USER,
|
|
$source_type = FinancialRecord::SOURCE_TYPE_ORDER,
|
|
$money_type = FinancialRecord::MONEY_TYPE_USER_OL_ORDER_REFUND,
|
|
$desc = '线上订单退款',
|
|
$comment = '线上订单退款到微信'
|
|
)
|
|
{
|
|
$this->recordAll($user_id, $source_id, $money, $user_type, $source_type, $money_type, $desc, $comment);
|
|
}
|
|
}
|