| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- namespace app\controller\notify;
- use app\extra\basic\Base;
- use app\model\saas\SaasOrder;
- use app\model\saas\SaasOrderExpress;
- use app\model\saas\SaasOrderLog;
- use LinFly\Annotation\Route\Controller;
- use LinFly\Annotation\Route\Route;
- use support\Request;
- use support\Response;
- #[Controller(prefix: "/sf")]
- class SfExpress extends Base
- {
- protected array $opCode = [
- 50 => "已揽件",
- 30 => "运输中",
- 31 => "运输中",
- 44 => "运输中",
- 80 => "已签收"
- ];
- /**
- *
- * @param Request $request
- * @param $id
- * @return Response
- */
- #[Route(path: "hook/{id}",methods: ['get','post'])]
- public function getHook(Request $request,$id): Response
- {
- try {
- if ($request->method() == "GET") {
- $data = $request->get();
- } else {
- $data = $request->post();
- }
- if (!empty($data['orderState'])){
- foreach ($data['orderState'] as $val) {
- $order = (new SaasOrder)->where("express_id",$val['waybillNo'])->findOrEmpty();
- if ($order->isEmpty()) return json(['code' => 0,"success" => true,"msg" => ""]);
- if ($val['empCode'] == 500963) {
- (new SaasOrderExpress)->insertGetId(['order_id' => $order['order_sn'],'express_id' => $val['waybillNo'],'content' => "顺丰快递",'title' => "系统已接收"]);
- (new SaasOrderLog)->insertGetId(['order_id' => $order['order_sn'],'remark' => "顺丰快递",'title' => "系统已接收"]);
- }
- }
- }
- if (!empty($data['Body']['WaybillRoute'])){
- foreach ($data['Body']['WaybillRoute'] as $val) {
- $order = (new SaasOrder)->where("express_id",$val['mailno'])->with(['store' => function($query){
- $query->field('store_id,store_name,appid,secret,express_time,order_end');
- }])->findOrEmpty();
- if ($order->isEmpty()) return json(['code' => 0,"success" => true,"msg" => ""]);
- if ($order['status'] >= 2) return json(['code' => 0,"success" => true,"msg" => ""]);
- (new SaasOrderExpress)->insertGetId(['order_id' => $order['order_sn'],'express_id' => $val['mailno'],'content' => $val['remark'],'title' => $this->opCode[$val['opCode']]??'']);
- (new SaasOrderLog)->insertGetId(['order_id' => $order['order_sn'],'remark' => $val['remark'],'title' => $this->opCode[$val['opCode']]??'' ]);
- if ($val['opCode'] == 50 && $order['store']['order_end'] == "2") { // 已揽收,发起核销
- // $val['acceptAddress'] 发货地址
- $this->orderDone($order->toArray(),1);
- $order->status = 2;
- $order->save();
- }
- if ($val['opCode'] == 80 && $order['store']['order_end'] == "3") { // 已签收
- // $val['acceptAddress'] 发货地址
- $this->orderDone($order->toArray(),2);
- $order->status = 2;
- $order->save();
- }
- }
- }
- return json(['code' => 0,"success" => true,"msg" => ""]);
- } catch (\Throwable $throwable) {
- return error($throwable->getMessage());
- }
- }
- protected function orderDone(array $data = [],int $type = 1)
- {
- }
- }
|