Просмотр исходного кода

Merge branch 'master' of http://git.huaml.com/zhh/huahuibao

# Conflicts:
#	biz-ghs/product/classes/ProductClass.php
林琦海 5 лет назад
Родитель
Сommit
8d79036a72

+ 654 - 602
app/shop/controllers/OrderController.php

@@ -6,623 +6,675 @@ use biz\merchant\services\MerchantAssetService;
 use biz\merchant\services\MerchantExtendService;
 use biz\merchant\services\MerchantService;
 use biz\merchant\services\ShopService;
+use biz\order\classes\OrderClass;
 use biz\order\classes\OrderSendClass;
 use biz\order\services\OrderService;
 use biz\saas\services\RegionService;
 use biz\user\services\UserService;
+use bizGhs\order\classes\OrderItemClass;
 use common\components\configDict;
 use common\services\xhPayToolService;
 use Yii;
 use common\components\util;
 use common\components\stringUtil;
-use biz\goods\services\CategoryService;
-use biz\goods\services\GoodsCategoryService;
 use biz\goods\services\GoodsService;
 use biz\merchant\services\ExpressService;
 use biz\order\services\OrderGoodsService;
 use biz\promote\services\CouponService;
-use biz\user\services\UserAssetService;
 use common\components\httpUtil;
