v1.0

parent aab9b3c0
......@@ -7,6 +7,7 @@ use App\Model\GoodsAuditModel;
use App\Model\Server\ServerFinanceModel;
use App\Model\Server\ServerPurModel;
use App\Model\SupplierAccountModel;
use App\Model\UploadLogModel;
use Illuminate\Http\Request;
use App\Http\Requests;
use RedisDB;
......@@ -73,6 +74,10 @@ class ApiController extends Controller
private function ApiGoodsAuditList($request, $id){
ExportLayui((new GoodsAuditModel())->getList($request->input(),$request->supplier_id));
}
//价格审核操作
private function ApiGoodsAuditExmine($request, $id){
Export((new GoodsAuditModel())->exmine($request->input('id'),$request->input('status'),$request->supplier_id));
}
//获取对账单列表明细
private function ApiAccountCheckingDetail($request, $id){
(new ServerFinanceModel($request->appid,$request->key))->accountCheckingDetail($request->input());
......@@ -83,6 +88,10 @@ class ApiController extends Controller
$input['checking_name'] = $request->supplier_name;
(new ServerFinanceModel($request->appid,$request->key))->accountChangeChecking($input);
}
//上传批量修改价格
private function ApiUploadChangePrice($request,$id){
Export((new UploadLogModel())->uploadFile($request->supplier_name));
}
}
<?php
namespace App\Jobs;
use App\Model\OperationLogModel;
use DB;
use App\Jobs\Job;
use App\Model\AbnormalItemsModel;
use App\Model\AbnormalModel;
use App\Model\PurchaseDeliveryItemsModel;
use App\Model\PurchaseModel;
use App\Model\PurDeliveryModel;
use App\Model\SnModel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
/*
* 计算来料异常,存入异常表
*/
class AddAbnormal extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
private $delivery_sn; //来料通知单
private $putaway_sn; //入库单号
private $putaway_id; //入库id
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($delivery_sn,$putaway_sn,$putaway_id)
{
$this->delivery_sn = $delivery_sn;
$this->putaway_sn = $putaway_sn;
$this->putaway_id = $putaway_id;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$purchaseModel= new PurchaseModel();
$abModel = new AbnormalModel();
$abItemModel = new AbnormalItemsModel();
$deliveryModel = new PurDeliveryModel();
$deliveryItem = new PurchaseDeliveryItemsModel();
$strError = "来料通知单:".$this->delivery_sn." 入库单:".$this->putaway_sn ." 入库ID:".$this->putaway_id;//错误提示
try{
$con = DB::connection('web');
$con->beginTransaction();
#判断此来料是否已经是异常
$deliveryArr = $abModel->where('delivery_sn',$this->delivery_sn)->first();
if ($deliveryArr){
$strError .= '已经存在此来料异常';
$con->rollBack();
OperationLogModel::log(0,1,'add_abnormal_error',$this->putaway_id,$this->delivery_sn,$strError);
return $strError;
}
$deliveryArr = $deliveryModel->where('delivery_sn',$this->delivery_sn)->first();
if ($deliveryArr['status'] != 5){ //部分发货情况下是来料异常
$strError .= '此来料不是部分收货状态';
$con->rollBack();
OperationLogModel::log(0,1,'add_abnormal_error',$this->putaway_id,$this->delivery_sn,$strError);
return $strError;
}
$deliveryItemObj = $deliveryItem->where('delivery_id',$deliveryArr['delivery_id'])->get(); //来料明细
if (!$deliveryItemObj){
$strError .= '没有异常数据';
$con->rollBack();
OperationLogModel::log(0,1,'add_abnormal_error',$this->putaway_id,$this->delivery_sn,$strError);
return $strError;
}else{
$deliveryItemArr = $deliveryItemObj->toArray();
$purchaseObj = $purchaseModel->where('picking_sn',current($deliveryItemArr)['picking_sn'])->first(); //来料明细
if (!$purchaseObj){
$strError .= '不存在此采购单:'.current($deliveryItemArr)['picking_sn'];
$con->rollBack();
OperationLogModel::log(0,1,'add_abnormal_error',$this->putaway_id,$this->delivery_sn,$strError);
return $strError;
}
$purchaseArr = $purchaseObj->toArray();
}
$abArr=[
'abnormal_sn'=>(new SnModel())->Sn('abnormal_sn'),
'picking_id'=>$purchaseArr['picking_id'],
'picking_sn'=>$purchaseArr['picking_sn'],
'delivery_id'=>$deliveryArr['delivery_id'],
'delivery_sn'=>$this->delivery_sn,
'putaway_id'=>$this->putaway_id,
'putaway_sn'=>$this->putaway_sn,
'supplier_id'=>$purchaseArr['supplier_id'],
'supplier_code'=>$purchaseArr['supplier_code'],
'supplier_name'=>$purchaseArr['supplier_name'],
'abnormal_type'=>1,
'create_time' =>time()
];
//插入异常主表
$abnormalID = $abModel->insertGetId($abArr); //差异ID
foreach ($deliveryItemArr as $k=>$v){
if ($v['shipping_number'] > $v['putaway_number']){ //大于差异数量才插入
$cha_number = $v['shipping_number']-$v['putaway_number'];
$abItemArr[$k]=[
'abnormal_id'=>$abnormalID,
'picking_items_id'=>$v['picking_items_id'],
'abnormal_number' => $cha_number, //原差异数量
'real_number'=>$cha_number,
'withdraw_amount'=>sprintf('%.6f',$v['picking_price']*$cha_number),
'abnormal_items_type'=>2,
'deal_type1'=>2,
'deal_type2'=>2,
'create_time' =>time()
];
}
}
//插入异常明细表
$abItemModel->BatchADD($abItemArr);
$con->commit();
OperationLogModel::log(0,1,'add_abnormal_success',$this->putaway_id,$this->delivery_sn,$strError);
}catch (\Exception $e) {
$con->rollBack();
OperationLogModel::log(0,1,'add_abnormal_error',0,$this->delivery_sn,json_encode($e->getMessage()).$strError);
}
}
}
<?php
namespace App\Jobs;
use App\Jobs\Job;
use App\Model\PackingModel;
use App\Model\PurchaseDeliveryItemsModel;
use App\Model\PurchaseDeliveryModel;
use App\Model\PurchaseItemsModel;
use App\Model\PurchaseModel;
use App\Model\PurDeliveryItemsModel;
use App\Model\PurDeliveryModel;
use App\Model\SnModel;
use App\Model\UploadLogModel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use DB;
use Illuminate\Support\Facades\Storage;
use League\Flysystem\Exception;
/*
* 快速生成来料通知单
*/
class FastDelivery extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
private $picking_id; //采购单号
private $create_id; //创建用户id
private $shipping_sn; //发货单号
/**
* Create a new job instance.
* @return void
*/
public function __construct($picking_id,$create_id,$shipping_sn)
{
$this->picking_id=$picking_id;
$this->create_id=$create_id;
$this->shipping_sn=$shipping_sn;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$PurchaseModel = new PurchaseModel();
$PurchaseItemsModel = new PurchaseItemsModel();
$PurchaseDeliveryModel=new PurchaseDeliveryModel();
$UploadLogModel=new UploadLogModel();
$PurchaseDeliveryItemsModel = new PurchaseDeliveryItemsModel();
//判断是否符合条件
if ($PurchaseDeliveryModel->checkHas($this->picking_id)){
return "已存在有效的来料通知单,不能在此生成送货单!";
}
#生成任务日志
$logId=$UploadLogModel->insertAndGetId($this->create_id,5,$this->picking_id,[date('Y-m-d H:i',time()). '建立任务']);
if(!$logId){
return "生成任务失败";
}
try{
$con = DB::connection('web');
$con->beginTransaction();
$purchaseInfo = $PurchaseModel->where("picking_id",$this->picking_id)->first();
$purchaseItemsInfo = $PurchaseItemsModel->where("picking_id",$this->picking_id)->where("status",1)->get()->toArray();
$incomingSn = (new SnModel())->Sn('incoming_sn');
#插入来料通知主表
$deliveryId=$PurchaseDeliveryModel->GrDelivery($this->create_id,$incomingSn);
#插入来料通知明细表
$all_picking_number = 0;
foreach ($purchaseItemsInfo as $k=>$v){
$dataArr[]=[
'delivery_id'=>$deliveryId,
'picking_items_id'=>$v['picking_items_id'],
'picking_id'=>$this->picking_id,
'picking_sn'=>$purchaseInfo['picking_sn'],
'packing_id'=>$v['packing_id'],
'delivery_type'=>1,
'sku_id'=>$v['sku_id'],
'goods_name'=>$v['goods_name'],
'brand_id'=>$v['brand_id'],
'brand_name'=>$v['brand_name'],
'picking_price'=>$v['picking_price'],
'initial_price'=>$v['initial_price'], //原始价格
'shipping_number'=>$v['picking_number'],
];
$all_picking_number += $v['picking_number'];
}
$insert1 = $PurchaseDeliveryItemsModel->insert($dataArr);
if(!$insert1){
throw new Exception("插入来料通知明细失败");
}
#更新来料通知
$SpNumber['picking_type']=$purchaseInfo['picking_type'];
$SpNumber['purchase_type']=$purchaseInfo['purchase_type']; //采购类型
$SpNumber['supplier_id']=$purchaseInfo['supplier_id'];
$SpNumber['supplier_code']=$purchaseInfo['supplier_code'];
$SpNumber['supplier_name']=$purchaseInfo['supplier_name'];
$SpNumber['currency']=$purchaseInfo['currency'];
$SpNumber['shipping_sn']=$this->shipping_sn; //客户号,发货单号
$SpNumber['shipping_number']=$all_picking_number;
$update1 = $PurchaseDeliveryModel->SaveDelivery($deliveryId,$SpNumber);
if(!$update1){
throw new Exception("更新来料通知失败");
}
#更新采购单详情的发货总数
foreach ($dataArr as $k=>$v){
$update2 = $PurchaseItemsModel->where('picking_items_id','=',$v['picking_items_id'])->increment('shipping_number',$v['shipping_number']);
if(!$update2){
throw new Exception("更新采购发货总数失败");
}
}
$insert2 = $PurchaseDeliveryModel->PushAmq($incomingSn);
if(!$insert2){
throw new Exception("推送到WMS失败");
}
$UploadLogModel->UpdateLogArr($logId,'执行成功',2,[date('Y-m-d H:i',time()). '执行成功'],['remark'=>$incomingSn]);
$con->commit();
return "success";
}catch (\Exception $e) {
$con->rollBack();
$this->delete();
$UploadLogModel->UpdateLogArr($logId,$e->getMessage(),3,[date('Y-m-d H:i',time()). '执行失败']);
return $e->getMessage();
}
}
}
<?php
namespace App\Jobs;
use App\Model\OperationLogModel;
use App\Model\PreSaleOrderModel;
use App\Model\PurchaseItemsModel;
use App\Model\PurchaseNeedItemsModel;
use App\Model\PurchaseNeedModel;
use App\Model\SnModel;
use App\Model\SupplierChannelModel;
use League\Flysystem\Exception;
use RedisDB;
use App\Jobs\Job;
use App\Model\SafeStockModel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use DB;
class PreSaleOrder extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
private $id;
private $delays;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($id,$delay=true)//默认为延时队列
{
$this->id=$id;
$this->delays=$delay;
}
/**
* Execute the job.
* @return void
*/
public function handle()
{
$Redis=RedisDB::connection();
$QueueID=$Redis->get('Pur_PreSaleOrderQueueID');
if($QueueID!=$this->id && $this->delays===true){
OperationLogModel::log(0,1,'pre_sale_order_queue_error',0,0,"'任务ID对比失败,当前任务终止,当前任务ID:'.$this->id.',记录任务ID:'.$QueueID");
return $this->delete();
}
$time=strtotime(date('Y-m-d',strtotime('+1 day')))+60*60*5+1800;//获取第二天凌晨5点半的时间戳
$delay=$time-time();
if($QueueID==$this->id && $this->delays===true){//重新推送明天的任务
$time=time();
dispatch((new PreSaleOrder($time))->delay($delay));
$Redis->set('Pur_PreSaleOrderQueueID',$time);
}
$this->run();
}
public function run(){
$preSaleOrderModel = new PreSaleOrderModel();
$PurchaseNeedModel = new PurchaseNeedModel();
$PurchaseNeedItemsModel = new PurchaseNeedItemsModel();
#整理数据
if ($this->delays===false){
$saleData = $preSaleOrderModel->whereRaw("is_collect=0 and status=1 ")->get();
}else{
$saleData = $preSaleOrderModel->whereRaw("is_collect=0 and status=1 and create_time < ".dateToTime(date("Y-m-d 00:00:00")))->get();
}
if (!$saleData->count()){
OperationLogModel::log(0,1,'pre_sale_order_queue_error',0,0,"没有超售数据");
return '没有超售数据';
}
$saleDataGroup = arrayGroup($saleData->toArray(),'sku_id');
$SupplierChannelModel = new SupplierChannelModel();
try{
$con = DB::connection('web');
$con->beginTransaction();
$temp = "";
foreach ($saleDataGroup as $sku_id=>$v){
$need_number = array_sum(array_column($v,'need_number'));
#查询旧需求,合并需求
$oldObj = $PurchaseNeedModel->where("status","1")->where("sku_id",$sku_id)->get();
if(!$oldObj->isEmpty()){
$oldArr = $oldObj->toArray();
$need_number = $need_number+array_sum(array_column($oldArr,'need_number')); //汇总
$PurchaseNeedModel->where("status","1")->where("sku_id",$sku_id)->delete(); //删除需求主表
}
#查询最新供应商和采购员
$supplier_id = $supplier_code = $supplier_name = "";
$purchaseInfo = $SupplierChannelModel
->from("purchase as t")
->select(DB::Raw("lie_t.supplier_id,lie_t.supplier_code,lie_t.supplier_name,lie_t.create_uid"))
->join('purchase_items as i', 't.picking_id', '=', 'i.picking_id')
->where("i.sku_id",$sku_id)
->orderBy("i.picking_id","desc")
->first();
$salesname_id = 0;
if ($purchaseInfo) {
$salesname_id = $purchaseInfo['create_uid'] ;
}
if(current($v)['picking_type'] == 1){ //自采
if ($purchaseInfo){
$supplier_id = $purchaseInfo['supplier_id']; //最新供应商
$supplier_code = $purchaseInfo['supplier_code'];
$supplier_name = $purchaseInfo['supplier_name'];
$salesname_id = $purchaseInfo['create_uid'] ;
}
}else{
$supplierObj = $SupplierChannelModel->where("supplier_id",current($v)['supplier_id'])->first();
$supplier_code = $supplierObj['supplier_code'];
$supplier_name = $supplierObj['supplier_name'];
}
#插入purchase_need
$insert1 = [ //需求ID
'picking_type'=>current($v)['picking_type'],
'supplier_id'=>$supplier_id == "" ? current($v)['supplier_id'] : $supplier_id,
'supplier_code'=>$supplier_code,
'supplier_name'=>$supplier_name,
'salesman_id'=>$salesname_id,
'need_sn'=>(new SnModel())->Sn('need_sn'),
'sku_id'=>$sku_id,
'encap'=>current($v)['encap'],
'goods_name'=>current($v)['goods_name'],
'brand_id'=>current($v)['brand_id'],
'brand_name'=>current($v)['brand_name'],
'mpq'=>current($v)['mpq'],
'packing_id'=>current($v)['packing_id'],
'need_number'=>$need_number,
'need_time'=>date("Ymd",current($v)['create_time']),
'create_time'=>time(),
];
// print_r($insert1);
// die();
$needId = $PurchaseNeedModel->insertGetId($insert1);
if (!$needId){
throw new Exception("插入采购需求失败");
}
if(!$oldObj->isEmpty()){
$PurchaseNeedItemsModel->whereIn("need_id",array_column($oldArr,'need_id'))->update(["need_id"=>$needId]); //修改管理需求明细
}
#插入purchase_need_items
$insert2 =[];
foreach ($v as $a=>$b){
array_push($insert2,[
'need_id'=>$needId,
'rec_id'=>@$b['rec_id']
]);
}
$insertStatus = $PurchaseNeedItemsModel->insert($insert2);
if (!$insertStatus){
throw new Exception("插入采购需求明细失败");
}
$temp = $temp.$needId.',';
}
//更新日志状态
if ($this->delays===false){
$update1 = $preSaleOrderModel->whereRaw("is_collect=0 and status=1 ")->update(['is_collect'=>1]);
}else{
$update1 = $preSaleOrderModel->whereRaw("is_collect=0 and status=1 and create_time < ".dateToTime(date("Y-m-d 00:00:00")))->update(['is_collect'=>1]);
}
OperationLogModel::log(0,1,'pre_sale_order_queue_success',0,0,"超售统计任务成功,插入purchase_need 的id为:$temp"); //日志
$con->commit();
return "success,插入purchase_need 的id为:$temp";
}catch (\Exception $e) {
$con->rollBack();
OperationLogModel::log(0,1,'pre_sale_order_queue_error',0,0,"超售统计任务统计失败:".$e->getMessage()); //日志
return "error:".$e->getMessage();
}
}
}
<?php
namespace App\Jobs;
use App\Jobs\Job;
use App\Model\PackingModel;
use App\Model\PurchaseModel;
use App\Model\PutawayItemsModel;
use App\Model\PutawayModel;
use App\Model\SupplierChannelModel;
use App\Model\SupplierReceiptModel;
use App\Model\UploadLogModel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use DB;
class PushFinancePeriod extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
private $id;
private $admin;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($ID,$admin)
{
$this->id=$ID;
$this->admin=$admin;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$LogModel=new UploadLogModel();
$data['remark']=$this->id;
$Log=[date('Y-m-d H:i',time()). '建立任务'];
$data['log']=json_encode($Log);
$data['create_time']=time();
$data['update_time']=time();
$data['type']=3;
$data['admin_id']=$this->admin;
$result=$LogModel->insertGetId($data);
if(!$result) return $this->delete();
$LogID=$result;
$PutawayModel=new PutawayModel();
$PutawayInfo=$PutawayModel->where('putaway_id','=',$this->id)->select('delivery_sn','putaway_sn','picking_type','purchase_type','supplier_id','pay_status')->first();//查入库主表
if(!$PutawayInfo) return $LogModel->UpdateLogArr($LogID,'没有找到这个入库单',3,$Log);
$PutawayInfo=$PutawayInfo->toArray();
//样品\赠品采购不需要推送账期
if ($PutawayInfo['purchase_type'] != 1){
return $LogModel->UpdateLogArr($LogID,'样品\赠品采购不需要推送账期',3,$Log);
}
//$this->closeOrder($PutawayInfo['delivery_sn']); //关闭来料通知,hcy9.12
if($PutawayInfo['pay_status']!=1 && $PutawayInfo['pay_status']!=4) return $LogModel->UpdateLogArr($LogID,'该入库单已经处理',3,$Log);
if($PutawayInfo['picking_type']!=1){//不是自营
$result=$PutawayModel->where('putaway_id','=',$this->id)->update(['pay_status'=>3]);
if(!$result) return $LogModel->UpdateLogArr($LogID,'非自营采购单处理失败',3,$Log);
return $LogModel->UpdateLogArr($LogID,'非自营采购单处理成功',2,$Log);
}
$PurchaseModel=new PurchaseModel();
$PutawayItemsModel=new PutawayItemsModel();
$PuItemArr=['picking_id','putaway_items_id','picking_sn','picking_items_id','sku_id','goods_name','brand_id','brand_name','encap','mpq','packing_id',
'picking_price','putaway_number'];
$PutawayList=$PutawayItemsModel->where('putaway_id','=',$this->id)->select($PuItemArr)->get()->toArray();//查出所有的采购商品
$PurArr=['picking_sn','picking_id','purchaser_id','supplier_id','supplier_code','supplier_name','pay_type','day_num','currency',
'picking_amount','picking_info','status'];
$PurchaseInfo=$PurchaseModel->where('picking_id','=',$PutawayList[0]['picking_id'])->select($PurArr)->first();//查采购单信息
if(!$PurchaseInfo) return $LogModel->UpdateLogArr($LogID,'没有找到这个采购单',3,$Log);
$PurchaseInfo=$PurchaseInfo->toArray();
//todo 入库时间
$PurchaseInfo['create_time'] = $PutawayInfo['create_time'];
if($PurchaseInfo['pay_type']!=1 && $PurchaseInfo['pay_type']!=2){//不是账期订单
$result=$PutawayModel->where('putaway_id','=',$this->id)->update(['pay_status'=>3]);
if(!$result){
return $LogModel->UpdateLogArr($LogID,'处理非账期入库单失败',3,$Log);
}else{
return $LogModel->UpdateLogArr($LogID,'处理非账期入库单成功',2,$Log);
}
}
$PurchaseInfo['picking_info']=json_decode($PurchaseInfo['picking_info'],true);
$PurchaseInfo['settle_party']=$PurchaseInfo['picking_info']['agent_type'];
$PurchaseInfo['putaway_id']=$this->id;
$PurchaseInfo['putaway_sn']=$PutawayInfo['putaway_sn'];
$SuArr=['supplier_consignee','supplier_telephone','supplier_mobile'];
$SuModel=new SupplierChannelModel();
$supplier_address = $SuModel->where('supplier_id', $PurchaseInfo['supplier_id'])->select($SuArr)->first();//查供应商信息
$PurchaseInfo['supplier_consignee'] = $supplier_address['supplier_consignee'];//联系人
$PurchaseInfo['supplier_telephone'] = empty($supplier_address['supplier_telephone'])?$supplier_address['supplier_mobile']:$supplier_address['supplier_telephone'];//联系电话
$PackingModel=new PackingModel();
$PackingList=$PackingModel->PackingList();
$PurchaseInfo['putaway_amount']=0;
foreach ($PutawayList as $k=>$v){
$v['putaway_price']=$v['picking_price'];
$v['packing_name']=empty($PackingList[$v['packing_id']])?'':$PackingList[$v['packing_id']];
$PurchaseInfo['putaway_amount'] +=$v['picking_price']*$v['putaway_number'];
unset($v['picking_price']);
unset($v['packing_id']);
$PurchaseInfo['sb_items'][$k]=$v;
}
$PurchaseInfo['putaway_amount']=round($PurchaseInfo['putaway_amount'],2);
unset($PurchaseInfo['picking_info']);
unset($PurchaseInfo['purchaser_id']);
$SupplierReModel=new SupplierReceiptModel();
$SuArr=['bank_name','bank_adderss','account_no','bank_code','branch_no','swift_code','account_name','account_adderss'];
$supplier_data = $SupplierReModel->where('supplier_id', $PurchaseInfo['supplier_id'])->select($SuArr)->first();
if(!$supplier_data) return false;
$supplier_data=$supplier_data->toArray();
DB::connection('web')->beginTransaction();
$result=$PutawayModel->where('putaway_id','=',$this->id)->update(['pay_status'=>2]);
if(!$result){
DB::connection('web')->rollback();
return $LogModel->UpdateLogArr($LogID,'更新支付状态失败',3,$Log);
}
//todo 不需要同步采购状态,hcy 2018.12.07
// if($PurchaseInfo['status']==6 || $PurchaseInfo['status']==10){
// $pay_status=$PurchaseInfo['status']==10?1:4;
// $PurchaseModel->where('picking_id','=',$PurchaseInfo['picking_id'])->update(['pay_status'=>$pay_status]);
// }
$PurchaseInfo['supplier']=$supplier_data;
$CurlData['data']=$PurchaseInfo;
$CurlData['data']=urlencode(json_encode($CurlData['data']));
$CurlData['timestamp']=time();
$token=WMSencryption($CurlData);
$url=Config('website.FinanceUrl').'/webapi/pushAccountPeriodOrders?token='.$token;
$result=curl($url,$CurlData,true);
$result=json_decode($result,true);
if(isset($result['err_code']) && $result['err_code']==0){
DB::connection('web')->commit();
return $LogModel->UpdateLogArr($LogID,'推送付款单成功',2,$Log);
}else{
DB::connection('web')->rollback();
$ErrInfo='财务系统返回失败';
$ErrInfo .=empty($result['err_msg'])?'无':$result['err_msg'];
$result=$PutawayModel->where('putaway_id','=',$this->id)->update(['pay_status'=>4]);
if(!$result){
return $LogModel->UpdateLogArr($LogID,$ErrInfo.',状态未记录',3,$Log);
}else{
return $LogModel->UpdateLogArr($LogID,$ErrInfo,3,$Log);
}
}
}
/*
* 关闭来料通知
*/
private function closeOrder($delivery_sn){
#完成wms采购单
$dataWms['type'] = 'cancelinstockorder';
$dataWms['from'] = 'purchase';
$dataWms['to'] = 'wms';
$dataWms['Timestamp'] = time();
$dataWms['jsonParas'] = json_encode(array('entity' => array(array('delivery_sn' =>$delivery_sn,'userid'=>0,'status'=>1))));
$colose = curl(Config('website.WmsServiceUrl'), http_build_query($dataWms), true,false,'');
$coloseRes = json_decode($colose,true);
if(empty($coloseRes['entity'][0]['Status'])){
return [30115,'来料通知单关闭失败,请与仓库人员确认来料通知单的处理情况后再作处理'];
}
return true;
}
}
<?php
namespace App\Jobs;
use App\Model\PurchaseModel;
use RedisDB;
use App\Jobs\Job;
use App\Model\SafeStockModel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class SafeStock extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
private $id;
private $delays;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($id,$delay=true)//默认为延时队列
{
$this->id=$id;
$this->delays=$delay;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$Redis=RedisDB::connection();
$QueueID=$Redis->get('Pur_SafeStockQueueID');
if($QueueID!=$this->id && $this->delays===true){
$Ding['su']=0;
$Ding['fail']=0;
$Ding['count']=0;
$Ding['info']=urlencode('任务ID对比失败,当前任务终止,当前任务ID:'.$this->id.',记录任务ID:'.$QueueID);
$Ding['yes_day']=date('Y-m-d H:i:s');
SendAlarmMsg($Ding,'PurSafeStock',['ymx@ichunt.com','hcy@ichunt.com']);
return $this->delete();
}
$time=strtotime(date('Y-m-d',strtotime('+1 day')))+60*60*5;//获取第二天凌晨5点的时间戳
$delay=$time-time();
if($QueueID==$this->id && $this->delays===true){//重新推送明天的任务
$time=time();
dispatch((new SafeStock($time))->delay($delay));
$Redis->set('Pur_SafeStockQueueID',$time);
}
$count=100;
$SafeModel=new SafeStockModel();
$PurModel=new PurchaseModel();
$fail=0;
$su=0;
$i=0;
for ($p=1;$p<$count;$p++){
$data['data']=['p'=>$p];
$data['data']=urlencode(json_encode($data['data']));
$data['timestamp']=time();
$token=WMSencryption($data);
$list=json_decode(curl(GenerateApiUrl('http://','footstone').'/wmsapi/WebApiSafeStock?token='.$token,$data,true),true);
if(!$list){
$Ding['su']=$su;
$Ding['fail']=$fail;
$Ding['count']=$i;
$Ding['yes_day']=date('Y-m-d H:i:s');
SendAlarmMsg($Ding,'PurSafeStock',['ymx@ichunt.com','hcy@ichunt.com']);
return $this->delete();
}
$Arr=['goods_id'=>'sku_id','status'=>'goods_status','packing'=>'packing_id'];
$count=$list['total']+1;
foreach ($list['data'] as $k=>$v){
$i++;
foreach ($v as $k1=>$v1){
if(!empty($Arr[$k1])){
$list['data'][$k][$Arr[$k1]]=$v[$k1];
unset($list['data'][$k][$k1]);
}
}
$list['data'][$k]['update_time']=time();
$find=$SafeModel->where('sku_id','=',$list['data'][$k]['sku_id'])->select()->first();
if($find){
$info=$PurModel->whereIn('purchase.status',[4,6])->join('purchase_items',function($join) use ($v){
$join->on('purchase.picking_id','=','purchase_items.picking_id')->where('purchase_items.sku_id','=',$v['goods_id']);
})->select('purchase_items.picking_number','purchase_items.shipping_number','purchase_items.putaway_number')->get()->toArray();
if(!$info){
$list['data'][$k]['purchase_num']=0;
$list['data'][$k]['in_num']=0;
}else{
$CountPur=0;
$CountIn=0;
$CountPt=0;
foreach ($info as $k1=>$v1){
$CountPur +=$v1['picking_number'];
$CountIn +=$v1['shipping_number'];
$CountPt +=$v1['putaway_number'];
}
$list['data'][$k]['purchase_num']=$CountPur-$CountPt;
$list['data'][$k]['in_num']=$CountIn-$CountPt;
}
$result=$SafeModel->where('sku_id','=',$list['data'][$k]['sku_id'])->update($list['data'][$k]);
}else{
$list['data'][$k]['create_time']=time();
$result=$SafeModel->insert($list['data'][$k]);
}
if(!$result){
$fail++;
}else{
$su++;
}
}
}
$Ding['su']=$su;
$Ding['fail']=$fail;
$Ding['count']=$i;
$Ding['info']=urlencode('下一个任务ID为:'.$Redis->get('Pur_SafeStockQueueID'));
$Ding['yes_day']=date('Y-m-d H:i:s');
SendAlarmMsg($Ding,'PurSafeStock',['ymx@ichunt.com','hcy@ichunt.com']);
}
}
<?php
namespace App\Jobs;
use App\Jobs\Job;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
class SysLog extends Job implements ShouldQueue
{
use InteractsWithQueue, SerializesModels;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct($adminID,$table,$id,$log)
{
$this->AdminID=$adminID;
$this->table=$table;
$this->id=$id;
$this->log=$log;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
}
}
......@@ -50,18 +50,28 @@ class GoodsAuditModel extends Model
}
/*
* 价格审核
* @param int $id 审核id
* @param array $id 审核id,[1]
* @param int $status 状态:-1审核驳回 0 未审核 1:审核通过
*/
public function exmine($id,$status){
public function exmine($ids,$status,$supplier_id){
if(!in_array($status,[-1,0,1])){
return [1001,'状态不正确'];
return [1001,'状态不正确!'];
}
$info = $this->where("id",$id)->first();
if (!$info){
return [1002,'不存在此账号'];
$idsArr = explode(',',$ids);
$info = $this->select("id","status")->where("supplier_id",$supplier_id)->whereIn("id",$idsArr)->get();
if ($info->count() != count($idsArr) ){
return [1002,'不存在记录id!'];
}
$this->where("id",$id)->update(['status'=>$status]);
foreach ($info->toArray() as $k=>$v){
if ($v['status'] != 0){
return [1003,'ID:'.$v['id']."不得重复审核!"];
}
}
if ($status == 1){
//todo 审核通过,需要通知基石
}
$this->whereIn("id",explode(',',$ids))->update(['status'=>$status]);
return [0,"审核成功"];
}
......
......@@ -10,7 +10,7 @@ use DB;
class LogOperationModel extends Model
{
protected $connection='yunxin';
protected $table='log_operation';
protected $table='operation_log';
protected $primaryKey='id';
public $timestamps = false;
......
......@@ -74,7 +74,7 @@ class SupplierAccountModel extends Model
$log['action_ip'] = $request->getClientIp();
$log['create_time'] = time();
$log['remark'] = utf8JsonEncode($info);
$logid = $yunxinCon->table("log_login")->insertGetId($log);
$logid = $yunxinCon->table("login_log")->insertGetId($log);
if (!$logid){
throw new Exception('插入日志失败',1005);
}
......
......@@ -2,10 +2,13 @@
namespace App\Model;
use App\Jobs\UploadChangePrice;
use Illuminate\Database\Eloquent\Model;
use RedisDB;
use Request;
use App\map\UploadLogMap;
use Illuminate\Support\Facades\Storage;
use DB;
class UploadLogModel extends Model
{
......@@ -34,4 +37,84 @@ class UploadLogModel extends Model
return [0,'成功',$list['data'],$list['total']];
}
public function LogInfo($up_id){
if(empty($up_id)) return false;
$info=$this->where('up_id','=',$up_id)->first();
$info && $info=$info->toArray();
return $info;
}
public function UpdateLog($up_id,$data){
if(empty($up_id)) return false;
if(empty($data)) return false;
$result=$this->where('up_id','=',$up_id)->update($data); //debug
if(!$result) return false;
return true;
}
public function UpdateLogArr($up_id,$info,$status='',$Log,$data=[]){
if(empty($up_id)) return false;
$data['update_time'] = time();
$Log[] = date('Y-m-d H:i',$data['update_time']).$info;
$data['log'] = json_encode($Log, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
empty($status) || $data['status']=$status;
$result=$this->where('up_id','=',$up_id)->update($data); //debug
if(!$result) return false;
return true;
}
//生成的文件上传到OSS
public function SaveDownFile($FileName=''){
if(empty($FileName)) return false;
$result=json_decode(UploadToOss(storage_path().DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'uploads'.DIRECTORY_SEPARATOR.$FileName),true);
if(empty($result['code']) || $result['code'] != 200 || empty($result['data'][0])) return false;
return $result['data'][0];
}
//上传文件
public function uploadFile($create_name = ''){
$file = Request::file('file');
if ($file->isValid()) {
$ext = $file->getClientOriginalExtension();
$realPath = $file->getRealPath();
if($ext!='csv'){
$this->Export(10001,'上传格式错误');
}
// 上传文件
$filename = date('Y-m-d-H-i-s') . '-' . uniqid() . '.' . $ext;
// 使用新建的uploads本地存储空间(目录)
$bool = Storage::disk('uploads')->put($filename, file_get_contents($realPath));
if(!$bool) return [10002,'文件处理失败'];
$filePath = storage_path().DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'uploads'.DIRECTORY_SEPARATOR.$filename;
$result=json_decode(UploadToOss($filePath),true);
Storage::disk('uploads')->delete($filename);
if(!empty($result['code']) && $result['code']==200 && !empty($result['data'][0])){
$data['file_path']= $result['data'][0];
$data['log']=json_encode([
date('Y-m-d H:i',time()). '建立任务'
]);
$data['create_time'] = $data['update_time'] =time();
$data['create_name'] = $create_name;
$data['type']=1;
DB::connection($this->connection)->beginTransaction();
$insert=$this->insertGetId($data);
if($insert){
$return=dispatch(new UploadChangePrice($insert));
if($return){
DB::connection($this->connection)->commit();
return [0,'上传成功,请等待系统自动处理'];
}else{
return [10004,'上传失败'];
}
}else{
return [10003,'上传失败'];
}
}else{
return [10002,'上传失败'];
}
}else{
return [10005,'上传失败'];
}
}
}
;!function () {
var ids = []; //选择的ids
var table_data = [];
window.app = {
init: function () {
app.tableList();
//刷新搜索
app.checkbox();
//刷新列表
$("#search").click(function () {
console.log($("#form1").serialize())
app.tableList()
})
//审核通过
$("#exmine_pass").click(function () {
app.exmine(1)
})
//审核驳回
$("#exmine_no").click(function () {
app.exmine(-1)
})
},
tableList:function () {
layui.table.render({
......@@ -24,6 +34,7 @@
,last: false //不显示尾页
,cols: [[
{field:'id', title: '全选',type:'checkbox',align:'center'}
,{field:'id', title: 'ID',align:'center'}
,{field:'goods_code', title: '商品编码',align:'center'}
,{field:'goods_name', title: '商品型号',align:'center'}
,{field:'brand_name', title: '品牌名称',align:'center'}
......@@ -51,10 +62,49 @@
} else {
$('.export').removeClass('layui-disabled');
}
//设置全部数据到全局变量
table_data=res.data;
}
});
},
exmine:function (status) { //审核操作
var msg = status == 1 ? "确定审核通过?" : "确定审核驳回?";
alert_confirm(msg,function () {
if(ids.length == 0){
alert_err("请勾选记录")
return false;
}
var res = ajax_push('/api/ApiGoodsAuditExmine',{id:ids.join(','),'status':status})
res.errcode > 0 ? alert_err(res.errmsg) : alert_succ(res.errmsg,function () {
app.tableList();
})
})
},
checkbox:function () { //多选全选
layui.table.on('checkbox(test)', function (obj) {
if(obj.checked==true){
if(obj.type=='one'){
ids.push(obj.data.id);
}else if(obj.type=='all'){
ids = [];
for(var i=0;i<table_data.length;i++){
ids.push(table_data[i].id);
}
}
}else{
if(obj.type=='one'){
for(var i=0;i<ids.length;i++){
if(ids[i]==obj.data.id){
ids.splice(i, 1)
}
}
}else if(obj.type=='all') {
ids = [];
}
}
// console.log(JSON.stringify(ids))
});
}
}, $(function () {
app.init();
})
......
;!function () {
var ids = []; //选择的ids
var table_data = [];
window.app = {
init: function () {
app.tableList();
app.checkbox();
app.uploadChangePrice();
//刷新列表
$("#search").click(function () {
app.tableList()
})
//审核通过
$("#exmine_pass").click(function () {
app.exmine(1)
})
//审核驳回
$("#exmine_no").click(function () {
app.exmine(-1)
})
},
tableList:function () {
layui.table.render({
elem: '#list'
,url:'/api/ApiGoodsAuditList'
,method:'post'
,cellMinWidth: 100 //全局定义常规单元格的最小宽度
,request: {
pageName: 'p' //页码的参数名称,默认:page
,limitName: 'limit' //每页数据量的参数名,默认:limit
}
,where: formJson('form1')
,loading:true
,first: true //不显示首页
,last: false //不显示尾页
,cols: [[
{field:'id', title: '全选',type:'checkbox',align:'center'}
,{field:'goods_code', title: '商品编码',align:'center'}
,{field:'goods_name', title: '商品型号',align:'center'}
,{field:'brand_name', title: '品牌名称',align:'center'}
,{field:'status', title: '状态',align:'center'}
,{field:'encap', title: '封装',align:'center'}
,{field:'packing', title: '包装方式',align:'center'}
,{field:'mpq', title: '标准包装量',align:'center'}
,{field:'last_price', title: '原始售价',align:'center'}
,{field:'new_price', title: '最新售价',align:'center'}
,{field:'create_name', title: '创建人',align:'center'}
,{field:'create_time', title: '创建时间',align:'center'}
,{field:'deal_name', title: '处理人',align:'center'}
,{field:'deal_time', title: '处理人名称',align:'center'}
,{field:'remark', title: '备注',align:'center'}
//,{field:'cahe', title: '操作',templet:'#cahe',width:150,align:'center', fixed: 'right'}
]]
,id:'Abnormal'
,page:{
}
,done: function(res, curr, count) {
// 若无数据,则禁用导出按钮
if (!count) {
$('.export').addClass('layui-disabled');
} else {
$('.export').removeClass('layui-disabled');
}
//设置全部数据到全局变量
table_data=res.data;
}
});
},
uploadChangePrice:function () { //审核操作
//执行实例
var uploadInst = layui.upload.render({
elem: '#BatchAdd' //绑定元素
,url: '/api/ApiUploadChangePrice' //上传接口
,accept:'file'
,exts:'csv'
,done: function(res){
if(!res) return layer.msg('网络连接失败,请重试',{icon:6});
return layer.msg(res.errmsg,{icon:6});
}
,error: function(){
return layer.msg('上传异常',{icon:5});
}
});
},
checkbox:function () { //多选全选
layui.table.on('checkbox(test)', function (obj) {
if(obj.checked==true){
if(obj.type=='one'){
ids.push(obj.data.id);
}else if(obj.type=='all'){
ids = [];
for(var i=0;i<table_data.length;i++){
ids.push(table_data[i].id);
}
}
}else{
if(obj.type=='one'){
for(var i=0;i<ids.length;i++){
if(ids[i]==obj.data.id){
ids.splice(i, 1)
}
}
}else if(obj.type=='all') {
ids = [];
}
}
// console.log(JSON.stringify(ids))
});
}
}, $(function () {
app.init();
})
}();
\ No newline at end of file
......@@ -26,6 +26,18 @@
<span>查询</span>
</a>
</div>
<div class="lineBlock input-inline va-m" id="exmine_pass">
<a href="javascript:;" class="search-btn">
<i class="iconfont icon-chaxun-"></i>
<span>审核通过</span>
</a>
</div>
<div class="lineBlock input-inline va-m" id="exmine_no">
<a href="javascript:;" class="search-btn">
<i class="iconfont icon-chaxun-"></i>
<span>审核驳回</span>
</a>
</div>
</div>
</form>
<div class="table-list" id="shopList">
......
<div class="lx-content-r fr">
<div class="tit-bar">
<a href="">商品管理</a>
<a href="">订单管理</a>
<span>&gt;</span>
<a class="text" href="">商品列表</a>
<a class="text" href="">{{ $title }}</a>
</div>
<div class="con-section shop-list">
<p class="text">商品列表</p>
<form action="">
<p class="text">{{ $title }}</p>
<form action="" id="form1">
<div class="search-bar">
<div class="lineBlock input-inline va-m">
<label class="tag">商品编码:</label>
<input type="text" class="inp w180">
<input type="text" class="inp w180" name="order_sn" >
</div>
<div class="lineBlock input-inline va-m">
<label class="tag">商品型号:</label>
<input type="text" class="inp w180">
<label class="tag">型号:</label>
<input type="text" class="inp w180" name="goods_name">
</div>
<div class="lineBlock input-inline va-m">
<label class="tag">品牌:</label>
<select class="sel w180">
<option value="">品牌1</option>
<option value="">品牌2</option>
<option value="">品牌3</option>
</select>
<input type="text" class="inp w180" name="brand_name">
</div>
<div class="lineBlock input-inline va-m mr0">
<div class="lineBlock input-inline va-m" id="search">
<a href="javascript:;" class="search-btn">
<i class="iconfont icon-chaxun-"></i>
<span>查询</span>
</a>
</div>
<div class="lineBlock input-inline va-m" id="BatchAdd">
<a href="javascript:;" class="search-btn">
<i class="iconfont icon-chaxun-"></i>
<span>批量修改价格</span>
</a>
</div>
<div class="lineBlock input-inline va-m" id="exmine_no">
<a href="javascript:;" class="search-btn">
<i class="iconfont icon-chaxun-"></i>
<span>模板下载</span>
</a>
</div>
<div class="lineBlock input-inline va-m" id="exmine_no">
<a href="javascript:;" class="search-btn">
<i class="iconfont icon-chaxun-"></i>
<span>导出</span>
</a>
</div>
</div>
</form>
<div class="table-list" id="shopList">
<table>
<tbody>
<tr>
<th>商品编码<b></b></th>
<th>商品型号<b></b></th>
<th>封装<b></b></th>
<th>包装方式<b></b></th>
<th>品牌<b></b></th>
<th>状态<b></b></th>
<th>操作</th>
</tr>
<tr>
<td>
<span class="t1">11033</span>
</td>
<td>
<span class="t1">STM32F103C8T6</span>
</td>
<td>
<span class="t1">1000</span>
</td>
<td>
<span class="t1">袋装</span>
</td>
<td>
<span class="t1">品牌</span>
</td>
<td>
<span class="t1">上架</span>
</td>
<td>
<a href="javascript:;" class="operation-1">
<i class="iconfont icon-mingxi-"></i>
<em>价格变化明细</em>
</a>
</td>
</tr>
<tr>
<td>
<span class="t1">11033</span>
</td>
<td>
<span class="t1">STM32F103C8T6</span>
</td>
<td>
<span class="t1">1000</span>
</td>
<td>
<span class="t1">袋装</span>
</td>
<td>
<span class="t1">品牌</span>
</td>
<td>
<span class="t1">上架</span>
</td>
<td>
<a href="javascript:;" class="operation-1">
<i class="iconfont icon-mingxi-"></i>
<em>价格变化明细</em>
</a>
</td>
</tr>
<tr>
<td>
<span class="t1">11033</span>
</td>
<td>
<span class="t1">STM32F103C8T6</span>
</td>
<td>
<span class="t1">1000</span>
</td>
<td>
<span class="t1">袋装</span>
</td>
<td>
<span class="t1">品牌</span>
</td>
<td>
<span class="t1">上架</span>
</td>
<td>
<a href="javascript:;" class="operation-1">
<i class="iconfont icon-mingxi-"></i>
<em>价格变化明细</em>
</a>
</td>
</tr>
</tbody>
</table>
<table class="layui-table" lay-filter="test" id="list"></table>
</div>
<div class="pagination-with" id="pagination"><div class="layui-box layui-laypage layui-laypage-molv" id="layui-laypage-1"><a href="javascript:;" class="layui-laypage-prev layui-disabled" data-page="0">上一页</a><span class="layui-laypage-curr"><em class="layui-laypage-em" style="background-color:#1080d0;"></em><em>1</em></span><a href="javascript:;" data-page="2">2</a><a href="javascript:;" data-page="3">3</a><a href="javascript:;" data-page="4">4</a><a href="javascript:;" data-page="5">5</a><a href="javascript:;" data-page="6">6</a><a href="javascript:;" data-page="7">7</a><a href="javascript:;" data-page="8">8</a><a href="javascript:;" data-page="9">9</a><a href="javascript:;" data-page="10">10</a><span class="layui-laypage-spr"></span><a href="javascript:;" class="layui-laypage-last" title="尾页" data-page="50">50</a><a href="javascript:;" class="layui-laypage-next" data-page="2">下一页</a></div></div>
<div class="pagination-with" id="pagination"></div>
</div>
</div>
\ No newline at end of file
</div>
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