Quellcode durchsuchen

orderId orderSn 变化

shish vor 6 Jahren
Ursprung
Commit
96923bbe30

+ 9 - 10
app/client/controllers/OrderController.php

@@ -105,7 +105,7 @@ class OrderController extends BaseController
 		$post['actPrice'] = $actPrice;
 		$order = OrderService::addOrder($post);
 		$orderId = $order['id'];
-		
+		$orderSn = $order['orderSn'];
 		$data = [
 			'orderId' => $orderId,
 			'goodsId' => $goodsId,
@@ -120,8 +120,7 @@ class OrderController extends BaseController
 			'createTime' => date("Y-m-d H:i:s"),
 		];
 		OrderGoodsService::add($data);//创建订单商品列表
-		
-		util::success(['orderId' => $orderId, 'totalPrice' => $showPrice, 'couponId' => $couponId]);
+		util::success(['orderSn' => $orderSn, 'totalPrice' => $showPrice, 'couponId' => $couponId]);
 	}
 	
 	//下单要用到的相关信息 shish 2019.12.6
@@ -138,13 +137,13 @@ class OrderController extends BaseController
 	public function actionBalancePay()
 	{
 		$post = Yii::$app->request->post();
-		$orderId = isset($post['orderId']) ? $post['orderId'] : 0;
+		$orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
 		$payPassword = isset($post['payPassword']) ? $post['payPassword'] : 0;
 		$couponId = isset($post['couponId']) ? $post['couponId'] : 0;
-		$order = OrderService::getById($orderId);
-		
+		$order = OrderService::getByOrderSn($orderSn);
+
 		//dd(password_hash('123456', PASSWORD_BCRYPT));
-		
+
 		//验证支付密码是否正确
 		UserService::validPayPassword($payPassword, $this->user);
 		
@@ -154,7 +153,7 @@ class OrderController extends BaseController
 		$typeList = configDict::getConfig('capitalType');
 		$capitalType = $typeList['xhOrder']['id'];
 		$totalFee = $order['actPrice'];
-		xhPayToolService::balancePay($orderId, $totalFee, $capitalType, $couponId);
+		xhPayToolService::balancePay($orderSn, $totalFee, $capitalType, $couponId);
 		util::success('支付成功');
 	}
 	
@@ -377,7 +376,7 @@ class OrderController extends BaseController
 			util::fail('无效的支付方式');
 		}
 	}
-
+	
 	//订单列表 shish 2019.12.12
 	public function actionList()
 	{
@@ -385,5 +384,5 @@ class OrderController extends BaseController
 		$list = OrderService::getOrderList($where);
 		util::success($list);
 	}
-
+	
 }

+ 7 - 2
biz/order/classes/OrderClass.php

@@ -18,7 +18,7 @@ class OrderClass extends BaseClass
 	{
 		$date = date("Y-m-d H:i:s");
 		$merchantId = $data['merchantId'];
-		$data['id'] = stringUtil::generateOrderNo($merchantId, $data['userId']);
+		$data['orderSn'] = stringUtil::generateOrderNo($merchantId, $data['userId']);
 		$data['payStatus'] = 0;
 		$data['createTime'] = $date;
 		$data['addTime'] = time();
@@ -34,5 +34,10 @@ class OrderClass extends BaseClass
 		$return = self::add($data);
 		return $return;
 	}
-	
+
+	public static function getByOrderSn($orderSn)
+	{
+		return self::getByCondition(['orderSn' => $orderSn]);
+	}
+
 }

+ 7 - 1
biz/order/services/OrderService.php

@@ -80,5 +80,11 @@ class OrderService extends BaseService
 			util::fail('订单已经付款了');
 		}
 	}
-	
+
+	//根据编号查询 shish 2019.12.14
+	public static function getByOrderSn($orderSn)
+	{
+		return OrderClass::getByOrderSn($orderSn);
+	}
+
 }

+ 66 - 56
common/services/xhOrderService.php

@@ -1,80 +1,89 @@
 <?php
+
 namespace common\services;
+
 use Yii;
 use common\models\xhOrder;
 use common\components\stringUtil;
 use common\components\configDict;
 
