| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818 |
- <?php
- namespace mall\controllers;
- use biz\product\classes\ProductClass;
- use bizHd\custom\classes\HdClass;
- use bizHd\wx\classes\WxOpenClass;
- use bizMall\custom\classes\CustomClass;
- use bizMall\goods\classes\GoodsClass;
- use bizMall\order\classes\OrderClass;
- use bizMall\order\classes\OrderForwardClass;
- use bizMall\order\classes\OrderGoodsClass;
- use bizMall\order\classes\OrderItemClass;
- use bizMall\order\services\OrderService;
- use bizMall\promote\services\CouponService;
- use bizMall\saas\services\RegionService;
- use bizMall\shop\classes\ShopExtClass;
- use bizMall\user\services\UserService;
- use common\components\dateUtil;
- use common\components\dict;
- use common\components\httpUtil;
- use common\components\noticeUtil;
- use common\components\orderSn;
- use common\components\stringUtil;
- use common\services\xhPayToolService;
- use Yii;
- use common\components\util;
- use common\components\lakala\Lakala;
- class OrderController extends BaseController
- {
- //二维码收款使用
- public $guestAccess = ['order-relate', 'fast-pay'];
- //记账单列表 ssh 20250627
- public function actionDebtList()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $where = [];
- $where['userId'] = $this->userId;
- if (!empty($id)) {
- $hd = \bizMall\hd\classes\HdClass::getById($id, true);
- if (empty($hd)) {
- util::fail('无效的花店');
- }
- $where['hdId'] = $id;
- }
- $where['debt'] = 1;
- $searchTime = $get['searchTime'] ?? '';
- if (!empty($searchTime)) {
- $startTime = $get['startTime'] ?? '';
- $endTime = $get['endTime'] ?? '';
- $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
- $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
- }
- $respond = OrderClass::getDebtList($where);
- util::success($respond);
- }
- //计算运费,请搜索关键词calc_freight,二个方法要合一起 ssh 20221014
- public function actionFreight()
- {
- $get = Yii::$app->request->get();
- $shop = $this->shop;
- $shopLat = isset($shop->lat) ? $shop->lat : '';
- $shopLong = isset($shop->long) ? $shop->long : '';
- if (empty($shopLat) || empty($shopLong)) {
- util::success(['distance' => 0, 'showDistance' => 0, 'fee' => 0]);
- }
- $userLat = $get['lat'] ?? '';
- $userLong = $get['long'] ?? '';
- if (empty($userLat) || empty($userLong)) {
- util::success(['distance' => 0, 'showDistance' => 0, 'fee' => 0]);
- }
- $weight = $get['weight'] ?? 0;
- if (empty($weight)) {
- util::success(['distance' => 0, 'showDistance' => 0, 'fee' => 0]);
- }
- $respond = OrderClass::getDistanceFee($userLat, $userLong, $shopLat, $shopLong, $weight);
- util::success($respond);
- }
- //购买花材 ssh 20220511
- public function actionBuyItem()
- {
- $post = Yii::$app->request->post();
- $post['sjId'] = $this->sjId;
- $post['shopId'] = $this->shopId;
- $post['payWay'] = $this->isWx == true ? 0 : 1;
- $post['mainId'] = $this->mainId ?? 0;
- $post['userId'] = $this->userId ?? 0;
- //普莲花艺、叶上花、丰行、小武鲜花、九江云朵、源花汇、紫荆不能在花卉宝下单,多处要同步修改,关键词ls_mall_not_open
- $mainId = $this->mainId;
- if (getenv('YII_ENV') == 'production') {
- if (in_array($mainId, [40057, 7779, 42940, 26374, 10536, 65381])) {
- util::fail('暂时无法访问');
- }
- } else {
- if (in_array($mainId, [0, 1])) {
- util::fail('暂时无法访问');
- }
- }
- $hdId = $post['hdId'] ?? 0;
- $hd = HdClass::getById($hdId, true);
- if (empty($hd)) {
- util::fail('没有找到花店');
- }
- if ($hd->shopId != $this->shopId) {
- util::fail('不是你的花店');
- }
- $post['hdName'] = $hd->name ?? '';
- $customId = $hd->customId ?? 0;
- $custom = CustomClass::getById($customId, true);
- if (empty($custom)) {
- util::fail('没有找到客户');
- }
- $customName = $custom->name ?? '';
- $post['customId'] = $customId;
- $post['customName'] = $customName;
- $post['customNamePy'] = stringUtil::py($customName);
- $now = time();
- //订单30分钟后过期
- $expireTime = $now + 1800;
- $post['deadline'] = $expireTime;
- //商城
- $post['fromType'] = dict::getDict('fromType', 'mall');
- $productJson = $post['product'] ?? '';
- if (empty($productJson) && empty($groupId)) {
- util::fail('请选择商品');
- }
- $productList = json_decode($productJson, true);
- if (empty($productList)) {
- util::fail('请选择商品');
- }
- $ids = array_unique(array_filter(array_column($productList, 'productId')));
- $productInfoList = productClass::getByIds($ids, null, 'id');
- if (!empty($productInfoList)) {
- $presellData = [];
- $nowTime = strtotime(date("Y-m-d"));
- foreach ($productInfoList as $currentInfo) {
- if (isset($currentInfo['mainId']) == false || $currentInfo['mainId'] != $this->mainId) {
- util::fail('只能选择同一家的商品哦');
- }
- $currentName = $currentInfo['name'] ?? '';
- $presell = $currentInfo['presell'] ?? 0;
- $presellData[] = $presell;
- if ($presell == 1) {
- if (isset($post['reachDate']) == false || empty($post['reachDate'])) {
- util::fail('请选择配送或取货日期');
- }
- $sendTimeWant = $post['reachDate'];
- if (strtotime($sendTimeWant) < $nowTime) {
- util::fail('不能选择过去时间');
- }
- $hasDateStr = $currentInfo['presellDate'] ?? [];
- $hasDate = explode(',', trim($hasDateStr));
- if (empty($hasDate)) {
- util::fail('预售日期有问题,请提醒门店');
- }
- if (in_array(strtotime($sendTimeWant), $hasDate) == false) {
- util::fail("有预售花材在{$sendTimeWant}没到货");
- }
- $post['presell'] = 1;
- }
- }
- if (count($productInfoList) != count($ids)) {
- util::fail('存在无效商品');
- }
- $presellData = array_unique($presellData);
- if (count($presellData) > 1) {
- util::fail('预售和非预售花材不能一起下单');
- }
- } else {
- util::fail('花材不存在');
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $post['product'] = $productList;
- $orderValidTime = getenv('ORDER_VALID_TIME') == false ? 600 : getenv('ORDER_VALID_TIME');
- $post['deadline'] = time() + $orderValidTime;
- $post['reachDate'] = isset($post['reachDate']) && !empty($post['reachDate']) ? $post['reachDate'] : date("Y-m-d");
- $post['needPrint'] = dict::getDict('needPrint', 'need');
- $user = $this->user;
- $post['bookMobile'] = $user->mobile ?? '';
- $post['bookName'] = $user->name ?? '';
- $return = OrderService::createOrder($post, $custom);
- if (isset($return->shopId)) {
- if ($return->shopId == 7610) {
- if ($return->actPrice < 200) {
- if ($return->sendType == 0) {
- util::fail('满200元支持送货上门');
- }
- }
- }
- }
- if ($return->sendType == 2) {
- if (in_array($return->shopId, [2, 726, 1490, 13626, 7856, 7688])) {
- util::fail('暂时不能使用跑腿');
- }
- }
- $transaction->commit();
- $orderSn = $return->orderSn ?? '';
- $orderPrice = $return->orderPrice ?? 0;
- $id = $return->id ?? 0;
- $getPayType = dict::getDict('getPayType');
- util::success(['orderSn' => $orderSn, 'totalPrice' => $orderPrice, 'couponId' => 0, 'id' => $id, 'getPayType' => $getPayType]);
- } catch (\Exception $e) {
- $transaction->rollBack();
- Yii::error("失败原因:" . $e->getMessage());
- util::fail('下单失败');
- }
- }
- //商城下单操作 ssh 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;
- $sendType = $post['sendType'] ?? dict::getDict('sendType', 'thirdSend');
- if (empty($goodsId)) {
- util::fail('请选择商品');
- }
- $goodsInfo = GoodsClass::getGoodsInfo($goodsId);
- if (empty($goodsInfo)) {
- util::fail('没有找到商品');
- }
- $stock = $goodsInfo['stock'] && is_numeric($goodsInfo['stock']) ? $goodsInfo['stock'] : 0;
- $stockSet = $goodsInfo['stockSet'] && is_numeric($goodsInfo['stockSet']) ? $goodsInfo['stockSet'] : 0;
- if ($stock <= 0 && $stockSet == 0) {
- util::fail('库存不足');
- }
- //事务处理
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $custom = CustomClass::getByCondition(['shopId' => $this->shopId, 'userId' => $this->userId], true);
- $customId = $custom->id ?? 0;
- if (!empty($custom)) {
- $post['customId'] = $customId;
- $customName = $custom->name ?? '';
- $post['customName'] = $customName;
- $post['customNamePy'] = stringUtil::py($customName);
- $hdId = $custom->hdId ?? 0;
- $hd = HdClass::getById($hdId, true);
- if (!empty($hd)) {
- $post['hdId'] = $hd->id ?? 0;
- $post['hdName'] = $hd->name ?? '';
- }
- }
- $user = isset($this->user->attributes) ? $this->user->attributes : [];
- $post['bookName'] = isset($user['userName']) ? $user['userName'] : '';
- $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;
- //计算运费
- $sendDistance = 0;
- $sendCost = 0;
- $shop = $this->shop;
- if ($sendType == dict::getDict('sendType', 'thirdSend')) {
- $lat = $post['lat'] ?? '';
- $lng = $post['long'] ?? '';
- if (empty($lat) || empty($lng)) {
- util::fail('请填写收花地址哦');
- }
- $address = $post['address'] ?? '';
- $floor = $post['floor'] ?? '';
- $fullAddress = $address . $floor;
- $post['fullAddress'] = $fullAddress;
- $shopLat = $shop->lat ?? '';
- $shopLong = $shop->long ?? '';
- if (empty($shopLat) || empty($shopLong)) {
- //util::fail('请完成门店地址');
- }
- //花束重量默认1.5
- $weight = 1.5;
- $disRespond = OrderClass::getDistanceFee($lat, $lng, $shopLat, $shopLong, $weight);
- $sendCost = $disRespond['fee'] ?? 0;
- $sendDistance = $disRespond['distance'] ?? 0;
- }
- $post['sendDistance'] = $sendDistance;
- $post['sendCost'] = $sendCost;
- $post['sjId'] = $this->sjId;
- $post['shopId'] = $this->shopId;
- $mainId = $this->mainId;
- $post['mainId'] = $mainId;
- $post['userId'] = $this->userId;
- //计算总金额
- $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);
- //非门店订单
- $post['store'] = 0;
- //来源 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->userId]);
- $actPrice = $discountData['price'];
- $post['discountType'] = $discountData['discountType'];
- $post['discountAmount'] = $discountData['discountAmount'];
- //非自取订单考虑配送时间
- $post['reachDate'] = isset($post['reachDate']) && !empty($post['reachDate']) ? $post['reachDate'] : date("Y-m-d");
- $sendType = $post['sendType'] ?? 0;
- if ($sendType != 1) {
- if (isset($post['reachPeriod']) == false || empty($post['reachPeriod'])) {
- util::fail('请选择配送时间');
- }
- $post['reachTime'] = strtotime($post['reachDate'] . ' ' . $post['reachPeriod']);
- }
- $now = time();
- $expireTime = $now + 1800;//订单30分钟后过期
- $post['deadline'] = $expireTime;
- $orderSn = orderSn::getOrderSn();
- $post['orderSn'] = $orderSn;
- $post['fromType'] = dict::getDict('fromType', 'mall');
- $post['prePrice'] = $prePrice;
- $post['orderPrice'] = $actPrice;
- $post['actPrice'] = $actPrice;
- $post['realPrice'] = $actPrice;
- $post['mainPay'] = $actPrice;
- $post['cash'] = 0;
- $post['mainId'] = $mainId;
- $post['needPrint'] = dict::getDict('needPrint', 'need');
- $order = OrderClass::addOrder($post);
- $orderId = $order['id'];
- $orderSn = $order['orderSn'];
- $currentCover = isset($goodsInfo['shortImgList']) && !empty($goodsInfo['shortImgList']) ? current($goodsInfo['shortImgList']) : '';
- $flower = $goodsInfo['flower'] ?? 0;
- $price = bcmul($goodsNum, $unitPrice, 2);
- $data = [
- 'orderId' => $orderId,
- 'goodsId' => $goodsId,
- 'flower' => $flower,
- 'userId' => $this->userId,
- 'sjId' => $this->sjId,
- 'mainId' => $mainId,
- 'name' => $goodsInfo['name'] ?? '',
- 'cover' => $currentCover,
- 'unitPrice' => $unitPrice,
- 'num' => $goodsNum,
- 'orderSn' => $orderSn,
- 'price' => $price,
- 'createTime' => date("Y-m-d H:i:s"),
- ];
- OrderGoodsClass::addData($data);
- $transaction->commit();
- util::success(['orderSn' => $orderSn, 'totalPrice' => $actPrice, 'couponId' => $couponId, 'id' => $orderId]);
- } catch (Exception $e) {
- $transaction->rollBack();
- Yii::info("失败原因:" . $e->getMessage());
- util::fail('下单失败');
- }
- }
- //下单要用到的相关信息 ssh 2019.12.6
- public function actionOrderRelate()
- {
- $regionTree = RegionService::tree();
- //门店名称
- $shop = isset($this->shop) && !empty($this->shop) ? $this->shop->attributes : [];
- $sjName = $shop['merchantName'] ?? '';
- $shopName = $shop['shopName'] ?? '';
- $default = $shop['default'] ?? 0;
- $shop['showName'] = $default == 1 && $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
- $freight = ['first' => 5, 'add' => 2];
- $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
- $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'thirdMapKey' => $mapKey, 'merchant' => $shop];
- util::success($out);
- }
- //余额支付 ssh 20250410
- public function actionBalancePay()
- {
- $post = Yii::$app->request->post();
- $orderSn = $post['orderSn'] ?? '';
- //避免重复提交
- util::checkRepeatCommit($orderSn, 10);
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $order = OrderClass::getByCondition(['orderSn' => $orderSn], true);
- if (empty($order)) {
- util::fail('没有找到订单');
- }
- if ($order->shopId != $this->shopId) {
- util::fail('不是你的订单');
- }
- $payWay = dict::getDict('payWay', 'balancePay');
- \bizHd\order\classes\OrderClass::payAfter($order, $payWay);
- $transaction->commit();
- util::complete('支付成功');
- } catch (\Exception $e) {
- $transaction->rollBack();
- Yii::error("支付原因:" . $e->getMessage());
- util::fail('支付失败');
- }
- }
- //获取商城下单要用的微信支付和小程序支付参数 ssh 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);
- $name = !empty($order['orderName']) ? $order['orderName'] : '购买花材';
- $shop = $this->shop;
- if (empty($shop)) {
- util::fail('没有找到门店');
- }
- if (!empty($shop->shopName)) {
- $name .= '(' . $shop->shopName . ')';
- }
- $totalFee = $order['mainPay'];
- $openId = '';
- if (!empty($post['miniOpenId'])) {
- $openId = $post['miniOpenId'];
- //noticeUtil::push('散客买花时,通过前端获取了openId:' . $openId, '15280215347');
- }
- if (empty($openId)) {
- if (isset($this->user['miniOpenId']) && !empty($this->user['miniOpenId'])) {
- $openId = $this->user['miniOpenId'];
- //noticeUtil::push('散客买花时,通过数据库获取了openId:' . $openId, '15280215347');
- }
- }
- if (empty($openId)) {
- util::fail('没有找到openId');
- }
- $now = time();
- $expireTime = $now + 1800;
- $updateData = [];
- if (isset($order['modPrice']) && $order['modPrice'] == 0) {
- $oldOrderSn = $orderSn;
- //老单号需要关单,否则有付款成功的风险,老单号关闭成功了,才能生成新单号
- $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
- $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
- $params = [
- 'appid' => 'OP00002119',
- 'serial_no' => '018b08cfddbd',
- 'merchant_no' => $shop->lklSjNo,
- 'term_no' => $shop->lklScanTermNo,
- 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
- 'lklCertificatePath' => $lklCertificatePath,
- ];
- $laResource = new Lakala($params);
- $closeParams = [
- 'orderSn' => $oldOrderSn,
- ];
- $response = $laResource->close($closeParams);
- if (!isset($response['code']) || $response['code'] != 'BBS00000') {
- $msg = $response['msg'] ?? '';
- $lklSjNo = $shop->lklSjNo ?? '';
- noticeUtil::push('重点注意,散客买花更换单号没有成功,单号:' . $oldOrderSn . ',关单没有成功,' . $msg . '。商户号:' . $lklSjNo, '15280215347');
- util::fail('出错了哦,请重新下一单');
- }
- $orderSn = orderSn::getOrderSn();
- $updateData['orderSn'] = $orderSn;
- OrderItemClass::updateByCondition(['orderSn' => $oldOrderSn], ['orderSn' => $orderSn]);
- } else {
- //已请求的不能再修改价格
- $updateData['modPrice'] = 0;
- }
- if (empty($order['deadline'])) {
- $updateData['deadline'] = $expireTime;
- }
- if (!empty($updateData)) {
- OrderService::updateById($orderId, $updateData);
- }
- $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
- $sjExtend = WxOpenClass::getMallWxInfo();
- $shop = $this->shop;
- $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
- $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
- $params = [
- 'appid' => 'OP00002119',
- 'serial_no' => '018b08cfddbd',
- 'merchant_no' => $shop->lklSjNo,
- 'term_no' => $shop->lklScanTermNo,
- 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
- 'lklCertificatePath' => $lklCertificatePath,
- ];
- $laResource = new Lakala($params);
- $notifyUrl = Yii::$app->params['mallHost'] . "/notice/pay-callback";
- $wxParams = [
- 'orderSn' => $orderSn,
- 'amount' => $totalFee,
- 'capitalType' => $capitalType,
- 'notifyUrl' => $notifyUrl,
- 'wxAppId' => $sjExtend['miniAppId'],
- 'openId' => $openId,
- 'subject' => $name,
- 'couponId' => $couponId,
- ];
- $response = $laResource->driveWxPay($wxParams);
- if (!isset($response['code']) || $response['code'] != 'BBS00000') {
- $errMsg = $response['msg'] ?? '';
- noticeUtil::push($errMsg, '15280215347');
- util::fail('支付失败');
- }
- $newParams = isset($response['resp_data']['acc_resp_fields']) ? $response['resp_data']['acc_resp_fields'] : [];
- $appId = $newParams['app_id'] ?? '';
- $nonceStr = $newParams['nonce_str'] ?? '';
- $paySign = $newParams['pay_sign'] ?? '';
- $package = $newParams['package'] ?? '';
- $signType = $newParams['sign_type'] ?? '';
- $timeStamp = $newParams['time_stamp'] ?? '';
- $new = [
- 'id' => $orderId,
- 'appId' => $appId,
- 'nonceStr' => $nonceStr,
- 'paySign' => $paySign,
- 'package' => $package,
- 'signType' => $signType,
- 'timeStamp' => $timeStamp,
- 'orderSn' => $orderSn,
- ];
- util::success($new);
- }
- //快捷付款订单
- public function actionFastPay()
- {
- ini_set('date.timezone', 'Asia/Shanghai');
- $post = Yii::$app->request->post();
- $payWay = isset($post['payWay']) ? $post['payWay'] : 0;
- $shopId = $this->shopId;
- $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true);
- $gatheringItem = !empty($ext) ? $ext->gatheringItem : 0;
- if (empty($gatheringItem)) {
- util::fail('请设置付款用的商品');
- }
- $post['shopId'] = $shopId;
- $post['mainId'] = $this->mainId;
- $post['sjId'] = $this->sjId;
- $post['store'] = 0;
- $post['customId'] = $this->customId;
- $user = isset($this->user->attributes) ? $this->user->attributes : [];
- $post['bookName'] = isset($user['userName']) ? $user['userName'] : '';
- $bookMobile = !empty($post['bookMobile']) && stringUtil::isMobile($post['bookMobile']) ? $post['bookMobile'] : '';
- $bookMobile = empty($bookMobile) && !empty($user['mobile']) ? $user['mobile'] : $bookMobile;
- $post['bookMobile'] = $bookMobile;
- $prePrice = round($post['prePrice'], 2);
- $couponId = isset($post['couponId']) ? $post['couponId'] : 0;
- $discountData = OrderService::getDiscountPrice(['price' => $prePrice, 'sourceType' => 0, 'couponId' => $couponId, 'userId' => $this->userId]);
- $actPrice = $discountData['price'];
- $post['discountType'] = $discountData['discountType'];
- $post['discountAmount'] = $discountData['discountAmount'];
- $post['orderPrice'] = $actPrice;
- $post['actPrice'] = $actPrice;
- $post['realPrice'] = $actPrice;
- $post['mainPay'] = $actPrice;
- $post['payStyle'] = 0;
- $post['userId'] = $this->userId;
- $post['needPrint'] = dict::getDict('needPrint', 'noNeed');
- $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['goodsNum'] = 1;
- $post['fromType'] = $post['fromType'] ?? 1;
- $post['reachDate'] = !empty($post['reachDate']) ? $post['reachDate'] : '00-00-00';
- $post['onlinePay'] = dict::getDict('onlinePay', 'yes');
- //前端未修改时这边做兼容
- if (!empty($post['receiveAddress'])) {
- $post['address'] = $post['receiveAddress'];
- if (!empty($post['receiveProvince'])) {
- $post['province'] = $post['receiveProvince'];
- }
- if (!empty($post['receiveCity'])) {
- $post['city'] = $post['receiveCity'];
- }
- if (!empty($post['receiveFloor'])) {
- $post['floor'] = $post['receiveFloor'];
- }
- if (!empty($post['latitude'])) {
- $post['lat'] = $post['latitude'];
- }
- if (!empty($post['longitude'])) {
- $post['long'] = $post['longitude'];
- }
- $city = $post['receiveCity'] ?? '';
- $address = $post['receiveAddress'];
- $floor = $post['receiveFloor'] ?? '';
- $post['fullAddress'] = $city . $address . $floor;
- }
- $order = OrderClass::addOrder($post);
- $orderId = $order['id'] ?? 0;
- $orderSn = $order['orderSn'] ?? '';
- if ($payWay == 0) {
- $name = '购买商品';
- $totalFee = $actPrice;
- $user = UserService::getById($this->userId);
- //小程序使用miniOpenId
- $openId = $user['miniOpenId'];
- if (empty($openId)) {
- $openId = !empty($post['miniOpenId']) ? $post['miniOpenId'] : '';
- }
- if (empty($openId)) {
- util::fail('没有微信信息');
- }
- $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
- $sjExtend = WxOpenClass::getMallWxInfo();
- $shop = $this->shop;
- $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
- $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
- $params = [
- 'appid' => 'OP00002119',
- 'serial_no' => '018b08cfddbd',
- 'merchant_no' => $shop->lklSjNo,
- 'term_no' => $shop->lklScanTermNo,
- 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
- 'lklCertificatePath' => $lklCertificatePath,
- ];
- $laResource = new Lakala($params);
- $notifyUrl = Yii::$app->params['mallHost'] . "/notice/pay-callback";
- $wxParams = [
- 'orderSn' => $orderSn,
- 'amount' => $totalFee,
- 'capitalType' => $capitalType,
- 'notifyUrl' => $notifyUrl,
- 'wxAppId' => $sjExtend['miniAppId'],
- 'openId' => $openId,
- 'subject' => $name,
- 'couponId' => $couponId,
- ];
- $response = $laResource->driveWxPay($wxParams);
- if (!isset($response['code']) || $response['code'] != 'BBS00000') {
- $errMsg = $response['msg'] ?? '';
- noticeUtil::push($errMsg, '15280215347');
- util::fail('支付失败');
- }
- $newParams = isset($response['resp_data']['acc_resp_fields']) ? $response['resp_data']['acc_resp_fields'] : [];
- $appId = $newParams['app_id'] ?? '';
- $nonceStr = $newParams['nonce_str'] ?? '';
- $paySign = $newParams['pay_sign'] ?? '';
- $package = $newParams['package'] ?? '';
- $signType = $newParams['sign_type'] ?? '';
- $timeStamp = $newParams['time_stamp'] ?? '';
- $new = [
- 'id' => $orderId,
- 'appId' => $appId,
- 'nonceStr' => $nonceStr,
- 'paySign' => $paySign,
- 'package' => $package,
- 'signType' => $signType,
- 'timeStamp' => $timeStamp,
- 'orderSn' => $orderSn,
- ];
- util::success($new);
- } elseif ($payWay == 1) {
- $totalFee = $order['realPrice'];
- $subject = '购买花材';
- $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
- $shop = $this->shop;
- $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
- $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
- $params = [
- 'appid' => 'OP00002119',
- 'serial_no' => '018b08cfddbd',
- 'merchant_no' => $shop->lklSjNo,
- 'term_no' => $shop->lklB2BTermNo,
- 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
- 'lklCertificatePath' => $lklCertificatePath,
- ];
- $laResource = new Lakala($params);
- $notifyUrl = Yii::$app->params['mallHost'] . "/notice/cash-pay-callback";
- $cashParams = [
- 'orderSn' => $orderSn,
- 'amount' => $totalFee,
- 'capitalType' => $capitalType,
- 'notifyUrl' => $notifyUrl,
- 'subject' => $subject,
- ];
- $response = $laResource->cashierPay($cashParams);
- if (!isset($response['code']) || $response['code'] != '000000') {
- util::fail('支付失败了');
- }
- $url = $response['resp_data']['counter_url'] ? $response['resp_data']['counter_url'] : '';
- if (empty($url)) {
- util::fail('支付失败');
- }
- util::success(['url' => $url]);
- } elseif ($payWay == 2) {
- util::fail('无效的支付方式');
- //余额支付,验证支付密码是否正确
- $payPassword = isset($post['payPassword']) ? $post['payPassword'] : 0;
- $user = UserService::getUserInfo($this->userId);
- UserService::validPayPassword($payPassword, $user);
- $capitalType = dict::getDict('capitalType', '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('无效的支付方式');
- }
- }
- //订单列表 ssh 2019.12.12
- public function actionList()
- {
- $get = Yii::$app->request->get();
- $status = $get['status'] ?? 0;
- $userId = $this->userId;
- $where = ['userId' => $userId];
- if (!empty($status)) {
- $where['status'] = $status;
- }
- $list = OrderService::getOrderList($where);
- util::success($list);
- }
- //订单评价
- public function actionComment()
- {
- $post = Yii::$app->request->post();
- $id = $post['id'];
- $order = OrderClass::getById($id);
- if ($order['grade'] > 0) {
- util::fail('您已经评过了');
- }
- OrderService::comment($post);
- util::complete('提交成功');
- }
- //订单详情 ssh 2019.12.16
- public function actionDetail()
- {
- $id = Yii::$app->request->get('id', 0);
- $detail = OrderClass::getOrderById($id);
- $shOrderMap = [];
- if ($detail['hasForward'] == 1) {
- $shOrderMap = OrderForwardClass::getAllByCondition(['orderId' => $id], null, '*');
- }
- $detail['shOrderMap'] = $shOrderMap;
- util::success($detail);
- }
- //获取详情 ssh 20220512
- public function actionInfo()
- {
- $sn = Yii::$app->request->get('orderSn', '');
- $detail = OrderClass::getOrderBySn($sn);
- util::success($detail);
- }
- }
|