Browse Source

配送流程的完善

shish 6 years ago
parent
commit
a1c15dcd86

+ 6 - 6
app/business/controllers/OrderSendController.php

@@ -37,12 +37,12 @@ class OrderSendController extends BaseController
 	{
 		$post = Yii::$app->request->post();
 		$id = isset($post['id']) ? $post['id'] : 0;
-		$option = isset($post['option']) ? $post['option'] : 0;
 		$order = OrderService::getById($id);
 		OrderService::valid($order, $this->merchantId);
-		OrderSendService::deliver(['id' => $id, 'option' => $option]);
+		$post['merchantId'] = $this->merchantId;
+		OrderSendService::deliver($post);
 	}
-	
+
 	//送达 shish 2019.12.17
 	public function actionReach()
 	{
@@ -53,7 +53,7 @@ class OrderSendController extends BaseController
 		OrderService::valid($order, $this->merchantId);
 		OrderSendService::reach(['id' => $id, 'option' => $option]);
 	}
-
+	
 	//向快递公司发起配送需求
 	public function actionExpress()
 	{
@@ -78,12 +78,12 @@ class OrderSendController extends BaseController
 	{
 	
 	}
-
+	
 	//快递服务提供方
 	public function actionExpressProvide()
 	{
 		$data = ['id' => 1, 'name' => '达达'];
 		util::success($data);
 	}
-
+	
 }

+ 37 - 0
biz/order/classes/OrderExpressClass.php

@@ -0,0 +1,37 @@
+<?php
+
+namespace biz\order\classes;
+
+use Yii;
+use biz\base\classes\BaseClass;
+
+class OrderExpressClass extends BaseClass
+{
+	
+	public static $baseFile = '\biz\order\models\OrderExpress';
+	
+	//配送方列表
+	public static $side = [
+		1 => '达达',
+		2 => '蜂鸟',
+	];
+	
+	//配送方ID
+	const SIDE_DADA = 1;
+	const SIDE_FN = 2;
+	
+	//取当前订单的配送信息
+	public static function getExpress($orderId)
+	{
+		$info = self::getByCondition(['orderId' => $orderId]);
+		if (empty($info)) {
+			return [];
+		}
+		$sideId = $info['sideId'];
+		$sideData = self::$side;
+		$sideName = isset($sideData[$sideId]) ? $sideData[$sideId] : '';
+		$info['sideName'] = $sideName;
+		return $info;
+	}
+
+}

+ 15 - 0
biz/order/models/OrderExpress.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace biz\order\models;
+
+use biz\base\models\Base;
+
+class OrderExpress extends Base
+{
+	
+	public static function tableName()
+	{
+		return 'xhOrderExpress';
+	}
+	
+}

+ 12 - 0
biz/order/services/OrderExpressService.php

@@ -0,0 +1,12 @@
+<?php
+
+namespace biz\order\services;
+
+use biz\base\services\BaseService;
+
+class OrderExpressService extends BaseService
+{
+
+	public static $baseFile = '\biz\order\classes\OrderExpressClass';
+	
+}

+ 28 - 31
biz/order/services/OrderSendService.php

@@ -7,6 +7,7 @@ use biz\goods\classes\CategoryClass;
 use biz\goods\classes\UsageClass;
 use biz\merchant\services\MerchantCapitalService;
 use biz\order\classes\OrderClass;
+use biz\order\classes\OrderExpressClass;
 use biz\order\classes\OrderSendClass;
 use biz\order\models\Order;
 use biz\promote\services\CouponRightService;
@@ -33,7 +34,7 @@ class OrderSendService extends BaseService
 		if ($printOrderId != $currentId) {
 			util::fail('当前流程无法操作');
 		}
-		//1有配送单 2 填单并打单 3 不需要配送单
+		//1有配送单 2 填单并打单
 		if (in_array($option, [1, 2]) == false) {
 			util::fail('操作无效');
 		}
