Order.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace app\api\controller\plus\lottery;
  3. use app\api\controller\Controller;
  4. use app\api\model\plus\lottery\Order as OrderModel;
  5. use app\api\model\product\Product as ProductModel;
  6. use app\api\model\plus\lottery\Record as RecordModel;
  7. /**
  8. *
  9. * 转盘商品订单控制器
  10. *
  11. */
  12. class Order extends Controller
  13. {
  14. /**
  15. * 记录详情
  16. */
  17. public function buy($record_id)
  18. {
  19. $detail = RecordModel::detail($record_id);
  20. $params = $this->request->param();
  21. $user = $this->getUser();
  22. $model = new OrderModel();
  23. if ($this->request->isGet()) {
  24. if ($detail['prize_type'] != 3) {
  25. return $this->renderError('礼品类型错误');
  26. }
  27. if ($detail['status'] == 1) {
  28. return $this->renderError('礼品已兑换');
  29. }
  30. $data = $model->getOrderData($params, $user);
  31. $data['product'] = (new ProductModel)->getProduct([$detail['award_id']]);
  32. return $this->renderSuccess('', compact('data'));
  33. }
  34. if ($model->addOrder($params, $this->getUser())) {
  35. return $this->renderSuccess('兑换成功');
  36. }
  37. return $this->renderError($model->getError() ?: '兑换失败');
  38. }
  39. }