| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\client\models\v1;
- use app\models\Cart;
- use app\modules\client\models\ApiModel;
- class CartDeleteForm extends ApiModel
- {
- public $store_id;
- public $user_id;
- public $cart_id_list;
- public function rules()
- {
- return [
- [['cart_id_list'], 'required'],
- ];
- }
- public function save($params = [])
- {
- if (!$this->validate()) {
- return $this->errorResponse;
- }
- try {
- $this->cart_id_list = json_decode($this->cart_id_list, true);
- $data = [];
- foreach ($this->cart_id_list as $cart_id) {
- $cart = Cart::findOne([
- 'store_id' => $this->store_id,
- 'is_delete' => 0,
- 'user_id' => $this->user_id,
- 'id' => $cart_id,
- ]);
- if (!$cart) {
- continue;
- }
- $cart->is_delete = 1;
- $cart->save();
- $data[] = [
- 'user_id' => $this->user_id,
- 'good_id' => $cart->goods_id,
- ];
- }
- return [
- 'code' => 0,
- 'msg' => '删除完成',
- ];
- } catch (\Exception $e) {
- }
- }
- }
|