|
|
@@ -1,119 +1,279 @@
|
|
|
<?php
|
|
|
-/**
|
|
|
- * User: admin
|
|
|
- * Date Time: 2021/2/21 19:55
|
|
|
- */
|
|
|
|
|
|
namespace ghs\controllers;
|
|
|
|
|
|
-
|
|
|
-use biz\shop\classes\ShopExpressClass;
|
|
|
use bizGhs\custom\classes\CustomClass;
|
|
|
-use bizGhs\custom\services\CustomService;
|
|
|
-use bizGhs\express\services\MiniExpressService;
|
|
|
-use bizGhs\merchant\services\ShopService;
|
|
|
-use bizGhs\product\services\ProductService;
|
|
|
+use bizGhs\express\classes\ExpressClass;
|
|
|
+use bizGhs\order\classes\OrderClass;
|
|
|
+use common\components\dict;
|
|
|
+use common\components\imgUtil;
|
|
|
use common\components\util;
|
|
|
use Yii;
|
|
|
|
|
|
+//用于物流服务
|
|
|
class ExpressController extends BaseController
|
|
|
{
|
|
|
|
|
|
-
|
|
|
- //获取即时配送快递列表
|
|
|
- public function actionList()
|
|
|
+ //获取采购单物流运单的轨迹 ssh 20250705
|
|
|
+ public function actionGetCgExpressTrack()
|
|
|
{
|
|
|
- $data = MiniExpressService::getAllImmeDelivery("id,deliveryId,deliveryName", ['status' => 1]);
|
|
|
- util::success($data);
|
|
|
+ $get = Yii::$app->request->get();
|
|
|
+ $id = $get['id'] ?? 0;
|
|
|
+ $order = OrderClass::getById($id, true);
|
|
|
+ if (empty($order)) {
|
|
|
+ util::fail('没有找到订单');
|
|
|
+ }
|
|
|
+ if ($order->mainId != $this->mainId) {
|
|
|
+ util::fail('不是你的订单');
|
|
|
+ }
|
|
|
+ $mainId = $this->mainId;
|
|
|
+ $bizIdMap = dict::getDict('expressBizIdMap');
|
|
|
+ if (getenv('YII_ENV') == 'production') {
|
|
|
+ $bizId = $bizIdMap[$mainId] ?? 0;
|
|
|
+ if (empty($bizId)) {
|
|
|
+ util::fail('没有找到月结账号');
|
|
|
+ }
|
|
|
+ //暂时只支持顺丰
|
|
|
+ $deliveryId = 'SF';
|
|
|
+ } else {
|
|
|
+ $deliveryId = 'TEST';
|
|
|
+ $bizId = 'test_biz_id';
|
|
|
+ }
|
|
|
+ $params = [
|
|
|
+ 'deliveryId' => $deliveryId,
|
|
|
+ ];
|
|
|
+ $respond = ExpressClass::getTrack($params, $order);
|
|
|
+ util::success($respond);
|
|
|
}
|
|
|
|
|
|
- //配送费预估
|
|
|
- public function actionPreAddOrder()
|
|
|
+ public function actionTestUpdate()
|
|
|
{
|
|
|
- // util::success(['fee' => 16.5]);
|
|
|
+ $get = Yii::$app->request->get();
|
|
|
+ $id = $get['id'] ?? 0;
|
|
|
+ $action = $get['action'] ?? 0;
|
|
|
+ $order = OrderClass::getById($id, true);
|
|
|
+ if (empty($order)) {
|
|
|
+ util::fail('没有找到订单');
|
|
|
+ }
|
|
|
+ if ($order->mainId != $this->mainId) {
|
|
|
+ util::fail('不是你的订单');
|
|
|
+ }
|
|
|
+ $fhWlNo = $order->fhWlNo ?? '';
|
|
|
+ if (empty($fhWlNo)) {
|
|
|
+ util::fail('没有找到物流单');
|
|
|
+ }
|
|
|
|
|
|
- $post = Yii::$app->request->post();
|
|
|
- $expressId = $post['expressId'] ?? 0;
|
|
|
- $ghsItemInfo = $post['itemInfo'] ?? '';
|
|
|
- if (empty($ghsItemInfo)) {
|
|
|
- util::fail('请选择花材5');
|
|
|
- }
|
|
|
- $ghsItemInfo = json_decode($ghsItemInfo, true); // [{productId:0,itemPrice:1,bigNum:1,smallNum:0}]
|
|
|
-
|
|
|
- //计算总价格,总重量
|
|
|
- $cargoInfo = ProductService::groupCargo($ghsItemInfo);
|
|
|
-
|
|
|
- $shop_order_id = time();
|
|
|
- $expressData = MiniExpressService::getExpressInfo($expressId);
|
|
|
- if(empty($expressData)){
|
|
|
- util::fail("暂不支持");
|
|
|
- }
|
|
|
-
|
|
|
- $shop_no = ShopExpressClass::getShopNo($this->sjId,$this->shopId,strtolower( $expressData['deliveryId'])); //与快递签约时的门店ID
|
|
|
-
|
|
|
- $openid = isset($this->admin) && !empty($this->admin) ? $this->admin->miniOpenId : '';
|
|
|
- if (empty($openId)) {
|
|
|
- util::fail('没有找到openId');
|
|
|
- }
|
|
|
-
|
|
|
- //客户id
|
|
|
- $customId = $post['customId'] ?? 0;
|
|
|
- //获取客户name
|
|
|
- $customInfo = CustomService::getCustomInfo($customId);
|
|
|
- CustomClass::valid($customInfo, $this->shopId);
|
|
|
-
|
|
|
- //当前门店的地址信息
|
|
|
- $shopInfo = ShopService::getById($this->shopId);
|
|
|
- $sender = [
|
|
|
- 'name' => $shopInfo['shopName'],
|
|
|
- 'city' => $shopInfo['city'] ?? '',
|
|
|
- 'address' => $shopInfo['address'] ?? '',
|
|
|
- 'address_detail' => $shopInfo['floor'] ?? '',
|
|
|
- 'phone' => $shopInfo['telephone'] ?? '',
|
|
|
- 'lng' => (float)$shopInfo['long'] ?? '',
|
|
|
- 'lat' => (float)$shopInfo['lat'] ?? '',
|
|
|
- 'coordinate_type' => 0,
|
|
|
+ $orderSn = $order->orderSn;
|
|
|
+ $wayBillId = $order->fhWlNo;
|
|
|
+ $actionTime = time();
|
|
|
+ $actionTypeMap = [
|
|
|
+ 0 => 100001,
|
|
|
+ 1 => 100002,
|
|
|
+ 2 => 100003,
|
|
|
+ 3 => 200001,
|
|
|
+ 4 => 300002,
|
|
|
+ 5 => 300003,
|
|
|
+ 6 => 300004,
|
|
|
+ 7 => 400001,
|
|
|
+ 8 => 400002,
|
|
|
];
|
|
|
+ $actionType = $actionTypeMap[$action] ?? 100001;
|
|
|
+ $actionMsg = '编号' . rand(1111, 9999);
|
|
|
|
|
|
- $receiver = [
|
|
|
- 'name' => $customInfo['name'],
|
|
|
- 'city' => $post['city'] ?? '',
|
|
|
- 'address' => $post['address'] ?? '',
|
|
|
- 'address_detail' => $post['floor'] ?? '',
|
|
|
- //'phone'=>$customInfo['mobile']??'199121223333',
|
|
|
- 'phone' => '18030142050',
|
|
|
- 'lng' => (float)$post['long'] ?? '118.134343',
|
|
|
- 'lat' => (float)$post['lat'] ?? '24.491566',
|
|
|
- 'coordinate_type' => 0,
|
|
|
- ];
|
|
|
- $cargo = [
|
|
|
- 'goods_value' => $cargoInfo['totalPrice'], //总价格 元
|
|
|
- 'goods_weight' => $cargoInfo['totalWeight'], //总重量 kg
|
|
|
- 'cargo_first_class' => '鲜花',
|
|
|
- 'cargo_second_class' => '鲜花',
|
|
|
- ];
|
|
|
- $orderInfo = [
|
|
|
- 'is_direct_delivery' => 0,//闪送只能为1,只能直拿直送
|
|
|
+ $bizIdMap = dict::getDict('expressBizIdMap');
|
|
|
+ if (getenv('YII_ENV') == 'production') {
|
|
|
+ $bizId = $bizIdMap[$mainId] ?? 0;
|
|
|
+ if (empty($bizId)) {
|
|
|
+ util::fail('没有找到月结账号');
|
|
|
+ }
|
|
|
+ //暂时只支持顺丰
|
|
|
+ $deliveryId = 'SF';
|
|
|
+ } else {
|
|
|
+ $deliveryId = 'TEST';
|
|
|
+ $bizId = 'test_biz_id';
|
|
|
+ }
|
|
|
+ $params = [
|
|
|
+ 'deliveryId' => $deliveryId,
|
|
|
+ 'bizId' => $bizId,
|
|
|
+ 'orderSn' => $orderSn,
|
|
|
+ 'wayBillId' => $wayBillId,
|
|
|
+ 'actionType' => $actionType,
|
|
|
+ 'actionMsg' => $actionMsg,
|
|
|
+ 'actionTime' => $actionTime,
|
|
|
];
|
|
|
- $shop = [
|
|
|
- 'wxa_path' => '/shop',
|
|
|
- 'img_url' => 'http://www.baidu.com/test.png',
|
|
|
- 'goods_name' => '鲜花',
|
|
|
- 'goods_count' => count($ghsItemInfo),
|
|
|
+ ExpressClass::testUpdate($params, $order);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function actionCancelWayBill()
|
|
|
+ {
|
|
|
+ $get = Yii::$app->request->get();
|
|
|
+ $id = $get['id'] ?? 0;
|
|
|
+ $order = OrderClass::getById($id, true);
|
|
|
+ if (empty($order)) {
|
|
|
+ util::fail('没有找到订单');
|
|
|
+ }
|
|
|
+ if ($order->mainId != $this->mainId) {
|
|
|
+ util::fail('不是你的订单');
|
|
|
+ }
|
|
|
+ $fhWlNo = $order->fhWlNo ?? '';
|
|
|
+ if (empty($fhWlNo)) {
|
|
|
+ util::fail('没有找到物流单');
|
|
|
+ }
|
|
|
+ $mainId = $this->mainId;
|
|
|
+ $bizIdMap = dict::getDict('expressBizIdMap');
|
|
|
+ if (getenv('YII_ENV') == 'production') {
|
|
|
+ $bizId = $bizIdMap[$mainId] ?? 0;
|
|
|
+ if (empty($bizId)) {
|
|
|
+ util::fail('没有找到月结账号');
|
|
|
+ }
|
|
|
+ //暂时只支持顺丰
|
|
|
+ $deliveryId = 'SF';
|
|
|
+ } else {
|
|
|
+ $deliveryId = 'TEST';
|
|
|
+ $bizId = 'test_biz_id';
|
|
|
+ }
|
|
|
+ $params = [
|
|
|
+ 'deliveryId' => $deliveryId,
|
|
|
+ 'bizId' => $bizId,
|
|
|
];
|
|
|
- $res = MiniExpressService::preAddOrder($expressId, $shop_no, $shop_order_id, $openid, $sender, $receiver, $cargo, $orderInfo, $shop);
|
|
|
- util::success(['fee' => $res['fee']]);
|
|
|
+ ExpressClass::cancel($params, $order);
|
|
|
}
|
|
|
|
|
|
- //根据订单号发货
|
|
|
- public function actionAddOrder()
|
|
|
+ //新建运单 ssh
|
|
|
+ public function actionCreateWayBill()
|
|
|
{
|
|
|
$post = Yii::$app->request->post();
|
|
|
- $expressId = $post['expressId'] ?? 0;// 快递ID
|
|
|
- $orderSn = $post['orderSn'] ?? '';
|
|
|
+ $id = $post['id'] ?? 0;
|
|
|
+ $weight = $post['weight'] ?? 0;
|
|
|
+ if (empty($weight) || $weight <= 0) {
|
|
|
+ util::fail('请填写重量');
|
|
|
+ }
|
|
|
+ $length = $post['length'] ? trim($post['length']) : 0;
|
|
|
+ if (!is_numeric($length) || $length <= 0) {
|
|
|
+ util::fail('请填写长度');
|
|
|
+ }
|
|
|
+ $width = $post['width'] ? trim($post['width']) : 0;
|
|
|
+ if (!is_numeric($width) || $width <= 0) {
|
|
|
+ util::fail('请填写宽度');
|
|
|
+ }
|
|
|
+ $height = $post['height'] ? trim($post['height']) : 0;
|
|
|
+ if (!is_numeric($height) || $height <= 0) {
|
|
|
+ util::fail('请填写高度');
|
|
|
+ }
|
|
|
+ $packageNum = $post['packageNum'] ? trim($post['packageNum']) : 0;
|
|
|
+ if (!is_numeric($packageNum) || $packageNum <= 0) {
|
|
|
+ util::fail('请填写包裹数量');
|
|
|
+ }
|
|
|
+
|
|
|
+ $order = OrderClass::getById($id, true);
|
|
|
+ if (empty($order)) {
|
|
|
+ util::fail('没有找到订单');
|
|
|
+ }
|
|
|
+ if ($order->mainId != $this->mainId) {
|
|
|
+ util::fail('不是你的订单');
|
|
|
+ }
|
|
|
+ if ($order->payStatus == 0) {
|
|
|
+ util::fail('订单没有付款');
|
|
|
+ }
|
|
|
+ if (in_array($order->status, [3, 4]) && $order->fhWlStatus == 1) {
|
|
|
+ util::fail('已经发过快递了');
|
|
|
+ }
|
|
|
+ $orderSn = $order->orderSn ?? '';
|
|
|
+ $customId = $order->customId ?? 0;
|
|
|
+ $custom = CustomClass::getById($customId, true);
|
|
|
+ if (empty($custom)) {
|
|
|
+ util::fail('没有找到客户');
|
|
|
+ }
|
|
|
+ //要先去后台绑定,这里填写才有用,mainId对应月结账号
|
|
|
+ $bizIdMap = dict::getDict('expressBizIdMap');
|
|
|
+ $mainId = $this->mainId;
|
|
|
|
|
|
+ if (getenv('YII_ENV') == 'production') {
|
|
|
+ $bizId = $bizIdMap[$mainId] ?? 0;
|
|
|
+ if (empty($bizId)) {
|
|
|
+ util::fail('没有找到月结账号');
|
|
|
+ }
|
|
|
+ //暂时只支持顺丰
|
|
|
+ $deliveryId = 'SF';
|
|
|
+ $serviceType = 0;
|
|
|
+ $serviceName = '标准快递';
|
|
|
+ //销花宝移动应用的微信appId
|
|
|
+ $wxAppId = 'wxb379c1f2f3ef705e';
|
|
|
+ } else {
|
|
|
+ $deliveryId = 'TEST';
|
|
|
+ $bizId = 'test_biz_id';
|
|
|
+ $serviceType = 1;
|
|
|
+ $serviceName = 'test_service_name';
|
|
|
+ $wxAppId = 'wx4bf74abf453eb789';
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+// $admin = $this->admin;
|
|
|
+// $openId = $admin->ghsMiniOpenId ?? '';
|
|
|
+// if (empty($openId)) {
|
|
|
+// util::fail('请用小程序发单');
|
|
|
+// }
|
|
|
+
|
|
|
+ $shop = $this->shop;
|
|
|
+ $shopName = $shop->shopName;
|
|
|
+ $sjName = $shop->merchantName;
|
|
|
+ $senderName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
|
|
|
+ $senderMobile = !empty($shop->telephone) ? $shop->telephone : $shop->mobile;
|
|
|
+ $senderProvince = $shop->province;
|
|
|
+ $senderCity = $shop->city;
|
|
|
+ $senderAddress = $shop->address;
|
|
|
+ if (empty($senderAddress)) {
|
|
|
+ util::fail('你的门店地址还没有设置');
|
|
|
+ }
|
|
|
|
|
|
+ $receiverName = $custom->name;
|
|
|
+ $receiverMobile = $custom->mobile;
|
|
|
+ $receiverProvince = $custom->province;
|
|
|
+ $receiverCity = $custom->city;
|
|
|
+ $receiverAddress = $custom->address;
|
|
|
+ $receiverFloor = $custom->floor;
|
|
|
+ $goodsName = '鲜花花材';
|
|
|
+ $customRemark = '鲜花花材,编号:' . $order->sendNum;
|
|
|
+ $goodsCount = ceil($order->itemNum);;
|
|
|
+
|
|
|
+ $shopImgUrl = imgUtil::groupImg('logo4.png') . "?x-oss-process=image/resize,m_fill,h_80,w_80";
|
|
|
+
|
|
|
+ $staff = $this->shopAdmin;
|
|
|
+ $staffId = $staff->id;
|
|
|
+ $staffName = $staff->name ?? '';
|
|
|
+
|
|
|
+ $params = [
|
|
|
+ 'bizId' => $bizId,// 快递公司客户编码或月结账号
|
|
|
+ //'openId' => $openId,
|
|
|
+ 'senderName' => $senderName,
|
|
|
+ 'senderMobile' => $senderMobile,
|
|
|
+ 'senderProvince' => $senderProvince,
|
|
|
+ 'senderCity' => $senderCity,
|
|
|
+ 'senderAddress' => $senderAddress,
|
|
|
+ 'receiverName' => $receiverName,
|
|
|
+ 'receiverMobile' => $receiverMobile,
|
|
|
+ 'receiverProvince' => $receiverProvince,
|
|
|
+ 'receiverCity' => $receiverCity,
|
|
|
+ 'receiverAddress' => $receiverAddress,
|
|
|
+ 'receiverFloor' => $receiverFloor,
|
|
|
+ 'goodsCount' => $goodsCount,
|
|
|
+ 'goodsName' => $goodsName,
|
|
|
+ 'customRemark' => $customRemark,
|
|
|
+ 'weight' => $weight,
|
|
|
+ 'length' => $length,
|
|
|
+ 'width' => $width,
|
|
|
+ 'height' => $height,
|
|
|
+ 'packageNum' => $packageNum,
|
|
|
+ 'deliveryId' => $deliveryId,
|
|
|
+ 'serviceType' => $serviceType,
|
|
|
+ 'serviceName' => $serviceName,
|
|
|
+ 'orderSn' => $orderSn,
|
|
|
+ 'shopImgUrl' => $shopImgUrl,
|
|
|
+ 'staffId' => $staffId,
|
|
|
+ 'staffName' => $staffName,
|
|
|
+ 'wxAppId' => $wxAppId,
|
|
|
+ ];
|
|
|
+ ExpressClass::addWayBill($params, $order);
|
|
|
+ util::complete('操作成功');
|
|
|
+ }
|
|
|
|
|
|
-}
|
|
|
+}
|