OrderCance.php 1.3 KB

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