|
|
@@ -66,11 +66,17 @@ class OrderController extends BaseController
|
|
|
public function actionNewFreight()
|
|
|
{
|
|
|
$post = Yii::$app->request->post();
|
|
|
- $mainId = intval($this->mainId);
|
|
|
- if (empty($mainId)) {
|
|
|
- util::fail("门店信息出错");
|
|
|
+
|
|
|
+ $hasMap = dict::getDict('hasMap');
|
|
|
+ if ($hasMap == 0) {
|
|
|
+ util::fail('暂不支持跑腿功能');
|
|
|
+ }
|
|
|
+
|
|
|
+ $mainData = $this->main;
|
|
|
+ $wxStoreId = $mainData->wxStoreId ?? '';
|
|
|
+ if (empty($wxStoreId)) {
|
|
|
+ util::fail('商家还没有开通跑腿');
|
|
|
}
|
|
|
- $mainData = MainClass::getById($mainId, false, 'id, wxStoreId');
|
|
|
|
|
|
$cargoName = $post['cargo_name']; // 商品名称
|
|
|
$cargo = [
|
|
|
@@ -83,7 +89,7 @@ class OrderController extends BaseController
|
|
|
$originalLng = doubleval($post['user_lng']);
|
|
|
$originalLat = doubleval($post['user_lat']);
|
|
|
$orderData = [
|
|
|
- 'wx_store_id' => $mainData['wxStoreId'],
|
|
|
+ 'wx_store_id' => $wxStoreId,
|
|
|
'user_name' => $post['user_name'],
|
|
|
'user_phone' => $post['user_phone'],
|
|
|
'user_lng' => $originalLng,
|
|
|
@@ -119,7 +125,7 @@ class OrderController extends BaseController
|
|
|
'distance' => 0,
|
|
|
'showDistance' => 0,
|
|
|
'fee' => 0,
|
|
|
- 'hasMap'=>dict::getDict('hasMap'),
|
|
|
+ 'hasMap' => dict::getDict('hasMap'),
|
|
|
'shop' => 'fail' //门店引起的失败
|
|
|
]);
|
|
|
}
|
|
|
@@ -130,7 +136,7 @@ class OrderController extends BaseController
|
|
|
'distance' => 0,
|
|
|
'showDistance' => 0,
|
|
|
'fee' => 0,
|
|
|
- 'hasMap'=>dict::getDict('hasMap'),
|
|
|
+ 'hasMap' => dict::getDict('hasMap'),
|
|
|
'client' => 'fail' //用户端定位失败
|
|
|
]);
|
|
|
}
|
|
|
@@ -140,7 +146,7 @@ class OrderController extends BaseController
|
|
|
'distance' => 0,
|
|
|
'showDistance' => 0,
|
|
|
'fee' => 0,
|
|
|
- 'hasMap'=>dict::getDict('hasMap'),
|
|
|
+ 'hasMap' => dict::getDict('hasMap'),
|
|
|
'weight' => 'fail' //重量不对
|
|
|
]);
|
|
|
}
|
|
|
@@ -213,14 +219,14 @@ class OrderController extends BaseController
|
|
|
$presellData = [];
|
|
|
$nowTime = strtotime(date("Y-m-d"));
|
|
|
foreach ($productInfoList as $currentInfo) {
|
|
|
- if (isset($currentInfo['mainId']) == false || $currentInfo['mainId'] != $this->mainId) {
|
|
|
+ if (!isset($currentInfo['mainId']) || $currentInfo['mainId'] != $this->mainId) {
|
|
|
util::fail('只能选择同一家的商品哦');
|
|
|
}
|
|
|
$currentName = $currentInfo['name'] ?? '';
|
|
|
$presell = $currentInfo['presell'] ?? 0;
|
|
|
$presellData[] = $presell;
|
|
|
if ($presell == 1) {
|
|
|
- if (isset($post['reachDate']) == false || empty($post['reachDate'])) {
|
|
|
+ if (empty($post['reachDate'])) {
|
|
|
util::fail('请选择配送或取货日期');
|
|
|
}
|
|
|
$sendTimeWant = $post['reachDate'];
|
|
|
@@ -232,7 +238,7 @@ class OrderController extends BaseController
|
|
|
if (empty($hasDate)) {
|
|
|
util::fail('预售日期有问题,请提醒门店');
|
|
|
}
|
|
|
- if (in_array(strtotime($sendTimeWant), $hasDate) == false) {
|
|
|
+ if (!in_array(strtotime($sendTimeWant), $hasDate)) {
|
|
|
util::fail("有预售花材在{$sendTimeWant}没到货");
|
|
|
}
|
|
|
$post['presell'] = 1;
|
|
|
@@ -253,9 +259,9 @@ class OrderController extends BaseController
|
|
|
$connection = Yii::$app->db;
|
|
|
$transaction = $connection->beginTransaction();
|
|
|
try {
|
|
|
- $orderValidTime = getenv('ORDER_VALID_TIME') == false ? 600 : getenv('ORDER_VALID_TIME');
|
|
|
+ $orderValidTime = !getenv('ORDER_VALID_TIME') ? 600 : getenv('ORDER_VALID_TIME');
|
|
|
$post['deadline'] = time() + $orderValidTime;
|
|
|
- $post['reachDate'] = isset($post['reachDate']) && !empty($post['reachDate']) ? $post['reachDate'] : date("Y-m-d");
|
|
|
+ $post['reachDate'] = !empty($post['reachDate']) ? $post['reachDate'] : date("Y-m-d");
|
|
|
$post['needPrint'] = dict::getDict('needPrint', 'need');
|
|
|
$user = $this->user;
|
|
|
$post['bookMobile'] = $user->mobile ?? '';
|
|
|
@@ -266,6 +272,7 @@ class OrderController extends BaseController
|
|
|
//各个等级对应的price addPrice字段
|
|
|
$priceMap = \bizGhs\custom\classes\CustomClass::$levelPriceKeyMap;
|
|
|
$addPriceMap = \bizGhs\custom\classes\CustomClass::$levelAddPriceKeyMap;
|
|
|
+ $totalWeight = 0;
|
|
|
foreach ($productList as $eleKey => $element) {
|
|
|
$level = 0;
|
|
|
$productId = $element['productId'];
|
|
|
@@ -278,8 +285,67 @@ class OrderController extends BaseController
|
|
|
$currentTotal = bcmul($price, $num, 2);
|
|
|
$modifyPrice = bcadd($modifyPrice, $currentTotal, 2);
|
|
|
$productList[$eleKey]['unitPrice'] = $price;
|
|
|
+ $weight = $current['weight'] ?? 0;
|
|
|
+ $currentWeight = bcmul($num, $weight, 2);
|
|
|
+ $totalWeight = bcadd($totalWeight, $currentWeight, 2);
|
|
|
}
|
|
|
$post['product'] = $productList;
|
|
|
+
|
|
|
+ //不能前端传运费过来,只能通过跑腿接口计算出来
|
|
|
+ unset($post['sendCost']);
|
|
|
+ if (isset($post['sendType']) && $post['sendType'] == 2) {
|
|
|
+ $hasMap = dict::getDict('hasMap');
|
|
|
+ if ($hasMap == 0) {
|
|
|
+ util::fail('不能使用跑腿');
|
|
|
+ }
|
|
|
+ $cargoName = '花材'; // 商品名称
|
|
|
+ $cargo = [
|
|
|
+ 'cargo_name' => $cargoName, // 商品名称
|
|
|
+ 'cargo_weight' => intval($totalWeight * 1000), // 单位:克 -- 把千克转换为克 ---- 重量(用户未知)-- 大概
|
|
|
+ 'cargo_price' => intval($modifyPrice * 100), // 单位:分 -- 把元转换为分
|
|
|
+ 'cargo_type' => IntraCityExpress::GOODS_TYPE_FLOWER,
|
|
|
+ 'cargo_num' => 1
|
|
|
+ ];
|
|
|
+ $customName = $custom->name;
|
|
|
+ $customMobile = $custom->mobile;
|
|
|
+ if (empty($post['long']) || empty($post['lat'])) {
|
|
|
+ util::fail('位置错误');
|
|
|
+ }
|
|
|
+ $originalLng = doubleval($post['long']);
|
|
|
+ $originalLat = doubleval($post['lat']);
|
|
|
+ $city = $post['city'] ?? '';
|
|
|
+ $dist = $post['dist'] ?? '';
|
|
|
+ $address = $post['address'] ?? '';
|
|
|
+ $showAddress = $post['showAddress'] ?? '';
|
|
|
+ $userAddress = $city . $dist . $address . "({$showAddress})";
|
|
|
+ $main = $this->main;
|
|
|
+ $wxStoreId = $main->wxStoreId ?? 0;
|
|
|
+ if (empty($wxStoreId)) {
|
|
|
+ util::fail('商家还没有开通跑腿功能');
|
|
|
+ }
|
|
|
+ $orderData = [
|
|
|
+ 'wx_store_id' => $wxStoreId,
|
|
|
+ 'user_name' => $customName,
|
|
|
+ 'user_phone' => $customMobile,
|
|
|
+ 'user_lng' => $originalLng,
|
|
|
+ 'user_lat' => $originalLat,
|
|
|
+ 'user_address' => $userAddress,
|
|
|
+ 'cargo' => $cargo,
|
|
|
+ ];
|
|
|
+ $result = IntraCityExpress::preAddOrder($orderData);
|
|
|
+ $errCode = $result['errcode'] ?? 1;
|
|
|
+ if ($errCode == 0) {
|
|
|
+ $errMsg = $result['errmsg'] ?? '';
|
|
|
+ util::fail('获取运费错误:' . $errMsg);
|
|
|
+ }
|
|
|
+ $fee = $result['est_fee'] ?? 0;
|
|
|
+ //距离,好像是米
|
|
|
+ $distance = $result['distance'] ?? 0;
|
|
|
+ $sendCost = bcdiv($fee, 100, 2);
|
|
|
+ $post['sendCost'] = $sendCost;
|
|
|
+ noticeUtil::push("运费:{$sendCost} 重量:{$totalWeight} 距离:{$distance} {$customName} {$customMobile} 经纬 {$originalLng} {$originalLat}", '15280215347');
|
|
|
+ }
|
|
|
+
|
|
|
$post['modifyPrice'] = $modifyPrice;
|
|
|
//多处调用这个方法,注意同步修改,搜索关键词 createHdNewOrder
|
|
|
$return = \bizHd\order\services\OrderService::createHdOrder($post, $custom, $hasPay);
|