Ordercreate.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * Index.php
  4. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  5. * =========================================================
  6. * Copy right 2015-2025 杭州牛之云科技有限公司, 保留所有权利。
  7. * ----------------------------------------------
  8. * 官方网址: https://www.niushop.com
  9. * =========================================================
  10. * @author : niuteam
  11. * @date : 2022.8.8
  12. * @version : v5.0.0.1
  13. */
  14. namespace addon\giftcard\api\controller;
  15. use app\api\controller\BaseApi;
  16. use addon\giftcard\model\order\GiftCardOrderCreate as OrderCreateModel;
  17. /**
  18. * 订单创建
  19. * @author Administrator
  20. *
  21. */
  22. class Ordercreate extends BaseApi
  23. {
  24. /**
  25. * 创建订单
  26. */
  27. public function create()
  28. {
  29. $token = $this->checkToken();
  30. if ($token[ 'code' ] < 0) return $this->response($token);
  31. $order_create = new OrderCreateModel();
  32. $data = [
  33. 'giftcard_id' => $this->params[ 'giftcard_id' ] ?? 0,//礼包id
  34. 'num' => $this->params[ 'num' ] ?? 1,//商品数量(买几套)
  35. 'media_id' => $this->params[ 'media_id' ] ?? 0,
  36. 'card_cover' => $this->params[ 'card_cover' ] ?? '',
  37. 'site_id' => $this->site_id,//站点id
  38. 'member_id' => $this->member_id,
  39. 'order_from' => $this->params[ 'app_type' ],
  40. 'order_from_name' => $this->params[ 'app_type_name' ],
  41. 'buyer_message' => $this->params[ 'buyer_message' ] ?? '',
  42. ];
  43. if (empty($data[ 'giftcard_id' ])) {
  44. return $this->response($this->error('', '缺少必填参数商品数据'));
  45. }
  46. $res = $order_create->create($data);
  47. return $this->response($res);
  48. }
  49. /**
  50. * 计算信息
  51. */
  52. public function calculate()
  53. {
  54. $token = $this->checkToken();
  55. if ($token[ 'code' ] < 0) return $this->response($token);
  56. $order_create = new OrderCreateModel();
  57. $data = [
  58. 'giftcard_id' => $this->params[ 'giftcard_id' ] ?? 0,//礼包id
  59. 'num' => $this->params[ 'num' ] ?? 1,//商品数量(买几套)
  60. 'media_id' => $this->params[ 'media_id' ] ?? 0,
  61. 'card_cover' => $this->params[ 'card_cover' ] ?? '',
  62. 'site_id' => $this->site_id,//站点id
  63. 'member_id' => $this->member_id,
  64. 'order_from' => $this->params[ 'app_type' ],
  65. 'order_from_name' => $this->params[ 'app_type_name' ],
  66. 'buyer_message' => $this->params[ 'buyer_message' ] ?? '',
  67. ];
  68. if (empty($data[ 'giftcard_id' ])) {
  69. return $this->response($this->error('', '缺少必填参数商品数据'));
  70. }
  71. $res = $order_create->calculate($data);
  72. return $this->response($res);
  73. }
  74. }