@@ -61,29 +62,35 @@ class OrderSendService extends BaseService
 		if ($deliverId != $currentId) {
 			util::fail('当前流程无法操作');
 		}
-		//1 确认发货
-		if (in_array($option, [1]) == false) {
-			util::fail('操作无效');
-		}
 		$time = time();
-		OrderSendClass::updateByCondition(['orderId' => $id, 'actionId' => $deliverId], ['option' => $option, 'finishTime' => $time]);
-		OrderClass::updateById($id, ['status' => 2, 'currentFlow' => 3]);
 		
 		$sendType = isset($data['sendType']) ? $data['sendType'] : 1;
-		//使用快递
-		$sendInfo = [];
+		
+		//1 自己送 2代送
 		if ($sendType == 2) {
-			$sendSide = $data['sendSide'];
-			$sendTime = $data['sendTime'];
+			$side = $data['sendSide'];
+			$sendTime = strtotime(date("Y-m-d") . ' ' . $data['sendTime']);
+			if ($sendTime < ($time + 30 * 60)) {
+				util::fail('请选择30分钟之后的时间');
+			}
+			$sendInfo = [
+				'side' => $side,
+				'sendTime' => $sendTime,
+				'addTime' => $time,
+				'sendTip' => 0,
+				'merchantId' => $data['merchantId'],
+				'orderId' => $id,
+				'cost' => 6,
+				'tip' => 0,
+				'distance' => 7,
+				'sendTime' => $sendTime,
+				'side' => $side,
+			];
+			OrderExpressClass::add($sendInfo);
 		}
-		$sendInfo = [
-			'sendSideName' => '达达',
-			'sendDistance' => 5.5,
-			'sendCost' => 20,
-			'sendTip' => 5,
-			'sendTime' => '1576549653',
-			'sendStatus' => 0,
-		];
+		
+		OrderSendClass::updateByCondition(['orderId' => $id, 'actionId' => $deliverId], ['option' => $option, 'finishTime' => $time]);
+		OrderClass::updateById($id, ['status' => 2, 'currentFlow' => 3, 'sendType' => $sendType]);
 		
 		//进入送达流程
 		$reachId = $actionIdList['reach'];
@@ -112,7 +119,7 @@ class OrderSendService extends BaseService
 		$time = time();
 		OrderSendClass::updateByCondition(['orderId' => $id, 'actionId' => $reachId], ['option' => $option, 'finishTime' => $time]);
 		OrderClass::updateById($id, ['status' => 5, 'currentFlow' => 4]);
-
+		
 		util::complete();
 	}
 	
