aaa'); // 在画布上输出HTML内容 imagestring($image, 5, 0, 0, $html, 0x000000); // 将画布保存为PNG格式图像 imagepng($image, 'output.png'); // 显示图像 header('Content-Type: image/png'); imagepng($image); // 释放画布资源 imagedestroy($image); } //欠款的查询与跟踪 ssh 20240103 public function actionDebt() { $customId = 17081; $custom = CustomClass::getById($customId, true); if (empty($custom)) { echo '没有找到客户'; die; } $flag = []; $changeList = CustomDebtChangeClass::getAllByCondition(['customId' => $customId], null, '*'); if (!empty($changeList)) { foreach ($changeList as $change) { $event = $change['evnet'] ?? ''; $relateId = $change['relateId'] ?? 0; $amount = $change['amount'] ?? 0; if (strpos($event, '购买花材') >= 0) { $flag['40-' . $relateId] = $amount; } if (strpos($event, '退款') >= 0) { $flag['33-' . $relateId] = $amount; } if (strpos($event, '结账') >= 0) { $flag['20-' . $relateId] = $amount; } } } print_r($flag); $orderList = OrderClass::getAllByCondition(['customId' => $customId, 'debtPrice>' => 0], null, 'id,actPrice,payTime', null); $arr = []; if (!empty($orderList)) { foreach ($orderList as $order) { $payTime = $order['payTime'] ?? ''; $id = $order['id'] ?? 0; $arr[$payTime] = $order; if (isset($flag['40-' . $id]) == false) { echo '40-' . $id . "订单有问题\n"; } } } //20 $clearList = PurchaseClearClass::getAllByCondition(['customId' => $customId, 'status' => 2], null, 'id,actPrice,payTime', null); if (!empty($clearList)) { foreach ($clearList as $clear) { $payTime = $clear['payTime'] ?? ''; $id = $clear['id'] ?? 0; $arr[$payTime] = $clear; if (isset($flag['20-' . $id]) == false) { echo '20-' . $id . "结账有问题\n"; } } } //33 $refundList = RefundOrderClass::getAllByCondition(['customId' => $customId], null, 'id,refundPrice,updateTime', null); if (!empty($refundList)) { foreach ($refundList as $refund) { $id = $refund['id'] ?? 0; $updateTime = $refund['updateTime'] ?? ''; $arr[$updateTime] = $refund; if (isset($flag['33-' . $id]) == false) { echo '33-' . $id . "退款单有问题\n"; } } } echo "
";
        ksort($arr);
        print_r($arr);
        die;
    }

    //退款操作 ssh 20231029
    public function actionRefund()
    {
        $shopId = 36524;
        $shop = ShopClass::getById($shopId, true);
        if (empty($shop)) {
            util::fail('没有找到门店');
        }
        $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);
        $refundReason = '暂无';
        $refundOrderSn = orderSn::getCgRefundSn();
        $refundPrice = 0.01;
        $refundFee = bcmul($refundPrice, 100);
        $orderSn = 'KD_CS61235203';
        $originTradeNo = '20231030110113230266215266468756';
        //$originLogNo = '66215266025626';
        $aliParams = [
            'refundSn' => $refundOrderSn,
            'orderSn' => $orderSn,
            'refundAmount' => $refundFee,
            'refundReason' => $refundReason,
            'originTradeNo' => $originTradeNo,
            //'originLogNo' => $originLogNo,
        ];
        $response = $laResource->refund($aliParams);
        echo '
