OrderCance.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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::appiontOrderCancel($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. if(!empty($openid)){
  33. $msg = [
  34. $openid,$sn,'儿保预约',$price,$time,$pantient,$organization,'医生取消',$paystatus
  35. ];
  36. $miniMsg = [
  37. $openid,$sn,'医生取消','儿保预约',$paystatus
  38. ];
  39. //用户和医生都要发
  40. $ret = admin_send_wechat_message(1,$msg,$miniMsg);
  41. }
  42. DB::commit();
  43. } catch ( \Exception $e){
  44. DB::rollBack();
  45. return $this->response()->error('操作失败!');
  46. }
  47. if($res){
  48. return $this->response()->success('操作成功!')->refresh();
  49. }
  50. return $this->response()->error('操作失败!');
  51. }
  52. }