1. 引入了 OrderEnum 枚举类,

2. 修改了订单号的生成方式,
3. 引入了 `FinancialRecord` 模型,并创建了新的财务记录。
This commit is contained in:
mkm 2024-05-23 16:31:04 +08:00
parent b07d38698d
commit 8aa441214d

View File

@ -2,9 +2,10 @@
namespace app\admin\logic\operation; namespace app\admin\logic\operation;
use app\common\enum\OrderEnum;
use app\common\model\operation\Opurchaseclass; use app\common\model\operation\Opurchaseclass;
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
use app\common\model\financial\FinancialRecord;
use app\common\model\goods\Goods; use app\common\model\goods\Goods;
use app\common\model\merchant\Merchant; use app\common\model\merchant\Merchant;
use app\common\model\opurchase\OpurchaseGoodsOffer; use app\common\model\opurchase\OpurchaseGoodsOffer;
@ -64,7 +65,7 @@ class OpurchaseclassLogic extends BaseLogic
} }
$order = [ $order = [
'time' => time(), 'time' => time(),
'number' => static::getNewOrderId('CG'), 'number' => getNewOrderId('CG'),
'total' => array_sum(array_column($cart_select, 'total')), 'total' => array_sum(array_column($cart_select, 'total')),
'pay_type' => $params['pay_type'] ?? 0, 'pay_type' => $params['pay_type'] ?? 0,
'cart_id' => implode(',', $cart_arr), 'cart_id' => implode(',', $cart_arr),
@ -253,6 +254,40 @@ class OpurchaseclassLogic extends BaseLogic
$find->notes = $notes; $find->notes = $notes;
$find->before_nums = $find->nums; $find->before_nums = $find->nums;
$find->nums = $nums; $find->nums = $nums;
$price=0;
if ($nums != 0) {
$price = bcmul($find['price'], $nums, 2);
Supplier::where('id', $id)->inc('mer_money', $price)->update();
}
$number=Opurchaseclass::where('id',$find['order_id'])->value('number');
$time=time();
//平台支出
$record[] = [
'financial_record_sn' => $time,
'order_id' => $find['order_id'],
'number_sn' => $number,
'user_id' => 0,
'financial_type' => OrderEnum::PLATFORM_ORDER_PAY,
'financial_pm' => OrderEnum::EXPENDITURE,
'number' => $price,
'status' => 1,
'type' => OrderEnum::USER,
'mer_id' => getenv('OPERATED')
];
//供应链获得流水
$record[] = [
'financial_record_sn' => $time,
'order_id' => $find['order_id'],
'number_sn' => $number,
'user_id' => 0,
'financial_type' => OrderEnum::PLATFORM_ORDER_OBTAINS,
'financial_pm' => OrderEnum::INCOME,
'number' => $price,
'status' => 1,
'type' => OrderEnum::SUPPLIER,
'mer_id' => $find['supplier_id'],
];
(new FinancialRecord())->saveAll($record);
} }
$res = $find->save(); $res = $find->save();
if ($res) { if ($res) {
@ -264,19 +299,4 @@ class OpurchaseclassLogic extends BaseLogic
return false; return false;
} }
} }
/**
* @notes 获取订单号
* @param $type
* @return string
* @author likeadmin
* @date 2021/7/28 17:05
*/
static public function getNewOrderId($type)
{
list($msec, $sec) = explode(' ', microtime());
$msectime = number_format((floatval($msec) + floatval($sec)) * 1000, 0, '', '');
$orderId = $type . $msectime . mt_rand(10000, max(intval($msec * 10000) + 10000, 98369));
return $orderId;
}
} }