-class xhOrderService {
-
+class xhOrderService
+{
+	
 	/**
 	 * 创建订单
 	 */
 	public static function add($data)
 	{
-		$date					= date("Y-m-d H:i:s");
-		$merchantId				= isset($data['merchantId']) ? $data['merchantId'] : 0;
-		$data['id']				= self::generateOrderNo($data['merchantId'],$data['userId']);
-		$data['merchantId']		= $merchantId;
-		$data['payStatus']		= 0;
-		$data['createTime']		= $date;
-		$data['addTime']		= time();
-
-		$time					= strtotime(date("Y-m-d"));
-        $year					= date("Y");
-        $month					= date("m");
-		$dayReturn				= xhOrderDayNumService::addOne($time, $merchantId);
-		$monthReturn			= xhOrderMonthNumService::addOne($year, $month, $merchantId);
-		$data['sendNum']		= (string)$monthReturn['riseNum'];//将花店每月的总订单数作为编号
-		$return					= xhOrder::add($data);		
-		$id						= $return['id'];
+		$date = date("Y-m-d H:i:s");
+		$merchantId = isset($data['merchantId']) ? $data['merchantId'] : 0;
+		$data['id'] = self::generateOrderNo($data['merchantId'], $data['userId']);
+		$data['merchantId'] = $merchantId;
+		$data['payStatus'] = 0;
+		$data['createTime'] = $date;
+		$data['addTime'] = time();
+		
+		$time = strtotime(date("Y-m-d"));
+		$year = date("Y");
+		$month = date("m");
+		$dayReturn = xhOrderDayNumService::addOne($time, $merchantId);
+		$monthReturn = xhOrderMonthNumService::addOne($year, $month, $merchantId);
+		$data['sendNum'] = (string)$monthReturn['riseNum'];//将花店每月的总订单数作为编号
+		$return = xhOrder::add($data);
+		$id = $return['id'];
 		self::refresh($id);
 		return $return;
 	}
-
-    /**
-     * 通过ID获取数据
-     * @param $id
-     * @param int $merchantId 商户号  --  默认为0; 当不为0时,会与订单的merchantId进行校验(必须要相同)
-     * @return array|null|\yii\db\ActiveRecord
-     */
-	public static function getById($id, $merchantId=0)
+	
+	/**
+	 * 通过ID获取数据
+	 * @param $id
+	 * @param int $merchantId 商户号  --  默认为0; 当不为0时,会与订单的merchantId进行校验(必须要相同)
+	 * @return array|null|\yii\db\ActiveRecord
+	 */
+	public static function getById($id, $merchantId = 0)
 	{
-		$order			= xhOrder::find()->where(['id' => $id])->asArray()->one();
+		$order = xhOrder::find()->where(['id' => $id])->asArray()->one();
 		return $order;
 	}
+	
+	public static function getByOrderSn($orderSn)
+	{
+		return xhOrder::find()->where(['orderSn' => $orderSn])->asArray()->one();
+	}
 
-	public static function updateById($id,$data)
+	public static function updateById($id, $data)
 	{
 		$re = xhOrder::updateById($id, $data);
 		self::refresh($id);
 		return $re;
 	}
-
-	public static function updateByCondition($condition,$data)
+	
+	public static function updateByCondition($condition, $data)
 	{
 		xhOrder::updateByCondition($condition, $data);
 	}
-
+	
 	public static function refresh($id)
 	{
-		$cacheKey = configDict::getCacheKey('order').$id;
+		$cacheKey = configDict::getCacheKey('order') . $id;
 		Yii::$app->redis->executeCommand('DEL', [$cacheKey]);
 		self::getById($id);
 	}
-
+	
 	public static function getAllByCondition($condition)
 	{
 		return xhOrder::find()->where($condition)->orderBy('createTime desc')->asArray()->all();
 	}
-
-    /**
-     * 付款订单 表单提交数据处理
-     * @param $payAdd
-     * @param $post
-     */
-	public static function formatPost(&$payAdd, $post){
-	    $payAdd['actPrice'] = self::handle($post, 'consumeAmount', 0);
+	
+	/**
+	 * 付款订单 表单提交数据处理
+	 * @param $payAdd
+	 * @param $post
+	 */
+	public static function formatPost(&$payAdd, $post)
+	{
+		$payAdd['actPrice'] = self::handle($post, 'consumeAmount', 0);
 		$payAdd['receiveProvince'] = self::handle($post, 'province');
 		$payAdd['receiveCity'] = self::handle($post, 'city');
 		$payAdd['receiveDist'] = self::handle($post, 'receiveDist');
@@ -94,16 +103,16 @@ class xhOrderService {
 		$payAdd['receiveMobile'] = self::handle($post, 'receiveMobile');
 		$payAdd['receiveUserName'] = self::handle($post, 'receiveUserName');
 		$payAdd['needCard'] = (int)self::handle($post, 'needCard', 0);//默认不要贺卡
-        $payAdd['needSend'] = (int)self::handle($post, 'needSend', 1);//默认要配送
+		$payAdd['needSend'] = (int)self::handle($post, 'needSend', 1);//默认要配送
 		$payAdd['blessing'] = self::handle($post, 'blessing');
-        $payAdd['remark'] = self::handle($post, 'remark');
-
+		$payAdd['remark'] = self::handle($post, 'remark');
+		
 		$payAdd['uniCode'] = self::handle($post, 'uniCode'); //唯一号码,预留字段
 		$payAdd['luckyNum'] = self::handle($post, 'luckyNum', 0); //抽奖号码
 		$payAdd['printStatus'] = self::handle($post, 'printStatus', 0);
 		$payAdd['status'] = self::handle($post, 'status', 0); //订单生存状态 0正常 1删除
 		$payAdd['orderName'] = self::handle($post, 'orderName'); //订单名称(商品名称)
-        $payAdd['sourceType'] = self::handle($post, 'sourceType', 1); //订单来源,0商城订单 1付款订单
+		$payAdd['sourceType'] = self::handle($post, 'sourceType', 1); //订单来源,0商城订单 1付款订单
 	}
 	
 	/**
@@ -114,20 +123,21 @@ class xhOrderService {
 	 * @param string $checkType
 	 * @return string
 	 */
-	public static function handle($post, $key, $default='', $checkType=''){
-		switch ($checkType){
+	public static function handle($post, $key, $default = '', $checkType = '')
+	{
+		switch ($checkType) {
 			case 'date':
 				break;
 		}
 		return isset($post["$key"]) ? $post["$key"] : $default;
 	}
-
-    /**
-     * 生成订单号
-     */
-	public static function generateOrderNo($merchantId,$userId)
-    {
-        return stringUtil::generateOrderNo($merchantId,$userId);
-    }
-
+	
+	/**
+	 * 生成订单号
+	 */
+	public static function generateOrderNo($merchantId, $userId)
+	{
+		return stringUtil::generateOrderNo($merchantId, $userId);
+	}
+	
 }

+ 27 - 26
common/services/xhPayToolService.php

@@ -23,37 +23,37 @@ class xhPayToolService
 	/**
 	 * 余额支付
 	 */
-	public static function balancePay($orderId, $totalFee, $capitalType, $couponId)
+	public static function balancePay($orderSn, $totalFee, $capitalType, $couponId)
 	{
 		$payWay = configDict::getConfig('payWay', 'balancePay');
-		return self::basePay($orderId, $totalFee, $capitalType, $couponId, $payWay);
+		return self::basePay($orderSn, $totalFee, $capitalType, $couponId, $payWay);
 	}
 	
 	/**
 	 * 微信支付
 	 */
-	public static function weixinPay($orderId, $totalFee, $capitalType, $couponId)
+	public static function weixinPay($orderSn, $totalFee, $capitalType, $couponId)
 	{
 		$payWay = configDict::getConfig('payWay', 'weixinPay');
-		return self::basePay($orderId, $totalFee, $capitalType, $couponId, $payWay);
+		return self::basePay($orderSn, $totalFee, $capitalType, $couponId, $payWay);
 	}
 	
 	/**
 	 * 支付宝支付
 	 */
-	public static function alipay($orderId, $totalFee, $capitalType, $couponId, $alipayParams)
+	public static function alipay($orderSn, $totalFee, $capitalType, $couponId, $alipayParams)
 	{
 		$payWay = configDict::getConfig('payWay', 'alipay');
-		return self::basePay($orderId, $totalFee, $capitalType, $couponId, $payWay, $alipayParams);
+		return self::basePay($orderSn, $totalFee, $capitalType, $couponId, $payWay, $alipayParams);
 	}
 	
 	/**
 	 * 现金支付,转店主微信,转店主支付宝
 	 */
-	public static function cashPay($orderId, $totalFee, $capitalType, $couponId)
+	public static function cashPay($orderSn, $totalFee, $capitalType, $couponId)
 	{
 		$payWay = configDict::getConfig('payWay', 'cashPay');
-		return self::basePay($orderId, $totalFee, $capitalType, $couponId, $payWay);
+		return self::basePay($orderSn, $totalFee, $capitalType, $couponId, $payWay);
 	}
 	
 	/**
@@ -61,7 +61,7 @@ class xhPayToolService
 	 * $capitalType 需要支付订单来源:xhOrder xhActiveOrder xhApplyOrder
 	 * $payWay 支付方式:weixinPay alipay balancePay cashPay
 	 */
-	public static function basePay($orderId, $totalFee, $capitalType, $couponId, $payWay, $alipayParams = [])
+	public static function basePay($orderSn, $totalFee, $capitalType, $couponId, $payWay, $alipayParams = [])
 	{
 		$connection = Yii::$app->db;//事务处理
 		$transaction = $connection->beginTransaction();
@@ -69,31 +69,32 @@ class xhPayToolService
 			$typeList = configDict::getConfig('capitalType');//流水类型列表
 			switch ($capitalType) {
 				case $typeList['xhOrder']['id']://购买商品
-					$order = xhOrderService::getById($orderId);
+					$order = xhOrderService::getByOrderSn($orderSn);
 					break;
 				case $typeList['xhActiveOrder']['id']://活动报名
-					$order = xhActiveOrderService::getById($orderId);
+					$order = xhActiveOrderService::getById($orderSn);
 					break;
 				case $typeList['xhApplyOrder']['id']:
-					$order = xhApplyOrderService::getById($orderId);
+					$order = xhApplyOrderService::getById($orderSn);
 					break;
 				default:
-					Yii::warning('获取订单信息失败,回调传过来的 capitalType 不符合要求,capitalType:' . $capitalType . ' orderId:' . $orderId);
+					Yii::warning('获取订单信息失败,回调传过来的 capitalType 不符合要求,capitalType:' . $capitalType . ' orderSn:' . $orderSn);
 					util::fail('订单流水类型不明确');
 			}
 			if (empty($order)) {
-				Yii::warning('order info empty,capitalType:' . $capitalType . ' orderId:' . $orderId);
+				Yii::warning('order info empty,capitalType:' . $capitalType . ' orderSn:' . $orderSn);
 				util::fail('订单信息为空');
 			}
 			if ($order['payStatus'] == 1) {
-				Yii::warning('already pay,capitalType:' . $capitalType . ' orderId:' . $orderId);
+				Yii::warning('already pay,capitalType:' . $capitalType . ' orderSn:' . $orderSn);
 				util::fail('已经付款过了');
 			}
 			if ($totalFee != $order['actPrice']) {
-				Yii::warning('第三方回调金额与订单表里金额不一致,capitalType:' . $capitalType . ' orderId:' . $orderId);
+				Yii::warning('第三方回调金额与订单表里金额不一致,capitalType:' . $capitalType . ' orderSn:' . $orderSn);
 				util::fail('订单出错了');
 			}
 			$orderId = $order['id'];
+			$orderSn = $order['orderSn'];
 			$userId = $order['userId'];
 			$totalFee = $order['actPrice'];
 			$merchantId = $order['merchantId'];
@@ -117,7 +118,7 @@ class xhPayToolService
 			}
 			if (empty($userId) && $payWay == $balancePay) {
 				$transaction->rollBack();
-				Yii::warning('未登陆用户无法使用余额支付,capitalType:' . $capitalType . ' orderId:' . $orderId);
+				Yii::warning('未登陆用户无法使用余额支付,capitalType:' . $capitalType . ' orderSn:' . $orderSn);
 				util::fail('没有登陆不能使用余额支付');
 			}
 			$updateData = [];
@@ -146,7 +147,7 @@ class xhPayToolService
 			
 			$balance = $userAsset['balance'];
 			if ($payWay == $balancePay && $balance < $totalFee) {
-				Yii::warning('余额不足,capitalType:' . $capitalType . ' orderId:' . $orderId);
+				Yii::warning('余额不足,capitalType:' . $capitalType . ' orderSn:' . $orderSn);
 				util::fail('余额不足');
 			}
 			
@@ -181,7 +182,7 @@ class xhPayToolService
 				default:
 			}
 			$capitalData = [
-				'relateId' => (string)$orderId,
+				'relateId' => (string)$orderSn,
 				'balance' => $mBalance,
 				'totalIncome' => $mIncome,
 				'totalExpend' => $mExpend,
@@ -207,19 +208,19 @@ class xhPayToolService
 			$updateData['payTime'] = $now;
 			switch ($capitalType) {
 				case $typeList['xhOrder']['id']://购买商品
-					xhOrderService::updateById($orderId, $updateData);
+					xhOrderService::updateById($orderSn, $updateData);
 					//发货里的下单流程完成
 					OrderSendClass::placeOrder(['orderId' => $orderId, 'payTime' => $now]);
 					break;
 				case $typeList['xhActiveOrder']['id']://活动报名
-					xhActiveOrderService::updateById($orderId, $updateData);
+					xhActiveOrderService::updateById($orderSn, $updateData);
 					break;
 				case $typeList['xhApplyOrder']['id']://申请服务
 					$updateData['inviteCodeStatus'] = 1;
-					xhApplyOrderService::updateById($orderId, $updateData);
+					xhApplyOrderService::updateById($orderSn, $updateData);
 					break;
 				default:
-					Yii::warning('更新订单失败,回调传过来的 capitalType 不符合要求,即订单流水类型不明确,capitalType:' . $capitalType . ' orderId:' . $orderId);
+					Yii::warning('更新订单失败,回调传过来的 capitalType 不符合要求,即订单流水类型不明确,capitalType:' . $capitalType . ' orderSn:' . $orderSn);
 					util::fail('订单流水类型不明确');
 			}
 			
@@ -241,7 +242,7 @@ class xhPayToolService
 				'userId' => $userId,
 				'userName' => $userName,
 				'merchantId' => $merchantId,
-				'relateId' => (string)$orderId,
+				'relateId' => (string)$orderSn,
 				'growth' => $userGrowth,
 				'num' => floor($totalFee),
 				'io' => 1,
@@ -256,7 +257,7 @@ class xhPayToolService
 			xhUserGrowthService::add($integralData);//用户兑换型积分流水增加
 			
 			$userCapitalData = [
-				'relateId' => (string)$orderId,
+				'relateId' => (string)$orderSn,
 				'balance' => $remainBalance,
 				'totalIncome' => $userAsset['totalIncome'],
 				'totalExpend' => $userTotalExpend,
@@ -279,7 +280,7 @@ class xhPayToolService
 			
 			//订单有选择分类和用途,则直接进行老带新的发放和资金分类登记 shish 2019.9.3
 			if (isset($order['categoryId']) && !empty($order['categoryId']) && isset($order['usageId']) && !empty($order['usageId'])) {
-				//$setOrderData = ['id' => $orderId, 'categoryId' => $order['categoryId'], 'usageId' => $order['usageId']];
+				//$setOrderData = ['id' => $orderSn, 'categoryId' => $order['categoryId'], 'usageId' => $order['usageId']];
 				//OrderService::setOrderStyle($setOrderData, true);
 			}
 		} catch (Exception $e) {

+ 5 - 1
sql.txt

@@ -1,4 +1,8 @@
-2019.12.14 shish 订单表的优化 !!!!
+2019.12.14 shish
+DELETE FROM `xhOrderSend`;
+ALTER TABLE `xhOrderSend` MODIFY `orderId` INT NOT NULL DEFAULT 0 COMMENT '订单id';
+
+2019.12.14 shish 订单表的优化 !!!要写php更新 xhOrder xhOrderGoods
 ALTER TABLE `xhOrder` DROP PRIMARY KEY;
 ALTER TABLE `xhOrder` DROP  INDEX `id`;
 ALTER TABLE `xhOrder` CHANGE `id` `orderSn` CHAR(32) NOT NULL DEFAULT '' COMMENT '订单编号';