12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?php
- namespace App\Console\Commands;
- use Illuminate\Console\Command;
- use DB;
- use App\OrderGoodsSkus;
- use App\GoodsSkus;
- use App\Order;
- use App\RedisModel;
- use YPSMS;
- class MonitorSkuToRedis extends Command {
- protected $signature = 'MonitorSkuToRedis';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '监控预占库存';
- public function handle()
- {
- $this->MonitorSkuToRedis();
-
- }
- public function MonitorSkuToRedis(){
- echo "\nStart: ".date('Y-m-d H:i:s');
- $order_ids = Order::where('warehouse', 3)->where('is_del', 0)->whereNull('orderCode')->lists('id');
- $res = OrderGoodsSkus::select(DB::raw('sum(num) as num , sku_id'))->whereIn('order_id', $order_ids)->where('mj_status', 0)->where('is_del', 0)->groupBy('sku_id')->get();
- $res = json_decode(json_encode($res), true);
- $sku_arr = array();
- foreach($res as $k=>$v){
- $sku_arr[$v['sku_id']] = $v['num'];
- }
- $order_ids = DB::table('seafood_fx.order')->where('warehouse', 3)->where('is_del', 0)->whereNull('orderCode')->lists('id');
- if(!empty($order_ids)){
- $res = DB::table('seafood_fx.order_goods_skus')->select(DB::raw('sum(num) as num , sku_id'))->whereIn('order_id', $order_ids)->where('mj_status', 0)->where('is_del', 0)->groupBy('sku_id')->get();
- $res = json_decode(json_encode($res), true);
- foreach($res as $k=>$v){
- if(isset($sku_arr[$v['sku_id']])){
- $sku_arr[$v['sku_id']] += $v['num'];
- }else{
- $sku_arr[$v['sku_id']] = $v['num'];
- }
- }
- }
- $order_ids = DB::table('seafood_fx2.order')->where('warehouse', 3)->where('is_del', 0)->whereNull('orderCode')->lists('id');
- if(!empty($order_ids)){
- $res = DB::table('seafood_fx2.order_goods_skus')->select(DB::raw('sum(num) as num , sku_id'))->whereIn('order_id', $order_ids)->where('mj_status', 0)->where('is_del', 0)->groupBy('sku_id')->get();
- $res = json_decode(json_encode($res), true);
- foreach($res as $k=>$v){
- if(isset($sku_arr[$v['sku_id']])){
- $sku_arr[$v['sku_id']] += $v['num'];
- }else{
- $sku_arr[$v['sku_id']] = $v['num'];
- }
- }
- }
- $redis_table = config('constants.SKU_QUANTITY_TABLE');
- foreach($sku_arr as $key=>$val){
- $code = GoodsSkus::where('id', $key)->pluck('code');
- $sku_redis_val = RedisModel::hGet($redis_table, $code);
- if($val != $sku_redis_val){
- echo "\nWARNING_Sku: ". $key.' '.$code.' true_num->redis_num:'.$val.' -> '.$sku_redis_val;
- $msg = '规格:'.$code. ',真实预占库存:'.$val.',Redis值:'.$sku_redis_val;
- YPSMS::sendSkuWnum('18501257479', $msg);
- }else{
- //echo "\nSUCCESS_Sku: ". $key.' '.$code.' true_num->redis_num:'.$val.' -> '.$sku_redis_val;
- }
- }
- }
- }
|