完全解放双手,实现订单自由
简介
独角数卡->一个开源式站长自动化售货系统,支持多种支付以及发货方式,相当之强大,简单来说,独角数卡相当于一个门店,可以免费帮你开店,可以上架一些虚拟货品(激活码,KEY等等,当时实物也不是不行)实现自动,或半自动发货,实现人在家中坐,💰从天上来的效果,有了它,人人都可以当老板了!
项目地址=项目地址
强迫症用了很难受
虽然基础功能十分强大,但是并不完美
1.自动发货不支持用户输入侧的数据
2.卡密信息还是要站长手动录入,这算哪门子的自动发货
3.录入卡密不能根据根据客户输入侧进行调整,会产生冗余卡密以及库存不足的情况,毕竟没有人能预测产品能卖出多少份
4.等等等等
问题的产出来自于一次续费操作,用户续订我的业务,需要拿着订单号来找我,我查询后台的订单信息确认,确认无误后给用户数据库更新数据.这是一系列完全可以有机器来进行的繁琐工作,而且看起来,好像与没用卡网是一个效果,甚至来说如果不用卡网,用户直接给我转账甚至还会省掉后台查询这一步骤,像我如此懒的人是不允许这样的事情发生的!
几种构思
说干就干,我要彻底完善它,以解放双手
想解决这些问题,读取用户输入侧信息是关键,这相当于你与用户之间的交流,也就是用户能向我们传达的信息
于是我下单测试了一下,确实会在管理员的邮件推送中得到这个值,如图所示
那么这就好办了,既然我们能够通过推送来拿到这个输入值,那么是不是只要我在自己的服务器搭建一个邮件系统,就可以自由的获取这个信息了呀(搭建邮件系统可以看毛毛哥的文章)虽然我并没有采用这个方案,因为我突然想到,我们的DUJIAOKA不仅仅支持邮件推送呀,还有我们熟悉的BARK推送,而BARK,是支持http协议的!
我们对比一下DUJIAOKA后台配置和BARK的推送配置
我们只需要模仿BARK的请求,写一个自己的API就可以了,通过看BARK的推送文件,发现是POST请求,所以:
from flask import Flask, request, jsonify
@app.route('/token', methods=["POST"])
def test():
params = request.form if request.form else request.json
print(params)
果然收到了我们的消息!
但是看了一下好像并没有用户侧输入,会不会是隐藏在了其他的参数里面,于是我再推送给我的BARK康康
好像也没有,只能通过他的代码入手了,发现并没有将输入信息添加到推送内容当中去,难道白忙活一场了?!
<?php
namespace App\Jobs;
use App\Models\Order;
#这里是引入的订单信息
use GuzzleHttp\Client;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use App\Models\BaseModel;
class BarkPush implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* 任务最大尝试次数。
*
* @var int
*/
public $tries = 2;
/**
* 任务运行的超时时间。
*
* @var int
*/
public $timeout = 30;
/**
* @var Order
*/
private $order;
/**
* 商品服务层.
* @var \App\Service\PayService
*/
private $goodsService;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct(Order $order)
{
$this->order = $order;
$this->goodsService = app('Service\GoodsService');
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
#下面这些就是推送的信息啦,好多没用的,可以删掉
{
$goodInfo = $this->goodsService->detail($this->order->goods_id);
$client = new Client();
$apiUrl = dujiaoka_config_get('bark_server') .'/'. dujiaoka_config_get('bark_token');
$params = [
"title" => __('dujiaoka.prompt.new_order_push').'('.$this->order->actual_price.'元)',
"body" => __('order.fields.order_id') .': '.$this->order->id."\n"
. __('order.fields.order_sn') .': '.$this->order->order_sn."\n"
. __('order.fields.pay_id') .': '.$this->order->pay->pay_name."\n"
. __('order.fields.title') .': '.$this->order->title."\n"
. __('order.fields.actual_price') .': '.$this->order->actual_price."\n"
. __('order.fields.email') .': '.$this->order->email."\n"
. __('goods.fields.gd_name') .': '.$goodInfo->gd_name."\n"
. __('goods.fields.in_stock') .': '.$goodInfo->in_stock."\n"
. __('order.fields.order_created') .': '.$this->order->created_at,
"icon"=>url('assets/common/images/default.jpg'),
"level"=>"timeSensitive",
"group"=>dujiaoka_config_get('text_logo', '独角数卡')
];
if (dujiaoka_config_get('is_open_bark_push_url', 0) == BaseModel::STATUS_OPEN) {
$params["url"] = url('detail-order-sn/'.$this->order->order_sn);
}
$client->post($apiUrl,['form_params' => $params, 'verify' => false]);
}
}
我们可以在生成订单的代码中,来修改上面的推送代码
/**
* 创建订单.
* @return Order
* @throws RuleValidationException
*
* @author assimon<ashang@utf8.hk>
* @copyright assimon<ashang@utf8.hk>
* @link http://utf8.hk/
*/
public function createOrder(): Order
{
try {
$order = new Order();
// 生成订单号
$order->order_sn = strtoupper(Str::random(16));
// 设置商品
$order->goods_id = $this->goods->id;
// 标题
$order->title = $this->goods->gd_name . ' x ' . $this->buyAmount;
// 订单类型
$order->type = $this->goods->type;
// 查询密码
$order->search_pwd = $this->searchPwd;
// 邮箱
$order->email = $this->email;
// 支付方式.
$order->pay_id = $this->payID;
// 商品单价
$order->goods_price = $this->goods->actual_price;
// 购买数量
$order->buy_amount = $this->buyAmount;
// 订单详情
$order->info = $this->otherIpt;
// ip地址
$order->buy_ip = $this->buyIP;
// 优惠码优惠价格
$order->coupon_discount_price = $this->calculateTheCouponPrice();
if ($this->coupon) {
$order->coupon_id = $this->coupon->id;
}
// 批发价
$order->wholesale_discount_price = $this->calculateTheWholesalePrice();
// 订单总价
$order->total_price = $this->calculateTheTotalPrice();
// 订单实际需要支付价格
$order->actual_price = $this->calculateTheActualPrice(
$this->calculateTheTotalPrice(),
$this->calculateTheCouponPrice(),
$this->calculateTheWholesalePrice()
);
// 保存订单
$order->save();
// 如果有用到优惠券
if ($this->coupon) {
// 设置优惠码已经使用
$this->couponService->used($this->coupon->coupon);
// 使用次数-1
$this->couponService->retDecr($this->coupon->coupon);
}
// 将订单加入队列 x分钟后过期
$expiredOrderDate = dujiaoka_config_get('order_expire_time', 5);
OrderExpired::dispatch($order->order_sn)->delay(Carbon::now()->addMinutes($expiredOrderDate));
return $order;
} catch (\Exception $exception) {
throw new RuleValidationException($exception->getMessage());
}
}
#添加这一行代码,就可以将用户输入推送过去了
"input"=>$this->order->info
#如果你想推送其他内容,也可以自己修改
我们简单的试验一下,果然得到了输入值
事已至此,差不多就完结了
有了这个,我们想得到的所有订单信息我们都可以拿到,就可以通过有用信息,定制我们的自动化脚本啦!
Comments | 1 条评论
博主 毛豆豆