|
|
@@ -3,14 +3,17 @@
|
|
|
namespace app\controller\merchant;
|
|
|
|
|
|
use app\extra\basic\Base;
|
|
|
+use app\extra\dyLife\data\OrderData;
|
|
|
use app\middleware\AuthMiddleware;
|
|
|
use app\model\saas\SaasOrder;
|
|
|
+use app\model\saas\SaasStore;
|
|
|
use app\service\saas\GoodsService;
|
|
|
use app\service\saas\OrderService;
|
|
|
use DI\Attribute\Inject;
|
|
|
use LinFly\Annotation\Attributes\Route\Controller;
|
|
|
use LinFly\Annotation\Attributes\Route\GetMapping;
|
|
|
use LinFly\Annotation\Attributes\Route\Middleware;
|
|
|
+use LinFly\Annotation\Attributes\Route\PostMapping;
|
|
|
use support\Request;
|
|
|
use support\Response;
|
|
|
|
|
|
@@ -64,8 +67,8 @@ class Order extends Base
|
|
|
],$request->method());
|
|
|
if (!is_array($param)) return error($param);
|
|
|
$order = $this->model->where("out_order_no",$param['order'])->with(['product','poi','user'])->findOrEmpty();
|
|
|
- if ($order['poi_id'] <> $request->user['store_id']) return errorTrans("empty.data");
|
|
|
if ($order->isEmpty()) return errorTrans("empty.data");
|
|
|
+ if ($order['poi_id'] <> $request->user['store_id']) return errorTrans("empty.data");
|
|
|
$order['end_time'] = timeDiff(strtotime("+30 minutes",strtotime($order['create_at'])),time());
|
|
|
return successTrans("success.data",$order->toArray());
|
|
|
} catch (\Throwable $throwable) {
|
|
|
@@ -73,4 +76,59 @@ class Order extends Base
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 手动核销
|
|
|
+ * @param Request $request
|
|
|
+ * @return Response|void
|
|
|
+ */
|
|
|
+ #[PostMapping('done')]
|
|
|
+ public function doneOrder(Request $request)
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $param = $this->_valid([
|
|
|
+ "id.require" => trans("empty.require")
|
|
|
+ ],$request->method());
|
|
|
+ if (!is_array($param)) return error($param);
|
|
|
+ $order = $this->model->where("order_sn",$param['id'])->with(['product','poi','user'])->findOrEmpty();
|
|
|
+ if ($order->isEmpty()) return errorTrans("empty.data");
|
|
|
+ if ($order['poi_id'] <> $request->user['store_id']) return errorTrans("empty.data");
|
|
|
+ if ($order['status'] <> 1) return error("该订单状态不支持核销");
|
|
|
+ $store = (new SaasStore)->where("poi_id",$request->user['store_id'])->findOrEmpty();
|
|
|
+ if ($store->isEmpty()) return errorTrans("error.data");
|
|
|
+ // 获取到订单encrypted_code
|
|
|
+ $orderCode = (new OrderData)->config([
|
|
|
+ "appid" => sConf("wechat.appid"),
|
|
|
+ "secret" => sConf("wechat.secret"),
|
|
|
+ "account" => sConf("wechat.shop_id"),
|
|
|
+ ])->token()->getCertificate($order['order_sn'],$store['store_id']);
|
|
|
+ if (empty($orderCode['certificates'])) return error("获取订单数据失败");
|
|
|
+ if (!isset($orderCode['certificates'][0]['encrypted_code'])) return error("获取订单数据失败");
|
|
|
+ if ($orderCode['certificates'][0]['status'] <> 1) return error("该订单状态不支持核销");
|
|
|
+ // 核销订单
|
|
|
+ $orderDone = (new OrderData)->config([
|
|
|
+ "appid" => sConf("wechat.appid"),
|
|
|
+ "secret" => sConf("wechat.secret"),
|
|
|
+ "account" => sConf("wechat.shop_id"),
|
|
|
+ ])->token()->verifyCertificate([
|
|
|
+ "account_id" => $store['store_id'],
|
|
|
+ "pay_sn" => $order['pay_sn'],
|
|
|
+ "encrypted_code" => $orderCode['certificates'][0]['encrypted_code'],
|
|
|
+ "order_id" => $order['order_sn'],
|
|
|
+ "poi_id" => $order['poi_id']
|
|
|
+ ]);
|
|
|
+ if (empty($orderDone['verify_results'])) return error("核销失败");
|
|
|
+ if (!isset($orderDone['verify_results'][0]['verify_id'])) return error("核销失败");
|
|
|
+ if (!isset($orderDone['verify_results'][0]['certificate_id'])) return error("核销失败");
|
|
|
+ $order->status = 2;
|
|
|
+ $order->verify_id = $orderDone['verify_results'][0]['verify_id'];
|
|
|
+ $order->certificate_id = $orderDone['verify_results'][0]['certificate_id'];
|
|
|
+ $order->done_at = getDateFull();
|
|
|
+ $state = $order->save();
|
|
|
+ if (!$state) return error("核销失败");
|
|
|
+ return success("核销成功");
|
|
|
+ } catch (\Throwable $throwable) {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|