erp/app/queue/redis/PushPlatformPrintSend.php

66 lines
2.6 KiB
PHP

<?php
namespace app\queue\redis;
use app\admin\logic\operation\OpurchaseclassLogic;
use app\common\model\goods\Goods;
use app\common\model\goods\Unit;
use app\common\model\merchant\Merchant;
use app\common\model\opurchase\Opurchaseinfo;
use app\common\model\retail\Cashierclass;
use app\common\model\retail\Cashierinfo;
use app\common\model\user\User;
use app\common\service\PushService;
use Webman\RedisQueue\Consumer;
use Webman\Push\Api;
use support\exception\BusinessException;
use support\Log;
use think\facade\Db;
/**
* 零售订单推送给后台
*/
class PushPlatformPrintSend implements Consumer
{
// 要消费的队列名
public $queue = 'push-platform-print';
// 连接名,对应 plugin/webman/redis-queue/redis.php 里的连接`
public $connection = 'default';
// 消费
public function consume($data)
{
$id=$data['order_id']??0;
Log::info('打印推送开始'.$id);
if(!$id)return false;
$find = Cashierclass::where('id', $id)->where('is_print',0)->field('id,merchant,real_name,user_phone,user_address,uid,number,total,actual,create_time')->find();
if ($find) {
$merchant = Merchant::where('mer_id', $find['merchant'])->field('mer_name,uid,service_phone')->find();
$mer_user_info = User::where('id', $merchant['uid'])->field('real_name,mobile')->find();
$user = User::where('id', $find['uid'])->field('nickname,mobile')->find();
$find['mer_name'] = $merchant['mer_name'];
$find['mer_phone'] = $merchant['service_phone'];
$find['mer_nickname'] = $mer_user_info['real_name'];
$find['mer_user_mobile'] = $mer_user_info['mobile'];
$find['nickname'] = $user['nickname'];
$find['user_mobile'] = $user['mobile'];
$find['info'] = Cashierinfo::where('pid', 445)->field('goods,nums,price,total')->select()->each(function ($item) {
$goods = Goods::where('id', $item['goods'])->field('name,unit')->find();
$item['unit_name'] = Unit::where('id', $goods['unit'])->value('name');
$item['goods_name'] = $goods['name'];
return $item;
});
PushService::push('platform_1', 1, ['type'=>'platform_print','msg'=>'打印队列','data'=>$find]);
Log::info('打印推送结束'.$id);
}
}
public function onConsumeFailure(\Throwable $exception, $package)
{
if($package['attempts'] ==$exception['max_attempts']){
Log::error('打印队列推送失败。order_id:'. $package['data']['order_id']??0);
}
return $package;
}
}