feat: 批量购买
This commit is contained in:
@@ -6,8 +6,11 @@ namespace app\index\controller;
|
||||
use app\index\model\AgentBusinessTypeModel;
|
||||
use app\index\model\AgentEnterpriseSizeTypeModel;
|
||||
use app\index\model\AgentModel;
|
||||
use app\index\model\BulkPurchaseInquiryModel;
|
||||
use app\index\model\LeaveMessageModel;
|
||||
use app\index\model\SysBannerModel;
|
||||
use app\index\model\SysConfigModel;
|
||||
use app\index\validate\ContactUsBulkBuyValidate;
|
||||
use app\index\validate\ContactUsDistributorValidate;
|
||||
use app\index\validate\ContactUsMessageValidate;
|
||||
use think\facade\View;
|
||||
@@ -173,4 +176,63 @@ class ContactUs extends Common
|
||||
|
||||
return View::fetch('distributor');
|
||||
}
|
||||
|
||||
/**
|
||||
* 留言批量购买
|
||||
*/
|
||||
public function bulkbuy()
|
||||
{
|
||||
if (request()->isPost()) {
|
||||
// 提交留言处理
|
||||
$form_data = request()->post([
|
||||
'corp_name',
|
||||
'url',
|
||||
'first_name',
|
||||
'last_name',
|
||||
'email',
|
||||
'phone',
|
||||
'interested',
|
||||
'message'
|
||||
]);
|
||||
|
||||
// 验证字段
|
||||
$validate = new ContactUsBulkBuyValidate;
|
||||
if (!$validate->check($form_data)) {
|
||||
return error($validate->getError());
|
||||
}
|
||||
|
||||
// 保存留言
|
||||
$ret = BulkPurchaseInquiryModel::create([
|
||||
'language_id' => $this->lang_id,
|
||||
'corp_name' => $form_data['corp_name'],
|
||||
'url' => $form_data['url'],
|
||||
'first_name' => $form_data['first_name'],
|
||||
'last_name' => $form_data['last_name'],
|
||||
'email' => $form_data['email'],
|
||||
'phone' => $form_data['phone'],
|
||||
'interested' => $form_data['interested'],
|
||||
'referer_url' => request()->header('referer'),
|
||||
'website_url' => request()->header('host'),
|
||||
'message' => $form_data['message'],
|
||||
'ip' => request()->ip(),
|
||||
]);
|
||||
if ($ret->isEmpty()) {
|
||||
return error(lang('contact_bulkbuy.send_fail'));
|
||||
}
|
||||
return success(lang('contact_bulkbuy.send_success'));
|
||||
}
|
||||
|
||||
// 获取可选产品品类配置
|
||||
$config = SysConfigModel::hasWhere('group', function($query) {
|
||||
$query->where('language_id', '=', $this->lang_id);
|
||||
})
|
||||
->byName('bulk_purchase_inquiry_interested')
|
||||
->find();
|
||||
if (empty($config)) {
|
||||
return error('当前选定语言的采购可选品类配置出错');
|
||||
}
|
||||
View::assign('interested', explode(',', preg_replace('/\r?\n/', ',', $config->value)));
|
||||
|
||||
return View::fetch('bulkbuy');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,5 +119,42 @@ return [
|
||||
// 返回文本
|
||||
'send_success' => 'Add Success!',
|
||||
'send_fail' => 'Add Fail!',
|
||||
]
|
||||
],
|
||||
'contact_bulkbuy' => [
|
||||
'title' => '',
|
||||
'form_title' => 'Bulk Buy',
|
||||
'form_corp_name_label' => 'Company Name',
|
||||
'form_corp_name_placeholder' => 'Legal business name',
|
||||
'form_website_url_label' => 'Official website',
|
||||
'form_website_url_placeholder' => 'Please paste the URL',
|
||||
'form_username_label' => 'Your Name',
|
||||
'form_firstname_placeholder' => 'First name',
|
||||
'form_lastname_placeholder' => 'Last name',
|
||||
'form_email_label' => 'Email',
|
||||
'form_email_placeholder' => 'Please enter your email',
|
||||
'form_phone_label' => 'Phone Numbe',
|
||||
'form_phone_placeholder' => 'Please enter your phone number',
|
||||
'form_checkbox_label' => 'Products you are interested in?',
|
||||
'form_message_label' => 'Message',
|
||||
'form_message_placeholder' => 'Methods used',
|
||||
'form_submit' => 'SUBMIT',
|
||||
// 验证器中文本
|
||||
'validate_corp_name_require' => 'Company Name is required',
|
||||
'validate_corp_name_max' => 'Company Name cannot exceed 128 characters',
|
||||
'validate_url_max' => 'URL cannot exceed 255 characters',
|
||||
'validate_first_name_require' => 'First Name is required',
|
||||
'validate_first_name_max' => 'First Name cannot exceed 64 characters',
|
||||
'validate_last_name_require' => 'Last Name is required',
|
||||
'validate_last_name_max' => 'Last Name cannot exceed 64 characters',
|
||||
'validate_email_require' => 'Email is required',
|
||||
'validate_email_email' => 'Email format is incorrect',
|
||||
'validate_email_max' => 'Email cannot exceed 128 characters',
|
||||
'validate_phone_max' => 'Phone Number cannot exceed 32 characters',
|
||||
'validate_interested_max' => 'Interested in cannot exceed 255 characters',
|
||||
'validate_message_require' => 'Message is required',
|
||||
'validate_message_max' => 'Message cannot exceed 1024 characters',
|
||||
// 返回文本
|
||||
'send_success' => 'Add Success!',
|
||||
'send_fail' => 'Add Fail!',
|
||||
],
|
||||
];
|
||||
@@ -119,5 +119,42 @@ return [
|
||||
// 返回文本
|
||||
'send_success' => '信息已成功提交',
|
||||
'send_fail' => '信息提交失败',
|
||||
]
|
||||
],
|
||||
'contact_bulkbuy' => [
|
||||
'title' => '商务订单',
|
||||
'form_title' => '批量购买',
|
||||
'form_corp_name_label' => '公司名称',
|
||||
'form_corp_name_placeholder' => '法定营业名称',
|
||||
'form_website_url_label' => '官方网站',
|
||||
'form_website_url_placeholder' => '请粘贴网址',
|
||||
'form_username_label' => '姓名',
|
||||
'form_firstname_placeholder' => '名',
|
||||
'form_lastname_placeholder' => '姓',
|
||||
'form_email_label' => '电子邮箱',
|
||||
'form_email_placeholder' => '请输入邮箱',
|
||||
'form_phone_label' => '电话号码',
|
||||
'form_phone_placeholder' => '请输入电话号码',
|
||||
'form_checkbox_label' => '您对哪个产品品类感兴趣?',
|
||||
'form_message_label' => '留言',
|
||||
'form_message_placeholder' => '请输入留言',
|
||||
'form_submit' => '提交',
|
||||
// 验证器中文本
|
||||
'validate_corp_name_require' => '公司名称不能为空',
|
||||
'validate_corp_name_max' => '公司名称不能超过128个字符',
|
||||
'validate_url_max' => '网址不能超过255个字符',
|
||||
'validate_first_name_require' => '名不能为空',
|
||||
'validate_first_name_max' => '名不能超过64个字符',
|
||||
'validate_last_name_require' => '姓不能为空',
|
||||
'validate_last_name_max' => '姓不能超过64个字符',
|
||||
'validate_email_require' => '邮箱不能为空',
|
||||
'validate_email_email' => '邮箱格式不正确',
|
||||
'validate_email_max' => '邮箱不能超过128个字符',
|
||||
'validate_phone_max' => '电话号码不能超过32个字符',
|
||||
'validate_interested_max' => '感兴趣的产品种类不能超过255个字符',
|
||||
'validate_message_require' => '留言内容不能为空',
|
||||
'validate_message_max' => '留言内容不能超过1024个字符',
|
||||
// 返回文本
|
||||
'send_success' => '信息已成功提交',
|
||||
'send_fail' => '信息提交失败',
|
||||
],
|
||||
];
|
||||
15
app/index/model/BulkPurchaseInquiryModel.php
Normal file
15
app/index/model/BulkPurchaseInquiryModel.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\index\model;
|
||||
|
||||
use app\common\model\BulkPurchaseInquiryBaseModel;
|
||||
|
||||
/**
|
||||
* 批量购买询单模型
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class BulkPurchaseInquiryModel extends BulkPurchaseInquiryBaseModel
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -22,4 +22,10 @@ class SysConfigModel extends SysConfigBaseModel
|
||||
{
|
||||
return $this->belongsTo(SysConfigGroupModel::class, 'group_id', 'id');
|
||||
}
|
||||
|
||||
// 所属名称标识范围查询
|
||||
public function scopeByName($query, $name)
|
||||
{
|
||||
$query->where('name', '=', $name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +70,10 @@ Route::group('contactus', function() {
|
||||
Route::get('distributor', 'ContactUs/distributor');
|
||||
// 提交留言成为分销商
|
||||
Route::post('distributor', 'ContactUs/distributor');
|
||||
// 留言批量购买
|
||||
Route::get('bulkbuy', 'ContactUs/bulkbuy');
|
||||
// 提交留言批量购买
|
||||
Route::post('bulkbuy', 'ContactUs/bulkbuy');
|
||||
});
|
||||
// 数据迁移
|
||||
Route::get('/data/migration', 'DataMigration/index');
|
||||
|
||||
49
app/index/validate/ContactUsBulkBuyValidate.php
Normal file
49
app/index/validate/ContactUsBulkBuyValidate.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\index\validate;
|
||||
|
||||
use think\Validate;
|
||||
|
||||
class ContactUsBulkBuyValidate extends Validate
|
||||
{
|
||||
/**
|
||||
* 定义验证规则
|
||||
* 格式:'字段名' => ['规则1','规则2'...]
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $rule = [
|
||||
'corp_name' => 'require|max:128',
|
||||
'url' => 'max:255',
|
||||
'first_name' => 'require|max:64',
|
||||
'last_name' => 'require|max:64',
|
||||
'email' => 'require|email|max:128',
|
||||
'phone' => 'max:32',
|
||||
'interested' => 'max:255',
|
||||
'message' => 'require|max:1024',
|
||||
];
|
||||
|
||||
/**
|
||||
* 定义错误信息
|
||||
* 格式:'字段名.规则名' => '错误信息'
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $message = [
|
||||
'corp_name.require' => 'valudate_corp_name_require',
|
||||
'corp_name.max' => 'valudate_corp_name_max',
|
||||
'url.max' => 'valudate_url_max',
|
||||
'first_name.require' => 'valudate_first_name_require',
|
||||
'first_name.max' => 'valudate_first_name_max',
|
||||
'last_name.require' => 'valudate_last_name_require',
|
||||
'last_name.max' => 'valudate_last_name_max',
|
||||
'email.require' => 'valudate_email_require',
|
||||
'email.email' => 'valudate_email_email',
|
||||
'email.max' => 'valudate_email_max',
|
||||
'phone.max' => 'valudate_phone_max',
|
||||
'interested.max' => 'valudate_interested_max' ,
|
||||
'message.require' => 'valudate_message_require',
|
||||
'message.max' => 'valudate_message_max',
|
||||
];
|
||||
}
|
||||
104
app/index/view/contact_us/bulkbuy.html
Normal file
104
app/index/view/contact_us/bulkbuy.html
Normal file
@@ -0,0 +1,104 @@
|
||||
{extend name="public/base" /}
|
||||
{block name="title"}
|
||||
{notempty name=":lang('contact_bulkbuy.title')"}<title>{:lang('contact_bulkbuy.title')}</title>{else /}{__BLOCK__}{/notempty}
|
||||
{/block}
|
||||
{block name="style"}
|
||||
<link rel="stylesheet" href="__CSS__/contactus_bulkbuy.css">
|
||||
{/block}
|
||||
{block name="main"}
|
||||
<div class="orico_Page_bussiness">
|
||||
<!--首内容 -->
|
||||
<div class="bussinessMain">
|
||||
<form class="bd_main" action="" method="post">
|
||||
<h1 class="sfbt1">{:lang('contact_bulkbuy.form_title')}</h1>
|
||||
<!--内容-->
|
||||
<div class="bd_ct ">
|
||||
<div class="bd_from" style="padding: 0 300px;">
|
||||
<div class="theit">
|
||||
<div class="bditem">
|
||||
<label class="itlable">{:lang('contact_bulkbuy.form_corp_name_label')}<span class="redtag">*</span></label>
|
||||
<input type="text" class="form-control itinp" placeholder="{:lang('contact_bulkbuy.form_corp_name_placeholder')}" name="corp_name" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="theit">
|
||||
<div class="bditem">
|
||||
<label class="itlable">{:lang('contact_bulkbuy.form_website_url_label')}</label>
|
||||
<input type="text" class="form-control itinp" placeholder="{:lang('contact_bulkbuy.form_website_url_placeholder')}" name="url" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="theit">
|
||||
<div class="bditem">
|
||||
<label class="itlable">{:lang('contact_bulkbuy.form_username_label')}<span class="redtag">*</span></label>
|
||||
<input type="text" class="form-control itinp" placeholder="{:lang('contact_bulkbuy.form_firstname_placeholder')}" name="first_name" />
|
||||
</div>
|
||||
<div class="bditem">
|
||||
<label class="itlable"> </label>
|
||||
<input type="text" class="form-control itinp" placeholder="{:lang('contact_bulkbuy.form_lastname_placeholder')}" name="last_name" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="theit">
|
||||
<div class="bditem">
|
||||
<label class="itlable">{:lang('contact_bulkbuy.form_email_label')}<span class="redtag">*</span></label>
|
||||
<input type="email" class="form-control itinp" placeholder="{:lang('contact_bulkbuy.form_email_placeholder')}" name="email" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="theit">
|
||||
<div class="bditem bditem1">
|
||||
<label class="itlable">{:lang('contact_bulkbuy.form_phone_label')}</label>
|
||||
<input type="text" class="form-control itinp" placeholder="{:lang('contact_bulkbuy.form_phone_placeholder')}" name="phone" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="theit">
|
||||
<div class="bditem bditem1">
|
||||
<label class="itlable">{:lang('contact_bulkbuy.form_checkbox_label')}</label>
|
||||
<div class="sfbchecks">
|
||||
<div class="sfbcheckboxlist">
|
||||
{notempty name="interested"}
|
||||
{volist name="interested" id="it"}
|
||||
<label class="cit">
|
||||
<input name="interested" type="checkbox" value="{$it}" class="sfbcheckboxit" />{$it}
|
||||
</label>
|
||||
{/volist}
|
||||
{/notempty}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="theit">
|
||||
<div class="bditem bditem1">
|
||||
<label class="itlable">{:lang('contact_bulkbuy.form_message_label')}<span class="redtag">*</span></label>
|
||||
<textarea class="ittextarea ittextarea2" placeholder="{:lang('contact_bulkbuy.form_message_placeholder')}" name="message"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 提交-->
|
||||
<div class="bttj" id="send">{:lang('contact_bulkbuy.form_submit')}</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{/block}
|
||||
{block name="script"}
|
||||
<script type="text/javascript">
|
||||
$(function(){
|
||||
$("#send").click(function(){
|
||||
var form = $(this).parents("form");
|
||||
$.ajax({
|
||||
url: "{:url('contactus/bulkbuy')}",
|
||||
type: "post",
|
||||
dataType: "json",
|
||||
data: form.serialize(),
|
||||
success: function(r){
|
||||
if(r.code == 0){
|
||||
form.get(0).reset();
|
||||
}
|
||||
alert(r.msg);
|
||||
},
|
||||
error: function(e){
|
||||
console.error(e);
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
</script>
|
||||
{/block}
|
||||
Reference in New Issue
Block a user