15 changed files with 337 additions and 104 deletions
-
8MySQL_change.sql
-
80app/AdminAgent/Controllers/AgentProductController.php
-
14app/AdminAgent/Controllers/OrderController.php
-
27app/AdminAgent/Forms/LoadSupplierSpec.php
-
21app/AdminSupplier/Controllers/ProductController.php
-
7app/Http/Controllers/Api/AgentProductController.php
-
119app/Http/Controllers/Api/OrderController.php
-
5app/Http/Controllers/Api/WxpayController.php
-
5app/Models/AgentProduct.php
-
29app/Models/AgentProductSpec.php
-
2app/Models/ProductSpec.php
-
78resources/js/batch-add-spec.js
-
43resources/js/select-supplier-product-change.js
-
1resources/lang/zh_CN/agent-product.php
-
2resources/views/admin/form/hasmanytable.blade.php
@ -0,0 +1,27 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\AdminAgent\Forms; |
||||
|
|
||||
|
use App\Models\ProductSpec; |
||||
|
use Dcat\Admin\Widgets\Form; |
||||
|
use Dcat\Admin\Traits\LazyWidget; |
||||
|
use Dcat\Admin\Contracts\LazyRenderable; |
||||
|
|
||||
|
class LoadSupplierSpec extends Form implements LazyRenderable |
||||
|
{ |
||||
|
use LazyWidget; |
||||
|
|
||||
|
// 处理请求
|
||||
|
public function handle(array $input) |
||||
|
{ |
||||
|
$id = $input['id']; |
||||
|
$spec = ProductSpec::where('product_id', $id)->get()->toArray(); |
||||
|
|
||||
|
return $this->response()->data($spec); |
||||
|
} |
||||
|
|
||||
|
public function form() |
||||
|
{ |
||||
|
$this->hidden('id'); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,29 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Models; |
||||
|
|
||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory; |
||||
|
use Illuminate\Database\Eloquent\Model; |
||||
|
|
||||
|
class AgentProductSpec extends Model |
||||
|
{ |
||||
|
use HasFactory; |
||||
|
|
||||
|
protected $guarded = ['id']; |
||||
|
|
||||
|
public function __construct(array $attributes = []) |
||||
|
{ |
||||
|
parent::__construct($attributes); |
||||
|
$this->timestamps = false; |
||||
|
} |
||||
|
|
||||
|
public function agentProduct() |
||||
|
{ |
||||
|
return $this->belongsTo(AgentProduct::class); |
||||
|
} |
||||
|
|
||||
|
public function productSpec() |
||||
|
{ |
||||
|
return $this->belongsTo(ProductSpec::class); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,78 @@ |
|||||
|
Date.prototype.format = function(fmt) { |
||||
|
var o = { |
||||
|
"M+" : this.getMonth()+1, //月份
|
||||
|
"d+" : this.getDate(), //日
|
||||
|
"h+" : this.getHours(), //小时
|
||||
|
"m+" : this.getMinutes(), //分
|
||||
|
"s+" : this.getSeconds(), //秒
|
||||
|
"q+" : Math.floor((this.getMonth()+3)/3), //季度
|
||||
|
"S" : this.getMilliseconds() //毫秒
|
||||
|
}; |
||||
|
if(/(y+)/.test(fmt)) { |
||||
|
fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); |
||||
|
} |
||||
|
for(var k in o) { |
||||
|
if(new RegExp("("+ k +")").test(fmt)){ |
||||
|
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length))); |
||||
|
} |
||||
|
} |
||||
|
return fmt; |
||||
|
} |
||||
|
|
||||
|
$(function() { |
||||
|
$(".has-many-spec .add.btn") |
||||
|
.after('<div class="btn btn-spec batch-sub btn-primary btn-outline btn-sm" style="margin-left:10px;"><i class="feather icon-minus"></i> 删除所有</div>') |
||||
|
.after('<div class="btn btn-spec batch-add btn-primary btn-outline btn-sm" style="margin-left:10px;"><i class="feather icon-plus"></i> 批量新增</div>'); |
||||
|
|
||||
|
//批量新增
|
||||
|
$(".has-many-spec .batch-add").click(function() { |
||||
|
var name = prompt("请输入规格名称"); |
||||
|
if(!name) return; |
||||
|
|
||||
|
var num = parseInt(prompt("请输入新增数量,最多只能是100", 30)); |
||||
|
if(isNaN(num) || !num) return; |
||||
|
if(num > 100) num = 100; |
||||
|
|
||||
|
var date = new Date(); |
||||
|
date = prompt("请输入起始日期", date.format("yyyy-MM-dd")); |
||||
|
if(!date) return; |
||||
|
|
||||
|
var stock = prompt("请输入默认库存", 9999); |
||||
|
if(!stock) return; |
||||
|
|
||||
|
var original_price = prompt("请输入默认原价"); |
||||
|
if(!original_price) return; |
||||
|
|
||||
|
var price = prompt("请输入默认售价"); |
||||
|
if(!price) return; |
||||
|
|
||||
|
$("template.spec-tpl .field_name").prop("value", name); |
||||
|
var html = $("template.spec-tpl").html() |
||||
|
|
||||
|
var fields = {'name' : name, 'date' : date, 'stock' : stock, 'original_price' : original_price, 'price' : price}; |
||||
|
for(var key in fields) { |
||||
|
html = html.replace('name="spec[new___LA_KEY__][' + key + ']" value=""', 'name="spec[new___LA_KEY__][' + key + ']" value="' + fields[key] + '"'); |
||||
|
} |
||||
|
|
||||
|
var nestedIndex = $(".has-many-spec-forms tr").length - 1; |
||||
|
function replaceNestedFormIndex(value) { |
||||
|
return String(value).replace(/__LA_KEY__/g, nestedIndex); |
||||
|
} |
||||
|
|
||||
|
for(var i=0; i<num; i++) { |
||||
|
nestedIndex++; |
||||
|
|
||||
|
var d = new Date(date); |
||||
|
d.setDate(d.getDate() + i); |
||||
|
|
||||
|
var template = replaceNestedFormIndex(html.replace(date, d.format('yyyy-MM-dd'))); |
||||
|
$(".has-many-spec-forms").append(template); |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
//清空全部
|
||||
|
$(".has-many-spec .batch-sub").click(function() { |
||||
|
$(".has-many-spec-forms .remove.btn").click(); |
||||
|
console.log(123213) |
||||
|
}); |
||||
|
}); |
||||
@ -0,0 +1,43 @@ |
|||||
|
$(function () { |
||||
|
var template = $('template.spec-tpl').html(); |
||||
|
$('input[name="product_id"]').change(function () { |
||||
|
$.ajax({ |
||||
|
url: '{{url}}', |
||||
|
method: 'POST', |
||||
|
data: {id: $(this).val(), _form_: '{{class}}'}, |
||||
|
success: function (res) { |
||||
|
var fields = { |
||||
|
name: 'name', |
||||
|
date: 'date', |
||||
|
supplier_price: 'price', |
||||
|
supplier_stock: 'stock', |
||||
|
price: 'price', |
||||
|
stock: 'stock', |
||||
|
original_price: 'original_price', |
||||
|
product_spec_id: 'id' |
||||
|
}; |
||||
|
var data = res.data; |
||||
|
var forms = $('.has-many-spec-forms'); |
||||
|
forms.html(''); |
||||
|
for (var key in data) { |
||||
|
var row = $(template.replace(/new___LA_KEY__/g, key)); |
||||
|
for(var key2 in fields) { |
||||
|
var value = fields[key2], insert_value; |
||||
|
if (key2 === 'original_price') { |
||||
|
insert_value = data[key][value] * 2; |
||||
|
} else if (key2 === 'price') { |
||||
|
insert_value = data[key][value] * 1.5; |
||||
|
} else { |
||||
|
insert_value = data[key][value]; |
||||
|
} |
||||
|
row.find('input.field_' + key2).val(insert_value); |
||||
|
} |
||||
|
forms.append(row); |
||||
|
} |
||||
|
}, |
||||
|
error: function () { |
||||
|
Dcat.error('服务器出现未知错误,获取供应商产品规格失败'); |
||||
|
} |
||||
|
}); |
||||
|
}); |
||||
|
}); |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue