Other.php
6.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<?php
/**
+-----------------------------------------------------------------------------------------------------------------------
* Steps 表单: Goods Step Form-分类
+-----------------------------------------------------------------------------------------------------------------------
* PHP version 7
*
* @category App\Admin\Forms\Steps\Goods
* @package App\Admin\Forms\Steps\Goods
* @author Richer <yangzi1028@163.com>
* @date 2022年5月7日15:14:47
* @copyright 2020-2022 Richer (http://www.Richer.com/)
* @license http://www.Richer.com/ License
* @link http://www.Richer.com/
*/
namespace App\Admin\Forms\Steps\Goods;
use App\Admin\Traits\FormFieldTrait;
use App\Models\Goods\Goods;
use App\Models\Goods\GoodsCategory;
use App\Admin\Rewrite\Widgets\StepForm;
use Encore\Admin\Facades\Admin;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
/**
* Class Other
*
* @category App\Admin\Forms\Steps\Goods
* @package App\Admin\Forms\Steps\Goods
* @author Richer <yangzi1028@163.com>
* @date 2022年5月7日15:14:47
* @copyright 2020-2022 Richer (http://www.Richer.com/)
* @license http://www.Richer.com/ License
* @link http://www.Richer.com/
*/
class Other extends StepForm
{
use FormFieldTrait;
/**
* The form title.
*
* @var string
*/
public $title = '详细信息';
/**
* The form.
*
* @var string
*/
public $form = null;
public $suffix = 'goods';
/**
* Other constructor.
* @param array $data
*/
public function __construct($data = [])
{
$this->model = new Goods();
$this->form = $this;
parent::__construct($data);
}
/**
* The form title.
*
* @var string
*/
public $model = null;
/**
* Handle the form request.
*
* @param Request $request
*
* @return \Illuminate\Http\RedirectResponse
*/
public function handle(Request $request)
{
$this->save($request);
$this->clear();
admin_toastr(trans('admin.save_succeeded'));
$route_prefix = config('admin.route.prefix');
$url = '/'.$route_prefix.'/'.$this->suffix;
return redirect($url);
}
/**
* Build a form here.
*/
public function form()
{
Admin::script(' $(".step-submit").on("click", function() {$(this).text("Loading...").addClass("disabled");});');
$id = $this->getId() ;
if ($id) {
$this->hidden('id')->default($this->getId());
}
// 渲染视频字段域
$this->formVideoField('video', '视频');
$this->formSingleImageField('cover_image', '商品封面图', 0, 1, 1);
$this->formMultipleImageField('images', '商品主图', 0, 1, 1);
$this->formTextField('origin_place', __('origin_place'), 100, 1, 2);
$this->formTextField('shipment_place', __('shipment_place'), 100, 1, 2);
$this->formTextAreaField('server', __('server'), 255, 3);
$this->formTextAreaField('non_delivery_area', __('non_delivery_area'), 255, 3);
$this->formRichTextField();
$this->formTextAreaField();
$this->formCommonFields();
// 设置专用字段
$this->renderSpecialFields();
}
/**
* 渲染不同模块的特殊字段
*/
public function renderSpecialFields()
{
}
/**
* The data of the form.
*
* @return array $data
*/
public function data()
{
return optional($this->getBase())->toArray();
}
/**
* 获取 id
*
* @return int|null
*/
private function getId()
{
return optional($this->getBase())->id;
}
/**
* 获取基础信息模型对象
*
* @return array
*/
protected function getBase()
{
return Arr::get(session('steps'), 'base');
}
/**
* 保存方案:新增或者更新
*
* @param $request
* @return mixed
*/
public function save($request)
{
$id = $request->id;
// 获取信息
$data = $request->all();
// 封面图
if (array_key_exists('url_cover_image', $data)) {
$image = $request->url_cover_image;
if ($image && $image !== 'undefined' && $image !== 'null') {
$data['cover_image'] = substr_file_path($image);
}
unset($data['url_cover_image']);
}
if (array_key_exists('images', $data)) {
$images = array_filter($request->images);
if ($images && is_array($images)) {
$data['images'] = my_json_encode(substr_file_path($images));
}
}
if (array_key_exists('url_images', $data)) {
$images = array_filter($request->url_images);
if ($images && is_array($images)) {
$data['images'] = my_json_encode(substr_file_path($images));
}
unset($data['url_images']);
}
if (array_key_exists('name_images', $data)) {
unset($data['name_images']);
}
if (array_key_exists('file', $data)) {
unset($data['file']);
}
// $model['facility'] = implode(',', array_filter(Arr::get($model, 'facility')));
// $model['tags'] = $request->tags;//implode(',', array_filter(Arr::get($model, 'tags') ?? []));
// 设置上架
$data['unshelved_status'] = config('constants.SHELVED');
$data['unshelved_opinion'] = '';
$data['unshelved_at'] = null;
$data['unshelved_by'] = 0;
$model = $this->model->find($id);
if ($model) {
// $model->video = request('video');
$model->video = Arr::get($data, 'video');
$model->cover_image = Arr::get($data, 'cover_image');
$model->images = Arr::get($data, 'images');
$model->origin_place = request('origin_place');
$model->shipment_place = request('shipment_place');
$model->server = request('server');
$model->non_delivery_area = request('non_delivery_area');
$model->body = request('body');
$model->non_delivery_area = request('description');
$model->unshelved_status = config('constants.SHELVED');
$model->unshelved_opinion = '';
$model->unshelved_at = null;
$model->unshelved_by = 0;
$model->save();
}
// $this->model->where('id', $id)->update($data);
return true;
}
}