|
|
@@ -2,6 +2,9 @@
|
|
|
|
|
|
namespace hd\controllers;
|
|
|
|
|
|
+use bizHd\wx\classes\WxOpenClass;
|
|
|
+use common\components\dict;
|
|
|
+use common\components\expressUtil;
|
|
|
use common\components\util;
|
|
|
use Yii;
|
|
|
use biz\shop\classes\ShopClass;
|
|
|
@@ -10,11 +13,14 @@ use common\components\IntraCityExpress;
|
|
|
|
|
|
/**
|
|
|
* 同城配送控制器
|
|
|
- *
|
|
|
+ *
|
|
|
* 提供同城配送相关的API接口
|
|
|
*/
|
|
|
class IntraCityController extends BaseController
|
|
|
{
|
|
|
+
|
|
|
+ public $guestAccess = ['cs'];
|
|
|
+
|
|
|
/**
|
|
|
* 禁用CSRF验证(用于接收微信回调)
|
|
|
*/
|
|
|
@@ -33,7 +39,7 @@ class IntraCityController extends BaseController
|
|
|
public function actionCreateStore()
|
|
|
{
|
|
|
Yii::$app->response->format = Response::FORMAT_JSON;
|
|
|
-
|
|
|
+
|
|
|
try {
|
|
|
$shopId = intval($this->shopId);
|
|
|
if (empty($shopId)) {
|
|
|
@@ -49,7 +55,7 @@ class IntraCityController extends BaseController
|
|
|
'store_latitude' => $shop->lat,
|
|
|
'store_phone' => $shop->telephone
|
|
|
];
|
|
|
-
|
|
|
+
|
|
|
// 验证必填参数
|
|
|
$requiredFields = ['out_store_id', 'store_name', 'store_address', 'store_longitude', 'store_latitude', 'store_phone'];
|
|
|
foreach ($requiredFields as $field) {
|
|
|
@@ -57,9 +63,9 @@ class IntraCityController extends BaseController
|
|
|
util::fail("缺少必填参数:{$field}");
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$result = IntraCityExpress::createStore($storeData);
|
|
|
-
|
|
|
+
|
|
|
if ($result['errcode'] === 0) {
|
|
|
util::success("门店创建成功", $result);
|
|
|
} else {
|
|
|
@@ -87,11 +93,11 @@ class IntraCityController extends BaseController
|
|
|
public function actionCreateOrder()
|
|
|
{
|
|
|
Yii::$app->response->format = Response::FORMAT_JSON;
|
|
|
-
|
|
|
+
|
|
|
try {
|
|
|
$request = Yii::$app->request;
|
|
|
$orderData = $request->post();
|
|
|
-
|
|
|
+
|
|
|
// 验证必填参数
|
|
|
$requiredFields = [
|
|
|
'out_store_id', 'store_order_id', 'delivery_service_code',
|
|
|
@@ -99,15 +105,15 @@ class IntraCityController extends BaseController
|
|
|
'to_user_longitude', 'to_user_latitude', 'goods_value',
|
|
|
'goods_weight'
|
|
|
];
|
|
|
-
|
|
|
+
|
|
|
foreach ($requiredFields as $field) {
|
|
|
if (empty($orderData[$field])) {
|
|
|
util::fail("缺少必填参数:{$field}");
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$result = IntraCityExpress::createOrder($orderData);
|
|
|
-
|
|
|
+
|
|
|
if (isset($result['errcode']) && $result['errcode'] === 0) {
|
|
|
util::success('订单创建成功', [
|
|
|
'wx_order_id' => $result['wx_order_id'] ?? null,
|
|
|
@@ -132,19 +138,19 @@ class IntraCityController extends BaseController
|
|
|
public function actionGetOrder()
|
|
|
{
|
|
|
Yii::$app->response->format = Response::FORMAT_JSON;
|
|
|
-
|
|
|
+
|
|
|
try {
|
|
|
$request = Yii::$app->request;
|
|
|
$wxOrderId = $request->get('wx_order_id');
|
|
|
$outOrderId = $request->get('store_order_id'); // 修正为 store_order_id
|
|
|
$outStoreId = $request->get('out_store_id');
|
|
|
-
|
|
|
+
|
|
|
if (empty($wxOrderId) && (empty($outOrderId) || empty($outStoreId))) {
|
|
|
- util::fail("参数不足:wx_order_id 或 (store_order_id + out_store_id) 必须提供一组");
|
|
|
+ util::fail("参数不足:wx_order_id 或 (store_order_id + out_store_id) 必须提供一组");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$result = IntraCityExpress::getOrder($wxOrderId, $outOrderId, $outStoreId);
|
|
|
-
|
|
|
+
|
|
|
if (isset($result['errcode']) && $result['errcode'] === 0) {
|
|
|
util::success("查询成功", $result);
|
|
|
} else {
|
|
|
@@ -164,19 +170,19 @@ class IntraCityController extends BaseController
|
|
|
public function actionCancelOrder()
|
|
|
{
|
|
|
Yii::$app->response->format = Response::FORMAT_JSON;
|
|
|
-
|
|
|
+
|
|
|
try {
|
|
|
$request = Yii::$app->request;
|
|
|
$wxOrderId = $request->post('wx_order_id');
|
|
|
$outOrderId = $request->post('store_order_id'); // 修正为 store_order_id
|
|
|
$outStoreId = $request->post('out_store_id');
|
|
|
-
|
|
|
+
|
|
|
if (empty($wxOrderId) && (empty($outOrderId) || empty($outStoreId))) {
|
|
|
util::fail("参数不足:wx_order_id 或 (store_order_id + out_store_id) 必须提供一组");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$result = IntraCityExpress::cancelOrder($wxOrderId, $outOrderId, $outStoreId);
|
|
|
-
|
|
|
+
|
|
|
if (isset($result['errcode']) && $result['errcode'] === 0) {
|
|
|
util::success("订单取消成功", $result);
|
|
|
} else {
|
|
|
@@ -196,14 +202,14 @@ class IntraCityController extends BaseController
|
|
|
public function actionStoreList()
|
|
|
{
|
|
|
Yii::$app->response->format = Response::FORMAT_JSON;
|
|
|
-
|
|
|
+
|
|
|
try {
|
|
|
$request = Yii::$app->request;
|
|
|
$offset = $request->get('offset', 0);
|
|
|
$limit = $request->get('limit', 20);
|
|
|
-
|
|
|
+
|
|
|
$result = IntraCityExpress::getStoreList($offset, $limit);
|
|
|
-
|
|
|
+
|
|
|
if ($result['errcode'] === 0) {
|
|
|
return [
|
|
|
'success' => true,
|
|
|
@@ -232,14 +238,14 @@ class IntraCityController extends BaseController
|
|
|
public function actionOrderList()
|
|
|
{
|
|
|
Yii::$app->response->format = Response::FORMAT_JSON;
|
|
|
-
|
|
|
+
|
|
|
try {
|
|
|
$request = Yii::$app->request;
|
|
|
$offset = $request->get('offset', 0);
|
|
|
$limit = $request->get('limit', 20);
|
|
|
-
|
|
|
+
|
|
|
$result = IntraCityExpress::getOrderList($offset, $limit);
|
|
|
-
|
|
|
+
|
|
|
if ($result['errcode'] === 0) {
|
|
|
return [
|
|
|
'success' => true,
|
|
|
@@ -268,10 +274,10 @@ class IntraCityController extends BaseController
|
|
|
public function actionDeliveryList()
|
|
|
{
|
|
|
Yii::$app->response->format = Response::FORMAT_JSON;
|
|
|
-
|
|
|
+
|
|
|
try {
|
|
|
$result = IntraCityExpress::getDeliveryList();
|
|
|
-
|
|
|
+
|
|
|
if ($result['errcode'] === 0) {
|
|
|
return [
|
|
|
'success' => true,
|
|
|
@@ -300,19 +306,19 @@ class IntraCityController extends BaseController
|
|
|
public function actionCallback()
|
|
|
{
|
|
|
Yii::$app->response->format = Response::FORMAT_JSON;
|
|
|
-
|
|
|
+
|
|
|
try {
|
|
|
$request = Yii::$app->request;
|
|
|
$callbackData = $request->post();
|
|
|
-
|
|
|
+
|
|
|
// 从配置中获取安全token
|
|
|
$token = Yii::$app->params['wx_intracity_token'] ?? 'your_token_here';
|
|
|
-
|
|
|
+
|
|
|
$result = IntraCityExpress::handleOrderCallback($callbackData, $token);
|
|
|
-
|
|
|
+
|
|
|
// 记录回调日志
|
|
|
Yii::info('同城配送回调:' . json_encode($callbackData, JSON_UNESCAPED_UNICODE), 'intracity_callback');
|
|
|
-
|
|
|
+
|
|
|
return $result;
|
|
|
} catch (\Exception $e) {
|
|
|
Yii::error('同城配送回调处理异常:' . $e->getMessage(), 'intracity_callback');
|
|
|
@@ -330,14 +336,14 @@ class IntraCityController extends BaseController
|
|
|
public function actionMockNotify()
|
|
|
{
|
|
|
Yii::$app->response->format = Response::FORMAT_JSON;
|
|
|
-
|
|
|
+
|
|
|
try {
|
|
|
$request = Yii::$app->request;
|
|
|
$orderStatus = $request->post('order_status');
|
|
|
$wxOrderId = $request->post('wx_order_id');
|
|
|
$outStoreId = $request->post('out_store_id');
|
|
|
$outOrderId = $request->post('store_order_id'); // 修正为 store_order_id
|
|
|
-
|
|
|
+
|
|
|
if (empty($orderStatus)) {
|
|
|
util::fail("请提供订单状态");
|
|
|
}
|
|
|
@@ -345,9 +351,9 @@ class IntraCityController extends BaseController
|
|
|
if (empty($wxOrderId) && (empty($outStoreId) || empty($outOrderId))) {
|
|
|
util::fail("参数不足:wx_order_id 或 (out_store_id + store_order_id) 必须提供一组");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$result = IntraCityExpress::mockNotify($orderStatus, $wxOrderId, $outStoreId, $outOrderId);
|
|
|
-
|
|
|
+
|
|
|
if (isset($result['errcode']) && $result['errcode'] === 0) {
|
|
|
util::success("模拟回调成功", $result);
|
|
|
} else {
|
|
|
@@ -367,7 +373,7 @@ class IntraCityController extends BaseController
|
|
|
public function actionOrderStatusList()
|
|
|
{
|
|
|
Yii::$app->response->format = Response::FORMAT_JSON;
|
|
|
-
|
|
|
+
|
|
|
$statusList = [
|
|
|
IntraCityExpress::ORDER_STATUS_CREATED => '订单创建成功',
|
|
|
IntraCityExpress::ORDER_STATUS_CANCELED_BY_MERCHANT => '商家取消订单',
|
|
|
@@ -379,7 +385,7 @@ class IntraCityController extends BaseController
|
|
|
IntraCityExpress::ORDER_STATUS_COMPLETED => '配送完成',
|
|
|
IntraCityExpress::ORDER_STATUS_EXCEPTION => '配送异常',
|
|
|
];
|
|
|
-
|
|
|
+
|
|
|
return [
|
|
|
'success' => true,
|
|
|
'message' => '查询成功',
|
|
|
@@ -394,7 +400,7 @@ class IntraCityController extends BaseController
|
|
|
public function actionGoodsTypeList()
|
|
|
{
|
|
|
Yii::$app->response->format = Response::FORMAT_JSON;
|
|
|
-
|
|
|
+
|
|
|
$goodsTypeList = [
|
|
|
IntraCityExpress::GOODS_TYPE_FAST_FOOD => '快餐',
|
|
|
IntraCityExpress::GOODS_TYPE_MEDICINE => '药品',
|
|
|
@@ -416,11 +422,20 @@ class IntraCityController extends BaseController
|
|
|
IntraCityExpress::GOODS_TYPE_HOME => '家居建材',
|
|
|
IntraCityExpress::GOODS_TYPE_OTHER => '其他',
|
|
|
];
|
|
|
-
|
|
|
+
|
|
|
return [
|
|
|
'success' => true,
|
|
|
'message' => '查询成功',
|
|
|
'data' => $goodsTypeList
|
|
|
];
|
|
|
}
|
|
|
-}
|
|
|
+
|
|
|
+ public function actionCs()
|
|
|
+ {
|
|
|
+ $merchant = WxOpenClass::getWxInfo();
|
|
|
+ $ptStyle = dict::getDict('ptStyle', 'hd');
|
|
|
+ $r = expressUtil::getShopList($merchant, [],$ptStyle);
|
|
|
+ print_r($r);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|