shish преди 6 години
родител
ревизия
ce68c2715b
променени са 2 файла, в които са добавени 329 реда и са изтрити 326 реда
  1. 167 165
      app/mall/controllers/AuthController.php
  2. 162 161
      biz/order/classes/OrderClass.php

+ 167 - 165
app/mall/controllers/AuthController.php

@@ -21,169 +21,171 @@ use yii\helpers\Json;
  */
 class AuthController extends PublicController
 {
-	
-	//准备授权 shish 2019.11.19
-	public function actionPrepare()
-	{
-		$get = Yii::$app->request->get();
-		$url = isset($get['url']) && !empty($get['url']) ? $get['url'] : '';
-		if (empty($url)) {
-			util::fail('没有网址');
-		}
-		$account = httpUtil::getAccount($url);
-		if (empty($account)) {
-			util::fail('没有商家帐号');
-		}
-		$merchant = MerchantService::getById($account);
-		if (empty($merchant)) {
-			util::fail('商家无效');
-		}
-		/**
-		 * authScope 参数的说明
-		 * 1.用户通过公众号菜单打开网页,因为已经关注过了公众号,已经生成过用户信息,所以只要使用snsapi_base静默方式拿到openid就可以
-		 * 2.为了保证付款页的访问速度,暂时只要通过snsapi_base静默方式拿到openid先生成可以用的用户信息即可
-		 * 3.其它情况需要获取用户完整信息的,使用snsapi_userinfo让用户授权获取信息即可
-		 * 4.snsapi_base静默方式使用的场景更多,所以参数authScope默认使用snsapi_base
-		 */
-		$authScope = isset($get['authScope']) ? $get['authScope'] : 'snsapi_base';
-		$urlEncode = stringUtil::urlSafeB64Encode($url);
-		//微信授权获取code shish 2019.11.24
-		wxUtil::getCode($urlEncode, $merchant, $authScope);
-		util::end();
-	}
-	
-	//微信授权获取用户信息 shish 2019.11.20
-	public function actionGetUserInfo()
-	{
-		$get = Yii::$app->request->get();
-		$code = isset($get['code']) ? $get['code'] : '';
-		if (empty($code)) {
-			util::fail('没有获取用户code');
-		}
-		if (isset($get['state']) && $get['state'] == 'authdeny') {
-			util::fail('auth fail');
-		}
-		$urlEncode = $get['url'];
-		$url = stringUtil::urlSafeBase64Decode($urlEncode);
-		$account = httpUtil::getAccount($url);
-		if (empty($account)) {
-			util::stop('商店ID无效。');
-		}
-		$merchant = xhMerchantService::getByAccount($account);
-		if (empty($merchant)) {
-			util::stop('商店无效');
-		}
-		$merchantId = $merchant['id'];
-		$authScope = isset($get['authScope']) ? $get['authScope'] : '';
-		if (empty($authScope)) {
-			util::stop('没有授权类型');
-		}
-		$data = wxUtil::getOpenId($code, $merchant);
-		if ($data === false) {
-			//微信授权获取code shish 2019.11.24
-			wxUtil::getCode($urlEncode, $merchant, $authScope);
-			util::end();
-		}
-		$openId = $data['openid'];
-		$access_token = $data['access_token'];
-		$user = UserService::getByOpenId($openId, $merchantId);
-		//用户来源
-		$userSource = Yii::$app->dict->getValue('userSourceGetId', 'official');
-		$source = $userSource['name'];
-		if (empty($user)) {
-			//$authScope 默认是 snsapi_base 公众号菜单打开网页(已经关注公众号,有完整信息)、打开付款页(有些客户只付款,没有后续可以不用登记完整信息),只需要获取openid
-			$originalInfo = [];
-			$originalInfo['openId'] = $openId;
-			$originalInfo['merchantId'] = $merchantId;
-			
-			//没有关注公众号,需要获取用户完整信息的情况,则通过弹框授权
-			if ($authScope == 'snsapi_userinfo') {
-				$baseInfo = wxUtil::authGetUserInfo($openId, $access_token);
-				$originalInfo = array_merge($baseInfo, $originalInfo);
-				$originalInfo['isFull'] = 1;
-				$originalInfo['unionId'] = $baseInfo['unionid'];
-				$originalInfo['headImgUrl'] = $baseInfo['headimgurl'];
-				$originalInfo['nickName'] = $baseInfo['nickName'];
-			}
-			$user = UserService::replaceUser($originalInfo, $source, $merchantId);
-		} else {
-			if ($user['isFull'] == 0) {
-				if ($authScope == 'snsapi_userinfo') {
-					$baseInfo = wxUtil::authGetUserInfo($openId, $access_token);
-					$originalInfo = $baseInfo;
-					$originalInfo['isFull'] = 1;
-					$originalInfo['unionId'] = $baseInfo['unionid'];
-					$originalInfo['headImgUrl'] = $baseInfo['headimgurl'];
-					$originalInfo['openId'] = $baseInfo['openid'];
-					$originalInfo['nickName'] = $baseInfo['nickName'];
-					$originalInfo['merchantId'] = $merchantId;
-					$user = UserService::replaceUser($originalInfo, $source, $merchantId);
-				}
-			}
-		}
-		//这个的基类没有设置统一的全局变量,这里进行设置一次
-		$userId = $user['id'];
-		//获取token
-		$token = jwt::getNewToken($userId);
-		$url = strpos($url, '?') === false ? $url . '?token=' . $token : $url . '&token=' . $token;
-		$this->redirect($url);
-	}
-	
-	//静默获取小程序用户信息
-	public function actionMiniInfo()
-	{
-		$code = Yii::$app->request->get('code', '');
-		if (empty($code)) {
-			util::fail('没有CODE信息');
-		}
-		$merchant = $this->merchant;
-		$account = $this->merchantId;
-		$appId = $merchant['miniAppId'];
-		$appSecret = $merchant['miniAppSecret'];
-		if (empty($appSecret)) {
-			util::fail('没有找到小程序的密钥');
-		}
-		$url = "https://api.weixin.qq.com/sns/jscode2session?appid={$appId}&secret={$appSecret}&js_code={$code}&grant_type=authorization_code";
-		
-		$curl = new curl\Curl();
-		$result = $curl->get($url);
-		$arr = Json::decode($result);
-		$sessionKey = isset($arr['session_key']) ? $arr['session_key'] : '';
-		$miniOpenId = isset($arr['openid']) ? $arr['openid'] : '';
-		if (empty($miniOpenId)) {
-			Yii::info(json_encode($arr));
-			util::fail('没有获取到小程序openId');
-		}
-		$unionId = isset($arr['unionid']) && !empty($arr['unionid']) ? $arr['unionid'] : '';
-		//先关注公众号或手动网页授权,小程序这边可以拿到unionId
-		if (!empty($unionId)) {
-			$user = UserService::getByUnionId($unionId);
-			if (empty($user['miniOpenId'])) {
-				$miniUser = UserService::getByMiniOpenId($miniOpenId);
-				if (!empty($miniUser)) {
-					//有独立的小程序信息,将公众号和小程序合并
-					$user = UserService::mergeUser($miniUser, $user);
-				} else {
-					//没有小程序信息可以直接将当前的公众号信息置成小程序信息
-					$userId = $user['id'];
-					UserService::updateById($userId, ['miniOpenId' => $miniOpenId]);
-					$user['miniOpenId'] = $miniOpenId;
-				}
-			}
-		} else {
-			$user = UserService::getByMiniOpenId($miniOpenId);
-		}
-		if (empty($user)) {
-			$userInfo = ['miniOpenId' => $miniOpenId, 'merchantId' => $account, 'unionId' => $unionId];
-			$userSource = UserClass::$userSourceId['mini']['name'];
-			$user = UserService::replaceUser($userInfo, $userSource, $account);
-		}
-		$cacheKey = 'MALL_MINI_SESSION_KEY_' . $miniOpenId;
-		Yii::$app->redis->executeCommand('SET', [$cacheKey, $sessionKey]);
-		$userId = $user['id'];
-		$token = jwt::getNewToken($userId);
-		//update = 1 表示要求启动时更新(如果需要马上应用最新版本,可以使用 wx.getUpdateManager API 进行处理。)
-		util::success(['token' => $token, 'user' => $user, 'update' => 0]);
-	}
-	
+
+    //准备授权 shish 2019.11.19
+    public function actionPrepare()
+    {
+        $get = Yii::$app->request->get();
+        $url = isset($get['url']) && !empty($get['url']) ? $get['url'] : '';
+        if (empty($url)) {
+            util::fail('没有网址');
+        }
+        $account = httpUtil::getAccount($url);
+        if (empty($account)) {
+            util::fail('没有商家帐号');
+        }
+        $merchant = MerchantService::getById($account);
+        if (empty($merchant)) {
+            util::fail('商家无效');
+        }
+        /**
+         * authScope 参数的说明
+         * 1.用户通过公众号菜单打开网页,因为已经关注过了公众号,已经生成过用户信息,所以只要使用snsapi_base静默方式拿到openid就可以
+         * 2.为了保证付款页的访问速度,暂时只要通过snsapi_base静默方式拿到openid先生成可以用的用户信息即可
+         * 3.其它情况需要获取用户完整信息的,使用snsapi_userinfo让用户授权获取信息即可
+         * 4.snsapi_base静默方式使用的场景更多,所以参数authScope默认使用snsapi_base
+         */
+        $authScope = isset($get['authScope']) ? $get['authScope'] : 'snsapi_base';
+        $urlEncode = stringUtil::urlSafeB64Encode($url);
+        //微信授权获取code shish 2019.11.24
+        wxUtil::getCode($urlEncode, $merchant, $authScope);
+        util::end();
+    }
+
+    //微信授权获取用户信息 shish 2019.11.20
+    public function actionGetUserInfo()
+    {
+        $get = Yii::$app->request->get();
+        $code = isset($get['code']) ? $get['code'] : '';
+        if (empty($code)) {
+            util::fail('没有获取用户code');
+        }
+        if (isset($get['state']) && $get['state'] == 'authdeny') {
+            util::fail('auth fail');
+        }
+        $urlEncode = $get['url'];
+        $url = stringUtil::urlSafeBase64Decode($urlEncode);
+        $account = httpUtil::getAccount($url);
+        if (empty($account)) {
+            util::stop('商店ID无效。');
+        }
+        $merchant = xhMerchantService::getByAccount($account);
+        if (empty($merchant)) {
+            util::stop('商店无效');
+        }
+        $merchantId = $merchant['id'];
+        $authScope = isset($get['authScope']) ? $get['authScope'] : '';
+        if (empty($authScope)) {
+            util::stop('没有授权类型');
+        }
+        $data = wxUtil::getOpenId($code, $merchant);
+        if ($data === false) {
+            //微信授权获取code shish 2019.11.24
+            wxUtil::getCode($urlEncode, $merchant, $authScope);
+            util::end();
+        }
+        $openId = $data['openid'];
+        $access_token = $data['access_token'];
+        $user = UserService::getByOpenId($openId, $merchantId);
+        //用户来源
+        $userSource = Yii::$app->dict->getValue('userSourceGetId', 'official');
+        $source = $userSource['name'];
+        if (empty($user)) {
+            //$authScope 默认是 snsapi_base 公众号菜单打开网页(已经关注公众号,有完整信息)、打开付款页(有些客户只付款,没有后续可以不用登记完整信息),只需要获取openid
+            $originalInfo = [];
+            $originalInfo['openId'] = $openId;
+            $originalInfo['merchantId'] = $merchantId;
+
+            //没有关注公众号,需要获取用户完整信息的情况,则通过弹框授权
+            if ($authScope == 'snsapi_userinfo') {
+                $baseInfo = wxUtil::authGetUserInfo($openId, $access_token);
+                $originalInfo = array_merge($baseInfo, $originalInfo);
+                $originalInfo['isFull'] = 1;
+                $originalInfo['unionId'] = $baseInfo['unionid'];
+                $originalInfo['headImgUrl'] = $baseInfo['headimgurl'];
+                $originalInfo['nickName'] = $baseInfo['nickName'];
+            }
+            $user = UserService::replaceUser($originalInfo, $source, $merchantId);
+        } else {
+            if ($user['isFull'] == 0) {
+                if ($authScope == 'snsapi_userinfo') {
+                    $baseInfo = wxUtil::authGetUserInfo($openId, $access_token);
+                    $originalInfo = $baseInfo;
+                    $originalInfo['isFull'] = 1;
+                    $originalInfo['unionId'] = $baseInfo['unionid'];
+                    $originalInfo['headImgUrl'] = $baseInfo['headimgurl'];
+                    $originalInfo['openId'] = $baseInfo['openid'];
+                    $originalInfo['nickName'] = $baseInfo['nickName'];
+                    $originalInfo['merchantId'] = $merchantId;
+                    $user = UserService::replaceUser($originalInfo, $source, $merchantId);
+                }
+            }
+        }
+        //这个的基类没有设置统一的全局变量,这里进行设置一次
+        $userId = $user['id'];
+        //获取token
+        $token = jwt::getNewToken($userId);
+        $url = strpos($url, '?') === false ? $url . '?token=' . $token : $url . '&token=' . $token;
+        $this->redirect($url);
+    }
+
+    //静默获取小程序用户信息
+    public function actionMiniInfo()
+    {
+        $code = Yii::$app->request->get('code', '');
+        if (empty($code)) {
+            util::fail('没有CODE信息');
+        }
+        $merchant = $this->merchant;
+        $account = $this->merchantId;
+        $appId = $merchant['miniAppId'];
+        $appSecret = $merchant['miniAppSecret'];
+        if (empty($appSecret)) {
+            util::fail('没有找到小程序的密钥');
+        }
+        $url = "https://api.weixin.qq.com/sns/jscode2session?appid={$appId}&secret={$appSecret}&js_code={$code}&grant_type=authorization_code";
+
+        $curl = new curl\Curl();
+        $result = $curl->get($url);
+        $arr = Json::decode($result);
+        $sessionKey = isset($arr['session_key']) ? $arr['session_key'] : '';
+        $miniOpenId = isset($arr['openid']) ? $arr['openid'] : '';
+        if (empty($miniOpenId)) {
+            Yii::info(json_encode($arr));
+            util::fail('没有获取到小程序openId');
+        }
+        $unionId = isset($arr['unionid']) && !empty($arr['unionid']) ? $arr['unionid'] : '';
+        //先关注公众号或手动网页授权,小程序这边可以拿到unionId
+        if (!empty($unionId)) {
+            $user = UserService::getByUnionId($unionId);
+            if (!empty($user)) {
+                if (isset($user['miniOpenId']) && empty($user['miniOpenId'])) {
+                    $miniUser = UserService::getByMiniOpenId($miniOpenId);
+                    if (!empty($miniUser)) {
+                        //有独立的小程序信息,将公众号和小程序合并
+                        $user = UserService::mergeUser($miniUser, $user);
+                    } else {
+                        //没有小程序信息可以直接将当前的公众号信息置成小程序信息
+                        $userId = $user['id'];
+                        UserService::updateById($userId, ['miniOpenId' => $miniOpenId]);
+                        $user['miniOpenId'] = $miniOpenId;
+                    }
+                }
+            }
+        } else {
+            $user = UserService::getByMiniOpenId($miniOpenId);
+        }
+        if (empty($user)) {
+            $userInfo = ['miniOpenId' => $miniOpenId, 'merchantId' => $account, 'unionId' => $unionId];
+            $userSource = UserClass::$userSourceId['mini']['name'];
+            $user = UserService::replaceUser($userInfo, $userSource, $account);
+        }
+        $cacheKey = 'MALL_MINI_SESSION_KEY_' . $miniOpenId;
+        Yii::$app->redis->executeCommand('SET', [$cacheKey, $sessionKey]);
+        $userId = $user['id'];
+        $token = jwt::getNewToken($userId);
+        //update = 1 表示要求启动时更新(如果需要马上应用最新版本,可以使用 wx.getUpdateManager API 进行处理。)
+        util::success(['token' => $token, 'user' => $user, 'update' => 0]);
+    }
+
 }

