|
@@ -3,6 +3,7 @@
|
|
|
namespace app\admin\service\order;
|
|
|
|
|
|
use app\model\Appointment;
|
|
|
+use app\model\MemberBenefit;
|
|
|
use support\Db;
|
|
|
use support\Request;
|
|
|
use function _PHPStan_cc8d35ffb\RingCentral\Psr7\str;
|
|
@@ -70,10 +71,12 @@ class AppointmentService
|
|
|
public static function update(Request $request)
|
|
|
{
|
|
|
$appointmentId = $request->post('appointment_id');
|
|
|
- if (!Appointment::where('appointment_id', $appointmentId)->exists()) {
|
|
|
+ $appointment = Appointment::where('appointment_id', $appointmentId)->first();
|
|
|
+ if (!$appointment) {
|
|
|
return json_fail("数据不存在");
|
|
|
}
|
|
|
$params = $request->post();
|
|
|
+ Db::beginTransaction();
|
|
|
try {
|
|
|
$data = [
|
|
|
'appointment_status'=>$params['appointment_status'],
|
|
@@ -86,9 +89,15 @@ class AppointmentService
|
|
|
];
|
|
|
|
|
|
Appointment::where('appointment_id', $appointmentId)->update($data);
|
|
|
+ // 如果是完成状态
|
|
|
+ if ($params['appointment_status'] == 'DONE' && $appointment->appointment_status != 'DONE'){
|
|
|
+ MemberBenefit::where('member_benefit_id',$appointment->join_appointment_member_benefit_id)->increment('member_benefit_used_count');
|
|
|
+ }
|
|
|
|
|
|
+ Db::commit();
|
|
|
return json_success("数据更新成功");
|
|
|
}catch (\Exception $e){
|
|
|
+ Db::rollBack();
|
|
|
dump($e->getMessage());
|
|
|
return json_fail("数据更新失败");
|
|
|
}
|