@@ -137,17 +144,7 @@ class OrderSendService extends BaseService
 				}
 			}
 			if ($actionId == $idList['deliver']) {
-				$list[$key]['sendInfo'] = [];
-				if ($order['sendType'] == 2) {
-					$list[$key]['sendInfo'] = [
-						'sendSideName' => '达达',
-						'sendDistance' => 5.5,
-						'sendCost' => 20,
-						'sendTip' => 5,
-						'sendTime' => '1576549653',
-						'sendStatus' => 0,
-					];
-				}
+				$list[$key]['sendInfo'] = $order['sendType'] == 3 ? OrderExpressClass::getExpress($orderId) : [];
 			}
 			if ($actionId == $idList['finish']) {
 				$list[$key]['classify'] = [];

+ 25 - 8
console/controllers/UpgradeController.php

@@ -693,7 +693,7 @@ ALTER TABLE `xhRecharge` AUTO_INCREMENT=135790;
 ALTER TABLE `xhRecharge` DROP COLUMN `createTime`;
 ALTER TABLE `xhRecharge` DROP COLUMN `updateTime`;";
 		Yii::$app->db->createCommand($sql)->execute();
-
+		
 		$sql = "ALTER TABLE `xhUserAsset` MODIFY `memberLevel` SMALLINT NOT NULL DEFAULT -1 COMMENT '会员等级 -1普通用户 0普通会员,登记了手机号 1 一级会员';
 ALTER TABLE `xhUserAsset` CHANGE `memberLevel` `member` SMALLINT NOT NULL DEFAULT -1 COMMENT '会员等级 -1普通用户 0普通会员,登记了手机号 1 一级会员';
 ALTER TABLE `xhUserAsset` DROP COLUMN `isMember`;
@@ -1234,20 +1234,20 @@ ALTER TABLE `xhMerchantExtend` MODIFY `freight` TINYINT NOT NULL DEFAULT 0 COMME
 ALTER TABLE `xhMerchantExtend` ADD freeDistance TINYINT NOT NULL DEFAULT 0 COMMENT '免运费距离' AFTER `freight`;
 UPDATE `xhMerchantExtend` SET `freeDistance`=5;";
 		Yii::$app->db->createCommand($sql)->execute($sql);
-
+		
 		$sql = "ALTER TABLE `xhGoodsCategory` ADD `goodsName` VARCHAR(200) NOT NULL DEFAULT '' COMMENT '商品名称' AFTER `gId`;";
 		Yii::$app->db->createCommand($sql)->execute($sql);
-
+		
 		//确认密码判断字段 shish 2020.3.12
 		$sql = "ALTER TABLE `xhUser` ADD hasPayPwd TINYINT NOT NULL DEFAULT 0 COMMENT '0 没有支付密码 1有' AFTER `payPassword`;";
 		Yii::$app->db->createCommand($sql)->execute($sql);
-
+		
 		$sql = "ALTER TABLE `xhOrder` ADD inform TINYINT NOT NULL DEFAULT 0 COMMENT '通知 0待通知 1通知成功 2通知失败' AFTER `sendStatus`;";
 		Yii::$app->db->createCommand($sql)->execute($sql);
-
+		
 		$sql = "ALTER TABLE `xhOrder` MODIFY `sendType` TINYINT NOT NULL DEFAULT 0 COMMENT '0未确认配送方式 1免配送 2自己送 3别人送;快递送';";
 		Yii::$app->db->createCommand($sql)->execute($sql);
-
+		
 		$sql = "DROP TABLE IF EXISTS `xhStatOrderCount`;
 CREATE TABLE `xhStatOrderCount` (
   `id` INT(11) NOT NULL AUTO_INCREMENT,
@@ -1259,9 +1259,26 @@ CREATE TABLE `xhStatOrderCount` (
   KEY `merchant` (`merchantId`,`time`)
 ) COMMENT='商家月订单量,包括未付款';";
 		Yii::$app->db->createCommand($sql)->execute($sql);
-		
-	}
 
+		//第三方配送
+		$sql = "CREATE TABLE `xhOrderExpress`(
+id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+orderId INT NOT NULL DEFAULT 0 COMMENT '订单id',
+merchantId INT NOT NULL DEFAULT 0 COMMENT '商家id',
+`side` TINYINT NOT NULL DEFAULT 0 COMMENT '配送方',
+distance DECIMAL(6,1) NOT NULL DEFAULT 0.0 COMMENT '距离',
+`cost` DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '运费',
+`tip` DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '小费',
+`sendTime` INT NOT NULL DEFAULT 0 COMMENT '要求配送时间',
+`addTime` INT NOT NULL DEFAULT 0 COMMENT '添加时间'
+)COMMENT='第三方配送信息';";
+		Yii::$app->db->createCommand($sql)->execute($sql);
+
+		$sql = "ALTER TABLE `xhOrderExpress` CHANGE `side` `sideId` TINYINT NOT NULL DEFAULT 0 COMMENT '配送方id';";
+		Yii::$app->db->createCommand($sql)->execute($sql);
+
+	}
+	
 	//数据迁移 shish 2020.1.12
 	//./yii upgrade/sync
 	public function actionSync()