multi-store/app/common/logic/StoreFinanceFlowLogic.php
2024-06-04 15:21:14 +08:00

86 lines
2.4 KiB
PHP

<?php
namespace app\common\logic;
use app\common\enum\OrderEnum;
use app\common\model\store_finance_flow\StoreFinanceFlow;
class StoreFinanceFlowLogic extends BaseLogic
{
public $order;
public $user;
public $index = 0;
public $financeSn;
public $list = [];
/**
* 支出财务流水
* @param $number
* @param $financialType
* @param $storeId
* @param $staffId
* @param $status
*/
public function out($number, $financialType, $storeId = 0, $staffId = 0, $status = 1)
{
$this->setData($number, $financialType, 0, $storeId, $staffId, $status);
}
/**
* 收入财务流水
* @param $number
* @param $financialType
* @param $storeId
* @param $staffId
* @param $status
*/
public function in($number, $financialType, $storeId = 0, $staffId = 0, $status = 1)
{
$this->setData($number, $financialType, 1, $storeId, $staffId, $status);
}
public function setData($number, $financialType, $pm, $storeId, $staffId, $status)
{
if (empty($this->financeSn)) {
$this->financeSn = $this->getSn();
}
$this->list[] = [
'order_id' => $this->order['id'],
'order_sn' => $this->order['order_id'],
'user_id' => $this->user['uid'],
'financial_type' => $financialType,
'financial_pm' => $pm,
'number' => $number,
'status' => $status,
'store_id' => $storeId !== '' ? $storeId : $this->order['store_id'],
'staff_id' => $staffId !== '' ? $staffId : $this->order['staff_id'],
'financial_record_sn' => $this->financeSn . ($this->index++)
];
}
public function save()
{
if (count($this->list) > 0) {
(new StoreFinanceFlow())->insertAll($this->list);
}
}
public function getSn()
{
list($msec, $sec) = explode(' ', microtime());
$msectime = number_format((floatval($msec) + floatval($sec)) * 1000, 0, '', '');
return 'fn' . $msectime . mt_rand(10000, max(intval($msec * 10000) + 10000, 98369));
}
public function getStoreOrder($orderId, $storeId = 0, $status = 0)
{
return StoreFinanceFlow::where('order_id', $orderId)
->where('store_id', $storeId)
->where('status', $status)
->where('financial_type', OrderEnum::MERCHANT_ORDER_OBTAINS)
->find();
}
}