Răsfoiți Sursa

可以创建订单

shish 6 ani în urmă
părinte
comite
d99feabd85

+ 54 - 54
app/client/controllers/OrderController.php

@@ -7,6 +7,7 @@ use biz\goods\services\GoodsCategoryService;
 use biz\goods\services\GoodsService;
 use biz\merchant\services\MerchantService;
 use biz\merchant\services\ShopService;
+use biz\order\services\OrderGoodsService;
 use biz\order\services\OrderService;
 use biz\promote\services\CouponService;
 use biz\user\services\UserAssetService;
@@ -18,18 +19,17 @@ use common\components\util;
 
 class OrderController extends BaseController
 {
-	
-	
+
 	//商城下单操作 shish 2019.12.3
 	public function actionCreateOrder()
 	{
-		
+
 		//给出省市区的接口 todo
 		//给出商家门店地址接口 todo
 		//给出腾讯的接口 todo
 		//运费 计算方式 todo
 		//余额支付 要使用哪个接口 todo
-		
+
 		$post = Yii::$app->request->post();
 		$goodsId = isset($post['goodsId']) ? $post['goodsId'] : 0;
 		$goodsStyleId = isset($post['goodsStyleId']) ? $post['goodsStyleId'] : 0;
@@ -101,9 +101,9 @@ class OrderController extends BaseController
 		}
 		$post['prePrice'] = $prePrice;
 		$post['actPrice'] = $actPrice;
-		$order = OrderService::add($post);
+		$order = OrderService::addOrder($post);
 		$orderId = $order['id'];
-		
+
 		$data = [
 			'orderId' => $orderId,
 			'goodsId' => $goodsId,
@@ -117,7 +117,7 @@ class OrderController extends BaseController
 			'goodsStyleId' => $goodsStyleId,
 			'createTime' => date("Y-m-d H:i:s"),
 		];
-		xhOrderGoodsService::add($data);//创建订单商品列表
+		OrderGoodsService::add($data);//创建订单商品列表
 		
 		util::success(['orderId' => $orderId, 'totalPrice' => $showPrice, 'couponId' => $couponId]);
 	}
@@ -134,7 +134,7 @@ class OrderController extends BaseController
 			util::fail('还没开通支付功能哟');
 		}
 		$orderId = isset($post['orderId']) ? $post['orderId'] : 0;