+ 162 - 161
biz/order/classes/OrderClass.php

@@ -7,6 +7,7 @@ use biz\message\classes\InformAdminClass;
 use biz\message\classes\InformUserClass;
 use biz\stat\classes\StatOrderCountClass;
 use biz\user\classes\UserClass;
+use common\components\miniUtil;
 use common\components\stringUtil;
 use common\services\xhOrderDayNumService;
 use common\services\xhOrderMonthNumService;
@@ -15,166 +16,166 @@ use biz\base\classes\BaseClass;
 
 class OrderClass extends BaseClass
 {
-	
-	public static $baseFile = '\biz\order\models\Order';
-	
-	//已退款
-	const ORDER_STATUS_REFUND = 6;
-	//完成
-	const ORDER_STATUS_COMPLETE = 5;
-	//已取消
-	const ORDER_STATUS_CANCEL = 4;
-	//待通知
-	const ORDER_STATUS_UN_NOTICE = 3;
-	//配送中
-	const ORDER_STATUS_SENDING = 2;
-	//待配送
-	const ORDER_STATUS_UN_SEND = 1;
-	//待付款
-	const ORDER_STATUS_UN_PAY = 0;
-	//订单总流程数
-	const ORDER_TOTAL_FLOW = 5;
-	
-	//未确认配送方式
-	const SEND_TYPE_UNKNOWN = 0;
-	//自取
-	const SEND_TYPE_NO = 1;
-	//自己送
-	const SEND_TYPE_MYSELF = 2;
-	//代送
-	const SEND_TYPE_OTHER = 3;
-	
-	//送达时间段
-	public static $reachPeriod = [0 => '上午', 1 => '下午', 2 => '晚上'];
-	
-	//添加订单 shish 2019.12.5
-	public static function addOrder($data)
-	{
-		$date = date("Y-m-d H:i:s");
-		$merchantId = $data['merchantId'];
-		$data['orderSn'] = stringUtil::generateOrderNo($merchantId, $data['userId']);
-		$data['payStatus'] = 0;
-		$data['createTime'] = $date;
-		$data['addTime'] = time();
-		
-		$month = date("Ym");
-		$riseNum = StatOrderCountClass::addOrder($month, $merchantId);
-		//将花店每月的总订单数作为编号
-		$data['sendNum'] = $riseNum;
-		$data['totalFlow'] = OrderSendClass::TOTAL_FLOW;
-		$return = self::add($data);
-		return $return;
-	}
-	
-	public static function getByOrderSn($orderSn)
-	{
-		return self::getByCondition(['orderSn' => $orderSn]);
-	}
-	
-	//评价 shish 2019.12.16
-	public static function comment($data)
-	{
-		$id = $data['id'];
-		unset($data['id']);
-		return self::updateById($id, $data);
-	}
-	
-	//订单
-	public static function getOrderById($id)
-	{
-		$order = self::getById($id);
-		if (empty($order)) {
-			return [];
-		}
-		$order['goodsInfoList'] = OrderGoodsClass::getGoodsListById($id);
-		return $order;
-	}
-	
-	//根据订单查询 shish 2020.1.4
-	public static function getOrderBySn($orderSn)
-	{
-		$order = self::getByCondition(['orderSn' => $orderSn]);
-		if (empty($order)) {
-			return [];
-		}
-		$id = $order['id'];
-		$order['goodsInfoList'] = OrderGoodsClass::getGoodsListById($id);
-		return $order;
-	}
-	
-	//返回随机优惠金额 shish 2019.9.12
-	public static function getRandDiscount($amount)
-	{
-		if ($amount <= 0) {
-			return 0;
-		}
-		if ($amount >= 20000) {
-			$rand = rand(90, 100);
-		} elseif ($amount > 1000) {
-			$rand = rand(10, 30);
-		} elseif ($amount > 500) {
-			$rand = rand(10, 20);
-		} elseif ($amount > 260) {
-			$rand = rand(10, 15);
-		} elseif ($amount > 100) {
-			$rand = rand(5, 9);
-		} elseif ($amount > 50) {
-			$rand = rand(1, 3);
-		} elseif ($amount > 10) {
-			$rand = 1;
-		} else {
-			$rand = 0;
-		}
-		return $rand / 10;
-	}
-	
-	//订单完成 shish 2020.3.12
-	public static function complete($order)
-	{
-		$id = $order['id'];
-		self::updateById($id, ['status' => OrderClass::ORDER_STATUS_COMPLETE, 'currentFlow' => 4]);
-		$userId = $order['userId'];
-		$user = UserClass::getById($userId);
-		$merchantId = $order['merchantId'];
-		$merchant = MerchantClass::getById($merchantId);
-		//完成通知客户
-		InformUserClass::sendComplete($user, $order, $merchant);
-		//完成通知管理员
-		InformAdminClass::sendComplete($order, $merchant);
-	}
-	
-	//转化出送到时间 shish 2020.3.15
-	public static function getReachTime($order)
-	{
-		$reachTime = '';
-		if (isset($order['reachDate']) && !empty($order['reachDate'])) {
-			$prev = date("n-j", strtotime($order['reachDate']));
-			$periodData = self::$reachPeriod;
-			$periodKey = $order['reachPeriod'];
-			$period = isset($periodData[$periodKey]) ? $periodData[$periodKey] : '上午';
-			$reachTime = $prev . ' ' . $period;
-		}
-		return $reachTime;
-	}
-	
-	//支付成功获取unionId shish 2020.5.12
-	public static function payToUpdateUnionId($merchant, $merchantExtend, $orderSn, $user)
-	{
-		$mcId = $merchantExtend['wxPayMerchantId'];
-		$miniOpenId = isset($user['miniOpenId']) ? $user['miniOpenId'] : '';
-		$unionId = isset($user['unionId']) ? $user['unionId'] : '';
-		$userId = $user['id'];
-		if (empty($unionId)) {
-			$unionId = miniUtil::getPaidUnionId($merchant, $miniOpenId, $mcId, (string)$orderSn, 0);
-			if (!empty($unionId)) {
-				$findUser = UserClass::getByUnionId($unionId);
-				if (empty($findUser)) {
-					UserClass::updateByCondition(['userId' => $userId], ['unionId' => $unionId]);
-				} else {
-					UserClass::mergeUser($findUser, $user);
-				}
-			}
-		}
-	}
+
+    public static $baseFile = '\biz\order\models\Order';
+
+    //已退款
+    const ORDER_STATUS_REFUND = 6;
+    //完成
+    const ORDER_STATUS_COMPLETE = 5;
+    //已取消
+    const ORDER_STATUS_CANCEL = 4;
+    //待通知
+    const ORDER_STATUS_UN_NOTICE = 3;
+    //配送中
+    const ORDER_STATUS_SENDING = 2;
+    //待配送
+    const ORDER_STATUS_UN_SEND = 1;
+    //待付款
+    const ORDER_STATUS_UN_PAY = 0;
+    //订单总流程数
+    const ORDER_TOTAL_FLOW = 5;
+
+    //未确认配送方式
+    const SEND_TYPE_UNKNOWN = 0;
+    //自取
+    const SEND_TYPE_NO = 1;
+    //自己送
+    const SEND_TYPE_MYSELF = 2;
+    //代送
+    const SEND_TYPE_OTHER = 3;
+
+    //送达时间段
+    public static $reachPeriod = [0 => '上午', 1 => '下午', 2 => '晚上'];
+
+    //添加订单 shish 2019.12.5
+    public static function addOrder($data)
+    {
+        $date = date("Y-m-d H:i:s");
+        $merchantId = $data['merchantId'];
+        $data['orderSn'] = stringUtil::generateOrderNo($merchantId, $data['userId']);
+        $data['payStatus'] = 0;
+        $data['createTime'] = $date;
+        $data['addTime'] = time();
+
+        $month = date("Ym");
+        $riseNum = StatOrderCountClass::addOrder($month, $merchantId);
+        //将花店每月的总订单数作为编号
+        $data['sendNum'] = $riseNum;
+        $data['totalFlow'] = OrderSendClass::TOTAL_FLOW;
+        $return = self::add($data);
+        return $return;
+    }
+
+    public static function getByOrderSn($orderSn)
+    {
+        return self::getByCondition(['orderSn' => $orderSn]);
+    }
+
+    //评价 shish 2019.12.16
+    public static function comment($data)
+    {
+        $id = $data['id'];
+        unset($data['id']);
+        return self::updateById($id, $data);
+    }
+
+    //订单
+    public static function getOrderById($id)
+    {
+        $order = self::getById($id);
+        if (empty($order)) {
+            return [];
+        }
+        $order['goodsInfoList'] = OrderGoodsClass::getGoodsListById($id);
+        return $order;
+    }
+
+    //根据订单查询 shish 2020.1.4
+    public static function getOrderBySn($orderSn)
+    {
+        $order = self::getByCondition(['orderSn' => $orderSn]);
+        if (empty($order)) {
+            return [];
+        }
+        $id = $order['id'];
+        $order['goodsInfoList'] = OrderGoodsClass::getGoodsListById($id);
+        return $order;
+    }
+
+    //返回随机优惠金额 shish 2019.9.12
+    public static function getRandDiscount($amount)
+    {
+        if ($amount <= 0) {
+            return 0;
+        }
+        if ($amount >= 20000) {
+            $rand = rand(90, 100);
+        } elseif ($amount > 1000) {
+            $rand = rand(10, 30);
+        } elseif ($amount > 500) {
+            $rand = rand(10, 20);
+        } elseif ($amount > 260) {
+            $rand = rand(10, 15);
+        } elseif ($amount > 100) {
+            $rand = rand(5, 9);
+        } elseif ($amount > 50) {
+            $rand = rand(1, 3);
+        } elseif ($amount > 10) {
+            $rand = 1;
+        } else {
+            $rand = 0;
+        }
+        return $rand / 10;
+    }
+
+    //订单完成 shish 2020.3.12
+    public static function complete($order)
+    {
+        $id = $order['id'];
+        self::updateById($id, ['status' => OrderClass::ORDER_STATUS_COMPLETE, 'currentFlow' => 4]);
+        $userId = $order['userId'];
+        $user = UserClass::getById($userId);
+        $merchantId = $order['merchantId'];
+        $merchant = MerchantClass::getById($merchantId);
+        //完成通知客户
+        InformUserClass::sendComplete($user, $order, $merchant);
+        //完成通知管理员
+        InformAdminClass::sendComplete($order, $merchant);
+    }
+
+    //转化出送到时间 shish 2020.3.15
+    public static function getReachTime($order)
+    {
+        $reachTime = '';
+        if (isset($order['reachDate']) && !empty($order['reachDate'])) {
+            $prev = date("n-j", strtotime($order['reachDate']));
+            $periodData = self::$reachPeriod;
+            $periodKey = $order['reachPeriod'];
+            $period = isset($periodData[$periodKey]) ? $periodData[$periodKey] : '上午';
+            $reachTime = $prev . ' ' . $period;
+        }
+        return $reachTime;
+    }
+
+    //支付成功获取unionId shish 2020.5.12
+    public static function payToUpdateUnionId($merchant, $merchantExtend, $orderSn, $user)
+    {
+        $mcId = $merchantExtend['wxPayMerchantId'];
+        $miniOpenId = isset($user['miniOpenId']) ? $user['miniOpenId'] : '';
+        $unionId = isset($user['unionId']) ? $user['unionId'] : '';
+        $userId = $user['id'];
+        if (empty($unionId)) {
+            $unionId = miniUtil::getPaidUnionId($merchant, $miniOpenId, $mcId, (string)$orderSn, 0);
+            if (!empty($unionId)) {
+                $findUser = UserClass::getByUnionId($unionId);
+                if (empty($findUser)) {
+                    UserClass::updateByCondition(['userId' => $userId], ['unionId' => $unionId]);
+                } else {
+                    UserClass::mergeUser($findUser, $user);
+                }
+            }
+        }
+    }
 
 }