OrderCance.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace App\Community\Actions\Nurse;
  3. use App\Models\Order;
  4. use App\Models\Organization;
  5. use App\Models\User;
  6. use Encore\Admin\Actions\RowAction;
  7. use Illuminate\Database\Eloquent\Model;
  8. use Illuminate\Support\Facades\DB;
  9. class OrderCance extends RowAction
  10. {
  11. public $name = '取消订单';
  12. public function handle(Model $model)
  13. {
  14. $id = $this->row->id;
  15. $order = Order::where(['id'=>$id])->with('orderUser')->first();
  16. $sn = $order->order_sn;
  17. // $openid = 'oYmUA5A1OIqtpA1XSrw35tbjtv1w';
  18. $time = $this->row->created_at;
  19. $price = ($this->row->total_amount / 100);
  20. $pantient = $this->row->orderPatient->name;
  21. $organization = Organization::where(['id'=>$this->row->organization_id])->value('name');
  22. $paystatus = Order::getPayStatus()[$this->row->payment_status];
  23. DB::beginTransaction();
  24. try {
  25. //退还余额
  26. $res = Order::orderCancel($id,'社区取消');
  27. if(empty($order->orderUser) || empty($order->orderUser->openid) ) {
  28. DB::commit();
  29. return $this->response()->success('操作成功!')->refresh();
  30. }
  31. $openid = $order->orderUser->openid;
  32. $msg = [
  33. $openid,$sn,'儿保预约',$price,$time,$pantient,$organization,'社区取消',$paystatus
  34. ];
  35. $miniMsg = [
  36. $openid,$sn,'社区取消','儿保预约',$paystatus
  37. ];
  38. //用户和医生都要发
  39. // $ret = admin_send_wechat_message(1,$msg,$miniMsg);
  40. DB::commit();
  41. } catch ( \Exception $e){
  42. dump($e->getMessage());
  43. DB::rollBack();
  44. return $this->response()->error('操作失败!');
  45. }
  46. if($res){
  47. return $this->response()->success('操作成功!')->refresh();
  48. }
  49. return $this->response()->error('操作失败!');
  50. }
  51. }