-use common\components\miniUtil;
-use yii\web\Controller;
+
 
 class OrderController extends BaseController
 {
-
-    public $guestAccessAction = ['order-relate', 'fast-pay', 'create-order', 'list'];
-
-    //商城下单操作 shish 2019.12.3
-    public function actionCreateOrder()
-    {
-        $post = Yii::$app->request->post();
-        $goodsId = isset($post['goodsId']) ? $post['goodsId'] : 0;
-        $goodsStyleId = isset($post['goodsStyleId']) ? $post['goodsStyleId'] : 0;
-        $goodsNum = isset($post['goodsNum']) && $post['goodsNum'] > 0 ? $post['goodsNum'] : 1;
-        $needSend = isset($post['needSend']) && is_numeric($post['needSend']) ? $post['needSend'] : 1;
-        if (empty($goodsId)) {
-            util::fail('请选择商品');
-        }
-        $goodsInfo = GoodsService::getGoodsInfo($goodsId);
-        if (empty($goodsInfo)) {
-            util::fail('没有找到商品');
-        }
-        if (isset($goodsInfo['stock']) == false || $goodsInfo['stock'] == 0) {
-            util::fail('已经卖完了');
-        }
-        //运费计算方式
-        $freightType = isset($goodsInfo['freightType']) ? $goodsInfo['freightType'] : 0;
-        $customId = $post['customId'] ?? 0;
-        if (!empty($customId)) {
-            $customId = $this->customId;
-        }
-        $post['customId'] = $customId;
-        $user = $this->custom;
-        $post['bookName'] = isset($user['name']) ? $user['name'] : '';
-        $bookMobile = isset($post['bookMobile']) && !empty($post['bookMobile']) && stringUtil::isMobile($post['bookMobile']) ? $post['bookMobile'] : '';
-        $bookMobile = empty($bookMobile) && isset($user['mobile']) && !empty($user['mobile']) ? $user['mobile'] : $bookMobile;
-        $post['bookMobile'] = $bookMobile;
-        $post['payWay'] = $this->isWx == true ? 0 : 1;
-        $defaultShopId = MerchantService::getDefaultShopId($this->sj);
-        if (empty($defaultShopId)) {
-            util::fail('没有找到门店');
-        }
-        //计算运费
-        $post['sendDistance'] = isset($post['sendDistance']) ? $post['sendDistance'] : 0;
-        $sendCost = 0;
-        //按距离计算运费并且客户要求送的
-        if ($freightType == 0 && $needSend == 1) {
-            $lat = $post['latitude'];//收货人纬度
-            $lng = $post['longitude'];//收货人经度
-            $respond = ExpressService::getUserDistance($lng, $lat, $defaultShopId, $this->sjExtend);
-            $sendCost = isset($respond['fee']) ? $respond['fee'] : 0;
-        }
-        $post['sendCost'] = $sendCost;
-        $post['merchantId'] = $this->sjId;
-        $post['shopId'] = $defaultShopId;
-
-        //计算总金额
-        $unitPrice = $goodsInfo['price'];
-        $goodsStyleList = isset($goodsInfo['goodsStyleList']) ? $goodsInfo['goodsStyleList'] : [];
-        if (!empty($goodsStyleId)) {
-            if (empty($goodsStyleList)) {
-                util::fail('商品款式没有找到');
-            }
-            $styleIdList = array_keys($goodsStyleList);
-            if (in_array($goodsStyleId, $styleIdList) == false) {
-                util::fail('商品款式没有找到!');
-            }
-            $unitPrice = isset($goodsStyleList[$goodsStyleId]['price']) ? $goodsStyleList[$goodsStyleId]['price'] : 9999;
-        }
-        $goodsPrice = $unitPrice * $goodsNum;
-        $prePrice = stringUtil::calcAdd($sendCost, $goodsPrice);
-        //非门店订单
-        $store = 0;
-        $post['store'] = $store;
-        //来源 0微信 1支付宝 2小程序 3朋友圈 4美团
-        $sourceType = $this->isWx ? 0 : 1;
-        if (httpUtil::isMiniProgram()) {
-            $sourceType = 2;
-        }
-        $couponId = isset($post['couponId']) && !empty($post['couponId']) ? $post['couponId'] : 0;
-        $discountData = OrderService::getDiscountPrice(['price' => $prePrice, 'sourceType' => $sourceType, 'couponId' => $couponId, 'userId' => $this->adminId]);
-        $actPrice = $discountData['price'];
-        $post['discountType'] = $discountData['discountType'];
-        $post['discountAmount'] = $discountData['discountAmount'];
-
-        $now = time();
-        $expireTime = $now + 1800;//订单30分钟后过期
-        $post['deadline'] = $expireTime;
-        $post['fromType'] = 1;//商城
-        $post['prePrice'] = $prePrice;
-        $post['actPrice'] = $actPrice;
-        $order = OrderService::addOrder($post);
-        $orderId = $order['id'];
-        $orderSn = $order['orderSn'];
-        $data = [
-            'orderId' => $orderId,
-            'goodsId' => $goodsId,
-            'userId' => $this->adminId,
-            'merchantId' => $this->sjId,
-            'title' => $goodsInfo['goodsName'],
-            'cover' => isset($goodsInfo['shortImgList']) && !empty($goodsInfo['shortImgList']) ? current($goodsInfo['shortImgList']) : '',
-            'unitPrice' => $unitPrice,
-            'num' => $goodsNum,
-            'goodsStyleName' => isset($goodsInfo['goodsStyleList'][$goodsStyleId]['title']) ? $goodsInfo['goodsStyleList'][$goodsStyleId]['title'] : '',
-            'goodsStyleId' => $goodsStyleId,
-            'createTime' => date("Y-m-d H:i:s"),
-        ];
-        OrderGoodsService::add($data);//创建订单商品列表
-        util::success(['orderSn' => $orderSn, 'totalPrice' => $actPrice, 'couponId' => $couponId]);
-    }
-
-    //下单要用到的相关信息 shish 2019.12.6
-    public function actionOrderRelate()
-    {
-        $regionTree = RegionService::tree();
-        $shop = ShopService::getDefaultShop($this->sj);
-        $freight = MerchantExtendService::getFreight($this->sjExtend);
-        $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
-        $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'txMapKey' => $mapKey, 'merchant' => $this->sj];
-        util::success($out);
-    }
-
-    //余额支付 shish 2019.12.6
-    public function actionBalancePay()
-    {
-        $post = Yii::$app->request->post();
-        $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
-        $payPassword = isset($post['payPassword']) ? $post['payPassword'] : 0;
-        $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
-
-        //验证优惠券是否还有效
-        if (!empty($couponId)) {
-            CouponService::checkBeforeUse($couponId, $order['prePrice'], $order['userId']);
-        }
-
-        $order = OrderService::getByOrderSn($orderSn);
-        $userId = $this->adminId;
-        $user = UserService::getUserInfo($userId, false);
-        //验证支付密码是否正确
-        UserService::validPayPassword($payPassword, $user);
-        //支付前验证订单有效性
-        OrderService::checkBeforePay($order, $this->adminId);
-        $typeList = configDict::getConfig('capitalType');
-        $capitalType = $typeList['xhOrder']['id'];
-        $totalFee = $order['prePrice'];
-        $sourceType = 0;
-        $discountData = OrderService::getDiscountPrice(['price' => $totalFee, 'sourceType' => $sourceType, 'couponId' => $couponId, 'userId' => $this->adminId]);
-        $actPrice = $discountData['price'];
-        $callbackParams = [];
-        $respond = xhPayToolService::balancePay($callbackParams, $orderSn, $actPrice, $capitalType, $couponId);
-        $balance = isset($respond['balance']) ? $respond['balance'] : 0;
-        util::success(['discountAmount' => $discountData['discountAmount'], 'discountType' => $discountData['discountType'], 'balance' => $balance]);
-    }
-
-    //获取商城下单要用的微信支付和小程序支付参数 shish 2019.21.3
-    public function actionWxPay()
-    {
-        ini_set('date.timezone', 'Asia/Shanghai');
-        $post = Yii::$app->request->post();
-        $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
-        $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
-        $order = OrderService::getByOrderSn($orderSn);
-        $orderId = $order['id'];
-
-        //验证优惠券是否还有效
-        if (!empty($couponId)) {
-            CouponService::checkBeforeUse($couponId, $order['prePrice'], $order['userId']);
-        }
-
-        //支付前验证订单有效性
-        OrderService::checkBeforePay($order, $this->adminId);
-
-        $name = isset($order['orderName']) && !empty($order['orderName']) ? $order['orderName'] : '购买商品';
-        $totalFee = $order['actPrice'];
-
-        //小程序使用miniOpenId
-        if (httpUtil::isMiniProgram()) {
-            $openId = $this->user['miniOpenId'];
-        } else {
-            $openId = $this->user['openId'];
-        }
-        $typeList = configDict::getConfig('capitalType');
-        $capitalType = $typeList['xhOrder']['id'];
-        //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
-        $wxPayType = 0;
-        if (httpUtil::isMiniProgram()) {
-            $wxPayType = 1;
-        }
-        $attach = "couponId=" . $couponId . "&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType;
-        //订单30分钟后过期
-        $now = time();
-        $expireTime = $now + 1800;
-
-        $wx = Yii::getAlias("@vendor/weixin");
-        require_once($wx . '/lib/WxPay.Api.php');
-        require_once($wx . '/example/WxPay.JsApiPay.php');
-        $input = new \WxPayUnifiedOrder();
-        $input->SetBody($name);
-        $input->SetOut_trade_no($orderSn);
-        $input->SetTotal_fee($totalFee * 100);
-        $input->SetTime_start(date("YmdHis", $now));
-        $input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传
-        $input->SetTime_expire(date("YmdHis", $expireTime));
-        $input->SetNotify_url(Yii::$app->params['mallHost'] . '/notice/wx-callback/');
-        $input->SetTrade_type("JSAPI");
-
-        //花卉宝代为申请的微信支付
-        $merchantExtend = $this->sjExtend;
-        if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) {
-            $input->SetSub_openid($openId);
-        } else {
-            $input->SetOpenid($openId);
-        }
-        //小程序使用miniAppId
-        if (httpUtil::isMiniProgram()) {
-            $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
-        }
-
-        $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
-        $tools = new \JsApiPay();
-        $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
-        $newParams = json_decode($jsApiParameters, true);
-        //已请求微信不能修改价格
-        $updateData = [];
-        $updateData['modPrice'] = 0;
-        if (empty($order['deadline'])) {
-            $updateData['deadline'] = $expireTime;
-        }
-        OrderService::updateById($orderId, $updateData);
-        util::success($newParams);
-    }
-
-    //快捷付款订单
-    public function actionFastPay()
-    {
-        ini_set('date.timezone', 'Asia/Shanghai');
-        $post = Yii::$app->request->post();
-        $payWay = isset($post['payWay']) ? $post['payWay'] : 0;
-        $shopId = !empty($this->shopId) ? $this->shopId : ShopService::getDefaultShopId($this->sj);
-        //验证门店是否有效
-        $shopInfo = ShopService::getById($shopId);
-        ShopService::valid($shopInfo, $this->sjId);
-        $post['shopId'] = $shopId;
-        //默认门店订单
-        $store = isset($post['store']) ? $post['store'] : 1;
-        $post['store'] = $store;
-        //来源 0微信 1支付宝 2小程序 3朋友圈 4美团
-        $sourceType = $this->isWx ? 0 : 1;
-        if (httpUtil::isMiniProgram()) {
-            $sourceType = 2;
-        }
-        $sourceType = isset($post['sourceType']) ? $post['sourceType'] : 0;
-        //兼容旧系统sourceType=3表示朋友圈来源
-        $fromType = $sourceType == 3 ? 2 : 0;
-        $fromType = isset($post['fromType']) && !empty($post['fromType']) ? $post['fromType'] : $fromType;
-        $post['userId'] = $this->adminId;
-        $custom = $this->custom;
-        $post['bookName'] = $custom['userName'] ?? '';
-        $bookMobile = isset($post['bookMobile']) && !empty($post['bookMobile']) && stringUtil::isMobile($post['bookMobile']) ? $post['bookMobile'] : '';
-        $bookMobile = empty($bookMobile) && isset($custom['mobile']) && !empty($custom['mobile']) ? $custom['mobile'] : $bookMobile;
-        $post['bookMobile'] = $bookMobile;
-        $prePrice = round($post['prePrice'], 2);
-        $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
-        $discountData = OrderService::getDiscountPrice(['price' => $prePrice, 'sourceType' => $sourceType, 'couponId' => $couponId, 'userId' => $this->adminId]);
-        $actPrice = $discountData['price'];
-        $post['discountType'] = $discountData['discountType'];
-        $post['discountAmount'] = $discountData['discountAmount'];
-        $post['actPrice'] = $actPrice;
-        $post['payStyle'] = 0;
-        $post['merchantId'] = $this->sjId;
-        $now = time();
-        $expireTime = $now + 300;//订单5分钟后过期
-        $post['createTime'] = date("Y-m-d H:i:s", $now);
-        $post['deadline'] = $expireTime;
-        if ($actPrice <= 0) {
-            util::fail('请填写正确的金额');
-        }
-        //微信支付订单提交不能修改价格
-        $post['modPrice'] = $this->isWx ? 0 : 1;
-        $post['sourceType'] = $sourceType;
-        $post['goodsNum'] = 1;
-        $post['fromType'] = $fromType;
-        $order = OrderService::addOrder($post);
-        $orderId = $order['id'];
-        $orderSn = $order['orderSn'];
-        $merchantId = $this->sjId;
-        if ($payWay == 0) {
-            $orderId = $order['id'];
-            $name = '购买商品';
-            $totalFee = $actPrice;
-            $user = UserService::getById($this->adminId);
-            $openId = isset($user['openId']) ? $user['openId'] : 0;
-            if (httpUtil::isMiniProgram()) {
-                //小程序使用miniOpenId
-                $openId = $user['miniOpenId'];
-            }
-            if (empty($openId)) {
-                util::fail('没有找到客户的openId');
-            }
-            $typeList = configDict::getConfig('capitalType');
-            $capitalType = $typeList['xhOrder']['id'];
-            //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
-            $wxPayType = 0;
-            if (httpUtil::isMiniProgram()) {
-                $wxPayType = 1;
-            }
-            $attach = 'capitalType=' . $capitalType . '&couponId=' . $couponId . '&wxPayType=' . $wxPayType;
-            $wx = Yii::getAlias("@vendor/weixin");
-            require_once($wx . '/lib/WxPay.Api.php');
-            require_once($wx . '/example/WxPay.JsApiPay.php');
-            $input = new \WxPayUnifiedOrder();
-            $input->SetBody($name);
-            $input->SetOut_trade_no($orderSn);
-            $input->SetTotal_fee($totalFee * 100);
-            $input->SetTime_start(date("YmdHis", $now));
-            $input->SetAttach($attach);
-            //设置订单有效期5分钟
-            $input->SetTime_expire(date("YmdHis", $expireTime));
-            $input->SetNotify_url(Yii::$app->params['mallHost'] . '/notice/wx-callback/');
-            $input->SetTrade_type("JSAPI");
-
-            //花卉宝代为申请的微信支付
-            $merchantExtend = $this->sjExtend;
-            if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) {
-                $input->SetSub_openid($openId);
-            } else {
-                $input->SetOpenid($openId);
-            }
-            //小程序使用miniAppId
-            if (httpUtil::isMiniProgram()) {
-                $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
-            }
-            Yii::info('支付发起使用小程序信息' . json_encode($merchantExtend));
-            $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
-            $tools = new \JsApiPay();
-            $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
-            $newParams = json_decode($jsApiParameters, true);
-            $newParams['orderId'] = $orderId;
-            util::success($newParams);
-        } elseif ($payWay == 1) {
-            $extend = MerchantExtendService::getByMerchantId($merchantId);
-            if (isset($extend['alipayInit']) == false || $extend['alipayInit'] == 0) {
-                util::fail('支付宝付款即将开通...');
-            }
-            $config = [
-                //应用ID,您的APPID。
-                'app_id' => $extend['alipayPId'],
-                //商户私钥,您的原始格式RSA私钥
-                'merchant_private_key' => $extend['alipayKey'],
-                //异步通知地址
-                'notify_url' => Yii::$app->params['mallHost'] . "/notice/alipay-callback",
-                //同步跳转
-                'return_url' => "",
-                //编码格式
-                'charset' => "UTF-8",
-                //签名方式
-                'sign_type' => "RSA2",
-                //支付宝网关
-                'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
-                //支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
-                'alipay_public_key' => $extend['alipayPublicKey'],
-            ];
-
-            Yii::info(json_encode($config) . ' aplipay config');
-
-            $alipayWap = Yii::getAlias("@vendor/alipayWap");
-            require_once($alipayWap . '/wappay/service/AlipayTradeService.php');
-            require_once($alipayWap . '/wappay/buildermodel/AlipayTradeWapPayContentBuilder.php');
-
-            $totalFee = $order['actPrice'];
-            $out_trade_no = $orderSn;//商户订单号,商户网站订单系统中唯一订单号,必填
-            $subject = '购买商品';//订单名称,必填
-            $total_amount = $totalFee;//付款金额,必填
-            $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['mallDomain'] . "/#/pages/callback/success?account={$merchantId}&shopId={$shopId}&orderSn={$orderSn}&totalPrice={$totalFee}&pageStatus=3&payDiscountPrice=0&payDiscountType=0";
-            //异步通知
-            $notifyUrl = Yii::$app->params['mallHost'] . "/notice/alipay-callback";
-            $payResponse = new \AlipayTradeService($config);
-            $result = $payResponse->wapPay($payRequestBuilder, $returnUrl, $notifyUrl);
-            //直接将支付宝的html返回给前端
-            echo $result;
-        } elseif ($payWay == 2) {
-            //余额支付,验证支付密码是否正确
-            $payPassword = isset($post['payPassword']) ? $post['payPassword'] : 0;
-            $user = UserService::getUserInfo($this->adminId, false);
-            UserService::validPayPassword($payPassword, $user);
-            $typeList = configDict::getConfig('capitalType');
-            $capitalType = $typeList['xhOrder']['id'];
-            $callbackParams = [];
-            $respond = xhPayToolService::balancePay($callbackParams, $orderSn, $actPrice, $capitalType, $couponId);
-            $balance = isset($respond['balance']) ? $respond['balance'] : 0;
-            util::success(['discountAmount' => $discountData['discountAmount'], 'discountType' => $discountData['discountType'], 'orderSn' => $orderSn, 'orderId' => $orderId, 'balance' => $balance]);
-        } else {
-            util::fail('无效的支付方式');
-        }
-    }
-
-    //订单评价
-    public function actionComment()
-    {
-        $post = Yii::$app->request->post();
-        $id = $post['id'];
-        $order = OrderService::getById($id);
-        OrderService::valid($order, $this->sjId);
-        if ($order['grade'] > 0) {
-            util::fail('您已经评过了');
-        }
-        OrderService::comment($post);
-        util::complete('提交成功');
-    }
-
-    //订单详情 shish 2019.12.16
-    public function actionDetail()
-    {
-        $id = Yii::$app->request->get('id', 0);
-        $orderSn = Yii::$app->request->get('orderSn', '');
-        $detail = [];
-        if (!empty($id)) {
-            $detail = OrderService::getOrderById($id);
-        }
-        if (!empty($orderSn)) {
-            $detail = OrderService::getOrderBySn($orderSn);
-        }
-        OrderService::valid($detail, $this->sjId);
-        util::success($detail);
-    }
-
-    public function actionList()
-    {
-        $get = Yii::$app->request->get();
-        $search = isset($get['search']) ? $get['search'] : '';
-        $where = [];
-        $where['merchantId'] = $this->sjId;
-        if (isset($get['status']) && $get['status'] != -1) {
-            $where['status'] = $get['status'];
-        }
-        if (!empty($search)) {
-            if (stringUtil::isMobile($search)) {
-                $where['receiveMobile'] = $search;
-            } else {
-                $where['id'] = $search;
-            }
-        }
-        $list = OrderService::getOrderList($where);
-        $list['asset'] = MerchantAssetService::getByMerchantId($this->sjId);
-        util::success($list);
-    }
-
-    //订单归类 shish 2019.12.17
-    public function actionClassify()
-    {
-        $post = Yii::$app->request->post();
-        $id = isset($post['id']) ? $post['id'] : 0;
-        $order = OrderService::getById($id);
-        OrderService::valid($order, $this->sjId);
-        $categoryId = isset($post['categoryId']) ? $post['categoryId'] : $post['categoryId'];
-        $usageId = isset($post['usageId']) ? $post['usageId'] : $post['usageId'];
-        OrderService::classify($id, $categoryId, $usageId);
-        util::complete();
-    }
-
-    //更新配送单 shish 2019.12.17
-    public function actionUpdateSheet()
-    {
-        $post = Yii::$app->request->post();
-        $id = isset($post['id']) ? $post['id'] : 0;
-        unset($post['id']);
-        $order = OrderService::getById($id);
-        OrderService::valid($order, $this->sjId);
-        OrderService::updateSheet($order, $post);
-        util::complete('提交成功');
-    }
-
-    //商家收款与发货 shish 2019.12.18
-    public function actionGathering()
-    {
-        $post = Yii::$app->request->post();
-        $price = isset($post['price']) && is_numeric($post['price']) ? $post['price'] : 0;
-        $payWay = isset($post['payWay']) && is_numeric($post['payWay']) ? $post['payWay'] : 0;
-        $userId = isset($post['userId']) ? $post['userId'] : 0;
-        $userInfo = UserService::getById($userId);
-        if (empty($userInfo) || $userInfo['merchantId'] != $this->sjId) {
-            util::fail('您选择的客户无效');
-        }
-        if ($price <= 0) {
-            util::fail('请输入金额');
-        }
-        $post['prePrice'] = $price;
-        $post['actPrice'] = $price;
-        $post['payWay'] = $payWay;
-        $post['sourceType'] = 1;
-        $post['userId'] = $userId;
-        $post['goodsNum'] = 1;
-        $post['orderName'] = '商品';
-        $shopId = MerchantService::getDefaultShopId($this->sj);
-        $post['shopId'] = $shopId;
-        $order = OrderService::addOrder($post);
-        $id = $order['id'];
-        $orderSn = $order['orderSn'];
-
-        //流水类型列表
-        $capitalTypeList = configDict::getConfig('capitalType');
-        $capitalType = $capitalTypeList['xhOrder']['id'];
-        $callbackParams = [];
-        switch ($payWay) {
-            case 0:
-                xhPayToolService::weixinPay($callbackParams, $orderSn, $price, $capitalType, 0);
-                break;
-            case 1:
-                xhPayToolService::alipay($callbackParams, $orderSn, $price, $capitalType, 0, []);
-                break;
-            case 2:
-                xhPayToolService::balancePay($callbackParams, $orderSn, $price, $capitalType, 0);
-                break;
-            default:
-                util::fail('无效支付方式');
-        }
-        util::success($order);
-    }
-
-    //免发货管理 shish 2020.1.6
-    public function actionWithoutSend()
-    {
-        $id = Yii::$app->request->get('id');
-        $order = OrderService::getById($id);
-        OrderService::valid($order, $this->sjId);
-        //配送流程变更
-        $currentFlow = OrderSendClass::withoutSend($order);
-        util::success(['currentFlow' => $currentFlow]);
-    }
-
-    //修改价格 shish 2020.1.6
-    public function actionUpdatePrice()
-    {
-        $id = Yii::$app->request->get('id');
-        $price = Yii::$app->request->get('price', 1);
-        $order = OrderService::getById($id);
-        OrderService::valid($order, $this->sjId);
-        if (isset($order['modPrice']) && $order['modPrice'] == 0) {
-            util::fail('已发起支付,不能修改价格');
-        }
-        OrderService::updateById($id, ['actPrice' => $price]);
-        util::complete('修改成功');
-    }
-
-    //配送单 shish 2020.2.29
-    public function actionGetDeliverDetail()
-    {
-        $id = Yii::$app->request->get('id', 0);
-        $order = OrderService::getById($id);
-        OrderService::valid($order, $this->sjId);
-        $reachDate = isset($order['reachDate']) && !empty($order['reachDate']) ? $order['reachDate'] : '';
-        $reachPeriodId = $order['reachPeriod'];
-        $reachPeriodArr = [0 => '上午', 1 => '下午', 2 => '晚上'];
-        $reachPeriod = isset($reachPeriodArr[$reachPeriodId]) ? $reachPeriodArr[$reachPeriodId] : '';
-        $shopId = $order['shopId'];
-        $telephone = '';
-        if (!empty($shopId)) {
-            $shop = ShopService::getById($shopId);
-        }
-        $telephone = isset($shop['telephone']) ? $shop['telephone'] : '';
-        $bookName = isset($order['bookName']) ? $order['bookName'] : '';
-        $bookMobile = isset($order['bookMobile']) ? $order['bookMobile'] : '';
-        if (isset($order['anonymity']) && $order['anonymity'] == 1) {
-            $bookName = '--';
-            $bookMobile = '--';
-        }
-        $data = [
-            'reachDate' => $reachDate . ' ' . $reachPeriod,
-            'orderSn' => $order['orderSn'],
-            'receiveUserName' => $order['receiveUserName'],
-            'receiveMobile' => $order['receiveMobile'],
-            'receiveFullAddress' => $order['receiveAddress'] . $order['receiveFloor'] . "(" . $order['receiveFullAddress'] . ")",
-            'cardInfo' => $order['cardInfo'],
-            'bookMobile' => $bookMobile,
-            'bookName' => $bookName,
-            'remark' => $order['remark'],
-            'sendNum' => $order['sendNum'],
-            'telephone' => 13600903070,
-            'printTime' => '',
-            'img' => '',
-        ];
-        util::success($data);
-    }
-
+	
+	public $guestAccessAction = ['order-relate', 'fast-pay', 'create-order', 'list'];
+	
+	//商城下单操作 shish 2019.12.3
+	public function actionCreateOrder()
+	{
+		$post = Yii::$app->request->post();
+		$needSend = isset($post['needSend']) && is_numeric($post['needSend']) ? $post['needSend'] : 1;
+		$orderType = $post['orderType'] ?? 1;
+		
+		$defaultShopId = MerchantService::getDefaultShopId($this->sj);
+		if (empty($defaultShopId)) {
+			util::fail('没有找到门店');
+		}
+		$post['merchantId'] = $this->sjId;
+		$post['shopId'] = $defaultShopId;
+		$post['payWay'] = $this->isWx == true ? 0 : 1;
+		$now = time();
+		$expireTime = $now + 1800;//订单30分钟后过期
+		$post['deadline'] = $expireTime;
+		$post['fromType'] = 1;//商城
+		$customId = $post['customId'] ?? 0;
+		if (!empty($customId)) {
+			$customId = $this->customId;
+		}
+		$post['customId'] = $customId;
+		//非门店订单
+		$store = 0;
+		$post['store'] = $store;
+		
+		$couponId = isset($post['couponId']) && !empty($post['couponId']) ? $post['couponId'] : 0;
+		
+		//$orderType = 1 成品订单
+		if ($orderType == 1) {
+			
+			$goodsInfo = $post['goodsInfo'] ?? '';
+			$goodsInfoArr = json_decode($goodsInfo, true);
+			if (empty($goodsInfoArr)) {
+				util::fail('请选择商品');
+			}
+			//总的商品金额
+			$totalGoodsPrice = 0;
+			$orderGoods = [];
+			foreach ($goodsInfoArr as $key => $currentGoods) {
+				$currentGoodsId = $currentGoods['goodsId'];
+				$currentGoodsInfo = GoodsService::getGoodsInfo($currentGoodsId);
+				if (empty($currentGoodsInfo)) {
+					util::fail('没有找到商品');
+				}
+				$goodsStyleId = $currentGoods['goodsStyleId'];
+				$goodsNum = $currentGoods['goodsNum'];
+				//计算总金额
+				$unitPrice = $currentGoodsInfo['price'];
+				$goodsStyleList = isset($currentGoodsInfo['goodsStyleList']) ? $currentGoodsInfo['goodsStyleList'] : [];
+				if (!empty($goodsStyleId)) {
+					if (empty($goodsStyleList)) {
+						util::fail('商品款式没有找到');
+					}
+					$styleIdList = array_keys($goodsStyleList);
+					if (in_array($goodsStyleId, $styleIdList) == false) {
+						util::fail('商品款式没有找到!');
+					}
+					$unitPrice = isset($goodsStyleList[$goodsStyleId]['price']) ? $goodsStyleList[$goodsStyleId]['price'] : 9999;
+				}
+				$goodsPrice = $unitPrice * $goodsNum;
+				$totalGoodsPrice = stringUtil::calcAdd($totalGoodsPrice, $goodsPrice);
+				
+				$orderGoods[] = [
+					'goodsId' => $currentGoodsId,
+					'userId' => $this->adminId,
+					'merchantId' => $this->sjId,
+					'title' => $currentGoodsInfo['goodsName'],
+					'cover' => isset($goodsInfo['shortImgList']) && !empty($currentGoodsInfo['shortImgList']) ? current($currentGoodsInfo['shortImgList']) : '',
+					'unitPrice' => $unitPrice,
+					'num' => $goodsNum,
+					'goodsStyleName' => isset($currentGoodsInfo['goodsStyleList'][$goodsStyleId]['title']) ? $currentGoodsInfo['goodsStyleList'][$goodsStyleId]['title'] : '',
+					'goodsStyleId' => $goodsStyleId,
+					'createTime' => date("Y-m-d H:i:s"),
+				];
+				
+			}
+			
+			$user = $this->custom;
+			$post['bookName'] = isset($user['name']) ? $user['name'] : '';
+			$bookMobile = isset($post['bookMobile']) && !empty($post['bookMobile']) && stringUtil::isMobile($post['bookMobile']) ? $post['bookMobile'] : '';
+			$bookMobile = empty($bookMobile) && isset($user['mobile']) && !empty($user['mobile']) ? $user['mobile'] : $bookMobile;
+			$post['bookMobile'] = $bookMobile;
+			
+			//计算运费
+			$post['sendDistance'] = isset($post['sendDistance']) ? $post['sendDistance'] : 0;
+			$sendCost = 0;
+			//按距离计算运费并且客户要求送的
+			//运费计算方式
+			$freightType = 0;
+			if ($freightType == 0 && $needSend == 1) {
+				$lat = $post['latitude'];//收货人纬度
+				$lng = $post['longitude'];//收货人经度
+				$respond = ExpressService::getUserDistance($lng, $lat, $defaultShopId, $this->sjExtend);
+				$sendCost = isset($respond['fee']) ? $respond['fee'] : 0;
+			}
+			$post['sendCost'] = $sendCost;
+			
+			$prePrice = stringUtil::calcAdd($sendCost, $totalGoodsPrice);
+			
+			//来源 0微信 1支付宝 2小程序 3朋友圈 4美团
+			$sourceType = $this->isWx ? 0 : 1;
+			if (httpUtil::isMiniProgram()) {
+				$sourceType = 2;
+			}
+			$discountData = OrderService::getDiscountPrice(['price' => $prePrice, 'sourceType' => $sourceType, 'couponId' => $couponId, 'userId' => $this->adminId]);
+			$actPrice = $discountData['price'];
+			$post['discountType'] = $discountData['discountType'];
+			$post['discountAmount'] = $discountData['discountAmount'];
+			$post['prePrice'] = $prePrice;
+			$post['actPrice'] = $actPrice;
+			$order = OrderClass::addOrder($post);
+			$orderId = $order['id'];
+			$orderSn = $order['orderSn'];
+			
+			foreach ($orderGoods as $key => $val) {
+				$val['orderId'] = $orderId;
+				$val['orderSn'] = $orderSn;
+				OrderGoodsService::add($val);//创建订单商品列表
+			}
+		} else {
+			//$orderType = 2 花材订单
+			
+			$productData = $post['product'] ?? '';
+			$product = json_decode($productData, true);
+			if (empty($product)) {
+				util::fail('请选择花材');
+			}
+            $actPrice = 0;
+			$orderProduct = [];
+			foreach ($product as $key => $val) {
+				$productId = $val['productId'];
+				$bigNum = $val['bigNum'];
+				$smallNum = $val['smallNum'];
+                $actPrice += 2;
+				$orderProduct[] = [
+					'productId' => $productId,
+					'bigNum' => $bigNum,
+					'smallNum' => $smallNum,
+				];
+			}
+
+			$post['prePrice'] = $actPrice;
+			$post['actPrice'] = $actPrice;
+			$order = OrderClass::addOrder($post);
+			$orderId = $order['id'];
+			$orderSn = $order['orderSn'];
+
+			foreach ($orderProduct as $key => $val) {
+				$val['orderSn'] = $orderSn;
+				OrderItemClass::add($val);
+			}
+
+		}
+		util::success(['orderSn' => $orderSn, 'totalPrice' => $actPrice, 'couponId' => $couponId, 'orderId' => $orderId]);
+	}
+	
+	//下单要用到的相关信息 shish 2019.12.6
+	public function actionOrderRelate()
+	{
+		$regionTree = RegionService::tree();
+		$shop = ShopService::getDefaultShop($this->sj);
+		$freight = MerchantExtendService::getFreight($this->sjExtend);
+		$mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
+		$out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'txMapKey' => $mapKey, 'merchant' => $this->sj];
+		util::success($out);
+	}
+	
+	//余额支付 shish 2019.12.6
+	public function actionBalancePay()
+	{
+		$post = Yii::$app->request->post();
+		$orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
+		$payPassword = isset($post['payPassword']) ? $post['payPassword'] : 0;
+		$couponId = isset($post['couponId']) ? $post['couponId'] : 0;
+		
+		//验证优惠券是否还有效
+		if (!empty($couponId)) {
+			CouponService::checkBeforeUse($couponId, $order['prePrice'], $order['userId']);
+		}
+		
+		$order = OrderService::getByOrderSn($orderSn);
+		$userId = $this->adminId;
+		$user = UserService::getUserInfo($userId, false);
+		//验证支付密码是否正确
+		UserService::validPayPassword($payPassword, $user);
+		//支付前验证订单有效性
+		OrderService::checkBeforePay($order, $this->adminId);
+		$typeList = configDict::getConfig('capitalType');
+		$capitalType = $typeList['xhOrder']['id'];
+		$totalFee = $order['prePrice'];
+		$sourceType = 0;
+		$discountData = OrderService::getDiscountPrice(['price' => $totalFee, 'sourceType' => $sourceType, 'couponId' => $couponId, 'userId' => $this->adminId]);
+		$actPrice = $discountData['price'];
+		$callbackParams = [];
+		$respond = xhPayToolService::balancePay($callbackParams, $orderSn, $actPrice, $capitalType, $couponId);
+		$balance = isset($respond['balance']) ? $respond['balance'] : 0;
+		util::success(['discountAmount' => $discountData['discountAmount'], 'discountType' => $discountData['discountType'], 'balance' => $balance]);
+	}
+	
+	//获取商城下单要用的微信支付和小程序支付参数 shish 2019.21.3
+	public function actionWxPay()
+	{
+		ini_set('date.timezone', 'Asia/Shanghai');
+		$post = Yii::$app->request->post();
+		$couponId = isset($post['couponId']) ? $post['couponId'] : 0;
+		$orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0;
+		$order = OrderService::getByOrderSn($orderSn);
+		$orderId = $order['id'];
+		
+		//验证优惠券是否还有效
+		if (!empty($couponId)) {
+			CouponService::checkBeforeUse($couponId, $order['prePrice'], $order['userId']);
+		}
+		
+		//支付前验证订单有效性
+		OrderService::checkBeforePay($order, $this->adminId);
+		
+		$name = isset($order['orderName']) && !empty($order['orderName']) ? $order['orderName'] : '购买商品';
+		$totalFee = $order['actPrice'];
+		
+		//小程序使用miniOpenId
+		if (httpUtil::isMiniProgram()) {
+			$openId = $this->user['miniOpenId'];
+		} else {
+			$openId = $this->user['openId'];
+		}
+		$typeList = configDict::getConfig('capitalType');
+		$capitalType = $typeList['xhOrder']['id'];
+		//流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
+		$wxPayType = 0;
+		if (httpUtil::isMiniProgram()) {
+			$wxPayType = 1;
+		}
+		$attach = "couponId=" . $couponId . "&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType;
+		//订单30分钟后过期
+		$now = time();
+		$expireTime = $now + 1800;
+		
+		$wx = Yii::getAlias("@vendor/weixin");
+		require_once($wx . '/lib/WxPay.Api.php');
+		require_once($wx . '/example/WxPay.JsApiPay.php');
+		$input = new \WxPayUnifiedOrder();
+		$input->SetBody($name);
+		$input->SetOut_trade_no($orderSn);
+		$input->SetTotal_fee($totalFee * 100);
+		$input->SetTime_start(date("YmdHis", $now));
+		$input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传
+		$input->SetTime_expire(date("YmdHis", $expireTime));
+		$input->SetNotify_url(Yii::$app->params['mallHost'] . '/notice/wx-callback/');
+		$input->SetTrade_type("JSAPI");
+		
+		//花卉宝代为申请的微信支付
+		$merchantExtend = $this->sjExtend;
+		if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) {
+			$input->SetSub_openid($openId);
+		} else {
+			$input->SetOpenid($openId);
+		}
+		//小程序使用miniAppId
+		if (httpUtil::isMiniProgram()) {
+			$merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
+		}
+		
+		$wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
+		$tools = new \JsApiPay();
+		$jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
+		$newParams = json_decode($jsApiParameters, true);
+		//已请求微信不能修改价格
+		$updateData = [];
+		$updateData['modPrice'] = 0;
+		if (empty($order['deadline'])) {
+			$updateData['deadline'] = $expireTime;
+		}
+		OrderService::updateById($orderId, $updateData);
+		util::success($newParams);
+	}
+	
+	//快捷付款订单
+	public function actionFastPay()
+	{
+		ini_set('date.timezone', 'Asia/Shanghai');
+		$post = Yii::$app->request->post();
+		$payWay = isset($post['payWay']) ? $post['payWay'] : 0;
+		$shopId = !empty($this->shopId) ? $this->shopId : ShopService::getDefaultShopId($this->sj);
+		//验证门店是否有效
+		$shopInfo = ShopService::getById($shopId);
+		ShopService::valid($shopInfo, $this->sjId);
+		$post['shopId'] = $shopId;
+		//默认门店订单
+		$store = isset($post['store']) ? $post['store'] : 1;
+		$post['store'] = $store;
+		//来源 0微信 1支付宝 2小程序 3朋友圈 4美团
+		$sourceType = $this->isWx ? 0 : 1;
+		if (httpUtil::isMiniProgram()) {
+			$sourceType = 2;
+		}
+		$sourceType = isset($post['sourceType']) ? $post['sourceType'] : 0;
+		//兼容旧系统sourceType=3表示朋友圈来源
+		$fromType = $sourceType == 3 ? 2 : 0;
+		$fromType = isset($post['fromType']) && !empty($post['fromType']) ? $post['fromType'] : $fromType;
+		$post['userId'] = $this->adminId;
+		$custom = $this->custom;
+		$post['bookName'] = $custom['userName'] ?? '';
+		$bookMobile = isset($post['bookMobile']) && !empty($post['bookMobile']) && stringUtil::isMobile($post['bookMobile']) ? $post['bookMobile'] : '';
+		$bookMobile = empty($bookMobile) && isset($custom['mobile']) && !empty($custom['mobile']) ? $custom['mobile'] : $bookMobile;
+		$post['bookMobile'] = $bookMobile;
+		$prePrice = round($post['prePrice'], 2);
+		$couponId = isset($post['couponId']) ? $post['couponId'] : 0;
+		$discountData = OrderService::getDiscountPrice(['price' => $prePrice, 'sourceType' => $sourceType, 'couponId' => $couponId, 'userId' => $this->adminId]);
+		$actPrice = $discountData['price'];
+		$post['discountType'] = $discountData['discountType'];
+		$post['discountAmount'] = $discountData['discountAmount'];
+		$post['actPrice'] = $actPrice;
+		$post['payStyle'] = 0;
+		$post['merchantId'] = $this->sjId;
+		$now = time();
+		$expireTime = $now + 300;//订单5分钟后过期
+		$post['createTime'] = date("Y-m-d H:i:s", $now);
+		$post['deadline'] = $expireTime;
+		if ($actPrice <= 0) {
+			util::fail('请填写正确的金额');
+		}
+		//微信支付订单提交不能修改价格
+		$post['modPrice'] = $this->isWx ? 0 : 1;
+		$post['sourceType'] = $sourceType;
+		$post['goodsNum'] = 1;
+		$post['fromType'] = $fromType;
+		$order = OrderService::addOrder($post);
+		$orderId = $order['id'];
+		$orderSn = $order['orderSn'];
+		$merchantId = $this->sjId;
+		if ($payWay == 0) {
+			$orderId = $order['id'];
+			$name = '购买商品';
+			$totalFee = $actPrice;
+			$user = UserService::getById($this->adminId);
+			$openId = isset($user['openId']) ? $user['openId'] : 0;
+			if (httpUtil::isMiniProgram()) {
+				//小程序使用miniOpenId
+				$openId = $user['miniOpenId'];
+			}
+			if (empty($openId)) {
+				util::fail('没有找到客户的openId');
+			}
+			$typeList = configDict::getConfig('capitalType');
+			$capitalType = $typeList['xhOrder']['id'];
+			//流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
+			$wxPayType = 0;
+			if (httpUtil::isMiniProgram()) {
+				$wxPayType = 1;
+			}
+			$attach = 'capitalType=' . $capitalType . '&couponId=' . $couponId . '&wxPayType=' . $wxPayType;
+			$wx = Yii::getAlias("@vendor/weixin");
+			require_once($wx . '/lib/WxPay.Api.php');
+			require_once($wx . '/example/WxPay.JsApiPay.php');
+			$input = new \WxPayUnifiedOrder();
+			$input->SetBody($name);
+			$input->SetOut_trade_no($orderSn);
+			$input->SetTotal_fee($totalFee * 100);
+			$input->SetTime_start(date("YmdHis", $now));
+			$input->SetAttach($attach);
+			//设置订单有效期5分钟
+			$input->SetTime_expire(date("YmdHis", $expireTime));
+			$input->SetNotify_url(Yii::$app->params['mallHost'] . '/notice/wx-callback/');
+			$input->SetTrade_type("JSAPI");
+			
+			//花卉宝代为申请的微信支付
+			$merchantExtend = $this->sjExtend;
+			if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) {
+				$input->SetSub_openid($openId);
+			} else {
+				$input->SetOpenid($openId);
+			}
+			//小程序使用miniAppId
+			if (httpUtil::isMiniProgram()) {
+				$merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
+			}
+			Yii::info('支付发起使用小程序信息' . json_encode($merchantExtend));
+			$wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
+			$tools = new \JsApiPay();
+			$jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
+			$newParams = json_decode($jsApiParameters, true);
+			$newParams['orderId'] = $orderId;
+			util::success($newParams);
+		} elseif ($payWay == 1) {
+			$extend = MerchantExtendService::getByMerchantId($merchantId);
+			if (isset($extend['alipayInit']) == false || $extend['alipayInit'] == 0) {
+				util::fail('支付宝付款即将开通...');
+			}
+			$config = [
+				//应用ID,您的APPID。
+				'app_id' => $extend['alipayPId'],
+				//商户私钥,您的原始格式RSA私钥
+				'merchant_private_key' => $extend['alipayKey'],
+				//异步通知地址
+				'notify_url' => Yii::$app->params['mallHost'] . "/notice/alipay-callback",
+				//同步跳转
+				'return_url' => "",
+				//编码格式
+				'charset' => "UTF-8",
+				//签名方式
+				'sign_type' => "RSA2",
+				//支付宝网关
+				'gatewayUrl' => "https://openapi.alipay.com/gateway.do",
+				//支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
+				'alipay_public_key' => $extend['alipayPublicKey'],
+			];
+			
+			Yii::info(json_encode($config) . ' aplipay config');
+			
+			$alipayWap = Yii::getAlias("@vendor/alipayWap");
+			require_once($alipayWap . '/wappay/service/AlipayTradeService.php');
+			require_once($alipayWap . '/wappay/buildermodel/AlipayTradeWapPayContentBuilder.php');
+			
+			$totalFee = $order['actPrice'];
+			$out_trade_no = $orderSn;//商户订单号,商户网站订单系统中唯一订单号,必填
+			$subject = '购买商品';//订单名称,必填
+			$total_amount = $totalFee;//付款金额,必填
+			$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['mallDomain'] . "/#/pages/callback/success?account={$merchantId}&shopId={$shopId}&orderSn={$orderSn}&totalPrice={$totalFee}&pageStatus=3&payDiscountPrice=0&payDiscountType=0";
+			//异步通知
+			$notifyUrl = Yii::$app->params['mallHost'] . "/notice/alipay-callback";
+			$payResponse = new \AlipayTradeService($config);
+			$result = $payResponse->wapPay($payRequestBuilder, $returnUrl, $notifyUrl);
+			//直接将支付宝的html返回给前端
+			echo $result;
+		} elseif ($payWay == 2) {
+			//余额支付,验证支付密码是否正确
+			$payPassword = isset($post['payPassword']) ? $post['payPassword'] : 0;
+			$user = UserService::getUserInfo($this->adminId, false);
+			UserService::validPayPassword($payPassword, $user);
+			$typeList = configDict::getConfig('capitalType');
+			$capitalType = $typeList['xhOrder']['id'];
+			$callbackParams = [];
+			$respond = xhPayToolService::balancePay($callbackParams, $orderSn, $actPrice, $capitalType, $couponId);
+			$balance = isset($respond['balance']) ? $respond['balance'] : 0;
+			util::success(['discountAmount' => $discountData['discountAmount'], 'discountType' => $discountData['discountType'], 'orderSn' => $orderSn, 'orderId' => $orderId, 'balance' => $balance]);
+		} else {
+			util::fail('无效的支付方式');
+		}
+	}
+	
+	//订单评价
+	public function actionComment()
+	{
+		$post = Yii::$app->request->post();
+		$id = $post['id'];
+		$order = OrderService::getById($id);
+		OrderService::valid($order, $this->sjId);
+		if ($order['grade'] > 0) {
+			util::fail('您已经评过了');
+		}
+		OrderService::comment($post);
+		util::complete('提交成功');
+	}
+	
+	//订单详情 shish 2019.12.16
+	public function actionDetail()
+	{
+		$id = Yii::$app->request->get('id', 0);
+		$orderSn = Yii::$app->request->get('orderSn', '');
+		$detail = [];
+		if (!empty($id)) {
+			$detail = OrderService::getOrderById($id);
+		}
+		if (!empty($orderSn)) {
+			$detail = OrderService::getOrderBySn($orderSn);
+		}
+		OrderService::valid($detail, $this->sjId);
+		util::success($detail);
+	}
+	
+	public function actionList()
+	{
+		$get = Yii::$app->request->get();
+		$search = isset($get['search']) ? $get['search'] : '';
+		$where = [];
+		$where['merchantId'] = $this->sjId;
+		if (isset($get['status']) && $get['status'] != -1) {
+			$where['status'] = $get['status'];
+		}
+		if (!empty($search)) {
+			if (stringUtil::isMobile($search)) {
+				$where['receiveMobile'] = $search;
+			} else {
+				$where['id'] = $search;
+			}
+		}
+		$list = OrderService::getOrderList($where);
+		$list['asset'] = MerchantAssetService::getByMerchantId($this->sjId);
+		util::success($list);
+	}
+	
+	//订单归类 shish 2019.12.17
+	public function actionClassify()
+	{
+		$post = Yii::$app->request->post();
+		$id = isset($post['id']) ? $post['id'] : 0;
+		$order = OrderService::getById($id);
+		OrderService::valid($order, $this->sjId);
+		$categoryId = isset($post['categoryId']) ? $post['categoryId'] : $post['categoryId'];
+		$usageId = isset($post['usageId']) ? $post['usageId'] : $post['usageId'];
+		OrderService::classify($id, $categoryId, $usageId);
+		util::complete();
+	}
+	
+	//更新配送单 shish 2019.12.17
+	public function actionUpdateSheet()
+	{
+		$post = Yii::$app->request->post();
+		$id = isset($post['id']) ? $post['id'] : 0;
+		unset($post['id']);
+		$order = OrderService::getById($id);
+		OrderService::valid($order, $this->sjId);
+		OrderService::updateSheet($order, $post);
+		util::complete('提交成功');
+	}
+	
+	//商家收款与发货 shish 2019.12.18
+	public function actionGathering()
+	{
+		$post = Yii::$app->request->post();
+		$price = isset($post['price']) && is_numeric($post['price']) ? $post['price'] : 0;
+		$payWay = isset($post['payWay']) && is_numeric($post['payWay']) ? $post['payWay'] : 0;
+		$userId = isset($post['userId']) ? $post['userId'] : 0;
+		$userInfo = UserService::getById($userId);
+		if (empty($userInfo) || $userInfo['merchantId'] != $this->sjId) {
+			util::fail('您选择的客户无效');
+		}
+		if ($price <= 0) {
+			util::fail('请输入金额');
+		}
+		$post['prePrice'] = $price;
+		$post['actPrice'] = $price;
+		$post['payWay'] = $payWay;
+		$post['sourceType'] = 1;
+		$post['userId'] = $userId;
+		$post['goodsNum'] = 1;
+		$post['orderName'] = '商品';
+		$shopId = MerchantService::getDefaultShopId($this->sj);
+		$post['shopId'] = $shopId;
+		$order = OrderService::addOrder($post);
+		$id = $order['id'];
+		$orderSn = $order['orderSn'];
+		
+		//流水类型列表
+		$capitalTypeList = configDict::getConfig('capitalType');
+		$capitalType = $capitalTypeList['xhOrder']['id'];
+		$callbackParams = [];
+		switch ($payWay) {
+			case 0:
+				xhPayToolService::weixinPay($callbackParams, $orderSn, $price, $capitalType, 0);
+				break;
+			case 1:
+				xhPayToolService::alipay($callbackParams, $orderSn, $price, $capitalType, 0, []);
+				break;
+			case 2:
+				xhPayToolService::balancePay($callbackParams, $orderSn, $price, $capitalType, 0);
+				break;
+			default:
+				util::fail('无效支付方式');
+		}
+		util::success($order);
+	}
+	
+	//免发货管理 shish 2020.1.6
+	public function actionWithoutSend()
+	{
+		$id = Yii::$app->request->get('id');
+		$order = OrderService::getById($id);
+		OrderService::valid($order, $this->sjId);
+		//配送流程变更
+		$currentFlow = OrderSendClass::withoutSend($order);
+		util::success(['currentFlow' => $currentFlow]);
+	}
+	
+	//修改价格 shish 2020.1.6
+	public function actionUpdatePrice()
+	{
+		$id = Yii::$app->request->get('id');
+		$price = Yii::$app->request->get('price', 1);
+		$order = OrderService::getById($id);
+		OrderService::valid($order, $this->sjId);
+		if (isset($order['modPrice']) && $order['modPrice'] == 0) {
+			util::fail('已发起支付,不能修改价格');
+		}
+		OrderService::updateById($id, ['actPrice' => $price]);
+		util::complete('修改成功');
+	}
+	
+	//配送单 shish 2020.2.29
+	public function actionGetDeliverDetail()
+	{
+		$id = Yii::$app->request->get('id', 0);
+		$order = OrderService::getById($id);
+		OrderService::valid($order, $this->sjId);
+		$reachDate = isset($order['reachDate']) && !empty($order['reachDate']) ? $order['reachDate'] : '';
+		$reachPeriodId = $order['reachPeriod'];
+		$reachPeriodArr = [0 => '上午', 1 => '下午', 2 => '晚上'];
+		$reachPeriod = isset($reachPeriodArr[$reachPeriodId]) ? $reachPeriodArr[$reachPeriodId] : '';
+		$shopId = $order['shopId'];
+		$telephone = '';
+		if (!empty($shopId)) {
+			$shop = ShopService::getById($shopId);
+		}
+		$telephone = isset($shop['telephone']) ? $shop['telephone'] : '';
+		$bookName = isset($order['bookName']) ? $order['bookName'] : '';
+		$bookMobile = isset($order['bookMobile']) ? $order['bookMobile'] : '';
+		if (isset($order['anonymity']) && $order['anonymity'] == 1) {
+			$bookName = '--';
+			$bookMobile = '--';
+		}
+		$data = [
+			'reachDate' => $reachDate . ' ' . $reachPeriod,
+			'orderSn' => $order['orderSn'],
+			'receiveUserName' => $order['receiveUserName'],
+			'receiveMobile' => $order['receiveMobile'],
+			'receiveFullAddress' => $order['receiveAddress'] . $order['receiveFloor'] . "(" . $order['receiveFullAddress'] . ")",
+			'cardInfo' => $order['cardInfo'],
+			'bookMobile' => $bookMobile,
+			'bookName' => $bookName,
+			'remark' => $order['remark'],
+			'sendNum' => $order['sendNum'],
+			'telephone' => 13600903070,
+			'printTime' => '',
+			'img' => '',
+		];
+		util::success($data);
+	}
+	
 }

