WokerTask/app/common/logic/approve/ApproveLogic.php

78 lines
2.6 KiB
PHP
Raw Normal View History

2023-12-27 14:06:33 +08:00
<?php
namespace app\common\logic\approve;
use app\common\logic\BaseLogic;
use app\common\model\Approve;
use app\common\model\ShopMerchantSettleinLog;
use Symfony\Component\HttpClient\HttpClient;
use think\facade\Db;
use think\facade\Log;
class ApproveLogic extends BaseLogic
{
public static function audit($approve, $params, $userInfo)
{
// 拒绝通过
if ($params['check_status'] == 3) {
if (empty($params['remark'])) {
self::setError('请输入拒绝理由');
}
self::refuse($approve, $params);
}
// 修改任务完成状态
if ($params['check_status'] == 2) {
self::pass($approve);
}
// 回调商城,通知审核状态
if (in_array($approve['type'], [2, 3])) {
$shopMerchantInfo = json_decode($approve['extend'], true);
self::shopCallBack($approve, $shopMerchantInfo, $params, $userInfo);
}
}
private static function pass(Approve $approve)
{
$approve->check_status = 2;
$approve->save();
}
private static function refuse(Approve $approve, $params)
{
$approve->check_status = 3;
$approve->remark = $params['remark'];
$approve->save();
}
private static function shopCallBack(Approve $approve, $shopMerchantInfo, $params, $userInfo)
{
$status = $params['check_status'] == 2? 1: 2;
// 通过商户入驻审批, 记录商户入驻时间,镇农科公司市场部长任务会使用到
if ($status == 1 && $approve['type'] == 2) {
$shopMerchantInfo = json_decode($approve['extend'], true);
$data = [
'town_company_id' => $userInfo['company_id'],
'mer_intention_id' => $shopMerchantInfo['mer_intention_id'],
'create_time' => time()
];
ShopMerchantSettleinLog::create($data);
}
// 通知商城审批状态
$requestResponse = HttpClient::create()->request('POST', env('url.shop_prefix') . '/api/merchant/syncStatus/'.$shopMerchantInfo['mer_intention_id'], [
'body' => ['status' => $status, 'type' => $approve['type'] ==2 ? 1: 2, 'remark'=> $params['remark']??'']
]);
Log::info(['通知商城审批状态-参数', ['status' => $status, 'type' => $approve['type']]]);
Log::info(['通知商城审批状态-响应', [$requestResponse->getContent()]]);
}
public static function detail($id)
{
return Approve::where('id', $id)->withAttr('extend', function ($value, $data) {
return json_decode($data['extend'], true);
})->find();
}
}