';
        print_r($response);
    }

    public function actionApply()
    {
        $id = 2888;
        $shopId = 36524;
        $cg = PurchaseClass::getById($id, true);
        $shop = ShopClass::getById($shopId, true);
        WxMessageClass::hdNewCgOrderInform($shop, $cg);
    }

    public function actionGet()
    {
        ini_set('memory_limit', '2045M');
        set_time_limit(0);

        $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
        $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';

        $arr = [
            //['name' => '国兰花尚OK', 'merchantNo' => '82239305992006L', 'wx' => [600913569, 600907053], 'zfb' => '2088820709029782'],
            //['name' => '花掌柜OK', 'merchantNo' => '82240505992000P', 'wx' => [600466131, 600465187], 'zfb' => '2088820656569304'],
            //['name' => '纯彩花艺OK', 'merchantNo' => '82239305992006M', 'wx' => [600922790, 600915407], 'zfb' => '2088820710146836'],
            //['name' => '集美天天鲜花OK', 'merchantNo' => '82239305992006P', 'wx' => [601036538, 601036322], 'zfb' => '2088820726763339'],
            //['name' => '丰行花行OK', 'merchantNo' => '82260205992007P', 'wx' => [601053759, 601052157], 'zfb' => '2088820725885465'],
            //['name' => '独家花行OK', 'merchantNo' => '82239305992006Q', 'wx' => [601049483, 601048223], 'zfb' => '2088820725546555'],
            //['name' => '好多花海沧OK', 'merchantNo' => '82239305992006R', 'wx' => [601052177, 601053735], 'zfb' => '2088820725549695'],
            //['name' => '美天鲜花OK', 'merchantNo' => '82259505992003F', 'wx' => [601062064, 601138175], 'zfb' => '2088820729400990'],
            //['name' => '天天陈江店OK', 'merchantNo' => '82259505992003E', 'wx' => [601060616, 601059382], 'zfb' => '2088820725555368'],
            //['name' => '叶上花OK', 'merchantNo' => '82231805992002G', 'wx' => [601062892, 601062589], 'zfb' => '2088820728763546'],
            //['name' => '好又多(小明)OK', 'merchantNo' => '82239305992006S', 'wx' => [601135715, 601067347], 'zfb' => '2088820729698012'],
            //['name' => '我卖花OK', 'merchantNo' => '82227505992000R', 'wx' => [601177139, 601148755], 'zfb' => '2088820746424032'],
            //['name' => '问境OK', 'merchantNo' => '8226900599200KX', 'wx' => [601299388, 601299453], 'zfb' => '2088820787661843'],
            //['name' => '昱成OK', 'merchantNo' => '8226900599200KY', 'wx' => [601312993, 601325844], 'zfb' => '2088820788900240'],
            //['name' => '杭州斗南', 'merchantNo' => '杭州斗南', 'wx' => [601405963, 601405929], 'zfb' => '2088820793601705'],
            //['name' => '杭州斗南(没用)', 'merchantNo' => '8223310599200AD', 'wx' => [601254682, 601250805], 'zfb' => '2088820782666872'],
            //['name' => '珑松花卉长安店', 'merchantNo' => '82260205992007U', 'wx' => [602499045, 602497558], 'zfb' => '2088820959620797'],
            //['name' => '福州花福(个人)', 'merchantNo' => '82239105992007P', 'wx' => [603301197, 603302321], 'zfb' => '2088920058098261'],
            //['name' => '福州花福', 'merchantNo' => '82239105992007N', 'wx' => [602796807, 602774796], 'zfb' => '2088820996010582'],
            //['name' => '昆明新宏源', 'merchantNo' => '82239305992007H', 'wx' => [606098318, 606100317], 'zfb' => '2088920878302843'],
            //['name' => '昆明纯彩', 'merchantNo' => '82239905992003L', 'wx' => [604923629, 604922175], 'zfb' => '2088920533160795'],
            //['name' => '花优田(军兴旺)', 'merchantNo' => '8227310599200GX', 'wx' => [605191281, 605190492], 'zfb' => '2088920588715249'],
            ['name' => '肇庆兄弟鲜花', 'merchantNo' => '82259305992001V', 'wx' => [628299301, 628297384], 'zfb' => '2088930936937722'],
            //['name' => '郑州唯一鲜花', 'merchantNo' => '8224910599200NB', 'wx' => [624877731, 624877902], 'zfb' => '2088830970964611'],
            //['name' => '昆明期待鲜花', 'merchantNo' => '8227310599200J6', 'wx' => [615582300, 615582180], 'zfb' => '2088530113958388'],
            //['name' => '厦门遇见你', 'merchantNo' => '82239305992008D', 'wx' => [614782373, 614783346], 'zfb' => '2088430828233036'],
            //['name' => '淄博花超鲜花批发', 'merchantNo' => '82245305992001R', 'wx' => [614685779, 614682986], 'zfb' => '2088430805221810'],
            //['name' => '广州国恋', 'merchantNo' => '8225810599200Q7', 'wx' => [612321716, 612320978], 'zfb' => '2088330479975012'],
            //['name' => '欣研鲜花', 'merchantNo' => '82260305992001Y', 'wx' => [612181234, 612181615], 'zfb' => '2088330365608286'],
            //['name' => '村长冷链', 'merchantNo' => '82260205992008G', 'wx' => [612168406, 612168000], 'zfb' => '2088330360870932'],
            //['name' => '惠州惠雅鲜花批发', 'merchantNo' => '82259505992003S', 'wx' => [611676975, 611677314], 'zfb' => '2088330136601427'],
            //['name' => '杭州斗南鲜花', 'merchantNo' => '8223310599200AR', 'wx' => [608955814, 608955082], 'zfb' => '2088130449323603'],
            //['name' => '营口简约花卉', 'merchantNo' => '8227310599200HJ', 'wx' => [608439898, 608440994], 'zfb' => '2088130112725929'],
            //['name' => '惠雅鲜花惠州店', 'merchantNo' => '82260205992007Z', 'wx' => [608406948, 608403207], 'zfb' => '2088130098167302'],
            //['name' => '云南珑松花卉珠海店', 'merchantNo' => '82258505992002U', 'wx' => [608062727, 608056474], 'zfb' => '2088030873238576'],
            ['name' => '昆明鹏诚花卉', 'merchantNo' => '8227310599200JK', 'wx' => [630710385, 630711403], 'zfb' => '2088040532857091'],
            ['name' => '买手很忙', 'merchantNo' => '8227310599200GJ', 'wx' => [601597167, 601595526], 'zfb' => '2088820818930267'],
            //['name' => '七彩花都', 'merchantNo' => '8227310599200GF', 'wx' => [601176481, 601148503], 'zfb' => '2088820748594478'],
            //['name' => '十年', 'merchantNo' => '82252305992001U', 'wx' => [601285154, 601261795], 'zfb' => '2088820782171763'],
            //['name' => '都市花季OK', 'merchantNo' => '82239305992006U', 'wx' => [601174342, 601147649], 'zfb' => '2088820748507346'],
            //['name' => '花样年华OK', 'merchantNo' => '82260205992007Q', 'wx' => [601134352, 601091710], 'zfb' => '2088820735043444'],
            //['name' => '精茂城OK', 'merchantNo' => '8225840599200TF', 'wx' => [601173752, 601143352], 'zfb' => '2088820746800005'],
            //['name' => '莱漫OK', 'merchantNo' => '82239305992007A', 'wx' => [601288494, 601288166], 'zfb' => '2088820783686611'],
            //['name' => '莱漫(没用)', 'merchantNo' => '82239305992006T', 'wx' => [601134065, 601125595], 'zfb' => '2088820743859918'],
            //['name' => '福州我要花OK', 'merchantNo' => '82239105992007J', 'wx' => [601134030, 601128111], 'zfb' => '2088820745276973'],
            //['name' => '泉城OK', 'merchantNo' => '82239705992004F', 'wx' => [601273270, 601272854], 'zfb' => '2088820784658561'],
            //['name' => '泉城(没用)', 'merchantNo' => '82239705992004E', 'wx' => [601133056, 601133821], 'zfb' => '2088820746111323'],
            //['name' => '美丽花行OK', 'merchantNo' => '82239305992006V', 'wx' => [601155249, 601149712], 'zfb' => '2088820747673312'],
            //['name' => '三叶OK', 'merchantNo' => '82236805992001Y', 'wx' => [601152233, 601151024], 'zfb' => '2088820747556725'],
            //['name' => '花大苪OK', 'merchantNo' => '8227310599200GG', 'wx' => [601174221, 601165136], 'zfb' => '2088820751181377'],
            //['name' => '十堰天天鲜花OK', 'merchantNo' => '82252305992001S', 'wx' => [601171131, 601170642], 'zfb' => '2088820750844626'],
            //['name' => '珑松花卉OK', 'merchantNo' => '82260205992007S', 'wx' => [601176093, 601174262], 'zfb' => '2088820754742492'],
            //['name' => '惠雅鲜花OK', 'merchantNo' => '82260205992007R', 'wx' => [601173390, 601174002], 'zfb' => '2088820753174540'],
            //['name' => '锦绣花卉OK', 'merchantNo' => '82252305992001T', 'wx' => [601176719, 601176660], 'zfb' => '2088820754751663'],
            //['name' => '祥瑞鲜花同安店OK', 'merchantNo' => '82239305992006W', 'wx' => [601178350, 601177795], 'zfb' => '2088820755715024'],
            //['name' => '祥瑞鲜花翔安店OK', 'merchantNo' => '82239305992006X', 'wx' => [601178260, 601178199], 'zfb' => '2088820754481553'],
            //['name' => '初见花季OK', 'merchantNo' => '82239305992006Y', 'wx' => [601178998, 601179605], 'zfb' => '2088820757223312'],
            //['name' => '荣发鲜花OK', 'merchantNo' => '82242705992000D', 'wx' => [601179681, 601179180], 'zfb' => '2088820756926593'],
            //['name' => '花千朵(多多)OK', 'merchantNo' => '82239305992006Z', 'wx' => [601223474, 601208096], 'zfb' => '2088820766783276'],
            //['name' => '花悠星OK', 'merchantNo' => '8225810599200NH', 'wx' => [601228194, 601227691], 'zfb' => '2088820774587446'],
            //['name' => '花悠星(没用)', 'merchantNo' => '8225810599200NG', 'wx' => [601223630, 601210952], 'zfb' => '2088820767072874'],
            //['name' => '源花汇OK', 'merchantNo' => '82222105992004A', 'wx' => [601221944, 601214269], 'zfb' => '2088820770594246'],
            //['name' => '源花汇2(没用)', 'merchantNo' => '8227310599200GD', 'wx' => [601136305, 601067016], 'zfb' => '2088820729832744'],
        ];
        $new = [];
        foreach ($arr as $item) {
            $wx = $item['wx'];
            $zfb = $item['zfb'];
            $merchantNo = $item['merchantNo'];
            $name = $item['name'] . ' ' . $merchantNo;
            $group = [];
            foreach ($wx as $oneWx) {
                $params = [
                    'appid' => 'OP00002119',
                    'serial_no' => '018b08cfddbd',
                    'merchant_no' => $merchantNo,
                    'term_no' => 'C6337694',
                    'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
                    'lklCertificatePath' => $lklCertificatePath,
                ];
                $data = [
                    'subMerchantId' => $oneWx,
                    'tradeMode' => 'WECHAT',
                ];
                $laResource = new Lakala($params);
                $response = $laResource->openStateQuery($data);
                $statusName = '出错了';
                if ($response['retCode'] == '000000') {
                    $checkResult = $response['respData']['checkResult'] ?? '';
                    $statusName = '未认证';
                    if ($checkResult == 'AUTHORIZE_STATE_AUTHORIZED') {
                        $statusName = '已认证';
                    }
                }
                $group[] = '微信 ' . $oneWx . ' ' . $statusName;
            }

            $params = [
                'appid' => 'OP00002119',
                'serial_no' => '018b08cfddbd',
                'merchant_no' => $merchantNo,
                'term_no' => 'C6337694',
                'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
                'lklCertificatePath' => $lklCertificatePath,
            ];
            $data = [
                'subMerchantId' => $zfb,
                'tradeMode' => 'ALIPAY',
            ];
            $laResource = new Lakala($params);
            $response = $laResource->openStateQuery($data);
            $statusName = '出错了';
            if ($response['retCode'] == '000000') {
                $checkResult = $response['respData']['checkResult'] ?? '';
                $statusName = '未认证';
                if ($checkResult == 'AUTHORIZED') {
                    $statusName = '已认证';
                }
            }
            $group[] = '支付宝 ' . $zfb . ' ' . $statusName;
            $new[] = ['name' => $name, 'status' => $group];
        }
        echo '
';
        print_r($new);
        die;
    }

    public function actionRefundQuery()
    {
        $shopId = 520;
        $shop = ShopClass::getById($shopId, true);
        if (empty($shop)) {
            util::stop('没有找到门店');
        }
        $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);

        $orderSn = '20231201110113131266165492618754';
        $data = [
            'orderSn' => $orderSn,
        ];
        $response = $laResource->refundQuery($data);
        echo "
