Commit daa6b500 by 孙龙

up

parent c1ade109
......@@ -42,7 +42,14 @@ class BomModel extends BomItemMatchBaseModel{
public function scopeSearchByBomSn($query,$bom_sn=""){
if($bom_sn != ''){
$query = $query->where('bom_sn',$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;
}
......@@ -74,7 +81,7 @@ class BomModel extends BomItemMatchBaseModel{
}else{
$query = $query->whereHas("bomExtend",function ($query) use($username,$is_kefu) {
if($username){
$query->where('user_name', $username);
$query->where('user_name', trim($username));
}
if($is_kefu == '0'){
$query->where('kefu_id', "=",0);
......@@ -130,4 +137,6 @@ class BomModel extends BomItemMatchBaseModel{
}
\ 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
......@@ -6,6 +6,7 @@ use App\Model\Bom\BomItemMatchModel;
use App\Model\Bom\BomItemModel;
use App\Model\Bom\BomItemMatchExtendModel;
use App\Exceptions\BomException;
use App\Model\Bom\BomOrderModel;
use DB;
class BomService {
......@@ -41,7 +42,8 @@ class BomService {
public function getBomList($request){
$page = $request->input("page",1);
$limit = $request->input("limit",10);
$bom_sn = $request->input("bom_sn",'');
// $bom_sn = $request->input("bom_sn",'');
$bom_name = $request->input("bom_name",'');
$is_corder = $request->input("is_corder",'all');
$begin_time = $request->input("begin_time",'');
$end_time = $request->input("end_time",'');
......@@ -52,7 +54,7 @@ class BomService {
list($role_id,$sale_ids) = $this->getRole($request);
$query = BomModel::select("*")->with("bomExtend")->SearchByUserNameOrKefu($username,$is_kefu)
->SearchByBomSn($bom_sn)->SearchByIsCorder($is_corder)->SearchByTime($begin_time,$end_time)
->SearchByBomName($bom_name)->SearchByIsCorder($is_corder)->SearchByTime($begin_time,$end_time)
->SearchByrole($role_id,$sale_ids)
->orderBy("bom_id","desc");
// $tmp = str_replace('?', '"'.'%s'.'"', $query->toSql());
......@@ -62,9 +64,15 @@ class BomService {
$list = $query->paginate($limit,[],'page',$page);
$bomItemMatchModel = new BomItemMatchModel;
foreach($list as $k=>$item){
//bom单金额
$bomMoneyObj = $bomItemMatchModel->getBomAmount($item->bom_id);
$bomMoney = $bomMoneyObj->amount;
$item->bomMoney = $bomMoney ? round($bomMoney,2) : 0;
//bom下单金额
$item->bomCOrderAmount = BomOrderModel::getBomOrderAmount($item->bom_id);
$item->bomCOrderSn = BomOrderModel::getBomOrderSn($item->bom_id);
}
$list = $list->toArray();
......@@ -456,14 +464,44 @@ class BomService {
foreach($data as $k=>$item){
if($item["is_corder"] == 1) continue;
if(!isset($item["matching_id"])){
array_push($err_msg,sprintf("您勾选的第%s行数据没有匹配到任何型号,不能下单",$k+1));
break;
}
if($item["is_corder"] == 1) {
array_push($err_msg,sprintf("您勾选的第%s行数据已经下单了,不能重复下单",$k+1));
break;
}
if(in_array($item["match_goods_type"],[0])){
if($item["match_goods_id"] <= 0){
array_push($err_msg,sprintf("您勾选的第%s行数据自营订单没有skuid",$k+1));
break;
}
if($item["match_number"] <= 0){
array_push($err_msg,sprintf("您勾选的第%s行数据数量有问题哦",$k+1));
break;
}
//自营
$ziying[$k]["id"] = $item["match_goods_id"];
$ziying[$k]["num"] = $item["match_number"];
$ziying[$k]["delivery_place"] = $delivery_type;
$ziying[$k]["matching_id"] = $item["matching_id"];
}else{
if($item["match_number"] <= 0){
array_push($err_msg,sprintf("您勾选的第%s行数据数量有问题哦",$k+1));
break;
}
if(!$item["match_goods_name"] || !$item['match_brand_name'] || $item['match_price'] <= 0){
array_push($err_msg,sprintf("您勾选的第%s行数据没有填写完整,请检查型号,品牌,数量等是否填写了",$k+1));
break;
}
//联营
$lianying[$k]["matching_id"] = $item['matching_id'];
$lianying[$k]["goods_name"] = $item['match_goods_name'];
......@@ -473,22 +511,46 @@ class BomService {
$lianying[$k]["delivery_time"] = $item['match_delivery'];
$lianying[$k]["supplier_name"] =$item['match_supplier_name'];
$lianying[$k]["id"] = $item['match_goods_id'];
$ziying[$k]["matching_id"] = $item["matching_id"];
$lianying[$k]["matching_id"] = $item["matching_id"];
}
}
if(!empty($err_msg)){
throw new BomException("",-1);
}
//清理用户以前的购物车 type=2 后台 extend_type=5 bom
$this->cleanBomShopCart($user_id);
if($ziying){
$bk1 = $this->zyOrder($user_id,$ziying,$extend,$err_msg);
}
if($lianying){
$bk2 = $this->lyOrder($user_id,$lianying,$extend,$err_msg);
}
$returnErrorMsg = "";
$this->zyOrder($user_id,$ziying,$extend,$err_msg);
$this->lyOrder($user_id,$lianying,$extend,$err_msg);
if(isset($bk1))
$returnErrorMsg .= $bk1 ? "自营下单成功" : "自营下单失败";
return ['errcode'=>0,"errmsg"=>"下单成功"];
if(isset($bk2))
$returnErrorMsg .= $bk2 ? "联营下单成功" : "联营下单失败";
if(!empty($err_msg))
$returnErrorMsg .= implode("\n",$err_msg);
return ['errcode'=>0,"errmsg"=>$returnErrorMsg];
}catch(BomException $e){
array_push($err_msg,$e->getMessage());
return ['errcode'=>$e->getCode(),"errmsg"=>implode(",",$err_msg)];
return ['errcode'=>$e->getCode(),"errmsg"=>implode("\n",$err_msg)];
}catch(\Exception $e){
array_push($err_msg,$e->getMessage());
return ['errcode'=>-1,"errmsg"=>$e->getMessage()];
}
}
......@@ -512,14 +574,20 @@ class BomService {
return true;
}else{
if(is_array($addOrder) && !empty($addOrder)){
array_push($err_msg,$addOrder["err_msg"]);
array_push($err_msg,sprintf("联营订单下单失败 原因:%s",$addOrder["err_msg"]));
}else{
array_push($err_msg,sprintf("联营订单下单失败 原因:%s","出现异常"));
}
}
}else{
array_push($err_msg,sprintf("%s","联营订单加入购物车失败,原因:没有找到该用户bom单购物车数据"));
}
}else{//bom加入购物车失败
if(is_array($lyShopCart) && !empty($lyShopCart)){
array_push($err_msg,$lyShopCart["err_msg"]);
array_push($err_msg,sprintf("联营订单加入购物车失败 %s",$lyShopCart["err_msg"]));
}else{
array_push($err_msg,"联营订单加入购物车失败,原因:出现异常");
}
}
......@@ -564,14 +632,20 @@ class BomService {
return true;
}else{
if(is_array($addzyOrder) && !empty($addzyOrder)){
array_push($err_msg,$addzyOrder["err_msg"]);
array_push($err_msg,sprintf("自营订单下单失败 %s",$addzyOrder["err_msg"]));
}else{
array_push($err_msg,"自营订单下单失败,原因:出现异常");
}
}
}else{
array_push($err_msg,"自营订单加入购物车失败,原因:没有找到该用户bom单购物车数据");
}
}else{//bom加入购物车失败
if(is_array($addZYShopCart) && !empty($addZYShopCart)){
array_push($err_msg,$addZYShopCart["err_msg"]);
array_push($err_msg,sprintf("自营订单加入购物车失败 %s",$addZYShopCart["err_msg"]));
}else{
array_push($err_msg,"自营订单加入购物车失败,原因:出现异常");
}
}
......@@ -676,6 +750,13 @@ class BomService {
}
/*
* 清楚用户bom购物车
*/
protected function cleanBomShopCart($user_id){
if($user_id <= 0) return true;
DB::connection("order")->table("lie_shopping_cart")->where(["user_id"=>$user_id,"type"=>2,"extend_type"=>5])->delete();
}
public function bomReportCount($request){
try{
......
......@@ -22,13 +22,13 @@ layui.use(['form', 'table', 'laydate'], function(){
,cols: [[ //表头
{title: 'id',field: 'bom_id', fixed: 'left', width: 80}
,{field: 'add_time', title: '创建时间', width: 180}
,{field: 'bom_sn', title: 'BOM单号', width: 160}
,{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}
,{field: '', title: '下单金额', 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}
......
......@@ -98,7 +98,8 @@ layui.use(['form', 'table', 'laydate'], function() {
data: datax,
success: function(resp) {
if (resp.errcode == 0) {
layer.msg(resp.errmsg);
layer.alert(resp.errmsg);
//return
renderTable(); // 重新加载table
}else{
......
<form class="layui-form layui-box" method="post">
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label">BOM单号</label>
<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">
<input type="text" name="bom_name" placeholder="填写BOM名称" autocomplete="off" class="layui-input">
</div>
</div>
......@@ -74,8 +74,8 @@
</script>
<script type="text/html" id="is_corder">
@{{# if (d.status == 0) { }}
<div style="color:green;">下单</div>
@{{# if (d.is_corder == 1) { }}
<div style="color:green;">下单</div>
@{{# } else { }}
<div style="color:#ccc;">未下单</div>
@{{# } }}
......@@ -84,6 +84,12 @@
@{{# d.bom_extend.kefu_name }}
</script>
<script type="text/html" id="bomCOrderSn">
@{{# if (d.bomCOrderSn) { }}
@{{ d.bomCOrderSn.join(",")}}
@{{# } }}
</script>
......@@ -42,7 +42,7 @@
<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_amount',width:150}">下单金额</th>--}}
<th lay-data="{field:'bom_match_extend',templet: '#match_extend_order_sn',width:150}">订单编号</th>
</tr>
</thead>
......@@ -78,8 +78,16 @@
</script>
<script type="text/html" id="match_extend_order_sn">
@{{# if (d.bom_match_extend) { }}
@{{ d.bom_match_extend.order_sn }}
@{{# 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>
......
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