+ 112 - 0
app/shop/controllers/RechargeController.php

@@ -0,0 +1,112 @@
+<?php
+
+namespace shop\controllers;
+
+use biz\merchant\classes\MerchantClass;
+use biz\recharge\classes\RechargeClass;
+use biz\wx\classes\WxOpenClass;
+use common\components\configDict;
+use common\components\httpUtil;
+use common\components\util;
+use Yii;
+
+class RechargeController extends BaseController
+{
+
+    //充值记录 shish 2021.2.21
+    public function actionList()
+    {
+        $where = ['shopId' => $this->shopId, 'payStatus' => RechargeClass::PAY_STATUS_HAS_PAY];
+        $list = RechargeClass::getRechargeList($where);
+        util::success($list);
+    }
+
+    //免费续期活动 shish 2021.2.21
+    public function actionRenew()
+    {
+        $data = [
+            'renew' => 3980,
+            'recharge' => 5980,
+            'shopName' => '纯彩花艺',
+            'userNum' => 150,
+            'userAvatar' => [
+                Yii::$app->params['imgHost'] . '/hhb_small.png',
+                Yii::$app->params['imgHost'] . '/hhb_small.png',
+            ],
+        ];
+        util::success($data);
+    }
+
+    //续期充值付款 shish 2021.2.21
+    public function actionRenewPay()
+    {
+        ini_set('date.timezone', 'Asia/Shanghai');
+        $wxPay = configDict::getConfig('payWay', 'weixinPay');
+        $data = [
+            'amount' => 5980,
+            'payWay' => $wxPay,
+            'sjId' => $this->sjId,
+            'sjStyle' => MerchantClass::STYLE_RETAIL,
+            'shopId' => $this->shopId,
+            'modPrice' => 0,
+            'remark' => '免费续期充值',
+        ];
+        $order = RechargeClass::addOrder($data);
+        $orderSn = $order['orderSn'];
+        $name = $order['orderName'] ?? '充值';
+        $totalFee = $order['amount'];
+
+        //强制使用小程序的miniOpenId
+        $openId = $this->admin['miniOpenId'];
+
+        $capitalTypeData = configDict::getConfig('capitalType');
+        $capitalType = $capitalTypeData['xhRecharge']['id'];
+        //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
+        $wxPayType = 0;
+        if (httpUtil::isMiniProgram()) {
+            $wxPayType = 1;
+        }
+        $attach = "couponId=0&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType;
+        //订单30分钟后过期
+        $now = time();
+        $expireTime = $now + 1800;
+
+        $wx = Yii::getAlias("@vendor/weixin");
+        require_once($wx . '/lib/WxPay.Api.php');
+        require_once($wx . '/example/WxPay.JsApiPay.php');
+        $input = new \WxPayUnifiedOrder();
+        $input->SetBody($name);
+        $input->SetOut_trade_no($orderSn);
+        $input->SetTotal_fee($totalFee * 100);
+        $input->SetTime_start(date("YmdHis", $now));
+        $input->SetAttach($attach);//将流水类型、代金劵等传给微信再回传
+        $input->SetTime_expire(date("YmdHis", $expireTime));
+        $input->SetNotify_url(Yii::$app->params['shopHost'] . '/notice/wx-callback/');
+        $input->SetTrade_type("JSAPI");
+
+        $merchantExtend = WxOpenClass::getWxInfo();
+        if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) {
+            $input->SetSub_openid($openId);
+        } else {
+            $input->SetOpenid($openId);
+        }
+
+        //强制使用小程序的AppId
+        $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
+
+        $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
+        $tools = new \JsApiPay();
+        $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
+        $newParams = json_decode($jsApiParameters, true);
+        util::success($newParams);
+    }
+
+    //续期成功 shish 2021.2.21
+    public function actionRenewSuccess()
+    {
+        $sj = $this->sj;
+        $deadline = date("Y-m-d H:i", strtotime($sj['deadline']));
+        util::success(['deadline' => $deadline]);
+    }
+
+}