-		$order = xhOrderService::getById($orderId);
+		$order = OrderService::getById($orderId);
 		if (!empty($couponId)) {
 			$coupon = xhCouponService::getById($couponId);
 			if ($coupon['useStatus'] == 1 || $now > $coupon['deadline']) {
@@ -195,51 +195,6 @@ class OrderController extends BaseController
 		util::success($newParams);
 	}
 	
-	/**
-	 * 订单 - 支付宝支付
-	 */
-	public function actionZfbPay()
-	{
-		header("Content-type: text/html; charset=utf-8");
-		$alipayWap = Yii::getAlias("@vendor/alipayWap");
-		require_once($alipayWap . '/wappay/service/AlipayTradeService.php');
-		require_once($alipayWap . '/wappay/buildermodel/AlipayTradeWapPayContentBuilder.php');
-		require_once($alipayWap . '/config.php');
-		
-		$get = Yii::$app->request->get();
-		$orderId = isset($get['orderId']) ? $get['orderId'] : 0;
-		$couponId = isset($get['couponId']) ? $get['couponId'] : 0;
-		$orderData = xhOrderService::getById($orderId);
-		$waitForPay = configDict::getConfig('payStatus', 'waitForPay');
-		if ($orderData['payStatus'] != $waitForPay) {
-			echo '已经支付成功';
-			util::end();
-		}
-		$merchantId = $orderData['merchantId'];
-		$out_trade_no = $orderId;//商户订单号,商户网站订单系统中唯一订单号,必填
-		$subject = $orderData['orderName'];//订单名称,必填
-		$total_amount = $orderData['actPrice'];;//付款金额,必填
-		$body = '';//商品描述,可空
-		$timeout_express = "1m";//超时时间
-		
-		$typeList = configDict::getConfig('capitalType');
-		$capitalType = $typeList['xhOrder']['id'];
-		$passbackParams = 'capitalType=' . $capitalType . '&couponId=' . $couponId . '&merchantId=' . $merchantId;//将流水类型、代金劵传过去
-		$passbackParams = urlencode($passbackParams);
-		
-		$payRequestBuilder = new \AlipayTradeWapPayContentBuilder();
-		$payRequestBuilder->setBody($body);
-		$payRequestBuilder->setSubject($subject);
-		$payRequestBuilder->setOutTradeNo($out_trade_no);
-		$payRequestBuilder->setTotalAmount($total_amount);
-		$payRequestBuilder->setTimeExpress($timeout_express);
-		$payRequestBuilder->setPassbackParams($passbackParams);//在异步通知时将该参数原样返回
-		$returnUrl = Yii::$app->params['frontUrl'] . "/notice/order-alipay-sync";
-		$payResponse = new \AlipayTradeService($config);
-		$result = $payResponse->wapPay($payRequestBuilder, $returnUrl, $config['notify_url']);
-		util::success($result);
-	}
-	
 	//快速付款订单
 	public function actionFastCreateOrder()
 	{
@@ -464,5 +419,50 @@ class OrderController extends BaseController
 		$result = $payResponse->wapPay($payRequestBuilder, $returnUrl, $notifyUrl);
 		util::success($result);
 	}
-	
+
+	/**
+	 * 订单 - 支付宝支付
+	 */
+	public function actionZfbPay()
+	{
+		header("Content-type: text/html; charset=utf-8");
+		$alipayWap = Yii::getAlias("@vendor/alipayWap");
+		require_once($alipayWap . '/wappay/service/AlipayTradeService.php');
+		require_once($alipayWap . '/wappay/buildermodel/AlipayTradeWapPayContentBuilder.php');
+		require_once($alipayWap . '/config.php');
+		
+		$get = Yii::$app->request->get();
+		$orderId = isset($get['orderId']) ? $get['orderId'] : 0;
+		$couponId = isset($get['couponId']) ? $get['couponId'] : 0;
+		$orderData = xhOrderService::getById($orderId);
+		$waitForPay = configDict::getConfig('payStatus', 'waitForPay');
+		if ($orderData['payStatus'] != $waitForPay) {
+			echo '已经支付成功';
+			util::end();
+		}
+		$merchantId = $orderData['merchantId'];
+		$out_trade_no = $orderId;//商户订单号,商户网站订单系统中唯一订单号,必填
+		$subject = $orderData['orderName'];//订单名称,必填
+		$total_amount = $orderData['actPrice'];;//付款金额,必填
+		$body = '';//商品描述,可空
+		$timeout_express = "1m";//超时时间
+		
+		$typeList = configDict::getConfig('capitalType');
+		$capitalType = $typeList['xhOrder']['id'];
+		$passbackParams = 'capitalType=' . $capitalType . '&couponId=' . $couponId . '&merchantId=' . $merchantId;//将流水类型、代金劵传过去
+		$passbackParams = urlencode($passbackParams);
+		
+		$payRequestBuilder = new \AlipayTradeWapPayContentBuilder();
+		$payRequestBuilder->setBody($body);
+		$payRequestBuilder->setSubject($subject);
+		$payRequestBuilder->setOutTradeNo($out_trade_no);
+		$payRequestBuilder->setTotalAmount($total_amount);
+		$payRequestBuilder->setTimeExpress($timeout_express);
+		$payRequestBuilder->setPassbackParams($passbackParams);//在异步通知时将该参数原样返回
+		$returnUrl = Yii::$app->params['frontUrl'] . "/notice/order-alipay-sync";
+		$payResponse = new \AlipayTradeService($config);
+		$result = $payResponse->wapPay($payRequestBuilder, $returnUrl, $config['notify_url']);
+		util::success($result);
+	}
+
 }

+ 25 - 0
biz/order/classes/OrderClass.php

