OrderCance.php 1.6 KB

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