|
|
@@ -10,6 +10,7 @@ use SixShop\Lakala\Enum\ReceiverStatusEnum;
|
|
|
use SixShop\Lakala\Facade\Config;
|
|
|
use SixShop\Lakala\Facade\LaepIndustryService;
|
|
|
use SixShop\Lakala\Facade\LedgerService;
|
|
|
+use SixShop\Lakala\Facade\SACSService;
|
|
|
use SixShop\Lakala\Model\ProfitShareOrderModel;
|
|
|
use SixShop\Lakala\Model\ProfitShareReceiverModel;
|
|
|
use think\db\Query;
|
|
|
@@ -23,13 +24,20 @@ class ProfitShareOrderEntity extends BaseEntity
|
|
|
{
|
|
|
public function getOrderList(array $params, array $pageAndLimit): Paginator
|
|
|
{
|
|
|
- return $this->withSearch(['out_separate_no', 'status'], $params)
|
|
|
+ $paginate = $this->withSearch(['out_separate_no', 'status'], $params)
|
|
|
->with(['user' => function (Query $query) {
|
|
|
$query->field(['id', 'nickname', 'avatar', 'username', 'mobile']);
|
|
|
}])
|
|
|
->append(['status_text'])
|
|
|
->order('id', 'desc')
|
|
|
->paginate($pageAndLimit);
|
|
|
+ $paginate->each(function (self $entity) {
|
|
|
+ if ($entity->status == ProfitShareOrderStatusEnum::PROCESSING || $entity->status == ProfitShareOrderStatusEnum::ACCEPTED) {
|
|
|
+ $this->queryProfitShareOrderResult($entity->id);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ return $paginate;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -93,7 +101,7 @@ class ProfitShareOrderEntity extends BaseEntity
|
|
|
|
|
|
public function getStats()
|
|
|
{
|
|
|
- $stats = $this->whereIn('status',['SUCCESS', 'PENDING'])->field([
|
|
|
+ $stats = $this->whereIn('status', ['SUCCESS', 'PENDING'])->field([
|
|
|
"COALESCE(SUM(CASE WHEN status = 'SUCCESS' THEN total_amt ELSE 0 END), 0) AS total_amount", // 总分账金额
|
|
|
"COALESCE(SUM(CASE WHEN status = 'SUCCESS' THEN separate_value ELSE 0 END), 0) AS user_total_amount", // 用户分账总金额
|
|
|
"COALESCE(SUM(CASE WHEN status = 'PENDING' THEN separate_value ELSE 0 END), 0) AS user_pending_amount", // 用户待分账总金额
|
|
|
@@ -104,4 +112,27 @@ class ProfitShareOrderEntity extends BaseEntity
|
|
|
'user_pending_amount' => (float)$stats['user_pending_amount'],
|
|
|
];
|
|
|
}
|
|
|
+
|
|
|
+ public function queryProfitShareOrderResult(int $id): self
|
|
|
+ {
|
|
|
+ $entity = $this->findOrEmpty($id);
|
|
|
+ if ($entity->isEmpty()) {
|
|
|
+ throw_logic_exception('分账订单不存在');
|
|
|
+ }
|
|
|
+ if ($entity->status == ProfitShareOrderStatusEnum::PROCESSING || $entity->status == ProfitShareOrderStatusEnum::ACCEPTED) {
|
|
|
+ $resData = SACSService::balanceSeparateQuery(merchantNo: $entity->merchant_no, separateNo: $entity->separate_no);
|
|
|
+ if ($resData->status == 'SUCCESS') {
|
|
|
+ $entity->status = ProfitShareOrderStatusEnum::SUCCESS;
|
|
|
+ }
|
|
|
+ $entity->status = match ($resData->status) {
|
|
|
+ 'ACCEPTED' => ProfitShareOrderStatusEnum::ACCEPTED,
|
|
|
+ 'SUCCESS' => ProfitShareOrderStatusEnum::SUCCESS,
|
|
|
+ 'FAIL' => ProfitShareOrderStatusEnum::FAIL,
|
|
|
+ default => throw_logic_exception('分账状态异常')
|
|
|
+ };
|
|
|
+ $resData->acc_result_desc && $entity->fail_reason = $resData->acc_result_desc;
|
|
|
+ $entity->save();
|
|
|
+ }
|
|
|
+ return $entity;
|
|
|
+ }
|
|
|
}
|