| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- namespace addons\CloudStock\api\services;
- use addons\CloudStock\common\models\CloudStockFillCart;
- use addons\CloudStock\common\services\BaseService;
- use common\enums\StatusEnum;
- class CloudStockFillCartService extends BaseService
- {
- /**
- * 购物车数据
- *
- * @param array $goodsIds
- *
- * @return array
- */
- public function getCartList(array $goodsIds = []): array
- {
- $where = [
- ['mall_id' => $this->mall_id, 'user_id' => $this->user_id, 'status' => StatusEnum::ENABLED]
- ];
- if ($goodsIds) {
- $where[] = ['goods_id' => $goodsIds];
- }
- return CloudStockFillCart::lists(
- [
- 'where' => $where,
- 'select' => 'goods_id, num'
- ]
- );
- }
- /**
- * 购物车转为订单
- *
- * @return void
- */
- public function cart2Order(int $orderId)
- {
- CloudStockFillCart::updateAll(
- [
- 'status' => StatusEnum::DISABLED,
- 'order_id' => $orderId,
- 'updated_at' => time()
- ],
- [
- 'user_id' => $this->user_id,
- 'mall_id' => $this->mall_id,
- 'status' => StatusEnum::ENABLED,
- ]
- );
- }
- /**
- * 返回购物车汇总信息
- *
- * @return array
- */
- public function getCartInfo(): array
- {
- $res = [
- 'cart_list' => [],
- 'replenish_price' => 0,
- 'profit' => 0,
- ];
- $cartList = $this->getCartList();
- if (empty($cartList)) {
- return $res;
- }
- $res['cart_list'] = $cartList;
- $goodsPriceList = (new CloudStockGoodsService(['mall_id' => $this->mall_id, 'user_id' => $this->user_id, 'stock_agent' => $this->stock_agent]))
- ->getGoodsPrice($cartList);
- $res['replenish_price'] = $goodsPriceList['replenish_price'];
- $res['profit'] = $goodsPriceList['profit'];
- return $res;
- }
- }
|