CartDeleteForm.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\client\models\v1;
  8. use app\models\Cart;
  9. use app\modules\client\models\ApiModel;
  10. class CartDeleteForm extends ApiModel
  11. {
  12. public $store_id;
  13. public $user_id;
  14. public $cart_id_list;
  15. public function rules()
  16. {
  17. return [
  18. [['cart_id_list'], 'required'],
  19. ];
  20. }
  21. public function save($params = [])
  22. {
  23. if (!$this->validate()) {
  24. return $this->errorResponse;
  25. }
  26. try {
  27. $this->cart_id_list = json_decode($this->cart_id_list, true);
  28. $data = [];
  29. foreach ($this->cart_id_list as $cart_id) {
  30. $cart = Cart::findOne([
  31. 'store_id' => $this->store_id,
  32. 'is_delete' => 0,
  33. 'user_id' => $this->user_id,
  34. 'id' => $cart_id,
  35. ]);
  36. if (!$cart) {
  37. continue;
  38. }
  39. $cart->is_delete = 1;
  40. $cart->save();
  41. $data[] = [
  42. 'user_id' => $this->user_id,
  43. 'good_id' => $cart->goods_id,
  44. ];
  45. }
  46. return [
  47. 'code' => 0,
  48. 'msg' => '删除完成',
  49. ];
  50. } catch (\Exception $e) {
  51. }
  52. }
  53. }