|
@@ -4,7 +4,9 @@ namespace app\controller\notify;
|
|
|
|
|
|
|
|
use app\extra\basic\Base;
|
|
use app\extra\basic\Base;
|
|
|
use app\extra\dyLife\data\OrderData;
|
|
use app\extra\dyLife\data\OrderData;
|
|
|
|
|
+use app\extra\tools\LifeWeb;
|
|
|
use app\model\saas\SaasOrder;
|
|
use app\model\saas\SaasOrder;
|
|
|
|
|
+use app\model\saas\SaasOrderExpress;
|
|
|
use app\model\saas\SaasOrderItem;
|
|
use app\model\saas\SaasOrderItem;
|
|
|
use app\model\saas\SaasOrderVerify;
|
|
use app\model\saas\SaasOrderVerify;
|
|
|
use LinFly\Annotation\Attributes\Route\Controller;
|
|
use LinFly\Annotation\Attributes\Route\Controller;
|
|
@@ -26,99 +28,138 @@ class Test extends Base
|
|
|
'order.require' => trans("empty.require")
|
|
'order.require' => trans("empty.require")
|
|
|
]);
|
|
]);
|
|
|
if (!is_array($param)) return error($param);
|
|
if (!is_array($param)) return error($param);
|
|
|
- $order = (new SaasOrder)->where("order_sn",$param["order"])->with(['poi'])->findOrEmpty();
|
|
|
|
|
|
|
+ $order = (new SaasOrder)->where("order_sn",$param["order"])->with(['product','poi','user'])->findOrEmpty();
|
|
|
echo "订单状态==={$order['status']}\n";
|
|
echo "订单状态==={$order['status']}\n";
|
|
|
- if ($order['status'] <> 2)
|
|
|
|
|
- {
|
|
|
|
|
- echo getDateFull()."===订单状态不符合核销\n";
|
|
|
|
|
- return error("订单状态不符合核销",$order->toArray());
|
|
|
|
|
|
|
+ if ($order->isEmpty()) return errorTrans("empty.data");
|
|
|
|
|
+ if ($order['status'] <> 7) return error("该订单状态不支持核销");
|
|
|
|
|
+// if ($request->user['store_id'] <> $order['poi_id'] && $request->user['is_super'] == 0) return errorTrans("empty.data");
|
|
|
|
|
+ $orderExpress = (new SaasOrderExpress)->where("order_sn",$order['out_order_no'])->findOrEmpty();
|
|
|
|
|
+ if ($orderExpress->isEmpty()) return error("订单尚未发货");
|
|
|
|
|
+ if (!empty($order['error_at'])) {
|
|
|
|
|
+ if (strtotime("+24 hour",strtotime($order['error_at'])) < time()) return error("新订单需24小时后方可核销");
|
|
|
}
|
|
}
|
|
|
- // 获取到订单encrypted_code
|
|
|
|
|
- $orderCode = (new OrderData)->config([
|
|
|
|
|
- "appid" => sConf("wechat.appid"),
|
|
|
|
|
- "secret" => sConf("wechat.secret"),
|
|
|
|
|
- "account" => sConf("wechat.shop_id"),
|
|
|
|
|
- ])->token()->getCertificate($order['order_sn'],$order['poi']['store_id']);
|
|
|
|
|
- if (empty($orderCode['certificates']))
|
|
|
|
|
- {
|
|
|
|
|
- echo getDateFull()."===获取订单数据失败\n";
|
|
|
|
|
- return error("获取订单数据失败",$orderCode);
|
|
|
|
|
- }
|
|
|
|
|
- echo getDateFull()."===核销数据\n";
|
|
|
|
|
- print_r($orderCode['certificates']);
|
|
|
|
|
- $encrypted_code = [];
|
|
|
|
|
- foreach ($orderCode['certificates'] as $key=>$v)
|
|
|
|
|
- {
|
|
|
|
|
- if (empty($v['encrypted_code']))
|
|
|
|
|
- {
|
|
|
|
|
- echo getDateFull()."===获取订单数据失败\n";
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
- if ($v['status'] <> 1) {
|
|
|
|
|
- echo getDateFull()."===该订单状态不支持核销\n";
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
- $encrypted_code[$key] = $v['encrypted_code'];
|
|
|
|
|
- }
|
|
|
|
|
- echo getDateFull()."===券码数据\n";
|
|
|
|
|
- print_r($encrypted_code);
|
|
|
|
|
- if (empty($encrypted_code))
|
|
|
|
|
- {
|
|
|
|
|
- echo getDateFull()."===没有可核销券码\n";
|
|
|
|
|
|
|
+ [$state,$expressData] = (new LifeWeb)->getExpressData($orderExpress['express_sn'],$orderExpress['mobile']);
|
|
|
|
|
+ if (!$state) return error("查询物流失败,请联系管理员");
|
|
|
|
|
+ if (!in_array($expressData['logisticsStatusDesc'],['派件中',"已签收"])) return error("当前物流状态不允许核销");
|
|
|
|
|
+ $startTime = $order['poi']['order_start']??'09:00';
|
|
|
|
|
+ $endTime = $order['poi']['order_end']??'22:30';
|
|
|
|
|
+ $startTimeStamp = strtotime(date("Y-m-d {$startTime}:00"));
|
|
|
|
|
+ $endTimeStamp = strtotime(date("Y-m-d {$endTime}:00"));
|
|
|
|
|
+ if (time() > $startTimeStamp && time() < $endTimeStamp) {
|
|
|
|
|
+ $data = (new OrderData)->config([
|
|
|
|
|
+ "appid" => sConf("wechat.mini_appid"),
|
|
|
|
|
+ "secret" => sConf("wechat.mini_secret")
|
|
|
|
|
+ ])->token()->verifyOrder($order->toArray());
|
|
|
|
|
+ if (empty($data['verify_results'])) return error($data['description']); // 核销失败
|
|
|
|
|
+ $order->status = 2;
|
|
|
$order->express_status = 3;
|
|
$order->express_status = 3;
|
|
|
$order->done_at = getDateFull();
|
|
$order->done_at = getDateFull();
|
|
|
$order->save();
|
|
$order->save();
|
|
|
- return error("没有可核销券码",$encrypted_code);
|
|
|
|
|
- }
|
|
|
|
|
- // 核销订单
|
|
|
|
|
- $orderDone = (new OrderData)->config([
|
|
|
|
|
- "appid" => sConf("wechat.appid"),
|
|
|
|
|
- "secret" => sConf("wechat.secret"),
|
|
|
|
|
- "account" => sConf("wechat.shop_id"),
|
|
|
|
|
- ])->token()->verifyCertificate([
|
|
|
|
|
- "account_id" => $order['poi']['store_id'],
|
|
|
|
|
- "pay_sn" => $order['pay_sn'],
|
|
|
|
|
-// "encrypted_code" => $orderCode['certificates'][0]['encrypted_code'],
|
|
|
|
|
- "encrypted_code" => array_values($encrypted_code),
|
|
|
|
|
- "order_id" => $order['order_sn'],
|
|
|
|
|
- "poi_id" => $order['poi_id']
|
|
|
|
|
- ]);
|
|
|
|
|
- echo getDateFull()."===核销返回\n";
|
|
|
|
|
- print_r($orderDone);
|
|
|
|
|
- if (empty($orderDone['verify_results']))
|
|
|
|
|
- {
|
|
|
|
|
- echo getDateFull()."===核销失败\n";
|
|
|
|
|
- return error("核销失败",$orderDone);
|
|
|
|
|
- }
|
|
|
|
|
- $doneData = [];
|
|
|
|
|
- foreach ($orderDone['verify_results'] as $key=>$v)
|
|
|
|
|
- {
|
|
|
|
|
- if(empty($v['verify_id'])) {
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
- if(empty($v['certificate_id'])) {
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
- $doneData[$key] = [
|
|
|
|
|
|
|
+ (new SaasOrderItem)->where(['order_sn'=>$order['order_sn'],'status'=>1])->update(['status'=>3]);
|
|
|
|
|
+ (new SaasOrderVerify)->insertGetId([
|
|
|
"poi_id" => $order['poi_id'],
|
|
"poi_id" => $order['poi_id'],
|
|
|
"order_sn" => $order['order_sn'],
|
|
"order_sn" => $order['order_sn'],
|
|
|
"money" => $order['price'],
|
|
"money" => $order['price'],
|
|
|
- "certificate_id" => $v['certificate_id'],
|
|
|
|
|
- "verify_id" => $v['verify_id'],
|
|
|
|
|
- ];
|
|
|
|
|
- }
|
|
|
|
|
- if (empty($doneData))
|
|
|
|
|
- {
|
|
|
|
|
- echo getDateFull()."===核销完成无数据返回\n";
|
|
|
|
|
- return error("核销完成无数据返回",$doneData);
|
|
|
|
|
|
|
+ "certificate_id" => $data['verify_results'][0]['certificate_id']??'0',
|
|
|
|
|
+ "verify_id" => $data['verify_results'][0]['verify_id']??'0',
|
|
|
|
|
+ ]);
|
|
|
|
|
+ return success("核销成功");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return error("当前时间段不支持核销");
|
|
|
}
|
|
}
|
|
|
- $order->express_status = 3;
|
|
|
|
|
- $order->done_at = getDateFull();
|
|
|
|
|
- $order->save();
|
|
|
|
|
- (new SaasOrderItem)->where(['order_sn'=>$order['order_sn'],'status'=>1])->update(['status'=>3]);
|
|
|
|
|
- (new SaasOrderVerify)->insertAll(array_values($doneData));
|
|
|
|
|
- return success("核销成功");
|
|
|
|
|
|
|
+// if ($order['status'] <> 2)
|
|
|
|
|
+// {
|
|
|
|
|
+// echo getDateFull()."===订单状态不符合核销\n";
|
|
|
|
|
+// return error("订单状态不符合核销",$order->toArray());
|
|
|
|
|
+// }
|
|
|
|
|
+// // 获取到订单encrypted_code
|
|
|
|
|
+// $orderCode = (new OrderData)->config([
|
|
|
|
|
+// "appid" => sConf("wechat.appid"),
|
|
|
|
|
+// "secret" => sConf("wechat.secret"),
|
|
|
|
|
+// "account" => sConf("wechat.shop_id"),
|
|
|
|
|
+// ])->token()->getCertificate($order['order_sn'],$order['poi']['store_id']);
|
|
|
|
|
+// if (empty($orderCode['certificates']))
|
|
|
|
|
+// {
|
|
|
|
|
+// echo getDateFull()."===获取订单数据失败\n";
|
|
|
|
|
+// return error("获取订单数据失败",$orderCode);
|
|
|
|
|
+// }
|
|
|
|
|
+// echo getDateFull()."===核销数据\n";
|
|
|
|
|
+// print_r($orderCode['certificates']);
|
|
|
|
|
+// $encrypted_code = [];
|
|
|
|
|
+// foreach ($orderCode['certificates'] as $key=>$v)
|
|
|
|
|
+// {
|
|
|
|
|
+// if (empty($v['encrypted_code']))
|
|
|
|
|
+// {
|
|
|
|
|
+// echo getDateFull()."===获取订单数据失败\n";
|
|
|
|
|
+// continue;
|
|
|
|
|
+// }
|
|
|
|
|
+// if ($v['status'] <> 1) {
|
|
|
|
|
+// echo getDateFull()."===该订单状态不支持核销\n";
|
|
|
|
|
+// continue;
|
|
|
|
|
+// }
|
|
|
|
|
+// $encrypted_code[$key] = $v['encrypted_code'];
|
|
|
|
|
+// }
|
|
|
|
|
+// echo getDateFull()."===券码数据\n";
|
|
|
|
|
+// print_r($encrypted_code);
|
|
|
|
|
+// if (empty($encrypted_code))
|
|
|
|
|
+// {
|
|
|
|
|
+// echo getDateFull()."===没有可核销券码\n";
|
|
|
|
|
+// $order->express_status = 3;
|
|
|
|
|
+// $order->done_at = getDateFull();
|
|
|
|
|
+// $order->save();
|
|
|
|
|
+// return error("没有可核销券码",$encrypted_code);
|
|
|
|
|
+// }
|
|
|
|
|
+// // 核销订单
|
|
|
|
|
+// $orderDone = (new OrderData)->config([
|
|
|
|
|
+// "appid" => sConf("wechat.appid"),
|
|
|
|
|
+// "secret" => sConf("wechat.secret"),
|
|
|
|
|
+// "account" => sConf("wechat.shop_id"),
|
|
|
|
|
+// ])->token()->verifyCertificate([
|
|
|
|
|
+// "account_id" => $order['poi']['store_id'],
|
|
|
|
|
+// "pay_sn" => $order['pay_sn'],
|
|
|
|
|
+//// "encrypted_code" => $orderCode['certificates'][0]['encrypted_code'],
|
|
|
|
|
+// "encrypted_code" => array_values($encrypted_code),
|
|
|
|
|
+// "order_id" => $order['order_sn'],
|
|
|
|
|
+// "poi_id" => $order['poi_id']
|
|
|
|
|
+// ]);
|
|
|
|
|
+// echo getDateFull()."===核销返回\n";
|
|
|
|
|
+// print_r($orderDone);
|
|
|
|
|
+// if (empty($orderDone['verify_results']))
|
|
|
|
|
+// {
|
|
|
|
|
+// echo getDateFull()."===核销失败\n";
|
|
|
|
|
+// return error("核销失败",$orderDone);
|
|
|
|
|
+// }
|
|
|
|
|
+// $doneData = [];
|
|
|
|
|
+// foreach ($orderDone['verify_results'] as $key=>$v)
|
|
|
|
|
+// {
|
|
|
|
|
+// if(empty($v['verify_id'])) {
|
|
|
|
|
+// continue;
|
|
|
|
|
+// }
|
|
|
|
|
+// if(empty($v['certificate_id'])) {
|
|
|
|
|
+// continue;
|
|
|
|
|
+// }
|
|
|
|
|
+// $doneData[$key] = [
|
|
|
|
|
+// "poi_id" => $order['poi_id'],
|
|
|
|
|
+// "order_sn" => $order['order_sn'],
|
|
|
|
|
+// "money" => $order['price'],
|
|
|
|
|
+// "certificate_id" => $v['certificate_id'],
|
|
|
|
|
+// "verify_id" => $v['verify_id'],
|
|
|
|
|
+// ];
|
|
|
|
|
+// }
|
|
|
|
|
+// if (empty($doneData))
|
|
|
|
|
+// {
|
|
|
|
|
+// echo getDateFull()."===核销完成无数据返回\n";
|
|
|
|
|
+// return error("核销完成无数据返回",$doneData);
|
|
|
|
|
+// }
|
|
|
|
|
+// $order->express_status = 3;
|
|
|
|
|
+// $order->done_at = getDateFull();
|
|
|
|
|
+// $order->save();
|
|
|
|
|
+// (new SaasOrderItem)->where(['order_sn'=>$order['order_sn'],'status'=>1])->update(['status'=>3]);
|
|
|
|
|
+// (new SaasOrderVerify)->insertAll(array_values($doneData));
|
|
|
} catch (\Throwable $throwable) {
|
|
} catch (\Throwable $throwable) {
|
|
|
|
|
+ echo $throwable->getMessage()."\n";
|
|
|
|
|
+ echo $throwable->getFile()."\n";
|
|
|
|
|
+ echo $throwable->getLine()."\n";
|
|
|
return error($throwable->getMessage());
|
|
return error($throwable->getMessage());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|