@@ -2,6 +2,9 @@
 
 namespace biz\order\classes;
 
+use common\components\stringUtil;
+use common\services\xhOrderDayNumService;
+use common\services\xhOrderMonthNumService;
 use Yii;
 use biz\base\classes\BaseClass;
 
@@ -10,4 +13,26 @@ class OrderClass extends BaseClass
 	
 	public static $baseFile = '\biz\order\models\Order';
 	
+	//添加订单 shish 2019.12.5
+	public static function addOrder($data)
+	{
+		$date = date("Y-m-d H:i:s");
+		$merchantId = $data['merchantId'];
+		$data['id'] = stringUtil::generateOrderNo($merchantId, $data['userId']);
+		$data['payStatus'] = 0;
+		$data['createTime'] = $date;
+		$data['addTime'] = time();
+		
+		$time = strtotime(date("Y-m-d"));
+		$year = date("Y");
+		$month = date("m");
+		//后面要把下面二个service方法移到class层
+		xhOrderDayNumService::addOne($time, $merchantId);
+		$monthReturn = xhOrderMonthNumService::addOne($year, $month, $merchantId);
+		//将花店每月的总订单数作为编号
+		$data['sendNum'] = (string)$monthReturn['riseNum'];
+		$return = self::add($data);
+		return $return;
+	}
+	
 }

+ 9 - 2
biz/order/services/OrderService.php

@@ -4,6 +4,7 @@ namespace biz\order\services;
 
 use biz\base\services\BaseService;
 use biz\merchant\services\MerchantCapitalService;
+use biz\order\classes\OrderClass;
 use biz\order\models\Order;
 use biz\promote\services\CouponRightService;
 use biz\user\services\UserService;
@@ -18,6 +19,12 @@ class OrderService extends BaseService
 	
 	public static $baseFile = '\biz\order\classes\OrderClass';
 	
+	//添加订单
+	public static function addOrder($data)
+	{
+		return OrderClass::addOrder($data);
+	}
+
 	//获取订单信息 shish 2019.11.28
 	public static function getOrderList($where)
 	{
@@ -45,12 +52,12 @@ class OrderService extends BaseService
 		}
 		return $data;
 	}
-
+	
 	//取客户最近若干条订单 shish 2019.11.30
 	public static function getUserOrder($userId, $limit = 10, $order = null, $with = null)
 	{
 		$where = ['userId' => $userId];
 		return self::getLimitList('*', $where, $limit, $order, $with);
 	}
-
+	
 }

+ 0 - 53
common/services/xhOrderDayNumService.php