";
        print_r($response);
    }

    public function actionBalanceQuery()
    {
        $shopId = 1212;
        $shop = ShopClass::getById($shopId, true);
        if (empty($shop)) {
            util::stop('没有找到门店');
        }
        $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);
        $response = $laResource->accountBalanceQuery();
        echo "
";
        print_r($response);
    }

    //测试环境查线上数据 ssh 20231230
    public function actionCsQuery()
    {
//        $shopId = 1527;
//        $shop = ShopClass::getById($shopId, true);
//        if (empty($shop)) {
//            util::stop('没有找到门店');
//        }
        $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,
            'merchant_no' => '82222105992004A',
            //'term_no' => $shop->lklScanTermNo,
            'term_no' => 'H3656802',
            'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
            'lklCertificatePath' => $lklCertificatePath,
        ];
        $laResource = new Lakala($params);
        $queryParams = [
            //'orderSn' => 'KD26452235',
            'tradeNo' => '20231230110113130266215700775011',
        ];
        $response = $laResource->query($queryParams, 1);
        echo "
";
        print_r($response);
    }

    public function actionQuery()
    {
        $shopId = 726;
        $shop = ShopClass::getById($shopId, true);
        if (empty($shop)) {
            util::stop('没有找到门店');
        }
        $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);
        $queryParams = [
            'orderSn' => 'KD26481486',
            //'tradeNo' => '20231230110113130266215700775011',
        ];
        $response = $laResource->query($queryParams, 0);
        echo "
