baji/app/command/FlwOpen.php
2025-03-04 21:49:31 +08:00

173 lines
7.0 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\command;
use app\common\model\CardLevel;
use app\common\model\Goods;
use app\common\model\GoodsLock;
use app\common\model\ItemCard;
use app\common\model\OrderListSend;
use app\common\model\OrderSale;
use app\common\model\ProductOrder;
use app\common\model\ProductOrderList;
use app\common\model\ProfitPay;
use app\common\model\Shang;
use app\common\model\User;
use app\common\model\UserLevelCoupon;
use app\common\model\UserRecharge;
use app\common\model\Ads;
use app\common\model\CouponReceive as CouponReceiveModel;
use app\common\model\GoodsExtendList as GoodsExtendListModel;
use think\facade\Log;
use app\common\model\GoodsList;
use app\common\model\Order;
use app\common\model\OrderList;
use app\api\controller\Notify;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
use think\facade\Db;
class FlwOpen extends Command
{
static $shang_prize_id = [10, 33];#抽奖赏品id
static $shang_give_first_id = 1;#赠送(FIRST赏)赏品id
static $shang_give_arr = [2, 3, 4];#赠送(LAST赏 最终赏 全局赏)赏品id
static $shang_give_w_id = 4;#赠送(全局赏)赏品id
static $shang_give_quan_id = 5;#赠送(拳王赏)赏品id
static $secretKey = null;
static $secretKeyAccount = null;
protected function configure()
{
$this->setName('FlwOpen')->setDescription('福利屋开奖');
}
protected function execute(Input $input, Output $output)
{
//php /www/wwwroot/xinglanmh.shequtuangou.vip think FlwOpen
$time = date('Y-m-d H:i:s', time());
Log::info('福利屋开奖' . $time);
Log::info('福利屋开奖' . $time);
Log::info('福利屋开奖' . $time);
print('福利屋开奖' . $time);
print('福利屋开奖' . $time);
print_r(time());
// $notify=new Notify();
//cd /www/wwwroot/xinglanmh.shequtuangou.vip && php think FlwOpen
$goodslist = Goods::where('status', 1)->where('is_flw', 1)->where('is_open', 0)->select()->toArray();
foreach ($goodslist as $k => $v) {
Log::info('福利屋开奖$goods_id' . $v['id']);
Log::info('福利屋开奖open_time' . date('Y-m-d H:i:s', $v['open_time']));
print_r('福利屋开奖open_time' . date('Y-m-d H:i:s', $v['open_time']));
if($v['open_time']<time()){
Log::info('福利屋开奖$goods_id时间小于所以开奖啦' . $v['id']);
print_r('福利屋开奖$goods_id时间小于所以开奖啦' . $v['id']);
$this->special_prize_notice_time($v['id']);
}
}
$time = date('Y-m-d H:i:s', time());
$output->writeln('success' . $time);
}
/**
* 特殊奖品开奖 LAST 最终赏 全局赏 到时间开奖修改此处
* @param $order 订单信息
* @param $first_count
*/
protected function special_prize_notice_time($goods_id)
{
$res = [];
// $goods_id = $order['goods_id'];
// $num = $order['num'];
// $order_type = $order['order_type'];
// $goods_id=request()->param('goods_id/d', 0);
// $num = request()->param('goods_num/d', 0); #第几箱
$num = 1; #第几箱
$order_type =6;
print_r('$goods_id'.$goods_id);
#特殊奖品存在
$special_prize = GoodsList::where('goods_id', '=', $goods_id)
->where('num', '=', $num)
->where('surplus_stock', '>', 0)
->where('shang_id', 'in', self::$shang_give_arr)
->select()->toArray();
$surplus_give_stock = $special_prize ? array_sum(array_column($special_prize, 'surplus_stock')) : 0;
if ($special_prize && $surplus_give_stock > 0) {
#所有奖品信息
$all_order_list = OrderList::field('id,user_id')
->where('goods_id', '=', $goods_id)
->where('num', '=', $num)
->where('order_type', '=', $order_type)
->where('shang_id', 'between', self::$shang_prize_id)
->order('id asc')
->select()->toArray();
$order_goods = [];
foreach ($special_prize as $k => $v) {
if ($v['shang_id'] == 4) {#全局赏
for ($surplus_stock_i = 0; $surplus_stock_i < $v['surplus_stock']; $surplus_stock_i++) {
$overall_order_list = $all_order_list;
shuffle($overall_order_list);
shuffle($overall_order_list);
$prize_info = $overall_order_list[0];
$user_id = $prize_info['user_id'];
#特殊赏中奖订单id
$order_list_id = $prize_info['id'];
#中奖奖项
$ordinary_prize_info = $v;
$order_goods[] = [
'order_id' => 0,
'user_id' => $user_id,
'status' => 0,#0未操作 1选择兑换 2选择发货
'goods_id' => $goods_id,
'num' => $num,
'shang_id' => $ordinary_prize_info['shang_id'],
'goodslist_id' => $ordinary_prize_info['id'],
'goodslist_title' => $ordinary_prize_info['title'],
'goodslist_imgurl' => $ordinary_prize_info['imgurl'],
'goodslist_price' => $ordinary_prize_info['price'],
'goodslist_money' => $ordinary_prize_info['money'],
'goodslist_type' => $ordinary_prize_info['goods_type'],
'goodslist_sale_time' => $ordinary_prize_info['sale_time'],
'addtime' => time(),
'prize_code' => $ordinary_prize_info['prize_code'],
'order_type' => $order_type,
'order_list_id' => $order_list_id,
];
print_r($user_id.'中奖'.$goods_id.'商品'.$v['title']);
#减少库存
$res[] = GoodsList::field('surplus_stock')
->where(['id' => $ordinary_prize_info['id']])
->dec('surplus_stock')
->update();
}
}
}
#新增奖品列表
$res[] = OrderList::insertAll($order_goods);
Goods::where(['id' => $goods_id])->update([
'is_open' => 1
]);
Log::info('福利屋开奖$goods_idupdate_is_open' . $goods_id);
} else {
$res[] = 1;
}
return $res;
}
}