|
|
@@ -10,7 +10,9 @@ use bizHd\shop\classes\MainClass;
|
|
|
use bizHd\user\classes\UserClass;
|
|
|
use bizHd\wx\classes\WxOpenClass;
|
|
|
use common\components\dict;
|
|
|
+use common\components\imgUtil;
|
|
|
use common\components\noticeUtil;
|
|
|
+use common\components\orderSn;
|
|
|
use common\components\util;
|
|
|
use hd\models\IntraCity\StoreFeeForm;
|
|
|
use Yii;
|
|
|
@@ -247,6 +249,7 @@ class IntraCityController extends BaseController
|
|
|
public function actionStoreFee()
|
|
|
{
|
|
|
$post = Yii::$app->request->post();
|
|
|
+
|
|
|
// 创建表单验证模型
|
|
|
$form = new StoreFeeForm();
|
|
|
$form->setScenario('store_fee');
|
|
|
@@ -262,54 +265,42 @@ class IntraCityController extends BaseController
|
|
|
if ($order['mainId'] != $this->mainId) {
|
|
|
util::fail('不是你的订单哈。');
|
|
|
}
|
|
|
- $sn = $order['orderSn'];
|
|
|
$shopId = intval($this->shopId);
|
|
|
if (empty($shopId)) {
|
|
|
util::fail("门店不存在");
|
|
|
}
|
|
|
- //$shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], false, false, 'id, wxStoreId');
|
|
|
- $shopExt = MainClass::getById($this->mainId, false, 'id, wxStoreId');
|
|
|
- if (empty($shopExt)) {
|
|
|
- util::fail("微信门店不存在");
|
|
|
- }
|
|
|
|
|
|
- $itemInfoList = OrderItemClass::getListBySn($sn);
|
|
|
- $orderType = 2; // 默认是 2。说明:1花束订单 2花材订单 3花束和花材都有
|
|
|
- if (empty($itemInfoList)) {
|
|
|
- $orderType = 1;
|
|
|
- }
|
|
|
+ $weight = $post['weight'] ?? 0;
|
|
|
+ $price = $post['price'] ?? 0;
|
|
|
+ $packageNum = $post['packageNum'] ?? 0;
|
|
|
|
|
|
- $cargoName = '花材'; // 商品名称,默认是花材
|
|
|
- $goodsInfoList = OrderGoodsClass::getListBySn($sn);
|
|
|
- if (count($goodsInfoList) == 1) {
|
|
|
- $goodsInfo = $goodsInfoList[0];
|
|
|
- $cargoName = $goodsInfo['name'];
|
|
|
- } else {
|
|
|
- if ($orderType != 2) {
|
|
|
- util::fail("订单商品数量不正确");
|
|
|
- }
|
|
|
+ $main = $this->main;
|
|
|
+ $wxStoreId = $main->wxStoreId ?? '';
|
|
|
+ if (empty($wxStoreId)) {
|
|
|
+ util::fail('你还没有开通跑腿');
|
|
|
}
|
|
|
|
|
|
+ $cargoName = '花材'; // 商品名称,默认是花材
|
|
|
$cargo = [
|
|
|
'cargo_name' => $cargoName, // 商品名称 -- $order 中没有,要在 goodsInfo 中取
|
|
|
- 'cargo_weight' => intval($post['weight'] * 1000), // 单位:克 -- 把千克转换为克
|
|
|
- 'cargo_price' => intval($post['price'] * 100), // 单位:分 -- 把元转换为分
|
|
|
+ 'cargo_weight' => intval($weight * 1000), // 单位:克 -- 把千克转换为克
|
|
|
+ 'cargo_price' => intval($price * 100), // 单位:分 -- 把元转换为分
|
|
|
'cargo_type' => IntraCityExpress::GOODS_TYPE_FLOWER,
|
|
|
- 'cargo_num' => intval($post['packageNum'])
|
|
|
+ 'cargo_num' => intval($packageNum)
|
|
|
];
|
|
|
$originalLng = doubleval($post['user_lng']);
|
|
|
$originalLat = doubleval($post['user_lat']);
|
|
|
+ $useSandBox = getenv('YII_ENV') == 'production' ? 0 : 1;// 根据环境变量判断是否使用沙盒环境
|
|
|
$orderData = [
|
|
|
//'out_store_id' => $shopId,
|
|
|
- 'wx_store_id' => $shopExt['wxStoreId'],
|
|
|
+ 'wx_store_id' => $wxStoreId,
|
|
|
'user_name' => $post['user_name'],
|
|
|
'user_phone' => $post['user_phone'],
|
|
|
'user_lng' => $originalLng,
|
|
|
'user_lat' => $originalLat,
|
|
|
'user_address' => $post['user_address'],
|
|
|
'cargo' => $cargo,
|
|
|
- //'use_sandbox' => 1 // 如果不需要沙箱,use_sandbox就不传就好了 -- 踩坑人的经验
|
|
|
- //'use_sandbox' => getenv('YII_ENV') == 'production' ? 0 : 1 // 根据环境变量判断是否使用沙盒环境 -- 没用,不生效
|
|
|
+ 'use_sandbox' => $useSandBox,
|
|
|
];
|
|
|
//多处有用到这个方法,需修改请同步修改,搜索关键词 intra_city_express_pre_add
|
|
|
$result = IntraCityExpress::preAddOrder($orderData);
|
|
|
@@ -358,53 +349,37 @@ class IntraCityController extends BaseController
|
|
|
util::fail('售后付款单不支持跑腿');
|
|
|
}
|
|
|
|
|
|
+ $packageNum = $post['packageNum'] ?? 0;
|
|
|
+ if ($packageNum <= 0) {
|
|
|
+ util::fail('请填写包裹数量');
|
|
|
+ }
|
|
|
+
|
|
|
$sn = $order['orderSn'];
|
|
|
$salt = $order['salt'] ?? "";
|
|
|
- $itemInfoList = OrderItemClass::getListBySn($sn, 'id, name, cover, num');
|
|
|
- $itemList = [];
|
|
|
- $orderType = 2; // 默认是 2。说明:1花束订单 2花材订单 3花束和花材都有
|
|
|
- if (empty($itemInfoList)) {
|
|
|
- $orderType = 1; // 花束订单
|
|
|
- $goodsInfoList = OrderGoodsClass::getListBySn($sn);
|
|
|
- $itemCount = 0;
|
|
|
- foreach ($goodsInfoList as $itemInfo) {
|
|
|
- $itemList[] = [
|
|
|
- 'item_name' => $itemInfo['name'],
|
|
|
- 'item_pic_url' => $itemInfo['bigCover'],
|
|
|
- 'count' => intval($itemInfo['num']),
|
|
|
- ];
|
|
|
- $itemCount += $itemInfo['num'];
|
|
|
+ $orderType = $order['orderType'] ?? 1;
|
|
|
+ $goodsNum = $order['goodsNum'] ?? 0;
|
|
|
+ $goodsNum = $goodsNum > 0 ? $goodsNum : 1;
|
|
|
+ $itemList = [['item_name' => '花材', 'item_pic_url' => imgUtil::groupImg(''), 'count' => $goodsNum]];
|
|
|
+ if ($orderType == 1) {
|
|
|
+ $itemInfo = OrderGoodsClass::getByCondition(['orderSn' => $sn], true);
|
|
|
+ if (!empty($itemInfo)) {
|
|
|
+ $cover = $itemInfo['cover'] ?? '';
|
|
|
+ $itemList = [['item_name' => '花束', 'item_pic_url' => imgUtil::groupImg($cover), 'count' => $goodsNum]];
|
|
|
}
|
|
|
- $post['packageNum'] = $itemCount;
|
|
|
} else {
|
|
|
- $itemCount = 0;
|
|
|
- foreach ($itemInfoList as $itemInfo) {
|
|
|
- $itemList[] = [
|
|
|
- 'item_name' => $itemInfo['name'],
|
|
|
- 'item_pic_url' => $itemInfo['bigCover'],
|
|
|
- 'count' => intval($itemInfo['num']),
|
|
|
- ];
|
|
|
- $itemCount += $itemInfo['num'];
|
|
|
+ $itemInfo = OrderItemClass::getByCondition(['orderSn' => $sn], true);
|
|
|
+ if (!empty($itemInfo)) {
|
|
|
+ $cover = $itemInfo['cover'] ?? '';
|
|
|
+ $itemList = [['item_name' => '花材', 'item_pic_url' => imgUtil::groupImg($cover), 'count' => $goodsNum]];
|
|
|
}
|
|
|
- $post['packageNum'] = $itemCount;
|
|
|
}
|
|
|
|
|
|
- //$shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], false, false, 'id, wxStoreId');
|
|
|
- $shopExt = MainClass::getById($this->mainId, false, 'id, wxStoreId');
|
|
|
- if (empty($shopExt)) {
|
|
|
- util::fail("微信门店不存在");
|
|
|
- }
|
|
|
+ $cargoName = $orderType == 1 ? '花束' : '花材';
|
|
|
|
|
|
- $cargoName = '花材'; // 商品名称,默认是花材
|
|
|
- $goodsInfoList = OrderGoodsClass::getListBySn($sn);
|
|
|
- if (count($goodsInfoList) == 1) {
|
|
|
- $goodsInfo = $goodsInfoList[0];
|
|
|
- $cargoName = $goodsInfo['name'];
|
|
|
- } else {
|
|
|
- if ($orderType != 2) {
|
|
|
- Yii::error('订单商品数量不正确');
|
|
|
- util::fail("订单商品数量不正确");
|
|
|
- }
|
|
|
+ $main = $this->main;
|
|
|
+ $wxStoreId = $main->wxStoreId ?? '';
|
|
|
+ if (empty($wxStoreId)) {
|
|
|
+ util::fail('你还没有开通跑腿');
|
|
|
}
|
|
|
|
|
|
// 通过 userId 获取 openid(小程序OpenId)
|
|
|
@@ -413,6 +388,10 @@ class IntraCityController extends BaseController
|
|
|
util::fail('用户信息缺失');
|
|
|
}
|
|
|
$miniOpenId = $user['miniOpenId'] ?? '';
|
|
|
+ if (empty($miniOpenId)) {
|
|
|
+ $admin = $this->admin;
|
|
|
+ $miniOpenId = $admin->miniOpenId ?? '';
|
|
|
+ }
|
|
|
if (empty($miniOpenId)) {
|
|
|
util::fail('没有找到用户的微信数据');
|
|
|
}
|
|
|
@@ -421,33 +400,19 @@ class IntraCityController extends BaseController
|
|
|
'cargo_name' => $cargoName,
|
|
|
'cargo_weight' => intval($post['weight'] * 1000),
|
|
|
'cargo_type' => IntraCityExpress::GOODS_TYPE_FLOWER,
|
|
|
- 'cargo_num' => intval($post['packageNum']),
|
|
|
+ 'cargo_num' => intval($packageNum),
|
|
|
'cargo_price' => intval($order['actPrice'] * 100), // $order 中有各个价格,请注意
|
|
|
'item_list' => $itemList,
|
|
|
];
|
|
|
|
|
|
- //生成 store_order_id,加统一后缀,避免线上线下ID命中
|
|
|
- $storeOrderId = $orderId . '_exp';
|
|
|
- if ($order['sendStatus'] == 3) { // 如果不是首次用 $orderId 创建快递配送,则要生成新 store_order_id
|
|
|
- // store_order_id 门店订单编号, 即 orderId。如果是重新配送的第n次,订单编号的命名规则为:orderId_cp_n
|
|
|
- $query = (new Query())
|
|
|
- ->from('xhExpressOrder')
|
|
|
- ->where(['orderId' => $orderId]);
|
|
|
- // $command = $query->createCommand();
|
|
|
- // $sql = $command->sql;
|
|
|
- $copyOrderCount = $query->count();
|
|
|
- $copyOrderCount += 1;
|
|
|
- //区分线上线下
|
|
|
- if (getenv('YII_ENV') == 'production') {
|
|
|
- $storeOrderId = $storeOrderId . '_cp_' . $copyOrderCount;
|
|
|
- } else {
|
|
|
- $storeOrderId = $storeOrderId . '_cs_cp_' . $copyOrderCount;
|
|
|
- }
|
|
|
- }
|
|
|
+ $shopId = $this->shopId;
|
|
|
+ $mainId = $this->mainId;
|
|
|
+ $snData = ['shopId' => $shopId, 'mainId' => $mainId];
|
|
|
+ $storeOrderId = orderSn::getExpressSn($snData);
|
|
|
|
|
|
$callbackUrl = Yii::$app->params['hdHost'] . '/intra-city/callback';
|
|
|
$orderData = [
|
|
|
- 'wx_store_id' => $shopExt['wxStoreId'],
|
|
|
+ 'wx_store_id' => $wxStoreId,
|
|
|
'store_order_id' => $storeOrderId, //同一个门店订单编号要保证唯一,相同的订单号会重入
|
|
|
'user_openid' => $miniOpenId,
|
|
|
'user_lng' => $post['user_lng'],
|
|
|
@@ -459,20 +424,10 @@ class IntraCityController extends BaseController
|
|
|
'verify_code_type' => 0,
|
|
|
'order_detail_path' => '/admin/order/info?id=' . $orderId . '&salt=' . $salt,
|
|
|
'callback_url' => $callbackUrl, // 订单状态回调地址(非必传)
|
|
|
- 'use_sandbox' => getenv('YII_ENV') == 'production' ? 0 : 1, // 开发环境默认使用沙箱
|
|
|
+ 'use_sandbox' => 0,
|
|
|
'cargo' => $cargo
|
|
|
];
|
|
|
|
|
|
- //开发环境只能使用沙箱 ssh
|
|
|
- if (getenv('YII_ENV') != 'production') {
|
|
|
- $orderData['use_sandbox'] = 1;
|
|
|
- $orderData['user_name'] = '顺丰同城';
|
|
|
- $orderData['user_phone'] = 13881979410;
|
|
|
- $orderData['user_address'] = '北京市海淀区学清嘉创大厦A座15层';
|
|
|
- $orderData['user_lng'] = '116.352954';
|
|
|
- $orderData['user_lat'] = '40.014747';
|
|
|
- }
|
|
|
-
|
|
|
$result = IntraCityExpress::createOrder($orderData);
|
|
|
|
|
|
if (isset($result['errcode']) && $result['errcode'] === 0) {
|