Parcourir la source

新增自定义字段接口

chenxiqiang il y a 6 ans
Parent
révision
3b485a6706

+ 100
- 0
manage-server/app/Http/Controllers/OptionOrderController.php Voir le fichier

@@ -0,0 +1,100 @@
1
+<?php
2
+
3
+namespace App\Http\Controllers;
4
+
5
+use App\Models\OptionOrder;
6
+use App\Models\OptionValue;
7
+use App\Models\Classify;
8
+use Illuminate\Http\Request;
9
+
10
+
11
+class OptionOrderController extends Controller
12
+{
13
+    public $classify_map = [];
14
+    public $classify_name = [];
15
+
16
+    public function __construct() {
17
+        $classifies = Classify::all();
18
+        foreach ($classifies as $classify) {
19
+            $this->classify_map[$classify->id] = $classify;
20
+            $this->classify_name[$classify->name] = $classify;
21
+        }
22
+    }
23
+
24
+    public function store(Request $request) {
25
+
26
+        $wechat_id = $request->header("openid");
27
+
28
+        $option_ids = $request->input("options");
29
+        $id = $request->input("id");
30
+        $address = $request->input('address');
31
+        $contact = $request->input('contact');
32
+        $phone = $request->input('phone');
33
+        $notes = $request->input('notes');
34
+        $classify = $request->input('type');
35
+        $price = $request->input('price');
36
+        $status = $request->input('status');
37
+        $photo = $request->input('photo');
38
+
39
+        if($option_ids && $address && $contact && $phone && $classify) {
40
+            $kvs = [];
41
+            foreach ($option_ids as $option_id) {
42
+                $option_value = OptionValue::with("optionKey")->find($option_id);
43
+                $kvs[$option_value->optionKey->key] = $option_value->value;
44
+            }
45
+
46
+            if(!$id) {
47
+                $option_order = new OptionOrder;
48
+                $option_order->status = 0;
49
+                $option_order->price = 0;
50
+            } else {
51
+                $option_order = OptinOrder::find($id);
52
+                $option_order->status = $status;
53
+                $option_order->price = $price;
54
+            }
55
+            $option_order->address = $address;
56
+            $option_order->contact = $contact;
57
+            $option_order->phone = $phone;
58
+            $option_order->notes = $notes;
59
+            $option_order->classify = $classify;
60
+            $option_order->options = json_encode($kvs, JSON_UNESCAPED_UNICODE);
61
+            if($classify) {
62
+                $classify2 = $this->classify_name[$classify]->name;
63
+                $pid = $this->classify_name[$classify]->pid;
64
+                $classify1 = $this->classify_map[$pid]->name;
65
+                $option_order->classify1 = $classify1;
66
+                $option_order->classify2 = $classify2;
67
+                $option_order->classify = $this->classify_name[$classify]->id;
68
+            }
69
+            $option_order->wechat_id = $wechat_id;
70
+            $option_order->photo = $photo;
71
+
72
+            $option_order->save();
73
+            return Response()->json([
74
+                "status" => 0,
75
+                "message" => "保存成功"
76
+            ]);
77
+        } else {
78
+            return Response()->json([
79
+                "status" => -1,
80
+                "message" => "信息不能为空!",
81
+                "options" => $option_ids
82
+            ]);
83
+        }
84
+    }
85
+
86
+
87
+    /**
88
+     * 每页20进行分页
89
+     * @param Request $request
90
+     * @return mixed
91
+     */
92
+    public function list(Request $request)
93
+    {
94
+        $classify = $request->input("classify");
95
+        if($classify) {
96
+            return OptionOrder::where("classify", $classify)->paginate(20);
97
+        }
98
+        return OptionOrder::paginate(20);
99
+    }
100
+}

+ 24
- 0
manage-server/app/Models/OptionOrder.php Voir le fichier

@@ -0,0 +1,24 @@
1
+<?php
2
+
3
+namespace App\Models;
4
+
5
+use Illuminate\Database\Eloquent\Model;
6
+
7
+class OptionOrder extends Order
8
+{
9
+    function __construct() {
10
+        parent::__construct("option_order");
11
+        $fillable = [
12
+            'options',
13
+        ];
14
+        parent::mergeFillable(parent::getFillable(), $fillable);
15
+    }
16
+
17
+    /**
18
+     * 获取评论
19
+     */
20
+    public function comments()
21
+    {
22
+        return $this->hasMany('App\Comment');
23
+    }
24
+}

+ 45
- 0
manage-server/database/migrations/2018_09_23_094814_create_option_orders_table.php Voir le fichier

@@ -0,0 +1,45 @@
1
+<?php
2
+
3
+use Illuminate\Support\Facades\Schema;
4
+use Illuminate\Database\Schema\Blueprint;
5
+use Illuminate\Database\Migrations\Migration;
6
+
7
+class CreateOptionOrdersTable extends Migration
8
+{
9
+    /**
10
+     * Run the migrations.
11
+     *
12
+     * @return void
13
+     */
14
+    public function up()
15
+    {
16
+        Schema::create('option_orders', function (Blueprint $table) {
17
+            $table->increments('id');
18
+            $table->timestamps();
19
+            $table->string('wechat_id');
20
+            $table->string('options');
21
+            $table->string('contact');
22
+            $table->string('address');
23
+            $table->string('phone');
24
+            $table->integer('status');
25
+            $table->double('price');
26
+            $table->string('photo');
27
+            $table->string('notes');
28
+            $table->unsignedInteger('classify');
29
+            $table->string('classify1');
30
+            $table->string('classify2');
31
+            $table->unsignedInteger('comment_id');
32
+            $table->timestamp("paid_at");
33
+        });
34
+    }
35
+
36
+    /**
37
+     * Reverse the migrations.
38
+     *
39
+     * @return void
40
+     */
41
+    public function down()
42
+    {
43
+        Schema::dropIfExists('option_orders');
44
+    }
45
+}

Loading…
Annuler
Enregistrer