OrderCance.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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->order_id;
  15. $order = Order::where(['id'=>$id])->with('orderUser')->first();
  16. $sn = $order->order_sn;
  17. if(empty($order->orderUser) || empty($order->orderUser->openid) ) return true;
  18. $openid = $order->orderUser->openid;
  19. // $openid = 'oYmUA5A1OIqtpA1XSrw35tbjtv1w';
  20. $time = $this->row->created_at;
  21. $price = ($this->row->total_amount / 100);
  22. $pantient = $this->row->patients->name;
  23. $organization = Organization::where(['id'=>$this->row->orders->organization_id])->value('name');
  24. $paystatus = Order::getPayStatus()[$this->row->orders->payment_status];
  25. DB::beginTransaction();
  26. try {
  27. //退还余额
  28. $res = Order::orderCancel($id,'社区取消');
  29. $msg = [
  30. $openid,$sn,'儿保预约',$price,$time,$pantient,$organization,'社区取消',$paystatus
  31. ];
  32. $miniMsg = [
  33. $openid,$sn,'社区取消','儿保预约',$paystatus
  34. ];
  35. //用户和医生都要发
  36. $ret = admin_send_wechat_message(1,$msg,$miniMsg);
  37. DB::commit();
  38. } catch ( \Exception $e){
  39. dump($e->getMessage());
  40. DB::rollBack();
  41. return $this->response()->error('操作失败!');
  42. }
  43. if($res){
  44. return $this->response()->success('操作成功!')->refresh();
  45. }
  46. return $this->response()->error('操作失败!');
  47. }
  48. }