Commit 9f756e7d by 孙龙

Merge branch 'sl/bom/20200528'

parents 05b2beab 9abdda59
<?php
namespace App\Exceptions;
class BomException extends \Exception{
}
\ No newline at end of file
<?php
namespace App\Http\Controllers;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Services\Bom\BomService;
class BomApiController extends Controller{
public $bomService =null;
public function __construct()
{
$this->bomService = new BomService;
}
public function Entrance(Request $request,$id){
return call_user_func_array([$this,$id],[$request, $id]);
}
private function ajaxReturn($errcode=0,$errmsg='成功',$data=''){
if(is_array($errcode)){
ErrorLog($errcode[0],$errcode[1]);
return [
'errcode'=>$errcode[0],
'errmsg'=>$errcode[1],
'data'=>!empty($errcode[2])?$errcode[2]:''
];
}else{
ErrorLog($errcode,$errmsg);
return [
'errcode'=>$errcode,
'errmsg'=>$errmsg,
'data'=>$data
];
}
}
private function LayuiAjaxReturn($errcode=0,$errmsg=0,$data=[],$count=0,$total=''){
if(is_array($errcode)){
ErrorLog($errcode[0],$errcode[1]);
return [
'code'=>$errcode[0],
'msg'=>$errcode[1],
'data'=>$errcode[2],
'count'=>$errcode[3],
'total'=>!empty($errcode[4])?$errcode[4]:''
];
}else{
ErrorLog($errcode,$errmsg);
return [
'code'=>$errcode,
'msg'=>$errmsg,
'data'=>$data,
'count'=>$count,
'total'=>$total
];
}
}
// bom单列表
public function BomList($request,$id)
{
list($count,$data) = $this->bomService->getBomList($request);
return $this->LayuiAjaxReturn(0,"ok",$data,$count);
}
// bom单详情
public function BomView($request,$id)
{
list($count,$data) = $this->bomService->getBomView($request);
return $this->LayuiAjaxReturn(0,"ok",$data,$count);
}
//bom单详情 保存bom单
public function saveBomInfo($request,$id){
$res = $this->bomService->saveBomInfo($request);
return $this->ajaxReturn($res['errcode'],$res['errmsg']);
}
/*
* 创建订单
*/
public function createBomOrder($request,$id){
$res = $this->bomService->createBomOrder($request);
return $this->ajaxReturn($res['errcode'],$res['errmsg']);
}
/*
* 数据报表
*/
public function bomReportCount($request,$id){
$res = $this->bomService->bomReportCount($request);
return $this->ajaxReturn($res['errcode'],$res['errmsg'],$res['data']);
}
}
\ No newline at end of file
<?php
namespace App\Model\Bom;
use Illuminate\Database\Eloquent\Model;
class BomExtendModel extends Model{
protected $connection = 'bom'; //库名
protected $table = 'bom_extend';
protected $primaryKey = 'id'; //设置id
protected $guarded = ['id']; //设置字段黑名单
public $timestamps = true;
const CREATED_AT = 'create_time';
const UPDATED_AT = 'update_time';
protected $dateFormat = 'Y-m-d H:i:s';
// protected $dates = ['fcorder_time'];
public static $STATUS = [
1=>"正常",
2=>"删除",
];
public function fromDateTime($value){
return strtotime(parent::fromDateTime($value));
}
public function getFcorderTimeAttribute($value)
{
if($value > 0){
return date("Y-m-d h:i",$value);
}else{
return "";
}
}
}
\ No newline at end of file
<?php
namespace App\Model\Bom;
use Illuminate\Database\Eloquent\Model;
class BomItemMatchBaseModel extends Model{
protected $suffix = null;
// 设置表后缀
public function setSuffix($suffix)
{
$this->suffix = $suffix;
if ($suffix !== null) {
$this->table = $this->getTable() . '_' . $suffix;
}
}
// 提供一个静态方法设置表后缀
public static function suffix($suffix)
{
$instance = new static;
$instance->setSuffix($suffix);
return $instance->newQuery();
}
// 创建新的"chapters_{$suffix}"的模型实例并返回
public function newInstance($attributes = [], $exists = false)
{
$model = parent::newInstance($attributes, $exists);
$model->setSuffix($this->suffix);
return $model;
}
}
\ No newline at end of file
<?php
namespace App\Model\Bom;
class BomItemMatchExtendModel extends BomItemMatchBaseModel{
protected $connection = 'bom'; //库名
protected $table = 'bom_match_extend'; //库名
protected $primaryKey = 'id'; //设置id
protected $guarded = ['id']; //设置字段黑名单
public $timestamps = true;
const CREATED_AT = 'create_time';
const UPDATED_AT = null;
protected $dateFormat = 'Y-m-d H:i:s';
public function fromDateTime($value){
return strtotime(parent::fromDateTime($value));
}
public function get_bom_match_extend($bom_id,$matching_id){
return static::where(["bom_id"=>$bom_id,"matching_id"=>$matching_id])->first();
}
}
\ No newline at end of file
<?php
namespace App\Model\Bom;
class BomItemMatchModel extends BomItemMatchBaseModel{
protected $connection = 'bom'; //库名
protected $table = 'bom_item_matching'; //库名
protected $primaryKey = 'matching_id'; //设置id
protected $guarded = ['matching_id']; //设置字段黑名单
public $timestamps = true;
const CREATED_AT = 'add_time';
const UPDATED_AT = 'update_time';
protected $dateFormat = 'Y-m-d H:i:s';
public function fromDateTime($value){
return strtotime(parent::fromDateTime($value));
}
public function getBomAmount($bom_id){
$suffix = substr(strrev($bom_id),0,1);
return self::suffix($suffix)->where('bom_id', $bom_id)->where("status",1)->selectRaw("sum(price*number) as amount")->first();
}
public function getBomItemsMatching($bom_id,$bom_item_id){
$suffix = substr(strrev($bom_id),0,1);
return self::suffix($suffix)->where('bom_id', $bom_id)->where("bom_item_id",$bom_item_id)->where("status",1)->first();
}
public function updateBomMatch($bom_id,$where,$data){
$suffix = substr(strrev($bom_id),0,1);
return self::suffix($suffix)->where($where)->update($data);
}
public function addBomMatch($bom_id,$data){
$suffix = substr(strrev($bom_id),0,1);
return self::suffix($suffix)->insert($data);
}
public function bomExtend(){
return $this->belongsTo(\App\Model\Bom\BomExtendModel::class,"bom_id","bom_id");
}
/*
* 获取bom下单型号的数量
*/
public function countCOrderBomItems($is_kefu,$bom_sn,$begin_time,$end_time){
$count = 0;
for($i=0;$i<=9;$i++){
$query = self::suffix($i);
$query = $this->buildCountQuery($query,$is_kefu,$bom_sn,$begin_time,$end_time);
$count += $query->where(["is_corder"=>1])->count("matching_id");
}
return $count;
}
protected function buildCountQuery($query,$is_kefu,$bom_sn,$begin_time,$end_time){
$bom_id = 0;
if($bom_sn != ""){
$bom = BomModel::where("bom_sn",trim($bom_sn))->select("bom_id")->first();
$bom_id = $bom ? $bom->bom_id : 0;
}
if($bom_id > 0){
$query = $query->where(["bom_id"=>$bom_id]);
}
$begin_time = $begin_time ? strtotime($begin_time." 00:00:00") : 0;
$end_time = $end_time ? strtotime($end_time." 23:59:59") : 0;
if($begin_time){
if($end_time){
$query = $query->where('add_time',">=",$begin_time)->where('add_time',"<=",$end_time);
}else{
$query = $query->where('add_time',">=",$begin_time);
}
}elseif($end_time){
$query = $query->where('add_time',"<=",$end_time);
}
if($is_kefu == '0'){
$query = $query->whereDoesntHave("bomExtend",function ($query) {
$query->where('kefu_id', "!=",0);
});
}elseif($is_kefu == '1'){
$query = $query->whereHas("bomExtend",function ($query) {
$query->where('kefu_id', "!=",0);
});
}
return $query;
}
/*
* 获取bom提交BOM金额
* $type 1提交的bom金额 2下单的bom金额
*/
public function bomAmount($is_kefu,$bom_sn,$begin_time,$end_time,$type=0){
$amount = 0;
for($i=0;$i<=9;$i++){
$query = self::suffix($i);
$query = $this->buildCountQuery($query,$is_kefu,$bom_sn,$begin_time,$end_time);
if($type == 0){
$query = $query->where(["is_corder"=>0]);
}elseif($type == 1){
$query = $query->where(["is_corder"=>1]);
}
$sumamount = $query->selectRaw("sum(number*price) as sumamount")->first();
$amount += $sumamount ? $sumamount->sumamount : 0;
}
return $amount;
}
}
\ No newline at end of file
<?php
namespace App\Model\Bom;
class BomItemModel extends BomItemMatchBaseModel{
protected $connection = 'bom'; //库名
protected $table = 'bom_item'; //库名
protected $primaryKey = 'bom_item_id'; //设置id
protected $guarded = ['bom_item_id']; //设置字段黑名单
public $timestamps = true;
const CREATED_AT = 'add_time';
const UPDATED_AT = 'update_time';
protected $dateFormat = 'Y-m-d H:i:s';
public function fromDateTime($value){
return strtotime(parent::fromDateTime($value));
}
public function getBomAmount($bom_id){
$suffix = substr(strrev($bom_id),0,1);
return self::suffix($suffix)->where('bom_id', $bom_id)->where("status",1)->selectRaw("sum(price*number) as amount")->first();
}
public function getBomItems($request,$bom_id){
$page = $request->input("page",1);
$limit = $request->input("limit",10);
$suffix = substr(strrev($bom_id),0,1);
$query = self::suffix($suffix)->select("*")->where('bom_id', $bom_id)->where(["del_status"=>1]);
$query = $query->paginate($limit,[],'page',$page);
return $query;
}
public function bomExtend(){
return $this->belongsTo(\App\Model\Bom\BomExtendModel::class,"bom_id","bom_id");
}
/*
* 获取bom提交型号的数量
*/
public function countBomItems($is_kefu,$bom_sn,$begin_time,$end_time){
$count = 0;
for($i=0;$i<=9;$i++){
$query = self::suffix($i);
$bom_id = 0;
if($bom_sn != ""){
$bom = BomModel::where("bom_sn",trim($bom_sn))->select("bom_id")->first();
$bom_id = $bom ? $bom->bom_id : 0;
}
if($bom_id > 0){
$query = $query->where(["bom_id"=>$bom_id]);
}
$begin_time = $begin_time ? strtotime($begin_time." 00:00:00") : 0;
$end_time = $end_time ? strtotime($end_time." 23:59:59") : 0;
if($begin_time){
if($end_time){
$query = $query->where('add_time',">=",$begin_time)->where('add_time',"<=",$end_time);
}else{
$query = $query->where('add_time',">=",$begin_time);
}
}elseif($end_time){
$query = $query->where('add_time',"<=",$end_time);
}
if($is_kefu == '0'){
$query = $query->whereDoesntHave("bomExtend",function ($query) {
$query->where('kefu_id', "!=",0);
});
}elseif($is_kefu == '1'){
$query = $query->whereHas("bomExtend",function ($query) {
$query->where('kefu_id', "!=",0);
});
}
$count += $query->count("bom_item_id");
}
return $count;
}
}
\ No newline at end of file
<?php
namespace App\Model\Bom;
use Illuminate\Database\Eloquent\Model;
class BomModel extends BomItemMatchBaseModel{
protected $connection = 'bom'; //库名
protected $table = 'bom';
protected $primaryKey = 'bom_id'; //设置id
protected $guarded = ['bom_id']; //设置字段黑名单
public $timestamps = true;
const CREATED_AT = 'add_time';
const UPDATED_AT = 'update_time';
protected $dateFormat = 'Y-m-d H:i:s';
public static $STATUS = [
1=>"正常",
2=>"删除",
];
public function fromDateTime($value){
return strtotime(parent::fromDateTime($value));
}
public function scopeSearchByrole($query,$role_id="",$sale_ids=[]){
if($role_id ==1){
return $query;
}elseif($role_id ==2 && is_array($sale_ids) && !empty($sale_ids) && count($sale_ids) > 0){
array_push($sale_ids,0);
$wherein = implode(",",$sale_ids);
$query = $query->whereRaw("bom_id in (select bom_id from lie_bom_extend where kefu_id in ({$wherein}))");
}elseif($role_id ==3 && !is_array($sale_ids)){
$query = $query->whereRaw("bom_id in (select bom_id from lie_bom_extend where kefu_id = 0 or kefu_id = {$sale_ids})");
}
return $query;
}
public function scopeSearchByBomSn($query,$bom_sn=""){
if($bom_sn != ''){
$query = $query->where('bom_sn',trim($bom_sn));
}
return $query;
}
public function scopeSearchByBomName($query,$bom_name=""){
if($bom_name != ''){
$query = $query->where('bom_name',trim($bom_name));
}
return $query;
}
public function scopeSearchByIsCorder($query,$is_corder=""){
if($is_corder == "all" || $is_corder == "" ){
return $query;
}else{
$query = $query->where('is_corder',intval($is_corder));
}
return $query;
}
public function scopeSearchByUserNameOrKefu($query,$username="",$is_kefu='all'){
$username = trim($username);
$is_kefu = trim($is_kefu);
if($username == "" ){
if($is_kefu == '0'){
$query = $query->whereDoesntHave("bomExtend",function ($query) {
$query->where('kefu_id', "!=",0);
});
}elseif($is_kefu == '1'){
$query = $query->whereHas("bomExtend",function ($query) {
$query->where('kefu_id', "!=",0);
});
}
return $query;
}else{
$query = $query->whereHas("bomExtend",function ($query) use($username,$is_kefu) {
if($username){
$query->where('user_name', trim($username));
}
if($is_kefu == '0'){
$query->where('kefu_id', "=",0);
}elseif($is_kefu == '1'){
$query->where('kefu_id', "!=",0);
}
});
}
return $query;
}
public function scopeSearchByTime($query,$begin_time='',$end_time=''){
$begin_time = $begin_time ? strtotime($begin_time." 00:00:00") : 0;
$end_time = $end_time ? strtotime($end_time." 23:59:59") : 0;
if($begin_time){
if($end_time){
$query = $query->where('add_time',">=",$begin_time)->where('add_time',"<=",$end_time);
}else{
$query = $query->where('add_time',">=",$begin_time);
}
}elseif($end_time){
$query = $query->where('add_time',"<=",$end_time);
}
return $query;
}
public function scopeCreateUserId($query,$create_userid=0,$role=null,$create_username='',$userType=0){
if($userType == 1){
return $query->where('create_userid',1000);
}
if($create_userid && $role != 1){
$query = $query->where('create_userid',$create_userid);
}
if($create_username && $role == 1){
$query = $query->where('create_username',"like","%".trim($create_username)."%");
}
return $query;
}
public function bomExtend()
{
return $this->hasOne(\App\Model\Bom\BomExtendModel::class,"bom_id","bom_id");
}
}
\ No newline at end of file
<?php
namespace App\Model\Bom;
use Illuminate\Database\Eloquent\Model;
class BomOrderModel extends Model{
protected $connection = 'bom'; //库名
protected $table = 'bom_order';
protected $primaryKey = 'id'; //设置id
protected $guarded = ['id']; //设置字段黑名单
public $timestamps = true;
const CREATED_AT = 'create_time';
const UPDATED_AT = 'update_time';
protected $dateFormat = 'Y-m-d H:i:s';
// protected $dates = ['fcorder_time'];
public function fromDateTime($value){
return strtotime(parent::fromDateTime($value));
}
//获取bom单的 下单金额
public static function getBomOrderAmount($bom_id=0){
return static::where(["bom_id"=>$bom_id])->sum("add_order_amount");
}
//获取bom单的 下单单号
public static function getBomOrderSn($bom_id=0){
return static::where(["bom_id"=>$bom_id])->get()->pluck("order_sn");
}
}
\ No newline at end of file
......@@ -109,6 +109,18 @@ return [
'prefix' => 'lie_',
'strict' => false,
],
'bom' => [
'driver' => 'mysql',
'host' => env('DB_HOST_BOM', ''),
'database' => env('DB_DATABASE_BOM', ''),
'username' => env('DB_USERNAME_BOM', ''),
'password' => env('DB_PASSWORD_BOM', ''),
'port' => env('DB_PORT_BOM', 3306),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => 'lie_',
'strict' => false,
],
'sqlite' => [
'driver' => 'sqlite',
'database' => database_path('database.sqlite'),
......
<?php
return [
'admin' => ['admin@ichunt.com'],
'login' => [
'login' => 'http://' . env('LOGIN_DOMAIN', '') . '/login',
'logout'=> 'http://' . env('LOGIN_DOMAIN', '') . '/logout',
'check' => 'http://' . env('LOGIN_DOMAIN', '') . '/api/checklogin',
'search'=> 'http://' . env('LOGIN_DOMAIN', '') . '/api/search',
],
'domain' => 'liexin.net',
// 订单系统
'order_url' => 'http://order.liexin.net',
// API项目
'api_domain' => 'http://api.liexin.com/',
'upload_key' => 'fh6y5t4rr351d2c3bryi', // 上传文件key
// 权限系统
'perm_url' => 'http://perm.liexin.net',
// 获取用户权限接口
'perm_api' => 'http://perm.liexin.net/api/perms/',
// 获取用户许可权限接口
'check_access_api' => 'http://perm.liexin.net/api/perms/access',
// 竞调账户配置显示时间
'vp_time_set' => '2018-05-01',
// 基石服务地址
'SERVICE_DOMAIN' => 'http://192.168.1.100',
//中间服务秘钥
'SERVICE_KEY' => 'j9q##VRhaXBEtznIEeDiR@1Hvy0sW3wp',
// 快递配置
'express_fee_key' => 'express_fee',
'express_fee' => [
'sz_inside' => 10,
'gd_inside' => 10,
'gd_outside' => 15,
],
// www站点
'main_url' => 'https://www.liexin.com/',
// 新增自营线下订单内部账号
'internal-account' => '15011111111',
// 新增用户入口
'add-user-url' => 'http://member.liexin.net/add',
// 编辑用户入口
'check-user-url' => 'http://member.liexin.net/list',
// 查询SKUID接口
// 'search-skuid' => 'http://footstone.liexin.net/webapi/sku_list',
// 'search-skuid' => 'http://www.liexin.com/v3/sku/list',
'search-skuid' => 'http://api.liexin.com/goods/detail',
// 新增SKU入口
'add-sku-url' => 'http://footstone.liexin.net/manage/addsku',
// 查询联营SKU入口
'search-sku-url-1' => 'http://footstone.liexin.net/manage/skulist',
// 查询自营SKU入口
'search-sku-url-2' => 'http://footstone.liexin.net/manage/GoodsList',
// 新增自营线上订单付款地址
'pay_online_url' => 'http://www.liexin.com/v3/pay/online?id=',
// 获取自营商品库存
'self-stock-url' => 'http://footstone.liexin.net/webapi/goods_details?sku_id=',
// 财务系统接口地址 (自营发票)
'finance-self-invoice-url' => 'http://192.168.1.97/webapi/checkOrderBillStatus',
// 支付地址
'pay_url' => 'https://www.liexin.com/v3/pay/online?id=',
// 订单微服务
'order_api_domain' => 'http://orderapi.liexin.com',
// crm
'crm_domain' => 'http://lcrm.liexin.net',
// 导出系统
'export_url' => 'http://export.liexin.com',
'export_joint_source_id' => 16,
'export_self_source_id' => 17,
];
<?php
return [
'admin' => ['admin@ichunt.com'],
'login' => [
'login' => 'http://' . env('LOGIN_DOMAIN', '') . '/login',
'logout'=> 'http://' . env('LOGIN_DOMAIN', '') . '/logout',
'check' => 'http://' . env('LOGIN_DOMAIN', '') . '/api/checklogin',
'search'=> 'http://' . env('LOGIN_DOMAIN', '') . '/api/search',
],
'domain' => 'liexin.net',
// 订单系统
'order_url' => 'http://order.liexin.net',
// API项目
'api_domain' => 'http://api.liexin.com/',
'upload_key' => 'fh6y5t4rr351d2c3bryi', // 上传文件key
// 权限系统
'perm_url' => 'http://perm.liexin.net',
// 获取用户权限接口
'perm_api' => 'http://perm.liexin.net/api/perms/',
// 获取用户许可权限接口
'check_access_api' => 'http://perm.liexin.net/api/perms/access',
// 竞调账户配置显示时间
'vp_time_set' => '2018-05-01',
// 基石服务地址
'SERVICE_DOMAIN' => 'http://192.168.1.100',
//中间服务秘钥
'SERVICE_KEY' => 'j9q##VRhaXBEtznIEeDiR@1Hvy0sW3wp',
// 快递配置
'express_fee_key' => 'express_fee',
'express_fee' => [
'sz_inside' => 10,
'gd_inside' => 10,
'gd_outside' => 15,
],
// www站点
'main_url' => 'https://www.liexin.com/',
// 新增自营线下订单内部账号
'internal-account' => '15011111111',
// 新增用户入口
'add-user-url' => 'http://member.liexin.net/add',
// 编辑用户入口
'check-user-url' => 'http://member.liexin.net/list',
// 查询SKUID接口
// 'search-skuid' => 'http://footstone.liexin.net/webapi/sku_list',
// 'search-skuid' => 'http://www.liexin.com/v3/sku/list',
'search-skuid' => 'http://api.liexin.com/goods/detail',
'search-skuid-finalInfo' => 'http://api.liexin.com/cart/bomOrderGetFinalGoods',
//自营订单添加购物车
'addzyorder_url' => 'http://api.liexin.com/cart/addBatch',
//联营加入购物车
'addlyorder_url' => 'http://api.liexin.com/cart/addBatchByOrderSystem',
//bom创建订单
'api_create_order' => 'http://api.liexin.com/order/create',
// 新增SKU入口
'add-sku-url' => 'http://footstone.liexin.net/manage/addsku',
// 查询联营SKU入口
'search-sku-url-1' => 'http://footstone.liexin.net/manage/skulist',
// 查询自营SKU入口
'search-sku-url-2' => 'http://footstone.liexin.net/manage/GoodsList',
// 新增自营线上订单付款地址
'pay_online_url' => 'http://www.liexin.com/v3/pay/online?id=',
// 获取自营商品库存
'self-stock-url' => 'http://footstone.liexin.net/webapi/goods_details?sku_id=',
// 财务系统接口地址 (自营发票)
'finance-self-invoice-url' => 'http://192.168.1.97/webapi/checkOrderBillStatus',
// 支付地址
'pay_url' => 'https://www.liexin.com/v3/pay/online?id=',
// 订单微服务
'order_api_domain' => 'http://orderapi.liexin.com',
// crm
'crm_domain' => 'http://lcrm.liexin.net',
// 导出系统
'export_url' => 'http://export.liexin.com',
'export_joint_source_id' => 16,
'export_self_source_id' => 17,
];
layui.use(['form', 'table', 'laydate'], function(){
var form = layui.form;
var table = layui.table;
var laydate = layui.laydate;
laydate.render({
elem: '#begin_time' //指定元素
});
laydate.render({
elem: '#end_time' //指定元素
});
var renderTable = function () {
table.render({
id: 'list'
,elem: '#list'
,url: '/ajax/bom/BomList' //数据接口
,method:'post'
,cellMinWidth: 80 //全局定义常规单元格的最小宽度
,page: true //开启分页
,cols: [[ //表头
{title: 'id',field: 'bom_id', fixed: 'left', width: 80}
,{field: 'add_time', title: '创建时间', width: 180}
,{field: 'bom_name', title: 'BOM名称', width: 160}
,{templet: '<div>{{d.bom_extend ? d.bom_extend.user_name : ""}}</div>', title: '会员账号', width: 180}
,{templet: '<div>{{d.bom_extend ? d.bom_extend.company_name : ""}}</div>', title: '公司名称', width: 160}
,{field:'bomMoney', title: 'BOM单金额', width: 130}
,{field: 'is_corder', title: '是否下单', templet: '#is_corder', width: 150}
,{field: '', title: '对应订单编号', width: 120,templet:"#bomCOrderSn"}
,{field: 'bomCOrderAmount', title: '下单金额', width: 150}
,{templet: '<div>{{d.bom_extend ? d.bom_extend.fcorder_time : ""}}</div>', title: '首次下单时间', width: 180}
,{templet: '<div>{{d.bom_extend ? d.bom_extend.kefu_name : ""}}</div>', title: '客服', width: 150}
,{field: 'status', title: '状态', templet: '#status', width: 150}
,{field: 'join_time', title: '操作',toolbar: '#action',width:130,fixed: 'right',}
]]
,limit: 10
,limits: [10, 20, 50,]
});
};
renderTable();
form.on('submit(load)', function(data) {
//执行重载
table.reload('list', {
page: {
curr: 1
}
,where: data.field
});
return false;
});
$('.add').click(function() {
layer.open({
area: ['400px', '200px'],
title: '新增客服',
type: 1,
content: $('#kefu-action'),
btn: ['确认', '取消'],
yes: function(index) {
var email = $('.kefu-email').val();
if (!email) {
layer.tips('请输入邮箱', $('.kefu-email'));
return false;
}
$.ajax({
url : '/api/ApiAddKefu',
type: 'post',
data: {email: email},
dataType: 'json',
success: function(resp) {
if (resp.errcode == 0) {
layer.close(index);
layer.msg(resp.errmsg);
renderTable(); // 重新加载table
return false;
}
layer.msg(resp.errmsg);
},
error: function(err) {
console.log(err)
}
})
layer.msg('新增客服中...', {icon: 16, time: 0, shade: 0.3}); // 阻止重复提交
return false;
},
cancel: function(index) {
layer.close(index);
}
})
$('.kefu-email').val('');
})
// tool操作
table.on('tool(kefu)', function(obj){ //注:tool是工具条事件名,test是table原始容器的属性lay-filter="对应的值"
var data = obj.data; //获得当前行数据
var layEvent = obj.event; //获得 lay-event 对应的值(也可以是表头的 event 参数对应的值)
var url = '';
var title = '';
var content = '';
var datax = {};
datax.id = data.id;
if(layEvent === 'edit') {
url = '/api/ApiEditKefu';
title = '编辑客服';
content = $('#kefu-action');
} else if (layEvent === 'del') {
url = '/api/ApiDelKefu';
title = '删除客服';
content = '<div style="margin: 40px;">确定删除该客服吗?</div>';
datax.status = data.status;
} else if (layEvent === 'top') {
url = '/api/ApiTopKefu';
title = '置顶客服';
content = '<div style="margin: 40px;">确定置顶该客服吗?</div>';
}
layer.open({
area: ['400px', '200px'],
title: title,
type: 1,
content: content,
btn: ['确认', '取消'],
yes: function(index) {
if (layEvent == 'edit') {
var email = $('.kefu-email').val();
if (!email) {
layer.tips('请输入邮箱', $('.kefu-email'));
return false;
}
datax.email = email;
}
$.ajax({
url : url,
type: 'post',
data: datax,
dataType: 'json',
success: function(resp) {
if (resp.errcode == 0) {
layer.close(index);
layer.msg(resp.errmsg);
renderTable(); // 重新加载table
return false;
}
layer.msg(resp.errmsg);
},
error: function(err) {
console.log(err)
}
})
layer.msg(title+'中...', {icon: 16, time: 0, shade: 0.3}); // 阻止重复提交
return false;
},
cancel: function(index) {
layer.close(index);
}
})
if (layEvent == 'edit') {
$('.kefu-email').val(data.email);
}
});
});
\ No newline at end of file
layui.use(['form', 'table', 'laydate'], function() {
var form = layui.form;
var table = layui.table;
var laydate = layui.laydate;
//时间选择器
laydate.render({
elem: '#begin_time' //指定元素
});
laydate.render({
elem: '#end_time' //指定元素
});
function initDataCount(datax){
$.post("/ajax/bom/bomReportCount",datax,function(res){
if(res.errcode == 0){
$.each(res.data,function(k,v){
$("#"+k).text(v);
})
}
})
}
initDataCount({});
$("#test1_button").click(function(){
var aa = $("#test1_form").serialize()
initDataCount(aa)
})
})
\ No newline at end of file
layui.use(['form', 'table', 'laydate'], function() {
var form = layui.form;
var table = layui.table;
var laydate = layui.laydate;
//转换静态表格
table.init('bomView', {
limit:10
,url: '/ajax/bom/BomView?bom_id='+bom_id //数据接口
,toolbar: '#toolbarDemo' //开启头部工具栏,并为其绑定左侧模板
,defaultToolbar:[]
,method:'post'
,cellMinWidth: 80 //全局定义常规单元格的最小宽度
,page: true //开启分页
});
function renderTable(){
table.init('bomView', {
limit:10
,url: '/ajax/bom/BomView?bom_id='+bom_id //数据接口
,toolbar: '#toolbarDemo' //开启头部工具栏,并为其绑定左侧模板
,defaultToolbar:[]
,method:'post'
,cellMinWidth: 80 //全局定义常规单元格的最小宽度
,page: true //开启分页
});
}
form.on('checkbox(checkall)', function (data) {
var child = $(data.elem).parents('.layui-tab-item').find('input[type="checkbox"]');
child.each(function (index, item) {
item.checked = data.elem.checked;
});
form.render('checkbox');
});
//监听单元格编辑
table.on('edit(bomView)', function(obj){
var value = obj.value //得到修改后的值
,data = obj.data //得到所在行所有键值
,field = obj.field; //得到字段
if(field != "match_goods_id"){
obj.data.match_goods_id = 0;
obj.update(data) //修改当前行数据
}
});
function save_form_ajax(datax){
layer.open({
title: "保存bom单",
content: "你确定保存吗?",
btn: ['确认?', '取消'],
yes: function(index) {
layer.close(index);
$.ajax({
url : "/ajax/bom/saveBomInfo",
type: 'post',
data: datax,
success: function(resp) {
if (resp.errcode == 0) {
layer.msg(resp.errmsg);
renderTable(); // 重新加载table
}else{
layer.alert(resp.errmsg);
}
},
error: function(err) {
console.log(err)
}
})
layer.msg('请耐心等待....', {icon: 16, time: 5000, shade: 0.3})
return false;
},
cancel: function(index) {
layer.close(index);
}
})
}
function create_order_ajax(datax){
layer.open({
title: "创建bom订单",
content: "你确定下单吗?",
btn: ['确认?', '取消'],
yes: function(index) {
layer.close(index);
$.ajax({
url : "/ajax/bom/createBomOrder",
type: 'post',
data: datax,
success: function(resp) {
if (resp.errcode == 0) {
layer.alert(resp.errmsg);
//return
renderTable(); // 重新加载table
}else{
layer.alert(resp.errmsg);
}
},
error: function(err) {
console.log(err)
}
})
layer.msg('请耐心等待....', {icon: 16, time: 10000, shade: 0.3})
return false;
},
cancel: function(index) {
layer.close(index);
}
})
}
//头工具栏事件
table.on('toolbar(bomView)', function(obj){
var checkStatus = table.checkStatus("layui_table_bomView");
var data = checkStatus.data;
if(checkStatus.data.length <= 0){
layer.msg('请先选择需要保存的数据行', {icon: 16, time: 3000, shade: 0.3})
return
}
var datax = {}
datax.data = data
switch(obj.event){
case 'create_order':
create_order_ajax(datax);
break;
case 'save_form':
save_form_ajax(datax)
break;
};
});
})
\ No newline at end of file
<form class="layui-form layui-box" method="post">
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label">BOM名称</label>
<div class="layui-input-inline">
<input type="text" name="bom_name" placeholder="填写BOM名称" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">创建用户</label>
<div class="layui-input-inline">
<input type="text" name="username" placeholder="填写创建用户" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">创建日期:</label>
<div class="layui-input-inline">
<input type="text" name="begin_time" value="" autocomplete="off" placeholder="选择开始时间" class="layui-input" id="begin_time" readonly>
</div>
<div class="layui-form-mid">-</div>
<div class="layui-input-inline">
<input type="text" name="end_time" value="" autocomplete="off" placeholder="选择结束时间" class="layui-input" id="end_time" readonly>
</div>
</div>
</div>
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label">是否下单</label>
<div class="layui-input-inline">
<select name="is_corder" lay-verify="" lay-search>
<option value="">全部</option>
<option value="1"></option>
<option value="0"></option>
</select>
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">客服</label>
<div class="layui-input-inline">
<select name="is_kefu" lay-verify="" lay-search>
<option value="all">全部</option>
<option value="1"></option>
<option value="0"></option>
</select>
</div>
</div>
<div class="layui-inline" style="text-align: center;">
<button lay-submit lay-filter="load" class="layui-btn" data-type="search">搜索</button>
<!-- <button type="button" class="layui-btn layui-btn-normal export">导出</button> -->
</div>
</div>
</form>
<table id="list" lay-filter="list"></table>
<script type="text/html" id="action">
{{--<a class="btn btn-xs btn-outline btn-success" href="/web/showTemplate?t_id=@{{ d.bom_id }}" target="_blank" lay-event="show">下载</a>--}}
<a class="btn btn-xs btn-outline btn-success" href="/web/BomView?bom_id=@{{ d.bom_id }}" target="_blank" lay-event="show">详情</a>
</script>
<script type="text/html" id="status">
@{{# if (d.status == 1) { }}
<div style="color:green;">正常</div>
@{{# } else { }}
<div style="color:#ccc;">删除</div>
@{{# } }}
</script>
<script type="text/html" id="is_corder">
@{{# if (d.is_corder == 1) { }}
<div style="color:green;">已下单</div>
@{{# } else { }}
<div style="color:#ccc;">未下单</div>
@{{# } }}
</script>
<script type="text/html" id="kefu_name">
@{{# d.bom_extend.kefu_name }}
</script>
<script type="text/html" id="bomCOrderSn">
@{{# if (d.bomCOrderSn) { }}
@{{ d.bomCOrderSn.join(",")}}
@{{# } }}
</script>
<div class="layui-col-md12" style="padding-bottom: 15px">
<h3>数据概况</h3>
<hr>
<form class="layui-form layui-box" id="test1_form" method="post">
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label">BOM单号</label>
<div class="layui-input-inline">
<input type="text" name="bom_sn" placeholder="填写BOM单号" autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">创建日期:</label>
<div class="layui-input-inline">
<input type="text" name="begin_time" value="" autocomplete="off" placeholder="选择开始时间" class="layui-input" id="begin_time" readonly>
</div>
<div class="layui-form-mid">-</div>
<div class="layui-input-inline">
<input type="text" name="end_time" value="" autocomplete="off" placeholder="选择结束时间" class="layui-input" id="end_time" readonly>
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">客服</label>
<div class="layui-input-inline">
<select name="is_kefu" lay-verify="" lay-search>
<option value="all">全部</option>
<option value="1"></option>
<option value="0"></option>
</select>
</div>
</div>
<div class="layui-inline" style="text-align: center;">
<a id="test1_button" class="layui-btn" >搜索</a>
<!-- <button type="button" class="layui-btn layui-btn-normal export">导出</button> -->
</div>
</div>
</form>
<div class="layui-card-body">
<table class="layui-table" id="dataCont">
<tr>
<th lay-data="">提交BOM单数量</th>
<th lay-data="">BOM单数量</th>
{{--<th lay-data="">BOM付款数量</th>--}}
<th lay-data="">提交型号数</th>
<th lay-data="">下单型号数</th>
{{--<th lay-data=>付款型号数</th>--}}
<th lay-data=>提交BOM金额</th>
<th lay-data=>下单BOM金额</th>
<th >无结果型号</th>
<th>询价型号数</th>
</tr>
<tr>
<th id="field1"></th>
<th id="field2"></th>
{{--<th id="field3"></th>--}}
<th id="field4"></th>
<th id="field5"></th>
{{--<th id="field6"></th>--}}
<th id="field7"></th>
<th id="field8"></th>
<th id="field10"></th>
<th id="field11"></th>
</tr>
</table>
</div>
</div>
{{--<div class="layui-card" style="">--}}
{{--<h3>用户数据</h3>--}}
{{--<hr>--}}
{{--<form class="layui-form layui-box" id="test5" method="post">--}}
{{--<div class="layui-form-item">--}}
{{--<div class="layui-inline">--}}
{{--<label class="layui-form-label">创建日期:</label>--}}
{{--<div class="layui-input-inline">--}}
{{--<input type="text" name="begin_time" value="" autocomplete="off" placeholder="选择开始时间" class="layui-input" id="begin_time" readonly>--}}
{{--</div>--}}
{{--<div class="layui-form-mid">-</div>--}}
{{--<div class="layui-input-inline">--}}
{{--<input type="text" name="end_time" value="" autocomplete="off" placeholder="选择结束时间" class="layui-input" id="end_time" readonly>--}}
{{--</div>--}}
{{--</div>--}}
{{--<div class="layui-inline">--}}
{{--<label class="layui-form-label">客服</label>--}}
{{--<div class="layui-input-inline">--}}
{{--<select name="is_kefu" lay-verify="" lay-search>--}}
{{--<option value="all">全部</option>--}}
{{--<option value="1"></option>--}}
{{--<option value="0"></option>--}}
{{--</select>--}}
{{--</div>--}}
{{--</div>--}}
{{--<div class="layui-inline" style="text-align: center;">--}}
{{--<button class="layui-btn" data-type="search">搜索</button>--}}
{{--<!-- <button type="button" class="layui-btn layui-btn-normal export">导出</button> -->--}}
{{--</div>--}}
{{--</div>--}}
{{--</form>--}}
{{--</div>--}}
<style>
::-webkit-scrollbar-track-piece {
-webkit-border-radius: 0
}
::-webkit-scrollbar {
width: 5px;
height: 10px
}
::-webkit-scrollbar-thumb {
height: 50px;
background-color: #b8b8b8;
-webkit-border-radius: 6px;
outline-offset: -2px;
filter: alpha(opacity = 50);
-moz-opacity: 0.5;
-khtml-opacity: 0.5;
opacity: 0.5
}
::-webkit-scrollbar-thumb:hover {
height: 50px;
background-color: #878987;
-webkit-border-radius: 6px;
}
</style>
<table class="layui-table" lay-filter="bomView" id="layui_table_bomView">
<thead>
<tr>
<th lay-data="{fixed: 'left',templet:'#checkbd'}"><input type="checkbox" >全选</th>
<th lay-data="{type:'numbers', width:80, sort: true,fixed: 'left'}">序号</th>
<th lay-data="{field:'goods_name', width:150}">需求型号</th>
<th lay-data="{field:'brand_name',width:140,}">品牌</th>
<th lay-data="{field:'number',width:120,}">需求数量</th>
<th lay-data="{field:'attrs',width:120,}">参数</th>
<th lay-data="{field: 'match_goods_id',width:150,edit:'text'}">skuID(可修改)</th>
<th lay-data="{field: 'match_goods_name',width:200,edit:'text'}">推荐型号(可修改)</th>
<th lay-data="{field: 'match_brand_name',width:200,edit:'text'}">推荐品牌(可修改)</th>
<th lay-data="{field:'match_number', width:130,edit:'text'}"><i class="layui-icon-edit"></i>推荐数量(可修改)</th>
<th lay-data="{field:'match_price',width:130,edit:'text'}">单价(可修改)</th>
<th lay-data="{field:'match_delivery',width:160,edit:'text'}">货期/天(可修改)</th>
<th lay-data="{field:'match_supplier_name',edit:'text',width:160}">供应商(可修改)</th>
<th lay-data="{field:'match_mpq'}">包装</th>
<th lay-data="{field:'match_moq'}">起订量</th>
<th lay-data="{field:'match_amount',width:100}">小计</th>
<th lay-data="{field:'is_corder',templet: '#match_ic_corder',width:100}">是否下单</th>
{{--<th lay-data="{field:'bom_match_extend',templet: '#match_extend_order_amount',width:150}">下单金额</th>--}}
<th lay-data="{field:'bom_match_extend',templet: '#match_extend_order_sn',width:150}">订单编号</th>
</tr>
</thead>
</table>
<script type="text/html" id="toolbarDemo">
<div class="layui-btn-container">
<button class="layui-btn layui-btn-sm" lay-event="save_form">保存</button>
<button class="layui-btn layui-btn-sm" lay-event="create_order">下单</button>
</div>
</script>
<script type="text/html" id="match_ic_corder">
@{{# if (d.is_corder == 1) { }}
<div style="color: #ff0000">下单</div>
@{{# }else{ }}
未下单
@{{# } }}
</script>
<script type="text/html" id="checkbd">
@{{# if (d.is_corder != 1) { }}
<input type="checkbox" name="layTableCheckbox" lay-skin="primary">
@{{# } }}
</script>
<script type="text/html" id="match_extend_order_amount">
@{{# if (d.bom_match_extend) { }}
@{{ d.bom_match_extend.order_amount }}
@{{# } }}
</script>
<script type="text/html" id="match_extend_order_sn">
@{{# if (d.bom_match_extend) { }}
@{{# if(d.bom_match_extend.order_id > 0){ }}
@{{# if(d.match_goods_type == 0){ }}
<a href="/details/@{{ d.bom_match_extend.order_id }}?tags=self">@{{ d.bom_match_extend.order_sn }}</a>
@{{# }else{ }}
<a href="/details/@{{ d.bom_match_extend.order_id }}">@{{ d.bom_match_extend.order_sn }}</a>
@{{# } }}
@{{# } }}
@{{# } }}
</script>
<script>
var bom_id = "{{$bom_id}}"
</script>
\ No newline at end of file
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