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. if(empty($openid)) return true;
  17. $time = $this->row->created_at;
  18. $price = (intval($this->row->total_amount) / 100);
  19. $pantient = $this->row->orderPatient->name;
  20. $organization = $this->row->organization->name;
  21. $paystatus = Order::getPayStatus()[$this->row->payment_status];
  22. DB::beginTransaction();
  23. try {
  24. //退还余额
  25. $res = Order::orderCancel($id,'社区取消');
  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. DB::commit();
  35. } catch ( \Exception $e){
  36. dd($e->getMessage());
  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. }