OrderCance.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace App\Community\Actions\Nurse;
  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->order_id;
  14. $order = Order::where(['id'=>$id])->with('orderUser')->first();
  15. $sn = $order->order_sn;
  16. if(empty($order->orderUser) || empty($order->orderUser->openid) ) return true;
  17. $openid = $order->orderUser->openid;
  18. //$openid = 'oYmUA5A1OIqtpA1XSrw35tbjtv1w';
  19. $time = $this->row->created_at;
  20. $price = (intval($this->row->price) / 100).'元';
  21. DB::beginTransaction();
  22. try {
  23. //退还余额
  24. $res = Order::orderCancel($id,'社区取消');
  25. $msg = [
  26. $openid,'/pages/index/index','您有一个订单已取消',$sn,'儿保订单',$price,$time,'社区取消','如有疑问请联系客服'
  27. ];
  28. $ret = send_wechat_message(9,$msg,'','');
  29. DB::commit();
  30. } catch ( \Exception $e){
  31. dump($e->getMessage());
  32. DB::rollBack();
  33. return $this->response()->error('操作失败!');
  34. }
  35. if($res){
  36. return $this->response()->success('操作成功!')->refresh();
  37. }
  38. return $this->response()->error('操作失败!');
  39. }
  40. }