kphcdr 1 年之前
父节点
当前提交
dcf2868626

+ 50 - 0
app/Models/Cart.php

@@ -0,0 +1,50 @@
+<?php
+
+namespace App\Models;
+
+use App\Base\BaseModel;
+use Illuminate\Support\Arr;
+
+/**
+ * App\Models\Cart
+ *
+ * @property int                             $id
+ * @property int                             $user_id
+ * @property int                             $goods_id
+ * @property array                           $extra
+ * @property int                             $count
+ * @property \Illuminate\Support\Carbon|null $created_at
+ * @property \Illuminate\Support\Carbon|null $updated_at
+ * @method static \Illuminate\Database\Eloquent\Builder|Cart newModelQuery()
+ * @method static \Illuminate\Database\Eloquent\Builder|Cart newQuery()
+ * @method static \Illuminate\Database\Eloquent\Builder|Cart query()
+ * @method static \Illuminate\Database\Eloquent\Builder|Cart whereCount($value)
+ * @method static \Illuminate\Database\Eloquent\Builder|Cart whereCreatedAt($value)
+ * @method static \Illuminate\Database\Eloquent\Builder|Cart whereExtra($value)
+ * @method static \Illuminate\Database\Eloquent\Builder|Cart whereGoodsId($value)
+ * @method static \Illuminate\Database\Eloquent\Builder|Cart whereId($value)
+ * @method static \Illuminate\Database\Eloquent\Builder|Cart whereUpdatedAt($value)
+ * @method static \Illuminate\Database\Eloquent\Builder|Cart whereUserId($value)
+ * @mixin \Eloquent
+ * @property-read mixed                      $thumb
+ * @property-read mixed                      $goods_name
+ */
+class Cart extends BaseModel
+{
+
+    protected $table = "cart";
+
+    protected $casts = [
+        "extra" => "array",
+    ];
+
+    public function getThumbAttribute()
+    {
+        return Arr::get($this->extra, "thumb", "");
+    }
+
+    public function getGoodsNameAttribute()
+    {
+        return Arr::get($this->extra, "goods_name", "");
+    }
+}

+ 10 - 1
app/Modules/Mini/Controllers/UserController.php

@@ -3,6 +3,7 @@
 namespace App\Modules\Mini\Controllers;
 
 use App\Base\BaseController;
+use App\Models\User\UserAddress;
 use App\Models\User\UserFav;
 use App\Modules\Mini\Services\AddressService;
 use App\Modules\Mini\Services\CompanyService;
@@ -52,7 +53,15 @@ class UserController extends BaseController
 
     public function addressDel()
     {
-        return $this->ok();
+        $params = $this->valid([
+            "id" => "required",
+        ]);
+
+        $row = UserAddress::where("user_id", Auth::id())->where("id", $params['id'])->delete();
+
+        return $this->ok([
+            "row" => $row,
+        ]);
     }
 
     public function addressStore()

+ 34 - 0
database/migrations/2023_05_11_064203_create_cart_table.php

@@ -0,0 +1,34 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration {
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('cart', function (Blueprint $table) {
+            $table->id();
+            $table->unsignedInteger("user_id");
+            $table->unsignedInteger("goods_id");
+            $table->string("extra", 1000);
+            $table->unsignedInteger("count")->default(1);
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('cart');
+    }
+};