@@ -27,70 +27,17 @@ class xhOrderDayNumService {
 	public static function updateByIds($time,$merchantId,$data)
 	{
 		xhOrderDayNum::updateByCondition(['time'=>$time,'merchantId'=>$merchantId], $data);
-		self::getByIds($time, $merchantId);
-		$cacheKey		= configDict::getCacheKey('xhOrderDayNum').'_'.$time.'_'.$merchantId;
-		$params			= [$cacheKey];
-		if(!empty($data)){
-			foreach($data as $key => $val){
-				$params[] = $key;
-				$params[] = $val;
-			}
-		}
-		Yii::$app->redis->executeCommand('HMSET',$params);
 	}
 
 	public static function add($data)
 	{
 		$return			= xhOrderDayNum::add($data);
-		$merchantId		= $return['merchantId'];
-		$time			= $return['time'];
-		$cacheKey		= configDict::getCacheKey('xhOrderDayNum').'_'.$time.'_'.$merchantId;
-		$params			= [$cacheKey];
-		if(!empty($return)){
-			foreach($return as $key => $val){
-				$params[] = $key;
-				$params[] = $val;
-			}
-		}
-		Yii::$app->redis->executeCommand('HMSET',$params);
 		return $return;
 	}
 
 	public static function getByIds($time,$merchantId)
 	{
-		$cacheKey		= configDict::getCacheKey('xhOrderDayNum').'_'.$time.'_'.$merchantId;
-		$order			= Yii::$app->redis->executeCommand('HGETALL', [$cacheKey]);
-		if(!empty($order)){
-			$arr		= [];
-			$i			= 0;
-			$x			= 0;
-			foreach($order as $key => $val){
-				$i++;
-				if($i%2 == 0){
-					$arr[$x]['value'] = $val;
-					$x++;
-				}else{
-					$arr[$x]['key'] = $val;
-				}
-			}
-			$orderArr	= [];
-			foreach($arr as $key => $val){
-				$orderArr[$val['key']] = $val['value'];
-			}
-			unset($orderArr['info_already_get_by_sql']);
-			return $orderArr;
-		}
 		$order			= xhOrderDayNum::find()->where(['time'=>$time,'merchantId'=>$merchantId])->asArray()->one();
-		$params			= [$cacheKey];
-		$params[]		= 'info_already_get_by_sql';
-		$params[]		= 'ok';//redis没有办法设置带空值的键,加此可以数据空时表示取过
-		if(!empty($order)){
-			foreach($order as $key => $val){
-				$params[] = $key;
-				$params[] = $val;
-			}
-		}
-		Yii::$app->redis->executeCommand('HMSET',$params);
 		return $order;
 	}
 

+ 0 - 54
common/services/xhOrderMonthNumService.php

@@ -27,71 +27,17 @@ class xhOrderMonthNumService {
 	public static function updateByIds($year,$month,$merchantId,$data)
 	{
 		xhOrderMonthNum::updateByCondition(['year'=>$year,'month'=>$month,'merchantId'=>$merchantId], $data);
-		self::getByIds($year,$month,$merchantId);
-		$cacheKey		= configDict::getCacheKey('xhOrderMonthNum').'_'.$year.'_'.$month.'_'.$merchantId;
-		$params			= [$cacheKey];
-		if(!empty($data)){
-			foreach($data as $key => $val){
-				$params[] = $key;
-				$params[] = $val;
-			}
-		}
-		Yii::$app->redis->executeCommand('HMSET',$params);
 	}
 	
 	public static function add($data)
 	{
 		$return			= xhOrderMonthNum::add($data);
-		$merchantId		= $return['merchantId'];
-		$year			= $return['year'];
-		$month			= $return['month'];
-		$cacheKey		= configDict::getCacheKey('xhOrderMonthNum').'_'.$year.'_'.$month.'_'.$merchantId;
-		$params			= [$cacheKey];
-		if(!empty($return)){
-			foreach($return as $key => $val){
-				$params[] = $key;
-				$params[] = $val;
-			}
-		}
-		Yii::$app->redis->executeCommand('HMSET',$params);
 		return $return;
 	}
 	
 	public static function getByIds($year,$month,$merchantId)
 	{
-		$cacheKey		= configDict::getCacheKey('xhOrderMonthNum').'_'.$year.'_'.$month.'_'.$merchantId;
-		$order			= Yii::$app->redis->executeCommand('HGETALL', [$cacheKey]);
-		if(!empty($order)){
-			$arr		= [];
-			$i			= 0;
-			$x			= 0;
-			foreach($order as $key => $val){
-				$i++;
-				if($i%2 == 0){
-					$arr[$x]['value'] = $val;
-					$x++;
-				}else{
-					$arr[$x]['key'] = $val;
-				}
-			}
-			$orderArr	= [];
-			foreach($arr as $key => $val){
-				$orderArr[$val['key']] = $val['value'];
-			}
-			unset($orderArr['info_already_get_by_sql']);
-			return $orderArr;
-		}
 		$order			= xhOrderMonthNum::find()->where(['year'=>$year,'month'=>$month,'merchantId'=>$merchantId])->asArray()->one();
-		$params			= [$cacheKey];
-		$params[]		= 'info_already_get_by_sql';
-		$params[]		= 'ok';//redis没有办法设置带空值的键,加此可以数据空时表示取过
-		if(!empty($order)){
-			foreach($order as $key => $val){
-				$params[] = $key;
-				$params[] = $val;
-			}
-		}
-		Yii::$app->redis->executeCommand('HMSET',$params);
 		return $order;
 	}