";
        print_r($response);
    }

    public function actionClearQuery()
    {
        $shopId = 8249;
        $shop = ShopClass::getById($shopId, true);
        if (empty($shop)) {
            util::stop('没有找到门店');
        }
        $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);
        $queryParams = [
            //'orderSn' => 'CL28693295',
            'tradeNo' => '66215417437878',
        ];
        $response = $laResource->query($queryParams, 1);
        echo "
";
        print_r($response);
    }

    //零售订单查询 ssh 20231031
    public function actionLsTradeQuery()
    {
        $shopId = 520;
        $shop = ShopClass::getById($shopId, true);
        if (empty($shop)) {
            util::stop('没有找到门店');
        }
        $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);
        $queryParams = [
            'orderSn' => 'KD26487879',
            //'tradeNo' => '20231029110113130266215259252887',
        ];
        $response = $laResource->query($queryParams, 0);
        print_r($response);
        util::stop();
        if (isset($response['code']) && $response['code'] == 'BBS00000') {

            $connection = Yii::$app->db;
            $transaction = $connection->beginTransaction();
            try {

                $postData = $response['resp_data'] ?? [];
                $orderSn = $postData['out_trade_no'] ?? '';
                $total_amount = $postData['total_amount'] ?? 0;
                $account_type = $postData['account_type'] ?? '';
                if (empty($account_type)) {
                    noticeUtil::push('支付回调失败了,没有找到钱包类型,请注意,orderSn:' . $orderSn, '15280215347');
                    util::end();
                }
                $totalFee = $total_amount / 100;
                $transactionId = $postData['trade_no'] ?? 0;
                $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');

                $currentPayWay = null;
                if ($account_type == 'WECHAT') {
                    $currentPayWay = dict::getDict('payWay', 'wxPay');
                } elseif ($account_type == 'ALIPAY') {
                    $currentPayWay = dict::getDict('payWay', 'alipay');
                } else {
                    noticeUtil::push('支付回调失败了,没有找到支付类型,orderSn:' . $orderSn, '15280215347');
                    util::end();
                }
                $attach = '';
                payUtil::thirdPay($currentPayWay, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
                $transaction->commit();
                echo 'OK';
            } catch (\Exception $e) {
                $transaction->rollBack();
                Yii::error("失败原因:" . $e->getMessage());
            }
        }
    }

    //零售订单查询 ssh 20231031
    public function actionClear()
    {
        $shopId = 10649;
        $shop = ShopClass::getById($shopId, true);
        if (empty($shop)) {
            util::stop('没有找到门店');
        }
        $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);
        $queryParams = [
            //'orderSn' => 'KD26461864',
            'tradeNo' => '20231230110113130266215700775011',
        ];
        $response = $laResource->query($queryParams, 1);
        print_r($response);
        util::stop();
        if (isset($response['code']) && $response['code'] == 'BBS00000') {

            $connection = Yii::$app->db;
            $transaction = $connection->beginTransaction();
            try {

                $postData = $response['resp_data'] ?? [];
                $orderSn = $postData['out_trade_no'] ?? '';
                $total_amount = $postData['total_amount'] ?? 0;
                $account_type = $postData['account_type'] ?? '';
                if (empty($account_type)) {
                    noticeUtil::push('支付回调失败了,没有找到钱包类型,请注意,orderSn:' . $orderSn, '15280215347');
                    util::end();
                }
                $totalFee = $total_amount / 100;
                $transactionId = $postData['trade_no'] ?? 0;

                $capitalType = dict::getDict('capitalType', 'hdPurchaseClear', 'id');

                $currentPayWay = null;
                if ($account_type == 'WECHAT') {
                    $currentPayWay = dict::getDict('payWay', 'wxPay');
                } elseif ($account_type == 'ALIPAY') {
                    $currentPayWay = dict::getDict('payWay', 'alipay');
                } else {
                    noticeUtil::push('支付回调失败了,没有找到支付类型,orderSn:' . $orderSn, '15280215347');
                    util::end();
                }
                $attach = '';
                payUtil::thirdPay($currentPayWay, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
                $transaction->commit();
                echo 'OK';
            } catch (\Exception $e) {
                $transaction->rollBack();
                Yii::error("失败原因:" . $e->getMessage());
            }
        }
    }

    //交易查询 ssh 20231021
    public function actionTradeQuery()
    {
        $shopId = 7855;
        $shop = ShopClass::getById($shopId, true);
        if (empty($shop)) {
            util::stop('没有找到门店');
        }
        $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);
        $queryParams = [
            //'orderSn' => 'CG26890919',
            'tradeNo' => '66215960152739',
        ];
        $response = $laResource->query($queryParams, 1);
        print_r($response);
        util::stop();
        if (isset($response['code']) && $response['code'] == 'BBS00000') {
            $capitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
            $connection = Yii::$app->db;
            $transaction = $connection->beginTransaction();
            try {

                $account_type = $response['resp_data']['account_type'] ?? 0;
                if (empty($account_type)) {
                    noticeUtil::push('支付回调失败了,没有找到钱包类型,请注意', '15280215347');
                    util::end();
                }
                $currentPayWay = null;
                if ($account_type == 'WECHAT') {
                    $currentPayWay = dict::getDict('payWay', 'wxPay');
                } elseif ($account_type == 'ALIPAY') {
                    $currentPayWay = dict::getDict('payWay', 'alipay');
                } else {
                    noticeUtil::push('支付回调失败了,没有找到支付类型', '15280215347');
                    util::end();
                }

                $attach = '';
                $total_amount = $response['resp_data']['total_amount'] ?? 0;
                $orderSn = $response['resp_data']['out_trade_no'] ?? 0;
                $totalFee = $total_amount / 100;
                $transactionId = $response['resp_data']['trade_no'] ?? 0;
                payUtil::thirdPay($currentPayWay, $capitalType, $orderSn, $totalFee, $attach, $transactionId);
                $transaction->commit();
                echo 'OK';
            } catch (\Exception $e) {
                $transaction->rollBack();
                Yii::error("失败原因:" . $e->getMessage());
            }
        }
    }

    public function actionAliRun2()
    {
        $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' => '82240505992000N',
            'term_no' => 'C6337694',
            'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
            'lklCertificatePath' => $lklCertificatePath,
        ];
        $outTradeNo = orderSn::getPurchaseSn();
        $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback";
        $currentCapitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
        $aliParams = [
            'orderSn' => $outTradeNo,
            'amount' => 0.16,
            'capitalType' => $currentCapitalType,
            'notifyUrl' => $notifyUrl,
        ];
        $laResource = new Lakala($params);
        $response = $laResource->driveAliPay($aliParams);
        if ($response && isset($response['cmdRetCode']) && $response['cmdRetCode'] == 'GLOBAL_SUCCESS') {
            echo '
';
            echo "下单成功
"; print_r($response); } else { echo '
';
            echo "下单失败
"; print_r($response); } } public function actionAliRun3() { $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' => '82240505992000N', 'term_no' => 'C6337694', 'merchantPrivateKeyPath' => $merchantPrivateKeyPath, 'lklCertificatePath' => $lklCertificatePath, ]; $laResource = new Lakala($params); $outTradeNo = orderSn::getPurchaseSn(); $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback"; $currentCapitalType = dict::getDict('capitalType', 'xhPurchase', 'id'); $wxParams = [ 'orderSn' => $outTradeNo, 'amount' => 0.16, 'capitalType' => $currentCapitalType, 'notifyUrl' => $notifyUrl, ]; $response = $laResource->driveWxPay($wxParams); if ($response && isset($response['cmdRetCode']) && $response['cmdRetCode'] == 'GLOBAL_SUCCESS') { echo '
';
            echo "下单成功
"; print_r($response); } else { echo '
';
            echo "下单失败
"; print_r($response); } } //dada 城市code public function actionDadaCityCode() { $res = dada::getCityCode(0); util::success($res); } //理由 public function actionDadaReasons() { $res = dada::getCancelReason(0); util::success($res); } //达达 :下单 public function actionDadaAddOrder() { $orderSn = 'XSD_CS26316851'; $orderInfo = OrderClass::getByOrderSn($orderSn); $res = DadaExpressServices::addOrder($orderInfo); util::success($res); } //重发快递 public function actionDadaReAdd() { $orderSn = 'XSD_CS26316851'; $orderInfo = OrderClass::getByOrderSn($orderSn); $res = DadaExpressServices::reAddOrder($orderInfo); util::success($res); } //达达状态查询 public function actionDadaOrderStatus() { $orderSn = 'XSD_CS26316851'; $res = DadaExpressServices::statusOrder($orderSn); util::success($res); } //达达取消下单 public function actionDadaCancelOrder() { $orderSn = 'XSD_CS26316851'; $res = DadaExpressServices::cancelOrder($orderSn, 1); util::success($res); } //获取已支持的配送公司列表接口 public function actionGetAllDelivery() { $data = MiniExpressService::getAllImmeDelivery(); util::success($data); } //即时配送 /* * Array ( [resultcode] => 0 [resultmsg] => OK [shop_list] => Array ( [0] => Array ( [shopid] => 1588714266 [delivery_id] => SFTC [audit_result] => 0 [create_time] => 1612172838 [remark] => [delivery_name] => 顺丰同城急送 ) ) ) */ public function actionGetBindAccount() { $merchant = WxOpenClass::getGhsWxInfo(); $isOpen = 2; $r = miniUtil::getBindAccount($merchant, $isOpen); dd($r); } //下单 (沙箱) /** * Array * ( * [resultcode] => 0 * [resultmsg] => ok * [fee] => 10 * [waybill_id] => test_shop_id1612365974_waybillid * [order_status] => 101 * [dispatch_duration] => 300 * ) */ public function actionCreateWaybill() { $merchant = WxOpenClass::getGhsWxInfo(); $isOpen = 2; $shopId = 'test_shop_id'; $shopOrderId = 'test_shop_id' . time(); $appSecret = 'test_app_secrect'; $data = [ 'shopid' => $shopId, 'shop_order_id' => $shopOrderId, 'shop_no' => '1', 'delivery_sign' => miniUtil::getDeliverySign($shopId, $shopOrderId, $appSecret), //,则delivery_sign=SHA1(shopid + shop_order_id + AppSecret) 'delivery_id' => "TEST", 'openid' => 'oGKMp45YLxewOTWEbpMFzWoVqdW0', 'sender' => [ 'name' => 'test', 'city' => '厦门市', 'address' => '思明区', 'address_detail' => '软件园二期', 'phone' => '19959271111', 'lng' => 118.134343, 'lat' => 24.483566, 'coordinate_type' => 0, ], 'receiver' => [ 'name' => 'test', 'city' => '厦门市', 'address' => '思明区', 'address_detail' => '软件园二期', 'phone' => '19959271111', 'lng' => 118.134343, 'lat' => 24.493566, 'coordinate_type' => 0, ], 'cargo' => [ 'goods_value' => 1, 'goods_weight' => 0.1, 'cargo_first_class' => '鲜花', 'cargo_second_class' => '鲜花', ], 'order_info' => [ 'order_type' => 0, ], 'shop' => [ 'wxa_path' => '/shop', 'img_url' => 'http://www.baidu.com/test.png', 'goods_name' => 'test', 'goods_count' => 1, ], ]; $r = miniUtil::addOrder($data, $merchant, $isOpen); dd($r); } //获取运单数据 /** * Array * ( * [resultcode] => 0 * [resultmsg] => ok * [order_status] => 101 * [agent_info] => Array * ( * ) * * [waybill_id] => test_shop_id1612365974_waybillid * [rider_name] => * [rider_phone] => * [order_token] => NsXweKCKhSyAEIhAdnX3TYZsVDES0-t-tymHDONG0MpRsF31dQvVxiP_JJvLFaKS-kwXuOG3D0hzKkl7o-gzew * ) */ public function actionGetOrder() { $shopId = 'test_shop_id'; $shopOrderId = 'test_shop_id1612365974'; $appSecret = 'test_app_secrect'; $merchant = WxOpenClass::getGhsWxInfo(); $isOpen = 2; $data = [ 'shopid' => $shopId, 'shop_order_id' => $shopOrderId, 'shop_no' => '1', 'delivery_sign' => MiniExpressService::getDeliverySign($shopId, $shopOrderId, $appSecret), ]; $r = miniUtil::getOrder($data, $merchant, $isOpen); dd($r); } //沙盒 更新快递状态 public function actionMockUpdateOrder() { $merchant = WxOpenClass::getGhsWxInfo(); $isOpen = 2; /** * { * "shopid": "test_shop_id", * "shop_order_id": "xxxxxxxxxxx", * "waybill_id": "xxxxxxxxxxxxx", * "action_time": 12345678, * "order_status": 101, * "action_msg": "", * } */ $shopId = 'test_shop_id'; $shopOrderId = 'test_shop_id1612365974'; $data = [ 'shop_order_id' => $shopOrderId, "shopid" => $shopId, "action_time" => time(), "order_status" => 302, 'action_msg' => '状态变更', ]; $r = miniUtil::mockUpdateOrder($data, $merchant, $isOpen); dd($r); } public function actionTest() { } //新增订单 public function actionAddOrder() { $dada = Yii::getAlias("@vendor/dada/"); require_once $dada . 'api/addOrderApi.php'; require_once $dada . 'client/dadaRequestClient.php'; require_once $dada . 'client/dadaResponse.php'; require_once $dada . 'config/config.php'; require_once $dada . 'model/orderModel.php'; // isOnline 判断是否是测试环境,会有不同的域名等 $isOnline = false; $sourceId = 1000000; // 初始化一个config $config = new \Config($sourceId, $isOnline); $orderModel = new \OrderModel(); $orderModel->setShopNo('11047059'); $orderModel->setOriginId('2018091100000002'); $orderModel->setCityCode('021'); $orderModel->setCargoPrice(10); $orderModel->setIsPrepay(0); $orderModel->setReceiverName('测试达达'); $orderModel->setReceiverAddress('上海市崇明岛'); $orderModel->setReceiverLat(31.63); $orderModel->setReceiverLng(121.41); $orderModel->setReceiverPhone('18588888888'); $orderModel->setCallback('http://api.b.huaml.com/data/request'); // api主要有2个参数,一个是url, 一个是业务参数 $addOrderApi = new \AddOrderApi(json_encode($orderModel)); $dada_client = new \DadaRequestClient($config, $addOrderApi); $resp = $dada_client->makeRequest(); echo json_encode($resp); } //订单详情查询 public function actionOrderQuery() { $dada = Yii::getAlias("@vendor/dada/"); require_once $dada . 'api/OrderQueryApi.php'; require_once $dada . 'client/dadaRequestClient.php'; require_once $dada . 'client/dadaResponse.php'; require_once $dada . 'config/config.php'; require_once $dada . 'model/orderModel.php'; // isOnline 判断是否是测试环境,会有不同的域名等 $isOnline = false; $sourceId = 1000000; // 初始化一个config $config = new \Config($sourceId, $isOnline); $orderModel = new \OrderModel(); $orderModel->setOrderId('2018091100000002'); // api主要有2个参数,一个是url, 一个是业务参数 $addOrderApi = new \OrderQueryApi(json_encode($orderModel)); $dada_client = new \DadaRequestClient($config, $addOrderApi); $resp = $dada_client->makeRequest(); echo json_encode($resp); } public function actionFocus() { $name = '花卉宝'; if (getenv('YII_ENV') == 'dev') { $name = '花美灵'; } $merchant = MerchantService::getByCondition(['name' => $name]); $list = wxUtil::getSubscribeUserList($merchant); dd($list); } //宝贝售出提醒 ssh 2020.1.30 public function actionInform() { $merchant = MerchantService::getMerchantById(12362); $order = OrderService::getById(214810); InformAdminClass::sendComplete($order); } public function actionNotice() { $data = ['messageType' => 'inform', 'informWay' => 'wx', 'userType' => 'admin', 'id' => 6, 'mobile' => '15280215347']; $producer = Yii::$app->rabbitmq->getProducer('informProducer'); echo '
';
        print_r($data);
        $msg = serialize($data);
        $r = $producer->publish($msg, 'informExchange', 'informRoute');
    }

}