123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- <?php
- namespace App\Console\Commands;
- use App\Models\Anchor;
- use App\Models\Order;
- use App\Models\Package;
- use App\Models\Channe;
- use Illuminate\Support\Facades\Log;
- class BroadbandOrder extends \Illuminate\Console\Command
- {
- protected $signature = "broadband:order";
- protected $description = 'broadband order';
- public function __construct()
- {
- parent::__construct();
- }
- public function handle()
- {
- // 0未支付,1已支付,2申请退款,3已退款,4不同意,5退款失败 6退款中 pay_status
- $packages = Package::where('is_upload', 1)
- // ->where('operator_id', 6)
- ->where('product_type',1)
- ->get();
-
-
- $ids = [];
- foreach ($packages as $p) {
- array_push($ids, $p->id);
- }
-
- // $orderss = [
- // '20240927161554995579'
- // ];
-
- $today = date('Y-m-d', strtotime("-10 day"));
- $orders = Order::where('open_status', 0)
- // ->where('pay_status', 0)
- ->whereIn('package_id', $ids)
- ->whereDate('created_at', ">", $today)
- ->where('order_type', 1)
- // ->whereIn('order_no', $orderss)
- ->get();
- foreach ($orders as $order) {
- if ($order['agent_pro_id'] == 107 || $order['agent_id'] == 107) {
- continue;
- }
- $this->send($order);
- }
-
-
- $orders = Order::where('open_status', 1)
- ->whereIn('package_id', $ids)
- ->whereDate('created_at', ">", $today)
- ->where('order_type', 1)
- // ->whereIn('order_no', $orderss)
- ->get();
- foreach ($orders as $order) {
- if ($order['agent_pro_id'] == 107 || $order['agent_id'] == 107) {
- continue;
- }
- $this->check($order);
- }
- Log::info('宽带订单同步完成,等待下次同步');
- $i = 0;
- while ($i < 120) {
- sleep(1);
- $i++;
- }
- $this->handle();
- }
- public function send($order)
- {
- // $package = Package::where('id', $order->package_id)->first();
- // if(empty($package->out_package_id)) return;
-
- $url = "";
- $data = [
- 'business_order_no' => $order->order_no, //订单号
- 'iden_card_name' => $order->id_card_name, //身份证姓名
- 'iden_card_id' => $order->id_card, //身份证号
- 'contact' => $order->contact, //联系人姓名
- 'mobile' => $order->mobile, //联系人电话
- 'address' => $order->express_address, //收货地址
- 'package_id' => $order->out_package_id, //商品编码(对应的集客仓的商品编码)
- 'remark' => $order->remark,
- ];
- Log::info($order->order_no.'分销宽带订单同步提交:'.json_encode($data,JSON_UNESCAPED_UNICODE));
- $res = $this->req($url, $data);
- Log::info($order->order_no.'分销宽带订单同步返回:'.json_encode($res,JSON_UNESCAPED_UNICODE));
-
- if(empty($res)) return ["code" => 2, "msg" => "服务器请求超时"];
-
- if(!empty($res["data"]["order_no"])){
- $updata = [
- 'open_status' => 1,
- 'api_order_no' => $res["data"]["order_no"]
- ];
- }else{
- $updata = [
- 'open_status' => 3,
- 'open_message' => $res["error"]
- ];
- }
-
- if (!empty($updata)) {
- $order->update($updata);
- }
-
- }
-
-
-
-
- public function check($order)
- {
-
- $url = "";
- $data = [
- "business_order_no" => $order->order_no
- ];
- $res = $this->reqGet($url, $data);
- // Log::info('宽带订单查询返回:'.json_encode($res,JSON_UNESCAPED_UNICODE));
- if(empty($res)) return false;
-
- $updata = [];
-
- if(empty($res["data"])) return;
-
- $resData = $res["data"][count($res["data"]) - 1];
-
- if($resData["open_status"] == 3){
- $updata = [
- 'open_status' => 2,
- 'phonenum' => $resData["phonenum"],
- ];
- }
-
- if($resData["open_status"] == 4){
- $updata = [
- 'open_status' => 3,
- 'open_message' => $resData["open_message"],
- ];
- }
-
- // $orderInfo = Order::where('order_no', $order->order_no)->first();
- if (!empty($updata)) {
- $order->update($updata);
- }
- }
-
-
- public function reqGet($url, $data)
- {
-
- $headers = array(
- "Content-Type:application/json;charset=utf-8",
- "Authorization:Bearer 980|vOkaPQixrLHNh97344ON0tlpY7YPDLl4vUnqp8KV5e33b43a"
- );
- $url = $url .'?'. http_build_query($data);
-
- $curl = curl_init();// 初始化
- curl_setopt($curl, CURLOPT_URL, $url);// 设置url路径
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true) ;// 将 curl_exec()获取的信息以文件流的形式返回,而不是直接输出
- curl_setopt($curl, CURLOPT_BINARYTRANSFER, true) ;// 在启用 CURLOPT_RETURNTRANSFER 时候将获取数据返回
- curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);// 添加头信息
- curl_setopt($curl, CURLINFO_HEADER_OUT, true); // CURLINFO_HEADER_OUT选项可以拿到请求头信息
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);// 不验证SSL
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);// 不验证SSL
- curl_setopt($curl, CURLOPT_TIMEOUT, 10);// 请求超时
-
- $data = curl_exec($curl);// 执行
- curl_close($curl);// 关闭连接
- return json_decode($data, true);// 返回数据
- }
-
-
-
-
-
- public function req($url, $data)
- {
-
-
- $data = json_encode($data, JSON_UNESCAPED_UNICODE);
- $headers = array(
- "Content-Type:application/json;charset=utf-8",
- "Authorization:Bearer 980|vOkaPQixrLHNh97344ON0tlpY7YPDLl4vUnqp8KV5e33b43a"
- );
- $curl = curl_init(); //初始化
- curl_setopt($curl, CURLOPT_URL, $url); //设置抓取的url
- curl_setopt($curl, CURLOPT_HEADER, false); //设置头文件的信息作为数据流输出
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); //设置获取的信息以文件流的形式返回,而不是直接输出。
- curl_setopt($curl, CURLOPT_POST, true); //设置post方式提交
- curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // 设置post请求参数
- curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); // 添加头信息
- curl_setopt($curl, CURLINFO_HEADER_OUT, true); // CURLINFO_HEADER_OUT选项可以拿到请求头信息
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); // 不验证SSL
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); // 不验证SSL
- $data = curl_exec($curl);
- curl_close($curl);
- return json_decode($data,true);
- }
- }
|