You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
118 lines
3.5 KiB
118 lines
3.5 KiB
<?php
|
|
declare (strict_types=1);
|
|
|
|
namespace app\command;
|
|
|
|
|
|
use think\console\Command;
|
|
use think\console\Input;
|
|
use think\console\input\Argument;
|
|
use think\console\input\Option;
|
|
use think\console\Output;
|
|
use Tx\Mailer;
|
|
use app\wap\model\store\StoreOrder;
|
|
use app\wap\model\store\StoreOrderCartInfo;
|
|
use app\wap\model\user\User;
|
|
|
|
class SendUserGoodsByEmail extends Command
|
|
{
|
|
protected function configure()
|
|
{
|
|
|
|
// 指令配置
|
|
$this->setName('SendUserGoodsByEmail')->setDescription('邮箱发送给用户虚拟商品');
|
|
}
|
|
|
|
/**
|
|
* 订单超时3天,未归还支付宝,未支付异常订单处理
|
|
* @param Input $input
|
|
* @param Output $output
|
|
* @return int|void|null
|
|
* @throws DataNotFoundException
|
|
* @throws DbException
|
|
* @throws ModelNotFoundException
|
|
*/
|
|
protected function execute(Input $input, Output $output)
|
|
{
|
|
$virtual_order = StoreOrder::where('is_virtual',1)->where('is_send',0)->select();
|
|
|
|
if (!$virtual_order->toArray()) {
|
|
echo "没有虚拟订单".PHP_EOL;
|
|
return;
|
|
}
|
|
foreach ($virtual_order as $item) {
|
|
$cartInfo = StoreOrderCartInfo::where('oid', $item['id'])->column('cart_info', 'unique') ?: [];
|
|
foreach ($cartInfo as $k => $cart) {
|
|
$temp = json_decode($cart, true);
|
|
|
|
if ($temp['productInfo']['is_virtual'] == 0 || (!$temp['productInfo']['link'] && !$temp['productInfo']['network_disk_link'])) {
|
|
echo $item['id']."没有配置附件地址".PHP_EOL;
|
|
continue;
|
|
}
|
|
$user = User::where('uid', $item['uid'])->find();
|
|
if (!$user || !$user['email']) {
|
|
echo $user['uid']."用户不存在或者邮箱不存在".PHP_EOL;
|
|
continue;
|
|
}
|
|
$content = "";
|
|
if ($temp['productInfo']['link']) {
|
|
$content .= "附件地址:".$temp['productInfo']['link'].PHP_EOL;
|
|
}
|
|
if ($temp['productInfo']['network_disk_link'] && $temp['productInfo']['network_disk_pwd']) {
|
|
$content .= "百度网盘地址:".$temp['productInfo']['network_disk_link']." 密码:".$temp['productInfo']['network_disk_pwd'];
|
|
}
|
|
try {
|
|
$ret = $this->sendEmail($user['nickname'], $user['email'], $content);
|
|
if ($ret) {
|
|
StoreOrder::where('id', $item['id'])->update(['is_send' => 1]);
|
|
}
|
|
var_dump($temp);
|
|
exit();
|
|
} catch (\Exception $e) {
|
|
echo $e->getMessage();
|
|
continue;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public function sendEmail($username, $email, $content){
|
|
$ok = (new Mailer())
|
|
->setServer('smtp.qq.com', 465,'ssl')
|
|
->setAuth('570161239@qq.com', 'yoaajyqudwccbefb')
|
|
->setFrom('梦航教育', '570161239@qq.com')
|
|
// ->setAuth('136268885@qq.com', 'ncdbyyyfddcmbgdd')
|
|
// ->setFrom('梦航教育', '136268885@qq.com')
|
|
// ->setServer('smtp.163.com', 465, 'ssl')
|
|
// ->setAuth('liuqing161@163.com', '199liu')
|
|
// ->setFrom('Tom', 'liuqing161@163.com')
|
|
->addTo($username, $email)
|
|
->setSubject('梦航教育')
|
|
->setBody($content)
|
|
//->addAttachment('host', '/etc/hosts')
|
|
->send();
|
|
return $ok;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|