|
@@ -17,10 +17,15 @@ namespace app\adminapi\logic\works;
|
|
|
use think\db\Query;
|
|
use think\db\Query;
|
|
|
use think\Exception;
|
|
use think\Exception;
|
|
|
use think\facade\Db;
|
|
use think\facade\Db;
|
|
|
|
|
+use app\common\enum\RefundEnum;
|
|
|
use app\common\logic\BaseLogic;
|
|
use app\common\logic\BaseLogic;
|
|
|
|
|
+use app\common\logic\RefundLogic;
|
|
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
|
|
|
+use app\common\model\refund\RefundRecord;
|
|
|
use app\common\model\works\GroupServiceWork;
|
|
use app\common\model\works\GroupServiceWork;
|
|
|
|
|
+use app\common\model\group_activity\GroupOrder;
|
|
|
use app\workerapi\logic\GroupServiceWorkLogLogic;
|
|
use app\workerapi\logic\GroupServiceWorkLogLogic;
|
|
|
|
|
+use app\common\model\group_activity\GroupUserOrder;
|
|
|
use app\common\model\master_worker\MasterWorkerTemporary;
|
|
use app\common\model\master_worker\MasterWorkerTemporary;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -44,6 +49,7 @@ class GroupServiceWorkLogic extends BaseLogic
|
|
|
GroupServiceWork::where('id', $params['id'])->update([
|
|
GroupServiceWork::where('id', $params['id'])->update([
|
|
|
'address' => $params['address'],
|
|
'address' => $params['address'],
|
|
|
'appointment_time' => strtotime($params['appointment_time']),
|
|
'appointment_time' => strtotime($params['appointment_time']),
|
|
|
|
|
+ 'remark' => $params['remark'],
|
|
|
]);
|
|
]);
|
|
|
Db::commit();
|
|
Db::commit();
|
|
|
return true;
|
|
return true;
|
|
@@ -358,7 +364,6 @@ class GroupServiceWorkLogic extends BaseLogic
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
$data['third_type'] = 2;
|
|
$data['third_type'] = 2;
|
|
|
- $data['work_status'] = 3;
|
|
|
|
|
$data['work_pay_status'] = 2;
|
|
$data['work_pay_status'] = 2;
|
|
|
$data['category_type'] = 2;
|
|
$data['category_type'] = 2;
|
|
|
$data['appointment_time'] = $data['appointment_time'] ? strtotime($data['appointment_time']) : 0;
|
|
$data['appointment_time'] = $data['appointment_time'] ? strtotime($data['appointment_time']) : 0;
|
|
@@ -376,4 +381,83 @@ class GroupServiceWorkLogic extends BaseLogic
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 退款
|
|
|
|
|
+ */
|
|
|
|
|
+ public static function refund($params,$userInfo){
|
|
|
|
|
+ Db::startTrans();
|
|
|
|
|
+ try {
|
|
|
|
|
+
|
|
|
|
|
+ $work = GroupServiceWork::findOrEmpty($params['id']);
|
|
|
|
|
+ if($work->isEmpty()){
|
|
|
|
|
+ throw new Exception('工单不存在');
|
|
|
|
|
+ }
|
|
|
|
|
+ if($work->work_status >=7 ){
|
|
|
|
|
+ throw new \Exception('工单已完结,不支持退款');
|
|
|
|
|
+ }
|
|
|
|
|
+ if(!$work->group_user_order_id ){
|
|
|
|
|
+ throw new \Exception('临时工单,不支持退款');
|
|
|
|
|
+ }
|
|
|
|
|
+ $order = GroupUserOrder::where(['id'=>$work->group_user_order_id])->findOrEmpty()->toArray();
|
|
|
|
|
+ if (empty($order)){
|
|
|
|
|
+ throw new \Exception('用户拼团订单不存在');
|
|
|
|
|
+ }
|
|
|
|
|
+ if ($order['refund_status'] != 0) {
|
|
|
|
|
+ throw new \Exception('用户拼团订单已退款');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //添加变更日志
|
|
|
|
|
+ $work_log = [
|
|
|
|
|
+ 'type' => 5,
|
|
|
|
|
+ 'work_id'=>$work->id,
|
|
|
|
|
+ 'master_worker_id'=>$work->master_worker_id,
|
|
|
|
|
+ 'opera_log'=>'后台用户['.$userInfo['admin_id'].']'.$userInfo['name'].'于'.date('Y-m-d H:i:s',time()).'执行退款'
|
|
|
|
|
+ ];
|
|
|
|
|
+ GroupServiceWorkLogLogic::add($work_log);
|
|
|
|
|
+
|
|
|
|
|
+ //退款
|
|
|
|
|
+ $work->work_status = 9;
|
|
|
|
|
+ $work->service_status = 5;
|
|
|
|
|
+ $work->save();
|
|
|
|
|
+
|
|
|
|
|
+ // 生成退款记录
|
|
|
|
|
+ $recordSn = generate_sn(RefundRecord::class, 'sn');
|
|
|
|
|
+ $record = RefundRecord::create([
|
|
|
|
|
+ 'sn' => $recordSn,
|
|
|
|
|
+ 'user_id' => $order['user_id'],
|
|
|
|
|
+ 'order_id' => $order['id'],
|
|
|
|
|
+ 'order_sn' => $order['sn'],
|
|
|
|
|
+ 'order_type' => RefundEnum::ORDER_TYPE_GROUP,
|
|
|
|
|
+ 'order_amount' => $order['order_amount'],
|
|
|
|
|
+ 'refund_amount' => $order['order_amount'],
|
|
|
|
|
+ 'refund_type' => RefundEnum::TYPE_ADMIN,
|
|
|
|
|
+ 'transaction_id' => $order['transaction_id'] ?? '',
|
|
|
|
|
+ 'refund_way' => RefundEnum::getRefundWayByPayWay($order['pay_way']),
|
|
|
|
|
+ ]);
|
|
|
|
|
+
|
|
|
|
|
+ //更新用户拼团订单
|
|
|
|
|
+ GroupUserOrder::where('id',$order['id'])->update(['status' => 2,'refund_status' => 1]);
|
|
|
|
|
+
|
|
|
|
|
+ //更新拼团订单
|
|
|
|
|
+ GroupOrder::where('id',$order['id'])->update([
|
|
|
|
|
+ 'num' => Db::raw('num-1')
|
|
|
|
|
+ ]);
|
|
|
|
|
+
|
|
|
|
|
+ // 退款
|
|
|
|
|
+ $result = RefundLogic::refund($order, $record['id'], $order['order_amount'], $userInfo['admin_id']);
|
|
|
|
|
+
|
|
|
|
|
+ if ($result !== true) {
|
|
|
|
|
+ throw new Exception(RefundLogic::getError());
|
|
|
|
|
+ Db::rollback();
|
|
|
|
|
+ return false;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ Db::commit();
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ }catch(\Exception $e){
|
|
|
|
|
+ Db::rollback();
|
|
|
|
|
+ self::setError($e->getMessage());
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|