+ 1 - 1
biz-ghs/merchant/models/Shop.php

@@ -7,7 +7,7 @@ class Shop extends Base
 
 	public static function tableName()
 	{
-		return 'xhGhsShop';
+		return 'xhShop';
 	}
 
 }

+ 1 - 1
biz-ghs/order/models/OrderItem.php

@@ -9,7 +9,7 @@ class OrderItem extends Base
 
     public static function tableName()
     {
-        return 'xhGhsOrderItem';
+        return 'xhOrderItem';
     }
 
 }

+ 50 - 42
biz-ghs/product/classes/ProductClass.php

@@ -5,9 +5,9 @@ namespace bizGhs\product\classes;
 
 use bizGhs\base\classes\BaseClass;
 use bizGhs\item\classes\ItemClass;
-use common\components\business;
 use common\components\util;
 use common\services\xhItemService;
+use Yii;
 
 class ProductClass extends BaseClass
 {
@@ -33,12 +33,17 @@ class ProductClass extends BaseClass
         //取得itemIds
         $itemIds = array_column($list, 'itemId');
         //获取相应的图片,名称,py
-        $where = ['id' =>  ['in', $itemIds]];
+        $where = ['id' => ['in', $itemIds]];
         $data = xhItemService::getAllByCondition($where, null, '*');
         if (!empty($data)) {
             $data = array_column($data, NULL, 'id');
             foreach ($list as $k => $v) {
-                $cover = self::groupImg($data[$v['itemId']]['cover']);
+                if (isset($data[$v['itemId']]['cover']) && !empty($data[$v['itemId']]['cover'])) {
+                    $cover = self::groupImg($data[$v['itemId']]['cover']);
+                } else {
+                    //没有图片时取默认图片 shish 2021.2.18
+                    $cover = Yii::$app->params['imgHost'] . '/hhb_small.png';
+                }
                 $unitNum = $data[$v['itemId']]['unitNum'] ?? 0;
                 $stockInfo = self::formatStock($v['stock'], $unitNum);
                 $list[$k]['cover'] = $cover;
@@ -73,7 +78,7 @@ class ProductClass extends BaseClass
     public static function formatStock($stock, $unitNum)
     {
         $pn = true; //正数
-        if($stock < 0 ){
+        if ($stock < 0) {
             $pn = false;
             $stock = abs($stock);
         }
@@ -81,14 +86,14 @@ class ProductClass extends BaseClass
         $stockArr = explode('.', $stock);
         $smallNum = 0; //支
         if (count($stockArr) === 2) {
-            $smallNum = bcmul(($stock-$bigNum),$unitNum);
+            $smallNum = bcmul(($stock - $bigNum), $unitNum);
         }
-        if(!$pn){
-            $bigNum *=-1;
-            $smallNum *=-1;
+        if (!$pn) {
+            $bigNum *= -1;
+            $smallNum *= -1;
         }
         return [
-            'bigNum'   => $bigNum,
+            'bigNum' => $bigNum,
             'smallNum' => $smallNum,
         ];
     }
@@ -161,6 +166,7 @@ class ProductClass extends BaseClass
 
 
     //todo 库存修改 加锁
+
     /**
      * 对商品ID 加库存
      * @param $productId  商品ID
@@ -223,6 +229,7 @@ class ProductClass extends BaseClass
 
 
     //计算价格
+
     /**
      * @param $productId  门店下的花材ID(xhGhsItemInfo 主键ID)
      * @param $bigNum  花材数量(扎)
@@ -281,24 +288,24 @@ class ProductClass extends BaseClass
     }
 
     //补全itemId (针对入库时 当前门店下无对应的花材 itemId)  linqh 2021.1.24
-    public static function complementProduct($merchantId,$shopId, $itemInfo)
+    public static function complementProduct($merchantId, $shopId, $itemInfo)
     {
-        $itemIds = array_column($itemInfo,"itemId");
-        $itemData = array_column($itemInfo,null,"itemId");
-        $productData = self::getGhsProductDataByItemIds($shopId,$itemIds);
+        $itemIds = array_column($itemInfo, "itemId");
+        $itemData = array_column($itemInfo, null, "itemId");
+        $productData = self::getGhsProductDataByItemIds($shopId, $itemIds);
 
-        if(count($productData) !== count($itemIds)){
-            $productDataItemIds = array_column($productData,'itemId');
+        if (count($productData) !== count($itemIds)) {
+            $productDataItemIds = array_column($productData, 'itemId');
             //取差集
-            $diffItemIds = array_diff($itemIds,$productDataItemIds);
-            if($diffItemIds){
+            $diffItemIds = array_diff($itemIds, $productDataItemIds);
+            if ($diffItemIds) {
                 //新增到product表,price = itemPrice (出库时的售价), stock=0
-                foreach ($diffItemIds as $v){
+                foreach ($diffItemIds as $v) {
                     $addData = [];
                     $addData['merchantId'] = $merchantId;
                     $addData['shopId'] = $shopId;
                     $addData['itemId'] = $v;
-                    $addData['price'] = $itemData[$v]['itemPrice']??0;
+                    $addData['price'] = $itemData[$v]['itemPrice'] ?? 0;
                     self::add($addData);
                 }
             }
@@ -345,38 +352,38 @@ class ProductClass extends BaseClass
     //订单退回库存
     public static function backStockByOrderItemInfo($orderItemInfo)
     {
-        foreach ($orderItemInfo as $v){
-            ProductClass::addStockByItemNum($v['productId'],$v['itemNum']);
+        foreach ($orderItemInfo as $v) {
+            ProductClass::addStockByItemNum($v['productId'], $v['itemNum']);
         }
     }
 
 
     //库存告警的itemIds (库存数量少于告警数量)  linqh 2021.1.26
-    public static function getItemIdsWarning($merchantId,$shopId)
+    public static function getItemIdsWarning($merchantId, $shopId)
     {
         //获取当前门店下的 itemId=>stock
-        $productData = ProductClass::getAllList("itemId,stock",['shopId'=>$shopId]);
+        $productData = ProductClass::getAllList("itemId,stock", ['shopId' => $shopId]);
         $productItemStock = [];
-        if($productData){
-            foreach ($productData as $v){
+        if ($productData) {
+            foreach ($productData as $v) {
                 $productItemStock[$v['itemId']] = $v['stock'];
             }
         }
 
         //获取merchantId 下 对应的itemId=>stockWaring
-        $itemData = ItemClass::getAllList("itemId,stockWarning",['merchantId'=>$merchantId]);
+        $itemData = ItemClass::getAllList("itemId,stockWarning", ['merchantId' => $merchantId]);
         $itemStockWaring = [];
-        if($itemData){
-            foreach ($itemData as $v){
+        if ($itemData) {
+            foreach ($itemData as $v) {
                 $itemStockWaring[$v['itemId']] = $v['stockWarning'];
             }
         }
 
         //取库存数量少于告警数量 的itemId
         $itemIds = [];
-        foreach ($productItemStock as $k=>$v){
-            $stockWaring = $itemStockWaring[$k]??0;
-            if($v < $stockWaring) {
+        foreach ($productItemStock as $k => $v) {
+            $stockWaring = $itemStockWaring[$k] ?? 0;
+            if ($v < $stockWaring) {
                 $itemIds[] = $k;
             }
         }
@@ -384,14 +391,15 @@ class ProductClass extends BaseClass
     }
 
     //获取当前门店下商品信息 linqh 2021.1.28
-    public static function getProductData($id,$shopId,$obj=false)
+    public static function getProductData($id, $shopId, $obj = false)
     {
-        return ProductClass::getByCondition(['id'=>$id,'shopId'=>$shopId],$obj);
+        return ProductClass::getByCondition(['id' => $id, 'shopId' => $shopId], $obj);
     }
 
     //修改价格 linqh 2021.1.28
-    public static function changePrice($id,$shopId,$price,$priceLabel)
+    public static function changePrice($id, $shopId, $price, $priceLabel)
     {
+
         $res =  ProductClass::updateByCondition(['id'=>$id,'shopId'=>$shopId],['price'=>$price,'priceLabel'=>$priceLabel]);
         return $res;
     }
@@ -402,26 +410,26 @@ class ProductClass extends BaseClass
     public static function computedPriceByItemInfo(array $itemInfo)
     {
         $data = [];
-        if(empty($itemInfo)){
+        if (empty($itemInfo)) {
             return $data;
         }
         $productIds = array_column($itemInfo, 'productId');
         $productData = ProductClass::getProductByIds($productIds);
         $productData = array_column($productData, NULL, 'id');
 
-        $itemIds =  array_column($productData,'itemId');
+        $itemIds = array_column($productData, 'itemId');
         $itemData = xhItemService::getByIds($itemIds);
         $itemData = array_column($itemData, NULL, 'id');
-        foreach ($itemInfo as $v){
+        foreach ($itemInfo as $v) {
             $productId = $v['productId'];
-            $itemId = $productData[$productId]['itemId']??0;
-            $unitNum =  $itemData[$itemId]['unitNum']??0;
+            $itemId = $productData[$productId]['itemId'] ?? 0;
+            $unitNum = $itemData[$itemId]['unitNum'] ?? 0;
             //大小数量合并多少扎
-            $itemNum = self::mergeItemNum($v['bigNum'],$v['smallNum'],$unitNum);
+            $itemNum = self::mergeItemNum($v['bigNum'], $v['smallNum'], $unitNum);
             //售卖价格
-            $itemPrice = $productData[$productId]['price']??0;
+            $itemPrice = $productData[$productId]['price'] ?? 0;
             //合计价格
-            $price = bcmul($itemNum,$itemPrice,2);
+            $price = bcmul($itemNum, $itemPrice, 2);
             $tmp = [];
             $tmp['productId'] = $productId;
             $tmp['price'] = $price;

+ 1 - 1
biz-ghs/shop/models/ShopAdmin.php

@@ -9,7 +9,7 @@ class ShopAdmin extends Base
 	
 	public static function tableName()
 	{
-		return 'xhGhsShopAdmin';
+		return 'xhShopAdmin';
 	}
 	
 }

+ 1 - 1
biz/goods/classes/GoodsClass.php

@@ -47,7 +47,7 @@ class GoodsClass extends BaseClass
             //免费配送范围
             $val['freeSendDist'] = 5;
             //多款式
-            $val['goodsStyleList'] = isset($val['goodsStyle']) && $val['goodsStyle'] == 1 ? GoodsStyleClass::getStyleList($id) : [];
+            $val['goodsStyleList'] = isset($val['goodsStyle']) && $val['goodsStyle'] == 1 ? array_values(GoodsStyleClass::getStyleList($id)) : [];
             $val['createDate'] = date("Y-m-d", strtotime($val['createTime']));
             $val['merchantName'] = '';
             //节日涨价

+ 12 - 0
biz/merchant/classes/ShopClass.php

@@ -105,4 +105,16 @@ class ShopClass extends BaseClass
         return \biz\admin\classes\AdminClass::getDetail($adminId);
     }
 
+    //增加余额 shish 2021.2.21
+    //$fix = false 余额使用时不需要指定在谁那边用
+    public static function addBalance($shop, $amount, $fix = false)
+    {
+        $shop->balance += $amount;
+        $shop->totalRecharge += $amount;
+        if ($fix) {
+            $shop->fixBalance += $amount;
+        }
+        $shop->save();
+    }
+
 }

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

@@ -11,6 +11,7 @@ use biz\stat\classes\StatOrderCountClass;
 use biz\stat\classes\StatOrderMonthClass;
 use biz\user\classes\UserClass;
 use common\components\miniUtil;
+use common\components\orderSn;
 use common\components\stringUtil;
 use common\services\xhOrderDayNumService;
 use common\services\xhOrderMonthNumService;
@@ -66,7 +67,7 @@ class OrderClass extends BaseClass
     {
         $date = date("Y-m-d H:i:s");
         $merchantId = $data['merchantId'];
-        $data['orderSn'] = stringUtil::generateOrderNo($merchantId, $data['userId']);
+        $data['orderSn'] = orderSn::getOrderSn();
         $data['payStatus'] = 0;
         $data['createTime'] = $date;
         $data['addTime'] = time();

+ 48 - 0
biz/recharge/classes/RechargeClass.php

@@ -0,0 +1,48 @@
+<?php
+
+namespace biz\recharge\classes;
+
+use biz\base\classes\BaseClass;
+use biz\merchant\classes\ShopClass;
+use common\components\noticeUtil;
+use common\components\orderSn;
+
+class RechargeClass extends BaseClass
+{
+
+    public static $baseFile = '\biz\recharge\models\Recharge';
+
+    const PAY_STATUS_UN_PAY = 1;
+    const PAY_STATUS_HAS_PAY = 2;
+
+    //充值记录 shish 2021.2.21
+    public static function getRechargeList($where)
+    {
+        $data = self::getList('*', $where, 'addTime DESC');
+        return $data;
+    }
+
+    //创建订单 shish 2021.2.21
+    public static function addOrder($data)
+    {
+        $data['orderSn'] = orderSn::getRechargeSn();
+        return self::add($data);
+    }
+
+    //处理充值流程 shish 2021.2.21
+    public static function complete($recharge)
+    {
+        $recharge->payStatus = self::PAY_STATUS_HAS_PAY;
+        $recharge->save();
+        $orderSn = $recharge->orderSn;
+        $shopId = $recharge->shopId;
+        $shop = ShopClass::getById($shopId, true);
+        if (empty($shop)) {
+            noticeUtil::push("充值支付回调通知,没有找到门店 orderSn:{$orderSn}");
+            return false;
+        }
+        $amount = $recharge->amount;
+        ShopClass::addBalance($shop, $amount);
+    }
+
+}

+ 12 - 0
biz/recharge/classes/RechargeSnClass.php

@@ -0,0 +1,12 @@
+<?php
+
+namespace biz\recharge\classes;
+
+use biz\base\classes\BaseClass;
+
+class RechargeSnClass extends BaseClass
+{
+
+    public static $baseFile = '\biz\recharge\models\RechargeSn';
+
+}

+ 15 - 0
biz/recharge/models/Recharge.php

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

+ 15 - 0
biz/recharge/models/RechargeSn.php

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

+ 12 - 0
biz/recharge/services/RechargeService.php

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

+ 1 - 0
common/components/configDict.php

@@ -97,6 +97,7 @@ class configDict
         "capitalType" => [//流水类型,充值支付回调时的订单类型
             'xhOrder' => ['id' => 0, 'name' => 'xhOrder'],
             'xhActiveOrder' => ['id' => 2, 'name' => 'xhActiveOrder'],
+            //充值
             'xhRecharge' => ['id' => 4, 'name' => 'xhRecharge'],
             //支付宝关联微信帐号,积分累加订单
             'xhUserUnite' => ['id' => 5, 'name' => 'xhUserUnite'],

+ 136 - 119
common/components/orderSn.php

@@ -3,6 +3,7 @@
 namespace common\components;
 
 use biz\purchase\classes\PurchaseClearSnClass;
+use biz\recharge\classes\RechargeSnClass;
 use bizGhs\check\classes\CheckSnClass;
 use bizGhs\order\classes\OrderSnClass;
 use bizGhs\order\classes\PurchaseSnClass;
@@ -12,124 +13,140 @@ use yii\imagine\Image;
 //订单号生成 shish 2021.1.19
 class orderSn
 {
-	
-	//供货商订单号生成 shish 2021.1.19
-	public static function getGhsOrderSn()
-	{
-		$prefix = 'XSD_CS';
-		if (getenv('YII_ENV', 'local') == 'production') {
-			$prefix = 'XSD';
-		}
-		$respond = OrderSnClass::add(['id' => null]);
-		$id = $respond['id'] ?? 0;
-		if (empty($id)) {
-			util::fail('订单号没有生成');
-		}
-		return $prefix . $id;
-	}
-	
-	//零售商订单号生成 shish 2021.1.19
-	public static function getOrderSn()
-	{
-		$prefix = 'KD_CS';
-		if (getenv('YII_ENV', 'local') == 'production') {
-			$prefix = 'KD';
-		}
-		$respond = \biz\order\classes\OrderSnClass::add(['id' => null]);
-		$id = $respond['id'] ?? 0;
-		if (empty($id)) {
-			util::fail('订单号没有生成');
-		}
-		return $prefix . $id;
-	}
-	
-	//供货商采购单号 shish 2021.1.19
-	public static function getGhsPurchaseSn()
-	{
-		$prefix = 'PH_CS';
-		if (getenv('YII_ENV', 'local') == 'production') {
-			$prefix = 'PH';
-		}
-		$respond = PurchaseSnClass::add(['id' => null]);
-		$id = $respond['id'] ?? 0;
-		if (empty($id)) {
-			util::fail('采购单号没有生成');
-		}
-		return $prefix . $id;
-	}
-	
-	//供货商盘点单号 shish 2021.1.19
-	public static function getGhsCheckSn()
-	{
-		$prefix = 'PD_CS';
-		if (getenv('YII_ENV', 'local') == 'production') {
-			$prefix = 'PD';
-		}
-		$respond = CheckSnClass::add(['id' => null]);
-		$id = $respond['id'] ?? 0;
-		if (empty($id)) {
-			util::fail('盘点单号没有生成');
-		}
-		return $prefix . $id;
-	}
-	
-	//零售商采购单号 shish 2021.1.19
-	public static function getPurchaseSn()
-	{
-		$prefix = 'CG_CS';
-		if (getenv('YII_ENV', 'local') == 'production') {
-			$prefix = 'CG';
-		}
-		$respond = \biz\purchase\classes\PurchaseSnClass::add(['id' => null]);
-		$id = $respond['id'] ?? 0;
-		if (empty($id)) {
-			util::fail('采购单号没有生成');
-		}
-		return $prefix . $id;
-	}
 
-	//零售商采购单号 shish 2021.1.19
-	public static function getPurchaseClearSn()
-	{
-		$prefix = 'PC_CS';
-		if (getenv('YII_ENV', 'local') == 'production') {
-			$prefix = 'PC';
-		}
-		$respond = PurchaseClearSnClass::add(['id' => null]);
-		$id = $respond['id'] ?? 0;
-		if (empty($id)) {
-			util::fail('单号没有生成');
-		}
-		return $prefix . $id;
-	}
+    //供货商订单号生成 shish 2021.1.19
+    public static function getGhsOrderSn()
+    {
+        $prefix = 'XSD_CS';
+        if (getenv('YII_ENV', 'local') == 'production') {
+            $prefix = 'XSD';
+        }
+        $respond = OrderSnClass::add(['id' => null]);
+        $id = $respond['id'] ?? 0;
+        if (empty($id)) {
+            util::fail('订单号没有生成');
+        }
+        return $prefix . $id;
+    }
 
-	//供货商入库订单号 linqh 2021.1.23
-	public static function getGhsStockInSn()
-	{
-		$prefix = 'RK_CS';
-		if (getenv('YII_ENV', 'local') == 'production') {
-			$prefix = 'RK';
-		}
-		$respond = \bizGhs\order\classes\StockInSnClass::add(['id' => null]);
-		$id = $respond['id'] ?? 0;
-		if (empty($id)) {
-			util::fail('入库单号没有生成');
-		}
-		return $prefix . $id;
-	}
-	
-	//供货商出库订单号 linqh 2021.1.23
-	public static function getGhsStockOutSn()
-	{
-		$prefix = 'CK_CS';
-		if (getenv('YII_ENV', 'local') == 'production') {
-			$prefix = 'CK';
-		}
-		$respond = \bizGhs\order\classes\StockOutSnClass::add(['id' => null]);
-		$id = $respond['id'] ?? 0;
-		if (empty($id)) {
-			util::fail('出库单号没有生成');
-		}
-		return $prefix . $id;
-	}
-}
+    //零售商订单号生成 shish 2021.1.19
+    public static function getOrderSn()
+    {
+        $prefix = 'KD_CS';
+        if (getenv('YII_ENV', 'local') == 'production') {
+            $prefix = 'KD';
+        }
+        $respond = \biz\order\classes\OrderSnClass::add(['id' => null]);
+        $id = $respond['id'] ?? 0;
+        if (empty($id)) {
+            util::fail('订单号没有生成');
+        }
+        return $prefix . $id;
+    }
+
+    //供货商采购单号 shish 2021.1.19
+    public static function getGhsPurchaseSn()
+    {
+        $prefix = 'PH_CS';
+        if (getenv('YII_ENV', 'local') == 'production') {
+            $prefix = 'PH';
+        }
+        $respond = PurchaseSnClass::add(['id' => null]);
+        $id = $respond['id'] ?? 0;
+        if (empty($id)) {
+            util::fail('采购单号没有生成');
+        }
+        return $prefix . $id;
+    }
+
+    //供货商盘点单号 shish 2021.1.19
+    public static function getGhsCheckSn()
+    {
+        $prefix = 'PD_CS';
+        if (getenv('YII_ENV', 'local') == 'production') {
+            $prefix = 'PD';
+        }
+        $respond = CheckSnClass::add(['id' => null]);
+        $id = $respond['id'] ?? 0;
+        if (empty($id)) {
+            util::fail('盘点单号没有生成');
+        }
+        return $prefix . $id;
+    }
+
+    //零售商采购单号 shish 2021.1.19
+    public static function getPurchaseSn()
+    {
+        $prefix = 'CG_CS';
+        if (getenv('YII_ENV', 'local') == 'production') {
+            $prefix = 'CG';
+        }
+        $respond = \biz\purchase\classes\PurchaseSnClass::add(['id' => null]);
+        $id = $respond['id'] ?? 0;
+        if (empty($id)) {
+            util::fail('采购单号没有生成');
+        }
+        return $prefix . $id;
+    }
+
+    //零售商采购单号 shish 2021.1.19
+    public static function getPurchaseClearSn()
+    {
+        $prefix = 'PC_CS';
+        if (getenv('YII_ENV', 'local') == 'production') {
+            $prefix = 'PC';
+        }
+        $respond = PurchaseClearSnClass::add(['id' => null]);
+        $id = $respond['id'] ?? 0;
+        if (empty($id)) {
+            util::fail('单号没有生成');
+        }
+        return $prefix . $id;
+    }
+
+    //供货商入库订单号 linqh 2021.1.23
+    public static function getGhsStockInSn()
+    {
+        $prefix = 'RK_CS';
+        if (getenv('YII_ENV', 'local') == 'production') {
+            $prefix = 'RK';
+        }
+        $respond = \bizGhs\order\classes\StockInSnClass::add(['id' => null]);
+        $id = $respond['id'] ?? 0;
+        if (empty($id)) {
+            util::fail('入库单号没有生成');
+        }
+        return $prefix . $id;
+    }
+
+    //供货商出库订单号 linqh 2021.1.23
+    public static function getGhsStockOutSn()
+    {
+        $prefix = 'CK_CS';
+        if (getenv('YII_ENV', 'local') == 'production') {
+            $prefix = 'CK';
+        }
+        $respond = \bizGhs\order\classes\StockOutSnClass::add(['id' => null]);
+        $id = $respond['id'] ?? 0;
+        if (empty($id)) {
+            util::fail('出库单号没有生成');
+        }
+        return $prefix . $id;
+    }
+
+    //充值单号 shish 2021.2.20
+    public static function getRechargeSn()
+    {
+        $prefix = 'CZ_CS';
+        if (getenv('YII_ENV', 'local') == 'production') {
+            $prefix = 'CZ';
+        }
+        $respond = RechargeSnClass::add(['id' => null]);
+        $id = $respond['id'] ?? 0;
+        if (empty($id)) {
+            util::fail('充值单号没有生成');
+        }
+        return $prefix . $id;
+    }
+
+}

+ 33 - 3
common/services/xhPayToolService.php

@@ -7,9 +7,11 @@ use biz\merchant\classes\ShopClass;
 use biz\order\classes\OrderClass;
 use biz\order\classes\OrderSendClass;
 use biz\order\services\OrderService;
+use biz\recharge\classes\RechargeClass;
 use biz\user\classes\UserClass;
 use biz\user\services\UserAssetService;
 use biz\user\services\UserService;
+use common\components\noticeUtil;
 use common\components\stringUtil;
 use common\components\util;
 use Yii;
@@ -57,9 +59,34 @@ class xhPayToolService
         return self::basePay($callbackParams, $orderSn, $totalFee, $capitalType, $couponId, $payWay);
     }
 
-    public static function ghsOrderPay($callbackParams, $orderSn, $totalFee, $capitalType, $couponId, $payWay, $alipayParams)
+    public static function ghsOrderPay($transaction, $callbackParams, $orderSn, $totalFee, $capitalType, $couponId, $payWay, $alipayParams)
+    {
+        $transaction->commit();
+    }
+
+    //充值回调处理 shish 2021.2.21
+    public static function recharge($transaction, $callbackParams, $orderSn, $totalFee, $capitalType, $couponId, $payWay, $alipayParams)
     {
 
+        $recharge = RechargeClass::getByCondition(['orderSn' => $orderSn],true);
+        if (empty($recharge)) {
+            noticeUtil::push('充值付款成功,收到回调,但没有找到充值记录,orderSn:' . $orderSn, '15280215347');
+            return ['amount' => $totalFee];
+        }
+        if ($totalFee != $recharge->amount) {
+            noticeUtil::push("充值付款成功,收到回调,但金额不一致 {$totalFee} {$recharge->amount},orderSn:" . $orderSn, '15280215347');
+            return ['amount' => $totalFee];
+        }
+        if($recharge->payStatus == RechargeClass::PAY_STATUS_HAS_PAY){
+            noticeUtil::push("充值付款成功,收到回调,但订单是已经支付过了,orderSn:" . $orderSn, '15280215347');
+            return ['amount' => $totalFee];
+        }
+
+        //处理充值成功的流程
+        RechargeClass::complete($recharge);
+
+        $transaction->commit();
+        return ['amount' => $totalFee];
     }
 
     /**
@@ -75,6 +102,10 @@ class xhPayToolService
             $capitalTypeList = configDict::getConfig('capitalType');//流水类型列表
             $order = [];
             switch ($capitalType) {
+                case $capitalTypeList['xhRecharge']['id']:
+                    return self::recharge($transaction, $callbackParams, $orderSn, $totalFee, $capitalType, $couponId, $payWay, $alipayParams);
+                    Yii::$app->end();
+                    break;
                 case $capitalTypeList['xhOrder']['id']:
                     //购买商品
                     $order = xhOrderService::getByOrderSn($orderSn);
@@ -88,10 +119,9 @@ class xhPayToolService
                     break;
                 case $capitalTypeList['xhGhsOrder']['id']:
                     //供货商订单
-                    return self::ghsOrderPay($callbackParams, $orderSn, $totalFee, $capitalType, $couponId, $payWay, $alipayParams);
+                    return self::ghsOrderPay($transaction, $callbackParams, $orderSn, $totalFee, $capitalType, $couponId, $payWay, $alipayParams);
                     Yii::$app->end();
                     break;
-
                 default:
                     Yii::warning('获取订单信息失败,回调传过来的 capitalType 不符合要求,capitalType:' . $capitalType . ' orderSn:' . $orderSn);
                     util::fail('订单流水类型不明确');

+ 66 - 1
sql.sql

@@ -1139,4 +1139,69 @@ ALTER TABLE xhItemClass ADD `group` TINYINT NOT NULL DEFAULT 0 COMMENT ' 所属
 ALTER TABLE xhItem ADD classId INT NOT NULL DEFAULT 0 COMMENT '平台分类id' AFTER `cover`;
 ALTER TABLE `xhItem`
 MODIFY COLUMN `addTime`  TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',
-MODIFY COLUMN `updateTime`  TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间';
+MODIFY COLUMN `updateTime`  TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间';
+ALTER TABLE xhOrderGoods ADD orderSn CHAR(20) NOT NULL DEFAULT '' COMMENT '' AFTER `orderId`;
+ALTER TABLE xhOrder ADD packingFee DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '包装费' AFTER `anonymity`;
+ALTER TABLE xhOrder ADD orderType TINYINT NOT NULL DEFAULT 1 COMMENT '1成品订单 2花材订单' AFTER `goodsNum`;
+DROP TABLE IF EXISTS `xhOrderItem`;
+CREATE TABLE IF NOT EXISTS `xhOrderItem`(
+  id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+  `orderSn` CHAR(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '订单编号',
+  `itemId` INT(11) NOT NULL DEFAULT '0' COMMENT '商家花材id',
+  `productId` INT(11) NOT NULL DEFAULT '0' COMMENT '商家商品id',
+  `smallUnit` SMALLINT(6) NOT NULL DEFAULT '2' COMMENT '小单位,支,个,条',
+  `bigUnit` SMALLINT(6) NOT NULL DEFAULT '1' COMMENT '大单位,扎,箱,包',
+  `price` DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '总价格',
+  `num` DECIMAL(10,2) NOT NULL DEFAULT '0.00' COMMENT '总数量',
+  `bigNum` SMALLINT(6) NOT NULL DEFAULT '0' COMMENT '大单位数量,扎,包,箱',
+  `smallNum` SMALLINT(6) NOT NULL DEFAULT '0' COMMENT '小单位数量,支,个,条',
+  `ratio` TINYINT(4) NOT NULL DEFAULT '0' COMMENT '大小单位转换比例,1扎多少支,1包多少支'
+)COMMENT='零售订单的花材';
+DROP TABLE IF EXISTS `xhRecharge`;
+CREATE TABLE IF NOT EXISTS `xhRecharge`(
+id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+`payWay` TINYINT(4) NOT NULL DEFAULT '0' COMMENT '支付方式 0微信 1支付宝 2余额',
+`payCode` VARCHAR(1000) NOT NULL DEFAULT '' COMMENT '支付返回号',
+sjId INT NOT NULL DEFAULT 0 COMMENT '商家id',
+sjStyle TINYINT NOT NULL DEFAULT 1 COMMENT '商家类型 1零售 2供货',
+shopId INT NOT NULL DEFAULT 0 COMMENT '门店id',
+`amount` DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '金额',
+`balance` DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '余额',
+`totalRecharge` DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '门店累计充值'
+)COMMENT='门店充值记录';
+DROP TABLE IF EXISTS `xhRechargeSn`;
+CREATE TABLE IF NOT EXISTS `xhRechargeSn` (
+  `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
+  PRIMARY KEY (`id`)
+) AUTO_INCREMENT=18213721 COMMENT='充值订单号';
+ALTER TABLE xhRecharge ADD orderSn CHAR(20) NOT NULL DEFAULT '' COMMENT '订单编号' AFTER `id`;
+ALTER TABLE `xhRecharge` ADD `modPrice` TINYINT(4) NOT NULL DEFAULT '1' COMMENT '0不能修改价格 1可以修改' AFTER `orderSn`;
+ALTER TABLE `xhRecharge` ADD `deadline` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '订单有效时间' AFTER `modPrice`;
+ALTER TABLE xhRecharge ADD payStatus TINYINT NOT NULL DEFAULT 1 COMMENT '1待付款 2已付款' AFTER `totalRecharge`;
+DROP TABLE `xhGhsShopAdmin`;
+DROP TABLE `xhGhsShop`;
+ALTER TABLE `xhShop` MODIFY `createTime` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT '创建时间';
+ALTER TABLE xhShop ADD balance DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '余额' AFTER `adminId`;
+ALTER TABLE xhShop ADD fixBalance DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '只能向推荐人消费的余额,指定余额' AFTER `balance`;
+ALTER TABLE xhMerchant ADD parentId INT NOT NULL DEFAULT 0 COMMENT '父id' AFTER `adminId`;
+ALTER TABLE `xhRecharge` ADD INDEX `orderSn` (`orderSn`);
+DROP TABLE IF EXISTS `xhRechargeRecord`;
+CREATE TABLE IF NOT EXISTS `xhRechargeRecord`(
+id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+sjId INT NOT NULL DEFAULT 0 COMMENT '商家id',
+shopId INT NOT NULL DEFAULT 0 COMMENT '门店id',
+`amount` DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '充值金额',
+`totalRecharge` DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '充值金额',
+`remark` VARCHAR(1000) NOT NULL DEFAULT '' COMMENT '备注',
+`addTime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间',
+`updateTime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间'
+)COMMENT='充值记录';
+ALTER TABLE `xhShop` DROP COLUMN `createTime`;
+ALTER TABLE `xhShop` DROP COLUMN `addTime`;
+ALTER TABLE `xhShop` ADD `addTime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间' AFTER `status`;
+ALTER TABLE xhRechargeRecord RENAME TO xhRechargeLog;
+ALTER TABLE xhShop ADD totalRecharge DECIMAL(9,2) NOT NULL DEFAULT '0.00' COMMENT '累计充值' AFTER `fixBalance`;
+ALTER TABLE xhRecharge ADD `addTime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '添加时间' AFTER `payStatus`;
+ALTER TABLE xhRecharge ADD `updateTime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间' AFTER `addTime`;
+ALTER TABLE xhRecharge ADD remark VARCHAR(1000) NOT NULL DEFAULT '' COMMENT '' AFTER `payStatus`;
+DROP TABLE IF EXISTS `xhRechargeLog`;