OrderCancel.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace App\Community\Actions\Clinc;
  3. use App\Models\Order;
  4. use Encore\Admin\Actions\RowAction;
  5. use Illuminate\Database\Eloquent\Model;
  6. use Illuminate\Support\Facades\DB;
  7. class OrderCancel extends RowAction
  8. {
  9. public $name = '取消订单';
  10. public function handle(Model $model)
  11. {
  12. $id = $this->row->id;
  13. $sn = $this->row->order_sn;
  14. $openid = $this->row->orderUser->openid;
  15. // $openid = 'oYmUA5A1OIqtpA1XSrw35tbjtv1w';
  16. $time = $this->row->created_at;
  17. $price = (intval($this->row->total_amount) / 100);
  18. $pantient = $this->row->orderPatient->name;
  19. $organization = $this->row->organization->name;
  20. $paystatus = Order::getPayStatus()[$this->row->payment_status];
  21. DB::beginTransaction();
  22. try {
  23. //退还余额
  24. $res = Order::appiontOrderCancel($id,'医生取消');
  25. if(!empty($openid)) {
  26. $msg = [
  27. $openid,$sn,'门诊预约',$price,$time,$pantient,$organization,'医生取消',$paystatus
  28. ];
  29. $miniMsg = [
  30. $openid,$sn,'医生取消','门诊预约',$paystatus
  31. ];
  32. //发送消息
  33. // $ret = admin_send_wechat_message(1,$msg,$miniMsg);
  34. }
  35. DB::commit();
  36. } catch ( Exception $e){
  37. DB::rollBack();
  38. return $this->response()->error('操作失败!');
  39. }
  40. if($res){
  41. return $this->response()->success('操作成功!')->refresh();
  42. }
  43. return $this->response()->error('操作失败!');
  44. }
  45. }