OrderCancel.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. if(empty($openid)) return true;
  16. //$openid = 'oYmUA5A1OIqtpA1XSrw35tbjtv1w';
  17. $time = $this->row->created_at;
  18. $price = (intval($this->row->price) / 100).'元';
  19. DB::beginTransaction();
  20. try {
  21. //退还余额
  22. $res = Order::orderCancel($id);
  23. $msg = [
  24. $openid,'/pages/index/index','您有一个订单已取消',$sn,'门诊订单',$price,$time,'社区取消','如有疑问请联系客服'
  25. ];
  26. $ret = send_wechat_message(9,$msg,'','');
  27. DB::commit();
  28. } catch ( \Exception $e){
  29. DB::rollBack();
  30. return $this->response()->error('操作失败!');
  31. }
  32. if($res){
  33. return $this->response()->success('操作成功!')->refresh();
  34. }
  35. return $this->response()->error('操作失败!');
  36. }
  37. }