Commit d624e727 by 李洋

添加修改数据库api

parent 42bcfda6
<?php
/**
* Created by PhpStorm.
* User: leo
* Date: 2017/12/7
* Time: 13:04
*/
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use DB;
use RedisDB;
class MessageApiController extends Controller
{
public function Entrance(Request $request, $id ){
//统一入口
$this->$id($request, $id);
}
private function Export($errcode=0,$errmsg='成功',$data=''){
echo json_encode(['errcode'=>$errcode,'errmsg'=>$errmsg,'data'=>$data]);
exit();
}
//新增/编辑 消息模板
private function addTemplate($request)
{
$data = $request->input();
//至少选择一个渠道
if(empty($data['channels']))
{
$this->Export(11001,'请选择渠道');
}else{
//选了站内信渠道 就要选站内信类型
if(strpos($data['channels'],'1'))
{
if(empty($data['msg_type']))
{
$this->Export(11001,'请选择选择站内信类型');
}
}
}
$input_model = [];
$input_model['brand_id']=$data['brand_id'];
$input_model['brand_name']=$data['brand_name'];
$input_model['brand_logo']=$data['brand_logo'];
$input_model['brand_desc']=$data['brand_desc'];
$input_model['status']=$data['status'];
$input_model['main_product']=$data['main_product'];
$input_model['brand_brief']=$data['brand_brief'];
if(isset($data['brand_area']))
{
$input_model['brand_area']=$data['brand_area'];
}
$db=DB::connection('spu')->table('lie_brand');
if(!empty($input_model['brand_id'])){
$resurt=$db->where('brand_id',$input_model['brand_id'])->update($input_model);
if(!$resurt) {
$this->Export(11011, '修改制造商失败', 'sql');
}
}else{
$find=DB::connection('spu')->table('lie_brand')->where('brand_name',$input_model['brand_name'])->first();
if($find){
$this->Export(11012, '当前品牌名字已经存在', 'brand_name');
}
$input_model['create_time']=time();
$resurt=$db->insert($input_model);
if(!$resurt) {
$this->Export(11013, '新增制造商失败', 'sql');
}
}
$this->Export(0,empty($input_model['brand_id'])? '新增成功':'修改成功');
}
//编辑手动消息
//发送手动消息
private function sendManualMessage($request)
{
}
}
\ No newline at end of file
......@@ -52,7 +52,7 @@ Route::group(['middleware' => 'web'], function () {
Route::post('/api/user/register', 'LoginController@register');
//Message
Route::match(['get', 'post'],'/fsapi/{key}', 'MessageApiController@Entrance');
Route::match(['get', 'post'],'/msgapi/{key}', 'MessageApiController@Entrance');
// 页面
Route::get('/page/{id?}', 'TablePageController@page');
......
......@@ -94,22 +94,20 @@ function addTemplate()
url: '/msgapi/addTemplate',
timeout : 10000, //超时时间设置,单位毫秒
data: {
spu_id:$('#spu_id').val(),
class_id1:$('#class_id1').val(),
class_id2:$('#class_id2').val(),
class_id3:$('#class_id3').val(),
brand_id:$('#brand_id').val(),
spu_name:$('#spu_name').val(),
status:$("input[name='status']:checked").val(),
images_l:$('#images_l').val(),
images_s:$('#images_s').val(),
encap:$('#encap').val(),
pdf:$('#pdf').val(),
spu_brief:$('#spu_brief').val(),
has_rohs:$("input[name='has_rohs']:checked").val(),
attrs:$('#spu_attrs').val(),
spu_detail:ue.getContent(),
bussiness_area:checkBoxes,
tpl_id:$('#spu_id').val(),
channels:$('#class_id1').val(),
msg_type:$('#class_id2').val(),
source_type:$('#class_id3').val(),
creater:$('#brand_id').val(),
obj_user:$('#spu_name').val(),
description:$("input[name='status']:checked").val(),
channel_tpl_id:$('#images_l').val(),
channel_type:$('#images_s').val(),
title:$('#encap').val(),
content:$('#pdf').val(),
op_type:$('#spu_brief').val(),
url:$("input[name='has_rohs']:checked").val(),
},
dataType: 'json',
success: function(resp){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment