TestCart.Class.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace JinDouYun\Controller\Cart;
  3. use JinDouYun\Controller\BaseController;
  4. use JinDouYun\Model\Cart\MTestCart;
  5. use JinDouYun\Model\System\MEnterpriseBindPayment;
  6. use Mall\Framework\Core\ErrorCode;
  7. use Mall\Framework\Core\StatusCode;
  8. class TestCart extends BaseController
  9. {
  10. private $objMTestCart;
  11. /**
  12. * TestCart constructor.
  13. * @param bool $isCheckAcl
  14. * @param bool $isMustLogin
  15. * @throws \Exception
  16. */
  17. public function __construct($isCheckAcl = true, $isMustLogin = true)
  18. {
  19. parent::__construct($isCheckAcl, $isMustLogin);
  20. $thisChoiceCustomerId = $this->request->param('request_id');//当前选择的客户id
  21. $this->objMTestCart = new MTestCart($this->onlineUserId, $this->onlineEnterpriseId, false, $thisChoiceCustomerId);
  22. }
  23. /**
  24. * 添加购物车,公共字段
  25. *
  26. * @return array
  27. */
  28. public function commonFieldFilter()
  29. {
  30. $params = $this->request->getRawJson();
  31. if (!isset($params['goodsData'])) {
  32. parent::sendOutput('goodsData参数错误', ErrorCode::$paramError);
  33. }
  34. $goodsData = [];
  35. foreach ($params['goodsData'] as $key => $val) {
  36. $goodsData[$key] = [
  37. 'goodsBasicId' => isset($val['goodsBasicId']) ? $val['goodsBasicId'] : '',
  38. 'goodsId' => isset($val['goodsId']) ? $val['goodsId'] : '',
  39. 'skuId' => isset($val['skuId']) ? $val['skuId'] : '',
  40. 'buyNum' => isset($val['buyNum']) ? $val['buyNum'] : '',
  41. 'shopId' => isset($val['shopId']) ? $val['shopId'] : '',
  42. 'source' => isset($val['source']) ? $val['source'] : '',
  43. ];
  44. foreach ($goodsData[$key] as $k => $v) {
  45. if (empty($v)) {
  46. parent::sendOutput($k . '参数错误', ErrorCode::$paramError);
  47. }
  48. }
  49. $goodsData[$key]['goodsCode'] = createCode(StatusCode::$code['goodsBasic']['prefix'], $goodsData[$key]['goodsId'], StatusCode::$code['goodsBasic']['length']);
  50. }
  51. $cartData['goodsData'] = $goodsData;//过滤后数据
  52. return $cartData;
  53. }
  54. /**
  55. * 加入购物车
  56. * @throws \Exception
  57. */
  58. public function addCart()
  59. {
  60. $cartData = $this->commonFieldFilter();
  61. $result = $this->objMTestCart->addCart($cartData);
  62. if ($result->isSuccess()) {
  63. parent::sendOutput($result->getData());
  64. }
  65. parent::sendOutput($result->getData(), $result->getErrorCode());
  66. }
  67. }