shop-php/crmeb/jobs/AutoMarginJob.php

70 lines
2.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace crmeb\jobs;
use app\common\dao\system\serve\ServeOrderDao;
use app\common\repositories\store\order\StoreOrderRepository;
use app\common\repositories\system\merchant\MerchantRepository;
use app\common\repositories\system\serve\ServeOrderRepository;
use crmeb\interfaces\JobInterface;
use think\facade\Log;
class AutoMarginJob implements JobInterface
{
public function fire($job, $data)
{
Log::info('utoMarginStart' . var_export($data, 1));
try {
$merchant = app()->make(MerchantRepository::class)->get($data['merId']);
$orderInfo = [
'type_id' => $merchant['type_id'],
'is_margin' => $merchant['is_margin'],
'margin' => $data['margin'],
];
$values = [
'status' => 1,
'is_del' => 0,
'mer_id' => $merchant['mer_id'],
'type' => ServeOrderRepository::TYPE_MARGIN,
'meal_id'=> $merchant['type_id'],
'pay_type' => ServeOrderRepository::PAY_TYPE_BALANCE,
'order_info' => json_encode($orderInfo,JSON_UNESCAPED_UNICODE),
'pay_price' => $data['margin'],
'store_order_id' => $data['orderId'],
];
$values['order_sn'] = app()->make(StoreOrderRepository::class)->getNewOrderId('cs');
$values['pay_time'] = date('y_m-d H:i:s', time());
if (!app()->make(ServeOrderDao::class)->create($values)) {
throw new \Exception('serve_order 保存出错');
}
$merchant->paid_margin = bcadd($data['margin'], $merchant->paid_margin, 2);
$merchant->ot_margin = $merchant->paid_margin;
$merchant->is_margin = MerchantRepository::PaidMargin;
$merchant->save();
$job->delete();
} catch (\Exception $exception) {
Log::info('更新商户保证金出错:' . var_export($exception, 1));
} finally {
Log::info('autoMarginEnd' . var_export($data, 1));
}
}
public function failed($data)
{
// TODO: Implement failed() method.
}
}